[cpl-plugin-sinfo] 04/42: Upstream version 2.3.2

Ole Streicher olebole-guest at alioth.debian.org
Mon Sep 16 11:16:10 UTC 2013


This is an automated email from the git hooks/post-receive script.

olebole-guest pushed a commit to branch debian
in repository cpl-plugin-sinfo.

commit f5e1d49b7f00f7aa7bf72925b0673fb5b7dd5965
Author: Ole Streicher <debian at liska.ath.cx>
Date:   Mon Jan 7 16:33:52 2013 +0100

    Upstream version 2.3.2
---
 AUTHORS                                            |    5 +
 COPYING                                            |  340 +
 COPYING.LIB                                        |  515 +
 ChangeLog                                          |  156 +
 INSTALL                                            |  229 +
 Makefile.am                                        |   73 +
 Makefile.in                                        |  917 ++
 Makefile.purify.in                                 |  109 +
 README                                             |  230 +
 acinclude.m4                                       |  300 +
 aclocal.m4                                         | 1075 ++
 admin/compile                                      |  143 +
 admin/config.guess                                 | 1561 ++
 admin/config.sub                                   | 1686 ++
 admin/depcomp                                      |  630 +
 admin/html.am                                      |   74 +
 admin/install-sh                                   |  520 +
 admin/ltmain.sh                                    | 8406 ++++++++++
 admin/missing                                      |  376 +
 calib/cal/REF_BP_MAP.fits                          |    1 +
 calib/cal/SI_GATM_REF_CORR_HK_025.fits             |  Bin 0 -> 8640 bytes
 calib/cal/SI_GATM_REF_CORR_HK_100.fits             |  Bin 0 -> 8640 bytes
 calib/cal/SI_GATM_REF_CORR_H_025.fits              |  Bin 0 -> 8640 bytes
 calib/cal/SI_GATM_REF_CORR_H_100.fits              |  Bin 0 -> 8640 bytes
 calib/cal/SI_GATM_REF_CORR_J_025.fits              |  Bin 0 -> 8640 bytes
 calib/cal/SI_GATM_REF_CORR_J_100.fits              |  Bin 0 -> 8640 bytes
 calib/cal/SI_GATM_REF_CORR_K_025.fits              |  Bin 0 -> 8640 bytes
 calib/cal/SI_GATM_REF_CORR_K_100.fits              |  Bin 0 -> 8640 bytes
 calib/cal/SLIT_POS_HK_025.fits                     |    1 +
 calib/cal/SLIT_POS_HK_100.fits                     |    1 +
 calib/cal/SLIT_POS_HK_250.fits                     |    1 +
 calib/cal/SLIT_POS_HK_PUPIL.fits                   |    1 +
 calib/cal/SLIT_POS_H_025.fits                      |    1 +
 calib/cal/SLIT_POS_H_100.fits                      |    3 +
 calib/cal/SLIT_POS_H_250.fits                      |    2 +
 calib/cal/SLIT_POS_H_PUPIL.fits                    |    3 +
 calib/cal/SLIT_POS_J_025.fits                      |    4 +
 calib/cal/SLIT_POS_J_100.fits                      |    5 +
 calib/cal/SLIT_POS_J_250.fits                      |    4 +
 calib/cal/SLIT_POS_J_PUPIL.fits                    |    5 +
 calib/cal/SLIT_POS_K_025.fits                      |    3 +
 calib/cal/SLIT_POS_K_100.fits                      |    5 +
 calib/cal/SLIT_POS_K_250.fits                      |    4 +
 calib/cal/SLIT_POS_K_PUPIL.fits                    |    5 +
 calib/cal/argonJ.fits                              |  Bin 0 -> 8641 bytes
 calib/cal/atmoexan.fits                            |   15 +
 calib/cal/drs_setup_wave.fits                      |  Bin 0 -> 20160 bytes
 calib/cal/drs_setup_wave_oh.fits                   |  Bin 0 -> 20160 bytes
 calib/cal/neonK.fits                               |  Bin 0 -> 8641 bytes
 calib/cal/xenonHK.fits                             |  Bin 0 -> 8640 bytes
 calib/cal/xenonargonH.fits                         |  Bin 0 -> 14400 bytes
 calib/dic/ESO-DFS-DIC.SINFONI_QC                   | 1103 ++
 calib/dic/ESO-VLT-DIC.MACS_ICS                     | 2158 +++
 calib/dic/ESO-VLT-DIC.SPIF_ICS                     | 3777 +++++
 calib/gasgano/config/SINFO.prefs                   |   53 +
 calib/gasgano/config/SINFO.rul                     |  Bin 0 -> 12806 bytes
 calib/gasgano/config/sinfo.oca                     |  731 +
 config.h.in                                        |  137 +
 configure                                          |17365 ++++++++++++++++++++
 configure.ac                                       |  108 +
 doxygen/Doxyfile.in                                |  197 +
 html/doxygen.css                                   |  498 +
 html/doxygen.png                                   |  Bin 0 -> 1281 bytes
 html/files.html                                    |  395 +
 html/group__irplib__calib.html                     |  366 +
 html/group__irplib__cat.html                       |  252 +
 html/group__irplib__distortion.html                |   19 +
 html/group__irplib__flat.html                      |  122 +
 html/group__irplib__framelist.html                 | 1029 ++
 html/group__irplib__oddeven.html                   |  100 +
 html/group__irplib__plugin.html                    |   21 +
 html/group__irplib__polynomial.html                |  242 +
 html/group__irplib__ppm.html                       |  114 +
 html/group__irplib__slitpos.html                   |   80 +
 html/group__irplib__spectrum.html                  |  162 +
 html/group__irplib__stdstar.html                   |  604 +
 html/group__irplib__strehl.html                    |   19 +
 html/group__irplib__utils.html                     | 1359 ++
 html/group__irplib__wavecal.html                   |  988 ++
 html/group__irplib__wcs.html                       |   19 +
 html/group__irplib__wlxcorr.html                   |   21 +
 html/group__sinfo__absolute.html                   |   19 +
 html/group__sinfo__absolute__utils.html            |   20 +
 html/group__sinfo__bad__pix__search.html           |  151 +
 html/group__sinfo__balance.html                    |   20 +
 html/group__sinfo__baryvel.html                    |   21 +
 html/group__sinfo__boltzmann.html                  |  450 +
 html/group__sinfo__coltilt.html                    |   20 +
 html/group__sinfo__companion.html                  |   20 +
 html/group__sinfo__cube__construct.html            |   20 +
 html/group__sinfo__dark__cfg.html                  |   20 +
 html/group__sinfo__detlin.html                     |   20 +
 html/group__sinfo__dfs.html                        |   20 +
 html/group__sinfo__distortion.html                 |   19 +
 html/group__sinfo__dump.html                       |   20 +
 html/group__sinfo__error.html                      |  234 +
 html/group__sinfo__finddist__cfg.html              |   20 +
 html/group__sinfo__fit.html                        |   20 +
 html/group__sinfo__flat__cfg.html                  |   20 +
 html/group__sinfo__flat__ini__file.html            |   20 +
 html/group__sinfo__focus.html                      |   20 +
 html/group__sinfo__function__1d.html               |   20 +
 html/group__sinfo__globals.html                    |   20 +
 html/group__sinfo__image__ops.html                 |   20 +
 html/group__sinfo__img__noise.html                 |   19 +
 html/group__sinfo__lamp__cfg.html                  |   20 +
 html/group__sinfo__lamp__spec__config.html         |   20 +
 html/group__sinfo__msg.html                        |  551 +
 html/group__sinfo__new__bezier.html                |   20 +
 html/group__sinfo__new__cube__ops.html             |   20 +
 html/group__sinfo__new__resampling.html            |   20 +
 html/group__sinfo__new__slit__pos.html             |   20 +
 html/group__sinfo__pfits.html                      |   20 +
 html/group__sinfo__pro__save.html                  |   20 +
 html/group__sinfo__produc__config.html             |   20 +
 html/group__sinfo__qr__companion.html              |   20 +
 html/group__sinfo__rec__detlin.html                |   53 +
 html/group__sinfo__rec__distortion.html            |   55 +
 html/group__sinfo__rec__jitter.html                |   57 +
 html/group__sinfo__rec__lingain.html               |   19 +
 html/group__sinfo__rec__mdark.html                 |   55 +
 html/group__sinfo__rec__mflat.html                 |   55 +
 html/group__sinfo__rec__objnod.html                |   53 +
 html/group__sinfo__rec__psf.html                   |   53 +
 html/group__sinfo__rec__pupil.html                 |   53 +
 html/group__sinfo__rec__stdstar.html               |   53 +
 html/group__sinfo__rec__utils.html                 |   19 +
 html/group__sinfo__rec__wavecal.html               |   55 +
 html/group__sinfo__recipes.html                    |   20 +
 html/group__sinfo__remove__crh__single.html        |   20 +
 html/group__sinfo__shift__images.html              |   20 +
 html/group__sinfo__skycor__config.html             |   21 +
 html/group__sinfo__spectrum__ops.html              |   20 +
 html/group__sinfo__step__distortion.html           |   19 +
 html/group__sinfo__step__jitter.html               |   19 +
 html/group__sinfo__step__objnod.html               |   19 +
 html/group__sinfo__step__psf.html                  |   19 +
 html/group__sinfo__step__stdstar.html              |   19 +
 html/group__sinfo__tilt__cfg.html                  |   20 +
 html/group__sinfo__time.html                       |   20 +
 html/group__sinfo__tpl__dfs.html                   |   20 +
 html/group__sinfo__tpl__utils.html                 |   19 +
 html/group__sinfo__utilities.html                  |   20 +
 html/group__sinfo__utils.html                      |   20 +
 html/group__sinfo__utils__wrappers.html            |   20 +
 html/group__sinfo__utl__bp__mask__add.html         |   19 +
 html/group__sinfo__utl__cube2ima.html              |   55 +
 html/group__sinfo__utl__cube2spectrum.html         |   55 +
 html/group__sinfo__utl__cube__arith.html           |   55 +
 html/group__sinfo__utl__cube__combine.html         |   55 +
 html/group__sinfo__utl__cube__create.html          |   53 +
 html/group__sinfo__utl__cube__test.html            |   53 +
 html/group__sinfo__utl__eff.html                   |   53 +
 html/group__sinfo__utl__illumcorr.html             |   20 +
 html/group__sinfo__utl__ima__arith.html            |   53 +
 html/group__sinfo__utl__ima__cube__ks__test.html   |   53 +
 html/group__sinfo__utl__ima__gauss.html            |   53 +
 html/group__sinfo__utl__ima__line__corr.html       |   53 +
 html/group__sinfo__utl__remove__crh__single.html   |   53 +
 html/group__sinfo__utl__skycor.html                |   53 +
 html/group__sinfo__utl__skymap.html                |   53 +
 ...info__utl__spectrum__divide__by__blackbody.html |   55 +
 ...p__sinfo__utl__spectrum__wavelength__shift.html |   55 +
 html/group__sinfo__utl__stdstars.html              |   19 +
 html/group__sinfo__utl__table__ex.html             |   53 +
 html/group__sinfo__utl__table__test.html           |   19 +
 html/group__spiffi__general__config.html           |   20 +
 html/index.html                                    |   23 +
 html/irplib__calib_8c_source.html                  |  591 +
 html/irplib__calib_8h_source.html                  |   65 +
 html/irplib__cat_8c_source.html                    |  415 +
 html/irplib__cat_8h_source.html                    |   73 +
 html/irplib__distortion_8c_source.html             | 1267 ++
 html/irplib__distortion_8h_source.html             |   60 +
 html/irplib__flat_8c_source.html                   |  342 +
 html/irplib__flat_8h_source.html                   |   56 +
 html/irplib__framelist_8c_source.html              |  969 ++
 html/irplib__framelist_8h_source.html              |  123 +
 html/irplib__hist_8c_source.html                   |  366 +
 html/irplib__hist_8h_source.html                   |  109 +
 html/irplib__ksigma__clip_8c_source.html           |  223 +
 html/irplib__ksigma__clip_8h_source.html           |   68 +
 html/irplib__ksigma__clip__body_8h_source.html     |  123 +
 html/irplib__match__cats_8c_source.html            |  201 +
 html/irplib__match__cats_8h_source.html            |   62 +
 html/irplib__mkmaster_8c_source.html               |  483 +
 html/irplib__mkmaster_8h_source.html               |   69 +
 html/irplib__oddeven_8c_source.html                |  313 +
 html/irplib__oddeven_8h_source.html                |   56 +
 html/irplib__plugin_8c_source.html                 | 1040 ++
 html/irplib__plugin_8h_source.html                 |  109 +
 html/irplib__polynomial_8c_source.html             | 1251 ++
 html/irplib__polynomial_8h_source.html             |   86 +
 html/irplib__ppm_8c_source.html                    |  469 +
 html/irplib__ppm_8h_source.html                    |   56 +
 html/irplib__slitpos_8c_source.html                |  510 +
 html/irplib__slitpos_8h_source.html                |   55 +
 html/irplib__spectrum_8c_source.html               |  569 +
 html/irplib__spectrum_8h_source.html               |   75 +
 html/irplib__stdstar_8c_source.html                |  719 +
 html/irplib__stdstar_8h_source.html                |   94 +
 html/irplib__strehl_8c_source.html                 |  677 +
 html/irplib__strehl_8h_source.html                 |   91 +
 html/irplib__utils_8c_source.html                  | 1262 ++
 html/irplib__utils_8h_source.html                  |  433 +
 html/irplib__wavecal_8c_source.html                | 1460 ++
 html/irplib__wavecal_8h_source.html                |  200 +
 html/irplib__wavecal__impl_8h_source.html          |   72 +
 html/irplib__wcs_8c_source.html                    |  311 +
 html/irplib__wcs_8h_source.html                    |   82 +
 html/irplib__wlxcorr_8c_source.html                | 1084 ++
 html/irplib__wlxcorr_8h_source.html                |   89 +
 html/modules.html                                  |  122 +
 html/recipes_2sinfo__utl__cube2ima_8c_source.html  |  201 +
 ...cipes_2sinfo__utl__cube2spectrum_8c_source.html |  275 +
 ...recipes_2sinfo__utl__cube__arith_8c_source.html |  217 +
 ...cipes_2sinfo__utl__cube__combine_8c_source.html |  234 +
 ..._spectrum__divide__by__blackbody_8c_source.html |  192 +
 ...utl__spectrum__wavelength__shift_8c_source.html |  207 +
 html/sinfo__absolute_8c_source.html                | 3214 ++++
 html/sinfo__absolute_8h_source.html                |  155 +
 html/sinfo__atmo__disp_8c_source.html              |  344 +
 html/sinfo__atmo__disp_8h_source.html              |   86 +
 html/sinfo__bad__cfg_8c_source.html                |   71 +
 html/sinfo__bad__cfg_8h_source.html                |  127 +
 html/sinfo__bad__ini_8h_source.html                |   71 +
 html/sinfo__baddist__ini__by__cpl_8c_source.html   |  271 +
 html/sinfo__baddist__ini__by__cpl_8h_source.html   |   72 +
 html/sinfo__badnorm__ini__by__cpl_8c_source.html   |  295 +
 html/sinfo__badnorm__ini__by__cpl_8h_source.html   |   66 +
 html/sinfo__badsky__cfg_8c_source.html             |   69 +
 html/sinfo__badsky__cfg_8h_source.html             |  123 +
 html/sinfo__badsky__ini__by__cpl_8c_source.html    |  260 +
 html/sinfo__badsky__ini__by__cpl_8h_source.html    |   66 +
 html/sinfo__balance_8c_source.html                 |  146 +
 html/sinfo__baryvel_8c_source.html                 | 1041 ++
 html/sinfo__baryvel_8h_source.html                 |   77 +
 html/sinfo__boltzmann_8c_source.html               | 2292 +++
 html/sinfo__bp__config_8c_source.html              |   78 +
 html/sinfo__bp__config_8h_source.html              |   53 +
 html/sinfo__bp__dist__config_8c_source.html        |  270 +
 html/sinfo__bp__dist__config_8h_source.html        |   57 +
 html/sinfo__bp__lin_8c_source.html                 |  369 +
 html/sinfo__bp__lin_8h_source.html                 |   67 +
 html/sinfo__bp__lin__config_8c_source.html         |  145 +
 html/sinfo__bp__lin__config_8h_source.html         |   53 +
 html/sinfo__bp__noise_8c_source.html               |  151 +
 html/sinfo__bp__noise_8h_source.html               |   67 +
 html/sinfo__bp__noise__config_8c_source.html       |  114 +
 html/sinfo__bp__noise__config_8h_source.html       |   53 +
 html/sinfo__bp__norm_8c_source.html                |  363 +
 html/sinfo__bp__norm_8h_source.html                |   70 +
 html/sinfo__bp__norm__config_8c_source.html        |  271 +
 html/sinfo__bp__norm__config_8h_source.html        |   57 +
 html/sinfo__bp__sky__config_8c_source.html         |  281 +
 html/sinfo__bp__sky__config_8h_source.html         |   54 +
 html/sinfo__coltilt_8c_source.html                 | 1129 ++
 html/sinfo__coltilt_8h_source.html                 |  118 +
 html/sinfo__companion_8c_source.html               |   54 +
 html/sinfo__compare__tags_8h_source.html           |   44 +
 html/sinfo__cpl__size_8h_source.html               |   33 +
 html/sinfo__cube__construct_8c_source.html         | 3268 ++++
 html/sinfo__cube__construct_8h_source.html         |  152 +
 html/sinfo__cubecreate__ini_8h_source.html         |   61 +
 html/sinfo__dark__cfg_8c_source.html               |   69 +
 html/sinfo__dark__cfg_8h_source.html               |  109 +
 html/sinfo__dark__config_8c_source.html            |  215 +
 html/sinfo__dark__config_8h_source.html            |   52 +
 html/sinfo__dark__ini_8h_source.html               |   63 +
 html/sinfo__dark__ini__by__cpl_8c_source.html      |  259 +
 html/sinfo__dark__ini__by__cpl_8h_source.html      |   63 +
 html/sinfo__define__opt_8h_source.html             |   45 +
 html/sinfo__detlin_8c_source.html                  | 1126 ++
 html/sinfo__detlin_8h_source.html                  |  133 +
 html/sinfo__detlin__cfg_8c_source.html             |   67 +
 html/sinfo__detlin__cfg_8h_source.html             |  103 +
 html/sinfo__detlin__ini_8h_source.html             |   64 +
 html/sinfo__detlin__ini__by__cpl_8c_source.html    |  234 +
 html/sinfo__detlin__ini__by__cpl_8h_source.html    |   65 +
 html/sinfo__detnoise__cfg_8c_source.html           |   69 +
 html/sinfo__detnoise__cfg_8h_source.html           |   92 +
 html/sinfo__detnoise__ini_8h_source.html           |   67 +
 html/sinfo__detnoise__ini__by__cpl_8c_source.html  |  199 +
 html/sinfo__detnoise__ini__by__cpl_8h_source.html  |   66 +
 html/sinfo__dfs_8c_source.html                     | 4220 +++++
 html/sinfo__dfs_8h_source.html                     |   68 +
 html/sinfo__distortion_8c_source.html              | 1513 ++
 html/sinfo__distortion_8h_source.html              |   91 +
 html/sinfo__distortion__config_8c_source.html      |  553 +
 html/sinfo__distortion__config_8h_source.html      |   48 +
 html/sinfo__dump_8c_source.html                    |  377 +
 html/sinfo__dump_8h_source.html                    |  100 +
 html/sinfo__error_8h_source.html                   |  139 +
 html/sinfo__fft__base_8c_source.html               |  191 +
 html/sinfo__fft__base_8h_source.html               |   78 +
 html/sinfo__file__handling_8c_source.html          |   66 +
 html/sinfo__file__handling_8h_source.html          |   44 +
 html/sinfo__finddist__cfg_8c_source.html           |   68 +
 html/sinfo__finddist__cfg_8h_source.html           |  158 +
 html/sinfo__finddist__ini_8h_source.html           |   63 +
 html/sinfo__finddist__ini__by__cpl_8c_source.html  |  459 +
 html/sinfo__finddist__ini__by__cpl_8h_source.html  |   63 +
 html/sinfo__fit_8c_source.html                     |  388 +
 html/sinfo__fit_8h_source.html                     |   54 +
 html/sinfo__fit__curve_8c_source.html              |  146 +
 html/sinfo__fit__curve_8h_source.html              |   73 +
 html/sinfo__flat__cfg_8c_source.html               |   70 +
 html/sinfo__flat__cfg_8h_source.html               |  160 +
 html/sinfo__flat__ini_8c_source.html               |  562 +
 html/sinfo__flat__ini_8h_source.html               |   64 +
 html/sinfo__flat__ini__by__cpl_8c_source.html      |  468 +
 html/sinfo__flat__ini__by__cpl_8h_source.html      |   69 +
 html/sinfo__focus_8c_source.html                   | 1373 ++
 html/sinfo__focus_8h_source.html                   |  108 +
 html/sinfo__focus__cfg_8c_source.html              |   69 +
 html/sinfo__focus__cfg_8h_source.html              |  137 +
 ...fo__focus__determination__config_8c_source.html |  306 +
 ...fo__focus__determination__config_8h_source.html |   52 +
 html/sinfo__focus__ini_8h_source.html              |   65 +
 html/sinfo__focus__ini__by__cpl_8c_source.html     |  289 +
 html/sinfo__focus__ini__by__cpl_8h_source.html     |   63 +
 html/sinfo__function__1d_8c_source.html            |  724 +
 html/sinfo__function__1d_8h_source.html            |  154 +
 html/sinfo__functions_8h_source.html               |  289 +
 html/sinfo__general__config_8c_source.html         |  107 +
 html/sinfo__general__config_8h_source.html         |   53 +
 html/sinfo__globals_8c_source.html                 |  185 +
 html/sinfo__globals_8h_source.html                 |  196 +
 html/sinfo__hidden_8h_source.html                  |  128 +
 html/sinfo__image__ops_8c_source.html              | 3117 ++++
 html/sinfo__image__ops_8h_source.html              |  195 +
 html/sinfo__img__noise_8c_source.html              |  140 +
 html/sinfo__ipow_8c_source.html                    |   83 +
 html/sinfo__ipow_8h_source.html                    |   58 +
 html/sinfo__irplib__cpl__wrp_8h_source.html        |   70 +
 html/sinfo__key__names_8h_source.html              |  244 +
 html/sinfo__lamp__cfg_8c_source.html               |   69 +
 html/sinfo__lamp__cfg_8h_source.html               |   96 +
 html/sinfo__lamp__flats__config_8c_source.html     |  378 +
 html/sinfo__lamp__flats__config_8h_source.html     |   55 +
 ...nfo__lamp__flats__hidden__config_8c_source.html |   92 +
 ...nfo__lamp__flats__hidden__config_8h_source.html |   55 +
 html/sinfo__lamp__ini_8c_source.html               |  364 +
 html/sinfo__lamp__ini_8h_source.html               |   63 +
 html/sinfo__lamp__ini__by__cpl_8c_source.html      |  208 +
 html/sinfo__lamp__ini__by__cpl_8h_source.html      |   61 +
 html/sinfo__lamp__spec__config_8c_source.html      |  134 +
 html/sinfo__lamp__spec__config_8h_source.html      |   51 +
 html/sinfo__local__types_8h_source.html            |  147 +
 html/sinfo__matrix_8c_source.html                  |  329 +
 html/sinfo__matrix_8h_source.html                  |  123 +
 html/sinfo__median_8c_source.html                  |  247 +
 html/sinfo__median_8h_source.html                  |  103 +
 html/sinfo__merge_8c_source.html                   |  985 ++
 html/sinfo__merge_8h_source.html                   |   93 +
 html/sinfo__msg_8c_source.html                     |  247 +
 html/sinfo__msg_8h_source.html                     |  119 +
 html/sinfo__new__add__bp__map_8c_source.html       |  286 +
 html/sinfo__new__add__bp__map_8h_source.html       |   71 +
 html/sinfo__new__bezier_8c_source.html             | 1540 ++
 html/sinfo__new__bezier_8h_source.html             |  199 +
 html/sinfo__new__cube__ops_8c_source.html          | 5012 ++++++
 html/sinfo__new__cube__ops_8h_source.html          |  316 +
 html/sinfo__new__cubes__build_8c_source.html       |  929 ++
 html/sinfo__new__cubes__build_8h_source.html       |   91 +
 html/sinfo__new__cubes__coadd_8c_source.html       |  649 +
 html/sinfo__new__cubes__coadd_8h_source.html       |   86 +
 html/sinfo__new__dark_8c_source.html               |  725 +
 html/sinfo__new__dark_8h_source.html               |   80 +
 html/sinfo__new__find__distortions_8c_source.html  |  766 +
 html/sinfo__new__find__distortions_8h_source.html  |   81 +
 html/sinfo__new__lamp__flats_8c_source.html        | 1017 ++
 html/sinfo__new__lamp__flats_8h_source.html        |   93 +
 html/sinfo__new__nst_8c_source.html                |  398 +
 html/sinfo__new__nst_8h_source.html                |  103 +
 html/sinfo__new__objnod_8c_source.html             |  884 +
 html/sinfo__new__objnod_8h_source.html             |   86 +
 ...o__new__prepare__stacked__frames_8c_source.html | 1415 ++
 ...o__new__prepare__stacked__frames_8h_source.html |   97 +
 html/sinfo__new__psf_8c_source.html                | 2518 +++
 html/sinfo__new__psf_8h_source.html                |  171 +
 html/sinfo__new__resampling_8c_source.html         |  452 +
 html/sinfo__new__resampling_8h_source.html         |  135 +
 html/sinfo__new__slit__pos_8c_source.html          |  734 +
 html/sinfo__new__slit__pos_8h_source.html          |  146 +
 html/sinfo__new__stdstar_8c_source.html            |  668 +
 html/sinfo__new__stdstar_8h_source.html            |   84 +
 html/sinfo__new__wave__cal__slit2_8c_source.html   |  863 +
 html/sinfo__new__wave__cal__slit2_8h_source.html   |  149 +
 ...info__north__south__test__config_8c_source.html |  164 +
 ...info__north__south__test__config_8h_source.html |   50 +
 html/sinfo__ns__cfg_8c_source.html                 |   90 +
 html/sinfo__ns__cfg_8h_source.html                 |  120 +
 html/sinfo__ns__ini_8h_source.html                 |   67 +
 html/sinfo__ns__ini__by__cpl_8c_source.html        |  360 +
 html/sinfo__ns__ini__by__cpl_8h_source.html        |   67 +
 html/sinfo__object__cfg_8c_source.html             |   91 +
 html/sinfo__object__cfg_8h_source.html             |  162 +
 html/sinfo__object__ini_8h_source.html             |   63 +
 html/sinfo__objnod__config_8c_source.html          |  414 +
 html/sinfo__objnod__config_8h_source.html          |   48 +
 html/sinfo__objnod__ini__by__cpl_8c_source.html    |  421 +
 html/sinfo__objnod__ini__by__cpl_8h_source.html    |   65 +
 html/sinfo__objspider__config_8c_source.html       |  314 +
 html/sinfo__objspider__config_8h_source.html       |   49 +
 html/sinfo__objspider__ini__by__cpl_8c_source.html |  394 +
 html/sinfo__objspider__ini__by__cpl_8h_source.html |   63 +
 html/sinfo__pfits_8c_source.html                   |  743 +
 html/sinfo__pfits_8h_source.html                   |  143 +
 html/sinfo__pixel__handling_8c_source.html         |  136 +
 html/sinfo__pixel__handling_8h_source.html         |   61 +
 html/sinfo__poly2d_8c_source.html                  |   72 +
 html/sinfo__poly2d_8h_source.html                  |   90 +
 ...prepare__stacked__frames__config_8c_source.html |  359 +
 ...prepare__stacked__frames__config_8h_source.html |   49 +
 html/sinfo__pro__save_8c_source.html               | 1049 ++
 html/sinfo__pro__save_8h_source.html               |  228 +
 html/sinfo__pro__types_8h_source.html              |  207 +
 html/sinfo__product__config_8c_source.html         |   81 +
 html/sinfo__product__config_8h_source.html         |   53 +
 html/sinfo__psf__cfg_8c_source.html                |   88 +
 html/sinfo__psf__cfg_8h_source.html                |  108 +
 html/sinfo__psf__config_8c_source.html             |   74 +
 html/sinfo__psf__config_8h_source.html             |   48 +
 html/sinfo__psf__ini_8h_source.html                |   63 +
 html/sinfo__psf__ini__by__cpl_8c_source.html       |  205 +
 html/sinfo__psf__ini__by__cpl_8h_source.html       |   59 +
 html/sinfo__qr_8c_source.html                      |  277 +
 html/sinfo__raw__types_8h_source.html              |  129 +
 html/sinfo__rec__detlin_8c_source.html             |  268 +
 html/sinfo__rec__distortion_8c_source.html         |  828 +
 html/sinfo__rec__jitter_8c_source.html             |  366 +
 html/sinfo__rec__lingain_8c_source.html            |  183 +
 html/sinfo__rec__mdark_8c_source.html              |  424 +
 html/sinfo__rec__mdark__detmon_8c_source.html      |  103 +
 html/sinfo__rec__mflat_8c_source.html              |  296 +
 html/sinfo__rec__objnod_8c_source.html             |  299 +
 html/sinfo__rec__psf_8c_source.html                |  307 +
 html/sinfo__rec__pupil_8c_source.html              |  280 +
 html/sinfo__rec__stdstar_8c_source.html            |  316 +
 html/sinfo__rec__utils_8c_source.html              | 1381 ++
 html/sinfo__rec__utils_8h_source.html              |  124 +
 html/sinfo__rec__wavecal_8c_source.html            |  429 +
 html/sinfo__recipes_8c_source.html                 | 1257 ++
 html/sinfo__recipes_8h_source.html                 |  163 +
 html/sinfo__ref__types_8h_source.html              |   61 +
 html/sinfo__remove__crh__single_8c_source.html     |  483 +
 html/sinfo__remove__crh__single_8h_source.html     |   23 +
 html/sinfo__resampling_8c_source.html              |  289 +
 html/sinfo__resampling_8h_source.html              |  101 +
 html/sinfo__shift__images_8c_source.html           |  749 +
 html/sinfo__shift__images_8h_source.html           |   97 +
 html/sinfo__skycor_8c_source.html                  | 6541 ++++++++
 html/sinfo__skycor_8h_source.html                  |  123 +
 html/sinfo__skycor__config_8c_source.html          |  225 +
 html/sinfo__skycor__config_8h_source.html          |   53 +
 html/sinfo__solve__poly__root_8c_source.html       |  137 +
 html/sinfo__solve__poly__root_8h_source.html       |   93 +
 html/sinfo__spectrum__ops_8c_source.html           | 2420 +++
 html/sinfo__spectrum__ops_8h_source.html           |  210 +
 html/sinfo__spiffi__types_8h_source.html           |  168 +
 html/sinfo__stack__cfg_8c_source.html              |   75 +
 html/sinfo__stack__cfg_8h_source.html              |  179 +
 html/sinfo__stack__ini_8h_source.html              |   87 +
 html/sinfo__stack__ini__by__cpl_8c_source.html     |  644 +
 html/sinfo__stack__ini__by__cpl_8h_source.html     |   73 +
 html/sinfo__stacked__hidden__config_8c_source.html |   86 +
 html/sinfo__stacked__hidden__config_8h_source.html |   49 +
 html/sinfo__standard__star__config_8c_source.html  |  156 +
 html/sinfo__standard__star__config_8h_source.html  |   49 +
 html/sinfo__standstar__cfg_8c_source.html          |   92 +
 html/sinfo__standstar__cfg_8h_source.html          |  151 +
 html/sinfo__standstar__ini_8h_source.html          |   78 +
 html/sinfo__standstar__ini__by__cpl_8c_source.html |  248 +
 html/sinfo__standstar__ini__by__cpl_8h_source.html |   78 +
 html/sinfo__star__index_8c_source.html             |  338 +
 html/sinfo__star__index_8h_source.html             |   78 +
 html/sinfo__step__distortion_8c_source.html        |  318 +
 html/sinfo__step__jitter_8c_source.html            |  366 +
 html/sinfo__step__objnod_8c_source.html            |  183 +
 html/sinfo__step__psf_8c_source.html               |  197 +
 html/sinfo__step__stdstar_8c_source.html           |  282 +
 html/sinfo__svd_8c_source.html                     |  441 +
 html/sinfo__svd_8h_source.html                     |  100 +
 html/sinfo__tilt__cfg_8c_source.html               |   91 +
 html/sinfo__tilt__cfg_8h_source.html               |  105 +
 html/sinfo__tilt__ini_8h_source.html               |   68 +
 html/sinfo__time_8c_source.html                    |  201 +
 html/sinfo__time_8h_source.html                    |   53 +
 html/sinfo__tpl__dfs_8c_source.html                |  242 +
 html/sinfo__tpl__dfs_8h_source.html                |   90 +
 html/sinfo__tpl__utils_8c_source.html              |  160 +
 html/sinfo__tpl__utils_8h_source.html              |   81 +
 html/sinfo__utilities_8c_source.html               | 1075 ++
 html/sinfo__utilities_8h_source.html               |  230 +
 html/sinfo__utilities__scired_8c_source.html       | 1869 +++
 html/sinfo__utilities__scired_8h_source.html       |  162 +
 html/sinfo__utils_8c_source.html                   |  128 +
 html/sinfo__utils_8h_source.html                   |  115 +
 html/sinfo__utils__wrappers_8c_source.html         |  335 +
 html/sinfo__utils__wrappers_8h_source.html         |  100 +
 html/sinfo__utl__bp__mask__add_8c_source.html      |  252 +
 html/sinfo__utl__cube2ima_8h_source.html           |   58 +
 html/sinfo__utl__cube2spectrum_8h_source.html      |   60 +
 html/sinfo__utl__cube__arith_8h_source.html        |   59 +
 html/sinfo__utl__cube__combine_8h_source.html      |   59 +
 html/sinfo__utl__cube__create_8c_source.html       |  656 +
 html/sinfo__utl__cube__test_8c_source.html         |  257 +
 html/sinfo__utl__eff_8c_source.html                |  279 +
 html/sinfo__utl__efficiency_8c_source.html         |  675 +
 html/sinfo__utl__efficiency_8h_source.html         |  107 +
 html/sinfo__utl__illumcorr_8c_source.html          | 1945 +++
 html/sinfo__utl__ima__arith_8c_source.html         |  403 +
 .../sinfo__utl__ima__cube__ks__test_8c_source.html |  875 +
 html/sinfo__utl__ima__gauss_8c_source.html         |  435 +
 html/sinfo__utl__ima__line__corr_8c_source.html    |  321 +
 .../sinfo__utl__remove__crh__single_8c_source.html |  431 +
 html/sinfo__utl__seds_8c_source.html               |  284 +
 html/sinfo__utl__skycor_8c_source.html             |  339 +
 html/sinfo__utl__skymap_8c_source.html             |  421 +
 ..._spectrum__divide__by__blackbody_8h_source.html |   62 +
 ...utl__spectrum__wavelength__shift_8h_source.html |   61 +
 html/sinfo__utl__stdstars_8c_source.html           |  283 +
 html/sinfo__utl__table__ex_8c_source.html          |  331 +
 html/sinfo__utl__table__test_8c_source.html        | 1133 ++
 html/sinfo__vltPort_8h_source.html                 |  117 +
 html/sinfo__wave__calibration_8c_source.html       | 2638 +++
 html/sinfo__wave__calibration_8h_source.html       |  185 +
 html/sinfo__wavecal_8c_source.html                 | 3590 ++++
 html/sinfo__wavecal_8h_source.html                 |  170 +
 html/sinfo__wavecal__cfg_8c_source.html            |   89 +
 html/sinfo__wavecal__cfg_8h_source.html            |  173 +
 html/sinfo__wavecal__config_8c_source.html         |  434 +
 html/sinfo__wavecal__config_8h_source.html         |   48 +
 html/sinfo__wavecal__ini_8h_source.html            |   65 +
 html/sinfo__wavecal__ini__by__cpl_8c_source.html   |  540 +
 html/sinfo__wavecal__ini__by__cpl_8h_source.html   |   61 +
 html/sinfo__wcal__functions_8c_source.html         |  422 +
 html/sinfo__wcal__functions_8h_source.html         |   84 +
 html/sinfoni_2sinfo__utl__cube2ima_8c_source.html  |  246 +
 ...nfoni_2sinfo__utl__cube2spectrum_8c_source.html |  489 +
 ...sinfoni_2sinfo__utl__cube__arith_8c_source.html |  333 +
 ...nfoni_2sinfo__utl__cube__combine_8c_source.html |  381 +
 ..._spectrum__divide__by__blackbody_8c_source.html |  162 +
 ...utl__spectrum__wavelength__shift_8c_source.html |  190 +
 html/tab_b.gif                                     |  Bin 0 -> 35 bytes
 html/tab_l.gif                                     |  Bin 0 -> 706 bytes
 html/tab_r.gif                                     |  Bin 0 -> 2585 bytes
 html/tabs.css                                      |  105 +
 irplib/Makefile.am                                 |   87 +
 irplib/Makefile.in                                 |  799 +
 irplib/irplib_calib.c                              |  646 +
 irplib/irplib_calib.h                              |   49 +
 irplib/irplib_cat.c                                |  469 +
 irplib/irplib_cat.h                                |   57 +
 irplib/irplib_distortion.c                         | 1398 ++
 irplib/irplib_distortion.h                         |   44 +
 irplib/irplib_flat.c                               |  402 +
 irplib/irplib_flat.h                               |   40 +
 irplib/irplib_framelist.c                          | 1289 ++
 irplib/irplib_framelist.h                          |  107 +
 irplib/irplib_hist.c                               |  350 +
 irplib/irplib_hist.h                               |   93 +
 irplib/irplib_ksigma_clip.c                        |  258 +
 irplib/irplib_ksigma_clip.h                        |   52 +
 irplib/irplib_ksigma_clip_body.h                   |  107 +
 irplib/irplib_match_cats.c                         |  211 +
 irplib/irplib_match_cats.h                         |   46 +
 irplib/irplib_mkmaster.c                           |  565 +
 irplib/irplib_mkmaster.h                           |   53 +
 irplib/irplib_oddeven.c                            |  338 +
 irplib/irplib_oddeven.h                            |   40 +
 irplib/irplib_plugin.c                             | 1267 ++
 irplib/irplib_plugin.h                             |   93 +
 irplib/irplib_polynomial.c                         | 1486 ++
 irplib/irplib_polynomial.h                         |   70 +
 irplib/irplib_ppm.c                                |  494 +
 irplib/irplib_ppm.h                                |   40 +
 irplib/irplib_slitpos.c                            |  568 +
 irplib/irplib_slitpos.h                            |   39 +
 irplib/irplib_spectrum.c                           |  606 +
 irplib/irplib_spectrum.h                           |   59 +
 irplib/irplib_stdstar.c                            |  823 +
 irplib/irplib_stdstar.h                            |   78 +
 irplib/irplib_strehl.c                             |  806 +
 irplib/irplib_strehl.h                             |   75 +
 irplib/irplib_utils.c                              | 1659 ++
 irplib/irplib_utils.h                              |  464 +
 irplib/irplib_wavecal.c                            | 1646 ++
 irplib/irplib_wavecal.h                            |  184 +
 irplib/irplib_wavecal_impl.h                       |   56 +
 irplib/irplib_wcs.c                                |  391 +
 irplib/irplib_wcs.h                                |   66 +
 irplib/irplib_wlxcorr.c                            | 1261 ++
 irplib/irplib_wlxcorr.h                            |   73 +
 irplib/tests/Makefile.am                           |   90 +
 irplib/tests/Makefile.in                           |  766 +
 irplib/tests/irplib_cat-test.c                     |   98 +
 irplib/tests/irplib_framelist-test.c               |   98 +
 irplib/tests/irplib_hist-test.c                    |  150 +
 irplib/tests/irplib_plugin-test.c                  |  129 +
 irplib/tests/irplib_polynomial-test.c              |  582 +
 irplib/tests/irplib_utils-test.c                   |  331 +
 irplib/tests/irplib_wcs-test.c                     |  307 +
 irplib/tests/irplib_wlxcorr-test.c                 |  483 +
 m4macros/cpl.m4                                    | 1499 ++
 m4macros/eso.m4                                    | 1065 ++
 m4macros/libtool.m4                                | 7360 +++++++++
 m4macros/ltoptions.m4                              |  368 +
 m4macros/ltsugar.m4                                |  123 +
 m4macros/ltversion.m4                              |   23 +
 m4macros/lt~obsolete.m4                            |   92 +
 m4macros/purify.m4                                 |   28 +
 recipes/Makefile.am                                |  278 +
 recipes/Makefile.in                                | 1158 ++
 recipes/sinfo_rec_detlin.c                         |  303 +
 recipes/sinfo_rec_distortion.c                     |  848 +
 recipes/sinfo_rec_jitter.c                         |  386 +
 recipes/sinfo_rec_mdark.c                          |  444 +
 recipes/sinfo_rec_mflat.c                          |  318 +
 recipes/sinfo_rec_pupil.c                          |  300 +
 recipes/sinfo_rec_wavecal.c                        |  449 +
 recipes/sinfo_utl_bp_mask_add.c                    |  271 +
 recipes/sinfo_utl_cube2ima.c                       |  215 +
 recipes/sinfo_utl_cube2spectrum.c                  |  289 +
 recipes/sinfo_utl_cube_arith.c                     |  231 +
 recipes/sinfo_utl_cube_combine.c                   |  248 +
 recipes/sinfo_utl_cube_create.c                    |  676 +
 recipes/sinfo_utl_eff.c                            |  299 +
 recipes/sinfo_utl_ima_arith.c                      |  423 +
 recipes/sinfo_utl_ima_line_corr.c                  |  341 +
 recipes/sinfo_utl_skycor.c                         |  359 +
 recipes/sinfo_utl_skymap.c                         |  435 +
 recipes/sinfo_utl_spectrum_divide_by_blackbody.c   |  208 +
 recipes/sinfo_utl_spectrum_wavelength_shift.c      |  223 +
 recipes/tests/Makefile.am                          |  172 +
 recipes/tests/Makefile.in                          |  770 +
 recipes/tests/README                               |    9 +
 recipes/tests/recipe_main.c                        |  279 +
 regtests/Makefile.am                               |   30 +
 regtests/Makefile.in                               |  604 +
 regtests/tests/Makefile.am                         |   61 +
 regtests/tests/Makefile.in                         |  425 +
 setup                                              |   77 +
 sinfoni/Makefile.am                                |  337 +
 sinfoni/Makefile.in                                | 1231 ++
 sinfoni/sinfo_absolute.c                           | 3638 ++++
 sinfoni/sinfo_absolute.h                           |  432 +
 sinfoni/sinfo_atmo_disp.c                          |  328 +
 sinfoni/sinfo_atmo_disp.h                          |   70 +
 sinfoni/sinfo_bad_cfg.c                            |   78 +
 sinfoni/sinfo_bad_cfg.h                            |  124 +
 sinfoni/sinfo_bad_ini.h                            |   75 +
 sinfoni/sinfo_baddist_ini_by_cpl.c                 |  302 +
 sinfoni/sinfo_baddist_ini_by_cpl.h                 |   75 +
 sinfoni/sinfo_badnorm_ini_by_cpl.c                 |  337 +
 sinfoni/sinfo_badnorm_ini_by_cpl.h                 |   66 +
 sinfoni/sinfo_badsky_cfg.c                         |   77 +
 sinfoni/sinfo_badsky_cfg.h                         |  120 +
 sinfoni/sinfo_badsky_ini_by_cpl.c                  |  295 +
 sinfoni/sinfo_badsky_ini_by_cpl.h                  |   50 +
 sinfoni/sinfo_balance.c                            |  145 +
 sinfoni/sinfo_baryvel.c                            | 1110 ++
 sinfoni/sinfo_baryvel.h                            |   61 +
 sinfoni/sinfo_boltzmann.c                          | 2513 +++
 sinfoni/sinfo_bp_config.c                          |   81 +
 sinfoni/sinfo_bp_config.h                          |   37 +
 sinfoni/sinfo_bp_dist_config.c                     |  273 +
 sinfoni/sinfo_bp_dist_config.h                     |   41 +
 sinfoni/sinfo_bp_lin.c                             |  385 +
 sinfoni/sinfo_bp_lin.h                             |   59 +
 sinfoni/sinfo_bp_lin_config.c                      |  148 +
 sinfoni/sinfo_bp_lin_config.h                      |   37 +
 sinfoni/sinfo_bp_noise.c                           |  158 +
 sinfoni/sinfo_bp_noise.h                           |   51 +
 sinfoni/sinfo_bp_noise_config.c                    |  117 +
 sinfoni/sinfo_bp_noise_config.h                    |   37 +
 sinfoni/sinfo_bp_norm.c                            |  392 +
 sinfoni/sinfo_bp_norm.h                            |   54 +
 sinfoni/sinfo_bp_norm_config.c                     |  274 +
 sinfoni/sinfo_bp_norm_config.h                     |   41 +
 sinfoni/sinfo_bp_sky_config.c                      |  284 +
 sinfoni/sinfo_bp_sky_config.h                      |   38 +
 sinfoni/sinfo_coltilt.c                            | 1200 ++
 sinfoni/sinfo_coltilt.h                            |  162 +
 sinfoni/sinfo_companion.c                          |   54 +
 sinfoni/sinfo_cpl_size.h                           |   17 +
 sinfoni/sinfo_cube_construct.c                     | 3572 ++++
 sinfoni/sinfo_cube_construct.h                     |  406 +
 sinfoni/sinfo_dark_cfg.c                           |   77 +
 sinfoni/sinfo_dark_cfg.h                           |  106 +
 sinfoni/sinfo_dark_config.c                        |  218 +
 sinfoni/sinfo_dark_config.h                        |   36 +
 sinfoni/sinfo_dark_ini.h                           |   68 +
 sinfoni/sinfo_dark_ini_by_cpl.c                    |  294 +
 sinfoni/sinfo_dark_ini_by_cpl.h                    |   65 +
 sinfoni/sinfo_define_opt.h                         |   29 +
 sinfoni/sinfo_detlin.c                             | 1217 ++
 sinfoni/sinfo_detlin.h                             |  217 +
 sinfoni/sinfo_detlin_cfg.c                         |   73 +
 sinfoni/sinfo_detlin_cfg.h                         |  100 +
 sinfoni/sinfo_detlin_ini.h                         |   67 +
 sinfoni/sinfo_detlin_ini_by_cpl.c                  |  263 +
 sinfoni/sinfo_detlin_ini_by_cpl.h                  |   66 +
 sinfoni/sinfo_detnoise_cfg.c                       |   75 +
 sinfoni/sinfo_detnoise_cfg.h                       |   89 +
 sinfoni/sinfo_detnoise_ini.h                       |   70 +
 sinfoni/sinfo_detnoise_ini_by_cpl.c                |  226 +
 sinfoni/sinfo_detnoise_ini_by_cpl.h                |   67 +
 sinfoni/sinfo_dfs.c                                | 4739 ++++++
 sinfoni/sinfo_dfs.h                                |   52 +
 sinfoni/sinfo_distortion.c                         | 1605 ++
 sinfoni/sinfo_distortion.h                         |   75 +
 sinfoni/sinfo_distortion_config.c                  |  542 +
 sinfoni/sinfo_distortion_config.h                  |   32 +
 sinfoni/sinfo_dump.c                               |  422 +
 sinfoni/sinfo_dump.h                               |   84 +
 sinfoni/sinfo_error.h                              |  410 +
 sinfoni/sinfo_fft_base.c                           |  242 +
 sinfoni/sinfo_fft_base.h                           |  118 +
 sinfoni/sinfo_file_handling.c                      |   68 +
 sinfoni/sinfo_file_handling.h                      |   38 +
 sinfoni/sinfo_finddist_cfg.c                       |   76 +
 sinfoni/sinfo_finddist_cfg.h                       |  155 +
 sinfoni/sinfo_finddist_ini.h                       |   71 +
 sinfoni/sinfo_finddist_ini_by_cpl.c                |  523 +
 sinfoni/sinfo_finddist_ini_by_cpl.h                |   64 +
 sinfoni/sinfo_fit.c                                |  395 +
 sinfoni/sinfo_fit.h                                |   38 +
 sinfoni/sinfo_fit_curve.c                          |  161 +
 sinfoni/sinfo_fit_curve.h                          |   78 +
 sinfoni/sinfo_flat_cfg.c                           |   80 +
 sinfoni/sinfo_flat_cfg.h                           |  158 +
 sinfoni/sinfo_flat_ini.h                           |   57 +
 sinfoni/sinfo_flat_ini_by_cpl.c                    |  531 +
 sinfoni/sinfo_flat_ini_by_cpl.h                    |   71 +
 sinfoni/sinfo_focus.c                              | 1578 ++
 sinfoni/sinfo_focus.h                              |  238 +
 sinfoni/sinfo_focus_cfg.c                          |   77 +
 sinfoni/sinfo_focus_cfg.h                          |  134 +
 sinfoni/sinfo_focus_determination_config.c         |  299 +
 sinfoni/sinfo_focus_determination_config.h         |   36 +
 sinfoni/sinfo_focus_ini.h                          |   72 +
 sinfoni/sinfo_focus_ini_by_cpl.c                   |  326 +
 sinfoni/sinfo_focus_ini_by_cpl.h                   |   65 +
 sinfoni/sinfo_function_1d.c                        |  995 ++
 sinfoni/sinfo_function_1d.h                        |  383 +
 sinfoni/sinfo_functions.h                          |  273 +
 sinfoni/sinfo_general_config.c                     |  110 +
 sinfoni/sinfo_general_config.h                     |   37 +
 sinfoni/sinfo_globals.c                            |  251 +
 sinfoni/sinfo_globals.h                            |  180 +
 sinfoni/sinfo_hidden.h                             |  112 +
 sinfoni/sinfo_image_ops.c                          | 3516 ++++
 sinfoni/sinfo_image_ops.h                          |  451 +
 sinfoni/sinfo_ipow.c                               |   89 +
 sinfoni/sinfo_ipow.h                               |   56 +
 sinfoni/sinfo_key_names.h                          |  228 +
 sinfoni/sinfo_lamp_cfg.c                           |   76 +
 sinfoni/sinfo_lamp_cfg.h                           |   94 +
 sinfoni/sinfo_lamp_flats_config.c                  |  370 +
 sinfoni/sinfo_lamp_flats_config.h                  |   39 +
 sinfoni/sinfo_lamp_ini.h                           |   68 +
 sinfoni/sinfo_lamp_ini_by_cpl.c                    |  240 +
 sinfoni/sinfo_lamp_ini_by_cpl.h                    |   61 +
 sinfoni/sinfo_lamp_spec_config.c                   |  126 +
 sinfoni/sinfo_lamp_spec_config.h                   |   35 +
 sinfoni/sinfo_local_types.h                        |  131 +
 sinfoni/sinfo_matrix.c                             |  424 +
 sinfoni/sinfo_matrix.h                             |  203 +
 sinfoni/sinfo_median.c                             |  374 +
 sinfoni/sinfo_median.h                             |  221 +
 sinfoni/sinfo_merge.c                              | 1048 ++
 sinfoni/sinfo_merge.h                              |  142 +
 sinfoni/sinfo_msg.c                                |  327 +
 sinfoni/sinfo_msg.h                                |  145 +
 sinfoni/sinfo_new_add_bp_map.c                     |  288 +
 sinfoni/sinfo_new_add_bp_map.h                     |   64 +
 sinfoni/sinfo_new_bezier.c                         | 1632 ++
 sinfoni/sinfo_new_bezier.h                         |  184 +
 sinfoni/sinfo_new_cube_ops.c                       | 5365 ++++++
 sinfoni/sinfo_new_cube_ops.h                       |  864 +
 sinfoni/sinfo_new_cubes_build.c                    |  922 ++
 sinfoni/sinfo_new_cubes_build.h                    |   76 +
 sinfoni/sinfo_new_cubes_coadd.c                    |  642 +
 sinfoni/sinfo_new_cubes_coadd.h                    |   71 +
 sinfoni/sinfo_new_dark.c                           |  731 +
 sinfoni/sinfo_new_dark.h                           |   64 +
 sinfoni/sinfo_new_find_distortions.c               |  759 +
 sinfoni/sinfo_new_find_distortions.h               |   65 +
 sinfoni/sinfo_new_lamp_flats.c                     | 1009 ++
 sinfoni/sinfo_new_lamp_flats.h                     |   77 +
 sinfoni/sinfo_new_nst.c                            |  392 +
 sinfoni/sinfo_new_nst.h                            |   87 +
 sinfoni/sinfo_new_objnod.c                         |  877 +
 sinfoni/sinfo_new_objnod.h                         |   71 +
 sinfoni/sinfo_new_prepare_stacked_frames.c         | 1409 ++
 sinfoni/sinfo_new_prepare_stacked_frames.h         |   81 +
 sinfoni/sinfo_new_psf.c                            | 2592 +++
 sinfoni/sinfo_new_psf.h                            |  155 +
 sinfoni/sinfo_new_resampling.c                     |  556 +
 sinfoni/sinfo_new_resampling.h                     |  209 +
 sinfoni/sinfo_new_slit_pos.c                       |  727 +
 sinfoni/sinfo_new_slit_pos.h                       |  130 +
 sinfoni/sinfo_new_stdstar.c                        |  660 +
 sinfoni/sinfo_new_stdstar.h                        |   69 +
 sinfoni/sinfo_new_wave_cal_slit2.c                 |  910 +
 sinfoni/sinfo_new_wave_cal_slit2.h                 |  133 +
 sinfoni/sinfo_north_south_test_config.c            |  162 +
 sinfoni/sinfo_north_south_test_config.h            |   34 +
 sinfoni/sinfo_ns_cfg.c                             |   84 +
 sinfoni/sinfo_ns_cfg.h                             |  118 +
 sinfoni/sinfo_ns_ini.h                             |   76 +
 sinfoni/sinfo_ns_ini_by_cpl.c                      |  364 +
 sinfoni/sinfo_ns_ini_by_cpl.h                      |   69 +
 sinfoni/sinfo_object_cfg.c                         |   85 +
 sinfoni/sinfo_object_cfg.h                         |  159 +
 sinfoni/sinfo_object_ini.h                         |   75 +
 sinfoni/sinfo_objnod_config.c                      |  411 +
 sinfoni/sinfo_objnod_config.h                      |   32 +
 sinfoni/sinfo_objnod_ini_by_cpl.c                  |  425 +
 sinfoni/sinfo_objnod_ini_by_cpl.h                  |   68 +
 sinfoni/sinfo_objspider_config.c                   |  313 +
 sinfoni/sinfo_objspider_config.h                   |   33 +
 sinfoni/sinfo_objspider_ini_by_cpl.c               |  397 +
 sinfoni/sinfo_objspider_ini_by_cpl.h               |   67 +
 sinfoni/sinfo_pfits.c                              | 1076 ++
 sinfoni/sinfo_pfits.h                              |  127 +
 sinfoni/sinfo_pixel_handling.c                     |  141 +
 sinfoni/sinfo_pixel_handling.h                     |   57 +
 sinfoni/sinfo_poly2d.c                             |   82 +
 sinfoni/sinfo_poly2d.h                             |  129 +
 sinfoni/sinfo_prepare_stacked_frames_config.c      |  357 +
 sinfoni/sinfo_prepare_stacked_frames_config.h      |   33 +
 sinfoni/sinfo_pro_save.c                           | 1145 ++
 sinfoni/sinfo_pro_save.h                           |  327 +
 sinfoni/sinfo_pro_types.h                          |  191 +
 sinfoni/sinfo_product_config.c                     |   84 +
 sinfoni/sinfo_product_config.h                     |   37 +
 sinfoni/sinfo_psf_cfg.c                            |   82 +
 sinfoni/sinfo_psf_cfg.h                            |  105 +
 sinfoni/sinfo_psf_config.c                         |   73 +
 sinfoni/sinfo_psf_config.h                         |   32 +
 sinfoni/sinfo_psf_ini.h                            |   76 +
 sinfoni/sinfo_psf_ini_by_cpl.c                     |  208 +
 sinfoni/sinfo_psf_ini_by_cpl.h                     |   63 +
 sinfoni/sinfo_qr.c                                 |  270 +
 sinfoni/sinfo_raw_types.h                          |  113 +
 sinfoni/sinfo_rec_utils.c                          | 1370 ++
 sinfoni/sinfo_rec_utils.h                          |  108 +
 sinfoni/sinfo_recipes.c                            | 1516 ++
 sinfoni/sinfo_recipes.h                            |  303 +
 sinfoni/sinfo_ref_types.h                          |   45 +
 sinfoni/sinfo_remove_crh_single.c                  |  497 +
 sinfoni/sinfo_remove_crh_single.h                  |    7 +
 sinfoni/sinfo_resampling.c                         |  388 +
 sinfoni/sinfo_resampling.h                         |  157 +
 sinfoni/sinfo_shift_images.c                       |  790 +
 sinfoni/sinfo_shift_images.h                       |  135 +
 sinfoni/sinfo_skycor.c                             | 7234 ++++++++
 sinfoni/sinfo_skycor.h                             |  107 +
 sinfoni/sinfo_skycor_config.c                      |  229 +
 sinfoni/sinfo_skycor_config.h                      |   37 +
 sinfoni/sinfo_solve_poly_root.c                    |  131 +
 sinfoni/sinfo_solve_poly_root.h                    |   77 +
 sinfoni/sinfo_spectrum_ops.c                       | 2674 +++
 sinfoni/sinfo_spectrum_ops.h                       |  476 +
 sinfoni/sinfo_spiffi_types.h                       |  153 +
 sinfoni/sinfo_stack_cfg.c                          |   85 +
 sinfoni/sinfo_stack_cfg.h                          |  176 +
 sinfoni/sinfo_stack_ini.h                          |   95 +
 sinfoni/sinfo_stack_ini_by_cpl.c                   |  712 +
 sinfoni/sinfo_stack_ini_by_cpl.h                   |   69 +
 sinfoni/sinfo_stacked_hidden_config.c              |   83 +
 sinfoni/sinfo_stacked_hidden_config.h              |   33 +
 sinfoni/sinfo_standard_star_config.c               |  154 +
 sinfoni/sinfo_standard_star_config.h               |   33 +
 sinfoni/sinfo_standstar_cfg.c                      |   86 +
 sinfoni/sinfo_standstar_cfg.h                      |  135 +
 sinfoni/sinfo_standstar_ini.h                      |   88 +
 sinfoni/sinfo_standstar_ini_by_cpl.c               |  252 +
 sinfoni/sinfo_standstar_ini_by_cpl.h               |   72 +
 sinfoni/sinfo_star_index.c                         |  325 +
 sinfoni/sinfo_star_index.h                         |   62 +
 sinfoni/sinfo_svd.c                                |  433 +
 sinfoni/sinfo_svd.h                                |   85 +
 sinfoni/sinfo_tilt_cfg.c                           |   84 +
 sinfoni/sinfo_tilt_cfg.h                           |  103 +
 sinfoni/sinfo_tilt_ini.h                           |   78 +
 sinfoni/sinfo_time.c                               |  244 +
 sinfoni/sinfo_time.h                               |   37 +
 sinfoni/sinfo_tpl_dfs.c                            |  247 +
 sinfoni/sinfo_tpl_dfs.h                            |   74 +
 sinfoni/sinfo_tpl_utils.c                          |  175 +
 sinfoni/sinfo_tpl_utils.h                          |   65 +
 sinfoni/sinfo_utilities.c                          | 1152 ++
 sinfoni/sinfo_utilities.h                          |  214 +
 sinfoni/sinfo_utilities_scired.c                   | 2165 +++
 sinfoni/sinfo_utilities_scired.h                   |  146 +
 sinfoni/sinfo_utils.c                              |  139 +
 sinfoni/sinfo_utils.h                              |   99 +
 sinfoni/sinfo_utils_wrappers.c                     |  496 +
 sinfoni/sinfo_utils_wrappers.h                     |   84 +
 sinfoni/sinfo_utl_cube2ima.c                       |  244 +
 sinfoni/sinfo_utl_cube2ima.h                       |   42 +
 sinfoni/sinfo_utl_cube2spectrum.c                  |  488 +
 sinfoni/sinfo_utl_cube2spectrum.h                  |   44 +
 sinfoni/sinfo_utl_cube_arith.c                     |  331 +
 sinfoni/sinfo_utl_cube_arith.h                     |   43 +
 sinfoni/sinfo_utl_cube_combine.c                   |  381 +
 sinfoni/sinfo_utl_cube_combine.h                   |   43 +
 sinfoni/sinfo_utl_efficiency.c                     |  734 +
 sinfoni/sinfo_utl_efficiency.h                     |   91 +
 sinfoni/sinfo_utl_spectrum_divide_by_blackbody.c   |  161 +
 sinfoni/sinfo_utl_spectrum_divide_by_blackbody.h   |   46 +
 sinfoni/sinfo_utl_spectrum_wavelength_shift.c      |  189 +
 sinfoni/sinfo_utl_spectrum_wavelength_shift.h      |   45 +
 sinfoni/sinfo_vltPort.h                            |  101 +
 sinfoni/sinfo_wave_calibration.c                   | 2919 ++++
 sinfoni/sinfo_wave_calibration.h                   |  450 +
 sinfoni/sinfo_wavecal.c                            | 3889 +++++
 sinfoni/sinfo_wavecal.h                            |  375 +
 sinfoni/sinfo_wavecal_cfg.c                        |   84 +
 sinfoni/sinfo_wavecal_cfg.h                        |  171 +
 sinfoni/sinfo_wavecal_config.c                     |  428 +
 sinfoni/sinfo_wavecal_config.h                     |   32 +
 sinfoni/sinfo_wavecal_ini.h                        |   78 +
 sinfoni/sinfo_wavecal_ini_by_cpl.c                 |  560 +
 sinfoni/sinfo_wavecal_ini_by_cpl.h                 |   64 +
 sinfoni/sinfo_wcal_functions.c                     |  414 +
 sinfoni/sinfo_wcal_functions.h                     |   68 +
 sinfoni/tests/Makefile.am                          |   84 +
 sinfoni/tests/Makefile.in                          |  777 +
 sinfoni/tests/sinfo_cube_coadd_test.c              |  622 +
 sinfoni/tests/sinfo_cube_ops_test.c                |  153 +
 sinfoni/tests/sinfo_efficiency_test.c              |  313 +
 sinfoni/tests/sinfo_gauss_fit_test.c               |   98 +
 sinfoni/tests/sinfo_image_ops_test.c               |  205 +
 sinfoni/tests/sinfo_kappa_sigma_test.c             |  745 +
 sinfoni/tests/sinfo_line_corr_test.c               |  106 +
 sinfoni/tests/sinfo_skycor_test.c                  |   87 +
 sinfoni/tests/sinfo_star_catalog.c                 |  303 +
 sinfoni/tests/sinfo_star_index_test.c              |  174 +
 sinfoni/tests/sinfo_strehl_test.c                  | 1155 ++
 sinfoni/tests/sinfo_table_ops_test.c               |  173 +
 sinfoni/tests/test_atmo_disp.c                     | 1080 ++
 946 files changed, 355517 insertions(+)

diff --git a/AUTHORS b/AUTHORS
new file mode 100644
index 0000000..49c6e1a
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1,5 @@
+This package is maintained by
+
+    Andrea Modigliani <amodigli at eso.org>
+
+on behalf of the European Southern Observatory (ESO).
diff --git a/COPYING b/COPYING
new file mode 100644
index 0000000..d60c31a
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,340 @@
+		    GNU GENERAL PUBLIC LICENSE
+		       Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+     59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+			    Preamble
+
+  The licenses for most software are designed to take away your
+freedom to share and change it.  By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users.  This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it.  (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.)  You can apply it to
+your programs, too.
+
+  When we speak of free software, we are referring to freedom, not
+price.  Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+  To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+  For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have.  You must make sure that they, too, receive or can get the
+source code.  And you must show them these terms so they know their
+rights.
+
+  We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+  Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software.  If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+  Finally, any free program is threatened constantly by software
+patents.  We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary.  To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.
+

+		    GNU GENERAL PUBLIC LICENSE
+   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+  0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License.  The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language.  (Hereinafter, translation is included without limitation in
+the term "modification".)  Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope.  The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+  1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+  2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+    a) You must cause the modified files to carry prominent notices
+    stating that you changed the files and the date of any change.
+
+    b) You must cause any work that you distribute or publish, that in
+    whole or in part contains or is derived from the Program or any
+    part thereof, to be licensed as a whole at no charge to all third
+    parties under the terms of this License.
+
+    c) If the modified program normally reads commands interactively
+    when run, you must cause it, when started running for such
+    interactive use in the most ordinary way, to print or display an
+    announcement including an appropriate copyright notice and a
+    notice that there is no warranty (or else, saying that you provide
+    a warranty) and that users may redistribute the program under
+    these conditions, and telling the user how to view a copy of this
+    License.  (Exception: if the Program itself is interactive but
+    does not normally print such an announcement, your work based on
+    the Program is not required to print an announcement.)
+

+These requirements apply to the modified work as a whole.  If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works.  But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+  3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+    a) Accompany it with the complete corresponding machine-readable
+    source code, which must be distributed under the terms of Sections
+    1 and 2 above on a medium customarily used for software interchange; or,
+
+    b) Accompany it with a written offer, valid for at least three
+    years, to give any third party, for a charge no more than your
+    cost of physically performing source distribution, a complete
+    machine-readable copy of the corresponding source code, to be
+    distributed under the terms of Sections 1 and 2 above on a medium
+    customarily used for software interchange; or,
+
+    c) Accompany it with the information you received as to the offer
+    to distribute corresponding source code.  (This alternative is
+    allowed only for noncommercial distribution and only if you
+    received the program in object code or executable form with such
+    an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it.  For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable.  However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+

+  4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License.  Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+  5. You are not required to accept this License, since you have not
+signed it.  However, nothing else grants you permission to modify or
+distribute the Program or its derivative works.  These actions are
+prohibited by law if you do not accept this License.  Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+  6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions.  You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+  7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all.  For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices.  Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+

+  8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded.  In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+  9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time.  Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number.  If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation.  If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+  10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission.  For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this.  Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+			    NO WARRANTY
+
+  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+		     END OF TERMS AND CONDITIONS
+

+	    How to Apply These Terms to Your New Programs
+
+  If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+  To do so, attach the following notices to the program.  It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+    <one line to give the program's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+    Gnomovision version 69, Copyright (C) year  name of author
+    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+    This is free software, and you are welcome to redistribute it
+    under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License.  Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary.  Here is a sample; alter the names:
+
+  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+  `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+  <signature of Ty Coon>, 1 April 1989
+  Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs.  If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library.  If this is what you want to do, use the GNU Library General
+Public License instead of this License.
diff --git a/COPYING.LIB b/COPYING.LIB
new file mode 100644
index 0000000..c4792dd
--- /dev/null
+++ b/COPYING.LIB
@@ -0,0 +1,515 @@
+
+                  GNU LESSER GENERAL PUBLIC LICENSE
+                       Version 2.1, February 1999
+
+ Copyright (C) 1991, 1999 Free Software Foundation, Inc.
+     59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+[This is the first released version of the Lesser GPL.  It also counts
+ as the successor of the GNU Library Public License, version 2, hence
+ the version number 2.1.]
+
+                            Preamble
+
+  The licenses for most software are designed to take away your
+freedom to share and change it.  By contrast, the GNU General Public
+Licenses are intended to guarantee your freedom to share and change
+free software--to make sure the software is free for all its users.
+
+  This license, the Lesser General Public License, applies to some
+specially designated software packages--typically libraries--of the
+Free Software Foundation and other authors who decide to use it.  You
+can use it too, but we suggest you first think carefully about whether
+this license or the ordinary General Public License is the better
+strategy to use in any particular case, based on the explanations
+below.
+
+  When we speak of free software, we are referring to freedom of use,
+not price.  Our General Public Licenses are designed to make sure that
+you have the freedom to distribute copies of free software (and charge
+for this service if you wish); that you receive source code or can get
+it if you want it; that you can change the software and use pieces of
+it in new free programs; and that you are informed that you can do
+these things.
+
+  To protect your rights, we need to make restrictions that forbid
+distributors to deny you these rights or to ask you to surrender these
+rights.  These restrictions translate to certain responsibilities for
+you if you distribute copies of the library or if you modify it.
+
+  For example, if you distribute copies of the library, whether gratis
+or for a fee, you must give the recipients all the rights that we gave
+you.  You must make sure that they, too, receive or can get the source
+code.  If you link other code with the library, you must provide
+complete object files to the recipients, so that they can relink them
+with the library after making changes to the library and recompiling
+it.  And you must show them these terms so they know their rights.
+
+  We protect your rights with a two-step method: (1) we copyright the
+library, and (2) we offer you this license, which gives you legal
+permission to copy, distribute and/or modify the library.
+
+  To protect each distributor, we want to make it very clear that
+there is no warranty for the free library.  Also, if the library is
+modified by someone else and passed on, the recipients should know
+that what they have is not the original version, so that the original
+author's reputation will not be affected by problems that might be
+introduced by others.
+^L
+  Finally, software patents pose a constant threat to the existence of
+any free program.  We wish to make sure that a company cannot
+effectively restrict the users of a free program by obtaining a
+restrictive license from a patent holder.  Therefore, we insist that
+any patent license obtained for a version of the library must be
+consistent with the full freedom of use specified in this license.
+
+  Most GNU software, including some libraries, is covered by the
+ordinary GNU General Public License.  This license, the GNU Lesser
+General Public License, applies to certain designated libraries, and
+is quite different from the ordinary General Public License.  We use
+this license for certain libraries in order to permit linking those
+libraries into non-free programs.
+
+  When a program is linked with a library, whether statically or using
+a shared library, the combination of the two is legally speaking a
+combined work, a derivative of the original library.  The ordinary
+General Public License therefore permits such linking only if the
+entire combination fits its criteria of freedom.  The Lesser General
+Public License permits more lax criteria for linking other code with
+the library.
+
+  We call this license the "Lesser" General Public License because it
+does Less to protect the user's freedom than the ordinary General
+Public License.  It also provides other free software developers Less
+of an advantage over competing non-free programs.  These disadvantages
+are the reason we use the ordinary General Public License for many
+libraries.  However, the Lesser license provides advantages in certain
+special circumstances.
+
+  For example, on rare occasions, there may be a special need to
+encourage the widest possible use of a certain library, so that it
+becomes
+a de-facto standard.  To achieve this, non-free programs must be
+allowed to use the library.  A more frequent case is that a free
+library does the same job as widely used non-free libraries.  In this
+case, there is little to gain by limiting the free library to free
+software only, so we use the Lesser General Public License.
+
+  In other cases, permission to use a particular library in non-free
+programs enables a greater number of people to use a large body of
+free software.  For example, permission to use the GNU C Library in
+non-free programs enables many more people to use the whole GNU
+operating system, as well as its variant, the GNU/Linux operating
+system.
+
+  Although the Lesser General Public License is Less protective of the
+users' freedom, it does ensure that the user of a program that is
+linked with the Library has the freedom and the wherewithal to run
+that program using a modified version of the Library.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.  Pay close attention to the difference between a
+"work based on the library" and a "work that uses the library".  The
+former contains code derived from the library, whereas the latter must
+be combined with the library in order to run.
+^L
+                  GNU LESSER GENERAL PUBLIC LICENSE
+   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+  0. This License Agreement applies to any software library or other
+program which contains a notice placed by the copyright holder or
+other authorized party saying it may be distributed under the terms of
+this Lesser General Public License (also called "this License").
+Each licensee is addressed as "you".
+
+  A "library" means a collection of software functions and/or data
+prepared so as to be conveniently linked with application programs
+(which use some of those functions and data) to form executables.
+
+  The "Library", below, refers to any such software library or work
+which has been distributed under these terms.  A "work based on the
+Library" means either the Library or any derivative work under
+copyright law: that is to say, a work containing the Library or a
+portion of it, either verbatim or with modifications and/or translated
+straightforwardly into another language.  (Hereinafter, translation is
+included without limitation in the term "modification".)
+
+  "Source code" for a work means the preferred form of the work for
+making modifications to it.  For a library, complete source code means
+all the source code for all modules it contains, plus any associated
+interface definition files, plus the scripts used to control
+compilation
+and installation of the library.
+
+  Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope.  The act of
+running a program using the Library is not restricted, and output from
+such a program is covered only if its contents constitute a work based
+on the Library (independent of the use of the Library in a tool for
+writing it).  Whether that is true depends on what the Library does
+and what the program that uses the Library does.
+
+  1. You may copy and distribute verbatim copies of the Library's
+complete source code as you receive it, in any medium, provided that
+you conspicuously and appropriately publish on each copy an
+appropriate copyright notice and disclaimer of warranty; keep intact
+all the notices that refer to this License and to the absence of any
+warranty; and distribute a copy of this License along with the
+Library.
+
+  You may charge a fee for the physical act of transferring a copy,
+and you may at your option offer warranty protection in exchange for a
+fee.
+

+  2. You may modify your copy or copies of the Library or any portion
+of it, thus forming a work based on the Library, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+    a) The modified work must itself be a software library.
+
+    b) You must cause the files modified to carry prominent notices
+    stating that you changed the files and the date of any change.
+
+    c) You must cause the whole of the work to be licensed at no
+    charge to all third parties under the terms of this License.
+
+    d) If a facility in the modified Library refers to a function or a
+    table of data to be supplied by an application program that uses
+    the facility, other than as an argument passed when the facility
+    is invoked, then you must make a good faith effort to ensure that,
+    in the event an application does not supply such function or
+    table, the facility still operates, and performs whatever part of
+    its purpose remains meaningful.
+
+    (For example, a function in a library to compute square roots has
+    a purpose that is entirely well-defined independent of the
+    application.  Therefore, Subsection 2d requires that any
+    application-supplied function or table used by this function must
+    be optional: if the application does not supply it, the square
+    root function must still compute square roots.)
+
+These requirements apply to the modified work as a whole.  If
+identifiable sections of that work are not derived from the Library,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works.  But when you
+distribute the same sections as part of a whole which is a work based
+on the Library, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote
+it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Library.
+
+In addition, mere aggregation of another work not based on the Library
+with the Library (or with a work based on the Library) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+  3. You may opt to apply the terms of the ordinary GNU General Public
+License instead of this License to a given copy of the Library.  To do
+this, you must alter all the notices that refer to this License, so
+that they refer to the ordinary GNU General Public License, version 2,
+instead of to this License.  (If a newer version than version 2 of the
+ordinary GNU General Public License has appeared, then you can specify
+that version instead if you wish.)  Do not make any other change in
+these notices.
+^L
+  Once this change is made in a given copy, it is irreversible for
+that copy, so the ordinary GNU General Public License applies to all
+subsequent copies and derivative works made from that copy.
+
+  This option is useful when you wish to copy part of the code of
+the Library into a program that is not a library.
+
+  4. You may copy and distribute the Library (or a portion or
+derivative of it, under Section 2) in object code or executable form
+under the terms of Sections 1 and 2 above provided that you accompany
+it with the complete corresponding machine-readable source code, which
+must be distributed under the terms of Sections 1 and 2 above on a
+medium customarily used for software interchange.
+
+  If distribution of object code is made by offering access to copy
+from a designated place, then offering equivalent access to copy the
+source code from the same place satisfies the requirement to
+distribute the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+  5. A program that contains no derivative of any portion of the
+Library, but is designed to work with the Library by being compiled or
+linked with it, is called a "work that uses the Library".  Such a
+work, in isolation, is not a derivative work of the Library, and
+therefore falls outside the scope of this License.
+
+  However, linking a "work that uses the Library" with the Library
+creates an executable that is a derivative of the Library (because it
+contains portions of the Library), rather than a "work that uses the
+library".  The executable is therefore covered by this License.
+Section 6 states terms for distribution of such executables.
+
+  When a "work that uses the Library" uses material from a header file
+that is part of the Library, the object code for the work may be a
+derivative work of the Library even though the source code is not.
+Whether this is true is especially significant if the work can be
+linked without the Library, or if the work is itself a library.  The
+threshold for this to be true is not precisely defined by law.
+
+  If such an object file uses only numerical parameters, data
+structure layouts and accessors, and small macros and small inline
+functions (ten lines or less in length), then the use of the object
+file is unrestricted, regardless of whether it is legally a derivative
+work.  (Executables containing this object code plus portions of the
+Library will still fall under Section 6.)
+
+  Otherwise, if the work is a derivative of the Library, you may
+distribute the object code for the work under the terms of Section 6.
+Any executables containing that work also fall under Section 6,
+whether or not they are linked directly with the Library itself.
+^L
+  6. As an exception to the Sections above, you may also combine or
+link a "work that uses the Library" with the Library to produce a
+work containing portions of the Library, and distribute that work
+under terms of your choice, provided that the terms permit
+modification of the work for the customer's own use and reverse
+engineering for debugging such modifications.
+
+  You must give prominent notice with each copy of the work that the
+Library is used in it and that the Library and its use are covered by
+this License.  You must supply a copy of this License.  If the work
+during execution displays copyright notices, you must include the
+copyright notice for the Library among them, as well as a reference
+directing the user to the copy of this License.  Also, you must do one
+of these things:
+
+    a) Accompany the work with the complete corresponding
+    machine-readable source code for the Library including whatever
+    changes were used in the work (which must be distributed under
+    Sections 1 and 2 above); and, if the work is an executable linked
+    with the Library, with the complete machine-readable "work that
+    uses the Library", as object code and/or source code, so that the
+    user can modify the Library and then relink to produce a modified
+    executable containing the modified Library.  (It is understood
+    that the user who changes the contents of definitions files in the
+    Library will not necessarily be able to recompile the application
+    to use the modified definitions.)
+
+    b) Use a suitable shared library mechanism for linking with the
+    Library.  A suitable mechanism is one that (1) uses at run time a
+    copy of the library already present on the user's computer system,
+    rather than copying library functions into the executable, and (2)
+    will operate properly with a modified version of the library, if
+    the user installs one, as long as the modified version is
+    interface-compatible with the version that the work was made with.
+
+    c) Accompany the work with a written offer, valid for at
+    least three years, to give the same user the materials
+    specified in Subsection 6a, above, for a charge no more
+    than the cost of performing this distribution.
+
+    d) If distribution of the work is made by offering access to copy
+    from a designated place, offer equivalent access to copy the above
+    specified materials from the same place.
+
+    e) Verify that the user has already received a copy of these
+    materials or that you have already sent this user a copy.
+
+  For an executable, the required form of the "work that uses the
+Library" must include any data and utility programs needed for
+reproducing the executable from it.  However, as a special exception,
+the materials to be distributed need not include anything that is
+normally distributed (in either source or binary form) with the major
+components (compiler, kernel, and so on) of the operating system on
+which the executable runs, unless that component itself accompanies
+the executable.
+
+  It may happen that this requirement contradicts the license
+restrictions of other proprietary libraries that do not normally
+accompany the operating system.  Such a contradiction means you cannot
+use both them and the Library together in an executable that you
+distribute.
+^L
+  7. You may place library facilities that are a work based on the
+Library side-by-side in a single library together with other library
+facilities not covered by this License, and distribute such a combined
+library, provided that the separate distribution of the work based on
+the Library and of the other library facilities is otherwise
+permitted, and provided that you do these two things:
+
+    a) Accompany the combined library with a copy of the same work
+    based on the Library, uncombined with any other library
+    facilities.  This must be distributed under the terms of the
+    Sections above.
+
+    b) Give prominent notice with the combined library of the fact
+    that part of it is a work based on the Library, and explaining
+    where to find the accompanying uncombined form of the same work.
+
+  8. You may not copy, modify, sublicense, link with, or distribute
+the Library except as expressly provided under this License.  Any
+attempt otherwise to copy, modify, sublicense, link with, or
+distribute the Library is void, and will automatically terminate your
+rights under this License.  However, parties who have received copies,
+or rights, from you under this License will not have their licenses
+terminated so long as such parties remain in full compliance.
+
+  9. You are not required to accept this License, since you have not
+signed it.  However, nothing else grants you permission to modify or
+distribute the Library or its derivative works.  These actions are
+prohibited by law if you do not accept this License.  Therefore, by
+modifying or distributing the Library (or any work based on the
+Library), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Library or works based on it.
+
+  10. Each time you redistribute the Library (or any work based on the
+Library), the recipient automatically receives a license from the
+original licensor to copy, distribute, link with or modify the Library
+subject to these terms and conditions.  You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties with
+this License.
+^L
+  11. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Library at all.  For example, if a patent
+license would not permit royalty-free redistribution of the Library by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Library.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply, and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system which is
+implemented by public license practices.  Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+  12. If the distribution and/or use of the Library is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Library under this License
+may add an explicit geographical distribution limitation excluding those
+countries, so that distribution is permitted only in or among
+countries not thus excluded.  In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+  13. The Free Software Foundation may publish revised and/or new
+versions of the Lesser General Public License from time to time.
+Such new versions will be similar in spirit to the present version,
+but may differ in detail to address new problems or concerns.
+
+Each version is given a distinguishing version number.  If the Library
+specifies a version number of this License which applies to it and
+"any later version", you have the option of following the terms and
+conditions either of that version or of any later version published by
+the Free Software Foundation.  If the Library does not specify a
+license version number, you may choose any version ever published by
+the Free Software Foundation.
+^L
+  14. If you wish to incorporate parts of the Library into other free
+programs whose distribution conditions are incompatible with these,
+write to the author to ask for permission.  For software which is
+copyrighted by the Free Software Foundation, write to the Free
+Software Foundation; we sometimes make exceptions for this.  Our
+decision will be guided by the two goals of preserving the free status
+of all derivatives of our free software and of promoting the sharing
+and reuse of software generally.
+
+                            NO WARRANTY
+
+  15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
+WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
+EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
+OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
+KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
+LIBRARY IS WITH YOU.  SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
+THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+  16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
+WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
+AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
+FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
+CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
+LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
+RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
+FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
+SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGES.
+
+                     END OF TERMS AND CONDITIONS
+^L
+           How to Apply These Terms to Your New Libraries
+
+  If you develop a new library, and you want it to be of the greatest
+possible use to the public, we recommend making it free software that
+everyone can redistribute and change.  You can do so by permitting
+redistribution under these terms (or, alternatively, under the terms
+of the ordinary General Public License).
+
+  To apply these terms, attach the following notices to the library.
+It is safest to attach them to the start of each source file to most
+effectively convey the exclusion of warranty; and each file should
+have at least the "copyright" line and a pointer to where the full
+notice is found.
+
+
+    <one line to give the library's name and a brief idea of what it
+does.>
+    Copyright (C) <year>  <name of author>
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
+
+Also add information on how to contact you by electronic and paper
+mail.
+
+You should also get your employer (if you work as a programmer) or
+your
+school, if any, to sign a "copyright disclaimer" for the library, if
+necessary.  Here is a sample; alter the names:
+
+  Yoyodyne, Inc., hereby disclaims all copyright interest in the
+  library `Frob' (a library for tweaking knobs) written by James
+Random Hacker.
+
+  <signature of Ty Coon>, 1 April 1990
+  Ty Coon, President of Vice
+
+That's all there is to it!
+
+
diff --git a/ChangeLog b/ChangeLog
new file mode 100644
index 0000000..616a28a
--- /dev/null
+++ b/ChangeLog
@@ -0,0 +1,156 @@
+2.3.2            Clean static errors from Jenkins
+2.3.1            Updated id for DFO                         
+2.3.0            Added proper CUBE FITS header keys for CASA
+2.2.11
+                 Updated to CPL6
+2.2.10
+                 removed irplib_detmon dependency
+2.2.9
+                 Fixed sinfo_rec_jitter portability problem on a platform
+2.2.8
+                 Changed cube reconstruction algorithm to fix quality problem on a few cases (butterfly)
+cvs ci -m "name of corrected frame is now equal to basename of frame to have correct PRO.REC1.RAW.NAME (DFS10448)" sinfo_utilities.c
+2.2.7
+                 "changes to make bad-line-correction work with any recipe" sinfo_utilities.c
+2.2.6            Work to improve bad line cor in mdark (DFS10195)
+           "if we correct bad line we rename input file" sinfo_utilities.c
+                 "added sinfo_image_filter_linear2 (using CPL)" sinfo_utilities.h
+                 "added sinfo_image_filter_linear2 (using CPL), sinfo_image_filter_mode, changed some params in sinfo_image_line_corr" sinfo_utilities.c
+                 "added commented debug info" sinfo_image_ops.c
+
+2.2.5            Updated id- PSO Rel, changed CUNIT2/3 from mum to um and CRPIX key from in to double to fit FITS conversion
+2.2.4            Updated id
+2.2.3            Fixed DFS09196 - error during atmospheric refraction
+
+2.2.2            Internal Release.
+		 Fixed DFS09121 - Wrong calculation of the size of the output mask.
+		 Fixed DFS09155 - Put into the documentation explanation about heliocentric correction
+ 
+2.2.1            Updated directory structure
+		 new CPL version (5.2.0)
+		 updated irplib (detmon) recipes
+2.2.0
+                 Updated rel id
+                 added efficiency computation
+2.1.0
+                 "changed sinfo_utl_efficiency API" sinfo_utl_eff.c
+                 "added sinfo_atm_dispersion_cube" sinfo_atmo_disp.h
+                 "changed way to handle cpl objects free" sinfo_atmo_disp.c
+                 "changed way to handle cpl objects free" sinfo_new_cubes_build.c
+                 "removed from CVS" sinfo_utl_fpn.h sinfo_utl_fpn.c
+                 "changed functions API to allow more flexibility and to call it from jitter recipe" sinfo_utl_efficiency.c
+                 "changed functions API to allow more flexibility and to call it from jitter recipe" sinfo_utl_efficiency.h
+                 "removed sinfo_utl_fpn.h sinfo_utl_fpn.c" Makefile.am
+                 "rempved from CVS" sinfo_fpn_test.c
+                 "removed sinfo_fpn_test.c" Makefile.am
+                 "removed CVS log" test_atmo_disp.c
+                 "removed CVS log" test_atmo_disp.c
+                 "several changes to reflect efficiency functions API changes" sinfo_efficiency_test.c
+
+
+
+
+    Changed efficiency recipe, calibration file for atmospheric refraction
+2.0.9
+    Included possibility to do atmospheric refraction correction in jitter recipe
+2.0.8
+    Included detmon lingain bug fix (actually applicable only to OPT instruments)
+2.0.7
+    Fixed some problems with NRI unit tests
+2.0.6
+    Fixed problem with missing sinfo_irplib_cpl_wrp.h
+2.0.5
+    Fixed compiler warnings
+    Fixed some failures unit tests
+2.0.4
+    Increased mosaic_max_size default to 14196
+2.0.3
+    Implemented sinfo_utl_efficiency (still to be fully verified) to compute efficiency.
+2.0.2
+    Improved speed kappa-sigma clipping (jitter recipe).
+2.0.1
+     To fix problems reducing FIBER fed PSF frames:
+     "now return cpl_error_code" sinfo_baryvel.h sinfo_baryvel.c
+     "properly exit if baryvel fails" sinfo_new_cubes_coadd.c
+
+2.0.0
+     Fixed seg fault (apparing only on ubuntu) due to improper array sizing
+     Set to -100 QC STREHL if by chanche comes to NAN to fix DFS06717
+1.9.9
+     Upgrade sinfo_utl_cube_combine to support mosaic coaddition and remove
+     seg fault on some platforms
+1.9.8
+     Fixed seg fault with sinfo_utl_cube_arithm
+     Updated irplib_detmon
+1.9.7
+      Added unit tests on recipes
+      Fixed some problems on lingain recipe
+      Fixed some mem leaks
+1.9.5
+      sinfo_utl_cube_create: "fixed seg fault and added WCS in output cube" 
+      sinfo_rec_wavecal: "Now one can do wave cal based on OH lines" 
+
+1.9.4
+    Add sinfo_utl_cube_create to generate a cube out of any input raw frame.
+    Set kappa default to 9 in sinfo_rec_lingain
+    Fixed problem in sinfo_utl_cube_arith reading 1D images (spectrum)
+1.9.3
+    Implemernted sinfo_rec_mdark_detmon to implement detmon alghorithm
+    DFS04156: Improper flat generation
+    Updated SINFO.rul to support new linearity frames.
+    DFS05016: Installation corrupts calibration data base
+1.9.2
+   Fixed DFS05004 (COADD_OBS is not the result of sky-corrected OBJ_OBS if 
+   sky_cor=TRUE)
+1.9.1
+    Added sinfo_dark from detmon project
+    Cleaned warnings from compiler and static checks
+1.9.0
+    Added reference to DETMON_QC in rules
+    Fixed a bug in Strehl Computation
+    Cleaned some warnings
+    More robust STD star and PSF steps
+    Added parameters:
+    --lc_sw               : Correct for bad lines introduced by instrument software:. [FALSE]
+    --lc_kappa            : Kappa sigma value. [18]
+    --lc_filt_rad         : Filtering radii applied during median filter. Should be small. [3]
+
+
+1.8.9
+    Update sifo_new_add_bp_map to support 'detmon' BP_MAP_NL map conventions.
+    Implemented function to correct bad lines on visible on long exposure frames
+    Implemented sinfo_utl_ima_line_corr which corrects input image for bad lines
+    on visible on long exposure frames
+1.8.8
+    Fixed Strehl compuation
+    
+1.8.6
+     Extended product-density parameter allowed values to better differentiate
+     possible pipeline recipes product density:
+     0: less
+     1: less+skycor
+     2: DFO
+     3: debug
+     Added llx,lly,urx,ury parameters to skycor recipe to extract obj & sky
+     spectra on a given region (where the object is located)
+     Added pshift parameter to skycor recipe to eventually set a given obj-sky
+     correlation shift (overwrite what eventually found by the recipe).
+
+1.8.5
+     Now SLITLETS_POS_PREDIST is generated only if product-density=2
+     More robust sinfo_utl_cube2spectrum: 
+	added check on FITS key existence/removal
+	added error stack dump
+
+     Added parameter mflat_smooth_rad to prepare_stacked_frames and
+     defined mean, median, fft flat filtering methods
+	
+	 
+1.8.4
+Fixed DFS04509: uves_obs_scired fails to reduce STD data. Now PSF and STD steps are not executed on OBJNOD data.
+Added RESAMPLED_WAVE product of WAVECAL
+
+1.8.2
+Fixed DFS04336: to have proper FITS header in distortion recipe products
+1.8.1
+Support CPL4
diff --git a/INSTALL b/INSTALL
new file mode 100644
index 0000000..54caf7c
--- /dev/null
+++ b/INSTALL
@@ -0,0 +1,229 @@
+Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002 Free Software
+Foundation, Inc.
+
+   This file is free documentation; the Free Software Foundation gives
+unlimited permission to copy, distribute and modify it.
+
+Basic Installation
+==================
+
+   These are generic installation instructions.
+
+   The `configure' shell script attempts to guess correct values for
+various system-dependent variables used during compilation.  It uses
+those values to create a `Makefile' in each directory of the package.
+It may also create one or more `.h' files containing system-dependent
+definitions.  Finally, it creates a shell script `config.status' that
+you can run in the future to recreate the current configuration, and a
+file `config.log' containing compiler output (useful mainly for
+debugging `configure').
+
+   It can also use an optional file (typically called `config.cache'
+and enabled with `--cache-file=config.cache' or simply `-C') that saves
+the results of its tests to speed up reconfiguring.  (Caching is
+disabled by default to prevent problems with accidental use of stale
+cache files.)
+
+   If you need to do unusual things to compile the package, please try
+to figure out how `configure' could check whether to do them, and mail
+diffs or instructions to the address given in the `README' so they can
+be considered for the next release.  If you are using the cache, and at
+some point `config.cache' contains results you don't want to keep, you
+may remove or edit it.
+
+   The file `configure.ac' (or `configure.in') is used to create
+`configure' by a program called `autoconf'.  You only need
+`configure.ac' if you want to change it or regenerate `configure' using
+a newer version of `autoconf'.
+
+The simplest way to compile this package is:
+
+  1. `cd' to the directory containing the package's source code and type
+     `./configure' to configure the package for your system.  If you're
+     using `csh' on an old version of System V, you might need to type
+     `sh ./configure' instead to prevent `csh' from trying to execute
+     `configure' itself.
+
+     Running `configure' takes awhile.  While running, it prints some
+     messages telling which features it is checking for.
+
+  2. Type `make' to compile the package.
+
+  3. Optionally, type `make check' to run any self-tests that come with
+     the package.
+
+  4. Type `make install' to install the programs and any data files and
+     documentation.
+
+  5. You can remove the program binaries and object files from the
+     source code directory by typing `make clean'.  To also remove the
+     files that `configure' created (so you can compile the package for
+     a different kind of computer), type `make distclean'.  There is
+     also a `make maintainer-clean' target, but that is intended mainly
+     for the package's developers.  If you use it, you may have to get
+     all sorts of other programs in order to regenerate files that came
+     with the distribution.
+
+Compilers and Options
+=====================
+
+   Some systems require unusual options for compilation or linking that
+the `configure' script does not know about.  Run `./configure --help'
+for details on some of the pertinent environment variables.
+
+   You can give `configure' initial values for configuration parameters
+by setting variables in the command line or in the environment.  Here
+is an example:
+
+     ./configure CC=c89 CFLAGS=-O2 LIBS=-lposix
+
+   *Note Defining Variables::, for more details.
+
+Compiling For Multiple Architectures
+====================================
+
+   You can compile the package for more than one kind of computer at the
+same time, by placing the object files for each architecture in their
+own directory.  To do this, you must use a version of `make' that
+supports the `VPATH' variable, such as GNU `make'.  `cd' to the
+directory where you want the object files and executables to go and run
+the `configure' script.  `configure' automatically checks for the
+source code in the directory that `configure' is in and in `..'.
+
+   If you have to use a `make' that does not support the `VPATH'
+variable, you have to compile the package for one architecture at a
+time in the source code directory.  After you have installed the
+package for one architecture, use `make distclean' before reconfiguring
+for another architecture.
+
+Installation Names
+==================
+
+   By default, `make install' will install the package's files in
+`/usr/local/bin', `/usr/local/man', etc.  You can specify an
+installation prefix other than `/usr/local' by giving `configure' the
+option `--prefix=PATH'.
+
+   You can specify separate installation prefixes for
+architecture-specific files and architecture-independent files.  If you
+give `configure' the option `--exec-prefix=PATH', the package will use
+PATH as the prefix for installing programs and libraries.
+Documentation and other data files will still use the regular prefix.
+
+   In addition, if you use an unusual directory layout you can give
+options like `--bindir=PATH' to specify different values for particular
+kinds of files.  Run `configure --help' for a list of the directories
+you can set and what kinds of files go in them.
+
+   If the package supports it, you can cause programs to be installed
+with an extra prefix or suffix on their names by giving `configure' the
+option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'.
+
+Optional Features
+=================
+
+   Some packages pay attention to `--enable-FEATURE' options to
+`configure', where FEATURE indicates an optional part of the package.
+They may also pay attention to `--with-PACKAGE' options, where PACKAGE
+is something like `gnu-as' or `x' (for the X Window System).  The
+`README' should mention any `--enable-' and `--with-' options that the
+package recognizes.
+
+   For packages that use the X Window System, `configure' can usually
+find the X include and library files automatically, but if it doesn't,
+you can use the `configure' options `--x-includes=DIR' and
+`--x-libraries=DIR' to specify their locations.
+
+Specifying the System Type
+==========================
+
+   There may be some features `configure' cannot figure out
+automatically, but needs to determine by the type of machine the package
+will run on.  Usually, assuming the package is built to be run on the
+_same_ architectures, `configure' can figure that out, but if it prints
+a message saying it cannot guess the machine type, give it the
+`--build=TYPE' option.  TYPE can either be a short name for the system
+type, such as `sun4', or a canonical name which has the form:
+
+     CPU-COMPANY-SYSTEM
+
+where SYSTEM can have one of these forms:
+
+     OS KERNEL-OS
+
+   See the file `config.sub' for the possible values of each field.  If
+`config.sub' isn't included in this package, then this package doesn't
+need to know the machine type.
+
+   If you are _building_ compiler tools for cross-compiling, you should
+use the `--target=TYPE' option to select the type of system they will
+produce code for.
+
+   If you want to _use_ a cross compiler, that generates code for a
+platform different from the build platform, you should specify the
+"host" platform (i.e., that on which the generated programs will
+eventually be run) with `--host=TYPE'.
+
+Sharing Defaults
+================
+
+   If you want to set default values for `configure' scripts to share,
+you can create a site shell script called `config.site' that gives
+default values for variables like `CC', `cache_file', and `prefix'.
+`configure' looks for `PREFIX/share/config.site' if it exists, then
+`PREFIX/etc/config.site' if it exists.  Or, you can set the
+`CONFIG_SITE' environment variable to the location of the site script.
+A warning: not all `configure' scripts look for a site script.
+
+Defining Variables
+==================
+
+   Variables not defined in a site shell script can be set in the
+environment passed to `configure'.  However, some packages may run
+configure again during the build, and the customized values of these
+variables may be lost.  In order to avoid this problem, you should set
+them in the `configure' command line, using `VAR=value'.  For example:
+
+     ./configure CC=/usr/local2/bin/gcc
+
+will cause the specified gcc to be used as the C compiler (unless it is
+overridden in the site shell script).
+
+`configure' Invocation
+======================
+
+   `configure' recognizes the following options to control how it
+operates.
+
+`--help'
+`-h'
+     Print a summary of the options to `configure', and exit.
+
+`--version'
+`-V'
+     Print the version of Autoconf used to generate the `configure'
+     script, and exit.
+
+`--cache-file=FILE'
+     Enable the cache: use and save the results of the tests in FILE,
+     traditionally `config.cache'.  FILE defaults to `/dev/null' to
+     disable caching.
+
+`--config-cache'
+`-C'
+     Alias for `--cache-file=config.cache'.
+
+`--quiet'
+`--silent'
+`-q'
+     Do not print messages saying which checks are being made.  To
+     suppress all normal output, redirect it to `/dev/null' (any error
+     messages will still be shown).
+
+`--srcdir=DIR'
+     Look for the package's source code in directory DIR.  Usually
+     `configure' can determine that directory automatically.
+
+`configure' also accepts some other, not widely useful, options.  Run
+`configure --help' for more details.
+
diff --git a/Makefile.am b/Makefile.am
new file mode 100644
index 0000000..387a8dc
--- /dev/null
+++ b/Makefile.am
@@ -0,0 +1,73 @@
+## Process this file with automake to produce Makefile.in
+
+##   This file is part of the SINFONI Pipeline
+##   Copyright (C) 2002,2003 European Southern Observatory
+
+##   This program is free software; you can redistribute it and/or modify
+##   it under the terms of the GNU General Public License as published by
+##   the Free Software Foundation; either version 2 of the License, or
+##   (at your option) any later version.
+
+##   This program is distributed in the hope that it will be useful,
+##   but WITHOUT ANY WARRANTY; without even the implied warranty of
+##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+##   GNU General Public License for more details.
+
+##   You should have received a copy of the GNU General Public License
+##   along with this program; if not, write to the Free Software
+##   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+AUTOMAKE_OPTIONS = 1.8 foreign
+
+ACLOCAL_AMFLAGS = -I m4macros
+
+DISTCLEANFILES = *~ .logfile
+
+DISTCHECK_CONFIGURE_FLAGS = --enable-maintainer-mode
+
+
+COMPILE_FIRST = 
+
+TOPSUBDIRS = irplib sinfoni recipes regtests
+
+#COMPILE_LAST = sinfoni/tests
+COMPILE_LAST = 
+
+
+HTML_SUBDIRS =
+
+SUBDIRS = $(COMPILE_FIRST) $(TOPSUBDIRS) $(COMPILE_LAST)
+
+EXTRA_DIST = m4macros/eso.m4 m4macros/cpl.m4 admin/html.am \
+        doxygen/Doxyfile.in setup
+
+
+pipedocs_DATA = ChangeLog AUTHORS NEWS README TODO
+
+
+if MAINTAINER_MODE
+
+MAINTAINERCLEANFILES = Makefile.in aclocal.m4 config.h.in configure stamp-h.in
+
+clean-local: clean-html
+
+dist-hook: html
+	@if test -d $(top_srcdir)/html; then \
+	  echo "cp -pr $(top_srcdir)/html $(distdir)"; \
+	  cp -pr $(top_srcdir)/html $(distdir); \
+	fi
+	find $(distdir) -type d ! -perm -222 -exec chmod u+w {} \; -o \
+	-type f ! -perm -222 -exec chmod u+w {} \; || chmod -R u+w $(distdir)
+
+else
+
+clean-local:
+
+endif
+
+uninstall-local: uninstall-html
+
+libtool: $(LIBTOOL_DEPS)
+	$(SHELL) ./config.status --recheck
+
+include $(top_srcdir)/admin/html.am
diff --git a/Makefile.in b/Makefile.in
new file mode 100644
index 0000000..a8975fd
--- /dev/null
+++ b/Makefile.in
@@ -0,0 +1,917 @@
+# Makefile.in generated by automake 1.11 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009  Free Software Foundation,
+# Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+ at SET_MAKE@
+
+VPATH = @srcdir@
+pkgdatadir = $(datadir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkglibexecdir = $(libexecdir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
+target_triplet = @target@
+DIST_COMMON = README $(am__configure_deps) $(srcdir)/Makefile.am \
+	$(srcdir)/Makefile.in $(srcdir)/Makefile.purify.in \
+	$(srcdir)/config.h.in $(top_srcdir)/admin/html.am \
+	$(top_srcdir)/configure $(top_srcdir)/doxygen/Doxyfile.in \
+	AUTHORS COPYING COPYING.LIB ChangeLog INSTALL NEWS TODO \
+	admin/compile admin/config.guess admin/config.sub \
+	admin/depcomp admin/install-sh admin/ltmain.sh admin/missing
+subdir = .
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/m4macros/cpl.m4 \
+	$(top_srcdir)/m4macros/eso.m4 \
+	$(top_srcdir)/m4macros/libtool.m4 \
+	$(top_srcdir)/m4macros/ltoptions.m4 \
+	$(top_srcdir)/m4macros/ltsugar.m4 \
+	$(top_srcdir)/m4macros/ltversion.m4 \
+	$(top_srcdir)/m4macros/lt~obsolete.m4 \
+	$(top_srcdir)/m4macros/purify.m4 $(top_srcdir)/acinclude.m4 \
+	$(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+	$(ACLOCAL_M4)
+am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \
+ configure.lineno config.status.lineno
+mkinstalldirs = $(install_sh) -d
+CONFIG_HEADER = config.h
+CONFIG_CLEAN_FILES = Makefile.purify doxygen/Doxyfile
+CONFIG_CLEAN_VPATH_FILES =
+SOURCES =
+DIST_SOURCES =
+RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \
+	html-recursive info-recursive install-data-recursive \
+	install-dvi-recursive install-exec-recursive \
+	install-html-recursive install-info-recursive \
+	install-pdf-recursive install-ps-recursive install-recursive \
+	installcheck-recursive installdirs-recursive pdf-recursive \
+	ps-recursive uninstall-recursive
+am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
+am__vpath_adj = case $$p in \
+    $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
+    *) f=$$p;; \
+  esac;
+am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`;
+am__install_max = 40
+am__nobase_strip_setup = \
+  srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'`
+am__nobase_strip = \
+  for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||"
+am__nobase_list = $(am__nobase_strip_setup); \
+  for p in $$list; do echo "$$p $$p"; done | \
+  sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \
+  $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \
+    if (++n[$$2] == $(am__install_max)) \
+      { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \
+    END { for (dir in files) print dir, files[dir] }'
+am__base_list = \
+  sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
+  sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
+am__installdirs = "$(DESTDIR)$(pipedocsdir)"
+DATA = $(pipedocs_DATA)
+RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive	\
+  distclean-recursive maintainer-clean-recursive
+AM_RECURSIVE_TARGETS = $(RECURSIVE_TARGETS:-recursive=) \
+	$(RECURSIVE_CLEAN_TARGETS:-recursive=) tags TAGS ctags CTAGS \
+	distdir dist dist-all distcheck
+ETAGS = etags
+CTAGS = ctags
+DIST_SUBDIRS = $(SUBDIRS)
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+distdir = $(PACKAGE)-$(VERSION)
+top_distdir = $(distdir)
+am__remove_distdir = \
+  { test ! -d "$(distdir)" \
+    || { find "$(distdir)" -type d ! -perm -200 -exec chmod u+w {} ';' \
+         && rm -fr "$(distdir)"; }; }
+am__relativize = \
+  dir0=`pwd`; \
+  sed_first='s,^\([^/]*\)/.*$$,\1,'; \
+  sed_rest='s,^[^/]*/*,,'; \
+  sed_last='s,^.*/\([^/]*\)$$,\1,'; \
+  sed_butlast='s,/*[^/]*$$,,'; \
+  while test -n "$$dir1"; do \
+    first=`echo "$$dir1" | sed -e "$$sed_first"`; \
+    if test "$$first" != "."; then \
+      if test "$$first" = ".."; then \
+        dir2=`echo "$$dir0" | sed -e "$$sed_last"`/"$$dir2"; \
+        dir0=`echo "$$dir0" | sed -e "$$sed_butlast"`; \
+      else \
+        first2=`echo "$$dir2" | sed -e "$$sed_first"`; \
+        if test "$$first2" = "$$first"; then \
+          dir2=`echo "$$dir2" | sed -e "$$sed_rest"`; \
+        else \
+          dir2="../$$dir2"; \
+        fi; \
+        dir0="$$dir0"/"$$first"; \
+      fi; \
+    fi; \
+    dir1=`echo "$$dir1" | sed -e "$$sed_rest"`; \
+  done; \
+  reldir="$$dir2"
+DIST_ARCHIVES = $(distdir).tar.gz
+GZIP_ENV = --best
+distuninstallcheck_listfiles = find . -type f -print
+distcleancheck_listfiles = find . -type f -print
+ACLOCAL = @ACLOCAL@
+AMTAR = @AMTAR@
+AR = @AR@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CPL_INCLUDES = @CPL_INCLUDES@
+CPL_LDFLAGS = @CPL_LDFLAGS@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CX_INCLUDES = @CX_INCLUDES@
+CX_LDFLAGS = @CX_LDFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+DOXYGEN = @DOXYGEN@
+DSYMUTIL = @DSYMUTIL@
+DUMPBIN = @DUMPBIN@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+ESO_DEBUG_FLAGS = @ESO_DEBUG_FLAGS@
+EXEEXT = @EXEEXT@
+FGREP = @FGREP@
+GREP = @GREP@
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+IRPLIB_INCLUDES = @IRPLIB_INCLUDES@
+IRPLIB_LDFLAGS = @IRPLIB_LDFLAGS@
+LATEX = @LATEX@
+LD = @LD@
+LDFLAGS = @LDFLAGS@
+LIBCEXT = @LIBCEXT@
+LIBCPLCORE = @LIBCPLCORE@
+LIBCPLDFS = @LIBCPLDFS@
+LIBCPLDRS = @LIBCPLDRS@
+LIBCPLUI = @LIBCPLUI@
+LIBIRPLIB = @LIBIRPLIB@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LIBSINFONI = @LIBSINFONI@
+LIBTOOL = @LIBTOOL@
+LIBTOOL_DEPS = @LIBTOOL_DEPS@
+LIPO = @LIPO@
+LN_S = @LN_S@
+LTLIBOBJS = @LTLIBOBJS@
+LT_AGE = @LT_AGE@
+LT_CURRENT = @LT_CURRENT@
+LT_REVISION = @LT_REVISION@
+MAINT = @MAINT@
+MAKEINFO = @MAKEINFO@
+MKDIR_P = @MKDIR_P@
+NM = @NM@
+NMEDIT = @NMEDIT@
+OBJDUMP = @OBJDUMP@
+OBJEXT = @OBJEXT@
+OTOOL = @OTOOL@
+OTOOL64 = @OTOOL64@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+PURIFY_CMD = @PURIFY_CMD@
+RANLIB = @RANLIB@
+SED = @SED@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+SINFONI_BINARY_AGE = @SINFONI_BINARY_AGE@
+SINFONI_BINARY_VERSION = @SINFONI_BINARY_VERSION@
+SINFONI_INCLUDES = @SINFONI_INCLUDES@
+SINFONI_INTERFACE_AGE = @SINFONI_INTERFACE_AGE@
+SINFONI_LDFLAGS = @SINFONI_LDFLAGS@
+SINFONI_MAJOR_VERSION = @SINFONI_MAJOR_VERSION@
+SINFONI_MICRO_VERSION = @SINFONI_MICRO_VERSION@
+SINFONI_MINOR_VERSION = @SINFONI_MINOR_VERSION@
+SINFONI_VERSION = @SINFONI_VERSION@
+STRIP = @STRIP@
+VERSION = @VERSION@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
+all_includes = @all_includes@
+all_ldflags = @all_ldflags@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build = @build@
+build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
+builddir = @builddir@
+configdir = @configdir@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
+exec_prefix = @exec_prefix@
+host = @host@
+host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localedir = @localedir@
+localstatedir = @localstatedir@
+lt_ECHO = @lt_ECHO@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+pipedocsdir = @pipedocsdir@
+plugindir = @plugindir@
+prefix = @prefix@
+privatelibdir = @privatelibdir@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
+sysconfdir = @sysconfdir@
+target = @target@
+target_alias = @target_alias@
+target_cpu = @target_cpu@
+target_os = @target_os@
+target_vendor = @target_vendor@
+top_build_prefix = @top_build_prefix@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+AUTOMAKE_OPTIONS = 1.8 foreign
+ACLOCAL_AMFLAGS = -I m4macros
+DISTCLEANFILES = *~ .logfile
+DISTCHECK_CONFIGURE_FLAGS = --enable-maintainer-mode
+COMPILE_FIRST = 
+TOPSUBDIRS = irplib sinfoni recipes regtests
+
+#COMPILE_LAST = sinfoni/tests
+COMPILE_LAST = 
+HTML_SUBDIRS = 
+SUBDIRS = $(COMPILE_FIRST) $(TOPSUBDIRS) $(COMPILE_LAST)
+EXTRA_DIST = m4macros/eso.m4 m4macros/cpl.m4 admin/html.am \
+        doxygen/Doxyfile.in setup
+
+pipedocs_DATA = ChangeLog AUTHORS NEWS README TODO
+ at MAINTAINER_MODE_TRUE@MAINTAINERCLEANFILES = Makefile.in aclocal.m4 config.h.in configure stamp-h.in
+ at MAINTAINER_MODE_FALSE@HTML_RECURSIVE_TARGETS = install-html-recursive
+ at MAINTAINER_MODE_TRUE@HTML_RECURSIVE_TARGETS = install-html-recursive
+all: config.h
+	$(MAKE) $(AM_MAKEFLAGS) all-recursive
+
+.SUFFIXES:
+am--refresh:
+	@:
+$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(top_srcdir)/admin/html.am $(am__configure_deps)
+	@for dep in $?; do \
+	  case '$(am__configure_deps)' in \
+	    *$$dep*) \
+	      echo ' cd $(srcdir) && $(AUTOMAKE) --foreign'; \
+	      $(am__cd) $(srcdir) && $(AUTOMAKE) --foreign \
+		&& exit 0; \
+	      exit 1;; \
+	  esac; \
+	done; \
+	echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign Makefile'; \
+	$(am__cd) $(top_srcdir) && \
+	  $(AUTOMAKE) --foreign Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+	@case '$?' in \
+	  *config.status*) \
+	    echo ' $(SHELL) ./config.status'; \
+	    $(SHELL) ./config.status;; \
+	  *) \
+	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__depfiles_maybe)'; \
+	    cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__depfiles_maybe);; \
+	esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+	$(SHELL) ./config.status --recheck
+
+$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
+	$(am__cd) $(srcdir) && $(AUTOCONF)
+$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
+	$(am__cd) $(srcdir) && $(ACLOCAL) $(ACLOCAL_AMFLAGS)
+$(am__aclocal_m4_deps):
+
+config.h: stamp-h1
+	@if test ! -f $@; then \
+	  rm -f stamp-h1; \
+	  $(MAKE) $(AM_MAKEFLAGS) stamp-h1; \
+	else :; fi
+
+stamp-h1: $(srcdir)/config.h.in $(top_builddir)/config.status
+	@rm -f stamp-h1
+	cd $(top_builddir) && $(SHELL) ./config.status config.h
+$(srcdir)/config.h.in: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) 
+	($(am__cd) $(top_srcdir) && $(AUTOHEADER))
+	rm -f stamp-h1
+	touch $@
+
+distclean-hdr:
+	-rm -f config.h stamp-h1
+Makefile.purify: $(top_builddir)/config.status $(srcdir)/Makefile.purify.in
+	cd $(top_builddir) && $(SHELL) ./config.status $@
+doxygen/Doxyfile: $(top_builddir)/config.status $(top_srcdir)/doxygen/Doxyfile.in
+	cd $(top_builddir) && $(SHELL) ./config.status $@
+
+mostlyclean-libtool:
+	-rm -f *.lo
+
+clean-libtool:
+	-rm -rf .libs _libs
+
+distclean-libtool:
+	-rm -f libtool config.lt
+install-pipedocsDATA: $(pipedocs_DATA)
+	@$(NORMAL_INSTALL)
+	test -z "$(pipedocsdir)" || $(MKDIR_P) "$(DESTDIR)$(pipedocsdir)"
+	@list='$(pipedocs_DATA)'; test -n "$(pipedocsdir)" || list=; \
+	for p in $$list; do \
+	  if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
+	  echo "$$d$$p"; \
+	done | $(am__base_list) | \
+	while read files; do \
+	  echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(pipedocsdir)'"; \
+	  $(INSTALL_DATA) $$files "$(DESTDIR)$(pipedocsdir)" || exit $$?; \
+	done
+
+uninstall-pipedocsDATA:
+	@$(NORMAL_UNINSTALL)
+	@list='$(pipedocs_DATA)'; test -n "$(pipedocsdir)" || list=; \
+	files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
+	test -n "$$files" || exit 0; \
+	echo " ( cd '$(DESTDIR)$(pipedocsdir)' && rm -f" $$files ")"; \
+	cd "$(DESTDIR)$(pipedocsdir)" && rm -f $$files
+
+# This directory's subdirectories are mostly independent; you can cd
+# into them and run `make' without going through this Makefile.
+# To change the values of `make' variables: instead of editing Makefiles,
+# (1) if the variable is set in `config.status', edit `config.status'
+#     (which will cause the Makefiles to be regenerated when you run `make');
+# (2) otherwise, pass the desired values on the `make' command line.
+$(RECURSIVE_TARGETS):
+	@failcom='exit 1'; \
+	for f in x $$MAKEFLAGS; do \
+	  case $$f in \
+	    *=* | --[!k]*);; \
+	    *k*) failcom='fail=yes';; \
+	  esac; \
+	done; \
+	dot_seen=no; \
+	target=`echo $@ | sed s/-recursive//`; \
+	list='$(SUBDIRS)'; for subdir in $$list; do \
+	  echo "Making $$target in $$subdir"; \
+	  if test "$$subdir" = "."; then \
+	    dot_seen=yes; \
+	    local_target="$$target-am"; \
+	  else \
+	    local_target="$$target"; \
+	  fi; \
+	  ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
+	  || eval $$failcom; \
+	done; \
+	if test "$$dot_seen" = "no"; then \
+	  $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \
+	fi; test -z "$$fail"
+
+$(RECURSIVE_CLEAN_TARGETS):
+	@failcom='exit 1'; \
+	for f in x $$MAKEFLAGS; do \
+	  case $$f in \
+	    *=* | --[!k]*);; \
+	    *k*) failcom='fail=yes';; \
+	  esac; \
+	done; \
+	dot_seen=no; \
+	case "$@" in \
+	  distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \
+	  *) list='$(SUBDIRS)' ;; \
+	esac; \
+	rev=''; for subdir in $$list; do \
+	  if test "$$subdir" = "."; then :; else \
+	    rev="$$subdir $$rev"; \
+	  fi; \
+	done; \
+	rev="$$rev ."; \
+	target=`echo $@ | sed s/-recursive//`; \
+	for subdir in $$rev; do \
+	  echo "Making $$target in $$subdir"; \
+	  if test "$$subdir" = "."; then \
+	    local_target="$$target-am"; \
+	  else \
+	    local_target="$$target"; \
+	  fi; \
+	  ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
+	  || eval $$failcom; \
+	done && test -z "$$fail"
+tags-recursive:
+	list='$(SUBDIRS)'; for subdir in $$list; do \
+	  test "$$subdir" = . || ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) tags); \
+	done
+ctags-recursive:
+	list='$(SUBDIRS)'; for subdir in $$list; do \
+	  test "$$subdir" = . || ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) ctags); \
+	done
+
+ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
+	list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	mkid -fID $$unique
+tags: TAGS
+
+TAGS: tags-recursive $(HEADERS) $(SOURCES) config.h.in $(TAGS_DEPENDENCIES) \
+		$(TAGS_FILES) $(LISP)
+	set x; \
+	here=`pwd`; \
+	if ($(ETAGS) --etags-include --version) >/dev/null 2>&1; then \
+	  include_option=--etags-include; \
+	  empty_fix=.; \
+	else \
+	  include_option=--include; \
+	  empty_fix=; \
+	fi; \
+	list='$(SUBDIRS)'; for subdir in $$list; do \
+	  if test "$$subdir" = .; then :; else \
+	    test ! -f $$subdir/TAGS || \
+	      set "$$@" "$$include_option=$$here/$$subdir/TAGS"; \
+	  fi; \
+	done; \
+	list='$(SOURCES) $(HEADERS) config.h.in $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	shift; \
+	if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
+	  test -n "$$unique" || unique=$$empty_fix; \
+	  if test $$# -gt 0; then \
+	    $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+	      "$$@" $$unique; \
+	  else \
+	    $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+	      $$unique; \
+	  fi; \
+	fi
+ctags: CTAGS
+CTAGS: ctags-recursive $(HEADERS) $(SOURCES) config.h.in $(TAGS_DEPENDENCIES) \
+		$(TAGS_FILES) $(LISP)
+	list='$(SOURCES) $(HEADERS) config.h.in $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	test -z "$(CTAGS_ARGS)$$unique" \
+	  || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+	     $$unique
+
+GTAGS:
+	here=`$(am__cd) $(top_builddir) && pwd` \
+	  && $(am__cd) $(top_srcdir) \
+	  && gtags -i $(GTAGS_ARGS) "$$here"
+
+distclean-tags:
+	-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+ at MAINTAINER_MODE_FALSE@dist-hook:
+
+distdir: $(DISTFILES)
+	$(am__remove_distdir)
+	test -d "$(distdir)" || mkdir "$(distdir)"
+	@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+	topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+	list='$(DISTFILES)'; \
+	  dist_files=`for file in $$list; do echo $$file; done | \
+	  sed -e "s|^$$srcdirstrip/||;t" \
+	      -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+	case $$dist_files in \
+	  */*) $(MKDIR_P) `echo "$$dist_files" | \
+			   sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+			   sort -u` ;; \
+	esac; \
+	for file in $$dist_files; do \
+	  if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+	  if test -d $$d/$$file; then \
+	    dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+	    if test -d "$(distdir)/$$file"; then \
+	      find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+	    fi; \
+	    if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+	      cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
+	      find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+	    fi; \
+	    cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
+	  else \
+	    test -f "$(distdir)/$$file" \
+	    || cp -p $$d/$$file "$(distdir)/$$file" \
+	    || exit 1; \
+	  fi; \
+	done
+	@list='$(DIST_SUBDIRS)'; for subdir in $$list; do \
+	  if test "$$subdir" = .; then :; else \
+	    test -d "$(distdir)/$$subdir" \
+	    || $(MKDIR_P) "$(distdir)/$$subdir" \
+	    || exit 1; \
+	  fi; \
+	done
+	@list='$(DIST_SUBDIRS)'; for subdir in $$list; do \
+	  if test "$$subdir" = .; then :; else \
+	    dir1=$$subdir; dir2="$(distdir)/$$subdir"; \
+	    $(am__relativize); \
+	    new_distdir=$$reldir; \
+	    dir1=$$subdir; dir2="$(top_distdir)"; \
+	    $(am__relativize); \
+	    new_top_distdir=$$reldir; \
+	    echo " (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) top_distdir="$$new_top_distdir" distdir="$$new_distdir" \\"; \
+	    echo "     am__remove_distdir=: am__skip_length_check=: am__skip_mode_fix=: distdir)"; \
+	    ($(am__cd) $$subdir && \
+	      $(MAKE) $(AM_MAKEFLAGS) \
+	        top_distdir="$$new_top_distdir" \
+	        distdir="$$new_distdir" \
+		am__remove_distdir=: \
+		am__skip_length_check=: \
+		am__skip_mode_fix=: \
+	        distdir) \
+	      || exit 1; \
+	  fi; \
+	done
+	$(MAKE) $(AM_MAKEFLAGS) \
+	  top_distdir="$(top_distdir)" distdir="$(distdir)" \
+	  dist-hook
+	-test -n "$(am__skip_mode_fix)" \
+	|| find "$(distdir)" -type d ! -perm -777 -exec chmod a+rwx {} \; -o \
+	  ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; -o \
+	  ! -type d ! -perm -400 -exec chmod a+r {} \; -o \
+	  ! -type d ! -perm -444 -exec $(install_sh) -c -m a+r {} {} \; \
+	|| chmod -R a+r "$(distdir)"
+dist-gzip: distdir
+	tardir=$(distdir) && $(am__tar) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz
+	$(am__remove_distdir)
+
+dist-bzip2: distdir
+	tardir=$(distdir) && $(am__tar) | bzip2 -9 -c >$(distdir).tar.bz2
+	$(am__remove_distdir)
+
+dist-lzma: distdir
+	tardir=$(distdir) && $(am__tar) | lzma -9 -c >$(distdir).tar.lzma
+	$(am__remove_distdir)
+
+dist-xz: distdir
+	tardir=$(distdir) && $(am__tar) | xz -c >$(distdir).tar.xz
+	$(am__remove_distdir)
+
+dist-tarZ: distdir
+	tardir=$(distdir) && $(am__tar) | compress -c >$(distdir).tar.Z
+	$(am__remove_distdir)
+
+dist-shar: distdir
+	shar $(distdir) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).shar.gz
+	$(am__remove_distdir)
+
+dist-zip: distdir
+	-rm -f $(distdir).zip
+	zip -rq $(distdir).zip $(distdir)
+	$(am__remove_distdir)
+
+dist dist-all: distdir
+	tardir=$(distdir) && $(am__tar) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz
+	$(am__remove_distdir)
+
+# This target untars the dist file and tries a VPATH configuration.  Then
+# it guarantees that the distribution is self-contained by making another
+# tarfile.
+distcheck: dist
+	case '$(DIST_ARCHIVES)' in \
+	*.tar.gz*) \
+	  GZIP=$(GZIP_ENV) gunzip -c $(distdir).tar.gz | $(am__untar) ;;\
+	*.tar.bz2*) \
+	  bunzip2 -c $(distdir).tar.bz2 | $(am__untar) ;;\
+	*.tar.lzma*) \
+	  unlzma -c $(distdir).tar.lzma | $(am__untar) ;;\
+	*.tar.xz*) \
+	  xz -dc $(distdir).tar.xz | $(am__untar) ;;\
+	*.tar.Z*) \
+	  uncompress -c $(distdir).tar.Z | $(am__untar) ;;\
+	*.shar.gz*) \
+	  GZIP=$(GZIP_ENV) gunzip -c $(distdir).shar.gz | unshar ;;\
+	*.zip*) \
+	  unzip $(distdir).zip ;;\
+	esac
+	chmod -R a-w $(distdir); chmod a+w $(distdir)
+	mkdir $(distdir)/_build
+	mkdir $(distdir)/_inst
+	chmod a-w $(distdir)
+	test -d $(distdir)/_build || exit 0; \
+	dc_install_base=`$(am__cd) $(distdir)/_inst && pwd | sed -e 's,^[^:\\/]:[\\/],/,'` \
+	  && dc_destdir="$${TMPDIR-/tmp}/am-dc-$$$$/" \
+	  && am__cwd=`pwd` \
+	  && $(am__cd) $(distdir)/_build \
+	  && ../configure --srcdir=.. --prefix="$$dc_install_base" \
+	    $(DISTCHECK_CONFIGURE_FLAGS) \
+	  && $(MAKE) $(AM_MAKEFLAGS) \
+	  && $(MAKE) $(AM_MAKEFLAGS) dvi \
+	  && $(MAKE) $(AM_MAKEFLAGS) check \
+	  && $(MAKE) $(AM_MAKEFLAGS) install \
+	  && $(MAKE) $(AM_MAKEFLAGS) installcheck \
+	  && $(MAKE) $(AM_MAKEFLAGS) uninstall \
+	  && $(MAKE) $(AM_MAKEFLAGS) distuninstallcheck_dir="$$dc_install_base" \
+	        distuninstallcheck \
+	  && chmod -R a-w "$$dc_install_base" \
+	  && ({ \
+	       (cd ../.. && umask 077 && mkdir "$$dc_destdir") \
+	       && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" install \
+	       && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" uninstall \
+	       && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" \
+	            distuninstallcheck_dir="$$dc_destdir" distuninstallcheck; \
+	      } || { rm -rf "$$dc_destdir"; exit 1; }) \
+	  && rm -rf "$$dc_destdir" \
+	  && $(MAKE) $(AM_MAKEFLAGS) dist \
+	  && rm -rf $(DIST_ARCHIVES) \
+	  && $(MAKE) $(AM_MAKEFLAGS) distcleancheck \
+	  && cd "$$am__cwd" \
+	  || exit 1
+	$(am__remove_distdir)
+	@(echo "$(distdir) archives ready for distribution: "; \
+	  list='$(DIST_ARCHIVES)'; for i in $$list; do echo $$i; done) | \
+	  sed -e 1h -e 1s/./=/g -e 1p -e 1x -e '$$p' -e '$$x'
+distuninstallcheck:
+	@$(am__cd) '$(distuninstallcheck_dir)' \
+	&& test `$(distuninstallcheck_listfiles) | wc -l` -le 1 \
+	   || { echo "ERROR: files left after uninstall:" ; \
+	        if test -n "$(DESTDIR)"; then \
+	          echo "  (check DESTDIR support)"; \
+	        fi ; \
+	        $(distuninstallcheck_listfiles) ; \
+	        exit 1; } >&2
+distcleancheck: distclean
+	@if test '$(srcdir)' = . ; then \
+	  echo "ERROR: distcleancheck can only run from a VPATH build" ; \
+	  exit 1 ; \
+	fi
+	@test `$(distcleancheck_listfiles) | wc -l` -eq 0 \
+	  || { echo "ERROR: files left in build directory after distclean:" ; \
+	       $(distcleancheck_listfiles) ; \
+	       exit 1; } >&2
+check-am: all-am
+check: check-recursive
+all-am: Makefile $(DATA) config.h
+installdirs: installdirs-recursive
+installdirs-am:
+	for dir in "$(DESTDIR)$(pipedocsdir)"; do \
+	  test -z "$$dir" || $(MKDIR_P) "$$dir"; \
+	done
+install: install-recursive
+install-exec: install-exec-recursive
+install-data: install-data-recursive
+uninstall: uninstall-recursive
+
+install-am: all-am
+	@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-recursive
+install-strip:
+	$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+	  install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+	  `test -z '$(STRIP)' || \
+	    echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+	-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+	-test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
+	-test -z "$(DISTCLEANFILES)" || rm -f $(DISTCLEANFILES)
+
+maintainer-clean-generic:
+	@echo "This command is intended for maintainers to use"
+	@echo "it deletes files that may require special tools to rebuild."
+	-test -z "$(MAINTAINERCLEANFILES)" || rm -f $(MAINTAINERCLEANFILES)
+clean: clean-recursive
+
+clean-am: clean-generic clean-libtool clean-local mostlyclean-am
+
+distclean: distclean-recursive
+	-rm -f $(am__CONFIG_DISTCLEAN_FILES)
+	-rm -f Makefile
+distclean-am: clean-am distclean-generic distclean-hdr \
+	distclean-libtool distclean-tags
+
+dvi: dvi-recursive
+
+dvi-am:
+
+html: html-recursive
+
+ at MAINTAINER_MODE_FALSE@html-am:
+
+info: info-recursive
+
+info-am:
+
+install-data-am: install-pipedocsDATA
+
+install-dvi: install-dvi-recursive
+
+install-dvi-am:
+
+install-exec-am:
+
+install-info: install-info-recursive
+
+install-info-am:
+
+install-man:
+
+install-pdf: install-pdf-recursive
+
+install-pdf-am:
+
+install-ps: install-ps-recursive
+
+install-ps-am:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-recursive
+	-rm -f $(am__CONFIG_DISTCLEAN_FILES)
+	-rm -rf $(top_srcdir)/autom4te.cache
+	-rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-recursive
+
+mostlyclean-am: mostlyclean-generic mostlyclean-libtool
+
+pdf: pdf-recursive
+
+pdf-am:
+
+ps: ps-recursive
+
+ps-am:
+
+uninstall-am: uninstall-local uninstall-pipedocsDATA
+
+.MAKE: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) all \
+	ctags-recursive install-am install-strip tags-recursive
+
+.PHONY: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) CTAGS GTAGS \
+	all all-am am--refresh check check-am clean clean-generic \
+	clean-libtool clean-local ctags ctags-recursive dist dist-all \
+	dist-bzip2 dist-gzip dist-hook dist-lzma dist-shar dist-tarZ \
+	dist-xz dist-zip distcheck distclean distclean-generic \
+	distclean-hdr distclean-libtool distclean-tags distcleancheck \
+	distdir distuninstallcheck dvi dvi-am html html-am info \
+	info-am install install-am install-data install-data-am \
+	install-dvi install-dvi-am install-exec install-exec-am \
+	install-html install-html-am install-info install-info-am \
+	install-man install-pdf install-pdf-am install-pipedocsDATA \
+	install-ps install-ps-am install-strip installcheck \
+	installcheck-am installdirs installdirs-am maintainer-clean \
+	maintainer-clean-generic mostlyclean mostlyclean-generic \
+	mostlyclean-libtool pdf pdf-am ps ps-am tags tags-recursive \
+	uninstall uninstall-am uninstall-local uninstall-pipedocsDATA
+
+
+ at MAINTAINER_MODE_TRUE@clean-local: clean-html
+
+ at MAINTAINER_MODE_TRUE@dist-hook: html
+ at MAINTAINER_MODE_TRUE@	@if test -d $(top_srcdir)/html; then \
+ at MAINTAINER_MODE_TRUE@	  echo "cp -pr $(top_srcdir)/html $(distdir)"; \
+ at MAINTAINER_MODE_TRUE@	  cp -pr $(top_srcdir)/html $(distdir); \
+ at MAINTAINER_MODE_TRUE@	fi
+ at MAINTAINER_MODE_TRUE@	find $(distdir) -type d ! -perm -222 -exec chmod u+w {} \; -o \
+ at MAINTAINER_MODE_TRUE@	-type f ! -perm -222 -exec chmod u+w {} \; || chmod -R u+w $(distdir)
+
+ at MAINTAINER_MODE_FALSE@clean-local:
+
+uninstall-local: uninstall-html
+
+libtool: $(LIBTOOL_DEPS)
+	$(SHELL) ./config.status --recheck
+
+ at MAINTAINER_MODE_TRUE@html-am: 
+ at MAINTAINER_MODE_TRUE@	@if test -f doxygen/Doxyfile; then \
+ at MAINTAINER_MODE_TRUE@	  echo "cd doxygen && $(DOXYGEN)"; \
+ at MAINTAINER_MODE_TRUE@	  d=`pwd`; cd doxygen && $(DOXYGEN); cd $$d; \
+ at MAINTAINER_MODE_TRUE@	  if test -n "$(POST_DOXYGEN_CLEANFILES)"; then \
+ at MAINTAINER_MODE_TRUE@	    cd $(top_srcdir)/html && rm -f $(POST_DOXYGEN_CLEANFILES); \
+ at MAINTAINER_MODE_TRUE@	  fi; \
+ at MAINTAINER_MODE_TRUE@	else \
+ at MAINTAINER_MODE_TRUE@	  echo "Nothing to be done for \`$@'."; \
+ at MAINTAINER_MODE_TRUE@	fi
+
+ at MAINTAINER_MODE_TRUE@clean-html: clean-html-am
+
+ at MAINTAINER_MODE_TRUE@clean-html-am:
+ at MAINTAINER_MODE_TRUE@	-rm -rf $(top_builddir)/html
+
+ at MAINTAINER_MODE_TRUE@install-html-am: html-am install-html-generic
+
+ at MAINTAINER_MODE_FALSE@install-html-am: install-html-generic
+
+install-html: install-html-recursive
+
+install-html-generic:
+	@$(NORMAL_INSTALL)
+	@if test -d $(top_srcdir)/html; then \
+	  echo "$(mkinstalldirs) $(DESTDIR)$(htmldir)"; \
+	  $(mkinstalldirs) $(DESTDIR)$(htmldir); \
+	  list="`ls -1 $(top_srcdir)/html`"; \
+	  for p in $$list; do \
+	    if test -f $(top_srcdir)/html/$$p; then \
+	      echo " $(INSTALL_DATA) $(top_srcdir)/html/$$p $(DESTDIR)$(htmldir)/$$p"; \
+	      $(INSTALL_DATA) $(top_srcdir)/html/$$p $(DESTDIR)$(htmldir)/$$p; \
+	    else if test -f $$p; then \
+	      echo " $(INSTALL_DATA) $$p $(DESTDIR)$(htmldir)/$$p"; \
+	      $(INSTALL_DATA) $$p $(DESTDIR)$(htmldir)/$$p; \
+	    fi; fi; \
+	  done; \
+	fi
+
+uninstall-html:
+	@$(NORMAL_UNINSTALL)
+	@list="`ls -1 $(DESTDIR)$(htmldir)`"; for p in $$list; do \
+	  echo " rm -f $(DESTDIR)$(htmldir)/$$p"; \
+	  rm -f $(DESTDIR)$(htmldir)/$$p; \
+	done
+
+$(HTML_RECURSIVE_TARGETS):
+	@set fnord $(MAKEFLAGS); amf=$$2; \
+	dot_seen=no; \
+	target=`echo $@ | sed s/-recursive//`; \
+	list='$(HTML_SUBDIRS)'; for subdir in $$list; do \
+	  echo "Making $$target in $$subdir"; \
+	  if test "$$subdir" = "."; then \
+	    dot_seen=yes; \
+	    local_target="$$target-am"; \
+	  else \
+	    local_target="$$target"; \
+	  fi; \
+	  (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
+	   || case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \
+	done; \
+	if test "$$dot_seen" = "no"; then \
+	  $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \
+	fi; test -z "$$fail"
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/Makefile.purify.in b/Makefile.purify.in
new file mode 100644
index 0000000..a8e3b25
--- /dev/null
+++ b/Makefile.purify.in
@@ -0,0 +1,109 @@
+#*******************************************************************************
+# E.S.O. - VLT project
+#
+# "@(#) $Id: Makefile.purify.in,v 1.2 2008/05/09 14:01:27 cguirao Exp $"
+#
+# Makefile of Pipeline subsystem.
+#
+# who       when        what
+# --------  ----------  ----------------------------------------------
+#
+
+
+ifdef MAKE_PURE
+  ENABLE_PURIFY=on
+  ENABLE_PURECOV=on
+  ENABLE_PURE=on
+endif
+
+ifdef MAKE_PUREGUI
+  ENABLE_PURIFY=on
+  ENABLE_PURECOV=on
+endif
+
+ifdef MAKE_PURIFY
+  ENABLE_PURIFY=on
+endif
+
+ifdef MAKE_PURECOV
+  ENABLE_PURECOV=on
+endif
+
+#           -user-path="../test:../src:src:test" \
+
+
+ifdef ENABLE_PURIFY
+  PURIFY = purify \
+           -always-use-cache-dir \
+           -g++=yes \
+           -log-file=./.purifydir/MemoryReport \
+           -linker=$(GNU_ROOT)/bin/ld \
+           -append-logfile=yes \
+           -messages=batch \
+           -dlclose-mode=2 \
+           -view-file=./.purifydir/purify-%v.pv \
+           -chain-length=100
+
+else
+  PURIFY =
+endif
+
+ifdef MAKE_PUREGUI
+  PURIFY = purify \
+           -always-use-cache-dir \
+           -user-path="../test:../src:src:test" \
+           -g++=yes \
+           -linker=$(GNU_ROOT)/bin/ld
+endif
+
+ifdef ENABLE_PURECOV
+  PURECOV = purecov \
+	    -always-use-cache-dir \
+	    -counts-file=./.purifydir/purecov-%v.pcv
+  ifdef MAKE_PUREGUI
+    PURECOV = purecov -always-use-cache-dir
+  endif
+else
+  PURECOV =
+endif 
+
+ifdef ENABLE_PURIFY
+   CCLD = "$(PURIFY)" $(CC)
+endif
+
+ifdef ENABLE_PURECOV
+   CCLD = "$(PURECOV)" $(CC)
+endif
+
+ifdef ENABLE_PURE
+   CCLD = "$(PURIFY) $(PURECOV)" $(CC)
+endif
+
+
+pureReport:
+	@ purecov -export=.purifydir/CoverageReport .purifydir/*.pcv
+	@ echo "== Purify coverage report in '.purifydir/CoverageReport'."
+
+pureGUI:
+	@ ls purecov*.pcv > /dev/null 2>&1; if [ $$? = "0" ]; then purecov -view purecov*.pcv &; fi
+	@ ls purify*.pv > /dev/null 2>&1; if [ $$? = "0" ]; then \
+	for member in `ls purify*.pv`; \
+	do purify -view $$member &  \
+	done \
+	fi
+
+check-am: make_links
+
+make_links:
+ifeq ($(ENABLE_PURIFY),on)
+	- at if  [ ! -d .purifydir ]; then mkdir .purifydir ; fi
+endif
+
+ifeq ($(ENABLE_PURECOV),on)
+	- at if  [ ! -d .purifydir ]; then mkdir .purifydir ;fi
+endif
+
+clean-am: pureClean
+
+pureClean:
+	-@ rm -rf .purifydir/*
diff --git a/NEWS b/NEWS
new file mode 100644
index 0000000..e69de29
diff --git a/README b/README
new file mode 100644
index 0000000..957044d
--- /dev/null
+++ b/README
@@ -0,0 +1,230 @@
+This distribution contains:
+
+README                     This file
+sinfo-manual-4.0.pdf       The SINFONI pipeline manual
+install_pipeline           Install script
+qfits-6.2.0.tar.gz         QFITS 6.2.0
+cpl-3.1.tar.gz             CPL 3.1  
+esorex-3.6.1.tar.gz        esorex 3.6.1
+gasgano-2.2.7.tar.gz       GASGANO 2.2.7 for SunOS 5.8
+sinfo-1.7.1.tar.gz         SINFONI 1.7.1
+sinfo-calib-1.7.1.tar.gz   SNFONI calibration files 1.7.1
+
+To install the pipeline execute the install script:
+
+     ./install_pipeline
+
+The script will ask you to specify under what directory the software 
+and the calibration files should be installed: you can just press 
+return if the proposed default (i.e., your home-directory) suits you. 
+The software installation will be organised in bin/, lib/, include/ and share/ 
+ sub-directories, while the calibration files will be 
+installed in a calib/ sub-directory. Pay attection to any information,
+in particular possible warnings indicated by the install script.
+To have Gasgano installed you need to make sure you have the Java Development
+Kit (JDK, version 1.5.0) properly installed and the JAVA_HOME environment 
+varaiable set to point to the directory where the JDK is.
+
+Alternatively, if you are an experienced user you may decide to install 
+only the packages you are actually going to use. To do so you have to 
+unpack, configure, build and install the packages of your choice manually. 
+You can find the packages in the root directory of the unpacked distribution,
+or even download them separately from the corresponding Web pages. Note 
+that a cksum file is associated to each package: this file has the same 
+name of the corresponding package, but with extension .cksum instead of 
+.tar.gz (e.g., the cksum of package cpl-3.1.tar.gz is contained in the 
+file cpl-3.1.cksum). It is advisable to compare the output of the cksum 
+command applied to each package with the content of the corresponding files, 
+to ensure that the packages were copied withour errors. In general, the 
+output of the command
+
+  $ cksum *.gz
+
+should be identical to the output of the command
+
+  $ cat *.cksum
+
+The qfits package must be installed first, and the CPL package next.
+The eclipse-sinfo external library need to be installed before the SINFONI package.
+It doesn't matter in what order are installed 'esorex', 'gasgano', and
+the SINFONI pipeline recipes. The packages 'esorex' and 'gasgano' are 
+optional, but you need at least one of them for using the SINFONI recipes.
+
+For detailed instructions on the installation of the individual packages
+please refer to the information provided by these packages. Below we provide
+a typical sequence of steps for a valid installation.
+
+        1.  In the following we suppose the user does an installation in the directory ${HOME}/pipelines
+            It is usefult to have set the environment variables CPLDIR  and QFITSDIR. In our case as
+            (the following commands are valid if the user is running bash):
+
+  $ export CPLDIR=${HOME}/pipelines
+  $ export QFITSDIR=${CPLDIR}
+  $ mkdir ${CPLDIR}
+
+
+
+        2. Unpack the qfits distribution into a directory of your choice
+           and 'cd' into it. For example:
+
+  $ gunzip qfits-6.2.0.tar.gz
+  $ tar -xvf qfits-6.2.0.tar
+  $ cd qfits-6.2.0/
+
+        3. Setup the qfits package by running configure. For example
+           (assuming that CPLDIR points to a chosen installation directory):
+
+  $ ./configure --prefix=${CPLDIR} --max-ptrs=562168 --debug
+           Note: 
+           Mac users at this stage should also specify --enable-memory-mode=1
+
+        4. Build and install qfits. For example:
+
+  $ make
+  $ make install
+  $ cd ..
+
+
+
+        5. Unpack the CPL distribution into a directory of your choice and
+           'cd' into it. For example:
+
+  $ gunzip cpl-3.1.tar.gz
+  $ tar -xvf cpl-3.1.tar
+  $ cd cpl-3.1/
+
+        5. Run 'configure' with the appropriate settings (installation
+           prefix, location of the qfits installation...). For example
+           (assuming that CPLDIR points to a chosen installation directory,
+           and that qfits was installed in the same location):
+
+  $ ./configure --prefix=${CPLDIR} --enable-debug
+
+        6. Build and install 'cpl':
+
+  $ make
+  $ make install
+  $ cd ..
+
+
+        7. Unpack the 'esorex' distribution into a directory of your choice
+           and 'cd' into it. For example:
+
+  $ gunzip esorex-3.6.1.tar.gz
+  $ tar -xvf esorex-3.6.1.tar
+  $ cd esorex-3.6.1/
+
+        8. Run 'configure' with the appropriate settings. For example
+           (assuming that CPLDIR points to a chosen installation directory,
+           and that both qfits and CPL were installed in the same location):
+
+  $  ./configure --prefix=${CPLDIR} --enable-debug
+
+
+        9. Build and install 'esorex':
+
+  $ make
+  $ make install
+  $ cd ..
+
+
+       10. Unpack the appropriate gasgano distribution for your platform
+           in your home directory (ensure that you are not overwriting
+           an existing 'gasgano' installation): 
+
+  $ cd
+  $ gunzip -c gasgano-2.2.4-Linux.tar.gz | tar xovf -
+  $ ln -s gasgano-2.2.4-Linux gasgano
+  $ export PATH="$HOME/gasgano/bin:"$PATH
+  $ cd -
+
+
+       11. Unpack the 'sinfo' distribution into a directory of your choice and
+           'cd' into it. For example:
+
+  $ gunzip  sinfo-1.7.1.tar.gz
+  $ tar -xvf sinfo-1.7.1.tar
+  $ cd sinfo-1.7.1
+
+       12. Run 'configure' with the appropriate settings. For example
+           (assuming that CPLDIR points to a chosen installation directory,
+           and that both qfits, CPL, eclipse-sinfo were installed in the same location):
+
+  $ ./configure --prefix=${CPLDIR} --enable-debug
+
+
+       13. Build and install 'sinfo':
+
+  $ make
+  $ make install
+
+       14. Include CPLDIR in your path:
+
+  $ export PATH=${PATH}:${CPLDIR}
+
+       15. Include CPLDIR in your path:
+
+  $ export PATH=${PATH}:${CPLDIR}/bin
+
+
+       16. In order to use the just installed SINFONI recipes with 'esorex'
+           you can either use the '--recipe-dir' command line option
+           and pass the path to the recipes as argument when esorex 
+           is called. For instance,
+
+  $ esorex --recipe-dir=${HOME}/pipelines/lib/sinfo/plugins/sinfo-1.7.1 [...]
+        
+           Alternatively an 'esorex' run-time configuration file can be
+           created and/or updated, either manually or automatically (i.e.,
+           using 'esorex' itself). The 'esorex' configuration file is
+
+              $HOME/.esorex/esorex.rc
+
+           If no such file exists you can create it by simply running
+           esorex with the command line option '--create-config' and
+           the '--recipe-dir' option. For example:
+
+ $ esorex --create-config --recipe-dir=${HOME}/pipelines/lib/sinfo/plugins/sinfo-1.7.1
+
+           If the configuration file already exists, the same command 
+           will simply upgrade it: all previous settings apart from 
+           the entry 'esorex.caller.recipe-dir' are inherited from 
+           the previous file. The original file will be saved as 
+           $HOME/.esorex/esorex.rc.bak .
+
+           The 'esorex' configuration file may also be modified using
+           an editor. The entry 'esorex.caller.recipe-dir' is the one
+           to modify. Its argument consist of a colon separated list 
+           of directories, which are searched for recipes when running 
+           'esorex'. For instance:
+
+esorex.caller.recipe-dir=<path1>:<path2>:${HOME}/pipelines/lib/sinfo/plugins/sinfo-1.7.1
+
+           where the new path is appended to the existing ones. Old paths,
+           valid for older installations, may be removed from the list.
+
+           For further information about configuring 'esorex' please refer
+           to the 'esorex' documentation (see http://www.eso.org/cpl).
+        
+        2. To add the just installed SINFONI recipe set to the 'gasgano'
+           recipe set, you must use the preferences dialog of 'gasgano'. 
+           It is available from its 'File' menu on the main window. 
+           Select the tab 'Recipe Configuration' and modify the recipe 
+           set as found appropriate. For instance, if SINFONI was installed 
+           in the directory tree rooted at ${HOME}/pipelines 
+           you will find the recipes in:
+
+              ${HOME}/pipelines/lib/sinfo/plugins/sinfo-1.7.1
+
+           For further information about 'gasgano' please refer to the 
+           Gasgano User Manual (see http://www.eso.org/gasgano).
+
+           
+Reporting Bugs
+--------------
+
+Please report any bugs to <usd-help at eso.org>
+
+For support contact <usd-help at eso.org> or, alternatively, Lars Lundin 
+<llundin at eso.org> for the installation script, and Andrea Modigliani <amodigli at eso.org>
+for the pipeline recipes.
diff --git a/TODO b/TODO
new file mode 100644
index 0000000..e69de29
diff --git a/acinclude.m4 b/acinclude.m4
new file mode 100644
index 0000000..1344684
--- /dev/null
+++ b/acinclude.m4
@@ -0,0 +1,300 @@
+# LIB_CHECK_FFTW
+#------------------
+# Checks for the fftw library and header files.
+AC_DEFUN([LIB_CHECK_FFTW],
+[
+
+    AC_MSG_CHECKING([for fftw])
+
+    detmon_fftw_check_header="fftw3.h"
+    detmon_fftw_check_lib="libfftw3f.a"
+
+    detmon_fftw_includes=""
+    detmon_fftw_libraries=""
+
+    AC_ARG_WITH(fftw,
+                AC_HELP_STRING([--with-fftw],
+                               [location where fftw is installed]),
+                [
+                    detmon_with_fftw_includes=$withval/include
+                    detmon_with_fftw_libs=$withval/lib
+                ])
+
+    AC_ARG_WITH(fftw-includes,
+                AC_HELP_STRING([--with-fftw-includes],
+                               [location of the fftw header files]),
+                detmon_with_fftw_includes=$withval)
+
+    AC_ARG_WITH(fftw-libs,
+                AC_HELP_STRING([--with-fftw-libs],
+                               [location of the fftw library]),
+                detmon_with_fftw_libs=$withval)
+
+    AC_ARG_ENABLE(fftw-test,
+                  AC_HELP_STRING([--disable-fftw-test],
+                                 [disables checks for the fftw library and headers]),
+                  detmon_enable_fftw_test=$enableval,
+                  detmon_enable_fftw_test=yes)
+
+
+    if test "x$detmon_enable_fftw_test" = xyes; then
+
+        # Check for the fftw includes
+
+        if test -z "$detmon_with_fftw_includes"; then
+            detmon_fftw_incdirs="/opt/fftw/include /usr/local/include /usr/include"
+
+            test -n "$CPLDIR" && detmon_fftw_incdirs="$CPLDIR/include \
+                $detmon_fftw_incdirs"
+
+            test -n "$FFTWDIR" && detmon_fftw_incdirs="$FFTWDIR/include \
+                $detmon_fftw_incdirs"
+        else
+            detmon_fftw_incdirs="$detmon_with_fftw_includes"
+        fi
+
+        ESO_FIND_FILE($detmon_fftw_check_header, $detmon_fftw_incdirs,
+                      detmon_fftw_includes)
+
+
+        # Check for the fftw library
+
+        if test -z "$detmon_with_fftw_libs"; then
+            detmon_fftw_libdirs="/opt/fftw/lib /usr/local/lib /usr/lib"
+
+            test -n "$CPLDIR" && detmon_fftw_libdirs="$CPLDIR/lib \
+                $detmon_fftw_libdirs"
+
+            test -n "$FFTWDIR" && detmon_fftw_libdirs="$FFTWDIR/lib \
+                $detmon_fftw_libdirs"
+        else
+            detmon_fftw_libdirs="$detmon_with_fftw_libs"
+        fi
+
+        ESO_FIND_FILE($detmon_fftw_check_lib, $detmon_fftw_libdirs,
+                      detmon_fftw_libraries)
+
+
+        if test x"$detmon_fftw_includes" = xno || \
+            test x"$detmon_fftw_libraries" = xno; then
+            detmon_fftw_notfound=""
+
+            if test x"$detmon_fftw_includes" = xno; then
+                if test x"$detmon_fftw_libraries" = xno; then
+                    detmon_fftw_notfound="(headers and libraries)"
+                else
+                    detmon_fftw_notfound="(headers)"
+                fi
+            else
+                detmon_fftw_notfound="(libraries)"
+            fi
+
+            AC_MSG_ERROR([fftw $detmon_fftw_notfound was not found on your system. Please check!])
+        else
+            AC_MSG_RESULT([libraries $detmon_fftw_libraries, headers $detmon_fftw_includes])
+        fi
+
+        # Set up the symbols
+
+        FFTW_INCLUDES="-I$detmon_fftw_includes"
+        FFTW_LDFLAGS="-L$detmon_fftw_libraries"
+        LDFLAGS="$LDFLAGS $FFTW_LDFLAGS"
+        AC_CHECK_LIB([fftw3f], [main], [LIBFFTWC="-lfftw3f"], AC_MSG_ERROR([Library fftwcblas not found]))
+	AC_DEFINE_UNQUOTED(HAVE_FFTW, 1, [Define to 1 if you have FFTW v. 3.X])
+        LIBS="$LIBS $LIBFFTWC"
+        LIBFFTW="$LIBFFTWC"
+    else
+        AC_MSG_RESULT([disabled])
+        AC_MSG_WARN([fftw checks have been disabled! This package may not build!])
+        FFTW_INCLUDES=""
+        FFTW_LDFLAGS=""
+        LIBFFTW=""
+    fi
+
+    # To be removed after CPL switched to fftw
+    FFTW_INCLUDES="$FFTW_INCLUDES"
+    FFTW_LDFLAGS="$FFTW_LDFLAGS"
+    LIBFFTW="$LIBFFTW"
+
+    AC_SUBST(FFTW_INCLUDES)
+    AC_SUBST(FFTW_LDFLAGS)
+    AC_SUBST(LIBFFTW)
+
+])
+
+
+# SINFONI_SET_PREFIX(PREFIX)
+#---------------------------
+AC_DEFUN([SINFONI_SET_PREFIX],
+[
+    unset CDPATH
+    # make $PIPE_HOME the default for the installation
+    AC_PREFIX_DEFAULT($1)
+
+    if test "x$prefix" = "xNONE"; then
+        prefix=$ac_default_prefix
+        ac_configure_args="$ac_configure_args --prefix $prefix"
+    fi
+
+    if test "x$exec_prefix" = "xNONE"; then
+        exec_prefix=$prefix
+    fi
+
+])
+
+
+# SINFONI_SET_VERSION_INFO(VERSION, [CURRENT], [REVISION], [AGE])
+#----------------------------------------------------------------
+# Setup various version information, especially the libtool versioning
+AC_DEFUN([SINFONI_SET_VERSION_INFO],
+[
+    sinfoni_version=`echo "$1" | sed -e 's/[[a-z,A-Z]].*$//'`
+
+    sinfoni_major_version=`echo "$sinfoni_version" | \
+        sed 's/\([[0-9]]*\).\(.*\)/\1/'`
+    sinfoni_minor_version=`echo "$sinfoni_version" | \
+        sed 's/\([[0-9]]*\).\([[0-9]]*\)\(.*\)/\2/'`
+    sinfoni_micro_version=`echo "$sinfoni_version" | \
+        sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
+
+    if test -z "$sinfoni_major_version"; then
+        sinfoni_major_version=0
+    fi
+
+    if test -z "$sinfoni_minor_version"; then
+        sinfoni_minor_version=0
+    fi
+
+    if test -z "$sinfoni_micro_version"; then
+        sinfoni_micro_version=0
+    fi
+
+    SINFONI_VERSION="$sinfoni_version"
+    SINFONI_MAJOR_VERSION=$sinfoni_major_version
+    SINFONI_MINOR_VERSION=$sinfoni_minor_version
+    SINFONI_MICRO_VERSION=$sinfoni_micro_version
+
+    if test -z "$4"; then
+        SINFONI_INTERFACE_AGE=0
+    else
+        SINFONI_INTERFACE_AGE="$4"
+    fi
+
+    SINFONI_BINARY_AGE=`expr 100 '*' $SINFONI_MINOR_VERSION + $SINFONI_MICRO_VERSION`
+    SINFONI_BINARY_VERSION=`expr 10000 '*' $SINFONI_MAJOR_VERSION + \
+                          $SINFONI_BINARY_AGE`
+
+    AC_SUBST(SINFONI_VERSION)
+    AC_SUBST(SINFONI_MAJOR_VERSION)
+    AC_SUBST(SINFONI_MINOR_VERSION)
+    AC_SUBST(SINFONI_MICRO_VERSION)
+    AC_SUBST(SINFONI_INTERFACE_AGE)
+    AC_SUBST(SINFONI_BINARY_VERSION)
+    AC_SUBST(SINFONI_BINARY_AGE)
+
+    AC_DEFINE_UNQUOTED(SINFONI_MAJOR_VERSION, $SINFONI_MAJOR_VERSION,
+                       [SINFONI major version number])
+    AC_DEFINE_UNQUOTED(SINFONI_MINOR_VERSION, $SINFONI_MINOR_VERSION,
+                       [SINFONI minor version number])
+    AC_DEFINE_UNQUOTED(SINFONI_MICRO_VERSION, $SINFONI_MICRO_VERSION,
+                       [SINFONI micro version number])
+    AC_DEFINE_UNQUOTED(SINFONI_INTERFACE_AGE, $SINFONI_INTERFACE_AGE,
+                       [SINFONI interface age])
+    AC_DEFINE_UNQUOTED(SINFONI_BINARY_VERSION, $SINFONI_BINARY_VERSION,
+                       [SINFONI binary version number])
+    AC_DEFINE_UNQUOTED(SINFONI_BINARY_AGE, $SINFONI_BINARY_AGE,
+                       [SINFONI binary age])
+
+    ESO_SET_LIBRARY_VERSION([$2], [$3], [$4])
+])
+
+
+# SINFONI_SET_PATHS
+#------------------
+# Define auxiliary directories of the installed directory tree.
+AC_DEFUN([SINFONI_SET_PATHS],
+[
+
+    if test -z "$plugindir"; then
+        plugindir='${libdir}/esopipes-plugins/${PACKAGE}-${VERSION}'
+    fi
+
+    if test -z "$privatelibdir"; then
+        privatelibdir='${libdir}/${PACKAGE}-${VERSION}'
+    fi
+
+    if test -z "$pipedocsdir"; then
+        pipedocsdir='${datadir}/doc/esopipes/${PACKAGE}-${VERSION}'
+    fi
+
+    htmldir='${pipedocsdir}/html'
+
+    if test -z "$confdir"; then
+       configdir='${datadir}/${PACKAGE}/config'
+    fi
+
+
+
+    AC_SUBST(plugindir)
+    AC_SUBST(privatelibdir)
+    AC_SUBST(htmldir)
+    AC_SUBST(pipedocsdir)
+    AC_SUBST(configdir)
+
+
+    # Define a preprocesor symbol for the plugin search paths
+
+    AC_DEFINE_UNQUOTED(SINFONI_PLUGIN_DIR, "esopipes-plugins",
+                       [Plugin directory tree prefix])
+
+    eval plugin_dir="$plugindir"
+    plugin_path=`eval echo $plugin_dir | \
+                sed -e "s/\/${PACKAGE}-${VERSION}.*$//"`
+
+    AC_DEFINE_UNQUOTED(SINFONI_PLUGIN_PATH, "$plugin_path",
+                       [Absolute path to the plugin directory tree])
+
+])
+
+
+# SINFONI_CREATE_SYMBOLS
+#-----------------------
+# Define include and library related makefile symbols
+AC_DEFUN([SINFONI_CREATE_SYMBOLS],
+[
+
+    # Symbols for package include file and library search paths
+
+    SINFONI_INCLUDES='-I$(top_srcdir)/sinfoni'
+    IRPLIB_INCLUDES='-I$(top_srcdir)/irplib'
+
+    SINFONI_LDFLAGS='-L$(top_builddir)/sinfoni'
+    IRPLIB_LDFLAGS='-I$(top_builddir)/irplib'
+
+    # Library aliases
+
+    LIBSINFONI='$(top_builddir)/sinfoni/libsinfo.la'
+    LIBIRPLIB='$(top_builddir)/irplib/libirplib.la'
+
+    # Substitute the defined symbols
+
+    AC_SUBST(SINFONI_INCLUDES)
+    AC_SUBST(SINFONI_LDFLAGS)
+    AC_SUBST(IRPLIB_INCLUDES)
+    AC_SUBST(IRPLIB_LDFLAGS)
+
+    AC_SUBST(LIBSINFONI)
+    AC_SUBST(LIBIRPLIB)
+
+    # Check for CPL and user defined libraries
+    AC_REQUIRE([CPL_CHECK_LIBS])
+    AC_REQUIRE([ESO_CHECK_EXTRA_LIBS])
+
+    all_includes='$(SINFONI_INCLUDES) $(IRPLIB_INCLUDES) $(CPL_INCLUDES) $(CX_INCLUDES) $(EXTRA_INCLUDES)'
+    all_ldflags='$(SINFONI_LDFLAGS) $(IRPLIB_LDFLAGS) $(CPL_LDFLAGS) $(CX_LDFLAGS) $(EXTRA_LDFLAGS)'
+
+    AC_SUBST(all_includes)
+    AC_SUBST(all_ldflags)
+])
+
+
diff --git a/aclocal.m4 b/aclocal.m4
new file mode 100644
index 0000000..abf663d
--- /dev/null
+++ b/aclocal.m4
@@ -0,0 +1,1075 @@
+# generated automatically by aclocal 1.11 -*- Autoconf -*-
+
+# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
+# 2005, 2006, 2007, 2008, 2009  Free Software Foundation, Inc.
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+m4_ifndef([AC_AUTOCONF_VERSION],
+  [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl
+m4_if(m4_defn([AC_AUTOCONF_VERSION]), [2.63],,
+[m4_warning([this file was generated for autoconf 2.63.
+You have another version of autoconf.  It may work, but is not guaranteed to.
+If you have problems, you may need to regenerate the build system entirely.
+To do so, use the procedure documented by the package, typically `autoreconf'.])])
+
+# Copyright (C) 2002, 2003, 2005, 2006, 2007, 2008  Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# AM_AUTOMAKE_VERSION(VERSION)
+# ----------------------------
+# Automake X.Y traces this macro to ensure aclocal.m4 has been
+# generated from the m4 files accompanying Automake X.Y.
+# (This private macro should not be called outside this file.)
+AC_DEFUN([AM_AUTOMAKE_VERSION],
+[am__api_version='1.11'
+dnl Some users find AM_AUTOMAKE_VERSION and mistake it for a way to
+dnl require some minimum version.  Point them to the right macro.
+m4_if([$1], [1.11], [],
+      [AC_FATAL([Do not call $0, use AM_INIT_AUTOMAKE([$1]).])])dnl
+])
+
+# _AM_AUTOCONF_VERSION(VERSION)
+# -----------------------------
+# aclocal traces this macro to find the Autoconf version.
+# This is a private macro too.  Using m4_define simplifies
+# the logic in aclocal, which can simply ignore this definition.
+m4_define([_AM_AUTOCONF_VERSION], [])
+
+# AM_SET_CURRENT_AUTOMAKE_VERSION
+# -------------------------------
+# Call AM_AUTOMAKE_VERSION and AM_AUTOMAKE_VERSION so they can be traced.
+# This function is AC_REQUIREd by AM_INIT_AUTOMAKE.
+AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION],
+[AM_AUTOMAKE_VERSION([1.11])dnl
+m4_ifndef([AC_AUTOCONF_VERSION],
+  [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl
+_AM_AUTOCONF_VERSION(m4_defn([AC_AUTOCONF_VERSION]))])
+
+# AM_AUX_DIR_EXPAND                                         -*- Autoconf -*-
+
+# Copyright (C) 2001, 2003, 2005  Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# For projects using AC_CONFIG_AUX_DIR([foo]), Autoconf sets
+# $ac_aux_dir to `$srcdir/foo'.  In other projects, it is set to
+# `$srcdir', `$srcdir/..', or `$srcdir/../..'.
+#
+# Of course, Automake must honor this variable whenever it calls a
+# tool from the auxiliary directory.  The problem is that $srcdir (and
+# therefore $ac_aux_dir as well) can be either absolute or relative,
+# depending on how configure is run.  This is pretty annoying, since
+# it makes $ac_aux_dir quite unusable in subdirectories: in the top
+# source directory, any form will work fine, but in subdirectories a
+# relative path needs to be adjusted first.
+#
+# $ac_aux_dir/missing
+#    fails when called from a subdirectory if $ac_aux_dir is relative
+# $top_srcdir/$ac_aux_dir/missing
+#    fails if $ac_aux_dir is absolute,
+#    fails when called from a subdirectory in a VPATH build with
+#          a relative $ac_aux_dir
+#
+# The reason of the latter failure is that $top_srcdir and $ac_aux_dir
+# are both prefixed by $srcdir.  In an in-source build this is usually
+# harmless because $srcdir is `.', but things will broke when you
+# start a VPATH build or use an absolute $srcdir.
+#
+# So we could use something similar to $top_srcdir/$ac_aux_dir/missing,
+# iff we strip the leading $srcdir from $ac_aux_dir.  That would be:
+#   am_aux_dir='\$(top_srcdir)/'`expr "$ac_aux_dir" : "$srcdir//*\(.*\)"`
+# and then we would define $MISSING as
+#   MISSING="\${SHELL} $am_aux_dir/missing"
+# This will work as long as MISSING is not called from configure, because
+# unfortunately $(top_srcdir) has no meaning in configure.
+# However there are other variables, like CC, which are often used in
+# configure, and could therefore not use this "fixed" $ac_aux_dir.
+#
+# Another solution, used here, is to always expand $ac_aux_dir to an
+# absolute PATH.  The drawback is that using absolute paths prevent a
+# configured tree to be moved without reconfiguration.
+
+AC_DEFUN([AM_AUX_DIR_EXPAND],
+[dnl Rely on autoconf to set up CDPATH properly.
+AC_PREREQ([2.50])dnl
+# expand $ac_aux_dir to an absolute path
+am_aux_dir=`cd $ac_aux_dir && pwd`
+])
+
+# AM_CONDITIONAL                                            -*- Autoconf -*-
+
+# Copyright (C) 1997, 2000, 2001, 2003, 2004, 2005, 2006, 2008
+# Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# serial 9
+
+# AM_CONDITIONAL(NAME, SHELL-CONDITION)
+# -------------------------------------
+# Define a conditional.
+AC_DEFUN([AM_CONDITIONAL],
+[AC_PREREQ(2.52)dnl
+ ifelse([$1], [TRUE],  [AC_FATAL([$0: invalid condition: $1])],
+	[$1], [FALSE], [AC_FATAL([$0: invalid condition: $1])])dnl
+AC_SUBST([$1_TRUE])dnl
+AC_SUBST([$1_FALSE])dnl
+_AM_SUBST_NOTMAKE([$1_TRUE])dnl
+_AM_SUBST_NOTMAKE([$1_FALSE])dnl
+m4_define([_AM_COND_VALUE_$1], [$2])dnl
+if $2; then
+  $1_TRUE=
+  $1_FALSE='#'
+else
+  $1_TRUE='#'
+  $1_FALSE=
+fi
+AC_CONFIG_COMMANDS_PRE(
+[if test -z "${$1_TRUE}" && test -z "${$1_FALSE}"; then
+  AC_MSG_ERROR([[conditional "$1" was never defined.
+Usually this means the macro was only invoked conditionally.]])
+fi])])
+
+# Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2009
+# Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# serial 10
+
+# There are a few dirty hacks below to avoid letting `AC_PROG_CC' be
+# written in clear, in which case automake, when reading aclocal.m4,
+# will think it sees a *use*, and therefore will trigger all it's
+# C support machinery.  Also note that it means that autoscan, seeing
+# CC etc. in the Makefile, will ask for an AC_PROG_CC use...
+
+
+# _AM_DEPENDENCIES(NAME)
+# ----------------------
+# See how the compiler implements dependency checking.
+# NAME is "CC", "CXX", "GCJ", or "OBJC".
+# We try a few techniques and use that to set a single cache variable.
+#
+# We don't AC_REQUIRE the corresponding AC_PROG_CC since the latter was
+# modified to invoke _AM_DEPENDENCIES(CC); we would have a circular
+# dependency, and given that the user is not expected to run this macro,
+# just rely on AC_PROG_CC.
+AC_DEFUN([_AM_DEPENDENCIES],
+[AC_REQUIRE([AM_SET_DEPDIR])dnl
+AC_REQUIRE([AM_OUTPUT_DEPENDENCY_COMMANDS])dnl
+AC_REQUIRE([AM_MAKE_INCLUDE])dnl
+AC_REQUIRE([AM_DEP_TRACK])dnl
+
+ifelse([$1], CC,   [depcc="$CC"   am_compiler_list=],
+       [$1], CXX,  [depcc="$CXX"  am_compiler_list=],
+       [$1], OBJC, [depcc="$OBJC" am_compiler_list='gcc3 gcc'],
+       [$1], UPC,  [depcc="$UPC"  am_compiler_list=],
+       [$1], GCJ,  [depcc="$GCJ"  am_compiler_list='gcc3 gcc'],
+                   [depcc="$$1"   am_compiler_list=])
+
+AC_CACHE_CHECK([dependency style of $depcc],
+               [am_cv_$1_dependencies_compiler_type],
+[if test -z "$AMDEP_TRUE" && test -f "$am_depcomp"; then
+  # We make a subdir and do the tests there.  Otherwise we can end up
+  # making bogus files that we don't know about and never remove.  For
+  # instance it was reported that on HP-UX the gcc test will end up
+  # making a dummy file named `D' -- because `-MD' means `put the output
+  # in D'.
+  mkdir conftest.dir
+  # Copy depcomp to subdir because otherwise we won't find it if we're
+  # using a relative directory.
+  cp "$am_depcomp" conftest.dir
+  cd conftest.dir
+  # We will build objects and dependencies in a subdirectory because
+  # it helps to detect inapplicable dependency modes.  For instance
+  # both Tru64's cc and ICC support -MD to output dependencies as a
+  # side effect of compilation, but ICC will put the dependencies in
+  # the current directory while Tru64 will put them in the object
+  # directory.
+  mkdir sub
+
+  am_cv_$1_dependencies_compiler_type=none
+  if test "$am_compiler_list" = ""; then
+     am_compiler_list=`sed -n ['s/^#*\([a-zA-Z0-9]*\))$/\1/p'] < ./depcomp`
+  fi
+  am__universal=false
+  m4_case([$1], [CC],
+    [case " $depcc " in #(
+     *\ -arch\ *\ -arch\ *) am__universal=true ;;
+     esac],
+    [CXX],
+    [case " $depcc " in #(
+     *\ -arch\ *\ -arch\ *) am__universal=true ;;
+     esac])
+
+  for depmode in $am_compiler_list; do
+    # Setup a source with many dependencies, because some compilers
+    # like to wrap large dependency lists on column 80 (with \), and
+    # we should not choose a depcomp mode which is confused by this.
+    #
+    # We need to recreate these files for each test, as the compiler may
+    # overwrite some of them when testing with obscure command lines.
+    # This happens at least with the AIX C compiler.
+    : > sub/conftest.c
+    for i in 1 2 3 4 5 6; do
+      echo '#include "conftst'$i'.h"' >> sub/conftest.c
+      # Using `: > sub/conftst$i.h' creates only sub/conftst1.h with
+      # Solaris 8's {/usr,}/bin/sh.
+      touch sub/conftst$i.h
+    done
+    echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf
+
+    # We check with `-c' and `-o' for the sake of the "dashmstdout"
+    # mode.  It turns out that the SunPro C++ compiler does not properly
+    # handle `-M -o', and we need to detect this.  Also, some Intel
+    # versions had trouble with output in subdirs
+    am__obj=sub/conftest.${OBJEXT-o}
+    am__minus_obj="-o $am__obj"
+    case $depmode in
+    gcc)
+      # This depmode causes a compiler race in universal mode.
+      test "$am__universal" = false || continue
+      ;;
+    nosideeffect)
+      # after this tag, mechanisms are not by side-effect, so they'll
+      # only be used when explicitly requested
+      if test "x$enable_dependency_tracking" = xyes; then
+	continue
+      else
+	break
+      fi
+      ;;
+    msvisualcpp | msvcmsys)
+      # This compiler won't grok `-c -o', but also, the minuso test has
+      # not run yet.  These depmodes are late enough in the game, and
+      # so weak that their functioning should not be impacted.
+      am__obj=conftest.${OBJEXT-o}
+      am__minus_obj=
+      ;;
+    none) break ;;
+    esac
+    if depmode=$depmode \
+       source=sub/conftest.c object=$am__obj \
+       depfile=sub/conftest.Po tmpdepfile=sub/conftest.TPo \
+       $SHELL ./depcomp $depcc -c $am__minus_obj sub/conftest.c \
+         >/dev/null 2>conftest.err &&
+       grep sub/conftst1.h sub/conftest.Po > /dev/null 2>&1 &&
+       grep sub/conftst6.h sub/conftest.Po > /dev/null 2>&1 &&
+       grep $am__obj sub/conftest.Po > /dev/null 2>&1 &&
+       ${MAKE-make} -s -f confmf > /dev/null 2>&1; then
+      # icc doesn't choke on unknown options, it will just issue warnings
+      # or remarks (even with -Werror).  So we grep stderr for any message
+      # that says an option was ignored or not supported.
+      # When given -MP, icc 7.0 and 7.1 complain thusly:
+      #   icc: Command line warning: ignoring option '-M'; no argument required
+      # The diagnosis changed in icc 8.0:
+      #   icc: Command line remark: option '-MP' not supported
+      if (grep 'ignoring option' conftest.err ||
+          grep 'not supported' conftest.err) >/dev/null 2>&1; then :; else
+        am_cv_$1_dependencies_compiler_type=$depmode
+        break
+      fi
+    fi
+  done
+
+  cd ..
+  rm -rf conftest.dir
+else
+  am_cv_$1_dependencies_compiler_type=none
+fi
+])
+AC_SUBST([$1DEPMODE], [depmode=$am_cv_$1_dependencies_compiler_type])
+AM_CONDITIONAL([am__fastdep$1], [
+  test "x$enable_dependency_tracking" != xno \
+  && test "$am_cv_$1_dependencies_compiler_type" = gcc3])
+])
+
+
+# AM_SET_DEPDIR
+# -------------
+# Choose a directory name for dependency files.
+# This macro is AC_REQUIREd in _AM_DEPENDENCIES
+AC_DEFUN([AM_SET_DEPDIR],
+[AC_REQUIRE([AM_SET_LEADING_DOT])dnl
+AC_SUBST([DEPDIR], ["${am__leading_dot}deps"])dnl
+])
+
+
+# AM_DEP_TRACK
+# ------------
+AC_DEFUN([AM_DEP_TRACK],
+[AC_ARG_ENABLE(dependency-tracking,
+[  --disable-dependency-tracking  speeds up one-time build
+  --enable-dependency-tracking   do not reject slow dependency extractors])
+if test "x$enable_dependency_tracking" != xno; then
+  am_depcomp="$ac_aux_dir/depcomp"
+  AMDEPBACKSLASH='\'
+fi
+AM_CONDITIONAL([AMDEP], [test "x$enable_dependency_tracking" != xno])
+AC_SUBST([AMDEPBACKSLASH])dnl
+_AM_SUBST_NOTMAKE([AMDEPBACKSLASH])dnl
+])
+
+# Generate code to set up dependency tracking.              -*- Autoconf -*-
+
+# Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2008
+# Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+#serial 5
+
+# _AM_OUTPUT_DEPENDENCY_COMMANDS
+# ------------------------------
+AC_DEFUN([_AM_OUTPUT_DEPENDENCY_COMMANDS],
+[{
+  # Autoconf 2.62 quotes --file arguments for eval, but not when files
+  # are listed without --file.  Let's play safe and only enable the eval
+  # if we detect the quoting.
+  case $CONFIG_FILES in
+  *\'*) eval set x "$CONFIG_FILES" ;;
+  *)   set x $CONFIG_FILES ;;
+  esac
+  shift
+  for mf
+  do
+    # Strip MF so we end up with the name of the file.
+    mf=`echo "$mf" | sed -e 's/:.*$//'`
+    # Check whether this is an Automake generated Makefile or not.
+    # We used to match only the files named `Makefile.in', but
+    # some people rename them; so instead we look at the file content.
+    # Grep'ing the first line is not enough: some people post-process
+    # each Makefile.in and add a new line on top of each file to say so.
+    # Grep'ing the whole file is not good either: AIX grep has a line
+    # limit of 2048, but all sed's we know have understand at least 4000.
+    if sed -n 's,^#.*generated by automake.*,X,p' "$mf" | grep X >/dev/null 2>&1; then
+      dirpart=`AS_DIRNAME("$mf")`
+    else
+      continue
+    fi
+    # Extract the definition of DEPDIR, am__include, and am__quote
+    # from the Makefile without running `make'.
+    DEPDIR=`sed -n 's/^DEPDIR = //p' < "$mf"`
+    test -z "$DEPDIR" && continue
+    am__include=`sed -n 's/^am__include = //p' < "$mf"`
+    test -z "am__include" && continue
+    am__quote=`sed -n 's/^am__quote = //p' < "$mf"`
+    # When using ansi2knr, U may be empty or an underscore; expand it
+    U=`sed -n 's/^U = //p' < "$mf"`
+    # Find all dependency output files, they are included files with
+    # $(DEPDIR) in their names.  We invoke sed twice because it is the
+    # simplest approach to changing $(DEPDIR) to its actual value in the
+    # expansion.
+    for file in `sed -n "
+      s/^$am__include $am__quote\(.*(DEPDIR).*\)$am__quote"'$/\1/p' <"$mf" | \
+	 sed -e 's/\$(DEPDIR)/'"$DEPDIR"'/g' -e 's/\$U/'"$U"'/g'`; do
+      # Make sure the directory exists.
+      test -f "$dirpart/$file" && continue
+      fdir=`AS_DIRNAME(["$file"])`
+      AS_MKDIR_P([$dirpart/$fdir])
+      # echo "creating $dirpart/$file"
+      echo '# dummy' > "$dirpart/$file"
+    done
+  done
+}
+])# _AM_OUTPUT_DEPENDENCY_COMMANDS
+
+
+# AM_OUTPUT_DEPENDENCY_COMMANDS
+# -----------------------------
+# This macro should only be invoked once -- use via AC_REQUIRE.
+#
+# This code is only required when automatic dependency tracking
+# is enabled.  FIXME.  This creates each `.P' file that we will
+# need in order to bootstrap the dependency handling code.
+AC_DEFUN([AM_OUTPUT_DEPENDENCY_COMMANDS],
+[AC_CONFIG_COMMANDS([depfiles],
+     [test x"$AMDEP_TRUE" != x"" || _AM_OUTPUT_DEPENDENCY_COMMANDS],
+     [AMDEP_TRUE="$AMDEP_TRUE" ac_aux_dir="$ac_aux_dir"])
+])
+
+
+# Copyright (C) 1996, 1998, 1999, 2000, 2001, 2002, 2003, 2005
+# Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# serial 3
+
+AC_DEFUN([AM_WITH_DMALLOC],
+[AC_MSG_CHECKING([if malloc debugging is wanted])
+AC_ARG_WITH(dmalloc,
+[  --with-dmalloc          use dmalloc, as in
+			  http://www.dmalloc.com/dmalloc.tar.gz],
+[if test "$withval" = yes; then
+  AC_MSG_RESULT(yes)
+  AC_DEFINE(WITH_DMALLOC,1,
+	    [Define if using the dmalloc debugging malloc package])
+  LIBS="$LIBS -ldmalloc"
+  LDFLAGS="$LDFLAGS -g"
+else
+  AC_MSG_RESULT(no)
+fi], [AC_MSG_RESULT(no)])
+])
+
+AU_DEFUN([fp_WITH_DMALLOC], [AM_WITH_DMALLOC])
+
+# Copyright (C) 1996, 1997, 2000, 2001, 2003, 2005
+# Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# serial 8
+
+# AM_CONFIG_HEADER is obsolete.  It has been replaced by AC_CONFIG_HEADERS.
+AU_DEFUN([AM_CONFIG_HEADER], [AC_CONFIG_HEADERS($@)])
+
+# Do all the work for Automake.                             -*- Autoconf -*-
+
+# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
+# 2005, 2006, 2008, 2009 Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# serial 16
+
+# This macro actually does too much.  Some checks are only needed if
+# your package does certain things.  But this isn't really a big deal.
+
+# AM_INIT_AUTOMAKE(PACKAGE, VERSION, [NO-DEFINE])
+# AM_INIT_AUTOMAKE([OPTIONS])
+# -----------------------------------------------
+# The call with PACKAGE and VERSION arguments is the old style
+# call (pre autoconf-2.50), which is being phased out.  PACKAGE
+# and VERSION should now be passed to AC_INIT and removed from
+# the call to AM_INIT_AUTOMAKE.
+# We support both call styles for the transition.  After
+# the next Automake release, Autoconf can make the AC_INIT
+# arguments mandatory, and then we can depend on a new Autoconf
+# release and drop the old call support.
+AC_DEFUN([AM_INIT_AUTOMAKE],
+[AC_PREREQ([2.62])dnl
+dnl Autoconf wants to disallow AM_ names.  We explicitly allow
+dnl the ones we care about.
+m4_pattern_allow([^AM_[A-Z]+FLAGS$])dnl
+AC_REQUIRE([AM_SET_CURRENT_AUTOMAKE_VERSION])dnl
+AC_REQUIRE([AC_PROG_INSTALL])dnl
+if test "`cd $srcdir && pwd`" != "`pwd`"; then
+  # Use -I$(srcdir) only when $(srcdir) != ., so that make's output
+  # is not polluted with repeated "-I."
+  AC_SUBST([am__isrc], [' -I$(srcdir)'])_AM_SUBST_NOTMAKE([am__isrc])dnl
+  # test to see if srcdir already configured
+  if test -f $srcdir/config.status; then
+    AC_MSG_ERROR([source directory already configured; run "make distclean" there first])
+  fi
+fi
+
+# test whether we have cygpath
+if test -z "$CYGPATH_W"; then
+  if (cygpath --version) >/dev/null 2>/dev/null; then
+    CYGPATH_W='cygpath -w'
+  else
+    CYGPATH_W=echo
+  fi
+fi
+AC_SUBST([CYGPATH_W])
+
+# Define the identity of the package.
+dnl Distinguish between old-style and new-style calls.
+m4_ifval([$2],
+[m4_ifval([$3], [_AM_SET_OPTION([no-define])])dnl
+ AC_SUBST([PACKAGE], [$1])dnl
+ AC_SUBST([VERSION], [$2])],
+[_AM_SET_OPTIONS([$1])dnl
+dnl Diagnose old-style AC_INIT with new-style AM_AUTOMAKE_INIT.
+m4_if(m4_ifdef([AC_PACKAGE_NAME], 1)m4_ifdef([AC_PACKAGE_VERSION], 1), 11,,
+  [m4_fatal([AC_INIT should be called with package and version arguments])])dnl
+ AC_SUBST([PACKAGE], ['AC_PACKAGE_TARNAME'])dnl
+ AC_SUBST([VERSION], ['AC_PACKAGE_VERSION'])])dnl
+
+_AM_IF_OPTION([no-define],,
+[AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of package])
+ AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Version number of package])])dnl
+
+# Some tools Automake needs.
+AC_REQUIRE([AM_SANITY_CHECK])dnl
+AC_REQUIRE([AC_ARG_PROGRAM])dnl
+AM_MISSING_PROG(ACLOCAL, aclocal-${am__api_version})
+AM_MISSING_PROG(AUTOCONF, autoconf)
+AM_MISSING_PROG(AUTOMAKE, automake-${am__api_version})
+AM_MISSING_PROG(AUTOHEADER, autoheader)
+AM_MISSING_PROG(MAKEINFO, makeinfo)
+AC_REQUIRE([AM_PROG_INSTALL_SH])dnl
+AC_REQUIRE([AM_PROG_INSTALL_STRIP])dnl
+AC_REQUIRE([AM_PROG_MKDIR_P])dnl
+# We need awk for the "check" target.  The system "awk" is bad on
+# some platforms.
+AC_REQUIRE([AC_PROG_AWK])dnl
+AC_REQUIRE([AC_PROG_MAKE_SET])dnl
+AC_REQUIRE([AM_SET_LEADING_DOT])dnl
+_AM_IF_OPTION([tar-ustar], [_AM_PROG_TAR([ustar])],
+	      [_AM_IF_OPTION([tar-pax], [_AM_PROG_TAR([pax])],
+			     [_AM_PROG_TAR([v7])])])
+_AM_IF_OPTION([no-dependencies],,
+[AC_PROVIDE_IFELSE([AC_PROG_CC],
+		  [_AM_DEPENDENCIES(CC)],
+		  [define([AC_PROG_CC],
+			  defn([AC_PROG_CC])[_AM_DEPENDENCIES(CC)])])dnl
+AC_PROVIDE_IFELSE([AC_PROG_CXX],
+		  [_AM_DEPENDENCIES(CXX)],
+		  [define([AC_PROG_CXX],
+			  defn([AC_PROG_CXX])[_AM_DEPENDENCIES(CXX)])])dnl
+AC_PROVIDE_IFELSE([AC_PROG_OBJC],
+		  [_AM_DEPENDENCIES(OBJC)],
+		  [define([AC_PROG_OBJC],
+			  defn([AC_PROG_OBJC])[_AM_DEPENDENCIES(OBJC)])])dnl
+])
+_AM_IF_OPTION([silent-rules], [AC_REQUIRE([AM_SILENT_RULES])])dnl
+dnl The `parallel-tests' driver may need to know about EXEEXT, so add the
+dnl `am__EXEEXT' conditional if _AM_COMPILER_EXEEXT was seen.  This macro
+dnl is hooked onto _AC_COMPILER_EXEEXT early, see below.
+AC_CONFIG_COMMANDS_PRE(dnl
+[m4_provide_if([_AM_COMPILER_EXEEXT],
+  [AM_CONDITIONAL([am__EXEEXT], [test -n "$EXEEXT"])])])dnl
+])
+
+dnl Hook into `_AC_COMPILER_EXEEXT' early to learn its expansion.  Do not
+dnl add the conditional right here, as _AC_COMPILER_EXEEXT may be further
+dnl mangled by Autoconf and run in a shell conditional statement.
+m4_define([_AC_COMPILER_EXEEXT],
+m4_defn([_AC_COMPILER_EXEEXT])[m4_provide([_AM_COMPILER_EXEEXT])])
+
+
+# When config.status generates a header, we must update the stamp-h file.
+# This file resides in the same directory as the config header
+# that is generated.  The stamp files are numbered to have different names.
+
+# Autoconf calls _AC_AM_CONFIG_HEADER_HOOK (when defined) in the
+# loop where config.status creates the headers, so we can generate
+# our stamp files there.
+AC_DEFUN([_AC_AM_CONFIG_HEADER_HOOK],
+[# Compute $1's index in $config_headers.
+_am_arg=$1
+_am_stamp_count=1
+for _am_header in $config_headers :; do
+  case $_am_header in
+    $_am_arg | $_am_arg:* )
+      break ;;
+    * )
+      _am_stamp_count=`expr $_am_stamp_count + 1` ;;
+  esac
+done
+echo "timestamp for $_am_arg" >`AS_DIRNAME(["$_am_arg"])`/stamp-h[]$_am_stamp_count])
+
+# Copyright (C) 2001, 2003, 2005, 2008  Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# AM_PROG_INSTALL_SH
+# ------------------
+# Define $install_sh.
+AC_DEFUN([AM_PROG_INSTALL_SH],
+[AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl
+if test x"${install_sh}" != xset; then
+  case $am_aux_dir in
+  *\ * | *\	*)
+    install_sh="\${SHELL} '$am_aux_dir/install-sh'" ;;
+  *)
+    install_sh="\${SHELL} $am_aux_dir/install-sh"
+  esac
+fi
+AC_SUBST(install_sh)])
+
+# Copyright (C) 2003, 2005  Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# serial 2
+
+# Check whether the underlying file-system supports filenames
+# with a leading dot.  For instance MS-DOS doesn't.
+AC_DEFUN([AM_SET_LEADING_DOT],
+[rm -rf .tst 2>/dev/null
+mkdir .tst 2>/dev/null
+if test -d .tst; then
+  am__leading_dot=.
+else
+  am__leading_dot=_
+fi
+rmdir .tst 2>/dev/null
+AC_SUBST([am__leading_dot])])
+
+# Add --enable-maintainer-mode option to configure.         -*- Autoconf -*-
+# From Jim Meyering
+
+# Copyright (C) 1996, 1998, 2000, 2001, 2002, 2003, 2004, 2005, 2008
+# Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# serial 5
+
+# AM_MAINTAINER_MODE([DEFAULT-MODE])
+# ----------------------------------
+# Control maintainer-specific portions of Makefiles.
+# Default is to disable them, unless `enable' is passed literally.
+# For symmetry, `disable' may be passed as well.  Anyway, the user
+# can override the default with the --enable/--disable switch.
+AC_DEFUN([AM_MAINTAINER_MODE],
+[m4_case(m4_default([$1], [disable]),
+       [enable], [m4_define([am_maintainer_other], [disable])],
+       [disable], [m4_define([am_maintainer_other], [enable])],
+       [m4_define([am_maintainer_other], [enable])
+        m4_warn([syntax], [unexpected argument to AM@&t at _MAINTAINER_MODE: $1])])
+AC_MSG_CHECKING([whether to am_maintainer_other maintainer-specific portions of Makefiles])
+  dnl maintainer-mode's default is 'disable' unless 'enable' is passed
+  AC_ARG_ENABLE([maintainer-mode],
+[  --][am_maintainer_other][-maintainer-mode  am_maintainer_other make rules and dependencies not useful
+			  (and sometimes confusing) to the casual installer],
+      [USE_MAINTAINER_MODE=$enableval],
+      [USE_MAINTAINER_MODE=]m4_if(am_maintainer_other, [enable], [no], [yes]))
+  AC_MSG_RESULT([$USE_MAINTAINER_MODE])
+  AM_CONDITIONAL([MAINTAINER_MODE], [test $USE_MAINTAINER_MODE = yes])
+  MAINT=$MAINTAINER_MODE_TRUE
+  AC_SUBST([MAINT])dnl
+]
+)
+
+AU_DEFUN([jm_MAINTAINER_MODE], [AM_MAINTAINER_MODE])
+
+# Check to see how 'make' treats includes.	            -*- Autoconf -*-
+
+# Copyright (C) 2001, 2002, 2003, 2005, 2009  Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# serial 4
+
+# AM_MAKE_INCLUDE()
+# -----------------
+# Check to see how make treats includes.
+AC_DEFUN([AM_MAKE_INCLUDE],
+[am_make=${MAKE-make}
+cat > confinc << 'END'
+am__doit:
+	@echo this is the am__doit target
+.PHONY: am__doit
+END
+# If we don't find an include directive, just comment out the code.
+AC_MSG_CHECKING([for style of include used by $am_make])
+am__include="#"
+am__quote=
+_am_result=none
+# First try GNU make style include.
+echo "include confinc" > confmf
+# Ignore all kinds of additional output from `make'.
+case `$am_make -s -f confmf 2> /dev/null` in #(
+*the\ am__doit\ target*)
+  am__include=include
+  am__quote=
+  _am_result=GNU
+  ;;
+esac
+# Now try BSD make style include.
+if test "$am__include" = "#"; then
+   echo '.include "confinc"' > confmf
+   case `$am_make -s -f confmf 2> /dev/null` in #(
+   *the\ am__doit\ target*)
+     am__include=.include
+     am__quote="\""
+     _am_result=BSD
+     ;;
+   esac
+fi
+AC_SUBST([am__include])
+AC_SUBST([am__quote])
+AC_MSG_RESULT([$_am_result])
+rm -f confinc confmf
+])
+
+# Copyright (C) 1999, 2000, 2001, 2003, 2004, 2005, 2008
+# Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# serial 6
+
+# AM_PROG_CC_C_O
+# --------------
+# Like AC_PROG_CC_C_O, but changed for automake.
+AC_DEFUN([AM_PROG_CC_C_O],
+[AC_REQUIRE([AC_PROG_CC_C_O])dnl
+AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl
+AC_REQUIRE_AUX_FILE([compile])dnl
+# FIXME: we rely on the cache variable name because
+# there is no other way.
+set dummy $CC
+am_cc=`echo $[2] | sed ['s/[^a-zA-Z0-9_]/_/g;s/^[0-9]/_/']`
+eval am_t=\$ac_cv_prog_cc_${am_cc}_c_o
+if test "$am_t" != yes; then
+   # Losing compiler, so override with the script.
+   # FIXME: It is wrong to rewrite CC.
+   # But if we don't then we get into trouble of one sort or another.
+   # A longer-term fix would be to have automake use am__CC in this case,
+   # and then we could set am__CC="\$(top_srcdir)/compile \$(CC)"
+   CC="$am_aux_dir/compile $CC"
+fi
+dnl Make sure AC_PROG_CC is never called again, or it will override our
+dnl setting of CC.
+m4_define([AC_PROG_CC],
+          [m4_fatal([AC_PROG_CC cannot be called after AM_PROG_CC_C_O])])
+])
+
+# Fake the existence of programs that GNU maintainers use.  -*- Autoconf -*-
+
+# Copyright (C) 1997, 1999, 2000, 2001, 2003, 2004, 2005, 2008
+# Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# serial 6
+
+# AM_MISSING_PROG(NAME, PROGRAM)
+# ------------------------------
+AC_DEFUN([AM_MISSING_PROG],
+[AC_REQUIRE([AM_MISSING_HAS_RUN])
+$1=${$1-"${am_missing_run}$2"}
+AC_SUBST($1)])
+
+
+# AM_MISSING_HAS_RUN
+# ------------------
+# Define MISSING if not defined so far and test if it supports --run.
+# If it does, set am_missing_run to use it, otherwise, to nothing.
+AC_DEFUN([AM_MISSING_HAS_RUN],
+[AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl
+AC_REQUIRE_AUX_FILE([missing])dnl
+if test x"${MISSING+set}" != xset; then
+  case $am_aux_dir in
+  *\ * | *\	*)
+    MISSING="\${SHELL} \"$am_aux_dir/missing\"" ;;
+  *)
+    MISSING="\${SHELL} $am_aux_dir/missing" ;;
+  esac
+fi
+# Use eval to expand $SHELL
+if eval "$MISSING --run true"; then
+  am_missing_run="$MISSING --run "
+else
+  am_missing_run=
+  AC_MSG_WARN([`missing' script is too old or missing])
+fi
+])
+
+# Copyright (C) 2003, 2004, 2005, 2006  Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# AM_PROG_MKDIR_P
+# ---------------
+# Check for `mkdir -p'.
+AC_DEFUN([AM_PROG_MKDIR_P],
+[AC_PREREQ([2.60])dnl
+AC_REQUIRE([AC_PROG_MKDIR_P])dnl
+dnl Automake 1.8 to 1.9.6 used to define mkdir_p.  We now use MKDIR_P,
+dnl while keeping a definition of mkdir_p for backward compatibility.
+dnl @MKDIR_P@ is magic: AC_OUTPUT adjusts its value for each Makefile.
+dnl However we cannot define mkdir_p as $(MKDIR_P) for the sake of
+dnl Makefile.ins that do not define MKDIR_P, so we do our own
+dnl adjustment using top_builddir (which is defined more often than
+dnl MKDIR_P).
+AC_SUBST([mkdir_p], ["$MKDIR_P"])dnl
+case $mkdir_p in
+  [[\\/$]]* | ?:[[\\/]]*) ;;
+  */*) mkdir_p="\$(top_builddir)/$mkdir_p" ;;
+esac
+])
+
+# Helper functions for option handling.                     -*- Autoconf -*-
+
+# Copyright (C) 2001, 2002, 2003, 2005, 2008  Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# serial 4
+
+# _AM_MANGLE_OPTION(NAME)
+# -----------------------
+AC_DEFUN([_AM_MANGLE_OPTION],
+[[_AM_OPTION_]m4_bpatsubst($1, [[^a-zA-Z0-9_]], [_])])
+
+# _AM_SET_OPTION(NAME)
+# ------------------------------
+# Set option NAME.  Presently that only means defining a flag for this option.
+AC_DEFUN([_AM_SET_OPTION],
+[m4_define(_AM_MANGLE_OPTION([$1]), 1)])
+
+# _AM_SET_OPTIONS(OPTIONS)
+# ----------------------------------
+# OPTIONS is a space-separated list of Automake options.
+AC_DEFUN([_AM_SET_OPTIONS],
+[m4_foreach_w([_AM_Option], [$1], [_AM_SET_OPTION(_AM_Option)])])
+
+# _AM_IF_OPTION(OPTION, IF-SET, [IF-NOT-SET])
+# -------------------------------------------
+# Execute IF-SET if OPTION is set, IF-NOT-SET otherwise.
+AC_DEFUN([_AM_IF_OPTION],
+[m4_ifset(_AM_MANGLE_OPTION([$1]), [$2], [$3])])
+
+# Check to make sure that the build environment is sane.    -*- Autoconf -*-
+
+# Copyright (C) 1996, 1997, 2000, 2001, 2003, 2005, 2008
+# Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# serial 5
+
+# AM_SANITY_CHECK
+# ---------------
+AC_DEFUN([AM_SANITY_CHECK],
+[AC_MSG_CHECKING([whether build environment is sane])
+# Just in case
+sleep 1
+echo timestamp > conftest.file
+# Reject unsafe characters in $srcdir or the absolute working directory
+# name.  Accept space and tab only in the latter.
+am_lf='
+'
+case `pwd` in
+  *[[\\\"\#\$\&\'\`$am_lf]]*)
+    AC_MSG_ERROR([unsafe absolute working directory name]);;
+esac
+case $srcdir in
+  *[[\\\"\#\$\&\'\`$am_lf\ \	]]*)
+    AC_MSG_ERROR([unsafe srcdir value: `$srcdir']);;
+esac
+
+# Do `set' in a subshell so we don't clobber the current shell's
+# arguments.  Must try -L first in case configure is actually a
+# symlink; some systems play weird games with the mod time of symlinks
+# (eg FreeBSD returns the mod time of the symlink's containing
+# directory).
+if (
+   set X `ls -Lt "$srcdir/configure" conftest.file 2> /dev/null`
+   if test "$[*]" = "X"; then
+      # -L didn't work.
+      set X `ls -t "$srcdir/configure" conftest.file`
+   fi
+   rm -f conftest.file
+   if test "$[*]" != "X $srcdir/configure conftest.file" \
+      && test "$[*]" != "X conftest.file $srcdir/configure"; then
+
+      # If neither matched, then we have a broken ls.  This can happen
+      # if, for instance, CONFIG_SHELL is bash and it inherits a
+      # broken ls alias from the environment.  This has actually
+      # happened.  Such a system could not be considered "sane".
+      AC_MSG_ERROR([ls -t appears to fail.  Make sure there is not a broken
+alias in your environment])
+   fi
+
+   test "$[2]" = conftest.file
+   )
+then
+   # Ok.
+   :
+else
+   AC_MSG_ERROR([newly created file is older than distributed files!
+Check your system clock])
+fi
+AC_MSG_RESULT(yes)])
+
+# Copyright (C) 2001, 2003, 2005  Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# AM_PROG_INSTALL_STRIP
+# ---------------------
+# One issue with vendor `install' (even GNU) is that you can't
+# specify the program used to strip binaries.  This is especially
+# annoying in cross-compiling environments, where the build's strip
+# is unlikely to handle the host's binaries.
+# Fortunately install-sh will honor a STRIPPROG variable, so we
+# always use install-sh in `make install-strip', and initialize
+# STRIPPROG with the value of the STRIP variable (set by the user).
+AC_DEFUN([AM_PROG_INSTALL_STRIP],
+[AC_REQUIRE([AM_PROG_INSTALL_SH])dnl
+# Installed binaries are usually stripped using `strip' when the user
+# run `make install-strip'.  However `strip' might not be the right
+# tool to use in cross-compilation environments, therefore Automake
+# will honor the `STRIP' environment variable to overrule this program.
+dnl Don't test for $cross_compiling = yes, because it might be `maybe'.
+if test "$cross_compiling" != no; then
+  AC_CHECK_TOOL([STRIP], [strip], :)
+fi
+INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s"
+AC_SUBST([INSTALL_STRIP_PROGRAM])])
+
+# Copyright (C) 2006, 2008  Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# serial 2
+
+# _AM_SUBST_NOTMAKE(VARIABLE)
+# ---------------------------
+# Prevent Automake from outputting VARIABLE = @VARIABLE@ in Makefile.in.
+# This macro is traced by Automake.
+AC_DEFUN([_AM_SUBST_NOTMAKE])
+
+# AM_SUBST_NOTMAKE(VARIABLE)
+# ---------------------------
+# Public sister of _AM_SUBST_NOTMAKE.
+AC_DEFUN([AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE($@)])
+
+# Check how to create a tarball.                            -*- Autoconf -*-
+
+# Copyright (C) 2004, 2005  Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# serial 2
+
+# _AM_PROG_TAR(FORMAT)
+# --------------------
+# Check how to create a tarball in format FORMAT.
+# FORMAT should be one of `v7', `ustar', or `pax'.
+#
+# Substitute a variable $(am__tar) that is a command
+# writing to stdout a FORMAT-tarball containing the directory
+# $tardir.
+#     tardir=directory && $(am__tar) > result.tar
+#
+# Substitute a variable $(am__untar) that extract such
+# a tarball read from stdin.
+#     $(am__untar) < result.tar
+AC_DEFUN([_AM_PROG_TAR],
+[# Always define AMTAR for backward compatibility.
+AM_MISSING_PROG([AMTAR], [tar])
+m4_if([$1], [v7],
+     [am__tar='${AMTAR} chof - "$$tardir"'; am__untar='${AMTAR} xf -'],
+     [m4_case([$1], [ustar],, [pax],,
+              [m4_fatal([Unknown tar format])])
+AC_MSG_CHECKING([how to create a $1 tar archive])
+# Loop over all known methods to create a tar archive until one works.
+_am_tools='gnutar m4_if([$1], [ustar], [plaintar]) pax cpio none'
+_am_tools=${am_cv_prog_tar_$1-$_am_tools}
+# Do not fold the above two line into one, because Tru64 sh and
+# Solaris sh will not grok spaces in the rhs of `-'.
+for _am_tool in $_am_tools
+do
+  case $_am_tool in
+  gnutar)
+    for _am_tar in tar gnutar gtar;
+    do
+      AM_RUN_LOG([$_am_tar --version]) && break
+    done
+    am__tar="$_am_tar --format=m4_if([$1], [pax], [posix], [$1]) -chf - "'"$$tardir"'
+    am__tar_="$_am_tar --format=m4_if([$1], [pax], [posix], [$1]) -chf - "'"$tardir"'
+    am__untar="$_am_tar -xf -"
+    ;;
+  plaintar)
+    # Must skip GNU tar: if it does not support --format= it doesn't create
+    # ustar tarball either.
+    (tar --version) >/dev/null 2>&1 && continue
+    am__tar='tar chf - "$$tardir"'
+    am__tar_='tar chf - "$tardir"'
+    am__untar='tar xf -'
+    ;;
+  pax)
+    am__tar='pax -L -x $1 -w "$$tardir"'
+    am__tar_='pax -L -x $1 -w "$tardir"'
+    am__untar='pax -r'
+    ;;
+  cpio)
+    am__tar='find "$$tardir" -print | cpio -o -H $1 -L'
+    am__tar_='find "$tardir" -print | cpio -o -H $1 -L'
+    am__untar='cpio -i -H $1 -d'
+    ;;
+  none)
+    am__tar=false
+    am__tar_=false
+    am__untar=false
+    ;;
+  esac
+
+  # If the value was cached, stop now.  We just wanted to have am__tar
+  # and am__untar set.
+  test -n "${am_cv_prog_tar_$1}" && break
+
+  # tar/untar a dummy directory, and stop if the command works
+  rm -rf conftest.dir
+  mkdir conftest.dir
+  echo GrepMe > conftest.dir/file
+  AM_RUN_LOG([tardir=conftest.dir && eval $am__tar_ >conftest.tar])
+  rm -rf conftest.dir
+  if test -s conftest.tar; then
+    AM_RUN_LOG([$am__untar <conftest.tar])
+    grep GrepMe conftest.dir/file >/dev/null 2>&1 && break
+  fi
+done
+rm -rf conftest.dir
+
+AC_CACHE_VAL([am_cv_prog_tar_$1], [am_cv_prog_tar_$1=$_am_tool])
+AC_MSG_RESULT([$am_cv_prog_tar_$1])])
+AC_SUBST([am__tar])
+AC_SUBST([am__untar])
+]) # _AM_PROG_TAR
+
+m4_include([m4macros/cpl.m4])
+m4_include([m4macros/eso.m4])
+m4_include([m4macros/libtool.m4])
+m4_include([m4macros/ltoptions.m4])
+m4_include([m4macros/ltsugar.m4])
+m4_include([m4macros/ltversion.m4])
+m4_include([m4macros/lt~obsolete.m4])
+m4_include([m4macros/purify.m4])
+m4_include([acinclude.m4])
diff --git a/admin/compile b/admin/compile
new file mode 100755
index 0000000..ec64c62
--- /dev/null
+++ b/admin/compile
@@ -0,0 +1,143 @@
+#! /bin/sh
+# Wrapper for compilers which do not understand `-c -o'.
+
+scriptversion=2009-04-28.21; # UTC
+
+# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2009  Free Software
+# Foundation, Inc.
+# Written by Tom Tromey <tromey at cygnus.com>.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that program.
+
+# This file is maintained in Automake, please report
+# bugs to <bug-automake at gnu.org> or send patches to
+# <automake-patches at gnu.org>.
+
+case $1 in
+  '')
+     echo "$0: No command.  Try \`$0 --help' for more information." 1>&2
+     exit 1;
+     ;;
+  -h | --h*)
+    cat <<\EOF
+Usage: compile [--help] [--version] PROGRAM [ARGS]
+
+Wrapper for compilers which do not understand `-c -o'.
+Remove `-o dest.o' from ARGS, run PROGRAM with the remaining
+arguments, and rename the output as expected.
+
+If you are trying to build a whole package this is not the
+right script to run: please start by reading the file `INSTALL'.
+
+Report bugs to <bug-automake at gnu.org>.
+EOF
+    exit $?
+    ;;
+  -v | --v*)
+    echo "compile $scriptversion"
+    exit $?
+    ;;
+esac
+
+ofile=
+cfile=
+eat=
+
+for arg
+do
+  if test -n "$eat"; then
+    eat=
+  else
+    case $1 in
+      -o)
+	# configure might choose to run compile as `compile cc -o foo foo.c'.
+	# So we strip `-o arg' only if arg is an object.
+	eat=1
+	case $2 in
+	  *.o | *.obj)
+	    ofile=$2
+	    ;;
+	  *)
+	    set x "$@" -o "$2"
+	    shift
+	    ;;
+	esac
+	;;
+      *.c)
+	cfile=$1
+	set x "$@" "$1"
+	shift
+	;;
+      *)
+	set x "$@" "$1"
+	shift
+	;;
+    esac
+  fi
+  shift
+done
+
+if test -z "$ofile" || test -z "$cfile"; then
+  # If no `-o' option was seen then we might have been invoked from a
+  # pattern rule where we don't need one.  That is ok -- this is a
+  # normal compilation that the losing compiler can handle.  If no
+  # `.c' file was seen then we are probably linking.  That is also
+  # ok.
+  exec "$@"
+fi
+
+# Name of file we expect compiler to create.
+cofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'`
+
+# Create the lock directory.
+# Note: use `[/\\:.-]' here to ensure that we don't use the same name
+# that we are using for the .o file.  Also, base the name on the expected
+# object file name, since that is what matters with a parallel build.
+lockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d
+while true; do
+  if mkdir "$lockdir" >/dev/null 2>&1; then
+    break
+  fi
+  sleep 1
+done
+# FIXME: race condition here if user kills between mkdir and trap.
+trap "rmdir '$lockdir'; exit 1" 1 2 15
+
+# Run the compile.
+"$@"
+ret=$?
+
+if test -f "$cofile"; then
+  mv "$cofile" "$ofile"
+elif test -f "${cofile}bj"; then
+  mv "${cofile}bj" "$ofile"
+fi
+
+rmdir "$lockdir"
+exit $ret
+
+# Local Variables:
+# mode: shell-script
+# sh-indentation: 2
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "scriptversion="
+# time-stamp-format: "%:y-%02m-%02d.%02H"
+# time-stamp-time-zone: "UTC"
+# time-stamp-end: "; # UTC"
+# End:
diff --git a/admin/config.guess b/admin/config.guess
new file mode 100755
index 0000000..da83314
--- /dev/null
+++ b/admin/config.guess
@@ -0,0 +1,1561 @@
+#! /bin/sh
+# Attempt to guess a canonical system name.
+#   Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
+#   2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
+#   Free Software Foundation, Inc.
+
+timestamp='2009-04-27'
+
+# This file is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
+# 02110-1301, USA.
+#
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that program.
+
+
+# Originally written by Per Bothner <per at bothner.com>.
+# Please send patches to <config-patches at gnu.org>.  Submit a context
+# diff and a properly formatted ChangeLog entry.
+#
+# This script attempts to guess a canonical system name similar to
+# config.sub.  If it succeeds, it prints the system name on stdout, and
+# exits with 0.  Otherwise, it exits with 1.
+#
+# The plan is that this can be called by configure scripts if you
+# don't specify an explicit build system type.
+
+me=`echo "$0" | sed -e 's,.*/,,'`
+
+usage="\
+Usage: $0 [OPTION]
+
+Output the configuration name of the system \`$me' is run on.
+
+Operation modes:
+  -h, --help         print this help, then exit
+  -t, --time-stamp   print date of last modification, then exit
+  -v, --version      print version number, then exit
+
+Report bugs and patches to <config-patches at gnu.org>."
+
+version="\
+GNU config.guess ($timestamp)
+
+Originally written by Per Bothner.
+Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
+2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+
+This is free software; see the source for copying conditions.  There is NO
+warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
+
+help="
+Try \`$me --help' for more information."
+
+# Parse command line
+while test $# -gt 0 ; do
+  case $1 in
+    --time-stamp | --time* | -t )
+       echo "$timestamp" ; exit ;;
+    --version | -v )
+       echo "$version" ; exit ;;
+    --help | --h* | -h )
+       echo "$usage"; exit ;;
+    -- )     # Stop option processing
+       shift; break ;;
+    - )	# Use stdin as input.
+       break ;;
+    -* )
+       echo "$me: invalid option $1$help" >&2
+       exit 1 ;;
+    * )
+       break ;;
+  esac
+done
+
+if test $# != 0; then
+  echo "$me: too many arguments$help" >&2
+  exit 1
+fi
+
+trap 'exit 1' 1 2 15
+
+# CC_FOR_BUILD -- compiler used by this script. Note that the use of a
+# compiler to aid in system detection is discouraged as it requires
+# temporary files to be created and, as you can see below, it is a
+# headache to deal with in a portable fashion.
+
+# Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still
+# use `HOST_CC' if defined, but it is deprecated.
+
+# Portable tmp directory creation inspired by the Autoconf team.
+
+set_cc_for_build='
+trap "exitcode=\$?; (rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null) && exit \$exitcode" 0 ;
+trap "rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null; exit 1" 1 2 13 15 ;
+: ${TMPDIR=/tmp} ;
+ { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } ||
+ { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir $tmp) ; } ||
+ { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir $tmp) && echo "Warning: creating insecure temp directory" >&2 ; } ||
+ { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } ;
+dummy=$tmp/dummy ;
+tmpfiles="$dummy.c $dummy.o $dummy.rel $dummy" ;
+case $CC_FOR_BUILD,$HOST_CC,$CC in
+ ,,)    echo "int x;" > $dummy.c ;
+	for c in cc gcc c89 c99 ; do
+	  if ($c -c -o $dummy.o $dummy.c) >/dev/null 2>&1 ; then
+	     CC_FOR_BUILD="$c"; break ;
+	  fi ;
+	done ;
+	if test x"$CC_FOR_BUILD" = x ; then
+	  CC_FOR_BUILD=no_compiler_found ;
+	fi
+	;;
+ ,,*)   CC_FOR_BUILD=$CC ;;
+ ,*,*)  CC_FOR_BUILD=$HOST_CC ;;
+esac ; set_cc_for_build= ;'
+
+# This is needed to find uname on a Pyramid OSx when run in the BSD universe.
+# (ghazi at noc.rutgers.edu 1994-08-24)
+if (test -f /.attbin/uname) >/dev/null 2>&1 ; then
+	PATH=$PATH:/.attbin ; export PATH
+fi
+
+UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown
+UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown
+UNAME_SYSTEM=`(uname -s) 2>/dev/null`  || UNAME_SYSTEM=unknown
+UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown
+
+# Note: order is significant - the case branches are not exclusive.
+
+case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
+    *:NetBSD:*:*)
+	# NetBSD (nbsd) targets should (where applicable) match one or
+	# more of the tupples: *-*-netbsdelf*, *-*-netbsdaout*,
+	# *-*-netbsdecoff* and *-*-netbsd*.  For targets that recently
+	# switched to ELF, *-*-netbsd* would select the old
+	# object file format.  This provides both forward
+	# compatibility and a consistent mechanism for selecting the
+	# object file format.
+	#
+	# Note: NetBSD doesn't particularly care about the vendor
+	# portion of the name.  We always set it to "unknown".
+	sysctl="sysctl -n hw.machine_arch"
+	UNAME_MACHINE_ARCH=`(/sbin/$sysctl 2>/dev/null || \
+	    /usr/sbin/$sysctl 2>/dev/null || echo unknown)`
+	case "${UNAME_MACHINE_ARCH}" in
+	    armeb) machine=armeb-unknown ;;
+	    arm*) machine=arm-unknown ;;
+	    sh3el) machine=shl-unknown ;;
+	    sh3eb) machine=sh-unknown ;;
+	    sh5el) machine=sh5le-unknown ;;
+	    *) machine=${UNAME_MACHINE_ARCH}-unknown ;;
+	esac
+	# The Operating System including object format, if it has switched
+	# to ELF recently, or will in the future.
+	case "${UNAME_MACHINE_ARCH}" in
+	    arm*|i386|m68k|ns32k|sh3*|sparc|vax)
+		eval $set_cc_for_build
+		if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \
+			| grep __ELF__ >/dev/null
+		then
+		    # Once all utilities can be ECOFF (netbsdecoff) or a.out (netbsdaout).
+		    # Return netbsd for either.  FIX?
+		    os=netbsd
+		else
+		    os=netbsdelf
+		fi
+		;;
+	    *)
+	        os=netbsd
+		;;
+	esac
+	# The OS release
+	# Debian GNU/NetBSD machines have a different userland, and
+	# thus, need a distinct triplet. However, they do not need
+	# kernel version information, so it can be replaced with a
+	# suitable tag, in the style of linux-gnu.
+	case "${UNAME_VERSION}" in
+	    Debian*)
+		release='-gnu'
+		;;
+	    *)
+		release=`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'`
+		;;
+	esac
+	# Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM:
+	# contains redundant information, the shorter form:
+	# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used.
+	echo "${machine}-${os}${release}"
+	exit ;;
+    *:OpenBSD:*:*)
+	UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'`
+	echo ${UNAME_MACHINE_ARCH}-unknown-openbsd${UNAME_RELEASE}
+	exit ;;
+    *:ekkoBSD:*:*)
+	echo ${UNAME_MACHINE}-unknown-ekkobsd${UNAME_RELEASE}
+	exit ;;
+    *:SolidBSD:*:*)
+	echo ${UNAME_MACHINE}-unknown-solidbsd${UNAME_RELEASE}
+	exit ;;
+    macppc:MirBSD:*:*)
+	echo powerpc-unknown-mirbsd${UNAME_RELEASE}
+	exit ;;
+    *:MirBSD:*:*)
+	echo ${UNAME_MACHINE}-unknown-mirbsd${UNAME_RELEASE}
+	exit ;;
+    alpha:OSF1:*:*)
+	case $UNAME_RELEASE in
+	*4.0)
+		UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'`
+		;;
+	*5.*)
+	        UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'`
+		;;
+	esac
+	# According to Compaq, /usr/sbin/psrinfo has been available on
+	# OSF/1 and Tru64 systems produced since 1995.  I hope that
+	# covers most systems running today.  This code pipes the CPU
+	# types through head -n 1, so we only detect the type of CPU 0.
+	ALPHA_CPU_TYPE=`/usr/sbin/psrinfo -v | sed -n -e 's/^  The alpha \(.*\) processor.*$/\1/p' | head -n 1`
+	case "$ALPHA_CPU_TYPE" in
+	    "EV4 (21064)")
+		UNAME_MACHINE="alpha" ;;
+	    "EV4.5 (21064)")
+		UNAME_MACHINE="alpha" ;;
+	    "LCA4 (21066/21068)")
+		UNAME_MACHINE="alpha" ;;
+	    "EV5 (21164)")
+		UNAME_MACHINE="alphaev5" ;;
+	    "EV5.6 (21164A)")
+		UNAME_MACHINE="alphaev56" ;;
+	    "EV5.6 (21164PC)")
+		UNAME_MACHINE="alphapca56" ;;
+	    "EV5.7 (21164PC)")
+		UNAME_MACHINE="alphapca57" ;;
+	    "EV6 (21264)")
+		UNAME_MACHINE="alphaev6" ;;
+	    "EV6.7 (21264A)")
+		UNAME_MACHINE="alphaev67" ;;
+	    "EV6.8CB (21264C)")
+		UNAME_MACHINE="alphaev68" ;;
+	    "EV6.8AL (21264B)")
+		UNAME_MACHINE="alphaev68" ;;
+	    "EV6.8CX (21264D)")
+		UNAME_MACHINE="alphaev68" ;;
+	    "EV6.9A (21264/EV69A)")
+		UNAME_MACHINE="alphaev69" ;;
+	    "EV7 (21364)")
+		UNAME_MACHINE="alphaev7" ;;
+	    "EV7.9 (21364A)")
+		UNAME_MACHINE="alphaev79" ;;
+	esac
+	# A Pn.n version is a patched version.
+	# A Vn.n version is a released version.
+	# A Tn.n version is a released field test version.
+	# A Xn.n version is an unreleased experimental baselevel.
+	# 1.2 uses "1.2" for uname -r.
+	echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[PVTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
+	exit ;;
+    Alpha\ *:Windows_NT*:*)
+	# How do we know it's Interix rather than the generic POSIX subsystem?
+	# Should we change UNAME_MACHINE based on the output of uname instead
+	# of the specific Alpha model?
+	echo alpha-pc-interix
+	exit ;;
+    21064:Windows_NT:50:3)
+	echo alpha-dec-winnt3.5
+	exit ;;
+    Amiga*:UNIX_System_V:4.0:*)
+	echo m68k-unknown-sysv4
+	exit ;;
+    *:[Aa]miga[Oo][Ss]:*:*)
+	echo ${UNAME_MACHINE}-unknown-amigaos
+	exit ;;
+    *:[Mm]orph[Oo][Ss]:*:*)
+	echo ${UNAME_MACHINE}-unknown-morphos
+	exit ;;
+    *:OS/390:*:*)
+	echo i370-ibm-openedition
+	exit ;;
+    *:z/VM:*:*)
+	echo s390-ibm-zvmoe
+	exit ;;
+    *:OS400:*:*)
+        echo powerpc-ibm-os400
+	exit ;;
+    arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*)
+	echo arm-acorn-riscix${UNAME_RELEASE}
+	exit ;;
+    arm:riscos:*:*|arm:RISCOS:*:*)
+	echo arm-unknown-riscos
+	exit ;;
+    SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*)
+	echo hppa1.1-hitachi-hiuxmpp
+	exit ;;
+    Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*)
+	# akee at wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE.
+	if test "`(/bin/universe) 2>/dev/null`" = att ; then
+		echo pyramid-pyramid-sysv3
+	else
+		echo pyramid-pyramid-bsd
+	fi
+	exit ;;
+    NILE*:*:*:dcosx)
+	echo pyramid-pyramid-svr4
+	exit ;;
+    DRS?6000:unix:4.0:6*)
+	echo sparc-icl-nx6
+	exit ;;
+    DRS?6000:UNIX_SV:4.2*:7* | DRS?6000:isis:4.2*:7*)
+	case `/usr/bin/uname -p` in
+	    sparc) echo sparc-icl-nx7; exit ;;
+	esac ;;
+    s390x:SunOS:*:*)
+	echo ${UNAME_MACHINE}-ibm-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+	exit ;;
+    sun4H:SunOS:5.*:*)
+	echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+	exit ;;
+    sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*)
+	echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+	exit ;;
+    i86pc:SunOS:5.*:* | i86xen:SunOS:5.*:*)
+	eval $set_cc_for_build
+	SUN_ARCH="i386"
+	# If there is a compiler, see if it is configured for 64-bit objects.
+	# Note that the Sun cc does not turn __LP64__ into 1 like gcc does.
+	# This test works for both compilers.
+	if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then
+	    if (echo '#ifdef __amd64'; echo IS_64BIT_ARCH; echo '#endif') | \
+		(CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \
+		grep IS_64BIT_ARCH >/dev/null
+	    then
+		SUN_ARCH="x86_64"
+	    fi
+	fi
+	echo ${SUN_ARCH}-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+	exit ;;
+    sun4*:SunOS:6*:*)
+	# According to config.sub, this is the proper way to canonicalize
+	# SunOS6.  Hard to guess exactly what SunOS6 will be like, but
+	# it's likely to be more like Solaris than SunOS4.
+	echo sparc-sun-solaris3`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+	exit ;;
+    sun4*:SunOS:*:*)
+	case "`/usr/bin/arch -k`" in
+	    Series*|S4*)
+		UNAME_RELEASE=`uname -v`
+		;;
+	esac
+	# Japanese Language versions have a version number like `4.1.3-JL'.
+	echo sparc-sun-sunos`echo ${UNAME_RELEASE}|sed -e 's/-/_/'`
+	exit ;;
+    sun3*:SunOS:*:*)
+	echo m68k-sun-sunos${UNAME_RELEASE}
+	exit ;;
+    sun*:*:4.2BSD:*)
+	UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null`
+	test "x${UNAME_RELEASE}" = "x" && UNAME_RELEASE=3
+	case "`/bin/arch`" in
+	    sun3)
+		echo m68k-sun-sunos${UNAME_RELEASE}
+		;;
+	    sun4)
+		echo sparc-sun-sunos${UNAME_RELEASE}
+		;;
+	esac
+	exit ;;
+    aushp:SunOS:*:*)
+	echo sparc-auspex-sunos${UNAME_RELEASE}
+	exit ;;
+    # The situation for MiNT is a little confusing.  The machine name
+    # can be virtually everything (everything which is not
+    # "atarist" or "atariste" at least should have a processor
+    # > m68000).  The system name ranges from "MiNT" over "FreeMiNT"
+    # to the lowercase version "mint" (or "freemint").  Finally
+    # the system name "TOS" denotes a system which is actually not
+    # MiNT.  But MiNT is downward compatible to TOS, so this should
+    # be no problem.
+    atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*)
+        echo m68k-atari-mint${UNAME_RELEASE}
+	exit ;;
+    atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*)
+	echo m68k-atari-mint${UNAME_RELEASE}
+        exit ;;
+    *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*)
+        echo m68k-atari-mint${UNAME_RELEASE}
+	exit ;;
+    milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*)
+        echo m68k-milan-mint${UNAME_RELEASE}
+        exit ;;
+    hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*)
+        echo m68k-hades-mint${UNAME_RELEASE}
+        exit ;;
+    *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*)
+        echo m68k-unknown-mint${UNAME_RELEASE}
+        exit ;;
+    m68k:machten:*:*)
+	echo m68k-apple-machten${UNAME_RELEASE}
+	exit ;;
+    powerpc:machten:*:*)
+	echo powerpc-apple-machten${UNAME_RELEASE}
+	exit ;;
+    RISC*:Mach:*:*)
+	echo mips-dec-mach_bsd4.3
+	exit ;;
+    RISC*:ULTRIX:*:*)
+	echo mips-dec-ultrix${UNAME_RELEASE}
+	exit ;;
+    VAX*:ULTRIX*:*:*)
+	echo vax-dec-ultrix${UNAME_RELEASE}
+	exit ;;
+    2020:CLIX:*:* | 2430:CLIX:*:*)
+	echo clipper-intergraph-clix${UNAME_RELEASE}
+	exit ;;
+    mips:*:*:UMIPS | mips:*:*:RISCos)
+	eval $set_cc_for_build
+	sed 's/^	//' << EOF >$dummy.c
+#ifdef __cplusplus
+#include <stdio.h>  /* for printf() prototype */
+	int main (int argc, char *argv[]) {
+#else
+	int main (argc, argv) int argc; char *argv[]; {
+#endif
+	#if defined (host_mips) && defined (MIPSEB)
+	#if defined (SYSTYPE_SYSV)
+	  printf ("mips-mips-riscos%ssysv\n", argv[1]); exit (0);
+	#endif
+	#if defined (SYSTYPE_SVR4)
+	  printf ("mips-mips-riscos%ssvr4\n", argv[1]); exit (0);
+	#endif
+	#if defined (SYSTYPE_BSD43) || defined(SYSTYPE_BSD)
+	  printf ("mips-mips-riscos%sbsd\n", argv[1]); exit (0);
+	#endif
+	#endif
+	  exit (-1);
+	}
+EOF
+	$CC_FOR_BUILD -o $dummy $dummy.c &&
+	  dummyarg=`echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` &&
+	  SYSTEM_NAME=`$dummy $dummyarg` &&
+	    { echo "$SYSTEM_NAME"; exit; }
+	echo mips-mips-riscos${UNAME_RELEASE}
+	exit ;;
+    Motorola:PowerMAX_OS:*:*)
+	echo powerpc-motorola-powermax
+	exit ;;
+    Motorola:*:4.3:PL8-*)
+	echo powerpc-harris-powermax
+	exit ;;
+    Night_Hawk:*:*:PowerMAX_OS | Synergy:PowerMAX_OS:*:*)
+	echo powerpc-harris-powermax
+	exit ;;
+    Night_Hawk:Power_UNIX:*:*)
+	echo powerpc-harris-powerunix
+	exit ;;
+    m88k:CX/UX:7*:*)
+	echo m88k-harris-cxux7
+	exit ;;
+    m88k:*:4*:R4*)
+	echo m88k-motorola-sysv4
+	exit ;;
+    m88k:*:3*:R3*)
+	echo m88k-motorola-sysv3
+	exit ;;
+    AViiON:dgux:*:*)
+        # DG/UX returns AViiON for all architectures
+        UNAME_PROCESSOR=`/usr/bin/uname -p`
+	if [ $UNAME_PROCESSOR = mc88100 ] || [ $UNAME_PROCESSOR = mc88110 ]
+	then
+	    if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx ] || \
+	       [ ${TARGET_BINARY_INTERFACE}x = x ]
+	    then
+		echo m88k-dg-dgux${UNAME_RELEASE}
+	    else
+		echo m88k-dg-dguxbcs${UNAME_RELEASE}
+	    fi
+	else
+	    echo i586-dg-dgux${UNAME_RELEASE}
+	fi
+ 	exit ;;
+    M88*:DolphinOS:*:*)	# DolphinOS (SVR3)
+	echo m88k-dolphin-sysv3
+	exit ;;
+    M88*:*:R3*:*)
+	# Delta 88k system running SVR3
+	echo m88k-motorola-sysv3
+	exit ;;
+    XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3)
+	echo m88k-tektronix-sysv3
+	exit ;;
+    Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD)
+	echo m68k-tektronix-bsd
+	exit ;;
+    *:IRIX*:*:*)
+	echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'`
+	exit ;;
+    ????????:AIX?:[12].1:2)   # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX.
+	echo romp-ibm-aix     # uname -m gives an 8 hex-code CPU id
+	exit ;;               # Note that: echo "'`uname -s`'" gives 'AIX '
+    i*86:AIX:*:*)
+	echo i386-ibm-aix
+	exit ;;
+    ia64:AIX:*:*)
+	if [ -x /usr/bin/oslevel ] ; then
+		IBM_REV=`/usr/bin/oslevel`
+	else
+		IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE}
+	fi
+	echo ${UNAME_MACHINE}-ibm-aix${IBM_REV}
+	exit ;;
+    *:AIX:2:3)
+	if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then
+		eval $set_cc_for_build
+		sed 's/^		//' << EOF >$dummy.c
+		#include <sys/systemcfg.h>
+
+		main()
+			{
+			if (!__power_pc())
+				exit(1);
+			puts("powerpc-ibm-aix3.2.5");
+			exit(0);
+			}
+EOF
+		if $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy`
+		then
+			echo "$SYSTEM_NAME"
+		else
+			echo rs6000-ibm-aix3.2.5
+		fi
+	elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then
+		echo rs6000-ibm-aix3.2.4
+	else
+		echo rs6000-ibm-aix3.2
+	fi
+	exit ;;
+    *:AIX:*:[456])
+	IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'`
+	if /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then
+		IBM_ARCH=rs6000
+	else
+		IBM_ARCH=powerpc
+	fi
+	if [ -x /usr/bin/oslevel ] ; then
+		IBM_REV=`/usr/bin/oslevel`
+	else
+		IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE}
+	fi
+	echo ${IBM_ARCH}-ibm-aix${IBM_REV}
+	exit ;;
+    *:AIX:*:*)
+	echo rs6000-ibm-aix
+	exit ;;
+    ibmrt:4.4BSD:*|romp-ibm:BSD:*)
+	echo romp-ibm-bsd4.4
+	exit ;;
+    ibmrt:*BSD:*|romp-ibm:BSD:*)            # covers RT/PC BSD and
+	echo romp-ibm-bsd${UNAME_RELEASE}   # 4.3 with uname added to
+	exit ;;                             # report: romp-ibm BSD 4.3
+    *:BOSX:*:*)
+	echo rs6000-bull-bosx
+	exit ;;
+    DPX/2?00:B.O.S.:*:*)
+	echo m68k-bull-sysv3
+	exit ;;
+    9000/[34]??:4.3bsd:1.*:*)
+	echo m68k-hp-bsd
+	exit ;;
+    hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*)
+	echo m68k-hp-bsd4.4
+	exit ;;
+    9000/[34678]??:HP-UX:*:*)
+	HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'`
+	case "${UNAME_MACHINE}" in
+	    9000/31? )            HP_ARCH=m68000 ;;
+	    9000/[34]?? )         HP_ARCH=m68k ;;
+	    9000/[678][0-9][0-9])
+		if [ -x /usr/bin/getconf ]; then
+		    sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null`
+                    sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null`
+                    case "${sc_cpu_version}" in
+                      523) HP_ARCH="hppa1.0" ;; # CPU_PA_RISC1_0
+                      528) HP_ARCH="hppa1.1" ;; # CPU_PA_RISC1_1
+                      532)                      # CPU_PA_RISC2_0
+                        case "${sc_kernel_bits}" in
+                          32) HP_ARCH="hppa2.0n" ;;
+                          64) HP_ARCH="hppa2.0w" ;;
+			  '') HP_ARCH="hppa2.0" ;;   # HP-UX 10.20
+                        esac ;;
+                    esac
+		fi
+		if [ "${HP_ARCH}" = "" ]; then
+		    eval $set_cc_for_build
+		    sed 's/^              //' << EOF >$dummy.c
+
+              #define _HPUX_SOURCE
+              #include <stdlib.h>
+              #include <unistd.h>
+
+              int main ()
+              {
+              #if defined(_SC_KERNEL_BITS)
+                  long bits = sysconf(_SC_KERNEL_BITS);
+              #endif
+                  long cpu  = sysconf (_SC_CPU_VERSION);
+
+                  switch (cpu)
+              	{
+              	case CPU_PA_RISC1_0: puts ("hppa1.0"); break;
+              	case CPU_PA_RISC1_1: puts ("hppa1.1"); break;
+              	case CPU_PA_RISC2_0:
+              #if defined(_SC_KERNEL_BITS)
+              	    switch (bits)
+              		{
+              		case 64: puts ("hppa2.0w"); break;
+              		case 32: puts ("hppa2.0n"); break;
+              		default: puts ("hppa2.0"); break;
+              		} break;
+              #else  /* !defined(_SC_KERNEL_BITS) */
+              	    puts ("hppa2.0"); break;
+              #endif
+              	default: puts ("hppa1.0"); break;
+              	}
+                  exit (0);
+              }
+EOF
+		    (CCOPTS= $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null) && HP_ARCH=`$dummy`
+		    test -z "$HP_ARCH" && HP_ARCH=hppa
+		fi ;;
+	esac
+	if [ ${HP_ARCH} = "hppa2.0w" ]
+	then
+	    eval $set_cc_for_build
+
+	    # hppa2.0w-hp-hpux* has a 64-bit kernel and a compiler generating
+	    # 32-bit code.  hppa64-hp-hpux* has the same kernel and a compiler
+	    # generating 64-bit code.  GNU and HP use different nomenclature:
+	    #
+	    # $ CC_FOR_BUILD=cc ./config.guess
+	    # => hppa2.0w-hp-hpux11.23
+	    # $ CC_FOR_BUILD="cc +DA2.0w" ./config.guess
+	    # => hppa64-hp-hpux11.23
+
+	    if echo __LP64__ | (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) |
+		grep __LP64__ >/dev/null
+	    then
+		HP_ARCH="hppa2.0w"
+	    else
+		HP_ARCH="hppa64"
+	    fi
+	fi
+	echo ${HP_ARCH}-hp-hpux${HPUX_REV}
+	exit ;;
+    ia64:HP-UX:*:*)
+	HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'`
+	echo ia64-hp-hpux${HPUX_REV}
+	exit ;;
+    3050*:HI-UX:*:*)
+	eval $set_cc_for_build
+	sed 's/^	//' << EOF >$dummy.c
+	#include <unistd.h>
+	int
+	main ()
+	{
+	  long cpu = sysconf (_SC_CPU_VERSION);
+	  /* The order matters, because CPU_IS_HP_MC68K erroneously returns
+	     true for CPU_PA_RISC1_0.  CPU_IS_PA_RISC returns correct
+	     results, however.  */
+	  if (CPU_IS_PA_RISC (cpu))
+	    {
+	      switch (cpu)
+		{
+		  case CPU_PA_RISC1_0: puts ("hppa1.0-hitachi-hiuxwe2"); break;
+		  case CPU_PA_RISC1_1: puts ("hppa1.1-hitachi-hiuxwe2"); break;
+		  case CPU_PA_RISC2_0: puts ("hppa2.0-hitachi-hiuxwe2"); break;
+		  default: puts ("hppa-hitachi-hiuxwe2"); break;
+		}
+	    }
+	  else if (CPU_IS_HP_MC68K (cpu))
+	    puts ("m68k-hitachi-hiuxwe2");
+	  else puts ("unknown-hitachi-hiuxwe2");
+	  exit (0);
+	}
+EOF
+	$CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` &&
+		{ echo "$SYSTEM_NAME"; exit; }
+	echo unknown-hitachi-hiuxwe2
+	exit ;;
+    9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* )
+	echo hppa1.1-hp-bsd
+	exit ;;
+    9000/8??:4.3bsd:*:*)
+	echo hppa1.0-hp-bsd
+	exit ;;
+    *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*)
+	echo hppa1.0-hp-mpeix
+	exit ;;
+    hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* )
+	echo hppa1.1-hp-osf
+	exit ;;
+    hp8??:OSF1:*:*)
+	echo hppa1.0-hp-osf
+	exit ;;
+    i*86:OSF1:*:*)
+	if [ -x /usr/sbin/sysversion ] ; then
+	    echo ${UNAME_MACHINE}-unknown-osf1mk
+	else
+	    echo ${UNAME_MACHINE}-unknown-osf1
+	fi
+	exit ;;
+    parisc*:Lites*:*:*)
+	echo hppa1.1-hp-lites
+	exit ;;
+    C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*)
+	echo c1-convex-bsd
+        exit ;;
+    C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*)
+	if getsysinfo -f scalar_acc
+	then echo c32-convex-bsd
+	else echo c2-convex-bsd
+	fi
+        exit ;;
+    C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*)
+	echo c34-convex-bsd
+        exit ;;
+    C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*)
+	echo c38-convex-bsd
+        exit ;;
+    C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*)
+	echo c4-convex-bsd
+        exit ;;
+    CRAY*Y-MP:*:*:*)
+	echo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
+	exit ;;
+    CRAY*[A-Z]90:*:*:*)
+	echo ${UNAME_MACHINE}-cray-unicos${UNAME_RELEASE} \
+	| sed -e 's/CRAY.*\([A-Z]90\)/\1/' \
+	      -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \
+	      -e 's/\.[^.]*$/.X/'
+	exit ;;
+    CRAY*TS:*:*:*)
+	echo t90-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
+	exit ;;
+    CRAY*T3E:*:*:*)
+	echo alphaev5-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
+	exit ;;
+    CRAY*SV1:*:*:*)
+	echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
+	exit ;;
+    *:UNICOS/mp:*:*)
+	echo craynv-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
+	exit ;;
+    F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*)
+	FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
+        FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
+        FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'`
+        echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
+        exit ;;
+    5000:UNIX_System_V:4.*:*)
+        FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
+        FUJITSU_REL=`echo ${UNAME_RELEASE} | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/ /_/'`
+        echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
+	exit ;;
+    i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*)
+	echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE}
+	exit ;;
+    sparc*:BSD/OS:*:*)
+	echo sparc-unknown-bsdi${UNAME_RELEASE}
+	exit ;;
+    *:BSD/OS:*:*)
+	echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE}
+	exit ;;
+    *:FreeBSD:*:*)
+	case ${UNAME_MACHINE} in
+	    pc98)
+		echo i386-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
+	    amd64)
+		echo x86_64-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
+	    *)
+		echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
+	esac
+	exit ;;
+    i*:CYGWIN*:*)
+	echo ${UNAME_MACHINE}-pc-cygwin
+	exit ;;
+    *:MINGW*:*)
+	echo ${UNAME_MACHINE}-pc-mingw32
+	exit ;;
+    i*:windows32*:*)
+    	# uname -m includes "-pc" on this system.
+    	echo ${UNAME_MACHINE}-mingw32
+	exit ;;
+    i*:PW*:*)
+	echo ${UNAME_MACHINE}-pc-pw32
+	exit ;;
+    *:Interix*:[3456]*)
+    	case ${UNAME_MACHINE} in
+	    x86)
+		echo i586-pc-interix${UNAME_RELEASE}
+		exit ;;
+	    EM64T | authenticamd | genuineintel)
+		echo x86_64-unknown-interix${UNAME_RELEASE}
+		exit ;;
+	    IA64)
+		echo ia64-unknown-interix${UNAME_RELEASE}
+		exit ;;
+	esac ;;
+    [345]86:Windows_95:* | [345]86:Windows_98:* | [345]86:Windows_NT:*)
+	echo i${UNAME_MACHINE}-pc-mks
+	exit ;;
+    i*:Windows_NT*:* | Pentium*:Windows_NT*:*)
+	# How do we know it's Interix rather than the generic POSIX subsystem?
+	# It also conflicts with pre-2.0 versions of AT&T UWIN. Should we
+	# UNAME_MACHINE based on the output of uname instead of i386?
+	echo i586-pc-interix
+	exit ;;
+    i*:UWIN*:*)
+	echo ${UNAME_MACHINE}-pc-uwin
+	exit ;;
+    amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*)
+	echo x86_64-unknown-cygwin
+	exit ;;
+    p*:CYGWIN*:*)
+	echo powerpcle-unknown-cygwin
+	exit ;;
+    prep*:SunOS:5.*:*)
+	echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+	exit ;;
+    *:GNU:*:*)
+	# the GNU system
+	echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'`
+	exit ;;
+    *:GNU/*:*:*)
+	# other systems with GNU libc and userland
+	echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-gnu
+	exit ;;
+    i*86:Minix:*:*)
+	echo ${UNAME_MACHINE}-pc-minix
+	exit ;;
+    arm*:Linux:*:*)
+	eval $set_cc_for_build
+	if echo __ARM_EABI__ | $CC_FOR_BUILD -E - 2>/dev/null \
+	    | grep -q __ARM_EABI__
+	then
+	    echo ${UNAME_MACHINE}-unknown-linux-gnu
+	else
+	    echo ${UNAME_MACHINE}-unknown-linux-gnueabi
+	fi
+	exit ;;
+    avr32*:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-gnu
+	exit ;;
+    cris:Linux:*:*)
+	echo cris-axis-linux-gnu
+	exit ;;
+    crisv32:Linux:*:*)
+	echo crisv32-axis-linux-gnu
+	exit ;;
+    frv:Linux:*:*)
+    	echo frv-unknown-linux-gnu
+	exit ;;
+    ia64:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-gnu
+	exit ;;
+    m32r*:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-gnu
+	exit ;;
+    m68*:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-gnu
+	exit ;;
+    mips:Linux:*:*)
+	eval $set_cc_for_build
+	sed 's/^	//' << EOF >$dummy.c
+	#undef CPU
+	#undef mips
+	#undef mipsel
+	#if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL)
+	CPU=mipsel
+	#else
+	#if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB)
+	CPU=mips
+	#else
+	CPU=
+	#endif
+	#endif
+EOF
+	eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n '
+	    /^CPU/{
+		s: ::g
+		p
+	    }'`"
+	test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; }
+	;;
+    mips64:Linux:*:*)
+	eval $set_cc_for_build
+	sed 's/^	//' << EOF >$dummy.c
+	#undef CPU
+	#undef mips64
+	#undef mips64el
+	#if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL)
+	CPU=mips64el
+	#else
+	#if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB)
+	CPU=mips64
+	#else
+	CPU=
+	#endif
+	#endif
+EOF
+	eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n '
+	    /^CPU/{
+		s: ::g
+		p
+	    }'`"
+	test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; }
+	;;
+    or32:Linux:*:*)
+	echo or32-unknown-linux-gnu
+	exit ;;
+    ppc:Linux:*:*)
+	echo powerpc-unknown-linux-gnu
+	exit ;;
+    ppc64:Linux:*:*)
+	echo powerpc64-unknown-linux-gnu
+	exit ;;
+    alpha:Linux:*:*)
+	case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in
+	  EV5)   UNAME_MACHINE=alphaev5 ;;
+	  EV56)  UNAME_MACHINE=alphaev56 ;;
+	  PCA56) UNAME_MACHINE=alphapca56 ;;
+	  PCA57) UNAME_MACHINE=alphapca56 ;;
+	  EV6)   UNAME_MACHINE=alphaev6 ;;
+	  EV67)  UNAME_MACHINE=alphaev67 ;;
+	  EV68*) UNAME_MACHINE=alphaev68 ;;
+        esac
+	objdump --private-headers /bin/sh | grep ld.so.1 >/dev/null
+	if test "$?" = 0 ; then LIBC="libc1" ; else LIBC="" ; fi
+	echo ${UNAME_MACHINE}-unknown-linux-gnu${LIBC}
+	exit ;;
+    padre:Linux:*:*)
+	echo sparc-unknown-linux-gnu
+	exit ;;
+    parisc:Linux:*:* | hppa:Linux:*:*)
+	# Look for CPU level
+	case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in
+	  PA7*) echo hppa1.1-unknown-linux-gnu ;;
+	  PA8*) echo hppa2.0-unknown-linux-gnu ;;
+	  *)    echo hppa-unknown-linux-gnu ;;
+	esac
+	exit ;;
+    parisc64:Linux:*:* | hppa64:Linux:*:*)
+	echo hppa64-unknown-linux-gnu
+	exit ;;
+    s390:Linux:*:* | s390x:Linux:*:*)
+	echo ${UNAME_MACHINE}-ibm-linux
+	exit ;;
+    sh64*:Linux:*:*)
+    	echo ${UNAME_MACHINE}-unknown-linux-gnu
+	exit ;;
+    sh*:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-gnu
+	exit ;;
+    sparc:Linux:*:* | sparc64:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-gnu
+	exit ;;
+    vax:Linux:*:*)
+	echo ${UNAME_MACHINE}-dec-linux-gnu
+	exit ;;
+    x86_64:Linux:*:*)
+	echo x86_64-unknown-linux-gnu
+	exit ;;
+    xtensa*:Linux:*:*)
+    	echo ${UNAME_MACHINE}-unknown-linux-gnu
+	exit ;;
+    i*86:Linux:*:*)
+	# The BFD linker knows what the default object file format is, so
+	# first see if it will tell us. cd to the root directory to prevent
+	# problems with other programs or directories called `ld' in the path.
+	# Set LC_ALL=C to ensure ld outputs messages in English.
+	ld_supported_targets=`cd /; LC_ALL=C ld --help 2>&1 \
+			 | sed -ne '/supported targets:/!d
+				    s/[ 	][ 	]*/ /g
+				    s/.*supported targets: *//
+				    s/ .*//
+				    p'`
+        case "$ld_supported_targets" in
+	  elf32-i386)
+		TENTATIVE="${UNAME_MACHINE}-pc-linux-gnu"
+		;;
+	  a.out-i386-linux)
+		echo "${UNAME_MACHINE}-pc-linux-gnuaout"
+		exit ;;
+	  "")
+		# Either a pre-BFD a.out linker (linux-gnuoldld) or
+		# one that does not give us useful --help.
+		echo "${UNAME_MACHINE}-pc-linux-gnuoldld"
+		exit ;;
+	esac
+	# Determine whether the default compiler is a.out or elf
+	eval $set_cc_for_build
+	sed 's/^	//' << EOF >$dummy.c
+	#include <features.h>
+	#ifdef __ELF__
+	# ifdef __GLIBC__
+	#  if __GLIBC__ >= 2
+	LIBC=gnu
+	#  else
+	LIBC=gnulibc1
+	#  endif
+	# else
+	LIBC=gnulibc1
+	# endif
+	#else
+	#if defined(__INTEL_COMPILER) || defined(__PGI) || defined(__SUNPRO_C) || defined(__SUNPRO_CC)
+	LIBC=gnu
+	#else
+	LIBC=gnuaout
+	#endif
+	#endif
+	#ifdef __dietlibc__
+	LIBC=dietlibc
+	#endif
+EOF
+	eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n '
+	    /^LIBC/{
+		s: ::g
+		p
+	    }'`"
+	test x"${LIBC}" != x && {
+		echo "${UNAME_MACHINE}-pc-linux-${LIBC}"
+		exit
+	}
+	test x"${TENTATIVE}" != x && { echo "${TENTATIVE}"; exit; }
+	;;
+    i*86:DYNIX/ptx:4*:*)
+	# ptx 4.0 does uname -s correctly, with DYNIX/ptx in there.
+	# earlier versions are messed up and put the nodename in both
+	# sysname and nodename.
+	echo i386-sequent-sysv4
+	exit ;;
+    i*86:UNIX_SV:4.2MP:2.*)
+        # Unixware is an offshoot of SVR4, but it has its own version
+        # number series starting with 2...
+        # I am not positive that other SVR4 systems won't match this,
+	# I just have to hope.  -- rms.
+        # Use sysv4.2uw... so that sysv4* matches it.
+	echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION}
+	exit ;;
+    i*86:OS/2:*:*)
+	# If we were able to find `uname', then EMX Unix compatibility
+	# is probably installed.
+	echo ${UNAME_MACHINE}-pc-os2-emx
+	exit ;;
+    i*86:XTS-300:*:STOP)
+	echo ${UNAME_MACHINE}-unknown-stop
+	exit ;;
+    i*86:atheos:*:*)
+	echo ${UNAME_MACHINE}-unknown-atheos
+	exit ;;
+    i*86:syllable:*:*)
+	echo ${UNAME_MACHINE}-pc-syllable
+	exit ;;
+    i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.0*:*)
+	echo i386-unknown-lynxos${UNAME_RELEASE}
+	exit ;;
+    i*86:*DOS:*:*)
+	echo ${UNAME_MACHINE}-pc-msdosdjgpp
+	exit ;;
+    i*86:*:4.*:* | i*86:SYSTEM_V:4.*:*)
+	UNAME_REL=`echo ${UNAME_RELEASE} | sed 's/\/MP$//'`
+	if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then
+		echo ${UNAME_MACHINE}-univel-sysv${UNAME_REL}
+	else
+		echo ${UNAME_MACHINE}-pc-sysv${UNAME_REL}
+	fi
+	exit ;;
+    i*86:*:5:[678]*)
+    	# UnixWare 7.x, OpenUNIX and OpenServer 6.
+	case `/bin/uname -X | grep "^Machine"` in
+	    *486*)	     UNAME_MACHINE=i486 ;;
+	    *Pentium)	     UNAME_MACHINE=i586 ;;
+	    *Pent*|*Celeron) UNAME_MACHINE=i686 ;;
+	esac
+	echo ${UNAME_MACHINE}-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION}
+	exit ;;
+    i*86:*:3.2:*)
+	if test -f /usr/options/cb.name; then
+		UNAME_REL=`sed -n 's/.*Version //p' </usr/options/cb.name`
+		echo ${UNAME_MACHINE}-pc-isc$UNAME_REL
+	elif /bin/uname -X 2>/dev/null >/dev/null ; then
+		UNAME_REL=`(/bin/uname -X|grep Release|sed -e 's/.*= //')`
+		(/bin/uname -X|grep i80486 >/dev/null) && UNAME_MACHINE=i486
+		(/bin/uname -X|grep '^Machine.*Pentium' >/dev/null) \
+			&& UNAME_MACHINE=i586
+		(/bin/uname -X|grep '^Machine.*Pent *II' >/dev/null) \
+			&& UNAME_MACHINE=i686
+		(/bin/uname -X|grep '^Machine.*Pentium Pro' >/dev/null) \
+			&& UNAME_MACHINE=i686
+		echo ${UNAME_MACHINE}-pc-sco$UNAME_REL
+	else
+		echo ${UNAME_MACHINE}-pc-sysv32
+	fi
+	exit ;;
+    pc:*:*:*)
+	# Left here for compatibility:
+        # uname -m prints for DJGPP always 'pc', but it prints nothing about
+        # the processor, so we play safe by assuming i586.
+	# Note: whatever this is, it MUST be the same as what config.sub
+	# prints for the "djgpp" host, or else GDB configury will decide that
+	# this is a cross-build.
+	echo i586-pc-msdosdjgpp
+        exit ;;
+    Intel:Mach:3*:*)
+	echo i386-pc-mach3
+	exit ;;
+    paragon:*:*:*)
+	echo i860-intel-osf1
+	exit ;;
+    i860:*:4.*:*) # i860-SVR4
+	if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then
+	  echo i860-stardent-sysv${UNAME_RELEASE} # Stardent Vistra i860-SVR4
+	else # Add other i860-SVR4 vendors below as they are discovered.
+	  echo i860-unknown-sysv${UNAME_RELEASE}  # Unknown i860-SVR4
+	fi
+	exit ;;
+    mini*:CTIX:SYS*5:*)
+	# "miniframe"
+	echo m68010-convergent-sysv
+	exit ;;
+    mc68k:UNIX:SYSTEM5:3.51m)
+	echo m68k-convergent-sysv
+	exit ;;
+    M680?0:D-NIX:5.3:*)
+	echo m68k-diab-dnix
+	exit ;;
+    M68*:*:R3V[5678]*:*)
+	test -r /sysV68 && { echo 'm68k-motorola-sysv'; exit; } ;;
+    3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0 | S7501*:*:4.0:3.0)
+	OS_REL=''
+	test -r /etc/.relid \
+	&& OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid`
+	/bin/uname -p 2>/dev/null | grep 86 >/dev/null \
+	  && { echo i486-ncr-sysv4.3${OS_REL}; exit; }
+	/bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \
+	  && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;;
+    3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*)
+        /bin/uname -p 2>/dev/null | grep 86 >/dev/null \
+          && { echo i486-ncr-sysv4; exit; } ;;
+    NCR*:*:4.2:* | MPRAS*:*:4.2:*)
+	OS_REL='.3'
+	test -r /etc/.relid \
+	    && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid`
+	/bin/uname -p 2>/dev/null | grep 86 >/dev/null \
+	    && { echo i486-ncr-sysv4.3${OS_REL}; exit; }
+	/bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \
+	    && { echo i586-ncr-sysv4.3${OS_REL}; exit; }
+	/bin/uname -p 2>/dev/null | /bin/grep pteron >/dev/null \
+	    && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;;
+    m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*)
+	echo m68k-unknown-lynxos${UNAME_RELEASE}
+	exit ;;
+    mc68030:UNIX_System_V:4.*:*)
+	echo m68k-atari-sysv4
+	exit ;;
+    TSUNAMI:LynxOS:2.*:*)
+	echo sparc-unknown-lynxos${UNAME_RELEASE}
+	exit ;;
+    rs6000:LynxOS:2.*:*)
+	echo rs6000-unknown-lynxos${UNAME_RELEASE}
+	exit ;;
+    PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.0*:*)
+	echo powerpc-unknown-lynxos${UNAME_RELEASE}
+	exit ;;
+    SM[BE]S:UNIX_SV:*:*)
+	echo mips-dde-sysv${UNAME_RELEASE}
+	exit ;;
+    RM*:ReliantUNIX-*:*:*)
+	echo mips-sni-sysv4
+	exit ;;
+    RM*:SINIX-*:*:*)
+	echo mips-sni-sysv4
+	exit ;;
+    *:SINIX-*:*:*)
+	if uname -p 2>/dev/null >/dev/null ; then
+		UNAME_MACHINE=`(uname -p) 2>/dev/null`
+		echo ${UNAME_MACHINE}-sni-sysv4
+	else
+		echo ns32k-sni-sysv
+	fi
+	exit ;;
+    PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort
+                      # says <Richard.M.Bartel at ccMail.Census.GOV>
+        echo i586-unisys-sysv4
+        exit ;;
+    *:UNIX_System_V:4*:FTX*)
+	# From Gerald Hewes <hewes at openmarket.com>.
+	# How about differentiating between stratus architectures? -djm
+	echo hppa1.1-stratus-sysv4
+	exit ;;
+    *:*:*:FTX*)
+	# From seanf at swdc.stratus.com.
+	echo i860-stratus-sysv4
+	exit ;;
+    i*86:VOS:*:*)
+	# From Paul.Green at stratus.com.
+	echo ${UNAME_MACHINE}-stratus-vos
+	exit ;;
+    *:VOS:*:*)
+	# From Paul.Green at stratus.com.
+	echo hppa1.1-stratus-vos
+	exit ;;
+    mc68*:A/UX:*:*)
+	echo m68k-apple-aux${UNAME_RELEASE}
+	exit ;;
+    news*:NEWS-OS:6*:*)
+	echo mips-sony-newsos6
+	exit ;;
+    R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*)
+	if [ -d /usr/nec ]; then
+	        echo mips-nec-sysv${UNAME_RELEASE}
+	else
+	        echo mips-unknown-sysv${UNAME_RELEASE}
+	fi
+        exit ;;
+    BeBox:BeOS:*:*)	# BeOS running on hardware made by Be, PPC only.
+	echo powerpc-be-beos
+	exit ;;
+    BeMac:BeOS:*:*)	# BeOS running on Mac or Mac clone, PPC only.
+	echo powerpc-apple-beos
+	exit ;;
+    BePC:BeOS:*:*)	# BeOS running on Intel PC compatible.
+	echo i586-pc-beos
+	exit ;;
+    BePC:Haiku:*:*)	# Haiku running on Intel PC compatible.
+	echo i586-pc-haiku
+	exit ;;
+    SX-4:SUPER-UX:*:*)
+	echo sx4-nec-superux${UNAME_RELEASE}
+	exit ;;
+    SX-5:SUPER-UX:*:*)
+	echo sx5-nec-superux${UNAME_RELEASE}
+	exit ;;
+    SX-6:SUPER-UX:*:*)
+	echo sx6-nec-superux${UNAME_RELEASE}
+	exit ;;
+    SX-7:SUPER-UX:*:*)
+	echo sx7-nec-superux${UNAME_RELEASE}
+	exit ;;
+    SX-8:SUPER-UX:*:*)
+	echo sx8-nec-superux${UNAME_RELEASE}
+	exit ;;
+    SX-8R:SUPER-UX:*:*)
+	echo sx8r-nec-superux${UNAME_RELEASE}
+	exit ;;
+    Power*:Rhapsody:*:*)
+	echo powerpc-apple-rhapsody${UNAME_RELEASE}
+	exit ;;
+    *:Rhapsody:*:*)
+	echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE}
+	exit ;;
+    *:Darwin:*:*)
+	UNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown
+	case $UNAME_PROCESSOR in
+	    unknown) UNAME_PROCESSOR=powerpc ;;
+	esac
+	echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE}
+	exit ;;
+    *:procnto*:*:* | *:QNX:[0123456789]*:*)
+	UNAME_PROCESSOR=`uname -p`
+	if test "$UNAME_PROCESSOR" = "x86"; then
+		UNAME_PROCESSOR=i386
+		UNAME_MACHINE=pc
+	fi
+	echo ${UNAME_PROCESSOR}-${UNAME_MACHINE}-nto-qnx${UNAME_RELEASE}
+	exit ;;
+    *:QNX:*:4*)
+	echo i386-pc-qnx
+	exit ;;
+    NSE-?:NONSTOP_KERNEL:*:*)
+	echo nse-tandem-nsk${UNAME_RELEASE}
+	exit ;;
+    NSR-?:NONSTOP_KERNEL:*:*)
+	echo nsr-tandem-nsk${UNAME_RELEASE}
+	exit ;;
+    *:NonStop-UX:*:*)
+	echo mips-compaq-nonstopux
+	exit ;;
+    BS2000:POSIX*:*:*)
+	echo bs2000-siemens-sysv
+	exit ;;
+    DS/*:UNIX_System_V:*:*)
+	echo ${UNAME_MACHINE}-${UNAME_SYSTEM}-${UNAME_RELEASE}
+	exit ;;
+    *:Plan9:*:*)
+	# "uname -m" is not consistent, so use $cputype instead. 386
+	# is converted to i386 for consistency with other x86
+	# operating systems.
+	if test "$cputype" = "386"; then
+	    UNAME_MACHINE=i386
+	else
+	    UNAME_MACHINE="$cputype"
+	fi
+	echo ${UNAME_MACHINE}-unknown-plan9
+	exit ;;
+    *:TOPS-10:*:*)
+	echo pdp10-unknown-tops10
+	exit ;;
+    *:TENEX:*:*)
+	echo pdp10-unknown-tenex
+	exit ;;
+    KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*)
+	echo pdp10-dec-tops20
+	exit ;;
+    XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*)
+	echo pdp10-xkl-tops20
+	exit ;;
+    *:TOPS-20:*:*)
+	echo pdp10-unknown-tops20
+	exit ;;
+    *:ITS:*:*)
+	echo pdp10-unknown-its
+	exit ;;
+    SEI:*:*:SEIUX)
+        echo mips-sei-seiux${UNAME_RELEASE}
+	exit ;;
+    *:DragonFly:*:*)
+	echo ${UNAME_MACHINE}-unknown-dragonfly`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`
+	exit ;;
+    *:*VMS:*:*)
+    	UNAME_MACHINE=`(uname -p) 2>/dev/null`
+	case "${UNAME_MACHINE}" in
+	    A*) echo alpha-dec-vms ; exit ;;
+	    I*) echo ia64-dec-vms ; exit ;;
+	    V*) echo vax-dec-vms ; exit ;;
+	esac ;;
+    *:XENIX:*:SysV)
+	echo i386-pc-xenix
+	exit ;;
+    i*86:skyos:*:*)
+	echo ${UNAME_MACHINE}-pc-skyos`echo ${UNAME_RELEASE}` | sed -e 's/ .*$//'
+	exit ;;
+    i*86:rdos:*:*)
+	echo ${UNAME_MACHINE}-pc-rdos
+	exit ;;
+    i*86:AROS:*:*)
+	echo ${UNAME_MACHINE}-pc-aros
+	exit ;;
+esac
+
+#echo '(No uname command or uname output not recognized.)' 1>&2
+#echo "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" 1>&2
+
+eval $set_cc_for_build
+cat >$dummy.c <<EOF
+#ifdef _SEQUENT_
+# include <sys/types.h>
+# include <sys/utsname.h>
+#endif
+main ()
+{
+#if defined (sony)
+#if defined (MIPSEB)
+  /* BFD wants "bsd" instead of "newsos".  Perhaps BFD should be changed,
+     I don't know....  */
+  printf ("mips-sony-bsd\n"); exit (0);
+#else
+#include <sys/param.h>
+  printf ("m68k-sony-newsos%s\n",
+#ifdef NEWSOS4
+          "4"
+#else
+	  ""
+#endif
+         ); exit (0);
+#endif
+#endif
+
+#if defined (__arm) && defined (__acorn) && defined (__unix)
+  printf ("arm-acorn-riscix\n"); exit (0);
+#endif
+
+#if defined (hp300) && !defined (hpux)
+  printf ("m68k-hp-bsd\n"); exit (0);
+#endif
+
+#if defined (NeXT)
+#if !defined (__ARCHITECTURE__)
+#define __ARCHITECTURE__ "m68k"
+#endif
+  int version;
+  version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`;
+  if (version < 4)
+    printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version);
+  else
+    printf ("%s-next-openstep%d\n", __ARCHITECTURE__, version);
+  exit (0);
+#endif
+
+#if defined (MULTIMAX) || defined (n16)
+#if defined (UMAXV)
+  printf ("ns32k-encore-sysv\n"); exit (0);
+#else
+#if defined (CMU)
+  printf ("ns32k-encore-mach\n"); exit (0);
+#else
+  printf ("ns32k-encore-bsd\n"); exit (0);
+#endif
+#endif
+#endif
+
+#if defined (__386BSD__)
+  printf ("i386-pc-bsd\n"); exit (0);
+#endif
+
+#if defined (sequent)
+#if defined (i386)
+  printf ("i386-sequent-dynix\n"); exit (0);
+#endif
+#if defined (ns32000)
+  printf ("ns32k-sequent-dynix\n"); exit (0);
+#endif
+#endif
+
+#if defined (_SEQUENT_)
+    struct utsname un;
+
+    uname(&un);
+
+    if (strncmp(un.version, "V2", 2) == 0) {
+	printf ("i386-sequent-ptx2\n"); exit (0);
+    }
+    if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */
+	printf ("i386-sequent-ptx1\n"); exit (0);
+    }
+    printf ("i386-sequent-ptx\n"); exit (0);
+
+#endif
+
+#if defined (vax)
+# if !defined (ultrix)
+#  include <sys/param.h>
+#  if defined (BSD)
+#   if BSD == 43
+      printf ("vax-dec-bsd4.3\n"); exit (0);
+#   else
+#    if BSD == 199006
+      printf ("vax-dec-bsd4.3reno\n"); exit (0);
+#    else
+      printf ("vax-dec-bsd\n"); exit (0);
+#    endif
+#   endif
+#  else
+    printf ("vax-dec-bsd\n"); exit (0);
+#  endif
+# else
+    printf ("vax-dec-ultrix\n"); exit (0);
+# endif
+#endif
+
+#if defined (alliant) && defined (i860)
+  printf ("i860-alliant-bsd\n"); exit (0);
+#endif
+
+  exit (1);
+}
+EOF
+
+$CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null && SYSTEM_NAME=`$dummy` &&
+	{ echo "$SYSTEM_NAME"; exit; }
+
+# Apollos put the system type in the environment.
+
+test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit; }
+
+# Convex versions that predate uname can use getsysinfo(1)
+
+if [ -x /usr/convex/getsysinfo ]
+then
+    case `getsysinfo -f cpu_type` in
+    c1*)
+	echo c1-convex-bsd
+	exit ;;
+    c2*)
+	if getsysinfo -f scalar_acc
+	then echo c32-convex-bsd
+	else echo c2-convex-bsd
+	fi
+	exit ;;
+    c34*)
+	echo c34-convex-bsd
+	exit ;;
+    c38*)
+	echo c38-convex-bsd
+	exit ;;
+    c4*)
+	echo c4-convex-bsd
+	exit ;;
+    esac
+fi
+
+cat >&2 <<EOF
+$0: unable to guess system type
+
+This script, last modified $timestamp, has failed to recognize
+the operating system you are using. It is advised that you
+download the most up to date version of the config scripts from
+
+  http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD
+and
+  http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD
+
+If the version you run ($0) is already up to date, please
+send the following data and any information you think might be
+pertinent to <config-patches at gnu.org> in order to provide the needed
+information to handle your system.
+
+config.guess timestamp = $timestamp
+
+uname -m = `(uname -m) 2>/dev/null || echo unknown`
+uname -r = `(uname -r) 2>/dev/null || echo unknown`
+uname -s = `(uname -s) 2>/dev/null || echo unknown`
+uname -v = `(uname -v) 2>/dev/null || echo unknown`
+
+/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null`
+/bin/uname -X     = `(/bin/uname -X) 2>/dev/null`
+
+hostinfo               = `(hostinfo) 2>/dev/null`
+/bin/universe          = `(/bin/universe) 2>/dev/null`
+/usr/bin/arch -k       = `(/usr/bin/arch -k) 2>/dev/null`
+/bin/arch              = `(/bin/arch) 2>/dev/null`
+/usr/bin/oslevel       = `(/usr/bin/oslevel) 2>/dev/null`
+/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null`
+
+UNAME_MACHINE = ${UNAME_MACHINE}
+UNAME_RELEASE = ${UNAME_RELEASE}
+UNAME_SYSTEM  = ${UNAME_SYSTEM}
+UNAME_VERSION = ${UNAME_VERSION}
+EOF
+
+exit 1
+
+# Local variables:
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "timestamp='"
+# time-stamp-format: "%:y-%02m-%02d"
+# time-stamp-end: "'"
+# End:
diff --git a/admin/config.sub b/admin/config.sub
new file mode 100755
index 0000000..a39437d
--- /dev/null
+++ b/admin/config.sub
@@ -0,0 +1,1686 @@
+#! /bin/sh
+# Configuration validation subroutine script.
+#   Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
+#   2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
+#   Free Software Foundation, Inc.
+
+timestamp='2009-04-17'
+
+# This file is (in principle) common to ALL GNU software.
+# The presence of a machine in this file suggests that SOME GNU software
+# can handle that machine.  It does not imply ALL GNU software can.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
+# 02110-1301, USA.
+#
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that program.
+
+
+# Please send patches to <config-patches at gnu.org>.  Submit a context
+# diff and a properly formatted ChangeLog entry.
+#
+# Configuration subroutine to validate and canonicalize a configuration type.
+# Supply the specified configuration type as an argument.
+# If it is invalid, we print an error message on stderr and exit with code 1.
+# Otherwise, we print the canonical config type on stdout and succeed.
+
+# This file is supposed to be the same for all GNU packages
+# and recognize all the CPU types, system types and aliases
+# that are meaningful with *any* GNU software.
+# Each package is responsible for reporting which valid configurations
+# it does not support.  The user should be able to distinguish
+# a failure to support a valid configuration from a meaningless
+# configuration.
+
+# The goal of this file is to map all the various variations of a given
+# machine specification into a single specification in the form:
+#	CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM
+# or in some cases, the newer four-part form:
+#	CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM
+# It is wrong to echo any other type of specification.
+
+me=`echo "$0" | sed -e 's,.*/,,'`
+
+usage="\
+Usage: $0 [OPTION] CPU-MFR-OPSYS
+       $0 [OPTION] ALIAS
+
+Canonicalize a configuration name.
+
+Operation modes:
+  -h, --help         print this help, then exit
+  -t, --time-stamp   print date of last modification, then exit
+  -v, --version      print version number, then exit
+
+Report bugs and patches to <config-patches at gnu.org>."
+
+version="\
+GNU config.sub ($timestamp)
+
+Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
+2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+
+This is free software; see the source for copying conditions.  There is NO
+warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
+
+help="
+Try \`$me --help' for more information."
+
+# Parse command line
+while test $# -gt 0 ; do
+  case $1 in
+    --time-stamp | --time* | -t )
+       echo "$timestamp" ; exit ;;
+    --version | -v )
+       echo "$version" ; exit ;;
+    --help | --h* | -h )
+       echo "$usage"; exit ;;
+    -- )     # Stop option processing
+       shift; break ;;
+    - )	# Use stdin as input.
+       break ;;
+    -* )
+       echo "$me: invalid option $1$help"
+       exit 1 ;;
+
+    *local*)
+       # First pass through any local machine types.
+       echo $1
+       exit ;;
+
+    * )
+       break ;;
+  esac
+done
+
+case $# in
+ 0) echo "$me: missing argument$help" >&2
+    exit 1;;
+ 1) ;;
+ *) echo "$me: too many arguments$help" >&2
+    exit 1;;
+esac
+
+# Separate what the user gave into CPU-COMPANY and OS or KERNEL-OS (if any).
+# Here we must recognize all the valid KERNEL-OS combinations.
+maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'`
+case $maybe_os in
+  nto-qnx* | linux-gnu* | linux-dietlibc | linux-newlib* | linux-uclibc* | \
+  uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* | \
+  kopensolaris*-gnu* | \
+  storm-chaos* | os2-emx* | rtmk-nova*)
+    os=-$maybe_os
+    basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`
+    ;;
+  *)
+    basic_machine=`echo $1 | sed 's/-[^-]*$//'`
+    if [ $basic_machine != $1 ]
+    then os=`echo $1 | sed 's/.*-/-/'`
+    else os=; fi
+    ;;
+esac
+
+### Let's recognize common machines as not being operating systems so
+### that things like config.sub decstation-3100 work.  We also
+### recognize some manufacturers as not being operating systems, so we
+### can provide default operating systems below.
+case $os in
+	-sun*os*)
+		# Prevent following clause from handling this invalid input.
+		;;
+	-dec* | -mips* | -sequent* | -encore* | -pc532* | -sgi* | -sony* | \
+	-att* | -7300* | -3300* | -delta* | -motorola* | -sun[234]* | \
+	-unicom* | -ibm* | -next | -hp | -isi* | -apollo | -altos* | \
+	-convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\
+	-c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \
+	-harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \
+	-apple | -axis | -knuth | -cray)
+		os=
+		basic_machine=$1
+		;;
+	-sim | -cisco | -oki | -wec | -winbond)
+		os=
+		basic_machine=$1
+		;;
+	-scout)
+		;;
+	-wrs)
+		os=-vxworks
+		basic_machine=$1
+		;;
+	-chorusos*)
+		os=-chorusos
+		basic_machine=$1
+		;;
+ 	-chorusrdb)
+ 		os=-chorusrdb
+		basic_machine=$1
+ 		;;
+	-hiux*)
+		os=-hiuxwe2
+		;;
+	-sco6)
+		os=-sco5v6
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-sco5)
+		os=-sco3.2v5
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-sco4)
+		os=-sco3.2v4
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-sco3.2.[4-9]*)
+		os=`echo $os | sed -e 's/sco3.2./sco3.2v/'`
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-sco3.2v[4-9]*)
+		# Don't forget version if it is 3.2v4 or newer.
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-sco5v6*)
+		# Don't forget version if it is 3.2v4 or newer.
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-sco*)
+		os=-sco3.2v2
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-udk*)
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-isc)
+		os=-isc2.2
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-clix*)
+		basic_machine=clipper-intergraph
+		;;
+	-isc*)
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-lynx*)
+		os=-lynxos
+		;;
+	-ptx*)
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-sequent/'`
+		;;
+	-windowsnt*)
+		os=`echo $os | sed -e 's/windowsnt/winnt/'`
+		;;
+	-psos*)
+		os=-psos
+		;;
+	-mint | -mint[0-9]*)
+		basic_machine=m68k-atari
+		os=-mint
+		;;
+esac
+
+# Decode aliases for certain CPU-COMPANY combinations.
+case $basic_machine in
+	# Recognize the basic CPU types without company name.
+	# Some are omitted here because they have special meanings below.
+	1750a | 580 \
+	| a29k \
+	| alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \
+	| alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \
+	| am33_2.0 \
+	| arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr | avr32 \
+	| bfin \
+	| c4x | clipper \
+	| d10v | d30v | dlx | dsp16xx \
+	| fido | fr30 | frv \
+	| h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \
+	| i370 | i860 | i960 | ia64 \
+	| ip2k | iq2000 \
+	| lm32 \
+	| m32c | m32r | m32rle | m68000 | m68k | m88k \
+	| maxq | mb | microblaze | mcore | mep | metag \
+	| mips | mipsbe | mipseb | mipsel | mipsle \
+	| mips16 \
+	| mips64 | mips64el \
+	| mips64octeon | mips64octeonel \
+	| mips64orion | mips64orionel \
+	| mips64r5900 | mips64r5900el \
+	| mips64vr | mips64vrel \
+	| mips64vr4100 | mips64vr4100el \
+	| mips64vr4300 | mips64vr4300el \
+	| mips64vr5000 | mips64vr5000el \
+	| mips64vr5900 | mips64vr5900el \
+	| mipsisa32 | mipsisa32el \
+	| mipsisa32r2 | mipsisa32r2el \
+	| mipsisa64 | mipsisa64el \
+	| mipsisa64r2 | mipsisa64r2el \
+	| mipsisa64sb1 | mipsisa64sb1el \
+	| mipsisa64sr71k | mipsisa64sr71kel \
+	| mipstx39 | mipstx39el \
+	| mn10200 | mn10300 \
+	| moxie \
+	| mt \
+	| msp430 \
+	| nios | nios2 \
+	| ns16k | ns32k \
+	| or32 \
+	| pdp10 | pdp11 | pj | pjl \
+	| powerpc | powerpc64 | powerpc64le | powerpcle | ppcbe \
+	| pyramid \
+	| score \
+	| sh | sh[1234] | sh[24]a | sh[24]aeb | sh[23]e | sh[34]eb | sheb | shbe | shle | sh[1234]le | sh3ele \
+	| sh64 | sh64le \
+	| sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet | sparclite \
+	| sparcv8 | sparcv9 | sparcv9b | sparcv9v \
+	| spu | strongarm \
+	| tahoe | thumb | tic4x | tic80 | tron \
+	| v850 | v850e \
+	| we32k \
+	| x86 | xc16x | xscale | xscalee[bl] | xstormy16 | xtensa \
+	| z8k | z80)
+		basic_machine=$basic_machine-unknown
+		;;
+	m6811 | m68hc11 | m6812 | m68hc12)
+		# Motorola 68HC11/12.
+		basic_machine=$basic_machine-unknown
+		os=-none
+		;;
+	m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | v70 | w65 | z8k)
+		;;
+	ms1)
+		basic_machine=mt-unknown
+		;;
+
+	# We use `pc' rather than `unknown'
+	# because (1) that's what they normally are, and
+	# (2) the word "unknown" tends to confuse beginning users.
+	i*86 | x86_64)
+	  basic_machine=$basic_machine-pc
+	  ;;
+	# Object if more than one company name word.
+	*-*-*)
+		echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2
+		exit 1
+		;;
+	# Recognize the basic CPU types with company name.
+	580-* \
+	| a29k-* \
+	| alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \
+	| alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \
+	| alphapca5[67]-* | alpha64pca5[67]-* | arc-* \
+	| arm-*  | armbe-* | armle-* | armeb-* | armv*-* \
+	| avr-* | avr32-* \
+	| bfin-* | bs2000-* \
+	| c[123]* | c30-* | [cjt]90-* | c4x-* | c54x-* | c55x-* | c6x-* \
+	| clipper-* | craynv-* | cydra-* \
+	| d10v-* | d30v-* | dlx-* \
+	| elxsi-* \
+	| f30[01]-* | f700-* | fido-* | fr30-* | frv-* | fx80-* \
+	| h8300-* | h8500-* \
+	| hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \
+	| i*86-* | i860-* | i960-* | ia64-* \
+	| ip2k-* | iq2000-* \
+	| lm32-* \
+	| m32c-* | m32r-* | m32rle-* \
+	| m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \
+	| m88110-* | m88k-* | maxq-* | mcore-* | metag-* \
+	| mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \
+	| mips16-* \
+	| mips64-* | mips64el-* \
+	| mips64octeon-* | mips64octeonel-* \
+	| mips64orion-* | mips64orionel-* \
+	| mips64r5900-* | mips64r5900el-* \
+	| mips64vr-* | mips64vrel-* \
+	| mips64vr4100-* | mips64vr4100el-* \
+	| mips64vr4300-* | mips64vr4300el-* \
+	| mips64vr5000-* | mips64vr5000el-* \
+	| mips64vr5900-* | mips64vr5900el-* \
+	| mipsisa32-* | mipsisa32el-* \
+	| mipsisa32r2-* | mipsisa32r2el-* \
+	| mipsisa64-* | mipsisa64el-* \
+	| mipsisa64r2-* | mipsisa64r2el-* \
+	| mipsisa64sb1-* | mipsisa64sb1el-* \
+	| mipsisa64sr71k-* | mipsisa64sr71kel-* \
+	| mipstx39-* | mipstx39el-* \
+	| mmix-* \
+	| mt-* \
+	| msp430-* \
+	| nios-* | nios2-* \
+	| none-* | np1-* | ns16k-* | ns32k-* \
+	| orion-* \
+	| pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \
+	| powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* | ppcbe-* \
+	| pyramid-* \
+	| romp-* | rs6000-* \
+	| sh-* | sh[1234]-* | sh[24]a-* | sh[24]aeb-* | sh[23]e-* | sh[34]eb-* | sheb-* | shbe-* \
+	| shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \
+	| sparc-* | sparc64-* | sparc64b-* | sparc64v-* | sparc86x-* | sparclet-* \
+	| sparclite-* \
+	| sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | strongarm-* | sv1-* | sx?-* \
+	| tahoe-* | thumb-* \
+	| tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* | tile-* \
+	| tron-* \
+	| v850-* | v850e-* | vax-* \
+	| we32k-* \
+	| x86-* | x86_64-* | xc16x-* | xps100-* | xscale-* | xscalee[bl]-* \
+	| xstormy16-* | xtensa*-* \
+	| ymp-* \
+	| z8k-* | z80-*)
+		;;
+	# Recognize the basic CPU types without company name, with glob match.
+	xtensa*)
+		basic_machine=$basic_machine-unknown
+		;;
+	# Recognize the various machine names and aliases which stand
+	# for a CPU type and a company and sometimes even an OS.
+	386bsd)
+		basic_machine=i386-unknown
+		os=-bsd
+		;;
+	3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc)
+		basic_machine=m68000-att
+		;;
+	3b*)
+		basic_machine=we32k-att
+		;;
+	a29khif)
+		basic_machine=a29k-amd
+		os=-udi
+		;;
+    	abacus)
+		basic_machine=abacus-unknown
+		;;
+	adobe68k)
+		basic_machine=m68010-adobe
+		os=-scout
+		;;
+	alliant | fx80)
+		basic_machine=fx80-alliant
+		;;
+	altos | altos3068)
+		basic_machine=m68k-altos
+		;;
+	am29k)
+		basic_machine=a29k-none
+		os=-bsd
+		;;
+	amd64)
+		basic_machine=x86_64-pc
+		;;
+	amd64-*)
+		basic_machine=x86_64-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	amdahl)
+		basic_machine=580-amdahl
+		os=-sysv
+		;;
+	amiga | amiga-*)
+		basic_machine=m68k-unknown
+		;;
+	amigaos | amigados)
+		basic_machine=m68k-unknown
+		os=-amigaos
+		;;
+	amigaunix | amix)
+		basic_machine=m68k-unknown
+		os=-sysv4
+		;;
+	apollo68)
+		basic_machine=m68k-apollo
+		os=-sysv
+		;;
+	apollo68bsd)
+		basic_machine=m68k-apollo
+		os=-bsd
+		;;
+	aros)
+		basic_machine=i386-pc
+		os=-aros
+		;;
+	aux)
+		basic_machine=m68k-apple
+		os=-aux
+		;;
+	balance)
+		basic_machine=ns32k-sequent
+		os=-dynix
+		;;
+	blackfin)
+		basic_machine=bfin-unknown
+		os=-linux
+		;;
+	blackfin-*)
+		basic_machine=bfin-`echo $basic_machine | sed 's/^[^-]*-//'`
+		os=-linux
+		;;
+	c90)
+		basic_machine=c90-cray
+		os=-unicos
+		;;
+        cegcc)
+		basic_machine=arm-unknown
+		os=-cegcc
+		;;
+	convex-c1)
+		basic_machine=c1-convex
+		os=-bsd
+		;;
+	convex-c2)
+		basic_machine=c2-convex
+		os=-bsd
+		;;
+	convex-c32)
+		basic_machine=c32-convex
+		os=-bsd
+		;;
+	convex-c34)
+		basic_machine=c34-convex
+		os=-bsd
+		;;
+	convex-c38)
+		basic_machine=c38-convex
+		os=-bsd
+		;;
+	cray | j90)
+		basic_machine=j90-cray
+		os=-unicos
+		;;
+	craynv)
+		basic_machine=craynv-cray
+		os=-unicosmp
+		;;
+	cr16)
+		basic_machine=cr16-unknown
+		os=-elf
+		;;
+	crds | unos)
+		basic_machine=m68k-crds
+		;;
+	crisv32 | crisv32-* | etraxfs*)
+		basic_machine=crisv32-axis
+		;;
+	cris | cris-* | etrax*)
+		basic_machine=cris-axis
+		;;
+	crx)
+		basic_machine=crx-unknown
+		os=-elf
+		;;
+	da30 | da30-*)
+		basic_machine=m68k-da30
+		;;
+	decstation | decstation-3100 | pmax | pmax-* | pmin | dec3100 | decstatn)
+		basic_machine=mips-dec
+		;;
+	decsystem10* | dec10*)
+		basic_machine=pdp10-dec
+		os=-tops10
+		;;
+	decsystem20* | dec20*)
+		basic_machine=pdp10-dec
+		os=-tops20
+		;;
+	delta | 3300 | motorola-3300 | motorola-delta \
+	      | 3300-motorola | delta-motorola)
+		basic_machine=m68k-motorola
+		;;
+	delta88)
+		basic_machine=m88k-motorola
+		os=-sysv3
+		;;
+	dicos)
+		basic_machine=i686-pc
+		os=-dicos
+		;;
+	djgpp)
+		basic_machine=i586-pc
+		os=-msdosdjgpp
+		;;
+	dpx20 | dpx20-*)
+		basic_machine=rs6000-bull
+		os=-bosx
+		;;
+	dpx2* | dpx2*-bull)
+		basic_machine=m68k-bull
+		os=-sysv3
+		;;
+	ebmon29k)
+		basic_machine=a29k-amd
+		os=-ebmon
+		;;
+	elxsi)
+		basic_machine=elxsi-elxsi
+		os=-bsd
+		;;
+	encore | umax | mmax)
+		basic_machine=ns32k-encore
+		;;
+	es1800 | OSE68k | ose68k | ose | OSE)
+		basic_machine=m68k-ericsson
+		os=-ose
+		;;
+	fx2800)
+		basic_machine=i860-alliant
+		;;
+	genix)
+		basic_machine=ns32k-ns
+		;;
+	gmicro)
+		basic_machine=tron-gmicro
+		os=-sysv
+		;;
+	go32)
+		basic_machine=i386-pc
+		os=-go32
+		;;
+	h3050r* | hiux*)
+		basic_machine=hppa1.1-hitachi
+		os=-hiuxwe2
+		;;
+	h8300hms)
+		basic_machine=h8300-hitachi
+		os=-hms
+		;;
+	h8300xray)
+		basic_machine=h8300-hitachi
+		os=-xray
+		;;
+	h8500hms)
+		basic_machine=h8500-hitachi
+		os=-hms
+		;;
+	harris)
+		basic_machine=m88k-harris
+		os=-sysv3
+		;;
+	hp300-*)
+		basic_machine=m68k-hp
+		;;
+	hp300bsd)
+		basic_machine=m68k-hp
+		os=-bsd
+		;;
+	hp300hpux)
+		basic_machine=m68k-hp
+		os=-hpux
+		;;
+	hp3k9[0-9][0-9] | hp9[0-9][0-9])
+		basic_machine=hppa1.0-hp
+		;;
+	hp9k2[0-9][0-9] | hp9k31[0-9])
+		basic_machine=m68000-hp
+		;;
+	hp9k3[2-9][0-9])
+		basic_machine=m68k-hp
+		;;
+	hp9k6[0-9][0-9] | hp6[0-9][0-9])
+		basic_machine=hppa1.0-hp
+		;;
+	hp9k7[0-79][0-9] | hp7[0-79][0-9])
+		basic_machine=hppa1.1-hp
+		;;
+	hp9k78[0-9] | hp78[0-9])
+		# FIXME: really hppa2.0-hp
+		basic_machine=hppa1.1-hp
+		;;
+	hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893)
+		# FIXME: really hppa2.0-hp
+		basic_machine=hppa1.1-hp
+		;;
+	hp9k8[0-9][13679] | hp8[0-9][13679])
+		basic_machine=hppa1.1-hp
+		;;
+	hp9k8[0-9][0-9] | hp8[0-9][0-9])
+		basic_machine=hppa1.0-hp
+		;;
+	hppa-next)
+		os=-nextstep3
+		;;
+	hppaosf)
+		basic_machine=hppa1.1-hp
+		os=-osf
+		;;
+	hppro)
+		basic_machine=hppa1.1-hp
+		os=-proelf
+		;;
+	i370-ibm* | ibm*)
+		basic_machine=i370-ibm
+		;;
+# I'm not sure what "Sysv32" means.  Should this be sysv3.2?
+	i*86v32)
+		basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
+		os=-sysv32
+		;;
+	i*86v4*)
+		basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
+		os=-sysv4
+		;;
+	i*86v)
+		basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
+		os=-sysv
+		;;
+	i*86sol2)
+		basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
+		os=-solaris2
+		;;
+	i386mach)
+		basic_machine=i386-mach
+		os=-mach
+		;;
+	i386-vsta | vsta)
+		basic_machine=i386-unknown
+		os=-vsta
+		;;
+	iris | iris4d)
+		basic_machine=mips-sgi
+		case $os in
+		    -irix*)
+			;;
+		    *)
+			os=-irix4
+			;;
+		esac
+		;;
+	isi68 | isi)
+		basic_machine=m68k-isi
+		os=-sysv
+		;;
+	m68knommu)
+		basic_machine=m68k-unknown
+		os=-linux
+		;;
+	m68knommu-*)
+		basic_machine=m68k-`echo $basic_machine | sed 's/^[^-]*-//'`
+		os=-linux
+		;;
+	m88k-omron*)
+		basic_machine=m88k-omron
+		;;
+	magnum | m3230)
+		basic_machine=mips-mips
+		os=-sysv
+		;;
+	merlin)
+		basic_machine=ns32k-utek
+		os=-sysv
+		;;
+	mingw32)
+		basic_machine=i386-pc
+		os=-mingw32
+		;;
+	mingw32ce)
+		basic_machine=arm-unknown
+		os=-mingw32ce
+		;;
+	miniframe)
+		basic_machine=m68000-convergent
+		;;
+	*mint | -mint[0-9]* | *MiNT | *MiNT[0-9]*)
+		basic_machine=m68k-atari
+		os=-mint
+		;;
+	mips3*-*)
+		basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`
+		;;
+	mips3*)
+		basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown
+		;;
+	monitor)
+		basic_machine=m68k-rom68k
+		os=-coff
+		;;
+	morphos)
+		basic_machine=powerpc-unknown
+		os=-morphos
+		;;
+	msdos)
+		basic_machine=i386-pc
+		os=-msdos
+		;;
+	ms1-*)
+		basic_machine=`echo $basic_machine | sed -e 's/ms1-/mt-/'`
+		;;
+	mvs)
+		basic_machine=i370-ibm
+		os=-mvs
+		;;
+	ncr3000)
+		basic_machine=i486-ncr
+		os=-sysv4
+		;;
+	netbsd386)
+		basic_machine=i386-unknown
+		os=-netbsd
+		;;
+	netwinder)
+		basic_machine=armv4l-rebel
+		os=-linux
+		;;
+	news | news700 | news800 | news900)
+		basic_machine=m68k-sony
+		os=-newsos
+		;;
+	news1000)
+		basic_machine=m68030-sony
+		os=-newsos
+		;;
+	news-3600 | risc-news)
+		basic_machine=mips-sony
+		os=-newsos
+		;;
+	necv70)
+		basic_machine=v70-nec
+		os=-sysv
+		;;
+	next | m*-next )
+		basic_machine=m68k-next
+		case $os in
+		    -nextstep* )
+			;;
+		    -ns2*)
+		      os=-nextstep2
+			;;
+		    *)
+		      os=-nextstep3
+			;;
+		esac
+		;;
+	nh3000)
+		basic_machine=m68k-harris
+		os=-cxux
+		;;
+	nh[45]000)
+		basic_machine=m88k-harris
+		os=-cxux
+		;;
+	nindy960)
+		basic_machine=i960-intel
+		os=-nindy
+		;;
+	mon960)
+		basic_machine=i960-intel
+		os=-mon960
+		;;
+	nonstopux)
+		basic_machine=mips-compaq
+		os=-nonstopux
+		;;
+	np1)
+		basic_machine=np1-gould
+		;;
+	nsr-tandem)
+		basic_machine=nsr-tandem
+		;;
+	op50n-* | op60c-*)
+		basic_machine=hppa1.1-oki
+		os=-proelf
+		;;
+	openrisc | openrisc-*)
+		basic_machine=or32-unknown
+		;;
+	os400)
+		basic_machine=powerpc-ibm
+		os=-os400
+		;;
+	OSE68000 | ose68000)
+		basic_machine=m68000-ericsson
+		os=-ose
+		;;
+	os68k)
+		basic_machine=m68k-none
+		os=-os68k
+		;;
+	pa-hitachi)
+		basic_machine=hppa1.1-hitachi
+		os=-hiuxwe2
+		;;
+	paragon)
+		basic_machine=i860-intel
+		os=-osf
+		;;
+	parisc)
+		basic_machine=hppa-unknown
+		os=-linux
+		;;
+	parisc-*)
+		basic_machine=hppa-`echo $basic_machine | sed 's/^[^-]*-//'`
+		os=-linux
+		;;
+	pbd)
+		basic_machine=sparc-tti
+		;;
+	pbb)
+		basic_machine=m68k-tti
+		;;
+	pc532 | pc532-*)
+		basic_machine=ns32k-pc532
+		;;
+	pc98)
+		basic_machine=i386-pc
+		;;
+	pc98-*)
+		basic_machine=i386-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	pentium | p5 | k5 | k6 | nexgen | viac3)
+		basic_machine=i586-pc
+		;;
+	pentiumpro | p6 | 6x86 | athlon | athlon_*)
+		basic_machine=i686-pc
+		;;
+	pentiumii | pentium2 | pentiumiii | pentium3)
+		basic_machine=i686-pc
+		;;
+	pentium4)
+		basic_machine=i786-pc
+		;;
+	pentium-* | p5-* | k5-* | k6-* | nexgen-* | viac3-*)
+		basic_machine=i586-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	pentiumpro-* | p6-* | 6x86-* | athlon-*)
+		basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	pentiumii-* | pentium2-* | pentiumiii-* | pentium3-*)
+		basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	pentium4-*)
+		basic_machine=i786-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	pn)
+		basic_machine=pn-gould
+		;;
+	power)	basic_machine=power-ibm
+		;;
+	ppc)	basic_machine=powerpc-unknown
+		;;
+	ppc-*)	basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	ppcle | powerpclittle | ppc-le | powerpc-little)
+		basic_machine=powerpcle-unknown
+		;;
+	ppcle-* | powerpclittle-*)
+		basic_machine=powerpcle-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	ppc64)	basic_machine=powerpc64-unknown
+		;;
+	ppc64-*) basic_machine=powerpc64-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	ppc64le | powerpc64little | ppc64-le | powerpc64-little)
+		basic_machine=powerpc64le-unknown
+		;;
+	ppc64le-* | powerpc64little-*)
+		basic_machine=powerpc64le-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	ps2)
+		basic_machine=i386-ibm
+		;;
+	pw32)
+		basic_machine=i586-unknown
+		os=-pw32
+		;;
+	rdos)
+		basic_machine=i386-pc
+		os=-rdos
+		;;
+	rom68k)
+		basic_machine=m68k-rom68k
+		os=-coff
+		;;
+	rm[46]00)
+		basic_machine=mips-siemens
+		;;
+	rtpc | rtpc-*)
+		basic_machine=romp-ibm
+		;;
+	s390 | s390-*)
+		basic_machine=s390-ibm
+		;;
+	s390x | s390x-*)
+		basic_machine=s390x-ibm
+		;;
+	sa29200)
+		basic_machine=a29k-amd
+		os=-udi
+		;;
+	sb1)
+		basic_machine=mipsisa64sb1-unknown
+		;;
+	sb1el)
+		basic_machine=mipsisa64sb1el-unknown
+		;;
+	sde)
+		basic_machine=mipsisa32-sde
+		os=-elf
+		;;
+	sei)
+		basic_machine=mips-sei
+		os=-seiux
+		;;
+	sequent)
+		basic_machine=i386-sequent
+		;;
+	sh)
+		basic_machine=sh-hitachi
+		os=-hms
+		;;
+	sh5el)
+		basic_machine=sh5le-unknown
+		;;
+	sh64)
+		basic_machine=sh64-unknown
+		;;
+	sparclite-wrs | simso-wrs)
+		basic_machine=sparclite-wrs
+		os=-vxworks
+		;;
+	sps7)
+		basic_machine=m68k-bull
+		os=-sysv2
+		;;
+	spur)
+		basic_machine=spur-unknown
+		;;
+	st2000)
+		basic_machine=m68k-tandem
+		;;
+	stratus)
+		basic_machine=i860-stratus
+		os=-sysv4
+		;;
+	sun2)
+		basic_machine=m68000-sun
+		;;
+	sun2os3)
+		basic_machine=m68000-sun
+		os=-sunos3
+		;;
+	sun2os4)
+		basic_machine=m68000-sun
+		os=-sunos4
+		;;
+	sun3os3)
+		basic_machine=m68k-sun
+		os=-sunos3
+		;;
+	sun3os4)
+		basic_machine=m68k-sun
+		os=-sunos4
+		;;
+	sun4os3)
+		basic_machine=sparc-sun
+		os=-sunos3
+		;;
+	sun4os4)
+		basic_machine=sparc-sun
+		os=-sunos4
+		;;
+	sun4sol2)
+		basic_machine=sparc-sun
+		os=-solaris2
+		;;
+	sun3 | sun3-*)
+		basic_machine=m68k-sun
+		;;
+	sun4)
+		basic_machine=sparc-sun
+		;;
+	sun386 | sun386i | roadrunner)
+		basic_machine=i386-sun
+		;;
+	sv1)
+		basic_machine=sv1-cray
+		os=-unicos
+		;;
+	symmetry)
+		basic_machine=i386-sequent
+		os=-dynix
+		;;
+	t3e)
+		basic_machine=alphaev5-cray
+		os=-unicos
+		;;
+	t90)
+		basic_machine=t90-cray
+		os=-unicos
+		;;
+	tic54x | c54x*)
+		basic_machine=tic54x-unknown
+		os=-coff
+		;;
+	tic55x | c55x*)
+		basic_machine=tic55x-unknown
+		os=-coff
+		;;
+	tic6x | c6x*)
+		basic_machine=tic6x-unknown
+		os=-coff
+		;;
+	tile*)
+		basic_machine=tile-unknown
+		os=-linux-gnu
+		;;
+	tx39)
+		basic_machine=mipstx39-unknown
+		;;
+	tx39el)
+		basic_machine=mipstx39el-unknown
+		;;
+	toad1)
+		basic_machine=pdp10-xkl
+		os=-tops20
+		;;
+	tower | tower-32)
+		basic_machine=m68k-ncr
+		;;
+	tpf)
+		basic_machine=s390x-ibm
+		os=-tpf
+		;;
+	udi29k)
+		basic_machine=a29k-amd
+		os=-udi
+		;;
+	ultra3)
+		basic_machine=a29k-nyu
+		os=-sym1
+		;;
+	v810 | necv810)
+		basic_machine=v810-nec
+		os=-none
+		;;
+	vaxv)
+		basic_machine=vax-dec
+		os=-sysv
+		;;
+	vms)
+		basic_machine=vax-dec
+		os=-vms
+		;;
+	vpp*|vx|vx-*)
+		basic_machine=f301-fujitsu
+		;;
+	vxworks960)
+		basic_machine=i960-wrs
+		os=-vxworks
+		;;
+	vxworks68)
+		basic_machine=m68k-wrs
+		os=-vxworks
+		;;
+	vxworks29k)
+		basic_machine=a29k-wrs
+		os=-vxworks
+		;;
+	w65*)
+		basic_machine=w65-wdc
+		os=-none
+		;;
+	w89k-*)
+		basic_machine=hppa1.1-winbond
+		os=-proelf
+		;;
+	xbox)
+		basic_machine=i686-pc
+		os=-mingw32
+		;;
+	xps | xps100)
+		basic_machine=xps100-honeywell
+		;;
+	ymp)
+		basic_machine=ymp-cray
+		os=-unicos
+		;;
+	z8k-*-coff)
+		basic_machine=z8k-unknown
+		os=-sim
+		;;
+	z80-*-coff)
+		basic_machine=z80-unknown
+		os=-sim
+		;;
+	none)
+		basic_machine=none-none
+		os=-none
+		;;
+
+# Here we handle the default manufacturer of certain CPU types.  It is in
+# some cases the only manufacturer, in others, it is the most popular.
+	w89k)
+		basic_machine=hppa1.1-winbond
+		;;
+	op50n)
+		basic_machine=hppa1.1-oki
+		;;
+	op60c)
+		basic_machine=hppa1.1-oki
+		;;
+	romp)
+		basic_machine=romp-ibm
+		;;
+	mmix)
+		basic_machine=mmix-knuth
+		;;
+	rs6000)
+		basic_machine=rs6000-ibm
+		;;
+	vax)
+		basic_machine=vax-dec
+		;;
+	pdp10)
+		# there are many clones, so DEC is not a safe bet
+		basic_machine=pdp10-unknown
+		;;
+	pdp11)
+		basic_machine=pdp11-dec
+		;;
+	we32k)
+		basic_machine=we32k-att
+		;;
+	sh[1234] | sh[24]a | sh[24]aeb | sh[34]eb | sh[1234]le | sh[23]ele)
+		basic_machine=sh-unknown
+		;;
+	sparc | sparcv8 | sparcv9 | sparcv9b | sparcv9v)
+		basic_machine=sparc-sun
+		;;
+	cydra)
+		basic_machine=cydra-cydrome
+		;;
+	orion)
+		basic_machine=orion-highlevel
+		;;
+	orion105)
+		basic_machine=clipper-highlevel
+		;;
+	mac | mpw | mac-mpw)
+		basic_machine=m68k-apple
+		;;
+	pmac | pmac-mpw)
+		basic_machine=powerpc-apple
+		;;
+	*-unknown)
+		# Make sure to match an already-canonicalized machine name.
+		;;
+	*)
+		echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2
+		exit 1
+		;;
+esac
+
+# Here we canonicalize certain aliases for manufacturers.
+case $basic_machine in
+	*-digital*)
+		basic_machine=`echo $basic_machine | sed 's/digital.*/dec/'`
+		;;
+	*-commodore*)
+		basic_machine=`echo $basic_machine | sed 's/commodore.*/cbm/'`
+		;;
+	*)
+		;;
+esac
+
+# Decode manufacturer-specific aliases for certain operating systems.
+
+if [ x"$os" != x"" ]
+then
+case $os in
+        # First match some system type aliases
+        # that might get confused with valid system types.
+	# -solaris* is a basic system type, with this one exception.
+	-solaris1 | -solaris1.*)
+		os=`echo $os | sed -e 's|solaris1|sunos4|'`
+		;;
+	-solaris)
+		os=-solaris2
+		;;
+	-svr4*)
+		os=-sysv4
+		;;
+	-unixware*)
+		os=-sysv4.2uw
+		;;
+	-gnu/linux*)
+		os=`echo $os | sed -e 's|gnu/linux|linux-gnu|'`
+		;;
+	# First accept the basic system types.
+	# The portable systems comes first.
+	# Each alternative MUST END IN A *, to match a version number.
+	# -sysv* is not here because it comes later, after sysvr4.
+	-gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \
+	      | -*vms* | -sco* | -esix* | -isc* | -aix* | -sunos | -sunos[34]*\
+	      | -hpux* | -unos* | -osf* | -luna* | -dgux* | -solaris* | -sym* \
+	      | -kopensolaris* \
+	      | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \
+	      | -aos* | -aros* \
+	      | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \
+	      | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \
+	      | -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \
+	      | -openbsd* | -solidbsd* \
+	      | -ekkobsd* | -kfreebsd* | -freebsd* | -riscix* | -lynxos* \
+	      | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \
+	      | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \
+	      | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \
+	      | -chorusos* | -chorusrdb* | -cegcc* \
+	      | -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \
+	      | -mingw32* | -linux-gnu* | -linux-newlib* | -linux-uclibc* \
+	      | -uxpv* | -beos* | -mpeix* | -udk* \
+	      | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \
+	      | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \
+	      | -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \
+	      | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \
+	      | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \
+	      | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \
+	      | -skyos* | -haiku* | -rdos* | -toppers* | -drops*)
+	# Remember, each alternative MUST END IN *, to match a version number.
+		;;
+	-qnx*)
+		case $basic_machine in
+		    x86-* | i*86-*)
+			;;
+		    *)
+			os=-nto$os
+			;;
+		esac
+		;;
+	-nto-qnx*)
+		;;
+	-nto*)
+		os=`echo $os | sed -e 's|nto|nto-qnx|'`
+		;;
+	-sim | -es1800* | -hms* | -xray | -os68k* | -none* | -v88r* \
+	      | -windows* | -osx | -abug | -netware* | -os9* | -beos* | -haiku* \
+	      | -macos* | -mpw* | -magic* | -mmixware* | -mon960* | -lnews*)
+		;;
+	-mac*)
+		os=`echo $os | sed -e 's|mac|macos|'`
+		;;
+	-linux-dietlibc)
+		os=-linux-dietlibc
+		;;
+	-linux*)
+		os=`echo $os | sed -e 's|linux|linux-gnu|'`
+		;;
+	-sunos5*)
+		os=`echo $os | sed -e 's|sunos5|solaris2|'`
+		;;
+	-sunos6*)
+		os=`echo $os | sed -e 's|sunos6|solaris3|'`
+		;;
+	-opened*)
+		os=-openedition
+		;;
+        -os400*)
+		os=-os400
+		;;
+	-wince*)
+		os=-wince
+		;;
+	-osfrose*)
+		os=-osfrose
+		;;
+	-osf*)
+		os=-osf
+		;;
+	-utek*)
+		os=-bsd
+		;;
+	-dynix*)
+		os=-bsd
+		;;
+	-acis*)
+		os=-aos
+		;;
+	-atheos*)
+		os=-atheos
+		;;
+	-syllable*)
+		os=-syllable
+		;;
+	-386bsd)
+		os=-bsd
+		;;
+	-ctix* | -uts*)
+		os=-sysv
+		;;
+	-nova*)
+		os=-rtmk-nova
+		;;
+	-ns2 )
+		os=-nextstep2
+		;;
+	-nsk*)
+		os=-nsk
+		;;
+	# Preserve the version number of sinix5.
+	-sinix5.*)
+		os=`echo $os | sed -e 's|sinix|sysv|'`
+		;;
+	-sinix*)
+		os=-sysv4
+		;;
+        -tpf*)
+		os=-tpf
+		;;
+	-triton*)
+		os=-sysv3
+		;;
+	-oss*)
+		os=-sysv3
+		;;
+	-svr4)
+		os=-sysv4
+		;;
+	-svr3)
+		os=-sysv3
+		;;
+	-sysvr4)
+		os=-sysv4
+		;;
+	# This must come after -sysvr4.
+	-sysv*)
+		;;
+	-ose*)
+		os=-ose
+		;;
+	-es1800*)
+		os=-ose
+		;;
+	-xenix)
+		os=-xenix
+		;;
+	-*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*)
+		os=-mint
+		;;
+	-aros*)
+		os=-aros
+		;;
+	-kaos*)
+		os=-kaos
+		;;
+	-zvmoe)
+		os=-zvmoe
+		;;
+	-dicos*)
+		os=-dicos
+		;;
+	-none)
+		;;
+	*)
+		# Get rid of the `-' at the beginning of $os.
+		os=`echo $os | sed 's/[^-]*-//'`
+		echo Invalid configuration \`$1\': system \`$os\' not recognized 1>&2
+		exit 1
+		;;
+esac
+else
+
+# Here we handle the default operating systems that come with various machines.
+# The value should be what the vendor currently ships out the door with their
+# machine or put another way, the most popular os provided with the machine.
+
+# Note that if you're going to try to match "-MANUFACTURER" here (say,
+# "-sun"), then you have to tell the case statement up towards the top
+# that MANUFACTURER isn't an operating system.  Otherwise, code above
+# will signal an error saying that MANUFACTURER isn't an operating
+# system, and we'll never get to this point.
+
+case $basic_machine in
+        score-*)
+		os=-elf
+		;;
+        spu-*)
+		os=-elf
+		;;
+	*-acorn)
+		os=-riscix1.2
+		;;
+	arm*-rebel)
+		os=-linux
+		;;
+	arm*-semi)
+		os=-aout
+		;;
+        c4x-* | tic4x-*)
+        	os=-coff
+		;;
+	# This must come before the *-dec entry.
+	pdp10-*)
+		os=-tops20
+		;;
+	pdp11-*)
+		os=-none
+		;;
+	*-dec | vax-*)
+		os=-ultrix4.2
+		;;
+	m68*-apollo)
+		os=-domain
+		;;
+	i386-sun)
+		os=-sunos4.0.2
+		;;
+	m68000-sun)
+		os=-sunos3
+		# This also exists in the configure program, but was not the
+		# default.
+		# os=-sunos4
+		;;
+	m68*-cisco)
+		os=-aout
+		;;
+        mep-*)
+		os=-elf
+		;;
+	mips*-cisco)
+		os=-elf
+		;;
+	mips*-*)
+		os=-elf
+		;;
+	or32-*)
+		os=-coff
+		;;
+	*-tti)	# must be before sparc entry or we get the wrong os.
+		os=-sysv3
+		;;
+	sparc-* | *-sun)
+		os=-sunos4.1.1
+		;;
+	*-be)
+		os=-beos
+		;;
+	*-haiku)
+		os=-haiku
+		;;
+	*-ibm)
+		os=-aix
+		;;
+    	*-knuth)
+		os=-mmixware
+		;;
+	*-wec)
+		os=-proelf
+		;;
+	*-winbond)
+		os=-proelf
+		;;
+	*-oki)
+		os=-proelf
+		;;
+	*-hp)
+		os=-hpux
+		;;
+	*-hitachi)
+		os=-hiux
+		;;
+	i860-* | *-att | *-ncr | *-altos | *-motorola | *-convergent)
+		os=-sysv
+		;;
+	*-cbm)
+		os=-amigaos
+		;;
+	*-dg)
+		os=-dgux
+		;;
+	*-dolphin)
+		os=-sysv3
+		;;
+	m68k-ccur)
+		os=-rtu
+		;;
+	m88k-omron*)
+		os=-luna
+		;;
+	*-next )
+		os=-nextstep
+		;;
+	*-sequent)
+		os=-ptx
+		;;
+	*-crds)
+		os=-unos
+		;;
+	*-ns)
+		os=-genix
+		;;
+	i370-*)
+		os=-mvs
+		;;
+	*-next)
+		os=-nextstep3
+		;;
+	*-gould)
+		os=-sysv
+		;;
+	*-highlevel)
+		os=-bsd
+		;;
+	*-encore)
+		os=-bsd
+		;;
+	*-sgi)
+		os=-irix
+		;;
+	*-siemens)
+		os=-sysv4
+		;;
+	*-masscomp)
+		os=-rtu
+		;;
+	f30[01]-fujitsu | f700-fujitsu)
+		os=-uxpv
+		;;
+	*-rom68k)
+		os=-coff
+		;;
+	*-*bug)
+		os=-coff
+		;;
+	*-apple)
+		os=-macos
+		;;
+	*-atari*)
+		os=-mint
+		;;
+	*)
+		os=-none
+		;;
+esac
+fi
+
+# Here we handle the case where we know the os, and the CPU type, but not the
+# manufacturer.  We pick the logical manufacturer.
+vendor=unknown
+case $basic_machine in
+	*-unknown)
+		case $os in
+			-riscix*)
+				vendor=acorn
+				;;
+			-sunos*)
+				vendor=sun
+				;;
+			-aix*)
+				vendor=ibm
+				;;
+			-beos*)
+				vendor=be
+				;;
+			-hpux*)
+				vendor=hp
+				;;
+			-mpeix*)
+				vendor=hp
+				;;
+			-hiux*)
+				vendor=hitachi
+				;;
+			-unos*)
+				vendor=crds
+				;;
+			-dgux*)
+				vendor=dg
+				;;
+			-luna*)
+				vendor=omron
+				;;
+			-genix*)
+				vendor=ns
+				;;
+			-mvs* | -opened*)
+				vendor=ibm
+				;;
+			-os400*)
+				vendor=ibm
+				;;
+			-ptx*)
+				vendor=sequent
+				;;
+			-tpf*)
+				vendor=ibm
+				;;
+			-vxsim* | -vxworks* | -windiss*)
+				vendor=wrs
+				;;
+			-aux*)
+				vendor=apple
+				;;
+			-hms*)
+				vendor=hitachi
+				;;
+			-mpw* | -macos*)
+				vendor=apple
+				;;
+			-*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*)
+				vendor=atari
+				;;
+			-vos*)
+				vendor=stratus
+				;;
+		esac
+		basic_machine=`echo $basic_machine | sed "s/unknown/$vendor/"`
+		;;
+esac
+
+echo $basic_machine$os
+exit
+
+# Local variables:
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "timestamp='"
+# time-stamp-format: "%:y-%02m-%02d"
+# time-stamp-end: "'"
+# End:
diff --git a/admin/depcomp b/admin/depcomp
new file mode 100755
index 0000000..df8eea7
--- /dev/null
+++ b/admin/depcomp
@@ -0,0 +1,630 @@
+#! /bin/sh
+# depcomp - compile a program generating dependencies as side-effects
+
+scriptversion=2009-04-28.21; # UTC
+
+# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2006, 2007, 2009 Free
+# Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that program.
+
+# Originally written by Alexandre Oliva <oliva at dcc.unicamp.br>.
+
+case $1 in
+  '')
+     echo "$0: No command.  Try \`$0 --help' for more information." 1>&2
+     exit 1;
+     ;;
+  -h | --h*)
+    cat <<\EOF
+Usage: depcomp [--help] [--version] PROGRAM [ARGS]
+
+Run PROGRAMS ARGS to compile a file, generating dependencies
+as side-effects.
+
+Environment variables:
+  depmode     Dependency tracking mode.
+  source      Source file read by `PROGRAMS ARGS'.
+  object      Object file output by `PROGRAMS ARGS'.
+  DEPDIR      directory where to store dependencies.
+  depfile     Dependency file to output.
+  tmpdepfile  Temporary file to use when outputing dependencies.
+  libtool     Whether libtool is used (yes/no).
+
+Report bugs to <bug-automake at gnu.org>.
+EOF
+    exit $?
+    ;;
+  -v | --v*)
+    echo "depcomp $scriptversion"
+    exit $?
+    ;;
+esac
+
+if test -z "$depmode" || test -z "$source" || test -z "$object"; then
+  echo "depcomp: Variables source, object and depmode must be set" 1>&2
+  exit 1
+fi
+
+# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
+depfile=${depfile-`echo "$object" |
+  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
+tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
+
+rm -f "$tmpdepfile"
+
+# Some modes work just like other modes, but use different flags.  We
+# parameterize here, but still list the modes in the big case below,
+# to make depend.m4 easier to write.  Note that we *cannot* use a case
+# here, because this file can only contain one case statement.
+if test "$depmode" = hp; then
+  # HP compiler uses -M and no extra arg.
+  gccflag=-M
+  depmode=gcc
+fi
+
+if test "$depmode" = dashXmstdout; then
+   # This is just like dashmstdout with a different argument.
+   dashmflag=-xM
+   depmode=dashmstdout
+fi
+
+cygpath_u="cygpath -u -f -"
+if test "$depmode" = msvcmsys; then
+   # This is just like msvisualcpp but w/o cygpath translation.
+   # Just convert the backslash-escaped backslashes to single forward
+   # slashes to satisfy depend.m4
+   cygpath_u="sed s,\\\\\\\\,/,g"
+   depmode=msvisualcpp
+fi
+
+case "$depmode" in
+gcc3)
+## gcc 3 implements dependency tracking that does exactly what
+## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
+## it if -MD -MP comes after the -MF stuff.  Hmm.
+## Unfortunately, FreeBSD c89 acceptance of flags depends upon
+## the command line argument order; so add the flags where they
+## appear in depend2.am.  Note that the slowdown incurred here
+## affects only configure: in makefiles, %FASTDEP% shortcuts this.
+  for arg
+  do
+    case $arg in
+    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
+    *)  set fnord "$@" "$arg" ;;
+    esac
+    shift # fnord
+    shift # $arg
+  done
+  "$@"
+  stat=$?
+  if test $stat -eq 0; then :
+  else
+    rm -f "$tmpdepfile"
+    exit $stat
+  fi
+  mv "$tmpdepfile" "$depfile"
+  ;;
+
+gcc)
+## There are various ways to get dependency output from gcc.  Here's
+## why we pick this rather obscure method:
+## - Don't want to use -MD because we'd like the dependencies to end
+##   up in a subdir.  Having to rename by hand is ugly.
+##   (We might end up doing this anyway to support other compilers.)
+## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
+##   -MM, not -M (despite what the docs say).
+## - Using -M directly means running the compiler twice (even worse
+##   than renaming).
+  if test -z "$gccflag"; then
+    gccflag=-MD,
+  fi
+  "$@" -Wp,"$gccflag$tmpdepfile"
+  stat=$?
+  if test $stat -eq 0; then :
+  else
+    rm -f "$tmpdepfile"
+    exit $stat
+  fi
+  rm -f "$depfile"
+  echo "$object : \\" > "$depfile"
+  alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
+## The second -e expression handles DOS-style file names with drive letters.
+  sed -e 's/^[^:]*: / /' \
+      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
+## This next piece of magic avoids the `deleted header file' problem.
+## The problem is that when a header file which appears in a .P file
+## is deleted, the dependency causes make to die (because there is
+## typically no way to rebuild the header).  We avoid this by adding
+## dummy dependencies for each header file.  Too bad gcc doesn't do
+## this for us directly.
+  tr ' ' '
+' < "$tmpdepfile" |
+## Some versions of gcc put a space before the `:'.  On the theory
+## that the space means something, we add a space to the output as
+## well.
+## Some versions of the HPUX 10.20 sed can't process this invocation
+## correctly.  Breaking it into two sed invocations is a workaround.
+    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
+  rm -f "$tmpdepfile"
+  ;;
+
+hp)
+  # This case exists only to let depend.m4 do its work.  It works by
+  # looking at the text of this script.  This case will never be run,
+  # since it is checked for above.
+  exit 1
+  ;;
+
+sgi)
+  if test "$libtool" = yes; then
+    "$@" "-Wp,-MDupdate,$tmpdepfile"
+  else
+    "$@" -MDupdate "$tmpdepfile"
+  fi
+  stat=$?
+  if test $stat -eq 0; then :
+  else
+    rm -f "$tmpdepfile"
+    exit $stat
+  fi
+  rm -f "$depfile"
+
+  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
+    echo "$object : \\" > "$depfile"
+
+    # Clip off the initial element (the dependent).  Don't try to be
+    # clever and replace this with sed code, as IRIX sed won't handle
+    # lines with more than a fixed number of characters (4096 in
+    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
+    # the IRIX cc adds comments like `#:fec' to the end of the
+    # dependency line.
+    tr ' ' '
+' < "$tmpdepfile" \
+    | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
+    tr '
+' ' ' >> "$depfile"
+    echo >> "$depfile"
+
+    # The second pass generates a dummy entry for each header file.
+    tr ' ' '
+' < "$tmpdepfile" \
+   | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
+   >> "$depfile"
+  else
+    # The sourcefile does not contain any dependencies, so just
+    # store a dummy comment line, to avoid errors with the Makefile
+    # "include basename.Plo" scheme.
+    echo "#dummy" > "$depfile"
+  fi
+  rm -f "$tmpdepfile"
+  ;;
+
+aix)
+  # The C for AIX Compiler uses -M and outputs the dependencies
+  # in a .u file.  In older versions, this file always lives in the
+  # current directory.  Also, the AIX compiler puts `$object:' at the
+  # start of each line; $object doesn't have directory information.
+  # Version 6 uses the directory in both cases.
+  dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
+  test "x$dir" = "x$object" && dir=
+  base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
+  if test "$libtool" = yes; then
+    tmpdepfile1=$dir$base.u
+    tmpdepfile2=$base.u
+    tmpdepfile3=$dir.libs/$base.u
+    "$@" -Wc,-M
+  else
+    tmpdepfile1=$dir$base.u
+    tmpdepfile2=$dir$base.u
+    tmpdepfile3=$dir$base.u
+    "$@" -M
+  fi
+  stat=$?
+
+  if test $stat -eq 0; then :
+  else
+    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
+    exit $stat
+  fi
+
+  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
+  do
+    test -f "$tmpdepfile" && break
+  done
+  if test -f "$tmpdepfile"; then
+    # Each line is of the form `foo.o: dependent.h'.
+    # Do two passes, one to just change these to
+    # `$object: dependent.h' and one to simply `dependent.h:'.
+    sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
+    # That's a tab and a space in the [].
+    sed -e 's,^.*\.[a-z]*:[	 ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
+  else
+    # The sourcefile does not contain any dependencies, so just
+    # store a dummy comment line, to avoid errors with the Makefile
+    # "include basename.Plo" scheme.
+    echo "#dummy" > "$depfile"
+  fi
+  rm -f "$tmpdepfile"
+  ;;
+
+icc)
+  # Intel's C compiler understands `-MD -MF file'.  However on
+  #    icc -MD -MF foo.d -c -o sub/foo.o sub/foo.c
+  # ICC 7.0 will fill foo.d with something like
+  #    foo.o: sub/foo.c
+  #    foo.o: sub/foo.h
+  # which is wrong.  We want:
+  #    sub/foo.o: sub/foo.c
+  #    sub/foo.o: sub/foo.h
+  #    sub/foo.c:
+  #    sub/foo.h:
+  # ICC 7.1 will output
+  #    foo.o: sub/foo.c sub/foo.h
+  # and will wrap long lines using \ :
+  #    foo.o: sub/foo.c ... \
+  #     sub/foo.h ... \
+  #     ...
+
+  "$@" -MD -MF "$tmpdepfile"
+  stat=$?
+  if test $stat -eq 0; then :
+  else
+    rm -f "$tmpdepfile"
+    exit $stat
+  fi
+  rm -f "$depfile"
+  # Each line is of the form `foo.o: dependent.h',
+  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
+  # Do two passes, one to just change these to
+  # `$object: dependent.h' and one to simply `dependent.h:'.
+  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
+  # Some versions of the HPUX 10.20 sed can't process this invocation
+  # correctly.  Breaking it into two sed invocations is a workaround.
+  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" |
+    sed -e 's/$/ :/' >> "$depfile"
+  rm -f "$tmpdepfile"
+  ;;
+
+hp2)
+  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
+  # compilers, which have integrated preprocessors.  The correct option
+  # to use with these is +Maked; it writes dependencies to a file named
+  # 'foo.d', which lands next to the object file, wherever that
+  # happens to be.
+  # Much of this is similar to the tru64 case; see comments there.
+  dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
+  test "x$dir" = "x$object" && dir=
+  base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
+  if test "$libtool" = yes; then
+    tmpdepfile1=$dir$base.d
+    tmpdepfile2=$dir.libs/$base.d
+    "$@" -Wc,+Maked
+  else
+    tmpdepfile1=$dir$base.d
+    tmpdepfile2=$dir$base.d
+    "$@" +Maked
+  fi
+  stat=$?
+  if test $stat -eq 0; then :
+  else
+     rm -f "$tmpdepfile1" "$tmpdepfile2"
+     exit $stat
+  fi
+
+  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
+  do
+    test -f "$tmpdepfile" && break
+  done
+  if test -f "$tmpdepfile"; then
+    sed -e "s,^.*\.[a-z]*:,$object:," "$tmpdepfile" > "$depfile"
+    # Add `dependent.h:' lines.
+    sed -ne '2,${
+	       s/^ *//
+	       s/ \\*$//
+	       s/$/:/
+	       p
+	     }' "$tmpdepfile" >> "$depfile"
+  else
+    echo "#dummy" > "$depfile"
+  fi
+  rm -f "$tmpdepfile" "$tmpdepfile2"
+  ;;
+
+tru64)
+   # The Tru64 compiler uses -MD to generate dependencies as a side
+   # effect.  `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.
+   # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
+   # dependencies in `foo.d' instead, so we check for that too.
+   # Subdirectories are respected.
+   dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
+   test "x$dir" = "x$object" && dir=
+   base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
+
+   if test "$libtool" = yes; then
+      # With Tru64 cc, shared objects can also be used to make a
+      # static library.  This mechanism is used in libtool 1.4 series to
+      # handle both shared and static libraries in a single compilation.
+      # With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d.
+      #
+      # With libtool 1.5 this exception was removed, and libtool now
+      # generates 2 separate objects for the 2 libraries.  These two
+      # compilations output dependencies in $dir.libs/$base.o.d and
+      # in $dir$base.o.d.  We have to check for both files, because
+      # one of the two compilations can be disabled.  We should prefer
+      # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
+      # automatically cleaned when .libs/ is deleted, while ignoring
+      # the former would cause a distcleancheck panic.
+      tmpdepfile1=$dir.libs/$base.lo.d   # libtool 1.4
+      tmpdepfile2=$dir$base.o.d          # libtool 1.5
+      tmpdepfile3=$dir.libs/$base.o.d    # libtool 1.5
+      tmpdepfile4=$dir.libs/$base.d      # Compaq CCC V6.2-504
+      "$@" -Wc,-MD
+   else
+      tmpdepfile1=$dir$base.o.d
+      tmpdepfile2=$dir$base.d
+      tmpdepfile3=$dir$base.d
+      tmpdepfile4=$dir$base.d
+      "$@" -MD
+   fi
+
+   stat=$?
+   if test $stat -eq 0; then :
+   else
+      rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
+      exit $stat
+   fi
+
+   for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
+   do
+     test -f "$tmpdepfile" && break
+   done
+   if test -f "$tmpdepfile"; then
+      sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
+      # That's a tab and a space in the [].
+      sed -e 's,^.*\.[a-z]*:[	 ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
+   else
+      echo "#dummy" > "$depfile"
+   fi
+   rm -f "$tmpdepfile"
+   ;;
+
+#nosideeffect)
+  # This comment above is used by automake to tell side-effect
+  # dependency tracking mechanisms from slower ones.
+
+dashmstdout)
+  # Important note: in order to support this mode, a compiler *must*
+  # always write the preprocessed file to stdout, regardless of -o.
+  "$@" || exit $?
+
+  # Remove the call to Libtool.
+  if test "$libtool" = yes; then
+    while test "X$1" != 'X--mode=compile'; do
+      shift
+    done
+    shift
+  fi
+
+  # Remove `-o $object'.
+  IFS=" "
+  for arg
+  do
+    case $arg in
+    -o)
+      shift
+      ;;
+    $object)
+      shift
+      ;;
+    *)
+      set fnord "$@" "$arg"
+      shift # fnord
+      shift # $arg
+      ;;
+    esac
+  done
+
+  test -z "$dashmflag" && dashmflag=-M
+  # Require at least two characters before searching for `:'
+  # in the target name.  This is to cope with DOS-style filenames:
+  # a dependency such as `c:/foo/bar' could be seen as target `c' otherwise.
+  "$@" $dashmflag |
+    sed 's:^[  ]*[^: ][^:][^:]*\:[    ]*:'"$object"'\: :' > "$tmpdepfile"
+  rm -f "$depfile"
+  cat < "$tmpdepfile" > "$depfile"
+  tr ' ' '
+' < "$tmpdepfile" | \
+## Some versions of the HPUX 10.20 sed can't process this invocation
+## correctly.  Breaking it into two sed invocations is a workaround.
+    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
+  rm -f "$tmpdepfile"
+  ;;
+
+dashXmstdout)
+  # This case only exists to satisfy depend.m4.  It is never actually
+  # run, as this mode is specially recognized in the preamble.
+  exit 1
+  ;;
+
+makedepend)
+  "$@" || exit $?
+  # Remove any Libtool call
+  if test "$libtool" = yes; then
+    while test "X$1" != 'X--mode=compile'; do
+      shift
+    done
+    shift
+  fi
+  # X makedepend
+  shift
+  cleared=no eat=no
+  for arg
+  do
+    case $cleared in
+    no)
+      set ""; shift
+      cleared=yes ;;
+    esac
+    if test $eat = yes; then
+      eat=no
+      continue
+    fi
+    case "$arg" in
+    -D*|-I*)
+      set fnord "$@" "$arg"; shift ;;
+    # Strip any option that makedepend may not understand.  Remove
+    # the object too, otherwise makedepend will parse it as a source file.
+    -arch)
+      eat=yes ;;
+    -*|$object)
+      ;;
+    *)
+      set fnord "$@" "$arg"; shift ;;
+    esac
+  done
+  obj_suffix=`echo "$object" | sed 's/^.*\././'`
+  touch "$tmpdepfile"
+  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
+  rm -f "$depfile"
+  cat < "$tmpdepfile" > "$depfile"
+  sed '1,2d' "$tmpdepfile" | tr ' ' '
+' | \
+## Some versions of the HPUX 10.20 sed can't process this invocation
+## correctly.  Breaking it into two sed invocations is a workaround.
+    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
+  rm -f "$tmpdepfile" "$tmpdepfile".bak
+  ;;
+
+cpp)
+  # Important note: in order to support this mode, a compiler *must*
+  # always write the preprocessed file to stdout.
+  "$@" || exit $?
+
+  # Remove the call to Libtool.
+  if test "$libtool" = yes; then
+    while test "X$1" != 'X--mode=compile'; do
+      shift
+    done
+    shift
+  fi
+
+  # Remove `-o $object'.
+  IFS=" "
+  for arg
+  do
+    case $arg in
+    -o)
+      shift
+      ;;
+    $object)
+      shift
+      ;;
+    *)
+      set fnord "$@" "$arg"
+      shift # fnord
+      shift # $arg
+      ;;
+    esac
+  done
+
+  "$@" -E |
+    sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
+       -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
+    sed '$ s: \\$::' > "$tmpdepfile"
+  rm -f "$depfile"
+  echo "$object : \\" > "$depfile"
+  cat < "$tmpdepfile" >> "$depfile"
+  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
+  rm -f "$tmpdepfile"
+  ;;
+
+msvisualcpp)
+  # Important note: in order to support this mode, a compiler *must*
+  # always write the preprocessed file to stdout.
+  "$@" || exit $?
+
+  # Remove the call to Libtool.
+  if test "$libtool" = yes; then
+    while test "X$1" != 'X--mode=compile'; do
+      shift
+    done
+    shift
+  fi
+
+  IFS=" "
+  for arg
+  do
+    case "$arg" in
+    -o)
+      shift
+      ;;
+    $object)
+      shift
+      ;;
+    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
+	set fnord "$@"
+	shift
+	shift
+	;;
+    *)
+	set fnord "$@" "$arg"
+	shift
+	shift
+	;;
+    esac
+  done
+  "$@" -E 2>/dev/null |
+  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
+  rm -f "$depfile"
+  echo "$object : \\" > "$depfile"
+  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::	\1 \\:p' >> "$depfile"
+  echo "	" >> "$depfile"
+  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
+  rm -f "$tmpdepfile"
+  ;;
+
+msvcmsys)
+  # This case exists only to let depend.m4 do its work.  It works by
+  # looking at the text of this script.  This case will never be run,
+  # since it is checked for above.
+  exit 1
+  ;;
+
+none)
+  exec "$@"
+  ;;
+
+*)
+  echo "Unknown depmode $depmode" 1>&2
+  exit 1
+  ;;
+esac
+
+exit 0
+
+# Local Variables:
+# mode: shell-script
+# sh-indentation: 2
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "scriptversion="
+# time-stamp-format: "%:y-%02m-%02d.%02H"
+# time-stamp-time-zone: "UTC"
+# time-stamp-end: "; # UTC"
+# End:
diff --git a/admin/html.am b/admin/html.am
new file mode 100644
index 0000000..59e55fa
--- /dev/null
+++ b/admin/html.am
@@ -0,0 +1,74 @@
+if MAINTAINER_MODE
+
+HTML_RECURSIVE_TARGETS = install-html-recursive
+
+html-am: 
+	@if test -f doxygen/Doxyfile; then \
+	  echo "cd doxygen && $(DOXYGEN)"; \
+	  d=`pwd`; cd doxygen && $(DOXYGEN); cd $$d; \
+	  if test -n "$(POST_DOXYGEN_CLEANFILES)"; then \
+	    cd $(top_srcdir)/html && rm -f $(POST_DOXYGEN_CLEANFILES); \
+	  fi; \
+	else \
+	  echo "Nothing to be done for \`$@'."; \
+	fi
+
+clean-html: clean-html-am
+
+clean-html-am:
+	-rm -rf $(top_builddir)/html
+
+install-html-am: html-am install-html-generic
+
+else
+
+HTML_RECURSIVE_TARGETS = install-html-recursive
+
+install-html-am: install-html-generic
+
+endif
+
+install-html: install-html-recursive
+
+install-html-generic:
+	@$(NORMAL_INSTALL)
+	@if test -d $(top_srcdir)/html; then \
+	  echo "$(mkinstalldirs) $(DESTDIR)$(htmldir)"; \
+	  $(mkinstalldirs) $(DESTDIR)$(htmldir); \
+	  list="`ls -1 $(top_srcdir)/html`"; \
+	  for p in $$list; do \
+	    if test -f $(top_srcdir)/html/$$p; then \
+	      echo " $(INSTALL_DATA) $(top_srcdir)/html/$$p $(DESTDIR)$(htmldir)/$$p"; \
+	      $(INSTALL_DATA) $(top_srcdir)/html/$$p $(DESTDIR)$(htmldir)/$$p; \
+	    else if test -f $$p; then \
+	      echo " $(INSTALL_DATA) $$p $(DESTDIR)$(htmldir)/$$p"; \
+	      $(INSTALL_DATA) $$p $(DESTDIR)$(htmldir)/$$p; \
+	    fi; fi; \
+	  done; \
+	fi
+
+uninstall-html:
+	@$(NORMAL_UNINSTALL)
+	@list="`ls -1 $(DESTDIR)$(htmldir)`"; for p in $$list; do \
+	  echo " rm -f $(DESTDIR)$(htmldir)/$$p"; \
+	  rm -f $(DESTDIR)$(htmldir)/$$p; \
+	done
+
+$(HTML_RECURSIVE_TARGETS):
+	@set fnord $(MAKEFLAGS); amf=$$2; \
+	dot_seen=no; \
+	target=`echo $@ | sed s/-recursive//`; \
+	list='$(HTML_SUBDIRS)'; for subdir in $$list; do \
+	  echo "Making $$target in $$subdir"; \
+	  if test "$$subdir" = "."; then \
+	    dot_seen=yes; \
+	    local_target="$$target-am"; \
+	  else \
+	    local_target="$$target"; \
+	  fi; \
+	  (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
+	   || case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \
+	done; \
+	if test "$$dot_seen" = "no"; then \
+	  $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \
+	fi; test -z "$$fail"
diff --git a/admin/install-sh b/admin/install-sh
new file mode 100755
index 0000000..6781b98
--- /dev/null
+++ b/admin/install-sh
@@ -0,0 +1,520 @@
+#!/bin/sh
+# install - install a program, script, or datafile
+
+scriptversion=2009-04-28.21; # UTC
+
+# This originates from X11R5 (mit/util/scripts/install.sh), which was
+# later released in X11R6 (xc/config/util/install.sh) with the
+# following copyright and license.
+#
+# Copyright (C) 1994 X Consortium
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to
+# deal in the Software without restriction, including without limitation the
+# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+# sell copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
+# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+# Except as contained in this notice, the name of the X Consortium shall not
+# be used in advertising or otherwise to promote the sale, use or other deal-
+# ings in this Software without prior written authorization from the X Consor-
+# tium.
+#
+#
+# FSF changes to this file are in the public domain.
+#
+# Calling this script install-sh is preferred over install.sh, to prevent
+# `make' implicit rules from creating a file called install from it
+# when there is no Makefile.
+#
+# This script is compatible with the BSD install script, but was written
+# from scratch.
+
+nl='
+'
+IFS=" ""	$nl"
+
+# set DOITPROG to echo to test this script
+
+# Don't use :- since 4.3BSD and earlier shells don't like it.
+doit=${DOITPROG-}
+if test -z "$doit"; then
+  doit_exec=exec
+else
+  doit_exec=$doit
+fi
+
+# Put in absolute file names if you don't have them in your path;
+# or use environment vars.
+
+chgrpprog=${CHGRPPROG-chgrp}
+chmodprog=${CHMODPROG-chmod}
+chownprog=${CHOWNPROG-chown}
+cmpprog=${CMPPROG-cmp}
+cpprog=${CPPROG-cp}
+mkdirprog=${MKDIRPROG-mkdir}
+mvprog=${MVPROG-mv}
+rmprog=${RMPROG-rm}
+stripprog=${STRIPPROG-strip}
+
+posix_glob='?'
+initialize_posix_glob='
+  test "$posix_glob" != "?" || {
+    if (set -f) 2>/dev/null; then
+      posix_glob=
+    else
+      posix_glob=:
+    fi
+  }
+'
+
+posix_mkdir=
+
+# Desired mode of installed file.
+mode=0755
+
+chgrpcmd=
+chmodcmd=$chmodprog
+chowncmd=
+mvcmd=$mvprog
+rmcmd="$rmprog -f"
+stripcmd=
+
+src=
+dst=
+dir_arg=
+dst_arg=
+
+copy_on_change=false
+no_target_directory=
+
+usage="\
+Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE
+   or: $0 [OPTION]... SRCFILES... DIRECTORY
+   or: $0 [OPTION]... -t DIRECTORY SRCFILES...
+   or: $0 [OPTION]... -d DIRECTORIES...
+
+In the 1st form, copy SRCFILE to DSTFILE.
+In the 2nd and 3rd, copy all SRCFILES to DIRECTORY.
+In the 4th, create DIRECTORIES.
+
+Options:
+     --help     display this help and exit.
+     --version  display version info and exit.
+
+  -c            (ignored)
+  -C            install only if different (preserve the last data modification time)
+  -d            create directories instead of installing files.
+  -g GROUP      $chgrpprog installed files to GROUP.
+  -m MODE       $chmodprog installed files to MODE.
+  -o USER       $chownprog installed files to USER.
+  -s            $stripprog installed files.
+  -t DIRECTORY  install into DIRECTORY.
+  -T            report an error if DSTFILE is a directory.
+
+Environment variables override the default commands:
+  CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG
+  RMPROG STRIPPROG
+"
+
+while test $# -ne 0; do
+  case $1 in
+    -c) ;;
+
+    -C) copy_on_change=true;;
+
+    -d) dir_arg=true;;
+
+    -g) chgrpcmd="$chgrpprog $2"
+	shift;;
+
+    --help) echo "$usage"; exit $?;;
+
+    -m) mode=$2
+	case $mode in
+	  *' '* | *'	'* | *'
+'*	  | *'*'* | *'?'* | *'['*)
+	    echo "$0: invalid mode: $mode" >&2
+	    exit 1;;
+	esac
+	shift;;
+
+    -o) chowncmd="$chownprog $2"
+	shift;;
+
+    -s) stripcmd=$stripprog;;
+
+    -t) dst_arg=$2
+	shift;;
+
+    -T) no_target_directory=true;;
+
+    --version) echo "$0 $scriptversion"; exit $?;;
+
+    --)	shift
+	break;;
+
+    -*)	echo "$0: invalid option: $1" >&2
+	exit 1;;
+
+    *)  break;;
+  esac
+  shift
+done
+
+if test $# -ne 0 && test -z "$dir_arg$dst_arg"; then
+  # When -d is used, all remaining arguments are directories to create.
+  # When -t is used, the destination is already specified.
+  # Otherwise, the last argument is the destination.  Remove it from $@.
+  for arg
+  do
+    if test -n "$dst_arg"; then
+      # $@ is not empty: it contains at least $arg.
+      set fnord "$@" "$dst_arg"
+      shift # fnord
+    fi
+    shift # arg
+    dst_arg=$arg
+  done
+fi
+
+if test $# -eq 0; then
+  if test -z "$dir_arg"; then
+    echo "$0: no input file specified." >&2
+    exit 1
+  fi
+  # It's OK to call `install-sh -d' without argument.
+  # This can happen when creating conditional directories.
+  exit 0
+fi
+
+if test -z "$dir_arg"; then
+  trap '(exit $?); exit' 1 2 13 15
+
+  # Set umask so as not to create temps with too-generous modes.
+  # However, 'strip' requires both read and write access to temps.
+  case $mode in
+    # Optimize common cases.
+    *644) cp_umask=133;;
+    *755) cp_umask=22;;
+
+    *[0-7])
+      if test -z "$stripcmd"; then
+	u_plus_rw=
+      else
+	u_plus_rw='% 200'
+      fi
+      cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;;
+    *)
+      if test -z "$stripcmd"; then
+	u_plus_rw=
+      else
+	u_plus_rw=,u+rw
+      fi
+      cp_umask=$mode$u_plus_rw;;
+  esac
+fi
+
+for src
+do
+  # Protect names starting with `-'.
+  case $src in
+    -*) src=./$src;;
+  esac
+
+  if test -n "$dir_arg"; then
+    dst=$src
+    dstdir=$dst
+    test -d "$dstdir"
+    dstdir_status=$?
+  else
+
+    # Waiting for this to be detected by the "$cpprog $src $dsttmp" command
+    # might cause directories to be created, which would be especially bad
+    # if $src (and thus $dsttmp) contains '*'.
+    if test ! -f "$src" && test ! -d "$src"; then
+      echo "$0: $src does not exist." >&2
+      exit 1
+    fi
+
+    if test -z "$dst_arg"; then
+      echo "$0: no destination specified." >&2
+      exit 1
+    fi
+
+    dst=$dst_arg
+    # Protect names starting with `-'.
+    case $dst in
+      -*) dst=./$dst;;
+    esac
+
+    # If destination is a directory, append the input filename; won't work
+    # if double slashes aren't ignored.
+    if test -d "$dst"; then
+      if test -n "$no_target_directory"; then
+	echo "$0: $dst_arg: Is a directory" >&2
+	exit 1
+      fi
+      dstdir=$dst
+      dst=$dstdir/`basename "$src"`
+      dstdir_status=0
+    else
+      # Prefer dirname, but fall back on a substitute if dirname fails.
+      dstdir=`
+	(dirname "$dst") 2>/dev/null ||
+	expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	     X"$dst" : 'X\(//\)[^/]' \| \
+	     X"$dst" : 'X\(//\)$' \| \
+	     X"$dst" : 'X\(/\)' \| . 2>/dev/null ||
+	echo X"$dst" |
+	    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+		   s//\1/
+		   q
+		 }
+		 /^X\(\/\/\)[^/].*/{
+		   s//\1/
+		   q
+		 }
+		 /^X\(\/\/\)$/{
+		   s//\1/
+		   q
+		 }
+		 /^X\(\/\).*/{
+		   s//\1/
+		   q
+		 }
+		 s/.*/./; q'
+      `
+
+      test -d "$dstdir"
+      dstdir_status=$?
+    fi
+  fi
+
+  obsolete_mkdir_used=false
+
+  if test $dstdir_status != 0; then
+    case $posix_mkdir in
+      '')
+	# Create intermediate dirs using mode 755 as modified by the umask.
+	# This is like FreeBSD 'install' as of 1997-10-28.
+	umask=`umask`
+	case $stripcmd.$umask in
+	  # Optimize common cases.
+	  *[2367][2367]) mkdir_umask=$umask;;
+	  .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;;
+
+	  *[0-7])
+	    mkdir_umask=`expr $umask + 22 \
+	      - $umask % 100 % 40 + $umask % 20 \
+	      - $umask % 10 % 4 + $umask % 2
+	    `;;
+	  *) mkdir_umask=$umask,go-w;;
+	esac
+
+	# With -d, create the new directory with the user-specified mode.
+	# Otherwise, rely on $mkdir_umask.
+	if test -n "$dir_arg"; then
+	  mkdir_mode=-m$mode
+	else
+	  mkdir_mode=
+	fi
+
+	posix_mkdir=false
+	case $umask in
+	  *[123567][0-7][0-7])
+	    # POSIX mkdir -p sets u+wx bits regardless of umask, which
+	    # is incompatible with FreeBSD 'install' when (umask & 300) != 0.
+	    ;;
+	  *)
+	    tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$
+	    trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0
+
+	    if (umask $mkdir_umask &&
+		exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1
+	    then
+	      if test -z "$dir_arg" || {
+		   # Check for POSIX incompatibilities with -m.
+		   # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
+		   # other-writeable bit of parent directory when it shouldn't.
+		   # FreeBSD 6.1 mkdir -m -p sets mode of existing directory.
+		   ls_ld_tmpdir=`ls -ld "$tmpdir"`
+		   case $ls_ld_tmpdir in
+		     d????-?r-*) different_mode=700;;
+		     d????-?--*) different_mode=755;;
+		     *) false;;
+		   esac &&
+		   $mkdirprog -m$different_mode -p -- "$tmpdir" && {
+		     ls_ld_tmpdir_1=`ls -ld "$tmpdir"`
+		     test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1"
+		   }
+		 }
+	      then posix_mkdir=:
+	      fi
+	      rmdir "$tmpdir/d" "$tmpdir"
+	    else
+	      # Remove any dirs left behind by ancient mkdir implementations.
+	      rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null
+	    fi
+	    trap '' 0;;
+	esac;;
+    esac
+
+    if
+      $posix_mkdir && (
+	umask $mkdir_umask &&
+	$doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir"
+      )
+    then :
+    else
+
+      # The umask is ridiculous, or mkdir does not conform to POSIX,
+      # or it failed possibly due to a race condition.  Create the
+      # directory the slow way, step by step, checking for races as we go.
+
+      case $dstdir in
+	/*) prefix='/';;
+	-*) prefix='./';;
+	*)  prefix='';;
+      esac
+
+      eval "$initialize_posix_glob"
+
+      oIFS=$IFS
+      IFS=/
+      $posix_glob set -f
+      set fnord $dstdir
+      shift
+      $posix_glob set +f
+      IFS=$oIFS
+
+      prefixes=
+
+      for d
+      do
+	test -z "$d" && continue
+
+	prefix=$prefix$d
+	if test -d "$prefix"; then
+	  prefixes=
+	else
+	  if $posix_mkdir; then
+	    (umask=$mkdir_umask &&
+	     $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break
+	    # Don't fail if two instances are running concurrently.
+	    test -d "$prefix" || exit 1
+	  else
+	    case $prefix in
+	      *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;;
+	      *) qprefix=$prefix;;
+	    esac
+	    prefixes="$prefixes '$qprefix'"
+	  fi
+	fi
+	prefix=$prefix/
+      done
+
+      if test -n "$prefixes"; then
+	# Don't fail if two instances are running concurrently.
+	(umask $mkdir_umask &&
+	 eval "\$doit_exec \$mkdirprog $prefixes") ||
+	  test -d "$dstdir" || exit 1
+	obsolete_mkdir_used=true
+      fi
+    fi
+  fi
+
+  if test -n "$dir_arg"; then
+    { test -z "$chowncmd" || $doit $chowncmd "$dst"; } &&
+    { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } &&
+    { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false ||
+      test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1
+  else
+
+    # Make a couple of temp file names in the proper directory.
+    dsttmp=$dstdir/_inst.$$_
+    rmtmp=$dstdir/_rm.$$_
+
+    # Trap to clean up those temp files at exit.
+    trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
+
+    # Copy the file name to the temp name.
+    (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") &&
+
+    # and set any options; do chmod last to preserve setuid bits.
+    #
+    # If any of these fail, we abort the whole thing.  If we want to
+    # ignore errors from any of these, just make sure not to ignore
+    # errors from the above "$doit $cpprog $src $dsttmp" command.
+    #
+    { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } &&
+    { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } &&
+    { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } &&
+    { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } &&
+
+    # If -C, don't bother to copy if it wouldn't change the file.
+    if $copy_on_change &&
+       old=`LC_ALL=C ls -dlL "$dst"	2>/dev/null` &&
+       new=`LC_ALL=C ls -dlL "$dsttmp"	2>/dev/null` &&
+
+       eval "$initialize_posix_glob" &&
+       $posix_glob set -f &&
+       set X $old && old=:$2:$4:$5:$6 &&
+       set X $new && new=:$2:$4:$5:$6 &&
+       $posix_glob set +f &&
+
+       test "$old" = "$new" &&
+       $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1
+    then
+      rm -f "$dsttmp"
+    else
+      # Rename the file to the real destination.
+      $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null ||
+
+      # The rename failed, perhaps because mv can't rename something else
+      # to itself, or perhaps because mv is so ancient that it does not
+      # support -f.
+      {
+	# Now remove or move aside any old file at destination location.
+	# We try this two ways since rm can't unlink itself on some
+	# systems and the destination file might be busy for other
+	# reasons.  In this case, the final cleanup might fail but the new
+	# file should still install successfully.
+	{
+	  test ! -f "$dst" ||
+	  $doit $rmcmd -f "$dst" 2>/dev/null ||
+	  { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null &&
+	    { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; }
+	  } ||
+	  { echo "$0: cannot unlink or rename $dst" >&2
+	    (exit 1); exit 1
+	  }
+	} &&
+
+	# Now rename the file to the real destination.
+	$doit $mvcmd "$dsttmp" "$dst"
+      }
+    fi || exit 1
+
+    trap '' 0
+  fi
+done
+
+# Local variables:
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "scriptversion="
+# time-stamp-format: "%:y-%02m-%02d.%02H"
+# time-stamp-time-zone: "UTC"
+# time-stamp-end: "; # UTC"
+# End:
diff --git a/admin/ltmain.sh b/admin/ltmain.sh
new file mode 100755
index 0000000..a72f2fd
--- /dev/null
+++ b/admin/ltmain.sh
@@ -0,0 +1,8406 @@
+# Generated from ltmain.m4sh.
+
+# ltmain.sh (GNU libtool) 2.2.6b
+# Written by Gordon Matzigkeit <gord at gnu.ai.mit.edu>, 1996
+
+# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006, 2007 2008 Free Software Foundation, Inc.
+# This is free software; see the source for copying conditions.  There is NO
+# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+# GNU Libtool is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# As a special exception to the GNU General Public License,
+# if you distribute this file as part of a program or library that
+# is built using GNU Libtool, you may include this file under the
+# same distribution terms that you use for the rest of that program.
+#
+# GNU Libtool is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Libtool; see the file COPYING.  If not, a copy
+# can be downloaded from http://www.gnu.org/licenses/gpl.html,
+# or obtained by writing to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+# Usage: $progname [OPTION]... [MODE-ARG]...
+#
+# Provide generalized library-building support services.
+#
+#     --config             show all configuration variables
+#     --debug              enable verbose shell tracing
+# -n, --dry-run            display commands without modifying any files
+#     --features           display basic configuration information and exit
+#     --mode=MODE          use operation mode MODE
+#     --preserve-dup-deps  don't remove duplicate dependency libraries
+#     --quiet, --silent    don't print informational messages
+#     --tag=TAG            use configuration variables from tag TAG
+# -v, --verbose            print informational messages (default)
+#     --version            print version information
+# -h, --help               print short or long help message
+#
+# MODE must be one of the following:
+#
+#       clean              remove files from the build directory
+#       compile            compile a source file into a libtool object
+#       execute            automatically set library path, then run a program
+#       finish             complete the installation of libtool libraries
+#       install            install libraries or executables
+#       link               create a library or an executable
+#       uninstall          remove libraries from an installed directory
+#
+# MODE-ARGS vary depending on the MODE.
+# Try `$progname --help --mode=MODE' for a more detailed description of MODE.
+#
+# When reporting a bug, please describe a test case to reproduce it and
+# include the following information:
+#
+#       host-triplet:	$host
+#       shell:		$SHELL
+#       compiler:		$LTCC
+#       compiler flags:		$LTCFLAGS
+#       linker:		$LD (gnu? $with_gnu_ld)
+#       $progname:		(GNU libtool) 2.2.6b
+#       automake:		$automake_version
+#       autoconf:		$autoconf_version
+#
+# Report bugs to <bug-libtool at gnu.org>.
+
+PROGRAM=ltmain.sh
+PACKAGE=libtool
+VERSION=2.2.6b
+TIMESTAMP=""
+package_revision=1.3017
+
+# Be Bourne compatible
+if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
+  emulate sh
+  NULLCMD=:
+  # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which
+  # is contrary to our usage.  Disable this feature.
+  alias -g '${1+"$@"}'='"$@"'
+  setopt NO_GLOB_SUBST
+else
+  case `(set -o) 2>/dev/null` in *posix*) set -o posix;; esac
+fi
+BIN_SH=xpg4; export BIN_SH # for Tru64
+DUALCASE=1; export DUALCASE # for MKS sh
+
+# NLS nuisances: We save the old values to restore during execute mode.
+# Only set LANG and LC_ALL to C if already set.
+# These must not be set unconditionally because not all systems understand
+# e.g. LANG=C (notably SCO).
+lt_user_locale=
+lt_safe_locale=
+for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
+do
+  eval "if test \"\${$lt_var+set}\" = set; then
+          save_$lt_var=\$$lt_var
+          $lt_var=C
+	  export $lt_var
+	  lt_user_locale=\"$lt_var=\\\$save_\$lt_var; \$lt_user_locale\"
+	  lt_safe_locale=\"$lt_var=C; \$lt_safe_locale\"
+	fi"
+done
+
+$lt_unset CDPATH
+
+
+
+
+
+: ${CP="cp -f"}
+: ${ECHO="echo"}
+: ${EGREP="/bin/grep -E"}
+: ${FGREP="/bin/grep -F"}
+: ${GREP="/bin/grep"}
+: ${LN_S="ln -s"}
+: ${MAKE="make"}
+: ${MKDIR="mkdir"}
+: ${MV="mv -f"}
+: ${RM="rm -f"}
+: ${SED="/bin/sed"}
+: ${SHELL="${CONFIG_SHELL-/bin/sh}"}
+: ${Xsed="$SED -e 1s/^X//"}
+
+# Global variables:
+EXIT_SUCCESS=0
+EXIT_FAILURE=1
+EXIT_MISMATCH=63  # $? = 63 is used to indicate version mismatch to missing.
+EXIT_SKIP=77	  # $? = 77 is used to indicate a skipped test to automake.
+
+exit_status=$EXIT_SUCCESS
+
+# Make sure IFS has a sensible default
+lt_nl='
+'
+IFS=" 	$lt_nl"
+
+dirname="s,/[^/]*$,,"
+basename="s,^.*/,,"
+
+# func_dirname_and_basename file append nondir_replacement
+# perform func_basename and func_dirname in a single function
+# call:
+#   dirname:  Compute the dirname of FILE.  If nonempty,
+#             add APPEND to the result, otherwise set result
+#             to NONDIR_REPLACEMENT.
+#             value returned in "$func_dirname_result"
+#   basename: Compute filename of FILE.
+#             value retuned in "$func_basename_result"
+# Implementation must be kept synchronized with func_dirname
+# and func_basename. For efficiency, we do not delegate to
+# those functions but instead duplicate the functionality here.
+func_dirname_and_basename ()
+{
+  # Extract subdirectory from the argument.
+  func_dirname_result=`$ECHO "X${1}" | $Xsed -e "$dirname"`
+  if test "X$func_dirname_result" = "X${1}"; then
+    func_dirname_result="${3}"
+  else
+    func_dirname_result="$func_dirname_result${2}"
+  fi
+  func_basename_result=`$ECHO "X${1}" | $Xsed -e "$basename"`
+}
+
+# Generated shell functions inserted here.
+
+# Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh
+# is ksh but when the shell is invoked as "sh" and the current value of
+# the _XPG environment variable is not equal to 1 (one), the special
+# positional parameter $0, within a function call, is the name of the
+# function.
+progpath="$0"
+
+# The name of this program:
+# In the unlikely event $progname began with a '-', it would play havoc with
+# func_echo (imagine progname=-n), so we prepend ./ in that case:
+func_dirname_and_basename "$progpath"
+progname=$func_basename_result
+case $progname in
+  -*) progname=./$progname ;;
+esac
+
+# Make sure we have an absolute path for reexecution:
+case $progpath in
+  [\\/]*|[A-Za-z]:\\*) ;;
+  *[\\/]*)
+     progdir=$func_dirname_result
+     progdir=`cd "$progdir" && pwd`
+     progpath="$progdir/$progname"
+     ;;
+  *)
+     save_IFS="$IFS"
+     IFS=:
+     for progdir in $PATH; do
+       IFS="$save_IFS"
+       test -x "$progdir/$progname" && break
+     done
+     IFS="$save_IFS"
+     test -n "$progdir" || progdir=`pwd`
+     progpath="$progdir/$progname"
+     ;;
+esac
+
+# Sed substitution that helps us do robust quoting.  It backslashifies
+# metacharacters that are still active within double-quoted strings.
+Xsed="${SED}"' -e 1s/^X//'
+sed_quote_subst='s/\([`"$\\]\)/\\\1/g'
+
+# Same as above, but do not quote variable references.
+double_quote_subst='s/\(["`\\]\)/\\\1/g'
+
+# Re-`\' parameter expansions in output of double_quote_subst that were
+# `\'-ed in input to the same.  If an odd number of `\' preceded a '$'
+# in input to double_quote_subst, that '$' was protected from expansion.
+# Since each input `\' is now two `\'s, look for any number of runs of
+# four `\'s followed by two `\'s and then a '$'.  `\' that '$'.
+bs='\\'
+bs2='\\\\'
+bs4='\\\\\\\\'
+dollar='\$'
+sed_double_backslash="\
+  s/$bs4/&\\
+/g
+  s/^$bs2$dollar/$bs&/
+  s/\\([^$bs]\\)$bs2$dollar/\\1$bs2$bs$dollar/g
+  s/\n//g"
+
+# Standard options:
+opt_dry_run=false
+opt_help=false
+opt_quiet=false
+opt_verbose=false
+opt_warning=:
+
+# func_echo arg...
+# Echo program name prefixed message, along with the current mode
+# name if it has been set yet.
+func_echo ()
+{
+    $ECHO "$progname${mode+: }$mode: $*"
+}
+
+# func_verbose arg...
+# Echo program name prefixed message in verbose mode only.
+func_verbose ()
+{
+    $opt_verbose && func_echo ${1+"$@"}
+
+    # A bug in bash halts the script if the last line of a function
+    # fails when set -e is in force, so we need another command to
+    # work around that:
+    :
+}
+
+# func_error arg...
+# Echo program name prefixed message to standard error.
+func_error ()
+{
+    $ECHO "$progname${mode+: }$mode: "${1+"$@"} 1>&2
+}
+
+# func_warning arg...
+# Echo program name prefixed warning message to standard error.
+func_warning ()
+{
+    $opt_warning && $ECHO "$progname${mode+: }$mode: warning: "${1+"$@"} 1>&2
+
+    # bash bug again:
+    :
+}
+
+# func_fatal_error arg...
+# Echo program name prefixed message to standard error, and exit.
+func_fatal_error ()
+{
+    func_error ${1+"$@"}
+    exit $EXIT_FAILURE
+}
+
+# func_fatal_help arg...
+# Echo program name prefixed message to standard error, followed by
+# a help hint, and exit.
+func_fatal_help ()
+{
+    func_error ${1+"$@"}
+    func_fatal_error "$help"
+}
+help="Try \`$progname --help' for more information."  ## default
+
+
+# func_grep expression filename
+# Check whether EXPRESSION matches any line of FILENAME, without output.
+func_grep ()
+{
+    $GREP "$1" "$2" >/dev/null 2>&1
+}
+
+
+# func_mkdir_p directory-path
+# Make sure the entire path to DIRECTORY-PATH is available.
+func_mkdir_p ()
+{
+    my_directory_path="$1"
+    my_dir_list=
+
+    if test -n "$my_directory_path" && test "$opt_dry_run" != ":"; then
+
+      # Protect directory names starting with `-'
+      case $my_directory_path in
+        -*) my_directory_path="./$my_directory_path" ;;
+      esac
+
+      # While some portion of DIR does not yet exist...
+      while test ! -d "$my_directory_path"; do
+        # ...make a list in topmost first order.  Use a colon delimited
+	# list incase some portion of path contains whitespace.
+        my_dir_list="$my_directory_path:$my_dir_list"
+
+        # If the last portion added has no slash in it, the list is done
+        case $my_directory_path in */*) ;; *) break ;; esac
+
+        # ...otherwise throw away the child directory and loop
+        my_directory_path=`$ECHO "X$my_directory_path" | $Xsed -e "$dirname"`
+      done
+      my_dir_list=`$ECHO "X$my_dir_list" | $Xsed -e 's,:*$,,'`
+
+      save_mkdir_p_IFS="$IFS"; IFS=':'
+      for my_dir in $my_dir_list; do
+	IFS="$save_mkdir_p_IFS"
+        # mkdir can fail with a `File exist' error if two processes
+        # try to create one of the directories concurrently.  Don't
+        # stop in that case!
+        $MKDIR "$my_dir" 2>/dev/null || :
+      done
+      IFS="$save_mkdir_p_IFS"
+
+      # Bail out if we (or some other process) failed to create a directory.
+      test -d "$my_directory_path" || \
+        func_fatal_error "Failed to create \`$1'"
+    fi
+}
+
+
+# func_mktempdir [string]
+# Make a temporary directory that won't clash with other running
+# libtool processes, and avoids race conditions if possible.  If
+# given, STRING is the basename for that directory.
+func_mktempdir ()
+{
+    my_template="${TMPDIR-/tmp}/${1-$progname}"
+
+    if test "$opt_dry_run" = ":"; then
+      # Return a directory name, but don't create it in dry-run mode
+      my_tmpdir="${my_template}-$$"
+    else
+
+      # If mktemp works, use that first and foremost
+      my_tmpdir=`mktemp -d "${my_template}-XXXXXXXX" 2>/dev/null`
+
+      if test ! -d "$my_tmpdir"; then
+        # Failing that, at least try and use $RANDOM to avoid a race
+        my_tmpdir="${my_template}-${RANDOM-0}$$"
+
+        save_mktempdir_umask=`umask`
+        umask 0077
+        $MKDIR "$my_tmpdir"
+        umask $save_mktempdir_umask
+      fi
+
+      # If we're not in dry-run mode, bomb out on failure
+      test -d "$my_tmpdir" || \
+        func_fatal_error "cannot create temporary directory \`$my_tmpdir'"
+    fi
+
+    $ECHO "X$my_tmpdir" | $Xsed
+}
+
+
+# func_quote_for_eval arg
+# Aesthetically quote ARG to be evaled later.
+# This function returns two values: FUNC_QUOTE_FOR_EVAL_RESULT
+# is double-quoted, suitable for a subsequent eval, whereas
+# FUNC_QUOTE_FOR_EVAL_UNQUOTED_RESULT has merely all characters
+# which are still active within double quotes backslashified.
+func_quote_for_eval ()
+{
+    case $1 in
+      *[\\\`\"\$]*)
+	func_quote_for_eval_unquoted_result=`$ECHO "X$1" | $Xsed -e "$sed_quote_subst"` ;;
+      *)
+        func_quote_for_eval_unquoted_result="$1" ;;
+    esac
+
+    case $func_quote_for_eval_unquoted_result in
+      # Double-quote args containing shell metacharacters to delay
+      # word splitting, command substitution and and variable
+      # expansion for a subsequent eval.
+      # Many Bourne shells cannot handle close brackets correctly
+      # in scan sets, so we specify it separately.
+      *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
+        func_quote_for_eval_result="\"$func_quote_for_eval_unquoted_result\""
+        ;;
+      *)
+        func_quote_for_eval_result="$func_quote_for_eval_unquoted_result"
+    esac
+}
+
+
+# func_quote_for_expand arg
+# Aesthetically quote ARG to be evaled later; same as above,
+# but do not quote variable references.
+func_quote_for_expand ()
+{
+    case $1 in
+      *[\\\`\"]*)
+	my_arg=`$ECHO "X$1" | $Xsed \
+	    -e "$double_quote_subst" -e "$sed_double_backslash"` ;;
+      *)
+        my_arg="$1" ;;
+    esac
+
+    case $my_arg in
+      # Double-quote args containing shell metacharacters to delay
+      # word splitting and command substitution for a subsequent eval.
+      # Many Bourne shells cannot handle close brackets correctly
+      # in scan sets, so we specify it separately.
+      *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
+        my_arg="\"$my_arg\""
+        ;;
+    esac
+
+    func_quote_for_expand_result="$my_arg"
+}
+
+
+# func_show_eval cmd [fail_exp]
+# Unless opt_silent is true, then output CMD.  Then, if opt_dryrun is
+# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
+# is given, then evaluate it.
+func_show_eval ()
+{
+    my_cmd="$1"
+    my_fail_exp="${2-:}"
+
+    ${opt_silent-false} || {
+      func_quote_for_expand "$my_cmd"
+      eval "func_echo $func_quote_for_expand_result"
+    }
+
+    if ${opt_dry_run-false}; then :; else
+      eval "$my_cmd"
+      my_status=$?
+      if test "$my_status" -eq 0; then :; else
+	eval "(exit $my_status); $my_fail_exp"
+      fi
+    fi
+}
+
+
+# func_show_eval_locale cmd [fail_exp]
+# Unless opt_silent is true, then output CMD.  Then, if opt_dryrun is
+# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
+# is given, then evaluate it.  Use the saved locale for evaluation.
+func_show_eval_locale ()
+{
+    my_cmd="$1"
+    my_fail_exp="${2-:}"
+
+    ${opt_silent-false} || {
+      func_quote_for_expand "$my_cmd"
+      eval "func_echo $func_quote_for_expand_result"
+    }
+
+    if ${opt_dry_run-false}; then :; else
+      eval "$lt_user_locale
+	    $my_cmd"
+      my_status=$?
+      eval "$lt_safe_locale"
+      if test "$my_status" -eq 0; then :; else
+	eval "(exit $my_status); $my_fail_exp"
+      fi
+    fi
+}
+
+
+
+
+
+# func_version
+# Echo version message to standard output and exit.
+func_version ()
+{
+    $SED -n '/^# '$PROGRAM' (GNU /,/# warranty; / {
+        s/^# //
+	s/^# *$//
+        s/\((C)\)[ 0-9,-]*\( [1-9][0-9]*\)/\1\2/
+        p
+     }' < "$progpath"
+     exit $?
+}
+
+# func_usage
+# Echo short help message to standard output and exit.
+func_usage ()
+{
+    $SED -n '/^# Usage:/,/# -h/ {
+        s/^# //
+	s/^# *$//
+	s/\$progname/'$progname'/
+	p
+    }' < "$progpath"
+    $ECHO
+    $ECHO "run \`$progname --help | more' for full usage"
+    exit $?
+}
+
+# func_help
+# Echo long help message to standard output and exit.
+func_help ()
+{
+    $SED -n '/^# Usage:/,/# Report bugs to/ {
+        s/^# //
+	s/^# *$//
+	s*\$progname*'$progname'*
+	s*\$host*'"$host"'*
+	s*\$SHELL*'"$SHELL"'*
+	s*\$LTCC*'"$LTCC"'*
+	s*\$LTCFLAGS*'"$LTCFLAGS"'*
+	s*\$LD*'"$LD"'*
+	s/\$with_gnu_ld/'"$with_gnu_ld"'/
+	s/\$automake_version/'"`(automake --version) 2>/dev/null |$SED 1q`"'/
+	s/\$autoconf_version/'"`(autoconf --version) 2>/dev/null |$SED 1q`"'/
+	p
+     }' < "$progpath"
+    exit $?
+}
+
+# func_missing_arg argname
+# Echo program name prefixed message to standard error and set global
+# exit_cmd.
+func_missing_arg ()
+{
+    func_error "missing argument for $1"
+    exit_cmd=exit
+}
+
+exit_cmd=:
+
+
+
+
+
+# Check that we have a working $ECHO.
+if test "X$1" = X--no-reexec; then
+  # Discard the --no-reexec flag, and continue.
+  shift
+elif test "X$1" = X--fallback-echo; then
+  # Avoid inline document here, it may be left over
+  :
+elif test "X`{ $ECHO '\t'; } 2>/dev/null`" = 'X\t'; then
+  # Yippee, $ECHO works!
+  :
+else
+  # Restart under the correct shell, and then maybe $ECHO will work.
+  exec $SHELL "$progpath" --no-reexec ${1+"$@"}
+fi
+
+if test "X$1" = X--fallback-echo; then
+  # used as fallback echo
+  shift
+  cat <<EOF
+$*
+EOF
+  exit $EXIT_SUCCESS
+fi
+
+magic="%%%MAGIC variable%%%"
+magic_exe="%%%MAGIC EXE variable%%%"
+
+# Global variables.
+# $mode is unset
+nonopt=
+execute_dlfiles=
+preserve_args=
+lo2o="s/\\.lo\$/.${objext}/"
+o2lo="s/\\.${objext}\$/.lo/"
+extracted_archives=
+extracted_serial=0
+
+opt_dry_run=false
+opt_duplicate_deps=false
+opt_silent=false
+opt_debug=:
+
+# If this variable is set in any of the actions, the command in it
+# will be execed at the end.  This prevents here-documents from being
+# left over by shells.
+exec_cmd=
+
+# func_fatal_configuration arg...
+# Echo program name prefixed message to standard error, followed by
+# a configuration failure hint, and exit.
+func_fatal_configuration ()
+{
+    func_error ${1+"$@"}
+    func_error "See the $PACKAGE documentation for more information."
+    func_fatal_error "Fatal configuration error."
+}
+
+
+# func_config
+# Display the configuration for all the tags in this script.
+func_config ()
+{
+    re_begincf='^# ### BEGIN LIBTOOL'
+    re_endcf='^# ### END LIBTOOL'
+
+    # Default configuration.
+    $SED "1,/$re_begincf CONFIG/d;/$re_endcf CONFIG/,\$d" < "$progpath"
+
+    # Now print the configurations for the tags.
+    for tagname in $taglist; do
+      $SED -n "/$re_begincf TAG CONFIG: $tagname\$/,/$re_endcf TAG CONFIG: $tagname\$/p" < "$progpath"
+    done
+
+    exit $?
+}
+
+# func_features
+# Display the features supported by this script.
+func_features ()
+{
+    $ECHO "host: $host"
+    if test "$build_libtool_libs" = yes; then
+      $ECHO "enable shared libraries"
+    else
+      $ECHO "disable shared libraries"
+    fi
+    if test "$build_old_libs" = yes; then
+      $ECHO "enable static libraries"
+    else
+      $ECHO "disable static libraries"
+    fi
+
+    exit $?
+}
+
+# func_enable_tag tagname
+# Verify that TAGNAME is valid, and either flag an error and exit, or
+# enable the TAGNAME tag.  We also add TAGNAME to the global $taglist
+# variable here.
+func_enable_tag ()
+{
+  # Global variable:
+  tagname="$1"
+
+  re_begincf="^# ### BEGIN LIBTOOL TAG CONFIG: $tagname\$"
+  re_endcf="^# ### END LIBTOOL TAG CONFIG: $tagname\$"
+  sed_extractcf="/$re_begincf/,/$re_endcf/p"
+
+  # Validate tagname.
+  case $tagname in
+    *[!-_A-Za-z0-9,/]*)
+      func_fatal_error "invalid tag name: $tagname"
+      ;;
+  esac
+
+  # Don't test for the "default" C tag, as we know it's
+  # there but not specially marked.
+  case $tagname in
+    CC) ;;
+    *)
+      if $GREP "$re_begincf" "$progpath" >/dev/null 2>&1; then
+	taglist="$taglist $tagname"
+
+	# Evaluate the configuration.  Be careful to quote the path
+	# and the sed script, to avoid splitting on whitespace, but
+	# also don't use non-portable quotes within backquotes within
+	# quotes we have to do it in 2 steps:
+	extractedcf=`$SED -n -e "$sed_extractcf" < "$progpath"`
+	eval "$extractedcf"
+      else
+	func_error "ignoring unknown tag $tagname"
+      fi
+      ;;
+  esac
+}
+
+# Parse options once, thoroughly.  This comes as soon as possible in
+# the script to make things like `libtool --version' happen quickly.
+{
+
+  # Shorthand for --mode=foo, only valid as the first argument
+  case $1 in
+  clean|clea|cle|cl)
+    shift; set dummy --mode clean ${1+"$@"}; shift
+    ;;
+  compile|compil|compi|comp|com|co|c)
+    shift; set dummy --mode compile ${1+"$@"}; shift
+    ;;
+  execute|execut|execu|exec|exe|ex|e)
+    shift; set dummy --mode execute ${1+"$@"}; shift
+    ;;
+  finish|finis|fini|fin|fi|f)
+    shift; set dummy --mode finish ${1+"$@"}; shift
+    ;;
+  install|instal|insta|inst|ins|in|i)
+    shift; set dummy --mode install ${1+"$@"}; shift
+    ;;
+  link|lin|li|l)
+    shift; set dummy --mode link ${1+"$@"}; shift
+    ;;
+  uninstall|uninstal|uninsta|uninst|unins|unin|uni|un|u)
+    shift; set dummy --mode uninstall ${1+"$@"}; shift
+    ;;
+  esac
+
+  # Parse non-mode specific arguments:
+  while test "$#" -gt 0; do
+    opt="$1"
+    shift
+
+    case $opt in
+      --config)		func_config					;;
+
+      --debug)		preserve_args="$preserve_args $opt"
+			func_echo "enabling shell trace mode"
+			opt_debug='set -x'
+			$opt_debug
+			;;
+
+      -dlopen)		test "$#" -eq 0 && func_missing_arg "$opt" && break
+			execute_dlfiles="$execute_dlfiles $1"
+			shift
+			;;
+
+      --dry-run | -n)	opt_dry_run=:					;;
+      --features)       func_features					;;
+      --finish)		mode="finish"					;;
+
+      --mode)		test "$#" -eq 0 && func_missing_arg "$opt" && break
+			case $1 in
+			  # Valid mode arguments:
+			  clean)	;;
+			  compile)	;;
+			  execute)	;;
+			  finish)	;;
+			  install)	;;
+			  link)		;;
+			  relink)	;;
+			  uninstall)	;;
+
+			  # Catch anything else as an error
+			  *) func_error "invalid argument for $opt"
+			     exit_cmd=exit
+			     break
+			     ;;
+		        esac
+
+			mode="$1"
+			shift
+			;;
+
+      --preserve-dup-deps)
+			opt_duplicate_deps=:				;;
+
+      --quiet|--silent)	preserve_args="$preserve_args $opt"
+			opt_silent=:
+			;;
+
+      --verbose| -v)	preserve_args="$preserve_args $opt"
+			opt_silent=false
+			;;
+
+      --tag)		test "$#" -eq 0 && func_missing_arg "$opt" && break
+			preserve_args="$preserve_args $opt $1"
+			func_enable_tag "$1"	# tagname is set here
+			shift
+			;;
+
+      # Separate optargs to long options:
+      -dlopen=*|--mode=*|--tag=*)
+			func_opt_split "$opt"
+			set dummy "$func_opt_split_opt" "$func_opt_split_arg" ${1+"$@"}
+			shift
+			;;
+
+      -\?|-h)		func_usage					;;
+      --help)		opt_help=:					;;
+      --version)	func_version					;;
+
+      -*)		func_fatal_help "unrecognized option \`$opt'"	;;
+
+      *)		nonopt="$opt"
+			break
+			;;
+    esac
+  done
+
+
+  case $host in
+    *cygwin* | *mingw* | *pw32* | *cegcc*)
+      # don't eliminate duplications in $postdeps and $predeps
+      opt_duplicate_compiler_generated_deps=:
+      ;;
+    *)
+      opt_duplicate_compiler_generated_deps=$opt_duplicate_deps
+      ;;
+  esac
+
+  # Having warned about all mis-specified options, bail out if
+  # anything was wrong.
+  $exit_cmd $EXIT_FAILURE
+}
+
+# func_check_version_match
+# Ensure that we are using m4 macros, and libtool script from the same
+# release of libtool.
+func_check_version_match ()
+{
+  if test "$package_revision" != "$macro_revision"; then
+    if test "$VERSION" != "$macro_version"; then
+      if test -z "$macro_version"; then
+        cat >&2 <<_LT_EOF
+$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
+$progname: definition of this LT_INIT comes from an older release.
+$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
+$progname: and run autoconf again.
+_LT_EOF
+      else
+        cat >&2 <<_LT_EOF
+$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
+$progname: definition of this LT_INIT comes from $PACKAGE $macro_version.
+$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
+$progname: and run autoconf again.
+_LT_EOF
+      fi
+    else
+      cat >&2 <<_LT_EOF
+$progname: Version mismatch error.  This is $PACKAGE $VERSION, revision $package_revision,
+$progname: but the definition of this LT_INIT comes from revision $macro_revision.
+$progname: You should recreate aclocal.m4 with macros from revision $package_revision
+$progname: of $PACKAGE $VERSION and run autoconf again.
+_LT_EOF
+    fi
+
+    exit $EXIT_MISMATCH
+  fi
+}
+
+
+## ----------- ##
+##    Main.    ##
+## ----------- ##
+
+$opt_help || {
+  # Sanity checks first:
+  func_check_version_match
+
+  if test "$build_libtool_libs" != yes && test "$build_old_libs" != yes; then
+    func_fatal_configuration "not configured to build any kind of library"
+  fi
+
+  test -z "$mode" && func_fatal_error "error: you must specify a MODE."
+
+
+  # Darwin sucks
+  eval std_shrext=\"$shrext_cmds\"
+
+
+  # Only execute mode is allowed to have -dlopen flags.
+  if test -n "$execute_dlfiles" && test "$mode" != execute; then
+    func_error "unrecognized option \`-dlopen'"
+    $ECHO "$help" 1>&2
+    exit $EXIT_FAILURE
+  fi
+
+  # Change the help message to a mode-specific one.
+  generic_help="$help"
+  help="Try \`$progname --help --mode=$mode' for more information."
+}
+
+
+# func_lalib_p file
+# True iff FILE is a libtool `.la' library or `.lo' object file.
+# This function is only a basic sanity check; it will hardly flush out
+# determined imposters.
+func_lalib_p ()
+{
+    test -f "$1" &&
+      $SED -e 4q "$1" 2>/dev/null \
+        | $GREP "^# Generated by .*$PACKAGE" > /dev/null 2>&1
+}
+
+# func_lalib_unsafe_p file
+# True iff FILE is a libtool `.la' library or `.lo' object file.
+# This function implements the same check as func_lalib_p without
+# resorting to external programs.  To this end, it redirects stdin and
+# closes it afterwards, without saving the original file descriptor.
+# As a safety measure, use it only where a negative result would be
+# fatal anyway.  Works if `file' does not exist.
+func_lalib_unsafe_p ()
+{
+    lalib_p=no
+    if test -f "$1" && test -r "$1" && exec 5<&0 <"$1"; then
+	for lalib_p_l in 1 2 3 4
+	do
+	    read lalib_p_line
+	    case "$lalib_p_line" in
+		\#\ Generated\ by\ *$PACKAGE* ) lalib_p=yes; break;;
+	    esac
+	done
+	exec 0<&5 5<&-
+    fi
+    test "$lalib_p" = yes
+}
+
+# func_ltwrapper_script_p file
+# True iff FILE is a libtool wrapper script
+# This function is only a basic sanity check; it will hardly flush out
+# determined imposters.
+func_ltwrapper_script_p ()
+{
+    func_lalib_p "$1"
+}
+
+# func_ltwrapper_executable_p file
+# True iff FILE is a libtool wrapper executable
+# This function is only a basic sanity check; it will hardly flush out
+# determined imposters.
+func_ltwrapper_executable_p ()
+{
+    func_ltwrapper_exec_suffix=
+    case $1 in
+    *.exe) ;;
+    *) func_ltwrapper_exec_suffix=.exe ;;
+    esac
+    $GREP "$magic_exe" "$1$func_ltwrapper_exec_suffix" >/dev/null 2>&1
+}
+
+# func_ltwrapper_scriptname file
+# Assumes file is an ltwrapper_executable
+# uses $file to determine the appropriate filename for a
+# temporary ltwrapper_script.
+func_ltwrapper_scriptname ()
+{
+    func_ltwrapper_scriptname_result=""
+    if func_ltwrapper_executable_p "$1"; then
+	func_dirname_and_basename "$1" "" "."
+	func_stripname '' '.exe' "$func_basename_result"
+	func_ltwrapper_scriptname_result="$func_dirname_result/$objdir/${func_stripname_result}_ltshwrapper"
+    fi
+}
+
+# func_ltwrapper_p file
+# True iff FILE is a libtool wrapper script or wrapper executable
+# This function is only a basic sanity check; it will hardly flush out
+# determined imposters.
+func_ltwrapper_p ()
+{
+    func_ltwrapper_script_p "$1" || func_ltwrapper_executable_p "$1"
+}
+
+
+# func_execute_cmds commands fail_cmd
+# Execute tilde-delimited COMMANDS.
+# If FAIL_CMD is given, eval that upon failure.
+# FAIL_CMD may read-access the current command in variable CMD!
+func_execute_cmds ()
+{
+    $opt_debug
+    save_ifs=$IFS; IFS='~'
+    for cmd in $1; do
+      IFS=$save_ifs
+      eval cmd=\"$cmd\"
+      func_show_eval "$cmd" "${2-:}"
+    done
+    IFS=$save_ifs
+}
+
+
+# func_source file
+# Source FILE, adding directory component if necessary.
+# Note that it is not necessary on cygwin/mingw to append a dot to
+# FILE even if both FILE and FILE.exe exist: automatic-append-.exe
+# behavior happens only for exec(3), not for open(2)!  Also, sourcing
+# `FILE.' does not work on cygwin managed mounts.
+func_source ()
+{
+    $opt_debug
+    case $1 in
+    */* | *\\*)	. "$1" ;;
+    *)		. "./$1" ;;
+    esac
+}
+
+
+# func_infer_tag arg
+# Infer tagged configuration to use if any are available and
+# if one wasn't chosen via the "--tag" command line option.
+# Only attempt this if the compiler in the base compile
+# command doesn't match the default compiler.
+# arg is usually of the form 'gcc ...'
+func_infer_tag ()
+{
+    $opt_debug
+    if test -n "$available_tags" && test -z "$tagname"; then
+      CC_quoted=
+      for arg in $CC; do
+        func_quote_for_eval "$arg"
+	CC_quoted="$CC_quoted $func_quote_for_eval_result"
+      done
+      case $@ in
+      # Blanks in the command may have been stripped by the calling shell,
+      # but not from the CC environment variable when configure was run.
+      " $CC "* | "$CC "* | " `$ECHO $CC` "* | "`$ECHO $CC` "* | " $CC_quoted"* | "$CC_quoted "* | " `$ECHO $CC_quoted` "* | "`$ECHO $CC_quoted` "*) ;;
+      # Blanks at the start of $base_compile will cause this to fail
+      # if we don't check for them as well.
+      *)
+	for z in $available_tags; do
+	  if $GREP "^# ### BEGIN LIBTOOL TAG CONFIG: $z$" < "$progpath" > /dev/null; then
+	    # Evaluate the configuration.
+	    eval "`${SED} -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$z'$/,/^# ### END LIBTOOL TAG CONFIG: '$z'$/p' < $progpath`"
+	    CC_quoted=
+	    for arg in $CC; do
+	      # Double-quote args containing other shell metacharacters.
+	      func_quote_for_eval "$arg"
+	      CC_quoted="$CC_quoted $func_quote_for_eval_result"
+	    done
+	    case "$@ " in
+	      " $CC "* | "$CC "* | " `$ECHO $CC` "* | "`$ECHO $CC` "* | " $CC_quoted"* | "$CC_quoted "* | " `$ECHO $CC_quoted` "* | "`$ECHO $CC_quoted` "*)
+	      # The compiler in the base compile command matches
+	      # the one in the tagged configuration.
+	      # Assume this is the tagged configuration we want.
+	      tagname=$z
+	      break
+	      ;;
+	    esac
+	  fi
+	done
+	# If $tagname still isn't set, then no tagged configuration
+	# was found and let the user know that the "--tag" command
+	# line option must be used.
+	if test -z "$tagname"; then
+	  func_echo "unable to infer tagged configuration"
+	  func_fatal_error "specify a tag with \`--tag'"
+#	else
+#	  func_verbose "using $tagname tagged configuration"
+	fi
+	;;
+      esac
+    fi
+}
+
+
+
+# func_write_libtool_object output_name pic_name nonpic_name
+# Create a libtool object file (analogous to a ".la" file),
+# but don't create it if we're doing a dry run.
+func_write_libtool_object ()
+{
+    write_libobj=${1}
+    if test "$build_libtool_libs" = yes; then
+      write_lobj=\'${2}\'
+    else
+      write_lobj=none
+    fi
+
+    if test "$build_old_libs" = yes; then
+      write_oldobj=\'${3}\'
+    else
+      write_oldobj=none
+    fi
+
+    $opt_dry_run || {
+      cat >${write_libobj}T <<EOF
+# $write_libobj - a libtool object file
+# Generated by $PROGRAM (GNU $PACKAGE$TIMESTAMP) $VERSION
+#
+# Please DO NOT delete this file!
+# It is necessary for linking the library.
+
+# Name of the PIC object.
+pic_object=$write_lobj
+
+# Name of the non-PIC object
+non_pic_object=$write_oldobj
+
+EOF
+      $MV "${write_libobj}T" "${write_libobj}"
+    }
+}
+
+# func_mode_compile arg...
+func_mode_compile ()
+{
+    $opt_debug
+    # Get the compilation command and the source file.
+    base_compile=
+    srcfile="$nonopt"  #  always keep a non-empty value in "srcfile"
+    suppress_opt=yes
+    suppress_output=
+    arg_mode=normal
+    libobj=
+    later=
+    pie_flag=
+
+    for arg
+    do
+      case $arg_mode in
+      arg  )
+	# do not "continue".  Instead, add this to base_compile
+	lastarg="$arg"
+	arg_mode=normal
+	;;
+
+      target )
+	libobj="$arg"
+	arg_mode=normal
+	continue
+	;;
+
+      normal )
+	# Accept any command-line options.
+	case $arg in
+	-o)
+	  test -n "$libobj" && \
+	    func_fatal_error "you cannot specify \`-o' more than once"
+	  arg_mode=target
+	  continue
+	  ;;
+
+	-pie | -fpie | -fPIE)
+          pie_flag="$pie_flag $arg"
+	  continue
+	  ;;
+
+	-shared | -static | -prefer-pic | -prefer-non-pic)
+	  later="$later $arg"
+	  continue
+	  ;;
+
+	-no-suppress)
+	  suppress_opt=no
+	  continue
+	  ;;
+
+	-Xcompiler)
+	  arg_mode=arg  #  the next one goes into the "base_compile" arg list
+	  continue      #  The current "srcfile" will either be retained or
+	  ;;            #  replaced later.  I would guess that would be a bug.
+
+	-Wc,*)
+	  func_stripname '-Wc,' '' "$arg"
+	  args=$func_stripname_result
+	  lastarg=
+	  save_ifs="$IFS"; IFS=','
+	  for arg in $args; do
+	    IFS="$save_ifs"
+	    func_quote_for_eval "$arg"
+	    lastarg="$lastarg $func_quote_for_eval_result"
+	  done
+	  IFS="$save_ifs"
+	  func_stripname ' ' '' "$lastarg"
+	  lastarg=$func_stripname_result
+
+	  # Add the arguments to base_compile.
+	  base_compile="$base_compile $lastarg"
+	  continue
+	  ;;
+
+	*)
+	  # Accept the current argument as the source file.
+	  # The previous "srcfile" becomes the current argument.
+	  #
+	  lastarg="$srcfile"
+	  srcfile="$arg"
+	  ;;
+	esac  #  case $arg
+	;;
+      esac    #  case $arg_mode
+
+      # Aesthetically quote the previous argument.
+      func_quote_for_eval "$lastarg"
+      base_compile="$base_compile $func_quote_for_eval_result"
+    done # for arg
+
+    case $arg_mode in
+    arg)
+      func_fatal_error "you must specify an argument for -Xcompile"
+      ;;
+    target)
+      func_fatal_error "you must specify a target with \`-o'"
+      ;;
+    *)
+      # Get the name of the library object.
+      test -z "$libobj" && {
+	func_basename "$srcfile"
+	libobj="$func_basename_result"
+      }
+      ;;
+    esac
+
+    # Recognize several different file suffixes.
+    # If the user specifies -o file.o, it is replaced with file.lo
+    case $libobj in
+    *.[cCFSifmso] | \
+    *.ada | *.adb | *.ads | *.asm | \
+    *.c++ | *.cc | *.ii | *.class | *.cpp | *.cxx | \
+    *.[fF][09]? | *.for | *.java | *.obj | *.sx)
+      func_xform "$libobj"
+      libobj=$func_xform_result
+      ;;
+    esac
+
+    case $libobj in
+    *.lo) func_lo2o "$libobj"; obj=$func_lo2o_result ;;
+    *)
+      func_fatal_error "cannot determine name of library object from \`$libobj'"
+      ;;
+    esac
+
+    func_infer_tag $base_compile
+
+    for arg in $later; do
+      case $arg in
+      -shared)
+	test "$build_libtool_libs" != yes && \
+	  func_fatal_configuration "can not build a shared library"
+	build_old_libs=no
+	continue
+	;;
+
+      -static)
+	build_libtool_libs=no
+	build_old_libs=yes
+	continue
+	;;
+
+      -prefer-pic)
+	pic_mode=yes
+	continue
+	;;
+
+      -prefer-non-pic)
+	pic_mode=no
+	continue
+	;;
+      esac
+    done
+
+    func_quote_for_eval "$libobj"
+    test "X$libobj" != "X$func_quote_for_eval_result" \
+      && $ECHO "X$libobj" | $GREP '[]~#^*{};<>?"'"'"'	 &()|`$[]' \
+      && func_warning "libobj name \`$libobj' may not contain shell special characters."
+    func_dirname_and_basename "$obj" "/" ""
+    objname="$func_basename_result"
+    xdir="$func_dirname_result"
+    lobj=${xdir}$objdir/$objname
+
+    test -z "$base_compile" && \
+      func_fatal_help "you must specify a compilation command"
+
+    # Delete any leftover library objects.
+    if test "$build_old_libs" = yes; then
+      removelist="$obj $lobj $libobj ${libobj}T"
+    else
+      removelist="$lobj $libobj ${libobj}T"
+    fi
+
+    # On Cygwin there's no "real" PIC flag so we must build both object types
+    case $host_os in
+    cygwin* | mingw* | pw32* | os2* | cegcc*)
+      pic_mode=default
+      ;;
+    esac
+    if test "$pic_mode" = no && test "$deplibs_check_method" != pass_all; then
+      # non-PIC code in shared libraries is not supported
+      pic_mode=default
+    fi
+
+    # Calculate the filename of the output object if compiler does
+    # not support -o with -c
+    if test "$compiler_c_o" = no; then
+      output_obj=`$ECHO "X$srcfile" | $Xsed -e 's%^.*/%%' -e 's%\.[^.]*$%%'`.${objext}
+      lockfile="$output_obj.lock"
+    else
+      output_obj=
+      need_locks=no
+      lockfile=
+    fi
+
+    # Lock this critical section if it is needed
+    # We use this script file to make the link, it avoids creating a new file
+    if test "$need_locks" = yes; then
+      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
+	func_echo "Waiting for $lockfile to be removed"
+	sleep 2
+      done
+    elif test "$need_locks" = warn; then
+      if test -f "$lockfile"; then
+	$ECHO "\
+*** ERROR, $lockfile exists and contains:
+`cat $lockfile 2>/dev/null`
+
+This indicates that another process is trying to use the same
+temporary object file, and libtool could not work around it because
+your compiler does not support \`-c' and \`-o' together.  If you
+repeat this compilation, it may succeed, by chance, but you had better
+avoid parallel builds (make -j) in this platform, or get a better
+compiler."
+
+	$opt_dry_run || $RM $removelist
+	exit $EXIT_FAILURE
+      fi
+      removelist="$removelist $output_obj"
+      $ECHO "$srcfile" > "$lockfile"
+    fi
+
+    $opt_dry_run || $RM $removelist
+    removelist="$removelist $lockfile"
+    trap '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE' 1 2 15
+
+    if test -n "$fix_srcfile_path"; then
+      eval srcfile=\"$fix_srcfile_path\"
+    fi
+    func_quote_for_eval "$srcfile"
+    qsrcfile=$func_quote_for_eval_result
+
+    # Only build a PIC object if we are building libtool libraries.
+    if test "$build_libtool_libs" = yes; then
+      # Without this assignment, base_compile gets emptied.
+      fbsd_hideous_sh_bug=$base_compile
+
+      if test "$pic_mode" != no; then
+	command="$base_compile $qsrcfile $pic_flag"
+      else
+	# Don't build PIC code
+	command="$base_compile $qsrcfile"
+      fi
+
+      func_mkdir_p "$xdir$objdir"
+
+      if test -z "$output_obj"; then
+	# Place PIC objects in $objdir
+	command="$command -o $lobj"
+      fi
+
+      func_show_eval_locale "$command"	\
+          'test -n "$output_obj" && $RM $removelist; exit $EXIT_FAILURE'
+
+      if test "$need_locks" = warn &&
+	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
+	$ECHO "\
+*** ERROR, $lockfile contains:
+`cat $lockfile 2>/dev/null`
+
+but it should contain:
+$srcfile
+
+This indicates that another process is trying to use the same
+temporary object file, and libtool could not work around it because
+your compiler does not support \`-c' and \`-o' together.  If you
+repeat this compilation, it may succeed, by chance, but you had better
+avoid parallel builds (make -j) in this platform, or get a better
+compiler."
+
+	$opt_dry_run || $RM $removelist
+	exit $EXIT_FAILURE
+      fi
+
+      # Just move the object if needed, then go on to compile the next one
+      if test -n "$output_obj" && test "X$output_obj" != "X$lobj"; then
+	func_show_eval '$MV "$output_obj" "$lobj"' \
+	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
+      fi
+
+      # Allow error messages only from the first compilation.
+      if test "$suppress_opt" = yes; then
+	suppress_output=' >/dev/null 2>&1'
+      fi
+    fi
+
+    # Only build a position-dependent object if we build old libraries.
+    if test "$build_old_libs" = yes; then
+      if test "$pic_mode" != yes; then
+	# Don't build PIC code
+	command="$base_compile $qsrcfile$pie_flag"
+      else
+	command="$base_compile $qsrcfile $pic_flag"
+      fi
+      if test "$compiler_c_o" = yes; then
+	command="$command -o $obj"
+      fi
+
+      # Suppress compiler output if we already did a PIC compilation.
+      command="$command$suppress_output"
+      func_show_eval_locale "$command" \
+        '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE'
+
+      if test "$need_locks" = warn &&
+	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
+	$ECHO "\
+*** ERROR, $lockfile contains:
+`cat $lockfile 2>/dev/null`
+
+but it should contain:
+$srcfile
+
+This indicates that another process is trying to use the same
+temporary object file, and libtool could not work around it because
+your compiler does not support \`-c' and \`-o' together.  If you
+repeat this compilation, it may succeed, by chance, but you had better
+avoid parallel builds (make -j) in this platform, or get a better
+compiler."
+
+	$opt_dry_run || $RM $removelist
+	exit $EXIT_FAILURE
+      fi
+
+      # Just move the object if needed
+      if test -n "$output_obj" && test "X$output_obj" != "X$obj"; then
+	func_show_eval '$MV "$output_obj" "$obj"' \
+	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
+      fi
+    fi
+
+    $opt_dry_run || {
+      func_write_libtool_object "$libobj" "$objdir/$objname" "$objname"
+
+      # Unlock the critical section if it was locked
+      if test "$need_locks" != no; then
+	removelist=$lockfile
+        $RM "$lockfile"
+      fi
+    }
+
+    exit $EXIT_SUCCESS
+}
+
+$opt_help || {
+test "$mode" = compile && func_mode_compile ${1+"$@"}
+}
+
+func_mode_help ()
+{
+    # We need to display help for each of the modes.
+    case $mode in
+      "")
+        # Generic help is extracted from the usage comments
+        # at the start of this file.
+        func_help
+        ;;
+
+      clean)
+        $ECHO \
+"Usage: $progname [OPTION]... --mode=clean RM [RM-OPTION]... FILE...
+
+Remove files from the build directory.
+
+RM is the name of the program to use to delete files associated with each FILE
+(typically \`/bin/rm').  RM-OPTIONS are options (such as \`-f') to be passed
+to RM.
+
+If FILE is a libtool library, object or program, all the files associated
+with it are deleted. Otherwise, only FILE itself is deleted using RM."
+        ;;
+
+      compile)
+      $ECHO \
+"Usage: $progname [OPTION]... --mode=compile COMPILE-COMMAND... SOURCEFILE
+
+Compile a source file into a libtool library object.
+
+This mode accepts the following additional options:
+
+  -o OUTPUT-FILE    set the output file name to OUTPUT-FILE
+  -no-suppress      do not suppress compiler output for multiple passes
+  -prefer-pic       try to building PIC objects only
+  -prefer-non-pic   try to building non-PIC objects only
+  -shared           do not build a \`.o' file suitable for static linking
+  -static           only build a \`.o' file suitable for static linking
+
+COMPILE-COMMAND is a command to be used in creating a \`standard' object file
+from the given SOURCEFILE.
+
+The output file name is determined by removing the directory component from
+SOURCEFILE, then substituting the C source code suffix \`.c' with the
+library object suffix, \`.lo'."
+        ;;
+
+      execute)
+        $ECHO \
+"Usage: $progname [OPTION]... --mode=execute COMMAND [ARGS]...
+
+Automatically set library path, then run a program.
+
+This mode accepts the following additional options:
+
+  -dlopen FILE      add the directory containing FILE to the library path
+
+This mode sets the library path environment variable according to \`-dlopen'
+flags.
+
+If any of the ARGS are libtool executable wrappers, then they are translated
+into their corresponding uninstalled binary, and any of their required library
+directories are added to the library path.
+
+Then, COMMAND is executed, with ARGS as arguments."
+        ;;
+
+      finish)
+        $ECHO \
+"Usage: $progname [OPTION]... --mode=finish [LIBDIR]...
+
+Complete the installation of libtool libraries.
+
+Each LIBDIR is a directory that contains libtool libraries.
+
+The commands that this mode executes may require superuser privileges.  Use
+the \`--dry-run' option if you just want to see what would be executed."
+        ;;
+
+      install)
+        $ECHO \
+"Usage: $progname [OPTION]... --mode=install INSTALL-COMMAND...
+
+Install executables or libraries.
+
+INSTALL-COMMAND is the installation command.  The first component should be
+either the \`install' or \`cp' program.
+
+The following components of INSTALL-COMMAND are treated specially:
+
+  -inst-prefix PREFIX-DIR  Use PREFIX-DIR as a staging area for installation
+
+The rest of the components are interpreted as arguments to that command (only
+BSD-compatible install options are recognized)."
+        ;;
+
+      link)
+        $ECHO \
+"Usage: $progname [OPTION]... --mode=link LINK-COMMAND...
+
+Link object files or libraries together to form another library, or to
+create an executable program.
+
+LINK-COMMAND is a command using the C compiler that you would use to create
+a program from several object files.
+
+The following components of LINK-COMMAND are treated specially:
+
+  -all-static       do not do any dynamic linking at all
+  -avoid-version    do not add a version suffix if possible
+  -dlopen FILE      \`-dlpreopen' FILE if it cannot be dlopened at runtime
+  -dlpreopen FILE   link in FILE and add its symbols to lt_preloaded_symbols
+  -export-dynamic   allow symbols from OUTPUT-FILE to be resolved with dlsym(3)
+  -export-symbols SYMFILE
+                    try to export only the symbols listed in SYMFILE
+  -export-symbols-regex REGEX
+                    try to export only the symbols matching REGEX
+  -LLIBDIR          search LIBDIR for required installed libraries
+  -lNAME            OUTPUT-FILE requires the installed library libNAME
+  -module           build a library that can dlopened
+  -no-fast-install  disable the fast-install mode
+  -no-install       link a not-installable executable
+  -no-undefined     declare that a library does not refer to external symbols
+  -o OUTPUT-FILE    create OUTPUT-FILE from the specified objects
+  -objectlist FILE  Use a list of object files found in FILE to specify objects
+  -precious-files-regex REGEX
+                    don't remove output files matching REGEX
+  -release RELEASE  specify package release information
+  -rpath LIBDIR     the created library will eventually be installed in LIBDIR
+  -R[ ]LIBDIR       add LIBDIR to the runtime path of programs and libraries
+  -shared           only do dynamic linking of libtool libraries
+  -shrext SUFFIX    override the standard shared library file extension
+  -static           do not do any dynamic linking of uninstalled libtool libraries
+  -static-libtool-libs
+                    do not do any dynamic linking of libtool libraries
+  -version-info CURRENT[:REVISION[:AGE]]
+                    specify library version info [each variable defaults to 0]
+  -weak LIBNAME     declare that the target provides the LIBNAME interface
+
+All other options (arguments beginning with \`-') are ignored.
+
+Every other argument is treated as a filename.  Files ending in \`.la' are
+treated as uninstalled libtool libraries, other files are standard or library
+object files.
+
+If the OUTPUT-FILE ends in \`.la', then a libtool library is created,
+only library objects (\`.lo' files) may be specified, and \`-rpath' is
+required, except when creating a convenience library.
+
+If OUTPUT-FILE ends in \`.a' or \`.lib', then a standard library is created
+using \`ar' and \`ranlib', or on Windows using \`lib'.
+
+If OUTPUT-FILE ends in \`.lo' or \`.${objext}', then a reloadable object file
+is created, otherwise an executable program is created."
+        ;;
+
+      uninstall)
+        $ECHO \
+"Usage: $progname [OPTION]... --mode=uninstall RM [RM-OPTION]... FILE...
+
+Remove libraries from an installation directory.
+
+RM is the name of the program to use to delete files associated with each FILE
+(typically \`/bin/rm').  RM-OPTIONS are options (such as \`-f') to be passed
+to RM.
+
+If FILE is a libtool library, all the files associated with it are deleted.
+Otherwise, only FILE itself is deleted using RM."
+        ;;
+
+      *)
+        func_fatal_help "invalid operation mode \`$mode'"
+        ;;
+    esac
+
+    $ECHO
+    $ECHO "Try \`$progname --help' for more information about other modes."
+
+    exit $?
+}
+
+  # Now that we've collected a possible --mode arg, show help if necessary
+  $opt_help && func_mode_help
+
+
+# func_mode_execute arg...
+func_mode_execute ()
+{
+    $opt_debug
+    # The first argument is the command name.
+    cmd="$nonopt"
+    test -z "$cmd" && \
+      func_fatal_help "you must specify a COMMAND"
+
+    # Handle -dlopen flags immediately.
+    for file in $execute_dlfiles; do
+      test -f "$file" \
+	|| func_fatal_help "\`$file' is not a file"
+
+      dir=
+      case $file in
+      *.la)
+	# Check to see that this really is a libtool archive.
+	func_lalib_unsafe_p "$file" \
+	  || func_fatal_help "\`$lib' is not a valid libtool archive"
+
+	# Read the libtool library.
+	dlname=
+	library_names=
+	func_source "$file"
+
+	# Skip this library if it cannot be dlopened.
+	if test -z "$dlname"; then
+	  # Warn if it was a shared library.
+	  test -n "$library_names" && \
+	    func_warning "\`$file' was not linked with \`-export-dynamic'"
+	  continue
+	fi
+
+	func_dirname "$file" "" "."
+	dir="$func_dirname_result"
+
+	if test -f "$dir/$objdir/$dlname"; then
+	  dir="$dir/$objdir"
+	else
+	  if test ! -f "$dir/$dlname"; then
+	    func_fatal_error "cannot find \`$dlname' in \`$dir' or \`$dir/$objdir'"
+	  fi
+	fi
+	;;
+
+      *.lo)
+	# Just add the directory containing the .lo file.
+	func_dirname "$file" "" "."
+	dir="$func_dirname_result"
+	;;
+
+      *)
+	func_warning "\`-dlopen' is ignored for non-libtool libraries and objects"
+	continue
+	;;
+      esac
+
+      # Get the absolute pathname.
+      absdir=`cd "$dir" && pwd`
+      test -n "$absdir" && dir="$absdir"
+
+      # Now add the directory to shlibpath_var.
+      if eval "test -z \"\$$shlibpath_var\""; then
+	eval "$shlibpath_var=\"\$dir\""
+      else
+	eval "$shlibpath_var=\"\$dir:\$$shlibpath_var\""
+      fi
+    done
+
+    # This variable tells wrapper scripts just to set shlibpath_var
+    # rather than running their programs.
+    libtool_execute_magic="$magic"
+
+    # Check if any of the arguments is a wrapper script.
+    args=
+    for file
+    do
+      case $file in
+      -*) ;;
+      *)
+	# Do a test to see if this is really a libtool program.
+	if func_ltwrapper_script_p "$file"; then
+	  func_source "$file"
+	  # Transform arg to wrapped name.
+	  file="$progdir/$program"
+	elif func_ltwrapper_executable_p "$file"; then
+	  func_ltwrapper_scriptname "$file"
+	  func_source "$func_ltwrapper_scriptname_result"
+	  # Transform arg to wrapped name.
+	  file="$progdir/$program"
+	fi
+	;;
+      esac
+      # Quote arguments (to preserve shell metacharacters).
+      func_quote_for_eval "$file"
+      args="$args $func_quote_for_eval_result"
+    done
+
+    if test "X$opt_dry_run" = Xfalse; then
+      if test -n "$shlibpath_var"; then
+	# Export the shlibpath_var.
+	eval "export $shlibpath_var"
+      fi
+
+      # Restore saved environment variables
+      for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
+      do
+	eval "if test \"\${save_$lt_var+set}\" = set; then
+                $lt_var=\$save_$lt_var; export $lt_var
+	      else
+		$lt_unset $lt_var
+	      fi"
+      done
+
+      # Now prepare to actually exec the command.
+      exec_cmd="\$cmd$args"
+    else
+      # Display what would be done.
+      if test -n "$shlibpath_var"; then
+	eval "\$ECHO \"\$shlibpath_var=\$$shlibpath_var\""
+	$ECHO "export $shlibpath_var"
+      fi
+      $ECHO "$cmd$args"
+      exit $EXIT_SUCCESS
+    fi
+}
+
+test "$mode" = execute && func_mode_execute ${1+"$@"}
+
+
+# func_mode_finish arg...
+func_mode_finish ()
+{
+    $opt_debug
+    libdirs="$nonopt"
+    admincmds=
+
+    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
+      for dir
+      do
+	libdirs="$libdirs $dir"
+      done
+
+      for libdir in $libdirs; do
+	if test -n "$finish_cmds"; then
+	  # Do each command in the finish commands.
+	  func_execute_cmds "$finish_cmds" 'admincmds="$admincmds
+'"$cmd"'"'
+	fi
+	if test -n "$finish_eval"; then
+	  # Do the single finish_eval.
+	  eval cmds=\"$finish_eval\"
+	  $opt_dry_run || eval "$cmds" || admincmds="$admincmds
+       $cmds"
+	fi
+      done
+    fi
+
+    # Exit here if they wanted silent mode.
+    $opt_silent && exit $EXIT_SUCCESS
+
+    $ECHO "X----------------------------------------------------------------------" | $Xsed
+    $ECHO "Libraries have been installed in:"
+    for libdir in $libdirs; do
+      $ECHO "   $libdir"
+    done
+    $ECHO
+    $ECHO "If you ever happen to want to link against installed libraries"
+    $ECHO "in a given directory, LIBDIR, you must either use libtool, and"
+    $ECHO "specify the full pathname of the library, or use the \`-LLIBDIR'"
+    $ECHO "flag during linking and do at least one of the following:"
+    if test -n "$shlibpath_var"; then
+      $ECHO "   - add LIBDIR to the \`$shlibpath_var' environment variable"
+      $ECHO "     during execution"
+    fi
+    if test -n "$runpath_var"; then
+      $ECHO "   - add LIBDIR to the \`$runpath_var' environment variable"
+      $ECHO "     during linking"
+    fi
+    if test -n "$hardcode_libdir_flag_spec"; then
+      libdir=LIBDIR
+      eval flag=\"$hardcode_libdir_flag_spec\"
+
+      $ECHO "   - use the \`$flag' linker flag"
+    fi
+    if test -n "$admincmds"; then
+      $ECHO "   - have your system administrator run these commands:$admincmds"
+    fi
+    if test -f /etc/ld.so.conf; then
+      $ECHO "   - have your system administrator add LIBDIR to \`/etc/ld.so.conf'"
+    fi
+    $ECHO
+
+    $ECHO "See any operating system documentation about shared libraries for"
+    case $host in
+      solaris2.[6789]|solaris2.1[0-9])
+        $ECHO "more information, such as the ld(1), crle(1) and ld.so(8) manual"
+	$ECHO "pages."
+	;;
+      *)
+        $ECHO "more information, such as the ld(1) and ld.so(8) manual pages."
+        ;;
+    esac
+    $ECHO "X----------------------------------------------------------------------" | $Xsed
+    exit $EXIT_SUCCESS
+}
+
+test "$mode" = finish && func_mode_finish ${1+"$@"}
+
+
+# func_mode_install arg...
+func_mode_install ()
+{
+    $opt_debug
+    # There may be an optional sh(1) argument at the beginning of
+    # install_prog (especially on Windows NT).
+    if test "$nonopt" = "$SHELL" || test "$nonopt" = /bin/sh ||
+       # Allow the use of GNU shtool's install command.
+       $ECHO "X$nonopt" | $GREP shtool >/dev/null; then
+      # Aesthetically quote it.
+      func_quote_for_eval "$nonopt"
+      install_prog="$func_quote_for_eval_result "
+      arg=$1
+      shift
+    else
+      install_prog=
+      arg=$nonopt
+    fi
+
+    # The real first argument should be the name of the installation program.
+    # Aesthetically quote it.
+    func_quote_for_eval "$arg"
+    install_prog="$install_prog$func_quote_for_eval_result"
+
+    # We need to accept at least all the BSD install flags.
+    dest=
+    files=
+    opts=
+    prev=
+    install_type=
+    isdir=no
+    stripme=
+    for arg
+    do
+      if test -n "$dest"; then
+	files="$files $dest"
+	dest=$arg
+	continue
+      fi
+
+      case $arg in
+      -d) isdir=yes ;;
+      -f)
+	case " $install_prog " in
+	*[\\\ /]cp\ *) ;;
+	*) prev=$arg ;;
+	esac
+	;;
+      -g | -m | -o)
+	prev=$arg
+	;;
+      -s)
+	stripme=" -s"
+	continue
+	;;
+      -*)
+	;;
+      *)
+	# If the previous option needed an argument, then skip it.
+	if test -n "$prev"; then
+	  prev=
+	else
+	  dest=$arg
+	  continue
+	fi
+	;;
+      esac
+
+      # Aesthetically quote the argument.
+      func_quote_for_eval "$arg"
+      install_prog="$install_prog $func_quote_for_eval_result"
+    done
+
+    test -z "$install_prog" && \
+      func_fatal_help "you must specify an install program"
+
+    test -n "$prev" && \
+      func_fatal_help "the \`$prev' option requires an argument"
+
+    if test -z "$files"; then
+      if test -z "$dest"; then
+	func_fatal_help "no file or destination specified"
+      else
+	func_fatal_help "you must specify a destination"
+      fi
+    fi
+
+    # Strip any trailing slash from the destination.
+    func_stripname '' '/' "$dest"
+    dest=$func_stripname_result
+
+    # Check to see that the destination is a directory.
+    test -d "$dest" && isdir=yes
+    if test "$isdir" = yes; then
+      destdir="$dest"
+      destname=
+    else
+      func_dirname_and_basename "$dest" "" "."
+      destdir="$func_dirname_result"
+      destname="$func_basename_result"
+
+      # Not a directory, so check to see that there is only one file specified.
+      set dummy $files; shift
+      test "$#" -gt 1 && \
+	func_fatal_help "\`$dest' is not a directory"
+    fi
+    case $destdir in
+    [\\/]* | [A-Za-z]:[\\/]*) ;;
+    *)
+      for file in $files; do
+	case $file in
+	*.lo) ;;
+	*)
+	  func_fatal_help "\`$destdir' must be an absolute directory name"
+	  ;;
+	esac
+      done
+      ;;
+    esac
+
+    # This variable tells wrapper scripts just to set variables rather
+    # than running their programs.
+    libtool_install_magic="$magic"
+
+    staticlibs=
+    future_libdirs=
+    current_libdirs=
+    for file in $files; do
+
+      # Do each installation.
+      case $file in
+      *.$libext)
+	# Do the static libraries later.
+	staticlibs="$staticlibs $file"
+	;;
+
+      *.la)
+	# Check to see that this really is a libtool archive.
+	func_lalib_unsafe_p "$file" \
+	  || func_fatal_help "\`$file' is not a valid libtool archive"
+
+	library_names=
+	old_library=
+	relink_command=
+	func_source "$file"
+
+	# Add the libdir to current_libdirs if it is the destination.
+	if test "X$destdir" = "X$libdir"; then
+	  case "$current_libdirs " in
+	  *" $libdir "*) ;;
+	  *) current_libdirs="$current_libdirs $libdir" ;;
+	  esac
+	else
+	  # Note the libdir as a future libdir.
+	  case "$future_libdirs " in
+	  *" $libdir "*) ;;
+	  *) future_libdirs="$future_libdirs $libdir" ;;
+	  esac
+	fi
+
+	func_dirname "$file" "/" ""
+	dir="$func_dirname_result"
+	dir="$dir$objdir"
+
+	if test -n "$relink_command"; then
+	  # Determine the prefix the user has applied to our future dir.
+	  inst_prefix_dir=`$ECHO "X$destdir" | $Xsed -e "s%$libdir\$%%"`
+
+	  # Don't allow the user to place us outside of our expected
+	  # location b/c this prevents finding dependent libraries that
+	  # are installed to the same prefix.
+	  # At present, this check doesn't affect windows .dll's that
+	  # are installed into $libdir/../bin (currently, that works fine)
+	  # but it's something to keep an eye on.
+	  test "$inst_prefix_dir" = "$destdir" && \
+	    func_fatal_error "error: cannot install \`$file' to a directory not ending in $libdir"
+
+	  if test -n "$inst_prefix_dir"; then
+	    # Stick the inst_prefix_dir data into the link command.
+	    relink_command=`$ECHO "X$relink_command" | $Xsed -e "s%@inst_prefix_dir@%-inst-prefix-dir $inst_prefix_dir%"`
+	  else
+	    relink_command=`$ECHO "X$relink_command" | $Xsed -e "s%@inst_prefix_dir@%%"`
+	  fi
+
+	  func_warning "relinking \`$file'"
+	  func_show_eval "$relink_command" \
+	    'func_fatal_error "error: relink \`$file'\'' with the above command before installing it"'
+	fi
+
+	# See the names of the shared library.
+	set dummy $library_names; shift
+	if test -n "$1"; then
+	  realname="$1"
+	  shift
+
+	  srcname="$realname"
+	  test -n "$relink_command" && srcname="$realname"T
+
+	  # Install the shared library and build the symlinks.
+	  func_show_eval "$install_prog $dir/$srcname $destdir/$realname" \
+	      'exit $?'
+	  tstripme="$stripme"
+	  case $host_os in
+	  cygwin* | mingw* | pw32* | cegcc*)
+	    case $realname in
+	    *.dll.a)
+	      tstripme=""
+	      ;;
+	    esac
+	    ;;
+	  esac
+	  if test -n "$tstripme" && test -n "$striplib"; then
+	    func_show_eval "$striplib $destdir/$realname" 'exit $?'
+	  fi
+
+	  if test "$#" -gt 0; then
+	    # Delete the old symlinks, and create new ones.
+	    # Try `ln -sf' first, because the `ln' binary might depend on
+	    # the symlink we replace!  Solaris /bin/ln does not understand -f,
+	    # so we also need to try rm && ln -s.
+	    for linkname
+	    do
+	      test "$linkname" != "$realname" \
+		&& func_show_eval "(cd $destdir && { $LN_S -f $realname $linkname || { $RM $linkname && $LN_S $realname $linkname; }; })"
+	    done
+	  fi
+
+	  # Do each command in the postinstall commands.
+	  lib="$destdir/$realname"
+	  func_execute_cmds "$postinstall_cmds" 'exit $?'
+	fi
+
+	# Install the pseudo-library for information purposes.
+	func_basename "$file"
+	name="$func_basename_result"
+	instname="$dir/$name"i
+	func_show_eval "$install_prog $instname $destdir/$name" 'exit $?'
+
+	# Maybe install the static library, too.
+	test -n "$old_library" && staticlibs="$staticlibs $dir/$old_library"
+	;;
+
+      *.lo)
+	# Install (i.e. copy) a libtool object.
+
+	# Figure out destination file name, if it wasn't already specified.
+	if test -n "$destname"; then
+	  destfile="$destdir/$destname"
+	else
+	  func_basename "$file"
+	  destfile="$func_basename_result"
+	  destfile="$destdir/$destfile"
+	fi
+
+	# Deduce the name of the destination old-style object file.
+	case $destfile in
+	*.lo)
+	  func_lo2o "$destfile"
+	  staticdest=$func_lo2o_result
+	  ;;
+	*.$objext)
+	  staticdest="$destfile"
+	  destfile=
+	  ;;
+	*)
+	  func_fatal_help "cannot copy a libtool object to \`$destfile'"
+	  ;;
+	esac
+
+	# Install the libtool object if requested.
+	test -n "$destfile" && \
+	  func_show_eval "$install_prog $file $destfile" 'exit $?'
+
+	# Install the old object if enabled.
+	if test "$build_old_libs" = yes; then
+	  # Deduce the name of the old-style object file.
+	  func_lo2o "$file"
+	  staticobj=$func_lo2o_result
+	  func_show_eval "$install_prog \$staticobj \$staticdest" 'exit $?'
+	fi
+	exit $EXIT_SUCCESS
+	;;
+
+      *)
+	# Figure out destination file name, if it wasn't already specified.
+	if test -n "$destname"; then
+	  destfile="$destdir/$destname"
+	else
+	  func_basename "$file"
+	  destfile="$func_basename_result"
+	  destfile="$destdir/$destfile"
+	fi
+
+	# If the file is missing, and there is a .exe on the end, strip it
+	# because it is most likely a libtool script we actually want to
+	# install
+	stripped_ext=""
+	case $file in
+	  *.exe)
+	    if test ! -f "$file"; then
+	      func_stripname '' '.exe' "$file"
+	      file=$func_stripname_result
+	      stripped_ext=".exe"
+	    fi
+	    ;;
+	esac
+
+	# Do a test to see if this is really a libtool program.
+	case $host in
+	*cygwin* | *mingw*)
+	    if func_ltwrapper_executable_p "$file"; then
+	      func_ltwrapper_scriptname "$file"
+	      wrapper=$func_ltwrapper_scriptname_result
+	    else
+	      func_stripname '' '.exe' "$file"
+	      wrapper=$func_stripname_result
+	    fi
+	    ;;
+	*)
+	    wrapper=$file
+	    ;;
+	esac
+	if func_ltwrapper_script_p "$wrapper"; then
+	  notinst_deplibs=
+	  relink_command=
+
+	  func_source "$wrapper"
+
+	  # Check the variables that should have been set.
+	  test -z "$generated_by_libtool_version" && \
+	    func_fatal_error "invalid libtool wrapper script \`$wrapper'"
+
+	  finalize=yes
+	  for lib in $notinst_deplibs; do
+	    # Check to see that each library is installed.
+	    libdir=
+	    if test -f "$lib"; then
+	      func_source "$lib"
+	    fi
+	    libfile="$libdir/"`$ECHO "X$lib" | $Xsed -e 's%^.*/%%g'` ### testsuite: skip nested quoting test
+	    if test -n "$libdir" && test ! -f "$libfile"; then
+	      func_warning "\`$lib' has not been installed in \`$libdir'"
+	      finalize=no
+	    fi
+	  done
+
+	  relink_command=
+	  func_source "$wrapper"
+
+	  outputname=
+	  if test "$fast_install" = no && test -n "$relink_command"; then
+	    $opt_dry_run || {
+	      if test "$finalize" = yes; then
+	        tmpdir=`func_mktempdir`
+		func_basename "$file$stripped_ext"
+		file="$func_basename_result"
+	        outputname="$tmpdir/$file"
+	        # Replace the output file specification.
+	        relink_command=`$ECHO "X$relink_command" | $Xsed -e 's%@OUTPUT@%'"$outputname"'%g'`
+
+	        $opt_silent || {
+	          func_quote_for_expand "$relink_command"
+		  eval "func_echo $func_quote_for_expand_result"
+	        }
+	        if eval "$relink_command"; then :
+	          else
+		  func_error "error: relink \`$file' with the above command before installing it"
+		  $opt_dry_run || ${RM}r "$tmpdir"
+		  continue
+	        fi
+	        file="$outputname"
+	      else
+	        func_warning "cannot relink \`$file'"
+	      fi
+	    }
+	  else
+	    # Install the binary that we compiled earlier.
+	    file=`$ECHO "X$file$stripped_ext" | $Xsed -e "s%\([^/]*\)$%$objdir/\1%"`
+	  fi
+	fi
+
+	# remove .exe since cygwin /usr/bin/install will append another
+	# one anyway
+	case $install_prog,$host in
+	*/usr/bin/install*,*cygwin*)
+	  case $file:$destfile in
+	  *.exe:*.exe)
+	    # this is ok
+	    ;;
+	  *.exe:*)
+	    destfile=$destfile.exe
+	    ;;
+	  *:*.exe)
+	    func_stripname '' '.exe' "$destfile"
+	    destfile=$func_stripname_result
+	    ;;
+	  esac
+	  ;;
+	esac
+	func_show_eval "$install_prog\$stripme \$file \$destfile" 'exit $?'
+	$opt_dry_run || if test -n "$outputname"; then
+	  ${RM}r "$tmpdir"
+	fi
+	;;
+      esac
+    done
+
+    for file in $staticlibs; do
+      func_basename "$file"
+      name="$func_basename_result"
+
+      # Set up the ranlib parameters.
+      oldlib="$destdir/$name"
+
+      func_show_eval "$install_prog \$file \$oldlib" 'exit $?'
+
+      if test -n "$stripme" && test -n "$old_striplib"; then
+	func_show_eval "$old_striplib $oldlib" 'exit $?'
+      fi
+
+      # Do each command in the postinstall commands.
+      func_execute_cmds "$old_postinstall_cmds" 'exit $?'
+    done
+
+    test -n "$future_libdirs" && \
+      func_warning "remember to run \`$progname --finish$future_libdirs'"
+
+    if test -n "$current_libdirs"; then
+      # Maybe just do a dry run.
+      $opt_dry_run && current_libdirs=" -n$current_libdirs"
+      exec_cmd='$SHELL $progpath $preserve_args --finish$current_libdirs'
+    else
+      exit $EXIT_SUCCESS
+    fi
+}
+
+test "$mode" = install && func_mode_install ${1+"$@"}
+
+
+# func_generate_dlsyms outputname originator pic_p
+# Extract symbols from dlprefiles and create ${outputname}S.o with
+# a dlpreopen symbol table.
+func_generate_dlsyms ()
+{
+    $opt_debug
+    my_outputname="$1"
+    my_originator="$2"
+    my_pic_p="${3-no}"
+    my_prefix=`$ECHO "$my_originator" | sed 's%[^a-zA-Z0-9]%_%g'`
+    my_dlsyms=
+
+    if test -n "$dlfiles$dlprefiles" || test "$dlself" != no; then
+      if test -n "$NM" && test -n "$global_symbol_pipe"; then
+	my_dlsyms="${my_outputname}S.c"
+      else
+	func_error "not configured to extract global symbols from dlpreopened files"
+      fi
+    fi
+
+    if test -n "$my_dlsyms"; then
+      case $my_dlsyms in
+      "") ;;
+      *.c)
+	# Discover the nlist of each of the dlfiles.
+	nlist="$output_objdir/${my_outputname}.nm"
+
+	func_show_eval "$RM $nlist ${nlist}S ${nlist}T"
+
+	# Parse the name list into a source file.
+	func_verbose "creating $output_objdir/$my_dlsyms"
+
+	$opt_dry_run || $ECHO > "$output_objdir/$my_dlsyms" "\
+/* $my_dlsyms - symbol resolution table for \`$my_outputname' dlsym emulation. */
+/* Generated by $PROGRAM (GNU $PACKAGE$TIMESTAMP) $VERSION */
+
+#ifdef __cplusplus
+extern \"C\" {
+#endif
+
+/* External symbol declarations for the compiler. */\
+"
+
+	if test "$dlself" = yes; then
+	  func_verbose "generating symbol list for \`$output'"
+
+	  $opt_dry_run || echo ': @PROGRAM@ ' > "$nlist"
+
+	  # Add our own program objects to the symbol list.
+	  progfiles=`$ECHO "X$objs$old_deplibs" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP`
+	  for progfile in $progfiles; do
+	    func_verbose "extracting global C symbols from \`$progfile'"
+	    $opt_dry_run || eval "$NM $progfile | $global_symbol_pipe >> '$nlist'"
+	  done
+
+	  if test -n "$exclude_expsyms"; then
+	    $opt_dry_run || {
+	      eval '$EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T'
+	      eval '$MV "$nlist"T "$nlist"'
+	    }
+	  fi
+
+	  if test -n "$export_symbols_regex"; then
+	    $opt_dry_run || {
+	      eval '$EGREP -e "$export_symbols_regex" "$nlist" > "$nlist"T'
+	      eval '$MV "$nlist"T "$nlist"'
+	    }
+	  fi
+
+	  # Prepare the list of exported symbols
+	  if test -z "$export_symbols"; then
+	    export_symbols="$output_objdir/$outputname.exp"
+	    $opt_dry_run || {
+	      $RM $export_symbols
+	      eval "${SED} -n -e '/^: @PROGRAM@ $/d' -e 's/^.* \(.*\)$/\1/p' "'< "$nlist" > "$export_symbols"'
+	      case $host in
+	      *cygwin* | *mingw* | *cegcc* )
+                eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
+                eval 'cat "$export_symbols" >> "$output_objdir/$outputname.def"'
+	        ;;
+	      esac
+	    }
+	  else
+	    $opt_dry_run || {
+	      eval "${SED} -e 's/\([].[*^$]\)/\\\\\1/g' -e 's/^/ /' -e 's/$/$/'"' < "$export_symbols" > "$output_objdir/$outputname.exp"'
+	      eval '$GREP -f "$output_objdir/$outputname.exp" < "$nlist" > "$nlist"T'
+	      eval '$MV "$nlist"T "$nlist"'
+	      case $host in
+	        *cygwin | *mingw* | *cegcc* )
+	          eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
+	          eval 'cat "$nlist" >> "$output_objdir/$outputname.def"'
+	          ;;
+	      esac
+	    }
+	  fi
+	fi
+
+	for dlprefile in $dlprefiles; do
+	  func_verbose "extracting global C symbols from \`$dlprefile'"
+	  func_basename "$dlprefile"
+	  name="$func_basename_result"
+	  $opt_dry_run || {
+	    eval '$ECHO ": $name " >> "$nlist"'
+	    eval "$NM $dlprefile 2>/dev/null | $global_symbol_pipe >> '$nlist'"
+	  }
+	done
+
+	$opt_dry_run || {
+	  # Make sure we have at least an empty file.
+	  test -f "$nlist" || : > "$nlist"
+
+	  if test -n "$exclude_expsyms"; then
+	    $EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T
+	    $MV "$nlist"T "$nlist"
+	  fi
+
+	  # Try sorting and uniquifying the output.
+	  if $GREP -v "^: " < "$nlist" |
+	      if sort -k 3 </dev/null >/dev/null 2>&1; then
+		sort -k 3
+	      else
+		sort +2
+	      fi |
+	      uniq > "$nlist"S; then
+	    :
+	  else
+	    $GREP -v "^: " < "$nlist" > "$nlist"S
+	  fi
+
+	  if test -f "$nlist"S; then
+	    eval "$global_symbol_to_cdecl"' < "$nlist"S >> "$output_objdir/$my_dlsyms"'
+	  else
+	    $ECHO '/* NONE */' >> "$output_objdir/$my_dlsyms"
+	  fi
+
+	  $ECHO >> "$output_objdir/$my_dlsyms" "\
+
+/* The mapping between symbol names and symbols.  */
+typedef struct {
+  const char *name;
+  void *address;
+} lt_dlsymlist;
+"
+	  case $host in
+	  *cygwin* | *mingw* | *cegcc* )
+	    $ECHO >> "$output_objdir/$my_dlsyms" "\
+/* DATA imports from DLLs on WIN32 con't be const, because
+   runtime relocations are performed -- see ld's documentation
+   on pseudo-relocs.  */"
+	    lt_dlsym_const= ;;
+	  *osf5*)
+	    echo >> "$output_objdir/$my_dlsyms" "\
+/* This system does not cope well with relocations in const data */"
+	    lt_dlsym_const= ;;
+	  *)
+	    lt_dlsym_const=const ;;
+	  esac
+
+	  $ECHO >> "$output_objdir/$my_dlsyms" "\
+extern $lt_dlsym_const lt_dlsymlist
+lt_${my_prefix}_LTX_preloaded_symbols[];
+$lt_dlsym_const lt_dlsymlist
+lt_${my_prefix}_LTX_preloaded_symbols[] =
+{\
+  { \"$my_originator\", (void *) 0 },"
+
+	  case $need_lib_prefix in
+	  no)
+	    eval "$global_symbol_to_c_name_address" < "$nlist" >> "$output_objdir/$my_dlsyms"
+	    ;;
+	  *)
+	    eval "$global_symbol_to_c_name_address_lib_prefix" < "$nlist" >> "$output_objdir/$my_dlsyms"
+	    ;;
+	  esac
+	  $ECHO >> "$output_objdir/$my_dlsyms" "\
+  {0, (void *) 0}
+};
+
+/* This works around a problem in FreeBSD linker */
+#ifdef FREEBSD_WORKAROUND
+static const void *lt_preloaded_setup() {
+  return lt_${my_prefix}_LTX_preloaded_symbols;
+}
+#endif
+
+#ifdef __cplusplus
+}
+#endif\
+"
+	} # !$opt_dry_run
+
+	pic_flag_for_symtable=
+	case "$compile_command " in
+	*" -static "*) ;;
+	*)
+	  case $host in
+	  # compiling the symbol table file with pic_flag works around
+	  # a FreeBSD bug that causes programs to crash when -lm is
+	  # linked before any other PIC object.  But we must not use
+	  # pic_flag when linking with -static.  The problem exists in
+	  # FreeBSD 2.2.6 and is fixed in FreeBSD 3.1.
+	  *-*-freebsd2*|*-*-freebsd3.0*|*-*-freebsdelf3.0*)
+	    pic_flag_for_symtable=" $pic_flag -DFREEBSD_WORKAROUND" ;;
+	  *-*-hpux*)
+	    pic_flag_for_symtable=" $pic_flag"  ;;
+	  *)
+	    if test "X$my_pic_p" != Xno; then
+	      pic_flag_for_symtable=" $pic_flag"
+	    fi
+	    ;;
+	  esac
+	  ;;
+	esac
+	symtab_cflags=
+	for arg in $LTCFLAGS; do
+	  case $arg in
+	  -pie | -fpie | -fPIE) ;;
+	  *) symtab_cflags="$symtab_cflags $arg" ;;
+	  esac
+	done
+
+	# Now compile the dynamic symbol file.
+	func_show_eval '(cd $output_objdir && $LTCC$symtab_cflags -c$no_builtin_flag$pic_flag_for_symtable "$my_dlsyms")' 'exit $?'
+
+	# Clean up the generated files.
+	func_show_eval '$RM "$output_objdir/$my_dlsyms" "$nlist" "${nlist}S" "${nlist}T"'
+
+	# Transform the symbol file into the correct name.
+	symfileobj="$output_objdir/${my_outputname}S.$objext"
+	case $host in
+	*cygwin* | *mingw* | *cegcc* )
+	  if test -f "$output_objdir/$my_outputname.def"; then
+	    compile_command=`$ECHO "X$compile_command" | $Xsed -e "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
+	    finalize_command=`$ECHO "X$finalize_command" | $Xsed -e "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
+	  else
+	    compile_command=`$ECHO "X$compile_command" | $Xsed -e "s%@SYMFILE@%$symfileobj%"`
+	    finalize_command=`$ECHO "X$finalize_command" | $Xsed -e "s%@SYMFILE@%$symfileobj%"`
+	  fi
+	  ;;
+	*)
+	  compile_command=`$ECHO "X$compile_command" | $Xsed -e "s%@SYMFILE@%$symfileobj%"`
+	  finalize_command=`$ECHO "X$finalize_command" | $Xsed -e "s%@SYMFILE@%$symfileobj%"`
+	  ;;
+	esac
+	;;
+      *)
+	func_fatal_error "unknown suffix for \`$my_dlsyms'"
+	;;
+      esac
+    else
+      # We keep going just in case the user didn't refer to
+      # lt_preloaded_symbols.  The linker will fail if global_symbol_pipe
+      # really was required.
+
+      # Nullify the symbol file.
+      compile_command=`$ECHO "X$compile_command" | $Xsed -e "s% @SYMFILE@%%"`
+      finalize_command=`$ECHO "X$finalize_command" | $Xsed -e "s% @SYMFILE@%%"`
+    fi
+}
+
+# func_win32_libid arg
+# return the library type of file 'arg'
+#
+# Need a lot of goo to handle *both* DLLs and import libs
+# Has to be a shell function in order to 'eat' the argument
+# that is supplied when $file_magic_command is called.
+func_win32_libid ()
+{
+  $opt_debug
+  win32_libid_type="unknown"
+  win32_fileres=`file -L $1 2>/dev/null`
+  case $win32_fileres in
+  *ar\ archive\ import\ library*) # definitely import
+    win32_libid_type="x86 archive import"
+    ;;
+  *ar\ archive*) # could be an import, or static
+    if eval $OBJDUMP -f $1 | $SED -e '10q' 2>/dev/null |
+       $EGREP 'file format pe-i386(.*architecture: i386)?' >/dev/null ; then
+      win32_nmres=`eval $NM -f posix -A $1 |
+	$SED -n -e '
+	    1,100{
+		/ I /{
+		    s,.*,import,
+		    p
+		    q
+		}
+	    }'`
+      case $win32_nmres in
+      import*)  win32_libid_type="x86 archive import";;
+      *)        win32_libid_type="x86 archive static";;
+      esac
+    fi
+    ;;
+  *DLL*)
+    win32_libid_type="x86 DLL"
+    ;;
+  *executable*) # but shell scripts are "executable" too...
+    case $win32_fileres in
+    *MS\ Windows\ PE\ Intel*)
+      win32_libid_type="x86 DLL"
+      ;;
+    esac
+    ;;
+  esac
+  $ECHO "$win32_libid_type"
+}
+
+
+
+# func_extract_an_archive dir oldlib
+func_extract_an_archive ()
+{
+    $opt_debug
+    f_ex_an_ar_dir="$1"; shift
+    f_ex_an_ar_oldlib="$1"
+    func_show_eval "(cd \$f_ex_an_ar_dir && $AR x \"\$f_ex_an_ar_oldlib\")" 'exit $?'
+    if ($AR t "$f_ex_an_ar_oldlib" | sort | sort -uc >/dev/null 2>&1); then
+     :
+    else
+      func_fatal_error "object name conflicts in archive: $f_ex_an_ar_dir/$f_ex_an_ar_oldlib"
+    fi
+}
+
+
+# func_extract_archives gentop oldlib ...
+func_extract_archives ()
+{
+    $opt_debug
+    my_gentop="$1"; shift
+    my_oldlibs=${1+"$@"}
+    my_oldobjs=""
+    my_xlib=""
+    my_xabs=""
+    my_xdir=""
+
+    for my_xlib in $my_oldlibs; do
+      # Extract the objects.
+      case $my_xlib in
+	[\\/]* | [A-Za-z]:[\\/]*) my_xabs="$my_xlib" ;;
+	*) my_xabs=`pwd`"/$my_xlib" ;;
+      esac
+      func_basename "$my_xlib"
+      my_xlib="$func_basename_result"
+      my_xlib_u=$my_xlib
+      while :; do
+        case " $extracted_archives " in
+	*" $my_xlib_u "*)
+	  func_arith $extracted_serial + 1
+	  extracted_serial=$func_arith_result
+	  my_xlib_u=lt$extracted_serial-$my_xlib ;;
+	*) break ;;
+	esac
+      done
+      extracted_archives="$extracted_archives $my_xlib_u"
+      my_xdir="$my_gentop/$my_xlib_u"
+
+      func_mkdir_p "$my_xdir"
+
+      case $host in
+      *-darwin*)
+	func_verbose "Extracting $my_xabs"
+	# Do not bother doing anything if just a dry run
+	$opt_dry_run || {
+	  darwin_orig_dir=`pwd`
+	  cd $my_xdir || exit $?
+	  darwin_archive=$my_xabs
+	  darwin_curdir=`pwd`
+	  darwin_base_archive=`basename "$darwin_archive"`
+	  darwin_arches=`$LIPO -info "$darwin_archive" 2>/dev/null | $GREP Architectures 2>/dev/null || true`
+	  if test -n "$darwin_arches"; then
+	    darwin_arches=`$ECHO "$darwin_arches" | $SED -e 's/.*are://'`
+	    darwin_arch=
+	    func_verbose "$darwin_base_archive has multiple architectures $darwin_arches"
+	    for darwin_arch in  $darwin_arches ; do
+	      func_mkdir_p "unfat-$$/${darwin_base_archive}-${darwin_arch}"
+	      $LIPO -thin $darwin_arch -output "unfat-$$/${darwin_base_archive}-${darwin_arch}/${darwin_base_archive}" "${darwin_archive}"
+	      cd "unfat-$$/${darwin_base_archive}-${darwin_arch}"
+	      func_extract_an_archive "`pwd`" "${darwin_base_archive}"
+	      cd "$darwin_curdir"
+	      $RM "unfat-$$/${darwin_base_archive}-${darwin_arch}/${darwin_base_archive}"
+	    done # $darwin_arches
+            ## Okay now we've a bunch of thin objects, gotta fatten them up :)
+	    darwin_filelist=`find unfat-$$ -type f -name \*.o -print -o -name \*.lo -print | $SED -e "$basename" | sort -u`
+	    darwin_file=
+	    darwin_files=
+	    for darwin_file in $darwin_filelist; do
+	      darwin_files=`find unfat-$$ -name $darwin_file -print | $NL2SP`
+	      $LIPO -create -output "$darwin_file" $darwin_files
+	    done # $darwin_filelist
+	    $RM -rf unfat-$$
+	    cd "$darwin_orig_dir"
+	  else
+	    cd $darwin_orig_dir
+	    func_extract_an_archive "$my_xdir" "$my_xabs"
+	  fi # $darwin_arches
+	} # !$opt_dry_run
+	;;
+      *)
+        func_extract_an_archive "$my_xdir" "$my_xabs"
+	;;
+      esac
+      my_oldobjs="$my_oldobjs "`find $my_xdir -name \*.$objext -print -o -name \*.lo -print | $NL2SP`
+    done
+
+    func_extract_archives_result="$my_oldobjs"
+}
+
+
+
+# func_emit_wrapper_part1 [arg=no]
+#
+# Emit the first part of a libtool wrapper script on stdout.
+# For more information, see the description associated with
+# func_emit_wrapper(), below.
+func_emit_wrapper_part1 ()
+{
+	func_emit_wrapper_part1_arg1=no
+	if test -n "$1" ; then
+	  func_emit_wrapper_part1_arg1=$1
+	fi
+
+	$ECHO "\
+#! $SHELL
+
+# $output - temporary wrapper script for $objdir/$outputname
+# Generated by $PROGRAM (GNU $PACKAGE$TIMESTAMP) $VERSION
+#
+# The $output program cannot be directly executed until all the libtool
+# libraries that it depends on are installed.
+#
+# This wrapper script should never be moved out of the build directory.
+# If it is, it will not operate correctly.
+
+# Sed substitution that helps us do robust quoting.  It backslashifies
+# metacharacters that are still active within double-quoted strings.
+Xsed='${SED} -e 1s/^X//'
+sed_quote_subst='$sed_quote_subst'
+
+# Be Bourne compatible
+if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then
+  emulate sh
+  NULLCMD=:
+  # Zsh 3.x and 4.x performs word splitting on \${1+\"\$@\"}, which
+  # is contrary to our usage.  Disable this feature.
+  alias -g '\${1+\"\$@\"}'='\"\$@\"'
+  setopt NO_GLOB_SUBST
+else
+  case \`(set -o) 2>/dev/null\` in *posix*) set -o posix;; esac
+fi
+BIN_SH=xpg4; export BIN_SH # for Tru64
+DUALCASE=1; export DUALCASE # for MKS sh
+
+# The HP-UX ksh and POSIX shell print the target directory to stdout
+# if CDPATH is set.
+(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
+
+relink_command=\"$relink_command\"
+
+# This environment variable determines our operation mode.
+if test \"\$libtool_install_magic\" = \"$magic\"; then
+  # install mode needs the following variables:
+  generated_by_libtool_version='$macro_version'
+  notinst_deplibs='$notinst_deplibs'
+else
+  # When we are sourced in execute mode, \$file and \$ECHO are already set.
+  if test \"\$libtool_execute_magic\" != \"$magic\"; then
+    ECHO=\"$qecho\"
+    file=\"\$0\"
+    # Make sure echo works.
+    if test \"X\$1\" = X--no-reexec; then
+      # Discard the --no-reexec flag, and continue.
+      shift
+    elif test \"X\`{ \$ECHO '\t'; } 2>/dev/null\`\" = 'X\t'; then
+      # Yippee, \$ECHO works!
+      :
+    else
+      # Restart under the correct shell, and then maybe \$ECHO will work.
+      exec $SHELL \"\$0\" --no-reexec \${1+\"\$@\"}
+    fi
+  fi\
+"
+	$ECHO "\
+
+  # Find the directory that this script lives in.
+  thisdir=\`\$ECHO \"X\$file\" | \$Xsed -e 's%/[^/]*$%%'\`
+  test \"x\$thisdir\" = \"x\$file\" && thisdir=.
+
+  # Follow symbolic links until we get to the real thisdir.
+  file=\`ls -ld \"\$file\" | ${SED} -n 's/.*-> //p'\`
+  while test -n \"\$file\"; do
+    destdir=\`\$ECHO \"X\$file\" | \$Xsed -e 's%/[^/]*\$%%'\`
+
+    # If there was a directory component, then change thisdir.
+    if test \"x\$destdir\" != \"x\$file\"; then
+      case \"\$destdir\" in
+      [\\\\/]* | [A-Za-z]:[\\\\/]*) thisdir=\"\$destdir\" ;;
+      *) thisdir=\"\$thisdir/\$destdir\" ;;
+      esac
+    fi
+
+    file=\`\$ECHO \"X\$file\" | \$Xsed -e 's%^.*/%%'\`
+    file=\`ls -ld \"\$thisdir/\$file\" | ${SED} -n 's/.*-> //p'\`
+  done
+"
+}
+# end: func_emit_wrapper_part1
+
+# func_emit_wrapper_part2 [arg=no]
+#
+# Emit the second part of a libtool wrapper script on stdout.
+# For more information, see the description associated with
+# func_emit_wrapper(), below.
+func_emit_wrapper_part2 ()
+{
+	func_emit_wrapper_part2_arg1=no
+	if test -n "$1" ; then
+	  func_emit_wrapper_part2_arg1=$1
+	fi
+
+	$ECHO "\
+
+  # Usually 'no', except on cygwin/mingw when embedded into
+  # the cwrapper.
+  WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=$func_emit_wrapper_part2_arg1
+  if test \"\$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR\" = \"yes\"; then
+    # special case for '.'
+    if test \"\$thisdir\" = \".\"; then
+      thisdir=\`pwd\`
+    fi
+    # remove .libs from thisdir
+    case \"\$thisdir\" in
+    *[\\\\/]$objdir ) thisdir=\`\$ECHO \"X\$thisdir\" | \$Xsed -e 's%[\\\\/][^\\\\/]*$%%'\` ;;
+    $objdir )   thisdir=. ;;
+    esac
+  fi
+
+  # Try to get the absolute directory name.
+  absdir=\`cd \"\$thisdir\" && pwd\`
+  test -n \"\$absdir\" && thisdir=\"\$absdir\"
+"
+
+	if test "$fast_install" = yes; then
+	  $ECHO "\
+  program=lt-'$outputname'$exeext
+  progdir=\"\$thisdir/$objdir\"
+
+  if test ! -f \"\$progdir/\$program\" ||
+     { file=\`ls -1dt \"\$progdir/\$program\" \"\$progdir/../\$program\" 2>/dev/null | ${SED} 1q\`; \\
+       test \"X\$file\" != \"X\$progdir/\$program\"; }; then
+
+    file=\"\$\$-\$program\"
+
+    if test ! -d \"\$progdir\"; then
+      $MKDIR \"\$progdir\"
+    else
+      $RM \"\$progdir/\$file\"
+    fi"
+
+	  $ECHO "\
+
+    # relink executable if necessary
+    if test -n \"\$relink_command\"; then
+      if relink_command_output=\`eval \$relink_command 2>&1\`; then :
+      else
+	$ECHO \"\$relink_command_output\" >&2
+	$RM \"\$progdir/\$file\"
+	exit 1
+      fi
+    fi
+
+    $MV \"\$progdir/\$file\" \"\$progdir/\$program\" 2>/dev/null ||
+    { $RM \"\$progdir/\$program\";
+      $MV \"\$progdir/\$file\" \"\$progdir/\$program\"; }
+    $RM \"\$progdir/\$file\"
+  fi"
+	else
+	  $ECHO "\
+  program='$outputname'
+  progdir=\"\$thisdir/$objdir\"
+"
+	fi
+
+	$ECHO "\
+
+  if test -f \"\$progdir/\$program\"; then"
+
+	# Export our shlibpath_var if we have one.
+	if test "$shlibpath_overrides_runpath" = yes && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
+	  $ECHO "\
+    # Add our own library path to $shlibpath_var
+    $shlibpath_var=\"$temp_rpath\$$shlibpath_var\"
+
+    # Some systems cannot cope with colon-terminated $shlibpath_var
+    # The second colon is a workaround for a bug in BeOS R4 sed
+    $shlibpath_var=\`\$ECHO \"X\$$shlibpath_var\" | \$Xsed -e 's/::*\$//'\`
+
+    export $shlibpath_var
+"
+	fi
+
+	# fixup the dll searchpath if we need to.
+	if test -n "$dllsearchpath"; then
+	  $ECHO "\
+    # Add the dll search path components to the executable PATH
+    PATH=$dllsearchpath:\$PATH
+"
+	fi
+
+	$ECHO "\
+    if test \"\$libtool_execute_magic\" != \"$magic\"; then
+      # Run the actual program with our arguments.
+"
+	case $host in
+	# Backslashes separate directories on plain windows
+	*-*-mingw | *-*-os2* | *-cegcc*)
+	  $ECHO "\
+      exec \"\$progdir\\\\\$program\" \${1+\"\$@\"}
+"
+	  ;;
+
+	*)
+	  $ECHO "\
+      exec \"\$progdir/\$program\" \${1+\"\$@\"}
+"
+	  ;;
+	esac
+	$ECHO "\
+      \$ECHO \"\$0: cannot exec \$program \$*\" 1>&2
+      exit 1
+    fi
+  else
+    # The program doesn't exist.
+    \$ECHO \"\$0: error: \\\`\$progdir/\$program' does not exist\" 1>&2
+    \$ECHO \"This script is just a wrapper for \$program.\" 1>&2
+    $ECHO \"See the $PACKAGE documentation for more information.\" 1>&2
+    exit 1
+  fi
+fi\
+"
+}
+# end: func_emit_wrapper_part2
+
+
+# func_emit_wrapper [arg=no]
+#
+# Emit a libtool wrapper script on stdout.
+# Don't directly open a file because we may want to
+# incorporate the script contents within a cygwin/mingw
+# wrapper executable.  Must ONLY be called from within
+# func_mode_link because it depends on a number of variables
+# set therein.
+#
+# ARG is the value that the WRAPPER_SCRIPT_BELONGS_IN_OBJDIR
+# variable will take.  If 'yes', then the emitted script
+# will assume that the directory in which it is stored is
+# the $objdir directory.  This is a cygwin/mingw-specific
+# behavior.
+func_emit_wrapper ()
+{
+	func_emit_wrapper_arg1=no
+	if test -n "$1" ; then
+	  func_emit_wrapper_arg1=$1
+	fi
+
+	# split this up so that func_emit_cwrapperexe_src
+	# can call each part independently.
+	func_emit_wrapper_part1 "${func_emit_wrapper_arg1}"
+	func_emit_wrapper_part2 "${func_emit_wrapper_arg1}"
+}
+
+
+# func_to_host_path arg
+#
+# Convert paths to host format when used with build tools.
+# Intended for use with "native" mingw (where libtool itself
+# is running under the msys shell), or in the following cross-
+# build environments:
+#    $build          $host
+#    mingw (msys)    mingw  [e.g. native]
+#    cygwin          mingw
+#    *nix + wine     mingw
+# where wine is equipped with the `winepath' executable.
+# In the native mingw case, the (msys) shell automatically
+# converts paths for any non-msys applications it launches,
+# but that facility isn't available from inside the cwrapper.
+# Similar accommodations are necessary for $host mingw and
+# $build cygwin.  Calling this function does no harm for other
+# $host/$build combinations not listed above.
+#
+# ARG is the path (on $build) that should be converted to
+# the proper representation for $host. The result is stored
+# in $func_to_host_path_result.
+func_to_host_path ()
+{
+  func_to_host_path_result="$1"
+  if test -n "$1" ; then
+    case $host in
+      *mingw* )
+        lt_sed_naive_backslashify='s|\\\\*|\\|g;s|/|\\|g;s|\\|\\\\|g'
+        case $build in
+          *mingw* ) # actually, msys
+            # awkward: cmd appends spaces to result
+            lt_sed_strip_trailing_spaces="s/[ ]*\$//"
+            func_to_host_path_tmp1=`( cmd //c echo "$1" |\
+              $SED -e "$lt_sed_strip_trailing_spaces" ) 2>/dev/null || echo ""`
+            func_to_host_path_result=`echo "$func_to_host_path_tmp1" |\
+              $SED -e "$lt_sed_naive_backslashify"`
+            ;;
+          *cygwin* )
+            func_to_host_path_tmp1=`cygpath -w "$1"`
+            func_to_host_path_result=`echo "$func_to_host_path_tmp1" |\
+              $SED -e "$lt_sed_naive_backslashify"`
+            ;;
+          * )
+            # Unfortunately, winepath does not exit with a non-zero
+            # error code, so we are forced to check the contents of
+            # stdout. On the other hand, if the command is not
+            # found, the shell will set an exit code of 127 and print
+            # *an error message* to stdout. So we must check for both
+            # error code of zero AND non-empty stdout, which explains
+            # the odd construction:
+            func_to_host_path_tmp1=`winepath -w "$1" 2>/dev/null`
+            if test "$?" -eq 0 && test -n "${func_to_host_path_tmp1}"; then
+              func_to_host_path_result=`echo "$func_to_host_path_tmp1" |\
+                $SED -e "$lt_sed_naive_backslashify"`
+            else
+              # Allow warning below.
+              func_to_host_path_result=""
+            fi
+            ;;
+        esac
+        if test -z "$func_to_host_path_result" ; then
+          func_error "Could not determine host path corresponding to"
+          func_error "  '$1'"
+          func_error "Continuing, but uninstalled executables may not work."
+          # Fallback:
+          func_to_host_path_result="$1"
+        fi
+        ;;
+    esac
+  fi
+}
+# end: func_to_host_path
+
+# func_to_host_pathlist arg
+#
+# Convert pathlists to host format when used with build tools.
+# See func_to_host_path(), above. This function supports the
+# following $build/$host combinations (but does no harm for
+# combinations not listed here):
+#    $build          $host
+#    mingw (msys)    mingw  [e.g. native]
+#    cygwin          mingw
+#    *nix + wine     mingw
+#
+# Path separators are also converted from $build format to
+# $host format. If ARG begins or ends with a path separator
+# character, it is preserved (but converted to $host format)
+# on output.
+#
+# ARG is a pathlist (on $build) that should be converted to
+# the proper representation on $host. The result is stored
+# in $func_to_host_pathlist_result.
+func_to_host_pathlist ()
+{
+  func_to_host_pathlist_result="$1"
+  if test -n "$1" ; then
+    case $host in
+      *mingw* )
+        lt_sed_naive_backslashify='s|\\\\*|\\|g;s|/|\\|g;s|\\|\\\\|g'
+        # Remove leading and trailing path separator characters from
+        # ARG. msys behavior is inconsistent here, cygpath turns them
+        # into '.;' and ';.', and winepath ignores them completely.
+        func_to_host_pathlist_tmp2="$1"
+        # Once set for this call, this variable should not be
+        # reassigned. It is used in tha fallback case.
+        func_to_host_pathlist_tmp1=`echo "$func_to_host_pathlist_tmp2" |\
+          $SED -e 's|^:*||' -e 's|:*$||'`
+        case $build in
+          *mingw* ) # Actually, msys.
+            # Awkward: cmd appends spaces to result.
+            lt_sed_strip_trailing_spaces="s/[ ]*\$//"
+            func_to_host_pathlist_tmp2=`( cmd //c echo "$func_to_host_pathlist_tmp1" |\
+              $SED -e "$lt_sed_strip_trailing_spaces" ) 2>/dev/null || echo ""`
+            func_to_host_pathlist_result=`echo "$func_to_host_pathlist_tmp2" |\
+              $SED -e "$lt_sed_naive_backslashify"`
+            ;;
+          *cygwin* )
+            func_to_host_pathlist_tmp2=`cygpath -w -p "$func_to_host_pathlist_tmp1"`
+            func_to_host_pathlist_result=`echo "$func_to_host_pathlist_tmp2" |\
+              $SED -e "$lt_sed_naive_backslashify"`
+            ;;
+          * )
+            # unfortunately, winepath doesn't convert pathlists
+            func_to_host_pathlist_result=""
+            func_to_host_pathlist_oldIFS=$IFS
+            IFS=:
+            for func_to_host_pathlist_f in $func_to_host_pathlist_tmp1 ; do
+              IFS=$func_to_host_pathlist_oldIFS
+              if test -n "$func_to_host_pathlist_f" ; then
+                func_to_host_path "$func_to_host_pathlist_f"
+                if test -n "$func_to_host_path_result" ; then
+                  if test -z "$func_to_host_pathlist_result" ; then
+                    func_to_host_pathlist_result="$func_to_host_path_result"
+                  else
+                    func_to_host_pathlist_result="$func_to_host_pathlist_result;$func_to_host_path_result"
+                  fi
+                fi
+              fi
+              IFS=:
+            done
+            IFS=$func_to_host_pathlist_oldIFS
+            ;;
+        esac
+        if test -z "$func_to_host_pathlist_result" ; then
+          func_error "Could not determine the host path(s) corresponding to"
+          func_error "  '$1'"
+          func_error "Continuing, but uninstalled executables may not work."
+          # Fallback. This may break if $1 contains DOS-style drive
+          # specifications. The fix is not to complicate the expression
+          # below, but for the user to provide a working wine installation
+          # with winepath so that path translation in the cross-to-mingw
+          # case works properly.
+          lt_replace_pathsep_nix_to_dos="s|:|;|g"
+          func_to_host_pathlist_result=`echo "$func_to_host_pathlist_tmp1" |\
+            $SED -e "$lt_replace_pathsep_nix_to_dos"`
+        fi
+        # Now, add the leading and trailing path separators back
+        case "$1" in
+          :* ) func_to_host_pathlist_result=";$func_to_host_pathlist_result"
+            ;;
+        esac
+        case "$1" in
+          *: ) func_to_host_pathlist_result="$func_to_host_pathlist_result;"
+            ;;
+        esac
+        ;;
+    esac
+  fi
+}
+# end: func_to_host_pathlist
+
+# func_emit_cwrapperexe_src
+# emit the source code for a wrapper executable on stdout
+# Must ONLY be called from within func_mode_link because
+# it depends on a number of variable set therein.
+func_emit_cwrapperexe_src ()
+{
+	cat <<EOF
+
+/* $cwrappersource - temporary wrapper executable for $objdir/$outputname
+   Generated by $PROGRAM (GNU $PACKAGE$TIMESTAMP) $VERSION
+
+   The $output program cannot be directly executed until all the libtool
+   libraries that it depends on are installed.
+
+   This wrapper executable should never be moved out of the build directory.
+   If it is, it will not operate correctly.
+
+   Currently, it simply execs the wrapper *script* "$SHELL $output",
+   but could eventually absorb all of the scripts functionality and
+   exec $objdir/$outputname directly.
+*/
+EOF
+	    cat <<"EOF"
+#include <stdio.h>
+#include <stdlib.h>
+#ifdef _MSC_VER
+# include <direct.h>
+# include <process.h>
+# include <io.h>
+# define setmode _setmode
+#else
+# include <unistd.h>
+# include <stdint.h>
+# ifdef __CYGWIN__
+#  include <io.h>
+#  define HAVE_SETENV
+#  ifdef __STRICT_ANSI__
+char *realpath (const char *, char *);
+int putenv (char *);
+int setenv (const char *, const char *, int);
+#  endif
+# endif
+#endif
+#include <malloc.h>
+#include <stdarg.h>
+#include <assert.h>
+#include <string.h>
+#include <ctype.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+
+#if defined(PATH_MAX)
+# define LT_PATHMAX PATH_MAX
+#elif defined(MAXPATHLEN)
+# define LT_PATHMAX MAXPATHLEN
+#else
+# define LT_PATHMAX 1024
+#endif
+
+#ifndef S_IXOTH
+# define S_IXOTH 0
+#endif
+#ifndef S_IXGRP
+# define S_IXGRP 0
+#endif
+
+#ifdef _MSC_VER
+# define S_IXUSR _S_IEXEC
+# define stat _stat
+# ifndef _INTPTR_T_DEFINED
+#  define intptr_t int
+# endif
+#endif
+
+#ifndef DIR_SEPARATOR
+# define DIR_SEPARATOR '/'
+# define PATH_SEPARATOR ':'
+#endif
+
+#if defined (_WIN32) || defined (__MSDOS__) || defined (__DJGPP__) || \
+  defined (__OS2__)
+# define HAVE_DOS_BASED_FILE_SYSTEM
+# define FOPEN_WB "wb"
+# ifndef DIR_SEPARATOR_2
+#  define DIR_SEPARATOR_2 '\\'
+# endif
+# ifndef PATH_SEPARATOR_2
+#  define PATH_SEPARATOR_2 ';'
+# endif
+#endif
+
+#ifndef DIR_SEPARATOR_2
+# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
+#else /* DIR_SEPARATOR_2 */
+# define IS_DIR_SEPARATOR(ch) \
+	(((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
+#endif /* DIR_SEPARATOR_2 */
+
+#ifndef PATH_SEPARATOR_2
+# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR)
+#else /* PATH_SEPARATOR_2 */
+# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR_2)
+#endif /* PATH_SEPARATOR_2 */
+
+#ifdef __CYGWIN__
+# define FOPEN_WB "wb"
+#endif
+
+#ifndef FOPEN_WB
+# define FOPEN_WB "w"
+#endif
+#ifndef _O_BINARY
+# define _O_BINARY 0
+#endif
+
+#define XMALLOC(type, num)      ((type *) xmalloc ((num) * sizeof(type)))
+#define XFREE(stale) do { \
+  if (stale) { free ((void *) stale); stale = 0; } \
+} while (0)
+
+#undef LTWRAPPER_DEBUGPRINTF
+#if defined DEBUGWRAPPER
+# define LTWRAPPER_DEBUGPRINTF(args) ltwrapper_debugprintf args
+static void
+ltwrapper_debugprintf (const char *fmt, ...)
+{
+    va_list args;
+    va_start (args, fmt);
+    (void) vfprintf (stderr, fmt, args);
+    va_end (args);
+}
+#else
+# define LTWRAPPER_DEBUGPRINTF(args)
+#endif
+
+const char *program_name = NULL;
+
+void *xmalloc (size_t num);
+char *xstrdup (const char *string);
+const char *base_name (const char *name);
+char *find_executable (const char *wrapper);
+char *chase_symlinks (const char *pathspec);
+int make_executable (const char *path);
+int check_executable (const char *path);
+char *strendzap (char *str, const char *pat);
+void lt_fatal (const char *message, ...);
+void lt_setenv (const char *name, const char *value);
+char *lt_extend_str (const char *orig_value, const char *add, int to_end);
+void lt_opt_process_env_set (const char *arg);
+void lt_opt_process_env_prepend (const char *arg);
+void lt_opt_process_env_append (const char *arg);
+int lt_split_name_value (const char *arg, char** name, char** value);
+void lt_update_exe_path (const char *name, const char *value);
+void lt_update_lib_path (const char *name, const char *value);
+
+static const char *script_text_part1 =
+EOF
+
+	    func_emit_wrapper_part1 yes |
+	        $SED -e 's/\([\\"]\)/\\\1/g' \
+	             -e 's/^/  "/' -e 's/$/\\n"/'
+	    echo ";"
+	    cat <<EOF
+
+static const char *script_text_part2 =
+EOF
+	    func_emit_wrapper_part2 yes |
+	        $SED -e 's/\([\\"]\)/\\\1/g' \
+	             -e 's/^/  "/' -e 's/$/\\n"/'
+	    echo ";"
+
+	    cat <<EOF
+const char * MAGIC_EXE = "$magic_exe";
+const char * LIB_PATH_VARNAME = "$shlibpath_var";
+EOF
+
+	    if test "$shlibpath_overrides_runpath" = yes && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
+              func_to_host_pathlist "$temp_rpath"
+	      cat <<EOF
+const char * LIB_PATH_VALUE   = "$func_to_host_pathlist_result";
+EOF
+	    else
+	      cat <<"EOF"
+const char * LIB_PATH_VALUE   = "";
+EOF
+	    fi
+
+	    if test -n "$dllsearchpath"; then
+              func_to_host_pathlist "$dllsearchpath:"
+	      cat <<EOF
+const char * EXE_PATH_VARNAME = "PATH";
+const char * EXE_PATH_VALUE   = "$func_to_host_pathlist_result";
+EOF
+	    else
+	      cat <<"EOF"
+const char * EXE_PATH_VARNAME = "";
+const char * EXE_PATH_VALUE   = "";
+EOF
+	    fi
+
+	    if test "$fast_install" = yes; then
+	      cat <<EOF
+const char * TARGET_PROGRAM_NAME = "lt-$outputname"; /* hopefully, no .exe */
+EOF
+	    else
+	      cat <<EOF
+const char * TARGET_PROGRAM_NAME = "$outputname"; /* hopefully, no .exe */
+EOF
+	    fi
+
+
+	    cat <<"EOF"
+
+#define LTWRAPPER_OPTION_PREFIX         "--lt-"
+#define LTWRAPPER_OPTION_PREFIX_LENGTH  5
+
+static const size_t opt_prefix_len         = LTWRAPPER_OPTION_PREFIX_LENGTH;
+static const char *ltwrapper_option_prefix = LTWRAPPER_OPTION_PREFIX;
+
+static const char *dumpscript_opt       = LTWRAPPER_OPTION_PREFIX "dump-script";
+
+static const size_t env_set_opt_len     = LTWRAPPER_OPTION_PREFIX_LENGTH + 7;
+static const char *env_set_opt          = LTWRAPPER_OPTION_PREFIX "env-set";
+  /* argument is putenv-style "foo=bar", value of foo is set to bar */
+
+static const size_t env_prepend_opt_len = LTWRAPPER_OPTION_PREFIX_LENGTH + 11;
+static const char *env_prepend_opt      = LTWRAPPER_OPTION_PREFIX "env-prepend";
+  /* argument is putenv-style "foo=bar", new value of foo is bar${foo} */
+
+static const size_t env_append_opt_len  = LTWRAPPER_OPTION_PREFIX_LENGTH + 10;
+static const char *env_append_opt       = LTWRAPPER_OPTION_PREFIX "env-append";
+  /* argument is putenv-style "foo=bar", new value of foo is ${foo}bar */
+
+int
+main (int argc, char *argv[])
+{
+  char **newargz;
+  int  newargc;
+  char *tmp_pathspec;
+  char *actual_cwrapper_path;
+  char *actual_cwrapper_name;
+  char *target_name;
+  char *lt_argv_zero;
+  intptr_t rval = 127;
+
+  int i;
+
+  program_name = (char *) xstrdup (base_name (argv[0]));
+  LTWRAPPER_DEBUGPRINTF (("(main) argv[0]      : %s\n", argv[0]));
+  LTWRAPPER_DEBUGPRINTF (("(main) program_name : %s\n", program_name));
+
+  /* very simple arg parsing; don't want to rely on getopt */
+  for (i = 1; i < argc; i++)
+    {
+      if (strcmp (argv[i], dumpscript_opt) == 0)
+	{
+EOF
+	    case "$host" in
+	      *mingw* | *cygwin* )
+		# make stdout use "unix" line endings
+		echo "          setmode(1,_O_BINARY);"
+		;;
+	      esac
+
+	    cat <<"EOF"
+	  printf ("%s", script_text_part1);
+	  printf ("%s", script_text_part2);
+	  return 0;
+	}
+    }
+
+  newargz = XMALLOC (char *, argc + 1);
+  tmp_pathspec = find_executable (argv[0]);
+  if (tmp_pathspec == NULL)
+    lt_fatal ("Couldn't find %s", argv[0]);
+  LTWRAPPER_DEBUGPRINTF (("(main) found exe (before symlink chase) at : %s\n",
+			  tmp_pathspec));
+
+  actual_cwrapper_path = chase_symlinks (tmp_pathspec);
+  LTWRAPPER_DEBUGPRINTF (("(main) found exe (after symlink chase) at : %s\n",
+			  actual_cwrapper_path));
+  XFREE (tmp_pathspec);
+
+  actual_cwrapper_name = xstrdup( base_name (actual_cwrapper_path));
+  strendzap (actual_cwrapper_path, actual_cwrapper_name);
+
+  /* wrapper name transforms */
+  strendzap (actual_cwrapper_name, ".exe");
+  tmp_pathspec = lt_extend_str (actual_cwrapper_name, ".exe", 1);
+  XFREE (actual_cwrapper_name);
+  actual_cwrapper_name = tmp_pathspec;
+  tmp_pathspec = 0;
+
+  /* target_name transforms -- use actual target program name; might have lt- prefix */
+  target_name = xstrdup (base_name (TARGET_PROGRAM_NAME));
+  strendzap (target_name, ".exe");
+  tmp_pathspec = lt_extend_str (target_name, ".exe", 1);
+  XFREE (target_name);
+  target_name = tmp_pathspec;
+  tmp_pathspec = 0;
+
+  LTWRAPPER_DEBUGPRINTF (("(main) libtool target name: %s\n",
+			  target_name));
+EOF
+
+	    cat <<EOF
+  newargz[0] =
+    XMALLOC (char, (strlen (actual_cwrapper_path) +
+		    strlen ("$objdir") + 1 + strlen (actual_cwrapper_name) + 1));
+  strcpy (newargz[0], actual_cwrapper_path);
+  strcat (newargz[0], "$objdir");
+  strcat (newargz[0], "/");
+EOF
+
+	    cat <<"EOF"
+  /* stop here, and copy so we don't have to do this twice */
+  tmp_pathspec = xstrdup (newargz[0]);
+
+  /* do NOT want the lt- prefix here, so use actual_cwrapper_name */
+  strcat (newargz[0], actual_cwrapper_name);
+
+  /* DO want the lt- prefix here if it exists, so use target_name */
+  lt_argv_zero = lt_extend_str (tmp_pathspec, target_name, 1);
+  XFREE (tmp_pathspec);
+  tmp_pathspec = NULL;
+EOF
+
+	    case $host_os in
+	      mingw*)
+	    cat <<"EOF"
+  {
+    char* p;
+    while ((p = strchr (newargz[0], '\\')) != NULL)
+      {
+	*p = '/';
+      }
+    while ((p = strchr (lt_argv_zero, '\\')) != NULL)
+      {
+	*p = '/';
+      }
+  }
+EOF
+	    ;;
+	    esac
+
+	    cat <<"EOF"
+  XFREE (target_name);
+  XFREE (actual_cwrapper_path);
+  XFREE (actual_cwrapper_name);
+
+  lt_setenv ("BIN_SH", "xpg4"); /* for Tru64 */
+  lt_setenv ("DUALCASE", "1");  /* for MSK sh */
+  lt_update_lib_path (LIB_PATH_VARNAME, LIB_PATH_VALUE);
+  lt_update_exe_path (EXE_PATH_VARNAME, EXE_PATH_VALUE);
+
+  newargc=0;
+  for (i = 1; i < argc; i++)
+    {
+      if (strncmp (argv[i], env_set_opt, env_set_opt_len) == 0)
+        {
+          if (argv[i][env_set_opt_len] == '=')
+            {
+              const char *p = argv[i] + env_set_opt_len + 1;
+              lt_opt_process_env_set (p);
+            }
+          else if (argv[i][env_set_opt_len] == '\0' && i + 1 < argc)
+            {
+              lt_opt_process_env_set (argv[++i]); /* don't copy */
+            }
+          else
+            lt_fatal ("%s missing required argument", env_set_opt);
+          continue;
+        }
+      if (strncmp (argv[i], env_prepend_opt, env_prepend_opt_len) == 0)
+        {
+          if (argv[i][env_prepend_opt_len] == '=')
+            {
+              const char *p = argv[i] + env_prepend_opt_len + 1;
+              lt_opt_process_env_prepend (p);
+            }
+          else if (argv[i][env_prepend_opt_len] == '\0' && i + 1 < argc)
+            {
+              lt_opt_process_env_prepend (argv[++i]); /* don't copy */
+            }
+          else
+            lt_fatal ("%s missing required argument", env_prepend_opt);
+          continue;
+        }
+      if (strncmp (argv[i], env_append_opt, env_append_opt_len) == 0)
+        {
+          if (argv[i][env_append_opt_len] == '=')
+            {
+              const char *p = argv[i] + env_append_opt_len + 1;
+              lt_opt_process_env_append (p);
+            }
+          else if (argv[i][env_append_opt_len] == '\0' && i + 1 < argc)
+            {
+              lt_opt_process_env_append (argv[++i]); /* don't copy */
+            }
+          else
+            lt_fatal ("%s missing required argument", env_append_opt);
+          continue;
+        }
+      if (strncmp (argv[i], ltwrapper_option_prefix, opt_prefix_len) == 0)
+        {
+          /* however, if there is an option in the LTWRAPPER_OPTION_PREFIX
+             namespace, but it is not one of the ones we know about and
+             have already dealt with, above (inluding dump-script), then
+             report an error. Otherwise, targets might begin to believe
+             they are allowed to use options in the LTWRAPPER_OPTION_PREFIX
+             namespace. The first time any user complains about this, we'll
+             need to make LTWRAPPER_OPTION_PREFIX a configure-time option
+             or a configure.ac-settable value.
+           */
+          lt_fatal ("Unrecognized option in %s namespace: '%s'",
+                    ltwrapper_option_prefix, argv[i]);
+        }
+      /* otherwise ... */
+      newargz[++newargc] = xstrdup (argv[i]);
+    }
+  newargz[++newargc] = NULL;
+
+  LTWRAPPER_DEBUGPRINTF     (("(main) lt_argv_zero : %s\n", (lt_argv_zero ? lt_argv_zero : "<NULL>")));
+  for (i = 0; i < newargc; i++)
+    {
+      LTWRAPPER_DEBUGPRINTF (("(main) newargz[%d]   : %s\n", i, (newargz[i] ? newargz[i] : "<NULL>")));
+    }
+
+EOF
+
+	    case $host_os in
+	      mingw*)
+		cat <<"EOF"
+  /* execv doesn't actually work on mingw as expected on unix */
+  rval = _spawnv (_P_WAIT, lt_argv_zero, (const char * const *) newargz);
+  if (rval == -1)
+    {
+      /* failed to start process */
+      LTWRAPPER_DEBUGPRINTF (("(main) failed to launch target \"%s\": errno = %d\n", lt_argv_zero, errno));
+      return 127;
+    }
+  return rval;
+EOF
+		;;
+	      *)
+		cat <<"EOF"
+  execv (lt_argv_zero, newargz);
+  return rval; /* =127, but avoids unused variable warning */
+EOF
+		;;
+	    esac
+
+	    cat <<"EOF"
+}
+
+void *
+xmalloc (size_t num)
+{
+  void *p = (void *) malloc (num);
+  if (!p)
+    lt_fatal ("Memory exhausted");
+
+  return p;
+}
+
+char *
+xstrdup (const char *string)
+{
+  return string ? strcpy ((char *) xmalloc (strlen (string) + 1),
+			  string) : NULL;
+}
+
+const char *
+base_name (const char *name)
+{
+  const char *base;
+
+#if defined (HAVE_DOS_BASED_FILE_SYSTEM)
+  /* Skip over the disk name in MSDOS pathnames. */
+  if (isalpha ((unsigned char) name[0]) && name[1] == ':')
+    name += 2;
+#endif
+
+  for (base = name; *name; name++)
+    if (IS_DIR_SEPARATOR (*name))
+      base = name + 1;
+  return base;
+}
+
+int
+check_executable (const char *path)
+{
+  struct stat st;
+
+  LTWRAPPER_DEBUGPRINTF (("(check_executable)  : %s\n",
+			  path ? (*path ? path : "EMPTY!") : "NULL!"));
+  if ((!path) || (!*path))
+    return 0;
+
+  if ((stat (path, &st) >= 0)
+      && (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)))
+    return 1;
+  else
+    return 0;
+}
+
+int
+make_executable (const char *path)
+{
+  int rval = 0;
+  struct stat st;
+
+  LTWRAPPER_DEBUGPRINTF (("(make_executable)   : %s\n",
+			  path ? (*path ? path : "EMPTY!") : "NULL!"));
+  if ((!path) || (!*path))
+    return 0;
+
+  if (stat (path, &st) >= 0)
+    {
+      rval = chmod (path, st.st_mode | S_IXOTH | S_IXGRP | S_IXUSR);
+    }
+  return rval;
+}
+
+/* Searches for the full path of the wrapper.  Returns
+   newly allocated full path name if found, NULL otherwise
+   Does not chase symlinks, even on platforms that support them.
+*/
+char *
+find_executable (const char *wrapper)
+{
+  int has_slash = 0;
+  const char *p;
+  const char *p_next;
+  /* static buffer for getcwd */
+  char tmp[LT_PATHMAX + 1];
+  int tmp_len;
+  char *concat_name;
+
+  LTWRAPPER_DEBUGPRINTF (("(find_executable)   : %s\n",
+			  wrapper ? (*wrapper ? wrapper : "EMPTY!") : "NULL!"));
+
+  if ((wrapper == NULL) || (*wrapper == '\0'))
+    return NULL;
+
+  /* Absolute path? */
+#if defined (HAVE_DOS_BASED_FILE_SYSTEM)
+  if (isalpha ((unsigned char) wrapper[0]) && wrapper[1] == ':')
+    {
+      concat_name = xstrdup (wrapper);
+      if (check_executable (concat_name))
+	return concat_name;
+      XFREE (concat_name);
+    }
+  else
+    {
+#endif
+      if (IS_DIR_SEPARATOR (wrapper[0]))
+	{
+	  concat_name = xstrdup (wrapper);
+	  if (check_executable (concat_name))
+	    return concat_name;
+	  XFREE (concat_name);
+	}
+#if defined (HAVE_DOS_BASED_FILE_SYSTEM)
+    }
+#endif
+
+  for (p = wrapper; *p; p++)
+    if (*p == '/')
+      {
+	has_slash = 1;
+	break;
+      }
+  if (!has_slash)
+    {
+      /* no slashes; search PATH */
+      const char *path = getenv ("PATH");
+      if (path != NULL)
+	{
+	  for (p = path; *p; p = p_next)
+	    {
+	      const char *q;
+	      size_t p_len;
+	      for (q = p; *q; q++)
+		if (IS_PATH_SEPARATOR (*q))
+		  break;
+	      p_len = q - p;
+	      p_next = (*q == '\0' ? q : q + 1);
+	      if (p_len == 0)
+		{
+		  /* empty path: current directory */
+		  if (getcwd (tmp, LT_PATHMAX) == NULL)
+		    lt_fatal ("getcwd failed");
+		  tmp_len = strlen (tmp);
+		  concat_name =
+		    XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
+		  memcpy (concat_name, tmp, tmp_len);
+		  concat_name[tmp_len] = '/';
+		  strcpy (concat_name + tmp_len + 1, wrapper);
+		}
+	      else
+		{
+		  concat_name =
+		    XMALLOC (char, p_len + 1 + strlen (wrapper) + 1);
+		  memcpy (concat_name, p, p_len);
+		  concat_name[p_len] = '/';
+		  strcpy (concat_name + p_len + 1, wrapper);
+		}
+	      if (check_executable (concat_name))
+		return concat_name;
+	      XFREE (concat_name);
+	    }
+	}
+      /* not found in PATH; assume curdir */
+    }
+  /* Relative path | not found in path: prepend cwd */
+  if (getcwd (tmp, LT_PATHMAX) == NULL)
+    lt_fatal ("getcwd failed");
+  tmp_len = strlen (tmp);
+  concat_name = XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
+  memcpy (concat_name, tmp, tmp_len);
+  concat_name[tmp_len] = '/';
+  strcpy (concat_name + tmp_len + 1, wrapper);
+
+  if (check_executable (concat_name))
+    return concat_name;
+  XFREE (concat_name);
+  return NULL;
+}
+
+char *
+chase_symlinks (const char *pathspec)
+{
+#ifndef S_ISLNK
+  return xstrdup (pathspec);
+#else
+  char buf[LT_PATHMAX];
+  struct stat s;
+  char *tmp_pathspec = xstrdup (pathspec);
+  char *p;
+  int has_symlinks = 0;
+  while (strlen (tmp_pathspec) && !has_symlinks)
+    {
+      LTWRAPPER_DEBUGPRINTF (("checking path component for symlinks: %s\n",
+			      tmp_pathspec));
+      if (lstat (tmp_pathspec, &s) == 0)
+	{
+	  if (S_ISLNK (s.st_mode) != 0)
+	    {
+	      has_symlinks = 1;
+	      break;
+	    }
+
+	  /* search backwards for last DIR_SEPARATOR */
+	  p = tmp_pathspec + strlen (tmp_pathspec) - 1;
+	  while ((p > tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
+	    p--;
+	  if ((p == tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
+	    {
+	      /* no more DIR_SEPARATORS left */
+	      break;
+	    }
+	  *p = '\0';
+	}
+      else
+	{
+	  char *errstr = strerror (errno);
+	  lt_fatal ("Error accessing file %s (%s)", tmp_pathspec, errstr);
+	}
+    }
+  XFREE (tmp_pathspec);
+
+  if (!has_symlinks)
+    {
+      return xstrdup (pathspec);
+    }
+
+  tmp_pathspec = realpath (pathspec, buf);
+  if (tmp_pathspec == 0)
+    {
+      lt_fatal ("Could not follow symlinks for %s", pathspec);
+    }
+  return xstrdup (tmp_pathspec);
+#endif
+}
+
+char *
+strendzap (char *str, const char *pat)
+{
+  size_t len, patlen;
+
+  assert (str != NULL);
+  assert (pat != NULL);
+
+  len = strlen (str);
+  patlen = strlen (pat);
+
+  if (patlen <= len)
+    {
+      str += len - patlen;
+      if (strcmp (str, pat) == 0)
+	*str = '\0';
+    }
+  return str;
+}
+
+static void
+lt_error_core (int exit_status, const char *mode,
+	       const char *message, va_list ap)
+{
+  fprintf (stderr, "%s: %s: ", program_name, mode);
+  vfprintf (stderr, message, ap);
+  fprintf (stderr, ".\n");
+
+  if (exit_status >= 0)
+    exit (exit_status);
+}
+
+void
+lt_fatal (const char *message, ...)
+{
+  va_list ap;
+  va_start (ap, message);
+  lt_error_core (EXIT_FAILURE, "FATAL", message, ap);
+  va_end (ap);
+}
+
+void
+lt_setenv (const char *name, const char *value)
+{
+  LTWRAPPER_DEBUGPRINTF (("(lt_setenv) setting '%s' to '%s'\n",
+                          (name ? name : "<NULL>"),
+                          (value ? value : "<NULL>")));
+  {
+#ifdef HAVE_SETENV
+    /* always make a copy, for consistency with !HAVE_SETENV */
+    char *str = xstrdup (value);
+    setenv (name, str, 1);
+#else
+    int len = strlen (name) + 1 + strlen (value) + 1;
+    char *str = XMALLOC (char, len);
+    sprintf (str, "%s=%s", name, value);
+    if (putenv (str) != EXIT_SUCCESS)
+      {
+        XFREE (str);
+      }
+#endif
+  }
+}
+
+char *
+lt_extend_str (const char *orig_value, const char *add, int to_end)
+{
+  char *new_value;
+  if (orig_value && *orig_value)
+    {
+      int orig_value_len = strlen (orig_value);
+      int add_len = strlen (add);
+      new_value = XMALLOC (char, add_len + orig_value_len + 1);
+      if (to_end)
+        {
+          strcpy (new_value, orig_value);
+          strcpy (new_value + orig_value_len, add);
+        }
+      else
+        {
+          strcpy (new_value, add);
+          strcpy (new_value + add_len, orig_value);
+        }
+    }
+  else
+    {
+      new_value = xstrdup (add);
+    }
+  return new_value;
+}
+
+int
+lt_split_name_value (const char *arg, char** name, char** value)
+{
+  const char *p;
+  int len;
+  if (!arg || !*arg)
+    return 1;
+
+  p = strchr (arg, (int)'=');
+
+  if (!p)
+    return 1;
+
+  *value = xstrdup (++p);
+
+  len = strlen (arg) - strlen (*value);
+  *name = XMALLOC (char, len);
+  strncpy (*name, arg, len-1);
+  (*name)[len - 1] = '\0';
+
+  return 0;
+}
+
+void
+lt_opt_process_env_set (const char *arg)
+{
+  char *name = NULL;
+  char *value = NULL;
+
+  if (lt_split_name_value (arg, &name, &value) != 0)
+    {
+      XFREE (name);
+      XFREE (value);
+      lt_fatal ("bad argument for %s: '%s'", env_set_opt, arg);
+    }
+
+  lt_setenv (name, value);
+  XFREE (name);
+  XFREE (value);
+}
+
+void
+lt_opt_process_env_prepend (const char *arg)
+{
+  char *name = NULL;
+  char *value = NULL;
+  char *new_value = NULL;
+
+  if (lt_split_name_value (arg, &name, &value) != 0)
+    {
+      XFREE (name);
+      XFREE (value);
+      lt_fatal ("bad argument for %s: '%s'", env_prepend_opt, arg);
+    }
+
+  new_value = lt_extend_str (getenv (name), value, 0);
+  lt_setenv (name, new_value);
+  XFREE (new_value);
+  XFREE (name);
+  XFREE (value);
+}
+
+void
+lt_opt_process_env_append (const char *arg)
+{
+  char *name = NULL;
+  char *value = NULL;
+  char *new_value = NULL;
+
+  if (lt_split_name_value (arg, &name, &value) != 0)
+    {
+      XFREE (name);
+      XFREE (value);
+      lt_fatal ("bad argument for %s: '%s'", env_append_opt, arg);
+    }
+
+  new_value = lt_extend_str (getenv (name), value, 1);
+  lt_setenv (name, new_value);
+  XFREE (new_value);
+  XFREE (name);
+  XFREE (value);
+}
+
+void
+lt_update_exe_path (const char *name, const char *value)
+{
+  LTWRAPPER_DEBUGPRINTF (("(lt_update_exe_path) modifying '%s' by prepending '%s'\n",
+                          (name ? name : "<NULL>"),
+                          (value ? value : "<NULL>")));
+
+  if (name && *name && value && *value)
+    {
+      char *new_value = lt_extend_str (getenv (name), value, 0);
+      /* some systems can't cope with a ':'-terminated path #' */
+      int len = strlen (new_value);
+      while (((len = strlen (new_value)) > 0) && IS_PATH_SEPARATOR (new_value[len-1]))
+        {
+          new_value[len-1] = '\0';
+        }
+      lt_setenv (name, new_value);
+      XFREE (new_value);
+    }
+}
+
+void
+lt_update_lib_path (const char *name, const char *value)
+{
+  LTWRAPPER_DEBUGPRINTF (("(lt_update_lib_path) modifying '%s' by prepending '%s'\n",
+                          (name ? name : "<NULL>"),
+                          (value ? value : "<NULL>")));
+
+  if (name && *name && value && *value)
+    {
+      char *new_value = lt_extend_str (getenv (name), value, 0);
+      lt_setenv (name, new_value);
+      XFREE (new_value);
+    }
+}
+
+
+EOF
+}
+# end: func_emit_cwrapperexe_src
+
+# func_mode_link arg...
+func_mode_link ()
+{
+    $opt_debug
+    case $host in
+    *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
+      # It is impossible to link a dll without this setting, and
+      # we shouldn't force the makefile maintainer to figure out
+      # which system we are compiling for in order to pass an extra
+      # flag for every libtool invocation.
+      # allow_undefined=no
+
+      # FIXME: Unfortunately, there are problems with the above when trying
+      # to make a dll which has undefined symbols, in which case not
+      # even a static library is built.  For now, we need to specify
+      # -no-undefined on the libtool link line when we can be certain
+      # that all symbols are satisfied, otherwise we get a static library.
+      allow_undefined=yes
+      ;;
+    *)
+      allow_undefined=yes
+      ;;
+    esac
+    libtool_args=$nonopt
+    base_compile="$nonopt $@"
+    compile_command=$nonopt
+    finalize_command=$nonopt
+
+    compile_rpath=
+    finalize_rpath=
+    compile_shlibpath=
+    finalize_shlibpath=
+    convenience=
+    old_convenience=
+    deplibs=
+    old_deplibs=
+    compiler_flags=
+    linker_flags=
+    dllsearchpath=
+    lib_search_path=`pwd`
+    inst_prefix_dir=
+    new_inherited_linker_flags=
+
+    avoid_version=no
+    dlfiles=
+    dlprefiles=
+    dlself=no
+    export_dynamic=no
+    export_symbols=
+    export_symbols_regex=
+    generated=
+    libobjs=
+    ltlibs=
+    module=no
+    no_install=no
+    objs=
+    non_pic_objects=
+    precious_files_regex=
+    prefer_static_libs=no
+    preload=no
+    prev=
+    prevarg=
+    release=
+    rpath=
+    xrpath=
+    perm_rpath=
+    temp_rpath=
+    thread_safe=no
+    vinfo=
+    vinfo_number=no
+    weak_libs=
+    single_module="${wl}-single_module"
+    func_infer_tag $base_compile
+
+    # We need to know -static, to get the right output filenames.
+    for arg
+    do
+      case $arg in
+      -shared)
+	test "$build_libtool_libs" != yes && \
+	  func_fatal_configuration "can not build a shared library"
+	build_old_libs=no
+	break
+	;;
+      -all-static | -static | -static-libtool-libs)
+	case $arg in
+	-all-static)
+	  if test "$build_libtool_libs" = yes && test -z "$link_static_flag"; then
+	    func_warning "complete static linking is impossible in this configuration"
+	  fi
+	  if test -n "$link_static_flag"; then
+	    dlopen_self=$dlopen_self_static
+	  fi
+	  prefer_static_libs=yes
+	  ;;
+	-static)
+	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
+	    dlopen_self=$dlopen_self_static
+	  fi
+	  prefer_static_libs=built
+	  ;;
+	-static-libtool-libs)
+	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
+	    dlopen_self=$dlopen_self_static
+	  fi
+	  prefer_static_libs=yes
+	  ;;
+	esac
+	build_libtool_libs=no
+	build_old_libs=yes
+	break
+	;;
+      esac
+    done
+
+    # See if our shared archives depend on static archives.
+    test -n "$old_archive_from_new_cmds" && build_old_libs=yes
+
+    # Go through the arguments, transforming them on the way.
+    while test "$#" -gt 0; do
+      arg="$1"
+      shift
+      func_quote_for_eval "$arg"
+      qarg=$func_quote_for_eval_unquoted_result
+      func_append libtool_args " $func_quote_for_eval_result"
+
+      # If the previous option needs an argument, assign it.
+      if test -n "$prev"; then
+	case $prev in
+	output)
+	  func_append compile_command " @OUTPUT@"
+	  func_append finalize_command " @OUTPUT@"
+	  ;;
+	esac
+
+	case $prev in
+	dlfiles|dlprefiles)
+	  if test "$preload" = no; then
+	    # Add the symbol object into the linking commands.
+	    func_append compile_command " @SYMFILE@"
+	    func_append finalize_command " @SYMFILE@"
+	    preload=yes
+	  fi
+	  case $arg in
+	  *.la | *.lo) ;;  # We handle these cases below.
+	  force)
+	    if test "$dlself" = no; then
+	      dlself=needless
+	      export_dynamic=yes
+	    fi
+	    prev=
+	    continue
+	    ;;
+	  self)
+	    if test "$prev" = dlprefiles; then
+	      dlself=yes
+	    elif test "$prev" = dlfiles && test "$dlopen_self" != yes; then
+	      dlself=yes
+	    else
+	      dlself=needless
+	      export_dynamic=yes
+	    fi
+	    prev=
+	    continue
+	    ;;
+	  *)
+	    if test "$prev" = dlfiles; then
+	      dlfiles="$dlfiles $arg"
+	    else
+	      dlprefiles="$dlprefiles $arg"
+	    fi
+	    prev=
+	    continue
+	    ;;
+	  esac
+	  ;;
+	expsyms)
+	  export_symbols="$arg"
+	  test -f "$arg" \
+	    || func_fatal_error "symbol file \`$arg' does not exist"
+	  prev=
+	  continue
+	  ;;
+	expsyms_regex)
+	  export_symbols_regex="$arg"
+	  prev=
+	  continue
+	  ;;
+	framework)
+	  case $host in
+	    *-*-darwin*)
+	      case "$deplibs " in
+		*" $qarg.ltframework "*) ;;
+		*) deplibs="$deplibs $qarg.ltframework" # this is fixed later
+		   ;;
+	      esac
+	      ;;
+	  esac
+	  prev=
+	  continue
+	  ;;
+	inst_prefix)
+	  inst_prefix_dir="$arg"
+	  prev=
+	  continue
+	  ;;
+	objectlist)
+	  if test -f "$arg"; then
+	    save_arg=$arg
+	    moreargs=
+	    for fil in `cat "$save_arg"`
+	    do
+#	      moreargs="$moreargs $fil"
+	      arg=$fil
+	      # A libtool-controlled object.
+
+	      # Check to see that this really is a libtool object.
+	      if func_lalib_unsafe_p "$arg"; then
+		pic_object=
+		non_pic_object=
+
+		# Read the .lo file
+		func_source "$arg"
+
+		if test -z "$pic_object" ||
+		   test -z "$non_pic_object" ||
+		   test "$pic_object" = none &&
+		   test "$non_pic_object" = none; then
+		  func_fatal_error "cannot find name of object for \`$arg'"
+		fi
+
+		# Extract subdirectory from the argument.
+		func_dirname "$arg" "/" ""
+		xdir="$func_dirname_result"
+
+		if test "$pic_object" != none; then
+		  # Prepend the subdirectory the object is found in.
+		  pic_object="$xdir$pic_object"
+
+		  if test "$prev" = dlfiles; then
+		    if test "$build_libtool_libs" = yes && test "$dlopen_support" = yes; then
+		      dlfiles="$dlfiles $pic_object"
+		      prev=
+		      continue
+		    else
+		      # If libtool objects are unsupported, then we need to preload.
+		      prev=dlprefiles
+		    fi
+		  fi
+
+		  # CHECK ME:  I think I busted this.  -Ossama
+		  if test "$prev" = dlprefiles; then
+		    # Preload the old-style object.
+		    dlprefiles="$dlprefiles $pic_object"
+		    prev=
+		  fi
+
+		  # A PIC object.
+		  func_append libobjs " $pic_object"
+		  arg="$pic_object"
+		fi
+
+		# Non-PIC object.
+		if test "$non_pic_object" != none; then
+		  # Prepend the subdirectory the object is found in.
+		  non_pic_object="$xdir$non_pic_object"
+
+		  # A standard non-PIC object
+		  func_append non_pic_objects " $non_pic_object"
+		  if test -z "$pic_object" || test "$pic_object" = none ; then
+		    arg="$non_pic_object"
+		  fi
+		else
+		  # If the PIC object exists, use it instead.
+		  # $xdir was prepended to $pic_object above.
+		  non_pic_object="$pic_object"
+		  func_append non_pic_objects " $non_pic_object"
+		fi
+	      else
+		# Only an error if not doing a dry-run.
+		if $opt_dry_run; then
+		  # Extract subdirectory from the argument.
+		  func_dirname "$arg" "/" ""
+		  xdir="$func_dirname_result"
+
+		  func_lo2o "$arg"
+		  pic_object=$xdir$objdir/$func_lo2o_result
+		  non_pic_object=$xdir$func_lo2o_result
+		  func_append libobjs " $pic_object"
+		  func_append non_pic_objects " $non_pic_object"
+	        else
+		  func_fatal_error "\`$arg' is not a valid libtool object"
+		fi
+	      fi
+	    done
+	  else
+	    func_fatal_error "link input file \`$arg' does not exist"
+	  fi
+	  arg=$save_arg
+	  prev=
+	  continue
+	  ;;
+	precious_regex)
+	  precious_files_regex="$arg"
+	  prev=
+	  continue
+	  ;;
+	release)
+	  release="-$arg"
+	  prev=
+	  continue
+	  ;;
+	rpath | xrpath)
+	  # We need an absolute path.
+	  case $arg in
+	  [\\/]* | [A-Za-z]:[\\/]*) ;;
+	  *)
+	    func_fatal_error "only absolute run-paths are allowed"
+	    ;;
+	  esac
+	  if test "$prev" = rpath; then
+	    case "$rpath " in
+	    *" $arg "*) ;;
+	    *) rpath="$rpath $arg" ;;
+	    esac
+	  else
+	    case "$xrpath " in
+	    *" $arg "*) ;;
+	    *) xrpath="$xrpath $arg" ;;
+	    esac
+	  fi
+	  prev=
+	  continue
+	  ;;
+	shrext)
+	  shrext_cmds="$arg"
+	  prev=
+	  continue
+	  ;;
+	weak)
+	  weak_libs="$weak_libs $arg"
+	  prev=
+	  continue
+	  ;;
+	xcclinker)
+	  linker_flags="$linker_flags $qarg"
+	  compiler_flags="$compiler_flags $qarg"
+	  prev=
+	  func_append compile_command " $qarg"
+	  func_append finalize_command " $qarg"
+	  continue
+	  ;;
+	xcompiler)
+	  compiler_flags="$compiler_flags $qarg"
+	  prev=
+	  func_append compile_command " $qarg"
+	  func_append finalize_command " $qarg"
+	  continue
+	  ;;
+	xlinker)
+	  linker_flags="$linker_flags $qarg"
+	  compiler_flags="$compiler_flags $wl$qarg"
+	  prev=
+	  func_append compile_command " $wl$qarg"
+	  func_append finalize_command " $wl$qarg"
+	  continue
+	  ;;
+	*)
+	  eval "$prev=\"\$arg\""
+	  prev=
+	  continue
+	  ;;
+	esac
+      fi # test -n "$prev"
+
+      prevarg="$arg"
+
+      case $arg in
+      -all-static)
+	if test -n "$link_static_flag"; then
+	  # See comment for -static flag below, for more details.
+	  func_append compile_command " $link_static_flag"
+	  func_append finalize_command " $link_static_flag"
+	fi
+	continue
+	;;
+
+      -allow-undefined)
+	# FIXME: remove this flag sometime in the future.
+	func_fatal_error "\`-allow-undefined' must not be used because it is the default"
+	;;
+
+      -avoid-version)
+	avoid_version=yes
+	continue
+	;;
+
+      -dlopen)
+	prev=dlfiles
+	continue
+	;;
+
+      -dlpreopen)
+	prev=dlprefiles
+	continue
+	;;
+
+      -export-dynamic)
+	export_dynamic=yes
+	continue
+	;;
+
+      -export-symbols | -export-symbols-regex)
+	if test -n "$export_symbols" || test -n "$export_symbols_regex"; then
+	  func_fatal_error "more than one -exported-symbols argument is not allowed"
+	fi
+	if test "X$arg" = "X-export-symbols"; then
+	  prev=expsyms
+	else
+	  prev=expsyms_regex
+	fi
+	continue
+	;;
+
+      -framework)
+	prev=framework
+	continue
+	;;
+
+      -inst-prefix-dir)
+	prev=inst_prefix
+	continue
+	;;
+
+      # The native IRIX linker understands -LANG:*, -LIST:* and -LNO:*
+      # so, if we see these flags be careful not to treat them like -L
+      -L[A-Z][A-Z]*:*)
+	case $with_gcc/$host in
+	no/*-*-irix* | /*-*-irix*)
+	  func_append compile_command " $arg"
+	  func_append finalize_command " $arg"
+	  ;;
+	esac
+	continue
+	;;
+
+      -L*)
+	func_stripname '-L' '' "$arg"
+	dir=$func_stripname_result
+	if test -z "$dir"; then
+	  if test "$#" -gt 0; then
+	    func_fatal_error "require no space between \`-L' and \`$1'"
+	  else
+	    func_fatal_error "need path for \`-L' option"
+	  fi
+	fi
+	# We need an absolute path.
+	case $dir in
+	[\\/]* | [A-Za-z]:[\\/]*) ;;
+	*)
+	  absdir=`cd "$dir" && pwd`
+	  test -z "$absdir" && \
+	    func_fatal_error "cannot determine absolute directory name of \`$dir'"
+	  dir="$absdir"
+	  ;;
+	esac
+	case "$deplibs " in
+	*" -L$dir "*) ;;
+	*)
+	  deplibs="$deplibs -L$dir"
+	  lib_search_path="$lib_search_path $dir"
+	  ;;
+	esac
+	case $host in
+	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
+	  testbindir=`$ECHO "X$dir" | $Xsed -e 's*/lib$*/bin*'`
+	  case :$dllsearchpath: in
+	  *":$dir:"*) ;;
+	  ::) dllsearchpath=$dir;;
+	  *) dllsearchpath="$dllsearchpath:$dir";;
+	  esac
+	  case :$dllsearchpath: in
+	  *":$testbindir:"*) ;;
+	  ::) dllsearchpath=$testbindir;;
+	  *) dllsearchpath="$dllsearchpath:$testbindir";;
+	  esac
+	  ;;
+	esac
+	continue
+	;;
+
+      -l*)
+	if test "X$arg" = "X-lc" || test "X$arg" = "X-lm"; then
+	  case $host in
+	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-beos* | *-cegcc*)
+	    # These systems don't actually have a C or math library (as such)
+	    continue
+	    ;;
+	  *-*-os2*)
+	    # These systems don't actually have a C library (as such)
+	    test "X$arg" = "X-lc" && continue
+	    ;;
+	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly*)
+	    # Do not include libc due to us having libc/libc_r.
+	    test "X$arg" = "X-lc" && continue
+	    ;;
+	  *-*-rhapsody* | *-*-darwin1.[012])
+	    # Rhapsody C and math libraries are in the System framework
+	    deplibs="$deplibs System.ltframework"
+	    continue
+	    ;;
+	  *-*-sco3.2v5* | *-*-sco5v6*)
+	    # Causes problems with __ctype
+	    test "X$arg" = "X-lc" && continue
+	    ;;
+	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
+	    # Compiler inserts libc in the correct place for threads to work
+	    test "X$arg" = "X-lc" && continue
+	    ;;
+	  esac
+	elif test "X$arg" = "X-lc_r"; then
+	 case $host in
+	 *-*-openbsd* | *-*-freebsd* | *-*-dragonfly*)
+	   # Do not include libc_r directly, use -pthread flag.
+	   continue
+	   ;;
+	 esac
+	fi
+	deplibs="$deplibs $arg"
+	continue
+	;;
+
+      -module)
+	module=yes
+	continue
+	;;
+
+      # Tru64 UNIX uses -model [arg] to determine the layout of C++
+      # classes, name mangling, and exception handling.
+      # Darwin uses the -arch flag to determine output architecture.
+      -model|-arch|-isysroot)
+	compiler_flags="$compiler_flags $arg"
+	func_append compile_command " $arg"
+	func_append finalize_command " $arg"
+	prev=xcompiler
+	continue
+	;;
+
+      -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe|-threads)
+	compiler_flags="$compiler_flags $arg"
+	func_append compile_command " $arg"
+	func_append finalize_command " $arg"
+	case "$new_inherited_linker_flags " in
+	    *" $arg "*) ;;
+	    * ) new_inherited_linker_flags="$new_inherited_linker_flags $arg" ;;
+	esac
+	continue
+	;;
+
+      -multi_module)
+	single_module="${wl}-multi_module"
+	continue
+	;;
+
+      -no-fast-install)
+	fast_install=no
+	continue
+	;;
+
+      -no-install)
+	case $host in
+	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-darwin* | *-cegcc*)
+	  # The PATH hackery in wrapper scripts is required on Windows
+	  # and Darwin in order for the loader to find any dlls it needs.
+	  func_warning "\`-no-install' is ignored for $host"
+	  func_warning "assuming \`-no-fast-install' instead"
+	  fast_install=no
+	  ;;
+	*) no_install=yes ;;
+	esac
+	continue
+	;;
+
+      -no-undefined)
+	allow_undefined=no
+	continue
+	;;
+
+      -objectlist)
+	prev=objectlist
+	continue
+	;;
+
+      -o) prev=output ;;
+
+      -precious-files-regex)
+	prev=precious_regex
+	continue
+	;;
+
+      -release)
+	prev=release
+	continue
+	;;
+
+      -rpath)
+	prev=rpath
+	continue
+	;;
+
+      -R)
+	prev=xrpath
+	continue
+	;;
+
+      -R*)
+	func_stripname '-R' '' "$arg"
+	dir=$func_stripname_result
+	# We need an absolute path.
+	case $dir in
+	[\\/]* | [A-Za-z]:[\\/]*) ;;
+	*)
+	  func_fatal_error "only absolute run-paths are allowed"
+	  ;;
+	esac
+	case "$xrpath " in
+	*" $dir "*) ;;
+	*) xrpath="$xrpath $dir" ;;
+	esac
+	continue
+	;;
+
+      -shared)
+	# The effects of -shared are defined in a previous loop.
+	continue
+	;;
+
+      -shrext)
+	prev=shrext
+	continue
+	;;
+
+      -static | -static-libtool-libs)
+	# The effects of -static are defined in a previous loop.
+	# We used to do the same as -all-static on platforms that
+	# didn't have a PIC flag, but the assumption that the effects
+	# would be equivalent was wrong.  It would break on at least
+	# Digital Unix and AIX.
+	continue
+	;;
+
+      -thread-safe)
+	thread_safe=yes
+	continue
+	;;
+
+      -version-info)
+	prev=vinfo
+	continue
+	;;
+
+      -version-number)
+	prev=vinfo
+	vinfo_number=yes
+	continue
+	;;
+
+      -weak)
+        prev=weak
+	continue
+	;;
+
+      -Wc,*)
+	func_stripname '-Wc,' '' "$arg"
+	args=$func_stripname_result
+	arg=
+	save_ifs="$IFS"; IFS=','
+	for flag in $args; do
+	  IFS="$save_ifs"
+          func_quote_for_eval "$flag"
+	  arg="$arg $wl$func_quote_for_eval_result"
+	  compiler_flags="$compiler_flags $func_quote_for_eval_result"
+	done
+	IFS="$save_ifs"
+	func_stripname ' ' '' "$arg"
+	arg=$func_stripname_result
+	;;
+
+      -Wl,*)
+	func_stripname '-Wl,' '' "$arg"
+	args=$func_stripname_result
+	arg=
+	save_ifs="$IFS"; IFS=','
+	for flag in $args; do
+	  IFS="$save_ifs"
+          func_quote_for_eval "$flag"
+	  arg="$arg $wl$func_quote_for_eval_result"
+	  compiler_flags="$compiler_flags $wl$func_quote_for_eval_result"
+	  linker_flags="$linker_flags $func_quote_for_eval_result"
+	done
+	IFS="$save_ifs"
+	func_stripname ' ' '' "$arg"
+	arg=$func_stripname_result
+	;;
+
+      -Xcompiler)
+	prev=xcompiler
+	continue
+	;;
+
+      -Xlinker)
+	prev=xlinker
+	continue
+	;;
+
+      -XCClinker)
+	prev=xcclinker
+	continue
+	;;
+
+      # -msg_* for osf cc
+      -msg_*)
+	func_quote_for_eval "$arg"
+	arg="$func_quote_for_eval_result"
+	;;
+
+      # -64, -mips[0-9] enable 64-bit mode on the SGI compiler
+      # -r[0-9][0-9]* specifies the processor on the SGI compiler
+      # -xarch=*, -xtarget=* enable 64-bit mode on the Sun compiler
+      # +DA*, +DD* enable 64-bit mode on the HP compiler
+      # -q* pass through compiler args for the IBM compiler
+      # -m*, -t[45]*, -txscale* pass through architecture-specific
+      # compiler args for GCC
+      # -F/path gives path to uninstalled frameworks, gcc on darwin
+      # -p, -pg, --coverage, -fprofile-* pass through profiling flag for GCC
+      # @file GCC response files
+      -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \
+      -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*)
+        func_quote_for_eval "$arg"
+	arg="$func_quote_for_eval_result"
+        func_append compile_command " $arg"
+        func_append finalize_command " $arg"
+        compiler_flags="$compiler_flags $arg"
+        continue
+        ;;
+
+      # Some other compiler flag.
+      -* | +*)
+        func_quote_for_eval "$arg"
+	arg="$func_quote_for_eval_result"
+	;;
+
+      *.$objext)
+	# A standard object.
+	objs="$objs $arg"
+	;;
+
+      *.lo)
+	# A libtool-controlled object.
+
+	# Check to see that this really is a libtool object.
+	if func_lalib_unsafe_p "$arg"; then
+	  pic_object=
+	  non_pic_object=
+
+	  # Read the .lo file
+	  func_source "$arg"
+
+	  if test -z "$pic_object" ||
+	     test -z "$non_pic_object" ||
+	     test "$pic_object" = none &&
+	     test "$non_pic_object" = none; then
+	    func_fatal_error "cannot find name of object for \`$arg'"
+	  fi
+
+	  # Extract subdirectory from the argument.
+	  func_dirname "$arg" "/" ""
+	  xdir="$func_dirname_result"
+
+	  if test "$pic_object" != none; then
+	    # Prepend the subdirectory the object is found in.
+	    pic_object="$xdir$pic_object"
+
+	    if test "$prev" = dlfiles; then
+	      if test "$build_libtool_libs" = yes && test "$dlopen_support" = yes; then
+		dlfiles="$dlfiles $pic_object"
+		prev=
+		continue
+	      else
+		# If libtool objects are unsupported, then we need to preload.
+		prev=dlprefiles
+	      fi
+	    fi
+
+	    # CHECK ME:  I think I busted this.  -Ossama
+	    if test "$prev" = dlprefiles; then
+	      # Preload the old-style object.
+	      dlprefiles="$dlprefiles $pic_object"
+	      prev=
+	    fi
+
+	    # A PIC object.
+	    func_append libobjs " $pic_object"
+	    arg="$pic_object"
+	  fi
+
+	  # Non-PIC object.
+	  if test "$non_pic_object" != none; then
+	    # Prepend the subdirectory the object is found in.
+	    non_pic_object="$xdir$non_pic_object"
+
+	    # A standard non-PIC object
+	    func_append non_pic_objects " $non_pic_object"
+	    if test -z "$pic_object" || test "$pic_object" = none ; then
+	      arg="$non_pic_object"
+	    fi
+	  else
+	    # If the PIC object exists, use it instead.
+	    # $xdir was prepended to $pic_object above.
+	    non_pic_object="$pic_object"
+	    func_append non_pic_objects " $non_pic_object"
+	  fi
+	else
+	  # Only an error if not doing a dry-run.
+	  if $opt_dry_run; then
+	    # Extract subdirectory from the argument.
+	    func_dirname "$arg" "/" ""
+	    xdir="$func_dirname_result"
+
+	    func_lo2o "$arg"
+	    pic_object=$xdir$objdir/$func_lo2o_result
+	    non_pic_object=$xdir$func_lo2o_result
+	    func_append libobjs " $pic_object"
+	    func_append non_pic_objects " $non_pic_object"
+	  else
+	    func_fatal_error "\`$arg' is not a valid libtool object"
+	  fi
+	fi
+	;;
+
+      *.$libext)
+	# An archive.
+	deplibs="$deplibs $arg"
+	old_deplibs="$old_deplibs $arg"
+	continue
+	;;
+
+      *.la)
+	# A libtool-controlled library.
+
+	if test "$prev" = dlfiles; then
+	  # This library was specified with -dlopen.
+	  dlfiles="$dlfiles $arg"
+	  prev=
+	elif test "$prev" = dlprefiles; then
+	  # The library was specified with -dlpreopen.
+	  dlprefiles="$dlprefiles $arg"
+	  prev=
+	else
+	  deplibs="$deplibs $arg"
+	fi
+	continue
+	;;
+
+      # Some other compiler argument.
+      *)
+	# Unknown arguments in both finalize_command and compile_command need
+	# to be aesthetically quoted because they are evaled later.
+	func_quote_for_eval "$arg"
+	arg="$func_quote_for_eval_result"
+	;;
+      esac # arg
+
+      # Now actually substitute the argument into the commands.
+      if test -n "$arg"; then
+	func_append compile_command " $arg"
+	func_append finalize_command " $arg"
+      fi
+    done # argument parsing loop
+
+    test -n "$prev" && \
+      func_fatal_help "the \`$prevarg' option requires an argument"
+
+    if test "$export_dynamic" = yes && test -n "$export_dynamic_flag_spec"; then
+      eval arg=\"$export_dynamic_flag_spec\"
+      func_append compile_command " $arg"
+      func_append finalize_command " $arg"
+    fi
+
+    oldlibs=
+    # calculate the name of the file, without its directory
+    func_basename "$output"
+    outputname="$func_basename_result"
+    libobjs_save="$libobjs"
+
+    if test -n "$shlibpath_var"; then
+      # get the directories listed in $shlibpath_var
+      eval shlib_search_path=\`\$ECHO \"X\${$shlibpath_var}\" \| \$Xsed -e \'s/:/ /g\'\`
+    else
+      shlib_search_path=
+    fi
+    eval sys_lib_search_path=\"$sys_lib_search_path_spec\"
+    eval sys_lib_dlsearch_path=\"$sys_lib_dlsearch_path_spec\"
+
+    func_dirname "$output" "/" ""
+    output_objdir="$func_dirname_result$objdir"
+    # Create the object directory.
+    func_mkdir_p "$output_objdir"
+
+    # Determine the type of output
+    case $output in
+    "")
+      func_fatal_help "you must specify an output file"
+      ;;
+    *.$libext) linkmode=oldlib ;;
+    *.lo | *.$objext) linkmode=obj ;;
+    *.la) linkmode=lib ;;
+    *) linkmode=prog ;; # Anything else should be a program.
+    esac
+
+    specialdeplibs=
+
+    libs=
+    # Find all interdependent deplibs by searching for libraries
+    # that are linked more than once (e.g. -la -lb -la)
+    for deplib in $deplibs; do
+      if $opt_duplicate_deps ; then
+	case "$libs " in
+	*" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;;
+	esac
+      fi
+      libs="$libs $deplib"
+    done
+
+    if test "$linkmode" = lib; then
+      libs="$predeps $libs $compiler_lib_search_path $postdeps"
+
+      # Compute libraries that are listed more than once in $predeps
+      # $postdeps and mark them as special (i.e., whose duplicates are
+      # not to be eliminated).
+      pre_post_deps=
+      if $opt_duplicate_compiler_generated_deps; then
+	for pre_post_dep in $predeps $postdeps; do
+	  case "$pre_post_deps " in
+	  *" $pre_post_dep "*) specialdeplibs="$specialdeplibs $pre_post_deps" ;;
+	  esac
+	  pre_post_deps="$pre_post_deps $pre_post_dep"
+	done
+      fi
+      pre_post_deps=
+    fi
+
+    deplibs=
+    newdependency_libs=
+    newlib_search_path=
+    need_relink=no # whether we're linking any uninstalled libtool libraries
+    notinst_deplibs= # not-installed libtool libraries
+    notinst_path= # paths that contain not-installed libtool libraries
+
+    case $linkmode in
+    lib)
+	passes="conv dlpreopen link"
+	for file in $dlfiles $dlprefiles; do
+	  case $file in
+	  *.la) ;;
+	  *)
+	    func_fatal_help "libraries can \`-dlopen' only libtool libraries: $file"
+	    ;;
+	  esac
+	done
+	;;
+    prog)
+	compile_deplibs=
+	finalize_deplibs=
+	alldeplibs=no
+	newdlfiles=
+	newdlprefiles=
+	passes="conv scan dlopen dlpreopen link"
+	;;
+    *)  passes="conv"
+	;;
+    esac
+
+    for pass in $passes; do
+      # The preopen pass in lib mode reverses $deplibs; put it back here
+      # so that -L comes before libs that need it for instance...
+      if test "$linkmode,$pass" = "lib,link"; then
+	## FIXME: Find the place where the list is rebuilt in the wrong
+	##        order, and fix it there properly
+        tmp_deplibs=
+	for deplib in $deplibs; do
+	  tmp_deplibs="$deplib $tmp_deplibs"
+	done
+	deplibs="$tmp_deplibs"
+      fi
+
+      if test "$linkmode,$pass" = "lib,link" ||
+	 test "$linkmode,$pass" = "prog,scan"; then
+	libs="$deplibs"
+	deplibs=
+      fi
+      if test "$linkmode" = prog; then
+	case $pass in
+	dlopen) libs="$dlfiles" ;;
+	dlpreopen) libs="$dlprefiles" ;;
+	link) libs="$deplibs %DEPLIBS% $dependency_libs" ;;
+	esac
+      fi
+      if test "$linkmode,$pass" = "lib,dlpreopen"; then
+	# Collect and forward deplibs of preopened libtool libs
+	for lib in $dlprefiles; do
+	  # Ignore non-libtool-libs
+	  dependency_libs=
+	  case $lib in
+	  *.la)	func_source "$lib" ;;
+	  esac
+
+	  # Collect preopened libtool deplibs, except any this library
+	  # has declared as weak libs
+	  for deplib in $dependency_libs; do
+            deplib_base=`$ECHO "X$deplib" | $Xsed -e "$basename"`
+	    case " $weak_libs " in
+	    *" $deplib_base "*) ;;
+	    *) deplibs="$deplibs $deplib" ;;
+	    esac
+	  done
+	done
+	libs="$dlprefiles"
+      fi
+      if test "$pass" = dlopen; then
+	# Collect dlpreopened libraries
+	save_deplibs="$deplibs"
+	deplibs=
+      fi
+
+      for deplib in $libs; do
+	lib=
+	found=no
+	case $deplib in
+	-mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe|-threads)
+	  if test "$linkmode,$pass" = "prog,link"; then
+	    compile_deplibs="$deplib $compile_deplibs"
+	    finalize_deplibs="$deplib $finalize_deplibs"
+	  else
+	    compiler_flags="$compiler_flags $deplib"
+	    if test "$linkmode" = lib ; then
+		case "$new_inherited_linker_flags " in
+		    *" $deplib "*) ;;
+		    * ) new_inherited_linker_flags="$new_inherited_linker_flags $deplib" ;;
+		esac
+	    fi
+	  fi
+	  continue
+	  ;;
+	-l*)
+	  if test "$linkmode" != lib && test "$linkmode" != prog; then
+	    func_warning "\`-l' is ignored for archives/objects"
+	    continue
+	  fi
+	  func_stripname '-l' '' "$deplib"
+	  name=$func_stripname_result
+	  if test "$linkmode" = lib; then
+	    searchdirs="$newlib_search_path $lib_search_path $compiler_lib_search_dirs $sys_lib_search_path $shlib_search_path"
+	  else
+	    searchdirs="$newlib_search_path $lib_search_path $sys_lib_search_path $shlib_search_path"
+	  fi
+	  for searchdir in $searchdirs; do
+	    for search_ext in .la $std_shrext .so .a; do
+	      # Search the libtool library
+	      lib="$searchdir/lib${name}${search_ext}"
+	      if test -f "$lib"; then
+		if test "$search_ext" = ".la"; then
+		  found=yes
+		else
+		  found=no
+		fi
+		break 2
+	      fi
+	    done
+	  done
+	  if test "$found" != yes; then
+	    # deplib doesn't seem to be a libtool library
+	    if test "$linkmode,$pass" = "prog,link"; then
+	      compile_deplibs="$deplib $compile_deplibs"
+	      finalize_deplibs="$deplib $finalize_deplibs"
+	    else
+	      deplibs="$deplib $deplibs"
+	      test "$linkmode" = lib && newdependency_libs="$deplib $newdependency_libs"
+	    fi
+	    continue
+	  else # deplib is a libtool library
+	    # If $allow_libtool_libs_with_static_runtimes && $deplib is a stdlib,
+	    # We need to do some special things here, and not later.
+	    if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then
+	      case " $predeps $postdeps " in
+	      *" $deplib "*)
+		if func_lalib_p "$lib"; then
+		  library_names=
+		  old_library=
+		  func_source "$lib"
+		  for l in $old_library $library_names; do
+		    ll="$l"
+		  done
+		  if test "X$ll" = "X$old_library" ; then # only static version available
+		    found=no
+		    func_dirname "$lib" "" "."
+		    ladir="$func_dirname_result"
+		    lib=$ladir/$old_library
+		    if test "$linkmode,$pass" = "prog,link"; then
+		      compile_deplibs="$deplib $compile_deplibs"
+		      finalize_deplibs="$deplib $finalize_deplibs"
+		    else
+		      deplibs="$deplib $deplibs"
+		      test "$linkmode" = lib && newdependency_libs="$deplib $newdependency_libs"
+		    fi
+		    continue
+		  fi
+		fi
+		;;
+	      *) ;;
+	      esac
+	    fi
+	  fi
+	  ;; # -l
+	*.ltframework)
+	  if test "$linkmode,$pass" = "prog,link"; then
+	    compile_deplibs="$deplib $compile_deplibs"
+	    finalize_deplibs="$deplib $finalize_deplibs"
+	  else
+	    deplibs="$deplib $deplibs"
+	    if test "$linkmode" = lib ; then
+		case "$new_inherited_linker_flags " in
+		    *" $deplib "*) ;;
+		    * ) new_inherited_linker_flags="$new_inherited_linker_flags $deplib" ;;
+		esac
+	    fi
+	  fi
+	  continue
+	  ;;
+	-L*)
+	  case $linkmode in
+	  lib)
+	    deplibs="$deplib $deplibs"
+	    test "$pass" = conv && continue
+	    newdependency_libs="$deplib $newdependency_libs"
+	    func_stripname '-L' '' "$deplib"
+	    newlib_search_path="$newlib_search_path $func_stripname_result"
+	    ;;
+	  prog)
+	    if test "$pass" = conv; then
+	      deplibs="$deplib $deplibs"
+	      continue
+	    fi
+	    if test "$pass" = scan; then
+	      deplibs="$deplib $deplibs"
+	    else
+	      compile_deplibs="$deplib $compile_deplibs"
+	      finalize_deplibs="$deplib $finalize_deplibs"
+	    fi
+	    func_stripname '-L' '' "$deplib"
+	    newlib_search_path="$newlib_search_path $func_stripname_result"
+	    ;;
+	  *)
+	    func_warning "\`-L' is ignored for archives/objects"
+	    ;;
+	  esac # linkmode
+	  continue
+	  ;; # -L
+	-R*)
+	  if test "$pass" = link; then
+	    func_stripname '-R' '' "$deplib"
+	    dir=$func_stripname_result
+	    # Make sure the xrpath contains only unique directories.
+	    case "$xrpath " in
+	    *" $dir "*) ;;
+	    *) xrpath="$xrpath $dir" ;;
+	    esac
+	  fi
+	  deplibs="$deplib $deplibs"
+	  continue
+	  ;;
+	*.la) lib="$deplib" ;;
+	*.$libext)
+	  if test "$pass" = conv; then
+	    deplibs="$deplib $deplibs"
+	    continue
+	  fi
+	  case $linkmode in
+	  lib)
+	    # Linking convenience modules into shared libraries is allowed,
+	    # but linking other static libraries is non-portable.
+	    case " $dlpreconveniencelibs " in
+	    *" $deplib "*) ;;
+	    *)
+	      valid_a_lib=no
+	      case $deplibs_check_method in
+		match_pattern*)
+		  set dummy $deplibs_check_method; shift
+		  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
+		  if eval "\$ECHO \"X$deplib\"" 2>/dev/null | $Xsed -e 10q \
+		    | $EGREP "$match_pattern_regex" > /dev/null; then
+		    valid_a_lib=yes
+		  fi
+		;;
+		pass_all)
+		  valid_a_lib=yes
+		;;
+	      esac
+	      if test "$valid_a_lib" != yes; then
+		$ECHO
+		$ECHO "*** Warning: Trying to link with static lib archive $deplib."
+		$ECHO "*** I have the capability to make that library automatically link in when"
+		$ECHO "*** you link to this library.  But I can only do this if you have a"
+		$ECHO "*** shared version of the library, which you do not appear to have"
+		$ECHO "*** because the file extensions .$libext of this argument makes me believe"
+		$ECHO "*** that it is just a static archive that I should not use here."
+	      else
+		$ECHO
+		$ECHO "*** Warning: Linking the shared library $output against the"
+		$ECHO "*** static library $deplib is not portable!"
+		deplibs="$deplib $deplibs"
+	      fi
+	      ;;
+	    esac
+	    continue
+	    ;;
+	  prog)
+	    if test "$pass" != link; then
+	      deplibs="$deplib $deplibs"
+	    else
+	      compile_deplibs="$deplib $compile_deplibs"
+	      finalize_deplibs="$deplib $finalize_deplibs"
+	    fi
+	    continue
+	    ;;
+	  esac # linkmode
+	  ;; # *.$libext
+	*.lo | *.$objext)
+	  if test "$pass" = conv; then
+	    deplibs="$deplib $deplibs"
+	  elif test "$linkmode" = prog; then
+	    if test "$pass" = dlpreopen || test "$dlopen_support" != yes || test "$build_libtool_libs" = no; then
+	      # If there is no dlopen support or we're linking statically,
+	      # we need to preload.
+	      newdlprefiles="$newdlprefiles $deplib"
+	      compile_deplibs="$deplib $compile_deplibs"
+	      finalize_deplibs="$deplib $finalize_deplibs"
+	    else
+	      newdlfiles="$newdlfiles $deplib"
+	    fi
+	  fi
+	  continue
+	  ;;
+	%DEPLIBS%)
+	  alldeplibs=yes
+	  continue
+	  ;;
+	esac # case $deplib
+
+	if test "$found" = yes || test -f "$lib"; then :
+	else
+	  func_fatal_error "cannot find the library \`$lib' or unhandled argument \`$deplib'"
+	fi
+
+	# Check to see that this really is a libtool archive.
+	func_lalib_unsafe_p "$lib" \
+	  || func_fatal_error "\`$lib' is not a valid libtool archive"
+
+	func_dirname "$lib" "" "."
+	ladir="$func_dirname_result"
+
+	dlname=
+	dlopen=
+	dlpreopen=
+	libdir=
+	library_names=
+	old_library=
+	inherited_linker_flags=
+	# If the library was installed with an old release of libtool,
+	# it will not redefine variables installed, or shouldnotlink
+	installed=yes
+	shouldnotlink=no
+	avoidtemprpath=
+
+
+	# Read the .la file
+	func_source "$lib"
+
+	# Convert "-framework foo" to "foo.ltframework"
+	if test -n "$inherited_linker_flags"; then
+	  tmp_inherited_linker_flags=`$ECHO "X$inherited_linker_flags" | $Xsed -e 's/-framework \([^ $]*\)/\1.ltframework/g'`
+	  for tmp_inherited_linker_flag in $tmp_inherited_linker_flags; do
+	    case " $new_inherited_linker_flags " in
+	      *" $tmp_inherited_linker_flag "*) ;;
+	      *) new_inherited_linker_flags="$new_inherited_linker_flags $tmp_inherited_linker_flag";;
+	    esac
+	  done
+	fi
+	dependency_libs=`$ECHO "X $dependency_libs" | $Xsed -e 's% \([^ $]*\).ltframework% -framework \1%g'`
+	if test "$linkmode,$pass" = "lib,link" ||
+	   test "$linkmode,$pass" = "prog,scan" ||
+	   { test "$linkmode" != prog && test "$linkmode" != lib; }; then
+	  test -n "$dlopen" && dlfiles="$dlfiles $dlopen"
+	  test -n "$dlpreopen" && dlprefiles="$dlprefiles $dlpreopen"
+	fi
+
+	if test "$pass" = conv; then
+	  # Only check for convenience libraries
+	  deplibs="$lib $deplibs"
+	  if test -z "$libdir"; then
+	    if test -z "$old_library"; then
+	      func_fatal_error "cannot find name of link library for \`$lib'"
+	    fi
+	    # It is a libtool convenience library, so add in its objects.
+	    convenience="$convenience $ladir/$objdir/$old_library"
+	    old_convenience="$old_convenience $ladir/$objdir/$old_library"
+	  elif test "$linkmode" != prog && test "$linkmode" != lib; then
+	    func_fatal_error "\`$lib' is not a convenience library"
+	  fi
+	  tmp_libs=
+	  for deplib in $dependency_libs; do
+	    deplibs="$deplib $deplibs"
+	    if $opt_duplicate_deps ; then
+	      case "$tmp_libs " in
+	      *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;;
+	      esac
+	    fi
+	    tmp_libs="$tmp_libs $deplib"
+	  done
+	  continue
+	fi # $pass = conv
+
+
+	# Get the name of the library we link against.
+	linklib=
+	for l in $old_library $library_names; do
+	  linklib="$l"
+	done
+	if test -z "$linklib"; then
+	  func_fatal_error "cannot find name of link library for \`$lib'"
+	fi
+
+	# This library was specified with -dlopen.
+	if test "$pass" = dlopen; then
+	  if test -z "$libdir"; then
+	    func_fatal_error "cannot -dlopen a convenience library: \`$lib'"
+	  fi
+	  if test -z "$dlname" ||
+	     test "$dlopen_support" != yes ||
+	     test "$build_libtool_libs" = no; then
+	    # If there is no dlname, no dlopen support or we're linking
+	    # statically, we need to preload.  We also need to preload any
+	    # dependent libraries so libltdl's deplib preloader doesn't
+	    # bomb out in the load deplibs phase.
+	    dlprefiles="$dlprefiles $lib $dependency_libs"
+	  else
+	    newdlfiles="$newdlfiles $lib"
+	  fi
+	  continue
+	fi # $pass = dlopen
+
+	# We need an absolute path.
+	case $ladir in
+	[\\/]* | [A-Za-z]:[\\/]*) abs_ladir="$ladir" ;;
+	*)
+	  abs_ladir=`cd "$ladir" && pwd`
+	  if test -z "$abs_ladir"; then
+	    func_warning "cannot determine absolute directory name of \`$ladir'"
+	    func_warning "passing it literally to the linker, although it might fail"
+	    abs_ladir="$ladir"
+	  fi
+	  ;;
+	esac
+	func_basename "$lib"
+	laname="$func_basename_result"
+
+	# Find the relevant object directory and library name.
+	if test "X$installed" = Xyes; then
+	  if test ! -f "$libdir/$linklib" && test -f "$abs_ladir/$linklib"; then
+	    func_warning "library \`$lib' was moved."
+	    dir="$ladir"
+	    absdir="$abs_ladir"
+	    libdir="$abs_ladir"
+	  else
+	    dir="$libdir"
+	    absdir="$libdir"
+	  fi
+	  test "X$hardcode_automatic" = Xyes && avoidtemprpath=yes
+	else
+	  if test ! -f "$ladir/$objdir/$linklib" && test -f "$abs_ladir/$linklib"; then
+	    dir="$ladir"
+	    absdir="$abs_ladir"
+	    # Remove this search path later
+	    notinst_path="$notinst_path $abs_ladir"
+	  else
+	    dir="$ladir/$objdir"
+	    absdir="$abs_ladir/$objdir"
+	    # Remove this search path later
+	    notinst_path="$notinst_path $abs_ladir"
+	  fi
+	fi # $installed = yes
+	func_stripname 'lib' '.la' "$laname"
+	name=$func_stripname_result
+
+	# This library was specified with -dlpreopen.
+	if test "$pass" = dlpreopen; then
+	  if test -z "$libdir" && test "$linkmode" = prog; then
+	    func_fatal_error "only libraries may -dlpreopen a convenience library: \`$lib'"
+	  fi
+	  # Prefer using a static library (so that no silly _DYNAMIC symbols
+	  # are required to link).
+	  if test -n "$old_library"; then
+	    newdlprefiles="$newdlprefiles $dir/$old_library"
+	    # Keep a list of preopened convenience libraries to check
+	    # that they are being used correctly in the link pass.
+	    test -z "$libdir" && \
+		dlpreconveniencelibs="$dlpreconveniencelibs $dir/$old_library"
+	  # Otherwise, use the dlname, so that lt_dlopen finds it.
+	  elif test -n "$dlname"; then
+	    newdlprefiles="$newdlprefiles $dir/$dlname"
+	  else
+	    newdlprefiles="$newdlprefiles $dir/$linklib"
+	  fi
+	fi # $pass = dlpreopen
+
+	if test -z "$libdir"; then
+	  # Link the convenience library
+	  if test "$linkmode" = lib; then
+	    deplibs="$dir/$old_library $deplibs"
+	  elif test "$linkmode,$pass" = "prog,link"; then
+	    compile_deplibs="$dir/$old_library $compile_deplibs"
+	    finalize_deplibs="$dir/$old_library $finalize_deplibs"
+	  else
+	    deplibs="$lib $deplibs" # used for prog,scan pass
+	  fi
+	  continue
+	fi
+
+
+	if test "$linkmode" = prog && test "$pass" != link; then
+	  newlib_search_path="$newlib_search_path $ladir"
+	  deplibs="$lib $deplibs"
+
+	  linkalldeplibs=no
+	  if test "$link_all_deplibs" != no || test -z "$library_names" ||
+	     test "$build_libtool_libs" = no; then
+	    linkalldeplibs=yes
+	  fi
+
+	  tmp_libs=
+	  for deplib in $dependency_libs; do
+	    case $deplib in
+	    -L*) func_stripname '-L' '' "$deplib"
+	         newlib_search_path="$newlib_search_path $func_stripname_result"
+		 ;;
+	    esac
+	    # Need to link against all dependency_libs?
+	    if test "$linkalldeplibs" = yes; then
+	      deplibs="$deplib $deplibs"
+	    else
+	      # Need to hardcode shared library paths
+	      # or/and link against static libraries
+	      newdependency_libs="$deplib $newdependency_libs"
+	    fi
+	    if $opt_duplicate_deps ; then
+	      case "$tmp_libs " in
+	      *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;;
+	      esac
+	    fi
+	    tmp_libs="$tmp_libs $deplib"
+	  done # for deplib
+	  continue
+	fi # $linkmode = prog...
+
+	if test "$linkmode,$pass" = "prog,link"; then
+	  if test -n "$library_names" &&
+	     { { test "$prefer_static_libs" = no ||
+	         test "$prefer_static_libs,$installed" = "built,yes"; } ||
+	       test -z "$old_library"; }; then
+	    # We need to hardcode the library path
+	    if test -n "$shlibpath_var" && test -z "$avoidtemprpath" ; then
+	      # Make sure the rpath contains only unique directories.
+	      case "$temp_rpath:" in
+	      *"$absdir:"*) ;;
+	      *) temp_rpath="$temp_rpath$absdir:" ;;
+	      esac
+	    fi
+
+	    # Hardcode the library path.
+	    # Skip directories that are in the system default run-time
+	    # search path.
+	    case " $sys_lib_dlsearch_path " in
+	    *" $absdir "*) ;;
+	    *)
+	      case "$compile_rpath " in
+	      *" $absdir "*) ;;
+	      *) compile_rpath="$compile_rpath $absdir"
+	      esac
+	      ;;
+	    esac
+	    case " $sys_lib_dlsearch_path " in
+	    *" $libdir "*) ;;
+	    *)
+	      case "$finalize_rpath " in
+	      *" $libdir "*) ;;
+	      *) finalize_rpath="$finalize_rpath $libdir"
+	      esac
+	      ;;
+	    esac
+	  fi # $linkmode,$pass = prog,link...
+
+	  if test "$alldeplibs" = yes &&
+	     { test "$deplibs_check_method" = pass_all ||
+	       { test "$build_libtool_libs" = yes &&
+		 test -n "$library_names"; }; }; then
+	    # We only need to search for static libraries
+	    continue
+	  fi
+	fi
+
+	link_static=no # Whether the deplib will be linked statically
+	use_static_libs=$prefer_static_libs
+	if test "$use_static_libs" = built && test "$installed" = yes; then
+	  use_static_libs=no
+	fi
+	if test -n "$library_names" &&
+	   { test "$use_static_libs" = no || test -z "$old_library"; }; then
+	  case $host in
+	  *cygwin* | *mingw* | *cegcc*)
+	      # No point in relinking DLLs because paths are not encoded
+	      notinst_deplibs="$notinst_deplibs $lib"
+	      need_relink=no
+	    ;;
+	  *)
+	    if test "$installed" = no; then
+	      notinst_deplibs="$notinst_deplibs $lib"
+	      need_relink=yes
+	    fi
+	    ;;
+	  esac
+	  # This is a shared library
+
+	  # Warn about portability, can't link against -module's on some
+	  # systems (darwin).  Don't bleat about dlopened modules though!
+	  dlopenmodule=""
+	  for dlpremoduletest in $dlprefiles; do
+	    if test "X$dlpremoduletest" = "X$lib"; then
+	      dlopenmodule="$dlpremoduletest"
+	      break
+	    fi
+	  done
+	  if test -z "$dlopenmodule" && test "$shouldnotlink" = yes && test "$pass" = link; then
+	    $ECHO
+	    if test "$linkmode" = prog; then
+	      $ECHO "*** Warning: Linking the executable $output against the loadable module"
+	    else
+	      $ECHO "*** Warning: Linking the shared library $output against the loadable module"
+	    fi
+	    $ECHO "*** $linklib is not portable!"
+	  fi
+	  if test "$linkmode" = lib &&
+	     test "$hardcode_into_libs" = yes; then
+	    # Hardcode the library path.
+	    # Skip directories that are in the system default run-time
+	    # search path.
+	    case " $sys_lib_dlsearch_path " in
+	    *" $absdir "*) ;;
+	    *)
+	      case "$compile_rpath " in
+	      *" $absdir "*) ;;
+	      *) compile_rpath="$compile_rpath $absdir"
+	      esac
+	      ;;
+	    esac
+	    case " $sys_lib_dlsearch_path " in
+	    *" $libdir "*) ;;
+	    *)
+	      case "$finalize_rpath " in
+	      *" $libdir "*) ;;
+	      *) finalize_rpath="$finalize_rpath $libdir"
+	      esac
+	      ;;
+	    esac
+	  fi
+
+	  if test -n "$old_archive_from_expsyms_cmds"; then
+	    # figure out the soname
+	    set dummy $library_names
+	    shift
+	    realname="$1"
+	    shift
+	    libname=`eval "\\$ECHO \"$libname_spec\""`
+	    # use dlname if we got it. it's perfectly good, no?
+	    if test -n "$dlname"; then
+	      soname="$dlname"
+	    elif test -n "$soname_spec"; then
+	      # bleh windows
+	      case $host in
+	      *cygwin* | mingw* | *cegcc*)
+	        func_arith $current - $age
+		major=$func_arith_result
+		versuffix="-$major"
+		;;
+	      esac
+	      eval soname=\"$soname_spec\"
+	    else
+	      soname="$realname"
+	    fi
+
+	    # Make a new name for the extract_expsyms_cmds to use
+	    soroot="$soname"
+	    func_basename "$soroot"
+	    soname="$func_basename_result"
+	    func_stripname 'lib' '.dll' "$soname"
+	    newlib=libimp-$func_stripname_result.a
+
+	    # If the library has no export list, then create one now
+	    if test -f "$output_objdir/$soname-def"; then :
+	    else
+	      func_verbose "extracting exported symbol list from \`$soname'"
+	      func_execute_cmds "$extract_expsyms_cmds" 'exit $?'
+	    fi
+
+	    # Create $newlib
+	    if test -f "$output_objdir/$newlib"; then :; else
+	      func_verbose "generating import library for \`$soname'"
+	      func_execute_cmds "$old_archive_from_expsyms_cmds" 'exit $?'
+	    fi
+	    # make sure the library variables are pointing to the new library
+	    dir=$output_objdir
+	    linklib=$newlib
+	  fi # test -n "$old_archive_from_expsyms_cmds"
+
+	  if test "$linkmode" = prog || test "$mode" != relink; then
+	    add_shlibpath=
+	    add_dir=
+	    add=
+	    lib_linked=yes
+	    case $hardcode_action in
+	    immediate | unsupported)
+	      if test "$hardcode_direct" = no; then
+		add="$dir/$linklib"
+		case $host in
+		  *-*-sco3.2v5.0.[024]*) add_dir="-L$dir" ;;
+		  *-*-sysv4*uw2*) add_dir="-L$dir" ;;
+		  *-*-sysv5OpenUNIX* | *-*-sysv5UnixWare7.[01].[10]* | \
+		    *-*-unixware7*) add_dir="-L$dir" ;;
+		  *-*-darwin* )
+		    # if the lib is a (non-dlopened) module then we can not
+		    # link against it, someone is ignoring the earlier warnings
+		    if /usr/bin/file -L $add 2> /dev/null |
+			 $GREP ": [^:]* bundle" >/dev/null ; then
+		      if test "X$dlopenmodule" != "X$lib"; then
+			$ECHO "*** Warning: lib $linklib is a module, not a shared library"
+			if test -z "$old_library" ; then
+			  $ECHO
+			  $ECHO "*** And there doesn't seem to be a static archive available"
+			  $ECHO "*** The link will probably fail, sorry"
+			else
+			  add="$dir/$old_library"
+			fi
+		      elif test -n "$old_library"; then
+			add="$dir/$old_library"
+		      fi
+		    fi
+		esac
+	      elif test "$hardcode_minus_L" = no; then
+		case $host in
+		*-*-sunos*) add_shlibpath="$dir" ;;
+		esac
+		add_dir="-L$dir"
+		add="-l$name"
+	      elif test "$hardcode_shlibpath_var" = no; then
+		add_shlibpath="$dir"
+		add="-l$name"
+	      else
+		lib_linked=no
+	      fi
+	      ;;
+	    relink)
+	      if test "$hardcode_direct" = yes &&
+	         test "$hardcode_direct_absolute" = no; then
+		add="$dir/$linklib"
+	      elif test "$hardcode_minus_L" = yes; then
+		add_dir="-L$dir"
+		# Try looking first in the location we're being installed to.
+		if test -n "$inst_prefix_dir"; then
+		  case $libdir in
+		    [\\/]*)
+		      add_dir="$add_dir -L$inst_prefix_dir$libdir"
+		      ;;
+		  esac
+		fi
+		add="-l$name"
+	      elif test "$hardcode_shlibpath_var" = yes; then
+		add_shlibpath="$dir"
+		add="-l$name"
+	      else
+		lib_linked=no
+	      fi
+	      ;;
+	    *) lib_linked=no ;;
+	    esac
+
+	    if test "$lib_linked" != yes; then
+	      func_fatal_configuration "unsupported hardcode properties"
+	    fi
+
+	    if test -n "$add_shlibpath"; then
+	      case :$compile_shlibpath: in
+	      *":$add_shlibpath:"*) ;;
+	      *) compile_shlibpath="$compile_shlibpath$add_shlibpath:" ;;
+	      esac
+	    fi
+	    if test "$linkmode" = prog; then
+	      test -n "$add_dir" && compile_deplibs="$add_dir $compile_deplibs"
+	      test -n "$add" && compile_deplibs="$add $compile_deplibs"
+	    else
+	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
+	      test -n "$add" && deplibs="$add $deplibs"
+	      if test "$hardcode_direct" != yes &&
+		 test "$hardcode_minus_L" != yes &&
+		 test "$hardcode_shlibpath_var" = yes; then
+		case :$finalize_shlibpath: in
+		*":$libdir:"*) ;;
+		*) finalize_shlibpath="$finalize_shlibpath$libdir:" ;;
+		esac
+	      fi
+	    fi
+	  fi
+
+	  if test "$linkmode" = prog || test "$mode" = relink; then
+	    add_shlibpath=
+	    add_dir=
+	    add=
+	    # Finalize command for both is simple: just hardcode it.
+	    if test "$hardcode_direct" = yes &&
+	       test "$hardcode_direct_absolute" = no; then
+	      add="$libdir/$linklib"
+	    elif test "$hardcode_minus_L" = yes; then
+	      add_dir="-L$libdir"
+	      add="-l$name"
+	    elif test "$hardcode_shlibpath_var" = yes; then
+	      case :$finalize_shlibpath: in
+	      *":$libdir:"*) ;;
+	      *) finalize_shlibpath="$finalize_shlibpath$libdir:" ;;
+	      esac
+	      add="-l$name"
+	    elif test "$hardcode_automatic" = yes; then
+	      if test -n "$inst_prefix_dir" &&
+		 test -f "$inst_prefix_dir$libdir/$linklib" ; then
+		add="$inst_prefix_dir$libdir/$linklib"
+	      else
+		add="$libdir/$linklib"
+	      fi
+	    else
+	      # We cannot seem to hardcode it, guess we'll fake it.
+	      add_dir="-L$libdir"
+	      # Try looking first in the location we're being installed to.
+	      if test -n "$inst_prefix_dir"; then
+		case $libdir in
+		  [\\/]*)
+		    add_dir="$add_dir -L$inst_prefix_dir$libdir"
+		    ;;
+		esac
+	      fi
+	      add="-l$name"
+	    fi
+
+	    if test "$linkmode" = prog; then
+	      test -n "$add_dir" && finalize_deplibs="$add_dir $finalize_deplibs"
+	      test -n "$add" && finalize_deplibs="$add $finalize_deplibs"
+	    else
+	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
+	      test -n "$add" && deplibs="$add $deplibs"
+	    fi
+	  fi
+	elif test "$linkmode" = prog; then
+	  # Here we assume that one of hardcode_direct or hardcode_minus_L
+	  # is not unsupported.  This is valid on all known static and
+	  # shared platforms.
+	  if test "$hardcode_direct" != unsupported; then
+	    test -n "$old_library" && linklib="$old_library"
+	    compile_deplibs="$dir/$linklib $compile_deplibs"
+	    finalize_deplibs="$dir/$linklib $finalize_deplibs"
+	  else
+	    compile_deplibs="-l$name -L$dir $compile_deplibs"
+	    finalize_deplibs="-l$name -L$dir $finalize_deplibs"
+	  fi
+	elif test "$build_libtool_libs" = yes; then
+	  # Not a shared library
+	  if test "$deplibs_check_method" != pass_all; then
+	    # We're trying link a shared library against a static one
+	    # but the system doesn't support it.
+
+	    # Just print a warning and add the library to dependency_libs so
+	    # that the program can be linked against the static library.
+	    $ECHO
+	    $ECHO "*** Warning: This system can not link to static lib archive $lib."
+	    $ECHO "*** I have the capability to make that library automatically link in when"
+	    $ECHO "*** you link to this library.  But I can only do this if you have a"
+	    $ECHO "*** shared version of the library, which you do not appear to have."
+	    if test "$module" = yes; then
+	      $ECHO "*** But as you try to build a module library, libtool will still create "
+	      $ECHO "*** a static module, that should work as long as the dlopening application"
+	      $ECHO "*** is linked with the -dlopen flag to resolve symbols at runtime."
+	      if test -z "$global_symbol_pipe"; then
+		$ECHO
+		$ECHO "*** However, this would only work if libtool was able to extract symbol"
+		$ECHO "*** lists from a program, using \`nm' or equivalent, but libtool could"
+		$ECHO "*** not find such a program.  So, this module is probably useless."
+		$ECHO "*** \`nm' from GNU binutils and a full rebuild may help."
+	      fi
+	      if test "$build_old_libs" = no; then
+		build_libtool_libs=module
+		build_old_libs=yes
+	      else
+		build_libtool_libs=no
+	      fi
+	    fi
+	  else
+	    deplibs="$dir/$old_library $deplibs"
+	    link_static=yes
+	  fi
+	fi # link shared/static library?
+
+	if test "$linkmode" = lib; then
+	  if test -n "$dependency_libs" &&
+	     { test "$hardcode_into_libs" != yes ||
+	       test "$build_old_libs" = yes ||
+	       test "$link_static" = yes; }; then
+	    # Extract -R from dependency_libs
+	    temp_deplibs=
+	    for libdir in $dependency_libs; do
+	      case $libdir in
+	      -R*) func_stripname '-R' '' "$libdir"
+	           temp_xrpath=$func_stripname_result
+		   case " $xrpath " in
+		   *" $temp_xrpath "*) ;;
+		   *) xrpath="$xrpath $temp_xrpath";;
+		   esac;;
+	      *) temp_deplibs="$temp_deplibs $libdir";;
+	      esac
+	    done
+	    dependency_libs="$temp_deplibs"
+	  fi
+
+	  newlib_search_path="$newlib_search_path $absdir"
+	  # Link against this library
+	  test "$link_static" = no && newdependency_libs="$abs_ladir/$laname $newdependency_libs"
+	  # ... and its dependency_libs
+	  tmp_libs=
+	  for deplib in $dependency_libs; do
+	    newdependency_libs="$deplib $newdependency_libs"
+	    if $opt_duplicate_deps ; then
+	      case "$tmp_libs " in
+	      *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;;
+	      esac
+	    fi
+	    tmp_libs="$tmp_libs $deplib"
+	  done
+
+	  if test "$link_all_deplibs" != no; then
+	    # Add the search paths of all dependency libraries
+	    for deplib in $dependency_libs; do
+	      case $deplib in
+	      -L*) path="$deplib" ;;
+	      *.la)
+	        func_dirname "$deplib" "" "."
+		dir="$func_dirname_result"
+		# We need an absolute path.
+		case $dir in
+		[\\/]* | [A-Za-z]:[\\/]*) absdir="$dir" ;;
+		*)
+		  absdir=`cd "$dir" && pwd`
+		  if test -z "$absdir"; then
+		    func_warning "cannot determine absolute directory name of \`$dir'"
+		    absdir="$dir"
+		  fi
+		  ;;
+		esac
+		if $GREP "^installed=no" $deplib > /dev/null; then
+		case $host in
+		*-*-darwin*)
+		  depdepl=
+		  eval deplibrary_names=`${SED} -n -e 's/^library_names=\(.*\)$/\1/p' $deplib`
+		  if test -n "$deplibrary_names" ; then
+		    for tmp in $deplibrary_names ; do
+		      depdepl=$tmp
+		    done
+		    if test -f "$absdir/$objdir/$depdepl" ; then
+		      depdepl="$absdir/$objdir/$depdepl"
+		      darwin_install_name=`${OTOOL} -L $depdepl | awk '{if (NR == 2) {print $1;exit}}'`
+                      if test -z "$darwin_install_name"; then
+                          darwin_install_name=`${OTOOL64} -L $depdepl  | awk '{if (NR == 2) {print $1;exit}}'`
+                      fi
+		      compiler_flags="$compiler_flags ${wl}-dylib_file ${wl}${darwin_install_name}:${depdepl}"
+		      linker_flags="$linker_flags -dylib_file ${darwin_install_name}:${depdepl}"
+		      path=
+		    fi
+		  fi
+		  ;;
+		*)
+		  path="-L$absdir/$objdir"
+		  ;;
+		esac
+		else
+		  eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $deplib`
+		  test -z "$libdir" && \
+		    func_fatal_error "\`$deplib' is not a valid libtool archive"
+		  test "$absdir" != "$libdir" && \
+		    func_warning "\`$deplib' seems to be moved"
+
+		  path="-L$absdir"
+		fi
+		;;
+	      esac
+	      case " $deplibs " in
+	      *" $path "*) ;;
+	      *) deplibs="$path $deplibs" ;;
+	      esac
+	    done
+	  fi # link_all_deplibs != no
+	fi # linkmode = lib
+      done # for deplib in $libs
+      if test "$pass" = link; then
+	if test "$linkmode" = "prog"; then
+	  compile_deplibs="$new_inherited_linker_flags $compile_deplibs"
+	  finalize_deplibs="$new_inherited_linker_flags $finalize_deplibs"
+	else
+	  compiler_flags="$compiler_flags "`$ECHO "X $new_inherited_linker_flags" | $Xsed -e 's% \([^ $]*\).ltframework% -framework \1%g'`
+	fi
+      fi
+      dependency_libs="$newdependency_libs"
+      if test "$pass" = dlpreopen; then
+	# Link the dlpreopened libraries before other libraries
+	for deplib in $save_deplibs; do
+	  deplibs="$deplib $deplibs"
+	done
+      fi
+      if test "$pass" != dlopen; then
+	if test "$pass" != conv; then
+	  # Make sure lib_search_path contains only unique directories.
+	  lib_search_path=
+	  for dir in $newlib_search_path; do
+	    case "$lib_search_path " in
+	    *" $dir "*) ;;
+	    *) lib_search_path="$lib_search_path $dir" ;;
+	    esac
+	  done
+	  newlib_search_path=
+	fi
+
+	if test "$linkmode,$pass" != "prog,link"; then
+	  vars="deplibs"
+	else
+	  vars="compile_deplibs finalize_deplibs"
+	fi
+	for var in $vars dependency_libs; do
+	  # Add libraries to $var in reverse order
+	  eval tmp_libs=\"\$$var\"
+	  new_libs=
+	  for deplib in $tmp_libs; do
+	    # FIXME: Pedantically, this is the right thing to do, so
+	    #        that some nasty dependency loop isn't accidentally
+	    #        broken:
+	    #new_libs="$deplib $new_libs"
+	    # Pragmatically, this seems to cause very few problems in
+	    # practice:
+	    case $deplib in
+	    -L*) new_libs="$deplib $new_libs" ;;
+	    -R*) ;;
+	    *)
+	      # And here is the reason: when a library appears more
+	      # than once as an explicit dependence of a library, or
+	      # is implicitly linked in more than once by the
+	      # compiler, it is considered special, and multiple
+	      # occurrences thereof are not removed.  Compare this
+	      # with having the same library being listed as a
+	      # dependency of multiple other libraries: in this case,
+	      # we know (pedantically, we assume) the library does not
+	      # need to be listed more than once, so we keep only the
+	      # last copy.  This is not always right, but it is rare
+	      # enough that we require users that really mean to play
+	      # such unportable linking tricks to link the library
+	      # using -Wl,-lname, so that libtool does not consider it
+	      # for duplicate removal.
+	      case " $specialdeplibs " in
+	      *" $deplib "*) new_libs="$deplib $new_libs" ;;
+	      *)
+		case " $new_libs " in
+		*" $deplib "*) ;;
+		*) new_libs="$deplib $new_libs" ;;
+		esac
+		;;
+	      esac
+	      ;;
+	    esac
+	  done
+	  tmp_libs=
+	  for deplib in $new_libs; do
+	    case $deplib in
+	    -L*)
+	      case " $tmp_libs " in
+	      *" $deplib "*) ;;
+	      *) tmp_libs="$tmp_libs $deplib" ;;
+	      esac
+	      ;;
+	    *) tmp_libs="$tmp_libs $deplib" ;;
+	    esac
+	  done
+	  eval $var=\"$tmp_libs\"
+	done # for var
+      fi
+      # Last step: remove runtime libs from dependency_libs
+      # (they stay in deplibs)
+      tmp_libs=
+      for i in $dependency_libs ; do
+	case " $predeps $postdeps $compiler_lib_search_path " in
+	*" $i "*)
+	  i=""
+	  ;;
+	esac
+	if test -n "$i" ; then
+	  tmp_libs="$tmp_libs $i"
+	fi
+      done
+      dependency_libs=$tmp_libs
+    done # for pass
+    if test "$linkmode" = prog; then
+      dlfiles="$newdlfiles"
+    fi
+    if test "$linkmode" = prog || test "$linkmode" = lib; then
+      dlprefiles="$newdlprefiles"
+    fi
+
+    case $linkmode in
+    oldlib)
+      if test -n "$dlfiles$dlprefiles" || test "$dlself" != no; then
+	func_warning "\`-dlopen' is ignored for archives"
+      fi
+
+      case " $deplibs" in
+      *\ -l* | *\ -L*)
+	func_warning "\`-l' and \`-L' are ignored for archives" ;;
+      esac
+
+      test -n "$rpath" && \
+	func_warning "\`-rpath' is ignored for archives"
+
+      test -n "$xrpath" && \
+	func_warning "\`-R' is ignored for archives"
+
+      test -n "$vinfo" && \
+	func_warning "\`-version-info/-version-number' is ignored for archives"
+
+      test -n "$release" && \
+	func_warning "\`-release' is ignored for archives"
+
+      test -n "$export_symbols$export_symbols_regex" && \
+	func_warning "\`-export-symbols' is ignored for archives"
+
+      # Now set the variables for building old libraries.
+      build_libtool_libs=no
+      oldlibs="$output"
+      objs="$objs$old_deplibs"
+      ;;
+
+    lib)
+      # Make sure we only generate libraries of the form `libNAME.la'.
+      case $outputname in
+      lib*)
+	func_stripname 'lib' '.la' "$outputname"
+	name=$func_stripname_result
+	eval shared_ext=\"$shrext_cmds\"
+	eval libname=\"$libname_spec\"
+	;;
+      *)
+	test "$module" = no && \
+	  func_fatal_help "libtool library \`$output' must begin with \`lib'"
+
+	if test "$need_lib_prefix" != no; then
+	  # Add the "lib" prefix for modules if required
+	  func_stripname '' '.la' "$outputname"
+	  name=$func_stripname_result
+	  eval shared_ext=\"$shrext_cmds\"
+	  eval libname=\"$libname_spec\"
+	else
+	  func_stripname '' '.la' "$outputname"
+	  libname=$func_stripname_result
+	fi
+	;;
+      esac
+
+      if test -n "$objs"; then
+	if test "$deplibs_check_method" != pass_all; then
+	  func_fatal_error "cannot build libtool library \`$output' from non-libtool objects on this host:$objs"
+	else
+	  $ECHO
+	  $ECHO "*** Warning: Linking the shared library $output against the non-libtool"
+	  $ECHO "*** objects $objs is not portable!"
+	  libobjs="$libobjs $objs"
+	fi
+      fi
+
+      test "$dlself" != no && \
+	func_warning "\`-dlopen self' is ignored for libtool libraries"
+
+      set dummy $rpath
+      shift
+      test "$#" -gt 1 && \
+	func_warning "ignoring multiple \`-rpath's for a libtool library"
+
+      install_libdir="$1"
+
+      oldlibs=
+      if test -z "$rpath"; then
+	if test "$build_libtool_libs" = yes; then
+	  # Building a libtool convenience library.
+	  # Some compilers have problems with a `.al' extension so
+	  # convenience libraries should have the same extension an
+	  # archive normally would.
+	  oldlibs="$output_objdir/$libname.$libext $oldlibs"
+	  build_libtool_libs=convenience
+	  build_old_libs=yes
+	fi
+
+	test -n "$vinfo" && \
+	  func_warning "\`-version-info/-version-number' is ignored for convenience libraries"
+
+	test -n "$release" && \
+	  func_warning "\`-release' is ignored for convenience libraries"
+      else
+
+	# Parse the version information argument.
+	save_ifs="$IFS"; IFS=':'
+	set dummy $vinfo 0 0 0
+	shift
+	IFS="$save_ifs"
+
+	test -n "$7" && \
+	  func_fatal_help "too many parameters to \`-version-info'"
+
+	# convert absolute version numbers to libtool ages
+	# this retains compatibility with .la files and attempts
+	# to make the code below a bit more comprehensible
+
+	case $vinfo_number in
+	yes)
+	  number_major="$1"
+	  number_minor="$2"
+	  number_revision="$3"
+	  #
+	  # There are really only two kinds -- those that
+	  # use the current revision as the major version
+	  # and those that subtract age and use age as
+	  # a minor version.  But, then there is irix
+	  # which has an extra 1 added just for fun
+	  #
+	  case $version_type in
+	  darwin|linux|osf|windows|none)
+	    func_arith $number_major + $number_minor
+	    current=$func_arith_result
+	    age="$number_minor"
+	    revision="$number_revision"
+	    ;;
+	  freebsd-aout|freebsd-elf|sunos)
+	    current="$number_major"
+	    revision="$number_minor"
+	    age="0"
+	    ;;
+	  irix|nonstopux)
+	    func_arith $number_major + $number_minor
+	    current=$func_arith_result
+	    age="$number_minor"
+	    revision="$number_minor"
+	    lt_irix_increment=no
+	    ;;
+	  esac
+	  ;;
+	no)
+	  current="$1"
+	  revision="$2"
+	  age="$3"
+	  ;;
+	esac
+
+	# Check that each of the things are valid numbers.
+	case $current in
+	0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;;
+	*)
+	  func_error "CURRENT \`$current' must be a nonnegative integer"
+	  func_fatal_error "\`$vinfo' is not valid version information"
+	  ;;
+	esac
+
+	case $revision in
+	0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;;
+	*)
+	  func_error "REVISION \`$revision' must be a nonnegative integer"
+	  func_fatal_error "\`$vinfo' is not valid version information"
+	  ;;
+	esac
+
+	case $age in
+	0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;;
+	*)
+	  func_error "AGE \`$age' must be a nonnegative integer"
+	  func_fatal_error "\`$vinfo' is not valid version information"
+	  ;;
+	esac
+
+	if test "$age" -gt "$current"; then
+	  func_error "AGE \`$age' is greater than the current interface number \`$current'"
+	  func_fatal_error "\`$vinfo' is not valid version information"
+	fi
+
+	# Calculate the version variables.
+	major=
+	versuffix=
+	verstring=
+	case $version_type in
+	none) ;;
+
+	darwin)
+	  # Like Linux, but with the current version available in
+	  # verstring for coding it into the library header
+	  func_arith $current - $age
+	  major=.$func_arith_result
+	  versuffix="$major.$age.$revision"
+	  # Darwin ld doesn't like 0 for these options...
+	  func_arith $current + 1
+	  minor_current=$func_arith_result
+	  xlcverstring="${wl}-compatibility_version ${wl}$minor_current ${wl}-current_version ${wl}$minor_current.$revision"
+	  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
+	  ;;
+
+	freebsd-aout)
+	  major=".$current"
+	  versuffix=".$current.$revision";
+	  ;;
+
+	freebsd-elf)
+	  major=".$current"
+	  versuffix=".$current"
+	  ;;
+
+	irix | nonstopux)
+	  if test "X$lt_irix_increment" = "Xno"; then
+	    func_arith $current - $age
+	  else
+	    func_arith $current - $age + 1
+	  fi
+	  major=$func_arith_result
+
+	  case $version_type in
+	    nonstopux) verstring_prefix=nonstopux ;;
+	    *)         verstring_prefix=sgi ;;
+	  esac
+	  verstring="$verstring_prefix$major.$revision"
+
+	  # Add in all the interfaces that we are compatible with.
+	  loop=$revision
+	  while test "$loop" -ne 0; do
+	    func_arith $revision - $loop
+	    iface=$func_arith_result
+	    func_arith $loop - 1
+	    loop=$func_arith_result
+	    verstring="$verstring_prefix$major.$iface:$verstring"
+	  done
+
+	  # Before this point, $major must not contain `.'.
+	  major=.$major
+	  versuffix="$major.$revision"
+	  ;;
+
+	linux)
+	  func_arith $current - $age
+	  major=.$func_arith_result
+	  versuffix="$major.$age.$revision"
+	  ;;
+
+	osf)
+	  func_arith $current - $age
+	  major=.$func_arith_result
+	  versuffix=".$current.$age.$revision"
+	  verstring="$current.$age.$revision"
+
+	  # Add in all the interfaces that we are compatible with.
+	  loop=$age
+	  while test "$loop" -ne 0; do
+	    func_arith $current - $loop
+	    iface=$func_arith_result
+	    func_arith $loop - 1
+	    loop=$func_arith_result
+	    verstring="$verstring:${iface}.0"
+	  done
+
+	  # Make executables depend on our current version.
+	  verstring="$verstring:${current}.0"
+	  ;;
+
+	qnx)
+	  major=".$current"
+	  versuffix=".$current"
+	  ;;
+
+	sunos)
+	  major=".$current"
+	  versuffix=".$current.$revision"
+	  ;;
+
+	windows)
+	  # Use '-' rather than '.', since we only want one
+	  # extension on DOS 8.3 filesystems.
+	  func_arith $current - $age
+	  major=$func_arith_result
+	  versuffix="-$major"
+	  ;;
+
+	*)
+	  func_fatal_configuration "unknown library version type \`$version_type'"
+	  ;;
+	esac
+
+	# Clear the version info if we defaulted, and they specified a release.
+	if test -z "$vinfo" && test -n "$release"; then
+	  major=
+	  case $version_type in
+	  darwin)
+	    # we can't check for "0.0" in archive_cmds due to quoting
+	    # problems, so we reset it completely
+	    verstring=
+	    ;;
+	  *)
+	    verstring="0.0"
+	    ;;
+	  esac
+	  if test "$need_version" = no; then
+	    versuffix=
+	  else
+	    versuffix=".0.0"
+	  fi
+	fi
+
+	# Remove version info from name if versioning should be avoided
+	if test "$avoid_version" = yes && test "$need_version" = no; then
+	  major=
+	  versuffix=
+	  verstring=""
+	fi
+
+	# Check to see if the archive will have undefined symbols.
+	if test "$allow_undefined" = yes; then
+	  if test "$allow_undefined_flag" = unsupported; then
+	    func_warning "undefined symbols not allowed in $host shared libraries"
+	    build_libtool_libs=no
+	    build_old_libs=yes
+	  fi
+	else
+	  # Don't allow undefined symbols.
+	  allow_undefined_flag="$no_undefined_flag"
+	fi
+
+      fi
+
+      func_generate_dlsyms "$libname" "$libname" "yes"
+      libobjs="$libobjs $symfileobj"
+      test "X$libobjs" = "X " && libobjs=
+
+      if test "$mode" != relink; then
+	# Remove our outputs, but don't remove object files since they
+	# may have been created when compiling PIC objects.
+	removelist=
+	tempremovelist=`$ECHO "$output_objdir/*"`
+	for p in $tempremovelist; do
+	  case $p in
+	    *.$objext | *.gcno)
+	       ;;
+	    $output_objdir/$outputname | $output_objdir/$libname.* | $output_objdir/${libname}${release}.*)
+	       if test "X$precious_files_regex" != "X"; then
+		 if $ECHO "$p" | $EGREP -e "$precious_files_regex" >/dev/null 2>&1
+		 then
+		   continue
+		 fi
+	       fi
+	       removelist="$removelist $p"
+	       ;;
+	    *) ;;
+	  esac
+	done
+	test -n "$removelist" && \
+	  func_show_eval "${RM}r \$removelist"
+      fi
+
+      # Now set the variables for building old libraries.
+      if test "$build_old_libs" = yes && test "$build_libtool_libs" != convenience ; then
+	oldlibs="$oldlibs $output_objdir/$libname.$libext"
+
+	# Transform .lo files to .o files.
+	oldobjs="$objs "`$ECHO "X$libobjs" | $SP2NL | $Xsed -e '/\.'${libext}'$/d' -e "$lo2o" | $NL2SP`
+      fi
+
+      # Eliminate all temporary directories.
+      #for path in $notinst_path; do
+      #	lib_search_path=`$ECHO "X$lib_search_path " | $Xsed -e "s% $path % %g"`
+      #	deplibs=`$ECHO "X$deplibs " | $Xsed -e "s% -L$path % %g"`
+      #	dependency_libs=`$ECHO "X$dependency_libs " | $Xsed -e "s% -L$path % %g"`
+      #done
+
+      if test -n "$xrpath"; then
+	# If the user specified any rpath flags, then add them.
+	temp_xrpath=
+	for libdir in $xrpath; do
+	  temp_xrpath="$temp_xrpath -R$libdir"
+	  case "$finalize_rpath " in
+	  *" $libdir "*) ;;
+	  *) finalize_rpath="$finalize_rpath $libdir" ;;
+	  esac
+	done
+	if test "$hardcode_into_libs" != yes || test "$build_old_libs" = yes; then
+	  dependency_libs="$temp_xrpath $dependency_libs"
+	fi
+      fi
+
+      # Make sure dlfiles contains only unique files that won't be dlpreopened
+      old_dlfiles="$dlfiles"
+      dlfiles=
+      for lib in $old_dlfiles; do
+	case " $dlprefiles $dlfiles " in
+	*" $lib "*) ;;
+	*) dlfiles="$dlfiles $lib" ;;
+	esac
+      done
+
+      # Make sure dlprefiles contains only unique files
+      old_dlprefiles="$dlprefiles"
+      dlprefiles=
+      for lib in $old_dlprefiles; do
+	case "$dlprefiles " in
+	*" $lib "*) ;;
+	*) dlprefiles="$dlprefiles $lib" ;;
+	esac
+      done
+
+      if test "$build_libtool_libs" = yes; then
+	if test -n "$rpath"; then
+	  case $host in
+	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-beos* | *-cegcc*)
+	    # these systems don't actually have a c library (as such)!
+	    ;;
+	  *-*-rhapsody* | *-*-darwin1.[012])
+	    # Rhapsody C library is in the System framework
+	    deplibs="$deplibs System.ltframework"
+	    ;;
+	  *-*-netbsd*)
+	    # Don't link with libc until the a.out ld.so is fixed.
+	    ;;
+	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly*)
+	    # Do not include libc due to us having libc/libc_r.
+	    ;;
+	  *-*-sco3.2v5* | *-*-sco5v6*)
+	    # Causes problems with __ctype
+	    ;;
+	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
+	    # Compiler inserts libc in the correct place for threads to work
+	    ;;
+	  *)
+	    # Add libc to deplibs on all other systems if necessary.
+	    if test "$build_libtool_need_lc" = "yes"; then
+	      deplibs="$deplibs -lc"
+	    fi
+	    ;;
+	  esac
+	fi
+
+	# Transform deplibs into only deplibs that can be linked in shared.
+	name_save=$name
+	libname_save=$libname
+	release_save=$release
+	versuffix_save=$versuffix
+	major_save=$major
+	# I'm not sure if I'm treating the release correctly.  I think
+	# release should show up in the -l (ie -lgmp5) so we don't want to
+	# add it in twice.  Is that correct?
+	release=""
+	versuffix=""
+	major=""
+	newdeplibs=
+	droppeddeps=no
+	case $deplibs_check_method in
+	pass_all)
+	  # Don't check for shared/static.  Everything works.
+	  # This might be a little naive.  We might want to check
+	  # whether the library exists or not.  But this is on
+	  # osf3 & osf4 and I'm not really sure... Just
+	  # implementing what was already the behavior.
+	  newdeplibs=$deplibs
+	  ;;
+	test_compile)
+	  # This code stresses the "libraries are programs" paradigm to its
+	  # limits. Maybe even breaks it.  We compile a program, linking it
+	  # against the deplibs as a proxy for the library.  Then we can check
+	  # whether they linked in statically or dynamically with ldd.
+	  $opt_dry_run || $RM conftest.c
+	  cat > conftest.c <<EOF
+	  int main() { return 0; }
+EOF
+	  $opt_dry_run || $RM conftest
+	  if $LTCC $LTCFLAGS -o conftest conftest.c $deplibs; then
+	    ldd_output=`ldd conftest`
+	    for i in $deplibs; do
+	      case $i in
+	      -l*)
+		func_stripname -l '' "$i"
+		name=$func_stripname_result
+		if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then
+		  case " $predeps $postdeps " in
+		  *" $i "*)
+		    newdeplibs="$newdeplibs $i"
+		    i=""
+		    ;;
+		  esac
+		fi
+		if test -n "$i" ; then
+		  libname=`eval "\\$ECHO \"$libname_spec\""`
+		  deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
+		  set dummy $deplib_matches; shift
+		  deplib_match=$1
+		  if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0 ; then
+		    newdeplibs="$newdeplibs $i"
+		  else
+		    droppeddeps=yes
+		    $ECHO
+		    $ECHO "*** Warning: dynamic linker does not accept needed library $i."
+		    $ECHO "*** I have the capability to make that library automatically link in when"
+		    $ECHO "*** you link to this library.  But I can only do this if you have a"
+		    $ECHO "*** shared version of the library, which I believe you do not have"
+		    $ECHO "*** because a test_compile did reveal that the linker did not use it for"
+		    $ECHO "*** its dynamic dependency list that programs get resolved with at runtime."
+		  fi
+		fi
+		;;
+	      *)
+		newdeplibs="$newdeplibs $i"
+		;;
+	      esac
+	    done
+	  else
+	    # Error occurred in the first compile.  Let's try to salvage
+	    # the situation: Compile a separate program for each library.
+	    for i in $deplibs; do
+	      case $i in
+	      -l*)
+		func_stripname -l '' "$i"
+		name=$func_stripname_result
+		$opt_dry_run || $RM conftest
+		if $LTCC $LTCFLAGS -o conftest conftest.c $i; then
+		  ldd_output=`ldd conftest`
+		  if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then
+		    case " $predeps $postdeps " in
+		    *" $i "*)
+		      newdeplibs="$newdeplibs $i"
+		      i=""
+		      ;;
+		    esac
+		  fi
+		  if test -n "$i" ; then
+		    libname=`eval "\\$ECHO \"$libname_spec\""`
+		    deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
+		    set dummy $deplib_matches; shift
+		    deplib_match=$1
+		    if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0 ; then
+		      newdeplibs="$newdeplibs $i"
+		    else
+		      droppeddeps=yes
+		      $ECHO
+		      $ECHO "*** Warning: dynamic linker does not accept needed library $i."
+		      $ECHO "*** I have the capability to make that library automatically link in when"
+		      $ECHO "*** you link to this library.  But I can only do this if you have a"
+		      $ECHO "*** shared version of the library, which you do not appear to have"
+		      $ECHO "*** because a test_compile did reveal that the linker did not use this one"
+		      $ECHO "*** as a dynamic dependency that programs can get resolved with at runtime."
+		    fi
+		  fi
+		else
+		  droppeddeps=yes
+		  $ECHO
+		  $ECHO "*** Warning!  Library $i is needed by this library but I was not able to"
+		  $ECHO "*** make it link in!  You will probably need to install it or some"
+		  $ECHO "*** library that it depends on before this library will be fully"
+		  $ECHO "*** functional.  Installing it before continuing would be even better."
+		fi
+		;;
+	      *)
+		newdeplibs="$newdeplibs $i"
+		;;
+	      esac
+	    done
+	  fi
+	  ;;
+	file_magic*)
+	  set dummy $deplibs_check_method; shift
+	  file_magic_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
+	  for a_deplib in $deplibs; do
+	    case $a_deplib in
+	    -l*)
+	      func_stripname -l '' "$a_deplib"
+	      name=$func_stripname_result
+	      if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then
+		case " $predeps $postdeps " in
+		*" $a_deplib "*)
+		  newdeplibs="$newdeplibs $a_deplib"
+		  a_deplib=""
+		  ;;
+		esac
+	      fi
+	      if test -n "$a_deplib" ; then
+		libname=`eval "\\$ECHO \"$libname_spec\""`
+		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
+		  potential_libs=`ls $i/$libname[.-]* 2>/dev/null`
+		  for potent_lib in $potential_libs; do
+		      # Follow soft links.
+		      if ls -lLd "$potent_lib" 2>/dev/null |
+			 $GREP " -> " >/dev/null; then
+			continue
+		      fi
+		      # The statement above tries to avoid entering an
+		      # endless loop below, in case of cyclic links.
+		      # We might still enter an endless loop, since a link
+		      # loop can be closed while we follow links,
+		      # but so what?
+		      potlib="$potent_lib"
+		      while test -h "$potlib" 2>/dev/null; do
+			potliblink=`ls -ld $potlib | ${SED} 's/.* -> //'`
+			case $potliblink in
+			[\\/]* | [A-Za-z]:[\\/]*) potlib="$potliblink";;
+			*) potlib=`$ECHO "X$potlib" | $Xsed -e 's,[^/]*$,,'`"$potliblink";;
+			esac
+		      done
+		      if eval $file_magic_cmd \"\$potlib\" 2>/dev/null |
+			 $SED -e 10q |
+			 $EGREP "$file_magic_regex" > /dev/null; then
+			newdeplibs="$newdeplibs $a_deplib"
+			a_deplib=""
+			break 2
+		      fi
+		  done
+		done
+	      fi
+	      if test -n "$a_deplib" ; then
+		droppeddeps=yes
+		$ECHO
+		$ECHO "*** Warning: linker path does not have real file for library $a_deplib."
+		$ECHO "*** I have the capability to make that library automatically link in when"
+		$ECHO "*** you link to this library.  But I can only do this if you have a"
+		$ECHO "*** shared version of the library, which you do not appear to have"
+		$ECHO "*** because I did check the linker path looking for a file starting"
+		if test -z "$potlib" ; then
+		  $ECHO "*** with $libname but no candidates were found. (...for file magic test)"
+		else
+		  $ECHO "*** with $libname and none of the candidates passed a file format test"
+		  $ECHO "*** using a file magic. Last file checked: $potlib"
+		fi
+	      fi
+	      ;;
+	    *)
+	      # Add a -L argument.
+	      newdeplibs="$newdeplibs $a_deplib"
+	      ;;
+	    esac
+	  done # Gone through all deplibs.
+	  ;;
+	match_pattern*)
+	  set dummy $deplibs_check_method; shift
+	  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
+	  for a_deplib in $deplibs; do
+	    case $a_deplib in
+	    -l*)
+	      func_stripname -l '' "$a_deplib"
+	      name=$func_stripname_result
+	      if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then
+		case " $predeps $postdeps " in
+		*" $a_deplib "*)
+		  newdeplibs="$newdeplibs $a_deplib"
+		  a_deplib=""
+		  ;;
+		esac
+	      fi
+	      if test -n "$a_deplib" ; then
+		libname=`eval "\\$ECHO \"$libname_spec\""`
+		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
+		  potential_libs=`ls $i/$libname[.-]* 2>/dev/null`
+		  for potent_lib in $potential_libs; do
+		    potlib="$potent_lib" # see symlink-check above in file_magic test
+		    if eval "\$ECHO \"X$potent_lib\"" 2>/dev/null | $Xsed -e 10q | \
+		       $EGREP "$match_pattern_regex" > /dev/null; then
+		      newdeplibs="$newdeplibs $a_deplib"
+		      a_deplib=""
+		      break 2
+		    fi
+		  done
+		done
+	      fi
+	      if test -n "$a_deplib" ; then
+		droppeddeps=yes
+		$ECHO
+		$ECHO "*** Warning: linker path does not have real file for library $a_deplib."
+		$ECHO "*** I have the capability to make that library automatically link in when"
+		$ECHO "*** you link to this library.  But I can only do this if you have a"
+		$ECHO "*** shared version of the library, which you do not appear to have"
+		$ECHO "*** because I did check the linker path looking for a file starting"
+		if test -z "$potlib" ; then
+		  $ECHO "*** with $libname but no candidates were found. (...for regex pattern test)"
+		else
+		  $ECHO "*** with $libname and none of the candidates passed a file format test"
+		  $ECHO "*** using a regex pattern. Last file checked: $potlib"
+		fi
+	      fi
+	      ;;
+	    *)
+	      # Add a -L argument.
+	      newdeplibs="$newdeplibs $a_deplib"
+	      ;;
+	    esac
+	  done # Gone through all deplibs.
+	  ;;
+	none | unknown | *)
+	  newdeplibs=""
+	  tmp_deplibs=`$ECHO "X $deplibs" | $Xsed \
+	      -e 's/ -lc$//' -e 's/ -[LR][^ ]*//g'`
+	  if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then
+	    for i in $predeps $postdeps ; do
+	      # can't use Xsed below, because $i might contain '/'
+	      tmp_deplibs=`$ECHO "X $tmp_deplibs" | $Xsed -e "s,$i,,"`
+	    done
+	  fi
+	  if $ECHO "X $tmp_deplibs" | $Xsed -e 's/[	 ]//g' |
+	     $GREP . >/dev/null; then
+	    $ECHO
+	    if test "X$deplibs_check_method" = "Xnone"; then
+	      $ECHO "*** Warning: inter-library dependencies are not supported in this platform."
+	    else
+	      $ECHO "*** Warning: inter-library dependencies are not known to be supported."
+	    fi
+	    $ECHO "*** All declared inter-library dependencies are being dropped."
+	    droppeddeps=yes
+	  fi
+	  ;;
+	esac
+	versuffix=$versuffix_save
+	major=$major_save
+	release=$release_save
+	libname=$libname_save
+	name=$name_save
+
+	case $host in
+	*-*-rhapsody* | *-*-darwin1.[012])
+	  # On Rhapsody replace the C library with the System framework
+	  newdeplibs=`$ECHO "X $newdeplibs" | $Xsed -e 's/ -lc / System.ltframework /'`
+	  ;;
+	esac
+
+	if test "$droppeddeps" = yes; then
+	  if test "$module" = yes; then
+	    $ECHO
+	    $ECHO "*** Warning: libtool could not satisfy all declared inter-library"
+	    $ECHO "*** dependencies of module $libname.  Therefore, libtool will create"
+	    $ECHO "*** a static module, that should work as long as the dlopening"
+	    $ECHO "*** application is linked with the -dlopen flag."
+	    if test -z "$global_symbol_pipe"; then
+	      $ECHO
+	      $ECHO "*** However, this would only work if libtool was able to extract symbol"
+	      $ECHO "*** lists from a program, using \`nm' or equivalent, but libtool could"
+	      $ECHO "*** not find such a program.  So, this module is probably useless."
+	      $ECHO "*** \`nm' from GNU binutils and a full rebuild may help."
+	    fi
+	    if test "$build_old_libs" = no; then
+	      oldlibs="$output_objdir/$libname.$libext"
+	      build_libtool_libs=module
+	      build_old_libs=yes
+	    else
+	      build_libtool_libs=no
+	    fi
+	  else
+	    $ECHO "*** The inter-library dependencies that have been dropped here will be"
+	    $ECHO "*** automatically added whenever a program is linked with this library"
+	    $ECHO "*** or is declared to -dlopen it."
+
+	    if test "$allow_undefined" = no; then
+	      $ECHO
+	      $ECHO "*** Since this library must not contain undefined symbols,"
+	      $ECHO "*** because either the platform does not support them or"
+	      $ECHO "*** it was explicitly requested with -no-undefined,"
+	      $ECHO "*** libtool will only create a static version of it."
+	      if test "$build_old_libs" = no; then
+		oldlibs="$output_objdir/$libname.$libext"
+		build_libtool_libs=module
+		build_old_libs=yes
+	      else
+		build_libtool_libs=no
+	      fi
+	    fi
+	  fi
+	fi
+	# Done checking deplibs!
+	deplibs=$newdeplibs
+      fi
+      # Time to change all our "foo.ltframework" stuff back to "-framework foo"
+      case $host in
+	*-*-darwin*)
+	  newdeplibs=`$ECHO "X $newdeplibs" | $Xsed -e 's% \([^ $]*\).ltframework% -framework \1%g'`
+	  new_inherited_linker_flags=`$ECHO "X $new_inherited_linker_flags" | $Xsed -e 's% \([^ $]*\).ltframework% -framework \1%g'`
+	  deplibs=`$ECHO "X $deplibs" | $Xsed -e 's% \([^ $]*\).ltframework% -framework \1%g'`
+	  ;;
+      esac
+
+      # move library search paths that coincide with paths to not yet
+      # installed libraries to the beginning of the library search list
+      new_libs=
+      for path in $notinst_path; do
+	case " $new_libs " in
+	*" -L$path/$objdir "*) ;;
+	*)
+	  case " $deplibs " in
+	  *" -L$path/$objdir "*)
+	    new_libs="$new_libs -L$path/$objdir" ;;
+	  esac
+	  ;;
+	esac
+      done
+      for deplib in $deplibs; do
+	case $deplib in
+	-L*)
+	  case " $new_libs " in
+	  *" $deplib "*) ;;
+	  *) new_libs="$new_libs $deplib" ;;
+	  esac
+	  ;;
+	*) new_libs="$new_libs $deplib" ;;
+	esac
+      done
+      deplibs="$new_libs"
+
+      # All the library-specific variables (install_libdir is set above).
+      library_names=
+      old_library=
+      dlname=
+
+      # Test again, we may have decided not to build it any more
+      if test "$build_libtool_libs" = yes; then
+	if test "$hardcode_into_libs" = yes; then
+	  # Hardcode the library paths
+	  hardcode_libdirs=
+	  dep_rpath=
+	  rpath="$finalize_rpath"
+	  test "$mode" != relink && rpath="$compile_rpath$rpath"
+	  for libdir in $rpath; do
+	    if test -n "$hardcode_libdir_flag_spec"; then
+	      if test -n "$hardcode_libdir_separator"; then
+		if test -z "$hardcode_libdirs"; then
+		  hardcode_libdirs="$libdir"
+		else
+		  # Just accumulate the unique libdirs.
+		  case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
+		  *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
+		    ;;
+		  *)
+		    hardcode_libdirs="$hardcode_libdirs$hardcode_libdir_separator$libdir"
+		    ;;
+		  esac
+		fi
+	      else
+		eval flag=\"$hardcode_libdir_flag_spec\"
+		dep_rpath="$dep_rpath $flag"
+	      fi
+	    elif test -n "$runpath_var"; then
+	      case "$perm_rpath " in
+	      *" $libdir "*) ;;
+	      *) perm_rpath="$perm_rpath $libdir" ;;
+	      esac
+	    fi
+	  done
+	  # Substitute the hardcoded libdirs into the rpath.
+	  if test -n "$hardcode_libdir_separator" &&
+	     test -n "$hardcode_libdirs"; then
+	    libdir="$hardcode_libdirs"
+	    if test -n "$hardcode_libdir_flag_spec_ld"; then
+	      eval dep_rpath=\"$hardcode_libdir_flag_spec_ld\"
+	    else
+	      eval dep_rpath=\"$hardcode_libdir_flag_spec\"
+	    fi
+	  fi
+	  if test -n "$runpath_var" && test -n "$perm_rpath"; then
+	    # We should set the runpath_var.
+	    rpath=
+	    for dir in $perm_rpath; do
+	      rpath="$rpath$dir:"
+	    done
+	    eval "$runpath_var='$rpath\$$runpath_var'; export $runpath_var"
+	  fi
+	  test -n "$dep_rpath" && deplibs="$dep_rpath $deplibs"
+	fi
+
+	shlibpath="$finalize_shlibpath"
+	test "$mode" != relink && shlibpath="$compile_shlibpath$shlibpath"
+	if test -n "$shlibpath"; then
+	  eval "$shlibpath_var='$shlibpath\$$shlibpath_var'; export $shlibpath_var"
+	fi
+
+	# Get the real and link names of the library.
+	eval shared_ext=\"$shrext_cmds\"
+	eval library_names=\"$library_names_spec\"
+	set dummy $library_names
+	shift
+	realname="$1"
+	shift
+
+	if test -n "$soname_spec"; then
+	  eval soname=\"$soname_spec\"
+	else
+	  soname="$realname"
+	fi
+	if test -z "$dlname"; then
+	  dlname=$soname
+	fi
+
+	lib="$output_objdir/$realname"
+	linknames=
+	for link
+	do
+	  linknames="$linknames $link"
+	done
+
+	# Use standard objects if they are pic
+	test -z "$pic_flag" && libobjs=`$ECHO "X$libobjs" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP`
+	test "X$libobjs" = "X " && libobjs=
+
+	delfiles=
+	if test -n "$export_symbols" && test -n "$include_expsyms"; then
+	  $opt_dry_run || cp "$export_symbols" "$output_objdir/$libname.uexp"
+	  export_symbols="$output_objdir/$libname.uexp"
+	  delfiles="$delfiles $export_symbols"
+	fi
+
+	orig_export_symbols=
+	case $host_os in
+	cygwin* | mingw* | cegcc*)
+	  if test -n "$export_symbols" && test -z "$export_symbols_regex"; then
+	    # exporting using user supplied symfile
+	    if test "x`$SED 1q $export_symbols`" != xEXPORTS; then
+	      # and it's NOT already a .def file. Must figure out
+	      # which of the given symbols are data symbols and tag
+	      # them as such. So, trigger use of export_symbols_cmds.
+	      # export_symbols gets reassigned inside the "prepare
+	      # the list of exported symbols" if statement, so the
+	      # include_expsyms logic still works.
+	      orig_export_symbols="$export_symbols"
+	      export_symbols=
+	      always_export_symbols=yes
+	    fi
+	  fi
+	  ;;
+	esac
+
+	# Prepare the list of exported symbols
+	if test -z "$export_symbols"; then
+	  if test "$always_export_symbols" = yes || test -n "$export_symbols_regex"; then
+	    func_verbose "generating symbol list for \`$libname.la'"
+	    export_symbols="$output_objdir/$libname.exp"
+	    $opt_dry_run || $RM $export_symbols
+	    cmds=$export_symbols_cmds
+	    save_ifs="$IFS"; IFS='~'
+	    for cmd in $cmds; do
+	      IFS="$save_ifs"
+	      eval cmd=\"$cmd\"
+	      func_len " $cmd"
+	      len=$func_len_result
+	      if test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
+		func_show_eval "$cmd" 'exit $?'
+		skipped_export=false
+	      else
+		# The command line is too long to execute in one step.
+		func_verbose "using reloadable object file for export list..."
+		skipped_export=:
+		# Break out early, otherwise skipped_export may be
+		# set to false by a later but shorter cmd.
+		break
+	      fi
+	    done
+	    IFS="$save_ifs"
+	    if test -n "$export_symbols_regex" && test "X$skipped_export" != "X:"; then
+	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
+	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
+	    fi
+	  fi
+	fi
+
+	if test -n "$export_symbols" && test -n "$include_expsyms"; then
+	  tmp_export_symbols="$export_symbols"
+	  test -n "$orig_export_symbols" && tmp_export_symbols="$orig_export_symbols"
+	  $opt_dry_run || eval '$ECHO "X$include_expsyms" | $Xsed | $SP2NL >> "$tmp_export_symbols"'
+	fi
+
+	if test "X$skipped_export" != "X:" && test -n "$orig_export_symbols"; then
+	  # The given exports_symbols file has to be filtered, so filter it.
+	  func_verbose "filter symbol list for \`$libname.la' to tag DATA exports"
+	  # FIXME: $output_objdir/$libname.filter potentially contains lots of
+	  # 's' commands which not all seds can handle. GNU sed should be fine
+	  # though. Also, the filter scales superlinearly with the number of
+	  # global variables. join(1) would be nice here, but unfortunately
+	  # isn't a blessed tool.
+	  $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
+	  delfiles="$delfiles $export_symbols $output_objdir/$libname.filter"
+	  export_symbols=$output_objdir/$libname.def
+	  $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
+	fi
+
+	tmp_deplibs=
+	for test_deplib in $deplibs; do
+	  case " $convenience " in
+	  *" $test_deplib "*) ;;
+	  *)
+	    tmp_deplibs="$tmp_deplibs $test_deplib"
+	    ;;
+	  esac
+	done
+	deplibs="$tmp_deplibs"
+
+	if test -n "$convenience"; then
+	  if test -n "$whole_archive_flag_spec" &&
+	    test "$compiler_needs_object" = yes &&
+	    test -z "$libobjs"; then
+	    # extract the archives, so we have objects to list.
+	    # TODO: could optimize this to just extract one archive.
+	    whole_archive_flag_spec=
+	  fi
+	  if test -n "$whole_archive_flag_spec"; then
+	    save_libobjs=$libobjs
+	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
+	    test "X$libobjs" = "X " && libobjs=
+	  else
+	    gentop="$output_objdir/${outputname}x"
+	    generated="$generated $gentop"
+
+	    func_extract_archives $gentop $convenience
+	    libobjs="$libobjs $func_extract_archives_result"
+	    test "X$libobjs" = "X " && libobjs=
+	  fi
+	fi
+
+	if test "$thread_safe" = yes && test -n "$thread_safe_flag_spec"; then
+	  eval flag=\"$thread_safe_flag_spec\"
+	  linker_flags="$linker_flags $flag"
+	fi
+
+	# Make a backup of the uninstalled library when relinking
+	if test "$mode" = relink; then
+	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}U && $MV $realname ${realname}U)' || exit $?
+	fi
+
+	# Do each of the archive commands.
+	if test "$module" = yes && test -n "$module_cmds" ; then
+	  if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
+	    eval test_cmds=\"$module_expsym_cmds\"
+	    cmds=$module_expsym_cmds
+	  else
+	    eval test_cmds=\"$module_cmds\"
+	    cmds=$module_cmds
+	  fi
+	else
+	  if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
+	    eval test_cmds=\"$archive_expsym_cmds\"
+	    cmds=$archive_expsym_cmds
+	  else
+	    eval test_cmds=\"$archive_cmds\"
+	    cmds=$archive_cmds
+	  fi
+	fi
+
+	if test "X$skipped_export" != "X:" &&
+	   func_len " $test_cmds" &&
+	   len=$func_len_result &&
+	   test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
+	  :
+	else
+	  # The command line is too long to link in one step, link piecewise
+	  # or, if using GNU ld and skipped_export is not :, use a linker
+	  # script.
+
+	  # Save the value of $output and $libobjs because we want to
+	  # use them later.  If we have whole_archive_flag_spec, we
+	  # want to use save_libobjs as it was before
+	  # whole_archive_flag_spec was expanded, because we can't
+	  # assume the linker understands whole_archive_flag_spec.
+	  # This may have to be revisited, in case too many
+	  # convenience libraries get linked in and end up exceeding
+	  # the spec.
+	  if test -z "$convenience" || test -z "$whole_archive_flag_spec"; then
+	    save_libobjs=$libobjs
+	  fi
+	  save_output=$output
+	  output_la=`$ECHO "X$output" | $Xsed -e "$basename"`
+
+	  # Clear the reloadable object creation command queue and
+	  # initialize k to one.
+	  test_cmds=
+	  concat_cmds=
+	  objlist=
+	  last_robj=
+	  k=1
+
+	  if test -n "$save_libobjs" && test "X$skipped_export" != "X:" && test "$with_gnu_ld" = yes; then
+	    output=${output_objdir}/${output_la}.lnkscript
+	    func_verbose "creating GNU ld script: $output"
+	    $ECHO 'INPUT (' > $output
+	    for obj in $save_libobjs
+	    do
+	      $ECHO "$obj" >> $output
+	    done
+	    $ECHO ')' >> $output
+	    delfiles="$delfiles $output"
+	  elif test -n "$save_libobjs" && test "X$skipped_export" != "X:" && test "X$file_list_spec" != X; then
+	    output=${output_objdir}/${output_la}.lnk
+	    func_verbose "creating linker input file list: $output"
+	    : > $output
+	    set x $save_libobjs
+	    shift
+	    firstobj=
+	    if test "$compiler_needs_object" = yes; then
+	      firstobj="$1 "
+	      shift
+	    fi
+	    for obj
+	    do
+	      $ECHO "$obj" >> $output
+	    done
+	    delfiles="$delfiles $output"
+	    output=$firstobj\"$file_list_spec$output\"
+	  else
+	    if test -n "$save_libobjs"; then
+	      func_verbose "creating reloadable object files..."
+	      output=$output_objdir/$output_la-${k}.$objext
+	      eval test_cmds=\"$reload_cmds\"
+	      func_len " $test_cmds"
+	      len0=$func_len_result
+	      len=$len0
+
+	      # Loop over the list of objects to be linked.
+	      for obj in $save_libobjs
+	      do
+		func_len " $obj"
+		func_arith $len + $func_len_result
+		len=$func_arith_result
+		if test "X$objlist" = X ||
+		   test "$len" -lt "$max_cmd_len"; then
+		  func_append objlist " $obj"
+		else
+		  # The command $test_cmds is almost too long, add a
+		  # command to the queue.
+		  if test "$k" -eq 1 ; then
+		    # The first file doesn't have a previous command to add.
+		    eval concat_cmds=\"$reload_cmds $objlist $last_robj\"
+		  else
+		    # All subsequent reloadable object files will link in
+		    # the last one created.
+		    eval concat_cmds=\"\$concat_cmds~$reload_cmds $objlist $last_robj~\$RM $last_robj\"
+		  fi
+		  last_robj=$output_objdir/$output_la-${k}.$objext
+		  func_arith $k + 1
+		  k=$func_arith_result
+		  output=$output_objdir/$output_la-${k}.$objext
+		  objlist=$obj
+		  func_len " $last_robj"
+		  func_arith $len0 + $func_len_result
+		  len=$func_arith_result
+		fi
+	      done
+	      # Handle the remaining objects by creating one last
+	      # reloadable object file.  All subsequent reloadable object
+	      # files will link in the last one created.
+	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
+	      eval concat_cmds=\"\${concat_cmds}$reload_cmds $objlist $last_robj\"
+	      if test -n "$last_robj"; then
+	        eval concat_cmds=\"\${concat_cmds}~\$RM $last_robj\"
+	      fi
+	      delfiles="$delfiles $output"
+
+	    else
+	      output=
+	    fi
+
+	    if ${skipped_export-false}; then
+	      func_verbose "generating symbol list for \`$libname.la'"
+	      export_symbols="$output_objdir/$libname.exp"
+	      $opt_dry_run || $RM $export_symbols
+	      libobjs=$output
+	      # Append the command to create the export file.
+	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
+	      eval concat_cmds=\"\$concat_cmds$export_symbols_cmds\"
+	      if test -n "$last_robj"; then
+		eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
+	      fi
+	    fi
+
+	    test -n "$save_libobjs" &&
+	      func_verbose "creating a temporary reloadable object file: $output"
+
+	    # Loop through the commands generated above and execute them.
+	    save_ifs="$IFS"; IFS='~'
+	    for cmd in $concat_cmds; do
+	      IFS="$save_ifs"
+	      $opt_silent || {
+		  func_quote_for_expand "$cmd"
+		  eval "func_echo $func_quote_for_expand_result"
+	      }
+	      $opt_dry_run || eval "$cmd" || {
+		lt_exit=$?
+
+		# Restore the uninstalled library and exit
+		if test "$mode" = relink; then
+		  ( cd "$output_objdir" && \
+		    $RM "${realname}T" && \
+		    $MV "${realname}U" "$realname" )
+		fi
+
+		exit $lt_exit
+	      }
+	    done
+	    IFS="$save_ifs"
+
+	    if test -n "$export_symbols_regex" && ${skipped_export-false}; then
+	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
+	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
+	    fi
+	  fi
+
+          if ${skipped_export-false}; then
+	    if test -n "$export_symbols" && test -n "$include_expsyms"; then
+	      tmp_export_symbols="$export_symbols"
+	      test -n "$orig_export_symbols" && tmp_export_symbols="$orig_export_symbols"
+	      $opt_dry_run || eval '$ECHO "X$include_expsyms" | $Xsed | $SP2NL >> "$tmp_export_symbols"'
+	    fi
+
+	    if test -n "$orig_export_symbols"; then
+	      # The given exports_symbols file has to be filtered, so filter it.
+	      func_verbose "filter symbol list for \`$libname.la' to tag DATA exports"
+	      # FIXME: $output_objdir/$libname.filter potentially contains lots of
+	      # 's' commands which not all seds can handle. GNU sed should be fine
+	      # though. Also, the filter scales superlinearly with the number of
+	      # global variables. join(1) would be nice here, but unfortunately
+	      # isn't a blessed tool.
+	      $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
+	      delfiles="$delfiles $export_symbols $output_objdir/$libname.filter"
+	      export_symbols=$output_objdir/$libname.def
+	      $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
+	    fi
+	  fi
+
+	  libobjs=$output
+	  # Restore the value of output.
+	  output=$save_output
+
+	  if test -n "$convenience" && test -n "$whole_archive_flag_spec"; then
+	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
+	    test "X$libobjs" = "X " && libobjs=
+	  fi
+	  # Expand the library linking commands again to reset the
+	  # value of $libobjs for piecewise linking.
+
+	  # Do each of the archive commands.
+	  if test "$module" = yes && test -n "$module_cmds" ; then
+	    if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
+	      cmds=$module_expsym_cmds
+	    else
+	      cmds=$module_cmds
+	    fi
+	  else
+	    if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
+	      cmds=$archive_expsym_cmds
+	    else
+	      cmds=$archive_cmds
+	    fi
+	  fi
+	fi
+
+	if test -n "$delfiles"; then
+	  # Append the command to remove temporary files to $cmds.
+	  eval cmds=\"\$cmds~\$RM $delfiles\"
+	fi
+
+	# Add any objects from preloaded convenience libraries
+	if test -n "$dlprefiles"; then
+	  gentop="$output_objdir/${outputname}x"
+	  generated="$generated $gentop"
+
+	  func_extract_archives $gentop $dlprefiles
+	  libobjs="$libobjs $func_extract_archives_result"
+	  test "X$libobjs" = "X " && libobjs=
+	fi
+
+	save_ifs="$IFS"; IFS='~'
+	for cmd in $cmds; do
+	  IFS="$save_ifs"
+	  eval cmd=\"$cmd\"
+	  $opt_silent || {
+	    func_quote_for_expand "$cmd"
+	    eval "func_echo $func_quote_for_expand_result"
+	  }
+	  $opt_dry_run || eval "$cmd" || {
+	    lt_exit=$?
+
+	    # Restore the uninstalled library and exit
+	    if test "$mode" = relink; then
+	      ( cd "$output_objdir" && \
+	        $RM "${realname}T" && \
+		$MV "${realname}U" "$realname" )
+	    fi
+
+	    exit $lt_exit
+	  }
+	done
+	IFS="$save_ifs"
+
+	# Restore the uninstalled library and exit
+	if test "$mode" = relink; then
+	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}T && $MV $realname ${realname}T && $MV ${realname}U $realname)' || exit $?
+
+	  if test -n "$convenience"; then
+	    if test -z "$whole_archive_flag_spec"; then
+	      func_show_eval '${RM}r "$gentop"'
+	    fi
+	  fi
+
+	  exit $EXIT_SUCCESS
+	fi
+
+	# Create links to the real library.
+	for linkname in $linknames; do
+	  if test "$realname" != "$linkname"; then
+	    func_show_eval '(cd "$output_objdir" && $RM "$linkname" && $LN_S "$realname" "$linkname")' 'exit $?'
+	  fi
+	done
+
+	# If -module or -export-dynamic was specified, set the dlname.
+	if test "$module" = yes || test "$export_dynamic" = yes; then
+	  # On all known operating systems, these are identical.
+	  dlname="$soname"
+	fi
+      fi
+      ;;
+
+    obj)
+      if test -n "$dlfiles$dlprefiles" || test "$dlself" != no; then
+	func_warning "\`-dlopen' is ignored for objects"
+      fi
+
+      case " $deplibs" in
+      *\ -l* | *\ -L*)
+	func_warning "\`-l' and \`-L' are ignored for objects" ;;
+      esac
+
+      test -n "$rpath" && \
+	func_warning "\`-rpath' is ignored for objects"
+
+      test -n "$xrpath" && \
+	func_warning "\`-R' is ignored for objects"
+
+      test -n "$vinfo" && \
+	func_warning "\`-version-info' is ignored for objects"
+
+      test -n "$release" && \
+	func_warning "\`-release' is ignored for objects"
+
+      case $output in
+      *.lo)
+	test -n "$objs$old_deplibs" && \
+	  func_fatal_error "cannot build library object \`$output' from non-libtool objects"
+
+	libobj=$output
+	func_lo2o "$libobj"
+	obj=$func_lo2o_result
+	;;
+      *)
+	libobj=
+	obj="$output"
+	;;
+      esac
+
+      # Delete the old objects.
+      $opt_dry_run || $RM $obj $libobj
+
+      # Objects from convenience libraries.  This assumes
+      # single-version convenience libraries.  Whenever we create
+      # different ones for PIC/non-PIC, this we'll have to duplicate
+      # the extraction.
+      reload_conv_objs=
+      gentop=
+      # reload_cmds runs $LD directly, so let us get rid of
+      # -Wl from whole_archive_flag_spec and hope we can get by with
+      # turning comma into space..
+      wl=
+
+      if test -n "$convenience"; then
+	if test -n "$whole_archive_flag_spec"; then
+	  eval tmp_whole_archive_flags=\"$whole_archive_flag_spec\"
+	  reload_conv_objs=$reload_objs\ `$ECHO "X$tmp_whole_archive_flags" | $Xsed -e 's|,| |g'`
+	else
+	  gentop="$output_objdir/${obj}x"
+	  generated="$generated $gentop"
+
+	  func_extract_archives $gentop $convenience
+	  reload_conv_objs="$reload_objs $func_extract_archives_result"
+	fi
+      fi
+
+      # Create the old-style object.
+      reload_objs="$objs$old_deplibs "`$ECHO "X$libobjs" | $SP2NL | $Xsed -e '/\.'${libext}$'/d' -e '/\.lib$/d' -e "$lo2o" | $NL2SP`" $reload_conv_objs" ### testsuite: skip nested quoting test
+
+      output="$obj"
+      func_execute_cmds "$reload_cmds" 'exit $?'
+
+      # Exit if we aren't doing a library object file.
+      if test -z "$libobj"; then
+	if test -n "$gentop"; then
+	  func_show_eval '${RM}r "$gentop"'
+	fi
+
+	exit $EXIT_SUCCESS
+      fi
+
+      if test "$build_libtool_libs" != yes; then
+	if test -n "$gentop"; then
+	  func_show_eval '${RM}r "$gentop"'
+	fi
+
+	# Create an invalid libtool object if no PIC, so that we don't
+	# accidentally link it into a program.
+	# $show "echo timestamp > $libobj"
+	# $opt_dry_run || eval "echo timestamp > $libobj" || exit $?
+	exit $EXIT_SUCCESS
+      fi
+
+      if test -n "$pic_flag" || test "$pic_mode" != default; then
+	# Only do commands if we really have different PIC objects.
+	reload_objs="$libobjs $reload_conv_objs"
+	output="$libobj"
+	func_execute_cmds "$reload_cmds" 'exit $?'
+      fi
+
+      if test -n "$gentop"; then
+	func_show_eval '${RM}r "$gentop"'
+      fi
+
+      exit $EXIT_SUCCESS
+      ;;
+
+    prog)
+      case $host in
+	*cygwin*) func_stripname '' '.exe' "$output"
+	          output=$func_stripname_result.exe;;
+      esac
+      test -n "$vinfo" && \
+	func_warning "\`-version-info' is ignored for programs"
+
+      test -n "$release" && \
+	func_warning "\`-release' is ignored for programs"
+
+      test "$preload" = yes \
+        && test "$dlopen_support" = unknown \
+	&& test "$dlopen_self" = unknown \
+	&& test "$dlopen_self_static" = unknown && \
+	  func_warning "\`LT_INIT([dlopen])' not used. Assuming no dlopen support."
+
+      case $host in
+      *-*-rhapsody* | *-*-darwin1.[012])
+	# On Rhapsody replace the C library is the System framework
+	compile_deplibs=`$ECHO "X $compile_deplibs" | $Xsed -e 's/ -lc / System.ltframework /'`
+	finalize_deplibs=`$ECHO "X $finalize_deplibs" | $Xsed -e 's/ -lc / System.ltframework /'`
+	;;
+      esac
+
+      case $host in
+      *-*-darwin*)
+	# Don't allow lazy linking, it breaks C++ global constructors
+	# But is supposedly fixed on 10.4 or later (yay!).
+	if test "$tagname" = CXX ; then
+	  case ${MACOSX_DEPLOYMENT_TARGET-10.0} in
+	    10.[0123])
+	      compile_command="$compile_command ${wl}-bind_at_load"
+	      finalize_command="$finalize_command ${wl}-bind_at_load"
+	    ;;
+	  esac
+	fi
+	# Time to change all our "foo.ltframework" stuff back to "-framework foo"
+	compile_deplibs=`$ECHO "X $compile_deplibs" | $Xsed -e 's% \([^ $]*\).ltframework% -framework \1%g'`
+	finalize_deplibs=`$ECHO "X $finalize_deplibs" | $Xsed -e 's% \([^ $]*\).ltframework% -framework \1%g'`
+	;;
+      esac
+
+
+      # move library search paths that coincide with paths to not yet
+      # installed libraries to the beginning of the library search list
+      new_libs=
+      for path in $notinst_path; do
+	case " $new_libs " in
+	*" -L$path/$objdir "*) ;;
+	*)
+	  case " $compile_deplibs " in
+	  *" -L$path/$objdir "*)
+	    new_libs="$new_libs -L$path/$objdir" ;;
+	  esac
+	  ;;
+	esac
+      done
+      for deplib in $compile_deplibs; do
+	case $deplib in
+	-L*)
+	  case " $new_libs " in
+	  *" $deplib "*) ;;
+	  *) new_libs="$new_libs $deplib" ;;
+	  esac
+	  ;;
+	*) new_libs="$new_libs $deplib" ;;
+	esac
+      done
+      compile_deplibs="$new_libs"
+
+
+      compile_command="$compile_command $compile_deplibs"
+      finalize_command="$finalize_command $finalize_deplibs"
+
+      if test -n "$rpath$xrpath"; then
+	# If the user specified any rpath flags, then add them.
+	for libdir in $rpath $xrpath; do
+	  # This is the magic to use -rpath.
+	  case "$finalize_rpath " in
+	  *" $libdir "*) ;;
+	  *) finalize_rpath="$finalize_rpath $libdir" ;;
+	  esac
+	done
+      fi
+
+      # Now hardcode the library paths
+      rpath=
+      hardcode_libdirs=
+      for libdir in $compile_rpath $finalize_rpath; do
+	if test -n "$hardcode_libdir_flag_spec"; then
+	  if test -n "$hardcode_libdir_separator"; then
+	    if test -z "$hardcode_libdirs"; then
+	      hardcode_libdirs="$libdir"
+	    else
+	      # Just accumulate the unique libdirs.
+	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
+	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
+		;;
+	      *)
+		hardcode_libdirs="$hardcode_libdirs$hardcode_libdir_separator$libdir"
+		;;
+	      esac
+	    fi
+	  else
+	    eval flag=\"$hardcode_libdir_flag_spec\"
+	    rpath="$rpath $flag"
+	  fi
+	elif test -n "$runpath_var"; then
+	  case "$perm_rpath " in
+	  *" $libdir "*) ;;
+	  *) perm_rpath="$perm_rpath $libdir" ;;
+	  esac
+	fi
+	case $host in
+	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
+	  testbindir=`${ECHO} "$libdir" | ${SED} -e 's*/lib$*/bin*'`
+	  case :$dllsearchpath: in
+	  *":$libdir:"*) ;;
+	  ::) dllsearchpath=$libdir;;
+	  *) dllsearchpath="$dllsearchpath:$libdir";;
+	  esac
+	  case :$dllsearchpath: in
+	  *":$testbindir:"*) ;;
+	  ::) dllsearchpath=$testbindir;;
+	  *) dllsearchpath="$dllsearchpath:$testbindir";;
+	  esac
+	  ;;
+	esac
+      done
+      # Substitute the hardcoded libdirs into the rpath.
+      if test -n "$hardcode_libdir_separator" &&
+	 test -n "$hardcode_libdirs"; then
+	libdir="$hardcode_libdirs"
+	eval rpath=\" $hardcode_libdir_flag_spec\"
+      fi
+      compile_rpath="$rpath"
+
+      rpath=
+      hardcode_libdirs=
+      for libdir in $finalize_rpath; do
+	if test -n "$hardcode_libdir_flag_spec"; then
+	  if test -n "$hardcode_libdir_separator"; then
+	    if test -z "$hardcode_libdirs"; then
+	      hardcode_libdirs="$libdir"
+	    else
+	      # Just accumulate the unique libdirs.
+	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
+	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
+		;;
+	      *)
+		hardcode_libdirs="$hardcode_libdirs$hardcode_libdir_separator$libdir"
+		;;
+	      esac
+	    fi
+	  else
+	    eval flag=\"$hardcode_libdir_flag_spec\"
+	    rpath="$rpath $flag"
+	  fi
+	elif test -n "$runpath_var"; then
+	  case "$finalize_perm_rpath " in
+	  *" $libdir "*) ;;
+	  *) finalize_perm_rpath="$finalize_perm_rpath $libdir" ;;
+	  esac
+	fi
+      done
+      # Substitute the hardcoded libdirs into the rpath.
+      if test -n "$hardcode_libdir_separator" &&
+	 test -n "$hardcode_libdirs"; then
+	libdir="$hardcode_libdirs"
+	eval rpath=\" $hardcode_libdir_flag_spec\"
+      fi
+      finalize_rpath="$rpath"
+
+      if test -n "$libobjs" && test "$build_old_libs" = yes; then
+	# Transform all the library objects into standard objects.
+	compile_command=`$ECHO "X$compile_command" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP`
+	finalize_command=`$ECHO "X$finalize_command" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP`
+      fi
+
+      func_generate_dlsyms "$outputname" "@PROGRAM@" "no"
+
+      # template prelinking step
+      if test -n "$prelink_cmds"; then
+	func_execute_cmds "$prelink_cmds" 'exit $?'
+      fi
+
+      wrappers_required=yes
+      case $host in
+      *cygwin* | *mingw* )
+        if test "$build_libtool_libs" != yes; then
+          wrappers_required=no
+        fi
+        ;;
+      *cegcc)
+        # Disable wrappers for cegcc, we are cross compiling anyway.
+        wrappers_required=no
+        ;;
+      *)
+        if test "$need_relink" = no || test "$build_libtool_libs" != yes; then
+          wrappers_required=no
+        fi
+        ;;
+      esac
+      if test "$wrappers_required" = no; then
+	# Replace the output file specification.
+	compile_command=`$ECHO "X$compile_command" | $Xsed -e 's%@OUTPUT@%'"$output"'%g'`
+	link_command="$compile_command$compile_rpath"
+
+	# We have no uninstalled library dependencies, so finalize right now.
+	exit_status=0
+	func_show_eval "$link_command" 'exit_status=$?'
+
+	# Delete the generated files.
+	if test -f "$output_objdir/${outputname}S.${objext}"; then
+	  func_show_eval '$RM "$output_objdir/${outputname}S.${objext}"'
+	fi
+
+	exit $exit_status
+      fi
+
+      if test -n "$compile_shlibpath$finalize_shlibpath"; then
+	compile_command="$shlibpath_var=\"$compile_shlibpath$finalize_shlibpath\$$shlibpath_var\" $compile_command"
+      fi
+      if test -n "$finalize_shlibpath"; then
+	finalize_command="$shlibpath_var=\"$finalize_shlibpath\$$shlibpath_var\" $finalize_command"
+      fi
+
+      compile_var=
+      finalize_var=
+      if test -n "$runpath_var"; then
+	if test -n "$perm_rpath"; then
+	  # We should set the runpath_var.
+	  rpath=
+	  for dir in $perm_rpath; do
+	    rpath="$rpath$dir:"
+	  done
+	  compile_var="$runpath_var=\"$rpath\$$runpath_var\" "
+	fi
+	if test -n "$finalize_perm_rpath"; then
+	  # We should set the runpath_var.
+	  rpath=
+	  for dir in $finalize_perm_rpath; do
+	    rpath="$rpath$dir:"
+	  done
+	  finalize_var="$runpath_var=\"$rpath\$$runpath_var\" "
+	fi
+      fi
+
+      if test "$no_install" = yes; then
+	# We don't need to create a wrapper script.
+	link_command="$compile_var$compile_command$compile_rpath"
+	# Replace the output file specification.
+	link_command=`$ECHO "X$link_command" | $Xsed -e 's%@OUTPUT@%'"$output"'%g'`
+	# Delete the old output file.
+	$opt_dry_run || $RM $output
+	# Link the executable and exit
+	func_show_eval "$link_command" 'exit $?'
+	exit $EXIT_SUCCESS
+      fi
+
+      if test "$hardcode_action" = relink; then
+	# Fast installation is not supported
+	link_command="$compile_var$compile_command$compile_rpath"
+	relink_command="$finalize_var$finalize_command$finalize_rpath"
+
+	func_warning "this platform does not like uninstalled shared libraries"
+	func_warning "\`$output' will be relinked during installation"
+      else
+	if test "$fast_install" != no; then
+	  link_command="$finalize_var$compile_command$finalize_rpath"
+	  if test "$fast_install" = yes; then
+	    relink_command=`$ECHO "X$compile_var$compile_command$compile_rpath" | $Xsed -e 's%@OUTPUT@%\$progdir/\$file%g'`
+	  else
+	    # fast_install is set to needless
+	    relink_command=
+	  fi
+	else
+	  link_command="$compile_var$compile_command$compile_rpath"
+	  relink_command="$finalize_var$finalize_command$finalize_rpath"
+	fi
+      fi
+
+      # Replace the output file specification.
+      link_command=`$ECHO "X$link_command" | $Xsed -e 's%@OUTPUT@%'"$output_objdir/$outputname"'%g'`
+
+      # Delete the old output files.
+      $opt_dry_run || $RM $output $output_objdir/$outputname $output_objdir/lt-$outputname
+
+      func_show_eval "$link_command" 'exit $?'
+
+      # Now create the wrapper script.
+      func_verbose "creating $output"
+
+      # Quote the relink command for shipping.
+      if test -n "$relink_command"; then
+	# Preserve any variables that may affect compiler behavior
+	for var in $variables_saved_for_relink; do
+	  if eval test -z \"\${$var+set}\"; then
+	    relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
+	  elif eval var_value=\$$var; test -z "$var_value"; then
+	    relink_command="$var=; export $var; $relink_command"
+	  else
+	    func_quote_for_eval "$var_value"
+	    relink_command="$var=$func_quote_for_eval_result; export $var; $relink_command"
+	  fi
+	done
+	relink_command="(cd `pwd`; $relink_command)"
+	relink_command=`$ECHO "X$relink_command" | $Xsed -e "$sed_quote_subst"`
+      fi
+
+      # Quote $ECHO for shipping.
+      if test "X$ECHO" = "X$SHELL $progpath --fallback-echo"; then
+	case $progpath in
+	[\\/]* | [A-Za-z]:[\\/]*) qecho="$SHELL $progpath --fallback-echo";;
+	*) qecho="$SHELL `pwd`/$progpath --fallback-echo";;
+	esac
+	qecho=`$ECHO "X$qecho" | $Xsed -e "$sed_quote_subst"`
+      else
+	qecho=`$ECHO "X$ECHO" | $Xsed -e "$sed_quote_subst"`
+      fi
+
+      # Only actually do things if not in dry run mode.
+      $opt_dry_run || {
+	# win32 will think the script is a binary if it has
+	# a .exe suffix, so we strip it off here.
+	case $output in
+	  *.exe) func_stripname '' '.exe' "$output"
+	         output=$func_stripname_result ;;
+	esac
+	# test for cygwin because mv fails w/o .exe extensions
+	case $host in
+	  *cygwin*)
+	    exeext=.exe
+	    func_stripname '' '.exe' "$outputname"
+	    outputname=$func_stripname_result ;;
+	  *) exeext= ;;
+	esac
+	case $host in
+	  *cygwin* | *mingw* )
+	    func_dirname_and_basename "$output" "" "."
+	    output_name=$func_basename_result
+	    output_path=$func_dirname_result
+	    cwrappersource="$output_path/$objdir/lt-$output_name.c"
+	    cwrapper="$output_path/$output_name.exe"
+	    $RM $cwrappersource $cwrapper
+	    trap "$RM $cwrappersource $cwrapper; exit $EXIT_FAILURE" 1 2 15
+
+	    func_emit_cwrapperexe_src > $cwrappersource
+
+	    # The wrapper executable is built using the $host compiler,
+	    # because it contains $host paths and files. If cross-
+	    # compiling, it, like the target executable, must be
+	    # executed on the $host or under an emulation environment.
+	    $opt_dry_run || {
+	      $LTCC $LTCFLAGS -o $cwrapper $cwrappersource
+	      $STRIP $cwrapper
+	    }
+
+	    # Now, create the wrapper script for func_source use:
+	    func_ltwrapper_scriptname $cwrapper
+	    $RM $func_ltwrapper_scriptname_result
+	    trap "$RM $func_ltwrapper_scriptname_result; exit $EXIT_FAILURE" 1 2 15
+	    $opt_dry_run || {
+	      # note: this script will not be executed, so do not chmod.
+	      if test "x$build" = "x$host" ; then
+		$cwrapper --lt-dump-script > $func_ltwrapper_scriptname_result
+	      else
+		func_emit_wrapper no > $func_ltwrapper_scriptname_result
+	      fi
+	    }
+	  ;;
+	  * )
+	    $RM $output
+	    trap "$RM $output; exit $EXIT_FAILURE" 1 2 15
+
+	    func_emit_wrapper no > $output
+	    chmod +x $output
+	  ;;
+	esac
+      }
+      exit $EXIT_SUCCESS
+      ;;
+    esac
+
+    # See if we need to build an old-fashioned archive.
+    for oldlib in $oldlibs; do
+
+      if test "$build_libtool_libs" = convenience; then
+	oldobjs="$libobjs_save $symfileobj"
+	addlibs="$convenience"
+	build_libtool_libs=no
+      else
+	if test "$build_libtool_libs" = module; then
+	  oldobjs="$libobjs_save"
+	  build_libtool_libs=no
+	else
+	  oldobjs="$old_deplibs $non_pic_objects"
+	  if test "$preload" = yes && test -f "$symfileobj"; then
+	    oldobjs="$oldobjs $symfileobj"
+	  fi
+	fi
+	addlibs="$old_convenience"
+      fi
+
+      if test -n "$addlibs"; then
+	gentop="$output_objdir/${outputname}x"
+	generated="$generated $gentop"
+
+	func_extract_archives $gentop $addlibs
+	oldobjs="$oldobjs $func_extract_archives_result"
+      fi
+
+      # Do each command in the archive commands.
+      if test -n "$old_archive_from_new_cmds" && test "$build_libtool_libs" = yes; then
+	cmds=$old_archive_from_new_cmds
+      else
+
+	# Add any objects from preloaded convenience libraries
+	if test -n "$dlprefiles"; then
+	  gentop="$output_objdir/${outputname}x"
+	  generated="$generated $gentop"
+
+	  func_extract_archives $gentop $dlprefiles
+	  oldobjs="$oldobjs $func_extract_archives_result"
+	fi
+
+	# POSIX demands no paths to be encoded in archives.  We have
+	# to avoid creating archives with duplicate basenames if we
+	# might have to extract them afterwards, e.g., when creating a
+	# static archive out of a convenience library, or when linking
+	# the entirety of a libtool archive into another (currently
+	# not supported by libtool).
+	if (for obj in $oldobjs
+	    do
+	      func_basename "$obj"
+	      $ECHO "$func_basename_result"
+	    done | sort | sort -uc >/dev/null 2>&1); then
+	  :
+	else
+	  $ECHO "copying selected object files to avoid basename conflicts..."
+	  gentop="$output_objdir/${outputname}x"
+	  generated="$generated $gentop"
+	  func_mkdir_p "$gentop"
+	  save_oldobjs=$oldobjs
+	  oldobjs=
+	  counter=1
+	  for obj in $save_oldobjs
+	  do
+	    func_basename "$obj"
+	    objbase="$func_basename_result"
+	    case " $oldobjs " in
+	    " ") oldobjs=$obj ;;
+	    *[\ /]"$objbase "*)
+	      while :; do
+		# Make sure we don't pick an alternate name that also
+		# overlaps.
+		newobj=lt$counter-$objbase
+		func_arith $counter + 1
+		counter=$func_arith_result
+		case " $oldobjs " in
+		*[\ /]"$newobj "*) ;;
+		*) if test ! -f "$gentop/$newobj"; then break; fi ;;
+		esac
+	      done
+	      func_show_eval "ln $obj $gentop/$newobj || cp $obj $gentop/$newobj"
+	      oldobjs="$oldobjs $gentop/$newobj"
+	      ;;
+	    *) oldobjs="$oldobjs $obj" ;;
+	    esac
+	  done
+	fi
+	eval cmds=\"$old_archive_cmds\"
+
+	func_len " $cmds"
+	len=$func_len_result
+	if test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
+	  cmds=$old_archive_cmds
+	else
+	  # the command line is too long to link in one step, link in parts
+	  func_verbose "using piecewise archive linking..."
+	  save_RANLIB=$RANLIB
+	  RANLIB=:
+	  objlist=
+	  concat_cmds=
+	  save_oldobjs=$oldobjs
+	  oldobjs=
+	  # Is there a better way of finding the last object in the list?
+	  for obj in $save_oldobjs
+	  do
+	    last_oldobj=$obj
+	  done
+	  eval test_cmds=\"$old_archive_cmds\"
+	  func_len " $test_cmds"
+	  len0=$func_len_result
+	  len=$len0
+	  for obj in $save_oldobjs
+	  do
+	    func_len " $obj"
+	    func_arith $len + $func_len_result
+	    len=$func_arith_result
+	    func_append objlist " $obj"
+	    if test "$len" -lt "$max_cmd_len"; then
+	      :
+	    else
+	      # the above command should be used before it gets too long
+	      oldobjs=$objlist
+	      if test "$obj" = "$last_oldobj" ; then
+		RANLIB=$save_RANLIB
+	      fi
+	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
+	      eval concat_cmds=\"\${concat_cmds}$old_archive_cmds\"
+	      objlist=
+	      len=$len0
+	    fi
+	  done
+	  RANLIB=$save_RANLIB
+	  oldobjs=$objlist
+	  if test "X$oldobjs" = "X" ; then
+	    eval cmds=\"\$concat_cmds\"
+	  else
+	    eval cmds=\"\$concat_cmds~\$old_archive_cmds\"
+	  fi
+	fi
+      fi
+      func_execute_cmds "$cmds" 'exit $?'
+    done
+
+    test -n "$generated" && \
+      func_show_eval "${RM}r$generated"
+
+    # Now create the libtool archive.
+    case $output in
+    *.la)
+      old_library=
+      test "$build_old_libs" = yes && old_library="$libname.$libext"
+      func_verbose "creating $output"
+
+      # Preserve any variables that may affect compiler behavior
+      for var in $variables_saved_for_relink; do
+	if eval test -z \"\${$var+set}\"; then
+	  relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
+	elif eval var_value=\$$var; test -z "$var_value"; then
+	  relink_command="$var=; export $var; $relink_command"
+	else
+	  func_quote_for_eval "$var_value"
+	  relink_command="$var=$func_quote_for_eval_result; export $var; $relink_command"
+	fi
+      done
+      # Quote the link command for shipping.
+      relink_command="(cd `pwd`; $SHELL $progpath $preserve_args --mode=relink $libtool_args @inst_prefix_dir@)"
+      relink_command=`$ECHO "X$relink_command" | $Xsed -e "$sed_quote_subst"`
+      if test "$hardcode_automatic" = yes ; then
+	relink_command=
+      fi
+
+      # Only create the output if not a dry run.
+      $opt_dry_run || {
+	for installed in no yes; do
+	  if test "$installed" = yes; then
+	    if test -z "$install_libdir"; then
+	      break
+	    fi
+	    output="$output_objdir/$outputname"i
+	    # Replace all uninstalled libtool libraries with the installed ones
+	    newdependency_libs=
+	    for deplib in $dependency_libs; do
+	      case $deplib in
+	      *.la)
+		func_basename "$deplib"
+		name="$func_basename_result"
+		eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $deplib`
+		test -z "$libdir" && \
+		  func_fatal_error "\`$deplib' is not a valid libtool archive"
+		newdependency_libs="$newdependency_libs $libdir/$name"
+		;;
+	      *) newdependency_libs="$newdependency_libs $deplib" ;;
+	      esac
+	    done
+	    dependency_libs="$newdependency_libs"
+	    newdlfiles=
+
+	    for lib in $dlfiles; do
+	      case $lib in
+	      *.la)
+	        func_basename "$lib"
+		name="$func_basename_result"
+		eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
+		test -z "$libdir" && \
+		  func_fatal_error "\`$lib' is not a valid libtool archive"
+		newdlfiles="$newdlfiles $libdir/$name"
+		;;
+	      *) newdlfiles="$newdlfiles $lib" ;;
+	      esac
+	    done
+	    dlfiles="$newdlfiles"
+	    newdlprefiles=
+	    for lib in $dlprefiles; do
+	      case $lib in
+	      *.la)
+		# Only pass preopened files to the pseudo-archive (for
+		# eventual linking with the app. that links it) if we
+		# didn't already link the preopened objects directly into
+		# the library:
+		func_basename "$lib"
+		name="$func_basename_result"
+		eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
+		test -z "$libdir" && \
+		  func_fatal_error "\`$lib' is not a valid libtool archive"
+		newdlprefiles="$newdlprefiles $libdir/$name"
+		;;
+	      esac
+	    done
+	    dlprefiles="$newdlprefiles"
+	  else
+	    newdlfiles=
+	    for lib in $dlfiles; do
+	      case $lib in
+		[\\/]* | [A-Za-z]:[\\/]*) abs="$lib" ;;
+		*) abs=`pwd`"/$lib" ;;
+	      esac
+	      newdlfiles="$newdlfiles $abs"
+	    done
+	    dlfiles="$newdlfiles"
+	    newdlprefiles=
+	    for lib in $dlprefiles; do
+	      case $lib in
+		[\\/]* | [A-Za-z]:[\\/]*) abs="$lib" ;;
+		*) abs=`pwd`"/$lib" ;;
+	      esac
+	      newdlprefiles="$newdlprefiles $abs"
+	    done
+	    dlprefiles="$newdlprefiles"
+	  fi
+	  $RM $output
+	  # place dlname in correct position for cygwin
+	  tdlname=$dlname
+	  case $host,$output,$installed,$module,$dlname in
+	    *cygwin*,*lai,yes,no,*.dll | *mingw*,*lai,yes,no,*.dll | *cegcc*,*lai,yes,no,*.dll) tdlname=../bin/$dlname ;;
+	  esac
+	  $ECHO > $output "\
+# $outputname - a libtool library file
+# Generated by $PROGRAM (GNU $PACKAGE$TIMESTAMP) $VERSION
+#
+# Please DO NOT delete this file!
+# It is necessary for linking the library.
+
+# The name that we can dlopen(3).
+dlname='$tdlname'
+
+# Names of this library.
+library_names='$library_names'
+
+# The name of the static archive.
+old_library='$old_library'
+
+# Linker flags that can not go in dependency_libs.
+inherited_linker_flags='$new_inherited_linker_flags'
+
+# Libraries that this one depends upon.
+dependency_libs='$dependency_libs'
+
+# Names of additional weak libraries provided by this library
+weak_library_names='$weak_libs'
+
+# Version information for $libname.
+current=$current
+age=$age
+revision=$revision
+
+# Is this an already installed library?
+installed=$installed
+
+# Should we warn about portability when linking against -modules?
+shouldnotlink=$module
+
+# Files to dlopen/dlpreopen
+dlopen='$dlfiles'
+dlpreopen='$dlprefiles'
+
+# Directory that this library needs to be installed in:
+libdir='$install_libdir'"
+	  if test "$installed" = no && test "$need_relink" = yes; then
+	    $ECHO >> $output "\
+relink_command=\"$relink_command\""
+	  fi
+	done
+      }
+
+      # Do a symbolic link so that the libtool archive can be found in
+      # LD_LIBRARY_PATH before the program is installed.
+      func_show_eval '( cd "$output_objdir" && $RM "$outputname" && $LN_S "../$outputname" "$outputname" )' 'exit $?'
+      ;;
+    esac
+    exit $EXIT_SUCCESS
+}
+
+{ test "$mode" = link || test "$mode" = relink; } &&
+    func_mode_link ${1+"$@"}
+
+
+# func_mode_uninstall arg...
+func_mode_uninstall ()
+{
+    $opt_debug
+    RM="$nonopt"
+    files=
+    rmforce=
+    exit_status=0
+
+    # This variable tells wrapper scripts just to set variables rather
+    # than running their programs.
+    libtool_install_magic="$magic"
+
+    for arg
+    do
+      case $arg in
+      -f) RM="$RM $arg"; rmforce=yes ;;
+      -*) RM="$RM $arg" ;;
+      *) files="$files $arg" ;;
+      esac
+    done
+
+    test -z "$RM" && \
+      func_fatal_help "you must specify an RM program"
+
+    rmdirs=
+
+    origobjdir="$objdir"
+    for file in $files; do
+      func_dirname "$file" "" "."
+      dir="$func_dirname_result"
+      if test "X$dir" = X.; then
+	objdir="$origobjdir"
+      else
+	objdir="$dir/$origobjdir"
+      fi
+      func_basename "$file"
+      name="$func_basename_result"
+      test "$mode" = uninstall && objdir="$dir"
+
+      # Remember objdir for removal later, being careful to avoid duplicates
+      if test "$mode" = clean; then
+	case " $rmdirs " in
+	  *" $objdir "*) ;;
+	  *) rmdirs="$rmdirs $objdir" ;;
+	esac
+      fi
+
+      # Don't error if the file doesn't exist and rm -f was used.
+      if { test -L "$file"; } >/dev/null 2>&1 ||
+	 { test -h "$file"; } >/dev/null 2>&1 ||
+	 test -f "$file"; then
+	:
+      elif test -d "$file"; then
+	exit_status=1
+	continue
+      elif test "$rmforce" = yes; then
+	continue
+      fi
+
+      rmfiles="$file"
+
+      case $name in
+      *.la)
+	# Possibly a libtool archive, so verify it.
+	if func_lalib_p "$file"; then
+	  func_source $dir/$name
+
+	  # Delete the libtool libraries and symlinks.
+	  for n in $library_names; do
+	    rmfiles="$rmfiles $objdir/$n"
+	  done
+	  test -n "$old_library" && rmfiles="$rmfiles $objdir/$old_library"
+
+	  case "$mode" in
+	  clean)
+	    case "  $library_names " in
+	    # "  " in the beginning catches empty $dlname
+	    *" $dlname "*) ;;
+	    *) rmfiles="$rmfiles $objdir/$dlname" ;;
+	    esac
+	    test -n "$libdir" && rmfiles="$rmfiles $objdir/$name $objdir/${name}i"
+	    ;;
+	  uninstall)
+	    if test -n "$library_names"; then
+	      # Do each command in the postuninstall commands.
+	      func_execute_cmds "$postuninstall_cmds" 'test "$rmforce" = yes || exit_status=1'
+	    fi
+
+	    if test -n "$old_library"; then
+	      # Do each command in the old_postuninstall commands.
+	      func_execute_cmds "$old_postuninstall_cmds" 'test "$rmforce" = yes || exit_status=1'
+	    fi
+	    # FIXME: should reinstall the best remaining shared library.
+	    ;;
+	  esac
+	fi
+	;;
+
+      *.lo)
+	# Possibly a libtool object, so verify it.
+	if func_lalib_p "$file"; then
+
+	  # Read the .lo file
+	  func_source $dir/$name
+
+	  # Add PIC object to the list of files to remove.
+	  if test -n "$pic_object" &&
+	     test "$pic_object" != none; then
+	    rmfiles="$rmfiles $dir/$pic_object"
+	  fi
+
+	  # Add non-PIC object to the list of files to remove.
+	  if test -n "$non_pic_object" &&
+	     test "$non_pic_object" != none; then
+	    rmfiles="$rmfiles $dir/$non_pic_object"
+	  fi
+	fi
+	;;
+
+      *)
+	if test "$mode" = clean ; then
+	  noexename=$name
+	  case $file in
+	  *.exe)
+	    func_stripname '' '.exe' "$file"
+	    file=$func_stripname_result
+	    func_stripname '' '.exe' "$name"
+	    noexename=$func_stripname_result
+	    # $file with .exe has already been added to rmfiles,
+	    # add $file without .exe
+	    rmfiles="$rmfiles $file"
+	    ;;
+	  esac
+	  # Do a test to see if this is a libtool program.
+	  if func_ltwrapper_p "$file"; then
+	    if func_ltwrapper_executable_p "$file"; then
+	      func_ltwrapper_scriptname "$file"
+	      relink_command=
+	      func_source $func_ltwrapper_scriptname_result
+	      rmfiles="$rmfiles $func_ltwrapper_scriptname_result"
+	    else
+	      relink_command=
+	      func_source $dir/$noexename
+	    fi
+
+	    # note $name still contains .exe if it was in $file originally
+	    # as does the version of $file that was added into $rmfiles
+	    rmfiles="$rmfiles $objdir/$name $objdir/${name}S.${objext}"
+	    if test "$fast_install" = yes && test -n "$relink_command"; then
+	      rmfiles="$rmfiles $objdir/lt-$name"
+	    fi
+	    if test "X$noexename" != "X$name" ; then
+	      rmfiles="$rmfiles $objdir/lt-${noexename}.c"
+	    fi
+	  fi
+	fi
+	;;
+      esac
+      func_show_eval "$RM $rmfiles" 'exit_status=1'
+    done
+    objdir="$origobjdir"
+
+    # Try to remove the ${objdir}s in the directories where we deleted files
+    for dir in $rmdirs; do
+      if test -d "$dir"; then
+	func_show_eval "rmdir $dir >/dev/null 2>&1"
+      fi
+    done
+
+    exit $exit_status
+}
+
+{ test "$mode" = uninstall || test "$mode" = clean; } &&
+    func_mode_uninstall ${1+"$@"}
+
+test -z "$mode" && {
+  help="$generic_help"
+  func_fatal_help "you must specify a MODE"
+}
+
+test -z "$exec_cmd" && \
+  func_fatal_help "invalid operation mode \`$mode'"
+
+if test -n "$exec_cmd"; then
+  eval exec "$exec_cmd"
+  exit $EXIT_FAILURE
+fi
+
+exit $exit_status
+
+
+# The TAGs below are defined such that we never get into a situation
+# in which we disable both kinds of libraries.  Given conflicting
+# choices, we go for a static library, that is the most portable,
+# since we can't tell whether shared libraries were disabled because
+# the user asked for that or because the platform doesn't support
+# them.  This is particularly important on AIX, because we don't
+# support having both static and shared libraries enabled at the same
+# time on that platform, so we default to a shared-only configuration.
+# If a disable-shared tag is given, we'll fallback to a static-only
+# configuration.  But we'll never go from static-only to shared-only.
+
+# ### BEGIN LIBTOOL TAG CONFIG: disable-shared
+build_libtool_libs=no
+build_old_libs=yes
+# ### END LIBTOOL TAG CONFIG: disable-shared
+
+# ### BEGIN LIBTOOL TAG CONFIG: disable-static
+build_old_libs=`case $build_libtool_libs in yes) echo no;; *) echo yes;; esac`
+# ### END LIBTOOL TAG CONFIG: disable-static
+
+# Local Variables:
+# mode:shell-script
+# sh-indentation:2
+# End:
+# vi:sw=2
+
diff --git a/admin/missing b/admin/missing
new file mode 100755
index 0000000..28055d2
--- /dev/null
+++ b/admin/missing
@@ -0,0 +1,376 @@
+#! /bin/sh
+# Common stub for a few missing GNU programs while installing.
+
+scriptversion=2009-04-28.21; # UTC
+
+# Copyright (C) 1996, 1997, 1999, 2000, 2002, 2003, 2004, 2005, 2006,
+# 2008, 2009 Free Software Foundation, Inc.
+# Originally by Fran,cois Pinard <pinard at iro.umontreal.ca>, 1996.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that program.
+
+if test $# -eq 0; then
+  echo 1>&2 "Try \`$0 --help' for more information"
+  exit 1
+fi
+
+run=:
+sed_output='s/.* --output[ =]\([^ ]*\).*/\1/p'
+sed_minuso='s/.* -o \([^ ]*\).*/\1/p'
+
+# In the cases where this matters, `missing' is being run in the
+# srcdir already.
+if test -f configure.ac; then
+  configure_ac=configure.ac
+else
+  configure_ac=configure.in
+fi
+
+msg="missing on your system"
+
+case $1 in
+--run)
+  # Try to run requested program, and just exit if it succeeds.
+  run=
+  shift
+  "$@" && exit 0
+  # Exit code 63 means version mismatch.  This often happens
+  # when the user try to use an ancient version of a tool on
+  # a file that requires a minimum version.  In this case we
+  # we should proceed has if the program had been absent, or
+  # if --run hadn't been passed.
+  if test $? = 63; then
+    run=:
+    msg="probably too old"
+  fi
+  ;;
+
+  -h|--h|--he|--hel|--help)
+    echo "\
+$0 [OPTION]... PROGRAM [ARGUMENT]...
+
+Handle \`PROGRAM [ARGUMENT]...' for when PROGRAM is missing, or return an
+error status if there is no known handling for PROGRAM.
+
+Options:
+  -h, --help      display this help and exit
+  -v, --version   output version information and exit
+  --run           try to run the given command, and emulate it if it fails
+
+Supported PROGRAM values:
+  aclocal      touch file \`aclocal.m4'
+  autoconf     touch file \`configure'
+  autoheader   touch file \`config.h.in'
+  autom4te     touch the output file, or create a stub one
+  automake     touch all \`Makefile.in' files
+  bison        create \`y.tab.[ch]', if possible, from existing .[ch]
+  flex         create \`lex.yy.c', if possible, from existing .c
+  help2man     touch the output file
+  lex          create \`lex.yy.c', if possible, from existing .c
+  makeinfo     touch the output file
+  tar          try tar, gnutar, gtar, then tar without non-portable flags
+  yacc         create \`y.tab.[ch]', if possible, from existing .[ch]
+
+Version suffixes to PROGRAM as well as the prefixes \`gnu-', \`gnu', and
+\`g' are ignored when checking the name.
+
+Send bug reports to <bug-automake at gnu.org>."
+    exit $?
+    ;;
+
+  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
+    echo "missing $scriptversion (GNU Automake)"
+    exit $?
+    ;;
+
+  -*)
+    echo 1>&2 "$0: Unknown \`$1' option"
+    echo 1>&2 "Try \`$0 --help' for more information"
+    exit 1
+    ;;
+
+esac
+
+# normalize program name to check for.
+program=`echo "$1" | sed '
+  s/^gnu-//; t
+  s/^gnu//; t
+  s/^g//; t'`
+
+# Now exit if we have it, but it failed.  Also exit now if we
+# don't have it and --version was passed (most likely to detect
+# the program).  This is about non-GNU programs, so use $1 not
+# $program.
+case $1 in
+  lex*|yacc*)
+    # Not GNU programs, they don't have --version.
+    ;;
+
+  tar*)
+    if test -n "$run"; then
+       echo 1>&2 "ERROR: \`tar' requires --run"
+       exit 1
+    elif test "x$2" = "x--version" || test "x$2" = "x--help"; then
+       exit 1
+    fi
+    ;;
+
+  *)
+    if test -z "$run" && ($1 --version) > /dev/null 2>&1; then
+       # We have it, but it failed.
+       exit 1
+    elif test "x$2" = "x--version" || test "x$2" = "x--help"; then
+       # Could not run --version or --help.  This is probably someone
+       # running `$TOOL --version' or `$TOOL --help' to check whether
+       # $TOOL exists and not knowing $TOOL uses missing.
+       exit 1
+    fi
+    ;;
+esac
+
+# If it does not exist, or fails to run (possibly an outdated version),
+# try to emulate it.
+case $program in
+  aclocal*)
+    echo 1>&2 "\
+WARNING: \`$1' is $msg.  You should only need it if
+         you modified \`acinclude.m4' or \`${configure_ac}'.  You might want
+         to install the \`Automake' and \`Perl' packages.  Grab them from
+         any GNU archive site."
+    touch aclocal.m4
+    ;;
+
+  autoconf*)
+    echo 1>&2 "\
+WARNING: \`$1' is $msg.  You should only need it if
+         you modified \`${configure_ac}'.  You might want to install the
+         \`Autoconf' and \`GNU m4' packages.  Grab them from any GNU
+         archive site."
+    touch configure
+    ;;
+
+  autoheader*)
+    echo 1>&2 "\
+WARNING: \`$1' is $msg.  You should only need it if
+         you modified \`acconfig.h' or \`${configure_ac}'.  You might want
+         to install the \`Autoconf' and \`GNU m4' packages.  Grab them
+         from any GNU archive site."
+    files=`sed -n 's/^[ ]*A[CM]_CONFIG_HEADER(\([^)]*\)).*/\1/p' ${configure_ac}`
+    test -z "$files" && files="config.h"
+    touch_files=
+    for f in $files; do
+      case $f in
+      *:*) touch_files="$touch_files "`echo "$f" |
+				       sed -e 's/^[^:]*://' -e 's/:.*//'`;;
+      *) touch_files="$touch_files $f.in";;
+      esac
+    done
+    touch $touch_files
+    ;;
+
+  automake*)
+    echo 1>&2 "\
+WARNING: \`$1' is $msg.  You should only need it if
+         you modified \`Makefile.am', \`acinclude.m4' or \`${configure_ac}'.
+         You might want to install the \`Automake' and \`Perl' packages.
+         Grab them from any GNU archive site."
+    find . -type f -name Makefile.am -print |
+	   sed 's/\.am$/.in/' |
+	   while read f; do touch "$f"; done
+    ;;
+
+  autom4te*)
+    echo 1>&2 "\
+WARNING: \`$1' is needed, but is $msg.
+         You might have modified some files without having the
+         proper tools for further handling them.
+         You can get \`$1' as part of \`Autoconf' from any GNU
+         archive site."
+
+    file=`echo "$*" | sed -n "$sed_output"`
+    test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"`
+    if test -f "$file"; then
+	touch $file
+    else
+	test -z "$file" || exec >$file
+	echo "#! /bin/sh"
+	echo "# Created by GNU Automake missing as a replacement of"
+	echo "#  $ $@"
+	echo "exit 0"
+	chmod +x $file
+	exit 1
+    fi
+    ;;
+
+  bison*|yacc*)
+    echo 1>&2 "\
+WARNING: \`$1' $msg.  You should only need it if
+         you modified a \`.y' file.  You may need the \`Bison' package
+         in order for those modifications to take effect.  You can get
+         \`Bison' from any GNU archive site."
+    rm -f y.tab.c y.tab.h
+    if test $# -ne 1; then
+        eval LASTARG="\${$#}"
+	case $LASTARG in
+	*.y)
+	    SRCFILE=`echo "$LASTARG" | sed 's/y$/c/'`
+	    if test -f "$SRCFILE"; then
+	         cp "$SRCFILE" y.tab.c
+	    fi
+	    SRCFILE=`echo "$LASTARG" | sed 's/y$/h/'`
+	    if test -f "$SRCFILE"; then
+	         cp "$SRCFILE" y.tab.h
+	    fi
+	  ;;
+	esac
+    fi
+    if test ! -f y.tab.h; then
+	echo >y.tab.h
+    fi
+    if test ! -f y.tab.c; then
+	echo 'main() { return 0; }' >y.tab.c
+    fi
+    ;;
+
+  lex*|flex*)
+    echo 1>&2 "\
+WARNING: \`$1' is $msg.  You should only need it if
+         you modified a \`.l' file.  You may need the \`Flex' package
+         in order for those modifications to take effect.  You can get
+         \`Flex' from any GNU archive site."
+    rm -f lex.yy.c
+    if test $# -ne 1; then
+        eval LASTARG="\${$#}"
+	case $LASTARG in
+	*.l)
+	    SRCFILE=`echo "$LASTARG" | sed 's/l$/c/'`
+	    if test -f "$SRCFILE"; then
+	         cp "$SRCFILE" lex.yy.c
+	    fi
+	  ;;
+	esac
+    fi
+    if test ! -f lex.yy.c; then
+	echo 'main() { return 0; }' >lex.yy.c
+    fi
+    ;;
+
+  help2man*)
+    echo 1>&2 "\
+WARNING: \`$1' is $msg.  You should only need it if
+	 you modified a dependency of a manual page.  You may need the
+	 \`Help2man' package in order for those modifications to take
+	 effect.  You can get \`Help2man' from any GNU archive site."
+
+    file=`echo "$*" | sed -n "$sed_output"`
+    test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"`
+    if test -f "$file"; then
+	touch $file
+    else
+	test -z "$file" || exec >$file
+	echo ".ab help2man is required to generate this page"
+	exit $?
+    fi
+    ;;
+
+  makeinfo*)
+    echo 1>&2 "\
+WARNING: \`$1' is $msg.  You should only need it if
+         you modified a \`.texi' or \`.texinfo' file, or any other file
+         indirectly affecting the aspect of the manual.  The spurious
+         call might also be the consequence of using a buggy \`make' (AIX,
+         DU, IRIX).  You might want to install the \`Texinfo' package or
+         the \`GNU make' package.  Grab either from any GNU archive site."
+    # The file to touch is that specified with -o ...
+    file=`echo "$*" | sed -n "$sed_output"`
+    test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"`
+    if test -z "$file"; then
+      # ... or it is the one specified with @setfilename ...
+      infile=`echo "$*" | sed 's/.* \([^ ]*\) *$/\1/'`
+      file=`sed -n '
+	/^@setfilename/{
+	  s/.* \([^ ]*\) *$/\1/
+	  p
+	  q
+	}' $infile`
+      # ... or it is derived from the source name (dir/f.texi becomes f.info)
+      test -z "$file" && file=`echo "$infile" | sed 's,.*/,,;s,.[^.]*$,,'`.info
+    fi
+    # If the file does not exist, the user really needs makeinfo;
+    # let's fail without touching anything.
+    test -f $file || exit 1
+    touch $file
+    ;;
+
+  tar*)
+    shift
+
+    # We have already tried tar in the generic part.
+    # Look for gnutar/gtar before invocation to avoid ugly error
+    # messages.
+    if (gnutar --version > /dev/null 2>&1); then
+       gnutar "$@" && exit 0
+    fi
+    if (gtar --version > /dev/null 2>&1); then
+       gtar "$@" && exit 0
+    fi
+    firstarg="$1"
+    if shift; then
+	case $firstarg in
+	*o*)
+	    firstarg=`echo "$firstarg" | sed s/o//`
+	    tar "$firstarg" "$@" && exit 0
+	    ;;
+	esac
+	case $firstarg in
+	*h*)
+	    firstarg=`echo "$firstarg" | sed s/h//`
+	    tar "$firstarg" "$@" && exit 0
+	    ;;
+	esac
+    fi
+
+    echo 1>&2 "\
+WARNING: I can't seem to be able to run \`tar' with the given arguments.
+         You may want to install GNU tar or Free paxutils, or check the
+         command line arguments."
+    exit 1
+    ;;
+
+  *)
+    echo 1>&2 "\
+WARNING: \`$1' is needed, and is $msg.
+         You might have modified some files without having the
+         proper tools for further handling them.  Check the \`README' file,
+         it often tells you about the needed prerequisites for installing
+         this package.  You may also peek at any GNU archive site, in case
+         some other package would contain this missing \`$1' program."
+    exit 1
+    ;;
+esac
+
+exit 0
+
+# Local variables:
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "scriptversion="
+# time-stamp-format: "%:y-%02m-%02d.%02H"
+# time-stamp-time-zone: "UTC"
+# time-stamp-end: "; # UTC"
+# End:
diff --git a/calib/cal/REF_BP_MAP.fits b/calib/cal/REF_BP_MAP.fits
new file mode 100644
index 0000000..9dff1f1
--- /dev/null
+++ b/calib/cal/REF_BP_MAP.fits
@@ -0,0 +1 @@
+SIMPLE  =                    T / Standard FITS format: NOST 100-2.0             BITPIX  =                  -32 / No. of bits per pixel                          NAXIS   =                    2 / No. of axes in image                           NAXIS1  =                 2048 / No. of pixels                                  NAXIS2  =                 2048 / No. of pixels                                  EXTEND  =                    T / FITS extension may be present                  BLOCKED =    [...]
\ No newline at end of file
diff --git a/calib/cal/SI_GATM_REF_CORR_HK_025.fits b/calib/cal/SI_GATM_REF_CORR_HK_025.fits
new file mode 100644
index 0000000..cf6535e
Binary files /dev/null and b/calib/cal/SI_GATM_REF_CORR_HK_025.fits differ
diff --git a/calib/cal/SI_GATM_REF_CORR_HK_100.fits b/calib/cal/SI_GATM_REF_CORR_HK_100.fits
new file mode 100644
index 0000000..64819c9
Binary files /dev/null and b/calib/cal/SI_GATM_REF_CORR_HK_100.fits differ
diff --git a/calib/cal/SI_GATM_REF_CORR_H_025.fits b/calib/cal/SI_GATM_REF_CORR_H_025.fits
new file mode 100644
index 0000000..4a45c64
Binary files /dev/null and b/calib/cal/SI_GATM_REF_CORR_H_025.fits differ
diff --git a/calib/cal/SI_GATM_REF_CORR_H_100.fits b/calib/cal/SI_GATM_REF_CORR_H_100.fits
new file mode 100644
index 0000000..07c68f2
Binary files /dev/null and b/calib/cal/SI_GATM_REF_CORR_H_100.fits differ
diff --git a/calib/cal/SI_GATM_REF_CORR_J_025.fits b/calib/cal/SI_GATM_REF_CORR_J_025.fits
new file mode 100644
index 0000000..905c213
Binary files /dev/null and b/calib/cal/SI_GATM_REF_CORR_J_025.fits differ
diff --git a/calib/cal/SI_GATM_REF_CORR_J_100.fits b/calib/cal/SI_GATM_REF_CORR_J_100.fits
new file mode 100644
index 0000000..fb499f7
Binary files /dev/null and b/calib/cal/SI_GATM_REF_CORR_J_100.fits differ
diff --git a/calib/cal/SI_GATM_REF_CORR_K_025.fits b/calib/cal/SI_GATM_REF_CORR_K_025.fits
new file mode 100644
index 0000000..bcf304c
Binary files /dev/null and b/calib/cal/SI_GATM_REF_CORR_K_025.fits differ
diff --git a/calib/cal/SI_GATM_REF_CORR_K_100.fits b/calib/cal/SI_GATM_REF_CORR_K_100.fits
new file mode 100644
index 0000000..fddae4b
Binary files /dev/null and b/calib/cal/SI_GATM_REF_CORR_K_100.fits differ
diff --git a/calib/cal/SLIT_POS_HK_025.fits b/calib/cal/SLIT_POS_HK_025.fits
new file mode 100644
index 0000000..db249cc
--- /dev/null
+++ b/calib/cal/SLIT_POS_HK_025.fits
@@ -0,0 +1 @@
+SIMPLE  =                    T / Standard FITS format: NOST 100-2.0             BITPIX  =                    8 / No. of bits per pixel                          NAXIS   =                    0 / Empty Prime data matrix                        EXTEND  =                    T / FITS extension may be present                  BLOCKED =                    T / FITS file may be blocked                       COMMENT NOST 100-2.0: Hanisch,R. et al. 2001, Astron. & Astrophys. 376, 559                  [...]
\ No newline at end of file
diff --git a/calib/cal/SLIT_POS_HK_100.fits b/calib/cal/SLIT_POS_HK_100.fits
new file mode 100644
index 0000000..3ce0220
--- /dev/null
+++ b/calib/cal/SLIT_POS_HK_100.fits
@@ -0,0 +1 @@
+SIMPLE  =                    T / Standard FITS format: NOST 100-2.0             BITPIX  =                    8 / No. of bits per pixel                          NAXIS   =                    0 / Empty Prime data matrix                        EXTEND  =                    T / FITS extension may be present                  BLOCKED =                    T / FITS file may be blocked                       COMMENT NOST 100-2.0: Hanisch,R. et al. 2001, Astron. & Astrophys. 376, 559                  [...]
\ No newline at end of file
diff --git a/calib/cal/SLIT_POS_HK_250.fits b/calib/cal/SLIT_POS_HK_250.fits
new file mode 100644
index 0000000..a600d2b
--- /dev/null
+++ b/calib/cal/SLIT_POS_HK_250.fits
@@ -0,0 +1 @@
+SIMPLE  =                    T / Standard FITS format: NOST 100-2.0             BITPIX  =                    8 / No. of bits per pixel                          NAXIS   =                    0 / Empty Prime data matrix                        EXTEND  =                    T / FITS extension may be present                  BLOCKED =                    T / FITS file may be blocked                       COMMENT NOST 100-2.0: Hanisch,R. et al. 2001, Astron. & Astrophys. 376, 559                  [...]
\ No newline at end of file
diff --git a/calib/cal/SLIT_POS_HK_PUPIL.fits b/calib/cal/SLIT_POS_HK_PUPIL.fits
new file mode 100644
index 0000000..5ff425f
--- /dev/null
+++ b/calib/cal/SLIT_POS_HK_PUPIL.fits
@@ -0,0 +1 @@
+SIMPLE  =                    T / Standard FITS format: NOST 100-2.0             BITPIX  =                    8 / No. of bits per pixel                          NAXIS   =                    0 / Empty Prime data matrix                        EXTEND  =                    T / FITS extension may be present                  BLOCKED =                    T / FITS file may be blocked                       COMMENT NOST 100-2.0: Hanisch,R. et al. 2001, Astron. & Astrophys. 376, 559                  [...]
\ No newline at end of file
diff --git a/calib/cal/SLIT_POS_H_025.fits b/calib/cal/SLIT_POS_H_025.fits
new file mode 100644
index 0000000..32150f8
--- /dev/null
+++ b/calib/cal/SLIT_POS_H_025.fits
@@ -0,0 +1 @@
+SIMPLE  =                    T / Standard FITS format: NOST 100-2.0             BITPIX  =                    8 / No. of bits per pixel                          NAXIS   =                    0 / Empty Prime data matrix                        EXTEND  =                    T / FITS extension may be present                  BLOCKED =                    T / FITS file may be blocked                       COMMENT NOST 100-2.0: Hanisch,R. et al. 2001, Astron. & Astrophys. 376, 559                  [...]
\ No newline at end of file
diff --git a/calib/cal/SLIT_POS_H_100.fits b/calib/cal/SLIT_POS_H_100.fits
new file mode 100644
index 0000000..d0ce779
--- /dev/null
+++ b/calib/cal/SLIT_POS_H_100.fits
@@ -0,0 +1,3 @@
+SIMPLE  =                    T / Standard FITS format: NOST 100-2.0             BITPIX  =                    8 / No. of bits per pixel                          NAXIS   =                    0 / Empty Prime data matrix                        EXTEND  =                    T / FITS extension may be present                  BLOCKED =                    T / FITS file may be blocked                       COMMENT NOST 100-2.0: Hanisch,R. et al. 2001, Astron. & Astrophys. 376, 559                  [...]
=@   @p;`   @t�`   @t	)@   @x

+�   @x	f�   @|
+f�   @|=�   @�ݠ   @��@   @�@�   @���   @�    @�
�   @�"`   @�e�   @�s�   @���   @�^`   @�0    @��   @��    @� ؠ   @��    @��`   @��    @��`   @�a`   @��`   @�O�   @��    @�u�   @�2@   @��`   @��`   @�Y    @�Z@   @���   @���   @��@   @�@   @�؀   @���   @���   @�
�   @�c@   @�:@   @�i    @���   @�(�   @�t�   @��    @� �    @� `   @��:�   @��T�   @��G`                                                                                              [...]
\ No newline at end of file
diff --git a/calib/cal/SLIT_POS_H_250.fits b/calib/cal/SLIT_POS_H_250.fits
new file mode 100644
index 0000000..437b797
--- /dev/null
+++ b/calib/cal/SLIT_POS_H_250.fits
@@ -0,0 +1,2 @@
+SIMPLE  =                    T / Standard FITS format: NOST 100-2.0             BITPIX  =                    8 / No. of bits per pixel                          NAXIS   =                    0 / Empty Prime data matrix                        EXTEND  =                    T / FITS extension may be present                  BLOCKED =                    T / FITS file may be blocked                       COMMENT NOST 100-2.0: Hanisch,R. et al. 2001, Astron. & Astrophys. 376, 559                  [...]
+�   @� T�   @����   @���   @��5�   @��o�   @����   @����   @��,�   @��)�                                                                                                                                                                                                                                                                                                                                                                                                                                     [...]
\ No newline at end of file
diff --git a/calib/cal/SLIT_POS_H_PUPIL.fits b/calib/cal/SLIT_POS_H_PUPIL.fits
new file mode 100644
index 0000000..d17cc36
--- /dev/null
+++ b/calib/cal/SLIT_POS_H_PUPIL.fits
@@ -0,0 +1,3 @@
+SIMPLE  =                    T / Standard FITS format: NOST 100-2.0             BITPIX  =                    8 / No. of bits per pixel                          NAXIS   =                    0 / Empty Prime data matrix                        EXTEND  =                    T / FITS extension may be present                  BLOCKED =                    T / FITS file may be blocked                       COMMENT NOST 100-2.0: Hanisch,R. et al. 2001, Astron. & Astrophys. 376, 559                  [...]
=@   @p;`   @t�`   @t	)@   @x

+�   @x	f�   @|
+f�   @|=�   @�ݠ   @��@   @�@�   @���   @�    @�
�   @�"`   @�e�   @�s�   @���   @�^`   @�0    @��   @��    @� ؠ   @��    @��`   @��    @��`   @�a`   @��`   @�O�   @��    @�u�   @�2@   @��`   @��`   @�Y    @�Z@   @���   @���   @��@   @�@   @�؀   @���   @���   @�
�   @�c@   @�:@   @�i    @���   @�(�   @�t�   @��    @� �    @� `   @��:�   @��T�   @��G`                                                                                              [...]
\ No newline at end of file
diff --git a/calib/cal/SLIT_POS_J_025.fits b/calib/cal/SLIT_POS_J_025.fits
new file mode 100644
index 0000000..2d8c453
--- /dev/null
+++ b/calib/cal/SLIT_POS_J_025.fits
@@ -0,0 +1,4 @@
+SIMPLE  =                    T / Standard FITS format: NOST 100-2.0             BITPIX  =                    8 / No. of bits per pixel                          NAXIS   =                    0 / Empty Prime data matrix                        EXTEND  =                    T / FITS extension may be present                  BLOCKED =                    T / FITS file may be blocked                       COMMENT NOST 100-2.0: Hanisch,R. et al. 2001, Astron. & Astrophys. 376, 559                  [...]
+�    @��E    @�w�   @��A    @��    @��   @�
+V    @�@�   @��`   @���   @��`   @���   @�7�   @���   @���   @���   @���   @�
    @�
+
�   @���   @���   @���   @���   @�͠   @�`   @����   @���   @��
�   @��   @�]    @��   @���    @�K�   @��@   @���    @���                                                                                                                                                                                                                                                                                                                                                                      [...]
\ No newline at end of file
diff --git a/calib/cal/SLIT_POS_J_100.fits b/calib/cal/SLIT_POS_J_100.fits
new file mode 100644
index 0000000..def8683
--- /dev/null
+++ b/calib/cal/SLIT_POS_J_100.fits
@@ -0,0 +1,5 @@
+SIMPLE  =                    T / Standard FITS format: NOST 100-2.0             BITPIX  =                    8 / No. of bits per pixel                          NAXIS   =                    0 / Empty Prime data matrix                        EXTEND  =                    T / FITS extension may be present                  BLOCKED =                    T / FITS file may be blocked                       COMMENT NOST 100-2.0: Hanisch,R. et al. 2001, Astron. & Astrophys. 376, 559                  [...]
��   @xr�   @|�    @|�    @�`   @�	:`   @�	�@   @�

+�   @��@   @���   @�_�   @�	��   @�'@   @�$�   @�	��   @�
5�   @�Ǡ   @�	{�   @��`   @�
+��   @�g    @� �   @�
9�   @�
+�@   @�^�   @�I�   @�d@   @���   @��    @���   @�	*�   @�	}�   @��   @��   @�	�    @�
+1�   @�e�   @�	
    @���   @�	��   @���   @�`�   @�6`   @�
    @���   @�w�   @�@   @��`   @�0@   @���   @��@   @�2�   @��                                                                                                                                                                                                                                                                                                                                                                                       [...]
\ No newline at end of file
diff --git a/calib/cal/SLIT_POS_J_250.fits b/calib/cal/SLIT_POS_J_250.fits
new file mode 100644
index 0000000..20f515b
--- /dev/null
+++ b/calib/cal/SLIT_POS_J_250.fits
@@ -0,0 +1,4 @@
+SIMPLE  =                    T / Standard FITS format: NOST 100-2.0             BITPIX  =                    8 / No. of bits per pixel                          NAXIS   =                    0 / Empty Prime data matrix                        EXTEND  =                    T / FITS extension may be present                  BLOCKED =                    T / FITS file may be blocked                       COMMENT NOST 100-2.0: Hanisch,R. et al. 2001, Astron. & Astrophys. 376, 559                  [...]
�    @x�@   @x��   @|��   @|
�    @���   @��   @��`   @�z�   @�`   @��v�   @�-�   @��   @��    @�f    @�y@   @�4�   @�	�    @�@   @���   @�	~@   @�
@   @��`   @�
=`   @�J�   @���   @��`   @�
+)@   @���   @�
 `   @��    @�
�   @���   @�	��   @��@   @�
�    @�t`   @�	�@   @�
+�   @�
��   @���   @�

    @�`   @�
+�`   @�`   @�W    @���   @���   @�6�   @��    @��    @�0@   @� ��   @��                                                                                                                                                                                                                                                                                                                                                                                                                             [...]
\ No newline at end of file
diff --git a/calib/cal/SLIT_POS_J_PUPIL.fits b/calib/cal/SLIT_POS_J_PUPIL.fits
new file mode 100644
index 0000000..c375b2d
--- /dev/null
+++ b/calib/cal/SLIT_POS_J_PUPIL.fits
@@ -0,0 +1,5 @@
+SIMPLE  =                    T / Standard FITS format: NOST 100-2.0             BITPIX  =                    8 / No. of bits per pixel                          NAXIS   =                    0 / Empty Prime data matrix                        EXTEND  =                    T / FITS extension may be present                  BLOCKED =                    T / FITS file may be blocked                       COMMENT NOST 100-2.0: Hanisch,R. et al. 2001, Astron. & Astrophys. 376, 559                  [...]
��   @xr�   @|�    @|�    @�`   @�	:`   @�	�@   @�

+�   @��@   @���   @�_�   @�	��   @�'@   @�$�   @�	��   @�
5�   @�Ǡ   @�	{�   @��`   @�
+��   @�g    @� �   @�
9�   @�
+�@   @�^�   @�I�   @�d@   @���   @��    @���   @�	*�   @�	}�   @��   @��   @�	�    @�
+1�   @�e�   @�	
    @���   @�	��   @���   @�`�   @�6`   @�
    @���   @�w�   @�@   @��`   @�0@   @���   @��@   @�2�   @��                                                                                                                                                                                                                                                                                                                                                                                       [...]
\ No newline at end of file
diff --git a/calib/cal/SLIT_POS_K_025.fits b/calib/cal/SLIT_POS_K_025.fits
new file mode 100644
index 0000000..935faa4
--- /dev/null
+++ b/calib/cal/SLIT_POS_K_025.fits
@@ -0,0 +1,3 @@
+SIMPLE  =                    T / Standard FITS format: NOST 100-2.0             BITPIX  =                    8 / No. of bits per pixel                          NAXIS   =                    0 / Empty Prime data matrix                        EXTEND  =                    T / FITS extension may be present                  BLOCKED =                    T / FITS file may be blocked                       COMMENT NOST 100-2.0: Hanisch,R. et al. 2001, Astron. & Astrophys. 376, 559                  [...]
+ �   @�v    @�
�    @��@   @�	_@   @��   @�
�    @���   @�t@   @�     @�`   @� ��   @�
`   @�J�   @�
+7    @���   @�
S�   @��   @�
��   @�     @�
j`   @���`   @�      @�      @�    @��                                                                                                                                                                                                                                                                                                                                                                                                                     [...]
\ No newline at end of file
diff --git a/calib/cal/SLIT_POS_K_100.fits b/calib/cal/SLIT_POS_K_100.fits
new file mode 100644
index 0000000..d89b61a
--- /dev/null
+++ b/calib/cal/SLIT_POS_K_100.fits
@@ -0,0 +1,5 @@
+SIMPLE  =                    T / Standard FITS format: NOST 100-2.0             BITPIX  =                    8 / No. of bits per pixel                          NAXIS   =                    0 / Empty Prime data matrix                        EXTEND  =                    T / FITS extension may be present                  BLOCKED =                    T / FITS file may be blocked                       COMMENT NOST 100-2.0: Hanisch,R. et al. 2001, Astron. & Astrophys. 376, 559                  [...]
�@   @p�   @t��   @to�   @xQ�   @xb    @|    @|L�   @�+�   @�
+O    @�5@   @�0�   @���   @��@   @��`   @�
+�@   @�;`   @��@   @�Y�   @���   @��    @�
>�   @���   @�	��   @�Z�   @��    @�	��   @�	��   @��    @�	�    @�}    @�m�   @�    @�	�`   @���   @�	�   @�%`   @�
+�   @��@   @�	�   @�
    @�
+��   @�(�   @��    @�a�   @��   @�     @��@   @��    @��    @���   @���   @��`   @�	�@   @����   @�,�   @��                                                                                                                                                                                                                                                                                                                                                                                     [...]
\ No newline at end of file
diff --git a/calib/cal/SLIT_POS_K_250.fits b/calib/cal/SLIT_POS_K_250.fits
new file mode 100644
index 0000000..11794c2
--- /dev/null
+++ b/calib/cal/SLIT_POS_K_250.fits
@@ -0,0 +1,4 @@
+SIMPLE  =                    T / Standard FITS format: NOST 100-2.0             BITPIX  =                    8 / No. of bits per pixel                          NAXIS   =                    0 / Empty Prime data matrix                        EXTEND  =                    T / FITS extension may be present                  BLOCKED =                    T / FITS file may be blocked                       COMMENT NOST 100-2.0: Hanisch,R. et al. 2001, Astron. & Astrophys. 376, 559                  [...]
�   @h"��   @p
�@   @p��   @t\�   @t��   @x
+r�   @x��   @|~�   @|ŀ   @��    @�	��   @�V`   @���   @���   @���   @�    @�	�    @��`   @�	    @�A�   @���   @�F�   @�
��   @�
+>�   @�	�@   @�
�   @� �   @���   @�D    @��    @��    @��    @���   @���   @�	�`   @�=@   @��@   @��    @�
+;    @�h@   @�à   @�@   @�	D�   @���   @���   @�Հ   @�*�   @�@    @���   @�Z@   @��@   @�)    @�(@   @�q@   @��    @� �    @��`   @��                                                                                                                                                                                                                                                                                                                                                       [...]
\ No newline at end of file
diff --git a/calib/cal/SLIT_POS_K_PUPIL.fits b/calib/cal/SLIT_POS_K_PUPIL.fits
new file mode 100644
index 0000000..9e1182b
--- /dev/null
+++ b/calib/cal/SLIT_POS_K_PUPIL.fits
@@ -0,0 +1,5 @@
+SIMPLE  =                    T / Standard FITS format: NOST 100-2.0             BITPIX  =                    8 / No. of bits per pixel                          NAXIS   =                    0 / Empty Prime data matrix                        EXTEND  =                    T / FITS extension may be present                  BLOCKED =                    T / FITS file may be blocked                       COMMENT NOST 100-2.0: Hanisch,R. et al. 2001, Astron. & Astrophys. 376, 559                  [...]
�@   @p�   @t��   @to�   @xQ�   @xb    @|    @|L�   @�+�   @�
+O    @�5@   @�0�   @���   @��@   @��`   @�
+�@   @�;`   @��@   @�Y�   @���   @��    @�
>�   @���   @�	��   @�Z�   @��    @�	��   @�	��   @��    @�	�    @�}    @�m�   @�    @�	�`   @���   @�	�   @�%`   @�
+�   @��@   @�	�   @�
    @�
+��   @�(�   @��    @�a�   @��   @�     @��@   @��    @��    @���   @���   @��`   @�	�@   @����   @�,�   @��                                                                                                                                                                                                                                                                                                                                                                                     [...]
\ No newline at end of file
diff --git a/calib/cal/argonJ.fits b/calib/cal/argonJ.fits
new file mode 100644
index 0000000..86b4e58
Binary files /dev/null and b/calib/cal/argonJ.fits differ
diff --git a/calib/cal/atmoexan.fits b/calib/cal/atmoexan.fits
new file mode 100644
index 0000000..490ef0e
--- /dev/null
+++ b/calib/cal/atmoexan.fits
@@ -0,0 +1,15 @@
+SIMPLE  =                    T / Standard FITS format                           BITPIX  =                  -32 / No. of bits per pixel                          NAXIS   =                    0 / Empty Prime data matrix                        EXTEND  =                    T / FITS extension may be present                  BLOCKED =                    T / FITS file may be blocked                                                                                                       ORIGIN  = 'E [...]
+EH  ?p��EN@ ?8Q�ET� ?��EZ� ?
�Ea  >�Eg@ >��Em� >�p�Es� >���Ez  >���E�  >�=qE�@ >�  E�` >aG�E�� >L��E�� >B�\E�� >.{E�� >#�
+E�  >#�
+E�  >\)E�@ >
�E�� =�E�� =�G�E�  =���E�@ =���E�� =�Q�E�� =��
+E�  =�\)E�@ =L��EԀ =#�
+E�� =#�
+E�  <�E�@ <�E� <��
+E�� <��
+E�  <��
+F   <��
+F@ <#�
+F` <#�
+F	� <#�
+F
� <#�
+F
@     F��     F�P                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          [...]
\ No newline at end of file
diff --git a/calib/cal/drs_setup_wave.fits b/calib/cal/drs_setup_wave.fits
new file mode 100644
index 0000000..3bd9548
Binary files /dev/null and b/calib/cal/drs_setup_wave.fits differ
diff --git a/calib/cal/drs_setup_wave_oh.fits b/calib/cal/drs_setup_wave_oh.fits
new file mode 100644
index 0000000..7f191af
Binary files /dev/null and b/calib/cal/drs_setup_wave_oh.fits differ
diff --git a/calib/cal/neonK.fits b/calib/cal/neonK.fits
new file mode 100644
index 0000000..e68dd30
Binary files /dev/null and b/calib/cal/neonK.fits differ
diff --git a/calib/cal/xenonHK.fits b/calib/cal/xenonHK.fits
new file mode 100644
index 0000000..edda449
Binary files /dev/null and b/calib/cal/xenonHK.fits differ
diff --git a/calib/cal/xenonargonH.fits b/calib/cal/xenonargonH.fits
new file mode 100644
index 0000000..c232777
Binary files /dev/null and b/calib/cal/xenonargonH.fits differ
diff --git a/calib/dic/ESO-DFS-DIC.SINFONI_QC b/calib/dic/ESO-DFS-DIC.SINFONI_QC
new file mode 100644
index 0000000..1792f21
--- /dev/null
+++ b/calib/dic/ESO-DFS-DIC.SINFONI_QC
@@ -0,0 +1,1103 @@
+#******************************************************************************
+# E.S.O. - VLT project
+# who       when      what
+# --------  --------  ----------------------------------------------
+# amodigli  29/07/04  V0.1 - First version
+#******************************************************************************
+#   NAME
+#   ESO-DFS-DIC.SINFO - Data Interface Dictionary for SINFONI  description
+#
+# -----------------------------------------------------------------------------
+Dictionary Name:   ESO-DFS-DIC.UVES_QC
+Scope:             QC
+Source:            ESO DFS/DMD
+Version Control:   "@(#) $Id: ESO-DFS-DIC.SINFONI_QC,v 1.1.1.1 2007/08/24 09:49:23 amodigli Exp $"
+
+
+Parameter Name:    QC DID
+Class:             header|qc-log
+Context:           process
+Type:              string
+Value Format:      %30s
+Unit:
+Comment Field:     Data dictionary for QC
+Description:       Name/version of ESO DID to which QC keywords comply.
+
+Parameter Name:    QC TESTi ID
+Class:             qc-log|header
+Context:           process
+Type:              string
+Value Format:      %30s
+Unit:
+Comment Field:     Name of QC test
+Description:       Name of QC test. In case the same template can originate more
+                   than one test it is useful to specify it.
+
+
+#
+# BP Search:
+#
+
+Parameter Name:    QC BP-MAP METHOD
+Class:             header|qc-log
+Context:           process
+Type:              string
+Value Format:      %30s
+Unit:              
+Comment Field:     BP method 
+Description:       Method used to find bad pixels
+
+Parameter Name:    QC BP-MAP NBADPIX
+Class:             header|qc-log
+Context:           process
+Type:              integer
+Value Format:      %d
+Unit:              
+Comment Field:     Number of bad pixels 
+Description:       Number of bad pixels in a frame
+
+
+Parameter Name:    QC MBP-MAP NBADPIX
+Class:             header|qc-log
+Context:           process
+Type:              integer
+Value Format:      %d
+Unit:              
+Comment Field:     Number of bad pixels 
+Description:       Number of bad pixels in a frame
+
+Parameter Name:    QC BP-MAP LINi MEAN
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     Mean of linearity coeff 
+Description:       Mean of Linearity coefficient
+
+Parameter Name:    QC BP-MAP LINi MED
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     Median of linearity coeff 
+Description:       Median of Linearity coefficient
+
+#
+# Master Dark :
+#
+
+Parameter Name:    QC DARKMED AVE
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     Average of medians on all pixels of each input frame
+Description:       For each on the N raw input frames the median over all the
+                   pixels should be calculated. The average of the N raw frame
+                   median values is returned.
+
+
+Parameter Name:    QC DARKMED STDEV
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     Standard deviation of the N raw frames medians
+Description:       Standard deviation of the N raw frames medians
+
+
+
+
+Parameter Name:    QC DARKFPN
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     Fixed Pattern Noise
+Description:       TBD
+
+Parameter Name:    QC RONi
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     Read Out Noise
+Description:       TBD
+
+
+Parameter Name:    QC RONRMS
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     Read Out Noise
+Description:       TBD
+
+
+
+#
+# DetLinearity :
+#
+
+#Not dumped
+Parameter Name:    QC LINi MEAN
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     Linearity coefficient
+Description:       Detector Linearity coefficient
+
+#Not dumped
+Parameter Name:    QC LINi MEDIAN
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     Linearity coefficient
+Description:       Detector Linearity coefficient
+
+Parameter Name:    QC GAINi 
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     Detector Gain 
+Description:       Detector Gain 
+
+#
+# Lamp Flat :
+#
+
+Parameter Name:    QC ICTILT STDEV
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     Standard deviation of intensity column tilt
+Description:       Standard deviation of intensity column tilt    
+
+
+Parameter Name:    QC ICTILT MEAN
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     Mean of intensity column tilt
+Description:       Mean of intensity column tilt    
+
+
+
+Parameter Name:    QC SPECFLAT NCNTSAVG
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     Average medians on total Counts
+Description:       Number of counts in the product spectrum
+
+Parameter Name:    QC SPECFLAT NCNTSSTD
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     Standard deviation medians on total Counts
+Description:       Number of counts in the product spectrum
+
+Parameter Name:    QC SPECFLAT OFFFLUX
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     Flux off lamps
+Description:       Flux off lamps
+
+#Not dumped
+Parameter Name:    QC SPECFLAT NCOUNTS
+Class:             header|qc-log
+Context:           process
+Type:              integer
+Value Format:      %d
+Unit:              
+Comment Field:     Total Counts
+Description:       Number of counts in the product spectrum
+
+#Not dumped
+Parameter Name:    QC SPECFLAT STD
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     STD deviation of three off-lamp subtracted fluxes
+Description:       STD deviation of three off-lamp subtracted fluxes
+
+#Not dumped
+Parameter Name:    QC LFLAT OFFFLUX
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     Flux of off lamp frames
+Description:       Flux of off lamp frames to parametrize contamination 
+                   (light,heat) in the optical path efficiently.
+
+#Not dumped
+Parameter Name:    QC LFLAT NSAT
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     Number of saturated pixels
+Description:       Number of saturated pixels in the on-lamp raw frame
+
+
+Parameter Name:    QC LFLAT FPNi
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     Fixed pattern noise
+Description:       Fixed Pattern Noise as derived from the product spectrum
+
+#not dumped
+Parameter Name:    QC LFLAT OFFNOISE
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     noise of off-lamp frames
+Description:       noise of off-lamp frames
+
+#not dumped
+Parameter Name:    QC LFLAT ONNOISE
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     noise of on-lamp frames
+Description:       noise of on-lamp frames
+
+#not dumped
+Parameter Name:    QC LFLAT ONFLUX
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     flux of on-lamp frames
+Description:       flux of on-lamp frames
+
+#not dumped
+Parameter Name:    QC LFLAT SLOPEX
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     slope in x 
+Description:       collapse the image in y and show slope in x
+
+#not dumped
+Parameter Name:    QC LFLAT SLOPEY
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     slope in y 
+Description:       collapse the image in x and show slope in y
+
+#not dumped
+Parameter Name:    QC LFLAT STD
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     standard deviation of the 64x64 pixel
+Description:       standard deviation of the 64x64 pixel
+
+#
+# Spec Flat :
+#
+
+
+#
+# North South Test :
+#
+
+Parameter Name:    QC SL DISTi
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     i slitlet distance
+Description:       i slitlet distance
+
+
+Parameter Name:    QC SL DISTAVG
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     average slitlet distances
+Description:       average slitlet distances
+
+#not dumped
+Parameter Name:    QC SL DISTSTD
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     STD deviation slitlet distances
+Description:       STD deviation slitlet distances
+
+
+Parameter Name:    QC SL DISTRMS
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     RMS deviation slitlet distances
+Description:       RMS deviation slitlet distances
+
+
+
+#
+# Slope/Tilt/Distortion :
+#
+
+Parameter Name:    QC OFFSET
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     distortion offset
+Description:       distortion offset
+
+#Not dumped
+Parameter Name:    QC SLOPE
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     spectra slope
+Description:       spectra slope
+
+#Can this dump a 2 digit coeffs?
+Parameter Name:    QC COEFFi
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     i polynomial coefficient
+Description:       i polynomial coefficient
+
+Parameter Name:    QC XSHIFT CC
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     Detector shift
+Description:       Detector shift
+
+Parameter Name:    QC XSHIFT UL
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     Detector shift
+Description:       Detector shift
+
+Parameter Name:    QC XSHIFT UR
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     Detector shift
+Description:       Detector shift
+
+Parameter Name:    QC XSHIFT LL
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     Detector shift
+Description:       Detector shift
+
+
+Parameter Name:    QC XSHIFT LR
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     Detector shift
+Description:       Detector shift
+
+#
+# Twiflat :
+#
+ 
+
+#
+# Wavecal :
+#
+
+Parameter Name:    QC FRMON MEANFLUX
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     Mean flux frame-on  
+Description:       Mean flux frame-on    
+
+
+Parameter Name:    QC FRMON MAXFLUX
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     Max flux frame-on  
+Description:       Max flux frame-on    
+
+Parameter Name:    QC FRMON NPIXSAT
+Class:             header|qc-log
+Context:           process
+Type:              integer
+Value Format:      %d
+Unit:              
+Comment Field:     No of saturated pixels for frame-on  
+Description:       No of staturated pixels for flux frame-on    
+
+
+Parameter Name:    QC FRMOFF MEANFLUX
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     Mean flux frame-off  
+Description:       Mean flux frame-off   
+
+
+Parameter Name:    QC FRMOFF MAXFLUX
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     Max flux frame-off 
+Description:       Max flux frame-off   
+
+Parameter Name:    QC FRMOFF NPIXSAT
+Class:             header|qc-log
+Context:           process
+Type:              integer
+Value Format:      %d
+Unit:              
+Comment Field:     No of saturated pixels for frame-off 
+Description:       No of staturated pixels for flux frame-off    
+
+
+Parameter Name:    QC FRMDIF MEANFLUX
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     Mean flux frame-on-off  
+Description:       Mean flux frame-on-off
+
+
+Parameter Name:    QC FRMDIF MAXFLUX
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     Max flux frame-on-off 
+Description:       Max flux frame-on-off   
+
+Parameter Name:    QC FRMDIF NPIXSAT
+Class:             header|qc-log
+Context:           process
+Type:              integer
+Value Format:      %d
+Unit:              
+Comment Field:     No of saturated pixels for frame-on-off 
+Description:       No of staturated pixels for flux frame-on-off    
+
+
+
+
+
+Parameter Name:    QC WAVE POSERR
+Class:             header|qc-log
+Context:           process
+Type:              integer
+Value Format:      %d
+Unit:              
+Comment Field:     Overall positioning error (um)
+Description:       Overall positioning error (um)
+
+
+Parameter Name:    QC WAVE ALL
+Class:             header|qc-log
+Context:           process
+Type:              integer
+Value Format:      %d
+Unit:              
+Comment Field:     Number of found arc lines
+Description:       Number of found arc lines
+
+#Not dumped
+Parameter Name:    QC WAVE NLINES
+Class:             header|qc-log
+Context:           process
+Type:              integer
+Value Format:      %d
+Unit:              
+Comment Field:     Number of arc lines used
+Description:       Number of arc lines used to evaluate dispersion
+
+
+Parameter Name:    QC WAVE NPIXSAT
+Class:             header|qc-log
+Context:           process
+Type:              integer
+Value Format:      %d
+Unit:              
+Comment Field:     Number of saturated pixels
+Description:       Number of saturated pixels
+
+
+Parameter Name:    QC WAVE MAXFLUX
+Class:             header|qc-log
+Context:           process
+Type:              integer
+Value Format:      %d
+Unit:              
+Comment Field:     Max flux
+Description:       Max flux in arc frame to evaluate lamp aging
+
+
+Parameter Name:    QC COEFi AVG
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     Average Dispersion Coefficient i
+Description:       Average Dispersion Coefficient i
+
+
+Parameter Name:    QC COEFi MED
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     Median Dispersion Coefficient i
+Description:       Median Dispersion Coefficient i
+
+
+
+#Not dumped
+Parameter Name:    QC DISP COEFFi
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     Dispersion Coefficient i
+Description:       Dispersion Coefficient i
+
+#not dumped
+Parameter Name:    QC PARMSi COEFi
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     Parameter i Coefficient j
+Description:       Parameter i Coefficient j
+
+#not dumped
+Parameter Name:    QC MED FWHM
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     Spectral resolution 
+Description:       Spectral resolution
+
+
+Parameter Name:    QC FWHM MED
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     Median Spectral resolution 
+Description:       Median Spectral resolution
+
+Parameter Name:    QC FWHM AVG
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     Average Spectral resolution 
+Description:       Average Spectral resolution
+
+
+Parameter Name:    QC FWHMX
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     FWHM X
+Description:       FWHM X
+
+
+Parameter Name:    QC FWHMY
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     FWHM Y 
+Description:       FWHM Y
+
+
+
+Parameter Name:    QC NSAT
+Class:             header|qc-log
+Context:           process
+Type:              integer
+Value Format:      %d
+Unit:              
+Comment Field:     No of saturated pixel
+Description:       No of saturated pixel
+
+Parameter Name:    QC NLINES
+Class:             header|qc-log
+Context:           process
+Type:              integer
+Value Format:      %d
+Unit:              
+Comment Field:     No of found arc lines
+Description:       No of found arc lines
+
+Parameter Name:    QC NLINES USED
+Class:             header|qc-log
+Context:           process
+Type:              integer
+Value Format:      %d
+Unit:              
+Comment Field:     No of found arc lines used 
+Description:       No of found arc lines used to define the solution
+
+#not used
+Parameter Name:    QC LAMPi AGE
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     Lamp i age 
+Description:       A parameter which allows to measure the lamp i age
+                   e.g. the maximum of the off-lamp subtracted clean mean
+                   arc exposure
+
+#
+# Focus : TBD
+#
+ 
+#
+# PSF : TBD
+#
+
+Parameter Name:    QC ENC CORE 
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     Encircled energy within PSF core
+Description:       Encircled energy within PSF core
+
+
+
+#
+# PUPIL :
+#
+
+
+Parameter Name:    QC PUPILi SHIFTX
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     X shift centroid - center image
+Description:       X shift centroid - center image
+
+Parameter Name:    QC PUPILi SHIFTY
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     Y shift centroid - center image
+Description:       Y shift centroid - center image
+ 
+#
+# STD :
+#
+
+
+Parameter Name:    QC SHIFTX
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     X shift centroid - center image
+Description:       X shift centroid - center image
+
+
+Parameter Name:    QC SHIFTY
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     Y shift centroid - center image
+Description:       Y shift centroid - center image
+
+
+Parameter Name:    QC CONVFCT 
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     Conversion factor
+Description:       Conversion factor
+
+
+Parameter Name:    QC NOBJ 
+Class:             header|qc-log
+Context:           process
+Type:              integer
+Value Format:      %d
+Unit:              
+Comment Field:     Number of obj frames in stack
+Description:       Number of obj frames in stack
+
+Parameter Name:    QC NSKY 
+Class:             header|qc-log
+Context:           process
+Type:              integer
+Value Format:      %d
+Unit:              
+Comment Field:     Number of sky frames in stack
+Description:       Number of sky frames in stack
+
+
+Parameter Name:    QC NREJECT 
+Class:             header|qc-log
+Context:           process
+Type:              integer
+Value Format:      %d
+Unit:              
+Comment Field:     Number of rejected frames
+Description:       Number of frames that could not be correlated and have
+                   been rejected by the recipe.
+
+Parameter Name:    QC MOVING AVE
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     Average of moving average values
+Description:       The sky background subtracted by the jitter sky subtraction
+                   method. The average of the moving average values and the 
+                   sky background standard deviation should be given
+
+Parameter Name:    QC MOVING STD
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     SKY bkg std deviation
+Description:       The sky background subtracted by the jitter sky subtraction
+                   method. The average of the moving average values and the 
+                   sky background standard deviation should be given
+
+
+
+Parameter Name:    QC FWHMX
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     sources X FWHM 
+Description:       sources X FWHM 
+
+
+Parameter Name:    QC FWHMY
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     sources Y FWHM 
+Description:       sources Y FWHM 
+
+Parameter Name:    QC FWHM MAJ
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     sources FWHM major ellipse axis 
+Description:       sources FWHM major ellipse axis
+
+Parameter Name:    QC FWHM MIN
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     sources FWHM minor ellipse axis 
+Description:       sources FWHM minor ellipse axis
+
+Parameter Name:    QC FWHM THETA
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     sources THETA ellipse angle 
+Description:       sources THETA ellipse angle
+
+
+Parameter Name:    QC FWHM LLX
+Class:             header|qc-log
+Context:           process
+Type:              integer
+Value Format:      %d
+Unit:              
+Comment Field:     lower left X for ellipse computation 
+Description:       lower left X for ellipse computation 
+
+Parameter Name:    QC FWHM LLY
+Class:             header|qc-log
+Context:           process
+Type:              integer
+Value Format:      %d
+Unit:              
+Comment Field:     lower left Y for ellipse computation 
+Description:       lower left Y for ellipse computation 
+
+
+Parameter Name:    QC FWHM HBX
+Class:             header|qc-log
+Context:           process
+Type:              integer
+Value Format:      %d
+Unit:              
+Comment Field:     half box size X for ellipse computation 
+Description:       half box size X for ellipse computation 
+
+
+Parameter Name:    QC FWHM HBY
+Class:             header|qc-log
+Context:           process
+Type:              integer
+Value Format:      %d
+Unit:              
+Comment Field:     half box size Y for ellipse computation 
+Description:       half box size Y for ellipse computation 
+
+Parameter Name:    QC FWHM MEDIAN
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     sources FWHM median
+Description:       sources FWHM median
+
+Parameter Name:    QC FWHM MODE
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     sources FWHM mode
+Description:       sources FWHM mode
+
+Parameter Name:    QC OBS NAME
+Class:             header|qc-log
+Context:           process
+Type:              string
+Value Format:      %30s
+Unit:              
+Comment Field:     Target name to used for STREHL 
+Description:       Target name to used for STREHL
+
+Parameter Name:    QC LAMBDAi
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     wavelength at which STREHL is computed  
+Description:       wavelength at which STREHL is computed
+
+
+Parameter Name:    QC STREHLi
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     sources STREHL 
+Description:       sources STREHL
+
+Parameter Name:    QC STREHLERi
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     sources STREHL ERROR 
+Description:       sources STREHL ERROR
+
+
+Parameter Name:    QC STREHL MED
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     sources STREHL median 
+Description:       sources STREHL median
+
+
+Parameter Name:    QC STREHL AVG
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     sources STREHL mean 
+Description:       sources STREHL mean
+
+
+Parameter Name:    QC STREHL MEDERR
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     sources STREHL error median 
+Description:       sources STREHL error median
+
+Parameter Name:    QC ELLIPT MEDIAN
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     median ellipticity
+Description:       median ellipticity
+
+
+
+Parameter Name:    QC ELLIPT AVE
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     average direction of semi-major axis of point sources
+Description:       average direction of semi-major axis of point sources
+
+
+Parameter Name:    QC ELLIPT MEAN
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     mean convertion factor
+Description:       mean convertion factor for selected wavelength bands
+
+
+Parameter Name:    QC CHECKi
+Class:             header|qc-log
+Context:           process
+Type:              integer
+Value Format:      %d
+Unit:              
+Comment Field:     Check parameter
+Description:       Parameter to monitor how is performed some the spectrum extraction
+
+Parameter Name:    QC CONVFCT
+Class:             header|qc-log
+Context:           process
+Type:              double
+Value Format:      %e
+Unit:              
+Comment Field:     Conversion factor
+Description:       Conversion factor
+
+
+#
+# Science :
+#
+
diff --git a/calib/dic/ESO-VLT-DIC.MACS_ICS b/calib/dic/ESO-VLT-DIC.MACS_ICS
new file mode 100644
index 0000000..0210759
--- /dev/null
+++ b/calib/dic/ESO-VLT-DIC.MACS_ICS
@@ -0,0 +1,2158 @@
+#******************************************************************************
+# E.S.O. - VLT project
+#
+# "@(#) $Id: ESO-VLT-DIC.MACS_ICS,v 1.1.1.1 2007/08/24 09:49:23 amodigli Exp $"
+#
+# MACS_ICS/ICB_CFG dictionaries
+#
+# Refer to appendix A of document VLT-SPE-ESO-17240-1676 for details.
+#
+# who       when      what
+# --------  --------  ----------------------------------------------
+# rdonalds  11/10/2001 Ported from template instrument
+#
+
+#******************************************************************************
+#
+# The MACS_ICS dictionary contains all keywords used by MACS ICS at
+# runtime to execute and understand commands with -function option,
+# such as SETUP and STATUS.
+#
+#******************************************************************************
+
+#
+# Notes
+# 1) The letters within () indicate the Class that keyword belongs to:
+#    c = config
+#    h = header
+#    l = conf-log
+#    p = private
+#    s = setup
+#    o = ops-log
+#
+
+Dictionary Name:   ESO-VLT-DIC.MACS_ICS
+Scope:             MACS
+Source:            ESO VLT
+Version Control:   @(#) $Id: ESO-VLT-DIC.MACS_ICS,v 1.1.1.1 2007/08/24 09:49:23 amodigli Exp $
+Revision:          $Revision: 1.1.1.1 $
+Date:              2004-07-07
+Status:            Development
+Description:       ICB Template Instrument ICS keywords
+
+
+
+#
+# 1.1 General instrument config.
+#
+
+#
+# 1.2 Environments and LCUs
+#
+
+#
+# 2.1 ICS general config.
+#
+
+#
+# 2.2 ICS setup and header
+#
+Parameter Name:    INSi ID
+Class:             conf-log|config|header
+Context:           Instrument
+Type:              string
+Value Format:      %30s
+Unit:              
+Comment Format:    Instrument ID.
+Description:       Combines the ESO identification of the instrument
+                   and the software version of the control software.
+                   Format: NAME/HW-REV/SW-VERSION
+
+Parameter Name:    INSi DID
+Class:             config|header
+Context:           Instrument
+Type:              string
+Value Format:      %30s
+Unit:              
+Comment Format:    Data dictionary for INS.
+Description:       Name and version of ESO DID to which INS keywords
+                   comply to.
+
+Parameter Name:    INSi OPER
+Class:             header|setup
+Context:           Instrument
+Type:              string
+Value Format:      %30s
+Unit:              
+Comment Format:    Instrument Operator.
+Description:       Initials and family name of instrument operator or
+                   service observer.
+
+Parameter Name:    INSi SWSIM
+Class:             config|header|setup
+Context:           Instrument
+Type:              string
+Value Format:      %15s
+Unit:              
+Comment Format:    Software simulation.
+Description:       Possible values:
+                   NORMAL:  no simulation.
+                   LCU_SIM: LCU is simulated by WS simulator.
+                   HW_SIM:  Hardware is simulated on LCU.
+
+Parameter Name:    INSi MODE
+Class:             header|setup
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Instrument mode used.
+Description:       Acronym of instrument mode used. This acronym identifies
+                   the optical path within the instrument. Examples:
+                   BLUE, RED, DIC1, DIC2
+
+Parameter Name:    INSi PATH
+Class:             header
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Optical path used.
+Description:       The optical path within the instrument used for
+                   this exposure.
+
+#
+# The following configuration parameters describe the individual instrument
+# devices.  Each device type has its own set of configuration parameters.
+#
+# Defaults:
+#
+# - The <subsystem>.TYPE keyword specifies the implementation to be used
+#   for the device.  The default corresponds to the implementation supplied
+#   by Base ICS.
+#
+# - If the <subsystem>.PREFIX keyword is not supplied, then the 'FITS prefix'
+#   needed by the ic0 devices corresponds to the <subsystem>.
+#
+
+#
+# 3. Device configuration
+#
+# 3.1 Lamp
+# 3.2 Shutter
+#
+# 3.3 ADC
+# 3.4 Depolarizer
+# 3.5 Derotator
+# 3.6 Filter wheel
+# 3.7 Grating function (e.g. two gratings back to back)
+# 3.8 Mirror wheel or linear function
+# 3.9.1 Generic optical function
+# 3.9.2 Grism wheel
+# 3.10.1 Generic position function
+# 3.10.2 Focus: Linear position function
+# 3.10.3 Rot: Circular position function
+# 3.11.1 Length slit (two motors)
+# 3.11.2 Width slit (two motors)
+# 3.11.3 Slits wheel
+# 3.12 Tilt
+#
+# 3.13.1 Analog sensors
+# 3.13.2 Digital sensors
+# 3.13.3 Exposure meter
+
+#
+# 3.14 Special function
+#
+
+#
+# 3.1 Lamp
+#
+#   Config. FITS keywords:
+#	DEVNAME, DEVDESC, LCUID, AVAIL, ENABLED, SWSIM,
+#	ID, NAME, WARMUP, CHGABLE, TIMEOUT,
+#	SIGUSED, SIGDEV, SIGBITi, SIGLOWi.
+#   Setup and header FITS keywords:
+#	ID, NAME, ST, WAIT, SWSIM.
+#   Operational log FITS keywords:
+#	INIT, START, TIME, STOP, CHANGE.
+#   Maint. keywords (reserved):
+#	STAT, ONTIME, STBYTIME, READY.
+#
+
+# 3.1.1 Lamp config. FITS keywords
+#
+Parameter Name:    INSi LAMPi SWSIM
+Class:             config|header|ops-log
+Context:           Instrument
+Type:              logical
+Value Format:      %c
+Unit:              
+Comment Format:    If T, function is software simulated.
+Description:       If T, function is software simulated.
+
+Parameter Name:    INSi LAMPi ID
+Class:             conf-log|config|header
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Lamp ID.
+Description:       Hardware identification of lamp bulb unit.
+
+Parameter Name:    INSi LAMPi NAME
+Class:             conf-log|config|header|setup
+Context:           Instrument
+Type:              string
+Value Format:      %15s
+Unit:              
+Comment Format:    Lamp name.
+Description:       Name for lamp unit.
+
+Parameter Name:    INSi LAMPi WAIT
+Class:             config|setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              sec
+Comment Format:    Max. time [sec] to wait for lamp warm-up.
+Description:       ICS must check if the lamp is warm. If not, it must
+                   wait maximum n sec before replying. The reply is
+                   FAILURE if after this time the lamp is NOT warm yet.
+
+# Digital signals:
+
+# 3.1.2 Lamp setup and header FITS keywords
+#
+# INSi.LAMPi is used to address the device in commands such as SIM, ONLINE etc.
+Parameter Name:    INSi LAMPi
+Class:             header|ops-log|setup
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Lamp device.
+Description:       Lamp device.
+
+Parameter Name:    INSi LAMPi ST
+Class:             header|setup
+Context:           Instrument
+Type:              logical
+Value Format:      %c
+Unit:              
+Comment Format:    Lamp activated.
+Description:       Lamp activated.
+
+# 3.1.3 Lamp operational logs.
+#
+Parameter Name:    INSi LAMPi INIT
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Lamp hardware initialized.
+Description:       Lamp hardware initialized.
+
+Parameter Name:    INSi LAMPi START
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Lamp turned on.
+Description:       Lamp turned on.
+
+Parameter Name:    INSi LAMPi TIME
+Class:             ops-log
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              sec
+Comment Format:    Time [sec] lamp was on.
+Description:       Time [sec] lamp was on.
+
+Parameter Name:    INSi LAMPi STOP
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Lamp turned off.
+Description:       Lamp turned off.
+
+Parameter Name:    INSi LAMPi CHANGE
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Lamp changed.
+Description:       Lamp has been physically replaced.
+                   Maintenance operation.
+
+Parameter Name:    INSi LAMPi VALUE
+Class:             header|setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              
+Comment Format:    Lamp value.
+Description:       Lamp value.
+
+# 3.1.4 Lamp ICS GUI widget.
+#
+
+#
+# 3.2 Shutter
+#
+#   Config. FITS keywords:
+#	DEVNAME, DEVDESC, LCUID, AVAIL, ENABLED, SWSIM,
+#	ID, NAME, TIMEOUT
+#	SIGUSED, SIGDEV, SIGBITi, SIGLOWi.
+#   Setup and header FITS keywords:
+#	ID, NAME, ST, SWSIM.
+#   Operational log FITS keywords:
+#	INIT, OPEN, TIME, CLOSE.
+#   Maint. keywords (reserved):
+#	STAT, OPENTIME.
+#
+
+# 3.2.1 Shutter config. FITS keywords
+#
+Parameter Name:    INSi SHUTi SWSIM
+Class:             config|header|ops-log
+Context:           Instrument
+Type:              logical
+Value Format:      %c
+Unit:              
+Comment Format:    If T, function is software simulated.
+Description:       If T, function is software simulated.
+
+Parameter Name:    INSi SHUTi ID
+Class:             conf-log|config|header
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Shutter ID.
+Description:       Hardware identification of shutter unit.
+
+Parameter Name:    INSi SHUTi NAME
+Class:             conf-log|config|header
+Context:           Instrument
+Type:              string
+Value Format:      %15s
+Unit:              
+Comment Format:    Shutter name.
+Description:       Name for shutter unit.
+
+# Digital signals:
+
+# 3.2.2 Shutter setup and header FITS keywords
+#
+Parameter Name:    INSi SHUTi
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Shutter device.
+Description:       Shutter device.
+
+Parameter Name:    INSi SHUTi ST
+Class:             header|setup
+Context:           Instrument
+Type:              logical
+Value Format:      %c
+Unit:              
+Comment Format:    Shutter open.
+Description:       Shutter open.
+
+# 3.2.3 Shutter operational logs.
+#
+Parameter Name:    INSi SHUTi INIT
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Shutter initialized.
+Description:       Shutter initialized.
+
+Parameter Name:    INSi SHUTi OPEN
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Shutter opened.
+Description:       Shutter opened.
+
+Parameter Name:    INSi SHUTi TIME
+Class:             ops-log
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              sec
+Comment Format:    Time [sec] shutter was open.
+Description:       Time [sec] shutter was open.
+
+Parameter Name:    INSi SHUTi CLOSE
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Shutter closed.
+Description:       Shutter closed.
+
+# 3.2.4 Shutter ICS GUI widget.
+#
+
+#
+# 3.6 Filter wheel
+#
+#   Config. FITS keywords:
+#	DEVNAME, DEVDESC, LCUID, AVAIL, ENABLED, SWSIM,
+#	CHGABLE, POSNUM, POSIDi, IDi, NAMEi, FOCUSi.
+#   Setup and header FITS keywords:
+#	NO, ID, NAME, SWSIM.
+#   Maint. keywords (reserved):
+#	ENC, ENCREL, TURN, SPEED.
+#   Conf. log FITS keywords:
+#	INIT, MOVE, STOP, CHANGE.
+#
+
+# 3.6.1 Filter config. FITS keywords
+#
+Parameter Name:    INSi FILTi SWSIM
+Class:             config|header|ops-log
+Context:           Instrument
+Type:              logical
+Value Format:      %c
+Unit:              
+Comment Format:    If T, function is software simulated.
+Description:       If T, function is software simulated.
+
+# Each element position registers only the IDi of the mounted element.
+# A corresponding ID entry is searched to retrieve the rest of the
+# element data.
+#
+# A list of elements that can be mounted in this function is described
+# with entries IDi, NAMEi and FOCUSi (one keyword set describes one
+# element, see section 3.6 of the INS Common Software Spec. manual,
+# VLT-SPE-ESO-17240-0385).
+
+
+Parameter Name:    INSi FILTi IDi
+Class:             conf-log|config|header|setup
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Filter unique id.
+Description:       ESO identification number for the filter.
+                   Format: #n where n is a unique number for the
+                   observatory.
+
+Parameter Name:    INSi FILTi NAMEi
+Class:             conf-log|config|header|setup
+Context:           Instrument
+Type:              string
+Value Format:      %15s
+Unit:              
+Comment Format:    Filter name.
+Description:       Name for the filter.
+                   Format: SYSTEM/NAME where the filter system is
+                   given when applicable, eg BESS for Besselian.
+
+# 3.6.2 Filter setup and header FITS keywords
+#
+Parameter Name:    INSi FILTi
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Filter wheel device.
+Description:       Filter wheel device.
+
+Parameter Name:    INSi FILTi NO
+Class:             header|setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              
+Comment Format:    Filter wheel position index.
+Description:       Index of the selected position of the filter wheel
+
+Parameter Name:    INSi FILTi ENC
+Class:             setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              Enc
+Comment Format:    Filter wheel absolute position [Enc].
+Description:       Filter wheel absolute position [Enc].
+
+Parameter Name:    INSi FILTi ENCREL
+Class:             setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              Enc
+Comment Format:    Filter wheel relative position [Enc].
+Description:       Filter wheel relative position [Enc].
+
+Parameter Name:    INSi FILTi TURN
+Class:             setup
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Turn right/left.
+Description:       Turn the wheel to the right or to the left.
+
+Parameter Name:    INSi FILTi SPEED
+Class:             setup
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              
+Comment Format:    Turning speed.
+Description:       Speed (default units) the wheel is turned (see TURN).
+
+# 3.6.3 Filter operational logs.
+#
+Parameter Name:    INSi FILTi INIT
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Hardware initialisation.
+Description:       Hardware initialisation.
+
+Parameter Name:    INSi FILTi MOVE
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Motion execution.
+Description:       Motion execution.
+
+Parameter Name:    INSi FILTi STOP
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Motion stop.
+Description:       Motion stop.
+
+Parameter Name:    INSi FILTi CHANGE
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Filter changed.
+Description:       Filter element has been physically replaced.
+                   Maintenance operation.
+
+
+#
+# 3.8 Mirror
+#
+#   Config. FITS keywords:
+#	DEVNAME, DEVDESC, LCUID, AVAIL, ENABLED, SWSIM,
+#	POSNUM, POSIDi, IDi, NAMEi, FOCUSi.
+#   Setup and header FITS keywords:
+#	NO, ID.
+#   Maint. keywords (reserved):
+#	ENC, ENCREL, LIMIT, TURN, SPEED.
+#   Conf. log FITS keywords:
+#	INIT, MOVE, STOP.
+#
+
+# 3.8.1 Mirror config. FITS keywords
+#
+Parameter Name:    INSi MIRRi SWSIM
+Class:             config|header|ops-log
+Context:           Instrument
+Type:              logical
+Value Format:      %c
+Unit:              
+Comment Format:    If T, function is software simulated.
+Description:       If T, function is software simulated.
+
+Parameter Name:    INSi MIRRi IDi
+Class:             conf-log|config|header|setup
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Mirror unique ID.
+Description:       Name and hardware identification of mirror.
+                   Format: NAME/SER-NO
+
+Parameter Name:    INSi MIRRi NAMEi
+Class:             conf-log|config|header|setup
+Context:           Instrument
+Type:              string
+Value Format:      %15s
+Unit:              
+Comment Format:    Mirror name.
+Description:       Name for the mirror.
+
+Parameter Name:    INSi MIRRi TYPEi
+Class:             conf-log|config
+Context:           Instrument
+Type:              string
+Value Format:      %19s
+Unit:              
+Comment Format:    Element type.
+Description:       Kind of optical element described.
+
+# 3.8.2 Mirror setup and header FITS keywords
+#
+Parameter Name:    INSi MIRRi
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Mirror device.
+Description:       Mirror device.
+
+Parameter Name:    INSi MIRRi NO
+Class:             header|setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              
+Comment Format:    Mirror slide position.
+Description:       Index of the position of the mirror slide
+
+Parameter Name:    INSi MIRRi ENC
+Class:             setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              Enc
+Comment Format:    Mirror slide absolute position [Enc].
+Description:       Mirror slide absolute position [Enc].
+
+Parameter Name:    INSi MIRRi ENCREL
+Class:             setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              Enc
+Comment Format:    Mirror slide relative position [Enc].
+Description:       Mirror slide relative position [Enc].
+
+Parameter Name:    INSi MIRRi LIMIT
+Class:             setup
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Move to the limit.
+Description:       Move to the lower or upper limit.
+
+Parameter Name:    INSi MIRRi TURN
+Class:             setup
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Turn right/left.
+Description:       Turn the wheel to the right or to the left.
+
+Parameter Name:    INSi MIRRi SPEED
+Class:             setup
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              
+Comment Format:    Moving speed.
+Description:       Speed (default units) the motor is moved (see LIMIT).
+
+# 3.8.3 Mirror operational logs.
+#
+Parameter Name:    INSi MIRRi INIT
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Hardware initialisation.
+Description:       Hardware initialisation.
+
+Parameter Name:    INSi MIRRi MOVE
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Motion execution.
+Description:       Motion execution.
+
+Parameter Name:    INSi MIRRi STOP
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Motion stop.
+Description:       Motion stop.
+
+# 3.8.4 Mirror ICS GUI widget.
+#
+
+
+#
+# 3.9.1 Generic optical function
+#
+#   Config. FITS keywords:
+#	DEVNAME, DEVDESC, LCUID, AVAIL, ENABLED, SWSIM,
+#	CHGABLE, POSNUM, POSIDi, IDi, NAMEi, TYPEi, FOCUSi, ALIGNi.
+#   Setup and header FITS keywords:
+#	NO, ID, NAME, TYPE.
+#   Maint. keywords (reserved):
+#	ENC, ENCREL, LIMIT, TURN, SPEED.
+#   Conf. log FITS keywords:
+#	INIT, MOVE, STOP, CHANGE.
+#
+
+# 3.9.1.1 Optical function config. FITS keywords
+#
+Parameter Name:    INSi OPTIi SWSIM
+Class:             config|header|ops-log
+Context:           Instrument
+Type:              logical
+Value Format:      %c
+Unit:              
+Comment Format:    If T, function is software simulated.
+Description:       If T, function is software simulated.
+
+# Each element position registers only the IDi of the mounted element.
+# A corresponding ID entry is searched to retrieve the rest of the
+# element data.
+#
+# A list of elements that can be mounted in this function is described
+# with entries IDi, NAMEi, etc. (one keyword set describes one element,
+# see section 3.6 of the INS Common Software Spec. manual,
+# VLT-SPE-ESO-17240-0385).
+
+
+Parameter Name:    INSi OPTIi IDi
+Class:             conf-log|config|header|setup
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    OPTIi unique ID.
+Description:       Identification of element.
+
+Parameter Name:    INSi OPTIi NAMEi
+Class:             conf-log|config|header|setup
+Context:           Instrument
+Type:              string
+Value Format:      %15s
+Unit:              
+Comment Format:    OPTIi name.
+Description:       Name of element.
+
+Parameter Name:    INSi OPTIi TYPEi
+Class:             conf-log|config|header
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    OPTIi element.
+Description:       Kind of optical element described.
+
+Parameter Name:    INSi OPTIi ALIGNi
+Class:             config|setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              Enc
+Comment Format:    OPTIi element alignment [Enc].
+Description:       Alignment value of element.
+
+# 3.9.1.2 Optical function setup and header FITS keywords
+#
+Parameter Name:    INSi OPTIi
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Generic Optical device.
+Description:       Generic Optical device.
+
+Parameter Name:    INSi OPTIi NO
+Class:             conf-log|header|setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              
+Comment Format:    OPTIi slot number.
+Description:       When OPTIi can mount more than one element, like
+                   filters on a wheel, this keyword gives the number
+                   of the slot positioned in the optical axis.
+
+Parameter Name:    INSi OPTIi ENC
+Class:             setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              Enc
+Comment Format:    Component absolute position [Enc].
+Description:       Component absolute position [Enc].
+
+Parameter Name:    INSi OPTIi ENCREL
+Class:             setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              Enc
+Comment Format:    Component relative position [Enc].
+Description:       Component relative position [Enc].
+
+Parameter Name:    INSi OPTIi LIMIT
+Class:             setup
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Move to the limit.
+Description:       Move to the lower or upper limit.
+
+Parameter Name:    INSi OPTIi TURN
+Class:             setup
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Turn right/left.
+Description:       Turn the wheel to the right or to the left.
+
+Parameter Name:    INSi OPTIi SPEED
+Class:             setup
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              
+Comment Format:    Moving speed.
+Description:       Speed (default units) the motor is moved (see LIMIT).
+
+# 3.9.1.3 Optical function operational logs.
+#
+Parameter Name:    INSi OPTIi INIT
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Hardware initialisation.
+Description:       Hardware initialisation.
+
+Parameter Name:    INSi OPTIi MOVE
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Motion execution.
+Description:       Motion execution.
+
+Parameter Name:    INSi OPTIi STOP
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Motion stop.
+Description:       Motion stop.
+
+Parameter Name:    INSi OPTIi CHANGE
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Element changed.
+Description:       Element has been physically replaced.
+                   Maintenance operation.
+
+#
+# 3.10.1 Generic position function
+#
+#   Config. FITS keywords:
+#	DEVNAME, DEVDESC, LCUID, AVAIL, ENABLED, SWSIM,
+#	FRML, POSMIN, POSMAX, TOLERANC, OFFSET, RAMP.
+#   Setup and header FITS keywords:
+#	POS.
+#   Maint. keywords (reserved):
+#	ENC, ENCREL, LIMIT, TURN, SPEED.
+#   Conf. log FITS keywords:
+#	INIT, MOVE, STOP.
+#
+
+# 3.10.1.1 Position function config. FITS keywords
+#
+Parameter Name:    INSi POSi SWSIM
+Class:             config|header|ops-log
+Context:           Instrument
+Type:              logical
+Value Format:      %c
+Unit:              
+Comment Format:    If T, function is software simulated.
+Description:       If T, function is software simulated.
+
+Parameter Name:    INSi POSi FRML
+Class:             header
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Conversion Formula.
+Description:       ENC=OFFSET+RAMP*POS+TEMPRAMP*(TEMP-TEMPREF).
+
+Parameter Name:    INSi POSi POSMIN
+Class:             config|header
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              <user
+Comment Format:    Minimum position value [<user].
+Description:       Minimum position value [<user unit>].
+
+Parameter Name:    INSi POSi POSMAX
+Class:             config|header
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              <user
+Comment Format:    Maximum position value [<user].
+Description:       Maximum position value [<user unit>].
+
+# 3.10.1.2 Position function setup and header FITS keywords
+#
+Parameter Name:    INSi POSi
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Generic Position device.
+Description:       Generic Position device.
+
+Parameter Name:    INSi POSi POS
+Class:             header|setup
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              mm
+Comment Format:    Position [mm].
+Description:       Position [mm].
+
+Parameter Name:    INSi POSi TEMP
+Class:             setup
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              deg
+Comment Format:    Temperature used to adjust the position [deg].
+Description:       Temperature used to adjust the position [deg].
+
+Parameter Name:    INSi POSi ENC
+Class:             header|setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              Enc
+Comment Format:    Absolute position [Enc].
+Description:       Absolute position [Enc].
+
+Parameter Name:    INSi POSi ENCREL
+Class:             setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              Enc
+Comment Format:    Relative position [Enc].
+Description:       Relative position [Enc].
+
+Parameter Name:    INSi POSi LIMIT
+Class:             setup
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Move to the limit.
+Description:       Move to the lower or upper limit.
+
+Parameter Name:    INSi POSi TURN
+Class:             setup
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Turn right/left.
+Description:       Turn the wheel to the right or to the left.
+
+Parameter Name:    INSi POSi SPEED
+Class:             setup
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              
+Comment Format:    Moving speed.
+Description:       Speed (default units) the motor is moved (see TURN).
+
+# 3.10.1.3 Position function operational logs.
+#
+Parameter Name:    INSi POSi INIT
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Hardware initialisation.
+Description:       Hardware initialisation.
+
+Parameter Name:    INSi POSi MOVE
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Motion execution.
+Description:       Motion execution.
+
+Parameter Name:    INSi POSi STOP
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Motion stop.
+Description:       Motion stop.
+
+# 3.10.1.4 Position function ICS GUI widget.
+#
+
+
+#
+# 3.10.2 Focus: Linear position function
+#
+#   Config. FITS keywords:
+#	See INSi.POSi keywords.
+#   Setup and header FITS keywords:
+#	POS, TEMP.
+#   Maint. keywords (reserved):
+#	ENC, ENCREL, LIMIT, TURN, SPEED.
+#   Conf. log FITS keywords:
+#	INIT, MOVE, STOP.
+#
+
+# 3.10.2.1 Position function config. FITS keywords
+#
+Parameter Name:    INSi FOCUi SWSIM
+Class:             header|ops-log
+Context:           Instrument
+Type:              logical
+Value Format:      %c
+Unit:              
+Comment Format:    If T, function is software simulated.
+Description:       If T, function is software simulated.
+
+# 3.10.2.2 Position function setup and header FITS keywords
+#
+Parameter Name:    INSi FOCUi
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Generic focus device.
+Description:       Generic focus device.
+
+Parameter Name:    INSi FOCUi POS
+Class:             header|setup
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              mm
+Comment Format:    Position [mm].
+Description:       Position [mm].
+
+Parameter Name:    INSi FOCUi TEMP
+Class:             setup
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              deg
+Comment Format:    Temperature used to adjust the position [deg].
+Description:       Temperature used to adjust the position [deg].
+
+Parameter Name:    INSi FOCUi ENC
+Class:             header|setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              Enc
+Comment Format:    Absolute position [Enc].
+Description:       Absolute position [Enc].
+
+Parameter Name:    INSi FOCUi ENCREL
+Class:             setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              Enc
+Comment Format:    Relative position [Enc].
+Description:       Relative position [Enc].
+
+Parameter Name:    INSi FOCUi LIMIT
+Class:             setup
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Move to the limit.
+Description:       Move to the lower or upper limit.
+
+Parameter Name:    INSi FOCUi TURN
+Class:             setup
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Turn right/left.
+Description:       Turn the wheel to the right or to the left.
+
+Parameter Name:    INSi FOCUi SPEED
+Class:             setup
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              
+Comment Format:    Moving speed.
+Description:       Speed (default units) the motor is moved (see TURN).
+
+# 3.10.2.3 Position function operational logs.
+#
+Parameter Name:    INSi FOCUi INIT
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Hardware initialisation.
+Description:       Hardware initialisation.
+
+Parameter Name:    INSi FOCUi MOVE
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Motion execution.
+Description:       Motion execution.
+
+Parameter Name:    INSi FOCUi STOP
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Motion stop.
+Description:       Motion stop.
+
+# 3.10.2.4 Position function ICS GUI widget.
+#
+
+
+#
+# 3.10.3 Rot: Circular position function
+#
+#   Config. FITS keywords:
+#	See INSi.POSi keywords.
+#   Setup and header FITS keywords:
+#	POS, TEMP.
+#   Maint. keywords (reserved):
+#	ENC, ENCREL, LIMIT, TURN, SPEED.
+#   Conf. log FITS keywords:
+#	INIT, MOVE, STOP.
+#
+
+# 3.10.3.1 Position function config. FITS keywords
+#
+Parameter Name:    INSi ROTi SWSIM
+Class:             header|ops-log
+Context:           Instrument
+Type:              logical
+Value Format:      %c
+Unit:              
+Comment Format:    If T, function is software simulated.
+Description:       If T, function is software simulated.
+
+Parameter Name:    INSi ROTi TYPE
+Class:             conf-log|header
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    ROTi element.
+Description:       Kind of optical element described.
+
+# 3.10.3.2 Position function setup and header FITS keywords
+#
+Parameter Name:    INSi ROTi
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Generic rotating device.
+Description:       Generic rotating device.
+
+Parameter Name:    INSi ROTi POS
+Class:             header|setup
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              deg
+Comment Format:    Position [deg].
+Description:       Position [deg].
+
+Parameter Name:    INSi ROTi TEMP
+Class:             setup
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              deg
+Comment Format:    Temperature used to adjust the position [deg].
+Description:       Temperature used to adjust the position [deg].
+
+Parameter Name:    INSi ROTi ENC
+Class:             header|setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              Enc
+Comment Format:    Absolute position [Enc].
+Description:       Absolute position [Enc].
+
+Parameter Name:    INSi ROTi ENCREL
+Class:             setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              Enc
+Comment Format:    Relative position [Enc].
+Description:       Relative position [Enc].
+
+Parameter Name:    INSi ROTi TURN
+Class:             setup
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Turn right/left.
+Description:       Turn the wheel to the right or to the left.
+
+Parameter Name:    INSi ROTi SPEED
+Class:             setup
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              
+Comment Format:    Moving speed.
+Description:       Speed (default units) the motor is moved (see TURN).
+
+# 3.10.3.3 Position function operational logs.
+#
+Parameter Name:    INSi ROTi INIT
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Hardware initialisation.
+Description:       Hardware initialisation.
+
+Parameter Name:    INSi ROTi MOVE
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Motion execution.
+Description:       Motion execution.
+
+Parameter Name:    INSi ROTi STOP
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Motion stop.
+Description:       Motion stop.
+
+# 3.10.3.4 Position function ICS GUI widget.
+#
+
+#
+# 3.12 Tilt
+#
+#   Config. FITS keywords:
+#	DEVNAME, DEVDESC, LCUID, AVAIL, ENABLED, SWSIM,
+#	FRML, POSMIN, POSMAX, TOLERANC, OFFSET, RESOL.
+#   Setup and header FITS keywords:
+#	POS, TILT, TEMP.
+#   Maint. keywords (reserved):
+#	ENC, ENCREL, LIMIT, TURN, SPEED.
+#   Conf. log FITS keywords:
+#	INIT, MOVE, STOP.
+#
+
+Parameter Name:    INSi TIPi
+Class:             private
+Context:           Instrument
+Type:              string
+Value Format:      %5s
+Unit:              
+Comment Format:    Tip device.
+Description:       Used in connection with ENABLE/DISABLE commands
+
+Parameter Name:    INSi TIPi POS
+Class:             header|setup
+Context:           Instrument
+Type:              double
+Value Format:      %.3f
+Unit:              mm
+Comment Format:    Position [mm].
+Description:       Position [mm].
+
+Parameter Name:    INSi TIPi TEMP
+Class:             setup
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              deg
+Comment Format:    Temperature used to adjust the position [deg].
+Description:       Temperature used to adjust the position [deg].
+
+Parameter Name:    INSi TIPi ENC
+Class:             private|setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              
+Comment Format:    Component absolute encoder position.
+Description:       Component absolute encoder position.
+
+Parameter Name:    INSi TIPi ENCREL
+Class:             private|setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              
+Comment Format:    Component relative encoder position.
+Description:       Component relative encoder position.
+
+Parameter Name:    INSi TIPi INIT
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Hardware initialisation.
+Description:       Hardware initialisation.
+
+Parameter Name:    INSi TIPi MOVE
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Motion execution.
+Description:       Motion execution.
+
+Parameter Name:    INSi TIPi STOP
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Motion stop.
+Description:       Motion stop.
+
+Parameter Name:    INSi TIPi UNFORSEEN
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Unforeseen event.
+Description:       Unforeseen event.
+
+Parameter Name:    INSi TIPi SWSIM
+Class:             header|ops-log
+Context:           Instrument
+Type:              logical
+Value Format:      %c
+Unit:              
+Comment Format:    If T, function is software simulated.
+Description:       Function software simulation.
+
+Parameter Name:    INSi TIPi LIMIT
+Class:             private|setup
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Move to the limit.
+Description:       Move to the lower or upper limit.
+
+Parameter Name:    INSi TIPi SPEED
+Class:             private|setup
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              
+Comment Format:    Moving speed.
+Description:       Speed (default units) the motor is moved (see LIMIT).
+
+Parameter Name:    INSi TILTi
+Class:             private
+Context:           Instrument
+Type:              string
+Value Format:      %5s
+Unit:              
+Comment Format:    Tilt device.
+Description:       Used in connection with ENABLE/DISABLE commands
+
+Parameter Name:    INSi TILTi POS
+Class:             header|setup
+Context:           Instrument
+Type:              double
+Value Format:      %.3f
+Unit:              mm
+Comment Format:    Position [mm].
+Description:       Position [mm].
+
+Parameter Name:    INSi TILTi TEMP
+Class:             setup
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              deg
+Comment Format:    Temperature used to adjust the position [deg].
+Description:       Temperature used to adjust the position [deg].
+
+Parameter Name:    INSi TILTi ENC
+Class:             private|setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              
+Comment Format:    Component absolute encoder position.
+Description:       Component absolute encoder position.
+
+Parameter Name:    INSi TILTi ENCREL
+Class:             private|setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              
+Comment Format:    Component relative encoder position.
+Description:       Component relative encoder position.
+
+Parameter Name:    INSi TILTi INIT
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Hardware initialisation.
+Description:       Hardware initialisation.
+
+Parameter Name:    INSi TILTi MOVE
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Motion execution.
+Description:       Motion execution.
+
+Parameter Name:    INSi TILTi STOP
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Motion stop.
+Description:       Motion stop.
+
+Parameter Name:    INSi TILTi UNFORSEEN
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Unforeseen event.
+Description:       Unforeseen event.
+
+Parameter Name:    INSi TILTi SWSIM
+Class:             header|ops-log
+Context:           Instrument
+Type:              logical
+Value Format:      %c
+Unit:              
+Comment Format:    If T, function is software simulated.
+Description:       Function software simulation.
+
+Parameter Name:    INSi TILTi LIMIT
+Class:             private|setup
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Move to the limit.
+Description:       Move to the lower or upper limit.
+
+Parameter Name:    INSi TILTi SPEED
+Class:             private|setup
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              
+Comment Format:    Moving speed.
+Description:       Speed (default units) the motor is moved (see LIMIT).
+
+
+#
+# 3.13 Sensors
+#
+# Each sensor device INSi.SENSORi manages a set of related sensors values
+# INSi.SENSi.  The index SENSi of each sensor value must be unique within
+# the instrument (to be able to report each sensor value with a different
+# FITS keyword).
+#
+# There is no relation between sensor device indexes (SENSORi) and sensor
+# value indexes (SENSi), e.g. one sensor device INSi.SENSOR3 can manage
+# e.g. the sensor values INSi.SENS12 to INSi.SENS16.
+#
+# The sensor values managed by one sensor device are usually connected
+# to a single harware port (PORT).  The hardware port of analog sensors
+# is normally a serial port, the hardware 'port' of a digital sensor
+# device is an ACRO board.
+#
+
+#
+# 3.13.1 Analog sensors
+#
+#   Config. FITS keywords:
+#	DEVNAME, DEVDESC, DEVTYPE, LCUID, AVAIL, ENABLED, SWSIM,
+#	PORT, NUM, NAMEi, DESCi, HEADERi, FITSi, LOGi,
+#	SENADDRi, SENTYPEi, SENREFi, SENRAMPi, SENUNITi.
+#   Setup and header FITS keywords:
+#	INSi.SENSi.ST, INSi.SENSi.STAT, INSi.SENSi.VAL, INSi.SENSi.REF.
+#   Maint. keywords (reserved):
+#	-
+#   Conf. log FITS keywords:
+#	INIT.
+#
+
+#
+# 3.13.2 Digital sensors (DEVTYPE=DIGITAL)
+#
+#   Config. FITS keywords:
+#	DEVNAME, DEVDESC, DEVTYPE, LCUID, AVAIL, ENABLED, SWSIM,
+#	ID, NAME, PORT, NUM, NAMEi, DESCi, HEADERi, FITSi, LOGi,
+#	SIGBITi, SIGWIDTHi, SIGLOWi, SIGVALi, SIGSIMi.
+#   Setup and header FITS keywords:
+#	INSi.SENSi.ST, INSi.SENSi.STAT, INSi.SENSi.VAL.
+#   Maint. keywords (reserved):
+#	-
+#   Conf. log FITS keywords:
+#	INIT.
+#
+
+# 3.13.[12].1 Sensors common config. FITS keywords
+#
+Parameter Name:    INSi SENSORi SWSIM
+Class:             config|header|ops-log
+Context:           Instrument
+Type:              logical
+Value Format:      %c
+Unit:              
+Comment Format:    If T, function is software simulated.
+Description:       If T, function is software simulated.
+
+Parameter Name:    INSi SENSORi ID
+Class:             conf-log|config|ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Sensor device unique id.
+Description:       ESO identification number for the sensor device.
+
+Parameter Name:    INSi SENSORi NAME
+Class:             conf-log|config|ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %30s
+Unit:              
+Comment Format:    Sensor device common name.
+Description:       Name for the sensor device.
+
+# 3.13.1.1 Analog sensors config. FITS keywords
+#
+
+# 3.13.2.1 Digital sensors config. FITS keywords
+#
+
+# 3.13.[12].2 Sensors setup and header FITS keywords
+#
+Parameter Name:    INSi SENSORi
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Sensor device.
+Description:       Sensor device.
+
+Parameter Name:    INSi SENSi ID
+Class:             header|ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    sensor ID.
+Description:       sensor ID.
+
+Parameter Name:    INSi SENSi NAME
+Class:             header|ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %30s
+Unit:              
+Comment Format:    sensor common name.
+Description:       sensor common name.
+
+Parameter Name:    INSi SENSi ST
+Class:             header|ops-log
+Context:           Instrument
+Type:              logical
+Value Format:      %c
+Unit:              
+Comment Format:    Sensor boolean value.
+Description:       Sensor boolean value.
+
+Parameter Name:    INSi SENSi STAT
+Class:             header|ops-log
+Context:           Instrument
+Type:              double
+Value Format:      %f
+Unit:              
+Comment Format:    Sensor string value.
+Description:       Sensor string value.
+
+Parameter Name:    INSi SENSi VAL
+Class:             header|ops-log
+Context:           Instrument
+Type:              double
+Value Format:      %f
+Unit:              
+Comment Format:    Sensor numeric value.
+Description:       Sensor numeric value.
+
+Parameter Name:    INSi SENSi REF
+Class:             header|ops-log
+Context:           Instrument
+Type:              double
+Value Format:      %f
+Unit:              
+Comment Format:    Sensor reference value.
+Description:       Sensor reference value.
+
+Parameter Name:    INSi TEMPi ID
+Class:             header|ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Temperature sensor ID.
+Description:       Temperature sensor ID.
+
+Parameter Name:    INSi TEMPi NAME
+Class:             header|ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %30s
+Unit:              
+Comment Format:    Temperature sensor name.
+Description:       Temperature sensor name.
+
+Parameter Name:    INSi TEMPi VAL
+Class:             header|ops-log
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              
+Comment Format:    Temperature sensor numeric value.
+Description:       Temperature sensor numeric value.
+
+Parameter Name:    INSi TEMPi REF
+Class:             header|ops-log
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              
+Comment Format:    Temperature sensor reference value.
+Description:       Temperature sensor reference value.
+# Statistical values
+# They are all calculated over the last exposure (i.e. considering
+# samples collected between EXPSTRT and EXPEND)
+Parameter Name:    INSi SENSi MIN
+Class:             header
+Context:           Instrument
+Type:              double
+Value Format:      %f
+Unit:              
+Comment Format:    Minimum value.
+Description:       Minimum value.
+
+Parameter Name:    INSi SENSi MAX
+Class:             header
+Context:           Instrument
+Type:              double
+Value Format:      %f
+Unit:              
+Comment Format:    Maximum value.
+Description:       Maximum value.
+
+Parameter Name:    INSi SENSi MEAN
+Class:             header|ops-log
+Context:           Instrument
+Type:              double
+Value Format:      %f
+Unit:              
+Comment Format:    Average value.
+Description:       Average value.
+
+Parameter Name:    INSi SENSi RMS
+Class:             header|ops-log
+Context:           Instrument
+Type:              double
+Value Format:      %f
+Unit:              
+Comment Format:    RMS of samples over exposure.
+Description:       RMS of samples over exposure.
+
+Parameter Name:    INSi SENSi TMMEAN
+Class:             header|ops-log
+Context:           Instrument
+Type:              double
+Value Format:      %f
+Unit:              
+Comment Format:    Time waighted average.
+Description:       Time waighted average.
+
+Parameter Name:    INSi SENSi GRAD
+Class:             header|ops-log
+Context:           Instrument
+Type:              double
+Value Format:      %f
+Unit:              
+Comment Format:    Linear regression slope.
+Description:       Linear regression slope.
+
+Parameter Name:    INSi SENSi DETCOEF
+Class:             header|ops-log
+Context:           Instrument
+Type:              double
+Value Format:      %f
+Unit:              
+Comment Format:    RMS of linear regression slope.
+Description:       RMS of linear regression slope.
+
+Parameter Name:    INSi TEMPi MIN
+Class:             header
+Context:           Instrument
+Type:              double
+Value Format:      %f
+Unit:              
+Comment Format:    Minimum value.
+Description:       Minimum value.
+
+Parameter Name:    INSi TEMPi MAX
+Class:             header
+Context:           Instrument
+Type:              double
+Value Format:      %f
+Unit:              
+Comment Format:    Maximum value.
+Description:       Maximum value.
+
+Parameter Name:    INSi TEMPi MEAN
+Class:             header|ops-log
+Context:           Instrument
+Type:              double
+Value Format:      %f
+Unit:              
+Comment Format:    Average value.
+Description:       Average value.
+
+Parameter Name:    INSi TEMPi RMS
+Class:             header|ops-log
+Context:           Instrument
+Type:              double
+Value Format:      %f
+Unit:              
+Comment Format:    RMS of samples over exposure.
+Description:       RMS of samples over exposure.
+
+Parameter Name:    INSi TEMPi TMMEAN
+Class:             header|ops-log
+Context:           Instrument
+Type:              double
+Value Format:      %f
+Unit:              
+Comment Format:    Time waighted average.
+Description:       Time waighted average.
+
+Parameter Name:    INSi TEMPi GRAD
+Class:             header|ops-log
+Context:           Instrument
+Type:              double
+Value Format:      %f
+Unit:              
+Comment Format:    Linear regression slope.
+Description:       Linear regression slope.
+
+Parameter Name:    INSi TEMPi DETCOEF
+Class:             header|ops-log
+Context:           Instrument
+Type:              double
+Value Format:      %f
+Unit:              
+Comment Format:    RMS of linear regression slope.
+Description:       RMS of linear regression slope.
+
+# 3.13.[12].3 Sensors operational logs.
+#
+Parameter Name:    INSi SENSORi INIT
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Hardware initialisation.
+Description:       Hardware initialisation.
+
+# 3.13.4 Sensors ICS GUI widget.
+#
+
+
+#
+# Field selector
+#
+# Basic ic0INS_DEVICE configuration
+#
+Parameter Name:    INSi FSELi DEVNAME
+Class:             config
+Context:           Instrument
+Type:              string
+Value Format:      %19s
+Unit:              
+Comment Format:    Name of the ICS device.
+Description:       Name of the ICS device.
+
+Parameter Name:    INSi FSELi DEVDESC
+Class:             config
+Context:           Instrument
+Type:              string
+Value Format:      %19s
+Unit:              
+Comment Format:    Description of the ICS device.
+Description:       Description of the ICS device.
+
+Parameter Name:    INSi FSELi LCUID
+Class:             config
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              
+Comment Format:    Id. of the LCU managing the device.
+Description:       Id. of the LCU managing the device.
+
+Parameter Name:    INSi FSELi AVAIL
+Class:             config
+Context:           Instrument
+Type:              logical
+Value Format:      %c
+Unit:              
+Comment Format:    Device availability flag.
+Description:       Device availability flag.
+
+Parameter Name:    INSi FSELi ENABLED
+Class:             config
+Context:           Instrument
+Type:              logical
+Value Format:      %c
+Unit:              
+Comment Format:    Flag for enabling and disabling.
+Description:       Flag for enabling and disabling.
+
+Parameter Name:    INSi FSELi SWSIM
+Class:             config|header|ops-log
+Context:           Instrument
+Type:              logical
+Value Format:      %c
+Unit:              
+Comment Format:    If T, function is software simulated.
+Description:       If T, function is software simulated.
+
+# Field selector specific setup
+Parameter Name:    INSi FSELi ALPHA
+Class:             header|setup
+Context:           Instrument
+Type:              double
+Value Format:      %f
+Unit:              
+Comment Format:    Abs Alpha offset form center field.
+Description:       Abs Alpha offset form center field.
+
+Parameter Name:    INSi FSELi DELTA
+Class:             header|setup
+Context:           Instrument
+Type:              double
+Value Format:      %f
+Unit:              
+Comment Format:    Abs Delta offset form center field.
+Description:       Abs Delta offset form center field.
+
+Parameter Name:    INSi FSELi ABSPOSX
+Class:             header|setup
+Context:           Instrument
+Type:              double
+Value Format:      %f
+Unit:              
+Comment Format:    Abs X in field mm.
+Description:       Abs X in field mm.
+
+Parameter Name:    INSi FSELi ABSPOSY
+Class:             header|setup
+Context:           Instrument
+Type:              double
+Value Format:      %f
+Unit:              
+Comment Format:    Abs Y in field mm.
+Description:       Abs Y in field mm.
+
+Parameter Name:    INSi FSELi FOCUS
+Class:             header|setup
+Context:           Instrument
+Type:              double
+Value Format:      %f
+Unit:              
+Comment Format:    Focus setting in mm.
+Description:       Focus setting in mm.
+
+Parameter Name:    INSi FSELi OFFALPHA
+Class:             header|setup
+Context:           Instrument
+Type:              double
+Value Format:      %f
+Unit:              
+Comment Format:    Rel Alpha offset form center field.
+Description:       Rel Alpha offset form center field.
+
+Parameter Name:    INSi FSELi OFFDELTA
+Class:             header|setup
+Context:           Instrument
+Type:              double
+Value Format:      %f
+Unit:              
+Comment Format:    Rel Delta offset form center field.
+Description:       Rel Delta offset form center field.
+
+Parameter Name:    INSi FSELi OFFX
+Class:             header|setup
+Context:           Instrument
+Type:              double
+Value Format:      %f
+Unit:              
+Comment Format:    Rel X Field MM from current pos.
+Description:       Rel X Field MM from current pos.
+
+Parameter Name:    INSi FSELi OFFY
+Class:             header|setup
+Context:           Instrument
+Type:              double
+Value Format:      %f
+Unit:              
+Comment Format:    Rel Y Field MM from current pos.
+Description:       Rel Y Field MM from current pos.
+
+Parameter Name:    INSi FSELi OFFFOCUS
+Class:             header|setup
+Context:           Instrument
+Type:              double
+Value Format:      %f
+Unit:              
+Comment Format:    Rel Focus setting in mm.
+Description:       Rel Focus setting in mm.
+
+Parameter Name:    INSi FSELi METROX
+Class:             header|setup
+Context:           Instrument
+Type:              double
+Value Format:      %f
+Unit:              
+Comment Format:    Rel metrology offset in focal plane mm(hs).
+Description:       Rel metrology offset in focal plane mm(hs).
+
+Parameter Name:    INSi FSELi METROY
+Class:             header|setup
+Context:           Instrument
+Type:              double
+Value Format:      %f
+Unit:              
+Comment Format:    Rel metrology offset in focal plane mm(hs).
+Description:       Rel metrology offset in focal plane mm(hs).
+
+Parameter Name:    INSi FSELi OFFGIMBTIP
+Class:             header|setup
+Context:           Instrument
+Type:              double
+Value Format:      %f
+Unit:              
+Comment Format:    Gimbal tip offset(hs).
+Description:       Gimbal tip offset(hs).
+
+Parameter Name:    INSi FSELi OFFGIMBTILT
+Class:             header|setup
+Context:           Instrument
+Type:              double
+Value Format:      %f
+Unit:              
+Comment Format:    Gimbal tilt offset(hs).
+Description:       Gimbal tilt offset(hs).
+
+Parameter Name:    INSi FSELi ENABLEREFRACT
+Class:             header|setup
+Context:           Instrument
+Type:              logical
+Value Format:      %c
+Unit:              
+Comment Format:    Enable atmospheric refraction calculation.
+Description:       Enable atmospheric refraction calculation.
+
+Parameter Name:    INSi FSELi CLOSEDLP
+Class:             header|setup
+Context:           Instrument
+Type:              logical
+Value Format:      %c
+Unit:              
+Comment Format:    Movement performed in closed loop flag(s).
+Description:       Movement performed in closed loop flag(s).
+
+Parameter Name:    INSi FSELi REFRACTRATE
+Class:             header|setup
+Context:           Instrument
+Type:              double
+Value Format:      %f
+Unit:              
+Comment Format:    Period in seconds at for update calculations.
+Description:       Period in seconds at for update calculations.
+
+Parameter Name:    INSi FSELi UPDATERATE
+Class:             header|setup
+Context:           Instrument
+Type:              double
+Value Format:      %f
+Unit:              
+Comment Format:    Period in seconds at for update calculations.
+Description:       Period in seconds at for update calculations.
+
+Parameter Name:    INSi FSELi ROBJ WLEN
+Class:             header|setup
+Context:           Instrument
+Type:              double
+Value Format:      %f
+Unit:              
+Comment Format:    Wavelength of object being tracked in nanometers
+Description:       Wavelength of object being tracked in nanometers
+
+Parameter Name:    INSi FSELi ROBJ OFFALPHA
+Class:             header|setup
+Context:           Instrument
+Type:              double
+Value Format:      %f
+Unit:              
+Comment Format:    Alpha offset of object being tracked
+Description:       Alpha offset of object being tracked
+
+Parameter Name:    INSi FSELi ROBJ OFFDELTA
+Class:             header|setup
+Context:           Instrument
+Type:              double
+Value Format:      %f
+Unit:              
+Comment Format:    Delta offset of object being tracked
+Description:       Delta offset of object being tracked
+
+Parameter Name:    INSi FSELi WHICHFIELD
+Class:             header|setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              
+Comment Format:    Select field for field selecor - debugging only(hs)
+Description:       Select field for field selecor - debugging only(hs)
+
+Parameter Name:    INSi TARG ALPHA
+Class:             header|setup
+Context:           Instrument
+Type:              double
+Value Format:      %f
+Unit:              
+Comment Format:    Abs Alpha of target.
+Description:       Abs Alpha of target.
+
+Parameter Name:    INSi TARG DELTA
+Class:             header|setup
+Context:           Instrument
+Type:              double
+Value Format:      %f
+Unit:              
+Comment Format:    Abs Delta of target.
+Description:       Abs Delta of target.
+
+Parameter Name:    INSi TARG WLEN
+Class:             header|setup
+Context:           Instrument
+Type:              double
+Value Format:      %f
+Unit:              
+Comment Format:    Wavelength of target in nanometers
+Description:       Wavelength of target in nanometers
+
+#___oOo___
+
diff --git a/calib/dic/ESO-VLT-DIC.SPIF_ICS b/calib/dic/ESO-VLT-DIC.SPIF_ICS
new file mode 100644
index 0000000..c4e6a4b
--- /dev/null
+++ b/calib/dic/ESO-VLT-DIC.SPIF_ICS
@@ -0,0 +1,3777 @@
+#******************************************************************************
+# E.S.O. - VLT project
+#
+# "@(#) $Id: ESO-VLT-DIC.SPIF_ICS,v 1.2 2007/09/05 15:09:37 amodigli Exp $"
+#
+# SPIF_ICS/ICB_CFG dictionaries
+#
+# Refer to appendix A of document VLT-SPE-ESO-17240-1676 for details.
+#
+# who       when      what
+# --------  --------  ----------------------------------------------
+# sinfmgr 2003-01-25 increased precision of TEMPi.VAL to %.4f
+# rabuter 2003-01-22 modified format of SENSi.VAL from %f to %.9f
+# rabuter 2002-11-14 increased precision of GRATi.WLEN from %.1f to %.3f
+# rabuter 2002-10-11 Added OFFSET keyword missing from the default and required by ics. see SPR 20020491
+# rabuter 2002-07-17 removed more junk
+# rabuter 2002-05-06 clean up
+# rabuter 2002-05-06 Copied from template dictionary
+#
+
+#******************************************************************************
+# NOTE FOR SPIF TEMPLATE INSTRUMENT MAINTAINERS
+# (this note can be ignored/deleted by other instruments)
+#
+# To keep files:
+#  icb/ws/src/icbDictionary.txt
+#  dicSPIF/src/dicSPIF_ICS.txt
+# in sync. please do NOT directly update file dicSPIF_ICS.txt.
+#
+# To update file dicSPIF_ICS.txt proceed as follows:
+#  1. cmmModify both modules: icb and dicSPIF.
+#  2. Update file icb/ws/src/icbDictionary.txt
+#  3. run (from icb/ws/src):  'make dicSPIF'
+#  4. copy the created file dicSPIF_ICS.txt to module dicSPIF.
+#  5. run (from icb/ws/src):  'make clean' before archiving module icb.
+#
+#******************************************************************************
+
+#******************************************************************************
+#
+# The SPIF_ICS dictionary contains all keywords used by SPIF ICS at
+# runtime to execute and understand commands with -function option,
+# such as SETUP and STATUS.
+#
+#******************************************************************************
+
+#
+# Notes
+# 1) The letters within () indicate the Class that keyword belongs to:
+#    c = config
+#    h = header
+#    l = conf-log
+#    p = private
+#    s = setup
+#    o = ops-log
+#
+
+Dictionary Name:   ESO-VLT-DIC.SPIF_ICS
+Scope:             SPIF
+Source:            ESO VLT
+Version Control:   @(#) $Id: ESO-VLT-DIC.SPIF_ICS,v 1.2 2007/09/05 15:09:37 amodigli Exp $
+Revision:          $Revision: 1.2 $
+Date:              2004-07-07
+Status:            Development
+Description:       ICB Template Instrument ICS keywords
+
+
+
+#
+# 1.1 General instrument config.
+#
+
+#
+# 1.2 Environments and LCUs
+#
+
+#
+# 2.1 ICS general config.
+#
+
+#
+# 2.2 ICS setup and header
+#
+Parameter Name:    INS ID
+Class:             conf-log|config|header
+Context:           Instrument
+Type:              string
+Value Format:      %30s
+Unit:              
+Comment Format:    Instrument ID.
+Description:       Combines the ESO identification of the instrument
+                   and the software version of the control software.
+                   Format: NAME/HW-REV/SW-VERSION
+
+
+Parameter Name:    INS SETUP ID
+Class:             conf-log|config|header
+Context:           Instrument
+Type:              string
+Value Format:      %30s
+Unit:              
+Comment Format:    Instrument SETUP ID.
+Description:       Specifies instrument setup
+
+
+Parameter Name:    INS DID
+Class:             config|header
+Context:           Instrument
+Type:              string
+Value Format:      %30s
+Unit:              
+Comment Format:    Data dictionary for INS.
+Description:       Name and version of ESO DID to which INS keywords
+                   comply to.
+
+Parameter Name:    INS OPER
+Class:             header|setup
+Context:           Instrument
+Type:              string
+Value Format:      %30s
+Unit:              
+Comment Format:    Instrument Operator.
+Description:       Initials and family name of instrument operator or
+                   service observer.
+
+Parameter Name:    INS SWSIM
+Class:             config|header|setup
+Context:           Instrument
+Type:              string
+Value Format:      %15s
+Unit:              
+Comment Format:    Software simulation.
+Description:       Possible values:
+                   NORMAL:  no simulation.
+                   LCU_SIM: LCU is simulated by WS simulator.
+                   HW_SIM:  Hardware is simulated on LCU.
+
+Parameter Name:    INS MODE
+Class:             header|setup
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Instrument mode used.
+Description:       Acronym of instrument mode used. This acronym identifies
+                   the optical path within the instrument. Examples:
+                   BLUE, RED, DIC1, DIC2
+
+Parameter Name:    INS PATH
+Class:             header
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Optical path used.
+Description:       The optical path within the instrument used for
+                   this exposure.
+
+#
+# The following configuration parameters describe the individual instrument
+# devices.  Each device type has its own set of configuration parameters.
+#
+# Defaults:
+#
+# - The <subsystem>.TYPE keyword specifies the implementation to be used
+#   for the device.  The default corresponds to the implementation supplied
+#   by Base ICS.
+#
+# - If the <subsystem>.PREFIX keyword is not supplied, then the 'FITS prefix'
+#   needed by the ic0 devices corresponds to the <subsystem>.
+#
+
+#
+# 3. Device configuration
+#
+# 3.1 Lamp
+# 3.2 Shutter
+#
+# 3.3 ADC
+# 3.4 Depolarizer
+# 3.5 Derotator
+# 3.6 Filter wheel
+# 3.7 Grating function (e.g. two gratings back to back)
+# 3.8 Mirror wheel or linear function
+# 3.9.1 Generic optical function
+# 3.9.2 Grism wheel
+# 3.10.1 Generic position function
+# 3.10.2 Focus: Linear position function
+# 3.10.3 Rot: Circular position function
+# 3.11.1 Length slit (two motors)
+# 3.11.2 Width slit (two motors)
+# 3.11.3 Slits wheel
+# 3.12 Tilt
+#
+# 3.13.1 Analog sensors
+# 3.13.2 Digital sensors
+# 3.13.3 Exposure meter
+
+#
+# 3.14 Special function
+#
+
+#
+# 3.1 Lamp
+#
+#   Config. FITS keywords:
+#	DEVNAME, DEVDESC, LCUID, AVAIL, ENABLED, SWSIM,
+#	ID, NAME, WARMUP, CHGABLE, TIMEOUT,
+#	SIGUSED, SIGDEV, SIGBITi, SIGLOWi.
+#   Setup and header FITS keywords:
+#	ID, NAME, ST, WAIT, SWSIM.
+#   Operational log FITS keywords:
+#	INIT, START, TIME, STOP, CHANGE.
+#   Maint. keywords (reserved):
+#	STAT, ONTIME, STBYTIME, READY.
+#
+
+# 3.1.1 Lamp config. FITS keywords
+#
+Parameter Name:    INS LAMPi SWSIM
+Class:             config|header|ops-log
+Context:           Instrument
+Type:              logical
+Value Format:      %c
+Unit:              
+Comment Format:    If T, function is software simulated.
+Description:       If T, function is software simulated.
+
+Parameter Name:    INS LAMPi ID
+Class:             conf-log|config|header
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Lamp ID.
+Description:       Hardware identification of lamp bulb unit.
+
+Parameter Name:    INS LAMPi NAME
+Class:             conf-log|config|header|setup
+Context:           Instrument
+Type:              string
+Value Format:      %15s
+Unit:              
+Comment Format:    Lamp name.
+Description:       Name for lamp unit.
+
+Parameter Name:    INS LAMPi WAIT
+Class:             config|setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              sec
+Comment Format:    Max. time [sec] to wait for lamp warm-up.
+Description:       ICS must check if the lamp is warm. If not, it must
+                   wait maximum n sec before replying. The reply is
+                   FAILURE if after this time the lamp is NOT warm yet.
+
+# Digital signals:
+
+# 3.1.2 Lamp setup and header FITS keywords
+#
+# INS.LAMPi is used to address the device in commands such as SIM, ONLINE etc.
+Parameter Name:    INS LAMPi
+Class:             header|ops-log|setup
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Lamp device.
+Description:       Lamp device.
+
+Parameter Name:    INS LAMPi ST
+Class:             header|setup
+Context:           Instrument
+Type:              logical
+Value Format:      %c
+Unit:              
+Comment Format:    Lamp activated.
+Description:       Lamp activated.
+
+# 3.1.3 Lamp operational logs.
+#
+Parameter Name:    INS LAMPi INIT
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Lamp hardware initialized.
+Description:       Lamp hardware initialized.
+
+Parameter Name:    INS LAMPi START
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Lamp turned on.
+Description:       Lamp turned on.
+
+Parameter Name:    INS LAMPi TIME
+Class:             ops-log
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              sec
+Comment Format:    Time [sec] lamp was on.
+Description:       Time [sec] lamp was on.
+
+Parameter Name:    INS LAMPi STOP
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Lamp turned off.
+Description:       Lamp turned off.
+
+Parameter Name:    INS LAMPi CHANGE
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Lamp changed.
+Description:       Lamp has been physically replaced.
+                   Maintenance operation.
+# 3.1.4 Lamp ICS GUI widget.
+#
+
+#
+# 3.2 Shutter
+#
+#   Config. FITS keywords:
+#	DEVNAME, DEVDESC, LCUID, AVAIL, ENABLED, SWSIM,
+#	ID, NAME, TIMEOUT
+#	SIGUSED, SIGDEV, SIGBITi, SIGLOWi.
+#   Setup and header FITS keywords:
+#	ID, NAME, ST, SWSIM.
+#   Operational log FITS keywords:
+#	INIT, OPEN, TIME, CLOSE.
+#   Maint. keywords (reserved):
+#	STAT, OPENTIME.
+#
+
+# 3.2.1 Shutter config. FITS keywords
+#
+Parameter Name:    INS SHUTi SWSIM
+Class:             config|header|ops-log
+Context:           Instrument
+Type:              logical
+Value Format:      %c
+Unit:              
+Comment Format:    If T, function is software simulated.
+Description:       If T, function is software simulated.
+
+Parameter Name:    INS SHUTi ID
+Class:             conf-log|config|header
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Shutter ID.
+Description:       Hardware identification of shutter unit.
+
+Parameter Name:    INS SHUTi NAME
+Class:             conf-log|config|header
+Context:           Instrument
+Type:              string
+Value Format:      %15s
+Unit:              
+Comment Format:    Shutter name.
+Description:       Name for shutter unit.
+
+# Digital signals:
+
+# 3.2.2 Shutter setup and header FITS keywords
+#
+Parameter Name:    INS SHUTi
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Shutter device.
+Description:       Shutter device.
+
+Parameter Name:    INS SHUTi ST
+Class:             header|setup
+Context:           Instrument
+Type:              logical
+Value Format:      %c
+Unit:              
+Comment Format:    Shutter open.
+Description:       Shutter open.
+
+# 3.2.3 Shutter operational logs.
+#
+Parameter Name:    INS SHUTi INIT
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Shutter initialized.
+Description:       Shutter initialized.
+
+Parameter Name:    INS SHUTi OPEN
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Shutter opened.
+Description:       Shutter opened.
+
+Parameter Name:    INS SHUTi TIME
+Class:             ops-log
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              sec
+Comment Format:    Time [sec] shutter was open.
+Description:       Time [sec] shutter was open.
+
+Parameter Name:    INS SHUTi CLOSE
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Shutter closed.
+Description:       Shutter closed.
+
+# 3.2.4 Shutter ICS GUI widget.
+#
+
+#
+# 3.3 ADC
+#
+#   Config. FITS keywords:
+#	DEVNAME, DEVDESC, LCUID, AVAIL, ENABLED, SWSIM,
+#	PERIOD, REFENC, MOTSIGN, FORMULA, MINELEV,
+#	POSOFFST, COFFSET, PSLOPE, POFFSET, TSLOPE,
+#	TOFFSET, AFACTOR, DROTFACT.
+#   Setup and header FITS keywords:
+#	MODE, RA, DEC, TEMP, SENS1.
+#   Maint. keywords (reserved):
+#	POSANG, ENC, ENCREL, TURN, SPEED.
+#   Conf. log FITS keywords:
+#	INIT, MOVE, STOP.
+#
+
+# 3.3.1 ADC config. FITS keywords
+#
+Parameter Name:    INS ADCi SWSIM
+Class:             config|header|ops-log
+Context:           Instrument
+Type:              logical
+Value Format:      %c
+Unit:              
+Comment Format:    If T, function is software simulated.
+Description:       If T, function is software simulated.
+
+# 3.3.2 ADC setup and header FITS keywords
+#
+Parameter Name:    INS ADCi
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    ADC device.
+Description:       ADC device.
+
+Parameter Name:    INS ADCi MODE
+Class:             header|setup
+Context:           Instrument
+Type:              string
+Value Format:      %4s
+Unit:              
+Comment Format:    ADC mode.
+Description:       Possible values: AUTO, OFF.
+
+Parameter Name:    INS ADCi RA
+Class:             header|setup
+Context:           Instrument
+Type:              double
+Value Format:      %.6f
+Unit:              deg
+Comment Format:    Telescope right ascension [deg].
+Description:       Telescope right ascension [deg].
+
+Parameter Name:    INS ADCi DEC
+Class:             header|setup
+Context:           Instrument
+Type:              double
+Value Format:      %.5f
+Unit:              deg
+Comment Format:    Telescope desclination [deg].
+Description:       Telescope desclination [deg].
+
+Parameter Name:    INS ADCi POSANG
+Class:             header|setup
+Context:           Instrument
+Type:              double
+Value Format:      %.4f
+Unit:              deg
+Comment Format:    Position angle [deg].
+Description:       Position angle [deg].
+
+Parameter Name:    INS ADCi BEGIN
+Class:             header
+Context:           Instrument
+Type:              double
+Value Format:      %.4f
+Unit:              deg
+Comment Format:    Position angle at start [deg].
+Description:       Position angle at start [deg].
+
+Parameter Name:    INS ADCi END
+Class:             header
+Context:           Instrument
+Type:              double
+Value Format:      %.4f
+Unit:              deg
+Comment Format:    Position angle at end [deg].
+Description:       Position angle at end [deg].
+
+Parameter Name:    INS ADCi TEMP
+Class:             header|setup
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              C
+Comment Format:    Temperature [C].
+Description:       Temperature [C].
+
+Parameter Name:    INS ADCi SENS1
+Class:             header|setup
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              mbar
+Comment Format:    Pressure [mbar].
+Description:       Pressure [mbar].
+
+Parameter Name:    INS ADCi ENC
+Class:             setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              Enc
+Comment Format:    ADC absolute position [Enc].
+Description:       ADC absolute position [Enc].
+
+Parameter Name:    INS ADCi ENCREL
+Class:             setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              Enc
+Comment Format:    ADC relative position [Enc].
+Description:       ADC relative position [Enc].
+
+Parameter Name:    INS ADCi TURN
+Class:             setup
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Turn right/left.
+Description:       Turn the wheel to the right or to the left.
+
+Parameter Name:    INS ADCi SPEED
+Class:             setup
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              
+Comment Format:    Turning speed.
+Description:       Speed (default units) the wheel is turned (see TURN).
+
+# 3.3.3 ADC operational logs.
+#
+Parameter Name:    INS ADCi INIT
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Hardware initialisation.
+Description:       Hardware initialisation.
+
+Parameter Name:    INS ADCi MOVE
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Motion execution.
+Description:       Motion execution.
+
+Parameter Name:    INS ADCi STOP
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Motion stop.
+Description:       Motion stop.
+
+# 3.3.4 ADC ICS GUI widget.
+#
+
+
+#
+# 3.4 Depolarizer
+#
+#   Combined assembly of depolarizer and slide
+#	ID, MODE.
+#
+#   Config. FITS keywords:
+#	DEVNAME, DEVDESC, LCUID, AVAIL, ENABLED, SWSIM,
+#   Setup and header FITS keywords:
+#	ST.
+#   Maint. keywords (reserved):
+#	STAT, POS, ENC, ENCREL, TURN, SPEED.
+#   Conf. log FITS keywords:
+#	INIT, MOVE, STOP.
+#
+
+# 3.4.0 Combined assembly of depolarizer and slide
+Parameter Name:    INS DPOLi ID
+Class:             conf-log|config|header
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Depolarizer unique id.
+Description:       ESO identification number for the depolarizer.
+
+Parameter Name:    INS DPOLi MODE
+Class:             header|setup
+Context:           Instrument
+Type:              string
+Value Format:      %5s
+Unit:              
+Comment Format:    Instrument depolarizer mode.
+Description:       Possible values: ON, OFF.
+                   The MODE moves the associated slide IN, resp. OUT
+                   and turns or stops turning the depolarizer.
+
+# 3.4.1 Depolarizer config. FITS keywords
+#
+Parameter Name:    INS DPORi SWSIM
+Class:             config|header|ops-log
+Context:           Instrument
+Type:              logical
+Value Format:      %c
+Unit:              
+Comment Format:    If T, function is software simulated.
+Description:       If T, function is software simulated.
+
+# 3.4.2 Depolarizer setup and header FITS keywords
+#
+Parameter Name:    INS DPORi
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Depolarizer device.
+Description:       Depolarizer device.
+
+Parameter Name:    INS DPORi ST
+Class:             header|setup
+Context:           Instrument
+Type:              logical
+Value Format:      %c
+Unit:              
+Comment Format:    Instrument depolarizer rotating.
+Description:       Instrument depolarizer rotating.
+
+Parameter Name:    INS DPORi ENC
+Class:             setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              Enc
+Comment Format:    Depolarizer rotate absolute position [Enc].
+Description:       Depolarizer rotate absolute position [Enc].
+
+Parameter Name:    INS DPORi ENCREL
+Class:             setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              Enc
+Comment Format:    Depolarizer rotate relative position [Enc].
+Description:       Depolarizer rotate relative position [Enc].
+
+Parameter Name:    INS DPORi TURN
+Class:             setup
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Turn right/left.
+Description:       Turn the wheel to the right or to the left.
+
+Parameter Name:    INS DPORi SPEED
+Class:             setup
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              
+Comment Format:    Turning speed.
+Description:       Speed (default units) the wheel is turned (see TURN).
+
+# 3.4.3 Depolarizer operational logs.
+#
+Parameter Name:    INS DPORi INIT
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Hardware initialisation.
+Description:       Hardware initialisation.
+
+Parameter Name:    INS DPORi MOVE
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Motion execution.
+Description:       Motion execution.
+
+Parameter Name:    INS DPORi STOP
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Motion stop.
+Description:       Motion stop.
+
+# 3.4.4 Depolarizer ICS GUI widget.
+#
+
+
+#
+# 3.5 Derotator
+#
+#   Config. FITS keywords:
+#	DEVNAME, DEVDESC, LCUID, AVAIL, ENABLED, SWSIM,
+#	ANGMIN, ANGMAX, TOLERANC, SKYENC, ELEVENC, STATENCi,
+#	PERIOD, SPDMIN, SPDMAX.
+#   Setup and header FITS keywords:
+#	MODE, RA, DEC, POSANG, STATINDX,
+#	BEGIN, END, MIN, MAX, MEAN, SWSIM.
+#   Maint. keywords (reserved):
+#	ENC, ENCREL, TURN, SPEED.
+#   Conf. log FITS keywords:
+#	INIT, MOVE, STOP.
+#
+
+# 3.5.1 Derotator config. FITS keywords
+#
+Parameter Name:    INS DROTi SWSIM
+Class:             config|header|ops-log
+Context:           Instrument
+Type:              logical
+Value Format:      %c
+Unit:              
+Comment Format:    If T, function is software simulated.
+Description:       If T, function is software simulated.
+
+# 3.5.2 Derotator setup and header FITS keywords
+#
+Parameter Name:    INS DROTi
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Derotator device.
+Description:       Derotator device.
+
+Parameter Name:    INS DROTi MODE
+Class:             header|setup
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Instrument derotator mode.
+Description:       Possible values: REGULAR, VERT, STAT.
+
+Parameter Name:    INS DROTi RA
+Class:             setup
+Context:           Instrument
+Type:              double
+Value Format:      %.6f
+Unit:              deg
+Comment Format:    Telescope right ascension [deg].
+Description:       Telescope right ascension [deg].
+
+Parameter Name:    INS DROTi DEC
+Class:             setup
+Context:           Instrument
+Type:              double
+Value Format:      %.5f
+Unit:              deg
+Comment Format:    Telescope desclination [deg].
+Description:       Telescope desclination [deg].
+
+Parameter Name:    INS DROTi POSANG
+Class:             setup
+Context:           Instrument
+Type:              double
+Value Format:      %.4f
+Unit:              deg
+Comment Format:    Position angle [deg].
+Description:       Position angle [deg].
+
+Parameter Name:    INS DROTi POS
+Class:             header
+Context:           Instrument
+Type:              double
+Value Format:      %.4f
+Unit:              deg
+Comment Format:    Position angle [deg].
+Description:       Position angle [deg].
+
+Parameter Name:    INS DROTi STATINDX
+Class:             setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              
+Comment Format:    STAT position index.
+Description:       STAT position index.
+
+Parameter Name:    INS DROTi BEGIN
+Class:             header
+Context:           Instrument
+Type:              double
+Value Format:      %.4f
+Unit:              deg
+Comment Format:    Position angle at start [deg].
+Description:       Position angle at start [deg].
+
+Parameter Name:    INS DROTi END
+Class:             header
+Context:           Instrument
+Type:              double
+Value Format:      %.4f
+Unit:              deg
+Comment Format:    Position angle at end [deg].
+Description:       Position angle at end [deg].
+
+Parameter Name:    INS DROTi MIN
+Class:             header
+Context:           Instrument
+Type:              double
+Value Format:      %.4f
+Unit:              deg
+Comment Format:    Minimum position angle [deg].
+Description:       Minimum position angle [deg].
+
+Parameter Name:    INS DROTi MAX
+Class:             header
+Context:           Instrument
+Type:              double
+Value Format:      %.4f
+Unit:              deg
+Comment Format:    Maximum position angle [deg].
+Description:       Maximum position angle [deg].
+
+Parameter Name:    INS DROTi MEAN
+Class:             header
+Context:           Instrument
+Type:              double
+Value Format:      %.4f
+Unit:              deg
+Comment Format:    Average position angle [deg].
+Description:       Average position angle [deg].
+
+Parameter Name:    INS DROTi ENC
+Class:             setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              Enc
+Comment Format:    Derotator absolute position [Enc].
+Description:       Derotator absolute position [Enc].
+
+Parameter Name:    INS DROTi ENCREL
+Class:             setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              Enc
+Comment Format:    Derotator relative position [Enc].
+Description:       Derotator relative position [Enc].
+
+Parameter Name:    INS DROTi TURN
+Class:             setup
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Turn right/left.
+Description:       Turn the wheel to the right or to the left.
+
+Parameter Name:    INS DROTi SPEED
+Class:             setup
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              
+Comment Format:    Turning speed.
+Description:       Speed (default units) the wheel is turned (see TURN).
+
+# 3.5.3 Derotator operational logs.
+#
+Parameter Name:    INS DROTi INIT
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Hardware initialisation.
+Description:       Hardware initialisation.
+
+Parameter Name:    INS DROTi MOVE
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Motion execution.
+Description:       Motion execution.
+
+Parameter Name:    INS DROTi STOP
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Motion stop.
+Description:       Motion stop.
+
+# 3.5.4 Derotator ICS GUI widget.
+#
+
+
+#
+# 3.6 Filter wheel
+#
+#   Config. FITS keywords:
+#	DEVNAME, DEVDESC, LCUID, AVAIL, ENABLED, SWSIM,
+#	CHGABLE, POSNUM, POSIDi, IDi, NAMEi, FOCUSi.
+#   Setup and header FITS keywords:
+#	NO, ID, NAME, SWSIM.
+#   Maint. keywords (reserved):
+#	ENC, ENCREL, TURN, SPEED.
+#   Conf. log FITS keywords:
+#	INIT, MOVE, STOP, CHANGE.
+#
+
+# 3.6.1 Filter config. FITS keywords
+#
+Parameter Name:    INS FILTi SWSIM
+Class:             config|header|ops-log
+Context:           Instrument
+Type:              logical
+Value Format:      %c
+Unit:              
+Comment Format:    If T, function is software simulated.
+Description:       If T, function is software simulated.
+
+# Each element position registers only the IDi of the mounted element.
+# A corresponding ID entry is searched to retrieve the rest of the
+# element data.
+#
+# A list of elements that can be mounted in this function is described
+# with entries IDi, NAMEi and FOCUSi (one keyword set describes one
+# element, see section 3.6 of the INS Common Software Spec. manual,
+# VLT-SPE-ESO-17240-0385).
+
+
+Parameter Name:    INS FILTi IDi
+Class:             conf-log|config|header|setup
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Filter unique id.
+Description:       ESO identification number for the filter.
+                   Format: #n where n is a unique number for the
+                   observatory.
+
+Parameter Name:    INS FILTi NAMEi
+Class:             conf-log|config|header|setup
+Context:           Instrument
+Type:              string
+Value Format:      %15s
+Unit:              
+Comment Format:    Filter name.
+Description:       Name for the filter.
+                   Format: SYSTEM/NAME where the filter system is
+                   given when applicable, eg BESS for Besselian.
+
+# 3.6.2 Filter setup and header FITS keywords
+#
+Parameter Name:    INS FILTi
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Filter wheel device.
+Description:       Filter wheel device.
+
+Parameter Name:    INS FILTi NO
+Class:             header|setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              
+Comment Format:    Filter wheel position index.
+Description:       Index of the selected position of the filter wheel
+
+Parameter Name:    INS FILTi ENC
+Class:             setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              Enc
+Comment Format:    Filter wheel absolute position [Enc].
+Description:       Filter wheel absolute position [Enc].
+
+Parameter Name:    INS FILTi ENCREL
+Class:             setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              Enc
+Comment Format:    Filter wheel relative position [Enc].
+Description:       Filter wheel relative position [Enc].
+
+Parameter Name:    INS FILTi TURN
+Class:             setup
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Turn right/left.
+Description:       Turn the wheel to the right or to the left.
+
+Parameter Name:    INS FILTi SPEED
+Class:             setup
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              
+Comment Format:    Turning speed.
+Description:       Speed (default units) the wheel is turned (see TURN).
+
+# 3.6.3 Filter operational logs.
+#
+Parameter Name:    INS FILTi INIT
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Hardware initialisation.
+Description:       Hardware initialisation.
+
+Parameter Name:    INS FILTi MOVE
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Motion execution.
+Description:       Motion execution.
+
+Parameter Name:    INS FILTi STOP
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Motion stop.
+Description:       Motion stop.
+
+Parameter Name:    INS FILTi CHANGE
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Filter changed.
+Description:       Filter element has been physically replaced.
+                   Maintenance operation.
+
+# 3.6.4 Filter ICS GUI widget.
+#
+
+
+#
+# 3.7 Gratings
+#
+#   Config. FITS keywords:
+#	DEVNAME, DEVDESC, LCUID, AVAIL, ENABLED, SWSIM,
+#	CHGABLE, TOLERANC, ALIGNMIN, ALIGNMAX,
+#	FRML, RESOL, ROT, POSIDi,
+#	IDi, NAMEi, TYPEi, WLENMINi, WLENMAXi, ZORDERi, ALIGNi,
+#	GROOVESi, FOCUSi, DISPi.
+#   Setup and header FITS keywords:
+#	ID, NAME, WLEN, ORDER, TEMP,
+#	NO, ZORDER, ALIGN, GROOVES, DISP,
+#	FRML, RESOL, ROT.
+#   Maint. keywords (reserved):
+#	ALIGN, ENC, ENCREL, TURN, SPEED.
+#   Conf. log FITS keywords:
+#	INIT, MOVE, STOP, CHANGE.
+#
+#   Formula used to position a grating:
+#	ENC=ZORDER+ALIGN+RESOL*asin(WLEN*ORDER*GRV/(2*cos(ROT)))
+#	    +TEMPRAMP*(TEMP-TEMPREF)
+#
+
+# 3.7.1 Gratings config. FITS keywords
+#
+Parameter Name:    INS GRATi SWSIM
+Class:             config|header|ops-log
+Context:           Instrument
+Type:              logical
+Value Format:      %c
+Unit:              
+Comment Format:    If T, function is software simulated.
+Description:       If T, function is software simulated.
+
+# Each element position registers only the IDi of the mounted element.
+# A corresponding ID entry is searched to retrieve the rest of the
+# element data.
+#
+# A list of elements that can be mounted in this function is described
+# with entries IDi, NAMEi, etc. (one keyword set describes one element,
+# see section 3.6 of the INS Common Software Spec. manual,
+# VLT-SPE-ESO-17240-0385).
+#
+# If there are more than one element mounted (e.g. two gratings back
+# to back), that have to be exchanged together, consecutive set of
+# keywords correspond to one such assembly.
+#
+# E.g.:
+#   INS.GRAT1.ID1	CD#1
+#   INS.GRAT1.NAME1	Grating 1 of assembly 1
+#   ... other entries
+#
+#   INS.GRAT1.ID2	CD#2
+#   INS.GRAT1.NAME2	Grating 2 of assembly 1
+#   ... other entries
+#
+#   INS.GRAT1.ID3	CD#3
+#   INS.GRAT1.NAME3	Grating 1 of assembly 2
+#   ... other entries
+#
+#   INS.GRAT1.ID4	CD#4
+#   INS.GRAT1.NAME4	Grating 2 of assembly 2
+#   ... other entries
+#
+#   INS.GRAT1.POSID1	CD#3	<- assembly 2 is mounted.
+#   INS.GRAT1.POSID2	CD#4	<- assembly 2 is mounted.
+#
+
+Parameter Name:    INS GRATi FRML
+Class:             header
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Conversion Formula.
+Description:       ENC=ZORDER+ALIGN+RESOL*asin(WLEN*ORDER*GRV/(2*cos(ROT)))
+                   +TEMPRAMP*(TEMP-TEMPREF)
+
+Parameter Name:    INS GRATi RESOL
+Class:             config|header
+Context:           Instrument
+Type:              double
+Value Format:      %.3f
+Unit:              Enc/deg
+Comment Format:    Encoder resolution [Enc/deg].
+Description:       Encoder resolution RESOL used in the conversion
+                   formula:
+                   ENC=ZORDER+ALIGN+RESOL*asin(WLEN*ORDER*GRV/(2*cos(ROT)))
+                   +TEMPRAMP*(TEMP-TEMPREF)
+
+Parameter Name:    INS GRATi ROT
+Class:             conf-log|config|header
+Context:           Instrument
+Type:              double
+Value Format:      %.3f
+Unit:              deg
+Comment Format:    Grating rot angle [deg].
+Description:       Rotation angle of grating.
+                   The reference frame is given in the corresponding
+                   instrument specification.
+                   The rot angle ROT is used in the conversion formula:
+                   ENC=ZORDER+ALIGN+RESOL*asin(WLEN*ORDER*GRV/(2*cos(ROT)))
+                   +TEMPRAMP*(TEMP-TEMPREF)
+
+Parameter Name:    INS GRATi TEMPREF
+Class:             config|header
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              
+Comment Format:    Temperature reference value.
+Description:       The temperature reference is used in the conversion
+                   formula:
+                   ENC=ZORDER+ALIGN+RESOL*asin(WLEN*ORDER*GRV/(2*cos(ROT)))
+                   +TEMPRAMP*(TEMP-TEMPREF)
+
+Parameter Name:    INS GRATi IDi
+Class:             conf-log|config|header|setup
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Grating unique ID.
+Description:       ESO identification of grating unit.
+                   Format: #n where n is a unique number for the
+                   observatory.
+
+Parameter Name:    INS GRATi NAMEi
+Class:             conf-log|config|header|setup
+Context:           Instrument
+Type:              string
+Value Format:      %15s
+Unit:              
+Comment Format:    Grating common name.
+Description:       Name for grating unit.
+
+Parameter Name:    INS GRATi TYPEi
+Class:             conf-log|config
+Context:           Instrument
+Type:              string
+Value Format:      %19s
+Unit:              
+Comment Format:    Element type.
+Description:       Kind of optical element described.
+
+Parameter Name:    INS GRATi WLENMINi
+Class:             conf-log|config
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              nm
+Comment Format:    Minimum grating central wavelength [nm].
+Description:       Minimum wavelength that the grating transmits along
+                   the optical axis of the instrument.
+
+Parameter Name:    INS GRATi WLENMAXi
+Class:             conf-log|config
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              nm
+Comment Format:    Maximum grating central wavelength [nm].
+Description:       Maximum wavelength that the grating transmits along
+                   the optical axis of the instrument.
+
+Parameter Name:    INS GRATi ORDERMAXi
+Class:             conf-log|config
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              
+Comment Format:    Maximum order number.
+Description:       Maximum order number supported by the grating.
+                   If this keyword is not supplied, then the order
+                   number is fixed to 1 and the INS.GRATi.ORDER
+                   keyword is not accepted.
+
+Parameter Name:    INS GRATi ZORDERi
+Class:             conf-log|config|header
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              Enc
+Comment Format:    Grating zero order position [Enc].
+Description:       The zero order position ZORDER is used in the
+                   conversion formula:
+                   ENC=ZORDER+ALIGN+RESOL*asin(WLEN*ORDER*GRV/(2*cos(ROT)))
+                   +TEMPRAMP*(TEMP-TEMPREF)
+
+Parameter Name:    INS GRATi ALIGNi
+Class:             config|header|setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              Enc
+Comment Format:    Grating alignment value [Enc].
+Description:       The alignment value ALIGN is used in the conversion
+                   formula:
+                   ENC=ZORDER+ALIGN+RESOL*asin(WLEN*ORDER*GRV/(2*cos(ROT)))
+                   +TEMPRAMP*(TEMP-TEMPREF)
+
+Parameter Name:    INS GRATi GROOVESi
+Class:             conf-log|config|header
+Context:           Instrument
+Type:              double
+Value Format:      %.7f
+Unit:              gr/nm
+Comment Format:    Grating grooves / nm [gr/nm].
+Description:       Grating's number of grooves per nanometer GROOVES is
+                   used in the conversion formula.
+                   ENC=ZORDER+ALIGN+RESOL*asin(WLEN*ORDER*GRV/(2*cos(ROT)))
+                   +TEMPRAMP*(TEMP-TEMPREF)
+
+Parameter Name:    INS GRATi TEMPRAMPi
+Class:             config|header
+Context:           Instrument
+Type:              double
+Value Format:      %.3f
+Unit:              Enc/C
+Comment Format:    Temperature slope [Enc/C].
+Description:       The temperature slope is used in the conversion
+                   formula:
+                   ENC=ZORDER+ALIGN+RESOL*asin(WLEN*ORDER*GRV/(2*cos(ROT)))
+                   +TEMPRAMP*(TEMP-TEMPREF)
+                   Note: simultaneous use of TEMPRAMPi and FOCUSi is
+                   not supported.
+
+Parameter Name:    INS GRATi DISPi
+Class:             conf-log|config|header
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              nm/mm
+Comment Format:    Grating dispersion [nm/mm].
+Description:       Measured dispersion of grating unit.
+                   The grating dispersion is focal length dependent and
+                   therefore if the f ratio changes the dispersion
+                   needs to be updated.
+
+# 3.7.2 Gratings setup and header FITS keywords
+#
+Parameter Name:    INS GRATi
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Grating device.
+Description:       Grating device.
+
+Parameter Name:    INS GRATi NO
+Class:             header|setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              
+Comment Format:    Grating wheel position index.
+Description:       Index of the selected position of the grating wheel
+
+Parameter Name:    INS GRATi WLEN
+Class:             header|setup
+Context:           Instrument
+Type:              double
+Value Format:      %.3f
+Unit:              nm
+Comment Format:    Grating central wavelength [nm].
+Description:       Wavelength that the grating transmits along
+                   the optical axis of the instrument.
+
+Parameter Name:    INS GRATi ORDER
+Class:             header|setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              
+Comment Format:    Grating order number.
+Description:       Grating order number.
+
+Parameter Name:    INS GRATi TEMP
+Class:             header|setup
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              deg
+Comment Format:    Temperature used to adjust the grating position [deg].
+Description:       Temperature used to adjust the grating position [deg].
+
+Parameter Name:    INS GRATi ENC
+Class:             header|setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              Enc
+Comment Format:    Grating absolute position [Enc].
+Description:       Grating absolute position [Enc].
+
+Parameter Name:    INS GRATi ENCREL
+Class:             setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              Enc
+Comment Format:    Grating relative position [Enc].
+Description:       Grating relative position [Enc].
+
+Parameter Name:    INS GRATi TURN
+Class:             setup
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Turn right/left.
+Description:       Turn the wheel to the right or to the left.
+
+Parameter Name:    INS GRATi SPEED
+Class:             setup
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              
+Comment Format:    Turning speed.
+Description:       Speed (default units) the wheel is turned (see TURN).
+
+# 3.7.3 Gratings operational logs.
+#
+Parameter Name:    INS GRATi INIT
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Hardware initialisation.
+Description:       Hardware initialisation.
+
+Parameter Name:    INS GRATi MOVE
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Motion execution.
+Description:       Motion execution.
+
+Parameter Name:    INS GRATi STOP
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Motion stop.
+Description:       Motion stop.
+
+Parameter Name:    INS GRATi CHANGE
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Element changed.
+Description:       Element has been physically replaced.
+                   Maintenance operation.
+
+# 3.7.4 Gratings ICS GUI widget.
+#
+
+
+#
+# 3.8 Mirror
+#
+#   Config. FITS keywords:
+#	DEVNAME, DEVDESC, LCUID, AVAIL, ENABLED, SWSIM,
+#	POSNUM, POSIDi, IDi, NAMEi, FOCUSi.
+#   Setup and header FITS keywords:
+#	NO, ID.
+#   Maint. keywords (reserved):
+#	ENC, ENCREL, LIMIT, TURN, SPEED.
+#   Conf. log FITS keywords:
+#	INIT, MOVE, STOP.
+#
+
+# 3.8.1 Mirror config. FITS keywords
+#
+Parameter Name:    INS MIRRi SWSIM
+Class:             config|header|ops-log
+Context:           Instrument
+Type:              logical
+Value Format:      %c
+Unit:              
+Comment Format:    If T, function is software simulated.
+Description:       If T, function is software simulated.
+
+Parameter Name:    INS MIRRi IDi
+Class:             conf-log|config|header|setup
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Mirror unique ID.
+Description:       Name and hardware identification of mirror.
+                   Format: NAME/SER-NO
+
+Parameter Name:    INS MIRRi NAMEi
+Class:             conf-log|config|header|setup
+Context:           Instrument
+Type:              string
+Value Format:      %15s
+Unit:              
+Comment Format:    Mirror name.
+Description:       Name for the mirror.
+
+Parameter Name:    INS MIRRi TYPEi
+Class:             conf-log|config
+Context:           Instrument
+Type:              string
+Value Format:      %19s
+Unit:              
+Comment Format:    Element type.
+Description:       Kind of optical element described.
+
+# 3.8.2 Mirror setup and header FITS keywords
+#
+Parameter Name:    INS MIRRi
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Mirror device.
+Description:       Mirror device.
+
+Parameter Name:    INS MIRRi NO
+Class:             header|setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              
+Comment Format:    Mirror slide position.
+Description:       Index of the position of the mirror slide
+
+Parameter Name:    INS MIRRi ENC
+Class:             setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              Enc
+Comment Format:    Mirror slide absolute position [Enc].
+Description:       Mirror slide absolute position [Enc].
+
+Parameter Name:    INS MIRRi ENCREL
+Class:             setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              Enc
+Comment Format:    Mirror slide relative position [Enc].
+Description:       Mirror slide relative position [Enc].
+
+Parameter Name:    INS MIRRi LIMIT
+Class:             setup
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Move to the limit.
+Description:       Move to the lower or upper limit.
+
+Parameter Name:    INS MIRRi TURN
+Class:             setup
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Turn right/left.
+Description:       Turn the wheel to the right or to the left.
+
+Parameter Name:    INS MIRRi SPEED
+Class:             setup
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              
+Comment Format:    Moving speed.
+Description:       Speed (default units) the motor is moved (see LIMIT).
+
+# 3.8.3 Mirror operational logs.
+#
+Parameter Name:    INS MIRRi INIT
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Hardware initialisation.
+Description:       Hardware initialisation.
+
+Parameter Name:    INS MIRRi MOVE
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Motion execution.
+Description:       Motion execution.
+
+Parameter Name:    INS MIRRi STOP
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Motion stop.
+Description:       Motion stop.
+
+# 3.8.4 Mirror ICS GUI widget.
+#
+
+
+#
+# 3.9.1 Generic optical function
+#
+#   Config. FITS keywords:
+#	DEVNAME, DEVDESC, LCUID, AVAIL, ENABLED, SWSIM,
+#	CHGABLE, POSNUM, POSIDi, IDi, NAMEi, TYPEi, FOCUSi, ALIGNi.
+#   Setup and header FITS keywords:
+#	NO, ID, NAME, TYPE.
+#   Maint. keywords (reserved):
+#	ENC, ENCREL, LIMIT, TURN, SPEED.
+#   Conf. log FITS keywords:
+#	INIT, MOVE, STOP, CHANGE.
+#
+
+# 3.9.1.1 Optical function config. FITS keywords
+#
+Parameter Name:    INS OPTIi SWSIM
+Class:             config|header|ops-log
+Context:           Instrument
+Type:              logical
+Value Format:      %c
+Unit:              
+Comment Format:    If T, function is software simulated.
+Description:       If T, function is software simulated.
+
+# Each element position registers only the IDi of the mounted element.
+# A corresponding ID entry is searched to retrieve the rest of the
+# element data.
+#
+# A list of elements that can be mounted in this function is described
+# with entries IDi, NAMEi, etc. (one keyword set describes one element,
+# see section 3.6 of the INS Common Software Spec. manual,
+# VLT-SPE-ESO-17240-0385).
+
+
+Parameter Name:    INS OPTIi IDi
+Class:             conf-log|config|header|setup
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    OPTIi unique ID.
+Description:       Identification of element.
+
+Parameter Name:    INS OPTIi NAMEi
+Class:             conf-log|config|header|setup
+Context:           Instrument
+Type:              string
+Value Format:      %15s
+Unit:              
+Comment Format:    OPTIi name.
+Description:       Name of element.
+
+Parameter Name:    INS OPTIi TYPEi
+Class:             conf-log|config|header
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    OPTIi element.
+Description:       Kind of optical element described.
+
+Parameter Name:    INS OPTIi ALIGNi
+Class:             config|setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              Enc
+Comment Format:    OPTIi element alignment [Enc].
+Description:       Alignment value of element.
+
+# 3.9.1.2 Optical function setup and header FITS keywords
+#
+Parameter Name:    INS OPTIi
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Generic Optical device.
+Description:       Generic Optical device.
+
+Parameter Name:    INS OPTIi NO
+Class:             conf-log|header|setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              
+Comment Format:    OPTIi slot number.
+Description:       When OPTIi can mount more than one element, like
+                   filters on a wheel, this keyword gives the number
+                   of the slot positioned in the optical axis.
+
+Parameter Name:    INS OPTIi ENC
+Class:             setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              Enc
+Comment Format:    Component absolute position [Enc].
+Description:       Component absolute position [Enc].
+
+Parameter Name:    INS OPTIi ENCREL
+Class:             setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              Enc
+Comment Format:    Component relative position [Enc].
+Description:       Component relative position [Enc].
+
+Parameter Name:    INS OPTIi LIMIT
+Class:             setup
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Move to the limit.
+Description:       Move to the lower or upper limit.
+
+Parameter Name:    INS OPTIi TURN
+Class:             setup
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Turn right/left.
+Description:       Turn the wheel to the right or to the left.
+
+Parameter Name:    INS OPTIi SPEED
+Class:             setup
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              
+Comment Format:    Moving speed.
+Description:       Speed (default units) the motor is moved (see LIMIT).
+
+# 3.9.1.3 Optical function operational logs.
+#
+Parameter Name:    INS OPTIi INIT
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Hardware initialisation.
+Description:       Hardware initialisation.
+
+Parameter Name:    INS OPTIi MOVE
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Motion execution.
+Description:       Motion execution.
+
+Parameter Name:    INS OPTIi STOP
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Motion stop.
+Description:       Motion stop.
+
+Parameter Name:    INS OPTIi CHANGE
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Element changed.
+Description:       Element has been physically replaced.
+                   Maintenance operation.
+
+# 3.9.1.4 Optical function ICS GUI widget.
+#
+
+
+#
+# 3.9.2 Grism
+#
+#   Config. FITS keywords:
+#	See INS.OPTIi keywords.
+#   Setup and header FITS keywords:
+#	NO, ID, NAME, TYPE.
+#   Maint. keywords (reserved):
+#	ENC, ENCREL, LIMIT, TURN, SPEED.
+#   Conf. log FITS keywords:
+#	INIT, MOVE, STOP, CHANGE.
+#
+
+# 3.9.2.1 Grism config. FITS keywords
+#
+Parameter Name:    INS GRISi SWSIM
+Class:             header|ops-log
+Context:           Instrument
+Type:              logical
+Value Format:      %c
+Unit:              
+Comment Format:    If T, function is software simulated.
+Description:       If T, function is software simulated.
+
+# Each element position registers only the IDi of the mounted element.
+# A corresponding ID entry is searched to retrieve the rest of the
+# element data.
+#
+# A list of elements that can be mounted in this function is described
+# with entries IDi, NAMEi, etc. (one keyword set describes one element,
+# see section 3.6 of the INS Common Software Spec. manual,
+# VLT-SPE-ESO-17240-0385).
+
+Parameter Name:    INS GRISi IDi
+Class:             conf-log|header|setup
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    OPTIi unique ID.
+Description:       Identification of element.
+
+Parameter Name:    INS GRISi NAMEi
+Class:             conf-log|header|setup
+Context:           Instrument
+Type:              string
+Value Format:      %15s
+Unit:              
+Comment Format:    OPTIi name.
+Description:       Name of element.
+
+Parameter Name:    INS GRISi TYPEi
+Class:             conf-log|header
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    OPTIi element.
+Description:       Kind of optical element described.
+
+Parameter Name:    INS GRISi ALIGNi
+Class:             setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              Enc
+Comment Format:    OPTIi element alignment [Enc].
+Description:       Alignment value of element.
+
+# 3.9.2.2 Grism setup and header FITS keywords
+#
+Parameter Name:    INS GRISi
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Grism device.
+Description:       Grism device.
+
+Parameter Name:    INS GRISi NO
+Class:             conf-log|header|setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              
+Comment Format:    OPTIi slot number.
+Description:       When OPTIi can mount more than one element, like
+                   filters on a wheel, this keyword gives the number
+                   of the slot positioned in the optical axis.
+
+Parameter Name:    INS GRISi ENC
+Class:             setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              Enc
+Comment Format:    Component absolute position [Enc].
+Description:       Component absolute position [Enc].
+
+Parameter Name:    INS GRISi ENCREL
+Class:             setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              Enc
+Comment Format:    Component relative position [Enc].
+Description:       Component relative position [Enc].
+
+Parameter Name:    INS GRISi LIMIT
+Class:             setup
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Move to the limit.
+Description:       Move to the lower or upper limit.
+
+Parameter Name:    INS GRISi TURN
+Class:             setup
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Turn right/left.
+Description:       Turn the wheel to the right or to the left.
+
+Parameter Name:    INS GRISi SPEED
+Class:             setup
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              
+Comment Format:    Moving speed.
+Description:       Speed (default units) the motor is moved (see LIMIT).
+
+# 3.9.2.3 Optical function operational logs.
+#
+Parameter Name:    INS GRISi INIT
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Hardware initialisation.
+Description:       Hardware initialisation.
+
+Parameter Name:    INS GRISi MOVE
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Motion execution.
+Description:       Motion execution.
+
+Parameter Name:    INS GRISi STOP
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Motion stop.
+Description:       Motion stop.
+
+Parameter Name:    INS GRISi CHANGE
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Element changed.
+Description:       Element has been physically replaced.
+                   Maintenance operation.
+
+# 3.9.2.4 Optical function ICS GUI widget.
+#
+
+
+#
+# 3.10.1 Generic position function
+#
+#   Config. FITS keywords:
+#	DEVNAME, DEVDESC, LCUID, AVAIL, ENABLED, SWSIM,
+#	FRML, POSMIN, POSMAX, TOLERANC, OFFSET, RAMP.
+#   Setup and header FITS keywords:
+#	POS.
+#   Maint. keywords (reserved):
+#	ENC, ENCREL, LIMIT, TURN, SPEED.
+#   Conf. log FITS keywords:
+#	INIT, MOVE, STOP.
+#
+
+# 3.10.1.1 Position function config. FITS keywords
+#
+Parameter Name:    INS POSi SWSIM
+Class:             config|header|ops-log
+Context:           Instrument
+Type:              logical
+Value Format:      %c
+Unit:              
+Comment Format:    If T, function is software simulated.
+Description:       If T, function is software simulated.
+
+Parameter Name:    INS POSi FRML
+Class:             header
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Conversion Formula.
+Description:       ENC=OFFSET+RAMP*POS+TEMPRAMP*(TEMP-TEMPREF).
+
+Parameter Name:    INS POSi POSMIN
+Class:             config|header
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              <user
+Comment Format:    Minimum position value [<user].
+Description:       Minimum position value [<user unit>].
+
+Parameter Name:    INS POSi POSMAX
+Class:             config|header
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              <user
+Comment Format:    Maximum position value [<user].
+Description:       Maximum position value [<user unit>].
+
+# 3.10.1.2 Position function setup and header FITS keywords
+#
+Parameter Name:    INS POSi
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Generic Position device.
+Description:       Generic Position device.
+
+Parameter Name:    INS POSi POS
+Class:             header|setup
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              <user
+Comment Format:    Position [<user].
+Description:       Position [<user unit>].
+
+Parameter Name:    INS POSi TEMP
+Class:             setup
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              deg
+Comment Format:    Temperature used to adjust the position [deg].
+Description:       Temperature used to adjust the position [deg].
+
+Parameter Name:    INS POSi ENC
+Class:             header|setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              Enc
+Comment Format:    Absolute position [Enc].
+Description:       Absolute position [Enc].
+
+Parameter Name:    INS POSi ENCREL
+Class:             setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              Enc
+Comment Format:    Relative position [Enc].
+Description:       Relative position [Enc].
+
+Parameter Name:    INS POSi LIMIT
+Class:             setup
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Move to the limit.
+Description:       Move to the lower or upper limit.
+
+Parameter Name:    INS POSi TURN
+Class:             setup
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Turn right/left.
+Description:       Turn the wheel to the right or to the left.
+
+Parameter Name:    INS POSi SPEED
+Class:             setup
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              
+Comment Format:    Moving speed.
+Description:       Speed (default units) the motor is moved (see TURN).
+
+# 3.10.1.3 Position function operational logs.
+#
+Parameter Name:    INS POSi INIT
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Hardware initialisation.
+Description:       Hardware initialisation.
+
+Parameter Name:    INS POSi MOVE
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Motion execution.
+Description:       Motion execution.
+
+Parameter Name:    INS POSi STOP
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Motion stop.
+Description:       Motion stop.
+
+# 3.10.1.4 Position function ICS GUI widget.
+#
+
+
+#
+# 3.10.2 Focus: Linear position function
+#
+#   Config. FITS keywords:
+#	See INS.POSi keywords.
+#   Setup and header FITS keywords:
+#	POS, TEMP.
+#   Maint. keywords (reserved):
+#	ENC, ENCREL, LIMIT, TURN, SPEED.
+#   Conf. log FITS keywords:
+#	INIT, MOVE, STOP.
+#
+
+# 3.10.2.1 Position function config. FITS keywords
+#
+Parameter Name:    INS FOCUi SWSIM
+Class:             header|ops-log
+Context:           Instrument
+Type:              logical
+Value Format:      %c
+Unit:              
+Comment Format:    If T, function is software simulated.
+Description:       If T, function is software simulated.
+
+# 3.10.2.2 Position function setup and header FITS keywords
+#
+Parameter Name:    INS FOCUi
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Generic focus device.
+Description:       Generic focus device.
+
+Parameter Name:    INS FOCUi POS
+Class:             header|setup
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              mm
+Comment Format:    Position [mm].
+Description:       Position [mm].
+
+Parameter Name:    INS FOCUi TEMP
+Class:             setup
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              deg
+Comment Format:    Temperature used to adjust the position [deg].
+Description:       Temperature used to adjust the position [deg].
+
+Parameter Name:    INS FOCUi ENC
+Class:             header|setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              Enc
+Comment Format:    Absolute position [Enc].
+Description:       Absolute position [Enc].
+
+Parameter Name:    INS FOCUi ENCREL
+Class:             setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              Enc
+Comment Format:    Relative position [Enc].
+Description:       Relative position [Enc].
+
+Parameter Name:    INS FOCUi LIMIT
+Class:             setup
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Move to the limit.
+Description:       Move to the lower or upper limit.
+
+Parameter Name:    INS FOCUi TURN
+Class:             setup
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Turn right/left.
+Description:       Turn the wheel to the right or to the left.
+
+Parameter Name:    INS FOCUi SPEED
+Class:             setup
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              
+Comment Format:    Moving speed.
+Description:       Speed (default units) the motor is moved (see TURN).
+
+# 3.10.2.3 Position function operational logs.
+#
+Parameter Name:    INS FOCUi INIT
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Hardware initialisation.
+Description:       Hardware initialisation.
+
+Parameter Name:    INS FOCUi MOVE
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Motion execution.
+Description:       Motion execution.
+
+Parameter Name:    INS FOCUi STOP
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Motion stop.
+Description:       Motion stop.
+
+# 3.10.2.4 Position function ICS GUI widget.
+#
+
+
+#
+# 3.10.3 Rot: Circular position function
+#
+#   Config. FITS keywords:
+#	See INS.POSi keywords.
+#   Setup and header FITS keywords:
+#	POS, TEMP.
+#   Maint. keywords (reserved):
+#	ENC, ENCREL, LIMIT, TURN, SPEED.
+#   Conf. log FITS keywords:
+#	INIT, MOVE, STOP.
+#
+
+# 3.10.3.1 Position function config. FITS keywords
+#
+Parameter Name:    INS ROTi SWSIM
+Class:             header|ops-log
+Context:           Instrument
+Type:              logical
+Value Format:      %c
+Unit:              
+Comment Format:    If T, function is software simulated.
+Description:       If T, function is software simulated.
+
+Parameter Name:    INS ROTi TYPE
+Class:             conf-log|header
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    ROTi element.
+Description:       Kind of optical element described.
+
+# 3.10.3.2 Position function setup and header FITS keywords
+#
+Parameter Name:    INS ROTi
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Generic rotating device.
+Description:       Generic rotating device.
+
+Parameter Name:    INS ROTi POS
+Class:             header|setup
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              deg
+Comment Format:    Position [deg].
+Description:       Position [deg].
+
+Parameter Name:    INS ROTi TEMP
+Class:             setup
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              deg
+Comment Format:    Temperature used to adjust the position [deg].
+Description:       Temperature used to adjust the position [deg].
+
+Parameter Name:    INS ROTi ENC
+Class:             header|setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              Enc
+Comment Format:    Absolute position [Enc].
+Description:       Absolute position [Enc].
+
+Parameter Name:    INS ROTi ENCREL
+Class:             setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              Enc
+Comment Format:    Relative position [Enc].
+Description:       Relative position [Enc].
+
+Parameter Name:    INS ROTi TURN
+Class:             setup
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Turn right/left.
+Description:       Turn the wheel to the right or to the left.
+
+Parameter Name:    INS ROTi SPEED
+Class:             setup
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              
+Comment Format:    Moving speed.
+Description:       Speed (default units) the motor is moved (see TURN).
+
+# 3.10.3.3 Position function operational logs.
+#
+Parameter Name:    INS ROTi INIT
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Hardware initialisation.
+Description:       Hardware initialisation.
+
+Parameter Name:    INS ROTi MOVE
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Motion execution.
+Description:       Motion execution.
+
+Parameter Name:    INS ROTi STOP
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Motion stop.
+Description:       Motion stop.
+
+# 3.10.3.4 Position function ICS GUI widget.
+#
+
+
+#
+# Length and width slits:
+#   If more than one slits exist, then the following keywords
+#   are recommended to be used:
+#	Config. keywords for the length slit: INS.SLITi1
+#	Config. keywords for the width  slit: INS.SLITi2
+#	Value for INS.SLITi1.PREFIX = "INS.SLITi"
+#	Value for INS.SLITi2.PREFIX = "INS.SLITi"
+#
+
+#
+# 3.11.1 Length slit (two motors)
+#
+#   Config. FITS keywords:
+#	DEVNAME, DEVDESC, LCUID, AVAIL, ENABLED, SWSIM,
+#   Setup and header FITS keywords:
+#	LEN.
+#   Maint. keywords (reserved):
+#	X1LEN, X2LEN, X1ENC, X2ENC, X1ENCREL, X2ENCREL,
+#	X1LIMIT, X2LIMIT, X1TURN, X2TURN, X1SPEED, X2SPEED.
+#   Conf. log FITS keywords:
+#	INIT, MOVE, STOP.
+#
+
+#
+# 3.11.2 Width slit (two motors)
+#
+#   Config. FITS keywords:
+#	DEVNAME, DEVDESC, LCUID, AVAIL, ENABLED, SWSIM,
+#   Setup and header FITS keywords:
+#	WID.
+#   Maint. keywords (reserved):
+#	Y1WID, Y2WID, Y1ENC, Y2ENC, Y1ENCREL, Y2ENCREL,
+#	Y1LIMIT, Y2LIMIT, Y1TURN, Y2TURN, Y1SPEED, Y2SPEED.
+#   Conf. log FITS keywords:
+#	INIT, MOVE, STOP.
+#
+
+#
+# 3.11.3 Slits wheel
+#
+#   Config. FITS keywords:
+#	DEVNAME, DEVDESC, LCUID, AVAIL, ENABLED, SWSIM,
+#	POSNUM, POSIDi, IDi, NAMEi, WIDi, LENi.
+#   Setup and header FITS keywords:
+#	NO, ID, NAME, WID, LEN.
+#   Maint. keywords (reserved):
+#	ENC, ENCREL, LIMIT, TURN, SPEED.
+#   Conf. log FITS keywords:
+#	INIT, MOVE, STOP, CHANGE.
+#
+
+# 3.11.[123].1 Common slit config. FITS keywords
+#
+
+# 3.11.1.1 Length slit config. FITS keywords
+#
+Parameter Name:    INS SLITi LENSWSIM
+Class:             header|ops-log
+Context:           Instrument
+Type:              logical
+Value Format:      %c
+Unit:              
+Comment Format:    If T, function is software simulated.
+Description:       If T, function is software simulated.
+
+Parameter Name:    INS SLITi X1FRML
+Class:             header
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Conversion Formula.
+Description:       ENC=X1OFFSET+X1RESOL*acos((LEN-(X1LENMAX+X1LENMIN))/(X1LENMAX-X1LENMIN))
+
+Parameter Name:    INS SLITi X2FRML
+Class:             header
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Conversion Formula.
+Description:       ENC=X2OFFSET+X2RESOL*acos((LEN-(X2LENMAX+X2LENMIN))/(X2LENMAX-X2LENMIN))
+
+Parameter Name:    INS SLITi X1OFFSET
+Class:             config|header
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              Enc
+Comment Format:    Left ref. position [Enc].
+Description:       The ref. position X1OFFSET is used in the conversion formula:
+                   ENC=X1OFFSET+X1RESOL*acos((LEN-(X1LENMAX+X1LENMIN))/(X1LENMAX-X1LENMIN))
+
+Parameter Name:    INS SLITi X2OFFSET
+Class:             config|header
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              Enc
+Comment Format:    Right ref. position [Enc].
+Description:       The ref. position X1OFFSET is used in the conversion formula:
+                   ENC=X2OFFSET+X2RESOL*acos((LEN-(X2LENMAX+X2LENMIN))/(X2LENMAX-X2LENMIN))
+
+Parameter Name:    INS SLITi X1RESOL
+Class:             config|header
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              Enc/deg
+Comment Format:    Left encoder resolution [Enc/deg].
+Description:       The encoder resolution X1RESOL is used in the conversion formula:
+                   ENC=X1OFFSET+X1RESOL*acos((LEN-(X1LENMAX+X1LENMIN))/(X1LENMAX-X1LENMIN))
+
+Parameter Name:    INS SLITi X2RESOL
+Class:             config|header
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              Enc/deg
+Comment Format:    Right encoder resolution [Enc/deg].
+Description:       The encoder resolution X2RESOL is used in the conversion formula:
+                   ENC=X2OFFSET+X2RESOL*acos((LEN-(X2LENMAX+X2LENMIN))/(X2LENMAX-X2LENMIN))
+
+Parameter Name:    INS SLITi X1LENMIN
+Class:             config|header
+Context:           Instrument
+Type:              double
+Value Format:      %.3f
+Unit:              arcsec
+Comment Format:    Left min. slit length [arcsec].
+Description:       The left min. slit length X1LENMIN is used in the conversion formula:
+                   ENC=X1OFFSET+X1RESOL*acos((LEN-(X1LENMAX+X1LENMIN))/(X1LENMAX-X1LENMIN))
+
+Parameter Name:    INS SLITi X1LENMAX
+Class:             config|header
+Context:           Instrument
+Type:              double
+Value Format:      %.3f
+Unit:              arcsec
+Comment Format:    Left max. slit length [arcsec].
+Description:       The left max. slit length X1LENMAX is used in the conversion formula:
+                   ENC=X1OFFSET+X1RESOL*acos((LEN-(X1LENMAX+X1LENMIN))/(X1LENMAX-X1LENMIN))
+
+Parameter Name:    INS SLITi X2LENMIN
+Class:             config|header
+Context:           Instrument
+Type:              double
+Value Format:      %.3f
+Unit:              arcsec
+Comment Format:    Right min. slit length [arcsec].
+Description:       The right min. slit length X2LENMIN is used in the conversion formula:
+                   ENC=X2OFFSET+X2RESOL*acos((LEN-(X2LENMAX+X2LENMIN))/(X2LENMAX-X2LENMIN))
+
+Parameter Name:    INS SLITi X2LENMAX
+Class:             config|header
+Context:           Instrument
+Type:              double
+Value Format:      %.3f
+Unit:              arcsec
+Comment Format:    Right max. slit length [arcsec].
+Description:       The right max. slit length X2LENMAX is used in the conversion formula:
+                   ENC=X2OFFSET+X2RESOL*acos((LEN-(X2LENMAX+X2LENMIN))/(X2LENMAX-X2LENMIN))
+
+# 3.11.2.1 Width slit config. FITS keywords
+#
+Parameter Name:    INS SLITi WIDSWSIM
+Class:             header|ops-log
+Context:           Instrument
+Type:              logical
+Value Format:      %c
+Unit:              
+Comment Format:    If T, function is software simulated.
+Description:       If T, function is software simulated.
+##INS.SLITi.TOLERANC	%.2f	LEN, WID tolerance [arcsec] (c).
+
+Parameter Name:    INS SLITi Y1FRML
+Class:             header
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Conversion Formula.
+Description:       ENC=Y1OFFSET+Y1RESOL*acos((WID-(Y1WIDMAX+Y1WIDMIN))/(Y1WIDMAX-Y1WIDMIN))
+
+Parameter Name:    INS SLITi Y2FRML
+Class:             header
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Conversion Formula.
+Description:       ENC=Y2OFFSET+Y2RESOL*acos((WID-(Y2WIDMAX+Y2WIDMIN))/(Y2WIDMAX-Y2WIDMIN))
+
+Parameter Name:    INS SLITi Y1OFFSET
+Class:             config|header
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              Enc
+Comment Format:    Left ref. position [Enc].
+Description:       The ref. position Y1OFFSET is used in the conversion formula:
+                   ENC=Y1OFFSET+Y1RESOL*acos((WID-(Y1WIDMAX+Y1WIDMIN))/(Y1WIDMAX-Y1WIDMIN))
+
+Parameter Name:    INS SLITi Y2OFFSET
+Class:             config|header
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              Enc
+Comment Format:    Right ref. position [Enc].
+Description:       The ref. position Y2OFFSET is used in the conversion formula:
+                   ENC=Y2OFFSET+Y2RESOL*acos((WID-(Y2WIDMAX+Y2WIDMIN))/(Y2WIDMAX-Y2WIDMIN))
+
+Parameter Name:    INS SLITi Y1RESOL
+Class:             config|header
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              Enc/deg
+Comment Format:    Left encoder resolution [Enc/deg].
+Description:       The encoder resolution Y1RESOL is used in the conversion formula:
+                   ENC=Y1OFFSET+Y1RESOL*acos((WID-(Y1WIDMAX+Y1WIDMIN))/(Y1WIDMAX-Y1WIDMIN))
+
+Parameter Name:    INS SLITi Y2RESOL
+Class:             config|header
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              Enc/deg
+Comment Format:    Right encoder resolution [Enc/deg].
+Description:       The encoder resolution Y2RESOL is used in the conversion formula:
+                   ENC=Y2OFFSET+Y2RESOL*acos((WID-(Y2WIDMAX+Y2WIDMIN))/(Y2WIDMAX-Y2WIDMIN))
+
+Parameter Name:    INS SLITi Y1WIDMIN
+Class:             config|header
+Context:           Instrument
+Type:              double
+Value Format:      %.3f
+Unit:              arcsec
+Comment Format:    Left min. slit width value [arcsec].
+Description:       The left min. slit length Y1LENMIN is used in the conversion formula:
+                   ENC=Y1OFFSET+Y1RESOL*acos((WID-(Y1WIDMAX+Y1WIDMIN))/(Y1WIDMAX-Y1WIDMIN))
+
+Parameter Name:    INS SLITi Y1WIDMAX
+Class:             config|header
+Context:           Instrument
+Type:              double
+Value Format:      %.3f
+Unit:              arcsec
+Comment Format:    Left max. slit width value [arcsec].
+Description:       The left max. slit length Y1LENMAX is used in the conversion formula:
+                   ENC=Y1OFFSET+Y1RESOL*acos((WID-(Y1WIDMAX+Y1WIDMIN))/(Y1WIDMAX-Y1WIDMIN))
+
+Parameter Name:    INS SLITi Y2WIDMIN
+Class:             config|header
+Context:           Instrument
+Type:              double
+Value Format:      %.3f
+Unit:              arcsec
+Comment Format:    Right min. slit width value [arcsec].
+Description:       The right min. slit length Y2LENMIN is used in the conversion formula:
+                   ENC=Y2OFFSET+Y2RESOL*acos((WID-(Y2WIDMAX+Y2WIDMIN))/(Y2WIDMAX-Y2WIDMIN))
+
+Parameter Name:    INS SLITi Y2WIDMAX
+Class:             config|header
+Context:           Instrument
+Type:              double
+Value Format:      %.3f
+Unit:              arcsec
+Comment Format:    Right max. slit width value [arcsec].
+Description:       The right max. slit length Y2LENMAX is used in the conversion formula:
+                   ENC=Y2OFFSET+Y2RESOL*acos((WID-(Y2WIDMAX+Y2WIDMIN))/(Y2WIDMAX-Y2WIDMIN))
+
+# 3.11.3.1 Slits wheel config. FITS keywords
+#
+
+# Each element position registers only the IDi of the mounted element.
+# A corresponding ID entry is searched to retrieve the rest of the
+# element data.
+#
+# A list of elements that can be mounted in this function is described
+# with entries IDi, NAMEi, etc. (one keyword set describes one element,
+# see section 3.6 of the INS Common Software Spec. manual,
+# VLT-SPE-ESO-17240-0385).
+
+Parameter Name:    INS SLITi SWSIM
+Class:             config|header|ops-log
+Context:           Instrument
+Type:              logical
+Value Format:      %c
+Unit:              
+Comment Format:    If T, function is software simulated.
+Description:       If T, function is software simulated.
+
+Parameter Name:    INS SLITi IDi
+Class:             conf-log|config
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    SLIT unit ID.
+Description:       Combines the name of the SLIT unit
+                   and hardware serial number.
+                   Format: NAME/SERIAL-NO
+
+Parameter Name:    INS SLITi NAMEi
+Class:             conf-log|config|header|setup
+Context:           Instrument
+Type:              string
+Value Format:      %15s
+Unit:              
+Comment Format:    Slit common name.
+Description:       Name of slit.
+
+# 3.11.1.2 Length slit setup and header FITS keywords
+#
+Parameter Name:    INS SLITi
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Slit device.
+Description:       Slit device.
+
+Parameter Name:    INS SLITi LEN
+Class:             header|setup
+Context:           Instrument
+Type:              double
+Value Format:      %.2f
+Unit:              arcsec
+Comment Format:    SLIT length [arcsec].
+Description:       Length of the slit.
+
+Parameter Name:    INS SLITi X1ENC
+Class:             setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              Enc
+Comment Format:    Slit horizontal left motor absolute position [Enc].
+Description:       Slit horizontal left motor absolute position [Enc].
+
+Parameter Name:    INS SLITi X1ENCREL
+Class:             setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              Enc
+Comment Format:    Slit horizontal left motor relative position [Enc].
+Description:       Slit horizontal left motor relative position [Enc].
+
+Parameter Name:    INS SLITi X1TURN
+Class:             setup
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Turn right/left.
+Description:       Turn the motor to the right or to the left.
+
+Parameter Name:    INS SLITi X1SPEED
+Class:             setup
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              
+Comment Format:    Moving speed.
+Description:       Speed (default units) the motor is moved (see TURN).
+
+Parameter Name:    INS SLITi X2ENC
+Class:             setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              Enc
+Comment Format:    Slit horizontal right motor absolute position [Enc].
+Description:       Slit horizontal right motor absolute position [Enc].
+
+Parameter Name:    INS SLITi X2ENCREL
+Class:             setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              Enc
+Comment Format:    Slit horizontal right motor relative position [Enc].
+Description:       Slit horizontal right motor relative position [Enc].
+
+Parameter Name:    INS SLITi X2TURN
+Class:             setup
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Turn right/left.
+Description:       Turn the motor to the right or to the left.
+
+Parameter Name:    INS SLITi X2SPEED
+Class:             setup
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              
+Comment Format:    Moving speed.
+Description:       Speed (default units) the motor is moved (see TURN).
+
+# 3.11.2.2 Width slit setup and header FITS keywords
+#
+Parameter Name:    INS SLITi WID
+Class:             header|setup
+Context:           Instrument
+Type:              double
+Value Format:      %.2f
+Unit:              arcsec
+Comment Format:    SLIT width [arcsec].
+Description:       Width of the slit.
+
+Parameter Name:    INS SLITi Y1ENC
+Class:             setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              Enc
+Comment Format:    Slit vertical top motor absolute position [Enc].
+Description:       Slit vertical top motor absolute position [Enc].
+
+Parameter Name:    INS SLITi Y1ENCREL
+Class:             setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              Enc
+Comment Format:    Slit vertical top motor relative position [Enc].
+Description:       Slit vertical top motor relative position [Enc].
+
+Parameter Name:    INS SLITi Y1TURN
+Class:             setup
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Turn right/left.
+Description:       Turn the motor to the right or to the left.
+
+Parameter Name:    INS SLITi Y1SPEED
+Class:             setup
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              
+Comment Format:    Moving speed.
+Description:       Speed (default units) the motor is moved (see TURN).
+
+Parameter Name:    INS SLITi Y2ENC
+Class:             setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              Enc
+Comment Format:    Slit vertical bottom motor absolute position [Enc].
+Description:       Slit vertical bottom motor absolute position [Enc].
+
+Parameter Name:    INS SLITi Y2ENCREL
+Class:             setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              Enc
+Comment Format:    Slit vertical bottom motor relative position [Enc].
+Description:       Slit vertical bottom motor relative position [Enc].
+
+Parameter Name:    INS SLITi Y2TURN
+Class:             setup
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Turn right/left.
+Description:       Turn the motor to the right or to the left.
+
+Parameter Name:    INS SLITi Y2SPEED
+Class:             setup
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              
+Comment Format:    Moving speed.
+Description:       Speed (default units) the motor is moved (see TURN).
+
+# 3.11.3.2 Slits wheel setup and header FITS keywords
+#
+Parameter Name:    INS SLITi NO
+Class:             header|setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              
+Comment Format:    Slide position.
+Description:       Index of the position of the slide.
+
+Parameter Name:    INS SLITi ENC
+Class:             header|setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              Enc
+Comment Format:    Slit absolute position [Enc].
+Description:       Slit absolute position [Enc].
+
+Parameter Name:    INS SLITi ENCREL
+Class:             setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              Enc
+Comment Format:    Slit relative position [Enc].
+Description:       Slit relative position [Enc].
+
+Parameter Name:    INS SLITi LIMIT
+Class:             setup
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Move to the limit.
+Description:       Move to the lower or upper limit.
+
+Parameter Name:    INS SLITi TURN
+Class:             setup
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Turn right/left.
+Description:       Turn the motor to the right or to the left.
+
+Parameter Name:    INS SLITi SPEED
+Class:             setup
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              
+Comment Format:    Moving speed.
+Description:       Speed (default units) the motor is moved (see LIMIT).
+
+# 3.11.[123].3 Common slit operational logs.
+#
+Parameter Name:    INS SLITi INIT
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Hardware initialisation.
+Description:       Hardware initialisation.
+
+Parameter Name:    INS SLITi MOVE
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Motion execution.
+Description:       Motion execution.
+
+Parameter Name:    INS SLITi STOP
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Motion stop.
+Description:       Motion stop.
+
+Parameter Name:    INS SLITi CHANGE
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Element changed.
+Description:       Element has been physically replaced.
+                   Maintenance operation.
+
+# 3.11.4 Slit ICS GUI widget.
+#
+
+
+#
+# 3.12 Tilt
+#
+#   Config. FITS keywords:
+#	DEVNAME, DEVDESC, LCUID, AVAIL, ENABLED, SWSIM,
+#	FRML, POSMIN, POSMAX, TOLERANC, OFFSET, RESOL.
+#   Setup and header FITS keywords:
+#	POS, TILT, TEMP.
+#   Maint. keywords (reserved):
+#	ENC, ENCREL, LIMIT, TURN, SPEED.
+#   Conf. log FITS keywords:
+#	INIT, MOVE, STOP.
+#
+
+# 3.12.1 Tilt config. FITS keywords
+#
+Parameter Name:    INS TILTi SWSIM
+Class:             config|header|ops-log
+Context:           Instrument
+Type:              logical
+Value Format:      %c
+Unit:              
+Comment Format:    If T, function is software simulated.
+Description:       If T, function is software simulated.
+
+Parameter Name:    INS TILTi FRML
+Class:             header
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Conversion Formula.
+Description:       ENC=OFFSET+RESOL*asin((2*POS-(POSMAX+POSMIN))\(POSMAX-POSMIN))
+                   .   +TEMPRAMP*(TEMP-TEMPREF)
+
+Parameter Name:    INS TILTi POSMIN
+Class:             config|header
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              pix
+Comment Format:    Minimum camera tilt [pix].
+Description:       Minimum camera tilt [pix].
+
+Parameter Name:    INS TILTi POSMAX
+Class:             config|header
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              pix
+Comment Format:    Maximum camera tilt [pix].
+Description:       Maximum camera tilt [pix].
+
+Parameter Name:    INS TILTi OFFSET
+Class:             config|header
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              Enc
+Comment Format:    Tilt reference position [Enc].
+Description:       The tilt reference position OFFSET is used in the conversion
+                   formula:
+                   ENC=OFFSET+RESOL*asin((2*POS-(POSMAX+POSMIN))\(POSMAX-POSMIN))
+                   .   +TEMPRAMP*(TEMP-TEMPREF)
+
+Parameter Name:    INS TILTi RESOL
+Class:             config|header
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              Enc/deg
+Comment Format:    Encoder resolution [Enc/deg].
+Description:       The encoder resolution RESOL is used in the conversion
+                   formula:
+                   ENC=OFFSET+RESOL*asin((2*POS-(POSMAX+POSMIN))\(POSMAX-POSMIN))
+                   .   +TEMPRAMP*(TEMP-TEMPREF)
+
+# 3.12.2 Tilt setup and header FITS keywords
+#
+Parameter Name:    INS TILTi
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Tilt device.
+Description:       Tilt device.
+
+Parameter Name:    INS TILTi POS
+Class:             header|setup
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              pix
+Comment Format:    Science camera tilt [pix].
+Description:       Science camera tilt [pix].
+
+Parameter Name:    INS TILTi TEMP
+Class:             setup
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              deg
+Comment Format:    Temperature used to adjust the position [deg].
+Description:       Temperature used to adjust the position [deg].
+
+Parameter Name:    INS TILTi ENC
+Class:             header|setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              Enc
+Comment Format:    Camera tilt absolute position [Enc].
+Description:       Camera tilt absolute position [Enc].
+
+Parameter Name:    INS TILTi ENCREL
+Class:             setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              Enc
+Comment Format:    Camera tilt relative position [Enc].
+Description:       Camera tilt relative position [Enc].
+
+Parameter Name:    INS TILTi LIMIT
+Class:             setup
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Move to the limit.
+Description:       Move to the lower or upper limit.
+
+Parameter Name:    INS TILTi TURN
+Class:             setup
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Turn right/left.
+Description:       Turn the wheel to the right or to the left.
+
+Parameter Name:    INS TILTi SPEED
+Class:             setup
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              
+Comment Format:    Moving speed.
+Description:       Speed (default units) the motor is moved (see TURN).
+
+# 3.12.3 Tilt operational logs.
+#
+Parameter Name:    INS TILTi INIT
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Hardware initialisation.
+Description:       Hardware initialisation.
+
+Parameter Name:    INS TILTi MOVE
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Motion execution.
+Description:       Motion execution.
+
+Parameter Name:    INS TILTi STOP
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Motion stop.
+Description:       Motion stop.
+
+# 3.12.4 Tilt ICS GUI widget.
+#
+
+
+#
+# 3.13 Sensors
+#
+# Each sensor device INS.SENSORi manages a set of related sensors values
+# INS.SENSi.  The index SENSi of each sensor value must be unique within
+# the instrument (to be able to report each sensor value with a different
+# FITS keyword).
+#
+# There is no relation between sensor device indexes (SENSORi) and sensor
+# value indexes (SENSi), e.g. one sensor device INS.SENSOR3 can manage
+# e.g. the sensor values INS.SENS12 to INS.SENS16.
+#
+# The sensor values managed by one sensor device are usually connected
+# to a single harware port (PORT).  The hardware port of analog sensors
+# is normally a serial port, the hardware 'port' of a digital sensor
+# device is an ACRO board.
+#
+
+#
+# 3.13.1 Analog sensors
+#
+#   Config. FITS keywords:
+#	DEVNAME, DEVDESC, DEVTYPE, LCUID, AVAIL, ENABLED, SWSIM,
+#	PORT, NUM, NAMEi, DESCi, HEADERi, FITSi, LOGi,
+#	SENADDRi, SENTYPEi, SENREFi, SENRAMPi, SENUNITi.
+#   Setup and header FITS keywords:
+#	INS.SENSi.ST, INS.SENSi.STAT, INS.SENSi.VAL, INS.SENSi.REF.
+#   Maint. keywords (reserved):
+#	-
+#   Conf. log FITS keywords:
+#	INIT.
+#
+
+#
+# 3.13.2 Digital sensors (DEVTYPE=DIGITAL)
+#
+#   Config. FITS keywords:
+#	DEVNAME, DEVDESC, DEVTYPE, LCUID, AVAIL, ENABLED, SWSIM,
+#	ID, NAME, PORT, NUM, NAMEi, DESCi, HEADERi, FITSi, LOGi,
+#	SIGBITi, SIGWIDTHi, SIGLOWi, SIGVALi, SIGSIMi.
+#   Setup and header FITS keywords:
+#	INS.SENSi.ST, INS.SENSi.STAT, INS.SENSi.VAL.
+#   Maint. keywords (reserved):
+#	-
+#   Conf. log FITS keywords:
+#	INIT.
+#
+
+# 3.13.[12].1 Sensors common config. FITS keywords
+#
+Parameter Name:    INS SENSORi SWSIM
+Class:             config|header|ops-log
+Context:           Instrument
+Type:              logical
+Value Format:      %c
+Unit:              
+Comment Format:    If T, function is software simulated.
+Description:       If T, function is software simulated.
+
+Parameter Name:    INS SENSORi ID
+Class:             conf-log|config|ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Sensor device unique id.
+Description:       ESO identification number for the sensor device.
+
+Parameter Name:    INS SENSORi NAME
+Class:             conf-log|config|ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %30s
+Unit:              
+Comment Format:    Sensor device common name.
+Description:       Name for the sensor device.
+
+# 3.13.1.1 Analog sensors config. FITS keywords
+#
+
+# 3.13.2.1 Digital sensors config. FITS keywords
+#
+
+# 3.13.[12].2 Sensors setup and header FITS keywords
+#
+Parameter Name:    INS SENSORi
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Sensor device.
+Description:       Sensor device.
+
+Parameter Name:    INS SENSi ID
+Class:             header|ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    sensor ID.
+Description:       sensor ID.
+
+Parameter Name:    INS SENSi NAME
+Class:             header|ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %30s
+Unit:              
+Comment Format:    sensor common name.
+Description:       sensor common name.
+
+Parameter Name:    INS SENSi ST
+Class:             header|ops-log
+Context:           Instrument
+Type:              logical
+Value Format:      %c
+Unit:              
+Comment Format:    Sensor boolean value.
+Description:       Sensor boolean value.
+
+Parameter Name:    INS SENSi STAT
+Class:             header|ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Sensor string value.
+Description:       Sensor string value.
+
+Parameter Name:    INS SENSi VAL
+Class:             header|ops-log
+Context:           Instrument
+Type:              double
+Value Format:      %.9f
+Unit:              
+Comment Format:    Sensor numeric value.
+Description:       Sensor numeric value.
+
+Parameter Name:    INS SENSi REF
+Class:             header|ops-log
+Context:           Instrument
+Type:              double
+Value Format:      %f
+Unit:              
+Comment Format:    Sensor reference value.
+Description:       Sensor reference value.
+
+Parameter Name:    INS TEMPi ID
+Class:             header|ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Temperature sensor ID.
+Description:       Temperature sensor ID.
+
+Parameter Name:    INS TEMPi NAME
+Class:             header|ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %30s
+Unit:              
+Comment Format:    Temperature sensor name.
+Description:       Temperature sensor name.
+
+Parameter Name:    INS TEMPi VAL
+Class:             header|ops-log
+Context:           Instrument
+Type:              double
+Value Format:      %.4f
+Unit:              
+Comment Format:    Temperature sensor numeric value.
+Description:       Temperature sensor numeric value.
+
+Parameter Name:    INS TEMPi REF
+Class:             header|ops-log
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              
+Comment Format:    Temperature sensor reference value.
+Description:       Temperature sensor reference value.
+# Statistical values
+# They are all calculated over the last exposure (i.e. considering
+# samples collected between EXPSTRT and EXPEND)
+Parameter Name:    INS SENSi MIN
+Class:             header
+Context:           Instrument
+Type:              double
+Value Format:      %f
+Unit:              
+Comment Format:    Minimum value.
+Description:       Minimum value.
+
+Parameter Name:    INS SENSi MAX
+Class:             header
+Context:           Instrument
+Type:              double
+Value Format:      %f
+Unit:              
+Comment Format:    Maximum value.
+Description:       Maximum value.
+
+Parameter Name:    INS SENSi MEAN
+Class:             header|ops-log
+Context:           Instrument
+Type:              double
+Value Format:      %f
+Unit:              
+Comment Format:    Average value.
+Description:       Average value.
+
+Parameter Name:    INS SENSi RMS
+Class:             header|ops-log
+Context:           Instrument
+Type:              double
+Value Format:      %f
+Unit:              
+Comment Format:    RMS of samples over exposure.
+Description:       RMS of samples over exposure.
+
+Parameter Name:    INS SENSi TMMEAN
+Class:             header|ops-log
+Context:           Instrument
+Type:              double
+Value Format:      %f
+Unit:              
+Comment Format:    Time waighted average.
+Description:       Time waighted average.
+
+Parameter Name:    INS SENSi GRAD
+Class:             header|ops-log
+Context:           Instrument
+Type:              double
+Value Format:      %f
+Unit:              
+Comment Format:    Linear regression slope.
+Description:       Linear regression slope.
+
+Parameter Name:    INS SENSi DETCOEF
+Class:             header|ops-log
+Context:           Instrument
+Type:              double
+Value Format:      %f
+Unit:              
+Comment Format:    RMS of linear regression slope.
+Description:       RMS of linear regression slope.
+
+Parameter Name:    INS TEMPi MIN
+Class:             header
+Context:           Instrument
+Type:              double
+Value Format:      %f
+Unit:              
+Comment Format:    Minimum value.
+Description:       Minimum value.
+
+Parameter Name:    INS TEMPi MAX
+Class:             header
+Context:           Instrument
+Type:              double
+Value Format:      %f
+Unit:              
+Comment Format:    Maximum value.
+Description:       Maximum value.
+
+Parameter Name:    INS TEMPi MEAN
+Class:             header|ops-log
+Context:           Instrument
+Type:              double
+Value Format:      %f
+Unit:              
+Comment Format:    Average value.
+Description:       Average value.
+
+Parameter Name:    INS TEMPi RMS
+Class:             header|ops-log
+Context:           Instrument
+Type:              double
+Value Format:      %f
+Unit:              
+Comment Format:    RMS of samples over exposure.
+Description:       RMS of samples over exposure.
+
+Parameter Name:    INS TEMPi TMMEAN
+Class:             header|ops-log
+Context:           Instrument
+Type:              double
+Value Format:      %f
+Unit:              
+Comment Format:    Time waighted average.
+Description:       Time waighted average.
+
+Parameter Name:    INS TEMPi GRAD
+Class:             header|ops-log
+Context:           Instrument
+Type:              double
+Value Format:      %f
+Unit:              
+Comment Format:    Linear regression slope.
+Description:       Linear regression slope.
+
+Parameter Name:    INS TEMPi DETCOEF
+Class:             header|ops-log
+Context:           Instrument
+Type:              double
+Value Format:      %f
+Unit:              
+Comment Format:    RMS of linear regression slope.
+Description:       RMS of linear regression slope.
+
+# 3.13.[12].3 Sensors operational logs.
+#
+Parameter Name:    INS SENSORi INIT
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Hardware initialisation.
+Description:       Hardware initialisation.
+
+# 3.13.4 Sensors ICS GUI widget.
+#
+
+
+#
+# 3.13.3 Exposure meters
+#
+#   Config. FITS keywords:
+#	DEVNAME, DEVDESC, DEVTYPE, LCUID, AVAIL, ENABLED, SWSIM,
+#	NAME, PORT, UIT, OFFDRK, OFFSKY, SIMVALUE.
+#   Setup and header FITS keywords:
+#	CTMIN, CTMAX, CTTOT, CTMEAN, CTRMS, TMMEAN.
+#   Maint. keywords (reserved):
+#	-
+#   Conf. log FITS keywords:
+#	INIT, CTLAST.
+#
+
+# 3.13.3.1 Exposure meter config. FITS keywords
+#
+Parameter Name:    INS DETi SWSIM
+Class:             config|header|ops-log
+Context:           Instrument
+Type:              logical
+Value Format:      %c
+Unit:              
+Comment Format:    If T, function is software simulated.
+Description:       If T, function is software simulated.
+
+Parameter Name:    INS DETi NAME
+Class:             conf-log|config|header
+Context:           Instrument
+Type:              string
+Value Format:      %10s
+Unit:              
+Comment Format:    Detector name.
+Description:       Name of the detector.
+
+Parameter Name:    INS DETi UIT
+Class:             config|header|setup
+Context:           Instrument
+Type:              double
+Value Format:      %.3f
+Unit:              sec
+Comment Format:    User defined Integration time [sec].
+Description:       Default integration time: 1 sec.
+
+Parameter Name:    INS DETi OFFDRK
+Class:             config|header|setup
+Context:           Instrument
+Type:              double
+Value Format:      %.0f
+Unit:              
+Comment Format:    Average dark background counts.
+Description:       Average dark background counts.
+
+Parameter Name:    INS DETi OFFSKY
+Class:             config|header|setup
+Context:           Instrument
+Type:              double
+Value Format:      %.0f
+Unit:              
+Comment Format:    Average sky background counts.
+Description:       Average sky background counts.
+
+# 3.13.3.2 Exposure meter setup and header FITS keywords
+#
+Parameter Name:    INS DETi
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %5s
+Unit:              
+Comment Format:    Detector device.
+Description:       Detector device.
+
+Parameter Name:    INS DETi CTMIN
+Class:             header
+Context:           Instrument
+Type:              double
+Value Format:      %.0f
+Unit:              
+Comment Format:    Minimum count during exposure.
+Description:       Minimum count during exposure.
+
+Parameter Name:    INS DETi CTMAX
+Class:             header
+Context:           Instrument
+Type:              double
+Value Format:      %.0f
+Unit:              
+Comment Format:    Maximum count during exposure.
+Description:       Maximum count during exposure.
+
+Parameter Name:    INS DETi CTTOT
+Class:             header
+Context:           Instrument
+Type:              double
+Value Format:      %.0f
+Unit:              
+Comment Format:    Total counts during exposure.
+Description:       Total counts during exposure.
+
+Parameter Name:    INS DETi CTMEAN
+Class:             header
+Context:           Instrument
+Type:              double
+Value Format:      %.1f
+Unit:              
+Comment Format:    Average counts during exposure.
+Description:       Mean value of counts during exposure.
+
+Parameter Name:    INS DETi CTRMS
+Class:             header
+Context:           Instrument
+Type:              double
+Value Format:      %.2f
+Unit:              
+Comment Format:    RMS of counts during exposure.
+Description:       Root Mean Square value of counts during exposure.
+
+Parameter Name:    INS DETi TMMEAN
+Class:             header
+Context:           Instrument
+Type:              double
+Value Format:      %.2f
+Unit:              
+Comment Format:    Normalised mean exposure time.
+Description:       Normalised mean exposure time.
+                   Formula: sum(i * count(i))/(ncounts * sum(count(i))
+                   Result in the range (0,1).
+
+# 3.13.3.3 Exposure meter operational logs.
+#
+Parameter Name:    INS DETi INIT
+Class:             ops-log
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    Hardware initialisation.
+Description:       Hardware initialisation.
+
+Parameter Name:    INS DETi CTLAST
+Class:             ops-log
+Context:           Instrument
+Type:              double
+Value Format:      %.0f
+Unit:              
+Comment Format:    Last counts read.
+Description:       Last counts read.
+
+# 3.13.3.4 Exposure meter ICS GUI widget.
+#
+
+
+#
+# 3.14 Special devices
+#
+# A special device is an instrument specific device not directly supported by Base ICS.
+# The FITS keywords associated to a special device must be stored in the instrument
+# dictionary.
+#
+# When the special device is registered in the instrument configuration file, then
+# a new INS.CON.DEVICEi parameter is added to the instrument configuration. This
+# INS.CON.DEVICEi parameter contains the device FITS prefix (e.g. "INS.TBDROT1").
+# The device specific dictionary should contain keywords starting with this prefix
+# (e.g. type = "INS.TBDROT1").
+#
+# Special devices should normally not use a type name already known to Base ICS.
+# If an instrument needs to specify e.g. a special type of derotator, then it should
+# use another type name for the config. parameters (e.g. "INS.TBDROTi") and add an
+# entry 'INS.TBDROT1.PREFIX "INS.DROT1"' to specify the prefix used for setup, header
+# and log FITS keywords.
+#
+# The Base ICS utilities expect to find the following keywords associated to the
+# special device (specified in the device type dictionary and stored in the instrument
+# configuration by the configuration UIF associated to the device):
+#
+# INS.<type>.DEVNAME	%19s	Name of the ICS device (C).
+# INS.<type>.DEVDESC	%19s    Description of the ICS device (c).
+# INS.<type>.DEVTYPE	%30s	ICS device type (C).
+# INS.<type>.PREFIX	%15s	Device FITS prefix (c).
+#				FITS prefix "INS.<name>" associated to the device.
+#				All FITS keywords starting with this prefix are sent to the
+#				device process.
+# INS.<type>.LCUID	%d	Id. of the LCU managing the device (c).
+#				LCU, where the device process is running.
+# INS.<type>.AVAIL	%c	Device availability flag (c).
+# INS.<type>.SWSIM	%c	If T, function is software simulated (c).
+#
+# Template Instrument special device (i.e. for ESO-VLT-DIC.SPIF_ICS only)
+Parameter Name:    INS MIRRi DATAi
+Class:             conf-log|header|setup
+Context:           Instrument
+Type:              double
+Value Format:      %f
+Unit:              
+Comment Format:    Data item.
+Description:       This is just an example of floating
+                   point value which can be set with a
+                   SETUP command and retrieved with
+                   STATUS for a special device.
+
+Parameter Name:    INS SENSORi MODE
+Class:             conf-log|header|setup
+Context:           Instrument
+Type:              string
+Value Format:      %s
+Unit:              
+Comment Format:    mode of operation
+Description:       operating mode monitoring or control
+
+Parameter Name:    INS LAMPi VOLTAGE
+Class:             conf-log|header|setup
+Context:           Instrument
+Type:              double
+Value Format:      %.2f
+Unit:              
+Comment Format:    voltage to be used when the lamp goes on(c).
+Description:       voltage [volts]
+
+Parameter Name:    INS SENSORi SENREFi
+Class:             conf-log|header|setup
+Context:           Instrument
+Type:              double
+Value Format:      %.2f
+Unit:              
+Comment Format:    sensor reference temperature
+Description:       temperature [K]
+
+Parameter Name:    INS MIRRi OFFSET
+Class:             setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              Enc
+Comment Format:    Mirror slide relative position [Enc].
+Description:       Mirror slide relative position [Enc].
+
+Parameter Name:    INS FILTi OFFSET
+Class:             setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              Enc
+Comment Format:    Filter wheel relative position [Enc].
+Description:       Filter wheel relative position [Enc].
+
+Parameter Name:    INS OPTIi OFFSET
+Class:             setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              Enc
+Comment Format:    Component relative position [Enc].
+Description:       Component relative position [Enc].
+
+Parameter Name:    INS GRATi OFFSET
+Class:             setup
+Context:           Instrument
+Type:              integer
+Value Format:      %d
+Unit:              Enc
+Comment Format:    Grating relative position [Enc].
+Description:       Grating relative position [Enc].
+#___oOo___
+
diff --git a/calib/gasgano/config/SINFO.prefs b/calib/gasgano/config/SINFO.prefs
new file mode 100644
index 0000000..c70e8ed
--- /dev/null
+++ b/calib/gasgano/config/SINFO.prefs
@@ -0,0 +1,53 @@
+# Gasgano Application Properties 
+# Date: Wed Oct 05 15:27:15 MEST 2005
+AUTO_DISPLAY=false
+CLASSRULE_FILE=/cal/sinfo/rul/sinfo.oca
+COMPONENT_FONT=Dialog:14
+CUBE_TO_VIEWER=
+CUBE_VIEWER_TYPE=SHELLCOMMAND
+DATA_FILES=
+DBOBS_DISPLAY_COLUMNS=CLASSIFICATION:RA:DEC:TPL.EXPNO:TPL.NEXP
+DBOBS_DISPLAY_COLUMNS_SIZE=0:0:0:0:0
+DBOBS_INSTRUMENT=All
+DBOBS_INSTRUMENTS=ISAAC;FORS1;FORS2;UVES;VIMOS;CONICA;EFOSC;CES;SUSI;SOFI;EMMI;WFI;VINCI;MIDI
+DBOBS_PERIOD=66
+DBOBS_REQUIRED=false
+DBOBS_SERVER_ID=
+DBOBS_SERVER_URL=jdbc:sybase:Tds:
+DBOBS_USERID=
+DB_SERVER_URL=jdbc:sybase:Tds:
+DB_USER_NAME=qc
+DISPLAY_COLUMNS=CLASSIFICATION:INS.SETUP.ID:INS.OPTI1.NAME:TPL.EXPNO:TPL.NEXP:OBS.TARG.NAME:DPR.TYPE
+DISPLAY_COLUMNS_SIZE=0:0:0:0:0:0:0
+FILTER_FILE=gasgano/filter.rul
+FITS_TO_VIEWER=rtd
+FITS_VIEWER_TYPE=SKYCAT
+FRAME_BOUNDS=0,0,1234,650
+INSTRUMENT_GROUPING=ISAAC=;FORS1=;FORS2=;UVES=;VIMOS=;CONICA=;EFOSC=;CES=;SUSI=;SOFI=;EMMI=;WFI=;VINCI=;MIDI=;
+KEYWORDLIST_DIR=gasgano/keywords
+MENU_CUSTOM1=
+MENU_CUSTOM1_LBL=Custom  Menu1
+MENU_CUSTOM2=
+MENU_CUSTOM2_LBL=Custom  Menu2
+MENU_CUSTOM3=
+MENU_CUSTOM3_LBL=Custom  Menu3
+MENU_CUSTOM4=
+MENU_CUSTOM4_LBL=Custom  Menu4
+MENU_RETRIEVE=dpclient  -renameschema ARCFILE -outpath 
+MJD_SORTING=false
+OBSTATUS_MAPPING=P:Partially defined D:Defined Q:queued for scheduling I:Initiated S:Started p:Paused during execution A:Aborted X:Executed R:Reduced C:Completed L:released K:Cancelled 
+OB_STATUS_FROM_DB_REQUIRED=false
+PRINTER_NAME=lp
+PRINT_FONT=Monospaced:16
+PRINT_ORIENTATION=P
+RADEC_CONVERSION=true
+RECIPE_SET=sinfo_rec_detlin=/home/quality/pipelines/sinfo/lib/esopipes-plugins/sinfo-2.3.2/sinfo_rec_detlin.so;sinfo_rec_distortion=/home/quality/pipelines/sinfo/lib/esopipes-plugins/sinfo-2.3.2/sinfo_rec_distortion.so;sinfo_rec_jitter=/home/quality/pipelines/sinfo/lib/esopipes-plugins/sinfo-2.3.2/sinfo_rec_jitter.so;sinfo_rec_mdark=/home/quality/pipelines/sinfo/lib/esopipes-plugins/sinfo-2.3.2/sinfo_rec_mdark.so;sinfo_rec_mflat=/home/quality/pipelines/sinfo/lib/esopipes-plugins/sinfo-2. [...]
+SCRIPTS_DIR=/home/astro4/gasgano/scripts/gas-scripts
+SHORTEN_FILES_PATH=false
+SHORT_FILENAME=true
+SHOW_EXTENSIONS=true
+TEXTFILE_EXTENSIONS=ascii;paf;longlog
+TFITS_TO_VIEWER=rtd
+TFITS_VIEWER_TYPE=SHELLCOMMAND
+UPDATE_TIMER=0
+VERBOSE_LEVEL=0
diff --git a/calib/gasgano/config/SINFO.rul b/calib/gasgano/config/SINFO.rul
new file mode 100644
index 0000000..b043443
Binary files /dev/null and b/calib/gasgano/config/SINFO.rul differ
diff --git a/calib/gasgano/config/sinfo.oca b/calib/gasgano/config/sinfo.oca
new file mode 100644
index 0000000..e503df7
--- /dev/null
+++ b/calib/gasgano/config/sinfo.oca
@@ -0,0 +1,731 @@
+if DPR.CATG like "%TEST%" and DPR.TYPE like "%DARK%" and DPR.TECH like "%IFU%" then
+{
+  DO.CATG = "DARK_tec_Focus";
+}
+if DPR.CATG like "%TEST%" and DPR.TYPE like "%DARK%" and DPR.TECH like "%IMAGE%" then
+{
+  DO.CATG = "DARK_cal_Darks";
+}
+if DPR.CATG like "%TECHNICAL%" and DPR.TYPE like "%DARK,PSF-CALIBRATOR%" and DPR.TECH like "%IFU%" then
+{
+  DO.CATG = "DARK_PSF";
+}
+if DPR.CATG like "%TECHNICAL%" and DPR.TYPE like "%VOLTAGES,FLAT%" and DPR.TECH like "%MEASURED,LAMP,ZONAL%" then
+{
+  DO.CATG = "FLAT_VOLTAGES_gen_tec_FlatDM";
+}
+if DPR.CATG like "%CALIB%" and DPR.TYPE like "%MATRIX,INTERACTION,PRIM%" and DPR.TECH like "%MEASURED,LAMP,ZONAL%" then
+{
+  DO.CATG = "MATRIX_INTERACTION_PRIM";
+}
+if DPR.CATG like "%TEST%" and DPR.TYPE like "%FIBRE%" and DPR.TECH like "%IFU%" then
+{
+  DO.CATG = "FIBRE_tec_ClGravityPM";
+}
+if DPR.CATG like "%CALIB%" and DPR.TYPE like "%FIBRE%" and DPR.TECH like "%IFU%" then
+{
+  DO.CATG = "FIBRE_gen_tec_QuickHealthCheck";
+}
+if DPR.CATG like "%TECHNICAL%" and DPR.TYPE like "%FIBRE,PSF-CALIBRATOR%" and DPR.TECH like "%IFU%" then
+{
+  DO.CATG = "FIBRE_PSF";
+}
+if DPR.CATG like "%CALIB%" and DPR.TYPE like "%DISTORTION,FIBRE,NS%" and DPR.TECH like "%IFU%" then
+{
+  DO.CATG = "FIBRE_NS";
+}
+if DPR.CATG like "%TECHNICAL%" and DPR.TYPE like "%FIBRE,NS%" and DPR.TECH like "%IFU%" then
+{
+  DO.CATG = "FIBRE_tec_NorthSouth";
+}
+if DPR.CATG like "%TECHNICAL%" and DPR.TYPE like "%FIBRE,EW%" and DPR.TECH like "%IFU%" then
+{
+  DO.CATG = "FIBRE_EW";
+}
+if DPR.CATG like "%CALIB%" and DPR.TYPE like "%DISTORTION,WAVE,NS%" and DPR.TECH like "%IFU%" then
+{
+  DO.CATG = "WAVE_NS";
+}
+if DPR.CATG like "%CALIB%" and DPR.TYPE like "%DISTORTION,FLAT,NS%" and DPR.TECH like "%IFU%" then
+{
+  DO.CATG = "FLAT_NS";
+}
+if DPR.CATG like "%TECHNICAL%" and DPR.TYPE like "%DISTORTION,FLAT,NS%" and DPR.TECH like "%IFU%" then
+{
+  DO.CATG = "FLAT_NS_ifs_tec_NorthSouth";
+}
+if DPR.CATG like "%TECHNICAL%" and DPR.TYPE like "%DISTORTION,WAVE,NS%" and DPR.TECH like "%IFU%" then
+{
+  DO.CATG = "WAVE_NS_ifs_tec_NorthSouth";
+}
+if DPR.CATG like "%TEST%" and DPR.TYPE like "%WAVE,LAMP%" and DPR.TECH like "%IFU%" then
+{
+  DO.CATG = "WAVE_cal_Arcs";
+}
+if DPR.CATG like "%TEST%" and DPR.TYPE like "%LAMP,WAVE%" and DPR.TECH like "%IFU%" then
+{
+  DO.CATG = "WAVE_tec_Focus";
+}
+if DPR.CATG like "%CALIB%" and DPR.TYPE like "%LINEARITY%" and DPR.TYPE like "%LAMP%" and DPR.TECH like "%IFU%" then
+{
+  DO.CATG = "LINEARITY_LAMP";
+}
+if DPR.CATG like "%CALIB%" and 
+   DPR.TYPE like "%LINEARITY,LAMP,DETCHAR%" and 
+   DPR.TECH like "%IFU%" and
+   INS1.LAMP5.ST == T then
+{
+  DO.CATG = "LINEARITY_LAMP";
+}
+if DPR.CATG like "%CALIB%" and 
+   DPR.TYPE like "%LINEARITY,LAMP,DETCHAR%" and 
+   DPR.TECH like "%IFU%" and
+   INS1.LAMP5.ST == F then
+{
+  DO.CATG = "LINEARITY_LAMP";
+}
+
+if DPR.CATG like "%CALIB%" and DPR.TYPE like "%DARK%" and ( DPR.TECH like "%IFU%" or DPR.TECH like "%IMAGE%" ) then
+{
+  DO.CATG = "DARK";
+}
+if DPR.CATG like "%TEST%" and DPR.TYPE like "%FLAT,LAMP%" and DPR.TECH like "%IFU%" then
+{
+  DO.CATG = "FLAT_cal_LampFlats";
+}
+if DPR.CATG like "%CALIB%" and DPR.TYPE like "%FLAT%" and DPR.TYPE like "%LAMP%" and DPR.TECH like "%IFU%" then
+{
+  DO.CATG = "FLAT_LAMP";
+}
+if DPR.CATG like "%CALIB%" and DPR.TYPE like "%FLAT%" and DPR.TYPE like "%LAMP%" and DPR.TECH like "%IFU,DITHER%" then
+{
+  DO.CATG = "FLAT_LAMP_DITHER";
+}
+if DPR.CATG like "%CALIB%" and DPR.TYPE like "%WAVE%" and DPR.TYPE like "%LAMP%" and DPR.TECH like "%IFU%" then
+{
+  DO.CATG = "WAVE_LAMP";
+}
+if DPR.CATG like "%CALIB%" and DPR.TYPE like "%WAVE%" and DPR.TYPE like "%LAMP%" and DPR.TECH like "%IFU,DITHER%" then
+{
+  DO.CATG = "WAVE_LAMP_DITHER";
+}
+if DPR.CATG like "%CALIB%" and DPR.TYPE like "%PUPIL,LAMP%" and DPR.TECH like "%IFU%" then
+{
+  DO.CATG = "PUPIL_LAMP";
+}
+if DPR.CATG like "%CALIB%" and DPR.TYPE like "%PSF-CALIBRATOR%" and DPR.TECH like "%IFU%" then
+{
+  DO.CATG = "PSF_CALIBRATOR";
+}
+if DPR.CATG like "%CALIB%" and DPR.TYPE like "%PSF-CALIBRATOR%" and DPR.TECH like "%IFU%" and DPR.TECH like "%DITHER%" then
+{
+  DO.CATG = "PSF_CALIBRATOR_DITHER";
+}
+if DPR.CATG like "%CALIB%" and DPR.TYPE like "%SKY,PSF-CALIBRATOR%" and DPR.TECH like "%IFU%" then
+{
+  DO.CATG = "SKY_PSF_CALIBRATOR";
+}
+if DPR.CATG like "%CALIB%" and DPR.TYPE like "%SKY,PSF-CALIBRATOR%" and DPR.TECH like "%IFU%" and DPR.TECH like "%DITHER%" then
+{
+  DO.CATG = "SKY_PSF_CALIBRATOR_DITHER";
+}
+if DPR.CATG like "%CALIB%" and DPR.TYPE like "%STD%" and DPR.TECH like "%IFU%" then
+{
+  DO.CATG = "STD";
+}
+if DPR.CATG like "%CALIB%" and DPR.TYPE like "%SKY,STD%" and DPR.TECH like "%IFU%" then
+{
+  DO.CATG = "SKY_STD";
+}
+if DPR.CATG like "%CALIB%" and DPR.TYPE like "%SKY,SKY,STD%" and DPR.TECH like "%IFU%" then
+{
+  DO.CATG = "SKY_SKY_STD";
+}
+if DPR.TECH like "%IMAGE,PRE%" and DPR.TYPE like "%OBJECT%" and DPR.CATG like "%SCIENCE%" then
+{
+  DO.CATG = "IMAGE_PRE_OBJECT";
+}
+if DPR.TECH like "%IMAGE,PRE%" and DPR.TYPE like "%SKY%" and DPR.CATG like "%SCIENCE%" then
+{
+  DO.CATG = "IMAGE_PRE_SKY";
+}
+if DPR.TECH like "%IFU,NODDING%" and DPR.TYPE like "%OBJECT%" and DPR.CATG like "%TEST%" then
+{
+  DO.CATG = "OBJECT_ifs_tec_GenericOffset";
+}
+if DPR.TECH like "%IFU,JITTER%" and DPR.TYPE like "%OBJECT%" and DPR.CATG like "%SCIENCE%" then
+{
+  DO.CATG = "OBJECT_JITTER";
+}
+if DPR.TECH like "%IFU,NODDING%" and DPR.TYPE like "%OBJECT%" and DPR.CATG like "%SCIENCE%" then
+{
+  DO.CATG = "OBJECT_NODDING";
+}
+if DPR.TECH like "%IFU,NODDING%" and DPR.TECH like "%DITHER%" and DPR.TYPE like "%OBJECT%" and DPR.CATG like "%SCIENCE%" then
+{
+  DO.CATG = "OBJECT_NODDING_DITHER";
+}
+if DPR.TECH like "%IFU,NODDING%" and DPR.TYPE like "%SKY%" and DPR.CATG like "%SCIENCE%" then
+{
+  DO.CATG = "SKY_NODDING";
+}
+if DPR.TECH like "%IFU,NODDING%" and DPR.TYPE like "%SKY%" and DPR.CATG like "%TEST%" then
+{
+  DO.CATG = "SKY_tec_GenericOffset";
+}
+if DPR.TECH like "%IFU,JITTER%" and DPR.TYPE like "%SKY%" and DPR.CATG like "%SCIENCE%" then
+{
+  DO.CATG = "SKY_JITTER";
+}
+if DPR.TECH like "%IFU,NODDING%" and DPR.TECH like "%DITHER%" and DPR.TYPE like "%SKY%" and DPR.CATG like "%SCIENCE%" then
+{
+  DO.CATG = "SKY_NODDING_DITHER";
+}
+
+
+
+if PRO.CATG like "%SEDS%" then
+{
+  DO.CATG = "SEDS";
+}
+if PRO.CATG like "%STDSTARS_CATS%" then
+{
+  DO.CATG = "STDSTARS_CATS";
+}
+
+
+if PRO.CATG like "%EXTCOEFF_TABLE%" then
+{
+  DO.CATG = "EXTCOEFF_TABLE";
+}
+if PRO.CATG like "%FLUX_STD_CATALOG%" then
+{
+  DO.CATG = "FLUX_STD_CATALOG";
+}
+
+
+if PRO.CATG like "%BP_MAP%" then
+{
+  DO.CATG = "BP_MAP";
+}
+if PRO.CATG like "%REF_BP_MAP%" then
+{
+  DO.CATG = "REF_BP_MAP";
+}
+if PRO.CATG like "%BP_MAP_HP%" then
+{
+  DO.CATG = "BP_MAP_HP";
+}
+if PRO.CATG like "%BP_MAP_NL%" then
+{
+  DO.CATG = "BP_MAP_NL";
+}
+if PRO.CATG like "%BP_MAP_NO%" then
+{
+  DO.CATG = "BP_MAP_NO";
+}
+if PRO.CATG like "%BP_MAP_DI%" then
+{
+  DO.CATG = "BP_MAP_DI";
+}
+if PRO.CATG like "%MASTER_BP_MAP%" then
+{
+  DO.CATG = "MASTER_BP_MAP";
+}
+if PRO.CATG like "%MASTER_DARK%" then
+{
+  DO.CATG = "MASTER_DARK";
+}
+if PRO.CATG like "%DISTORTION%" then
+{
+  DO.CATG = "DISTORTION";
+}
+if PRO.CATG like "%AO_PERFORMANCE%" then
+{
+  DO.CATG = "AO_PERFORMANCE";
+}
+if PRO.CATG like "%SLITLETS_DISTANCE%" then
+{
+  DO.CATG = "SLITLETS_DISTANCE";
+}
+if PRO.CATG like "%SLITLETS_POS_PREDIST%" then
+{
+  DO.CATG = "SLITLETS_POS_PREDIST";
+}
+if PRO.CATG like "%REF_LINE_ARC%" then
+{
+  DO.CATG = "REF_LINE_ARC";
+}
+if PRO.CATG like "%REF_LINE_SKY%" then
+{
+  DO.CATG = "REF_LINE_SKY";
+}
+if PRO.CATG like "%WAVE_MAP%" then
+{
+  DO.CATG = "WAVE_MAP";
+}
+if PRO.CATG like "%WAVE_MAP_DITHER%" then
+{
+  DO.CATG = "WAVE_MAP_DITHER";
+}
+if PRO.CATG like "%FIRST_COL%" then
+{
+  DO.CATG = "FIRST_COL";
+}
+if PRO.CATG like "%DRS_SETUP_WAVE%" then
+{
+  DO.CATG = "DRS_SETUP_WAVE";
+}
+if PRO.CATG like "%MASTER_FLAT_LAMP%" then
+{
+  DO.CATG = "MASTER_FLAT_LAMP";
+}
+if PRO.CATG like "%BP_COEFF%" then
+{
+  DO.CATG = "BP_COEFF";
+}
+if PRO.CATG like "%INT_COL_TILT%" then
+{
+  DO.CATG = "INT_COL_TILT";
+}
+if PRO.CATG like "%MASTER_FLAT_LAMP_DITHER%" then
+{
+  DO.CATG = "MASTER_FLAT_LAMP_DITHER";
+}
+if PRO.CATG like "%SLIT_POS%" then
+{
+  DO.CATG = "SLIT_POS";
+}
+if PRO.CATG like "%WAVE_COEF_SLIT%" then
+{
+  DO.CATG = "WAVE_COEF_SLIT";
+}
+if PRO.CATG like "%WAVE_FIT_PARAMS%" then
+{
+  DO.CATG = "WAVE_FIT_PARAMS";
+}
+if PRO.CATG like "%WAVE_PARAMS%" then
+{
+  DO.CATG = "WAVE_PARAMS";
+}
+if PRO.CATG like "%MASTER_FLUX_LAMP%" then
+{
+  DO.CATG = "MASTER_FLUX_LAMP";
+}
+if PRO.CATG like "%STD_STAR%" then
+{
+  DO.CATG = "STD_STAR";
+}
+if PRO.CATG like "%PSF_INFO%" then
+{
+  DO.CATG = "PSF_INFO";
+}
+if PRO.CATG like "%FIBRE_NS_STACKED%" then
+{
+  DO.CATG = "FIBRE_NS_STACKED";
+}
+if PRO.CATG like "%FIBRE_NS_STACKED_DIST%" then
+{
+  DO.CATG = "FIBRE_NS_STACKED_DIST";
+}
+if PRO.CATG like "%FIBRE_NS_STACKED_OFF%" then
+{
+  DO.CATG = "FIBRE_NS_STACKED_OFF";
+}
+if PRO.CATG like "%FIBRE_NS_STACKED_ON%" then
+{
+  DO.CATG = "FIBRE_NS_STACKED_ON";
+}
+if PRO.CATG like "%CUBE%" then
+{
+  DO.CATG = "CUBE";
+}
+if PRO.CATG like "%SCIENCE_CUBE%" then
+{
+  DO.CATG = "SCIENCE_CUBE";
+}
+if PRO.CATG like "%STD_CUBE_SKY%" then
+{
+  DO.CATG = "STD_CUBE_SKY";
+}
+if PRO.CATG like "%OBS_CUBE_SKY%" then
+{
+  DO.CATG = "OBS_CUBE_SKY";
+}
+if PRO.CATG like "%PSF_CUBE_SKY%" then
+{
+  DO.CATG = "PSF_CUBE_SKY";
+}
+if PRO.CATG like "%MASTER_PSF%" then
+{
+  DO.CATG = "MASTER_PSF";
+}
+if PRO.CATG like "%MASTER_SLIT%" then
+{
+  DO.CATG = "MASTER_SLIT";
+}
+if PRO.CATG like "%STD_MED_SKY%" then
+{
+  DO.CATG = "STD_MED_SKY";
+}
+if PRO.CATG like "%OBS_MED_SKY%" then
+{
+  DO.CATG = "OBS_MED_SKY";
+}
+if PRO.CATG like "%PSF_MED_SKY%" then
+{
+  DO.CATG = "PSF_MED_SKY";
+}
+if PRO.CATG like "%WAVE_LAMP_STACKED%" then
+{
+  DO.CATG = "WAVE_LAMP_STACKED";
+}
+if PRO.CATG like "%FLUX_LAMP_STACKED%" then
+{
+  DO.CATG = "FLUX_LAMP_STACKED";
+}
+if PRO.CATG like "%PSF_CALIBRATOR_STACKED%" then
+{
+  DO.CATG = "PSF_CALIBRATOR_STACKED";
+}
+if PRO.CATG like "%STD_STACKED%" then
+{
+  DO.CATG = "STD_STACKED";
+}
+if PRO.CATG like "%SKY_NODDING_STACKED%" then
+{
+  DO.CATG = "SKY_NODDING_STACKED";
+}
+if PRO.CATG like "%OBJ_NODDING_STACKED%" then
+{
+  DO.CATG = "OBJ_NODDING_STACKED";
+}
+if PRO.CATG like "%OBJECT_SKYSPIDER_STACKED%" then
+{
+  DO.CATG = "OBJECT_SKYSPIDER_STACKED";
+}
+if PRO.CATG like "%CUBE_COLL%" then
+{
+  DO.CATG = "CUBE_COLL";
+}
+if PRO.CATG like "%CUBE_COLL_SLOPEX%" then
+{
+  DO.CATG = "CUBE_COLL_SLOPEX";
+}
+if PRO.CATG like "%CUBE_COLL_SLOPEY%" then
+{
+  DO.CATG = "CUBE_COLL_SLOPEY";
+}
+if PRO.CATG like "%COADD_OBJ%" then
+{
+  DO.CATG = "COADD_OBJ";
+}
+if PRO.CATG like "%COADD_PUPIL%" then
+{
+  DO.CATG = "COADD_PUPIL";
+}
+if PRO.CATG like "%PUPIL_LAMP_STACKED%" then
+{
+  DO.CATG = "PUPIL_LAMP_STACKED";
+}
+if PRO.CATG like "%RESAMPLED_FLAT_LAMP%" then
+{
+  DO.CATG = "RESAMPLED_FLAT_LAMP";
+}
+if PRO.CATG like "%RESAMPLED_OBJ%" then
+{
+  DO.CATG = "RESAMPLED_OBJ";
+}
+if PRO.CATG like "%RESAMPLED_SKY%" then
+{
+  DO.CATG = "RESAMPLED_SKY";
+}
+if PRO.CATG like "%COADD_STD%" then
+{
+  DO.CATG = "COADD_STD";
+}
+if PRO.CATG like "%COADD_PSF%" then
+{
+  DO.CATG = "COADD_PSF";
+}
+if PRO.CATG like "%ENC_ENERGY%" then
+{
+  DO.CATG = "ENC_ENERGY";
+}
+if PRO.CATG like "%MASK_COADD_OBJ%" then
+{
+  DO.CATG = "MASK_COADD_OBJ";
+}
+if PRO.CATG like "%MASK_COADD_STD%" then
+{
+  DO.CATG = "MASK_COADD_STD";
+}
+if PRO.CATG like "%MASK_COADD_PSF%" then
+{
+  DO.CATG = "MASK_COADD_PSF";
+}
+if PRO.CATG like "%MED_COADD_OBJ%" then
+{
+  DO.CATG = "MED_COADD_OBJ";
+}
+if PRO.CATG like "%MED_COADD_STD%" then
+{
+  DO.CATG = "MED_COADD_STD";
+}
+if PRO.CATG like "%MED_COADD_PSF%" then
+{
+  DO.CATG = "MED_COADD_PSF";
+}
+if PRO.CATG like "%OBS_OBJ%" then
+{
+  DO.CATG = "OBS_OBJ";
+}
+if PRO.CATG like "%OBS_STD%" then
+{
+  DO.CATG = "OBS_STD";
+}
+if PRO.CATG like "%OBS_PSF%" then
+{
+  DO.CATG = "OBS_PSF";
+}
+if PRO.CATG like "%OBJECT_NODDING_STACKED%" then
+{
+  DO.CATG = "OBJECT_NODDING_STACKED";
+}
+if PRO.CATG like "%STD_NODDING_STACKED%" then
+{
+  DO.CATG = "STD_NODDING_STACKED";
+}
+if PRO.CATG like "%STD_STAR_SPECTRA%" then
+{
+  DO.CATG = "STD_STAR_SPECTRA";
+}
+if PRO.CATG like "%STD_STAR_SPECTRUM%" then
+{
+  DO.CATG = "STD_STAR_SPECTRUM";
+}
+if PRO.CATG like "%PSF_NODDING_STACKED%" then
+{
+  DO.CATG = "PSF_NODDING_STACKED";
+}
+if PRO.CATG like "%GAIN_INFO%" then
+{
+  DO.CATG = "GAIN_INFO";
+}
+if PRO.CATG like "%INT_COL_TILT_COR%" then
+{
+  DO.CATG = "INT_COL_TILT_COR";
+}
+if PRO.CATG like "%LIN_DET_INFO%" then
+{
+  DO.CATG = "LIN_DET_INFO";
+}
+if PRO.CATG like "%MFLAT_AVG%" then
+{
+  DO.CATG = "MFLAT_AVG";
+}
+if PRO.CATG like "%MFLAT_CUBE%" then
+{
+  DO.CATG = "MFLAT_CUBE";
+}
+if PRO.CATG like "%MFLAT_MED%" then
+{
+  DO.CATG = "MFLAT_MED";
+}
+if PRO.CATG like "%MFLAT_STACKED_DIST%" then
+{
+  DO.CATG = "MFLAT_STACKED_DIST";
+}
+if PRO.CATG like "%OBS_SKY%" then
+{
+  DO.CATG = "OBS_SKY";
+}
+if PRO.CATG like "%SKY_MED%" then
+{
+  DO.CATG = "SKY_MED";
+}
+if PRO.CATG like "%SKY_STACKED_DIST%" then
+{
+  DO.CATG = "SKY_STACKED_DIST";
+}
+if PRO.CATG like "%SKY_STACKED_DUMMY%" then
+{
+  DO.CATG = "SKY_STACKED_DUMMY";
+}
+
+select execute(sinfo_rec_jitter_stdstar) from inputFiles where SIG.TEMPLATE == 1 and LF.DO.CATG == "STD";
+select execute(sinfo_rec_mflat) from inputFiles where SIG.TEMPLATE == 1 and LF.DO.CATG == "FLAT_LAMP";
+select execute(sinfo_rec_distortion) from inputFiles where SIG.TEMPLATE == 1 and LF.DO.CATG == "FLAT_NS";
+select execute(sinfo_rec_jitter) from inputFiles where SIG.TEMPLATE == 1 and LF.DO.CATG == "DARK_PSF";
+select execute(sinfo_rec_detlin) from inputFiles where SIG.TEMPLATE == 1 and LF.DO.CATG == "LINEARITY_LAMP";
+select execute(sinfo_rec_lingain) from inputFiles where SIG.TEMPLATE == 1 and LF.DO.CATG == "LINEARITY_LAMP_ON";
+select execute(sinfo_rec_lingain) from inputFiles where SIG.TEMPLATE == 1 and LF.DO.CATG == "LINEARITY_LAMP_OFF";
+select execute(sinfo_rec_jitter) from inputFiles where SIG.TEMPLATE == 1 and LF.DO.CATG == "FIBRE_PSF";
+select execute(sinfo_rec_jitter) from inputFiles where SIG.TEMPLATE == 1 and LF.DO.CATG == "IMAGE_PRE_SKY";
+select execute(sinfo_rec_jitter) from inputFiles where SIG.TEMPLATE == 1 and LF.DO.CATG == "SKY_JITTER";
+select execute(sinfo_rec_jitter) from inputFiles where SIG.TEMPLATE == 1 and LF.DO.CATG == "IMAGE_PRE_OBJECT";
+select execute(sinfo_rec_mdark) from inputFiles where SIG.TEMPLATE == 1 and LF.DO.CATG == "DARK";
+select execute(sinfo_rec_distortion) from inputFiles where SIG.TEMPLATE == 1 and LF.DO.CATG == "WAVE_NS";
+select execute(sinfo_rec_jitter) from inputFiles where SIG.TEMPLATE == 1 and LF.DO.CATG == "SKY_NODDING";
+select execute(sinfo_rec_jitter) from inputFiles where SIG.TEMPLATE == 1 and LF.DO.CATG == "OBJECT_NODDING";
+select execute(sinfo_rec_jitter) from inputFiles where SIG.TEMPLATE == 1 and LF.DO.CATG == "OBJECT_JITTER";
+select execute(sinfo_rec_distortion) from inputFiles where SIG.TEMPLATE == 1 and LF.DO.CATG == "FIBRE_NS";
+select execute(sinfo_rec_jitter) from inputFiles where SIG.TEMPLATE == 1 and LF.DO.CATG == "SKY_PSF_CALIBRATOR";
+select execute(sinfo_rec_pupil) from inputFiles where SIG.TEMPLATE == 1 and LF.DO.CATG == "PUPIL_LAMP";
+select execute(sinfo_rec_wavecal) from inputFiles where SIG.TEMPLATE == 1 and LF.DO.CATG == "WAVE_LAMP";
+select execute(sinfo_rec_jitter) from inputFiles where SIG.TEMPLATE == 1 and LF.DO.CATG == "SKY_STD";
+select execute(sinfo_rec_jitter) from inputFiles where SIG.TEMPLATE == 1 and LF.DO.CATG == "PSF_CALIBRATOR";
+
+
+action sinfo_rec_distortion
+{
+minRet = 1; maxRet = 1;
+select file as REF_LINE_ARC from calibFiles where DO.CATG == "REF_LINE_ARC"
+   and inputFile.INSTRUME==INSTRUME and inputFile.INS.SETUP.ID==INS.SETUP.ID;
+minRet = 1; maxRet = 1;
+select file as DRS_SETUP_WAVE from calibFiles where DO.CATG == "DRS_SETUP_WAVE";
+recipe sinfo_rec_distortion;
+}
+
+action sinfo_rec_detlin
+{
+recipe sinfo_rec_detlin;
+}
+
+action sinfo_rec_lingain
+{
+recipe sinfo_rec_lingain;
+}
+
+action sinfo_rec_mdark
+{
+recipe sinfo_rec_mdark;
+}
+
+action sinfo_rec_mflat
+{
+minRet = 1; maxRet = 1;
+select file as REF_BP_MAP from calibFiles where DO.CATG == "REF_BP_MAP";
+minRet = 1; maxRet = 1;
+select file as BP_MAP_NL from calibFiles where DO.CATG == "BP_MAP_NL"
+   and inputFile.INSTRUME==INSTRUME and inputFile.INS.SETUP.ID==INS.SETUP.ID;
+recipe sinfo_rec_mflat;
+}
+
+action sinfo_rec_wavecal
+{
+minRet = 1; maxRet = 1;
+select file as REF_LINE_ARC from calibFiles where DO.CATG == "REF_LINE_ARC"
+   and inputFile.INSTRUME==INSTRUME and inputFile.INS.SETUP.ID==INS.SETUP.ID;
+minRet = 1; maxRet = 1;
+select file as DRS_SETUP_WAVE from calibFiles where DO.CATG == "DRS_SETUP_WAVE";
+minRet = 1; maxRet = 1;
+select file as MASTER_FLAT_LAMP from calibFiles where DO.CATG == "MASTER_FLAT_LAMP"
+   and inputFile.INSTRUME==INSTRUME and inputFile.INS.SETUP.ID==INS.SETUP.ID and inputFile.INS.OPTI1.NAME==INS.OPTI1.NAME;
+minRet = 1; maxRet = 1;
+select file as MASTER_BP_MAP from calibFiles where DO.CATG == "MASTER_BP_MAP"
+   and inputFile.INSTRUME==INSTRUME and inputFile.INS.SETUP.ID==INS.SETUP.ID and inputFile.INS.OPTI1.NAME==INS.OPTI1.NAME;
+minRet = 1; maxRet = 1;
+select file as SLIT_POS from calibFiles where DO.CATG == "SLIT_POS"
+   and inputFile.INSTRUME==INSTRUME and inputFile.INS.SETUP.ID==INS.SETUP.ID and inputFile.INS.OPTI1.NAME==INS.OPTI1.NAME;
+minRet = 1; maxRet = 1;
+select file as DISTORTION from calibFiles where DO.CATG == "DISTORTION"
+   and inputFile.INSTRUME==INSTRUME and inputFile.INS.SETUP.ID==INS.SETUP.ID;
+recipe sinfo_rec_wavecal;
+}
+
+action sinfo_rec_jitter
+{
+minRet = 1; maxRet = 1;
+select file as MASTER_BP_MAP from calibFiles where DO.CATG == "MASTER_BP_MAP"
+   and inputFile.INSTRUME==INSTRUME and inputFile.INS.SETUP.ID==INS.SETUP.ID and inputFile.INS.OPTI1.NAME==INS.OPTI1.NAME;
+
+minRet = 1; maxRet = 1;
+select file as MASTER_FLAT_LAMP from calibFiles where DO.CATG == "MASTER_FLAT_LAMP"
+   and inputFile.INSTRUME==INSTRUME and inputFile.INS.SETUP.ID==INS.SETUP.ID and inputFile.INS.OPTI1.NAME==INS.OPTI1.NAME;
+minRet = 0; maxRet = 1;
+select file as MASTER_DARK from calibFiles where DO.CATG == "MASTER_DARK"
+   and inputFile.DET.DIT==DET.DIT and inputFile.INSTRUME==INSTRUME;
+minRet = 1; maxRet = 1;
+select file as FIRST_COL from calibFiles where DO.CATG == "FIRST_COL";
+minRet = 1; maxRet = 1;
+select file as WAVE_MAP from calibFiles where DO.CATG == "WAVE_MAP"
+   and inputFile.INSTRUME==INSTRUME and inputFile.INS.SETUP.ID==INS.SETUP.ID and inputFile.INS.OPTI1.NAME==INS.OPTI1.NAME;
+minRet = 1; maxRet = 1;
+select file as SLITLETS_DISTANCE from calibFiles where DO.CATG == "SLITLETS_DISTANCE"
+   and inputFile.INSTRUME==INSTRUME and inputFile.INS.SETUP.ID==INS.SETUP.ID;
+minRet = 1; maxRet = 1;
+select file as SLIT_POS from calibFiles where DO.CATG == "SLIT_POS"
+   and inputFile.INSTRUME==INSTRUME and inputFile.INS.SETUP.ID==INS.SETUP.ID and inputFile.INS.OPTI1.NAME==INS.OPTI1.NAME;
+minRet = 1; maxRet = 1;
+select file as DISTORTION from calibFiles where DO.CATG == "DISTORTION"
+   and inputFile.INSTRUME==INSTRUME and inputFile.INS.SETUP.ID==INS.SETUP.ID;
+recipe sinfo_rec_jitter;
+}
+
+
+
+action sinfo_rec_jitter_stdstar
+{
+minRet = 0; maxRet = 1;
+select file as EXTCOEFF_TABLE from calibFiles where DO.CATG == "EXTCOEFF_TABLE"
+   and inputFile.INSTRUME==INSTRUME;
+minRet = 0; maxRet = 1;
+select file as FLUX_STD_CATALOG from calibFiles where DO.CATG == "FLUX_STD_CATALOG"
+   and inputFile.INSTRUME==INSTRUME;
+minRet = 1; maxRet = 1;
+select file as MASTER_BP_MAP from calibFiles where DO.CATG == "MASTER_BP_MAP"
+   and inputFile.INSTRUME==INSTRUME and inputFile.INS.SETUP.ID==INS.SETUP.ID and inputFile.INS.OPTI1.NAME==INS.OPTI1.NAME;
+
+minRet = 1; maxRet = 1;
+select file as MASTER_FLAT_LAMP from calibFiles where DO.CATG == "MASTER_FLAT_LAMP"
+   and inputFile.INSTRUME==INSTRUME and inputFile.INS.SETUP.ID==INS.SETUP.ID and inputFile.INS.OPTI1.NAME==INS.OPTI1.NAME;
+minRet = 0; maxRet = 1;
+select file as MASTER_DARK from calibFiles where DO.CATG == "MASTER_DARK"
+   and inputFile.DET.DIT==DET.DIT and inputFile.INSTRUME==INSTRUME;
+minRet = 1; maxRet = 1;
+select file as FIRST_COL from calibFiles where DO.CATG == "FIRST_COL";
+minRet = 1; maxRet = 1;
+select file as WAVE_MAP from calibFiles where DO.CATG == "WAVE_MAP"
+   and inputFile.INSTRUME==INSTRUME and inputFile.INS.SETUP.ID==INS.SETUP.ID and inputFile.INS.OPTI1.NAME==INS.OPTI1.NAME;
+minRet = 1; maxRet = 1;
+select file as SLITLETS_DISTANCE from calibFiles where DO.CATG == "SLITLETS_DISTANCE"
+   and inputFile.INSTRUME==INSTRUME and inputFile.INS.SETUP.ID==INS.SETUP.ID;
+minRet = 1; maxRet = 1;
+select file as SLIT_POS from calibFiles where DO.CATG == "SLIT_POS"
+   and inputFile.INSTRUME==INSTRUME and inputFile.INS.SETUP.ID==INS.SETUP.ID and inputFile.INS.OPTI1.NAME==INS.OPTI1.NAME;
+minRet = 1; maxRet = 1;
+select file as DISTORTION from calibFiles where DO.CATG == "DISTORTION"
+   and inputFile.INSTRUME==INSTRUME and inputFile.INS.SETUP.ID==INS.SETUP.ID;
+recipe sinfo_rec_jitter;
+}
+
+
+
+action sinfo_rec_pupil
+{
+minRet = 1; maxRet = 1;
+select file as MASTER_BP_MAP from calibFiles where DO.CATG == "MASTER_BP_MAP"
+   and inputFile.INSTRUME==INSTRUME and inputFile.INS.SETUP.ID==INS.SETUP.ID and inputFile.INS.OPTI1.NAME==INS.OPTI1.NAME;
+minRet = 1; maxRet = 1;
+select file as MASTER_FLAT_LAMP from calibFiles where DO.CATG == "MASTER_FLAT_LAMP"
+   and inputFile.INSTRUME==INSTRUME and inputFile.INS.SETUP.ID==INS.SETUP.ID and inputFile.INS.OPTI1.NAME==INS.OPTI1.NAME;
+minRet = 0; maxRet = 1;
+select file as MASTER_DARK from calibFiles where DO.CATG == "MASTER_DARK"
+   and inputFile.DET.DIT==DET.DIT and inputFile.INSTRUME==INSTRUME;
+minRet = 1; maxRet = 1;
+select file as FIRST_COL from calibFiles where DO.CATG == "FIRST_COL";
+minRet = 1; maxRet = 1;
+select file as WAVE_MAP from calibFiles where DO.CATG == "WAVE_MAP"
+   and inputFile.INSTRUME==INSTRUME and inputFile.INS.SETUP.ID==INS.SETUP.ID and inputFile.INS.OPTI1.NAME==INS.OPTI1.NAME;
+minRet = 1; maxRet = 1;
+select file as SLITLETS_DISTANCE from calibFiles where DO.CATG == "SLITLETS_DISTANCE"
+   and inputFile.INSTRUME==INSTRUME and inputFile.INS.SETUP.ID==INS.SETUP.ID;
+minRet = 1; maxRet = 1;
+select file as SLIT_POS from calibFiles where DO.CATG == "SLIT_POS"
+   and inputFile.INSTRUME==INSTRUME and inputFile.INS.SETUP.ID==INS.SETUP.ID and inputFile.INS.OPTI1.NAME==INS.OPTI1.NAME;
+minRet = 1; maxRet = 1;
+select file as DISTORTION from calibFiles where DO.CATG == "DISTORTION"
+   and inputFile.INSTRUME==INSTRUME and inputFile.INS.SETUP.ID==INS.SETUP.ID;
+recipe sinfo_rec_pupil;
+}
diff --git a/config.h.in b/config.h.in
new file mode 100644
index 0000000..1a30853
--- /dev/null
+++ b/config.h.in
@@ -0,0 +1,137 @@
+/* config.h.in.  Generated from configure.ac by autoheader.  */
+
+/* Define to 1 if you have the `cos' function. */
+#undef HAVE_COS
+
+/* Define to 1 if you have CPL version 3.1 or later */
+#undef HAVE_CPL31
+
+/* Define to 1 if you have the declaration of `pclose', and to 0 if you don't.
+   */
+#undef HAVE_DECL_PCLOSE
+
+/* Define to 1 if you have the declaration of `popen', and to 0 if you don't.
+   */
+#undef HAVE_DECL_POPEN
+
+/* Define to 1 if you have the declaration of `__func__', and to 0 if you
+   don't. */
+#undef HAVE_DECL___FUNC__
+
+/* Define to 1 if you have the <dlfcn.h> header file. */
+#undef HAVE_DLFCN_H
+
+/* Define to 1 if you have the `floor' function. */
+#undef HAVE_FLOOR
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+#undef HAVE_INTTYPES_H
+
+/* Define to 1 if you have the <memory.h> header file. */
+#undef HAVE_MEMORY_H
+
+/* Define to 1 if you have the `pow' function. */
+#undef HAVE_POW
+
+/* Define to 1 if you have the `sin' function. */
+#undef HAVE_SIN
+
+/* Define to 1 if you have the `sqrt' function. */
+#undef HAVE_SQRT
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#undef HAVE_STDINT_H
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#undef HAVE_STDLIB_H
+
+/* Define if you have the `strdup' function */
+#undef HAVE_STRDUP
+
+/* Define to 1 if you have the <strings.h> header file. */
+#undef HAVE_STRINGS_H
+
+/* Define to 1 if you have the <string.h> header file. */
+#undef HAVE_STRING_H
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#undef HAVE_SYS_STAT_H
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#undef HAVE_SYS_TYPES_H
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#undef HAVE_UNISTD_H
+
+/* Define to the sub-directory in which libtool stores uninstalled libraries.
+   */
+#undef LT_OBJDIR
+
+/* Define to 1 if your C compiler doesn't accept -c and -o together. */
+#undef NO_MINUS_C_MINUS_O
+
+/* Name of package */
+#undef PACKAGE
+
+/* Define to the address where bug reports for this package should be sent. */
+#undef PACKAGE_BUGREPORT
+
+/* Define to the full name of this package. */
+#undef PACKAGE_NAME
+
+/* Define to the full name and version of this package. */
+#undef PACKAGE_STRING
+
+/* Define to the one symbol short name of this package. */
+#undef PACKAGE_TARNAME
+
+/* Define to the version of this package. */
+#undef PACKAGE_VERSION
+
+/* SINFONI binary age */
+#undef SINFONI_BINARY_AGE
+
+/* SINFONI binary version number */
+#undef SINFONI_BINARY_VERSION
+
+/* SINFONI interface age */
+#undef SINFONI_INTERFACE_AGE
+
+/* SINFONI major version number */
+#undef SINFONI_MAJOR_VERSION
+
+/* SINFONI micro version number */
+#undef SINFONI_MICRO_VERSION
+
+/* SINFONI minor version number */
+#undef SINFONI_MINOR_VERSION
+
+/* Plugin directory tree prefix */
+#undef SINFONI_PLUGIN_DIR
+
+/* Absolute path to the plugin directory tree */
+#undef SINFONI_PLUGIN_PATH
+
+/* Define to 1 if you have the ANSI C header files. */
+#undef STDC_HEADERS
+
+/* Version number of package */
+#undef VERSION
+
+/* Define if using the dmalloc debugging malloc package */
+#undef WITH_DMALLOC
+
+/* Define to empty if `const' does not conform to ANSI C. */
+#undef const
+
+/* Define to `__inline__' or `__inline' if that's what the C compiler
+   calls it, or to nothing if 'inline' is not supported under any name.  */
+#ifndef __cplusplus
+#undef inline
+#endif
+
+
+#ifndef HAVE_STRDUP
+#  define strdup  cx_strdup
+#endif
+              
diff --git a/configure b/configure
new file mode 100755
index 0000000..e865180
--- /dev/null
+++ b/configure
@@ -0,0 +1,17365 @@
+#! /bin/sh
+# Guess values for system-dependent variables and create Makefiles.
+# Generated by GNU Autoconf 2.63 for SINFONI Instrument Pipeline 2.3.2.
+#
+# Report bugs to <amodigli at eso.org>.
+#
+# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
+# 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+# This configure script is free software; the Free Software Foundation
+# gives unlimited permission to copy, distribute and modify it.
+## --------------------- ##
+## M4sh Initialization.  ##
+## --------------------- ##
+
+# Be more Bourne compatible
+DUALCASE=1; export DUALCASE # for MKS sh
+if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
+  emulate sh
+  NULLCMD=:
+  # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
+  # is contrary to our usage.  Disable this feature.
+  alias -g '${1+"$@"}'='"$@"'
+  setopt NO_GLOB_SUBST
+else
+  case `(set -o) 2>/dev/null` in
+  *posix*) set -o posix ;;
+esac
+
+fi
+
+
+
+
+# PATH needs CR
+# Avoid depending upon Character Ranges.
+as_cr_letters='abcdefghijklmnopqrstuvwxyz'
+as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
+as_cr_Letters=$as_cr_letters$as_cr_LETTERS
+as_cr_digits='0123456789'
+as_cr_alnum=$as_cr_Letters$as_cr_digits
+
+as_nl='
+'
+export as_nl
+# Printing a long string crashes Solaris 7 /usr/bin/printf.
+as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'
+as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo
+as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo
+if (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then
+  as_echo='printf %s\n'
+  as_echo_n='printf %s'
+else
+  if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then
+    as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"'
+    as_echo_n='/usr/ucb/echo -n'
+  else
+    as_echo_body='eval expr "X$1" : "X\\(.*\\)"'
+    as_echo_n_body='eval
+      arg=$1;
+      case $arg in
+      *"$as_nl"*)
+	expr "X$arg" : "X\\(.*\\)$as_nl";
+	arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;;
+      esac;
+      expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl"
+    '
+    export as_echo_n_body
+    as_echo_n='sh -c $as_echo_n_body as_echo'
+  fi
+  export as_echo_body
+  as_echo='sh -c $as_echo_body as_echo'
+fi
+
+# The user is always right.
+if test "${PATH_SEPARATOR+set}" != set; then
+  PATH_SEPARATOR=:
+  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
+    (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
+      PATH_SEPARATOR=';'
+  }
+fi
+
+# Support unset when possible.
+if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then
+  as_unset=unset
+else
+  as_unset=false
+fi
+
+
+# IFS
+# We need space, tab and new line, in precisely that order.  Quoting is
+# there to prevent editors from complaining about space-tab.
+# (If _AS_PATH_WALK were called with IFS unset, it would disable word
+# splitting by setting IFS to empty value.)
+IFS=" ""	$as_nl"
+
+# Find who we are.  Look in the path if we contain no directory separator.
+case $0 in
+  *[\\/]* ) as_myself=$0 ;;
+  *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break
+done
+IFS=$as_save_IFS
+
+     ;;
+esac
+# We did not find ourselves, most probably we were run as `sh COMMAND'
+# in which case we are not to be found in the path.
+if test "x$as_myself" = x; then
+  as_myself=$0
+fi
+if test ! -f "$as_myself"; then
+  $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2
+  { (exit 1); exit 1; }
+fi
+
+# Work around bugs in pre-3.0 UWIN ksh.
+for as_var in ENV MAIL MAILPATH
+do ($as_unset $as_var) >/dev/null 2>&1 && $as_unset $as_var
+done
+PS1='$ '
+PS2='> '
+PS4='+ '
+
+# NLS nuisances.
+LC_ALL=C
+export LC_ALL
+LANGUAGE=C
+export LANGUAGE
+
+# Required to use basename.
+if expr a : '\(a\)' >/dev/null 2>&1 &&
+   test "X`expr 00001 : '.*\(...\)'`" = X001; then
+  as_expr=expr
+else
+  as_expr=false
+fi
+
+if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then
+  as_basename=basename
+else
+  as_basename=false
+fi
+
+
+# Name of the executable.
+as_me=`$as_basename -- "$0" ||
+$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \
+	 X"$0" : 'X\(//\)$' \| \
+	 X"$0" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X/"$0" |
+    sed '/^.*\/\([^/][^/]*\)\/*$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\/\(\/\/\)$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\/\(\/\).*/{
+	    s//\1/
+	    q
+	  }
+	  s/.*/./; q'`
+
+# CDPATH.
+$as_unset CDPATH
+
+
+if test "x$CONFIG_SHELL" = x; then
+  if (eval ":") 2>/dev/null; then
+  as_have_required=yes
+else
+  as_have_required=no
+fi
+
+  if test $as_have_required = yes &&	 (eval ":
+(as_func_return () {
+  (exit \$1)
+}
+as_func_success () {
+  as_func_return 0
+}
+as_func_failure () {
+  as_func_return 1
+}
+as_func_ret_success () {
+  return 0
+}
+as_func_ret_failure () {
+  return 1
+}
+
+exitcode=0
+if as_func_success; then
+  :
+else
+  exitcode=1
+  echo as_func_success failed.
+fi
+
+if as_func_failure; then
+  exitcode=1
+  echo as_func_failure succeeded.
+fi
+
+if as_func_ret_success; then
+  :
+else
+  exitcode=1
+  echo as_func_ret_success failed.
+fi
+
+if as_func_ret_failure; then
+  exitcode=1
+  echo as_func_ret_failure succeeded.
+fi
+
+if ( set x; as_func_ret_success y && test x = \"\$1\" ); then
+  :
+else
+  exitcode=1
+  echo positional parameters were not saved.
+fi
+
+test \$exitcode = 0) || { (exit 1); exit 1; }
+
+(
+  as_lineno_1=\$LINENO
+  as_lineno_2=\$LINENO
+  test \"x\$as_lineno_1\" != \"x\$as_lineno_2\" &&
+  test \"x\`expr \$as_lineno_1 + 1\`\" = \"x\$as_lineno_2\") || { (exit 1); exit 1; }
+") 2> /dev/null; then
+  :
+else
+  as_candidate_shells=
+    as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  case $as_dir in
+	 /*)
+	   for as_base in sh bash ksh sh5; do
+	     as_candidate_shells="$as_candidate_shells $as_dir/$as_base"
+	   done;;
+       esac
+done
+IFS=$as_save_IFS
+
+
+      for as_shell in $as_candidate_shells $SHELL; do
+	 # Try only shells that exist, to save several forks.
+	 if { test -f "$as_shell" || test -f "$as_shell.exe"; } &&
+		{ ("$as_shell") 2> /dev/null <<\_ASEOF
+if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
+  emulate sh
+  NULLCMD=:
+  # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
+  # is contrary to our usage.  Disable this feature.
+  alias -g '${1+"$@"}'='"$@"'
+  setopt NO_GLOB_SUBST
+else
+  case `(set -o) 2>/dev/null` in
+  *posix*) set -o posix ;;
+esac
+
+fi
+
+
+:
+_ASEOF
+}; then
+  CONFIG_SHELL=$as_shell
+	       as_have_required=yes
+	       if { "$as_shell" 2> /dev/null <<\_ASEOF
+if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
+  emulate sh
+  NULLCMD=:
+  # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
+  # is contrary to our usage.  Disable this feature.
+  alias -g '${1+"$@"}'='"$@"'
+  setopt NO_GLOB_SUBST
+else
+  case `(set -o) 2>/dev/null` in
+  *posix*) set -o posix ;;
+esac
+
+fi
+
+
+:
+(as_func_return () {
+  (exit $1)
+}
+as_func_success () {
+  as_func_return 0
+}
+as_func_failure () {
+  as_func_return 1
+}
+as_func_ret_success () {
+  return 0
+}
+as_func_ret_failure () {
+  return 1
+}
+
+exitcode=0
+if as_func_success; then
+  :
+else
+  exitcode=1
+  echo as_func_success failed.
+fi
+
+if as_func_failure; then
+  exitcode=1
+  echo as_func_failure succeeded.
+fi
+
+if as_func_ret_success; then
+  :
+else
+  exitcode=1
+  echo as_func_ret_success failed.
+fi
+
+if as_func_ret_failure; then
+  exitcode=1
+  echo as_func_ret_failure succeeded.
+fi
+
+if ( set x; as_func_ret_success y && test x = "$1" ); then
+  :
+else
+  exitcode=1
+  echo positional parameters were not saved.
+fi
+
+test $exitcode = 0) || { (exit 1); exit 1; }
+
+(
+  as_lineno_1=$LINENO
+  as_lineno_2=$LINENO
+  test "x$as_lineno_1" != "x$as_lineno_2" &&
+  test "x`expr $as_lineno_1 + 1`" = "x$as_lineno_2") || { (exit 1); exit 1; }
+
+_ASEOF
+}; then
+  break
+fi
+
+fi
+
+      done
+
+      if test "x$CONFIG_SHELL" != x; then
+  for as_var in BASH_ENV ENV
+	do ($as_unset $as_var) >/dev/null 2>&1 && $as_unset $as_var
+	done
+	export CONFIG_SHELL
+	exec "$CONFIG_SHELL" "$as_myself" ${1+"$@"}
+fi
+
+
+    if test $as_have_required = no; then
+  echo This script requires a shell more modern than all the
+      echo shells that I found on your system.  Please install a
+      echo modern shell, or manually run the script under such a
+      echo shell if you do have one.
+      { (exit 1); exit 1; }
+fi
+
+
+fi
+
+fi
+
+
+
+(eval "as_func_return () {
+  (exit \$1)
+}
+as_func_success () {
+  as_func_return 0
+}
+as_func_failure () {
+  as_func_return 1
+}
+as_func_ret_success () {
+  return 0
+}
+as_func_ret_failure () {
+  return 1
+}
+
+exitcode=0
+if as_func_success; then
+  :
+else
+  exitcode=1
+  echo as_func_success failed.
+fi
+
+if as_func_failure; then
+  exitcode=1
+  echo as_func_failure succeeded.
+fi
+
+if as_func_ret_success; then
+  :
+else
+  exitcode=1
+  echo as_func_ret_success failed.
+fi
+
+if as_func_ret_failure; then
+  exitcode=1
+  echo as_func_ret_failure succeeded.
+fi
+
+if ( set x; as_func_ret_success y && test x = \"\$1\" ); then
+  :
+else
+  exitcode=1
+  echo positional parameters were not saved.
+fi
+
+test \$exitcode = 0") || {
+  echo No shell found that supports shell functions.
+  echo Please tell bug-autoconf at gnu.org about your system,
+  echo including any error possibly output before this message.
+  echo This can help us improve future autoconf versions.
+  echo Configuration will now proceed without shell functions.
+}
+
+
+
+  as_lineno_1=$LINENO
+  as_lineno_2=$LINENO
+  test "x$as_lineno_1" != "x$as_lineno_2" &&
+  test "x`expr $as_lineno_1 + 1`" = "x$as_lineno_2" || {
+
+  # Create $as_me.lineno as a copy of $as_myself, but with $LINENO
+  # uniformly replaced by the line number.  The first 'sed' inserts a
+  # line-number line after each line using $LINENO; the second 'sed'
+  # does the real work.  The second script uses 'N' to pair each
+  # line-number line with the line containing $LINENO, and appends
+  # trailing '-' during substitution so that $LINENO is not a special
+  # case at line end.
+  # (Raja R Harinath suggested sed '=', and Paul Eggert wrote the
+  # scripts with optimization help from Paolo Bonzini.  Blame Lee
+  # E. McMahon (1931-1989) for sed's syntax.  :-)
+  sed -n '
+    p
+    /[$]LINENO/=
+  ' <$as_myself |
+    sed '
+      s/[$]LINENO.*/&-/
+      t lineno
+      b
+      :lineno
+      N
+      :loop
+      s/[$]LINENO\([^'$as_cr_alnum'_].*\n\)\(.*\)/\2\1\2/
+      t loop
+      s/-\n.*//
+    ' >$as_me.lineno &&
+  chmod +x "$as_me.lineno" ||
+    { $as_echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2
+   { (exit 1); exit 1; }; }
+
+  # Don't try to exec as it changes $[0], causing all sort of problems
+  # (the dirname of $[0] is not the place where we might find the
+  # original and so on.  Autoconf is especially sensitive to this).
+  . "./$as_me.lineno"
+  # Exit status is that of the last command.
+  exit
+}
+
+
+if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then
+  as_dirname=dirname
+else
+  as_dirname=false
+fi
+
+ECHO_C= ECHO_N= ECHO_T=
+case `echo -n x` in
+-n*)
+  case `echo 'x\c'` in
+  *c*) ECHO_T='	';;	# ECHO_T is single tab character.
+  *)   ECHO_C='\c';;
+  esac;;
+*)
+  ECHO_N='-n';;
+esac
+if expr a : '\(a\)' >/dev/null 2>&1 &&
+   test "X`expr 00001 : '.*\(...\)'`" = X001; then
+  as_expr=expr
+else
+  as_expr=false
+fi
+
+rm -f conf$$ conf$$.exe conf$$.file
+if test -d conf$$.dir; then
+  rm -f conf$$.dir/conf$$.file
+else
+  rm -f conf$$.dir
+  mkdir conf$$.dir 2>/dev/null
+fi
+if (echo >conf$$.file) 2>/dev/null; then
+  if ln -s conf$$.file conf$$ 2>/dev/null; then
+    as_ln_s='ln -s'
+    # ... but there are two gotchas:
+    # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail.
+    # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable.
+    # In both cases, we have to default to `cp -p'.
+    ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe ||
+      as_ln_s='cp -p'
+  elif ln conf$$.file conf$$ 2>/dev/null; then
+    as_ln_s=ln
+  else
+    as_ln_s='cp -p'
+  fi
+else
+  as_ln_s='cp -p'
+fi
+rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file
+rmdir conf$$.dir 2>/dev/null
+
+if mkdir -p . 2>/dev/null; then
+  as_mkdir_p=:
+else
+  test -d ./-p && rmdir ./-p
+  as_mkdir_p=false
+fi
+
+if test -x / >/dev/null 2>&1; then
+  as_test_x='test -x'
+else
+  if ls -dL / >/dev/null 2>&1; then
+    as_ls_L_option=L
+  else
+    as_ls_L_option=
+  fi
+  as_test_x='
+    eval sh -c '\''
+      if test -d "$1"; then
+	test -d "$1/.";
+      else
+	case $1 in
+	-*)set "./$1";;
+	esac;
+	case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in
+	???[sx]*):;;*)false;;esac;fi
+    '\'' sh
+  '
+fi
+as_executable_p=$as_test_x
+
+# Sed expression to map a string onto a valid CPP name.
+as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'"
+
+# Sed expression to map a string onto a valid variable name.
+as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'"
+
+
+
+
+# Check that we are running under the correct shell.
+SHELL=${CONFIG_SHELL-/bin/sh}
+
+case X$lt_ECHO in
+X*--fallback-echo)
+  # Remove one level of quotation (which was required for Make).
+  ECHO=`echo "$lt_ECHO" | sed 's,\\\\\$\\$0,'$0','`
+  ;;
+esac
+
+ECHO=${lt_ECHO-echo}
+if test "X$1" = X--no-reexec; then
+  # Discard the --no-reexec flag, and continue.
+  shift
+elif test "X$1" = X--fallback-echo; then
+  # Avoid inline document here, it may be left over
+  :
+elif test "X`{ $ECHO '\t'; } 2>/dev/null`" = 'X\t' ; then
+  # Yippee, $ECHO works!
+  :
+else
+  # Restart under the correct shell.
+  exec $SHELL "$0" --no-reexec ${1+"$@"}
+fi
+
+if test "X$1" = X--fallback-echo; then
+  # used as fallback echo
+  shift
+  cat <<_LT_EOF
+$*
+_LT_EOF
+  exit 0
+fi
+
+# The HP-UX ksh and POSIX shell print the target directory to stdout
+# if CDPATH is set.
+(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
+
+if test -z "$lt_ECHO"; then
+  if test "X${echo_test_string+set}" != Xset; then
+    # find a string as large as possible, as long as the shell can cope with it
+    for cmd in 'sed 50q "$0"' 'sed 20q "$0"' 'sed 10q "$0"' 'sed 2q "$0"' 'echo test'; do
+      # expected sizes: less than 2Kb, 1Kb, 512 bytes, 16 bytes, ...
+      if { echo_test_string=`eval $cmd`; } 2>/dev/null &&
+	 { test "X$echo_test_string" = "X$echo_test_string"; } 2>/dev/null
+      then
+        break
+      fi
+    done
+  fi
+
+  if test "X`{ $ECHO '\t'; } 2>/dev/null`" = 'X\t' &&
+     echo_testing_string=`{ $ECHO "$echo_test_string"; } 2>/dev/null` &&
+     test "X$echo_testing_string" = "X$echo_test_string"; then
+    :
+  else
+    # The Solaris, AIX, and Digital Unix default echo programs unquote
+    # backslashes.  This makes it impossible to quote backslashes using
+    #   echo "$something" | sed 's/\\/\\\\/g'
+    #
+    # So, first we look for a working echo in the user's PATH.
+
+    lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
+    for dir in $PATH /usr/ucb; do
+      IFS="$lt_save_ifs"
+      if (test -f $dir/echo || test -f $dir/echo$ac_exeext) &&
+         test "X`($dir/echo '\t') 2>/dev/null`" = 'X\t' &&
+         echo_testing_string=`($dir/echo "$echo_test_string") 2>/dev/null` &&
+         test "X$echo_testing_string" = "X$echo_test_string"; then
+        ECHO="$dir/echo"
+        break
+      fi
+    done
+    IFS="$lt_save_ifs"
+
+    if test "X$ECHO" = Xecho; then
+      # We didn't find a better echo, so look for alternatives.
+      if test "X`{ print -r '\t'; } 2>/dev/null`" = 'X\t' &&
+         echo_testing_string=`{ print -r "$echo_test_string"; } 2>/dev/null` &&
+         test "X$echo_testing_string" = "X$echo_test_string"; then
+        # This shell has a builtin print -r that does the trick.
+        ECHO='print -r'
+      elif { test -f /bin/ksh || test -f /bin/ksh$ac_exeext; } &&
+	   test "X$CONFIG_SHELL" != X/bin/ksh; then
+        # If we have ksh, try running configure again with it.
+        ORIGINAL_CONFIG_SHELL=${CONFIG_SHELL-/bin/sh}
+        export ORIGINAL_CONFIG_SHELL
+        CONFIG_SHELL=/bin/ksh
+        export CONFIG_SHELL
+        exec $CONFIG_SHELL "$0" --no-reexec ${1+"$@"}
+      else
+        # Try using printf.
+        ECHO='printf %s\n'
+        if test "X`{ $ECHO '\t'; } 2>/dev/null`" = 'X\t' &&
+	   echo_testing_string=`{ $ECHO "$echo_test_string"; } 2>/dev/null` &&
+	   test "X$echo_testing_string" = "X$echo_test_string"; then
+	  # Cool, printf works
+	  :
+        elif echo_testing_string=`($ORIGINAL_CONFIG_SHELL "$0" --fallback-echo '\t') 2>/dev/null` &&
+	     test "X$echo_testing_string" = 'X\t' &&
+	     echo_testing_string=`($ORIGINAL_CONFIG_SHELL "$0" --fallback-echo "$echo_test_string") 2>/dev/null` &&
+	     test "X$echo_testing_string" = "X$echo_test_string"; then
+	  CONFIG_SHELL=$ORIGINAL_CONFIG_SHELL
+	  export CONFIG_SHELL
+	  SHELL="$CONFIG_SHELL"
+	  export SHELL
+	  ECHO="$CONFIG_SHELL $0 --fallback-echo"
+        elif echo_testing_string=`($CONFIG_SHELL "$0" --fallback-echo '\t') 2>/dev/null` &&
+	     test "X$echo_testing_string" = 'X\t' &&
+	     echo_testing_string=`($CONFIG_SHELL "$0" --fallback-echo "$echo_test_string") 2>/dev/null` &&
+	     test "X$echo_testing_string" = "X$echo_test_string"; then
+	  ECHO="$CONFIG_SHELL $0 --fallback-echo"
+        else
+	  # maybe with a smaller string...
+	  prev=:
+
+	  for cmd in 'echo test' 'sed 2q "$0"' 'sed 10q "$0"' 'sed 20q "$0"' 'sed 50q "$0"'; do
+	    if { test "X$echo_test_string" = "X`eval $cmd`"; } 2>/dev/null
+	    then
+	      break
+	    fi
+	    prev="$cmd"
+	  done
+
+	  if test "$prev" != 'sed 50q "$0"'; then
+	    echo_test_string=`eval $prev`
+	    export echo_test_string
+	    exec ${ORIGINAL_CONFIG_SHELL-${CONFIG_SHELL-/bin/sh}} "$0" ${1+"$@"}
+	  else
+	    # Oops.  We lost completely, so just stick with echo.
+	    ECHO=echo
+	  fi
+        fi
+      fi
+    fi
+  fi
+fi
+
+# Copy echo and quote the copy suitably for passing to libtool from
+# the Makefile, instead of quoting the original, which is used later.
+lt_ECHO=$ECHO
+if test "X$lt_ECHO" = "X$CONFIG_SHELL $0 --fallback-echo"; then
+   lt_ECHO="$CONFIG_SHELL \\\$\$0 --fallback-echo"
+fi
+
+
+
+
+exec 7<&0 </dev/null 6>&1
+
+# Name of the host.
+# hostname on some systems (SVR3.2, Linux) returns a bogus exit status,
+# so uname gets run too.
+ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q`
+
+#
+# Initializations.
+#
+ac_default_prefix=/usr/local
+ac_clean_files=
+ac_config_libobj_dir=.
+LIBOBJS=
+cross_compiling=no
+subdirs=
+MFLAGS=
+MAKEFLAGS=
+SHELL=${CONFIG_SHELL-/bin/sh}
+
+# Identity of this package.
+PACKAGE_NAME='SINFONI Instrument Pipeline'
+PACKAGE_TARNAME='sinfo'
+PACKAGE_VERSION='2.3.2'
+PACKAGE_STRING='SINFONI Instrument Pipeline 2.3.2'
+PACKAGE_BUGREPORT='amodigli at eso.org'
+
+ac_unique_file="Makefile.am"
+ac_default_prefix=${PIPE_HOME:-/usr/local}
+# Factoring default headers for most tests.
+ac_includes_default="\
+#include <stdio.h>
+#ifdef HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_STAT_H
+# include <sys/stat.h>
+#endif
+#ifdef STDC_HEADERS
+# include <stdlib.h>
+# include <stddef.h>
+#else
+# ifdef HAVE_STDLIB_H
+#  include <stdlib.h>
+# endif
+#endif
+#ifdef HAVE_STRING_H
+# if !defined STDC_HEADERS && defined HAVE_MEMORY_H
+#  include <memory.h>
+# endif
+# include <string.h>
+#endif
+#ifdef HAVE_STRINGS_H
+# include <strings.h>
+#endif
+#ifdef HAVE_INTTYPES_H
+# include <inttypes.h>
+#endif
+#ifdef HAVE_STDINT_H
+# include <stdint.h>
+#endif
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif"
+
+ac_subst_vars='am__EXEEXT_FALSE
+am__EXEEXT_TRUE
+LTLIBOBJS
+LIBOBJS
+all_ldflags
+all_includes
+LIBIRPLIB
+LIBSINFONI
+IRPLIB_LDFLAGS
+IRPLIB_INCLUDES
+SINFONI_LDFLAGS
+SINFONI_INCLUDES
+configdir
+pipedocsdir
+privatelibdir
+plugindir
+PURIFY_FALSE
+PURIFY_TRUE
+PURIFY_CMD
+CPL_LDFLAGS
+CPL_INCLUDES
+LIBCPLDFS
+LIBCPLUI
+LIBCPLDRS
+LIBCPLCORE
+LIBCEXT
+CX_LDFLAGS
+CX_INCLUDES
+LIBTOOL_DEPS
+OTOOL64
+OTOOL
+LIPO
+NMEDIT
+DSYMUTIL
+lt_ECHO
+RANLIB
+AR
+OBJDUMP
+NM
+ac_ct_DUMPBIN
+DUMPBIN
+LD
+FGREP
+SED
+LIBTOOL
+LATEX
+DOXYGEN
+EGREP
+GREP
+ESO_DEBUG_FLAGS
+LN_S
+CPP
+am__fastdepCC_FALSE
+am__fastdepCC_TRUE
+CCDEPMODE
+AMDEPBACKSLASH
+AMDEP_FALSE
+AMDEP_TRUE
+am__quote
+am__include
+DEPDIR
+OBJEXT
+EXEEXT
+ac_ct_CC
+CPPFLAGS
+LDFLAGS
+CFLAGS
+CC
+LT_AGE
+LT_REVISION
+LT_CURRENT
+SINFONI_BINARY_AGE
+SINFONI_BINARY_VERSION
+SINFONI_INTERFACE_AGE
+SINFONI_MICRO_VERSION
+SINFONI_MINOR_VERSION
+SINFONI_MAJOR_VERSION
+SINFONI_VERSION
+MAINT
+MAINTAINER_MODE_FALSE
+MAINTAINER_MODE_TRUE
+am__untar
+am__tar
+AMTAR
+am__leading_dot
+SET_MAKE
+AWK
+mkdir_p
+MKDIR_P
+INSTALL_STRIP_PROGRAM
+STRIP
+install_sh
+MAKEINFO
+AUTOHEADER
+AUTOMAKE
+AUTOCONF
+ACLOCAL
+VERSION
+PACKAGE
+CYGPATH_W
+am__isrc
+INSTALL_DATA
+INSTALL_SCRIPT
+INSTALL_PROGRAM
+target_os
+target_vendor
+target_cpu
+target
+host_os
+host_vendor
+host_cpu
+host
+build_os
+build_vendor
+build_cpu
+build
+target_alias
+host_alias
+build_alias
+LIBS
+ECHO_T
+ECHO_N
+ECHO_C
+DEFS
+mandir
+localedir
+libdir
+psdir
+pdfdir
+dvidir
+htmldir
+infodir
+docdir
+oldincludedir
+includedir
+localstatedir
+sharedstatedir
+sysconfdir
+datadir
+datarootdir
+libexecdir
+sbindir
+bindir
+program_transform_name
+prefix
+exec_prefix
+PACKAGE_BUGREPORT
+PACKAGE_STRING
+PACKAGE_VERSION
+PACKAGE_TARNAME
+PACKAGE_NAME
+PATH_SEPARATOR
+SHELL'
+ac_subst_files=''
+ac_user_opts='
+enable_option_checking
+enable_maintainer_mode
+enable_dependency_tracking
+enable_debug
+enable_strict
+enable_static
+enable_shared
+with_pic
+enable_fast_install
+with_gnu_ld
+enable_libtool_lock
+with_cext
+with_cext_includes
+with_cext_libs
+enable_cext_test
+with_cpl
+with_cpl_includes
+with_cpl_libs
+enable_cpl_test
+enable_purify
+enable_profile
+with_extra_includes
+with_extra_libs
+with_dmalloc
+'
+      ac_precious_vars='build_alias
+host_alias
+target_alias
+CC
+CFLAGS
+LDFLAGS
+LIBS
+CPPFLAGS
+CPP
+DOXYGEN
+LATEX'
+
+
+# Initialize some variables set by options.
+ac_init_help=
+ac_init_version=false
+ac_unrecognized_opts=
+ac_unrecognized_sep=
+# The variables have the same names as the options, with
+# dashes changed to underlines.
+cache_file=/dev/null
+exec_prefix=NONE
+no_create=
+no_recursion=
+prefix=NONE
+program_prefix=NONE
+program_suffix=NONE
+program_transform_name=s,x,x,
+silent=
+site=
+srcdir=
+verbose=
+x_includes=NONE
+x_libraries=NONE
+
+# Installation directory options.
+# These are left unexpanded so users can "make install exec_prefix=/foo"
+# and all the variables that are supposed to be based on exec_prefix
+# by default will actually change.
+# Use braces instead of parens because sh, perl, etc. also accept them.
+# (The list follows the same order as the GNU Coding Standards.)
+bindir='${exec_prefix}/bin'
+sbindir='${exec_prefix}/sbin'
+libexecdir='${exec_prefix}/libexec'
+datarootdir='${prefix}/share'
+datadir='${datarootdir}'
+sysconfdir='${prefix}/etc'
+sharedstatedir='${prefix}/com'
+localstatedir='${prefix}/var'
+includedir='${prefix}/include'
+oldincludedir='/usr/include'
+docdir='${datarootdir}/doc/${PACKAGE_TARNAME}'
+infodir='${datarootdir}/info'
+htmldir='${docdir}'
+dvidir='${docdir}'
+pdfdir='${docdir}'
+psdir='${docdir}'
+libdir='${exec_prefix}/lib'
+localedir='${datarootdir}/locale'
+mandir='${datarootdir}/man'
+
+ac_prev=
+ac_dashdash=
+for ac_option
+do
+  # If the previous option needs an argument, assign it.
+  if test -n "$ac_prev"; then
+    eval $ac_prev=\$ac_option
+    ac_prev=
+    continue
+  fi
+
+  case $ac_option in
+  *=*)	ac_optarg=`expr "X$ac_option" : '[^=]*=\(.*\)'` ;;
+  *)	ac_optarg=yes ;;
+  esac
+
+  # Accept the important Cygnus configure options, so we can diagnose typos.
+
+  case $ac_dashdash$ac_option in
+  --)
+    ac_dashdash=yes ;;
+
+  -bindir | --bindir | --bindi | --bind | --bin | --bi)
+    ac_prev=bindir ;;
+  -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*)
+    bindir=$ac_optarg ;;
+
+  -build | --build | --buil | --bui | --bu)
+    ac_prev=build_alias ;;
+  -build=* | --build=* | --buil=* | --bui=* | --bu=*)
+    build_alias=$ac_optarg ;;
+
+  -cache-file | --cache-file | --cache-fil | --cache-fi \
+  | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c)
+    ac_prev=cache_file ;;
+  -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \
+  | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*)
+    cache_file=$ac_optarg ;;
+
+  --config-cache | -C)
+    cache_file=config.cache ;;
+
+  -datadir | --datadir | --datadi | --datad)
+    ac_prev=datadir ;;
+  -datadir=* | --datadir=* | --datadi=* | --datad=*)
+    datadir=$ac_optarg ;;
+
+  -datarootdir | --datarootdir | --datarootdi | --datarootd | --dataroot \
+  | --dataroo | --dataro | --datar)
+    ac_prev=datarootdir ;;
+  -datarootdir=* | --datarootdir=* | --datarootdi=* | --datarootd=* \
+  | --dataroot=* | --dataroo=* | --dataro=* | --datar=*)
+    datarootdir=$ac_optarg ;;
+
+  -disable-* | --disable-*)
+    ac_useropt=`expr "x$ac_option" : 'x-*disable-\(.*\)'`
+    # Reject names that are not valid shell variable names.
+    expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
+      { $as_echo "$as_me: error: invalid feature name: $ac_useropt" >&2
+   { (exit 1); exit 1; }; }
+    ac_useropt_orig=$ac_useropt
+    ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
+    case $ac_user_opts in
+      *"
+"enable_$ac_useropt"
+"*) ;;
+      *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--disable-$ac_useropt_orig"
+	 ac_unrecognized_sep=', ';;
+    esac
+    eval enable_$ac_useropt=no ;;
+
+  -docdir | --docdir | --docdi | --doc | --do)
+    ac_prev=docdir ;;
+  -docdir=* | --docdir=* | --docdi=* | --doc=* | --do=*)
+    docdir=$ac_optarg ;;
+
+  -dvidir | --dvidir | --dvidi | --dvid | --dvi | --dv)
+    ac_prev=dvidir ;;
+  -dvidir=* | --dvidir=* | --dvidi=* | --dvid=* | --dvi=* | --dv=*)
+    dvidir=$ac_optarg ;;
+
+  -enable-* | --enable-*)
+    ac_useropt=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'`
+    # Reject names that are not valid shell variable names.
+    expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
+      { $as_echo "$as_me: error: invalid feature name: $ac_useropt" >&2
+   { (exit 1); exit 1; }; }
+    ac_useropt_orig=$ac_useropt
+    ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
+    case $ac_user_opts in
+      *"
+"enable_$ac_useropt"
+"*) ;;
+      *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--enable-$ac_useropt_orig"
+	 ac_unrecognized_sep=', ';;
+    esac
+    eval enable_$ac_useropt=\$ac_optarg ;;
+
+  -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \
+  | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \
+  | --exec | --exe | --ex)
+    ac_prev=exec_prefix ;;
+  -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \
+  | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \
+  | --exec=* | --exe=* | --ex=*)
+    exec_prefix=$ac_optarg ;;
+
+  -gas | --gas | --ga | --g)
+    # Obsolete; use --with-gas.
+    with_gas=yes ;;
+
+  -help | --help | --hel | --he | -h)
+    ac_init_help=long ;;
+  -help=r* | --help=r* | --hel=r* | --he=r* | -hr*)
+    ac_init_help=recursive ;;
+  -help=s* | --help=s* | --hel=s* | --he=s* | -hs*)
+    ac_init_help=short ;;
+
+  -host | --host | --hos | --ho)
+    ac_prev=host_alias ;;
+  -host=* | --host=* | --hos=* | --ho=*)
+    host_alias=$ac_optarg ;;
+
+  -htmldir | --htmldir | --htmldi | --htmld | --html | --htm | --ht)
+    ac_prev=htmldir ;;
+  -htmldir=* | --htmldir=* | --htmldi=* | --htmld=* | --html=* | --htm=* \
+  | --ht=*)
+    htmldir=$ac_optarg ;;
+
+  -includedir | --includedir | --includedi | --included | --include \
+  | --includ | --inclu | --incl | --inc)
+    ac_prev=includedir ;;
+  -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \
+  | --includ=* | --inclu=* | --incl=* | --inc=*)
+    includedir=$ac_optarg ;;
+
+  -infodir | --infodir | --infodi | --infod | --info | --inf)
+    ac_prev=infodir ;;
+  -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*)
+    infodir=$ac_optarg ;;
+
+  -libdir | --libdir | --libdi | --libd)
+    ac_prev=libdir ;;
+  -libdir=* | --libdir=* | --libdi=* | --libd=*)
+    libdir=$ac_optarg ;;
+
+  -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \
+  | --libexe | --libex | --libe)
+    ac_prev=libexecdir ;;
+  -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \
+  | --libexe=* | --libex=* | --libe=*)
+    libexecdir=$ac_optarg ;;
+
+  -localedir | --localedir | --localedi | --localed | --locale)
+    ac_prev=localedir ;;
+  -localedir=* | --localedir=* | --localedi=* | --localed=* | --locale=*)
+    localedir=$ac_optarg ;;
+
+  -localstatedir | --localstatedir | --localstatedi | --localstated \
+  | --localstate | --localstat | --localsta | --localst | --locals)
+    ac_prev=localstatedir ;;
+  -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \
+  | --localstate=* | --localstat=* | --localsta=* | --localst=* | --locals=*)
+    localstatedir=$ac_optarg ;;
+
+  -mandir | --mandir | --mandi | --mand | --man | --ma | --m)
+    ac_prev=mandir ;;
+  -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*)
+    mandir=$ac_optarg ;;
+
+  -nfp | --nfp | --nf)
+    # Obsolete; use --without-fp.
+    with_fp=no ;;
+
+  -no-create | --no-create | --no-creat | --no-crea | --no-cre \
+  | --no-cr | --no-c | -n)
+    no_create=yes ;;
+
+  -no-recursion | --no-recursion | --no-recursio | --no-recursi \
+  | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r)
+    no_recursion=yes ;;
+
+  -oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \
+  | --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \
+  | --oldin | --oldi | --old | --ol | --o)
+    ac_prev=oldincludedir ;;
+  -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \
+  | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \
+  | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*)
+    oldincludedir=$ac_optarg ;;
+
+  -prefix | --prefix | --prefi | --pref | --pre | --pr | --p)
+    ac_prev=prefix ;;
+  -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*)
+    prefix=$ac_optarg ;;
+
+  -program-prefix | --program-prefix | --program-prefi | --program-pref \
+  | --program-pre | --program-pr | --program-p)
+    ac_prev=program_prefix ;;
+  -program-prefix=* | --program-prefix=* | --program-prefi=* \
+  | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*)
+    program_prefix=$ac_optarg ;;
+
+  -program-suffix | --program-suffix | --program-suffi | --program-suff \
+  | --program-suf | --program-su | --program-s)
+    ac_prev=program_suffix ;;
+  -program-suffix=* | --program-suffix=* | --program-suffi=* \
+  | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*)
+    program_suffix=$ac_optarg ;;
+
+  -program-transform-name | --program-transform-name \
+  | --program-transform-nam | --program-transform-na \
+  | --program-transform-n | --program-transform- \
+  | --program-transform | --program-transfor \
+  | --program-transfo | --program-transf \
+  | --program-trans | --program-tran \
+  | --progr-tra | --program-tr | --program-t)
+    ac_prev=program_transform_name ;;
+  -program-transform-name=* | --program-transform-name=* \
+  | --program-transform-nam=* | --program-transform-na=* \
+  | --program-transform-n=* | --program-transform-=* \
+  | --program-transform=* | --program-transfor=* \
+  | --program-transfo=* | --program-transf=* \
+  | --program-trans=* | --program-tran=* \
+  | --progr-tra=* | --program-tr=* | --program-t=*)
+    program_transform_name=$ac_optarg ;;
+
+  -pdfdir | --pdfdir | --pdfdi | --pdfd | --pdf | --pd)
+    ac_prev=pdfdir ;;
+  -pdfdir=* | --pdfdir=* | --pdfdi=* | --pdfd=* | --pdf=* | --pd=*)
+    pdfdir=$ac_optarg ;;
+
+  -psdir | --psdir | --psdi | --psd | --ps)
+    ac_prev=psdir ;;
+  -psdir=* | --psdir=* | --psdi=* | --psd=* | --ps=*)
+    psdir=$ac_optarg ;;
+
+  -q | -quiet | --quiet | --quie | --qui | --qu | --q \
+  | -silent | --silent | --silen | --sile | --sil)
+    silent=yes ;;
+
+  -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
+    ac_prev=sbindir ;;
+  -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
+  | --sbi=* | --sb=*)
+    sbindir=$ac_optarg ;;
+
+  -sharedstatedir | --sharedstatedir | --sharedstatedi \
+  | --sharedstated | --sharedstate | --sharedstat | --sharedsta \
+  | --sharedst | --shareds | --shared | --share | --shar \
+  | --sha | --sh)
+    ac_prev=sharedstatedir ;;
+  -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \
+  | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \
+  | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \
+  | --sha=* | --sh=*)
+    sharedstatedir=$ac_optarg ;;
+
+  -site | --site | --sit)
+    ac_prev=site ;;
+  -site=* | --site=* | --sit=*)
+    site=$ac_optarg ;;
+
+  -srcdir | --srcdir | --srcdi | --srcd | --src | --sr)
+    ac_prev=srcdir ;;
+  -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*)
+    srcdir=$ac_optarg ;;
+
+  -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \
+  | --syscon | --sysco | --sysc | --sys | --sy)
+    ac_prev=sysconfdir ;;
+  -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \
+  | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*)
+    sysconfdir=$ac_optarg ;;
+
+  -target | --target | --targe | --targ | --tar | --ta | --t)
+    ac_prev=target_alias ;;
+  -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*)
+    target_alias=$ac_optarg ;;
+
+  -v | -verbose | --verbose | --verbos | --verbo | --verb)
+    verbose=yes ;;
+
+  -version | --version | --versio | --versi | --vers | -V)
+    ac_init_version=: ;;
+
+  -with-* | --with-*)
+    ac_useropt=`expr "x$ac_option" : 'x-*with-\([^=]*\)'`
+    # Reject names that are not valid shell variable names.
+    expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
+      { $as_echo "$as_me: error: invalid package name: $ac_useropt" >&2
+   { (exit 1); exit 1; }; }
+    ac_useropt_orig=$ac_useropt
+    ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
+    case $ac_user_opts in
+      *"
+"with_$ac_useropt"
+"*) ;;
+      *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--with-$ac_useropt_orig"
+	 ac_unrecognized_sep=', ';;
+    esac
+    eval with_$ac_useropt=\$ac_optarg ;;
+
+  -without-* | --without-*)
+    ac_useropt=`expr "x$ac_option" : 'x-*without-\(.*\)'`
+    # Reject names that are not valid shell variable names.
+    expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
+      { $as_echo "$as_me: error: invalid package name: $ac_useropt" >&2
+   { (exit 1); exit 1; }; }
+    ac_useropt_orig=$ac_useropt
+    ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
+    case $ac_user_opts in
+      *"
+"with_$ac_useropt"
+"*) ;;
+      *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--without-$ac_useropt_orig"
+	 ac_unrecognized_sep=', ';;
+    esac
+    eval with_$ac_useropt=no ;;
+
+  --x)
+    # Obsolete; use --with-x.
+    with_x=yes ;;
+
+  -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \
+  | --x-incl | --x-inc | --x-in | --x-i)
+    ac_prev=x_includes ;;
+  -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \
+  | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*)
+    x_includes=$ac_optarg ;;
+
+  -x-libraries | --x-libraries | --x-librarie | --x-librari \
+  | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l)
+    ac_prev=x_libraries ;;
+  -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \
+  | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*)
+    x_libraries=$ac_optarg ;;
+
+  -*) { $as_echo "$as_me: error: unrecognized option: $ac_option
+Try \`$0 --help' for more information." >&2
+   { (exit 1); exit 1; }; }
+    ;;
+
+  *=*)
+    ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='`
+    # Reject names that are not valid shell variable names.
+    expr "x$ac_envvar" : ".*[^_$as_cr_alnum]" >/dev/null &&
+      { $as_echo "$as_me: error: invalid variable name: $ac_envvar" >&2
+   { (exit 1); exit 1; }; }
+    eval $ac_envvar=\$ac_optarg
+    export $ac_envvar ;;
+
+  *)
+    # FIXME: should be removed in autoconf 3.0.
+    $as_echo "$as_me: WARNING: you should use --build, --host, --target" >&2
+    expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null &&
+      $as_echo "$as_me: WARNING: invalid host type: $ac_option" >&2
+    : ${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option}
+    ;;
+
+  esac
+done
+
+if test -n "$ac_prev"; then
+  ac_option=--`echo $ac_prev | sed 's/_/-/g'`
+  { $as_echo "$as_me: error: missing argument to $ac_option" >&2
+   { (exit 1); exit 1; }; }
+fi
+
+if test -n "$ac_unrecognized_opts"; then
+  case $enable_option_checking in
+    no) ;;
+    fatal) { $as_echo "$as_me: error: unrecognized options: $ac_unrecognized_opts" >&2
+   { (exit 1); exit 1; }; } ;;
+    *)     $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2 ;;
+  esac
+fi
+
+# Check all directory arguments for consistency.
+for ac_var in	exec_prefix prefix bindir sbindir libexecdir datarootdir \
+		datadir sysconfdir sharedstatedir localstatedir includedir \
+		oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
+		libdir localedir mandir
+do
+  eval ac_val=\$$ac_var
+  # Remove trailing slashes.
+  case $ac_val in
+    */ )
+      ac_val=`expr "X$ac_val" : 'X\(.*[^/]\)' \| "X$ac_val" : 'X\(.*\)'`
+      eval $ac_var=\$ac_val;;
+  esac
+  # Be sure to have absolute directory names.
+  case $ac_val in
+    [\\/$]* | ?:[\\/]* )  continue;;
+    NONE | '' ) case $ac_var in *prefix ) continue;; esac;;
+  esac
+  { $as_echo "$as_me: error: expected an absolute directory name for --$ac_var: $ac_val" >&2
+   { (exit 1); exit 1; }; }
+done
+
+# There might be people who depend on the old broken behavior: `$host'
+# used to hold the argument of --host etc.
+# FIXME: To remove some day.
+build=$build_alias
+host=$host_alias
+target=$target_alias
+
+# FIXME: To remove some day.
+if test "x$host_alias" != x; then
+  if test "x$build_alias" = x; then
+    cross_compiling=maybe
+    $as_echo "$as_me: WARNING: If you wanted to set the --build type, don't use --host.
+    If a cross compiler is detected then cross compile mode will be used." >&2
+  elif test "x$build_alias" != "x$host_alias"; then
+    cross_compiling=yes
+  fi
+fi
+
+ac_tool_prefix=
+test -n "$host_alias" && ac_tool_prefix=$host_alias-
+
+test "$silent" = yes && exec 6>/dev/null
+
+
+ac_pwd=`pwd` && test -n "$ac_pwd" &&
+ac_ls_di=`ls -di .` &&
+ac_pwd_ls_di=`cd "$ac_pwd" && ls -di .` ||
+  { $as_echo "$as_me: error: working directory cannot be determined" >&2
+   { (exit 1); exit 1; }; }
+test "X$ac_ls_di" = "X$ac_pwd_ls_di" ||
+  { $as_echo "$as_me: error: pwd does not report name of working directory" >&2
+   { (exit 1); exit 1; }; }
+
+
+# Find the source files, if location was not specified.
+if test -z "$srcdir"; then
+  ac_srcdir_defaulted=yes
+  # Try the directory containing this script, then the parent directory.
+  ac_confdir=`$as_dirname -- "$as_myself" ||
+$as_expr X"$as_myself" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	 X"$as_myself" : 'X\(//\)[^/]' \| \
+	 X"$as_myself" : 'X\(//\)$' \| \
+	 X"$as_myself" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X"$as_myself" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)[^/].*/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\).*/{
+	    s//\1/
+	    q
+	  }
+	  s/.*/./; q'`
+  srcdir=$ac_confdir
+  if test ! -r "$srcdir/$ac_unique_file"; then
+    srcdir=..
+  fi
+else
+  ac_srcdir_defaulted=no
+fi
+if test ! -r "$srcdir/$ac_unique_file"; then
+  test "$ac_srcdir_defaulted" = yes && srcdir="$ac_confdir or .."
+  { $as_echo "$as_me: error: cannot find sources ($ac_unique_file) in $srcdir" >&2
+   { (exit 1); exit 1; }; }
+fi
+ac_msg="sources are in $srcdir, but \`cd $srcdir' does not work"
+ac_abs_confdir=`(
+	cd "$srcdir" && test -r "./$ac_unique_file" || { $as_echo "$as_me: error: $ac_msg" >&2
+   { (exit 1); exit 1; }; }
+	pwd)`
+# When building in place, set srcdir=.
+if test "$ac_abs_confdir" = "$ac_pwd"; then
+  srcdir=.
+fi
+# Remove unnecessary trailing slashes from srcdir.
+# Double slashes in file names in object file debugging info
+# mess up M-x gdb in Emacs.
+case $srcdir in
+*/) srcdir=`expr "X$srcdir" : 'X\(.*[^/]\)' \| "X$srcdir" : 'X\(.*\)'`;;
+esac
+for ac_var in $ac_precious_vars; do
+  eval ac_env_${ac_var}_set=\${${ac_var}+set}
+  eval ac_env_${ac_var}_value=\$${ac_var}
+  eval ac_cv_env_${ac_var}_set=\${${ac_var}+set}
+  eval ac_cv_env_${ac_var}_value=\$${ac_var}
+done
+
+#
+# Report the --help message.
+#
+if test "$ac_init_help" = "long"; then
+  # Omit some internal or obsolete options to make the list less imposing.
+  # This message is too long to be a string in the A/UX 3.1 sh.
+  cat <<_ACEOF
+\`configure' configures SINFONI Instrument Pipeline 2.3.2 to adapt to many kinds of systems.
+
+Usage: $0 [OPTION]... [VAR=VALUE]...
+
+To assign environment variables (e.g., CC, CFLAGS...), specify them as
+VAR=VALUE.  See below for descriptions of some of the useful variables.
+
+Defaults for the options are specified in brackets.
+
+Configuration:
+  -h, --help              display this help and exit
+      --help=short        display options specific to this package
+      --help=recursive    display the short help of all the included packages
+  -V, --version           display version information and exit
+  -q, --quiet, --silent   do not print \`checking...' messages
+      --cache-file=FILE   cache test results in FILE [disabled]
+  -C, --config-cache      alias for \`--cache-file=config.cache'
+  -n, --no-create         do not create output files
+      --srcdir=DIR        find the sources in DIR [configure dir or \`..']
+
+Installation directories:
+  --prefix=PREFIX         install architecture-independent files in PREFIX
+                          [$ac_default_prefix]
+  --exec-prefix=EPREFIX   install architecture-dependent files in EPREFIX
+                          [PREFIX]
+
+By default, \`make install' will install all the files in
+\`$ac_default_prefix/bin', \`$ac_default_prefix/lib' etc.  You can specify
+an installation prefix other than \`$ac_default_prefix' using \`--prefix',
+for instance \`--prefix=\$HOME'.
+
+For better control, use the options below.
+
+Fine tuning of the installation directories:
+  --bindir=DIR            user executables [EPREFIX/bin]
+  --sbindir=DIR           system admin executables [EPREFIX/sbin]
+  --libexecdir=DIR        program executables [EPREFIX/libexec]
+  --sysconfdir=DIR        read-only single-machine data [PREFIX/etc]
+  --sharedstatedir=DIR    modifiable architecture-independent data [PREFIX/com]
+  --localstatedir=DIR     modifiable single-machine data [PREFIX/var]
+  --libdir=DIR            object code libraries [EPREFIX/lib]
+  --includedir=DIR        C header files [PREFIX/include]
+  --oldincludedir=DIR     C header files for non-gcc [/usr/include]
+  --datarootdir=DIR       read-only arch.-independent data root [PREFIX/share]
+  --datadir=DIR           read-only architecture-independent data [DATAROOTDIR]
+  --infodir=DIR           info documentation [DATAROOTDIR/info]
+  --localedir=DIR         locale-dependent data [DATAROOTDIR/locale]
+  --mandir=DIR            man documentation [DATAROOTDIR/man]
+  --docdir=DIR            documentation root [DATAROOTDIR/doc/sinfo]
+  --htmldir=DIR           html documentation [DOCDIR]
+  --dvidir=DIR            dvi documentation [DOCDIR]
+  --pdfdir=DIR            pdf documentation [DOCDIR]
+  --psdir=DIR             ps documentation [DOCDIR]
+_ACEOF
+
+  cat <<\_ACEOF
+
+Program names:
+  --program-prefix=PREFIX            prepend PREFIX to installed program names
+  --program-suffix=SUFFIX            append SUFFIX to installed program names
+  --program-transform-name=PROGRAM   run sed PROGRAM on installed program names
+
+System types:
+  --build=BUILD     configure for building on BUILD [guessed]
+  --host=HOST       cross-compile to build programs to run on HOST [BUILD]
+  --target=TARGET   configure for building compilers for TARGET [HOST]
+_ACEOF
+fi
+
+if test -n "$ac_init_help"; then
+  case $ac_init_help in
+     short | recursive ) echo "Configuration of SINFONI Instrument Pipeline 2.3.2:";;
+   esac
+  cat <<\_ACEOF
+
+Optional Features:
+  --disable-option-checking  ignore unrecognized --enable/--with options
+  --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
+  --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
+  --enable-maintainer-mode  enable make rules and dependencies not useful
+			  (and sometimes confusing) to the casual installer
+  --disable-dependency-tracking  speeds up one-time build
+  --enable-dependency-tracking   do not reject slow dependency extractors
+  --enable-debug          creates debugging code [default=no]
+  --enable-strict         compiles with strict compiler options (may not
+                          work!) [default=no]
+  --enable-static[=PKGS]  build static libraries [default=no]
+  --enable-shared[=PKGS]  build shared libraries [default=yes]
+  --enable-fast-install[=PKGS]
+                          optimize for fast installation [default=yes]
+  --disable-libtool-lock  avoid locking (might break parallel builds)
+  --disable-cext-test     disables checks for the libcext library and headers
+  --disable-cpl-test      disables checks for the CPL library and headers
+  --disable-purify        disables the check for the PURIFY installation
+  --enable-profile        compiles with compiler options necessary for
+                          profiling (may not work!) [default=no]
+
+Optional Packages:
+  --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
+  --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
+  --with-pic              try to use only PIC/non-PIC objects [default=use
+                          both]
+  --with-gnu-ld           assume the C compiler uses GNU ld [default=no]
+  --with-cext             location where libcext is installed
+  --with-cext-includes    location of the libcext header files
+  --with-cext-libs        location of the libcext library
+  --with-cpl              location where CPL is installed
+  --with-cpl-includes     location of the CPL header files
+  --with-cpl-libs         location of the CPL library
+  --with-extra-includes=DIR
+                          adds non standard include paths
+  --with-extra-libs=DIR   adds non standard library paths
+  --with-dmalloc          use dmalloc, as in
+			  http://www.dmalloc.com/dmalloc.tar.gz
+
+Some influential environment variables:
+  CC          C compiler command
+  CFLAGS      C compiler flags
+  LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a
+              nonstandard directory <lib dir>
+  LIBS        libraries to pass to the linker, e.g. -l<library>
+  CPPFLAGS    C/C++/Objective C preprocessor flags, e.g. -I<include dir> if
+              you have headers in a nonstandard directory <include dir>
+  CPP         C preprocessor
+  DOXYGEN     doxygen command
+  LATEX       latex command
+
+Use these variables to override the choices made by `configure' or to help
+it to find libraries and programs with nonstandard names/locations.
+
+Report bugs to <amodigli at eso.org>.
+_ACEOF
+ac_status=$?
+fi
+
+if test "$ac_init_help" = "recursive"; then
+  # If there are subdirs, report their specific --help.
+  for ac_dir in : $ac_subdirs_all; do test "x$ac_dir" = x: && continue
+    test -d "$ac_dir" ||
+      { cd "$srcdir" && ac_pwd=`pwd` && srcdir=. && test -d "$ac_dir"; } ||
+      continue
+    ac_builddir=.
+
+case "$ac_dir" in
+.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;;
+*)
+  ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'`
+  # A ".." for each directory in $ac_dir_suffix.
+  ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'`
+  case $ac_top_builddir_sub in
+  "") ac_top_builddir_sub=. ac_top_build_prefix= ;;
+  *)  ac_top_build_prefix=$ac_top_builddir_sub/ ;;
+  esac ;;
+esac
+ac_abs_top_builddir=$ac_pwd
+ac_abs_builddir=$ac_pwd$ac_dir_suffix
+# for backward compatibility:
+ac_top_builddir=$ac_top_build_prefix
+
+case $srcdir in
+  .)  # We are building in place.
+    ac_srcdir=.
+    ac_top_srcdir=$ac_top_builddir_sub
+    ac_abs_top_srcdir=$ac_pwd ;;
+  [\\/]* | ?:[\\/]* )  # Absolute name.
+    ac_srcdir=$srcdir$ac_dir_suffix;
+    ac_top_srcdir=$srcdir
+    ac_abs_top_srcdir=$srcdir ;;
+  *) # Relative name.
+    ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix
+    ac_top_srcdir=$ac_top_build_prefix$srcdir
+    ac_abs_top_srcdir=$ac_pwd/$srcdir ;;
+esac
+ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix
+
+    cd "$ac_dir" || { ac_status=$?; continue; }
+    # Check for guested configure.
+    if test -f "$ac_srcdir/configure.gnu"; then
+      echo &&
+      $SHELL "$ac_srcdir/configure.gnu" --help=recursive
+    elif test -f "$ac_srcdir/configure"; then
+      echo &&
+      $SHELL "$ac_srcdir/configure" --help=recursive
+    else
+      $as_echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2
+    fi || ac_status=$?
+    cd "$ac_pwd" || { ac_status=$?; break; }
+  done
+fi
+
+test -n "$ac_init_help" && exit $ac_status
+if $ac_init_version; then
+  cat <<\_ACEOF
+SINFONI Instrument Pipeline configure 2.3.2
+generated by GNU Autoconf 2.63
+
+Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
+2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+This configure script is free software; the Free Software Foundation
+gives unlimited permission to copy, distribute and modify it.
+_ACEOF
+  exit
+fi
+cat >config.log <<_ACEOF
+This file contains any messages produced by compilers while
+running configure, to aid debugging if configure makes a mistake.
+
+It was created by SINFONI Instrument Pipeline $as_me 2.3.2, which was
+generated by GNU Autoconf 2.63.  Invocation command line was
+
+  $ $0 $@
+
+_ACEOF
+exec 5>>config.log
+{
+cat <<_ASUNAME
+## --------- ##
+## Platform. ##
+## --------- ##
+
+hostname = `(hostname || uname -n) 2>/dev/null | sed 1q`
+uname -m = `(uname -m) 2>/dev/null || echo unknown`
+uname -r = `(uname -r) 2>/dev/null || echo unknown`
+uname -s = `(uname -s) 2>/dev/null || echo unknown`
+uname -v = `(uname -v) 2>/dev/null || echo unknown`
+
+/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null || echo unknown`
+/bin/uname -X     = `(/bin/uname -X) 2>/dev/null     || echo unknown`
+
+/bin/arch              = `(/bin/arch) 2>/dev/null              || echo unknown`
+/usr/bin/arch -k       = `(/usr/bin/arch -k) 2>/dev/null       || echo unknown`
+/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null || echo unknown`
+/usr/bin/hostinfo      = `(/usr/bin/hostinfo) 2>/dev/null      || echo unknown`
+/bin/machine           = `(/bin/machine) 2>/dev/null           || echo unknown`
+/usr/bin/oslevel       = `(/usr/bin/oslevel) 2>/dev/null       || echo unknown`
+/bin/universe          = `(/bin/universe) 2>/dev/null          || echo unknown`
+
+_ASUNAME
+
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  $as_echo "PATH: $as_dir"
+done
+IFS=$as_save_IFS
+
+} >&5
+
+cat >&5 <<_ACEOF
+
+
+## ----------- ##
+## Core tests. ##
+## ----------- ##
+
+_ACEOF
+
+
+# Keep a trace of the command line.
+# Strip out --no-create and --no-recursion so they do not pile up.
+# Strip out --silent because we don't want to record it for future runs.
+# Also quote any args containing shell meta-characters.
+# Make two passes to allow for proper duplicate-argument suppression.
+ac_configure_args=
+ac_configure_args0=
+ac_configure_args1=
+ac_must_keep_next=false
+for ac_pass in 1 2
+do
+  for ac_arg
+  do
+    case $ac_arg in
+    -no-create | --no-c* | -n | -no-recursion | --no-r*) continue ;;
+    -q | -quiet | --quiet | --quie | --qui | --qu | --q \
+    | -silent | --silent | --silen | --sile | --sil)
+      continue ;;
+    *\'*)
+      ac_arg=`$as_echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;;
+    esac
+    case $ac_pass in
+    1) ac_configure_args0="$ac_configure_args0 '$ac_arg'" ;;
+    2)
+      ac_configure_args1="$ac_configure_args1 '$ac_arg'"
+      if test $ac_must_keep_next = true; then
+	ac_must_keep_next=false # Got value, back to normal.
+      else
+	case $ac_arg in
+	  *=* | --config-cache | -C | -disable-* | --disable-* \
+	  | -enable-* | --enable-* | -gas | --g* | -nfp | --nf* \
+	  | -q | -quiet | --q* | -silent | --sil* | -v | -verb* \
+	  | -with-* | --with-* | -without-* | --without-* | --x)
+	    case "$ac_configure_args0 " in
+	      "$ac_configure_args1"*" '$ac_arg' "* ) continue ;;
+	    esac
+	    ;;
+	  -* ) ac_must_keep_next=true ;;
+	esac
+      fi
+      ac_configure_args="$ac_configure_args '$ac_arg'"
+      ;;
+    esac
+  done
+done
+$as_unset ac_configure_args0 || test "${ac_configure_args0+set}" != set || { ac_configure_args0=; export ac_configure_args0; }
+$as_unset ac_configure_args1 || test "${ac_configure_args1+set}" != set || { ac_configure_args1=; export ac_configure_args1; }
+
+# When interrupted or exit'd, cleanup temporary files, and complete
+# config.log.  We remove comments because anyway the quotes in there
+# would cause problems or look ugly.
+# WARNING: Use '\'' to represent an apostrophe within the trap.
+# WARNING: Do not start the trap code with a newline, due to a FreeBSD 4.0 bug.
+trap 'exit_status=$?
+  # Save into config.log some information that might help in debugging.
+  {
+    echo
+
+    cat <<\_ASBOX
+## ---------------- ##
+## Cache variables. ##
+## ---------------- ##
+_ASBOX
+    echo
+    # The following way of writing the cache mishandles newlines in values,
+(
+  for ac_var in `(set) 2>&1 | sed -n '\''s/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'\''`; do
+    eval ac_val=\$$ac_var
+    case $ac_val in #(
+    *${as_nl}*)
+      case $ac_var in #(
+      *_cv_*) { $as_echo "$as_me:$LINENO: WARNING: cache variable $ac_var contains a newline" >&5
+$as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;;
+      esac
+      case $ac_var in #(
+      _ | IFS | as_nl) ;; #(
+      BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #(
+      *) $as_unset $ac_var ;;
+      esac ;;
+    esac
+  done
+  (set) 2>&1 |
+    case $as_nl`(ac_space='\'' '\''; set) 2>&1` in #(
+    *${as_nl}ac_space=\ *)
+      sed -n \
+	"s/'\''/'\''\\\\'\'''\''/g;
+	  s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\''\\2'\''/p"
+      ;; #(
+    *)
+      sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p"
+      ;;
+    esac |
+    sort
+)
+    echo
+
+    cat <<\_ASBOX
+## ----------------- ##
+## Output variables. ##
+## ----------------- ##
+_ASBOX
+    echo
+    for ac_var in $ac_subst_vars
+    do
+      eval ac_val=\$$ac_var
+      case $ac_val in
+      *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;;
+      esac
+      $as_echo "$ac_var='\''$ac_val'\''"
+    done | sort
+    echo
+
+    if test -n "$ac_subst_files"; then
+      cat <<\_ASBOX
+## ------------------- ##
+## File substitutions. ##
+## ------------------- ##
+_ASBOX
+      echo
+      for ac_var in $ac_subst_files
+      do
+	eval ac_val=\$$ac_var
+	case $ac_val in
+	*\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;;
+	esac
+	$as_echo "$ac_var='\''$ac_val'\''"
+      done | sort
+      echo
+    fi
+
+    if test -s confdefs.h; then
+      cat <<\_ASBOX
+## ----------- ##
+## confdefs.h. ##
+## ----------- ##
+_ASBOX
+      echo
+      cat confdefs.h
+      echo
+    fi
+    test "$ac_signal" != 0 &&
+      $as_echo "$as_me: caught signal $ac_signal"
+    $as_echo "$as_me: exit $exit_status"
+  } >&5
+  rm -f core *.core core.conftest.* &&
+    rm -f -r conftest* confdefs* conf$$* $ac_clean_files &&
+    exit $exit_status
+' 0
+for ac_signal in 1 2 13 15; do
+  trap 'ac_signal='$ac_signal'; { (exit 1); exit 1; }' $ac_signal
+done
+ac_signal=0
+
+# confdefs.h avoids OS command line length limits that DEFS can exceed.
+rm -f -r conftest* confdefs.h
+
+# Predefined preprocessor variables.
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_NAME "$PACKAGE_NAME"
+_ACEOF
+
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_TARNAME "$PACKAGE_TARNAME"
+_ACEOF
+
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_VERSION "$PACKAGE_VERSION"
+_ACEOF
+
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_STRING "$PACKAGE_STRING"
+_ACEOF
+
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_BUGREPORT "$PACKAGE_BUGREPORT"
+_ACEOF
+
+
+# Let the site file select an alternate cache file if it wants to.
+# Prefer an explicitly selected file to automatically selected ones.
+ac_site_file1=NONE
+ac_site_file2=NONE
+if test -n "$CONFIG_SITE"; then
+  ac_site_file1=$CONFIG_SITE
+elif test "x$prefix" != xNONE; then
+  ac_site_file1=$prefix/share/config.site
+  ac_site_file2=$prefix/etc/config.site
+else
+  ac_site_file1=$ac_default_prefix/share/config.site
+  ac_site_file2=$ac_default_prefix/etc/config.site
+fi
+for ac_site_file in "$ac_site_file1" "$ac_site_file2"
+do
+  test "x$ac_site_file" = xNONE && continue
+  if test -r "$ac_site_file"; then
+    { $as_echo "$as_me:$LINENO: loading site script $ac_site_file" >&5
+$as_echo "$as_me: loading site script $ac_site_file" >&6;}
+    sed 's/^/| /' "$ac_site_file" >&5
+    . "$ac_site_file"
+  fi
+done
+
+if test -r "$cache_file"; then
+  # Some versions of bash will fail to source /dev/null (special
+  # files actually), so we avoid doing that.
+  if test -f "$cache_file"; then
+    { $as_echo "$as_me:$LINENO: loading cache $cache_file" >&5
+$as_echo "$as_me: loading cache $cache_file" >&6;}
+    case $cache_file in
+      [\\/]* | ?:[\\/]* ) . "$cache_file";;
+      *)                      . "./$cache_file";;
+    esac
+  fi
+else
+  { $as_echo "$as_me:$LINENO: creating cache $cache_file" >&5
+$as_echo "$as_me: creating cache $cache_file" >&6;}
+  >$cache_file
+fi
+
+# Check that the precious variables saved in the cache have kept the same
+# value.
+ac_cache_corrupted=false
+for ac_var in $ac_precious_vars; do
+  eval ac_old_set=\$ac_cv_env_${ac_var}_set
+  eval ac_new_set=\$ac_env_${ac_var}_set
+  eval ac_old_val=\$ac_cv_env_${ac_var}_value
+  eval ac_new_val=\$ac_env_${ac_var}_value
+  case $ac_old_set,$ac_new_set in
+    set,)
+      { $as_echo "$as_me:$LINENO: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5
+$as_echo "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;}
+      ac_cache_corrupted=: ;;
+    ,set)
+      { $as_echo "$as_me:$LINENO: error: \`$ac_var' was not set in the previous run" >&5
+$as_echo "$as_me: error: \`$ac_var' was not set in the previous run" >&2;}
+      ac_cache_corrupted=: ;;
+    ,);;
+    *)
+      if test "x$ac_old_val" != "x$ac_new_val"; then
+	# differences in whitespace do not lead to failure.
+	ac_old_val_w=`echo x $ac_old_val`
+	ac_new_val_w=`echo x $ac_new_val`
+	if test "$ac_old_val_w" != "$ac_new_val_w"; then
+	  { $as_echo "$as_me:$LINENO: error: \`$ac_var' has changed since the previous run:" >&5
+$as_echo "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;}
+	  ac_cache_corrupted=:
+	else
+	  { $as_echo "$as_me:$LINENO: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&5
+$as_echo "$as_me: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&2;}
+	  eval $ac_var=\$ac_old_val
+	fi
+	{ $as_echo "$as_me:$LINENO:   former value:  \`$ac_old_val'" >&5
+$as_echo "$as_me:   former value:  \`$ac_old_val'" >&2;}
+	{ $as_echo "$as_me:$LINENO:   current value: \`$ac_new_val'" >&5
+$as_echo "$as_me:   current value: \`$ac_new_val'" >&2;}
+      fi;;
+  esac
+  # Pass precious variables to config.status.
+  if test "$ac_new_set" = set; then
+    case $ac_new_val in
+    *\'*) ac_arg=$ac_var=`$as_echo "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;;
+    *) ac_arg=$ac_var=$ac_new_val ;;
+    esac
+    case " $ac_configure_args " in
+      *" '$ac_arg' "*) ;; # Avoid dups.  Use of quotes ensures accuracy.
+      *) ac_configure_args="$ac_configure_args '$ac_arg'" ;;
+    esac
+  fi
+done
+if $ac_cache_corrupted; then
+  { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+  { $as_echo "$as_me:$LINENO: error: changes in the environment can compromise the build" >&5
+$as_echo "$as_me: error: changes in the environment can compromise the build" >&2;}
+  { { $as_echo "$as_me:$LINENO: error: run \`make distclean' and/or \`rm $cache_file' and start over" >&5
+$as_echo "$as_me: error: run \`make distclean' and/or \`rm $cache_file' and start over" >&2;}
+   { (exit 1); exit 1; }; }
+fi
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+
+
+
+
+ac_aux_dir=
+for ac_dir in admin "$srcdir"/admin; do
+  if test -f "$ac_dir/install-sh"; then
+    ac_aux_dir=$ac_dir
+    ac_install_sh="$ac_aux_dir/install-sh -c"
+    break
+  elif test -f "$ac_dir/install.sh"; then
+    ac_aux_dir=$ac_dir
+    ac_install_sh="$ac_aux_dir/install.sh -c"
+    break
+  elif test -f "$ac_dir/shtool"; then
+    ac_aux_dir=$ac_dir
+    ac_install_sh="$ac_aux_dir/shtool install -c"
+    break
+  fi
+done
+if test -z "$ac_aux_dir"; then
+  { { $as_echo "$as_me:$LINENO: error: cannot find install-sh or install.sh in admin \"$srcdir\"/admin" >&5
+$as_echo "$as_me: error: cannot find install-sh or install.sh in admin \"$srcdir\"/admin" >&2;}
+   { (exit 1); exit 1; }; }
+fi
+
+# These three variables are undocumented and unsupported,
+# and are intended to be withdrawn in a future Autoconf release.
+# They can cause serious problems if a builder's source tree is in a directory
+# whose full name contains unusual characters.
+ac_config_guess="$SHELL $ac_aux_dir/config.guess"  # Please don't use this var.
+ac_config_sub="$SHELL $ac_aux_dir/config.sub"  # Please don't use this var.
+ac_configure="$SHELL $ac_aux_dir/configure"  # Please don't use this var.
+
+
+
+# Make sure we can run config.sub.
+$SHELL "$ac_aux_dir/config.sub" sun4 >/dev/null 2>&1 ||
+  { { $as_echo "$as_me:$LINENO: error: cannot run $SHELL $ac_aux_dir/config.sub" >&5
+$as_echo "$as_me: error: cannot run $SHELL $ac_aux_dir/config.sub" >&2;}
+   { (exit 1); exit 1; }; }
+
+{ $as_echo "$as_me:$LINENO: checking build system type" >&5
+$as_echo_n "checking build system type... " >&6; }
+if test "${ac_cv_build+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  ac_build_alias=$build_alias
+test "x$ac_build_alias" = x &&
+  ac_build_alias=`$SHELL "$ac_aux_dir/config.guess"`
+test "x$ac_build_alias" = x &&
+  { { $as_echo "$as_me:$LINENO: error: cannot guess build type; you must specify one" >&5
+$as_echo "$as_me: error: cannot guess build type; you must specify one" >&2;}
+   { (exit 1); exit 1; }; }
+ac_cv_build=`$SHELL "$ac_aux_dir/config.sub" $ac_build_alias` ||
+  { { $as_echo "$as_me:$LINENO: error: $SHELL $ac_aux_dir/config.sub $ac_build_alias failed" >&5
+$as_echo "$as_me: error: $SHELL $ac_aux_dir/config.sub $ac_build_alias failed" >&2;}
+   { (exit 1); exit 1; }; }
+
+fi
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_build" >&5
+$as_echo "$ac_cv_build" >&6; }
+case $ac_cv_build in
+*-*-*) ;;
+*) { { $as_echo "$as_me:$LINENO: error: invalid value of canonical build" >&5
+$as_echo "$as_me: error: invalid value of canonical build" >&2;}
+   { (exit 1); exit 1; }; };;
+esac
+build=$ac_cv_build
+ac_save_IFS=$IFS; IFS='-'
+set x $ac_cv_build
+shift
+build_cpu=$1
+build_vendor=$2
+shift; shift
+# Remember, the first character of IFS is used to create $*,
+# except with old shells:
+build_os=$*
+IFS=$ac_save_IFS
+case $build_os in *\ *) build_os=`echo "$build_os" | sed 's/ /-/g'`;; esac
+
+
+{ $as_echo "$as_me:$LINENO: checking host system type" >&5
+$as_echo_n "checking host system type... " >&6; }
+if test "${ac_cv_host+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  if test "x$host_alias" = x; then
+  ac_cv_host=$ac_cv_build
+else
+  ac_cv_host=`$SHELL "$ac_aux_dir/config.sub" $host_alias` ||
+    { { $as_echo "$as_me:$LINENO: error: $SHELL $ac_aux_dir/config.sub $host_alias failed" >&5
+$as_echo "$as_me: error: $SHELL $ac_aux_dir/config.sub $host_alias failed" >&2;}
+   { (exit 1); exit 1; }; }
+fi
+
+fi
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_host" >&5
+$as_echo "$ac_cv_host" >&6; }
+case $ac_cv_host in
+*-*-*) ;;
+*) { { $as_echo "$as_me:$LINENO: error: invalid value of canonical host" >&5
+$as_echo "$as_me: error: invalid value of canonical host" >&2;}
+   { (exit 1); exit 1; }; };;
+esac
+host=$ac_cv_host
+ac_save_IFS=$IFS; IFS='-'
+set x $ac_cv_host
+shift
+host_cpu=$1
+host_vendor=$2
+shift; shift
+# Remember, the first character of IFS is used to create $*,
+# except with old shells:
+host_os=$*
+IFS=$ac_save_IFS
+case $host_os in *\ *) host_os=`echo "$host_os" | sed 's/ /-/g'`;; esac
+
+
+{ $as_echo "$as_me:$LINENO: checking target system type" >&5
+$as_echo_n "checking target system type... " >&6; }
+if test "${ac_cv_target+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  if test "x$target_alias" = x; then
+  ac_cv_target=$ac_cv_host
+else
+  ac_cv_target=`$SHELL "$ac_aux_dir/config.sub" $target_alias` ||
+    { { $as_echo "$as_me:$LINENO: error: $SHELL $ac_aux_dir/config.sub $target_alias failed" >&5
+$as_echo "$as_me: error: $SHELL $ac_aux_dir/config.sub $target_alias failed" >&2;}
+   { (exit 1); exit 1; }; }
+fi
+
+fi
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_target" >&5
+$as_echo "$ac_cv_target" >&6; }
+case $ac_cv_target in
+*-*-*) ;;
+*) { { $as_echo "$as_me:$LINENO: error: invalid value of canonical target" >&5
+$as_echo "$as_me: error: invalid value of canonical target" >&2;}
+   { (exit 1); exit 1; }; };;
+esac
+target=$ac_cv_target
+ac_save_IFS=$IFS; IFS='-'
+set x $ac_cv_target
+shift
+target_cpu=$1
+target_vendor=$2
+shift; shift
+# Remember, the first character of IFS is used to create $*,
+# except with old shells:
+target_os=$*
+IFS=$ac_save_IFS
+case $target_os in *\ *) target_os=`echo "$target_os" | sed 's/ /-/g'`;; esac
+
+
+# The aliases save the names the user supplied, while $host etc.
+# will get canonicalized.
+test -n "$target_alias" &&
+  test "$program_prefix$program_suffix$program_transform_name" = \
+    NONENONEs,x,x, &&
+  program_prefix=${target_alias}-
+
+am__api_version='1.11'
+
+# Find a good install program.  We prefer a C program (faster),
+# so one script is as good as another.  But avoid the broken or
+# incompatible versions:
+# SysV /etc/install, /usr/sbin/install
+# SunOS /usr/etc/install
+# IRIX /sbin/install
+# AIX /bin/install
+# AmigaOS /C/install, which installs bootblocks on floppy discs
+# AIX 4 /usr/bin/installbsd, which doesn't work without a -g flag
+# AFS /usr/afsws/bin/install, which mishandles nonexistent args
+# SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff"
+# OS/2's system install, which has a completely different semantic
+# ./install, which can be erroneously created by make from ./install.sh.
+# Reject install programs that cannot install multiple files.
+{ $as_echo "$as_me:$LINENO: checking for a BSD-compatible install" >&5
+$as_echo_n "checking for a BSD-compatible install... " >&6; }
+if test -z "$INSTALL"; then
+if test "${ac_cv_path_install+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  # Account for people who put trailing slashes in PATH elements.
+case $as_dir/ in
+  ./ | .// | /cC/* | \
+  /etc/* | /usr/sbin/* | /usr/etc/* | /sbin/* | /usr/afsws/bin/* | \
+  ?:\\/os2\\/install\\/* | ?:\\/OS2\\/INSTALL\\/* | \
+  /usr/ucb/* ) ;;
+  *)
+    # OSF1 and SCO ODT 3.0 have their own names for install.
+    # Don't use installbsd from OSF since it installs stuff as root
+    # by default.
+    for ac_prog in ginstall scoinst install; do
+      for ac_exec_ext in '' $ac_executable_extensions; do
+	if { test -f "$as_dir/$ac_prog$ac_exec_ext" && $as_test_x "$as_dir/$ac_prog$ac_exec_ext"; }; then
+	  if test $ac_prog = install &&
+	    grep dspmsg "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then
+	    # AIX install.  It has an incompatible calling convention.
+	    :
+	  elif test $ac_prog = install &&
+	    grep pwplus "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then
+	    # program-specific install script used by HP pwplus--don't use.
+	    :
+	  else
+	    rm -rf conftest.one conftest.two conftest.dir
+	    echo one > conftest.one
+	    echo two > conftest.two
+	    mkdir conftest.dir
+	    if "$as_dir/$ac_prog$ac_exec_ext" -c conftest.one conftest.two "`pwd`/conftest.dir" &&
+	      test -s conftest.one && test -s conftest.two &&
+	      test -s conftest.dir/conftest.one &&
+	      test -s conftest.dir/conftest.two
+	    then
+	      ac_cv_path_install="$as_dir/$ac_prog$ac_exec_ext -c"
+	      break 3
+	    fi
+	  fi
+	fi
+      done
+    done
+    ;;
+esac
+
+done
+IFS=$as_save_IFS
+
+rm -rf conftest.one conftest.two conftest.dir
+
+fi
+  if test "${ac_cv_path_install+set}" = set; then
+    INSTALL=$ac_cv_path_install
+  else
+    # As a last resort, use the slow shell script.  Don't cache a
+    # value for INSTALL within a source directory, because that will
+    # break other packages using the cache if that directory is
+    # removed, or if the value is a relative name.
+    INSTALL=$ac_install_sh
+  fi
+fi
+{ $as_echo "$as_me:$LINENO: result: $INSTALL" >&5
+$as_echo "$INSTALL" >&6; }
+
+# Use test -z because SunOS4 sh mishandles braces in ${var-val}.
+# It thinks the first close brace ends the variable substitution.
+test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}'
+
+test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL}'
+
+test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644'
+
+{ $as_echo "$as_me:$LINENO: checking whether build environment is sane" >&5
+$as_echo_n "checking whether build environment is sane... " >&6; }
+# Just in case
+sleep 1
+echo timestamp > conftest.file
+# Reject unsafe characters in $srcdir or the absolute working directory
+# name.  Accept space and tab only in the latter.
+am_lf='
+'
+case `pwd` in
+  *[\\\"\#\$\&\'\`$am_lf]*)
+    { { $as_echo "$as_me:$LINENO: error: unsafe absolute working directory name" >&5
+$as_echo "$as_me: error: unsafe absolute working directory name" >&2;}
+   { (exit 1); exit 1; }; };;
+esac
+case $srcdir in
+  *[\\\"\#\$\&\'\`$am_lf\ \	]*)
+    { { $as_echo "$as_me:$LINENO: error: unsafe srcdir value: \`$srcdir'" >&5
+$as_echo "$as_me: error: unsafe srcdir value: \`$srcdir'" >&2;}
+   { (exit 1); exit 1; }; };;
+esac
+
+# Do `set' in a subshell so we don't clobber the current shell's
+# arguments.  Must try -L first in case configure is actually a
+# symlink; some systems play weird games with the mod time of symlinks
+# (eg FreeBSD returns the mod time of the symlink's containing
+# directory).
+if (
+   set X `ls -Lt "$srcdir/configure" conftest.file 2> /dev/null`
+   if test "$*" = "X"; then
+      # -L didn't work.
+      set X `ls -t "$srcdir/configure" conftest.file`
+   fi
+   rm -f conftest.file
+   if test "$*" != "X $srcdir/configure conftest.file" \
+      && test "$*" != "X conftest.file $srcdir/configure"; then
+
+      # If neither matched, then we have a broken ls.  This can happen
+      # if, for instance, CONFIG_SHELL is bash and it inherits a
+      # broken ls alias from the environment.  This has actually
+      # happened.  Such a system could not be considered "sane".
+      { { $as_echo "$as_me:$LINENO: error: ls -t appears to fail.  Make sure there is not a broken
+alias in your environment" >&5
+$as_echo "$as_me: error: ls -t appears to fail.  Make sure there is not a broken
+alias in your environment" >&2;}
+   { (exit 1); exit 1; }; }
+   fi
+
+   test "$2" = conftest.file
+   )
+then
+   # Ok.
+   :
+else
+   { { $as_echo "$as_me:$LINENO: error: newly created file is older than distributed files!
+Check your system clock" >&5
+$as_echo "$as_me: error: newly created file is older than distributed files!
+Check your system clock" >&2;}
+   { (exit 1); exit 1; }; }
+fi
+{ $as_echo "$as_me:$LINENO: result: yes" >&5
+$as_echo "yes" >&6; }
+test "$program_prefix" != NONE &&
+  program_transform_name="s&^&$program_prefix&;$program_transform_name"
+# Use a double $ so make ignores it.
+test "$program_suffix" != NONE &&
+  program_transform_name="s&\$&$program_suffix&;$program_transform_name"
+# Double any \ or $.
+# By default was `s,x,x', remove it if useless.
+ac_script='s/[\\$]/&&/g;s/;s,x,x,$//'
+program_transform_name=`$as_echo "$program_transform_name" | sed "$ac_script"`
+
+# expand $ac_aux_dir to an absolute path
+am_aux_dir=`cd $ac_aux_dir && pwd`
+
+if test x"${MISSING+set}" != xset; then
+  case $am_aux_dir in
+  *\ * | *\	*)
+    MISSING="\${SHELL} \"$am_aux_dir/missing\"" ;;
+  *)
+    MISSING="\${SHELL} $am_aux_dir/missing" ;;
+  esac
+fi
+# Use eval to expand $SHELL
+if eval "$MISSING --run true"; then
+  am_missing_run="$MISSING --run "
+else
+  am_missing_run=
+  { $as_echo "$as_me:$LINENO: WARNING: \`missing' script is too old or missing" >&5
+$as_echo "$as_me: WARNING: \`missing' script is too old or missing" >&2;}
+fi
+
+if test x"${install_sh}" != xset; then
+  case $am_aux_dir in
+  *\ * | *\	*)
+    install_sh="\${SHELL} '$am_aux_dir/install-sh'" ;;
+  *)
+    install_sh="\${SHELL} $am_aux_dir/install-sh"
+  esac
+fi
+
+# Installed binaries are usually stripped using `strip' when the user
+# run `make install-strip'.  However `strip' might not be the right
+# tool to use in cross-compilation environments, therefore Automake
+# will honor the `STRIP' environment variable to overrule this program.
+if test "$cross_compiling" != no; then
+  if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}strip", so it can be a program name with args.
+set dummy ${ac_tool_prefix}strip; ac_word=$2
+{ $as_echo "$as_me:$LINENO: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_STRIP+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$STRIP"; then
+  ac_cv_prog_STRIP="$STRIP" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_STRIP="${ac_tool_prefix}strip"
+    $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+IFS=$as_save_IFS
+
+fi
+fi
+STRIP=$ac_cv_prog_STRIP
+if test -n "$STRIP"; then
+  { $as_echo "$as_me:$LINENO: result: $STRIP" >&5
+$as_echo "$STRIP" >&6; }
+else
+  { $as_echo "$as_me:$LINENO: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_STRIP"; then
+  ac_ct_STRIP=$STRIP
+  # Extract the first word of "strip", so it can be a program name with args.
+set dummy strip; ac_word=$2
+{ $as_echo "$as_me:$LINENO: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_ac_ct_STRIP+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_STRIP"; then
+  ac_cv_prog_ac_ct_STRIP="$ac_ct_STRIP" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_ac_ct_STRIP="strip"
+    $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_STRIP=$ac_cv_prog_ac_ct_STRIP
+if test -n "$ac_ct_STRIP"; then
+  { $as_echo "$as_me:$LINENO: result: $ac_ct_STRIP" >&5
+$as_echo "$ac_ct_STRIP" >&6; }
+else
+  { $as_echo "$as_me:$LINENO: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_ct_STRIP" = x; then
+    STRIP=":"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:$LINENO: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    STRIP=$ac_ct_STRIP
+  fi
+else
+  STRIP="$ac_cv_prog_STRIP"
+fi
+
+fi
+INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s"
+
+{ $as_echo "$as_me:$LINENO: checking for a thread-safe mkdir -p" >&5
+$as_echo_n "checking for a thread-safe mkdir -p... " >&6; }
+if test -z "$MKDIR_P"; then
+  if test "${ac_cv_path_mkdir+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH$PATH_SEPARATOR/opt/sfw/bin
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for ac_prog in mkdir gmkdir; do
+	 for ac_exec_ext in '' $ac_executable_extensions; do
+	   { test -f "$as_dir/$ac_prog$ac_exec_ext" && $as_test_x "$as_dir/$ac_prog$ac_exec_ext"; } || continue
+	   case `"$as_dir/$ac_prog$ac_exec_ext" --version 2>&1` in #(
+	     'mkdir (GNU coreutils) '* | \
+	     'mkdir (coreutils) '* | \
+	     'mkdir (fileutils) '4.1*)
+	       ac_cv_path_mkdir=$as_dir/$ac_prog$ac_exec_ext
+	       break 3;;
+	   esac
+	 done
+       done
+done
+IFS=$as_save_IFS
+
+fi
+
+  if test "${ac_cv_path_mkdir+set}" = set; then
+    MKDIR_P="$ac_cv_path_mkdir -p"
+  else
+    # As a last resort, use the slow shell script.  Don't cache a
+    # value for MKDIR_P within a source directory, because that will
+    # break other packages using the cache if that directory is
+    # removed, or if the value is a relative name.
+    test -d ./--version && rmdir ./--version
+    MKDIR_P="$ac_install_sh -d"
+  fi
+fi
+{ $as_echo "$as_me:$LINENO: result: $MKDIR_P" >&5
+$as_echo "$MKDIR_P" >&6; }
+
+mkdir_p="$MKDIR_P"
+case $mkdir_p in
+  [\\/$]* | ?:[\\/]*) ;;
+  */*) mkdir_p="\$(top_builddir)/$mkdir_p" ;;
+esac
+
+for ac_prog in gawk mawk nawk awk
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ $as_echo "$as_me:$LINENO: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_AWK+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$AWK"; then
+  ac_cv_prog_AWK="$AWK" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_AWK="$ac_prog"
+    $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+IFS=$as_save_IFS
+
+fi
+fi
+AWK=$ac_cv_prog_AWK
+if test -n "$AWK"; then
+  { $as_echo "$as_me:$LINENO: result: $AWK" >&5
+$as_echo "$AWK" >&6; }
+else
+  { $as_echo "$as_me:$LINENO: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  test -n "$AWK" && break
+done
+
+{ $as_echo "$as_me:$LINENO: checking whether ${MAKE-make} sets \$(MAKE)" >&5
+$as_echo_n "checking whether ${MAKE-make} sets \$(MAKE)... " >&6; }
+set x ${MAKE-make}
+ac_make=`$as_echo "$2" | sed 's/+/p/g; s/[^a-zA-Z0-9_]/_/g'`
+if { as_var=ac_cv_prog_make_${ac_make}_set; eval "test \"\${$as_var+set}\" = set"; }; then
+  $as_echo_n "(cached) " >&6
+else
+  cat >conftest.make <<\_ACEOF
+SHELL = /bin/sh
+all:
+	@echo '@@@%%%=$(MAKE)=@@@%%%'
+_ACEOF
+# GNU make sometimes prints "make[1]: Entering...", which would confuse us.
+case `${MAKE-make} -f conftest.make 2>/dev/null` in
+  *@@@%%%=?*=@@@%%%*)
+    eval ac_cv_prog_make_${ac_make}_set=yes;;
+  *)
+    eval ac_cv_prog_make_${ac_make}_set=no;;
+esac
+rm -f conftest.make
+fi
+if eval test \$ac_cv_prog_make_${ac_make}_set = yes; then
+  { $as_echo "$as_me:$LINENO: result: yes" >&5
+$as_echo "yes" >&6; }
+  SET_MAKE=
+else
+  { $as_echo "$as_me:$LINENO: result: no" >&5
+$as_echo "no" >&6; }
+  SET_MAKE="MAKE=${MAKE-make}"
+fi
+
+rm -rf .tst 2>/dev/null
+mkdir .tst 2>/dev/null
+if test -d .tst; then
+  am__leading_dot=.
+else
+  am__leading_dot=_
+fi
+rmdir .tst 2>/dev/null
+
+if test "`cd $srcdir && pwd`" != "`pwd`"; then
+  # Use -I$(srcdir) only when $(srcdir) != ., so that make's output
+  # is not polluted with repeated "-I."
+  am__isrc=' -I$(srcdir)'
+  # test to see if srcdir already configured
+  if test -f $srcdir/config.status; then
+    { { $as_echo "$as_me:$LINENO: error: source directory already configured; run \"make distclean\" there first" >&5
+$as_echo "$as_me: error: source directory already configured; run \"make distclean\" there first" >&2;}
+   { (exit 1); exit 1; }; }
+  fi
+fi
+
+# test whether we have cygpath
+if test -z "$CYGPATH_W"; then
+  if (cygpath --version) >/dev/null 2>/dev/null; then
+    CYGPATH_W='cygpath -w'
+  else
+    CYGPATH_W=echo
+  fi
+fi
+
+
+# Define the identity of the package.
+ PACKAGE='sinfo'
+ VERSION='2.3.2'
+
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE "$PACKAGE"
+_ACEOF
+
+
+cat >>confdefs.h <<_ACEOF
+#define VERSION "$VERSION"
+_ACEOF
+
+# Some tools Automake needs.
+
+ACLOCAL=${ACLOCAL-"${am_missing_run}aclocal-${am__api_version}"}
+
+
+AUTOCONF=${AUTOCONF-"${am_missing_run}autoconf"}
+
+
+AUTOMAKE=${AUTOMAKE-"${am_missing_run}automake-${am__api_version}"}
+
+
+AUTOHEADER=${AUTOHEADER-"${am_missing_run}autoheader"}
+
+
+MAKEINFO=${MAKEINFO-"${am_missing_run}makeinfo"}
+
+# We need awk for the "check" target.  The system "awk" is bad on
+# some platforms.
+# Always define AMTAR for backward compatibility.
+
+AMTAR=${AMTAR-"${am_missing_run}tar"}
+
+am__tar='${AMTAR} chof - "$$tardir"'; am__untar='${AMTAR} xf -'
+
+
+
+
+
+ac_config_headers="$ac_config_headers config.h"
+
+
+
+{ $as_echo "$as_me:$LINENO: checking whether to enable maintainer-specific portions of Makefiles" >&5
+$as_echo_n "checking whether to enable maintainer-specific portions of Makefiles... " >&6; }
+    # Check whether --enable-maintainer-mode was given.
+if test "${enable_maintainer_mode+set}" = set; then
+  enableval=$enable_maintainer_mode; USE_MAINTAINER_MODE=$enableval
+else
+  USE_MAINTAINER_MODE=no
+fi
+
+  { $as_echo "$as_me:$LINENO: result: $USE_MAINTAINER_MODE" >&5
+$as_echo "$USE_MAINTAINER_MODE" >&6; }
+   if test $USE_MAINTAINER_MODE = yes; then
+  MAINTAINER_MODE_TRUE=
+  MAINTAINER_MODE_FALSE='#'
+else
+  MAINTAINER_MODE_TRUE='#'
+  MAINTAINER_MODE_FALSE=
+fi
+
+  MAINT=$MAINTAINER_MODE_TRUE
+
+
+
+
+    unset CDPATH
+    # make $PIPE_HOME the default for the installation
+
+
+    if test "x$prefix" = "xNONE"; then
+        prefix=$ac_default_prefix
+        ac_configure_args="$ac_configure_args --prefix $prefix"
+    fi
+
+    if test "x$exec_prefix" = "xNONE"; then
+        exec_prefix=$prefix
+    fi
+
+
+
+# Immediately before every release do:
+#-------------------------------------
+#   if (the interface is totally unchanged from previous release)
+#       REVISION++;
+#   else {
+#       /* interfaces have been added, removed or changed */
+#       REVISION = 0;
+#       CURRENT++;
+#       if (any interfaces have been _added_ since last release)
+#           AGE++;
+#       if (any interfaces have been _removed_ or incompatibly changed)
+#           AGE = 0;
+#   }
+
+
+    sinfoni_version=`echo "$VERSION" | sed -e 's/[a-z,A-Z].*$//'`
+
+    sinfoni_major_version=`echo "$sinfoni_version" | \
+        sed 's/\([0-9]*\).\(.*\)/\1/'`
+    sinfoni_minor_version=`echo "$sinfoni_version" | \
+        sed 's/\([0-9]*\).\([0-9]*\)\(.*\)/\2/'`
+    sinfoni_micro_version=`echo "$sinfoni_version" | \
+        sed 's/\([0-9]*\).\([0-9]*\).\([0-9]*\)/\3/'`
+
+    if test -z "$sinfoni_major_version"; then
+        sinfoni_major_version=0
+    fi
+
+    if test -z "$sinfoni_minor_version"; then
+        sinfoni_minor_version=0
+    fi
+
+    if test -z "$sinfoni_micro_version"; then
+        sinfoni_micro_version=0
+    fi
+
+    SINFONI_VERSION="$sinfoni_version"
+    SINFONI_MAJOR_VERSION=$sinfoni_major_version
+    SINFONI_MINOR_VERSION=$sinfoni_minor_version
+    SINFONI_MICRO_VERSION=$sinfoni_micro_version
+
+    if test -z ""; then
+        SINFONI_INTERFACE_AGE=0
+    else
+        SINFONI_INTERFACE_AGE=""
+    fi
+
+    SINFONI_BINARY_AGE=`expr 100 '*' $SINFONI_MINOR_VERSION + $SINFONI_MICRO_VERSION`
+    SINFONI_BINARY_VERSION=`expr 10000 '*' $SINFONI_MAJOR_VERSION + \
+                          $SINFONI_BINARY_AGE`
+
+
+
+
+
+
+
+
+
+
+cat >>confdefs.h <<_ACEOF
+#define SINFONI_MAJOR_VERSION $SINFONI_MAJOR_VERSION
+_ACEOF
+
+
+cat >>confdefs.h <<_ACEOF
+#define SINFONI_MINOR_VERSION $SINFONI_MINOR_VERSION
+_ACEOF
+
+
+cat >>confdefs.h <<_ACEOF
+#define SINFONI_MICRO_VERSION $SINFONI_MICRO_VERSION
+_ACEOF
+
+
+cat >>confdefs.h <<_ACEOF
+#define SINFONI_INTERFACE_AGE $SINFONI_INTERFACE_AGE
+_ACEOF
+
+
+cat >>confdefs.h <<_ACEOF
+#define SINFONI_BINARY_VERSION $SINFONI_BINARY_VERSION
+_ACEOF
+
+
+cat >>confdefs.h <<_ACEOF
+#define SINFONI_BINARY_AGE $SINFONI_BINARY_AGE
+_ACEOF
+
+
+
+
+    if test -z ""; then
+        LT_CURRENT=0
+    else
+        LT_CURRENT=""
+    fi
+
+    if test -z ""; then
+        LT_REVISION=0
+    else
+        LT_REVISION=""
+    fi
+
+    if test -z ""; then
+        LT_AGE=0
+    else
+        LT_AGE=""
+    fi
+
+
+
+
+
+
+
+# Checks for programs.
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args.
+set dummy ${ac_tool_prefix}gcc; ac_word=$2
+{ $as_echo "$as_me:$LINENO: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_CC+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$CC"; then
+  ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_CC="${ac_tool_prefix}gcc"
+    $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+IFS=$as_save_IFS
+
+fi
+fi
+CC=$ac_cv_prog_CC
+if test -n "$CC"; then
+  { $as_echo "$as_me:$LINENO: result: $CC" >&5
+$as_echo "$CC" >&6; }
+else
+  { $as_echo "$as_me:$LINENO: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_CC"; then
+  ac_ct_CC=$CC
+  # Extract the first word of "gcc", so it can be a program name with args.
+set dummy gcc; ac_word=$2
+{ $as_echo "$as_me:$LINENO: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_ac_ct_CC+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_CC"; then
+  ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_ac_ct_CC="gcc"
+    $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_CC=$ac_cv_prog_ac_ct_CC
+if test -n "$ac_ct_CC"; then
+  { $as_echo "$as_me:$LINENO: result: $ac_ct_CC" >&5
+$as_echo "$ac_ct_CC" >&6; }
+else
+  { $as_echo "$as_me:$LINENO: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_ct_CC" = x; then
+    CC=""
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:$LINENO: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    CC=$ac_ct_CC
+  fi
+else
+  CC="$ac_cv_prog_CC"
+fi
+
+if test -z "$CC"; then
+          if test -n "$ac_tool_prefix"; then
+    # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args.
+set dummy ${ac_tool_prefix}cc; ac_word=$2
+{ $as_echo "$as_me:$LINENO: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_CC+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$CC"; then
+  ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_CC="${ac_tool_prefix}cc"
+    $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+IFS=$as_save_IFS
+
+fi
+fi
+CC=$ac_cv_prog_CC
+if test -n "$CC"; then
+  { $as_echo "$as_me:$LINENO: result: $CC" >&5
+$as_echo "$CC" >&6; }
+else
+  { $as_echo "$as_me:$LINENO: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  fi
+fi
+if test -z "$CC"; then
+  # Extract the first word of "cc", so it can be a program name with args.
+set dummy cc; ac_word=$2
+{ $as_echo "$as_me:$LINENO: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_CC+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$CC"; then
+  ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+  ac_prog_rejected=no
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then
+       ac_prog_rejected=yes
+       continue
+     fi
+    ac_cv_prog_CC="cc"
+    $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+IFS=$as_save_IFS
+
+if test $ac_prog_rejected = yes; then
+  # We found a bogon in the path, so make sure we never use it.
+  set dummy $ac_cv_prog_CC
+  shift
+  if test $# != 0; then
+    # We chose a different compiler from the bogus one.
+    # However, it has the same basename, so the bogon will be chosen
+    # first if we set CC to just the basename; use the full file name.
+    shift
+    ac_cv_prog_CC="$as_dir/$ac_word${1+' '}$@"
+  fi
+fi
+fi
+fi
+CC=$ac_cv_prog_CC
+if test -n "$CC"; then
+  { $as_echo "$as_me:$LINENO: result: $CC" >&5
+$as_echo "$CC" >&6; }
+else
+  { $as_echo "$as_me:$LINENO: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$CC"; then
+  if test -n "$ac_tool_prefix"; then
+  for ac_prog in cl.exe
+  do
+    # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args.
+set dummy $ac_tool_prefix$ac_prog; ac_word=$2
+{ $as_echo "$as_me:$LINENO: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_CC+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$CC"; then
+  ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_CC="$ac_tool_prefix$ac_prog"
+    $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+IFS=$as_save_IFS
+
+fi
+fi
+CC=$ac_cv_prog_CC
+if test -n "$CC"; then
+  { $as_echo "$as_me:$LINENO: result: $CC" >&5
+$as_echo "$CC" >&6; }
+else
+  { $as_echo "$as_me:$LINENO: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+    test -n "$CC" && break
+  done
+fi
+if test -z "$CC"; then
+  ac_ct_CC=$CC
+  for ac_prog in cl.exe
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ $as_echo "$as_me:$LINENO: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_ac_ct_CC+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_CC"; then
+  ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_ac_ct_CC="$ac_prog"
+    $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_CC=$ac_cv_prog_ac_ct_CC
+if test -n "$ac_ct_CC"; then
+  { $as_echo "$as_me:$LINENO: result: $ac_ct_CC" >&5
+$as_echo "$ac_ct_CC" >&6; }
+else
+  { $as_echo "$as_me:$LINENO: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  test -n "$ac_ct_CC" && break
+done
+
+  if test "x$ac_ct_CC" = x; then
+    CC=""
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:$LINENO: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    CC=$ac_ct_CC
+  fi
+fi
+
+fi
+
+
+test -z "$CC" && { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+{ { $as_echo "$as_me:$LINENO: error: no acceptable C compiler found in \$PATH
+See \`config.log' for more details." >&5
+$as_echo "$as_me: error: no acceptable C compiler found in \$PATH
+See \`config.log' for more details." >&2;}
+   { (exit 1); exit 1; }; }; }
+
+# Provide some information about the compiler.
+$as_echo "$as_me:$LINENO: checking for C compiler version" >&5
+set X $ac_compile
+ac_compiler=$2
+{ (ac_try="$ac_compiler --version >&5"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_compiler --version >&5") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }
+{ (ac_try="$ac_compiler -v >&5"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_compiler -v >&5") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }
+{ (ac_try="$ac_compiler -V >&5"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_compiler -V >&5") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }
+
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+ac_clean_files_save=$ac_clean_files
+ac_clean_files="$ac_clean_files a.out a.out.dSYM a.exe b.out"
+# Try to create an executable without -o first, disregard a.out.
+# It will help us diagnose broken compilers, and finding out an intuition
+# of exeext.
+{ $as_echo "$as_me:$LINENO: checking for C compiler default output file name" >&5
+$as_echo_n "checking for C compiler default output file name... " >&6; }
+ac_link_default=`$as_echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'`
+
+# The possible output files:
+ac_files="a.out conftest.exe conftest a.exe a_out.exe b.out conftest.*"
+
+ac_rmfiles=
+for ac_file in $ac_files
+do
+  case $ac_file in
+    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;;
+    * ) ac_rmfiles="$ac_rmfiles $ac_file";;
+  esac
+done
+rm -f $ac_rmfiles
+
+if { (ac_try="$ac_link_default"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_link_default") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; then
+  # Autoconf-2.13 could set the ac_cv_exeext variable to `no'.
+# So ignore a value of `no', otherwise this would lead to `EXEEXT = no'
+# in a Makefile.  We should not override ac_cv_exeext if it was cached,
+# so that the user can short-circuit this test for compilers unknown to
+# Autoconf.
+for ac_file in $ac_files ''
+do
+  test -f "$ac_file" || continue
+  case $ac_file in
+    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj )
+	;;
+    [ab].out )
+	# We found the default executable, but exeext='' is most
+	# certainly right.
+	break;;
+    *.* )
+        if test "${ac_cv_exeext+set}" = set && test "$ac_cv_exeext" != no;
+	then :; else
+	   ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'`
+	fi
+	# We set ac_cv_exeext here because the later test for it is not
+	# safe: cross compilers may not add the suffix if given an `-o'
+	# argument, so we may need to know it at that point already.
+	# Even if this section looks crufty: it has the advantage of
+	# actually working.
+	break;;
+    * )
+	break;;
+  esac
+done
+test "$ac_cv_exeext" = no && ac_cv_exeext=
+
+else
+  ac_file=''
+fi
+
+{ $as_echo "$as_me:$LINENO: result: $ac_file" >&5
+$as_echo "$ac_file" >&6; }
+if test -z "$ac_file"; then
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+{ { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+{ { $as_echo "$as_me:$LINENO: error: C compiler cannot create executables
+See \`config.log' for more details." >&5
+$as_echo "$as_me: error: C compiler cannot create executables
+See \`config.log' for more details." >&2;}
+   { (exit 77); exit 77; }; }; }
+fi
+
+ac_exeext=$ac_cv_exeext
+
+# Check that the compiler produces executables we can run.  If not, either
+# the compiler is broken, or we cross compile.
+{ $as_echo "$as_me:$LINENO: checking whether the C compiler works" >&5
+$as_echo_n "checking whether the C compiler works... " >&6; }
+# FIXME: These cross compiler hacks should be removed for Autoconf 3.0
+# If not cross compiling, check that we can run a simple program.
+if test "$cross_compiling" != yes; then
+  if { ac_try='./$ac_file'
+  { (case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_try") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+    cross_compiling=no
+  else
+    if test "$cross_compiling" = maybe; then
+	cross_compiling=yes
+    else
+	{ { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+{ { $as_echo "$as_me:$LINENO: error: cannot run C compiled programs.
+If you meant to cross compile, use \`--host'.
+See \`config.log' for more details." >&5
+$as_echo "$as_me: error: cannot run C compiled programs.
+If you meant to cross compile, use \`--host'.
+See \`config.log' for more details." >&2;}
+   { (exit 1); exit 1; }; }; }
+    fi
+  fi
+fi
+{ $as_echo "$as_me:$LINENO: result: yes" >&5
+$as_echo "yes" >&6; }
+
+rm -f -r a.out a.out.dSYM a.exe conftest$ac_cv_exeext b.out
+ac_clean_files=$ac_clean_files_save
+# Check that the compiler produces executables we can run.  If not, either
+# the compiler is broken, or we cross compile.
+{ $as_echo "$as_me:$LINENO: checking whether we are cross compiling" >&5
+$as_echo_n "checking whether we are cross compiling... " >&6; }
+{ $as_echo "$as_me:$LINENO: result: $cross_compiling" >&5
+$as_echo "$cross_compiling" >&6; }
+
+{ $as_echo "$as_me:$LINENO: checking for suffix of executables" >&5
+$as_echo_n "checking for suffix of executables... " >&6; }
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_link") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; then
+  # If both `conftest.exe' and `conftest' are `present' (well, observable)
+# catch `conftest.exe'.  For instance with Cygwin, `ls conftest' will
+# work properly (i.e., refer to `conftest.exe'), while it won't with
+# `rm'.
+for ac_file in conftest.exe conftest conftest.*; do
+  test -f "$ac_file" || continue
+  case $ac_file in
+    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;;
+    *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'`
+	  break;;
+    * ) break;;
+  esac
+done
+else
+  { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+{ { $as_echo "$as_me:$LINENO: error: cannot compute suffix of executables: cannot compile and link
+See \`config.log' for more details." >&5
+$as_echo "$as_me: error: cannot compute suffix of executables: cannot compile and link
+See \`config.log' for more details." >&2;}
+   { (exit 1); exit 1; }; }; }
+fi
+
+rm -f conftest$ac_cv_exeext
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_exeext" >&5
+$as_echo "$ac_cv_exeext" >&6; }
+
+rm -f conftest.$ac_ext
+EXEEXT=$ac_cv_exeext
+ac_exeext=$EXEEXT
+{ $as_echo "$as_me:$LINENO: checking for suffix of object files" >&5
+$as_echo_n "checking for suffix of object files... " >&6; }
+if test "${ac_cv_objext+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.o conftest.obj
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_compile") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; then
+  for ac_file in conftest.o conftest.obj conftest.*; do
+  test -f "$ac_file" || continue;
+  case $ac_file in
+    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM ) ;;
+    *) ac_cv_objext=`expr "$ac_file" : '.*\.\(.*\)'`
+       break;;
+  esac
+done
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+{ { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+{ { $as_echo "$as_me:$LINENO: error: cannot compute suffix of object files: cannot compile
+See \`config.log' for more details." >&5
+$as_echo "$as_me: error: cannot compute suffix of object files: cannot compile
+See \`config.log' for more details." >&2;}
+   { (exit 1); exit 1; }; }; }
+fi
+
+rm -f conftest.$ac_cv_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_objext" >&5
+$as_echo "$ac_cv_objext" >&6; }
+OBJEXT=$ac_cv_objext
+ac_objext=$OBJEXT
+{ $as_echo "$as_me:$LINENO: checking whether we are using the GNU C compiler" >&5
+$as_echo_n "checking whether we are using the GNU C compiler... " >&6; }
+if test "${ac_cv_c_compiler_gnu+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+int
+main ()
+{
+#ifndef __GNUC__
+       choke me
+#endif
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  ac_compiler_gnu=yes
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_compiler_gnu=no
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+ac_cv_c_compiler_gnu=$ac_compiler_gnu
+
+fi
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_c_compiler_gnu" >&5
+$as_echo "$ac_cv_c_compiler_gnu" >&6; }
+if test $ac_compiler_gnu = yes; then
+  GCC=yes
+else
+  GCC=
+fi
+ac_test_CFLAGS=${CFLAGS+set}
+ac_save_CFLAGS=$CFLAGS
+{ $as_echo "$as_me:$LINENO: checking whether $CC accepts -g" >&5
+$as_echo_n "checking whether $CC accepts -g... " >&6; }
+if test "${ac_cv_prog_cc_g+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  ac_save_c_werror_flag=$ac_c_werror_flag
+   ac_c_werror_flag=yes
+   ac_cv_prog_cc_g=no
+   CFLAGS="-g"
+   cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  ac_cv_prog_cc_g=yes
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	CFLAGS=""
+      cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  :
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_c_werror_flag=$ac_save_c_werror_flag
+	 CFLAGS="-g"
+	 cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  ac_cv_prog_cc_g=yes
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+   ac_c_werror_flag=$ac_save_c_werror_flag
+fi
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_prog_cc_g" >&5
+$as_echo "$ac_cv_prog_cc_g" >&6; }
+if test "$ac_test_CFLAGS" = set; then
+  CFLAGS=$ac_save_CFLAGS
+elif test $ac_cv_prog_cc_g = yes; then
+  if test "$GCC" = yes; then
+    CFLAGS="-g -O2"
+  else
+    CFLAGS="-g"
+  fi
+else
+  if test "$GCC" = yes; then
+    CFLAGS="-O2"
+  else
+    CFLAGS=
+  fi
+fi
+{ $as_echo "$as_me:$LINENO: checking for $CC option to accept ISO C89" >&5
+$as_echo_n "checking for $CC option to accept ISO C89... " >&6; }
+if test "${ac_cv_prog_cc_c89+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  ac_cv_prog_cc_c89=no
+ac_save_CC=$CC
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <stdarg.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+/* Most of the following tests are stolen from RCS 5.7's src/conf.sh.  */
+struct buf { int x; };
+FILE * (*rcsopen) (struct buf *, struct stat *, int);
+static char *e (p, i)
+     char **p;
+     int i;
+{
+  return p[i];
+}
+static char *f (char * (*g) (char **, int), char **p, ...)
+{
+  char *s;
+  va_list v;
+  va_start (v,p);
+  s = g (p, va_arg (v,int));
+  va_end (v);
+  return s;
+}
+
+/* OSF 4.0 Compaq cc is some sort of almost-ANSI by default.  It has
+   function prototypes and stuff, but not '\xHH' hex character constants.
+   These don't provoke an error unfortunately, instead are silently treated
+   as 'x'.  The following induces an error, until -std is added to get
+   proper ANSI mode.  Curiously '\x00'!='x' always comes out true, for an
+   array size at least.  It's necessary to write '\x00'==0 to get something
+   that's true only with -std.  */
+int osf4_cc_array ['\x00' == 0 ? 1 : -1];
+
+/* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters
+   inside strings and character constants.  */
+#define FOO(x) 'x'
+int xlc6_cc_array[FOO(a) == 'x' ? 1 : -1];
+
+int test (int i, double x);
+struct s1 {int (*f) (int a);};
+struct s2 {int (*f) (double a);};
+int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int);
+int argc;
+char **argv;
+int
+main ()
+{
+return f (e, argv, 0) != argv[0]  ||  f (e, argv, 1) != argv[1];
+  ;
+  return 0;
+}
+_ACEOF
+for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std \
+	-Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__"
+do
+  CC="$ac_save_CC $ac_arg"
+  rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  ac_cv_prog_cc_c89=$ac_arg
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+
+fi
+
+rm -f core conftest.err conftest.$ac_objext
+  test "x$ac_cv_prog_cc_c89" != "xno" && break
+done
+rm -f conftest.$ac_ext
+CC=$ac_save_CC
+
+fi
+# AC_CACHE_VAL
+case "x$ac_cv_prog_cc_c89" in
+  x)
+    { $as_echo "$as_me:$LINENO: result: none needed" >&5
+$as_echo "none needed" >&6; } ;;
+  xno)
+    { $as_echo "$as_me:$LINENO: result: unsupported" >&5
+$as_echo "unsupported" >&6; } ;;
+  *)
+    CC="$CC $ac_cv_prog_cc_c89"
+    { $as_echo "$as_me:$LINENO: result: $ac_cv_prog_cc_c89" >&5
+$as_echo "$ac_cv_prog_cc_c89" >&6; } ;;
+esac
+
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+DEPDIR="${am__leading_dot}deps"
+
+ac_config_commands="$ac_config_commands depfiles"
+
+
+am_make=${MAKE-make}
+cat > confinc << 'END'
+am__doit:
+	@echo this is the am__doit target
+.PHONY: am__doit
+END
+# If we don't find an include directive, just comment out the code.
+{ $as_echo "$as_me:$LINENO: checking for style of include used by $am_make" >&5
+$as_echo_n "checking for style of include used by $am_make... " >&6; }
+am__include="#"
+am__quote=
+_am_result=none
+# First try GNU make style include.
+echo "include confinc" > confmf
+# Ignore all kinds of additional output from `make'.
+case `$am_make -s -f confmf 2> /dev/null` in #(
+*the\ am__doit\ target*)
+  am__include=include
+  am__quote=
+  _am_result=GNU
+  ;;
+esac
+# Now try BSD make style include.
+if test "$am__include" = "#"; then
+   echo '.include "confinc"' > confmf
+   case `$am_make -s -f confmf 2> /dev/null` in #(
+   *the\ am__doit\ target*)
+     am__include=.include
+     am__quote="\""
+     _am_result=BSD
+     ;;
+   esac
+fi
+
+
+{ $as_echo "$as_me:$LINENO: result: $_am_result" >&5
+$as_echo "$_am_result" >&6; }
+rm -f confinc confmf
+
+# Check whether --enable-dependency-tracking was given.
+if test "${enable_dependency_tracking+set}" = set; then
+  enableval=$enable_dependency_tracking;
+fi
+
+if test "x$enable_dependency_tracking" != xno; then
+  am_depcomp="$ac_aux_dir/depcomp"
+  AMDEPBACKSLASH='\'
+fi
+ if test "x$enable_dependency_tracking" != xno; then
+  AMDEP_TRUE=
+  AMDEP_FALSE='#'
+else
+  AMDEP_TRUE='#'
+  AMDEP_FALSE=
+fi
+
+
+
+depcc="$CC"   am_compiler_list=
+
+{ $as_echo "$as_me:$LINENO: checking dependency style of $depcc" >&5
+$as_echo_n "checking dependency style of $depcc... " >&6; }
+if test "${am_cv_CC_dependencies_compiler_type+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  if test -z "$AMDEP_TRUE" && test -f "$am_depcomp"; then
+  # We make a subdir and do the tests there.  Otherwise we can end up
+  # making bogus files that we don't know about and never remove.  For
+  # instance it was reported that on HP-UX the gcc test will end up
+  # making a dummy file named `D' -- because `-MD' means `put the output
+  # in D'.
+  mkdir conftest.dir
+  # Copy depcomp to subdir because otherwise we won't find it if we're
+  # using a relative directory.
+  cp "$am_depcomp" conftest.dir
+  cd conftest.dir
+  # We will build objects and dependencies in a subdirectory because
+  # it helps to detect inapplicable dependency modes.  For instance
+  # both Tru64's cc and ICC support -MD to output dependencies as a
+  # side effect of compilation, but ICC will put the dependencies in
+  # the current directory while Tru64 will put them in the object
+  # directory.
+  mkdir sub
+
+  am_cv_CC_dependencies_compiler_type=none
+  if test "$am_compiler_list" = ""; then
+     am_compiler_list=`sed -n 's/^#*\([a-zA-Z0-9]*\))$/\1/p' < ./depcomp`
+  fi
+  am__universal=false
+  case " $depcc " in #(
+     *\ -arch\ *\ -arch\ *) am__universal=true ;;
+     esac
+
+  for depmode in $am_compiler_list; do
+    # Setup a source with many dependencies, because some compilers
+    # like to wrap large dependency lists on column 80 (with \), and
+    # we should not choose a depcomp mode which is confused by this.
+    #
+    # We need to recreate these files for each test, as the compiler may
+    # overwrite some of them when testing with obscure command lines.
+    # This happens at least with the AIX C compiler.
+    : > sub/conftest.c
+    for i in 1 2 3 4 5 6; do
+      echo '#include "conftst'$i'.h"' >> sub/conftest.c
+      # Using `: > sub/conftst$i.h' creates only sub/conftst1.h with
+      # Solaris 8's {/usr,}/bin/sh.
+      touch sub/conftst$i.h
+    done
+    echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf
+
+    # We check with `-c' and `-o' for the sake of the "dashmstdout"
+    # mode.  It turns out that the SunPro C++ compiler does not properly
+    # handle `-M -o', and we need to detect this.  Also, some Intel
+    # versions had trouble with output in subdirs
+    am__obj=sub/conftest.${OBJEXT-o}
+    am__minus_obj="-o $am__obj"
+    case $depmode in
+    gcc)
+      # This depmode causes a compiler race in universal mode.
+      test "$am__universal" = false || continue
+      ;;
+    nosideeffect)
+      # after this tag, mechanisms are not by side-effect, so they'll
+      # only be used when explicitly requested
+      if test "x$enable_dependency_tracking" = xyes; then
+	continue
+      else
+	break
+      fi
+      ;;
+    msvisualcpp | msvcmsys)
+      # This compiler won't grok `-c -o', but also, the minuso test has
+      # not run yet.  These depmodes are late enough in the game, and
+      # so weak that their functioning should not be impacted.
+      am__obj=conftest.${OBJEXT-o}
+      am__minus_obj=
+      ;;
+    none) break ;;
+    esac
+    if depmode=$depmode \
+       source=sub/conftest.c object=$am__obj \
+       depfile=sub/conftest.Po tmpdepfile=sub/conftest.TPo \
+       $SHELL ./depcomp $depcc -c $am__minus_obj sub/conftest.c \
+         >/dev/null 2>conftest.err &&
+       grep sub/conftst1.h sub/conftest.Po > /dev/null 2>&1 &&
+       grep sub/conftst6.h sub/conftest.Po > /dev/null 2>&1 &&
+       grep $am__obj sub/conftest.Po > /dev/null 2>&1 &&
+       ${MAKE-make} -s -f confmf > /dev/null 2>&1; then
+      # icc doesn't choke on unknown options, it will just issue warnings
+      # or remarks (even with -Werror).  So we grep stderr for any message
+      # that says an option was ignored or not supported.
+      # When given -MP, icc 7.0 and 7.1 complain thusly:
+      #   icc: Command line warning: ignoring option '-M'; no argument required
+      # The diagnosis changed in icc 8.0:
+      #   icc: Command line remark: option '-MP' not supported
+      if (grep 'ignoring option' conftest.err ||
+          grep 'not supported' conftest.err) >/dev/null 2>&1; then :; else
+        am_cv_CC_dependencies_compiler_type=$depmode
+        break
+      fi
+    fi
+  done
+
+  cd ..
+  rm -rf conftest.dir
+else
+  am_cv_CC_dependencies_compiler_type=none
+fi
+
+fi
+{ $as_echo "$as_me:$LINENO: result: $am_cv_CC_dependencies_compiler_type" >&5
+$as_echo "$am_cv_CC_dependencies_compiler_type" >&6; }
+CCDEPMODE=depmode=$am_cv_CC_dependencies_compiler_type
+
+ if
+  test "x$enable_dependency_tracking" != xno \
+  && test "$am_cv_CC_dependencies_compiler_type" = gcc3; then
+  am__fastdepCC_TRUE=
+  am__fastdepCC_FALSE='#'
+else
+  am__fastdepCC_TRUE='#'
+  am__fastdepCC_FALSE=
+fi
+
+
+
+{ $as_echo "$as_me:$LINENO: checking for library containing strerror" >&5
+$as_echo_n "checking for library containing strerror... " >&6; }
+if test "${ac_cv_search_strerror+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  ac_func_search_save_LIBS=$LIBS
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char strerror ();
+int
+main ()
+{
+return strerror ();
+  ;
+  return 0;
+}
+_ACEOF
+for ac_lib in '' cposix; do
+  if test -z "$ac_lib"; then
+    ac_res="none required"
+  else
+    ac_res=-l$ac_lib
+    LIBS="-l$ac_lib  $ac_func_search_save_LIBS"
+  fi
+  rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext && {
+	 test "$cross_compiling" = yes ||
+	 $as_test_x conftest$ac_exeext
+       }; then
+  ac_cv_search_strerror=$ac_res
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+
+fi
+
+rm -rf conftest.dSYM
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext
+  if test "${ac_cv_search_strerror+set}" = set; then
+  break
+fi
+done
+if test "${ac_cv_search_strerror+set}" = set; then
+  :
+else
+  ac_cv_search_strerror=no
+fi
+rm conftest.$ac_ext
+LIBS=$ac_func_search_save_LIBS
+fi
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_search_strerror" >&5
+$as_echo "$ac_cv_search_strerror" >&6; }
+ac_res=$ac_cv_search_strerror
+if test "$ac_res" != no; then
+  test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
+
+fi
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+{ $as_echo "$as_me:$LINENO: checking how to run the C preprocessor" >&5
+$as_echo_n "checking how to run the C preprocessor... " >&6; }
+# On Suns, sometimes $CPP names a directory.
+if test -n "$CPP" && test -d "$CPP"; then
+  CPP=
+fi
+if test -z "$CPP"; then
+  if test "${ac_cv_prog_CPP+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+      # Double quotes because CPP needs to be expanded
+    for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp"
+    do
+      ac_preproc_ok=false
+for ac_c_preproc_warn_flag in '' yes
+do
+  # Use a header file that comes with gcc, so configuring glibc
+  # with a fresh cross-compiler works.
+  # Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+  # <limits.h> exists even on freestanding compilers.
+  # On the NeXT, cc -E runs the code through the compiler's parser,
+  # not just through cpp. "Syntax error" is here to catch this case.
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+		     Syntax error
+_ACEOF
+if { (ac_try="$ac_cpp conftest.$ac_ext"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } >/dev/null && {
+	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       }; then
+  :
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+  # Broken: fails on valid input.
+continue
+fi
+
+rm -f conftest.err conftest.$ac_ext
+
+  # OK, works on sane cases.  Now check whether nonexistent headers
+  # can be detected and how.
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <ac_nonexistent.h>
+_ACEOF
+if { (ac_try="$ac_cpp conftest.$ac_ext"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } >/dev/null && {
+	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       }; then
+  # Broken: success on invalid input.
+continue
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+  # Passes both tests.
+ac_preproc_ok=:
+break
+fi
+
+rm -f conftest.err conftest.$ac_ext
+
+done
+# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped.
+rm -f conftest.err conftest.$ac_ext
+if $ac_preproc_ok; then
+  break
+fi
+
+    done
+    ac_cv_prog_CPP=$CPP
+
+fi
+  CPP=$ac_cv_prog_CPP
+else
+  ac_cv_prog_CPP=$CPP
+fi
+{ $as_echo "$as_me:$LINENO: result: $CPP" >&5
+$as_echo "$CPP" >&6; }
+ac_preproc_ok=false
+for ac_c_preproc_warn_flag in '' yes
+do
+  # Use a header file that comes with gcc, so configuring glibc
+  # with a fresh cross-compiler works.
+  # Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+  # <limits.h> exists even on freestanding compilers.
+  # On the NeXT, cc -E runs the code through the compiler's parser,
+  # not just through cpp. "Syntax error" is here to catch this case.
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+		     Syntax error
+_ACEOF
+if { (ac_try="$ac_cpp conftest.$ac_ext"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } >/dev/null && {
+	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       }; then
+  :
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+  # Broken: fails on valid input.
+continue
+fi
+
+rm -f conftest.err conftest.$ac_ext
+
+  # OK, works on sane cases.  Now check whether nonexistent headers
+  # can be detected and how.
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <ac_nonexistent.h>
+_ACEOF
+if { (ac_try="$ac_cpp conftest.$ac_ext"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } >/dev/null && {
+	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       }; then
+  # Broken: success on invalid input.
+continue
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+  # Passes both tests.
+ac_preproc_ok=:
+break
+fi
+
+rm -f conftest.err conftest.$ac_ext
+
+done
+# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped.
+rm -f conftest.err conftest.$ac_ext
+if $ac_preproc_ok; then
+  :
+else
+  { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+{ { $as_echo "$as_me:$LINENO: error: C preprocessor \"$CPP\" fails sanity check
+See \`config.log' for more details." >&5
+$as_echo "$as_me: error: C preprocessor \"$CPP\" fails sanity check
+See \`config.log' for more details." >&2;}
+   { (exit 1); exit 1; }; }; }
+fi
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+if test "x$CC" != xcc; then
+  { $as_echo "$as_me:$LINENO: checking whether $CC and cc understand -c and -o together" >&5
+$as_echo_n "checking whether $CC and cc understand -c and -o together... " >&6; }
+else
+  { $as_echo "$as_me:$LINENO: checking whether cc understands -c and -o together" >&5
+$as_echo_n "checking whether cc understands -c and -o together... " >&6; }
+fi
+set dummy $CC; ac_cc=`$as_echo "$2" |
+		      sed 's/[^a-zA-Z0-9_]/_/g;s/^[0-9]/_/'`
+if { as_var=ac_cv_prog_cc_${ac_cc}_c_o; eval "test \"\${$as_var+set}\" = set"; }; then
+  $as_echo_n "(cached) " >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+# Make sure it works both with $CC and with simple cc.
+# We do the test twice because some compilers refuse to overwrite an
+# existing .o file with -o, though they will create one.
+ac_try='$CC -c conftest.$ac_ext -o conftest2.$ac_objext >&5'
+rm -f conftest2.*
+if { (case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_try") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+   test -f conftest2.$ac_objext && { (case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_try") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); };
+then
+  eval ac_cv_prog_cc_${ac_cc}_c_o=yes
+  if test "x$CC" != xcc; then
+    # Test first that cc exists at all.
+    if { ac_try='cc -c conftest.$ac_ext >&5'
+  { (case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_try") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+      ac_try='cc -c conftest.$ac_ext -o conftest2.$ac_objext >&5'
+      rm -f conftest2.*
+      if { (case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_try") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 test -f conftest2.$ac_objext && { (case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_try") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); };
+      then
+	# cc works too.
+	:
+      else
+	# cc exists but doesn't like -o.
+	eval ac_cv_prog_cc_${ac_cc}_c_o=no
+      fi
+    fi
+  fi
+else
+  eval ac_cv_prog_cc_${ac_cc}_c_o=no
+fi
+rm -f core conftest*
+
+fi
+if eval test \$ac_cv_prog_cc_${ac_cc}_c_o = yes; then
+  { $as_echo "$as_me:$LINENO: result: yes" >&5
+$as_echo "yes" >&6; }
+else
+  { $as_echo "$as_me:$LINENO: result: no" >&5
+$as_echo "no" >&6; }
+
+cat >>confdefs.h <<\_ACEOF
+#define NO_MINUS_C_MINUS_O 1
+_ACEOF
+
+fi
+
+# FIXME: we rely on the cache variable name because
+# there is no other way.
+set dummy $CC
+am_cc=`echo $2 | sed 's/[^a-zA-Z0-9_]/_/g;s/^[0-9]/_/'`
+eval am_t=\$ac_cv_prog_cc_${am_cc}_c_o
+if test "$am_t" != yes; then
+   # Losing compiler, so override with the script.
+   # FIXME: It is wrong to rewrite CC.
+   # But if we don't then we get into trouble of one sort or another.
+   # A longer-term fix would be to have automake use am__CC in this case,
+   # and then we could set am__CC="\$(top_srcdir)/compile \$(CC)"
+   CC="$am_aux_dir/compile $CC"
+fi
+
+
+{ $as_echo "$as_me:$LINENO: checking whether ln -s works" >&5
+$as_echo_n "checking whether ln -s works... " >&6; }
+LN_S=$as_ln_s
+if test "$LN_S" = "ln -s"; then
+  { $as_echo "$as_me:$LINENO: result: yes" >&5
+$as_echo "yes" >&6; }
+else
+  { $as_echo "$as_me:$LINENO: result: no, using $LN_S" >&5
+$as_echo "no, using $LN_S" >&6; }
+fi
+
+
+
+
+
+    # Check whether --enable-debug was given.
+if test "${enable_debug+set}" = set; then
+  enableval=$enable_debug; eso_enable_debug=$enableval
+else
+  eso_enable_debug=no
+fi
+
+
+    { $as_echo "$as_me:$LINENO: checking whether debugging code should be created" >&5
+$as_echo_n "checking whether debugging code should be created... " >&6; }
+if test "${eso_cv_enable_debug+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  eso_cv_enable_debug=$eso_enable_debug
+fi
+{ $as_echo "$as_me:$LINENO: result: $eso_cv_enable_debug" >&5
+$as_echo "$eso_cv_enable_debug" >&6; }
+
+    if test x"$eso_cv_enable_debug" = xyes; then
+
+        eso_clean_CFLAGS="`echo $CFLAGS | sed -e 's/-O[0-9]//g' \
+                                              -e 's/-g[0-9]//g' \
+                                              -e 's/-g[a-z,A-Z]* / /g' \
+                                              -e 's/-[Og]//g'`"
+
+
+
+
+    flag=`echo g3 | sed 'y%.=/+-%___p_%'`
+    { $as_echo "$as_me:$LINENO: checking whether $CC supports -g3" >&5
+$as_echo_n "checking whether $CC supports -g3... " >&6; }
+if { as_var=eso_cv_prog_cc_$flag; eval "test \"\${$as_var+set}\" = set"; }; then
+  $as_echo_n "(cached) " >&6
+else
+
+                       eval "eso_cv_prog_cc_$flag=no"
+                       ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+                       echo 'int main() { return 0; }' >conftest.$ac_ext
+
+                       try_compile="`$CC -g3 -c conftest.$ac_ext 2>&1`"
+                       if test -z "$try_compile"; then
+                           try_link="`$CC -g3 -o conftest$ac_exeext \
+                                    conftest.$ac_ext 2>&1`"
+                           if test -z "$try_link"; then
+                               eval "eso_cv_prog_cc_$flag=yes"
+                           fi
+                       fi
+                       rm -f conftest*
+
+                       ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+fi
+ac_res=`eval 'as_val=${'eso_cv_prog_cc_$flag'}
+		 $as_echo "$as_val"'`
+	       { $as_echo "$as_me:$LINENO: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+
+    if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then
+        :
+        CFLAGS="$CFLAGS -g3"
+    else
+        :
+
+    fi
+
+
+        if test x"$eso_cv_prog_cc_g3" = xyes; then
+            CFLAGS="-g3"
+        else
+            if test x"$ac_cv_prog_cc_g" = xyes; then
+                CFLAGS="-g"
+            else
+                CFLAGS=""
+            fi
+        fi
+
+
+
+
+    flag=`echo ggdb | sed 'y%.=/+-%___p_%'`
+    { $as_echo "$as_me:$LINENO: checking whether $CC supports -ggdb" >&5
+$as_echo_n "checking whether $CC supports -ggdb... " >&6; }
+if { as_var=eso_cv_prog_cc_$flag; eval "test \"\${$as_var+set}\" = set"; }; then
+  $as_echo_n "(cached) " >&6
+else
+
+                       eval "eso_cv_prog_cc_$flag=no"
+                       ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+                       echo 'int main() { return 0; }' >conftest.$ac_ext
+
+                       try_compile="`$CC -ggdb -c conftest.$ac_ext 2>&1`"
+                       if test -z "$try_compile"; then
+                           try_link="`$CC -ggdb -o conftest$ac_exeext \
+                                    conftest.$ac_ext 2>&1`"
+                           if test -z "$try_link"; then
+                               eval "eso_cv_prog_cc_$flag=yes"
+                           fi
+                       fi
+                       rm -f conftest*
+
+                       ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+fi
+ac_res=`eval 'as_val=${'eso_cv_prog_cc_$flag'}
+		 $as_echo "$as_val"'`
+	       { $as_echo "$as_me:$LINENO: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+
+    if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then
+        :
+        CFLAGS="$CFLAGS -ggdb"
+    else
+        :
+
+    fi
+
+
+
+
+    flag=`echo O0 | sed 'y%.=/+-%___p_%'`
+    { $as_echo "$as_me:$LINENO: checking whether $CC supports -O0" >&5
+$as_echo_n "checking whether $CC supports -O0... " >&6; }
+if { as_var=eso_cv_prog_cc_$flag; eval "test \"\${$as_var+set}\" = set"; }; then
+  $as_echo_n "(cached) " >&6
+else
+
+                       eval "eso_cv_prog_cc_$flag=no"
+                       ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+                       echo 'int main() { return 0; }' >conftest.$ac_ext
+
+                       try_compile="`$CC -O0 -c conftest.$ac_ext 2>&1`"
+                       if test -z "$try_compile"; then
+                           try_link="`$CC -O0 -o conftest$ac_exeext \
+                                    conftest.$ac_ext 2>&1`"
+                           if test -z "$try_link"; then
+                               eval "eso_cv_prog_cc_$flag=yes"
+                           fi
+                       fi
+                       rm -f conftest*
+
+                       ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+fi
+ac_res=`eval 'as_val=${'eso_cv_prog_cc_$flag'}
+		 $as_echo "$as_val"'`
+	       { $as_echo "$as_me:$LINENO: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+
+    if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then
+        :
+        CFLAGS="$CFLAGS -O0"
+    else
+        :
+
+    fi
+
+
+
+
+    flag=`echo rdynamic | sed 'y%.=/+-%___p_%'`
+    { $as_echo "$as_me:$LINENO: checking whether $CC supports -rdynamic" >&5
+$as_echo_n "checking whether $CC supports -rdynamic... " >&6; }
+if { as_var=eso_cv_prog_cc_$flag; eval "test \"\${$as_var+set}\" = set"; }; then
+  $as_echo_n "(cached) " >&6
+else
+
+                       eval "eso_cv_prog_cc_$flag=no"
+                       ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+                       echo 'int main() { return 0; }' >conftest.$ac_ext
+
+                       try_compile="`$CC -rdynamic -c conftest.$ac_ext 2>&1`"
+                       if test -z "$try_compile"; then
+                           try_link="`$CC -rdynamic -o conftest$ac_exeext \
+                                    conftest.$ac_ext 2>&1`"
+                           if test -z "$try_link"; then
+                               eval "eso_cv_prog_cc_$flag=yes"
+                           fi
+                       fi
+                       rm -f conftest*
+
+                       ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+fi
+ac_res=`eval 'as_val=${'eso_cv_prog_cc_$flag'}
+		 $as_echo "$as_val"'`
+	       { $as_echo "$as_me:$LINENO: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+
+    if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then
+        :
+        CFLAGS="$CFLAGS -rdynamic"
+    else
+        :
+
+    fi
+
+
+
+
+    flag=`echo Wall | sed 'y%.=/+-%___p_%'`
+    { $as_echo "$as_me:$LINENO: checking whether $CC supports -Wall" >&5
+$as_echo_n "checking whether $CC supports -Wall... " >&6; }
+if { as_var=eso_cv_prog_cc_$flag; eval "test \"\${$as_var+set}\" = set"; }; then
+  $as_echo_n "(cached) " >&6
+else
+
+                       eval "eso_cv_prog_cc_$flag=no"
+                       ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+                       echo 'int main() { return 0; }' >conftest.$ac_ext
+
+                       try_compile="`$CC -Wall -c conftest.$ac_ext 2>&1`"
+                       if test -z "$try_compile"; then
+                           try_link="`$CC -Wall -o conftest$ac_exeext \
+                                    conftest.$ac_ext 2>&1`"
+                           if test -z "$try_link"; then
+                               eval "eso_cv_prog_cc_$flag=yes"
+                           fi
+                       fi
+                       rm -f conftest*
+
+                       ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+fi
+ac_res=`eval 'as_val=${'eso_cv_prog_cc_$flag'}
+		 $as_echo "$as_val"'`
+	       { $as_echo "$as_me:$LINENO: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+
+    if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then
+        :
+        CFLAGS="$CFLAGS -Wall"
+    else
+        :
+
+    fi
+
+
+
+
+    flag=`echo W | sed 'y%.=/+-%___p_%'`
+    { $as_echo "$as_me:$LINENO: checking whether $CC supports -W" >&5
+$as_echo_n "checking whether $CC supports -W... " >&6; }
+if { as_var=eso_cv_prog_cc_$flag; eval "test \"\${$as_var+set}\" = set"; }; then
+  $as_echo_n "(cached) " >&6
+else
+
+                       eval "eso_cv_prog_cc_$flag=no"
+                       ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+                       echo 'int main() { return 0; }' >conftest.$ac_ext
+
+                       try_compile="`$CC -W -c conftest.$ac_ext 2>&1`"
+                       if test -z "$try_compile"; then
+                           try_link="`$CC -W -o conftest$ac_exeext \
+                                    conftest.$ac_ext 2>&1`"
+                           if test -z "$try_link"; then
+                               eval "eso_cv_prog_cc_$flag=yes"
+                           fi
+                       fi
+                       rm -f conftest*
+
+                       ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+fi
+ac_res=`eval 'as_val=${'eso_cv_prog_cc_$flag'}
+		 $as_echo "$as_val"'`
+	       { $as_echo "$as_me:$LINENO: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+
+    if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then
+        :
+        CFLAGS="$CFLAGS -W"
+    else
+        :
+
+    fi
+
+
+        CFLAGS="$CFLAGS $eso_clean_CFLAGS"
+        ESO_DEBUG_FLAGS="-DESO_ENABLE_DEBUG"
+    else
+        ESO_DEBUG_FLAGS="-DNDEBUG"
+    fi
+
+
+
+{ $as_echo "$as_me:$LINENO: checking for grep that handles long lines and -e" >&5
+$as_echo_n "checking for grep that handles long lines and -e... " >&6; }
+if test "${ac_cv_path_GREP+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  if test -z "$GREP"; then
+  ac_path_GREP_found=false
+  # Loop through the user's path and test for each of PROGNAME-LIST
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for ac_prog in grep ggrep; do
+    for ac_exec_ext in '' $ac_executable_extensions; do
+      ac_path_GREP="$as_dir/$ac_prog$ac_exec_ext"
+      { test -f "$ac_path_GREP" && $as_test_x "$ac_path_GREP"; } || continue
+# Check for GNU ac_path_GREP and select it if it is found.
+  # Check for GNU $ac_path_GREP
+case `"$ac_path_GREP" --version 2>&1` in
+*GNU*)
+  ac_cv_path_GREP="$ac_path_GREP" ac_path_GREP_found=:;;
+*)
+  ac_count=0
+  $as_echo_n 0123456789 >"conftest.in"
+  while :
+  do
+    cat "conftest.in" "conftest.in" >"conftest.tmp"
+    mv "conftest.tmp" "conftest.in"
+    cp "conftest.in" "conftest.nl"
+    $as_echo 'GREP' >> "conftest.nl"
+    "$ac_path_GREP" -e 'GREP$' -e '-(cannot match)-' < "conftest.nl" >"conftest.out" 2>/dev/null || break
+    diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break
+    ac_count=`expr $ac_count + 1`
+    if test $ac_count -gt ${ac_path_GREP_max-0}; then
+      # Best one so far, save it but keep looking for a better one
+      ac_cv_path_GREP="$ac_path_GREP"
+      ac_path_GREP_max=$ac_count
+    fi
+    # 10*(2^10) chars as input seems more than enough
+    test $ac_count -gt 10 && break
+  done
+  rm -f conftest.in conftest.tmp conftest.nl conftest.out;;
+esac
+
+      $ac_path_GREP_found && break 3
+    done
+  done
+done
+IFS=$as_save_IFS
+  if test -z "$ac_cv_path_GREP"; then
+    { { $as_echo "$as_me:$LINENO: error: no acceptable grep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" >&5
+$as_echo "$as_me: error: no acceptable grep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" >&2;}
+   { (exit 1); exit 1; }; }
+  fi
+else
+  ac_cv_path_GREP=$GREP
+fi
+
+fi
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_path_GREP" >&5
+$as_echo "$ac_cv_path_GREP" >&6; }
+ GREP="$ac_cv_path_GREP"
+
+
+{ $as_echo "$as_me:$LINENO: checking for egrep" >&5
+$as_echo_n "checking for egrep... " >&6; }
+if test "${ac_cv_path_EGREP+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  if echo a | $GREP -E '(a|b)' >/dev/null 2>&1
+   then ac_cv_path_EGREP="$GREP -E"
+   else
+     if test -z "$EGREP"; then
+  ac_path_EGREP_found=false
+  # Loop through the user's path and test for each of PROGNAME-LIST
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for ac_prog in egrep; do
+    for ac_exec_ext in '' $ac_executable_extensions; do
+      ac_path_EGREP="$as_dir/$ac_prog$ac_exec_ext"
+      { test -f "$ac_path_EGREP" && $as_test_x "$ac_path_EGREP"; } || continue
+# Check for GNU ac_path_EGREP and select it if it is found.
+  # Check for GNU $ac_path_EGREP
+case `"$ac_path_EGREP" --version 2>&1` in
+*GNU*)
+  ac_cv_path_EGREP="$ac_path_EGREP" ac_path_EGREP_found=:;;
+*)
+  ac_count=0
+  $as_echo_n 0123456789 >"conftest.in"
+  while :
+  do
+    cat "conftest.in" "conftest.in" >"conftest.tmp"
+    mv "conftest.tmp" "conftest.in"
+    cp "conftest.in" "conftest.nl"
+    $as_echo 'EGREP' >> "conftest.nl"
+    "$ac_path_EGREP" 'EGREP$' < "conftest.nl" >"conftest.out" 2>/dev/null || break
+    diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break
+    ac_count=`expr $ac_count + 1`
+    if test $ac_count -gt ${ac_path_EGREP_max-0}; then
+      # Best one so far, save it but keep looking for a better one
+      ac_cv_path_EGREP="$ac_path_EGREP"
+      ac_path_EGREP_max=$ac_count
+    fi
+    # 10*(2^10) chars as input seems more than enough
+    test $ac_count -gt 10 && break
+  done
+  rm -f conftest.in conftest.tmp conftest.nl conftest.out;;
+esac
+
+      $ac_path_EGREP_found && break 3
+    done
+  done
+done
+IFS=$as_save_IFS
+  if test -z "$ac_cv_path_EGREP"; then
+    { { $as_echo "$as_me:$LINENO: error: no acceptable egrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" >&5
+$as_echo "$as_me: error: no acceptable egrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" >&2;}
+   { (exit 1); exit 1; }; }
+  fi
+else
+  ac_cv_path_EGREP=$EGREP
+fi
+
+   fi
+fi
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_path_EGREP" >&5
+$as_echo "$ac_cv_path_EGREP" >&6; }
+ EGREP="$ac_cv_path_EGREP"
+
+
+
+
+
+
+    # Check whether --enable-strict was given.
+if test "${enable_strict+set}" = set; then
+  enableval=$enable_strict; eso_enable_strict=$enableval
+else
+  eso_enable_strict=no
+fi
+
+
+    { $as_echo "$as_me:$LINENO: checking whether strict compiler options should be used" >&5
+$as_echo_n "checking whether strict compiler options should be used... " >&6; }
+if test "${eso_cv_enable_strict+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  eso_cv_enable_strict=$eso_enable_strict
+fi
+{ $as_echo "$as_me:$LINENO: result: $eso_cv_enable_strict" >&5
+$as_echo "$eso_cv_enable_strict" >&6; }
+
+
+    if test x"$eso_cv_enable_strict" = xyes; then
+
+    	eso_enable_strict_std_set=no
+
+        if test -n "$CFLAGS"; then
+            echo $CFLAGS | $EGREP '(\-std=|-ansi)' >/dev/null 2>&1
+            if test x"$?" = x0; then
+            	eso_enable_strict_std_set=yes
+            fi
+        fi
+
+        if test x"$eso_enable_strict_std_set" = xno; then
+
+
+
+    flag=`echo std=c99 | sed 'y%.=/+-%___p_%'`
+    { $as_echo "$as_me:$LINENO: checking whether $CC supports -std=c99" >&5
+$as_echo_n "checking whether $CC supports -std=c99... " >&6; }
+if { as_var=eso_cv_prog_cc_$flag; eval "test \"\${$as_var+set}\" = set"; }; then
+  $as_echo_n "(cached) " >&6
+else
+
+                       eval "eso_cv_prog_cc_$flag=no"
+                       ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+                       echo 'int main() { return 0; }' >conftest.$ac_ext
+
+                       try_compile="`$CC -std=c99 -c conftest.$ac_ext 2>&1`"
+                       if test -z "$try_compile"; then
+                           try_link="`$CC -std=c99 -o conftest$ac_exeext \
+                                    conftest.$ac_ext 2>&1`"
+                           if test -z "$try_link"; then
+                               eval "eso_cv_prog_cc_$flag=yes"
+                           fi
+                       fi
+                       rm -f conftest*
+
+                       ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+fi
+ac_res=`eval 'as_val=${'eso_cv_prog_cc_$flag'}
+		 $as_echo "$as_val"'`
+	       { $as_echo "$as_me:$LINENO: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+
+    if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then
+        :
+        CFLAGS="$CFLAGS -std=c99"
+    else
+        :
+
+    fi
+
+        fi
+
+
+
+
+    flag=`echo pedantic | sed 'y%.=/+-%___p_%'`
+    { $as_echo "$as_me:$LINENO: checking whether $CC supports -pedantic" >&5
+$as_echo_n "checking whether $CC supports -pedantic... " >&6; }
+if { as_var=eso_cv_prog_cc_$flag; eval "test \"\${$as_var+set}\" = set"; }; then
+  $as_echo_n "(cached) " >&6
+else
+
+                       eval "eso_cv_prog_cc_$flag=no"
+                       ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+                       echo 'int main() { return 0; }' >conftest.$ac_ext
+
+                       try_compile="`$CC -pedantic -c conftest.$ac_ext 2>&1`"
+                       if test -z "$try_compile"; then
+                           try_link="`$CC -pedantic -o conftest$ac_exeext \
+                                    conftest.$ac_ext 2>&1`"
+                           if test -z "$try_link"; then
+                               eval "eso_cv_prog_cc_$flag=yes"
+                           fi
+                       fi
+                       rm -f conftest*
+
+                       ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+fi
+ac_res=`eval 'as_val=${'eso_cv_prog_cc_$flag'}
+		 $as_echo "$as_val"'`
+	       { $as_echo "$as_me:$LINENO: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+
+    if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then
+        :
+        CFLAGS="$CFLAGS -pedantic"
+    else
+        :
+
+    fi
+
+
+    fi
+
+
+
+
+    flag=`echo fno-builtin | sed 'y%.=/+-%___p_%'`
+    { $as_echo "$as_me:$LINENO: checking whether $CC supports -fno-builtin" >&5
+$as_echo_n "checking whether $CC supports -fno-builtin... " >&6; }
+if { as_var=eso_cv_prog_cc_$flag; eval "test \"\${$as_var+set}\" = set"; }; then
+  $as_echo_n "(cached) " >&6
+else
+
+                       eval "eso_cv_prog_cc_$flag=no"
+                       ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+                       echo 'int main() { return 0; }' >conftest.$ac_ext
+
+                       try_compile="`$CC -fno-builtin -c conftest.$ac_ext 2>&1`"
+                       if test -z "$try_compile"; then
+                           try_link="`$CC -fno-builtin -o conftest$ac_exeext \
+                                    conftest.$ac_ext 2>&1`"
+                           if test -z "$try_link"; then
+                               eval "eso_cv_prog_cc_$flag=yes"
+                           fi
+                       fi
+                       rm -f conftest*
+
+                       ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+fi
+ac_res=`eval 'as_val=${'eso_cv_prog_cc_$flag'}
+		 $as_echo "$as_val"'`
+	       { $as_echo "$as_me:$LINENO: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+
+    if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then
+        :
+        CFLAGS="$CFLAGS -fno-builtin"
+    else
+        :
+
+    fi
+
+
+
+
+    flag=`echo std=c99 | sed 'y%.=/+-%___p_%'`
+    { $as_echo "$as_me:$LINENO: checking whether $CC supports -std=c99" >&5
+$as_echo_n "checking whether $CC supports -std=c99... " >&6; }
+if { as_var=eso_cv_prog_cc_$flag; eval "test \"\${$as_var+set}\" = set"; }; then
+  $as_echo_n "(cached) " >&6
+else
+
+                       eval "eso_cv_prog_cc_$flag=no"
+                       ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+                       echo 'int main() { return 0; }' >conftest.$ac_ext
+
+                       try_compile="`$CC -std=c99 -c conftest.$ac_ext 2>&1`"
+                       if test -z "$try_compile"; then
+                           try_link="`$CC -std=c99 -o conftest$ac_exeext \
+                                    conftest.$ac_ext 2>&1`"
+                           if test -z "$try_link"; then
+                               eval "eso_cv_prog_cc_$flag=yes"
+                           fi
+                       fi
+                       rm -f conftest*
+
+                       ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+fi
+ac_res=`eval 'as_val=${'eso_cv_prog_cc_$flag'}
+		 $as_echo "$as_val"'`
+	       { $as_echo "$as_me:$LINENO: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+
+    if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then
+        :
+        CFLAGS="$CFLAGS -std=c99"
+    else
+        :
+
+    fi
+
+
+
+    # Extract the first word of "doxygen", so it can be a program name with args.
+set dummy doxygen; ac_word=$2
+{ $as_echo "$as_me:$LINENO: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_path_DOXYGEN+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  case $DOXYGEN in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_DOXYGEN="$DOXYGEN" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_path_DOXYGEN="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+IFS=$as_save_IFS
+
+  ;;
+esac
+fi
+DOXYGEN=$ac_cv_path_DOXYGEN
+if test -n "$DOXYGEN"; then
+  { $as_echo "$as_me:$LINENO: result: $DOXYGEN" >&5
+$as_echo "$DOXYGEN" >&6; }
+else
+  { $as_echo "$as_me:$LINENO: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+
+
+    # Extract the first word of "latex", so it can be a program name with args.
+set dummy latex; ac_word=$2
+{ $as_echo "$as_me:$LINENO: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_path_LATEX+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  case $LATEX in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_LATEX="$LATEX" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_path_LATEX="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+IFS=$as_save_IFS
+
+  ;;
+esac
+fi
+LATEX=$ac_cv_path_LATEX
+if test -n "$LATEX"; then
+  { $as_echo "$as_me:$LINENO: result: $LATEX" >&5
+$as_echo "$LATEX" >&6; }
+else
+  { $as_echo "$as_me:$LINENO: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+
+
+    if test -z "${DOXYGEN}"; then
+        DOXYGEN=":"
+    fi
+
+    if test -z "${LATEX}"; then
+        LATEX=":"
+    fi
+
+
+
+# Check whether --enable-static was given.
+if test "${enable_static+set}" = set; then
+  enableval=$enable_static; p=${PACKAGE-default}
+    case $enableval in
+    yes) enable_static=yes ;;
+    no) enable_static=no ;;
+    *)
+     enable_static=no
+      # Look at the argument we got.  We use all the common list separators.
+      lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR,"
+      for pkg in $enableval; do
+	IFS="$lt_save_ifs"
+	if test "X$pkg" = "X$p"; then
+	  enable_static=yes
+	fi
+      done
+      IFS="$lt_save_ifs"
+      ;;
+    esac
+else
+  enable_static=no
+fi
+
+
+
+
+
+
+
+
+
+# Check whether --enable-shared was given.
+if test "${enable_shared+set}" = set; then
+  enableval=$enable_shared; p=${PACKAGE-default}
+    case $enableval in
+    yes) enable_shared=yes ;;
+    no) enable_shared=no ;;
+    *)
+      enable_shared=no
+      # Look at the argument we got.  We use all the common list separators.
+      lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR,"
+      for pkg in $enableval; do
+	IFS="$lt_save_ifs"
+	if test "X$pkg" = "X$p"; then
+	  enable_shared=yes
+	fi
+      done
+      IFS="$lt_save_ifs"
+      ;;
+    esac
+else
+  enable_shared=yes
+fi
+
+
+
+
+
+
+
+
+
+
+case `pwd` in
+  *\ * | *\	*)
+    { $as_echo "$as_me:$LINENO: WARNING: Libtool does not cope well with whitespace in \`pwd\`" >&5
+$as_echo "$as_me: WARNING: Libtool does not cope well with whitespace in \`pwd\`" >&2;} ;;
+esac
+
+
+
+macro_version='2.2.6b'
+macro_revision='1.3017'
+
+
+
+
+
+
+
+
+
+
+
+
+
+ltmain="$ac_aux_dir/ltmain.sh"
+
+{ $as_echo "$as_me:$LINENO: checking for a sed that does not truncate output" >&5
+$as_echo_n "checking for a sed that does not truncate output... " >&6; }
+if test "${ac_cv_path_SED+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+            ac_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/
+     for ac_i in 1 2 3 4 5 6 7; do
+       ac_script="$ac_script$as_nl$ac_script"
+     done
+     echo "$ac_script" 2>/dev/null | sed 99q >conftest.sed
+     $as_unset ac_script || ac_script=
+     if test -z "$SED"; then
+  ac_path_SED_found=false
+  # Loop through the user's path and test for each of PROGNAME-LIST
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for ac_prog in sed gsed; do
+    for ac_exec_ext in '' $ac_executable_extensions; do
+      ac_path_SED="$as_dir/$ac_prog$ac_exec_ext"
+      { test -f "$ac_path_SED" && $as_test_x "$ac_path_SED"; } || continue
+# Check for GNU ac_path_SED and select it if it is found.
+  # Check for GNU $ac_path_SED
+case `"$ac_path_SED" --version 2>&1` in
+*GNU*)
+  ac_cv_path_SED="$ac_path_SED" ac_path_SED_found=:;;
+*)
+  ac_count=0
+  $as_echo_n 0123456789 >"conftest.in"
+  while :
+  do
+    cat "conftest.in" "conftest.in" >"conftest.tmp"
+    mv "conftest.tmp" "conftest.in"
+    cp "conftest.in" "conftest.nl"
+    $as_echo '' >> "conftest.nl"
+    "$ac_path_SED" -f conftest.sed < "conftest.nl" >"conftest.out" 2>/dev/null || break
+    diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break
+    ac_count=`expr $ac_count + 1`
+    if test $ac_count -gt ${ac_path_SED_max-0}; then
+      # Best one so far, save it but keep looking for a better one
+      ac_cv_path_SED="$ac_path_SED"
+      ac_path_SED_max=$ac_count
+    fi
+    # 10*(2^10) chars as input seems more than enough
+    test $ac_count -gt 10 && break
+  done
+  rm -f conftest.in conftest.tmp conftest.nl conftest.out;;
+esac
+
+      $ac_path_SED_found && break 3
+    done
+  done
+done
+IFS=$as_save_IFS
+  if test -z "$ac_cv_path_SED"; then
+    { { $as_echo "$as_me:$LINENO: error: no acceptable sed could be found in \$PATH" >&5
+$as_echo "$as_me: error: no acceptable sed could be found in \$PATH" >&2;}
+   { (exit 1); exit 1; }; }
+  fi
+else
+  ac_cv_path_SED=$SED
+fi
+
+fi
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_path_SED" >&5
+$as_echo "$ac_cv_path_SED" >&6; }
+ SED="$ac_cv_path_SED"
+  rm -f conftest.sed
+
+test -z "$SED" && SED=sed
+Xsed="$SED -e 1s/^X//"
+
+
+
+
+
+
+
+
+
+
+
+{ $as_echo "$as_me:$LINENO: checking for fgrep" >&5
+$as_echo_n "checking for fgrep... " >&6; }
+if test "${ac_cv_path_FGREP+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  if echo 'ab*c' | $GREP -F 'ab*c' >/dev/null 2>&1
+   then ac_cv_path_FGREP="$GREP -F"
+   else
+     if test -z "$FGREP"; then
+  ac_path_FGREP_found=false
+  # Loop through the user's path and test for each of PROGNAME-LIST
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for ac_prog in fgrep; do
+    for ac_exec_ext in '' $ac_executable_extensions; do
+      ac_path_FGREP="$as_dir/$ac_prog$ac_exec_ext"
+      { test -f "$ac_path_FGREP" && $as_test_x "$ac_path_FGREP"; } || continue
+# Check for GNU ac_path_FGREP and select it if it is found.
+  # Check for GNU $ac_path_FGREP
+case `"$ac_path_FGREP" --version 2>&1` in
+*GNU*)
+  ac_cv_path_FGREP="$ac_path_FGREP" ac_path_FGREP_found=:;;
+*)
+  ac_count=0
+  $as_echo_n 0123456789 >"conftest.in"
+  while :
+  do
+    cat "conftest.in" "conftest.in" >"conftest.tmp"
+    mv "conftest.tmp" "conftest.in"
+    cp "conftest.in" "conftest.nl"
+    $as_echo 'FGREP' >> "conftest.nl"
+    "$ac_path_FGREP" FGREP < "conftest.nl" >"conftest.out" 2>/dev/null || break
+    diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break
+    ac_count=`expr $ac_count + 1`
+    if test $ac_count -gt ${ac_path_FGREP_max-0}; then
+      # Best one so far, save it but keep looking for a better one
+      ac_cv_path_FGREP="$ac_path_FGREP"
+      ac_path_FGREP_max=$ac_count
+    fi
+    # 10*(2^10) chars as input seems more than enough
+    test $ac_count -gt 10 && break
+  done
+  rm -f conftest.in conftest.tmp conftest.nl conftest.out;;
+esac
+
+      $ac_path_FGREP_found && break 3
+    done
+  done
+done
+IFS=$as_save_IFS
+  if test -z "$ac_cv_path_FGREP"; then
+    { { $as_echo "$as_me:$LINENO: error: no acceptable fgrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" >&5
+$as_echo "$as_me: error: no acceptable fgrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" >&2;}
+   { (exit 1); exit 1; }; }
+  fi
+else
+  ac_cv_path_FGREP=$FGREP
+fi
+
+   fi
+fi
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_path_FGREP" >&5
+$as_echo "$ac_cv_path_FGREP" >&6; }
+ FGREP="$ac_cv_path_FGREP"
+
+
+test -z "$GREP" && GREP=grep
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+# Check whether --with-gnu-ld was given.
+if test "${with_gnu_ld+set}" = set; then
+  withval=$with_gnu_ld; test "$withval" = no || with_gnu_ld=yes
+else
+  with_gnu_ld=no
+fi
+
+ac_prog=ld
+if test "$GCC" = yes; then
+  # Check if gcc -print-prog-name=ld gives a path.
+  { $as_echo "$as_me:$LINENO: checking for ld used by $CC" >&5
+$as_echo_n "checking for ld used by $CC... " >&6; }
+  case $host in
+  *-*-mingw*)
+    # gcc leaves a trailing carriage return which upsets mingw
+    ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;;
+  *)
+    ac_prog=`($CC -print-prog-name=ld) 2>&5` ;;
+  esac
+  case $ac_prog in
+    # Accept absolute paths.
+    [\\/]* | ?:[\\/]*)
+      re_direlt='/[^/][^/]*/\.\./'
+      # Canonicalize the pathname of ld
+      ac_prog=`$ECHO "$ac_prog"| $SED 's%\\\\%/%g'`
+      while $ECHO "$ac_prog" | $GREP "$re_direlt" > /dev/null 2>&1; do
+	ac_prog=`$ECHO $ac_prog| $SED "s%$re_direlt%/%"`
+      done
+      test -z "$LD" && LD="$ac_prog"
+      ;;
+  "")
+    # If it fails, then pretend we aren't using GCC.
+    ac_prog=ld
+    ;;
+  *)
+    # If it is relative, then search for the first ld in PATH.
+    with_gnu_ld=unknown
+    ;;
+  esac
+elif test "$with_gnu_ld" = yes; then
+  { $as_echo "$as_me:$LINENO: checking for GNU ld" >&5
+$as_echo_n "checking for GNU ld... " >&6; }
+else
+  { $as_echo "$as_me:$LINENO: checking for non-GNU ld" >&5
+$as_echo_n "checking for non-GNU ld... " >&6; }
+fi
+if test "${lt_cv_path_LD+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  if test -z "$LD"; then
+  lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
+  for ac_dir in $PATH; do
+    IFS="$lt_save_ifs"
+    test -z "$ac_dir" && ac_dir=.
+    if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then
+      lt_cv_path_LD="$ac_dir/$ac_prog"
+      # Check to see if the program is GNU ld.  I'd rather use --version,
+      # but apparently some variants of GNU ld only accept -v.
+      # Break only if it was the GNU/non-GNU ld that we prefer.
+      case `"$lt_cv_path_LD" -v 2>&1 </dev/null` in
+      *GNU* | *'with BFD'*)
+	test "$with_gnu_ld" != no && break
+	;;
+      *)
+	test "$with_gnu_ld" != yes && break
+	;;
+      esac
+    fi
+  done
+  IFS="$lt_save_ifs"
+else
+  lt_cv_path_LD="$LD" # Let the user override the test with a path.
+fi
+fi
+
+LD="$lt_cv_path_LD"
+if test -n "$LD"; then
+  { $as_echo "$as_me:$LINENO: result: $LD" >&5
+$as_echo "$LD" >&6; }
+else
+  { $as_echo "$as_me:$LINENO: result: no" >&5
+$as_echo "no" >&6; }
+fi
+test -z "$LD" && { { $as_echo "$as_me:$LINENO: error: no acceptable ld found in \$PATH" >&5
+$as_echo "$as_me: error: no acceptable ld found in \$PATH" >&2;}
+   { (exit 1); exit 1; }; }
+{ $as_echo "$as_me:$LINENO: checking if the linker ($LD) is GNU ld" >&5
+$as_echo_n "checking if the linker ($LD) is GNU ld... " >&6; }
+if test "${lt_cv_prog_gnu_ld+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  # I'd rather use --version here, but apparently some GNU lds only accept -v.
+case `$LD -v 2>&1 </dev/null` in
+*GNU* | *'with BFD'*)
+  lt_cv_prog_gnu_ld=yes
+  ;;
+*)
+  lt_cv_prog_gnu_ld=no
+  ;;
+esac
+fi
+{ $as_echo "$as_me:$LINENO: result: $lt_cv_prog_gnu_ld" >&5
+$as_echo "$lt_cv_prog_gnu_ld" >&6; }
+with_gnu_ld=$lt_cv_prog_gnu_ld
+
+
+
+
+
+
+
+
+
+{ $as_echo "$as_me:$LINENO: checking for BSD- or MS-compatible name lister (nm)" >&5
+$as_echo_n "checking for BSD- or MS-compatible name lister (nm)... " >&6; }
+if test "${lt_cv_path_NM+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$NM"; then
+  # Let the user override the test.
+  lt_cv_path_NM="$NM"
+else
+  lt_nm_to_check="${ac_tool_prefix}nm"
+  if test -n "$ac_tool_prefix" && test "$build" = "$host"; then
+    lt_nm_to_check="$lt_nm_to_check nm"
+  fi
+  for lt_tmp_nm in $lt_nm_to_check; do
+    lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
+    for ac_dir in $PATH /usr/ccs/bin/elf /usr/ccs/bin /usr/ucb /bin; do
+      IFS="$lt_save_ifs"
+      test -z "$ac_dir" && ac_dir=.
+      tmp_nm="$ac_dir/$lt_tmp_nm"
+      if test -f "$tmp_nm" || test -f "$tmp_nm$ac_exeext" ; then
+	# Check to see if the nm accepts a BSD-compat flag.
+	# Adding the `sed 1q' prevents false positives on HP-UX, which says:
+	#   nm: unknown option "B" ignored
+	# Tru64's nm complains that /dev/null is an invalid object file
+	case `"$tmp_nm" -B /dev/null 2>&1 | sed '1q'` in
+	*/dev/null* | *'Invalid file or object type'*)
+	  lt_cv_path_NM="$tmp_nm -B"
+	  break
+	  ;;
+	*)
+	  case `"$tmp_nm" -p /dev/null 2>&1 | sed '1q'` in
+	  */dev/null*)
+	    lt_cv_path_NM="$tmp_nm -p"
+	    break
+	    ;;
+	  *)
+	    lt_cv_path_NM=${lt_cv_path_NM="$tmp_nm"} # keep the first match, but
+	    continue # so that we can try to find one that supports BSD flags
+	    ;;
+	  esac
+	  ;;
+	esac
+      fi
+    done
+    IFS="$lt_save_ifs"
+  done
+  : ${lt_cv_path_NM=no}
+fi
+fi
+{ $as_echo "$as_me:$LINENO: result: $lt_cv_path_NM" >&5
+$as_echo "$lt_cv_path_NM" >&6; }
+if test "$lt_cv_path_NM" != "no"; then
+  NM="$lt_cv_path_NM"
+else
+  # Didn't find any BSD compatible name lister, look for dumpbin.
+  if test -n "$ac_tool_prefix"; then
+  for ac_prog in "dumpbin -symbols" "link -dump -symbols"
+  do
+    # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args.
+set dummy $ac_tool_prefix$ac_prog; ac_word=$2
+{ $as_echo "$as_me:$LINENO: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_DUMPBIN+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$DUMPBIN"; then
+  ac_cv_prog_DUMPBIN="$DUMPBIN" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_DUMPBIN="$ac_tool_prefix$ac_prog"
+    $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+IFS=$as_save_IFS
+
+fi
+fi
+DUMPBIN=$ac_cv_prog_DUMPBIN
+if test -n "$DUMPBIN"; then
+  { $as_echo "$as_me:$LINENO: result: $DUMPBIN" >&5
+$as_echo "$DUMPBIN" >&6; }
+else
+  { $as_echo "$as_me:$LINENO: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+    test -n "$DUMPBIN" && break
+  done
+fi
+if test -z "$DUMPBIN"; then
+  ac_ct_DUMPBIN=$DUMPBIN
+  for ac_prog in "dumpbin -symbols" "link -dump -symbols"
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ $as_echo "$as_me:$LINENO: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_ac_ct_DUMPBIN+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_DUMPBIN"; then
+  ac_cv_prog_ac_ct_DUMPBIN="$ac_ct_DUMPBIN" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_ac_ct_DUMPBIN="$ac_prog"
+    $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_DUMPBIN=$ac_cv_prog_ac_ct_DUMPBIN
+if test -n "$ac_ct_DUMPBIN"; then
+  { $as_echo "$as_me:$LINENO: result: $ac_ct_DUMPBIN" >&5
+$as_echo "$ac_ct_DUMPBIN" >&6; }
+else
+  { $as_echo "$as_me:$LINENO: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  test -n "$ac_ct_DUMPBIN" && break
+done
+
+  if test "x$ac_ct_DUMPBIN" = x; then
+    DUMPBIN=":"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:$LINENO: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    DUMPBIN=$ac_ct_DUMPBIN
+  fi
+fi
+
+
+  if test "$DUMPBIN" != ":"; then
+    NM="$DUMPBIN"
+  fi
+fi
+test -z "$NM" && NM=nm
+
+
+
+
+
+
+{ $as_echo "$as_me:$LINENO: checking the name lister ($NM) interface" >&5
+$as_echo_n "checking the name lister ($NM) interface... " >&6; }
+if test "${lt_cv_nm_interface+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  lt_cv_nm_interface="BSD nm"
+  echo "int some_variable = 0;" > conftest.$ac_ext
+  (eval echo "\"\$as_me:5887: $ac_compile\"" >&5)
+  (eval "$ac_compile" 2>conftest.err)
+  cat conftest.err >&5
+  (eval echo "\"\$as_me:5890: $NM \\\"conftest.$ac_objext\\\"\"" >&5)
+  (eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out)
+  cat conftest.err >&5
+  (eval echo "\"\$as_me:5893: output\"" >&5)
+  cat conftest.out >&5
+  if $GREP 'External.*some_variable' conftest.out > /dev/null; then
+    lt_cv_nm_interface="MS dumpbin"
+  fi
+  rm -f conftest*
+fi
+{ $as_echo "$as_me:$LINENO: result: $lt_cv_nm_interface" >&5
+$as_echo "$lt_cv_nm_interface" >&6; }
+
+# find the maximum length of command line arguments
+{ $as_echo "$as_me:$LINENO: checking the maximum length of command line arguments" >&5
+$as_echo_n "checking the maximum length of command line arguments... " >&6; }
+if test "${lt_cv_sys_max_cmd_len+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+    i=0
+  teststring="ABCD"
+
+  case $build_os in
+  msdosdjgpp*)
+    # On DJGPP, this test can blow up pretty badly due to problems in libc
+    # (any single argument exceeding 2000 bytes causes a buffer overrun
+    # during glob expansion).  Even if it were fixed, the result of this
+    # check would be larger than it should be.
+    lt_cv_sys_max_cmd_len=12288;    # 12K is about right
+    ;;
+
+  gnu*)
+    # Under GNU Hurd, this test is not required because there is
+    # no limit to the length of command line arguments.
+    # Libtool will interpret -1 as no limit whatsoever
+    lt_cv_sys_max_cmd_len=-1;
+    ;;
+
+  cygwin* | mingw* | cegcc*)
+    # On Win9x/ME, this test blows up -- it succeeds, but takes
+    # about 5 minutes as the teststring grows exponentially.
+    # Worse, since 9x/ME are not pre-emptively multitasking,
+    # you end up with a "frozen" computer, even though with patience
+    # the test eventually succeeds (with a max line length of 256k).
+    # Instead, let's just punt: use the minimum linelength reported by
+    # all of the supported platforms: 8192 (on NT/2K/XP).
+    lt_cv_sys_max_cmd_len=8192;
+    ;;
+
+  amigaos*)
+    # On AmigaOS with pdksh, this test takes hours, literally.
+    # So we just punt and use a minimum line length of 8192.
+    lt_cv_sys_max_cmd_len=8192;
+    ;;
+
+  netbsd* | freebsd* | openbsd* | darwin* | dragonfly*)
+    # This has been around since 386BSD, at least.  Likely further.
+    if test -x /sbin/sysctl; then
+      lt_cv_sys_max_cmd_len=`/sbin/sysctl -n kern.argmax`
+    elif test -x /usr/sbin/sysctl; then
+      lt_cv_sys_max_cmd_len=`/usr/sbin/sysctl -n kern.argmax`
+    else
+      lt_cv_sys_max_cmd_len=65536	# usable default for all BSDs
+    fi
+    # And add a safety zone
+    lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4`
+    lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3`
+    ;;
+
+  interix*)
+    # We know the value 262144 and hardcode it with a safety zone (like BSD)
+    lt_cv_sys_max_cmd_len=196608
+    ;;
+
+  osf*)
+    # Dr. Hans Ekkehard Plesser reports seeing a kernel panic running configure
+    # due to this test when exec_disable_arg_limit is 1 on Tru64. It is not
+    # nice to cause kernel panics so lets avoid the loop below.
+    # First set a reasonable default.
+    lt_cv_sys_max_cmd_len=16384
+    #
+    if test -x /sbin/sysconfig; then
+      case `/sbin/sysconfig -q proc exec_disable_arg_limit` in
+        *1*) lt_cv_sys_max_cmd_len=-1 ;;
+      esac
+    fi
+    ;;
+  sco3.2v5*)
+    lt_cv_sys_max_cmd_len=102400
+    ;;
+  sysv5* | sco5v6* | sysv4.2uw2*)
+    kargmax=`grep ARG_MAX /etc/conf/cf.d/stune 2>/dev/null`
+    if test -n "$kargmax"; then
+      lt_cv_sys_max_cmd_len=`echo $kargmax | sed 's/.*[	 ]//'`
+    else
+      lt_cv_sys_max_cmd_len=32768
+    fi
+    ;;
+  *)
+    lt_cv_sys_max_cmd_len=`(getconf ARG_MAX) 2> /dev/null`
+    if test -n "$lt_cv_sys_max_cmd_len"; then
+      lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4`
+      lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3`
+    else
+      # Make teststring a little bigger before we do anything with it.
+      # a 1K string should be a reasonable start.
+      for i in 1 2 3 4 5 6 7 8 ; do
+        teststring=$teststring$teststring
+      done
+      SHELL=${SHELL-${CONFIG_SHELL-/bin/sh}}
+      # If test is not a shell built-in, we'll probably end up computing a
+      # maximum length that is only half of the actual maximum length, but
+      # we can't tell.
+      while { test "X"`$SHELL $0 --fallback-echo "X$teststring$teststring" 2>/dev/null` \
+	         = "XX$teststring$teststring"; } >/dev/null 2>&1 &&
+	      test $i != 17 # 1/2 MB should be enough
+      do
+        i=`expr $i + 1`
+        teststring=$teststring$teststring
+      done
+      # Only check the string length outside the loop.
+      lt_cv_sys_max_cmd_len=`expr "X$teststring" : ".*" 2>&1`
+      teststring=
+      # Add a significant safety factor because C++ compilers can tack on
+      # massive amounts of additional arguments before passing them to the
+      # linker.  It appears as though 1/2 is a usable value.
+      lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 2`
+    fi
+    ;;
+  esac
+
+fi
+
+if test -n $lt_cv_sys_max_cmd_len ; then
+  { $as_echo "$as_me:$LINENO: result: $lt_cv_sys_max_cmd_len" >&5
+$as_echo "$lt_cv_sys_max_cmd_len" >&6; }
+else
+  { $as_echo "$as_me:$LINENO: result: none" >&5
+$as_echo "none" >&6; }
+fi
+max_cmd_len=$lt_cv_sys_max_cmd_len
+
+
+
+
+
+
+: ${CP="cp -f"}
+: ${MV="mv -f"}
+: ${RM="rm -f"}
+
+{ $as_echo "$as_me:$LINENO: checking whether the shell understands some XSI constructs" >&5
+$as_echo_n "checking whether the shell understands some XSI constructs... " >&6; }
+# Try some XSI features
+xsi_shell=no
+( _lt_dummy="a/b/c"
+  test "${_lt_dummy##*/},${_lt_dummy%/*},"${_lt_dummy%"$_lt_dummy"}, \
+      = c,a/b,, \
+    && eval 'test $(( 1 + 1 )) -eq 2 \
+    && test "${#_lt_dummy}" -eq 5' ) >/dev/null 2>&1 \
+  && xsi_shell=yes
+{ $as_echo "$as_me:$LINENO: result: $xsi_shell" >&5
+$as_echo "$xsi_shell" >&6; }
+
+
+{ $as_echo "$as_me:$LINENO: checking whether the shell understands \"+=\"" >&5
+$as_echo_n "checking whether the shell understands \"+=\"... " >&6; }
+lt_shell_append=no
+( foo=bar; set foo baz; eval "$1+=\$2" && test "$foo" = barbaz ) \
+    >/dev/null 2>&1 \
+  && lt_shell_append=yes
+{ $as_echo "$as_me:$LINENO: result: $lt_shell_append" >&5
+$as_echo "$lt_shell_append" >&6; }
+
+
+if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then
+  lt_unset=unset
+else
+  lt_unset=false
+fi
+
+
+
+
+
+# test EBCDIC or ASCII
+case `echo X|tr X '\101'` in
+ A) # ASCII based system
+    # \n is not interpreted correctly by Solaris 8 /usr/ucb/tr
+  lt_SP2NL='tr \040 \012'
+  lt_NL2SP='tr \015\012 \040\040'
+  ;;
+ *) # EBCDIC based system
+  lt_SP2NL='tr \100 \n'
+  lt_NL2SP='tr \r\n \100\100'
+  ;;
+esac
+
+
+
+
+
+
+
+
+
+{ $as_echo "$as_me:$LINENO: checking for $LD option to reload object files" >&5
+$as_echo_n "checking for $LD option to reload object files... " >&6; }
+if test "${lt_cv_ld_reload_flag+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  lt_cv_ld_reload_flag='-r'
+fi
+{ $as_echo "$as_me:$LINENO: result: $lt_cv_ld_reload_flag" >&5
+$as_echo "$lt_cv_ld_reload_flag" >&6; }
+reload_flag=$lt_cv_ld_reload_flag
+case $reload_flag in
+"" | " "*) ;;
+*) reload_flag=" $reload_flag" ;;
+esac
+reload_cmds='$LD$reload_flag -o $output$reload_objs'
+case $host_os in
+  darwin*)
+    if test "$GCC" = yes; then
+      reload_cmds='$LTCC $LTCFLAGS -nostdlib ${wl}-r -o $output$reload_objs'
+    else
+      reload_cmds='$LD$reload_flag -o $output$reload_objs'
+    fi
+    ;;
+esac
+
+
+
+
+
+
+
+
+
+if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}objdump", so it can be a program name with args.
+set dummy ${ac_tool_prefix}objdump; ac_word=$2
+{ $as_echo "$as_me:$LINENO: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_OBJDUMP+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$OBJDUMP"; then
+  ac_cv_prog_OBJDUMP="$OBJDUMP" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_OBJDUMP="${ac_tool_prefix}objdump"
+    $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+IFS=$as_save_IFS
+
+fi
+fi
+OBJDUMP=$ac_cv_prog_OBJDUMP
+if test -n "$OBJDUMP"; then
+  { $as_echo "$as_me:$LINENO: result: $OBJDUMP" >&5
+$as_echo "$OBJDUMP" >&6; }
+else
+  { $as_echo "$as_me:$LINENO: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_OBJDUMP"; then
+  ac_ct_OBJDUMP=$OBJDUMP
+  # Extract the first word of "objdump", so it can be a program name with args.
+set dummy objdump; ac_word=$2
+{ $as_echo "$as_me:$LINENO: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_ac_ct_OBJDUMP+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_OBJDUMP"; then
+  ac_cv_prog_ac_ct_OBJDUMP="$ac_ct_OBJDUMP" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_ac_ct_OBJDUMP="objdump"
+    $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_OBJDUMP=$ac_cv_prog_ac_ct_OBJDUMP
+if test -n "$ac_ct_OBJDUMP"; then
+  { $as_echo "$as_me:$LINENO: result: $ac_ct_OBJDUMP" >&5
+$as_echo "$ac_ct_OBJDUMP" >&6; }
+else
+  { $as_echo "$as_me:$LINENO: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_ct_OBJDUMP" = x; then
+    OBJDUMP="false"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:$LINENO: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    OBJDUMP=$ac_ct_OBJDUMP
+  fi
+else
+  OBJDUMP="$ac_cv_prog_OBJDUMP"
+fi
+
+test -z "$OBJDUMP" && OBJDUMP=objdump
+
+
+
+
+
+
+
+
+
+{ $as_echo "$as_me:$LINENO: checking how to recognize dependent libraries" >&5
+$as_echo_n "checking how to recognize dependent libraries... " >&6; }
+if test "${lt_cv_deplibs_check_method+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  lt_cv_file_magic_cmd='$MAGIC_CMD'
+lt_cv_file_magic_test_file=
+lt_cv_deplibs_check_method='unknown'
+# Need to set the preceding variable on all platforms that support
+# interlibrary dependencies.
+# 'none' -- dependencies not supported.
+# `unknown' -- same as none, but documents that we really don't know.
+# 'pass_all' -- all dependencies passed with no checks.
+# 'test_compile' -- check by making test program.
+# 'file_magic [[regex]]' -- check by looking for files in library path
+# which responds to the $file_magic_cmd with a given extended regex.
+# If you have `file' or equivalent on your system and you're not sure
+# whether `pass_all' will *always* work, you probably want this one.
+
+case $host_os in
+aix[4-9]*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+beos*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+bsdi[45]*)
+  lt_cv_deplibs_check_method='file_magic ELF [0-9][0-9]*-bit [ML]SB (shared object|dynamic lib)'
+  lt_cv_file_magic_cmd='/usr/bin/file -L'
+  lt_cv_file_magic_test_file=/shlib/libc.so
+  ;;
+
+cygwin*)
+  # func_win32_libid is a shell function defined in ltmain.sh
+  lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL'
+  lt_cv_file_magic_cmd='func_win32_libid'
+  ;;
+
+mingw* | pw32*)
+  # Base MSYS/MinGW do not provide the 'file' command needed by
+  # func_win32_libid shell function, so use a weaker test based on 'objdump',
+  # unless we find 'file', for example because we are cross-compiling.
+  if ( file / ) >/dev/null 2>&1; then
+    lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL'
+    lt_cv_file_magic_cmd='func_win32_libid'
+  else
+    lt_cv_deplibs_check_method='file_magic file format pei*-i386(.*architecture: i386)?'
+    lt_cv_file_magic_cmd='$OBJDUMP -f'
+  fi
+  ;;
+
+cegcc)
+  # use the weaker test based on 'objdump'. See mingw*.
+  lt_cv_deplibs_check_method='file_magic file format pe-arm-.*little(.*architecture: arm)?'
+  lt_cv_file_magic_cmd='$OBJDUMP -f'
+  ;;
+
+darwin* | rhapsody*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+freebsd* | dragonfly*)
+  if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then
+    case $host_cpu in
+    i*86 )
+      # Not sure whether the presence of OpenBSD here was a mistake.
+      # Let's accept both of them until this is cleared up.
+      lt_cv_deplibs_check_method='file_magic (FreeBSD|OpenBSD|DragonFly)/i[3-9]86 (compact )?demand paged shared library'
+      lt_cv_file_magic_cmd=/usr/bin/file
+      lt_cv_file_magic_test_file=`echo /usr/lib/libc.so.*`
+      ;;
+    esac
+  else
+    lt_cv_deplibs_check_method=pass_all
+  fi
+  ;;
+
+gnu*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+hpux10.20* | hpux11*)
+  lt_cv_file_magic_cmd=/usr/bin/file
+  case $host_cpu in
+  ia64*)
+    lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|ELF-[0-9][0-9]) shared object file - IA64'
+    lt_cv_file_magic_test_file=/usr/lib/hpux32/libc.so
+    ;;
+  hppa*64*)
+    lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|ELF-[0-9][0-9]) shared object file - PA-RISC [0-9].[0-9]'
+    lt_cv_file_magic_test_file=/usr/lib/pa20_64/libc.sl
+    ;;
+  *)
+    lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|PA-RISC[0-9].[0-9]) shared library'
+    lt_cv_file_magic_test_file=/usr/lib/libc.sl
+    ;;
+  esac
+  ;;
+
+interix[3-9]*)
+  # PIC code is broken on Interix 3.x, that's why |\.a not |_pic\.a here
+  lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so|\.a)$'
+  ;;
+
+irix5* | irix6* | nonstopux*)
+  case $LD in
+  *-32|*"-32 ") libmagic=32-bit;;
+  *-n32|*"-n32 ") libmagic=N32;;
+  *-64|*"-64 ") libmagic=64-bit;;
+  *) libmagic=never-match;;
+  esac
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+# This must be Linux ELF.
+linux* | k*bsd*-gnu)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+netbsd*)
+  if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then
+    lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so\.[0-9]+\.[0-9]+|_pic\.a)$'
+  else
+    lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so|_pic\.a)$'
+  fi
+  ;;
+
+newos6*)
+  lt_cv_deplibs_check_method='file_magic ELF [0-9][0-9]*-bit [ML]SB (executable|dynamic lib)'
+  lt_cv_file_magic_cmd=/usr/bin/file
+  lt_cv_file_magic_test_file=/usr/lib/libnls.so
+  ;;
+
+*nto* | *qnx*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+openbsd*)
+  if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
+    lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so\.[0-9]+\.[0-9]+|\.so|_pic\.a)$'
+  else
+    lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so\.[0-9]+\.[0-9]+|_pic\.a)$'
+  fi
+  ;;
+
+osf3* | osf4* | osf5*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+rdos*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+solaris*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+sysv4 | sysv4.3*)
+  case $host_vendor in
+  motorola)
+    lt_cv_deplibs_check_method='file_magic ELF [0-9][0-9]*-bit [ML]SB (shared object|dynamic lib) M[0-9][0-9]* Version [0-9]'
+    lt_cv_file_magic_test_file=`echo /usr/lib/libc.so*`
+    ;;
+  ncr)
+    lt_cv_deplibs_check_method=pass_all
+    ;;
+  sequent)
+    lt_cv_file_magic_cmd='/bin/file'
+    lt_cv_deplibs_check_method='file_magic ELF [0-9][0-9]*-bit [LM]SB (shared object|dynamic lib )'
+    ;;
+  sni)
+    lt_cv_file_magic_cmd='/bin/file'
+    lt_cv_deplibs_check_method="file_magic ELF [0-9][0-9]*-bit [LM]SB dynamic lib"
+    lt_cv_file_magic_test_file=/lib/libc.so
+    ;;
+  siemens)
+    lt_cv_deplibs_check_method=pass_all
+    ;;
+  pc)
+    lt_cv_deplibs_check_method=pass_all
+    ;;
+  esac
+  ;;
+
+tpf*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+esac
+
+fi
+{ $as_echo "$as_me:$LINENO: result: $lt_cv_deplibs_check_method" >&5
+$as_echo "$lt_cv_deplibs_check_method" >&6; }
+file_magic_cmd=$lt_cv_file_magic_cmd
+deplibs_check_method=$lt_cv_deplibs_check_method
+test -z "$deplibs_check_method" && deplibs_check_method=unknown
+
+
+
+
+
+
+
+
+
+
+
+
+if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}ar", so it can be a program name with args.
+set dummy ${ac_tool_prefix}ar; ac_word=$2
+{ $as_echo "$as_me:$LINENO: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_AR+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$AR"; then
+  ac_cv_prog_AR="$AR" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_AR="${ac_tool_prefix}ar"
+    $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+IFS=$as_save_IFS
+
+fi
+fi
+AR=$ac_cv_prog_AR
+if test -n "$AR"; then
+  { $as_echo "$as_me:$LINENO: result: $AR" >&5
+$as_echo "$AR" >&6; }
+else
+  { $as_echo "$as_me:$LINENO: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_AR"; then
+  ac_ct_AR=$AR
+  # Extract the first word of "ar", so it can be a program name with args.
+set dummy ar; ac_word=$2
+{ $as_echo "$as_me:$LINENO: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_ac_ct_AR+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_AR"; then
+  ac_cv_prog_ac_ct_AR="$ac_ct_AR" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_ac_ct_AR="ar"
+    $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_AR=$ac_cv_prog_ac_ct_AR
+if test -n "$ac_ct_AR"; then
+  { $as_echo "$as_me:$LINENO: result: $ac_ct_AR" >&5
+$as_echo "$ac_ct_AR" >&6; }
+else
+  { $as_echo "$as_me:$LINENO: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_ct_AR" = x; then
+    AR="false"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:$LINENO: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    AR=$ac_ct_AR
+  fi
+else
+  AR="$ac_cv_prog_AR"
+fi
+
+test -z "$AR" && AR=ar
+test -z "$AR_FLAGS" && AR_FLAGS=cru
+
+
+
+
+
+
+
+
+
+
+
+if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}strip", so it can be a program name with args.
+set dummy ${ac_tool_prefix}strip; ac_word=$2
+{ $as_echo "$as_me:$LINENO: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_STRIP+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$STRIP"; then
+  ac_cv_prog_STRIP="$STRIP" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_STRIP="${ac_tool_prefix}strip"
+    $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+IFS=$as_save_IFS
+
+fi
+fi
+STRIP=$ac_cv_prog_STRIP
+if test -n "$STRIP"; then
+  { $as_echo "$as_me:$LINENO: result: $STRIP" >&5
+$as_echo "$STRIP" >&6; }
+else
+  { $as_echo "$as_me:$LINENO: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_STRIP"; then
+  ac_ct_STRIP=$STRIP
+  # Extract the first word of "strip", so it can be a program name with args.
+set dummy strip; ac_word=$2
+{ $as_echo "$as_me:$LINENO: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_ac_ct_STRIP+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_STRIP"; then
+  ac_cv_prog_ac_ct_STRIP="$ac_ct_STRIP" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_ac_ct_STRIP="strip"
+    $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_STRIP=$ac_cv_prog_ac_ct_STRIP
+if test -n "$ac_ct_STRIP"; then
+  { $as_echo "$as_me:$LINENO: result: $ac_ct_STRIP" >&5
+$as_echo "$ac_ct_STRIP" >&6; }
+else
+  { $as_echo "$as_me:$LINENO: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_ct_STRIP" = x; then
+    STRIP=":"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:$LINENO: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    STRIP=$ac_ct_STRIP
+  fi
+else
+  STRIP="$ac_cv_prog_STRIP"
+fi
+
+test -z "$STRIP" && STRIP=:
+
+
+
+
+
+
+if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}ranlib", so it can be a program name with args.
+set dummy ${ac_tool_prefix}ranlib; ac_word=$2
+{ $as_echo "$as_me:$LINENO: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_RANLIB+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$RANLIB"; then
+  ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_RANLIB="${ac_tool_prefix}ranlib"
+    $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+IFS=$as_save_IFS
+
+fi
+fi
+RANLIB=$ac_cv_prog_RANLIB
+if test -n "$RANLIB"; then
+  { $as_echo "$as_me:$LINENO: result: $RANLIB" >&5
+$as_echo "$RANLIB" >&6; }
+else
+  { $as_echo "$as_me:$LINENO: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_RANLIB"; then
+  ac_ct_RANLIB=$RANLIB
+  # Extract the first word of "ranlib", so it can be a program name with args.
+set dummy ranlib; ac_word=$2
+{ $as_echo "$as_me:$LINENO: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_ac_ct_RANLIB+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_RANLIB"; then
+  ac_cv_prog_ac_ct_RANLIB="$ac_ct_RANLIB" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_ac_ct_RANLIB="ranlib"
+    $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_RANLIB=$ac_cv_prog_ac_ct_RANLIB
+if test -n "$ac_ct_RANLIB"; then
+  { $as_echo "$as_me:$LINENO: result: $ac_ct_RANLIB" >&5
+$as_echo "$ac_ct_RANLIB" >&6; }
+else
+  { $as_echo "$as_me:$LINENO: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_ct_RANLIB" = x; then
+    RANLIB=":"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:$LINENO: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    RANLIB=$ac_ct_RANLIB
+  fi
+else
+  RANLIB="$ac_cv_prog_RANLIB"
+fi
+
+test -z "$RANLIB" && RANLIB=:
+
+
+
+
+
+
+# Determine commands to create old-style static archives.
+old_archive_cmds='$AR $AR_FLAGS $oldlib$oldobjs'
+old_postinstall_cmds='chmod 644 $oldlib'
+old_postuninstall_cmds=
+
+if test -n "$RANLIB"; then
+  case $host_os in
+  openbsd*)
+    old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB -t \$oldlib"
+    ;;
+  *)
+    old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB \$oldlib"
+    ;;
+  esac
+  old_archive_cmds="$old_archive_cmds~\$RANLIB \$oldlib"
+fi
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+# If no C compiler was specified, use CC.
+LTCC=${LTCC-"$CC"}
+
+# If no C compiler flags were specified, use CFLAGS.
+LTCFLAGS=${LTCFLAGS-"$CFLAGS"}
+
+# Allow CC to be a program name with arguments.
+compiler=$CC
+
+
+# Check for command to grab the raw symbol name followed by C symbol from nm.
+{ $as_echo "$as_me:$LINENO: checking command to parse $NM output from $compiler object" >&5
+$as_echo_n "checking command to parse $NM output from $compiler object... " >&6; }
+if test "${lt_cv_sys_global_symbol_pipe+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+
+# These are sane defaults that work on at least a few old systems.
+# [They come from Ultrix.  What could be older than Ultrix?!! ;)]
+
+# Character class describing NM global symbol codes.
+symcode='[BCDEGRST]'
+
+# Regexp to match symbols that can be accessed directly from C.
+sympat='\([_A-Za-z][_A-Za-z0-9]*\)'
+
+# Define system-specific variables.
+case $host_os in
+aix*)
+  symcode='[BCDT]'
+  ;;
+cygwin* | mingw* | pw32* | cegcc*)
+  symcode='[ABCDGISTW]'
+  ;;
+hpux*)
+  if test "$host_cpu" = ia64; then
+    symcode='[ABCDEGRST]'
+  fi
+  ;;
+irix* | nonstopux*)
+  symcode='[BCDEGRST]'
+  ;;
+osf*)
+  symcode='[BCDEGQRST]'
+  ;;
+solaris*)
+  symcode='[BDRT]'
+  ;;
+sco3.2v5*)
+  symcode='[DT]'
+  ;;
+sysv4.2uw2*)
+  symcode='[DT]'
+  ;;
+sysv5* | sco5v6* | unixware* | OpenUNIX*)
+  symcode='[ABDT]'
+  ;;
+sysv4)
+  symcode='[DFNSTU]'
+  ;;
+esac
+
+# If we're using GNU nm, then use its standard symbol codes.
+case `$NM -V 2>&1` in
+*GNU* | *'with BFD'*)
+  symcode='[ABCDGIRSTW]' ;;
+esac
+
+# Transform an extracted symbol line into a proper C declaration.
+# Some systems (esp. on ia64) link data and code symbols differently,
+# so use this general approach.
+lt_cv_sys_global_symbol_to_cdecl="sed -n -e 's/^T .* \(.*\)$/extern int \1();/p' -e 's/^$symcode* .* \(.*\)$/extern char \1;/p'"
+
+# Transform an extracted symbol line into symbol name and symbol address
+lt_cv_sys_global_symbol_to_c_name_address="sed -n -e 's/^: \([^ ]*\) $/  {\\\"\1\\\", (void *) 0},/p' -e 's/^$symcode* \([^ ]*\) \([^ ]*\)$/  {\"\2\", (void *) \&\2},/p'"
+lt_cv_sys_global_symbol_to_c_name_address_lib_prefix="sed -n -e 's/^: \([^ ]*\) $/  {\\\"\1\\\", (void *) 0},/p' -e 's/^$symcode* \([^ ]*\) \(lib[^ ]*\)$/  {\"\2\", (void *) \&\2},/p' -e 's/^$symcode* \([^ ]*\) \([^ ]*\)$/  {\"lib\2\", (void *) \&\2},/p'"
+
+# Handle CRLF in mingw tool chain
+opt_cr=
+case $build_os in
+mingw*)
+  opt_cr=`$ECHO 'x\{0,1\}' | tr x '\015'` # option cr in regexp
+  ;;
+esac
+
+# Try without a prefix underscore, then with it.
+for ac_symprfx in "" "_"; do
+
+  # Transform symcode, sympat, and symprfx into a raw symbol and a C symbol.
+  symxfrm="\\1 $ac_symprfx\\2 \\2"
+
+  # Write the raw and C identifiers.
+  if test "$lt_cv_nm_interface" = "MS dumpbin"; then
+    # Fake it for dumpbin and say T for any non-static function
+    # and D for any global variable.
+    # Also find C++ and __fastcall symbols from MSVC++,
+    # which start with @ or ?.
+    lt_cv_sys_global_symbol_pipe="$AWK '"\
+"     {last_section=section; section=\$ 3};"\
+"     /Section length .*#relocs.*(pick any)/{hide[last_section]=1};"\
+"     \$ 0!~/External *\|/{next};"\
+"     / 0+ UNDEF /{next}; / UNDEF \([^|]\)*()/{next};"\
+"     {if(hide[section]) next};"\
+"     {f=0}; \$ 0~/\(\).*\|/{f=1}; {printf f ? \"T \" : \"D \"};"\
+"     {split(\$ 0, a, /\||\r/); split(a[2], s)};"\
+"     s[1]~/^[@?]/{print s[1], s[1]; next};"\
+"     s[1]~prfx {split(s[1],t,\"@\"); print t[1], substr(t[1],length(prfx))}"\
+"     ' prfx=^$ac_symprfx"
+  else
+    lt_cv_sys_global_symbol_pipe="sed -n -e 's/^.*[	 ]\($symcode$symcode*\)[	 ][	 ]*$ac_symprfx$sympat$opt_cr$/$symxfrm/p'"
+  fi
+
+  # Check to see that the pipe works correctly.
+  pipe_works=no
+
+  rm -f conftest*
+  cat > conftest.$ac_ext <<_LT_EOF
+#ifdef __cplusplus
+extern "C" {
+#endif
+char nm_test_var;
+void nm_test_func(void);
+void nm_test_func(void){}
+#ifdef __cplusplus
+}
+#endif
+int main(){nm_test_var='a';nm_test_func();return(0);}
+_LT_EOF
+
+  if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; then
+    # Now try to grab the symbols.
+    nlist=conftest.nm
+    if { (eval echo "$as_me:$LINENO: \"$NM conftest.$ac_objext \| $lt_cv_sys_global_symbol_pipe \> $nlist\"") >&5
+  (eval $NM conftest.$ac_objext \| $lt_cv_sys_global_symbol_pipe \> $nlist) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && test -s "$nlist"; then
+      # Try sorting and uniquifying the output.
+      if sort "$nlist" | uniq > "$nlist"T; then
+	mv -f "$nlist"T "$nlist"
+      else
+	rm -f "$nlist"T
+      fi
+
+      # Make sure that we snagged all the symbols we need.
+      if $GREP ' nm_test_var$' "$nlist" >/dev/null; then
+	if $GREP ' nm_test_func$' "$nlist" >/dev/null; then
+	  cat <<_LT_EOF > conftest.$ac_ext
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+_LT_EOF
+	  # Now generate the symbol file.
+	  eval "$lt_cv_sys_global_symbol_to_cdecl"' < "$nlist" | $GREP -v main >> conftest.$ac_ext'
+
+	  cat <<_LT_EOF >> conftest.$ac_ext
+
+/* The mapping between symbol names and symbols.  */
+const struct {
+  const char *name;
+  void       *address;
+}
+lt__PROGRAM__LTX_preloaded_symbols[] =
+{
+  { "@PROGRAM@", (void *) 0 },
+_LT_EOF
+	  $SED "s/^$symcode$symcode* \(.*\) \(.*\)$/  {\"\2\", (void *) \&\2},/" < "$nlist" | $GREP -v main >> conftest.$ac_ext
+	  cat <<\_LT_EOF >> conftest.$ac_ext
+  {0, (void *) 0}
+};
+
+/* This works around a problem in FreeBSD linker */
+#ifdef FREEBSD_WORKAROUND
+static const void *lt_preloaded_setup() {
+  return lt__PROGRAM__LTX_preloaded_symbols;
+}
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+_LT_EOF
+	  # Now try linking the two files.
+	  mv conftest.$ac_objext conftstm.$ac_objext
+	  lt_save_LIBS="$LIBS"
+	  lt_save_CFLAGS="$CFLAGS"
+	  LIBS="conftstm.$ac_objext"
+	  CFLAGS="$CFLAGS$lt_prog_compiler_no_builtin_flag"
+	  if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && test -s conftest${ac_exeext}; then
+	    pipe_works=yes
+	  fi
+	  LIBS="$lt_save_LIBS"
+	  CFLAGS="$lt_save_CFLAGS"
+	else
+	  echo "cannot find nm_test_func in $nlist" >&5
+	fi
+      else
+	echo "cannot find nm_test_var in $nlist" >&5
+      fi
+    else
+      echo "cannot run $lt_cv_sys_global_symbol_pipe" >&5
+    fi
+  else
+    echo "$progname: failed program was:" >&5
+    cat conftest.$ac_ext >&5
+  fi
+  rm -rf conftest* conftst*
+
+  # Do not use the global_symbol_pipe unless it works.
+  if test "$pipe_works" = yes; then
+    break
+  else
+    lt_cv_sys_global_symbol_pipe=
+  fi
+done
+
+fi
+
+if test -z "$lt_cv_sys_global_symbol_pipe"; then
+  lt_cv_sys_global_symbol_to_cdecl=
+fi
+if test -z "$lt_cv_sys_global_symbol_pipe$lt_cv_sys_global_symbol_to_cdecl"; then
+  { $as_echo "$as_me:$LINENO: result: failed" >&5
+$as_echo "failed" >&6; }
+else
+  { $as_echo "$as_me:$LINENO: result: ok" >&5
+$as_echo "ok" >&6; }
+fi
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+# Check whether --enable-libtool-lock was given.
+if test "${enable_libtool_lock+set}" = set; then
+  enableval=$enable_libtool_lock;
+fi
+
+test "x$enable_libtool_lock" != xno && enable_libtool_lock=yes
+
+# Some flags need to be propagated to the compiler or linker for good
+# libtool support.
+case $host in
+ia64-*-hpux*)
+  # Find out which ABI we are using.
+  echo 'int i;' > conftest.$ac_ext
+  if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; then
+    case `/usr/bin/file conftest.$ac_objext` in
+      *ELF-32*)
+	HPUX_IA64_MODE="32"
+	;;
+      *ELF-64*)
+	HPUX_IA64_MODE="64"
+	;;
+    esac
+  fi
+  rm -rf conftest*
+  ;;
+*-*-irix6*)
+  # Find out which ABI we are using.
+  echo '#line 7087 "configure"' > conftest.$ac_ext
+  if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; then
+    if test "$lt_cv_prog_gnu_ld" = yes; then
+      case `/usr/bin/file conftest.$ac_objext` in
+	*32-bit*)
+	  LD="${LD-ld} -melf32bsmip"
+	  ;;
+	*N32*)
+	  LD="${LD-ld} -melf32bmipn32"
+	  ;;
+	*64-bit*)
+	  LD="${LD-ld} -melf64bmip"
+	;;
+      esac
+    else
+      case `/usr/bin/file conftest.$ac_objext` in
+	*32-bit*)
+	  LD="${LD-ld} -32"
+	  ;;
+	*N32*)
+	  LD="${LD-ld} -n32"
+	  ;;
+	*64-bit*)
+	  LD="${LD-ld} -64"
+	  ;;
+      esac
+    fi
+  fi
+  rm -rf conftest*
+  ;;
+
+x86_64-*kfreebsd*-gnu|x86_64-*linux*|ppc*-*linux*|powerpc*-*linux*| \
+s390*-*linux*|s390*-*tpf*|sparc*-*linux*)
+  # Find out which ABI we are using.
+  echo 'int i;' > conftest.$ac_ext
+  if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; then
+    case `/usr/bin/file conftest.o` in
+      *32-bit*)
+	case $host in
+	  x86_64-*kfreebsd*-gnu)
+	    LD="${LD-ld} -m elf_i386_fbsd"
+	    ;;
+	  x86_64-*linux*)
+	    LD="${LD-ld} -m elf_i386"
+	    ;;
+	  ppc64-*linux*|powerpc64-*linux*)
+	    LD="${LD-ld} -m elf32ppclinux"
+	    ;;
+	  s390x-*linux*)
+	    LD="${LD-ld} -m elf_s390"
+	    ;;
+	  sparc64-*linux*)
+	    LD="${LD-ld} -m elf32_sparc"
+	    ;;
+	esac
+	;;
+      *64-bit*)
+	case $host in
+	  x86_64-*kfreebsd*-gnu)
+	    LD="${LD-ld} -m elf_x86_64_fbsd"
+	    ;;
+	  x86_64-*linux*)
+	    LD="${LD-ld} -m elf_x86_64"
+	    ;;
+	  ppc*-*linux*|powerpc*-*linux*)
+	    LD="${LD-ld} -m elf64ppc"
+	    ;;
+	  s390*-*linux*|s390*-*tpf*)
+	    LD="${LD-ld} -m elf64_s390"
+	    ;;
+	  sparc*-*linux*)
+	    LD="${LD-ld} -m elf64_sparc"
+	    ;;
+	esac
+	;;
+    esac
+  fi
+  rm -rf conftest*
+  ;;
+
+*-*-sco3.2v5*)
+  # On SCO OpenServer 5, we need -belf to get full-featured binaries.
+  SAVE_CFLAGS="$CFLAGS"
+  CFLAGS="$CFLAGS -belf"
+  { $as_echo "$as_me:$LINENO: checking whether the C compiler needs -belf" >&5
+$as_echo_n "checking whether the C compiler needs -belf... " >&6; }
+if test "${lt_cv_cc_needs_belf+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+     cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext && {
+	 test "$cross_compiling" = yes ||
+	 $as_test_x conftest$ac_exeext
+       }; then
+  lt_cv_cc_needs_belf=yes
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	lt_cv_cc_needs_belf=no
+fi
+
+rm -rf conftest.dSYM
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+     ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+fi
+{ $as_echo "$as_me:$LINENO: result: $lt_cv_cc_needs_belf" >&5
+$as_echo "$lt_cv_cc_needs_belf" >&6; }
+  if test x"$lt_cv_cc_needs_belf" != x"yes"; then
+    # this is probably gcc 2.8.0, egcs 1.0 or newer; no need for -belf
+    CFLAGS="$SAVE_CFLAGS"
+  fi
+  ;;
+sparc*-*solaris*)
+  # Find out which ABI we are using.
+  echo 'int i;' > conftest.$ac_ext
+  if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; then
+    case `/usr/bin/file conftest.o` in
+    *64-bit*)
+      case $lt_cv_prog_gnu_ld in
+      yes*) LD="${LD-ld} -m elf64_sparc" ;;
+      *)
+	if ${LD-ld} -64 -r -o conftest2.o conftest.o >/dev/null 2>&1; then
+	  LD="${LD-ld} -64"
+	fi
+	;;
+      esac
+      ;;
+    esac
+  fi
+  rm -rf conftest*
+  ;;
+esac
+
+need_locks="$enable_libtool_lock"
+
+
+  case $host_os in
+    rhapsody* | darwin*)
+    if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}dsymutil", so it can be a program name with args.
+set dummy ${ac_tool_prefix}dsymutil; ac_word=$2
+{ $as_echo "$as_me:$LINENO: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_DSYMUTIL+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$DSYMUTIL"; then
+  ac_cv_prog_DSYMUTIL="$DSYMUTIL" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_DSYMUTIL="${ac_tool_prefix}dsymutil"
+    $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+IFS=$as_save_IFS
+
+fi
+fi
+DSYMUTIL=$ac_cv_prog_DSYMUTIL
+if test -n "$DSYMUTIL"; then
+  { $as_echo "$as_me:$LINENO: result: $DSYMUTIL" >&5
+$as_echo "$DSYMUTIL" >&6; }
+else
+  { $as_echo "$as_me:$LINENO: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_DSYMUTIL"; then
+  ac_ct_DSYMUTIL=$DSYMUTIL
+  # Extract the first word of "dsymutil", so it can be a program name with args.
+set dummy dsymutil; ac_word=$2
+{ $as_echo "$as_me:$LINENO: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_ac_ct_DSYMUTIL+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_DSYMUTIL"; then
+  ac_cv_prog_ac_ct_DSYMUTIL="$ac_ct_DSYMUTIL" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_ac_ct_DSYMUTIL="dsymutil"
+    $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_DSYMUTIL=$ac_cv_prog_ac_ct_DSYMUTIL
+if test -n "$ac_ct_DSYMUTIL"; then
+  { $as_echo "$as_me:$LINENO: result: $ac_ct_DSYMUTIL" >&5
+$as_echo "$ac_ct_DSYMUTIL" >&6; }
+else
+  { $as_echo "$as_me:$LINENO: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_ct_DSYMUTIL" = x; then
+    DSYMUTIL=":"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:$LINENO: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    DSYMUTIL=$ac_ct_DSYMUTIL
+  fi
+else
+  DSYMUTIL="$ac_cv_prog_DSYMUTIL"
+fi
+
+    if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}nmedit", so it can be a program name with args.
+set dummy ${ac_tool_prefix}nmedit; ac_word=$2
+{ $as_echo "$as_me:$LINENO: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_NMEDIT+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$NMEDIT"; then
+  ac_cv_prog_NMEDIT="$NMEDIT" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_NMEDIT="${ac_tool_prefix}nmedit"
+    $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+IFS=$as_save_IFS
+
+fi
+fi
+NMEDIT=$ac_cv_prog_NMEDIT
+if test -n "$NMEDIT"; then
+  { $as_echo "$as_me:$LINENO: result: $NMEDIT" >&5
+$as_echo "$NMEDIT" >&6; }
+else
+  { $as_echo "$as_me:$LINENO: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_NMEDIT"; then
+  ac_ct_NMEDIT=$NMEDIT
+  # Extract the first word of "nmedit", so it can be a program name with args.
+set dummy nmedit; ac_word=$2
+{ $as_echo "$as_me:$LINENO: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_ac_ct_NMEDIT+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_NMEDIT"; then
+  ac_cv_prog_ac_ct_NMEDIT="$ac_ct_NMEDIT" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_ac_ct_NMEDIT="nmedit"
+    $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_NMEDIT=$ac_cv_prog_ac_ct_NMEDIT
+if test -n "$ac_ct_NMEDIT"; then
+  { $as_echo "$as_me:$LINENO: result: $ac_ct_NMEDIT" >&5
+$as_echo "$ac_ct_NMEDIT" >&6; }
+else
+  { $as_echo "$as_me:$LINENO: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_ct_NMEDIT" = x; then
+    NMEDIT=":"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:$LINENO: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    NMEDIT=$ac_ct_NMEDIT
+  fi
+else
+  NMEDIT="$ac_cv_prog_NMEDIT"
+fi
+
+    if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}lipo", so it can be a program name with args.
+set dummy ${ac_tool_prefix}lipo; ac_word=$2
+{ $as_echo "$as_me:$LINENO: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_LIPO+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$LIPO"; then
+  ac_cv_prog_LIPO="$LIPO" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_LIPO="${ac_tool_prefix}lipo"
+    $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+IFS=$as_save_IFS
+
+fi
+fi
+LIPO=$ac_cv_prog_LIPO
+if test -n "$LIPO"; then
+  { $as_echo "$as_me:$LINENO: result: $LIPO" >&5
+$as_echo "$LIPO" >&6; }
+else
+  { $as_echo "$as_me:$LINENO: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_LIPO"; then
+  ac_ct_LIPO=$LIPO
+  # Extract the first word of "lipo", so it can be a program name with args.
+set dummy lipo; ac_word=$2
+{ $as_echo "$as_me:$LINENO: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_ac_ct_LIPO+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_LIPO"; then
+  ac_cv_prog_ac_ct_LIPO="$ac_ct_LIPO" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_ac_ct_LIPO="lipo"
+    $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_LIPO=$ac_cv_prog_ac_ct_LIPO
+if test -n "$ac_ct_LIPO"; then
+  { $as_echo "$as_me:$LINENO: result: $ac_ct_LIPO" >&5
+$as_echo "$ac_ct_LIPO" >&6; }
+else
+  { $as_echo "$as_me:$LINENO: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_ct_LIPO" = x; then
+    LIPO=":"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:$LINENO: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    LIPO=$ac_ct_LIPO
+  fi
+else
+  LIPO="$ac_cv_prog_LIPO"
+fi
+
+    if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}otool", so it can be a program name with args.
+set dummy ${ac_tool_prefix}otool; ac_word=$2
+{ $as_echo "$as_me:$LINENO: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_OTOOL+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$OTOOL"; then
+  ac_cv_prog_OTOOL="$OTOOL" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_OTOOL="${ac_tool_prefix}otool"
+    $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+IFS=$as_save_IFS
+
+fi
+fi
+OTOOL=$ac_cv_prog_OTOOL
+if test -n "$OTOOL"; then
+  { $as_echo "$as_me:$LINENO: result: $OTOOL" >&5
+$as_echo "$OTOOL" >&6; }
+else
+  { $as_echo "$as_me:$LINENO: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_OTOOL"; then
+  ac_ct_OTOOL=$OTOOL
+  # Extract the first word of "otool", so it can be a program name with args.
+set dummy otool; ac_word=$2
+{ $as_echo "$as_me:$LINENO: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_ac_ct_OTOOL+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_OTOOL"; then
+  ac_cv_prog_ac_ct_OTOOL="$ac_ct_OTOOL" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_ac_ct_OTOOL="otool"
+    $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_OTOOL=$ac_cv_prog_ac_ct_OTOOL
+if test -n "$ac_ct_OTOOL"; then
+  { $as_echo "$as_me:$LINENO: result: $ac_ct_OTOOL" >&5
+$as_echo "$ac_ct_OTOOL" >&6; }
+else
+  { $as_echo "$as_me:$LINENO: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_ct_OTOOL" = x; then
+    OTOOL=":"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:$LINENO: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    OTOOL=$ac_ct_OTOOL
+  fi
+else
+  OTOOL="$ac_cv_prog_OTOOL"
+fi
+
+    if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}otool64", so it can be a program name with args.
+set dummy ${ac_tool_prefix}otool64; ac_word=$2
+{ $as_echo "$as_me:$LINENO: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_OTOOL64+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$OTOOL64"; then
+  ac_cv_prog_OTOOL64="$OTOOL64" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_OTOOL64="${ac_tool_prefix}otool64"
+    $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+IFS=$as_save_IFS
+
+fi
+fi
+OTOOL64=$ac_cv_prog_OTOOL64
+if test -n "$OTOOL64"; then
+  { $as_echo "$as_me:$LINENO: result: $OTOOL64" >&5
+$as_echo "$OTOOL64" >&6; }
+else
+  { $as_echo "$as_me:$LINENO: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_OTOOL64"; then
+  ac_ct_OTOOL64=$OTOOL64
+  # Extract the first word of "otool64", so it can be a program name with args.
+set dummy otool64; ac_word=$2
+{ $as_echo "$as_me:$LINENO: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_ac_ct_OTOOL64+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_OTOOL64"; then
+  ac_cv_prog_ac_ct_OTOOL64="$ac_ct_OTOOL64" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_ac_ct_OTOOL64="otool64"
+    $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_OTOOL64=$ac_cv_prog_ac_ct_OTOOL64
+if test -n "$ac_ct_OTOOL64"; then
+  { $as_echo "$as_me:$LINENO: result: $ac_ct_OTOOL64" >&5
+$as_echo "$ac_ct_OTOOL64" >&6; }
+else
+  { $as_echo "$as_me:$LINENO: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_ct_OTOOL64" = x; then
+    OTOOL64=":"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:$LINENO: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    OTOOL64=$ac_ct_OTOOL64
+  fi
+else
+  OTOOL64="$ac_cv_prog_OTOOL64"
+fi
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+    { $as_echo "$as_me:$LINENO: checking for -single_module linker flag" >&5
+$as_echo_n "checking for -single_module linker flag... " >&6; }
+if test "${lt_cv_apple_cc_single_mod+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  lt_cv_apple_cc_single_mod=no
+      if test -z "${LT_MULTI_MODULE}"; then
+	# By default we will add the -single_module flag. You can override
+	# by either setting the environment variable LT_MULTI_MODULE
+	# non-empty at configure time, or by adding -multi_module to the
+	# link flags.
+	rm -rf libconftest.dylib*
+	echo "int foo(void){return 1;}" > conftest.c
+	echo "$LTCC $LTCFLAGS $LDFLAGS -o libconftest.dylib \
+-dynamiclib -Wl,-single_module conftest.c" >&5
+	$LTCC $LTCFLAGS $LDFLAGS -o libconftest.dylib \
+	  -dynamiclib -Wl,-single_module conftest.c 2>conftest.err
+        _lt_result=$?
+	if test -f libconftest.dylib && test ! -s conftest.err && test $_lt_result = 0; then
+	  lt_cv_apple_cc_single_mod=yes
+	else
+	  cat conftest.err >&5
+	fi
+	rm -rf libconftest.dylib*
+	rm -f conftest.*
+      fi
+fi
+{ $as_echo "$as_me:$LINENO: result: $lt_cv_apple_cc_single_mod" >&5
+$as_echo "$lt_cv_apple_cc_single_mod" >&6; }
+    { $as_echo "$as_me:$LINENO: checking for -exported_symbols_list linker flag" >&5
+$as_echo_n "checking for -exported_symbols_list linker flag... " >&6; }
+if test "${lt_cv_ld_exported_symbols_list+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  lt_cv_ld_exported_symbols_list=no
+      save_LDFLAGS=$LDFLAGS
+      echo "_main" > conftest.sym
+      LDFLAGS="$LDFLAGS -Wl,-exported_symbols_list,conftest.sym"
+      cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext && {
+	 test "$cross_compiling" = yes ||
+	 $as_test_x conftest$ac_exeext
+       }; then
+  lt_cv_ld_exported_symbols_list=yes
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	lt_cv_ld_exported_symbols_list=no
+fi
+
+rm -rf conftest.dSYM
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+	LDFLAGS="$save_LDFLAGS"
+
+fi
+{ $as_echo "$as_me:$LINENO: result: $lt_cv_ld_exported_symbols_list" >&5
+$as_echo "$lt_cv_ld_exported_symbols_list" >&6; }
+    case $host_os in
+    rhapsody* | darwin1.[012])
+      _lt_dar_allow_undefined='${wl}-undefined ${wl}suppress' ;;
+    darwin1.*)
+      _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' ;;
+    darwin*) # darwin 5.x on
+      # if running on 10.5 or later, the deployment target defaults
+      # to the OS version, if on x86, and 10.4, the deployment
+      # target defaults to 10.4. Don't you love it?
+      case ${MACOSX_DEPLOYMENT_TARGET-10.0},$host in
+	10.0,*86*-darwin8*|10.0,*-darwin[91]*)
+	  _lt_dar_allow_undefined='${wl}-undefined ${wl}dynamic_lookup' ;;
+	10.[012]*)
+	  _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' ;;
+	10.*)
+	  _lt_dar_allow_undefined='${wl}-undefined ${wl}dynamic_lookup' ;;
+      esac
+    ;;
+  esac
+    if test "$lt_cv_apple_cc_single_mod" = "yes"; then
+      _lt_dar_single_mod='$single_module'
+    fi
+    if test "$lt_cv_ld_exported_symbols_list" = "yes"; then
+      _lt_dar_export_syms=' ${wl}-exported_symbols_list,$output_objdir/${libname}-symbols.expsym'
+    else
+      _lt_dar_export_syms='~$NMEDIT -s $output_objdir/${libname}-symbols.expsym ${lib}'
+    fi
+    if test "$DSYMUTIL" != ":"; then
+      _lt_dsymutil='~$DSYMUTIL $lib || :'
+    else
+      _lt_dsymutil=
+    fi
+    ;;
+  esac
+
+
+{ $as_echo "$as_me:$LINENO: checking for ANSI C header files" >&5
+$as_echo_n "checking for ANSI C header files... " >&6; }
+if test "${ac_cv_header_stdc+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include <float.h>
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  ac_cv_header_stdc=yes
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_cv_header_stdc=no
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
+if test $ac_cv_header_stdc = yes; then
+  # SunOS 4.x string.h does not declare mem*, contrary to ANSI.
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <string.h>
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "memchr" >/dev/null 2>&1; then
+  :
+else
+  ac_cv_header_stdc=no
+fi
+rm -f conftest*
+
+fi
+
+if test $ac_cv_header_stdc = yes; then
+  # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI.
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <stdlib.h>
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "free" >/dev/null 2>&1; then
+  :
+else
+  ac_cv_header_stdc=no
+fi
+rm -f conftest*
+
+fi
+
+if test $ac_cv_header_stdc = yes; then
+  # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi.
+  if test "$cross_compiling" = yes; then
+  :
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <ctype.h>
+#include <stdlib.h>
+#if ((' ' & 0x0FF) == 0x020)
+# define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
+# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c))
+#else
+# define ISLOWER(c) \
+		   (('a' <= (c) && (c) <= 'i') \
+		     || ('j' <= (c) && (c) <= 'r') \
+		     || ('s' <= (c) && (c) <= 'z'))
+# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c))
+#endif
+
+#define XOR(e, f) (((e) && !(f)) || (!(e) && (f)))
+int
+main ()
+{
+  int i;
+  for (i = 0; i < 256; i++)
+    if (XOR (islower (i), ISLOWER (i))
+	|| toupper (i) != TOUPPER (i))
+      return 2;
+  return 0;
+}
+_ACEOF
+rm -f conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_link") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && { ac_try='./conftest$ac_exeext'
+  { (case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_try") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  :
+else
+  $as_echo "$as_me: program exited with status $ac_status" >&5
+$as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+( exit $ac_status )
+ac_cv_header_stdc=no
+fi
+rm -rf conftest.dSYM
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
+fi
+
+
+fi
+fi
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_header_stdc" >&5
+$as_echo "$ac_cv_header_stdc" >&6; }
+if test $ac_cv_header_stdc = yes; then
+
+cat >>confdefs.h <<\_ACEOF
+#define STDC_HEADERS 1
+_ACEOF
+
+fi
+
+# On IRIX 5.3, sys/types and inttypes.h are conflicting.
+
+
+
+
+
+
+
+
+
+for ac_header in sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \
+		  inttypes.h stdint.h unistd.h
+do
+as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
+{ $as_echo "$as_me:$LINENO: checking for $ac_header" >&5
+$as_echo_n "checking for $ac_header... " >&6; }
+if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then
+  $as_echo_n "(cached) " >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_includes_default
+
+#include <$ac_header>
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  eval "$as_ac_Header=yes"
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	eval "$as_ac_Header=no"
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+ac_res=`eval 'as_val=${'$as_ac_Header'}
+		 $as_echo "$as_val"'`
+	       { $as_echo "$as_me:$LINENO: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+as_val=`eval 'as_val=${'$as_ac_Header'}
+		 $as_echo "$as_val"'`
+   if test "x$as_val" = x""yes; then
+  cat >>confdefs.h <<_ACEOF
+#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1
+_ACEOF
+
+fi
+
+done
+
+
+
+for ac_header in dlfcn.h
+do
+as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
+{ $as_echo "$as_me:$LINENO: checking for $ac_header" >&5
+$as_echo_n "checking for $ac_header... " >&6; }
+if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then
+  $as_echo_n "(cached) " >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_includes_default
+
+#include <$ac_header>
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  eval "$as_ac_Header=yes"
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	eval "$as_ac_Header=no"
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+ac_res=`eval 'as_val=${'$as_ac_Header'}
+		 $as_echo "$as_val"'`
+	       { $as_echo "$as_me:$LINENO: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+as_val=`eval 'as_val=${'$as_ac_Header'}
+		 $as_echo "$as_val"'`
+   if test "x$as_val" = x""yes; then
+  cat >>confdefs.h <<_ACEOF
+#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1
+_ACEOF
+
+fi
+
+done
+
+
+
+# Set options
+
+
+
+        enable_dlopen=no
+
+
+  enable_win32_dll=no
+
+
+
+
+
+# Check whether --with-pic was given.
+if test "${with_pic+set}" = set; then
+  withval=$with_pic; pic_mode="$withval"
+else
+  pic_mode=default
+fi
+
+
+test -z "$pic_mode" && pic_mode=default
+
+
+
+
+
+
+
+  # Check whether --enable-fast-install was given.
+if test "${enable_fast_install+set}" = set; then
+  enableval=$enable_fast_install; p=${PACKAGE-default}
+    case $enableval in
+    yes) enable_fast_install=yes ;;
+    no) enable_fast_install=no ;;
+    *)
+      enable_fast_install=no
+      # Look at the argument we got.  We use all the common list separators.
+      lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR,"
+      for pkg in $enableval; do
+	IFS="$lt_save_ifs"
+	if test "X$pkg" = "X$p"; then
+	  enable_fast_install=yes
+	fi
+      done
+      IFS="$lt_save_ifs"
+      ;;
+    esac
+else
+  enable_fast_install=yes
+fi
+
+
+
+
+
+
+
+
+
+
+
+# This can be used to rebuild libtool when needed
+LIBTOOL_DEPS="$ltmain"
+
+# Always use our own libtool.
+LIBTOOL='$(SHELL) $(top_builddir)/libtool'
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+test -z "$LN_S" && LN_S="ln -s"
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+if test -n "${ZSH_VERSION+set}" ; then
+   setopt NO_GLOB_SUBST
+fi
+
+{ $as_echo "$as_me:$LINENO: checking for objdir" >&5
+$as_echo_n "checking for objdir... " >&6; }
+if test "${lt_cv_objdir+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  rm -f .libs 2>/dev/null
+mkdir .libs 2>/dev/null
+if test -d .libs; then
+  lt_cv_objdir=.libs
+else
+  # MS-DOS does not allow filenames that begin with a dot.
+  lt_cv_objdir=_libs
+fi
+rmdir .libs 2>/dev/null
+fi
+{ $as_echo "$as_me:$LINENO: result: $lt_cv_objdir" >&5
+$as_echo "$lt_cv_objdir" >&6; }
+objdir=$lt_cv_objdir
+
+
+
+
+
+cat >>confdefs.h <<_ACEOF
+#define LT_OBJDIR "$lt_cv_objdir/"
+_ACEOF
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+case $host_os in
+aix3*)
+  # AIX sometimes has problems with the GCC collect2 program.  For some
+  # reason, if we set the COLLECT_NAMES environment variable, the problems
+  # vanish in a puff of smoke.
+  if test "X${COLLECT_NAMES+set}" != Xset; then
+    COLLECT_NAMES=
+    export COLLECT_NAMES
+  fi
+  ;;
+esac
+
+# Sed substitution that helps us do robust quoting.  It backslashifies
+# metacharacters that are still active within double-quoted strings.
+sed_quote_subst='s/\(["`$\\]\)/\\\1/g'
+
+# Same as above, but do not quote variable references.
+double_quote_subst='s/\(["`\\]\)/\\\1/g'
+
+# Sed substitution to delay expansion of an escaped shell variable in a
+# double_quote_subst'ed string.
+delay_variable_subst='s/\\\\\\\\\\\$/\\\\\\$/g'
+
+# Sed substitution to delay expansion of an escaped single quote.
+delay_single_quote_subst='s/'\''/'\'\\\\\\\'\''/g'
+
+# Sed substitution to avoid accidental globbing in evaled expressions
+no_glob_subst='s/\*/\\\*/g'
+
+# Global variables:
+ofile=libtool
+can_build_shared=yes
+
+# All known linkers require a `.a' archive for static linking (except MSVC,
+# which needs '.lib').
+libext=a
+
+with_gnu_ld="$lt_cv_prog_gnu_ld"
+
+old_CC="$CC"
+old_CFLAGS="$CFLAGS"
+
+# Set sane defaults for various variables
+test -z "$CC" && CC=cc
+test -z "$LTCC" && LTCC=$CC
+test -z "$LTCFLAGS" && LTCFLAGS=$CFLAGS
+test -z "$LD" && LD=ld
+test -z "$ac_objext" && ac_objext=o
+
+for cc_temp in $compiler""; do
+  case $cc_temp in
+    compile | *[\\/]compile | ccache | *[\\/]ccache ) ;;
+    distcc | *[\\/]distcc | purify | *[\\/]purify ) ;;
+    \-*) ;;
+    *) break;;
+  esac
+done
+cc_basename=`$ECHO "X$cc_temp" | $Xsed -e 's%.*/%%' -e "s%^$host_alias-%%"`
+
+
+# Only perform the check for file, if the check method requires it
+test -z "$MAGIC_CMD" && MAGIC_CMD=file
+case $deplibs_check_method in
+file_magic*)
+  if test "$file_magic_cmd" = '$MAGIC_CMD'; then
+    { $as_echo "$as_me:$LINENO: checking for ${ac_tool_prefix}file" >&5
+$as_echo_n "checking for ${ac_tool_prefix}file... " >&6; }
+if test "${lt_cv_path_MAGIC_CMD+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  case $MAGIC_CMD in
+[\\/*] |  ?:[\\/]*)
+  lt_cv_path_MAGIC_CMD="$MAGIC_CMD" # Let the user override the test with a path.
+  ;;
+*)
+  lt_save_MAGIC_CMD="$MAGIC_CMD"
+  lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
+  ac_dummy="/usr/bin$PATH_SEPARATOR$PATH"
+  for ac_dir in $ac_dummy; do
+    IFS="$lt_save_ifs"
+    test -z "$ac_dir" && ac_dir=.
+    if test -f $ac_dir/${ac_tool_prefix}file; then
+      lt_cv_path_MAGIC_CMD="$ac_dir/${ac_tool_prefix}file"
+      if test -n "$file_magic_test_file"; then
+	case $deplibs_check_method in
+	"file_magic "*)
+	  file_magic_regex=`expr "$deplibs_check_method" : "file_magic \(.*\)"`
+	  MAGIC_CMD="$lt_cv_path_MAGIC_CMD"
+	  if eval $file_magic_cmd \$file_magic_test_file 2> /dev/null |
+	    $EGREP "$file_magic_regex" > /dev/null; then
+	    :
+	  else
+	    cat <<_LT_EOF 1>&2
+
+*** Warning: the command libtool uses to detect shared libraries,
+*** $file_magic_cmd, produces output that libtool cannot recognize.
+*** The result is that libtool may fail to recognize shared libraries
+*** as such.  This will affect the creation of libtool libraries that
+*** depend on shared libraries, but programs linked with such libtool
+*** libraries will work regardless of this problem.  Nevertheless, you
+*** may want to report the problem to your system manager and/or to
+*** bug-libtool at gnu.org
+
+_LT_EOF
+	  fi ;;
+	esac
+      fi
+      break
+    fi
+  done
+  IFS="$lt_save_ifs"
+  MAGIC_CMD="$lt_save_MAGIC_CMD"
+  ;;
+esac
+fi
+
+MAGIC_CMD="$lt_cv_path_MAGIC_CMD"
+if test -n "$MAGIC_CMD"; then
+  { $as_echo "$as_me:$LINENO: result: $MAGIC_CMD" >&5
+$as_echo "$MAGIC_CMD" >&6; }
+else
+  { $as_echo "$as_me:$LINENO: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+
+
+
+if test -z "$lt_cv_path_MAGIC_CMD"; then
+  if test -n "$ac_tool_prefix"; then
+    { $as_echo "$as_me:$LINENO: checking for file" >&5
+$as_echo_n "checking for file... " >&6; }
+if test "${lt_cv_path_MAGIC_CMD+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  case $MAGIC_CMD in
+[\\/*] |  ?:[\\/]*)
+  lt_cv_path_MAGIC_CMD="$MAGIC_CMD" # Let the user override the test with a path.
+  ;;
+*)
+  lt_save_MAGIC_CMD="$MAGIC_CMD"
+  lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
+  ac_dummy="/usr/bin$PATH_SEPARATOR$PATH"
+  for ac_dir in $ac_dummy; do
+    IFS="$lt_save_ifs"
+    test -z "$ac_dir" && ac_dir=.
+    if test -f $ac_dir/file; then
+      lt_cv_path_MAGIC_CMD="$ac_dir/file"
+      if test -n "$file_magic_test_file"; then
+	case $deplibs_check_method in
+	"file_magic "*)
+	  file_magic_regex=`expr "$deplibs_check_method" : "file_magic \(.*\)"`
+	  MAGIC_CMD="$lt_cv_path_MAGIC_CMD"
+	  if eval $file_magic_cmd \$file_magic_test_file 2> /dev/null |
+	    $EGREP "$file_magic_regex" > /dev/null; then
+	    :
+	  else
+	    cat <<_LT_EOF 1>&2
+
+*** Warning: the command libtool uses to detect shared libraries,
+*** $file_magic_cmd, produces output that libtool cannot recognize.
+*** The result is that libtool may fail to recognize shared libraries
+*** as such.  This will affect the creation of libtool libraries that
+*** depend on shared libraries, but programs linked with such libtool
+*** libraries will work regardless of this problem.  Nevertheless, you
+*** may want to report the problem to your system manager and/or to
+*** bug-libtool at gnu.org
+
+_LT_EOF
+	  fi ;;
+	esac
+      fi
+      break
+    fi
+  done
+  IFS="$lt_save_ifs"
+  MAGIC_CMD="$lt_save_MAGIC_CMD"
+  ;;
+esac
+fi
+
+MAGIC_CMD="$lt_cv_path_MAGIC_CMD"
+if test -n "$MAGIC_CMD"; then
+  { $as_echo "$as_me:$LINENO: result: $MAGIC_CMD" >&5
+$as_echo "$MAGIC_CMD" >&6; }
+else
+  { $as_echo "$as_me:$LINENO: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  else
+    MAGIC_CMD=:
+  fi
+fi
+
+  fi
+  ;;
+esac
+
+# Use C for the default configuration in the libtool script
+
+lt_save_CC="$CC"
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+# Source file extension for C test sources.
+ac_ext=c
+
+# Object file extension for compiled C test sources.
+objext=o
+objext=$objext
+
+# Code to be used in simple compile tests
+lt_simple_compile_test_code="int some_variable = 0;"
+
+# Code to be used in simple link tests
+lt_simple_link_test_code='int main(){return(0);}'
+
+
+
+
+
+
+
+# If no C compiler was specified, use CC.
+LTCC=${LTCC-"$CC"}
+
+# If no C compiler flags were specified, use CFLAGS.
+LTCFLAGS=${LTCFLAGS-"$CFLAGS"}
+
+# Allow CC to be a program name with arguments.
+compiler=$CC
+
+# Save the default compiler, since it gets overwritten when the other
+# tags are being tested, and _LT_TAGVAR(compiler, []) is a NOP.
+compiler_DEFAULT=$CC
+
+# save warnings/boilerplate of simple test code
+ac_outfile=conftest.$ac_objext
+echo "$lt_simple_compile_test_code" >conftest.$ac_ext
+eval "$ac_compile" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err
+_lt_compiler_boilerplate=`cat conftest.err`
+$RM conftest*
+
+ac_outfile=conftest.$ac_objext
+echo "$lt_simple_link_test_code" >conftest.$ac_ext
+eval "$ac_link" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err
+_lt_linker_boilerplate=`cat conftest.err`
+$RM -r conftest*
+
+
+## CAVEAT EMPTOR:
+## There is no encapsulation within the following macros, do not change
+## the running order or otherwise move them around unless you know exactly
+## what you are doing...
+if test -n "$compiler"; then
+
+lt_prog_compiler_no_builtin_flag=
+
+if test "$GCC" = yes; then
+  lt_prog_compiler_no_builtin_flag=' -fno-builtin'
+
+  { $as_echo "$as_me:$LINENO: checking if $compiler supports -fno-rtti -fno-exceptions" >&5
+$as_echo_n "checking if $compiler supports -fno-rtti -fno-exceptions... " >&6; }
+if test "${lt_cv_prog_compiler_rtti_exceptions+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  lt_cv_prog_compiler_rtti_exceptions=no
+   ac_outfile=conftest.$ac_objext
+   echo "$lt_simple_compile_test_code" > conftest.$ac_ext
+   lt_compiler_flag="-fno-rtti -fno-exceptions"
+   # Insert the option either (1) after the last *FLAGS variable, or
+   # (2) before a word containing "conftest.", or (3) at the end.
+   # Note that $ac_compile itself does not contain backslashes and begins
+   # with a dollar sign (not a hyphen), so the echo should work correctly.
+   # The option is referenced via a variable to avoid confusing sed.
+   lt_compile=`echo "$ac_compile" | $SED \
+   -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
+   -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
+   -e 's:$: $lt_compiler_flag:'`
+   (eval echo "\"\$as_me:8648: $lt_compile\"" >&5)
+   (eval "$lt_compile" 2>conftest.err)
+   ac_status=$?
+   cat conftest.err >&5
+   echo "$as_me:8652: \$? = $ac_status" >&5
+   if (exit $ac_status) && test -s "$ac_outfile"; then
+     # The compiler can only warn and ignore the option if not recognized
+     # So say no if there are warnings other than the usual output.
+     $ECHO "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' >conftest.exp
+     $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2
+     if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then
+       lt_cv_prog_compiler_rtti_exceptions=yes
+     fi
+   fi
+   $RM conftest*
+
+fi
+{ $as_echo "$as_me:$LINENO: result: $lt_cv_prog_compiler_rtti_exceptions" >&5
+$as_echo "$lt_cv_prog_compiler_rtti_exceptions" >&6; }
+
+if test x"$lt_cv_prog_compiler_rtti_exceptions" = xyes; then
+    lt_prog_compiler_no_builtin_flag="$lt_prog_compiler_no_builtin_flag -fno-rtti -fno-exceptions"
+else
+    :
+fi
+
+fi
+
+
+
+
+
+
+  lt_prog_compiler_wl=
+lt_prog_compiler_pic=
+lt_prog_compiler_static=
+
+{ $as_echo "$as_me:$LINENO: checking for $compiler option to produce PIC" >&5
+$as_echo_n "checking for $compiler option to produce PIC... " >&6; }
+
+  if test "$GCC" = yes; then
+    lt_prog_compiler_wl='-Wl,'
+    lt_prog_compiler_static='-static'
+
+    case $host_os in
+      aix*)
+      # All AIX code is PIC.
+      if test "$host_cpu" = ia64; then
+	# AIX 5 now supports IA64 processor
+	lt_prog_compiler_static='-Bstatic'
+      fi
+      ;;
+
+    amigaos*)
+      case $host_cpu in
+      powerpc)
+            # see comment about AmigaOS4 .so support
+            lt_prog_compiler_pic='-fPIC'
+        ;;
+      m68k)
+            # FIXME: we need at least 68020 code to build shared libraries, but
+            # adding the `-m68020' flag to GCC prevents building anything better,
+            # like `-m68040'.
+            lt_prog_compiler_pic='-m68020 -resident32 -malways-restore-a4'
+        ;;
+      esac
+      ;;
+
+    beos* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*)
+      # PIC is the default for these OSes.
+      ;;
+
+    mingw* | cygwin* | pw32* | os2* | cegcc*)
+      # This hack is so that the source file can tell whether it is being
+      # built for inclusion in a dll (and should export symbols for example).
+      # Although the cygwin gcc ignores -fPIC, still need this for old-style
+      # (--disable-auto-import) libraries
+      lt_prog_compiler_pic='-DDLL_EXPORT'
+      ;;
+
+    darwin* | rhapsody*)
+      # PIC is the default on this platform
+      # Common symbols not allowed in MH_DYLIB files
+      lt_prog_compiler_pic='-fno-common'
+      ;;
+
+    hpux*)
+      # PIC is the default for 64-bit PA HP-UX, but not for 32-bit
+      # PA HP-UX.  On IA64 HP-UX, PIC is the default but the pic flag
+      # sets the default TLS model and affects inlining.
+      case $host_cpu in
+      hppa*64*)
+	# +Z the default
+	;;
+      *)
+	lt_prog_compiler_pic='-fPIC'
+	;;
+      esac
+      ;;
+
+    interix[3-9]*)
+      # Interix 3.x gcc -fpic/-fPIC options generate broken code.
+      # Instead, we relocate shared libraries at runtime.
+      ;;
+
+    msdosdjgpp*)
+      # Just because we use GCC doesn't mean we suddenly get shared libraries
+      # on systems that don't support them.
+      lt_prog_compiler_can_build_shared=no
+      enable_shared=no
+      ;;
+
+    *nto* | *qnx*)
+      # QNX uses GNU C++, but need to define -shared option too, otherwise
+      # it will coredump.
+      lt_prog_compiler_pic='-fPIC -shared'
+      ;;
+
+    sysv4*MP*)
+      if test -d /usr/nec; then
+	lt_prog_compiler_pic=-Kconform_pic
+      fi
+      ;;
+
+    *)
+      lt_prog_compiler_pic='-fPIC'
+      ;;
+    esac
+  else
+    # PORTME Check for flag to pass linker flags through the system compiler.
+    case $host_os in
+    aix*)
+      lt_prog_compiler_wl='-Wl,'
+      if test "$host_cpu" = ia64; then
+	# AIX 5 now supports IA64 processor
+	lt_prog_compiler_static='-Bstatic'
+      else
+	lt_prog_compiler_static='-bnso -bI:/lib/syscalls.exp'
+      fi
+      ;;
+
+    mingw* | cygwin* | pw32* | os2* | cegcc*)
+      # This hack is so that the source file can tell whether it is being
+      # built for inclusion in a dll (and should export symbols for example).
+      lt_prog_compiler_pic='-DDLL_EXPORT'
+      ;;
+
+    hpux9* | hpux10* | hpux11*)
+      lt_prog_compiler_wl='-Wl,'
+      # PIC is the default for IA64 HP-UX and 64-bit HP-UX, but
+      # not for PA HP-UX.
+      case $host_cpu in
+      hppa*64*|ia64*)
+	# +Z the default
+	;;
+      *)
+	lt_prog_compiler_pic='+Z'
+	;;
+      esac
+      # Is there a better lt_prog_compiler_static that works with the bundled CC?
+      lt_prog_compiler_static='${wl}-a ${wl}archive'
+      ;;
+
+    irix5* | irix6* | nonstopux*)
+      lt_prog_compiler_wl='-Wl,'
+      # PIC (with -KPIC) is the default.
+      lt_prog_compiler_static='-non_shared'
+      ;;
+
+    linux* | k*bsd*-gnu)
+      case $cc_basename in
+      # old Intel for x86_64 which still supported -KPIC.
+      ecc*)
+	lt_prog_compiler_wl='-Wl,'
+	lt_prog_compiler_pic='-KPIC'
+	lt_prog_compiler_static='-static'
+        ;;
+      # icc used to be incompatible with GCC.
+      # ICC 10 doesn't accept -KPIC any more.
+      icc* | ifort*)
+	lt_prog_compiler_wl='-Wl,'
+	lt_prog_compiler_pic='-fPIC'
+	lt_prog_compiler_static='-static'
+        ;;
+      # Lahey Fortran 8.1.
+      lf95*)
+	lt_prog_compiler_wl='-Wl,'
+	lt_prog_compiler_pic='--shared'
+	lt_prog_compiler_static='--static'
+	;;
+      pgcc* | pgf77* | pgf90* | pgf95*)
+        # Portland Group compilers (*not* the Pentium gcc compiler,
+	# which looks to be a dead project)
+	lt_prog_compiler_wl='-Wl,'
+	lt_prog_compiler_pic='-fpic'
+	lt_prog_compiler_static='-Bstatic'
+        ;;
+      ccc*)
+        lt_prog_compiler_wl='-Wl,'
+        # All Alpha code is PIC.
+        lt_prog_compiler_static='-non_shared'
+        ;;
+      xl*)
+	# IBM XL C 8.0/Fortran 10.1 on PPC
+	lt_prog_compiler_wl='-Wl,'
+	lt_prog_compiler_pic='-qpic'
+	lt_prog_compiler_static='-qstaticlink'
+	;;
+      *)
+	case `$CC -V 2>&1 | sed 5q` in
+	*Sun\ C*)
+	  # Sun C 5.9
+	  lt_prog_compiler_pic='-KPIC'
+	  lt_prog_compiler_static='-Bstatic'
+	  lt_prog_compiler_wl='-Wl,'
+	  ;;
+	*Sun\ F*)
+	  # Sun Fortran 8.3 passes all unrecognized flags to the linker
+	  lt_prog_compiler_pic='-KPIC'
+	  lt_prog_compiler_static='-Bstatic'
+	  lt_prog_compiler_wl=''
+	  ;;
+	esac
+	;;
+      esac
+      ;;
+
+    newsos6)
+      lt_prog_compiler_pic='-KPIC'
+      lt_prog_compiler_static='-Bstatic'
+      ;;
+
+    *nto* | *qnx*)
+      # QNX uses GNU C++, but need to define -shared option too, otherwise
+      # it will coredump.
+      lt_prog_compiler_pic='-fPIC -shared'
+      ;;
+
+    osf3* | osf4* | osf5*)
+      lt_prog_compiler_wl='-Wl,'
+      # All OSF/1 code is PIC.
+      lt_prog_compiler_static='-non_shared'
+      ;;
+
+    rdos*)
+      lt_prog_compiler_static='-non_shared'
+      ;;
+
+    solaris*)
+      lt_prog_compiler_pic='-KPIC'
+      lt_prog_compiler_static='-Bstatic'
+      case $cc_basename in
+      f77* | f90* | f95*)
+	lt_prog_compiler_wl='-Qoption ld ';;
+      *)
+	lt_prog_compiler_wl='-Wl,';;
+      esac
+      ;;
+
+    sunos4*)
+      lt_prog_compiler_wl='-Qoption ld '
+      lt_prog_compiler_pic='-PIC'
+      lt_prog_compiler_static='-Bstatic'
+      ;;
+
+    sysv4 | sysv4.2uw2* | sysv4.3*)
+      lt_prog_compiler_wl='-Wl,'
+      lt_prog_compiler_pic='-KPIC'
+      lt_prog_compiler_static='-Bstatic'
+      ;;
+
+    sysv4*MP*)
+      if test -d /usr/nec ;then
+	lt_prog_compiler_pic='-Kconform_pic'
+	lt_prog_compiler_static='-Bstatic'
+      fi
+      ;;
+
+    sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*)
+      lt_prog_compiler_wl='-Wl,'
+      lt_prog_compiler_pic='-KPIC'
+      lt_prog_compiler_static='-Bstatic'
+      ;;
+
+    unicos*)
+      lt_prog_compiler_wl='-Wl,'
+      lt_prog_compiler_can_build_shared=no
+      ;;
+
+    uts4*)
+      lt_prog_compiler_pic='-pic'
+      lt_prog_compiler_static='-Bstatic'
+      ;;
+
+    *)
+      lt_prog_compiler_can_build_shared=no
+      ;;
+    esac
+  fi
+
+case $host_os in
+  # For platforms which do not support PIC, -DPIC is meaningless:
+  *djgpp*)
+    lt_prog_compiler_pic=
+    ;;
+  *)
+    lt_prog_compiler_pic="$lt_prog_compiler_pic -DPIC"
+    ;;
+esac
+{ $as_echo "$as_me:$LINENO: result: $lt_prog_compiler_pic" >&5
+$as_echo "$lt_prog_compiler_pic" >&6; }
+
+
+
+
+
+
+#
+# Check to make sure the PIC flag actually works.
+#
+if test -n "$lt_prog_compiler_pic"; then
+  { $as_echo "$as_me:$LINENO: checking if $compiler PIC flag $lt_prog_compiler_pic works" >&5
+$as_echo_n "checking if $compiler PIC flag $lt_prog_compiler_pic works... " >&6; }
+if test "${lt_cv_prog_compiler_pic_works+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  lt_cv_prog_compiler_pic_works=no
+   ac_outfile=conftest.$ac_objext
+   echo "$lt_simple_compile_test_code" > conftest.$ac_ext
+   lt_compiler_flag="$lt_prog_compiler_pic -DPIC"
+   # Insert the option either (1) after the last *FLAGS variable, or
+   # (2) before a word containing "conftest.", or (3) at the end.
+   # Note that $ac_compile itself does not contain backslashes and begins
+   # with a dollar sign (not a hyphen), so the echo should work correctly.
+   # The option is referenced via a variable to avoid confusing sed.
+   lt_compile=`echo "$ac_compile" | $SED \
+   -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
+   -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
+   -e 's:$: $lt_compiler_flag:'`
+   (eval echo "\"\$as_me:8987: $lt_compile\"" >&5)
+   (eval "$lt_compile" 2>conftest.err)
+   ac_status=$?
+   cat conftest.err >&5
+   echo "$as_me:8991: \$? = $ac_status" >&5
+   if (exit $ac_status) && test -s "$ac_outfile"; then
+     # The compiler can only warn and ignore the option if not recognized
+     # So say no if there are warnings other than the usual output.
+     $ECHO "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' >conftest.exp
+     $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2
+     if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then
+       lt_cv_prog_compiler_pic_works=yes
+     fi
+   fi
+   $RM conftest*
+
+fi
+{ $as_echo "$as_me:$LINENO: result: $lt_cv_prog_compiler_pic_works" >&5
+$as_echo "$lt_cv_prog_compiler_pic_works" >&6; }
+
+if test x"$lt_cv_prog_compiler_pic_works" = xyes; then
+    case $lt_prog_compiler_pic in
+     "" | " "*) ;;
+     *) lt_prog_compiler_pic=" $lt_prog_compiler_pic" ;;
+     esac
+else
+    lt_prog_compiler_pic=
+     lt_prog_compiler_can_build_shared=no
+fi
+
+fi
+
+
+
+
+
+
+#
+# Check to make sure the static flag actually works.
+#
+wl=$lt_prog_compiler_wl eval lt_tmp_static_flag=\"$lt_prog_compiler_static\"
+{ $as_echo "$as_me:$LINENO: checking if $compiler static flag $lt_tmp_static_flag works" >&5
+$as_echo_n "checking if $compiler static flag $lt_tmp_static_flag works... " >&6; }
+if test "${lt_cv_prog_compiler_static_works+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  lt_cv_prog_compiler_static_works=no
+   save_LDFLAGS="$LDFLAGS"
+   LDFLAGS="$LDFLAGS $lt_tmp_static_flag"
+   echo "$lt_simple_link_test_code" > conftest.$ac_ext
+   if (eval $ac_link 2>conftest.err) && test -s conftest$ac_exeext; then
+     # The linker can only warn and ignore the option if not recognized
+     # So say no if there are warnings
+     if test -s conftest.err; then
+       # Append any errors to the config.log.
+       cat conftest.err 1>&5
+       $ECHO "X$_lt_linker_boilerplate" | $Xsed -e '/^$/d' > conftest.exp
+       $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2
+       if diff conftest.exp conftest.er2 >/dev/null; then
+         lt_cv_prog_compiler_static_works=yes
+       fi
+     else
+       lt_cv_prog_compiler_static_works=yes
+     fi
+   fi
+   $RM -r conftest*
+   LDFLAGS="$save_LDFLAGS"
+
+fi
+{ $as_echo "$as_me:$LINENO: result: $lt_cv_prog_compiler_static_works" >&5
+$as_echo "$lt_cv_prog_compiler_static_works" >&6; }
+
+if test x"$lt_cv_prog_compiler_static_works" = xyes; then
+    :
+else
+    lt_prog_compiler_static=
+fi
+
+
+
+
+
+
+
+  { $as_echo "$as_me:$LINENO: checking if $compiler supports -c -o file.$ac_objext" >&5
+$as_echo_n "checking if $compiler supports -c -o file.$ac_objext... " >&6; }
+if test "${lt_cv_prog_compiler_c_o+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  lt_cv_prog_compiler_c_o=no
+   $RM -r conftest 2>/dev/null
+   mkdir conftest
+   cd conftest
+   mkdir out
+   echo "$lt_simple_compile_test_code" > conftest.$ac_ext
+
+   lt_compiler_flag="-o out/conftest2.$ac_objext"
+   # Insert the option either (1) after the last *FLAGS variable, or
+   # (2) before a word containing "conftest.", or (3) at the end.
+   # Note that $ac_compile itself does not contain backslashes and begins
+   # with a dollar sign (not a hyphen), so the echo should work correctly.
+   lt_compile=`echo "$ac_compile" | $SED \
+   -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
+   -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
+   -e 's:$: $lt_compiler_flag:'`
+   (eval echo "\"\$as_me:9092: $lt_compile\"" >&5)
+   (eval "$lt_compile" 2>out/conftest.err)
+   ac_status=$?
+   cat out/conftest.err >&5
+   echo "$as_me:9096: \$? = $ac_status" >&5
+   if (exit $ac_status) && test -s out/conftest2.$ac_objext
+   then
+     # The compiler can only warn and ignore the option if not recognized
+     # So say no if there are warnings
+     $ECHO "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' > out/conftest.exp
+     $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2
+     if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then
+       lt_cv_prog_compiler_c_o=yes
+     fi
+   fi
+   chmod u+w . 2>&5
+   $RM conftest*
+   # SGI C++ compiler will create directory out/ii_files/ for
+   # template instantiation
+   test -d out/ii_files && $RM out/ii_files/* && rmdir out/ii_files
+   $RM out/* && rmdir out
+   cd ..
+   $RM -r conftest
+   $RM conftest*
+
+fi
+{ $as_echo "$as_me:$LINENO: result: $lt_cv_prog_compiler_c_o" >&5
+$as_echo "$lt_cv_prog_compiler_c_o" >&6; }
+
+
+
+
+
+
+  { $as_echo "$as_me:$LINENO: checking if $compiler supports -c -o file.$ac_objext" >&5
+$as_echo_n "checking if $compiler supports -c -o file.$ac_objext... " >&6; }
+if test "${lt_cv_prog_compiler_c_o+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  lt_cv_prog_compiler_c_o=no
+   $RM -r conftest 2>/dev/null
+   mkdir conftest
+   cd conftest
+   mkdir out
+   echo "$lt_simple_compile_test_code" > conftest.$ac_ext
+
+   lt_compiler_flag="-o out/conftest2.$ac_objext"
+   # Insert the option either (1) after the last *FLAGS variable, or
+   # (2) before a word containing "conftest.", or (3) at the end.
+   # Note that $ac_compile itself does not contain backslashes and begins
+   # with a dollar sign (not a hyphen), so the echo should work correctly.
+   lt_compile=`echo "$ac_compile" | $SED \
+   -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
+   -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
+   -e 's:$: $lt_compiler_flag:'`
+   (eval echo "\"\$as_me:9147: $lt_compile\"" >&5)
+   (eval "$lt_compile" 2>out/conftest.err)
+   ac_status=$?
+   cat out/conftest.err >&5
+   echo "$as_me:9151: \$? = $ac_status" >&5
+   if (exit $ac_status) && test -s out/conftest2.$ac_objext
+   then
+     # The compiler can only warn and ignore the option if not recognized
+     # So say no if there are warnings
+     $ECHO "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' > out/conftest.exp
+     $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2
+     if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then
+       lt_cv_prog_compiler_c_o=yes
+     fi
+   fi
+   chmod u+w . 2>&5
+   $RM conftest*
+   # SGI C++ compiler will create directory out/ii_files/ for
+   # template instantiation
+   test -d out/ii_files && $RM out/ii_files/* && rmdir out/ii_files
+   $RM out/* && rmdir out
+   cd ..
+   $RM -r conftest
+   $RM conftest*
+
+fi
+{ $as_echo "$as_me:$LINENO: result: $lt_cv_prog_compiler_c_o" >&5
+$as_echo "$lt_cv_prog_compiler_c_o" >&6; }
+
+
+
+
+hard_links="nottested"
+if test "$lt_cv_prog_compiler_c_o" = no && test "$need_locks" != no; then
+  # do not overwrite the value of need_locks provided by the user
+  { $as_echo "$as_me:$LINENO: checking if we can lock with hard links" >&5
+$as_echo_n "checking if we can lock with hard links... " >&6; }
+  hard_links=yes
+  $RM conftest*
+  ln conftest.a conftest.b 2>/dev/null && hard_links=no
+  touch conftest.a
+  ln conftest.a conftest.b 2>&5 || hard_links=no
+  ln conftest.a conftest.b 2>/dev/null && hard_links=no
+  { $as_echo "$as_me:$LINENO: result: $hard_links" >&5
+$as_echo "$hard_links" >&6; }
+  if test "$hard_links" = no; then
+    { $as_echo "$as_me:$LINENO: WARNING: \`$CC' does not support \`-c -o', so \`make -j' may be unsafe" >&5
+$as_echo "$as_me: WARNING: \`$CC' does not support \`-c -o', so \`make -j' may be unsafe" >&2;}
+    need_locks=warn
+  fi
+else
+  need_locks=no
+fi
+
+
+
+
+
+
+  { $as_echo "$as_me:$LINENO: checking whether the $compiler linker ($LD) supports shared libraries" >&5
+$as_echo_n "checking whether the $compiler linker ($LD) supports shared libraries... " >&6; }
+
+  runpath_var=
+  allow_undefined_flag=
+  always_export_symbols=no
+  archive_cmds=
+  archive_expsym_cmds=
+  compiler_needs_object=no
+  enable_shared_with_static_runtimes=no
+  export_dynamic_flag_spec=
+  export_symbols_cmds='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols'
+  hardcode_automatic=no
+  hardcode_direct=no
+  hardcode_direct_absolute=no
+  hardcode_libdir_flag_spec=
+  hardcode_libdir_flag_spec_ld=
+  hardcode_libdir_separator=
+  hardcode_minus_L=no
+  hardcode_shlibpath_var=unsupported
+  inherit_rpath=no
+  link_all_deplibs=unknown
+  module_cmds=
+  module_expsym_cmds=
+  old_archive_from_new_cmds=
+  old_archive_from_expsyms_cmds=
+  thread_safe_flag_spec=
+  whole_archive_flag_spec=
+  # include_expsyms should be a list of space-separated symbols to be *always*
+  # included in the symbol list
+  include_expsyms=
+  # exclude_expsyms can be an extended regexp of symbols to exclude
+  # it will be wrapped by ` (' and `)$', so one must not match beginning or
+  # end of line.  Example: `a|bc|.*d.*' will exclude the symbols `a' and `bc',
+  # as well as any symbol that contains `d'.
+  exclude_expsyms='_GLOBAL_OFFSET_TABLE_|_GLOBAL__F[ID]_.*'
+  # Although _GLOBAL_OFFSET_TABLE_ is a valid symbol C name, most a.out
+  # platforms (ab)use it in PIC code, but their linkers get confused if
+  # the symbol is explicitly referenced.  Since portable code cannot
+  # rely on this symbol name, it's probably fine to never include it in
+  # preloaded symbol tables.
+  # Exclude shared library initialization/finalization symbols.
+  extract_expsyms_cmds=
+
+  case $host_os in
+  cygwin* | mingw* | pw32* | cegcc*)
+    # FIXME: the MSVC++ port hasn't been tested in a loooong time
+    # When not using gcc, we currently assume that we are using
+    # Microsoft Visual C++.
+    if test "$GCC" != yes; then
+      with_gnu_ld=no
+    fi
+    ;;
+  interix*)
+    # we just hope/assume this is gcc and not c89 (= MSVC++)
+    with_gnu_ld=yes
+    ;;
+  openbsd*)
+    with_gnu_ld=no
+    ;;
+  esac
+
+  ld_shlibs=yes
+  if test "$with_gnu_ld" = yes; then
+    # If archive_cmds runs LD, not CC, wlarc should be empty
+    wlarc='${wl}'
+
+    # Set some defaults for GNU ld with shared library support. These
+    # are reset later if shared libraries are not supported. Putting them
+    # here allows them to be overridden if necessary.
+    runpath_var=LD_RUN_PATH
+    hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
+    export_dynamic_flag_spec='${wl}--export-dynamic'
+    # ancient GNU ld didn't support --whole-archive et. al.
+    if $LD --help 2>&1 | $GREP 'no-whole-archive' > /dev/null; then
+      whole_archive_flag_spec="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive'
+    else
+      whole_archive_flag_spec=
+    fi
+    supports_anon_versioning=no
+    case `$LD -v 2>&1` in
+      *\ [01].* | *\ 2.[0-9].* | *\ 2.10.*) ;; # catch versions < 2.11
+      *\ 2.11.93.0.2\ *) supports_anon_versioning=yes ;; # RH7.3 ...
+      *\ 2.11.92.0.12\ *) supports_anon_versioning=yes ;; # Mandrake 8.2 ...
+      *\ 2.11.*) ;; # other 2.11 versions
+      *) supports_anon_versioning=yes ;;
+    esac
+
+    # See if GNU ld supports shared libraries.
+    case $host_os in
+    aix[3-9]*)
+      # On AIX/PPC, the GNU linker is very broken
+      if test "$host_cpu" != ia64; then
+	ld_shlibs=no
+	cat <<_LT_EOF 1>&2
+
+*** Warning: the GNU linker, at least up to release 2.9.1, is reported
+*** to be unable to reliably create shared libraries on AIX.
+*** Therefore, libtool is disabling shared libraries support.  If you
+*** really care for shared libraries, you may want to modify your PATH
+*** so that a non-GNU linker is found, and then restart.
+
+_LT_EOF
+      fi
+      ;;
+
+    amigaos*)
+      case $host_cpu in
+      powerpc)
+            # see comment about AmigaOS4 .so support
+            archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+            archive_expsym_cmds=''
+        ;;
+      m68k)
+            archive_cmds='$RM $output_objdir/a2ixlibrary.data~$ECHO "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$ECHO "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$ECHO "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$ECHO "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)'
+            hardcode_libdir_flag_spec='-L$libdir'
+            hardcode_minus_L=yes
+        ;;
+      esac
+      ;;
+
+    beos*)
+      if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then
+	allow_undefined_flag=unsupported
+	# Joseph Beckenbach <jrb3 at best.com> says some releases of gcc
+	# support --undefined.  This deserves some investigation.  FIXME
+	archive_cmds='$CC -nostart $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+      else
+	ld_shlibs=no
+      fi
+      ;;
+
+    cygwin* | mingw* | pw32* | cegcc*)
+      # _LT_TAGVAR(hardcode_libdir_flag_spec, ) is actually meaningless,
+      # as there is no search path for DLLs.
+      hardcode_libdir_flag_spec='-L$libdir'
+      allow_undefined_flag=unsupported
+      always_export_symbols=no
+      enable_shared_with_static_runtimes=yes
+      export_symbols_cmds='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[BCDGRS][ ]/s/.*[ ]\([^ ]*\)/\1 DATA/'\'' | $SED -e '\''/^[AITW][ ]/s/.*[ ]//'\'' | sort | uniq > $export_symbols'
+
+      if $LD --help 2>&1 | $GREP 'auto-import' > /dev/null; then
+        archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib'
+	# If the export-symbols file already is a .def file (1st line
+	# is EXPORTS), use it as is; otherwise, prepend...
+	archive_expsym_cmds='if test "x`$SED 1q $export_symbols`" = xEXPORTS; then
+	  cp $export_symbols $output_objdir/$soname.def;
+	else
+	  echo EXPORTS > $output_objdir/$soname.def;
+	  cat $export_symbols >> $output_objdir/$soname.def;
+	fi~
+	$CC -shared $output_objdir/$soname.def $libobjs $deplibs $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib'
+      else
+	ld_shlibs=no
+      fi
+      ;;
+
+    interix[3-9]*)
+      hardcode_direct=no
+      hardcode_shlibpath_var=no
+      hardcode_libdir_flag_spec='${wl}-rpath,$libdir'
+      export_dynamic_flag_spec='${wl}-E'
+      # Hack: On Interix 3.x, we cannot compile PIC because of a broken gcc.
+      # Instead, shared libraries are loaded at an image base (0x10000000 by
+      # default) and relocated if they conflict, which is a slow very memory
+      # consuming and fragmenting process.  To avoid this, we pick a random,
+      # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link
+      # time.  Moving up from 0x10000000 also allows more sbrk(2) space.
+      archive_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib'
+      archive_expsym_cmds='sed "s,^,_," $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--retain-symbols-file,$output_objdir/$soname.expsym ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib'
+      ;;
+
+    gnu* | linux* | tpf* | k*bsd*-gnu)
+      tmp_diet=no
+      if test "$host_os" = linux-dietlibc; then
+	case $cc_basename in
+	  diet\ *) tmp_diet=yes;;	# linux-dietlibc with static linking (!diet-dyn)
+	esac
+      fi
+      if $LD --help 2>&1 | $EGREP ': supported targets:.* elf' > /dev/null \
+	 && test "$tmp_diet" = no
+      then
+	tmp_addflag=
+	tmp_sharedflag='-shared'
+	case $cc_basename,$host_cpu in
+        pgcc*)				# Portland Group C compiler
+	  whole_archive_flag_spec='${wl}--whole-archive`for conv in $convenience\"\"; do test  -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $ECHO \"$new_convenience\"` ${wl}--no-whole-archive'
+	  tmp_addflag=' $pic_flag'
+	  ;;
+	pgf77* | pgf90* | pgf95*)	# Portland Group f77 and f90 compilers
+	  whole_archive_flag_spec='${wl}--whole-archive`for conv in $convenience\"\"; do test  -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $ECHO \"$new_convenience\"` ${wl}--no-whole-archive'
+	  tmp_addflag=' $pic_flag -Mnomain' ;;
+	ecc*,ia64* | icc*,ia64*)	# Intel C compiler on ia64
+	  tmp_addflag=' -i_dynamic' ;;
+	efc*,ia64* | ifort*,ia64*)	# Intel Fortran compiler on ia64
+	  tmp_addflag=' -i_dynamic -nofor_main' ;;
+	ifc* | ifort*)			# Intel Fortran compiler
+	  tmp_addflag=' -nofor_main' ;;
+	lf95*)				# Lahey Fortran 8.1
+	  whole_archive_flag_spec=
+	  tmp_sharedflag='--shared' ;;
+	xl[cC]*)			# IBM XL C 8.0 on PPC (deal with xlf below)
+	  tmp_sharedflag='-qmkshrobj'
+	  tmp_addflag= ;;
+	esac
+	case `$CC -V 2>&1 | sed 5q` in
+	*Sun\ C*)			# Sun C 5.9
+	  whole_archive_flag_spec='${wl}--whole-archive`new_convenience=; for conv in $convenience\"\"; do test -z \"$conv\" || new_convenience=\"$new_convenience,$conv\"; done; $ECHO \"$new_convenience\"` ${wl}--no-whole-archive'
+	  compiler_needs_object=yes
+	  tmp_sharedflag='-G' ;;
+	*Sun\ F*)			# Sun Fortran 8.3
+	  tmp_sharedflag='-G' ;;
+	esac
+	archive_cmds='$CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+
+        if test "x$supports_anon_versioning" = xyes; then
+          archive_expsym_cmds='echo "{ global:" > $output_objdir/$libname.ver~
+	    cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~
+	    echo "local: *; };" >> $output_objdir/$libname.ver~
+	    $CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-version-script ${wl}$output_objdir/$libname.ver -o $lib'
+        fi
+
+	case $cc_basename in
+	xlf*)
+	  # IBM XL Fortran 10.1 on PPC cannot create shared libs itself
+	  whole_archive_flag_spec='--whole-archive$convenience --no-whole-archive'
+	  hardcode_libdir_flag_spec=
+	  hardcode_libdir_flag_spec_ld='-rpath $libdir'
+	  archive_cmds='$LD -shared $libobjs $deplibs $compiler_flags -soname $soname -o $lib'
+	  if test "x$supports_anon_versioning" = xyes; then
+	    archive_expsym_cmds='echo "{ global:" > $output_objdir/$libname.ver~
+	      cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~
+	      echo "local: *; };" >> $output_objdir/$libname.ver~
+	      $LD -shared $libobjs $deplibs $compiler_flags -soname $soname -version-script $output_objdir/$libname.ver -o $lib'
+	  fi
+	  ;;
+	esac
+      else
+        ld_shlibs=no
+      fi
+      ;;
+
+    netbsd*)
+      if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then
+	archive_cmds='$LD -Bshareable $libobjs $deplibs $linker_flags -o $lib'
+	wlarc=
+      else
+	archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+	archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+      fi
+      ;;
+
+    solaris*)
+      if $LD -v 2>&1 | $GREP 'BFD 2\.8' > /dev/null; then
+	ld_shlibs=no
+	cat <<_LT_EOF 1>&2
+
+*** Warning: The releases 2.8.* of the GNU linker cannot reliably
+*** create shared libraries on Solaris systems.  Therefore, libtool
+*** is disabling shared libraries support.  We urge you to upgrade GNU
+*** binutils to release 2.9.1 or newer.  Another option is to modify
+*** your PATH or compiler configuration so that the native linker is
+*** used, and then restart.
+
+_LT_EOF
+      elif $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then
+	archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+	archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+      else
+	ld_shlibs=no
+      fi
+      ;;
+
+    sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX*)
+      case `$LD -v 2>&1` in
+        *\ [01].* | *\ 2.[0-9].* | *\ 2.1[0-5].*)
+	ld_shlibs=no
+	cat <<_LT_EOF 1>&2
+
+*** Warning: Releases of the GNU linker prior to 2.16.91.0.3 can not
+*** reliably create shared libraries on SCO systems.  Therefore, libtool
+*** is disabling shared libraries support.  We urge you to upgrade GNU
+*** binutils to release 2.16.91.0.3 or newer.  Another option is to modify
+*** your PATH or compiler configuration so that the native linker is
+*** used, and then restart.
+
+_LT_EOF
+	;;
+	*)
+	  # For security reasons, it is highly recommended that you always
+	  # use absolute paths for naming shared libraries, and exclude the
+	  # DT_RUNPATH tag from executables and libraries.  But doing so
+	  # requires that you compile everything twice, which is a pain.
+	  if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then
+	    hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
+	    archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+	    archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+	  else
+	    ld_shlibs=no
+	  fi
+	;;
+      esac
+      ;;
+
+    sunos4*)
+      archive_cmds='$LD -assert pure-text -Bshareable -o $lib $libobjs $deplibs $linker_flags'
+      wlarc=
+      hardcode_direct=yes
+      hardcode_shlibpath_var=no
+      ;;
+
+    *)
+      if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then
+	archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+	archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+      else
+	ld_shlibs=no
+      fi
+      ;;
+    esac
+
+    if test "$ld_shlibs" = no; then
+      runpath_var=
+      hardcode_libdir_flag_spec=
+      export_dynamic_flag_spec=
+      whole_archive_flag_spec=
+    fi
+  else
+    # PORTME fill in a description of your system's linker (not GNU ld)
+    case $host_os in
+    aix3*)
+      allow_undefined_flag=unsupported
+      always_export_symbols=yes
+      archive_expsym_cmds='$LD -o $output_objdir/$soname $libobjs $deplibs $linker_flags -bE:$export_symbols -T512 -H512 -bM:SRE~$AR $AR_FLAGS $lib $output_objdir/$soname'
+      # Note: this linker hardcodes the directories in LIBPATH if there
+      # are no directories specified by -L.
+      hardcode_minus_L=yes
+      if test "$GCC" = yes && test -z "$lt_prog_compiler_static"; then
+	# Neither direct hardcoding nor static linking is supported with a
+	# broken collect2.
+	hardcode_direct=unsupported
+      fi
+      ;;
+
+    aix[4-9]*)
+      if test "$host_cpu" = ia64; then
+	# On IA64, the linker does run time linking by default, so we don't
+	# have to do anything special.
+	aix_use_runtimelinking=no
+	exp_sym_flag='-Bexport'
+	no_entry_flag=""
+      else
+	# If we're using GNU nm, then we don't want the "-C" option.
+	# -C means demangle to AIX nm, but means don't demangle with GNU nm
+	if $NM -V 2>&1 | $GREP 'GNU' > /dev/null; then
+	  export_symbols_cmds='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B")) && (substr(\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols'
+	else
+	  export_symbols_cmds='$NM -BCpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B")) && (substr(\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols'
+	fi
+	aix_use_runtimelinking=no
+
+	# Test if we are trying to use run time linking or normal
+	# AIX style linking. If -brtl is somewhere in LDFLAGS, we
+	# need to do runtime linking.
+	case $host_os in aix4.[23]|aix4.[23].*|aix[5-9]*)
+	  for ld_flag in $LDFLAGS; do
+	  if (test $ld_flag = "-brtl" || test $ld_flag = "-Wl,-brtl"); then
+	    aix_use_runtimelinking=yes
+	    break
+	  fi
+	  done
+	  ;;
+	esac
+
+	exp_sym_flag='-bexport'
+	no_entry_flag='-bnoentry'
+      fi
+
+      # When large executables or shared objects are built, AIX ld can
+      # have problems creating the table of contents.  If linking a library
+      # or program results in "error TOC overflow" add -mminimal-toc to
+      # CXXFLAGS/CFLAGS for g++/gcc.  In the cases where that is not
+      # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS.
+
+      archive_cmds=''
+      hardcode_direct=yes
+      hardcode_direct_absolute=yes
+      hardcode_libdir_separator=':'
+      link_all_deplibs=yes
+      file_list_spec='${wl}-f,'
+
+      if test "$GCC" = yes; then
+	case $host_os in aix4.[012]|aix4.[012].*)
+	# We only want to do this on AIX 4.2 and lower, the check
+	# below for broken collect2 doesn't work under 4.3+
+	  collect2name=`${CC} -print-prog-name=collect2`
+	  if test -f "$collect2name" &&
+	   strings "$collect2name" | $GREP resolve_lib_name >/dev/null
+	  then
+	  # We have reworked collect2
+	  :
+	  else
+	  # We have old collect2
+	  hardcode_direct=unsupported
+	  # It fails to find uninstalled libraries when the uninstalled
+	  # path is not listed in the libpath.  Setting hardcode_minus_L
+	  # to unsupported forces relinking
+	  hardcode_minus_L=yes
+	  hardcode_libdir_flag_spec='-L$libdir'
+	  hardcode_libdir_separator=
+	  fi
+	  ;;
+	esac
+	shared_flag='-shared'
+	if test "$aix_use_runtimelinking" = yes; then
+	  shared_flag="$shared_flag "'${wl}-G'
+	fi
+      else
+	# not using gcc
+	if test "$host_cpu" = ia64; then
+	# VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release
+	# chokes on -Wl,-G. The following line is correct:
+	  shared_flag='-G'
+	else
+	  if test "$aix_use_runtimelinking" = yes; then
+	    shared_flag='${wl}-G'
+	  else
+	    shared_flag='${wl}-bM:SRE'
+	  fi
+	fi
+      fi
+
+      export_dynamic_flag_spec='${wl}-bexpall'
+      # It seems that -bexpall does not export symbols beginning with
+      # underscore (_), so it is better to generate a list of symbols to export.
+      always_export_symbols=yes
+      if test "$aix_use_runtimelinking" = yes; then
+	# Warning - without using the other runtime loading flags (-brtl),
+	# -berok will link without error, but may produce a broken library.
+	allow_undefined_flag='-berok'
+        # Determine the default libpath from the value encoded in an
+        # empty executable.
+        cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext && {
+	 test "$cross_compiling" = yes ||
+	 $as_test_x conftest$ac_exeext
+       }; then
+
+lt_aix_libpath_sed='
+    /Import File Strings/,/^$/ {
+	/^0/ {
+	    s/^0  *\(.*\)$/\1/
+	    p
+	}
+    }'
+aix_libpath=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"`
+# Check for a 64-bit object if we didn't find anything.
+if test -z "$aix_libpath"; then
+  aix_libpath=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"`
+fi
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+
+fi
+
+rm -rf conftest.dSYM
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi
+
+        hardcode_libdir_flag_spec='${wl}-blibpath:$libdir:'"$aix_libpath"
+        archive_expsym_cmds='$CC -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags `if test "x${allow_undefined_flag}" != "x"; then $ECHO "X${wl}${allow_undefined_flag}" | $Xsed; else :; fi` '"\${wl}$exp_sym_flag:\$export_symbols $shared_flag"
+      else
+	if test "$host_cpu" = ia64; then
+	  hardcode_libdir_flag_spec='${wl}-R $libdir:/usr/lib:/lib'
+	  allow_undefined_flag="-z nodefs"
+	  archive_expsym_cmds="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags ${wl}${allow_undefined_flag} '"\${wl}$exp_sym_flag:\$export_symbols"
+	else
+	 # Determine the default libpath from the value encoded in an
+	 # empty executable.
+	 cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext && {
+	 test "$cross_compiling" = yes ||
+	 $as_test_x conftest$ac_exeext
+       }; then
+
+lt_aix_libpath_sed='
+    /Import File Strings/,/^$/ {
+	/^0/ {
+	    s/^0  *\(.*\)$/\1/
+	    p
+	}
+    }'
+aix_libpath=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"`
+# Check for a 64-bit object if we didn't find anything.
+if test -z "$aix_libpath"; then
+  aix_libpath=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"`
+fi
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+
+fi
+
+rm -rf conftest.dSYM
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi
+
+	 hardcode_libdir_flag_spec='${wl}-blibpath:$libdir:'"$aix_libpath"
+	  # Warning - without using the other run time loading flags,
+	  # -berok will link without error, but may produce a broken library.
+	  no_undefined_flag=' ${wl}-bernotok'
+	  allow_undefined_flag=' ${wl}-berok'
+	  # Exported symbols can be pulled into shared objects from archives
+	  whole_archive_flag_spec='$convenience'
+	  archive_cmds_need_lc=yes
+	  # This is similar to how AIX traditionally builds its shared libraries.
+	  archive_expsym_cmds="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs ${wl}-bnoentry $compiler_flags ${wl}-bE:$export_symbols${allow_undefined_flag}~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$soname'
+	fi
+      fi
+      ;;
+
+    amigaos*)
+      case $host_cpu in
+      powerpc)
+            # see comment about AmigaOS4 .so support
+            archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+            archive_expsym_cmds=''
+        ;;
+      m68k)
+            archive_cmds='$RM $output_objdir/a2ixlibrary.data~$ECHO "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$ECHO "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$ECHO "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$ECHO "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)'
+            hardcode_libdir_flag_spec='-L$libdir'
+            hardcode_minus_L=yes
+        ;;
+      esac
+      ;;
+
+    bsdi[45]*)
+      export_dynamic_flag_spec=-rdynamic
+      ;;
+
+    cygwin* | mingw* | pw32* | cegcc*)
+      # When not using gcc, we currently assume that we are using
+      # Microsoft Visual C++.
+      # hardcode_libdir_flag_spec is actually meaningless, as there is
+      # no search path for DLLs.
+      hardcode_libdir_flag_spec=' '
+      allow_undefined_flag=unsupported
+      # Tell ltmain to make .lib files, not .a files.
+      libext=lib
+      # Tell ltmain to make .dll files, not .so files.
+      shrext_cmds=".dll"
+      # FIXME: Setting linknames here is a bad hack.
+      archive_cmds='$CC -o $lib $libobjs $compiler_flags `$ECHO "X$deplibs" | $Xsed -e '\''s/ -lc$//'\''` -link -dll~linknames='
+      # The linker will automatically build a .lib file if we build a DLL.
+      old_archive_from_new_cmds='true'
+      # FIXME: Should let the user specify the lib program.
+      old_archive_cmds='lib -OUT:$oldlib$oldobjs$old_deplibs'
+      fix_srcfile_path='`cygpath -w "$srcfile"`'
+      enable_shared_with_static_runtimes=yes
+      ;;
+
+    darwin* | rhapsody*)
+
+
+  archive_cmds_need_lc=no
+  hardcode_direct=no
+  hardcode_automatic=yes
+  hardcode_shlibpath_var=unsupported
+  whole_archive_flag_spec=''
+  link_all_deplibs=yes
+  allow_undefined_flag="$_lt_dar_allow_undefined"
+  case $cc_basename in
+     ifort*) _lt_dar_can_shared=yes ;;
+     *) _lt_dar_can_shared=$GCC ;;
+  esac
+  if test "$_lt_dar_can_shared" = "yes"; then
+    output_verbose_link_cmd=echo
+    archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}"
+    module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}"
+    archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}"
+    module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}"
+
+  else
+  ld_shlibs=no
+  fi
+
+      ;;
+
+    dgux*)
+      archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+      hardcode_libdir_flag_spec='-L$libdir'
+      hardcode_shlibpath_var=no
+      ;;
+
+    freebsd1*)
+      ld_shlibs=no
+      ;;
+
+    # FreeBSD 2.2.[012] allows us to include c++rt0.o to get C++ constructor
+    # support.  Future versions do this automatically, but an explicit c++rt0.o
+    # does not break anything, and helps significantly (at the cost of a little
+    # extra space).
+    freebsd2.2*)
+      archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags /usr/lib/c++rt0.o'
+      hardcode_libdir_flag_spec='-R$libdir'
+      hardcode_direct=yes
+      hardcode_shlibpath_var=no
+      ;;
+
+    # Unfortunately, older versions of FreeBSD 2 do not have this feature.
+    freebsd2*)
+      archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags'
+      hardcode_direct=yes
+      hardcode_minus_L=yes
+      hardcode_shlibpath_var=no
+      ;;
+
+    # FreeBSD 3 and greater uses gcc -shared to do shared libraries.
+    freebsd* | dragonfly*)
+      archive_cmds='$CC -shared -o $lib $libobjs $deplibs $compiler_flags'
+      hardcode_libdir_flag_spec='-R$libdir'
+      hardcode_direct=yes
+      hardcode_shlibpath_var=no
+      ;;
+
+    hpux9*)
+      if test "$GCC" = yes; then
+	archive_cmds='$RM $output_objdir/$soname~$CC -shared -fPIC ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $libobjs $deplibs $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib'
+      else
+	archive_cmds='$RM $output_objdir/$soname~$LD -b +b $install_libdir -o $output_objdir/$soname $libobjs $deplibs $linker_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib'
+      fi
+      hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir'
+      hardcode_libdir_separator=:
+      hardcode_direct=yes
+
+      # hardcode_minus_L: Not really in the search PATH,
+      # but as the default location of the library.
+      hardcode_minus_L=yes
+      export_dynamic_flag_spec='${wl}-E'
+      ;;
+
+    hpux10*)
+      if test "$GCC" = yes -a "$with_gnu_ld" = no; then
+	archive_cmds='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags'
+      else
+	archive_cmds='$LD -b +h $soname +b $install_libdir -o $lib $libobjs $deplibs $linker_flags'
+      fi
+      if test "$with_gnu_ld" = no; then
+	hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir'
+	hardcode_libdir_flag_spec_ld='+b $libdir'
+	hardcode_libdir_separator=:
+	hardcode_direct=yes
+	hardcode_direct_absolute=yes
+	export_dynamic_flag_spec='${wl}-E'
+	# hardcode_minus_L: Not really in the search PATH,
+	# but as the default location of the library.
+	hardcode_minus_L=yes
+      fi
+      ;;
+
+    hpux11*)
+      if test "$GCC" = yes -a "$with_gnu_ld" = no; then
+	case $host_cpu in
+	hppa*64*)
+	  archive_cmds='$CC -shared ${wl}+h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags'
+	  ;;
+	ia64*)
+	  archive_cmds='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags'
+	  ;;
+	*)
+	  archive_cmds='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags'
+	  ;;
+	esac
+      else
+	case $host_cpu in
+	hppa*64*)
+	  archive_cmds='$CC -b ${wl}+h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags'
+	  ;;
+	ia64*)
+	  archive_cmds='$CC -b ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags'
+	  ;;
+	*)
+	  archive_cmds='$CC -b ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags'
+	  ;;
+	esac
+      fi
+      if test "$with_gnu_ld" = no; then
+	hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir'
+	hardcode_libdir_separator=:
+
+	case $host_cpu in
+	hppa*64*|ia64*)
+	  hardcode_direct=no
+	  hardcode_shlibpath_var=no
+	  ;;
+	*)
+	  hardcode_direct=yes
+	  hardcode_direct_absolute=yes
+	  export_dynamic_flag_spec='${wl}-E'
+
+	  # hardcode_minus_L: Not really in the search PATH,
+	  # but as the default location of the library.
+	  hardcode_minus_L=yes
+	  ;;
+	esac
+      fi
+      ;;
+
+    irix5* | irix6* | nonstopux*)
+      if test "$GCC" = yes; then
+	archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
+	# Try to use the -exported_symbol ld option, if it does not
+	# work, assume that -exports_file does not work either and
+	# implicitly export all symbols.
+        save_LDFLAGS="$LDFLAGS"
+        LDFLAGS="$LDFLAGS -shared ${wl}-exported_symbol ${wl}foo ${wl}-update_registry ${wl}/dev/null"
+        cat >conftest.$ac_ext <<_ACEOF
+int foo(void) {}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext && {
+	 test "$cross_compiling" = yes ||
+	 $as_test_x conftest$ac_exeext
+       }; then
+  archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations ${wl}-exports_file ${wl}$export_symbols -o $lib'
+
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+
+fi
+
+rm -rf conftest.dSYM
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+        LDFLAGS="$save_LDFLAGS"
+      else
+	archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib'
+	archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -exports_file $export_symbols -o $lib'
+      fi
+      archive_cmds_need_lc='no'
+      hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
+      hardcode_libdir_separator=:
+      inherit_rpath=yes
+      link_all_deplibs=yes
+      ;;
+
+    netbsd*)
+      if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then
+	archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags'  # a.out
+      else
+	archive_cmds='$LD -shared -o $lib $libobjs $deplibs $linker_flags'      # ELF
+      fi
+      hardcode_libdir_flag_spec='-R$libdir'
+      hardcode_direct=yes
+      hardcode_shlibpath_var=no
+      ;;
+
+    newsos6)
+      archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+      hardcode_direct=yes
+      hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
+      hardcode_libdir_separator=:
+      hardcode_shlibpath_var=no
+      ;;
+
+    *nto* | *qnx*)
+      ;;
+
+    openbsd*)
+      if test -f /usr/libexec/ld.so; then
+	hardcode_direct=yes
+	hardcode_shlibpath_var=no
+	hardcode_direct_absolute=yes
+	if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
+	  archive_cmds='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags'
+	  archive_expsym_cmds='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-retain-symbols-file,$export_symbols'
+	  hardcode_libdir_flag_spec='${wl}-rpath,$libdir'
+	  export_dynamic_flag_spec='${wl}-E'
+	else
+	  case $host_os in
+	   openbsd[01].* | openbsd2.[0-7] | openbsd2.[0-7].*)
+	     archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags'
+	     hardcode_libdir_flag_spec='-R$libdir'
+	     ;;
+	   *)
+	     archive_cmds='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags'
+	     hardcode_libdir_flag_spec='${wl}-rpath,$libdir'
+	     ;;
+	  esac
+	fi
+      else
+	ld_shlibs=no
+      fi
+      ;;
+
+    os2*)
+      hardcode_libdir_flag_spec='-L$libdir'
+      hardcode_minus_L=yes
+      allow_undefined_flag=unsupported
+      archive_cmds='$ECHO "LIBRARY $libname INITINSTANCE" > $output_objdir/$libname.def~$ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~$ECHO DATA >> $output_objdir/$libname.def~$ECHO " SINGLE NONSHARED" >> $output_objdir/$libname.def~$ECHO EXPORTS >> $output_objdir/$libname.def~emxexp $libobjs >> $output_objdir/$libname.def~$CC -Zdll -Zcrtdll -o $lib $libobjs $deplibs $compiler_flags $output_objdir/$libname.def'
+      old_archive_from_new_cmds='emximp -o $output_objdir/$libname.a $output_objdir/$libname.def'
+      ;;
+
+    osf3*)
+      if test "$GCC" = yes; then
+	allow_undefined_flag=' ${wl}-expect_unresolved ${wl}\*'
+	archive_cmds='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
+      else
+	allow_undefined_flag=' -expect_unresolved \*'
+	archive_cmds='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib'
+      fi
+      archive_cmds_need_lc='no'
+      hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
+      hardcode_libdir_separator=:
+      ;;
+
+    osf4* | osf5*)	# as osf3* with the addition of -msym flag
+      if test "$GCC" = yes; then
+	allow_undefined_flag=' ${wl}-expect_unresolved ${wl}\*'
+	archive_cmds='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags ${wl}-msym ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
+	hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
+      else
+	allow_undefined_flag=' -expect_unresolved \*'
+	archive_cmds='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags -msym -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib'
+	archive_expsym_cmds='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done; printf "%s\\n" "-hidden">> $lib.exp~
+	$CC -shared${allow_undefined_flag} ${wl}-input ${wl}$lib.exp $compiler_flags $libobjs $deplibs -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib~$RM $lib.exp'
+
+	# Both c and cxx compiler support -rpath directly
+	hardcode_libdir_flag_spec='-rpath $libdir'
+      fi
+      archive_cmds_need_lc='no'
+      hardcode_libdir_separator=:
+      ;;
+
+    solaris*)
+      no_undefined_flag=' -z defs'
+      if test "$GCC" = yes; then
+	wlarc='${wl}'
+	archive_cmds='$CC -shared ${wl}-z ${wl}text ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags'
+	archive_expsym_cmds='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~
+	  $CC -shared ${wl}-z ${wl}text ${wl}-M ${wl}$lib.exp ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags~$RM $lib.exp'
+      else
+	case `$CC -V 2>&1` in
+	*"Compilers 5.0"*)
+	  wlarc=''
+	  archive_cmds='$LD -G${allow_undefined_flag} -h $soname -o $lib $libobjs $deplibs $linker_flags'
+	  archive_expsym_cmds='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~
+	  $LD -G${allow_undefined_flag} -M $lib.exp -h $soname -o $lib $libobjs $deplibs $linker_flags~$RM $lib.exp'
+	  ;;
+	*)
+	  wlarc='${wl}'
+	  archive_cmds='$CC -G${allow_undefined_flag} -h $soname -o $lib $libobjs $deplibs $compiler_flags'
+	  archive_expsym_cmds='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~
+	  $CC -G${allow_undefined_flag} -M $lib.exp -h $soname -o $lib $libobjs $deplibs $compiler_flags~$RM $lib.exp'
+	  ;;
+	esac
+      fi
+      hardcode_libdir_flag_spec='-R$libdir'
+      hardcode_shlibpath_var=no
+      case $host_os in
+      solaris2.[0-5] | solaris2.[0-5].*) ;;
+      *)
+	# The compiler driver will combine and reorder linker options,
+	# but understands `-z linker_flag'.  GCC discards it without `$wl',
+	# but is careful enough not to reorder.
+	# Supported since Solaris 2.6 (maybe 2.5.1?)
+	if test "$GCC" = yes; then
+	  whole_archive_flag_spec='${wl}-z ${wl}allextract$convenience ${wl}-z ${wl}defaultextract'
+	else
+	  whole_archive_flag_spec='-z allextract$convenience -z defaultextract'
+	fi
+	;;
+      esac
+      link_all_deplibs=yes
+      ;;
+
+    sunos4*)
+      if test "x$host_vendor" = xsequent; then
+	# Use $CC to link under sequent, because it throws in some extra .o
+	# files that make .init and .fini sections work.
+	archive_cmds='$CC -G ${wl}-h $soname -o $lib $libobjs $deplibs $compiler_flags'
+      else
+	archive_cmds='$LD -assert pure-text -Bstatic -o $lib $libobjs $deplibs $linker_flags'
+      fi
+      hardcode_libdir_flag_spec='-L$libdir'
+      hardcode_direct=yes
+      hardcode_minus_L=yes
+      hardcode_shlibpath_var=no
+      ;;
+
+    sysv4)
+      case $host_vendor in
+	sni)
+	  archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+	  hardcode_direct=yes # is this really true???
+	;;
+	siemens)
+	  ## LD is ld it makes a PLAMLIB
+	  ## CC just makes a GrossModule.
+	  archive_cmds='$LD -G -o $lib $libobjs $deplibs $linker_flags'
+	  reload_cmds='$CC -r -o $output$reload_objs'
+	  hardcode_direct=no
+        ;;
+	motorola)
+	  archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+	  hardcode_direct=no #Motorola manual says yes, but my tests say they lie
+	;;
+      esac
+      runpath_var='LD_RUN_PATH'
+      hardcode_shlibpath_var=no
+      ;;
+
+    sysv4.3*)
+      archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+      hardcode_shlibpath_var=no
+      export_dynamic_flag_spec='-Bexport'
+      ;;
+
+    sysv4*MP*)
+      if test -d /usr/nec; then
+	archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+	hardcode_shlibpath_var=no
+	runpath_var=LD_RUN_PATH
+	hardcode_runpath_var=yes
+	ld_shlibs=yes
+      fi
+      ;;
+
+    sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[01].[10]* | unixware7* | sco3.2v5.0.[024]*)
+      no_undefined_flag='${wl}-z,text'
+      archive_cmds_need_lc=no
+      hardcode_shlibpath_var=no
+      runpath_var='LD_RUN_PATH'
+
+      if test "$GCC" = yes; then
+	archive_cmds='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+	archive_expsym_cmds='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+      else
+	archive_cmds='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+	archive_expsym_cmds='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+      fi
+      ;;
+
+    sysv5* | sco3.2v5* | sco5v6*)
+      # Note: We can NOT use -z defs as we might desire, because we do not
+      # link with -lc, and that would cause any symbols used from libc to
+      # always be unresolved, which means just about no library would
+      # ever link correctly.  If we're not using GNU ld we use -z text
+      # though, which does catch some bad symbols but isn't as heavy-handed
+      # as -z defs.
+      no_undefined_flag='${wl}-z,text'
+      allow_undefined_flag='${wl}-z,nodefs'
+      archive_cmds_need_lc=no
+      hardcode_shlibpath_var=no
+      hardcode_libdir_flag_spec='${wl}-R,$libdir'
+      hardcode_libdir_separator=':'
+      link_all_deplibs=yes
+      export_dynamic_flag_spec='${wl}-Bexport'
+      runpath_var='LD_RUN_PATH'
+
+      if test "$GCC" = yes; then
+	archive_cmds='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+	archive_expsym_cmds='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+      else
+	archive_cmds='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+	archive_expsym_cmds='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+      fi
+      ;;
+
+    uts4*)
+      archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+      hardcode_libdir_flag_spec='-L$libdir'
+      hardcode_shlibpath_var=no
+      ;;
+
+    *)
+      ld_shlibs=no
+      ;;
+    esac
+
+    if test x$host_vendor = xsni; then
+      case $host in
+      sysv4 | sysv4.2uw2* | sysv4.3* | sysv5*)
+	export_dynamic_flag_spec='${wl}-Blargedynsym'
+	;;
+      esac
+    fi
+  fi
+
+{ $as_echo "$as_me:$LINENO: result: $ld_shlibs" >&5
+$as_echo "$ld_shlibs" >&6; }
+test "$ld_shlibs" = no && can_build_shared=no
+
+with_gnu_ld=$with_gnu_ld
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#
+# Do we need to explicitly link libc?
+#
+case "x$archive_cmds_need_lc" in
+x|xyes)
+  # Assume -lc should be added
+  archive_cmds_need_lc=yes
+
+  if test "$enable_shared" = yes && test "$GCC" = yes; then
+    case $archive_cmds in
+    *'~'*)
+      # FIXME: we may have to deal with multi-command sequences.
+      ;;
+    '$CC '*)
+      # Test whether the compiler implicitly links with -lc since on some
+      # systems, -lgcc has to come before -lc. If gcc already passes -lc
+      # to ld, don't add -lc before -lgcc.
+      { $as_echo "$as_me:$LINENO: checking whether -lc should be explicitly linked in" >&5
+$as_echo_n "checking whether -lc should be explicitly linked in... " >&6; }
+      $RM conftest*
+      echo "$lt_simple_compile_test_code" > conftest.$ac_ext
+
+      if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } 2>conftest.err; then
+        soname=conftest
+        lib=conftest
+        libobjs=conftest.$ac_objext
+        deplibs=
+        wl=$lt_prog_compiler_wl
+	pic_flag=$lt_prog_compiler_pic
+        compiler_flags=-v
+        linker_flags=-v
+        verstring=
+        output_objdir=.
+        libname=conftest
+        lt_save_allow_undefined_flag=$allow_undefined_flag
+        allow_undefined_flag=
+        if { (eval echo "$as_me:$LINENO: \"$archive_cmds 2\>\&1 \| $GREP \" -lc \" \>/dev/null 2\>\&1\"") >&5
+  (eval $archive_cmds 2\>\&1 \| $GREP \" -lc \" \>/dev/null 2\>\&1) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }
+        then
+	  archive_cmds_need_lc=no
+        else
+	  archive_cmds_need_lc=yes
+        fi
+        allow_undefined_flag=$lt_save_allow_undefined_flag
+      else
+        cat conftest.err 1>&5
+      fi
+      $RM conftest*
+      { $as_echo "$as_me:$LINENO: result: $archive_cmds_need_lc" >&5
+$as_echo "$archive_cmds_need_lc" >&6; }
+      ;;
+    esac
+  fi
+  ;;
+esac
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+  { $as_echo "$as_me:$LINENO: checking dynamic linker characteristics" >&5
+$as_echo_n "checking dynamic linker characteristics... " >&6; }
+
+if test "$GCC" = yes; then
+  case $host_os in
+    darwin*) lt_awk_arg="/^libraries:/,/LR/" ;;
+    *) lt_awk_arg="/^libraries:/" ;;
+  esac
+  lt_search_path_spec=`$CC -print-search-dirs | awk $lt_awk_arg | $SED -e "s/^libraries://" -e "s,=/,/,g"`
+  if $ECHO "$lt_search_path_spec" | $GREP ';' >/dev/null ; then
+    # if the path contains ";" then we assume it to be the separator
+    # otherwise default to the standard path separator (i.e. ":") - it is
+    # assumed that no part of a normal pathname contains ";" but that should
+    # okay in the real world where ";" in dirpaths is itself problematic.
+    lt_search_path_spec=`$ECHO "$lt_search_path_spec" | $SED -e 's/;/ /g'`
+  else
+    lt_search_path_spec=`$ECHO "$lt_search_path_spec" | $SED  -e "s/$PATH_SEPARATOR/ /g"`
+  fi
+  # Ok, now we have the path, separated by spaces, we can step through it
+  # and add multilib dir if necessary.
+  lt_tmp_lt_search_path_spec=
+  lt_multi_os_dir=`$CC $CPPFLAGS $CFLAGS $LDFLAGS -print-multi-os-directory 2>/dev/null`
+  for lt_sys_path in $lt_search_path_spec; do
+    if test -d "$lt_sys_path/$lt_multi_os_dir"; then
+      lt_tmp_lt_search_path_spec="$lt_tmp_lt_search_path_spec $lt_sys_path/$lt_multi_os_dir"
+    else
+      test -d "$lt_sys_path" && \
+	lt_tmp_lt_search_path_spec="$lt_tmp_lt_search_path_spec $lt_sys_path"
+    fi
+  done
+  lt_search_path_spec=`$ECHO $lt_tmp_lt_search_path_spec | awk '
+BEGIN {RS=" "; FS="/|\n";} {
+  lt_foo="";
+  lt_count=0;
+  for (lt_i = NF; lt_i > 0; lt_i--) {
+    if ($lt_i != "" && $lt_i != ".") {
+      if ($lt_i == "..") {
+        lt_count++;
+      } else {
+        if (lt_count == 0) {
+          lt_foo="/" $lt_i lt_foo;
+        } else {
+          lt_count--;
+        }
+      }
+    }
+  }
+  if (lt_foo != "") { lt_freq[lt_foo]++; }
+  if (lt_freq[lt_foo] == 1) { print lt_foo; }
+}'`
+  sys_lib_search_path_spec=`$ECHO $lt_search_path_spec`
+else
+  sys_lib_search_path_spec="/lib /usr/lib /usr/local/lib"
+fi
+library_names_spec=
+libname_spec='lib$name'
+soname_spec=
+shrext_cmds=".so"
+postinstall_cmds=
+postuninstall_cmds=
+finish_cmds=
+finish_eval=
+shlibpath_var=
+shlibpath_overrides_runpath=unknown
+version_type=none
+dynamic_linker="$host_os ld.so"
+sys_lib_dlsearch_path_spec="/lib /usr/lib"
+need_lib_prefix=unknown
+hardcode_into_libs=no
+
+# when you set need_version to no, make sure it does not cause -set_version
+# flags to be left without arguments
+need_version=unknown
+
+case $host_os in
+aix3*)
+  version_type=linux
+  library_names_spec='${libname}${release}${shared_ext}$versuffix $libname.a'
+  shlibpath_var=LIBPATH
+
+  # AIX 3 has no versioning support, so we append a major version to the name.
+  soname_spec='${libname}${release}${shared_ext}$major'
+  ;;
+
+aix[4-9]*)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  hardcode_into_libs=yes
+  if test "$host_cpu" = ia64; then
+    # AIX 5 supports IA64
+    library_names_spec='${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext}$versuffix $libname${shared_ext}'
+    shlibpath_var=LD_LIBRARY_PATH
+  else
+    # With GCC up to 2.95.x, collect2 would create an import file
+    # for dependence libraries.  The import file would start with
+    # the line `#! .'.  This would cause the generated library to
+    # depend on `.', always an invalid library.  This was fixed in
+    # development snapshots of GCC prior to 3.0.
+    case $host_os in
+      aix4 | aix4.[01] | aix4.[01].*)
+      if { echo '#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 97)'
+	   echo ' yes '
+	   echo '#endif'; } | ${CC} -E - | $GREP yes > /dev/null; then
+	:
+      else
+	can_build_shared=no
+      fi
+      ;;
+    esac
+    # AIX (on Power*) has no versioning support, so currently we can not hardcode correct
+    # soname into executable. Probably we can add versioning support to
+    # collect2, so additional links can be useful in future.
+    if test "$aix_use_runtimelinking" = yes; then
+      # If using run time linking (on AIX 4.2 or later) use lib<name>.so
+      # instead of lib<name>.a to let people know that these are not
+      # typical AIX shared libraries.
+      library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+    else
+      # We preserve .a as extension for shared libraries through AIX4.2
+      # and later when we are not doing run time linking.
+      library_names_spec='${libname}${release}.a $libname.a'
+      soname_spec='${libname}${release}${shared_ext}$major'
+    fi
+    shlibpath_var=LIBPATH
+  fi
+  ;;
+
+amigaos*)
+  case $host_cpu in
+  powerpc)
+    # Since July 2007 AmigaOS4 officially supports .so libraries.
+    # When compiling the executable, add -use-dynld -Lsobjs: to the compileline.
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+    ;;
+  m68k)
+    library_names_spec='$libname.ixlibrary $libname.a'
+    # Create ${libname}_ixlibrary.a entries in /sys/libs.
+    finish_eval='for lib in `ls $libdir/*.ixlibrary 2>/dev/null`; do libname=`$ECHO "X$lib" | $Xsed -e '\''s%^.*/\([^/]*\)\.ixlibrary$%\1%'\''`; test $RM /sys/libs/${libname}_ixlibrary.a; $show "cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a"; cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a || exit 1; done'
+    ;;
+  esac
+  ;;
+
+beos*)
+  library_names_spec='${libname}${shared_ext}'
+  dynamic_linker="$host_os ld.so"
+  shlibpath_var=LIBRARY_PATH
+  ;;
+
+bsdi[45]*)
+  version_type=linux
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  finish_cmds='PATH="\$PATH:/sbin" ldconfig $libdir'
+  shlibpath_var=LD_LIBRARY_PATH
+  sys_lib_search_path_spec="/shlib /usr/lib /usr/X11/lib /usr/contrib/lib /lib /usr/local/lib"
+  sys_lib_dlsearch_path_spec="/shlib /usr/lib /usr/local/lib"
+  # the default ld.so.conf also contains /usr/contrib/lib and
+  # /usr/X11R6/lib (/usr/X11 is a link to /usr/X11R6), but let us allow
+  # libtool to hard-code these into programs
+  ;;
+
+cygwin* | mingw* | pw32* | cegcc*)
+  version_type=windows
+  shrext_cmds=".dll"
+  need_version=no
+  need_lib_prefix=no
+
+  case $GCC,$host_os in
+  yes,cygwin* | yes,mingw* | yes,pw32* | yes,cegcc*)
+    library_names_spec='$libname.dll.a'
+    # DLL is installed to $(libdir)/../bin by postinstall_cmds
+    postinstall_cmds='base_file=`basename \${file}`~
+      dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
+      dldir=$destdir/`dirname \$dlpath`~
+      test -d \$dldir || mkdir -p \$dldir~
+      $install_prog $dir/$dlname \$dldir/$dlname~
+      chmod a+x \$dldir/$dlname~
+      if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
+        eval '\''$striplib \$dldir/$dlname'\'' || exit \$?;
+      fi'
+    postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~
+      dlpath=$dir/\$dldll~
+       $RM \$dlpath'
+    shlibpath_overrides_runpath=yes
+
+    case $host_os in
+    cygwin*)
+      # Cygwin DLLs use 'cyg' prefix rather than 'lib'
+      soname_spec='`echo ${libname} | sed -e 's/^lib/cyg/'``echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}'
+      sys_lib_search_path_spec="/usr/lib /lib/w32api /lib /usr/local/lib"
+      ;;
+    mingw* | cegcc*)
+      # MinGW DLLs use traditional 'lib' prefix
+      soname_spec='${libname}`echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}'
+      sys_lib_search_path_spec=`$CC -print-search-dirs | $GREP "^libraries:" | $SED -e "s/^libraries://" -e "s,=/,/,g"`
+      if $ECHO "$sys_lib_search_path_spec" | $GREP ';[c-zC-Z]:/' >/dev/null; then
+        # It is most probably a Windows format PATH printed by
+        # mingw gcc, but we are running on Cygwin. Gcc prints its search
+        # path with ; separators, and with drive letters. We can handle the
+        # drive letters (cygwin fileutils understands them), so leave them,
+        # especially as we might pass files found there to a mingw objdump,
+        # which wouldn't understand a cygwinified path. Ahh.
+        sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED -e 's/;/ /g'`
+      else
+        sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED  -e "s/$PATH_SEPARATOR/ /g"`
+      fi
+      ;;
+    pw32*)
+      # pw32 DLLs use 'pw' prefix rather than 'lib'
+      library_names_spec='`echo ${libname} | sed -e 's/^lib/pw/'``echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}'
+      ;;
+    esac
+    ;;
+
+  *)
+    library_names_spec='${libname}`echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext} $libname.lib'
+    ;;
+  esac
+  dynamic_linker='Win32 ld.exe'
+  # FIXME: first we should search . and the directory the executable is in
+  shlibpath_var=PATH
+  ;;
+
+darwin* | rhapsody*)
+  dynamic_linker="$host_os dyld"
+  version_type=darwin
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${major}$shared_ext ${libname}$shared_ext'
+  soname_spec='${libname}${release}${major}$shared_ext'
+  shlibpath_overrides_runpath=yes
+  shlibpath_var=DYLD_LIBRARY_PATH
+  shrext_cmds='`test .$module = .yes && echo .so || echo .dylib`'
+
+  sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/local/lib"
+  sys_lib_dlsearch_path_spec='/usr/local/lib /lib /usr/lib'
+  ;;
+
+dgux*)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname$shared_ext'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  ;;
+
+freebsd1*)
+  dynamic_linker=no
+  ;;
+
+freebsd* | dragonfly*)
+  # DragonFly does not have aout.  When/if they implement a new
+  # versioning mechanism, adjust this.
+  if test -x /usr/bin/objformat; then
+    objformat=`/usr/bin/objformat`
+  else
+    case $host_os in
+    freebsd[123]*) objformat=aout ;;
+    *) objformat=elf ;;
+    esac
+  fi
+  version_type=freebsd-$objformat
+  case $version_type in
+    freebsd-elf*)
+      library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}'
+      need_version=no
+      need_lib_prefix=no
+      ;;
+    freebsd-*)
+      library_names_spec='${libname}${release}${shared_ext}$versuffix $libname${shared_ext}$versuffix'
+      need_version=yes
+      ;;
+  esac
+  shlibpath_var=LD_LIBRARY_PATH
+  case $host_os in
+  freebsd2*)
+    shlibpath_overrides_runpath=yes
+    ;;
+  freebsd3.[01]* | freebsdelf3.[01]*)
+    shlibpath_overrides_runpath=yes
+    hardcode_into_libs=yes
+    ;;
+  freebsd3.[2-9]* | freebsdelf3.[2-9]* | \
+  freebsd4.[0-5] | freebsdelf4.[0-5] | freebsd4.1.1 | freebsdelf4.1.1)
+    shlibpath_overrides_runpath=no
+    hardcode_into_libs=yes
+    ;;
+  *) # from 4.6 on, and DragonFly
+    shlibpath_overrides_runpath=yes
+    hardcode_into_libs=yes
+    ;;
+  esac
+  ;;
+
+gnu*)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}${major} ${libname}${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  hardcode_into_libs=yes
+  ;;
+
+hpux9* | hpux10* | hpux11*)
+  # Give a soname corresponding to the major version so that dld.sl refuses to
+  # link against other versions.
+  version_type=sunos
+  need_lib_prefix=no
+  need_version=no
+  case $host_cpu in
+  ia64*)
+    shrext_cmds='.so'
+    hardcode_into_libs=yes
+    dynamic_linker="$host_os dld.so"
+    shlibpath_var=LD_LIBRARY_PATH
+    shlibpath_overrides_runpath=yes # Unless +noenvvar is specified.
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+    soname_spec='${libname}${release}${shared_ext}$major'
+    if test "X$HPUX_IA64_MODE" = X32; then
+      sys_lib_search_path_spec="/usr/lib/hpux32 /usr/local/lib/hpux32 /usr/local/lib"
+    else
+      sys_lib_search_path_spec="/usr/lib/hpux64 /usr/local/lib/hpux64"
+    fi
+    sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec
+    ;;
+  hppa*64*)
+    shrext_cmds='.sl'
+    hardcode_into_libs=yes
+    dynamic_linker="$host_os dld.sl"
+    shlibpath_var=LD_LIBRARY_PATH # How should we handle SHLIB_PATH
+    shlibpath_overrides_runpath=yes # Unless +noenvvar is specified.
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+    soname_spec='${libname}${release}${shared_ext}$major'
+    sys_lib_search_path_spec="/usr/lib/pa20_64 /usr/ccs/lib/pa20_64"
+    sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec
+    ;;
+  *)
+    shrext_cmds='.sl'
+    dynamic_linker="$host_os dld.sl"
+    shlibpath_var=SHLIB_PATH
+    shlibpath_overrides_runpath=no # +s is required to enable SHLIB_PATH
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+    soname_spec='${libname}${release}${shared_ext}$major'
+    ;;
+  esac
+  # HP-UX runs *really* slowly unless shared libraries are mode 555.
+  postinstall_cmds='chmod 555 $lib'
+  ;;
+
+interix[3-9]*)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  dynamic_linker='Interix 3.x ld.so.1 (PE, like ELF)'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=no
+  hardcode_into_libs=yes
+  ;;
+
+irix5* | irix6* | nonstopux*)
+  case $host_os in
+    nonstopux*) version_type=nonstopux ;;
+    *)
+	if test "$lt_cv_prog_gnu_ld" = yes; then
+		version_type=linux
+	else
+		version_type=irix
+	fi ;;
+  esac
+  need_lib_prefix=no
+  need_version=no
+  soname_spec='${libname}${release}${shared_ext}$major'
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext} $libname${shared_ext}'
+  case $host_os in
+  irix5* | nonstopux*)
+    libsuff= shlibsuff=
+    ;;
+  *)
+    case $LD in # libtool.m4 will add one of these switches to LD
+    *-32|*"-32 "|*-melf32bsmip|*"-melf32bsmip ")
+      libsuff= shlibsuff= libmagic=32-bit;;
+    *-n32|*"-n32 "|*-melf32bmipn32|*"-melf32bmipn32 ")
+      libsuff=32 shlibsuff=N32 libmagic=N32;;
+    *-64|*"-64 "|*-melf64bmip|*"-melf64bmip ")
+      libsuff=64 shlibsuff=64 libmagic=64-bit;;
+    *) libsuff= shlibsuff= libmagic=never-match;;
+    esac
+    ;;
+  esac
+  shlibpath_var=LD_LIBRARY${shlibsuff}_PATH
+  shlibpath_overrides_runpath=no
+  sys_lib_search_path_spec="/usr/lib${libsuff} /lib${libsuff} /usr/local/lib${libsuff}"
+  sys_lib_dlsearch_path_spec="/usr/lib${libsuff} /lib${libsuff}"
+  hardcode_into_libs=yes
+  ;;
+
+# No shared lib support for Linux oldld, aout, or coff.
+linux*oldld* | linux*aout* | linux*coff*)
+  dynamic_linker=no
+  ;;
+
+# This must be Linux ELF.
+linux* | k*bsd*-gnu)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  finish_cmds='PATH="\$PATH:/sbin" ldconfig -n $libdir'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=no
+  # Some binutils ld are patched to set DT_RUNPATH
+  save_LDFLAGS=$LDFLAGS
+  save_libdir=$libdir
+  eval "libdir=/foo; wl=\"$lt_prog_compiler_wl\"; \
+       LDFLAGS=\"\$LDFLAGS $hardcode_libdir_flag_spec\""
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext && {
+	 test "$cross_compiling" = yes ||
+	 $as_test_x conftest$ac_exeext
+       }; then
+  if  ($OBJDUMP -p conftest$ac_exeext) 2>/dev/null | grep "RUNPATH.*$libdir" >/dev/null; then
+  shlibpath_overrides_runpath=yes
+fi
+
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+
+fi
+
+rm -rf conftest.dSYM
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+  LDFLAGS=$save_LDFLAGS
+  libdir=$save_libdir
+
+  # This implies no fast_install, which is unacceptable.
+  # Some rework will be needed to allow for fast_install
+  # before this can be enabled.
+  hardcode_into_libs=yes
+
+  # Add ABI-specific directories to the system library path.
+  sys_lib_dlsearch_path_spec="/lib64 /usr/lib64 /lib /usr/lib"
+
+  # Append ld.so.conf contents to the search path
+  if test -f /etc/ld.so.conf; then
+    lt_ld_extra=`awk '/^include / { system(sprintf("cd /etc; cat %s 2>/dev/null", \$2)); skip = 1; } { if (!skip) print \$0; skip = 0; }' < /etc/ld.so.conf | $SED -e 's/#.*//;/^[	 ]*hwcap[	 ]/d;s/[:,	]/ /g;s/=[^=]*$//;s/=[^= ]* / /g;/^$/d' | tr '\n' ' '`
+    sys_lib_dlsearch_path_spec="$sys_lib_dlsearch_path_spec $lt_ld_extra"
+  fi
+
+  # We used to test for /lib/ld.so.1 and disable shared libraries on
+  # powerpc, because MkLinux only supported shared libraries with the
+  # GNU dynamic linker.  Since this was broken with cross compilers,
+  # most powerpc-linux boxes support dynamic linking these days and
+  # people can always --disable-shared, the test was removed, and we
+  # assume the GNU/Linux dynamic linker is in use.
+  dynamic_linker='GNU/Linux ld.so'
+  ;;
+
+netbsd*)
+  version_type=sunos
+  need_lib_prefix=no
+  need_version=no
+  if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix'
+    finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir'
+    dynamic_linker='NetBSD (a.out) ld.so'
+  else
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}'
+    soname_spec='${libname}${release}${shared_ext}$major'
+    dynamic_linker='NetBSD ld.elf_so'
+  fi
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  hardcode_into_libs=yes
+  ;;
+
+newsos6)
+  version_type=linux
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  ;;
+
+*nto* | *qnx*)
+  version_type=qnx
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=no
+  hardcode_into_libs=yes
+  dynamic_linker='ldqnx.so'
+  ;;
+
+openbsd*)
+  version_type=sunos
+  sys_lib_dlsearch_path_spec="/usr/lib"
+  need_lib_prefix=no
+  # Some older versions of OpenBSD (3.3 at least) *do* need versioned libs.
+  case $host_os in
+    openbsd3.3 | openbsd3.3.*)	need_version=yes ;;
+    *)				need_version=no  ;;
+  esac
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix'
+  finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir'
+  shlibpath_var=LD_LIBRARY_PATH
+  if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
+    case $host_os in
+      openbsd2.[89] | openbsd2.[89].*)
+	shlibpath_overrides_runpath=no
+	;;
+      *)
+	shlibpath_overrides_runpath=yes
+	;;
+      esac
+  else
+    shlibpath_overrides_runpath=yes
+  fi
+  ;;
+
+os2*)
+  libname_spec='$name'
+  shrext_cmds=".dll"
+  need_lib_prefix=no
+  library_names_spec='$libname${shared_ext} $libname.a'
+  dynamic_linker='OS/2 ld.exe'
+  shlibpath_var=LIBPATH
+  ;;
+
+osf3* | osf4* | osf5*)
+  version_type=osf
+  need_lib_prefix=no
+  need_version=no
+  soname_spec='${libname}${release}${shared_ext}$major'
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  shlibpath_var=LD_LIBRARY_PATH
+  sys_lib_search_path_spec="/usr/shlib /usr/ccs/lib /usr/lib/cmplrs/cc /usr/lib /usr/local/lib /var/shlib"
+  sys_lib_dlsearch_path_spec="$sys_lib_search_path_spec"
+  ;;
+
+rdos*)
+  dynamic_linker=no
+  ;;
+
+solaris*)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  hardcode_into_libs=yes
+  # ldd complains unless libraries are executable
+  postinstall_cmds='chmod +x $lib'
+  ;;
+
+sunos4*)
+  version_type=sunos
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix'
+  finish_cmds='PATH="\$PATH:/usr/etc" ldconfig $libdir'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  if test "$with_gnu_ld" = yes; then
+    need_lib_prefix=no
+  fi
+  need_version=yes
+  ;;
+
+sysv4 | sysv4.3*)
+  version_type=linux
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  case $host_vendor in
+    sni)
+      shlibpath_overrides_runpath=no
+      need_lib_prefix=no
+      runpath_var=LD_RUN_PATH
+      ;;
+    siemens)
+      need_lib_prefix=no
+      ;;
+    motorola)
+      need_lib_prefix=no
+      need_version=no
+      shlibpath_overrides_runpath=no
+      sys_lib_search_path_spec='/lib /usr/lib /usr/ccs/lib'
+      ;;
+  esac
+  ;;
+
+sysv4*MP*)
+  if test -d /usr/nec ;then
+    version_type=linux
+    library_names_spec='$libname${shared_ext}.$versuffix $libname${shared_ext}.$major $libname${shared_ext}'
+    soname_spec='$libname${shared_ext}.$major'
+    shlibpath_var=LD_LIBRARY_PATH
+  fi
+  ;;
+
+sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*)
+  version_type=freebsd-elf
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  hardcode_into_libs=yes
+  if test "$with_gnu_ld" = yes; then
+    sys_lib_search_path_spec='/usr/local/lib /usr/gnu/lib /usr/ccs/lib /usr/lib /lib'
+  else
+    sys_lib_search_path_spec='/usr/ccs/lib /usr/lib'
+    case $host_os in
+      sco3.2v5*)
+        sys_lib_search_path_spec="$sys_lib_search_path_spec /lib"
+	;;
+    esac
+  fi
+  sys_lib_dlsearch_path_spec='/usr/lib'
+  ;;
+
+tpf*)
+  # TPF is a cross-target only.  Preferred cross-host = GNU/Linux.
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=no
+  hardcode_into_libs=yes
+  ;;
+
+uts4*)
+  version_type=linux
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  ;;
+
+*)
+  dynamic_linker=no
+  ;;
+esac
+{ $as_echo "$as_me:$LINENO: result: $dynamic_linker" >&5
+$as_echo "$dynamic_linker" >&6; }
+test "$dynamic_linker" = no && can_build_shared=no
+
+variables_saved_for_relink="PATH $shlibpath_var $runpath_var"
+if test "$GCC" = yes; then
+  variables_saved_for_relink="$variables_saved_for_relink GCC_EXEC_PREFIX COMPILER_PATH LIBRARY_PATH"
+fi
+
+if test "${lt_cv_sys_lib_search_path_spec+set}" = set; then
+  sys_lib_search_path_spec="$lt_cv_sys_lib_search_path_spec"
+fi
+if test "${lt_cv_sys_lib_dlsearch_path_spec+set}" = set; then
+  sys_lib_dlsearch_path_spec="$lt_cv_sys_lib_dlsearch_path_spec"
+fi
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+  { $as_echo "$as_me:$LINENO: checking how to hardcode library paths into programs" >&5
+$as_echo_n "checking how to hardcode library paths into programs... " >&6; }
+hardcode_action=
+if test -n "$hardcode_libdir_flag_spec" ||
+   test -n "$runpath_var" ||
+   test "X$hardcode_automatic" = "Xyes" ; then
+
+  # We can hardcode non-existent directories.
+  if test "$hardcode_direct" != no &&
+     # If the only mechanism to avoid hardcoding is shlibpath_var, we
+     # have to relink, otherwise we might link with an installed library
+     # when we should be linking with a yet-to-be-installed one
+     ## test "$_LT_TAGVAR(hardcode_shlibpath_var, )" != no &&
+     test "$hardcode_minus_L" != no; then
+    # Linking always hardcodes the temporary library directory.
+    hardcode_action=relink
+  else
+    # We can link without hardcoding, and we can hardcode nonexisting dirs.
+    hardcode_action=immediate
+  fi
+else
+  # We cannot hardcode anything, or else we can only hardcode existing
+  # directories.
+  hardcode_action=unsupported
+fi
+{ $as_echo "$as_me:$LINENO: result: $hardcode_action" >&5
+$as_echo "$hardcode_action" >&6; }
+
+if test "$hardcode_action" = relink ||
+   test "$inherit_rpath" = yes; then
+  # Fast installation is not supported
+  enable_fast_install=no
+elif test "$shlibpath_overrides_runpath" = yes ||
+     test "$enable_shared" = no; then
+  # Fast installation is not necessary
+  enable_fast_install=needless
+fi
+
+
+
+
+
+
+  if test "x$enable_dlopen" != xyes; then
+  enable_dlopen=unknown
+  enable_dlopen_self=unknown
+  enable_dlopen_self_static=unknown
+else
+  lt_cv_dlopen=no
+  lt_cv_dlopen_libs=
+
+  case $host_os in
+  beos*)
+    lt_cv_dlopen="load_add_on"
+    lt_cv_dlopen_libs=
+    lt_cv_dlopen_self=yes
+    ;;
+
+  mingw* | pw32* | cegcc*)
+    lt_cv_dlopen="LoadLibrary"
+    lt_cv_dlopen_libs=
+    ;;
+
+  cygwin*)
+    lt_cv_dlopen="dlopen"
+    lt_cv_dlopen_libs=
+    ;;
+
+  darwin*)
+  # if libdl is installed we need to link against it
+    { $as_echo "$as_me:$LINENO: checking for dlopen in -ldl" >&5
+$as_echo_n "checking for dlopen in -ldl... " >&6; }
+if test "${ac_cv_lib_dl_dlopen+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-ldl  $LIBS"
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char dlopen ();
+int
+main ()
+{
+return dlopen ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext && {
+	 test "$cross_compiling" = yes ||
+	 $as_test_x conftest$ac_exeext
+       }; then
+  ac_cv_lib_dl_dlopen=yes
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_cv_lib_dl_dlopen=no
+fi
+
+rm -rf conftest.dSYM
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_lib_dl_dlopen" >&5
+$as_echo "$ac_cv_lib_dl_dlopen" >&6; }
+if test "x$ac_cv_lib_dl_dlopen" = x""yes; then
+  lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-ldl"
+else
+
+    lt_cv_dlopen="dyld"
+    lt_cv_dlopen_libs=
+    lt_cv_dlopen_self=yes
+
+fi
+
+    ;;
+
+  *)
+    { $as_echo "$as_me:$LINENO: checking for shl_load" >&5
+$as_echo_n "checking for shl_load... " >&6; }
+if test "${ac_cv_func_shl_load+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+/* Define shl_load to an innocuous variant, in case <limits.h> declares shl_load.
+   For example, HP-UX 11i <limits.h> declares gettimeofday.  */
+#define shl_load innocuous_shl_load
+
+/* System header to define __stub macros and hopefully few prototypes,
+    which can conflict with char shl_load (); below.
+    Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+    <limits.h> exists even on freestanding compilers.  */
+
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+
+#undef shl_load
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char shl_load ();
+/* The GNU C library defines this for functions which it implements
+    to always fail with ENOSYS.  Some functions are actually named
+    something starting with __ and the normal name is an alias.  */
+#if defined __stub_shl_load || defined __stub___shl_load
+choke me
+#endif
+
+int
+main ()
+{
+return shl_load ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext && {
+	 test "$cross_compiling" = yes ||
+	 $as_test_x conftest$ac_exeext
+       }; then
+  ac_cv_func_shl_load=yes
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_cv_func_shl_load=no
+fi
+
+rm -rf conftest.dSYM
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_func_shl_load" >&5
+$as_echo "$ac_cv_func_shl_load" >&6; }
+if test "x$ac_cv_func_shl_load" = x""yes; then
+  lt_cv_dlopen="shl_load"
+else
+  { $as_echo "$as_me:$LINENO: checking for shl_load in -ldld" >&5
+$as_echo_n "checking for shl_load in -ldld... " >&6; }
+if test "${ac_cv_lib_dld_shl_load+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-ldld  $LIBS"
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char shl_load ();
+int
+main ()
+{
+return shl_load ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext && {
+	 test "$cross_compiling" = yes ||
+	 $as_test_x conftest$ac_exeext
+       }; then
+  ac_cv_lib_dld_shl_load=yes
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_cv_lib_dld_shl_load=no
+fi
+
+rm -rf conftest.dSYM
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_lib_dld_shl_load" >&5
+$as_echo "$ac_cv_lib_dld_shl_load" >&6; }
+if test "x$ac_cv_lib_dld_shl_load" = x""yes; then
+  lt_cv_dlopen="shl_load" lt_cv_dlopen_libs="-ldld"
+else
+  { $as_echo "$as_me:$LINENO: checking for dlopen" >&5
+$as_echo_n "checking for dlopen... " >&6; }
+if test "${ac_cv_func_dlopen+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+/* Define dlopen to an innocuous variant, in case <limits.h> declares dlopen.
+   For example, HP-UX 11i <limits.h> declares gettimeofday.  */
+#define dlopen innocuous_dlopen
+
+/* System header to define __stub macros and hopefully few prototypes,
+    which can conflict with char dlopen (); below.
+    Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+    <limits.h> exists even on freestanding compilers.  */
+
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+
+#undef dlopen
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char dlopen ();
+/* The GNU C library defines this for functions which it implements
+    to always fail with ENOSYS.  Some functions are actually named
+    something starting with __ and the normal name is an alias.  */
+#if defined __stub_dlopen || defined __stub___dlopen
+choke me
+#endif
+
+int
+main ()
+{
+return dlopen ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext && {
+	 test "$cross_compiling" = yes ||
+	 $as_test_x conftest$ac_exeext
+       }; then
+  ac_cv_func_dlopen=yes
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_cv_func_dlopen=no
+fi
+
+rm -rf conftest.dSYM
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_func_dlopen" >&5
+$as_echo "$ac_cv_func_dlopen" >&6; }
+if test "x$ac_cv_func_dlopen" = x""yes; then
+  lt_cv_dlopen="dlopen"
+else
+  { $as_echo "$as_me:$LINENO: checking for dlopen in -ldl" >&5
+$as_echo_n "checking for dlopen in -ldl... " >&6; }
+if test "${ac_cv_lib_dl_dlopen+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-ldl  $LIBS"
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char dlopen ();
+int
+main ()
+{
+return dlopen ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext && {
+	 test "$cross_compiling" = yes ||
+	 $as_test_x conftest$ac_exeext
+       }; then
+  ac_cv_lib_dl_dlopen=yes
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_cv_lib_dl_dlopen=no
+fi
+
+rm -rf conftest.dSYM
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_lib_dl_dlopen" >&5
+$as_echo "$ac_cv_lib_dl_dlopen" >&6; }
+if test "x$ac_cv_lib_dl_dlopen" = x""yes; then
+  lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-ldl"
+else
+  { $as_echo "$as_me:$LINENO: checking for dlopen in -lsvld" >&5
+$as_echo_n "checking for dlopen in -lsvld... " >&6; }
+if test "${ac_cv_lib_svld_dlopen+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lsvld  $LIBS"
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char dlopen ();
+int
+main ()
+{
+return dlopen ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext && {
+	 test "$cross_compiling" = yes ||
+	 $as_test_x conftest$ac_exeext
+       }; then
+  ac_cv_lib_svld_dlopen=yes
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_cv_lib_svld_dlopen=no
+fi
+
+rm -rf conftest.dSYM
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_lib_svld_dlopen" >&5
+$as_echo "$ac_cv_lib_svld_dlopen" >&6; }
+if test "x$ac_cv_lib_svld_dlopen" = x""yes; then
+  lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-lsvld"
+else
+  { $as_echo "$as_me:$LINENO: checking for dld_link in -ldld" >&5
+$as_echo_n "checking for dld_link in -ldld... " >&6; }
+if test "${ac_cv_lib_dld_dld_link+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-ldld  $LIBS"
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char dld_link ();
+int
+main ()
+{
+return dld_link ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext && {
+	 test "$cross_compiling" = yes ||
+	 $as_test_x conftest$ac_exeext
+       }; then
+  ac_cv_lib_dld_dld_link=yes
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_cv_lib_dld_dld_link=no
+fi
+
+rm -rf conftest.dSYM
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_lib_dld_dld_link" >&5
+$as_echo "$ac_cv_lib_dld_dld_link" >&6; }
+if test "x$ac_cv_lib_dld_dld_link" = x""yes; then
+  lt_cv_dlopen="dld_link" lt_cv_dlopen_libs="-ldld"
+fi
+
+
+fi
+
+
+fi
+
+
+fi
+
+
+fi
+
+
+fi
+
+    ;;
+  esac
+
+  if test "x$lt_cv_dlopen" != xno; then
+    enable_dlopen=yes
+  else
+    enable_dlopen=no
+  fi
+
+  case $lt_cv_dlopen in
+  dlopen)
+    save_CPPFLAGS="$CPPFLAGS"
+    test "x$ac_cv_header_dlfcn_h" = xyes && CPPFLAGS="$CPPFLAGS -DHAVE_DLFCN_H"
+
+    save_LDFLAGS="$LDFLAGS"
+    wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $export_dynamic_flag_spec\"
+
+    save_LIBS="$LIBS"
+    LIBS="$lt_cv_dlopen_libs $LIBS"
+
+    { $as_echo "$as_me:$LINENO: checking whether a program can dlopen itself" >&5
+$as_echo_n "checking whether a program can dlopen itself... " >&6; }
+if test "${lt_cv_dlopen_self+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  	  if test "$cross_compiling" = yes; then :
+  lt_cv_dlopen_self=cross
+else
+  lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+  lt_status=$lt_dlunknown
+  cat > conftest.$ac_ext <<_LT_EOF
+#line 11950 "configure"
+#include "confdefs.h"
+
+#if HAVE_DLFCN_H
+#include <dlfcn.h>
+#endif
+
+#include <stdio.h>
+
+#ifdef RTLD_GLOBAL
+#  define LT_DLGLOBAL		RTLD_GLOBAL
+#else
+#  ifdef DL_GLOBAL
+#    define LT_DLGLOBAL		DL_GLOBAL
+#  else
+#    define LT_DLGLOBAL		0
+#  endif
+#endif
+
+/* We may have to define LT_DLLAZY_OR_NOW in the command line if we
+   find out it does not work in some platform. */
+#ifndef LT_DLLAZY_OR_NOW
+#  ifdef RTLD_LAZY
+#    define LT_DLLAZY_OR_NOW		RTLD_LAZY
+#  else
+#    ifdef DL_LAZY
+#      define LT_DLLAZY_OR_NOW		DL_LAZY
+#    else
+#      ifdef RTLD_NOW
+#        define LT_DLLAZY_OR_NOW	RTLD_NOW
+#      else
+#        ifdef DL_NOW
+#          define LT_DLLAZY_OR_NOW	DL_NOW
+#        else
+#          define LT_DLLAZY_OR_NOW	0
+#        endif
+#      endif
+#    endif
+#  endif
+#endif
+
+void fnord() { int i=42;}
+int main ()
+{
+  void *self = dlopen (0, LT_DLGLOBAL|LT_DLLAZY_OR_NOW);
+  int status = $lt_dlunknown;
+
+  if (self)
+    {
+      if (dlsym (self,"fnord"))       status = $lt_dlno_uscore;
+      else if (dlsym( self,"_fnord")) status = $lt_dlneed_uscore;
+      /* dlclose (self); */
+    }
+  else
+    puts (dlerror ());
+
+  return status;
+}
+_LT_EOF
+  if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && test -s conftest${ac_exeext} 2>/dev/null; then
+    (./conftest; exit; ) >&5 2>/dev/null
+    lt_status=$?
+    case x$lt_status in
+      x$lt_dlno_uscore) lt_cv_dlopen_self=yes ;;
+      x$lt_dlneed_uscore) lt_cv_dlopen_self=yes ;;
+      x$lt_dlunknown|x*) lt_cv_dlopen_self=no ;;
+    esac
+  else :
+    # compilation failed
+    lt_cv_dlopen_self=no
+  fi
+fi
+rm -fr conftest*
+
+
+fi
+{ $as_echo "$as_me:$LINENO: result: $lt_cv_dlopen_self" >&5
+$as_echo "$lt_cv_dlopen_self" >&6; }
+
+    if test "x$lt_cv_dlopen_self" = xyes; then
+      wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $lt_prog_compiler_static\"
+      { $as_echo "$as_me:$LINENO: checking whether a statically linked program can dlopen itself" >&5
+$as_echo_n "checking whether a statically linked program can dlopen itself... " >&6; }
+if test "${lt_cv_dlopen_self_static+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  	  if test "$cross_compiling" = yes; then :
+  lt_cv_dlopen_self_static=cross
+else
+  lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+  lt_status=$lt_dlunknown
+  cat > conftest.$ac_ext <<_LT_EOF
+#line 12046 "configure"
+#include "confdefs.h"
+
+#if HAVE_DLFCN_H
+#include <dlfcn.h>
+#endif
+
+#include <stdio.h>
+
+#ifdef RTLD_GLOBAL
+#  define LT_DLGLOBAL		RTLD_GLOBAL
+#else
+#  ifdef DL_GLOBAL
+#    define LT_DLGLOBAL		DL_GLOBAL
+#  else
+#    define LT_DLGLOBAL		0
+#  endif
+#endif
+
+/* We may have to define LT_DLLAZY_OR_NOW in the command line if we
+   find out it does not work in some platform. */
+#ifndef LT_DLLAZY_OR_NOW
+#  ifdef RTLD_LAZY
+#    define LT_DLLAZY_OR_NOW		RTLD_LAZY
+#  else
+#    ifdef DL_LAZY
+#      define LT_DLLAZY_OR_NOW		DL_LAZY
+#    else
+#      ifdef RTLD_NOW
+#        define LT_DLLAZY_OR_NOW	RTLD_NOW
+#      else
+#        ifdef DL_NOW
+#          define LT_DLLAZY_OR_NOW	DL_NOW
+#        else
+#          define LT_DLLAZY_OR_NOW	0
+#        endif
+#      endif
+#    endif
+#  endif
+#endif
+
+void fnord() { int i=42;}
+int main ()
+{
+  void *self = dlopen (0, LT_DLGLOBAL|LT_DLLAZY_OR_NOW);
+  int status = $lt_dlunknown;
+
+  if (self)
+    {
+      if (dlsym (self,"fnord"))       status = $lt_dlno_uscore;
+      else if (dlsym( self,"_fnord")) status = $lt_dlneed_uscore;
+      /* dlclose (self); */
+    }
+  else
+    puts (dlerror ());
+
+  return status;
+}
+_LT_EOF
+  if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && test -s conftest${ac_exeext} 2>/dev/null; then
+    (./conftest; exit; ) >&5 2>/dev/null
+    lt_status=$?
+    case x$lt_status in
+      x$lt_dlno_uscore) lt_cv_dlopen_self_static=yes ;;
+      x$lt_dlneed_uscore) lt_cv_dlopen_self_static=yes ;;
+      x$lt_dlunknown|x*) lt_cv_dlopen_self_static=no ;;
+    esac
+  else :
+    # compilation failed
+    lt_cv_dlopen_self_static=no
+  fi
+fi
+rm -fr conftest*
+
+
+fi
+{ $as_echo "$as_me:$LINENO: result: $lt_cv_dlopen_self_static" >&5
+$as_echo "$lt_cv_dlopen_self_static" >&6; }
+    fi
+
+    CPPFLAGS="$save_CPPFLAGS"
+    LDFLAGS="$save_LDFLAGS"
+    LIBS="$save_LIBS"
+    ;;
+  esac
+
+  case $lt_cv_dlopen_self in
+  yes|no) enable_dlopen_self=$lt_cv_dlopen_self ;;
+  *) enable_dlopen_self=unknown ;;
+  esac
+
+  case $lt_cv_dlopen_self_static in
+  yes|no) enable_dlopen_self_static=$lt_cv_dlopen_self_static ;;
+  *) enable_dlopen_self_static=unknown ;;
+  esac
+fi
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+striplib=
+old_striplib=
+{ $as_echo "$as_me:$LINENO: checking whether stripping libraries is possible" >&5
+$as_echo_n "checking whether stripping libraries is possible... " >&6; }
+if test -n "$STRIP" && $STRIP -V 2>&1 | $GREP "GNU strip" >/dev/null; then
+  test -z "$old_striplib" && old_striplib="$STRIP --strip-debug"
+  test -z "$striplib" && striplib="$STRIP --strip-unneeded"
+  { $as_echo "$as_me:$LINENO: result: yes" >&5
+$as_echo "yes" >&6; }
+else
+# FIXME - insert some real tests, host_os isn't really good enough
+  case $host_os in
+  darwin*)
+    if test -n "$STRIP" ; then
+      striplib="$STRIP -x"
+      old_striplib="$STRIP -S"
+      { $as_echo "$as_me:$LINENO: result: yes" >&5
+$as_echo "yes" >&6; }
+    else
+      { $as_echo "$as_me:$LINENO: result: no" >&5
+$as_echo "no" >&6; }
+    fi
+    ;;
+  *)
+    { $as_echo "$as_me:$LINENO: result: no" >&5
+$as_echo "no" >&6; }
+    ;;
+  esac
+fi
+
+
+
+
+
+
+
+
+
+
+
+
+  # Report which library types will actually be built
+  { $as_echo "$as_me:$LINENO: checking if libtool supports shared libraries" >&5
+$as_echo_n "checking if libtool supports shared libraries... " >&6; }
+  { $as_echo "$as_me:$LINENO: result: $can_build_shared" >&5
+$as_echo "$can_build_shared" >&6; }
+
+  { $as_echo "$as_me:$LINENO: checking whether to build shared libraries" >&5
+$as_echo_n "checking whether to build shared libraries... " >&6; }
+  test "$can_build_shared" = "no" && enable_shared=no
+
+  # On AIX, shared libraries and static libraries use the same namespace, and
+  # are all built from PIC.
+  case $host_os in
+  aix3*)
+    test "$enable_shared" = yes && enable_static=no
+    if test -n "$RANLIB"; then
+      archive_cmds="$archive_cmds~\$RANLIB \$lib"
+      postinstall_cmds='$RANLIB $lib'
+    fi
+    ;;
+
+  aix[4-9]*)
+    if test "$host_cpu" != ia64 && test "$aix_use_runtimelinking" = no ; then
+      test "$enable_shared" = yes && enable_static=no
+    fi
+    ;;
+  esac
+  { $as_echo "$as_me:$LINENO: result: $enable_shared" >&5
+$as_echo "$enable_shared" >&6; }
+
+  { $as_echo "$as_me:$LINENO: checking whether to build static libraries" >&5
+$as_echo_n "checking whether to build static libraries... " >&6; }
+  # Make sure either enable_shared or enable_static is yes.
+  test "$enable_shared" = yes || enable_static=yes
+  { $as_echo "$as_me:$LINENO: result: $enable_static" >&5
+$as_echo "$enable_static" >&6; }
+
+
+
+
+fi
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+CC="$lt_save_CC"
+
+
+
+
+
+
+
+
+
+
+
+
+
+        ac_config_commands="$ac_config_commands libtool"
+
+
+
+
+# Only expand once:
+
+
+
+
+# Checks for libraries.
+{ $as_echo "$as_me:$LINENO: checking for pow in -lm" >&5
+$as_echo_n "checking for pow in -lm... " >&6; }
+if test "${ac_cv_lib_m_pow+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lm  $LIBS"
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char pow ();
+int
+main ()
+{
+return pow ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext && {
+	 test "$cross_compiling" = yes ||
+	 $as_test_x conftest$ac_exeext
+       }; then
+  ac_cv_lib_m_pow=yes
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_cv_lib_m_pow=no
+fi
+
+rm -rf conftest.dSYM
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_lib_m_pow" >&5
+$as_echo "$ac_cv_lib_m_pow" >&6; }
+if test "x$ac_cv_lib_m_pow" = x""yes; then
+  LIBS="$LIBS -lm"
+fi
+
+{ $as_echo "$as_me:$LINENO: checking for socket in -lsocket" >&5
+$as_echo_n "checking for socket in -lsocket... " >&6; }
+if test "${ac_cv_lib_socket_socket+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lsocket  $LIBS"
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char socket ();
+int
+main ()
+{
+return socket ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext && {
+	 test "$cross_compiling" = yes ||
+	 $as_test_x conftest$ac_exeext
+       }; then
+  ac_cv_lib_socket_socket=yes
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_cv_lib_socket_socket=no
+fi
+
+rm -rf conftest.dSYM
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_lib_socket_socket" >&5
+$as_echo "$ac_cv_lib_socket_socket" >&6; }
+if test "x$ac_cv_lib_socket_socket" = x""yes; then
+  LIBS="$LIBS -lsocket"
+fi
+
+{ $as_echo "$as_me:$LINENO: checking for inet_ntoa in -lnsl" >&5
+$as_echo_n "checking for inet_ntoa in -lnsl... " >&6; }
+if test "${ac_cv_lib_nsl_inet_ntoa+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lnsl  $LIBS"
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char inet_ntoa ();
+int
+main ()
+{
+return inet_ntoa ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext && {
+	 test "$cross_compiling" = yes ||
+	 $as_test_x conftest$ac_exeext
+       }; then
+  ac_cv_lib_nsl_inet_ntoa=yes
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_cv_lib_nsl_inet_ntoa=no
+fi
+
+rm -rf conftest.dSYM
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_lib_nsl_inet_ntoa" >&5
+$as_echo "$ac_cv_lib_nsl_inet_ntoa" >&6; }
+if test "x$ac_cv_lib_nsl_inet_ntoa" = x""yes; then
+  LIBS="$LIBS -lnsl"
+fi
+
+#LIB_CHECK_FFTW
+
+# Checks for header files.
+{ $as_echo "$as_me:$LINENO: checking for ANSI C header files" >&5
+$as_echo_n "checking for ANSI C header files... " >&6; }
+if test "${ac_cv_header_stdc+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include <float.h>
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  ac_cv_header_stdc=yes
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_cv_header_stdc=no
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
+if test $ac_cv_header_stdc = yes; then
+  # SunOS 4.x string.h does not declare mem*, contrary to ANSI.
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <string.h>
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "memchr" >/dev/null 2>&1; then
+  :
+else
+  ac_cv_header_stdc=no
+fi
+rm -f conftest*
+
+fi
+
+if test $ac_cv_header_stdc = yes; then
+  # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI.
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <stdlib.h>
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "free" >/dev/null 2>&1; then
+  :
+else
+  ac_cv_header_stdc=no
+fi
+rm -f conftest*
+
+fi
+
+if test $ac_cv_header_stdc = yes; then
+  # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi.
+  if test "$cross_compiling" = yes; then
+  :
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <ctype.h>
+#include <stdlib.h>
+#if ((' ' & 0x0FF) == 0x020)
+# define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
+# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c))
+#else
+# define ISLOWER(c) \
+		   (('a' <= (c) && (c) <= 'i') \
+		     || ('j' <= (c) && (c) <= 'r') \
+		     || ('s' <= (c) && (c) <= 'z'))
+# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c))
+#endif
+
+#define XOR(e, f) (((e) && !(f)) || (!(e) && (f)))
+int
+main ()
+{
+  int i;
+  for (i = 0; i < 256; i++)
+    if (XOR (islower (i), ISLOWER (i))
+	|| toupper (i) != TOUPPER (i))
+      return 2;
+  return 0;
+}
+_ACEOF
+rm -f conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_link") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && { ac_try='./conftest$ac_exeext'
+  { (case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_try") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  :
+else
+  $as_echo "$as_me: program exited with status $ac_status" >&5
+$as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+( exit $ac_status )
+ac_cv_header_stdc=no
+fi
+rm -rf conftest.dSYM
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
+fi
+
+
+fi
+fi
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_header_stdc" >&5
+$as_echo "$ac_cv_header_stdc" >&6; }
+if test $ac_cv_header_stdc = yes; then
+
+cat >>confdefs.h <<\_ACEOF
+#define STDC_HEADERS 1
+_ACEOF
+
+fi
+
+
+for ac_header in string.h
+do
+as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
+if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then
+  { $as_echo "$as_me:$LINENO: checking for $ac_header" >&5
+$as_echo_n "checking for $ac_header... " >&6; }
+if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then
+  $as_echo_n "(cached) " >&6
+fi
+ac_res=`eval 'as_val=${'$as_ac_Header'}
+		 $as_echo "$as_val"'`
+	       { $as_echo "$as_me:$LINENO: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+else
+  # Is the header compilable?
+{ $as_echo "$as_me:$LINENO: checking $ac_header usability" >&5
+$as_echo_n "checking $ac_header usability... " >&6; }
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_includes_default
+#include <$ac_header>
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  ac_header_compiler=yes
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_header_compiler=no
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+{ $as_echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
+$as_echo "$ac_header_compiler" >&6; }
+
+# Is the header present?
+{ $as_echo "$as_me:$LINENO: checking $ac_header presence" >&5
+$as_echo_n "checking $ac_header presence... " >&6; }
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <$ac_header>
+_ACEOF
+if { (ac_try="$ac_cpp conftest.$ac_ext"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } >/dev/null && {
+	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       }; then
+  ac_header_preproc=yes
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+  ac_header_preproc=no
+fi
+
+rm -f conftest.err conftest.$ac_ext
+{ $as_echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
+$as_echo "$ac_header_preproc" >&6; }
+
+# So?  What about this header?
+case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
+  yes:no: )
+    { $as_echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5
+$as_echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;}
+    { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5
+$as_echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;}
+    ac_header_preproc=yes
+    ;;
+  no:yes:* )
+    { $as_echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5
+$as_echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;}
+    { $as_echo "$as_me:$LINENO: WARNING: $ac_header:     check for missing prerequisite headers?" >&5
+$as_echo "$as_me: WARNING: $ac_header:     check for missing prerequisite headers?" >&2;}
+    { $as_echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5
+$as_echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;}
+    { $as_echo "$as_me:$LINENO: WARNING: $ac_header:     section \"Present But Cannot Be Compiled\"" >&5
+$as_echo "$as_me: WARNING: $ac_header:     section \"Present But Cannot Be Compiled\"" >&2;}
+    { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5
+$as_echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;}
+    { $as_echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5
+$as_echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;}
+    ( cat <<\_ASBOX
+## ------------------------------- ##
+## Report this to amodigli at eso.org ##
+## ------------------------------- ##
+_ASBOX
+     ) | sed "s/^/$as_me: WARNING:     /" >&2
+    ;;
+esac
+{ $as_echo "$as_me:$LINENO: checking for $ac_header" >&5
+$as_echo_n "checking for $ac_header... " >&6; }
+if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then
+  $as_echo_n "(cached) " >&6
+else
+  eval "$as_ac_Header=\$ac_header_preproc"
+fi
+ac_res=`eval 'as_val=${'$as_ac_Header'}
+		 $as_echo "$as_val"'`
+	       { $as_echo "$as_me:$LINENO: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+
+fi
+as_val=`eval 'as_val=${'$as_ac_Header'}
+		 $as_echo "$as_val"'`
+   if test "x$as_val" = x""yes; then
+  cat >>confdefs.h <<_ACEOF
+#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1
+_ACEOF
+
+fi
+
+done
+
+
+# Checks for typedefs, structures, and compiler characteristics.
+{ $as_echo "$as_me:$LINENO: checking for an ANSI C-conforming const" >&5
+$as_echo_n "checking for an ANSI C-conforming const... " >&6; }
+if test "${ac_cv_c_const+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+int
+main ()
+{
+/* FIXME: Include the comments suggested by Paul. */
+#ifndef __cplusplus
+  /* Ultrix mips cc rejects this.  */
+  typedef int charset[2];
+  const charset cs;
+  /* SunOS 4.1.1 cc rejects this.  */
+  char const *const *pcpcc;
+  char **ppc;
+  /* NEC SVR4.0.2 mips cc rejects this.  */
+  struct point {int x, y;};
+  static struct point const zero = {0,0};
+  /* AIX XL C 1.02.0.0 rejects this.
+     It does not let you subtract one const X* pointer from another in
+     an arm of an if-expression whose if-part is not a constant
+     expression */
+  const char *g = "string";
+  pcpcc = &g + (g ? g-g : 0);
+  /* HPUX 7.0 cc rejects these. */
+  ++pcpcc;
+  ppc = (char**) pcpcc;
+  pcpcc = (char const *const *) ppc;
+  { /* SCO 3.2v4 cc rejects this.  */
+    char *t;
+    char const *s = 0 ? (char *) 0 : (char const *) 0;
+
+    *t++ = 0;
+    if (s) return 0;
+  }
+  { /* Someone thinks the Sun supposedly-ANSI compiler will reject this.  */
+    int x[] = {25, 17};
+    const int *foo = &x[0];
+    ++foo;
+  }
+  { /* Sun SC1.0 ANSI compiler rejects this -- but not the above. */
+    typedef const int *iptr;
+    iptr p = 0;
+    ++p;
+  }
+  { /* AIX XL C 1.02.0.0 rejects this saying
+       "k.c", line 2.27: 1506-025 (S) Operand must be a modifiable lvalue. */
+    struct s { int j; const int *ap[3]; };
+    struct s *b; b->j = 5;
+  }
+  { /* ULTRIX-32 V3.1 (Rev 9) vcc rejects this */
+    const int foo = 10;
+    if (!foo) return 0;
+  }
+  return !cs[0] && !zero.x;
+#endif
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  ac_cv_c_const=yes
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_cv_c_const=no
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_c_const" >&5
+$as_echo "$ac_cv_c_const" >&6; }
+if test $ac_cv_c_const = no; then
+
+cat >>confdefs.h <<\_ACEOF
+#define const /**/
+_ACEOF
+
+fi
+
+{ $as_echo "$as_me:$LINENO: checking for inline" >&5
+$as_echo_n "checking for inline... " >&6; }
+if test "${ac_cv_c_inline+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  ac_cv_c_inline=no
+for ac_kw in inline __inline__ __inline; do
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#ifndef __cplusplus
+typedef int foo_t;
+static $ac_kw foo_t static_foo () {return 0; }
+$ac_kw foo_t foo () {return 0; }
+#endif
+
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  ac_cv_c_inline=$ac_kw
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+  test "$ac_cv_c_inline" != no && break
+done
+
+fi
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_c_inline" >&5
+$as_echo "$ac_cv_c_inline" >&6; }
+
+
+case $ac_cv_c_inline in
+  inline | yes) ;;
+  *)
+    case $ac_cv_c_inline in
+      no) ac_val=;;
+      *) ac_val=$ac_cv_c_inline;;
+    esac
+    cat >>confdefs.h <<_ACEOF
+#ifndef __cplusplus
+#define inline $ac_val
+#endif
+_ACEOF
+    ;;
+esac
+
+
+# Checks for library functions.
+
+
+
+
+
+for ac_func in sin cos floor pow sqrt
+do
+as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
+{ $as_echo "$as_me:$LINENO: checking for $ac_func" >&5
+$as_echo_n "checking for $ac_func... " >&6; }
+if { as_var=$as_ac_var; eval "test \"\${$as_var+set}\" = set"; }; then
+  $as_echo_n "(cached) " >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+/* Define $ac_func to an innocuous variant, in case <limits.h> declares $ac_func.
+   For example, HP-UX 11i <limits.h> declares gettimeofday.  */
+#define $ac_func innocuous_$ac_func
+
+/* System header to define __stub macros and hopefully few prototypes,
+    which can conflict with char $ac_func (); below.
+    Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+    <limits.h> exists even on freestanding compilers.  */
+
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+
+#undef $ac_func
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char $ac_func ();
+/* The GNU C library defines this for functions which it implements
+    to always fail with ENOSYS.  Some functions are actually named
+    something starting with __ and the normal name is an alias.  */
+#if defined __stub_$ac_func || defined __stub___$ac_func
+choke me
+#endif
+
+int
+main ()
+{
+return $ac_func ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext && {
+	 test "$cross_compiling" = yes ||
+	 $as_test_x conftest$ac_exeext
+       }; then
+  eval "$as_ac_var=yes"
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	eval "$as_ac_var=no"
+fi
+
+rm -rf conftest.dSYM
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+fi
+ac_res=`eval 'as_val=${'$as_ac_var'}
+		 $as_echo "$as_val"'`
+	       { $as_echo "$as_me:$LINENO: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+as_val=`eval 'as_val=${'$as_ac_var'}
+		 $as_echo "$as_val"'`
+   if test "x$as_val" = x""yes; then
+  cat >>confdefs.h <<_ACEOF
+#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1
+_ACEOF
+
+fi
+done
+
+
+
+
+
+
+
+
+    ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+    { $as_echo "$as_me:$LINENO: checking whether strdup is declared" >&5
+$as_echo_n "checking whether strdup is declared... " >&6; }
+if test "${ac_cv_have_decl_strdup+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <string.h>
+
+int
+main ()
+{
+#ifndef strdup
+  (void) strdup;
+#endif
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  ac_cv_have_decl_strdup=yes
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_cv_have_decl_strdup=no
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_have_decl_strdup" >&5
+$as_echo "$ac_cv_have_decl_strdup" >&6; }
+
+
+    eso_save_CFLAGS="$CFLAGS"
+
+    if test x"$GCC" = xyes; then
+        CFLAGS="$CFLAGS -pedantic-errors"
+    fi
+
+    { $as_echo "$as_me:$LINENO: checking for strdup" >&5
+$as_echo_n "checking for strdup... " >&6; }
+if test "${ac_cv_func_strdup+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+/* Define strdup to an innocuous variant, in case <limits.h> declares strdup.
+   For example, HP-UX 11i <limits.h> declares gettimeofday.  */
+#define strdup innocuous_strdup
+
+/* System header to define __stub macros and hopefully few prototypes,
+    which can conflict with char strdup (); below.
+    Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+    <limits.h> exists even on freestanding compilers.  */
+
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+
+#undef strdup
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char strdup ();
+/* The GNU C library defines this for functions which it implements
+    to always fail with ENOSYS.  Some functions are actually named
+    something starting with __ and the normal name is an alias.  */
+#if defined __stub_strdup || defined __stub___strdup
+choke me
+#endif
+
+int
+main ()
+{
+return strdup ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext && {
+	 test "$cross_compiling" = yes ||
+	 $as_test_x conftest$ac_exeext
+       }; then
+  ac_cv_func_strdup=yes
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_cv_func_strdup=no
+fi
+
+rm -rf conftest.dSYM
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_func_strdup" >&5
+$as_echo "$ac_cv_func_strdup" >&6; }
+
+
+    CFLAGS="$eso_save_CFLAGS"
+
+    ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+    if test x"$ac_cv_have_decl_strdup" = xyes &&
+       test x"$ac_cv_func_strdup" = xyes; then
+        cat >>confdefs.h <<\_ACEOF
+#define HAVE_STRDUP 1
+_ACEOF
+
+    fi
+
+
+
+
+
+
+
+# Check for CPL/Qfits presence and usability
+
+
+    { $as_echo "$as_me:$LINENO: checking for libcext" >&5
+$as_echo_n "checking for libcext... " >&6; }
+
+    cpl_cext_check_header="cxtypes.h"
+    cpl_cext_check_lib="libcext.a"
+
+    cpl_cext_incdirs=""
+    cpl_cext_libdirs=""
+
+    cpl_cext_includes=""
+    cpl_cext_libraries=""
+
+
+	# Initialize directory search paths with the arguments provided
+
+	if test -n ""; then
+		cpl_cext_incdirs=""
+	fi
+
+	if test -n ""; then
+		cpl_cext_libdirs=""
+	fi
+
+
+
+# Check whether --with-cext was given.
+if test "${with_cext+set}" = set; then
+  withval=$with_cext;
+                    cpl_with_cext=$withval
+
+fi
+
+
+
+# Check whether --with-cext-includes was given.
+if test "${with_cext_includes+set}" = set; then
+  withval=$with_cext_includes; cpl_with_cext_includes=$withval
+fi
+
+
+
+# Check whether --with-cext-libs was given.
+if test "${with_cext_libs+set}" = set; then
+  withval=$with_cext_libs; cpl_with_cext_libs=$withval
+fi
+
+
+    # Check whether --enable-cext-test was given.
+if test "${enable_cext_test+set}" = set; then
+  enableval=$enable_cext_test; cpl_enable_cext_test=$enableval
+else
+  cpl_enable_cext_test=yes
+fi
+
+
+
+    if test "x$cpl_enable_cext_test" = xyes; then
+
+        # Check for the libcext includes
+
+        if test -z "$cpl_with_cext_includes"; then
+
+            if test -z "$cpl_with_cext"; then
+
+            	if test -z "$cpl_cext_incdirs"; then
+
+	                # Try some known system locations
+
+    	            cpl_cext_incdirs="/opt/cext/include"
+        	        cpl_cext_incdirs="$cpl_cext_incdirs /usr/local/include/cext"
+            	    cpl_cext_incdirs="$cpl_cext_incdirs /usr/local/include"
+                	cpl_cext_incdirs="$cpl_cext_incdirs /usr/include/cext"
+                	cpl_cext_incdirs="$cpl_cext_incdirs /usr/include"
+
+                	test -n "$CPLDIR" && \
+                    	cpl_cext_incdirs="$CPLDIR/include/cext \
+                        	              $CPLDIR/include \
+                            	          $cpl_cext_incdirs"
+
+				fi
+
+            else
+
+                cpl_cext_incdirs="$cpl_with_cext/include/cext"
+                cpl_cext_incdirs="$cpl_cext_incdirs $cpl_with_cext/include"
+
+            fi
+
+        else
+            cpl_cext_incdirs="$cpl_with_cext_includes"
+        fi
+
+
+    cpl_cext_includes=no
+
+    for i in $cpl_cext_incdirs; do
+        for j in $cpl_cext_check_header; do
+
+            echo "configure: 13388: $i/$j" >&5
+
+            if test -r "$i/$j"; then
+                echo "taking that" >&5
+                cpl_cext_includes=$i
+                break 2
+            fi
+        done
+    done
+
+
+
+        # Check for the libcext library
+
+        if test -z "$cpl_with_cext_libs"; then
+
+            if test -z "$cpl_with_cext"; then
+
+            	if test -z "$cpl_cext_libdirs"; then
+
+	                # Try some known system locations
+
+    	            cpl_cext_libdirs="/opt/cext/lib"
+                	cpl_cext_libdirs="$cpl_cext_libdirs /usr/local/lib64"
+                	cpl_cext_libdirs="$cpl_cext_libdirs /usr/local/lib"
+                	cpl_cext_libdirs="$cpl_cext_libdirs /usr/local/lib32"
+                	cpl_cext_libdirs="$cpl_cext_libdirs /usr/lib64"
+                	cpl_cext_libdirs="$cpl_cext_libdirs /usr/lib"
+                	cpl_cext_libdirs="$cpl_cext_libdirs /usr/lib32"
+
+                	test -n "$CPLDIR" && \
+                    	cpl_cext_libdirs="$CPLDIR/lib64 \
+                    					  $CPLDIR/lib \
+                    					  $CPLDIR/lib32 \
+                                          $cpl_cext_libdirs"
+
+				fi
+
+            else
+
+                cpl_cext_libdirs="$cpl_with_cext/lib64"
+                cpl_cext_libdirs="$cpl_cext_libdirs $cpl_with_cext/lib"
+                cpl_cext_libdirs="$cpl_cext_libdirs $cpl_with_cext/lib32"
+
+            fi
+
+        else
+            cpl_cext_libdirs="$cpl_with_cext_libs"
+        fi
+
+
+    cpl_cext_libraries=no
+
+    for i in $cpl_cext_libdirs; do
+        for j in $cpl_cext_check_lib; do
+
+            echo "configure: 13444: $i/$j" >&5
+
+            if test -r "$i/$j"; then
+                echo "taking that" >&5
+                cpl_cext_libraries=$i
+                break 2
+            fi
+        done
+    done
+
+
+
+        if test x"$cpl_cext_includes" = xno || \
+            test x"$cpl_cext_libraries" = xno; then
+            cpl_cext_notfound=""
+
+            if test x"$cpl_cext_includes" = xno; then
+                if test x"$cpl_cext_libraries" = xno; then
+                    cpl_cext_notfound="(headers and libraries)"
+                else
+                    cpl_cext_notfound="(headers)"
+                fi
+            else
+                cpl_cext_notfound="(libraries)"
+            fi
+
+            { { $as_echo "$as_me:$LINENO: error: libcext $cpl_cext_notfound was not found on your system. Please check!" >&5
+$as_echo "$as_me: error: libcext $cpl_cext_notfound was not found on your system. Please check!" >&2;}
+   { (exit 1); exit 1; }; }
+        else
+            { $as_echo "$as_me:$LINENO: result: libraries $cpl_cext_libraries, headers $cpl_cext_includes" >&5
+$as_echo "libraries $cpl_cext_libraries, headers $cpl_cext_includes" >&6; }
+        fi
+
+
+        # Set up the symbols
+
+        CX_INCLUDES="-I$cpl_cext_includes"
+        CX_LDFLAGS="-L$cpl_cext_libraries"
+        LIBCEXT="-lcext"
+
+
+        { $as_echo "$as_me:$LINENO: checking whether libcext can be used" >&5
+$as_echo_n "checking whether libcext can be used... " >&6; }
+        ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+        cpl_cext_cflags_save="$CFLAGS"
+        cpl_cext_ldflags_save="$LDFLAGS"
+        cpl_cext_libs_save="$LIBS"
+
+        CFLAGS="$CX_INCLUDES $CFLAGS"
+        LDFLAGS="$CX_LDFLAGS $LDFLAGS"
+        LIBS="$LIBCEXT"
+
+        cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+                       #include <cxutils.h>
+
+int
+main ()
+{
+
+                       cx_program_set_name("MyProgram");
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext && {
+	 test "$cross_compiling" = yes ||
+	 $as_test_x conftest$ac_exeext
+       }; then
+  cpl_cext_is_usable="yes"
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	cpl_cext_is_usable="no"
+fi
+
+rm -rf conftest.dSYM
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+
+        { $as_echo "$as_me:$LINENO: result: $cpl_cext_is_usable" >&5
+$as_echo "$cpl_cext_is_usable" >&6; }
+
+        ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+        CFLAGS="$cpl_cext_cflags_save"
+        LDFLAGS="$cpl_cext_ldflags_save"
+        LIBS="$cpl_cext_libs_save"
+
+        if test x"$cpl_cext_is_usable" = xno; then
+            { { $as_echo "$as_me:$LINENO: error: Linking with libcext failed! Please check architecture!" >&5
+$as_echo "$as_me: error: Linking with libcext failed! Please check architecture!" >&2;}
+   { (exit 1); exit 1; }; }
+        fi
+
+    else
+
+        { $as_echo "$as_me:$LINENO: result: disabled" >&5
+$as_echo "disabled" >&6; }
+        { $as_echo "$as_me:$LINENO: WARNING: libcext checks have been disabled! This package may not build!" >&5
+$as_echo "$as_me: WARNING: libcext checks have been disabled! This package may not build!" >&2;}
+        CX_INCLUDES=""
+        CX_LDFLAGS=""
+        LIBCEXT=""
+
+    fi
+
+
+
+
+
+
+
+
+    { $as_echo "$as_me:$LINENO: checking for CPL" >&5
+$as_echo_n "checking for CPL... " >&6; }
+
+    cpl_check_cpl_header="cpl.h"
+    cpl_check_cpl_lib="libcplcore.a"
+
+    cpl_incdirs=""
+    cpl_libdirs=""
+    cpl_includes=""
+    cpl_libraries=""
+
+
+# Check whether --with-cpl was given.
+if test "${with_cpl+set}" = set; then
+  withval=$with_cpl;
+                    cpl_with_cpl=$withval
+
+fi
+
+
+
+# Check whether --with-cpl-includes was given.
+if test "${with_cpl_includes+set}" = set; then
+  withval=$with_cpl_includes; cpl_with_cpl_includes=$withval
+fi
+
+
+
+# Check whether --with-cpl-libs was given.
+if test "${with_cpl_libs+set}" = set; then
+  withval=$with_cpl_libs; cpl_with_cpl_libs=$withval
+fi
+
+
+    # Check whether --enable-cpl-test was given.
+if test "${enable_cpl_test+set}" = set; then
+  enableval=$enable_cpl_test; cpl_enable_cpl_test=$enableval
+else
+  cpl_enable_cpl_test=yes
+fi
+
+
+
+    if test "x$cpl_enable_cpl_test" = xyes; then
+
+        # Check for the CPL includes
+
+        if test -z "$cpl_with_cpl_includes"; then
+
+            if test -z "$cpl_with_cpl"; then
+
+                # Try some known system locations
+
+                cpl_incdirs="/opt/cpl/include"
+                cpl_incdirs="$cpl_incdirs /usr/local/include"
+                cpl_incdirs="$cpl_incdirs /usr/include"
+
+                test -n "$CPLDIR" && \
+                    cpl_incdirs="$CPLDIR/include \
+                                 $cpl_incdirs"
+
+            else
+
+                cpl_incdirs="$cpl_with_cpl/include"
+
+            fi
+
+        else
+            cpl_incdirs="$cpl_with_cpl_includes"
+        fi
+
+
+    cpl_includes=no
+
+    for i in $cpl_incdirs; do
+        for j in $cpl_check_cpl_header; do
+
+            echo "configure: 13671: $i/$j" >&5
+
+            if test -r "$i/$j"; then
+                echo "taking that" >&5
+                cpl_includes=$i
+                break 2
+            fi
+        done
+    done
+
+
+
+        # Check for the CPL libraries
+
+        if test -z "$cpl_with_cpl_libs"; then
+
+            if test -z "$cpl_with_cpl"; then
+
+                # Try some known system locations
+
+                cpl_libdirs="/opt/cpl/lib"
+                cpl_libdirs="$cpl_libdirs /usr/local/lib64"
+                cpl_libdirs="$cpl_libdirs /usr/local/lib"
+                cpl_libdirs="$cpl_libdirs /usr/local/lib32"
+                cpl_libdirs="$cpl_libdirs /usr/lib64"
+                cpl_libdirs="$cpl_libdirs /usr/lib"
+                cpl_libdirs="$cpl_libdirs /usr/lib32"
+
+                test -n "$CPLDIR" && \
+                    cpl_libdirs="$CPLDIR/lib64 $CPLDIR/lib $CPLDIR/lib32 \
+                                 $cpl_libdirs"
+
+            else
+
+                cpl_libdirs="$cpl_with_cpl/lib64"
+                cpl_libdirs="$cpl_libdirs $cpl_with_cpl/lib"
+                cpl_libdirs="$cpl_libdirs $cpl_with_cpl/lib32"
+
+            fi
+
+        else
+            cpl_libdirs="$cpl_with_cpl_libs"
+        fi
+
+
+    cpl_libraries=no
+
+    for i in $cpl_libdirs; do
+        for j in $cpl_check_cpl_lib; do
+
+            echo "configure: 13721: $i/$j" >&5
+
+            if test -r "$i/$j"; then
+                echo "taking that" >&5
+                cpl_libraries=$i
+                break 2
+            fi
+        done
+    done
+
+
+
+        if test x"$cpl_includes" = xno || test x"$cpl_libraries" = xno; then
+            cpl_notfound=""
+
+            if test x"$cpl_includes" = xno; then
+                if test x"$cpl_libraries" = xno; then
+                    cpl_notfound="(headers and libraries)"
+                else
+                    cpl_notfound="(headers)"
+                fi
+            else
+                cpl_notfound="(libraries)"
+            fi
+
+            { { $as_echo "$as_me:$LINENO: error: CPL $cpl_notfound was not found on your system. Please check!" >&5
+$as_echo "$as_me: error: CPL $cpl_notfound was not found on your system. Please check!" >&2;}
+   { (exit 1); exit 1; }; }
+        else
+            { $as_echo "$as_me:$LINENO: result: libraries $cpl_libraries, headers $cpl_includes" >&5
+$as_echo "libraries $cpl_libraries, headers $cpl_includes" >&6; }
+        fi
+
+    	# The libcext headers are required. By default it part of the
+    	# CPL installation and it is assumed that the cext headers are
+    	# present in the same location as the CPL headers
+
+
+
+    { $as_echo "$as_me:$LINENO: checking for libcext" >&5
+$as_echo_n "checking for libcext... " >&6; }
+
+    cpl_cext_check_header="cxtypes.h"
+    cpl_cext_check_lib="libcext.a"
+
+    cpl_cext_incdirs=""
+    cpl_cext_libdirs=""
+
+    cpl_cext_includes=""
+    cpl_cext_libraries=""
+
+
+	# Initialize directory search paths with the arguments provided
+
+	if test -n "$cpl_includes"; then
+		cpl_cext_incdirs="$cpl_includes"
+	fi
+
+	if test -n "$cpl_libraries"; then
+		cpl_cext_libdirs="$cpl_libraries"
+	fi
+
+
+
+# Check whether --with-cext was given.
+if test "${with_cext+set}" = set; then
+  withval=$with_cext;
+                    cpl_with_cext=$withval
+
+fi
+
+
+
+# Check whether --with-cext-includes was given.
+if test "${with_cext_includes+set}" = set; then
+  withval=$with_cext_includes; cpl_with_cext_includes=$withval
+fi
+
+
+
+# Check whether --with-cext-libs was given.
+if test "${with_cext_libs+set}" = set; then
+  withval=$with_cext_libs; cpl_with_cext_libs=$withval
+fi
+
+
+    # Check whether --enable-cext-test was given.
+if test "${enable_cext_test+set}" = set; then
+  enableval=$enable_cext_test; cpl_enable_cext_test=$enableval
+else
+  cpl_enable_cext_test=yes
+fi
+
+
+
+    if test "x$cpl_enable_cext_test" = xyes; then
+
+        # Check for the libcext includes
+
+        if test -z "$cpl_with_cext_includes"; then
+
+            if test -z "$cpl_with_cext"; then
+
+            	if test -z "$cpl_cext_incdirs"; then
+
+	                # Try some known system locations
+
+    	            cpl_cext_incdirs="/opt/cext/include"
+        	        cpl_cext_incdirs="$cpl_cext_incdirs /usr/local/include/cext"
+            	    cpl_cext_incdirs="$cpl_cext_incdirs /usr/local/include"
+                	cpl_cext_incdirs="$cpl_cext_incdirs /usr/include/cext"
+                	cpl_cext_incdirs="$cpl_cext_incdirs /usr/include"
+
+                	test -n "$CPLDIR" && \
+                    	cpl_cext_incdirs="$CPLDIR/include/cext \
+                        	              $CPLDIR/include \
+                            	          $cpl_cext_incdirs"
+
+				fi
+
+            else
+
+                cpl_cext_incdirs="$cpl_with_cext/include/cext"
+                cpl_cext_incdirs="$cpl_cext_incdirs $cpl_with_cext/include"
+
+            fi
+
+        else
+            cpl_cext_incdirs="$cpl_with_cext_includes"
+        fi
+
+
+    cpl_cext_includes=no
+
+    for i in $cpl_cext_incdirs; do
+        for j in $cpl_cext_check_header; do
+
+            echo "configure: 13858: $i/$j" >&5
+
+            if test -r "$i/$j"; then
+                echo "taking that" >&5
+                cpl_cext_includes=$i
+                break 2
+            fi
+        done
+    done
+
+
+
+        # Check for the libcext library
+
+        if test -z "$cpl_with_cext_libs"; then
+
+            if test -z "$cpl_with_cext"; then
+
+            	if test -z "$cpl_cext_libdirs"; then
+
+	                # Try some known system locations
+
+    	            cpl_cext_libdirs="/opt/cext/lib"
+                	cpl_cext_libdirs="$cpl_cext_libdirs /usr/local/lib64"
+                	cpl_cext_libdirs="$cpl_cext_libdirs /usr/local/lib"
+                	cpl_cext_libdirs="$cpl_cext_libdirs /usr/local/lib32"
+                	cpl_cext_libdirs="$cpl_cext_libdirs /usr/lib64"
+                	cpl_cext_libdirs="$cpl_cext_libdirs /usr/lib"
+                	cpl_cext_libdirs="$cpl_cext_libdirs /usr/lib32"
+
+                	test -n "$CPLDIR" && \
+                    	cpl_cext_libdirs="$CPLDIR/lib64 \
+                    					  $CPLDIR/lib \
+                    					  $CPLDIR/lib32 \
+                                          $cpl_cext_libdirs"
+
+				fi
+
+            else
+
+                cpl_cext_libdirs="$cpl_with_cext/lib64"
+                cpl_cext_libdirs="$cpl_cext_libdirs $cpl_with_cext/lib"
+                cpl_cext_libdirs="$cpl_cext_libdirs $cpl_with_cext/lib32"
+
+            fi
+
+        else
+            cpl_cext_libdirs="$cpl_with_cext_libs"
+        fi
+
+
+    cpl_cext_libraries=no
+
+    for i in $cpl_cext_libdirs; do
+        for j in $cpl_cext_check_lib; do
+
+            echo "configure: 13914: $i/$j" >&5
+
+            if test -r "$i/$j"; then
+                echo "taking that" >&5
+                cpl_cext_libraries=$i
+                break 2
+            fi
+        done
+    done
+
+
+
+        if test x"$cpl_cext_includes" = xno || \
+            test x"$cpl_cext_libraries" = xno; then
+            cpl_cext_notfound=""
+
+            if test x"$cpl_cext_includes" = xno; then
+                if test x"$cpl_cext_libraries" = xno; then
+                    cpl_cext_notfound="(headers and libraries)"
+                else
+                    cpl_cext_notfound="(headers)"
+                fi
+            else
+                cpl_cext_notfound="(libraries)"
+            fi
+
+            { { $as_echo "$as_me:$LINENO: error: libcext $cpl_cext_notfound was not found on your system. Please check!" >&5
+$as_echo "$as_me: error: libcext $cpl_cext_notfound was not found on your system. Please check!" >&2;}
+   { (exit 1); exit 1; }; }
+        else
+            { $as_echo "$as_me:$LINENO: result: libraries $cpl_cext_libraries, headers $cpl_cext_includes" >&5
+$as_echo "libraries $cpl_cext_libraries, headers $cpl_cext_includes" >&6; }
+        fi
+
+
+        # Set up the symbols
+
+        CX_INCLUDES="-I$cpl_cext_includes"
+        CX_LDFLAGS="-L$cpl_cext_libraries"
+        LIBCEXT="-lcext"
+
+
+        { $as_echo "$as_me:$LINENO: checking whether libcext can be used" >&5
+$as_echo_n "checking whether libcext can be used... " >&6; }
+        ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+        cpl_cext_cflags_save="$CFLAGS"
+        cpl_cext_ldflags_save="$LDFLAGS"
+        cpl_cext_libs_save="$LIBS"
+
+        CFLAGS="$CX_INCLUDES $CFLAGS"
+        LDFLAGS="$CX_LDFLAGS $LDFLAGS"
+        LIBS="$LIBCEXT"
+
+        cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+                       #include <cxutils.h>
+
+int
+main ()
+{
+
+                       cx_program_set_name("MyProgram");
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext && {
+	 test "$cross_compiling" = yes ||
+	 $as_test_x conftest$ac_exeext
+       }; then
+  cpl_cext_is_usable="yes"
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	cpl_cext_is_usable="no"
+fi
+
+rm -rf conftest.dSYM
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+
+        { $as_echo "$as_me:$LINENO: result: $cpl_cext_is_usable" >&5
+$as_echo "$cpl_cext_is_usable" >&6; }
+
+        ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+        CFLAGS="$cpl_cext_cflags_save"
+        LDFLAGS="$cpl_cext_ldflags_save"
+        LIBS="$cpl_cext_libs_save"
+
+        if test x"$cpl_cext_is_usable" = xno; then
+            { { $as_echo "$as_me:$LINENO: error: Linking with libcext failed! Please check architecture!" >&5
+$as_echo "$as_me: error: Linking with libcext failed! Please check architecture!" >&2;}
+   { (exit 1); exit 1; }; }
+        fi
+
+    else
+
+        { $as_echo "$as_me:$LINENO: result: disabled" >&5
+$as_echo "disabled" >&6; }
+        { $as_echo "$as_me:$LINENO: WARNING: libcext checks have been disabled! This package may not build!" >&5
+$as_echo "$as_me: WARNING: libcext checks have been disabled! This package may not build!" >&2;}
+        CX_INCLUDES=""
+        CX_LDFLAGS=""
+        LIBCEXT=""
+
+    fi
+
+
+
+
+
+
+
+
+        # Set up the symbols
+
+        CPL_INCLUDES="-I$cpl_includes $CX_INCLUDES $CFITSIO_INCLUDES"
+        CPL_LDFLAGS="-L$cpl_libraries $CX_LDFLAGS $CFITSIO_LDFLAGS"
+
+
+    if test -z ""; then
+        LIBCPLCORE='-lcplcore'
+        LIBCPLDRS='-lcpldrs'
+        LIBCPLUI='-lcplui'
+        LIBCPLDFS='-lcpldfs'
+    else
+        LIBCPLCORE='$(top_builddir)/cplcore/libcplcore.la'
+        LIBCPLDRS='$(top_builddir)/cpldrs/libcpldrs.la'
+        LIBCPLUI='$(top_builddir)/cplui/libcplui.la'
+        LIBCPLDFS='$(top_builddir)/cpldfs/libcpldfs.la'
+    fi
+
+
+
+
+
+
+
+
+
+        { $as_echo "$as_me:$LINENO: checking whether CPL can be used" >&5
+$as_echo_n "checking whether CPL can be used... " >&6; }
+        ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+        cpl_cflags_save="$CFLAGS"
+        cpl_ldflags_save="$LDFLAGS"
+        cpl_libs_save="$LIBS"
+
+        CFLAGS="$CPL_INCLUDES $CFLAGS"
+        LDFLAGS="$CPL_LDFLAGS $LDFLAGS"
+        LIBS="$LIBCPLCORE $LIBCEXT $LIBS"
+
+        cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+                       #include <cpl.h>
+
+int
+main ()
+{
+
+                       cpl_init(CPL_INIT_DEFAULT);
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext && {
+	 test "$cross_compiling" = yes ||
+	 $as_test_x conftest$ac_exeext
+       }; then
+  cpl_is_usable="yes"
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	cpl_is_usable="no"
+fi
+
+rm -rf conftest.dSYM
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+
+        { $as_echo "$as_me:$LINENO: result: $cpl_is_usable" >&5
+$as_echo "$cpl_is_usable" >&6; }
+
+        ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+        CFLAGS="$cpl_cflags_save"
+        LDFLAGS="$cpl_ldflags_save"
+        LIBS="$cpl_libs_save"
+
+        if test x"$cpl_is_usable" = xno; then
+            { { $as_echo "$as_me:$LINENO: error: Linking with CPL failed! Please check architecture!" >&5
+$as_echo "$as_me: error: Linking with CPL failed! Please check architecture!" >&2;}
+   { (exit 1); exit 1; }; }
+        fi
+
+    else
+
+        { $as_echo "$as_me:$LINENO: result: disabled" >&5
+$as_echo "disabled" >&6; }
+        { $as_echo "$as_me:$LINENO: WARNING: CPL checks have been disabled! This package may not build!" >&5
+$as_echo "$as_me: WARNING: CPL checks have been disabled! This package may not build!" >&2;}
+        CPL_INCLUDES=""
+        CPL_LDFLAGS=""
+        LIBCPLCORE=""
+        LIBCPLDRS=""
+        LIBCPLUI=""
+        LIBCPLDFS=""
+
+    fi
+
+
+
+
+
+
+
+
+
+
+# Check for Purify
+
+
+    { $as_echo "$as_me:$LINENO: checking for PURIFY availability" >&5
+$as_echo_n "checking for PURIFY availability... " >&6; }
+
+    # Check whether --enable-purify was given.
+if test "${enable_purify+set}" = set; then
+  enableval=$enable_purify; enable_purify=$enableval
+else
+  enable_purify=yes
+fi
+
+
+    if test "x$enable_purify" = xyes ; then
+      # Extract the first word of "purify", so it can be a program name with args.
+set dummy purify; ac_word=$2
+{ $as_echo "$as_me:$LINENO: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_PURIFY_CMD+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$PURIFY_CMD"; then
+  ac_cv_prog_PURIFY_CMD="$PURIFY_CMD" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_PURIFY_CMD="purify"
+    $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+IFS=$as_save_IFS
+
+  test -z "$ac_cv_prog_PURIFY_CMD" && ac_cv_prog_PURIFY_CMD="NONE"
+fi
+fi
+PURIFY_CMD=$ac_cv_prog_PURIFY_CMD
+if test -n "$PURIFY_CMD"; then
+  { $as_echo "$as_me:$LINENO: result: $PURIFY_CMD" >&5
+$as_echo "$PURIFY_CMD" >&6; }
+else
+  { $as_echo "$as_me:$LINENO: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+      if test "$PURIFY_CMD" = "NONE" ; then
+        { $as_echo "$as_me:$LINENO: result: disabled" >&5
+$as_echo "disabled" >&6; }
+        enable_purify=no
+      else
+        { $as_echo "$as_me:$LINENO: result: enabled" >&5
+$as_echo "enabled" >&6; }
+      fi
+    else
+      { $as_echo "$as_me:$LINENO: result: disabled" >&5
+$as_echo "disabled" >&6; }
+    fi
+
+     if test "x$enable_purify" = "xyes"; then
+  PURIFY_TRUE=
+  PURIFY_FALSE='#'
+else
+  PURIFY_TRUE='#'
+  PURIFY_FALSE=
+fi
+
+
+
+
+
+    # Check whether --enable-profile was given.
+if test "${enable_profile+set}" = set; then
+  enableval=$enable_profile; eso_enable_profile=$enableval
+else
+  eso_enable_profile=no
+fi
+
+
+    { $as_echo "$as_me:$LINENO: checking whether profiling compiler options should be used" >&5
+$as_echo_n "checking whether profiling compiler options should be used... " >&6; }
+if test "${eso_cv_enable_profile+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  eso_cv_enable_profile=$eso_enable_profile
+fi
+{ $as_echo "$as_me:$LINENO: result: $eso_cv_enable_profile" >&5
+$as_echo "$eso_cv_enable_profile" >&6; }
+
+
+    if test x"$eso_cv_enable_profile" = xyes; then
+
+
+
+    flag=`echo pg | sed 'y%.=/+-%___p_%'`
+    { $as_echo "$as_me:$LINENO: checking whether $CC supports -pg" >&5
+$as_echo_n "checking whether $CC supports -pg... " >&6; }
+if { as_var=eso_cv_prog_cc_$flag; eval "test \"\${$as_var+set}\" = set"; }; then
+  $as_echo_n "(cached) " >&6
+else
+
+                       eval "eso_cv_prog_cc_$flag=no"
+                       ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+                       echo 'int main() { return 0; }' >conftest.$ac_ext
+
+                       try_compile="`$CC -pg -c conftest.$ac_ext 2>&1`"
+                       if test -z "$try_compile"; then
+                           try_link="`$CC -pg -o conftest$ac_exeext \
+                                    conftest.$ac_ext 2>&1`"
+                           if test -z "$try_link"; then
+                               eval "eso_cv_prog_cc_$flag=yes"
+                           fi
+                       fi
+                       rm -f conftest*
+
+                       ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+fi
+ac_res=`eval 'as_val=${'eso_cv_prog_cc_$flag'}
+		 $as_echo "$as_val"'`
+	       { $as_echo "$as_me:$LINENO: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+
+    if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then
+        :
+        CFLAGS="$CFLAGS -pg"
+    else
+        :
+
+    fi
+
+
+
+
+    flag=`echo g | sed 'y%.=/+-%___p_%'`
+    { $as_echo "$as_me:$LINENO: checking whether $CC supports -g" >&5
+$as_echo_n "checking whether $CC supports -g... " >&6; }
+if { as_var=eso_cv_prog_cc_$flag; eval "test \"\${$as_var+set}\" = set"; }; then
+  $as_echo_n "(cached) " >&6
+else
+
+                       eval "eso_cv_prog_cc_$flag=no"
+                       ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+                       echo 'int main() { return 0; }' >conftest.$ac_ext
+
+                       try_compile="`$CC -g -c conftest.$ac_ext 2>&1`"
+                       if test -z "$try_compile"; then
+                           try_link="`$CC -g -o conftest$ac_exeext \
+                                    conftest.$ac_ext 2>&1`"
+                           if test -z "$try_link"; then
+                               eval "eso_cv_prog_cc_$flag=yes"
+                           fi
+                       fi
+                       rm -f conftest*
+
+                       ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+fi
+ac_res=`eval 'as_val=${'eso_cv_prog_cc_$flag'}
+		 $as_echo "$as_val"'`
+	       { $as_echo "$as_me:$LINENO: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+
+    if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then
+        :
+        CFLAGS="$CFLAGS -g"
+    else
+        :
+
+    fi
+
+
+
+
+    flag=`echo static-libgcc | sed 'y%.=/+-%___p_%'`
+    { $as_echo "$as_me:$LINENO: checking whether $CC supports -static-libgcc" >&5
+$as_echo_n "checking whether $CC supports -static-libgcc... " >&6; }
+if { as_var=eso_cv_prog_cc_$flag; eval "test \"\${$as_var+set}\" = set"; }; then
+  $as_echo_n "(cached) " >&6
+else
+
+                       eval "eso_cv_prog_cc_$flag=no"
+                       ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+                       echo 'int main() { return 0; }' >conftest.$ac_ext
+
+                       try_compile="`$CC -static-libgcc -c conftest.$ac_ext 2>&1`"
+                       if test -z "$try_compile"; then
+                           try_link="`$CC -static-libgcc -o conftest$ac_exeext \
+                                    conftest.$ac_ext 2>&1`"
+                           if test -z "$try_link"; then
+                               eval "eso_cv_prog_cc_$flag=yes"
+                           fi
+                       fi
+                       rm -f conftest*
+
+                       ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+fi
+ac_res=`eval 'as_val=${'eso_cv_prog_cc_$flag'}
+		 $as_echo "$as_val"'`
+	       { $as_echo "$as_me:$LINENO: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+
+    if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then
+        :
+        CFLAGS="$CFLAGS -static-libgcc"
+    else
+        :
+
+    fi
+
+
+        # Check whether --enable-shared was given.
+if test "${enable_shared+set}" = set; then
+  enableval=$enable_shared; p=${PACKAGE-default}
+    case $enableval in
+    yes) enable_shared=yes ;;
+    no) enable_shared=no ;;
+    *)
+      enable_shared=no
+      # Look at the argument we got.  We use all the common list separators.
+      lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR,"
+      for pkg in $enableval; do
+	IFS="$lt_save_ifs"
+	if test "X$pkg" = "X$p"; then
+	  enable_shared=yes
+	fi
+      done
+      IFS="$lt_save_ifs"
+      ;;
+    esac
+else
+  enable_shared=no
+fi
+
+
+
+
+
+
+        # Check whether --enable-static was given.
+if test "${enable_static+set}" = set; then
+  enableval=$enable_static; p=${PACKAGE-default}
+    case $enableval in
+    yes) enable_static=yes ;;
+    no) enable_static=no ;;
+    *)
+     enable_static=no
+      # Look at the argument we got.  We use all the common list separators.
+      lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR,"
+      for pkg in $enableval; do
+	IFS="$lt_save_ifs"
+	if test "X$pkg" = "X$p"; then
+	  enable_static=yes
+	fi
+      done
+      IFS="$lt_save_ifs"
+      ;;
+    esac
+else
+  enable_static=yes
+fi
+
+
+
+
+
+
+    fi
+
+
+# Check for a function which exists only in CPL 3.1 or later
+LDFLAGS="$LDFLAGS $CPL_LDFLAGS"
+{ $as_echo "$as_me:$LINENO: checking for cpl_image_get_bpm in -lcplcore" >&5
+$as_echo_n "checking for cpl_image_get_bpm in -lcplcore... " >&6; }
+if test "${ac_cv_lib_cplcore_cpl_image_get_bpm+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lcplcore  $LIBS"
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char cpl_image_get_bpm ();
+int
+main ()
+{
+return cpl_image_get_bpm ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext && {
+	 test "$cross_compiling" = yes ||
+	 $as_test_x conftest$ac_exeext
+       }; then
+  ac_cv_lib_cplcore_cpl_image_get_bpm=yes
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_cv_lib_cplcore_cpl_image_get_bpm=no
+fi
+
+rm -rf conftest.dSYM
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_lib_cplcore_cpl_image_get_bpm" >&5
+$as_echo "$ac_cv_lib_cplcore_cpl_image_get_bpm" >&6; }
+if test "x$ac_cv_lib_cplcore_cpl_image_get_bpm" = x""yes; then
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_CPL31 1
+_ACEOF
+
+else
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_CPL31 0
+_ACEOF
+
+fi
+
+
+
+# Check for __func__, popen(), pclose()
+{ $as_echo "$as_me:$LINENO: checking whether __func__ is declared" >&5
+$as_echo_n "checking whether __func__ is declared... " >&6; }
+if test "${ac_cv_have_decl___func__+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_includes_default
+int
+main ()
+{
+#ifndef __func__
+  (void) __func__;
+#endif
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  ac_cv_have_decl___func__=yes
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_cv_have_decl___func__=no
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_have_decl___func__" >&5
+$as_echo "$ac_cv_have_decl___func__" >&6; }
+if test "x$ac_cv_have_decl___func__" = x""yes; then
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_DECL___FUNC__ 1
+_ACEOF
+
+
+else
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_DECL___FUNC__ 0
+_ACEOF
+
+
+fi
+{ $as_echo "$as_me:$LINENO: checking whether popen is declared" >&5
+$as_echo_n "checking whether popen is declared... " >&6; }
+if test "${ac_cv_have_decl_popen+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_includes_default
+int
+main ()
+{
+#ifndef popen
+  (void) popen;
+#endif
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  ac_cv_have_decl_popen=yes
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_cv_have_decl_popen=no
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_have_decl_popen" >&5
+$as_echo "$ac_cv_have_decl_popen" >&6; }
+if test "x$ac_cv_have_decl_popen" = x""yes; then
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_DECL_POPEN 1
+_ACEOF
+
+
+else
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_DECL_POPEN 0
+_ACEOF
+
+
+fi
+{ $as_echo "$as_me:$LINENO: checking whether pclose is declared" >&5
+$as_echo_n "checking whether pclose is declared... " >&6; }
+if test "${ac_cv_have_decl_pclose+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_includes_default
+int
+main ()
+{
+#ifndef pclose
+  (void) pclose;
+#endif
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  ac_cv_have_decl_pclose=yes
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_cv_have_decl_pclose=no
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_have_decl_pclose" >&5
+$as_echo "$ac_cv_have_decl_pclose" >&6; }
+if test "x$ac_cv_have_decl_pclose" = x""yes; then
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_DECL_PCLOSE 1
+_ACEOF
+
+
+else
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_DECL_PCLOSE 0
+_ACEOF
+
+
+fi
+
+
+
+
+
+    if test -z "$plugindir"; then
+        plugindir='${libdir}/esopipes-plugins/${PACKAGE}-${VERSION}'
+    fi
+
+    if test -z "$privatelibdir"; then
+        privatelibdir='${libdir}/${PACKAGE}-${VERSION}'
+    fi
+
+    if test -z "$pipedocsdir"; then
+        pipedocsdir='${datadir}/doc/esopipes/${PACKAGE}-${VERSION}'
+    fi
+
+    htmldir='${pipedocsdir}/html'
+
+    if test -z "$confdir"; then
+       configdir='${datadir}/${PACKAGE}/config'
+    fi
+
+
+
+
+
+
+
+
+
+
+    # Define a preprocesor symbol for the plugin search paths
+
+
+cat >>confdefs.h <<_ACEOF
+#define SINFONI_PLUGIN_DIR "esopipes-plugins"
+_ACEOF
+
+
+    eval plugin_dir="$plugindir"
+    plugin_path=`eval echo $plugin_dir | \
+                sed -e "s/\/${PACKAGE}-${VERSION}.*$//"`
+
+
+cat >>confdefs.h <<_ACEOF
+#define SINFONI_PLUGIN_PATH "$plugin_path"
+_ACEOF
+
+
+
+
+
+
+# Check whether --with-extra-includes was given.
+if test "${with_extra_includes+set}" = set; then
+  withval=$with_extra_includes; eso_with_extra_includes=$withval
+else
+  eso_with_extra_includes=NONE
+fi
+
+
+
+# Check whether --with-extra-libs was given.
+if test "${with_extra_libs+set}" = set; then
+  withval=$with_extra_libs; eso_with_extra_libs=$withval
+else
+  eso_with_extra_libs=NONE
+fi
+
+
+    { $as_echo "$as_me:$LINENO: checking for extra includes" >&5
+$as_echo_n "checking for extra includes... " >&6; }
+    if test "${eso_cv_with_extra_includes+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+
+                     eso_cv_with_extra_includes=$eso_with_extra_includes
+
+fi
+
+
+    if test x"$eso_cv_with_extra_includes" != xNONE; then
+        eso_save_IFS=$IFS
+        IFS=':'
+
+        for dir in $eso_cv_with_extra_includes; do
+            EXTRA_INCLUDES="$EXTRA_INCLUDES -I$dir"
+        done
+
+        IFS=$eso_save_IFS
+        { $as_echo "$as_me:$LINENO: result: added" >&5
+$as_echo "added" >&6; }
+    else
+        { $as_echo "$as_me:$LINENO: result: no" >&5
+$as_echo "no" >&6; }
+    fi
+
+
+    { $as_echo "$as_me:$LINENO: checking for extra libs" >&5
+$as_echo_n "checking for extra libs... " >&6; }
+    if test "${eso_cv_with_extra_libs+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+
+                     eso_cv_with_extra_libs=$eso_with_extra_libs
+
+fi
+
+
+    if test x"$eso_cv_with_extra_libs" != xNONE; then
+        eso_save_IFS=$IFS
+        IFS=':'
+
+        for dir in $eso_cv_with_extra_libs; do
+            EXTRA_LDFLAGS="$EXTRA_LDFLAGS -L$dir"
+        done
+
+        IFS=$eso_save_IFS
+        { $as_echo "$as_me:$LINENO: result: added" >&5
+$as_echo "added" >&6; }
+    else
+        { $as_echo "$as_me:$LINENO: result: no" >&5
+$as_echo "no" >&6; }
+    fi
+
+
+
+
+    # Symbols for package include file and library search paths
+
+    SINFONI_INCLUDES='-I$(top_srcdir)/sinfoni'
+    IRPLIB_INCLUDES='-I$(top_srcdir)/irplib'
+
+    SINFONI_LDFLAGS='-L$(top_builddir)/sinfoni'
+    IRPLIB_LDFLAGS='-I$(top_builddir)/irplib'
+
+    # Library aliases
+
+    LIBSINFONI='$(top_builddir)/sinfoni/libsinfo.la'
+    LIBIRPLIB='$(top_builddir)/irplib/libirplib.la'
+
+    # Substitute the defined symbols
+
+
+
+
+
+
+
+
+
+    # Check for CPL and user defined libraries
+
+
+
+    all_includes='$(SINFONI_INCLUDES) $(IRPLIB_INCLUDES) $(CPL_INCLUDES) $(CX_INCLUDES) $(EXTRA_INCLUDES)'
+    all_ldflags='$(SINFONI_LDFLAGS) $(IRPLIB_LDFLAGS) $(CPL_LDFLAGS) $(CX_LDFLAGS) $(EXTRA_LDFLAGS)'
+
+
+
+
+
+{ $as_echo "$as_me:$LINENO: checking if malloc debugging is wanted" >&5
+$as_echo_n "checking if malloc debugging is wanted... " >&6; }
+
+# Check whether --with-dmalloc was given.
+if test "${with_dmalloc+set}" = set; then
+  withval=$with_dmalloc; if test "$withval" = yes; then
+  { $as_echo "$as_me:$LINENO: result: yes" >&5
+$as_echo "yes" >&6; }
+
+cat >>confdefs.h <<\_ACEOF
+#define WITH_DMALLOC 1
+_ACEOF
+
+  LIBS="$LIBS -ldmalloc"
+  LDFLAGS="$LDFLAGS -g"
+else
+  { $as_echo "$as_me:$LINENO: result: no" >&5
+$as_echo "no" >&6; }
+fi
+else
+  { $as_echo "$as_me:$LINENO: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+
+
+ac_config_files="$ac_config_files Makefile Makefile.purify doxygen/Doxyfile irplib/Makefile irplib/tests/Makefile sinfoni/Makefile sinfoni/tests/Makefile recipes/Makefile recipes/tests/Makefile regtests/Makefile regtests/tests/Makefile"
+
+cat >confcache <<\_ACEOF
+# This file is a shell script that caches the results of configure
+# tests run on this system so they can be shared between configure
+# scripts and configure runs, see configure's option --config-cache.
+# It is not useful on other systems.  If it contains results you don't
+# want to keep, you may remove or edit it.
+#
+# config.status only pays attention to the cache file if you give it
+# the --recheck option to rerun configure.
+#
+# `ac_cv_env_foo' variables (set or unset) will be overridden when
+# loading this file, other *unset* `ac_cv_foo' will be assigned the
+# following values.
+
+_ACEOF
+
+# The following way of writing the cache mishandles newlines in values,
+# but we know of no workaround that is simple, portable, and efficient.
+# So, we kill variables containing newlines.
+# Ultrix sh set writes to stderr and can't be redirected directly,
+# and sets the high bit in the cache file unless we assign to the vars.
+(
+  for ac_var in `(set) 2>&1 | sed -n 's/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'`; do
+    eval ac_val=\$$ac_var
+    case $ac_val in #(
+    *${as_nl}*)
+      case $ac_var in #(
+      *_cv_*) { $as_echo "$as_me:$LINENO: WARNING: cache variable $ac_var contains a newline" >&5
+$as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;;
+      esac
+      case $ac_var in #(
+      _ | IFS | as_nl) ;; #(
+      BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #(
+      *) $as_unset $ac_var ;;
+      esac ;;
+    esac
+  done
+
+  (set) 2>&1 |
+    case $as_nl`(ac_space=' '; set) 2>&1` in #(
+    *${as_nl}ac_space=\ *)
+      # `set' does not quote correctly, so add quotes (double-quote
+      # substitution turns \\\\ into \\, and sed turns \\ into \).
+      sed -n \
+	"s/'/'\\\\''/g;
+	  s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p"
+      ;; #(
+    *)
+      # `set' quotes correctly as required by POSIX, so do not add quotes.
+      sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p"
+      ;;
+    esac |
+    sort
+) |
+  sed '
+     /^ac_cv_env_/b end
+     t clear
+     :clear
+     s/^\([^=]*\)=\(.*[{}].*\)$/test "${\1+set}" = set || &/
+     t end
+     s/^\([^=]*\)=\(.*\)$/\1=${\1=\2}/
+     :end' >>confcache
+if diff "$cache_file" confcache >/dev/null 2>&1; then :; else
+  if test -w "$cache_file"; then
+    test "x$cache_file" != "x/dev/null" &&
+      { $as_echo "$as_me:$LINENO: updating cache $cache_file" >&5
+$as_echo "$as_me: updating cache $cache_file" >&6;}
+    cat confcache >$cache_file
+  else
+    { $as_echo "$as_me:$LINENO: not updating unwritable cache $cache_file" >&5
+$as_echo "$as_me: not updating unwritable cache $cache_file" >&6;}
+  fi
+fi
+rm -f confcache
+
+test "x$prefix" = xNONE && prefix=$ac_default_prefix
+# Let make expand exec_prefix.
+test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
+
+DEFS=-DHAVE_CONFIG_H
+
+ac_libobjs=
+ac_ltlibobjs=
+for ac_i in : $LIBOBJS; do test "x$ac_i" = x: && continue
+  # 1. Remove the extension, and $U if already installed.
+  ac_script='s/\$U\././;s/\.o$//;s/\.obj$//'
+  ac_i=`$as_echo "$ac_i" | sed "$ac_script"`
+  # 2. Prepend LIBOBJDIR.  When used with automake>=1.10 LIBOBJDIR
+  #    will be set to the directory where LIBOBJS objects are built.
+  ac_libobjs="$ac_libobjs \${LIBOBJDIR}$ac_i\$U.$ac_objext"
+  ac_ltlibobjs="$ac_ltlibobjs \${LIBOBJDIR}$ac_i"'$U.lo'
+done
+LIBOBJS=$ac_libobjs
+
+LTLIBOBJS=$ac_ltlibobjs
+
+
+ if test -n "$EXEEXT"; then
+  am__EXEEXT_TRUE=
+  am__EXEEXT_FALSE='#'
+else
+  am__EXEEXT_TRUE='#'
+  am__EXEEXT_FALSE=
+fi
+
+if test -z "${MAINTAINER_MODE_TRUE}" && test -z "${MAINTAINER_MODE_FALSE}"; then
+  { { $as_echo "$as_me:$LINENO: error: conditional \"MAINTAINER_MODE\" was never defined.
+Usually this means the macro was only invoked conditionally." >&5
+$as_echo "$as_me: error: conditional \"MAINTAINER_MODE\" was never defined.
+Usually this means the macro was only invoked conditionally." >&2;}
+   { (exit 1); exit 1; }; }
+fi
+if test -z "${AMDEP_TRUE}" && test -z "${AMDEP_FALSE}"; then
+  { { $as_echo "$as_me:$LINENO: error: conditional \"AMDEP\" was never defined.
+Usually this means the macro was only invoked conditionally." >&5
+$as_echo "$as_me: error: conditional \"AMDEP\" was never defined.
+Usually this means the macro was only invoked conditionally." >&2;}
+   { (exit 1); exit 1; }; }
+fi
+if test -z "${am__fastdepCC_TRUE}" && test -z "${am__fastdepCC_FALSE}"; then
+  { { $as_echo "$as_me:$LINENO: error: conditional \"am__fastdepCC\" was never defined.
+Usually this means the macro was only invoked conditionally." >&5
+$as_echo "$as_me: error: conditional \"am__fastdepCC\" was never defined.
+Usually this means the macro was only invoked conditionally." >&2;}
+   { (exit 1); exit 1; }; }
+fi
+if test -z "${PURIFY_TRUE}" && test -z "${PURIFY_FALSE}"; then
+  { { $as_echo "$as_me:$LINENO: error: conditional \"PURIFY\" was never defined.
+Usually this means the macro was only invoked conditionally." >&5
+$as_echo "$as_me: error: conditional \"PURIFY\" was never defined.
+Usually this means the macro was only invoked conditionally." >&2;}
+   { (exit 1); exit 1; }; }
+fi
+
+: ${CONFIG_STATUS=./config.status}
+ac_write_fail=0
+ac_clean_files_save=$ac_clean_files
+ac_clean_files="$ac_clean_files $CONFIG_STATUS"
+{ $as_echo "$as_me:$LINENO: creating $CONFIG_STATUS" >&5
+$as_echo "$as_me: creating $CONFIG_STATUS" >&6;}
+cat >$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+#! $SHELL
+# Generated by $as_me.
+# Run this file to recreate the current configuration.
+# Compiler output produced by configure, useful for debugging
+# configure, is in config.log if it exists.
+
+debug=false
+ac_cs_recheck=false
+ac_cs_silent=false
+SHELL=\${CONFIG_SHELL-$SHELL}
+_ACEOF
+
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+## --------------------- ##
+## M4sh Initialization.  ##
+## --------------------- ##
+
+# Be more Bourne compatible
+DUALCASE=1; export DUALCASE # for MKS sh
+if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
+  emulate sh
+  NULLCMD=:
+  # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
+  # is contrary to our usage.  Disable this feature.
+  alias -g '${1+"$@"}'='"$@"'
+  setopt NO_GLOB_SUBST
+else
+  case `(set -o) 2>/dev/null` in
+  *posix*) set -o posix ;;
+esac
+
+fi
+
+
+
+
+# PATH needs CR
+# Avoid depending upon Character Ranges.
+as_cr_letters='abcdefghijklmnopqrstuvwxyz'
+as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
+as_cr_Letters=$as_cr_letters$as_cr_LETTERS
+as_cr_digits='0123456789'
+as_cr_alnum=$as_cr_Letters$as_cr_digits
+
+as_nl='
+'
+export as_nl
+# Printing a long string crashes Solaris 7 /usr/bin/printf.
+as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'
+as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo
+as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo
+if (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then
+  as_echo='printf %s\n'
+  as_echo_n='printf %s'
+else
+  if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then
+    as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"'
+    as_echo_n='/usr/ucb/echo -n'
+  else
+    as_echo_body='eval expr "X$1" : "X\\(.*\\)"'
+    as_echo_n_body='eval
+      arg=$1;
+      case $arg in
+      *"$as_nl"*)
+	expr "X$arg" : "X\\(.*\\)$as_nl";
+	arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;;
+      esac;
+      expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl"
+    '
+    export as_echo_n_body
+    as_echo_n='sh -c $as_echo_n_body as_echo'
+  fi
+  export as_echo_body
+  as_echo='sh -c $as_echo_body as_echo'
+fi
+
+# The user is always right.
+if test "${PATH_SEPARATOR+set}" != set; then
+  PATH_SEPARATOR=:
+  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
+    (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
+      PATH_SEPARATOR=';'
+  }
+fi
+
+# Support unset when possible.
+if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then
+  as_unset=unset
+else
+  as_unset=false
+fi
+
+
+# IFS
+# We need space, tab and new line, in precisely that order.  Quoting is
+# there to prevent editors from complaining about space-tab.
+# (If _AS_PATH_WALK were called with IFS unset, it would disable word
+# splitting by setting IFS to empty value.)
+IFS=" ""	$as_nl"
+
+# Find who we are.  Look in the path if we contain no directory separator.
+case $0 in
+  *[\\/]* ) as_myself=$0 ;;
+  *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break
+done
+IFS=$as_save_IFS
+
+     ;;
+esac
+# We did not find ourselves, most probably we were run as `sh COMMAND'
+# in which case we are not to be found in the path.
+if test "x$as_myself" = x; then
+  as_myself=$0
+fi
+if test ! -f "$as_myself"; then
+  $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2
+  { (exit 1); exit 1; }
+fi
+
+# Work around bugs in pre-3.0 UWIN ksh.
+for as_var in ENV MAIL MAILPATH
+do ($as_unset $as_var) >/dev/null 2>&1 && $as_unset $as_var
+done
+PS1='$ '
+PS2='> '
+PS4='+ '
+
+# NLS nuisances.
+LC_ALL=C
+export LC_ALL
+LANGUAGE=C
+export LANGUAGE
+
+# Required to use basename.
+if expr a : '\(a\)' >/dev/null 2>&1 &&
+   test "X`expr 00001 : '.*\(...\)'`" = X001; then
+  as_expr=expr
+else
+  as_expr=false
+fi
+
+if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then
+  as_basename=basename
+else
+  as_basename=false
+fi
+
+
+# Name of the executable.
+as_me=`$as_basename -- "$0" ||
+$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \
+	 X"$0" : 'X\(//\)$' \| \
+	 X"$0" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X/"$0" |
+    sed '/^.*\/\([^/][^/]*\)\/*$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\/\(\/\/\)$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\/\(\/\).*/{
+	    s//\1/
+	    q
+	  }
+	  s/.*/./; q'`
+
+# CDPATH.
+$as_unset CDPATH
+
+
+
+  as_lineno_1=$LINENO
+  as_lineno_2=$LINENO
+  test "x$as_lineno_1" != "x$as_lineno_2" &&
+  test "x`expr $as_lineno_1 + 1`" = "x$as_lineno_2" || {
+
+  # Create $as_me.lineno as a copy of $as_myself, but with $LINENO
+  # uniformly replaced by the line number.  The first 'sed' inserts a
+  # line-number line after each line using $LINENO; the second 'sed'
+  # does the real work.  The second script uses 'N' to pair each
+  # line-number line with the line containing $LINENO, and appends
+  # trailing '-' during substitution so that $LINENO is not a special
+  # case at line end.
+  # (Raja R Harinath suggested sed '=', and Paul Eggert wrote the
+  # scripts with optimization help from Paolo Bonzini.  Blame Lee
+  # E. McMahon (1931-1989) for sed's syntax.  :-)
+  sed -n '
+    p
+    /[$]LINENO/=
+  ' <$as_myself |
+    sed '
+      s/[$]LINENO.*/&-/
+      t lineno
+      b
+      :lineno
+      N
+      :loop
+      s/[$]LINENO\([^'$as_cr_alnum'_].*\n\)\(.*\)/\2\1\2/
+      t loop
+      s/-\n.*//
+    ' >$as_me.lineno &&
+  chmod +x "$as_me.lineno" ||
+    { $as_echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2
+   { (exit 1); exit 1; }; }
+
+  # Don't try to exec as it changes $[0], causing all sort of problems
+  # (the dirname of $[0] is not the place where we might find the
+  # original and so on.  Autoconf is especially sensitive to this).
+  . "./$as_me.lineno"
+  # Exit status is that of the last command.
+  exit
+}
+
+
+if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then
+  as_dirname=dirname
+else
+  as_dirname=false
+fi
+
+ECHO_C= ECHO_N= ECHO_T=
+case `echo -n x` in
+-n*)
+  case `echo 'x\c'` in
+  *c*) ECHO_T='	';;	# ECHO_T is single tab character.
+  *)   ECHO_C='\c';;
+  esac;;
+*)
+  ECHO_N='-n';;
+esac
+if expr a : '\(a\)' >/dev/null 2>&1 &&
+   test "X`expr 00001 : '.*\(...\)'`" = X001; then
+  as_expr=expr
+else
+  as_expr=false
+fi
+
+rm -f conf$$ conf$$.exe conf$$.file
+if test -d conf$$.dir; then
+  rm -f conf$$.dir/conf$$.file
+else
+  rm -f conf$$.dir
+  mkdir conf$$.dir 2>/dev/null
+fi
+if (echo >conf$$.file) 2>/dev/null; then
+  if ln -s conf$$.file conf$$ 2>/dev/null; then
+    as_ln_s='ln -s'
+    # ... but there are two gotchas:
+    # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail.
+    # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable.
+    # In both cases, we have to default to `cp -p'.
+    ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe ||
+      as_ln_s='cp -p'
+  elif ln conf$$.file conf$$ 2>/dev/null; then
+    as_ln_s=ln
+  else
+    as_ln_s='cp -p'
+  fi
+else
+  as_ln_s='cp -p'
+fi
+rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file
+rmdir conf$$.dir 2>/dev/null
+
+if mkdir -p . 2>/dev/null; then
+  as_mkdir_p=:
+else
+  test -d ./-p && rmdir ./-p
+  as_mkdir_p=false
+fi
+
+if test -x / >/dev/null 2>&1; then
+  as_test_x='test -x'
+else
+  if ls -dL / >/dev/null 2>&1; then
+    as_ls_L_option=L
+  else
+    as_ls_L_option=
+  fi
+  as_test_x='
+    eval sh -c '\''
+      if test -d "$1"; then
+	test -d "$1/.";
+      else
+	case $1 in
+	-*)set "./$1";;
+	esac;
+	case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in
+	???[sx]*):;;*)false;;esac;fi
+    '\'' sh
+  '
+fi
+as_executable_p=$as_test_x
+
+# Sed expression to map a string onto a valid CPP name.
+as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'"
+
+# Sed expression to map a string onto a valid variable name.
+as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'"
+
+
+exec 6>&1
+
+# Save the log message, to keep $[0] and so on meaningful, and to
+# report actual input values of CONFIG_FILES etc. instead of their
+# values after options handling.
+ac_log="
+This file was extended by SINFONI Instrument Pipeline $as_me 2.3.2, which was
+generated by GNU Autoconf 2.63.  Invocation command line was
+
+  CONFIG_FILES    = $CONFIG_FILES
+  CONFIG_HEADERS  = $CONFIG_HEADERS
+  CONFIG_LINKS    = $CONFIG_LINKS
+  CONFIG_COMMANDS = $CONFIG_COMMANDS
+  $ $0 $@
+
+on `(hostname || uname -n) 2>/dev/null | sed 1q`
+"
+
+_ACEOF
+
+case $ac_config_files in *"
+"*) set x $ac_config_files; shift; ac_config_files=$*;;
+esac
+
+case $ac_config_headers in *"
+"*) set x $ac_config_headers; shift; ac_config_headers=$*;;
+esac
+
+
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+# Files that config.status was made for.
+config_files="$ac_config_files"
+config_headers="$ac_config_headers"
+config_commands="$ac_config_commands"
+
+_ACEOF
+
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+ac_cs_usage="\
+\`$as_me' instantiates files from templates according to the
+current configuration.
+
+Usage: $0 [OPTION]... [FILE]...
+
+  -h, --help       print this help, then exit
+  -V, --version    print version number and configuration settings, then exit
+  -q, --quiet, --silent
+                   do not print progress messages
+  -d, --debug      don't remove temporary files
+      --recheck    update $as_me by reconfiguring in the same conditions
+      --file=FILE[:TEMPLATE]
+                   instantiate the configuration file FILE
+      --header=FILE[:TEMPLATE]
+                   instantiate the configuration header FILE
+
+Configuration files:
+$config_files
+
+Configuration headers:
+$config_headers
+
+Configuration commands:
+$config_commands
+
+Report bugs to <bug-autoconf at gnu.org>."
+
+_ACEOF
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+ac_cs_version="\\
+SINFONI Instrument Pipeline config.status 2.3.2
+configured by $0, generated by GNU Autoconf 2.63,
+  with options \\"`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\"
+
+Copyright (C) 2008 Free Software Foundation, Inc.
+This config.status script is free software; the Free Software Foundation
+gives unlimited permission to copy, distribute and modify it."
+
+ac_pwd='$ac_pwd'
+srcdir='$srcdir'
+INSTALL='$INSTALL'
+MKDIR_P='$MKDIR_P'
+AWK='$AWK'
+test -n "\$AWK" || AWK=awk
+_ACEOF
+
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+# The default lists apply if the user does not specify any file.
+ac_need_defaults=:
+while test $# != 0
+do
+  case $1 in
+  --*=*)
+    ac_option=`expr "X$1" : 'X\([^=]*\)='`
+    ac_optarg=`expr "X$1" : 'X[^=]*=\(.*\)'`
+    ac_shift=:
+    ;;
+  *)
+    ac_option=$1
+    ac_optarg=$2
+    ac_shift=shift
+    ;;
+  esac
+
+  case $ac_option in
+  # Handling of the options.
+  -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r)
+    ac_cs_recheck=: ;;
+  --version | --versio | --versi | --vers | --ver | --ve | --v | -V )
+    $as_echo "$ac_cs_version"; exit ;;
+  --debug | --debu | --deb | --de | --d | -d )
+    debug=: ;;
+  --file | --fil | --fi | --f )
+    $ac_shift
+    case $ac_optarg in
+    *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;;
+    esac
+    CONFIG_FILES="$CONFIG_FILES '$ac_optarg'"
+    ac_need_defaults=false;;
+  --header | --heade | --head | --hea )
+    $ac_shift
+    case $ac_optarg in
+    *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;;
+    esac
+    CONFIG_HEADERS="$CONFIG_HEADERS '$ac_optarg'"
+    ac_need_defaults=false;;
+  --he | --h)
+    # Conflict between --help and --header
+    { $as_echo "$as_me: error: ambiguous option: $1
+Try \`$0 --help' for more information." >&2
+   { (exit 1); exit 1; }; };;
+  --help | --hel | -h )
+    $as_echo "$ac_cs_usage"; exit ;;
+  -q | -quiet | --quiet | --quie | --qui | --qu | --q \
+  | -silent | --silent | --silen | --sile | --sil | --si | --s)
+    ac_cs_silent=: ;;
+
+  # This is an error.
+  -*) { $as_echo "$as_me: error: unrecognized option: $1
+Try \`$0 --help' for more information." >&2
+   { (exit 1); exit 1; }; } ;;
+
+  *) ac_config_targets="$ac_config_targets $1"
+     ac_need_defaults=false ;;
+
+  esac
+  shift
+done
+
+ac_configure_extra_args=
+
+if $ac_cs_silent; then
+  exec 6>/dev/null
+  ac_configure_extra_args="$ac_configure_extra_args --silent"
+fi
+
+_ACEOF
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+if \$ac_cs_recheck; then
+  set X '$SHELL' '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion
+  shift
+  \$as_echo "running CONFIG_SHELL=$SHELL \$*" >&6
+  CONFIG_SHELL='$SHELL'
+  export CONFIG_SHELL
+  exec "\$@"
+fi
+
+_ACEOF
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+exec 5>>config.log
+{
+  echo
+  sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX
+## Running $as_me. ##
+_ASBOX
+  $as_echo "$ac_log"
+} >&5
+
+_ACEOF
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+#
+# INIT-COMMANDS
+#
+AMDEP_TRUE="$AMDEP_TRUE" ac_aux_dir="$ac_aux_dir"
+
+
+# The HP-UX ksh and POSIX shell print the target directory to stdout
+# if CDPATH is set.
+(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
+
+sed_quote_subst='$sed_quote_subst'
+double_quote_subst='$double_quote_subst'
+delay_variable_subst='$delay_variable_subst'
+enable_static='`$ECHO "X$enable_static" | $Xsed -e "$delay_single_quote_subst"`'
+enable_shared='`$ECHO "X$enable_shared" | $Xsed -e "$delay_single_quote_subst"`'
+macro_version='`$ECHO "X$macro_version" | $Xsed -e "$delay_single_quote_subst"`'
+macro_revision='`$ECHO "X$macro_revision" | $Xsed -e "$delay_single_quote_subst"`'
+pic_mode='`$ECHO "X$pic_mode" | $Xsed -e "$delay_single_quote_subst"`'
+enable_fast_install='`$ECHO "X$enable_fast_install" | $Xsed -e "$delay_single_quote_subst"`'
+host_alias='`$ECHO "X$host_alias" | $Xsed -e "$delay_single_quote_subst"`'
+host='`$ECHO "X$host" | $Xsed -e "$delay_single_quote_subst"`'
+host_os='`$ECHO "X$host_os" | $Xsed -e "$delay_single_quote_subst"`'
+build_alias='`$ECHO "X$build_alias" | $Xsed -e "$delay_single_quote_subst"`'
+build='`$ECHO "X$build" | $Xsed -e "$delay_single_quote_subst"`'
+build_os='`$ECHO "X$build_os" | $Xsed -e "$delay_single_quote_subst"`'
+SED='`$ECHO "X$SED" | $Xsed -e "$delay_single_quote_subst"`'
+Xsed='`$ECHO "X$Xsed" | $Xsed -e "$delay_single_quote_subst"`'
+GREP='`$ECHO "X$GREP" | $Xsed -e "$delay_single_quote_subst"`'
+EGREP='`$ECHO "X$EGREP" | $Xsed -e "$delay_single_quote_subst"`'
+FGREP='`$ECHO "X$FGREP" | $Xsed -e "$delay_single_quote_subst"`'
+LD='`$ECHO "X$LD" | $Xsed -e "$delay_single_quote_subst"`'
+NM='`$ECHO "X$NM" | $Xsed -e "$delay_single_quote_subst"`'
+LN_S='`$ECHO "X$LN_S" | $Xsed -e "$delay_single_quote_subst"`'
+max_cmd_len='`$ECHO "X$max_cmd_len" | $Xsed -e "$delay_single_quote_subst"`'
+ac_objext='`$ECHO "X$ac_objext" | $Xsed -e "$delay_single_quote_subst"`'
+exeext='`$ECHO "X$exeext" | $Xsed -e "$delay_single_quote_subst"`'
+lt_unset='`$ECHO "X$lt_unset" | $Xsed -e "$delay_single_quote_subst"`'
+lt_SP2NL='`$ECHO "X$lt_SP2NL" | $Xsed -e "$delay_single_quote_subst"`'
+lt_NL2SP='`$ECHO "X$lt_NL2SP" | $Xsed -e "$delay_single_quote_subst"`'
+reload_flag='`$ECHO "X$reload_flag" | $Xsed -e "$delay_single_quote_subst"`'
+reload_cmds='`$ECHO "X$reload_cmds" | $Xsed -e "$delay_single_quote_subst"`'
+OBJDUMP='`$ECHO "X$OBJDUMP" | $Xsed -e "$delay_single_quote_subst"`'
+deplibs_check_method='`$ECHO "X$deplibs_check_method" | $Xsed -e "$delay_single_quote_subst"`'
+file_magic_cmd='`$ECHO "X$file_magic_cmd" | $Xsed -e "$delay_single_quote_subst"`'
+AR='`$ECHO "X$AR" | $Xsed -e "$delay_single_quote_subst"`'
+AR_FLAGS='`$ECHO "X$AR_FLAGS" | $Xsed -e "$delay_single_quote_subst"`'
+STRIP='`$ECHO "X$STRIP" | $Xsed -e "$delay_single_quote_subst"`'
+RANLIB='`$ECHO "X$RANLIB" | $Xsed -e "$delay_single_quote_subst"`'
+old_postinstall_cmds='`$ECHO "X$old_postinstall_cmds" | $Xsed -e "$delay_single_quote_subst"`'
+old_postuninstall_cmds='`$ECHO "X$old_postuninstall_cmds" | $Xsed -e "$delay_single_quote_subst"`'
+old_archive_cmds='`$ECHO "X$old_archive_cmds" | $Xsed -e "$delay_single_quote_subst"`'
+CC='`$ECHO "X$CC" | $Xsed -e "$delay_single_quote_subst"`'
+CFLAGS='`$ECHO "X$CFLAGS" | $Xsed -e "$delay_single_quote_subst"`'
+compiler='`$ECHO "X$compiler" | $Xsed -e "$delay_single_quote_subst"`'
+GCC='`$ECHO "X$GCC" | $Xsed -e "$delay_single_quote_subst"`'
+lt_cv_sys_global_symbol_pipe='`$ECHO "X$lt_cv_sys_global_symbol_pipe" | $Xsed -e "$delay_single_quote_subst"`'
+lt_cv_sys_global_symbol_to_cdecl='`$ECHO "X$lt_cv_sys_global_symbol_to_cdecl" | $Xsed -e "$delay_single_quote_subst"`'
+lt_cv_sys_global_symbol_to_c_name_address='`$ECHO "X$lt_cv_sys_global_symbol_to_c_name_address" | $Xsed -e "$delay_single_quote_subst"`'
+lt_cv_sys_global_symbol_to_c_name_address_lib_prefix='`$ECHO "X$lt_cv_sys_global_symbol_to_c_name_address_lib_prefix" | $Xsed -e "$delay_single_quote_subst"`'
+objdir='`$ECHO "X$objdir" | $Xsed -e "$delay_single_quote_subst"`'
+SHELL='`$ECHO "X$SHELL" | $Xsed -e "$delay_single_quote_subst"`'
+ECHO='`$ECHO "X$ECHO" | $Xsed -e "$delay_single_quote_subst"`'
+MAGIC_CMD='`$ECHO "X$MAGIC_CMD" | $Xsed -e "$delay_single_quote_subst"`'
+lt_prog_compiler_no_builtin_flag='`$ECHO "X$lt_prog_compiler_no_builtin_flag" | $Xsed -e "$delay_single_quote_subst"`'
+lt_prog_compiler_wl='`$ECHO "X$lt_prog_compiler_wl" | $Xsed -e "$delay_single_quote_subst"`'
+lt_prog_compiler_pic='`$ECHO "X$lt_prog_compiler_pic" | $Xsed -e "$delay_single_quote_subst"`'
+lt_prog_compiler_static='`$ECHO "X$lt_prog_compiler_static" | $Xsed -e "$delay_single_quote_subst"`'
+lt_cv_prog_compiler_c_o='`$ECHO "X$lt_cv_prog_compiler_c_o" | $Xsed -e "$delay_single_quote_subst"`'
+need_locks='`$ECHO "X$need_locks" | $Xsed -e "$delay_single_quote_subst"`'
+DSYMUTIL='`$ECHO "X$DSYMUTIL" | $Xsed -e "$delay_single_quote_subst"`'
+NMEDIT='`$ECHO "X$NMEDIT" | $Xsed -e "$delay_single_quote_subst"`'
+LIPO='`$ECHO "X$LIPO" | $Xsed -e "$delay_single_quote_subst"`'
+OTOOL='`$ECHO "X$OTOOL" | $Xsed -e "$delay_single_quote_subst"`'
+OTOOL64='`$ECHO "X$OTOOL64" | $Xsed -e "$delay_single_quote_subst"`'
+libext='`$ECHO "X$libext" | $Xsed -e "$delay_single_quote_subst"`'
+shrext_cmds='`$ECHO "X$shrext_cmds" | $Xsed -e "$delay_single_quote_subst"`'
+extract_expsyms_cmds='`$ECHO "X$extract_expsyms_cmds" | $Xsed -e "$delay_single_quote_subst"`'
+archive_cmds_need_lc='`$ECHO "X$archive_cmds_need_lc" | $Xsed -e "$delay_single_quote_subst"`'
+enable_shared_with_static_runtimes='`$ECHO "X$enable_shared_with_static_runtimes" | $Xsed -e "$delay_single_quote_subst"`'
+export_dynamic_flag_spec='`$ECHO "X$export_dynamic_flag_spec" | $Xsed -e "$delay_single_quote_subst"`'
+whole_archive_flag_spec='`$ECHO "X$whole_archive_flag_spec" | $Xsed -e "$delay_single_quote_subst"`'
+compiler_needs_object='`$ECHO "X$compiler_needs_object" | $Xsed -e "$delay_single_quote_subst"`'
+old_archive_from_new_cmds='`$ECHO "X$old_archive_from_new_cmds" | $Xsed -e "$delay_single_quote_subst"`'
+old_archive_from_expsyms_cmds='`$ECHO "X$old_archive_from_expsyms_cmds" | $Xsed -e "$delay_single_quote_subst"`'
+archive_cmds='`$ECHO "X$archive_cmds" | $Xsed -e "$delay_single_quote_subst"`'
+archive_expsym_cmds='`$ECHO "X$archive_expsym_cmds" | $Xsed -e "$delay_single_quote_subst"`'
+module_cmds='`$ECHO "X$module_cmds" | $Xsed -e "$delay_single_quote_subst"`'
+module_expsym_cmds='`$ECHO "X$module_expsym_cmds" | $Xsed -e "$delay_single_quote_subst"`'
+with_gnu_ld='`$ECHO "X$with_gnu_ld" | $Xsed -e "$delay_single_quote_subst"`'
+allow_undefined_flag='`$ECHO "X$allow_undefined_flag" | $Xsed -e "$delay_single_quote_subst"`'
+no_undefined_flag='`$ECHO "X$no_undefined_flag" | $Xsed -e "$delay_single_quote_subst"`'
+hardcode_libdir_flag_spec='`$ECHO "X$hardcode_libdir_flag_spec" | $Xsed -e "$delay_single_quote_subst"`'
+hardcode_libdir_flag_spec_ld='`$ECHO "X$hardcode_libdir_flag_spec_ld" | $Xsed -e "$delay_single_quote_subst"`'
+hardcode_libdir_separator='`$ECHO "X$hardcode_libdir_separator" | $Xsed -e "$delay_single_quote_subst"`'
+hardcode_direct='`$ECHO "X$hardcode_direct" | $Xsed -e "$delay_single_quote_subst"`'
+hardcode_direct_absolute='`$ECHO "X$hardcode_direct_absolute" | $Xsed -e "$delay_single_quote_subst"`'
+hardcode_minus_L='`$ECHO "X$hardcode_minus_L" | $Xsed -e "$delay_single_quote_subst"`'
+hardcode_shlibpath_var='`$ECHO "X$hardcode_shlibpath_var" | $Xsed -e "$delay_single_quote_subst"`'
+hardcode_automatic='`$ECHO "X$hardcode_automatic" | $Xsed -e "$delay_single_quote_subst"`'
+inherit_rpath='`$ECHO "X$inherit_rpath" | $Xsed -e "$delay_single_quote_subst"`'
+link_all_deplibs='`$ECHO "X$link_all_deplibs" | $Xsed -e "$delay_single_quote_subst"`'
+fix_srcfile_path='`$ECHO "X$fix_srcfile_path" | $Xsed -e "$delay_single_quote_subst"`'
+always_export_symbols='`$ECHO "X$always_export_symbols" | $Xsed -e "$delay_single_quote_subst"`'
+export_symbols_cmds='`$ECHO "X$export_symbols_cmds" | $Xsed -e "$delay_single_quote_subst"`'
+exclude_expsyms='`$ECHO "X$exclude_expsyms" | $Xsed -e "$delay_single_quote_subst"`'
+include_expsyms='`$ECHO "X$include_expsyms" | $Xsed -e "$delay_single_quote_subst"`'
+prelink_cmds='`$ECHO "X$prelink_cmds" | $Xsed -e "$delay_single_quote_subst"`'
+file_list_spec='`$ECHO "X$file_list_spec" | $Xsed -e "$delay_single_quote_subst"`'
+variables_saved_for_relink='`$ECHO "X$variables_saved_for_relink" | $Xsed -e "$delay_single_quote_subst"`'
+need_lib_prefix='`$ECHO "X$need_lib_prefix" | $Xsed -e "$delay_single_quote_subst"`'
+need_version='`$ECHO "X$need_version" | $Xsed -e "$delay_single_quote_subst"`'
+version_type='`$ECHO "X$version_type" | $Xsed -e "$delay_single_quote_subst"`'
+runpath_var='`$ECHO "X$runpath_var" | $Xsed -e "$delay_single_quote_subst"`'
+shlibpath_var='`$ECHO "X$shlibpath_var" | $Xsed -e "$delay_single_quote_subst"`'
+shlibpath_overrides_runpath='`$ECHO "X$shlibpath_overrides_runpath" | $Xsed -e "$delay_single_quote_subst"`'
+libname_spec='`$ECHO "X$libname_spec" | $Xsed -e "$delay_single_quote_subst"`'
+library_names_spec='`$ECHO "X$library_names_spec" | $Xsed -e "$delay_single_quote_subst"`'
+soname_spec='`$ECHO "X$soname_spec" | $Xsed -e "$delay_single_quote_subst"`'
+postinstall_cmds='`$ECHO "X$postinstall_cmds" | $Xsed -e "$delay_single_quote_subst"`'
+postuninstall_cmds='`$ECHO "X$postuninstall_cmds" | $Xsed -e "$delay_single_quote_subst"`'
+finish_cmds='`$ECHO "X$finish_cmds" | $Xsed -e "$delay_single_quote_subst"`'
+finish_eval='`$ECHO "X$finish_eval" | $Xsed -e "$delay_single_quote_subst"`'
+hardcode_into_libs='`$ECHO "X$hardcode_into_libs" | $Xsed -e "$delay_single_quote_subst"`'
+sys_lib_search_path_spec='`$ECHO "X$sys_lib_search_path_spec" | $Xsed -e "$delay_single_quote_subst"`'
+sys_lib_dlsearch_path_spec='`$ECHO "X$sys_lib_dlsearch_path_spec" | $Xsed -e "$delay_single_quote_subst"`'
+hardcode_action='`$ECHO "X$hardcode_action" | $Xsed -e "$delay_single_quote_subst"`'
+enable_dlopen='`$ECHO "X$enable_dlopen" | $Xsed -e "$delay_single_quote_subst"`'
+enable_dlopen_self='`$ECHO "X$enable_dlopen_self" | $Xsed -e "$delay_single_quote_subst"`'
+enable_dlopen_self_static='`$ECHO "X$enable_dlopen_self_static" | $Xsed -e "$delay_single_quote_subst"`'
+old_striplib='`$ECHO "X$old_striplib" | $Xsed -e "$delay_single_quote_subst"`'
+striplib='`$ECHO "X$striplib" | $Xsed -e "$delay_single_quote_subst"`'
+
+LTCC='$LTCC'
+LTCFLAGS='$LTCFLAGS'
+compiler='$compiler_DEFAULT'
+
+# Quote evaled strings.
+for var in SED \
+GREP \
+EGREP \
+FGREP \
+LD \
+NM \
+LN_S \
+lt_SP2NL \
+lt_NL2SP \
+reload_flag \
+OBJDUMP \
+deplibs_check_method \
+file_magic_cmd \
+AR \
+AR_FLAGS \
+STRIP \
+RANLIB \
+CC \
+CFLAGS \
+compiler \
+lt_cv_sys_global_symbol_pipe \
+lt_cv_sys_global_symbol_to_cdecl \
+lt_cv_sys_global_symbol_to_c_name_address \
+lt_cv_sys_global_symbol_to_c_name_address_lib_prefix \
+SHELL \
+ECHO \
+lt_prog_compiler_no_builtin_flag \
+lt_prog_compiler_wl \
+lt_prog_compiler_pic \
+lt_prog_compiler_static \
+lt_cv_prog_compiler_c_o \
+need_locks \
+DSYMUTIL \
+NMEDIT \
+LIPO \
+OTOOL \
+OTOOL64 \
+shrext_cmds \
+export_dynamic_flag_spec \
+whole_archive_flag_spec \
+compiler_needs_object \
+with_gnu_ld \
+allow_undefined_flag \
+no_undefined_flag \
+hardcode_libdir_flag_spec \
+hardcode_libdir_flag_spec_ld \
+hardcode_libdir_separator \
+fix_srcfile_path \
+exclude_expsyms \
+include_expsyms \
+file_list_spec \
+variables_saved_for_relink \
+libname_spec \
+library_names_spec \
+soname_spec \
+finish_eval \
+old_striplib \
+striplib; do
+    case \`eval \\\\\$ECHO "X\\\\\$\$var"\` in
+    *[\\\\\\\`\\"\\\$]*)
+      eval "lt_\$var=\\\\\\"\\\`\\\$ECHO \\"X\\\$\$var\\" | \\\$Xsed -e \\"\\\$sed_quote_subst\\"\\\`\\\\\\""
+      ;;
+    *)
+      eval "lt_\$var=\\\\\\"\\\$\$var\\\\\\""
+      ;;
+    esac
+done
+
+# Double-quote double-evaled strings.
+for var in reload_cmds \
+old_postinstall_cmds \
+old_postuninstall_cmds \
+old_archive_cmds \
+extract_expsyms_cmds \
+old_archive_from_new_cmds \
+old_archive_from_expsyms_cmds \
+archive_cmds \
+archive_expsym_cmds \
+module_cmds \
+module_expsym_cmds \
+export_symbols_cmds \
+prelink_cmds \
+postinstall_cmds \
+postuninstall_cmds \
+finish_cmds \
+sys_lib_search_path_spec \
+sys_lib_dlsearch_path_spec; do
+    case \`eval \\\\\$ECHO "X\\\\\$\$var"\` in
+    *[\\\\\\\`\\"\\\$]*)
+      eval "lt_\$var=\\\\\\"\\\`\\\$ECHO \\"X\\\$\$var\\" | \\\$Xsed -e \\"\\\$double_quote_subst\\" -e \\"\\\$sed_quote_subst\\" -e \\"\\\$delay_variable_subst\\"\\\`\\\\\\""
+      ;;
+    *)
+      eval "lt_\$var=\\\\\\"\\\$\$var\\\\\\""
+      ;;
+    esac
+done
+
+# Fix-up fallback echo if it was mangled by the above quoting rules.
+case \$lt_ECHO in
+*'\\\$0 --fallback-echo"')  lt_ECHO=\`\$ECHO "X\$lt_ECHO" | \$Xsed -e 's/\\\\\\\\\\\\\\\$0 --fallback-echo"\$/\$0 --fallback-echo"/'\`
+  ;;
+esac
+
+ac_aux_dir='$ac_aux_dir'
+xsi_shell='$xsi_shell'
+lt_shell_append='$lt_shell_append'
+
+# See if we are running on zsh, and set the options which allow our
+# commands through without removal of \ escapes INIT.
+if test -n "\${ZSH_VERSION+set}" ; then
+   setopt NO_GLOB_SUBST
+fi
+
+
+    PACKAGE='$PACKAGE'
+    VERSION='$VERSION'
+    TIMESTAMP='$TIMESTAMP'
+    RM='$RM'
+    ofile='$ofile'
+
+
+
+
+_ACEOF
+
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+
+# Handling of arguments.
+for ac_config_target in $ac_config_targets
+do
+  case $ac_config_target in
+    "config.h") CONFIG_HEADERS="$CONFIG_HEADERS config.h" ;;
+    "depfiles") CONFIG_COMMANDS="$CONFIG_COMMANDS depfiles" ;;
+    "libtool") CONFIG_COMMANDS="$CONFIG_COMMANDS libtool" ;;
+    "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;;
+    "Makefile.purify") CONFIG_FILES="$CONFIG_FILES Makefile.purify" ;;
+    "doxygen/Doxyfile") CONFIG_FILES="$CONFIG_FILES doxygen/Doxyfile" ;;
+    "irplib/Makefile") CONFIG_FILES="$CONFIG_FILES irplib/Makefile" ;;
+    "irplib/tests/Makefile") CONFIG_FILES="$CONFIG_FILES irplib/tests/Makefile" ;;
+    "sinfoni/Makefile") CONFIG_FILES="$CONFIG_FILES sinfoni/Makefile" ;;
+    "sinfoni/tests/Makefile") CONFIG_FILES="$CONFIG_FILES sinfoni/tests/Makefile" ;;
+    "recipes/Makefile") CONFIG_FILES="$CONFIG_FILES recipes/Makefile" ;;
+    "recipes/tests/Makefile") CONFIG_FILES="$CONFIG_FILES recipes/tests/Makefile" ;;
+    "regtests/Makefile") CONFIG_FILES="$CONFIG_FILES regtests/Makefile" ;;
+    "regtests/tests/Makefile") CONFIG_FILES="$CONFIG_FILES regtests/tests/Makefile" ;;
+
+  *) { { $as_echo "$as_me:$LINENO: error: invalid argument: $ac_config_target" >&5
+$as_echo "$as_me: error: invalid argument: $ac_config_target" >&2;}
+   { (exit 1); exit 1; }; };;
+  esac
+done
+
+
+# If the user did not use the arguments to specify the items to instantiate,
+# then the envvar interface is used.  Set only those that are not.
+# We use the long form for the default assignment because of an extremely
+# bizarre bug on SunOS 4.1.3.
+if $ac_need_defaults; then
+  test "${CONFIG_FILES+set}" = set || CONFIG_FILES=$config_files
+  test "${CONFIG_HEADERS+set}" = set || CONFIG_HEADERS=$config_headers
+  test "${CONFIG_COMMANDS+set}" = set || CONFIG_COMMANDS=$config_commands
+fi
+
+# Have a temporary directory for convenience.  Make it in the build tree
+# simply because there is no reason against having it here, and in addition,
+# creating and moving files from /tmp can sometimes cause problems.
+# Hook for its removal unless debugging.
+# Note that there is a small window in which the directory will not be cleaned:
+# after its creation but before its name has been assigned to `$tmp'.
+$debug ||
+{
+  tmp=
+  trap 'exit_status=$?
+  { test -z "$tmp" || test ! -d "$tmp" || rm -fr "$tmp"; } && exit $exit_status
+' 0
+  trap '{ (exit 1); exit 1; }' 1 2 13 15
+}
+# Create a (secure) tmp directory for tmp files.
+
+{
+  tmp=`(umask 077 && mktemp -d "./confXXXXXX") 2>/dev/null` &&
+  test -n "$tmp" && test -d "$tmp"
+}  ||
+{
+  tmp=./conf$$-$RANDOM
+  (umask 077 && mkdir "$tmp")
+} ||
+{
+   $as_echo "$as_me: cannot create a temporary directory in ." >&2
+   { (exit 1); exit 1; }
+}
+
+# Set up the scripts for CONFIG_FILES section.
+# No need to generate them if there are no CONFIG_FILES.
+# This happens for instance with `./config.status config.h'.
+if test -n "$CONFIG_FILES"; then
+
+
+ac_cr='
'
+ac_cs_awk_cr=`$AWK 'BEGIN { print "a\rb" }' </dev/null 2>/dev/null`
+if test "$ac_cs_awk_cr" = "a${ac_cr}b"; then
+  ac_cs_awk_cr='\\r'
+else
+  ac_cs_awk_cr=$ac_cr
+fi
+
+echo 'BEGIN {' >"$tmp/subs1.awk" &&
+_ACEOF
+
+
+{
+  echo "cat >conf$$subs.awk <<_ACEOF" &&
+  echo "$ac_subst_vars" | sed 's/.*/&!$&$ac_delim/' &&
+  echo "_ACEOF"
+} >conf$$subs.sh ||
+  { { $as_echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5
+$as_echo "$as_me: error: could not make $CONFIG_STATUS" >&2;}
+   { (exit 1); exit 1; }; }
+ac_delim_num=`echo "$ac_subst_vars" | grep -c '$'`
+ac_delim='%!_!# '
+for ac_last_try in false false false false false :; do
+  . ./conf$$subs.sh ||
+    { { $as_echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5
+$as_echo "$as_me: error: could not make $CONFIG_STATUS" >&2;}
+   { (exit 1); exit 1; }; }
+
+  ac_delim_n=`sed -n "s/.*$ac_delim\$/X/p" conf$$subs.awk | grep -c X`
+  if test $ac_delim_n = $ac_delim_num; then
+    break
+  elif $ac_last_try; then
+    { { $as_echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5
+$as_echo "$as_me: error: could not make $CONFIG_STATUS" >&2;}
+   { (exit 1); exit 1; }; }
+  else
+    ac_delim="$ac_delim!$ac_delim _$ac_delim!! "
+  fi
+done
+rm -f conf$$subs.sh
+
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+cat >>"\$tmp/subs1.awk" <<\\_ACAWK &&
+_ACEOF
+sed -n '
+h
+s/^/S["/; s/!.*/"]=/
+p
+g
+s/^[^!]*!//
+:repl
+t repl
+s/'"$ac_delim"'$//
+t delim
+:nl
+h
+s/\(.\{148\}\).*/\1/
+t more1
+s/["\\]/\\&/g; s/^/"/; s/$/\\n"\\/
+p
+n
+b repl
+:more1
+s/["\\]/\\&/g; s/^/"/; s/$/"\\/
+p
+g
+s/.\{148\}//
+t nl
+:delim
+h
+s/\(.\{148\}\).*/\1/
+t more2
+s/["\\]/\\&/g; s/^/"/; s/$/"/
+p
+b
+:more2
+s/["\\]/\\&/g; s/^/"/; s/$/"\\/
+p
+g
+s/.\{148\}//
+t delim
+' <conf$$subs.awk | sed '
+/^[^""]/{
+  N
+  s/\n//
+}
+' >>$CONFIG_STATUS || ac_write_fail=1
+rm -f conf$$subs.awk
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+_ACAWK
+cat >>"\$tmp/subs1.awk" <<_ACAWK &&
+  for (key in S) S_is_set[key] = 1
+  FS = ""
+
+}
+{
+  line = $ 0
+  nfields = split(line, field, "@")
+  substed = 0
+  len = length(field[1])
+  for (i = 2; i < nfields; i++) {
+    key = field[i]
+    keylen = length(key)
+    if (S_is_set[key]) {
+      value = S[key]
+      line = substr(line, 1, len) "" value "" substr(line, len + keylen + 3)
+      len += length(value) + length(field[++i])
+      substed = 1
+    } else
+      len += 1 + keylen
+  }
+
+  print line
+}
+
+_ACAWK
+_ACEOF
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+if sed "s/$ac_cr//" < /dev/null > /dev/null 2>&1; then
+  sed "s/$ac_cr\$//; s/$ac_cr/$ac_cs_awk_cr/g"
+else
+  cat
+fi < "$tmp/subs1.awk" > "$tmp/subs.awk" \
+  || { { $as_echo "$as_me:$LINENO: error: could not setup config files machinery" >&5
+$as_echo "$as_me: error: could not setup config files machinery" >&2;}
+   { (exit 1); exit 1; }; }
+_ACEOF
+
+# VPATH may cause trouble with some makes, so we remove $(srcdir),
+# ${srcdir} and @srcdir@ from VPATH if srcdir is ".", strip leading and
+# trailing colons and then remove the whole line if VPATH becomes empty
+# (actually we leave an empty line to preserve line numbers).
+if test "x$srcdir" = x.; then
+  ac_vpsub='/^[	 ]*VPATH[	 ]*=/{
+s/:*\$(srcdir):*/:/
+s/:*\${srcdir}:*/:/
+s/:*@srcdir@:*/:/
+s/^\([^=]*=[	 ]*\):*/\1/
+s/:*$//
+s/^[^=]*=[	 ]*$//
+}'
+fi
+
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+fi # test -n "$CONFIG_FILES"
+
+# Set up the scripts for CONFIG_HEADERS section.
+# No need to generate them if there are no CONFIG_HEADERS.
+# This happens for instance with `./config.status Makefile'.
+if test -n "$CONFIG_HEADERS"; then
+cat >"$tmp/defines.awk" <<\_ACAWK ||
+BEGIN {
+_ACEOF
+
+# Transform confdefs.h into an awk script `defines.awk', embedded as
+# here-document in config.status, that substitutes the proper values into
+# config.h.in to produce config.h.
+
+# Create a delimiter string that does not exist in confdefs.h, to ease
+# handling of long lines.
+ac_delim='%!_!# '
+for ac_last_try in false false :; do
+  ac_t=`sed -n "/$ac_delim/p" confdefs.h`
+  if test -z "$ac_t"; then
+    break
+  elif $ac_last_try; then
+    { { $as_echo "$as_me:$LINENO: error: could not make $CONFIG_HEADERS" >&5
+$as_echo "$as_me: error: could not make $CONFIG_HEADERS" >&2;}
+   { (exit 1); exit 1; }; }
+  else
+    ac_delim="$ac_delim!$ac_delim _$ac_delim!! "
+  fi
+done
+
+# For the awk script, D is an array of macro values keyed by name,
+# likewise P contains macro parameters if any.  Preserve backslash
+# newline sequences.
+
+ac_word_re=[_$as_cr_Letters][_$as_cr_alnum]*
+sed -n '
+s/.\{148\}/&'"$ac_delim"'/g
+t rset
+:rset
+s/^[	 ]*#[	 ]*define[	 ][	 ]*/ /
+t def
+d
+:def
+s/\\$//
+t bsnl
+s/["\\]/\\&/g
+s/^ \('"$ac_word_re"'\)\(([^()]*)\)[	 ]*\(.*\)/P["\1"]="\2"\
+D["\1"]=" \3"/p
+s/^ \('"$ac_word_re"'\)[	 ]*\(.*\)/D["\1"]=" \2"/p
+d
+:bsnl
+s/["\\]/\\&/g
+s/^ \('"$ac_word_re"'\)\(([^()]*)\)[	 ]*\(.*\)/P["\1"]="\2"\
+D["\1"]=" \3\\\\\\n"\\/p
+t cont
+s/^ \('"$ac_word_re"'\)[	 ]*\(.*\)/D["\1"]=" \2\\\\\\n"\\/p
+t cont
+d
+:cont
+n
+s/.\{148\}/&'"$ac_delim"'/g
+t clear
+:clear
+s/\\$//
+t bsnlc
+s/["\\]/\\&/g; s/^/"/; s/$/"/p
+d
+:bsnlc
+s/["\\]/\\&/g; s/^/"/; s/$/\\\\\\n"\\/p
+b cont
+' <confdefs.h | sed '
+s/'"$ac_delim"'/"\\\
+"/g' >>$CONFIG_STATUS || ac_write_fail=1
+
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+  for (key in D) D_is_set[key] = 1
+  FS = ""
+}
+/^[\t ]*#[\t ]*(define|undef)[\t ]+$ac_word_re([\t (]|\$)/ {
+  line = \$ 0
+  split(line, arg, " ")
+  if (arg[1] == "#") {
+    defundef = arg[2]
+    mac1 = arg[3]
+  } else {
+    defundef = substr(arg[1], 2)
+    mac1 = arg[2]
+  }
+  split(mac1, mac2, "(") #)
+  macro = mac2[1]
+  prefix = substr(line, 1, index(line, defundef) - 1)
+  if (D_is_set[macro]) {
+    # Preserve the white space surrounding the "#".
+    print prefix "define", macro P[macro] D[macro]
+    next
+  } else {
+    # Replace #undef with comments.  This is necessary, for example,
+    # in the case of _POSIX_SOURCE, which is predefined and required
+    # on some systems where configure will not decide to define it.
+    if (defundef == "undef") {
+      print "/*", prefix defundef, macro, "*/"
+      next
+    }
+  }
+}
+{ print }
+_ACAWK
+_ACEOF
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+  { { $as_echo "$as_me:$LINENO: error: could not setup config headers machinery" >&5
+$as_echo "$as_me: error: could not setup config headers machinery" >&2;}
+   { (exit 1); exit 1; }; }
+fi # test -n "$CONFIG_HEADERS"
+
+
+eval set X "  :F $CONFIG_FILES  :H $CONFIG_HEADERS    :C $CONFIG_COMMANDS"
+shift
+for ac_tag
+do
+  case $ac_tag in
+  :[FHLC]) ac_mode=$ac_tag; continue;;
+  esac
+  case $ac_mode$ac_tag in
+  :[FHL]*:*);;
+  :L* | :C*:*) { { $as_echo "$as_me:$LINENO: error: invalid tag $ac_tag" >&5
+$as_echo "$as_me: error: invalid tag $ac_tag" >&2;}
+   { (exit 1); exit 1; }; };;
+  :[FH]-) ac_tag=-:-;;
+  :[FH]*) ac_tag=$ac_tag:$ac_tag.in;;
+  esac
+  ac_save_IFS=$IFS
+  IFS=:
+  set x $ac_tag
+  IFS=$ac_save_IFS
+  shift
+  ac_file=$1
+  shift
+
+  case $ac_mode in
+  :L) ac_source=$1;;
+  :[FH])
+    ac_file_inputs=
+    for ac_f
+    do
+      case $ac_f in
+      -) ac_f="$tmp/stdin";;
+      *) # Look for the file first in the build tree, then in the source tree
+	 # (if the path is not absolute).  The absolute path cannot be DOS-style,
+	 # because $ac_f cannot contain `:'.
+	 test -f "$ac_f" ||
+	   case $ac_f in
+	   [\\/$]*) false;;
+	   *) test -f "$srcdir/$ac_f" && ac_f="$srcdir/$ac_f";;
+	   esac ||
+	   { { $as_echo "$as_me:$LINENO: error: cannot find input file: $ac_f" >&5
+$as_echo "$as_me: error: cannot find input file: $ac_f" >&2;}
+   { (exit 1); exit 1; }; };;
+      esac
+      case $ac_f in *\'*) ac_f=`$as_echo "$ac_f" | sed "s/'/'\\\\\\\\''/g"`;; esac
+      ac_file_inputs="$ac_file_inputs '$ac_f'"
+    done
+
+    # Let's still pretend it is `configure' which instantiates (i.e., don't
+    # use $as_me), people would be surprised to read:
+    #    /* config.h.  Generated by config.status.  */
+    configure_input='Generated from '`
+	  $as_echo "$*" | sed 's|^[^:]*/||;s|:[^:]*/|, |g'
+	`' by configure.'
+    if test x"$ac_file" != x-; then
+      configure_input="$ac_file.  $configure_input"
+      { $as_echo "$as_me:$LINENO: creating $ac_file" >&5
+$as_echo "$as_me: creating $ac_file" >&6;}
+    fi
+    # Neutralize special characters interpreted by sed in replacement strings.
+    case $configure_input in #(
+    *\&* | *\|* | *\\* )
+       ac_sed_conf_input=`$as_echo "$configure_input" |
+       sed 's/[\\\\&|]/\\\\&/g'`;; #(
+    *) ac_sed_conf_input=$configure_input;;
+    esac
+
+    case $ac_tag in
+    *:-:* | *:-) cat >"$tmp/stdin" \
+      || { { $as_echo "$as_me:$LINENO: error: could not create $ac_file" >&5
+$as_echo "$as_me: error: could not create $ac_file" >&2;}
+   { (exit 1); exit 1; }; } ;;
+    esac
+    ;;
+  esac
+
+  ac_dir=`$as_dirname -- "$ac_file" ||
+$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	 X"$ac_file" : 'X\(//\)[^/]' \| \
+	 X"$ac_file" : 'X\(//\)$' \| \
+	 X"$ac_file" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X"$ac_file" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)[^/].*/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\).*/{
+	    s//\1/
+	    q
+	  }
+	  s/.*/./; q'`
+  { as_dir="$ac_dir"
+  case $as_dir in #(
+  -*) as_dir=./$as_dir;;
+  esac
+  test -d "$as_dir" || { $as_mkdir_p && mkdir -p "$as_dir"; } || {
+    as_dirs=
+    while :; do
+      case $as_dir in #(
+      *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'(
+      *) as_qdir=$as_dir;;
+      esac
+      as_dirs="'$as_qdir' $as_dirs"
+      as_dir=`$as_dirname -- "$as_dir" ||
+$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	 X"$as_dir" : 'X\(//\)[^/]' \| \
+	 X"$as_dir" : 'X\(//\)$' \| \
+	 X"$as_dir" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X"$as_dir" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)[^/].*/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\).*/{
+	    s//\1/
+	    q
+	  }
+	  s/.*/./; q'`
+      test -d "$as_dir" && break
+    done
+    test -z "$as_dirs" || eval "mkdir $as_dirs"
+  } || test -d "$as_dir" || { { $as_echo "$as_me:$LINENO: error: cannot create directory $as_dir" >&5
+$as_echo "$as_me: error: cannot create directory $as_dir" >&2;}
+   { (exit 1); exit 1; }; }; }
+  ac_builddir=.
+
+case "$ac_dir" in
+.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;;
+*)
+  ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'`
+  # A ".." for each directory in $ac_dir_suffix.
+  ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'`
+  case $ac_top_builddir_sub in
+  "") ac_top_builddir_sub=. ac_top_build_prefix= ;;
+  *)  ac_top_build_prefix=$ac_top_builddir_sub/ ;;
+  esac ;;
+esac
+ac_abs_top_builddir=$ac_pwd
+ac_abs_builddir=$ac_pwd$ac_dir_suffix
+# for backward compatibility:
+ac_top_builddir=$ac_top_build_prefix
+
+case $srcdir in
+  .)  # We are building in place.
+    ac_srcdir=.
+    ac_top_srcdir=$ac_top_builddir_sub
+    ac_abs_top_srcdir=$ac_pwd ;;
+  [\\/]* | ?:[\\/]* )  # Absolute name.
+    ac_srcdir=$srcdir$ac_dir_suffix;
+    ac_top_srcdir=$srcdir
+    ac_abs_top_srcdir=$srcdir ;;
+  *) # Relative name.
+    ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix
+    ac_top_srcdir=$ac_top_build_prefix$srcdir
+    ac_abs_top_srcdir=$ac_pwd/$srcdir ;;
+esac
+ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix
+
+
+  case $ac_mode in
+  :F)
+  #
+  # CONFIG_FILE
+  #
+
+  case $INSTALL in
+  [\\/$]* | ?:[\\/]* ) ac_INSTALL=$INSTALL ;;
+  *) ac_INSTALL=$ac_top_build_prefix$INSTALL ;;
+  esac
+  ac_MKDIR_P=$MKDIR_P
+  case $MKDIR_P in
+  [\\/$]* | ?:[\\/]* ) ;;
+  */*) ac_MKDIR_P=$ac_top_build_prefix$MKDIR_P ;;
+  esac
+_ACEOF
+
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+# If the template does not know about datarootdir, expand it.
+# FIXME: This hack should be removed a few years after 2.60.
+ac_datarootdir_hack=; ac_datarootdir_seen=
+
+ac_sed_dataroot='
+/datarootdir/ {
+  p
+  q
+}
+/@datadir@/p
+/@docdir@/p
+/@infodir@/p
+/@localedir@/p
+/@mandir@/p
+'
+case `eval "sed -n \"\$ac_sed_dataroot\" $ac_file_inputs"` in
+*datarootdir*) ac_datarootdir_seen=yes;;
+*@datadir@*|*@docdir@*|*@infodir@*|*@localedir@*|*@mandir@*)
+  { $as_echo "$as_me:$LINENO: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&5
+$as_echo "$as_me: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&2;}
+_ACEOF
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+  ac_datarootdir_hack='
+  s&@datadir@&$datadir&g
+  s&@docdir@&$docdir&g
+  s&@infodir@&$infodir&g
+  s&@localedir@&$localedir&g
+  s&@mandir@&$mandir&g
+    s&\\\${datarootdir}&$datarootdir&g' ;;
+esac
+_ACEOF
+
+# Neutralize VPATH when `$srcdir' = `.'.
+# Shell code in configure.ac might set extrasub.
+# FIXME: do we really want to maintain this feature?
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+ac_sed_extra="$ac_vpsub
+$extrasub
+_ACEOF
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+:t
+/@[a-zA-Z_][a-zA-Z_0-9]*@/!b
+s|@configure_input@|$ac_sed_conf_input|;t t
+s&@top_builddir@&$ac_top_builddir_sub&;t t
+s&@top_build_prefix@&$ac_top_build_prefix&;t t
+s&@srcdir@&$ac_srcdir&;t t
+s&@abs_srcdir@&$ac_abs_srcdir&;t t
+s&@top_srcdir@&$ac_top_srcdir&;t t
+s&@abs_top_srcdir@&$ac_abs_top_srcdir&;t t
+s&@builddir@&$ac_builddir&;t t
+s&@abs_builddir@&$ac_abs_builddir&;t t
+s&@abs_top_builddir@&$ac_abs_top_builddir&;t t
+s&@INSTALL@&$ac_INSTALL&;t t
+s&@MKDIR_P@&$ac_MKDIR_P&;t t
+$ac_datarootdir_hack
+"
+eval sed \"\$ac_sed_extra\" "$ac_file_inputs" | $AWK -f "$tmp/subs.awk" >$tmp/out \
+  || { { $as_echo "$as_me:$LINENO: error: could not create $ac_file" >&5
+$as_echo "$as_me: error: could not create $ac_file" >&2;}
+   { (exit 1); exit 1; }; }
+
+test -z "$ac_datarootdir_hack$ac_datarootdir_seen" &&
+  { ac_out=`sed -n '/\${datarootdir}/p' "$tmp/out"`; test -n "$ac_out"; } &&
+  { ac_out=`sed -n '/^[	 ]*datarootdir[	 ]*:*=/p' "$tmp/out"`; test -z "$ac_out"; } &&
+  { $as_echo "$as_me:$LINENO: WARNING: $ac_file contains a reference to the variable \`datarootdir'
+which seems to be undefined.  Please make sure it is defined." >&5
+$as_echo "$as_me: WARNING: $ac_file contains a reference to the variable \`datarootdir'
+which seems to be undefined.  Please make sure it is defined." >&2;}
+
+  rm -f "$tmp/stdin"
+  case $ac_file in
+  -) cat "$tmp/out" && rm -f "$tmp/out";;
+  *) rm -f "$ac_file" && mv "$tmp/out" "$ac_file";;
+  esac \
+  || { { $as_echo "$as_me:$LINENO: error: could not create $ac_file" >&5
+$as_echo "$as_me: error: could not create $ac_file" >&2;}
+   { (exit 1); exit 1; }; }
+ ;;
+  :H)
+  #
+  # CONFIG_HEADER
+  #
+  if test x"$ac_file" != x-; then
+    {
+      $as_echo "/* $configure_input  */" \
+      && eval '$AWK -f "$tmp/defines.awk"' "$ac_file_inputs"
+    } >"$tmp/config.h" \
+      || { { $as_echo "$as_me:$LINENO: error: could not create $ac_file" >&5
+$as_echo "$as_me: error: could not create $ac_file" >&2;}
+   { (exit 1); exit 1; }; }
+    if diff "$ac_file" "$tmp/config.h" >/dev/null 2>&1; then
+      { $as_echo "$as_me:$LINENO: $ac_file is unchanged" >&5
+$as_echo "$as_me: $ac_file is unchanged" >&6;}
+    else
+      rm -f "$ac_file"
+      mv "$tmp/config.h" "$ac_file" \
+	|| { { $as_echo "$as_me:$LINENO: error: could not create $ac_file" >&5
+$as_echo "$as_me: error: could not create $ac_file" >&2;}
+   { (exit 1); exit 1; }; }
+    fi
+  else
+    $as_echo "/* $configure_input  */" \
+      && eval '$AWK -f "$tmp/defines.awk"' "$ac_file_inputs" \
+      || { { $as_echo "$as_me:$LINENO: error: could not create -" >&5
+$as_echo "$as_me: error: could not create -" >&2;}
+   { (exit 1); exit 1; }; }
+  fi
+# Compute "$ac_file"'s index in $config_headers.
+_am_arg="$ac_file"
+_am_stamp_count=1
+for _am_header in $config_headers :; do
+  case $_am_header in
+    $_am_arg | $_am_arg:* )
+      break ;;
+    * )
+      _am_stamp_count=`expr $_am_stamp_count + 1` ;;
+  esac
+done
+echo "timestamp for $_am_arg" >`$as_dirname -- "$_am_arg" ||
+$as_expr X"$_am_arg" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	 X"$_am_arg" : 'X\(//\)[^/]' \| \
+	 X"$_am_arg" : 'X\(//\)$' \| \
+	 X"$_am_arg" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X"$_am_arg" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)[^/].*/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\).*/{
+	    s//\1/
+	    q
+	  }
+	  s/.*/./; q'`/stamp-h$_am_stamp_count
+ ;;
+
+  :C)  { $as_echo "$as_me:$LINENO: executing $ac_file commands" >&5
+$as_echo "$as_me: executing $ac_file commands" >&6;}
+ ;;
+  esac
+
+
+  case $ac_file$ac_mode in
+    "depfiles":C) test x"$AMDEP_TRUE" != x"" || {
+  # Autoconf 2.62 quotes --file arguments for eval, but not when files
+  # are listed without --file.  Let's play safe and only enable the eval
+  # if we detect the quoting.
+  case $CONFIG_FILES in
+  *\'*) eval set x "$CONFIG_FILES" ;;
+  *)   set x $CONFIG_FILES ;;
+  esac
+  shift
+  for mf
+  do
+    # Strip MF so we end up with the name of the file.
+    mf=`echo "$mf" | sed -e 's/:.*$//'`
+    # Check whether this is an Automake generated Makefile or not.
+    # We used to match only the files named `Makefile.in', but
+    # some people rename them; so instead we look at the file content.
+    # Grep'ing the first line is not enough: some people post-process
+    # each Makefile.in and add a new line on top of each file to say so.
+    # Grep'ing the whole file is not good either: AIX grep has a line
+    # limit of 2048, but all sed's we know have understand at least 4000.
+    if sed -n 's,^#.*generated by automake.*,X,p' "$mf" | grep X >/dev/null 2>&1; then
+      dirpart=`$as_dirname -- "$mf" ||
+$as_expr X"$mf" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	 X"$mf" : 'X\(//\)[^/]' \| \
+	 X"$mf" : 'X\(//\)$' \| \
+	 X"$mf" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X"$mf" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)[^/].*/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\).*/{
+	    s//\1/
+	    q
+	  }
+	  s/.*/./; q'`
+    else
+      continue
+    fi
+    # Extract the definition of DEPDIR, am__include, and am__quote
+    # from the Makefile without running `make'.
+    DEPDIR=`sed -n 's/^DEPDIR = //p' < "$mf"`
+    test -z "$DEPDIR" && continue
+    am__include=`sed -n 's/^am__include = //p' < "$mf"`
+    test -z "am__include" && continue
+    am__quote=`sed -n 's/^am__quote = //p' < "$mf"`
+    # When using ansi2knr, U may be empty or an underscore; expand it
+    U=`sed -n 's/^U = //p' < "$mf"`
+    # Find all dependency output files, they are included files with
+    # $(DEPDIR) in their names.  We invoke sed twice because it is the
+    # simplest approach to changing $(DEPDIR) to its actual value in the
+    # expansion.
+    for file in `sed -n "
+      s/^$am__include $am__quote\(.*(DEPDIR).*\)$am__quote"'$/\1/p' <"$mf" | \
+	 sed -e 's/\$(DEPDIR)/'"$DEPDIR"'/g' -e 's/\$U/'"$U"'/g'`; do
+      # Make sure the directory exists.
+      test -f "$dirpart/$file" && continue
+      fdir=`$as_dirname -- "$file" ||
+$as_expr X"$file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	 X"$file" : 'X\(//\)[^/]' \| \
+	 X"$file" : 'X\(//\)$' \| \
+	 X"$file" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X"$file" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)[^/].*/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\).*/{
+	    s//\1/
+	    q
+	  }
+	  s/.*/./; q'`
+      { as_dir=$dirpart/$fdir
+  case $as_dir in #(
+  -*) as_dir=./$as_dir;;
+  esac
+  test -d "$as_dir" || { $as_mkdir_p && mkdir -p "$as_dir"; } || {
+    as_dirs=
+    while :; do
+      case $as_dir in #(
+      *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'(
+      *) as_qdir=$as_dir;;
+      esac
+      as_dirs="'$as_qdir' $as_dirs"
+      as_dir=`$as_dirname -- "$as_dir" ||
+$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	 X"$as_dir" : 'X\(//\)[^/]' \| \
+	 X"$as_dir" : 'X\(//\)$' \| \
+	 X"$as_dir" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X"$as_dir" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)[^/].*/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\).*/{
+	    s//\1/
+	    q
+	  }
+	  s/.*/./; q'`
+      test -d "$as_dir" && break
+    done
+    test -z "$as_dirs" || eval "mkdir $as_dirs"
+  } || test -d "$as_dir" || { { $as_echo "$as_me:$LINENO: error: cannot create directory $as_dir" >&5
+$as_echo "$as_me: error: cannot create directory $as_dir" >&2;}
+   { (exit 1); exit 1; }; }; }
+      # echo "creating $dirpart/$file"
+      echo '# dummy' > "$dirpart/$file"
+    done
+  done
+}
+ ;;
+    "libtool":C)
+
+    # See if we are running on zsh, and set the options which allow our
+    # commands through without removal of \ escapes.
+    if test -n "${ZSH_VERSION+set}" ; then
+      setopt NO_GLOB_SUBST
+    fi
+
+    cfgfile="${ofile}T"
+    trap "$RM \"$cfgfile\"; exit 1" 1 2 15
+    $RM "$cfgfile"
+
+    cat <<_LT_EOF >> "$cfgfile"
+#! $SHELL
+
+# `$ECHO "$ofile" | sed 's%^.*/%%'` - Provide generalized library-building support services.
+# Generated automatically by $as_me ($PACKAGE$TIMESTAMP) $VERSION
+# Libtool was configured on host `(hostname || uname -n) 2>/dev/null | sed 1q`:
+# NOTE: Changes made to this file will be lost: look at ltmain.sh.
+#
+#   Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005,
+#                 2006, 2007, 2008 Free Software Foundation, Inc.
+#   Written by Gordon Matzigkeit, 1996
+#
+#   This file is part of GNU Libtool.
+#
+# GNU Libtool is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of
+# the License, or (at your option) any later version.
+#
+# As a special exception to the GNU General Public License,
+# if you distribute this file as part of a program or library that
+# is built using GNU Libtool, you may include this file under the
+# same distribution terms that you use for the rest of that program.
+#
+# GNU Libtool is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Libtool; see the file COPYING.  If not, a copy
+# can be downloaded from http://www.gnu.org/licenses/gpl.html, or
+# obtained by writing to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+
+# The names of the tagged configurations supported by this script.
+available_tags=""
+
+# ### BEGIN LIBTOOL CONFIG
+
+# Whether or not to build static libraries.
+build_old_libs=$enable_static
+
+# Whether or not to build shared libraries.
+build_libtool_libs=$enable_shared
+
+# Which release of libtool.m4 was used?
+macro_version=$macro_version
+macro_revision=$macro_revision
+
+# What type of objects to build.
+pic_mode=$pic_mode
+
+# Whether or not to optimize for fast installation.
+fast_install=$enable_fast_install
+
+# The host system.
+host_alias=$host_alias
+host=$host
+host_os=$host_os
+
+# The build system.
+build_alias=$build_alias
+build=$build
+build_os=$build_os
+
+# A sed program that does not truncate output.
+SED=$lt_SED
+
+# Sed that helps us avoid accidentally triggering echo(1) options like -n.
+Xsed="\$SED -e 1s/^X//"
+
+# A grep program that handles long lines.
+GREP=$lt_GREP
+
+# An ERE matcher.
+EGREP=$lt_EGREP
+
+# A literal string matcher.
+FGREP=$lt_FGREP
+
+# A BSD- or MS-compatible name lister.
+NM=$lt_NM
+
+# Whether we need soft or hard links.
+LN_S=$lt_LN_S
+
+# What is the maximum length of a command?
+max_cmd_len=$max_cmd_len
+
+# Object file suffix (normally "o").
+objext=$ac_objext
+
+# Executable file suffix (normally "").
+exeext=$exeext
+
+# whether the shell understands "unset".
+lt_unset=$lt_unset
+
+# turn spaces into newlines.
+SP2NL=$lt_lt_SP2NL
+
+# turn newlines into spaces.
+NL2SP=$lt_lt_NL2SP
+
+# How to create reloadable object files.
+reload_flag=$lt_reload_flag
+reload_cmds=$lt_reload_cmds
+
+# An object symbol dumper.
+OBJDUMP=$lt_OBJDUMP
+
+# Method to check whether dependent libraries are shared objects.
+deplibs_check_method=$lt_deplibs_check_method
+
+# Command to use when deplibs_check_method == "file_magic".
+file_magic_cmd=$lt_file_magic_cmd
+
+# The archiver.
+AR=$lt_AR
+AR_FLAGS=$lt_AR_FLAGS
+
+# A symbol stripping program.
+STRIP=$lt_STRIP
+
+# Commands used to install an old-style archive.
+RANLIB=$lt_RANLIB
+old_postinstall_cmds=$lt_old_postinstall_cmds
+old_postuninstall_cmds=$lt_old_postuninstall_cmds
+
+# A C compiler.
+LTCC=$lt_CC
+
+# LTCC compiler flags.
+LTCFLAGS=$lt_CFLAGS
+
+# Take the output of nm and produce a listing of raw symbols and C names.
+global_symbol_pipe=$lt_lt_cv_sys_global_symbol_pipe
+
+# Transform the output of nm in a proper C declaration.
+global_symbol_to_cdecl=$lt_lt_cv_sys_global_symbol_to_cdecl
+
+# Transform the output of nm in a C name address pair.
+global_symbol_to_c_name_address=$lt_lt_cv_sys_global_symbol_to_c_name_address
+
+# Transform the output of nm in a C name address pair when lib prefix is needed.
+global_symbol_to_c_name_address_lib_prefix=$lt_lt_cv_sys_global_symbol_to_c_name_address_lib_prefix
+
+# The name of the directory that contains temporary libtool files.
+objdir=$objdir
+
+# Shell to use when invoking shell scripts.
+SHELL=$lt_SHELL
+
+# An echo program that does not interpret backslashes.
+ECHO=$lt_ECHO
+
+# Used to examine libraries when file_magic_cmd begins with "file".
+MAGIC_CMD=$MAGIC_CMD
+
+# Must we lock files when doing compilation?
+need_locks=$lt_need_locks
+
+# Tool to manipulate archived DWARF debug symbol files on Mac OS X.
+DSYMUTIL=$lt_DSYMUTIL
+
+# Tool to change global to local symbols on Mac OS X.
+NMEDIT=$lt_NMEDIT
+
+# Tool to manipulate fat objects and archives on Mac OS X.
+LIPO=$lt_LIPO
+
+# ldd/readelf like tool for Mach-O binaries on Mac OS X.
+OTOOL=$lt_OTOOL
+
+# ldd/readelf like tool for 64 bit Mach-O binaries on Mac OS X 10.4.
+OTOOL64=$lt_OTOOL64
+
+# Old archive suffix (normally "a").
+libext=$libext
+
+# Shared library suffix (normally ".so").
+shrext_cmds=$lt_shrext_cmds
+
+# The commands to extract the exported symbol list from a shared archive.
+extract_expsyms_cmds=$lt_extract_expsyms_cmds
+
+# Variables whose values should be saved in libtool wrapper scripts and
+# restored at link time.
+variables_saved_for_relink=$lt_variables_saved_for_relink
+
+# Do we need the "lib" prefix for modules?
+need_lib_prefix=$need_lib_prefix
+
+# Do we need a version for libraries?
+need_version=$need_version
+
+# Library versioning type.
+version_type=$version_type
+
+# Shared library runtime path variable.
+runpath_var=$runpath_var
+
+# Shared library path variable.
+shlibpath_var=$shlibpath_var
+
+# Is shlibpath searched before the hard-coded library search path?
+shlibpath_overrides_runpath=$shlibpath_overrides_runpath
+
+# Format of library name prefix.
+libname_spec=$lt_libname_spec
+
+# List of archive names.  First name is the real one, the rest are links.
+# The last name is the one that the linker finds with -lNAME
+library_names_spec=$lt_library_names_spec
+
+# The coded name of the library, if different from the real name.
+soname_spec=$lt_soname_spec
+
+# Command to use after installation of a shared archive.
+postinstall_cmds=$lt_postinstall_cmds
+
+# Command to use after uninstallation of a shared archive.
+postuninstall_cmds=$lt_postuninstall_cmds
+
+# Commands used to finish a libtool library installation in a directory.
+finish_cmds=$lt_finish_cmds
+
+# As "finish_cmds", except a single script fragment to be evaled but
+# not shown.
+finish_eval=$lt_finish_eval
+
+# Whether we should hardcode library paths into libraries.
+hardcode_into_libs=$hardcode_into_libs
+
+# Compile-time system search path for libraries.
+sys_lib_search_path_spec=$lt_sys_lib_search_path_spec
+
+# Run-time system search path for libraries.
+sys_lib_dlsearch_path_spec=$lt_sys_lib_dlsearch_path_spec
+
+# Whether dlopen is supported.
+dlopen_support=$enable_dlopen
+
+# Whether dlopen of programs is supported.
+dlopen_self=$enable_dlopen_self
+
+# Whether dlopen of statically linked programs is supported.
+dlopen_self_static=$enable_dlopen_self_static
+
+# Commands to strip libraries.
+old_striplib=$lt_old_striplib
+striplib=$lt_striplib
+
+
+# The linker used to build libraries.
+LD=$lt_LD
+
+# Commands used to build an old-style archive.
+old_archive_cmds=$lt_old_archive_cmds
+
+# A language specific compiler.
+CC=$lt_compiler
+
+# Is the compiler the GNU compiler?
+with_gcc=$GCC
+
+# Compiler flag to turn off builtin functions.
+no_builtin_flag=$lt_lt_prog_compiler_no_builtin_flag
+
+# How to pass a linker flag through the compiler.
+wl=$lt_lt_prog_compiler_wl
+
+# Additional compiler flags for building library objects.
+pic_flag=$lt_lt_prog_compiler_pic
+
+# Compiler flag to prevent dynamic linking.
+link_static_flag=$lt_lt_prog_compiler_static
+
+# Does compiler simultaneously support -c and -o options?
+compiler_c_o=$lt_lt_cv_prog_compiler_c_o
+
+# Whether or not to add -lc for building shared libraries.
+build_libtool_need_lc=$archive_cmds_need_lc
+
+# Whether or not to disallow shared libs when runtime libs are static.
+allow_libtool_libs_with_static_runtimes=$enable_shared_with_static_runtimes
+
+# Compiler flag to allow reflexive dlopens.
+export_dynamic_flag_spec=$lt_export_dynamic_flag_spec
+
+# Compiler flag to generate shared objects directly from archives.
+whole_archive_flag_spec=$lt_whole_archive_flag_spec
+
+# Whether the compiler copes with passing no objects directly.
+compiler_needs_object=$lt_compiler_needs_object
+
+# Create an old-style archive from a shared archive.
+old_archive_from_new_cmds=$lt_old_archive_from_new_cmds
+
+# Create a temporary old-style archive to link instead of a shared archive.
+old_archive_from_expsyms_cmds=$lt_old_archive_from_expsyms_cmds
+
+# Commands used to build a shared archive.
+archive_cmds=$lt_archive_cmds
+archive_expsym_cmds=$lt_archive_expsym_cmds
+
+# Commands used to build a loadable module if different from building
+# a shared archive.
+module_cmds=$lt_module_cmds
+module_expsym_cmds=$lt_module_expsym_cmds
+
+# Whether we are building with GNU ld or not.
+with_gnu_ld=$lt_with_gnu_ld
+
+# Flag that allows shared libraries with undefined symbols to be built.
+allow_undefined_flag=$lt_allow_undefined_flag
+
+# Flag that enforces no undefined symbols.
+no_undefined_flag=$lt_no_undefined_flag
+
+# Flag to hardcode \$libdir into a binary during linking.
+# This must work even if \$libdir does not exist
+hardcode_libdir_flag_spec=$lt_hardcode_libdir_flag_spec
+
+# If ld is used when linking, flag to hardcode \$libdir into a binary
+# during linking.  This must work even if \$libdir does not exist.
+hardcode_libdir_flag_spec_ld=$lt_hardcode_libdir_flag_spec_ld
+
+# Whether we need a single "-rpath" flag with a separated argument.
+hardcode_libdir_separator=$lt_hardcode_libdir_separator
+
+# Set to "yes" if using DIR/libNAME\${shared_ext} during linking hardcodes
+# DIR into the resulting binary.
+hardcode_direct=$hardcode_direct
+
+# Set to "yes" if using DIR/libNAME\${shared_ext} during linking hardcodes
+# DIR into the resulting binary and the resulting library dependency is
+# "absolute",i.e impossible to change by setting \${shlibpath_var} if the
+# library is relocated.
+hardcode_direct_absolute=$hardcode_direct_absolute
+
+# Set to "yes" if using the -LDIR flag during linking hardcodes DIR
+# into the resulting binary.
+hardcode_minus_L=$hardcode_minus_L
+
+# Set to "yes" if using SHLIBPATH_VAR=DIR during linking hardcodes DIR
+# into the resulting binary.
+hardcode_shlibpath_var=$hardcode_shlibpath_var
+
+# Set to "yes" if building a shared library automatically hardcodes DIR
+# into the library and all subsequent libraries and executables linked
+# against it.
+hardcode_automatic=$hardcode_automatic
+
+# Set to yes if linker adds runtime paths of dependent libraries
+# to runtime path list.
+inherit_rpath=$inherit_rpath
+
+# Whether libtool must link a program against all its dependency libraries.
+link_all_deplibs=$link_all_deplibs
+
+# Fix the shell variable \$srcfile for the compiler.
+fix_srcfile_path=$lt_fix_srcfile_path
+
+# Set to "yes" if exported symbols are required.
+always_export_symbols=$always_export_symbols
+
+# The commands to list exported symbols.
+export_symbols_cmds=$lt_export_symbols_cmds
+
+# Symbols that should not be listed in the preloaded symbols.
+exclude_expsyms=$lt_exclude_expsyms
+
+# Symbols that must always be exported.
+include_expsyms=$lt_include_expsyms
+
+# Commands necessary for linking programs (against libraries) with templates.
+prelink_cmds=$lt_prelink_cmds
+
+# Specify filename containing input files.
+file_list_spec=$lt_file_list_spec
+
+# How to hardcode a shared library path into an executable.
+hardcode_action=$hardcode_action
+
+# ### END LIBTOOL CONFIG
+
+_LT_EOF
+
+  case $host_os in
+  aix3*)
+    cat <<\_LT_EOF >> "$cfgfile"
+# AIX sometimes has problems with the GCC collect2 program.  For some
+# reason, if we set the COLLECT_NAMES environment variable, the problems
+# vanish in a puff of smoke.
+if test "X${COLLECT_NAMES+set}" != Xset; then
+  COLLECT_NAMES=
+  export COLLECT_NAMES
+fi
+_LT_EOF
+    ;;
+  esac
+
+
+ltmain="$ac_aux_dir/ltmain.sh"
+
+
+  # We use sed instead of cat because bash on DJGPP gets confused if
+  # if finds mixed CR/LF and LF-only lines.  Since sed operates in
+  # text mode, it properly converts lines to CR/LF.  This bash problem
+  # is reportedly fixed, but why not run on old versions too?
+  sed '/^# Generated shell functions inserted here/q' "$ltmain" >> "$cfgfile" \
+    || (rm -f "$cfgfile"; exit 1)
+
+  case $xsi_shell in
+  yes)
+    cat << \_LT_EOF >> "$cfgfile"
+
+# func_dirname file append nondir_replacement
+# Compute the dirname of FILE.  If nonempty, add APPEND to the result,
+# otherwise set result to NONDIR_REPLACEMENT.
+func_dirname ()
+{
+  case ${1} in
+    */*) func_dirname_result="${1%/*}${2}" ;;
+    *  ) func_dirname_result="${3}" ;;
+  esac
+}
+
+# func_basename file
+func_basename ()
+{
+  func_basename_result="${1##*/}"
+}
+
+# func_dirname_and_basename file append nondir_replacement
+# perform func_basename and func_dirname in a single function
+# call:
+#   dirname:  Compute the dirname of FILE.  If nonempty,
+#             add APPEND to the result, otherwise set result
+#             to NONDIR_REPLACEMENT.
+#             value returned in "$func_dirname_result"
+#   basename: Compute filename of FILE.
+#             value retuned in "$func_basename_result"
+# Implementation must be kept synchronized with func_dirname
+# and func_basename. For efficiency, we do not delegate to
+# those functions but instead duplicate the functionality here.
+func_dirname_and_basename ()
+{
+  case ${1} in
+    */*) func_dirname_result="${1%/*}${2}" ;;
+    *  ) func_dirname_result="${3}" ;;
+  esac
+  func_basename_result="${1##*/}"
+}
+
+# func_stripname prefix suffix name
+# strip PREFIX and SUFFIX off of NAME.
+# PREFIX and SUFFIX must not contain globbing or regex special
+# characters, hashes, percent signs, but SUFFIX may contain a leading
+# dot (in which case that matches only a dot).
+func_stripname ()
+{
+  # pdksh 5.2.14 does not do ${X%$Y} correctly if both X and Y are
+  # positional parameters, so assign one to ordinary parameter first.
+  func_stripname_result=${3}
+  func_stripname_result=${func_stripname_result#"${1}"}
+  func_stripname_result=${func_stripname_result%"${2}"}
+}
+
+# func_opt_split
+func_opt_split ()
+{
+  func_opt_split_opt=${1%%=*}
+  func_opt_split_arg=${1#*=}
+}
+
+# func_lo2o object
+func_lo2o ()
+{
+  case ${1} in
+    *.lo) func_lo2o_result=${1%.lo}.${objext} ;;
+    *)    func_lo2o_result=${1} ;;
+  esac
+}
+
+# func_xform libobj-or-source
+func_xform ()
+{
+  func_xform_result=${1%.*}.lo
+}
+
+# func_arith arithmetic-term...
+func_arith ()
+{
+  func_arith_result=$(( $* ))
+}
+
+# func_len string
+# STRING may not start with a hyphen.
+func_len ()
+{
+  func_len_result=${#1}
+}
+
+_LT_EOF
+    ;;
+  *) # Bourne compatible functions.
+    cat << \_LT_EOF >> "$cfgfile"
+
+# func_dirname file append nondir_replacement
+# Compute the dirname of FILE.  If nonempty, add APPEND to the result,
+# otherwise set result to NONDIR_REPLACEMENT.
+func_dirname ()
+{
+  # Extract subdirectory from the argument.
+  func_dirname_result=`$ECHO "X${1}" | $Xsed -e "$dirname"`
+  if test "X$func_dirname_result" = "X${1}"; then
+    func_dirname_result="${3}"
+  else
+    func_dirname_result="$func_dirname_result${2}"
+  fi
+}
+
+# func_basename file
+func_basename ()
+{
+  func_basename_result=`$ECHO "X${1}" | $Xsed -e "$basename"`
+}
+
+
+# func_stripname prefix suffix name
+# strip PREFIX and SUFFIX off of NAME.
+# PREFIX and SUFFIX must not contain globbing or regex special
+# characters, hashes, percent signs, but SUFFIX may contain a leading
+# dot (in which case that matches only a dot).
+# func_strip_suffix prefix name
+func_stripname ()
+{
+  case ${2} in
+    .*) func_stripname_result=`$ECHO "X${3}" \
+           | $Xsed -e "s%^${1}%%" -e "s%\\\\${2}\$%%"`;;
+    *)  func_stripname_result=`$ECHO "X${3}" \
+           | $Xsed -e "s%^${1}%%" -e "s%${2}\$%%"`;;
+  esac
+}
+
+# sed scripts:
+my_sed_long_opt='1s/^\(-[^=]*\)=.*/\1/;q'
+my_sed_long_arg='1s/^-[^=]*=//'
+
+# func_opt_split
+func_opt_split ()
+{
+  func_opt_split_opt=`$ECHO "X${1}" | $Xsed -e "$my_sed_long_opt"`
+  func_opt_split_arg=`$ECHO "X${1}" | $Xsed -e "$my_sed_long_arg"`
+}
+
+# func_lo2o object
+func_lo2o ()
+{
+  func_lo2o_result=`$ECHO "X${1}" | $Xsed -e "$lo2o"`
+}
+
+# func_xform libobj-or-source
+func_xform ()
+{
+  func_xform_result=`$ECHO "X${1}" | $Xsed -e 's/\.[^.]*$/.lo/'`
+}
+
+# func_arith arithmetic-term...
+func_arith ()
+{
+  func_arith_result=`expr "$@"`
+}
+
+# func_len string
+# STRING may not start with a hyphen.
+func_len ()
+{
+  func_len_result=`expr "$1" : ".*" 2>/dev/null || echo $max_cmd_len`
+}
+
+_LT_EOF
+esac
+
+case $lt_shell_append in
+  yes)
+    cat << \_LT_EOF >> "$cfgfile"
+
+# func_append var value
+# Append VALUE to the end of shell variable VAR.
+func_append ()
+{
+  eval "$1+=\$2"
+}
+_LT_EOF
+    ;;
+  *)
+    cat << \_LT_EOF >> "$cfgfile"
+
+# func_append var value
+# Append VALUE to the end of shell variable VAR.
+func_append ()
+{
+  eval "$1=\$$1\$2"
+}
+
+_LT_EOF
+    ;;
+  esac
+
+
+  sed -n '/^# Generated shell functions inserted here/,$p' "$ltmain" >> "$cfgfile" \
+    || (rm -f "$cfgfile"; exit 1)
+
+  mv -f "$cfgfile" "$ofile" ||
+    (rm -f "$ofile" && cp "$cfgfile" "$ofile" && rm -f "$cfgfile")
+  chmod +x "$ofile"
+
+ ;;
+
+  esac
+done # for ac_tag
+
+
+{ (exit 0); exit 0; }
+_ACEOF
+chmod +x $CONFIG_STATUS
+ac_clean_files=$ac_clean_files_save
+
+test $ac_write_fail = 0 ||
+  { { $as_echo "$as_me:$LINENO: error: write failure creating $CONFIG_STATUS" >&5
+$as_echo "$as_me: error: write failure creating $CONFIG_STATUS" >&2;}
+   { (exit 1); exit 1; }; }
+
+
+# configure is writing to config.log, and then calls config.status.
+# config.status does its own redirection, appending to config.log.
+# Unfortunately, on DOS this fails, as config.log is still kept open
+# by configure, so config.status won't be able to write to it; its
+# output is simply discarded.  So we exec the FD to /dev/null,
+# effectively closing config.log, so it can be properly (re)opened and
+# appended to by config.status.  When coming back to configure, we
+# need to make the FD available again.
+if test "$no_create" != yes; then
+  ac_cs_success=:
+  ac_config_status_args=
+  test "$silent" = yes &&
+    ac_config_status_args="$ac_config_status_args --quiet"
+  exec 5>/dev/null
+  $SHELL $CONFIG_STATUS $ac_config_status_args || ac_cs_success=false
+  exec 5>>config.log
+  # Use ||, not &&, to avoid exiting from the if with $? = 1, which
+  # would make configure fail if this is the last instruction.
+  $ac_cs_success || { (exit 1); exit 1; }
+fi
+if test -n "$ac_unrecognized_opts" && test "$enable_option_checking" != no; then
+  { $as_echo "$as_me:$LINENO: WARNING: unrecognized options: $ac_unrecognized_opts" >&5
+$as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;}
+fi
+
diff --git a/configure.ac b/configure.ac
new file mode 100644
index 0000000..8c8a5bd
--- /dev/null
+++ b/configure.ac
@@ -0,0 +1,108 @@
+# Process this file with autoconf to produce a configure script.
+
+AC_INIT([SINFONI Instrument Pipeline], [2.3.2], [amodigli at eso.org], [sinfo])
+
+AC_PREREQ([2.59])
+
+AC_CONFIG_SRCDIR([Makefile.am])
+AC_CONFIG_AUX_DIR([admin])
+
+AC_CANONICAL_HOST
+AC_CANONICAL_TARGET
+
+AM_INIT_AUTOMAKE
+AM_CONFIG_HEADER([config.h])
+
+AM_MAINTAINER_MODE
+
+SINFONI_SET_PREFIX(${PIPE_HOME:-/usr/local})
+
+# Immediately before every release do:
+#-------------------------------------
+#   if (the interface is totally unchanged from previous release)
+#       REVISION++;
+#   else {
+#       /* interfaces have been added, removed or changed */
+#       REVISION = 0;
+#       CURRENT++;
+#       if (any interfaces have been _added_ since last release)
+#           AGE++;
+#       if (any interfaces have been _removed_ or incompatibly changed)
+#           AGE = 0;
+#   }
+
+SINFONI_SET_VERSION_INFO([$VERSION])
+
+# Checks for programs.
+AC_PROG_CC
+AC_ISC_POSIX
+AC_PROG_CPP
+AM_PROG_CC_C_O
+AC_PROG_LN_S
+
+ESO_ENABLE_DEBUG(no)
+ESO_ENABLE_STRICT(no)
+ESO_PROG_CC_FLAG([fno-builtin], [CFLAGS="$CFLAGS -fno-builtin"])
+ESO_PROG_CC_FLAG([std=c99], [CFLAGS="$CFLAGS -std=c99"])
+ESO_CHECK_DOCTOOLS
+
+AC_ENABLE_STATIC(no)
+AC_ENABLE_SHARED(yes)
+
+AC_PROG_LIBTOOL
+AC_SUBST(LIBTOOL_DEPS)
+
+# Checks for libraries.
+AC_CHECK_LIB(m, pow, [LIBS="$LIBS -lm"])
+AC_CHECK_LIB(socket, socket, [LIBS="$LIBS -lsocket"])
+AC_CHECK_LIB(nsl, inet_ntoa, [LIBS="$LIBS -lnsl"])
+#LIB_CHECK_FFTW
+
+# Checks for header files.
+AC_HEADER_STDC
+AC_CHECK_HEADERS([string.h])
+
+# Checks for typedefs, structures, and compiler characteristics.
+AC_C_CONST
+AC_C_INLINE
+
+# Checks for library functions.
+AC_CHECK_FUNCS([sin cos floor pow sqrt])
+ESO_FUNC_STRDUP
+
+# Check for CPL/Qfits presence and usability
+CPL_CHECK_CEXT
+CPL_CHECK_LIBS
+
+# Check for Purify
+CHECK_PURIFY
+ESO_ENABLE_PROFILE(no)
+
+# Check for a function which exists only in CPL 3.1 or later
+LDFLAGS="$LDFLAGS $CPL_LDFLAGS"
+AC_CHECK_LIB(cplcore, cpl_image_get_bpm,
+                      AC_DEFINE([HAVE_CPL31], 1, [Define to 1 if you have CPL version 3.1 or later]),
+                      AC_DEFINE([HAVE_CPL31], 0, [Define to 1 if you have CPL version 3.1 or later]))
+
+
+# Check for __func__, popen(), pclose()
+AC_CHECK_DECLS([__func__, popen, pclose])
+
+SINFONI_SET_PATHS
+SINFONI_CREATE_SYMBOLS
+
+AM_WITH_DMALLOC
+
+
+AC_CONFIG_FILES(Makefile
+                Makefile.purify
+                doxygen/Doxyfile
+                irplib/Makefile
+                irplib/tests/Makefile
+                sinfoni/Makefile
+                sinfoni/tests/Makefile
+                recipes/Makefile
+                recipes/tests/Makefile
+                regtests/Makefile
+                regtests/tests/Makefile)
+AC_OUTPUT
diff --git a/doxygen/Doxyfile.in b/doxygen/Doxyfile.in
new file mode 100644
index 0000000..a9e048f
--- /dev/null
+++ b/doxygen/Doxyfile.in
@@ -0,0 +1,197 @@
+# @configure_input@
+# Doxyfile 1.2.15
+
+#---------------------------------------------------------------------------
+# General configuration options
+#---------------------------------------------------------------------------
+PROJECT_NAME           = "SINFONI Pipeline Reference Manual"
+PROJECT_NUMBER         = @VERSION@
+OUTPUT_DIRECTORY       = ..
+OUTPUT_LANGUAGE        = English
+EXTRACT_ALL            = NO
+EXTRACT_PRIVATE        = NO
+EXTRACT_STATIC         = NO
+EXTRACT_LOCAL_CLASSES  = NO
+HIDE_UNDOC_MEMBERS     = YES
+HIDE_UNDOC_CLASSES     = YES
+BRIEF_MEMBER_DESC      = YES
+REPEAT_BRIEF           = YES
+ALWAYS_DETAILED_SEC    = NO
+INLINE_INHERITED_MEMB  = NO
+FULL_PATH_NAMES        = NO
+STRIP_FROM_PATH        = 
+INTERNAL_DOCS          = NO
+STRIP_CODE_COMMENTS    = YES
+CASE_SENSE_NAMES       = YES
+SHORT_NAMES            = NO
+HIDE_SCOPE_NAMES       = NO
+VERBATIM_HEADERS       = YES
+SHOW_INCLUDE_FILES     = YES
+JAVADOC_AUTOBRIEF      = NO
+INHERIT_DOCS           = YES
+INLINE_INFO            = NO
+SORT_MEMBER_DOCS       = YES
+DISTRIBUTE_GROUP_DOC   = NO
+TAB_SIZE               = 4
+GENERATE_TODOLIST      = NO
+GENERATE_TESTLIST      = NO
+GENERATE_BUGLIST       = YES
+ALIASES                = 
+ENABLED_SECTIONS       = 
+MAX_INITIALIZER_LINES  = 30
+OPTIMIZE_OUTPUT_FOR_C  = YES
+SHOW_USED_FILES        = YES
+
+#---------------------------------------------------------------------------
+# configuration options related to warning and progress messages
+#---------------------------------------------------------------------------
+QUIET                  = NO
+WARNINGS               = YES
+WARN_IF_UNDOCUMENTED   = NO
+WARN_FORMAT            = 
+WARN_LOGFILE           = 
+
+#---------------------------------------------------------------------------
+# configuration options related to the input files
+#---------------------------------------------------------------------------
+INPUT                  = ../sinfoni ../recipes ../irplib
+FILE_PATTERNS          = *.h \
+                         *.c \
+                         *.cpp
+RECURSIVE              = YES
+EXCLUDE                =
+EXCLUDE_PATTERNS       = */CVS/* \
+                         */test/* \ 
+                         */tests/* \ 
+                         */irplib_irlist.h
+EXAMPLE_PATH           = 
+EXAMPLE_PATTERNS       = 
+EXAMPLE_RECURSIVE      = NO
+IMAGE_PATH             = 
+INPUT_FILTER           = 
+FILTER_SOURCE_FILES    = NO
+
+#---------------------------------------------------------------------------
+# configuration options related to source browsing
+#---------------------------------------------------------------------------
+SOURCE_BROWSER         = YES
+INLINE_SOURCES         = NO
+REFERENCED_BY_RELATION = YES
+REFERENCES_RELATION    = YES
+
+#---------------------------------------------------------------------------
+# configuration options related to the alphabetical class index
+#---------------------------------------------------------------------------
+ALPHABETICAL_INDEX     = YES
+COLS_IN_ALPHA_INDEX    = 3
+IGNORE_PREFIX          = 
+
+#---------------------------------------------------------------------------
+# configuration options related to the HTML output
+#---------------------------------------------------------------------------
+GENERATE_HTML          = YES
+HTML_OUTPUT            = html
+HTML_HEADER            = 
+HTML_FOOTER            = 
+HTML_STYLESHEET        = 
+HTML_ALIGN_MEMBERS     = YES
+GENERATE_HTMLHELP      = NO
+GENERATE_CHI           = NO
+BINARY_TOC             = NO
+TOC_EXPAND             = NO
+DISABLE_INDEX          = YES
+ENUM_VALUES_PER_LINE   = 4
+GENERATE_TREEVIEW      = NO
+TREEVIEW_WIDTH         = 250
+
+#---------------------------------------------------------------------------
+# configuration options related to the LaTeX output
+#---------------------------------------------------------------------------
+GENERATE_LATEX         = NO
+LATEX_OUTPUT           = latex
+COMPACT_LATEX          = NO
+PAPER_TYPE             = a4wide
+EXTRA_PACKAGES         = 
+LATEX_HEADER           = 
+PDF_HYPERLINKS         = NO
+USE_PDFLATEX           = NO
+LATEX_BATCHMODE        = NO
+
+#---------------------------------------------------------------------------
+# configuration options related to the RTF output
+#---------------------------------------------------------------------------
+GENERATE_RTF           = NO
+RTF_OUTPUT             = rtf
+COMPACT_RTF            = NO
+RTF_HYPERLINKS         = NO
+RTF_STYLESHEET_FILE    = 
+RTF_EXTENSIONS_FILE    = 
+
+#---------------------------------------------------------------------------
+# configuration options related to the man page output
+#---------------------------------------------------------------------------
+GENERATE_MAN           = NO
+MAN_OUTPUT             = man
+MAN_EXTENSION          = 
+MAN_LINKS              = NO
+
+#---------------------------------------------------------------------------
+# configuration options related to the XML output
+#---------------------------------------------------------------------------
+GENERATE_XML           = NO
+
+#---------------------------------------------------------------------------
+# configuration options for the AutoGen Definitions output
+#---------------------------------------------------------------------------
+GENERATE_AUTOGEN_DEF   = NO
+
+#---------------------------------------------------------------------------
+# Configuration options related to the preprocessor   
+#---------------------------------------------------------------------------
+ENABLE_PREPROCESSING   = YES
+MACRO_EXPANSION        = NO
+EXPAND_ONLY_PREDEF     = NO
+SEARCH_INCLUDES        = YES
+INCLUDE_PATH           = 
+INCLUDE_FILE_PATTERNS  = 
+PREDEFINED             = 
+EXPAND_AS_DEFINED      = 
+SKIP_FUNCTION_MACROS   = YES
+
+#---------------------------------------------------------------------------
+# Configuration::addtions related to external references   
+#---------------------------------------------------------------------------
+TAGFILES               = 
+GENERATE_TAGFILE       = 
+ALLEXTERNALS           = NO
+PERL_PATH              = 
+
+#---------------------------------------------------------------------------
+# Configuration options related to the dot tool   
+#---------------------------------------------------------------------------
+CLASS_DIAGRAMS         = YES
+HAVE_DOT               = NO
+CLASS_GRAPH            = YES
+COLLABORATION_GRAPH    = YES
+TEMPLATE_RELATIONS     = YES
+HIDE_UNDOC_RELATIONS   = NO
+INCLUDE_GRAPH          = YES
+INCLUDED_BY_GRAPH      = YES
+GRAPHICAL_HIERARCHY    = NO
+DOT_PATH               = 
+DOTFILE_DIRS           = 
+MAX_DOT_GRAPH_WIDTH    = 1024
+MAX_DOT_GRAPH_HEIGHT   = 1024
+GENERATE_LEGEND        = YES
+DOT_CLEANUP            = YES
+
+#---------------------------------------------------------------------------
+# Configuration::addtions related to the search engine   
+#---------------------------------------------------------------------------
+SEARCHENGINE           = NO
+CGI_NAME               = 
+CGI_URL                = 
+DOC_URL                = 
+DOC_ABSPATH            = 
+BIN_ABSPATH            = 
+EXT_DOC_PATHS          = 
diff --git a/html/doxygen.css b/html/doxygen.css
new file mode 100644
index 0000000..9ca3caf
--- /dev/null
+++ b/html/doxygen.css
@@ -0,0 +1,498 @@
+/* The standard CSS for doxygen */
+
+body, table, div, p, dl {
+	font-family: Lucida Grande, Verdana, Geneva, Arial, sans-serif;
+	font-size: 12px;
+}
+
+/* @group Heading Levels */
+
+h1 {
+	text-align: center;
+	font-size: 150%;
+}
+
+h2 {
+	font-size: 120%;
+}
+
+h3 {
+	font-size: 100%;
+}
+
+dt {
+	font-weight: bold;
+}
+
+div.multicol {
+	-moz-column-gap: 1em;
+	-webkit-column-gap: 1em;
+	-moz-column-count: 3;
+	-webkit-column-count: 3;
+}
+
+p.startli, p.startdd {
+	margin-top: 2px;
+}
+
+p.endli {
+	margin-bottom: 0px;
+}
+
+p.enddd {
+	margin-bottom: 4px;
+}
+
+/* @end */
+
+caption {
+	font-weight: bold;
+}
+
+span.legend {
+        font-size: 70%;
+        text-align: center;
+}
+
+div.qindex, div.navtab{
+	background-color: #e8eef2;
+	border: 1px solid #84b0c7;
+	text-align: center;
+	margin: 2px;
+	padding: 2px;
+}
+
+div.qindex, div.navpath {
+	width: 100%;
+	line-height: 140%;
+}
+
+div.navtab {
+	margin-right: 15px;
+}
+
+/* @group Link Styling */
+
+a {
+	color: #153788;
+	font-weight: normal;
+	text-decoration: none;
+}
+
+.contents a:visited {
+	color: #1b77c5;
+}
+
+a:hover {
+	text-decoration: underline;
+}
+
+a.qindex {
+	font-weight: bold;
+}
+
+a.qindexHL {
+	font-weight: bold;
+	background-color: #6666cc;
+	color: #ffffff;
+	border: 1px double #9295C2;
+}
+
+.contents a.qindexHL:visited {
+        color: #ffffff;
+}
+
+a.el {
+	font-weight: bold;
+}
+
+a.elRef {
+}
+
+a.code {
+}
+
+a.codeRef {
+}
+
+/* @end */
+
+dl.el {
+	margin-left: -1cm;
+}
+
+.fragment {
+	font-family: monospace, fixed;
+	font-size: 105%;
+}
+
+pre.fragment {
+	border: 1px solid #CCCCCC;
+	background-color: #f5f5f5;
+	padding: 4px 6px;
+	margin: 4px 8px 4px 2px;
+}
+
+div.ah {
+	background-color: black;
+	font-weight: bold;
+	color: #ffffff;
+	margin-bottom: 3px;
+	margin-top: 3px
+}
+
+div.groupHeader {
+	margin-left: 16px;
+	margin-top: 12px;
+	margin-bottom: 6px;
+	font-weight: bold;
+}
+
+div.groupText {
+	margin-left: 16px;
+	font-style: italic;
+}
+
+body {
+	background: white;
+	color: black;
+	margin-right: 20px;
+	margin-left: 20px;
+}
+
+td.indexkey {
+	background-color: #e8eef2;
+	font-weight: bold;
+	border: 1px solid #CCCCCC;
+	margin: 2px 0px 2px 0;
+	padding: 2px 10px;
+}
+
+td.indexvalue {
+	background-color: #e8eef2;
+	border: 1px solid #CCCCCC;
+	padding: 2px 10px;
+	margin: 2px 0px;
+}
+
+tr.memlist {
+	background-color: #f0f0f0;
+}
+
+p.formulaDsp {
+	text-align: center;
+}
+
+img.formulaDsp {
+	
+}
+
+img.formulaInl {
+	vertical-align: middle;
+}
+
+div.center {
+	text-align: center;
+        margin-top: 0px;
+        margin-bottom: 0px;
+        padding: 0px;
+}
+
+div.center img {
+	border: 0px;
+}
+
+img.footer {
+	border: 0px;
+	vertical-align: middle;
+}
+
+/* @group Code Colorization */
+
+span.keyword {
+	color: #008000
+}
+
+span.keywordtype {
+	color: #604020
+}
+
+span.keywordflow {
+	color: #e08000
+}
+
+span.comment {
+	color: #800000
+}
+
+span.preprocessor {
+	color: #806020
+}
+
+span.stringliteral {
+	color: #002080
+}
+
+span.charliteral {
+	color: #008080
+}
+
+span.vhdldigit { 
+	color: #ff00ff 
+}
+
+span.vhdlchar { 
+	color: #000000 
+}
+
+span.vhdlkeyword { 
+	color: #700070 
+}
+
+span.vhdllogic { 
+	color: #ff0000 
+}
+
+/* @end */
+
+.search {
+	color: #003399;
+	font-weight: bold;
+}
+
+form.search {
+	margin-bottom: 0px;
+	margin-top: 0px;
+}
+
+input.search {
+	font-size: 75%;
+	color: #000080;
+	font-weight: normal;
+	background-color: #e8eef2;
+}
+
+td.tiny {
+	font-size: 75%;
+}
+
+.dirtab {
+	padding: 4px;
+	border-collapse: collapse;
+	border: 1px solid #84b0c7;
+}
+
+th.dirtab {
+	background: #e8eef2;
+	font-weight: bold;
+}
+
+hr {
+	height: 0;
+	border: none;
+	border-top: 1px solid #666;
+}
+
+/* @group Member Descriptions */
+
+.mdescLeft, .mdescRight,
+.memItemLeft, .memItemRight,
+.memTemplItemLeft, .memTemplItemRight, .memTemplParams {
+	background-color: #FAFAFA;
+	border: none;
+	margin: 4px;
+	padding: 1px 0 0 8px;
+}
+
+.mdescLeft, .mdescRight {
+	padding: 0px 8px 4px 8px;
+	color: #555;
+}
+
+.memItemLeft, .memItemRight, .memTemplParams {
+	border-top: 1px solid #ccc;
+}
+
+.memItemLeft, .memTemplItemLeft {
+        white-space: nowrap;
+}
+
+.memTemplParams {
+	color: #606060;
+        white-space: nowrap;
+}
+
+/* @end */
+
+/* @group Member Details */
+
+/* Styles for detailed member documentation */
+
+.memtemplate {
+	font-size: 80%;
+	color: #606060;
+	font-weight: normal;
+	margin-left: 3px;
+}
+
+.memnav {
+	background-color: #e8eef2;
+	border: 1px solid #84b0c7;
+	text-align: center;
+	margin: 2px;
+	margin-right: 15px;
+	padding: 2px;
+}
+
+.memitem {
+	padding: 0;
+	margin-bottom: 10px;
+}
+
+.memname {
+	white-space: nowrap;
+	font-weight: bold;
+}
+
+.memproto, .memdoc {
+	border: 1px solid #84b0c7;	
+}
+
+.memproto {
+	padding: 0;
+	background-color: #d5e1e8;
+	font-weight: bold;
+	-webkit-border-top-left-radius: 8px;
+	-webkit-border-top-right-radius: 8px;
+        -webkit-box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.15);
+	-moz-border-radius-topleft: 8px;
+	-moz-border-radius-topright: 8px;
+        -moz-box-shadow: rgba(0, 0, 0, 0.15) 5px 5px 5px;
+
+}
+
+.memdoc {
+	padding: 2px 5px;
+	background-color: #eef3f5;
+	border-top-width: 0;
+	-webkit-border-bottom-left-radius: 8px;
+	-webkit-border-bottom-right-radius: 8px;
+        -webkit-box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.15);
+	-moz-border-radius-bottomleft: 8px;
+	-moz-border-radius-bottomright: 8px;
+        -moz-box-shadow: rgba(0, 0, 0, 0.15) 5px 5px 5px;
+}
+
+.paramkey {
+	text-align: right;
+}
+
+.paramtype {
+	white-space: nowrap;
+}
+
+.paramname {
+	color: #602020;
+	white-space: nowrap;
+}
+.paramname em {
+	font-style: normal;
+}
+
+/* @end */
+
+/* @group Directory (tree) */
+
+/* for the tree view */
+
+.ftvtree {
+	font-family: sans-serif;
+	margin: 0.5em;
+}
+
+/* these are for tree view when used as main index */
+
+.directory {
+	font-size: 9pt;
+	font-weight: bold;
+}
+
+.directory h3 {
+	margin: 0px;
+	margin-top: 1em;
+	font-size: 11pt;
+}
+
+/*
+The following two styles can be used to replace the root node title
+with an image of your choice.  Simply uncomment the next two styles,
+specify the name of your image and be sure to set 'height' to the
+proper pixel height of your image.
+*/
+
+/*
+.directory h3.swap {
+	height: 61px;
+	background-repeat: no-repeat;
+	background-image: url("yourimage.gif");
+}
+.directory h3.swap span {
+	display: none;
+}
+*/
+
+.directory > h3 {
+	margin-top: 0;
+}
+
+.directory p {
+	margin: 0px;
+	white-space: nowrap;
+}
+
+.directory div {
+	display: none;
+	margin: 0px;
+}
+
+.directory img {
+	vertical-align: -30%;
+}
+
+/* these are for tree view when not used as main index */
+
+.directory-alt {
+	font-size: 100%;
+	font-weight: bold;
+}
+
+.directory-alt h3 {
+	margin: 0px;
+	margin-top: 1em;
+	font-size: 11pt;
+}
+
+.directory-alt > h3 {
+	margin-top: 0;
+}
+
+.directory-alt p {
+	margin: 0px;
+	white-space: nowrap;
+}
+
+.directory-alt div {
+	display: none;
+	margin: 0px;
+}
+
+.directory-alt img {
+	vertical-align: -30%;
+}
+
+/* @end */
+
+address {
+	font-style: normal;
+	color: #333;
+}
diff --git a/html/doxygen.png b/html/doxygen.png
new file mode 100644
index 0000000..f0a274b
Binary files /dev/null and b/html/doxygen.png differ
diff --git a/html/files.html b/html/files.html
new file mode 100644
index 0000000..60f1622
--- /dev/null
+++ b/html/files.html
@@ -0,0 +1,395 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: File Index</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>File List</h1>Here is a list of all documented files with brief descriptions:<table>
+  <tr><td class="indexkey"><b>irplib_calib.c</b> <a href="irplib__calib_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>irplib_calib.h</b> <a href="irplib__calib_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>irplib_cat.c</b> <a href="irplib__cat_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>irplib_cat.h</b> <a href="irplib__cat_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>irplib_distortion.c</b> <a href="irplib__distortion_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>irplib_distortion.h</b> <a href="irplib__distortion_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>irplib_flat.c</b> <a href="irplib__flat_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>irplib_flat.h</b> <a href="irplib__flat_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>irplib_framelist.c</b> <a href="irplib__framelist_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>irplib_framelist.h</b> <a href="irplib__framelist_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>irplib_hist.c</b> <a href="irplib__hist_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>irplib_hist.h</b> <a href="irplib__hist_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>irplib_ksigma_clip.c</b> <a href="irplib__ksigma__clip_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>irplib_ksigma_clip.h</b> <a href="irplib__ksigma__clip_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>irplib_ksigma_clip_body.h</b> <a href="irplib__ksigma__clip__body_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>irplib_match_cats.c</b> <a href="irplib__match__cats_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>irplib_match_cats.h</b> <a href="irplib__match__cats_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>irplib_mkmaster.c</b> <a href="irplib__mkmaster_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>irplib_mkmaster.h</b> <a href="irplib__mkmaster_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>irplib_oddeven.c</b> <a href="irplib__oddeven_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>irplib_oddeven.h</b> <a href="irplib__oddeven_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>irplib_plugin.c</b> <a href="irplib__plugin_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>irplib_plugin.h</b> <a href="irplib__plugin_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>irplib_polynomial.c</b> <a href="irplib__polynomial_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>irplib_polynomial.h</b> <a href="irplib__polynomial_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>irplib_ppm.c</b> <a href="irplib__ppm_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>irplib_ppm.h</b> <a href="irplib__ppm_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>irplib_slitpos.c</b> <a href="irplib__slitpos_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>irplib_slitpos.h</b> <a href="irplib__slitpos_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>irplib_spectrum.c</b> <a href="irplib__spectrum_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>irplib_spectrum.h</b> <a href="irplib__spectrum_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>irplib_stdstar.c</b> <a href="irplib__stdstar_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>irplib_stdstar.h</b> <a href="irplib__stdstar_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>irplib_strehl.c</b> <a href="irplib__strehl_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>irplib_strehl.h</b> <a href="irplib__strehl_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>irplib_utils.c</b> <a href="irplib__utils_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>irplib_utils.h</b> <a href="irplib__utils_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>irplib_wavecal.c</b> <a href="irplib__wavecal_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>irplib_wavecal.h</b> <a href="irplib__wavecal_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>irplib_wavecal_impl.h</b> <a href="irplib__wavecal__impl_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>irplib_wcs.c</b> <a href="irplib__wcs_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>irplib_wcs.h</b> <a href="irplib__wcs_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>irplib_wlxcorr.c</b> <a href="irplib__wlxcorr_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>irplib_wlxcorr.h</b> <a href="irplib__wlxcorr_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_absolute.c</b> <a href="sinfo__absolute_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_absolute.h</b> <a href="sinfo__absolute_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_atmo_disp.c</b> <a href="sinfo__atmo__disp_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_atmo_disp.h</b> <a href="sinfo__atmo__disp_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_bad_cfg.c</b> <a href="sinfo__bad__cfg_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_bad_cfg.h</b> <a href="sinfo__bad__cfg_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_bad_ini.h</b> <a href="sinfo__bad__ini_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_baddist_ini_by_cpl.c</b> <a href="sinfo__baddist__ini__by__cpl_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_baddist_ini_by_cpl.h</b> <a href="sinfo__baddist__ini__by__cpl_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_badnorm_ini_by_cpl.c</b> <a href="sinfo__badnorm__ini__by__cpl_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_badnorm_ini_by_cpl.h</b> <a href="sinfo__badnorm__ini__by__cpl_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_badsky_cfg.c</b> <a href="sinfo__badsky__cfg_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_badsky_cfg.h</b> <a href="sinfo__badsky__cfg_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_badsky_ini_by_cpl.c</b> <a href="sinfo__badsky__ini__by__cpl_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_badsky_ini_by_cpl.h</b> <a href="sinfo__badsky__ini__by__cpl_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_balance.c</b> <a href="sinfo__balance_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_baryvel.c</b> <a href="sinfo__baryvel_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_baryvel.h</b> <a href="sinfo__baryvel_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_boltzmann.c</b> <a href="sinfo__boltzmann_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_bp_config.c</b> <a href="sinfo__bp__config_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_bp_config.h</b> <a href="sinfo__bp__config_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_bp_dist_config.c</b> <a href="sinfo__bp__dist__config_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_bp_dist_config.h</b> <a href="sinfo__bp__dist__config_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_bp_lin.c</b> <a href="sinfo__bp__lin_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_bp_lin.h</b> <a href="sinfo__bp__lin_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_bp_lin_config.c</b> <a href="sinfo__bp__lin__config_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_bp_lin_config.h</b> <a href="sinfo__bp__lin__config_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_bp_noise.c</b> <a href="sinfo__bp__noise_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_bp_noise.h</b> <a href="sinfo__bp__noise_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_bp_noise_config.c</b> <a href="sinfo__bp__noise__config_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_bp_noise_config.h</b> <a href="sinfo__bp__noise__config_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_bp_norm.c</b> <a href="sinfo__bp__norm_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_bp_norm.h</b> <a href="sinfo__bp__norm_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_bp_norm_config.c</b> <a href="sinfo__bp__norm__config_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_bp_norm_config.h</b> <a href="sinfo__bp__norm__config_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_bp_sky_config.c</b> <a href="sinfo__bp__sky__config_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_bp_sky_config.h</b> <a href="sinfo__bp__sky__config_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_coltilt.c</b> <a href="sinfo__coltilt_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_coltilt.h</b> <a href="sinfo__coltilt_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_companion.c</b> <a href="sinfo__companion_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_compare_tags.h</b> <a href="sinfo__compare__tags_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_cpl_size.h</b> <a href="sinfo__cpl__size_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_cube_construct.c</b> <a href="sinfo__cube__construct_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_cube_construct.h</b> <a href="sinfo__cube__construct_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_cubecreate_ini.h</b> <a href="sinfo__cubecreate__ini_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_dark_cfg.c</b> <a href="sinfo__dark__cfg_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_dark_cfg.h</b> <a href="sinfo__dark__cfg_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_dark_config.c</b> <a href="sinfo__dark__config_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_dark_config.h</b> <a href="sinfo__dark__config_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_dark_ini.h</b> <a href="sinfo__dark__ini_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_dark_ini_by_cpl.c</b> <a href="sinfo__dark__ini__by__cpl_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_dark_ini_by_cpl.h</b> <a href="sinfo__dark__ini__by__cpl_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_define_opt.h</b> <a href="sinfo__define__opt_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_detlin.c</b> <a href="sinfo__detlin_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_detlin.h</b> <a href="sinfo__detlin_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_detlin_cfg.c</b> <a href="sinfo__detlin__cfg_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_detlin_cfg.h</b> <a href="sinfo__detlin__cfg_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_detlin_ini.h</b> <a href="sinfo__detlin__ini_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_detlin_ini_by_cpl.c</b> <a href="sinfo__detlin__ini__by__cpl_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_detlin_ini_by_cpl.h</b> <a href="sinfo__detlin__ini__by__cpl_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_detnoise_cfg.c</b> <a href="sinfo__detnoise__cfg_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_detnoise_cfg.h</b> <a href="sinfo__detnoise__cfg_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_detnoise_ini.h</b> <a href="sinfo__detnoise__ini_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_detnoise_ini_by_cpl.c</b> <a href="sinfo__detnoise__ini__by__cpl_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_detnoise_ini_by_cpl.h</b> <a href="sinfo__detnoise__ini__by__cpl_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_dfs.c</b> <a href="sinfo__dfs_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_dfs.h</b> <a href="sinfo__dfs_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_distortion.c</b> <a href="sinfo__distortion_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_distortion.h</b> <a href="sinfo__distortion_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_distortion_config.c</b> <a href="sinfo__distortion__config_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_distortion_config.h</b> <a href="sinfo__distortion__config_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_dump.c</b> <a href="sinfo__dump_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_dump.h</b> <a href="sinfo__dump_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_error.h</b> <a href="sinfo__error_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_fft_base.c</b> <a href="sinfo__fft__base_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_fft_base.h</b> <a href="sinfo__fft__base_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_file_handling.c</b> <a href="sinfo__file__handling_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_file_handling.h</b> <a href="sinfo__file__handling_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_finddist_cfg.c</b> <a href="sinfo__finddist__cfg_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_finddist_cfg.h</b> <a href="sinfo__finddist__cfg_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_finddist_ini.h</b> <a href="sinfo__finddist__ini_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_finddist_ini_by_cpl.c</b> <a href="sinfo__finddist__ini__by__cpl_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_finddist_ini_by_cpl.h</b> <a href="sinfo__finddist__ini__by__cpl_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_fit.c</b> <a href="sinfo__fit_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_fit.h</b> <a href="sinfo__fit_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_fit_curve.c</b> <a href="sinfo__fit__curve_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_fit_curve.h</b> <a href="sinfo__fit__curve_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_flat_cfg.c</b> <a href="sinfo__flat__cfg_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_flat_cfg.h</b> <a href="sinfo__flat__cfg_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_flat_ini.c</b> <a href="sinfo__flat__ini_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_flat_ini.h</b> <a href="sinfo__flat__ini_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_flat_ini_by_cpl.c</b> <a href="sinfo__flat__ini__by__cpl_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_flat_ini_by_cpl.h</b> <a href="sinfo__flat__ini__by__cpl_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_focus.c</b> <a href="sinfo__focus_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_focus.h</b> <a href="sinfo__focus_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_focus_cfg.c</b> <a href="sinfo__focus__cfg_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_focus_cfg.h</b> <a href="sinfo__focus__cfg_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_focus_determination_config.c</b> <a href="sinfo__focus__determination__config_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_focus_determination_config.h</b> <a href="sinfo__focus__determination__config_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_focus_ini.h</b> <a href="sinfo__focus__ini_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_focus_ini_by_cpl.c</b> <a href="sinfo__focus__ini__by__cpl_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_focus_ini_by_cpl.h</b> <a href="sinfo__focus__ini__by__cpl_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_function_1d.c</b> <a href="sinfo__function__1d_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_function_1d.h</b> <a href="sinfo__function__1d_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_functions.h</b> <a href="sinfo__functions_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_general_config.c</b> <a href="sinfo__general__config_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_general_config.h</b> <a href="sinfo__general__config_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_globals.c</b> <a href="sinfo__globals_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_globals.h</b> <a href="sinfo__globals_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_hidden.h</b> <a href="sinfo__hidden_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_image_ops.c</b> <a href="sinfo__image__ops_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_image_ops.h</b> <a href="sinfo__image__ops_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_img_noise.c</b> <a href="sinfo__img__noise_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_ipow.c</b> <a href="sinfo__ipow_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_ipow.h</b> <a href="sinfo__ipow_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_irplib_cpl_wrp.h</b> <a href="sinfo__irplib__cpl__wrp_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_key_names.h</b> <a href="sinfo__key__names_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_lamp_cfg.c</b> <a href="sinfo__lamp__cfg_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_lamp_cfg.h</b> <a href="sinfo__lamp__cfg_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_lamp_flats_config.c</b> <a href="sinfo__lamp__flats__config_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_lamp_flats_config.h</b> <a href="sinfo__lamp__flats__config_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_lamp_flats_hidden_config.c</b> <a href="sinfo__lamp__flats__hidden__config_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_lamp_flats_hidden_config.h</b> <a href="sinfo__lamp__flats__hidden__config_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_lamp_ini.c</b> <a href="sinfo__lamp__ini_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_lamp_ini.h</b> <a href="sinfo__lamp__ini_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_lamp_ini_by_cpl.c</b> <a href="sinfo__lamp__ini__by__cpl_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_lamp_ini_by_cpl.h</b> <a href="sinfo__lamp__ini__by__cpl_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_lamp_spec_config.c</b> <a href="sinfo__lamp__spec__config_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_lamp_spec_config.h</b> <a href="sinfo__lamp__spec__config_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_local_types.h</b> <a href="sinfo__local__types_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_matrix.c</b> <a href="sinfo__matrix_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_matrix.h</b> <a href="sinfo__matrix_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_median.c</b> <a href="sinfo__median_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_median.h</b> <a href="sinfo__median_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_merge.c</b> <a href="sinfo__merge_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_merge.h</b> <a href="sinfo__merge_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_msg.c</b> <a href="sinfo__msg_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_msg.h</b> <a href="sinfo__msg_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_new_add_bp_map.c</b> <a href="sinfo__new__add__bp__map_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_new_add_bp_map.h</b> <a href="sinfo__new__add__bp__map_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_new_bezier.c</b> <a href="sinfo__new__bezier_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_new_bezier.h</b> <a href="sinfo__new__bezier_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_new_cube_ops.c</b> <a href="sinfo__new__cube__ops_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_new_cube_ops.h</b> <a href="sinfo__new__cube__ops_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_new_cubes_build.c</b> <a href="sinfo__new__cubes__build_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_new_cubes_build.h</b> <a href="sinfo__new__cubes__build_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_new_cubes_coadd.c</b> <a href="sinfo__new__cubes__coadd_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_new_cubes_coadd.h</b> <a href="sinfo__new__cubes__coadd_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_new_dark.c</b> <a href="sinfo__new__dark_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_new_dark.h</b> <a href="sinfo__new__dark_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_new_find_distortions.c</b> <a href="sinfo__new__find__distortions_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_new_find_distortions.h</b> <a href="sinfo__new__find__distortions_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_new_lamp_flats.c</b> <a href="sinfo__new__lamp__flats_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_new_lamp_flats.h</b> <a href="sinfo__new__lamp__flats_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_new_nst.c</b> <a href="sinfo__new__nst_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_new_nst.h</b> <a href="sinfo__new__nst_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_new_objnod.c</b> <a href="sinfo__new__objnod_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_new_objnod.h</b> <a href="sinfo__new__objnod_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_new_prepare_stacked_frames.c</b> <a href="sinfo__new__prepare__stacked__frames_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_new_prepare_stacked_frames.h</b> <a href="sinfo__new__prepare__stacked__frames_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_new_psf.c</b> <a href="sinfo__new__psf_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_new_psf.h</b> <a href="sinfo__new__psf_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_new_resampling.c</b> <a href="sinfo__new__resampling_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_new_resampling.h</b> <a href="sinfo__new__resampling_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_new_slit_pos.c</b> <a href="sinfo__new__slit__pos_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_new_slit_pos.h</b> <a href="sinfo__new__slit__pos_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_new_stdstar.c</b> <a href="sinfo__new__stdstar_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_new_stdstar.h</b> <a href="sinfo__new__stdstar_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_new_wave_cal_slit2.c</b> <a href="sinfo__new__wave__cal__slit2_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_new_wave_cal_slit2.h</b> <a href="sinfo__new__wave__cal__slit2_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_north_south_test_config.c</b> <a href="sinfo__north__south__test__config_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_north_south_test_config.h</b> <a href="sinfo__north__south__test__config_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_ns_cfg.c</b> <a href="sinfo__ns__cfg_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_ns_cfg.h</b> <a href="sinfo__ns__cfg_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_ns_ini.h</b> <a href="sinfo__ns__ini_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_ns_ini_by_cpl.c</b> <a href="sinfo__ns__ini__by__cpl_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_ns_ini_by_cpl.h</b> <a href="sinfo__ns__ini__by__cpl_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_object_cfg.c</b> <a href="sinfo__object__cfg_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_object_cfg.h</b> <a href="sinfo__object__cfg_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_object_ini.h</b> <a href="sinfo__object__ini_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_objnod_config.c</b> <a href="sinfo__objnod__config_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_objnod_config.h</b> <a href="sinfo__objnod__config_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_objnod_ini_by_cpl.c</b> <a href="sinfo__objnod__ini__by__cpl_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_objnod_ini_by_cpl.h</b> <a href="sinfo__objnod__ini__by__cpl_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_objspider_config.c</b> <a href="sinfo__objspider__config_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_objspider_config.h</b> <a href="sinfo__objspider__config_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_objspider_ini_by_cpl.c</b> <a href="sinfo__objspider__ini__by__cpl_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_objspider_ini_by_cpl.h</b> <a href="sinfo__objspider__ini__by__cpl_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_pfits.c</b> <a href="sinfo__pfits_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_pfits.h</b> <a href="sinfo__pfits_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_pixel_handling.c</b> <a href="sinfo__pixel__handling_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_pixel_handling.h</b> <a href="sinfo__pixel__handling_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_poly2d.c</b> <a href="sinfo__poly2d_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_poly2d.h</b> <a href="sinfo__poly2d_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_prepare_stacked_frames_config.c</b> <a href="sinfo__prepare__stacked__frames__config_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_prepare_stacked_frames_config.h</b> <a href="sinfo__prepare__stacked__frames__config_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_pro_save.c</b> <a href="sinfo__pro__save_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_pro_save.h</b> <a href="sinfo__pro__save_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_pro_types.h</b> <a href="sinfo__pro__types_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_product_config.c</b> <a href="sinfo__product__config_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_product_config.h</b> <a href="sinfo__product__config_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_psf_cfg.c</b> <a href="sinfo__psf__cfg_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_psf_cfg.h</b> <a href="sinfo__psf__cfg_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_psf_config.c</b> <a href="sinfo__psf__config_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_psf_config.h</b> <a href="sinfo__psf__config_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_psf_ini.h</b> <a href="sinfo__psf__ini_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_psf_ini_by_cpl.c</b> <a href="sinfo__psf__ini__by__cpl_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_psf_ini_by_cpl.h</b> <a href="sinfo__psf__ini__by__cpl_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_qr.c</b> <a href="sinfo__qr_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_raw_types.h</b> <a href="sinfo__raw__types_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_rec_detlin.c</b> <a href="sinfo__rec__detlin_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_rec_distortion.c</b> <a href="sinfo__rec__distortion_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_rec_jitter.c</b> <a href="sinfo__rec__jitter_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_rec_lingain.c</b> <a href="sinfo__rec__lingain_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_rec_mdark.c</b> <a href="sinfo__rec__mdark_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_rec_mdark_detmon.c</b> <a href="sinfo__rec__mdark__detmon_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_rec_mflat.c</b> <a href="sinfo__rec__mflat_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_rec_objnod.c</b> <a href="sinfo__rec__objnod_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_rec_psf.c</b> <a href="sinfo__rec__psf_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_rec_pupil.c</b> <a href="sinfo__rec__pupil_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_rec_stdstar.c</b> <a href="sinfo__rec__stdstar_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_rec_utils.c</b> <a href="sinfo__rec__utils_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_rec_utils.h</b> <a href="sinfo__rec__utils_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_rec_wavecal.c</b> <a href="sinfo__rec__wavecal_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_recipes.c</b> <a href="sinfo__recipes_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_recipes.h</b> <a href="sinfo__recipes_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_ref_types.h</b> <a href="sinfo__ref__types_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_remove_crh_single.c</b> <a href="sinfo__remove__crh__single_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_remove_crh_single.h</b> <a href="sinfo__remove__crh__single_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_resampling.c</b> <a href="sinfo__resampling_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_resampling.h</b> <a href="sinfo__resampling_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_shift_images.c</b> <a href="sinfo__shift__images_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_shift_images.h</b> <a href="sinfo__shift__images_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_skycor.c</b> <a href="sinfo__skycor_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_skycor.h</b> <a href="sinfo__skycor_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_skycor_config.c</b> <a href="sinfo__skycor__config_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_skycor_config.h</b> <a href="sinfo__skycor__config_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_solve_poly_root.c</b> <a href="sinfo__solve__poly__root_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_solve_poly_root.h</b> <a href="sinfo__solve__poly__root_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_spectrum_ops.c</b> <a href="sinfo__spectrum__ops_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_spectrum_ops.h</b> <a href="sinfo__spectrum__ops_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_spiffi_types.h</b> <a href="sinfo__spiffi__types_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_stack_cfg.c</b> <a href="sinfo__stack__cfg_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_stack_cfg.h</b> <a href="sinfo__stack__cfg_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_stack_ini.h</b> <a href="sinfo__stack__ini_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_stack_ini_by_cpl.c</b> <a href="sinfo__stack__ini__by__cpl_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_stack_ini_by_cpl.h</b> <a href="sinfo__stack__ini__by__cpl_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_stacked_hidden_config.c</b> <a href="sinfo__stacked__hidden__config_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_stacked_hidden_config.h</b> <a href="sinfo__stacked__hidden__config_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_standard_star_config.c</b> <a href="sinfo__standard__star__config_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_standard_star_config.h</b> <a href="sinfo__standard__star__config_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_standstar_cfg.c</b> <a href="sinfo__standstar__cfg_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_standstar_cfg.h</b> <a href="sinfo__standstar__cfg_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_standstar_ini.h</b> <a href="sinfo__standstar__ini_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_standstar_ini_by_cpl.c</b> <a href="sinfo__standstar__ini__by__cpl_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_standstar_ini_by_cpl.h</b> <a href="sinfo__standstar__ini__by__cpl_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_star_index.c</b> <a href="sinfo__star__index_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_star_index.h</b> <a href="sinfo__star__index_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_step_distortion.c</b> <a href="sinfo__step__distortion_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_step_jitter.c</b> <a href="sinfo__step__jitter_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_step_objnod.c</b> <a href="sinfo__step__objnod_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_step_psf.c</b> <a href="sinfo__step__psf_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_step_stdstar.c</b> <a href="sinfo__step__stdstar_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_svd.c</b> <a href="sinfo__svd_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_svd.h</b> <a href="sinfo__svd_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_tilt_cfg.c</b> <a href="sinfo__tilt__cfg_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_tilt_cfg.h</b> <a href="sinfo__tilt__cfg_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_tilt_ini.h</b> <a href="sinfo__tilt__ini_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_time.c</b> <a href="sinfo__time_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_time.h</b> <a href="sinfo__time_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_tpl_dfs.c</b> <a href="sinfo__tpl__dfs_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_tpl_dfs.h</b> <a href="sinfo__tpl__dfs_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_tpl_utils.c</b> <a href="sinfo__tpl__utils_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_tpl_utils.h</b> <a href="sinfo__tpl__utils_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_utilities.c</b> <a href="sinfo__utilities_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_utilities.h</b> <a href="sinfo__utilities_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_utilities_scired.c</b> <a href="sinfo__utilities__scired_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_utilities_scired.h</b> <a href="sinfo__utilities__scired_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_utils.c</b> <a href="sinfo__utils_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_utils.h</b> <a href="sinfo__utils_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_utils_wrappers.c</b> <a href="sinfo__utils__wrappers_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_utils_wrappers.h</b> <a href="sinfo__utils__wrappers_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_utl_bp_mask_add.c</b> <a href="sinfo__utl__bp__mask__add_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfoni/sinfo_utl_cube2ima.c</b> <a href="sinfoni_2sinfo__utl__cube2ima_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>recipes/sinfo_utl_cube2ima.c</b> <a href="recipes_2sinfo__utl__cube2ima_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_utl_cube2ima.h</b> <a href="sinfo__utl__cube2ima_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfoni/sinfo_utl_cube2spectrum.c</b> <a href="sinfoni_2sinfo__utl__cube2spectrum_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>recipes/sinfo_utl_cube2spectrum.c</b> <a href="recipes_2sinfo__utl__cube2spectrum_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_utl_cube2spectrum.h</b> <a href="sinfo__utl__cube2spectrum_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfoni/sinfo_utl_cube_arith.c</b> <a href="sinfoni_2sinfo__utl__cube__arith_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>recipes/sinfo_utl_cube_arith.c</b> <a href="recipes_2sinfo__utl__cube__arith_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_utl_cube_arith.h</b> <a href="sinfo__utl__cube__arith_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfoni/sinfo_utl_cube_combine.c</b> <a href="sinfoni_2sinfo__utl__cube__combine_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>recipes/sinfo_utl_cube_combine.c</b> <a href="recipes_2sinfo__utl__cube__combine_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_utl_cube_combine.h</b> <a href="sinfo__utl__cube__combine_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_utl_cube_create.c</b> <a href="sinfo__utl__cube__create_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_utl_cube_test.c</b> <a href="sinfo__utl__cube__test_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_utl_eff.c</b> <a href="sinfo__utl__eff_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_utl_efficiency.c</b> <a href="sinfo__utl__efficiency_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_utl_efficiency.h</b> <a href="sinfo__utl__efficiency_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_utl_illumcorr.c</b> <a href="sinfo__utl__illumcorr_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_utl_ima_arith.c</b> <a href="sinfo__utl__ima__arith_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_utl_ima_cube_ks_test.c</b> <a href="sinfo__utl__ima__cube__ks__test_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_utl_ima_gauss.c</b> <a href="sinfo__utl__ima__gauss_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_utl_ima_line_corr.c</b> <a href="sinfo__utl__ima__line__corr_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_utl_remove_crh_single.c</b> <a href="sinfo__utl__remove__crh__single_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_utl_seds.c</b> <a href="sinfo__utl__seds_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_utl_skycor.c</b> <a href="sinfo__utl__skycor_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_utl_skymap.c</b> <a href="sinfo__utl__skymap_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfoni/sinfo_utl_spectrum_divide_by_blackbody.c</b> <a href="sinfoni_2sinfo__utl__spectrum__divide__by__blackbody_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>recipes/sinfo_utl_spectrum_divide_by_blackbody.c</b> <a href="recipes_2sinfo__utl__spectrum__divide__by__blackbody_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_utl_spectrum_divide_by_blackbody.h</b> <a href="sinfo__utl__spectrum__divide__by__blackbody_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfoni/sinfo_utl_spectrum_wavelength_shift.c</b> <a href="sinfoni_2sinfo__utl__spectrum__wavelength__shift_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>recipes/sinfo_utl_spectrum_wavelength_shift.c</b> <a href="recipes_2sinfo__utl__spectrum__wavelength__shift_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_utl_spectrum_wavelength_shift.h</b> <a href="sinfo__utl__spectrum__wavelength__shift_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_utl_stdstars.c</b> <a href="sinfo__utl__stdstars_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_utl_table_ex.c</b> <a href="sinfo__utl__table__ex_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_utl_table_test.c</b> <a href="sinfo__utl__table__test_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_vltPort.h</b> <a href="sinfo__vltPort_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_wave_calibration.c</b> <a href="sinfo__wave__calibration_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_wave_calibration.h</b> <a href="sinfo__wave__calibration_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_wavecal.c</b> <a href="sinfo__wavecal_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_wavecal.h</b> <a href="sinfo__wavecal_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_wavecal_cfg.c</b> <a href="sinfo__wavecal__cfg_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_wavecal_cfg.h</b> <a href="sinfo__wavecal__cfg_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_wavecal_config.c</b> <a href="sinfo__wavecal__config_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_wavecal_config.h</b> <a href="sinfo__wavecal__config_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_wavecal_ini.h</b> <a href="sinfo__wavecal__ini_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_wavecal_ini_by_cpl.c</b> <a href="sinfo__wavecal__ini__by__cpl_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_wavecal_ini_by_cpl.h</b> <a href="sinfo__wavecal__ini__by__cpl_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_wcal_functions.c</b> <a href="sinfo__wcal__functions_8c_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+  <tr><td class="indexkey"><b>sinfo_wcal_functions.h</b> <a href="sinfo__wcal__functions_8h_source.html">[code]</a></td><td class="indexvalue"></td></tr>
+</table>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__irplib__calib.html b/html/group__irplib__calib.html
new file mode 100644
index 0000000..0b81678
--- /dev/null
+++ b/html/group__irplib__calib.html
@@ -0,0 +1,366 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Functions for calibrations</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Functions for calibrations</h1><table border="0" cellpadding="0" cellspacing="0">
+<tr><td colspan="2"><h2>Functions</h2></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">cpl_table * </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__calib.html#ga98c9970b59c6b7919f531829f6f5dab9">irplib_compute_gain</a> (cpl_frameset *son, cpl_frameset *sof, int *zone, const int kappa, const int nclip)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Computes the detector's gain.  <a href="#ga98c9970b59c6b7919f531829f6f5dab9"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">cpl_table * </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__calib.html#gadefee4e970a548c25bcbb42797778a2a">irplib_compute_linearity</a> (cpl_frameset *son, cpl_frameset *sof)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Computes the detector's linearity.  <a href="#gadefee4e970a548c25bcbb42797778a2a"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__calib.html#gae9b762625dbd2c31c1b59cfd8c15fd90">irplib_detlin_correct</a> (cpl_imagelist *ilist, const char *detlin_a, const char *detlin_b, const char *detlin_c)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Apply the detector linearity correction.  <a href="#gae9b762625dbd2c31c1b59cfd8c15fd90"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__calib.html#gae650a3e54e1aff329b1b5ee356bcdbde">irplib_flat_dark_bpm_calib</a> (cpl_imagelist *ilist, const char *flat, const char *dark, const char *bpm)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Apply the calibration to the frames.  <a href="#gae650a3e54e1aff329b1b5ee356bcdbde"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">cpl_image * </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__calib.html#gae11ebd9b30a6c781265ba2e5af87722b">irplib_mkmaster_mean</a> (cpl_imagelist *images, const double kappa, const int nclip, const double tolerance, const double klow, const double khigh, const int niter)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Computes master frame by clean stack mean of the input imagelist.  <a href="#gae11ebd9b30a6c781265ba2e5af87722b"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">cpl_image * </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__calib.html#ga31157521720077a762a43644a503bbf2">irplib_mkmaster_median</a> (cpl_imagelist *images, const double kappa, const int nclip, const double tolerance)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Computes master frame by clean stack median of the input imagelist.  <a href="#ga31157521720077a762a43644a503bbf2"></a><br/></td></tr>
+</table>
+<hr/><h2>Function Documentation</h2>
+<a class="anchor" id="ga98c9970b59c6b7919f531829f6f5dab9"></a><!-- doxytag: member="irplib_calib.c::irplib_compute_gain" ref="ga98c9970b59c6b7919f531829f6f5dab9" args="(cpl_frameset *son, cpl_frameset *sof, int *zone, const int kappa, const int nclip)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">cpl_table* irplib_compute_gain </td>
+          <td>(</td>
+          <td class="paramtype">cpl_frameset * </td>
+          <td class="paramname"> <em>son</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">cpl_frameset * </td>
+          <td class="paramname"> <em>sof</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">int * </td>
+          <td class="paramname"> <em>zone</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const int </td>
+          <td class="paramname"> <em>kappa</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const int </td>
+          <td class="paramname"> <em>nclip</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Computes the detector's gain. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>son</em> </td><td>the input frameset of linearity on-flat fields </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>sof</em> </td><td>the input frameset of linearity off-flat fields </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>zone</em> </td><td>pointer to an integer array with locations (llx,lly,urx,ury) of region where a clean mean and noise are computed </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>kappa</em> </td><td>value of kappa in kappa-sigma clipping </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>nclip</em> </td><td>number of kappa-sigma clipping iterations</td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>pointer to a table containing single gain evaluations </dd></dl>
+<dl class="note"><dt><b>Note:</b></dt><dd>: #1 input frames need to have defined FITS keyword EXPTIME #2 input frames need to have defined FITS keyword DIT </dd></dl>
+
+<p>Definition at line <a class="el" href="irplib__calib_8c_source.html#l00179">179</a> of file <a class="el" href="irplib__calib_8c_source.html">irplib_calib.c</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="gadefee4e970a548c25bcbb42797778a2a"></a><!-- doxytag: member="irplib_calib.c::irplib_compute_linearity" ref="gadefee4e970a548c25bcbb42797778a2a" args="(cpl_frameset *son, cpl_frameset *sof)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">cpl_table* irplib_compute_linearity </td>
+          <td>(</td>
+          <td class="paramtype">cpl_frameset * </td>
+          <td class="paramname"> <em>son</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">cpl_frameset * </td>
+          <td class="paramname"> <em>sof</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Computes the detector's linearity. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>son</em> </td><td>the input frameset of linearity on flat fields </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>sof</em> </td><td>the input frameset of linearity off flat fields </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>pointer to a table containing linearity evaluations </dd></dl>
+<dl class="note"><dt><b>Note:</b></dt><dd>: #2 input frames need to have defined FITS keyword EXPTIME #3 input frames need to have defined FITS keyword DIT </dd></dl>
+
+<p>Definition at line <a class="el" href="irplib__calib_8c_source.html#l00360">360</a> of file <a class="el" href="irplib__calib_8c_source.html">irplib_calib.c</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="gae9b762625dbd2c31c1b59cfd8c15fd90"></a><!-- doxytag: member="irplib_calib.c::irplib_detlin_correct" ref="gae9b762625dbd2c31c1b59cfd8c15fd90" args="(cpl_imagelist *ilist, const char *detlin_a, const char *detlin_b, const char *detlin_c)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">int irplib_detlin_correct </td>
+          <td>(</td>
+          <td class="paramtype">cpl_imagelist * </td>
+          <td class="paramname"> <em>ilist</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>detlin_a</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>detlin_b</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>detlin_c</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Apply the detector linearity correction. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>ilist</em> </td><td>the input image list </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>detlin_a</em> </td><td>the a coeffs </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>detlin_b</em> </td><td>the b coeffs </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>detlin_c</em> </td><td>the c coeffs </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>0 if everything is ok, -1 otherwise </dd></dl>
+
+<p>Definition at line <a class="el" href="irplib__calib_8c_source.html#l00481">481</a> of file <a class="el" href="irplib__calib_8c_source.html">irplib_calib.c</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="gae650a3e54e1aff329b1b5ee356bcdbde"></a><!-- doxytag: member="irplib_calib.c::irplib_flat_dark_bpm_calib" ref="gae650a3e54e1aff329b1b5ee356bcdbde" args="(cpl_imagelist *ilist, const char *flat, const char *dark, const char *bpm)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">int irplib_flat_dark_bpm_calib </td>
+          <td>(</td>
+          <td class="paramtype">cpl_imagelist * </td>
+          <td class="paramname"> <em>ilist</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>flat</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>dark</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>bpm</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Apply the calibration to the frames. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>ilist</em> </td><td>the input image list </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>flat</em> </td><td>the flat field </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>dark</em> </td><td>the dark </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>bpm</em> </td><td>the bad pixels map </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>0 if everything is ok, -1 otherwise </dd></dl>
+
+<p>Definition at line <a class="el" href="irplib__calib_8c_source.html#l00566">566</a> of file <a class="el" href="irplib__calib_8c_source.html">irplib_calib.c</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="gae11ebd9b30a6c781265ba2e5af87722b"></a><!-- doxytag: member="irplib_mkmaster.c::irplib_mkmaster_mean" ref="gae11ebd9b30a6c781265ba2e5af87722b" args="(cpl_imagelist *images, const double kappa, const int nclip, const double tolerance, const double klow, const double khigh, const int niter)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">cpl_image* irplib_mkmaster_mean </td>
+          <td>(</td>
+          <td class="paramtype">cpl_imagelist * </td>
+          <td class="paramname"> <em>images</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const double </td>
+          <td class="paramname"> <em>kappa</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const int </td>
+          <td class="paramname"> <em>nclip</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const double </td>
+          <td class="paramname"> <em>tolerance</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const double </td>
+          <td class="paramname"> <em>klow</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const double </td>
+          <td class="paramname"> <em>khigh</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const int </td>
+          <td class="paramname"> <em>niter</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Computes master frame by clean stack mean of the input imagelist. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>images</em> </td><td>input imagelist </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>kappa</em> </td><td>value for kappa-sigma clip </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>nclip</em> </td><td>Number of clipping iterations </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>tolerance</em> </td><td>tolerance on range between two successive clip iterations</td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>master image</dd></dl>
+<p>The returned image must be deallocated. </p>
+
+<p>Definition at line <a class="el" href="irplib__mkmaster_8c_source.html#l00313">313</a> of file <a class="el" href="irplib__mkmaster_8c_source.html">irplib_mkmaster.c</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="ga31157521720077a762a43644a503bbf2"></a><!-- doxytag: member="irplib_mkmaster.c::irplib_mkmaster_median" ref="ga31157521720077a762a43644a503bbf2" args="(cpl_imagelist *images, const double kappa, const int nclip, const double tolerance)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">cpl_image* irplib_mkmaster_median </td>
+          <td>(</td>
+          <td class="paramtype">cpl_imagelist * </td>
+          <td class="paramname"> <em>images</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const double </td>
+          <td class="paramname"> <em>kappa</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const int </td>
+          <td class="paramname"> <em>nclip</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const double </td>
+          <td class="paramname"> <em>tolerance</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Computes master frame by clean stack median of the input imagelist. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>images</em> </td><td>input imagelist </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>kappa</em> </td><td>value for kappa-sigma clip </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>nclip</em> </td><td>Number of clipping iterations </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>tolerance</em> </td><td>tolerance on range between two successive clip iterations</td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>master image</dd></dl>
+<p>The returned image must be deallocated. </p>
+
+<p>Definition at line <a class="el" href="irplib__mkmaster_8c_source.html#l00352">352</a> of file <a class="el" href="irplib__mkmaster_8c_source.html">irplib_mkmaster.c</a>.</p>
+
+</div>
+</div>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__irplib__cat.html b/html/group__irplib__cat.html
new file mode 100644
index 0000000..0ad80e7
--- /dev/null
+++ b/html/group__irplib__cat.html
@@ -0,0 +1,252 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Functions for accessing catalogues</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Functions for accessing catalogues</h1><table border="0" cellpadding="0" cellspacing="0">
+<tr><td colspan="2"><h2>Functions</h2></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__cat.html#ga8dd2b5e6b7bc4a7ea3f2b275882aa200">irplib_2mass_get_catpars</a> (const cpl_frame *master_index, char **catpath, char **catname)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Find the name of the standard catalogue being used and its location.  <a href="#ga8dd2b5e6b7bc4a7ea3f2b275882aa200"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">cpl_error_code </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__cat.html#ga2289fa88ec0498a2930291b1d51a46af">irplib_cat_get_image_limits</a> (const cpl_wcs *wcs, float ext_search, double *ra1, double *ra2, double *dec1, double *dec2)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Get coverage in ra, dec of a frame.  <a href="#ga2289fa88ec0498a2930291b1d51a46af"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">cpl_table * </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__cat.html#ga7fdafd757d33d4096270027912a89cf6">irplib_2mass_extract</a> (char *path, float ramin, float ramax, float decmin, float decmax)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Extract standards from the 2mass catalogue.  <a href="#ga7fdafd757d33d4096270027912a89cf6"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">cpl_table * </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__cat.html#gaf3dbc2180a59e7187674707510205afe">irplib_match_cat_pairs</a> (cpl_table **catalogues, int ncats, int(*binary_match_condition)(cpl_table *catalogue1, cpl_table *catalogue2, intiobj1, intiobj2))</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Finds all the objects that appear at least in some of the catalogues.  <a href="#gaf3dbc2180a59e7187674707510205afe"></a><br/></td></tr>
+</table>
+<hr/><h2>Function Documentation</h2>
+<a class="anchor" id="ga7fdafd757d33d4096270027912a89cf6"></a><!-- doxytag: member="irplib_cat.c::irplib_2mass_extract" ref="ga7fdafd757d33d4096270027912a89cf6" args="(char *path, float ramin, float ramax, float decmin, float decmax)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">cpl_table* irplib_2mass_extract </td>
+          <td>(</td>
+          <td class="paramtype">char * </td>
+          <td class="paramname"> <em>path</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">float </td>
+          <td class="paramname"> <em>ramin</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">float </td>
+          <td class="paramname"> <em>ramax</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">float </td>
+          <td class="paramname"> <em>decmin</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">float </td>
+          <td class="paramname"> <em>decmax</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Extract standards from the 2mass catalogue. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>path</em> </td><td>The full path to the catalogue FITS files and index. </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>ramin1</em> </td><td>The minimum RA, this can be negative in the case the area wraps around the equinox. </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>ramax1</em> </td><td>The maximum RA </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>decmin</em> </td><td>The minimum Declination </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>decmax</em> </td><td>The maximum Declination </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>A table structure with the extracted catalogue objects</dd></dl>
+<p>The FITS tables containing the 2mass psc catalogue are searched to find all of the objects within an input equatorial area. Deals with the sigularity at the equinox, but not at the poles. </p>
+
+<p>Definition at line <a class="el" href="irplib__cat_8c_source.html#l00280">280</a> of file <a class="el" href="irplib__cat_8c_source.html">irplib_cat.c</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="ga8dd2b5e6b7bc4a7ea3f2b275882aa200"></a><!-- doxytag: member="irplib_cat.c::irplib_2mass_get_catpars" ref="ga8dd2b5e6b7bc4a7ea3f2b275882aa200" args="(const cpl_frame *master_index, char **catpath, char **catname)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">int irplib_2mass_get_catpars </td>
+          <td>(</td>
+          <td class="paramtype">const cpl_frame * </td>
+          <td class="paramname"> <em>master_index</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">char ** </td>
+          <td class="paramname"> <em>catpath</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">char ** </td>
+          <td class="paramname"> <em>catname</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Find the name of the standard catalogue being used and its location. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>index</em> </td><td>The frame for the index FITS file </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>catpath</em> </td><td>The full path to the catalgoue FITS files </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>catname</em> </td><td>The name of the catalogue </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>CPL_ERROR_NONE if sucess CPL_ERROR_FILE_IO if the file does not exist or the header cannot be read.</dd></dl>
+<p>Find the name of the standard catalogue being used and its location. The former should be in a header keyword in the specified FITS file. The latter is the full path of the FITS file. Both values need to be deallocated when you're finished with them. </p>
+
+<p>Definition at line <a class="el" href="irplib__cat_8c_source.html#l00075">75</a> of file <a class="el" href="irplib__cat_8c_source.html">irplib_cat.c</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="ga2289fa88ec0498a2930291b1d51a46af"></a><!-- doxytag: member="irplib_cat.c::irplib_cat_get_image_limits" ref="ga2289fa88ec0498a2930291b1d51a46af" args="(const cpl_wcs *wcs, float ext_search, double *ra1, double *ra2, double *dec1, double *dec2)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">cpl_error_code irplib_cat_get_image_limits </td>
+          <td>(</td>
+          <td class="paramtype">const cpl_wcs * </td>
+          <td class="paramname"> <em>wcs</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">float </td>
+          <td class="paramname"> <em>ext_search</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">double * </td>
+          <td class="paramname"> <em>ra1</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">double * </td>
+          <td class="paramname"> <em>ra2</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">double * </td>
+          <td class="paramname"> <em>dec1</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">double * </td>
+          <td class="paramname"> <em>dec2</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Get coverage in ra, dec of a frame. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>plist</em> </td><td>Input property list </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>ext_search</em> </td><td>Factor for an extra box search. </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>ra1</em> </td><td>Lower RA </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>ra2</em> </td><td>Upper RA </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>dec1</em> </td><td>Lower Dec </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>dec2</em> </td><td>Upper Dec </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>CPL_ERROR_NONE if sucess. CPL_ERROR_DATA_NOT_FOUND if wcs is not valid</dd></dl>
+<p>Given a WCS solution this routine works out the min and max equatorial coordinates covered by the image. </p>
+
+<p>Definition at line <a class="el" href="irplib__cat_8c_source.html#l00154">154</a> of file <a class="el" href="irplib__cat_8c_source.html">irplib_cat.c</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="gaf3dbc2180a59e7187674707510205afe"></a><!-- doxytag: member="irplib_match_cats.c::irplib_match_cat_pairs" ref="gaf3dbc2180a59e7187674707510205afe" args="(cpl_table **catalogues, int ncats, int(*binary_match_condition)(cpl_table *catalogue1, cpl_table *catalogue2, intiobj1, intiobj2))" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">cpl_table* irplib_match_cat_pairs </td>
+          <td>(</td>
+          <td class="paramtype">cpl_table ** </td>
+          <td class="paramname"> <em>catalogues</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">int </td>
+          <td class="paramname"> <em>ncats</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">int(*)(cpl_table *catalogue1, cpl_table *catalogue2, intiobj1, intiobj2) </td>
+          <td class="paramname"> <em>binary_match_condition</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Finds all the objects that appear at least in some of the catalogues. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>catalogues</em> </td><td>All the catalogues </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>ncats</em> </td><td>Number of catalogues </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>The matching table if sucess, NULL otherwise.</dd></dl>
+<p>Implementation notes:</p>
+<p>cat_indexing_order tells you in which order the catalogues are being iterated. For example cat_indexing_order[2] gives the index of the catalogue that is being iterated in the 3rd postion. </p>
+
+<p>Definition at line <a class="el" href="irplib__match__cats_8c_source.html#l00126">126</a> of file <a class="el" href="irplib__match__cats_8c_source.html">irplib_match_cats.c</a>.</p>
+
+</div>
+</div>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__irplib__distortion.html b/html/group__irplib__distortion.html
new file mode 100644
index 0000000..c6ce3a7
--- /dev/null
+++ b/html/group__irplib__distortion.html
@@ -0,0 +1,19 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Distortion correction functions</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Distortion correction functions</h1><table border="0" cellpadding="0" cellspacing="0">
+</table>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__irplib__flat.html b/html/group__irplib__flat.html
new file mode 100644
index 0000000..ce28993
--- /dev/null
+++ b/html/group__irplib__flat.html
@@ -0,0 +1,122 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Functions for flatfielding</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Functions for flatfielding</h1><table border="0" cellpadding="0" cellspacing="0">
+<tr><td colspan="2"><h2>Functions</h2></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">cpl_imagelist * </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__flat.html#gaf9bd48348cc91bb66304697b4c7aa58e">irplib_flat_fit_set</a> (cpl_imagelist *raw, int mode)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Compute a flat-field out of a set of exposures.  <a href="#gaf9bd48348cc91bb66304697b4c7aa58e"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">double * </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__flat.html#ga3e3e3bd45aef34e38758e1f2528d7c91">irplib_flat_fit_slope_robust</a> (double *x, double *y, int np)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Fit a slope to a list of points (robust fit).  <a href="#ga3e3e3bd45aef34e38758e1f2528d7c91"></a><br/></td></tr>
+</table>
+<hr/><h2>Function Documentation</h2>
+<a class="anchor" id="gaf9bd48348cc91bb66304697b4c7aa58e"></a><!-- doxytag: member="irplib_flat.c::irplib_flat_fit_set" ref="gaf9bd48348cc91bb66304697b4c7aa58e" args="(cpl_imagelist *raw, int mode)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">cpl_imagelist* irplib_flat_fit_set </td>
+          <td>(</td>
+          <td class="paramtype">cpl_imagelist * </td>
+          <td class="paramname"> <em>raw</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">int </td>
+          <td class="paramname"> <em>mode</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Compute a flat-field out of a set of exposures. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>raw</em> </td><td>Input image set </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>mode</em> </td><td>0 for proportional, 1 for robust fit </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>1 newly allocated set of 2 or 3 images</dd></dl>
+<p>The input is assumed to be a cube containing planes of different intensities (usually increasing or decreasing). Typical inputs are: twilight data sets, halogen lamp, or skies of different airmasses in the thermal regime.</p>
+<p>The input image list must be of type float.</p>
+<p>In robust mode, the output is a set of 3 images. The first image contains a regression map, i.e. for each pixel position on the detector, a curve is plotted of the pixel intensity in each plane against the median intensity of the plane. A slope is fit, and the gain factor is stored into this first image.</p>
+<p>The second image contains the y-intercepts of the slope fit. It is usually good to check it out in case of failures.</p>
+<p>The third image contains the sum of squared errors for each fit. The fit is using a robust least-squares criterion rejecting outliers. This is the algorithm to use with big telescopes like the VLT, which collect so much light that objects are actually seen in the twilight sky.</p>
+<p>In proportional mode, the output is a set of 2 images. The first image contains a regression map. The second image contains the sum of squared errors for each fit. </p>
+
+<p>Definition at line <a class="el" href="irplib__flat_8c_source.html#l00087">87</a> of file <a class="el" href="irplib__flat_8c_source.html">irplib_flat.c</a>.</p>
+
+<p>References <a class="el" href="irplib__flat_8c_source.html#l00191">irplib_flat_fit_slope_robust()</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="ga3e3e3bd45aef34e38758e1f2528d7c91"></a><!-- doxytag: member="irplib_flat.c::irplib_flat_fit_slope_robust" ref="ga3e3e3bd45aef34e38758e1f2528d7c91" args="(double *x, double *y, int np)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">double* irplib_flat_fit_slope_robust </td>
+          <td>(</td>
+          <td class="paramtype">double * </td>
+          <td class="paramname"> <em>x</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">double * </td>
+          <td class="paramname"> <em>y</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">int </td>
+          <td class="paramname"> <em>np</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Fit a slope to a list of points (robust fit). </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>x</em> </td><td>x coordinates </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>y</em> </td><td>y coordinates </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>np</em> </td><td>number of points </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>Pointer to newly allocated array of 3 doubles.</dd></dl>
+<p>The slope to fit has the following kind of equation: y = c[0] + c[1] * x</p>
+<p>The returned coefficients are defined as: c[0] is the y-intercept. c[1] is the slope. c[2] is the median squared error of the fit. This is a very robust slope fit. It tolerates up to 50% of outliers in input. </p>
+
+<p>Definition at line <a class="el" href="irplib__flat_8c_source.html#l00191">191</a> of file <a class="el" href="irplib__flat_8c_source.html">irplib_flat.c</a>.</p>
+
+<p>Referenced by <a class="el" href="irplib__flat_8c_source.html#l00087">irplib_flat_fit_set()</a>, and <a class="el" href="irplib__slitpos_8c_source.html#l00119">irplib_slitpos_analysis()</a>.</p>
+
+</div>
+</div>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__irplib__framelist.html b/html/group__irplib__framelist.html
new file mode 100644
index 0000000..dffac52
--- /dev/null
+++ b/html/group__irplib__framelist.html
@@ -0,0 +1,1029 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Lists of frames with properties.</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Lists of frames with properties.</h1><table border="0" cellpadding="0" cellspacing="0">
+<tr><td colspan="2"><h2>Functions</h2></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">irplib_framelist * </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__framelist.html#ga5b86add048651f73424d2542a04946a0">irplib_framelist_new</a> (void)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Create an empty framelist.  <a href="#ga5b86add048651f73424d2542a04946a0"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__framelist.html#ga7a5159e9d27ef277df3fb55b331aaf26">irplib_framelist_delete</a> (irplib_framelist *self)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Deallocate an irplib_framelist with its frames and properties.  <a href="#ga7a5159e9d27ef277df3fb55b331aaf26"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">irplib_framelist * </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__framelist.html#ga30cbfd003c6e6a6a42e610442f0b1bd1">irplib_framelist_cast</a> (const cpl_frameset *frameset)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Create an irplib_framelist from a cpl_framelist.  <a href="#ga30cbfd003c6e6a6a42e610442f0b1bd1"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">cpl_frameset * </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__framelist.html#gabeedce2770a1bc06c26c0891a41aa174">irplib_frameset_cast</a> (const irplib_framelist *self)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Create a CPL frameset from an irplib_framelist.  <a href="#gabeedce2770a1bc06c26c0891a41aa174"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">irplib_framelist * </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__framelist.html#ga86d6746d1c19356417815f7df04c3396">irplib_framelist_extract</a> (const irplib_framelist *self, const char *tag)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Extract the frames with the given tag from a framelist.  <a href="#ga86d6746d1c19356417815f7df04c3396"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">irplib_framelist * </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__framelist.html#gace77e5ae75183a22a0e5af9dd9018b01">irplib_framelist_extract_regexp</a> (const irplib_framelist *self, const char *regexp, cpl_boolean invert)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Extract the frames with the given tag from a framelist.  <a href="#gace77e5ae75183a22a0e5af9dd9018b01"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__framelist.html#ga2518fce55112b5008cb119a126e593d7">irplib_framelist_get_size</a> (const irplib_framelist *self)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Get the size of a framelist.  <a href="#ga2518fce55112b5008cb119a126e593d7"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">cpl_frame * </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__framelist.html#gaba8797bbb8394f5574cd88b2f1984387">irplib_framelist_get</a> (irplib_framelist *self, int pos)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Get the specified frame from the framelist.  <a href="#gaba8797bbb8394f5574cd88b2f1984387"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">const cpl_frame * </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__framelist.html#ga93d8f903729ea4b6fcb3eca85935716f">irplib_framelist_get_const</a> (const irplib_framelist *self, int pos)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Get the specified frame from the framelist.  <a href="#ga93d8f903729ea4b6fcb3eca85935716f"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">cpl_error_code </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__framelist.html#gada2c2e3f530a6dff763402eefceb5600">irplib_framelist_set_propertylist</a> (irplib_framelist *self, int pos, const cpl_propertylist *list)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Duplicate a propertylist to the specified position in the framelist.  <a href="#gada2c2e3f530a6dff763402eefceb5600"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">cpl_propertylist * </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__framelist.html#gab4858b1e9164f3a6cffcf40270f89032">irplib_framelist_get_propertylist</a> (irplib_framelist *self, int pos)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Get the propertylist of the specified frame in the framelist.  <a href="#gab4858b1e9164f3a6cffcf40270f89032"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">const cpl_propertylist * </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__framelist.html#ga7700dadcf17db5b86409e6cef233af4c">irplib_framelist_get_propertylist_const</a> (const irplib_framelist *self, int pos)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Get the propertylist of the specified frame in the framelist.  <a href="#ga7700dadcf17db5b86409e6cef233af4c"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">cpl_error_code </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__framelist.html#ga6ce5701e84915514975d09e0100c6005">irplib_framelist_load_propertylist</a> (irplib_framelist *self, int pos, int ind, const char *regexp, cpl_boolean invert)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Load the propertylist of the specified frame in the framelist.  <a href="#ga6ce5701e84915514975d09e0100c6005"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">cpl_error_code </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__framelist.html#gaf9204681e0b6aa2d952c974dcbd8729d">irplib_framelist_load_propertylist_all</a> (irplib_framelist *self, int ind, const char *regexp, cpl_boolean invert)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Load the propertylists of all frames in the framelist.  <a href="#gaf9204681e0b6aa2d952c974dcbd8729d"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">cpl_error_code </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__framelist.html#gab11bb60e44dea926cd50ee80c7fbbd14">irplib_framelist_set_tag_all</a> (irplib_framelist *self, const char *tag)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Set the tag of all frames in the list.  <a href="#gab11bb60e44dea926cd50ee80c7fbbd14"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">cpl_error_code </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__framelist.html#ga37e730f5627b4a0c7a81014f62421879">irplib_framelist_set</a> (irplib_framelist *self, cpl_frame *frame, int pos)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Add a frame to a framelist.  <a href="#ga37e730f5627b4a0c7a81014f62421879"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">cpl_error_code </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__framelist.html#gac66ea3ad4fc98c171f8b840229fe54ce">irplib_framelist_erase</a> (irplib_framelist *self, int pos)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Erase a frame from a framelist and delete it and its propertylist.  <a href="#gac66ea3ad4fc98c171f8b840229fe54ce"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">cpl_frame * </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__framelist.html#ga771f14f97f80a9bd7176d323999c9bce">irplib_framelist_unset</a> (irplib_framelist *self, int pos, cpl_propertylist **plist)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Erase a frame from a framelist and return it to the caller.  <a href="#ga771f14f97f80a9bd7176d323999c9bce"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__framelist.html#ga900ea254d9b2a2e4e3957360bbae4deb">irplib_framelist_empty</a> (irplib_framelist *self)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Erase all frames from a framelist.  <a href="#ga900ea254d9b2a2e4e3957360bbae4deb"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">cpl_error_code </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__framelist.html#gafed15e9e259ebad923b710f5eb0196ac">irplib_framelist_contains</a> (const irplib_framelist *self, const char *key, cpl_type type, cpl_boolean is_equal, double fp_tol)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Verify that a property is present for all frames.  <a href="#gafed15e9e259ebad923b710f5eb0196ac"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">cpl_imagelist * </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__framelist.html#ga0ff6c5e3b778c607544ca04ca3fb9e94">irplib_imagelist_load_framelist</a> (const irplib_framelist *self, cpl_type pixeltype, int planenum, int extnum)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Load an imagelist from a framelist.  <a href="#ga0ff6c5e3b778c607544ca04ca3fb9e94"></a><br/></td></tr>
+</table>
+<hr/><a name="_details"></a><h2>Detailed Description</h2>
+<p>This module implements a container type for frames and their propertylists. It differs from the cpl_frameset in these ways: 1) A propertylist can be associated to each frame 2) Access by index is a O(1)-operation 3) It can not be corrupted due to caching bugs (e.g. DFS02731).</p>
+<dl class="user"><dt><b>Synopsis:</b></dt><dd><div class="fragment"><pre class="fragment"><span class="preprocessor">     #include <irplib_framelist.h></span>
+</pre></div></dd></dl>
+<dl class="user"><dt><b>Example:</b></dt><dd><div class="fragment"><pre class="fragment">   <span class="keyword">static</span> <span class="keywordtype">int</span> rrecipe(cpl_frameset * frameset)
+   {
+      <span class="comment">// Error handling omitted for brevity</span>
+
+      irplib_framelist * allframes = <a class="code" href="group__irplib__framelist.html#ga30cbfd003c6e6a6a42e610442f0b1bd1" title="Create an irplib_framelist from a cpl_framelist.">irplib_framelist_cast</a>(frameset);
+
+      <span class="comment">// Get raw frames of either type</span>
+      irplib_framelist * rawframes = <a class="code" href="group__irplib__framelist.html#gace77e5ae75183a22a0e5af9dd9018b01" title="Extract the frames with the given tag from a framelist.">irplib_framelist_extract_regexp</a>(allframes,
+                                                                   <span class="stringliteral">"^("</span>
+                                                                   RAW_TYPE1 <span class="stringliteral">"|"</span>
+                                                                   RAW_TYPE2 <span class="stringliteral">")$"</span>,
+                                                                   CPL_FALSE);
+
+      <span class="comment">// Load the list of images</span>
+      cpl_imagelist * ilist = <a class="code" href="group__irplib__framelist.html#ga0ff6c5e3b778c607544ca04ca3fb9e94" title="Load an imagelist from a framelist.">irplib_imagelist_load_framelist</a>(rawframes,
+                                                              CPL_TYPE_FLOAT,
+                                                              0, 0);
+
+      <span class="keyword">const</span> cpl_propertylist * plist;
+
+      <span class="comment">// A regular expression of the FITS cards needed by this recipe</span>
+      <span class="keyword">const</span> <span class="keywordtype">char</span> cards[] = <span class="stringliteral">"^(RA|DEC|EXPTIME)$"</span>;
+      <span class="keywordtype">double</span> ra, dec;
+
+
+      <span class="comment">// Load the specified FITS cards for all raw frames</span>
+      <a class="code" href="group__irplib__framelist.html#gaf9204681e0b6aa2d952c974dcbd8729d" title="Load the propertylists of all frames in the framelist.">irplib_framelist_load_propertylist_all</a>(rawframes, 0, cards, CPL_FALSE));
+
+
+      <span class="comment">// Verify the presence and uniformity of the FITS cards</span>
+      <span class="keywordflow">if</span> (<a class="code" href="group__irplib__framelist.html#gafed15e9e259ebad923b710f5eb0196ac" title="Verify that a property is present for all frames.">irplib_framelist_contains</a>(rawframes, <span class="stringliteral">"RA"</span>,
+                                     CPL_TYPE_DOUBLE, CPL_TRUE, 1e-5)) {
+         <span class="comment">// RA is missing in one or more headers</span>
+         <span class="comment">//  - or it varies by more than 1e-5</span>
+      }
+
+       <span class="keywordflow">if</span> (<a class="code" href="group__irplib__framelist.html#gafed15e9e259ebad923b710f5eb0196ac" title="Verify that a property is present for all frames.">irplib_framelist_contains</a>(rawframes, <span class="stringliteral">"DEC"</span>,
+                                     CPL_TYPE_DOUBLE, CPL_TRUE, 1e-5)) {
+         <span class="comment">// DEC is missing in one or more headers</span>
+         <span class="comment">//  - or it varies by more than 1e-5</span>
+      }
+
+      <span class="comment">// Process the FITS cards </span>
+      plist = <a class="code" href="group__irplib__framelist.html#ga7700dadcf17db5b86409e6cef233af4c" title="Get the propertylist of the specified frame in the framelist.">irplib_framelist_get_propertylist_const</a>(rawframes, 0);
+
+      ra  = cpl_propertylist_get_double(plist, <span class="stringliteral">"RA"</span>);
+      dec = cpl_propertylist_get_double(plist, <span class="stringliteral">"DEC"</span>);
+
+      <span class="comment">// Object deallocation</span>
+      <a class="code" href="group__irplib__framelist.html#ga7a5159e9d27ef277df3fb55b331aaf26" title="Deallocate an irplib_framelist with its frames and properties.">irplib_framelist_delete</a>(allframes);
+      <a class="code" href="group__irplib__framelist.html#ga7a5159e9d27ef277df3fb55b331aaf26" title="Deallocate an irplib_framelist with its frames and properties.">irplib_framelist_delete</a>(rawframes);
+      cpl_imagelist_delete(ilist);
+
+      <span class="keywordflow">return</span> 0;
+
+   }
+</pre></div> </dd></dl>
+<hr/><h2>Function Documentation</h2>
+<a class="anchor" id="ga30cbfd003c6e6a6a42e610442f0b1bd1"></a><!-- doxytag: member="irplib_framelist.c::irplib_framelist_cast" ref="ga30cbfd003c6e6a6a42e610442f0b1bd1" args="(const cpl_frameset *frameset)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">irplib_framelist* irplib_framelist_cast </td>
+          <td>(</td>
+          <td class="paramtype">const cpl_frameset * </td>
+          <td class="paramname"> <em>frameset</em></td>
+          <td> ) </td>
+          <td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Create an irplib_framelist from a cpl_framelist. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>frameset</em> </td><td>The cpl_frameset </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>1 newly allocated irplib_framelist or NULL on error </dd></dl>
+<dl class="note"><dt><b>Note:</b></dt><dd>The returned irplib_framelist must be deallocated using <a class="el" href="group__irplib__framelist.html#ga7a5159e9d27ef277df3fb55b331aaf26" title="Deallocate an irplib_framelist with its frames and properties.">irplib_framelist_delete()</a> </dd></dl>
+
+<p>Definition at line <a class="el" href="irplib__framelist_8c_source.html#l00209">209</a> of file <a class="el" href="irplib__framelist_8c_source.html">irplib_framelist.c</a>.</p>
+
+<p>References <a class="el" href="irplib__framelist_8c_source.html#l00178">irplib_framelist_new()</a>, and <a class="el" href="irplib__framelist_8c_source.html#l00712">irplib_framelist_set()</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="gafed15e9e259ebad923b710f5eb0196ac"></a><!-- doxytag: member="irplib_framelist.c::irplib_framelist_contains" ref="gafed15e9e259ebad923b710f5eb0196ac" args="(const irplib_framelist *self, const char *key, cpl_type type, cpl_boolean is_equal, double fp_tol)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">cpl_error_code irplib_framelist_contains </td>
+          <td>(</td>
+          <td class="paramtype">const irplib_framelist * </td>
+          <td class="paramname"> <em>self</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>key</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">cpl_type </td>
+          <td class="paramname"> <em>type</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">cpl_boolean </td>
+          <td class="paramname"> <em>is_equal</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">double </td>
+          <td class="paramname"> <em>fp_tol</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Verify that a property is present for all frames. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>self</em> </td><td>The framelist to verify </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>key</em> </td><td>Property that must be present for all the frames </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>type</em> </td><td>The type the property must have, or CPL_TYPE_INVALID </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>is_equal</em> </td><td>If true, the value must be identical for all keys </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>fp_tol</em> </td><td>The non-negative tolerance for floating point comparison </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>CPL_ERROR_NONE or the relevant CPL error code </dd></dl>
+<dl class="note"><dt><b>Note:</b></dt><dd>It is allowed for a frame to have a NULL propertylist, in which case no check is performed. If type is CPL_TYPE_INVALID the check for a specific type is disabled. However, with is_equal true, all properties must nevertheless have the same type. fp_tol is used only when is_equal is true and the type is (explicitly or implicitly) CPL_TYPE_FLOAT or CPL_TYPE_DOUBLE.</dd></dl>
+<p>To verify the presence of the MJD-OBS keyword: </p>
+<div class="fragment"><pre class="fragment">       <a class="code" href="group__irplib__framelist.html#gafed15e9e259ebad923b710f5eb0196ac" title="Verify that a property is present for all frames.">irplib_framelist_contains</a>(myframes, <span class="stringliteral">"MJD-OBS"</span>, CPL_TYPE_INVALID,
+                                 CPL_FALSE, 0.0);
+</pre></div><p>To verify that the EXPTIME is identical to within 0.1 millisecond: </p>
+<div class="fragment"><pre class="fragment">       <a class="code" href="group__irplib__framelist.html#gafed15e9e259ebad923b710f5eb0196ac" title="Verify that a property is present for all frames.">irplib_framelist_contains</a>(myframes, <span class="stringliteral">"EXPTIME"</span>, CPL_TYPE_INVALID,
+                                 CPL_TRUE, 0.0001);
+</pre></div><p>To verify that the keyword "ESO INS LAMP ST" is of type boolean and that it has the same value for all frames: </p>
+<div class="fragment"><pre class="fragment">       <a class="code" href="group__irplib__framelist.html#gafed15e9e259ebad923b710f5eb0196ac" title="Verify that a property is present for all frames.">irplib_framelist_contains</a>(myframes, <span class="stringliteral">"ESO INS LAMP ST"</span>, CPL_TYPE_BOOL,
+                                 CPL_TRUE, 0.0);
+</pre></div> 
+<p>Definition at line <a class="el" href="irplib__framelist_8c_source.html#l00907">907</a> of file <a class="el" href="irplib__framelist_8c_source.html">irplib_framelist.c</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="ga7a5159e9d27ef277df3fb55b331aaf26"></a><!-- doxytag: member="irplib_framelist.c::irplib_framelist_delete" ref="ga7a5159e9d27ef277df3fb55b331aaf26" args="(irplib_framelist *self)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">void irplib_framelist_delete </td>
+          <td>(</td>
+          <td class="paramtype">irplib_framelist * </td>
+          <td class="paramname"> <em>self</em></td>
+          <td> ) </td>
+          <td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Deallocate an irplib_framelist with its frames and properties. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>self</em> </td><td>the framelist </td></tr>
+  </table>
+  </dd>
+</dl>
+
+<p>Definition at line <a class="el" href="irplib__framelist_8c_source.html#l00191">191</a> of file <a class="el" href="irplib__framelist_8c_source.html">irplib_framelist.c</a>.</p>
+
+<p>References <a class="el" href="irplib__framelist_8c_source.html#l00847">irplib_framelist_empty()</a>.</p>
+
+<p>Referenced by <a class="el" href="irplib__framelist_8c_source.html#l00290">irplib_framelist_extract()</a>, and <a class="el" href="irplib__framelist_8c_source.html#l00360">irplib_framelist_extract_regexp()</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="ga900ea254d9b2a2e4e3957360bbae4deb"></a><!-- doxytag: member="irplib_framelist.c::irplib_framelist_empty" ref="ga900ea254d9b2a2e4e3957360bbae4deb" args="(irplib_framelist *self)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">void irplib_framelist_empty </td>
+          <td>(</td>
+          <td class="paramtype">irplib_framelist * </td>
+          <td class="paramname"> <em>self</em></td>
+          <td> ) </td>
+          <td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Erase all frames from a framelist. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>self</em> </td><td>The framelist to modify, or NULL </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>CPL_ERROR_NONE or the relevant CPL error code </dd></dl>
+
+<p>Definition at line <a class="el" href="irplib__framelist_8c_source.html#l00847">847</a> of file <a class="el" href="irplib__framelist_8c_source.html">irplib_framelist.c</a>.</p>
+
+<p>Referenced by <a class="el" href="irplib__framelist_8c_source.html#l00191">irplib_framelist_delete()</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="gac66ea3ad4fc98c171f8b840229fe54ce"></a><!-- doxytag: member="irplib_framelist.c::irplib_framelist_erase" ref="gac66ea3ad4fc98c171f8b840229fe54ce" args="(irplib_framelist *self, int pos)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">cpl_error_code irplib_framelist_erase </td>
+          <td>(</td>
+          <td class="paramtype">irplib_framelist * </td>
+          <td class="paramname"> <em>self</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">int </td>
+          <td class="paramname"> <em>pos</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Erase a frame from a framelist and delete it and its propertylist. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>self</em> </td><td>The non-empty framelist to modify </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>pos</em> </td><td>position of frame to delete (0 for first). </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>CPL_ERROR_NONE or the relevant CPL error code </dd></dl>
+
+<p>Definition at line <a class="el" href="irplib__framelist_8c_source.html#l00751">751</a> of file <a class="el" href="irplib__framelist_8c_source.html">irplib_framelist.c</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="ga86d6746d1c19356417815f7df04c3396"></a><!-- doxytag: member="irplib_framelist.c::irplib_framelist_extract" ref="ga86d6746d1c19356417815f7df04c3396" args="(const irplib_framelist *self, const char *tag)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">irplib_framelist* irplib_framelist_extract </td>
+          <td>(</td>
+          <td class="paramtype">const irplib_framelist * </td>
+          <td class="paramname"> <em>self</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>tag</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Extract the frames with the given tag from a framelist. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>self</em> </td><td>A non-empty framelist </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>tag</em> </td><td>The frame tag to search for. </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>The newly created framelist or NULL on error </dd></dl>
+<dl class="see"><dt><b>See also:</b></dt><dd>cpl_frameset_find </dd></dl>
+<dl class="note"><dt><b>Note:</b></dt><dd>Any propertylists of the extracted frames are also extracted. It is an error if no matching frames are found, in which case an error is set. </dd></dl>
+
+<p>Definition at line <a class="el" href="irplib__framelist_8c_source.html#l00290">290</a> of file <a class="el" href="irplib__framelist_8c_source.html">irplib_framelist.c</a>.</p>
+
+<p>References <a class="el" href="irplib__framelist_8c_source.html#l00191">irplib_framelist_delete()</a>, <a class="el" href="irplib__framelist_8c_source.html#l00178">irplib_framelist_new()</a>, and <a class="el" href="irplib__framelist_8c_source.html#l00712">irplib_framelist_set()</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="gace77e5ae75183a22a0e5af9dd9018b01"></a><!-- doxytag: member="irplib_framelist.c::irplib_framelist_extract_regexp" ref="gace77e5ae75183a22a0e5af9dd9018b01" args="(const irplib_framelist *self, const char *regexp, cpl_boolean invert)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">irplib_framelist* irplib_framelist_extract_regexp </td>
+          <td>(</td>
+          <td class="paramtype">const irplib_framelist * </td>
+          <td class="paramname"> <em>self</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>regexp</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">cpl_boolean </td>
+          <td class="paramname"> <em>invert</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Extract the frames with the given tag from a framelist. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>self</em> </td><td>A non-empty framelist </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>regexp</em> </td><td>The regular expression of frame tag(s) to search for. </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>invert</em> </td><td>Boolean to invert the sense of the pattern matching. </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>The newly created framelist or NULL on error </dd></dl>
+<dl class="see"><dt><b>See also:</b></dt><dd><a class="el" href="group__irplib__framelist.html#ga86d6746d1c19356417815f7df04c3396" title="Extract the frames with the given tag from a framelist.">irplib_framelist_extract</a> </dd></dl>
+
+<p>Definition at line <a class="el" href="irplib__framelist_8c_source.html#l00360">360</a> of file <a class="el" href="irplib__framelist_8c_source.html">irplib_framelist.c</a>.</p>
+
+<p>References <a class="el" href="irplib__framelist_8c_source.html#l00191">irplib_framelist_delete()</a>, <a class="el" href="irplib__framelist_8c_source.html#l00178">irplib_framelist_new()</a>, and <a class="el" href="irplib__framelist_8c_source.html#l00712">irplib_framelist_set()</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="gaba8797bbb8394f5574cd88b2f1984387"></a><!-- doxytag: member="irplib_framelist.c::irplib_framelist_get" ref="gaba8797bbb8394f5574cd88b2f1984387" args="(irplib_framelist *self, int pos)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">cpl_frame* irplib_framelist_get </td>
+          <td>(</td>
+          <td class="paramtype">irplib_framelist * </td>
+          <td class="paramname"> <em>self</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">int </td>
+          <td class="paramname"> <em>pos</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Get the specified frame from the framelist. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>self</em> </td><td>The framelist </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>pos</em> </td><td>position (0 for first) </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>The frame or NULL on error </dd></dl>
+
+<p>Definition at line <a class="el" href="irplib__framelist_8c_source.html#l00456">456</a> of file <a class="el" href="irplib__framelist_8c_source.html">irplib_framelist.c</a>.</p>
+
+<p>References <a class="el" href="irplib__framelist_8c_source.html#l00472">irplib_framelist_get_const()</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="ga93d8f903729ea4b6fcb3eca85935716f"></a><!-- doxytag: member="irplib_framelist.c::irplib_framelist_get_const" ref="ga93d8f903729ea4b6fcb3eca85935716f" args="(const irplib_framelist *self, int pos)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">const cpl_frame* irplib_framelist_get_const </td>
+          <td>(</td>
+          <td class="paramtype">const irplib_framelist * </td>
+          <td class="paramname"> <em>self</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">int </td>
+          <td class="paramname"> <em>pos</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Get the specified frame from the framelist. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>self</em> </td><td>The framelist </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>pos</em> </td><td>position (0 for first) </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>The frame or NULL on error </dd></dl>
+
+<p>Definition at line <a class="el" href="irplib__framelist_8c_source.html#l00472">472</a> of file <a class="el" href="irplib__framelist_8c_source.html">irplib_framelist.c</a>.</p>
+
+<p>Referenced by <a class="el" href="irplib__framelist_8c_source.html#l00456">irplib_framelist_get()</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="gab4858b1e9164f3a6cffcf40270f89032"></a><!-- doxytag: member="irplib_framelist.c::irplib_framelist_get_propertylist" ref="gab4858b1e9164f3a6cffcf40270f89032" args="(irplib_framelist *self, int pos)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">cpl_propertylist* irplib_framelist_get_propertylist </td>
+          <td>(</td>
+          <td class="paramtype">irplib_framelist * </td>
+          <td class="paramname"> <em>self</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">int </td>
+          <td class="paramname"> <em>pos</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Get the propertylist of the specified frame in the framelist. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>self</em> </td><td>The framelist </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>pos</em> </td><td>position (0 for first) </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>The propertylist or NULL on error </dd></dl>
+<dl class="note"><dt><b>Note:</b></dt><dd>The propertylist must first be created, for example with irplib_framelist_load_propertylist(self, pos, ...), otherwise an error occurs. </dd></dl>
+
+<p>Definition at line <a class="el" href="irplib__framelist_8c_source.html#l00528">528</a> of file <a class="el" href="irplib__framelist_8c_source.html">irplib_framelist.c</a>.</p>
+
+<p>References <a class="el" href="irplib__framelist_8c_source.html#l00550">irplib_framelist_get_propertylist_const()</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="ga7700dadcf17db5b86409e6cef233af4c"></a><!-- doxytag: member="irplib_framelist.c::irplib_framelist_get_propertylist_const" ref="ga7700dadcf17db5b86409e6cef233af4c" args="(const irplib_framelist *self, int pos)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">const cpl_propertylist* irplib_framelist_get_propertylist_const </td>
+          <td>(</td>
+          <td class="paramtype">const irplib_framelist * </td>
+          <td class="paramname"> <em>self</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">int </td>
+          <td class="paramname"> <em>pos</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Get the propertylist of the specified frame in the framelist. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>self</em> </td><td>The framelist </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>pos</em> </td><td>position (0 for first) </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>The propertylist or NULL on error </dd></dl>
+<dl class="note"><dt><b>Note:</b></dt><dd>The propertylist must first be created, for example with irplib_framelist_load_propertylist(self, pos, ...), otherwise an error occurs. </dd></dl>
+
+<p>Definition at line <a class="el" href="irplib__framelist_8c_source.html#l00550">550</a> of file <a class="el" href="irplib__framelist_8c_source.html">irplib_framelist.c</a>.</p>
+
+<p>Referenced by <a class="el" href="irplib__framelist_8c_source.html#l00528">irplib_framelist_get_propertylist()</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="ga2518fce55112b5008cb119a126e593d7"></a><!-- doxytag: member="irplib_framelist.c::irplib_framelist_get_size" ref="ga2518fce55112b5008cb119a126e593d7" args="(const irplib_framelist *self)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">int irplib_framelist_get_size </td>
+          <td>(</td>
+          <td class="paramtype">const irplib_framelist * </td>
+          <td class="paramname"> <em>self</em></td>
+          <td> ) </td>
+          <td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Get the size of a framelist. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>self</em> </td><td>The framelist </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>The size or a negative number on error </dd></dl>
+
+<p>Definition at line <a class="el" href="irplib__framelist_8c_source.html#l00438">438</a> of file <a class="el" href="irplib__framelist_8c_source.html">irplib_framelist.c</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="ga6ce5701e84915514975d09e0100c6005"></a><!-- doxytag: member="irplib_framelist.c::irplib_framelist_load_propertylist" ref="ga6ce5701e84915514975d09e0100c6005" args="(irplib_framelist *self, int pos, int ind, const char *regexp, cpl_boolean invert)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">cpl_error_code irplib_framelist_load_propertylist </td>
+          <td>(</td>
+          <td class="paramtype">irplib_framelist * </td>
+          <td class="paramname"> <em>self</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">int </td>
+          <td class="paramname"> <em>pos</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">int </td>
+          <td class="paramname"> <em>ind</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>regexp</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">cpl_boolean </td>
+          <td class="paramname"> <em>invert</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Load the propertylist of the specified frame in the framelist. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>self</em> </td><td>The framelist to modify </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>pos</em> </td><td>position (0 for first). </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>ind</em> </td><td>The index of the date set to read </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>regexp</em> </td><td>The regular expression of properties to load </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>invert</em> </td><td>Boolean to invert the sense of the pattern matching. </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>CPL_ERROR_NONE or the relevant CPL error code </dd></dl>
+<dl class="see"><dt><b>See also:</b></dt><dd>cpl_propertylist_load_regexp() </dd></dl>
+<dl class="note"><dt><b>Note:</b></dt><dd>Use a regexp of ".?" to load all properties. If a propertylist already exists it is deleted and replaced by the new one. </dd></dl>
+
+<p>Definition at line <a class="el" href="irplib__framelist_8c_source.html#l00581">581</a> of file <a class="el" href="irplib__framelist_8c_source.html">irplib_framelist.c</a>.</p>
+
+<p>Referenced by <a class="el" href="irplib__framelist_8c_source.html#l00636">irplib_framelist_load_propertylist_all()</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="gaf9204681e0b6aa2d952c974dcbd8729d"></a><!-- doxytag: member="irplib_framelist.c::irplib_framelist_load_propertylist_all" ref="gaf9204681e0b6aa2d952c974dcbd8729d" args="(irplib_framelist *self, int ind, const char *regexp, cpl_boolean invert)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">cpl_error_code irplib_framelist_load_propertylist_all </td>
+          <td>(</td>
+          <td class="paramtype">irplib_framelist * </td>
+          <td class="paramname"> <em>self</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">int </td>
+          <td class="paramname"> <em>ind</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>regexp</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">cpl_boolean </td>
+          <td class="paramname"> <em>invert</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Load the propertylists of all frames in the framelist. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>self</em> </td><td>The framelist to modify </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>ind</em> </td><td>The index of the date set to read </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>regexp</em> </td><td>The regular expression of properties to load </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>invert</em> </td><td>Boolean to invert the sense of the pattern matching. </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>CPL_ERROR_NONE or the relevant CPL error code </dd></dl>
+<dl class="see"><dt><b>See also:</b></dt><dd><a class="el" href="group__irplib__framelist.html#ga6ce5701e84915514975d09e0100c6005" title="Load the propertylist of the specified frame in the framelist.">irplib_framelist_load_propertylist()</a> </dd></dl>
+<dl class="note"><dt><b>Note:</b></dt><dd>Use a regexp of "" to load all properties. If a frame already has a propertylist, it is not modified (and no propertylist is loaded for that frame). </dd></dl>
+
+<p>Definition at line <a class="el" href="irplib__framelist_8c_source.html#l00636">636</a> of file <a class="el" href="irplib__framelist_8c_source.html">irplib_framelist.c</a>.</p>
+
+<p>References <a class="el" href="irplib__framelist_8c_source.html#l00581">irplib_framelist_load_propertylist()</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="ga5b86add048651f73424d2542a04946a0"></a><!-- doxytag: member="irplib_framelist.c::irplib_framelist_new" ref="ga5b86add048651f73424d2542a04946a0" args="(void)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">irplib_framelist* irplib_framelist_new </td>
+          <td>(</td>
+          <td class="paramtype">void </td>
+          <td class="paramname"></td>
+          <td> ) </td>
+          <td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Create an empty framelist. </p>
+<dl class="return"><dt><b>Returns:</b></dt><dd>1 newly allocated irplib_framelist </dd></dl>
+<dl class="note"><dt><b>Note:</b></dt><dd>The returned irplib_framelist must be deallocated using <a class="el" href="group__irplib__framelist.html#ga7a5159e9d27ef277df3fb55b331aaf26" title="Deallocate an irplib_framelist with its frames and properties.">irplib_framelist_delete()</a> </dd></dl>
+
+<p>Definition at line <a class="el" href="irplib__framelist_8c_source.html#l00178">178</a> of file <a class="el" href="irplib__framelist_8c_source.html">irplib_framelist.c</a>.</p>
+
+<p>Referenced by <a class="el" href="irplib__framelist_8c_source.html#l00209">irplib_framelist_cast()</a>, <a class="el" href="irplib__framelist_8c_source.html#l00290">irplib_framelist_extract()</a>, and <a class="el" href="irplib__framelist_8c_source.html#l00360">irplib_framelist_extract_regexp()</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="ga37e730f5627b4a0c7a81014f62421879"></a><!-- doxytag: member="irplib_framelist.c::irplib_framelist_set" ref="ga37e730f5627b4a0c7a81014f62421879" args="(irplib_framelist *self, cpl_frame *frame, int pos)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">cpl_error_code irplib_framelist_set </td>
+          <td>(</td>
+          <td class="paramtype">irplib_framelist * </td>
+          <td class="paramname"> <em>self</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">cpl_frame * </td>
+          <td class="paramname"> <em>frame</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">int </td>
+          <td class="paramname"> <em>pos</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Add a frame to a framelist. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>self</em> </td><td>The framelist to modify </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>frame</em> </td><td>The frame to insert into the framelist </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>pos</em> </td><td>position (0 for first). </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>CPL_ERROR_NONE or the relevant CPL error code </dd></dl>
+<dl class="note"><dt><b>Note:</b></dt><dd>It is an error to call cpl_frame_delete() on a frame that is inserted in a framelist.</dd></dl>
+<p>It is allowed to specify the position equal to the size of the list. This will increment the size of the list. </p>
+
+<p>Definition at line <a class="el" href="irplib__framelist_8c_source.html#l00712">712</a> of file <a class="el" href="irplib__framelist_8c_source.html">irplib_framelist.c</a>.</p>
+
+<p>Referenced by <a class="el" href="irplib__framelist_8c_source.html#l00209">irplib_framelist_cast()</a>, <a class="el" href="irplib__framelist_8c_source.html#l00290">irplib_framelist_extract()</a>, and <a class="el" href="irplib__framelist_8c_source.html#l00360">irplib_framelist_extract_regexp()</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="gada2c2e3f530a6dff763402eefceb5600"></a><!-- doxytag: member="irplib_framelist.c::irplib_framelist_set_propertylist" ref="gada2c2e3f530a6dff763402eefceb5600" args="(irplib_framelist *self, int pos, const cpl_propertylist *list)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">cpl_error_code irplib_framelist_set_propertylist </td>
+          <td>(</td>
+          <td class="paramtype">irplib_framelist * </td>
+          <td class="paramname"> <em>self</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">int </td>
+          <td class="paramname"> <em>pos</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const cpl_propertylist * </td>
+          <td class="paramname"> <em>list</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Duplicate a propertylist to the specified position in the framelist. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>self</em> </td><td>The framelist to modify </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>pos</em> </td><td>position (0 for first). </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>list</em> </td><td>The propertylist to copy </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>CPL_ERROR_NONE or the relevant CPL error code </dd></dl>
+
+<p>Definition at line <a class="el" href="irplib__framelist_8c_source.html#l00495">495</a> of file <a class="el" href="irplib__framelist_8c_source.html">irplib_framelist.c</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="gab11bb60e44dea926cd50ee80c7fbbd14"></a><!-- doxytag: member="irplib_framelist.c::irplib_framelist_set_tag_all" ref="gab11bb60e44dea926cd50ee80c7fbbd14" args="(irplib_framelist *self, const char *tag)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">cpl_error_code irplib_framelist_set_tag_all </td>
+          <td>(</td>
+          <td class="paramtype">irplib_framelist * </td>
+          <td class="paramname"> <em>self</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>tag</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Set the tag of all frames in the list. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>self</em> </td><td>The framelist to modify </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>tag</em> </td><td>The new tag of the frames </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>CPL_ERROR_NONE or the relevant _cpl_error_code_ </dd></dl>
+
+<p>Definition at line <a class="el" href="irplib__framelist_8c_source.html#l00680">680</a> of file <a class="el" href="irplib__framelist_8c_source.html">irplib_framelist.c</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="ga771f14f97f80a9bd7176d323999c9bce"></a><!-- doxytag: member="irplib_framelist.c::irplib_framelist_unset" ref="ga771f14f97f80a9bd7176d323999c9bce" args="(irplib_framelist *self, int pos, cpl_propertylist **plist)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">cpl_frame* irplib_framelist_unset </td>
+          <td>(</td>
+          <td class="paramtype">irplib_framelist * </td>
+          <td class="paramname"> <em>self</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">int </td>
+          <td class="paramname"> <em>pos</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">cpl_propertylist ** </td>
+          <td class="paramname"> <em>plist</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Erase a frame from a framelist and return it to the caller. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>self</em> </td><td>The non-empty framelist to modify </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>pos</em> </td><td>position of frame to delete (0 for first). </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>plist</em> </td><td>Pointer to a propertylist or NULL </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>CPL_ERROR_NONE or the relevant CPL error code</dd></dl>
+<p>The specified frame is removed from the framelist and its size is decreased by one. The frame is returned to the caller. The caller may also retrieve the propertylist of the frame by passing a non-NULL pointer. On success this may point to NULL, if a propertylist was not created for the frame. If the caller passes a NULL-pointer for the propertylist, the propertylist is deallocated. </p>
+
+<p>Definition at line <a class="el" href="irplib__framelist_8c_source.html#l00801">801</a> of file <a class="el" href="irplib__framelist_8c_source.html">irplib_framelist.c</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="gabeedce2770a1bc06c26c0891a41aa174"></a><!-- doxytag: member="irplib_framelist.c::irplib_frameset_cast" ref="gabeedce2770a1bc06c26c0891a41aa174" args="(const irplib_framelist *self)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">cpl_frameset* irplib_frameset_cast </td>
+          <td>(</td>
+          <td class="paramtype">const irplib_framelist * </td>
+          <td class="paramname"> <em>self</em></td>
+          <td> ) </td>
+          <td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Create a CPL frameset from an irplib_framelist. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>self</em> </td><td>The framelist </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>1 newly allocated cpl_frameset or NULL on error </dd></dl>
+<dl class="note"><dt><b>Note:</b></dt><dd>The returned cpl_frameset must be deallocated using cpl_frameset_delete() </dd></dl>
+
+<p>Definition at line <a class="el" href="irplib__framelist_8c_source.html#l00251">251</a> of file <a class="el" href="irplib__framelist_8c_source.html">irplib_framelist.c</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="ga0ff6c5e3b778c607544ca04ca3fb9e94"></a><!-- doxytag: member="irplib_framelist.c::irplib_imagelist_load_framelist" ref="ga0ff6c5e3b778c607544ca04ca3fb9e94" args="(const irplib_framelist *self, cpl_type pixeltype, int planenum, int extnum)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">cpl_imagelist* irplib_imagelist_load_framelist </td>
+          <td>(</td>
+          <td class="paramtype">const irplib_framelist * </td>
+          <td class="paramname"> <em>self</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">cpl_type </td>
+          <td class="paramname"> <em>pixeltype</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">int </td>
+          <td class="paramname"> <em>planenum</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">int </td>
+          <td class="paramname"> <em>extnum</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Load an imagelist from a framelist. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>self</em> </td><td>The framelist </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>pixeltype</em> </td><td>The required type of the pixels in the images </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>planenum</em> </td><td>The (non-negative ) plane number </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>extnum</em> </td><td>The non-negative extension (0 for primary data unit) </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>The loaded list of images or NULL on error. </dd></dl>
+<dl class="see"><dt><b>See also:</b></dt><dd>cpl_image_load() </dd></dl>
+<dl class="note"><dt><b>Note:</b></dt><dd>The returned cpl_imagelist must be deallocated using cpl_imagelist_delete() </dd></dl>
+
+<p>Definition at line <a class="el" href="irplib__framelist_8c_source.html#l01050">1050</a> of file <a class="el" href="irplib__framelist_8c_source.html">irplib_framelist.c</a>.</p>
+
+</div>
+</div>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__irplib__oddeven.html b/html/group__irplib__oddeven.html
new file mode 100644
index 0000000..c29966a
--- /dev/null
+++ b/html/group__irplib__oddeven.html
@@ -0,0 +1,100 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Odd/Even column effect correction</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Odd/Even column effect correction</h1><table border="0" cellpadding="0" cellspacing="0">
+<tr><td colspan="2"><h2>Functions</h2></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__oddeven.html#gade0423dfae726cc1ffec66a24e376505">irplib_oddeven_monitor</a> (const cpl_image *in, int iquad, double *r_even)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Estimate the odd/even rate in an image quadrant.  <a href="#gade0423dfae726cc1ffec66a24e376505"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">cpl_image * </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__oddeven.html#ga7f7dafc1436a0aa2617048e1ada84e95">irplib_oddeven_correct</a> (const cpl_image *in)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Correct the odd/even in an image.  <a href="#ga7f7dafc1436a0aa2617048e1ada84e95"></a><br/></td></tr>
+</table>
+<hr/><h2>Function Documentation</h2>
+<a class="anchor" id="ga7f7dafc1436a0aa2617048e1ada84e95"></a><!-- doxytag: member="irplib_oddeven.c::irplib_oddeven_correct" ref="ga7f7dafc1436a0aa2617048e1ada84e95" args="(const cpl_image *in)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">cpl_image* irplib_oddeven_correct </td>
+          <td>(</td>
+          <td class="paramtype">const cpl_image * </td>
+          <td class="paramname"> <em>in</em></td>
+          <td> ) </td>
+          <td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Correct the odd/even in an image. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>in</em> </td><td>the inpute image </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>the corrected image or NULL on error case </dd></dl>
+
+<p>Definition at line <a class="el" href="irplib__oddeven_8c_source.html#l00152">152</a> of file <a class="el" href="irplib__oddeven_8c_source.html">irplib_oddeven.c</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="gade0423dfae726cc1ffec66a24e376505"></a><!-- doxytag: member="irplib_oddeven.c::irplib_oddeven_monitor" ref="gade0423dfae726cc1ffec66a24e376505" args="(const cpl_image *in, int iquad, double *r_even)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">int irplib_oddeven_monitor </td>
+          <td>(</td>
+          <td class="paramtype">const cpl_image * </td>
+          <td class="paramname"> <em>in</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">int </td>
+          <td class="paramname"> <em>iquad</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">double * </td>
+          <td class="paramname"> <em>r_even</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Estimate the odd/even rate in an image quadrant. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>in</em> </td><td>the inpute image </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>iquad</em> </td><td>the quadrant (ll=1, lr=2, ul=3, ur=4, all=0) </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>r_even</em> </td><td>the median of even columns / median of all columns </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>0 if ok, -1 otherwise </dd></dl>
+
+<p>Definition at line <a class="el" href="irplib__oddeven_8c_source.html#l00065">65</a> of file <a class="el" href="irplib__oddeven_8c_source.html">irplib_oddeven.c</a>.</p>
+
+</div>
+</div>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__irplib__plugin.html b/html/group__irplib__plugin.html
new file mode 100644
index 0000000..2f79190
--- /dev/null
+++ b/html/group__irplib__plugin.html
@@ -0,0 +1,21 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Irplib plugin functionality</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Irplib plugin functionality</h1><table border="0" cellpadding="0" cellspacing="0">
+</table>
+<p>This module provides a macro and a unit test function for <em>irplib_plugin</em>.</p>
+<div class="fragment"><pre class="fragment"><span class="preprocessor">   #include "irplib_plugin.h"</span>
+</pre></div> </div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__irplib__polynomial.html b/html/group__irplib__polynomial.html
new file mode 100644
index 0000000..235c310
--- /dev/null
+++ b/html/group__irplib__polynomial.html
@@ -0,0 +1,242 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: 1D-Polynomial roots</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>1D-Polynomial roots</h1><table border="0" cellpadding="0" cellspacing="0">
+<tr><td colspan="2"><h2>Functions</h2></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">cpl_error_code </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__polynomial.html#ga90e13f05c9addc584f154279681d1853">irplib_polynomial_add</a> (cpl_polynomial *self, const cpl_polynomial *first, const cpl_polynomial *second)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Add two polynomials of the same dimension.  <a href="#ga90e13f05c9addc584f154279681d1853"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">cpl_error_code </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__polynomial.html#ga0e83ae3c9e7accb70fdfe1aca030e084">irplib_polynomial_subtract</a> (cpl_polynomial *self, const cpl_polynomial *first, const cpl_polynomial *second)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Subtract two polynomials of the same dimension.  <a href="#ga0e83ae3c9e7accb70fdfe1aca030e084"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">cpl_error_code </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__polynomial.html#ga55c030413e6ef112753b280ad5213786">irplib_polynomial_multiply_scalar</a> (cpl_polynomial *self, const cpl_polynomial *other, double factor)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Multiply a polynomial with a scalar.  <a href="#ga55c030413e6ef112753b280ad5213786"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">cpl_error_code </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__polynomial.html#ga87e84d69eadbde803fce3c3cbdedf385">irplib_polynomial_solve_1d_all</a> (const cpl_polynomial *self, cpl_vector *roots, cpl_size *preal)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Compute all n roots of p(x) = 0, where p(x) is of degree n, n > 0.  <a href="#ga87e84d69eadbde803fce3c3cbdedf385"></a><br/></td></tr>
+</table>
+<hr/><h2>Function Documentation</h2>
+<a class="anchor" id="ga90e13f05c9addc584f154279681d1853"></a><!-- doxytag: member="irplib_polynomial.c::irplib_polynomial_add" ref="ga90e13f05c9addc584f154279681d1853" args="(cpl_polynomial *self, const cpl_polynomial *first, const cpl_polynomial *second)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">cpl_error_code irplib_polynomial_add </td>
+          <td>(</td>
+          <td class="paramtype">cpl_polynomial * </td>
+          <td class="paramname"> <em>self</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const cpl_polynomial * </td>
+          <td class="paramname"> <em>first</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const cpl_polynomial * </td>
+          <td class="paramname"> <em>second</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Add two polynomials of the same dimension. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>self</em> </td><td>The polynomial to hold the result </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>first</em> </td><td>The 1st polynomial to add </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>second</em> </td><td>The 2nd polynomial to add </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>CPL_ERROR_NONE or the relevant CPL error code </dd></dl>
+<dl class="note"><dt><b>Note:</b></dt><dd>self may be passed also as first and/or second</dd></dl>
+<p>Possible CPL error code set in this function:</p>
+<ul>
+<li>CPL_ERROR_NULL_INPUT if an input pointer is NULL</li>
+<li>CPL_ERROR_INCOMPATIBLE_INPUT if the polynomials do not have identical dimensions</li>
+<li>CPL_ERROR_UNSUPPORTED_MODE if the dimension is not 1 (FIXME) </li>
+</ul>
+
+<p>Definition at line <a class="el" href="irplib__polynomial_8c_source.html#l00134">134</a> of file <a class="el" href="irplib__polynomial_8c_source.html">irplib_polynomial.c</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="ga55c030413e6ef112753b280ad5213786"></a><!-- doxytag: member="irplib_polynomial.c::irplib_polynomial_multiply_scalar" ref="ga55c030413e6ef112753b280ad5213786" args="(cpl_polynomial *self, const cpl_polynomial *other, double factor)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">cpl_error_code irplib_polynomial_multiply_scalar </td>
+          <td>(</td>
+          <td class="paramtype">cpl_polynomial * </td>
+          <td class="paramname"> <em>self</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const cpl_polynomial * </td>
+          <td class="paramname"> <em>other</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">double </td>
+          <td class="paramname"> <em>factor</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Multiply a polynomial with a scalar. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>self</em> </td><td>The polynomial to hold the result </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>other</em> </td><td>The polynomial to scale, may equal self </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>factor</em> </td><td>The factor to multiply with </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>CPL_ERROR_NONE or the relevant CPL error code</dd></dl>
+<p>Possible CPL error code set in this function:</p>
+<ul>
+<li>CPL_ERROR_NULL_INPUT if an input pointer is NULL</li>
+<li>CPL_ERROR_UNSUPPORTED_MODE if the dimension is not 1 (FIXME) </li>
+</ul>
+
+<p>Definition at line <a class="el" href="irplib__polynomial_8c_source.html#l00253">253</a> of file <a class="el" href="irplib__polynomial_8c_source.html">irplib_polynomial.c</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="ga87e84d69eadbde803fce3c3cbdedf385"></a><!-- doxytag: member="irplib_polynomial.c::irplib_polynomial_solve_1d_all" ref="ga87e84d69eadbde803fce3c3cbdedf385" args="(const cpl_polynomial *self, cpl_vector *roots, cpl_size *preal)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">cpl_error_code irplib_polynomial_solve_1d_all </td>
+          <td>(</td>
+          <td class="paramtype">const cpl_polynomial * </td>
+          <td class="paramname"> <em>self</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">cpl_vector * </td>
+          <td class="paramname"> <em>roots</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">cpl_size * </td>
+          <td class="paramname"> <em>preal</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Compute all n roots of p(x) = 0, where p(x) is of degree n, n > 0. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>self</em> </td><td>The 1D-polynomial </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>roots</em> </td><td>A pre-allocated vector of length n to hold the roots </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>preal</em> </td><td>The number of real roots found, or undefined on error </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>CPL_ERROR_NONE or the relevant CPL error code</dd></dl>
+<p>The *preal real roots are stored first in ascending order, then follows for each pair of complex conjugate roots, the real and imaginary parts of the root in the positive imaginary half-plane, for example for a 3rd degree polynomial with 1 real root, the roots are represented as: x0 = v0 x1 = v1 + i v2 x2 = v1 - i v2, where v0, v1, v2 are the elements of the roots vector.</p>
+<p>Possible CPL error code set in this function:</p>
+<ul>
+<li>CPL_ERROR_NULL_INPUT if an input pointer is NULL</li>
+<li>CPL_ERROR_INVALID_TYPE if the polynomial has the wrong dimension</li>
+<li>CPL_ERROR_DATA_NOT_FOUND if the polynomial does not have a degree of at least 1.</li>
+<li>CPL_ERROR_INCOMPATIBLE_INPUT if the roots vector does not have length n</li>
+<li>CPL_ERROR_DIVISION_BY_ZERO if a division by zero occurs (n > 4)</li>
+<li>CPL_ERROR_CONTINUE if the algorithm does not converge (n > 4) </li>
+</ul>
+
+<p>Definition at line <a class="el" href="irplib__polynomial_8c_source.html#l00310">310</a> of file <a class="el" href="irplib__polynomial_8c_source.html">irplib_polynomial.c</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="ga0e83ae3c9e7accb70fdfe1aca030e084"></a><!-- doxytag: member="irplib_polynomial.c::irplib_polynomial_subtract" ref="ga0e83ae3c9e7accb70fdfe1aca030e084" args="(cpl_polynomial *self, const cpl_polynomial *first, const cpl_polynomial *second)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">cpl_error_code irplib_polynomial_subtract </td>
+          <td>(</td>
+          <td class="paramtype">cpl_polynomial * </td>
+          <td class="paramname"> <em>self</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const cpl_polynomial * </td>
+          <td class="paramname"> <em>first</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const cpl_polynomial * </td>
+          <td class="paramname"> <em>second</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Subtract two polynomials of the same dimension. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>self</em> </td><td>The polynomial to hold the result </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>first</em> </td><td>The polynomial to subtract from </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>second</em> </td><td>The polynomial to subtract </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>CPL_ERROR_NONE or the relevant CPL error code </dd></dl>
+<dl class="note"><dt><b>Note:</b></dt><dd>self may be passed also as first and/or second</dd></dl>
+<p>Possible CPL error code set in this function:</p>
+<ul>
+<li>CPL_ERROR_NULL_INPUT if an input pointer is NULL</li>
+<li>CPL_ERROR_INCOMPATIBLE_INPUT if the polynomials do not have identical dimensions</li>
+<li>CPL_ERROR_UNSUPPORTED_MODE if the dimension is not 1 (FIXME) </li>
+</ul>
+
+<p>Definition at line <a class="el" href="irplib__polynomial_8c_source.html#l00195">195</a> of file <a class="el" href="irplib__polynomial_8c_source.html">irplib_polynomial.c</a>.</p>
+
+</div>
+</div>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__irplib__ppm.html b/html/group__irplib__ppm.html
new file mode 100644
index 0000000..d4e54fd
--- /dev/null
+++ b/html/group__irplib__ppm.html
@@ -0,0 +1,114 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Point pattern matching</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Point pattern matching</h1><table border="0" cellpadding="0" cellspacing="0">
+<tr><td colspan="2"><h2>Functions</h2></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">cpl_polynomial * </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__ppm.html#ga9b49569fb0bd55977b533407c1ad956d">irplib_ppm_engine</a> (const cpl_vector *spectrum, const cpl_bivector *lines_catalog, const cpl_polynomial *poly_init, double slitw, double fwhm, double thresh, int degree, int doplot, cpl_table **tab_infos)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">The Wavelength Calibration using PPM.  <a href="#ga9b49569fb0bd55977b533407c1ad956d"></a><br/></td></tr>
+</table>
+<hr/><h2>Function Documentation</h2>
+<a class="anchor" id="ga9b49569fb0bd55977b533407c1ad956d"></a><!-- doxytag: member="irplib_ppm.c::irplib_ppm_engine" ref="ga9b49569fb0bd55977b533407c1ad956d" args="(const cpl_vector *spectrum, const cpl_bivector *lines_catalog, const cpl_polynomial *poly_init, double slitw, double fwhm, double thresh, int degree, int doplot, cpl_table **tab_infos)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">cpl_polynomial* irplib_ppm_engine </td>
+          <td>(</td>
+          <td class="paramtype">const cpl_vector * </td>
+          <td class="paramname"> <em>spectrum</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const cpl_bivector * </td>
+          <td class="paramname"> <em>lines_catalog</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const cpl_polynomial * </td>
+          <td class="paramname"> <em>poly_init</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">double </td>
+          <td class="paramname"> <em>slitw</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">double </td>
+          <td class="paramname"> <em>fwhm</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">double </td>
+          <td class="paramname"> <em>thresh</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">int </td>
+          <td class="paramname"> <em>degree</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">int </td>
+          <td class="paramname"> <em>doplot</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">cpl_table ** </td>
+          <td class="paramname"> <em>tab_infos</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>The Wavelength Calibration using PPM. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>spectrum</em> </td><td>The spectrum vector </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>lines_catalog</em> </td><td>The lines catalog </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>poly_init</em> </td><td>Polynomial with the initial guess </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>slitw</em> </td><td>The slit width </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>fwhm</em> </td><td>The spectral FWHM [pixel] </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>thresh</em> </td><td>The threshold for lines detection </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>degree</em> </td><td>The polynomial degree </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>doplot</em> </td><td>Plotting level (zero for none) </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>tab_infos</em> </td><td>The computed solution table or NULL (computed) </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>the polynomial solution or NULL in error case</dd></dl>
+<p>The returned table must be deallocated with cpl_table_delete(). The returned polynomial must be deallocated with cpl_polynomial_delete(). </p>
+
+<p>Definition at line <a class="el" href="irplib__ppm_8c_source.html#l00084">84</a> of file <a class="el" href="irplib__ppm_8c_source.html">irplib_ppm.c</a>.</p>
+
+<p>References <a class="el" href="irplib__spectrum_8c_source.html#l00273">irplib_spectrum_detect_peaks()</a>.</p>
+
+</div>
+</div>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__irplib__slitpos.html b/html/group__irplib__slitpos.html
new file mode 100644
index 0000000..a23c574
--- /dev/null
+++ b/html/group__irplib__slitpos.html
@@ -0,0 +1,80 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Functions for slit position</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Functions for slit position</h1><table border="0" cellpadding="0" cellspacing="0">
+<tr><td colspan="2"><h2>Functions</h2></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">cpl_table * </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__slitpos.html#ga632b21eccf3d4bb48426cdd23f321cba">irplib_slitpos_analysis</a> (const cpl_image *imslit, int slit_max_width, double *slit_flux)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Detect the slit position, detect its ends, extract a thin image containing only the slit and find its edges.  <a href="#ga632b21eccf3d4bb48426cdd23f321cba"></a><br/></td></tr>
+</table>
+<hr/><h2>Function Documentation</h2>
+<a class="anchor" id="ga632b21eccf3d4bb48426cdd23f321cba"></a><!-- doxytag: member="irplib_slitpos.c::irplib_slitpos_analysis" ref="ga632b21eccf3d4bb48426cdd23f321cba" args="(const cpl_image *imslit, int slit_max_width, double *slit_flux)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">cpl_table* irplib_slitpos_analysis </td>
+          <td>(</td>
+          <td class="paramtype">const cpl_image * </td>
+          <td class="paramname"> <em>imslit</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">int </td>
+          <td class="paramname"> <em>slit_max_width</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">double * </td>
+          <td class="paramname"> <em>slit_flux</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Detect the slit position, detect its ends, extract a thin image containing only the slit and find its edges. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>imslit</em> </td><td>Input image with a vertical slit </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>slit_max_width</em> </td><td>Maximum slit width </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>slit_flux</em> </td><td>Some of the pixels values of the slit </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>the table with the slit position or NULL on error</dd></dl>
+<p>On success the created table contains rows of four columns labeled: "SLIT_Y" (int) "SLIT_LEFT" (double) "SLIT_CENTER" (double) "SLIT_RIGHT" (double)</p>
+<p>This function returns a table with 3 columns:</p>
+<ul>
+<li>Left or Lower edge of the slit</li>
+<li>Center of the slit</li>
+<li>Right or Upper edge of the slit</li>
+</ul>
+<p>Additionally, the slit flux is computed. The passed slit_flux pointer parameter can be NULL. In error case, its value is undefined.</p>
+<p>NB: Coordinates use FITS convention. </p>
+
+<p>Definition at line <a class="el" href="irplib__slitpos_8c_source.html#l00119">119</a> of file <a class="el" href="irplib__slitpos_8c_source.html">irplib_slitpos.c</a>.</p>
+
+<p>References <a class="el" href="irplib__flat_8c_source.html#l00191">irplib_flat_fit_slope_robust()</a>.</p>
+
+</div>
+</div>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__irplib__spectrum.html b/html/group__irplib__spectrum.html
new file mode 100644
index 0000000..930c6fe
--- /dev/null
+++ b/html/group__irplib__spectrum.html
@@ -0,0 +1,162 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Functions for LSS spectra</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Functions for LSS spectra</h1><table border="0" cellpadding="0" cellspacing="0">
+<tr><td colspan="2"><h2>Functions</h2></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__spectrum.html#ga9ac928ba9a48e864b56e921c970638c0">irplib_spectrum_find_brightest</a> (const cpl_image *in, int offset, spec_shadows shadows, double min_bright, int orient, double *pos)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Finds the brightest spectrum in an image.  <a href="#ga9ac928ba9a48e864b56e921c970638c0"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">cpl_vector * </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__spectrum.html#ga1885902c29d7383674c85e2c3d935961">irplib_spectrum_detect_peaks</a> (const cpl_vector *in, int fwhm, double sigma, int display, cpl_vector **fwhms_out, cpl_vector **areas_out)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Detect the brightest features in a spectrum.  <a href="#ga1885902c29d7383674c85e2c3d935961"></a><br/></td></tr>
+</table>
+<hr/><h2>Function Documentation</h2>
+<a class="anchor" id="ga1885902c29d7383674c85e2c3d935961"></a><!-- doxytag: member="irplib_spectrum.c::irplib_spectrum_detect_peaks" ref="ga1885902c29d7383674c85e2c3d935961" args="(const cpl_vector *in, int fwhm, double sigma, int display, cpl_vector **fwhms_out, cpl_vector **areas_out)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">cpl_vector* irplib_spectrum_detect_peaks </td>
+          <td>(</td>
+          <td class="paramtype">const cpl_vector * </td>
+          <td class="paramname"> <em>in</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">int </td>
+          <td class="paramname"> <em>fwhm</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">double </td>
+          <td class="paramname"> <em>sigma</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">int </td>
+          <td class="paramname"> <em>display</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">cpl_vector ** </td>
+          <td class="paramname"> <em>fwhms_out</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">cpl_vector ** </td>
+          <td class="paramname"> <em>areas_out</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Detect the brightest features in a spectrum. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>in</em> </td><td>the spectrum </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>fwhm</em> </td><td>the FWHM used for the lines convolution </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>display</em> </td><td>the flag to display </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>fwhms</em> </td><td>the fwhms of the detected lines </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>areas</em> </td><td>the areas under the detected lines </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>The bright lines positions or NULL in error case</dd></dl>
+<p>The lines positions are in pixels (first pixel is 1) </p>
+
+<p>Definition at line <a class="el" href="irplib__spectrum_8c_source.html#l00273">273</a> of file <a class="el" href="irplib__spectrum_8c_source.html">irplib_spectrum.c</a>.</p>
+
+<p>Referenced by <a class="el" href="irplib__ppm_8c_source.html#l00084">irplib_ppm_engine()</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="ga9ac928ba9a48e864b56e921c970638c0"></a><!-- doxytag: member="irplib_spectrum.c::irplib_spectrum_find_brightest" ref="ga9ac928ba9a48e864b56e921c970638c0" args="(const cpl_image *in, int offset, spec_shadows shadows, double min_bright, int orient, double *pos)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">int irplib_spectrum_find_brightest </td>
+          <td>(</td>
+          <td class="paramtype">const cpl_image * </td>
+          <td class="paramname"> <em>in</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">int </td>
+          <td class="paramname"> <em>offset</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">spec_shadows </td>
+          <td class="paramname"> <em>shadows</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">double </td>
+          <td class="paramname"> <em>min_bright</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">int </td>
+          <td class="paramname"> <em>orient</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">double * </td>
+          <td class="paramname"> <em>pos</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Finds the brightest spectrum in an image. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>in</em> </td><td>spectral image with spectra </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>offset</em> </td><td>the diff. between pos. and neg. spectra </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>shadows</em> </td><td>the spectral shadows </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>min_bright</em> </td><td>min. bright. required for a spectrum </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>orient</em> </td><td>1 for vertical spec. 0 for horizontal ones </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>pos</em> </td><td>the computed spectrum position (1->npix) </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>int 0 if ok, -1 in error case</dd></dl>
+<p>Finds the brightest spectrum in an image by collapsing the image orthogonally to the spectrum orientation. Spectra are assumed to be horizontal for orient==0, vertical for 1 </p>
+
+<p>Definition at line <a class="el" href="irplib__spectrum_8c_source.html#l00093">93</a> of file <a class="el" href="irplib__spectrum_8c_source.html">irplib_spectrum.c</a>.</p>
+
+</div>
+</div>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__irplib__stdstar.html b/html/group__irplib__stdstar.html
new file mode 100644
index 0000000..be6978d
--- /dev/null
+++ b/html/group__irplib__stdstar.html
@@ -0,0 +1,604 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Functions for standard stars</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Functions for standard stars</h1><table border="0" cellpadding="0" cellspacing="0">
+<tr><td colspan="2"><h2>Functions</h2></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__stdstar.html#ga1d798cc23ce72891460133af03ee21ba">irplib_stdstar_write_catalogs</a> (cpl_frameset *set_in, const cpl_frameset *set_raw, const char *recipe_name, const char *pro_cat, const char *pro_type, const char *package_name, const char *ins_name, cpl_table *(*convert_ascii_table)(const char *))</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Write the ASCII catalogs as FITS files.  <a href="#ga1d798cc23ce72891460133af03ee21ba"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">cpl_table * </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__stdstar.html#ga1690bd84c24e905e384b8f725bf7aff1">irplib_stdstar_load_catalog</a> (const char *filename, const char *ext_name)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Load the FITS catalog in a table.  <a href="#ga1690bd84c24e905e384b8f725bf7aff1"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">cpl_error_code </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__stdstar.html#ga2dbe2031bf6d669778dca42f6c343efc">irplib_stdstar_check_columns_exist</a> (const cpl_table *catal)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Check that the table has the relevant columns of a stdstar table.  <a href="#ga2dbe2031bf6d669778dca42f6c343efc"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__stdstar.html#ga080e06303f3f83a91959ac01381dc4e8">irplib_stdstar_select_stars_dist</a> (cpl_table *cat, double ra, double dec, double dist)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Select the stars that are within a given distance.  <a href="#ga080e06303f3f83a91959ac01381dc4e8"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__stdstar.html#ga28316d8f0619bdbd0040b1f56799e7ab">irplib_stdstar_select_stars_mag</a> (cpl_table *cat, const char *mag_colname)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Select the stars that have a known magnitude.  <a href="#ga28316d8f0619bdbd0040b1f56799e7ab"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__stdstar.html#ga36b4c90fd548dd0c00afe97b17a558e5">irplib_stdstar_find_closest</a> (const cpl_table *cat, double ra, double dec)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Find the closest star.  <a href="#ga36b4c90fd548dd0c00afe97b17a558e5"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">cpl_error_code </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__stdstar.html#ga4d69ae957de04b1769ac225f12834027">irplib_stdstar_find_star</a> (const char *catfile, double ra, double dec, const char *band, const char *catname, double *mag, char **name, char **type, char **usedcatname, double *star_ra, double *star_dec, double dist_am)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Find the closest star to ra, dec in the catalog.  <a href="#ga4d69ae957de04b1769ac225f12834027"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">cpl_vector * </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__stdstar.html#ga93b46d8ac857a0d0fdc781b56a91a8ba">irplib_stdstar_get_conversion</a> (const cpl_bivector *spec, double dit, double surface, double gain, double mag)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Get the conversion.  <a href="#ga93b46d8ac857a0d0fdc781b56a91a8ba"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">cpl_vector * </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__stdstar.html#ga6e68e6a9d0bbb41ef717234b9f289dab">irplib_stdstar_get_mag_zero</a> (const cpl_bivector *sed, const cpl_vector *waves, double cent_wl)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Get the 0 magnitude spectrum.  <a href="#ga6e68e6a9d0bbb41ef717234b9f289dab"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">cpl_bivector * </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__stdstar.html#gabbad67ff18cb901914caa9e864969dea">irplib_stdstar_get_sed</a> (const char *seds_file, const char *sptype)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Get the SED.  <a href="#gabbad67ff18cb901914caa9e864969dea"></a><br/></td></tr>
+</table>
+<hr/><h2>Function Documentation</h2>
+<a class="anchor" id="ga2dbe2031bf6d669778dca42f6c343efc"></a><!-- doxytag: member="irplib_stdstar.c::irplib_stdstar_check_columns_exist" ref="ga2dbe2031bf6d669778dca42f6c343efc" args="(const cpl_table *catal)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">cpl_error_code irplib_stdstar_check_columns_exist </td>
+          <td>(</td>
+          <td class="paramtype">const cpl_table * </td>
+          <td class="paramname"> <em>catal</em></td>
+          <td> ) </td>
+          <td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Check that the table has the relevant columns of a stdstar table. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>catal</em> </td><td>Table with the catalogue </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>CPL_ERROR_NONE if the table has all the mandatory columns, a proper error code otherwise</dd></dl>
+<p>The table is checked for the presence of the mandatory keywords </p>
+
+<p>Definition at line <a class="el" href="irplib__stdstar_8c_source.html#l00291">291</a> of file <a class="el" href="irplib__stdstar_8c_source.html">irplib_stdstar.c</a>.</p>
+
+<p>Referenced by <a class="el" href="irplib__stdstar_8c_source.html#l00492">irplib_stdstar_find_star()</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="ga36b4c90fd548dd0c00afe97b17a558e5"></a><!-- doxytag: member="irplib_stdstar.c::irplib_stdstar_find_closest" ref="ga36b4c90fd548dd0c00afe97b17a558e5" args="(const cpl_table *cat, double ra, double dec)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">int irplib_stdstar_find_closest </td>
+          <td>(</td>
+          <td class="paramtype">const cpl_table * </td>
+          <td class="paramname"> <em>cat</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">double </td>
+          <td class="paramname"> <em>ra</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">double </td>
+          <td class="paramname"> <em>dec</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Find the closest star. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>cat</em> </td><td>the catalog </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>ra</em> </td><td>RA pos </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>dec</em> </td><td>DEC pos </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>the index of the star in the table or -1 in error case</dd></dl>
+<p>Returns the index of the star that is closest to (ra,dec) </p>
+
+<p>Definition at line <a class="el" href="irplib__stdstar_8c_source.html#l00424">424</a> of file <a class="el" href="irplib__stdstar_8c_source.html">irplib_stdstar.c</a>.</p>
+
+<p>Referenced by <a class="el" href="irplib__stdstar_8c_source.html#l00492">irplib_stdstar_find_star()</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="ga4d69ae957de04b1769ac225f12834027"></a><!-- doxytag: member="irplib_stdstar.c::irplib_stdstar_find_star" ref="ga4d69ae957de04b1769ac225f12834027" args="(const char *catfile, double ra, double dec, const char *band, const char *catname, double *mag, char **name, char **type, char **usedcatname, double *star_ra, double *star_dec, double dist_am)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">cpl_error_code irplib_stdstar_find_star </td>
+          <td>(</td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>catfile</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">double </td>
+          <td class="paramname"> <em>ra</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">double </td>
+          <td class="paramname"> <em>dec</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>band</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>catname</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">double * </td>
+          <td class="paramname"> <em>mag</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">char ** </td>
+          <td class="paramname"> <em>name</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">char ** </td>
+          <td class="paramname"> <em>type</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">char ** </td>
+          <td class="paramname"> <em>usedcatname</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">double * </td>
+          <td class="paramname"> <em>star_ra</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">double * </td>
+          <td class="paramname"> <em>star_dec</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">double </td>
+          <td class="paramname"> <em>dist_am</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Find the closest star to ra, dec in the catalog. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>catfile</em> </td><td>the catalog file name </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>ra</em> </td><td>RA pos where to search </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>dec</em> </td><td>DEC pos where to search </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>band</em> </td><td>the band name </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>catname</em> </td><td>the searched catalog name </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>mag</em> </td><td>the computed magnitude (output) </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>name</em> </td><td>the star name (output) </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>type</em> </td><td>the star type (output) </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>star_ra</em> </td><td>the star RA from the catalog (output) </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>star_dec</em> </td><td>the star DEC from the catalog (output) </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>dist_am</em> </td><td>the distance in arc minutes </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>CPL_ERROR_NONE if ok, or an appropiate error case otherwise</dd></dl>
+<p>The closest star to ra, dec with defined magnitude is search in all the catalogues included in catfile. If catname is "all", all the catalogs are searched at once. The output pointers can be NULL if one is not interested in them. </p>
+
+<p>Definition at line <a class="el" href="irplib__stdstar_8c_source.html#l00492">492</a> of file <a class="el" href="irplib__stdstar_8c_source.html">irplib_stdstar.c</a>.</p>
+
+<p>References <a class="el" href="irplib__stdstar_8c_source.html#l00291">irplib_stdstar_check_columns_exist()</a>, <a class="el" href="irplib__stdstar_8c_source.html#l00424">irplib_stdstar_find_closest()</a>, <a class="el" href="irplib__stdstar_8c_source.html#l00186">irplib_stdstar_load_catalog()</a>, <a class="el" href="irplib__stdstar_8c_source.html#l00339">irplib_stdstar_select_stars_dist()</a>, and <a class="el" href="irplib__stdstar_8c_source.html#l00388">irplib_stdstar_select_stars [...]
+
+</div>
+</div>
+<a class="anchor" id="ga93b46d8ac857a0d0fdc781b56a91a8ba"></a><!-- doxytag: member="irplib_stdstar.c::irplib_stdstar_get_conversion" ref="ga93b46d8ac857a0d0fdc781b56a91a8ba" args="(const cpl_bivector *spec, double dit, double surface, double gain, double mag)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">cpl_vector* irplib_stdstar_get_conversion </td>
+          <td>(</td>
+          <td class="paramtype">const cpl_bivector * </td>
+          <td class="paramname"> <em>spec</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">double </td>
+          <td class="paramname"> <em>dit</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">double </td>
+          <td class="paramname"> <em>surface</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">double </td>
+          <td class="paramname"> <em>gain</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">double </td>
+          <td class="paramname"> <em>mag</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Get the conversion. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>spec</em> </td><td>the extracted spectrum </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>dit</em> </td><td>the DIT (in sec) </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>surface</em> </td><td>the surface of the miror (in sq cm) </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>gain</em> </td><td>the gain of the instrument (ISAAC=4.5, SINFONI=2.42) </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>mag</em> </td><td>the star magnitude </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>the newly allocated conversion or NULL in error case</dd></dl>
+<p>conversion(wave) = (spec * gain * 10^(mag/2.5) * h * c) / (dit * surface * dispersion * wave) </p>
+
+<p>Definition at line <a class="el" href="irplib__stdstar_8c_source.html#l00600">600</a> of file <a class="el" href="irplib__stdstar_8c_source.html">irplib_stdstar.c</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="ga6e68e6a9d0bbb41ef717234b9f289dab"></a><!-- doxytag: member="irplib_stdstar.c::irplib_stdstar_get_mag_zero" ref="ga6e68e6a9d0bbb41ef717234b9f289dab" args="(const cpl_bivector *sed, const cpl_vector *waves, double cent_wl)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">cpl_vector* irplib_stdstar_get_mag_zero </td>
+          <td>(</td>
+          <td class="paramtype">const cpl_bivector * </td>
+          <td class="paramname"> <em>sed</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const cpl_vector * </td>
+          <td class="paramname"> <em>waves</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">double </td>
+          <td class="paramname"> <em>cent_wl</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Get the 0 magnitude spectrum. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>sed</em> </td><td>the SED in angstroms / ergs/s/cm^2/Angstrom </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>waves</em> </td><td>the wavelengths in angstroms </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>cent_wl</em> </td><td>the central wavelength in microns </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>the newly allocated spectrum or NULL in error case </dd></dl>
+
+<p>Definition at line <a class="el" href="irplib__stdstar_8c_source.html#l00659">659</a> of file <a class="el" href="irplib__stdstar_8c_source.html">irplib_stdstar.c</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="gabbad67ff18cb901914caa9e864969dea"></a><!-- doxytag: member="irplib_stdstar.c::irplib_stdstar_get_sed" ref="gabbad67ff18cb901914caa9e864969dea" args="(const char *seds_file, const char *sptype)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">cpl_bivector* irplib_stdstar_get_sed </td>
+          <td>(</td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>seds_file</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>sptype</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Get the SED. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>seds_file</em> </td><td>the table file name </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>sptype</em> </td><td>the requested spectral type </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>the newly allocated SED or NULL in error case</dd></dl>
+<p>wavelength in Angstroms SED in </p>
+
+<p>Definition at line <a class="el" href="irplib__stdstar_8c_source.html#l00762">762</a> of file <a class="el" href="irplib__stdstar_8c_source.html">irplib_stdstar.c</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="ga1690bd84c24e905e384b8f725bf7aff1"></a><!-- doxytag: member="irplib_stdstar.c::irplib_stdstar_load_catalog" ref="ga1690bd84c24e905e384b8f725bf7aff1" args="(const char *filename, const char *ext_name)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">cpl_table* irplib_stdstar_load_catalog </td>
+          <td>(</td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>filename</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>ext_name</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Load the FITS catalog in a table. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>filename</em> </td><td>Name of the FITS catalog </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>ext_name</em> </td><td>Name of the catalog or "all" </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>The newly allocated table orNULL in error case.</dd></dl>
+<p>The table is loaded from the specified extension. If "all" is specified, all extension with the same columns as the first one are loaded and put together in the returned table.</p>
+<p>The returned table must be de allocated with cpl_table_delete(). </p>
+
+<p>Definition at line <a class="el" href="irplib__stdstar_8c_source.html#l00186">186</a> of file <a class="el" href="irplib__stdstar_8c_source.html">irplib_stdstar.c</a>.</p>
+
+<p>Referenced by <a class="el" href="irplib__stdstar_8c_source.html#l00492">irplib_stdstar_find_star()</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="ga080e06303f3f83a91959ac01381dc4e8"></a><!-- doxytag: member="irplib_stdstar.c::irplib_stdstar_select_stars_dist" ref="ga080e06303f3f83a91959ac01381dc4e8" args="(cpl_table *cat, double ra, double dec, double dist)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">int irplib_stdstar_select_stars_dist </td>
+          <td>(</td>
+          <td class="paramtype">cpl_table * </td>
+          <td class="paramname"> <em>cat</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">double </td>
+          <td class="paramname"> <em>ra</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">double </td>
+          <td class="paramname"> <em>dec</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">double </td>
+          <td class="paramname"> <em>dist</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Select the stars that are within a given distance. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>cat</em> </td><td>the catalog </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>ra</em> </td><td>RA pos </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>dec</em> </td><td>DEC pos </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>dist</em> </td><td>the distancw </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>0 if ok, -1 in error case</dd></dl>
+<p>The stars that are within not further than dist from ra,dec are selected in the table. </p>
+
+<p>Definition at line <a class="el" href="irplib__stdstar_8c_source.html#l00339">339</a> of file <a class="el" href="irplib__stdstar_8c_source.html">irplib_stdstar.c</a>.</p>
+
+<p>Referenced by <a class="el" href="irplib__stdstar_8c_source.html#l00492">irplib_stdstar_find_star()</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="ga28316d8f0619bdbd0040b1f56799e7ab"></a><!-- doxytag: member="irplib_stdstar.c::irplib_stdstar_select_stars_mag" ref="ga28316d8f0619bdbd0040b1f56799e7ab" args="(cpl_table *cat, const char *mag_colname)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">int irplib_stdstar_select_stars_mag </td>
+          <td>(</td>
+          <td class="paramtype">cpl_table * </td>
+          <td class="paramname"> <em>cat</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>mag_colname</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Select the stars that have a known magnitude. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>cat</em> </td><td>the catalog </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>mag_colname</em> </td><td>the column name with the searched magnitude </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>0 if ok, -1 in error case</dd></dl>
+<p>The stars whose magnitude in the mag band is known are selected in the table. </p>
+
+<p>Definition at line <a class="el" href="irplib__stdstar_8c_source.html#l00388">388</a> of file <a class="el" href="irplib__stdstar_8c_source.html">irplib_stdstar.c</a>.</p>
+
+<p>Referenced by <a class="el" href="irplib__stdstar_8c_source.html#l00492">irplib_stdstar_find_star()</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="ga1d798cc23ce72891460133af03ee21ba"></a><!-- doxytag: member="irplib_stdstar.c::irplib_stdstar_write_catalogs" ref="ga1d798cc23ce72891460133af03ee21ba" args="(cpl_frameset *set_in, const cpl_frameset *set_raw, const char *recipe_name, const char *pro_cat, const char *pro_type, const char *package_name, const char *ins_name, cpl_table *(*convert_ascii_table)(const char *))" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">int irplib_stdstar_write_catalogs </td>
+          <td>(</td>
+          <td class="paramtype">cpl_frameset * </td>
+          <td class="paramname"> <em>set_in</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const cpl_frameset * </td>
+          <td class="paramname"> <em>set_raw</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>recipe_name</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>pro_cat</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>pro_type</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>package_name</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>ins_name</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">cpl_table *(*)(const char *) </td>
+          <td class="paramname"> <em>convert_ascii_table</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Write the ASCII catalogs as FITS files. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>set_in</em> </td><td>Input frameset wher the product is registered </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>set_raw</em> </td><td>Set of ASCII catalogs </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>recipe_name</em> </td><td>Recipe name </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>pro_cat</em> </td><td>PRO.CATG </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>pro_type</em> </td><td>PRO.TYPE </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>package_name</em> </td><td>Usually PACKAGE "/" PACKAGE_VERSION </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>ins_name</em> </td><td>Instrument name </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>convert_ascii_table</em> </td><td>Conversion function </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>0 if ok, -1 in error case</dd></dl>
+<p>Every catalog will be written in a different extension, where EXTNAME is the name of the catalog ASCII file name.</p>
+<p>The conversion ascii -> cpl_table is done by convert_ascii_table() and should be defined in each instrument </p>
+
+<p>Definition at line <a class="el" href="irplib__stdstar_8c_source.html#l00078">78</a> of file <a class="el" href="irplib__stdstar_8c_source.html">irplib_stdstar.c</a>.</p>
+
+</div>
+</div>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__irplib__strehl.html b/html/group__irplib__strehl.html
new file mode 100644
index 0000000..708215f
--- /dev/null
+++ b/html/group__irplib__strehl.html
@@ -0,0 +1,19 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Functions to compute the Strehl</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Functions to compute the Strehl</h1><table border="0" cellpadding="0" cellspacing="0">
+</table>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__irplib__utils.html b/html/group__irplib__utils.html
new file mode 100644
index 0000000..8637cf9
--- /dev/null
+++ b/html/group__irplib__utils.html
@@ -0,0 +1,1359 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Miscellaneous Utilities</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Miscellaneous Utilities</h1><table border="0" cellpadding="0" cellspacing="0">
+<tr><td colspan="2"><h2>Functions</h2></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__utils.html#ga6b29dac884b62ab52f43dd670d4d8386">irplib_errorstate_dump_warning</a> (unsigned self, unsigned first, unsigned last)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Dump a single CPL error at the CPL warning level.  <a href="#ga6b29dac884b62ab52f43dd670d4d8386"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__utils.html#ga901ff52a1c9dcdfcf2d2632d31064bdb">irplib_errorstate_dump_info</a> (unsigned self, unsigned first, unsigned last)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Dump a single CPL error at the CPL info level.  <a href="#ga901ff52a1c9dcdfcf2d2632d31064bdb"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__utils.html#ga26c6209e5df98978e2922a15b47b47d1">irplib_errorstate_dump_debug</a> (unsigned self, unsigned first, unsigned last)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Dump a single CPL error at the CPL debug level.  <a href="#ga26c6209e5df98978e2922a15b47b47d1"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">cpl_error_code </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__utils.html#ga346842d722834a2e6221ff2d86314b7e">irplib_dfs_save_image</a> (cpl_frameset *allframes, const cpl_parameterlist *parlist, const cpl_frameset *usedframes, const cpl_image *image, cpl_type_bpp bpp, const char *recipe, const char *procat, const cpl_propertylist *applist, const char *remregexp, const char *pipe_id, const char * [...]
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Save an image as a DFS-compliant pipeline product.  <a href="#ga346842d722834a2e6221ff2d86314b7e"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">cpl_error_code </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__utils.html#ga4dc12f321e7aeb5e67ff19f815bfd7b7">irplib_dfs_save_propertylist</a> (cpl_frameset *allframes, const cpl_parameterlist *parlist, const cpl_frameset *usedframes, const char *recipe, const char *procat, const cpl_propertylist *applist, const char *remregexp, const char *pipe_id, const char *filename)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Save a propertylist as a DFS-compliant pipeline product.  <a href="#ga4dc12f321e7aeb5e67ff19f815bfd7b7"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">cpl_error_code </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__utils.html#ga66f7adc9e165b4e934e3d57a700f55c1">irplib_dfs_save_imagelist</a> (cpl_frameset *allframes, const cpl_parameterlist *parlist, const cpl_frameset *usedframes, const cpl_imagelist *imagelist, cpl_type_bpp bpp, const char *recipe, const char *procat, const cpl_propertylist *applist, const char *remregexp, const char *pipe_id,  [...]
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Save an imagelist as a DFS-compliant pipeline product.  <a href="#ga66f7adc9e165b4e934e3d57a700f55c1"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">cpl_error_code </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__utils.html#ga62a91f8630af11164547c168660b2ade">irplib_dfs_save_table</a> (cpl_frameset *allframes, const cpl_parameterlist *parlist, const cpl_frameset *usedframes, const cpl_table *table, const cpl_propertylist *tablelist, const char *recipe, const char *procat, const cpl_propertylist *applist, const char *remregexp, const char *pipe [...]
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Save a table as a DFS-compliant pipeline product.  <a href="#ga62a91f8630af11164547c168660b2ade"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">cpl_error_code </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__utils.html#ga1fd7c2f4c00014049b0bf4bf6814b451">irplib_dfs_save_image_</a> (cpl_frameset *allframes, cpl_propertylist *header, const cpl_parameterlist *parlist, const cpl_frameset *usedframes, const cpl_frame *inherit, const cpl_image *image, cpl_type type, const char *recipe, const cpl_propertylist *applist, const char *remregexp, con [...]
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Save an image as a DFS-compliant pipeline product.  <a href="#ga1fd7c2f4c00014049b0bf4bf6814b451"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">cpl_error_code </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__utils.html#ga832676f36ecd647b77f4bb373b2d1954">irplib_image_split</a> (const cpl_image *self, cpl_image *im_low, cpl_image *im_mid, cpl_image *im_high, double th_low, cpl_boolean isleq_low, double th_high, cpl_boolean isgeq_high, double alt_low, double alt_high, cpl_boolean isbad_low, cpl_boolean isbad_mid, cpl_boolean isbad_high)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Split the values in an image in three according to two thresholds.  <a href="#ga832676f36ecd647b77f4bb373b2d1954"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">cpl_error_code </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__utils.html#ga3d1a791b5dc870770611c7dbf60d02df">irplib_dfs_table_convert</a> (cpl_table *self, cpl_frameset *allframes, const cpl_frameset *useframes, int maxlinelen, char commentchar, const char *product_name, const char *procatg, const cpl_parameterlist *parlist, const char *recipe_name, const cpl_propertylist *mainlist, const cpl_pr [...]
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Create a DFS product with one table from one or more (ASCII) file(s).  <a href="#ga3d1a791b5dc870770611c7dbf60d02df"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">cpl_error_code </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__utils.html#ga59a68df1795523d4f7653875bd9fc01d">irplib_table_read_from_frameset</a> (cpl_table *self, const cpl_frameset *useframes, int maxlinelen, char commentchar, const cpl_parameterlist *parlist, cpl_boolean(*table_set_row)(cpl_table *, const char *, int, const cpl_frame *, const cpl_parameterlist *))</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Set the rows of a table with data from one or more (ASCII) files.  <a href="#ga59a68df1795523d4f7653875bd9fc01d"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__utils.html#gaf9d392144014e2363054bc3f83c8e47e">irplib_reset</a> (void)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Reset IRPLIB state.  <a href="#gaf9d392144014e2363054bc3f83c8e47e"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__utils.html#gae13f0d6b24ade506a99ac9c4bb09efde">irplib_compare_tags</a> (cpl_frame *frame1, cpl_frame *frame2)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Comparison function to identify different input frames.  <a href="#gae13f0d6b24ade506a99ac9c4bb09efde"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">const char * </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__utils.html#ga9fe4dca85dee68061114e26fdc72a134">irplib_frameset_find_file</a> (const cpl_frameset *self, const char *tag)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Find the filename with the given tag in a frame set.  <a href="#ga9fe4dca85dee68061114e26fdc72a134"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">const cpl_frame * </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__utils.html#ga5b20a00f315410b49b1db1dd2417fe68">irplib_frameset_get_first_from_group</a> (const cpl_frameset *self, cpl_frame_group group)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Find the first frame belonging to the given group.  <a href="#ga5b20a00f315410b49b1db1dd2417fe68"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">cpl_error_code </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__utils.html#gac568c70a57ef8610f5fedc9f1943a3a1">irplib_apertures_find_max_flux</a> (const cpl_apertures *self, int *ind, int nfind)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Find the aperture(s) with the greatest flux.  <a href="#gac568c70a57ef8610f5fedc9f1943a3a1"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="ga09a11edf52efa78ddafce0bb4fa3b71f"></a><!-- doxytag: member="irplib_utils::irplib_isinf" ref="ga09a11edf52efa78ddafce0bb4fa3b71f" args="(double value)" -->
+int </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__utils.html#ga09a11edf52efa78ddafce0bb4fa3b71f">irplib_isinf</a> (double value)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">portable isinf <br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="ga804bfc739b5d55f9797ab881b1034ae4"></a><!-- doxytag: member="irplib_utils::irplib_isnan" ref="ga804bfc739b5d55f9797ab881b1034ae4" args="(double value)" -->
+int </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__utils.html#ga804bfc739b5d55f9797ab881b1034ae4">irplib_isnan</a> (double value)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">portable isnan <br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__utils.html#ga2dda571b0bbb3f7bf170210b38f95627">irplib_errorstate_warning</a> (unsigned self, unsigned first, unsigned last)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Dump a single CPL error.  <a href="#ga2dda571b0bbb3f7bf170210b38f95627"></a><br/></td></tr>
+</table>
+<hr/><h2>Function Documentation</h2>
+<a class="anchor" id="gac568c70a57ef8610f5fedc9f1943a3a1"></a><!-- doxytag: member="irplib_utils.c::irplib_apertures_find_max_flux" ref="gac568c70a57ef8610f5fedc9f1943a3a1" args="(const cpl_apertures *self, int *ind, int nfind)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">cpl_error_code irplib_apertures_find_max_flux </td>
+          <td>(</td>
+          <td class="paramtype">const cpl_apertures * </td>
+          <td class="paramname"> <em>self</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">int * </td>
+          <td class="paramname"> <em>ind</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">int </td>
+          <td class="paramname"> <em>nfind</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Find the aperture(s) with the greatest flux. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>self</em> </td><td>The aperture object </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>ind</em> </td><td>The aperture-indices in order of decreasing flux </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>nfind</em> </td><td>Number of indices to find </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>CPL_ERROR_NONE or the relevant _cpl_error_code_ on error</dd></dl>
+<p>nfind must be at least 1 and at most the size of the aperture object.</p>
+<p>The ind array must be able to hold (at least) nfind integers. On success the first nfind elements of ind point to indices of the aperture object.</p>
+<p>To find the single ind of the aperture with the maximum flux use simply: int ind; irplib_apertures_find_max_flux(self, &ind, 1); </p>
+
+<p>Definition at line <a class="el" href="irplib__utils_8c_source.html#l01253">1253</a> of file <a class="el" href="irplib__utils_8c_source.html">irplib_utils.c</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="gae13f0d6b24ade506a99ac9c4bb09efde"></a><!-- doxytag: member="irplib_utils.c::irplib_compare_tags" ref="gae13f0d6b24ade506a99ac9c4bb09efde" args="(cpl_frame *frame1, cpl_frame *frame2)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">int irplib_compare_tags </td>
+          <td>(</td>
+          <td class="paramtype">cpl_frame * </td>
+          <td class="paramname"> <em>frame1</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">cpl_frame * </td>
+          <td class="paramname"> <em>frame2</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Comparison function to identify different input frames. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>frame1</em> </td><td>first frame </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>frame2</em> </td><td>second frame </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>0 if frame1!=frame2, 1 if frame1==frame2, -1 in error case </dd></dl>
+
+<p>Definition at line <a class="el" href="irplib__utils_8c_source.html#l01152">1152</a> of file <a class="el" href="irplib__utils_8c_source.html">irplib_utils.c</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="ga346842d722834a2e6221ff2d86314b7e"></a><!-- doxytag: member="irplib_utils.c::irplib_dfs_save_image" ref="ga346842d722834a2e6221ff2d86314b7e" args="(cpl_frameset *allframes, const cpl_parameterlist *parlist, const cpl_frameset *usedframes, const cpl_image *image, cpl_type_bpp bpp, const char *recipe, const char *procat, const cpl_propertylist *applist, const char *remregexp, const char *pipe_id, const char *filename)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">cpl_error_code irplib_dfs_save_image </td>
+          <td>(</td>
+          <td class="paramtype">cpl_frameset * </td>
+          <td class="paramname"> <em>allframes</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const cpl_parameterlist * </td>
+          <td class="paramname"> <em>parlist</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const cpl_frameset * </td>
+          <td class="paramname"> <em>usedframes</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const cpl_image * </td>
+          <td class="paramname"> <em>image</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">cpl_type_bpp </td>
+          <td class="paramname"> <em>bpp</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>recipe</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>procat</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const cpl_propertylist * </td>
+          <td class="paramname"> <em>applist</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>remregexp</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>pipe_id</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>filename</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Save an image as a DFS-compliant pipeline product. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>allframes</em> </td><td>The list of input frames for the recipe </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>parlist</em> </td><td>The list of input parameters </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>usedframes</em> </td><td>The list of raw/calibration frames used for this product </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>image</em> </td><td>The image to be saved </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>bpp</em> </td><td>Bits per pixel </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>recipe</em> </td><td>The recipe name </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>procat</em> </td><td>The product category tag </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>applist</em> </td><td>Optional propertylist to append to primary header or NULL </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>remregexp</em> </td><td>Optional regexp of properties not to put in main header </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>pipe_id</em> </td><td>PACKAGE "/" PACKAGE_VERSION </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>filename</em> </td><td>Filename of created product </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="note"><dt><b>Note:</b></dt><dd>The image may be NULL in which case only the header information is saved but passing a NULL image is deprecated, use cpl_dfs_save_propertylist(). </dd>
+<dd>
+remregexp may be NULL </dd></dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>CPL_ERROR_NONE or the relevant CPL error code on error </dd></dl>
+<dl class="see"><dt><b>See also:</b></dt><dd>cpl_dfs_save_image(). </dd></dl>
+
+<p>Definition at line <a class="el" href="irplib__utils_8c_source.html#l00214">214</a> of file <a class="el" href="irplib__utils_8c_source.html">irplib_utils.c</a>.</p>
+
+<p>References <a class="el" href="irplib__utils_8c_source.html#l00417">irplib_dfs_save_image_()</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="ga1fd7c2f4c00014049b0bf4bf6814b451"></a><!-- doxytag: member="irplib_utils.c::irplib_dfs_save_image_" ref="ga1fd7c2f4c00014049b0bf4bf6814b451" args="(cpl_frameset *allframes, cpl_propertylist *header, const cpl_parameterlist *parlist, const cpl_frameset *usedframes, const cpl_frame *inherit, const cpl_image *image, cpl_type type, const char *recipe, const cpl_propertylist *applist, const char *remregexp, const char *pipe_id, const char *filename)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">cpl_error_code irplib_dfs_save_image_ </td>
+          <td>(</td>
+          <td class="paramtype">cpl_frameset * </td>
+          <td class="paramname"> <em>allframes</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">cpl_propertylist * </td>
+          <td class="paramname"> <em>header</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const cpl_parameterlist * </td>
+          <td class="paramname"> <em>parlist</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const cpl_frameset * </td>
+          <td class="paramname"> <em>usedframes</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const cpl_frame * </td>
+          <td class="paramname"> <em>inherit</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const cpl_image * </td>
+          <td class="paramname"> <em>image</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">cpl_type </td>
+          <td class="paramname"> <em>type</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>recipe</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const cpl_propertylist * </td>
+          <td class="paramname"> <em>applist</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>remregexp</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>pipe_id</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>filename</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Save an image as a DFS-compliant pipeline product. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>allframes</em> </td><td>The list of input frames for the recipe </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>header</em> </td><td>NULL, or filled with properties written to product header </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>parlist</em> </td><td>The list of input parameters </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>usedframes</em> </td><td>The list of raw/calibration frames used for this product </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>inherit</em> </td><td>NULL or product frames inherit their header from this frame </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>image</em> </td><td>The image to be saved </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>type</em> </td><td>The type used to represent the data in the file </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>recipe</em> </td><td>The recipe name </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>applist</em> </td><td>Propertylist to append to primary header, w. PRO.CATG </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>remregexp</em> </td><td>Optional regexp of properties not to put in main header </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>pipe_id</em> </td><td>PACKAGE "/" PACKAGE_VERSION </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>filename</em> </td><td>Filename of created product </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="note"><dt><b>Note:</b></dt><dd>The image may be NULL in which case only the header information is saved but passing a NULL image is deprecated, use cpl_dfs_save_propertylist(). </dd>
+<dd>
+remregexp may be NULL </dd>
+<dd>
+applist must contain a string-property with key CPL_DFS_PRO_CATG </dd>
+<dd>
+On success and iff header is non-NULL, it will be emptied and then filled with the properties written to the primary header of the product </dd></dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>CPL_ERROR_NONE or the relevant CPL error code on error </dd></dl>
+<dl class="see"><dt><b>See also:</b></dt><dd>cpl_dfs_save_image() </dd></dl>
+<dl class="note"><dt><b>Note:</b></dt><dd>applist is copied with cpl_propertylist_copy_property_regexp() instead pf cpl_propertylist_append() </dd></dl>
+
+<p>Definition at line <a class="el" href="irplib__utils_8c_source.html#l00417">417</a> of file <a class="el" href="irplib__utils_8c_source.html">irplib_utils.c</a>.</p>
+
+<p>Referenced by <a class="el" href="irplib__utils_8c_source.html#l00214">irplib_dfs_save_image()</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="ga66f7adc9e165b4e934e3d57a700f55c1"></a><!-- doxytag: member="irplib_utils.c::irplib_dfs_save_imagelist" ref="ga66f7adc9e165b4e934e3d57a700f55c1" args="(cpl_frameset *allframes, const cpl_parameterlist *parlist, const cpl_frameset *usedframes, const cpl_imagelist *imagelist, cpl_type_bpp bpp, const char *recipe, const char *procat, const cpl_propertylist *applist, const char *remregexp, const char *pipe_id, const char *filename)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">cpl_error_code irplib_dfs_save_imagelist </td>
+          <td>(</td>
+          <td class="paramtype">cpl_frameset * </td>
+          <td class="paramname"> <em>allframes</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const cpl_parameterlist * </td>
+          <td class="paramname"> <em>parlist</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const cpl_frameset * </td>
+          <td class="paramname"> <em>usedframes</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const cpl_imagelist * </td>
+          <td class="paramname"> <em>imagelist</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">cpl_type_bpp </td>
+          <td class="paramname"> <em>bpp</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>recipe</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>procat</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const cpl_propertylist * </td>
+          <td class="paramname"> <em>applist</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>remregexp</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>pipe_id</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>filename</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Save an imagelist as a DFS-compliant pipeline product. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>allframes</em> </td><td>The list of input frames for the recipe </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>parlist</em> </td><td>The list of input parameters </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>usedframes</em> </td><td>The list of raw/calibration frames used for this product </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>imagelist</em> </td><td>The imagelist to be saved </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>bpp</em> </td><td>Bits per pixel </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>recipe</em> </td><td>The recipe name </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>procat</em> </td><td>The product category tag </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>applist</em> </td><td>Optional propertylist to append to primary header or NULL </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>remregexp</em> </td><td>Optional regexp of properties not to put in main header </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>pipe_id</em> </td><td>PACKAGE "/" PACKAGE_VERSION </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>filename</em> </td><td>Filename of created product </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="note"><dt><b>Note:</b></dt><dd>remregexp may be NULL </dd></dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>CPL_ERROR_NONE or the relevant CPL error code on error </dd></dl>
+<dl class="see"><dt><b>See also:</b></dt><dd>cpl_dfs_save_imagelist(). </dd></dl>
+
+<p>Definition at line <a class="el" href="irplib__utils_8c_source.html#l00309">309</a> of file <a class="el" href="irplib__utils_8c_source.html">irplib_utils.c</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="ga4dc12f321e7aeb5e67ff19f815bfd7b7"></a><!-- doxytag: member="irplib_utils.c::irplib_dfs_save_propertylist" ref="ga4dc12f321e7aeb5e67ff19f815bfd7b7" args="(cpl_frameset *allframes, const cpl_parameterlist *parlist, const cpl_frameset *usedframes, const char *recipe, const char *procat, const cpl_propertylist *applist, const char *remregexp, const char *pipe_id, const char *filename)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">cpl_error_code irplib_dfs_save_propertylist </td>
+          <td>(</td>
+          <td class="paramtype">cpl_frameset * </td>
+          <td class="paramname"> <em>allframes</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const cpl_parameterlist * </td>
+          <td class="paramname"> <em>parlist</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const cpl_frameset * </td>
+          <td class="paramname"> <em>usedframes</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>recipe</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>procat</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const cpl_propertylist * </td>
+          <td class="paramname"> <em>applist</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>remregexp</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>pipe_id</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>filename</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Save a propertylist as a DFS-compliant pipeline product. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>allframes</em> </td><td>The list of input frames for the recipe </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>parlist</em> </td><td>The list of input parameters </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>usedframes</em> </td><td>The list of raw/calibration frames used for this product </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>recipe</em> </td><td>The recipe name </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>procat</em> </td><td>The product category tag </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>applist</em> </td><td>Optional propertylist to append to primary header or NULL </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>remregexp</em> </td><td>Optional regexp of properties not to put in main header </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>pipe_id</em> </td><td>PACKAGE "/" PACKAGE_VERSION </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>filename</em> </td><td>Filename of created product </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="note"><dt><b>Note:</b></dt><dd>remregexp may be NULL </dd></dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>CPL_ERROR_NONE or the relevant CPL error code on error </dd></dl>
+<dl class="see"><dt><b>See also:</b></dt><dd>cpl_dfs_save_propertylist(). </dd></dl>
+
+<p>Definition at line <a class="el" href="irplib__utils_8c_source.html#l00262">262</a> of file <a class="el" href="irplib__utils_8c_source.html">irplib_utils.c</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="ga62a91f8630af11164547c168660b2ade"></a><!-- doxytag: member="irplib_utils.c::irplib_dfs_save_table" ref="ga62a91f8630af11164547c168660b2ade" args="(cpl_frameset *allframes, const cpl_parameterlist *parlist, const cpl_frameset *usedframes, const cpl_table *table, const cpl_propertylist *tablelist, const char *recipe, const char *procat, const cpl_propertylist *applist, const char *remregexp, const char *pipe_id, const char *filename)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">cpl_error_code irplib_dfs_save_table </td>
+          <td>(</td>
+          <td class="paramtype">cpl_frameset * </td>
+          <td class="paramname"> <em>allframes</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const cpl_parameterlist * </td>
+          <td class="paramname"> <em>parlist</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const cpl_frameset * </td>
+          <td class="paramname"> <em>usedframes</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const cpl_table * </td>
+          <td class="paramname"> <em>table</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const cpl_propertylist * </td>
+          <td class="paramname"> <em>tablelist</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>recipe</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>procat</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const cpl_propertylist * </td>
+          <td class="paramname"> <em>applist</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>remregexp</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>pipe_id</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>filename</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Save a table as a DFS-compliant pipeline product. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>allframes</em> </td><td>The list of input frames for the recipe </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>parlist</em> </td><td>The list of input parameters </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>usedframes</em> </td><td>The list of raw/calibration frames used for this product </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>table</em> </td><td>The table to be saved </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>tablelist</em> </td><td>Optional propertylist to use in table extension or NULL </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>recipe</em> </td><td>The recipe name </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>procat</em> </td><td>The product category tag </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>applist</em> </td><td>Optional propertylist to append to primary header or NULL </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>remregexp</em> </td><td>Optional regexp of properties not to put in main header </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>pipe_id</em> </td><td>PACKAGE "/" PACKAGE_VERSION </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>filename</em> </td><td>Filename of created product </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>CPL_ERROR_NONE or the relevant CPL error code on error </dd></dl>
+<dl class="see"><dt><b>See also:</b></dt><dd>cpl_dfs_save_table(). </dd></dl>
+
+<p>Definition at line <a class="el" href="irplib__utils_8c_source.html#l00357">357</a> of file <a class="el" href="irplib__utils_8c_source.html">irplib_utils.c</a>.</p>
+
+<p>Referenced by <a class="el" href="irplib__utils_8c_source.html#l00866">irplib_dfs_table_convert()</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="ga3d1a791b5dc870770611c7dbf60d02df"></a><!-- doxytag: member="irplib_utils.c::irplib_dfs_table_convert" ref="ga3d1a791b5dc870770611c7dbf60d02df" args="(cpl_table *self, cpl_frameset *allframes, const cpl_frameset *useframes, int maxlinelen, char commentchar, const char *product_name, const char *procatg, const cpl_parameterlist *parlist, const char *recipe_name, const cpl_propertylist *mainlist, const cpl_propertylist *extlist, const char *remregexp, const char *ins [...]
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">cpl_error_code irplib_dfs_table_convert </td>
+          <td>(</td>
+          <td class="paramtype">cpl_table * </td>
+          <td class="paramname"> <em>self</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">cpl_frameset * </td>
+          <td class="paramname"> <em>allframes</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const cpl_frameset * </td>
+          <td class="paramname"> <em>useframes</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">int </td>
+          <td class="paramname"> <em>maxlinelen</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">char </td>
+          <td class="paramname"> <em>commentchar</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>product_name</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>procatg</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const cpl_parameterlist * </td>
+          <td class="paramname"> <em>parlist</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>recipe_name</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const cpl_propertylist * </td>
+          <td class="paramname"> <em>mainlist</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const cpl_propertylist * </td>
+          <td class="paramname"> <em>extlist</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>remregexp</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>instrume</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>pipe_id</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">cpl_boolean(*)(cpl_table *, const char *, int, const cpl_frame *, const cpl_parameterlist *) </td>
+          <td class="paramname"> <em>table_set_row</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">cpl_error_code(*)(cpl_table *, const cpl_frameset *, const cpl_parameterlist *) </td>
+          <td class="paramname"> <em>table_check</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Create a DFS product with one table from one or more (ASCII) file(s). </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>self</em> </td><td>Table with labels (and units) but no row data </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>allframes</em> </td><td>The list of input frames for the recipe </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>useframes</em> </td><td>The frames to process for the product </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>maxlinelen</em> </td><td>The maximum line length in the input file(s) </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>commentchar</em> </td><td>Skip lines that start with this character, e.g. '#' </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>product_name</em> </td><td>The name of the created FITS table product or NULL </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>procatg</em> </td><td>The PROCATG of the created FITS table product </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>parlist</em> </td><td>The list of input parameters </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>recipe_name</em> </td><td>The name of the calling recipe </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>mainlist</em> </td><td>Optional propertylist to append to main header or NULL </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>extlist</em> </td><td>Optional propertylist to append to ext. header or NULL </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>remregexp</em> </td><td>Optional regexp of properties not to put in main header </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>instrume</em> </td><td>The value to use for the INSTRUME key, uppercase PACKAGE </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>pipe_id</em> </td><td>PACKAGE "/" PACKAGE_VERSION </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>table_set_row</em> </td><td>Caller-defined function to insert one row in the table </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>table_check</em> </td><td>Optional caller-defined function to check table or NULL </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>CPL_ERROR_NONE or the relevant CPL error code on error </dd></dl>
+<dl class="see"><dt><b>See also:</b></dt><dd><a class="el" href="group__irplib__utils.html#ga59a68df1795523d4f7653875bd9fc01d" title="Set the rows of a table with data from one or more (ASCII) files.">irplib_table_read_from_frameset()</a>, cpl_dfs_save_table() </dd></dl>
+<dl class="note"><dt><b>Note:</b></dt><dd>If product_name is NULL, the product will be named <recipe_name>.fits.</dd></dl>
+<dl class="user"><dt><b>Example (error handling omitted for brevity):</b></dt><dd><div class="fragment"><pre class="fragment">      <span class="keyword">extern</span> cpl_boolean my_table_set_row(cpl_table *, <span class="keyword">const</span> <span class="keywordtype">char</span> *, <span class="keywordtype">int</span>,
+                                          <span class="keyword">const</span> cpl_frame *,
+                                          <span class="keyword">const</span> cpl_parameterlist *);
+      <span class="keyword">extern</span> cpl_error_code my_table_check(cpl_table *,
+                                           <span class="keyword">const</span> cpl_frameset *,
+                                           <span class="keyword">const</span> cpl_parameterlist *);
+      <span class="keyword">const</span> <span class="keywordtype">int</span> expected_rows = 42;
+      cpl_table * <span class="keyword">self</span> = cpl_table_new(expected_rows);
+
+      cpl_table_new_column(<span class="keyword">self</span>, <span class="stringliteral">"MYLABEL1"</span>, CPL_TYPE_STRING);
+      cpl_table_new_column(<span class="keyword">self</span>, <span class="stringliteral">"MYLABEL2"</span>, CPL_TYPE_DOUBLE);
+      cpl_table_set_column_unit(<span class="keyword">self</span>, <span class="stringliteral">"MYLABEL2"</span>, <span class="stringliteral">"Some_SI_Unit"</span>);
+
+      <a class="code" href="group__irplib__utils.html#ga3d1a791b5dc870770611c7dbf60d02df" title="Create a DFS product with one table from one or more (ASCII) file(s).">irplib_dfs_table_convert</a>(<span class="keyword">self</span>, allframes, useframes, 1024, <span class="charliteral">'#'</span>, NULL,
+                               <span class="stringliteral">"MYPROCATG"</span>, parlist, <span class="stringliteral">"myrecipe"</span>, NULL, NULL,
+                               NULL, <span class="stringliteral">"MYINSTRUME"</span>, PACKAGE <span class="stringliteral">"/"</span> PACKAGE_VERSION,
+                               my_table_set_row, my_table_check);
+
+      cpl_table_delete(<span class="keyword">self</span>);
+</pre></div> </dd></dl>
+
+<p>Definition at line <a class="el" href="irplib__utils_8c_source.html#l00866">866</a> of file <a class="el" href="irplib__utils_8c_source.html">irplib_utils.c</a>.</p>
+
+<p>References <a class="el" href="irplib__utils_8c_source.html#l00357">irplib_dfs_save_table()</a>, and <a class="el" href="irplib__utils_8c_source.html#l00994">irplib_table_read_from_frameset()</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="ga26c6209e5df98978e2922a15b47b47d1"></a><!-- doxytag: member="irplib_utils.c::irplib_errorstate_dump_debug" ref="ga26c6209e5df98978e2922a15b47b47d1" args="(unsigned self, unsigned first, unsigned last)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">void irplib_errorstate_dump_debug </td>
+          <td>(</td>
+          <td class="paramtype">unsigned </td>
+          <td class="paramname"> <em>self</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">unsigned </td>
+          <td class="paramname"> <em>first</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">unsigned </td>
+          <td class="paramname"> <em>last</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Dump a single CPL error at the CPL debug level. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>self</em> </td><td>The number of the current error to be dumped </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>first</em> </td><td>The number of the first error to be dumped </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>last</em> </td><td>The number of the last error to be dumped </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>void </dd></dl>
+<dl class="see"><dt><b>See also:</b></dt><dd>cpl_errorstate_dump_one </dd></dl>
+
+<p>Definition at line <a class="el" href="irplib__utils_8c_source.html#l00183">183</a> of file <a class="el" href="irplib__utils_8c_source.html">irplib_utils.c</a>.</p>
+
+<p>Referenced by <a class="el" href="irplib__wavecal_8c_source.html#l01421">irplib_polynomial_find_1d_from_correlation_all()</a>, and <a class="el" href="irplib__wavecal_8c_source.html#l00976">irplib_vector_fill_line_spectrum_model()</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="ga901ff52a1c9dcdfcf2d2632d31064bdb"></a><!-- doxytag: member="irplib_utils.c::irplib_errorstate_dump_info" ref="ga901ff52a1c9dcdfcf2d2632d31064bdb" args="(unsigned self, unsigned first, unsigned last)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">void irplib_errorstate_dump_info </td>
+          <td>(</td>
+          <td class="paramtype">unsigned </td>
+          <td class="paramname"> <em>self</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">unsigned </td>
+          <td class="paramname"> <em>first</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">unsigned </td>
+          <td class="paramname"> <em>last</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Dump a single CPL error at the CPL info level. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>self</em> </td><td>The number of the current error to be dumped </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>first</em> </td><td>The number of the first error to be dumped </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>last</em> </td><td>The number of the last error to be dumped </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>void </dd></dl>
+<dl class="see"><dt><b>See also:</b></dt><dd>cpl_errorstate_dump_one </dd></dl>
+
+<p>Definition at line <a class="el" href="irplib__utils_8c_source.html#l00163">163</a> of file <a class="el" href="irplib__utils_8c_source.html">irplib_utils.c</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="ga6b29dac884b62ab52f43dd670d4d8386"></a><!-- doxytag: member="irplib_utils.c::irplib_errorstate_dump_warning" ref="ga6b29dac884b62ab52f43dd670d4d8386" args="(unsigned self, unsigned first, unsigned last)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">void irplib_errorstate_dump_warning </td>
+          <td>(</td>
+          <td class="paramtype">unsigned </td>
+          <td class="paramname"> <em>self</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">unsigned </td>
+          <td class="paramname"> <em>first</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">unsigned </td>
+          <td class="paramname"> <em>last</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Dump a single CPL error at the CPL warning level. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>self</em> </td><td>The number of the current error to be dumped </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>first</em> </td><td>The number of the first error to be dumped </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>last</em> </td><td>The number of the last error to be dumped </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>void </dd></dl>
+<dl class="see"><dt><b>See also:</b></dt><dd>cpl_errorstate_dump_one</dd></dl>
+<p>FIXME: Move this function to the CPL errorstate module. </p>
+
+<p>Definition at line <a class="el" href="irplib__utils_8c_source.html#l00136">136</a> of file <a class="el" href="irplib__utils_8c_source.html">irplib_utils.c</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="ga2dda571b0bbb3f7bf170210b38f95627"></a><!-- doxytag: member="irplib_utils.c::irplib_errorstate_warning" ref="ga2dda571b0bbb3f7bf170210b38f95627" args="(unsigned self, unsigned first, unsigned last)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">void irplib_errorstate_warning </td>
+          <td>(</td>
+          <td class="paramtype">unsigned </td>
+          <td class="paramname"> <em>self</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">unsigned </td>
+          <td class="paramname"> <em>first</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">unsigned </td>
+          <td class="paramname"> <em>last</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Dump a single CPL error. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>self</em> </td><td>The number of the current error to be dumped </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>first</em> </td><td>The number of the first error to be dumped </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>last</em> </td><td>The number of the last error to be dumped </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>void </dd></dl>
+<dl class="note"><dt><b>Note:</b></dt><dd>This function differs from cpl_errorstate_dump_one only in message level </dd></dl>
+<dl class="see"><dt><b>See also:</b></dt><dd>cpl_errorstate_dump_one </dd></dl>
+
+<p>Definition at line <a class="el" href="irplib__utils_8c_source.html#l01334">1334</a> of file <a class="el" href="irplib__utils_8c_source.html">irplib_utils.c</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="ga9fe4dca85dee68061114e26fdc72a134"></a><!-- doxytag: member="irplib_utils.c::irplib_frameset_find_file" ref="ga9fe4dca85dee68061114e26fdc72a134" args="(const cpl_frameset *self, const char *tag)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">const char* irplib_frameset_find_file </td>
+          <td>(</td>
+          <td class="paramtype">const cpl_frameset * </td>
+          <td class="paramname"> <em>self</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>tag</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Find the filename with the given tag in a frame set. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>self</em> </td><td>A frame set. </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>tag</em> </td><td>The frame tag to search for. </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>The filename or NULL if none found and on error. </dd></dl>
+<dl class="see"><dt><b>See also:</b></dt><dd>cpl_frameset_find </dd></dl>
+<dl class="note"><dt><b>Note:</b></dt><dd>If called with a CPL error code, the location will be updated and NULL returned.</dd></dl>
+<p>NULL is returned and no error code set if the tag is not found.</p>
+<p>If the file is not unique, the name of the first one is returned and with a warning. </p>
+
+<p>Definition at line <a class="el" href="irplib__utils_8c_source.html#l01188">1188</a> of file <a class="el" href="irplib__utils_8c_source.html">irplib_utils.c</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="ga5b20a00f315410b49b1db1dd2417fe68"></a><!-- doxytag: member="irplib_utils.c::irplib_frameset_get_first_from_group" ref="ga5b20a00f315410b49b1db1dd2417fe68" args="(const cpl_frameset *self, cpl_frame_group group)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">const cpl_frame* irplib_frameset_get_first_from_group </td>
+          <td>(</td>
+          <td class="paramtype">const cpl_frameset * </td>
+          <td class="paramname"> <em>self</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">cpl_frame_group </td>
+          <td class="paramname"> <em>group</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Find the first frame belonging to the given group. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>self</em> </td><td>The frameset </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>group</em> </td><td>The group attribute </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>The first frame belonging to the given group, or <code>NULL</code> if no such frame was found. The function returns <code>NULL</code> if an error occurs and sets the appropriate error code. </dd></dl>
+
+<p>Definition at line <a class="el" href="irplib__utils_8c_source.html#l01219">1219</a> of file <a class="el" href="irplib__utils_8c_source.html">irplib_utils.c</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="ga832676f36ecd647b77f4bb373b2d1954"></a><!-- doxytag: member="irplib_utils.c::irplib_image_split" ref="ga832676f36ecd647b77f4bb373b2d1954" args="(const cpl_image *self, cpl_image *im_low, cpl_image *im_mid, cpl_image *im_high, double th_low, cpl_boolean isleq_low, double th_high, cpl_boolean isgeq_high, double alt_low, double alt_high, cpl_boolean isbad_low, cpl_boolean isbad_mid, cpl_boolean isbad_high)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">cpl_error_code irplib_image_split </td>
+          <td>(</td>
+          <td class="paramtype">const cpl_image * </td>
+          <td class="paramname"> <em>self</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">cpl_image * </td>
+          <td class="paramname"> <em>im_low</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">cpl_image * </td>
+          <td class="paramname"> <em>im_mid</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">cpl_image * </td>
+          <td class="paramname"> <em>im_high</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">double </td>
+          <td class="paramname"> <em>th_low</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">cpl_boolean </td>
+          <td class="paramname"> <em>isleq_low</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">double </td>
+          <td class="paramname"> <em>th_high</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">cpl_boolean </td>
+          <td class="paramname"> <em>isgeq_high</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">double </td>
+          <td class="paramname"> <em>alt_low</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">double </td>
+          <td class="paramname"> <em>alt_high</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">cpl_boolean </td>
+          <td class="paramname"> <em>isbad_low</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">cpl_boolean </td>
+          <td class="paramname"> <em>isbad_mid</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">cpl_boolean </td>
+          <td class="paramname"> <em>isbad_high</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Split the values in an image in three according to two thresholds. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>self</em> </td><td>The image to split </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>im_low</em> </td><td>If non-NULL low-valued pixels are assigned to this image </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>im_mid</em> </td><td>If non-NULL middle-valued pixels are assigned to this image </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>im_high</em> </td><td>If non-NULL high-valued pixels are assigned to this image </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>th_low</em> </td><td>The lower threshold </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>isleq_low</em> </td><td>Ift true use less than or equal </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>th_high</em> </td><td>The upper threshold, must be at least th_low </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>isgeq_high</em> </td><td>Iff true use greater than or equal </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>alt_low</em> </td><td>Assign this value when the pixel value is not low </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>alt_high</em> </td><td>Assign this value, when the pixel value is not high </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>isbad_low</em> </td><td>Flag non-low pixels as bad </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>isbad_mid</em> </td><td>Flag non-mid pixels as bad </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>isbad_high</em> </td><td>Flag non-high pixels as bad </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>CPL_ERROR_NONE or the relevant CPL error code on error </dd></dl>
+<dl class="note"><dt><b>Note:</b></dt><dd>At least one output image must be non-NULL; all non-NULL images must be of identical size, but may be of any pixel-type. self may be passed as one of the output images for an in-place split.</dd></dl>
+<p>FIXME: This function is way too slow and perhaps over-engineered...</p>
+<p>A split in two is achieved with th_low equal th_high (in this case there is little reason for im_mid to be non-NULL).</p>
+<p>All pixel values in the output images are reset, as well as their bad pixels maps.</p>
+<p>If an input pixel-value is flagged as bad, then the receiving pixel in the output image is flagged as well.</p>
+<dl class="user"><dt><b>The same image may be passed more than once which allows a split</b></dt><dd>into one image with the mid-valued pixels and another with both the low and high-valued pixels, i.e. <div class="fragment"><pre class="fragment">       <a class="code" href="group__irplib__utils.html#ga832676f36ecd647b77f4bb373b2d1954" title="Split the values in an image in three according to two thresholds.">irplib_image_split</a>(source, dest, im_mid, dest,
+                          th_low,  isleq_low, th_high, isgeq_high,
+                          alt_low, alt_high,
+                          isbad_low, isbad_mid, isbad_high);
+</pre></div></dd></dl>
+<dl class="user"><dt><b>These two calls are equivalent:</b></dt><dd><div class="fragment"><pre class="fragment">     cpl_image_threshold(img, th_low, th_high, alt_low, alt_high);
+</pre></div></dd></dl>
+<div class="fragment"><pre class="fragment">     <a class="code" href="group__irplib__utils.html#ga832676f36ecd647b77f4bb373b2d1954" title="Split the values in an image in three according to two thresholds.">irplib_image_split</a>(img, NULL, img, NULL,
+                        th_low,  CPL_TRUE, th_high, CPL_TRUE,
+                        alt_low, alt_high, dontcare, CPL_FALSE, dontcare);
+</pre></div> 
+<p>Definition at line <a class="el" href="irplib__utils_8c_source.html#l00671">671</a> of file <a class="el" href="irplib__utils_8c_source.html">irplib_utils.c</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="gaf9d392144014e2363054bc3f83c8e47e"></a><!-- doxytag: member="irplib_utils.c::irplib_reset" ref="gaf9d392144014e2363054bc3f83c8e47e" args="(void)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">void irplib_reset </td>
+          <td>(</td>
+          <td class="paramtype">void </td>
+          <td class="paramname"></td>
+          <td> ) </td>
+          <td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Reset IRPLIB state. </p>
+<p>This function resets all static memory used by IRPLIB to a well-defined, initial state.</p>
+<p>The function should be called (during initialization) by any application using static memory facilities in IRPLIB.</p>
+<p>Currently, this function does nothing. </p>
+
+<p>Definition at line <a class="el" href="irplib__utils_8c_source.html#l01139">1139</a> of file <a class="el" href="irplib__utils_8c_source.html">irplib_utils.c</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="ga59a68df1795523d4f7653875bd9fc01d"></a><!-- doxytag: member="irplib_utils.c::irplib_table_read_from_frameset" ref="ga59a68df1795523d4f7653875bd9fc01d" args="(cpl_table *self, const cpl_frameset *useframes, int maxlinelen, char commentchar, const cpl_parameterlist *parlist, cpl_boolean(*table_set_row)(cpl_table *, const char *, int, const cpl_frame *, const cpl_parameterlist *))" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">cpl_error_code irplib_table_read_from_frameset </td>
+          <td>(</td>
+          <td class="paramtype">cpl_table * </td>
+          <td class="paramname"> <em>self</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const cpl_frameset * </td>
+          <td class="paramname"> <em>useframes</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">int </td>
+          <td class="paramname"> <em>maxlinelen</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">char </td>
+          <td class="paramname"> <em>commentchar</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const cpl_parameterlist * </td>
+          <td class="paramname"> <em>parlist</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">cpl_boolean(*)(cpl_table *, const char *, int, const cpl_frame *, const cpl_parameterlist *) </td>
+          <td class="paramname"> <em>table_set_row</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Set the rows of a table with data from one or more (ASCII) files. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>self</em> </td><td>Table with labels (and units) but no row data </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>useframes</em> </td><td>The frames to process for the table </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>maxlinelen</em> </td><td>The maximum line length in the input file(s) </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>commentchar</em> </td><td>Skip lines that start with this character, e.g. '#' </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>parlist</em> </td><td>The list of input parameters </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>table_set_row</em> </td><td>Caller-defined function to insert one row in the table </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>CPL_ERROR_NONE or the relevant CPL error code on error</dd></dl>
+<p>table_set_row() is a function that sets the specified row in a table</p>
+<ul>
+<li>it may optionally include a check of the line for consistency. An integer is passed to table_set_row() to indicate which row to set. Instead of setting the row table_set_row() may decide to discard the data. Iff the row was set, table_set_row() should return CPL_TRUE.</li>
+</ul>
+<p>It needs to know: 1) How to parse the lines - each line is read with fgets(). 2) For each column: type/format (lg/s/d) + label</p>
+<p>During a succesful call self will have rows added or removed to exactly match the number of lines converted. Any a priori knowledge about the expected number of converted rows can be used in the creation of the table (to reduce memory reallocation overhead). On error the number of rows in self is undefined.</p>
+<dl class="user"><dt><b>Example (error handling omitted for brevity):</b></dt><dd><div class="fragment"><pre class="fragment">      <span class="keyword">extern</span> cpl_boolean my_table_set_row(cpl_table *, <span class="keyword">const</span> <span class="keywordtype">char</span> *, <span class="keywordtype">int</span>,
+                                          <span class="keyword">const</span> cpl_frame *,
+                                          <span class="keyword">const</span> cpl_parameterlist *);
+      <span class="keyword">const</span> <span class="keywordtype">int</span> expected_rows = 42;
+      cpl_table * <span class="keyword">self</span> = cpl_table_new(expected_rows);
+
+      cpl_table_new_column(<span class="keyword">self</span>, <span class="stringliteral">"MYLABEL1"</span>, CPL_TYPE_STRING);
+      cpl_table_new_column(<span class="keyword">self</span>, <span class="stringliteral">"MYLABEL2"</span>, CPL_TYPE_DOUBLE);
+      cpl_table_set_column_unit(<span class="keyword">self</span>, <span class="stringliteral">"MYLABEL2"</span>, <span class="stringliteral">"Some_SI_Unit"</span>);
+
+      <a class="code" href="group__irplib__utils.html#ga59a68df1795523d4f7653875bd9fc01d" title="Set the rows of a table with data from one or more (ASCII) files.">irplib_table_read_from_frameset</a>(<span class="keyword">self</span>, useframes, 1024, <span class="charliteral">'#'</span>, parlist,
+                                      my_table_set_row);
+
+      <span class="comment">// Use self...</span>
+
+      cpl_table_delete(<span class="keyword">self</span>);
+</pre></div> </dd></dl>
+
+<p>Definition at line <a class="el" href="irplib__utils_8c_source.html#l00994">994</a> of file <a class="el" href="irplib__utils_8c_source.html">irplib_utils.c</a>.</p>
+
+<p>Referenced by <a class="el" href="irplib__utils_8c_source.html#l00866">irplib_dfs_table_convert()</a>.</p>
+
+</div>
+</div>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__irplib__wavecal.html b/html/group__irplib__wavecal.html
new file mode 100644
index 0000000..b0a654c
--- /dev/null
+++ b/html/group__irplib__wavecal.html
@@ -0,0 +1,988 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Spectro functionality</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Spectro functionality</h1><table border="0" cellpadding="0" cellspacing="0">
+<tr><td colspan="2"><h2>Functions</h2></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__wavecal.html#ga03d7f038adc7e18e7a9071581fa47a25">irplib_bivector_count_positive</a> (const cpl_bivector *self, double x_min, double x_max)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Count the positive Y-entries in a given X-range.  <a href="#ga03d7f038adc7e18e7a9071581fa47a25"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">cpl_error_code </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__wavecal.html#ga2dd3251367e2ee8b8bd5ce080e9f31bb">irplib_polynomial_fit_2d_dispersion</a> (cpl_polynomial *self, const cpl_image *imgwave, int fitdeg, double *presid)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Fit a 2D-dispersion from an image of wavelengths.  <a href="#ga2dd3251367e2ee8b8bd5ce080e9f31bb"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">cpl_error_code </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__wavecal.html#gaaa889f20c9483965ff6bab186d4f9972">irplib_polynomial_find_1d_from_correlation</a> (cpl_polynomial *self, int maxdeg, const cpl_vector *obs, irplib_base_spectrum_model *model, cpl_error_code(*filler)(cpl_vector *, const cpl_polynomial *, irplib_base_spectrum_model *, int), double pixtol, double pixstep, int hsize, int max [...]
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Modify self by maximizing the cross-correlation.  <a href="#gaaa889f20c9483965ff6bab186d4f9972"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">cpl_error_code </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__wavecal.html#ga44aa21cb1fc1459ab3b360748a737974">irplib_vector_fill_line_spectrum</a> (cpl_vector *self, const cpl_polynomial *disp, irplib_base_spectrum_model *lsslamp, int hsize)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Generate a 1D spectrum from a model and a dispersion relation.  <a href="#ga44aa21cb1fc1459ab3b360748a737974"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">cpl_error_code </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__wavecal.html#ga631e29d63bc65109f458915b5d1c8bb9">irplib_vector_fill_logline_spectrum</a> (cpl_vector *self, const cpl_polynomial *disp, irplib_base_spectrum_model *lsslamp, int hsize)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Generate a 1D spectrum from a model and a dispersion relation.  <a href="#ga631e29d63bc65109f458915b5d1c8bb9"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">cpl_error_code </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__wavecal.html#gae8e236a419dedc99eab52690f4a33901">irplib_vector_fill_line_spectrum_fast</a> (cpl_vector *self, const cpl_polynomial *disp, irplib_base_spectrum_model *lsslamp, int hsize)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Generate a 1D spectrum from a model and a dispersion relation.  <a href="#gae8e236a419dedc99eab52690f4a33901"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">cpl_error_code </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__wavecal.html#gaa0000d5a34e290fc93dfcc936e631eb7">irplib_vector_fill_logline_spectrum_fast</a> (cpl_vector *self, const cpl_polynomial *disp, irplib_base_spectrum_model *lsslamp, int hsize)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Generate a 1D spectrum from a model and a dispersion relation.  <a href="#gaa0000d5a34e290fc93dfcc936e631eb7"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">cpl_error_code </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__wavecal.html#ga7eec8e48f4888aba01b98d9e0dc2acc5">irplib_plot_spectrum_and_model</a> (const cpl_vector *self, const cpl_polynomial *disp1d, irplib_base_spectrum_model *model, cpl_error_code(*filler)(cpl_vector *, const cpl_polynomial *, irplib_base_spectrum_model *, int))</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Plot a 1D spectrum and one from a model.  <a href="#ga7eec8e48f4888aba01b98d9e0dc2acc5"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">cpl_error_code </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__wavecal.html#gae027096b411661b9584c72ab3e8e6547">irplib_bivector_find_shift_from_correlation</a> (cpl_bivector *self, const cpl_polynomial *disp, const cpl_vector *obs, irplib_base_spectrum_model *model, cpl_error_code(*filler)(cpl_vector *, const cpl_polynomial *, irplib_base_spectrum_model *, int), int hsize, cpl_boolean doplot, dou [...]
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Find shift(s) that maximizes (locally) the cross-correlation.  <a href="#gae027096b411661b9584c72ab3e8e6547"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">cpl_error_code </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__wavecal.html#gabaec991ebc1b856766bf66768c4a6a19">irplib_polynomial_shift_1d_from_correlation</a> (cpl_polynomial *self, const cpl_vector *obs, irplib_base_spectrum_model *model, cpl_error_code(*filler)(cpl_vector *, const cpl_polynomial *, irplib_base_spectrum_model *, int), int hsize, cpl_boolean doplot, double *pxc)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Shift self by the amount that maximizes the cross-correlation.  <a href="#gabaec991ebc1b856766bf66768c4a6a19"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">cpl_error_code </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__wavecal.html#ga0db5e24244f88b41627d5a385af81b33">irplib_vector_fill_line_spectrum_model</a> (cpl_vector *self, cpl_vector *linepix, cpl_vector *erftmp, const cpl_polynomial *disp, const cpl_bivector *lines, double wslit, double wfwhm, double xtrunc, int hsize, cpl_boolean dofast, cpl_boolean dolog, unsigned *pulines)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Generate a 1D spectrum from (arc) lines and a dispersion relation.  <a href="#ga0db5e24244f88b41627d5a385af81b33"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">double </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__wavecal.html#ga2da9c21054a19322705de2d4f48d1d3f">irplib_erf_antideriv</a> (double x, double sigma)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">The antiderivative of erx(x/sigma/sqrt(2)) with respect to x.  <a href="#ga2da9c21054a19322705de2d4f48d1d3f"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">cpl_error_code </td><td class="memItemRight" valign="bottom"><a class="el" href="group__irplib__wavecal.html#ga0adf260c4d27fc50bc8b4cbcc0264a4e">irplib_polynomial_find_1d_from_correlation_all</a> (cpl_polynomial *self, int maxdeg, const cpl_vector *obs, int nmaxima, int linelim, irplib_base_spectrum_model *model, cpl_error_code(*filler)(cpl_vector *, const cpl_polynomial *, irplib_base_spectrum_model *, int), double pixtol, doub [...]
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Modify self by maximizing the cross-correlation across all maxima.  <a href="#ga0adf260c4d27fc50bc8b4cbcc0264a4e"></a><br/></td></tr>
+</table>
+<hr/><h2>Function Documentation</h2>
+<a class="anchor" id="ga03d7f038adc7e18e7a9071581fa47a25"></a><!-- doxytag: member="irplib_wavecal.c::irplib_bivector_count_positive" ref="ga03d7f038adc7e18e7a9071581fa47a25" args="(const cpl_bivector *self, double x_min, double x_max)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">int irplib_bivector_count_positive </td>
+          <td>(</td>
+          <td class="paramtype">const cpl_bivector * </td>
+          <td class="paramname"> <em>self</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">double </td>
+          <td class="paramname"> <em>x_min</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">double </td>
+          <td class="paramname"> <em>x_max</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Count the positive Y-entries in a given X-range. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>self</em> </td><td>Bivector with increasing X-entries </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>x_min</em> </td><td>minimum X-entry </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>x_max</em> </td><td>maximum X-entry </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>the number of matching entries, or negative on error </dd></dl>
+
+<p>Definition at line <a class="el" href="irplib__wavecal_8c_source.html#l00115">115</a> of file <a class="el" href="irplib__wavecal_8c_source.html">irplib_wavecal.c</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="gae027096b411661b9584c72ab3e8e6547"></a><!-- doxytag: member="irplib_wavecal.c::irplib_bivector_find_shift_from_correlation" ref="gae027096b411661b9584c72ab3e8e6547" args="(cpl_bivector *self, const cpl_polynomial *disp, const cpl_vector *obs, irplib_base_spectrum_model *model, cpl_error_code(*filler)(cpl_vector *, const cpl_polynomial *, irplib_base_spectrum_model *, int), int hsize, cpl_boolean doplot, double *pxc)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">cpl_error_code irplib_bivector_find_shift_from_correlation </td>
+          <td>(</td>
+          <td class="paramtype">cpl_bivector * </td>
+          <td class="paramname"> <em>self</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const cpl_polynomial * </td>
+          <td class="paramname"> <em>disp</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const cpl_vector * </td>
+          <td class="paramname"> <em>obs</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">irplib_base_spectrum_model * </td>
+          <td class="paramname"> <em>model</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">cpl_error_code(*)(cpl_vector *, const cpl_polynomial *, irplib_base_spectrum_model *, int) </td>
+          <td class="paramname"> <em>filler</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">int </td>
+          <td class="paramname"> <em>hsize</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">cpl_boolean </td>
+          <td class="paramname"> <em>doplot</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">double * </td>
+          <td class="paramname"> <em>pxc</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Find shift(s) that maximizes (locally) the cross-correlation. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>self</em> </td><td>list of shifts that maximizes the cross-correlation (locally) </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>disp</em> </td><td>1D-Dispersion relation, at least of degree 1 </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>obs</em> </td><td>The observed spectrum to correlate against </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>model</em> </td><td>Pointer to model parameters </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>filler</em> </td><td>The function to fill the model spectrum </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>hsize</em> </td><td>Half the search-distance, hsize > 0 [pixel] </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>doplot</em> </td><td>Plot the cross-correlation as a function of pixel shift </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>pxc</em> </td><td>Iff non-NULL, set *pxc to cross-correlation on success </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>CPL_ERROR_NONE on success, otherwise the relevant CPL error code </dd></dl>
+<dl class="note"><dt><b>Note:</b></dt><dd>On success, self will be resized to fit the number of shifts.</dd></dl>
+<p>The shifts are listed in order of decreasing cross-correlation. If pxc is non-NULL, *pxc will be set to the cross-correlation at shift 0. </p>
+
+<p>Definition at line <a class="el" href="irplib__wavecal_8c_source.html#l00704">704</a> of file <a class="el" href="irplib__wavecal_8c_source.html">irplib_wavecal.c</a>.</p>
+
+<p>Referenced by <a class="el" href="irplib__wavecal_8c_source.html#l01421">irplib_polynomial_find_1d_from_correlation_all()</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="ga2da9c21054a19322705de2d4f48d1d3f"></a><!-- doxytag: member="irplib_wavecal.c::irplib_erf_antideriv" ref="ga2da9c21054a19322705de2d4f48d1d3f" args="(double x, double sigma)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">double irplib_erf_antideriv </td>
+          <td>(</td>
+          <td class="paramtype">double </td>
+          <td class="paramname"> <em>x</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">double </td>
+          <td class="paramname"> <em>sigma</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>The antiderivative of erx(x/sigma/sqrt(2)) with respect to x. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>x</em> </td><td>x </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>sigma</em> </td><td>sigma </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>The antiderivative </dd></dl>
+<dl class="note"><dt><b>Note:</b></dt><dd>This function is even. </dd></dl>
+
+<p>Definition at line <a class="el" href="irplib__wavecal_8c_source.html#l01293">1293</a> of file <a class="el" href="irplib__wavecal_8c_source.html">irplib_wavecal.c</a>.</p>
+
+<p>Referenced by <a class="el" href="irplib__wavecal_8c_source.html#l00976">irplib_vector_fill_line_spectrum_model()</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="ga7eec8e48f4888aba01b98d9e0dc2acc5"></a><!-- doxytag: member="irplib_wavecal.c::irplib_plot_spectrum_and_model" ref="ga7eec8e48f4888aba01b98d9e0dc2acc5" args="(const cpl_vector *self, const cpl_polynomial *disp1d, irplib_base_spectrum_model *model, cpl_error_code(*filler)(cpl_vector *, const cpl_polynomial *, irplib_base_spectrum_model *, int))" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">cpl_error_code irplib_plot_spectrum_and_model </td>
+          <td>(</td>
+          <td class="paramtype">const cpl_vector * </td>
+          <td class="paramname"> <em>self</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const cpl_polynomial * </td>
+          <td class="paramname"> <em>disp1d</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">irplib_base_spectrum_model * </td>
+          <td class="paramname"> <em>model</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">cpl_error_code(*)(cpl_vector *, const cpl_polynomial *, irplib_base_spectrum_model *, int) </td>
+          <td class="paramname"> <em>filler</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Plot a 1D spectrum and one from a model. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>self</em> </td><td>Vector with observed spectrum </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>disp1d</em> </td><td>1D-Dispersion relation, at least of degree 1 </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>model</em> </td><td>Pointer to model parameters </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>filler</em> </td><td>The function to fill the model spectrum </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>CPL_ERROR_NONE on success, otherwise the relevant CPL error code </dd></dl>
+<dl class="see"><dt><b>See also:</b></dt><dd><a class="el" href="group__irplib__wavecal.html#ga44aa21cb1fc1459ab3b360748a737974" title="Generate a 1D spectrum from a model and a dispersion relation.">irplib_vector_fill_line_spectrum()</a> </dd></dl>
+
+<p>Definition at line <a class="el" href="irplib__wavecal_8c_source.html#l00618">618</a> of file <a class="el" href="irplib__wavecal_8c_source.html">irplib_wavecal.c</a>.</p>
+
+<p>Referenced by <a class="el" href="irplib__wavecal_8c_source.html#l01421">irplib_polynomial_find_1d_from_correlation_all()</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="gaaa889f20c9483965ff6bab186d4f9972"></a><!-- doxytag: member="irplib_wavecal.c::irplib_polynomial_find_1d_from_correlation" ref="gaaa889f20c9483965ff6bab186d4f9972" args="(cpl_polynomial *self, int maxdeg, const cpl_vector *obs, irplib_base_spectrum_model *model, cpl_error_code(*filler)(cpl_vector *, const cpl_polynomial *, irplib_base_spectrum_model *, int), double pixtol, double pixstep, int hsize, int maxite, double *pxc)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">cpl_error_code irplib_polynomial_find_1d_from_correlation </td>
+          <td>(</td>
+          <td class="paramtype">cpl_polynomial * </td>
+          <td class="paramname"> <em>self</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">int </td>
+          <td class="paramname"> <em>maxdeg</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const cpl_vector * </td>
+          <td class="paramname"> <em>obs</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">irplib_base_spectrum_model * </td>
+          <td class="paramname"> <em>model</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">cpl_error_code(*)(cpl_vector *, const cpl_polynomial *, irplib_base_spectrum_model *, int) </td>
+          <td class="paramname"> <em>filler</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">double </td>
+          <td class="paramname"> <em>pixtol</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">double </td>
+          <td class="paramname"> <em>pixstep</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">int </td>
+          <td class="paramname"> <em>hsize</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">int </td>
+          <td class="paramname"> <em>maxite</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">double * </td>
+          <td class="paramname"> <em>pxc</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Modify self by maximizing the cross-correlation. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>self</em> </td><td>1D-Dispersion relation to modify, at least of degree 1 </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>maxdeg</em> </td><td>Maximize the cross-correlation by modifying maxdeg degree </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>obs</em> </td><td>The observed spectrum to correlate against </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>model</em> </td><td>The model of the lines/OTF etc. </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>filler</em> </td><td>The function to fill the model spectrum </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>pixtol</em> </td><td>The (positive) dispersion tolerance, e.g. 1e-6 </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>pixstep</em> </td><td>The step length used in the maximization, e.g. 0.5 [pixel] </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>hsize</em> </td><td>Half the search-distance to ensure a global-maximum, hsize >= 0 </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>maxite</em> </td><td>Maximum number of iterations, e.g. 100 * maxdeg </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>pxc</em> </td><td>On sucess, *pxc is the cross-correlation </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>CPL_ERROR_NONE on success, otherwise the relevant CPL error code </dd></dl>
+<dl class="note"><dt><b>Note:</b></dt><dd>Fails with CPL_ERROR_UNSUPPORTED_MODE if compiled without GSL. self must be increasing in the interval from 1 to the length of obs. </dd></dl>
+
+<p>Definition at line <a class="el" href="irplib__wavecal_8c_source.html#l00232">232</a> of file <a class="el" href="irplib__wavecal_8c_source.html">irplib_wavecal.c</a>.</p>
+
+<p>Referenced by <a class="el" href="irplib__wavecal_8c_source.html#l01421">irplib_polynomial_find_1d_from_correlation_all()</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="ga0adf260c4d27fc50bc8b4cbcc0264a4e"></a><!-- doxytag: member="irplib_wavecal.c::irplib_polynomial_find_1d_from_correlation_all" ref="ga0adf260c4d27fc50bc8b4cbcc0264a4e" args="(cpl_polynomial *self, int maxdeg, const cpl_vector *obs, int nmaxima, int linelim, irplib_base_spectrum_model *model, cpl_error_code(*filler)(cpl_vector *, const cpl_polynomial *, irplib_base_spectrum_model *, int), double pixtol, double pixstep, int hsize, int maxite, int maxfail, int maxcont [...]
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">cpl_error_code irplib_polynomial_find_1d_from_correlation_all </td>
+          <td>(</td>
+          <td class="paramtype">cpl_polynomial * </td>
+          <td class="paramname"> <em>self</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">int </td>
+          <td class="paramname"> <em>maxdeg</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const cpl_vector * </td>
+          <td class="paramname"> <em>obs</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">int </td>
+          <td class="paramname"> <em>nmaxima</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">int </td>
+          <td class="paramname"> <em>linelim</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">irplib_base_spectrum_model * </td>
+          <td class="paramname"> <em>model</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">cpl_error_code(*)(cpl_vector *, const cpl_polynomial *, irplib_base_spectrum_model *, int) </td>
+          <td class="paramname"> <em>filler</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">double </td>
+          <td class="paramname"> <em>pixtol</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">double </td>
+          <td class="paramname"> <em>pixstep</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">int </td>
+          <td class="paramname"> <em>hsize</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">int </td>
+          <td class="paramname"> <em>maxite</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">int </td>
+          <td class="paramname"> <em>maxfail</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">int </td>
+          <td class="paramname"> <em>maxcont</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">cpl_boolean </td>
+          <td class="paramname"> <em>doplot</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">double * </td>
+          <td class="paramname"> <em>pxc</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Modify self by maximizing the cross-correlation across all maxima. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>self</em> </td><td>1D-Dispersion relation to modify, at least of degree 1 </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>maxdeg</em> </td><td>Maximize the cross-correlation by modifying maxdeg degree </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>obs</em> </td><td>The observed spectrum to correlate against </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>nmaxima</em> </td><td>Number of local maxima to try (0 for all, 1 for global only) </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>linelim</em> </td><td>Maximum number of lines allowed in iterative refinement </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>model</em> </td><td>The model of the lines/OTF etc. </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>filler</em> </td><td>The function to fill the model spectrum </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>pixtol</em> </td><td>The (positive) dispersion tolerance, e.g. 1e-6 </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>pixstep</em> </td><td>The step length used in the maximization, e.g. 0.5 [pixel] </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>hsize</em> </td><td>Half the search-distance to ensure a global-maximum, hsize >= 0 </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>maxite</em> </td><td>Maximum number of iterations, e.g. 100 * maxdeg </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>maxfail</em> </td><td>Number of retries on failure </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>maxcont</em> </td><td>Number of retries on non-convergence </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>doplot</em> </td><td>Plot the cross-correlation as a function of pixel shift </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>pxc</em> </td><td>On sucess, *pxc is the cross-correlation </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>CPL_ERROR_NONE on success, otherwise the relevant CPL error code </dd></dl>
+<dl class="note"><dt><b>Note:</b></dt><dd>Fails with CPL_ERROR_UNSUPPORTED_MODE if compiled without GSL. self must be increasing in the interval from 1 to the length of obs. </dd></dl>
+
+<p>Definition at line <a class="el" href="irplib__wavecal_8c_source.html#l01421">1421</a> of file <a class="el" href="irplib__wavecal_8c_source.html">irplib_wavecal.c</a>.</p>
+
+<p>References <a class="el" href="irplib__wavecal_8c_source.html#l00704">irplib_bivector_find_shift_from_correlation()</a>, <a class="el" href="irplib__utils_8c_source.html#l00183">irplib_errorstate_dump_debug()</a>, <a class="el" href="irplib__wavecal_8c_source.html#l00618">irplib_plot_spectrum_and_model()</a>, and <a class="el" href="irplib__wavecal_8c_source.html#l00232">irplib_polynomial_find_1d_from_correlation()</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="ga2dd3251367e2ee8b8bd5ce080e9f31bb"></a><!-- doxytag: member="irplib_wavecal.c::irplib_polynomial_fit_2d_dispersion" ref="ga2dd3251367e2ee8b8bd5ce080e9f31bb" args="(cpl_polynomial *self, const cpl_image *imgwave, int fitdeg, double *presid)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">cpl_error_code irplib_polynomial_fit_2d_dispersion </td>
+          <td>(</td>
+          <td class="paramtype">cpl_polynomial * </td>
+          <td class="paramname"> <em>self</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const cpl_image * </td>
+          <td class="paramname"> <em>imgwave</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">int </td>
+          <td class="paramname"> <em>fitdeg</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">double * </td>
+          <td class="paramname"> <em>presid</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Fit a 2D-dispersion from an image of wavelengths. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>self</em> </td><td>2D-polynomial to hold fit </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>imgwave</em> </td><td>Image map of wavelengths, any pixeltype </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>fitdeg</em> </td><td>Degree of fit </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>presid</em> </td><td>On success, points to fitting residual </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>CPL_ERROR_NONE on success, otherwise the relevant CPL error code </dd></dl>
+
+<p>Definition at line <a class="el" href="irplib__wavecal_8c_source.html#l00148">148</a> of file <a class="el" href="irplib__wavecal_8c_source.html">irplib_wavecal.c</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="gabaec991ebc1b856766bf66768c4a6a19"></a><!-- doxytag: member="irplib_wavecal.c::irplib_polynomial_shift_1d_from_correlation" ref="gabaec991ebc1b856766bf66768c4a6a19" args="(cpl_polynomial *self, const cpl_vector *obs, irplib_base_spectrum_model *model, cpl_error_code(*filler)(cpl_vector *, const cpl_polynomial *, irplib_base_spectrum_model *, int), int hsize, cpl_boolean doplot, double *pxc)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">cpl_error_code irplib_polynomial_shift_1d_from_correlation </td>
+          <td>(</td>
+          <td class="paramtype">cpl_polynomial * </td>
+          <td class="paramname"> <em>self</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const cpl_vector * </td>
+          <td class="paramname"> <em>obs</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">irplib_base_spectrum_model * </td>
+          <td class="paramname"> <em>model</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">cpl_error_code(*)(cpl_vector *, const cpl_polynomial *, irplib_base_spectrum_model *, int) </td>
+          <td class="paramname"> <em>filler</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">int </td>
+          <td class="paramname"> <em>hsize</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">cpl_boolean </td>
+          <td class="paramname"> <em>doplot</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">double * </td>
+          <td class="paramname"> <em>pxc</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Shift self by the amount that maximizes the cross-correlation. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>self</em> </td><td>1D-Dispersion relation to shift, at least of degree 1 </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>obs</em> </td><td>The observed spectrum to correlate against </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>model</em> </td><td>Pointer to model parameters </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>filler</em> </td><td>The function to fill the model spectrum </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>hsize</em> </td><td>Half the search-distance, hsize > 0 [pixel] </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>doplot</em> </td><td>Plot the cross-correlation as a function of pixel shift </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>pxc</em> </td><td>Iff non-NULL, set *pxc to cross-correlation on success </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>CPL_ERROR_NONE on success, otherwise the relevant CPL error code </dd></dl>
+
+<p>Definition at line <a class="el" href="irplib__wavecal_8c_source.html#l00870">870</a> of file <a class="el" href="irplib__wavecal_8c_source.html">irplib_wavecal.c</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="ga44aa21cb1fc1459ab3b360748a737974"></a><!-- doxytag: member="irplib_wavecal.c::irplib_vector_fill_line_spectrum" ref="ga44aa21cb1fc1459ab3b360748a737974" args="(cpl_vector *self, const cpl_polynomial *disp, irplib_base_spectrum_model *lsslamp, int hsize)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">cpl_error_code irplib_vector_fill_line_spectrum </td>
+          <td>(</td>
+          <td class="paramtype">cpl_vector * </td>
+          <td class="paramname"> <em>self</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const cpl_polynomial * </td>
+          <td class="paramname"> <em>disp</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">irplib_base_spectrum_model * </td>
+          <td class="paramname"> <em>lsslamp</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">int </td>
+          <td class="paramname"> <em>hsize</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Generate a 1D spectrum from a model and a dispersion relation. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>self</em> </td><td>Vector to fill with spectrum </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>disp</em> </td><td>1D-Dispersion relation, at least of degree 1 </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>lsslamp</em> </td><td>Pointer to irplib_line_spectrum_model struct </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>hsize</em> </td><td>The 1st intensity in self will be disp(1-hsize), hsize >= 0 </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>CPL_ERROR_NONE on success, otherwise the relevant CPL error code</dd></dl>
+<p>The model comprises these elements: </p>
+<div class="fragment"><pre class="fragment">    <span class="keywordtype">double</span> wslit;  <span class="comment">// Slit Width</span>
+    <span class="keywordtype">double</span> wfwhm;  <span class="comment">// FWHM of transfer function</span>
+    <span class="keywordtype">double</span> xtrunc; <span class="comment">// Truncate transfer function beyond xtrunc, xtrunc > 0</span>
+    <span class="keyword">const</span> cpl_bivector * lines;    <span class="comment">// Catalogue of intensities, with</span>
+                                   <span class="comment">//   increasing X-vector elements</span>
+    cpl_vector         * linepix;  <span class="comment">// NULL, or temporary work-space of size</span>
+                                   <span class="comment">// equal to the lines bivector</span>
+                                   <span class="comment">// - should be uninitialized to zero</span>
+    <span class="keywordtype">unsigned</span>             cost;     <span class="comment">// Will be incremented for each call</span>
+    <span class="keywordtype">unsigned</span>             xcost;    <span class="comment">// Will be incremented for each OK call</span>
+</pre></div><p>The units of the X-values of the lines is assumed to be the same as that of disp, the units of wslit, wfwhm and xtrunc are assumed to be the same as the input unit of disp(), the units of self will be that of the Y-values of the lines. </p>
+
+<p>Definition at line <a class="el" href="irplib__wavecal_8c_source.html#l00433">433</a> of file <a class="el" href="irplib__wavecal_8c_source.html">irplib_wavecal.c</a>.</p>
+
+<p>References <a class="el" href="irplib__wavecal_8c_source.html#l00976">irplib_vector_fill_line_spectrum_model()</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="gae8e236a419dedc99eab52690f4a33901"></a><!-- doxytag: member="irplib_wavecal.c::irplib_vector_fill_line_spectrum_fast" ref="gae8e236a419dedc99eab52690f4a33901" args="(cpl_vector *self, const cpl_polynomial *disp, irplib_base_spectrum_model *lsslamp, int hsize)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">cpl_error_code irplib_vector_fill_line_spectrum_fast </td>
+          <td>(</td>
+          <td class="paramtype">cpl_vector * </td>
+          <td class="paramname"> <em>self</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const cpl_polynomial * </td>
+          <td class="paramname"> <em>disp</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">irplib_base_spectrum_model * </td>
+          <td class="paramname"> <em>lsslamp</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">int </td>
+          <td class="paramname"> <em>hsize</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Generate a 1D spectrum from a model and a dispersion relation. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>self</em> </td><td>Vector to fill with spectrum </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>disp</em> </td><td>1D-Dispersion relation, at least of degree 1 </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>lsslamp</em> </td><td>Pointer to irplib_line_spectrum_model struct </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>hsize</em> </td><td>The 1st intensity in self will be disp(1-hsize), hsize >= 0 </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>CPL_ERROR_NONE on success, otherwise the relevant CPL error code </dd></dl>
+<dl class="see"><dt><b>See also:</b></dt><dd><a class="el" href="group__irplib__wavecal.html#ga44aa21cb1fc1459ab3b360748a737974" title="Generate a 1D spectrum from a model and a dispersion relation.">irplib_vector_fill_line_spectrum()</a></dd></dl>
+<p>Complexity reduced from O(nw) to O(n + w), where n is number of lines and truncation width [pixel] of the line. </p>
+
+<p>Definition at line <a class="el" href="irplib__wavecal_8c_source.html#l00528">528</a> of file <a class="el" href="irplib__wavecal_8c_source.html">irplib_wavecal.c</a>.</p>
+
+<p>References <a class="el" href="irplib__wavecal_8c_source.html#l00976">irplib_vector_fill_line_spectrum_model()</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="ga0db5e24244f88b41627d5a385af81b33"></a><!-- doxytag: member="irplib_wavecal.c::irplib_vector_fill_line_spectrum_model" ref="ga0db5e24244f88b41627d5a385af81b33" args="(cpl_vector *self, cpl_vector *linepix, cpl_vector *erftmp, const cpl_polynomial *disp, const cpl_bivector *lines, double wslit, double wfwhm, double xtrunc, int hsize, cpl_boolean dofast, cpl_boolean dolog, unsigned *pulines)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">cpl_error_code irplib_vector_fill_line_spectrum_model </td>
+          <td>(</td>
+          <td class="paramtype">cpl_vector * </td>
+          <td class="paramname"> <em>self</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">cpl_vector * </td>
+          <td class="paramname"> <em>linepix</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">cpl_vector * </td>
+          <td class="paramname"> <em>erftmp</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const cpl_polynomial * </td>
+          <td class="paramname"> <em>disp</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const cpl_bivector * </td>
+          <td class="paramname"> <em>lines</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">double </td>
+          <td class="paramname"> <em>wslit</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">double </td>
+          <td class="paramname"> <em>wfwhm</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">double </td>
+          <td class="paramname"> <em>xtrunc</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">int </td>
+          <td class="paramname"> <em>hsize</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">cpl_boolean </td>
+          <td class="paramname"> <em>dofast</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">cpl_boolean </td>
+          <td class="paramname"> <em>dolog</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">unsigned * </td>
+          <td class="paramname"> <em>pulines</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Generate a 1D spectrum from (arc) lines and a dispersion relation. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>self</em> </td><td>Vector to fill with spectrum </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>linepix</em> </td><td>Vector to update with best guess of line pixel position </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>disp</em> </td><td>1D-Dispersion relation, at least of degree 1 </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>lines</em> </td><td>Catalogue of lines, with increasing wavelengths </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>wslit</em> </td><td>Positive width of the slit </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>wfwhm</em> </td><td>Positive FWHM of the transfer function </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>xtrunc</em> </td><td>Truncate the line profile beyond distance xtrunc, xtrunc > 0 </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>hsize</em> </td><td>The 1st intensity in self will be disp(1-hsize), hsize >= 0 </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>dofast</em> </td><td>Iff true compose profile from pairs of two integer-placed </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>dolog</em> </td><td>Iff true log(1+I) is used for the (positive) intensities </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>pulines</em> </td><td>Iff non-NULL, number of lines used, on success </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>CPL_ERROR_NONE on success, otherwise the relevant CPL error code </dd></dl>
+<dl class="see"><dt><b>See also:</b></dt><dd><a class="el" href="group__irplib__wavecal.html#ga44aa21cb1fc1459ab3b360748a737974" title="Generate a 1D spectrum from a model and a dispersion relation.">irplib_vector_fill_line_spectrum()</a> </dd></dl>
+<dl class="note"><dt><b>Note:</b></dt><dd>This function is supposed to be called via <a class="el" href="group__irplib__wavecal.html#ga44aa21cb1fc1459ab3b360748a737974" title="Generate a 1D spectrum from a model and a dispersion relation.">irplib_vector_fill_line_spectrum()</a>. </dd></dl>
+
+<p>Definition at line <a class="el" href="irplib__wavecal_8c_source.html#l00976">976</a> of file <a class="el" href="irplib__wavecal_8c_source.html">irplib_wavecal.c</a>.</p>
+
+<p>References <a class="el" href="irplib__wavecal_8c_source.html#l01293">irplib_erf_antideriv()</a>, and <a class="el" href="irplib__utils_8c_source.html#l00183">irplib_errorstate_dump_debug()</a>.</p>
+
+<p>Referenced by <a class="el" href="irplib__wavecal_8c_source.html#l00433">irplib_vector_fill_line_spectrum()</a>, <a class="el" href="irplib__wavecal_8c_source.html#l00528">irplib_vector_fill_line_spectrum_fast()</a>, <a class="el" href="irplib__wavecal_8c_source.html#l00480">irplib_vector_fill_logline_spectrum()</a>, and <a class="el" href="irplib__wavecal_8c_source.html#l00575">irplib_vector_fill_logline_spectrum_fast()</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="ga631e29d63bc65109f458915b5d1c8bb9"></a><!-- doxytag: member="irplib_wavecal.c::irplib_vector_fill_logline_spectrum" ref="ga631e29d63bc65109f458915b5d1c8bb9" args="(cpl_vector *self, const cpl_polynomial *disp, irplib_base_spectrum_model *lsslamp, int hsize)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">cpl_error_code irplib_vector_fill_logline_spectrum </td>
+          <td>(</td>
+          <td class="paramtype">cpl_vector * </td>
+          <td class="paramname"> <em>self</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const cpl_polynomial * </td>
+          <td class="paramname"> <em>disp</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">irplib_base_spectrum_model * </td>
+          <td class="paramname"> <em>lsslamp</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">int </td>
+          <td class="paramname"> <em>hsize</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Generate a 1D spectrum from a model and a dispersion relation. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>self</em> </td><td>Vector to fill with spectrum </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>disp</em> </td><td>1D-Dispersion relation, at least of degree 1 </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>lsslamp</em> </td><td>Pointer to irplib_line_spectrum_model struct </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>hsize</em> </td><td>The 1st intensity in self will be disp(1-hsize), hsize >= 0 </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>CPL_ERROR_NONE on success, otherwise the relevant CPL error code </dd></dl>
+<dl class="note"><dt><b>Note:</b></dt><dd>The logarithm is taken on the intensities </dd></dl>
+<dl class="see"><dt><b>See also:</b></dt><dd><a class="el" href="group__irplib__wavecal.html#ga44aa21cb1fc1459ab3b360748a737974" title="Generate a 1D spectrum from a model and a dispersion relation.">irplib_vector_fill_line_spectrum</a></dd></dl>
+<p>log(1+I) is used for the (positive) intensities </p>
+
+<p>Definition at line <a class="el" href="irplib__wavecal_8c_source.html#l00480">480</a> of file <a class="el" href="irplib__wavecal_8c_source.html">irplib_wavecal.c</a>.</p>
+
+<p>References <a class="el" href="irplib__wavecal_8c_source.html#l00976">irplib_vector_fill_line_spectrum_model()</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="gaa0000d5a34e290fc93dfcc936e631eb7"></a><!-- doxytag: member="irplib_wavecal.c::irplib_vector_fill_logline_spectrum_fast" ref="gaa0000d5a34e290fc93dfcc936e631eb7" args="(cpl_vector *self, const cpl_polynomial *disp, irplib_base_spectrum_model *lsslamp, int hsize)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">cpl_error_code irplib_vector_fill_logline_spectrum_fast </td>
+          <td>(</td>
+          <td class="paramtype">cpl_vector * </td>
+          <td class="paramname"> <em>self</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const cpl_polynomial * </td>
+          <td class="paramname"> <em>disp</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">irplib_base_spectrum_model * </td>
+          <td class="paramname"> <em>lsslamp</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">int </td>
+          <td class="paramname"> <em>hsize</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Generate a 1D spectrum from a model and a dispersion relation. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>self</em> </td><td>Vector to fill with spectrum </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>disp</em> </td><td>1D-Dispersion relation, at least of degree 1 </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>lsslamp</em> </td><td>Pointer to irplib_line_spectrum_model struct </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>hsize</em> </td><td>The 1st intensity in self will be disp(1-hsize), hsize >= 0 </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>CPL_ERROR_NONE on success, otherwise the relevant CPL error code </dd></dl>
+<dl class="note"><dt><b>Note:</b></dt><dd>The logarithm is taken on the intensities </dd></dl>
+<dl class="see"><dt><b>See also:</b></dt><dd><a class="el" href="group__irplib__wavecal.html#gae8e236a419dedc99eab52690f4a33901" title="Generate a 1D spectrum from a model and a dispersion relation.">irplib_vector_fill_line_spectrum_fast()</a></dd></dl>
+<p>log(1+I) is used for the (positive) intensities </p>
+
+<p>Definition at line <a class="el" href="irplib__wavecal_8c_source.html#l00575">575</a> of file <a class="el" href="irplib__wavecal_8c_source.html">irplib_wavecal.c</a>.</p>
+
+<p>References <a class="el" href="irplib__wavecal_8c_source.html#l00976">irplib_vector_fill_line_spectrum_model()</a>.</p>
+
+</div>
+</div>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__irplib__wcs.html b/html/group__irplib__wcs.html
new file mode 100644
index 0000000..bbcf879
--- /dev/null
+++ b/html/group__irplib__wcs.html
@@ -0,0 +1,19 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Functions related to WCS</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Functions related to WCS</h1><table border="0" cellpadding="0" cellspacing="0">
+</table>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__irplib__wlxcorr.html b/html/group__irplib__wlxcorr.html
new file mode 100644
index 0000000..f12f103
--- /dev/null
+++ b/html/group__irplib__wlxcorr.html
@@ -0,0 +1,21 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Wavelength Cross correlation w. plotting</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Wavelength Cross correlation w. plotting</h1><table border="0" cellpadding="0" cellspacing="0">
+</table>
+<dl class="user"><dt><b>Synopsis:</b></dt><dd><div class="fragment"><pre class="fragment"><span class="preprocessor">   #include "irplib_wlxcorr.h"</span>
+</pre></div> </dd></dl>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__absolute.html b/html/group__sinfo__absolute.html
new file mode 100644
index 0000000..f099a0f
--- /dev/null
+++ b/html/group__sinfo__absolute.html
@@ -0,0 +1,19 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Sinfo_absolute</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Sinfo_absolute</h1><table border="0" cellpadding="0" cellspacing="0">
+</table>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__absolute__utils.html b/html/group__sinfo__absolute__utils.html
new file mode 100644
index 0000000..ba587b0
--- /dev/null
+++ b/html/group__sinfo__absolute__utils.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: routines to determine the absolute positions</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>routines to determine the absolute positions</h1><table border="0" cellpadding="0" cellspacing="0">
+</table>
+<p>of the slitlets out of an emission line frame </p>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__bad__pix__search.html b/html/group__sinfo__bad__pix__search.html
new file mode 100644
index 0000000..dc478b6
--- /dev/null
+++ b/html/group__sinfo__bad__pix__search.html
@@ -0,0 +1,151 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Bad Pixel Search</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Bad Pixel Search</h1><table border="0" cellpadding="0" cellspacing="0">
+<tr><td colspan="2"><h2>Functions</h2></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="group__sinfo__bad__pix__search.html#ga4f320ea65a00f127ece79fd2c6416a15">sinfo_bp_dist_config_add</a> (cpl_parameterlist *list)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Adds parameters for the spectrum extraction.  <a href="#ga4f320ea65a00f127ece79fd2c6416a15"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="group__sinfo__bad__pix__search.html#gaa86bb476f2328523607038df849c2beb">sinfo_bp_noise_config_add</a> (cpl_parameterlist *list)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Adds parameters for the spectrum extraction.  <a href="#gaa86bb476f2328523607038df849c2beb"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="group__sinfo__bad__pix__search.html#ga6f49eed82217a86089ff7f23465ae3e0">sinfo_bp_norm_config_add</a> (cpl_parameterlist *list)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Adds parameters for the spectrum extraction.  <a href="#ga6f49eed82217a86089ff7f23465ae3e0"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="group__sinfo__bad__pix__search.html#gaba8d9bda2f23ab3e4218598434a3ceeb">sinfo_bp_sky_config_add</a> (cpl_parameterlist *list)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Adds parameters for the spectrum extraction.  <a href="#gaba8d9bda2f23ab3e4218598434a3ceeb"></a><br/></td></tr>
+</table>
+<hr/><a name="_details"></a><h2>Detailed Description</h2>
+<p>TBD </p>
+<hr/><h2>Function Documentation</h2>
+<a class="anchor" id="ga4f320ea65a00f127ece79fd2c6416a15"></a><!-- doxytag: member="sinfo_bp_dist_config.c::sinfo_bp_dist_config_add" ref="ga4f320ea65a00f127ece79fd2c6416a15" args="(cpl_parameterlist *list)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">void sinfo_bp_dist_config_add </td>
+          <td>(</td>
+          <td class="paramtype">cpl_parameterlist * </td>
+          <td class="paramname"> <em>list</em></td>
+          <td> ) </td>
+          <td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Adds parameters for the spectrum extraction. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>list</em> </td><td>Parameter list to which parameters are added.</td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>Nothing.</dd></dl>
+<p>TBD </p>
+
+<p>Definition at line <a class="el" href="sinfo__bp__dist__config_8c_source.html#l00055">55</a> of file <a class="el" href="sinfo__bp__dist__config_8c_source.html">sinfo_bp_dist_config.c</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="gaa86bb476f2328523607038df849c2beb"></a><!-- doxytag: member="sinfo_bp_noise_config.c::sinfo_bp_noise_config_add" ref="gaa86bb476f2328523607038df849c2beb" args="(cpl_parameterlist *list)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">void sinfo_bp_noise_config_add </td>
+          <td>(</td>
+          <td class="paramtype">cpl_parameterlist * </td>
+          <td class="paramname"> <em>list</em></td>
+          <td> ) </td>
+          <td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Adds parameters for the spectrum extraction. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>list</em> </td><td>Parameter list to which parameters are added.</td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>Nothing.</dd></dl>
+<p>TBD </p>
+
+<p>Definition at line <a class="el" href="sinfo__bp__noise__config_8c_source.html#l00055">55</a> of file <a class="el" href="sinfo__bp__noise__config_8c_source.html">sinfo_bp_noise_config.c</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="ga6f49eed82217a86089ff7f23465ae3e0"></a><!-- doxytag: member="sinfo_bp_norm_config.c::sinfo_bp_norm_config_add" ref="ga6f49eed82217a86089ff7f23465ae3e0" args="(cpl_parameterlist *list)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">void sinfo_bp_norm_config_add </td>
+          <td>(</td>
+          <td class="paramtype">cpl_parameterlist * </td>
+          <td class="paramname"> <em>list</em></td>
+          <td> ) </td>
+          <td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Adds parameters for the spectrum extraction. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>list</em> </td><td>Parameter list to which parameters are added.</td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>Nothing.</dd></dl>
+<p>TBD </p>
+
+<p>Definition at line <a class="el" href="sinfo__bp__norm__config_8c_source.html#l00055">55</a> of file <a class="el" href="sinfo__bp__norm__config_8c_source.html">sinfo_bp_norm_config.c</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="gaba8d9bda2f23ab3e4218598434a3ceeb"></a><!-- doxytag: member="sinfo_bp_sky_config.c::sinfo_bp_sky_config_add" ref="gaba8d9bda2f23ab3e4218598434a3ceeb" args="(cpl_parameterlist *list)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">void sinfo_bp_sky_config_add </td>
+          <td>(</td>
+          <td class="paramtype">cpl_parameterlist * </td>
+          <td class="paramname"> <em>list</em></td>
+          <td> ) </td>
+          <td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Adds parameters for the spectrum extraction. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>list</em> </td><td>Parameter list to which parameters are added.</td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>Nothing.</dd></dl>
+<p>TBD </p>
+
+<p>Definition at line <a class="el" href="sinfo__bp__sky__config_8c_source.html#l00055">55</a> of file <a class="el" href="sinfo__bp__sky__config_8c_source.html">sinfo_bp_sky_config.c</a>.</p>
+
+</div>
+</div>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__balance.html b/html/group__sinfo__balance.html
new file mode 100644
index 0000000..dd39e85
--- /dev/null
+++ b/html/group__sinfo__balance.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: To be removed</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>To be removed</h1><table border="0" cellpadding="0" cellspacing="0">
+</table>
+<p>TBD </p>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__baryvel.html b/html/group__sinfo__baryvel.html
new file mode 100644
index 0000000..95ecd50
--- /dev/null
+++ b/html/group__sinfo__baryvel.html
@@ -0,0 +1,21 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Velocity correction</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Velocity correction</h1><table border="0" cellpadding="0" cellspacing="0">
+</table>
+<p>Compute barycentric, heliocentric velocity corrections</p>
+<p>The code in this source file is a 1-to-1 translation of MIDAS COMPUT/BARYCOR as defined in /prim/general/src/compxy.for (only the necessary parts were translated). The code is not meant to be particularly readable/maintainable. To understand the computation the best starting point is probably P. Stumpff, A&A Suppl. Ser. 41, pp. 1-8 (1980) </p>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__boltzmann.html b/html/group__sinfo__boltzmann.html
new file mode 100644
index 0000000..b2ffaf7
--- /dev/null
+++ b/html/group__sinfo__boltzmann.html
@@ -0,0 +1,450 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Boltzmann function operations</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Boltzmann function operations</h1><table border="0" cellpadding="0" cellspacing="0">
+<tr><td colspan="2"><h2>Functions</h2></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">float </td><td class="memItemRight" valign="bottom"><a class="el" href="group__sinfo__boltzmann.html#ga858ad4d37da835f1ff4740d0f23920c1">sinfo_new_boltz</a> (float *xdat, float *parlist)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">calculates the value of a Boltzmann function with parameters parlist at the position xdat  <a href="#ga858ad4d37da835f1ff4740d0f23920c1"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="group__sinfo__boltzmann.html#ga72b3c6f0c971fb402bd68c8d0fcf5e30">sinfo_new_boltz_deriv</a> (float *xdat, float *parlist, float *dervs)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">calculates the partial derivatives for a Boltzmann function with parameters parlist at position xdat  <a href="#ga72b3c6f0c971fb402bd68c8d0fcf5e30"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="group__sinfo__boltzmann.html#ga7e03e34851f7c367ab3827c58e8c81c5">sinfo_new_lsqfit</a> (float *xdat, int *xdim, float *ydat, float *wdat, int *ndat, float *fpar, float *epar, int *mpar, int *npar, float *tol, int *its, float *lab)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">makes a least-squares fit of a function to a set of data points.  <a href="#ga7e03e34851f7c367ab3827c58e8c81c5"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="group__sinfo__boltzmann.html#gab3549f7bb876fb4091ba3c0bd64d267d">sinfo_new_fit_slits_boltz</a> (cpl_image *lineImage, FitParams **par, float **slit_pos, int box_length, float y_box, float diff_tol)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">fits the beginning and end position of the slitlets by using non-linear least square fitting of a Boltzmann function fits a Boltzmann function to the slitlet edges exposed and indicated by the brightest emission lines.  <a href="#gab3549f7bb876fb4091ba3c0bd64d267d"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="group__sinfo__boltzmann.html#gafe44b4032a5b85ff4b88bf7518793b21">sinfo_new_fit_slits_boltz_single_line</a> (cpl_image *lineImage, float **slit_pos, int box_length, float y_box, int low_pos, int high_pos)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">fits the beginning and end position of the slitlets by using non-linear least square fitting of a Boltzmann function  <a href="#gafe44b4032a5b85ff4b88bf7518793b21"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="group__sinfo__boltzmann.html#ga1851d695a240ae0d23d20657f02867bb">sinfo_new_fit_slits_boltz_with_estimate</a> (cpl_image *lineImage, float **slit_pos, int box_length, float y_box, float diff_tol, int low_pos, int high_pos)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">its the beginning and end position of the slitlets by using non-linear least square fitting of a Boltzmann function  <a href="#ga1851d695a240ae0d23d20657f02867bb"></a><br/></td></tr>
+</table>
+<hr/><a name="_details"></a><h2>Detailed Description</h2>
+<p>TBD </p>
+<hr/><h2>Function Documentation</h2>
+<a class="anchor" id="ga858ad4d37da835f1ff4740d0f23920c1"></a><!-- doxytag: member="sinfo_boltzmann.c::sinfo_new_boltz" ref="ga858ad4d37da835f1ff4740d0f23920c1" args="(float *xdat, float *parlist)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">float sinfo_new_boltz </td>
+          <td>(</td>
+          <td class="paramtype">float * </td>
+          <td class="paramname"> <em>xdat</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">float * </td>
+          <td class="paramname"> <em>parlist</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>calculates the value of a Boltzmann function with parameters parlist at the position xdat </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>xdat</em> </td><td>position array </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>parlist</em> </td><td>parameter list</td></tr>
+  </table>
+  </dd>
+</dl>
+<p>The parameters are: # parlist(0): background1 # parlist(1): background2 # parlist(2): central position # parlist(3): width </p>
+<dl class="return"><dt><b>Returns:</b></dt><dd>function value of a Boltzmann function that is y = (parlist(0) - parlist(1)) / (1+exp((x-parlist(2))/parlist(3))) + parlist(1) </dd></dl>
+
+<p>Definition at line <a class="el" href="sinfo__boltzmann_8c_source.html#l00245">245</a> of file <a class="el" href="sinfo__boltzmann_8c_source.html">sinfo_boltzmann.c</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="ga72b3c6f0c971fb402bd68c8d0fcf5e30"></a><!-- doxytag: member="sinfo_boltzmann.c::sinfo_new_boltz_deriv" ref="ga72b3c6f0c971fb402bd68c8d0fcf5e30" args="(float *xdat, float *parlist, float *dervs)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">void sinfo_new_boltz_deriv </td>
+          <td>(</td>
+          <td class="paramtype">float * </td>
+          <td class="paramname"> <em>xdat</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">float * </td>
+          <td class="paramname"> <em>parlist</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">float * </td>
+          <td class="paramname"> <em>dervs</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>calculates the partial derivatives for a Boltzmann function with parameters parlist at position xdat </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>xdat</em> </td><td>position array xdat </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>parlist</em> </td><td>parameter list # The parameters are: # parlist(0): background1 # parlist(1): background2 # parlist(2): central position # parlist(3): width </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>dervs</em> </td><td>derivative value of a Boltzmann function at\ position xdat: dervs # dervs[0]: partial derivative by background1 # dervs[1]: partial derivative by background2 # dervs[2]: partial derivative by central position # dervs[3]: partial derivative by the width</td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>nothing, void </dd></dl>
+
+<p>Definition at line <a class="el" href="sinfo__boltzmann_8c_source.html#l00278">278</a> of file <a class="el" href="sinfo__boltzmann_8c_source.html">sinfo_boltzmann.c</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="gab3549f7bb876fb4091ba3c0bd64d267d"></a><!-- doxytag: member="sinfo_boltzmann.c::sinfo_new_fit_slits_boltz" ref="gab3549f7bb876fb4091ba3c0bd64d267d" args="(cpl_image *lineImage, FitParams **par, float **slit_pos, int box_length, float y_box, float diff_tol)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">int sinfo_new_fit_slits_boltz </td>
+          <td>(</td>
+          <td class="paramtype">cpl_image * </td>
+          <td class="paramname"> <em>lineImage</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">FitParams ** </td>
+          <td class="paramname"> <em>par</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">float ** </td>
+          <td class="paramname"> <em>slit_pos</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">int </td>
+          <td class="paramname"> <em>box_length</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">float </td>
+          <td class="paramname"> <em>y_box</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">float </td>
+          <td class="paramname"> <em>diff_tol</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>fits the beginning and end position of the slitlets by using non-linear least square fitting of a Boltzmann function fits a Boltzmann function to the slitlet edges exposed and indicated by the brightest emission lines. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>lineImage,:</em> </td><td>emission line frame </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>par,:</em> </td><td>fit parameter data structure of fitted lines </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>slit_pos,:</em> </td><td>allocated dummy array for the slitlet positions [32][2] </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>box_length,:</em> </td><td>pixel length of the row box within the fit is done </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>y_box,:</em> </td><td>small box in spectral direction within the slitlet may lie. </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>diff_tol,:</em> </td><td>maximum tolerable difference of the resulting fit position with respect to the expected position. If difference is greater the expected position is taken. </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>slit_pos: beginning and end position of the slitlets to sub-pixel accuracy # 0 if it worked, # -1 if there was no line image given, # -2 if there were no line fit parameters given, # -3 if there was no dummy array for the slit positions # allocated # -4 if the given box length is impossible # -5 if the given y box length is impossible # -6 if the given difference tolerance is too small # -7 if there were no emission lines found in the first  [...]
+<p>fits the beginning and end position of the slitlets by using non-linear least square fitting of a Boltzmann function fits a Boltzmann function to the slitlet edges exposed and indicated by the brightest emission lines. To achieve this, the fit parameters are used to find the brightest emission line and to get its position for each column. The least squares fit is done by using a box smaller than the size of two slitlets ----------------------------------------------------------------- [...]
+
+<p>Definition at line <a class="el" href="sinfo__boltzmann_8c_source.html#l00865">865</a> of file <a class="el" href="sinfo__boltzmann_8c_source.html">sinfo_boltzmann.c</a>.</p>
+
+<p>References <a class="el" href="sinfo__msg_8h_source.html#l00069">sinfo_msg_error</a>, <a class="el" href="sinfo__msg_8h_source.html#l00093">sinfo_msg_warning</a>, and <a class="el" href="sinfo__boltzmann_8c_source.html#l00627">sinfo_new_lsqfit()</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="gafe44b4032a5b85ff4b88bf7518793b21"></a><!-- doxytag: member="sinfo_boltzmann.c::sinfo_new_fit_slits_boltz_single_line" ref="gafe44b4032a5b85ff4b88bf7518793b21" args="(cpl_image *lineImage, float **slit_pos, int box_length, float y_box, int low_pos, int high_pos)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">int sinfo_new_fit_slits_boltz_single_line </td>
+          <td>(</td>
+          <td class="paramtype">cpl_image * </td>
+          <td class="paramname"> <em>lineImage</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">float ** </td>
+          <td class="paramname"> <em>slit_pos</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">int </td>
+          <td class="paramname"> <em>box_length</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">float </td>
+          <td class="paramname"> <em>y_box</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">int </td>
+          <td class="paramname"> <em>low_pos</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">int </td>
+          <td class="paramname"> <em>high_pos</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>fits the beginning and end position of the slitlets by using non-linear least square fitting of a Boltzmann function </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>lineImage</em> </td><td>emission line frame </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>slit_pos</em> </td><td>allocated dummy array for the slitlet positions [min32][2] </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>box_length</em> </td><td>pixel length of the row box within the fit is done </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>y_box,:</em> </td><td>small box in spectral direction within the slitlet may lie. </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>low_pos</em> </td><td>pixel positions in spectral direction between which the line should be located. </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>high_pos</em> </td><td>pixel positions in spectral direction between which the line should be located. </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>slit_pos: beginning and end position of the slitlets to sub-pixel accuracy # 0 if it worked, # -1 if it failed,</dd></dl>
+<p>fits the beginning and end position of the slitlets by using non-linear least square fitting of a Boltzmann function fits a Boltzmann function to the slitlet edges exposed and indicated by the brightest emission lines. The slitlet is searched with user given positions. The least squares fit is done by using a box smaller than the size of two slitlets </p>
+
+<p>Definition at line <a class="el" href="sinfo__boltzmann_8c_source.html#l01620">1620</a> of file <a class="el" href="sinfo__boltzmann_8c_source.html">sinfo_boltzmann.c</a>.</p>
+
+<p>References <a class="el" href="sinfo__msg_8h_source.html#l00069">sinfo_msg_error</a>, <a class="el" href="sinfo__msg_8h_source.html#l00093">sinfo_msg_warning</a>, and <a class="el" href="sinfo__boltzmann_8c_source.html#l00627">sinfo_new_lsqfit()</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="ga1851d695a240ae0d23d20657f02867bb"></a><!-- doxytag: member="sinfo_boltzmann.c::sinfo_new_fit_slits_boltz_with_estimate" ref="ga1851d695a240ae0d23d20657f02867bb" args="(cpl_image *lineImage, float **slit_pos, int box_length, float y_box, float diff_tol, int low_pos, int high_pos)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">int sinfo_new_fit_slits_boltz_with_estimate </td>
+          <td>(</td>
+          <td class="paramtype">cpl_image * </td>
+          <td class="paramname"> <em>lineImage</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">float ** </td>
+          <td class="paramname"> <em>slit_pos</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">int </td>
+          <td class="paramname"> <em>box_length</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">float </td>
+          <td class="paramname"> <em>y_box</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">float </td>
+          <td class="paramname"> <em>diff_tol</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">int </td>
+          <td class="paramname"> <em>low_pos</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">int </td>
+          <td class="paramname"> <em>high_pos</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>its the beginning and end position of the slitlets by using non-linear least square fitting of a Boltzmann function </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>lineImage</em> </td><td>emission line frame </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>slit_pos</em> </td><td>estimation array for the slitlet positions [min32][2] </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>box_length</em> </td><td>pixel length of the row box within the fit is done </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>y_box</em> </td><td>small box in spectral direction within the slitlet may lie. </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>diff_tol</em> </td><td>tolerance on slitlets position </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>low_pos</em> </td><td>pixel positions in spectral direction between which the line should be located. </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>high_pos</em> </td><td>pixel positions in spectral direction between which the line should be located.</td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>slit_pos beginning and end position of the slitlets to sub-pixel accuracy # 0 if it worked, # -1 if it failed, </dd></dl>
+<dl class="note"><dt><b>Note:</b></dt><dd>fits the beginning and end position of the slitlets by using non-linear least square fitting of a Boltzmann function fits a Boltzmann function to the slitlet edges exposed and indicated by the brightest emission lines. The slitlet is searched within user given positions. The least squares fit is done by using a box smaller than the size of two slitlets </dd></dl>
+
+<p>Definition at line <a class="el" href="sinfo__boltzmann_8c_source.html#l02164">2164</a> of file <a class="el" href="sinfo__boltzmann_8c_source.html">sinfo_boltzmann.c</a>.</p>
+
+<p>References <a class="el" href="sinfo__msg_8h_source.html#l00069">sinfo_msg_error</a>, <a class="el" href="sinfo__msg_8h_source.html#l00093">sinfo_msg_warning</a>, and <a class="el" href="sinfo__boltzmann_8c_source.html#l00627">sinfo_new_lsqfit()</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="ga7e03e34851f7c367ab3827c58e8c81c5"></a><!-- doxytag: member="sinfo_boltzmann.c::sinfo_new_lsqfit" ref="ga7e03e34851f7c367ab3827c58e8c81c5" args="(float *xdat, int *xdim, float *ydat, float *wdat, int *ndat, float *fpar, float *epar, int *mpar, int *npar, float *tol, int *its, float *lab)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">int sinfo_new_lsqfit </td>
+          <td>(</td>
+          <td class="paramtype">float * </td>
+          <td class="paramname"> <em>xdat</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">int * </td>
+          <td class="paramname"> <em>xdim</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">float * </td>
+          <td class="paramname"> <em>ydat</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">float * </td>
+          <td class="paramname"> <em>wdat</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">int * </td>
+          <td class="paramname"> <em>ndat</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">float * </td>
+          <td class="paramname"> <em>fpar</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">float * </td>
+          <td class="paramname"> <em>epar</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">int * </td>
+          <td class="paramname"> <em>mpar</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">int * </td>
+          <td class="paramname"> <em>npar</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">float * </td>
+          <td class="paramname"> <em>tol</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">int * </td>
+          <td class="paramname"> <em>its</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">float * </td>
+          <td class="paramname"> <em>lab</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>makes a least-squares fit of a function to a set of data points. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>xdat,:</em> </td><td>position, coordinates of data points. xdat is 2 dimensional: XDAT ( XDIM, NDAT ) </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>xdim,:</em> </td><td>dimension of fit </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>ydat,:</em> </td><td>data points </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>wdat,:</em> </td><td>weights for data points </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>ndat,:</em> </td><td>number of data points </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>fpar,:</em> </td><td>on input contains initial estimates of the parameters for non-linear fits, on output the fitted parameters. </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>epar,:</em> </td><td>contains estimates of the errors in fitted parameters </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>mpar,:</em> </td><td>logical mask telling which parameters are free (non-zero) and which parameters are fixed (0) </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>npar,:</em> </td><td>number of function parameters ( free + fixed ) </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>tol,:</em> </td><td>relative tolerance. sinfo_lsqfit stops when successive iterations fail to produce a decrement in reduced chi-squared less than tol. If tol is less than the minimum tolerance possible, tol will be set to this value. This means that maximum accuracy can be obtained by setting tol = 0.0. </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>its,:</em> </td><td>maximum number of iterations </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>lab,:</em> </td><td>mixing parameter, lab determines the initial weight of steepest descent method relative to the Taylor method lab should be a small value (i.e. 0.01). lab can only be zero when the partial derivatives are independent of the parameters. In fact in this case lab should be exactly equal to zero. </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>number of iterations needed to achieve convergence according to tol. When this number is negative, the fitting was not continued because a fatal error occurred: # -1 too many free parameters, maximum is 32 # -2 no free parameters # -3 not enough degrees of freedom # -4 maximum number of iterations too small to obtain a solution which satisfies tol. # -5 diagonal of sinfo_matrix contains elements which are zero # -6 determinant of the coeffic [...]
+<p>The method used is described in: Marquardt, J.Soc.Ind.Appl.Math. 11. 431 (1963). This method is a mixture of the steepest descent method and the Taylor method. </p>
+
+<p>Definition at line <a class="el" href="sinfo__boltzmann_8c_source.html#l00627">627</a> of file <a class="el" href="sinfo__boltzmann_8c_source.html">sinfo_boltzmann.c</a>.</p>
+
+<p>Referenced by <a class="el" href="sinfo__boltzmann_8c_source.html#l00865">sinfo_new_fit_slits_boltz()</a>, <a class="el" href="sinfo__boltzmann_8c_source.html#l01620">sinfo_new_fit_slits_boltz_single_line()</a>, and <a class="el" href="sinfo__boltzmann_8c_source.html#l02164">sinfo_new_fit_slits_boltz_with_estimate()</a>.</p>
+
+</div>
+</div>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__coltilt.html b/html/group__sinfo__coltilt.html
new file mode 100644
index 0000000..4c4bf31
--- /dev/null
+++ b/html/group__sinfo__coltilt.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Column tilt computation</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Column tilt computation</h1><table border="0" cellpadding="0" cellspacing="0">
+</table>
+<p>TBD </p>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__companion.html b/html/group__sinfo__companion.html
new file mode 100644
index 0000000..dd39e85
--- /dev/null
+++ b/html/group__sinfo__companion.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: To be removed</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>To be removed</h1><table border="0" cellpadding="0" cellspacing="0">
+</table>
+<p>TBD </p>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__cube__construct.html b/html/group__sinfo__cube__construct.html
new file mode 100644
index 0000000..a2b099a
--- /dev/null
+++ b/html/group__sinfo__cube__construct.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Cube generation functions</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Cube generation functions</h1><table border="0" cellpadding="0" cellspacing="0">
+</table>
+<p>TBD </p>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__dark__cfg.html b/html/group__sinfo__dark__cfg.html
new file mode 100644
index 0000000..f3530f3
--- /dev/null
+++ b/html/group__sinfo__dark__cfg.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Dark manipulation functions</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Dark manipulation functions</h1><table border="0" cellpadding="0" cellspacing="0">
+</table>
+<p>TBD </p>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__detlin.html b/html/group__sinfo__detlin.html
new file mode 100644
index 0000000..381c5ca
--- /dev/null
+++ b/html/group__sinfo__detlin.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Detector Linearity Determination Functions</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Detector Linearity Determination Functions</h1><table border="0" cellpadding="0" cellspacing="0">
+</table>
+<p>TBD </p>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__dfs.html b/html/group__sinfo__dfs.html
new file mode 100644
index 0000000..5d95b56
--- /dev/null
+++ b/html/group__sinfo__dfs.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: DFS related Utilities</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>DFS related Utilities</h1><table border="0" cellpadding="0" cellspacing="0">
+</table>
+<p>TBD </p>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__distortion.html b/html/group__sinfo__distortion.html
new file mode 100644
index 0000000..c6ce3a7
--- /dev/null
+++ b/html/group__sinfo__distortion.html
@@ -0,0 +1,19 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Distortion correction functions</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Distortion correction functions</h1><table border="0" cellpadding="0" cellspacing="0">
+</table>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__dump.html b/html/group__sinfo__dump.html
new file mode 100644
index 0000000..a47ad78
--- /dev/null
+++ b/html/group__sinfo__dump.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Print CPL objects</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Print CPL objects</h1><table border="0" cellpadding="0" cellspacing="0">
+</table>
+<p>Functions that enables dumping (using CPL's messaging system) some otherwise non-dumpable CPL objects </p>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__error.html b/html/group__sinfo__error.html
new file mode 100644
index 0000000..fed9bad
--- /dev/null
+++ b/html/group__sinfo__error.html
@@ -0,0 +1,234 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Error handling</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Error handling</h1><table border="0" cellpadding="0" cellspacing="0">
+</table>
+<hr/><a name="_details"></a><h2>Detailed Description</h2>
+<p>This error handling module extends CPL's error handler by adding error tracing and automatic memory deallocation in case of an error. Like in CPL the current error state is indicated by the <code>cpl_error_code</code> (returned by the function <code>cpl_error_get_code()</code> ).</p>
+<p>The error tracing makes it possible to see where (source file, function name, line number) an error first occured, as well as the sequence of function calls preceding the error. A typical output looks like: </p>
+<div class="fragment"><pre class="fragment">   An error occured, dumping error trace:
+   
+   Wavelength calibration did not converge. After 13 iterations the RMS was 
+   0.300812 pixels. Try to improve
+   the initial guess solution (The iterative process did not converge)
+     in [3]sinfo_wavecal_identify() at sinfo_wavecal_identify.c :101
+    
+   Could not calibrate orders
+     in [2]sinfo_wavecal_process_chip() at sinfo_wavecal.c  :426
+     
+   Wavelength calibration failed
+     in [1]sinfo_wavecal() at sinfo_wavecal.c  :679
+</pre></div><p>However, the main motivation of this extension is to simplify the error checking and handling. A single line of source code</p>
+<div class="fragment"><pre class="fragment">   check( dispersion_relation = sinfo_wavecal_identify(linetable[window-1],
+                                                      line_refer,
+                                                      initial_dispersion, 
+                                                      WAVECAL_MODE, DEGREE, 
+                                                      TOLERANCE, ALPHA, 
+                                                      MAXERROR),
+           <span class="stringliteral">"Could not calibrate orders"</span>);
+</pre></div><p>has the same effect as</p>
+<div class="fragment"><pre class="fragment">   <span class="keywordflow">if</span> (cpl_error_get_code() != CPL_ERROR_NONE) {
+      cpl_msg_error(cpl_func, 
+                    <span class="stringliteral">"An unexpected error (%s) has occurred "</span>
+                    <span class="stringliteral">"in %s() at %-15s :%-3d"</span>,
+                           cpl_error_get_message(),
+                           cpl_func,
+                           __FILE__,
+                           __LINE__);
+      sinfo_free_image(&spectrum);
+      sinfo_free_image(&cropped_image);
+      sinfo_free_image(&debug_image);
+      sinfo_free_cpl(&relative_order);
+      polynomial_delete(&initial_dispersion);
+      polynomial_delete(&dispersion_relation);
+      <span class="keywordflow">return</span> NULL;
+   }
+
+   dispersion_relation = sinfo_wavecal_identify(linetable[window-1],
+                                               line_refer,
+                                               initial_dispersion, 
+                                               WAVECAL_MODE, DEGREE, 
+                                               TOLERANCE, ALPHA, MAXERROR);
+
+   <span class="keywordflow">if</span> (cpl_error_get_code() != CPL_ERROR_NONE) {
+      cpl_msg_error(cpl_func, <span class="stringliteral">"ERROR: Could not calibrate orders (%s) in %s() </span>
+<span class="stringliteral">      at %-15s :%-3d"</span>,
+                           cpl_error_get_message(),
+                           cpl_func,
+                           __FILE__,
+                           __LINE__);
+      sinfo_free_image(&spectrum);
+      sinfo_free_image(&cropped_image);
+      sinfo_free_image(&debug_image);
+      sinfo_free_cpl(&relative_order);
+      polynomial_delete(&initial_dispersion);
+      polynomial_delete(&dispersion_relation);
+      <span class="keywordflow">return</span> NULL;
+   }
+</pre></div><p>This of course makes the source code more compact and hence easier to read (and maintain) and allows for intensive error checking with minimal effort.</p>
+<p>Additionally, editing the <code>check()</code> macro (described below) allows for debugging/tracing information at every function entry and exit.</p>
+<dl class="user"><dt><b>Usage</b></dt><dd></dd></dl>
+<p>New errors are set with the macros <code>assure()</code> and <code>passure()</code>, and sub-functions that might set a <code>cpl_error_code</code> are checked using the macros <code>check()</code> and <code>pcheck()</code> . The function <code>_sinfo_error_set()</code> should never be called directly. These macros check if an error occured and, if so, jumps to the <code>cleanup</code> label which must be defined at the end of each function. After the <code>cleanup</code> label every  [...]
+<p>At the very end of a recipe the error state should be checked and <code>sinfo_error_dump()</code> called on error: </p>
+<div class="fragment"><pre class="fragment">   <span class="keywordflow">if</span> ( cpl_error_get_code() != CPL_ERROR_NONE )
+   {
+      sinfo_error_dump(cpl_func);
+   }
+</pre></div><p>When using this scheme:</p>
+<ul>
+<li>There should be only one <code>return</code> statement per function (after the <code>cleanup</code> label).</li>
+</ul>
+<ul>
+<li>All pointers to dynamically allocated memory must be declared at the beginning of a function.</li>
+</ul>
+<ul>
+<li>Pointers must be initialized to NULL (which is a good idea anyway).</li>
+</ul>
+<ul>
+<li>Pointers must be set to NULL when they are not used (which is a good idea anyway).</li>
+</ul>
+<p>Consider the example</p>
+<div class="fragment"><pre class="fragment">   <span class="keywordtype">int</span> function_name(...)
+   {
+      cpl_image * image = NULL;
+      cpl_image * another_image;       / *  Wrong: Pointer must be initialized 
+                                                   to NULL. On cleanup, 
+                                                   cpl_image_delete() will try 
+                                                   to deallocate whatever
+                                                   this pointer points to. If 
+                                                   the pointer is NULL,
+                                                   the deallocator function 
+                                                   will do nothing.  * /
+      :
+      :
+
+      {
+         cpl_object * <span class="keywordtype">object</span> = NULL;   / *  Wrong: Pointer must be declared at 
+                                                   the beginning of a function.
+                                                   This <span class="keywordtype">object</span> will not be 
+                                                   deallocated, <span class="keywordflow">if</span> the following
+                                                   check() fails. * /
+     
+         <span class="keywordtype">object</span> = cpl_object_new();
+
+         :
+         :
+              
+         check( ... );
+
+         :
+         :
+
+         cpl_object_delete(<span class="keywordtype">object</span>);    / *  Wrong: The pointer must be set to 
+                                                   NULL after deallocation, or
+                                                   the following assure() might
+                                                   cause the already 
+                                                   deallocated <span class="keywordtype">object</span>
+                                                   to be deallocated again.  * /
+         :
+         :
+     
+         assure( ... );
+
+         return 7;                     / *  Wrong: Only one exit point per 
+                                            function. * /
+
+      }
+      
+      :
+      :
+
+    cleanup:
+      cpl_image_delete(image);
+      cpl_image_delete(another_image);
+
+      return 7;
+   }
+</pre></div><p>This is easily fixed:</p>
+<div class="fragment"><pre class="fragment">   <span class="keywordtype">int</span> function_name(...)
+   {
+      cpl_image  * image         = NULL;  / *  All pointers are declared at 
+                                               the beginning  * /
+      cpl_image  * another_image = NULL;  / *  of the function an initialized 
+                                               to NULL.     * /
+      cpl_object * <span class="keywordtype">object</span>        = NULL;
+
+      :
+      :
+
+      {
+
+         <span class="keywordtype">object</span> = cpl_object_new();
+
+         :
+         :
+              
+         check( ... );
+
+         :
+         :
+
+         sinfo_free_object(&<span class="keywordtype">object</span>);            / *  The <span class="keywordtype">object</span> is deallocated 
+                                                     and the pointer <span class="keyword">set</span> to 
+                                                     NULL.  * /
+
+         :
+         :
+     
+         assure( ... );
+
+      }
+      
+      :
+      :
+
+    cleanup:
+      sinfo_free_image (&image);                / *  All objects are 
+                                                     deallocated here.  * /
+      sinfo_free_image (&another_image);
+      sinfo_free_object(&<span class="keywordtype">object</span>);
+
+      <span class="keywordflow">return</span> 7;                           / *  This is the only exit point of 
+                                               the function. * /
+   }
+</pre></div><p>(Note that <code>sinfo_free_image()</code> et al. can be used instead of <code>cpl_image_delete()</code> et al. as a way to ensure that a pointer is always set to NULL after deallocation).</p>
+<dl class="user"><dt><b>Recovering from an error</b></dt><dd></dd></dl>
+<p>To recover from an error, call <code>sinfo_error_reset()</code>, not <code>cpl_error_reset()</code>. Example:</p>
+<div class="fragment"><pre class="fragment">   n = cpl_table_get_nrow(t);
+   <span class="keywordflow">if</span> (cpl_error_get_code() == CPL_ERROR_NULL_INPUT)  / *  This error code is 
+                                                           <span class="keyword">set</span> <span class="keywordflow">if</span> <span class="charliteral">'t'</span> is NULL.
+ /
+   {
+      / *  Recover from <span class="keyword">this</span> error  * /
+
+      sinfo_error_reset();
+      n = -3;
+   }
+   <span class="keywordflow">else</span>  / *  Also check <span class="keywordflow">for</span> unexpected errors  * /
+   {
+      assure( cpl_error_get_code() == CPL_ERROR_NONE, cpl_error_get_code(), 
+              <span class="stringliteral">"Error reading table size"</span>);
+   }
+</pre></div><p>However, error recovery is usually best avoided, and the functionality above is better written as:</p>
+<div class="fragment"><pre class="fragment">   <span class="keywordflow">if</span> (t != NULL)
+   {
+      check( n = cpl_table_get_nrow(t), <span class="stringliteral">"Error reading table size"</span>);
+   }
+   <span class="keywordflow">else</span>
+   {
+      n = -3;
+   }
+</pre></div> </div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__finddist__cfg.html b/html/group__sinfo__finddist__cfg.html
new file mode 100644
index 0000000..7238758
--- /dev/null
+++ b/html/group__sinfo__finddist__cfg.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: functions to determine slitlets distances</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>functions to determine slitlets distances</h1><table border="0" cellpadding="0" cellspacing="0">
+</table>
+<p>TBD </p>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__fit.html b/html/group__sinfo__fit.html
new file mode 100644
index 0000000..40cfa90
--- /dev/null
+++ b/html/group__sinfo__fit.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Fit functions</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Fit functions</h1><table border="0" cellpadding="0" cellspacing="0">
+</table>
+<p>TBD </p>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__flat__cfg.html b/html/group__sinfo__flat__cfg.html
new file mode 100644
index 0000000..d5850a4
--- /dev/null
+++ b/html/group__sinfo__flat__cfg.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Flat manipulation functions</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Flat manipulation functions</h1><table border="0" cellpadding="0" cellspacing="0">
+</table>
+<p>TBD </p>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__flat__ini__file.html b/html/group__sinfo__flat__ini__file.html
new file mode 100644
index 0000000..d5850a4
--- /dev/null
+++ b/html/group__sinfo__flat__ini__file.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Flat manipulation functions</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Flat manipulation functions</h1><table border="0" cellpadding="0" cellspacing="0">
+</table>
+<p>TBD </p>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__focus.html b/html/group__sinfo__focus.html
new file mode 100644
index 0000000..8957c58
--- /dev/null
+++ b/html/group__sinfo__focus.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Focus determination functions</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Focus determination functions</h1><table border="0" cellpadding="0" cellspacing="0">
+</table>
+<p>TBD </p>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__function__1d.html b/html/group__sinfo__function__1d.html
new file mode 100644
index 0000000..dda7f8d
--- /dev/null
+++ b/html/group__sinfo__function__1d.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: 1d functions</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>1d functions</h1><table border="0" cellpadding="0" cellspacing="0">
+</table>
+<p>TBD </p>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__globals.html b/html/group__sinfo__globals.html
new file mode 100644
index 0000000..d3166e6
--- /dev/null
+++ b/html/group__sinfo__globals.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: global functions</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>global functions</h1><table border="0" cellpadding="0" cellspacing="0">
+</table>
+<p>TBD </p>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__image__ops.html b/html/group__sinfo__image__ops.html
new file mode 100644
index 0000000..967de7e
--- /dev/null
+++ b/html/group__sinfo__image__ops.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Image operations</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Image operations</h1><table border="0" cellpadding="0" cellspacing="0">
+</table>
+<p>TBD </p>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__img__noise.html b/html/group__sinfo__img__noise.html
new file mode 100644
index 0000000..02f10b0
--- /dev/null
+++ b/html/group__sinfo__img__noise.html
@@ -0,0 +1,19 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Recipe to determine detector noise</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Recipe to determine detector noise</h1><table border="0" cellpadding="0" cellspacing="0">
+</table>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__lamp__cfg.html b/html/group__sinfo__lamp__cfg.html
new file mode 100644
index 0000000..0fcca12
--- /dev/null
+++ b/html/group__sinfo__lamp__cfg.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Flat frame manipulation functions</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Flat frame manipulation functions</h1><table border="0" cellpadding="0" cellspacing="0">
+</table>
+<p>TBD </p>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__lamp__spec__config.html b/html/group__sinfo__lamp__spec__config.html
new file mode 100644
index 0000000..bfb0ad5
--- /dev/null
+++ b/html/group__sinfo__lamp__spec__config.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Spectroscopic flats manipulation</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Spectroscopic flats manipulation</h1><table border="0" cellpadding="0" cellspacing="0">
+</table>
+<p>TBD </p>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__msg.html b/html/group__sinfo__msg.html
new file mode 100644
index 0000000..892ee97
--- /dev/null
+++ b/html/group__sinfo__msg.html
@@ -0,0 +1,551 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Messaging</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Messaging</h1><table border="0" cellpadding="0" cellspacing="0">
+<tr><td colspan="2"><h2>Defines</h2></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">#define </td><td class="memItemRight" valign="bottom"><a class="el" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789">sinfo_msg_error</a>(...)   cpl_msg_error(cpl_func, __VA_ARGS__)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Print an error message.  <a href="#ga207c781e45c0904f20faa13fdf08c789"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">#define </td><td class="memItemRight" valign="bottom"><a class="el" href="group__sinfo__msg.html#ga75cab6805099905b3b101f660a907f37">sinfo_msg_progress</a>(i, iter,...)   cpl_msg_progress(cpl_func, (i), (iter), __VA_ARGS__)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Print a progress message.  <a href="#ga75cab6805099905b3b101f660a907f37"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">#define </td><td class="memItemRight" valign="bottom"><a class="el" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6">sinfo_msg_warning</a>(...)   sinfo_msg_warning_macro(cpl_func, __VA_ARGS__)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Print an warning message.  <a href="#ga885dfc1c23dbdf3ea2051b42341a52a6"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">#define </td><td class="memItemRight" valign="bottom"><a class="el" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8">sinfo_msg_debug</a>(...)   cpl_msg_debug(cpl_func, __VA_ARGS__)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Print a debug message.  <a href="#ga5011f548e1cbc15d52154469a63343c8"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">#define </td><td class="memItemRight" valign="bottom"><a class="el" href="group__sinfo__msg.html#gaa6da02902135556d8517de4c05b7a1a6">sinfo_msg_low</a>(...)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Print a message on a lower message level.  <a href="#gaa6da02902135556d8517de4c05b7a1a6"></a><br/></td></tr>
+<tr><td colspan="2"><h2>Functions</h2></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="group__sinfo__msg.html#ga639b5d352f0518db6cc346c0737484cc">sinfo_msg_init</a> (int outlevel, const char *dom)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Initialize messaging.  <a href="#ga639b5d352f0518db6cc346c0737484cc"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="group__sinfo__msg.html#gad9c8f46542015d0c93094c337a557d5e">sinfo_msg_set_level</a> (int olevel)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Set output level.  <a href="#gad9c8f46542015d0c93094c337a557d5e"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">const char * </td><td class="memItemRight" valign="bottom"><a class="el" href="group__sinfo__msg.html#ga15d005a10b6dac6031d611eecdce129a">sinfo_msg_get_domain</a> (void)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Get current message domain.  <a href="#ga15d005a10b6dac6031d611eecdce129a"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="group__sinfo__msg.html#ga5671e5e7722c35d9d174772c80013ad5">sinfo_msg_set_domain</a> (const char *d)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Set message domain.  <a href="#ga5671e5e7722c35d9d174772c80013ad5"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="group__sinfo__msg.html#gacccff4e78e5f14f06b2c06686a0e19e1">sinfo_msg_macro</a> (const char *fct, const char *format,...)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Print a message on 'info' or 'debug' level.  <a href="#gacccff4e78e5f14f06b2c06686a0e19e1"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="group__sinfo__msg.html#ga905c39fd148a95c77ea1335aa9441b28">sinfo_msg_warning_macro</a> (const char *fct, const char *format,...)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Print a warning message.  <a href="#ga905c39fd148a95c77ea1335aa9441b28"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="group__sinfo__msg.html#ga819ca13f95340688515071106d88af30">sinfo_msg_get_warnings</a> (void)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Get number of warnings printed so far.  <a href="#ga819ca13f95340688515071106d88af30"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="group__sinfo__msg.html#gac95702d684d815593ec1516082c0071a">sinfo_msg_add_warnings</a> (int n)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Accumulate warnings.  <a href="#gac95702d684d815593ec1516082c0071a"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="group__sinfo__msg.html#gae0f3e727182610d92efdb755f1da6788">sinfo_msg_softer_macro</a> (const char *fct)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Decrease message level.  <a href="#gae0f3e727182610d92efdb755f1da6788"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="group__sinfo__msg.html#ga38ac31ae7cb0ce5c792486fd3c9478e6">sinfo_msg_louder_macro</a> (const char *fct)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Increase message level.  <a href="#ga38ac31ae7cb0ce5c792486fd3c9478e6"></a><br/></td></tr>
+</table>
+<hr/><a name="_details"></a><h2>Detailed Description</h2>
+<p>CPL's info message level is expanded to a set of relative message level. The functions sinfo_msg_louder() and sinfo_msg_softer() are used to turn up/down the message level (instead of setting the verbosity to an absolute level) These two functions should be used consistently, so that the level is always the same on function exit as on function entry.</p>
+<p>These functions never fail, but print warnings if called inconsistently. </p>
+<hr/><h2>Define Documentation</h2>
+<a class="anchor" id="ga5011f548e1cbc15d52154469a63343c8"></a><!-- doxytag: member="sinfo_msg.h::sinfo_msg_debug" ref="ga5011f548e1cbc15d52154469a63343c8" args="(...)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">#define sinfo_msg_debug</td>
+          <td>(</td>
+          <td class="paramtype"> <em>...</em> </td>
+          <td class="paramname"></td>
+          <td> ) </td>
+          <td>   cpl_msg_debug(cpl_func, __VA_ARGS__)</td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Print a debug message. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>...</em> </td><td>Message to print</td></tr>
+  </table>
+  </dd>
+</dl>
+<p>This function is used instead of <code>cpl_msg_debug()</code>, and saves the user from typing the calling function name. </p>
+
+<p>Definition at line <a class="el" href="sinfo__msg_8h_source.html#l00103">103</a> of file <a class="el" href="sinfo__msg_8h_source.html">sinfo_msg.h</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="ga207c781e45c0904f20faa13fdf08c789"></a><!-- doxytag: member="sinfo_msg.h::sinfo_msg_error" ref="ga207c781e45c0904f20faa13fdf08c789" args="(...)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">#define sinfo_msg_error</td>
+          <td>(</td>
+          <td class="paramtype"> <em>...</em> </td>
+          <td class="paramname"></td>
+          <td> ) </td>
+          <td>   cpl_msg_error(cpl_func, __VA_ARGS__)</td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Print an error message. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>...</em> </td><td>Message to print</td></tr>
+  </table>
+  </dd>
+</dl>
+<p>This function is used instead of <code>cpl_msg_error()</code>, and saves the user from typing the calling function name. </p>
+
+<p>Definition at line <a class="el" href="sinfo__msg_8h_source.html#l00069">69</a> of file <a class="el" href="sinfo__msg_8h_source.html">sinfo_msg.h</a>.</p>
+
+<p>Referenced by <a class="el" href="sinfo__boltzmann_8c_source.html#l00865">sinfo_new_fit_slits_boltz()</a>, <a class="el" href="sinfo__boltzmann_8c_source.html#l01620">sinfo_new_fit_slits_boltz_single_line()</a>, and <a class="el" href="sinfo__boltzmann_8c_source.html#l02164">sinfo_new_fit_slits_boltz_with_estimate()</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="gaa6da02902135556d8517de4c05b7a1a6"></a><!-- doxytag: member="sinfo_msg.h::sinfo_msg_low" ref="gaa6da02902135556d8517de4c05b7a1a6" args="(...)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">#define sinfo_msg_low</td>
+          <td>(</td>
+          <td class="paramtype"> <em>...</em> </td>
+          <td class="paramname"></td>
+          <td> ) </td>
+          <td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+<b>Value:</b><div class="fragment"><pre class="fragment"><span class="keywordflow">do</span> {                     \
+                           sinfo_msg_softer();       \
+                           sinfo_msg(__VA_ARGS__);   \
+                           sinfo_msg_louder();       \
+                           } <span class="keywordflow">while</span> (FALSE)
+</pre></div>
+<p>Print a message on a lower message level. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>...</em> </td><td>Message to print </td></tr>
+  </table>
+  </dd>
+</dl>
+
+<p>Definition at line <a class="el" href="sinfo__msg_8h_source.html#l00111">111</a> of file <a class="el" href="sinfo__msg_8h_source.html">sinfo_msg.h</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="ga75cab6805099905b3b101f660a907f37"></a><!-- doxytag: member="sinfo_msg.h::sinfo_msg_progress" ref="ga75cab6805099905b3b101f660a907f37" args="(i, iter,...)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">#define sinfo_msg_progress</td>
+          <td>(</td>
+          <td class="paramtype">i, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">iter, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype"> <em>...</em> </td>
+          <td class="paramname"></td>
+          <td> ) </td>
+          <td>   cpl_msg_progress(cpl_func, (i), (iter), __VA_ARGS__)</td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Print a progress message. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>i</em> </td><td>See <code>cpl_msg_progress()</code> </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>iter</em> </td><td>See <code>cpl_msg_progress()</code> </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>...</em> </td><td>Message to print</td></tr>
+  </table>
+  </dd>
+</dl>
+<p>This function is used instead of <code>cpl_msg_progress()</code>, and saves the user from typing the calling function name. </p>
+
+<p>Definition at line <a class="el" href="sinfo__msg_8h_source.html#l00082">82</a> of file <a class="el" href="sinfo__msg_8h_source.html">sinfo_msg.h</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="ga885dfc1c23dbdf3ea2051b42341a52a6"></a><!-- doxytag: member="sinfo_msg.h::sinfo_msg_warning" ref="ga885dfc1c23dbdf3ea2051b42341a52a6" args="(...)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">#define sinfo_msg_warning</td>
+          <td>(</td>
+          <td class="paramtype"> <em>...</em> </td>
+          <td class="paramname"></td>
+          <td> ) </td>
+          <td>   sinfo_msg_warning_macro(cpl_func, __VA_ARGS__)</td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Print an warning message. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>...</em> </td><td>Message to print</td></tr>
+  </table>
+  </dd>
+</dl>
+<p>This function is used instead of <code>cpl_msg_warning()</code>, and saves the user from typing the calling function name. </p>
+
+<p>Definition at line <a class="el" href="sinfo__msg_8h_source.html#l00093">93</a> of file <a class="el" href="sinfo__msg_8h_source.html">sinfo_msg.h</a>.</p>
+
+<p>Referenced by <a class="el" href="sinfo__msg_8c_source.html#l00176">sinfo_msg_louder_macro()</a>, <a class="el" href="sinfo__boltzmann_8c_source.html#l00865">sinfo_new_fit_slits_boltz()</a>, <a class="el" href="sinfo__boltzmann_8c_source.html#l01620">sinfo_new_fit_slits_boltz_single_line()</a>, and <a class="el" href="sinfo__boltzmann_8c_source.html#l02164">sinfo_new_fit_slits_boltz_with_estimate()</a>.</p>
+
+</div>
+</div>
+<hr/><h2>Function Documentation</h2>
+<a class="anchor" id="gac95702d684d815593ec1516082c0071a"></a><!-- doxytag: member="sinfo_msg.h::sinfo_msg_add_warnings" ref="gac95702d684d815593ec1516082c0071a" args="(int n)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">void sinfo_msg_add_warnings </td>
+          <td>(</td>
+          <td class="paramtype">int </td>
+          <td class="paramname"> <em>n</em></td>
+          <td> ) </td>
+          <td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Accumulate warnings. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>n</em> </td><td>Number of warnings to add</td></tr>
+  </table>
+  </dd>
+</dl>
+<p>The (internal) number of warnings (returned by <code><a class="el" href="group__sinfo__msg.html#ga819ca13f95340688515071106d88af30" title="Get number of warnings printed so far.">sinfo_msg_get_warnings()</a></code>) is increased by <em>n</em>, but without actually printing any warnings. </p>
+
+<p>Definition at line <a class="el" href="sinfo__msg_8c_source.html#l00266">266</a> of file <a class="el" href="sinfo__msg_8c_source.html">sinfo_msg.c</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="ga15d005a10b6dac6031d611eecdce129a"></a><!-- doxytag: member="sinfo_msg.h::sinfo_msg_get_domain" ref="ga15d005a10b6dac6031d611eecdce129a" args="(void)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">const char* sinfo_msg_get_domain </td>
+          <td>(</td>
+          <td class="paramtype">void </td>
+          <td class="paramname"></td>
+          <td> ) </td>
+          <td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Get current message domain. </p>
+<dl class="return"><dt><b>Returns:</b></dt><dd>The current message domain set by <code><a class="el" href="group__sinfo__msg.html#ga639b5d352f0518db6cc346c0737484cc" title="Initialize messaging.">sinfo_msg_init()</a></code> or <code><a class="el" href="group__sinfo__msg.html#ga5671e5e7722c35d9d174772c80013ad5" title="Set message domain.">sinfo_msg_set_domain()</a></code>. </dd></dl>
+
+<p>Definition at line <a class="el" href="sinfo__msg_8c_source.html#l00309">309</a> of file <a class="el" href="sinfo__msg_8c_source.html">sinfo_msg.c</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="ga819ca13f95340688515071106d88af30"></a><!-- doxytag: member="sinfo_msg.h::sinfo_msg_get_warnings" ref="ga819ca13f95340688515071106d88af30" args="(void)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">int sinfo_msg_get_warnings </td>
+          <td>(</td>
+          <td class="paramtype">void </td>
+          <td class="paramname"></td>
+          <td> ) </td>
+          <td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Get number of warnings printed so far. </p>
+<dl class="return"><dt><b>Returns:</b></dt><dd>Number of warnings since initialization of messaging </dd></dl>
+
+<p>Definition at line <a class="el" href="sinfo__msg_8c_source.html#l00251">251</a> of file <a class="el" href="sinfo__msg_8c_source.html">sinfo_msg.c</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="ga639b5d352f0518db6cc346c0737484cc"></a><!-- doxytag: member="sinfo_msg.h::sinfo_msg_init" ref="ga639b5d352f0518db6cc346c0737484cc" args="(int outlevel, const char *dom)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">void sinfo_msg_init </td>
+          <td>(</td>
+          <td class="paramtype">int </td>
+          <td class="paramname"> <em>olevel</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>dom</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Initialize messaging. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>olevel</em> </td><td>The output level </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>dom</em> </td><td>The message domain</td></tr>
+  </table>
+  </dd>
+</dl>
+<p>Only messages at levels 0 (most important) to <em>outlevel</em> are printed as 'info'. Messages at levels above <em>outlevel</em> are printed as 'debug'.</p>
+<p>Therefore, set <em>outlevel</em> = 0 to print fewest messages. Increase <em>outlevel</em> to increase verbosity.</p>
+<p>To print all messages as 'info' set <em>outlevel</em> to the special value -1 (which has the effect of infinity). </p>
+
+<p>Definition at line <a class="el" href="sinfo__msg_8c_source.html#l00101">101</a> of file <a class="el" href="sinfo__msg_8c_source.html">sinfo_msg.c</a>.</p>
+
+<p>References <a class="el" href="sinfo__msg_8c_source.html#l00320">sinfo_msg_set_domain()</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="ga38ac31ae7cb0ce5c792486fd3c9478e6"></a><!-- doxytag: member="sinfo_msg.h::sinfo_msg_louder_macro" ref="ga38ac31ae7cb0ce5c792486fd3c9478e6" args="(const char *fct)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">void sinfo_msg_louder_macro </td>
+          <td>(</td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>fctid</em></td>
+          <td> ) </td>
+          <td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Increase message level. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>fctid</em> </td><td>Identity of calling function</td></tr>
+  </table>
+  </dd>
+</dl>
+<p>Don't call this function directly, use <code>sinfo_msg_louder()</code>. </p>
+
+<p>Definition at line <a class="el" href="sinfo__msg_8c_source.html#l00176">176</a> of file <a class="el" href="sinfo__msg_8c_source.html">sinfo_msg.c</a>.</p>
+
+<p>References <a class="el" href="sinfo__msg_8h_source.html#l00093">sinfo_msg_warning</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="gacccff4e78e5f14f06b2c06686a0e19e1"></a><!-- doxytag: member="sinfo_msg.h::sinfo_msg_macro" ref="gacccff4e78e5f14f06b2c06686a0e19e1" args="(const char *fct, const char *format,...)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">void sinfo_msg_macro </td>
+          <td>(</td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>fct</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>format</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype"> </td>
+          <td class="paramname"> <em>...</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Print a message on 'info' or 'debug' level. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>fct</em> </td><td>Identity of calling function </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>format</em> </td><td>A printf()-like format string</td></tr>
+  </table>
+  </dd>
+</dl>
+<p>Don't call this function directly, use <code>sinfo_msg()</code>.</p>
+<p>If the current level (which might be equal to the current depth of the function call-tree) is less than the output level, the message printed on the 'info' level, otherwise it is printed on the 'debug' level. </p>
+
+<p>Definition at line <a class="el" href="sinfo__msg_8c_source.html#l00219">219</a> of file <a class="el" href="sinfo__msg_8c_source.html">sinfo_msg.c</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="ga5671e5e7722c35d9d174772c80013ad5"></a><!-- doxytag: member="sinfo_msg.h::sinfo_msg_set_domain" ref="ga5671e5e7722c35d9d174772c80013ad5" args="(const char *d)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">void sinfo_msg_set_domain </td>
+          <td>(</td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>d</em></td>
+          <td> ) </td>
+          <td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Set message domain. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>d</em> </td><td>The new message domain </td></tr>
+  </table>
+  </dd>
+</dl>
+
+<p>Definition at line <a class="el" href="sinfo__msg_8c_source.html#l00320">320</a> of file <a class="el" href="sinfo__msg_8c_source.html">sinfo_msg.c</a>.</p>
+
+<p>Referenced by <a class="el" href="sinfo__msg_8c_source.html#l00101">sinfo_msg_init()</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="gad9c8f46542015d0c93094c337a557d5e"></a><!-- doxytag: member="sinfo_msg.h::sinfo_msg_set_level" ref="gad9c8f46542015d0c93094c337a557d5e" args="(int olevel)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">void sinfo_msg_set_level </td>
+          <td>(</td>
+          <td class="paramtype">int </td>
+          <td class="paramname"> <em>olevel</em></td>
+          <td> ) </td>
+          <td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Set output level. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>olevel</em> </td><td>The output level</td></tr>
+  </table>
+  </dd>
+</dl>
+<p>See <code><a class="el" href="group__sinfo__msg.html#ga639b5d352f0518db6cc346c0737484cc" title="Initialize messaging.">sinfo_msg_init()</a></code> . </p>
+
+<p>Definition at line <a class="el" href="sinfo__msg_8c_source.html#l00139">139</a> of file <a class="el" href="sinfo__msg_8c_source.html">sinfo_msg.c</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="gae0f3e727182610d92efdb755f1da6788"></a><!-- doxytag: member="sinfo_msg.h::sinfo_msg_softer_macro" ref="gae0f3e727182610d92efdb755f1da6788" args="(const char *fct)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">void sinfo_msg_softer_macro </td>
+          <td>(</td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>fctid</em></td>
+          <td> ) </td>
+          <td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Decrease message level. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>fctid</em> </td><td>Identity of calling function</td></tr>
+  </table>
+  </dd>
+</dl>
+<p>Don't call this function directly, use <code>sinfo_msg_softer()</code>. </p>
+
+<p>Definition at line <a class="el" href="sinfo__msg_8c_source.html#l00153">153</a> of file <a class="el" href="sinfo__msg_8c_source.html">sinfo_msg.c</a>.</p>
+
+</div>
+</div>
+<a class="anchor" id="ga905c39fd148a95c77ea1335aa9441b28"></a><!-- doxytag: member="sinfo_msg.h::sinfo_msg_warning_macro" ref="ga905c39fd148a95c77ea1335aa9441b28" args="(const char *fct, const char *format,...)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">void sinfo_msg_warning_macro </td>
+          <td>(</td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>fct</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype">const char * </td>
+          <td class="paramname"> <em>format</em>, </td>
+        </tr>
+        <tr>
+          <td class="paramkey"></td>
+          <td></td>
+          <td class="paramtype"> </td>
+          <td class="paramname"> <em>...</em></td><td> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td>)</td>
+          <td></td><td></td><td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Print a warning message. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>fct</em> </td><td>Identity of calling function </td></tr>
+    <tr><td valign="top"></td><td valign="top"><em>format</em> </td><td>A printf()-like format string</td></tr>
+  </table>
+  </dd>
+</dl>
+<p>Don't call this function directly, use <code><a class="el" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning()</a></code>.</p>
+<p>This function is used instead of <code>cpl_msg_warning()</code>, and saves the user from typing the calling function name.</p>
+<p>Additionally, record is kept on the total number of warnings printed (see <code><a class="el" href="group__sinfo__msg.html#ga819ca13f95340688515071106d88af30" title="Get number of warnings printed so far.">sinfo_msg_get_warnings()</a></code>). </p>
+
+<p>Definition at line <a class="el" href="sinfo__msg_8c_source.html#l00287">287</a> of file <a class="el" href="sinfo__msg_8c_source.html">sinfo_msg.c</a>.</p>
+
+</div>
+</div>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__new__bezier.html b/html/group__sinfo__new__bezier.html
new file mode 100644
index 0000000..cb4fdb9
--- /dev/null
+++ b/html/group__sinfo__new__bezier.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Bezier Functions</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Bezier Functions</h1><table border="0" cellpadding="0" cellspacing="0">
+</table>
+<p>TBD </p>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__new__cube__ops.html b/html/group__sinfo__new__cube__ops.html
new file mode 100644
index 0000000..22d2397
--- /dev/null
+++ b/html/group__sinfo__new__cube__ops.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Cube operations</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Cube operations</h1><table border="0" cellpadding="0" cellspacing="0">
+</table>
+<p>TBD </p>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__new__resampling.html b/html/group__sinfo__new__resampling.html
new file mode 100644
index 0000000..750426d
--- /dev/null
+++ b/html/group__sinfo__new__resampling.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Image resampling</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Image resampling</h1><table border="0" cellpadding="0" cellspacing="0">
+</table>
+<p>TBD </p>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__new__slit__pos.html b/html/group__sinfo__new__slit__pos.html
new file mode 100644
index 0000000..6214985
--- /dev/null
+++ b/html/group__sinfo__new__slit__pos.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Slitlets position determination</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Slitlets position determination</h1><table border="0" cellpadding="0" cellspacing="0">
+</table>
+<p>TBD </p>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__pfits.html b/html/group__sinfo__pfits.html
new file mode 100644
index 0000000..9673799
--- /dev/null
+++ b/html/group__sinfo__pfits.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: In/Out on propertylist cards</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>In/Out on propertylist cards</h1><table border="0" cellpadding="0" cellspacing="0">
+</table>
+<p>TBD </p>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__pro__save.html b/html/group__sinfo__pro__save.html
new file mode 100644
index 0000000..3a9af5a
--- /dev/null
+++ b/html/group__sinfo__pro__save.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Functions to save a product</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Functions to save a product</h1><table border="0" cellpadding="0" cellspacing="0">
+</table>
+<p>TBD </p>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__produc__config.html b/html/group__sinfo__produc__config.html
new file mode 100644
index 0000000..5c3b0f5
--- /dev/null
+++ b/html/group__sinfo__produc__config.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: .c Pipeline products configurations</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>.c Pipeline products configurations</h1><table border="0" cellpadding="0" cellspacing="0">
+</table>
+<p>TBD </p>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__qr__companion.html b/html/group__sinfo__qr__companion.html
new file mode 100644
index 0000000..5cc7de2
--- /dev/null
+++ b/html/group__sinfo__qr__companion.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: functions for polynomial solution</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>functions for polynomial solution</h1><table border="0" cellpadding="0" cellspacing="0">
+</table>
+<p>TBD </p>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__rec__detlin.html b/html/group__sinfo__rec__detlin.html
new file mode 100644
index 0000000..9bcbea3
--- /dev/null
+++ b/html/group__sinfo__rec__detlin.html
@@ -0,0 +1,53 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Recipe to determine detector linearity</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Recipe to determine detector linearity</h1><table border="0" cellpadding="0" cellspacing="0">
+<tr><td colspan="2"><h2>Functions</h2></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="group__sinfo__rec__detlin.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693">cpl_plugin_get_info</a> (cpl_pluginlist *list)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Build the list of available plugins, for this module.  <a href="#ga31d1fccd4cd15b1c1f3c5edc8cb18693"></a><br/></td></tr>
+</table>
+<hr/><h2>Function Documentation</h2>
+<a class="anchor" id="ga31d1fccd4cd15b1c1f3c5edc8cb18693"></a><!-- doxytag: member="sinfo_rec_detlin.c::cpl_plugin_get_info" ref="ga31d1fccd4cd15b1c1f3c5edc8cb18693" args="(cpl_pluginlist *list)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">int cpl_plugin_get_info </td>
+          <td>(</td>
+          <td class="paramtype">cpl_pluginlist * </td>
+          <td class="paramname"> <em>list</em></td>
+          <td> ) </td>
+          <td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Build the list of available plugins, for this module. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>list</em> </td><td>the plugin list </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>0 if everything is ok, -1 otherwise</dd></dl>
+<p>Create the recipe instance and make it available to the application using the interface. This function is exported. </p>
+
+<p>Definition at line <a class="el" href="sinfo__rec__detlin_8c_source.html#l00121">121</a> of file <a class="el" href="sinfo__rec__detlin_8c_source.html">sinfo_rec_detlin.c</a>.</p>
+
+</div>
+</div>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__rec__distortion.html b/html/group__sinfo__rec__distortion.html
new file mode 100644
index 0000000..93d9c3f
--- /dev/null
+++ b/html/group__sinfo__rec__distortion.html
@@ -0,0 +1,55 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Recipe to compute optical distortions</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Recipe to compute optical distortions</h1><table border="0" cellpadding="0" cellspacing="0">
+<tr><td colspan="2"><h2>Functions</h2></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="group__sinfo__rec__distortion.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693">cpl_plugin_get_info</a> (cpl_pluginlist *list)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Build the list of available plugins, for this module.  <a href="#ga31d1fccd4cd15b1c1f3c5edc8cb18693"></a><br/></td></tr>
+</table>
+<hr/><a name="_details"></a><h2>Detailed Description</h2>
+<p>TBD </p>
+<hr/><h2>Function Documentation</h2>
+<a class="anchor" id="ga31d1fccd4cd15b1c1f3c5edc8cb18693"></a><!-- doxytag: member="sinfo_rec_distortion.c::cpl_plugin_get_info" ref="ga31d1fccd4cd15b1c1f3c5edc8cb18693" args="(cpl_pluginlist *list)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">int cpl_plugin_get_info </td>
+          <td>(</td>
+          <td class="paramtype">cpl_pluginlist * </td>
+          <td class="paramname"> <em>list</em></td>
+          <td> ) </td>
+          <td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Build the list of available plugins, for this module. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>list</em> </td><td>the plugin list </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>0 if everything is ok, -1 otherwise</dd></dl>
+<p>Create the recipe instance and make it available to the application using the interface. This function is exported. </p>
+
+<p>Definition at line <a class="el" href="sinfo__rec__distortion_8c_source.html#l00149">149</a> of file <a class="el" href="sinfo__rec__distortion_8c_source.html">sinfo_rec_distortion.c</a>.</p>
+
+</div>
+</div>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__rec__jitter.html b/html/group__sinfo__rec__jitter.html
new file mode 100644
index 0000000..5467e85
--- /dev/null
+++ b/html/group__sinfo__rec__jitter.html
@@ -0,0 +1,57 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Recipe to reduce science, PSF, telluric standards</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Recipe to reduce science, PSF, telluric standards</h1><table border="0" cellpadding="0" cellspacing="0">
+<tr><td colspan="2"><h2>Functions</h2></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="group__sinfo__rec__jitter.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693">cpl_plugin_get_info</a> (cpl_pluginlist *list)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Build the list of available plugins, for this module.  <a href="#ga31d1fccd4cd15b1c1f3c5edc8cb18693"></a><br/></td></tr>
+</table>
+<hr/><a name="_details"></a><h2>Detailed Description</h2>
+<p>TBD</p>
+<p>configuration</p>
+<p>TBD </p>
+<hr/><h2>Function Documentation</h2>
+<a class="anchor" id="ga31d1fccd4cd15b1c1f3c5edc8cb18693"></a><!-- doxytag: member="sinfo_rec_jitter.c::cpl_plugin_get_info" ref="ga31d1fccd4cd15b1c1f3c5edc8cb18693" args="(cpl_pluginlist *list)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">int cpl_plugin_get_info </td>
+          <td>(</td>
+          <td class="paramtype">cpl_pluginlist * </td>
+          <td class="paramname"> <em>list</em></td>
+          <td> ) </td>
+          <td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Build the list of available plugins, for this module. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>list</em> </td><td>the plugin list </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>0 if everything is ok, -1 otherwise</dd></dl>
+<p>Create the recipe instance and make it available to the application using the interface. This function is exported. </p>
+
+<p>Definition at line <a class="el" href="sinfo__rec__jitter_8c_source.html#l00152">152</a> of file <a class="el" href="sinfo__rec__jitter_8c_source.html">sinfo_rec_jitter.c</a>.</p>
+
+</div>
+</div>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__rec__lingain.html b/html/group__sinfo__rec__lingain.html
new file mode 100644
index 0000000..18b7cc0
--- /dev/null
+++ b/html/group__sinfo__rec__lingain.html
@@ -0,0 +1,19 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Recipe to monitor detector's linearity and gain</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Recipe to monitor detector's linearity and gain</h1><table border="0" cellpadding="0" cellspacing="0">
+</table>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__rec__mdark.html b/html/group__sinfo__rec__mdark.html
new file mode 100644
index 0000000..1998d5a
--- /dev/null
+++ b/html/group__sinfo__rec__mdark.html
@@ -0,0 +1,55 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Recipe to compute master dark</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Recipe to compute master dark</h1><table border="0" cellpadding="0" cellspacing="0">
+<tr><td colspan="2"><h2>Functions</h2></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="group__sinfo__rec__mdark.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693">cpl_plugin_get_info</a> (cpl_pluginlist *list)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Build the list of available plugins, for this module.  <a href="#ga31d1fccd4cd15b1c1f3c5edc8cb18693"></a><br/></td></tr>
+</table>
+<hr/><a name="_details"></a><h2>Detailed Description</h2>
+<p>TBD </p>
+<hr/><h2>Function Documentation</h2>
+<a class="anchor" id="ga31d1fccd4cd15b1c1f3c5edc8cb18693"></a><!-- doxytag: member="sinfo_rec_mdark.c::cpl_plugin_get_info" ref="ga31d1fccd4cd15b1c1f3c5edc8cb18693" args="(cpl_pluginlist *list)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">int cpl_plugin_get_info </td>
+          <td>(</td>
+          <td class="paramtype">cpl_pluginlist * </td>
+          <td class="paramname"> <em>list</em></td>
+          <td> ) </td>
+          <td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Build the list of available plugins, for this module. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>list</em> </td><td>the plugin list </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>0 if everything is ok, -1 otherwise</dd></dl>
+<p>Create the recipe instance and make it available to the application using the interface. This function is exported. </p>
+
+<p>Definition at line <a class="el" href="sinfo__rec__mdark_8c_source.html#l00113">113</a> of file <a class="el" href="sinfo__rec__mdark_8c_source.html">sinfo_rec_mdark.c</a>.</p>
+
+</div>
+</div>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__rec__mflat.html b/html/group__sinfo__rec__mflat.html
new file mode 100644
index 0000000..087edaa
--- /dev/null
+++ b/html/group__sinfo__rec__mflat.html
@@ -0,0 +1,55 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Recipe to compute master flat</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Recipe to compute master flat</h1><table border="0" cellpadding="0" cellspacing="0">
+<tr><td colspan="2"><h2>Functions</h2></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="group__sinfo__rec__mflat.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693">cpl_plugin_get_info</a> (cpl_pluginlist *list)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Build the list of available plugins, for this module.  <a href="#ga31d1fccd4cd15b1c1f3c5edc8cb18693"></a><br/></td></tr>
+</table>
+<hr/><a name="_details"></a><h2>Detailed Description</h2>
+<p>TBD </p>
+<hr/><h2>Function Documentation</h2>
+<a class="anchor" id="ga31d1fccd4cd15b1c1f3c5edc8cb18693"></a><!-- doxytag: member="sinfo_rec_mflat.c::cpl_plugin_get_info" ref="ga31d1fccd4cd15b1c1f3c5edc8cb18693" args="(cpl_pluginlist *list)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">int cpl_plugin_get_info </td>
+          <td>(</td>
+          <td class="paramtype">cpl_pluginlist * </td>
+          <td class="paramname"> <em>list</em></td>
+          <td> ) </td>
+          <td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Build the list of available plugins, for this module. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>list</em> </td><td>the plugin list </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>0 if everything is ok, -1 otherwise</dd></dl>
+<p>Create the recipe instance and make it available to the application using the interface. This function is exported. </p>
+
+<p>Definition at line <a class="el" href="sinfo__rec__mflat_8c_source.html#l00113">113</a> of file <a class="el" href="sinfo__rec__mflat_8c_source.html">sinfo_rec_mflat.c</a>.</p>
+
+</div>
+</div>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__rec__objnod.html b/html/group__sinfo__rec__objnod.html
new file mode 100644
index 0000000..414dd7a
--- /dev/null
+++ b/html/group__sinfo__rec__objnod.html
@@ -0,0 +1,53 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Recipe to reduce science data</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Recipe to reduce science data</h1><table border="0" cellpadding="0" cellspacing="0">
+<tr><td colspan="2"><h2>Functions</h2></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="group__sinfo__rec__objnod.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693">cpl_plugin_get_info</a> (cpl_pluginlist *list)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Build the list of available plugins, for this module.  <a href="#ga31d1fccd4cd15b1c1f3c5edc8cb18693"></a><br/></td></tr>
+</table>
+<hr/><h2>Function Documentation</h2>
+<a class="anchor" id="ga31d1fccd4cd15b1c1f3c5edc8cb18693"></a><!-- doxytag: member="sinfo_rec_objnod.c::cpl_plugin_get_info" ref="ga31d1fccd4cd15b1c1f3c5edc8cb18693" args="(cpl_pluginlist *list)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">int cpl_plugin_get_info </td>
+          <td>(</td>
+          <td class="paramtype">cpl_pluginlist * </td>
+          <td class="paramname"> <em>list</em></td>
+          <td> ) </td>
+          <td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Build the list of available plugins, for this module. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>list</em> </td><td>the plugin list </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>0 if everything is ok, -1 otherwise</dd></dl>
+<p>Create the recipe instance and make it available to the application using the interface. This function is exported. </p>
+
+<p>Definition at line <a class="el" href="sinfo__rec__objnod_8c_source.html#l00147">147</a> of file <a class="el" href="sinfo__rec__objnod_8c_source.html">sinfo_rec_objnod.c</a>.</p>
+
+</div>
+</div>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__rec__psf.html b/html/group__sinfo__rec__psf.html
new file mode 100644
index 0000000..6fde724
--- /dev/null
+++ b/html/group__sinfo__rec__psf.html
@@ -0,0 +1,53 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Recipe to reduce PSF standard star data</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Recipe to reduce PSF standard star data</h1><table border="0" cellpadding="0" cellspacing="0">
+<tr><td colspan="2"><h2>Functions</h2></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="group__sinfo__rec__psf.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693">cpl_plugin_get_info</a> (cpl_pluginlist *list)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Build the list of available plugins, for this module.  <a href="#ga31d1fccd4cd15b1c1f3c5edc8cb18693"></a><br/></td></tr>
+</table>
+<hr/><h2>Function Documentation</h2>
+<a class="anchor" id="ga31d1fccd4cd15b1c1f3c5edc8cb18693"></a><!-- doxytag: member="sinfo_rec_psf.c::cpl_plugin_get_info" ref="ga31d1fccd4cd15b1c1f3c5edc8cb18693" args="(cpl_pluginlist *list)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">int cpl_plugin_get_info </td>
+          <td>(</td>
+          <td class="paramtype">cpl_pluginlist * </td>
+          <td class="paramname"> <em>list</em></td>
+          <td> ) </td>
+          <td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Build the list of available plugins, for this module. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>list</em> </td><td>the plugin list </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>0 if everything is ok, -1 otherwise</dd></dl>
+<p>Create the recipe instance and make it available to the application using the interface. This function is exported. </p>
+
+<p>Definition at line <a class="el" href="sinfo__rec__psf_8c_source.html#l00146">146</a> of file <a class="el" href="sinfo__rec__psf_8c_source.html">sinfo_rec_psf.c</a>.</p>
+
+</div>
+</div>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__rec__pupil.html b/html/group__sinfo__rec__pupil.html
new file mode 100644
index 0000000..efedbbe
--- /dev/null
+++ b/html/group__sinfo__rec__pupil.html
@@ -0,0 +1,53 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Recipe to reduce pupil data</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Recipe to reduce pupil data</h1><table border="0" cellpadding="0" cellspacing="0">
+<tr><td colspan="2"><h2>Functions</h2></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="group__sinfo__rec__pupil.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693">cpl_plugin_get_info</a> (cpl_pluginlist *list)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Build the list of available plugins, for this module.  <a href="#ga31d1fccd4cd15b1c1f3c5edc8cb18693"></a><br/></td></tr>
+</table>
+<hr/><h2>Function Documentation</h2>
+<a class="anchor" id="ga31d1fccd4cd15b1c1f3c5edc8cb18693"></a><!-- doxytag: member="sinfo_rec_pupil.c::cpl_plugin_get_info" ref="ga31d1fccd4cd15b1c1f3c5edc8cb18693" args="(cpl_pluginlist *list)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">int cpl_plugin_get_info </td>
+          <td>(</td>
+          <td class="paramtype">cpl_pluginlist * </td>
+          <td class="paramname"> <em>list</em></td>
+          <td> ) </td>
+          <td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Build the list of available plugins, for this module. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>list</em> </td><td>the plugin list </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>0 if everything is ok, -1 otherwise</dd></dl>
+<p>Create the recipe instance and make it available to the application using the interface. This function is exported. </p>
+
+<p>Definition at line <a class="el" href="sinfo__rec__pupil_8c_source.html#l00137">137</a> of file <a class="el" href="sinfo__rec__pupil_8c_source.html">sinfo_rec_pupil.c</a>.</p>
+
+</div>
+</div>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__rec__stdstar.html b/html/group__sinfo__rec__stdstar.html
new file mode 100644
index 0000000..a63e714
--- /dev/null
+++ b/html/group__sinfo__rec__stdstar.html
@@ -0,0 +1,53 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Recipe to reduce telluric standard star data</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Recipe to reduce telluric standard star data</h1><table border="0" cellpadding="0" cellspacing="0">
+<tr><td colspan="2"><h2>Functions</h2></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="group__sinfo__rec__stdstar.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693">cpl_plugin_get_info</a> (cpl_pluginlist *list)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Build the list of available plugins, for this module.  <a href="#ga31d1fccd4cd15b1c1f3c5edc8cb18693"></a><br/></td></tr>
+</table>
+<hr/><h2>Function Documentation</h2>
+<a class="anchor" id="ga31d1fccd4cd15b1c1f3c5edc8cb18693"></a><!-- doxytag: member="sinfo_rec_stdstar.c::cpl_plugin_get_info" ref="ga31d1fccd4cd15b1c1f3c5edc8cb18693" args="(cpl_pluginlist *list)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">int cpl_plugin_get_info </td>
+          <td>(</td>
+          <td class="paramtype">cpl_pluginlist * </td>
+          <td class="paramname"> <em>list</em></td>
+          <td> ) </td>
+          <td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Build the list of available plugins, for this module. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>list</em> </td><td>the plugin list </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>0 if everything is ok, -1 otherwise</dd></dl>
+<p>Create the recipe instance and make it available to the application using the interface. This function is exported. </p>
+
+<p>Definition at line <a class="el" href="sinfo__rec__stdstar_8c_source.html#l00149">149</a> of file <a class="el" href="sinfo__rec__stdstar_8c_source.html">sinfo_rec_stdstar.c</a>.</p>
+
+</div>
+</div>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__rec__utils.html b/html/group__sinfo__rec__utils.html
new file mode 100644
index 0000000..dde84b5
--- /dev/null
+++ b/html/group__sinfo__rec__utils.html
@@ -0,0 +1,19 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Recipe utilities</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Recipe utilities</h1><table border="0" cellpadding="0" cellspacing="0">
+</table>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__rec__wavecal.html b/html/group__sinfo__rec__wavecal.html
new file mode 100644
index 0000000..7e58644
--- /dev/null
+++ b/html/group__sinfo__rec__wavecal.html
@@ -0,0 +1,55 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Recipe to reduce arc lamp data</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Recipe to reduce arc lamp data</h1><table border="0" cellpadding="0" cellspacing="0">
+<tr><td colspan="2"><h2>Functions</h2></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="group__sinfo__rec__wavecal.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693">cpl_plugin_get_info</a> (cpl_pluginlist *list)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Build the list of available plugins, for this module.  <a href="#ga31d1fccd4cd15b1c1f3c5edc8cb18693"></a><br/></td></tr>
+</table>
+<hr/><a name="_details"></a><h2>Detailed Description</h2>
+<p>TBD </p>
+<hr/><h2>Function Documentation</h2>
+<a class="anchor" id="ga31d1fccd4cd15b1c1f3c5edc8cb18693"></a><!-- doxytag: member="sinfo_rec_wavecal.c::cpl_plugin_get_info" ref="ga31d1fccd4cd15b1c1f3c5edc8cb18693" args="(cpl_pluginlist *list)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">int cpl_plugin_get_info </td>
+          <td>(</td>
+          <td class="paramtype">cpl_pluginlist * </td>
+          <td class="paramname"> <em>list</em></td>
+          <td> ) </td>
+          <td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Build the list of available plugins, for this module. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>list</em> </td><td>the plugin list </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>0 if everything is ok, -1 otherwise</dd></dl>
+<p>Create the recipe instance and make it available to the application using the interface. This function is exported. </p>
+
+<p>Definition at line <a class="el" href="sinfo__rec__wavecal_8c_source.html#l00146">146</a> of file <a class="el" href="sinfo__rec__wavecal_8c_source.html">sinfo_rec_wavecal.c</a>.</p>
+
+</div>
+</div>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__recipes.html b/html/group__sinfo__recipes.html
new file mode 100644
index 0000000..0ae7627
--- /dev/null
+++ b/html/group__sinfo__recipes.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Recipe utilities</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Recipe utilities</h1><table border="0" cellpadding="0" cellspacing="0">
+</table>
+<p>TBD </p>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__remove__crh__single.html b/html/group__sinfo__remove__crh__single.html
new file mode 100644
index 0000000..ad01cb7
--- /dev/null
+++ b/html/group__sinfo__remove__crh__single.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Remove Cosmic Rays single (sinfo_remove_crh_single)</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Remove Cosmic Rays single (sinfo_remove_crh_single)</h1><table border="0" cellpadding="0" cellspacing="0">
+</table>
+<p>Suppress Cosmic Rays by analysing on files </p>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__shift__images.html b/html/group__sinfo__shift__images.html
new file mode 100644
index 0000000..742a564
--- /dev/null
+++ b/html/group__sinfo__shift__images.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Functions to shift images</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Functions to shift images</h1><table border="0" cellpadding="0" cellspacing="0">
+</table>
+<p>TBD </p>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__skycor__config.html b/html/group__sinfo__skycor__config.html
new file mode 100644
index 0000000..0103c80
--- /dev/null
+++ b/html/group__sinfo__skycor__config.html
@@ -0,0 +1,21 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Sky residuals corrections configuration</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Sky residuals corrections configuration</h1><table border="0" cellpadding="0" cellspacing="0">
+</table>
+<p>parameters</p>
+<p>TBD </p>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__spectrum__ops.html b/html/group__sinfo__spectrum__ops.html
new file mode 100644
index 0000000..80cf663
--- /dev/null
+++ b/html/group__sinfo__spectrum__ops.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Operations on spectra</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Operations on spectra</h1><table border="0" cellpadding="0" cellspacing="0">
+</table>
+<p>TBD </p>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__step__distortion.html b/html/group__sinfo__step__distortion.html
new file mode 100644
index 0000000..c1f78d4
--- /dev/null
+++ b/html/group__sinfo__step__distortion.html
@@ -0,0 +1,19 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Recipe to compute optical distortions</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Recipe to compute optical distortions</h1><table border="0" cellpadding="0" cellspacing="0">
+</table>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__step__jitter.html b/html/group__sinfo__step__jitter.html
new file mode 100644
index 0000000..4e8acfa
--- /dev/null
+++ b/html/group__sinfo__step__jitter.html
@@ -0,0 +1,19 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Recipe to reduce science, PSF or telluric standard data</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Recipe to reduce science, PSF or telluric standard data</h1><table border="0" cellpadding="0" cellspacing="0">
+</table>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__step__objnod.html b/html/group__sinfo__step__objnod.html
new file mode 100644
index 0000000..d2b9a08
--- /dev/null
+++ b/html/group__sinfo__step__objnod.html
@@ -0,0 +1,19 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Recipe to reduce science data</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Recipe to reduce science data</h1><table border="0" cellpadding="0" cellspacing="0">
+</table>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__step__psf.html b/html/group__sinfo__step__psf.html
new file mode 100644
index 0000000..a46b158
--- /dev/null
+++ b/html/group__sinfo__step__psf.html
@@ -0,0 +1,19 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Recipe to reduce PSF data</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Recipe to reduce PSF data</h1><table border="0" cellpadding="0" cellspacing="0">
+</table>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__step__stdstar.html b/html/group__sinfo__step__stdstar.html
new file mode 100644
index 0000000..a19f7c1
--- /dev/null
+++ b/html/group__sinfo__step__stdstar.html
@@ -0,0 +1,19 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Recipe to reduce telluric standard data</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Recipe to reduce telluric standard data</h1><table border="0" cellpadding="0" cellspacing="0">
+</table>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__tilt__cfg.html b/html/group__sinfo__tilt__cfg.html
new file mode 100644
index 0000000..e801edd
--- /dev/null
+++ b/html/group__sinfo__tilt__cfg.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: tilt computation</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>tilt computation</h1><table border="0" cellpadding="0" cellspacing="0">
+</table>
+<p>TBD </p>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__time.html b/html/group__sinfo__time.html
new file mode 100644
index 0000000..66e4aee
--- /dev/null
+++ b/html/group__sinfo__time.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Get date/time, possibly in ISO8601 format</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Get date/time, possibly in ISO8601 format</h1><table border="0" cellpadding="0" cellspacing="0">
+</table>
+<p>This module contains various utilities to get the current date/time, and possibly format it according to the ISO 8601 format. </p>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__tpl__dfs.html b/html/group__sinfo__tpl__dfs.html
new file mode 100644
index 0000000..a002b70
--- /dev/null
+++ b/html/group__sinfo__tpl__dfs.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: DFS related functions</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>DFS related functions</h1><table border="0" cellpadding="0" cellspacing="0">
+</table>
+<p>TBD </p>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__tpl__utils.html b/html/group__sinfo__tpl__utils.html
new file mode 100644
index 0000000..94aaa6f
--- /dev/null
+++ b/html/group__sinfo__tpl__utils.html
@@ -0,0 +1,19 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Miscellaneous Utilities</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Miscellaneous Utilities</h1><table border="0" cellpadding="0" cellspacing="0">
+</table>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__utilities.html b/html/group__sinfo__utilities.html
new file mode 100644
index 0000000..b00efca
--- /dev/null
+++ b/html/group__sinfo__utilities.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: utilities</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>utilities</h1><table border="0" cellpadding="0" cellspacing="0">
+</table>
+<p>TBD </p>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__utils.html b/html/group__sinfo__utils.html
new file mode 100644
index 0000000..2048a32
--- /dev/null
+++ b/html/group__sinfo__utils.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Utility functions</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Utility functions</h1><table border="0" cellpadding="0" cellspacing="0">
+</table>
+<p>This module contains various functions that are shared between multiple recipes </p>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__utils__wrappers.html b/html/group__sinfo__utils__wrappers.html
new file mode 100644
index 0000000..3a7116f
--- /dev/null
+++ b/html/group__sinfo__utils__wrappers.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Utility functions (wrappers)</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Utility functions (wrappers)</h1><table border="0" cellpadding="0" cellspacing="0">
+</table>
+<p>This module contains wrapper functions, convenience functions and simple extensions of CPL functions. </p>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__utl__bp__mask__add.html b/html/group__sinfo__utl__bp__mask__add.html
new file mode 100644
index 0000000..d9c2e1f
--- /dev/null
+++ b/html/group__sinfo__utl__bp__mask__add.html
@@ -0,0 +1,19 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Recipe to coadd bad pixel masks</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Recipe to coadd bad pixel masks</h1><table border="0" cellpadding="0" cellspacing="0">
+</table>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__utl__cube2ima.html b/html/group__sinfo__utl__cube2ima.html
new file mode 100644
index 0000000..adc9848
--- /dev/null
+++ b/html/group__sinfo__utl__cube2ima.html
@@ -0,0 +1,55 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Recipe to collapse a cube in an image</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Recipe to collapse a cube in an image</h1><table border="0" cellpadding="0" cellspacing="0">
+<tr><td colspan="2"><h2>Functions</h2></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="group__sinfo__utl__cube2ima.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693">cpl_plugin_get_info</a> (cpl_pluginlist *list)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Build the list of available plugins, for this module.  <a href="#ga31d1fccd4cd15b1c1f3c5edc8cb18693"></a><br/></td></tr>
+</table>
+<hr/><a name="_details"></a><h2>Detailed Description</h2>
+<p>TBD </p>
+<hr/><h2>Function Documentation</h2>
+<a class="anchor" id="ga31d1fccd4cd15b1c1f3c5edc8cb18693"></a><!-- doxytag: member="recipes/sinfo_utl_cube2ima.c::cpl_plugin_get_info" ref="ga31d1fccd4cd15b1c1f3c5edc8cb18693" args="(cpl_pluginlist *list)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">int cpl_plugin_get_info </td>
+          <td>(</td>
+          <td class="paramtype">cpl_pluginlist * </td>
+          <td class="paramname"> <em>list</em></td>
+          <td> ) </td>
+          <td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Build the list of available plugins, for this module. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>list</em> </td><td>the plugin list </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>0 if everything is ok</dd></dl>
+<p>This function is exported. </p>
+
+<p>Definition at line <a class="el" href="recipes_2sinfo__utl__cube2ima_8c_source.html#l00088">88</a> of file <a class="el" href="recipes_2sinfo__utl__cube2ima_8c_source.html">recipes/sinfo_utl_cube2ima.c</a>.</p>
+
+</div>
+</div>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__utl__cube2spectrum.html b/html/group__sinfo__utl__cube2spectrum.html
new file mode 100644
index 0000000..e9a0bd5
--- /dev/null
+++ b/html/group__sinfo__utl__cube2spectrum.html
@@ -0,0 +1,55 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Recipe to collapse a cube in a spectrum</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Recipe to collapse a cube in a spectrum</h1><table border="0" cellpadding="0" cellspacing="0">
+<tr><td colspan="2"><h2>Functions</h2></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="group__sinfo__utl__cube2spectrum.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693">cpl_plugin_get_info</a> (cpl_pluginlist *list)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Build the list of available plugins, for this module.  <a href="#ga31d1fccd4cd15b1c1f3c5edc8cb18693"></a><br/></td></tr>
+</table>
+<hr/><a name="_details"></a><h2>Detailed Description</h2>
+<p>TBD </p>
+<hr/><h2>Function Documentation</h2>
+<a class="anchor" id="ga31d1fccd4cd15b1c1f3c5edc8cb18693"></a><!-- doxytag: member="recipes/sinfo_utl_cube2spectrum.c::cpl_plugin_get_info" ref="ga31d1fccd4cd15b1c1f3c5edc8cb18693" args="(cpl_pluginlist *list)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">int cpl_plugin_get_info </td>
+          <td>(</td>
+          <td class="paramtype">cpl_pluginlist * </td>
+          <td class="paramname"> <em>list</em></td>
+          <td> ) </td>
+          <td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Build the list of available plugins, for this module. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>list</em> </td><td>the plugin list </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>0 if everything is ok</dd></dl>
+<p>This function is exported. </p>
+
+<p>Definition at line <a class="el" href="recipes_2sinfo__utl__cube2spectrum_8c_source.html#l00090">90</a> of file <a class="el" href="recipes_2sinfo__utl__cube2spectrum_8c_source.html">recipes/sinfo_utl_cube2spectrum.c</a>.</p>
+
+</div>
+</div>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__utl__cube__arith.html b/html/group__sinfo__utl__cube__arith.html
new file mode 100644
index 0000000..74c174a
--- /dev/null
+++ b/html/group__sinfo__utl__cube__arith.html
@@ -0,0 +1,55 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Recipe for cube arithmetics</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Recipe for cube arithmetics</h1><table border="0" cellpadding="0" cellspacing="0">
+<tr><td colspan="2"><h2>Functions</h2></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="group__sinfo__utl__cube__arith.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693">cpl_plugin_get_info</a> (cpl_pluginlist *list)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Build the list of available plugins, for this module.  <a href="#ga31d1fccd4cd15b1c1f3c5edc8cb18693"></a><br/></td></tr>
+</table>
+<hr/><a name="_details"></a><h2>Detailed Description</h2>
+<p>TBD </p>
+<hr/><h2>Function Documentation</h2>
+<a class="anchor" id="ga31d1fccd4cd15b1c1f3c5edc8cb18693"></a><!-- doxytag: member="recipes/sinfo_utl_cube_arith.c::cpl_plugin_get_info" ref="ga31d1fccd4cd15b1c1f3c5edc8cb18693" args="(cpl_pluginlist *list)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">int cpl_plugin_get_info </td>
+          <td>(</td>
+          <td class="paramtype">cpl_pluginlist * </td>
+          <td class="paramname"> <em>list</em></td>
+          <td> ) </td>
+          <td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Build the list of available plugins, for this module. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>list</em> </td><td>the plugin list </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>0 if everything is ok</dd></dl>
+<p>This function is exported. </p>
+
+<p>Definition at line <a class="el" href="recipes_2sinfo__utl__cube__arith_8c_source.html#l00101">101</a> of file <a class="el" href="recipes_2sinfo__utl__cube__arith_8c_source.html">recipes/sinfo_utl_cube_arith.c</a>.</p>
+
+</div>
+</div>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__utl__cube__combine.html b/html/group__sinfo__utl__cube__combine.html
new file mode 100644
index 0000000..f41f954
--- /dev/null
+++ b/html/group__sinfo__utl__cube__combine.html
@@ -0,0 +1,55 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Recipe to coadd cubes</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Recipe to coadd cubes</h1><table border="0" cellpadding="0" cellspacing="0">
+<tr><td colspan="2"><h2>Functions</h2></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="group__sinfo__utl__cube__combine.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693">cpl_plugin_get_info</a> (cpl_pluginlist *list)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Build the list of available plugins, for this module.  <a href="#ga31d1fccd4cd15b1c1f3c5edc8cb18693"></a><br/></td></tr>
+</table>
+<hr/><a name="_details"></a><h2>Detailed Description</h2>
+<p>TBD </p>
+<hr/><h2>Function Documentation</h2>
+<a class="anchor" id="ga31d1fccd4cd15b1c1f3c5edc8cb18693"></a><!-- doxytag: member="recipes/sinfo_utl_cube_combine.c::cpl_plugin_get_info" ref="ga31d1fccd4cd15b1c1f3c5edc8cb18693" args="(cpl_pluginlist *list)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">int cpl_plugin_get_info </td>
+          <td>(</td>
+          <td class="paramtype">cpl_pluginlist * </td>
+          <td class="paramname"> <em>list</em></td>
+          <td> ) </td>
+          <td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Build the list of available plugins, for this module. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>list</em> </td><td>the plugin list </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>0 if everything is ok</dd></dl>
+<p>This function is exported. </p>
+
+<p>Definition at line <a class="el" href="recipes_2sinfo__utl__cube__combine_8c_source.html#l00094">94</a> of file <a class="el" href="recipes_2sinfo__utl__cube__combine_8c_source.html">recipes/sinfo_utl_cube_combine.c</a>.</p>
+
+</div>
+</div>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__utl__cube__create.html b/html/group__sinfo__utl__cube__create.html
new file mode 100644
index 0000000..7fde6e7
--- /dev/null
+++ b/html/group__sinfo__utl__cube__create.html
@@ -0,0 +1,53 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Recipe to coadd cubes</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Recipe to coadd cubes</h1><table border="0" cellpadding="0" cellspacing="0">
+<tr><td colspan="2"><h2>Functions</h2></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="group__sinfo__utl__cube__create.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693">cpl_plugin_get_info</a> (cpl_pluginlist *list)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Build the list of available plugins, for this module.  <a href="#ga31d1fccd4cd15b1c1f3c5edc8cb18693"></a><br/></td></tr>
+</table>
+<hr/><h2>Function Documentation</h2>
+<a class="anchor" id="ga31d1fccd4cd15b1c1f3c5edc8cb18693"></a><!-- doxytag: member="sinfo_utl_cube_create.c::cpl_plugin_get_info" ref="ga31d1fccd4cd15b1c1f3c5edc8cb18693" args="(cpl_pluginlist *list)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">int cpl_plugin_get_info </td>
+          <td>(</td>
+          <td class="paramtype">cpl_pluginlist * </td>
+          <td class="paramname"> <em>list</em></td>
+          <td> ) </td>
+          <td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Build the list of available plugins, for this module. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>list</em> </td><td>the plugin list </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>0 if everything is ok</dd></dl>
+<p>This function is exported. </p>
+
+<p>Definition at line <a class="el" href="sinfo__utl__cube__create_8c_source.html#l00104">104</a> of file <a class="el" href="sinfo__utl__cube__create_8c_source.html">sinfo_utl_cube_create.c</a>.</p>
+
+</div>
+</div>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__utl__cube__test.html b/html/group__sinfo__utl__cube__test.html
new file mode 100644
index 0000000..12832aa
--- /dev/null
+++ b/html/group__sinfo__utl__cube__test.html
@@ -0,0 +1,53 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Recipe to test cube operations</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Recipe to test cube operations</h1><table border="0" cellpadding="0" cellspacing="0">
+<tr><td colspan="2"><h2>Functions</h2></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="group__sinfo__utl__cube__test.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693">cpl_plugin_get_info</a> (cpl_pluginlist *list)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Build the list of available plugins, for this module.  <a href="#ga31d1fccd4cd15b1c1f3c5edc8cb18693"></a><br/></td></tr>
+</table>
+<hr/><h2>Function Documentation</h2>
+<a class="anchor" id="ga31d1fccd4cd15b1c1f3c5edc8cb18693"></a><!-- doxytag: member="sinfo_utl_cube_test.c::cpl_plugin_get_info" ref="ga31d1fccd4cd15b1c1f3c5edc8cb18693" args="(cpl_pluginlist *list)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">int cpl_plugin_get_info </td>
+          <td>(</td>
+          <td class="paramtype">cpl_pluginlist * </td>
+          <td class="paramname"> <em>list</em></td>
+          <td> ) </td>
+          <td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Build the list of available plugins, for this module. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>list</em> </td><td>the plugin list </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>0 if everything is ok</dd></dl>
+<p>This function is exported. </p>
+
+<p>Definition at line <a class="el" href="sinfo__utl__cube__test_8c_source.html#l00088">88</a> of file <a class="el" href="sinfo__utl__cube__test_8c_source.html">sinfo_utl_cube_test.c</a>.</p>
+
+</div>
+</div>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__utl__eff.html b/html/group__sinfo__utl__eff.html
new file mode 100644
index 0000000..bbff618
--- /dev/null
+++ b/html/group__sinfo__utl__eff.html
@@ -0,0 +1,53 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Recipe to do operations on an image</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Recipe to do operations on an image</h1><table border="0" cellpadding="0" cellspacing="0">
+<tr><td colspan="2"><h2>Functions</h2></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="group__sinfo__utl__eff.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693">cpl_plugin_get_info</a> (cpl_pluginlist *list)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Build the list of available plugins, for this module.  <a href="#ga31d1fccd4cd15b1c1f3c5edc8cb18693"></a><br/></td></tr>
+</table>
+<hr/><h2>Function Documentation</h2>
+<a class="anchor" id="ga31d1fccd4cd15b1c1f3c5edc8cb18693"></a><!-- doxytag: member="sinfo_utl_eff.c::cpl_plugin_get_info" ref="ga31d1fccd4cd15b1c1f3c5edc8cb18693" args="(cpl_pluginlist *list)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">int cpl_plugin_get_info </td>
+          <td>(</td>
+          <td class="paramtype">cpl_pluginlist * </td>
+          <td class="paramname"> <em>list</em></td>
+          <td> ) </td>
+          <td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Build the list of available plugins, for this module. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>list</em> </td><td>the plugin list </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>0 if everything is ok</dd></dl>
+<p>This function is exported. </p>
+
+<p>Definition at line <a class="el" href="sinfo__utl__eff_8c_source.html#l00116">116</a> of file <a class="el" href="sinfo__utl__eff_8c_source.html">sinfo_utl_eff.c</a>.</p>
+
+</div>
+</div>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__utl__illumcorr.html b/html/group__sinfo__utl__illumcorr.html
new file mode 100644
index 0000000..9bc35d3
--- /dev/null
+++ b/html/group__sinfo__utl__illumcorr.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Recipe to correct for slitlet illumination</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Recipe to correct for slitlet illumination</h1><table border="0" cellpadding="0" cellspacing="0">
+</table>
+<p>disomogeneities </p>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__utl__ima__arith.html b/html/group__sinfo__utl__ima__arith.html
new file mode 100644
index 0000000..0ea2f91
--- /dev/null
+++ b/html/group__sinfo__utl__ima__arith.html
@@ -0,0 +1,53 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Recipe to do operations on an image</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Recipe to do operations on an image</h1><table border="0" cellpadding="0" cellspacing="0">
+<tr><td colspan="2"><h2>Functions</h2></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="group__sinfo__utl__ima__arith.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693">cpl_plugin_get_info</a> (cpl_pluginlist *list)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Build the list of available plugins, for this module.  <a href="#ga31d1fccd4cd15b1c1f3c5edc8cb18693"></a><br/></td></tr>
+</table>
+<hr/><h2>Function Documentation</h2>
+<a class="anchor" id="ga31d1fccd4cd15b1c1f3c5edc8cb18693"></a><!-- doxytag: member="sinfo_utl_ima_arith.c::cpl_plugin_get_info" ref="ga31d1fccd4cd15b1c1f3c5edc8cb18693" args="(cpl_pluginlist *list)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">int cpl_plugin_get_info </td>
+          <td>(</td>
+          <td class="paramtype">cpl_pluginlist * </td>
+          <td class="paramname"> <em>list</em></td>
+          <td> ) </td>
+          <td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Build the list of available plugins, for this module. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>list</em> </td><td>the plugin list </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>0 if everything is ok</dd></dl>
+<p>This function is exported. </p>
+
+<p>Definition at line <a class="el" href="sinfo__utl__ima__arith_8c_source.html#l00097">97</a> of file <a class="el" href="sinfo__utl__ima__arith_8c_source.html">sinfo_utl_ima_arith.c</a>.</p>
+
+</div>
+</div>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__utl__ima__cube__ks__test.html b/html/group__sinfo__utl__ima__cube__ks__test.html
new file mode 100644
index 0000000..cdcbb6d
--- /dev/null
+++ b/html/group__sinfo__utl__ima__cube__ks__test.html
@@ -0,0 +1,53 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Recipe to do operations on an image</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Recipe to do operations on an image</h1><table border="0" cellpadding="0" cellspacing="0">
+<tr><td colspan="2"><h2>Functions</h2></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="group__sinfo__utl__ima__cube__ks__test.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693">cpl_plugin_get_info</a> (cpl_pluginlist *list)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Build the list of available plugins, for this module.  <a href="#ga31d1fccd4cd15b1c1f3c5edc8cb18693"></a><br/></td></tr>
+</table>
+<hr/><h2>Function Documentation</h2>
+<a class="anchor" id="ga31d1fccd4cd15b1c1f3c5edc8cb18693"></a><!-- doxytag: member="sinfo_utl_ima_cube_ks_test.c::cpl_plugin_get_info" ref="ga31d1fccd4cd15b1c1f3c5edc8cb18693" args="(cpl_pluginlist *list)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">int cpl_plugin_get_info </td>
+          <td>(</td>
+          <td class="paramtype">cpl_pluginlist * </td>
+          <td class="paramname"> <em>list</em></td>
+          <td> ) </td>
+          <td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Build the list of available plugins, for this module. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>list</em> </td><td>the plugin list </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>0 if everything is ok</dd></dl>
+<p>This function is exported. </p>
+
+<p>Definition at line <a class="el" href="sinfo__utl__ima__cube__ks__test_8c_source.html#l00170">170</a> of file <a class="el" href="sinfo__utl__ima__cube__ks__test_8c_source.html">sinfo_utl_ima_cube_ks_test.c</a>.</p>
+
+</div>
+</div>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__utl__ima__gauss.html b/html/group__sinfo__utl__ima__gauss.html
new file mode 100644
index 0000000..c83a148
--- /dev/null
+++ b/html/group__sinfo__utl__ima__gauss.html
@@ -0,0 +1,53 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Recipe to do operations on an image</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Recipe to do operations on an image</h1><table border="0" cellpadding="0" cellspacing="0">
+<tr><td colspan="2"><h2>Functions</h2></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="group__sinfo__utl__ima__gauss.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693">cpl_plugin_get_info</a> (cpl_pluginlist *list)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Build the list of available plugins, for this module.  <a href="#ga31d1fccd4cd15b1c1f3c5edc8cb18693"></a><br/></td></tr>
+</table>
+<hr/><h2>Function Documentation</h2>
+<a class="anchor" id="ga31d1fccd4cd15b1c1f3c5edc8cb18693"></a><!-- doxytag: member="sinfo_utl_ima_gauss.c::cpl_plugin_get_info" ref="ga31d1fccd4cd15b1c1f3c5edc8cb18693" args="(cpl_pluginlist *list)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">int cpl_plugin_get_info </td>
+          <td>(</td>
+          <td class="paramtype">cpl_pluginlist * </td>
+          <td class="paramname"> <em>list</em></td>
+          <td> ) </td>
+          <td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Build the list of available plugins, for this module. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>list</em> </td><td>the plugin list </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>0 if everything is ok</dd></dl>
+<p>This function is exported. </p>
+
+<p>Definition at line <a class="el" href="sinfo__utl__ima__gauss_8c_source.html#l00103">103</a> of file <a class="el" href="sinfo__utl__ima__gauss_8c_source.html">sinfo_utl_ima_gauss.c</a>.</p>
+
+</div>
+</div>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__utl__ima__line__corr.html b/html/group__sinfo__utl__ima__line__corr.html
new file mode 100644
index 0000000..69722cc
--- /dev/null
+++ b/html/group__sinfo__utl__ima__line__corr.html
@@ -0,0 +1,53 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Recipe to do operations on an image</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Recipe to do operations on an image</h1><table border="0" cellpadding="0" cellspacing="0">
+<tr><td colspan="2"><h2>Functions</h2></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="group__sinfo__utl__ima__line__corr.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693">cpl_plugin_get_info</a> (cpl_pluginlist *list)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Build the list of available plugins, for this module.  <a href="#ga31d1fccd4cd15b1c1f3c5edc8cb18693"></a><br/></td></tr>
+</table>
+<hr/><h2>Function Documentation</h2>
+<a class="anchor" id="ga31d1fccd4cd15b1c1f3c5edc8cb18693"></a><!-- doxytag: member="sinfo_utl_ima_line_corr.c::cpl_plugin_get_info" ref="ga31d1fccd4cd15b1c1f3c5edc8cb18693" args="(cpl_pluginlist *list)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">int cpl_plugin_get_info </td>
+          <td>(</td>
+          <td class="paramtype">cpl_pluginlist * </td>
+          <td class="paramname"> <em>list</em></td>
+          <td> ) </td>
+          <td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Build the list of available plugins, for this module. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>list</em> </td><td>the plugin list </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>0 if everything is ok</dd></dl>
+<p>This function is exported. </p>
+
+<p>Definition at line <a class="el" href="sinfo__utl__ima__line__corr_8c_source.html#l00096">96</a> of file <a class="el" href="sinfo__utl__ima__line__corr_8c_source.html">sinfo_utl_ima_line_corr.c</a>.</p>
+
+</div>
+</div>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__utl__remove__crh__single.html b/html/group__sinfo__utl__remove__crh__single.html
new file mode 100644
index 0000000..9a80232
--- /dev/null
+++ b/html/group__sinfo__utl__remove__crh__single.html
@@ -0,0 +1,53 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Recipe to remove CRHs from an image</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Recipe to remove CRHs from an image</h1><table border="0" cellpadding="0" cellspacing="0">
+<tr><td colspan="2"><h2>Functions</h2></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="group__sinfo__utl__remove__crh__single.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693">cpl_plugin_get_info</a> (cpl_pluginlist *list)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Build the list of available plugins, for this module.  <a href="#ga31d1fccd4cd15b1c1f3c5edc8cb18693"></a><br/></td></tr>
+</table>
+<hr/><h2>Function Documentation</h2>
+<a class="anchor" id="ga31d1fccd4cd15b1c1f3c5edc8cb18693"></a><!-- doxytag: member="sinfo_utl_remove_crh_single.c::cpl_plugin_get_info" ref="ga31d1fccd4cd15b1c1f3c5edc8cb18693" args="(cpl_pluginlist *list)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">int cpl_plugin_get_info </td>
+          <td>(</td>
+          <td class="paramtype">cpl_pluginlist * </td>
+          <td class="paramname"> <em>list</em></td>
+          <td> ) </td>
+          <td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Build the list of available plugins, for this module. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>list</em> </td><td>the plugin list </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>0 if everything is ok</dd></dl>
+<p>This function is exported. </p>
+
+<p>Definition at line <a class="el" href="sinfo__utl__remove__crh__single_8c_source.html#l00097">97</a> of file <a class="el" href="sinfo__utl__remove__crh__single_8c_source.html">sinfo_utl_remove_crh_single.c</a>.</p>
+
+</div>
+</div>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__utl__skycor.html b/html/group__sinfo__utl__skycor.html
new file mode 100644
index 0000000..b7b9214
--- /dev/null
+++ b/html/group__sinfo__utl__skycor.html
@@ -0,0 +1,53 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Recipe to correct sky residuals on science cubes</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Recipe to correct sky residuals on science cubes</h1><table border="0" cellpadding="0" cellspacing="0">
+<tr><td colspan="2"><h2>Functions</h2></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="group__sinfo__utl__skycor.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693">cpl_plugin_get_info</a> (cpl_pluginlist *list)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Build the list of available plugins, for this module.  <a href="#ga31d1fccd4cd15b1c1f3c5edc8cb18693"></a><br/></td></tr>
+</table>
+<hr/><h2>Function Documentation</h2>
+<a class="anchor" id="ga31d1fccd4cd15b1c1f3c5edc8cb18693"></a><!-- doxytag: member="sinfo_utl_skycor.c::cpl_plugin_get_info" ref="ga31d1fccd4cd15b1c1f3c5edc8cb18693" args="(cpl_pluginlist *list)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">int cpl_plugin_get_info </td>
+          <td>(</td>
+          <td class="paramtype">cpl_pluginlist * </td>
+          <td class="paramname"> <em>list</em></td>
+          <td> ) </td>
+          <td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Build the list of available plugins, for this module. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>list</em> </td><td>the plugin list </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>0 if everything is ok</dd></dl>
+<p>This function is exported. </p>
+
+<p>Definition at line <a class="el" href="sinfo__utl__skycor_8c_source.html#l00091">91</a> of file <a class="el" href="sinfo__utl__skycor_8c_source.html">sinfo_utl_skycor.c</a>.</p>
+
+</div>
+</div>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__utl__skymap.html b/html/group__sinfo__utl__skymap.html
new file mode 100644
index 0000000..2df0e53
--- /dev/null
+++ b/html/group__sinfo__utl__skymap.html
@@ -0,0 +1,53 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Recipe to generate a sky map for SINFONI SRTD</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Recipe to generate a sky map for SINFONI SRTD</h1><table border="0" cellpadding="0" cellspacing="0">
+<tr><td colspan="2"><h2>Functions</h2></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="group__sinfo__utl__skymap.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693">cpl_plugin_get_info</a> (cpl_pluginlist *list)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Build the list of available plugins, for this module.  <a href="#ga31d1fccd4cd15b1c1f3c5edc8cb18693"></a><br/></td></tr>
+</table>
+<hr/><h2>Function Documentation</h2>
+<a class="anchor" id="ga31d1fccd4cd15b1c1f3c5edc8cb18693"></a><!-- doxytag: member="sinfo_utl_skymap.c::cpl_plugin_get_info" ref="ga31d1fccd4cd15b1c1f3c5edc8cb18693" args="(cpl_pluginlist *list)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">int cpl_plugin_get_info </td>
+          <td>(</td>
+          <td class="paramtype">cpl_pluginlist * </td>
+          <td class="paramname"> <em>list</em></td>
+          <td> ) </td>
+          <td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Build the list of available plugins, for this module. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>list</em> </td><td>the plugin list </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>0 if everything is ok</dd></dl>
+<p>This function is exported. </p>
+
+<p>Definition at line <a class="el" href="sinfo__utl__skymap_8c_source.html#l00092">92</a> of file <a class="el" href="sinfo__utl__skymap_8c_source.html">sinfo_utl_skymap.c</a>.</p>
+
+</div>
+</div>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__utl__spectrum__divide__by__blackbody.html b/html/group__sinfo__utl__spectrum__divide__by__blackbody.html
new file mode 100644
index 0000000..3095eeb
--- /dev/null
+++ b/html/group__sinfo__utl__spectrum__divide__by__blackbody.html
@@ -0,0 +1,55 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Recipe to correct a   spectrum from the blackbody thermal emission</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Recipe to correct a spectrum from the blackbody thermal emission</h1><table border="0" cellpadding="0" cellspacing="0">
+<tr><td colspan="2"><h2>Functions</h2></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="group__sinfo__utl__spectrum__divide__by__blackbody.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693">cpl_plugin_get_info</a> (cpl_pluginlist *list)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Build the list of available plugins, for this module.  <a href="#ga31d1fccd4cd15b1c1f3c5edc8cb18693"></a><br/></td></tr>
+</table>
+<hr/><a name="_details"></a><h2>Detailed Description</h2>
+<p>TBD </p>
+<hr/><h2>Function Documentation</h2>
+<a class="anchor" id="ga31d1fccd4cd15b1c1f3c5edc8cb18693"></a><!-- doxytag: member="recipes/sinfo_utl_spectrum_divide_by_blackbody.c::cpl_plugin_get_info" ref="ga31d1fccd4cd15b1c1f3c5edc8cb18693" args="(cpl_pluginlist *list)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">int cpl_plugin_get_info </td>
+          <td>(</td>
+          <td class="paramtype">cpl_pluginlist * </td>
+          <td class="paramname"> <em>list</em></td>
+          <td> ) </td>
+          <td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Build the list of available plugins, for this module. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>list</em> </td><td>the plugin list </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>0 if everything is ok</dd></dl>
+<p>This function is exported. </p>
+
+<p>Definition at line <a class="el" href="recipes_2sinfo__utl__spectrum__divide__by__blackbody_8c_source.html#l00097">97</a> of file <a class="el" href="recipes_2sinfo__utl__spectrum__divide__by__blackbody_8c_source.html">recipes/sinfo_utl_spectrum_divide_by_blackbody.c</a>.</p>
+
+</div>
+</div>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__utl__spectrum__wavelength__shift.html b/html/group__sinfo__utl__spectrum__wavelength__shift.html
new file mode 100644
index 0000000..71b9415
--- /dev/null
+++ b/html/group__sinfo__utl__spectrum__wavelength__shift.html
@@ -0,0 +1,55 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Recipe to shift a spectrum in  wavelength</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Recipe to shift a spectrum in wavelength</h1><table border="0" cellpadding="0" cellspacing="0">
+<tr><td colspan="2"><h2>Functions</h2></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="group__sinfo__utl__spectrum__wavelength__shift.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693">cpl_plugin_get_info</a> (cpl_pluginlist *list)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Build the list of available plugins, for this module.  <a href="#ga31d1fccd4cd15b1c1f3c5edc8cb18693"></a><br/></td></tr>
+</table>
+<hr/><a name="_details"></a><h2>Detailed Description</h2>
+<p>TBD </p>
+<hr/><h2>Function Documentation</h2>
+<a class="anchor" id="ga31d1fccd4cd15b1c1f3c5edc8cb18693"></a><!-- doxytag: member="recipes/sinfo_utl_spectrum_wavelength_shift.c::cpl_plugin_get_info" ref="ga31d1fccd4cd15b1c1f3c5edc8cb18693" args="(cpl_pluginlist *list)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">int cpl_plugin_get_info </td>
+          <td>(</td>
+          <td class="paramtype">cpl_pluginlist * </td>
+          <td class="paramname"> <em>list</em></td>
+          <td> ) </td>
+          <td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Build the list of available plugins, for this module. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>list</em> </td><td>the plugin list </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>0 if everything is ok</dd></dl>
+<p>This function is exported. </p>
+
+<p>Definition at line <a class="el" href="recipes_2sinfo__utl__spectrum__wavelength__shift_8c_source.html#l00097">97</a> of file <a class="el" href="recipes_2sinfo__utl__spectrum__wavelength__shift_8c_source.html">recipes/sinfo_utl_spectrum_wavelength_shift.c</a>.</p>
+
+</div>
+</div>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__utl__stdstars.html b/html/group__sinfo__utl__stdstars.html
new file mode 100644
index 0000000..b878ad2
--- /dev/null
+++ b/html/group__sinfo__utl__stdstars.html
@@ -0,0 +1,19 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Recipe to generate standard stars catalogs</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Recipe to generate standard stars catalogs</h1><table border="0" cellpadding="0" cellspacing="0">
+</table>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__utl__table__ex.html b/html/group__sinfo__utl__table__ex.html
new file mode 100644
index 0000000..15b6155
--- /dev/null
+++ b/html/group__sinfo__utl__table__ex.html
@@ -0,0 +1,53 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Recipe to do operations on an image</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Recipe to do operations on an image</h1><table border="0" cellpadding="0" cellspacing="0">
+<tr><td colspan="2"><h2>Functions</h2></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="group__sinfo__utl__table__ex.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693">cpl_plugin_get_info</a> (cpl_pluginlist *list)</td></tr>
+<tr><td class="mdescLeft"> </td><td class="mdescRight">Build the list of available plugins, for this module.  <a href="#ga31d1fccd4cd15b1c1f3c5edc8cb18693"></a><br/></td></tr>
+</table>
+<hr/><h2>Function Documentation</h2>
+<a class="anchor" id="ga31d1fccd4cd15b1c1f3c5edc8cb18693"></a><!-- doxytag: member="sinfo_utl_table_ex.c::cpl_plugin_get_info" ref="ga31d1fccd4cd15b1c1f3c5edc8cb18693" args="(cpl_pluginlist *list)" -->
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">int cpl_plugin_get_info </td>
+          <td>(</td>
+          <td class="paramtype">cpl_pluginlist * </td>
+          <td class="paramname"> <em>list</em></td>
+          <td> ) </td>
+          <td></td>
+        </tr>
+      </table>
+</div>
+<div class="memdoc">
+
+<p>Build the list of available plugins, for this module. </p>
+<dl><dt><b>Parameters:</b></dt><dd>
+  <table border="0" cellspacing="2" cellpadding="0">
+    <tr><td valign="top"></td><td valign="top"><em>list</em> </td><td>the plugin list </td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>0 if everything is ok</dd></dl>
+<p>This function is exported. </p>
+
+<p>Definition at line <a class="el" href="sinfo__utl__table__ex_8c_source.html#l00101">101</a> of file <a class="el" href="sinfo__utl__table__ex_8c_source.html">sinfo_utl_table_ex.c</a>.</p>
+
+</div>
+</div>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__sinfo__utl__table__test.html b/html/group__sinfo__utl__table__test.html
new file mode 100644
index 0000000..029a842
--- /dev/null
+++ b/html/group__sinfo__utl__table__test.html
@@ -0,0 +1,19 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Utility to test column table shift</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Utility to test column table shift</h1><table border="0" cellpadding="0" cellspacing="0">
+</table>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/group__spiffi__general__config.html b/html/group__spiffi__general__config.html
new file mode 100644
index 0000000..881fc5f
--- /dev/null
+++ b/html/group__spiffi__general__config.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: General configuration parameters</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>General configuration parameters</h1><table border="0" cellpadding="0" cellspacing="0">
+</table>
+<p>TBD </p>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/index.html b/html/index.html
new file mode 100644
index 0000000..c12a6d3
--- /dev/null
+++ b/html/index.html
@@ -0,0 +1,23 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Main Page</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>SINFONI Pipeline Reference Manual Documentation</h1><h3>2.3.2 </h3><ul>      <li><a href="index.html"><span>Main Page</span></a></li>
+      <li><a href="modules.html"><span>Modules</span></a></li>
+      <li><a href="files.html"><span>Files</span></a></li>
+<ul>      <li><a href="files.html"><span>File List</span></a></li>
+</ul>
+</ul>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/irplib__calib_8c_source.html b/html/irplib__calib_8c_source.html
new file mode 100644
index 0000000..5263455
--- /dev/null
+++ b/html/irplib__calib_8c_source.html
@@ -0,0 +1,591 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: irplib_calib.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>irplib_calib.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: irplib_calib.c,v 1.17 2009/02/17 08:05:25 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the irplib package</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2009/02/17 08:05:25 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.17 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span>
+<a name="l00032"></a>00032 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                                   Includes</span>
+<a name="l00034"></a>00034 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 
+<a name="l00036"></a>00036 <span class="preprocessor">#include <math.h></span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00038"></a>00038 
+<a name="l00039"></a>00039 <span class="preprocessor">#include "irplib_calib.h"</span>
+<a name="l00040"></a>00040 
+<a name="l00041"></a>00041 <span class="keyword">static</span> <span class="keywordtype">int</span>  
+<a name="l00042"></a>00042 irplib_get_clean_mean_window(cpl_image* img, 
+<a name="l00043"></a>00043                              <span class="keyword">const</span> <span class="keywordtype">int</span> llx, 
+<a name="l00044"></a>00044                              <span class="keyword">const</span> <span class="keywordtype">int</span> lly, 
+<a name="l00045"></a>00045                              <span class="keyword">const</span> <span class="keywordtype">int</span> urx, <span class="keywordtype">int</span> ury, 
+<a name="l00046"></a>00046                              <span class="keyword">const</span> <span class="keywordtype">int</span> kappa, 
+<a name="l00047"></a>00047                              <span class="keyword">const</span> <span class="keywordtype">int</span> nclip, 
+<a name="l00048"></a>00048                              <span class="keywordtype">double</span>* clean_mean, 
+<a name="l00049"></a>00049                              <span class="keywordtype">double</span>* clean_stdev);
+<a name="l00050"></a>00050 
+<a name="l00051"></a>00051 <span class="keyword">static</span> <span class="keywordtype">double</span> irplib_pfits_get_dit(<span class="keyword">const</span> cpl_propertylist * plist);
+<a name="l00052"></a>00052 <span class="keyword">static</span> <span class="keywordtype">double</span> irplib_pfits_get_exp_time(<span class="keyword">const</span> cpl_propertylist* plist);
+<a name="l00053"></a>00053 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00057"></a>00057 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00058"></a>00058 
+<a name="l00060"></a>00060 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00067"></a>00067 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00068"></a>00068 <span class="keyword">static</span> <span class="keywordtype">double</span> irplib_pfits_get_dit(<span class="keyword">const</span> cpl_propertylist * plist)
+<a name="l00069"></a>00069 {
+<a name="l00070"></a>00070     <span class="keywordflow">return</span> cpl_propertylist_get_double(plist,<span class="stringliteral">"ESO DET DIT"</span>);
+<a name="l00071"></a>00071 }
+<a name="l00072"></a>00072 
+<a name="l00073"></a>00073 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00079"></a>00079 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00080"></a>00080 <span class="keyword">static</span> <span class="keywordtype">double</span> irplib_pfits_get_exp_time(<span class="keyword">const</span> cpl_propertylist* plist)
+<a name="l00081"></a>00081 {
+<a name="l00082"></a>00082   
+<a name="l00083"></a>00083     <span class="keywordflow">return</span> cpl_propertylist_get_double(plist,<span class="stringliteral">"EXPTIME"</span>);
+<a name="l00084"></a>00084 
+<a name="l00085"></a>00085 }
+<a name="l00086"></a>00086 
+<a name="l00087"></a>00087 
+<a name="l00103"></a>00103 <span class="keyword">static</span> <span class="keywordtype">int</span>  
+<a name="l00104"></a>00104 irplib_get_clean_mean_window(cpl_image* img, 
+<a name="l00105"></a>00105                              <span class="keyword">const</span> <span class="keywordtype">int</span> llx, 
+<a name="l00106"></a>00106                              <span class="keyword">const</span> <span class="keywordtype">int</span> lly, 
+<a name="l00107"></a>00107                              <span class="keyword">const</span> <span class="keywordtype">int</span> urx, <span class="keywordtype">int</span> ury, 
+<a name="l00108"></a>00108                              <span class="keyword">const</span> <span class="keywordtype">int</span> kappa, 
+<a name="l00109"></a>00109                              <span class="keyword">const</span> <span class="keywordtype">int</span> nclip, 
+<a name="l00110"></a>00110                              <span class="keywordtype">double</span>* clean_mean, 
+<a name="l00111"></a>00111                              <span class="keywordtype">double</span>* clean_stdev)
+<a name="l00112"></a>00112 {
+<a name="l00113"></a>00113 
+<a name="l00114"></a>00114 
+<a name="l00115"></a>00115   <span class="keywordtype">double</span> mean=0;
+<a name="l00116"></a>00116   <span class="keywordtype">double</span> stdev=0;
+<a name="l00117"></a>00117   <span class="keywordtype">double</span> threshold=0;
+<a name="l00118"></a>00118   <span class="keywordtype">double</span> lo_cut=0;
+<a name="l00119"></a>00119   <span class="keywordtype">double</span> hi_cut=0;
+<a name="l00120"></a>00120   cpl_mask* mask=NULL;
+<a name="l00121"></a>00121   cpl_image* tmp=NULL;
+<a name="l00122"></a>00122   cpl_stats* stats=NULL;
+<a name="l00123"></a>00123   <span class="keywordtype">int</span> i=0;
+<a name="l00124"></a>00124   
+<a name="l00125"></a>00125   tmp=cpl_image_extract(img,llx,lly,urx,ury);
+<a name="l00126"></a>00126   cpl_image_accept_all(tmp);
+<a name="l00127"></a>00127   <span class="keywordflow">for</span>(i=0;i<nclip;i++) {
+<a name="l00128"></a>00128    
+<a name="l00129"></a>00129 
+<a name="l00130"></a>00130     cpl_stats_delete(stats);
+<a name="l00131"></a>00131     stats = cpl_stats_new_from_image(tmp, CPL_STATS_MEAN | CPL_STATS_STDEV);
+<a name="l00132"></a>00132     mean = cpl_stats_get_mean(stats);
+<a name="l00133"></a>00133     stdev = cpl_stats_get_stdev(stats);
+<a name="l00134"></a>00134 
+<a name="l00135"></a>00135     threshold=kappa*stdev;
+<a name="l00136"></a>00136     lo_cut=mean-threshold;
+<a name="l00137"></a>00137     hi_cut=mean+threshold;
+<a name="l00138"></a>00138 
+<a name="l00139"></a>00139     cpl_image_accept_all(tmp);
+<a name="l00140"></a>00140     mask=cpl_mask_threshold_image_create(tmp,lo_cut,hi_cut);
+<a name="l00141"></a>00141 
+<a name="l00142"></a>00142     cpl_mask_not(mask);
+<a name="l00143"></a>00143     cpl_image_reject_from_mask(tmp,mask);
+<a name="l00144"></a>00144     cpl_mask_delete(mask);
+<a name="l00145"></a>00145 
+<a name="l00146"></a>00146 
+<a name="l00147"></a>00147   }
+<a name="l00148"></a>00148   *clean_mean=mean;
+<a name="l00149"></a>00149   *clean_stdev=stdev;
+<a name="l00150"></a>00150   cpl_image_delete(tmp);
+<a name="l00151"></a>00151   cpl_stats_delete(stats);
+<a name="l00152"></a>00152  
+<a name="l00153"></a>00153   <span class="keywordflow">return</span> 0;
+<a name="l00154"></a>00154 
+<a name="l00155"></a>00155 
+<a name="l00156"></a>00156 }
+<a name="l00157"></a>00157 
+<a name="l00158"></a>00158 
+<a name="l00159"></a>00159 
+<a name="l00160"></a>00160 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00175"></a>00175 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00176"></a>00176 
+<a name="l00177"></a>00177 
+<a name="l00178"></a>00178 cpl_table* 
+<a name="l00179"></a><a class="code" href="group__irplib__calib.html#ga98c9970b59c6b7919f531829f6f5dab9">00179</a> <a class="code" href="group__irplib__calib.html#ga98c9970b59c6b7919f531829f6f5dab9" title="Computes the detector&#39;s gain.">irplib_compute_gain</a>(
+<a name="l00180"></a>00180                 cpl_frameset* son, 
+<a name="l00181"></a>00181                 cpl_frameset* sof, 
+<a name="l00182"></a>00182                 <span class="keywordtype">int</span>* zone,   
+<a name="l00183"></a>00183                 <span class="keyword">const</span> <span class="keywordtype">int</span> kappa,
+<a name="l00184"></a>00184                 <span class="keyword">const</span> <span class="keywordtype">int</span> nclip)
+<a name="l00185"></a>00185 {
+<a name="l00186"></a>00186 
+<a name="l00187"></a>00187   cpl_frame*    frm=NULL;
+<a name="l00188"></a>00188 
+<a name="l00189"></a>00189   cpl_image* img_on1=NULL;
+<a name="l00190"></a>00190   cpl_image* img_on2=NULL;
+<a name="l00191"></a>00191   cpl_image* img_on_dif=NULL;
+<a name="l00192"></a>00192 
+<a name="l00193"></a>00193   cpl_image* img_of1=NULL;
+<a name="l00194"></a>00194   cpl_image* img_of2=NULL;
+<a name="l00195"></a>00195   cpl_image* img_of_dif=NULL;
+<a name="l00196"></a>00196 
+<a name="l00197"></a>00197   cpl_table* res_tbl=NULL;
+<a name="l00198"></a>00198   cpl_vector* dit_on=NULL;
+<a name="l00199"></a>00199   cpl_vector* dit_of=NULL;
+<a name="l00200"></a>00200   cpl_vector* exptime_on=NULL;
+<a name="l00201"></a>00201   cpl_vector* exptime_of=NULL;
+<a name="l00202"></a>00202   cpl_propertylist* plist=NULL;
+<a name="l00203"></a>00203 
+<a name="l00204"></a>00204   <span class="keywordtype">int</span> non=0;
+<a name="l00205"></a>00205   <span class="keywordtype">int</span> nof=0;
+<a name="l00206"></a>00206   <span class="keywordtype">int</span> nfr=0;
+<a name="l00207"></a>00207   <span class="keywordtype">int</span> llx;
+<a name="l00208"></a>00208   <span class="keywordtype">int</span> lly;
+<a name="l00209"></a>00209   <span class="keywordtype">int</span> urx;
+<a name="l00210"></a>00210   <span class="keywordtype">int</span> ury;
+<a name="l00211"></a>00211 
+<a name="l00212"></a>00212   <span class="keywordtype">double</span> avg_on1=0;
+<a name="l00213"></a>00213   <span class="keywordtype">double</span> avg_on2=0;
+<a name="l00214"></a>00214   <span class="keywordtype">double</span> avg_of1=0;
+<a name="l00215"></a>00215   <span class="keywordtype">double</span> avg_of2=0;
+<a name="l00216"></a>00216   <span class="keywordtype">double</span> avg_on_dif=0;
+<a name="l00217"></a>00217   <span class="keywordtype">double</span> avg_of_dif=0;
+<a name="l00218"></a>00218   <span class="keywordtype">double</span> std=0;
+<a name="l00219"></a>00219 
+<a name="l00220"></a>00220   <span class="keywordtype">double</span> sig_on_dif=0;
+<a name="l00221"></a>00221   <span class="keywordtype">double</span> sig_of_dif=0;
+<a name="l00222"></a>00222   <span class="keywordtype">char</span>* name=NULL;
+<a name="l00223"></a>00223   <span class="keywordtype">int</span> i=0;
+<a name="l00224"></a>00224   <span class="keywordtype">int</span> m=0;
+<a name="l00225"></a>00225 
+<a name="l00226"></a>00226   <span class="keywordtype">double</span> gain=0;
+<a name="l00227"></a>00227   <span class="keywordtype">double</span> dit_ref=0;
+<a name="l00228"></a>00228   <span class="keywordtype">double</span> dit_tmp=0;
+<a name="l00229"></a>00229   <span class="keywordtype">double</span> exptime_ref=0;
+<a name="l00230"></a>00230   <span class="keywordtype">double</span> exptime_tmp=0;
+<a name="l00231"></a>00231 
+<a name="l00232"></a>00232  
+<a name="l00233"></a>00233   non = cpl_frameset_get_size(son);
+<a name="l00234"></a>00234   nof = cpl_frameset_get_size(sof);
+<a name="l00235"></a>00235   nfr = (non <= nof) ? non : nof;
+<a name="l00236"></a>00236 
+<a name="l00237"></a>00237   dit_on=cpl_vector_new(nfr);
+<a name="l00238"></a>00238   dit_of=cpl_vector_new(nfr);  
+<a name="l00239"></a>00239   exptime_on=cpl_vector_new(nfr);
+<a name="l00240"></a>00240   exptime_of=cpl_vector_new(nfr);
+<a name="l00241"></a>00241 
+<a name="l00242"></a>00242   <span class="keywordflow">for</span>(i=0;i<nfr;i++) {
+<a name="l00243"></a>00243 
+<a name="l00244"></a>00244     frm=cpl_frameset_get_frame(son,i);
+<a name="l00245"></a>00245     name=(<span class="keywordtype">char</span>*)cpl_frame_get_filename(frm);
+<a name="l00246"></a>00246     plist=cpl_propertylist_load(name,0);
+<a name="l00247"></a>00247     dit_ref=irplib_pfits_get_dit(plist);
+<a name="l00248"></a>00248     exptime_ref=(double)irplib_pfits_get_exp_time(plist);
+<a name="l00249"></a>00249     cpl_propertylist_delete(plist);
+<a name="l00250"></a>00250     cpl_vector_set(dit_on,i,dit_ref);
+<a name="l00251"></a>00251     cpl_vector_set(exptime_on,i,exptime_ref);
+<a name="l00252"></a>00252 
+<a name="l00253"></a>00253     frm=cpl_frameset_get_frame(sof,i);
+<a name="l00254"></a>00254     name=(<span class="keywordtype">char</span>*)cpl_frame_get_filename(frm);
+<a name="l00255"></a>00255     plist=cpl_propertylist_load(name,0);
+<a name="l00256"></a>00256     dit_ref=irplib_pfits_get_dit(plist);
+<a name="l00257"></a>00257     exptime_ref=(double)irplib_pfits_get_exp_time(plist);
+<a name="l00258"></a>00258     cpl_propertylist_delete(plist);
+<a name="l00259"></a>00259     cpl_vector_set(dit_of,i,dit_ref);
+<a name="l00260"></a>00260     cpl_vector_set(exptime_of,i,exptime_ref);
+<a name="l00261"></a>00261 
+<a name="l00262"></a>00262   }
+<a name="l00263"></a>00263 
+<a name="l00264"></a>00264 
+<a name="l00265"></a>00265   llx=zone[0];
+<a name="l00266"></a>00266   lly=zone[1];
+<a name="l00267"></a>00267   urx=zone[2];
+<a name="l00268"></a>00268   ury=zone[3];
+<a name="l00269"></a>00269 
+<a name="l00270"></a>00270 
+<a name="l00271"></a>00271 
+<a name="l00272"></a>00272   res_tbl=cpl_table_new(nfr);
+<a name="l00273"></a>00273   cpl_table_new_column(res_tbl,<span class="stringliteral">"adu"</span>, CPL_TYPE_DOUBLE);
+<a name="l00274"></a>00274   cpl_table_new_column(res_tbl,<span class="stringliteral">"gain"</span>, CPL_TYPE_DOUBLE);
+<a name="l00275"></a>00275  
+<a name="l00276"></a>00276   <span class="keywordflow">for</span>(i=0;i<nfr;i++) {
+<a name="l00277"></a>00277     frm=cpl_frameset_get_frame(son,i);
+<a name="l00278"></a>00278     name=(<span class="keywordtype">char</span>*)cpl_frame_get_filename(frm);
+<a name="l00279"></a>00279     img_on1=cpl_image_load(name,CPL_TYPE_FLOAT,0,0);
+<a name="l00280"></a>00280 
+<a name="l00281"></a>00281     frm=cpl_frameset_get_frame(sof,i);
+<a name="l00282"></a>00282     name=(<span class="keywordtype">char</span>*)cpl_frame_get_filename(frm);
+<a name="l00283"></a>00283     img_of1=cpl_image_load(name,CPL_TYPE_FLOAT,0,0);
+<a name="l00284"></a>00284 
+<a name="l00285"></a>00285 
+<a name="l00286"></a>00286     dit_ref=cpl_vector_get(dit_on,i);
+<a name="l00287"></a>00287     exptime_ref=cpl_vector_get(exptime_on,i);
+<a name="l00288"></a>00288 
+<a name="l00289"></a>00289    
+<a name="l00290"></a>00290     <span class="keywordflow">for</span>(m=0;m<nfr; m++) {
+<a name="l00291"></a>00291       <span class="keywordflow">if</span>(m != i) {
+<a name="l00292"></a>00292     frm=cpl_frameset_get_frame(son,m);
+<a name="l00293"></a>00293     name=(<span class="keywordtype">char</span>*)cpl_frame_get_filename(frm);
+<a name="l00294"></a>00294     dit_tmp=cpl_vector_get(dit_on,m);
+<a name="l00295"></a>00295     exptime_tmp=cpl_vector_get(exptime_on,m);
+<a name="l00296"></a>00296     <span class="keywordflow">if</span>(dit_tmp == dit_ref && exptime_tmp == exptime_ref) {
+<a name="l00297"></a>00297       img_on2=cpl_image_load(name,CPL_TYPE_FLOAT,0,0);
+<a name="l00298"></a>00298       frm=cpl_frameset_get_frame(sof,m);
+<a name="l00299"></a>00299       name=(<span class="keywordtype">char</span>*)cpl_frame_get_filename(frm);
+<a name="l00300"></a>00300       img_of2=cpl_image_load(name,CPL_TYPE_FLOAT,0,0);
+<a name="l00301"></a>00301 
+<a name="l00302"></a>00302       img_on_dif=cpl_image_subtract_create(img_on1,img_on2);
+<a name="l00303"></a>00303       img_of_dif=cpl_image_subtract_create(img_of1,img_of2);
+<a name="l00304"></a>00304       
+<a name="l00305"></a>00305       irplib_get_clean_mean_window(img_on1,llx,lly,urx,ury,kappa,
+<a name="l00306"></a>00306                                       nclip,&avg_on1,&std);
+<a name="l00307"></a>00307       irplib_get_clean_mean_window(img_on2,llx,lly,urx,ury,kappa,
+<a name="l00308"></a>00308                                       nclip,&avg_on2,&std);
+<a name="l00309"></a>00309       irplib_get_clean_mean_window(img_of1,llx,lly,urx,ury,kappa,
+<a name="l00310"></a>00310                                       nclip,&avg_of1,&std);
+<a name="l00311"></a>00311       irplib_get_clean_mean_window(img_of2,llx,lly,urx,ury,kappa,
+<a name="l00312"></a>00312                                       nclip,&avg_of2,&std);
+<a name="l00313"></a>00313       irplib_get_clean_mean_window(img_on_dif,llx,lly,urx,ury,kappa,
+<a name="l00314"></a>00314                                       nclip,&avg_on_dif,&sig_on_dif);
+<a name="l00315"></a>00315       irplib_get_clean_mean_window(img_of_dif,llx,lly,urx,ury,kappa,
+<a name="l00316"></a>00316                                       nclip,&avg_of_dif,&sig_of_dif);
+<a name="l00317"></a>00317 
+<a name="l00318"></a>00318       cpl_image_delete(img_on2);
+<a name="l00319"></a>00319       cpl_image_delete(img_of2);
+<a name="l00320"></a>00320       cpl_image_delete(img_on_dif);
+<a name="l00321"></a>00321       cpl_image_delete(img_of_dif);
+<a name="l00322"></a>00322 
+<a name="l00323"></a>00323           gain=((avg_on1+avg_on2)-(avg_of1+avg_of2))/
+<a name="l00324"></a>00324                ((sig_on_dif*sig_on_dif)-(sig_of_dif*sig_of_dif));
+<a name="l00325"></a>00325 
+<a name="l00326"></a>00326           cpl_table_set_double(res_tbl,<span class="stringliteral">"gain"</span>,m,gain);
+<a name="l00327"></a>00327           cpl_table_set_double(res_tbl,<span class="stringliteral">"adu"</span>,m,
+<a name="l00328"></a>00328                                ((avg_on1+avg_on2)/2-(avg_of1+avg_of2)/2));
+<a name="l00329"></a>00329 
+<a name="l00330"></a>00330     }
+<a name="l00331"></a>00331       }
+<a name="l00332"></a>00332     }
+<a name="l00333"></a>00333     cpl_image_delete(img_on1);
+<a name="l00334"></a>00334     cpl_image_delete(img_of1);
+<a name="l00335"></a>00335   }
+<a name="l00336"></a>00336   
+<a name="l00337"></a>00337 
+<a name="l00338"></a>00338   cpl_vector_delete(dit_on);
+<a name="l00339"></a>00339   cpl_vector_delete(dit_of);
+<a name="l00340"></a>00340   cpl_vector_delete(exptime_on);
+<a name="l00341"></a>00341   cpl_vector_delete(exptime_of);
+<a name="l00342"></a>00342 
+<a name="l00343"></a>00343   <span class="keywordflow">return</span> res_tbl;
+<a name="l00344"></a>00344 
+<a name="l00345"></a>00345 }
+<a name="l00346"></a>00346 
+<a name="l00347"></a>00347 <span class="comment">/* --------------------------------------------------------------------------*/</span>
+<a name="l00357"></a>00357 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00358"></a>00358 
+<a name="l00359"></a>00359 
+<a name="l00360"></a><a class="code" href="group__irplib__calib.html#gadefee4e970a548c25bcbb42797778a2a">00360</a> cpl_table* <a class="code" href="group__irplib__calib.html#gadefee4e970a548c25bcbb42797778a2a" title="Computes the detector&#39;s linearity.">irplib_compute_linearity</a>(cpl_frameset* son, cpl_frameset* sof)
+<a name="l00361"></a>00361 {
+<a name="l00362"></a>00362 
+<a name="l00363"></a>00363 
+<a name="l00364"></a>00364   cpl_frame*    frm=NULL;
+<a name="l00365"></a>00365 
+<a name="l00366"></a>00366   <span class="keywordtype">int</span>* status=0;
+<a name="l00367"></a>00367   <span class="keywordtype">int</span> non=0;
+<a name="l00368"></a>00368   <span class="keywordtype">int</span> nof=0;
+<a name="l00369"></a>00369   <span class="keywordtype">int</span> nfr=0;
+<a name="l00370"></a>00370   <span class="keywordtype">int</span> i=0;
+<a name="l00371"></a>00371   <span class="keywordtype">double</span> med_on=0;
+<a name="l00372"></a>00372   <span class="keywordtype">double</span> avg_on=0;
+<a name="l00373"></a>00373   <span class="keywordtype">double</span> med_of=0;
+<a name="l00374"></a>00374   <span class="keywordtype">double</span> avg_of=0;
+<a name="l00375"></a>00375   <span class="keywordtype">double</span> med_dit=0;
+<a name="l00376"></a>00376   <span class="keywordtype">double</span> avg_dit=0;
+<a name="l00377"></a>00377 
+<a name="l00378"></a>00378   <span class="keywordtype">double</span> med=0;
+<a name="l00379"></a>00379   <span class="keywordtype">double</span> avg=0;
+<a name="l00380"></a>00380 
+<a name="l00381"></a>00381   <span class="keywordtype">char</span>* name=NULL;
+<a name="l00382"></a>00382   cpl_image* img=NULL;
+<a name="l00383"></a>00383   cpl_vector* vec_adl=NULL;
+<a name="l00384"></a>00384   cpl_vector* vec_dit=NULL;
+<a name="l00385"></a>00385   cpl_vector* vec_avg=NULL;
+<a name="l00386"></a>00386   cpl_vector* vec_med=NULL;
+<a name="l00387"></a>00387   cpl_vector* vec_avg_dit=NULL;
+<a name="l00388"></a>00388   cpl_vector* vec_med_dit=NULL;
+<a name="l00389"></a>00389   cpl_propertylist* plist=NULL;
+<a name="l00390"></a>00390 
+<a name="l00391"></a>00391   <span class="keywordtype">double</span> dit=0;
+<a name="l00392"></a>00392   cpl_table* lin_tbl=NULL;
+<a name="l00393"></a>00393 
+<a name="l00394"></a>00394  
+<a name="l00395"></a>00395   non = cpl_frameset_get_size(son);
+<a name="l00396"></a>00396   nof = cpl_frameset_get_size(sof);
+<a name="l00397"></a>00397   nfr = (non <= nof) ? non : nof;
+<a name="l00398"></a>00398 
+<a name="l00399"></a>00399   lin_tbl=cpl_table_new(nfr);
+<a name="l00400"></a>00400   cpl_table_new_column(lin_tbl,<span class="stringliteral">"med"</span>, CPL_TYPE_DOUBLE);
+<a name="l00401"></a>00401   cpl_table_new_column(lin_tbl,<span class="stringliteral">"avg"</span>, CPL_TYPE_DOUBLE);
+<a name="l00402"></a>00402   cpl_table_new_column(lin_tbl,<span class="stringliteral">"med_dit"</span>, CPL_TYPE_DOUBLE);
+<a name="l00403"></a>00403   cpl_table_new_column(lin_tbl,<span class="stringliteral">"avg_dit"</span>, CPL_TYPE_DOUBLE);
+<a name="l00404"></a>00404   cpl_table_new_column(lin_tbl,<span class="stringliteral">"dit"</span>, CPL_TYPE_DOUBLE);
+<a name="l00405"></a>00405   vec_med=cpl_vector_new(nfr);
+<a name="l00406"></a>00406   vec_avg=cpl_vector_new(nfr);
+<a name="l00407"></a>00407   vec_med_dit=cpl_vector_new(nfr);
+<a name="l00408"></a>00408   vec_avg_dit=cpl_vector_new(nfr);
+<a name="l00409"></a>00409   vec_dit=cpl_vector_new(nfr);
+<a name="l00410"></a>00410   vec_adl=cpl_vector_new(nfr);
+<a name="l00411"></a>00411   <span class="keywordflow">for</span>(i=0;i<nfr;i++) {
+<a name="l00412"></a>00412     frm=cpl_frameset_get_frame(son,i);
+<a name="l00413"></a>00413     name=(<span class="keywordtype">char</span>*)cpl_frame_get_filename(frm);
+<a name="l00414"></a>00414     img=cpl_image_load(name,CPL_TYPE_FLOAT,0,0);
+<a name="l00415"></a>00415     med_on=cpl_image_get_median(img);
+<a name="l00416"></a>00416     avg_on=cpl_image_get_mean(img);
+<a name="l00417"></a>00417     cpl_image_delete(img);
+<a name="l00418"></a>00418 
+<a name="l00419"></a>00419     frm=cpl_frameset_get_frame(sof,i);
+<a name="l00420"></a>00420     name=(<span class="keywordtype">char</span>*)cpl_frame_get_filename(frm);
+<a name="l00421"></a>00421     img=cpl_image_load(name,CPL_TYPE_FLOAT,0,0);
+<a name="l00422"></a>00422     med_of=cpl_image_get_median(img);
+<a name="l00423"></a>00423     avg_of=cpl_image_get_mean(img);
+<a name="l00424"></a>00424     cpl_image_delete(img);
+<a name="l00425"></a>00425     med=med_on-med_of;
+<a name="l00426"></a>00426     avg=avg_on-avg_of;
+<a name="l00427"></a>00427     plist=cpl_propertylist_load(name,0);
+<a name="l00428"></a>00428     dit=(double)irplib_pfits_get_dit(plist);
+<a name="l00429"></a>00429     cpl_propertylist_delete(plist);
+<a name="l00430"></a>00430     avg_dit=avg/dit;
+<a name="l00431"></a>00431     med_dit=med/dit;
+<a name="l00432"></a>00432 
+<a name="l00433"></a>00433     cpl_vector_set(vec_dit,i,dit);
+<a name="l00434"></a>00434     cpl_vector_set(vec_avg,i,avg);
+<a name="l00435"></a>00435     cpl_vector_set(vec_med,i,med);
+<a name="l00436"></a>00436     cpl_vector_set(vec_avg_dit,i,avg_dit);
+<a name="l00437"></a>00437     cpl_vector_set(vec_med_dit,i,med_dit);
+<a name="l00438"></a>00438 
+<a name="l00439"></a>00439 
+<a name="l00440"></a>00440     cpl_table_set_double(lin_tbl,<span class="stringliteral">"dit"</span>,i,dit);
+<a name="l00441"></a>00441     cpl_table_set_double(lin_tbl,<span class="stringliteral">"med"</span>,i,med);
+<a name="l00442"></a>00442     cpl_table_set_double(lin_tbl,<span class="stringliteral">"avg"</span>,i,avg);
+<a name="l00443"></a>00443     cpl_table_set_double(lin_tbl,<span class="stringliteral">"med_dit"</span>,i,med_dit);
+<a name="l00444"></a>00444     cpl_table_set_double(lin_tbl,<span class="stringliteral">"avg_dit"</span>,i,avg_dit);
+<a name="l00445"></a>00445 
+<a name="l00446"></a>00446   }
+<a name="l00447"></a>00447   cpl_table_new_column(lin_tbl,<span class="stringliteral">"adl"</span>, CPL_TYPE_DOUBLE);
+<a name="l00448"></a>00448   med_dit=cpl_vector_get_mean(vec_med_dit);
+<a name="l00449"></a>00449   avg_dit=cpl_vector_get_mean(vec_avg_dit);
+<a name="l00450"></a>00450 
+<a name="l00451"></a>00451   <span class="keywordflow">for</span>(i=0;i<nfr;i++) {
+<a name="l00452"></a>00452     dit = cpl_table_get_double(lin_tbl,<span class="stringliteral">"dit"</span>,i,status);
+<a name="l00453"></a>00453     cpl_vector_set(vec_adl,i,dit*med_dit);
+<a name="l00454"></a>00454     cpl_table_set_double(lin_tbl,<span class="stringliteral">"adl"</span>,i,dit*med_dit);
+<a name="l00455"></a>00455   }
+<a name="l00456"></a>00456  
+<a name="l00457"></a>00457   
+<a name="l00458"></a>00458   cpl_vector_delete(vec_dit);
+<a name="l00459"></a>00459   cpl_vector_delete(vec_adl);
+<a name="l00460"></a>00460   cpl_vector_delete(vec_avg);
+<a name="l00461"></a>00461   cpl_vector_delete(vec_med);
+<a name="l00462"></a>00462   cpl_vector_delete(vec_avg_dit);
+<a name="l00463"></a>00463   cpl_vector_delete(vec_med_dit);
+<a name="l00464"></a>00464 
+<a name="l00465"></a>00465 
+<a name="l00466"></a>00466   <span class="keywordflow">return</span> lin_tbl;
+<a name="l00467"></a>00467 
+<a name="l00468"></a>00468 }
+<a name="l00469"></a>00469 
+<a name="l00470"></a>00470 
+<a name="l00471"></a>00471 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00480"></a>00480 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00481"></a><a class="code" href="group__irplib__calib.html#gae9b762625dbd2c31c1b59cfd8c15fd90">00481</a> <span class="keywordtype">int</span> <a class="code" href="group__irplib__calib.html#gae9b762625dbd2c31c1b59cfd8c15fd90" title="Apply the detector linearity correction.">irplib_detlin_correct</a>(
+<a name="l00482"></a>00482         cpl_imagelist       *   ilist,
+<a name="l00483"></a>00483         <span class="keyword">const</span> <span class="keywordtype">char</span>          *   detlin_a,
+<a name="l00484"></a>00484         <span class="keyword">const</span> <span class="keywordtype">char</span>          *   detlin_b,
+<a name="l00485"></a>00485         <span class="keyword">const</span> <span class="keywordtype">char</span>          *   detlin_c)
+<a name="l00486"></a>00486 {
+<a name="l00487"></a>00487     cpl_image       *   ima ;
+<a name="l00488"></a>00488     cpl_image       *   imb ;
+<a name="l00489"></a>00489     cpl_image       *   imc ;
+<a name="l00490"></a>00490     <span class="keywordtype">float</span>           *   pima ;
+<a name="l00491"></a>00491     <span class="keywordtype">float</span>           *   pimb ;
+<a name="l00492"></a>00492     <span class="keywordtype">float</span>           *   pimc ;
+<a name="l00493"></a>00493     <span class="keywordtype">float</span>           *   pdata ;
+<a name="l00494"></a>00494     <span class="keywordtype">int</span>                 nx, ny, ni ; 
+<a name="l00495"></a>00495     <span class="keywordtype">double</span>              coeff_1, coeff_2, val ;
+<a name="l00496"></a>00496     <span class="keywordtype">int</span>                 i, j ;
+<a name="l00497"></a>00497 
+<a name="l00498"></a>00498     <span class="comment">/* Test entries */</span>
+<a name="l00499"></a>00499     <span class="keywordflow">if</span> (!ilist || !detlin_a || !detlin_b || !detlin_c) <span class="keywordflow">return</span> -1 ;
+<a name="l00500"></a>00500     
+<a name="l00501"></a>00501     <span class="comment">/* Load the 3 coeffs images */</span>
+<a name="l00502"></a>00502     ima = cpl_image_load(detlin_a, CPL_TYPE_FLOAT, 0, 0) ;
+<a name="l00503"></a>00503     imb = cpl_image_load(detlin_b, CPL_TYPE_FLOAT, 0, 0) ;
+<a name="l00504"></a>00504     imc = cpl_image_load(detlin_c, CPL_TYPE_FLOAT, 0, 0) ;
+<a name="l00505"></a>00505     <span class="keywordflow">if</span> (!ima || !imb || !imc) {
+<a name="l00506"></a>00506         cpl_msg_error(cpl_func, <span class="stringliteral">"Cannot load the detlin images"</span>) ;
+<a name="l00507"></a>00507         <span class="keywordflow">if</span> (ima) cpl_image_delete(ima) ;
+<a name="l00508"></a>00508         <span class="keywordflow">if</span> (imb) cpl_image_delete(imb) ;
+<a name="l00509"></a>00509         <span class="keywordflow">if</span> (imc) cpl_image_delete(imc) ;
+<a name="l00510"></a>00510         <span class="keywordflow">return</span> -1 ;
+<a name="l00511"></a>00511     }
+<a name="l00512"></a>00512     pima = cpl_image_get_data_float(ima) ;
+<a name="l00513"></a>00513     pimb = cpl_image_get_data_float(imb) ;
+<a name="l00514"></a>00514     pimc = cpl_image_get_data_float(imc) ;
+<a name="l00515"></a>00515     
+<a name="l00516"></a>00516     <span class="comment">/* Test sizes */</span>
+<a name="l00517"></a>00517     nx = cpl_image_get_size_x(cpl_imagelist_get(ilist, 0)) ;
+<a name="l00518"></a>00518     ny = cpl_image_get_size_y(cpl_imagelist_get(ilist, 0)) ;
+<a name="l00519"></a>00519     ni = cpl_imagelist_get_size(ilist) ;
+<a name="l00520"></a>00520     <span class="keywordflow">if</span> ((cpl_image_get_size_x(ima) != nx) ||
+<a name="l00521"></a>00521             (cpl_image_get_size_x(imb) != nx) ||
+<a name="l00522"></a>00522             (cpl_image_get_size_x(imc) != nx) ||
+<a name="l00523"></a>00523             (cpl_image_get_size_y(ima) != ny) ||
+<a name="l00524"></a>00524             (cpl_image_get_size_y(imb) != ny) ||
+<a name="l00525"></a>00525             (cpl_image_get_size_y(imc) != ny)) {
+<a name="l00526"></a>00526         cpl_msg_error(cpl_func, <span class="stringliteral">"Incompatible sizes"</span>) ;
+<a name="l00527"></a>00527         cpl_image_delete(ima) ;
+<a name="l00528"></a>00528         cpl_image_delete(imb) ;
+<a name="l00529"></a>00529         cpl_image_delete(imc) ;
+<a name="l00530"></a>00530         <span class="keywordflow">return</span> -1 ;
+<a name="l00531"></a>00531     }
+<a name="l00532"></a>00532     
+<a name="l00533"></a>00533     <span class="comment">/* Loop on pixels */</span>
+<a name="l00534"></a>00534     <span class="keywordflow">for</span> (i=0 ; i<nx*ny ; i++) {
+<a name="l00535"></a>00535         <span class="comment">/* Compute the coefficients */</span>
+<a name="l00536"></a>00536         <span class="keywordflow">if</span> (fabs(pima[i]) < 1e-30) {
+<a name="l00537"></a>00537             coeff_1 = coeff_2 = (double)0.0 ;
+<a name="l00538"></a>00538         } <span class="keywordflow">else</span> {
+<a name="l00539"></a>00539             coeff_1 = (double)pimb[i] / (<span class="keywordtype">double</span>)pima[i] ;
+<a name="l00540"></a>00540             coeff_2 = (double)pimc[i] / (<span class="keywordtype">double</span>)pima[i] ;
+<a name="l00541"></a>00541         }
+<a name="l00542"></a>00542         <span class="comment">/* Correct this pixel in each plane */</span>
+<a name="l00543"></a>00543         <span class="keywordflow">for</span> (j=0 ; j<ni ; j++) {
+<a name="l00544"></a>00544             pdata = cpl_image_get_data_float(cpl_imagelist_get(ilist, j)) ;
+<a name="l00545"></a>00545             val = (double)pdata[i] ;
+<a name="l00546"></a>00546             pdata[i]=(float)(val+coeff_1*val*val+coeff_2*val*val*val) ;
+<a name="l00547"></a>00547         }
+<a name="l00548"></a>00548     }
+<a name="l00549"></a>00549     <span class="comment">/* Free and return */</span>
+<a name="l00550"></a>00550     cpl_image_delete(ima) ;
+<a name="l00551"></a>00551     cpl_image_delete(imb) ;
+<a name="l00552"></a>00552     cpl_image_delete(imc) ;
+<a name="l00553"></a>00553     <span class="keywordflow">return</span> 0 ;
+<a name="l00554"></a>00554 }
+<a name="l00555"></a>00555  
+<a name="l00556"></a>00556 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00565"></a>00565 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00566"></a><a class="code" href="group__irplib__calib.html#gae650a3e54e1aff329b1b5ee356bcdbde">00566</a> <span class="keywordtype">int</span> <a class="code" href="group__irplib__calib.html#gae650a3e54e1aff329b1b5ee356bcdbde" title="Apply the calibration to the frames.">irplib_flat_dark_bpm_calib</a>(
+<a name="l00567"></a>00567         cpl_imagelist       *   ilist,
+<a name="l00568"></a>00568         <span class="keyword">const</span> <span class="keywordtype">char</span>          *   flat,
+<a name="l00569"></a>00569         <span class="keyword">const</span> <span class="keywordtype">char</span>          *   dark,
+<a name="l00570"></a>00570         <span class="keyword">const</span> <span class="keywordtype">char</span>          *   bpm)
+<a name="l00571"></a>00571 {
+<a name="l00572"></a>00572     cpl_image       *   dark_image ;
+<a name="l00573"></a>00573     cpl_image       *   flat_image ;
+<a name="l00574"></a>00574     cpl_mask        *   bpm_im_bin ;
+<a name="l00575"></a>00575     cpl_image       *   bpm_im_int ;
+<a name="l00576"></a>00576     <span class="keywordtype">int</span>                 i ;
+<a name="l00577"></a>00577 
+<a name="l00578"></a>00578     <span class="comment">/* Test entries */</span>
+<a name="l00579"></a>00579     <span class="keywordflow">if</span> (ilist == NULL) <span class="keywordflow">return</span> -1 ;
+<a name="l00580"></a>00580 
+<a name="l00581"></a>00581     <span class="comment">/* Dark correction */</span>
+<a name="l00582"></a>00582     <span class="keywordflow">if</span> (dark != NULL) {
+<a name="l00583"></a>00583         cpl_msg_info(cpl_func, <span class="stringliteral">"Subtract the dark to the images"</span>) ;
+<a name="l00584"></a>00584         <span class="comment">/* Load the dark image */</span>
+<a name="l00585"></a>00585         <span class="keywordflow">if</span> ((dark_image = cpl_image_load(dark, CPL_TYPE_FLOAT, 0, 0)) == NULL) {
+<a name="l00586"></a>00586             cpl_msg_error(cpl_func, <span class="stringliteral">"Cannot load the dark %s"</span>, dark) ;
+<a name="l00587"></a>00587             <span class="keywordflow">return</span> -1 ;
+<a name="l00588"></a>00588         }
+<a name="l00589"></a>00589         <span class="comment">/* Apply the dark correction to the images */</span>
+<a name="l00590"></a>00590         <span class="keywordflow">if</span> (cpl_imagelist_subtract_image(ilist, dark_image)!=CPL_ERROR_NONE) {
+<a name="l00591"></a>00591             cpl_msg_error(cpl_func, <span class="stringliteral">"Cannot apply the dark to the images"</span>) ;
+<a name="l00592"></a>00592             cpl_image_delete(dark_image) ;
+<a name="l00593"></a>00593             <span class="keywordflow">return</span> -1 ;
+<a name="l00594"></a>00594         }
+<a name="l00595"></a>00595         cpl_image_delete(dark_image) ;
+<a name="l00596"></a>00596     }
+<a name="l00597"></a>00597 
+<a name="l00598"></a>00598     <span class="comment">/* Flat-field correction */</span>
+<a name="l00599"></a>00599     <span class="keywordflow">if</span> (flat != NULL) {
+<a name="l00600"></a>00600         cpl_msg_info(cpl_func, <span class="stringliteral">"Divide the images by the flatfield"</span>) ;
+<a name="l00601"></a>00601         <span class="comment">/* Load the flat image */</span>
+<a name="l00602"></a>00602         <span class="keywordflow">if</span> ((flat_image = cpl_image_load(flat, CPL_TYPE_FLOAT, 0, 0)) == NULL) {
+<a name="l00603"></a>00603             cpl_msg_error(cpl_func, <span class="stringliteral">"Cannot load the flat field %s"</span>, flat) ;
+<a name="l00604"></a>00604             <span class="keywordflow">return</span> -1 ;
+<a name="l00605"></a>00605         }
+<a name="l00606"></a>00606         <span class="comment">/* Apply the flatfield correction to the images */</span>
+<a name="l00607"></a>00607         <span class="keywordflow">if</span> (cpl_imagelist_divide_image(ilist, flat_image)!=CPL_ERROR_NONE) {
+<a name="l00608"></a>00608             cpl_msg_error(cpl_func, <span class="stringliteral">"Cannot apply the flatfield to the images"</span>) ;
+<a name="l00609"></a>00609             cpl_image_delete(flat_image) ;
+<a name="l00610"></a>00610             <span class="keywordflow">return</span> -1 ;
+<a name="l00611"></a>00611         }
+<a name="l00612"></a>00612         cpl_image_delete(flat_image) ;
+<a name="l00613"></a>00613     }
+<a name="l00614"></a>00614 
+<a name="l00615"></a>00615     <span class="comment">/* Correct the bad pixels if requested */</span>
+<a name="l00616"></a>00616     <span class="keywordflow">if</span> (bpm != NULL) {
+<a name="l00617"></a>00617         cpl_msg_info(cpl_func, <span class="stringliteral">"Correct the bad pixels in the images"</span>) ;
+<a name="l00618"></a>00618          <span class="comment">/* Load the bad pixels image */</span>
+<a name="l00619"></a>00619         <span class="keywordflow">if</span> ((bpm_im_int = cpl_image_load(bpm, CPL_TYPE_INT, 0, 0)) == NULL) {
+<a name="l00620"></a>00620             cpl_msg_error(cpl_func, <span class="stringliteral">"Cannot load the bad pixel map %s"</span>, bpm) ;
+<a name="l00621"></a>00621             <span class="keywordflow">return</span> -1 ;
+<a name="l00622"></a>00622         }
+<a name="l00623"></a>00623         <span class="comment">/* Convert the map from integer to binary */</span>
+<a name="l00624"></a>00624         bpm_im_bin = cpl_mask_threshold_image_create(bpm_im_int, -0.5, 0.5) ;
+<a name="l00625"></a>00625         cpl_mask_not(bpm_im_bin) ;
+<a name="l00626"></a>00626         cpl_image_delete(bpm_im_int) ;
+<a name="l00627"></a>00627         <span class="comment">/* Apply the bad pixels cleaning */</span>
+<a name="l00628"></a>00628         <span class="keywordflow">for</span> (i=0 ; i<cpl_imagelist_get_size(ilist) ; i++) {
+<a name="l00629"></a>00629             cpl_image_reject_from_mask(cpl_imagelist_get(ilist, i), bpm_im_bin);
+<a name="l00630"></a>00630             <span class="keywordflow">if</span> (cpl_detector_interpolate_rejected(
+<a name="l00631"></a>00631                         cpl_imagelist_get(ilist, i)) != CPL_ERROR_NONE) {
+<a name="l00632"></a>00632                 cpl_msg_error(cpl_func, <span class="stringliteral">"Cannot clean the bad pixels in obj %d"</span>,
+<a name="l00633"></a>00633                         i+1);
+<a name="l00634"></a>00634                 cpl_mask_delete(bpm_im_bin) ;
+<a name="l00635"></a>00635                 <span class="keywordflow">return</span> -1 ;
+<a name="l00636"></a>00636             }
+<a name="l00637"></a>00637         }
+<a name="l00638"></a>00638         cpl_mask_delete(bpm_im_bin) ;
+<a name="l00639"></a>00639     }
+<a name="l00640"></a>00640 
+<a name="l00641"></a>00641     <span class="comment">/* Return */</span>
+<a name="l00642"></a>00642     <span class="keywordflow">return</span> 0 ;
+<a name="l00643"></a>00643 }
+<a name="l00644"></a>00644 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/irplib__calib_8h_source.html b/html/irplib__calib_8h_source.html
new file mode 100644
index 0000000..21a3b0b
--- /dev/null
+++ b/html/irplib__calib_8h_source.html
@@ -0,0 +1,65 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: irplib_calib.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>irplib_calib.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: irplib_calib.h,v 1.8 2007/02/12 10:34:51 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the irplib package</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2007/02/12 10:34:51 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.8 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifndef IRPLIB_CALIB_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#define IRPLIB_CALIB_H</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span>
+<a name="l00031"></a>00031 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00032"></a>00032 <span class="comment">                                   Includes</span>
+<a name="l00033"></a>00033 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00034"></a>00034 
+<a name="l00035"></a>00035 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00036"></a>00036 cpl_table*
+<a name="l00037"></a>00037 <a class="code" href="group__irplib__calib.html#ga98c9970b59c6b7919f531829f6f5dab9" title="Computes the detector&#39;s gain.">irplib_compute_gain</a>(
+<a name="l00038"></a>00038                 cpl_frameset* son, 
+<a name="l00039"></a>00039                 cpl_frameset* sof, 
+<a name="l00040"></a>00040                 <span class="keywordtype">int</span>* zone1, 
+<a name="l00041"></a>00041                 <span class="keyword">const</span> <span class="keywordtype">int</span> kappa1,
+<a name="l00042"></a>00042                 <span class="keyword">const</span> <span class="keywordtype">int</span> nclip1);
+<a name="l00043"></a>00043 cpl_table* <a class="code" href="group__irplib__calib.html#gadefee4e970a548c25bcbb42797778a2a" title="Computes the detector&#39;s linearity.">irplib_compute_linearity</a>(cpl_frameset* son, cpl_frameset* sof);
+<a name="l00044"></a>00044 <span class="keywordtype">int</span> <a class="code" href="group__irplib__calib.html#gae650a3e54e1aff329b1b5ee356bcdbde" title="Apply the calibration to the frames.">irplib_flat_dark_bpm_calib</a>(cpl_imagelist *, <span class="keyword">const</span> <span class="keywordtype">char</span> *, <span class="keyword">const</span> <span class="keywordtype">char</span> *,
+<a name="l00045"></a>00045                                <span class="keyword">const</span> <span class="keywordtype">char</span> *);
+<a name="l00046"></a>00046 <span class="keywordtype">int</span> <a class="code" href="group__irplib__calib.html#gae9b762625dbd2c31c1b59cfd8c15fd90" title="Apply the detector linearity correction.">irplib_detlin_correct</a>(cpl_imagelist *, <span class="keyword">const</span> <span class="keywordtype">char</span> *, <span class="keyword">const</span> <span class="keywordtype">char</span> *,
+<a name="l00047"></a>00047                           <span class="keyword">const</span> <span class="keywordtype">char</span> *);
+<a name="l00048"></a>00048 
+<a name="l00049"></a>00049 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/irplib__cat_8c_source.html b/html/irplib__cat_8c_source.html
new file mode 100644
index 0000000..b70a268
--- /dev/null
+++ b/html/irplib__cat_8c_source.html
@@ -0,0 +1,415 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: irplib_cat.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>irplib_cat.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: irplib_cat.c,v 1.10 2009/12/01 12:34:25 cgarcia Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the irplib package</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: cgarcia $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2009/12/01 12:34:25 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.10 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span>
+<a name="l00032"></a>00032 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                                   Includes</span>
+<a name="l00034"></a>00034 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 
+<a name="l00036"></a>00036 <span class="preprocessor">#include <libgen.h></span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include <math.h></span>
+<a name="l00038"></a>00038 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00039"></a>00039 
+<a name="l00040"></a>00040 <span class="preprocessor">#include "irplib_cat.h"</span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include "irplib_wcs.h"</span>
+<a name="l00042"></a>00042 
+<a name="l00043"></a>00043 <span class="preprocessor">#define FILENAME_SZBUF 1024</span>
+<a name="l00044"></a>00044 <span class="preprocessor"></span>
+<a name="l00045"></a>00045 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00049"></a>00049 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00050"></a>00050 
+<a name="l00053"></a>00053 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00072"></a>00072 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00073"></a>00073 
+<a name="l00074"></a>00074 <span class="keywordtype">int</span> <a class="code" href="group__irplib__cat.html#ga8dd2b5e6b7bc4a7ea3f2b275882aa200" title="Find the name of the standard catalogue being used and its location.">irplib_2mass_get_catpars</a>
+<a name="l00075"></a><a class="code" href="group__irplib__cat.html#ga8dd2b5e6b7bc4a7ea3f2b275882aa200">00075</a> (<span class="keyword">const</span> cpl_frame *  master_index,
+<a name="l00076"></a>00076  <span class="keywordtype">char</span>            ** catpath,
+<a name="l00077"></a>00077  <span class="keywordtype">char</span>            ** catname)
+<a name="l00078"></a>00078 {
+<a name="l00079"></a>00079     cpl_propertylist * p;
+<a name="l00080"></a>00080     <span class="keyword">const</span> <span class="keywordtype">char</span>       * unk = <span class="stringliteral">"unknown"</span>;
+<a name="l00081"></a>00081     <span class="keywordtype">char</span>             * fname;
+<a name="l00082"></a>00082     <span class="keywordtype">int</span>                status = CPL_ERROR_NONE;
+<a name="l00083"></a>00083 
+<a name="l00084"></a>00084     <span class="comment">/* Initialise a few things */</span>
+<a name="l00085"></a>00085     *catpath = NULL;
+<a name="l00086"></a>00086     *catname = NULL;
+<a name="l00087"></a>00087 
+<a name="l00088"></a>00088     <span class="comment">/* First get the full path to the index file and make sure it exists */</span>
+<a name="l00089"></a>00089     fname = cpl_strdup(cpl_frame_get_filename(master_index));
+<a name="l00090"></a>00090     <span class="keywordflow">if</span> (access((<span class="keyword">const</span> <span class="keywordtype">char</span> *)fname,R_OK) != 0)
+<a name="l00091"></a>00091     {
+<a name="l00092"></a>00092          cpl_msg_error(__func__,<span class="stringliteral">"Can't access index file %s"</span>,fname);
+<a name="l00093"></a>00093          cpl_free(fname);
+<a name="l00094"></a>00094          <span class="keywordflow">return</span> CPL_ERROR_FILE_IO;
+<a name="l00095"></a>00095     }
+<a name="l00096"></a>00096     *catpath = cpl_strdup(dirname(fname));
+<a name="l00097"></a>00097 
+<a name="l00098"></a>00098     <span class="comment">/* Try to load the propertylist. If it is not possible signal a fatal</span>
+<a name="l00099"></a>00099 <span class="comment">       error since this probably means the whole file is messed up */</span>
+<a name="l00100"></a>00100     <span class="keywordflow">if</span> ((p = cpl_propertylist_load(cpl_frame_get_filename(master_index),0)) == NULL)
+<a name="l00101"></a>00101     {
+<a name="l00102"></a>00102         cpl_msg_error(__func__,<span class="stringliteral">"Can't load index file header %s"</span>,fname);
+<a name="l00103"></a>00103         cpl_free(*catpath);
+<a name="l00104"></a>00104         cpl_free(fname);
+<a name="l00105"></a>00105         <span class="keywordflow">return</span> CPL_ERROR_FILE_IO;
+<a name="l00106"></a>00106     }
+<a name="l00107"></a>00107 
+<a name="l00108"></a>00108     <span class="comment">/* If there is a catalogue name in the header then send it back. If there</span>
+<a name="l00109"></a>00109 <span class="comment">       isn't then give a default name and send a warning */</span>
+<a name="l00110"></a>00110     <span class="keywordflow">if</span> (cpl_propertylist_has(p,<span class="stringliteral">"CATNAME"</span>))
+<a name="l00111"></a>00111     {
+<a name="l00112"></a>00112         *catname = cpl_strdup(cpl_propertylist_get_string(p,<span class="stringliteral">"CATNAME"</span>));
+<a name="l00113"></a>00113         status = CPL_ERROR_NONE;
+<a name="l00114"></a>00114     } <span class="keywordflow">else</span> {
+<a name="l00115"></a>00115         *catname = cpl_strdup(unk);
+<a name="l00116"></a>00116         cpl_msg_warning(__func__,<span class="stringliteral">"Property CATNAME not in index file header %s"</span>,
+<a name="l00117"></a>00117                         fname);
+<a name="l00118"></a>00118     }
+<a name="l00119"></a>00119 
+<a name="l00120"></a>00120     <span class="comment">/* Free and return */</span>
+<a name="l00121"></a>00121     cpl_free(fname);
+<a name="l00122"></a>00122     cpl_propertylist_delete(p);
+<a name="l00123"></a>00123     <span class="keywordflow">return</span>(status);
+<a name="l00124"></a>00124 }
+<a name="l00125"></a>00125 
+<a name="l00126"></a>00126 
+<a name="l00127"></a>00127 
+<a name="l00128"></a>00128 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00151"></a>00151 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00152"></a>00152 
+<a name="l00153"></a>00153 cpl_error_code <a class="code" href="group__irplib__cat.html#ga2289fa88ec0498a2930291b1d51a46af" title="Get coverage in ra, dec of a frame.">irplib_cat_get_image_limits</a>
+<a name="l00154"></a><a class="code" href="group__irplib__cat.html#ga2289fa88ec0498a2930291b1d51a46af">00154</a> (<span class="keyword">const</span> cpl_wcs    * wcs,
+<a name="l00155"></a>00155  <span class="keywordtype">float</span>              ext_search,
+<a name="l00156"></a>00156  <span class="keywordtype">double</span>           * ra1,
+<a name="l00157"></a>00157  <span class="keywordtype">double</span>           * ra2,
+<a name="l00158"></a>00158  <span class="keywordtype">double</span>           * dec1,
+<a name="l00159"></a>00159  <span class="keywordtype">double</span>           * dec2)
+<a name="l00160"></a>00160 {
+<a name="l00161"></a>00161     <span class="keywordtype">double</span>            ra;
+<a name="l00162"></a>00162     <span class="keywordtype">double</span>            dec;
+<a name="l00163"></a>00163     <span class="keywordtype">double</span>            x;
+<a name="l00164"></a>00164     <span class="keywordtype">double</span>            y;
+<a name="l00165"></a>00165     <span class="keywordtype">double</span>            dra;
+<a name="l00166"></a>00166     <span class="keywordtype">double</span>            ddec;
+<a name="l00167"></a>00167     <span class="keywordtype">double</span>            min_4q;
+<a name="l00168"></a>00168     <span class="keywordtype">double</span>            max_1q;
+<a name="l00169"></a>00169     <span class="keywordtype">int</span>               first_quad;
+<a name="l00170"></a>00170     <span class="keywordtype">int</span>               fourth_quad;
+<a name="l00171"></a>00171     <span class="keyword">const</span> <span class="keywordtype">int</span>       * naxes;
+<a name="l00172"></a>00172     <span class="keywordtype">long</span>              i;
+<a name="l00173"></a>00173     <span class="keywordtype">long</span>              j;
+<a name="l00174"></a>00174     <span class="keyword">const</span> cpl_array * a;
+<a name="l00175"></a>00175 
+<a name="l00176"></a>00176     <span class="comment">/* Initialise these in case of failure later*/</span>
+<a name="l00177"></a>00177     *ra1 = 0.0;
+<a name="l00178"></a>00178     *ra2 = 0.0;
+<a name="l00179"></a>00179     *dec1 = 0.0;
+<a name="l00180"></a>00180     *dec2 = 0.0;
+<a name="l00181"></a>00181 
+<a name="l00182"></a>00182     <span class="comment">/* Grab the WCS info from the property list */</span>
+<a name="l00183"></a>00183     <span class="keywordflow">if</span> (wcs == NULL)
+<a name="l00184"></a>00184         <span class="keywordflow">return</span> CPL_ERROR_DATA_NOT_FOUND;
+<a name="l00185"></a>00185 
+<a name="l00186"></a>00186     <span class="comment">/* Get the size of the data array */</span>
+<a name="l00187"></a>00187 
+<a name="l00188"></a>00188     a = cpl_wcs_get_image_dims(wcs);
+<a name="l00189"></a>00189     <span class="keywordflow">if</span>(a == NULL)
+<a name="l00190"></a>00190         <span class="keywordflow">return</span> CPL_ERROR_ILLEGAL_INPUT;
+<a name="l00191"></a>00191     naxes = cpl_array_get_data_int_const(a);
+<a name="l00192"></a>00192 
+<a name="l00193"></a>00193     <span class="comment">/* Find the RA and Dec limits of the image */</span>
+<a name="l00194"></a>00194 
+<a name="l00195"></a>00195     *ra1 = 370.0;
+<a name="l00196"></a>00196     *ra2 = -370.0;
+<a name="l00197"></a>00197     *dec1 = 95.0;
+<a name="l00198"></a>00198     *dec2 = -95.0;
+<a name="l00199"></a>00199     first_quad = 0;
+<a name="l00200"></a>00200     fourth_quad = 0;
+<a name="l00201"></a>00201     min_4q = 370.0;
+<a name="l00202"></a>00202     max_1q = 0.0;
+<a name="l00203"></a>00203     <span class="keywordflow">for</span> (j = 1; j < naxes[1]; j += 10) {
+<a name="l00204"></a>00204         y = (double)j;
+<a name="l00205"></a>00205         <span class="keywordflow">for</span> (i = 1; i < naxes[0]; i += 10) {
+<a name="l00206"></a>00206             x = (double)i;
+<a name="l00207"></a>00207             irplib_wcs_xytoradec(wcs,x,y,&ra,&dec);
+<a name="l00208"></a>00208             <span class="keywordflow">if</span> (ra >= 0.0 && ra <= 90.0) {
+<a name="l00209"></a>00209                 first_quad = 1;
+<a name="l00210"></a>00210                 <span class="keywordflow">if</span>(ra > max_1q)
+<a name="l00211"></a>00211                     max_1q = ra;
+<a name="l00212"></a>00212             } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (ra >= 270.0 && ra <= 360.0) {
+<a name="l00213"></a>00213                 fourth_quad = 1;
+<a name="l00214"></a>00214                 <span class="keywordflow">if</span>(ra - 360.0 < min_4q)
+<a name="l00215"></a>00215                     min_4q = ra - 360.0;
+<a name="l00216"></a>00216             }
+<a name="l00217"></a>00217             <span class="keywordflow">if</span>(ra < *ra1)
+<a name="l00218"></a>00218                 *ra1 = ra;
+<a name="l00219"></a>00219             <span class="keywordflow">if</span>(ra > *ra2)
+<a name="l00220"></a>00220                 *ra2 = ra;
+<a name="l00221"></a>00221             <span class="keywordflow">if</span>(dec < *dec1)
+<a name="l00222"></a>00222                 *dec1 = dec;
+<a name="l00223"></a>00223             <span class="keywordflow">if</span>(dec > *dec2)
+<a name="l00224"></a>00224                 *dec2 = dec;
+<a name="l00225"></a>00225         }
+<a name="l00226"></a>00226     }
+<a name="l00227"></a>00227 
+<a name="l00228"></a>00228     <span class="comment">/* Now have a look to see if you had RA values in both the first and</span>
+<a name="l00229"></a>00229 <span class="comment">       fourth quadrants.  If you have, then make the minimum RA a negative</span>
+<a name="l00230"></a>00230 <span class="comment">       value.  This will be the signal to the caller that you have the</span>
+<a name="l00231"></a>00231 <span class="comment">       wraparound... */</span>
+<a name="l00232"></a>00232 
+<a name="l00233"></a>00233     <span class="keywordflow">if</span> (first_quad && fourth_quad) {
+<a name="l00234"></a>00234         *ra1 = min_4q;
+<a name="l00235"></a>00235         *ra2 = max_1q;
+<a name="l00236"></a>00236     }
+<a name="l00237"></a>00237 
+<a name="l00238"></a>00238     <span class="comment">/* Pad out search a bit */</span>
+<a name="l00239"></a>00239     <span class="keywordflow">if</span> (ext_search)
+<a name="l00240"></a>00240     {
+<a name="l00241"></a>00241         dra = 0.5*ext_search*(*ra2 - *ra1);
+<a name="l00242"></a>00242         *ra1 -= dra;
+<a name="l00243"></a>00243         *ra2 += dra;
+<a name="l00244"></a>00244         ddec = 0.5*ext_search*(*dec2 - *dec1);
+<a name="l00245"></a>00245         *dec1 -= ddec;
+<a name="l00246"></a>00246         *dec2 += ddec;
+<a name="l00247"></a>00247     }
+<a name="l00248"></a>00248 
+<a name="l00249"></a>00249     <span class="comment">/* Exit */</span>
+<a name="l00250"></a>00250     <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l00251"></a>00251 }
+<a name="l00252"></a>00252 
+<a name="l00253"></a>00253 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00277"></a>00277 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00278"></a>00278 
+<a name="l00279"></a>00279 cpl_table *  <a class="code" href="group__irplib__cat.html#ga7fdafd757d33d4096270027912a89cf6" title="Extract standards from the 2mass catalogue.">irplib_2mass_extract</a>
+<a name="l00280"></a><a class="code" href="group__irplib__cat.html#ga7fdafd757d33d4096270027912a89cf6">00280</a> (<span class="keywordtype">char</span> *path,
+<a name="l00281"></a>00281  <span class="keywordtype">float</span> ramin,
+<a name="l00282"></a>00282  <span class="keywordtype">float</span> ramax,
+<a name="l00283"></a>00283  <span class="keywordtype">float</span> decmin,
+<a name="l00284"></a>00284  <span class="keywordtype">float</span> decmax)
+<a name="l00285"></a>00285 {
+<a name="l00286"></a>00286     cpl_table *t,*s;
+<a name="l00287"></a>00287     cpl_table *out;
+<a name="l00288"></a>00288     <span class="keywordtype">int</span> i,nrows,start,finish,first_index,last_index,irow,init,j;
+<a name="l00289"></a>00289     <span class="keywordtype">int</span> first_index_ra,last_index_ra,wrap,iwrap;
+<a name="l00290"></a>00290     <span class="keywordtype">float</span> dectest,ratest,ramin_wrap,ramax_wrap;
+<a name="l00291"></a>00291     <span class="keywordtype">char</span> fullname[FILENAME_SZBUF];
+<a name="l00292"></a>00292     cpl_array *a;
+<a name="l00293"></a>00293     <span class="keyword">const</span> <span class="keywordtype">char</span> *deccol[] = {<span class="stringliteral">"Dec"</span>};
+<a name="l00294"></a>00294     cpl_propertylist *p;
+<a name="l00295"></a>00295 
+<a name="l00296"></a>00296     <span class="comment">/* Create an output table */</span>
+<a name="l00297"></a>00297 
+<a name="l00298"></a>00298     out = cpl_table_new(0);
+<a name="l00299"></a>00299     init = 1;
+<a name="l00300"></a>00300 
+<a name="l00301"></a>00301     <span class="comment">/* Create a cpl array */</span>
+<a name="l00302"></a>00302 
+<a name="l00303"></a>00303     <span class="comment">/* deccol will NOT be modified */</span>
+<a name="l00304"></a>00304     a = cpl_array_wrap_string((<span class="keywordtype">char</span> **)deccol,1);
+<a name="l00305"></a>00305 
+<a name="l00306"></a>00306     <span class="comment">/* Is there a wrap around problem? */</span>
+<a name="l00307"></a>00307 
+<a name="l00308"></a>00308     wrap = (ramin < 0.0 && ramax > 0.0) ? 2 : 1;
+<a name="l00309"></a>00309 
+<a name="l00310"></a>00310     <span class="comment">/* Loop for each query. If there is a wrap around problem then we need 2</span>
+<a name="l00311"></a>00311 <span class="comment">       queries. If not, then we only need 1 */</span>
+<a name="l00312"></a>00312 
+<a name="l00313"></a>00313     <span class="keywordflow">for</span> (iwrap = 0; iwrap < wrap; iwrap++) {
+<a name="l00314"></a>00314         <span class="keywordflow">if</span> (wrap == 2) {
+<a name="l00315"></a>00315             <span class="keywordflow">if</span> (iwrap == 0) {
+<a name="l00316"></a>00316                 ramin_wrap = ramin + 360.0;
+<a name="l00317"></a>00317                 ramax_wrap = 360.0;
+<a name="l00318"></a>00318             } <span class="keywordflow">else</span> {
+<a name="l00319"></a>00319                 ramin_wrap = 0.000001;
+<a name="l00320"></a>00320                 ramax_wrap = ramax;
+<a name="l00321"></a>00321             }
+<a name="l00322"></a>00322         } <span class="keywordflow">else</span> {
+<a name="l00323"></a>00323             ramin_wrap = ramin;
+<a name="l00324"></a>00324             ramax_wrap = ramax;
+<a name="l00325"></a>00325         }
+<a name="l00326"></a>00326 
+<a name="l00327"></a>00327         <span class="comment">/* Find out where in the index to look */</span>
+<a name="l00328"></a>00328 
+<a name="l00329"></a>00329         first_index_ra = (int)ramin_wrap;
+<a name="l00330"></a>00330         last_index_ra = (int)ramax_wrap;
+<a name="l00331"></a>00331         <span class="keywordflow">if</span>(last_index_ra > 359)
+<a name="l00332"></a>00332             last_index_ra = 359;
+<a name="l00333"></a>00333 
+<a name="l00334"></a>00334         <span class="comment">/* Look at the min and max RA and decide which files need to be</span>
+<a name="l00335"></a>00335 <span class="comment">           opened. */</span>
+<a name="l00336"></a>00336 
+<a name="l00337"></a>00337         <span class="keywordflow">for</span> (i = first_index_ra; i <= last_index_ra; i++)
+<a name="l00338"></a>00338         {
+<a name="l00339"></a>00339 
+<a name="l00340"></a>00340             <span class="comment">/* Ok, we've found one that needs opening. Read the file with</span>
+<a name="l00341"></a>00341 <span class="comment">               the relevant CPL call */</span>
+<a name="l00342"></a>00342 
+<a name="l00343"></a>00343             (void)snprintf(fullname,FILENAME_SZBUF,<span class="stringliteral">"%s/npsc%03d.fits"</span>,path,i);
+<a name="l00344"></a>00344 
+<a name="l00345"></a>00345             <span class="comment">/* Read the propertylist so that you know how many rows there</span>
+<a name="l00346"></a>00346 <span class="comment">               are in the table */</span>
+<a name="l00347"></a>00347 
+<a name="l00348"></a>00348             p = cpl_propertylist_load(fullname,1);
+<a name="l00349"></a>00349             <span class="keywordflow">if</span> (p == NULL)
+<a name="l00350"></a>00350             {
+<a name="l00351"></a>00351                 cpl_error_set_message_macro(__func__,CPL_ERROR_DATA_NOT_FOUND,
+<a name="l00352"></a>00352                         __FILE__, __LINE__, <span class="stringliteral">"2mass file %s missing"</span>,fullname);
+<a name="l00353"></a>00353                 cpl_table_delete(out);
+<a name="l00354"></a>00354                 cpl_array_unwrap(a);
+<a name="l00355"></a>00355                 <span class="keywordflow">return</span>(NULL);
+<a name="l00356"></a>00356             }
+<a name="l00357"></a>00357             nrows = cpl_propertylist_get_int(p, <span class="stringliteral">"NAXIS2"</span>);
+<a name="l00358"></a>00358             cpl_propertylist_delete(p);
+<a name="l00359"></a>00359 
+<a name="l00360"></a>00360             <span class="comment">/* Load various rows until you find the Dec range that you</span>
+<a name="l00361"></a>00361 <span class="comment">             have specified. First the minimum Dec */</span>
+<a name="l00362"></a>00362 
+<a name="l00363"></a>00363             start = 0;
+<a name="l00364"></a>00364             finish = nrows;
+<a name="l00365"></a>00365             first_index = nrows/2;
+<a name="l00366"></a>00366             <span class="keywordflow">while</span> (finish - start >= 2)
+<a name="l00367"></a>00367             {
+<a name="l00368"></a>00368                 t = cpl_table_load_window(fullname, 1, 0, a, first_index, 1);
+<a name="l00369"></a>00369                 dectest = cpl_table_get_float(t, <span class="stringliteral">"Dec"</span>, 0, NULL);
+<a name="l00370"></a>00370                 cpl_table_delete(t);
+<a name="l00371"></a>00371                 <span class="keywordflow">if</span> (dectest < decmin)
+<a name="l00372"></a>00372                 {
+<a name="l00373"></a>00373                     start = first_index;
+<a name="l00374"></a>00374                     first_index = (first_index + finish)/2;
+<a name="l00375"></a>00375                 }
+<a name="l00376"></a>00376                 <span class="keywordflow">else</span>
+<a name="l00377"></a>00377                 {
+<a name="l00378"></a>00378                     finish = first_index;
+<a name="l00379"></a>00379                     first_index = (first_index + start)/2;
+<a name="l00380"></a>00380                 }
+<a name="l00381"></a>00381             }
+<a name="l00382"></a>00382 
+<a name="l00383"></a>00383             <span class="comment">/* Load various rows until you find the Dec range that you</span>
+<a name="l00384"></a>00384 <span class="comment">             have specified. Now the maximum Dec */</span>
+<a name="l00385"></a>00385 
+<a name="l00386"></a>00386             start = first_index;
+<a name="l00387"></a>00387             finish = nrows;
+<a name="l00388"></a>00388             last_index = start + (finish - start)/2;
+<a name="l00389"></a>00389             <span class="keywordflow">while</span> (finish - start >= 2)
+<a name="l00390"></a>00390             {
+<a name="l00391"></a>00391                 t = cpl_table_load_window(fullname, 1, 0, a, last_index, 1);
+<a name="l00392"></a>00392                 dectest = cpl_table_get_float(t, <span class="stringliteral">"Dec"</span>, 0, NULL);
+<a name="l00393"></a>00393                 cpl_table_delete(t);
+<a name="l00394"></a>00394                 <span class="keywordflow">if</span> (dectest < decmax)
+<a name="l00395"></a>00395                 {
+<a name="l00396"></a>00396                     start = last_index;
+<a name="l00397"></a>00397                     last_index = (last_index + finish)/2;
+<a name="l00398"></a>00398                 }
+<a name="l00399"></a>00399                 <span class="keywordflow">else</span>
+<a name="l00400"></a>00400                 {
+<a name="l00401"></a>00401                     finish = last_index;
+<a name="l00402"></a>00402                     last_index = (last_index + start)/2;
+<a name="l00403"></a>00403                 }
+<a name="l00404"></a>00404             }
+<a name="l00405"></a>00405             <span class="keywordflow">if</span> (last_index < first_index)
+<a name="l00406"></a>00406                 last_index = first_index;
+<a name="l00407"></a>00407 
+<a name="l00408"></a>00408             <span class="comment">/* Ok now now load all the rows in the relevant dec limits */</span>
+<a name="l00409"></a>00409 
+<a name="l00410"></a>00410             nrows = last_index - first_index + 1;
+<a name="l00411"></a>00411             <span class="keywordflow">if</span> ((t = cpl_table_load_window(fullname, 1, 0, NULL, first_index,
+<a name="l00412"></a>00412                                            nrows)) == NULL)
+<a name="l00413"></a>00413             {
+<a name="l00414"></a>00414                 cpl_error_set_message_macro(__func__,CPL_ERROR_DATA_NOT_FOUND,
+<a name="l00415"></a>00415                         __FILE__, __LINE__, <span class="stringliteral">"Error in subset of 2mass file %s "</span>,
+<a name="l00416"></a>00416                         fullname);
+<a name="l00417"></a>00417                 cpl_table_delete(out);
+<a name="l00418"></a>00418                 cpl_array_unwrap(a);
+<a name="l00419"></a>00419                 <span class="keywordflow">return</span> (NULL);
+<a name="l00420"></a>00420             }
+<a name="l00421"></a>00421             cpl_table_unselect_all(t);
+<a name="l00422"></a>00422 
+<a name="l00423"></a>00423             <span class="comment">/* Right, we now know what range of rows to search. Go through</span>
+<a name="l00424"></a>00424 <span class="comment">             these and pick the ones that are in the correct range of RA.</span>
+<a name="l00425"></a>00425 <span class="comment">             If a row qualifies, then 'select' it. */</span>
+<a name="l00426"></a>00426 
+<a name="l00427"></a>00427             <span class="keywordflow">for</span> (j = 0; j < nrows; j++)
+<a name="l00428"></a>00428             {
+<a name="l00429"></a>00429                 ratest = cpl_table_get_float(t, <span class="stringliteral">"RA"</span>, j, NULL);
+<a name="l00430"></a>00430                 <span class="keywordflow">if</span> (cpl_error_get_code() != CPL_ERROR_NONE)
+<a name="l00431"></a>00431                 {
+<a name="l00432"></a>00432                     cpl_error_set_message_macro(__func__,CPL_ERROR_DATA_NOT_FOUND,
+<a name="l00433"></a>00433                             __FILE__, __LINE__, <span class="stringliteral">"No RA column in 2mass file %s"</span>,
+<a name="l00434"></a>00434                             fullname);
+<a name="l00435"></a>00435                     cpl_table_delete(t);
+<a name="l00436"></a>00436                     cpl_array_unwrap(a);
+<a name="l00437"></a>00437                     cpl_table_delete(out);
+<a name="l00438"></a>00438                     <span class="keywordflow">return</span> (NULL);
+<a name="l00439"></a>00439                 }
+<a name="l00440"></a>00440                 <span class="keywordflow">if</span> (ratest >= ramin_wrap && ratest <= ramax_wrap)
+<a name="l00441"></a>00441                     cpl_table_select_row(t, j);
+<a name="l00442"></a>00442             }
+<a name="l00443"></a>00443 
+<a name="l00444"></a>00444             <span class="comment">/* Extract the rows that have been selected now and append them</span>
+<a name="l00445"></a>00445 <span class="comment">             onto the output table */</span>
+<a name="l00446"></a>00446 
+<a name="l00447"></a>00447             s = cpl_table_extract_selected(t);
+<a name="l00448"></a>00448             <span class="keywordflow">if</span> (init == 1)
+<a name="l00449"></a>00449             {
+<a name="l00450"></a>00450                 cpl_table_copy_structure(out, t);
+<a name="l00451"></a>00451                 init = 0;
+<a name="l00452"></a>00452             }
+<a name="l00453"></a>00453             irow = cpl_table_get_nrow(out) + 1;
+<a name="l00454"></a>00454             cpl_table_insert(out, s, irow);
+<a name="l00455"></a>00455 
+<a name="l00456"></a>00456             <span class="comment">/* Tidy up */</span>
+<a name="l00457"></a>00457 
+<a name="l00458"></a>00458             cpl_table_delete(t);
+<a name="l00459"></a>00459             cpl_table_delete(s);
+<a name="l00460"></a>00460         }
+<a name="l00461"></a>00461     }
+<a name="l00462"></a>00462 
+<a name="l00463"></a>00463     <span class="comment">/* Ok, now just return the table and get out of here */</span>
+<a name="l00464"></a>00464 
+<a name="l00465"></a>00465     cpl_array_unwrap(a);
+<a name="l00466"></a>00466     <span class="keywordflow">return</span>(out);
+<a name="l00467"></a>00467 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/irplib__cat_8h_source.html b/html/irplib__cat_8h_source.html
new file mode 100644
index 0000000..35efbcc
--- /dev/null
+++ b/html/irplib__cat_8h_source.html
@@ -0,0 +1,73 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: irplib_cat.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>irplib_cat.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: irplib_cat.h,v 1.5 2009/12/16 14:49:52 cgarcia Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the irplib package</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: cgarcia $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2009/12/16 14:49:52 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.5 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifndef IRPLIB_CAT_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#define IRPLIB_CAT_H</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span>
+<a name="l00031"></a>00031 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00032"></a>00032 <span class="comment">                                   Includes</span>
+<a name="l00033"></a>00033 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00034"></a>00034 
+<a name="l00035"></a>00035 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="keywordtype">int</span> <a class="code" href="group__irplib__cat.html#ga8dd2b5e6b7bc4a7ea3f2b275882aa200" title="Find the name of the standard catalogue being used and its location.">irplib_2mass_get_catpars</a>
+<a name="l00038"></a>00038 (<span class="keyword">const</span> cpl_frame *master_index,
+<a name="l00039"></a>00039  <span class="keywordtype">char</span>            **catpath,
+<a name="l00040"></a>00040  <span class="keywordtype">char</span>            **catname);
+<a name="l00041"></a>00041 
+<a name="l00042"></a>00042 cpl_table *  <a class="code" href="group__irplib__cat.html#ga7fdafd757d33d4096270027912a89cf6" title="Extract standards from the 2mass catalogue.">irplib_2mass_extract</a>
+<a name="l00043"></a>00043 (<span class="keywordtype">char</span> *path,
+<a name="l00044"></a>00044  <span class="keywordtype">float</span> ramin,
+<a name="l00045"></a>00045  <span class="keywordtype">float</span> ramax,
+<a name="l00046"></a>00046  <span class="keywordtype">float</span> decmin,
+<a name="l00047"></a>00047  <span class="keywordtype">float</span> decmax);
+<a name="l00048"></a>00048 
+<a name="l00049"></a>00049 cpl_error_code <a class="code" href="group__irplib__cat.html#ga2289fa88ec0498a2930291b1d51a46af" title="Get coverage in ra, dec of a frame.">irplib_cat_get_image_limits</a>
+<a name="l00050"></a>00050 (<span class="keyword">const</span> cpl_wcs    * wcs,
+<a name="l00051"></a>00051  <span class="keywordtype">float</span>              ext_search,
+<a name="l00052"></a>00052  <span class="keywordtype">double</span>           * ra1,
+<a name="l00053"></a>00053  <span class="keywordtype">double</span>           * ra2,
+<a name="l00054"></a>00054  <span class="keywordtype">double</span>           * dec1,
+<a name="l00055"></a>00055  <span class="keywordtype">double</span>           * dec2);
+<a name="l00056"></a>00056 
+<a name="l00057"></a>00057 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/irplib__distortion_8c_source.html b/html/irplib__distortion_8c_source.html
new file mode 100644
index 0000000..8c501fe
--- /dev/null
+++ b/html/irplib__distortion_8c_source.html
@@ -0,0 +1,1267 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: irplib_distortion.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>irplib_distortion.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: irplib_distortion.c,v 1.51 2012/02/03 15:08:14 llundin Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the irplib package</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: llundin $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2012/02/03 15:08:14 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.51 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span>
+<a name="l00032"></a>00032 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                                   Includes</span>
+<a name="l00034"></a>00034 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 
+<a name="l00036"></a>00036 <span class="comment">/* TEMPORARY SUPPORT OF CPL 5.x */</span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00038"></a>00038 
+<a name="l00039"></a>00039 <span class="preprocessor">#ifndef CPL_SIZE_FORMAT</span>
+<a name="l00040"></a>00040 <span class="preprocessor"></span><span class="preprocessor">#define CPL_SIZE_FORMAT "d"</span>
+<a name="l00041"></a>00041 <span class="preprocessor"></span><span class="preprocessor">#define cpl_size int</span>
+<a name="l00042"></a>00042 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
+<a name="l00043"></a>00043 <span class="preprocessor"></span>
+<a name="l00044"></a>00044 <span class="preprocessor">#if defined CPL_VERSION_CODE && CPL_VERSION_CODE <= CPL_VERSION(5, 92, 0)</span>
+<a name="l00045"></a>00045 <span class="preprocessor"></span><span class="preprocessor">#define cpl_apertures_get_pos_x cpl_apertures_get_max_x</span>
+<a name="l00046"></a>00046 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
+<a name="l00047"></a>00047 <span class="preprocessor"></span>
+<a name="l00048"></a>00048 <span class="comment">/* END TEMPORARY SUPPORT OF CPL 5.x */</span>
+<a name="l00049"></a>00049 
+<a name="l00050"></a>00050 <span class="preprocessor">#include "irplib_distortion.h"</span>
+<a name="l00051"></a>00051 
+<a name="l00052"></a>00052 <span class="preprocessor">#include "irplib_flat.h"</span>
+<a name="l00053"></a>00053 <span class="preprocessor">#include "irplib_utils.h"</span>
+<a name="l00054"></a>00054 <span class="preprocessor">#include "irplib_polynomial.h"</span>
+<a name="l00055"></a>00055 
+<a name="l00056"></a>00056 <span class="preprocessor">#include <math.h></span>
+<a name="l00057"></a>00057 <span class="preprocessor">#include <float.h></span>
+<a name="l00058"></a>00058 
+<a name="l00059"></a>00059 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00060"></a>00060 <span class="comment">                                   Define</span>
+<a name="l00061"></a>00061 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00062"></a>00062 
+<a name="l00063"></a>00063 <span class="preprocessor">#define IRPLIB_MAX(A,B) ((A) > (B) ? (A) : (B))</span>
+<a name="l00064"></a>00064 <span class="preprocessor"></span><span class="preprocessor">#define IRPLIB_MIN(A,B) ((A) < (B) ? (A) : (B))</span>
+<a name="l00065"></a>00065 <span class="preprocessor"></span>
+<a name="l00066"></a>00066 <span class="preprocessor">#define ARC_MINGOODPIX      100</span>
+<a name="l00067"></a>00067 <span class="preprocessor"></span><span class="preprocessor">#define ARC_MINARCLENFACT   2.0</span>
+<a name="l00068"></a>00068 <span class="preprocessor"></span><span class="preprocessor">#define ARC_MINNBARCS       4</span>
+<a name="l00069"></a>00069 <span class="preprocessor"></span><span class="preprocessor">#define ARC_RANGE_FACT      3.0</span>
+<a name="l00070"></a>00070 <span class="preprocessor"></span><span class="preprocessor">#define ARC_WINDOWSIZE      32</span>
+<a name="l00071"></a>00071 <span class="preprocessor"></span>
+<a name="l00072"></a>00072 <span class="preprocessor">#define TRESH_MEDIAN_MIN    0.0</span>
+<a name="l00073"></a>00073 <span class="preprocessor"></span><span class="preprocessor">#define TRESH_SIGMA_MAX     200.0</span>
+<a name="l00074"></a>00074 <span class="preprocessor"></span>
+<a name="l00075"></a>00075 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00079"></a>00079 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00080"></a>00080 
+<a name="l00081"></a>00081 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00082"></a>00082 <span class="comment">                                Functions prototypes</span>
+<a name="l00083"></a>00083 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00084"></a>00084 
+<a name="l00085"></a>00085 <span class="keyword">static</span> cpl_apertures * irplib_distortion_detect_arcs(cpl_image *,
+<a name="l00086"></a>00086         cpl_image **, <span class="keywordtype">int</span>, <span class="keywordtype">int</span>, <span class="keywordtype">double</span>, <span class="keywordtype">int</span>, <span class="keywordtype">int</span>, <span class="keywordtype">int</span>, <span class="keywordtype">int</span>);
+<a name="l00087"></a>00087 <span class="keyword">static</span> cpl_error_code irplib_distortion_fill_border(cpl_image *, <span class="keywordtype">int</span>, <span class="keywordtype">int</span>,
+<a name="l00088"></a>00088                                                     <span class="keywordtype">int</span>, <span class="keywordtype">int</span>, <span class="keywordtype">double</span>);
+<a name="l00089"></a>00089 <span class="keyword">static</span> <span class="keywordtype">int</span> irplib_distortion_threshold1d(cpl_image *, <span class="keywordtype">double</span>, cpl_image *, 
+<a name="l00090"></a>00090         <span class="keywordtype">double</span>);
+<a name="l00091"></a>00091 <span class="keyword">static</span> cpl_error_code irplib_distortion_purge_arcs(cpl_apertures **, cpl_image *,
+<a name="l00092"></a>00092                                                    <span class="keyword">const</span> cpl_image *, <span class="keywordtype">int</span>, <span class="keywordtype">int</span>,
+<a name="l00093"></a>00093                                                    <span class="keywordtype">double</span>);
+<a name="l00094"></a>00094 <span class="keyword">static</span> cpl_error_code irplib_distortion_fill_arc_positions(cpl_bivector *,
+<a name="l00095"></a>00095                                                           cpl_vector *,
+<a name="l00096"></a>00096                                                           <span class="keyword">const</span> cpl_image *,
+<a name="l00097"></a>00097                                                           <span class="keyword">const</span> cpl_image *,
+<a name="l00098"></a>00098                                                           <span class="keyword">const</span> cpl_apertures *);
+<a name="l00099"></a>00099 
+<a name="l00100"></a>00100 <span class="keyword">static</span> <span class="keywordtype">double</span> irplib_distortion_get_row_centroid(<span class="keyword">const</span> cpl_image *,
+<a name="l00101"></a>00101                                                  <span class="keyword">const</span> cpl_image *, <span class="keywordtype">int</span>, <span class="keywordtype">int</span>);
+<a name="l00102"></a>00102 
+<a name="l00103"></a>00103 <span class="keyword">static</span> <span class="keywordtype">int</span> irplib_distortion_sub_hor_lowpass(cpl_image *, <span class="keywordtype">int</span>);
+<a name="l00104"></a>00104 <span class="keyword">static</span> cpl_image * irplib_distortion_remove_ramp(<span class="keyword">const</span> cpl_image *);
+<a name="l00105"></a>00105 
+<a name="l00106"></a>00106 <span class="keyword">static</span> cpl_error_code irplib_image_filter_background_line(cpl_image *,
+<a name="l00107"></a>00107         <span class="keyword">const</span> cpl_image *, <span class="keywordtype">int</span>, cpl_boolean) ;
+<a name="l00108"></a>00108 
+<a name="l00109"></a>00109 <span class="keyword">static</span> cpl_error_code irplib_polynomial_fit_2d(cpl_polynomial *,
+<a name="l00110"></a>00110                                                <span class="keyword">const</span> cpl_bivector *,
+<a name="l00111"></a>00111                                                <span class="keyword">const</span> cpl_vector *, <span class="keywordtype">int</span>,
+<a name="l00112"></a>00112                                                <span class="keywordtype">double</span>, <span class="keywordtype">double</span> *);
+<a name="l00113"></a>00113 
+<a name="l00114"></a>00114 <span class="keyword">static</span> cpl_matrix * irplib_matrix_product_normal_create(<span class="keyword">const</span> cpl_matrix *);
+<a name="l00115"></a>00115 
+<a name="l00116"></a>00116 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00117"></a>00117 <span class="comment">                                Functions code</span>
+<a name="l00118"></a>00118 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00119"></a>00119 
+<a name="l00122"></a>00122 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00151"></a>00151 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00152"></a>00152 cpl_polynomial * irplib_distortion_estimate(
+<a name="l00153"></a>00153         <span class="keyword">const</span> cpl_image *   org,
+<a name="l00154"></a>00154         <span class="keywordtype">int</span>                 xmin,
+<a name="l00155"></a>00155         <span class="keywordtype">int</span>                 ymin,
+<a name="l00156"></a>00156         <span class="keywordtype">int</span>                 xmax,
+<a name="l00157"></a>00157         <span class="keywordtype">int</span>                 ymax,
+<a name="l00158"></a>00158         <span class="keywordtype">int</span>                 auto_ramp_sub,
+<a name="l00159"></a>00159         <span class="keywordtype">int</span>                 arc_sat,
+<a name="l00160"></a>00160         <span class="keywordtype">int</span>                 max_arc_width,
+<a name="l00161"></a>00161         <span class="keywordtype">double</span>              kappa,
+<a name="l00162"></a>00162         <span class="keywordtype">int</span>                 degree,
+<a name="l00163"></a>00163         cpl_apertures   **  arcs)
+<a name="l00164"></a>00164 {
+<a name="l00165"></a>00165     cpl_image      * local_im;
+<a name="l00166"></a>00166     cpl_image      * filtered;
+<a name="l00167"></a>00167     cpl_image      * label_image;
+<a name="l00168"></a>00168     <span class="keywordtype">double</span>           rightmost, leftmost;
+<a name="l00169"></a>00169     cpl_bivector   * grid;
+<a name="l00170"></a>00170     cpl_vector     * values_to_fit;
+<a name="l00171"></a>00171     <span class="keywordtype">int</span>              n_arcs;
+<a name="l00172"></a>00172     cpl_polynomial * poly2d;
+<a name="l00173"></a>00173     <span class="keywordtype">double</span>           mse = 0.0;
+<a name="l00174"></a>00174     <span class="keyword">const</span> <span class="keywordtype">int</span>        nx = cpl_image_get_size_x(org);
+<a name="l00175"></a>00175     <span class="keyword">const</span> <span class="keywordtype">int</span>        ny = cpl_image_get_size_y(org);
+<a name="l00176"></a>00176     <span class="keyword">const</span> <span class="keywordtype">int</span>        min_arc_range = (int)(nx / ARC_RANGE_FACT);
+<a name="l00177"></a>00177     <span class="keywordtype">int</span>              i;
+<a name="l00178"></a>00178 
+<a name="l00179"></a>00179     <span class="comment">/* Check entries */</span>
+<a name="l00180"></a>00180     cpl_ensure(org           != NULL, CPL_ERROR_NULL_INPUT,    NULL);
+<a name="l00181"></a>00181     cpl_ensure(kappa         >= 0.0,  CPL_ERROR_ILLEGAL_INPUT, NULL);
+<a name="l00182"></a>00182     cpl_ensure(max_arc_width > 0,     CPL_ERROR_ILLEGAL_INPUT, NULL);
+<a name="l00183"></a>00183 
+<a name="l00184"></a>00184     <span class="comment">/* The background may vary strongly along the vertical line. */</span>
+<a name="l00185"></a>00185     <span class="comment">/* Detect and rm background with a 1+2*max_arc_width x 1 median filter */</span>
+<a name="l00186"></a>00186 
+<a name="l00187"></a>00187     filtered = cpl_image_new(nx, ny, cpl_image_get_type(org));
+<a name="l00188"></a>00188 
+<a name="l00189"></a>00189     irplib_image_filter_background_line(filtered, org, max_arc_width, CPL_TRUE);
+<a name="l00190"></a>00190 
+<a name="l00191"></a>00191     <span class="keywordflow">if</span> (auto_ramp_sub) {
+<a name="l00192"></a>00192         local_im = irplib_distortion_remove_ramp(filtered);
+<a name="l00193"></a>00193         cpl_image_delete(filtered);
+<a name="l00194"></a>00194     } <span class="keywordflow">else</span> {
+<a name="l00195"></a>00195         local_im = filtered;
+<a name="l00196"></a>00196     }
+<a name="l00197"></a>00197 
+<a name="l00198"></a>00198     cpl_error_ensure(local_im != NULL, cpl_error_get_code(),
+<a name="l00199"></a>00199                      <span class="keywordflow">return</span>(NULL), <span class="stringliteral">"Cannot clean the image"</span>);
+<a name="l00200"></a>00200 
+<a name="l00201"></a>00201     <span class="comment">/* Detect the arcs in the input image */</span>
+<a name="l00202"></a>00202     *arcs = irplib_distortion_detect_arcs(local_im, &label_image, arc_sat,
+<a name="l00203"></a>00203                                           max_arc_width, kappa, xmin, ymin,
+<a name="l00204"></a>00204                                           xmax, ymax);
+<a name="l00205"></a>00205     <span class="keywordflow">if</span> (*arcs == NULL) {
+<a name="l00206"></a>00206         cpl_image_delete(local_im);
+<a name="l00207"></a>00207         cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
+<a name="l00208"></a>00208                               <span class="stringliteral">"Cannot detect the arcs"</span>);
+<a name="l00209"></a>00209         <span class="keywordflow">return</span> NULL;
+<a name="l00210"></a>00210     }
+<a name="l00211"></a>00211     n_arcs = cpl_apertures_get_size(*arcs);
+<a name="l00212"></a>00212     cpl_msg_info(cpl_func, <span class="stringliteral">"%d detected arcs"</span>, n_arcs);
+<a name="l00213"></a>00213 
+<a name="l00214"></a>00214     <span class="comment">/* Check that the arcs are not concentrated in the same zone */</span>
+<a name="l00215"></a>00215     rightmost = leftmost = cpl_apertures_get_pos_x(*arcs, 1);
+<a name="l00216"></a>00216     <span class="keywordflow">for</span> (i=1; i<n_arcs; i++) {
+<a name="l00217"></a>00217         <span class="keywordflow">if</span> (cpl_apertures_get_pos_x(*arcs, i+1) < leftmost)
+<a name="l00218"></a>00218             leftmost = cpl_apertures_get_pos_x(*arcs, i+1);
+<a name="l00219"></a>00219         <span class="keywordflow">if</span> (cpl_apertures_get_pos_x(*arcs, i+1) > rightmost)
+<a name="l00220"></a>00220             rightmost = cpl_apertures_get_pos_x(*arcs, i+1);
+<a name="l00221"></a>00221     }
+<a name="l00222"></a>00222     <span class="keywordflow">if</span> ((<span class="keywordtype">int</span>)(rightmost-leftmost) < min_arc_range) {
+<a name="l00223"></a>00223 <span class="preprocessor">#if defined CPL_HAVE_VA_ARGS && CPL_HAVE_VA_ARGS != 0</span>
+<a name="l00224"></a>00224 <span class="preprocessor"></span>        cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
+<a name="l00225"></a>00225                               <span class="stringliteral">"too narrow range (%g-%g)<%d"</span>,
+<a name="l00226"></a>00226                               rightmost, leftmost, min_arc_range);
+<a name="l00227"></a>00227 <span class="preprocessor">#else</span>
+<a name="l00228"></a>00228 <span class="preprocessor"></span>        cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
+<a name="l00229"></a>00229                               <span class="stringliteral">"too narrow range"</span>);
+<a name="l00230"></a>00230 <span class="preprocessor">#endif</span>
+<a name="l00231"></a>00231 <span class="preprocessor"></span>        cpl_apertures_delete(*arcs);
+<a name="l00232"></a>00232         cpl_image_delete(local_im);
+<a name="l00233"></a>00233         cpl_image_delete(label_image);
+<a name="l00234"></a>00234         *arcs = NULL;
+<a name="l00235"></a>00235         <span class="keywordflow">return</span> NULL;
+<a name="l00236"></a>00236     }
+<a name="l00237"></a>00237 
+<a name="l00238"></a>00238     <span class="comment">/* Create a 2-D deformation grid with detected arcs */</span>
+<a name="l00239"></a>00239     cpl_msg_info(cpl_func, <span class="stringliteral">"Create deformation grid"</span>);
+<a name="l00240"></a>00240     grid = cpl_bivector_new(n_arcs * ny);
+<a name="l00241"></a>00241     values_to_fit = cpl_vector_new(n_arcs * ny);
+<a name="l00242"></a>00242 
+<a name="l00243"></a>00243     <span class="keywordflow">if</span> (irplib_distortion_fill_arc_positions(grid, values_to_fit, local_im,
+<a name="l00244"></a>00244                                             label_image, *arcs)){
+<a name="l00245"></a>00245         cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
+<a name="l00246"></a>00246                               <span class="stringliteral">"cannot get arcs positions"</span>);
+<a name="l00247"></a>00247         cpl_apertures_delete(*arcs);
+<a name="l00248"></a>00248         cpl_image_delete(local_im);
+<a name="l00249"></a>00249         cpl_image_delete(label_image);
+<a name="l00250"></a>00250         *arcs = NULL;
+<a name="l00251"></a>00251         <span class="keywordflow">return</span> NULL;
+<a name="l00252"></a>00252     }
+<a name="l00253"></a>00253     cpl_image_delete(label_image);
+<a name="l00254"></a>00254     cpl_image_delete(local_im);
+<a name="l00255"></a>00255 
+<a name="l00256"></a>00256     <span class="comment">/* Apply the fitting */</span>
+<a name="l00257"></a>00257     poly2d = cpl_polynomial_new(2);
+<a name="l00258"></a>00258     <span class="keywordflow">if</span> (irplib_polynomial_fit_2d(poly2d, grid, values_to_fit, degree,
+<a name="l00259"></a>00259                                  0.5*(ny+1), &mse)) {
+<a name="l00260"></a>00260         cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
+<a name="l00261"></a>00261                               <span class="stringliteral">"cannot apply the 2d fit"</span>);
+<a name="l00262"></a>00262         cpl_bivector_delete(grid);
+<a name="l00263"></a>00263         cpl_vector_delete(values_to_fit);
+<a name="l00264"></a>00264         cpl_apertures_delete(*arcs);
+<a name="l00265"></a>00265         *arcs = NULL;
+<a name="l00266"></a>00266         <span class="keywordflow">return</span> NULL;
+<a name="l00267"></a>00267     }
+<a name="l00268"></a>00268 
+<a name="l00269"></a>00269     cpl_msg_info(cpl_func, 
+<a name="l00270"></a>00270             <span class="stringliteral">"Fitted a %d. degree 2D-polynomial to %"</span>CPL_SIZE_FORMAT<span class="stringliteral">" points "</span>
+<a name="l00271"></a>00271             <span class="stringliteral">"with mean-square error: %g"</span>, degree,
+<a name="l00272"></a>00272             cpl_vector_get_size(values_to_fit), mse);
+<a name="l00273"></a>00273 
+<a name="l00274"></a>00274     <span class="comment">/* Free and return */</span>
+<a name="l00275"></a>00275     cpl_bivector_delete(grid);
+<a name="l00276"></a>00276     cpl_vector_delete(values_to_fit);
+<a name="l00277"></a>00277     <span class="keywordflow">return</span> poly2d;
+<a name="l00278"></a>00278 }
+<a name="l00279"></a>00279 
+<a name="l00282"></a>00282 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00298"></a>00298 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00299"></a>00299 <span class="keyword">static</span> cpl_apertures * irplib_distortion_detect_arcs(
+<a name="l00300"></a>00300         cpl_image *   im,
+<a name="l00301"></a>00301         cpl_image **  label_im,
+<a name="l00302"></a>00302         <span class="keywordtype">int</span>             arc_sat,
+<a name="l00303"></a>00303         <span class="keywordtype">int</span>             max_arc_width,
+<a name="l00304"></a>00304         <span class="keywordtype">double</span>          kappa,
+<a name="l00305"></a>00305         <span class="keywordtype">int</span>             xmin,
+<a name="l00306"></a>00306         <span class="keywordtype">int</span>             ymin,
+<a name="l00307"></a>00307         <span class="keywordtype">int</span>             xmax,
+<a name="l00308"></a>00308         <span class="keywordtype">int</span>             ymax)
+<a name="l00309"></a>00309 {
+<a name="l00310"></a>00310     <span class="keyword">const</span> <span class="keywordtype">int</span>           ny = cpl_image_get_size_y(im);
+<a name="l00311"></a>00311     <span class="comment">/* Set min_arclen */</span>
+<a name="l00312"></a>00312     <span class="keyword">const</span> <span class="keywordtype">int</span>           min_arclen = (int)(ny / ARC_MINARCLENFACT);
+<a name="l00313"></a>00313     cpl_image       *   filt_im;
+<a name="l00314"></a>00314     cpl_mask        *   filter;
+<a name="l00315"></a>00315     cpl_image       *   collapsed;
+<a name="l00316"></a>00316     cpl_mask        *   bin_im;
+<a name="l00317"></a>00317     <span class="keywordtype">double</span>              threshold, fillval, median_val, sigma;
+<a name="l00318"></a>00318     cpl_apertures   *   det;
+<a name="l00319"></a>00319     cpl_size            nobj;
+<a name="l00320"></a>00320     <span class="keywordtype">int</span>                 ngoodpix;
+<a name="l00321"></a>00321     
+<a name="l00322"></a>00322     <span class="comment">/* Default values for output parameters */</span>
+<a name="l00323"></a>00323     *label_im = NULL;
+<a name="l00324"></a>00324 
+<a name="l00325"></a>00325     <span class="comment">/* Clear zones to be ignored (to avoid false detections) */</span>
+<a name="l00326"></a>00326     median_val = cpl_image_get_median_dev(im, &sigma);
+<a name="l00327"></a>00327     fillval = median_val-sigma/2.0;
+<a name="l00328"></a>00328     <span class="keywordflow">if</span> (irplib_distortion_fill_border(im, xmin, ymin, xmax, ymax, fillval)) {
+<a name="l00329"></a>00329         cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
+<a name="l00330"></a>00330                               <span class="stringliteral">"cannot fill bad zones"</span>);
+<a name="l00331"></a>00331         <span class="keywordflow">return</span> NULL;
+<a name="l00332"></a>00332     }
+<a name="l00333"></a>00333 
+<a name="l00334"></a>00334     <span class="comment">/* Subtract a low-pass */</span>
+<a name="l00335"></a>00335     filt_im = cpl_image_duplicate(im);
+<a name="l00336"></a>00336     <span class="keywordflow">if</span> (irplib_distortion_sub_hor_lowpass(filt_im, ARC_WINDOWSIZE) == -1) {
+<a name="l00337"></a>00337         cpl_image_delete(filt_im);
+<a name="l00338"></a>00338         <span class="keywordflow">return</span> NULL;
+<a name="l00339"></a>00339     }
+<a name="l00340"></a>00340     
+<a name="l00341"></a>00341     <span class="comment">/* Get relevant stats for thresholding */</span>
+<a name="l00342"></a>00342     median_val = cpl_image_get_median_dev(filt_im, &sigma);
+<a name="l00343"></a>00343 
+<a name="l00344"></a>00344     <span class="comment">/* Correct median_val and sigma if necessary */</span>
+<a name="l00345"></a>00345     <span class="keywordflow">if</span> (median_val < TRESH_MEDIAN_MIN) median_val = TRESH_MEDIAN_MIN;
+<a name="l00346"></a>00346     <span class="keywordflow">if</span> (sigma > TRESH_SIGMA_MAX) sigma = TRESH_SIGMA_MAX;
+<a name="l00347"></a>00347 
+<a name="l00348"></a>00348     <span class="comment">/* Set the threshold */</span>
+<a name="l00349"></a>00349     threshold = median_val + sigma * kappa;
+<a name="l00350"></a>00350 
+<a name="l00351"></a>00351     <span class="comment">/* Collapse the image */</span>
+<a name="l00352"></a>00352     collapsed = cpl_image_collapse_median_create(filt_im, 0, 0, 0);
+<a name="l00353"></a>00353 
+<a name="l00354"></a>00354     <span class="comment">/* Threshold to keep only the arcs - use of the collapsed image */</span>
+<a name="l00355"></a>00355     <span class="keywordflow">if</span> (irplib_distortion_threshold1d(filt_im, median_val, collapsed, 0.0)==-1) {
+<a name="l00356"></a>00356         cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
+<a name="l00357"></a>00357                               <span class="stringliteral">"cannot threshold the filtered image"</span>);
+<a name="l00358"></a>00358         cpl_image_delete(filt_im);
+<a name="l00359"></a>00359         cpl_image_delete(collapsed);
+<a name="l00360"></a>00360         <span class="keywordflow">return</span> NULL;
+<a name="l00361"></a>00361     }
+<a name="l00362"></a>00362     cpl_image_delete(collapsed);
+<a name="l00363"></a>00363 
+<a name="l00364"></a>00364     <span class="comment">/* Binarize the image */</span>
+<a name="l00365"></a>00365     bin_im = cpl_mask_threshold_image_create(filt_im, threshold, 
+<a name="l00366"></a>00366             DBL_MAX);
+<a name="l00367"></a>00367     cpl_image_delete(filt_im);
+<a name="l00368"></a>00368     <span class="keywordflow">if</span> (bin_im == NULL) {
+<a name="l00369"></a>00369         cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
+<a name="l00370"></a>00370                               <span class="stringliteral">"cannot binarise the image"</span>);
+<a name="l00371"></a>00371         <span class="keywordflow">return</span> NULL;
+<a name="l00372"></a>00372     }
+<a name="l00373"></a>00373 
+<a name="l00374"></a>00374     <span class="comment">/* Test if there are enough good pixels */</span>
+<a name="l00375"></a>00375     ngoodpix = cpl_mask_count(bin_im);
+<a name="l00376"></a>00376     <span class="keywordflow">if</span> (ngoodpix < ARC_MINGOODPIX) {
+<a name="l00377"></a>00377 <span class="preprocessor">#if defined CPL_HAVE_VA_ARGS && CPL_HAVE_VA_ARGS != 0</span>
+<a name="l00378"></a>00378 <span class="preprocessor"></span>        cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
+<a name="l00379"></a>00379                               <span class="stringliteral">"Too few (%d) white pixels"</span>, ngoodpix);
+<a name="l00380"></a>00380 <span class="preprocessor">#else</span>
+<a name="l00381"></a>00381 <span class="preprocessor"></span>        cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
+<a name="l00382"></a>00382                               <span class="stringliteral">"Too few white pixels"</span>);
+<a name="l00383"></a>00383 <span class="preprocessor">#endif</span>
+<a name="l00384"></a>00384 <span class="preprocessor"></span>        cpl_mask_delete(bin_im);
+<a name="l00385"></a>00385         <span class="keywordflow">return</span> NULL;
+<a name="l00386"></a>00386     }
+<a name="l00387"></a>00387 
+<a name="l00388"></a>00388     <span class="comment">/* Apply a morphological opening to clean the isolated pixels */</span>
+<a name="l00389"></a>00389     filter = cpl_mask_new(3, 3);
+<a name="l00390"></a>00390     cpl_mask_not(filter);
+<a name="l00391"></a>00391     cpl_mask_filter(bin_im, bin_im, filter, CPL_FILTER_OPENING,
+<a name="l00392"></a>00392                     CPL_BORDER_ZERO);
+<a name="l00393"></a>00393     cpl_mask_delete(filter);
+<a name="l00394"></a>00394 
+<a name="l00395"></a>00395     <span class="comment">/* Labelize pixel map to a label image */</span>
+<a name="l00396"></a>00396     *label_im = cpl_image_labelise_mask_create(bin_im, &nobj);
+<a name="l00397"></a>00397     cpl_mask_delete(bin_im);
+<a name="l00398"></a>00398 
+<a name="l00399"></a>00399     <span class="comment">/* Compute statistics on objects */</span>
+<a name="l00400"></a>00400     <span class="keywordflow">if</span> ((det = cpl_apertures_new_from_image(im, *label_im)) == NULL) {
+<a name="l00401"></a>00401         cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
+<a name="l00402"></a>00402                               <span class="stringliteral">"Cannot compute arcs stats"</span>);
+<a name="l00403"></a>00403         cpl_image_delete(*label_im);
+<a name="l00404"></a>00404         *label_im = NULL;
+<a name="l00405"></a>00405         <span class="keywordflow">return</span> NULL;
+<a name="l00406"></a>00406     }
+<a name="l00407"></a>00407 
+<a name="l00408"></a>00408     <span class="comment">/* Purge non-relevant arcs */</span>
+<a name="l00409"></a>00409     <span class="keywordflow">if</span> (irplib_distortion_purge_arcs(&det, *label_im, im, min_arclen,
+<a name="l00410"></a>00410                                      max_arc_width, arc_sat)) {
+<a name="l00411"></a>00411         cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
+<a name="l00412"></a>00412                               <span class="stringliteral">"Cannot purge the arcs"</span>);
+<a name="l00413"></a>00413         cpl_image_delete(*label_im);
+<a name="l00414"></a>00414         *label_im = NULL;
+<a name="l00415"></a>00415         cpl_apertures_delete(det);
+<a name="l00416"></a>00416         <span class="keywordflow">return</span> NULL;
+<a name="l00417"></a>00417     }
+<a name="l00418"></a>00418     <span class="keywordflow">if</span> (cpl_apertures_get_size(det) < ARC_MINNBARCS) {
+<a name="l00419"></a>00419 <span class="preprocessor">#if defined CPL_HAVE_VA_ARGS && CPL_HAVE_VA_ARGS != 0</span>
+<a name="l00420"></a>00420 <span class="preprocessor"></span>        cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
+<a name="l00421"></a>00421                 <span class="stringliteral">"Not enough valid arcs (%"</span>CPL_SIZE_FORMAT<span class="stringliteral">" < %d)"</span>, 
+<a name="l00422"></a>00422                 cpl_apertures_get_size(det), ARC_MINNBARCS);
+<a name="l00423"></a>00423 <span class="preprocessor">#else</span>
+<a name="l00424"></a>00424 <span class="preprocessor"></span>        cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
+<a name="l00425"></a>00425                               <span class="stringliteral">"Not enough valid arcs, min="</span>
+<a name="l00426"></a>00426                               IRPLIB_STRINGIFY(ARC_MINNBARCS));
+<a name="l00427"></a>00427 <span class="preprocessor">#endif</span>
+<a name="l00428"></a>00428 <span class="preprocessor"></span>        cpl_image_delete(*label_im);
+<a name="l00429"></a>00429         *label_im = NULL;
+<a name="l00430"></a>00430         cpl_apertures_delete(det);
+<a name="l00431"></a>00431         <span class="keywordflow">return</span> NULL;
+<a name="l00432"></a>00432     }
+<a name="l00433"></a>00433 
+<a name="l00434"></a>00434     <span class="comment">/* Return  */</span>
+<a name="l00435"></a>00435     <span class="keywordflow">return</span> det;
+<a name="l00436"></a>00436 }
+<a name="l00437"></a>00437 
+<a name="l00438"></a>00438 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00448"></a>00448 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00449"></a>00449 <span class="keyword">static</span> cpl_error_code irplib_distortion_fill_border(cpl_image * <span class="keyword">self</span>,
+<a name="l00450"></a>00450                                                     <span class="keywordtype">int</span>         xmin,
+<a name="l00451"></a>00451                                                     <span class="keywordtype">int</span>         ymin,
+<a name="l00452"></a>00452                                                     <span class="keywordtype">int</span>         xmax,
+<a name="l00453"></a>00453                                                     <span class="keywordtype">int</span>         ymax,
+<a name="l00454"></a>00454                                                     <span class="keywordtype">double</span>      fillval)
+<a name="l00455"></a>00455 {
+<a name="l00456"></a>00456     <span class="keyword">const</span> <span class="keywordtype">int</span>   nx     = cpl_image_get_size_x(<span class="keyword">self</span>);
+<a name="l00457"></a>00457     <span class="keyword">const</span> <span class="keywordtype">int</span>   ny     = cpl_image_get_size_y(<span class="keyword">self</span>);
+<a name="l00458"></a>00458     <span class="keywordtype">float</span>     * pfi    = cpl_image_get_data_float(<span class="keyword">self</span>);
+<a name="l00459"></a>00459     <span class="keyword">const</span> <span class="keywordtype">float</span> fvalue = (float)fillval;
+<a name="l00460"></a>00460     <span class="keywordtype">int</span>         i, j;
+<a name="l00461"></a>00461 
+<a name="l00462"></a>00462 
+<a name="l00463"></a>00463     cpl_ensure_code(pfi != NULL, cpl_error_get_code());
+<a name="l00464"></a>00464 
+<a name="l00465"></a>00465     <span class="comment">/* Ensure validity of pixel buffer access */</span>
+<a name="l00466"></a>00466     xmin = IRPLIB_MIN(xmin, nx+1);
+<a name="l00467"></a>00467     ymax = IRPLIB_MIN(ymax, ny);
+<a name="l00468"></a>00468 
+<a name="l00469"></a>00469     <span class="comment">/* - and avoid double access */</span>
+<a name="l00470"></a>00470     xmax = IRPLIB_MAX(xmax, xmin - 1);
+<a name="l00471"></a>00471     ymin = IRPLIB_MIN(ymin, ymax + 1);
+<a name="l00472"></a>00472 
+<a name="l00473"></a>00473     <span class="comment">/* Fill the zone */</span>
+<a name="l00474"></a>00474 
+<a name="l00475"></a>00475     <span class="keywordflow">for</span> (j = 0; j < ymin-1; j++) {
+<a name="l00476"></a>00476         <span class="keywordflow">for</span> (i = 0; i < nx; i++) {
+<a name="l00477"></a>00477             pfi[i+j*nx] = fvalue;
+<a name="l00478"></a>00478         }
+<a name="l00479"></a>00479     }
+<a name="l00480"></a>00480     <span class="comment">/* assert( j == IRPLIB_MAX(0, ymin-1) ); */</span>
+<a name="l00481"></a>00481 
+<a name="l00482"></a>00482     <span class="keywordflow">for</span> (; j < ymax; j++) {
+<a name="l00483"></a>00483         <span class="keywordflow">for</span> (i = 0; i < xmin-1; i++) {
+<a name="l00484"></a>00484             pfi[i+j*nx] = fvalue;
+<a name="l00485"></a>00485         }
+<a name="l00486"></a>00486         <span class="keywordflow">for</span> (i = xmax; i < nx; i++) {
+<a name="l00487"></a>00487             pfi[i+j*nx] = fvalue;
+<a name="l00488"></a>00488         }
+<a name="l00489"></a>00489     }
+<a name="l00490"></a>00490     <span class="comment">/* assert( j == IRPLIB_MAX(0, ymax) ); */</span>
+<a name="l00491"></a>00491 
+<a name="l00492"></a>00492     <span class="keywordflow">for</span> (; j < ny; j++) {
+<a name="l00493"></a>00493         <span class="keywordflow">for</span> (i = 0; i < nx; i++) {
+<a name="l00494"></a>00494             pfi[i+j*nx] = fvalue;
+<a name="l00495"></a>00495         }
+<a name="l00496"></a>00496     }
+<a name="l00497"></a>00497 
+<a name="l00498"></a>00498     <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l00499"></a>00499 }
+<a name="l00500"></a>00500 
+<a name="l00501"></a>00501 <span class="keyword">static</span> <span class="keywordtype">int</span> irplib_distortion_threshold1d(
+<a name="l00502"></a>00502         cpl_image   *   im,
+<a name="l00503"></a>00503         <span class="keywordtype">double</span>          threshold,
+<a name="l00504"></a>00504         cpl_image   *   im1d,
+<a name="l00505"></a>00505         <span class="keywordtype">double</span>          newval)
+<a name="l00506"></a>00506 {
+<a name="l00507"></a>00507     <span class="keywordtype">float</span>       *   pim;
+<a name="l00508"></a>00508     <span class="keywordtype">float</span>       *   pim1d;
+<a name="l00509"></a>00509     <span class="keywordtype">int</span>             nx, ny;
+<a name="l00510"></a>00510     <span class="keywordtype">int</span>             i, j;
+<a name="l00511"></a>00511 
+<a name="l00512"></a>00512     <span class="comment">/* Check entries */</span>
+<a name="l00513"></a>00513     <span class="keywordflow">if</span> (im == NULL) <span class="keywordflow">return</span> -1;
+<a name="l00514"></a>00514     <span class="keywordflow">if</span> (im1d == NULL) <span class="keywordflow">return</span> -1;
+<a name="l00515"></a>00515     <span class="keywordflow">if</span> (cpl_image_get_type(im) != CPL_TYPE_FLOAT) <span class="keywordflow">return</span> -1;
+<a name="l00516"></a>00516     <span class="keywordflow">if</span> (cpl_image_get_type(im1d) != CPL_TYPE_FLOAT) <span class="keywordflow">return</span> -1;
+<a name="l00517"></a>00517 
+<a name="l00518"></a>00518     <span class="comment">/* Get access to the im / im1d data */</span>
+<a name="l00519"></a>00519     pim = cpl_image_get_data_float(im);
+<a name="l00520"></a>00520     pim1d = cpl_image_get_data_float(im1d);
+<a name="l00521"></a>00521     nx = cpl_image_get_size_x(im);
+<a name="l00522"></a>00522     ny = cpl_image_get_size_y(im);
+<a name="l00523"></a>00523 
+<a name="l00524"></a>00524     <span class="comment">/* Apply the thresholding */</span>
+<a name="l00525"></a>00525     <span class="keywordflow">for</span> (i=0; i<nx; i++)
+<a name="l00526"></a>00526         <span class="keywordflow">if</span> (pim1d[i] < threshold) {
+<a name="l00527"></a>00527             <span class="keywordflow">for</span> (j=0; j<ny; j++) pim[i+j*nx] = (<span class="keywordtype">float</span>)newval;
+<a name="l00528"></a>00528         }
+<a name="l00529"></a>00529 
+<a name="l00530"></a>00530     <span class="comment">/* Return */</span>
+<a name="l00531"></a>00531     <span class="keywordflow">return</span> 0;
+<a name="l00532"></a>00532 }
+<a name="l00533"></a>00533 
+<a name="l00534"></a>00534 <span class="keyword">static</span> <span class="keywordtype">int</span> irplib_distortion_sub_hor_lowpass(
+<a name="l00535"></a>00535         cpl_image   *   im, 
+<a name="l00536"></a>00536         <span class="keywordtype">int</span>             filt_size)
+<a name="l00537"></a>00537 {
+<a name="l00538"></a>00538     cpl_vector  *   linehi;
+<a name="l00539"></a>00539     cpl_vector  *   linelo;
+<a name="l00540"></a>00540     cpl_vector  *   avglinehi;
+<a name="l00541"></a>00541     cpl_vector  *   avglinelo;
+<a name="l00542"></a>00542     <span class="keywordtype">double</span>      *   pavglinehi;
+<a name="l00543"></a>00543     <span class="keywordtype">float</span>       *   pim;
+<a name="l00544"></a>00544     <span class="keywordtype">int</span>             lopos, hipos, nx, ny;
+<a name="l00545"></a>00545     <span class="keywordtype">int</span>             i, j;
+<a name="l00546"></a>00546 
+<a name="l00547"></a>00547     <span class="comment">/* Test entries */</span>
+<a name="l00548"></a>00548     <span class="keywordflow">if</span> (im == NULL) <span class="keywordflow">return</span> -1;
+<a name="l00549"></a>00549     <span class="keywordflow">if</span> (filt_size <= 0) <span class="keywordflow">return</span> -1;
+<a name="l00550"></a>00550     
+<a name="l00551"></a>00551     <span class="comment">/* Initialise */</span>
+<a name="l00552"></a>00552     nx = cpl_image_get_size_x(im);
+<a name="l00553"></a>00553     ny = cpl_image_get_size_y(im);
+<a name="l00554"></a>00554     lopos = (int)(ny/4);
+<a name="l00555"></a>00555     hipos = (int)(3*ny/4);
+<a name="l00556"></a>00556 
+<a name="l00557"></a>00557     <span class="comment">/* Get the vectors out of the image */</span>
+<a name="l00558"></a>00558     <span class="keywordflow">if</span> ((linehi = cpl_vector_new_from_image_row(im, hipos)) == NULL) {
+<a name="l00559"></a>00559         <span class="keywordflow">return</span> -1;
+<a name="l00560"></a>00560     }
+<a name="l00561"></a>00561     <span class="keywordflow">if</span> ((linelo = cpl_vector_new_from_image_row(im, lopos)) == NULL) {
+<a name="l00562"></a>00562         cpl_vector_delete(linehi);
+<a name="l00563"></a>00563         <span class="keywordflow">return</span> -1;
+<a name="l00564"></a>00564     }
+<a name="l00565"></a>00565     
+<a name="l00566"></a>00566     <span class="comment">/* Filter the vectors */</span>
+<a name="l00567"></a>00567     <span class="keywordflow">if</span> ((avglinehi = cpl_vector_filter_median_create(linehi, 
+<a name="l00568"></a>00568                     filt_size)) == NULL) {
+<a name="l00569"></a>00569         cpl_vector_delete(linehi);
+<a name="l00570"></a>00570         cpl_vector_delete(linelo);
+<a name="l00571"></a>00571         <span class="keywordflow">return</span> -1;
+<a name="l00572"></a>00572     }
+<a name="l00573"></a>00573     cpl_vector_delete(linehi);
+<a name="l00574"></a>00574     
+<a name="l00575"></a>00575     <span class="keywordflow">if</span> ((avglinelo = cpl_vector_filter_median_create(linelo, 
+<a name="l00576"></a>00576                     filt_size)) == NULL) {
+<a name="l00577"></a>00577         cpl_vector_delete(linelo);
+<a name="l00578"></a>00578         cpl_vector_delete(avglinehi);
+<a name="l00579"></a>00579         <span class="keywordflow">return</span> -1;
+<a name="l00580"></a>00580     }
+<a name="l00581"></a>00581     cpl_vector_delete(linelo);
+<a name="l00582"></a>00582 
+<a name="l00583"></a>00583     <span class="comment">/* Average the filtered vectors to get the low freq signal */</span>
+<a name="l00584"></a>00584     cpl_vector_add(avglinehi, avglinelo);
+<a name="l00585"></a>00585     cpl_vector_delete(avglinelo);
+<a name="l00586"></a>00586     cpl_vector_divide_scalar(avglinehi, 2.0);
+<a name="l00587"></a>00587 
+<a name="l00588"></a>00588     <span class="comment">/* Subtract the low frequency signal */</span>
+<a name="l00589"></a>00589     pavglinehi = cpl_vector_get_data(avglinehi);
+<a name="l00590"></a>00590     pim = cpl_image_get_data_float(im);
+<a name="l00591"></a>00591     <span class="keywordflow">for</span> (i=0; i<nx; i++) {
+<a name="l00592"></a>00592         <span class="keywordflow">for</span> (j=0; j<ny; j++) {
+<a name="l00593"></a>00593             pim[i+j*nx] -= pavglinehi[i];
+<a name="l00594"></a>00594         }
+<a name="l00595"></a>00595     }
+<a name="l00596"></a>00596     cpl_vector_delete(avglinehi);
+<a name="l00597"></a>00597 
+<a name="l00598"></a>00598     <span class="keywordflow">return</span> 0;
+<a name="l00599"></a>00599 }
+<a name="l00600"></a>00600 
+<a name="l00601"></a>00601 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00612"></a>00612 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00613"></a>00613 <span class="keyword">static</span>
+<a name="l00614"></a>00614 cpl_error_code irplib_distortion_purge_arcs(cpl_apertures  ** <span class="keyword">self</span>,
+<a name="l00615"></a>00615                                             cpl_image       * lab_im,
+<a name="l00616"></a>00616                                             <span class="keyword">const</span> cpl_image * arc_im,
+<a name="l00617"></a>00617                                             <span class="keywordtype">int</span>               min_arclen,
+<a name="l00618"></a>00618                                             <span class="keywordtype">int</span>               max_arcwidth,
+<a name="l00619"></a>00619                                             <span class="keywordtype">double</span>            arc_sat)
+<a name="l00620"></a>00620 {
+<a name="l00621"></a>00621     <span class="keyword">const</span> <span class="keywordtype">double</span> ycenter = 0.5 * (1 + cpl_image_get_size_y(arc_im));
+<a name="l00622"></a>00622     <span class="keywordtype">int</span>   narcs;
+<a name="l00623"></a>00623     <span class="keywordtype">int</span>   nkeep  = 0;
+<a name="l00624"></a>00624     <span class="keywordtype">int</span>   ifirst = 1;
+<a name="l00625"></a>00625     <span class="keywordtype">int</span> * relabel;
+<a name="l00626"></a>00626     <span class="keywordtype">int</span>   i;
+<a name="l00627"></a>00627 
+<a name="l00628"></a>00628     <span class="comment">/* Check entries */</span>
+<a name="l00629"></a>00629     cpl_ensure_code(<span class="keyword">self</span> != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00630"></a>00630 
+<a name="l00631"></a>00631     <span class="comment">/* Get number of arcs */</span>
+<a name="l00632"></a>00632     narcs = cpl_apertures_get_size(*<span class="keyword">self</span>);
+<a name="l00633"></a>00633 
+<a name="l00634"></a>00634     cpl_ensure_code(narcs  > 0,     CPL_ERROR_DATA_NOT_FOUND);
+<a name="l00635"></a>00635     cpl_ensure_code(cpl_image_get_type(lab_im) == CPL_TYPE_INT,
+<a name="l00636"></a>00636                     CPL_ERROR_ILLEGAL_INPUT);
+<a name="l00637"></a>00637 
+<a name="l00638"></a>00638     <span class="comment">/* Allocate relabel array with default relabelling to zero */</span>
+<a name="l00639"></a>00639     relabel = cpl_calloc(narcs, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>));
+<a name="l00640"></a>00640 
+<a name="l00641"></a>00641     <span class="comment">/* Loop on the different arcs candidates */</span>
+<a name="l00642"></a>00642     <span class="keywordflow">for</span> (i = 0; i < narcs; i++) {
+<a name="l00643"></a>00643         <span class="comment">/* Test if the current object is a valid arc */</span>
+<a name="l00644"></a>00644         <span class="keyword">const</span> <span class="keywordtype">int</span> arclen = 1
+<a name="l00645"></a>00645             + cpl_apertures_get_top(*<span class="keyword">self</span>, i+1)
+<a name="l00646"></a>00646             - cpl_apertures_get_bottom(*<span class="keyword">self</span>, i+1);
+<a name="l00647"></a>00647 
+<a name="l00648"></a>00648         <span class="keywordflow">if</span> (cpl_apertures_get_top(*<span class="keyword">self</span>,    i+1) < ycenter) <span class="keywordflow">continue</span>;
+<a name="l00649"></a>00649         <span class="keywordflow">if</span> (cpl_apertures_get_bottom(*<span class="keyword">self</span>, i+1) > ycenter) <span class="keywordflow">continue</span>;
+<a name="l00650"></a>00650 
+<a name="l00651"></a>00651         <span class="keywordflow">if</span> (arclen > min_arclen) {
+<a name="l00652"></a>00652             <span class="keyword">const</span> <span class="keywordtype">int</span> arcwidth = 1
+<a name="l00653"></a>00653                 + cpl_apertures_get_right(*<span class="keyword">self</span>, i+1)
+<a name="l00654"></a>00654                 - cpl_apertures_get_left(*<span class="keyword">self</span>, i+1);
+<a name="l00655"></a>00655             <span class="keywordflow">if</span> (arcwidth < max_arcwidth) {
+<a name="l00656"></a>00656                 <span class="keyword">const</span> <span class="keywordtype">int</span> edge = cpl_apertures_get_left_y(*<span class="keyword">self</span>, i+1);
+<a name="l00657"></a>00657                 <span class="keywordflow">if</span> (edge > 0) {
+<a name="l00658"></a>00658                     <span class="keyword">const</span> <span class="keywordtype">double</span> mean = cpl_apertures_get_mean(*<span class="keyword">self</span>, i+1);
+<a name="l00659"></a>00659                     <span class="keywordflow">if</span> (mean < arc_sat) {
+<a name="l00660"></a>00660                         relabel[i] = ++nkeep;
+<a name="l00661"></a>00661                         <span class="comment">/* Relabeling, if any, starts with ifirst */</span>
+<a name="l00662"></a>00662                         <span class="keywordflow">if</span> (nkeep == i+1) ifirst = nkeep;
+<a name="l00663"></a>00663                     }
+<a name="l00664"></a>00664                 }
+<a name="l00665"></a>00665             }
+<a name="l00666"></a>00666         }
+<a name="l00667"></a>00667     }
+<a name="l00668"></a>00668 
+<a name="l00669"></a>00669     <span class="keywordflow">if</span> (nkeep < narcs) {
+<a name="l00670"></a>00670         <span class="comment">/* Update the labelised image by erasing non valid arcs */</span>
+<a name="l00671"></a>00671         <span class="keywordtype">int</span>     * plabim = cpl_image_get_data_int(lab_im);
+<a name="l00672"></a>00672         <span class="keyword">const</span> <span class="keywordtype">int</span> npix   = cpl_image_get_size_x(lab_im)
+<a name="l00673"></a>00673             * cpl_image_get_size_y(lab_im);
+<a name="l00674"></a>00674 
+<a name="l00675"></a>00675         <span class="keywordflow">if</span> (nkeep == 0) {
+<a name="l00676"></a>00676             cpl_free(relabel);
+<a name="l00677"></a>00677 <span class="preprocessor">#if defined CPL_HAVE_VA_ARGS && CPL_HAVE_VA_ARGS != 0</span>
+<a name="l00678"></a>00678 <span class="preprocessor"></span>            <span class="keywordflow">return</span> cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
+<a name="l00679"></a>00679                                          <span class="stringliteral">"All %d arc(s) are invalid"</span>, narcs);
+<a name="l00680"></a>00680 <span class="preprocessor">#else</span>
+<a name="l00681"></a>00681 <span class="preprocessor"></span>            <span class="keywordflow">return</span> cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
+<a name="l00682"></a>00682                                          <span class="stringliteral">"All arcs are invalid"</span>);
+<a name="l00683"></a>00683 <span class="preprocessor">#endif</span>
+<a name="l00684"></a>00684 <span class="preprocessor"></span>        }
+<a name="l00685"></a>00685 
+<a name="l00686"></a>00686         <span class="keywordflow">for</span> (i = 0; i < npix; i++) {
+<a name="l00687"></a>00687             <span class="keyword">const</span> <span class="keywordtype">int</span> label = plabim[i];
+<a name="l00688"></a>00688 
+<a name="l00689"></a>00689             <span class="keywordflow">if</span> (label < 0 || label > narcs) <span class="keywordflow">break</span>;
+<a name="l00690"></a>00690             <span class="keywordflow">if</span> (label >= ifirst) plabim[i] = relabel[label-1];
+<a name="l00691"></a>00691         }
+<a name="l00692"></a>00692 
+<a name="l00693"></a>00693         <span class="keywordflow">if</span> (i < npix) {
+<a name="l00694"></a>00694             <span class="comment">/* lab_im is not a valid label image */</span>
+<a name="l00695"></a>00695             cpl_free(relabel);
+<a name="l00696"></a>00696             <span class="keywordflow">return</span> cpl_error_set(cpl_func, plabim[i] < 0
+<a name="l00697"></a>00697                                          ? CPL_ERROR_ILLEGAL_INPUT
+<a name="l00698"></a>00698                                          : CPL_ERROR_INCOMPATIBLE_INPUT);
+<a name="l00699"></a>00699         }
+<a name="l00700"></a>00700 
+<a name="l00701"></a>00701         <span class="comment">/* Purge the bad arcs */</span>
+<a name="l00702"></a>00702         cpl_apertures_delete(*<span class="keyword">self</span>);
+<a name="l00703"></a>00703         *<span class="keyword">self</span> = cpl_apertures_new_from_image(arc_im, lab_im);
+<a name="l00704"></a>00704 
+<a name="l00705"></a>00705     }
+<a name="l00706"></a>00706 
+<a name="l00707"></a>00707     cpl_free(relabel);
+<a name="l00708"></a>00708 
+<a name="l00709"></a>00709     cpl_msg_info(cpl_func, <span class="stringliteral">"Purged %d of %d arcs (1st purged=%d)"</span>, narcs - nkeep,
+<a name="l00710"></a>00710                  narcs, ifirst);
+<a name="l00711"></a>00711 
+<a name="l00712"></a>00712     <span class="comment">/* arc_im may be invalid */</span>
+<a name="l00713"></a>00713     cpl_ensure_code(*<span class="keyword">self</span> != NULL, cpl_error_get_code());
+<a name="l00714"></a>00714 
+<a name="l00715"></a>00715     <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l00716"></a>00716 }
+<a name="l00717"></a>00717 
+<a name="l00718"></a>00718 
+<a name="l00719"></a>00719 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00733"></a>00733 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00734"></a>00734 <span class="keyword">static</span> cpl_error_code
+<a name="l00735"></a>00735 irplib_distortion_fill_arc_positions(cpl_bivector        * grid,
+<a name="l00736"></a>00736                                      cpl_vector          * fitvalues,
+<a name="l00737"></a>00737                                      <span class="keyword">const</span> cpl_image     * in,
+<a name="l00738"></a>00738                                      <span class="keyword">const</span> cpl_image     * label_im,
+<a name="l00739"></a>00739                                      <span class="keyword">const</span> cpl_apertures * det)
+<a name="l00740"></a>00740 {
+<a name="l00741"></a>00741     <span class="keyword">const</span> <span class="keywordtype">int</span>    narcs = cpl_apertures_get_size(det);
+<a name="l00742"></a>00742     <span class="keywordtype">int</span>          nfitvals = cpl_vector_get_size(fitvalues);
+<a name="l00743"></a>00743     <span class="keyword">const</span> <span class="keywordtype">int</span>    nx = cpl_image_get_size_x(label_im);
+<a name="l00744"></a>00744     <span class="keyword">const</span> <span class="keywordtype">int</span>    ny = cpl_image_get_size_y(label_im);
+<a name="l00745"></a>00745     cpl_image  * filt_img;
+<a name="l00746"></a>00746     cpl_mask   * kernel;
+<a name="l00747"></a>00747     cpl_vector * gridx = cpl_bivector_get_x(grid);
+<a name="l00748"></a>00748     cpl_vector * gridy = cpl_bivector_get_y(grid);
+<a name="l00749"></a>00749     cpl_polynomial* dist1d;
+<a name="l00750"></a>00750     cpl_matrix * dist1dx = NULL;
+<a name="l00751"></a>00751     cpl_vector * dist1dy = NULL;
+<a name="l00752"></a>00752     <span class="keywordtype">double</span>     * dgridx;
+<a name="l00753"></a>00753     <span class="keywordtype">double</span>     * dgridy;
+<a name="l00754"></a>00754     <span class="keywordtype">double</span>     * dfitv;
+<a name="l00755"></a>00755     <span class="keywordtype">int</span>          ndone = 0;
+<a name="l00756"></a>00756     <span class="keywordtype">int</span>          i, obj;
+<a name="l00757"></a>00757 
+<a name="l00758"></a>00758     cpl_ensure_code(nfitvals > 0,      CPL_ERROR_DATA_NOT_FOUND);
+<a name="l00759"></a>00759     cpl_ensure_code(narcs    > 0,      CPL_ERROR_DATA_NOT_FOUND);
+<a name="l00760"></a>00760     cpl_ensure_code(cpl_image_get_type(label_im) == CPL_TYPE_INT,
+<a name="l00761"></a>00761                     CPL_ERROR_TYPE_MISMATCH);
+<a name="l00762"></a>00762 
+<a name="l00763"></a>00763     <span class="comment">/* Ensure space for output */</span>
+<a name="l00764"></a>00764     <span class="keywordflow">if</span> (nfitvals < narcs * ny) {
+<a name="l00765"></a>00765         nfitvals = narcs * ny;
+<a name="l00766"></a>00766         cpl_vector_set_size(fitvalues, nfitvals);
+<a name="l00767"></a>00767     }
+<a name="l00768"></a>00768     <span class="keywordflow">if</span> (cpl_vector_get_size(gridx) < nfitvals ||
+<a name="l00769"></a>00769         cpl_vector_get_size(gridy) < nfitvals) {
+<a name="l00770"></a>00770         cpl_vector_set_size(gridx, nfitvals);
+<a name="l00771"></a>00771         cpl_vector_set_size(gridy, nfitvals);
+<a name="l00772"></a>00772     }
+<a name="l00773"></a>00773 
+<a name="l00774"></a>00774     <span class="comment">/* Get data after resizing */</span>
+<a name="l00775"></a>00775     dgridx = cpl_vector_get_data(gridx);
+<a name="l00776"></a>00776     dgridy = cpl_vector_get_data(gridy);
+<a name="l00777"></a>00777     dfitv  = cpl_vector_get_data(fitvalues);
+<a name="l00778"></a>00778 
+<a name="l00779"></a>00779     <span class="comment">/* Median filter on input image */</span>
+<a name="l00780"></a>00780     kernel = cpl_mask_new(3, 3);
+<a name="l00781"></a>00781     cpl_mask_not(kernel);
+<a name="l00782"></a>00782     filt_img = cpl_image_new(nx, ny, cpl_image_get_type(in));
+<a name="l00783"></a>00783     cpl_image_filter_mask(filt_img, in, kernel, CPL_FILTER_MEDIAN,
+<a name="l00784"></a>00784                                                 CPL_BORDER_FILTER);
+<a name="l00785"></a>00785     cpl_mask_delete(kernel);
+<a name="l00786"></a>00786 
+<a name="l00787"></a>00787     dist1d = cpl_polynomial_new(1);
+<a name="l00788"></a>00788 
+<a name="l00789"></a>00789     <span class="keywordflow">for</span> (obj = 0; obj < narcs; obj++) {
+<a name="l00790"></a>00790         <span class="comment">/* Find the reference X-coordinate for the arc */</span>
+<a name="l00791"></a>00791         <span class="keyword">const</span> <span class="keywordtype">int</span>  * plabel_im = cpl_image_get_data_int_const(label_im);
+<a name="l00792"></a>00792         <span class="keyword">const</span> <span class="keywordtype">int</span>    ndist1d = cpl_apertures_get_top(det, obj+1)
+<a name="l00793"></a>00793             - cpl_apertures_get_bottom(det, obj+1) + 1;
+<a name="l00794"></a>00794         cpl_boolean sampsym = CPL_TRUE;
+<a name="l00795"></a>00795         <span class="keywordtype">int</span>         j, prevj = 0;
+<a name="l00796"></a>00796         <span class="keywordtype">int</span>         k = 0;
+<a name="l00797"></a>00797 
+<a name="l00798"></a>00798         (void)cpl_matrix_unwrap(dist1dx);
+<a name="l00799"></a>00799         (void)cpl_vector_unwrap(dist1dy);
+<a name="l00800"></a>00800         dist1dx = cpl_matrix_wrap(1, ndist1d, dgridy + ndone);
+<a name="l00801"></a>00801         dist1dy = cpl_vector_wrap(ndist1d, dfitv  + ndone);
+<a name="l00802"></a>00802 
+<a name="l00803"></a>00803         <span class="comment">/* Find out the X coord. at all Y positions on the arc */</span>
+<a name="l00804"></a>00804 
+<a name="l00805"></a>00805         <span class="keywordflow">for</span> (j = cpl_apertures_get_bottom(det, obj+1)-1;
+<a name="l00806"></a>00806              j < cpl_apertures_get_top(det, obj+1); j++) {
+<a name="l00807"></a>00807 
+<a name="l00808"></a>00808             <span class="keywordflow">for</span> (i = 0; i < nx; i++) {
+<a name="l00809"></a>00809                 <span class="keywordflow">if</span> (plabel_im[i + j * nx] == obj + 1) <span class="keywordflow">break</span>;
+<a name="l00810"></a>00810             }
+<a name="l00811"></a>00811             <span class="keywordflow">if</span> (i < nx) {
+<a name="l00812"></a>00812                 <span class="comment">/* Found 1st pixel of aperture obj+1 in row j+1 */</span>
+<a name="l00813"></a>00813                 cpl_errorstate prestate = cpl_errorstate_get();
+<a name="l00814"></a>00814 
+<a name="l00815"></a>00815                 <span class="keyword">const</span> <span class="keywordtype">double</span> x_finepos
+<a name="l00816"></a>00816                     = irplib_distortion_get_row_centroid(filt_img, label_im,
+<a name="l00817"></a>00817                                                          i, j);
+<a name="l00818"></a>00818                 <span class="keywordflow">if</span> (!cpl_errorstate_is_equal(prestate)) {
+<a name="l00819"></a>00819                     irplib_error_recover(prestate, <span class="stringliteral">"Could not find X-position "</span>
+<a name="l00820"></a>00820                                          <span class="stringliteral">"for line %d at y=%d (x=%d)"</span>,
+<a name="l00821"></a>00821                                          obj+1, j+1, i+1);
+<a name="l00822"></a>00822                 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (x_finepos >= 0.0) {
+<a name="l00823"></a>00823                     cpl_matrix_set(dist1dx, 0, k, 1.0 + j);
+<a name="l00824"></a>00824                     cpl_vector_set(dist1dy, k, 1.0 + x_finepos);
+<a name="l00825"></a>00825                     <span class="keywordflow">if</span> (k > 0 && j != 1 + prevj) sampsym = CPL_FALSE;
+<a name="l00826"></a>00826                     prevj = j;
+<a name="l00827"></a>00827                     k++;
+<a name="l00828"></a>00828                 }
+<a name="l00829"></a>00829             }
+<a name="l00830"></a>00830         }
+<a name="l00831"></a>00831         <span class="keywordflow">if</span> (k > 0) {
+<a name="l00832"></a>00832             <span class="keywordtype">double</span> ref_xpos, grad;
+<a name="l00833"></a>00833             cpl_error_code error;
+<a name="l00834"></a>00834             <span class="keyword">const</span> cpl_boolean did_drop = k != ndist1d;
+<a name="l00835"></a>00835             <span class="keyword">const</span> cpl_size mindeg = 0;
+<a name="l00836"></a>00836             <span class="keyword">const</span> cpl_size maxdeg = 2;
+<a name="l00837"></a>00837 
+<a name="l00838"></a>00838             <span class="keywordflow">if</span> (did_drop) {
+<a name="l00839"></a>00839                 <span class="comment">/* Set correct size */</span>
+<a name="l00840"></a>00840                 dist1dx = cpl_matrix_wrap(1, k, cpl_matrix_unwrap(dist1dx));
+<a name="l00841"></a>00841                 dist1dy = cpl_vector_wrap(k, cpl_vector_unwrap(dist1dy));
+<a name="l00842"></a>00842             }
+<a name="l00843"></a>00843 
+<a name="l00844"></a>00844             error = cpl_polynomial_fit(dist1d, dist1dx, &sampsym, dist1dy, NULL,
+<a name="l00845"></a>00845                              CPL_FALSE, &mindeg, &maxdeg);
+<a name="l00846"></a>00846             <span class="keywordflow">if</span> (error) {
+<a name="l00847"></a>00847                 cpl_msg_error(cpl_func, <span class="stringliteral">"1D-fit failed"</span>);
+<a name="l00848"></a>00848                 <span class="keywordflow">break</span>;
+<a name="l00849"></a>00849             }
+<a name="l00850"></a>00850 
+<a name="l00851"></a>00851             ref_xpos = cpl_polynomial_eval_1d(dist1d, 0.5 * (ny + 1), &grad);
+<a name="l00852"></a>00852 
+<a name="l00853"></a>00853             <span class="keywordflow">for</span> (j = cpl_apertures_get_bottom(det, obj+1)-1;
+<a name="l00854"></a>00854                  j < cpl_apertures_get_top(det, obj+1); j++) {
+<a name="l00855"></a>00855                 <span class="keyword">const</span> <span class="keywordtype">double</span> xpos = cpl_polynomial_eval_1d(dist1d, j+1.0, NULL);
+<a name="l00856"></a>00856 
+<a name="l00857"></a>00857                 dfitv [ndone] = xpos;
+<a name="l00858"></a>00858                 dgridx[ndone] = ref_xpos;
+<a name="l00859"></a>00859                 <span class="comment">/* Wrapping dist1dx does _not_ take care of dgridy,</span>
+<a name="l00860"></a>00860 <span class="comment">                   in case of "Could not find X-position " */</span>
+<a name="l00861"></a>00861                 <span class="keywordflow">if</span> (did_drop)
+<a name="l00862"></a>00862                     dgridy[ndone] = 1.0 + j;
+<a name="l00863"></a>00863                 ndone++;
+<a name="l00864"></a>00864             }
+<a name="l00865"></a>00865             cpl_msg_info(cpl_func, <span class="stringliteral">"Line %d has center gradient %g"</span>, obj+1,
+<a name="l00866"></a>00866                          grad);
+<a name="l00867"></a>00867         }
+<a name="l00868"></a>00868     }
+<a name="l00869"></a>00869 
+<a name="l00870"></a>00870     cpl_image_delete(filt_img);
+<a name="l00871"></a>00871     cpl_polynomial_delete(dist1d);
+<a name="l00872"></a>00872     (void)cpl_matrix_unwrap(dist1dx);
+<a name="l00873"></a>00873     (void)cpl_vector_unwrap(dist1dy);
+<a name="l00874"></a>00874 
+<a name="l00875"></a>00875     cpl_msg_info(cpl_func, <span class="stringliteral">"Found %d fitting points ("</span>
+<a name="l00876"></a>00876                  <span class="stringliteral">"expected up to %d points)"</span>, ndone, nfitvals);
+<a name="l00877"></a>00877 
+<a name="l00878"></a>00878     cpl_ensure_code(obj == narcs, cpl_error_get_code());
+<a name="l00879"></a>00879 
+<a name="l00880"></a>00880     cpl_ensure_code(ndone > 0, CPL_ERROR_DATA_NOT_FOUND);
+<a name="l00881"></a>00881 
+<a name="l00882"></a>00882     cpl_vector_set_size(fitvalues, ndone);
+<a name="l00883"></a>00883     cpl_vector_set_size(gridx, ndone);
+<a name="l00884"></a>00884     cpl_vector_set_size(gridy, ndone);
+<a name="l00885"></a>00885 
+<a name="l00886"></a>00886     <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l00887"></a>00887 }
+<a name="l00888"></a>00888 
+<a name="l00889"></a>00889 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00899"></a>00899 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00900"></a>00900 <span class="keyword">static</span> <span class="keywordtype">double</span> irplib_distortion_get_row_centroid(<span class="keyword">const</span> cpl_image * im,
+<a name="l00901"></a>00901                                                  <span class="keyword">const</span> cpl_image * label_im,
+<a name="l00902"></a>00902                                                  <span class="keywordtype">int</span>               x,
+<a name="l00903"></a>00903                                                  <span class="keywordtype">int</span>               y)
+<a name="l00904"></a>00904 {
+<a name="l00905"></a>00905     <span class="keyword">const</span> <span class="keywordtype">int</span>     nx        = cpl_image_get_size_x(im);
+<a name="l00906"></a>00906     <span class="keyword">const</span> <span class="keywordtype">int</span>     ny        = cpl_image_get_size_y(im);
+<a name="l00907"></a>00907     <span class="keyword">const</span> <span class="keywordtype">int</span>     ynx       = y * nx;
+<a name="l00908"></a>00908     <span class="keyword">const</span> <span class="keywordtype">float</span> * pim       = cpl_image_get_data_float_const(im);
+<a name="l00909"></a>00909     <span class="keyword">const</span> <span class="keywordtype">int</span>   * plabel_im = cpl_image_get_data_int_const(label_im);
+<a name="l00910"></a>00910     <span class="keywordtype">int</span>           firstpos = -1;
+<a name="l00911"></a>00911     <span class="keywordtype">int</span>           lastpos  = -1;
+<a name="l00912"></a>00912     <span class="keywordtype">int</span>           maxpos   = x;
+<a name="l00913"></a>00913     <span class="keywordtype">int</span>           objnum;
+<a name="l00914"></a>00914     <span class="keywordtype">double</span>        wsum = 0.0;
+<a name="l00915"></a>00915     <span class="keywordtype">double</span>        sum  = 0.0;
+<a name="l00916"></a>00916     <span class="keywordtype">double</span>        max  = 0.0;
+<a name="l00917"></a>00917 
+<a name="l00918"></a>00918     cpl_ensure(pim       != NULL, cpl_error_get_code(),    -1.0);
+<a name="l00919"></a>00919     cpl_ensure(plabel_im != NULL, cpl_error_get_code(),    -2.0);
+<a name="l00920"></a>00920     cpl_ensure(x         >= 0,    CPL_ERROR_ILLEGAL_INPUT, -3.0);
+<a name="l00921"></a>00921     cpl_ensure(y         >= 0,    CPL_ERROR_ILLEGAL_INPUT, -4.0);
+<a name="l00922"></a>00922     cpl_ensure(x         <  nx,   CPL_ERROR_ILLEGAL_INPUT, -5.0);
+<a name="l00923"></a>00923     cpl_ensure(y         <  ny,   CPL_ERROR_ILLEGAL_INPUT, -6.0);
+<a name="l00924"></a>00924 
+<a name="l00925"></a>00925     max    = (double)pim[x + ynx];
+<a name="l00926"></a>00926     objnum = plabel_im[x + ynx];
+<a name="l00927"></a>00927 
+<a name="l00928"></a>00928     <span class="comment">/* While we stay in the same object... */</span>
+<a name="l00929"></a>00929     <span class="keywordflow">do</span> {
+<a name="l00930"></a>00930         <span class="keyword">const</span> <span class="keywordtype">double</span> val = (double)pim[x + ynx];
+<a name="l00931"></a>00931 
+<a name="l00932"></a>00932         <span class="keywordflow">if</span> (val > 0.0) { <span class="comment">/* FIXME: Handle this exception better */</span>
+<a name="l00933"></a>00933             wsum += x * val;
+<a name="l00934"></a>00934             sum += val;
+<a name="l00935"></a>00935 
+<a name="l00936"></a>00936             <span class="keywordflow">if</span> (firstpos < 0) firstpos = x;
+<a name="l00937"></a>00937             lastpos = x;
+<a name="l00938"></a>00938 
+<a name="l00939"></a>00939             <span class="keywordflow">if</span> (val > max) {
+<a name="l00940"></a>00940                 max = val;
+<a name="l00941"></a>00941                 maxpos = x;
+<a name="l00942"></a>00942             }
+<a name="l00943"></a>00943         }
+<a name="l00944"></a>00944 
+<a name="l00945"></a>00945 
+<a name="l00946"></a>00946         <span class="comment">/* Next point */</span>
+<a name="l00947"></a>00947         x++;
+<a name="l00948"></a>00948 
+<a name="l00949"></a>00949     } <span class="keywordflow">while</span> (x < nx && objnum == plabel_im[x + ynx]);
+<a name="l00950"></a>00950 
+<a name="l00951"></a>00951     cpl_ensure(sum > 0.0, CPL_ERROR_DATA_NOT_FOUND, -7.0);
+<a name="l00952"></a>00952 
+<a name="l00953"></a>00953     <span class="comment">/*</span>
+<a name="l00954"></a>00954 <span class="comment">       assert( 0 <= maxpos && maxpos < nx );</span>
+<a name="l00955"></a>00955 <span class="comment">       assert( objnum == plabel_im[maxpos + ynx] );</span>
+<a name="l00956"></a>00956 <span class="comment">       assert( wsum >= 0.0 );</span>
+<a name="l00957"></a>00957 <span class="comment">    */</span>
+<a name="l00958"></a>00958 
+<a name="l00959"></a>00959     <span class="keywordflow">return</span> (wsum < sum * firstpos || wsum > sum * lastpos)
+<a name="l00960"></a>00960         ? maxpos : wsum / sum;
+<a name="l00961"></a>00961 }
+<a name="l00962"></a>00962 
+<a name="l00963"></a>00963 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00969"></a>00969 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00970"></a>00970 <span class="preprocessor">#define IS_NB_TESTPOINTS    8</span>
+<a name="l00971"></a>00971 <span class="preprocessor"></span><span class="preprocessor">#define IS_MIN_SLOPE        0.01</span>
+<a name="l00972"></a>00972 <span class="preprocessor"></span><span class="preprocessor">#define IS_MAX_SLOPE_DIF    0.075</span>
+<a name="l00973"></a>00973 <span class="preprocessor"></span><span class="preprocessor">#define IS_MAX_FIT_EDGE_DIF 0.05</span>
+<a name="l00974"></a>00974 <span class="preprocessor"></span><span class="preprocessor">#define IS_MIN_RAMP         10.0</span>
+<a name="l00975"></a>00975 <span class="preprocessor"></span><span class="preprocessor">#define IS_MAX_MNERR        13.0</span>
+<a name="l00976"></a>00976 <span class="preprocessor"></span><span class="preprocessor">#define IS_MAX_MNERR_DIF    8.0</span>
+<a name="l00977"></a>00977 <span class="preprocessor"></span><span class="preprocessor">#define IS_MAX_INTER_DIF    20.0</span>
+<a name="l00978"></a>00978 <span class="preprocessor"></span><span class="preprocessor">#define IS_SKIPZONE         2.5</span>
+<a name="l00979"></a>00979 <span class="preprocessor"></span><span class="preprocessor">#define SQR(x) ((x)*(x))</span>
+<a name="l00980"></a>00980 <span class="preprocessor"></span><span class="keyword">static</span> cpl_image * irplib_distortion_remove_ramp(<span class="keyword">const</span> cpl_image * in) 
+<a name="l00981"></a>00981 {
+<a name="l00982"></a>00982     <span class="keywordtype">int</span>                 ramp_present;
+<a name="l00983"></a>00983     <span class="keyword">const</span> <span class="keywordtype">int</span>           nx = cpl_image_get_size_x(in);
+<a name="l00984"></a>00984     <span class="keyword">const</span> <span class="keywordtype">int</span>           ny = cpl_image_get_size_y(in);
+<a name="l00985"></a>00985     <span class="keyword">const</span> <span class="keywordtype">int</span>           yhi = (int)(ny/2);
+<a name="l00986"></a>00986     <span class="keyword">const</span> <span class="keywordtype">int</span>           ylo = yhi - 1;
+<a name="l00987"></a>00987     <span class="keywordtype">int</span>                 y;
+<a name="l00988"></a>00988     cpl_vector      *   tmp_vector;
+<a name="l00989"></a>00989     cpl_bivector    *   testpointlo;
+<a name="l00990"></a>00990     <span class="keywordtype">double</span>          *   testpointlo_x;
+<a name="l00991"></a>00991     <span class="keywordtype">double</span>          *   testpointlo_y;
+<a name="l00992"></a>00992     cpl_bivector    *   testpointhi;
+<a name="l00993"></a>00993     <span class="keywordtype">double</span>          *   testpointhi_x;
+<a name="l00994"></a>00994     <span class="keywordtype">double</span>          *   testpointhi_y;
+<a name="l00995"></a>00995     <span class="keyword">const</span> <span class="keywordtype">int</span>           spacing = ny / (IS_SKIPZONE*IS_NB_TESTPOINTS);
+<a name="l00996"></a>00996     <span class="keywordtype">double</span>              rampdif, fitslope;
+<a name="l00997"></a>00997     <span class="keywordtype">double</span>          *   pol_coefhi,
+<a name="l00998"></a>00998                     *   pol_coeflo;
+<a name="l00999"></a>00999     cpl_vector      *   median;
+<a name="l01000"></a>01000     <span class="keywordtype">double</span>          *   median_data;
+<a name="l01001"></a>01001     <span class="keywordtype">double</span>              medianerrlo, medianerrhi;
+<a name="l01002"></a>01002     <span class="keywordtype">double</span>              slope;
+<a name="l01003"></a>01003     cpl_image       *   out;
+<a name="l01004"></a>01004     <span class="keywordtype">float</span>           *   pout;
+<a name="l01005"></a>01005     <span class="keywordtype">float</span>               val;
+<a name="l01006"></a>01006     <span class="keywordtype">int</span>                 i, j;
+<a name="l01007"></a>01007 
+<a name="l01008"></a>01008     cpl_ensure(cpl_image_get_type(in) == CPL_TYPE_FLOAT,
+<a name="l01009"></a>01009                CPL_ERROR_UNSUPPORTED_MODE, NULL);
+<a name="l01010"></a>01010                     
+<a name="l01011"></a>01011     <span class="keywordflow">if</span> (ny < IS_SKIPZONE * IS_NB_TESTPOINTS){
+<a name="l01012"></a>01012 <span class="preprocessor">#if defined CPL_HAVE_VA_ARGS && CPL_HAVE_VA_ARGS != 0</span>
+<a name="l01013"></a>01013 <span class="preprocessor"></span>        cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
+<a name="l01014"></a>01014                               <span class="stringliteral">"image has %d lines, min="</span>
+<a name="l01015"></a>01015                               IRPLIB_STRINGIFY(IS_SKIPZONE) <span class="stringliteral">"*"</span>
+<a name="l01016"></a>01016                               IRPLIB_STRINGIFY(IS_NB_TESTPOINTS), ny);
+<a name="l01017"></a>01017 <span class="preprocessor">#else</span>
+<a name="l01018"></a>01018 <span class="preprocessor"></span>        cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
+<a name="l01019"></a>01019                               <span class="stringliteral">"image has too few lines, min="</span>
+<a name="l01020"></a>01020                               IRPLIB_STRINGIFY(IS_SKIPZONE) <span class="stringliteral">"*"</span>
+<a name="l01021"></a>01021                               IRPLIB_STRINGIFY(IS_NB_TESTPOINTS));
+<a name="l01022"></a>01022 <span class="preprocessor">#endif</span>
+<a name="l01023"></a>01023 <span class="preprocessor"></span>        <span class="keywordflow">return</span> NULL;
+<a name="l01024"></a>01024     }
+<a name="l01025"></a>01025     
+<a name="l01026"></a>01026     <span class="comment">/* Fill the vectors */</span>
+<a name="l01027"></a>01027     testpointhi = cpl_bivector_new(IS_NB_TESTPOINTS);
+<a name="l01028"></a>01028     testpointhi_x = cpl_bivector_get_x_data(testpointhi);
+<a name="l01029"></a>01029     testpointhi_y = cpl_bivector_get_y_data(testpointhi);
+<a name="l01030"></a>01030     testpointlo = cpl_bivector_new(IS_NB_TESTPOINTS);
+<a name="l01031"></a>01031     testpointlo_x = cpl_bivector_get_x_data(testpointlo);
+<a name="l01032"></a>01032     testpointlo_y = cpl_bivector_get_y_data(testpointlo);
+<a name="l01033"></a>01033     <span class="keywordflow">for</span> (i=0; i<IS_NB_TESTPOINTS; i++) {
+<a name="l01034"></a>01034         y = yhi + i * spacing;
+<a name="l01035"></a>01035         tmp_vector = cpl_vector_new_from_image_row(in, y+1);
+<a name="l01036"></a>01036         testpointhi_x[i] = y - ny / 2;
+<a name="l01037"></a>01037         testpointhi_y[i] = cpl_vector_get_median_const(tmp_vector);
+<a name="l01038"></a>01038         cpl_vector_delete(tmp_vector);
+<a name="l01039"></a>01039         y = ylo - i * spacing;
+<a name="l01040"></a>01040         tmp_vector = cpl_vector_new_from_image_row(in, y+1);
+<a name="l01041"></a>01041         testpointlo_x[IS_NB_TESTPOINTS-i-1] = y;
+<a name="l01042"></a>01042         testpointlo_y[IS_NB_TESTPOINTS-i-1]=cpl_vector_get_median_const(tmp_vector);
+<a name="l01043"></a>01043         cpl_vector_delete(tmp_vector);
+<a name="l01044"></a>01044     }
+<a name="l01045"></a>01045 
+<a name="l01046"></a>01046     <span class="comment">/* Apply the fit */</span>
+<a name="l01047"></a>01047     pol_coefhi = <a class="code" href="group__irplib__flat.html#ga3e3e3bd45aef34e38758e1f2528d7c91" title="Fit a slope to a list of points (robust fit).">irplib_flat_fit_slope_robust</a>(testpointhi_x,
+<a name="l01048"></a>01048             testpointhi_y, IS_NB_TESTPOINTS);
+<a name="l01049"></a>01049     pol_coeflo = <a class="code" href="group__irplib__flat.html#ga3e3e3bd45aef34e38758e1f2528d7c91" title="Fit a slope to a list of points (robust fit).">irplib_flat_fit_slope_robust</a>(testpointlo_x, 
+<a name="l01050"></a>01050             testpointlo_y, IS_NB_TESTPOINTS);
+<a name="l01051"></a>01051 
+<a name="l01052"></a>01052     <span class="comment">/* Compute the errors */</span>
+<a name="l01053"></a>01053     median = cpl_vector_new(IS_NB_TESTPOINTS);
+<a name="l01054"></a>01054     median_data = cpl_vector_get_data(median);
+<a name="l01055"></a>01055     <span class="keywordflow">for</span> (i=0; i<IS_NB_TESTPOINTS; i++) {
+<a name="l01056"></a>01056         median_data[i]=SQR(testpointhi_y[i]
+<a name="l01057"></a>01057                 - pol_coefhi[0] - pol_coefhi[1] * testpointhi_x[i]);
+<a name="l01058"></a>01058     }
+<a name="l01059"></a>01059     medianerrhi = cpl_vector_get_median(median);
+<a name="l01060"></a>01060     <span class="keywordflow">for</span> (i=0; i<IS_NB_TESTPOINTS; i++) {
+<a name="l01061"></a>01061         median_data[i]=SQR(testpointlo_y[i]
+<a name="l01062"></a>01062                 - pol_coeflo[0] - pol_coeflo[1] * testpointlo_x[i]);
+<a name="l01063"></a>01063     }
+<a name="l01064"></a>01064     medianerrlo = cpl_vector_get_median(median);
+<a name="l01065"></a>01065     cpl_vector_delete(median);
+<a name="l01066"></a>01066     rampdif = testpointlo_y[IS_NB_TESTPOINTS-1] - testpointhi_y[0];
+<a name="l01067"></a>01067     slope = rampdif / (ny/2.0);
+<a name="l01068"></a>01068     fitslope = (pol_coefhi[1] + pol_coeflo[1]) / 2.0;
+<a name="l01069"></a>01069 
+<a name="l01070"></a>01070     cpl_bivector_delete(testpointlo);
+<a name="l01071"></a>01071     cpl_bivector_delete(testpointhi);
+<a name="l01072"></a>01072 
+<a name="l01073"></a>01073     <span class="comment">/* Decide if there is a ramp or not  */</span>
+<a name="l01074"></a>01074     <span class="keywordflow">if</span> (fabs(rampdif)<IS_MIN_RAMP ||
+<a name="l01075"></a>01075             fabs(pol_coefhi[1]) < IS_MIN_SLOPE ||
+<a name="l01076"></a>01076             fabs(pol_coeflo[1]) < IS_MIN_SLOPE ||
+<a name="l01077"></a>01077             pol_coefhi[1]/pol_coeflo[1]<0.5 ||
+<a name="l01078"></a>01078             pol_coefhi[1]/pol_coeflo[1]>2.0 ||
+<a name="l01079"></a>01079             fabs(pol_coefhi[1]-pol_coeflo[1])>IS_MAX_SLOPE_DIF ||
+<a name="l01080"></a>01080             fabs(pol_coefhi[0]-pol_coeflo[0]) > IS_MAX_INTER_DIF ||
+<a name="l01081"></a>01081             medianerrlo> IS_MAX_MNERR ||
+<a name="l01082"></a>01082             medianerrhi> IS_MAX_MNERR ||
+<a name="l01083"></a>01083             fabs(medianerrlo-medianerrhi) >IS_MAX_MNERR_DIF ||
+<a name="l01084"></a>01084             fabs(slope-fitslope) > IS_MAX_FIT_EDGE_DIF ||
+<a name="l01085"></a>01085             slope/fitslope<0.5 ||
+<a name="l01086"></a>01086             slope/fitslope>2.0) ramp_present = 0;
+<a name="l01087"></a>01087     <span class="keywordflow">else</span> ramp_present = 1;
+<a name="l01088"></a>01088 
+<a name="l01089"></a>01089     cpl_free(pol_coeflo);
+<a name="l01090"></a>01090     cpl_free(pol_coefhi);
+<a name="l01091"></a>01091 
+<a name="l01092"></a>01092     <span class="comment">/* Correct the ramp if it is there */</span>
+<a name="l01093"></a>01093     out = cpl_image_duplicate(in);
+<a name="l01094"></a>01094     pout = cpl_image_get_data_float(out);
+<a name="l01095"></a>01095     <span class="keywordflow">if</span> (ramp_present == 1) {
+<a name="l01096"></a>01096         <span class="keywordflow">for</span> (j=0; j<ny/2; j++) {
+<a name="l01097"></a>01097             val = slope * (j-ny/2);
+<a name="l01098"></a>01098             <span class="keywordflow">for</span> (i=0; i<nx; i++)
+<a name="l01099"></a>01099                 pout[i+j*nx] -= val;
+<a name="l01100"></a>01100         }
+<a name="l01101"></a>01101         <span class="keywordflow">for</span> (j=ny/2; j<ny; j++) {
+<a name="l01102"></a>01102             val = slope * (j-ny);
+<a name="l01103"></a>01103             <span class="keywordflow">for</span> (i=0; i<nx; i++)
+<a name="l01104"></a>01104                 pout[i+j*nx] -= val;
+<a name="l01105"></a>01105         }
+<a name="l01106"></a>01106 
+<a name="l01107"></a>01107     }
+<a name="l01108"></a>01108 
+<a name="l01109"></a>01109     <span class="keywordflow">return</span> out;
+<a name="l01110"></a>01110 }
+<a name="l01111"></a>01111 
+<a name="l01112"></a>01112 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01126"></a>01126 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01127"></a>01127 <span class="keyword">static</span> cpl_error_code irplib_image_filter_background_line(cpl_image * <span class="keyword">self</span>,
+<a name="l01128"></a>01128                                                    <span class="keyword">const</span> cpl_image * other,
+<a name="l01129"></a>01129                                                    <span class="keywordtype">int</span> hsize,
+<a name="l01130"></a>01130                                                    cpl_boolean vertical)
+<a name="l01131"></a>01131 {
+<a name="l01132"></a>01132     <span class="keyword">const</span> <span class="keywordtype">int</span>      nx = cpl_image_get_size_x(<span class="keyword">self</span>);
+<a name="l01133"></a>01133     <span class="keyword">const</span> <span class="keywordtype">int</span>      ny = cpl_image_get_size_y(<span class="keyword">self</span>);
+<a name="l01134"></a>01134     <span class="keyword">const</span> <span class="keywordtype">int</span>      msize = 1 + 2 * hsize;
+<a name="l01135"></a>01135     cpl_mask     * mask;
+<a name="l01136"></a>01136     cpl_image    * background;
+<a name="l01137"></a>01137     cpl_error_code error = CPL_ERROR_NONE;
+<a name="l01138"></a>01138 
+<a name="l01139"></a>01139     cpl_ensure_code(<span class="keyword">self</span>  != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l01140"></a>01140     cpl_ensure_code(hsize >= 0,    CPL_ERROR_ILLEGAL_INPUT);
+<a name="l01141"></a>01141 
+<a name="l01142"></a>01142     <span class="keywordflow">if</span> (other == NULL) other = <span class="keyword">self</span>;
+<a name="l01143"></a>01143 
+<a name="l01144"></a>01144     mask = vertical ? cpl_mask_new(msize, 1) : cpl_mask_new(1, msize);
+<a name="l01145"></a>01145 
+<a name="l01146"></a>01146     error |= cpl_mask_not(mask);
+<a name="l01147"></a>01147 
+<a name="l01148"></a>01148     background = cpl_image_new(nx, ny, cpl_image_get_type(other));
+<a name="l01149"></a>01149 
+<a name="l01150"></a>01150     error |= cpl_image_filter_mask(background, other, mask, CPL_FILTER_MEDIAN,
+<a name="l01151"></a>01151                                    CPL_BORDER_FILTER);
+<a name="l01152"></a>01152     cpl_mask_delete(mask);
+<a name="l01153"></a>01153 
+<a name="l01154"></a>01154     <span class="keywordflow">if</span> (<span class="keyword">self</span> != other) {
+<a name="l01155"></a>01155         error |= cpl_image_copy(<span class="keyword">self</span>, other, 1, 1);
+<a name="l01156"></a>01156     }
+<a name="l01157"></a>01157 
+<a name="l01158"></a>01158     error |= cpl_image_subtract(<span class="keyword">self</span>, background);
+<a name="l01159"></a>01159     cpl_image_delete(background);
+<a name="l01160"></a>01160 
+<a name="l01161"></a>01161     <span class="keywordflow">return</span> error ? cpl_error_set_where(cpl_func) : CPL_ERROR_NONE;
+<a name="l01162"></a>01162 }
+<a name="l01163"></a>01163 
+<a name="l01164"></a>01164 
+<a name="l01165"></a>01165 
+<a name="l01191"></a>01191 <span class="keyword">static</span> cpl_matrix * irplib_matrix_product_normal_create(<span class="keyword">const</span> cpl_matrix * <span class="keyword">self</span>)
+<a name="l01192"></a>01192 {
+<a name="l01193"></a>01193 
+<a name="l01194"></a>01194     <span class="keywordtype">double</span>         sum;
+<a name="l01195"></a>01195     cpl_matrix   * product;
+<a name="l01196"></a>01196     <span class="keyword">const</span> <span class="keywordtype">double</span> * ai = cpl_matrix_get_data_const(<span class="keyword">self</span>);
+<a name="l01197"></a>01197     <span class="keyword">const</span> <span class="keywordtype">double</span> * aj;
+<a name="l01198"></a>01198     <span class="keywordtype">double</span>       * bwrite;
+<a name="l01199"></a>01199     <span class="keyword">const</span> <span class="keywordtype">int</span>      m = cpl_matrix_get_nrow(<span class="keyword">self</span>);
+<a name="l01200"></a>01200     <span class="keyword">const</span> <span class="keywordtype">int</span>      n = cpl_matrix_get_ncol(<span class="keyword">self</span>);
+<a name="l01201"></a>01201     <span class="keywordtype">int</span>            i, j, k;
+<a name="l01202"></a>01202 
+<a name="l01203"></a>01203 
+<a name="l01204"></a>01204     cpl_ensure(<span class="keyword">self</span> != NULL, CPL_ERROR_NULL_INPUT, NULL);
+<a name="l01205"></a>01205 
+<a name="l01206"></a>01206 <span class="preprocessor">#if 0</span>
+<a name="l01207"></a>01207 <span class="preprocessor"></span>    <span class="comment">/* Initialize all values to zero.</span>
+<a name="l01208"></a>01208 <span class="comment">       This is done to avoid access of uninitilized memory,  in case</span>
+<a name="l01209"></a>01209 <span class="comment">       someone passes the matrix to for example cpl_matrix_dump(). */</span>
+<a name="l01210"></a>01210     product = cpl_matrix_new(m, m);
+<a name="l01211"></a>01211     bwrite = cpl_matrix_get_data(product);
+<a name="l01212"></a>01212 <span class="preprocessor">#else</span>
+<a name="l01213"></a>01213 <span class="preprocessor"></span>    bwrite = (<span class="keywordtype">double</span> *) cpl_malloc(m * m * <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>));
+<a name="l01214"></a>01214     product = cpl_matrix_wrap(m, m, bwrite);
+<a name="l01215"></a>01215 <span class="preprocessor">#endif</span>
+<a name="l01216"></a>01216 <span class="preprocessor"></span>
+<a name="l01217"></a>01217     <span class="comment">/* The result at (i,j) is the dot-product of i'th and j'th row */</span>
+<a name="l01218"></a>01218     <span class="keywordflow">for</span> (i = 0; i < m; i++, bwrite += m, ai += n) {
+<a name="l01219"></a>01219         aj = ai; <span class="comment">/* aj points to first entry in j'th row */</span>
+<a name="l01220"></a>01220         <span class="keywordflow">for</span> (j = i; j < m; j++, aj += n) {
+<a name="l01221"></a>01221             sum = 0.0;
+<a name="l01222"></a>01222             <span class="keywordflow">for</span> (k = 0; k < n; k++) {
+<a name="l01223"></a>01223                 sum += ai[k] * aj[k];
+<a name="l01224"></a>01224             }
+<a name="l01225"></a>01225             bwrite[j] = sum;
+<a name="l01226"></a>01226         }
+<a name="l01227"></a>01227     }
+<a name="l01228"></a>01228 
+<a name="l01229"></a>01229     <span class="keywordflow">return</span> product;
+<a name="l01230"></a>01230 
+<a name="l01231"></a>01231 }
+<a name="l01232"></a>01232 
+<a name="l01233"></a>01233 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01247"></a>01247 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01248"></a>01248 <span class="keyword">static</span> cpl_error_code irplib_polynomial_fit_2d(cpl_polynomial * <span class="keyword">self</span>,
+<a name="l01249"></a>01249                                                <span class="keyword">const</span> cpl_bivector * xy_pos,
+<a name="l01250"></a>01250                                                <span class="keyword">const</span> cpl_vector * values,
+<a name="l01251"></a>01251                                                <span class="keywordtype">int</span> degree, <span class="keywordtype">double</span> fixy,
+<a name="l01252"></a>01252                                                <span class="keywordtype">double</span> * mse)
+<a name="l01253"></a>01253 {
+<a name="l01254"></a>01254 
+<a name="l01255"></a>01255     <span class="keyword">const</span> <span class="keywordtype">int</span>        np = cpl_bivector_get_size(xy_pos);
+<a name="l01256"></a>01256     <span class="comment">/* Number of unknowns to determine in one dimension */</span>
+<a name="l01257"></a>01257     <span class="keyword">const</span> <span class="keywordtype">int</span>        nc1 = 1+degree;
+<a name="l01258"></a>01258     <span class="comment">/* Number of unknowns to determine */</span>
+<a name="l01259"></a>01259     <span class="comment">/* P_{i,0} = 0, except P_{1,0} = 1 */</span>
+<a name="l01260"></a>01260     <span class="keyword">const</span> <span class="keywordtype">int</span>        nc = nc1 * (1 + nc1) / 2 - nc1;
+<a name="l01261"></a>01261     cpl_matrix     * mv;   <span class="comment">/* The transpose of the Vandermonde matrix */</span>
+<a name="l01262"></a>01262     cpl_matrix     * mh;   <span class="comment">/* Block-Hankel matrix, V'*V */</span>
+<a name="l01263"></a>01263     cpl_matrix     * mb;
+<a name="l01264"></a>01264     cpl_matrix     * mx;
+<a name="l01265"></a>01265 <span class="preprocessor">#ifdef IRPLIB_DISTORTION_ASSERT</span>
+<a name="l01266"></a>01266 <span class="preprocessor"></span>    <span class="keyword">const</span> <span class="keywordtype">double</span>   * coeffs1d;
+<a name="l01267"></a>01267 <span class="preprocessor">#endif</span>
+<a name="l01268"></a>01268 <span class="preprocessor"></span>    <span class="keywordtype">double</span>         * dmv;
+<a name="l01269"></a>01269     cpl_vector     * xhat;
+<a name="l01270"></a>01270     cpl_vector     * yhat;
+<a name="l01271"></a>01271     cpl_vector     * zhat;
+<a name="l01272"></a>01272     cpl_size         powers[2];
+<a name="l01273"></a>01273     <span class="keywordtype">int</span>              degx, degy;
+<a name="l01274"></a>01274     <span class="keywordtype">int</span>              i, j;
+<a name="l01275"></a>01275     cpl_error_code   error;
+<a name="l01276"></a>01276    
+<a name="l01277"></a>01277 
+<a name="l01278"></a>01278     cpl_ensure_code(<span class="keyword">self</span> != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l01279"></a>01279     cpl_ensure_code(cpl_polynomial_get_dimension(<span class="keyword">self</span>) == 2,
+<a name="l01280"></a>01280                     CPL_ERROR_INVALID_TYPE);
+<a name="l01281"></a>01281     cpl_ensure_code(np > 0,         cpl_error_get_code());
+<a name="l01282"></a>01282     cpl_ensure_code(values != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l01283"></a>01283 
+<a name="l01284"></a>01284     cpl_ensure_code(cpl_vector_get_size(values) == np,
+<a name="l01285"></a>01285                     CPL_ERROR_INCOMPATIBLE_INPUT);
+<a name="l01286"></a>01286 
+<a name="l01287"></a>01287     cpl_ensure_code(degree > 0, CPL_ERROR_ILLEGAL_INPUT);
+<a name="l01288"></a>01288     cpl_ensure_code(np >= nc,   CPL_ERROR_DATA_NOT_FOUND);
+<a name="l01289"></a>01289 
+<a name="l01290"></a>01290     <span class="comment">/* transform zero-point to fixy */</span>
+<a name="l01291"></a>01291     yhat = cpl_vector_duplicate(cpl_bivector_get_y_const(xy_pos));
+<a name="l01292"></a>01292     cpl_vector_subtract_scalar(yhat, fixy);
+<a name="l01293"></a>01293 
+<a name="l01294"></a>01294     <span class="comment">/* - and ensure P(y) = y on center line */</span>
+<a name="l01295"></a>01295     xhat = cpl_vector_duplicate(cpl_bivector_get_x_const(xy_pos));
+<a name="l01296"></a>01296     zhat = cpl_vector_duplicate(values);
+<a name="l01297"></a>01297     cpl_vector_subtract(zhat, xhat);
+<a name="l01298"></a>01298 
+<a name="l01299"></a>01299     <span class="comment">/* Initialize matrices */</span>
+<a name="l01300"></a>01300     <span class="comment">/* mv contains the polynomial terms in the order described */</span>
+<a name="l01301"></a>01301     <span class="comment">/* above in each row, for each input point. */</span>
+<a name="l01302"></a>01302     dmv = (<span class="keywordtype">double</span>*)cpl_malloc(nc*np*<span class="keyword">sizeof</span>(<span class="keywordtype">double</span>));
+<a name="l01303"></a>01303     mv = cpl_matrix_wrap(nc, np, dmv);
+<a name="l01304"></a>01304 
+<a name="l01305"></a>01305     <span class="comment">/* Has redundant FLOPs, appears to improve accuracy */</span>
+<a name="l01306"></a>01306     <span class="keywordflow">for</span> (i=0; i < np; i++) {
+<a name="l01307"></a>01307         <span class="keyword">const</span> <span class="keywordtype">double</span> x = cpl_vector_get(xhat, i);
+<a name="l01308"></a>01308         <span class="keyword">const</span> <span class="keywordtype">double</span> y = cpl_vector_get(yhat, i);
+<a name="l01309"></a>01309         <span class="keywordtype">double</span> xvalue;
+<a name="l01310"></a>01310         <span class="keywordtype">double</span> yvalue = y;
+<a name="l01311"></a>01311         j = 0;
+<a name="l01312"></a>01312         <span class="keywordflow">for</span> (degy = 1; degy <= degree; degy++) {
+<a name="l01313"></a>01313             xvalue = 1;
+<a name="l01314"></a>01314             <span class="keywordflow">for</span> (degx = 0; degx <= degree-degy; degx++, j++) {
+<a name="l01315"></a>01315                 dmv[np * j + i] = xvalue * yvalue;
+<a name="l01316"></a>01316                 xvalue *= x;
+<a name="l01317"></a>01317             }
+<a name="l01318"></a>01318             yvalue *= y;
+<a name="l01319"></a>01319         }
+<a name="l01320"></a>01320         <span class="comment">/* cx_assert( j == nc ); */</span>
+<a name="l01321"></a>01321     }
+<a name="l01322"></a>01322     cpl_vector_delete(xhat);
+<a name="l01323"></a>01323     cpl_vector_delete(yhat);
+<a name="l01324"></a>01324 
+<a name="l01325"></a>01325     <span class="comment">/* mb contains the values, it is not modified */</span>
+<a name="l01326"></a>01326     mb = cpl_matrix_wrap(np, 1, cpl_vector_get_data(zhat));
+<a name="l01327"></a>01327 
+<a name="l01328"></a>01328     <span class="comment">/* Form the right hand side of the normal equations */</span>
+<a name="l01329"></a>01329     mx = cpl_matrix_product_create(mv, mb);
+<a name="l01330"></a>01330 
+<a name="l01331"></a>01331     cpl_matrix_unwrap(mb);
+<a name="l01332"></a>01332     cpl_vector_delete(zhat);
+<a name="l01333"></a>01333 
+<a name="l01334"></a>01334     <span class="comment">/* Form the matrix of the normal equations */</span>
+<a name="l01335"></a>01335     mh = irplib_matrix_product_normal_create(mv);
+<a name="l01336"></a>01336     cpl_matrix_delete(mv);
+<a name="l01337"></a>01337 
+<a name="l01338"></a>01338     <span class="comment">/* Solve XA=B by a least-square solution (aka pseudo-inverse). */</span>
+<a name="l01339"></a>01339     error = cpl_matrix_decomp_chol(mh) || cpl_matrix_solve_chol(mh, mx);
+<a name="l01340"></a>01340 
+<a name="l01341"></a>01341     cpl_matrix_delete(mh);
+<a name="l01342"></a>01342 
+<a name="l01343"></a>01343     <span class="keywordflow">if</span> (error) {
+<a name="l01344"></a>01344         cpl_matrix_delete(mx);
+<a name="l01345"></a>01345         cpl_ensure_code(0, error);
+<a name="l01346"></a>01346     }
+<a name="l01347"></a>01347 
+<a name="l01348"></a>01348     <span class="comment">/* Store coefficients for output */</span>
+<a name="l01349"></a>01349 
+<a name="l01350"></a>01350 <span class="preprocessor">#ifdef IRPLIB_DISTORTION_ASSERT</span>
+<a name="l01351"></a>01351 <span class="preprocessor"></span>    coeffs1d = cpl_matrix_get_data(mx);
+<a name="l01352"></a>01352 <span class="preprocessor">#endif</span>
+<a name="l01353"></a>01353 <span class="preprocessor"></span>
+<a name="l01354"></a>01354     j = 0;
+<a name="l01355"></a>01355     <span class="keywordflow">for</span> (degy = 1; degy <= degree; degy++) {
+<a name="l01356"></a>01356         powers[1] = degy;
+<a name="l01357"></a>01357         <span class="keywordflow">for</span> (degx = 0; degx <= degree-degy; degx++, j++) {
+<a name="l01358"></a>01358             powers[0] = degx;
+<a name="l01359"></a>01359             <span class="comment">/* cx_assert( coeffs1d[j] == cpl_matrix_get(mx, j, 0) ); */</span>
+<a name="l01360"></a>01360             cpl_polynomial_set_coeff(<span class="keyword">self</span>, powers, cpl_matrix_get(mx, j, 0));
+<a name="l01361"></a>01361         }
+<a name="l01362"></a>01362     }
+<a name="l01363"></a>01363     <span class="comment">/* cx_assert( j == nc ); */</span>
+<a name="l01364"></a>01364 
+<a name="l01365"></a>01365     cpl_matrix_delete(mx);
+<a name="l01366"></a>01366 
+<a name="l01367"></a>01367     <span class="comment">/* P_{1,0} = 1 */</span>
+<a name="l01368"></a>01368     powers[0] = 1;
+<a name="l01369"></a>01369     powers[1] = 0;
+<a name="l01370"></a>01370     cpl_polynomial_set_coeff(<span class="keyword">self</span>, powers, 1.0);
+<a name="l01371"></a>01371 
+<a name="l01372"></a>01372     <span class="comment">/* Transform the polynomial back in Y */</span>
+<a name="l01373"></a>01373     cpl_polynomial_shift_1d(<span class="keyword">self</span>, 1, -fixy);
+<a name="l01374"></a>01374 
+<a name="l01375"></a>01375     <span class="comment">/* If requested, compute mean squared error */</span>
+<a name="l01376"></a>01376     <span class="keywordflow">if</span> (mse != NULL) {
+<a name="l01377"></a>01377         <span class="keyword">const</span> cpl_vector * x_pos = cpl_bivector_get_x_const(xy_pos);
+<a name="l01378"></a>01378         <span class="keyword">const</span> cpl_vector * y_pos = cpl_bivector_get_y_const(xy_pos);
+<a name="l01379"></a>01379         cpl_vector * x_val = cpl_vector_new(2);
+<a name="l01380"></a>01380         <span class="keywordtype">double</span> residue;
+<a name="l01381"></a>01381 
+<a name="l01382"></a>01382         *mse = 0;
+<a name="l01383"></a>01383         <span class="keywordflow">for</span> (i=0; i<np; i++) {
+<a name="l01384"></a>01384             cpl_vector_set(x_val, 0, cpl_vector_get(x_pos, i));
+<a name="l01385"></a>01385             cpl_vector_set(x_val, 1, cpl_vector_get(y_pos, i));
+<a name="l01386"></a>01386             <span class="comment">/* Subtract from the true value, square, accumulate */</span>
+<a name="l01387"></a>01387             residue = cpl_vector_get(values, i)
+<a name="l01388"></a>01388                 - cpl_polynomial_eval(<span class="keyword">self</span>, x_val);
+<a name="l01389"></a>01389             *mse += residue * residue;
+<a name="l01390"></a>01390         }
+<a name="l01391"></a>01391         cpl_vector_delete(x_val);
+<a name="l01392"></a>01392         <span class="comment">/* Average the error term */</span>
+<a name="l01393"></a>01393         *mse /= np;
+<a name="l01394"></a>01394     }
+<a name="l01395"></a>01395 
+<a name="l01396"></a>01396     <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l01397"></a>01397 }
+<a name="l01398"></a>01398 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/irplib__distortion_8h_source.html b/html/irplib__distortion_8h_source.html
new file mode 100644
index 0000000..6beefb1
--- /dev/null
+++ b/html/irplib__distortion_8h_source.html
@@ -0,0 +1,60 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: irplib_distortion.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>irplib_distortion.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: irplib_distortion.h,v 1.5 2006/07/26 14:47:34 yjung Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the irplib package</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: yjung $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2006/07/26 14:47:34 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.5 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifndef IRPLIB_DISTORTION_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#define IRPLIB_DISTORTION_H</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span>
+<a name="l00031"></a>00031 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00032"></a>00032 <span class="comment">                                Includes</span>
+<a name="l00033"></a>00033 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00034"></a>00034 
+<a name="l00035"></a>00035 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00038"></a>00038 <span class="comment">                                    Prototypes</span>
+<a name="l00039"></a>00039 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00040"></a>00040 
+<a name="l00041"></a>00041 cpl_polynomial * irplib_distortion_estimate(<span class="keyword">const</span> cpl_image *, <span class="keywordtype">int</span>, <span class="keywordtype">int</span>, <span class="keywordtype">int</span>, 
+<a name="l00042"></a>00042         <span class="keywordtype">int</span>, <span class="keywordtype">int</span>, <span class="keywordtype">int</span>, <span class="keywordtype">int</span>, <span class="keywordtype">double</span>, <span class="keywordtype">int</span>, cpl_apertures **) ;
+<a name="l00043"></a>00043 
+<a name="l00044"></a>00044 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/irplib__flat_8c_source.html b/html/irplib__flat_8c_source.html
new file mode 100644
index 0000000..0e0af4b
--- /dev/null
+++ b/html/irplib__flat_8c_source.html
@@ -0,0 +1,342 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: irplib_flat.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>irplib_flat.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: irplib_flat.c,v 1.15 2007/08/07 12:15:41 llundin Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the irplib package</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: llundin $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2007/08/07 12:15:41 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.15 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span>
+<a name="l00032"></a>00032 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                                   Includes</span>
+<a name="l00034"></a>00034 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 
+<a name="l00036"></a>00036 <span class="preprocessor">#include <math.h></span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00038"></a>00038 
+<a name="l00039"></a>00039 <span class="preprocessor">#include "irplib_flat.h"</span>
+<a name="l00040"></a>00040 
+<a name="l00041"></a>00041 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00042"></a>00042 <span class="comment">                            Functions prototypes</span>
+<a name="l00043"></a>00043 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00044"></a>00044 
+<a name="l00045"></a>00045 <span class="keyword">static</span> <span class="keywordtype">double</span> * irplib_flat_fit_proportional(<span class="keywordtype">double</span> *, <span class="keywordtype">double</span> *, <span class="keywordtype">int</span>) ;
+<a name="l00046"></a>00046 
+<a name="l00047"></a>00047 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00051"></a>00051 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00052"></a>00052 
+<a name="l00055"></a>00055 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00086"></a>00086 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00087"></a><a class="code" href="group__irplib__flat.html#gaf9bd48348cc91bb66304697b4c7aa58e">00087</a> cpl_imagelist * <a class="code" href="group__irplib__flat.html#gaf9bd48348cc91bb66304697b4c7aa58e" title="Compute a flat-field out of a set of exposures.">irplib_flat_fit_set</a>(
+<a name="l00088"></a>00088         cpl_imagelist   *   raw,
+<a name="l00089"></a>00089         <span class="keywordtype">int</span>                 mode)
+<a name="l00090"></a>00090 {
+<a name="l00091"></a>00091     <span class="keywordtype">double</span>          *   plane_med    = NULL ;
+<a name="l00092"></a>00092     <span class="keywordtype">double</span>          *   slope        = NULL ;
+<a name="l00093"></a>00093     cpl_image       *   gain         = NULL ;
+<a name="l00094"></a>00094     <span class="keywordtype">double</span>          *   pgain        = NULL ;
+<a name="l00095"></a>00095     cpl_image       *   intercept    = NULL ;
+<a name="l00096"></a>00096     <span class="keywordtype">double</span>          *   pintercept   = NULL ;
+<a name="l00097"></a>00097     cpl_image       *   sq_err       = NULL ;
+<a name="l00098"></a>00098     <span class="keywordtype">double</span>          *   psq_err      = NULL ;
+<a name="l00099"></a>00099     <span class="keywordtype">double</span>          *   timeline     = NULL ;
+<a name="l00100"></a>00100     <span class="keywordtype">float</span>           *   raw_im_data  = NULL ;
+<a name="l00101"></a>00101     cpl_imagelist   *   result       = NULL ;
+<a name="l00102"></a>00102     <span class="keyword">const</span> <span class="keywordtype">int</span>           nx = cpl_image_get_size_x(cpl_imagelist_get(raw, 0));
+<a name="l00103"></a>00103     <span class="keyword">const</span> <span class="keywordtype">int</span>           ny = cpl_image_get_size_y(cpl_imagelist_get(raw, 0));
+<a name="l00104"></a>00104     <span class="keyword">const</span> <span class="keywordtype">int</span>           ni = cpl_imagelist_get_size(raw);
+<a name="l00105"></a>00105     <span class="keywordtype">int</span>                 i, j ;
+<a name="l00106"></a>00106 
+<a name="l00107"></a>00107     <span class="comment">/* Check entries */</span>
+<a name="l00108"></a>00108     <span class="keywordflow">if</span> (raw==NULL) <span class="keywordflow">return</span> NULL ;
+<a name="l00109"></a>00109     <span class="keywordflow">if</span> ((mode != 0) && (mode != 1)) <span class="keywordflow">return</span> NULL ;
+<a name="l00110"></a>00110     <span class="keywordflow">if</span> (cpl_image_get_type(cpl_imagelist_get(raw, 0)) != CPL_TYPE_FLOAT)
+<a name="l00111"></a>00111         <span class="keywordflow">return</span> NULL ;
+<a name="l00112"></a>00112     <span class="keywordflow">if</span> (cpl_imagelist_get_size(raw) <= 1) <span class="keywordflow">return</span> NULL ;
+<a name="l00113"></a>00113 
+<a name="l00114"></a>00114     <span class="comment">/* Compute median for all planes */</span>
+<a name="l00115"></a>00115     plane_med = cpl_malloc(ni * <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>)) ;
+<a name="l00116"></a>00116     <span class="keywordflow">for</span> (i=0 ; i<ni ; i++)
+<a name="l00117"></a>00117         plane_med[i] = cpl_image_get_median(cpl_imagelist_get(raw, i));
+<a name="l00118"></a>00118 
+<a name="l00119"></a>00119     <span class="comment">/* Create result images */</span>
+<a name="l00120"></a>00120     gain = cpl_image_new(nx, ny, CPL_TYPE_DOUBLE) ;
+<a name="l00121"></a>00121     pgain = cpl_image_get_data_double(gain) ;
+<a name="l00122"></a>00122     <span class="keywordflow">if</span> (mode == 1) {
+<a name="l00123"></a>00123         intercept = cpl_image_new(nx, ny, CPL_TYPE_DOUBLE) ;
+<a name="l00124"></a>00124         pintercept = cpl_image_get_data_double(intercept) ;
+<a name="l00125"></a>00125     }
+<a name="l00126"></a>00126     sq_err = cpl_image_new(nx, ny, CPL_TYPE_DOUBLE) ;
+<a name="l00127"></a>00127     psq_err = cpl_image_get_data_double(sq_err) ;
+<a name="l00128"></a>00128     timeline = cpl_malloc(ni * <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>)) ;
+<a name="l00129"></a>00129 
+<a name="l00130"></a>00130     <span class="comment">/* Loop on all pixel positions */</span>
+<a name="l00131"></a>00131     cpl_msg_info(cpl_func, <span class="stringliteral">"Computing gains for all positions (long)..."</span>) ;
+<a name="l00132"></a>00132     <span class="keywordflow">for</span> (i=0 ; i<nx * ny ; i++) {
+<a name="l00133"></a>00133         <span class="comment">/* extract time line */</span>
+<a name="l00134"></a>00134         <span class="keywordflow">for</span> (j=0 ; j<ni ; j++) {
+<a name="l00135"></a>00135             raw_im_data = cpl_image_get_data_float(cpl_imagelist_get(raw, j)) ;
+<a name="l00136"></a>00136             timeline[j] = (double)raw_im_data[i] ;
+<a name="l00137"></a>00137         }
+<a name="l00138"></a>00138         <span class="comment">/* Fit slope to this time line */</span>
+<a name="l00139"></a>00139         <span class="keywordflow">if</span> (mode == 1) {
+<a name="l00140"></a>00140             slope = <a class="code" href="group__irplib__flat.html#ga3e3e3bd45aef34e38758e1f2528d7c91" title="Fit a slope to a list of points (robust fit).">irplib_flat_fit_slope_robust</a>(plane_med, timeline, ni) ;
+<a name="l00141"></a>00141             pintercept[i] = slope[0] ;
+<a name="l00142"></a>00142             pgain[i]      = slope[1] ;
+<a name="l00143"></a>00143             psq_err[i]    = slope[2] ;
+<a name="l00144"></a>00144             <span class="comment">/* Set results in output images */</span>
+<a name="l00145"></a>00145         } <span class="keywordflow">else</span> {
+<a name="l00146"></a>00146             slope = irplib_flat_fit_proportional(plane_med, timeline, ni) ;
+<a name="l00147"></a>00147             <span class="comment">/* Set results in output images */</span>
+<a name="l00148"></a>00148             pgain[i]      = slope[0] ;
+<a name="l00149"></a>00149             psq_err[i]    = slope[1] ;
+<a name="l00150"></a>00150         }
+<a name="l00151"></a>00151         cpl_free(slope);
+<a name="l00152"></a>00152     }
+<a name="l00153"></a>00153     cpl_free(plane_med) ;
+<a name="l00154"></a>00154     cpl_free(timeline) ;
+<a name="l00155"></a>00155 
+<a name="l00156"></a>00156     <span class="comment">/* Return */</span>
+<a name="l00157"></a>00157     result = cpl_imagelist_new() ;
+<a name="l00158"></a>00158     <span class="keywordflow">if</span> (mode == 1) {
+<a name="l00159"></a>00159         cpl_imagelist_set(result, gain, 0) ;
+<a name="l00160"></a>00160         cpl_imagelist_set(result, intercept, 1) ;
+<a name="l00161"></a>00161         cpl_imagelist_set(result, sq_err, 2) ;
+<a name="l00162"></a>00162     } <span class="keywordflow">else</span> {
+<a name="l00163"></a>00163         cpl_imagelist_set(result, gain, 0) ;
+<a name="l00164"></a>00164         cpl_imagelist_set(result, sq_err, 1) ;
+<a name="l00165"></a>00165     }
+<a name="l00166"></a>00166     <span class="keywordflow">return</span> result ;
+<a name="l00167"></a>00167 }
+<a name="l00168"></a>00168 
+<a name="l00169"></a>00169 <span class="comment">/* @cond */</span>
+<a name="l00170"></a>00170 <span class="preprocessor">#define SIGN(a,b) ((b) >= 0.0 ? fabs(a) : -fabs(a))</span>
+<a name="l00171"></a>00171 <span class="preprocessor"></span><span class="preprocessor">#define MAX_ITERATE     30</span>
+<a name="l00172"></a>00172 <span class="preprocessor"></span><span class="comment">/* @endcond */</span>
+<a name="l00173"></a>00173 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00190"></a>00190 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00191"></a><a class="code" href="group__irplib__flat.html#ga3e3e3bd45aef34e38758e1f2528d7c91">00191</a> <span class="keywordtype">double</span> * <a class="code" href="group__irplib__flat.html#ga3e3e3bd45aef34e38758e1f2528d7c91" title="Fit a slope to a list of points (robust fit).">irplib_flat_fit_slope_robust</a>(
+<a name="l00192"></a>00192         <span class="keywordtype">double</span>  *   x,
+<a name="l00193"></a>00193         <span class="keywordtype">double</span>  *   y,
+<a name="l00194"></a>00194         <span class="keywordtype">int</span>         np)
+<a name="l00195"></a>00195 {
+<a name="l00196"></a>00196     <span class="keywordtype">double</span>      *   c ;
+<a name="l00197"></a>00197     <span class="keywordtype">double</span>          aa, bb, bcomp, b1, b2, del, abdevt, f, f1, f2, sigb, temp,
+<a name="l00198"></a>00198                     d, sum ;
+<a name="l00199"></a>00199     <span class="keywordtype">double</span>          sx, sy, sxy, sxx, chisq ;
+<a name="l00200"></a>00200     cpl_vector  *   arr ;
+<a name="l00201"></a>00201     <span class="keywordtype">double</span>      *   parr ;
+<a name="l00202"></a>00202     <span class="keywordtype">double</span>          aa_ls, bb_ls ;
+<a name="l00203"></a>00203     <span class="keywordtype">int</span>             iter ;
+<a name="l00204"></a>00204     <span class="keywordtype">int</span>             i ;
+<a name="l00205"></a>00205 
+<a name="l00206"></a>00206     <span class="comment">/* Check entries */</span>
+<a name="l00207"></a>00207     <span class="keywordflow">if</span> (x==NULL || y==NULL) <span class="keywordflow">return</span> NULL ;
+<a name="l00208"></a>00208 
+<a name="l00209"></a>00209     c = cpl_malloc(3 * <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>)) ;
+<a name="l00210"></a>00210 
+<a name="l00211"></a>00211     sx = sy = sxx = sxy = 0.00 ;
+<a name="l00212"></a>00212     <span class="keywordflow">for</span> (i=0 ; i<np ; i++) {
+<a name="l00213"></a>00213         sx  += x[i];
+<a name="l00214"></a>00214         sy  += y[i];
+<a name="l00215"></a>00215         sxy += x[i] * y[i];
+<a name="l00216"></a>00216         sxx += x[i] * x[i];
+<a name="l00217"></a>00217     }
+<a name="l00218"></a>00218 
+<a name="l00219"></a>00219     del = np * sxx - sx * sx;
+<a name="l00220"></a>00220     aa_ls = aa  = (sxx * sy - sx * sxy) / del;
+<a name="l00221"></a>00221     bb_ls = bb  = (np * sxy - sx * sy) / del;
+<a name="l00222"></a>00222 
+<a name="l00223"></a>00223     chisq = 0.00 ;
+<a name="l00224"></a>00224     <span class="keywordflow">for</span> (i=0;i<np;i++) {
+<a name="l00225"></a>00225         temp = y[i] - (aa+bb*x[i]) ;
+<a name="l00226"></a>00226         temp *= temp ;
+<a name="l00227"></a>00227         chisq += temp ;
+<a name="l00228"></a>00228     }
+<a name="l00229"></a>00229 
+<a name="l00230"></a>00230     arr = cpl_vector_new(np) ;
+<a name="l00231"></a>00231     parr = cpl_vector_get_data(arr) ;
+<a name="l00232"></a>00232     sigb = sqrt(chisq/del);
+<a name="l00233"></a>00233     b1   = bb ;
+<a name="l00234"></a>00234 
+<a name="l00235"></a>00235     bcomp = b1 ;
+<a name="l00236"></a>00236     sum = 0.00 ;
+<a name="l00237"></a>00237     <span class="keywordflow">for</span> (i=0 ; i<np ; i++) {
+<a name="l00238"></a>00238             parr[i] = y[i] - bcomp * x[i];
+<a name="l00239"></a>00239         }
+<a name="l00240"></a>00240     aa = cpl_vector_get_median(arr); <span class="comment">/* arr permuted */</span>
+<a name="l00241"></a>00241     abdevt = 0.0;
+<a name="l00242"></a>00242     <span class="keywordflow">for</span> (i=0 ; i<np ; i++) {
+<a name="l00243"></a>00243         d = y[i] - (bcomp * x[i] + aa);
+<a name="l00244"></a>00244         abdevt += fabs(d);
+<a name="l00245"></a>00245         <span class="keywordflow">if</span> (fabs(y[i]) > 1e-7) d /= fabs(y[i]);
+<a name="l00246"></a>00246         <span class="keywordflow">if</span> (fabs(d) > 1e-7) sum += (d >= 0.0 ? x[i] : -x[i]);
+<a name="l00247"></a>00247     }
+<a name="l00248"></a>00248     f1 = sum ;
+<a name="l00249"></a>00249     b2   = bb + SIGN(3.0 * sigb, f1);
+<a name="l00250"></a>00250     bcomp = b2 ;
+<a name="l00251"></a>00251     sum = 0.00 ;
+<a name="l00252"></a>00252     <span class="keywordflow">for</span> (i=0 ; i<np ; i++) parr[i] = y[i] - bcomp * x[i];
+<a name="l00253"></a>00253     aa = cpl_vector_get_median(arr);  <span class="comment">/* arr permuted */</span>
+<a name="l00254"></a>00254     abdevt = 0.0;
+<a name="l00255"></a>00255     <span class="keywordflow">for</span> (i=0 ; i<np ; i++) {
+<a name="l00256"></a>00256         d = y[i] - (bcomp * x[i] + aa);
+<a name="l00257"></a>00257         abdevt += fabs(d);
+<a name="l00258"></a>00258         <span class="keywordflow">if</span> (fabs(y[i]) > 1e-7) d /= fabs(y[i]);
+<a name="l00259"></a>00259         <span class="keywordflow">if</span> (fabs(d) > 1e-7) sum += (d >= 0.0 ? x[i] : -x[i]);
+<a name="l00260"></a>00260     }
+<a name="l00261"></a>00261     f2 = sum ;
+<a name="l00262"></a>00262 
+<a name="l00263"></a>00263     <span class="keywordflow">if</span> (fabs(b2-b1)<1e-7) {
+<a name="l00264"></a>00264         c[0] = aa ;
+<a name="l00265"></a>00265         c[1] = bb ;
+<a name="l00266"></a>00266         c[2] = abdevt / (double)np;
+<a name="l00267"></a>00267         cpl_vector_delete(arr);
+<a name="l00268"></a>00268         <span class="keywordflow">return</span> c ;
+<a name="l00269"></a>00269     }
+<a name="l00270"></a>00270 
+<a name="l00271"></a>00271     iter = 0 ;
+<a name="l00272"></a>00272     <span class="keywordflow">while</span> (f1*f2 > 0.0) {
+<a name="l00273"></a>00273         bb = 2.0*b2-b1;
+<a name="l00274"></a>00274         b1 = b2;
+<a name="l00275"></a>00275         f1 = f2;
+<a name="l00276"></a>00276         b2 = bb;
+<a name="l00277"></a>00277 
+<a name="l00278"></a>00278         bcomp = b2 ;
+<a name="l00279"></a>00279         sum = 0.00 ;
+<a name="l00280"></a>00280         <span class="keywordflow">for</span> (i=0 ; i<np ; i++) parr[i] = y[i] - bcomp * x[i];
+<a name="l00281"></a>00281         aa = cpl_vector_get_median(arr); <span class="comment">/* arr permuted */</span>
+<a name="l00282"></a>00282         abdevt = 0.0;
+<a name="l00283"></a>00283         <span class="keywordflow">for</span> (i=0 ; i<np ; i++) {
+<a name="l00284"></a>00284             d = y[i] - (bcomp * x[i] + aa);
+<a name="l00285"></a>00285             abdevt += fabs(d);
+<a name="l00286"></a>00286             <span class="keywordflow">if</span> (fabs(y[i]) > 1e-7) d /= fabs(y[i]);
+<a name="l00287"></a>00287             <span class="keywordflow">if</span> (fabs(d) > 1e-7) sum += (d >= 0.0 ? x[i] : -x[i]);
+<a name="l00288"></a>00288         }
+<a name="l00289"></a>00289         f2 = sum ;
+<a name="l00290"></a>00290         iter++;
+<a name="l00291"></a>00291         <span class="keywordflow">if</span> (iter>=MAX_ITERATE) break ;
+<a name="l00292"></a>00292     }
+<a name="l00293"></a>00293     <span class="keywordflow">if</span> (iter>=MAX_ITERATE) {
+<a name="l00294"></a>00294         c[0] = aa_ls ;
+<a name="l00295"></a>00295         c[1] = bb_ls ;
+<a name="l00296"></a>00296         c[2] = -1.0 ;
+<a name="l00297"></a>00297         cpl_vector_delete(arr);
+<a name="l00298"></a>00298         <span class="keywordflow">return</span> c ;
+<a name="l00299"></a>00299     }
+<a name="l00300"></a>00300 
+<a name="l00301"></a>00301     sigb = 0.01 * sigb;
+<a name="l00302"></a>00302     <span class="keywordflow">while</span> (fabs(b2-b1) > sigb) {
+<a name="l00303"></a>00303         bb = 0.5 * (b1 + b2) ;
+<a name="l00304"></a>00304         <span class="keywordflow">if</span> ((fabs(bb-b1)<1e-7) || (fabs(bb-b2)<1e-7)) <span class="keywordflow">break</span>;
+<a name="l00305"></a>00305         bcomp = bb ;
+<a name="l00306"></a>00306         sum = 0.00 ;
+<a name="l00307"></a>00307         <span class="keywordflow">for</span> (i=0 ; i<np ; i++) parr[i] = y[i] - bcomp * x[i];
+<a name="l00308"></a>00308         aa = cpl_vector_get_median(arr); <span class="comment">/* arr permuted */</span>
+<a name="l00309"></a>00309         abdevt = 0.0;
+<a name="l00310"></a>00310         <span class="keywordflow">for</span> (i=0 ; i<np ; i++) {
+<a name="l00311"></a>00311             d = y[i] - (bcomp * x[i] + aa);
+<a name="l00312"></a>00312             abdevt += fabs(d);
+<a name="l00313"></a>00313             <span class="keywordflow">if</span> (fabs(y[i]) > 1e-7) d /= fabs(y[i]);
+<a name="l00314"></a>00314             <span class="keywordflow">if</span> (fabs(d) > 1e-7) sum += (d >= 0.0 ? x[i] : -x[i]);
+<a name="l00315"></a>00315         }
+<a name="l00316"></a>00316         f = sum ;
+<a name="l00317"></a>00317 
+<a name="l00318"></a>00318         <span class="keywordflow">if</span> (f*f1 >= 0.0) {
+<a name="l00319"></a>00319             f1=f;
+<a name="l00320"></a>00320             b1=bb;
+<a name="l00321"></a>00321         } <span class="keywordflow">else</span> {
+<a name="l00322"></a>00322             f2=f;
+<a name="l00323"></a>00323             b2=bb;
+<a name="l00324"></a>00324         }
+<a name="l00325"></a>00325     }
+<a name="l00326"></a>00326     cpl_vector_delete(arr) ;
+<a name="l00327"></a>00327     c[0]=aa;
+<a name="l00328"></a>00328     c[1]=bb;
+<a name="l00329"></a>00329     c[2]=abdevt/np;
+<a name="l00330"></a>00330     <span class="keywordflow">return</span> c ;
+<a name="l00331"></a>00331 }
+<a name="l00332"></a>00332 <span class="preprocessor">#undef MAX_ITERATE</span>
+<a name="l00333"></a>00333 <span class="preprocessor"></span><span class="preprocessor">#undef SIGN</span>
+<a name="l00334"></a>00334 <span class="preprocessor"></span>
+<a name="l00335"></a>00335 
+<a name="l00338"></a>00338 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00362"></a>00362 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00363"></a>00363 <span class="preprocessor">#define FITPROP_BIG_SLOPE   1e30</span>
+<a name="l00364"></a>00364 <span class="preprocessor"></span><span class="keyword">static</span> <span class="keywordtype">double</span> * irplib_flat_fit_proportional(
+<a name="l00365"></a>00365         <span class="keywordtype">double</span>  *   x,
+<a name="l00366"></a>00366         <span class="keywordtype">double</span>  *   y,
+<a name="l00367"></a>00367         <span class="keywordtype">int</span>         np)
+<a name="l00368"></a>00368 {
+<a name="l00369"></a>00369     cpl_vector  *   slopes ;
+<a name="l00370"></a>00370     <span class="keywordtype">double</span>      *   pslopes ;
+<a name="l00371"></a>00371     <span class="keywordtype">double</span>      *   med_slope ;
+<a name="l00372"></a>00372     <span class="keywordtype">double</span>          val ;
+<a name="l00373"></a>00373     <span class="keywordtype">double</span>          sq_err ;
+<a name="l00374"></a>00374     <span class="keywordtype">int</span>             i ;
+<a name="l00375"></a>00375 
+<a name="l00376"></a>00376     <span class="comment">/* Check entries */</span>
+<a name="l00377"></a>00377     <span class="keywordflow">if</span> (x==NULL || y==NULL) <span class="keywordflow">return</span> NULL ;
+<a name="l00378"></a>00378 
+<a name="l00379"></a>00379     slopes = cpl_vector_new(np) ;
+<a name="l00380"></a>00380     pslopes = cpl_vector_get_data(slopes) ;
+<a name="l00381"></a>00381     <span class="keywordflow">for</span> (i=0 ; i<np ; i++) {
+<a name="l00382"></a>00382         <span class="keywordflow">if</span> (fabs(x[i])>1e-30)  pslopes[i] = y[i] / x[i] ;
+<a name="l00383"></a>00383         <span class="keywordflow">else</span>                   pslopes[i] = FITPROP_BIG_SLOPE ;
+<a name="l00384"></a>00384     }
+<a name="l00385"></a>00385     med_slope = cpl_malloc(2 * <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>));
+<a name="l00386"></a>00386     med_slope[0] = cpl_vector_get_median(slopes); <span class="comment">/* slopes permuted */</span>
+<a name="l00387"></a>00387     cpl_vector_delete(slopes);
+<a name="l00388"></a>00388 
+<a name="l00389"></a>00389     sq_err = 0.00 ;
+<a name="l00390"></a>00390     <span class="keywordflow">for</span> (i=0 ; i<np ; i++) {
+<a name="l00391"></a>00391         val = med_slope[0] * x[i] ;
+<a name="l00392"></a>00392         sq_err += (val-y[i])*(val-y[i]) ;
+<a name="l00393"></a>00393     }
+<a name="l00394"></a>00394     sq_err /= (double)np ;
+<a name="l00395"></a>00395     med_slope[1] = sq_err ;
+<a name="l00396"></a>00396 
+<a name="l00397"></a>00397     <span class="keywordflow">return</span> med_slope ;
+<a name="l00398"></a>00398 <span class="preprocessor">#undef FITPROP_BIG_SLOPE</span>
+<a name="l00399"></a>00399 <span class="preprocessor"></span>}
+<a name="l00400"></a>00400 
+<a name="l00401"></a>00401 
+<a name="l00402"></a>00402 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/irplib__flat_8h_source.html b/html/irplib__flat_8h_source.html
new file mode 100644
index 0000000..e427401
--- /dev/null
+++ b/html/irplib__flat_8h_source.html
@@ -0,0 +1,56 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: irplib_flat.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>irplib_flat.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: irplib_flat.h,v 1.4 2005/09/15 11:47:16 llundin Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the irplib package</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: llundin $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2005/09/15 11:47:16 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.4 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifndef IRPLIB_FLAT_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#define IRPLIB_FLAT_H</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span>
+<a name="l00031"></a>00031 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00032"></a>00032 <span class="comment">                                   Includes</span>
+<a name="l00033"></a>00033 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00034"></a>00034 
+<a name="l00035"></a>00035 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 cpl_imagelist * <a class="code" href="group__irplib__flat.html#gaf9bd48348cc91bb66304697b4c7aa58e" title="Compute a flat-field out of a set of exposures.">irplib_flat_fit_set</a>(cpl_imagelist *, <span class="keywordtype">int</span>) ;
+<a name="l00038"></a>00038 <span class="keywordtype">double</span> * <a class="code" href="group__irplib__flat.html#ga3e3e3bd45aef34e38758e1f2528d7c91" title="Fit a slope to a list of points (robust fit).">irplib_flat_fit_slope_robust</a>(<span class="keywordtype">double</span> *, <span class="keywordtype">double</span> *, <span class="keywordtype">int</span>) ;
+<a name="l00039"></a>00039 
+<a name="l00040"></a>00040 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/irplib__framelist_8c_source.html b/html/irplib__framelist_8c_source.html
new file mode 100644
index 0000000..0a10fb0
--- /dev/null
+++ b/html/irplib__framelist_8c_source.html
@@ -0,0 +1,969 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: irplib_framelist.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>irplib_framelist.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: irplib_framelist.c,v 1.29 2012/02/03 13:55:14 llundin Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the irplib package </span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: llundin $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2012/02/03 13:55:14 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.29 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 
+<a name="l00029"></a>00029 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>
+<a name="l00031"></a>00031 <span class="preprocessor">#endif</span>
+<a name="l00032"></a>00032 <span class="preprocessor"></span>
+<a name="l00033"></a>00033 
+<a name="l00034"></a>00034 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00035"></a>00035 <span class="comment">                                 Includes</span>
+<a name="l00036"></a>00036 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00037"></a>00037 
+<a name="l00038"></a>00038 <span class="preprocessor">#include <stdio.h></span>
+<a name="l00039"></a>00039 <span class="preprocessor">#include <string.h></span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include <sys/types.h></span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include <regex.h></span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include <math.h></span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include <assert.h></span>
+<a name="l00044"></a>00044 
+<a name="l00045"></a>00045 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00046"></a>00046 
+<a name="l00047"></a>00047 <span class="preprocessor">#include "irplib_framelist.h"</span>
+<a name="l00048"></a>00048 
+<a name="l00049"></a>00049 
+<a name="l00050"></a>00050 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00051"></a>00051 <span class="comment">                                 New types</span>
+<a name="l00052"></a>00052 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00053"></a>00053 
+<a name="l00054"></a>00054 <span class="comment">/* @cond */</span>
+<a name="l00055"></a>00055 <span class="keyword">struct </span>_irplib_framelist_ {
+<a name="l00056"></a>00056     <span class="keywordtype">int</span> size;
+<a name="l00057"></a>00057     cpl_frame        ** frame;
+<a name="l00058"></a>00058     cpl_propertylist ** propertylist;
+<a name="l00059"></a>00059 
+<a name="l00060"></a>00060 };
+<a name="l00061"></a>00061 <span class="comment">/* @endcond */</span>
+<a name="l00062"></a>00062 
+<a name="l00063"></a>00063 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00064"></a>00064 <span class="comment">                                 Private funcions</span>
+<a name="l00065"></a>00065 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00066"></a>00066 
+<a name="l00067"></a>00067 <span class="keyword">static</span> <span class="keywordtype">void</span> irplib_framelist_set_size(irplib_framelist *)
+<a name="l00068"></a>00068 <span class="preprocessor">#if defined __GNUC__ &&  __GNUC__ >= 4</span>
+<a name="l00069"></a>00069 <span class="preprocessor"></span>    __attribute__((nonnull))
+<a name="l00070"></a>00070 <span class="preprocessor">#endif</span>
+<a name="l00071"></a>00071 <span class="preprocessor"></span>;
+<a name="l00072"></a>00072 
+<a name="l00073"></a>00073 <span class="keyword">static</span> cpl_boolean irplib_property_equal(<span class="keyword">const</span> cpl_propertylist *,
+<a name="l00074"></a>00074                                          <span class="keyword">const</span> cpl_propertylist *,
+<a name="l00075"></a>00075                                          <span class="keyword">const</span> <span class="keywordtype">char</span> *, cpl_type, <span class="keywordtype">double</span>,
+<a name="l00076"></a>00076                                          <span class="keywordtype">char</span> **, <span class="keywordtype">char</span> **)
+<a name="l00077"></a>00077 <span class="preprocessor">#if defined __GNUC__ &&  __GNUC__ >= 4</span>
+<a name="l00078"></a>00078 <span class="preprocessor"></span>    __attribute__((nonnull))
+<a name="l00079"></a>00079 <span class="preprocessor">#endif</span>
+<a name="l00080"></a>00080 <span class="preprocessor"></span>;
+<a name="l00081"></a>00081 
+<a name="l00082"></a>00082 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00161"></a>00161 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00162"></a>00162 
+<a name="l00165"></a>00165 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00166"></a>00166 <span class="comment">                            Function codes</span>
+<a name="l00167"></a>00167 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00168"></a>00168 
+<a name="l00169"></a>00169 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00177"></a>00177 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00178"></a><a class="code" href="group__irplib__framelist.html#ga5b86add048651f73424d2542a04946a0">00178</a> irplib_framelist * <a class="code" href="group__irplib__framelist.html#ga5b86add048651f73424d2542a04946a0" title="Create an empty framelist.">irplib_framelist_new</a>(<span class="keywordtype">void</span>)
+<a name="l00179"></a>00179 {
+<a name="l00180"></a>00180 
+<a name="l00181"></a>00181     <span class="keywordflow">return</span> (irplib_framelist *) cpl_calloc(1, <span class="keyword">sizeof</span>(irplib_framelist));
+<a name="l00182"></a>00182 
+<a name="l00183"></a>00183 }
+<a name="l00184"></a>00184 
+<a name="l00185"></a>00185 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00190"></a>00190 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00191"></a><a class="code" href="group__irplib__framelist.html#ga7a5159e9d27ef277df3fb55b331aaf26">00191</a> <span class="keywordtype">void</span> <a class="code" href="group__irplib__framelist.html#ga7a5159e9d27ef277df3fb55b331aaf26" title="Deallocate an irplib_framelist with its frames and properties.">irplib_framelist_delete</a>(irplib_framelist * <span class="keyword">self</span>)
+<a name="l00192"></a>00192 {
+<a name="l00193"></a>00193 
+<a name="l00194"></a>00194     <a class="code" href="group__irplib__framelist.html#ga900ea254d9b2a2e4e3957360bbae4deb" title="Erase all frames from a framelist.">irplib_framelist_empty</a>(<span class="keyword">self</span>);
+<a name="l00195"></a>00195     cpl_free(<span class="keyword">self</span>);
+<a name="l00196"></a>00196 }
+<a name="l00197"></a>00197 
+<a name="l00198"></a>00198 
+<a name="l00199"></a>00199 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00208"></a>00208 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00209"></a><a class="code" href="group__irplib__framelist.html#ga30cbfd003c6e6a6a42e610442f0b1bd1">00209</a> irplib_framelist * <a class="code" href="group__irplib__framelist.html#ga30cbfd003c6e6a6a42e610442f0b1bd1" title="Create an irplib_framelist from a cpl_framelist.">irplib_framelist_cast</a>(<span class="keyword">const</span> cpl_frameset * frameset)
+<a name="l00210"></a>00210 {
+<a name="l00211"></a>00211 
+<a name="l00212"></a>00212     irplib_framelist * <span class="keyword">self</span>;
+<a name="l00213"></a>00213     <span class="keyword">const</span> cpl_frame * frame;
+<a name="l00214"></a>00214     <span class="keywordtype">int</span> i;
+<a name="l00215"></a>00215 
+<a name="l00216"></a>00216 
+<a name="l00217"></a>00217     cpl_ensure(frameset != NULL, CPL_ERROR_NULL_INPUT, NULL);
+<a name="l00218"></a>00218 
+<a name="l00219"></a>00219     <span class="comment">/* The function cannot fail now */</span>
+<a name="l00220"></a>00220     <span class="keyword">self</span> = <a class="code" href="group__irplib__framelist.html#ga5b86add048651f73424d2542a04946a0" title="Create an empty framelist.">irplib_framelist_new</a>();
+<a name="l00221"></a>00221 
+<a name="l00222"></a>00222     <span class="keywordflow">for</span> (i = 0, frame = cpl_frameset_get_first_const(frameset);
+<a name="l00223"></a>00223          frame != NULL;
+<a name="l00224"></a>00224          i++, frame = cpl_frameset_get_next_const(frameset)) {
+<a name="l00225"></a>00225 
+<a name="l00226"></a>00226         cpl_frame * copy = cpl_frame_duplicate(frame);
+<a name="l00227"></a>00227 
+<a name="l00228"></a>00228         <span class="keyword">const</span> cpl_error_code error = <a class="code" href="group__irplib__framelist.html#ga37e730f5627b4a0c7a81014f62421879" title="Add a frame to a framelist.">irplib_framelist_set</a>(<span class="keyword">self</span>, copy, i);
+<a name="l00229"></a>00229 
+<a name="l00230"></a>00230         assert(error == CPL_ERROR_NONE);
+<a name="l00231"></a>00231 
+<a name="l00232"></a>00232     }
+<a name="l00233"></a>00233 
+<a name="l00234"></a>00234     assert(self->size == cpl_frameset_get_size(frameset));
+<a name="l00235"></a>00235 
+<a name="l00236"></a>00236     <span class="keywordflow">return</span> <span class="keyword">self</span>;
+<a name="l00237"></a>00237 
+<a name="l00238"></a>00238 }
+<a name="l00239"></a>00239 
+<a name="l00240"></a>00240 
+<a name="l00241"></a>00241 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00250"></a>00250 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00251"></a><a class="code" href="group__irplib__framelist.html#gabeedce2770a1bc06c26c0891a41aa174">00251</a> cpl_frameset * <a class="code" href="group__irplib__framelist.html#gabeedce2770a1bc06c26c0891a41aa174" title="Create a CPL frameset from an irplib_framelist.">irplib_frameset_cast</a>(<span class="keyword">const</span> irplib_framelist * <span class="keyword">self</span>)
+<a name="l00252"></a>00252 {
+<a name="l00253"></a>00253 
+<a name="l00254"></a>00254     cpl_frameset * <span class="keyword">new</span>;
+<a name="l00255"></a>00255     <span class="keywordtype">int</span> i;
+<a name="l00256"></a>00256 
+<a name="l00257"></a>00257     cpl_ensure(<span class="keyword">self</span> != NULL, CPL_ERROR_NULL_INPUT, NULL);
+<a name="l00258"></a>00258 
+<a name="l00259"></a>00259     <span class="comment">/* The function cannot fail now */</span>
+<a name="l00260"></a>00260     <span class="keyword">new</span> = cpl_frameset_new();
+<a name="l00261"></a>00261 
+<a name="l00262"></a>00262     <span class="keywordflow">for</span> (i = 0; i < <span class="keyword">self</span>->size; i++) {
+<a name="l00263"></a>00263         cpl_frame * frame = cpl_frame_duplicate(self->frame[i]);
+<a name="l00264"></a>00264         <span class="keyword">const</span> cpl_error_code error = cpl_frameset_insert(<span class="keyword">new</span>, frame);
+<a name="l00265"></a>00265 
+<a name="l00266"></a>00266         assert(error == CPL_ERROR_NONE);
+<a name="l00267"></a>00267 
+<a name="l00268"></a>00268     }
+<a name="l00269"></a>00269 
+<a name="l00270"></a>00270     assert(self->size == cpl_frameset_get_size(<span class="keyword">new</span>));
+<a name="l00271"></a>00271 
+<a name="l00272"></a>00272     <span class="keywordflow">return</span> <span class="keyword">new</span>;
+<a name="l00273"></a>00273 
+<a name="l00274"></a>00274 }
+<a name="l00275"></a>00275 
+<a name="l00276"></a>00276 
+<a name="l00277"></a>00277 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00289"></a>00289 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00290"></a><a class="code" href="group__irplib__framelist.html#ga86d6746d1c19356417815f7df04c3396">00290</a> irplib_framelist * <a class="code" href="group__irplib__framelist.html#ga86d6746d1c19356417815f7df04c3396" title="Extract the frames with the given tag from a framelist.">irplib_framelist_extract</a>(<span class="keyword">const</span> irplib_framelist * <span class="keyword">self</span>,
+<a name="l00291"></a>00291                                             <span class="keyword">const</span> <span class="keywordtype">char</span> * tag)
+<a name="l00292"></a>00292 {
+<a name="l00293"></a>00293 
+<a name="l00294"></a>00294     irplib_framelist * <span class="keyword">new</span>;
+<a name="l00295"></a>00295     <span class="keywordtype">int</span> i, newsize;
+<a name="l00296"></a>00296 
+<a name="l00297"></a>00297 
+<a name="l00298"></a>00298     cpl_ensure(<span class="keyword">self</span> != NULL, CPL_ERROR_NULL_INPUT, NULL);
+<a name="l00299"></a>00299     cpl_ensure(tag  != NULL, CPL_ERROR_NULL_INPUT, NULL);
+<a name="l00300"></a>00300 
+<a name="l00301"></a>00301     <span class="keyword">new</span> = <a class="code" href="group__irplib__framelist.html#ga5b86add048651f73424d2542a04946a0" title="Create an empty framelist.">irplib_framelist_new</a>();
+<a name="l00302"></a>00302     newsize = 0;
+<a name="l00303"></a>00303 
+<a name="l00304"></a>00304     <span class="keywordflow">for</span> (i = 0; i < <span class="keyword">self</span>->size; i++) {
+<a name="l00305"></a>00305         <span class="keyword">const</span> cpl_frame * frame = <span class="keyword">self</span>->frame[i];
+<a name="l00306"></a>00306         <span class="keyword">const</span> <span class="keywordtype">char</span> * ftag = cpl_frame_get_tag(frame);
+<a name="l00307"></a>00307         cpl_frame * copy;
+<a name="l00308"></a>00308         cpl_error_code error;
+<a name="l00309"></a>00309 
+<a name="l00310"></a>00310         <span class="keywordflow">if</span> (ftag == NULL) {
+<a name="l00311"></a>00311             <span class="comment">/* The frame is ill-formed */</span>
+<a name="l00312"></a>00312             <a class="code" href="group__irplib__framelist.html#ga7a5159e9d27ef277df3fb55b331aaf26" title="Deallocate an irplib_framelist with its frames and properties.">irplib_framelist_delete</a>(<span class="keyword">new</span>);
+<a name="l00313"></a>00313             cpl_ensure(0, CPL_ERROR_ILLEGAL_INPUT, NULL);
+<a name="l00314"></a>00314         }
+<a name="l00315"></a>00315 
+<a name="l00316"></a>00316         <span class="keywordflow">if</span> (strcmp(tag, ftag)) <span class="keywordflow">continue</span>;
+<a name="l00317"></a>00317 
+<a name="l00318"></a>00318         copy = cpl_frame_duplicate(frame);
+<a name="l00319"></a>00319 
+<a name="l00320"></a>00320         error = <a class="code" href="group__irplib__framelist.html#ga37e730f5627b4a0c7a81014f62421879" title="Add a frame to a framelist.">irplib_framelist_set</a>(<span class="keyword">new</span>, copy, newsize);
+<a name="l00321"></a>00321         assert(error == CPL_ERROR_NONE);
+<a name="l00322"></a>00322 
+<a name="l00323"></a>00323         <span class="keywordflow">if</span> (self->propertylist[i] != NULL) <span class="keyword">new</span>->propertylist[newsize]
+<a name="l00324"></a>00324             = cpl_propertylist_duplicate(self->propertylist[i]);
+<a name="l00325"></a>00325 
+<a name="l00326"></a>00326         newsize++;
+<a name="l00327"></a>00327     }
+<a name="l00328"></a>00328 
+<a name="l00329"></a>00329     assert( newsize == new->size );
+<a name="l00330"></a>00330 
+<a name="l00331"></a>00331     <span class="keywordflow">if</span> (newsize == 0) {
+<a name="l00332"></a>00332 <span class="preprocessor">#if defined CPL_HAVE_VA_ARGS && CPL_HAVE_VA_ARGS != 0</span>
+<a name="l00333"></a>00333 <span class="preprocessor"></span>        cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
+<a name="l00334"></a>00334                               <span class="stringliteral">"The list of %d frame(s) has no frames "</span>
+<a name="l00335"></a>00335                               <span class="stringliteral">"with tag: %s"</span>, self->size, tag);
+<a name="l00336"></a>00336 <span class="preprocessor">#else</span>
+<a name="l00337"></a>00337 <span class="preprocessor"></span>        cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
+<a name="l00338"></a>00338                               <span class="stringliteral">"The list of frame(s) has no frames "</span>
+<a name="l00339"></a>00339                               <span class="stringliteral">"with the given tag"</span>);
+<a name="l00340"></a>00340 <span class="preprocessor">#endif</span>
+<a name="l00341"></a>00341 <span class="preprocessor"></span>        <a class="code" href="group__irplib__framelist.html#ga7a5159e9d27ef277df3fb55b331aaf26" title="Deallocate an irplib_framelist with its frames and properties.">irplib_framelist_delete</a>(<span class="keyword">new</span>);
+<a name="l00342"></a>00342         <span class="keyword">new</span> = NULL;
+<a name="l00343"></a>00343     }
+<a name="l00344"></a>00344 
+<a name="l00345"></a>00345     <span class="keywordflow">return</span> <span class="keyword">new</span>;
+<a name="l00346"></a>00346 
+<a name="l00347"></a>00347 }
+<a name="l00348"></a>00348 
+<a name="l00349"></a>00349 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00359"></a>00359 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00360"></a><a class="code" href="group__irplib__framelist.html#gace77e5ae75183a22a0e5af9dd9018b01">00360</a> irplib_framelist * <a class="code" href="group__irplib__framelist.html#gace77e5ae75183a22a0e5af9dd9018b01" title="Extract the frames with the given tag from a framelist.">irplib_framelist_extract_regexp</a>(<span class="keyword">const</span> irplib_framelist* <span class="keyword">self</span>,
+<a name="l00361"></a>00361                                                    <span class="keyword">const</span> <span class="keywordtype">char</span> * regexp,
+<a name="l00362"></a>00362                                                    cpl_boolean invert)
+<a name="l00363"></a>00363 {
+<a name="l00364"></a>00364 
+<a name="l00365"></a>00365     irplib_framelist * <span class="keyword">new</span>;
+<a name="l00366"></a>00366     <span class="keywordtype">int</span> error;
+<a name="l00367"></a>00367     <span class="keywordtype">int</span> i, newsize;
+<a name="l00368"></a>00368     <span class="keyword">const</span> <span class="keywordtype">int</span> xor = invert == CPL_FALSE ? 0 : 1;
+<a name="l00369"></a>00369     regex_t re;
+<a name="l00370"></a>00370 
+<a name="l00371"></a>00371 
+<a name="l00372"></a>00372     cpl_ensure(<span class="keyword">self</span>   != NULL, CPL_ERROR_NULL_INPUT, NULL);
+<a name="l00373"></a>00373     cpl_ensure(regexp != NULL, CPL_ERROR_NULL_INPUT, NULL);
+<a name="l00374"></a>00374 
+<a name="l00375"></a>00375     error = regcomp(&re, regexp, REG_EXTENDED | REG_NOSUB);
+<a name="l00376"></a>00376     cpl_ensure(!error, CPL_ERROR_ILLEGAL_INPUT, NULL);
+<a name="l00377"></a>00377 
+<a name="l00378"></a>00378     <span class="keyword">new</span> = <a class="code" href="group__irplib__framelist.html#ga5b86add048651f73424d2542a04946a0" title="Create an empty framelist.">irplib_framelist_new</a>();
+<a name="l00379"></a>00379     newsize = 0;
+<a name="l00380"></a>00380 
+<a name="l00381"></a>00381     <span class="keywordflow">for</span> (i = 0; i < <span class="keyword">self</span>->size; i++) {
+<a name="l00382"></a>00382         <span class="keyword">const</span> cpl_frame * frame = <span class="keyword">self</span>->frame[i];
+<a name="l00383"></a>00383         <span class="keyword">const</span> <span class="keywordtype">char</span> * tag = cpl_frame_get_tag(frame);
+<a name="l00384"></a>00384         cpl_frame * copy;
+<a name="l00385"></a>00385 
+<a name="l00386"></a>00386         <span class="keywordflow">if</span> (tag == NULL) {
+<a name="l00387"></a>00387             <span class="comment">/* The frame is ill-formed */</span>
+<a name="l00388"></a>00388             <a class="code" href="group__irplib__framelist.html#ga7a5159e9d27ef277df3fb55b331aaf26" title="Deallocate an irplib_framelist with its frames and properties.">irplib_framelist_delete</a>(<span class="keyword">new</span>);
+<a name="l00389"></a>00389             regfree(&re);
+<a name="l00390"></a>00390             cpl_ensure(0, CPL_ERROR_ILLEGAL_INPUT, NULL);
+<a name="l00391"></a>00391         }
+<a name="l00392"></a>00392 
+<a name="l00393"></a>00393         <span class="keywordflow">if</span> ((regexec(&re, tag, (<span class="keywordtype">size_t</span>)0, NULL, 0) == REG_NOMATCH ? 1 : 0)
+<a name="l00394"></a>00394             ^ xor) <span class="keywordflow">continue</span>;
+<a name="l00395"></a>00395 
+<a name="l00396"></a>00396         copy = cpl_frame_duplicate(frame);
+<a name="l00397"></a>00397 
+<a name="l00398"></a>00398         error = (int)<a class="code" href="group__irplib__framelist.html#ga37e730f5627b4a0c7a81014f62421879" title="Add a frame to a framelist.">irplib_framelist_set</a>(<span class="keyword">new</span>, copy, newsize);
+<a name="l00399"></a>00399         assert(error == CPL_ERROR_NONE);
+<a name="l00400"></a>00400 
+<a name="l00401"></a>00401         <span class="keywordflow">if</span> (self->propertylist[i] != NULL) <span class="keyword">new</span>->propertylist[newsize]
+<a name="l00402"></a>00402             = cpl_propertylist_duplicate(self->propertylist[i]);
+<a name="l00403"></a>00403 
+<a name="l00404"></a>00404         newsize++;
+<a name="l00405"></a>00405 
+<a name="l00406"></a>00406     }
+<a name="l00407"></a>00407 
+<a name="l00408"></a>00408     regfree(&re);
+<a name="l00409"></a>00409 
+<a name="l00410"></a>00410     assert( newsize == new->size );
+<a name="l00411"></a>00411 
+<a name="l00412"></a>00412     <span class="keywordflow">if</span> (newsize == 0) {
+<a name="l00413"></a>00413 <span class="preprocessor">#if defined CPL_HAVE_VA_ARGS && CPL_HAVE_VA_ARGS != 0</span>
+<a name="l00414"></a>00414 <span class="preprocessor"></span>        cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
+<a name="l00415"></a>00415                               <span class="stringliteral">"The list of %d frame(s) has no frames "</span>
+<a name="l00416"></a>00416                               <span class="stringliteral">"that match: %s"</span>, self->size, regexp);
+<a name="l00417"></a>00417 <span class="preprocessor">#else</span>
+<a name="l00418"></a>00418 <span class="preprocessor"></span>        cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
+<a name="l00419"></a>00419                               <span class="stringliteral">"The list of frames has no frames "</span>
+<a name="l00420"></a>00420                               <span class="stringliteral">"that match the regular expression"</span>);
+<a name="l00421"></a>00421 <span class="preprocessor">#endif</span>
+<a name="l00422"></a>00422 <span class="preprocessor"></span>        <a class="code" href="group__irplib__framelist.html#ga7a5159e9d27ef277df3fb55b331aaf26" title="Deallocate an irplib_framelist with its frames and properties.">irplib_framelist_delete</a>(<span class="keyword">new</span>);
+<a name="l00423"></a>00423         <span class="keyword">new</span> = NULL;
+<a name="l00424"></a>00424     }
+<a name="l00425"></a>00425 
+<a name="l00426"></a>00426     <span class="keywordflow">return</span> <span class="keyword">new</span>;
+<a name="l00427"></a>00427 }
+<a name="l00428"></a>00428 
+<a name="l00429"></a>00429 
+<a name="l00430"></a>00430 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00437"></a>00437 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00438"></a><a class="code" href="group__irplib__framelist.html#ga2518fce55112b5008cb119a126e593d7">00438</a> <span class="keywordtype">int</span> <a class="code" href="group__irplib__framelist.html#ga2518fce55112b5008cb119a126e593d7" title="Get the size of a framelist.">irplib_framelist_get_size</a>(<span class="keyword">const</span> irplib_framelist * <span class="keyword">self</span>)
+<a name="l00439"></a>00439 {
+<a name="l00440"></a>00440 
+<a name="l00441"></a>00441     cpl_ensure(<span class="keyword">self</span> != NULL,  CPL_ERROR_NULL_INPUT, -1);
+<a name="l00442"></a>00442 
+<a name="l00443"></a>00443     <span class="keywordflow">return</span> <span class="keyword">self</span>->size;
+<a name="l00444"></a>00444 
+<a name="l00445"></a>00445 }
+<a name="l00446"></a>00446 
+<a name="l00447"></a>00447 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00455"></a>00455 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00456"></a><a class="code" href="group__irplib__framelist.html#gaba8797bbb8394f5574cd88b2f1984387">00456</a> cpl_frame * <a class="code" href="group__irplib__framelist.html#gaba8797bbb8394f5574cd88b2f1984387" title="Get the specified frame from the framelist.">irplib_framelist_get</a>(irplib_framelist * <span class="keyword">self</span>, <span class="keywordtype">int</span> pos)
+<a name="l00457"></a>00457 {
+<a name="l00458"></a>00458     <span class="keywordflow">return</span> (cpl_frame *)<a class="code" href="group__irplib__framelist.html#ga93d8f903729ea4b6fcb3eca85935716f" title="Get the specified frame from the framelist.">irplib_framelist_get_const</a>(<span class="keyword">self</span>, pos);
+<a name="l00459"></a>00459 
+<a name="l00460"></a>00460 }
+<a name="l00461"></a>00461 
+<a name="l00462"></a>00462 
+<a name="l00463"></a>00463 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00471"></a>00471 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00472"></a><a class="code" href="group__irplib__framelist.html#ga93d8f903729ea4b6fcb3eca85935716f">00472</a> <span class="keyword">const</span> cpl_frame * <a class="code" href="group__irplib__framelist.html#ga93d8f903729ea4b6fcb3eca85935716f" title="Get the specified frame from the framelist.">irplib_framelist_get_const</a>(<span class="keyword">const</span> irplib_framelist * <span class="keyword">self</span>,
+<a name="l00473"></a>00473                                              <span class="keywordtype">int</span> pos)
+<a name="l00474"></a>00474 {
+<a name="l00475"></a>00475 
+<a name="l00476"></a>00476     cpl_ensure(<span class="keyword">self</span> != NULL,      CPL_ERROR_NULL_INPUT,          NULL);
+<a name="l00477"></a>00477     cpl_ensure(pos >= 0,          CPL_ERROR_ILLEGAL_INPUT,       NULL);
+<a name="l00478"></a>00478     cpl_ensure(pos  < self->size, CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL);
+<a name="l00479"></a>00479 
+<a name="l00480"></a>00480     <span class="keywordflow">return</span> <span class="keyword">self</span>->frame[pos];
+<a name="l00481"></a>00481 
+<a name="l00482"></a>00482 }
+<a name="l00483"></a>00483 
+<a name="l00484"></a>00484 
+<a name="l00485"></a>00485 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00494"></a>00494 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00495"></a><a class="code" href="group__irplib__framelist.html#gada2c2e3f530a6dff763402eefceb5600">00495</a> cpl_error_code <a class="code" href="group__irplib__framelist.html#gada2c2e3f530a6dff763402eefceb5600" title="Duplicate a propertylist to the specified position in the framelist.">irplib_framelist_set_propertylist</a>(irplib_framelist * <span class="keyword">self</span>,
+<a name="l00496"></a>00496                                                  <span class="keywordtype">int</span> pos,
+<a name="l00497"></a>00497                                                  <span class="keyword">const</span> cpl_propertylist * list)
+<a name="l00498"></a>00498 {
+<a name="l00499"></a>00499 
+<a name="l00500"></a>00500     cpl_ensure_code(<span class="keyword">self</span> != NULL,      CPL_ERROR_NULL_INPUT);
+<a name="l00501"></a>00501     cpl_ensure_code(list != NULL,      CPL_ERROR_NULL_INPUT);
+<a name="l00502"></a>00502     cpl_ensure_code(pos  >= 0,         CPL_ERROR_ILLEGAL_INPUT);
+<a name="l00503"></a>00503     cpl_ensure_code(pos  < self->size, CPL_ERROR_ACCESS_OUT_OF_RANGE);
+<a name="l00504"></a>00504 
+<a name="l00505"></a>00505     cpl_propertylist_delete(self->propertylist[pos]);
+<a name="l00506"></a>00506 
+<a name="l00507"></a>00507     <span class="keyword">self</span>->propertylist[pos] = cpl_propertylist_duplicate(list);
+<a name="l00508"></a>00508 
+<a name="l00509"></a>00509     cpl_ensure_code(self->propertylist[pos] != NULL, cpl_error_get_code());
+<a name="l00510"></a>00510 
+<a name="l00511"></a>00511     <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l00512"></a>00512 
+<a name="l00513"></a>00513 }
+<a name="l00514"></a>00514 
+<a name="l00515"></a>00515 
+<a name="l00516"></a>00516 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00527"></a>00527 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00528"></a><a class="code" href="group__irplib__framelist.html#gab4858b1e9164f3a6cffcf40270f89032">00528</a> cpl_propertylist * <a class="code" href="group__irplib__framelist.html#gab4858b1e9164f3a6cffcf40270f89032" title="Get the propertylist of the specified frame in the framelist.">irplib_framelist_get_propertylist</a>(irplib_framelist * <span class="keyword">self</span>,
+<a name="l00529"></a>00529                                                      <span class="keywordtype">int</span> pos)
+<a name="l00530"></a>00530 {
+<a name="l00531"></a>00531 
+<a name="l00532"></a>00532     <span class="keywordflow">return</span> (cpl_propertylist *)<a class="code" href="group__irplib__framelist.html#ga7700dadcf17db5b86409e6cef233af4c" title="Get the propertylist of the specified frame in the framelist.">irplib_framelist_get_propertylist_const</a>(<span class="keyword">self</span>,
+<a name="l00533"></a>00533                                                                        pos);
+<a name="l00534"></a>00534 
+<a name="l00535"></a>00535 }
+<a name="l00536"></a>00536 
+<a name="l00537"></a>00537 
+<a name="l00538"></a>00538 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00549"></a>00549 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00550"></a><a class="code" href="group__irplib__framelist.html#ga7700dadcf17db5b86409e6cef233af4c">00550</a> <span class="keyword">const</span> cpl_propertylist * <a class="code" href="group__irplib__framelist.html#ga7700dadcf17db5b86409e6cef233af4c" title="Get the propertylist of the specified frame in the framelist.">irplib_framelist_get_propertylist_const</a>(
+<a name="l00551"></a>00551                                                   <span class="keyword">const</span> irplib_framelist * <span class="keyword">self</span>,
+<a name="l00552"></a>00552                                                   <span class="keywordtype">int</span> pos)
+<a name="l00553"></a>00553 {
+<a name="l00554"></a>00554     cpl_ensure(<span class="keyword">self</span> != NULL,      CPL_ERROR_NULL_INPUT,          NULL);
+<a name="l00555"></a>00555     cpl_ensure(pos  >= 0,         CPL_ERROR_ILLEGAL_INPUT,       NULL);
+<a name="l00556"></a>00556     cpl_ensure(pos  < self->size, CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL);
+<a name="l00557"></a>00557 
+<a name="l00558"></a>00558     cpl_ensure(self->propertylist[pos] != NULL,
+<a name="l00559"></a>00559                   CPL_ERROR_DATA_NOT_FOUND, NULL);
+<a name="l00560"></a>00560 
+<a name="l00561"></a>00561     <span class="keywordflow">return</span> <span class="keyword">self</span>->propertylist[pos];
+<a name="l00562"></a>00562 
+<a name="l00563"></a>00563 }
+<a name="l00564"></a>00564 
+<a name="l00565"></a>00565 
+<a name="l00566"></a>00566 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00580"></a>00580 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00581"></a><a class="code" href="group__irplib__framelist.html#ga6ce5701e84915514975d09e0100c6005">00581</a> cpl_error_code <a class="code" href="group__irplib__framelist.html#ga6ce5701e84915514975d09e0100c6005" title="Load the propertylist of the specified frame in the framelist.">irplib_framelist_load_propertylist</a>(irplib_framelist * <span class="keyword">self</span>,
+<a name="l00582"></a>00582                                                   <span class="keywordtype">int</span> pos, <span class="keywordtype">int</span> ind,
+<a name="l00583"></a>00583                                                   <span class="keyword">const</span> <span class="keywordtype">char</span> * regexp,
+<a name="l00584"></a>00584                                                   cpl_boolean invert)
+<a name="l00585"></a>00585 {
+<a name="l00586"></a>00586 
+<a name="l00587"></a>00587     <span class="keyword">const</span> <span class="keywordtype">char</span> * filename;
+<a name="l00588"></a>00588 
+<a name="l00589"></a>00589 
+<a name="l00590"></a>00590     cpl_ensure_code(<span class="keyword">self</span>   != NULL,    CPL_ERROR_NULL_INPUT);
+<a name="l00591"></a>00591     cpl_ensure_code(regexp != NULL,    CPL_ERROR_NULL_INPUT);
+<a name="l00592"></a>00592     cpl_ensure_code(pos >= 0,          CPL_ERROR_ILLEGAL_INPUT);
+<a name="l00593"></a>00593     cpl_ensure_code(pos <  self->size, CPL_ERROR_ACCESS_OUT_OF_RANGE);
+<a name="l00594"></a>00594 
+<a name="l00595"></a>00595     filename = cpl_frame_get_filename(self->frame[pos]);
+<a name="l00596"></a>00596 
+<a name="l00597"></a>00597     cpl_ensure_code(filename != NULL, cpl_error_get_code());
+<a name="l00598"></a>00598 
+<a name="l00599"></a>00599     cpl_propertylist_delete(self->propertylist[pos]);
+<a name="l00600"></a>00600 
+<a name="l00601"></a>00601     <span class="keyword">self</span>->propertylist[pos] = cpl_propertylist_load_regexp(filename, ind,
+<a name="l00602"></a>00602                                                            regexp,
+<a name="l00603"></a>00603                                                            invert ? 1 : 0);
+<a name="l00604"></a>00604 
+<a name="l00605"></a>00605     <span class="keywordflow">if</span> (self->propertylist[pos] == NULL) {
+<a name="l00606"></a>00606 <span class="preprocessor">#if defined CPL_HAVE_VA_ARGS && CPL_HAVE_VA_ARGS != 0</span>
+<a name="l00607"></a>00607 <span class="preprocessor"></span>        <span class="keywordflow">return</span> cpl_error_set_message(cpl_func, cpl_error_get_code(), <span class="stringliteral">"Could "</span>
+<a name="l00608"></a>00608                                      <span class="stringliteral">"not load FITS header from '%s' using "</span>
+<a name="l00609"></a>00609                                      <span class="stringliteral">"regexp '%s'"</span>, filename, regexp);
+<a name="l00610"></a>00610 <span class="preprocessor">#else</span>
+<a name="l00611"></a>00611 <span class="preprocessor"></span>        <span class="keywordflow">return</span> cpl_error_set_message(cpl_func, cpl_error_get_code(),
+<a name="l00612"></a>00612                                      <span class="stringliteral">"Could not load FITS header"</span>);
+<a name="l00613"></a>00613 <span class="preprocessor">#endif</span>
+<a name="l00614"></a>00614 <span class="preprocessor"></span>    }
+<a name="l00615"></a>00615 
+<a name="l00616"></a>00616     <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l00617"></a>00617 
+<a name="l00618"></a>00618 }
+<a name="l00619"></a>00619 
+<a name="l00620"></a>00620 
+<a name="l00621"></a>00621 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00635"></a>00635 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00636"></a><a class="code" href="group__irplib__framelist.html#gaf9204681e0b6aa2d952c974dcbd8729d">00636</a> cpl_error_code <a class="code" href="group__irplib__framelist.html#gaf9204681e0b6aa2d952c974dcbd8729d" title="Load the propertylists of all frames in the framelist.">irplib_framelist_load_propertylist_all</a>(irplib_framelist * <span class="keyword">self</span>,
+<a name="l00637"></a>00637                                                       <span class="keywordtype">int</span> ind,
+<a name="l00638"></a>00638                                                       <span class="keyword">const</span> <span class="keywordtype">char</span> * regexp,
+<a name="l00639"></a>00639                                                       cpl_boolean invert)
+<a name="l00640"></a>00640 {
+<a name="l00641"></a>00641 
+<a name="l00642"></a>00642     <span class="keywordtype">int</span> nprops = 0;
+<a name="l00643"></a>00643     <span class="keywordtype">int</span> nfiles = 0;
+<a name="l00644"></a>00644     <span class="keywordtype">int</span> i;
+<a name="l00645"></a>00645 
+<a name="l00646"></a>00646     cpl_ensure_code(<span class="keyword">self</span>   != NULL,    CPL_ERROR_NULL_INPUT);
+<a name="l00647"></a>00647     cpl_ensure_code(regexp != NULL,    CPL_ERROR_NULL_INPUT);
+<a name="l00648"></a>00648 
+<a name="l00649"></a>00649     <span class="keywordflow">for</span> (i=0; i < <span class="keyword">self</span>->size; i++) {
+<a name="l00650"></a>00650         <span class="keywordflow">if</span> (self->propertylist[i] == NULL)
+<a name="l00651"></a>00651             cpl_ensure_code(!<a class="code" href="group__irplib__framelist.html#ga6ce5701e84915514975d09e0100c6005" title="Load the propertylist of the specified frame in the framelist.">irplib_framelist_load_propertylist</a>(<span class="keyword">self</span>, i,
+<a name="l00652"></a>00652                                                                 ind,
+<a name="l00653"></a>00653                                                                 regexp,
+<a name="l00654"></a>00654                                                                 invert),
+<a name="l00655"></a>00655                                cpl_error_get_code());
+<a name="l00656"></a>00656         <span class="comment">/* Counting just for diagnostics - this actually causes</span>
+<a name="l00657"></a>00657 <span class="comment">           the whole list to be reiterated :-( */</span>
+<a name="l00658"></a>00658         nprops += cpl_propertylist_get_size(self->propertylist[i]);
+<a name="l00659"></a>00659         nfiles++;
+<a name="l00660"></a>00660     }
+<a name="l00661"></a>00661 
+<a name="l00662"></a>00662     cpl_msg_info(cpl_func, <span class="stringliteral">"List of %d frames has %d properties"</span>, nfiles,
+<a name="l00663"></a>00663                  nprops);
+<a name="l00664"></a>00664 
+<a name="l00665"></a>00665     <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l00666"></a>00666 
+<a name="l00667"></a>00667 }
+<a name="l00668"></a>00668 
+<a name="l00669"></a>00669 
+<a name="l00670"></a>00670 
+<a name="l00671"></a>00671 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00679"></a>00679 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00680"></a><a class="code" href="group__irplib__framelist.html#gab11bb60e44dea926cd50ee80c7fbbd14">00680</a> cpl_error_code <a class="code" href="group__irplib__framelist.html#gab11bb60e44dea926cd50ee80c7fbbd14" title="Set the tag of all frames in the list.">irplib_framelist_set_tag_all</a>(irplib_framelist * <span class="keyword">self</span>,
+<a name="l00681"></a>00681                                             <span class="keyword">const</span> <span class="keywordtype">char</span> * tag)
+<a name="l00682"></a>00682 {
+<a name="l00683"></a>00683 
+<a name="l00684"></a>00684     <span class="keywordtype">int</span> i;
+<a name="l00685"></a>00685 
+<a name="l00686"></a>00686     cpl_ensure_code(<span class="keyword">self</span> != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00687"></a>00687     cpl_ensure_code(tag  != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00688"></a>00688 
+<a name="l00689"></a>00689     <span class="keywordflow">for</span> (i=0; i < <span class="keyword">self</span>->size; i++)
+<a name="l00690"></a>00690         cpl_ensure_code(!cpl_frame_set_tag(self->frame[i], tag),
+<a name="l00691"></a>00691                            cpl_error_get_code());
+<a name="l00692"></a>00692 
+<a name="l00693"></a>00693     <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l00694"></a>00694 }
+<a name="l00695"></a>00695 
+<a name="l00696"></a>00696 
+<a name="l00697"></a>00697 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00711"></a>00711 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00712"></a><a class="code" href="group__irplib__framelist.html#ga37e730f5627b4a0c7a81014f62421879">00712</a> cpl_error_code <a class="code" href="group__irplib__framelist.html#ga37e730f5627b4a0c7a81014f62421879" title="Add a frame to a framelist.">irplib_framelist_set</a>(irplib_framelist * <span class="keyword">self</span>, cpl_frame * frame,
+<a name="l00713"></a>00713                                     <span class="keywordtype">int</span> pos)
+<a name="l00714"></a>00714 {
+<a name="l00715"></a>00715 
+<a name="l00716"></a>00716     cpl_ensure_code(<span class="keyword">self</span>  != NULL,     CPL_ERROR_NULL_INPUT);
+<a name="l00717"></a>00717     cpl_ensure_code(frame != NULL,     CPL_ERROR_NULL_INPUT);
+<a name="l00718"></a>00718     cpl_ensure_code(pos >= 0,          CPL_ERROR_ILLEGAL_INPUT);
+<a name="l00719"></a>00719 
+<a name="l00720"></a>00720     <span class="keywordflow">if</span> (pos == self->size) {
+<a name="l00721"></a>00721 
+<a name="l00722"></a>00722         <span class="keyword">self</span>->size++;
+<a name="l00723"></a>00723 
+<a name="l00724"></a>00724         irplib_framelist_set_size(<span class="keyword">self</span>);
+<a name="l00725"></a>00725 
+<a name="l00726"></a>00726     } <span class="keywordflow">else</span> {
+<a name="l00727"></a>00727 
+<a name="l00728"></a>00728         cpl_ensure_code(pos < self->size, CPL_ERROR_ACCESS_OUT_OF_RANGE);
+<a name="l00729"></a>00729 
+<a name="l00730"></a>00730         cpl_frame_delete(self->frame[pos]);
+<a name="l00731"></a>00731         cpl_propertylist_delete(self->propertylist[pos]);
+<a name="l00732"></a>00732     }
+<a name="l00733"></a>00733 
+<a name="l00734"></a>00734     <span class="keyword">self</span>->frame[pos] = frame;
+<a name="l00735"></a>00735     <span class="keyword">self</span>->propertylist[pos] = NULL;
+<a name="l00736"></a>00736 
+<a name="l00737"></a>00737     <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l00738"></a>00738 
+<a name="l00739"></a>00739 }
+<a name="l00740"></a>00740 
+<a name="l00741"></a>00741 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00750"></a>00750 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00751"></a><a class="code" href="group__irplib__framelist.html#gac66ea3ad4fc98c171f8b840229fe54ce">00751</a> cpl_error_code <a class="code" href="group__irplib__framelist.html#gac66ea3ad4fc98c171f8b840229fe54ce" title="Erase a frame from a framelist and delete it and its propertylist.">irplib_framelist_erase</a>(irplib_framelist * <span class="keyword">self</span>, <span class="keywordtype">int</span> pos)
+<a name="l00752"></a>00752 {
+<a name="l00753"></a>00753 
+<a name="l00754"></a>00754     <span class="keywordtype">int</span> i;
+<a name="l00755"></a>00755 
+<a name="l00756"></a>00756     cpl_ensure_code(<span class="keyword">self</span>  != NULL,    CPL_ERROR_NULL_INPUT);
+<a name="l00757"></a>00757     cpl_ensure_code(pos >= 0,         CPL_ERROR_ILLEGAL_INPUT);
+<a name="l00758"></a>00758     cpl_ensure_code(pos < self->size, CPL_ERROR_ACCESS_OUT_OF_RANGE);
+<a name="l00759"></a>00759 
+<a name="l00760"></a>00760 
+<a name="l00761"></a>00761     <span class="comment">/* Delete the specified frame and its propertylist */</span>
+<a name="l00762"></a>00762     cpl_frame_delete(self->frame[pos]);
+<a name="l00763"></a>00763     cpl_propertylist_delete(self->propertylist[pos]);
+<a name="l00764"></a>00764 
+<a name="l00765"></a>00765     <span class="comment">/* Move following frames down one position */</span>
+<a name="l00766"></a>00766     <span class="keywordflow">for</span> (i = pos+1; i < <span class="keyword">self</span>->size; i++) {
+<a name="l00767"></a>00767 
+<a name="l00768"></a>00768         <span class="keyword">self</span>->frame[i-1] = <span class="keyword">self</span>->frame[i];
+<a name="l00769"></a>00769 
+<a name="l00770"></a>00770         <span class="keyword">self</span>->propertylist[i-1] = <span class="keyword">self</span>->propertylist[i];
+<a name="l00771"></a>00771 
+<a name="l00772"></a>00772     }
+<a name="l00773"></a>00773 
+<a name="l00774"></a>00774     <span class="keyword">self</span>->size--;
+<a name="l00775"></a>00775 
+<a name="l00776"></a>00776     irplib_framelist_set_size(<span class="keyword">self</span>);
+<a name="l00777"></a>00777 
+<a name="l00778"></a>00778     <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l00779"></a>00779 
+<a name="l00780"></a>00780 }
+<a name="l00781"></a>00781 
+<a name="l00782"></a>00782 
+<a name="l00783"></a>00783 
+<a name="l00784"></a>00784 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00800"></a>00800 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00801"></a><a class="code" href="group__irplib__framelist.html#ga771f14f97f80a9bd7176d323999c9bce">00801</a> cpl_frame * <a class="code" href="group__irplib__framelist.html#ga771f14f97f80a9bd7176d323999c9bce" title="Erase a frame from a framelist and return it to the caller.">irplib_framelist_unset</a>(irplib_framelist * <span class="keyword">self</span>, <span class="keywordtype">int</span> pos,
+<a name="l00802"></a>00802                                    cpl_propertylist ** plist)
+<a name="l00803"></a>00803 
+<a name="l00804"></a>00804 {
+<a name="l00805"></a>00805     cpl_frame * frame;
+<a name="l00806"></a>00806     <span class="keywordtype">int</span> i;
+<a name="l00807"></a>00807 
+<a name="l00808"></a>00808 
+<a name="l00809"></a>00809     cpl_ensure(<span class="keyword">self</span>  != NULL,    CPL_ERROR_NULL_INPUT, NULL);
+<a name="l00810"></a>00810     cpl_ensure(pos >= 0,         CPL_ERROR_ILLEGAL_INPUT, NULL);
+<a name="l00811"></a>00811     cpl_ensure(pos < self->size, CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL);
+<a name="l00812"></a>00812 
+<a name="l00813"></a>00813     <span class="comment">/* Get the specified frame and its propertylist */</span>
+<a name="l00814"></a>00814     frame = <span class="keyword">self</span>->frame[pos];
+<a name="l00815"></a>00815 
+<a name="l00816"></a>00816     <span class="keywordflow">if</span> (plist != NULL)
+<a name="l00817"></a>00817         *plist = <span class="keyword">self</span>->propertylist[pos];
+<a name="l00818"></a>00818     <span class="keywordflow">else</span>
+<a name="l00819"></a>00819         cpl_propertylist_delete(self->propertylist[pos]);
+<a name="l00820"></a>00820 
+<a name="l00821"></a>00821 
+<a name="l00822"></a>00822     <span class="comment">/* Move following frames down one position */</span>
+<a name="l00823"></a>00823     <span class="keywordflow">for</span> (i = pos+1; i < <span class="keyword">self</span>->size; i++) {
+<a name="l00824"></a>00824 
+<a name="l00825"></a>00825         <span class="keyword">self</span>->frame[i-1] = <span class="keyword">self</span>->frame[i];
+<a name="l00826"></a>00826 
+<a name="l00827"></a>00827         <span class="keyword">self</span>->propertylist[i-1] = <span class="keyword">self</span>->propertylist[i];
+<a name="l00828"></a>00828 
+<a name="l00829"></a>00829     }
+<a name="l00830"></a>00830 
+<a name="l00831"></a>00831     <span class="keyword">self</span>->size--;
+<a name="l00832"></a>00832 
+<a name="l00833"></a>00833     irplib_framelist_set_size(<span class="keyword">self</span>);
+<a name="l00834"></a>00834 
+<a name="l00835"></a>00835     <span class="keywordflow">return</span> frame;
+<a name="l00836"></a>00836 
+<a name="l00837"></a>00837 }
+<a name="l00838"></a>00838 
+<a name="l00839"></a>00839 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00846"></a>00846 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00847"></a><a class="code" href="group__irplib__framelist.html#ga900ea254d9b2a2e4e3957360bbae4deb">00847</a> <span class="keywordtype">void</span> <a class="code" href="group__irplib__framelist.html#ga900ea254d9b2a2e4e3957360bbae4deb" title="Erase all frames from a framelist.">irplib_framelist_empty</a>(irplib_framelist * <span class="keyword">self</span>)
+<a name="l00848"></a>00848 {
+<a name="l00849"></a>00849 
+<a name="l00850"></a>00850     <span class="keywordflow">if</span> (<span class="keyword">self</span> != NULL) {
+<a name="l00851"></a>00851 
+<a name="l00852"></a>00852         <span class="comment">/* Deallocate all frames and their propertylists */</span>
+<a name="l00853"></a>00853         <span class="keywordflow">while</span> (self->size > 0) {
+<a name="l00854"></a>00854             <span class="keyword">self</span>->size--;
+<a name="l00855"></a>00855             cpl_frame_delete(self->frame[self->size]);
+<a name="l00856"></a>00856             cpl_propertylist_delete(self->propertylist[self->size]);
+<a name="l00857"></a>00857 
+<a name="l00858"></a>00858         }
+<a name="l00859"></a>00859         
+<a name="l00860"></a>00860         <span class="comment">/* Deallocate the arrays */</span>
+<a name="l00861"></a>00861         irplib_framelist_set_size(<span class="keyword">self</span>);
+<a name="l00862"></a>00862 
+<a name="l00863"></a>00863     }
+<a name="l00864"></a>00864 }
+<a name="l00865"></a>00865 
+<a name="l00866"></a>00866 
+<a name="l00867"></a>00867 
+<a name="l00868"></a>00868 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00906"></a>00906 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00907"></a><a class="code" href="group__irplib__framelist.html#gafed15e9e259ebad923b710f5eb0196ac">00907</a> cpl_error_code <a class="code" href="group__irplib__framelist.html#gafed15e9e259ebad923b710f5eb0196ac" title="Verify that a property is present for all frames.">irplib_framelist_contains</a>(<span class="keyword">const</span> irplib_framelist * <span class="keyword">self</span>,
+<a name="l00908"></a>00908                                          <span class="keyword">const</span> <span class="keywordtype">char</span> * key, cpl_type type,
+<a name="l00909"></a>00909                                          cpl_boolean is_equal, <span class="keywordtype">double</span> fp_tol)
+<a name="l00910"></a>00910 {
+<a name="l00911"></a>00911 
+<a name="l00912"></a>00912     <span class="keywordtype">char</span> * value_0;
+<a name="l00913"></a>00913     <span class="keywordtype">char</span> * value_i;
+<a name="l00914"></a>00914     cpl_type type_0 = CPL_TYPE_INVALID;
+<a name="l00915"></a>00915     <span class="keywordtype">int</span> i, ifirst = -1;  <span class="comment">/* First non-NULL propertylist */</span>
+<a name="l00916"></a>00916 
+<a name="l00917"></a>00917 
+<a name="l00918"></a>00918     cpl_ensure_code(<span class="keyword">self</span>  != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00919"></a>00919     cpl_ensure_code(key   != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00920"></a>00920     cpl_ensure_code(fp_tol >= 0.0, CPL_ERROR_ILLEGAL_INPUT);
+<a name="l00921"></a>00921 
+<a name="l00922"></a>00922     <span class="keywordflow">for</span> (i=0; i < <span class="keyword">self</span>->size; i++) {
+<a name="l00923"></a>00923         cpl_type type_i;
+<a name="l00924"></a>00924 
+<a name="l00925"></a>00925 
+<a name="l00926"></a>00926         <span class="keywordflow">if</span> (self->propertylist[i] == NULL) <span class="keywordflow">continue</span>;
+<a name="l00927"></a>00927         <span class="keywordflow">if</span> (ifirst < 0) ifirst = i;
+<a name="l00928"></a>00928 
+<a name="l00929"></a>00929         type_i = cpl_propertylist_get_type(self->propertylist[i], key);
+<a name="l00930"></a>00930 
+<a name="l00931"></a>00931         <span class="keywordflow">if</span> (type_i == CPL_TYPE_INVALID) {
+<a name="l00932"></a>00932             <span class="keywordflow">if</span> (type == CPL_TYPE_INVALID)
+<a name="l00933"></a>00933 <span class="preprocessor">#if defined CPL_HAVE_VA_ARGS && CPL_HAVE_VA_ARGS != 0</span>
+<a name="l00934"></a>00934 <span class="preprocessor"></span>                cpl_error_set_message(cpl_func, cpl_error_get_code(), <span class="stringliteral">"FITS "</span>
+<a name="l00935"></a>00935                                       <span class="stringliteral">"key '%s' is missing from file %s"</span>, key,
+<a name="l00936"></a>00936                                       cpl_frame_get_filename(self->frame[i]));
+<a name="l00937"></a>00937             <span class="keywordflow">else</span>
+<a name="l00938"></a>00938                 cpl_error_set_message(cpl_func, cpl_error_get_code(),
+<a name="l00939"></a>00939                                       <span class="stringliteral">"FITS key '%s' [%s] is missing from file "</span>
+<a name="l00940"></a>00940                                       <span class="stringliteral">"%s"</span>, key, cpl_type_get_name(type),
+<a name="l00941"></a>00941                                       cpl_frame_get_filename(self->frame[i]));
+<a name="l00942"></a>00942 <span class="preprocessor">#else</span>
+<a name="l00943"></a>00943 <span class="preprocessor"></span>                cpl_error_set_message(cpl_func, cpl_error_get_code(),
+<a name="l00944"></a>00944                                       <span class="stringliteral">"A FITS key is missing from a file"</span>);
+<a name="l00945"></a>00945             <span class="keywordflow">else</span>
+<a name="l00946"></a>00946                 cpl_error_set_message(cpl_func, cpl_error_get_code(),
+<a name="l00947"></a>00947                                       <span class="stringliteral">"A FITS key is missing from a file"</span>);
+<a name="l00948"></a>00948 <span class="preprocessor">#endif</span>
+<a name="l00949"></a>00949 <span class="preprocessor"></span>            <span class="keywordflow">return</span> cpl_error_get_code();
+<a name="l00950"></a>00950         }
+<a name="l00951"></a>00951 
+<a name="l00952"></a>00952         <span class="keywordflow">if</span> (type != CPL_TYPE_INVALID && type_i != type) {
+<a name="l00953"></a>00953 <span class="preprocessor">#if defined CPL_HAVE_VA_ARGS && CPL_HAVE_VA_ARGS != 0</span>
+<a name="l00954"></a>00954 <span class="preprocessor"></span>            <span class="keywordflow">return</span> cpl_error_set_message(cpl_func, CPL_ERROR_INVALID_TYPE,
+<a name="l00955"></a>00955                                          <span class="stringliteral">"FITS key '%s' has type %s instead of "</span>
+<a name="l00956"></a>00956                                          <span class="stringliteral">"%s in file %s"</span>, key,
+<a name="l00957"></a>00957                                          cpl_type_get_name(type_i),
+<a name="l00958"></a>00958                                          cpl_type_get_name(type),
+<a name="l00959"></a>00959                                          cpl_frame_get_filename(self->frame[i]));
+<a name="l00960"></a>00960 <span class="preprocessor">#else</span>
+<a name="l00961"></a>00961 <span class="preprocessor"></span>            <span class="keywordflow">return</span> cpl_error_set_message(cpl_func, CPL_ERROR_INVALID_TYPE,
+<a name="l00962"></a>00962                                          <span class="stringliteral">"A FITS key had an unexpected type"</span>);
+<a name="l00963"></a>00963 <span class="preprocessor">#endif</span>
+<a name="l00964"></a>00964 <span class="preprocessor"></span>
+<a name="l00965"></a>00965         }
+<a name="l00966"></a>00966 
+<a name="l00967"></a>00967         <span class="keywordflow">if</span> (!is_equal) <span class="keywordflow">continue</span>;
+<a name="l00968"></a>00968 
+<a name="l00969"></a>00969         <span class="keywordflow">if</span> (type_0 == CPL_TYPE_INVALID) {
+<a name="l00970"></a>00970             type_0 = type_i;
+<a name="l00971"></a>00971             <span class="keywordflow">continue</span>;
+<a name="l00972"></a>00972         }
+<a name="l00973"></a>00973 
+<a name="l00974"></a>00974         <span class="keywordflow">if</span> (type_i != type_0) {
+<a name="l00975"></a>00975             assert( type == CPL_TYPE_INVALID );
+<a name="l00976"></a>00976 <span class="preprocessor">#if defined CPL_HAVE_VA_ARGS && CPL_HAVE_VA_ARGS != 0</span>
+<a name="l00977"></a>00977 <span class="preprocessor"></span>            <span class="keywordflow">return</span> cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH,
+<a name="l00978"></a>00978                                          <span class="stringliteral">"FITS key '%s' has different types "</span>
+<a name="l00979"></a>00979                                          <span class="stringliteral">"(%s <=> %s) in files %s and %s"</span>, key,
+<a name="l00980"></a>00980                                          cpl_type_get_name(type_0),
+<a name="l00981"></a>00981                                          cpl_type_get_name(type_i),
+<a name="l00982"></a>00982                                          cpl_frame_get_filename(self->frame[0]),
+<a name="l00983"></a>00983                                          cpl_frame_get_filename(self->frame[i]));
+<a name="l00984"></a>00984 <span class="preprocessor">#else</span>
+<a name="l00985"></a>00985 <span class="preprocessor"></span>            <span class="keywordflow">return</span> cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH,
+<a name="l00986"></a>00986                                          <span class="stringliteral">"A FITS key has different types in "</span>
+<a name="l00987"></a>00987                                          <span class="stringliteral">"two files"</span>);
+<a name="l00988"></a>00988 <span class="preprocessor">#endif</span>
+<a name="l00989"></a>00989 <span class="preprocessor"></span>        }
+<a name="l00990"></a>00990 
+<a name="l00991"></a>00991         <span class="keywordflow">if</span> (irplib_property_equal(self->propertylist[ifirst],
+<a name="l00992"></a>00992                                   self->propertylist[i],
+<a name="l00993"></a>00993                                   key, type_0, fp_tol, &value_0, &value_i))
+<a name="l00994"></a>00994             <span class="keywordflow">continue</span>;
+<a name="l00995"></a>00995 
+<a name="l00996"></a>00996         <span class="keywordflow">if</span> ((type_0 == CPL_TYPE_FLOAT || type_0 == CPL_TYPE_DOUBLE)
+<a name="l00997"></a>00997             && fp_tol > 0.0) {
+<a name="l00998"></a>00998 <span class="preprocessor">#if defined CPL_HAVE_VA_ARGS && CPL_HAVE_VA_ARGS != 0</span>
+<a name="l00999"></a>00999 <span class="preprocessor"></span>            cpl_error_set_message(cpl_func, CPL_ERROR_INCOMPATIBLE_INPUT, <span class="stringliteral">"FITS"</span>
+<a name="l01000"></a>01000                                   <span class="stringliteral">" key '%s' [%s] has values that differ by "</span>
+<a name="l01001"></a>01001                                   <span class="stringliteral">"more than %g (%s <=> %s) in files %s and %s"</span>,
+<a name="l01002"></a>01002                                   key, cpl_type_get_name(type_0), fp_tol,
+<a name="l01003"></a>01003                                   value_0, value_i,
+<a name="l01004"></a>01004                                   cpl_frame_get_filename(self->frame[0]),
+<a name="l01005"></a>01005                                   cpl_frame_get_filename(self->frame[i]));
+<a name="l01006"></a>01006 <span class="preprocessor">#else</span>
+<a name="l01007"></a>01007 <span class="preprocessor"></span>            cpl_error_set_message(cpl_func, CPL_ERROR_INCOMPATIBLE_INPUT, <span class="stringliteral">"A "</span>
+<a name="l01008"></a>01008                                   <span class="stringliteral">"FITS key has values that differ by more "</span>
+<a name="l01009"></a>01009                                   <span class="stringliteral">"than the allowed tolerance in two file"</span>);
+<a name="l01010"></a>01010 <span class="preprocessor">#endif</span>
+<a name="l01011"></a>01011 <span class="preprocessor"></span>        } <span class="keywordflow">else</span> {
+<a name="l01012"></a>01012 <span class="preprocessor">#if defined CPL_HAVE_VA_ARGS && CPL_HAVE_VA_ARGS != 0</span>
+<a name="l01013"></a>01013 <span class="preprocessor"></span>            cpl_error_set_message(cpl_func, CPL_ERROR_INCOMPATIBLE_INPUT,
+<a name="l01014"></a>01014                                   <span class="stringliteral">"FITS key '%s' [%s] has different values "</span>
+<a name="l01015"></a>01015                                   <span class="stringliteral">"(%s <=> %s) in files %s and %s"</span>, key,
+<a name="l01016"></a>01016                                   cpl_type_get_name(type_0),
+<a name="l01017"></a>01017                                   value_0, value_i,
+<a name="l01018"></a>01018                                   cpl_frame_get_filename(self->frame[0]),
+<a name="l01019"></a>01019                                   cpl_frame_get_filename(self->frame[i]));
+<a name="l01020"></a>01020 <span class="preprocessor">#else</span>
+<a name="l01021"></a>01021 <span class="preprocessor"></span>            cpl_error_set_message(cpl_func, CPL_ERROR_INCOMPATIBLE_INPUT, <span class="stringliteral">"A "</span>
+<a name="l01022"></a>01022                                   <span class="stringliteral">"FITS key has different values in two files"</span>);
+<a name="l01023"></a>01023 <span class="preprocessor">#endif</span>
+<a name="l01024"></a>01024 <span class="preprocessor"></span>        }
+<a name="l01025"></a>01025         cpl_free(value_0);
+<a name="l01026"></a>01026         cpl_free(value_i);
+<a name="l01027"></a>01027 
+<a name="l01028"></a>01028         <span class="keywordflow">return</span> cpl_error_get_code();
+<a name="l01029"></a>01029     }        
+<a name="l01030"></a>01030 
+<a name="l01031"></a>01031     <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l01032"></a>01032 
+<a name="l01033"></a>01033 }
+<a name="l01034"></a>01034 
+<a name="l01035"></a>01035 
+<a name="l01036"></a>01036 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01049"></a>01049 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01050"></a><a class="code" href="group__irplib__framelist.html#ga0ff6c5e3b778c607544ca04ca3fb9e94">01050</a> cpl_imagelist * <a class="code" href="group__irplib__framelist.html#ga0ff6c5e3b778c607544ca04ca3fb9e94" title="Load an imagelist from a framelist.">irplib_imagelist_load_framelist</a>(<span class="keyword">const</span> irplib_framelist * <span class="keyword">self</span>,
+<a name="l01051"></a>01051                                                 cpl_type pixeltype,
+<a name="l01052"></a>01052                                                 <span class="keywordtype">int</span> planenum,
+<a name="l01053"></a>01053                                                 <span class="keywordtype">int</span> extnum)
+<a name="l01054"></a>01054 {
+<a name="l01055"></a>01055 
+<a name="l01056"></a>01056     cpl_imagelist * list = NULL;
+<a name="l01057"></a>01057     cpl_image     * image = NULL;
+<a name="l01058"></a>01058     <span class="keywordtype">int</span> i;
+<a name="l01059"></a>01059 
+<a name="l01060"></a>01060 
+<a name="l01061"></a>01061     cpl_ensure(<span class="keyword">self</span> != NULL,  CPL_ERROR_NULL_INPUT,          NULL);
+<a name="l01062"></a>01062     cpl_ensure(extnum >= 0,   CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL);
+<a name="l01063"></a>01063     cpl_ensure(planenum >= 0, CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL);
+<a name="l01064"></a>01064 
+<a name="l01065"></a>01065     list = cpl_imagelist_new();
+<a name="l01066"></a>01066 
+<a name="l01067"></a>01067     <span class="keywordflow">for</span> (i=0; i < <span class="keyword">self</span>->size; i++, image = NULL) {
+<a name="l01068"></a>01068         <span class="keyword">const</span> <span class="keywordtype">char</span> * filename = cpl_frame_get_filename(self->frame[i]);
+<a name="l01069"></a>01069         cpl_error_code error;
+<a name="l01070"></a>01070 
+<a name="l01071"></a>01071         <span class="keywordflow">if</span> (filename == NULL) <span class="keywordflow">break</span>;
+<a name="l01072"></a>01072 
+<a name="l01073"></a>01073         image = cpl_image_load(filename, pixeltype, planenum, extnum);
+<a name="l01074"></a>01074         <span class="keywordflow">if</span> (image == NULL) {
+<a name="l01075"></a>01075 <span class="preprocessor">#if defined CPL_HAVE_VA_ARGS && CPL_HAVE_VA_ARGS != 0</span>
+<a name="l01076"></a>01076 <span class="preprocessor"></span>            (void)cpl_error_set_message(cpl_func, cpl_error_get_code(),
+<a name="l01077"></a>01077                                         <span class="stringliteral">"Could not load FITS-image from plane "</span>
+<a name="l01078"></a>01078                                         <span class="stringliteral">"%d in extension %d in file %s"</span>,
+<a name="l01079"></a>01079                                         planenum, extnum, filename);
+<a name="l01080"></a>01080 <span class="preprocessor">#else</span>
+<a name="l01081"></a>01081 <span class="preprocessor"></span>            (void)cpl_error_set_message(cpl_func, cpl_error_get_code(),
+<a name="l01082"></a>01082                                         <span class="stringliteral">"Could not load FITS-image"</span>);
+<a name="l01083"></a>01083 <span class="preprocessor">#endif</span>
+<a name="l01084"></a>01084 <span class="preprocessor"></span>            <span class="keywordflow">break</span>;
+<a name="l01085"></a>01085         }
+<a name="l01086"></a>01086 
+<a name="l01087"></a>01087         error = cpl_imagelist_set(list, image, i);
+<a name="l01088"></a>01088         assert(error == CPL_ERROR_NONE);
+<a name="l01089"></a>01089     }
+<a name="l01090"></a>01090 
+<a name="l01091"></a>01091     cpl_image_delete(image);
+<a name="l01092"></a>01092     
+<a name="l01093"></a>01093     <span class="keywordflow">if</span> (cpl_imagelist_get_size(list) != self->size) {
+<a name="l01094"></a>01094         cpl_imagelist_delete(list);
+<a name="l01095"></a>01095         list = NULL;
+<a name="l01096"></a>01096         assert(cpl_error_get_code() != CPL_ERROR_NONE);
+<a name="l01097"></a>01097     }
+<a name="l01098"></a>01098 
+<a name="l01099"></a>01099     <span class="keywordflow">return</span> list;
+<a name="l01100"></a>01100 
+<a name="l01101"></a>01101 }
+<a name="l01102"></a>01102 
+<a name="l01103"></a>01103 
+<a name="l01107"></a>01107 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01119"></a>01119 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01120"></a>01120 <span class="keyword">static</span> <span class="keywordtype">void</span> irplib_framelist_set_size(irplib_framelist * <span class="keyword">self</span>)
+<a name="l01121"></a>01121 {
+<a name="l01122"></a>01122 
+<a name="l01123"></a>01123 
+<a name="l01124"></a>01124     assert( <span class="keyword">self</span> != NULL);
+<a name="l01125"></a>01125 
+<a name="l01126"></a>01126     <span class="keywordflow">if</span> (self->size == 0) {
+<a name="l01127"></a>01127         <span class="comment">/* The list has been emptied */</span>
+<a name="l01128"></a>01128         cpl_free(self->frame);
+<a name="l01129"></a>01129         cpl_free(self->propertylist);
+<a name="l01130"></a>01130         <span class="keyword">self</span>->frame = NULL;
+<a name="l01131"></a>01131         <span class="keyword">self</span>->propertylist = NULL;
+<a name="l01132"></a>01132     } <span class="keywordflow">else</span> {
+<a name="l01133"></a>01133         <span class="comment">/* Update the size of the arrays */</span>
+<a name="l01134"></a>01134 
+<a name="l01135"></a>01135         <span class="keyword">self</span>->frame = cpl_realloc(self->frame, self->size * <span class="keyword">sizeof</span>(cpl_frame*));
+<a name="l01136"></a>01136         <span class="keyword">self</span>->propertylist =
+<a name="l01137"></a>01137             cpl_realloc(self->propertylist,
+<a name="l01138"></a>01138                         self->size * <span class="keyword">sizeof</span>(cpl_propertylist*));
+<a name="l01139"></a>01139     }
+<a name="l01140"></a>01140 
+<a name="l01141"></a>01141 }
+<a name="l01142"></a>01142 
+<a name="l01143"></a>01143 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01167"></a>01167 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01168"></a>01168 <span class="keyword">static</span> cpl_boolean irplib_property_equal(<span class="keyword">const</span> cpl_propertylist * <span class="keyword">self</span>,
+<a name="l01169"></a>01169                                          <span class="keyword">const</span> cpl_propertylist * other,
+<a name="l01170"></a>01170                                          <span class="keyword">const</span> <span class="keywordtype">char</span> * key, cpl_type type,
+<a name="l01171"></a>01171                                          <span class="keywordtype">double</span> fp_tol,
+<a name="l01172"></a>01172                                          <span class="keywordtype">char</span> ** sstring, <span class="keywordtype">char</span> ** ostring)
+<a name="l01173"></a>01173 {
+<a name="l01174"></a>01174 
+<a name="l01175"></a>01175     cpl_boolean equal;
+<a name="l01176"></a>01176 
+<a name="l01177"></a>01177 
+<a name="l01178"></a>01178     assert(<span class="keyword">self</span>    != NULL);
+<a name="l01179"></a>01179     assert(other   != NULL);
+<a name="l01180"></a>01180     assert(key     != NULL);
+<a name="l01181"></a>01181     assert(sstring != NULL);
+<a name="l01182"></a>01182     assert(ostring != NULL);
+<a name="l01183"></a>01183 
+<a name="l01184"></a>01184     <span class="comment">/* FIXME: disable for better performance also with debugging */</span>
+<a name="l01185"></a>01185     assert(cpl_propertylist_get_type(other, key) == type);
+<a name="l01186"></a>01186     assert(fp_tol >= 0.0);
+<a name="l01187"></a>01187 
+<a name="l01188"></a>01188     <span class="keywordflow">if</span> (<span class="keyword">self</span> == other) <span class="keywordflow">return</span> CPL_TRUE;
+<a name="l01189"></a>01189 
+<a name="l01190"></a>01190     <span class="keywordflow">switch</span> (type) {
+<a name="l01191"></a>01191 
+<a name="l01192"></a>01192     <span class="keywordflow">case</span> CPL_TYPE_CHAR: {
+<a name="l01193"></a>01193         <span class="keyword">const</span> <span class="keywordtype">char</span> svalue = cpl_propertylist_get_char(<span class="keyword">self</span>, key);
+<a name="l01194"></a>01194         <span class="keyword">const</span> <span class="keywordtype">char</span> ovalue = cpl_propertylist_get_char(other, key);
+<a name="l01195"></a>01195 
+<a name="l01196"></a>01196         equal = svalue == ovalue ? CPL_TRUE : CPL_FALSE;
+<a name="l01197"></a>01197         <span class="keywordflow">if</span> (!equal) {
+<a name="l01198"></a>01198             *sstring = cpl_sprintf(<span class="stringliteral">"%c"</span>, svalue);
+<a name="l01199"></a>01199             *ostring = cpl_sprintf(<span class="stringliteral">"%c"</span>, ovalue);
+<a name="l01200"></a>01200         }
+<a name="l01201"></a>01201         <span class="keywordflow">break</span>;
+<a name="l01202"></a>01202     }
+<a name="l01203"></a>01203 
+<a name="l01204"></a>01204     <span class="keywordflow">case</span> CPL_TYPE_BOOL: {
+<a name="l01205"></a>01205         <span class="keyword">const</span> <span class="keywordtype">int</span> svalue = cpl_propertylist_get_bool(<span class="keyword">self</span>, key);
+<a name="l01206"></a>01206         <span class="keyword">const</span> <span class="keywordtype">int</span> ovalue = cpl_propertylist_get_bool(other, key);
+<a name="l01207"></a>01207 
+<a name="l01208"></a>01208         equal = svalue == ovalue ? CPL_TRUE : CPL_FALSE;
+<a name="l01209"></a>01209         <span class="keywordflow">if</span> (!equal) {
+<a name="l01210"></a>01210             *sstring = cpl_strdup(svalue == 0 ? <span class="stringliteral">"F"</span> : <span class="stringliteral">"T"</span>);
+<a name="l01211"></a>01211             *ostring = cpl_strdup(ovalue == 0 ? <span class="stringliteral">"F"</span> : <span class="stringliteral">"T"</span>);
+<a name="l01212"></a>01212         }
+<a name="l01213"></a>01213         <span class="keywordflow">break</span>;
+<a name="l01214"></a>01214     }
+<a name="l01215"></a>01215 
+<a name="l01216"></a>01216     <span class="keywordflow">case</span> CPL_TYPE_INT: {
+<a name="l01217"></a>01217         <span class="keyword">const</span> <span class="keywordtype">int</span> svalue = cpl_propertylist_get_int(<span class="keyword">self</span>, key);
+<a name="l01218"></a>01218         <span class="keyword">const</span> <span class="keywordtype">int</span> ovalue = cpl_propertylist_get_int(other, key);
+<a name="l01219"></a>01219 
+<a name="l01220"></a>01220         equal = svalue == ovalue ? CPL_TRUE : CPL_FALSE;
+<a name="l01221"></a>01221         <span class="keywordflow">if</span> (!equal) {
+<a name="l01222"></a>01222             *sstring = cpl_sprintf(<span class="stringliteral">"%d"</span>, svalue);
+<a name="l01223"></a>01223             *ostring = cpl_sprintf(<span class="stringliteral">"%d"</span>, ovalue);
+<a name="l01224"></a>01224         }
+<a name="l01225"></a>01225         <span class="keywordflow">break</span>;
+<a name="l01226"></a>01226     }
+<a name="l01227"></a>01227 
+<a name="l01228"></a>01228     <span class="keywordflow">case</span> CPL_TYPE_LONG: {
+<a name="l01229"></a>01229         <span class="keyword">const</span> <span class="keywordtype">long</span> svalue = cpl_propertylist_get_long(<span class="keyword">self</span>, key);
+<a name="l01230"></a>01230         <span class="keyword">const</span> <span class="keywordtype">long</span> ovalue = cpl_propertylist_get_long(other, key);
+<a name="l01231"></a>01231 
+<a name="l01232"></a>01232         equal = svalue == ovalue ? CPL_TRUE : CPL_FALSE;
+<a name="l01233"></a>01233         <span class="keywordflow">if</span> (!equal) {
+<a name="l01234"></a>01234             *sstring = cpl_sprintf(<span class="stringliteral">"%ld"</span>, svalue);
+<a name="l01235"></a>01235             *ostring = cpl_sprintf(<span class="stringliteral">"%ld"</span>, ovalue);
+<a name="l01236"></a>01236         }
+<a name="l01237"></a>01237         <span class="keywordflow">break</span>;
+<a name="l01238"></a>01238     }
+<a name="l01239"></a>01239 
+<a name="l01240"></a>01240     <span class="keywordflow">case</span> CPL_TYPE_FLOAT: {
+<a name="l01241"></a>01241         <span class="keyword">const</span> <span class="keywordtype">double</span> svalue = (double)cpl_propertylist_get_float(<span class="keyword">self</span>, key);
+<a name="l01242"></a>01242         <span class="keyword">const</span> <span class="keywordtype">double</span> ovalue = (double)cpl_propertylist_get_float(other, key);
+<a name="l01243"></a>01243 
+<a name="l01244"></a>01244         equal = (fabs(svalue - ovalue) <= fp_tol) ? CPL_TRUE : CPL_FALSE;
+<a name="l01245"></a>01245         <span class="keywordflow">if</span> (!equal) {
+<a name="l01246"></a>01246             *sstring = cpl_sprintf(<span class="stringliteral">"%f"</span>, svalue);
+<a name="l01247"></a>01247             *ostring = cpl_sprintf(<span class="stringliteral">"%f"</span>, ovalue);
+<a name="l01248"></a>01248         }
+<a name="l01249"></a>01249         <span class="keywordflow">break</span>;
+<a name="l01250"></a>01250     }
+<a name="l01251"></a>01251 
+<a name="l01252"></a>01252     <span class="keywordflow">case</span> CPL_TYPE_DOUBLE: {
+<a name="l01253"></a>01253         <span class="keyword">const</span> <span class="keywordtype">double</span> svalue = cpl_propertylist_get_double(<span class="keyword">self</span>, key);
+<a name="l01254"></a>01254         <span class="keyword">const</span> <span class="keywordtype">double</span> ovalue = cpl_propertylist_get_double(other, key);
+<a name="l01255"></a>01255 
+<a name="l01256"></a>01256         equal = (fabs(svalue - ovalue) <= fp_tol) ? CPL_TRUE : CPL_FALSE;
+<a name="l01257"></a>01257         <span class="keywordflow">if</span> (!equal) {
+<a name="l01258"></a>01258             *sstring = cpl_sprintf(<span class="stringliteral">"%g"</span>, svalue);
+<a name="l01259"></a>01259             *ostring = cpl_sprintf(<span class="stringliteral">"%g"</span>, ovalue);
+<a name="l01260"></a>01260         }
+<a name="l01261"></a>01261         <span class="keywordflow">break</span>;
+<a name="l01262"></a>01262     }
+<a name="l01263"></a>01263     <span class="keywordflow">case</span> CPL_TYPE_STRING: {
+<a name="l01264"></a>01264         <span class="keyword">const</span> <span class="keywordtype">char</span> * svalue = cpl_propertylist_get_string(<span class="keyword">self</span>, key);
+<a name="l01265"></a>01265         <span class="keyword">const</span> <span class="keywordtype">char</span> * ovalue = cpl_propertylist_get_string(other, key);
+<a name="l01266"></a>01266 
+<a name="l01267"></a>01267         equal = strcmp(svalue, ovalue) == 0 ? CPL_TRUE : CPL_FALSE;
+<a name="l01268"></a>01268         <span class="keywordflow">if</span> (!equal) {
+<a name="l01269"></a>01269             *sstring = cpl_strdup(svalue);
+<a name="l01270"></a>01270             *ostring = cpl_strdup(ovalue);
+<a name="l01271"></a>01271         }
+<a name="l01272"></a>01272         <span class="keywordflow">break</span>;
+<a name="l01273"></a>01273     }
+<a name="l01274"></a>01274     <span class="keywordflow">default</span>:
+<a name="l01275"></a>01275         <span class="comment">/* Unknown property type */</span>
+<a name="l01276"></a>01276         assert( 0 );
+<a name="l01277"></a>01277 
+<a name="l01278"></a>01278         equal = CPL_FALSE; <span class="comment">/* In case of -DNDEBUG */</span>
+<a name="l01279"></a>01279 
+<a name="l01280"></a>01280     }
+<a name="l01281"></a>01281 
+<a name="l01282"></a>01282     <span class="keywordflow">if</span> (!equal) {
+<a name="l01283"></a>01283         assert( *sstring != NULL );
+<a name="l01284"></a>01284         assert( *ostring != NULL );
+<a name="l01285"></a>01285     }
+<a name="l01286"></a>01286 
+<a name="l01287"></a>01287     <span class="keywordflow">return</span> equal;
+<a name="l01288"></a>01288 
+<a name="l01289"></a>01289 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/irplib__framelist_8h_source.html b/html/irplib__framelist_8h_source.html
new file mode 100644
index 0000000..15dde46
--- /dev/null
+++ b/html/irplib__framelist_8h_source.html
@@ -0,0 +1,123 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: irplib_framelist.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>irplib_framelist.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: irplib_framelist.h,v 1.8 2008/11/20 10:24:47 llundin Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the irplib package </span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: llundin $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2008/11/20 10:24:47 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.8 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifndef IRPLIB_FRAMELIST_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#define IRPLIB_FRAMELIST_H</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span>
+<a name="l00031"></a>00031 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00032"></a>00032 <span class="comment">                                   Includes</span>
+<a name="l00033"></a>00033 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00034"></a>00034 
+<a name="l00035"></a>00035 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00038"></a>00038 <span class="comment">                                   New type</span>
+<a name="l00039"></a>00039 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00040"></a>00040 
+<a name="l00041"></a>00041 <span class="keyword">typedef</span> <span class="keyword">struct </span>_irplib_framelist_ irplib_framelist;
+<a name="l00042"></a>00042 
+<a name="l00043"></a>00043 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00044"></a>00044 <span class="comment">                                   Function prototypes</span>
+<a name="l00045"></a>00045 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00046"></a>00046 
+<a name="l00047"></a>00047 <span class="comment">/* Constructors and destructor */</span>
+<a name="l00048"></a>00048 
+<a name="l00049"></a>00049 irplib_framelist * <a class="code" href="group__irplib__framelist.html#ga5b86add048651f73424d2542a04946a0" title="Create an empty framelist.">irplib_framelist_new</a>(<span class="keywordtype">void</span>);
+<a name="l00050"></a>00050 
+<a name="l00051"></a>00051 <span class="keywordtype">void</span> <a class="code" href="group__irplib__framelist.html#ga7a5159e9d27ef277df3fb55b331aaf26" title="Deallocate an irplib_framelist with its frames and properties.">irplib_framelist_delete</a>(irplib_framelist *);
+<a name="l00052"></a>00052 
+<a name="l00053"></a>00053 irplib_framelist * <a class="code" href="group__irplib__framelist.html#ga30cbfd003c6e6a6a42e610442f0b1bd1" title="Create an irplib_framelist from a cpl_framelist.">irplib_framelist_cast</a>(<span class="keyword">const</span> cpl_frameset *);
+<a name="l00054"></a>00054 
+<a name="l00055"></a>00055 irplib_framelist * <a class="code" href="group__irplib__framelist.html#ga86d6746d1c19356417815f7df04c3396" title="Extract the frames with the given tag from a framelist.">irplib_framelist_extract</a>(<span class="keyword">const</span> irplib_framelist *,
+<a name="l00056"></a>00056                                             <span class="keyword">const</span> <span class="keywordtype">char</span> *);
+<a name="l00057"></a>00057 irplib_framelist * <a class="code" href="group__irplib__framelist.html#gace77e5ae75183a22a0e5af9dd9018b01" title="Extract the frames with the given tag from a framelist.">irplib_framelist_extract_regexp</a>(<span class="keyword">const</span> irplib_framelist *,
+<a name="l00058"></a>00058                                                    <span class="keyword">const</span> <span class="keywordtype">char</span> *, cpl_boolean);
+<a name="l00059"></a>00059 
+<a name="l00060"></a>00060 <span class="comment">/* Accessors and element modifiers */</span>
+<a name="l00061"></a>00061 
+<a name="l00062"></a>00062 <span class="keywordtype">int</span> <a class="code" href="group__irplib__framelist.html#ga2518fce55112b5008cb119a126e593d7" title="Get the size of a framelist.">irplib_framelist_get_size</a>(<span class="keyword">const</span> irplib_framelist *);
+<a name="l00063"></a>00063 
+<a name="l00064"></a>00064 <span class="keyword">const</span> cpl_frame * <a class="code" href="group__irplib__framelist.html#ga93d8f903729ea4b6fcb3eca85935716f" title="Get the specified frame from the framelist.">irplib_framelist_get_const</a>(<span class="keyword">const</span> irplib_framelist *, <span class="keywordtype">int</span>);
+<a name="l00065"></a>00065 
+<a name="l00066"></a>00066 cpl_frame * <a class="code" href="group__irplib__framelist.html#gaba8797bbb8394f5574cd88b2f1984387" title="Get the specified frame from the framelist.">irplib_framelist_get</a>(irplib_framelist *, <span class="keywordtype">int</span>);
+<a name="l00067"></a>00067 
+<a name="l00068"></a>00068 <span class="keyword">const</span> cpl_propertylist * <a class="code" href="group__irplib__framelist.html#ga7700dadcf17db5b86409e6cef233af4c" title="Get the propertylist of the specified frame in the framelist.">irplib_framelist_get_propertylist_const</a>(
+<a name="l00069"></a>00069                                                        <span class="keyword">const</span> irplib_framelist *,
+<a name="l00070"></a>00070                                                        <span class="keywordtype">int</span>);
+<a name="l00071"></a>00071 
+<a name="l00072"></a>00072 cpl_propertylist * <a class="code" href="group__irplib__framelist.html#gab4858b1e9164f3a6cffcf40270f89032" title="Get the propertylist of the specified frame in the framelist.">irplib_framelist_get_propertylist</a>(irplib_framelist *, <span class="keywordtype">int</span>);
+<a name="l00073"></a>00073 
+<a name="l00074"></a>00074 cpl_error_code <a class="code" href="group__irplib__framelist.html#gada2c2e3f530a6dff763402eefceb5600" title="Duplicate a propertylist to the specified position in the framelist.">irplib_framelist_set_propertylist</a>(irplib_framelist *, <span class="keywordtype">int</span>,
+<a name="l00075"></a>00075                                                  <span class="keyword">const</span> cpl_propertylist *);
+<a name="l00076"></a>00076 
+<a name="l00077"></a>00077 cpl_error_code <a class="code" href="group__irplib__framelist.html#ga6ce5701e84915514975d09e0100c6005" title="Load the propertylist of the specified frame in the framelist.">irplib_framelist_load_propertylist</a>(irplib_framelist *, <span class="keywordtype">int</span>,
+<a name="l00078"></a>00078                                                   <span class="keywordtype">int</span>, <span class="keyword">const</span> <span class="keywordtype">char</span> *,
+<a name="l00079"></a>00079                                                   cpl_boolean);
+<a name="l00080"></a>00080 
+<a name="l00081"></a>00081 cpl_error_code <a class="code" href="group__irplib__framelist.html#gaf9204681e0b6aa2d952c974dcbd8729d" title="Load the propertylists of all frames in the framelist.">irplib_framelist_load_propertylist_all</a>(irplib_framelist *, <span class="keywordtype">int</span>,
+<a name="l00082"></a>00082                                                       <span class="keyword">const</span> <span class="keywordtype">char</span> *,
+<a name="l00083"></a>00083                                                       cpl_boolean);
+<a name="l00084"></a>00084 
+<a name="l00085"></a>00085 cpl_error_code <a class="code" href="group__irplib__framelist.html#gab11bb60e44dea926cd50ee80c7fbbd14" title="Set the tag of all frames in the list.">irplib_framelist_set_tag_all</a>(irplib_framelist *, <span class="keyword">const</span> <span class="keywordtype">char</span> *);
+<a name="l00086"></a>00086 
+<a name="l00087"></a>00087 
+<a name="l00088"></a>00088 <span class="comment">/* Inserting and removing elements */</span>
+<a name="l00089"></a>00089 
+<a name="l00090"></a>00090 cpl_error_code <a class="code" href="group__irplib__framelist.html#ga37e730f5627b4a0c7a81014f62421879" title="Add a frame to a framelist.">irplib_framelist_set</a>(irplib_framelist *, cpl_frame *, <span class="keywordtype">int</span>);
+<a name="l00091"></a>00091 
+<a name="l00092"></a>00092 cpl_error_code <a class="code" href="group__irplib__framelist.html#gac66ea3ad4fc98c171f8b840229fe54ce" title="Erase a frame from a framelist and delete it and its propertylist.">irplib_framelist_erase</a>(irplib_framelist *, <span class="keywordtype">int</span>);
+<a name="l00093"></a>00093 
+<a name="l00094"></a>00094 cpl_frame * <a class="code" href="group__irplib__framelist.html#ga771f14f97f80a9bd7176d323999c9bce" title="Erase a frame from a framelist and return it to the caller.">irplib_framelist_unset</a>(irplib_framelist *, <span class="keywordtype">int</span>, cpl_propertylist **);
+<a name="l00095"></a>00095 
+<a name="l00096"></a>00096 <span class="keywordtype">void</span> <a class="code" href="group__irplib__framelist.html#ga900ea254d9b2a2e4e3957360bbae4deb" title="Erase all frames from a framelist.">irplib_framelist_empty</a>(irplib_framelist *);
+<a name="l00097"></a>00097 
+<a name="l00098"></a>00098 <span class="comment">/* Others */</span>
+<a name="l00099"></a>00099 cpl_error_code <a class="code" href="group__irplib__framelist.html#gafed15e9e259ebad923b710f5eb0196ac" title="Verify that a property is present for all frames.">irplib_framelist_contains</a>(<span class="keyword">const</span> irplib_framelist *, <span class="keyword">const</span> <span class="keywordtype">char</span> *,
+<a name="l00100"></a>00100                                          cpl_type, cpl_boolean, <span class="keywordtype">double</span>);
+<a name="l00101"></a>00101 
+<a name="l00102"></a>00102 cpl_imagelist * <a class="code" href="group__irplib__framelist.html#ga0ff6c5e3b778c607544ca04ca3fb9e94" title="Load an imagelist from a framelist.">irplib_imagelist_load_framelist</a>(<span class="keyword">const</span> irplib_framelist *,
+<a name="l00103"></a>00103                                                 cpl_type, <span class="keywordtype">int</span>, <span class="keywordtype">int</span>);
+<a name="l00104"></a>00104 
+<a name="l00105"></a>00105 cpl_frameset * <a class="code" href="group__irplib__framelist.html#gabeedce2770a1bc06c26c0891a41aa174" title="Create a CPL frameset from an irplib_framelist.">irplib_frameset_cast</a>(<span class="keyword">const</span> irplib_framelist *);
+<a name="l00106"></a>00106 
+<a name="l00107"></a>00107 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/irplib__hist_8c_source.html b/html/irplib__hist_8c_source.html
new file mode 100644
index 0000000..2717f7c
--- /dev/null
+++ b/html/irplib__hist_8c_source.html
@@ -0,0 +1,366 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: irplib_hist.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>irplib_hist.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 
+<a name="l00002"></a>00002 
+<a name="l00003"></a>00003 <span class="comment">/*</span>
+<a name="l00004"></a>00004 <span class="comment"> * This file is part of the irplib package</span>
+<a name="l00005"></a>00005 <span class="comment"> * Copyright (C) 2002, 2003 European Southern Observatory</span>
+<a name="l00006"></a>00006 <span class="comment"> *</span>
+<a name="l00007"></a>00007 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00008"></a>00008 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00009"></a>00009 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00010"></a>00010 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00011"></a>00011 <span class="comment"> *</span>
+<a name="l00012"></a>00012 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00013"></a>00013 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00014"></a>00014 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
+<a name="l00015"></a>00015 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00016"></a>00016 <span class="comment"> *</span>
+<a name="l00017"></a>00017 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00018"></a>00018 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00019"></a>00019 <span class="comment"> * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA</span>
+<a name="l00020"></a>00020 <span class="comment"> */</span>
+<a name="l00021"></a>00021 
+<a name="l00022"></a>00022 <span class="comment">/*</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Author: kmirny $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Id: irplib_hist.c,v 1.7 2009/10/15 14:02:18 kmirny Exp $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Date: 2009/10/15 14:02:18 $</span>
+<a name="l00026"></a>00026 <span class="comment"> * $Revision: 1.7 $</span>
+<a name="l00027"></a>00027 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00028"></a>00028 <span class="comment"> */</span>
+<a name="l00029"></a>00029 
+<a name="l00030"></a>00030 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>
+<a name="l00032"></a>00032 <span class="preprocessor">#endif</span>
+<a name="l00033"></a>00033 <span class="preprocessor"></span>
+<a name="l00034"></a>00034 <span class="preprocessor">#include <stdlib.h></span>
+<a name="l00035"></a>00035 <span class="preprocessor">#include <stdio.h></span>
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="preprocessor">#include <math.h></span>
+<a name="l00038"></a>00038 
+<a name="l00039"></a>00039 <span class="preprocessor">#include "irplib_hist.h"</span>
+<a name="l00040"></a>00040 
+<a name="l00041"></a>00041 <span class="keyword">struct </span>_irplib_hist_
+<a name="l00042"></a>00042 {
+<a name="l00043"></a>00043     <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> * bins;
+<a name="l00044"></a>00044     <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>   nbins;
+<a name="l00045"></a>00045     <span class="keywordtype">double</span>          start;
+<a name="l00046"></a>00046     <span class="keywordtype">double</span>          range;
+<a name="l00047"></a>00047 };
+<a name="l00048"></a>00048 
+<a name="l00049"></a>00049 <span class="comment">/*</span>
+<a name="l00050"></a>00050 <span class="comment"> * Create a new empty histogram</span>
+<a name="l00051"></a>00051 <span class="comment"> */</span>
+<a name="l00052"></a>00052 
+<a name="l00053"></a>00053 irplib_hist *
+<a name="l00054"></a>00054 irplib_hist_new(<span class="keywordtype">void</span>)
+<a name="l00055"></a>00055 {
+<a name="l00056"></a>00056     <span class="keywordflow">return</span> (irplib_hist *) cpl_calloc(1, <span class="keyword">sizeof</span>(irplib_hist));
+<a name="l00057"></a>00057 }
+<a name="l00058"></a>00058 
+<a name="l00059"></a>00059 <span class="comment">/*</span>
+<a name="l00060"></a>00060 <span class="comment"> * Delete a histogram</span>
+<a name="l00061"></a>00061 <span class="comment"> */</span>
+<a name="l00062"></a>00062 
+<a name="l00063"></a>00063 <span class="keywordtype">void</span>
+<a name="l00064"></a>00064 irplib_hist_delete(irplib_hist * d)
+<a name="l00065"></a>00065 {
+<a name="l00066"></a>00066     <span class="keywordflow">if</span> (d == NULL)
+<a name="l00067"></a>00067     <span class="keywordflow">return</span>;
+<a name="l00068"></a>00068 
+<a name="l00069"></a>00069     <span class="keywordflow">if</span> (d -> bins)
+<a name="l00070"></a>00070     cpl_free(d -> bins);
+<a name="l00071"></a>00071 
+<a name="l00072"></a>00072     cpl_free(d);
+<a name="l00073"></a>00073 }
+<a name="l00074"></a>00074 
+<a name="l00075"></a>00075 <span class="comment">/*</span>
+<a name="l00076"></a>00076 <span class="comment"> * Initialise a histogram with user-defined values</span>
+<a name="l00077"></a>00077 <span class="comment"> */</span>
+<a name="l00078"></a>00078 
+<a name="l00079"></a>00079 cpl_error_code
+<a name="l00080"></a>00080 irplib_hist_init(irplib_hist   * hist,
+<a name="l00081"></a>00081                  <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>   nbins,
+<a name="l00082"></a>00082                  <span class="keywordtype">double</span>          start,
+<a name="l00083"></a>00083                  <span class="keywordtype">double</span>          range)
+<a name="l00084"></a>00084 {
+<a name="l00085"></a>00085     <span class="comment">/* Test the entries */</span>
+<a name="l00086"></a>00086     cpl_ensure_code(hist         != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00087"></a>00087     cpl_ensure_code(nbins        >  0,    CPL_ERROR_ILLEGAL_INPUT);
+<a name="l00088"></a>00088     cpl_ensure_code(range        >  0,    CPL_ERROR_ILLEGAL_INPUT);
+<a name="l00089"></a>00089     cpl_ensure_code(hist -> bins == NULL, CPL_ERROR_ILLEGAL_INPUT);
+<a name="l00090"></a>00090 
+<a name="l00091"></a>00091     <span class="comment">/* Initialise the histogram structure */</span>
+<a name="l00092"></a>00092     hist -> bins  = (<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> *) cpl_calloc(nbins, <span class="keyword">sizeof</span>(<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>));
+<a name="l00093"></a>00093     hist -> nbins = nbins;
+<a name="l00094"></a>00094     hist -> start = start;
+<a name="l00095"></a>00095     hist -> range = range;
+<a name="l00096"></a>00096 
+<a name="l00097"></a>00097     <span class="keywordflow">return</span> cpl_error_get_code();
+<a name="l00098"></a>00098 }
+<a name="l00099"></a>00099 
+<a name="l00100"></a>00100 <span class="comment">/*</span>
+<a name="l00101"></a>00101 <span class="comment"> * Return the value of a histogram bin.</span>
+<a name="l00102"></a>00102 <span class="comment"> * An uninitialised histogram is considered an illegal input.</span>
+<a name="l00103"></a>00103 <span class="comment"> */</span>
+<a name="l00104"></a>00104 
+<a name="l00105"></a>00105 <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>
+<a name="l00106"></a>00106 irplib_hist_get_value(<span class="keyword">const</span> irplib_hist * hist,
+<a name="l00107"></a>00107                       <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> binpos)
+<a name="l00108"></a>00108 {
+<a name="l00109"></a>00109     cpl_ensure(hist         != NULL,          CPL_ERROR_NULL_INPUT, 0);
+<a name="l00110"></a>00110     cpl_ensure(hist -> bins != NULL,          CPL_ERROR_ILLEGAL_INPUT, 0);
+<a name="l00111"></a>00111     cpl_ensure(binpos       <  hist -> nbins, CPL_ERROR_ILLEGAL_INPUT, 0);
+<a name="l00112"></a>00112 
+<a name="l00113"></a>00113     <span class="keywordflow">return</span> hist -> bins[binpos];
+<a name="l00114"></a>00114 }
+<a name="l00115"></a>00115 
+<a name="l00116"></a>00116 <span class="comment">/*</span>
+<a name="l00117"></a>00117 <span class="comment"> * Return the number of bins in the histogram.</span>
+<a name="l00118"></a>00118 <span class="comment"> */</span>
+<a name="l00119"></a>00119 
+<a name="l00120"></a>00120 <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>
+<a name="l00121"></a>00121 irplib_hist_get_nbins(<span class="keyword">const</span> irplib_hist * hist)
+<a name="l00122"></a>00122 {
+<a name="l00123"></a>00123     cpl_ensure(hist != NULL, CPL_ERROR_NULL_INPUT, 0);
+<a name="l00124"></a>00124 
+<a name="l00125"></a>00125     <span class="keywordflow">return</span> hist -> nbins;
+<a name="l00126"></a>00126 }
+<a name="l00127"></a>00127 
+<a name="l00128"></a>00128 <span class="comment">/*</span>
+<a name="l00129"></a>00129 <span class="comment"> * Return the binwidth of the histogram.</span>
+<a name="l00130"></a>00130 <span class="comment"> */</span>
+<a name="l00131"></a>00131 
+<a name="l00132"></a>00132 <span class="keywordtype">double</span>
+<a name="l00133"></a>00133 irplib_hist_get_bin_size(<span class="keyword">const</span> irplib_hist * hist)
+<a name="l00134"></a>00134 {
+<a name="l00135"></a>00135     cpl_ensure(hist         != NULL, CPL_ERROR_NULL_INPUT, 0);
+<a name="l00136"></a>00136     cpl_ensure(hist -> bins != NULL, CPL_ERROR_ILLEGAL_INPUT, 0);
+<a name="l00137"></a>00137 
+<a name="l00138"></a>00138     <span class="keywordflow">return</span> hist -> range / (double)(hist -> nbins - 2);
+<a name="l00139"></a>00139 }
+<a name="l00140"></a>00140 
+<a name="l00141"></a>00141 <span class="comment">/*</span>
+<a name="l00142"></a>00142 <span class="comment"> * Return the range covered by the histogram.</span>
+<a name="l00143"></a>00143 <span class="comment"> */</span>
+<a name="l00144"></a>00144 
+<a name="l00145"></a>00145 <span class="keywordtype">double</span>
+<a name="l00146"></a>00146 irplib_hist_get_range(<span class="keyword">const</span> irplib_hist * hist)
+<a name="l00147"></a>00147 {
+<a name="l00148"></a>00148     cpl_ensure(hist != NULL, CPL_ERROR_NULL_INPUT, 0);
+<a name="l00149"></a>00149 
+<a name="l00150"></a>00150     <span class="keywordflow">return</span> hist -> range;
+<a name="l00151"></a>00151 }
+<a name="l00152"></a>00152 
+<a name="l00153"></a>00153 <span class="comment">/*</span>
+<a name="l00154"></a>00154 <span class="comment"> * Return the real value corresponding</span>
+<a name="l00155"></a>00155 <span class="comment"> * to the inferior limit of the histogram..</span>
+<a name="l00156"></a>00156 <span class="comment"> */</span>
+<a name="l00157"></a>00157 
+<a name="l00158"></a>00158 <span class="keywordtype">double</span>
+<a name="l00159"></a>00159 irplib_hist_get_start(<span class="keyword">const</span> irplib_hist * hist)
+<a name="l00160"></a>00160 {
+<a name="l00161"></a>00161     cpl_ensure(hist         != NULL, CPL_ERROR_NULL_INPUT, 0);
+<a name="l00162"></a>00162     cpl_ensure(hist -> bins != NULL, CPL_ERROR_ILLEGAL_INPUT, 0);
+<a name="l00163"></a>00163 
+<a name="l00164"></a>00164     <span class="keywordflow">return</span> hist -> start;
+<a name="l00165"></a>00165 }
+<a name="l00166"></a>00166 
+<a name="l00167"></a>00167 <span class="comment">/*</span>
+<a name="l00168"></a>00168 <span class="comment"> * Fill a histogram for an image.</span>
+<a name="l00169"></a>00169 <span class="comment"> * If the histogram is uninitialised,</span>
+<a name="l00170"></a>00170 <span class="comment"> * the function initialises it with default values.</span>
+<a name="l00171"></a>00171 <span class="comment"> */</span>
+<a name="l00172"></a>00172 
+<a name="l00173"></a>00173 cpl_error_code
+<a name="l00174"></a>00174 irplib_hist_fill(irplib_hist     * hist,
+<a name="l00175"></a>00175                  <span class="keyword">const</span> cpl_image * image)
+<a name="l00176"></a>00176 {
+<a name="l00177"></a>00177     <span class="keywordtype">double</span>           binwidth = 1.0;
+<a name="l00178"></a>00178     <span class="keywordtype">int</span>              nsamples;
+<a name="l00179"></a>00179     <span class="keywordtype">int</span>              i;
+<a name="l00180"></a>00180     <span class="keyword">const</span> <span class="keywordtype">float</span>    * data = 0;
+<a name="l00181"></a>00181     <span class="keyword">const</span> cpl_binary*  bpm_data = 0;
+<a name="l00182"></a>00182     <span class="keyword">const</span> cpl_mask* bpm = 0;
+<a name="l00183"></a>00183     cpl_error_code   error;
+<a name="l00184"></a>00184 
+<a name="l00185"></a>00185     <span class="comment">/* Test the entries */</span>
+<a name="l00186"></a>00186     cpl_ensure_code(hist  != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00187"></a>00187     cpl_ensure_code(image != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00188"></a>00188 
+<a name="l00189"></a>00189     <span class="keywordflow">if</span> (hist -> bins == NULL) {
+<a name="l00190"></a>00190     <span class="keyword">const</span> <span class="keywordtype">double</span>        hstart = cpl_image_get_min(image);
+<a name="l00191"></a>00191     <span class="keyword">const</span> <span class="keywordtype">double</span>        hrange = cpl_image_get_max(image) - hstart;
+<a name="l00192"></a>00192 
+<a name="l00193"></a>00193     <span class="comment">/*</span>
+<a name="l00194"></a>00194 <span class="comment">         * Whichever function that computes an optimal binwidth</span>
+<a name="l00195"></a>00195 <span class="comment">         * should be introduced inside this if-statement, here.</span>
+<a name="l00196"></a>00196 <span class="comment">         */</span>
+<a name="l00197"></a>00197 
+<a name="l00198"></a>00198     <span class="comment">/* 2 extra-bins for possible out-of-range values */</span>
+<a name="l00199"></a>00199     <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> nbins  = (<span class="keywordtype">unsigned</span> long) (hrange / binwidth) + 2;
+<a name="l00200"></a>00200 
+<a name="l00201"></a>00201     error = irplib_hist_init(hist, nbins, hstart, hrange);
+<a name="l00202"></a>00202     cpl_ensure_code(!error, error);
+<a name="l00203"></a>00203     } <span class="keywordflow">else</span> {
+<a name="l00204"></a>00204     cpl_ensure_code(hist -> range > 0, CPL_ERROR_ILLEGAL_INPUT);
+<a name="l00205"></a>00205 
+<a name="l00206"></a>00206     <span class="comment">/* 2 bins reserved for possible out-of-range values */</span>
+<a name="l00207"></a>00207         binwidth = hist -> range / (double)(hist -> nbins - 2);
+<a name="l00208"></a>00208     }
+<a name="l00209"></a>00209 
+<a name="l00210"></a>00210     nsamples = cpl_image_get_size_x(image) * cpl_image_get_size_y(image);
+<a name="l00211"></a>00211     data     = cpl_image_get_data_float_const(image);
+<a name="l00212"></a>00212     bpm      = cpl_image_get_bpm_const(image);
+<a name="l00213"></a>00213     <span class="keywordflow">if</span> (bpm)
+<a name="l00214"></a>00214     {
+<a name="l00215"></a>00215         bpm_data     = cpl_mask_get_data_const(bpm); <span class="comment">// bad pixel mask</span>
+<a name="l00216"></a>00216     }
+<a name="l00217"></a>00217 
+<a name="l00218"></a>00218     <span class="keywordflow">for</span> (i = 0; i < nsamples; i++)
+<a name="l00219"></a>00219     {
+<a name="l00220"></a>00220         <span class="keywordtype">int</span> pos = 0;
+<a name="l00221"></a>00221         <span class="keywordflow">if</span>(bpm_data && bpm_data[i] == CPL_BINARY_1)
+<a name="l00222"></a>00222         {
+<a name="l00223"></a>00223             <span class="keywordflow">continue</span>;
+<a name="l00224"></a>00224         }
+<a name="l00225"></a>00225         pos = (int)((data[i] - hist -> start) / binwidth);
+<a name="l00226"></a>00226         <span class="keywordflow">if</span> (pos <  0)
+<a name="l00227"></a>00227         {
+<a name="l00228"></a>00228             hist -> bins[0]++;
+<a name="l00229"></a>00229         } <span class="keywordflow">else</span> <span class="keywordflow">if</span> ((<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>) pos >= (hist -> nbins - 2))
+<a name="l00230"></a>00230         {
+<a name="l00231"></a>00231             hist -> bins[hist -> nbins - 1]++;
+<a name="l00232"></a>00232         } <span class="keywordflow">else</span>
+<a name="l00233"></a>00233         {
+<a name="l00234"></a>00234             hist -> bins[pos + 1]++;
+<a name="l00235"></a>00235         }
+<a name="l00236"></a>00236     }
+<a name="l00237"></a>00237 
+<a name="l00238"></a>00238     <span class="keywordflow">return</span> cpl_error_get_code();
+<a name="l00239"></a>00239 }
+<a name="l00240"></a>00240 
+<a name="l00241"></a>00241 <span class="comment">/*</span>
+<a name="l00242"></a>00242 <span class="comment"> * Compute the maximum of a histogram.</span>
+<a name="l00243"></a>00243 <span class="comment"> * Return: the maximum value.</span>
+<a name="l00244"></a>00244 <span class="comment"> * The parameter max_where is a pointer to the position</span>
+<a name="l00245"></a>00245 <span class="comment"> * of the maximum in the histogram.</span>
+<a name="l00246"></a>00246 <span class="comment"> */</span>
+<a name="l00247"></a>00247 
+<a name="l00248"></a>00248 <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>
+<a name="l00249"></a>00249 irplib_hist_get_max(<span class="keyword">const</span> irplib_hist * hist,
+<a name="l00250"></a>00250                     <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>     * maxpos)
+<a name="l00251"></a>00251 {
+<a name="l00252"></a>00252     <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> max = 0;
+<a name="l00253"></a>00253     <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> ui;
+<a name="l00254"></a>00254 
+<a name="l00255"></a>00255     cpl_ensure(hist         != NULL, CPL_ERROR_NULL_INPUT, 0);
+<a name="l00256"></a>00256     cpl_ensure(maxpos       != NULL, CPL_ERROR_NULL_INPUT, 0);
+<a name="l00257"></a>00257     cpl_ensure(hist -> bins != NULL, CPL_ERROR_ILLEGAL_INPUT, 0);
+<a name="l00258"></a>00258 
+<a name="l00259"></a>00259     <span class="keywordflow">for</span>(ui = 0; ui < hist -> nbins; ui++) {
+<a name="l00260"></a>00260     <span class="keywordtype">double</span> c_value = irplib_hist_get_value(hist, ui);
+<a name="l00261"></a>00261     <span class="keywordflow">if</span>(c_value > max) {
+<a name="l00262"></a>00262         max     = c_value;
+<a name="l00263"></a>00263         *maxpos = ui;
+<a name="l00264"></a>00264     }
+<a name="l00265"></a>00265     }
+<a name="l00266"></a>00266 
+<a name="l00267"></a>00267     <span class="keywordflow">return</span> max;
+<a name="l00268"></a>00268 }
+<a name="l00269"></a>00269 
+<a name="l00270"></a>00270 <span class="comment">/*</span>
+<a name="l00271"></a>00271 <span class="comment"> * Cast a histogram into a table with a single column named "HIST"</span>
+<a name="l00272"></a>00272 <span class="comment"> */</span>
+<a name="l00273"></a>00273 
+<a name="l00274"></a>00274 cpl_table *
+<a name="l00275"></a>00275 irplib_hist_cast_table(<span class="keyword">const</span> irplib_hist * hist)
+<a name="l00276"></a>00276 {
+<a name="l00277"></a>00277     cpl_table      * table;
+<a name="l00278"></a>00278     cpl_error_code   error;
+<a name="l00279"></a>00279 
+<a name="l00280"></a>00280     cpl_ensure(hist         != NULL, CPL_ERROR_NULL_INPUT, NULL);
+<a name="l00281"></a>00281     cpl_ensure(hist -> bins != NULL, CPL_ERROR_ILLEGAL_INPUT, NULL);
+<a name="l00282"></a>00282 
+<a name="l00283"></a>00283     table = cpl_table_new(hist -> nbins);
+<a name="l00284"></a>00284 
+<a name="l00285"></a>00285     error = cpl_table_new_column(table, <span class="stringliteral">"HIST"</span>, CPL_TYPE_INT);
+<a name="l00286"></a>00286     cpl_ensure(!error, error, NULL);
+<a name="l00287"></a>00287 
+<a name="l00288"></a>00288     error = cpl_table_copy_data_int(table, <span class="stringliteral">"HIST"</span>, (<span class="keywordtype">int</span> *)(hist -> bins));
+<a name="l00289"></a>00289     cpl_ensure(!error, error, NULL);
+<a name="l00290"></a>00290 
+<a name="l00291"></a>00291     <span class="keywordflow">return</span> table;
+<a name="l00292"></a>00292 }
+<a name="l00293"></a>00293 
+<a name="l00294"></a>00294 <span class="comment">/*</span>
+<a name="l00295"></a>00295 <span class="comment"> * Collapse the histogram: add the values of all bins.</span>
+<a name="l00296"></a>00296 <span class="comment"> * Used now only for debugging purposes.</span>
+<a name="l00297"></a>00297 <span class="comment"> */</span>
+<a name="l00298"></a>00298 
+<a name="l00299"></a>00299 cpl_error_code
+<a name="l00300"></a>00300 irplib_hist_collapse(irplib_hist * hist,
+<a name="l00301"></a>00301                      <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> new_nbins)
+<a name="l00302"></a>00302 {
+<a name="l00303"></a>00303     <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>   ui, nuj;
+<a name="l00304"></a>00304     <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> * old_bins;
+<a name="l00305"></a>00305     <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>   old_nbins;
+<a name="l00306"></a>00306     <span class="keywordtype">double</span>          collapse_rate;
+<a name="l00307"></a>00307     cpl_error_code  error;
+<a name="l00308"></a>00308     <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>   rest;
+<a name="l00309"></a>00309 
+<a name="l00310"></a>00310     cpl_ensure_code(hist         != NULL,          CPL_ERROR_NULL_INPUT);
+<a name="l00311"></a>00311     cpl_ensure_code(hist -> bins != NULL,          CPL_ERROR_ILLEGAL_INPUT);
+<a name="l00312"></a>00312     cpl_ensure_code(new_nbins    >  0,             CPL_ERROR_ILLEGAL_INPUT);
+<a name="l00313"></a>00313     cpl_ensure_code(new_nbins    <= hist -> nbins, CPL_ERROR_ILLEGAL_INPUT);
+<a name="l00314"></a>00314 
+<a name="l00315"></a>00315     old_bins  = hist -> bins;
+<a name="l00316"></a>00316     old_nbins = hist -> nbins;
+<a name="l00317"></a>00317 
+<a name="l00318"></a>00318     hist -> bins = NULL;
+<a name="l00319"></a>00319     error = irplib_hist_init(hist, new_nbins, hist -> start, hist -> range);
+<a name="l00320"></a>00320     cpl_ensure_code(!error, error);
+<a name="l00321"></a>00321 
+<a name="l00322"></a>00322     collapse_rate = (double) (old_nbins - 2) / (double) (new_nbins - 2);
+<a name="l00323"></a>00323 
+<a name="l00324"></a>00324     <span class="comment">/* The out-of-range values are not affected by the collapsing operation */</span>
+<a name="l00325"></a>00325     hist -> bins[0]             = old_bins[0];
+<a name="l00326"></a>00326     hist -> bins[new_nbins - 1] = old_bins[old_nbins - 1];
+<a name="l00327"></a>00327 
+<a name="l00328"></a>00328     rest = 0;
+<a name="l00329"></a>00329     nuj  = 1;
+<a name="l00330"></a>00330 
+<a name="l00331"></a>00331     <span class="keywordflow">for</span> (ui = 1; ui < new_nbins - 1; ui++) {
+<a name="l00332"></a>00332     <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> uj;
+<a name="l00333"></a>00333     <span class="keyword">const</span> <span class="keywordtype">double</span>  up  = collapse_rate *  ui;
+<a name="l00334"></a>00334 
+<a name="l00335"></a>00335     hist -> bins[ui] += rest;
+<a name="l00336"></a>00336 
+<a name="l00337"></a>00337     <span class="keywordflow">for</span> (uj = nuj; uj < (<span class="keywordtype">unsigned</span> long) up + 1; uj++)
+<a name="l00338"></a>00338         hist -> bins[ui] +=  old_bins[uj];
+<a name="l00339"></a>00339 
+<a name="l00340"></a>00340     rest = (<span class="keywordtype">unsigned</span> long)(up - (<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>) up) * old_bins[uj];
+<a name="l00341"></a>00341     hist -> bins[ui] += rest;
+<a name="l00342"></a>00342 
+<a name="l00343"></a>00343     rest = old_bins[uj] - rest;
+<a name="l00344"></a>00344     nuj = uj + 1;
+<a name="l00345"></a>00345     }
+<a name="l00346"></a>00346 
+<a name="l00347"></a>00347     cpl_free(old_bins);
+<a name="l00348"></a>00348 
+<a name="l00349"></a>00349     <span class="keywordflow">return</span> cpl_error_get_code();
+<a name="l00350"></a>00350 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/irplib__hist_8h_source.html b/html/irplib__hist_8h_source.html
new file mode 100644
index 0000000..18660c3
--- /dev/null
+++ b/html/irplib__hist_8h_source.html
@@ -0,0 +1,109 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: irplib_hist.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>irplib_hist.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: irplib_hist.h,v 1.3 2007/09/07 14:23:50 lbilbao Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the irplib package</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002, 2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: lbilbao $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2007/09/07 14:23:50 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.3 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifndef IRPLIB_HIST_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#define IRPLIB_HIST_H</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span>
+<a name="l00031"></a>00031 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00032"></a>00032 
+<a name="l00033"></a>00033 <span class="keyword">typedef</span> <span class="keyword">struct </span>_irplib_hist_ irplib_hist;
+<a name="l00034"></a>00034 
+<a name="l00035"></a>00035 <span class="comment">/* Creation/Destruction functions */</span>
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 irplib_hist *
+<a name="l00038"></a>00038 irplib_hist_new(<span class="keywordtype">void</span>);
+<a name="l00039"></a>00039 
+<a name="l00040"></a>00040 <span class="keywordtype">void</span>
+<a name="l00041"></a>00041 irplib_hist_delete(irplib_hist *);
+<a name="l00042"></a>00042 
+<a name="l00043"></a>00043 <span class="comment">/* Initialisation function */</span>
+<a name="l00044"></a>00044 
+<a name="l00045"></a>00045 cpl_error_code
+<a name="l00046"></a>00046 irplib_hist_init(irplib_hist   *,
+<a name="l00047"></a>00047                  <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>  ,
+<a name="l00048"></a>00048                  <span class="keywordtype">double</span>         ,
+<a name="l00049"></a>00049                  <span class="keywordtype">double</span>         );
+<a name="l00050"></a>00050 
+<a name="l00051"></a>00051 <span class="comment">/* Accessor functions */</span>
+<a name="l00052"></a>00052 
+<a name="l00053"></a>00053 <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>
+<a name="l00054"></a>00054 irplib_hist_get_value(<span class="keyword">const</span> irplib_hist *,
+<a name="l00055"></a>00055                       <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>);
+<a name="l00056"></a>00056 
+<a name="l00057"></a>00057 <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>
+<a name="l00058"></a>00058 irplib_hist_get_nbins(<span class="keyword">const</span> irplib_hist *);
+<a name="l00059"></a>00059 
+<a name="l00060"></a>00060 <span class="keywordtype">double</span>
+<a name="l00061"></a>00061 irplib_hist_get_bin_size(<span class="keyword">const</span> irplib_hist *);
+<a name="l00062"></a>00062 
+<a name="l00063"></a>00063 <span class="keywordtype">double</span>
+<a name="l00064"></a>00064 irplib_hist_get_range(<span class="keyword">const</span> irplib_hist *);
+<a name="l00065"></a>00065 
+<a name="l00066"></a>00066 <span class="keywordtype">double</span>
+<a name="l00067"></a>00067 irplib_hist_get_start(<span class="keyword">const</span> irplib_hist *);
+<a name="l00068"></a>00068 
+<a name="l00069"></a>00069 <span class="comment">/* Histogram computing function */</span>
+<a name="l00070"></a>00070 
+<a name="l00071"></a>00071 cpl_error_code
+<a name="l00072"></a>00072 irplib_hist_fill(irplib_hist     *,
+<a name="l00073"></a>00073                  <span class="keyword">const</span> cpl_image *);
+<a name="l00074"></a>00074 
+<a name="l00075"></a>00075 <span class="comment">/* Statistics functions */</span>
+<a name="l00076"></a>00076 
+<a name="l00077"></a>00077 <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>
+<a name="l00078"></a>00078 irplib_hist_get_max(<span class="keyword">const</span> irplib_hist *,
+<a name="l00079"></a>00079                     <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>     *);
+<a name="l00080"></a>00080 
+<a name="l00081"></a>00081 <span class="comment">/* Casting function */</span>
+<a name="l00082"></a>00082 
+<a name="l00083"></a>00083 cpl_table *
+<a name="l00084"></a>00084 irplib_hist_cast_table(<span class="keyword">const</span> irplib_hist *);
+<a name="l00085"></a>00085 
+<a name="l00086"></a>00086 <span class="comment">/* Functions for operations on histograms */</span>
+<a name="l00087"></a>00087 
+<a name="l00088"></a>00088 cpl_error_code
+<a name="l00089"></a>00089 irplib_hist_collapse(irplib_hist *,
+<a name="l00090"></a>00090                      <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>);
+<a name="l00091"></a>00091 
+<a name="l00092"></a>00092 <span class="preprocessor">#endif </span><span class="comment">/* IRPLIB_HIST_H */</span>
+<a name="l00093"></a>00093 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/irplib__ksigma__clip_8c_source.html b/html/irplib__ksigma__clip_8c_source.html
new file mode 100644
index 0000000..fc09d41
--- /dev/null
+++ b/html/irplib__ksigma__clip_8c_source.html
@@ -0,0 +1,223 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: irplib_ksigma_clip.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>irplib_ksigma_clip.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: irplib_ksigma_clip.c,v 1.1 2011/11/02 13:18:28 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the irplib package</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002, 2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2011/11/02 13:18:28 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.1 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span>
+<a name="l00032"></a>00032 <span class="preprocessor">#include <complex.h></span>
+<a name="l00033"></a>00033 
+<a name="l00034"></a>00034 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00035"></a>00035 <span class="comment">                                  Includes</span>
+<a name="l00036"></a>00036 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00037"></a>00037 
+<a name="l00038"></a>00038 <span class="preprocessor">#include <math.h></span>
+<a name="l00039"></a>00039 <span class="preprocessor">#include <string.h></span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include <assert.h></span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include <float.h></span>
+<a name="l00042"></a>00042 
+<a name="l00043"></a>00043 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00044"></a>00044 
+<a name="l00045"></a>00045 <span class="preprocessor">#include "irplib_ksigma_clip.h"</span>
+<a name="l00046"></a>00046 
+<a name="l00047"></a>00047 <span class="preprocessor">#include "irplib_hist.h"</span>
+<a name="l00048"></a>00048 <span class="preprocessor">#include "irplib_utils.h"</span>
+<a name="l00049"></a>00049 
+<a name="l00050"></a>00050 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00051"></a>00051 
+<a name="l00052"></a>00052 <span class="comment">/*</span>
+<a name="l00053"></a>00053 <span class="comment"> * @defgroup ksigmaclip        kappa sigma clip functions</span>
+<a name="l00054"></a>00054 <span class="comment"> */</span>
+<a name="l00055"></a>00055 
+<a name="l00056"></a>00056 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00057"></a>00057 
+<a name="l00058"></a>00058 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00059"></a>00059 <span class="comment">                                  Defines</span>
+<a name="l00060"></a>00060 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00061"></a>00061 
+<a name="l00062"></a>00062 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00063"></a>00063 <span class="comment">                                  Private function prototypes</span>
+<a name="l00064"></a>00064 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00065"></a>00065 
+<a name="l00066"></a>00066 <span class="keyword">static</span> cpl_error_code
+<a name="l00067"></a>00067 irplib_ksigma_clip_double(<span class="keyword">const</span> <span class="keywordtype">double</span>  * pi,
+<a name="l00068"></a>00068               <span class="keywordtype">int</span>               llx,
+<a name="l00069"></a>00069               <span class="keywordtype">int</span>               lly,
+<a name="l00070"></a>00070               <span class="keywordtype">int</span>               urx,
+<a name="l00071"></a>00071               <span class="keywordtype">int</span>               ury,
+<a name="l00072"></a>00072               <span class="keywordtype">int</span>               nx,
+<a name="l00073"></a>00073               <span class="keywordtype">double</span>            var_sum,
+<a name="l00074"></a>00074               <span class="keywordtype">int</span>               npixs,
+<a name="l00075"></a>00075               <span class="keywordtype">double</span>            kappa,
+<a name="l00076"></a>00076               <span class="keywordtype">int</span>               nclip,
+<a name="l00077"></a>00077               <span class="keywordtype">double</span>            tolerance,
+<a name="l00078"></a>00078               <span class="keywordtype">double</span>          * mean,
+<a name="l00079"></a>00079               <span class="keywordtype">double</span>          * stdev);
+<a name="l00080"></a>00080 
+<a name="l00081"></a>00081 <span class="keyword">static</span> cpl_error_code
+<a name="l00082"></a>00082 irplib_ksigma_clip_float(<span class="keyword">const</span> <span class="keywordtype">float</span>     * pi,
+<a name="l00083"></a>00083              <span class="keywordtype">int</span>               llx,
+<a name="l00084"></a>00084              <span class="keywordtype">int</span>               lly,
+<a name="l00085"></a>00085              <span class="keywordtype">int</span>               urx,
+<a name="l00086"></a>00086              <span class="keywordtype">int</span>               ury,
+<a name="l00087"></a>00087              <span class="keywordtype">int</span>               nx,
+<a name="l00088"></a>00088              <span class="keywordtype">double</span>            var_sum,
+<a name="l00089"></a>00089              <span class="keywordtype">int</span>               npixs,
+<a name="l00090"></a>00090              <span class="keywordtype">double</span>            kappa,
+<a name="l00091"></a>00091              <span class="keywordtype">int</span>               nclip,
+<a name="l00092"></a>00092              <span class="keywordtype">double</span>            tolerance,
+<a name="l00093"></a>00093              <span class="keywordtype">double</span>          * mean,
+<a name="l00094"></a>00094              <span class="keywordtype">double</span>          * stdev);
+<a name="l00095"></a>00095 
+<a name="l00096"></a>00096 <span class="keyword">static</span> cpl_error_code
+<a name="l00097"></a>00097 irplib_ksigma_clip_int(<span class="keyword">const</span> <span class="keywordtype">int</span>       * pi,
+<a name="l00098"></a>00098                <span class="keywordtype">int</span>               llx,
+<a name="l00099"></a>00099                <span class="keywordtype">int</span>               lly,
+<a name="l00100"></a>00100                <span class="keywordtype">int</span>               urx,
+<a name="l00101"></a>00101                <span class="keywordtype">int</span>               ury,
+<a name="l00102"></a>00102                <span class="keywordtype">int</span>               nx,
+<a name="l00103"></a>00103                <span class="keywordtype">double</span>            var_sum,
+<a name="l00104"></a>00104                <span class="keywordtype">int</span>               npixs,
+<a name="l00105"></a>00105                <span class="keywordtype">double</span>            kappa,
+<a name="l00106"></a>00106                <span class="keywordtype">int</span>               nclip,
+<a name="l00107"></a>00107                <span class="keywordtype">double</span>            tolerance,
+<a name="l00108"></a>00108                <span class="keywordtype">double</span>          * mean,
+<a name="l00109"></a>00109                <span class="keywordtype">double</span>          * stdev);
+<a name="l00110"></a>00110 
+<a name="l00111"></a>00111 
+<a name="l00112"></a>00112 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00164"></a>00164 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00165"></a>00165 cpl_error_code
+<a name="l00166"></a>00166 irplib_ksigma_clip(<span class="keyword">const</span> cpl_image * img,
+<a name="l00167"></a>00167            <span class="keywordtype">int</span>               llx,
+<a name="l00168"></a>00168            <span class="keywordtype">int</span>               lly,
+<a name="l00169"></a>00169            <span class="keywordtype">int</span>               urx,
+<a name="l00170"></a>00170            <span class="keywordtype">int</span>               ury,
+<a name="l00171"></a>00171            <span class="keywordtype">double</span>            kappa,
+<a name="l00172"></a>00172            <span class="keywordtype">int</span>               nclip,
+<a name="l00173"></a>00173            <span class="keywordtype">double</span>            tolerance,
+<a name="l00174"></a>00174            <span class="keywordtype">double</span>          * kmean,
+<a name="l00175"></a>00175            <span class="keywordtype">double</span>          * kstdev)
+<a name="l00176"></a>00176 {
+<a name="l00177"></a>00177     cpl_errorstate inistate = cpl_errorstate_get();
+<a name="l00178"></a>00178 
+<a name="l00179"></a>00179     <span class="keywordtype">int</span> nx, ny;
+<a name="l00180"></a>00180 
+<a name="l00181"></a>00181     cpl_stats * stats;
+<a name="l00182"></a>00182     <span class="keywordtype">double</span>      mean, stdev, var_sum;
+<a name="l00183"></a>00183     <span class="keywordtype">int</span>         npixs;
+<a name="l00184"></a>00184 
+<a name="l00185"></a>00185     cpl_ensure_code(img != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00186"></a>00186 
+<a name="l00187"></a>00187     nx = cpl_image_get_size_x(img);
+<a name="l00188"></a>00188     ny = cpl_image_get_size_y(img);
+<a name="l00189"></a>00189 
+<a name="l00190"></a>00190     cpl_ensure_code(llx > 0 && urx > llx && urx <= nx &&
+<a name="l00191"></a>00191             lly > 0 && ury > lly && ury <= ny,
+<a name="l00192"></a>00192             CPL_ERROR_ILLEGAL_INPUT);
+<a name="l00193"></a>00193 
+<a name="l00194"></a>00194     cpl_ensure_code(tolerance >= 0.0, CPL_ERROR_ILLEGAL_INPUT);
+<a name="l00195"></a>00195     cpl_ensure_code(kappa     >  1.0, CPL_ERROR_ILLEGAL_INPUT);
+<a name="l00196"></a>00196     cpl_ensure_code(nclip     >    0, CPL_ERROR_ILLEGAL_INPUT);
+<a name="l00197"></a>00197 
+<a name="l00198"></a>00198     stats = cpl_stats_new_from_image_window(img,
+<a name="l00199"></a>00199                         CPL_STATS_MEAN | CPL_STATS_STDEV,
+<a name="l00200"></a>00200                         llx, lly, urx, ury);
+<a name="l00201"></a>00201 
+<a name="l00202"></a>00202     npixs   = cpl_stats_get_npix(stats); <span class="comment">/* Non-bad pixels in window */</span>
+<a name="l00203"></a>00203     mean    = cpl_stats_get_mean(stats);
+<a name="l00204"></a>00204     stdev   = cpl_stats_get_stdev(stats);
+<a name="l00205"></a>00205     var_sum = stdev * stdev * (npixs - 1);
+<a name="l00206"></a>00206 
+<a name="l00207"></a>00207     cpl_stats_delete(stats);
+<a name="l00208"></a>00208 
+<a name="l00209"></a>00209     <span class="comment">/* img, llx etc. may cause errors: Check and propagate */</span>
+<a name="l00210"></a>00210     cpl_ensure_code(cpl_errorstate_is_equal(inistate), cpl_error_get_code());
+<a name="l00211"></a>00211 
+<a name="l00212"></a>00212     <span class="keywordflow">switch</span> (cpl_image_get_type(img)) {
+<a name="l00213"></a>00213     <span class="keywordflow">case</span> CPL_TYPE_DOUBLE:
+<a name="l00214"></a>00214     skip_if(irplib_ksigma_clip_double(cpl_image_get_data_double_const(img),
+<a name="l00215"></a>00215                       llx, lly, urx, ury, nx, var_sum,
+<a name="l00216"></a>00216                       npixs, kappa, nclip, tolerance,
+<a name="l00217"></a>00217                       &mean, &stdev));
+<a name="l00218"></a>00218     <span class="keywordflow">break</span>;
+<a name="l00219"></a>00219     <span class="keywordflow">case</span> CPL_TYPE_FLOAT:
+<a name="l00220"></a>00220     skip_if(irplib_ksigma_clip_float(cpl_image_get_data_float_const(img),
+<a name="l00221"></a>00221                      llx, lly, urx, ury, nx, var_sum,
+<a name="l00222"></a>00222                      npixs, kappa, nclip, tolerance,
+<a name="l00223"></a>00223                      &mean, &stdev));
+<a name="l00224"></a>00224     <span class="keywordflow">break</span>;
+<a name="l00225"></a>00225     <span class="keywordflow">case</span> CPL_TYPE_INT:
+<a name="l00226"></a>00226     skip_if(irplib_ksigma_clip_int(cpl_image_get_data_int_const(img),
+<a name="l00227"></a>00227                        llx, lly, urx, ury, nx, var_sum,
+<a name="l00228"></a>00228                        npixs, kappa, nclip, tolerance,
+<a name="l00229"></a>00229                        &mean, &stdev));
+<a name="l00230"></a>00230     <span class="keywordflow">break</span>;
+<a name="l00231"></a>00231     <span class="keywordflow">default</span>:
+<a name="l00232"></a>00232     <span class="comment">/* It is an error in CPL to reach this point */</span>
+<a name="l00233"></a>00233     assert( 0 );
+<a name="l00234"></a>00234     }
+<a name="l00235"></a>00235 
+<a name="l00236"></a>00236     *kmean = mean;
+<a name="l00237"></a>00237     <span class="keywordflow">if</span> (kstdev != NULL) *kstdev = stdev; <span class="comment">/* Optional */</span>
+<a name="l00238"></a>00238 
+<a name="l00239"></a>00239     end_skip;
+<a name="l00240"></a>00240 
+<a name="l00241"></a>00241     <span class="keywordflow">return</span> cpl_error_get_code();
+<a name="l00242"></a>00242 }
+<a name="l00243"></a>00243 
+<a name="l00244"></a>00244 <span class="preprocessor">#define CONCAT(a,b) a ## _ ## b</span>
+<a name="l00245"></a>00245 <span class="preprocessor"></span><span class="preprocessor">#define CONCAT2X(a,b) CONCAT(a,b)</span>
+<a name="l00246"></a>00246 <span class="preprocessor"></span>
+<a name="l00247"></a>00247 <span class="preprocessor">#define CPL_TYPE double</span>
+<a name="l00248"></a>00248 <span class="preprocessor"></span><span class="preprocessor">#include "irplib_ksigma_clip_body.h"</span>
+<a name="l00249"></a>00249 <span class="preprocessor">#undef CPL_TYPE</span>
+<a name="l00250"></a>00250 <span class="preprocessor"></span>
+<a name="l00251"></a>00251 <span class="preprocessor">#define CPL_TYPE float</span>
+<a name="l00252"></a>00252 <span class="preprocessor"></span><span class="preprocessor">#include "irplib_ksigma_clip_body.h"</span>
+<a name="l00253"></a>00253 <span class="preprocessor">#undef CPL_TYPE</span>
+<a name="l00254"></a>00254 <span class="preprocessor"></span>
+<a name="l00255"></a>00255 <span class="preprocessor">#define CPL_TYPE int</span>
+<a name="l00256"></a>00256 <span class="preprocessor"></span><span class="preprocessor">#include "irplib_ksigma_clip_body.h"</span>
+<a name="l00257"></a>00257 <span class="preprocessor">#undef CPL_TYPE</span>
+<a name="l00258"></a>00258 <span class="preprocessor"></span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/irplib__ksigma__clip_8h_source.html b/html/irplib__ksigma__clip_8h_source.html
new file mode 100644
index 0000000..94007b5
--- /dev/null
+++ b/html/irplib__ksigma__clip_8h_source.html
@@ -0,0 +1,68 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: irplib_ksigma_clip.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>irplib_ksigma_clip.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: irplib_ksigma_clip.h,v 1.1 2011/11/02 13:18:28 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the irplib package</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002, 2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2011/11/02 13:18:28 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.1 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifndef IRPLIB_KSIGMA_CLIP_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#define IRPLIB_KSIGMA_CLIP_H</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span>
+<a name="l00031"></a>00031 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00032"></a>00032 <span class="comment">                                   Includes</span>
+<a name="l00033"></a>00033 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00034"></a>00034 
+<a name="l00035"></a>00035 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00038"></a>00038 <span class="comment">                                   Prototypes</span>
+<a name="l00039"></a>00039 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00040"></a>00040 cpl_error_code
+<a name="l00041"></a>00041 irplib_ksigma_clip(<span class="keyword">const</span> cpl_image *,
+<a name="l00042"></a>00042            <span class="keyword">const</span> <span class="keywordtype">int</span>,
+<a name="l00043"></a>00043            <span class="keyword">const</span> <span class="keywordtype">int</span>,
+<a name="l00044"></a>00044            <span class="keyword">const</span> <span class="keywordtype">int</span>,
+<a name="l00045"></a>00045            <span class="keyword">const</span> <span class="keywordtype">int</span>,
+<a name="l00046"></a>00046            <span class="keyword">const</span> <span class="keywordtype">double</span>,
+<a name="l00047"></a>00047            <span class="keyword">const</span> <span class="keywordtype">int</span>,
+<a name="l00048"></a>00048            <span class="keyword">const</span> <span class="keywordtype">double</span>,
+<a name="l00049"></a>00049            <span class="keywordtype">double</span> *,
+<a name="l00050"></a>00050            <span class="keywordtype">double</span> *);
+<a name="l00051"></a>00051 
+<a name="l00052"></a>00052 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/irplib__ksigma__clip__body_8h_source.html b/html/irplib__ksigma__clip__body_8h_source.html
new file mode 100644
index 0000000..a0bb956
--- /dev/null
+++ b/html/irplib__ksigma__clip__body_8h_source.html
@@ -0,0 +1,123 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: irplib_ksigma_clip_body.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>irplib_ksigma_clip_body.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: irplib_ksigma_clip_body.h,v 1.1 2011/11/02 13:18:28 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the irplib package </span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2011/11/02 13:18:28 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.1 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#define TYPE_ADD(a) CONCAT2X(a, CPL_TYPE)</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span>
+<a name="l00030"></a>00030 <span class="keyword">static</span> cpl_error_code
+<a name="l00031"></a>00031 TYPE_ADD(irplib_ksigma_clip)(<span class="keyword">const</span> CPL_TYPE  * pi,
+<a name="l00032"></a>00032                  <span class="keywordtype">int</span>               llx,
+<a name="l00033"></a>00033                  <span class="keywordtype">int</span>               lly,
+<a name="l00034"></a>00034                  <span class="keywordtype">int</span>               urx,
+<a name="l00035"></a>00035                  <span class="keywordtype">int</span>               ury,
+<a name="l00036"></a>00036                  <span class="keywordtype">int</span>               nx,
+<a name="l00037"></a>00037                  <span class="keywordtype">double</span>            var_sum,
+<a name="l00038"></a>00038                  <span class="keywordtype">int</span>               npixs,
+<a name="l00039"></a>00039                  <span class="keywordtype">double</span>            kappa,
+<a name="l00040"></a>00040                  <span class="keywordtype">int</span>               nclip,
+<a name="l00041"></a>00041                  <span class="keywordtype">double</span>            tolerance,
+<a name="l00042"></a>00042                  <span class="keywordtype">double</span>          * mean,
+<a name="l00043"></a>00043                  <span class="keywordtype">double</span>          * stdev)
+<a name="l00044"></a>00044 {
+<a name="l00045"></a>00045     <span class="keywordtype">int</span>    pos0 = (llx - 1) + (lly - 1) * nx; <span class="comment">/* 1st pixel to process */</span>
+<a name="l00046"></a>00046     <span class="keywordtype">double</span> nb   = (double) npixs;             <span class="comment">/* Non-bad pixels in window */</span>
+<a name="l00047"></a>00047 
+<a name="l00048"></a>00048     <span class="keywordtype">double</span> lo_cut    = *mean - kappa * (*stdev);
+<a name="l00049"></a>00049     <span class="keywordtype">double</span> hi_cut    = *mean + kappa * (*stdev);
+<a name="l00050"></a>00050     
+<a name="l00051"></a>00051     <span class="keywordtype">double</span> lo_cut_p  = lo_cut;
+<a name="l00052"></a>00052     <span class="keywordtype">double</span> hi_cut_p  = hi_cut;
+<a name="l00053"></a>00053 
+<a name="l00054"></a>00054     <span class="keywordtype">double</span> c_var_sum;
+<a name="l00055"></a>00055     <span class="keywordtype">double</span> c_mean = 0; <span class="comment">/* Avoid false uninit warning */</span>
+<a name="l00056"></a>00056     <span class="keywordtype">double</span> c_stdev = 0; <span class="comment">/* Avoid false uninit warning */</span>
+<a name="l00057"></a>00057 
+<a name="l00058"></a>00058     <span class="keywordtype">int</span>    iclip;
+<a name="l00059"></a>00059 
+<a name="l00060"></a>00060     <span class="keywordflow">for</span> (iclip = 0; iclip < nclip; iclip++) {
+<a name="l00061"></a>00061         <span class="keywordtype">int</span> pos = pos0;
+<a name="l00062"></a>00062         <span class="keywordtype">int</span> i, j;
+<a name="l00063"></a>00063 
+<a name="l00064"></a>00064     c_var_sum = var_sum;
+<a name="l00065"></a>00065     c_mean    = *mean;
+<a name="l00066"></a>00066     c_stdev   = *stdev;
+<a name="l00067"></a>00067     nb        = npixs;
+<a name="l00068"></a>00068     
+<a name="l00069"></a>00069         <span class="keywordflow">for</span> (j = lly - 1; j < ury; j++, pos += (nx - urx + llx - 1)) {
+<a name="l00070"></a>00070             <span class="keywordflow">for</span> (i = llx - 1; i < urx; i++, pos++) {
+<a name="l00071"></a>00071                 <span class="keywordflow">if</span> (pi[pos] > hi_cut || pi[pos] < lo_cut) {
+<a name="l00072"></a>00072                     <span class="keyword">const</span> <span class="keywordtype">double</span> delta = (double)pi[pos] - c_mean;
+<a name="l00073"></a>00073 
+<a name="l00074"></a>00074                     c_var_sum  -= nb * delta * delta / (nb - 1.0);
+<a name="l00075"></a>00075                     c_mean     -= delta / (nb - 1.0);
+<a name="l00076"></a>00076                     nb          = nb - 1.0;
+<a name="l00077"></a>00077                 }
+<a name="l00078"></a>00078             }
+<a name="l00079"></a>00079         }
+<a name="l00080"></a>00080 
+<a name="l00081"></a>00081     <span class="keywordflow">if</span> (nb == 1.0 || c_var_sum < 0.0) {
+<a name="l00082"></a>00082         cpl_msg_error(cpl_func, <span class="stringliteral">"Iteration %d: Too many pixels were "</span>
+<a name="l00083"></a>00083               <span class="stringliteral">"removed. This may cause unexpected behaviour. "</span>
+<a name="l00084"></a>00084               <span class="stringliteral">"Please set a lower number of iterations "</span>
+<a name="l00085"></a>00085                           <span class="stringliteral">"or increase the value of kappa\n"</span>, iclip);
+<a name="l00086"></a>00086         cpl_error_set(cpl_func, CPL_ERROR_DIVISION_BY_ZERO);
+<a name="l00087"></a>00087     } <span class="keywordflow">else</span> {
+<a name="l00088"></a>00088         c_stdev = sqrt(c_var_sum / (nb - 1.0));
+<a name="l00089"></a>00089     }
+<a name="l00090"></a>00090 
+<a name="l00091"></a>00091     lo_cut = c_mean - kappa * c_stdev;
+<a name="l00092"></a>00092     hi_cut = c_mean + kappa * c_stdev;
+<a name="l00093"></a>00093     
+<a name="l00094"></a>00094         <span class="keywordflow">if</span>(fabs(lo_cut - lo_cut_p) < tolerance &&
+<a name="l00095"></a>00095            fabs(hi_cut - hi_cut_p) < tolerance) {
+<a name="l00096"></a>00096             <span class="keywordflow">break</span>;
+<a name="l00097"></a>00097     } <span class="keywordflow">else</span> {
+<a name="l00098"></a>00098         lo_cut_p = lo_cut;
+<a name="l00099"></a>00099         hi_cut_p = hi_cut;
+<a name="l00100"></a>00100     }
+<a name="l00101"></a>00101     }
+<a name="l00102"></a>00102 
+<a name="l00103"></a>00103     *mean  = c_mean;
+<a name="l00104"></a>00104     *stdev = c_stdev;
+<a name="l00105"></a>00105 
+<a name="l00106"></a>00106     <span class="keywordflow">return</span> cpl_error_get_code();
+<a name="l00107"></a>00107 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/irplib__match__cats_8c_source.html b/html/irplib__match__cats_8c_source.html
new file mode 100644
index 0000000..36cca8f
--- /dev/null
+++ b/html/irplib__match__cats_8c_source.html
@@ -0,0 +1,201 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: irplib_match_cats.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>irplib_match_cats.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: irplib_match_cats.c,v 1.10 2009/12/18 10:44:48 cgarcia Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the irplib package</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: cgarcia $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2009/12/18 10:44:48 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.10 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span>
+<a name="l00032"></a>00032 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                                   Includes</span>
+<a name="l00034"></a>00034 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="preprocessor">#include <math.h></span>
+<a name="l00038"></a>00038 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00039"></a>00039 <span class="preprocessor">#include <cpl_table.h></span>
+<a name="l00040"></a>00040 
+<a name="l00041"></a>00041 <span class="preprocessor">#include "irplib_match_cats.h"</span>
+<a name="l00042"></a>00042 
+<a name="l00043"></a>00043 <span class="preprocessor">#define FILENAME_SZBUF 1024</span>
+<a name="l00044"></a>00044 <span class="preprocessor"></span>
+<a name="l00045"></a>00045 
+<a name="l00046"></a>00046 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00047"></a>00047 <span class="comment">/* Private functions</span>
+<a name="l00048"></a>00048 <span class="comment"> */</span>
+<a name="l00049"></a>00049 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00050"></a>00050 
+<a name="l00051"></a>00051 cpl_error_code irplib_match_cats_get_all_matching_pairs
+<a name="l00052"></a>00052 (cpl_table ** catalogues,
+<a name="l00053"></a>00053  <span class="keywordtype">int</span>          ncats,
+<a name="l00054"></a>00054  cpl_table  * matching_sets,
+<a name="l00055"></a>00055  <span class="keywordtype">int</span> (*binary_match_condition)
+<a name="l00056"></a>00056    (cpl_table * catalogue1,
+<a name="l00057"></a>00057     cpl_table * catalogue2,
+<a name="l00058"></a>00058     <span class="keywordtype">int</span>         iobj1,
+<a name="l00059"></a>00059     <span class="keywordtype">int</span>         iobj2)  );
+<a name="l00060"></a>00060 
+<a name="l00061"></a>00061 cpl_error_code irplib_match_cats_get_all_matches_cresc
+<a name="l00062"></a>00062 (cpl_table ** catalogues,
+<a name="l00063"></a>00063  cpl_array  * cat_index_begin,
+<a name="l00064"></a>00064  cpl_array  * cats_idx_set,
+<a name="l00065"></a>00065  <span class="keywordtype">int</span>          mincat_match,
+<a name="l00066"></a>00066  cpl_table * matching_sets);
+<a name="l00067"></a>00067 
+<a name="l00068"></a>00068 cpl_error_code irplib_match_cats_iterate_on_cat
+<a name="l00069"></a>00069 (cpl_table ** catalogues,
+<a name="l00070"></a>00070  cpl_array  * cats_idx_set,
+<a name="l00071"></a>00071  <span class="keywordtype">int</span>          icat_iterate,
+<a name="l00072"></a>00072  cpl_array  * valid_iobjs,
+<a name="l00073"></a>00073  <span class="keywordtype">int</span>          mincat_match,
+<a name="l00074"></a>00074  cpl_table  * matching_sets,
+<a name="l00075"></a>00075  cpl_table  * less_minmatch_sets);
+<a name="l00076"></a>00076 
+<a name="l00077"></a>00077 cpl_error_code irplib_match_cats_filter_obj_to_iter
+<a name="l00078"></a>00078 (cpl_array * cats_idx_set,
+<a name="l00079"></a>00079  <span class="keywordtype">int</span>         order_begin,
+<a name="l00080"></a>00080  cpl_table * matches_set,
+<a name="l00081"></a>00081  cpl_array * excluded_objs,
+<a name="l00082"></a>00082  <span class="keywordtype">int</span>         itercat_nobj);
+<a name="l00083"></a>00083 
+<a name="l00084"></a>00084 <span class="keywordtype">int</span> irplib_match_cats_match_condition
+<a name="l00085"></a>00085 (cpl_table ** catalogues,
+<a name="l00086"></a>00086  <span class="keywordtype">int</span>       *  cats_idx_set_ptr,
+<a name="l00087"></a>00087  <span class="keywordtype">int</span>          ncats);
+<a name="l00088"></a>00088 
+<a name="l00089"></a>00089 <span class="keywordtype">int</span> irplib_match_count_nonmatched
+<a name="l00090"></a>00090 (<span class="keywordtype">int</span> * cats_idx_set_ptr,
+<a name="l00091"></a>00091  <span class="keywordtype">int</span>   ncats);
+<a name="l00092"></a>00092 
+<a name="l00093"></a>00093 <span class="keywordtype">int</span> nCombinations;
+<a name="l00094"></a>00094 <span class="keywordtype">int</span> nFilter;
+<a name="l00095"></a>00095 
+<a name="l00096"></a>00096 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00100"></a>00100 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00101"></a>00101 
+<a name="l00104"></a>00104 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00124"></a>00124 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00125"></a>00125 cpl_table * <a class="code" href="group__irplib__cat.html#gaf3dbc2180a59e7187674707510205afe" title="Finds all the objects that appear at least in some of the catalogues.">irplib_match_cat_pairs</a>
+<a name="l00126"></a><a class="code" href="group__irplib__cat.html#gaf3dbc2180a59e7187674707510205afe">00126</a> (cpl_table ** catalogues,
+<a name="l00127"></a>00127  <span class="keywordtype">int</span>          ncats,
+<a name="l00128"></a>00128  <span class="keywordtype">int</span> (*binary_match_condition)
+<a name="l00129"></a>00129    (cpl_table * catalogue1,
+<a name="l00130"></a>00130     cpl_table * catalogue2,
+<a name="l00131"></a>00131     <span class="keywordtype">int</span>         iobj1,
+<a name="l00132"></a>00132     <span class="keywordtype">int</span>         iobj2)  )
+<a name="l00133"></a>00133 {
+<a name="l00134"></a>00134     cpl_table *  matching_sets;
+<a name="l00135"></a>00135 
+<a name="l00136"></a>00136     <span class="comment">//Initialize the solution</span>
+<a name="l00137"></a>00137     matching_sets = cpl_table_new(0);
+<a name="l00138"></a>00138     cpl_table_new_column_array(matching_sets, <span class="stringliteral">"MATCHING_SETS"</span>,
+<a name="l00139"></a>00139                                CPL_TYPE_INT, ncats);
+<a name="l00140"></a>00140 
+<a name="l00141"></a>00141     irplib_match_cats_get_all_matching_pairs
+<a name="l00142"></a>00142         (catalogues, ncats, matching_sets, binary_match_condition);
+<a name="l00143"></a>00143     
+<a name="l00144"></a>00144     <span class="keywordflow">return</span> matching_sets;
+<a name="l00145"></a>00145 }
+<a name="l00146"></a>00146 
+<a name="l00147"></a>00147 cpl_error_code irplib_match_cats_get_all_matching_pairs
+<a name="l00148"></a>00148 (cpl_table ** catalogues,
+<a name="l00149"></a>00149  <span class="keywordtype">int</span>          ncats,
+<a name="l00150"></a>00150  cpl_table  * matching_sets,
+<a name="l00151"></a>00151  <span class="keywordtype">int</span> (*binary_match_condition)
+<a name="l00152"></a>00152    (cpl_table * catalogue1,
+<a name="l00153"></a>00153     cpl_table * catalogue2,
+<a name="l00154"></a>00154     <span class="keywordtype">int</span>         iobj1,
+<a name="l00155"></a>00155     <span class="keywordtype">int</span>         iobj2)  )
+<a name="l00156"></a>00156 {
+<a name="l00157"></a>00157     <span class="keywordtype">int</span> icat1;
+<a name="l00158"></a>00158     <span class="keywordtype">int</span> icat2;
+<a name="l00159"></a>00159     
+<a name="l00160"></a>00160     nCombinations = 0;
+<a name="l00161"></a>00161     nFilter = 0;
+<a name="l00162"></a>00162 
+<a name="l00163"></a>00163     <span class="keywordflow">for</span>(icat1 = 0; icat1 < ncats ; ++icat1)
+<a name="l00164"></a>00164         <span class="keywordflow">for</span>(icat2 = icat1 + 1 ; icat2 < ncats ; ++icat2)
+<a name="l00165"></a>00165         {
+<a name="l00166"></a>00166             <span class="keywordtype">int</span> iobj1;
+<a name="l00167"></a>00167             <span class="keywordtype">int</span> iobj2;
+<a name="l00168"></a>00168             <span class="keywordtype">int</span> nobj1;
+<a name="l00169"></a>00169             <span class="keywordtype">int</span> nobj2;
+<a name="l00170"></a>00170             
+<a name="l00171"></a>00171             nobj1 = cpl_table_get_nrow(catalogues[icat1]);
+<a name="l00172"></a>00172             nobj2 = cpl_table_get_nrow(catalogues[icat2]);
+<a name="l00173"></a>00173 
+<a name="l00174"></a>00174             <span class="keywordflow">for</span>(iobj1 = 0; iobj1 < nobj1 ; ++iobj1)
+<a name="l00175"></a>00175                 <span class="keywordflow">for</span>(iobj2 = 0 ; iobj2 < nobj2 ; ++iobj2)
+<a name="l00176"></a>00176                 {
+<a name="l00177"></a>00177                     ++nCombinations;
+<a name="l00178"></a>00178                     <span class="keywordflow">if</span>(binary_match_condition(catalogues[icat1],
+<a name="l00179"></a>00179                                               catalogues[icat2],
+<a name="l00180"></a>00180                                               iobj1, iobj2))
+<a name="l00181"></a>00181                     {
+<a name="l00182"></a>00182                         cpl_array  * cats_idx_set;
+<a name="l00183"></a>00183                         <span class="keywordtype">int</span>          icat;
+<a name="l00184"></a>00184                         
+<a name="l00185"></a>00185                         ++nFilter;
+<a name="l00186"></a>00186                         cats_idx_set = cpl_array_new(ncats, CPL_TYPE_INT);
+<a name="l00187"></a>00187                         <span class="keywordflow">for</span>(icat = 0; icat < ncats; ++icat)
+<a name="l00188"></a>00188                         {
+<a name="l00189"></a>00189                             <span class="keywordflow">if</span>(icat == icat1)
+<a name="l00190"></a>00190                                 cpl_array_set_int(cats_idx_set, icat, iobj1);
+<a name="l00191"></a>00191                             <span class="keywordflow">else</span> <span class="keywordflow">if</span>(icat == icat2)
+<a name="l00192"></a>00192                                 cpl_array_set_int(cats_idx_set, icat, iobj2);
+<a name="l00193"></a>00193                             <span class="keywordflow">else</span>
+<a name="l00194"></a>00194                                 cpl_array_set_int(cats_idx_set, icat, -1);
+<a name="l00195"></a>00195                         }
+<a name="l00196"></a>00196                         
+<a name="l00197"></a>00197                         cpl_table_set_size(matching_sets,
+<a name="l00198"></a>00198                                            cpl_table_get_nrow(matching_sets)+1);
+<a name="l00199"></a>00199                         cpl_table_set_array(matching_sets,<span class="stringliteral">"MATCHING_SETS"</span>,
+<a name="l00200"></a>00200                                             cpl_table_get_nrow(matching_sets)-1,
+<a name="l00201"></a>00201                                             cats_idx_set);
+<a name="l00202"></a>00202                         cpl_array_delete(cats_idx_set);
+<a name="l00203"></a>00203                     }
+<a name="l00204"></a>00204                 }
+<a name="l00205"></a>00205         }
+<a name="l00206"></a>00206     
+<a name="l00207"></a>00207     <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l00208"></a>00208 }
+<a name="l00209"></a>00209 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/irplib__match__cats_8h_source.html b/html/irplib__match__cats_8h_source.html
new file mode 100644
index 0000000..b9742fe
--- /dev/null
+++ b/html/irplib__match__cats_8h_source.html
@@ -0,0 +1,62 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: irplib_match_cats.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>irplib_match_cats.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: irplib_match_cats.h,v 1.5 2009/12/18 10:44:48 cgarcia Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the irplib package</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: cgarcia $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2009/12/18 10:44:48 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.5 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifndef IRPLIB_MATCH_CATS_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#define IRPLIB_MATCH_CATS_H</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span>
+<a name="l00031"></a>00031 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00032"></a>00032 <span class="comment">                                   Includes</span>
+<a name="l00033"></a>00033 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00034"></a>00034 
+<a name="l00035"></a>00035 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 cpl_table * <a class="code" href="group__irplib__cat.html#gaf3dbc2180a59e7187674707510205afe" title="Finds all the objects that appear at least in some of the catalogues.">irplib_match_cat_pairs</a>
+<a name="l00038"></a>00038 (cpl_table ** catalogues,
+<a name="l00039"></a>00039  <span class="keywordtype">int</span>          nCats,
+<a name="l00040"></a>00040  <span class="keywordtype">int</span> (*binary_match_condition)
+<a name="l00041"></a>00041    (cpl_table * catalogue1,
+<a name="l00042"></a>00042     cpl_table * catalogue2,
+<a name="l00043"></a>00043     <span class="keywordtype">int</span>         iobj1,
+<a name="l00044"></a>00044     <span class="keywordtype">int</span>         iobj2)  );
+<a name="l00045"></a>00045 
+<a name="l00046"></a>00046 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/irplib__mkmaster_8c_source.html b/html/irplib__mkmaster_8c_source.html
new file mode 100644
index 0000000..db32378
--- /dev/null
+++ b/html/irplib__mkmaster_8c_source.html
@@ -0,0 +1,483 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: irplib_mkmaster.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>irplib_mkmaster.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: irplib_mkmaster.c,v 1.5 2012/01/12 14:29:41 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the irplib package</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2012/01/12 14:29:41 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.5 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span>
+<a name="l00032"></a>00032 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                                   Includes</span>
+<a name="l00034"></a>00034 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 
+<a name="l00036"></a>00036 <span class="preprocessor">#include <math.h></span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include <string.h></span>
+<a name="l00038"></a>00038 <span class="preprocessor">#include "irplib_mkmaster.h"</span>
+<a name="l00039"></a>00039 
+<a name="l00040"></a>00040 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00044"></a>00044 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00045"></a>00045 
+<a name="l00047"></a>00047 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00054"></a>00054 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00055"></a>00055 
+<a name="l00056"></a>00056 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l00068"></a>00068 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00069"></a>00069 <span class="keyword">static</span> cpl_vector * 
+<a name="l00070"></a>00070 irplib_imagelist_get_clean_mean_levels(<span class="keyword">const</span> cpl_imagelist* iml, 
+<a name="l00071"></a>00071                                        <span class="keyword">const</span> <span class="keywordtype">double</span> kappa, 
+<a name="l00072"></a>00072                                        <span class="keyword">const</span> <span class="keywordtype">int</span> nclip,
+<a name="l00073"></a>00073                                        <span class="keyword">const</span> <span class="keywordtype">double</span> tolerance)
+<a name="l00074"></a>00074 {
+<a name="l00075"></a>00075 
+<a name="l00076"></a>00076    <span class="keyword">const</span> cpl_image* img=NULL;
+<a name="l00077"></a>00077    <span class="keywordtype">int</span> size=0;
+<a name="l00078"></a>00078    <span class="keywordtype">int</span> i=0;
+<a name="l00079"></a>00079    cpl_vector* levels=NULL;
+<a name="l00080"></a>00080    <span class="keywordtype">double</span>* pval=NULL;
+<a name="l00081"></a>00081    <span class="keywordtype">double</span> mean=0;
+<a name="l00082"></a>00082    <span class="keywordtype">double</span> stdev=0;
+<a name="l00083"></a>00083 
+<a name="l00084"></a>00084 
+<a name="l00085"></a>00085    cpl_error_ensure(iml != NULL, CPL_ERROR_NULL_INPUT, <span class="keywordflow">return</span>(levels),
+<a name="l00086"></a>00086                     <span class="stringliteral">"Null input image list"</span>);
+<a name="l00087"></a>00087    cpl_error_ensure(kappa >= 0, CPL_ERROR_ILLEGAL_INPUT, <span class="keywordflow">return</span>(levels), 
+<a name="l00088"></a>00088                     <span class="stringliteral">"Must be kappa>0"</span>);
+<a name="l00089"></a>00089 
+<a name="l00090"></a>00090    size=cpl_imagelist_get_size(iml);
+<a name="l00091"></a>00091    levels=cpl_vector_new(size);
+<a name="l00092"></a>00092    pval=cpl_vector_get_data(levels);
+<a name="l00093"></a>00093 
+<a name="l00094"></a>00094    <span class="keywordflow">for</span>(i=0;i<size;i++) {
+<a name="l00095"></a>00095       img=cpl_imagelist_get_const(iml,i);
+<a name="l00096"></a>00096       irplib_ksigma_clip(img,1,1,
+<a name="l00097"></a>00097                          cpl_image_get_size_x(img),
+<a name="l00098"></a>00098                          cpl_image_get_size_y(img),
+<a name="l00099"></a>00099                          nclip,kappa,tolerance,&mean,&stdev);
+<a name="l00100"></a>00100       cpl_msg_info(cpl_func,<span class="stringliteral">"Ima %d mean level: %g"</span>,i+1,mean);
+<a name="l00101"></a>00101       pval[i]=mean;
+<a name="l00102"></a>00102    }
+<a name="l00103"></a>00103 
+<a name="l00104"></a>00104 
+<a name="l00105"></a>00105    <span class="keywordflow">return</span> levels;
+<a name="l00106"></a>00106 }
+<a name="l00107"></a>00107 
+<a name="l00108"></a>00108 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l00116"></a>00116 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00117"></a>00117 <span class="keyword">static</span> cpl_error_code
+<a name="l00118"></a>00118 irplib_imagelist_subtract_values(cpl_imagelist** iml, cpl_vector* values)
+<a name="l00119"></a>00119 {
+<a name="l00120"></a>00120 
+<a name="l00121"></a>00121    cpl_image* img=NULL;
+<a name="l00122"></a>00122    <span class="keywordtype">int</span> size=0;
+<a name="l00123"></a>00123    <span class="keywordtype">int</span> i=0;
+<a name="l00124"></a>00124    <span class="keywordtype">double</span>* pval=NULL;
+<a name="l00125"></a>00125   
+<a name="l00126"></a>00126    size=cpl_imagelist_get_size(*iml);
+<a name="l00127"></a>00127    pval=cpl_vector_get_data(values);
+<a name="l00128"></a>00128 
+<a name="l00129"></a>00129    <span class="keywordflow">for</span>(i=0;i<size;i++) {
+<a name="l00130"></a>00130       img=cpl_imagelist_get(*iml,i);
+<a name="l00131"></a>00131       cpl_image_subtract_scalar(img,pval[i]);
+<a name="l00132"></a>00132       cpl_imagelist_set(*iml,img,i);
+<a name="l00133"></a>00133    }
+<a name="l00134"></a>00134 
+<a name="l00135"></a>00135    <span class="keywordflow">return</span> cpl_error_get_code();
+<a name="l00136"></a>00136 }
+<a name="l00137"></a>00137 
+<a name="l00138"></a>00138 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00151"></a>00151 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00152"></a>00152 <span class="keyword">static</span> <span class="keywordtype">double</span> 
+<a name="l00153"></a>00153 irplib_vector_ksigma(cpl_vector *values,
+<a name="l00154"></a>00154                      <span class="keyword">const</span> <span class="keywordtype">double</span> klow, <span class="keyword">const</span> <span class="keywordtype">double</span> khigh, <span class="keywordtype">int</span> kiter)
+<a name="l00155"></a>00155 {
+<a name="l00156"></a>00156    cpl_vector *accepted;
+<a name="l00157"></a>00157    <span class="keywordtype">double</span>  mean  = 0.0;
+<a name="l00158"></a>00158    <span class="keywordtype">double</span>  sigma = 0.0;
+<a name="l00159"></a>00159    <span class="keywordtype">double</span> *data  = cpl_vector_get_data(values);
+<a name="l00160"></a>00160    <span class="keywordtype">int</span>     n     = cpl_vector_get_size(values);
+<a name="l00161"></a>00161    <span class="keywordtype">int</span>     ngood = n;
+<a name="l00162"></a>00162    <span class="keywordtype">int</span>     count = 0;
+<a name="l00163"></a>00163    <span class="keywordtype">int</span>     i;
+<a name="l00164"></a>00164  
+<a name="l00165"></a>00165    <span class="comment">/*</span>
+<a name="l00166"></a>00166 <span class="comment">    * At first iteration the mean is taken as the median, and the</span>
+<a name="l00167"></a>00167 <span class="comment">    * standard deviation relative to this value is computed.</span>
+<a name="l00168"></a>00168 <span class="comment">    */</span>
+<a name="l00169"></a>00169 
+<a name="l00170"></a>00170    mean = cpl_vector_get_median(values);
+<a name="l00171"></a>00171 
+<a name="l00172"></a>00172    <span class="keywordflow">for</span> (i = 0; i < n; i++) {
+<a name="l00173"></a>00173       sigma += (mean - data[i]) * (mean - data[i]);
+<a name="l00174"></a>00174    }
+<a name="l00175"></a>00175    sigma = sqrt(sigma / (n - 1));
+<a name="l00176"></a>00176 
+<a name="l00177"></a>00177    <span class="keywordflow">while</span> (kiter) {
+<a name="l00178"></a>00178       count = 0;
+<a name="l00179"></a>00179       <span class="keywordflow">for</span> (i = 0; i < ngood; i++) {
+<a name="l00180"></a>00180          <span class="keywordflow">if</span> (data[i]-mean < khigh*sigma && mean-data[i] < klow*sigma) {
+<a name="l00181"></a>00181             data[count] = data[i];
+<a name="l00182"></a>00182             ++count;
+<a name="l00183"></a>00183          }
+<a name="l00184"></a>00184       }
+<a name="l00185"></a>00185 
+<a name="l00186"></a>00186       <span class="keywordflow">if</span> (count == 0) <span class="comment">// This cannot happen at first iteration.</span>
+<a name="l00187"></a>00187          <span class="keywordflow">break</span>;      <span class="comment">// So we can break: we have already computed a mean.</span>
+<a name="l00188"></a>00188 
+<a name="l00189"></a>00189       <span class="comment">/*</span>
+<a name="l00190"></a>00190 <span class="comment">       * The mean must be computed even if no element was rejected</span>
+<a name="l00191"></a>00191 <span class="comment">       * (count == ngood), because at first iteration median instead</span>
+<a name="l00192"></a>00192 <span class="comment">       * of mean was computed.</span>
+<a name="l00193"></a>00193 <span class="comment">       */</span>
+<a name="l00194"></a>00194 
+<a name="l00195"></a>00195       accepted = cpl_vector_wrap(count, data);
+<a name="l00196"></a>00196       mean = cpl_vector_get_mean(accepted);
+<a name="l00197"></a>00197       <span class="keywordflow">if</span>(count>1) {
+<a name="l00198"></a>00198          sigma = cpl_vector_get_stdev(accepted);
+<a name="l00199"></a>00199       }
+<a name="l00200"></a>00200       cpl_vector_unwrap(accepted);
+<a name="l00201"></a>00201 
+<a name="l00202"></a>00202       <span class="keywordflow">if</span> (count == ngood) {
+<a name="l00203"></a>00203          <span class="keywordflow">break</span>;
+<a name="l00204"></a>00204       }
+<a name="l00205"></a>00205       ngood = count;
+<a name="l00206"></a>00206       --kiter;
+<a name="l00207"></a>00207    }
+<a name="l00208"></a>00208 
+<a name="l00209"></a>00209    <span class="keywordflow">return</span> mean;
+<a name="l00210"></a>00210 }
+<a name="l00211"></a>00211 
+<a name="l00212"></a>00212 
+<a name="l00231"></a>00231 <span class="keyword">static</span> cpl_image *
+<a name="l00232"></a>00232 irplib_imagelist_ksigma_stack(<span class="keyword">const</span> cpl_imagelist *imlist, 
+<a name="l00233"></a>00233                               <span class="keywordtype">double</span> klow, <span class="keywordtype">double</span> khigh, <span class="keywordtype">int</span> kiter)
+<a name="l00234"></a>00234 {
+<a name="l00235"></a>00235    <span class="keywordtype">int</span>         ni, nx, ny, npix;
+<a name="l00236"></a>00236    cpl_image  *out_ima=NULL;
+<a name="l00237"></a>00237    cpl_imagelist  *loc_iml=NULL;
+<a name="l00238"></a>00238    <span class="keywordtype">double</span>      *pout_ima=NULL;
+<a name="l00239"></a>00239    cpl_image  *image=NULL;
+<a name="l00240"></a>00240    <span class="keyword">const</span> <span class="keywordtype">double</span>     **data=NULL;
+<a name="l00241"></a>00241    <span class="keywordtype">double</span>     *med=NULL;
+<a name="l00242"></a>00242    cpl_vector *time_line=NULL;
+<a name="l00243"></a>00243   
+<a name="l00244"></a>00244    <span class="keywordtype">double</span>     *ptime_line=NULL;
+<a name="l00245"></a>00245    <span class="keywordtype">int</span>         i, j;
+<a name="l00246"></a>00246    <span class="keywordtype">double</span> mean_of_medians=0;
+<a name="l00247"></a>00247 
+<a name="l00248"></a>00248    cpl_error_ensure(imlist != NULL, CPL_ERROR_NULL_INPUT, <span class="keywordflow">return</span>(out_ima),
+<a name="l00249"></a>00249                     <span class="stringliteral">"Null input image list"</span>);
+<a name="l00250"></a>00250 
+<a name="l00251"></a>00251    ni         = cpl_imagelist_get_size(imlist);
+<a name="l00252"></a>00252    loc_iml        = cpl_imagelist_duplicate(imlist);
+<a name="l00253"></a>00253    image      = cpl_imagelist_get(loc_iml, 0);
+<a name="l00254"></a>00254    nx         = cpl_image_get_size_x(image);
+<a name="l00255"></a>00255    ny         = cpl_image_get_size_y(image);
+<a name="l00256"></a>00256    npix       = nx * ny;
+<a name="l00257"></a>00257 
+<a name="l00258"></a>00258    out_ima    = cpl_image_new(nx, ny, CPL_TYPE_DOUBLE);
+<a name="l00259"></a>00259    pout_ima   = cpl_image_get_data_double(out_ima);
+<a name="l00260"></a>00260 
+<a name="l00261"></a>00261    time_line  = cpl_vector_new(ni);
+<a name="l00262"></a>00262    
+<a name="l00263"></a>00263    ptime_line = cpl_vector_get_data(time_line);
+<a name="l00264"></a>00264 
+<a name="l00265"></a>00265    data = cpl_calloc(<span class="keyword">sizeof</span>(<span class="keywordtype">double</span> *), ni);
+<a name="l00266"></a>00266    med  = cpl_calloc(<span class="keyword">sizeof</span>(<span class="keywordtype">double</span>), ni);
+<a name="l00267"></a>00267 
+<a name="l00268"></a>00268    <span class="keywordflow">for</span> (i = 0; i < ni; i++) {
+<a name="l00269"></a>00269       image = cpl_imagelist_get(loc_iml, i);
+<a name="l00270"></a>00270       med[i]=cpl_image_get_median(image);
+<a name="l00271"></a>00271       cpl_image_subtract_scalar(image,med[i]);
+<a name="l00272"></a>00272       data[i] = cpl_image_get_data_double(image);
+<a name="l00273"></a>00273       mean_of_medians+=med[i];
+<a name="l00274"></a>00274    }
+<a name="l00275"></a>00275    mean_of_medians/=ni;
+<a name="l00276"></a>00276 
+<a name="l00277"></a>00277    <span class="keywordflow">for</span> (i = 0; i < npix; i++) {
+<a name="l00278"></a>00278       <span class="keywordflow">for</span> (j = 0; j < ni; j++) {
+<a name="l00279"></a>00279          ptime_line[j] = data[j][i];
+<a name="l00280"></a>00280       }
+<a name="l00281"></a>00281       pout_ima[i] = irplib_vector_ksigma(time_line, klow, khigh, kiter); 
+<a name="l00282"></a>00282    }
+<a name="l00283"></a>00283  
+<a name="l00284"></a>00284    cpl_image_add_scalar(out_ima,mean_of_medians);
+<a name="l00285"></a>00285 
+<a name="l00286"></a>00286  
+<a name="l00287"></a>00287    cpl_free(data);
+<a name="l00288"></a>00288    cpl_free(med);
+<a name="l00289"></a>00289    cpl_vector_delete(time_line);
+<a name="l00290"></a>00290    cpl_imagelist_delete(loc_iml);
+<a name="l00291"></a>00291 
+<a name="l00292"></a>00292    <span class="keywordflow">return</span> out_ima;
+<a name="l00293"></a>00293 
+<a name="l00294"></a>00294 } 
+<a name="l00295"></a>00295 
+<a name="l00296"></a>00296 
+<a name="l00297"></a>00297 
+<a name="l00298"></a>00298 
+<a name="l00299"></a>00299 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l00311"></a>00311 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00312"></a>00312 cpl_image*
+<a name="l00313"></a><a class="code" href="group__irplib__calib.html#gae11ebd9b30a6c781265ba2e5af87722b">00313</a> <a class="code" href="group__irplib__calib.html#gae11ebd9b30a6c781265ba2e5af87722b" title="Computes master frame by clean stack mean of the input imagelist.">irplib_mkmaster_mean</a>(cpl_imagelist* images,<span class="keyword">const</span> <span class="keywordtype">double</span> kappa, <span class="keyword">const</span> <span class="keywordtype">int</span> nclip, <span class [...]
+<a name="l00314"></a>00314 {
+<a name="l00315"></a>00315 
+<a name="l00316"></a>00316    cpl_image* master=NULL;
+<a name="l00317"></a>00317    cpl_vector* levels=NULL;
+<a name="l00318"></a>00318    <span class="keywordtype">double</span> mean=0;
+<a name="l00319"></a>00319    cpl_imagelist* iml=NULL;
+<a name="l00320"></a>00320 
+<a name="l00321"></a>00321    cpl_msg_info(cpl_func,<span class="stringliteral">"method mean"</span>);
+<a name="l00322"></a>00322    iml=cpl_imagelist_duplicate(images);
+<a name="l00323"></a>00323    levels=irplib_imagelist_get_clean_mean_levels(iml,kappa,nclip,tolerance);
+<a name="l00324"></a>00324    mean=cpl_vector_get_mean(levels);
+<a name="l00325"></a>00325    cpl_msg_info(cpl_func,<span class="stringliteral">"Master mean level: %g"</span>,mean);
+<a name="l00326"></a>00326 
+<a name="l00327"></a>00327    irplib_imagelist_subtract_values(&iml,levels);
+<a name="l00328"></a>00328 
+<a name="l00329"></a>00329    master = irplib_imagelist_ksigma_stack(iml,klow,khigh,niter);
+<a name="l00330"></a>00330    cpl_image_add_scalar(master,mean);
+<a name="l00331"></a>00331 
+<a name="l00332"></a>00332    cpl_vector_delete(levels);
+<a name="l00333"></a>00333    cpl_imagelist_delete(iml);
+<a name="l00334"></a>00334    <span class="keywordflow">return</span> master;
+<a name="l00335"></a>00335 
+<a name="l00336"></a>00336 }
+<a name="l00337"></a>00337 
+<a name="l00338"></a>00338 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l00350"></a>00350 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00351"></a>00351 cpl_image* 
+<a name="l00352"></a><a class="code" href="group__irplib__calib.html#ga31157521720077a762a43644a503bbf2">00352</a> <a class="code" href="group__irplib__calib.html#ga31157521720077a762a43644a503bbf2" title="Computes master frame by clean stack median of the input imagelist.">irplib_mkmaster_median</a>(cpl_imagelist* images,<span class="keyword">const</span> <span class="keywordtype">double</span> kappa, <span class="keyword">const</span> <span class="keywordtype">int</span> nclip, <span c [...]
+<a name="l00353"></a>00353 {
+<a name="l00354"></a>00354 
+<a name="l00355"></a>00355    cpl_image* master=NULL;
+<a name="l00356"></a>00356    cpl_vector* levels=NULL;
+<a name="l00357"></a>00357    <span class="keywordtype">double</span> mean=0;
+<a name="l00358"></a>00358    cpl_imagelist* iml=NULL;
+<a name="l00359"></a>00359 
+<a name="l00360"></a>00360    cpl_msg_info(cpl_func,<span class="stringliteral">"method median"</span>);
+<a name="l00361"></a>00361    iml=cpl_imagelist_duplicate(images);
+<a name="l00362"></a>00362    levels=irplib_imagelist_get_clean_mean_levels(iml,kappa,nclip,tolerance);
+<a name="l00363"></a>00363 
+<a name="l00364"></a>00364    mean=cpl_vector_get_mean(levels);
+<a name="l00365"></a>00365    cpl_msg_info(cpl_func,<span class="stringliteral">"Master mean level: %g"</span>,mean);
+<a name="l00366"></a>00366    irplib_imagelist_subtract_values(&iml,levels);
+<a name="l00367"></a>00367        
+<a name="l00368"></a>00368    master = cpl_imagelist_collapse_median_create(iml);
+<a name="l00369"></a>00369 
+<a name="l00370"></a>00370    cpl_image_add_scalar(master,mean);
+<a name="l00371"></a>00371 
+<a name="l00372"></a>00372    cpl_vector_delete(levels);
+<a name="l00373"></a>00373    cpl_imagelist_delete(iml);
+<a name="l00374"></a>00374 
+<a name="l00375"></a>00375    <span class="keywordflow">return</span> master;
+<a name="l00376"></a>00376 
+<a name="l00377"></a>00377 }
+<a name="l00378"></a>00378 
+<a name="l00379"></a>00379 <span class="comment">/* Work in progress */</span>
+<a name="l00380"></a>00380 <span class="keyword">static</span> cpl_error_code
+<a name="l00381"></a>00381 irplib_mkmaster_dark_qc(<span class="keyword">const</span> cpl_imagelist* raw_images,
+<a name="l00382"></a>00382     cpl_imagelist* preproc_images,
+<a name="l00383"></a>00383     <span class="keyword">const</span> cpl_parameterlist* parameters,
+<a name="l00384"></a>00384      <span class="keyword">const</span> <span class="keywordtype">int</span> pr_num_x, <span class="keyword">const</span> <span class="keywordtype">int</span> pr_num_y,
+<a name="l00385"></a>00385     <span class="keyword">const</span> <span class="keywordtype">int</span> pr_box_sx, <span class="keyword">const</span> <span class="keywordtype">int</span> pr_box_sy, <span class="keyword">const</span> <span class="keywordtype">char</span>* recipe_id,
+<a name="l00386"></a>00386     cpl_table* qclog) {
+<a name="l00387"></a>00387 
+<a name="l00388"></a>00388    cpl_ensure_code(qclog !=NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00389"></a>00389    cpl_ensure_code(recipe_id !=NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00390"></a>00390    cpl_ensure_code(parameters !=NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00391"></a>00391 
+<a name="l00392"></a>00392   <span class="keywordtype">int</span> i = 0;
+<a name="l00393"></a>00393   cpl_image* current_dark = 0;
+<a name="l00394"></a>00394   <span class="keywordflow">if</span> (pr_num_x != 0 && pr_num_y != 0 && pr_box_sx != 0 && pr_box_sy != 0) {
+<a name="l00395"></a>00395     <span class="keywordflow">for</span> (i = 0; i < cpl_imagelist_get_size(raw_images); i++) {
+<a name="l00396"></a>00396       current_dark = cpl_image_duplicate(
+<a name="l00397"></a>00397           cpl_imagelist_get_const(preproc_images, i));
+<a name="l00398"></a>00398       cpl_msg_info(cpl_func, <span class="stringliteral">"Calculating QC parameters on raw dark frame %d"</span>,
+<a name="l00399"></a>00399           i);
+<a name="l00400"></a>00400       <span class="comment">/* Here To be defined more general way to qc-log */</span>
+<a name="l00401"></a>00401        <span class="comment">/* UVES specific stuff: may be this function should not be put in irplib</span>
+<a name="l00402"></a>00402 <span class="comment">      irplib_mdark_region_qc(current_dark, parameters, raw_images, recipe_id,qclog);</span>
+<a name="l00403"></a>00403 <span class="comment">       */</span>    
+<a name="l00404"></a>00404     }
+<a name="l00405"></a>00405   }
+<a name="l00406"></a>00406   <span class="keywordflow">return</span> cpl_error_get_code();
+<a name="l00407"></a>00407 }
+<a name="l00408"></a>00408 
+<a name="l00409"></a>00409 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l00419"></a>00419 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l00420"></a>00420 <span class="keyword">static</span> <span class="keywordtype">double</span>
+<a name="l00421"></a>00421 irplib_head_get_exptime(<span class="keyword">const</span> cpl_propertylist * plist) {
+<a name="l00422"></a>00422   <span class="keywordtype">double</span> result = 0; <span class="comment">/* Conversion from electrons to ADUs */</span>
+<a name="l00423"></a>00423 
+<a name="l00424"></a>00424   result=cpl_propertylist_get_double(plist, <span class="stringliteral">"EXPTIME"</span>);
+<a name="l00425"></a>00425   cpl_ensure_code(result >= 0, CPL_ERROR_ILLEGAL_OUTPUT);
+<a name="l00426"></a>00426 
+<a name="l00427"></a>00427   <span class="keywordflow">return</span> result;
+<a name="l00428"></a>00428 }
+<a name="l00429"></a>00429 
+<a name="l00430"></a>00430 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l00438"></a>00438 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l00439"></a>00439 <span class="keyword">static</span> cpl_error_code
+<a name="l00440"></a>00440 irplib_head_set_exptime(cpl_propertylist *plist, <span class="keywordtype">double</span> exptime)
+<a name="l00441"></a>00441 {
+<a name="l00442"></a>00442    cpl_propertylist_update_double(plist, <span class="stringliteral">"EXPTIME"</span>, exptime);
+<a name="l00443"></a>00443    cpl_propertylist_set_comment(plist, <span class="stringliteral">"EXPTIME"</span>, <span class="stringliteral">"Total integration time"</span>);
+<a name="l00444"></a>00444 
+<a name="l00445"></a>00445     <span class="keywordflow">return</span> cpl_error_get_code();
+<a name="l00446"></a>00446 }
+<a name="l00447"></a>00447 
+<a name="l00448"></a>00448 <span class="keyword">static</span> cpl_imagelist*
+<a name="l00449"></a>00449 irplib_mkmaster_dark_fill_imagelist(<span class="keyword">const</span> cpl_imagelist* raw_images,
+<a name="l00450"></a>00450     cpl_propertylist** raw_headers, <span class="keyword">const</span> cpl_image* master_bias,
+<a name="l00451"></a>00451     <span class="keywordtype">double</span>* mean_exptime) {
+<a name="l00452"></a>00452   <span class="comment">/* First process each input image and store the results in a</span>
+<a name="l00453"></a>00453 <span class="comment">   new image list */</span>
+<a name="l00454"></a>00454 
+<a name="l00455"></a>00455   cpl_imagelist* preproc_images = NULL;
+<a name="l00456"></a>00456   <span class="keywordtype">int</span> i = 0;
+<a name="l00457"></a>00457   cpl_image* current_dark = NULL;
+<a name="l00458"></a>00458   <span class="keywordtype">double</span> min_exptime = 0;
+<a name="l00459"></a>00459   <span class="keywordtype">double</span> max_exptime = 0;
+<a name="l00460"></a>00460 
+<a name="l00461"></a>00461   preproc_images = cpl_imagelist_new();
+<a name="l00462"></a>00462   <span class="keywordflow">for</span> (i = 0; i < cpl_imagelist_get_size(raw_images); i++) {
+<a name="l00463"></a>00463     <span class="keywordtype">double</span> exposure_time = 0.0;
+<a name="l00464"></a>00464     <span class="keyword">const</span> cpl_propertylist *current_header;
+<a name="l00465"></a>00465 
+<a name="l00466"></a>00466     current_dark = cpl_image_duplicate(cpl_imagelist_get_const(raw_images, i));
+<a name="l00467"></a>00467     current_header = raw_headers[i];
+<a name="l00468"></a>00468 
+<a name="l00469"></a>00469     <span class="comment">/* Subtract master bias */</span>
+<a name="l00470"></a>00470     <span class="keywordflow">if</span> (master_bias != NULL) {
+<a name="l00471"></a>00471       cpl_msg_info(cpl_func, <span class="stringliteral">"Subtracting master bias"</span>);
+<a name="l00472"></a>00472       cpl_image_subtract(current_dark, master_bias);
+<a name="l00473"></a>00473     } <span class="keywordflow">else</span> {
+<a name="l00474"></a>00474       cpl_msg_info(cpl_func, <span class="stringliteral">"Skipping bias subtraction"</span>);
+<a name="l00475"></a>00475     }
+<a name="l00476"></a>00476 
+<a name="l00477"></a>00477     exposure_time = irplib_head_get_exptime(current_header);
+<a name="l00478"></a>00478 
+<a name="l00479"></a>00479     <span class="comment">/* Initialize/update min/max exposure time*/</span>
+<a name="l00480"></a>00480     <span class="keywordflow">if</span> (i == 0 || exposure_time < min_exptime) {
+<a name="l00481"></a>00481       min_exptime = exposure_time;
+<a name="l00482"></a>00482     }
+<a name="l00483"></a>00483     <span class="keywordflow">if</span> (i == 0 || exposure_time > max_exptime) {
+<a name="l00484"></a>00484       max_exptime = exposure_time;
+<a name="l00485"></a>00485     }
+<a name="l00486"></a>00486 
+<a name="l00487"></a>00487     <span class="comment">/* Do not normalize to unit exposure time */</span>
+<a name="l00488"></a>00488     <span class="comment">/*        If this is uncommented, then remember to also calculate the</span>
+<a name="l00489"></a>00489 <span class="comment">     correct master dark exposure time below.</span>
+<a name="l00490"></a>00490 <span class="comment">     irplib_msg("Normalizing from %f s to unit exposure time", exposure_time);</span>
+<a name="l00491"></a>00491 <span class="comment">     check( cpl_image_divide_scalar(current_dark, exposure_time),</span>
+<a name="l00492"></a>00492 <span class="comment">     "Error normalizing dark frame");   */</span>
+<a name="l00493"></a>00493 
+<a name="l00494"></a>00494     <span class="comment">/* Append to imagelist */</span>
+<a name="l00495"></a>00495     cpl_imagelist_set(preproc_images, current_dark, i);
+<a name="l00496"></a>00496 
+<a name="l00497"></a>00497     <span class="comment">/* Don't deallocate the image. It will be deallocated when</span>
+<a name="l00498"></a>00498 <span class="comment">     the image list is deallocated */</span>
+<a name="l00499"></a>00499     current_dark = NULL;
+<a name="l00500"></a>00500   }
+<a name="l00501"></a>00501 
+<a name="l00502"></a>00502 
+<a name="l00503"></a>00503   <span class="comment">/* Check exposure times */</span>
+<a name="l00504"></a>00504    cpl_msg_info(cpl_func,
+<a name="l00505"></a>00505        <span class="stringliteral">"Exposure times range from %e s to %e s (%e %% variation)"</span>, min_exptime,
+<a name="l00506"></a>00506        max_exptime, 100 * (max_exptime - min_exptime) / min_exptime);
+<a name="l00507"></a>00507 
+<a name="l00508"></a>00508    <span class="keywordflow">if</span> ((max_exptime - min_exptime) / min_exptime > .001) {
+<a name="l00509"></a>00509      cpl_msg_warning(cpl_func, <span class="stringliteral">"Exposure times differ by %e %%"</span>,
+<a name="l00510"></a>00510          100 * (max_exptime - min_exptime) / min_exptime);
+<a name="l00511"></a>00511    }
+<a name="l00512"></a>00512 
+<a name="l00513"></a>00513    <span class="comment">/* compute correct exposure time */</span>
+<a name="l00514"></a>00514    *mean_exptime=0.5 * (max_exptime + min_exptime);
+<a name="l00515"></a>00515   <span class="keywordflow">return</span> preproc_images;
+<a name="l00516"></a>00516 }
+<a name="l00517"></a>00517 
+<a name="l00518"></a>00518 
+<a name="l00519"></a>00519 cpl_image *
+<a name="l00520"></a>00520 irplib_mdark_process_chip(<span class="keyword">const</span> cpl_imagelist *raw_images,
+<a name="l00521"></a>00521     cpl_propertylist **raw_headers, <span class="keyword">const</span> cpl_image *master_bias,
+<a name="l00522"></a>00522     cpl_propertylist *mdark_header, <span class="keyword">const</span> cpl_parameterlist *parameters,
+<a name="l00523"></a>00523     <span class="keyword">const</span> <span class="keywordtype">char</span>* recipe_id, cpl_table* qclog, <span class="keyword">const</span> <span class="keywordtype">int</span> do_qc,
+<a name="l00524"></a>00524     <span class="keyword">const</span> <span class="keywordtype">char</span>* STACK_METHOD, <span class="keyword">const</span> <span class="keywordtype">double</span> STACK_KLOW, <span class="keyword">const</span> <span class="keywordtype">double</span> STACK_KHIGH,
+<a name="l00525"></a>00525     <span class="keyword">const</span> <span class="keywordtype">int</span> STACK_NITER,
+<a name="l00526"></a>00526     <span class="keyword">const</span> <span class="keywordtype">int</span> pr_num_x, <span class="keyword">const</span> <span class="keywordtype">int</span> pr_num_y,
+<a name="l00527"></a>00527     <span class="keyword">const</span> <span class="keywordtype">int</span> pr_box_sx, <span class="keyword">const</span> <span class="keywordtype">int</span> pr_box_sy) {
+<a name="l00528"></a>00528   cpl_image *master_dark = NULL; <span class="comment">/* Result */</span>
+<a name="l00529"></a>00529   cpl_image *current_dark = NULL;
+<a name="l00530"></a>00530   cpl_imagelist *preproc_images = NULL;
+<a name="l00531"></a>00531   <span class="keywordtype">double</span> mean_exptime = 0;
+<a name="l00532"></a>00532 
+<a name="l00533"></a>00533   <span class="comment">/* First process each input image and store the results in a</span>
+<a name="l00534"></a>00534 <span class="comment">   new image list */</span>
+<a name="l00535"></a>00535   preproc_images = irplib_mkmaster_dark_fill_imagelist(raw_images, raw_headers,
+<a name="l00536"></a>00536       master_bias, &mean_exptime);
+<a name="l00537"></a>00537   <span class="keywordflow">if</span> (do_qc) {
+<a name="l00538"></a>00538      <span class="comment">/* Here we should compute QC but a a better way to log it is TBD  */</span>
+<a name="l00539"></a>00539     irplib_mkmaster_dark_qc(raw_images, preproc_images, parameters, pr_num_x,
+<a name="l00540"></a>00540         pr_num_y, pr_box_sx, pr_box_sy, recipe_id, qclog);
+<a name="l00541"></a>00541      
+<a name="l00542"></a>00542   }
+<a name="l00543"></a>00543   <span class="comment">/* Get median stack of input darks */</span>
+<a name="l00544"></a>00544   <span class="keywordflow">if</span> (strcmp(STACK_METHOD, <span class="stringliteral">"MEDIAN"</span>) == 0) {
+<a name="l00545"></a>00545     cpl_msg_info(cpl_func, <span class="stringliteral">"Calculating stack median"</span>);
+<a name="l00546"></a>00546     master_dark = cpl_imagelist_collapse_median_create(preproc_images);
+<a name="l00547"></a>00547   } <span class="keywordflow">else</span> {
+<a name="l00548"></a>00548     cpl_msg_info(cpl_func, <span class="stringliteral">"Calculating stack mean"</span>);
+<a name="l00549"></a>00549     master_dark = irplib_imagelist_ksigma_stack(preproc_images, STACK_KLOW,
+<a name="l00550"></a>00550         STACK_KHIGH, STACK_NITER);
+<a name="l00551"></a>00551 
+<a name="l00552"></a>00552   }
+<a name="l00553"></a>00553   irplib_head_set_exptime(mdark_header, mean_exptime );
+<a name="l00554"></a>00554 
+<a name="l00555"></a>00555   cpl_image_delete(current_dark);
+<a name="l00556"></a>00556   cpl_imagelist_delete(preproc_images);
+<a name="l00557"></a>00557   <span class="keywordflow">if</span> (cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l00558"></a>00558     cpl_image_delete(master_dark);
+<a name="l00559"></a>00559   }
+<a name="l00560"></a>00560 
+<a name="l00561"></a>00561   <span class="keywordflow">return</span> master_dark;
+<a name="l00562"></a>00562 }
+<a name="l00563"></a>00563 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/irplib__mkmaster_8h_source.html b/html/irplib__mkmaster_8h_source.html
new file mode 100644
index 0000000..841c8b4
--- /dev/null
+++ b/html/irplib__mkmaster_8h_source.html
@@ -0,0 +1,69 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: irplib_mkmaster.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>irplib_mkmaster.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: irplib_mkmaster.h,v 1.3 2011/11/02 13:17:25 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the irplib package</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2011/11/02 13:17:25 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.3 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifndef IRPLIB_MKMASTER_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#define IRPLIB_MKMASTER_H</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span>
+<a name="l00031"></a>00031 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00032"></a>00032 <span class="comment">                                   Includes</span>
+<a name="l00033"></a>00033 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00034"></a>00034 
+<a name="l00035"></a>00035 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00036"></a>00036 <span class="preprocessor">#include <irplib_ksigma_clip.h></span>
+<a name="l00037"></a>00037 
+<a name="l00038"></a>00038 cpl_image*
+<a name="l00039"></a>00039 <a class="code" href="group__irplib__calib.html#gae11ebd9b30a6c781265ba2e5af87722b" title="Computes master frame by clean stack mean of the input imagelist.">irplib_mkmaster_mean</a>(cpl_imagelist* images,<span class="keyword">const</span> <span class="keywordtype">double</span> kappa, <span class="keyword">const</span> <span class="keywordtype">int</span> nclip, <span class="keyword">const</span> <span class="keywordtype">double</span> tolerance,<span class="k [...]
+<a name="l00040"></a>00040 
+<a name="l00041"></a>00041 cpl_image* 
+<a name="l00042"></a>00042 <a class="code" href="group__irplib__calib.html#ga31157521720077a762a43644a503bbf2" title="Computes master frame by clean stack median of the input imagelist.">irplib_mkmaster_median</a>(cpl_imagelist* images,<span class="keyword">const</span> <span class="keywordtype">double</span> kappa, <span class="keyword">const</span> <span class="keywordtype">int</span> nclip, <span class="keyword">const</span> <span class="keywordtype">double</span> tolerance);
+<a name="l00043"></a>00043 
+<a name="l00044"></a>00044 cpl_image *
+<a name="l00045"></a>00045 irplib_mdark_process_chip(<span class="keyword">const</span> cpl_imagelist *raw_images,
+<a name="l00046"></a>00046     cpl_propertylist **raw_headers, <span class="keyword">const</span> cpl_image *master_bias,
+<a name="l00047"></a>00047     cpl_propertylist *mdark_header, <span class="keyword">const</span> cpl_parameterlist *parameters,
+<a name="l00048"></a>00048     <span class="keyword">const</span> <span class="keywordtype">char</span>* recipe_id, cpl_table* qclog, <span class="keyword">const</span> <span class="keywordtype">int</span> do_qc,
+<a name="l00049"></a>00049     <span class="keyword">const</span> <span class="keywordtype">char</span>* STACK_METHOD, <span class="keyword">const</span> <span class="keywordtype">double</span> STACK_KLOW, <span class="keyword">const</span> <span class="keywordtype">double</span> STACK_KHIGH,
+<a name="l00050"></a>00050     <span class="keyword">const</span> <span class="keywordtype">int</span> STACK_NITER,
+<a name="l00051"></a>00051     <span class="keyword">const</span> <span class="keywordtype">int</span> pr_num_x, <span class="keyword">const</span> <span class="keywordtype">int</span> pr_num_y,
+<a name="l00052"></a>00052     <span class="keyword">const</span> <span class="keywordtype">int</span> pr_box_sx, <span class="keyword">const</span> <span class="keywordtype">int</span> pr_box_sy);
+<a name="l00053"></a>00053 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/irplib__oddeven_8c_source.html b/html/irplib__oddeven_8c_source.html
new file mode 100644
index 0000000..148993b
--- /dev/null
+++ b/html/irplib__oddeven_8c_source.html
@@ -0,0 +1,313 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: irplib_oddeven.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>irplib_oddeven.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: irplib_oddeven.c,v 1.9 2012/01/12 11:50:41 llundin Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the irplib package</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: llundin $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2012/01/12 11:50:41 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.9 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span>
+<a name="l00032"></a>00032 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                                   Includes</span>
+<a name="l00034"></a>00034 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 
+<a name="l00036"></a>00036 <span class="preprocessor">#include <math.h></span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00038"></a>00038 
+<a name="l00039"></a>00039 <span class="preprocessor">#include "irplib_oddeven.h"</span>
+<a name="l00040"></a>00040 
+<a name="l00041"></a>00041 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00042"></a>00042 <span class="comment">                            Functions prototypes</span>
+<a name="l00043"></a>00043 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00044"></a>00044 
+<a name="l00045"></a>00045 <span class="keyword">static</span> cpl_imagelist * irplib_oddeven_cube_conv_xy_rtheta(cpl_imagelist *) ;
+<a name="l00046"></a>00046 <span class="keyword">static</span> cpl_imagelist * irplib_oddeven_cube_conv_rtheta_xy(cpl_imagelist *) ;
+<a name="l00047"></a>00047  
+<a name="l00048"></a>00048 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00052"></a>00052 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00053"></a>00053 
+<a name="l00056"></a>00056 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00064"></a>00064 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00065"></a><a class="code" href="group__irplib__oddeven.html#gade0423dfae726cc1ffec66a24e376505">00065</a> <span class="keywordtype">int</span> <a class="code" href="group__irplib__oddeven.html#gade0423dfae726cc1ffec66a24e376505" title="Estimate the odd/even rate in an image quadrant.">irplib_oddeven_monitor</a>(
+<a name="l00066"></a>00066         <span class="keyword">const</span> cpl_image     *   in,
+<a name="l00067"></a>00067         <span class="keywordtype">int</span>                     iquad,
+<a name="l00068"></a>00068         <span class="keywordtype">double</span>              *   r_even) 
+<a name="l00069"></a>00069 {
+<a name="l00070"></a>00070     cpl_image       *   extracted ;        
+<a name="l00071"></a>00071     cpl_image       *   labels ;        
+<a name="l00072"></a>00072     <span class="keywordtype">int</span>             *   plabels ;
+<a name="l00073"></a>00073     <span class="keywordtype">int</span>                 llx, lly, urx, ury ;
+<a name="l00074"></a>00074     <span class="keywordtype">int</span>                 nx, ny ;
+<a name="l00075"></a>00075     <span class="keywordtype">double</span>              f_even, f_tot ;
+<a name="l00076"></a>00076     cpl_apertures   *   aperts ;
+<a name="l00077"></a>00077     <span class="keywordtype">int</span>                 i, j ;
+<a name="l00078"></a>00078 
+<a name="l00079"></a>00079     <span class="comment">/* Test entries */</span>
+<a name="l00080"></a>00080     <span class="keywordflow">if</span> (in == NULL || r_even == NULL) <span class="keywordflow">return</span> -1 ;
+<a name="l00081"></a>00081     nx = cpl_image_get_size_x(in) ;
+<a name="l00082"></a>00082     ny = cpl_image_get_size_y(in) ;
+<a name="l00083"></a>00083     
+<a name="l00084"></a>00084     <span class="keywordflow">switch</span> (iquad){
+<a name="l00085"></a>00085         <span class="keywordflow">case</span> 1:
+<a name="l00086"></a>00086             llx = 1 ; lly = 1 ; urx = nx/2 ; ury = ny/2 ; break ;
+<a name="l00087"></a>00087         <span class="keywordflow">case</span> 2:
+<a name="l00088"></a>00088             llx = (nx/2)+1 ; lly = 1 ; urx = nx ; ury = ny/2 ; break ;
+<a name="l00089"></a>00089         <span class="keywordflow">case</span> 3:
+<a name="l00090"></a>00090             llx = 1 ; lly = (ny/2)+1 ; urx = nx/2 ; ury = ny ; break ;
+<a name="l00091"></a>00091         <span class="keywordflow">case</span> 4:
+<a name="l00092"></a>00092             llx = (nx/2)+1 ; lly = (ny/2)+1 ; urx = nx ; ury = ny ; break ;
+<a name="l00093"></a>00093         <span class="keywordflow">case</span> 0:
+<a name="l00094"></a>00094             llx = 1 ; lly = 1 ; urx = nx ; ury = ny ; break ;
+<a name="l00095"></a>00095         <span class="keywordflow">default</span>:
+<a name="l00096"></a>00096             cpl_msg_error(cpl_func, <span class="stringliteral">"Unsupported mode"</span>) ;
+<a name="l00097"></a>00097             *r_even = 0.0 ;
+<a name="l00098"></a>00098             <span class="keywordflow">return</span> -1 ;
+<a name="l00099"></a>00099     }
+<a name="l00100"></a>00100    
+<a name="l00101"></a>00101     <span class="comment">/* Extract quadrant */</span>
+<a name="l00102"></a>00102     <span class="keywordflow">if</span> ((extracted = cpl_image_extract(in, llx, lly, urx, ury)) == NULL) {
+<a name="l00103"></a>00103         cpl_msg_error(cpl_func, <span class="stringliteral">"Cannot extract quadrant"</span>) ;
+<a name="l00104"></a>00104         *r_even = 0.0 ;
+<a name="l00105"></a>00105         <span class="keywordflow">return</span> -1 ;
+<a name="l00106"></a>00106     }
+<a name="l00107"></a>00107     nx = cpl_image_get_size_x(extracted) ;
+<a name="l00108"></a>00108     ny = cpl_image_get_size_y(extracted) ;
+<a name="l00109"></a>00109             
+<a name="l00110"></a>00110     <span class="comment">/* Get f_tot */</span>
+<a name="l00111"></a>00111     f_tot = cpl_image_get_median(extracted) ;
+<a name="l00112"></a>00112     <span class="keywordflow">if</span> (fabs(f_tot) < 1e-6) {
+<a name="l00113"></a>00113         cpl_msg_warning(cpl_func, <span class="stringliteral">"Quadrant median is 0.0"</span>) ;
+<a name="l00114"></a>00114         cpl_image_delete(extracted) ;
+<a name="l00115"></a>00115         *r_even = 0.0 ;
+<a name="l00116"></a>00116         <span class="keywordflow">return</span> -1 ;
+<a name="l00117"></a>00117     }
+<a name="l00118"></a>00118 
+<a name="l00119"></a>00119     <span class="comment">/* Create the label image to define the even columns */</span>
+<a name="l00120"></a>00120     labels = cpl_image_new(nx, ny, CPL_TYPE_INT) ;
+<a name="l00121"></a>00121     plabels = cpl_image_get_data_int(labels) ;
+<a name="l00122"></a>00122     <span class="keywordflow">for</span> (i=0 ; i<nx ; i++) {
+<a name="l00123"></a>00123         <span class="keywordflow">if</span> (i % 2) <span class="keywordflow">for</span> (j=0 ; j<ny ; j++) plabels[i+j*nx] = 0 ;
+<a name="l00124"></a>00124         <span class="keywordflow">else</span> <span class="keywordflow">for</span> (j=0 ; j<ny ; j++) plabels[i+j*nx] = 1 ;
+<a name="l00125"></a>00125     }
+<a name="l00126"></a>00126     
+<a name="l00127"></a>00127     <span class="comment">/* Get the median of even columns */</span>
+<a name="l00128"></a>00128     <span class="keywordflow">if</span> ((aperts = cpl_apertures_new_from_image(extracted, labels)) == NULL) {
+<a name="l00129"></a>00129         cpl_msg_error(cpl_func, <span class="stringliteral">"Cannot compute the even columns median"</span>) ;
+<a name="l00130"></a>00130         cpl_image_delete(extracted) ;
+<a name="l00131"></a>00131         cpl_image_delete(labels) ;
+<a name="l00132"></a>00132         *r_even = 0.0 ;
+<a name="l00133"></a>00133         <span class="keywordflow">return</span> -1 ;
+<a name="l00134"></a>00134     }
+<a name="l00135"></a>00135     cpl_image_delete(extracted) ;
+<a name="l00136"></a>00136     cpl_image_delete(labels) ;
+<a name="l00137"></a>00137     f_even = cpl_apertures_get_median(aperts, 1) ;
+<a name="l00138"></a>00138     cpl_apertures_delete(aperts) ;
+<a name="l00139"></a>00139     
+<a name="l00140"></a>00140     <span class="comment">/* Compute the even rate and return */</span>
+<a name="l00141"></a>00141     *r_even = f_even / f_tot ;
+<a name="l00142"></a>00142     <span class="keywordflow">return</span> 0 ;
+<a name="l00143"></a>00143 }
+<a name="l00144"></a>00144 
+<a name="l00145"></a>00145 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00151"></a>00151 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00152"></a><a class="code" href="group__irplib__oddeven.html#ga7f7dafc1436a0aa2617048e1ada84e95">00152</a> cpl_image * <a class="code" href="group__irplib__oddeven.html#ga7f7dafc1436a0aa2617048e1ada84e95" title="Correct the odd/even in an image.">irplib_oddeven_correct</a>(<span class="keyword">const</span> cpl_image * in)
+<a name="l00153"></a>00153 {
+<a name="l00154"></a>00154     cpl_image       *   in_real ;
+<a name="l00155"></a>00155     cpl_image       *   in_imag ;
+<a name="l00156"></a>00156     cpl_imagelist   *   freq_i ;
+<a name="l00157"></a>00157     cpl_imagelist   *   freq_i_amp ;
+<a name="l00158"></a>00158     cpl_image       *   cur_im ;
+<a name="l00159"></a>00159     <span class="keywordtype">double</span>          *   pcur_im ;
+<a name="l00160"></a>00160     cpl_image       *   cleaned ;
+<a name="l00161"></a>00161     <span class="keywordtype">int</span>                 nx ;
+<a name="l00162"></a>00162     cpl_vector      *   hf_med ;
+<a name="l00163"></a>00163 
+<a name="l00164"></a>00164     <span class="comment">/* Test entries */</span>
+<a name="l00165"></a>00165     <span class="keywordflow">if</span> (in==NULL) <span class="keywordflow">return</span> NULL ;
+<a name="l00166"></a>00166 
+<a name="l00167"></a>00167     nx = cpl_image_get_size_x(in) ;
+<a name="l00168"></a>00168 
+<a name="l00169"></a>00169     <span class="comment">/* Local copy of the input image in DOUBLE */</span>
+<a name="l00170"></a>00170     in_real = cpl_image_cast(in, CPL_TYPE_DOUBLE) ;
+<a name="l00171"></a>00171     in_imag = cpl_image_duplicate(in_real) ;
+<a name="l00172"></a>00172     cpl_image_multiply_scalar(in_imag, 0.0) ;
+<a name="l00173"></a>00173     
+<a name="l00174"></a>00174     <span class="comment">/* Apply FFT to input image */</span>
+<a name="l00175"></a>00175     cpl_image_fft(in_real, in_imag, CPL_FFT_DEFAULT) ;
+<a name="l00176"></a>00176 
+<a name="l00177"></a>00177     <span class="comment">/* Put the result in an image list */</span>
+<a name="l00178"></a>00178     freq_i = cpl_imagelist_new() ;
+<a name="l00179"></a>00179     cpl_imagelist_set(freq_i, in_real, 0) ;
+<a name="l00180"></a>00180     cpl_imagelist_set(freq_i, in_imag, 1) ;
+<a name="l00181"></a>00181     
+<a name="l00182"></a>00182     <span class="comment">/* Convert to amplitude/phase */</span>
+<a name="l00183"></a>00183     freq_i_amp = irplib_oddeven_cube_conv_xy_rtheta(freq_i);
+<a name="l00184"></a>00184     cpl_imagelist_delete(freq_i) ;
+<a name="l00185"></a>00185 
+<a name="l00186"></a>00186     <span class="comment">/* Correct the odd-even frequency */</span>
+<a name="l00187"></a>00187     cur_im = cpl_imagelist_get(freq_i_amp, 0) ;
+<a name="l00188"></a>00188     pcur_im = cpl_image_get_data_double(cur_im) ;
+<a name="l00189"></a>00189     <span class="comment">/* Odd-even frequency will be replaced by </span>
+<a name="l00190"></a>00190 <span class="comment">       the median of the 5 values around */</span>
+<a name="l00191"></a>00191     hf_med = cpl_vector_new(5); 
+<a name="l00192"></a>00192 
+<a name="l00193"></a>00193     cpl_vector_set(hf_med, 0, pcur_im[nx/2 + 1]); 
+<a name="l00194"></a>00194     cpl_vector_set(hf_med, 1, pcur_im[nx/2 + 2]);
+<a name="l00195"></a>00195     cpl_vector_set(hf_med, 2, pcur_im[nx/2 + 3]);
+<a name="l00196"></a>00196     cpl_vector_set(hf_med, 3, pcur_im[nx/2    ]);
+<a name="l00197"></a>00197     cpl_vector_set(hf_med, 4, pcur_im[nx/2  -1]);
+<a name="l00198"></a>00198 
+<a name="l00199"></a>00199     pcur_im[nx / 2 + 1] = cpl_vector_get_median(hf_med);
+<a name="l00200"></a>00200     cpl_vector_delete(hf_med);
+<a name="l00201"></a>00201 
+<a name="l00202"></a>00202     <span class="comment">/* Convert to X/Y */</span>
+<a name="l00203"></a>00203     freq_i = irplib_oddeven_cube_conv_rtheta_xy(freq_i_amp) ;
+<a name="l00204"></a>00204     cpl_imagelist_delete(freq_i_amp) ;
+<a name="l00205"></a>00205     <span class="comment">/* FFT back to image space */</span>
+<a name="l00206"></a>00206     cpl_image_fft(cpl_imagelist_get(freq_i, 0), cpl_imagelist_get(freq_i, 1), 
+<a name="l00207"></a>00207             CPL_FFT_INVERSE) ;
+<a name="l00208"></a>00208     cleaned = cpl_image_cast(cpl_imagelist_get(freq_i, 0), CPL_TYPE_FLOAT) ;
+<a name="l00209"></a>00209     cpl_imagelist_delete(freq_i) ;
+<a name="l00210"></a>00210     <span class="keywordflow">return</span> cleaned ;
+<a name="l00211"></a>00211 }
+<a name="l00212"></a>00212 
+<a name="l00215"></a>00215 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00226"></a>00226 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00227"></a>00227 <span class="keyword">static</span> cpl_imagelist * irplib_oddeven_cube_conv_xy_rtheta(
+<a name="l00228"></a>00228         cpl_imagelist   *   cube_in)
+<a name="l00229"></a>00229 {
+<a name="l00230"></a>00230     cpl_imagelist       *   cube_out ;
+<a name="l00231"></a>00231     <span class="keywordtype">double</span>                  re, im ;
+<a name="l00232"></a>00232     <span class="keywordtype">double</span>                  mod, phase ;
+<a name="l00233"></a>00233     <span class="keywordtype">int</span>                     nx, ny, np ;
+<a name="l00234"></a>00234     cpl_image           *   tmp_im ;
+<a name="l00235"></a>00235     <span class="keywordtype">double</span>              *   pim1 ;
+<a name="l00236"></a>00236     <span class="keywordtype">double</span>              *   pim2 ;
+<a name="l00237"></a>00237     <span class="keywordtype">double</span>              *   pim3 ;
+<a name="l00238"></a>00238     <span class="keywordtype">double</span>              *   pim4 ;
+<a name="l00239"></a>00239     <span class="keywordtype">int</span>                     i, j ;
+<a name="l00240"></a>00240 
+<a name="l00241"></a>00241     <span class="comment">/* Error handling : test entries    */</span>
+<a name="l00242"></a>00242     <span class="keywordflow">if</span> (cube_in == NULL) <span class="keywordflow">return</span> NULL ;
+<a name="l00243"></a>00243     np = cpl_imagelist_get_size(cube_in) ;
+<a name="l00244"></a>00244     <span class="keywordflow">if</span> (np != 2) <span class="keywordflow">return</span> NULL ;
+<a name="l00245"></a>00245 
+<a name="l00246"></a>00246     <span class="comment">/* Initialise */</span>
+<a name="l00247"></a>00247     tmp_im = cpl_imagelist_get(cube_in, 0) ;
+<a name="l00248"></a>00248     pim1 = cpl_image_get_data_double(tmp_im) ;
+<a name="l00249"></a>00249     nx = cpl_image_get_size_x(tmp_im) ;
+<a name="l00250"></a>00250     ny = cpl_image_get_size_y(tmp_im) ;
+<a name="l00251"></a>00251     tmp_im = cpl_imagelist_get(cube_in, 1) ;
+<a name="l00252"></a>00252     pim2 = cpl_image_get_data_double(tmp_im) ;
+<a name="l00253"></a>00253 
+<a name="l00254"></a>00254     <span class="comment">/* Allocate cube_out */</span>
+<a name="l00255"></a>00255     cube_out = cpl_imagelist_duplicate(cube_in) ;
+<a name="l00256"></a>00256 
+<a name="l00257"></a>00257     tmp_im = cpl_imagelist_get(cube_out, 0) ;
+<a name="l00258"></a>00258     pim3 = cpl_image_get_data_double(tmp_im) ;
+<a name="l00259"></a>00259     tmp_im = cpl_imagelist_get(cube_out, 1) ;
+<a name="l00260"></a>00260     pim4 = cpl_image_get_data_double(tmp_im) ;
+<a name="l00261"></a>00261     <span class="comment">/* Convert */</span>
+<a name="l00262"></a>00262     <span class="keywordflow">for</span> (j=0 ; j<ny ; j++) {
+<a name="l00263"></a>00263         <span class="keywordflow">for</span> (i=0 ; i<nx ; i++) {
+<a name="l00264"></a>00264             re = (double)pim1[i+j*nx] ;
+<a name="l00265"></a>00265             im = (double)pim2[i+j*nx] ;
+<a name="l00266"></a>00266             mod = (double)(sqrt(re*re + im*im)) ;
+<a name="l00267"></a>00267             <span class="keywordflow">if</span> (re != 0.0)
+<a name="l00268"></a>00268                 phase = (double)atan2(im, re) ;
+<a name="l00269"></a>00269             <span class="keywordflow">else</span> 
+<a name="l00270"></a>00270                 phase = 0.0 ;
+<a name="l00271"></a>00271             pim3[i+j*nx] = mod ; 
+<a name="l00272"></a>00272             pim4[i+j*nx] = phase ; 
+<a name="l00273"></a>00273         }
+<a name="l00274"></a>00274     }
+<a name="l00275"></a>00275     <span class="keywordflow">return</span> cube_out ;
+<a name="l00276"></a>00276 }
+<a name="l00277"></a>00277 
+<a name="l00278"></a>00278 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00291"></a>00291 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00292"></a>00292 <span class="keyword">static</span> cpl_imagelist * irplib_oddeven_cube_conv_rtheta_xy(
+<a name="l00293"></a>00293         cpl_imagelist   *   cube_in)
+<a name="l00294"></a>00294 {
+<a name="l00295"></a>00295     cpl_imagelist       *   cube_out ;
+<a name="l00296"></a>00296     <span class="keywordtype">double</span>                  re, im ;
+<a name="l00297"></a>00297     <span class="keywordtype">double</span>                  mod, phase ;
+<a name="l00298"></a>00298     <span class="keywordtype">int</span>                     nx, ny, np ;
+<a name="l00299"></a>00299     cpl_image           *   tmp_im ;
+<a name="l00300"></a>00300     <span class="keywordtype">double</span>              *   pim1 ;
+<a name="l00301"></a>00301     <span class="keywordtype">double</span>              *   pim2 ;
+<a name="l00302"></a>00302     <span class="keywordtype">double</span>              *   pim3 ;
+<a name="l00303"></a>00303     <span class="keywordtype">double</span>              *   pim4 ;
+<a name="l00304"></a>00304     <span class="keywordtype">int</span>                     i, j ;
+<a name="l00305"></a>00305 
+<a name="l00306"></a>00306     <span class="comment">/* Error handling : test entries    */</span>
+<a name="l00307"></a>00307     <span class="keywordflow">if</span> (cube_in == NULL) <span class="keywordflow">return</span> NULL ;
+<a name="l00308"></a>00308     np = cpl_imagelist_get_size(cube_in) ;
+<a name="l00309"></a>00309     <span class="keywordflow">if</span> (np != 2) <span class="keywordflow">return</span> NULL ;
+<a name="l00310"></a>00310 
+<a name="l00311"></a>00311     <span class="comment">/* Initialise */</span>
+<a name="l00312"></a>00312     tmp_im = cpl_imagelist_get(cube_in, 0) ;
+<a name="l00313"></a>00313     pim1 = cpl_image_get_data_double(tmp_im) ;
+<a name="l00314"></a>00314     nx = cpl_image_get_size_x(tmp_im) ;
+<a name="l00315"></a>00315     ny = cpl_image_get_size_y(tmp_im) ;
+<a name="l00316"></a>00316     tmp_im = cpl_imagelist_get(cube_in, 1) ;
+<a name="l00317"></a>00317     pim2 = cpl_image_get_data_double(tmp_im) ;
+<a name="l00318"></a>00318 
+<a name="l00319"></a>00319     <span class="comment">/* Allocate cube_out */</span>
+<a name="l00320"></a>00320     cube_out = cpl_imagelist_duplicate(cube_in) ;
+<a name="l00321"></a>00321 
+<a name="l00322"></a>00322     tmp_im = cpl_imagelist_get(cube_out, 0) ;
+<a name="l00323"></a>00323     pim3 = cpl_image_get_data_double(tmp_im) ;
+<a name="l00324"></a>00324     tmp_im = cpl_imagelist_get(cube_out, 1) ;
+<a name="l00325"></a>00325     pim4 = cpl_image_get_data_double(tmp_im) ;
+<a name="l00326"></a>00326     <span class="comment">/* Convert */</span>
+<a name="l00327"></a>00327     <span class="keywordflow">for</span> (j=0 ; j<ny ; j++) {
+<a name="l00328"></a>00328         <span class="keywordflow">for</span> (i=0 ; i<nx ; i++) {
+<a name="l00329"></a>00329             mod = (double)pim1[i+j*nx] ;
+<a name="l00330"></a>00330             phase = (double)pim2[i+j*nx] ;
+<a name="l00331"></a>00331             re = (double)(mod * cos(phase));
+<a name="l00332"></a>00332             im = (double)(mod * sin(phase));
+<a name="l00333"></a>00333             pim3[i+j*nx] = re ; 
+<a name="l00334"></a>00334             pim4[i+j*nx] = im ; 
+<a name="l00335"></a>00335         }
+<a name="l00336"></a>00336     }
+<a name="l00337"></a>00337     <span class="keywordflow">return</span> cube_out ;
+<a name="l00338"></a>00338 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/irplib__oddeven_8h_source.html b/html/irplib__oddeven_8h_source.html
new file mode 100644
index 0000000..d8a0516
--- /dev/null
+++ b/html/irplib__oddeven_8h_source.html
@@ -0,0 +1,56 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: irplib_oddeven.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>irplib_oddeven.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: irplib_oddeven.h,v 1.4 2006/10/06 20:46:04 yjung Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the irplib package</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: yjung $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2006/10/06 20:46:04 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.4 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifndef IRPLIB_ODDEVEN_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#define IRPLIB_ODDEVEN_H</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span>
+<a name="l00031"></a>00031 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00032"></a>00032 <span class="comment">                                   Includes</span>
+<a name="l00033"></a>00033 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00034"></a>00034 
+<a name="l00035"></a>00035 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="keywordtype">int</span> <a class="code" href="group__irplib__oddeven.html#gade0423dfae726cc1ffec66a24e376505" title="Estimate the odd/even rate in an image quadrant.">irplib_oddeven_monitor</a>(<span class="keyword">const</span> cpl_image *, <span class="keywordtype">int</span>, <span class="keywordtype">double</span> *) ;
+<a name="l00038"></a>00038 cpl_image * <a class="code" href="group__irplib__oddeven.html#ga7f7dafc1436a0aa2617048e1ada84e95" title="Correct the odd/even in an image.">irplib_oddeven_correct</a>(<span class="keyword">const</span> cpl_image *) ;
+<a name="l00039"></a>00039 
+<a name="l00040"></a>00040 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/irplib__plugin_8c_source.html b/html/irplib__plugin_8c_source.html
new file mode 100644
index 0000000..72d917d
--- /dev/null
+++ b/html/irplib__plugin_8c_source.html
@@ -0,0 +1,1040 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: irplib_plugin.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>irplib_plugin.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: irplib_plugin.c,v 1.39 2012/02/03 14:19:06 llundin Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the irplib package </span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: llundin $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2012/02/03 14:19:06 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.39 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00029"></a>00029 <span class="comment">                                Includes</span>
+<a name="l00030"></a>00030 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00031"></a>00031 
+<a name="l00032"></a>00032 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00033"></a>00033 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>
+<a name="l00034"></a>00034 <span class="preprocessor">#endif</span>
+<a name="l00035"></a>00035 <span class="preprocessor"></span>
+<a name="l00036"></a>00036 <span class="preprocessor">#include <string.h></span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include <stdlib.h></span>
+<a name="l00038"></a>00038 <span class="preprocessor">#include <assert.h></span>
+<a name="l00039"></a>00039 
+<a name="l00040"></a>00040 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00041"></a>00041 
+<a name="l00042"></a>00042 
+<a name="l00043"></a>00043 <span class="preprocessor">#include "irplib_plugin.h"</span>
+<a name="l00044"></a>00044 
+<a name="l00045"></a>00045 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00055"></a>00055 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00056"></a>00056 
+<a name="l00057"></a>00057 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00058"></a>00058 <span class="comment">                                Defines</span>
+<a name="l00059"></a>00059 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00060"></a>00060 
+<a name="l00061"></a>00061 <span class="comment">/* Maximum line length in SOF-file */</span>
+<a name="l00062"></a>00062 <span class="preprocessor">#ifndef LINE_LEN_MAX</span>
+<a name="l00063"></a>00063 <span class="preprocessor"></span><span class="preprocessor">#define LINE_LEN_MAX 1024</span>
+<a name="l00064"></a>00064 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
+<a name="l00065"></a>00065 <span class="preprocessor"></span>
+<a name="l00066"></a>00066 <span class="comment">/* This device provides quite-random data */</span>
+<a name="l00067"></a>00067 <span class="preprocessor">#define DEV_RANDOM "/dev/urandom"</span>
+<a name="l00068"></a>00068 <span class="preprocessor"></span>
+<a name="l00069"></a>00069 <span class="comment">/* Copied from cpl_tools.h */</span>
+<a name="l00070"></a>00070 <span class="preprocessor">#define recipe_assert(bool) \</span>
+<a name="l00071"></a>00071 <span class="preprocessor">  ((bool) ? (cpl_msg_debug(cpl_func, \</span>
+<a name="l00072"></a>00072 <span class="preprocessor">     "OK in " __FILE__ " line %d (CPL-error state: '%s' in %s): %s",__LINE__, \</span>
+<a name="l00073"></a>00073 <span class="preprocessor">       cpl_error_get_message(), cpl_error_get_where(), #bool), 0) \</span>
+<a name="l00074"></a>00074 <span class="preprocessor">          : (cpl_msg_error(cpl_func, \</span>
+<a name="l00075"></a>00075 <span class="preprocessor">     "Failure in " __FILE__ " line %d (CPL-error state: '%s' in %s): %s", \</span>
+<a name="l00076"></a>00076 <span class="preprocessor">      __LINE__, cpl_error_get_message(), cpl_error_get_where(), #bool), 1))</span>
+<a name="l00077"></a>00077 <span class="preprocessor"></span>
+<a name="l00078"></a>00078 
+<a name="l00079"></a>00079 
+<a name="l00080"></a>00080 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00081"></a>00081 <span class="comment">                            Private Function prototypes</span>
+<a name="l00082"></a>00082 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00083"></a>00083 
+<a name="l00084"></a>00084 <span class="keyword">static</span> <span class="keyword">const</span> cpl_parameter * irplib_parameterlist_get(<span class="keyword">const</span> cpl_parameterlist *,
+<a name="l00085"></a>00085                                                       <span class="keyword">const</span> <span class="keywordtype">char</span> *,
+<a name="l00086"></a>00086                                                       <span class="keyword">const</span> <span class="keywordtype">char</span> *,
+<a name="l00087"></a>00087                                                       <span class="keyword">const</span> <span class="keywordtype">char</span> *);
+<a name="l00088"></a>00088 
+<a name="l00089"></a>00089 <span class="keyword">static</span> <span class="keywordtype">void</span> recipe_parameterlist_set(cpl_parameterlist *);
+<a name="l00090"></a>00090 <span class="keyword">static</span> cpl_boolean irplib_plugin_has_sof_from_env(<span class="keyword">const</span> cpl_plugin *,
+<a name="l00091"></a>00091                                                   <span class="keyword">const</span> <span class="keywordtype">char</span> *);
+<a name="l00092"></a>00092 
+<a name="l00093"></a>00093 <span class="keyword">static</span> <span class="keywordtype">void</span> recipe_frameset_load(cpl_frameset *, <span class="keyword">const</span> <span class="keywordtype">char</span> *);
+<a name="l00094"></a>00094 
+<a name="l00095"></a>00095 <span class="keyword">static</span> <span class="keywordtype">void</span> recipe_sof_test_devfile(cpl_plugin *, <span class="keyword">const</span> <span class="keywordtype">char</span> *, <span class="keywordtype">size_t</span>,
+<a name="l00096"></a>00096                                    <span class="keyword">const</span> <span class="keywordtype">char</span> *[]);
+<a name="l00097"></a>00097 <span class="keyword">static</span> <span class="keywordtype">void</span> recipe_sof_test_image_empty(cpl_plugin *, <span class="keywordtype">size_t</span>, <span class="keyword">const</span> <span class="keywordtype">char</span> *[]);
+<a name="l00098"></a>00098 <span class="keyword">static</span> <span class="keywordtype">void</span> recipe_sof_test_local(cpl_plugin *);
+<a name="l00099"></a>00099 <span class="keyword">static</span> <span class="keywordtype">void</span> recipe_sof_test_from_env(cpl_plugin *);
+<a name="l00100"></a>00100 <span class="keyword">static</span> <span class="keywordtype">void</span> recipe_frameset_empty(cpl_frameset *);
+<a name="l00101"></a>00101 <span class="keyword">static</span> <span class="keywordtype">void</span> recipe_frameset_test_frame(<span class="keyword">const</span> cpl_frame *);
+<a name="l00102"></a>00102 <span class="keyword">static</span> <span class="keywordtype">void</span> recipe_frameset_test_frameset_diff(<span class="keyword">const</span> cpl_frameset *,
+<a name="l00103"></a>00103                                                <span class="keyword">const</span> cpl_frameset *);
+<a name="l00104"></a>00104 
+<a name="l00105"></a>00105 <span class="keyword">static</span> cpl_errorstate inistate;
+<a name="l00106"></a>00106 
+<a name="l00109"></a>00109 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00110"></a>00110 <span class="comment">                            Function definitions</span>
+<a name="l00111"></a>00111 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00112"></a>00112 
+<a name="l00113"></a>00113 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00123"></a>00123 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00124"></a>00124 <span class="keyword">const</span> <span class="keywordtype">char</span> * irplib_parameterlist_get_string(<span class="keyword">const</span> cpl_parameterlist * <span class="keyword">self</span>,
+<a name="l00125"></a>00125                                              <span class="keyword">const</span> <span class="keywordtype">char</span> * instrume,
+<a name="l00126"></a>00126                                              <span class="keyword">const</span> <span class="keywordtype">char</span> * recipe,
+<a name="l00127"></a>00127                                              <span class="keyword">const</span> <span class="keywordtype">char</span> * parameter)
+<a name="l00128"></a>00128 {
+<a name="l00129"></a>00129 
+<a name="l00130"></a>00130     <span class="keyword">const</span> cpl_parameter * par = irplib_parameterlist_get(<span class="keyword">self</span>, instrume,
+<a name="l00131"></a>00131                                                          recipe, parameter);
+<a name="l00132"></a>00132     <span class="keyword">const</span> <span class="keywordtype">char</span> * value;
+<a name="l00133"></a>00133 
+<a name="l00134"></a>00134     cpl_ensure(par != NULL, cpl_error_get_code(), NULL);
+<a name="l00135"></a>00135 
+<a name="l00136"></a>00136     value = cpl_parameter_get_string(par);
+<a name="l00137"></a>00137 
+<a name="l00138"></a>00138     <span class="keywordflow">if</span> (value == NULL) (void)cpl_error_set_where(cpl_func);
+<a name="l00139"></a>00139 
+<a name="l00140"></a>00140     <span class="keywordflow">return</span> value;
+<a name="l00141"></a>00141 
+<a name="l00142"></a>00142 }
+<a name="l00143"></a>00143 
+<a name="l00144"></a>00144 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00154"></a>00154 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00155"></a>00155 cpl_boolean irplib_parameterlist_get_bool(<span class="keyword">const</span> cpl_parameterlist * <span class="keyword">self</span>,
+<a name="l00156"></a>00156                                           <span class="keyword">const</span> <span class="keywordtype">char</span> * instrume,
+<a name="l00157"></a>00157                                           <span class="keyword">const</span> <span class="keywordtype">char</span> * recipe,
+<a name="l00158"></a>00158                                           <span class="keyword">const</span> <span class="keywordtype">char</span> * parameter)
+<a name="l00159"></a>00159 {
+<a name="l00160"></a>00160 
+<a name="l00161"></a>00161     <span class="keyword">const</span> cpl_parameter * par = irplib_parameterlist_get(<span class="keyword">self</span>, instrume,
+<a name="l00162"></a>00162                                                          recipe, parameter);
+<a name="l00163"></a>00163     cpl_errorstate        prestate = cpl_errorstate_get();
+<a name="l00164"></a>00164     cpl_boolean           value;
+<a name="l00165"></a>00165 
+<a name="l00166"></a>00166 
+<a name="l00167"></a>00167     cpl_ensure(par != NULL, cpl_error_get_code(), CPL_FALSE);
+<a name="l00168"></a>00168 
+<a name="l00169"></a>00169     value = cpl_parameter_get_bool(par);
+<a name="l00170"></a>00170 
+<a name="l00171"></a>00171     <span class="keywordflow">if</span> (!cpl_errorstate_is_equal(prestate)) (void)cpl_error_set_where(cpl_func);
+<a name="l00172"></a>00172 
+<a name="l00173"></a>00173     <span class="keywordflow">return</span> value;
+<a name="l00174"></a>00174 
+<a name="l00175"></a>00175 }
+<a name="l00176"></a>00176 
+<a name="l00177"></a>00177 
+<a name="l00178"></a>00178 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00188"></a>00188 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00189"></a>00189 <span class="keywordtype">int</span> irplib_parameterlist_get_int(<span class="keyword">const</span> cpl_parameterlist * <span class="keyword">self</span>,
+<a name="l00190"></a>00190                                  <span class="keyword">const</span> <span class="keywordtype">char</span> * instrume,
+<a name="l00191"></a>00191                                  <span class="keyword">const</span> <span class="keywordtype">char</span> * recipe,
+<a name="l00192"></a>00192                                  <span class="keyword">const</span> <span class="keywordtype">char</span> * parameter)
+<a name="l00193"></a>00193 {
+<a name="l00194"></a>00194 
+<a name="l00195"></a>00195     <span class="keyword">const</span> cpl_parameter * par = irplib_parameterlist_get(<span class="keyword">self</span>, instrume,
+<a name="l00196"></a>00196                                                          recipe, parameter);
+<a name="l00197"></a>00197     cpl_errorstate        prestate = cpl_errorstate_get();
+<a name="l00198"></a>00198     <span class="keywordtype">int</span>                   value;
+<a name="l00199"></a>00199 
+<a name="l00200"></a>00200 
+<a name="l00201"></a>00201     cpl_ensure(par != NULL, cpl_error_get_code(), 0);
+<a name="l00202"></a>00202 
+<a name="l00203"></a>00203     value = cpl_parameter_get_int(par);
+<a name="l00204"></a>00204 
+<a name="l00205"></a>00205     <span class="keywordflow">if</span> (!cpl_errorstate_is_equal(prestate)) (void)cpl_error_set_where(cpl_func);
+<a name="l00206"></a>00206 
+<a name="l00207"></a>00207     <span class="keywordflow">return</span> value;
+<a name="l00208"></a>00208 }
+<a name="l00209"></a>00209 
+<a name="l00210"></a>00210 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00220"></a>00220 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00221"></a>00221 <span class="keywordtype">double</span> irplib_parameterlist_get_double(<span class="keyword">const</span> cpl_parameterlist * <span class="keyword">self</span>,
+<a name="l00222"></a>00222                                        <span class="keyword">const</span> <span class="keywordtype">char</span> * instrume,
+<a name="l00223"></a>00223                                        <span class="keyword">const</span> <span class="keywordtype">char</span> * recipe,
+<a name="l00224"></a>00224                                        <span class="keyword">const</span> <span class="keywordtype">char</span> * parameter)
+<a name="l00225"></a>00225 {
+<a name="l00226"></a>00226 
+<a name="l00227"></a>00227     <span class="keyword">const</span> cpl_parameter * par = irplib_parameterlist_get(<span class="keyword">self</span>, instrume,
+<a name="l00228"></a>00228                                                          recipe, parameter);
+<a name="l00229"></a>00229     cpl_errorstate        prestate = cpl_errorstate_get();
+<a name="l00230"></a>00230     <span class="keywordtype">double</span>                value;
+<a name="l00231"></a>00231 
+<a name="l00232"></a>00232 
+<a name="l00233"></a>00233     cpl_ensure(par != NULL, cpl_error_get_code(), 0.0);
+<a name="l00234"></a>00234 
+<a name="l00235"></a>00235     value = cpl_parameter_get_double(par);
+<a name="l00236"></a>00236 
+<a name="l00237"></a>00237     <span class="keywordflow">if</span> (!cpl_errorstate_is_equal(prestate)) (void)cpl_error_set_where(cpl_func);
+<a name="l00238"></a>00238 
+<a name="l00239"></a>00239     <span class="keywordflow">return</span> value;
+<a name="l00240"></a>00240 }
+<a name="l00241"></a>00241 
+<a name="l00242"></a>00242 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00256"></a>00256 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00257"></a>00257 cpl_error_code irplib_parameterlist_set_string(cpl_parameterlist * <span class="keyword">self</span>,
+<a name="l00258"></a>00258                                                <span class="keyword">const</span> <span class="keywordtype">char</span> * instrume,
+<a name="l00259"></a>00259                                                <span class="keyword">const</span> <span class="keywordtype">char</span> * recipe,
+<a name="l00260"></a>00260                                                <span class="keyword">const</span> <span class="keywordtype">char</span> * parameter,
+<a name="l00261"></a>00261                                                <span class="keyword">const</span> <span class="keywordtype">char</span> * defvalue,
+<a name="l00262"></a>00262                                                <span class="keyword">const</span> <span class="keywordtype">char</span> * alias,
+<a name="l00263"></a>00263                                                <span class="keyword">const</span> <span class="keywordtype">char</span> * context,
+<a name="l00264"></a>00264                                                <span class="keyword">const</span> <span class="keywordtype">char</span> * man)
+<a name="l00265"></a>00265 {
+<a name="l00266"></a>00266 
+<a name="l00267"></a>00267     cpl_error_code  error;
+<a name="l00268"></a>00268     cpl_parameter * par;
+<a name="l00269"></a>00269     <span class="keywordtype">char</span>          * paramname = cpl_sprintf(<span class="stringliteral">"%s.%s.%s"</span>, instrume, recipe,
+<a name="l00270"></a>00270                                             parameter);
+<a name="l00271"></a>00271 
+<a name="l00272"></a>00272     cpl_ensure_code(paramname != NULL, cpl_error_get_code());
+<a name="l00273"></a>00273     
+<a name="l00274"></a>00274     par = cpl_parameter_new_value(paramname, CPL_TYPE_STRING, man, context,
+<a name="l00275"></a>00275                                   defvalue);
+<a name="l00276"></a>00276     cpl_free(paramname);
+<a name="l00277"></a>00277 
+<a name="l00278"></a>00278     cpl_ensure_code(par != NULL, cpl_error_get_code());
+<a name="l00279"></a>00279     
+<a name="l00280"></a>00280     error = cpl_parameter_set_alias(par, CPL_PARAMETER_MODE_CLI,
+<a name="l00281"></a>00281                                     alias ? alias : parameter);
+<a name="l00282"></a>00282     cpl_ensure_code(!error, error);
+<a name="l00283"></a>00283 
+<a name="l00284"></a>00284     error = cpl_parameter_disable(par, CPL_PARAMETER_MODE_ENV);
+<a name="l00285"></a>00285     cpl_ensure_code(!error, error);
+<a name="l00286"></a>00286 
+<a name="l00287"></a>00287     error = cpl_parameterlist_append(<span class="keyword">self</span>, par);
+<a name="l00288"></a>00288     cpl_ensure_code(!error, error);
+<a name="l00289"></a>00289     
+<a name="l00290"></a>00290     <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l00291"></a>00291 }
+<a name="l00292"></a>00292 
+<a name="l00293"></a>00293 
+<a name="l00294"></a>00294 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00308"></a>00308 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00309"></a>00309 cpl_error_code irplib_parameterlist_set_bool(cpl_parameterlist * <span class="keyword">self</span>,
+<a name="l00310"></a>00310                                              <span class="keyword">const</span> <span class="keywordtype">char</span> * instrume,
+<a name="l00311"></a>00311                                              <span class="keyword">const</span> <span class="keywordtype">char</span> * recipe,
+<a name="l00312"></a>00312                                              <span class="keyword">const</span> <span class="keywordtype">char</span> * parameter,
+<a name="l00313"></a>00313                                              cpl_boolean  defvalue,
+<a name="l00314"></a>00314                                              <span class="keyword">const</span> <span class="keywordtype">char</span> * alias,
+<a name="l00315"></a>00315                                              <span class="keyword">const</span> <span class="keywordtype">char</span> * context,
+<a name="l00316"></a>00316                                              <span class="keyword">const</span> <span class="keywordtype">char</span> * man)
+<a name="l00317"></a>00317 {
+<a name="l00318"></a>00318 
+<a name="l00319"></a>00319     cpl_error_code  error;
+<a name="l00320"></a>00320     cpl_parameter * par;
+<a name="l00321"></a>00321     <span class="keywordtype">char</span>          * paramname = cpl_sprintf(<span class="stringliteral">"%s.%s.%s"</span>, instrume, recipe,
+<a name="l00322"></a>00322                                             parameter);
+<a name="l00323"></a>00323 
+<a name="l00324"></a>00324     cpl_ensure_code(paramname != NULL, cpl_error_get_code());
+<a name="l00325"></a>00325     
+<a name="l00326"></a>00326     par = cpl_parameter_new_value(paramname, CPL_TYPE_BOOL, man, context,
+<a name="l00327"></a>00327                                   defvalue);
+<a name="l00328"></a>00328     cpl_free(paramname);
+<a name="l00329"></a>00329 
+<a name="l00330"></a>00330     cpl_ensure_code(par != NULL, cpl_error_get_code());
+<a name="l00331"></a>00331     
+<a name="l00332"></a>00332     error = cpl_parameter_set_alias(par, CPL_PARAMETER_MODE_CLI,
+<a name="l00333"></a>00333                                     alias ? alias : parameter);
+<a name="l00334"></a>00334     cpl_ensure_code(!error, error);
+<a name="l00335"></a>00335     
+<a name="l00336"></a>00336     error = cpl_parameter_disable(par, CPL_PARAMETER_MODE_ENV);
+<a name="l00337"></a>00337     cpl_ensure_code(!error, error);
+<a name="l00338"></a>00338 
+<a name="l00339"></a>00339     error = cpl_parameterlist_append(<span class="keyword">self</span>, par);
+<a name="l00340"></a>00340     cpl_ensure_code(!error, error);
+<a name="l00341"></a>00341     
+<a name="l00342"></a>00342     <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l00343"></a>00343 }
+<a name="l00344"></a>00344 
+<a name="l00345"></a>00345 
+<a name="l00346"></a>00346 
+<a name="l00347"></a>00347 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00361"></a>00361 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00362"></a>00362 cpl_error_code irplib_parameterlist_set_int(cpl_parameterlist * <span class="keyword">self</span>,
+<a name="l00363"></a>00363                                             <span class="keyword">const</span> <span class="keywordtype">char</span> * instrume,
+<a name="l00364"></a>00364                                             <span class="keyword">const</span> <span class="keywordtype">char</span> * recipe,
+<a name="l00365"></a>00365                                             <span class="keyword">const</span> <span class="keywordtype">char</span> * parameter,
+<a name="l00366"></a>00366                                             <span class="keywordtype">int</span>         defvalue,
+<a name="l00367"></a>00367                                             <span class="keyword">const</span> <span class="keywordtype">char</span> * alias,
+<a name="l00368"></a>00368                                             <span class="keyword">const</span> <span class="keywordtype">char</span> * context,
+<a name="l00369"></a>00369                                             <span class="keyword">const</span> <span class="keywordtype">char</span> * man)
+<a name="l00370"></a>00370 {
+<a name="l00371"></a>00371 
+<a name="l00372"></a>00372     cpl_error_code  error;
+<a name="l00373"></a>00373     cpl_parameter * par;
+<a name="l00374"></a>00374     <span class="keywordtype">char</span>          * paramname = cpl_sprintf(<span class="stringliteral">"%s.%s.%s"</span>, instrume, recipe,
+<a name="l00375"></a>00375                                             parameter);
+<a name="l00376"></a>00376 
+<a name="l00377"></a>00377     cpl_ensure_code(paramname != NULL, cpl_error_get_code());
+<a name="l00378"></a>00378     
+<a name="l00379"></a>00379     par = cpl_parameter_new_value(paramname, CPL_TYPE_INT, man, context,
+<a name="l00380"></a>00380                                   defvalue);
+<a name="l00381"></a>00381     cpl_free(paramname);
+<a name="l00382"></a>00382 
+<a name="l00383"></a>00383     cpl_ensure_code(par != NULL, cpl_error_get_code());
+<a name="l00384"></a>00384     
+<a name="l00385"></a>00385     error = cpl_parameter_set_alias(par, CPL_PARAMETER_MODE_CLI,
+<a name="l00386"></a>00386                                     alias ? alias : parameter);
+<a name="l00387"></a>00387     cpl_ensure_code(!error, error);
+<a name="l00388"></a>00388     
+<a name="l00389"></a>00389     error = cpl_parameter_disable(par, CPL_PARAMETER_MODE_ENV);
+<a name="l00390"></a>00390     cpl_ensure_code(!error, error);
+<a name="l00391"></a>00391 
+<a name="l00392"></a>00392     error = cpl_parameterlist_append(<span class="keyword">self</span>, par);
+<a name="l00393"></a>00393     cpl_ensure_code(!error, error);
+<a name="l00394"></a>00394     
+<a name="l00395"></a>00395     <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l00396"></a>00396 }
+<a name="l00397"></a>00397 
+<a name="l00398"></a>00398 
+<a name="l00399"></a>00399 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00413"></a>00413 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00414"></a>00414 cpl_error_code irplib_parameterlist_set_double(cpl_parameterlist * <span class="keyword">self</span>,
+<a name="l00415"></a>00415                                                <span class="keyword">const</span> <span class="keywordtype">char</span> * instrume,
+<a name="l00416"></a>00416                                                <span class="keyword">const</span> <span class="keywordtype">char</span> * recipe,
+<a name="l00417"></a>00417                                                <span class="keyword">const</span> <span class="keywordtype">char</span> * parameter,
+<a name="l00418"></a>00418                                                <span class="keywordtype">double</span>       defvalue,
+<a name="l00419"></a>00419                                                <span class="keyword">const</span> <span class="keywordtype">char</span> * alias,
+<a name="l00420"></a>00420                                                <span class="keyword">const</span> <span class="keywordtype">char</span> * context,
+<a name="l00421"></a>00421                                                <span class="keyword">const</span> <span class="keywordtype">char</span> * man)
+<a name="l00422"></a>00422 {
+<a name="l00423"></a>00423 
+<a name="l00424"></a>00424     cpl_error_code  error;
+<a name="l00425"></a>00425     cpl_parameter * par;
+<a name="l00426"></a>00426     <span class="keywordtype">char</span>          * paramname = cpl_sprintf(<span class="stringliteral">"%s.%s.%s"</span>, instrume, recipe,
+<a name="l00427"></a>00427                                             parameter);
+<a name="l00428"></a>00428 
+<a name="l00429"></a>00429     cpl_ensure_code(paramname != NULL, cpl_error_get_code());
+<a name="l00430"></a>00430     
+<a name="l00431"></a>00431     par = cpl_parameter_new_value(paramname, CPL_TYPE_DOUBLE, man, context,
+<a name="l00432"></a>00432                                   defvalue);
+<a name="l00433"></a>00433     cpl_free(paramname);
+<a name="l00434"></a>00434 
+<a name="l00435"></a>00435     cpl_ensure_code(par != NULL, cpl_error_get_code());
+<a name="l00436"></a>00436     
+<a name="l00437"></a>00437     error = cpl_parameter_set_alias(par, CPL_PARAMETER_MODE_CLI,
+<a name="l00438"></a>00438                                     alias ? alias : parameter);
+<a name="l00439"></a>00439     cpl_ensure_code(!error, error);
+<a name="l00440"></a>00440     
+<a name="l00441"></a>00441     error = cpl_parameter_disable(par, CPL_PARAMETER_MODE_ENV);
+<a name="l00442"></a>00442     cpl_ensure_code(!error, error);
+<a name="l00443"></a>00443 
+<a name="l00444"></a>00444     error = cpl_parameterlist_append(<span class="keyword">self</span>, par);
+<a name="l00445"></a>00445     cpl_ensure_code(!error, error);
+<a name="l00446"></a>00446     
+<a name="l00447"></a>00447     <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l00448"></a>00448 }
+<a name="l00449"></a>00449 
+<a name="l00450"></a>00450 
+<a name="l00451"></a>00451 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00465"></a>00465 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00466"></a>00466 <span class="keywordtype">int</span> irplib_plugin_test(cpl_pluginlist * <span class="keyword">self</span>, <span class="keywordtype">size_t</span> nstr, <span class="keyword">const</span> <span class="keywordtype">char</span> *astr[]) {
+<a name="l00467"></a>00467 
+<a name="l00468"></a>00468     cpl_plugin     * plugin;
+<a name="l00469"></a>00469     cpl_recipe     * recipe;
+<a name="l00470"></a>00470     int            (*recipe_create) (cpl_plugin *);
+<a name="l00471"></a>00471     int            (*recipe_exec  ) (cpl_plugin *);
+<a name="l00472"></a>00472     int            (*recipe_deinit) (cpl_plugin *);
+<a name="l00473"></a>00473     cpl_error_code error;
+<a name="l00474"></a>00474     FILE         * stream;
+<a name="l00475"></a>00475     cpl_boolean    is_debug;
+<a name="l00476"></a>00476 
+<a name="l00477"></a>00477 
+<a name="l00478"></a>00478     is_debug = cpl_msg_get_level() <= CPL_MSG_DEBUG ? CPL_TRUE : CPL_FALSE;
+<a name="l00479"></a>00479 
+<a name="l00480"></a>00480     <span class="comment">/* Modified from CPL unit tests */</span>
+<a name="l00481"></a>00481     stream = is_debug ? stdout : fopen(<span class="stringliteral">"/dev/null"</span>, <span class="stringliteral">"a"</span>);
+<a name="l00482"></a>00482 
+<a name="l00483"></a>00483     inistate = cpl_errorstate_get();
+<a name="l00484"></a>00484 
+<a name="l00485"></a>00485     assert( nstr == 0 || astr != NULL );
+<a name="l00486"></a>00486 
+<a name="l00487"></a>00487     plugin = cpl_pluginlist_get_first(<span class="keyword">self</span>);
+<a name="l00488"></a>00488 
+<a name="l00489"></a>00489     <span class="keywordflow">if</span> (plugin == NULL) {
+<a name="l00490"></a>00490         cpl_msg_warning(cpl_func, <span class="stringliteral">"With an empty pluginlist, "</span>
+<a name="l00491"></a>00491                         <span class="stringliteral">"no tests can be made"</span>);
+<a name="l00492"></a>00492         <span class="keywordflow">return</span> 0;
+<a name="l00493"></a>00493     }
+<a name="l00494"></a>00494 
+<a name="l00495"></a>00495     cpl_plugin_dump(plugin, stream);
+<a name="l00496"></a>00496 
+<a name="l00497"></a>00497     recipe_create = cpl_plugin_get_init(plugin);
+<a name="l00498"></a>00498     cpl_test( recipe_create != NULL);
+<a name="l00499"></a>00499 
+<a name="l00500"></a>00500     recipe_exec   = cpl_plugin_get_exec(plugin);
+<a name="l00501"></a>00501     cpl_test( recipe_exec != NULL);
+<a name="l00502"></a>00502 
+<a name="l00503"></a>00503     recipe_deinit = cpl_plugin_get_deinit(plugin);
+<a name="l00504"></a>00504     cpl_test( recipe_deinit != NULL);
+<a name="l00505"></a>00505 
+<a name="l00506"></a>00506     <span class="comment">/* Only plugins of type recipe are tested (further)  */</span>
+<a name="l00507"></a>00507     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
+<a name="l00508"></a>00508         cpl_msg_warning(cpl_func, <span class="stringliteral">"This plugin is not of type recipe, "</span>
+<a name="l00509"></a>00509                       <span class="stringliteral">"cannot test further"</span>);
+<a name="l00510"></a>00510         <span class="keywordflow">return</span> 0;
+<a name="l00511"></a>00511     }
+<a name="l00512"></a>00512 
+<a name="l00513"></a>00513     <span class="keywordflow">if</span> (recipe_create != NULL && recipe_exec != NULL && recipe_deinit != NULL) {
+<a name="l00514"></a>00514 
+<a name="l00515"></a>00515         cpl_test_zero(recipe_create(plugin));
+<a name="l00516"></a>00516 
+<a name="l00517"></a>00517         recipe = (cpl_recipe *) plugin;
+<a name="l00518"></a>00518 
+<a name="l00519"></a>00519         cpl_test_nonnull( recipe->parameters );
+<a name="l00520"></a>00520 
+<a name="l00521"></a>00521         recipe_parameterlist_set(recipe->parameters);
+<a name="l00522"></a>00522 
+<a name="l00523"></a>00523         cpl_parameterlist_dump(recipe->parameters, stream);
+<a name="l00524"></a>00524 
+<a name="l00525"></a>00525         recipe->frames = cpl_frameset_new();
+<a name="l00526"></a>00526 
+<a name="l00527"></a>00527         <span class="keywordflow">if</span> (irplib_plugin_has_sof_from_env(plugin, <span class="stringliteral">"RECIPE_SOF_PATH"</span>)) {
+<a name="l00528"></a>00528 
+<a name="l00529"></a>00529             recipe_sof_test_from_env(plugin);
+<a name="l00530"></a>00530 
+<a name="l00531"></a>00531         } <span class="keywordflow">else</span> {
+<a name="l00532"></a>00532 
+<a name="l00533"></a>00533             <span class="keyword">const</span> cpl_msg_severity msg_level = cpl_msg_get_level();
+<a name="l00534"></a>00534 
+<a name="l00535"></a>00535             <span class="comment">/* Unless the CPL_MSG_LEVEL has been explicitly set, turn off</span>
+<a name="l00536"></a>00536 <span class="comment">               terminal messaging completely while inside this function */</span>
+<a name="l00537"></a>00537             <span class="keywordflow">if</span> (getenv(<span class="stringliteral">"CPL_MSG_LEVEL"</span>) == NULL) cpl_msg_set_level(CPL_MSG_OFF);
+<a name="l00538"></a>00538 
+<a name="l00539"></a>00539             cpl_msg_info(cpl_func,<span class="stringliteral">"Checking handling of pre-existing CPL error "</span>
+<a name="l00540"></a>00540                          <span class="stringliteral">"state - may produce warning(s)/error(s):"</span>);
+<a name="l00541"></a>00541             cpl_error_set(cpl_func, CPL_ERROR_EOL);
+<a name="l00542"></a>00542             <span class="comment">/* Call recipe and expect non-zero return code */</span>
+<a name="l00543"></a>00543             cpl_test( recipe_exec(plugin) );
+<a name="l00544"></a>00544             <span class="comment">/* Expect also the CPL error code to be preserved */</span>
+<a name="l00545"></a>00545             cpl_test_error( CPL_ERROR_EOL );
+<a name="l00546"></a>00546 
+<a name="l00547"></a>00547             cpl_msg_info(cpl_func,<span class="stringliteral">"Checking handling of empty frameset - "</span>
+<a name="l00548"></a>00548                          <span class="stringliteral">"may produce warning(s)/error(s):"</span>);
+<a name="l00549"></a>00549             <span class="comment">/* Call recipe and expect non-zero return code */</span>
+<a name="l00550"></a>00550             cpl_test( recipe_exec(plugin) );
+<a name="l00551"></a>00551             error = cpl_error_get_code();
+<a name="l00552"></a>00552             <span class="comment">/* Expect also the CPL error code to be set */</span>
+<a name="l00553"></a>00553             cpl_test_error( error );
+<a name="l00554"></a>00554             cpl_test( error );
+<a name="l00555"></a>00555 
+<a name="l00556"></a>00556             cpl_msg_info(cpl_func,<span class="stringliteral">"Checking handling of dummy frameset - "</span>
+<a name="l00557"></a>00557                          <span class="stringliteral">"may produce warning(s)/error(s):"</span>);
+<a name="l00558"></a>00558             <span class="keywordflow">do</span> {
+<a name="l00559"></a>00559                 cpl_frame * f = cpl_frame_new();
+<a name="l00560"></a>00560                 error = cpl_frame_set_filename(f, <span class="stringliteral">"/dev/null"</span>);
+<a name="l00561"></a>00561                 cpl_test_eq_error(error, CPL_ERROR_NONE);
+<a name="l00562"></a>00562                 error = cpl_frame_set_tag(f, <span class="stringliteral">"RECIPE_DUMMY_TAG"</span>);
+<a name="l00563"></a>00563                 cpl_test_eq_error(error, CPL_ERROR_NONE);
+<a name="l00564"></a>00564                 error = cpl_frameset_insert(recipe->frames, f);
+<a name="l00565"></a>00565                 cpl_test_eq_error(error, CPL_ERROR_NONE);
+<a name="l00566"></a>00566 
+<a name="l00567"></a>00567                 <span class="comment">/* Call recipe and expect non-zero return code */</span>
+<a name="l00568"></a>00568                 cpl_test( recipe_exec(plugin) );
+<a name="l00569"></a>00569                 error = cpl_error_get_code();
+<a name="l00570"></a>00570                 <span class="comment">/* Expect also the CPL error code to be set */</span>
+<a name="l00571"></a>00571                 cpl_test_error( error );
+<a name="l00572"></a>00572                 cpl_test( error );
+<a name="l00573"></a>00573 
+<a name="l00574"></a>00574                 error = cpl_frameset_erase_frame(recipe->frames, f);
+<a name="l00575"></a>00575                 cpl_test_eq_error(error, CPL_ERROR_NONE);
+<a name="l00576"></a>00576 
+<a name="l00577"></a>00577             } <span class="keywordflow">while</span> (0);
+<a name="l00578"></a>00578 
+<a name="l00579"></a>00579 <span class="preprocessor">#ifdef IRPLIB_TEST_RANDOM_SOF</span>
+<a name="l00580"></a>00580 <span class="preprocessor"></span>            recipe_sof_test_devfile(plugin, DEV_RANDOM, nstr, astr);
+<a name="l00581"></a>00581 <span class="preprocessor">#endif</span>
+<a name="l00582"></a>00582 <span class="preprocessor"></span>
+<a name="l00583"></a>00583             recipe_sof_test_devfile(plugin, <span class="stringliteral">"/dev/null"</span>, nstr, astr);
+<a name="l00584"></a>00584 
+<a name="l00585"></a>00585             recipe_sof_test_devfile(plugin, <span class="stringliteral">"."</span>, nstr, astr);
+<a name="l00586"></a>00586 
+<a name="l00587"></a>00587             recipe_sof_test_image_empty(plugin, nstr, astr);
+<a name="l00588"></a>00588 
+<a name="l00589"></a>00589             recipe_sof_test_local(plugin);
+<a name="l00590"></a>00590 
+<a name="l00591"></a>00591             cpl_msg_set_level(msg_level);
+<a name="l00592"></a>00592 
+<a name="l00593"></a>00593         }
+<a name="l00594"></a>00594 
+<a name="l00595"></a>00595         cpl_frameset_delete(recipe->frames);
+<a name="l00596"></a>00596 
+<a name="l00597"></a>00597         error = recipe_deinit(plugin);
+<a name="l00598"></a>00598         cpl_test_eq_error(error, CPL_ERROR_NONE);
+<a name="l00599"></a>00599     }
+<a name="l00600"></a>00600 
+<a name="l00601"></a>00601     <span class="keywordflow">if</span> (stream != stdout) fclose(stream);
+<a name="l00602"></a>00602 
+<a name="l00603"></a>00603     <span class="keywordflow">return</span> 0;
+<a name="l00604"></a>00604 }
+<a name="l00605"></a>00605 
+<a name="l00608"></a>00608 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00618"></a>00618 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00619"></a>00619 <span class="keyword">static</span> <span class="keywordtype">void</span> recipe_parameterlist_set(cpl_parameterlist * <span class="keyword">self</span>)
+<a name="l00620"></a>00620 {
+<a name="l00621"></a>00621 
+<a name="l00622"></a>00622     cpl_parameter * p = cpl_parameterlist_get_first(<span class="keyword">self</span>);
+<a name="l00623"></a>00623 
+<a name="l00624"></a>00624     <span class="keywordflow">for</span> (; p != NULL; p = cpl_parameterlist_get_next(<span class="keyword">self</span>)) {
+<a name="l00625"></a>00625 
+<a name="l00626"></a>00626         <span class="keyword">const</span> <span class="keywordtype">char</span> * envvar;
+<a name="l00627"></a>00627         <span class="keyword">const</span> <span class="keywordtype">char</span> * svalue;
+<a name="l00628"></a>00628 
+<a name="l00629"></a>00629         <span class="comment">/* FIXME: Needed ? */</span>
+<a name="l00630"></a>00630         <span class="keywordflow">if</span> (cpl_parameter_get_default_flag(p)) <span class="keywordflow">continue</span>;
+<a name="l00631"></a>00631 
+<a name="l00632"></a>00632         cpl_msg_debug(cpl_func, __FILE__ <span class="stringliteral">" line %u: OK"</span>, __LINE__);
+<a name="l00633"></a>00633 
+<a name="l00634"></a>00634         envvar = cpl_parameter_get_alias(p, CPL_PARAMETER_MODE_ENV);
+<a name="l00635"></a>00635         svalue = envvar ? getenv(envvar) : NULL;
+<a name="l00636"></a>00636 
+<a name="l00637"></a>00637         <span class="keywordflow">switch</span> (cpl_parameter_get_type(p)) {
+<a name="l00638"></a>00638         <span class="keywordflow">case</span> CPL_TYPE_BOOL: {
+<a name="l00639"></a>00639             <span class="keyword">const</span> <span class="keywordtype">int</span> value
+<a name="l00640"></a>00640                 = svalue ? atoi(svalue) : cpl_parameter_get_default_bool(p);
+<a name="l00641"></a>00641             cpl_parameter_set_bool(p, value);
+<a name="l00642"></a>00642             <span class="keywordflow">break</span>;
+<a name="l00643"></a>00643         }
+<a name="l00644"></a>00644         <span class="keywordflow">case</span> CPL_TYPE_INT: {
+<a name="l00645"></a>00645             <span class="keyword">const</span> <span class="keywordtype">int</span> value
+<a name="l00646"></a>00646                 = svalue ? atoi(svalue) : cpl_parameter_get_default_int(p);
+<a name="l00647"></a>00647             cpl_parameter_set_int(p, value);
+<a name="l00648"></a>00648             <span class="keywordflow">break</span>;
+<a name="l00649"></a>00649         }
+<a name="l00650"></a>00650         <span class="keywordflow">case</span> CPL_TYPE_DOUBLE: {
+<a name="l00651"></a>00651             <span class="keyword">const</span> <span class="keywordtype">double</span> value
+<a name="l00652"></a>00652                 = svalue ? atof(svalue) : cpl_parameter_get_default_double(p);
+<a name="l00653"></a>00653             cpl_parameter_set_double(p, value);
+<a name="l00654"></a>00654             <span class="keywordflow">break</span>;
+<a name="l00655"></a>00655         }
+<a name="l00656"></a>00656         <span class="keywordflow">case</span> CPL_TYPE_STRING:
+<a name="l00657"></a>00657             {
+<a name="l00658"></a>00658                 <span class="keyword">const</span> <span class="keywordtype">char</span> * s_default = cpl_parameter_get_default_string(p);
+<a name="l00659"></a>00659                 <span class="comment">/* Replace NULL with "" */</span>
+<a name="l00660"></a>00660                 <span class="keyword">const</span> <span class="keywordtype">char</span> * value
+<a name="l00661"></a>00661                     = svalue ? svalue : (s_default ? s_default : <span class="stringliteral">""</span>);
+<a name="l00662"></a>00662                 cpl_parameter_set_string(p, value);
+<a name="l00663"></a>00663                 <span class="keywordflow">break</span>;
+<a name="l00664"></a>00664             }
+<a name="l00665"></a>00665 
+<a name="l00666"></a>00666         <span class="keywordflow">default</span>:
+<a name="l00667"></a>00667             assert( 0 ); <span class="comment">/* It is a testing error to reach this point */</span>
+<a name="l00668"></a>00668         }
+<a name="l00669"></a>00669     }
+<a name="l00670"></a>00670 }
+<a name="l00671"></a>00671 
+<a name="l00672"></a>00672 
+<a name="l00673"></a>00673 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00683"></a>00683 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00684"></a>00684 <span class="keyword">static</span> <span class="keywordtype">void</span> recipe_sof_test_devfile(cpl_plugin * plugin, <span class="keyword">const</span> <span class="keywordtype">char</span> * filename,
+<a name="l00685"></a>00685                                     <span class="keywordtype">size_t</span> nstr, <span class="keyword">const</span> <span class="keywordtype">char</span> *astr[])
+<a name="l00686"></a>00686 {
+<a name="l00687"></a>00687     cpl_recipe * recipe  = (cpl_recipe*)plugin;
+<a name="l00688"></a>00688     int       (*recipe_exec) (cpl_plugin *);
+<a name="l00689"></a>00689     cpl_frameset * copy;
+<a name="l00690"></a>00690     cpl_error_code error;
+<a name="l00691"></a>00691     <span class="keywordtype">size_t</span> i;
+<a name="l00692"></a>00692 
+<a name="l00693"></a>00693 
+<a name="l00694"></a>00694     <span class="keywordflow">if</span> (nstr < 1) <span class="keywordflow">return</span>;
+<a name="l00695"></a>00695     <span class="keywordflow">if</span> (filename == NULL) <span class="keywordflow">return</span>;
+<a name="l00696"></a>00696 
+<a name="l00697"></a>00697     cpl_msg_info(cpl_func, <span class="stringliteral">"Testing recipe with %u %s as input "</span>,
+<a name="l00698"></a>00698                  (<span class="keywordtype">unsigned</span>)nstr, filename);
+<a name="l00699"></a>00699 
+<a name="l00700"></a>00700     <span class="keywordflow">for</span> (i = 0; i < nstr; i++) {
+<a name="l00701"></a>00701         cpl_frame * f = cpl_frame_new();
+<a name="l00702"></a>00702 
+<a name="l00703"></a>00703         error = cpl_frame_set_filename(f, filename);
+<a name="l00704"></a>00704         cpl_test_eq_error(error, CPL_ERROR_NONE);
+<a name="l00705"></a>00705 
+<a name="l00706"></a>00706         error = cpl_frame_set_tag(f, astr[i]);
+<a name="l00707"></a>00707         cpl_test_eq_error(error, CPL_ERROR_NONE);
+<a name="l00708"></a>00708 
+<a name="l00709"></a>00709         error = cpl_frameset_insert(recipe->frames, f);
+<a name="l00710"></a>00710         cpl_test_eq_error(error, CPL_ERROR_NONE);
+<a name="l00711"></a>00711     }
+<a name="l00712"></a>00712 
+<a name="l00713"></a>00713     copy = cpl_frameset_duplicate(recipe->frames);
+<a name="l00714"></a>00714 
+<a name="l00715"></a>00715     recipe_exec = cpl_plugin_get_exec(plugin);
+<a name="l00716"></a>00716     cpl_test( recipe_exec != NULL);
+<a name="l00717"></a>00717 
+<a name="l00718"></a>00718     <span class="keywordflow">if</span> (recipe_exec != NULL) {
+<a name="l00719"></a>00719 
+<a name="l00720"></a>00720         <span class="comment">/* Call recipe and expect non-zero return code */</span>
+<a name="l00721"></a>00721         cpl_test( recipe_exec(plugin) );
+<a name="l00722"></a>00722         error = cpl_error_get_code();
+<a name="l00723"></a>00723         <span class="comment">/* Expect also the CPL error code to be set */</span>
+<a name="l00724"></a>00724         cpl_test_error( error );
+<a name="l00725"></a>00725         cpl_test( error );
+<a name="l00726"></a>00726 
+<a name="l00727"></a>00727         recipe_frameset_test_frameset_diff(recipe->frames, copy);
+<a name="l00728"></a>00728 
+<a name="l00729"></a>00729         recipe_frameset_empty(recipe->frames);
+<a name="l00730"></a>00730     }
+<a name="l00731"></a>00731 
+<a name="l00732"></a>00732     cpl_frameset_delete(copy);
+<a name="l00733"></a>00733 
+<a name="l00734"></a>00734     <span class="keywordflow">return</span>;
+<a name="l00735"></a>00735 }
+<a name="l00736"></a>00736 
+<a name="l00737"></a>00737 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00744"></a>00744 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00745"></a>00745 <span class="keyword">static</span> <span class="keywordtype">void</span> recipe_sof_test_image_empty(cpl_plugin * plugin, <span class="keywordtype">size_t</span> nstr,
+<a name="l00746"></a>00746                                         <span class="keyword">const</span> <span class="keywordtype">char</span> *astr[])
+<a name="l00747"></a>00747 {
+<a name="l00748"></a>00748     cpl_recipe * recipe  = (cpl_recipe*)plugin;
+<a name="l00749"></a>00749     int       (*recipe_exec) (cpl_plugin *);
+<a name="l00750"></a>00750     cpl_frameset * copy;
+<a name="l00751"></a>00751     cpl_error_code error;
+<a name="l00752"></a>00752     <span class="keywordtype">size_t</span> i;
+<a name="l00753"></a>00753     cpl_frame * frame;
+<a name="l00754"></a>00754     cpl_image * iempty;
+<a name="l00755"></a>00755     <span class="keywordtype">int</span> retstat;
+<a name="l00756"></a>00756 
+<a name="l00757"></a>00757 
+<a name="l00758"></a>00758     <span class="keywordflow">if</span> (nstr < 1) <span class="keywordflow">return</span>;
+<a name="l00759"></a>00759 
+<a name="l00760"></a>00760     cpl_msg_info(cpl_func, <span class="stringliteral">"Testing recipe with %u empty images as input "</span>,
+<a name="l00761"></a>00761                  (<span class="keywordtype">unsigned</span>)nstr);
+<a name="l00762"></a>00762 
+<a name="l00763"></a>00763     iempty = cpl_image_new(13, 17, CPL_TYPE_FLOAT);
+<a name="l00764"></a>00764     cpl_test_nonnull(iempty);
+<a name="l00765"></a>00765 
+<a name="l00766"></a>00766     <span class="keywordflow">for</span> (i = 0; i < nstr; i++) {
+<a name="l00767"></a>00767         cpl_frame * f = cpl_frame_new();
+<a name="l00768"></a>00768         <span class="keywordtype">char</span> * rawname = cpl_sprintf(<span class="stringliteral">"raw%05u.fits"</span>, (<span class="keywordtype">unsigned</span>)(i+1));
+<a name="l00769"></a>00769 
+<a name="l00770"></a>00770         error = cpl_image_save(iempty, rawname,CPL_BPP_IEEE_FLOAT, NULL,
+<a name="l00771"></a>00771                                CPL_IO_DEFAULT);
+<a name="l00772"></a>00772         cpl_test_eq_error(error, CPL_ERROR_NONE);
+<a name="l00773"></a>00773 
+<a name="l00774"></a>00774         error = cpl_frame_set_filename(f, rawname);
+<a name="l00775"></a>00775         cpl_test_eq_error(error, CPL_ERROR_NONE);
+<a name="l00776"></a>00776 
+<a name="l00777"></a>00777         error = cpl_frame_set_tag(f, astr[i]);
+<a name="l00778"></a>00778         cpl_test_eq_error(error, CPL_ERROR_NONE);
+<a name="l00779"></a>00779 
+<a name="l00780"></a>00780         error = cpl_frameset_insert(recipe->frames, f);
+<a name="l00781"></a>00781         cpl_test_eq_error(error, CPL_ERROR_NONE);
+<a name="l00782"></a>00782 
+<a name="l00783"></a>00783         cpl_free(rawname);
+<a name="l00784"></a>00784     }
+<a name="l00785"></a>00785     cpl_image_delete(iempty);
+<a name="l00786"></a>00786 
+<a name="l00787"></a>00787     copy = cpl_frameset_duplicate(recipe->frames);
+<a name="l00788"></a>00788 
+<a name="l00789"></a>00789     recipe_exec = cpl_plugin_get_exec(plugin);
+<a name="l00790"></a>00790     cpl_test(recipe_exec != NULL);
+<a name="l00791"></a>00791 
+<a name="l00792"></a>00792     <span class="keywordflow">if</span> (recipe_exec != NULL) {
+<a name="l00793"></a>00793 
+<a name="l00794"></a>00794         <span class="comment">/* Call recipe and expect consistency between return code and</span>
+<a name="l00795"></a>00795 <span class="comment">           CPL error */</span>
+<a name="l00796"></a>00796 
+<a name="l00797"></a>00797         retstat = recipe_exec(plugin);
+<a name="l00798"></a>00798         error = cpl_error_get_code();
+<a name="l00799"></a>00799         <span class="comment">/* Expect also the CPL error code to be set */</span>
+<a name="l00800"></a>00800         <span class="keywordflow">if</span> (error == 0) {
+<a name="l00801"></a>00801             cpl_test_zero(retstat);
+<a name="l00802"></a>00802         } <span class="keywordflow">else</span> {
+<a name="l00803"></a>00803             cpl_test(retstat);
+<a name="l00804"></a>00804         }
+<a name="l00805"></a>00805         cpl_test_error( error );
+<a name="l00806"></a>00806 
+<a name="l00807"></a>00807         recipe_frameset_test_frameset_diff(recipe->frames, copy);
+<a name="l00808"></a>00808 
+<a name="l00809"></a>00809         <span class="keywordflow">for</span> (frame = cpl_frameset_get_first(recipe->frames); frame != NULL;
+<a name="l00810"></a>00810              frame = cpl_frameset_get_next(recipe->frames))
+<a name="l00811"></a>00811             {
+<a name="l00812"></a>00812                 cpl_test_zero( <span class="keyword">remove</span>(cpl_frame_get_filename(frame)) );
+<a name="l00813"></a>00813             }
+<a name="l00814"></a>00814 
+<a name="l00815"></a>00815         recipe_frameset_empty(recipe->frames);
+<a name="l00816"></a>00816     }
+<a name="l00817"></a>00817 
+<a name="l00818"></a>00818     cpl_frameset_delete(copy);
+<a name="l00819"></a>00819 
+<a name="l00820"></a>00820     <span class="keywordflow">return</span>;
+<a name="l00821"></a>00821 }
+<a name="l00822"></a>00822 
+<a name="l00823"></a>00823 
+<a name="l00824"></a>00824 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00832"></a>00832 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00833"></a>00833 cpl_boolean irplib_plugin_has_sof_from_env(<span class="keyword">const</span> cpl_plugin * plugin,
+<a name="l00834"></a>00834                                            <span class="keyword">const</span> <span class="keywordtype">char</span> * envname)
+<a name="l00835"></a>00835 {
+<a name="l00836"></a>00836     <span class="keyword">const</span> <span class="keywordtype">char</span>      * recipename = cpl_plugin_get_name(plugin);
+<a name="l00837"></a>00837     <span class="keyword">const</span> <span class="keywordtype">char</span>      * sof_path   = envname ? getenv(envname) : NULL;
+<a name="l00838"></a>00838     cpl_frameset    * frames;
+<a name="l00839"></a>00839     <span class="keywordtype">char</span>            * sof_name;
+<a name="l00840"></a>00840     <span class="keyword">const</span> cpl_frame * ffirst;
+<a name="l00841"></a>00841 
+<a name="l00842"></a>00842     cpl_ensure(plugin  != NULL, CPL_ERROR_NULL_INPUT, CPL_FALSE);
+<a name="l00843"></a>00843     cpl_ensure(envname != NULL, CPL_ERROR_NULL_INPUT, CPL_FALSE);
+<a name="l00844"></a>00844     cpl_ensure(recipename != NULL, CPL_ERROR_DATA_NOT_FOUND, CPL_FALSE);
+<a name="l00845"></a>00845     cpl_ensure(!cpl_error_get_code(), cpl_error_get_code(), CPL_FALSE);
+<a name="l00846"></a>00846 
+<a name="l00847"></a>00847     <span class="keywordflow">if</span> (sof_path == NULL) <span class="keywordflow">return</span> CPL_FALSE;
+<a name="l00848"></a>00848 
+<a name="l00849"></a>00849     sof_name = cpl_sprintf(<span class="stringliteral">"%s/%s.sof"</span>, sof_path, recipename);
+<a name="l00850"></a>00850 
+<a name="l00851"></a>00851     frames = cpl_frameset_new();
+<a name="l00852"></a>00852     recipe_frameset_load(frames, sof_name);
+<a name="l00853"></a>00853 
+<a name="l00854"></a>00854     ffirst = cpl_frameset_get_first_const(frames);
+<a name="l00855"></a>00855 
+<a name="l00856"></a>00856     cpl_free(sof_name);
+<a name="l00857"></a>00857     cpl_frameset_delete(frames);
+<a name="l00858"></a>00858 
+<a name="l00859"></a>00859     cpl_ensure(!cpl_error_get_code(), cpl_error_get_code(), CPL_FALSE);
+<a name="l00860"></a>00860 
+<a name="l00861"></a>00861     <span class="keywordflow">return</span> ffirst ? CPL_TRUE : CPL_FALSE;
+<a name="l00862"></a>00862 
+<a name="l00863"></a>00863 }
+<a name="l00864"></a>00864 
+<a name="l00865"></a>00865 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00872"></a>00872 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00873"></a>00873 <span class="keyword">static</span> <span class="keywordtype">void</span> recipe_sof_test_from_env(cpl_plugin * plugin)
+<a name="l00874"></a>00874 {
+<a name="l00875"></a>00875     cpl_recipe * recipe  = (cpl_recipe*)plugin;
+<a name="l00876"></a>00876     <span class="keyword">const</span> <span class="keywordtype">char</span> * recipename = cpl_plugin_get_name(plugin);
+<a name="l00877"></a>00877     <span class="keyword">const</span> <span class="keywordtype">char</span> * var_name = <span class="stringliteral">"RECIPE_SOF_PATH"</span>;
+<a name="l00878"></a>00878     <span class="keyword">const</span> <span class="keywordtype">char</span> * sof_path = getenv(var_name);
+<a name="l00879"></a>00879     cpl_error_code error;
+<a name="l00880"></a>00880 
+<a name="l00881"></a>00881     <span class="keywordtype">char</span> * sof_name;
+<a name="l00882"></a>00882 
+<a name="l00883"></a>00883     <span class="keywordflow">if</span> (sof_path == NULL) {
+<a name="l00884"></a>00884         cpl_msg_warning(cpl_func, <span class="stringliteral">"Environment variable %s is unset: "</span>
+<a name="l00885"></a>00885                         <span class="stringliteral">"No SOFs to check"</span>, var_name);
+<a name="l00886"></a>00886         <span class="keywordflow">return</span>;
+<a name="l00887"></a>00887     }
+<a name="l00888"></a>00888 
+<a name="l00889"></a>00889     cpl_msg_debug(cpl_func, <span class="stringliteral">"Checking for SOFs in %s"</span>, sof_path);
+<a name="l00890"></a>00890 
+<a name="l00891"></a>00891     cpl_test_nonnull( recipename );
+<a name="l00892"></a>00892     <span class="keywordflow">if</span> (recipename == NULL) <span class="keywordflow">return</span>;
+<a name="l00893"></a>00893 
+<a name="l00894"></a>00894     sof_name = cpl_sprintf(<span class="stringliteral">"%s/%s.sof"</span>, sof_path, recipename);
+<a name="l00895"></a>00895 
+<a name="l00896"></a>00896     cpl_msg_debug(cpl_func, <span class="stringliteral">"Checking for SOF %s"</span>, sof_name);
+<a name="l00897"></a>00897     
+<a name="l00898"></a>00898     recipe_frameset_load(recipe->frames, sof_name);
+<a name="l00899"></a>00899 
+<a name="l00900"></a>00900     <span class="keywordflow">if</span> (!cpl_frameset_is_empty(recipe->frames)) {
+<a name="l00901"></a>00901 
+<a name="l00902"></a>00902         int          (*recipe_exec  ) (cpl_plugin *);
+<a name="l00903"></a>00903         cpl_frameset * copy = cpl_frameset_duplicate(recipe->frames);
+<a name="l00904"></a>00904 
+<a name="l00905"></a>00905         recipe_exec   = cpl_plugin_get_exec(plugin);
+<a name="l00906"></a>00906         cpl_test(recipe_exec != NULL);
+<a name="l00907"></a>00907 
+<a name="l00908"></a>00908         <span class="keywordflow">if</span> (recipe_exec != NULL) {
+<a name="l00909"></a>00909             cpl_msg_info(cpl_func,<span class="stringliteral">"Checking handling of SOF: %s"</span>, sof_name);
+<a name="l00910"></a>00910 
+<a name="l00911"></a>00911             <span class="comment">/* Call recipe and expect zero return code */</span>
+<a name="l00912"></a>00912             cpl_test_zero( recipe_exec(plugin) );
+<a name="l00913"></a>00913             <span class="comment">/* Expect also the CPL error code to be clear */</span>
+<a name="l00914"></a>00914             cpl_test_error(CPL_ERROR_NONE);
+<a name="l00915"></a>00915 
+<a name="l00916"></a>00916             error = cpl_dfs_update_product_header(recipe->frames);
+<a name="l00917"></a>00917             cpl_test_eq_error(error, CPL_ERROR_NONE);
+<a name="l00918"></a>00918 
+<a name="l00919"></a>00919             recipe_frameset_test_frameset_diff(recipe->frames, copy);
+<a name="l00920"></a>00920 
+<a name="l00921"></a>00921             recipe_frameset_empty(recipe->frames);
+<a name="l00922"></a>00922         }
+<a name="l00923"></a>00923 
+<a name="l00924"></a>00924         cpl_frameset_delete(copy);
+<a name="l00925"></a>00925 
+<a name="l00926"></a>00926     }
+<a name="l00927"></a>00927 
+<a name="l00928"></a>00928     cpl_free(sof_name);
+<a name="l00929"></a>00929 
+<a name="l00930"></a>00930     <span class="keywordflow">return</span>;
+<a name="l00931"></a>00931 }
+<a name="l00932"></a>00932 
+<a name="l00933"></a>00933 
+<a name="l00934"></a>00934 
+<a name="l00935"></a>00935 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00942"></a>00942 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00943"></a>00943 <span class="keyword">static</span> <span class="keywordtype">void</span> recipe_sof_test_local(cpl_plugin * plugin)
+<a name="l00944"></a>00944 {
+<a name="l00945"></a>00945     cpl_recipe * recipe  = (cpl_recipe*)plugin;
+<a name="l00946"></a>00946     <span class="keyword">const</span> <span class="keywordtype">char</span> * recipename = cpl_plugin_get_name(plugin);
+<a name="l00947"></a>00947     cpl_error_code error;
+<a name="l00948"></a>00948     <span class="keywordtype">char</span> * sof_name = cpl_sprintf(<span class="stringliteral">"%s.sof"</span>, recipename);
+<a name="l00949"></a>00949 
+<a name="l00950"></a>00950     cpl_msg_debug(cpl_func, <span class="stringliteral">"Checking for SOF %s"</span>, sof_name);
+<a name="l00951"></a>00951     
+<a name="l00952"></a>00952     recipe_frameset_load(recipe->frames, sof_name);
+<a name="l00953"></a>00953 
+<a name="l00954"></a>00954     <span class="keywordflow">if</span> (!cpl_frameset_is_empty(recipe->frames)) {
+<a name="l00955"></a>00955 
+<a name="l00956"></a>00956         int          (*recipe_exec  ) (cpl_plugin *);
+<a name="l00957"></a>00957         cpl_frameset * copy = cpl_frameset_duplicate(recipe->frames);
+<a name="l00958"></a>00958 
+<a name="l00959"></a>00959         recipe_exec   = cpl_plugin_get_exec(plugin);
+<a name="l00960"></a>00960         cpl_test(recipe_exec != NULL);
+<a name="l00961"></a>00961 
+<a name="l00962"></a>00962         <span class="keywordflow">if</span> (recipe_exec != NULL) {
+<a name="l00963"></a>00963 
+<a name="l00964"></a>00964             cpl_msg_info(cpl_func,<span class="stringliteral">"Checking handling of SOF: %s"</span>, sof_name);
+<a name="l00965"></a>00965 
+<a name="l00966"></a>00966             <span class="comment">/* Call recipe and expect zero return code */</span>
+<a name="l00967"></a>00967             cpl_test_zero( recipe_exec(plugin) );
+<a name="l00968"></a>00968             <span class="comment">/* Expect also the CPL error code to be clear */</span>
+<a name="l00969"></a>00969             cpl_test_error(CPL_ERROR_NONE);
+<a name="l00970"></a>00970 
+<a name="l00971"></a>00971             error = cpl_dfs_update_product_header(recipe->frames);
+<a name="l00972"></a>00972             cpl_test_eq_error( error, CPL_ERROR_NONE );
+<a name="l00973"></a>00973 
+<a name="l00974"></a>00974             recipe_frameset_test_frameset_diff(recipe->frames, copy);
+<a name="l00975"></a>00975 
+<a name="l00976"></a>00976             recipe_frameset_empty(recipe->frames);
+<a name="l00977"></a>00977         }
+<a name="l00978"></a>00978 
+<a name="l00979"></a>00979         cpl_frameset_delete(copy);
+<a name="l00980"></a>00980     }
+<a name="l00981"></a>00981 
+<a name="l00982"></a>00982     cpl_free(sof_name);
+<a name="l00983"></a>00983 
+<a name="l00984"></a>00984     <span class="keywordflow">return</span>;
+<a name="l00985"></a>00985 }
+<a name="l00986"></a>00986 
+<a name="l00987"></a>00987 
+<a name="l00988"></a>00988 
+<a name="l00989"></a>00989 
+<a name="l00990"></a>00990 <span class="comment">/**********************************************************************/</span>
+<a name="l01004"></a>01004 <span class="comment">/**********************************************************************/</span>
+<a name="l01005"></a>01005 
+<a name="l01006"></a>01006 <span class="keyword">static</span> <span class="keywordtype">void</span> recipe_frameset_load(cpl_frameset * <span class="keyword">set</span>, <span class="keyword">const</span> <span class="keywordtype">char</span> *name)
+<a name="l01007"></a>01007 {
+<a name="l01008"></a>01008 
+<a name="l01009"></a>01009     FILE *fp;
+<a name="l01010"></a>01010     <span class="keywordtype">char</span> line[LINE_LEN_MAX];
+<a name="l01011"></a>01011     <span class="keywordtype">char</span> path[LINE_LEN_MAX], group[LINE_LEN_MAX], tag[LINE_LEN_MAX];
+<a name="l01012"></a>01012     <span class="keywordtype">int</span> line_number;
+<a name="l01013"></a>01013 
+<a name="l01014"></a>01014     assert( <span class="keyword">set</span> != NULL );
+<a name="l01015"></a>01015     assert( name != NULL );
+<a name="l01016"></a>01016 
+<a name="l01017"></a>01017     fp = fopen(name, <span class="stringliteral">"r"</span>);
+<a name="l01018"></a>01018     <span class="keywordflow">if</span> (fp == NULL) {
+<a name="l01019"></a>01019         cpl_msg_debug(cpl_func, <span class="stringliteral">"Unable to open SOF file '%s'"</span>, name);
+<a name="l01020"></a>01020         <span class="keywordflow">return</span>;
+<a name="l01021"></a>01021     }
+<a name="l01022"></a>01022 
+<a name="l01023"></a>01023     <span class="comment">/* Loop over all the lines in the set-of-frames file */</span>
+<a name="l01024"></a>01024     <span class="keywordflow">for</span> (line_number = 0; fgets(line, LINE_LEN_MAX - 1, fp); line_number++) {
+<a name="l01025"></a>01025 
+<a name="l01026"></a>01026         cpl_frame_group grp;
+<a name="l01027"></a>01027         cpl_frame * frame;
+<a name="l01028"></a>01028         <span class="keywordtype">int</span> n;
+<a name="l01029"></a>01029 
+<a name="l01030"></a>01030         <span class="keywordflow">if</span> (line[0] == <span class="charliteral">'#'</span>) <span class="keywordflow">continue</span>;
+<a name="l01031"></a>01031 
+<a name="l01032"></a>01032         n = sscanf(line, <span class="stringliteral">"%s %s %s"</span>, path, tag, group);
+<a name="l01033"></a>01033 
+<a name="l01034"></a>01034         <span class="keywordflow">if</span> (n < 1) {
+<a name="l01035"></a>01035             cpl_msg_warning(cpl_func, <span class="stringliteral">"Spurious line no. %d in %s: %s"</span>,
+<a name="l01036"></a>01036                             line_number, name, line);
+<a name="l01037"></a>01037             <span class="keywordflow">break</span>;
+<a name="l01038"></a>01038         }
+<a name="l01039"></a>01039 
+<a name="l01040"></a>01040         <span class="comment">/* Allocate a new frame */</span>
+<a name="l01041"></a>01041         frame = cpl_frame_new();
+<a name="l01042"></a>01042 
+<a name="l01043"></a>01043         <span class="comment">/* Set the filename component of the frame */</span>
+<a name="l01044"></a>01044         cpl_frame_set_filename(frame, path);
+<a name="l01045"></a>01045 
+<a name="l01046"></a>01046         <span class="comment">/* Set the tag component of the frame (or set a default) */</span>
+<a name="l01047"></a>01047         cpl_frame_set_tag(frame, n == 1 ? <span class="stringliteral">""</span> : tag);
+<a name="l01048"></a>01048 
+<a name="l01049"></a>01049         cpl_frameset_insert(<span class="keyword">set</span>, frame);
+<a name="l01050"></a>01050 
+<a name="l01051"></a>01051         <span class="comment">/* Set the group component of the frame (or set a default) */</span>
+<a name="l01052"></a>01052         <span class="keywordflow">if</span> (n < 3) <span class="keywordflow">continue</span>;
+<a name="l01053"></a>01053 
+<a name="l01054"></a>01054         <span class="keywordflow">if</span> (!strcmp(group, CPL_FRAME_GROUP_RAW_ID))
+<a name="l01055"></a>01055             grp = CPL_FRAME_GROUP_RAW;
+<a name="l01056"></a>01056         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!strcmp(group, CPL_FRAME_GROUP_CALIB_ID))
+<a name="l01057"></a>01057             grp = CPL_FRAME_GROUP_CALIB;
+<a name="l01058"></a>01058         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!strcmp(group, CPL_FRAME_GROUP_PRODUCT_ID))
+<a name="l01059"></a>01059             grp = CPL_FRAME_GROUP_PRODUCT;
+<a name="l01060"></a>01060         <span class="keywordflow">else</span>
+<a name="l01061"></a>01061             grp = CPL_FRAME_GROUP_NONE;
+<a name="l01062"></a>01062 
+<a name="l01063"></a>01063         cpl_frame_set_group(frame, grp);
+<a name="l01064"></a>01064     }
+<a name="l01065"></a>01065 
+<a name="l01066"></a>01066     fclose(fp);
+<a name="l01067"></a>01067 
+<a name="l01068"></a>01068     <span class="keywordflow">return</span>;
+<a name="l01069"></a>01069 
+<a name="l01070"></a>01070 }
+<a name="l01071"></a>01071 
+<a name="l01072"></a>01072 
+<a name="l01073"></a>01073 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01083"></a>01083 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01084"></a>01084 <span class="keyword">static</span>
+<a name="l01085"></a>01085 <span class="keyword">const</span> cpl_parameter * irplib_parameterlist_get(<span class="keyword">const</span> cpl_parameterlist * <span class="keyword">self</span>,
+<a name="l01086"></a>01086                                                <span class="keyword">const</span> <span class="keywordtype">char</span> * instrume,
+<a name="l01087"></a>01087                                                <span class="keyword">const</span> <span class="keywordtype">char</span> * recipe,
+<a name="l01088"></a>01088                                                <span class="keyword">const</span> <span class="keywordtype">char</span> * parameter)
+<a name="l01089"></a>01089 {
+<a name="l01090"></a>01090 
+<a name="l01091"></a>01091     <span class="keywordtype">char</span>                * paramname;
+<a name="l01092"></a>01092     <span class="keyword">const</span> cpl_parameter * par;
+<a name="l01093"></a>01093 
+<a name="l01094"></a>01094 
+<a name="l01095"></a>01095     cpl_ensure(instrume  != NULL, CPL_ERROR_NULL_INPUT, NULL);
+<a name="l01096"></a>01096     cpl_ensure(recipe    != NULL, CPL_ERROR_NULL_INPUT, NULL);
+<a name="l01097"></a>01097     cpl_ensure(parameter != NULL, CPL_ERROR_NULL_INPUT, NULL);
+<a name="l01098"></a>01098 
+<a name="l01099"></a>01099     paramname = cpl_sprintf(<span class="stringliteral">"%s.%s.%s"</span>, instrume, recipe, parameter);
+<a name="l01100"></a>01100 
+<a name="l01101"></a>01101     par = cpl_parameterlist_find_const(<span class="keyword">self</span>, paramname);
+<a name="l01102"></a>01102 
+<a name="l01103"></a>01103     <span class="keywordflow">if</span> (par == NULL) (void)cpl_error_set_message(cpl_func,
+<a name="l01104"></a>01104                                                  cpl_error_get_code()
+<a name="l01105"></a>01105                                                  ? cpl_error_get_code()
+<a name="l01106"></a>01106                                                  : CPL_ERROR_DATA_NOT_FOUND,
+<a name="l01107"></a>01107                                                  <span class="stringliteral">"%s"</span>, paramname);
+<a name="l01108"></a>01108 
+<a name="l01109"></a>01109     cpl_free(paramname);
+<a name="l01110"></a>01110     
+<a name="l01111"></a>01111     <span class="keywordflow">return</span> par;
+<a name="l01112"></a>01112 
+<a name="l01113"></a>01113 }
+<a name="l01114"></a>01114 
+<a name="l01115"></a>01115 
+<a name="l01116"></a>01116 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01142"></a>01142 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01143"></a>01143 <span class="keyword">static</span> <span class="keywordtype">void</span> recipe_frameset_empty(cpl_frameset * <span class="keyword">self</span>)
+<a name="l01144"></a>01144 {
+<a name="l01145"></a>01145     cpl_frame * f;
+<a name="l01146"></a>01146 
+<a name="l01147"></a>01147     <span class="keywordflow">if</span> (<span class="keyword">self</span> == NULL) {
+<a name="l01148"></a>01148         cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT);
+<a name="l01149"></a>01149         <span class="keywordflow">return</span>;
+<a name="l01150"></a>01150     }
+<a name="l01151"></a>01151 
+<a name="l01152"></a>01152     <span class="keywordflow">for</span> (f = cpl_frameset_get_first(<span class="keyword">self</span>); f != NULL;
+<a name="l01153"></a>01153          f = cpl_frameset_get_first(<span class="keyword">self</span>))
+<a name="l01154"></a>01154         {
+<a name="l01155"></a>01155             cpl_frameset_erase_frame(<span class="keyword">self</span>, f);
+<a name="l01156"></a>01156         }
+<a name="l01157"></a>01157 }
+<a name="l01158"></a>01158 
+<a name="l01159"></a>01159 
+<a name="l01160"></a>01160 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01180"></a>01180 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01181"></a>01181 <span class="keyword">static</span> <span class="keywordtype">void</span> recipe_frameset_test_frame(<span class="keyword">const</span> cpl_frame * <span class="keyword">self</span>)
+<a name="l01182"></a>01182 {
+<a name="l01183"></a>01183 
+<a name="l01184"></a>01184     cpl_msg_info(cpl_func, <span class="stringliteral">"Validating new frame: %s"</span>,
+<a name="l01185"></a>01185                  cpl_frame_get_filename(<span class="keyword">self</span>));
+<a name="l01186"></a>01186 
+<a name="l01187"></a>01187     cpl_test_nonnull(<span class="keyword">self</span>);
+<a name="l01188"></a>01188 
+<a name="l01189"></a>01189     <span class="comment">/* Frame must be tagged */</span>
+<a name="l01190"></a>01190     cpl_test_nonnull(cpl_frame_get_tag(<span class="keyword">self</span>));
+<a name="l01191"></a>01191 
+<a name="l01192"></a>01192     <span class="comment">/* New frames must be products */</span>
+<a name="l01193"></a>01193     cpl_test_eq(cpl_frame_get_group(<span class="keyword">self</span>), CPL_FRAME_GROUP_PRODUCT);
+<a name="l01194"></a>01194 
+<a name="l01195"></a>01195     <span class="keywordflow">if</span> (cpl_frame_get_type(<span class="keyword">self</span>) != CPL_FRAME_TYPE_PAF) {
+<a name="l01196"></a>01196         <span class="comment">/* All but PAF (?) must be FITS */</span>
+<a name="l01197"></a>01197         cpl_test_fits(cpl_frame_get_filename(<span class="keyword">self</span>));
+<a name="l01198"></a>01198     } <span class="keywordflow">else</span> {
+<a name="l01199"></a>01199         <span class="comment">/* Frame must at least have a filename */</span>
+<a name="l01200"></a>01200         cpl_test_nonnull(cpl_frame_get_filename(<span class="keyword">self</span>));
+<a name="l01201"></a>01201     }
+<a name="l01202"></a>01202 }
+<a name="l01203"></a>01203 
+<a name="l01204"></a>01204 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01225"></a>01225 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01226"></a>01226 <span class="keyword">static</span> <span class="keywordtype">void</span> recipe_frameset_test_frameset_diff(<span class="keyword">const</span> cpl_frameset * <span class="keyword">self</span>,
+<a name="l01227"></a>01227                                                <span class="keyword">const</span> cpl_frameset * other)
+<a name="l01228"></a>01228 {
+<a name="l01229"></a>01229 
+<a name="l01230"></a>01230     <span class="keyword">const</span> cpl_frame * frame = cpl_frameset_get_first_const(other);
+<a name="l01231"></a>01231 
+<a name="l01232"></a>01232     <span class="comment">/* First verify that filenames in other are non-NULL */</span>
+<a name="l01233"></a>01233     <span class="keywordflow">for</span> (;frame != NULL; frame = cpl_frameset_get_next_const(other)) {
+<a name="l01234"></a>01234         <span class="keyword">const</span> <span class="keywordtype">char</span> * file = cpl_frame_get_filename(frame);
+<a name="l01235"></a>01235 
+<a name="l01236"></a>01236         <span class="keywordflow">if</span> (file == NULL) {
+<a name="l01237"></a>01237             cpl_test_nonnull(cpl_frame_get_filename(frame));
+<a name="l01238"></a>01238             <span class="keywordflow">break</span>;
+<a name="l01239"></a>01239         }
+<a name="l01240"></a>01240     }
+<a name="l01241"></a>01241     <span class="keywordflow">if</span> (frame != NULL) <span class="keywordflow">return</span>;
+<a name="l01242"></a>01242 
+<a name="l01243"></a>01243     frame = cpl_frameset_get_first_const(<span class="keyword">self</span>);
+<a name="l01244"></a>01244 
+<a name="l01245"></a>01245     <span class="keywordflow">for</span> (;frame != NULL; frame = cpl_frameset_get_next_const(<span class="keyword">self</span>)) {
+<a name="l01246"></a>01246         <span class="keyword">const</span> cpl_frame * cmp  = cpl_frameset_get_first_const(other);
+<a name="l01247"></a>01247         <span class="keyword">const</span> <span class="keywordtype">char</span> * file = cpl_frame_get_filename(frame);
+<a name="l01248"></a>01248 
+<a name="l01249"></a>01249         <span class="keywordflow">if</span> (file == NULL) {
+<a name="l01250"></a>01250             cpl_test_nonnull(cpl_frame_get_filename(frame));
+<a name="l01251"></a>01251             <span class="keywordflow">continue</span>;
+<a name="l01252"></a>01252         }
+<a name="l01253"></a>01253 
+<a name="l01254"></a>01254         <span class="keywordflow">for</span> (;cmp != NULL; cmp = cpl_frameset_get_next_const(other)) {
+<a name="l01255"></a>01255             <span class="keyword">const</span> <span class="keywordtype">char</span> * cfile = cpl_frame_get_filename(cmp);
+<a name="l01256"></a>01256 
+<a name="l01257"></a>01257             <span class="keywordflow">if</span> (!strcmp(file, cfile)) <span class="keywordflow">break</span>;
+<a name="l01258"></a>01258 
+<a name="l01259"></a>01259         }
+<a name="l01260"></a>01260         <span class="keywordflow">if</span> (cmp == NULL) {
+<a name="l01261"></a>01261             <span class="comment">/* frame is new */</span>
+<a name="l01262"></a>01262 
+<a name="l01263"></a>01263             cpl_test_eq(cpl_frame_get_group(frame), CPL_FRAME_GROUP_PRODUCT);
+<a name="l01264"></a>01264             recipe_frameset_test_frame(frame);
+<a name="l01265"></a>01265         }
+<a name="l01266"></a>01266     }
+<a name="l01267"></a>01267 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/irplib__plugin_8h_source.html b/html/irplib__plugin_8h_source.html
new file mode 100644
index 0000000..a3d6f05
--- /dev/null
+++ b/html/irplib__plugin_8h_source.html
@@ -0,0 +1,109 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: irplib_plugin.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>irplib_plugin.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: irplib_plugin.h,v 1.23 2012/01/11 08:03:37 llundin Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the irplib package </span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: llundin $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2012/01/11 08:03:37 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.23 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifndef IRPLIB_PLUGIN_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#define IRPLIB_PLUGIN_H</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span>
+<a name="l00031"></a>00031 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00032"></a>00032 <span class="comment">                                   Includes</span>
+<a name="l00033"></a>00033 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00034"></a>00034 
+<a name="l00035"></a>00035 <span class="preprocessor">#include <irplib_utils.h></span>  <span class="comment">/* irplib_reset() */</span>
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00038"></a>00038 
+<a name="l00039"></a>00039 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00040"></a>00040 <span class="comment">                                   Define</span>
+<a name="l00041"></a>00041 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00042"></a>00042 
+<a name="l00043"></a>00043 <span class="comment">/* Needed (by uves) to concatenate two macro arguments */</span>
+<a name="l00044"></a>00044 <span class="preprocessor">#define IRPLIB_CONCAT(a,b) a ## _ ## b</span>
+<a name="l00045"></a>00045 <span class="preprocessor"></span><span class="preprocessor">#define IRPLIB_CONCAT2X(a,b) IRPLIB_CONCAT(a,b)</span>
+<a name="l00046"></a>00046 <span class="preprocessor"></span>
+<a name="l00047"></a>00047 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00048"></a>00048 <span class="comment">                                   Function prototypes</span>
+<a name="l00049"></a>00049 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00050"></a>00050 
+<a name="l00051"></a>00051 <span class="keywordtype">int</span> irplib_plugin_test(cpl_pluginlist *, <span class="keywordtype">size_t</span>, <span class="keyword">const</span> <span class="keywordtype">char</span> *[]);
+<a name="l00052"></a>00052 
+<a name="l00053"></a>00053 cpl_error_code irplib_parameterlist_set_string(cpl_parameterlist *,
+<a name="l00054"></a>00054                                                <span class="keyword">const</span> <span class="keywordtype">char</span> *, <span class="keyword">const</span> <span class="keywordtype">char</span> *,
+<a name="l00055"></a>00055                                                <span class="keyword">const</span> <span class="keywordtype">char</span> *, <span class="keyword">const</span> <span class="keywordtype">char</span> *, 
+<a name="l00056"></a>00056                                                <span class="keyword">const</span> <span class="keywordtype">char</span> *, <span class="keyword">const</span> <span class="keywordtype">char</span> *,
+<a name="l00057"></a>00057                                                <span class="keyword">const</span> <span class="keywordtype">char</span> *);
+<a name="l00058"></a>00058 
+<a name="l00059"></a>00059 cpl_error_code irplib_parameterlist_set_bool(cpl_parameterlist *,
+<a name="l00060"></a>00060                                              <span class="keyword">const</span> <span class="keywordtype">char</span> *, <span class="keyword">const</span> <span class="keywordtype">char</span> *,
+<a name="l00061"></a>00061                                              <span class="keyword">const</span> <span class="keywordtype">char</span> *, cpl_boolean,
+<a name="l00062"></a>00062                                              <span class="keyword">const</span> <span class="keywordtype">char</span> *, <span class="keyword">const</span> <span class="keywordtype">char</span> *,
+<a name="l00063"></a>00063                                              <span class="keyword">const</span> <span class="keywordtype">char</span> *);
+<a name="l00064"></a>00064 
+<a name="l00065"></a>00065 cpl_error_code irplib_parameterlist_set_int(cpl_parameterlist *,
+<a name="l00066"></a>00066                                             <span class="keyword">const</span> <span class="keywordtype">char</span> *, <span class="keyword">const</span> <span class="keywordtype">char</span> *,
+<a name="l00067"></a>00067                                             <span class="keyword">const</span> <span class="keywordtype">char</span> *, <span class="keywordtype">int</span>,
+<a name="l00068"></a>00068                                             <span class="keyword">const</span> <span class="keywordtype">char</span> *, <span class="keyword">const</span> <span class="keywordtype">char</span> *,
+<a name="l00069"></a>00069                                             <span class="keyword">const</span> <span class="keywordtype">char</span> *);
+<a name="l00070"></a>00070 
+<a name="l00071"></a>00071 cpl_error_code irplib_parameterlist_set_double(cpl_parameterlist *,
+<a name="l00072"></a>00072                                                <span class="keyword">const</span> <span class="keywordtype">char</span> *, <span class="keyword">const</span> <span class="keywordtype">char</span> *,
+<a name="l00073"></a>00073                                                <span class="keyword">const</span> <span class="keywordtype">char</span> *, <span class="keywordtype">double</span>, 
+<a name="l00074"></a>00074                                                <span class="keyword">const</span> <span class="keywordtype">char</span> *, <span class="keyword">const</span> <span class="keywordtype">char</span> *,
+<a name="l00075"></a>00075                                                <span class="keyword">const</span> <span class="keywordtype">char</span> *);
+<a name="l00076"></a>00076 
+<a name="l00077"></a>00077 <span class="keyword">const</span> <span class="keywordtype">char</span> * irplib_parameterlist_get_string(<span class="keyword">const</span> cpl_parameterlist *,
+<a name="l00078"></a>00078                                              <span class="keyword">const</span> <span class="keywordtype">char</span> *, <span class="keyword">const</span> <span class="keywordtype">char</span> *,
+<a name="l00079"></a>00079                                              <span class="keyword">const</span> <span class="keywordtype">char</span> *);
+<a name="l00080"></a>00080 
+<a name="l00081"></a>00081 cpl_boolean irplib_parameterlist_get_bool(<span class="keyword">const</span> cpl_parameterlist *,
+<a name="l00082"></a>00082                                           <span class="keyword">const</span> <span class="keywordtype">char</span> *, <span class="keyword">const</span> <span class="keywordtype">char</span> *,
+<a name="l00083"></a>00083                                           <span class="keyword">const</span> <span class="keywordtype">char</span> *);
+<a name="l00084"></a>00084 
+<a name="l00085"></a>00085 <span class="keywordtype">int</span> irplib_parameterlist_get_int(<span class="keyword">const</span> cpl_parameterlist *,
+<a name="l00086"></a>00086                                  <span class="keyword">const</span> <span class="keywordtype">char</span> *, <span class="keyword">const</span> <span class="keywordtype">char</span> *,
+<a name="l00087"></a>00087                                  <span class="keyword">const</span> <span class="keywordtype">char</span> *);
+<a name="l00088"></a>00088 
+<a name="l00089"></a>00089 <span class="keywordtype">double</span> irplib_parameterlist_get_double(<span class="keyword">const</span> cpl_parameterlist *,
+<a name="l00090"></a>00090                                        <span class="keyword">const</span> <span class="keywordtype">char</span> *, <span class="keyword">const</span> <span class="keywordtype">char</span> *,
+<a name="l00091"></a>00091                                        <span class="keyword">const</span> <span class="keywordtype">char</span> *);
+<a name="l00092"></a>00092 
+<a name="l00093"></a>00093 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/irplib__polynomial_8c_source.html b/html/irplib__polynomial_8c_source.html
new file mode 100644
index 0000000..b9104b4
--- /dev/null
+++ b/html/irplib__polynomial_8c_source.html
@@ -0,0 +1,1251 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: irplib_polynomial.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>irplib_polynomial.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: irplib_polynomial.c,v 1.34 2012/02/03 14:54:06 llundin Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the ESO Common Pipeline Library</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2001-2004 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: llundin $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2012/02/03 14:54:06 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.34 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span>
+<a name="l00032"></a>00032 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                                   Includes</span>
+<a name="l00034"></a>00034 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 
+<a name="l00036"></a>00036 <span class="preprocessor">#include "irplib_polynomial.h"</span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include <assert.h></span>
+<a name="l00038"></a>00038 <span class="preprocessor">#include <math.h></span>
+<a name="l00039"></a>00039 <span class="comment">/* DBL_MAX: */</span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include <float.h></span>
+<a name="l00041"></a>00041 
+<a name="l00042"></a>00042 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00048"></a>00048 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00051"></a>00051 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00052"></a>00052 <span class="comment">                                   Macro definitions</span>
+<a name="l00053"></a>00053 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00054"></a>00054 
+<a name="l00055"></a>00055 <span class="preprocessor">#define IRPLIB_SWAP(a,b) { const double t=(a);(a)=(b);(b)=t; }</span>
+<a name="l00056"></a>00056 <span class="preprocessor"></span>
+<a name="l00057"></a>00057 <span class="preprocessor">#if 0</span>
+<a name="l00058"></a>00058 <span class="preprocessor"></span><span class="preprocessor">#define irplib_trace() cpl_msg_info(cpl_func, "%d: Trace", __LINE__)</span>
+<a name="l00059"></a>00059 <span class="preprocessor"></span><span class="preprocessor">#else</span>
+<a name="l00060"></a>00060 <span class="preprocessor"></span><span class="preprocessor">#define irplib_trace() </span><span class="comment">/* Trace */</span>
+<a name="l00061"></a>00061 <span class="preprocessor">#endif</span>
+<a name="l00062"></a>00062 <span class="preprocessor"></span>
+<a name="l00063"></a>00063 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00064"></a>00064 <span class="comment">                                   Static functions</span>
+<a name="l00065"></a>00065 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00066"></a>00066 
+<a name="l00067"></a>00067 <span class="keyword">static</span> <span class="keywordtype">double</span> irplib_polynomial_eval_2_max(<span class="keywordtype">double</span>, <span class="keywordtype">double</span>, <span class="keywordtype">double</span>, cpl_boolean,
+<a name="l00068"></a>00068                                            <span class="keywordtype">double</span>, <span class="keywordtype">double</span>);
+<a name="l00069"></a>00069 
+<a name="l00070"></a>00070 <span class="keyword">static</span> <span class="keywordtype">double</span> irplib_polynomial_eval_3_max(<span class="keywordtype">double</span>, <span class="keywordtype">double</span>, <span class="keywordtype">double</span>, <span class="keywordtype">double</span>,
+<a name="l00071"></a>00071                                            cpl_boolean, <span class="keywordtype">double</span>, <span class="keywordtype">double</span>, <span class="keywordtype">double</span>);
+<a name="l00072"></a>00072 
+<a name="l00073"></a>00073 
+<a name="l00074"></a>00074 <span class="keyword">static</span> cpl_boolean irplib_polynomial_solve_1d_2(<span class="keywordtype">double</span>, <span class="keywordtype">double</span>, <span class="keywordtype">double</span>,
+<a name="l00075"></a>00075                                                 <span class="keywordtype">double</span> *, <span class="keywordtype">double</span> *);
+<a name="l00076"></a>00076 <span class="keyword">static</span> cpl_boolean irplib_polynomial_solve_1d_3(<span class="keywordtype">double</span>, <span class="keywordtype">double</span>, <span class="keywordtype">double</span>, <span class="keywordtype">double</span>,
+<a name="l00077"></a>00077                                                 <span class="keywordtype">double</span> *, <span class="keywordtype">double</span> *, <span class="keywordtype">double</span> *,
+<a name="l00078"></a>00078                                                 cpl_boolean *,
+<a name="l00079"></a>00079                                                 cpl_boolean *);
+<a name="l00080"></a>00080 
+<a name="l00081"></a>00081 <span class="keyword">static</span> <span class="keywordtype">void</span> irplib_polynomial_solve_1d_31(<span class="keywordtype">double</span>, <span class="keywordtype">double</span>, <span class="keywordtype">double</span> *, <span class="keywordtype">double</span> *,
+<a name="l00082"></a>00082                                           <span class="keywordtype">double</span> *, cpl_boolean *);
+<a name="l00083"></a>00083 
+<a name="l00084"></a>00084 <span class="keyword">static</span> <span class="keywordtype">void</span> irplib_polynomial_solve_1d_32(<span class="keywordtype">double</span>, <span class="keywordtype">double</span>, <span class="keywordtype">double</span>, <span class="keywordtype">double</span> *,
+<a name="l00085"></a>00085                                           <span class="keywordtype">double</span> *, <span class="keywordtype">double</span> *, cpl_boolean *);
+<a name="l00086"></a>00086 
+<a name="l00087"></a>00087 <span class="keyword">static</span> <span class="keywordtype">void</span> irplib_polynomial_solve_1d_3r(<span class="keywordtype">double</span>, <span class="keywordtype">double</span>, <span class="keywordtype">double</span>, <span class="keywordtype">double</span>,
+<a name="l00088"></a>00088                                           <span class="keywordtype">double</span> *, <span class="keywordtype">double</span> *, <span class="keywordtype">double</span> *);
+<a name="l00089"></a>00089 
+<a name="l00090"></a>00090 <span class="keyword">static</span> <span class="keywordtype">void</span> irplib_polynomial_solve_1d_3c(<span class="keywordtype">double</span>, <span class="keywordtype">double</span>, <span class="keywordtype">double</span>,
+<a name="l00091"></a>00091                                           <span class="keywordtype">double</span>, <span class="keywordtype">double</span>, <span class="keywordtype">double</span>,
+<a name="l00092"></a>00092                                           <span class="keywordtype">double</span> *, <span class="keywordtype">double</span> *, <span class="keywordtype">double</span> *,
+<a name="l00093"></a>00093                                           cpl_boolean *, cpl_boolean *);
+<a name="l00094"></a>00094 
+<a name="l00095"></a>00095 <span class="keyword">static</span> cpl_error_code irplib_polynomial_solve_1d_4(<span class="keywordtype">double</span>, <span class="keywordtype">double</span>, <span class="keywordtype">double</span>,
+<a name="l00096"></a>00096                                                    <span class="keywordtype">double</span>, <span class="keywordtype">double</span>, cpl_size *,
+<a name="l00097"></a>00097                                                    <span class="keywordtype">double</span> *, <span class="keywordtype">double</span> *,
+<a name="l00098"></a>00098                                                    <span class="keywordtype">double</span> *, <span class="keywordtype">double</span> *);
+<a name="l00099"></a>00099 
+<a name="l00100"></a>00100 <span class="keyword">static</span> cpl_error_code irplib_polynomial_solve_1d_nonzero(cpl_polynomial *,
+<a name="l00101"></a>00101                                                          cpl_vector *,
+<a name="l00102"></a>00102                                                          cpl_size *);
+<a name="l00103"></a>00103 
+<a name="l00104"></a>00104 <span class="keyword">static</span> cpl_error_code irplib_polynomial_divide_1d_root(cpl_polynomial *, <span class="keywordtype">double</span>,
+<a name="l00105"></a>00105                                                        <span class="keywordtype">double</span> *);
+<a name="l00106"></a>00106 
+<a name="l00107"></a>00107 <span class="preprocessor">#ifdef IPRLIB_POLYNOMIAL_USE_MONOMIAL_ROOT</span>
+<a name="l00108"></a>00108 <span class="preprocessor"></span><span class="keyword">static</span> <span class="keywordtype">double</span> irplib_polynomial_depress_1d(cpl_polynomial *);
+<a name="l00109"></a>00109 <span class="preprocessor">#endif</span>
+<a name="l00110"></a>00110 <span class="preprocessor"></span>
+<a name="l00111"></a>00111 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00112"></a>00112 <span class="comment">                              Function codes</span>
+<a name="l00113"></a>00113 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00114"></a>00114 
+<a name="l00115"></a>00115 <span class="preprocessor">#if defined CPL_VERSION_CODE && CPL_VERSION_CODE > CPL_VERSION(5, 92, 0)</span>
+<a name="l00116"></a>00116 <span class="preprocessor"></span><span class="preprocessor">#else</span>
+<a name="l00117"></a>00117 <span class="preprocessor"></span>
+<a name="l00118"></a>00118 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00133"></a>00133 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00134"></a><a class="code" href="group__irplib__polynomial.html#ga90e13f05c9addc584f154279681d1853">00134</a> cpl_error_code <a class="code" href="group__irplib__polynomial.html#ga90e13f05c9addc584f154279681d1853" title="Add two polynomials of the same dimension.">irplib_polynomial_add</a>(cpl_polynomial * <span class="keyword">self</span>,
+<a name="l00135"></a>00135                                      <span class="keyword">const</span> cpl_polynomial * first,
+<a name="l00136"></a>00136                                      <span class="keyword">const</span> cpl_polynomial * second)
+<a name="l00137"></a>00137 {
+<a name="l00138"></a>00138     cpl_size       degree0 = cpl_polynomial_get_degree(<span class="keyword">self</span>);
+<a name="l00139"></a>00139     <span class="keyword">const</span> cpl_size degree1 = cpl_polynomial_get_degree(first);
+<a name="l00140"></a>00140     <span class="keyword">const</span> cpl_size degree2 = cpl_polynomial_get_degree(second);
+<a name="l00141"></a>00141     <span class="keyword">const</span> cpl_size maxdeg  = degree1 > degree2 ? degree1 : degree2;
+<a name="l00142"></a>00142 
+<a name="l00143"></a>00143 
+<a name="l00144"></a>00144     cpl_ensure_code(<span class="keyword">self</span>   != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00145"></a>00145     cpl_ensure_code(first  != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00146"></a>00146     cpl_ensure_code(second != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00147"></a>00147 
+<a name="l00148"></a>00148     cpl_ensure_code(cpl_polynomial_get_dimension(<span class="keyword">self</span>) ==
+<a name="l00149"></a>00149                     cpl_polynomial_get_dimension(first),
+<a name="l00150"></a>00150                     CPL_ERROR_INCOMPATIBLE_INPUT);
+<a name="l00151"></a>00151     cpl_ensure_code(cpl_polynomial_get_dimension(<span class="keyword">self</span>) ==
+<a name="l00152"></a>00152                     cpl_polynomial_get_dimension(second),
+<a name="l00153"></a>00153                     CPL_ERROR_INCOMPATIBLE_INPUT);
+<a name="l00154"></a>00154 
+<a name="l00155"></a>00155     <span class="comment">/* FIXME: */</span>
+<a name="l00156"></a>00156     cpl_ensure_code(cpl_polynomial_get_dimension(<span class="keyword">self</span>) == 1,
+<a name="l00157"></a>00157                     CPL_ERROR_UNSUPPORTED_MODE);
+<a name="l00158"></a>00158 
+<a name="l00159"></a>00159     <span class="keywordflow">if</span> (degree0 < maxdeg) {
+<a name="l00160"></a>00160         degree0 = maxdeg;
+<a name="l00161"></a>00161     } <span class="keywordflow">else</span> {
+<a name="l00162"></a>00162         <span class="comment">/* Reset coefficients in self as needed */</span>
+<a name="l00163"></a>00163         <span class="keywordflow">for</span> (; degree0 > maxdeg; degree0--) {
+<a name="l00164"></a>00164             cpl_polynomial_set_coeff(<span class="keyword">self</span>, &degree0, 0.0);
+<a name="l00165"></a>00165         }
+<a name="l00166"></a>00166     }
+<a name="l00167"></a>00167 
+<a name="l00168"></a>00168     <span class="comment">/* assert( degree0 == maxdeg ); */</span>
+<a name="l00169"></a>00169 
+<a name="l00170"></a>00170     <span class="keywordflow">for</span> (; degree0 >= 0; degree0--) {
+<a name="l00171"></a>00171         <span class="keyword">const</span> <span class="keywordtype">double</span> val1 = cpl_polynomial_get_coeff(first, &degree0);
+<a name="l00172"></a>00172         <span class="keyword">const</span> <span class="keywordtype">double</span> val2 = cpl_polynomial_get_coeff(second, &degree0);
+<a name="l00173"></a>00173         cpl_polynomial_set_coeff(<span class="keyword">self</span>, &degree0, val1 + val2);
+<a name="l00174"></a>00174     }
+<a name="l00175"></a>00175 
+<a name="l00176"></a>00176     <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l00177"></a>00177 }
+<a name="l00178"></a>00178 
+<a name="l00179"></a>00179 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00194"></a>00194 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00195"></a><a class="code" href="group__irplib__polynomial.html#ga0e83ae3c9e7accb70fdfe1aca030e084">00195</a> cpl_error_code <a class="code" href="group__irplib__polynomial.html#ga0e83ae3c9e7accb70fdfe1aca030e084" title="Subtract two polynomials of the same dimension.">irplib_polynomial_subtract</a>(cpl_polynomial * <span class="keyword">self</span>,
+<a name="l00196"></a>00196                                           <span class="keyword">const</span> cpl_polynomial * first,
+<a name="l00197"></a>00197                                           <span class="keyword">const</span> cpl_polynomial * second)
+<a name="l00198"></a>00198 {
+<a name="l00199"></a>00199     cpl_size       degree0 = cpl_polynomial_get_degree(<span class="keyword">self</span>);
+<a name="l00200"></a>00200     <span class="keyword">const</span> cpl_size degree1 = cpl_polynomial_get_degree(first);
+<a name="l00201"></a>00201     <span class="keyword">const</span> cpl_size degree2 = cpl_polynomial_get_degree(second);
+<a name="l00202"></a>00202     <span class="keyword">const</span> cpl_size maxdeg  = degree1 > degree2 ? degree1 : degree2;
+<a name="l00203"></a>00203 
+<a name="l00204"></a>00204 
+<a name="l00205"></a>00205     cpl_ensure_code(<span class="keyword">self</span>   != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00206"></a>00206     cpl_ensure_code(first  != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00207"></a>00207     cpl_ensure_code(second != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00208"></a>00208 
+<a name="l00209"></a>00209     cpl_ensure_code(cpl_polynomial_get_dimension(<span class="keyword">self</span>) ==
+<a name="l00210"></a>00210                     cpl_polynomial_get_dimension(first),
+<a name="l00211"></a>00211                     CPL_ERROR_INCOMPATIBLE_INPUT);
+<a name="l00212"></a>00212     cpl_ensure_code(cpl_polynomial_get_dimension(<span class="keyword">self</span>) ==
+<a name="l00213"></a>00213                     cpl_polynomial_get_dimension(second),
+<a name="l00214"></a>00214                     CPL_ERROR_INCOMPATIBLE_INPUT);
+<a name="l00215"></a>00215 
+<a name="l00216"></a>00216     <span class="comment">/* FIXME: */</span>
+<a name="l00217"></a>00217     cpl_ensure_code(cpl_polynomial_get_dimension(<span class="keyword">self</span>) == 1,
+<a name="l00218"></a>00218                     CPL_ERROR_UNSUPPORTED_MODE);
+<a name="l00219"></a>00219 
+<a name="l00220"></a>00220     <span class="keywordflow">if</span> (degree0 < maxdeg) {
+<a name="l00221"></a>00221         degree0 = maxdeg;
+<a name="l00222"></a>00222     } <span class="keywordflow">else</span> {
+<a name="l00223"></a>00223         <span class="comment">/* Reset coefficients in self as needed */</span>
+<a name="l00224"></a>00224         <span class="keywordflow">for</span> (; degree0 > maxdeg; degree0--) {
+<a name="l00225"></a>00225             cpl_polynomial_set_coeff(<span class="keyword">self</span>, &degree0, 0.0);
+<a name="l00226"></a>00226         }
+<a name="l00227"></a>00227     }
+<a name="l00228"></a>00228 
+<a name="l00229"></a>00229     <span class="comment">/* assert( degree0 == maxdeg ); */</span>
+<a name="l00230"></a>00230 
+<a name="l00231"></a>00231     <span class="keywordflow">for</span> (; degree0 >= 0; degree0--) {
+<a name="l00232"></a>00232         <span class="keyword">const</span> <span class="keywordtype">double</span> val1 = cpl_polynomial_get_coeff(first, &degree0);
+<a name="l00233"></a>00233         <span class="keyword">const</span> <span class="keywordtype">double</span> val2 = cpl_polynomial_get_coeff(second, &degree0);
+<a name="l00234"></a>00234         cpl_polynomial_set_coeff(<span class="keyword">self</span>, &degree0, val1 - val2);
+<a name="l00235"></a>00235     }
+<a name="l00236"></a>00236 
+<a name="l00237"></a>00237     <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l00238"></a>00238 }
+<a name="l00239"></a>00239 
+<a name="l00240"></a>00240 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00252"></a>00252 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00253"></a><a class="code" href="group__irplib__polynomial.html#ga55c030413e6ef112753b280ad5213786">00253</a> cpl_error_code <a class="code" href="group__irplib__polynomial.html#ga55c030413e6ef112753b280ad5213786" title="Multiply a polynomial with a scalar.">irplib_polynomial_multiply_scalar</a>(cpl_polynomial * <span class="keyword">self</span>,
+<a name="l00254"></a>00254                                                  <span class="keyword">const</span> cpl_polynomial * other,
+<a name="l00255"></a>00255                                                  <span class="keywordtype">double</span> factor)
+<a name="l00256"></a>00256 {
+<a name="l00257"></a>00257 
+<a name="l00258"></a>00258     <span class="keyword">const</span> cpl_size maxdeg  = cpl_polynomial_get_degree(other);
+<a name="l00259"></a>00259     <span class="keyword">const</span> cpl_size zerodeg = cpl_polynomial_get_degree(<span class="keyword">self</span>);
+<a name="l00260"></a>00260     cpl_size       degree;
+<a name="l00261"></a>00261 
+<a name="l00262"></a>00262     cpl_ensure_code(<span class="keyword">self</span>  != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00263"></a>00263     cpl_ensure_code(other != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00264"></a>00264 
+<a name="l00265"></a>00265     cpl_ensure_code(cpl_polynomial_get_dimension(<span class="keyword">self</span>) == 1,
+<a name="l00266"></a>00266                     CPL_ERROR_UNSUPPORTED_MODE);
+<a name="l00267"></a>00267     cpl_ensure_code(cpl_polynomial_get_dimension(other) == 1,
+<a name="l00268"></a>00268                     CPL_ERROR_UNSUPPORTED_MODE);
+<a name="l00269"></a>00269 
+<a name="l00270"></a>00270     <span class="keywordflow">for</span> (degree = 0; degree <= maxdeg; degree++) {
+<a name="l00271"></a>00271         <span class="keyword">const</span> <span class="keywordtype">double</span> val = factor * cpl_polynomial_get_coeff(other, &degree);
+<a name="l00272"></a>00272         cpl_polynomial_set_coeff(<span class="keyword">self</span>, &degree, val);
+<a name="l00273"></a>00273     }
+<a name="l00274"></a>00274 
+<a name="l00275"></a>00275     <span class="comment">/* Reset coefficients in self as needed */</span>
+<a name="l00276"></a>00276     <span class="keywordflow">for</span> (; degree <= zerodeg; degree++) {
+<a name="l00277"></a>00277         cpl_polynomial_set_coeff(<span class="keyword">self</span>, &zerodeg, 0.0);
+<a name="l00278"></a>00278     }
+<a name="l00279"></a>00279 
+<a name="l00280"></a>00280     <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l00281"></a>00281 }
+<a name="l00282"></a>00282 <span class="preprocessor">#endif</span>
+<a name="l00283"></a>00283 <span class="preprocessor"></span><span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00309"></a>00309 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00310"></a><a class="code" href="group__irplib__polynomial.html#ga87e84d69eadbde803fce3c3cbdedf385">00310</a> cpl_error_code <a class="code" href="group__irplib__polynomial.html#ga87e84d69eadbde803fce3c3cbdedf385" title="Compute all n roots of p(x) = 0, where p(x) is of degree n, n &gt; 0.">irplib_polynomial_solve_1d_all</a>(<span class="keyword">const</span> cpl_polynomial * <span class="keyword">self</span>,
+<a name="l00311"></a>00311                                               cpl_vector * roots,
+<a name="l00312"></a>00312                                               cpl_size * preal)
+<a name="l00313"></a>00313 {
+<a name="l00314"></a>00314 
+<a name="l00315"></a>00315     cpl_error_code error = CPL_ERROR_NONE;
+<a name="l00316"></a>00316     cpl_polynomial * p;
+<a name="l00317"></a>00317 
+<a name="l00318"></a>00318     cpl_ensure_code(<span class="keyword">self</span>  != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00319"></a>00319     cpl_ensure_code(roots != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00320"></a>00320     cpl_ensure_code(preal != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00321"></a>00321     cpl_ensure_code(cpl_polynomial_get_dimension(<span class="keyword">self</span>) == 1,
+<a name="l00322"></a>00322                     CPL_ERROR_INVALID_TYPE);
+<a name="l00323"></a>00323     cpl_ensure_code(cpl_polynomial_get_degree(<span class="keyword">self</span>) > 0,
+<a name="l00324"></a>00324                     CPL_ERROR_DATA_NOT_FOUND);
+<a name="l00325"></a>00325     cpl_ensure_code(cpl_polynomial_get_degree(<span class="keyword">self</span>) ==
+<a name="l00326"></a>00326                     cpl_vector_get_size(roots), CPL_ERROR_INCOMPATIBLE_INPUT);
+<a name="l00327"></a>00327 
+<a name="l00328"></a>00328     *preal = 0;
+<a name="l00329"></a>00329 
+<a name="l00330"></a>00330     p = cpl_polynomial_duplicate(<span class="keyword">self</span>);
+<a name="l00331"></a>00331 
+<a name="l00332"></a>00332     error = irplib_polynomial_solve_1d_nonzero(p, roots, preal);
+<a name="l00333"></a>00333 
+<a name="l00334"></a>00334     cpl_polynomial_delete(p);
+<a name="l00335"></a>00335 
+<a name="l00336"></a>00336     <span class="keywordflow">return</span> error;
+<a name="l00337"></a>00337 
+<a name="l00338"></a>00338 }
+<a name="l00339"></a>00339 
+<a name="l00342"></a>00342 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00368"></a>00368 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00369"></a>00369 <span class="keyword">static</span> cpl_error_code irplib_polynomial_solve_1d_nonzero(cpl_polynomial * <span class="keyword">self</span>,
+<a name="l00370"></a>00370                                                          cpl_vector * roots,
+<a name="l00371"></a>00371                                                          cpl_size * preal)
+<a name="l00372"></a>00372 {
+<a name="l00373"></a>00373     cpl_error_code error   = CPL_ERROR_NONE;
+<a name="l00374"></a>00374     <span class="keyword">const</span> cpl_size ncoeffs = 1 + cpl_polynomial_get_degree(<span class="keyword">self</span>);
+<a name="l00375"></a>00375 
+<a name="l00376"></a>00376     cpl_ensure_code(<span class="keyword">self</span>  != NULL,  CPL_ERROR_NULL_INPUT);
+<a name="l00377"></a>00377     cpl_ensure_code(roots != NULL,  CPL_ERROR_NULL_INPUT);
+<a name="l00378"></a>00378     cpl_ensure_code(preal != NULL,  CPL_ERROR_NULL_INPUT);
+<a name="l00379"></a>00379     cpl_ensure_code(cpl_polynomial_get_dimension(<span class="keyword">self</span>) == 1,
+<a name="l00380"></a>00380                     CPL_ERROR_INVALID_TYPE);
+<a name="l00381"></a>00381     cpl_ensure_code(ncoeffs   > 1,  CPL_ERROR_DATA_NOT_FOUND);
+<a name="l00382"></a>00382     cpl_ensure_code(*preal >= 0,    CPL_ERROR_ILLEGAL_INPUT);
+<a name="l00383"></a>00383     cpl_ensure_code(ncoeffs + *preal == 1+cpl_vector_get_size(roots),
+<a name="l00384"></a>00384                     CPL_ERROR_INCOMPATIBLE_INPUT);
+<a name="l00385"></a>00385 
+<a name="l00386"></a>00386     <span class="keywordflow">switch</span> (ncoeffs) {
+<a name="l00387"></a>00387 
+<a name="l00388"></a>00388     <span class="keywordflow">case</span> 2 : {
+<a name="l00389"></a>00389         <span class="keyword">const</span> cpl_size i1 = 1;
+<a name="l00390"></a>00390         <span class="keyword">const</span> cpl_size i0 = 0;
+<a name="l00391"></a>00391         <span class="keyword">const</span> <span class="keywordtype">double</span>   p1 = cpl_polynomial_get_coeff(<span class="keyword">self</span>, &i1);
+<a name="l00392"></a>00392         <span class="keyword">const</span> <span class="keywordtype">double</span>   p0 = cpl_polynomial_get_coeff(<span class="keyword">self</span>, &i0);
+<a name="l00393"></a>00393 
+<a name="l00394"></a>00394         cpl_vector_set(roots, (*preal)++, -p0/p1);
+<a name="l00395"></a>00395         <span class="keywordflow">break</span>;
+<a name="l00396"></a>00396     }
+<a name="l00397"></a>00397     <span class="keywordflow">case</span> 3 : {
+<a name="l00398"></a>00398         <span class="keyword">const</span> cpl_size i2 = 2;
+<a name="l00399"></a>00399         <span class="keyword">const</span> cpl_size i1 = 1;
+<a name="l00400"></a>00400         <span class="keyword">const</span> cpl_size i0 = 0;
+<a name="l00401"></a>00401         <span class="keyword">const</span> <span class="keywordtype">double</span>   p2 = cpl_polynomial_get_coeff(<span class="keyword">self</span>, &i2);
+<a name="l00402"></a>00402         <span class="keyword">const</span> <span class="keywordtype">double</span>   p1 = cpl_polynomial_get_coeff(<span class="keyword">self</span>, &i1);
+<a name="l00403"></a>00403         <span class="keyword">const</span> <span class="keywordtype">double</span>   p0 = cpl_polynomial_get_coeff(<span class="keyword">self</span>, &i0);
+<a name="l00404"></a>00404         <span class="keywordtype">double</span>         x1, x2;
+<a name="l00405"></a>00405 
+<a name="l00406"></a>00406         <span class="keywordflow">if</span> (irplib_polynomial_solve_1d_2(p2, p1, p0, &x1, &x2)) {
+<a name="l00407"></a>00407             <span class="comment">/* This is the complex root in the upper imaginary half-plane */</span>
+<a name="l00408"></a>00408             cpl_vector_set(roots, (*preal)  , x1);
+<a name="l00409"></a>00409             cpl_vector_set(roots, (*preal)+1, x2);
+<a name="l00410"></a>00410         } <span class="keywordflow">else</span> {
+<a name="l00411"></a>00411             cpl_vector_set(roots, (*preal)++, x1);
+<a name="l00412"></a>00412             cpl_vector_set(roots, (*preal)++, x2);
+<a name="l00413"></a>00413         }
+<a name="l00414"></a>00414         <span class="keywordflow">break</span>;
+<a name="l00415"></a>00415     }
+<a name="l00416"></a>00416     <span class="keywordflow">case</span> 4 : {
+<a name="l00417"></a>00417         <span class="keyword">const</span> cpl_size i3 = 3;
+<a name="l00418"></a>00418         <span class="keyword">const</span> cpl_size i2 = 2;
+<a name="l00419"></a>00419         <span class="keyword">const</span> cpl_size i1 = 1;
+<a name="l00420"></a>00420         <span class="keyword">const</span> cpl_size i0 = 0;
+<a name="l00421"></a>00421         <span class="keyword">const</span> <span class="keywordtype">double</span>   p3 = cpl_polynomial_get_coeff(<span class="keyword">self</span>, &i3);
+<a name="l00422"></a>00422         <span class="keyword">const</span> <span class="keywordtype">double</span>   p2 = cpl_polynomial_get_coeff(<span class="keyword">self</span>, &i2);
+<a name="l00423"></a>00423         <span class="keyword">const</span> <span class="keywordtype">double</span>   p1 = cpl_polynomial_get_coeff(<span class="keyword">self</span>, &i1);
+<a name="l00424"></a>00424         <span class="keyword">const</span> <span class="keywordtype">double</span>   p0 = cpl_polynomial_get_coeff(<span class="keyword">self</span>, &i0);
+<a name="l00425"></a>00425         <span class="keywordtype">double</span>         x1, x2, x3;
+<a name="l00426"></a>00426 
+<a name="l00427"></a>00427         <span class="keywordflow">if</span> (irplib_polynomial_solve_1d_3(p3, p2, p1, p0, &x1, &x2, &x3,
+<a name="l00428"></a>00428                                          NULL, NULL)) {
+<a name="l00429"></a>00429             cpl_vector_set(roots, (*preal)++, x1);
+<a name="l00430"></a>00430             <span class="comment">/* This is the complex root in the upper imaginary half-plane */</span>
+<a name="l00431"></a>00431             cpl_vector_set(roots, (*preal)  , x2);
+<a name="l00432"></a>00432             cpl_vector_set(roots, (*preal)+1, x3);
+<a name="l00433"></a>00433         } <span class="keywordflow">else</span> {
+<a name="l00434"></a>00434             cpl_vector_set(roots, (*preal)++, x1);
+<a name="l00435"></a>00435             cpl_vector_set(roots, (*preal)++, x2);
+<a name="l00436"></a>00436             cpl_vector_set(roots, (*preal)++, x3);
+<a name="l00437"></a>00437         }
+<a name="l00438"></a>00438         <span class="keywordflow">break</span>;
+<a name="l00439"></a>00439     }
+<a name="l00440"></a>00440     <span class="keywordflow">case</span> 5 : {
+<a name="l00441"></a>00441         <span class="keyword">const</span> cpl_size i4 = 4;
+<a name="l00442"></a>00442         <span class="keyword">const</span> cpl_size i3 = 3;
+<a name="l00443"></a>00443         <span class="keyword">const</span> cpl_size i2 = 2;
+<a name="l00444"></a>00444         <span class="keyword">const</span> cpl_size i1 = 1;
+<a name="l00445"></a>00445         <span class="keyword">const</span> cpl_size i0 = 0;
+<a name="l00446"></a>00446         <span class="keyword">const</span> <span class="keywordtype">double</span>   p4 = cpl_polynomial_get_coeff(<span class="keyword">self</span>, &i4);
+<a name="l00447"></a>00447         <span class="keyword">const</span> <span class="keywordtype">double</span>   p3 = cpl_polynomial_get_coeff(<span class="keyword">self</span>, &i3);
+<a name="l00448"></a>00448         <span class="keyword">const</span> <span class="keywordtype">double</span>   p2 = cpl_polynomial_get_coeff(<span class="keyword">self</span>, &i2);
+<a name="l00449"></a>00449         <span class="keyword">const</span> <span class="keywordtype">double</span>   p1 = cpl_polynomial_get_coeff(<span class="keyword">self</span>, &i1);
+<a name="l00450"></a>00450         <span class="keyword">const</span> <span class="keywordtype">double</span>   p0 = cpl_polynomial_get_coeff(<span class="keyword">self</span>, &i0);
+<a name="l00451"></a>00451         <span class="keywordtype">double</span>         x1, x2, x3, x4;
+<a name="l00452"></a>00452         cpl_size       nreal;
+<a name="l00453"></a>00453 
+<a name="l00454"></a>00454         error = irplib_polynomial_solve_1d_4(p4, p3, p2, p1, p0, &nreal,
+<a name="l00455"></a>00455                                              &x1, &x2, &x3, &x4);
+<a name="l00456"></a>00456         <span class="keywordflow">if</span> (!error) {
+<a name="l00457"></a>00457             cpl_vector_set(roots, (*preal)  , x1);
+<a name="l00458"></a>00458             cpl_vector_set(roots, (*preal)+1, x2);
+<a name="l00459"></a>00459             cpl_vector_set(roots, (*preal)+2, x3);
+<a name="l00460"></a>00460             cpl_vector_set(roots, (*preal)+3, x4);
+<a name="l00461"></a>00461 
+<a name="l00462"></a>00462             *preal += nreal;
+<a name="l00463"></a>00463         }
+<a name="l00464"></a>00464         <span class="keywordflow">break</span>;
+<a name="l00465"></a>00465     }
+<a name="l00466"></a>00466 
+<a name="l00467"></a>00467     <span class="keywordflow">default</span>: {
+<a name="l00468"></a>00468 
+<a name="l00469"></a>00469         <span class="comment">/* Try to reduce the problem by finding a single root */</span>
+<a name="l00470"></a>00470 <span class="preprocessor">#ifndef IPRLIB_POLYNOMIAL_USE_MONOMIAL_ROOT</span>
+<a name="l00471"></a>00471 <span class="preprocessor"></span>        <span class="keyword">const</span> cpl_size    n0 = ncoeffs-1;
+<a name="l00472"></a>00472         <span class="keyword">const</span> <span class="keywordtype">double</span> pn0 = cpl_polynomial_get_coeff(<span class="keyword">self</span>, &n0);
+<a name="l00473"></a>00473         <span class="keyword">const</span> cpl_size    n1 = ncoeffs-2;
+<a name="l00474"></a>00474         <span class="keyword">const</span> <span class="keywordtype">double</span> pn1 = cpl_polynomial_get_coeff(<span class="keyword">self</span>, &n1);
+<a name="l00475"></a>00475         <span class="comment">/* First guess of root is the root average.</span>
+<a name="l00476"></a>00476 <span class="comment">           FIXME: May need refinement, e.g. via bisection */</span>
+<a name="l00477"></a>00477         <span class="keyword">const</span> <span class="keywordtype">double</span> rmean = -pn1 / (pn0 * n0);
+<a name="l00478"></a>00478         <span class="keywordtype">double</span> root = rmean;
+<a name="l00479"></a>00479 <span class="preprocessor">#else</span>
+<a name="l00480"></a>00480 <span class="preprocessor"></span>        <span class="comment">/* Try an analytical solution to a (shifted) monomial */</span>
+<a name="l00481"></a>00481         cpl_polynomial * copy = cpl_polynomial_duplicate(<span class="keyword">self</span>);
+<a name="l00482"></a>00482         <span class="keyword">const</span> cpl_size    i0 = 0;
+<a name="l00483"></a>00483         <span class="keyword">const</span> <span class="keywordtype">double</span> rmean = irplib_polynomial_depress_1d(copy);
+<a name="l00484"></a>00484         <span class="keyword">const</span> <span class="keywordtype">double</span> c0 = cpl_polynomial_get_coeff(copy, &i0);
+<a name="l00485"></a>00485         <span class="keywordtype">double</span> root = rmean + ((n0&1) && c0 < 0.0 ? -1.0 : 1.0)
+<a name="l00486"></a>00486             * pow(fabs(c0), 1.0/n0);
+<a name="l00487"></a>00487 
+<a name="l00488"></a>00488         cpl_polynomial_delete(copy);
+<a name="l00489"></a>00489 <span class="preprocessor">#endif</span>
+<a name="l00490"></a>00490 <span class="preprocessor"></span>
+<a name="l00491"></a>00491         error = cpl_polynomial_solve_1d(<span class="keyword">self</span>, root, &root, 1);
+<a name="l00492"></a>00492 
+<a name="l00493"></a>00493         <span class="keywordflow">if</span> (!error) {
+<a name="l00494"></a>00494 
+<a name="l00495"></a>00495             cpl_vector_set(roots, (*preal)++, root);
+<a name="l00496"></a>00496 
+<a name="l00497"></a>00497             irplib_polynomial_divide_1d_root(<span class="keyword">self</span>, root, NULL);
+<a name="l00498"></a>00498 
+<a name="l00499"></a>00499             error = irplib_polynomial_solve_1d_nonzero(<span class="keyword">self</span>, roots, preal);
+<a name="l00500"></a>00500 
+<a name="l00501"></a>00501             <span class="keywordflow">if</span> (!error && *preal > 1) {
+<a name="l00502"></a>00502                 <span class="comment">/* Sort the real roots */</span>
+<a name="l00503"></a>00503 
+<a name="l00504"></a>00504                 <span class="comment">/* FIXME: Assumes that all roots found so far are real */</span>
+<a name="l00505"></a>00505 
+<a name="l00506"></a>00506                 cpl_vector * reals = cpl_vector_wrap(*preal,
+<a name="l00507"></a>00507                                                      cpl_vector_get_data(roots));
+<a name="l00508"></a>00508                 cpl_vector_sort(reals, 1);
+<a name="l00509"></a>00509                 (void)cpl_vector_unwrap(reals);
+<a name="l00510"></a>00510             }
+<a name="l00511"></a>00511         }
+<a name="l00512"></a>00512         <span class="keywordflow">break</span>;
+<a name="l00513"></a>00513     }
+<a name="l00514"></a>00514     }
+<a name="l00515"></a>00515 
+<a name="l00516"></a>00516     <span class="keywordflow">return</span> error;
+<a name="l00517"></a>00517 }
+<a name="l00518"></a>00518 
+<a name="l00519"></a>00519 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00531"></a>00531 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00532"></a>00532 <span class="keyword">static</span> cpl_boolean irplib_polynomial_solve_1d_2(<span class="keywordtype">double</span> p2, <span class="keywordtype">double</span> p1, <span class="keywordtype">double</span> p0,
+<a name="l00533"></a>00533                                                 <span class="keywordtype">double</span> * px1,
+<a name="l00534"></a>00534                                                 <span class="keywordtype">double</span> * px2) {
+<a name="l00535"></a>00535 
+<a name="l00536"></a>00536     <span class="keyword">const</span> <span class="keywordtype">double</span> sqrtD = sqrt(fabs(p1 * p1 - 4.0 * p2 * p0));
+<a name="l00537"></a>00537     cpl_boolean is_complex = CPL_FALSE;
+<a name="l00538"></a>00538     <span class="keywordtype">double</span> x1 = -0.5 * p1 / p2; <span class="comment">/* Double root */</span>
+<a name="l00539"></a>00539     <span class="keywordtype">double</span> x2;
+<a name="l00540"></a>00540 
+<a name="l00541"></a>00541     <span class="comment">/* Compute residual, assuming D == 0 */</span>
+<a name="l00542"></a>00542     <span class="keywordtype">double</span> res0 = irplib_polynomial_eval_2_max(p2, p1, p0, CPL_FALSE, x1, x1);
+<a name="l00543"></a>00543     <span class="keywordtype">double</span> res;
+<a name="l00544"></a>00544 
+<a name="l00545"></a>00545     assert(px1 != NULL );
+<a name="l00546"></a>00546     assert(px2 != NULL );
+<a name="l00547"></a>00547 
+<a name="l00548"></a>00548     *px2 = *px1 = x1;
+<a name="l00549"></a>00549 
+<a name="l00550"></a>00550     <span class="comment">/* Compute residual, assuming D > 0 */</span>
+<a name="l00551"></a>00551 
+<a name="l00552"></a>00552     <span class="comment">/* x1 is the root with largest absolute value */</span>
+<a name="l00553"></a>00553     <span class="keywordflow">if</span> (p1 > 0.0) {
+<a name="l00554"></a>00554         x1 = -0.5 * (p1 + sqrtD);
+<a name="l00555"></a>00555         irplib_trace(); <span class="comment">/* OK */</span>
+<a name="l00556"></a>00556     } <span class="keywordflow">else</span> {
+<a name="l00557"></a>00557         x1 = -0.5 * (p1 - sqrtD);
+<a name="l00558"></a>00558         irplib_trace(); <span class="comment">/* OK */</span>
+<a name="l00559"></a>00559     }
+<a name="l00560"></a>00560     <span class="comment">/* Compute smaller root via division to avoid</span>
+<a name="l00561"></a>00561 <span class="comment">       loss of precision due to cancellation */</span>
+<a name="l00562"></a>00562     x2 = p0 / x1;
+<a name="l00563"></a>00563     x1 /= p2; <span class="comment">/* Scale x1 with leading coefficient */</span>
+<a name="l00564"></a>00564 
+<a name="l00565"></a>00565     res = irplib_polynomial_eval_2_max(p2, p1, p0, CPL_FALSE, x1, x2);
+<a name="l00566"></a>00566 
+<a name="l00567"></a>00567     <span class="keywordflow">if</span> (res < res0) {
+<a name="l00568"></a>00568         res0 = res;
+<a name="l00569"></a>00569         <span class="keywordflow">if</span> (x2 > x1) {
+<a name="l00570"></a>00570             *px1 = x1;
+<a name="l00571"></a>00571             *px2 = x2;
+<a name="l00572"></a>00572             irplib_trace(); <span class="comment">/* OK */</span>
+<a name="l00573"></a>00573         } <span class="keywordflow">else</span> {
+<a name="l00574"></a>00574             *px1 = x2;
+<a name="l00575"></a>00575             *px2 = x1;
+<a name="l00576"></a>00576             irplib_trace(); <span class="comment">/* OK */</span>
+<a name="l00577"></a>00577         }
+<a name="l00578"></a>00578     }
+<a name="l00579"></a>00579 
+<a name="l00580"></a>00580     <span class="comment">/* Compute residual, assuming D < 0 */</span>
+<a name="l00581"></a>00581 
+<a name="l00582"></a>00582     x1 = -0.5 * p1 / p2;          <span class="comment">/* Real part of complex root */</span>
+<a name="l00583"></a>00583     x2 =  0.5 * sqrtD / fabs(p2); <span class="comment">/* Positive, imaginary part of root */</span>
+<a name="l00584"></a>00584 
+<a name="l00585"></a>00585     res  = irplib_polynomial_eval_2_max(p2, p1, p0, CPL_TRUE,  x1, x2);
+<a name="l00586"></a>00586 
+<a name="l00587"></a>00587     <span class="keywordflow">if</span> (res < res0) {
+<a name="l00588"></a>00588         *px1 = x1;
+<a name="l00589"></a>00589         *px2 = x2;
+<a name="l00590"></a>00590         is_complex = CPL_TRUE;
+<a name="l00591"></a>00591         irplib_trace(); <span class="comment">/* OK */</span>
+<a name="l00592"></a>00592     }
+<a name="l00593"></a>00593 
+<a name="l00594"></a>00594     <span class="keywordflow">return</span> is_complex;
+<a name="l00595"></a>00595 
+<a name="l00596"></a>00596 }
+<a name="l00597"></a>00597 
+<a name="l00598"></a>00598 
+<a name="l00599"></a>00599 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00612"></a>00612 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00613"></a>00613 <span class="keyword">static</span> <span class="keywordtype">double</span> irplib_polynomial_eval_2_max(<span class="keywordtype">double</span> p2, <span class="keywordtype">double</span> p1, <span class="keywordtype">double</span> p0,
+<a name="l00614"></a>00614                                            cpl_boolean is_c,
+<a name="l00615"></a>00615                                            <span class="keywordtype">double</span> x1, <span class="keywordtype">double</span> x2)
+<a name="l00616"></a>00616 {
+<a name="l00617"></a>00617     <span class="keywordtype">double</span> res;
+<a name="l00618"></a>00618 
+<a name="l00619"></a>00619     <span class="keywordflow">if</span> (is_c) {
+<a name="l00620"></a>00620         res = fabs(p0 + x1 * (p1 + x1 * p2) - p2 * x2 * x2);
+<a name="l00621"></a>00621         irplib_trace(); <span class="comment">/* OK */</span>
+<a name="l00622"></a>00622     } <span class="keywordflow">else</span> {
+<a name="l00623"></a>00623         <span class="keyword">const</span> <span class="keywordtype">double</span> r1 = fabs(p0 + x1 * (p1 + x1 * p2));
+<a name="l00624"></a>00624         <span class="keyword">const</span> <span class="keywordtype">double</span> r2 = fabs(p0 + x2 * (p1 + x2 * p2));
+<a name="l00625"></a>00625 
+<a name="l00626"></a>00626         res = r1 > r2 ? r1 : r2;
+<a name="l00627"></a>00627         irplib_trace(); <span class="comment">/* OK */</span>
+<a name="l00628"></a>00628     }
+<a name="l00629"></a>00629 
+<a name="l00630"></a>00630     <span class="keywordflow">return</span> res;
+<a name="l00631"></a>00631 }
+<a name="l00632"></a>00632 
+<a name="l00633"></a>00633 
+<a name="l00634"></a>00634 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00649"></a>00649 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00650"></a>00650 <span class="keyword">static</span> <span class="keywordtype">double</span> irplib_polynomial_eval_3_max(<span class="keywordtype">double</span> p3, <span class="keywordtype">double</span> p2,
+<a name="l00651"></a>00651                                            <span class="keywordtype">double</span> p1, <span class="keywordtype">double</span> p0,
+<a name="l00652"></a>00652                                            cpl_boolean is_c,
+<a name="l00653"></a>00653                                            <span class="keywordtype">double</span> x1, <span class="keywordtype">double</span> x2, <span class="keywordtype">double</span> x3)
+<a name="l00654"></a>00654 {
+<a name="l00655"></a>00655     <span class="keyword">const</span> <span class="keywordtype">double</span> r1 = fabs(p0 + x1 * (p1 + x1 * (p2 + x1 * p3)));
+<a name="l00656"></a>00656     <span class="keywordtype">double</span> res;
+<a name="l00657"></a>00657 
+<a name="l00658"></a>00658     <span class="keywordflow">if</span> (is_c) {
+<a name="l00659"></a>00659         <span class="keyword">const</span> <span class="keywordtype">double</span> r2 = fabs(p0 + x2 * (p1 + x2 * (p2 + x2 * p3))
+<a name="l00660"></a>00660                                - x3 * x3 * ( 3.0 * p3 * x2 + p2));
+<a name="l00661"></a>00661 
+<a name="l00662"></a>00662         res = r1 > r2 ? r1 : r2;
+<a name="l00663"></a>00663         irplib_trace(); <span class="comment">/* OK */</span>
+<a name="l00664"></a>00664     } <span class="keywordflow">else</span> {
+<a name="l00665"></a>00665         <span class="keyword">const</span> <span class="keywordtype">double</span> r2 = fabs(p0 + x2 * (p1 + x2 * (p2 + x2 * p3)));
+<a name="l00666"></a>00666         <span class="keyword">const</span> <span class="keywordtype">double</span> r3 = fabs(p0 + x3 * (p1 + x3 * (p2 + x3 * p3)));
+<a name="l00667"></a>00667         res = r1 > r2 ? (r1 > r3 ? r1 : r3) : (r2 > r3 ? r2 : r3);
+<a name="l00668"></a>00668         irplib_trace(); <span class="comment">/* OK */</span>
+<a name="l00669"></a>00669     }
+<a name="l00670"></a>00670 
+<a name="l00671"></a>00671     <span class="comment">/* cpl_msg_info(cpl_func, "%d: %g (%g)", __LINE__, res, r1); */</span>
+<a name="l00672"></a>00672 
+<a name="l00673"></a>00673     <span class="keywordflow">return</span> res;
+<a name="l00674"></a>00674 }
+<a name="l00675"></a>00675 
+<a name="l00676"></a>00676 
+<a name="l00677"></a>00677 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00696"></a>00696 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00697"></a>00697 <span class="keyword">static</span> cpl_boolean irplib_polynomial_solve_1d_3(<span class="keywordtype">double</span> p3, <span class="keywordtype">double</span> p2, <span class="keywordtype">double</span> p1,
+<a name="l00698"></a>00698                                                 <span class="keywordtype">double</span> p0,
+<a name="l00699"></a>00699                                                 <span class="keywordtype">double</span> * px1,
+<a name="l00700"></a>00700                                                 <span class="keywordtype">double</span> * px2,
+<a name="l00701"></a>00701                                                 <span class="keywordtype">double</span> * px3,
+<a name="l00702"></a>00702                                                 cpl_boolean * pdbl1,
+<a name="l00703"></a>00703                                                 cpl_boolean * pdbl2) {
+<a name="l00704"></a>00704     cpl_boolean is_complex = CPL_FALSE;
+<a name="l00705"></a>00705     <span class="keyword">const</span> <span class="keywordtype">double</span> a = p2/p3;
+<a name="l00706"></a>00706     <span class="keyword">const</span> <span class="keywordtype">double</span> b = p1/p3;
+<a name="l00707"></a>00707     <span class="keyword">const</span> <span class="keywordtype">double</span> c = p0/p3;
+<a name="l00708"></a>00708 
+<a name="l00709"></a>00709     <span class="keyword">const</span> <span class="keywordtype">double</span> q = (a * a - 3.0 * b);
+<a name="l00710"></a>00710     <span class="keyword">const</span> <span class="keywordtype">double</span> r = (a * (2.0 * a * a - 9.0 * b) + 27.0 * c);
+<a name="l00711"></a>00711 
+<a name="l00712"></a>00712     <span class="keyword">const</span> <span class="keywordtype">double</span> Q = q / 9.0;
+<a name="l00713"></a>00713     <span class="keyword">const</span> <span class="keywordtype">double</span> R = r / 54.0;
+<a name="l00714"></a>00714 
+<a name="l00715"></a>00715     <span class="keyword">const</span> <span class="keywordtype">double</span> Q3 = Q * Q * Q;
+<a name="l00716"></a>00716     <span class="keyword">const</span> <span class="keywordtype">double</span> R2 = R * R;
+<a name="l00717"></a>00717 
+<a name="l00718"></a>00718     <span class="keywordtype">double</span> x1 = DBL_MAX; <span class="comment">/* Fix (false) uninit warning */</span>
+<a name="l00719"></a>00719     <span class="keywordtype">double</span> x2 = DBL_MAX; <span class="comment">/* Fix (false) uninit warning */</span>
+<a name="l00720"></a>00720     <span class="keywordtype">double</span> x3 = DBL_MAX; <span class="comment">/* Fix (false) uninit warning */</span>
+<a name="l00721"></a>00721     <span class="keywordtype">double</span> xx1 = DBL_MAX; <span class="comment">/* Fix (false) uninit warning */</span>
+<a name="l00722"></a>00722     <span class="keywordtype">double</span> xx2 = DBL_MAX; <span class="comment">/* Fix (false) uninit warning */</span>
+<a name="l00723"></a>00723     <span class="keywordtype">double</span> xx3 = DBL_MAX; <span class="comment">/* Fix (false) uninit warning */</span>
+<a name="l00724"></a>00724 
+<a name="l00725"></a>00725     <span class="keywordtype">double</span> resx = DBL_MAX;
+<a name="l00726"></a>00726     <span class="keywordtype">double</span> res  = DBL_MAX;
+<a name="l00727"></a>00727     cpl_boolean is_first = CPL_TRUE;
+<a name="l00728"></a>00728 
+<a name="l00729"></a>00729     cpl_boolean dbl2;
+<a name="l00730"></a>00730 
+<a name="l00731"></a>00731 
+<a name="l00732"></a>00732     assert(px1 != NULL );
+<a name="l00733"></a>00733 
+<a name="l00734"></a>00734     <span class="keywordflow">if</span> (pdbl1 != NULL) *pdbl1 = CPL_FALSE;
+<a name="l00735"></a>00735     <span class="keywordflow">if</span> (pdbl2 != NULL) *pdbl2 = CPL_FALSE;
+<a name="l00736"></a>00736 
+<a name="l00737"></a>00737     dbl2 = CPL_FALSE;
+<a name="l00738"></a>00738 
+<a name="l00739"></a>00739     <span class="comment">/*</span>
+<a name="l00740"></a>00740 <span class="comment">      All branches (for which the roots are defined) are evaluated, and</span>
+<a name="l00741"></a>00741 <span class="comment">      the branch with the smallest maximum-residual is chosen.</span>
+<a name="l00742"></a>00742 <span class="comment">      When two maximum-residual are identical, preference is given to</span>
+<a name="l00743"></a>00743 <span class="comment">      the purely real solution and if necessary to the solution with a</span>
+<a name="l00744"></a>00744 <span class="comment">      double root.</span>
+<a name="l00745"></a>00745 <span class="comment">    */</span>
+<a name="l00746"></a>00746 
+<a name="l00747"></a>00747     <span class="keywordflow">if</span> ((R2 >= Q3 && R != 0.0) || R2 > Q3) {
+<a name="l00748"></a>00748 
+<a name="l00749"></a>00749         cpl_boolean is_c = CPL_FALSE;
+<a name="l00750"></a>00750 
+<a name="l00751"></a>00751         irplib_polynomial_solve_1d_3c(a, c, Q, Q3, R, R2, &x1, &x2, &x3,
+<a name="l00752"></a>00752                                       &is_c, &dbl2);
+<a name="l00753"></a>00753 
+<a name="l00754"></a>00754 
+<a name="l00755"></a>00755         res = resx = irplib_polynomial_eval_3_max(p3, p2, p1, p0, is_c,
+<a name="l00756"></a>00756                                             x1, x2, x3);
+<a name="l00757"></a>00757 
+<a name="l00758"></a>00758         is_first = CPL_FALSE;
+<a name="l00759"></a>00759 
+<a name="l00760"></a>00760         <span class="keywordflow">if</span> (pdbl1 != NULL) *pdbl1 = CPL_FALSE;
+<a name="l00761"></a>00761         <span class="keywordflow">if</span> (!is_c && pdbl2 != NULL) *pdbl2 = dbl2;
+<a name="l00762"></a>00762         is_complex = is_c;
+<a name="l00763"></a>00763         irplib_trace(); <span class="comment">/* OK */</span>
+<a name="l00764"></a>00764    
+<a name="l00765"></a>00765     }
+<a name="l00766"></a>00766 
+<a name="l00767"></a>00767     <span class="keywordflow">if</span> (Q > 0.0 && fabs(R / (Q * sqrt(Q))) <= 1.0) {
+<a name="l00768"></a>00768 
+<a name="l00769"></a>00769         <span class="comment">/* this test is actually R2 < Q3, written in a form suitable</span>
+<a name="l00770"></a>00770 <span class="comment">           for exact computation with integers */</span>
+<a name="l00771"></a>00771 
+<a name="l00772"></a>00772         <span class="comment">/* assert( Q > 0.0 ); */</span>
+<a name="l00773"></a>00773 
+<a name="l00774"></a>00774         irplib_polynomial_solve_1d_3r(a, c, Q, R, &xx1, &xx2, &xx3);
+<a name="l00775"></a>00775 
+<a name="l00776"></a>00776         resx = irplib_polynomial_eval_3_max(p3, p2, p1, p0, CPL_FALSE,
+<a name="l00777"></a>00777                                             xx1, xx2, xx3);
+<a name="l00778"></a>00778 
+<a name="l00779"></a>00779         <span class="keywordflow">if</span> (is_first || (dbl2 ? resx < res : resx <= res)) {
+<a name="l00780"></a>00780             is_first = CPL_FALSE;
+<a name="l00781"></a>00781             res = resx;
+<a name="l00782"></a>00782             x1 = xx1;
+<a name="l00783"></a>00783             x2 = xx2;
+<a name="l00784"></a>00784             x3 = xx3;
+<a name="l00785"></a>00785             <span class="keywordflow">if</span> (pdbl1 != NULL) *pdbl1 = CPL_FALSE;
+<a name="l00786"></a>00786             <span class="keywordflow">if</span> (pdbl2 != NULL) *pdbl2 = CPL_FALSE;
+<a name="l00787"></a>00787             is_complex = CPL_FALSE;
+<a name="l00788"></a>00788             irplib_trace(); <span class="comment">/* OK */</span>
+<a name="l00789"></a>00789         }
+<a name="l00790"></a>00790     }
+<a name="l00791"></a>00791 
+<a name="l00792"></a>00792     <span class="keywordflow">if</span> (Q >= 0) {
+<a name="l00793"></a>00793         cpl_boolean dbl1 = CPL_FALSE;
+<a name="l00794"></a>00794 
+<a name="l00795"></a>00795 
+<a name="l00796"></a>00796         irplib_polynomial_solve_1d_32(a, c, Q, &xx1, &xx2, &xx3, &dbl2);
+<a name="l00797"></a>00797 
+<a name="l00798"></a>00798         resx = irplib_polynomial_eval_3_max(p3, p2, p1, p0, CPL_FALSE,
+<a name="l00799"></a>00799                                             xx1, xx2, xx3);
+<a name="l00800"></a>00800         <span class="comment">/*</span>
+<a name="l00801"></a>00801 <span class="comment">        cpl_msg_info(cpl_func, "%d: %g = %g - %g (%u)", __LINE__,</span>
+<a name="l00802"></a>00802 <span class="comment">                     res - resx, res, resx, is_complex);</span>
+<a name="l00803"></a>00803 <span class="comment">        */</span>
+<a name="l00804"></a>00804 
+<a name="l00805"></a>00805         <span class="keywordflow">if</span> (is_first || resx <= res) {
+<a name="l00806"></a>00806             is_first = CPL_FALSE;
+<a name="l00807"></a>00807             res = resx;
+<a name="l00808"></a>00808             x1 = xx1;
+<a name="l00809"></a>00809             x2 = xx2;
+<a name="l00810"></a>00810             x3 = xx3;
+<a name="l00811"></a>00811             <span class="keywordflow">if</span> (pdbl1 != NULL) *pdbl1 = CPL_FALSE;
+<a name="l00812"></a>00812             <span class="keywordflow">if</span> (pdbl2 != NULL) *pdbl2 = dbl2;
+<a name="l00813"></a>00813             is_complex = CPL_FALSE;
+<a name="l00814"></a>00814             irplib_trace(); <span class="comment">/* OK */</span>
+<a name="l00815"></a>00815         }
+<a name="l00816"></a>00816 
+<a name="l00817"></a>00817 
+<a name="l00818"></a>00818         <span class="comment">/* This branch also covers the case where the depressed cubic</span>
+<a name="l00819"></a>00819 <span class="comment">           polynomial has zero as triple root (i.e. Q == R == 0) */</span>
+<a name="l00820"></a>00820 
+<a name="l00821"></a>00821         irplib_polynomial_solve_1d_31(a, Q, &xx1, &xx2, &xx3, &dbl1);
+<a name="l00822"></a>00822 
+<a name="l00823"></a>00823         resx = irplib_polynomial_eval_3_max(p3, p2, p1, p0, CPL_FALSE,
+<a name="l00824"></a>00824                                             xx1, xx2, xx3);
+<a name="l00825"></a>00825 
+<a name="l00826"></a>00826         <span class="keywordflow">if</span> (resx <= res) {
+<a name="l00827"></a>00827             is_first = CPL_FALSE;
+<a name="l00828"></a>00828             res = resx;
+<a name="l00829"></a>00829             x1 = xx1;
+<a name="l00830"></a>00830             x2 = xx2;
+<a name="l00831"></a>00831             x3 = xx3;
+<a name="l00832"></a>00832             <span class="keywordflow">if</span> (pdbl1 != NULL) *pdbl1 = dbl1;
+<a name="l00833"></a>00833             <span class="keywordflow">if</span> (pdbl2 != NULL) *pdbl2 = CPL_FALSE;
+<a name="l00834"></a>00834             is_complex = CPL_FALSE;
+<a name="l00835"></a>00835             irplib_trace(); <span class="comment">/* OK */</span>
+<a name="l00836"></a>00836         }
+<a name="l00837"></a>00837 
+<a name="l00838"></a>00838     }
+<a name="l00839"></a>00839 
+<a name="l00840"></a>00840     <span class="keywordflow">if</span> (px2 != NULL && px3 != NULL) {
+<a name="l00841"></a>00841         *px1 = x1;
+<a name="l00842"></a>00842         *px2 = x2;
+<a name="l00843"></a>00843         *px3 = x3;
+<a name="l00844"></a>00844         irplib_trace(); <span class="comment">/* OK */</span>
+<a name="l00845"></a>00845     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (is_complex) {
+<a name="l00846"></a>00846         *px1 = x1;
+<a name="l00847"></a>00847         irplib_trace(); <span class="comment">/* OK */</span>
+<a name="l00848"></a>00848     } <span class="keywordflow">else</span> {
+<a name="l00849"></a>00849         *px1 = x3;
+<a name="l00850"></a>00850         irplib_trace(); <span class="comment">/* OK */</span>
+<a name="l00851"></a>00851     }
+<a name="l00852"></a>00852 
+<a name="l00853"></a>00853     <span class="keywordflow">return</span> is_complex;
+<a name="l00854"></a>00854 }
+<a name="l00855"></a>00855 
+<a name="l00856"></a>00856 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00870"></a>00870 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00871"></a>00871 <span class="keyword">static</span> <span class="keywordtype">void</span> irplib_polynomial_solve_1d_31(<span class="keywordtype">double</span> a, <span class="keywordtype">double</span> Q,
+<a name="l00872"></a>00872                                           <span class="keywordtype">double</span> * px1, <span class="keywordtype">double</span> * px2,
+<a name="l00873"></a>00873                                           <span class="keywordtype">double</span> * px3, cpl_boolean * pdbl1)
+<a name="l00874"></a>00874 {
+<a name="l00875"></a>00875 
+<a name="l00876"></a>00876     <span class="keyword">const</span> <span class="keywordtype">double</span> sqrtQ = sqrt (Q);
+<a name="l00877"></a>00877 
+<a name="l00878"></a>00878     <span class="keywordtype">double</span> x1, x2, x3;
+<a name="l00879"></a>00879 
+<a name="l00880"></a>00880     x2 = x1 = -sqrtQ - a / 3.0;
+<a name="l00881"></a>00881     x3 = 2.0 * sqrtQ - a / 3.0;
+<a name="l00882"></a>00882     <span class="keywordflow">if</span> (pdbl1 != NULL) *pdbl1 = CPL_TRUE;
+<a name="l00883"></a>00883 
+<a name="l00884"></a>00884     *px1 = x1;
+<a name="l00885"></a>00885     *px2 = x2;
+<a name="l00886"></a>00886     *px3 = x3;
+<a name="l00887"></a>00887 
+<a name="l00888"></a>00888     irplib_trace(); <span class="comment">/* OK */</span>
+<a name="l00889"></a>00889     <span class="keywordflow">return</span>;
+<a name="l00890"></a>00890 }
+<a name="l00891"></a>00891 
+<a name="l00892"></a>00892 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00907"></a>00907 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00908"></a>00908 <span class="keyword">static</span> <span class="keywordtype">void</span> irplib_polynomial_solve_1d_32(<span class="keywordtype">double</span> a, <span class="keywordtype">double</span> c, <span class="keywordtype">double</span> Q,
+<a name="l00909"></a>00909                                           <span class="keywordtype">double</span> * px1, <span class="keywordtype">double</span> * px2,
+<a name="l00910"></a>00910                                           <span class="keywordtype">double</span> * px3, cpl_boolean * pdbl2)
+<a name="l00911"></a>00911 {
+<a name="l00912"></a>00912 
+<a name="l00913"></a>00913     <span class="keyword">const</span> <span class="keywordtype">double</span> sqrtQ = sqrt (Q);
+<a name="l00914"></a>00914 
+<a name="l00915"></a>00915     <span class="keywordtype">double</span> x1 = DBL_MAX;
+<a name="l00916"></a>00916     <span class="keywordtype">double</span> x2 = DBL_MAX;
+<a name="l00917"></a>00917     <span class="keywordtype">double</span> x3 = DBL_MAX;
+<a name="l00918"></a>00918 
+<a name="l00919"></a>00919     <span class="keywordflow">if</span> (a > 0.0) {
+<a name="l00920"></a>00920         <span class="comment">/* a and sqrt(Q) have same sign - or Q is zero */</span>
+<a name="l00921"></a>00921         x1 = -2.0 * sqrtQ - a / 3.0;
+<a name="l00922"></a>00922         <span class="comment">/* FIXME: Two small roots with opposite signs may</span>
+<a name="l00923"></a>00923 <span class="comment">           end up here, with the sign lost for one of them */</span>
+<a name="l00924"></a>00924         x3 = x2 = -a < x1 ? -sqrt(fabs(c / x1)) : sqrt(fabs(c / x1));
+<a name="l00925"></a>00925         <span class="keywordflow">if</span> (pdbl2 != NULL) *pdbl2 = CPL_TRUE;
+<a name="l00926"></a>00926         irplib_trace(); <span class="comment">/* OK */</span>
+<a name="l00927"></a>00927     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (a < 0.0) {
+<a name="l00928"></a>00928         <span class="comment">/* a and sqrt(Q) have opposite signs - or Q is zero */</span>
+<a name="l00929"></a>00929         x3 = x2 = sqrtQ - a / 3.0;
+<a name="l00930"></a>00930         x1 = -c / (x2 * x2);
+<a name="l00931"></a>00931         <span class="keywordflow">if</span> (pdbl2 != NULL) *pdbl2 = CPL_TRUE;
+<a name="l00932"></a>00932         irplib_trace(); <span class="comment">/* OK */</span>
+<a name="l00933"></a>00933     } <span class="keywordflow">else</span> {
+<a name="l00934"></a>00934         x1 = -2.0 * sqrtQ;
+<a name="l00935"></a>00935         x3 = x2 = sqrtQ;
+<a name="l00936"></a>00936         <span class="keywordflow">if</span> (pdbl2 != NULL) *pdbl2 = CPL_TRUE;
+<a name="l00937"></a>00937         irplib_trace(); <span class="comment">/* OK */</span>
+<a name="l00938"></a>00938     }
+<a name="l00939"></a>00939 
+<a name="l00940"></a>00940     *px1 = x1;
+<a name="l00941"></a>00941     *px2 = x2;
+<a name="l00942"></a>00942     *px3 = x3;
+<a name="l00943"></a>00943 
+<a name="l00944"></a>00944     <span class="keywordflow">return</span>;
+<a name="l00945"></a>00945 }
+<a name="l00946"></a>00946 
+<a name="l00947"></a>00947 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00967"></a>00967 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00968"></a>00968 <span class="keyword">static</span> <span class="keywordtype">void</span> irplib_polynomial_solve_1d_3c(<span class="keywordtype">double</span> a, <span class="keywordtype">double</span> c,
+<a name="l00969"></a>00969                                           <span class="keywordtype">double</span> Q, <span class="keywordtype">double</span> Q3,
+<a name="l00970"></a>00970                                           <span class="keywordtype">double</span> R, <span class="keywordtype">double</span> R2,
+<a name="l00971"></a>00971                                           <span class="keywordtype">double</span> * px1,
+<a name="l00972"></a>00972                                           <span class="keywordtype">double</span> * px2, <span class="keywordtype">double</span> * px3,
+<a name="l00973"></a>00973                                           cpl_boolean * pis_c,
+<a name="l00974"></a>00974                                           cpl_boolean * pdbl2)
+<a name="l00975"></a>00975 {
+<a name="l00976"></a>00976 
+<a name="l00977"></a>00977     <span class="comment">/* Due to finite precision some double roots may be missed, and</span>
+<a name="l00978"></a>00978 <span class="comment">       will be considered to be a pair of complex roots z = x +/-</span>
+<a name="l00979"></a>00979 <span class="comment">       epsilon i close to the real axis. */</span>
+<a name="l00980"></a>00980 
+<a name="l00981"></a>00981     <span class="comment">/* Another case: A double root, which is small relative to the</span>
+<a name="l00982"></a>00982 <span class="comment">       last root, may cause this branch to be taken - with the</span>
+<a name="l00983"></a>00983 <span class="comment">       imaginary part eventually being truncated to zero. */</span>
+<a name="l00984"></a>00984 
+<a name="l00985"></a>00985     <span class="keyword">const</span> <span class="keywordtype">double</span> sgnR = (R >= 0 ? 1.0 : -1.0);
+<a name="l00986"></a>00986     <span class="keyword">const</span> <span class="keywordtype">double</span> A = -sgnR * pow (fabs (R) + sqrt (R2 - Q3), 1.0 / 3.0);
+<a name="l00987"></a>00987     <span class="keyword">const</span> <span class="keywordtype">double</span> B = Q / A;
+<a name="l00988"></a>00988 
+<a name="l00989"></a>00989     <span class="keywordtype">double</span> x1 = DBL_MAX;
+<a name="l00990"></a>00990     <span class="keywordtype">double</span> x2 = DBL_MAX;
+<a name="l00991"></a>00991     <span class="keywordtype">double</span> x3 = DBL_MAX;
+<a name="l00992"></a>00992     cpl_boolean is_complex = CPL_FALSE;
+<a name="l00993"></a>00993 
+<a name="l00994"></a>00994     <span class="keywordflow">if</span> (( A > -B && a > 0.0) || (A < -B && a < 0.0)) {
+<a name="l00995"></a>00995         <span class="comment">/* A+B has same sign as a */</span>
+<a name="l00996"></a>00996 
+<a name="l00997"></a>00997         <span class="comment">/* Real part of complex conjugate */</span>
+<a name="l00998"></a>00998         x2 = -0.5 * (A + B) - a / 3.0; <span class="comment">/* No cancellation */</span>
+<a name="l00999"></a>00999         <span class="comment">/* Positive, imaginary part of complex conjugate */</span>
+<a name="l01000"></a>01000         x3 = 0.5 * CPL_MATH_SQRT3 * fabs(A - B);
+<a name="l01001"></a>01001 
+<a name="l01002"></a>01002         x1 = -c / (x2 * x2 + x3 * x3);
+<a name="l01003"></a>01003         irplib_trace(); <span class="comment">/* OK */</span>
+<a name="l01004"></a>01004     } <span class="keywordflow">else</span> {
+<a name="l01005"></a>01005         <span class="comment">/* A+B and a have opposite signs - or exactly one is zero */</span>
+<a name="l01006"></a>01006         x1 = A + B - a / 3.0;
+<a name="l01007"></a>01007         <span class="comment">/* Positive, imaginary part of complex conjugate */</span>
+<a name="l01008"></a>01008         x3 = 0.5 * CPL_MATH_SQRT3 * fabs(A - B);
+<a name="l01009"></a>01009 
+<a name="l01010"></a>01010         <span class="keywordflow">if</span> (x3 > 0.0) {
+<a name="l01011"></a>01011             <span class="comment">/* Real part of complex conjugate */</span>
+<a name="l01012"></a>01012             x2 = -0.5 * (A + B) - a / 3.0; <span class="comment">/* FIXME: Cancellation */</span>
+<a name="l01013"></a>01013             irplib_trace(); <span class="comment">/* OK */</span>
+<a name="l01014"></a>01014         } <span class="keywordflow">else</span> {
+<a name="l01015"></a>01015 
+<a name="l01016"></a>01016             x2 = -a < x1 ? -sqrt(fabs(c / x1)) : sqrt(fabs(c / x1));
+<a name="l01017"></a>01017             x3 = 0.0;
+<a name="l01018"></a>01018             irplib_trace(); <span class="comment">/* OK */</span>
+<a name="l01019"></a>01019         }
+<a name="l01020"></a>01020     }
+<a name="l01021"></a>01021 
+<a name="l01022"></a>01022     <span class="keywordflow">if</span> (x3 > 0.0) {
+<a name="l01023"></a>01023         is_complex = CPL_TRUE;
+<a name="l01024"></a>01024         irplib_trace(); <span class="comment">/* OK */</span>
+<a name="l01025"></a>01025     } <span class="keywordflow">else</span> {
+<a name="l01026"></a>01026         <span class="comment">/* Whoaa, the imaginary part was truncated to zero</span>
+<a name="l01027"></a>01027 <span class="comment">           - return a real, double root */</span>
+<a name="l01028"></a>01028         x3 = x2;
+<a name="l01029"></a>01029         <span class="keywordflow">if</span> (pdbl2 != NULL) *pdbl2 = CPL_TRUE;
+<a name="l01030"></a>01030         irplib_trace(); <span class="comment">/* OK */</span>
+<a name="l01031"></a>01031     }
+<a name="l01032"></a>01032 
+<a name="l01033"></a>01033     *px1 = x1;
+<a name="l01034"></a>01034     *px2 = x2;
+<a name="l01035"></a>01035     *px3 = x3;
+<a name="l01036"></a>01036     *pis_c = is_complex;
+<a name="l01037"></a>01037 
+<a name="l01038"></a>01038     <span class="keywordflow">return</span>;
+<a name="l01039"></a>01039 }
+<a name="l01040"></a>01040 
+<a name="l01041"></a>01041 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01056"></a>01056 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01057"></a>01057 <span class="keyword">static</span> <span class="keywordtype">void</span> irplib_polynomial_solve_1d_3r(<span class="keywordtype">double</span> a, <span class="keywordtype">double</span> c,
+<a name="l01058"></a>01058                                           <span class="keywordtype">double</span> Q, <span class="keywordtype">double</span> R,
+<a name="l01059"></a>01059                                           <span class="keywordtype">double</span> * px1,
+<a name="l01060"></a>01060                                           <span class="keywordtype">double</span> * px2, <span class="keywordtype">double</span> * px3)
+<a name="l01061"></a>01061 {
+<a name="l01062"></a>01062 
+<a name="l01063"></a>01063     <span class="keyword">const</span> <span class="keywordtype">double</span> sqrtQ = sqrt(Q);
+<a name="l01064"></a>01064     <span class="keyword">const</span> <span class="keywordtype">double</span> theta = acos (R / (Q * sqrtQ)); <span class="comment">/* theta in range [0; pi] */</span>
+<a name="l01065"></a>01065 
+<a name="l01066"></a>01066     <span class="comment">/* -1.0 <= cos((theta + CPL_MATH_2PI) / 3.0) <= -0.5</span>
+<a name="l01067"></a>01067 <span class="comment">       -0.5 <= cos((theta - CPL_MATH_2PI) / 3.0) <=  0.5</span>
+<a name="l01068"></a>01068 <span class="comment">        0.5 <= cos((theta                  ) / 3.0) <=  1.0 */</span>
+<a name="l01069"></a>01069 
+<a name="l01070"></a>01070 <span class="preprocessor">#define TR1 (-2.0 * sqrtQ * cos( theta                    / 3.0))</span>
+<a name="l01071"></a>01071 <span class="preprocessor"></span><span class="preprocessor">#define TR2 (-2.0 * sqrtQ * cos((theta - CPL_MATH_2PI) / 3.0))</span>
+<a name="l01072"></a>01072 <span class="preprocessor"></span><span class="preprocessor">#define TR3 (-2.0 * sqrtQ * cos((theta + CPL_MATH_2PI) / 3.0))</span>
+<a name="l01073"></a>01073 <span class="preprocessor"></span>
+<a name="l01074"></a>01074     <span class="comment">/* TR1 < TR2 < TR3, except when theta == 0, then TR2 == TR3 */</span>
+<a name="l01075"></a>01075 
+<a name="l01076"></a>01076     <span class="comment">/* The three roots must be transformed back via subtraction with a/3.</span>
+<a name="l01077"></a>01077 <span class="comment">       To prevent loss of precision due to cancellation, the root which</span>
+<a name="l01078"></a>01078 <span class="comment">       is closest to a/3 is computed using the relation</span>
+<a name="l01079"></a>01079 <span class="comment">       p3 * x1 * x2 * x3 = -p0 */</span>
+<a name="l01080"></a>01080 
+<a name="l01081"></a>01081     <span class="keywordtype">double</span> x1 = DBL_MAX;
+<a name="l01082"></a>01082     <span class="keywordtype">double</span> x2 = DBL_MAX;
+<a name="l01083"></a>01083     <span class="keywordtype">double</span> x3 = DBL_MAX;
+<a name="l01084"></a>01084 
+<a name="l01085"></a>01085     <span class="keywordflow">if</span> (a > 0.0) {
+<a name="l01086"></a>01086         x1 = TR1 - a / 3.0;
+<a name="l01087"></a>01087         <span class="keywordflow">if</span> (TR2 > 0.0 && (TR2 + TR3) > 2.0 * a) {
+<a name="l01088"></a>01088             <span class="comment">/* FIXME: Cancellation may still effect x3 ? */</span>
+<a name="l01089"></a>01089             x3 = TR3 - a / 3.0;
+<a name="l01090"></a>01090             x2 = -c / ( x1 * x3 );
+<a name="l01091"></a>01091             irplib_trace(); <span class="comment">/* OK */</span>
+<a name="l01092"></a>01092         } <span class="keywordflow">else</span> {
+<a name="l01093"></a>01093             <span class="comment">/* FIXME: Cancellation may still effect x2, especially</span>
+<a name="l01094"></a>01094 <span class="comment">               if x2, x3 is (almost) a double root, i.e.</span>
+<a name="l01095"></a>01095 <span class="comment">               if theta is close to zero. */</span>
+<a name="l01096"></a>01096             x2 = TR2 - a / 3.0;
+<a name="l01097"></a>01097  
+<a name="l01098"></a>01098             x3 = -c / ( x1 * x2 );
+<a name="l01099"></a>01099             irplib_trace(); <span class="comment">/* OK */</span>
+<a name="l01100"></a>01100         }
+<a name="l01101"></a>01101     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (a < 0.0) {
+<a name="l01102"></a>01102         x3 = TR3 - a / 3.0;
+<a name="l01103"></a>01103         <span class="keywordflow">if</span> (TR2 < 0.0 && (TR1 + TR2) > 2.0 * a) {
+<a name="l01104"></a>01104             x1 = TR1 - a / 3.0;
+<a name="l01105"></a>01105             x2 = -c / ( x1 * x3 );
+<a name="l01106"></a>01106             irplib_trace(); <span class="comment">/* OK */</span>
+<a name="l01107"></a>01107         } <span class="keywordflow">else</span> {
+<a name="l01108"></a>01108             x2 = TR2 - a / 3.0;
+<a name="l01109"></a>01109             x1 = -c / ( x2 * x3 );
+<a name="l01110"></a>01110             irplib_trace(); <span class="comment">/* OK */</span>
+<a name="l01111"></a>01111         }
+<a name="l01112"></a>01112     } <span class="keywordflow">else</span> {
+<a name="l01113"></a>01113         x1 = TR1;
+<a name="l01114"></a>01114         x2 = TR2;
+<a name="l01115"></a>01115         x3 = TR3;
+<a name="l01116"></a>01116         irplib_trace(); <span class="comment">/* OK */</span>
+<a name="l01117"></a>01117     }
+<a name="l01118"></a>01118 
+<a name="l01119"></a>01119     assert(x1 < x3);
+<a name="l01120"></a>01120 
+<a name="l01121"></a>01121     <span class="keywordflow">if</span> (x1 > x2) {
+<a name="l01122"></a>01122         <span class="comment">/* In absence of round-off:</span>
+<a name="l01123"></a>01123 <span class="comment">           theta == PI: x1 == x2,</span>
+<a name="l01124"></a>01124 <span class="comment">           theta  < PI: x1 <  x2,</span>
+<a name="l01125"></a>01125 <span class="comment"></span>
+<a name="l01126"></a>01126 <span class="comment">           The only way x1 could exceed x2 would be due to round-off when</span>
+<a name="l01127"></a>01127 <span class="comment">           theta is close to PI */</span>
+<a name="l01128"></a>01128      
+<a name="l01129"></a>01129         x1 = x2 = 0.5 * ( x1 + x2 );
+<a name="l01130"></a>01130         irplib_trace(); <span class="comment">/* OK, tested only for x1 == x2 */</span>
+<a name="l01131"></a>01131     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (x2 > x3) {
+<a name="l01132"></a>01132         <span class="comment">/* In absence of round-off:</span>
+<a name="l01133"></a>01133 <span class="comment">           theta == 0: x2 == x3,</span>
+<a name="l01134"></a>01134 <span class="comment">           theta  > 0: x2 <  x3,</span>
+<a name="l01135"></a>01135 <span class="comment"></span>
+<a name="l01136"></a>01136 <span class="comment">           For small theta:</span>
+<a name="l01137"></a>01137 <span class="comment">           Round-off can cause x2 to become greater than x3 */</span>
+<a name="l01138"></a>01138      
+<a name="l01139"></a>01139         x3 = x2 = 0.5 * ( x2 + x3 );
+<a name="l01140"></a>01140         irplib_trace(); <span class="comment">/* OK */</span>
+<a name="l01141"></a>01141     }
+<a name="l01142"></a>01142 
+<a name="l01143"></a>01143     *px1 = x1;
+<a name="l01144"></a>01144     *px2 = x2;
+<a name="l01145"></a>01145     *px3 = x3;
+<a name="l01146"></a>01146 
+<a name="l01147"></a>01147     <span class="keywordflow">return</span>;
+<a name="l01148"></a>01148 }
+<a name="l01149"></a>01149 
+<a name="l01150"></a>01150 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01168"></a>01168 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01169"></a>01169 <span class="keyword">static</span> cpl_error_code irplib_polynomial_solve_1d_4(<span class="keywordtype">double</span> p4, <span class="keywordtype">double</span> p3,
+<a name="l01170"></a>01170                                                    <span class="keywordtype">double</span> p2, <span class="keywordtype">double</span> p1,
+<a name="l01171"></a>01171                                                    <span class="keywordtype">double</span> p0, cpl_size * preal,
+<a name="l01172"></a>01172                                                    <span class="keywordtype">double</span> * px1, <span class="keywordtype">double</span> * px2,
+<a name="l01173"></a>01173                                                    <span class="keywordtype">double</span> * px3, <span class="keywordtype">double</span> * px4)
+<a name="l01174"></a>01174 {
+<a name="l01175"></a>01175 
+<a name="l01176"></a>01176     <span class="comment">/* Construct the monic, depressed quartic using Horners scheme on 1 / p4 */</span>
+<a name="l01177"></a>01177     <span class="keyword">const</span> <span class="keywordtype">double</span> a = (p2 - 0.375 * p3 * p3 / p4) / p4;
+<a name="l01178"></a>01178     <span class="keyword">const</span> <span class="keywordtype">double</span> b = (p1 - 0.5 * (p2 - 0.25 * p3 * p3 / p4 ) * p3 / p4 ) / p4;
+<a name="l01179"></a>01179     <span class="keyword">const</span> <span class="keywordtype">double</span> c =
+<a name="l01180"></a>01180         (p0 - 0.25 * (p1 - 0.25 * (p2 - 0.1875 * p3 * p3 / p4 ) * p3 / p4
+<a name="l01181"></a>01181                       ) * p3 / p4 ) / p4;
+<a name="l01182"></a>01182 
+<a name="l01183"></a>01183     <span class="keywordtype">double</span> x1 = DBL_MAX; <span class="comment">/* Fix (false) uninit warning */</span>
+<a name="l01184"></a>01184     <span class="keywordtype">double</span> x2 = DBL_MAX; <span class="comment">/* Fix (false) uninit warning */</span>
+<a name="l01185"></a>01185     <span class="keywordtype">double</span> x3 = DBL_MAX; <span class="comment">/* Fix (false) uninit warning */</span>
+<a name="l01186"></a>01186     <span class="keywordtype">double</span> x4 = DBL_MAX; <span class="comment">/* Fix (false) uninit warning */</span>
+<a name="l01187"></a>01187 
+<a name="l01188"></a>01188     assert(preal != NULL );
+<a name="l01189"></a>01189     assert(px1   != NULL );
+<a name="l01190"></a>01190     assert(px2   != NULL );
+<a name="l01191"></a>01191     assert(px3   != NULL );
+<a name="l01192"></a>01192     assert(px4   != NULL );
+<a name="l01193"></a>01193 
+<a name="l01194"></a>01194     *preal = 4;
+<a name="l01195"></a>01195 
+<a name="l01196"></a>01196     <span class="keywordflow">if</span> (c == 0.0) {
+<a name="l01197"></a>01197         <span class="comment">/* The depressed quartic has zero as root */</span>
+<a name="l01198"></a>01198         <span class="comment">/* Since the sum of the roots is zero, at least one is negative</span>
+<a name="l01199"></a>01199 <span class="comment">           and at least one is positive - unless they are all zero */</span>
+<a name="l01200"></a>01200         cpl_boolean dbl1, dbl2;
+<a name="l01201"></a>01201         <span class="keyword">const</span> cpl_boolean is_real =
+<a name="l01202"></a>01202             !irplib_polynomial_solve_1d_3(1.0, 0.0, a, b, &x1, &x3, &x4,
+<a name="l01203"></a>01203                                           &dbl1, &dbl2);
+<a name="l01204"></a>01204 
+<a name="l01205"></a>01205         x1 -= 0.25 * p3 / p4;
+<a name="l01206"></a>01206         x2 = -0.25 * p3 / p4;
+<a name="l01207"></a>01207         x3 -= 0.25 * p3 / p4;
+<a name="l01208"></a>01208         <span class="keywordflow">if</span> (is_real) {
+<a name="l01209"></a>01209 
+<a name="l01210"></a>01210             <span class="keywordflow">if</span> (dbl2) {
+<a name="l01211"></a>01211                 x4 = x3;
+<a name="l01212"></a>01212                 assert( x1 <= x2);
+<a name="l01213"></a>01213                 assert( x2 <= x3);
+<a name="l01214"></a>01214             } <span class="keywordflow">else</span> {
+<a name="l01215"></a>01215                 x4 -= 0.25 * p3 / p4;
+<a name="l01216"></a>01216                 <span class="comment">/* Need (only) a guarded swap of x2, x3 */</span>
+<a name="l01217"></a>01217                 <span class="keywordflow">if</span> (x2 > x3) {
+<a name="l01218"></a>01218                     IRPLIB_SWAP(x2, x3);
+<a name="l01219"></a>01219                 }
+<a name="l01220"></a>01220                 <span class="keywordflow">if</span> (dbl1) {
+<a name="l01221"></a>01221                     assert( x1 <= x2); <span class="comment">/* The cubic may have 0 as triple root */</span>
+<a name="l01222"></a>01222                     assert( x2 <= x3);
+<a name="l01223"></a>01223                     assert( x2 <= x4);
+<a name="l01224"></a>01224                 } <span class="keywordflow">else</span> {
+<a name="l01225"></a>01225                     assert( x1 < x2);
+<a name="l01226"></a>01226                     assert( x2 < x4);
+<a name="l01227"></a>01227                 }
+<a name="l01228"></a>01228             }
+<a name="l01229"></a>01229         } <span class="keywordflow">else</span> {
+<a name="l01230"></a>01230             *preal = 2;
+<a name="l01231"></a>01231 
+<a name="l01232"></a>01232             <span class="keywordflow">if</span> (x1 > x2) {
+<a name="l01233"></a>01233                 assert( x3 <= x2 ); <span class="comment">/* Don't swap a complex root */</span>
+<a name="l01234"></a>01234 
+<a name="l01235"></a>01235                 IRPLIB_SWAP(x1, x2);
+<a name="l01236"></a>01236             } <span class="keywordflow">else</span> {
+<a name="l01237"></a>01237                 assert( x3 >= x2 );
+<a name="l01238"></a>01238             }
+<a name="l01239"></a>01239         }
+<a name="l01240"></a>01240 
+<a name="l01241"></a>01241     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (b == 0.0) {
+<a name="l01242"></a>01242         <span class="comment">/* The monic, depressed quartic is a monic, biquadratic equation */</span>
+<a name="l01243"></a>01243         <span class="keywordtype">double</span> u1, u2;
+<a name="l01244"></a>01244         <span class="keyword">const</span> cpl_boolean is_complex = irplib_polynomial_solve_1d_2(1.0, a, c,
+<a name="l01245"></a>01245                                                                     &u1, &u2);
+<a name="l01246"></a>01246 
+<a name="l01247"></a>01247         <span class="keywordflow">if</span> (is_complex) {
+<a name="l01248"></a>01248             <span class="comment">/* All four roots are conjugate, complex */</span>
+<a name="l01249"></a>01249             <span class="keyword">const</span> <span class="keywordtype">double</span> norm = sqrt(u1*u1 + u2*u2);
+<a name="l01250"></a>01250             <span class="keyword">const</span> <span class="keywordtype">double</span>   v1 = sqrt(0.5*(norm+u1));
+<a name="l01251"></a>01251             <span class="keyword">const</span> <span class="keywordtype">double</span>   v2 = u2 / sqrt(2.0*(norm+u1));
+<a name="l01252"></a>01252 
+<a name="l01253"></a>01253 
+<a name="l01254"></a>01254             x1 = -0.25 * p3 / p4 - v1;
+<a name="l01255"></a>01255             x3 = -0.25 * p3 / p4 + v1;
+<a name="l01256"></a>01256 
+<a name="l01257"></a>01257             x4 = x2 = v2;
+<a name="l01258"></a>01258 
+<a name="l01259"></a>01259             *preal = 0;
+<a name="l01260"></a>01260 
+<a name="l01261"></a>01261         } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (u1 >= 0.0) {
+<a name="l01262"></a>01262             <span class="comment">/* All four roots are real */</span>
+<a name="l01263"></a>01263             <span class="keyword">const</span> <span class="keywordtype">double</span> sv1 = sqrt(u1);
+<a name="l01264"></a>01264             <span class="keyword">const</span> <span class="keywordtype">double</span> sv2 = sqrt(u2);
+<a name="l01265"></a>01265 
+<a name="l01266"></a>01266 
+<a name="l01267"></a>01267             *preal = 4;
+<a name="l01268"></a>01268 
+<a name="l01269"></a>01269             x1 = -0.25 * p3 / p4 - sv2;
+<a name="l01270"></a>01270             x2 = -0.25 * p3 / p4 - sv1;
+<a name="l01271"></a>01271             x3 = -0.25 * p3 / p4 + sv1;
+<a name="l01272"></a>01272             x4 = -0.25 * p3 / p4 + sv2;
+<a name="l01273"></a>01273         } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (u2 < 0.0) {
+<a name="l01274"></a>01274             <span class="comment">/* All four roots are conjugate, complex */</span>
+<a name="l01275"></a>01275             <span class="keyword">const</span> <span class="keywordtype">double</span> sv1 = sqrt(-u2);
+<a name="l01276"></a>01276             <span class="keyword">const</span> <span class="keywordtype">double</span> sv2 = sqrt(-u1);
+<a name="l01277"></a>01277 
+<a name="l01278"></a>01278 
+<a name="l01279"></a>01279             *preal = 0;
+<a name="l01280"></a>01280 
+<a name="l01281"></a>01281             x1 = x3 = -0.25 * p3 / p4;
+<a name="l01282"></a>01282 
+<a name="l01283"></a>01283             x2 = sv1;
+<a name="l01284"></a>01284             x4 = sv2;
+<a name="l01285"></a>01285         } <span class="keywordflow">else</span> {
+<a name="l01286"></a>01286             <span class="comment">/* Two roots are real, two roots are conjugate, complex */</span>
+<a name="l01287"></a>01287             <span class="keyword">const</span> <span class="keywordtype">double</span> sv1 = sqrt(-u1);
+<a name="l01288"></a>01288             <span class="keyword">const</span> <span class="keywordtype">double</span> sv2 = sqrt(u2);
+<a name="l01289"></a>01289 
+<a name="l01290"></a>01290 
+<a name="l01291"></a>01291             *preal = 2;
+<a name="l01292"></a>01292 
+<a name="l01293"></a>01293             x1 = -0.25 * p3 / p4 - sv2;
+<a name="l01294"></a>01294             x2 = -0.25 * p3 / p4 + sv2;
+<a name="l01295"></a>01295 
+<a name="l01296"></a>01296             x3 = -0.25 * p3 / p4;
+<a name="l01297"></a>01297             x4 = sv1;
+<a name="l01298"></a>01298         }
+<a name="l01299"></a>01299     } <span class="keywordflow">else</span> {
+<a name="l01300"></a>01300         <span class="comment">/* Need a root from the nested, monic cubic */</span>
+<a name="l01301"></a>01301         <span class="keyword">const</span> <span class="keywordtype">double</span> q2 = -a;
+<a name="l01302"></a>01302         <span class="keyword">const</span> <span class="keywordtype">double</span> q1 = -4.0 * c;
+<a name="l01303"></a>01303         <span class="keyword">const</span> <span class="keywordtype">double</span> q0 = 4.0 * a * c - b * b;
+<a name="l01304"></a>01304         <span class="keywordtype">double</span> u1, sqrtd, sqrtrd;
+<a name="l01305"></a>01305         <span class="keywordtype">double</span> z1, z2, z3, z4;
+<a name="l01306"></a>01306 
+<a name="l01307"></a>01307         cpl_boolean is_complex1, is_complex2;
+<a name="l01308"></a>01308 
+<a name="l01309"></a>01309         <span class="comment">/* Largest cubic root ensures real square roots when solving the</span>
+<a name="l01310"></a>01310 <span class="comment">           quartic equation */</span>
+<a name="l01311"></a>01311         (void)irplib_polynomial_solve_1d_3(1.0, q2, q1, q0, &u1, NULL, NULL,
+<a name="l01312"></a>01312                                            NULL, NULL);
+<a name="l01313"></a>01313 
+<a name="l01314"></a>01314 
+<a name="l01315"></a>01315         assert( u1 > a );
+<a name="l01316"></a>01316 
+<a name="l01317"></a>01317         sqrtd = sqrt(u1 - a);
+<a name="l01318"></a>01318 
+<a name="l01319"></a>01319         sqrtrd = 0.5 * b/sqrtd;
+<a name="l01320"></a>01320 
+<a name="l01321"></a>01321         is_complex1 = irplib_polynomial_solve_1d_2(1.0,  sqrtd, 0.5*u1 - sqrtrd,
+<a name="l01322"></a>01322                                                    &z1, &z2);
+<a name="l01323"></a>01323 
+<a name="l01324"></a>01324         is_complex2 = irplib_polynomial_solve_1d_2(1.0, -sqrtd, 0.5*u1 + sqrtrd,
+<a name="l01325"></a>01325                                                    &z3, &z4);
+<a name="l01326"></a>01326 
+<a name="l01327"></a>01327         z1 -= 0.25 * p3 / p4;
+<a name="l01328"></a>01328         z3 -= 0.25 * p3 / p4;
+<a name="l01329"></a>01329         <span class="keywordflow">if</span> (!is_complex1) z2 -= 0.25 * p3 / p4;
+<a name="l01330"></a>01330         <span class="keywordflow">if</span> (!is_complex2) z4 -= 0.25 * p3 / p4;
+<a name="l01331"></a>01331 
+<a name="l01332"></a>01332         <span class="keywordflow">if</span> (!is_complex1 && is_complex2) {
+<a name="l01333"></a>01333             *preal = 2;
+<a name="l01334"></a>01334             x1 = z1;
+<a name="l01335"></a>01335             x2 = z2;
+<a name="l01336"></a>01336             x3 = z3;
+<a name="l01337"></a>01337             x4 = z4;
+<a name="l01338"></a>01338         } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (is_complex1 && !is_complex2) {
+<a name="l01339"></a>01339             *preal = 2;
+<a name="l01340"></a>01340             x1 = z3;
+<a name="l01341"></a>01341             x2 = z4;
+<a name="l01342"></a>01342             x3 = z1;
+<a name="l01343"></a>01343             x4 = z2;
+<a name="l01344"></a>01344         } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (is_complex1 && is_complex2) {
+<a name="l01345"></a>01345             *preal = 0;
+<a name="l01346"></a>01346 
+<a name="l01347"></a>01347             <span class="keywordflow">if</span> (z1 < z3 || (z1 == z3 && z2 <= z4)) {
+<a name="l01348"></a>01348                 x1 = z1;
+<a name="l01349"></a>01349                 x2 = z2;
+<a name="l01350"></a>01350                 x3 = z3;
+<a name="l01351"></a>01351                 x4 = z4;
+<a name="l01352"></a>01352             } <span class="keywordflow">else</span> {
+<a name="l01353"></a>01353                 x1 = z3;
+<a name="l01354"></a>01354                 x2 = z4;
+<a name="l01355"></a>01355                 x3 = z1;
+<a name="l01356"></a>01356                 x4 = z2;
+<a name="l01357"></a>01357             }
+<a name="l01358"></a>01358         } <span class="keywordflow">else</span> {
+<a name="l01359"></a>01359             *preal = 4;
+<a name="l01360"></a>01360 
+<a name="l01361"></a>01361             <span class="keywordflow">if</span> (z3 >= z2) {
+<a name="l01362"></a>01362                 x1 = z1;
+<a name="l01363"></a>01363                 x2 = z2;
+<a name="l01364"></a>01364                 x3 = z3;
+<a name="l01365"></a>01365                 x4 = z4;
+<a name="l01366"></a>01366             } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (z4 <= z1) {
+<a name="l01367"></a>01367                 x1 = z3;
+<a name="l01368"></a>01368                 x2 = z4;
+<a name="l01369"></a>01369                 x3 = z1;
+<a name="l01370"></a>01370                 x4 = z2;
+<a name="l01371"></a>01371             } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (z2 > z4) {
+<a name="l01372"></a>01372                 x1 = z3;
+<a name="l01373"></a>01373                 x2 = z1;
+<a name="l01374"></a>01374                 x3 = z4;
+<a name="l01375"></a>01375                 x4 = z2;
+<a name="l01376"></a>01376             } <span class="keywordflow">else</span> {
+<a name="l01377"></a>01377                 x1 = z1;
+<a name="l01378"></a>01378                 x2 = z3;
+<a name="l01379"></a>01379                 x3 = z2;
+<a name="l01380"></a>01380                 x4 = z4;
+<a name="l01381"></a>01381             }
+<a name="l01382"></a>01382         }
+<a name="l01383"></a>01383     }
+<a name="l01384"></a>01384 
+<a name="l01385"></a>01385     *px1 = x1;
+<a name="l01386"></a>01386     *px2 = x2;
+<a name="l01387"></a>01387     *px3 = x3;
+<a name="l01388"></a>01388     *px4 = x4;
+<a name="l01389"></a>01389 
+<a name="l01390"></a>01390     <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l01391"></a>01391 }
+<a name="l01392"></a>01392 
+<a name="l01393"></a>01393 <span class="preprocessor">#ifdef IPRLIB_POLYNOMIAL_USE_MONOMIAL_ROOT</span>
+<a name="l01394"></a>01394 <span class="preprocessor"></span><span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01402"></a>01402 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01403"></a>01403 <span class="keyword">static</span> <span class="keywordtype">double</span> irplib_polynomial_depress_1d(cpl_polynomial * <span class="keyword">self</span>)
+<a name="l01404"></a>01404 {
+<a name="l01405"></a>01405 
+<a name="l01406"></a>01406     <span class="keyword">const</span> cpl_size degree = cpl_polynomial_get_degree(<span class="keyword">self</span>);
+<a name="l01407"></a>01407     <span class="keyword">const</span> cpl_size nc1    = degree - 1;
+<a name="l01408"></a>01408     <span class="keyword">const</span> <span class="keywordtype">double</span>   an     = cpl_polynomial_get_coeff(<span class="keyword">self</span>, &degree);
+<a name="l01409"></a>01409     <span class="keyword">const</span> <span class="keywordtype">double</span>   an1    = cpl_polynomial_get_coeff(<span class="keyword">self</span>, &nc1);
+<a name="l01410"></a>01410     <span class="keywordtype">double</span>         rmean;
+<a name="l01411"></a>01411     cpl_size       i;
+<a name="l01412"></a>01412 
+<a name="l01413"></a>01413 
+<a name="l01414"></a>01414     cpl_ensure(degree > 0,   CPL_ERROR_DATA_NOT_FOUND, 0.0);
+<a name="l01415"></a>01415 
+<a name="l01416"></a>01416     assert( an != 0.0 );
+<a name="l01417"></a>01417 
+<a name="l01418"></a>01418     rmean = -an1/(an * (double)degree);
+<a name="l01419"></a>01419 
+<a name="l01420"></a>01420     <span class="keywordflow">if</span> (rmean != 0.0) {
+<a name="l01421"></a>01421 
+<a name="l01422"></a>01422         cpl_polynomial_shift_1d(<span class="keyword">self</span>, 0, rmean);
+<a name="l01423"></a>01423 
+<a name="l01424"></a>01424         cpl_polynomial_set_coeff(<span class="keyword">self</span>, &nc1, 0.0); <span class="comment">/* Round-off... */</span>
+<a name="l01425"></a>01425 
+<a name="l01426"></a>01426     }
+<a name="l01427"></a>01427 
+<a name="l01428"></a>01428     <span class="comment">/* Set leading coefficient to one. */</span>
+<a name="l01429"></a>01429     <span class="keywordflow">for</span> (i = 0; i < degree-1; i++) {
+<a name="l01430"></a>01430         <span class="keyword">const</span> <span class="keywordtype">double</span> ai = cpl_polynomial_get_coeff(<span class="keyword">self</span>, &i) / an;
+<a name="l01431"></a>01431         cpl_polynomial_set_coeff(<span class="keyword">self</span>, &i, ai);
+<a name="l01432"></a>01432     }
+<a name="l01433"></a>01433 
+<a name="l01434"></a>01434     cpl_polynomial_set_coeff(<span class="keyword">self</span>, &degree, 1.0); <span class="comment">/* Round-off... */</span>
+<a name="l01435"></a>01435 
+<a name="l01436"></a>01436     <span class="keywordflow">return</span> rmean;
+<a name="l01437"></a>01437 }
+<a name="l01438"></a>01438 <span class="preprocessor">#endif</span>
+<a name="l01439"></a>01439 <span class="preprocessor"></span>
+<a name="l01440"></a>01440 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01455"></a>01455 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01456"></a>01456 <span class="keyword">static</span>
+<a name="l01457"></a>01457 cpl_error_code irplib_polynomial_divide_1d_root(cpl_polynomial * p, <span class="keywordtype">double</span> r,
+<a name="l01458"></a>01458                                                 <span class="keywordtype">double</span> * pres)
+<a name="l01459"></a>01459 {
+<a name="l01460"></a>01460 
+<a name="l01461"></a>01461     <span class="keyword">const</span> cpl_size n = cpl_polynomial_get_degree(p);
+<a name="l01462"></a>01462     <span class="keywordtype">double</span>         sum;
+<a name="l01463"></a>01463     cpl_size       i;
+<a name="l01464"></a>01464 
+<a name="l01465"></a>01465 
+<a name="l01466"></a>01466     cpl_ensure_code(p != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l01467"></a>01467     cpl_ensure_code(cpl_polynomial_get_dimension(p) == 1,
+<a name="l01468"></a>01468                     CPL_ERROR_INVALID_TYPE);
+<a name="l01469"></a>01469     cpl_ensure_code(n > 0, CPL_ERROR_DATA_NOT_FOUND);
+<a name="l01470"></a>01470 
+<a name="l01471"></a>01471     sum = cpl_polynomial_get_coeff(p, &n);
+<a name="l01472"></a>01472     cpl_polynomial_set_coeff(p, &n, 0.0);
+<a name="l01473"></a>01473 
+<a name="l01474"></a>01474     <span class="keywordflow">for</span> (i = n-1; i >= 0; i--) {
+<a name="l01475"></a>01475         <span class="keyword">const</span> <span class="keywordtype">double</span> coeff = cpl_polynomial_get_coeff(p, &i);
+<a name="l01476"></a>01476 
+<a name="l01477"></a>01477         cpl_polynomial_set_coeff(p, &i, sum);
+<a name="l01478"></a>01478 
+<a name="l01479"></a>01479         sum = coeff + r * sum;
+<a name="l01480"></a>01480 
+<a name="l01481"></a>01481     }
+<a name="l01482"></a>01482 
+<a name="l01483"></a>01483     <span class="keywordflow">if</span> (pres != NULL) *pres = sum;
+<a name="l01484"></a>01484 
+<a name="l01485"></a>01485     <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l01486"></a>01486 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/irplib__polynomial_8h_source.html b/html/irplib__polynomial_8h_source.html
new file mode 100644
index 0000000..497c71e
--- /dev/null
+++ b/html/irplib__polynomial_8h_source.html
@@ -0,0 +1,86 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: irplib_polynomial.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>irplib_polynomial.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: irplib_polynomial.h,v 1.9 2012/01/12 10:40:21 llundin Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the ESO Common Pipeline Library</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2007 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: llundin $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2012/01/12 10:40:21 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.9 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifndef IRPLIB_POLYNOMIAL_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#define IRPLIB_POLYNOMIAL_H</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span>
+<a name="l00031"></a>00031 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00032"></a>00032 <span class="comment">                                   Includes</span>
+<a name="l00033"></a>00033 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00034"></a>00034 
+<a name="l00035"></a>00035 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00038"></a>00038 <span class="comment">                              Function prototypes</span>
+<a name="l00039"></a>00039 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00040"></a>00040 
+<a name="l00041"></a>00041 <span class="comment">/* TEMPORARY SUPPORT OF CPL 5.x */</span>
+<a name="l00042"></a>00042 <span class="preprocessor">#ifndef CPL_SIZE_FORMAT</span>
+<a name="l00043"></a>00043 <span class="preprocessor"></span><span class="preprocessor">#define CPL_SIZE_FORMAT "d"</span>
+<a name="l00044"></a>00044 <span class="preprocessor"></span><span class="preprocessor">#define cpl_size int</span>
+<a name="l00045"></a>00045 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
+<a name="l00046"></a>00046 <span class="preprocessor"></span>
+<a name="l00047"></a>00047 <span class="preprocessor">#if defined CPL_VERSION_CODE && CPL_VERSION_CODE > CPL_VERSION(5, 92, 0)</span>
+<a name="l00048"></a>00048 <span class="preprocessor"></span><span class="preprocessor">#define irplib_polynomial_add cpl_polynomial_add</span>
+<a name="l00049"></a>00049 <span class="preprocessor"></span><span class="preprocessor">#define irplib_polynomial_subtract cpl_polynomial_subtract</span>
+<a name="l00050"></a>00050 <span class="preprocessor"></span><span class="preprocessor">#define irplib_polynomial_multiply_scalar cpl_polynomial_multiply_scalar</span>
+<a name="l00051"></a>00051 <span class="preprocessor"></span><span class="preprocessor">#else</span>
+<a name="l00052"></a>00052 <span class="preprocessor"></span>cpl_error_code <a class="code" href="group__irplib__polynomial.html#ga90e13f05c9addc584f154279681d1853" title="Add two polynomials of the same dimension.">irplib_polynomial_add</a>(cpl_polynomial *,
+<a name="l00053"></a>00053                                      <span class="keyword">const</span> cpl_polynomial *,
+<a name="l00054"></a>00054                                      <span class="keyword">const</span> cpl_polynomial *);
+<a name="l00055"></a>00055 
+<a name="l00056"></a>00056 cpl_error_code <a class="code" href="group__irplib__polynomial.html#ga0e83ae3c9e7accb70fdfe1aca030e084" title="Subtract two polynomials of the same dimension.">irplib_polynomial_subtract</a>(cpl_polynomial *,
+<a name="l00057"></a>00057                                           <span class="keyword">const</span> cpl_polynomial *,
+<a name="l00058"></a>00058                                           <span class="keyword">const</span> cpl_polynomial *);
+<a name="l00059"></a>00059 
+<a name="l00060"></a>00060 cpl_error_code <a class="code" href="group__irplib__polynomial.html#ga55c030413e6ef112753b280ad5213786" title="Multiply a polynomial with a scalar.">irplib_polynomial_multiply_scalar</a>(cpl_polynomial *,
+<a name="l00061"></a>00061                                                  <span class="keyword">const</span> cpl_polynomial *,
+<a name="l00062"></a>00062                                                  <span class="keywordtype">double</span>);
+<a name="l00063"></a>00063 <span class="preprocessor">#endif</span>
+<a name="l00064"></a>00064 <span class="preprocessor"></span>
+<a name="l00065"></a>00065 <span class="comment">/* END TEMPORARY SUPPORT OF CPL 5.x */</span>
+<a name="l00066"></a>00066 
+<a name="l00067"></a>00067 cpl_error_code <a class="code" href="group__irplib__polynomial.html#ga87e84d69eadbde803fce3c3cbdedf385" title="Compute all n roots of p(x) = 0, where p(x) is of degree n, n &gt; 0.">irplib_polynomial_solve_1d_all</a>(<span class="keyword">const</span> cpl_polynomial *,
+<a name="l00068"></a>00068                                               cpl_vector *, cpl_size *);
+<a name="l00069"></a>00069 
+<a name="l00070"></a>00070 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/irplib__ppm_8c_source.html b/html/irplib__ppm_8c_source.html
new file mode 100644
index 0000000..1d95d32
--- /dev/null
+++ b/html/irplib__ppm_8c_source.html
@@ -0,0 +1,469 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: irplib_ppm.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>irplib_ppm.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: irplib_ppm.c,v 1.30 2011/11/23 13:58:45 yjung Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the irplib package</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: yjung $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2011/11/23 13:58:45 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.30 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span>
+<a name="l00032"></a>00032 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                                   Includes</span>
+<a name="l00034"></a>00034 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 
+<a name="l00036"></a>00036 <span class="preprocessor">#include <math.h></span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00038"></a>00038 
+<a name="l00039"></a>00039 <span class="preprocessor">#include "irplib_ppm.h"</span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include "irplib_wlxcorr.h"</span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include "irplib_spectrum.h"</span>
+<a name="l00042"></a>00042 
+<a name="l00043"></a>00043 <span class="comment">/* TEMPORARY SUPPORT OF CPL 5.x */</span>
+<a name="l00044"></a>00044 <span class="preprocessor">#ifndef CPL_SIZE_FORMAT</span>
+<a name="l00045"></a>00045 <span class="preprocessor"></span><span class="preprocessor">#define CPL_SIZE_FORMAT "d"</span>
+<a name="l00046"></a>00046 <span class="preprocessor"></span><span class="preprocessor">#define cpl_size int</span>
+<a name="l00047"></a>00047 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
+<a name="l00048"></a>00048 <span class="preprocessor"></span><span class="comment">/* END TEMPORARY SUPPORT OF CPL 5.x */</span>
+<a name="l00049"></a>00049 
+<a name="l00050"></a>00050 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00051"></a>00051 <span class="comment">                                   Private functions</span>
+<a name="l00052"></a>00052 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00053"></a>00053 <span class="preprocessor">#ifdef IRPLIB_PPM_USE_METHOD2</span>
+<a name="l00054"></a>00054 <span class="preprocessor"></span><span class="keyword">static</span> cpl_vector * irplib_ppm_convolve_line(<span class="keyword">const</span> cpl_vector *, <span class="keywordtype">double</span>,<span class="keywordtype">double</span>);
+<a name="l00055"></a>00055 <span class="keyword">static</span> cpl_vector * irplib_ppm_detect_lines(<span class="keyword">const</span> cpl_vector *, <span class="keywordtype">double</span>) ;
+<a name="l00056"></a>00056 <span class="preprocessor">#endif</span>
+<a name="l00057"></a>00057 <span class="preprocessor"></span>
+<a name="l00058"></a>00058 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00062"></a>00062 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00063"></a>00063 
+<a name="l00066"></a>00066 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00083"></a>00083 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00084"></a><a class="code" href="group__irplib__ppm.html#ga9b49569fb0bd55977b533407c1ad956d">00084</a> cpl_polynomial * <a class="code" href="group__irplib__ppm.html#ga9b49569fb0bd55977b533407c1ad956d" title="The Wavelength Calibration using PPM.">irplib_ppm_engine</a>(
+<a name="l00085"></a>00085         <span class="keyword">const</span> cpl_vector        *   spectrum,
+<a name="l00086"></a>00086         <span class="keyword">const</span> cpl_bivector      *   lines_catalog,
+<a name="l00087"></a>00087         <span class="keyword">const</span> cpl_polynomial    *   poly_init,
+<a name="l00088"></a>00088         <span class="keywordtype">double</span>                      slitw,
+<a name="l00089"></a>00089         <span class="keywordtype">double</span>                      fwhm,
+<a name="l00090"></a>00090         <span class="keywordtype">double</span>                      thresh,
+<a name="l00091"></a>00091         <span class="keywordtype">int</span>                         degree,
+<a name="l00092"></a>00092         <span class="keywordtype">int</span>                         doplot,
+<a name="l00093"></a>00093         cpl_table               **  tab_infos)
+<a name="l00094"></a>00094 {
+<a name="l00095"></a>00095 <span class="preprocessor">#ifdef IRPLIB_PPM_USE_METHOD2</span>
+<a name="l00096"></a>00096 <span class="preprocessor"></span>    cpl_vector      *   spec_conv ;
+<a name="l00097"></a>00097 <span class="preprocessor">#endif</span>
+<a name="l00098"></a>00098 <span class="preprocessor"></span>    <span class="keywordtype">int</span>                 spec_sz ;
+<a name="l00099"></a>00099     cpl_vector      *   det_lines ;
+<a name="l00100"></a>00100     <span class="keywordtype">double</span>          *   pdet_lines ;
+<a name="l00101"></a>00101     cpl_vector      *   cat_lines ;
+<a name="l00102"></a>00102     <span class="keywordtype">double</span>          *   pcat_lines ;
+<a name="l00103"></a>00103     <span class="keywordtype">double</span>              wmin, wmax ;
+<a name="l00104"></a>00104     <span class="keywordtype">double</span>              disp_min, disp_max, disp ;
+<a name="l00105"></a>00105     <span class="keywordtype">int</span>                 nlines_cat, nlines ;
+<a name="l00106"></a>00106     <span class="keyword">const</span> <span class="keywordtype">double</span>    *   plines_catalog_x ;
+<a name="l00107"></a>00107     <span class="keyword">const</span> <span class="keywordtype">double</span>    *   plines_catalog_y ;
+<a name="l00108"></a>00108     cpl_bivector    *   matched ;
+<a name="l00109"></a>00109     cpl_matrix      *   matchedx;
+<a name="l00110"></a>00110     <span class="keywordtype">int</span>                 match_sz;
+<a name="l00111"></a>00111     cpl_polynomial  *   fitted ;
+<a name="l00112"></a>00112     cpl_table       *   spc_table ;
+<a name="l00113"></a>00113     <span class="keyword">const</span> cpl_vector*   vectors_plot[3];
+<a name="l00114"></a>00114     cpl_vector      *   plot_y ;
+<a name="l00115"></a>00115     <span class="keywordtype">int</span>                 wl_ind, start_ind, stop_ind ;
+<a name="l00116"></a>00116     <span class="keywordtype">double</span>              fill_val ;
+<a name="l00117"></a>00117     cpl_size            deg_loc ;
+<a name="l00118"></a>00118     <span class="keywordtype">int</span>                 i ;
+<a name="l00119"></a>00119     cpl_error_code      error;
+<a name="l00120"></a>00120 
+<a name="l00121"></a>00121     <span class="comment">/* Check entries */</span>
+<a name="l00122"></a>00122     <span class="keywordflow">if</span> (spectrum == NULL) <span class="keywordflow">return</span> NULL ;
+<a name="l00123"></a>00123     <span class="keywordflow">if</span> (lines_catalog == NULL) <span class="keywordflow">return</span> NULL ;
+<a name="l00124"></a>00124     <span class="keywordflow">if</span> (poly_init == NULL) <span class="keywordflow">return</span> NULL ;
+<a name="l00125"></a>00125 
+<a name="l00126"></a>00126     <span class="comment">/* Initialise */</span>
+<a name="l00127"></a>00127     spec_sz = cpl_vector_get_size(spectrum) ;
+<a name="l00128"></a>00128     deg_loc = (cpl_size)degree ;
+<a name="l00129"></a>00129    
+<a name="l00130"></a>00130 <span class="preprocessor">#ifdef IRPLIB_PPM_USE_METHOD2</span>
+<a name="l00131"></a>00131 <span class="preprocessor"></span>    <span class="comment">/* METHOD 2 */</span>
+<a name="l00132"></a>00132     <span class="comment">/* Correlate the spectrum with the line profile */</span>
+<a name="l00133"></a>00133     <span class="keywordflow">if</span> ((spec_conv = irplib_ppm_convolve_line(spectrum, slitw, fwhm)) == NULL) {
+<a name="l00134"></a>00134         cpl_msg_error(cpl_func, <span class="stringliteral">"Cannot convolve the signal"</span>) ;
+<a name="l00135"></a>00135         <span class="keywordflow">return</span> NULL ;
+<a name="l00136"></a>00136     }
+<a name="l00137"></a>00137    
+<a name="l00138"></a>00138     <span class="comment">/* Apply the lines detection */</span>
+<a name="l00139"></a>00139     <span class="keywordflow">if</span> ((det_lines = irplib_ppm_detect_lines(spec_conv, 0.9)) == NULL) {
+<a name="l00140"></a>00140         cpl_msg_error(cpl_func, <span class="stringliteral">"Cannot detect lines"</span>) ;
+<a name="l00141"></a>00141         cpl_vector_delete(spec_conv) ;
+<a name="l00142"></a>00142         <span class="keywordflow">return</span> NULL ;
+<a name="l00143"></a>00143     }
+<a name="l00144"></a>00144     cpl_vector_delete(spec_conv) ;
+<a name="l00145"></a>00145 <span class="preprocessor">#else</span>
+<a name="l00146"></a>00146 <span class="preprocessor"></span>    <span class="comment">/* METHOD 1 */</span>
+<a name="l00147"></a>00147     <span class="keywordflow">if</span> ((det_lines = <a class="code" href="group__irplib__spectrum.html#ga1885902c29d7383674c85e2c3d935961" title="Detect the brightest features in a spectrum.">irplib_spectrum_detect_peaks</a>(spectrum, fwhm,
+<a name="l00148"></a>00148                     thresh, 0, NULL, NULL)) == NULL) {
+<a name="l00149"></a>00149         cpl_msg_error(cpl_func, <span class="stringliteral">"Cannot convolve the signal"</span>) ;
+<a name="l00150"></a>00150         <span class="keywordflow">return</span> NULL ;
+<a name="l00151"></a>00151     }
+<a name="l00152"></a>00152 <span class="preprocessor">#endif</span>
+<a name="l00153"></a>00153 <span class="preprocessor"></span>    cpl_msg_info(cpl_func, <span class="stringliteral">"Detected %"</span>CPL_SIZE_FORMAT<span class="stringliteral">" lines"</span>, 
+<a name="l00154"></a>00154             cpl_vector_get_size(det_lines));
+<a name="l00155"></a>00155  
+<a name="l00156"></a>00156     <span class="comment">/* Get the catalog lines */</span>
+<a name="l00157"></a>00157     wmin = cpl_polynomial_eval_1d(poly_init, 1.0, NULL) ;
+<a name="l00158"></a>00158     wmax = cpl_polynomial_eval_1d(poly_init, spec_sz, NULL) ;
+<a name="l00159"></a>00159     plines_catalog_x = cpl_bivector_get_x_data_const(lines_catalog) ;
+<a name="l00160"></a>00160     plines_catalog_y = cpl_bivector_get_y_data_const(lines_catalog) ;
+<a name="l00161"></a>00161     nlines = cpl_bivector_get_size(lines_catalog) ;
+<a name="l00162"></a>00162     nlines_cat = 0 ;
+<a name="l00163"></a>00163     start_ind = stop_ind = -1 ;
+<a name="l00164"></a>00164     <span class="keywordflow">for</span> (i=0 ; i<nlines ; i++) {
+<a name="l00165"></a>00165         <span class="keywordflow">if</span> (plines_catalog_x[i] > wmin && plines_catalog_x[i] < wmax &&
+<a name="l00166"></a>00166                 plines_catalog_y[i] > 0.0) {
+<a name="l00167"></a>00167             nlines_cat++ ;
+<a name="l00168"></a>00168             <span class="keywordflow">if</span> (start_ind<0) start_ind = i ;
+<a name="l00169"></a>00169             stop_ind = i ;
+<a name="l00170"></a>00170         }
+<a name="l00171"></a>00171     }
+<a name="l00172"></a>00172     <span class="keywordflow">if</span> (nlines_cat == 0) {
+<a name="l00173"></a>00173         cpl_msg_error(cpl_func, <span class="stringliteral">"No lines in catalog"</span>) ;
+<a name="l00174"></a>00174         cpl_vector_delete(det_lines) ;
+<a name="l00175"></a>00175         <span class="keywordflow">return</span> NULL ;
+<a name="l00176"></a>00176     }
+<a name="l00177"></a>00177     cat_lines = cpl_vector_new(nlines_cat) ;
+<a name="l00178"></a>00178     pcat_lines = cpl_vector_get_data(cat_lines) ;
+<a name="l00179"></a>00179     nlines_cat = 0 ;
+<a name="l00180"></a>00180     <span class="keywordflow">for</span> (i=0 ; i<nlines ; i++) {
+<a name="l00181"></a>00181         <span class="keywordflow">if</span> (plines_catalog_x[i] > wmin && plines_catalog_x[i] < wmax &&
+<a name="l00182"></a>00182                 plines_catalog_y[i] > 0.0) {
+<a name="l00183"></a>00183             pcat_lines[nlines_cat] = plines_catalog_x[i] ; 
+<a name="l00184"></a>00184             nlines_cat++ ;
+<a name="l00185"></a>00185         }
+<a name="l00186"></a>00186     }
+<a name="l00187"></a>00187  
+<a name="l00188"></a>00188     <span class="comment">/* Plot inputs */</span>
+<a name="l00189"></a>00189     <span class="keywordflow">if</span> (doplot) {
+<a name="l00190"></a>00190         <span class="comment">/* Catalog */</span>
+<a name="l00191"></a>00191         irplib_wlxcorr_catalog_plot(lines_catalog, wmin, wmax) ;
+<a name="l00192"></a>00192 
+<a name="l00193"></a>00193         <span class="comment">/* Spectrum with detected lines */</span>
+<a name="l00194"></a>00194         fill_val = cpl_vector_get_max(spectrum) ;
+<a name="l00195"></a>00195         plot_y = cpl_vector_new(spec_sz);
+<a name="l00196"></a>00196         cpl_vector_fill(plot_y, 0.0) ;
+<a name="l00197"></a>00197         pdet_lines = cpl_vector_get_data(det_lines) ;
+<a name="l00198"></a>00198         <span class="keywordflow">for</span> (i=0 ; i<cpl_vector_get_size(det_lines) ; i++) {
+<a name="l00199"></a>00199             cpl_vector_set(plot_y, (<span class="keywordtype">int</span>)pdet_lines[i], fill_val) ;
+<a name="l00200"></a>00200         }
+<a name="l00201"></a>00201         vectors_plot[0] = NULL ;
+<a name="l00202"></a>00202         vectors_plot[1] = spectrum ;
+<a name="l00203"></a>00203         vectors_plot[2] = plot_y ;
+<a name="l00204"></a>00204 
+<a name="l00205"></a>00205         cpl_plot_vectors(<span class="stringliteral">"set grid;set xlabel 'Position (Pixel)';set ylabel "</span>
+<a name="l00206"></a>00206                             <span class="stringliteral">"'Intensity (ADU/sec)';"</span>,
+<a name="l00207"></a>00207                             <span class="stringliteral">"t 'Spectrum with detected lines' w lines"</span>, <span class="stringliteral">""</span>,
+<a name="l00208"></a>00208                             vectors_plot, 3);
+<a name="l00209"></a>00209         cpl_vector_delete(plot_y) ;
+<a name="l00210"></a>00210     }
+<a name="l00211"></a>00211    
+<a name="l00212"></a>00212     <span class="comment">/* Apply the point pattern matching */</span>
+<a name="l00213"></a>00213     disp = (wmax-wmin) / spec_sz ;
+<a name="l00214"></a>00214     disp_min = disp - (disp/10) ;
+<a name="l00215"></a>00215     disp_max = disp + (disp/10) ;
+<a name="l00216"></a>00216     matched = cpl_ppm_match_positions(det_lines, cat_lines, disp_min,
+<a name="l00217"></a>00217                                       disp_max, 0.05, NULL, NULL);
+<a name="l00218"></a>00218     cpl_vector_delete(det_lines) ;
+<a name="l00219"></a>00219     cpl_vector_delete(cat_lines) ;
+<a name="l00220"></a>00220 
+<a name="l00221"></a>00221     <span class="keywordflow">if</span> (matched == NULL) {
+<a name="l00222"></a>00222         cpl_msg_error(cpl_func, <span class="stringliteral">"Cannot apply the point pattern matching"</span>) ;
+<a name="l00223"></a>00223         <span class="keywordflow">return</span> NULL ;
+<a name="l00224"></a>00224     }
+<a name="l00225"></a>00225 
+<a name="l00226"></a>00226     match_sz = cpl_bivector_get_size(matched);
+<a name="l00227"></a>00227 
+<a name="l00228"></a>00228     cpl_msg_info(cpl_func, <span class="stringliteral">"Matched %d lines"</span>, match_sz) ;
+<a name="l00229"></a>00229 
+<a name="l00230"></a>00230     <span class="keywordflow">if</span> (match_sz <= deg_loc) {
+<a name="l00231"></a>00231         cpl_msg_error(cpl_func, <span class="stringliteral">"Not enough match for the fit"</span>) ;
+<a name="l00232"></a>00232         cpl_bivector_delete(matched) ;
+<a name="l00233"></a>00233         <span class="keywordflow">return</span> NULL ;
+<a name="l00234"></a>00234     }
+<a name="l00235"></a>00235     
+<a name="l00236"></a>00236     <span class="comment">/* Plot if requested */</span>
+<a name="l00237"></a>00237     <span class="keywordflow">if</span> (doplot) {
+<a name="l00238"></a>00238         <span class="keyword">const</span> <span class="keywordtype">double</span>    *   pmatched ;
+<a name="l00239"></a>00239         cpl_bivector    *   biplot ;
+<a name="l00240"></a>00240         cpl_vector      *   plot_cat_x ;
+<a name="l00241"></a>00241         cpl_vector      *   plot_cat_y ;
+<a name="l00242"></a>00242         <span class="comment">/* Spectrum with matched lines */</span>
+<a name="l00243"></a>00243         fill_val = cpl_vector_get_max(spectrum) ;
+<a name="l00244"></a>00244         plot_y = cpl_vector_new(spec_sz);
+<a name="l00245"></a>00245         cpl_vector_fill(plot_y, 0.0) ;
+<a name="l00246"></a>00246         pmatched = cpl_bivector_get_x_data_const(matched) ;
+<a name="l00247"></a>00247         <span class="keywordflow">for</span> (i=0 ; i < match_sz; i++) {
+<a name="l00248"></a>00248             cpl_vector_set(plot_y, (<span class="keywordtype">int</span>)pmatched[i], fill_val) ;
+<a name="l00249"></a>00249         }
+<a name="l00250"></a>00250         vectors_plot[0] = NULL ;
+<a name="l00251"></a>00251         vectors_plot[1] = spectrum ;
+<a name="l00252"></a>00252         vectors_plot[2] = plot_y ;
+<a name="l00253"></a>00253 
+<a name="l00254"></a>00254         cpl_plot_vectors(<span class="stringliteral">"set grid;set xlabel 'Position (Pixel)';set ylabel "</span>
+<a name="l00255"></a>00255                             <span class="stringliteral">"'Intensity (ADU/sec)';"</span>,
+<a name="l00256"></a>00256                             <span class="stringliteral">"t 'Spectrum with matched lines' w lines"</span>, <span class="stringliteral">""</span>,
+<a name="l00257"></a>00257                             vectors_plot, 3);
+<a name="l00258"></a>00258         cpl_vector_delete(plot_y) ;
+<a name="l00259"></a>00259 
+<a name="l00260"></a>00260         <span class="comment">/* Catalog with matched lines */</span>
+<a name="l00261"></a>00261         plot_cat_x=cpl_vector_extract(cpl_bivector_get_x_const(lines_catalog), 
+<a name="l00262"></a>00262                 start_ind, stop_ind, 1) ;
+<a name="l00263"></a>00263         plot_cat_y=cpl_vector_extract(cpl_bivector_get_y_const(lines_catalog), 
+<a name="l00264"></a>00264                 start_ind, stop_ind, 1) ;
+<a name="l00265"></a>00265         biplot = cpl_bivector_wrap_vectors(plot_cat_x, plot_cat_y) ;
+<a name="l00266"></a>00266         cpl_plot_bivector(<span class="stringliteral">"set grid;set xlabel 'Wavelength';set ylabel "</span>
+<a name="l00267"></a>00267                              <span class="stringliteral">"'Emission';"</span>, <span class="stringliteral">"t 'Catalog' w impulses"</span>, <span class="stringliteral">""</span>,
+<a name="l00268"></a>00268                              biplot);
+<a name="l00269"></a>00269         cpl_bivector_unwrap_vectors(biplot) ;
+<a name="l00270"></a>00270 
+<a name="l00271"></a>00271         plot_y = cpl_vector_duplicate(plot_cat_y) ;
+<a name="l00272"></a>00272         cpl_vector_fill(plot_y, 0.0) ;
+<a name="l00273"></a>00273         pmatched = cpl_bivector_get_y_data_const(matched) ;
+<a name="l00274"></a>00274         fill_val=cpl_vector_get_mean(plot_cat_y) ;
+<a name="l00275"></a>00275         <span class="keywordflow">for</span> (i=0 ; i < match_sz; i++) {
+<a name="l00276"></a>00276             wl_ind = 0 ;
+<a name="l00277"></a>00277             <span class="keywordflow">while</span> (pmatched[i] > cpl_vector_get(plot_cat_x, wl_ind) 
+<a name="l00278"></a>00278                     && wl_ind < spec_sz) wl_ind++ ;
+<a name="l00279"></a>00279             <span class="keywordflow">if</span> (wl_ind < spec_sz) cpl_vector_set(plot_y, wl_ind, fill_val) ;
+<a name="l00280"></a>00280         }
+<a name="l00281"></a>00281         biplot = cpl_bivector_wrap_vectors(plot_cat_x, plot_y) ;
+<a name="l00282"></a>00282         cpl_plot_bivector(<span class="stringliteral">"set grid;set xlabel 'Wavelength';set ylabel "</span>
+<a name="l00283"></a>00283                              <span class="stringliteral">"'Emission';"</span>, <span class="stringliteral">"t 'Catalog (matched lines)' w "</span>
+<a name="l00284"></a>00284                              <span class="stringliteral">"impulses"</span>, <span class="stringliteral">""</span>, biplot) ;
+<a name="l00285"></a>00285         cpl_bivector_unwrap_vectors(biplot) ;
+<a name="l00286"></a>00286         cpl_vector_delete(plot_cat_x) ;
+<a name="l00287"></a>00287         cpl_vector_delete(plot_cat_y) ;
+<a name="l00288"></a>00288         cpl_vector_delete(plot_y) ;
+<a name="l00289"></a>00289     }
+<a name="l00290"></a>00290     
+<a name="l00291"></a>00291     <span class="comment">/* Apply the fit */</span>
+<a name="l00292"></a>00292     matchedx = cpl_matrix_wrap(1, match_sz, cpl_bivector_get_x_data(matched));
+<a name="l00293"></a>00293     fitted = cpl_polynomial_new(1);
+<a name="l00294"></a>00294     error = cpl_polynomial_fit(fitted, matchedx, NULL,
+<a name="l00295"></a>00295                                cpl_bivector_get_y_const(matched), NULL,
+<a name="l00296"></a>00296                                CPL_FALSE, NULL, &deg_loc);
+<a name="l00297"></a>00297     cpl_bivector_delete(matched);
+<a name="l00298"></a>00298     (void)cpl_matrix_unwrap(matchedx);
+<a name="l00299"></a>00299     <span class="keywordflow">if</span> (error) {
+<a name="l00300"></a>00300         cpl_msg_error(cpl_func, <span class="stringliteral">"Cannot fit the polynomial"</span>) ;
+<a name="l00301"></a>00301         cpl_polynomial_delete(fitted);
+<a name="l00302"></a>00302         <span class="keywordflow">return</span> NULL ;
+<a name="l00303"></a>00303     }
+<a name="l00304"></a>00304    
+<a name="l00305"></a>00305     <span class="comment">/* Create the infos table */</span>
+<a name="l00306"></a>00306     <span class="keywordflow">if</span> ((spc_table = irplib_wlxcorr_gen_spc_table(spectrum,
+<a name="l00307"></a>00307                     lines_catalog, slitw, fwhm, poly_init, fitted)) == NULL) {
+<a name="l00308"></a>00308         cpl_msg_error(cpl_func, <span class="stringliteral">"Cannot generate the infos table"</span>) ;
+<a name="l00309"></a>00309         cpl_polynomial_delete(fitted) ;
+<a name="l00310"></a>00310         <span class="keywordflow">return</span> NULL ;
+<a name="l00311"></a>00311     }
+<a name="l00312"></a>00312     <span class="keywordflow">if</span> (tab_infos != NULL) *tab_infos = spc_table ;
+<a name="l00313"></a>00313     <span class="keywordflow">else</span> cpl_table_delete(spc_table) ;
+<a name="l00314"></a>00314     <span class="keywordflow">return</span> fitted ;
+<a name="l00315"></a>00315 }
+<a name="l00316"></a>00316 
+<a name="l00319"></a>00319 <span class="preprocessor">#ifdef IRPLIB_PPM_USE_METHOD2</span>
+<a name="l00320"></a>00320 <span class="preprocessor"></span><span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00331"></a>00331 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00332"></a>00332 <span class="keyword">static</span> cpl_vector * irplib_ppm_convolve_line(
+<a name="l00333"></a>00333         <span class="keyword">const</span> cpl_vector        *   spectrum,
+<a name="l00334"></a>00334         <span class="keywordtype">double</span>                      slitw,
+<a name="l00335"></a>00335         <span class="keywordtype">double</span>                      fwhm)
+<a name="l00336"></a>00336 {
+<a name="l00337"></a>00337     cpl_vector  *   conv_kernel ;
+<a name="l00338"></a>00338     cpl_vector  *   line_profile ;
+<a name="l00339"></a>00339     cpl_vector  *   xcorrs ;
+<a name="l00340"></a>00340     cpl_vector  *   spec_ext ;
+<a name="l00341"></a>00341     cpl_vector  *   xc_single ;
+<a name="l00342"></a>00342     <span class="keywordtype">int</span>             hs, line_sz, sp_sz ;
+<a name="l00343"></a>00343     <span class="keywordtype">int</span>             i ;
+<a name="l00344"></a>00344 
+<a name="l00345"></a>00345     <span class="comment">/* Test entries */</span>
+<a name="l00346"></a>00346     <span class="keywordflow">if</span> (spectrum == NULL) <span class="keywordflow">return</span> NULL ;
+<a name="l00347"></a>00347 
+<a name="l00348"></a>00348     <span class="comment">/* Create the convolution kernel */</span>
+<a name="l00349"></a>00349     <span class="keywordflow">if</span> ((conv_kernel = irplib_wlxcorr_convolve_create_kernel(slitw,
+<a name="l00350"></a>00350                     fwhm)) == NULL) {
+<a name="l00351"></a>00351         cpl_msg_error(cpl_func, <span class="stringliteral">"Cannot create kernel"</span>) ;
+<a name="l00352"></a>00352         <span class="keywordflow">return</span> NULL ;
+<a name="l00353"></a>00353     }
+<a name="l00354"></a>00354     hs = cpl_vector_get_size(conv_kernel) ;
+<a name="l00355"></a>00355     line_sz = 2 * hs + 1 ;
+<a name="l00356"></a>00356     
+<a name="l00357"></a>00357     <span class="comment">/* Create the line profile */</span>
+<a name="l00358"></a>00358     line_profile = cpl_vector_new(line_sz) ;
+<a name="l00359"></a>00359     cpl_vector_fill(line_profile, 0.0) ;
+<a name="l00360"></a>00360     cpl_vector_set(line_profile, hs, 1.0) ;
+<a name="l00361"></a>00361     <span class="keywordflow">if</span> (irplib_wlxcorr_convolve(line_profile, conv_kernel) != 0) {
+<a name="l00362"></a>00362         cpl_msg_error(cpl_func, <span class="stringliteral">"Cannot create line profile"</span>) ;
+<a name="l00363"></a>00363         cpl_vector_delete(line_profile) ;
+<a name="l00364"></a>00364         cpl_vector_delete(conv_kernel) ;
+<a name="l00365"></a>00365         <span class="keywordflow">return</span> NULL ;
+<a name="l00366"></a>00366     }
+<a name="l00367"></a>00367     cpl_vector_delete(conv_kernel) ;
+<a name="l00368"></a>00368     
+<a name="l00369"></a>00369     <span class="comment">/* Create the correlations values vector */</span>
+<a name="l00370"></a>00370     sp_sz = cpl_vector_get_size(spectrum) ;
+<a name="l00371"></a>00371     xcorrs = cpl_vector_new(sp_sz) ;
+<a name="l00372"></a>00372     cpl_vector_fill(xcorrs, 0.0) ;
+<a name="l00373"></a>00373     xc_single = cpl_vector_new(1) ;
+<a name="l00374"></a>00374 
+<a name="l00375"></a>00375     <span class="comment">/* Loop on the pixels of the spectrum */</span>
+<a name="l00376"></a>00376     <span class="keywordflow">for</span> (i=hs ; i<sp_sz-hs ; i++) {
+<a name="l00377"></a>00377         <span class="comment">/* Extract the current spectrum part */</span>
+<a name="l00378"></a>00378         <span class="keywordflow">if</span> ((spec_ext = cpl_vector_extract(spectrum, i-hs, i+hs, 1)) == NULL) {
+<a name="l00379"></a>00379             cpl_msg_error(cpl_func, <span class="stringliteral">"Cannot extract spectrum"</span>) ;
+<a name="l00380"></a>00380             cpl_vector_delete(xc_single) ;
+<a name="l00381"></a>00381             cpl_vector_delete(line_profile) ;
+<a name="l00382"></a>00382             <span class="keywordflow">return</span> NULL ;
+<a name="l00383"></a>00383         }
+<a name="l00384"></a>00384         <span class="keywordflow">if</span> (cpl_vector_correlate(xc_single, spec_ext, line_profile) < 0) {
+<a name="l00385"></a>00385             cpl_msg_error(cpl_func, <span class="stringliteral">"Cannot correlate"</span>) ;
+<a name="l00386"></a>00386             cpl_vector_delete(xc_single) ;
+<a name="l00387"></a>00387             cpl_vector_delete(line_profile) ;
+<a name="l00388"></a>00388             cpl_vector_delete(spec_ext) ;
+<a name="l00389"></a>00389             <span class="keywordflow">return</span> NULL ;
+<a name="l00390"></a>00390         }
+<a name="l00391"></a>00391         cpl_vector_set(xcorrs, i, cpl_vector_get(xc_single, 0)) ;
+<a name="l00392"></a>00392         cpl_vector_delete(spec_ext) ;
+<a name="l00393"></a>00393     }
+<a name="l00394"></a>00394     cpl_vector_delete(xc_single) ;
+<a name="l00395"></a>00395     cpl_vector_delete(line_profile) ;
+<a name="l00396"></a>00396 
+<a name="l00397"></a>00397     <span class="keywordflow">return</span> xcorrs ;
+<a name="l00398"></a>00398 } 
+<a name="l00399"></a>00399 
+<a name="l00400"></a>00400 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00409"></a>00409 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00410"></a>00410 <span class="keyword">static</span> cpl_vector * irplib_ppm_detect_lines(
+<a name="l00411"></a>00411         <span class="keyword">const</span> cpl_vector    *   spec,
+<a name="l00412"></a>00412         <span class="keywordtype">double</span>                  threshold)
+<a name="l00413"></a>00413 {
+<a name="l00414"></a>00414     cpl_vector  *   spec_loc ;
+<a name="l00415"></a>00415     <span class="keywordtype">double</span>      *   pspec_loc ;
+<a name="l00416"></a>00416     cpl_vector  *   lines ;
+<a name="l00417"></a>00417     <span class="keywordtype">double</span>      *   plines ;
+<a name="l00418"></a>00418     <span class="keywordtype">int</span>             spec_loc_sz, max_ind, nlines ;
+<a name="l00419"></a>00419     <span class="keywordtype">double</span>          max ;
+<a name="l00420"></a>00420     <span class="keywordtype">int</span>             i ;
+<a name="l00421"></a>00421 
+<a name="l00422"></a>00422     <span class="comment">/* Test inputs */</span>
+<a name="l00423"></a>00423     <span class="keywordflow">if</span> (spec == NULL) <span class="keywordflow">return</span> NULL ;
+<a name="l00424"></a>00424 
+<a name="l00425"></a>00425     <span class="comment">/* Local spectrum */</span>
+<a name="l00426"></a>00426     spec_loc = cpl_vector_duplicate(spec) ;
+<a name="l00427"></a>00427     pspec_loc = cpl_vector_get_data(spec_loc) ;
+<a name="l00428"></a>00428     spec_loc_sz = cpl_vector_get_size(spec_loc) ;
+<a name="l00429"></a>00429 
+<a name="l00430"></a>00430     <span class="comment">/* Threshold the local spectrum */</span>
+<a name="l00431"></a>00431     <span class="keywordflow">for</span> (i=0 ; i<spec_loc_sz ; i++) 
+<a name="l00432"></a>00432         <span class="keywordflow">if</span> (pspec_loc[i] < threshold) pspec_loc[i] = 0.0 ;
+<a name="l00433"></a>00433     
+<a name="l00434"></a>00434     <span class="comment">/* Allocate lines container */</span>
+<a name="l00435"></a>00435     lines = cpl_vector_new(spec_loc_sz) ;
+<a name="l00436"></a>00436     plines = cpl_vector_get_data(lines) ;
+<a name="l00437"></a>00437     nlines = 0 ;
+<a name="l00438"></a>00438     
+<a name="l00439"></a>00439     <span class="comment">/* Loop as long as there are lines */</span>
+<a name="l00440"></a>00440     <span class="keywordflow">while</span> ((max = cpl_vector_get_max(spec_loc)) > threshold) {
+<a name="l00441"></a>00441         <span class="comment">/* Find the max position */</span>
+<a name="l00442"></a>00442         max_ind = 0 ;
+<a name="l00443"></a>00443         <span class="keywordflow">while</span> (pspec_loc[max_ind]<max && max_ind<spec_loc_sz) max_ind++ ;
+<a name="l00444"></a>00444         <span class="keywordflow">if</span> (max_ind == spec_loc_sz) {
+<a name="l00445"></a>00445             cpl_msg_error(cpl_func, <span class="stringliteral">"Cannot find maximum"</span>) ;
+<a name="l00446"></a>00446             cpl_vector_delete(spec_loc) ;
+<a name="l00447"></a>00447             cpl_vector_delete(lines) ;
+<a name="l00448"></a>00448             <span class="keywordflow">return</span> NULL ;
+<a name="l00449"></a>00449         }
+<a name="l00450"></a>00450         <span class="keywordflow">if</span> (max_ind == 0 || max_ind == spec_loc_sz-1) {
+<a name="l00451"></a>00451             pspec_loc[max_ind] = 0 ;
+<a name="l00452"></a>00452             continue ;
+<a name="l00453"></a>00453         }
+<a name="l00454"></a>00454 
+<a name="l00455"></a>00455         <span class="comment">/* Get the precise position from the neighbours values */</span>
+<a name="l00456"></a>00456         plines[nlines] =    pspec_loc[max_ind] * max_ind + 
+<a name="l00457"></a>00457                             pspec_loc[max_ind-1] * (max_ind-1) +
+<a name="l00458"></a>00458                             pspec_loc[max_ind+1] * (max_ind+1) ; 
+<a name="l00459"></a>00459         plines[nlines] /= pspec_loc[max_ind] + pspec_loc[max_ind+1] +
+<a name="l00460"></a>00460             pspec_loc[max_ind-1] ;
+<a name="l00461"></a>00461         plines[nlines] ++ ;
+<a name="l00462"></a>00462         nlines ++ ;
+<a name="l00463"></a>00463 
+<a name="l00464"></a>00464         <span class="comment">/* Clean the line */</span>
+<a name="l00465"></a>00465         i = max_ind ;
+<a name="l00466"></a>00466         <span class="keywordflow">while</span> (i>=0 && pspec_loc[i] > threshold) {
+<a name="l00467"></a>00467             pspec_loc[i] = 0.0 ;
+<a name="l00468"></a>00468             i-- ;
+<a name="l00469"></a>00469         }
+<a name="l00470"></a>00470         i = max_ind+1 ;
+<a name="l00471"></a>00471         <span class="keywordflow">while</span> (i<spec_loc_sz && pspec_loc[i] > threshold) {
+<a name="l00472"></a>00472             pspec_loc[i] = 0.0 ;
+<a name="l00473"></a>00473             i++ ;
+<a name="l00474"></a>00474         }
+<a name="l00475"></a>00475     }
+<a name="l00476"></a>00476     cpl_vector_delete(spec_loc) ;
+<a name="l00477"></a>00477    
+<a name="l00478"></a>00478     <span class="comment">/* Check if there are lines */</span>
+<a name="l00479"></a>00479     <span class="keywordflow">if</span> (nlines == 0) {
+<a name="l00480"></a>00480         cpl_msg_error(cpl_func, <span class="stringliteral">"Cannot detect any line"</span>) ;
+<a name="l00481"></a>00481         cpl_vector_delete(lines) ;
+<a name="l00482"></a>00482         <span class="keywordflow">return</span> NULL ;
+<a name="l00483"></a>00483     }
+<a name="l00484"></a>00484     
+<a name="l00485"></a>00485     <span class="comment">/* Resize the vector */</span>
+<a name="l00486"></a>00486     cpl_vector_set_size(lines, nlines) ;
+<a name="l00487"></a>00487 
+<a name="l00488"></a>00488     <span class="comment">/* Sort the lines */</span>
+<a name="l00489"></a>00489     cpl_vector_sort(lines, 1) ;
+<a name="l00490"></a>00490     
+<a name="l00491"></a>00491     <span class="keywordflow">return</span> lines ;
+<a name="l00492"></a>00492 }
+<a name="l00493"></a>00493 
+<a name="l00494"></a>00494 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/irplib__ppm_8h_source.html b/html/irplib__ppm_8h_source.html
new file mode 100644
index 0000000..ebead8a
--- /dev/null
+++ b/html/irplib__ppm_8h_source.html
@@ -0,0 +1,56 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: irplib_ppm.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>irplib_ppm.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: irplib_ppm.h,v 1.5 2007/07/23 09:27:07 yjung Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the irplib package</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: yjung $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2007/07/23 09:27:07 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.5 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifndef IRPLIB_PPM_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#define IRPLIB_PPM_H</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span>
+<a name="l00031"></a>00031 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00032"></a>00032 <span class="comment">                                   Includes</span>
+<a name="l00033"></a>00033 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00034"></a>00034 
+<a name="l00035"></a>00035 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 cpl_polynomial * <a class="code" href="group__irplib__ppm.html#ga9b49569fb0bd55977b533407c1ad956d" title="The Wavelength Calibration using PPM.">irplib_ppm_engine</a>(<span class="keyword">const</span> cpl_vector *, <span class="keyword">const</span> cpl_bivector *,
+<a name="l00038"></a>00038         <span class="keyword">const</span> cpl_polynomial *, <span class="keywordtype">double</span>, <span class="keywordtype">double</span>, <span class="keywordtype">double</span>, <span class="keywordtype">int</span>, <span class="keywordtype">int</span>, cpl_table **);
+<a name="l00039"></a>00039 
+<a name="l00040"></a>00040 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/irplib__slitpos_8c_source.html b/html/irplib__slitpos_8c_source.html
new file mode 100644
index 0000000..757055e
--- /dev/null
+++ b/html/irplib__slitpos_8c_source.html
@@ -0,0 +1,510 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: irplib_slitpos.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>irplib_slitpos.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: irplib_slitpos.c,v 1.30 2011/11/23 13:58:45 yjung Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the irplib package</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: yjung $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2011/11/23 13:58:45 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.30 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span>
+<a name="l00032"></a>00032 <span class="comment">/* The IRPLIB-based application may have checked for the availability of</span>
+<a name="l00033"></a>00033 <span class="comment">   memrchr() in which case the macro HAVE_DECL_MEMRCHR is defined as either</span>
+<a name="l00034"></a>00034 <span class="comment">   0 or 1. Without checks it is assumed that the function is not available.</span>
+<a name="l00035"></a>00035 <span class="comment">   With a suitable version of autoconf the macro can be defined with this</span>
+<a name="l00036"></a>00036 <span class="comment">   entry in configure.ac:</span>
+<a name="l00037"></a>00037 <span class="comment">   AC_CHECK_DECLS([memrchr])</span>
+<a name="l00038"></a>00038 <span class="comment">*/</span>
+<a name="l00039"></a>00039 
+<a name="l00040"></a>00040 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00041"></a>00041 <span class="comment">                                Includes</span>
+<a name="l00042"></a>00042 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00043"></a>00043 
+<a name="l00044"></a>00044 <span class="preprocessor">#include <string.h></span>
+<a name="l00045"></a>00045 <span class="preprocessor">#include <math.h></span>
+<a name="l00046"></a>00046 <span class="preprocessor">#include <assert.h></span>
+<a name="l00047"></a>00047 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00048"></a>00048 
+<a name="l00049"></a>00049 <span class="preprocessor">#include "irplib_slitpos.h"</span>
+<a name="l00050"></a>00050 <span class="preprocessor">#include "irplib_flat.h"</span>
+<a name="l00051"></a>00051 
+<a name="l00052"></a>00052 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00053"></a>00053 <span class="comment">                                Defines</span>
+<a name="l00054"></a>00054 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00055"></a>00055 
+<a name="l00056"></a>00056 <span class="comment">/* TEMPORARY SUPPORT OF CPL 5.x */</span>
+<a name="l00057"></a>00057 <span class="preprocessor">#ifndef CPL_SIZE_FORMAT</span>
+<a name="l00058"></a>00058 <span class="preprocessor"></span><span class="preprocessor">#define CPL_SIZE_FORMAT "d"</span>
+<a name="l00059"></a>00059 <span class="preprocessor"></span><span class="preprocessor">#define cpl_size int</span>
+<a name="l00060"></a>00060 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
+<a name="l00061"></a>00061 <span class="preprocessor"></span><span class="comment">/* END TEMPORARY SUPPORT OF CPL 5.x */</span>
+<a name="l00062"></a>00062 
+<a name="l00063"></a>00063 <span class="preprocessor">#ifndef IRPLIB_SLITPOS_KERNEL_SIZE_Y</span>
+<a name="l00064"></a>00064 <span class="preprocessor"></span><span class="preprocessor">#define IRPLIB_SLITPOS_KERNEL_SIZE_Y      5</span>
+<a name="l00065"></a>00065 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
+<a name="l00066"></a>00066 <span class="preprocessor"></span>
+<a name="l00067"></a>00067 <span class="preprocessor">#ifndef IRPLIB_SLITPOS_MAX_EROSION</span>
+<a name="l00068"></a>00068 <span class="preprocessor"></span><span class="preprocessor">#define IRPLIB_SLITPOS_MAX_EROSION     1024</span>
+<a name="l00069"></a>00069 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
+<a name="l00070"></a>00070 <span class="preprocessor"></span>
+<a name="l00071"></a>00071 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00072"></a>00072 <span class="comment">                            Functions prototypes</span>
+<a name="l00073"></a>00073 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00074"></a>00074 
+<a name="l00075"></a>00075 <span class="keyword">static</span> cpl_error_code irplib_slitpos_find_edges_one_line(<span class="keyword">const</span> cpl_image *,
+<a name="l00076"></a>00076                                                          <span class="keywordtype">int</span>, <span class="keywordtype">int</span> *, <span class="keywordtype">int</span> *);
+<a name="l00077"></a>00077 <span class="keyword">static</span> cpl_error_code irplib_slitpos_find_vert_slit_ends(<span class="keyword">const</span> cpl_image *,
+<a name="l00078"></a>00078                                                          <span class="keywordtype">int</span>, <span class="keywordtype">int</span> *, <span class="keywordtype">int</span> *);
+<a name="l00079"></a>00079 <span class="keyword">static</span> cpl_error_code irplib_slitpos_find_vert_pos(<span class="keyword">const</span> cpl_image *, <span class="keywordtype">int</span>,
+<a name="l00080"></a>00080                                                    cpl_size *);
+<a name="l00081"></a>00081 <span class="keyword">static</span> cpl_error_code irplib_image_filter_background_line(cpl_image *,
+<a name="l00082"></a>00082                                                    <span class="keyword">const</span> cpl_image *,
+<a name="l00083"></a>00083                                                    <span class="keywordtype">int</span>, cpl_boolean) ;
+<a name="l00084"></a>00084 
+<a name="l00085"></a>00085 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00089"></a>00089 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00090"></a>00090 
+<a name="l00092"></a>00092 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00118"></a>00118 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00119"></a><a class="code" href="group__irplib__slitpos.html#ga632b21eccf3d4bb48426cdd23f321cba">00119</a> cpl_table * <a class="code" href="group__irplib__slitpos.html#ga632b21eccf3d4bb48426cdd23f321cba" title="Detect the slit position, detect its ends, extract a thin image containing only the...">irplib_slitpos_analysis</a>(<span class="keyword">const</span> cpl_image * imslit,
+<a name="l00120"></a>00120                                     <span class="keywordtype">int</span>               slit_max_width,
+<a name="l00121"></a>00121                                     <span class="keywordtype">double</span>          * slit_flux)
+<a name="l00122"></a>00122 {
+<a name="l00123"></a>00123     <span class="keyword">const</span> <span class="keywordtype">int</span>       size_x = cpl_image_get_size_x(imslit);
+<a name="l00124"></a>00124     <span class="keyword">const</span> <span class="keywordtype">int</span>       size_y = cpl_image_get_size_y(imslit);
+<a name="l00125"></a>00125     <span class="keywordtype">int</span>             slit_length;
+<a name="l00126"></a>00126     cpl_size        slit_pos;
+<a name="l00127"></a>00127     cpl_image   *   filtered;
+<a name="l00128"></a>00128     cpl_mask    *   mask;
+<a name="l00129"></a>00129     cpl_image   *   thin_im;
+<a name="l00130"></a>00130     <span class="keywordtype">int</span>             slit_top_y = 0; <span class="comment">/* Avoid (false) uninit warning */</span>
+<a name="l00131"></a>00131     <span class="keywordtype">int</span>             slit_bot_y = 0; <span class="comment">/* Avoid (false) uninit warning */</span>
+<a name="l00132"></a>00132     cpl_table   *   <span class="keyword">self</span>;
+<a name="l00133"></a>00133     <span class="keywordtype">double</span>      *   slit_y,
+<a name="l00134"></a>00134                 *   slit_x_l,
+<a name="l00135"></a>00135                 *   slit_x_r;
+<a name="l00136"></a>00136     <span class="keywordtype">double</span>      *   coeff_r;
+<a name="l00137"></a>00137     <span class="keywordtype">double</span>      *   coeff_l;
+<a name="l00138"></a>00138     <span class="keywordtype">int</span>             i;
+<a name="l00139"></a>00139     cpl_error_code error = CPL_ERROR_NONE;
+<a name="l00140"></a>00140 
+<a name="l00141"></a>00141     <span class="comment">/* Initialize */</span>
+<a name="l00142"></a>00142     <span class="keywordflow">if</span> (slit_flux != NULL) *slit_flux = 0.0 ;
+<a name="l00143"></a>00143 
+<a name="l00144"></a>00144     <span class="comment">/* Median vertical filtering 3x3 */</span>
+<a name="l00145"></a>00145     mask = cpl_mask_new(3, 3) ;
+<a name="l00146"></a>00146     cpl_mask_not(mask) ;
+<a name="l00147"></a>00147     filtered = cpl_image_new(size_x, size_y, cpl_image_get_type(imslit));
+<a name="l00148"></a>00148     error = cpl_image_filter_mask(filtered, imslit, mask,
+<a name="l00149"></a>00149                                   CPL_FILTER_MEDIAN, CPL_BORDER_FILTER);
+<a name="l00150"></a>00150     cpl_mask_delete(mask);
+<a name="l00151"></a>00151 
+<a name="l00152"></a>00152     <span class="keywordflow">if</span> (error) {
+<a name="l00153"></a>00153         cpl_image_delete(filtered);
+<a name="l00154"></a>00154         cpl_ensure(0, cpl_error_get_code(), NULL);
+<a name="l00155"></a>00155     }
+<a name="l00156"></a>00156 
+<a name="l00157"></a>00157     <span class="comment">/* The background may vary strongly along the vertical line. */</span>
+<a name="l00158"></a>00158     <span class="comment">/* Detect and remove background with a 1+2*Slit_max x 1 median filter */</span>
+<a name="l00159"></a>00159     error = irplib_image_filter_background_line(filtered, NULL, slit_max_width,
+<a name="l00160"></a>00160                                                 CPL_TRUE);
+<a name="l00161"></a>00161 
+<a name="l00162"></a>00162     <span class="keywordflow">if</span> (error) {
+<a name="l00163"></a>00163         cpl_image_delete(filtered) ;
+<a name="l00164"></a>00164         cpl_ensure(0, cpl_error_get_code(), NULL);
+<a name="l00165"></a>00165     }
+<a name="l00166"></a>00166 
+<a name="l00167"></a>00167     <span class="comment">/* Find the position of the slit */</span>
+<a name="l00168"></a>00168     <span class="keywordflow">if</span> (irplib_slitpos_find_vert_pos(filtered, slit_max_width/2, &slit_pos)) {
+<a name="l00169"></a>00169         cpl_image_delete(filtered);
+<a name="l00170"></a>00170         cpl_msg_error(cpl_func, <span class="stringliteral">"Could not find the slit position"</span>);
+<a name="l00171"></a>00171         cpl_ensure(0, cpl_error_get_code(), NULL);
+<a name="l00172"></a>00172     }
+<a name="l00173"></a>00173 
+<a name="l00174"></a>00174     <span class="comment">/* Extract a thin image containing the slit */</span>
+<a name="l00175"></a>00175     thin_im = cpl_image_extract(filtered, slit_pos-slit_max_width/2, 1,
+<a name="l00176"></a>00176                                 slit_pos+slit_max_width/2, size_y);
+<a name="l00177"></a>00177     <span class="keywordflow">if</span> (thin_im == NULL) {
+<a name="l00178"></a>00178         cpl_msg_error(cpl_func, <span class="stringliteral">"Could not extract the %d pixel thin image "</span>
+<a name="l00179"></a>00179                       <span class="stringliteral">"around position %"</span>CPL_SIZE_FORMAT, 
+<a name="l00180"></a>00180                       slit_max_width, slit_pos);
+<a name="l00181"></a>00181         cpl_image_delete(filtered);
+<a name="l00182"></a>00182         cpl_ensure(0, cpl_error_get_code(), NULL);
+<a name="l00183"></a>00183     }
+<a name="l00184"></a>00184 
+<a name="l00185"></a>00185     <span class="comment">/* Find the ends of the slit */</span>
+<a name="l00186"></a>00186     error = irplib_slitpos_find_vert_slit_ends(thin_im,
+<a name="l00187"></a>00187                                                IRPLIB_SLITPOS_KERNEL_SIZE_Y,
+<a name="l00188"></a>00188                                                &slit_bot_y,
+<a name="l00189"></a>00189                                                &slit_top_y);
+<a name="l00190"></a>00190     cpl_image_delete(thin_im);
+<a name="l00191"></a>00191     <span class="keywordflow">if</span> (error) {
+<a name="l00192"></a>00192         cpl_image_delete(filtered);
+<a name="l00193"></a>00193         cpl_ensure(0, cpl_error_get_code(), NULL);
+<a name="l00194"></a>00194     }
+<a name="l00195"></a>00195 
+<a name="l00196"></a>00196     <span class="comment">/* Extract an image with exactly the slit */</span>
+<a name="l00197"></a>00197     thin_im = cpl_image_extract(filtered,
+<a name="l00198"></a>00198                                 slit_pos-slit_max_width/2,
+<a name="l00199"></a>00199                                 slit_bot_y,
+<a name="l00200"></a>00200                                 slit_pos+slit_max_width/2,
+<a name="l00201"></a>00201                                 slit_top_y);
+<a name="l00202"></a>00202     cpl_image_delete(filtered);
+<a name="l00203"></a>00203 
+<a name="l00204"></a>00204     cpl_ensure(thin_im != NULL, cpl_error_get_code(), NULL);
+<a name="l00205"></a>00205 
+<a name="l00206"></a>00206     slit_length = 1 + slit_top_y - slit_bot_y;
+<a name="l00207"></a>00207 
+<a name="l00208"></a>00208     <span class="comment">/* Allocate some arrays */</span>
+<a name="l00209"></a>00209     slit_y = cpl_malloc(slit_length * <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>));
+<a name="l00210"></a>00210     slit_x_l = cpl_malloc(slit_length * <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>));
+<a name="l00211"></a>00211     slit_x_r = cpl_malloc(slit_length * <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>));
+<a name="l00212"></a>00212     
+<a name="l00213"></a>00213     <span class="comment">/* Find the edges of the slit */</span>
+<a name="l00214"></a>00214     <span class="keywordflow">for</span> (i=0 ; i<slit_length ; i++) {
+<a name="l00215"></a>00215         <span class="keywordtype">int</span> right_pos = 0; <span class="comment">/* Avoid (false) uninit warning */</span>
+<a name="l00216"></a>00216         <span class="keywordtype">int</span> left_pos  = 0; <span class="comment">/* Avoid (false) uninit warning */</span>
+<a name="l00217"></a>00217 
+<a name="l00218"></a>00218         <span class="keywordflow">if</span> (irplib_slitpos_find_edges_one_line(thin_im,
+<a name="l00219"></a>00219                                                 i,
+<a name="l00220"></a>00220                                                 &left_pos,
+<a name="l00221"></a>00221                                                 &right_pos)) {
+<a name="l00222"></a>00222             cpl_msg_error(cpl_func, <span class="stringliteral">"cannot find the edges of the [%d]th line"</span>, 
+<a name="l00223"></a>00223                     i+1);
+<a name="l00224"></a>00224             cpl_image_delete(thin_im);
+<a name="l00225"></a>00225             <span class="keywordflow">return</span> NULL;
+<a name="l00226"></a>00226         }
+<a name="l00227"></a>00227 
+<a name="l00228"></a>00228         <span class="comment">/* Update the slit_flux */</span>
+<a name="l00229"></a>00229         <span class="keywordflow">if</span> (slit_flux != NULL) {
+<a name="l00230"></a>00230             *slit_flux += cpl_image_get_flux_window(thin_im, left_pos+1,
+<a name="l00231"></a>00231                     i+1, right_pos+1, i+1) ;
+<a name="l00232"></a>00232         }
+<a name="l00233"></a>00233         
+<a name="l00234"></a>00234         <span class="comment">/* Store the edges for the fit */</span>
+<a name="l00235"></a>00235         slit_x_l[i] = (double)left_pos;
+<a name="l00236"></a>00236         slit_x_r[i] = (double)right_pos;
+<a name="l00237"></a>00237         slit_y[i]   = (double)(i+slit_bot_y-1);
+<a name="l00238"></a>00238     }
+<a name="l00239"></a>00239     cpl_image_delete(thin_im);
+<a name="l00240"></a>00240 
+<a name="l00241"></a>00241     <span class="comment">/* Linear regression to find the edges */</span>
+<a name="l00242"></a>00242     coeff_l = <a class="code" href="group__irplib__flat.html#ga3e3e3bd45aef34e38758e1f2528d7c91" title="Fit a slope to a list of points (robust fit).">irplib_flat_fit_slope_robust</a>(slit_y, slit_x_l, slit_length);
+<a name="l00243"></a>00243     coeff_r = <a class="code" href="group__irplib__flat.html#ga3e3e3bd45aef34e38758e1f2528d7c91" title="Fit a slope to a list of points (robust fit).">irplib_flat_fit_slope_robust</a>(slit_y, slit_x_r, slit_length);
+<a name="l00244"></a>00244     cpl_free(slit_y);
+<a name="l00245"></a>00245     cpl_free(slit_x_l);
+<a name="l00246"></a>00246     cpl_free(slit_x_r);
+<a name="l00247"></a>00247 
+<a name="l00248"></a>00248     <span class="comment">/* Allocate the table containing the results */</span>
+<a name="l00249"></a>00249     <span class="keyword">self</span> = cpl_table_new(slit_length);
+<a name="l00250"></a>00250     error |= cpl_table_new_column(<span class="keyword">self</span>, <span class="stringliteral">"SLIT_Y"</span>,      CPL_TYPE_INT);
+<a name="l00251"></a>00251     error |= cpl_table_new_column(<span class="keyword">self</span>, <span class="stringliteral">"SLIT_LEFT"</span>,   CPL_TYPE_DOUBLE);
+<a name="l00252"></a>00252     error |= cpl_table_new_column(<span class="keyword">self</span>, <span class="stringliteral">"SLIT_CENTER"</span>, CPL_TYPE_DOUBLE);
+<a name="l00253"></a>00253     error |= cpl_table_new_column(<span class="keyword">self</span>, <span class="stringliteral">"SLIT_RIGHT"</span>,  CPL_TYPE_DOUBLE);
+<a name="l00254"></a>00254 
+<a name="l00255"></a>00255     error |= cpl_table_set_column_unit(<span class="keyword">self</span>, <span class="stringliteral">"SLIT_Y"</span>, <span class="stringliteral">"pixel"</span>);
+<a name="l00256"></a>00256     error |= cpl_table_set_column_unit(<span class="keyword">self</span>, <span class="stringliteral">"SLIT_LEFT"</span>, <span class="stringliteral">"pixel"</span>);
+<a name="l00257"></a>00257     error |= cpl_table_set_column_unit(<span class="keyword">self</span>, <span class="stringliteral">"SLIT_CENTER"</span>, <span class="stringliteral">"pixel"</span>);
+<a name="l00258"></a>00258     error |= cpl_table_set_column_unit(<span class="keyword">self</span>, <span class="stringliteral">"SLIT_RIGHT"</span>, <span class="stringliteral">"pixel"</span>);
+<a name="l00259"></a>00259 
+<a name="l00260"></a>00260     cpl_ensure(!error, cpl_error_get_code(), NULL);
+<a name="l00261"></a>00261 
+<a name="l00262"></a>00262     <span class="comment">/* Rewrite the edges in the out table, and write the center */</span>
+<a name="l00263"></a>00263     <span class="keywordflow">for</span> (i=0 ; i < slit_length ; i++) {
+<a name="l00264"></a>00264         <span class="keyword">const</span> <span class="keywordtype">int</span>    islity = i + slit_bot_y;
+<a name="l00265"></a>00265         <span class="keyword">const</span> <span class="keywordtype">double</span> dslit  = slit_pos - slit_max_width / 2.0;
+<a name="l00266"></a>00266         <span class="keyword">const</span> <span class="keywordtype">double</span> dleft  = coeff_l[0] + coeff_l[1] * (double)islity + dslit;
+<a name="l00267"></a>00267         <span class="keyword">const</span> <span class="keywordtype">double</span> dright = coeff_r[0] + coeff_r[1] * (double)islity + dslit;
+<a name="l00268"></a>00268         <span class="keyword">const</span> <span class="keywordtype">double</span> dcent  = 0.5 * (dleft + dright);
+<a name="l00269"></a>00269 
+<a name="l00270"></a>00270         <span class="keywordflow">if</span> (cpl_table_set_int(<span class="keyword">self</span>,    <span class="stringliteral">"SLIT_Y"</span>,      i, islity)) <span class="keywordflow">break</span>;
+<a name="l00271"></a>00271         <span class="keywordflow">if</span> (cpl_table_set_double(<span class="keyword">self</span>, <span class="stringliteral">"SLIT_LEFT"</span>,   i, dleft))  <span class="keywordflow">break</span>;
+<a name="l00272"></a>00272         <span class="keywordflow">if</span> (cpl_table_set_double(<span class="keyword">self</span>, <span class="stringliteral">"SLIT_RIGHT"</span>,  i, dright)) <span class="keywordflow">break</span>;
+<a name="l00273"></a>00273         <span class="keywordflow">if</span> (cpl_table_set_double(<span class="keyword">self</span>, <span class="stringliteral">"SLIT_CENTER"</span>, i, dcent))  <span class="keywordflow">break</span>;
+<a name="l00274"></a>00274     }
+<a name="l00275"></a>00275 
+<a name="l00276"></a>00276     cpl_free(coeff_r);
+<a name="l00277"></a>00277     cpl_free(coeff_l);
+<a name="l00278"></a>00278 
+<a name="l00279"></a>00279     <span class="keywordflow">if</span> (i != slit_length) {
+<a name="l00280"></a>00280         cpl_table_delete(<span class="keyword">self</span>);
+<a name="l00281"></a>00281         cpl_ensure(0, cpl_error_get_code(), NULL);
+<a name="l00282"></a>00282     }
+<a name="l00283"></a>00283 
+<a name="l00284"></a>00284     <span class="keywordflow">return</span> <span class="keyword">self</span>;
+<a name="l00285"></a>00285 }
+<a name="l00286"></a>00286 
+<a name="l00289"></a>00289 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00301"></a>00301 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00302"></a>00302 <span class="keyword">static</span> cpl_error_code irplib_slitpos_find_edges_one_line(<span class="keyword">const</span> cpl_image * <span class="keyword">self</span>,
+<a name="l00303"></a>00303                                                          <span class="keywordtype">int</span>          line_pos,
+<a name="l00304"></a>00304                                                          <span class="keywordtype">int</span>        * left_pos,
+<a name="l00305"></a>00305                                                          <span class="keywordtype">int</span>        * right_pos)
+<a name="l00306"></a>00306 {
+<a name="l00307"></a>00307     <span class="keyword">const</span> <span class="keywordtype">int</span>     size_x = cpl_image_get_size_x(<span class="keyword">self</span>);
+<a name="l00308"></a>00308     <span class="keyword">const</span> <span class="keywordtype">float</span> * pself;
+<a name="l00309"></a>00309     <span class="keywordtype">double</span>        threshold;
+<a name="l00310"></a>00310     <span class="keywordtype">int</span>           i;
+<a name="l00311"></a>00311 
+<a name="l00312"></a>00312     cpl_ensure_code(<span class="keyword">self</span> != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00313"></a>00313     cpl_ensure_code(cpl_image_get_type(<span class="keyword">self</span>) == CPL_TYPE_FLOAT,
+<a name="l00314"></a>00314                     CPL_ERROR_INVALID_TYPE);
+<a name="l00315"></a>00315 
+<a name="l00316"></a>00316     pself = cpl_image_get_data_float_const(<span class="keyword">self</span>);
+<a name="l00317"></a>00317 
+<a name="l00318"></a>00318     <span class="comment">/* Find the threshold */</span>
+<a name="l00319"></a>00319     threshold = cpl_image_get_mean_window(<span class="keyword">self</span>, 1, line_pos+1, size_x,
+<a name="l00320"></a>00320                                           line_pos+1);
+<a name="l00321"></a>00321 
+<a name="l00322"></a>00322     <span class="comment">/* Detect the left edge */</span>
+<a name="l00323"></a>00323     i = 0;
+<a name="l00324"></a>00324     <span class="keywordflow">while</span> (i < size_x && pself[line_pos*size_x+i] < threshold) i++;
+<a name="l00325"></a>00325     *left_pos = i;
+<a name="l00326"></a>00326 
+<a name="l00327"></a>00327     <span class="comment">/* Detect the right edge */</span>
+<a name="l00328"></a>00328     i = size_x - 1;
+<a name="l00329"></a>00329     <span class="keywordflow">while</span> (i >= 0 && pself[line_pos*size_x+i] < threshold) i--;
+<a name="l00330"></a>00330     *right_pos = i;
+<a name="l00331"></a>00331 
+<a name="l00332"></a>00332     <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l00333"></a>00333 }
+<a name="l00334"></a>00334 
+<a name="l00335"></a>00335 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00346"></a>00346 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00347"></a>00347 <span class="keyword">static</span>
+<a name="l00348"></a>00348 cpl_error_code irplib_slitpos_find_vert_slit_ends(<span class="keyword">const</span> cpl_image * <span class="keyword">self</span>,
+<a name="l00349"></a>00349                                                   <span class="keywordtype">int</span>        kernel_size,
+<a name="l00350"></a>00350                                                   <span class="keywordtype">int</span>      * bot_slit_y,
+<a name="l00351"></a>00351                                                   <span class="keywordtype">int</span>      * top_slit_y)
+<a name="l00352"></a>00352 {
+<a name="l00353"></a>00353     cpl_mask         * binary;
+<a name="l00354"></a>00354     cpl_mask         * copy = NULL;
+<a name="l00355"></a>00355     cpl_mask         * kernel;
+<a name="l00356"></a>00356     cpl_image        * label_image;
+<a name="l00357"></a>00357     <span class="keywordtype">int</span>                erosions_nb;
+<a name="l00358"></a>00358     cpl_size           nobj ;
+<a name="l00359"></a>00359     <span class="keyword">const</span> <span class="keywordtype">int</span>          size_x = cpl_image_get_size_x(<span class="keyword">self</span>);
+<a name="l00360"></a>00360     <span class="keyword">const</span> <span class="keywordtype">int</span>          size_y = cpl_image_get_size_y(<span class="keyword">self</span>);
+<a name="l00361"></a>00361     <span class="keyword">const</span> <span class="keywordtype">int</span>          npix = size_x * size_y;
+<a name="l00362"></a>00362     <span class="keyword">const</span> cpl_binary * pbinary;
+<a name="l00363"></a>00363     <span class="keyword">const</span> cpl_binary * pfind;
+<a name="l00364"></a>00364     <span class="keywordtype">int</span>                i, itop, ibot;
+<a name="l00365"></a>00365 
+<a name="l00366"></a>00366 
+<a name="l00367"></a>00367     cpl_ensure_code(size_x      > 0, cpl_error_get_code());
+<a name="l00368"></a>00368     cpl_ensure_code(kernel_size > 0, cpl_error_get_code());
+<a name="l00369"></a>00369 
+<a name="l00370"></a>00370     <span class="comment">/* Threshold to have a binary image */</span>
+<a name="l00371"></a>00371     binary = cpl_mask_threshold_image_create(<span class="keyword">self</span>, cpl_image_get_mean(<span class="keyword">self</span>),
+<a name="l00372"></a>00372                                              cpl_image_get_max(<span class="keyword">self</span>));
+<a name="l00373"></a>00373     cpl_ensure_code(binary != NULL, cpl_error_get_code());
+<a name="l00374"></a>00374 
+<a name="l00375"></a>00375     <span class="comment">/* Erode until there is 1 object left in the image */</span>
+<a name="l00376"></a>00376     label_image = cpl_image_labelise_mask_create(binary, &nobj);
+<a name="l00377"></a>00377     cpl_image_delete(label_image);
+<a name="l00378"></a>00378 
+<a name="l00379"></a>00379     <span class="keywordflow">if</span> (label_image == NULL) {
+<a name="l00380"></a>00380         cpl_mask_delete(binary);
+<a name="l00381"></a>00381         cpl_ensure_code(0, cpl_error_get_code());
+<a name="l00382"></a>00382     }
+<a name="l00383"></a>00383 
+<a name="l00384"></a>00384     <span class="comment">/* Define the kernel for morpho operations */</span>
+<a name="l00385"></a>00385     kernel = cpl_mask_new(kernel_size, 1);
+<a name="l00386"></a>00386     cpl_mask_not(kernel);
+<a name="l00387"></a>00387     copy = cpl_mask_wrap(size_x, size_y, cpl_malloc(size_x * size_y *
+<a name="l00388"></a>00388                                                     <span class="keyword">sizeof</span>(cpl_binary)));
+<a name="l00389"></a>00389     <span class="keywordflow">for</span> (erosions_nb = 0; erosions_nb < IRPLIB_SLITPOS_MAX_EROSION && nobj > 1;
+<a name="l00390"></a>00390          erosions_nb++) {
+<a name="l00391"></a>00391         <span class="comment">/* Should not be possible to break from this loop */</span>
+<a name="l00392"></a>00392         cpl_mask_copy(copy, binary, 1, 1);
+<a name="l00393"></a>00393         <span class="keywordflow">if</span> (cpl_mask_filter(binary, copy, kernel, CPL_FILTER_EROSION,
+<a name="l00394"></a>00394                             CPL_BORDER_ZERO)) <span class="keywordflow">break</span>;
+<a name="l00395"></a>00395 
+<a name="l00396"></a>00396         label_image = cpl_image_labelise_mask_create(binary, &nobj);
+<a name="l00397"></a>00397         <span class="keywordflow">if</span> (label_image == NULL) <span class="keywordflow">break</span>; <span class="comment">/* Assuming nobj was not set to 1 */</span>
+<a name="l00398"></a>00398         cpl_image_delete(label_image);
+<a name="l00399"></a>00399     }
+<a name="l00400"></a>00400 
+<a name="l00401"></a>00401     <span class="keywordflow">if</span> (nobj > 1) {
+<a name="l00402"></a>00402         cpl_mask_delete(binary);
+<a name="l00403"></a>00403         cpl_mask_delete(copy);
+<a name="l00404"></a>00404         cpl_mask_delete(kernel);
+<a name="l00405"></a>00405         <span class="keywordflow">if</span> (erosions_nb >= IRPLIB_SLITPOS_MAX_EROSION) {
+<a name="l00406"></a>00406             cpl_msg_error(cpl_func, <span class="stringliteral">"Number of erosions reached a limit of %d "</span>
+<a name="l00407"></a>00407                           <span class="stringliteral">"with %"</span>CPL_SIZE_FORMAT<span class="stringliteral">" possible slits left"</span>,
+<a name="l00408"></a>00408                           IRPLIB_SLITPOS_MAX_EROSION, nobj);
+<a name="l00409"></a>00409             cpl_ensure_code(0, CPL_ERROR_CONTINUE);
+<a name="l00410"></a>00410         }
+<a name="l00411"></a>00411         cpl_ensure_code(0, cpl_error_get_code());
+<a name="l00412"></a>00412     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (nobj < 1) {
+<a name="l00413"></a>00413         cpl_mask_delete(binary);
+<a name="l00414"></a>00414         cpl_mask_delete(copy);
+<a name="l00415"></a>00415         cpl_mask_delete(kernel);
+<a name="l00416"></a>00416         <span class="keywordflow">if</span> (erosions_nb == 0)
+<a name="l00417"></a>00417             cpl_msg_error(cpl_func, <span class="stringliteral">"No slit could be detected across %d "</span>
+<a name="l00418"></a>00418                           <span class="stringliteral">"pixels"</span>, size_x);
+<a name="l00419"></a>00419         <span class="keywordflow">else</span> 
+<a name="l00420"></a>00420             cpl_msg_error(cpl_func, <span class="stringliteral">"The last of %d erosions removed all the "</span>
+<a name="l00421"></a>00421                           <span class="stringliteral">"possible slits"</span>, erosions_nb);
+<a name="l00422"></a>00422         cpl_ensure_code(0, CPL_ERROR_DATA_NOT_FOUND);
+<a name="l00423"></a>00423     }
+<a name="l00424"></a>00424 
+<a name="l00425"></a>00425     <span class="comment">/* Reconstruct the slit with dilations */</span>
+<a name="l00426"></a>00426     <span class="keywordflow">for</span> (i=0 ; i < erosions_nb ; i++) {
+<a name="l00427"></a>00427         cpl_mask_copy(copy, binary, 1, 1);
+<a name="l00428"></a>00428         <span class="keywordflow">if</span> (cpl_mask_filter(binary, copy, kernel, CPL_FILTER_DILATION,
+<a name="l00429"></a>00429                             CPL_BORDER_ZERO)) <span class="keywordflow">break</span>;
+<a name="l00430"></a>00430     }
+<a name="l00431"></a>00431     cpl_mask_delete(copy);
+<a name="l00432"></a>00432     cpl_mask_delete(kernel);
+<a name="l00433"></a>00433 
+<a name="l00434"></a>00434     <span class="keywordflow">if</span> (i != erosions_nb) {
+<a name="l00435"></a>00435         cpl_msg_error(cpl_func, <span class="stringliteral">"Dilation number %d out of %d failed"</span>,
+<a name="l00436"></a>00436                       i, erosions_nb);
+<a name="l00437"></a>00437         cpl_mask_delete(binary);
+<a name="l00438"></a>00438         cpl_ensure_code(0, cpl_error_get_code());
+<a name="l00439"></a>00439     }
+<a name="l00440"></a>00440 
+<a name="l00441"></a>00441     <span class="comment">/* Find the ends of the slit */</span>
+<a name="l00442"></a>00442     pbinary = cpl_mask_get_data(binary);
+<a name="l00443"></a>00443     assert( pbinary != NULL );
+<a name="l00444"></a>00444 
+<a name="l00445"></a>00445     pfind = memchr(pbinary, CPL_BINARY_1, (<span class="keywordtype">size_t</span>)npix);
+<a name="l00446"></a>00446     assert( pfind != NULL );
+<a name="l00447"></a>00447 
+<a name="l00448"></a>00448     ibot = (int)(pfind - pbinary);
+<a name="l00449"></a>00449 
+<a name="l00450"></a>00450 <span class="preprocessor">#if defined HAVE_DECL_MEMRCHR && HAVE_DECL_MEMRCHR == 1</span>
+<a name="l00451"></a>00451 <span class="preprocessor"></span>    <span class="comment">/* FIXME: Not tested */</span>
+<a name="l00452"></a>00452     pfind = memrchr(pfind, CPL_BINARY_1, (<span class="keywordtype">size_t</span>)(npix - ibot));
+<a name="l00453"></a>00453     assert( pfind != NULL );
+<a name="l00454"></a>00454 
+<a name="l00455"></a>00455     itop = (int)(pfind - pbinary);
+<a name="l00456"></a>00456 <span class="preprocessor">#else</span>
+<a name="l00457"></a>00457 <span class="preprocessor"></span>
+<a name="l00458"></a>00458     itop = npix - 1;
+<a name="l00459"></a>00459     <span class="keywordflow">while</span> (itop > ibot && pbinary[itop] != CPL_BINARY_1) itop--;
+<a name="l00460"></a>00460 
+<a name="l00461"></a>00461 <span class="preprocessor">#endif</span>
+<a name="l00462"></a>00462 <span class="preprocessor"></span>
+<a name="l00463"></a>00463     *bot_slit_y = 1 + ibot / size_x;
+<a name="l00464"></a>00464     *top_slit_y = 1 + itop / size_x;
+<a name="l00465"></a>00465 
+<a name="l00466"></a>00466     cpl_msg_info(cpl_func, 
+<a name="l00467"></a>00467             <span class="stringliteral">"Detected %"</span>CPL_SIZE_FORMAT<span class="stringliteral">"-pixel slit from pixel %d to %d "</span>
+<a name="l00468"></a>00468             <span class="stringliteral">"using %d erosions/dilations"</span>, cpl_mask_count(binary),
+<a name="l00469"></a>00469             *bot_slit_y, *top_slit_y, erosions_nb);
+<a name="l00470"></a>00470 
+<a name="l00471"></a>00471     cpl_mask_delete(binary);
+<a name="l00472"></a>00472 
+<a name="l00473"></a>00473     <span class="comment">/* Should really be an assert() */</span>
+<a name="l00474"></a>00474     cpl_ensure_code(ibot <= itop, CPL_ERROR_DATA_NOT_FOUND);
+<a name="l00475"></a>00475 
+<a name="l00476"></a>00476     <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l00477"></a>00477 }
+<a name="l00478"></a>00478 
+<a name="l00479"></a>00479 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00489"></a>00489 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00490"></a>00490 <span class="keyword">static</span> cpl_error_code irplib_slitpos_find_vert_pos(<span class="keyword">const</span> cpl_image * <span class="keyword">self</span>,
+<a name="l00491"></a>00491                                                    <span class="keywordtype">int</span>               xwidth,
+<a name="l00492"></a>00492                                                    cpl_size        * slit_pos)
+<a name="l00493"></a>00493 {
+<a name="l00494"></a>00494     <span class="keyword">const</span> <span class="keywordtype">int</span>       size_x = cpl_image_get_size_x(<span class="keyword">self</span>);
+<a name="l00495"></a>00495     cpl_image   *   image1D;
+<a name="l00496"></a>00496     cpl_size        yone;
+<a name="l00497"></a>00497     cpl_error_code  error;
+<a name="l00498"></a>00498 
+<a name="l00499"></a>00499 
+<a name="l00500"></a>00500     <span class="comment">/* Collapse the image to a horizontal 1D image */</span>
+<a name="l00501"></a>00501     image1D = cpl_image_collapse_create(<span class="keyword">self</span>, 0);
+<a name="l00502"></a>00502 
+<a name="l00503"></a>00503     cpl_ensure_code(image1D != NULL, cpl_error_get_code());
+<a name="l00504"></a>00504 
+<a name="l00505"></a>00505     <span class="comment">/* Search the max of the 1D image to identify the slit position */</span>
+<a name="l00506"></a>00506     error = cpl_image_get_maxpos_window(image1D, 1+xwidth, 1, size_x-xwidth,
+<a name="l00507"></a>00507                                         1, slit_pos, &yone);
+<a name="l00508"></a>00508 
+<a name="l00509"></a>00509     cpl_image_delete(image1D);
+<a name="l00510"></a>00510 
+<a name="l00511"></a>00511     cpl_ensure_code(!error, error);
+<a name="l00512"></a>00512 
+<a name="l00513"></a>00513     <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l00514"></a>00514 }
+<a name="l00515"></a>00515 
+<a name="l00516"></a>00516 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00530"></a>00530 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00531"></a>00531 <span class="keyword">static</span> cpl_error_code irplib_image_filter_background_line(cpl_image * <span class="keyword">self</span>,
+<a name="l00532"></a>00532                                                    <span class="keyword">const</span> cpl_image * other,
+<a name="l00533"></a>00533                                                    <span class="keywordtype">int</span> hsize,
+<a name="l00534"></a>00534                                                    cpl_boolean vertical)
+<a name="l00535"></a>00535 {
+<a name="l00536"></a>00536     <span class="keyword">const</span> <span class="keywordtype">int</span>      nx = cpl_image_get_size_x(<span class="keyword">self</span>);
+<a name="l00537"></a>00537     <span class="keyword">const</span> <span class="keywordtype">int</span>      ny = cpl_image_get_size_y(<span class="keyword">self</span>);
+<a name="l00538"></a>00538     <span class="keyword">const</span> <span class="keywordtype">int</span>      msize = 1 + 2 * hsize;
+<a name="l00539"></a>00539     cpl_mask     * mask;
+<a name="l00540"></a>00540     cpl_image    * background;
+<a name="l00541"></a>00541     cpl_error_code error = CPL_ERROR_NONE;
+<a name="l00542"></a>00542 
+<a name="l00543"></a>00543     cpl_ensure_code(<span class="keyword">self</span>  != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00544"></a>00544     cpl_ensure_code(hsize >= 0,    CPL_ERROR_ILLEGAL_INPUT);
+<a name="l00545"></a>00545 
+<a name="l00546"></a>00546     <span class="keywordflow">if</span> (other == NULL) other = <span class="keyword">self</span>;
+<a name="l00547"></a>00547 
+<a name="l00548"></a>00548     mask = vertical ? cpl_mask_new(msize, 1) : cpl_mask_new(1, msize);
+<a name="l00549"></a>00549 
+<a name="l00550"></a>00550     error |= cpl_mask_not(mask);
+<a name="l00551"></a>00551 
+<a name="l00552"></a>00552     background = cpl_image_new(nx, ny, cpl_image_get_type(other));
+<a name="l00553"></a>00553 
+<a name="l00554"></a>00554     error |= cpl_image_filter_mask(background, other, mask, CPL_FILTER_MEDIAN,
+<a name="l00555"></a>00555                                    CPL_BORDER_FILTER);
+<a name="l00556"></a>00556     cpl_mask_delete(mask);
+<a name="l00557"></a>00557 
+<a name="l00558"></a>00558     <span class="keywordflow">if</span> (<span class="keyword">self</span> != other) {
+<a name="l00559"></a>00559         error |= cpl_image_copy(<span class="keyword">self</span>, other, 1, 1);
+<a name="l00560"></a>00560     }
+<a name="l00561"></a>00561 
+<a name="l00562"></a>00562     error |= cpl_image_subtract(<span class="keyword">self</span>, background);
+<a name="l00563"></a>00563     cpl_image_delete(background);
+<a name="l00564"></a>00564 
+<a name="l00565"></a>00565     <span class="keywordflow">return</span> error ? cpl_error_set_where(cpl_func) : CPL_ERROR_NONE;
+<a name="l00566"></a>00566 }
+<a name="l00567"></a>00567 
+<a name="l00568"></a>00568 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/irplib__slitpos_8h_source.html b/html/irplib__slitpos_8h_source.html
new file mode 100644
index 0000000..a06609e
--- /dev/null
+++ b/html/irplib__slitpos_8h_source.html
@@ -0,0 +1,55 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: irplib_slitpos.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>irplib_slitpos.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: irplib_slitpos.h,v 1.6 2006/11/29 13:22:59 yjung Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the irplib package</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: yjung $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2006/11/29 13:22:59 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.6 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifndef IRPLIB_SLITPOS_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#define IRPLIB_SLITPOS_H</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span>
+<a name="l00031"></a>00031 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00032"></a>00032 <span class="comment">                                   Includes</span>
+<a name="l00033"></a>00033 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00034"></a>00034 
+<a name="l00035"></a>00035 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 cpl_table * <a class="code" href="group__irplib__slitpos.html#ga632b21eccf3d4bb48426cdd23f321cba" title="Detect the slit position, detect its ends, extract a thin image containing only the...">irplib_slitpos_analysis</a>(<span class="keyword">const</span> cpl_image *, <span class="keywordtype">int</span>, <span class="keywordtype">double</span> *);
+<a name="l00038"></a>00038 
+<a name="l00039"></a>00039 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/irplib__spectrum_8c_source.html b/html/irplib__spectrum_8c_source.html
new file mode 100644
index 0000000..446457d
--- /dev/null
+++ b/html/irplib__spectrum_8c_source.html
@@ -0,0 +1,569 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: irplib_spectrum.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>irplib_spectrum.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: irplib_spectrum.c,v 1.29 2012/01/12 11:50:41 llundin Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the irplib package</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: llundin $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2012/01/12 11:50:41 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.29 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span>
+<a name="l00032"></a>00032 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                                Includes</span>
+<a name="l00034"></a>00034 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 
+<a name="l00036"></a>00036 <span class="preprocessor">#include <math.h></span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include <float.h></span>
+<a name="l00038"></a>00038 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00039"></a>00039 
+<a name="l00040"></a>00040 <span class="preprocessor">#include "irplib_wlxcorr.h"</span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include "irplib_spectrum.h"</span>
+<a name="l00042"></a>00042 
+<a name="l00043"></a>00043 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00044"></a>00044 <span class="comment">                                   Define</span>
+<a name="l00045"></a>00045 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00046"></a>00046 
+<a name="l00047"></a>00047 <span class="comment">/* TEMPORARY SUPPORT OF CPL 5.x */</span>
+<a name="l00048"></a>00048 <span class="preprocessor">#ifndef CPL_SIZE_FORMAT</span>
+<a name="l00049"></a>00049 <span class="preprocessor"></span><span class="preprocessor">#define CPL_SIZE_FORMAT "d"</span>
+<a name="l00050"></a>00050 <span class="preprocessor"></span><span class="preprocessor">#define cpl_size int</span>
+<a name="l00051"></a>00051 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
+<a name="l00052"></a>00052 <span class="preprocessor"></span><span class="comment">/* END TEMPORARY SUPPORT OF CPL 5.x */</span>
+<a name="l00053"></a>00053 
+<a name="l00054"></a>00054 <span class="preprocessor">#define SPECTRUM_HW                     16</span>
+<a name="l00055"></a>00055 <span class="preprocessor"></span><span class="preprocessor">#define MIN_THRESH_FACT                 0.9</span>
+<a name="l00056"></a>00056 <span class="preprocessor"></span><span class="preprocessor">#define MAX_THRESH_FACT                 1.1</span>
+<a name="l00057"></a>00057 <span class="preprocessor"></span><span class="preprocessor">#define SPEC_SHADOW_FACT                30.0 </span><span class="comment">/* Negative spectrum intensity*/</span>
+<a name="l00058"></a>00058 <span class="preprocessor">#define SPEC_MAXWIDTH                   48</span>
+<a name="l00059"></a>00059 <span class="preprocessor"></span>
+<a name="l00060"></a>00060 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00061"></a>00061 <span class="comment">                            Functions prototypes</span>
+<a name="l00062"></a>00062 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00063"></a>00063 
+<a name="l00064"></a>00064 <span class="keyword">static</span> <span class="keywordtype">int</span> select_valid_spectra(cpl_image *, cpl_apertures *, <span class="keywordtype">int</span>,
+<a name="l00065"></a>00065         spec_shadows, <span class="keywordtype">int</span>, <span class="keywordtype">int</span> *, <span class="keywordtype">int</span> **) ;
+<a name="l00066"></a>00066 <span class="keyword">static</span> <span class="keywordtype">int</span> valid_spectrum(cpl_image *, cpl_apertures *, <span class="keywordtype">int</span>, spec_shadows, <span class="keywordtype">int</span>,
+<a name="l00067"></a>00067         <span class="keywordtype">int</span>) ;
+<a name="l00068"></a>00068 
+<a name="l00069"></a>00069 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00073"></a>00073 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00074"></a>00074 
+<a name="l00077"></a>00077 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00092"></a>00092 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00093"></a><a class="code" href="group__irplib__spectrum.html#ga9ac928ba9a48e864b56e921c970638c0">00093</a> <span class="keywordtype">int</span> <a class="code" href="group__irplib__spectrum.html#ga9ac928ba9a48e864b56e921c970638c0" title="Finds the brightest spectrum in an image.">irplib_spectrum_find_brightest</a>(
+<a name="l00094"></a>00094         <span class="keyword">const</span> cpl_image     *   in,
+<a name="l00095"></a>00095         <span class="keywordtype">int</span>                     offset,
+<a name="l00096"></a>00096         spec_shadows            shadows,
+<a name="l00097"></a>00097         <span class="keywordtype">double</span>                  min_bright,
+<a name="l00098"></a>00098         <span class="keywordtype">int</span>                     orient,
+<a name="l00099"></a>00099         <span class="keywordtype">double</span>              *   pos)
+<a name="l00100"></a>00100 {
+<a name="l00101"></a>00101     cpl_image       *   loc_ima ;
+<a name="l00102"></a>00102     cpl_image       *   filt_image ;
+<a name="l00103"></a>00103     cpl_image       *   collapsed ;
+<a name="l00104"></a>00104     <span class="keywordtype">float</span>           *   pcollapsed ;
+<a name="l00105"></a>00105     cpl_vector      *   line ;
+<a name="l00106"></a>00106     <span class="keywordtype">double</span>          *   pline ;
+<a name="l00107"></a>00107     cpl_vector      *   line_filt ;
+<a name="l00108"></a>00108     <span class="keywordtype">double</span>              threshold ;
+<a name="l00109"></a>00109     <span class="keywordtype">double</span>              median, stdev, max, mean ;
+<a name="l00110"></a>00110     cpl_mask        *   mask ;
+<a name="l00111"></a>00111     cpl_image       *   labels ;
+<a name="l00112"></a>00112     cpl_size            nlabels ;
+<a name="l00113"></a>00113     cpl_apertures   *   aperts ;
+<a name="l00114"></a>00114     <span class="keywordtype">int</span>                 n_valid_specs ;
+<a name="l00115"></a>00115     <span class="keywordtype">int</span>             *   valid_specs ;
+<a name="l00116"></a>00116     <span class="keywordtype">double</span>              brightness ;
+<a name="l00117"></a>00117     <span class="keywordtype">int</span>                 i ;
+<a name="l00118"></a>00118 
+<a name="l00119"></a>00119     <span class="comment">/* Test entries */</span>
+<a name="l00120"></a>00120     <span class="keywordflow">if</span> (in == NULL) <span class="keywordflow">return</span> -1 ;
+<a name="l00121"></a>00121     <span class="keywordflow">if</span> (orient!=0 && orient!=1) <span class="keywordflow">return</span> -1 ;
+<a name="l00122"></a>00122 
+<a name="l00123"></a>00123     <span class="comment">/* Flip the image if necessary */</span>
+<a name="l00124"></a>00124     <span class="keywordflow">if</span> (orient == 1) {
+<a name="l00125"></a>00125         loc_ima = cpl_image_duplicate(in) ;
+<a name="l00126"></a>00126         cpl_image_flip(loc_ima, 1) ;
+<a name="l00127"></a>00127     } <span class="keywordflow">else</span> {
+<a name="l00128"></a>00128         loc_ima = cpl_image_duplicate(in) ;
+<a name="l00129"></a>00129     }
+<a name="l00130"></a>00130 
+<a name="l00131"></a>00131     <span class="comment">/* Median vertical filtering 3x3 */</span>
+<a name="l00132"></a>00132     mask = cpl_mask_new(3, 3) ;
+<a name="l00133"></a>00133     cpl_mask_not(mask) ;
+<a name="l00134"></a>00134     filt_image = cpl_image_new(
+<a name="l00135"></a>00135             cpl_image_get_size_x(loc_ima),
+<a name="l00136"></a>00136             cpl_image_get_size_y(loc_ima),
+<a name="l00137"></a>00137             cpl_image_get_type(loc_ima)) ;
+<a name="l00138"></a>00138     <span class="keywordflow">if</span> (cpl_image_filter_mask(filt_image, loc_ima, mask,
+<a name="l00139"></a>00139                 CPL_FILTER_MEDIAN, CPL_BORDER_FILTER) != CPL_ERROR_NONE) {
+<a name="l00140"></a>00140         cpl_msg_error(__func__, <span class="stringliteral">"Cannot filter the image"</span>) ;
+<a name="l00141"></a>00141         cpl_mask_delete(mask) ;
+<a name="l00142"></a>00142         cpl_image_delete(filt_image) ;
+<a name="l00143"></a>00143         <span class="keywordflow">return</span> -1 ;
+<a name="l00144"></a>00144     }
+<a name="l00145"></a>00145     cpl_mask_delete(mask) ;
+<a name="l00146"></a>00146     cpl_image_delete(loc_ima) ;
+<a name="l00147"></a>00147 
+<a name="l00148"></a>00148     <span class="comment">/* Collapse the image */</span>
+<a name="l00149"></a>00149     <span class="keywordflow">if</span> ((collapsed = cpl_image_collapse_median_create(filt_image, 1, 0,
+<a name="l00150"></a>00150                     0)) == NULL) {
+<a name="l00151"></a>00151         cpl_msg_error(cpl_func, <span class="stringliteral">"collapsing image: aborting spectrum detection"</span>);
+<a name="l00152"></a>00152         cpl_image_delete(filt_image) ;
+<a name="l00153"></a>00153         <span class="keywordflow">return</span> -1 ;
+<a name="l00154"></a>00154     }
+<a name="l00155"></a>00155     cpl_image_delete(filt_image) ;
+<a name="l00156"></a>00156 
+<a name="l00157"></a>00157     <span class="comment">/* Subtract low frequency signal */</span>
+<a name="l00158"></a>00158     line = cpl_vector_new_from_image_column(collapsed, 1) ;
+<a name="l00159"></a>00159     cpl_image_delete(collapsed) ;
+<a name="l00160"></a>00160     line_filt = cpl_vector_filter_median_create(line, SPECTRUM_HW) ;
+<a name="l00161"></a>00161     cpl_vector_subtract(line, line_filt) ;
+<a name="l00162"></a>00162     cpl_vector_delete(line_filt) ;
+<a name="l00163"></a>00163 
+<a name="l00164"></a>00164     <span class="comment">/* Get relevant stats for thresholding */</span>
+<a name="l00165"></a>00165     median = cpl_vector_get_median_const(line) ;
+<a name="l00166"></a>00166     stdev = cpl_vector_get_stdev(line) ;
+<a name="l00167"></a>00167     max = cpl_vector_get_max(line) ;
+<a name="l00168"></a>00168     mean = cpl_vector_get_mean(line) ;
+<a name="l00169"></a>00169 
+<a name="l00170"></a>00170     <span class="comment">/* Set the threshold */</span>
+<a name="l00171"></a>00171     threshold = median + stdev ;
+<a name="l00172"></a>00172     <span class="keywordflow">if</span> (threshold > MIN_THRESH_FACT * max)  threshold = MIN_THRESH_FACT * max ;
+<a name="l00173"></a>00173     <span class="keywordflow">if</span> (threshold < MAX_THRESH_FACT * mean) threshold = MAX_THRESH_FACT * mean;
+<a name="l00174"></a>00174 
+<a name="l00175"></a>00175     <span class="comment">/* Recreate the image */</span>
+<a name="l00176"></a>00176     collapsed = cpl_image_new(1, cpl_vector_get_size(line), CPL_TYPE_FLOAT) ;
+<a name="l00177"></a>00177     pcollapsed = cpl_image_get_data_float(collapsed) ;
+<a name="l00178"></a>00178     pline = cpl_vector_get_data(line) ;
+<a name="l00179"></a>00179     <span class="keywordflow">for</span> (i=0 ; i<cpl_vector_get_size(line) ; i++)
+<a name="l00180"></a>00180         pcollapsed[i] = (<span class="keywordtype">float</span>)pline[i] ;
+<a name="l00181"></a>00181     cpl_vector_delete(line) ;
+<a name="l00182"></a>00182 
+<a name="l00183"></a>00183     <span class="comment">/* Binarise the image */</span>
+<a name="l00184"></a>00184     <span class="keywordflow">if</span> ((mask = cpl_mask_threshold_image_create(collapsed, threshold,
+<a name="l00185"></a>00185             DBL_MAX)) == NULL) {
+<a name="l00186"></a>00186         cpl_msg_error(cpl_func, <span class="stringliteral">"cannot binarise"</span>) ;
+<a name="l00187"></a>00187         cpl_image_delete(collapsed) ;
+<a name="l00188"></a>00188         <span class="keywordflow">return</span> -1 ;
+<a name="l00189"></a>00189     }
+<a name="l00190"></a>00190     <span class="keywordflow">if</span> (cpl_mask_count(mask) < 1) {
+<a name="l00191"></a>00191         cpl_msg_error(cpl_func, <span class="stringliteral">"not enough signal to detect spectra"</span>) ;
+<a name="l00192"></a>00192         cpl_image_delete(collapsed) ;
+<a name="l00193"></a>00193         cpl_mask_delete(mask) ;
+<a name="l00194"></a>00194         <span class="keywordflow">return</span> -1 ;
+<a name="l00195"></a>00195     }
+<a name="l00196"></a>00196     <span class="comment">/* Labelise the different detected apertures */</span>
+<a name="l00197"></a>00197     <span class="keywordflow">if</span> ((labels = cpl_image_labelise_mask_create(mask, &nlabels))==NULL) {
+<a name="l00198"></a>00198         cpl_msg_error(cpl_func, <span class="stringliteral">"cannot labelise"</span>) ;
+<a name="l00199"></a>00199         cpl_image_delete(collapsed) ;
+<a name="l00200"></a>00200         cpl_mask_delete(mask) ;
+<a name="l00201"></a>00201         <span class="keywordflow">return</span> -1 ;
+<a name="l00202"></a>00202     }
+<a name="l00203"></a>00203     cpl_mask_delete(mask) ;
+<a name="l00204"></a>00204 
+<a name="l00205"></a>00205     <span class="comment">/* Create the detected apertures list */</span>
+<a name="l00206"></a>00206     <span class="keywordflow">if</span> ((aperts = cpl_apertures_new_from_image(collapsed, labels)) == NULL) {
+<a name="l00207"></a>00207         cpl_msg_error(cpl_func, <span class="stringliteral">"cannot compute apertures"</span>) ;
+<a name="l00208"></a>00208         cpl_image_delete(collapsed) ;
+<a name="l00209"></a>00209         cpl_image_delete(labels) ;
+<a name="l00210"></a>00210         <span class="keywordflow">return</span> -1 ;
+<a name="l00211"></a>00211     }
+<a name="l00212"></a>00212     cpl_image_delete(labels) ;
+<a name="l00213"></a>00213 
+<a name="l00214"></a>00214     <span class="comment">/* Select only relevant specs, create corresponding LUT's */</span>
+<a name="l00215"></a>00215     <span class="keywordflow">if</span> (select_valid_spectra(collapsed, aperts, offset, shadows, SPEC_MAXWIDTH,
+<a name="l00216"></a>00216                 &n_valid_specs, &valid_specs) == -1) {
+<a name="l00217"></a>00217         cpl_msg_debug(cpl_func, 
+<a name="l00218"></a>00218                 <span class="stringliteral">"Could not select valid spectra from the %"</span>CPL_SIZE_FORMAT
+<a name="l00219"></a>00219                 <span class="stringliteral">" apertures in %"</span>CPL_SIZE_FORMAT<span class="stringliteral">"-col 1D-image, offset=%d"</span>
+<a name="l00220"></a>00220                 <span class="stringliteral">", min_bright=%d"</span>,
+<a name="l00221"></a>00221                       cpl_apertures_get_size(aperts),
+<a name="l00222"></a>00222                       cpl_image_get_size_y(collapsed), offset, SPEC_MAXWIDTH);
+<a name="l00223"></a>00223         <span class="keywordflow">if</span> (cpl_msg_get_level() <= CPL_MSG_DEBUG)
+<a name="l00224"></a>00224             cpl_apertures_dump(aperts, stderr);
+<a name="l00225"></a>00225         cpl_image_delete(collapsed);
+<a name="l00226"></a>00226         cpl_apertures_delete(aperts);
+<a name="l00227"></a>00227         <span class="keywordflow">return</span> -1;
+<a name="l00228"></a>00228     }
+<a name="l00229"></a>00229     cpl_image_delete(collapsed) ;
+<a name="l00230"></a>00230     <span class="keywordflow">if</span> (n_valid_specs < 1) {
+<a name="l00231"></a>00231         cpl_msg_error(cpl_func, <span class="stringliteral">"no valid spectrum detected"</span>) ;
+<a name="l00232"></a>00232         cpl_free(valid_specs) ;
+<a name="l00233"></a>00233         cpl_apertures_delete(aperts) ;
+<a name="l00234"></a>00234         <span class="keywordflow">return</span> -1 ;
+<a name="l00235"></a>00235     }
+<a name="l00236"></a>00236 
+<a name="l00237"></a>00237     <span class="comment">/* Look for the brightest, among the detected spectra */</span>
+<a name="l00238"></a>00238     *pos = cpl_apertures_get_centroid_y(aperts, valid_specs[0]+1) ;
+<a name="l00239"></a>00239     brightness = cpl_apertures_get_flux(aperts, valid_specs[0]+1) ;
+<a name="l00240"></a>00240     <span class="keywordflow">for</span> (i=0 ; i<n_valid_specs ; i++) {
+<a name="l00241"></a>00241         <span class="keywordflow">if</span> (cpl_apertures_get_flux(aperts, valid_specs[i]+1) > brightness) {
+<a name="l00242"></a>00242             *pos = cpl_apertures_get_centroid_y(aperts, valid_specs[i]+1) ;
+<a name="l00243"></a>00243             brightness = cpl_apertures_get_flux(aperts, valid_specs[i]+1) ;
+<a name="l00244"></a>00244         }
+<a name="l00245"></a>00245     }
+<a name="l00246"></a>00246     cpl_apertures_delete(aperts) ;
+<a name="l00247"></a>00247     cpl_free(valid_specs) ;
+<a name="l00248"></a>00248 
+<a name="l00249"></a>00249     <span class="comment">/* Minimum brightness required */</span>
+<a name="l00250"></a>00250     <span class="keywordflow">if</span> (brightness < min_bright) {
+<a name="l00251"></a>00251         cpl_msg_error(cpl_func, <span class="stringliteral">"brightness %f too low <%f"</span>, brightness,
+<a name="l00252"></a>00252                 min_bright) ;
+<a name="l00253"></a>00253         <span class="keywordflow">return</span> -1 ;
+<a name="l00254"></a>00254     }
+<a name="l00255"></a>00255 
+<a name="l00256"></a>00256     <span class="comment">/* Return */</span>
+<a name="l00257"></a>00257     <span class="keywordflow">return</span> 0 ;
+<a name="l00258"></a>00258 }
+<a name="l00259"></a>00259 
+<a name="l00260"></a>00260 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00272"></a>00272 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00273"></a><a class="code" href="group__irplib__spectrum.html#ga1885902c29d7383674c85e2c3d935961">00273</a> cpl_vector * <a class="code" href="group__irplib__spectrum.html#ga1885902c29d7383674c85e2c3d935961" title="Detect the brightest features in a spectrum.">irplib_spectrum_detect_peaks</a>(
+<a name="l00274"></a>00274         <span class="keyword">const</span> cpl_vector    *   in,
+<a name="l00275"></a>00275         <span class="keywordtype">int</span>                     fwhm,
+<a name="l00276"></a>00276         <span class="keywordtype">double</span>                  sigma,
+<a name="l00277"></a>00277         <span class="keywordtype">int</span>                     display,
+<a name="l00278"></a>00278         cpl_vector          **  fwhms_out,
+<a name="l00279"></a>00279         cpl_vector          **  areas_out)
+<a name="l00280"></a>00280 {
+<a name="l00281"></a>00281     cpl_vector      *   filtered ;
+<a name="l00282"></a>00282     cpl_vector      *   spec_clean ;
+<a name="l00283"></a>00283     cpl_vector      *   spec_convolved ;
+<a name="l00284"></a>00284     <span class="keywordtype">double</span>          *   pspec_convolved ;
+<a name="l00285"></a>00285     <span class="keywordtype">int</span>                 filt_size ;
+<a name="l00286"></a>00286     cpl_vector      *   conv_kernel ;
+<a name="l00287"></a>00287     cpl_vector      *   extract ;
+<a name="l00288"></a>00288     cpl_vector      *   extract_x ;
+<a name="l00289"></a>00289     cpl_vector      *   big_detected ;
+<a name="l00290"></a>00290     cpl_vector      *   big_fwhms ;
+<a name="l00291"></a>00291     cpl_vector      *   big_area ;
+<a name="l00292"></a>00292     <span class="keywordtype">double</span>          *   pbig_detected ;
+<a name="l00293"></a>00293     <span class="keywordtype">double</span>          *   pbig_fwhms ;
+<a name="l00294"></a>00294     <span class="keywordtype">double</span>          *   pbig_area ;
+<a name="l00295"></a>00295     cpl_vector      *   detected ;
+<a name="l00296"></a>00296     <span class="keywordtype">double</span>          *   pdetected ;
+<a name="l00297"></a>00297     cpl_vector      *   fwhms ;
+<a name="l00298"></a>00298     <span class="keywordtype">double</span>          *   pfwhms ;
+<a name="l00299"></a>00299     cpl_vector      *   area ;
+<a name="l00300"></a>00300     <span class="keywordtype">double</span>          *   parea ;
+<a name="l00301"></a>00301     <span class="keywordtype">double</span>              max, med, stdev, cur_val ;
+<a name="l00302"></a>00302     <span class="keywordtype">double</span>              x0, sig, norm, offset ;
+<a name="l00303"></a>00303     <span class="keywordtype">int</span>                 nb_det, nb_samples, hwidth, start, stop ;
+<a name="l00304"></a>00304     <span class="keywordtype">int</span>                 i, j ;
+<a name="l00305"></a>00305 
+<a name="l00306"></a>00306     <span class="comment">/* Test entries */</span>
+<a name="l00307"></a>00307     <span class="keywordflow">if</span> (in == NULL) <span class="keywordflow">return</span> NULL ;
+<a name="l00308"></a>00308 
+<a name="l00309"></a>00309     <span class="comment">/* Initialise */</span>
+<a name="l00310"></a>00310     nb_samples = cpl_vector_get_size(in) ;
+<a name="l00311"></a>00311     filt_size = 5 ;
+<a name="l00312"></a>00312     hwidth = 5 ;
+<a name="l00313"></a>00313 
+<a name="l00314"></a>00314     <span class="comment">/* Subtract the low frequency part */</span>
+<a name="l00315"></a>00315     cpl_msg_info(__func__, <span class="stringliteral">"Low Frequency signal removal"</span>) ;
+<a name="l00316"></a>00316     <span class="keywordflow">if</span> ((filtered=cpl_vector_filter_median_create(in, filt_size))==NULL){
+<a name="l00317"></a>00317         cpl_msg_error(__func__, <span class="stringliteral">"Cannot filter the spectrum"</span>) ;
+<a name="l00318"></a>00318         <span class="keywordflow">return</span> NULL ;
+<a name="l00319"></a>00319     }
+<a name="l00320"></a>00320     spec_clean = cpl_vector_duplicate(in) ;
+<a name="l00321"></a>00321     cpl_vector_subtract(spec_clean, filtered) ;
+<a name="l00322"></a>00322     cpl_vector_delete(filtered) ;
+<a name="l00323"></a>00323 
+<a name="l00324"></a>00324     <span class="comment">/* Display if requested */</span>
+<a name="l00325"></a>00325     <span class="keywordflow">if</span> (display) {
+<a name="l00326"></a>00326         cpl_plot_vector(
+<a name="l00327"></a>00327     <span class="stringliteral">"set grid;set xlabel 'Position (pixels)';set ylabel 'Intensity (ADU)';"</span>,
+<a name="l00328"></a>00328         <span class="stringliteral">"t 'Filtered extracted spectrum' w lines"</span>, <span class="stringliteral">""</span>, spec_clean);
+<a name="l00329"></a>00329     }
+<a name="l00330"></a>00330 
+<a name="l00331"></a>00331     <span class="comment">/* Convolve */</span>
+<a name="l00332"></a>00332     spec_convolved = cpl_vector_duplicate(spec_clean) ;
+<a name="l00333"></a>00333     <span class="keywordflow">if</span> (fwhm > 0) {
+<a name="l00334"></a>00334         cpl_msg_info(__func__, <span class="stringliteral">"Spectrum convolution"</span>) ;
+<a name="l00335"></a>00335         <span class="comment">/* Create convolution kernel */</span>
+<a name="l00336"></a>00336         <span class="keywordflow">if</span> ((conv_kernel = irplib_wlxcorr_convolve_create_kernel(fwhm,
+<a name="l00337"></a>00337                         fwhm)) == NULL) {
+<a name="l00338"></a>00338             cpl_msg_error(cpl_func, <span class="stringliteral">"Cannot create convolution kernel"</span>) ;
+<a name="l00339"></a>00339             cpl_vector_delete(spec_clean) ;
+<a name="l00340"></a>00340             cpl_vector_delete(spec_convolved) ;
+<a name="l00341"></a>00341             <span class="keywordflow">return</span> NULL ;
+<a name="l00342"></a>00342         }
+<a name="l00343"></a>00343 
+<a name="l00344"></a>00344         <span class="comment">/* Smooth the instrument resolution */</span>
+<a name="l00345"></a>00345         <span class="keywordflow">if</span> (irplib_wlxcorr_convolve(spec_convolved, conv_kernel)) {
+<a name="l00346"></a>00346             cpl_msg_error(cpl_func, <span class="stringliteral">"Cannot smoothe the signal"</span>);
+<a name="l00347"></a>00347             cpl_vector_delete(spec_clean) ;
+<a name="l00348"></a>00348             cpl_vector_delete(spec_convolved) ;
+<a name="l00349"></a>00349             cpl_vector_delete(conv_kernel) ;
+<a name="l00350"></a>00350             <span class="keywordflow">return</span> NULL ;
+<a name="l00351"></a>00351         }
+<a name="l00352"></a>00352         cpl_vector_delete(conv_kernel) ;
+<a name="l00353"></a>00353 
+<a name="l00354"></a>00354         <span class="comment">/* Display if requested */</span>
+<a name="l00355"></a>00355         <span class="keywordflow">if</span> (display) {
+<a name="l00356"></a>00356             cpl_plot_vector(
+<a name="l00357"></a>00357         <span class="stringliteral">"set grid;set xlabel 'Position (pixels)';set ylabel 'Intensity (ADU)';"</span>,
+<a name="l00358"></a>00358             <span class="stringliteral">"t 'Convolved extracted spectrum' w lines"</span>, <span class="stringliteral">""</span>, spec_convolved);
+<a name="l00359"></a>00359         }
+<a name="l00360"></a>00360     }
+<a name="l00361"></a>00361 
+<a name="l00362"></a>00362     <span class="comment">/* Apply the detection */</span>
+<a name="l00363"></a>00363     big_detected = cpl_vector_duplicate(spec_convolved) ;
+<a name="l00364"></a>00364     big_fwhms = cpl_vector_duplicate(spec_convolved) ;
+<a name="l00365"></a>00365     big_area = cpl_vector_duplicate(spec_convolved) ;
+<a name="l00366"></a>00366     pbig_detected = cpl_vector_get_data(big_detected) ;
+<a name="l00367"></a>00367     pbig_fwhms = cpl_vector_get_data(big_fwhms) ;
+<a name="l00368"></a>00368     pbig_area = cpl_vector_get_data(big_area) ;
+<a name="l00369"></a>00369     
+<a name="l00370"></a>00370     pspec_convolved = cpl_vector_get_data(spec_convolved) ;
+<a name="l00371"></a>00371 
+<a name="l00372"></a>00372     <span class="comment">/* To avoid detection on the side */</span>
+<a name="l00373"></a>00373     pspec_convolved[0] = pspec_convolved[nb_samples-1] = 0.0 ;
+<a name="l00374"></a>00374 
+<a name="l00375"></a>00375     <span class="comment">/* Compute stats */</span>
+<a name="l00376"></a>00376     max     =   cpl_vector_get_max(spec_convolved) ;
+<a name="l00377"></a>00377     stdev   =   cpl_vector_get_stdev(spec_convolved) ;
+<a name="l00378"></a>00378     med     =   cpl_vector_get_median_const(spec_convolved) ;
+<a name="l00379"></a>00379 
+<a name="l00380"></a>00380     <span class="comment">/* Loop on the detected lines */</span>
+<a name="l00381"></a>00381     nb_det = 0 ;
+<a name="l00382"></a>00382     <span class="keywordflow">while</span> (max > med + stdev * sigma) {
+<a name="l00383"></a>00383         <span class="comment">/* Compute the position */</span>
+<a name="l00384"></a>00384         i=0 ;
+<a name="l00385"></a>00385         <span class="keywordflow">while</span> (pspec_convolved[i] < max) i++ ;
+<a name="l00386"></a>00386         <span class="keywordflow">if</span> (i<=0 || i>=nb_samples-1) break ;
+<a name="l00387"></a>00387 
+<a name="l00388"></a>00388         <span class="comment">/* Extract the line */</span>
+<a name="l00389"></a>00389         <span class="keywordflow">if</span> (i - hwidth >= 0)                start = i - hwidth ;
+<a name="l00390"></a>00390         <span class="keywordflow">else</span>                                start = 0 ;
+<a name="l00391"></a>00391         <span class="keywordflow">if</span> (i + hwidth <= nb_samples-1)     stop = i + hwidth ;
+<a name="l00392"></a>00392         <span class="keywordflow">else</span>                                stop = nb_samples-1 ;
+<a name="l00393"></a>00393         extract = cpl_vector_extract(spec_clean, start, stop, 1) ;
+<a name="l00394"></a>00394         extract_x = cpl_vector_duplicate(extract) ;
+<a name="l00395"></a>00395         <span class="keywordflow">for</span> (j=0 ; j<cpl_vector_get_size(extract_x) ; j++) {
+<a name="l00396"></a>00396             cpl_vector_set(extract_x, j, (<span class="keywordtype">double</span>)j+1) ;
+<a name="l00397"></a>00397         }
+<a name="l00398"></a>00398         <span class="comment">/* Fit the gaussian */</span>
+<a name="l00399"></a>00399         <span class="keywordflow">if</span> (cpl_vector_fit_gaussian(extract_x, NULL, extract, NULL, 
+<a name="l00400"></a>00400                     CPL_FIT_ALL, &x0, &sig, &norm, &offset, NULL, NULL, 
+<a name="l00401"></a>00401                     NULL) != CPL_ERROR_NONE) {
+<a name="l00402"></a>00402             cpl_msg_warning(__func__, 
+<a name="l00403"></a>00403                     <span class="stringliteral">"Cannot fit a gaussian at [%d, %d]"</span>,
+<a name="l00404"></a>00404                     start, stop) ;
+<a name="l00405"></a>00405             cpl_error_reset() ;
+<a name="l00406"></a>00406         } <span class="keywordflow">else</span> {
+<a name="l00407"></a>00407             pbig_detected[nb_det] = x0+start ;
+<a name="l00408"></a>00408             pbig_area[nb_det] = norm ;
+<a name="l00409"></a>00409             pbig_fwhms[nb_det] = 2*sig*sqrt(2*log(2)) ;
+<a name="l00410"></a>00410             cpl_msg_debug(__func__, <span class="stringliteral">"Line nb %d at position %g"</span>,
+<a name="l00411"></a>00411                     nb_det+1, pbig_detected[nb_det]) ;
+<a name="l00412"></a>00412             nb_det ++ ;
+<a name="l00413"></a>00413         }
+<a name="l00414"></a>00414         cpl_vector_delete(extract) ;
+<a name="l00415"></a>00415         cpl_vector_delete(extract_x) ;
+<a name="l00416"></a>00416 
+<a name="l00417"></a>00417         <span class="comment">/* Cancel out the line on the left */</span>
+<a name="l00418"></a>00418         j = i-1 ;
+<a name="l00419"></a>00419         cur_val = pspec_convolved[i] ;
+<a name="l00420"></a>00420         <span class="keywordflow">while</span> (j>=0 && pspec_convolved[j] < cur_val) {
+<a name="l00421"></a>00421             cur_val = pspec_convolved[j] ;
+<a name="l00422"></a>00422             pspec_convolved[j] = 0.0 ;
+<a name="l00423"></a>00423             j-- ;
+<a name="l00424"></a>00424         }
+<a name="l00425"></a>00425         <span class="comment">/* Cancel out the line on the right */</span>
+<a name="l00426"></a>00426         j = i+1 ;
+<a name="l00427"></a>00427         cur_val = pspec_convolved[i] ;
+<a name="l00428"></a>00428         <span class="keywordflow">while</span> (j<=nb_samples-1 && pspec_convolved[j] < cur_val) {
+<a name="l00429"></a>00429             cur_val = pspec_convolved[j] ;
+<a name="l00430"></a>00430             pspec_convolved[j] = 0.0 ;
+<a name="l00431"></a>00431             j++ ;
+<a name="l00432"></a>00432         }
+<a name="l00433"></a>00433         <span class="comment">/* Cancel out the line on center */</span>
+<a name="l00434"></a>00434         pspec_convolved[i] = 0.0 ;
+<a name="l00435"></a>00435 
+<a name="l00436"></a>00436         <span class="comment">/* Recompute the stats */</span>
+<a name="l00437"></a>00437         max     =   cpl_vector_get_max(spec_convolved) ;
+<a name="l00438"></a>00438         stdev   =   cpl_vector_get_stdev(spec_convolved) ;
+<a name="l00439"></a>00439         med     =   cpl_vector_get_median_const(spec_convolved) ;
+<a name="l00440"></a>00440     }
+<a name="l00441"></a>00441     cpl_vector_delete(spec_convolved) ;
+<a name="l00442"></a>00442     cpl_vector_delete(spec_clean) ;
+<a name="l00443"></a>00443 
+<a name="l00444"></a>00444     <span class="comment">/* Create the output vector */</span>
+<a name="l00445"></a>00445     <span class="keywordflow">if</span> (nb_det == 0) {
+<a name="l00446"></a>00446         detected = NULL ;
+<a name="l00447"></a>00447         area = NULL ;
+<a name="l00448"></a>00448         fwhms = NULL ;
+<a name="l00449"></a>00449     } <span class="keywordflow">else</span> {
+<a name="l00450"></a>00450         detected = cpl_vector_new(nb_det) ;
+<a name="l00451"></a>00451         area = cpl_vector_new(nb_det) ;
+<a name="l00452"></a>00452         fwhms = cpl_vector_new(nb_det) ;
+<a name="l00453"></a>00453         pdetected = cpl_vector_get_data(detected) ;
+<a name="l00454"></a>00454         parea = cpl_vector_get_data(area) ;
+<a name="l00455"></a>00455         pfwhms = cpl_vector_get_data(fwhms) ;
+<a name="l00456"></a>00456         <span class="keywordflow">for</span> (i=0 ; i<nb_det ; i++) {
+<a name="l00457"></a>00457             pdetected[i] = pbig_detected[i] ;
+<a name="l00458"></a>00458             parea[i] = pbig_area[i] ;
+<a name="l00459"></a>00459             pfwhms[i] = pbig_fwhms[i] ;
+<a name="l00460"></a>00460         }
+<a name="l00461"></a>00461     }
+<a name="l00462"></a>00462     cpl_vector_delete(big_detected) ;
+<a name="l00463"></a>00463     cpl_vector_delete(big_area) ;
+<a name="l00464"></a>00464     cpl_vector_delete(big_fwhms) ;
+<a name="l00465"></a>00465 
+<a name="l00466"></a>00466     <span class="comment">/* Return  */</span>
+<a name="l00467"></a>00467     <span class="keywordflow">if</span> (fwhms_out == NULL)  cpl_vector_delete(fwhms) ;
+<a name="l00468"></a>00468     <span class="keywordflow">else</span>                    *fwhms_out = fwhms ;
+<a name="l00469"></a>00469     <span class="keywordflow">if</span> (areas_out == NULL)  cpl_vector_delete(area) ;
+<a name="l00470"></a>00470     <span class="keywordflow">else</span>                    *areas_out = area ;
+<a name="l00471"></a>00471     <span class="keywordflow">return</span> detected ;
+<a name="l00472"></a>00472 }
+<a name="l00473"></a>00473 
+<a name="l00476"></a>00476 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00488"></a>00488 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00489"></a>00489 <span class="keyword">static</span> <span class="keywordtype">int</span> select_valid_spectra(
+<a name="l00490"></a>00490         cpl_image       *   in,
+<a name="l00491"></a>00491         cpl_apertures   *   aperts,
+<a name="l00492"></a>00492         <span class="keywordtype">int</span>                 offset,
+<a name="l00493"></a>00493         spec_shadows        shadows,
+<a name="l00494"></a>00494         <span class="keywordtype">int</span>                 max_spec_width,
+<a name="l00495"></a>00495         <span class="keywordtype">int</span>             *   n_valid_specs,
+<a name="l00496"></a>00496         <span class="keywordtype">int</span>             **  valid_specs)
+<a name="l00497"></a>00497 {
+<a name="l00498"></a>00498     <span class="keywordtype">int</span>                 nb_aperts ;
+<a name="l00499"></a>00499     <span class="keywordtype">int</span>                 i, j ;
+<a name="l00500"></a>00500 
+<a name="l00501"></a>00501     <span class="comment">/* Initialise */</span>
+<a name="l00502"></a>00502     *valid_specs = NULL ;
+<a name="l00503"></a>00503     nb_aperts = cpl_apertures_get_size(aperts) ;
+<a name="l00504"></a>00504     *n_valid_specs = 0 ;
+<a name="l00505"></a>00505 
+<a name="l00506"></a>00506     <span class="comment">/* Test entries */</span>
+<a name="l00507"></a>00507     <span class="keywordflow">if</span> (nb_aperts < 1) <span class="keywordflow">return</span> -1 ;
+<a name="l00508"></a>00508 
+<a name="l00509"></a>00509     <span class="comment">/* Count nb of valid specs */</span>
+<a name="l00510"></a>00510     j = 0 ;
+<a name="l00511"></a>00511     <span class="keywordflow">for</span> (i=0 ; i<nb_aperts ; i++)
+<a name="l00512"></a>00512         <span class="keywordflow">if</span> (valid_spectrum(in, aperts, offset, shadows, max_spec_width,
+<a name="l00513"></a>00513                     i+1)) (*n_valid_specs)++ ;
+<a name="l00514"></a>00514 
+<a name="l00515"></a>00515     <span class="comment">/* Associate to each spectrum, its object number */</span>
+<a name="l00516"></a>00516     <span class="keywordflow">if</span> (*n_valid_specs) {
+<a name="l00517"></a>00517         *valid_specs = cpl_calloc(*n_valid_specs, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>)) ;
+<a name="l00518"></a>00518         j = 0 ;
+<a name="l00519"></a>00519         <span class="keywordflow">for</span> (i=0 ; i<nb_aperts ; i++)
+<a name="l00520"></a>00520             <span class="keywordflow">if</span> (valid_spectrum(in, aperts, offset, shadows, max_spec_width,
+<a name="l00521"></a>00521                         i+1)) {
+<a name="l00522"></a>00522                 (*valid_specs)[j] = i ;
+<a name="l00523"></a>00523                 j++ ;
+<a name="l00524"></a>00524             }
+<a name="l00525"></a>00525     } <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00526"></a>00526 
+<a name="l00527"></a>00527     <span class="keywordflow">return</span> 0 ;
+<a name="l00528"></a>00528 }
+<a name="l00529"></a>00529 
+<a name="l00530"></a>00530 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00541"></a>00541 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00542"></a>00542 <span class="keyword">static</span> <span class="keywordtype">int</span> valid_spectrum(
+<a name="l00543"></a>00543         cpl_image       *   in,
+<a name="l00544"></a>00544         cpl_apertures   *   aperts,
+<a name="l00545"></a>00545         <span class="keywordtype">int</span>                 offset,
+<a name="l00546"></a>00546         spec_shadows        shadows,
+<a name="l00547"></a>00547         <span class="keywordtype">int</span>                 max_spec_width,
+<a name="l00548"></a>00548         <span class="keywordtype">int</span>                 objnum)
+<a name="l00549"></a>00549 {
+<a name="l00550"></a>00550     <span class="keywordtype">int</span>                 objwidth ;
+<a name="l00551"></a>00551     <span class="keywordtype">double</span>              valover, valunder, valcenter ;
+<a name="l00552"></a>00552 
+<a name="l00553"></a>00553     <span class="comment">/* Find objwidth */</span>
+<a name="l00554"></a>00554     objwidth = cpl_apertures_get_top(aperts, objnum) -
+<a name="l00555"></a>00555         cpl_apertures_get_bottom(aperts, objnum) + 1 ;
+<a name="l00556"></a>00556     <span class="keywordflow">if</span> (objwidth > max_spec_width) {
+<a name="l00557"></a>00557         cpl_msg_error(cpl_func, <span class="stringliteral">"object is too wide"</span>) ;
+<a name="l00558"></a>00558         <span class="keywordflow">return</span> 0 ;
+<a name="l00559"></a>00559     }
+<a name="l00560"></a>00560 
+<a name="l00561"></a>00561     <span class="comment">/* Object is too small */</span>
+<a name="l00562"></a>00562     <span class="keywordflow">if</span> (cpl_apertures_get_npix(aperts, objnum) < 2) <span class="keywordflow">return</span> 0 ;
+<a name="l00563"></a>00563 
+<a name="l00564"></a>00564     <span class="comment">/* no shadow required */</span>
+<a name="l00565"></a>00565     <span class="keywordflow">if</span> (shadows == NO_SHADOW) <span class="keywordflow">return</span> 1 ;
+<a name="l00566"></a>00566 
+<a name="l00567"></a>00567     <span class="comment">/* Get the median of the object (valcenter) */</span>
+<a name="l00568"></a>00568     valcenter = cpl_apertures_get_median(aperts, objnum) ;
+<a name="l00569"></a>00569 
+<a name="l00570"></a>00570     <span class="comment">/* Get the black shadows medians (valunder and valover) */</span>
+<a name="l00571"></a>00571     <span class="keywordflow">if</span> (cpl_apertures_get_bottom(aperts, objnum) - offset < 1) valunder = 0.0 ;
+<a name="l00572"></a>00572     <span class="keywordflow">else</span> valunder = cpl_image_get_median_window(in, 1,
+<a name="l00573"></a>00573             cpl_apertures_get_bottom(aperts, objnum) - offset, 1, 
+<a name="l00574"></a>00574             cpl_apertures_get_top(aperts, objnum) - offset) ;
+<a name="l00575"></a>00575     
+<a name="l00576"></a>00576     <span class="keywordflow">if</span> (cpl_apertures_get_top(aperts, objnum) + offset > 1024) valover = 0.0 ;
+<a name="l00577"></a>00577     <span class="keywordflow">else</span> valover = cpl_image_get_median_window(in, 1,
+<a name="l00578"></a>00578             cpl_apertures_get_bottom(aperts, objnum) + offset, 1, 
+<a name="l00579"></a>00579             cpl_apertures_get_top(aperts, objnum) + offset) ;
+<a name="l00580"></a>00580 
+<a name="l00581"></a>00581     <span class="keywordflow">switch</span> (shadows) {
+<a name="l00582"></a>00582         <span class="keywordflow">case</span> TWO_SHADOWS:
+<a name="l00583"></a>00583         <span class="keywordflow">if</span> ((valunder < -fabs(valcenter/SPEC_SHADOW_FACT)) &&
+<a name="l00584"></a>00584             (valover < -fabs(valcenter/SPEC_SHADOW_FACT))    &&
+<a name="l00585"></a>00585             (valunder/valover > 0.5) &&
+<a name="l00586"></a>00586             (valunder/valover < 2.0)) <span class="keywordflow">return</span> 1 ;
+<a name="l00587"></a>00587         <span class="keywordflow">break</span>;
+<a name="l00588"></a>00588 
+<a name="l00589"></a>00589         <span class="keywordflow">case</span> ONE_SHADOW:
+<a name="l00590"></a>00590         <span class="keywordflow">if</span> ((valunder < -fabs(valcenter/SPEC_SHADOW_FACT)) ||
+<a name="l00591"></a>00591             (valover < -fabs(valcenter/SPEC_SHADOW_FACT))) <span class="keywordflow">return</span> 1 ;
+<a name="l00592"></a>00592         <span class="keywordflow">break</span>;
+<a name="l00593"></a>00593 
+<a name="l00594"></a>00594         <span class="keywordflow">case</span> NO_SHADOW:
+<a name="l00595"></a>00595         <span class="keywordflow">return</span> 1 ;
+<a name="l00596"></a>00596 
+<a name="l00597"></a>00597         <span class="keywordflow">default</span>:
+<a name="l00598"></a>00598         cpl_msg_error(cpl_func, <span class="stringliteral">"unknown spec_detect_mode"</span>) ;
+<a name="l00599"></a>00599         break ;
+<a name="l00600"></a>00600     }
+<a name="l00601"></a>00601 
+<a name="l00602"></a>00602     cpl_msg_debug(cpl_func, <span class="stringliteral">"No spectrum(%d): under=%g, center=%g, over=%g"</span>,
+<a name="l00603"></a>00603                   shadows, valunder, valcenter, valover);
+<a name="l00604"></a>00604 
+<a name="l00605"></a>00605     <span class="keywordflow">return</span> 0 ;
+<a name="l00606"></a>00606 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/irplib__spectrum_8h_source.html b/html/irplib__spectrum_8h_source.html
new file mode 100644
index 0000000..e85faf9
--- /dev/null
+++ b/html/irplib__spectrum_8h_source.html
@@ -0,0 +1,75 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: irplib_spectrum.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>irplib_spectrum.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: irplib_spectrum.h,v 1.7 2009/07/30 12:38:37 yjung Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the irplib package</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: yjung $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2009/07/30 12:38:37 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.7 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifndef IRPLIB_SPECTRUM_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#define IRPLIB_SPECTRUM_H</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span>
+<a name="l00031"></a>00031 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00032"></a>00032 <span class="comment">                                   Includes</span>
+<a name="l00033"></a>00033 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00034"></a>00034 
+<a name="l00035"></a>00035 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00038"></a>00038 <span class="comment">                                New types</span>
+<a name="l00039"></a>00039 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00040"></a>00040 
+<a name="l00041"></a>00041 <span class="keyword">typedef</span> <span class="keyword">enum</span> SPEC_SHADOWS {
+<a name="l00042"></a>00042     <span class="comment">/* 2 shadows above and below true spectrum */</span>
+<a name="l00043"></a>00043     TWO_SHADOWS,
+<a name="l00044"></a>00044     <span class="comment">/* 1 shadow at specified distance from spectrum */</span>
+<a name="l00045"></a>00045     ONE_SHADOW,
+<a name="l00046"></a>00046     <span class="comment">/* Do not search for shadow */</span>
+<a name="l00047"></a>00047     NO_SHADOW
+<a name="l00048"></a>00048 } spec_shadows ;
+<a name="l00049"></a>00049 
+<a name="l00050"></a>00050 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00051"></a>00051 <span class="comment">                                Prototypes</span>
+<a name="l00052"></a>00052 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00053"></a>00053 
+<a name="l00054"></a>00054 <span class="keywordtype">int</span> <a class="code" href="group__irplib__spectrum.html#ga9ac928ba9a48e864b56e921c970638c0" title="Finds the brightest spectrum in an image.">irplib_spectrum_find_brightest</a>(<span class="keyword">const</span> cpl_image *, <span class="keywordtype">int</span>, spec_shadows, 
+<a name="l00055"></a>00055         <span class="keywordtype">double</span>, <span class="keywordtype">int</span>, <span class="keywordtype">double</span> *) ;
+<a name="l00056"></a>00056 cpl_vector * <a class="code" href="group__irplib__spectrum.html#ga1885902c29d7383674c85e2c3d935961" title="Detect the brightest features in a spectrum.">irplib_spectrum_detect_peaks</a>(<span class="keyword">const</span> cpl_vector *, <span class="keywordtype">int</span>,
+<a name="l00057"></a>00057         <span class="keywordtype">double</span>, <span class="keywordtype">int</span>, cpl_vector **, cpl_vector **) ;
+<a name="l00058"></a>00058 
+<a name="l00059"></a>00059 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/irplib__stdstar_8c_source.html b/html/irplib__stdstar_8c_source.html
new file mode 100644
index 0000000..3e3912b
--- /dev/null
+++ b/html/irplib__stdstar_8c_source.html
@@ -0,0 +1,719 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: irplib_stdstar.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>irplib_stdstar.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: irplib_stdstar.c,v 1.41 2012/05/04 13:58:12 cgarcia Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the irplib package</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: cgarcia $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2012/05/04 13:58:12 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.41 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span>
+<a name="l00032"></a>00032 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                                   Includes</span>
+<a name="l00034"></a>00034 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 
+<a name="l00036"></a>00036 <span class="preprocessor">#include <string.h></span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include <math.h></span>
+<a name="l00038"></a>00038 <span class="preprocessor">#include <float.h></span>
+<a name="l00039"></a>00039 
+<a name="l00040"></a>00040 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00041"></a>00041 
+<a name="l00042"></a>00042 <span class="preprocessor">#include "irplib_stdstar.h"</span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include "irplib_utils.h"</span>
+<a name="l00044"></a>00044 <span class="preprocessor">#include "irplib_wcs.h"</span>
+<a name="l00045"></a>00045 
+<a name="l00046"></a>00046 
+<a name="l00047"></a>00047 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00051"></a>00051 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00054"></a>00054 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00055"></a>00055 <span class="comment">                                   Functions code</span>
+<a name="l00056"></a>00056 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00057"></a>00057 
+<a name="l00058"></a>00058 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00077"></a>00077 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00078"></a><a class="code" href="group__irplib__stdstar.html#ga1d798cc23ce72891460133af03ee21ba">00078</a> <span class="keywordtype">int</span> <a class="code" href="group__irplib__stdstar.html#ga1d798cc23ce72891460133af03ee21ba" title="Write the ASCII catalogs as FITS files.">irplib_stdstar_write_catalogs</a>(
+<a name="l00079"></a>00079         cpl_frameset        *   set_in,
+<a name="l00080"></a>00080         <span class="keyword">const</span> cpl_frameset  *   set_raw,
+<a name="l00081"></a>00081         <span class="keyword">const</span> <span class="keywordtype">char</span>          *   recipe_name,
+<a name="l00082"></a>00082         <span class="keyword">const</span> <span class="keywordtype">char</span>          *   pro_cat,
+<a name="l00083"></a>00083         <span class="keyword">const</span> <span class="keywordtype">char</span>          *   pro_type,
+<a name="l00084"></a>00084         <span class="keyword">const</span> <span class="keywordtype">char</span>          *   package_name,
+<a name="l00085"></a>00085         <span class="keyword">const</span> <span class="keywordtype">char</span>          *   ins_name,
+<a name="l00086"></a>00086         cpl_table * (*convert_ascii_table)(<span class="keyword">const</span> <span class="keywordtype">char</span> *))
+<a name="l00087"></a>00087 {
+<a name="l00088"></a>00088     cpl_table           *   out ;
+<a name="l00089"></a>00089     cpl_propertylist    *   plist ;
+<a name="l00090"></a>00090     cpl_propertylist    *   plist_ext ;
+<a name="l00091"></a>00091     cpl_parameterlist   *   parlist ;
+<a name="l00092"></a>00092     <span class="keyword">const</span> <span class="keywordtype">char</span>          *   cat_name ;
+<a name="l00093"></a>00093     <span class="keywordtype">char</span>                *   out_name ;
+<a name="l00094"></a>00094     <span class="keywordtype">int</span>                     nb_catalogs ;
+<a name="l00095"></a>00095     <span class="keyword">const</span> cpl_frame     *   cur_frame ;
+<a name="l00096"></a>00096     <span class="keywordtype">int</span>                     i ;
+<a name="l00097"></a>00097 
+<a name="l00098"></a>00098     <span class="comment">/* Check entries */</span>
+<a name="l00099"></a>00099     <span class="keywordflow">if</span> (set_in == NULL) <span class="keywordflow">return</span> CPL_ERROR_NULL_INPUT;
+<a name="l00100"></a>00100     <span class="keywordflow">if</span> (set_raw == NULL) <span class="keywordflow">return</span> CPL_ERROR_NULL_INPUT;
+<a name="l00101"></a>00101     <span class="keywordflow">if</span> (recipe_name == NULL) <span class="keywordflow">return</span> CPL_ERROR_NULL_INPUT;
+<a name="l00102"></a>00102     <span class="keywordflow">if</span> (pro_cat == NULL) <span class="keywordflow">return</span> CPL_ERROR_NULL_INPUT;
+<a name="l00103"></a>00103     <span class="keywordflow">if</span> (ins_name == NULL) <span class="keywordflow">return</span> CPL_ERROR_NULL_INPUT;
+<a name="l00104"></a>00104 
+<a name="l00105"></a>00105     <span class="comment">/* Define the file name */</span>
+<a name="l00106"></a>00106     out_name = cpl_sprintf(<span class="stringliteral">"%s.fits"</span>, recipe_name) ;
+<a name="l00107"></a>00107     
+<a name="l00108"></a>00108     <span class="comment">/* Number of catalogs */</span>
+<a name="l00109"></a>00109     nb_catalogs = cpl_frameset_get_size(set_raw) ;
+<a name="l00110"></a>00110 
+<a name="l00111"></a>00111     <span class="comment">/* Get the catalog name */</span>
+<a name="l00112"></a>00112     cur_frame = cpl_frameset_get_frame_const(set_raw, 0) ;
+<a name="l00113"></a>00113     cat_name = cpl_frame_get_filename(cur_frame) ;
+<a name="l00114"></a>00114     
+<a name="l00115"></a>00115     <span class="comment">/* Create the output table */</span>
+<a name="l00116"></a>00116     <span class="keywordflow">if</span> ((out = convert_ascii_table(cat_name)) == NULL) {
+<a name="l00117"></a>00117         cpl_free(out_name) ;
+<a name="l00118"></a>00118         <span class="keywordflow">return</span> CPL_ERROR_UNSPECIFIED;
+<a name="l00119"></a>00119     }
+<a name="l00120"></a>00120 
+<a name="l00121"></a>00121     <span class="comment">/* Some keywords  */</span>
+<a name="l00122"></a>00122     plist = cpl_propertylist_new() ;
+<a name="l00123"></a>00123     cpl_propertylist_append_string(plist, <span class="stringliteral">"INSTRUME"</span>, ins_name) ;
+<a name="l00124"></a>00124     cpl_propertylist_append_string(plist, CPL_DFS_PRO_CATG, pro_cat) ;
+<a name="l00125"></a>00125     <span class="keywordflow">if</span> (pro_type != NULL) {
+<a name="l00126"></a>00126         cpl_propertylist_append_string(plist, CPL_DFS_PRO_TYPE, pro_type) ;
+<a name="l00127"></a>00127     }
+<a name="l00128"></a>00128     plist_ext = cpl_propertylist_new() ;
+<a name="l00129"></a>00129     cpl_propertylist_append_string(plist_ext, <span class="stringliteral">"EXTNAME"</span>, cat_name) ;
+<a name="l00130"></a>00130 
+<a name="l00131"></a>00131     <span class="comment">/* Write the table */</span>
+<a name="l00132"></a>00132     parlist = cpl_parameterlist_new() ;
+<a name="l00133"></a>00133     cpl_dfs_save_table(set_in, 
+<a name="l00134"></a>00134             NULL,
+<a name="l00135"></a>00135             parlist,
+<a name="l00136"></a>00136             set_raw,
+<a name="l00137"></a>00137             NULL,
+<a name="l00138"></a>00138             out,
+<a name="l00139"></a>00139             plist_ext,
+<a name="l00140"></a>00140             recipe_name,
+<a name="l00141"></a>00141             plist,
+<a name="l00142"></a>00142             NULL,
+<a name="l00143"></a>00143             package_name,
+<a name="l00144"></a>00144             out_name) ;
+<a name="l00145"></a>00145     cpl_parameterlist_delete(parlist) ;
+<a name="l00146"></a>00146     cpl_propertylist_delete(plist) ;
+<a name="l00147"></a>00147     cpl_propertylist_delete(plist_ext) ;
+<a name="l00148"></a>00148     cpl_table_delete(out) ;
+<a name="l00149"></a>00149     
+<a name="l00150"></a>00150     <span class="comment">/* Append the next catalogs */</span>
+<a name="l00151"></a>00151     <span class="keywordflow">for</span> (i=1 ; i<nb_catalogs ; i++) {
+<a name="l00152"></a>00152         <span class="comment">/* Get the catalog name */</span>
+<a name="l00153"></a>00153         cur_frame = cpl_frameset_get_frame_const(set_raw, i) ;
+<a name="l00154"></a>00154         cat_name = cpl_frame_get_filename(cur_frame) ;
+<a name="l00155"></a>00155      
+<a name="l00156"></a>00156         <span class="comment">/* Create the output table */</span>
+<a name="l00157"></a>00157         <span class="keywordflow">if</span> ((out = convert_ascii_table(cat_name)) == NULL) {
+<a name="l00158"></a>00158             cpl_free(out_name) ;
+<a name="l00159"></a>00159             <span class="keywordflow">return</span> CPL_ERROR_UNSPECIFIED;
+<a name="l00160"></a>00160         }
+<a name="l00161"></a>00161 
+<a name="l00162"></a>00162         plist_ext = cpl_propertylist_new() ;
+<a name="l00163"></a>00163         cpl_propertylist_append_string(plist_ext, <span class="stringliteral">"EXTNAME"</span>, cat_name) ;
+<a name="l00164"></a>00164         cpl_table_save(out, NULL, plist_ext, out_name, CPL_IO_EXTEND) ;
+<a name="l00165"></a>00165         cpl_table_delete(out) ;
+<a name="l00166"></a>00166         cpl_propertylist_delete(plist_ext) ;
+<a name="l00167"></a>00167     }
+<a name="l00168"></a>00168     cpl_free(out_name) ;
+<a name="l00169"></a>00169     <span class="keywordflow">return</span> 0 ;
+<a name="l00170"></a>00170 }
+<a name="l00171"></a>00171 
+<a name="l00172"></a>00172 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00185"></a>00185 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00186"></a><a class="code" href="group__irplib__stdstar.html#ga1690bd84c24e905e384b8f725bf7aff1">00186</a> cpl_table * <a class="code" href="group__irplib__stdstar.html#ga1690bd84c24e905e384b8f725bf7aff1" title="Load the FITS catalog in a table.">irplib_stdstar_load_catalog</a>(
+<a name="l00187"></a>00187         <span class="keyword">const</span> <span class="keywordtype">char</span>  *   filename, 
+<a name="l00188"></a>00188         <span class="keyword">const</span> <span class="keywordtype">char</span>  *   ext_name)
+<a name="l00189"></a>00189 {
+<a name="l00190"></a>00190     <span class="keywordtype">int</span>                     next ;
+<a name="l00191"></a>00191     cpl_propertylist    *   plist ;
+<a name="l00192"></a>00192     <span class="keyword">const</span> <span class="keywordtype">char</span>          *   cur_name ;
+<a name="l00193"></a>00193     cpl_table           *   out ;
+<a name="l00194"></a>00194     cpl_table           *   out_cur ;
+<a name="l00195"></a>00195     cpl_frame           *   cur_frame ;
+<a name="l00196"></a>00196     <span class="keywordtype">int</span>                     i ;
+<a name="l00197"></a>00197 
+<a name="l00198"></a>00198     <span class="comment">/* Check entries */</span>
+<a name="l00199"></a>00199     <span class="keywordflow">if</span> (filename == NULL) <span class="keywordflow">return</span> NULL ;
+<a name="l00200"></a>00200     <span class="keywordflow">if</span> (ext_name == NULL) <span class="keywordflow">return</span> NULL ;
+<a name="l00201"></a>00201     
+<a name="l00202"></a>00202     <span class="comment">/* Initialise */</span>
+<a name="l00203"></a>00203     out = NULL ;
+<a name="l00204"></a>00204     
+<a name="l00205"></a>00205     <span class="comment">/* Get the number of extensions in the catalog */</span>
+<a name="l00206"></a>00206     cur_frame = cpl_frame_new() ;
+<a name="l00207"></a>00207     cpl_frame_set_filename(cur_frame, filename) ;
+<a name="l00208"></a>00208     next = cpl_frame_get_nextensions(cur_frame) ;
+<a name="l00209"></a>00209     cpl_frame_delete(cur_frame) ;
+<a name="l00210"></a>00210 
+<a name="l00211"></a>00211     <span class="comment">/* Loop on the extentions */</span>
+<a name="l00212"></a>00212     <span class="keywordflow">for</span> (i=0 ; i<next ; i++) {
+<a name="l00213"></a>00213         <span class="comment">/* Check the name of the current extension */</span>
+<a name="l00214"></a>00214         <span class="keywordflow">if</span> ((plist = cpl_propertylist_load_regexp(filename, i+1, <span class="stringliteral">"EXTNAME"</span>, 
+<a name="l00215"></a>00215                         0)) == NULL) {
+<a name="l00216"></a>00216             cpl_msg_error(cpl_func, <span class="stringliteral">"Cannot load header of %d th extension"</span>,
+<a name="l00217"></a>00217                     i+1);
+<a name="l00218"></a>00218             <span class="keywordflow">return</span> NULL ;
+<a name="l00219"></a>00219         }
+<a name="l00220"></a>00220         cur_name = cpl_propertylist_get_string(plist, <span class="stringliteral">"EXTNAME"</span>) ;
+<a name="l00221"></a>00221         
+<a name="l00222"></a>00222         <span class="comment">/* Check the current extension */</span>
+<a name="l00223"></a>00223         <span class="keywordflow">if</span> (!strcmp(cur_name, ext_name)) {
+<a name="l00224"></a>00224             <span class="comment">/* Load the table */</span>
+<a name="l00225"></a>00225             <span class="keywordflow">if</span> (out == NULL) {
+<a name="l00226"></a>00226                 out = cpl_table_load(filename, i+1, 1) ;
+<a name="l00227"></a>00227                 cpl_table_new_column(out, IRPLIB_STDSTAR_CAT_COL, CPL_TYPE_STRING);
+<a name="l00228"></a>00228                 cpl_table_fill_column_window_string(out, IRPLIB_STDSTAR_CAT_COL,
+<a name="l00229"></a>00229                                                     0, cpl_table_get_nrow(out),
+<a name="l00230"></a>00230                                                     cur_name);
+<a name="l00231"></a>00231                 <span class="keywordflow">if</span> (out == NULL) {
+<a name="l00232"></a>00232                     cpl_msg_error(cpl_func, <span class="stringliteral">"Cannot load extension %d"</span>, i+1) ;
+<a name="l00233"></a>00233                     cpl_propertylist_delete(plist) ;
+<a name="l00234"></a>00234                     <span class="keywordflow">return</span> NULL ;
+<a name="l00235"></a>00235                 }
+<a name="l00236"></a>00236             }
+<a name="l00237"></a>00237         } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!strcmp(ext_name, <span class="stringliteral">"all"</span>)) {
+<a name="l00238"></a>00238             <span class="comment">/* Load the table and append it */</span>
+<a name="l00239"></a>00239             <span class="keywordflow">if</span> (i==0) {
+<a name="l00240"></a>00240                 <span class="comment">/* Load the first table */</span>
+<a name="l00241"></a>00241                 out = cpl_table_load(filename, i+1, 1) ;
+<a name="l00242"></a>00242                 cpl_table_new_column(out, IRPLIB_STDSTAR_CAT_COL, CPL_TYPE_STRING);
+<a name="l00243"></a>00243                 cpl_table_fill_column_window_string(out, IRPLIB_STDSTAR_CAT_COL,
+<a name="l00244"></a>00244                                                     0, cpl_table_get_nrow(out),
+<a name="l00245"></a>00245                                                     cur_name);
+<a name="l00246"></a>00246                 <span class="keywordflow">if</span> (out == NULL) {
+<a name="l00247"></a>00247                     cpl_msg_error(cpl_func, <span class="stringliteral">"Cannot load extension %d"</span>, i+1) ;
+<a name="l00248"></a>00248                     cpl_propertylist_delete(plist) ; 
+<a name="l00249"></a>00249                     <span class="keywordflow">return</span> NULL ;
+<a name="l00250"></a>00250                 }
+<a name="l00251"></a>00251             } <span class="keywordflow">else</span> {
+<a name="l00252"></a>00252                 <span class="comment">/* Load the current table */</span>
+<a name="l00253"></a>00253                 out_cur = cpl_table_load(filename, i+1, 1) ;
+<a name="l00254"></a>00254                 <span class="keywordflow">if</span> (out_cur == NULL) {
+<a name="l00255"></a>00255                     cpl_msg_error(cpl_func, <span class="stringliteral">"Cannot load extension %d"</span>, i+1) ;
+<a name="l00256"></a>00256                     cpl_table_delete(out) ;
+<a name="l00257"></a>00257                     cpl_propertylist_delete(plist) ; 
+<a name="l00258"></a>00258                     <span class="keywordflow">return</span> NULL ;
+<a name="l00259"></a>00259                 }
+<a name="l00260"></a>00260                 cpl_table_new_column(out_cur, IRPLIB_STDSTAR_CAT_COL, CPL_TYPE_STRING);
+<a name="l00261"></a>00261                 cpl_table_fill_column_window_string(out_cur, IRPLIB_STDSTAR_CAT_COL,
+<a name="l00262"></a>00262                                                     0, cpl_table_get_nrow(out_cur),
+<a name="l00263"></a>00263                                                     cur_name);
+<a name="l00264"></a>00264                 <span class="comment">/* Append the table */</span>
+<a name="l00265"></a>00265                 <span class="keywordflow">if</span> (cpl_table_insert(out, out_cur, 
+<a name="l00266"></a>00266                             cpl_table_get_nrow(out)) != CPL_ERROR_NONE) {
+<a name="l00267"></a>00267                     cpl_msg_error(cpl_func, <span class="stringliteral">"Cannot merge table %d"</span>, i+1) ;
+<a name="l00268"></a>00268                     cpl_table_delete(out) ;
+<a name="l00269"></a>00269                     cpl_table_delete(out_cur) ;
+<a name="l00270"></a>00270                     cpl_propertylist_delete(plist) ; 
+<a name="l00271"></a>00271                     <span class="keywordflow">return</span> NULL ;
+<a name="l00272"></a>00272                 }
+<a name="l00273"></a>00273                 cpl_table_delete(out_cur) ;
+<a name="l00274"></a>00274             }
+<a name="l00275"></a>00275         }
+<a name="l00276"></a>00276         cpl_propertylist_delete(plist) ;
+<a name="l00277"></a>00277     }
+<a name="l00278"></a>00278     <span class="keywordflow">return</span> out ;
+<a name="l00279"></a>00279 }
+<a name="l00280"></a>00280 
+<a name="l00281"></a>00281 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00290"></a>00290 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00291"></a><a class="code" href="group__irplib__stdstar.html#ga2dbe2031bf6d669778dca42f6c343efc">00291</a> cpl_error_code <a class="code" href="group__irplib__stdstar.html#ga2dbe2031bf6d669778dca42f6c343efc" title="Check that the table has the relevant columns of a stdstar table.">irplib_stdstar_check_columns_exist</a>(
+<a name="l00292"></a>00292         <span class="keyword">const</span> cpl_table  *   catal)
+<a name="l00293"></a>00293 {
+<a name="l00294"></a>00294     <span class="comment">/* Check for all the mandatory columns */</span>
+<a name="l00295"></a>00295     <span class="keywordflow">if</span> (!cpl_table_has_column(catal, IRPLIB_STDSTAR_STAR_COL)) {
+<a name="l00296"></a>00296         <span class="keywordflow">return</span> cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
+<a name="l00297"></a>00297                 <span class="stringliteral">"Missing column: %s"</span>,
+<a name="l00298"></a>00298                 IRPLIB_STDSTAR_STAR_COL);
+<a name="l00299"></a>00299     }
+<a name="l00300"></a>00300     <span class="keywordflow">if</span> (!cpl_table_has_column(catal, IRPLIB_STDSTAR_TYPE_COL)) {
+<a name="l00301"></a>00301         <span class="keywordflow">return</span> cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
+<a name="l00302"></a>00302                 <span class="stringliteral">"Missing column: %s"</span>,
+<a name="l00303"></a>00303                 IRPLIB_STDSTAR_TYPE_COL);
+<a name="l00304"></a>00304     }
+<a name="l00305"></a>00305     <span class="keywordflow">if</span> (!cpl_table_has_column(catal, IRPLIB_STDSTAR_CAT_COL)) {
+<a name="l00306"></a>00306         <span class="keywordflow">return</span> cpl_error_set_message(cpl_func, 
+<a name="l00307"></a>00307                 CPL_ERROR_ILLEGAL_INPUT,
+<a name="l00308"></a>00308                 <span class="stringliteral">"Missing column: %s"</span>,
+<a name="l00309"></a>00309                 IRPLIB_STDSTAR_CAT_COL);
+<a name="l00310"></a>00310     }
+<a name="l00311"></a>00311     <span class="keywordflow">if</span> (!cpl_table_has_column(catal, IRPLIB_STDSTAR_RA_COL)) {
+<a name="l00312"></a>00312         <span class="keywordflow">return</span> cpl_error_set_message(cpl_func, 
+<a name="l00313"></a>00313                 CPL_ERROR_ILLEGAL_INPUT,
+<a name="l00314"></a>00314                 <span class="stringliteral">"Missing column: %s"</span>,
+<a name="l00315"></a>00315                 IRPLIB_STDSTAR_RA_COL);
+<a name="l00316"></a>00316     }
+<a name="l00317"></a>00317     <span class="keywordflow">if</span> (!cpl_table_has_column(catal, IRPLIB_STDSTAR_DEC_COL)) {
+<a name="l00318"></a>00318         <span class="keywordflow">return</span> cpl_error_set_message(cpl_func, 
+<a name="l00319"></a>00319                 CPL_ERROR_ILLEGAL_INPUT,
+<a name="l00320"></a>00320                 <span class="stringliteral">"Missing column: %s"</span>,
+<a name="l00321"></a>00321                 IRPLIB_STDSTAR_DEC_COL);
+<a name="l00322"></a>00322     }
+<a name="l00323"></a>00323     <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l00324"></a>00324 }
+<a name="l00325"></a>00325 
+<a name="l00326"></a>00326 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00338"></a>00338 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00339"></a><a class="code" href="group__irplib__stdstar.html#ga080e06303f3f83a91959ac01381dc4e8">00339</a> <span class="keywordtype">int</span> <a class="code" href="group__irplib__stdstar.html#ga080e06303f3f83a91959ac01381dc4e8" title="Select the stars that are within a given distance.">irplib_stdstar_select_stars_dist</a>(
+<a name="l00340"></a>00340         cpl_table   *   cat, 
+<a name="l00341"></a>00341         <span class="keywordtype">double</span>          ra, 
+<a name="l00342"></a>00342         <span class="keywordtype">double</span>          dec, 
+<a name="l00343"></a>00343         <span class="keywordtype">double</span>          dist)
+<a name="l00344"></a>00344 {
+<a name="l00345"></a>00345     <span class="keywordtype">double</span>              distance ;
+<a name="l00346"></a>00346     <span class="keywordtype">int</span>                 nrows ;
+<a name="l00347"></a>00347     <span class="keywordtype">int</span>                 i ;
+<a name="l00348"></a>00348     
+<a name="l00349"></a>00349     <span class="comment">/* Check entries */</span>
+<a name="l00350"></a>00350     <span class="keywordflow">if</span> (cat == NULL) <span class="keywordflow">return</span> -1;
+<a name="l00351"></a>00351 
+<a name="l00352"></a>00352     <span class="comment">/* Get the number of selected rows */</span>
+<a name="l00353"></a>00353     nrows = cpl_table_get_nrow(cat) ;
+<a name="l00354"></a>00354     
+<a name="l00355"></a>00355     <span class="comment">/* Check if the columns are there */</span>
+<a name="l00356"></a>00356     <span class="keywordflow">if</span> (!cpl_table_has_column(cat, IRPLIB_STDSTAR_RA_COL)) {
+<a name="l00357"></a>00357         cpl_msg_error(cpl_func, <span class="stringliteral">"Missing %s column"</span>, IRPLIB_STDSTAR_RA_COL) ;
+<a name="l00358"></a>00358         <span class="keywordflow">return</span> -1 ;
+<a name="l00359"></a>00359     }
+<a name="l00360"></a>00360     <span class="keywordflow">if</span> (!cpl_table_has_column(cat, IRPLIB_STDSTAR_DEC_COL)) {
+<a name="l00361"></a>00361         cpl_msg_error(cpl_func, <span class="stringliteral">"Missing %s column"</span>, IRPLIB_STDSTAR_DEC_COL) ;
+<a name="l00362"></a>00362         <span class="keywordflow">return</span> -1 ;
+<a name="l00363"></a>00363     }
+<a name="l00364"></a>00364     
+<a name="l00365"></a>00365     <span class="comment">/* Compute distances of the selected rows */</span>
+<a name="l00366"></a>00366     <span class="keywordflow">for</span> (i=0 ; i<nrows ; i++) {
+<a name="l00367"></a>00367         <span class="keywordflow">if</span> (cpl_table_is_selected(cat, i)) {
+<a name="l00368"></a>00368             <span class="comment">/* The row is selected - compute the distance */</span>
+<a name="l00369"></a>00369             distance = irplib_wcs_great_circle_dist(ra, dec, 
+<a name="l00370"></a>00370                     cpl_table_get_double(cat, IRPLIB_STDSTAR_RA_COL, i, NULL),
+<a name="l00371"></a>00371                     cpl_table_get_double(cat, IRPLIB_STDSTAR_DEC_COL, i, NULL));            
+<a name="l00372"></a>00372             <span class="keywordflow">if</span> (distance > dist) cpl_table_unselect_row(cat, i) ;
+<a name="l00373"></a>00373         }
+<a name="l00374"></a>00374     }
+<a name="l00375"></a>00375     <span class="keywordflow">return</span> 0;
+<a name="l00376"></a>00376 }
+<a name="l00377"></a>00377 
+<a name="l00378"></a>00378 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00387"></a>00387 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00388"></a><a class="code" href="group__irplib__stdstar.html#ga28316d8f0619bdbd0040b1f56799e7ab">00388</a> <span class="keywordtype">int</span> <a class="code" href="group__irplib__stdstar.html#ga28316d8f0619bdbd0040b1f56799e7ab" title="Select the stars that have a known magnitude.">irplib_stdstar_select_stars_mag</a>(
+<a name="l00389"></a>00389         cpl_table   *   cat, 
+<a name="l00390"></a>00390         <span class="keyword">const</span> <span class="keywordtype">char</span>  *   mag_colname)
+<a name="l00391"></a>00391 {
+<a name="l00392"></a>00392     <span class="comment">/* Check entries */</span>
+<a name="l00393"></a>00393     <span class="keywordflow">if</span> (cat == NULL) <span class="keywordflow">return</span> -1 ;
+<a name="l00394"></a>00394     <span class="keywordflow">if</span> (mag_colname == NULL) <span class="keywordflow">return</span> -1 ;
+<a name="l00395"></a>00395 
+<a name="l00396"></a>00396     <span class="comment">/* Check that the table has the mag column */</span>
+<a name="l00397"></a>00397     <span class="keywordflow">if</span> (!cpl_table_has_column(cat, mag_colname)) {
+<a name="l00398"></a>00398         cpl_msg_error(cpl_func, <span class="stringliteral">"Column %s does not exist in the catalog"</span>,
+<a name="l00399"></a>00399                 mag_colname) ;
+<a name="l00400"></a>00400         <span class="keywordflow">return</span> -1 ;
+<a name="l00401"></a>00401     }
+<a name="l00402"></a>00402 
+<a name="l00403"></a>00403     <span class="comment">/* Apply the selection */</span>
+<a name="l00404"></a>00404     <span class="keywordflow">if</span> (cpl_table_and_selected_double(cat, mag_colname, CPL_NOT_GREATER_THAN, 
+<a name="l00405"></a>00405                 98.0) <= 0) {
+<a name="l00406"></a>00406         cpl_msg_error(cpl_func, <span class="stringliteral">"Column %s does not exist in the catalog"</span>,
+<a name="l00407"></a>00407                 mag_colname) ;
+<a name="l00408"></a>00408         <span class="keywordflow">return</span> -1 ;
+<a name="l00409"></a>00409     }
+<a name="l00410"></a>00410     <span class="keywordflow">return</span> 0 ;
+<a name="l00411"></a>00411 }
+<a name="l00412"></a>00412 
+<a name="l00413"></a>00413 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00423"></a>00423 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00424"></a><a class="code" href="group__irplib__stdstar.html#ga36b4c90fd548dd0c00afe97b17a558e5">00424</a> <span class="keywordtype">int</span> <a class="code" href="group__irplib__stdstar.html#ga36b4c90fd548dd0c00afe97b17a558e5" title="Find the closest star.">irplib_stdstar_find_closest</a>(
+<a name="l00425"></a>00425         <span class="keyword">const</span> cpl_table     *   cat, 
+<a name="l00426"></a>00426         <span class="keywordtype">double</span>                  ra, 
+<a name="l00427"></a>00427         <span class="keywordtype">double</span>                  dec)
+<a name="l00428"></a>00428 {
+<a name="l00429"></a>00429     <span class="keywordtype">double</span>              min_dist, distance ;
+<a name="l00430"></a>00430     <span class="keywordtype">int</span>                 nrows ;
+<a name="l00431"></a>00431     <span class="keywordtype">int</span>                 ind ;
+<a name="l00432"></a>00432     <span class="keywordtype">int</span>                 i ;
+<a name="l00433"></a>00433 
+<a name="l00434"></a>00434     <span class="comment">/* Check entries */</span>
+<a name="l00435"></a>00435     <span class="keywordflow">if</span> (cat == NULL) <span class="keywordflow">return</span> -1 ;
+<a name="l00436"></a>00436 
+<a name="l00437"></a>00437     <span class="comment">/* Initialize */</span>
+<a name="l00438"></a>00438     min_dist = 1000.0 ;
+<a name="l00439"></a>00439     ind = -1 ;
+<a name="l00440"></a>00440 
+<a name="l00441"></a>00441     <span class="comment">/* Get the number of selected rows */</span>
+<a name="l00442"></a>00442     nrows = cpl_table_get_nrow(cat) ;
+<a name="l00443"></a>00443 
+<a name="l00444"></a>00444     <span class="comment">/* Check if the columns are there */</span>
+<a name="l00445"></a>00445     <span class="keywordflow">if</span> (!cpl_table_has_column(cat, IRPLIB_STDSTAR_RA_COL)) {
+<a name="l00446"></a>00446         cpl_msg_error(cpl_func, <span class="stringliteral">"Missing %s column"</span>, IRPLIB_STDSTAR_RA_COL) ;
+<a name="l00447"></a>00447         <span class="keywordflow">return</span> -1 ;
+<a name="l00448"></a>00448     }
+<a name="l00449"></a>00449     <span class="keywordflow">if</span> (!cpl_table_has_column(cat, IRPLIB_STDSTAR_DEC_COL)) {
+<a name="l00450"></a>00450         cpl_msg_error(cpl_func, <span class="stringliteral">"Missing %s column"</span>, IRPLIB_STDSTAR_DEC_COL) ;
+<a name="l00451"></a>00451         <span class="keywordflow">return</span> -1 ;
+<a name="l00452"></a>00452     }
+<a name="l00453"></a>00453     
+<a name="l00454"></a>00454     <span class="comment">/* Compute distances of the selected rows */</span>
+<a name="l00455"></a>00455     <span class="keywordflow">for</span> (i=0 ; i<nrows ; i++) {
+<a name="l00456"></a>00456         <span class="keywordflow">if</span> (cpl_table_is_selected(cat, i)) {
+<a name="l00457"></a>00457             <span class="comment">/* The row is selected - compute the distance */</span>
+<a name="l00458"></a>00458             distance = irplib_wcs_great_circle_dist(ra, dec,
+<a name="l00459"></a>00459                     cpl_table_get_double(cat, IRPLIB_STDSTAR_RA_COL, i, NULL),
+<a name="l00460"></a>00460                     cpl_table_get_double(cat, IRPLIB_STDSTAR_DEC_COL, i, NULL));
+<a name="l00461"></a>00461             <span class="keywordflow">if</span> (distance <= min_dist) {
+<a name="l00462"></a>00462                 min_dist = distance ;
+<a name="l00463"></a>00463                 ind = i ;
+<a name="l00464"></a>00464             }
+<a name="l00465"></a>00465         }
+<a name="l00466"></a>00466     }
+<a name="l00467"></a>00467     <span class="keywordflow">return</span> ind ;
+<a name="l00468"></a>00468 }
+<a name="l00469"></a>00469 
+<a name="l00470"></a>00470 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00491"></a>00491 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00492"></a><a class="code" href="group__irplib__stdstar.html#ga4d69ae957de04b1769ac225f12834027">00492</a> cpl_error_code <a class="code" href="group__irplib__stdstar.html#ga4d69ae957de04b1769ac225f12834027" title="Find the closest star to ra, dec in the catalog.">irplib_stdstar_find_star</a>(
+<a name="l00493"></a>00493         <span class="keyword">const</span> <span class="keywordtype">char</span>          *   catfile,
+<a name="l00494"></a>00494         <span class="keywordtype">double</span>                  ra, 
+<a name="l00495"></a>00495         <span class="keywordtype">double</span>                  dec,
+<a name="l00496"></a>00496         <span class="keyword">const</span> <span class="keywordtype">char</span>          *   band,
+<a name="l00497"></a>00497         <span class="keyword">const</span> <span class="keywordtype">char</span>          *   catname,
+<a name="l00498"></a>00498         <span class="keywordtype">double</span>              *   mag,
+<a name="l00499"></a>00499         <span class="keywordtype">char</span>                **  name,
+<a name="l00500"></a>00500         <span class="keywordtype">char</span>                **  type,
+<a name="l00501"></a>00501         <span class="keywordtype">char</span>                **  usedcatname,
+<a name="l00502"></a>00502         <span class="keywordtype">double</span>              *   star_ra,
+<a name="l00503"></a>00503         <span class="keywordtype">double</span>              *   star_dec,
+<a name="l00504"></a>00504         <span class="keywordtype">double</span>                  dist_am)
+<a name="l00505"></a>00505 {
+<a name="l00506"></a>00506     cpl_errorstate prestate = cpl_errorstate_get();
+<a name="l00507"></a>00507     cpl_table   *   catal ;
+<a name="l00508"></a>00508     <span class="keyword">const</span> <span class="keywordtype">double</span>    dist = dist_am / 60.0 ;
+<a name="l00509"></a>00509     <span class="keywordtype">int</span>             ind ;
+<a name="l00510"></a>00510 
+<a name="l00511"></a>00511     <span class="comment">/* Check entries */</span>
+<a name="l00512"></a>00512     <span class="keywordflow">if</span> (catfile == NULL) <span class="keywordflow">return</span> cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT);
+<a name="l00513"></a>00513     <span class="keywordflow">if</span> (band    == NULL) <span class="keywordflow">return</span> cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT);
+<a name="l00514"></a>00514     <span class="keywordflow">if</span> (catname == NULL) <span class="keywordflow">return</span> cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT);
+<a name="l00515"></a>00515     
+<a name="l00516"></a>00516     <span class="comment">/* Load the catalog */</span>
+<a name="l00517"></a>00517     <span class="keywordflow">if</span> ((catal = <a class="code" href="group__irplib__stdstar.html#ga1690bd84c24e905e384b8f725bf7aff1" title="Load the FITS catalog in a table.">irplib_stdstar_load_catalog</a>(catfile, catname)) == NULL) {
+<a name="l00518"></a>00518         <span class="keywordflow">return</span> cpl_error_set_message(cpl_func, CPL_ERROR_FILE_NOT_FOUND,
+<a name="l00519"></a>00519                                            <span class="stringliteral">"Cannot load the catalog %s from %s"</span>,
+<a name="l00520"></a>00520                                            catname, catfile);
+<a name="l00521"></a>00521     }
+<a name="l00522"></a>00522     
+<a name="l00523"></a>00523     <span class="comment">/* Check the columns are present */</span>
+<a name="l00524"></a>00524     <span class="keywordflow">if</span> (<a class="code" href="group__irplib__stdstar.html#ga2dbe2031bf6d669778dca42f6c343efc" title="Check that the table has the relevant columns of a stdstar table.">irplib_stdstar_check_columns_exist</a>(catal) != CPL_ERROR_NONE) {
+<a name="l00525"></a>00525         cpl_table_delete(catal);
+<a name="l00526"></a>00526         <span class="keywordflow">return</span> cpl_error_set_where(cpl_func);
+<a name="l00527"></a>00527     }
+<a name="l00528"></a>00528     
+<a name="l00529"></a>00529     <span class="comment">/* Select stars with known magnitude */</span>
+<a name="l00530"></a>00530     <span class="keywordflow">if</span> (<a class="code" href="group__irplib__stdstar.html#ga28316d8f0619bdbd0040b1f56799e7ab" title="Select the stars that have a known magnitude.">irplib_stdstar_select_stars_mag</a>(catal, band) == -1) {
+<a name="l00531"></a>00531         cpl_table_delete(catal) ;
+<a name="l00532"></a>00532         <span class="keywordflow">return</span> cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
+<a name="l00533"></a>00533                                            <span class="stringliteral">"Cannot select stars in that band"</span>);
+<a name="l00534"></a>00534     }
+<a name="l00535"></a>00535 
+<a name="l00536"></a>00536     <span class="comment">/* Select stars within a given distance */</span>
+<a name="l00537"></a>00537     <span class="keywordflow">if</span> (<a class="code" href="group__irplib__stdstar.html#ga080e06303f3f83a91959ac01381dc4e8" title="Select the stars that are within a given distance.">irplib_stdstar_select_stars_dist</a>(catal, ra, dec, dist) == -1) {
+<a name="l00538"></a>00538         cpl_table_delete(catal) ;
+<a name="l00539"></a>00539         <span class="keywordflow">return</span> cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
+<a name="l00540"></a>00540                                            <span class="stringliteral">"Cannot select close stars"</span>);
+<a name="l00541"></a>00541     }
+<a name="l00542"></a>00542 
+<a name="l00543"></a>00543     <span class="comment">/* Take the closest */</span>
+<a name="l00544"></a>00544     <span class="keywordflow">if</span> ((ind=<a class="code" href="group__irplib__stdstar.html#ga36b4c90fd548dd0c00afe97b17a558e5" title="Find the closest star.">irplib_stdstar_find_closest</a>(catal, ra, dec)) < 0) {
+<a name="l00545"></a>00545         cpl_table_delete(catal) ;
+<a name="l00546"></a>00546         <span class="keywordflow">return</span> cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
+<a name="l00547"></a>00547                                            <span class="stringliteral">"Cannot get the closest star with "</span>
+<a name="l00548"></a>00548                                            <span class="stringliteral">"known %s magnitude"</span>,band);
+<a name="l00549"></a>00549     }
+<a name="l00550"></a>00550 
+<a name="l00551"></a>00551     <span class="keywordflow">if</span>(mag != NULL)
+<a name="l00552"></a>00552         *mag = cpl_table_get_double(catal, band, ind, NULL) ;
+<a name="l00553"></a>00553 
+<a name="l00554"></a>00554     <span class="keywordflow">if</span>(name != NULL)
+<a name="l00555"></a>00555     {
+<a name="l00556"></a>00556         *name = cpl_strdup(cpl_table_get_string(catal,
+<a name="l00557"></a>00557                                                 IRPLIB_STDSTAR_STAR_COL, ind));
+<a name="l00558"></a>00558 
+<a name="l00559"></a>00559     }
+<a name="l00560"></a>00560     <span class="keywordflow">if</span>(type != NULL)
+<a name="l00561"></a>00561     {
+<a name="l00562"></a>00562         *type = cpl_strdup(cpl_table_get_string(catal, IRPLIB_STDSTAR_TYPE_COL,
+<a name="l00563"></a>00563                                                 ind));
+<a name="l00564"></a>00564     }
+<a name="l00565"></a>00565     <span class="keywordflow">if</span>(usedcatname != NULL)
+<a name="l00566"></a>00566     {
+<a name="l00567"></a>00567         <span class="keywordflow">if</span>(strcmp(catname, <span class="stringliteral">"all"</span>))
+<a name="l00568"></a>00568             *usedcatname = cpl_strdup(catname);
+<a name="l00569"></a>00569         <span class="keywordflow">else</span>
+<a name="l00570"></a>00570         {
+<a name="l00571"></a>00571             *usedcatname = cpl_strdup(cpl_table_get_string
+<a name="l00572"></a>00572                                       (catal, IRPLIB_STDSTAR_CAT_COL, ind));
+<a name="l00573"></a>00573         }
+<a name="l00574"></a>00574     }
+<a name="l00575"></a>00575     <span class="keywordflow">if</span>(star_ra != NULL)
+<a name="l00576"></a>00576         *star_ra  = cpl_table_get_double(catal, IRPLIB_STDSTAR_RA_COL, ind, NULL);
+<a name="l00577"></a>00577     <span class="keywordflow">if</span>(star_dec != NULL)
+<a name="l00578"></a>00578         *star_dec = cpl_table_get_double(catal, IRPLIB_STDSTAR_DEC_COL, ind, NULL);
+<a name="l00579"></a>00579     
+<a name="l00580"></a>00580     <span class="comment">/* Free and return */</span>
+<a name="l00581"></a>00581     cpl_table_delete(catal);
+<a name="l00582"></a>00582     <span class="keywordflow">return</span> cpl_errorstate_is_equal(prestate) ? CPL_ERROR_NONE
+<a name="l00583"></a>00583         : cpl_error_set_where(cpl_func);
+<a name="l00584"></a>00584 }
+<a name="l00585"></a>00585 
+<a name="l00586"></a>00586 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00599"></a>00599 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00600"></a><a class="code" href="group__irplib__stdstar.html#ga93b46d8ac857a0d0fdc781b56a91a8ba">00600</a> cpl_vector * <a class="code" href="group__irplib__stdstar.html#ga93b46d8ac857a0d0fdc781b56a91a8ba" title="Get the conversion.">irplib_stdstar_get_conversion</a>(
+<a name="l00601"></a>00601         <span class="keyword">const</span> cpl_bivector  *   spec,
+<a name="l00602"></a>00602         <span class="keywordtype">double</span>                  dit,
+<a name="l00603"></a>00603         <span class="keywordtype">double</span>                  surface,
+<a name="l00604"></a>00604         <span class="keywordtype">double</span>                  gain,
+<a name="l00605"></a>00605         <span class="keywordtype">double</span>                  mag)
+<a name="l00606"></a>00606 {
+<a name="l00607"></a>00607     <span class="keywordtype">double</span>                      h = 6.62e-27 ;
+<a name="l00608"></a>00608     <span class="keywordtype">double</span>                      c = 3e18 ;
+<a name="l00609"></a>00609     <span class="keyword">const</span> cpl_vector    *       wave ;
+<a name="l00610"></a>00610     <span class="keyword">const</span> cpl_vector    *       extr ;
+<a name="l00611"></a>00611     cpl_vector          *       out ;
+<a name="l00612"></a>00612     <span class="keywordtype">double</span>                      factor ;
+<a name="l00613"></a>00613 
+<a name="l00614"></a>00614     <span class="comment">/* Test entries */</span>
+<a name="l00615"></a>00615     <span class="keywordflow">if</span> (spec == NULL) <span class="keywordflow">return</span> NULL ;
+<a name="l00616"></a>00616     <span class="keywordflow">if</span> (dit <= 0.0) <span class="keywordflow">return</span> NULL ;
+<a name="l00617"></a>00617 
+<a name="l00618"></a>00618     <span class="comment">/* Get the extracted spectrum */</span>
+<a name="l00619"></a>00619     wave = cpl_bivector_get_x_const(spec) ;
+<a name="l00620"></a>00620     extr = cpl_bivector_get_y_const(spec) ;
+<a name="l00621"></a>00621 
+<a name="l00622"></a>00622     <span class="comment">/* Get the spectrum */</span>
+<a name="l00623"></a>00623     out = cpl_vector_duplicate(extr) ;
+<a name="l00624"></a>00624 
+<a name="l00625"></a>00625     <span class="comment">/* Divide by DIT */</span>
+<a name="l00626"></a>00626     cpl_vector_divide_scalar(out, dit) ;
+<a name="l00627"></a>00627 
+<a name="l00628"></a>00628     <span class="comment">/* Divide by the surface */</span>
+<a name="l00629"></a>00629     cpl_vector_divide_scalar(out, surface) ;
+<a name="l00630"></a>00630 
+<a name="l00631"></a>00631     <span class="comment">/* Multiply by the gain */</span>
+<a name="l00632"></a>00632     cpl_vector_multiply_scalar(out, gain) ;
+<a name="l00633"></a>00633 
+<a name="l00634"></a>00634     <span class="comment">/* Multiply by the difference magnitude */</span>
+<a name="l00635"></a>00635     factor = pow(10, mag/2.5) ;
+<a name="l00636"></a>00636     cpl_vector_multiply_scalar(out, factor) ;
+<a name="l00637"></a>00637 
+<a name="l00638"></a>00638     <span class="comment">/* Divide by the dispersion */</span>
+<a name="l00639"></a>00639     factor = (cpl_vector_get(wave, cpl_vector_get_size(wave)-1) -
+<a name="l00640"></a>00640             cpl_vector_get(wave, 0)) / cpl_vector_get_size(wave) ;
+<a name="l00641"></a>00641     cpl_vector_divide_scalar(out, factor) ;
+<a name="l00642"></a>00642 
+<a name="l00643"></a>00643     <span class="comment">/* Multiply by the energy of the photon */</span>
+<a name="l00644"></a>00644     cpl_vector_multiply_scalar(out, h*c) ;
+<a name="l00645"></a>00645     cpl_vector_divide(out, wave) ;
+<a name="l00646"></a>00646 
+<a name="l00647"></a>00647     <span class="keywordflow">return</span> out ;
+<a name="l00648"></a>00648 }
+<a name="l00649"></a>00649 
+<a name="l00650"></a>00650 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00658"></a>00658 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00659"></a><a class="code" href="group__irplib__stdstar.html#ga6e68e6a9d0bbb41ef717234b9f289dab">00659</a> cpl_vector * <a class="code" href="group__irplib__stdstar.html#ga6e68e6a9d0bbb41ef717234b9f289dab" title="Get the 0 magnitude spectrum.">irplib_stdstar_get_mag_zero</a>(
+<a name="l00660"></a>00660         <span class="keyword">const</span> cpl_bivector  *   sed,
+<a name="l00661"></a>00661         <span class="keyword">const</span> cpl_vector    *   waves,
+<a name="l00662"></a>00662         <span class="keywordtype">double</span>                  cent_wl)
+<a name="l00663"></a>00663 {
+<a name="l00664"></a>00664     <span class="keywordtype">double</span>              wmin, wmax, wstep ;
+<a name="l00665"></a>00665     <span class="keywordtype">int</span>                 nb_sed ;
+<a name="l00666"></a>00666     <span class="keyword">const</span> <span class="keywordtype">double</span>    *   sed_x ;
+<a name="l00667"></a>00667     <span class="keyword">const</span> <span class="keywordtype">double</span>    *   sed_y ;
+<a name="l00668"></a>00668     cpl_bivector    *   sed_loc ;
+<a name="l00669"></a>00669     <span class="keywordtype">double</span>          *   sed_loc_x ;
+<a name="l00670"></a>00670     <span class="keywordtype">double</span>          *   sed_loc_y ;
+<a name="l00671"></a>00671     cpl_vector      *   out ;
+<a name="l00672"></a>00672     cpl_bivector    *   out_biv ;
+<a name="l00673"></a>00673     <span class="keywordtype">double</span>              f0_jan, f0_erg, cent_val ;
+<a name="l00674"></a>00674     <span class="keywordtype">int</span>                 i ;
+<a name="l00675"></a>00675 
+<a name="l00676"></a>00676     <span class="comment">/* Test entries */</span>
+<a name="l00677"></a>00677     <span class="keywordflow">if</span> (sed == NULL) <span class="keywordflow">return</span> NULL ;
+<a name="l00678"></a>00678     <span class="keywordflow">if</span> (waves == NULL) <span class="keywordflow">return</span> NULL ;
+<a name="l00679"></a>00679 
+<a name="l00680"></a>00680     <span class="comment">/* Initialise */</span>
+<a name="l00681"></a>00681     nb_sed = cpl_bivector_get_size(sed) ;
+<a name="l00682"></a>00682     sed_x = cpl_bivector_get_x_data_const(sed) ;
+<a name="l00683"></a>00683     sed_y = cpl_bivector_get_y_data_const(sed) ;
+<a name="l00684"></a>00684     wstep = sed_x[1] - sed_x[0] ;
+<a name="l00685"></a>00685     wmin = cpl_vector_get(waves, 0) ;
+<a name="l00686"></a>00686     wmax = cpl_vector_get(waves, cpl_vector_get_size(waves)-1) ;
+<a name="l00687"></a>00687 
+<a name="l00688"></a>00688     <span class="comment">/* Expand sed with 0 to have it bigger than the required wavelengths */</span>
+<a name="l00689"></a>00689     sed_loc = cpl_bivector_new(nb_sed + 4) ;
+<a name="l00690"></a>00690     sed_loc_x = cpl_bivector_get_x_data(sed_loc) ;
+<a name="l00691"></a>00691     sed_loc_y = cpl_bivector_get_y_data(sed_loc) ;
+<a name="l00692"></a>00692     <span class="keywordflow">for</span> (i=0 ; i<nb_sed ; i++) {
+<a name="l00693"></a>00693         sed_loc_x[i+2] = sed_x[i] ;
+<a name="l00694"></a>00694         sed_loc_y[i+2] = sed_y[i] ;
+<a name="l00695"></a>00695     }
+<a name="l00696"></a>00696 
+<a name="l00697"></a>00697     <span class="comment">/* Low bound */</span>
+<a name="l00698"></a>00698     sed_loc_x[1] = sed_loc_x[2] - wstep ;
+<a name="l00699"></a>00699     <span class="keywordflow">if</span> (sed_loc_x[2] < wmin) {
+<a name="l00700"></a>00700         sed_loc_x[0] = sed_loc_x[1] - wstep ;
+<a name="l00701"></a>00701     } <span class="keywordflow">else</span> {
+<a name="l00702"></a>00702         sed_loc_x[0] = wmin - wstep ;
+<a name="l00703"></a>00703     }
+<a name="l00704"></a>00704     sed_loc_y[0] = 1e-20 ;
+<a name="l00705"></a>00705     sed_loc_y[1] = 1e-20 ;
+<a name="l00706"></a>00706 
+<a name="l00707"></a>00707     <span class="comment">/* High bound */</span>
+<a name="l00708"></a>00708     sed_loc_x[nb_sed+2] = sed_loc_x[nb_sed+1] + wstep ;
+<a name="l00709"></a>00709     <span class="keywordflow">if</span> (sed_loc_x[nb_sed+1] > wmax) {
+<a name="l00710"></a>00710         sed_loc_x[nb_sed+3] = sed_loc_x[nb_sed+2] + wstep ;
+<a name="l00711"></a>00711     } <span class="keywordflow">else</span> {
+<a name="l00712"></a>00712         sed_loc_x[nb_sed+3] = wmax + wstep ;
+<a name="l00713"></a>00713     }
+<a name="l00714"></a>00714     sed_loc_y[nb_sed+2] = 1e-20 ;
+<a name="l00715"></a>00715     sed_loc_y[nb_sed+3] = 1e-20 ;
+<a name="l00716"></a>00716 
+<a name="l00717"></a>00717     <span class="comment">/* Create the output bivector */</span>
+<a name="l00718"></a>00718     out = cpl_vector_duplicate(waves) ;
+<a name="l00719"></a>00719     out_biv = cpl_bivector_wrap_vectors((cpl_vector*)waves, out) ;
+<a name="l00720"></a>00720 
+<a name="l00721"></a>00721     <span class="comment">/* Interpolate */</span>
+<a name="l00722"></a>00722     <span class="keywordflow">if</span> (cpl_bivector_interpolate_linear(out_biv, sed_loc) != CPL_ERROR_NONE) {
+<a name="l00723"></a>00723         cpl_msg_error(cpl_func, <span class="stringliteral">"Cannot interpolate the wavelength"</span>) ;
+<a name="l00724"></a>00724         cpl_bivector_unwrap_vectors(out_biv) ;
+<a name="l00725"></a>00725         cpl_vector_delete(out) ;
+<a name="l00726"></a>00726         cpl_bivector_delete(sed_loc) ;
+<a name="l00727"></a>00727         <span class="keywordflow">return</span> NULL ;
+<a name="l00728"></a>00728     }
+<a name="l00729"></a>00729     cpl_bivector_unwrap_vectors(out_biv) ;
+<a name="l00730"></a>00730     cpl_bivector_delete(sed_loc) ;
+<a name="l00731"></a>00731 
+<a name="l00732"></a>00732     <span class="comment">/* Compute f0_jan */</span>
+<a name="l00733"></a>00733     f0_jan = 5513.15 / ( pow(cent_wl,3) * (exp(1.2848/cent_wl)-1) ) ;
+<a name="l00734"></a>00734 
+<a name="l00735"></a>00735     <span class="comment">/* Convert f0 Jansky -> ergs/s/cm^2/Angstrom */</span>
+<a name="l00736"></a>00736     f0_erg = f0_jan * 1e-26 * 1e7 * 3e18 / (1e4 * cent_wl*cent_wl*1e4*1e4) ;
+<a name="l00737"></a>00737 
+<a name="l00738"></a>00738     <span class="comment">/* Scale out so that the central value is f0 */</span>
+<a name="l00739"></a>00739     cent_val = cpl_vector_get(out, cpl_vector_get_size(out)/2) ;
+<a name="l00740"></a>00740     <span class="keywordflow">if</span> (cent_val <= 0.0) {
+<a name="l00741"></a>00741         cpl_msg_error(cpl_func, <span class="stringliteral">"Negative or 0 central value"</span>) ;
+<a name="l00742"></a>00742         cpl_vector_delete(out) ;
+<a name="l00743"></a>00743         <span class="keywordflow">return</span> NULL ;
+<a name="l00744"></a>00744     }
+<a name="l00745"></a>00745     cpl_vector_multiply_scalar(out, f0_erg/cent_val) ;
+<a name="l00746"></a>00746 
+<a name="l00747"></a>00747     <span class="comment">/* Return */</span>
+<a name="l00748"></a>00748     <span class="keywordflow">return</span> out ;
+<a name="l00749"></a>00749 }
+<a name="l00750"></a>00750 
+<a name="l00751"></a>00751 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00761"></a>00761 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00762"></a><a class="code" href="group__irplib__stdstar.html#gabbad67ff18cb901914caa9e864969dea">00762</a> cpl_bivector * <a class="code" href="group__irplib__stdstar.html#gabbad67ff18cb901914caa9e864969dea" title="Get the SED.">irplib_stdstar_get_sed</a>(
+<a name="l00763"></a>00763         <span class="keyword">const</span> <span class="keywordtype">char</span>  *   seds_file,
+<a name="l00764"></a>00764         <span class="keyword">const</span> <span class="keywordtype">char</span>  *   sptype)
+<a name="l00765"></a>00765 {
+<a name="l00766"></a>00766     cpl_table           *   seds ;
+<a name="l00767"></a>00767     cpl_bivector        *   out ;
+<a name="l00768"></a>00768     cpl_vector          *   wave ;
+<a name="l00769"></a>00769     cpl_vector          *   sed ;
+<a name="l00770"></a>00770     cpl_bivector        *   tmp ;
+<a name="l00771"></a>00771     <span class="keywordtype">int</span>                     nlines ;
+<a name="l00772"></a>00772 
+<a name="l00773"></a>00773     <span class="comment">/* Test entries */</span>
+<a name="l00774"></a>00774     <span class="keywordflow">if</span> (seds_file == NULL) <span class="keywordflow">return</span> NULL ;
+<a name="l00775"></a>00775     <span class="keywordflow">if</span> (sptype == NULL) <span class="keywordflow">return</span> NULL ;
+<a name="l00776"></a>00776 
+<a name="l00777"></a>00777     <span class="comment">/* Load the table */</span>
+<a name="l00778"></a>00778     <span class="keywordflow">if</span> ((seds = cpl_table_load(seds_file, 1, 0)) == NULL) {
+<a name="l00779"></a>00779         cpl_msg_error(cpl_func, <span class="stringliteral">"Cannot load the table"</span>) ;
+<a name="l00780"></a>00780         <span class="keywordflow">return</span> NULL ;
+<a name="l00781"></a>00781     }
+<a name="l00782"></a>00782 
+<a name="l00783"></a>00783     <span class="comment">/* Check if the column is there */</span>
+<a name="l00784"></a>00784     <span class="keywordflow">if</span> (!cpl_table_has_column(seds, sptype)) {
+<a name="l00785"></a>00785         cpl_msg_error(cpl_func, <span class="stringliteral">"SED of the requested star not available"</span>) ;
+<a name="l00786"></a>00786         cpl_table_delete(seds) ;
+<a name="l00787"></a>00787         <span class="keywordflow">return</span> NULL ;
+<a name="l00788"></a>00788     }
+<a name="l00789"></a>00789 
+<a name="l00790"></a>00790     <span class="comment">/* Get the nb lines */</span>
+<a name="l00791"></a>00791     nlines = cpl_table_get_nrow(seds) ;
+<a name="l00792"></a>00792 
+<a name="l00793"></a>00793     <span class="comment">/* Get the wavelength as a vector */</span>
+<a name="l00794"></a>00794     <span class="keywordflow">if</span> ((wave = cpl_vector_wrap(nlines,
+<a name="l00795"></a>00795             cpl_table_get_data_double(seds, <span class="stringliteral">"Wavelength"</span>))) == NULL) {
+<a name="l00796"></a>00796         cpl_msg_error(cpl_func, <span class="stringliteral">"Cannot get the Wavelength column"</span>) ;
+<a name="l00797"></a>00797         cpl_table_delete(seds) ;
+<a name="l00798"></a>00798         <span class="keywordflow">return</span> NULL ;
+<a name="l00799"></a>00799     }
+<a name="l00800"></a>00800 
+<a name="l00801"></a>00801     <span class="comment">/* Get the SED as a vector */</span>
+<a name="l00802"></a>00802     <span class="keywordflow">if</span> ((sed = cpl_vector_wrap(nlines,
+<a name="l00803"></a>00803             cpl_table_get_data_double(seds, sptype))) == NULL) {
+<a name="l00804"></a>00804         cpl_msg_error(cpl_func, <span class="stringliteral">"Cannot get the SED column"</span>) ;
+<a name="l00805"></a>00805         cpl_table_delete(seds) ;
+<a name="l00806"></a>00806         cpl_vector_unwrap(wave) ;
+<a name="l00807"></a>00807         <span class="keywordflow">return</span> NULL ;
+<a name="l00808"></a>00808     }
+<a name="l00809"></a>00809     tmp = cpl_bivector_wrap_vectors(wave, sed) ;
+<a name="l00810"></a>00810 
+<a name="l00811"></a>00811     <span class="comment">/* Create the output bivector */</span>
+<a name="l00812"></a>00812     out = cpl_bivector_duplicate(tmp) ;
+<a name="l00813"></a>00813 
+<a name="l00814"></a>00814     <span class="comment">/* Free */</span>
+<a name="l00815"></a>00815     cpl_bivector_unwrap_vectors(tmp) ;
+<a name="l00816"></a>00816     cpl_vector_unwrap(wave) ;
+<a name="l00817"></a>00817     cpl_vector_unwrap(sed) ;
+<a name="l00818"></a>00818     cpl_table_delete(seds) ;
+<a name="l00819"></a>00819 
+<a name="l00820"></a>00820     <span class="comment">/* Return  */</span>
+<a name="l00821"></a>00821     <span class="keywordflow">return</span> out ;
+<a name="l00822"></a>00822 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/irplib__stdstar_8h_source.html b/html/irplib__stdstar_8h_source.html
new file mode 100644
index 0000000..7cb390c
--- /dev/null
+++ b/html/irplib__stdstar_8h_source.html
@@ -0,0 +1,94 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: irplib_stdstar.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>irplib_stdstar.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: irplib_stdstar.h,v 1.15 2011/12/14 08:53:04 cgarcia Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the irplib package</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: cgarcia $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2011/12/14 08:53:04 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.15 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifndef IRPLIB_STDSTAR_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#define IRPLIB_STDSTAR_H</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span>
+<a name="l00031"></a>00031 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00032"></a>00032 <span class="comment">                                   Includes</span>
+<a name="l00033"></a>00033 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00034"></a>00034 
+<a name="l00035"></a>00035 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00038"></a>00038 <span class="comment">                                   Defines</span>
+<a name="l00039"></a>00039 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00040"></a>00040 
+<a name="l00041"></a>00041 <span class="preprocessor">#define     IRPLIB_STDSTAR_STAR_COL     "STARS"</span>
+<a name="l00042"></a>00042 <span class="preprocessor"></span><span class="preprocessor">#define     IRPLIB_STDSTAR_TYPE_COL     "SP_TYPE"</span>
+<a name="l00043"></a>00043 <span class="preprocessor"></span><span class="preprocessor">#define     IRPLIB_STDSTAR_RA_COL       "RA"</span>
+<a name="l00044"></a>00044 <span class="preprocessor"></span><span class="preprocessor">#define     IRPLIB_STDSTAR_DEC_COL      "DEC"</span>
+<a name="l00045"></a>00045 <span class="preprocessor"></span><span class="preprocessor">#define     IRPLIB_STDSTAR_CAT_COL      "CATALOG"</span>
+<a name="l00046"></a>00046 <span class="preprocessor"></span>
+<a name="l00047"></a>00047 <span class="comment">/* Maximum allowed distance [arc minutes] between observation and</span>
+<a name="l00048"></a>00048 <span class="comment">   catalogue coordinates  */</span>
+<a name="l00049"></a>00049 <span class="preprocessor">#define     IRPLIB_STDSTAR_MAXDIST       2.0</span>
+<a name="l00050"></a>00050 <span class="preprocessor"></span>
+<a name="l00051"></a>00051 <span class="comment">/* Magical value to indicate an invalid magnitude  */</span>
+<a name="l00052"></a>00052 <span class="preprocessor">#define     IRPLIB_STDSTAR_NOMAG         99.0</span>
+<a name="l00053"></a>00053 <span class="preprocessor"></span>
+<a name="l00054"></a>00054 <span class="comment">/* Use this limit in comparisons regarding an invalid magnitude  */</span>
+<a name="l00055"></a>00055 <span class="preprocessor">#define     IRPLIB_STDSTAR_LIMIT         (IRPLIB_STDSTAR_NOMAG-1.0)</span>
+<a name="l00056"></a>00056 <span class="preprocessor"></span>
+<a name="l00057"></a>00057 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00058"></a>00058 <span class="comment">                                   Function prototypes</span>
+<a name="l00059"></a>00059 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00060"></a>00060 
+<a name="l00061"></a>00061 <span class="keywordtype">int</span> <a class="code" href="group__irplib__stdstar.html#ga1d798cc23ce72891460133af03ee21ba" title="Write the ASCII catalogs as FITS files.">irplib_stdstar_write_catalogs</a>(cpl_frameset *, <span class="keyword">const</span> cpl_frameset *, 
+<a name="l00062"></a>00062         <span class="keyword">const</span> <span class="keywordtype">char</span> *, <span class="keyword">const</span> <span class="keywordtype">char</span> *, <span class="keyword">const</span> <span class="keywordtype">char</span> *, <span class="keyword">const</span> <span class="keywordtype">char</span> *,
+<a name="l00063"></a>00063         <span class="keyword">const</span> <span class="keywordtype">char</span> *, cpl_table * (*convert_ascii_table)(<span class="keyword">const</span> <span class="keywordtype">char</span> *)) ;
+<a name="l00064"></a>00064 cpl_table * <a class="code" href="group__irplib__stdstar.html#ga1690bd84c24e905e384b8f725bf7aff1" title="Load the FITS catalog in a table.">irplib_stdstar_load_catalog</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *, <span class="keyword">const</span> <span class="keywordtype">char</span> *) ;
+<a name="l00065"></a>00065 cpl_error_code <a class="code" href="group__irplib__stdstar.html#ga2dbe2031bf6d669778dca42f6c343efc" title="Check that the table has the relevant columns of a stdstar table.">irplib_stdstar_check_columns_exist</a>(<span class="keyword">const</span> cpl_table  *);
+<a name="l00066"></a>00066 <span class="keywordtype">int</span> <a class="code" href="group__irplib__stdstar.html#ga080e06303f3f83a91959ac01381dc4e8" title="Select the stars that are within a given distance.">irplib_stdstar_select_stars_dist</a>(cpl_table *, <span class="keywordtype">double</span>, <span class="keywordtype">double</span>, <span class="keywordtype">double</span>) ;
+<a name="l00067"></a>00067 <span class="keywordtype">int</span> <a class="code" href="group__irplib__stdstar.html#ga28316d8f0619bdbd0040b1f56799e7ab" title="Select the stars that have a known magnitude.">irplib_stdstar_select_stars_mag</a>(cpl_table *, <span class="keyword">const</span> <span class="keywordtype">char</span> *) ;
+<a name="l00068"></a>00068 <span class="keywordtype">int</span> <a class="code" href="group__irplib__stdstar.html#ga36b4c90fd548dd0c00afe97b17a558e5" title="Find the closest star.">irplib_stdstar_find_closest</a>(<span class="keyword">const</span> cpl_table *, <span class="keywordtype">double</span>, <span class="keywordtype">double</span>) ;
+<a name="l00069"></a>00069 cpl_error_code <a class="code" href="group__irplib__stdstar.html#ga4d69ae957de04b1769ac225f12834027" title="Find the closest star to ra, dec in the catalog.">irplib_stdstar_find_star</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *, <span class="keywordtype">double</span>, <span class="keywordtype">double</span>, <span class="keyword">const</span> <span class="keywordtype">char</span> *, 
+<a name="l00070"></a>00070         <span class="keyword">const</span> <span class="keywordtype">char</span> *, <span class="keywordtype">double</span> *, <span class="keywordtype">char</span> **, <span class="keywordtype">char</span> **, <span class="keywordtype">char</span> **, 
+<a name="l00071"></a>00071         <span class="keywordtype">double</span> *, <span class="keywordtype">double</span>  * , <span class="keywordtype">double</span>);
+<a name="l00072"></a>00072 cpl_vector * <a class="code" href="group__irplib__stdstar.html#ga93b46d8ac857a0d0fdc781b56a91a8ba" title="Get the conversion.">irplib_stdstar_get_conversion</a>(<span class="keyword">const</span> cpl_bivector *, <span class="keywordtype">double</span>, <span class="keywordtype">double</span>,
+<a name="l00073"></a>00073         <span class="keywordtype">double</span>, <span class="keywordtype">double</span>);
+<a name="l00074"></a>00074 cpl_vector * <a class="code" href="group__irplib__stdstar.html#ga6e68e6a9d0bbb41ef717234b9f289dab" title="Get the 0 magnitude spectrum.">irplib_stdstar_get_mag_zero</a>(<span class="keyword">const</span> cpl_bivector *,
+<a name="l00075"></a>00075         <span class="keyword">const</span> cpl_vector *, <span class="keywordtype">double</span>);
+<a name="l00076"></a>00076 cpl_bivector * <a class="code" href="group__irplib__stdstar.html#gabbad67ff18cb901914caa9e864969dea" title="Get the SED.">irplib_stdstar_get_sed</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *, <span class="keyword">const</span> <span class="keywordtype">char</span> *);
+<a name="l00077"></a>00077 
+<a name="l00078"></a>00078 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/irplib__strehl_8c_source.html b/html/irplib__strehl_8c_source.html
new file mode 100644
index 0000000..5e8f0c7
--- /dev/null
+++ b/html/irplib__strehl_8c_source.html
@@ -0,0 +1,677 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: irplib_strehl.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>irplib_strehl.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: irplib_strehl.c,v 1.43 2009/11/18 21:37:48 llundin Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the irplib package</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: llundin $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2009/11/18 21:37:48 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.43 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span>
+<a name="l00032"></a>00032 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                                   Includes</span>
+<a name="l00034"></a>00034 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 
+<a name="l00036"></a>00036 <span class="preprocessor">#include <string.h></span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include <assert.h></span>
+<a name="l00038"></a>00038 <span class="preprocessor">#include <math.h></span>
+<a name="l00039"></a>00039 <span class="preprocessor">#include <float.h></span>
+<a name="l00040"></a>00040 
+<a name="l00041"></a>00041 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00042"></a>00042 
+<a name="l00043"></a>00043 <span class="preprocessor">#include "irplib_utils.h"</span>
+<a name="l00044"></a>00044 <span class="preprocessor">#include "irplib_strehl.h"</span>
+<a name="l00045"></a>00045 
+<a name="l00046"></a>00046 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00050"></a>00050 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00051"></a>00051 
+<a name="l00052"></a>00052 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00053"></a>00053 <span class="comment">                                   Define</span>
+<a name="l00054"></a>00054 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00055"></a>00055 
+<a name="l00056"></a>00056 <span class="preprocessor">#ifndef IRPLIB_STREHL_RAD_CENTRAL</span>
+<a name="l00057"></a>00057 <span class="preprocessor"></span><span class="preprocessor">#define IRPLIB_STREHL_RAD_CENTRAL 5</span>
+<a name="l00058"></a>00058 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
+<a name="l00059"></a>00059 <span class="preprocessor"></span>
+<a name="l00060"></a>00060 <span class="preprocessor">#define IRPLIB_DISK_BG_MIN_PIX_NB    30</span>
+<a name="l00061"></a>00061 <span class="preprocessor"></span><span class="preprocessor">#define IRPLIB_DISK_BG_REJ_LOW       0.1</span>
+<a name="l00062"></a>00062 <span class="preprocessor"></span><span class="preprocessor">#define IRPLIB_DISK_BG_REJ_HIGH      0.1</span>
+<a name="l00063"></a>00063 <span class="preprocessor"></span>
+<a name="l00064"></a>00064 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00065"></a>00065 <span class="comment">                                   Functions prototypes</span>
+<a name="l00066"></a>00066 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00067"></a>00067 
+<a name="l00068"></a>00068 <span class="keyword">static</span> cpl_image * irplib_strehl_generate_otf(<span class="keywordtype">double</span>, <span class="keywordtype">double</span>, <span class="keywordtype">double</span>, <span class="keywordtype">double</span>,
+<a name="l00069"></a>00069                                               <span class="keywordtype">int</span>, <span class="keywordtype">double</span>);
+<a name="l00070"></a>00070 <span class="keyword">static</span> <span class="keywordtype">double</span> PSF_H1(<span class="keywordtype">double</span>, <span class="keywordtype">double</span>, <span class="keywordtype">double</span>);
+<a name="l00071"></a>00071 <span class="keyword">static</span> <span class="keywordtype">double</span> PSF_H2(<span class="keywordtype">double</span>, <span class="keywordtype">double</span>);
+<a name="l00072"></a>00072 <span class="keyword">static</span> <span class="keywordtype">double</span> PSF_G(<span class="keywordtype">double</span>, <span class="keywordtype">double</span>);
+<a name="l00073"></a>00073 <span class="keyword">static</span> <span class="keywordtype">double</span> PSF_sinc(<span class="keywordtype">double</span>);
+<a name="l00074"></a>00074 <span class="keyword">static</span> <span class="keywordtype">double</span> PSF_TelOTF(<span class="keywordtype">double</span>, <span class="keywordtype">double</span>);
+<a name="l00075"></a>00075 <span class="keyword">static</span> cpl_error_code update_bad_pixel_map(cpl_image* im);
+<a name="l00076"></a>00076 
+<a name="l00077"></a>00077 
+<a name="l00078"></a>00078 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00079"></a>00079 <span class="comment">                                   Functions code</span>
+<a name="l00080"></a>00080 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00088"></a>00088 cpl_error_code update_bad_pixel_map(cpl_image* im)
+<a name="l00089"></a>00089 {
+<a name="l00090"></a>00090     <span class="keywordtype">int</span> szx = cpl_image_get_size_x(im);
+<a name="l00091"></a>00091     <span class="keywordtype">int</span> szy = cpl_image_get_size_y(im);
+<a name="l00092"></a>00092     <span class="keywordtype">int</span> x = 0;
+<a name="l00093"></a>00093     cpl_mask* bpm = cpl_image_get_bpm(im);
+<a name="l00094"></a>00094 
+<a name="l00095"></a>00095     <span class="keywordflow">for</span> (x = 1; x <=szx; x++)
+<a name="l00096"></a>00096     {
+<a name="l00097"></a>00097         <span class="keywordtype">int</span> y = 0;
+<a name="l00098"></a>00098         <span class="keywordflow">for</span>(y = 1; y <= szy; y++)
+<a name="l00099"></a>00099         {
+<a name="l00100"></a>00100             <span class="keywordtype">int</span> isnull = 0;
+<a name="l00101"></a>00101             <span class="keywordtype">double</span> value = cpl_image_get(im, x, y, &isnull);
+<a name="l00102"></a>00102             <span class="keywordflow">if</span> (isnan(value))
+<a name="l00103"></a>00103             {
+<a name="l00104"></a>00104                 cpl_mask_set(bpm, x, y, CPL_BINARY_1);
+<a name="l00105"></a>00105             }
+<a name="l00106"></a>00106         }
+<a name="l00107"></a>00107     }
+<a name="l00108"></a>00108     <span class="keywordflow">return</span> cpl_error_get_code();
+<a name="l00109"></a>00109 }
+<a name="l00140"></a>00140 cpl_error_code irplib_strehl_mark_bad_and_compute(cpl_image *   im,
+<a name="l00141"></a>00141                                      <span class="keywordtype">double</span>              m1,
+<a name="l00142"></a>00142                                      <span class="keywordtype">double</span>              m2,
+<a name="l00143"></a>00143                                      <span class="keywordtype">double</span>              lam,
+<a name="l00144"></a>00144                                      <span class="keywordtype">double</span>              dlam,
+<a name="l00145"></a>00145                                      <span class="keywordtype">double</span>              pscale,
+<a name="l00146"></a>00146                                      <span class="keywordtype">int</span>                 size,
+<a name="l00147"></a>00147                                      <span class="keywordtype">double</span>              xpos,
+<a name="l00148"></a>00148                                      <span class="keywordtype">double</span>              ypos,
+<a name="l00149"></a>00149                                      <span class="keywordtype">double</span>              r1,
+<a name="l00150"></a>00150                                      <span class="keywordtype">double</span>              r2,
+<a name="l00151"></a>00151                                      <span class="keywordtype">double</span>              r3,
+<a name="l00152"></a>00152                                      <span class="keywordtype">int</span>                 noise_box_sz,
+<a name="l00153"></a>00153                                      <span class="keywordtype">int</span>                 noise_nsamples,
+<a name="l00154"></a>00154                                      <span class="keywordtype">double</span>          *   strehl,
+<a name="l00155"></a>00155                                      <span class="keywordtype">double</span>          *   strehl_err,
+<a name="l00156"></a>00156                                      <span class="keywordtype">double</span>          *   star_bg,
+<a name="l00157"></a>00157                                      <span class="keywordtype">double</span>          *   star_peak,
+<a name="l00158"></a>00158                                      <span class="keywordtype">double</span>          *   star_flux,
+<a name="l00159"></a>00159                                      <span class="keywordtype">double</span>          *   psf_peak,
+<a name="l00160"></a>00160                                      <span class="keywordtype">double</span>          *   psf_flux,
+<a name="l00161"></a>00161                                      <span class="keywordtype">double</span>          *   bg_noise)
+<a name="l00162"></a>00162 {
+<a name="l00163"></a>00163     cpl_ensure_code(!update_bad_pixel_map(im), cpl_error_get_code());
+<a name="l00164"></a>00164     <span class="keywordflow">return</span> irplib_strehl_compute(im, m1, m2, lam, dlam, pscale, size, xpos, ypos,
+<a name="l00165"></a>00165             r1,
+<a name="l00166"></a>00166             r2,
+<a name="l00167"></a>00167             r3,
+<a name="l00168"></a>00168             noise_box_sz,
+<a name="l00169"></a>00169             noise_nsamples,
+<a name="l00170"></a>00170             strehl,
+<a name="l00171"></a>00171             strehl_err,
+<a name="l00172"></a>00172             star_bg,
+<a name="l00173"></a>00173             star_peak,
+<a name="l00174"></a>00174             star_flux,
+<a name="l00175"></a>00175             psf_peak,
+<a name="l00176"></a>00176             psf_flux,
+<a name="l00177"></a>00177             bg_noise);
+<a name="l00178"></a>00178 }
+<a name="l00179"></a>00179 
+<a name="l00180"></a>00180 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00211"></a>00211 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00212"></a>00212 cpl_error_code irplib_strehl_compute(<span class="keyword">const</span> cpl_image *   im,
+<a name="l00213"></a>00213                                      <span class="keywordtype">double</span>              m1,
+<a name="l00214"></a>00214                                      <span class="keywordtype">double</span>              m2,
+<a name="l00215"></a>00215                                      <span class="keywordtype">double</span>              lam,
+<a name="l00216"></a>00216                                      <span class="keywordtype">double</span>              dlam,
+<a name="l00217"></a>00217                                      <span class="keywordtype">double</span>              pscale,
+<a name="l00218"></a>00218                                      <span class="keywordtype">int</span>                 size,
+<a name="l00219"></a>00219                                      <span class="keywordtype">double</span>              xpos,
+<a name="l00220"></a>00220                                      <span class="keywordtype">double</span>              ypos,
+<a name="l00221"></a>00221                                      <span class="keywordtype">double</span>              r1,
+<a name="l00222"></a>00222                                      <span class="keywordtype">double</span>              r2,
+<a name="l00223"></a>00223                                      <span class="keywordtype">double</span>              r3,
+<a name="l00224"></a>00224                                      <span class="keywordtype">int</span>                 noise_box_sz,
+<a name="l00225"></a>00225                                      <span class="keywordtype">int</span>                 noise_nsamples,
+<a name="l00226"></a>00226                                      <span class="keywordtype">double</span>          *   strehl,
+<a name="l00227"></a>00227                                      <span class="keywordtype">double</span>          *   strehl_err,
+<a name="l00228"></a>00228                                      <span class="keywordtype">double</span>          *   star_bg,
+<a name="l00229"></a>00229                                      <span class="keywordtype">double</span>          *   star_peak,
+<a name="l00230"></a>00230                                      <span class="keywordtype">double</span>          *   star_flux,
+<a name="l00231"></a>00231                                      <span class="keywordtype">double</span>          *   psf_peak,
+<a name="l00232"></a>00232                                      <span class="keywordtype">double</span>          *   psf_flux,
+<a name="l00233"></a>00233                                      <span class="keywordtype">double</span>          *   bg_noise)
+<a name="l00234"></a>00234 {
+<a name="l00235"></a>00235     cpl_image  * psf;
+<a name="l00236"></a>00236     <span class="keywordtype">double</span>       star_radius, max_radius;
+<a name="l00237"></a>00237 
+<a name="l00238"></a>00238     <span class="comment">/* FIXME: Arbitrary choice of image border */</span>
+<a name="l00239"></a>00239     <span class="keyword">const</span> <span class="keywordtype">double</span> window_size = (double)(IRPLIB_STREHL_RAD_CENTRAL);
+<a name="l00240"></a>00240 
+<a name="l00241"></a>00241     <span class="comment">/* Determined empirically by C. Lidman for Strehl error computation */</span>
+<a name="l00242"></a>00242     <span class="keyword">const</span> <span class="keywordtype">double</span> strehl_error_coefficient = CPL_MATH_PI * 0.007 / 0.0271;
+<a name="l00243"></a>00243     <span class="keywordtype">double</span>       ring[4];
+<a name="l00244"></a>00244     <span class="comment">/* cpl_flux_get_noise_ring() must succeed with this many tries */</span>
+<a name="l00245"></a>00245     <span class="keywordtype">int</span>          ring_tries = 3;
+<a name="l00246"></a>00246     cpl_errorstate prestate;
+<a name="l00247"></a>00247 
+<a name="l00248"></a>00248     <span class="comment">/* Check compile-time constant */</span>
+<a name="l00249"></a>00249     cpl_ensure_code(window_size > 0.0,  CPL_ERROR_ILLEGAL_INPUT);
+<a name="l00250"></a>00250 
+<a name="l00251"></a>00251     <span class="comment">/* Test inputs */</span>
+<a name="l00252"></a>00252     cpl_ensure_code(im != NULL,         CPL_ERROR_NULL_INPUT);
+<a name="l00253"></a>00253     cpl_ensure_code(strehl != NULL,     CPL_ERROR_NULL_INPUT);
+<a name="l00254"></a>00254     cpl_ensure_code(strehl_err != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00255"></a>00255     cpl_ensure_code(star_bg != NULL,    CPL_ERROR_NULL_INPUT);
+<a name="l00256"></a>00256     cpl_ensure_code(star_peak != NULL,  CPL_ERROR_NULL_INPUT);
+<a name="l00257"></a>00257     cpl_ensure_code(star_flux != NULL,  CPL_ERROR_NULL_INPUT);
+<a name="l00258"></a>00258     cpl_ensure_code(psf_peak != NULL,   CPL_ERROR_NULL_INPUT);
+<a name="l00259"></a>00259     cpl_ensure_code(psf_flux != NULL,   CPL_ERROR_NULL_INPUT);
+<a name="l00260"></a>00260 
+<a name="l00261"></a>00261     cpl_ensure_code(pscale > 0.0,      CPL_ERROR_ILLEGAL_INPUT);
+<a name="l00262"></a>00262 
+<a name="l00263"></a>00263     cpl_ensure_code(r1 > 0.0,      CPL_ERROR_ILLEGAL_INPUT);
+<a name="l00264"></a>00264     cpl_ensure_code(r2 > 0.0,      CPL_ERROR_ILLEGAL_INPUT);
+<a name="l00265"></a>00265     cpl_ensure_code(r3 > r2,       CPL_ERROR_ILLEGAL_INPUT);
+<a name="l00266"></a>00266 
+<a name="l00267"></a>00267     <span class="comment">/* Computing a Strehl ratio is a story between an ideal PSF */</span>
+<a name="l00268"></a>00268     <span class="comment">/* and a candidate image supposed to approximate this ideal PSF. */</span>
+<a name="l00269"></a>00269 
+<a name="l00270"></a>00270     <span class="comment">/* Generate first appropriate PSF to find max peak */</span>
+<a name="l00271"></a>00271     psf = irplib_strehl_generate_psf(m1, m2, lam, dlam, pscale, size);
+<a name="l00272"></a>00272     cpl_ensure_code(psf != NULL,      CPL_ERROR_ILLEGAL_OUTPUT);
+<a name="l00273"></a>00273 
+<a name="l00274"></a>00274     <span class="comment">/* Compute flux in PSF and find max peak */</span>
+<a name="l00275"></a>00275     *psf_peak = cpl_image_get_max(psf);
+<a name="l00276"></a>00276     cpl_image_delete(psf);
+<a name="l00277"></a>00277 
+<a name="l00278"></a>00278     assert( *psf_peak > 0.0); <span class="comment">/* The ideal PSF has a positive maximum */</span>
+<a name="l00279"></a>00279     *psf_flux = 1.0; <span class="comment">/* The psf flux, cpl_image_get_flux(psf), is always 1 */</span>
+<a name="l00280"></a>00280 
+<a name="l00281"></a>00281     <span class="comment">/* Measure the background in the candidate image */</span>
+<a name="l00282"></a>00282     *star_bg = irplib_strehl_ring_background(im, xpos, ypos, r2/pscale, r3/pscale,
+<a name="l00283"></a>00283                                              IRPLIB_BG_METHOD_AVER_REJ);
+<a name="l00284"></a>00284 
+<a name="l00285"></a>00285     <span class="comment">/* Compute star_radius in pixels */</span>
+<a name="l00286"></a>00286     star_radius = r1/pscale;
+<a name="l00287"></a>00287 
+<a name="l00288"></a>00288     <span class="comment">/* Measure the flux on the candidate image */</span>
+<a name="l00289"></a>00289     *star_flux = irplib_strehl_disk_flux(im, xpos, ypos, star_radius, *star_bg);
+<a name="l00290"></a>00290 
+<a name="l00291"></a>00291     cpl_ensure_code(*star_flux > 0.0,      CPL_ERROR_ILLEGAL_OUTPUT);
+<a name="l00292"></a>00292 
+<a name="l00293"></a>00293     <span class="comment">/* Find the peak value on the central part of the candidate image */</span>
+<a name="l00294"></a>00294     max_radius = window_size < star_radius ? window_size : star_radius;
+<a name="l00295"></a>00295     cpl_ensure_code(!irplib_strehl_disk_max(im, xpos, ypos, max_radius,
+<a name="l00296"></a>00296                                             star_peak), cpl_error_get_code());
+<a name="l00297"></a>00297     *star_peak -= *star_bg;
+<a name="l00298"></a>00298 
+<a name="l00299"></a>00299     cpl_ensure_code(*star_peak > 0.0,      CPL_ERROR_ILLEGAL_OUTPUT);
+<a name="l00300"></a>00300 
+<a name="l00301"></a>00301     <span class="comment">/* Compute Strehl */</span>
+<a name="l00302"></a>00302     <span class="comment">/* (StarPeak / StarFlux) / (PsfPeak / PsfFlux) */</span>
+<a name="l00303"></a>00303     *strehl = (*star_peak * *psf_flux ) / ( *star_flux * *psf_peak);
+<a name="l00304"></a>00304 
+<a name="l00305"></a>00305     <span class="keywordflow">if</span> (*strehl > 1)
+<a name="l00306"></a>00306         cpl_msg_warning(cpl_func, <span class="stringliteral">"Extreme Strehl-ratio=%g, star_peak=%g, "</span>
+<a name="l00307"></a>00307                         <span class="stringliteral">"star_flux=%g, psf_peak=%g, psf_flux=%g"</span>, *strehl,
+<a name="l00308"></a>00308                         *star_peak, *star_flux, *psf_peak, *psf_flux);
+<a name="l00309"></a>00309 
+<a name="l00310"></a>00310     <span class="comment">/* Compute Strehl error */</span>
+<a name="l00311"></a>00311     <span class="comment">/* computation could fail if the image contains pixels with NaN value*/</span>
+<a name="l00312"></a>00312     ring[0] = xpos;
+<a name="l00313"></a>00313     ring[1] = ypos;
+<a name="l00314"></a>00314     ring[2] = r2/pscale;
+<a name="l00315"></a>00315     ring[3] = r3/pscale;
+<a name="l00316"></a>00316 
+<a name="l00317"></a>00317     <span class="comment">/* FIXME: With CPL 5.1 the recoverable error</span>
+<a name="l00318"></a>00318 <span class="comment">       will be CPL_ERROR_DATA_NOT_FOUND */</span>
+<a name="l00319"></a>00319     prestate = cpl_errorstate_get();
+<a name="l00320"></a>00320     <span class="keywordflow">while</span> (cpl_flux_get_noise_ring(im, ring, noise_box_sz, noise_nsamples,
+<a name="l00321"></a>00321                                    bg_noise, NULL) && --ring_tries > 0);
+<a name="l00322"></a>00322     <span class="keywordflow">if</span> (ring_tries > 0) {
+<a name="l00323"></a>00323         cpl_errorstate_set(prestate); <span class="comment">/* Recover, if an error happened */</span>
+<a name="l00324"></a>00324     } <span class="keywordflow">else</span> {
+<a name="l00325"></a>00325         <span class="keywordflow">return</span> cpl_error_set_where(cpl_func);
+<a name="l00326"></a>00326     }
+<a name="l00327"></a>00327 
+<a name="l00328"></a>00328     *strehl_err = strehl_error_coefficient * (*bg_noise) * pscale *
+<a name="l00329"></a>00329         star_radius * star_radius / *star_flux;
+<a name="l00330"></a>00330 
+<a name="l00331"></a>00331     <span class="comment">/* This check should not be able to fail, but just to be sure */</span>
+<a name="l00332"></a>00332     cpl_ensure_code(*strehl_err >= 0.0,       CPL_ERROR_ILLEGAL_OUTPUT);
+<a name="l00333"></a>00333 
+<a name="l00334"></a>00334     <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l00335"></a>00335 }
+<a name="l00336"></a>00336 
+<a name="l00337"></a>00337 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00353"></a>00353 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00354"></a>00354 <span class="keywordtype">double</span> irplib_strehl_disk_flux(<span class="keyword">const</span> cpl_image * im,
+<a name="l00355"></a>00355                                <span class="keywordtype">double</span>            xpos,
+<a name="l00356"></a>00356                                <span class="keywordtype">double</span>            ypos,
+<a name="l00357"></a>00357                                <span class="keywordtype">double</span>            rad,
+<a name="l00358"></a>00358                                <span class="keywordtype">double</span>            bg)
+<a name="l00359"></a>00359 {
+<a name="l00360"></a>00360     <span class="keyword">const</span> <span class="keywordtype">double</span>    sqr = rad * rad;
+<a name="l00361"></a>00361     <span class="keywordtype">double</span>          sqrest;
+<a name="l00362"></a>00362     <span class="keyword">const</span> <span class="keywordtype">float</span> *   pim;
+<a name="l00363"></a>00363     <span class="keywordtype">double</span>          flux = 0.0;
+<a name="l00364"></a>00364     <span class="keywordtype">double</span>          yj, xi;
+<a name="l00365"></a>00365     <span class="keywordtype">int</span>             nx, ny;
+<a name="l00366"></a>00366     <span class="keywordtype">int</span>             lx, ly, ux, uy;
+<a name="l00367"></a>00367     <span class="keywordtype">int</span>             i, j;
+<a name="l00368"></a>00368 
+<a name="l00369"></a>00369 
+<a name="l00370"></a>00370     <span class="comment">/* Check entries */</span>
+<a name="l00371"></a>00371     cpl_ensure(im != NULL, CPL_ERROR_NULL_INPUT, 0.0);
+<a name="l00372"></a>00372     cpl_ensure(cpl_image_get_type(im) == CPL_TYPE_FLOAT,
+<a name="l00373"></a>00373                CPL_ERROR_UNSUPPORTED_MODE, 0.0);
+<a name="l00374"></a>00374     cpl_ensure(rad > 0.0, CPL_ERROR_ILLEGAL_INPUT, 0.0);
+<a name="l00375"></a>00375 
+<a name="l00376"></a>00376     nx = cpl_image_get_size_x(im);
+<a name="l00377"></a>00377     ny = cpl_image_get_size_y(im);
+<a name="l00378"></a>00378 
+<a name="l00379"></a>00379     <span class="comment">/* Round down */</span>
+<a name="l00380"></a>00380     lx = (int)(xpos - rad);
+<a name="l00381"></a>00381     ly = (int)(ypos - rad);
+<a name="l00382"></a>00382     <span class="keywordflow">if</span> (lx < 0) lx = 0;
+<a name="l00383"></a>00383     <span class="keywordflow">if</span> (ly < 0) ly = 0;
+<a name="l00384"></a>00384 
+<a name="l00385"></a>00385     <span class="comment">/* Round up */</span>
+<a name="l00386"></a>00386     ux = (int)(xpos + rad) + 1;
+<a name="l00387"></a>00387     uy = (int)(ypos + rad) + 1;
+<a name="l00388"></a>00388     <span class="keywordflow">if</span> (ux > (nx-1)) ux = nx-1;
+<a name="l00389"></a>00389     <span class="keywordflow">if</span> (uy > (ny-1)) uy = ny-1;
+<a name="l00390"></a>00390 
+<a name="l00391"></a>00391     pim = cpl_image_get_data_float_const(im);
+<a name="l00392"></a>00392     <span class="keywordflow">for</span> (j=ly ; j<uy ; j++) {
+<a name="l00393"></a>00393         yj = (double)j - ypos;
+<a name="l00394"></a>00394         sqrest = sqr - yj * yj;
+<a name="l00395"></a>00395         <span class="keywordflow">for</span> (i=lx; i<ux ; i++) {
+<a name="l00396"></a>00396             xi = (double)i - xpos;
+<a name="l00397"></a>00397             <span class="keywordflow">if</span> (sqrest >= xi * xi && <a class="code" href="group__irplib__utils.html#ga804bfc739b5d55f9797ab881b1034ae4" title="portable isnan">irplib_isnan</a>(pim[i+j*nx]) == 0) {
+<a name="l00398"></a>00398                 flux += (double)pim[i+j*nx] - bg;
+<a name="l00399"></a>00399             }
+<a name="l00400"></a>00400         }
+<a name="l00401"></a>00401     }
+<a name="l00402"></a>00402     <span class="keywordflow">return</span> flux;
+<a name="l00403"></a>00403 }
+<a name="l00404"></a>00404 
+<a name="l00405"></a>00405 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00419"></a>00419 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00420"></a>00420 <span class="keywordtype">double</span> irplib_strehl_ring_background(<span class="keyword">const</span> cpl_image *       im,
+<a name="l00421"></a>00421                                      <span class="keywordtype">double</span>                  xpos,
+<a name="l00422"></a>00422                                      <span class="keywordtype">double</span>                  ypos,
+<a name="l00423"></a>00423                                      <span class="keywordtype">double</span>                  rad_int,
+<a name="l00424"></a>00424                                      <span class="keywordtype">double</span>                  rad_ext,
+<a name="l00425"></a>00425                                      irplib_strehl_bg_method mode)
+<a name="l00426"></a>00426 {
+<a name="l00427"></a>00427     <span class="keywordtype">int</span>             npix;
+<a name="l00428"></a>00428     <span class="keyword">const</span> <span class="keywordtype">double</span>    sqr_int = rad_int * rad_int;
+<a name="l00429"></a>00429     <span class="keyword">const</span> <span class="keywordtype">double</span>    sqr_ext = rad_ext * rad_ext;
+<a name="l00430"></a>00430     <span class="keywordtype">double</span>          dist;
+<a name="l00431"></a>00431     cpl_vector  *   pix_arr;
+<a name="l00432"></a>00432     <span class="keyword">const</span> <span class="keywordtype">float</span> *   pim;
+<a name="l00433"></a>00433     <span class="keywordtype">double</span>          flux = 0.0;
+<a name="l00434"></a>00434     <span class="keywordtype">double</span>          yj, xi;
+<a name="l00435"></a>00435     <span class="keywordtype">int</span>             lx, ly, ux, uy;
+<a name="l00436"></a>00436     <span class="keywordtype">int</span>             nx, ny;
+<a name="l00437"></a>00437     <span class="keywordtype">int</span>             i, j;
+<a name="l00438"></a>00438 
+<a name="l00439"></a>00439     <span class="comment">/* Check entries */</span>
+<a name="l00440"></a>00440     cpl_ensure(im != NULL, CPL_ERROR_NULL_INPUT, 0.0);
+<a name="l00441"></a>00441     cpl_ensure(cpl_image_get_type(im) == CPL_TYPE_FLOAT,
+<a name="l00442"></a>00442                CPL_ERROR_UNSUPPORTED_MODE, 0.0);
+<a name="l00443"></a>00443     cpl_ensure(rad_int > 0.0, CPL_ERROR_ILLEGAL_INPUT, 0.0);
+<a name="l00444"></a>00444     cpl_ensure(rad_ext > rad_int, CPL_ERROR_ILLEGAL_INPUT, 0.0);
+<a name="l00445"></a>00445 
+<a name="l00446"></a>00446     cpl_ensure(mode == IRPLIB_BG_METHOD_AVER_REJ ||
+<a name="l00447"></a>00447                mode == IRPLIB_BG_METHOD_MEDIAN,
+<a name="l00448"></a>00448                CPL_ERROR_UNSUPPORTED_MODE, 0.0);
+<a name="l00449"></a>00449 
+<a name="l00450"></a>00450     nx = cpl_image_get_size_x(im);
+<a name="l00451"></a>00451     ny = cpl_image_get_size_y(im);
+<a name="l00452"></a>00452 
+<a name="l00453"></a>00453     <span class="comment">/* Round down */</span>
+<a name="l00454"></a>00454     lx = (int)(xpos - rad_ext);
+<a name="l00455"></a>00455     ly = (int)(ypos - rad_ext);
+<a name="l00456"></a>00456     <span class="keywordflow">if</span> (lx < 0) lx = 0;
+<a name="l00457"></a>00457     <span class="keywordflow">if</span> (ly < 0) ly = 0;
+<a name="l00458"></a>00458 
+<a name="l00459"></a>00459     <span class="comment">/* Round up */</span>
+<a name="l00460"></a>00460     ux = (int)(xpos + rad_ext) + 1;
+<a name="l00461"></a>00461     uy = (int)(ypos + rad_ext) + 1;
+<a name="l00462"></a>00462     <span class="keywordflow">if</span> (ux > (nx-1)) ux = nx-1;
+<a name="l00463"></a>00463     <span class="keywordflow">if</span> (uy > (ny-1)) uy = ny-1;
+<a name="l00464"></a>00464 
+<a name="l00465"></a>00465     npix = (ux - lx + 1) * (uy - ly + 1);
+<a name="l00466"></a>00466     cpl_ensure(npix >= IRPLIB_DISK_BG_MIN_PIX_NB, CPL_ERROR_DATA_NOT_FOUND, 0.0);
+<a name="l00467"></a>00467 
+<a name="l00468"></a>00468     <span class="comment">/* Allocate pixel array to hold values in the ring */</span>
+<a name="l00469"></a>00469     pix_arr = cpl_vector_new(npix);
+<a name="l00470"></a>00470 
+<a name="l00471"></a>00471     <span class="comment">/* Count number of pixels in the ring */</span>
+<a name="l00472"></a>00472     <span class="comment">/* Retrieve all pixels which belong to the ring */</span>
+<a name="l00473"></a>00473     pim = cpl_image_get_data_float_const(im);
+<a name="l00474"></a>00474     npix = 0;
+<a name="l00475"></a>00475     <span class="keywordflow">for</span> (j=ly ; j<uy ; j++) {
+<a name="l00476"></a>00476         yj = (double)j - ypos;
+<a name="l00477"></a>00477         <span class="keywordflow">for</span> (i=lx ; i<ux; i++) {
+<a name="l00478"></a>00478             xi = (double)i - xpos;
+<a name="l00479"></a>00479             dist = yj * yj + xi * xi;
+<a name="l00480"></a>00480             <span class="keywordflow">if</span> (sqr_int <= dist && dist <= sqr_ext &&
+<a name="l00481"></a>00481                 <a class="code" href="group__irplib__utils.html#ga804bfc739b5d55f9797ab881b1034ae4" title="portable isnan">irplib_isnan</a>(pim[i+j*nx]) == 0) {
+<a name="l00482"></a>00482                 cpl_vector_set(pix_arr, npix, (<span class="keywordtype">double</span>)pim[i+j*nx]);
+<a name="l00483"></a>00483                 npix++;
+<a name="l00484"></a>00484             }
+<a name="l00485"></a>00485         }
+<a name="l00486"></a>00486     }
+<a name="l00487"></a>00487 
+<a name="l00488"></a>00488     <span class="keywordflow">if</span> (npix < IRPLIB_DISK_BG_MIN_PIX_NB) {
+<a name="l00489"></a>00489         cpl_vector_delete(pix_arr);
+<a name="l00490"></a>00490         cpl_ensure(0, CPL_ERROR_DATA_NOT_FOUND, 0.0);
+<a name="l00491"></a>00491     }
+<a name="l00492"></a>00492 
+<a name="l00493"></a>00493     <span class="comment">/* Should not be able to fail now */</span>
+<a name="l00494"></a>00494 
+<a name="l00495"></a>00495     <span class="comment">/* Resize pixel array to actual number of values within the ring */</span>
+<a name="l00496"></a>00496     cpl_vector_set_size(pix_arr, npix);
+<a name="l00497"></a>00497 
+<a name="l00498"></a>00498     <span class="keywordflow">if</span> (mode == IRPLIB_BG_METHOD_AVER_REJ) {
+<a name="l00499"></a>00499         <span class="keyword">const</span> <span class="keywordtype">int</span> low_ind  = (int)((<span class="keywordtype">double</span>)npix * IRPLIB_DISK_BG_REJ_LOW);
+<a name="l00500"></a>00500         <span class="keyword">const</span> <span class="keywordtype">int</span> high_ind = (int)((<span class="keywordtype">double</span>)npix
+<a name="l00501"></a>00501                                    * (1.0 - IRPLIB_DISK_BG_REJ_HIGH));
+<a name="l00502"></a>00502 
+<a name="l00503"></a>00503         <span class="comment">/* Sort the array */</span>
+<a name="l00504"></a>00504         cpl_vector_sort(pix_arr, 1);
+<a name="l00505"></a>00505 
+<a name="l00506"></a>00506         <span class="keywordflow">for</span> (i=low_ind ; i<high_ind ; i++) {
+<a name="l00507"></a>00507             flux += cpl_vector_get(pix_arr, i);
+<a name="l00508"></a>00508         }
+<a name="l00509"></a>00509         <span class="keywordflow">if</span> (high_ind - low_ind > 1) flux /= (double)(high_ind - low_ind);
+<a name="l00510"></a>00510     } <span class="keywordflow">else</span> <span class="comment">/* if (mode == IRPLIB_BG_METHOD_MEDIAN) */</span> {
+<a name="l00511"></a>00511         flux = cpl_vector_get_median(pix_arr);
+<a name="l00512"></a>00512     }
+<a name="l00513"></a>00513 
+<a name="l00514"></a>00514     cpl_vector_delete(pix_arr);
+<a name="l00515"></a>00515 
+<a name="l00516"></a>00516     <span class="keywordflow">return</span> flux;
+<a name="l00517"></a>00517 }
+<a name="l00518"></a>00518 
+<a name="l00519"></a>00519 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00539"></a>00539 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00540"></a>00540 cpl_image * irplib_strehl_generate_psf(
+<a name="l00541"></a>00541         <span class="keywordtype">double</span>   m1,
+<a name="l00542"></a>00542         <span class="keywordtype">double</span>   m2,
+<a name="l00543"></a>00543         <span class="keywordtype">double</span>   lam,
+<a name="l00544"></a>00544         <span class="keywordtype">double</span>   dlam,
+<a name="l00545"></a>00545         <span class="keywordtype">double</span>   pscale,
+<a name="l00546"></a>00546         <span class="keywordtype">int</span>      size)
+<a name="l00547"></a>00547 {
+<a name="l00548"></a>00548     cpl_image * otf_image = irplib_strehl_generate_otf(m1, m2, lam, dlam,
+<a name="l00549"></a>00549             size, pscale);
+<a name="l00550"></a>00550 
+<a name="l00551"></a>00551     <span class="keywordflow">if</span> (otf_image == NULL) <span class="keywordflow">return</span> NULL;
+<a name="l00552"></a>00552 
+<a name="l00553"></a>00553     <span class="comment">/* Transform back to real space</span>
+<a name="l00554"></a>00554 <span class="comment">       - Normalization is unnecessary, due to the subsequent normalisation.</span>
+<a name="l00555"></a>00555 <span class="comment">       - An OTF is point symmetric about its center, i.e. it is even,</span>
+<a name="l00556"></a>00556 <span class="comment">         i.e. the real space image is real.</span>
+<a name="l00557"></a>00557 <span class="comment">       - Because of this a forward FFT works as well.</span>
+<a name="l00558"></a>00558 <span class="comment">       - If the PSF ever needs to have its images halves swapped add</span>
+<a name="l00559"></a>00559 <span class="comment">         CPL_FFT_SWAP_HALVES to the FFT call.</span>
+<a name="l00560"></a>00560 <span class="comment">     */</span>
+<a name="l00561"></a>00561 
+<a name="l00562"></a>00562     <span class="keywordflow">if</span> (cpl_image_fft(otf_image, NULL, CPL_FFT_UNNORMALIZED) ||
+<a name="l00563"></a>00563 
+<a name="l00564"></a>00564         <span class="comment">/* Compute absolute values of PSF */</span>
+<a name="l00565"></a>00565         cpl_image_abs(otf_image) ||
+<a name="l00566"></a>00566 
+<a name="l00567"></a>00567         <span class="comment">/* Normalize PSF to get flux=1  */</span>
+<a name="l00568"></a>00568         cpl_image_normalise(otf_image, CPL_NORM_FLUX)) {
+<a name="l00569"></a>00569 
+<a name="l00570"></a>00570         cpl_image_delete(otf_image);
+<a name="l00571"></a>00571         <span class="keywordflow">return</span> NULL;
+<a name="l00572"></a>00572     }
+<a name="l00573"></a>00573 
+<a name="l00574"></a>00574     <span class="keywordflow">return</span> otf_image;
+<a name="l00575"></a>00575 }
+<a name="l00576"></a>00576 
+<a name="l00579"></a>00579 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00595"></a>00595 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00596"></a>00596 <span class="keyword">static</span> cpl_image * irplib_strehl_generate_otf(
+<a name="l00597"></a>00597         <span class="keywordtype">double</span>  m1,
+<a name="l00598"></a>00598         <span class="keywordtype">double</span>  m2,
+<a name="l00599"></a>00599         <span class="keywordtype">double</span>  lam,
+<a name="l00600"></a>00600         <span class="keywordtype">double</span>  dlam,
+<a name="l00601"></a>00601         <span class="keywordtype">int</span>     size,
+<a name="l00602"></a>00602         <span class="keywordtype">double</span>  pscale)
+<a name="l00603"></a>00603 {
+<a name="l00604"></a>00604     cpl_image   *   otf_image;
+<a name="l00605"></a>00605     <span class="keywordtype">double</span>      *   otf_data;
+<a name="l00606"></a>00606     <span class="keywordtype">double</span>          obs_ratio ;  <span class="comment">/* m1 / m2    */</span>
+<a name="l00607"></a>00607     <span class="keywordtype">double</span>          f_max ;      <span class="comment">/* cut-off frequency        */</span>
+<a name="l00608"></a>00608     <span class="keywordtype">int</span>             pix0 ;      <span class="comment">/* Pixel corresponding to the zero frequency */</span>
+<a name="l00609"></a>00609     <span class="keywordtype">double</span>          a, x, y;
+<a name="l00610"></a>00610     <span class="keywordtype">double</span>          f, rsq, fc, invfc, lambda;
+<a name="l00611"></a>00611     <span class="keywordtype">double</span>          sincy;
+<a name="l00612"></a>00612     <span class="keywordtype">double</span>          invsize;
+<a name="l00613"></a>00613     <span class="keyword">register</span> <span class="keywordtype">int</span>    pos;
+<a name="l00614"></a>00614     <span class="keywordtype">int</span>             i, j, k;
+<a name="l00615"></a>00615 
+<a name="l00616"></a>00616 
+<a name="l00617"></a>00617     cpl_ensure(m2   > 0.0,      CPL_ERROR_ILLEGAL_INPUT, NULL);
+<a name="l00618"></a>00618     cpl_ensure(m1   > m2,       CPL_ERROR_ILLEGAL_INPUT, NULL);
+<a name="l00619"></a>00619     cpl_ensure(lam  > 0.0,      CPL_ERROR_ILLEGAL_INPUT, NULL);
+<a name="l00620"></a>00620     cpl_ensure(dlam > 0.0,      CPL_ERROR_ILLEGAL_INPUT, NULL);
+<a name="l00621"></a>00621     cpl_ensure(size > 0,        CPL_ERROR_ILLEGAL_INPUT, NULL);
+<a name="l00622"></a>00622     cpl_ensure(pscale > 0.0,    CPL_ERROR_ILLEGAL_INPUT, NULL);
+<a name="l00623"></a>00623 
+<a name="l00624"></a>00624     <span class="comment">/* Convert pixel scale from sec to radians, microns in meters    */</span>
+<a name="l00625"></a>00625     pscale /= (double)206265;
+<a name="l00626"></a>00626     lam /= (double)1.0e6;
+<a name="l00627"></a>00627     dlam /= (double)1.0e6;
+<a name="l00628"></a>00628 
+<a name="l00629"></a>00629     <span class="comment">/* Obscuration ratio    */</span>
+<a name="l00630"></a>00630     obs_ratio = m2 / m1;
+<a name="l00631"></a>00631 
+<a name="l00632"></a>00632     <span class="comment">/* Pixel corresponding to the zero frequency    */</span>
+<a name="l00633"></a>00633     pix0 = size/2;
+<a name="l00634"></a>00634     invsize = (double)1.0 / (<span class="keywordtype">double</span>)size;
+<a name="l00635"></a>00635 
+<a name="l00636"></a>00636     <span class="comment">/* Cut-off frequency in pixels  */</span>
+<a name="l00637"></a>00637     f_max = m1 * pscale * (double)size / lam;
+<a name="l00638"></a>00638 
+<a name="l00639"></a>00639     <span class="comment">/* Allocate for output image    */</span>
+<a name="l00640"></a>00640     otf_image = cpl_image_new(size, size, CPL_TYPE_DOUBLE);
+<a name="l00641"></a>00641     <span class="keywordflow">if</span> (otf_image==NULL) <span class="keywordflow">return</span> NULL;
+<a name="l00642"></a>00642     otf_data = cpl_image_get_data_double(otf_image);
+<a name="l00643"></a>00643 
+<a name="l00644"></a>00644     <span class="comment">/* Now compute the OTF  */</span>
+<a name="l00645"></a>00645     <span class="comment">/* OPTIMIZED CODE !!! LIMITED READABILITY !!!   */</span>
+<a name="l00646"></a>00646 
+<a name="l00647"></a>00647     <span class="keywordflow">for</span> (k=1 ; k<=9 ; k++) {    <span class="comment">/* iteration on the wavelength  */</span>
+<a name="l00648"></a>00648         <span class="comment">/* Compute intermediate cut-off frequency   */</span>
+<a name="l00649"></a>00649         lambda = (double)(lam - dlam*(<span class="keywordtype">double</span>)(k-5)/8.0);
+<a name="l00650"></a>00650         fc = (double)f_max * (<span class="keywordtype">double</span>)lam / lambda;
+<a name="l00651"></a>00651         invfc = 1.0 / fc;
+<a name="l00652"></a>00652 
+<a name="l00653"></a>00653         <span class="comment">/* Convolution with the detector pixels */</span>
+<a name="l00654"></a>00654         pos = 0;
+<a name="l00655"></a>00655         <span class="keywordflow">for</span> (j=0 ; j<size ; j++) {
+<a name="l00656"></a>00656             y = (double)(j-pix0);
+<a name="l00657"></a>00657             sincy = PSF_sinc(CPL_MATH_PI * y * invsize);
+<a name="l00658"></a>00658             <span class="keywordflow">for</span> (i=0 ; i<size ; i++) {
+<a name="l00659"></a>00659                 x = (double)(i-pix0);
+<a name="l00660"></a>00660                 rsq = x*x + y*y;
+<a name="l00661"></a>00661                 <span class="keywordflow">if</span> (rsq < fc*fc) {
+<a name="l00662"></a>00662                     <span class="keywordflow">if</span> (rsq < 0.01)
+<a name="l00663"></a>00663                         a = 1.0;
+<a name="l00664"></a>00664                     <span class="keywordflow">else</span> {
+<a name="l00665"></a>00665                         f = sqrt(rsq) * invfc;
+<a name="l00666"></a>00666                         a = PSF_TelOTF(f,obs_ratio) *
+<a name="l00667"></a>00667                             PSF_sinc(CPL_MATH_PI * x * invsize) * sincy;
+<a name="l00668"></a>00668                     }
+<a name="l00669"></a>00669                 } <span class="keywordflow">else</span> {
+<a name="l00670"></a>00670                     a = 0.0;
+<a name="l00671"></a>00671                 }
+<a name="l00672"></a>00672                 otf_data[pos++] += a / 9.0;
+<a name="l00673"></a>00673             }
+<a name="l00674"></a>00674         }
+<a name="l00675"></a>00675     }
+<a name="l00676"></a>00676     <span class="keywordflow">return</span> otf_image;
+<a name="l00677"></a>00677 }
+<a name="l00678"></a>00678 
+<a name="l00679"></a>00679 <span class="comment">/*----------------------------------------------------------------------------*</span>
+<a name="l00680"></a>00680 <span class="comment"> * H1 function</span>
+<a name="l00681"></a>00681 <span class="comment"> *----------------------------------------------------------------------------*/</span>
+<a name="l00682"></a>00682 <span class="keyword">static</span> <span class="keywordtype">double</span> PSF_H1(
+<a name="l00683"></a>00683         <span class="keywordtype">double</span>  f,
+<a name="l00684"></a>00684         <span class="keywordtype">double</span>  u,
+<a name="l00685"></a>00685         <span class="keywordtype">double</span>  v)
+<a name="l00686"></a>00686 {
+<a name="l00687"></a>00687     <span class="keyword">const</span> <span class="keywordtype">double</span> e = fabs(1.0-v) > 0.0 ? -1.0 : 1.0; <span class="comment">/* e = 1.0 iff v = 1.0 */</span>
+<a name="l00688"></a>00688 
+<a name="l00689"></a>00689     <span class="keywordflow">return</span>((v*v/CPL_MATH_PI)*acos((f/v)*(1.0+e*(1.0-u*u)/(4.0*f*f))));
+<a name="l00690"></a>00690 }
+<a name="l00691"></a>00691 
+<a name="l00692"></a>00692 <span class="comment">/*----------------------------------------------------------------------------*</span>
+<a name="l00693"></a>00693 <span class="comment"> * H2 function</span>
+<a name="l00694"></a>00694 <span class="comment"> *----------------------------------------------------------------------------*/</span>
+<a name="l00695"></a>00695 <span class="keyword">static</span> <span class="keywordtype">double</span> PSF_H2(<span class="keywordtype">double</span>  f,
+<a name="l00696"></a>00696                      <span class="keywordtype">double</span>  u)
+<a name="l00697"></a>00697 {
+<a name="l00698"></a>00698     <span class="keyword">const</span> <span class="keywordtype">double</span> tmp1 = (2.0 * f) / (1.0 + u);
+<a name="l00699"></a>00699     <span class="keyword">const</span> <span class="keywordtype">double</span> tmp2 = (1.0 - u) / (2.0 * f);
+<a name="l00700"></a>00700 
+<a name="l00701"></a>00701     <span class="keywordflow">return</span> -1.0 * (f/CPL_MATH_PI) * (1.0+u)
+<a name="l00702"></a>00702         * sqrt((1.0-tmp1*tmp1)*(1.0-tmp2*tmp2));
+<a name="l00703"></a>00703 }
+<a name="l00704"></a>00704 
+<a name="l00705"></a>00705 <span class="comment">/*----------------------------------------------------------------------------*</span>
+<a name="l00706"></a>00706 <span class="comment"> * G function</span>
+<a name="l00707"></a>00707 <span class="comment"> *----------------------------------------------------------------------------*/</span>
+<a name="l00708"></a>00708 <span class="keyword">static</span> <span class="keywordtype">double</span> PSF_G(<span class="keywordtype">double</span>  f,
+<a name="l00709"></a>00709                     <span class="keywordtype">double</span>  u)
+<a name="l00710"></a>00710 {
+<a name="l00711"></a>00711     <span class="keywordflow">if</span> (f <= (1.0-u)/2.0) <span class="keywordflow">return</span>(u*u);
+<a name="l00712"></a>00712     <span class="keywordflow">if</span> (f >= (1.0+u)/2.0) <span class="keywordflow">return</span>(0.0);
+<a name="l00713"></a>00713     <span class="keywordflow">else</span> <span class="keywordflow">return</span>(PSF_H1(f,u,1.0) + PSF_H1(f,u,u) + PSF_H2(f,u));
+<a name="l00714"></a>00714 }
+<a name="l00715"></a>00715 
+<a name="l00716"></a>00716 <span class="comment">/*----------------------------------------------------------------------------*</span>
+<a name="l00717"></a>00717 <span class="comment"> * sinc function</span>
+<a name="l00718"></a>00718 <span class="comment"> *----------------------------------------------------------------------------*/</span>
+<a name="l00719"></a>00719 <span class="keyword">static</span> <span class="keywordtype">double</span> PSF_sinc(<span class="keywordtype">double</span> x)
+<a name="l00720"></a>00720 {
+<a name="l00721"></a>00721   <span class="keywordflow">return</span> fabs(x) > fabs(sin(x)) ? sin(x)/x : 1.0;
+<a name="l00722"></a>00722 }
+<a name="l00723"></a>00723 
+<a name="l00724"></a>00724 <span class="comment">/*----------------------------------------------------------------------------*</span>
+<a name="l00725"></a>00725 <span class="comment"> * Telescope OTF function</span>
+<a name="l00726"></a>00726 <span class="comment"> *----------------------------------------------------------------------------*/</span>
+<a name="l00727"></a>00727 <span class="keyword">static</span> <span class="keywordtype">double</span> PSF_TelOTF(<span class="keywordtype">double</span>  f,
+<a name="l00728"></a>00728                          <span class="keywordtype">double</span>  u)
+<a name="l00729"></a>00729 {
+<a name="l00730"></a>00730     <span class="keywordflow">return</span>((PSF_G(f,1.0)+u*u*PSF_G(f/u,1.0)-2.0*PSF_G(f,u))/(1.0-u*u));
+<a name="l00731"></a>00731 }
+<a name="l00732"></a>00732 
+<a name="l00733"></a>00733 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00745"></a>00745 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00746"></a>00746 cpl_error_code irplib_strehl_disk_max(<span class="keyword">const</span> cpl_image * <span class="keyword">self</span>,
+<a name="l00747"></a>00747                                              <span class="keywordtype">double</span>            xpos,
+<a name="l00748"></a>00748                                              <span class="keywordtype">double</span>            ypos,
+<a name="l00749"></a>00749                                              <span class="keywordtype">double</span>            radius,
+<a name="l00750"></a>00750                                              <span class="keywordtype">double</span>          * ppeak)
+<a name="l00751"></a>00751 {
+<a name="l00752"></a>00752 
+<a name="l00753"></a>00753     <span class="keyword">const</span> <span class="keywordtype">double</span>    sqr = radius * radius;
+<a name="l00754"></a>00754     <span class="keywordtype">double</span>          sqrest;
+<a name="l00755"></a>00755     <span class="keyword">const</span> <span class="keywordtype">float</span> *   pself;
+<a name="l00756"></a>00756     <span class="keywordtype">float</span>           peak = FLT_MAX;  <span class="comment">/* Avoid (false) uninit warning */</span>
+<a name="l00757"></a>00757     <span class="keywordtype">double</span>          yj, xi;
+<a name="l00758"></a>00758     <span class="keywordtype">int</span>             nx, ny;
+<a name="l00759"></a>00759     <span class="keywordtype">int</span>             lx, ly, ux, uy;
+<a name="l00760"></a>00760     <span class="keywordtype">int</span>             i, j;
+<a name="l00761"></a>00761     cpl_boolean     first = CPL_TRUE;
+<a name="l00762"></a>00762 
+<a name="l00763"></a>00763 
+<a name="l00764"></a>00764     <span class="comment">/* Check entries */</span>
+<a name="l00765"></a>00765     cpl_ensure_code(ppeak != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00766"></a>00766     cpl_ensure_code(<span class="keyword">self</span>  != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00767"></a>00767     cpl_ensure_code(cpl_image_get_type(<span class="keyword">self</span>) == CPL_TYPE_FLOAT,
+<a name="l00768"></a>00768                     CPL_ERROR_UNSUPPORTED_MODE);
+<a name="l00769"></a>00769     cpl_ensure_code(radius > 0.0, CPL_ERROR_ILLEGAL_INPUT);
+<a name="l00770"></a>00770 
+<a name="l00771"></a>00771     nx = cpl_image_get_size_x(<span class="keyword">self</span>);
+<a name="l00772"></a>00772     ny = cpl_image_get_size_y(<span class="keyword">self</span>);
+<a name="l00773"></a>00773 
+<a name="l00774"></a>00774     <span class="comment">/* Round down */</span>
+<a name="l00775"></a>00775     lx = (int)(xpos - radius);
+<a name="l00776"></a>00776     ly = (int)(ypos - radius);
+<a name="l00777"></a>00777     <span class="keywordflow">if</span> (lx < 0) lx = 0;
+<a name="l00778"></a>00778     <span class="keywordflow">if</span> (ly < 0) ly = 0;
+<a name="l00779"></a>00779 
+<a name="l00780"></a>00780     <span class="comment">/* Round up */</span>
+<a name="l00781"></a>00781     ux = (int)(xpos + radius) + 1;
+<a name="l00782"></a>00782     uy = (int)(ypos + radius) + 1;
+<a name="l00783"></a>00783     <span class="keywordflow">if</span> (ux > (nx-1)) ux = nx-1;
+<a name="l00784"></a>00784     <span class="keywordflow">if</span> (uy > (ny-1)) uy = ny-1;
+<a name="l00785"></a>00785 
+<a name="l00786"></a>00786     pself = cpl_image_get_data_float_const(<span class="keyword">self</span>);
+<a name="l00787"></a>00787     <span class="keywordflow">for</span> (j=ly ; j<uy ; j++) {
+<a name="l00788"></a>00788         yj = (double)j - ypos;
+<a name="l00789"></a>00789         sqrest = sqr - yj * yj;
+<a name="l00790"></a>00790         <span class="keywordflow">for</span> (i=lx; i<ux ; i++) {
+<a name="l00791"></a>00791             xi = (double)i - xpos;
+<a name="l00792"></a>00792             <span class="keywordflow">if</span> (sqrest >= xi * xi && <a class="code" href="group__irplib__utils.html#ga804bfc739b5d55f9797ab881b1034ae4" title="portable isnan">irplib_isnan</a>(pself[i+j*nx]) == 0) {
+<a name="l00793"></a>00793                 <span class="keywordflow">if</span> (first || pself[i+j*nx] > peak) {
+<a name="l00794"></a>00794                     first = CPL_FALSE;
+<a name="l00795"></a>00795                     peak = pself[i+j*nx];
+<a name="l00796"></a>00796                 }
+<a name="l00797"></a>00797             }
+<a name="l00798"></a>00798         }
+<a name="l00799"></a>00799     }
+<a name="l00800"></a>00800 
+<a name="l00801"></a>00801     cpl_ensure_code(!first, CPL_ERROR_DATA_NOT_FOUND);
+<a name="l00802"></a>00802 
+<a name="l00803"></a>00803     *ppeak = (double)peak;
+<a name="l00804"></a>00804 
+<a name="l00805"></a>00805     <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l00806"></a>00806 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/irplib__strehl_8h_source.html b/html/irplib__strehl_8h_source.html
new file mode 100644
index 0000000..0c93fac
--- /dev/null
+++ b/html/irplib__strehl_8h_source.html
@@ -0,0 +1,91 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: irplib_strehl.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>irplib_strehl.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: irplib_strehl.h,v 1.12 2009/06/29 14:32:53 kmirny Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the irplib package</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: kmirny $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2009/06/29 14:32:53 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.12 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifndef IRPLIB_STREHL_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#define IRPLIB_STREHL_H</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span>
+<a name="l00031"></a>00031 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00032"></a>00032 <span class="comment">                                   Includes</span>
+<a name="l00033"></a>00033 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00034"></a>00034 
+<a name="l00035"></a>00035 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00038"></a>00038 <span class="comment">                                   Define</span>
+<a name="l00039"></a>00039 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00040"></a>00040 
+<a name="l00041"></a>00041 <span class="preprocessor">#ifndef IRPLIB_STREHL_BORDER</span>
+<a name="l00042"></a>00042 <span class="preprocessor"></span><span class="preprocessor">#define IRPLIB_STREHL_BORDER        5</span>
+<a name="l00043"></a>00043 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
+<a name="l00044"></a>00044 <span class="preprocessor"></span>
+<a name="l00045"></a>00045 <span class="keyword">typedef</span> <span class="keyword">enum</span> {
+<a name="l00046"></a>00046     IRPLIB_BG_METHOD_AVER_REJ,
+<a name="l00047"></a>00047     IRPLIB_BG_METHOD_MEDIAN
+<a name="l00048"></a>00048 } irplib_strehl_bg_method;
+<a name="l00049"></a>00049 
+<a name="l00050"></a>00050 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00051"></a>00051 <span class="comment">                               Functions prototypes</span>
+<a name="l00052"></a>00052 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00053"></a>00053 
+<a name="l00054"></a>00054 cpl_error_code irplib_strehl_compute(<span class="keyword">const</span> cpl_image *, <span class="keywordtype">double</span>, <span class="keywordtype">double</span>, <span class="keywordtype">double</span>,
+<a name="l00055"></a>00055                                      <span class="keywordtype">double</span>, <span class="keywordtype">double</span>, <span class="keywordtype">int</span>, <span class="keywordtype">double</span>, <span class="keywordtype">double</span>,
+<a name="l00056"></a>00056                                      <span class="keywordtype">double</span>, <span class="keywordtype">double</span>, <span class="keywordtype">double</span>, <span class="keywordtype">int</span>, <span class="keywordtype">int</span>,
+<a name="l00057"></a>00057                                      <span class="keywordtype">double</span> *, <span class="keywordtype">double</span> *, <span class="keywordtype">double</span> *, <span class="keywordtype">double</span> *,
+<a name="l00058"></a>00058                                      <span class="keywordtype">double</span> *, <span class="keywordtype">double</span> *, <span class="keywordtype">double</span> *, <span class="keywordtype">double</span> *);
+<a name="l00059"></a>00059 cpl_error_code irplib_strehl_mark_bad_and_compute(
+<a name="l00060"></a>00060                     cpl_image *, <span class="keywordtype">double</span>, <span class="keywordtype">double</span>, <span class="keywordtype">double</span>,
+<a name="l00061"></a>00061                     <span class="keywordtype">double</span>, <span class="keywordtype">double</span>, <span class="keywordtype">int</span>, <span class="keywordtype">double</span>, <span class="keywordtype">double</span>,
+<a name="l00062"></a>00062                     <span class="keywordtype">double</span>, <span class="keywordtype">double</span>, <span class="keywordtype">double</span>, <span class="keywordtype">int</span>, <span class="keywordtype">int</span>,
+<a name="l00063"></a>00063                     <span class="keywordtype">double</span> *, <span class="keywordtype">double</span> *, <span class="keywordtype">double</span> *, <span class="keywordtype">double</span> *,
+<a name="l00064"></a>00064                     <span class="keywordtype">double</span> *, <span class="keywordtype">double</span> *, <span class="keywordtype">double</span> *, <span class="keywordtype">double</span> *);
+<a name="l00065"></a>00065 <span class="keywordtype">double</span> irplib_strehl_disk_flux(<span class="keyword">const</span> cpl_image *, <span class="keywordtype">double</span>, <span class="keywordtype">double</span>, <span class="keywordtype">double</span>,
+<a name="l00066"></a>00066                                <span class="keywordtype">double</span>);
+<a name="l00067"></a>00067 
+<a name="l00068"></a>00068 <span class="keywordtype">double</span> irplib_strehl_ring_background(<span class="keyword">const</span> cpl_image *, <span class="keywordtype">double</span>, <span class="keywordtype">double</span>, <span class="keywordtype">double</span>,
+<a name="l00069"></a>00069                                      <span class="keywordtype">double</span>, irplib_strehl_bg_method);
+<a name="l00070"></a>00070 
+<a name="l00071"></a>00071 cpl_image * irplib_strehl_generate_psf(<span class="keywordtype">double</span>, <span class="keywordtype">double</span>, <span class="keywordtype">double</span>, <span class="keywordtype">double</span>, <span class="keywordtype">double</span>,
+<a name="l00072"></a>00072                                        <span class="keywordtype">int</span>);
+<a name="l00073"></a>00073 cpl_error_code irplib_strehl_disk_max(<span class="keyword">const</span> cpl_image *, <span class="keywordtype">double</span>, <span class="keywordtype">double</span>,
+<a name="l00074"></a>00074                                              <span class="keywordtype">double</span>, <span class="keywordtype">double</span> *);
+<a name="l00075"></a>00075 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/irplib__utils_8c_source.html b/html/irplib__utils_8c_source.html
new file mode 100644
index 0000000..360b01d
--- /dev/null
+++ b/html/irplib__utils_8c_source.html
@@ -0,0 +1,1262 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: irplib_utils.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>irplib_utils.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: irplib_utils.c,v 1.78 2012/05/08 13:56:09 llundin Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the irplib package</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: llundin $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2012/05/08 13:56:09 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.78 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span>
+<a name="l00032"></a>00032 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                                   Includes</span>
+<a name="l00034"></a>00034 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 
+<a name="l00036"></a>00036 <span class="preprocessor">#include <math.h></span>
+<a name="l00037"></a>00037 
+<a name="l00038"></a>00038 <span class="preprocessor">#include <string.h></span>
+<a name="l00039"></a>00039 <span class="preprocessor">#include <assert.h></span>
+<a name="l00040"></a>00040 
+<a name="l00041"></a>00041 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00042"></a>00042 
+<a name="l00043"></a>00043 <span class="preprocessor">#include "irplib_utils.h"</span>
+<a name="l00044"></a>00044 
+<a name="l00045"></a>00045 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00046"></a>00046 <span class="comment">                           Defines</span>
+<a name="l00047"></a>00047 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00048"></a>00048 
+<a name="l00049"></a>00049 <span class="comment">/* TEMPORARY SUPPORT OF CPL 5.x */</span>
+<a name="l00050"></a>00050 <span class="preprocessor">#ifndef CPL_SIZE_FORMAT</span>
+<a name="l00051"></a>00051 <span class="preprocessor"></span><span class="preprocessor">#define CPL_SIZE_FORMAT "d"</span>
+<a name="l00052"></a>00052 <span class="preprocessor"></span><span class="preprocessor">#define cpl_size int</span>
+<a name="l00053"></a>00053 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
+<a name="l00054"></a>00054 <span class="preprocessor"></span><span class="comment">/* END TEMPORARY SUPPORT OF CPL 5.x */</span>
+<a name="l00055"></a>00055 
+<a name="l00056"></a>00056 <span class="preprocessor">#ifndef inline</span>
+<a name="l00057"></a>00057 <span class="preprocessor"></span><span class="preprocessor">#define inline </span><span class="comment">/* inline */</span>
+<a name="l00058"></a>00058 <span class="preprocessor">#endif</span>
+<a name="l00059"></a>00059 <span class="preprocessor"></span>
+<a name="l00060"></a>00060 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00061"></a>00061 <span class="comment">                           Missing Function Prototypes</span>
+<a name="l00062"></a>00062 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00063"></a>00063 
+<a name="l00064"></a>00064 <span class="preprocessor">#if defined HAVE_ISNAN && HAVE_ISNAN != 0</span>
+<a name="l00065"></a>00065 <span class="preprocessor"></span><span class="preprocessor">#if !defined isnan && defined HAVE_DECL_ISNAN && HAVE_DECL_ISNAN == 0</span>
+<a name="l00066"></a>00066 <span class="preprocessor"></span><span class="comment">/* HP-UX and Solaris may have isnan() available at link-time</span>
+<a name="l00067"></a>00067 <span class="comment">   without the prototype */</span>
+<a name="l00068"></a>00068 <span class="keywordtype">int</span> isnan(<span class="keywordtype">double</span>);
+<a name="l00069"></a>00069 <span class="preprocessor">#endif</span>
+<a name="l00070"></a>00070 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
+<a name="l00071"></a>00071 <span class="preprocessor"></span>
+<a name="l00072"></a>00072 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00073"></a>00073 <span class="comment">                           Private Function Prototypes</span>
+<a name="l00074"></a>00074 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00075"></a>00075 
+<a name="l00076"></a>00076 <span class="keyword">inline</span> <span class="keyword">static</span> <span class="keywordtype">double</span> irplib_data_get_double(<span class="keyword">const</span> <span class="keywordtype">void</span> *, cpl_type, <span class="keywordtype">int</span>)
+<a name="l00077"></a>00077 <span class="preprocessor">#ifdef CPL_HAVE_GNUC_NONNULL</span>
+<a name="l00078"></a>00078 <span class="preprocessor"></span>     __attribute__((nonnull))
+<a name="l00079"></a>00079 <span class="preprocessor">#endif</span>
+<a name="l00080"></a>00080 <span class="preprocessor"></span>    ;
+<a name="l00081"></a>00081 
+<a name="l00082"></a>00082 <span class="keyword">inline</span> <span class="keyword">static</span> <span class="keywordtype">void</span> irplib_data_set_double(<span class="keywordtype">void</span> *, cpl_type, <span class="keywordtype">int</span>, <span class="keywordtype">double</span>)
+<a name="l00083"></a>00083 <span class="preprocessor">#ifdef CPL_HAVE_GNUC_NONNULL</span>
+<a name="l00084"></a>00084 <span class="preprocessor"></span>     __attribute__((nonnull))
+<a name="l00085"></a>00085 <span class="preprocessor">#endif</span>
+<a name="l00086"></a>00086 <span class="preprocessor"></span>    ;
+<a name="l00087"></a>00087 
+<a name="l00088"></a>00088 
+<a name="l00089"></a>00089 <span class="keyword">static</span>
+<a name="l00090"></a>00090 <span class="keywordtype">void</span> irplib_errorstate_dump_one_level(<span class="keywordtype">void</span> (*)(<span class="keyword">const</span> <span class="keywordtype">char</span> *,
+<a name="l00091"></a>00091                                                <span class="keyword">const</span> <span class="keywordtype">char</span> *, ...)
+<a name="l00092"></a>00092   #ifdef __GNUC__
+<a name="l00093"></a>00093       __attribute__((format (printf, 2, 3)))
+<a name="l00094"></a>00094   #endif
+<a name="l00095"></a>00095                                       , <span class="keywordtype">unsigned</span>, <span class="keywordtype">unsigned</span>, <span class="keywordtype">unsigned</span>);
+<a name="l00096"></a>00096 <span class="keyword">static</span> <span class="keywordtype">double</span> frame_get_exptime(<span class="keyword">const</span> cpl_frame * pframe);
+<a name="l00097"></a>00097 <span class="keyword">static</span> <span class="keywordtype">void</span> quicksort(<span class="keywordtype">int</span>* index, <span class="keywordtype">double</span>* exptime, <span class="keywordtype">int</span> left, <span class="keywordtype">int</span> right);
+<a name="l00098"></a>00098 
+<a name="l00099"></a>00099 <span class="keyword">static</span> cpl_error_code irplib_dfs_product_save(cpl_frameset *,
+<a name="l00100"></a>00100                                               cpl_propertylist *,
+<a name="l00101"></a>00101                                               <span class="keyword">const</span> cpl_parameterlist *,
+<a name="l00102"></a>00102                                               <span class="keyword">const</span> cpl_frameset *,
+<a name="l00103"></a>00103                                               <span class="keyword">const</span> cpl_frame *,
+<a name="l00104"></a>00104                                               <span class="keyword">const</span> cpl_imagelist *,
+<a name="l00105"></a>00105                                               <span class="keyword">const</span> cpl_image *,
+<a name="l00106"></a>00106                                               cpl_type,
+<a name="l00107"></a>00107                                               <span class="keyword">const</span> cpl_table *,
+<a name="l00108"></a>00108                                               <span class="keyword">const</span> cpl_propertylist *,
+<a name="l00109"></a>00109                                               <span class="keyword">const</span> <span class="keywordtype">char</span> *,
+<a name="l00110"></a>00110                                               <span class="keyword">const</span> cpl_propertylist *,
+<a name="l00111"></a>00111                                               <span class="keyword">const</span> <span class="keywordtype">char</span> *,
+<a name="l00112"></a>00112                                               <span class="keyword">const</span> <span class="keywordtype">char</span> *,
+<a name="l00113"></a>00113                                               <span class="keyword">const</span> <span class="keywordtype">char</span> *);
+<a name="l00114"></a>00114 
+<a name="l00115"></a>00115 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00119"></a>00119 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00123"></a>00123 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00135"></a>00135 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00136"></a><a class="code" href="group__irplib__utils.html#ga6b29dac884b62ab52f43dd670d4d8386">00136</a> <span class="keywordtype">void</span> <a class="code" href="group__irplib__utils.html#ga6b29dac884b62ab52f43dd670d4d8386" title="Dump a single CPL error at the CPL warning level.">irplib_errorstate_dump_warning</a>(<span class="keywordtype">unsigned</span> <span class="keyword">self</span>, <span class="keywordtype">unsigned</span> first,
+<a name="l00137"></a>00137                                     <span class="keywordtype">unsigned</span> last)
+<a name="l00138"></a>00138 {
+<a name="l00139"></a>00139 
+<a name="l00140"></a>00140     irplib_errorstate_dump_one_level(&cpl_msg_warning, <span class="keyword">self</span>, first, last);
+<a name="l00141"></a>00141 
+<a name="l00142"></a>00142 }
+<a name="l00143"></a>00143 
+<a name="l00144"></a>00144 <span class="keyword">static</span> cpl_polynomial * irplib_polynomial_fit_1d_create_common(
+<a name="l00145"></a>00145         <span class="keyword">const</span> cpl_vector    *   x_pos,
+<a name="l00146"></a>00146         <span class="keyword">const</span> cpl_vector    *   values,
+<a name="l00147"></a>00147         <span class="keywordtype">int</span>                     degree,
+<a name="l00148"></a>00148         <span class="keywordtype">double</span>              *   mse,
+<a name="l00149"></a>00149         <span class="keywordtype">double</span>              *  rechisq
+<a name="l00150"></a>00150         );
+<a name="l00151"></a>00151 
+<a name="l00152"></a>00152 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00162"></a>00162 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00163"></a><a class="code" href="group__irplib__utils.html#ga901ff52a1c9dcdfcf2d2632d31064bdb">00163</a> <span class="keywordtype">void</span> <a class="code" href="group__irplib__utils.html#ga901ff52a1c9dcdfcf2d2632d31064bdb" title="Dump a single CPL error at the CPL info level.">irplib_errorstate_dump_info</a>(<span class="keywordtype">unsigned</span> <span class="keyword">self</span>, <span class="keywordtype">unsigned</span> first,
+<a name="l00164"></a>00164                                     <span class="keywordtype">unsigned</span> last)
+<a name="l00165"></a>00165 {
+<a name="l00166"></a>00166 
+<a name="l00167"></a>00167     irplib_errorstate_dump_one_level(&cpl_msg_info, <span class="keyword">self</span>, first, last);
+<a name="l00168"></a>00168 
+<a name="l00169"></a>00169 }
+<a name="l00170"></a>00170 
+<a name="l00171"></a>00171 
+<a name="l00172"></a>00172 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00182"></a>00182 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00183"></a><a class="code" href="group__irplib__utils.html#ga26c6209e5df98978e2922a15b47b47d1">00183</a> <span class="keywordtype">void</span> <a class="code" href="group__irplib__utils.html#ga26c6209e5df98978e2922a15b47b47d1" title="Dump a single CPL error at the CPL debug level.">irplib_errorstate_dump_debug</a>(<span class="keywordtype">unsigned</span> <span class="keyword">self</span>, <span class="keywordtype">unsigned</span> first,
+<a name="l00184"></a>00184                                     <span class="keywordtype">unsigned</span> last)
+<a name="l00185"></a>00185 {
+<a name="l00186"></a>00186 
+<a name="l00187"></a>00187     irplib_errorstate_dump_one_level(&cpl_msg_debug, <span class="keyword">self</span>, first, last);
+<a name="l00188"></a>00188 
+<a name="l00189"></a>00189 }
+<a name="l00190"></a>00190 
+<a name="l00191"></a>00191 
+<a name="l00192"></a>00192 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00213"></a>00213 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00214"></a><a class="code" href="group__irplib__utils.html#ga346842d722834a2e6221ff2d86314b7e">00214</a> cpl_error_code <a class="code" href="group__irplib__utils.html#ga346842d722834a2e6221ff2d86314b7e" title="Save an image as a DFS-compliant pipeline product.">irplib_dfs_save_image</a>(cpl_frameset            * allframes,
+<a name="l00215"></a>00215                                      <span class="keyword">const</span> cpl_parameterlist * parlist,
+<a name="l00216"></a>00216                                      <span class="keyword">const</span> cpl_frameset      * usedframes,
+<a name="l00217"></a>00217                                      <span class="keyword">const</span> cpl_image         * image,
+<a name="l00218"></a>00218                                      cpl_type_bpp              bpp,
+<a name="l00219"></a>00219                                      <span class="keyword">const</span> <span class="keywordtype">char</span>              * recipe,
+<a name="l00220"></a>00220                                      <span class="keyword">const</span> <span class="keywordtype">char</span>              * procat,
+<a name="l00221"></a>00221                                      <span class="keyword">const</span> cpl_propertylist  * applist,
+<a name="l00222"></a>00222                                      <span class="keyword">const</span> <span class="keywordtype">char</span>              * remregexp,
+<a name="l00223"></a>00223                                      <span class="keyword">const</span> <span class="keywordtype">char</span>              * pipe_id,
+<a name="l00224"></a>00224                                      <span class="keyword">const</span> <span class="keywordtype">char</span>              * filename)
+<a name="l00225"></a>00225 {
+<a name="l00226"></a>00226     cpl_errorstate     prestate = cpl_errorstate_get();
+<a name="l00227"></a>00227     cpl_propertylist * prolist  = applist ? cpl_propertylist_duplicate(applist)
+<a name="l00228"></a>00228         : cpl_propertylist_new();
+<a name="l00229"></a>00229 
+<a name="l00230"></a>00230     cpl_propertylist_update_string(prolist, CPL_DFS_PRO_CATG, procat);
+<a name="l00231"></a>00231 
+<a name="l00232"></a>00232     <a class="code" href="group__irplib__utils.html#ga1fd7c2f4c00014049b0bf4bf6814b451" title="Save an image as a DFS-compliant pipeline product.">irplib_dfs_save_image_</a>(allframes, NULL, parlist, usedframes, NULL, image,
+<a name="l00233"></a>00233                            bpp, recipe, prolist, remregexp, pipe_id, filename);
+<a name="l00234"></a>00234 
+<a name="l00235"></a>00235     cpl_propertylist_delete(prolist);
+<a name="l00236"></a>00236 
+<a name="l00237"></a>00237     cpl_ensure_code(cpl_errorstate_is_equal(prestate), cpl_error_get_code());
+<a name="l00238"></a>00238 
+<a name="l00239"></a>00239     <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l00240"></a>00240 
+<a name="l00241"></a>00241 }
+<a name="l00242"></a>00242 
+<a name="l00243"></a>00243 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00260"></a>00260 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00261"></a>00261 cpl_error_code
+<a name="l00262"></a><a class="code" href="group__irplib__utils.html#ga4dc12f321e7aeb5e67ff19f815bfd7b7">00262</a> <a class="code" href="group__irplib__utils.html#ga4dc12f321e7aeb5e67ff19f815bfd7b7" title="Save a propertylist as a DFS-compliant pipeline product.">irplib_dfs_save_propertylist</a>(cpl_frameset            * allframes,
+<a name="l00263"></a>00263                              <span class="keyword">const</span> cpl_parameterlist * parlist,
+<a name="l00264"></a>00264                              <span class="keyword">const</span> cpl_frameset      * usedframes,
+<a name="l00265"></a>00265                              <span class="keyword">const</span> <span class="keywordtype">char</span>              * recipe,
+<a name="l00266"></a>00266                              <span class="keyword">const</span> <span class="keywordtype">char</span>              * procat,
+<a name="l00267"></a>00267                              <span class="keyword">const</span> cpl_propertylist  * applist,
+<a name="l00268"></a>00268                              <span class="keyword">const</span> <span class="keywordtype">char</span>              * remregexp,
+<a name="l00269"></a>00269                              <span class="keyword">const</span> <span class="keywordtype">char</span>              * pipe_id,
+<a name="l00270"></a>00270                              <span class="keyword">const</span> <span class="keywordtype">char</span>              * filename)
+<a name="l00271"></a>00271 {
+<a name="l00272"></a>00272     cpl_errorstate     prestate = cpl_errorstate_get();
+<a name="l00273"></a>00273     cpl_propertylist * prolist  = applist ? cpl_propertylist_duplicate(applist)
+<a name="l00274"></a>00274         : cpl_propertylist_new();
+<a name="l00275"></a>00275 
+<a name="l00276"></a>00276     cpl_propertylist_update_string(prolist, CPL_DFS_PRO_CATG, procat);
+<a name="l00277"></a>00277 
+<a name="l00278"></a>00278     cpl_dfs_save_propertylist(allframes, NULL, parlist, usedframes, NULL,
+<a name="l00279"></a>00279                               recipe, prolist, remregexp, pipe_id, filename);
+<a name="l00280"></a>00280 
+<a name="l00281"></a>00281     cpl_propertylist_delete(prolist);
+<a name="l00282"></a>00282 
+<a name="l00283"></a>00283     cpl_ensure_code(cpl_errorstate_is_equal(prestate), cpl_error_get_code());
+<a name="l00284"></a>00284 
+<a name="l00285"></a>00285     <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l00286"></a>00286 
+<a name="l00287"></a>00287 }
+<a name="l00288"></a>00288 
+<a name="l00289"></a>00289 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00308"></a>00308 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00309"></a><a class="code" href="group__irplib__utils.html#ga66f7adc9e165b4e934e3d57a700f55c1">00309</a> cpl_error_code <a class="code" href="group__irplib__utils.html#ga66f7adc9e165b4e934e3d57a700f55c1" title="Save an imagelist as a DFS-compliant pipeline product.">irplib_dfs_save_imagelist</a>(cpl_frameset            * allframes,
+<a name="l00310"></a>00310                                          <span class="keyword">const</span> cpl_parameterlist * parlist,
+<a name="l00311"></a>00311                                          <span class="keyword">const</span> cpl_frameset      * usedframes,
+<a name="l00312"></a>00312                                          <span class="keyword">const</span> cpl_imagelist     * imagelist,
+<a name="l00313"></a>00313                                          cpl_type_bpp              bpp,
+<a name="l00314"></a>00314                                          <span class="keyword">const</span> <span class="keywordtype">char</span>              * recipe,
+<a name="l00315"></a>00315                                          <span class="keyword">const</span> <span class="keywordtype">char</span>              * procat,
+<a name="l00316"></a>00316                                          <span class="keyword">const</span> cpl_propertylist  * applist,
+<a name="l00317"></a>00317                                          <span class="keyword">const</span> <span class="keywordtype">char</span>              * remregexp,
+<a name="l00318"></a>00318                                          <span class="keyword">const</span> <span class="keywordtype">char</span>              * pipe_id,
+<a name="l00319"></a>00319                                          <span class="keyword">const</span> <span class="keywordtype">char</span>              * filename)
+<a name="l00320"></a>00320 {
+<a name="l00321"></a>00321     cpl_errorstate     prestate = cpl_errorstate_get();
+<a name="l00322"></a>00322     cpl_propertylist * prolist  = applist ? cpl_propertylist_duplicate(applist)
+<a name="l00323"></a>00323         : cpl_propertylist_new();
+<a name="l00324"></a>00324 
+<a name="l00325"></a>00325     cpl_propertylist_update_string(prolist, CPL_DFS_PRO_CATG, procat);
+<a name="l00326"></a>00326 
+<a name="l00327"></a>00327     cpl_dfs_save_imagelist(allframes, NULL, parlist, usedframes, NULL,
+<a name="l00328"></a>00328                            imagelist, bpp, recipe, prolist, remregexp, pipe_id,
+<a name="l00329"></a>00329                            filename);
+<a name="l00330"></a>00330 
+<a name="l00331"></a>00331     cpl_propertylist_delete(prolist);
+<a name="l00332"></a>00332 
+<a name="l00333"></a>00333     cpl_ensure_code(cpl_errorstate_is_equal(prestate), cpl_error_get_code());
+<a name="l00334"></a>00334 
+<a name="l00335"></a>00335     <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l00336"></a>00336 }
+<a name="l00337"></a>00337 
+<a name="l00338"></a>00338 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00356"></a>00356 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00357"></a><a class="code" href="group__irplib__utils.html#ga62a91f8630af11164547c168660b2ade">00357</a> cpl_error_code <a class="code" href="group__irplib__utils.html#ga62a91f8630af11164547c168660b2ade" title="Save a table as a DFS-compliant pipeline product.">irplib_dfs_save_table</a>(cpl_frameset            * allframes,
+<a name="l00358"></a>00358                                      <span class="keyword">const</span> cpl_parameterlist * parlist,
+<a name="l00359"></a>00359                                      <span class="keyword">const</span> cpl_frameset      * usedframes,
+<a name="l00360"></a>00360                                      <span class="keyword">const</span> cpl_table         * table,
+<a name="l00361"></a>00361                                      <span class="keyword">const</span> cpl_propertylist  * tablelist,
+<a name="l00362"></a>00362                                      <span class="keyword">const</span> <span class="keywordtype">char</span>              * recipe,
+<a name="l00363"></a>00363                                      <span class="keyword">const</span> <span class="keywordtype">char</span>              * procat,
+<a name="l00364"></a>00364                                      <span class="keyword">const</span> cpl_propertylist  * applist,
+<a name="l00365"></a>00365                                      <span class="keyword">const</span> <span class="keywordtype">char</span>              * remregexp,
+<a name="l00366"></a>00366                                      <span class="keyword">const</span> <span class="keywordtype">char</span>              * pipe_id,
+<a name="l00367"></a>00367                                      <span class="keyword">const</span> <span class="keywordtype">char</span>              * filename)
+<a name="l00368"></a>00368 {
+<a name="l00369"></a>00369 
+<a name="l00370"></a>00370     cpl_errorstate     prestate = cpl_errorstate_get();
+<a name="l00371"></a>00371     cpl_propertylist * prolist  = applist ? cpl_propertylist_duplicate(applist)
+<a name="l00372"></a>00372         : cpl_propertylist_new();
+<a name="l00373"></a>00373 
+<a name="l00374"></a>00374     cpl_propertylist_update_string(prolist, CPL_DFS_PRO_CATG, procat);
+<a name="l00375"></a>00375 
+<a name="l00376"></a>00376     cpl_dfs_save_table(allframes, NULL, parlist, usedframes, NULL,
+<a name="l00377"></a>00377                            table, tablelist, recipe, prolist, remregexp,
+<a name="l00378"></a>00378                            pipe_id, filename);
+<a name="l00379"></a>00379 
+<a name="l00380"></a>00380     cpl_propertylist_delete(prolist);
+<a name="l00381"></a>00381 
+<a name="l00382"></a>00382     cpl_ensure_code(cpl_errorstate_is_equal(prestate), cpl_error_get_code());
+<a name="l00383"></a>00383 
+<a name="l00384"></a>00384     <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l00385"></a>00385 }
+<a name="l00386"></a>00386 
+<a name="l00387"></a>00387 
+<a name="l00388"></a>00388 
+<a name="l00389"></a>00389 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00416"></a>00416 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00417"></a><a class="code" href="group__irplib__utils.html#ga1fd7c2f4c00014049b0bf4bf6814b451">00417</a> cpl_error_code <a class="code" href="group__irplib__utils.html#ga1fd7c2f4c00014049b0bf4bf6814b451" title="Save an image as a DFS-compliant pipeline product.">irplib_dfs_save_image_</a>(cpl_frameset            * allframes,
+<a name="l00418"></a>00418                                       cpl_propertylist        * header,
+<a name="l00419"></a>00419                                       <span class="keyword">const</span> cpl_parameterlist * parlist,
+<a name="l00420"></a>00420                                       <span class="keyword">const</span> cpl_frameset      * usedframes,
+<a name="l00421"></a>00421                                       <span class="keyword">const</span> cpl_frame         * inherit,
+<a name="l00422"></a>00422                                       <span class="keyword">const</span> cpl_image         * image,
+<a name="l00423"></a>00423                                       cpl_type                  type,
+<a name="l00424"></a>00424                                       <span class="keyword">const</span> <span class="keywordtype">char</span>              * recipe,
+<a name="l00425"></a>00425                                       <span class="keyword">const</span> cpl_propertylist  * applist,
+<a name="l00426"></a>00426                                       <span class="keyword">const</span> <span class="keywordtype">char</span>              * remregexp,
+<a name="l00427"></a>00427                                       <span class="keyword">const</span> <span class="keywordtype">char</span>              * pipe_id,
+<a name="l00428"></a>00428                                       <span class="keyword">const</span> <span class="keywordtype">char</span>              * filename)
+<a name="l00429"></a>00429 {
+<a name="l00430"></a>00430     <span class="keywordflow">return</span>
+<a name="l00431"></a>00431         irplib_dfs_product_save(allframes, header, parlist, usedframes, inherit,
+<a name="l00432"></a>00432                                 NULL, image, type, NULL, NULL, recipe,
+<a name="l00433"></a>00433                                 applist, remregexp, pipe_id, filename)
+<a name="l00434"></a>00434         ? cpl_error_set_where(cpl_func) : CPL_ERROR_NONE;
+<a name="l00435"></a>00435 
+<a name="l00436"></a>00436 }
+<a name="l00437"></a>00437 
+<a name="l00438"></a>00438 
+<a name="l00439"></a>00439 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00463"></a>00463 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00464"></a>00464 
+<a name="l00465"></a>00465 <span class="keyword">static</span>
+<a name="l00466"></a>00466 cpl_error_code irplib_dfs_product_save(cpl_frameset            * allframes,
+<a name="l00467"></a>00467                                        cpl_propertylist        * header,
+<a name="l00468"></a>00468                                        <span class="keyword">const</span> cpl_parameterlist * parlist,
+<a name="l00469"></a>00469                                        <span class="keyword">const</span> cpl_frameset      * usedframes,
+<a name="l00470"></a>00470                                        <span class="keyword">const</span> cpl_frame         * inherit,
+<a name="l00471"></a>00471                                        <span class="keyword">const</span> cpl_imagelist     * imagelist,
+<a name="l00472"></a>00472                                        <span class="keyword">const</span> cpl_image         * image,
+<a name="l00473"></a>00473                                        cpl_type                  type,
+<a name="l00474"></a>00474                                        <span class="keyword">const</span> cpl_table         * table,
+<a name="l00475"></a>00475                                        <span class="keyword">const</span> cpl_propertylist  * tablelist,
+<a name="l00476"></a>00476                                        <span class="keyword">const</span> <span class="keywordtype">char</span>              * recipe,
+<a name="l00477"></a>00477                                        <span class="keyword">const</span> cpl_propertylist  * applist,
+<a name="l00478"></a>00478                                        <span class="keyword">const</span> <span class="keywordtype">char</span>              * remregexp,
+<a name="l00479"></a>00479                                        <span class="keyword">const</span> <span class="keywordtype">char</span>              * pipe_id,
+<a name="l00480"></a>00480                                        <span class="keyword">const</span> <span class="keywordtype">char</span>              * filename) {
+<a name="l00481"></a>00481 
+<a name="l00482"></a>00482     <span class="keyword">const</span> <span class="keywordtype">char</span>       * procat;
+<a name="l00483"></a>00483     cpl_propertylist * plist;
+<a name="l00484"></a>00484     cpl_frame        * product_frame;
+<a name="l00485"></a>00485     <span class="comment">/* Inside this function the product-types are numbered:</span>
+<a name="l00486"></a>00486 <span class="comment">       0: imagelist</span>
+<a name="l00487"></a>00487 <span class="comment">       1: table</span>
+<a name="l00488"></a>00488 <span class="comment">       2: image</span>
+<a name="l00489"></a>00489 <span class="comment">       3: propertylist only</span>
+<a name="l00490"></a>00490 <span class="comment">    */</span>
+<a name="l00491"></a>00491     <span class="keyword">const</span> <span class="keywordtype">unsigned</span>     pronum
+<a name="l00492"></a>00492         = imagelist != NULL ? 0 : table != NULL ? 1 :  (image != NULL ? 2 : 3);
+<a name="l00493"></a>00493     <span class="keyword">const</span> <span class="keywordtype">char</span>       * proname[] = {<span class="stringliteral">"imagelist"</span>, <span class="stringliteral">"table"</span>, <span class="stringliteral">"image"</span>,
+<a name="l00494"></a>00494                                     <span class="stringliteral">"propertylist"</span>};
+<a name="l00495"></a>00495     <span class="comment">/* FIXME: Define a frame type for an imagelist and when data-less */</span>
+<a name="l00496"></a>00496     <span class="keyword">const</span> <span class="keywordtype">int</span>          protype[] = {CPL_FRAME_TYPE_ANY, CPL_FRAME_TYPE_TABLE,
+<a name="l00497"></a>00497                                     CPL_FRAME_TYPE_IMAGE, CPL_FRAME_TYPE_ANY};
+<a name="l00498"></a>00498     cpl_error_code     error = CPL_ERROR_NONE;
+<a name="l00499"></a>00499 
+<a name="l00500"></a>00500 
+<a name="l00501"></a>00501     <span class="comment">/* No more than one of imagelist, table and image may be non-NULL */</span>
+<a name="l00502"></a>00502     <span class="comment">/* tablelist may only be non-NULL when table is non-NULL */</span>
+<a name="l00503"></a>00503     <span class="keywordflow">if</span> (imagelist != NULL) {
+<a name="l00504"></a>00504         assert(pronum == 0);
+<a name="l00505"></a>00505         assert(image == NULL);
+<a name="l00506"></a>00506         assert(table == NULL);
+<a name="l00507"></a>00507         assert(tablelist == NULL);
+<a name="l00508"></a>00508     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (table != NULL) {
+<a name="l00509"></a>00509         assert(pronum == 1);
+<a name="l00510"></a>00510         assert(imagelist == NULL);
+<a name="l00511"></a>00511         assert(image == NULL);
+<a name="l00512"></a>00512     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (image != NULL) {
+<a name="l00513"></a>00513         assert(pronum == 2);
+<a name="l00514"></a>00514         assert(imagelist == NULL);
+<a name="l00515"></a>00515         assert(table == NULL);
+<a name="l00516"></a>00516         assert(tablelist == NULL);
+<a name="l00517"></a>00517     } <span class="keywordflow">else</span> {
+<a name="l00518"></a>00518         assert(pronum == 3);
+<a name="l00519"></a>00519         assert(imagelist == NULL);
+<a name="l00520"></a>00520         assert(table == NULL);
+<a name="l00521"></a>00521         assert(tablelist == NULL);
+<a name="l00522"></a>00522         assert(image == NULL);
+<a name="l00523"></a>00523     }
+<a name="l00524"></a>00524 
+<a name="l00525"></a>00525     cpl_ensure_code(allframes  != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00526"></a>00526     cpl_ensure_code(parlist    != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00527"></a>00527     cpl_ensure_code(usedframes != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00528"></a>00528     cpl_ensure_code(recipe     != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00529"></a>00529     cpl_ensure_code(applist    != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00530"></a>00530     cpl_ensure_code(pipe_id    != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00531"></a>00531     cpl_ensure_code(filename   != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00532"></a>00532 
+<a name="l00533"></a>00533     procat = cpl_propertylist_get_string(applist, CPL_DFS_PRO_CATG);
+<a name="l00534"></a>00534 
+<a name="l00535"></a>00535     cpl_ensure_code(procat     != NULL, cpl_error_get_code());
+<a name="l00536"></a>00536 
+<a name="l00537"></a>00537     cpl_msg_info(cpl_func, <span class="stringliteral">"Writing FITS %s product(%s): %s"</span>, proname[pronum],
+<a name="l00538"></a>00538                  procat, filename);
+<a name="l00539"></a>00539 
+<a name="l00540"></a>00540     product_frame = cpl_frame_new();
+<a name="l00541"></a>00541 
+<a name="l00542"></a>00542     <span class="comment">/* Create product frame */</span>
+<a name="l00543"></a>00543     error |= cpl_frame_set_filename(product_frame, filename);
+<a name="l00544"></a>00544     error |= cpl_frame_set_tag(product_frame, procat);
+<a name="l00545"></a>00545     error |= cpl_frame_set_type(product_frame, protype[pronum]);
+<a name="l00546"></a>00546     error |= cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT);
+<a name="l00547"></a>00547     error |= cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL);
+<a name="l00548"></a>00548 
+<a name="l00549"></a>00549     <span class="keywordflow">if</span> (error) {
+<a name="l00550"></a>00550         cpl_frame_delete(product_frame);
+<a name="l00551"></a>00551         <span class="keywordflow">return</span> cpl_error_set_where(cpl_func);
+<a name="l00552"></a>00552     }
+<a name="l00553"></a>00553 
+<a name="l00554"></a>00554     <span class="keywordflow">if</span> (header != NULL) {
+<a name="l00555"></a>00555         cpl_propertylist_empty(header);
+<a name="l00556"></a>00556         plist = header;
+<a name="l00557"></a>00557     } <span class="keywordflow">else</span> {
+<a name="l00558"></a>00558         plist = cpl_propertylist_new();
+<a name="l00559"></a>00559     }
+<a name="l00560"></a>00560 
+<a name="l00561"></a>00561     <span class="comment">/* Add any QC parameters here */</span>
+<a name="l00562"></a>00562     <span class="keywordflow">if</span> (applist != NULL) error = cpl_propertylist_copy_property_regexp(plist,
+<a name="l00563"></a>00563                                                                        applist,
+<a name="l00564"></a>00564                                                                        <span class="stringliteral">"."</span>, 0);
+<a name="l00565"></a>00565 
+<a name="l00566"></a>00566     <span class="comment">/* Add DataFlow keywords */</span>
+<a name="l00567"></a>00567     <span class="keywordflow">if</span> (!error)
+<a name="l00568"></a>00568         error = cpl_dfs_setup_product_header(plist, product_frame, usedframes,
+<a name="l00569"></a>00569                                              parlist, recipe, pipe_id,
+<a name="l00570"></a>00570                                              <span class="stringliteral">"PRO-1.15"</span>, inherit);
+<a name="l00571"></a>00571 
+<a name="l00572"></a>00572     <span class="keywordflow">if</span> (remregexp != NULL && !error) {
+<a name="l00573"></a>00573         cpl_errorstate prestate = cpl_errorstate_get();
+<a name="l00574"></a>00574         (void)cpl_propertylist_erase_regexp(plist, remregexp, 0);
+<a name="l00575"></a>00575         <span class="keywordflow">if</span> (!cpl_errorstate_is_equal(prestate)) error = cpl_error_get_code();
+<a name="l00576"></a>00576     }
+<a name="l00577"></a>00577 
+<a name="l00578"></a>00578     <span class="keywordflow">if</span> (!error) {
+<a name="l00579"></a>00579         <span class="keywordflow">switch</span> (pronum) {
+<a name="l00580"></a>00580             <span class="keywordflow">case</span> 0:
+<a name="l00581"></a>00581                 error = cpl_imagelist_save(imagelist, filename, type, plist,
+<a name="l00582"></a>00582                                            CPL_IO_CREATE);
+<a name="l00583"></a>00583                 <span class="keywordflow">break</span>;
+<a name="l00584"></a>00584             <span class="keywordflow">case</span> 1:
+<a name="l00585"></a>00585                 error = cpl_table_save(table, plist, tablelist, filename,
+<a name="l00586"></a>00586                                        CPL_IO_CREATE);
+<a name="l00587"></a>00587                 <span class="keywordflow">break</span>;
+<a name="l00588"></a>00588             <span class="keywordflow">case</span> 2:
+<a name="l00589"></a>00589                 error = cpl_image_save(image, filename, type, plist,
+<a name="l00590"></a>00590                                        CPL_IO_CREATE);
+<a name="l00591"></a>00591                 <span class="keywordflow">break</span>;
+<a name="l00592"></a>00592             <span class="keywordflow">default</span>:
+<a name="l00593"></a>00593                 <span class="comment">/* case 3: */</span>
+<a name="l00594"></a>00594                 error = cpl_propertylist_save(plist, filename, CPL_IO_CREATE);
+<a name="l00595"></a>00595         }
+<a name="l00596"></a>00596     }
+<a name="l00597"></a>00597 
+<a name="l00598"></a>00598     <span class="keywordflow">if</span> (!error) {
+<a name="l00599"></a>00599         <span class="comment">/* Insert the frame of the saved file in the input frameset */</span>
+<a name="l00600"></a>00600         error = cpl_frameset_insert(allframes, product_frame);
+<a name="l00601"></a>00601 
+<a name="l00602"></a>00602     } <span class="keywordflow">else</span> {
+<a name="l00603"></a>00603         cpl_frame_delete(product_frame);
+<a name="l00604"></a>00604     }
+<a name="l00605"></a>00605 
+<a name="l00606"></a>00606     <span class="keywordflow">if</span> (plist != header) cpl_propertylist_delete(plist);
+<a name="l00607"></a>00607 
+<a name="l00608"></a>00608     cpl_ensure_code(!error, error);
+<a name="l00609"></a>00609 
+<a name="l00610"></a>00610     <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l00611"></a>00611 
+<a name="l00612"></a>00612 }    
+<a name="l00613"></a>00613 
+<a name="l00614"></a>00614 
+<a name="l00615"></a>00615 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00670"></a>00670 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00671"></a><a class="code" href="group__irplib__utils.html#ga832676f36ecd647b77f4bb373b2d1954">00671</a> cpl_error_code <a class="code" href="group__irplib__utils.html#ga832676f36ecd647b77f4bb373b2d1954" title="Split the values in an image in three according to two thresholds.">irplib_image_split</a>(<span class="keyword">const</span> cpl_image * <span class="keyword">self</span>,
+<a name="l00672"></a>00672                                   cpl_image * im_low,
+<a name="l00673"></a>00673                                   cpl_image * im_mid,
+<a name="l00674"></a>00674                                   cpl_image * im_high,
+<a name="l00675"></a>00675                                   <span class="keywordtype">double</span> th_low,
+<a name="l00676"></a>00676                                   cpl_boolean isleq_low,
+<a name="l00677"></a>00677                                   <span class="keywordtype">double</span> th_high,
+<a name="l00678"></a>00678                                   cpl_boolean isgeq_high,
+<a name="l00679"></a>00679                                   <span class="keywordtype">double</span> alt_low,
+<a name="l00680"></a>00680                                   <span class="keywordtype">double</span> alt_high,
+<a name="l00681"></a>00681                                   cpl_boolean isbad_low,
+<a name="l00682"></a>00682                                   cpl_boolean isbad_mid,
+<a name="l00683"></a>00683                                   cpl_boolean isbad_high)
+<a name="l00684"></a>00684 {
+<a name="l00685"></a>00685 
+<a name="l00686"></a>00686     <span class="keyword">const</span> <span class="keywordtype">void</span>       * selfdata = cpl_image_get_data_const(<span class="keyword">self</span>);
+<a name="l00687"></a>00687     <span class="comment">/* hasbpm reduces check-overhead if self does not have a bpm, and if</span>
+<a name="l00688"></a>00688 <span class="comment">       self is also passed as an output image, that ends up with bad pixels */</span>
+<a name="l00689"></a>00689     <span class="comment">/* FIXME: Need a proper way to know if a bpm has been allocated :-((((((( */</span>
+<a name="l00690"></a>00690     <span class="keyword">const</span> cpl_boolean  hasbpm
+<a name="l00691"></a>00691         = cpl_image_count_rejected(<span class="keyword">self</span>) ? CPL_TRUE : CPL_FALSE;
+<a name="l00692"></a>00692     <span class="keyword">const</span> cpl_binary * selfbpm = hasbpm
+<a name="l00693"></a>00693         ? cpl_mask_get_data_const(cpl_image_get_bpm_const(<span class="keyword">self</span>)) : NULL;
+<a name="l00694"></a>00694     <span class="keyword">const</span> cpl_type     selftype = cpl_image_get_type(<span class="keyword">self</span>);
+<a name="l00695"></a>00695     <span class="keyword">const</span> <span class="keywordtype">int</span>          nx = cpl_image_get_size_x(<span class="keyword">self</span>);
+<a name="l00696"></a>00696     <span class="keyword">const</span> <span class="keywordtype">int</span>          ny = cpl_image_get_size_y(<span class="keyword">self</span>);
+<a name="l00697"></a>00697     <span class="keyword">const</span> <span class="keywordtype">int</span>          npix = nx * ny;
+<a name="l00698"></a>00698     <span class="keyword">const</span> cpl_boolean  do_low   = im_low  != NULL;
+<a name="l00699"></a>00699     <span class="keyword">const</span> cpl_boolean  do_mid   = im_mid  != NULL;
+<a name="l00700"></a>00700     <span class="keyword">const</span> cpl_boolean  do_high  = im_high != NULL;
+<a name="l00701"></a>00701     <span class="keywordtype">void</span>             * lowdata  = NULL;
+<a name="l00702"></a>00702     <span class="keywordtype">void</span>             * middata  = NULL;
+<a name="l00703"></a>00703     <span class="keywordtype">void</span>             * highdata = NULL;
+<a name="l00704"></a>00704     cpl_binary       * lowbpm   = NULL;
+<a name="l00705"></a>00705     cpl_binary       * midbpm   = NULL;
+<a name="l00706"></a>00706     cpl_binary       * highbpm  = NULL;
+<a name="l00707"></a>00707     <span class="keyword">const</span> cpl_type     lowtype
+<a name="l00708"></a>00708         = do_low ? cpl_image_get_type(im_low) : CPL_TYPE_INVALID;
+<a name="l00709"></a>00709     <span class="keyword">const</span> cpl_type     midtype
+<a name="l00710"></a>00710         = do_mid ? cpl_image_get_type(im_mid) : CPL_TYPE_INVALID;
+<a name="l00711"></a>00711     <span class="keyword">const</span> cpl_type     hightype
+<a name="l00712"></a>00712         = do_high ? cpl_image_get_type(im_high) : CPL_TYPE_INVALID;
+<a name="l00713"></a>00713     <span class="keywordtype">int</span> i;
+<a name="l00714"></a>00714 
+<a name="l00715"></a>00715 
+<a name="l00716"></a>00716     cpl_ensure_code(<span class="keyword">self</span> != NULL,                CPL_ERROR_NULL_INPUT);
+<a name="l00717"></a>00717     cpl_ensure_code(do_low || do_mid || do_high, CPL_ERROR_NULL_INPUT);
+<a name="l00718"></a>00718     cpl_ensure_code(th_low <= th_high,           CPL_ERROR_ILLEGAL_INPUT);
+<a name="l00719"></a>00719 
+<a name="l00720"></a>00720     <span class="keywordflow">if</span> (do_low) {
+<a name="l00721"></a>00721         cpl_ensure_code(cpl_image_get_size_x(im_low) == nx,
+<a name="l00722"></a>00722                         CPL_ERROR_INCOMPATIBLE_INPUT);
+<a name="l00723"></a>00723         cpl_ensure_code(cpl_image_get_size_y(im_low) == ny,
+<a name="l00724"></a>00724                         CPL_ERROR_INCOMPATIBLE_INPUT);
+<a name="l00725"></a>00725         lowdata = cpl_image_get_data(im_low);
+<a name="l00726"></a>00726     }
+<a name="l00727"></a>00727 
+<a name="l00728"></a>00728     <span class="keywordflow">if</span> (do_mid) {
+<a name="l00729"></a>00729         cpl_ensure_code(cpl_image_get_size_x(im_mid) == nx,
+<a name="l00730"></a>00730                         CPL_ERROR_INCOMPATIBLE_INPUT);
+<a name="l00731"></a>00731         cpl_ensure_code(cpl_image_get_size_y(im_mid) == ny,
+<a name="l00732"></a>00732                         CPL_ERROR_INCOMPATIBLE_INPUT);
+<a name="l00733"></a>00733         middata = cpl_image_get_data(im_mid);
+<a name="l00734"></a>00734     }
+<a name="l00735"></a>00735 
+<a name="l00736"></a>00736     <span class="keywordflow">if</span> (do_high) {
+<a name="l00737"></a>00737         cpl_ensure_code(cpl_image_get_size_x(im_high) == nx,
+<a name="l00738"></a>00738                         CPL_ERROR_INCOMPATIBLE_INPUT);
+<a name="l00739"></a>00739         cpl_ensure_code(cpl_image_get_size_y(im_high) == ny,
+<a name="l00740"></a>00740                         CPL_ERROR_INCOMPATIBLE_INPUT);
+<a name="l00741"></a>00741         highdata = cpl_image_get_data(im_high);
+<a name="l00742"></a>00742     }
+<a name="l00743"></a>00743 
+<a name="l00744"></a>00744     <span class="comment">/* From this point a failure would indicate a serious bug in CPL */</span>
+<a name="l00745"></a>00745 
+<a name="l00746"></a>00746     <span class="keywordflow">for</span> (i = 0; i < npix; i++) {
+<a name="l00747"></a>00747         <span class="keyword">const</span> <span class="keywordtype">double</span> value = irplib_data_get_double(selfdata, selftype, i);
+<a name="l00748"></a>00748         cpl_boolean  isalt_low   = do_low;
+<a name="l00749"></a>00749         cpl_boolean  isalt_mid   = do_mid;
+<a name="l00750"></a>00750         cpl_boolean  isalt_high  = do_high;
+<a name="l00751"></a>00751         cpl_boolean  setbad_low  = do_low;
+<a name="l00752"></a>00752         cpl_boolean  setbad_mid  = do_mid;
+<a name="l00753"></a>00753         cpl_boolean  setbad_high = do_high;
+<a name="l00754"></a>00754         <span class="keyword">const</span> <span class="keywordtype">void</span> * setdata     = NULL;
+<a name="l00755"></a>00755         <span class="keywordtype">double</span>       alt_mid     = 0.0; <span class="comment">/* Avoid (false) uninit warning */</span>
+<a name="l00756"></a>00756 
+<a name="l00757"></a>00757         <span class="keywordflow">if</span> (isleq_low ? value <= th_low : value < th_low) {
+<a name="l00758"></a>00758             <span class="keywordflow">if</span> (do_low) {
+<a name="l00759"></a>00759                 isalt_low = CPL_FALSE;
+<a name="l00760"></a>00760                 irplib_data_set_double(lowdata, lowtype, i, value);
+<a name="l00761"></a>00761                 setbad_low = hasbpm && selfbpm[i];
+<a name="l00762"></a>00762                 setdata = lowdata;
+<a name="l00763"></a>00763             }
+<a name="l00764"></a>00764             alt_mid = alt_low;
+<a name="l00765"></a>00765         } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (isgeq_high ? value >= th_high : value > th_high) {
+<a name="l00766"></a>00766             <span class="keywordflow">if</span> (do_high) {
+<a name="l00767"></a>00767                 isalt_high = CPL_FALSE;
+<a name="l00768"></a>00768                 irplib_data_set_double(highdata, hightype, i, value);
+<a name="l00769"></a>00769                 setbad_high = hasbpm && selfbpm[i];
+<a name="l00770"></a>00770                 setdata = highdata;
+<a name="l00771"></a>00771             }
+<a name="l00772"></a>00772             alt_mid = alt_high;
+<a name="l00773"></a>00773         } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (do_mid) {
+<a name="l00774"></a>00774             isalt_mid = CPL_FALSE;
+<a name="l00775"></a>00775             irplib_data_set_double(middata, midtype, i, value);
+<a name="l00776"></a>00776             setbad_mid = hasbpm && selfbpm[i];
+<a name="l00777"></a>00777             setdata = middata;
+<a name="l00778"></a>00778         }
+<a name="l00779"></a>00779 
+<a name="l00780"></a>00780         <span class="keywordflow">if</span> (isalt_low && lowdata != setdata) {
+<a name="l00781"></a>00781             irplib_data_set_double(lowdata, lowtype, i, alt_low);
+<a name="l00782"></a>00782             setbad_low = isbad_low;
+<a name="l00783"></a>00783         }
+<a name="l00784"></a>00784         <span class="keywordflow">if</span> (isalt_mid && middata != setdata) {
+<a name="l00785"></a>00785             irplib_data_set_double(middata, midtype, i, alt_mid);
+<a name="l00786"></a>00786             setbad_mid = isbad_mid;
+<a name="l00787"></a>00787         }
+<a name="l00788"></a>00788         <span class="keywordflow">if</span> (isalt_high && highdata != setdata) {
+<a name="l00789"></a>00789             irplib_data_set_double(highdata, hightype, i, alt_high);
+<a name="l00790"></a>00790             setbad_high = isbad_high;
+<a name="l00791"></a>00791         }
+<a name="l00792"></a>00792 
+<a name="l00793"></a>00793         <span class="keywordflow">if</span> (setbad_low) {
+<a name="l00794"></a>00794             <span class="keywordflow">if</span> (lowbpm == NULL) lowbpm
+<a name="l00795"></a>00795                 = cpl_mask_get_data(cpl_image_get_bpm(im_low));
+<a name="l00796"></a>00796             lowbpm[i] = CPL_BINARY_1;
+<a name="l00797"></a>00797         }
+<a name="l00798"></a>00798         <span class="keywordflow">if</span> (setbad_mid) {
+<a name="l00799"></a>00799             <span class="keywordflow">if</span> (midbpm == NULL) midbpm
+<a name="l00800"></a>00800                 = cpl_mask_get_data(cpl_image_get_bpm(im_mid));
+<a name="l00801"></a>00801             midbpm[i] = CPL_BINARY_1;
+<a name="l00802"></a>00802         }
+<a name="l00803"></a>00803         <span class="keywordflow">if</span> (setbad_high) {
+<a name="l00804"></a>00804             <span class="keywordflow">if</span> (highbpm == NULL) highbpm
+<a name="l00805"></a>00805                 = cpl_mask_get_data(cpl_image_get_bpm(im_high));
+<a name="l00806"></a>00806             highbpm[i] = CPL_BINARY_1;
+<a name="l00807"></a>00807         }
+<a name="l00808"></a>00808     }
+<a name="l00809"></a>00809 
+<a name="l00810"></a>00810     <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l00811"></a>00811 
+<a name="l00812"></a>00812 }
+<a name="l00813"></a>00813 
+<a name="l00814"></a>00814 
+<a name="l00815"></a>00815 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00863"></a>00863 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00864"></a>00864 
+<a name="l00865"></a>00865 cpl_error_code
+<a name="l00866"></a><a class="code" href="group__irplib__utils.html#ga3d1a791b5dc870770611c7dbf60d02df">00866</a> <a class="code" href="group__irplib__utils.html#ga3d1a791b5dc870770611c7dbf60d02df" title="Create a DFS product with one table from one or more (ASCII) file(s).">irplib_dfs_table_convert</a>(cpl_table               * <span class="keyword">self</span>,
+<a name="l00867"></a>00867                          cpl_frameset            * allframes,
+<a name="l00868"></a>00868                          <span class="keyword">const</span> cpl_frameset      * useframes,
+<a name="l00869"></a>00869                          <span class="keywordtype">int</span>                       maxlinelen,
+<a name="l00870"></a>00870                          <span class="keywordtype">char</span>                      commentchar,
+<a name="l00871"></a>00871                          <span class="keyword">const</span> <span class="keywordtype">char</span>              * product_name,
+<a name="l00872"></a>00872                          <span class="keyword">const</span> <span class="keywordtype">char</span>              * procatg,
+<a name="l00873"></a>00873                          <span class="keyword">const</span> cpl_parameterlist * parlist,
+<a name="l00874"></a>00874                          <span class="keyword">const</span> <span class="keywordtype">char</span>              * recipe_name,
+<a name="l00875"></a>00875                          <span class="keyword">const</span> cpl_propertylist  * mainlist,
+<a name="l00876"></a>00876                          <span class="keyword">const</span> cpl_propertylist  * extlist,
+<a name="l00877"></a>00877                          <span class="keyword">const</span> <span class="keywordtype">char</span>              * remregexp,
+<a name="l00878"></a>00878                          <span class="keyword">const</span> <span class="keywordtype">char</span>              * instrume,
+<a name="l00879"></a>00879                          <span class="keyword">const</span> <span class="keywordtype">char</span>              * pipe_id,
+<a name="l00880"></a>00880                          cpl_boolean (*table_set_row)
+<a name="l00881"></a>00881                          (cpl_table *, <span class="keyword">const</span> <span class="keywordtype">char</span> *, <span class="keywordtype">int</span>,
+<a name="l00882"></a>00882                           <span class="keyword">const</span> cpl_frame *,
+<a name="l00883"></a>00883                           <span class="keyword">const</span> cpl_parameterlist *),
+<a name="l00884"></a>00884                          cpl_error_code (*table_check)
+<a name="l00885"></a>00885                          (cpl_table *,
+<a name="l00886"></a>00886                           <span class="keyword">const</span> cpl_frameset *,
+<a name="l00887"></a>00887                           <span class="keyword">const</span> cpl_parameterlist *))
+<a name="l00888"></a>00888 {
+<a name="l00889"></a>00889 
+<a name="l00890"></a>00890     <span class="keyword">const</span> <span class="keywordtype">char</span>       * filename;
+<a name="l00891"></a>00891     cpl_propertylist * applist    = NULL;
+<a name="l00892"></a>00892     cpl_errorstate     prestate   = cpl_errorstate_get();
+<a name="l00893"></a>00893     cpl_error_code     error;
+<a name="l00894"></a>00894 
+<a name="l00895"></a>00895     cpl_ensure_code(<span class="keyword">self</span>         != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00896"></a>00896     cpl_ensure_code(allframes    != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00897"></a>00897     cpl_ensure_code(useframes    != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00898"></a>00898     cpl_ensure_code(procatg      != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00899"></a>00899     cpl_ensure_code(parlist      != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00900"></a>00900     cpl_ensure_code(recipe_name  != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00901"></a>00901     cpl_ensure_code(instrume     != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00902"></a>00902     cpl_ensure_code(pipe_id      != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00903"></a>00903 
+<a name="l00904"></a>00904     cpl_ensure_code(!<a class="code" href="group__irplib__utils.html#ga59a68df1795523d4f7653875bd9fc01d" title="Set the rows of a table with data from one or more (ASCII) files.">irplib_table_read_from_frameset</a>(<span class="keyword">self</span>, useframes,
+<a name="l00905"></a>00905                                                      maxlinelen,
+<a name="l00906"></a>00906                                                      commentchar,
+<a name="l00907"></a>00907                                                      parlist,
+<a name="l00908"></a>00908                                                      table_set_row),
+<a name="l00909"></a>00909                     cpl_error_get_code());
+<a name="l00910"></a>00910 
+<a name="l00911"></a>00911     <span class="keywordflow">if</span> (table_check != NULL && (table_check(<span class="keyword">self</span>, useframes, parlist) ||
+<a name="l00912"></a>00912                                 !cpl_errorstate_is_equal(prestate))) {
+<a name="l00913"></a>00913         <span class="keywordflow">return</span> cpl_error_set_message(cpl_func, cpl_error_get_code(),
+<a name="l00914"></a>00914                                      <span class="stringliteral">"Consistency check of table failed"</span>);
+<a name="l00915"></a>00915     }
+<a name="l00916"></a>00916 
+<a name="l00917"></a>00917     filename = product_name != NULL
+<a name="l00918"></a>00918         ? product_name : cpl_sprintf(<span class="stringliteral">"%s"</span> CPL_DFS_FITS, recipe_name);
+<a name="l00919"></a>00919 
+<a name="l00920"></a>00920     applist = mainlist == NULL
+<a name="l00921"></a>00921         ? cpl_propertylist_new() : cpl_propertylist_duplicate(mainlist);
+<a name="l00922"></a>00922 
+<a name="l00923"></a>00923     error = cpl_propertylist_update_string(applist, <span class="stringliteral">"INSTRUME"</span>, instrume);
+<a name="l00924"></a>00924 
+<a name="l00925"></a>00925     <span class="keywordflow">if</span> (!error)
+<a name="l00926"></a>00926         error = <a class="code" href="group__irplib__utils.html#ga62a91f8630af11164547c168660b2ade" title="Save a table as a DFS-compliant pipeline product.">irplib_dfs_save_table</a>(allframes, parlist, useframes, <span class="keyword">self</span>,
+<a name="l00927"></a>00927                                       extlist, recipe_name, procatg, applist,
+<a name="l00928"></a>00928                                       remregexp, pipe_id, filename);
+<a name="l00929"></a>00929 
+<a name="l00930"></a>00930     cpl_propertylist_delete(applist);
+<a name="l00931"></a>00931     <span class="keywordflow">if</span> (filename != product_name) cpl_free((<span class="keywordtype">char</span>*)filename);
+<a name="l00932"></a>00932 
+<a name="l00933"></a>00933     <span class="comment">/* Propagate the error, if any */</span>
+<a name="l00934"></a>00934     cpl_ensure_code(!error, error);
+<a name="l00935"></a>00935 
+<a name="l00936"></a>00936     <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l00937"></a>00937 
+<a name="l00938"></a>00938 }
+<a name="l00939"></a>00939 
+<a name="l00940"></a>00940 
+<a name="l00941"></a>00941 
+<a name="l00942"></a>00942 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00991"></a>00991 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00992"></a>00992 
+<a name="l00993"></a>00993 cpl_error_code
+<a name="l00994"></a><a class="code" href="group__irplib__utils.html#ga59a68df1795523d4f7653875bd9fc01d">00994</a> <a class="code" href="group__irplib__utils.html#ga59a68df1795523d4f7653875bd9fc01d" title="Set the rows of a table with data from one or more (ASCII) files.">irplib_table_read_from_frameset</a>(cpl_table               * <span class="keyword">self</span>,
+<a name="l00995"></a>00995                                 <span class="keyword">const</span> cpl_frameset      * useframes,
+<a name="l00996"></a>00996                                 <span class="keywordtype">int</span>                       maxlinelen,
+<a name="l00997"></a>00997                                 <span class="keywordtype">char</span>                      commentchar,
+<a name="l00998"></a>00998                                 <span class="keyword">const</span> cpl_parameterlist * parlist,
+<a name="l00999"></a>00999                                 cpl_boolean (*table_set_row)
+<a name="l01000"></a>01000                                 (cpl_table *, <span class="keyword">const</span> <span class="keywordtype">char</span> *, <span class="keywordtype">int</span>,
+<a name="l01001"></a>01001                                  <span class="keyword">const</span> cpl_frame *,
+<a name="l01002"></a>01002                                  <span class="keyword">const</span> cpl_parameterlist *))
+<a name="l01003"></a>01003 {
+<a name="l01004"></a>01004 
+<a name="l01005"></a>01005     <span class="keyword">const</span> cpl_frame  * rawframe;
+<a name="l01006"></a>01006     <span class="keywordtype">char</span>             * linebuffer = NULL;
+<a name="l01007"></a>01007     FILE             * stream     = NULL;
+<a name="l01008"></a>01008     <span class="keywordtype">int</span>                nfiles     = 0;
+<a name="l01009"></a>01009     <span class="keywordtype">int</span>                nrow       = cpl_table_get_nrow(<span class="keyword">self</span>);
+<a name="l01010"></a>01010     <span class="keywordtype">int</span>                irow       = 0;
+<a name="l01011"></a>01011     cpl_errorstate     prestate   = cpl_errorstate_get();
+<a name="l01012"></a>01012 
+<a name="l01013"></a>01013     cpl_ensure_code(<span class="keyword">self</span>         != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l01014"></a>01014     cpl_ensure_code(useframes    != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l01015"></a>01015     cpl_ensure_code(maxlinelen > 0, CPL_ERROR_ILLEGAL_INPUT);
+<a name="l01016"></a>01016     cpl_ensure_code(parlist      != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l01017"></a>01017     cpl_ensure_code(table_set_row != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l01018"></a>01018 
+<a name="l01019"></a>01019     linebuffer = cpl_malloc(maxlinelen);
+<a name="l01020"></a>01020 
+<a name="l01021"></a>01021     <span class="keywordflow">for</span> (rawframe = cpl_frameset_get_first_const(useframes);
+<a name="l01022"></a>01022          rawframe != NULL;
+<a name="l01023"></a>01023          rawframe = cpl_frameset_get_next_const(useframes), nfiles++) {
+<a name="l01024"></a>01024 
+<a name="l01025"></a>01025         <span class="keyword">const</span> <span class="keywordtype">char</span> * rawfile = cpl_frame_get_filename(rawframe);
+<a name="l01026"></a>01026         <span class="keyword">const</span> <span class="keywordtype">char</span> * done; <span class="comment">/* Indicate when the reading is done */</span>
+<a name="l01027"></a>01027         <span class="keyword">const</span> <span class="keywordtype">int</span> irowpre = irow;
+<a name="l01028"></a>01028         <span class="keywordtype">int</span> iirow = 0;
+<a name="l01029"></a>01029         <span class="keywordtype">int</span> ierror;
+<a name="l01030"></a>01030 
+<a name="l01031"></a>01031         <span class="keywordflow">if</span> (rawfile == NULL) <span class="keywordflow">break</span>; <span class="comment">/* Should not happen... */</span>
+<a name="l01032"></a>01032 
+<a name="l01033"></a>01033         stream = fopen(rawfile, <span class="stringliteral">"r"</span>);
+<a name="l01034"></a>01034 
+<a name="l01035"></a>01035         <span class="keywordflow">if</span> (stream == NULL) {
+<a name="l01036"></a>01036 <span class="preprocessor">#if defined CPL_HAVE_VA_ARGS && CPL_HAVE_VA_ARGS != 0</span>
+<a name="l01037"></a>01037 <span class="preprocessor"></span>            cpl_error_set_message(cpl_func, CPL_ERROR_FILE_IO, <span class="stringliteral">"Could not "</span>
+<a name="l01038"></a>01038                                   <span class="stringliteral">"open %s for reading"</span>, rawfile);
+<a name="l01039"></a>01039 <span class="preprocessor">#else</span>
+<a name="l01040"></a>01040 <span class="preprocessor"></span>            cpl_error_set_message(cpl_func, CPL_ERROR_FILE_IO, <span class="stringliteral">"Could not "</span>
+<a name="l01041"></a>01041                                   <span class="stringliteral">"open file for reading"</span>);
+<a name="l01042"></a>01042 <span class="preprocessor">#endif</span>
+<a name="l01043"></a>01043 <span class="preprocessor"></span>            <span class="keywordflow">break</span>;
+<a name="l01044"></a>01044         }
+<a name="l01045"></a>01045 
+<a name="l01046"></a>01046         <span class="keywordflow">for</span> (;(done = fgets(linebuffer, maxlinelen, stream)) != NULL; iirow++) {
+<a name="l01047"></a>01047 
+<a name="l01048"></a>01048             <span class="keywordflow">if</span> (linebuffer[0] != commentchar) {
+<a name="l01049"></a>01049                 cpl_boolean didset;
+<a name="l01050"></a>01050 <span class="preprocessor">#if defined CPL_HAVE_VA_ARGS && CPL_HAVE_VA_ARGS != 0</span>
+<a name="l01051"></a>01051 <span class="preprocessor"></span>                <span class="keyword">const</span> <span class="keywordtype">int</span> prerow = irow;
+<a name="l01052"></a>01052 <span class="preprocessor">#endif</span>
+<a name="l01053"></a>01053 <span class="preprocessor"></span>
+<a name="l01054"></a>01054                 <span class="keywordflow">if</span> (irow == nrow) {
+<a name="l01055"></a>01055                     nrow += nrow ? nrow : 1;
+<a name="l01056"></a>01056                     <span class="keywordflow">if</span> (cpl_table_set_size(<span class="keyword">self</span>, nrow)) <span class="keywordflow">break</span>;
+<a name="l01057"></a>01057                 }
+<a name="l01058"></a>01058 
+<a name="l01059"></a>01059                 didset = table_set_row(<span class="keyword">self</span>, linebuffer, irow, rawframe,
+<a name="l01060"></a>01060                                        parlist);
+<a name="l01061"></a>01061                 <span class="keywordflow">if</span> (didset) irow++;
+<a name="l01062"></a>01062 
+<a name="l01063"></a>01063                 <span class="keywordflow">if</span> (!cpl_errorstate_is_equal(prestate)) {
+<a name="l01064"></a>01064                     <span class="keywordflow">if</span> (didset)
+<a name="l01065"></a>01065 <span class="preprocessor">#if defined CPL_HAVE_VA_ARGS && CPL_HAVE_VA_ARGS != 0</span>
+<a name="l01066"></a>01066 <span class="preprocessor"></span>                        cpl_error_set_message(cpl_func, cpl_error_get_code(),
+<a name="l01067"></a>01067                                               <span class="stringliteral">"Failed to set table row %d "</span>
+<a name="l01068"></a>01068                                               <span class="stringliteral">"using line %d from %d. file %s"</span>,
+<a name="l01069"></a>01069                                               1+prerow, iirow+1,
+<a name="l01070"></a>01070                                               nfiles+1, rawfile);
+<a name="l01071"></a>01071                     <span class="keywordflow">else</span>
+<a name="l01072"></a>01072                         cpl_error_set_message(cpl_func, cpl_error_get_code(),
+<a name="l01073"></a>01073                                               <span class="stringliteral">"Failure with line %d from %d. "</span>
+<a name="l01074"></a>01074                                               <span class="stringliteral">"file %s"</span>, iirow+1,
+<a name="l01075"></a>01075                                               nfiles+1, rawfile);
+<a name="l01076"></a>01076 <span class="preprocessor">#else</span>
+<a name="l01077"></a>01077 <span class="preprocessor"></span>                        cpl_error_set_message(cpl_func, cpl_error_get_code(),
+<a name="l01078"></a>01078                                               <span class="stringliteral">"Failed to set table row"</span>
+<a name="l01079"></a>01079                                               <span class="stringliteral">"using catalogue line"</span>);
+<a name="l01080"></a>01080                     <span class="keywordflow">else</span>
+<a name="l01081"></a>01081                         cpl_error_set_message(cpl_func, cpl_error_get_code(),
+<a name="l01082"></a>01082                                               <span class="stringliteral">"Failure with catalogue line"</span>);
+<a name="l01083"></a>01083 <span class="preprocessor">#endif</span>
+<a name="l01084"></a>01084 <span class="preprocessor"></span>
+<a name="l01085"></a>01085                     <span class="keywordflow">break</span>;
+<a name="l01086"></a>01086                 }
+<a name="l01087"></a>01087             }
+<a name="l01088"></a>01088         }
+<a name="l01089"></a>01089         <span class="keywordflow">if</span> (done != NULL) <span class="keywordflow">break</span>;
+<a name="l01090"></a>01090 
+<a name="l01091"></a>01091         ierror = fclose(stream);
+<a name="l01092"></a>01092         stream = NULL;
+<a name="l01093"></a>01093         <span class="keywordflow">if</span> (ierror) <span class="keywordflow">break</span>;
+<a name="l01094"></a>01094 
+<a name="l01095"></a>01095 
+<a name="l01096"></a>01096         <span class="keywordflow">if</span> (irow == irowpre)
+<a name="l01097"></a>01097             cpl_msg_warning(cpl_func, <span class="stringliteral">"No usable lines in the %d. file: %s"</span>,
+<a name="l01098"></a>01098                             1+nfiles, rawfile);
+<a name="l01099"></a>01099     }
+<a name="l01100"></a>01100 
+<a name="l01101"></a>01101     cpl_free(linebuffer);
+<a name="l01102"></a>01102     <span class="keywordflow">if</span> (stream != NULL) fclose(stream);
+<a name="l01103"></a>01103 
+<a name="l01104"></a>01104     <span class="comment">/* Check for premature end */</span>
+<a name="l01105"></a>01105     cpl_ensure_code(rawframe == NULL, cpl_error_get_code());
+<a name="l01106"></a>01106 
+<a name="l01107"></a>01107     <span class="keywordflow">if</span> (irow == 0) {
+<a name="l01108"></a>01108 <span class="preprocessor">#if defined CPL_HAVE_VA_ARGS && CPL_HAVE_VA_ARGS != 0</span>
+<a name="l01109"></a>01109 <span class="preprocessor"></span>        <span class="keywordflow">return</span> cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
+<a name="l01110"></a>01110                                      <span class="stringliteral">"No usable lines in the %d input "</span>
+<a name="l01111"></a>01111                                      <span class="stringliteral">"frame(s)"</span>, nfiles);
+<a name="l01112"></a>01112 <span class="preprocessor">#else</span>
+<a name="l01113"></a>01113 <span class="preprocessor"></span>        <span class="keywordflow">return</span> cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
+<a name="l01114"></a>01114                                      <span class="stringliteral">"No usable lines in the input frame(s)"</span>);
+<a name="l01115"></a>01115 <span class="preprocessor">#endif</span>
+<a name="l01116"></a>01116 <span class="preprocessor"></span>    }
+<a name="l01117"></a>01117 
+<a name="l01118"></a>01118     <span class="comment">/* Resize the table to the actual number of rows set */</span>
+<a name="l01119"></a>01119     cpl_ensure_code(!cpl_table_set_size(<span class="keyword">self</span>, irow), cpl_error_get_code());
+<a name="l01120"></a>01120 
+<a name="l01121"></a>01121     <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l01122"></a>01122 }
+<a name="l01123"></a>01123 
+<a name="l01124"></a>01124 
+<a name="l01125"></a>01125 
+<a name="l01126"></a>01126 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01138"></a>01138 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01139"></a><a class="code" href="group__irplib__utils.html#gaf9d392144014e2363054bc3f83c8e47e">01139</a> <span class="keywordtype">void</span> <a class="code" href="group__irplib__utils.html#gaf9d392144014e2363054bc3f83c8e47e" title="Reset IRPLIB state.">irplib_reset</a>(<span class="keywordtype">void</span>)
+<a name="l01140"></a>01140 {
+<a name="l01141"></a>01141     <span class="keywordflow">return</span>;
+<a name="l01142"></a>01142 }
+<a name="l01143"></a>01143 
+<a name="l01144"></a>01144 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01151"></a>01151 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01152"></a><a class="code" href="group__irplib__utils.html#gae13f0d6b24ade506a99ac9c4bb09efde">01152</a> <span class="keywordtype">int</span> <a class="code" href="group__irplib__utils.html#gae13f0d6b24ade506a99ac9c4bb09efde" title="Comparison function to identify different input frames.">irplib_compare_tags</a>(
+<a name="l01153"></a>01153         cpl_frame   *   frame1,
+<a name="l01154"></a>01154         cpl_frame   *   frame2)
+<a name="l01155"></a>01155 {
+<a name="l01156"></a>01156     <span class="keywordtype">char</span>            *   v1 ;
+<a name="l01157"></a>01157     <span class="keywordtype">char</span>            *   v2 ;
+<a name="l01158"></a>01158 
+<a name="l01159"></a>01159     <span class="comment">/* Test entries */</span>
+<a name="l01160"></a>01160     <span class="keywordflow">if</span> (frame1==NULL || frame2==NULL) <span class="keywordflow">return</span> -1 ;
+<a name="l01161"></a>01161 
+<a name="l01162"></a>01162     <span class="comment">/* Get the tags */</span>
+<a name="l01163"></a>01163     <span class="keywordflow">if</span> ((v1 = (<span class="keywordtype">char</span>*)cpl_frame_get_tag(frame1)) == NULL) <span class="keywordflow">return</span> -1 ;
+<a name="l01164"></a>01164     <span class="keywordflow">if</span> ((v2 = (<span class="keywordtype">char</span>*)cpl_frame_get_tag(frame2)) == NULL) <span class="keywordflow">return</span> -1 ;
+<a name="l01165"></a>01165 
+<a name="l01166"></a>01166     <span class="comment">/* Compare the tags */</span>
+<a name="l01167"></a>01167     <span class="keywordflow">if</span> (strcmp(v1, v2)) <span class="keywordflow">return</span> 0 ;
+<a name="l01168"></a>01168     <span class="keywordflow">else</span> <span class="keywordflow">return</span> 1 ;
+<a name="l01169"></a>01169 }
+<a name="l01170"></a>01170 
+<a name="l01171"></a>01171 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01187"></a>01187 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01188"></a><a class="code" href="group__irplib__utils.html#ga9fe4dca85dee68061114e26fdc72a134">01188</a> <span class="keyword">const</span> <span class="keywordtype">char</span> * <a class="code" href="group__irplib__utils.html#ga9fe4dca85dee68061114e26fdc72a134" title="Find the filename with the given tag in a frame set.">irplib_frameset_find_file</a>(<span class="keyword">const</span> cpl_frameset * <span class="keyword">self</span>,
+<a name="l01189"></a>01189                                       <span class="keyword">const</span> <span class="keywordtype">char</span> * tag)
+<a name="l01190"></a>01190 {
+<a name="l01191"></a>01191     <span class="keyword">const</span> cpl_frame * frame = cpl_frameset_find_const(<span class="keyword">self</span>, tag);
+<a name="l01192"></a>01192 
+<a name="l01193"></a>01193 
+<a name="l01194"></a>01194     cpl_ensure(!cpl_error_get_code(), cpl_error_get_code(), NULL);
+<a name="l01195"></a>01195 
+<a name="l01196"></a>01196     <span class="keywordflow">if</span> (frame == NULL) <span class="keywordflow">return</span> NULL;
+<a name="l01197"></a>01197 
+<a name="l01198"></a>01198     <span class="keywordflow">if</span> (cpl_frameset_find_const(<span class="keyword">self</span>, NULL))
+<a name="l01199"></a>01199         cpl_msg_warning(cpl_func,
+<a name="l01200"></a>01200             <span class="stringliteral">"Frameset has more than one file with tag: %s"</span>,
+<a name="l01201"></a>01201                         tag);
+<a name="l01202"></a>01202 
+<a name="l01203"></a>01203     <span class="keywordflow">return</span> cpl_frame_get_filename(frame);
+<a name="l01204"></a>01204 
+<a name="l01205"></a>01205 }
+<a name="l01206"></a>01206 
+<a name="l01207"></a>01207 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01217"></a>01217 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01218"></a>01218 <span class="keyword">const</span>
+<a name="l01219"></a><a class="code" href="group__irplib__utils.html#ga5b20a00f315410b49b1db1dd2417fe68">01219</a> cpl_frame * <a class="code" href="group__irplib__utils.html#ga5b20a00f315410b49b1db1dd2417fe68" title="Find the first frame belonging to the given group.">irplib_frameset_get_first_from_group</a>(<span class="keyword">const</span> cpl_frameset * <span class="keyword">self</span>,
+<a name="l01220"></a>01220                                                  cpl_frame_group      group)
+<a name="l01221"></a>01221 {
+<a name="l01222"></a>01222     <span class="keyword">const</span> cpl_frame * frame;
+<a name="l01223"></a>01223 
+<a name="l01224"></a>01224     cpl_ensure(<span class="keyword">self</span> != NULL, CPL_ERROR_NULL_INPUT, NULL);
+<a name="l01225"></a>01225 
+<a name="l01226"></a>01226     <span class="keywordflow">for</span> (frame = cpl_frameset_get_first_const(<span class="keyword">self</span>); frame != NULL ;
+<a name="l01227"></a>01227          frame = cpl_frameset_get_next_const(<span class="keyword">self</span>)) {
+<a name="l01228"></a>01228         <span class="keywordflow">if</span> (cpl_frame_get_group(frame) == group) <span class="keywordflow">break</span>;
+<a name="l01229"></a>01229     }
+<a name="l01230"></a>01230     <span class="keywordflow">return</span> frame;
+<a name="l01231"></a>01231 }
+<a name="l01232"></a>01232 
+<a name="l01233"></a>01233 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01252"></a>01252 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01253"></a><a class="code" href="group__irplib__utils.html#gac568c70a57ef8610f5fedc9f1943a3a1">01253</a> cpl_error_code <a class="code" href="group__irplib__utils.html#gac568c70a57ef8610f5fedc9f1943a3a1" title="Find the aperture(s) with the greatest flux.">irplib_apertures_find_max_flux</a>(<span class="keyword">const</span> cpl_apertures * <span class="keyword">self</span>,
+<a name="l01254"></a>01254                                               <span class="keywordtype">int</span> * ind, <span class="keywordtype">int</span> nfind)
+<a name="l01255"></a>01255 {
+<a name="l01256"></a>01256     <span class="keyword">const</span> <span class="keywordtype">int</span>    nsize = cpl_apertures_get_size(<span class="keyword">self</span>);
+<a name="l01257"></a>01257     <span class="keywordtype">int</span>          ifind;
+<a name="l01258"></a>01258 
+<a name="l01259"></a>01259 
+<a name="l01260"></a>01260     cpl_ensure_code(nsize > 0,      cpl_error_get_code());
+<a name="l01261"></a>01261     cpl_ensure_code(ind,          CPL_ERROR_NULL_INPUT);
+<a name="l01262"></a>01262     cpl_ensure_code(nfind > 0,      CPL_ERROR_ILLEGAL_INPUT);
+<a name="l01263"></a>01263     cpl_ensure_code(nfind <= nsize, CPL_ERROR_ILLEGAL_INPUT);
+<a name="l01264"></a>01264 
+<a name="l01265"></a>01265     <span class="keywordflow">for</span> (ifind=0; ifind < nfind; ifind++) {
+<a name="l01266"></a>01266         <span class="keywordtype">double</span> maxflux = -1;
+<a name="l01267"></a>01267         <span class="keywordtype">int</span> maxind = -1;
+<a name="l01268"></a>01268         <span class="keywordtype">int</span> i;
+<a name="l01269"></a>01269         <span class="keywordflow">for</span> (i=1; i <= nsize; i++) {
+<a name="l01270"></a>01270             <span class="keywordtype">int</span> k;
+<a name="l01271"></a>01271 
+<a name="l01272"></a>01272             <span class="comment">/* The flux has to be the highest among those not already found */</span>
+<a name="l01273"></a>01273             <span class="keywordflow">for</span> (k=0; k < ifind; k++) <span class="keywordflow">if</span> (ind[k] == i) <span class="keywordflow">break</span>;
+<a name="l01274"></a>01274 
+<a name="l01275"></a>01275             <span class="keywordflow">if</span> (k == ifind) {
+<a name="l01276"></a>01276                 <span class="comment">/* i has not been inserted into ind */</span>
+<a name="l01277"></a>01277                 <span class="keyword">const</span> <span class="keywordtype">double</span> flux = cpl_apertures_get_flux(<span class="keyword">self</span>, i);
+<a name="l01278"></a>01278 
+<a name="l01279"></a>01279                 <span class="keywordflow">if</span> (maxind < 0 || flux > maxflux) {
+<a name="l01280"></a>01280                     maxind = i;
+<a name="l01281"></a>01281                     maxflux = flux;
+<a name="l01282"></a>01282                 }
+<a name="l01283"></a>01283             }
+<a name="l01284"></a>01284         }
+<a name="l01285"></a>01285         ind[ifind] = maxind;
+<a name="l01286"></a>01286     }
+<a name="l01287"></a>01287 
+<a name="l01288"></a>01288     <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l01289"></a>01289 
+<a name="l01290"></a>01290 }
+<a name="l01291"></a>01291 
+<a name="l01292"></a>01292 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01296"></a>01296 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01297"></a><a class="code" href="group__irplib__utils.html#ga09a11edf52efa78ddafce0bb4fa3b71f">01297</a> <span class="keywordtype">int</span> <a class="code" href="group__irplib__utils.html#ga09a11edf52efa78ddafce0bb4fa3b71f" title="portable isinf">irplib_isinf</a>(<span class="keywordtype">double</span> value)
+<a name="l01298"></a>01298 {
+<a name="l01299"></a>01299 <span class="preprocessor">#if defined HAVE_ISINF && HAVE_ISINF</span>
+<a name="l01300"></a>01300 <span class="preprocessor"></span>    <span class="keywordflow">return</span> isinf(value);
+<a name="l01301"></a>01301 <span class="preprocessor">#else</span>
+<a name="l01302"></a>01302 <span class="preprocessor"></span>    <span class="keywordflow">return</span> value != 0 && value == 2 * value;
+<a name="l01303"></a>01303 <span class="preprocessor">#endif</span>
+<a name="l01304"></a>01304 <span class="preprocessor"></span>}
+<a name="l01305"></a>01305 
+<a name="l01306"></a>01306 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01310"></a>01310 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01311"></a><a class="code" href="group__irplib__utils.html#ga804bfc739b5d55f9797ab881b1034ae4">01311</a> <span class="keywordtype">int</span> <a class="code" href="group__irplib__utils.html#ga804bfc739b5d55f9797ab881b1034ae4" title="portable isnan">irplib_isnan</a>(<span class="keywordtype">double</span> value)
+<a name="l01312"></a>01312 {
+<a name="l01313"></a>01313 <span class="preprocessor">#if defined HAVE_ISNAN && HAVE_ISNAN</span>
+<a name="l01314"></a>01314 <span class="preprocessor"></span>    <span class="keywordflow">return</span> isnan(value);
+<a name="l01315"></a>01315 <span class="preprocessor">#else</span>
+<a name="l01316"></a>01316 <span class="preprocessor"></span>    <span class="keywordflow">return</span> value != value;
+<a name="l01317"></a>01317 <span class="preprocessor">#endif</span>
+<a name="l01318"></a>01318 <span class="preprocessor"></span>}
+<a name="l01319"></a>01319 
+<a name="l01320"></a>01320 
+<a name="l01321"></a>01321 
+<a name="l01322"></a>01322 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01333"></a>01333 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01334"></a><a class="code" href="group__irplib__utils.html#ga2dda571b0bbb3f7bf170210b38f95627">01334</a> <span class="keywordtype">void</span> <a class="code" href="group__irplib__utils.html#ga2dda571b0bbb3f7bf170210b38f95627" title="Dump a single CPL error.">irplib_errorstate_warning</a>(<span class="keywordtype">unsigned</span> <span class="keyword">self</span>, <span class="keywordtype">unsigned</span> first, <span class="keywordtype">unsigned</span> last)
+<a name="l01335"></a>01335 {
+<a name="l01336"></a>01336 
+<a name="l01337"></a>01337     <span class="keyword">const</span> cpl_boolean is_reverse = first > last ? CPL_TRUE : CPL_FALSE;
+<a name="l01338"></a>01338     <span class="keyword">const</span> <span class="keywordtype">unsigned</span>    newest     = is_reverse ? first : last;
+<a name="l01339"></a>01339     <span class="keyword">const</span> <span class="keywordtype">unsigned</span>    oldest     = is_reverse ? last : first;
+<a name="l01340"></a>01340     <span class="keyword">const</span> <span class="keywordtype">char</span>      * revmsg     = is_reverse ? <span class="stringliteral">" in reverse order"</span> : <span class="stringliteral">""</span>;
+<a name="l01341"></a>01341 
+<a name="l01342"></a>01342 
+<a name="l01343"></a>01343     assert( oldest <= <span class="keyword">self</span> );
+<a name="l01344"></a>01344     assert( newest >= <span class="keyword">self</span> );
+<a name="l01345"></a>01345 
+<a name="l01346"></a>01346     <span class="keywordflow">if</span> (newest == 0) {
+<a name="l01347"></a>01347         cpl_msg_info(cpl_func, <span class="stringliteral">"No error(s) to dump"</span>);
+<a name="l01348"></a>01348         assert( oldest == 0);
+<a name="l01349"></a>01349     } <span class="keywordflow">else</span> {
+<a name="l01350"></a>01350         assert( oldest > 0);
+<a name="l01351"></a>01351         assert( newest >= oldest);
+<a name="l01352"></a>01352         <span class="keywordflow">if</span> (<span class="keyword">self</span> == first) {
+<a name="l01353"></a>01353             <span class="keywordflow">if</span> (oldest == 1) {
+<a name="l01354"></a>01354                 cpl_msg_warning(cpl_func, <span class="stringliteral">"Dumping all %u error(s)%s:"</span>, newest,
+<a name="l01355"></a>01355                               revmsg);
+<a name="l01356"></a>01356             } <span class="keywordflow">else</span> {
+<a name="l01357"></a>01357                 cpl_msg_warning(cpl_func, <span class="stringliteral">"Dumping the %u most recent error(s) "</span>
+<a name="l01358"></a>01358                               <span class="stringliteral">"out of a total of %u errors%s:"</span>,
+<a name="l01359"></a>01359                               newest - oldest + 1, newest, revmsg);
+<a name="l01360"></a>01360             }
+<a name="l01361"></a>01361             cpl_msg_indent_more();
+<a name="l01362"></a>01362         }
+<a name="l01363"></a>01363 
+<a name="l01364"></a>01364         cpl_msg_warning(cpl_func, <span class="stringliteral">"[%u/%u] '%s' (%u) at %s"</span>, <span class="keyword">self</span>, newest,
+<a name="l01365"></a>01365                       cpl_error_get_message(), cpl_error_get_code(),
+<a name="l01366"></a>01366                       cpl_error_get_where());
+<a name="l01367"></a>01367 
+<a name="l01368"></a>01368         <span class="keywordflow">if</span> (<span class="keyword">self</span> == last) cpl_msg_indent_less();
+<a name="l01369"></a>01369     }
+<a name="l01370"></a>01370 }
+<a name="l01371"></a>01371 
+<a name="l01372"></a>01372 
+<a name="l01377"></a>01377 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01388"></a>01388 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01389"></a>01389 <span class="keyword">inline</span> <span class="keyword">static</span>
+<a name="l01390"></a>01390 <span class="keywordtype">double</span> irplib_data_get_double(<span class="keyword">const</span> <span class="keywordtype">void</span> * <span class="keyword">self</span>, cpl_type type, <span class="keywordtype">int</span> i)
+<a name="l01391"></a>01391 {
+<a name="l01392"></a>01392 
+<a name="l01393"></a>01393     <span class="keywordtype">double</span> value;
+<a name="l01394"></a>01394 
+<a name="l01395"></a>01395 
+<a name="l01396"></a>01396     <span class="keywordflow">switch</span> (type) {
+<a name="l01397"></a>01397     <span class="keywordflow">case</span> CPL_TYPE_FLOAT:
+<a name="l01398"></a>01398         {
+<a name="l01399"></a>01399             <span class="keyword">const</span> <span class="keywordtype">float</span> * pself = (<span class="keyword">const</span> <span class="keywordtype">float</span>*)<span class="keyword">self</span>;
+<a name="l01400"></a>01400             value = (double)pself[i];
+<a name="l01401"></a>01401             <span class="keywordflow">break</span>;
+<a name="l01402"></a>01402         }
+<a name="l01403"></a>01403     <span class="keywordflow">case</span> CPL_TYPE_INT:
+<a name="l01404"></a>01404         {
+<a name="l01405"></a>01405             <span class="keyword">const</span> <span class="keywordtype">int</span> * pself = (<span class="keyword">const</span> <span class="keywordtype">int</span>*)<span class="keyword">self</span>;
+<a name="l01406"></a>01406             value = (double)pself[i];
+<a name="l01407"></a>01407             <span class="keywordflow">break</span>;
+<a name="l01408"></a>01408         }
+<a name="l01409"></a>01409     <span class="keywordflow">default</span>: <span class="comment">/* case CPL_TYPE_DOUBLE */</span>
+<a name="l01410"></a>01410         {
+<a name="l01411"></a>01411             <span class="keyword">const</span> <span class="keywordtype">double</span> * pself = (<span class="keyword">const</span> <span class="keywordtype">double</span>*)<span class="keyword">self</span>;
+<a name="l01412"></a>01412             value = pself[i];
+<a name="l01413"></a>01413             <span class="keywordflow">break</span>;
+<a name="l01414"></a>01414         }
+<a name="l01415"></a>01415     }
+<a name="l01416"></a>01416 
+<a name="l01417"></a>01417     <span class="keywordflow">return</span> value;
+<a name="l01418"></a>01418 
+<a name="l01419"></a>01419 }
+<a name="l01420"></a>01420 
+<a name="l01421"></a>01421 
+<a name="l01422"></a>01422 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01433"></a>01433 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01434"></a>01434 <span class="keyword">inline</span> <span class="keyword">static</span>
+<a name="l01435"></a>01435 <span class="keywordtype">void</span> irplib_data_set_double(<span class="keywordtype">void</span> * <span class="keyword">self</span>, cpl_type type, <span class="keywordtype">int</span> i, <span class="keywordtype">double</span> value)
+<a name="l01436"></a>01436 {
+<a name="l01437"></a>01437 
+<a name="l01438"></a>01438     <span class="keywordflow">switch</span> (type) {
+<a name="l01439"></a>01439     <span class="keywordflow">case</span> CPL_TYPE_FLOAT:
+<a name="l01440"></a>01440         {
+<a name="l01441"></a>01441             <span class="keywordtype">float</span> * pself = (<span class="keywordtype">float</span>*)<span class="keyword">self</span>;
+<a name="l01442"></a>01442             pself[i] = (float)value;
+<a name="l01443"></a>01443             <span class="keywordflow">break</span>;
+<a name="l01444"></a>01444         }
+<a name="l01445"></a>01445     <span class="keywordflow">case</span> CPL_TYPE_INT:
+<a name="l01446"></a>01446         {
+<a name="l01447"></a>01447             <span class="keywordtype">int</span> * pself = (<span class="keywordtype">int</span>*)<span class="keyword">self</span>;
+<a name="l01448"></a>01448             pself[i] = (int)value;
+<a name="l01449"></a>01449             <span class="keywordflow">break</span>;
+<a name="l01450"></a>01450         }
+<a name="l01451"></a>01451     <span class="keywordflow">default</span>: <span class="comment">/* case CPL_TYPE_DOUBLE */</span>
+<a name="l01452"></a>01452         {
+<a name="l01453"></a>01453             <span class="keywordtype">double</span> * pself = (<span class="keywordtype">double</span>*)<span class="keyword">self</span>;
+<a name="l01454"></a>01454             pself[i] = value;
+<a name="l01455"></a>01455             <span class="keywordflow">break</span>;
+<a name="l01456"></a>01456         }
+<a name="l01457"></a>01457     }
+<a name="l01458"></a>01458 }
+<a name="l01459"></a>01459 
+<a name="l01460"></a>01460 
+<a name="l01461"></a>01461 
+<a name="l01462"></a>01462 
+<a name="l01463"></a>01463 
+<a name="l01464"></a>01464 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01475"></a>01475 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01476"></a>01476 <span class="keyword">static</span>
+<a name="l01477"></a>01477 <span class="keywordtype">void</span> irplib_errorstate_dump_one_level(<span class="keywordtype">void</span> (*messenger)(<span class="keyword">const</span> <span class="keywordtype">char</span> *,
+<a name="l01478"></a>01478                                                         <span class="keyword">const</span> <span class="keywordtype">char</span> *, ...),
+<a name="l01479"></a>01479                                       <span class="keywordtype">unsigned</span> <span class="keyword">self</span>, <span class="keywordtype">unsigned</span> first,
+<a name="l01480"></a>01480                                       <span class="keywordtype">unsigned</span> last)
+<a name="l01481"></a>01481 {
+<a name="l01482"></a>01482 
+<a name="l01483"></a>01483     <span class="keyword">const</span> cpl_boolean is_reverse = first > last ? CPL_TRUE : CPL_FALSE;
+<a name="l01484"></a>01484     <span class="keyword">const</span> <span class="keywordtype">unsigned</span>    newest     = is_reverse ? first : last;
+<a name="l01485"></a>01485     <span class="keyword">const</span> <span class="keywordtype">unsigned</span>    oldest     = is_reverse ? last : first;
+<a name="l01486"></a>01486     <span class="keyword">const</span> <span class="keywordtype">char</span>      * revmsg     = is_reverse ? <span class="stringliteral">" in reverse order"</span> : <span class="stringliteral">""</span>;
+<a name="l01487"></a>01487 
+<a name="l01488"></a>01488 
+<a name="l01489"></a>01489     <span class="comment">/*</span>
+<a name="l01490"></a>01490 <span class="comment">    cx_assert( messenger != NULL );</span>
+<a name="l01491"></a>01491 <span class="comment">    cx_assert( oldest <= self );</span>
+<a name="l01492"></a>01492 <span class="comment">    cx_assert( newest >= self );</span>
+<a name="l01493"></a>01493 <span class="comment">    */</span>
+<a name="l01494"></a>01494 
+<a name="l01495"></a>01495     <span class="keywordflow">if</span> (newest == 0) {
+<a name="l01496"></a>01496         messenger(cpl_func, <span class="stringliteral">"No error(s) to dump"</span>);
+<a name="l01497"></a>01497         <span class="comment">/* cx_assert( oldest == 0); */</span>
+<a name="l01498"></a>01498     } <span class="keywordflow">else</span> {
+<a name="l01499"></a>01499         <span class="comment">/*</span>
+<a name="l01500"></a>01500 <span class="comment">          cx_assert( oldest > 0);</span>
+<a name="l01501"></a>01501 <span class="comment">          cx_assert( newest >= oldest);</span>
+<a name="l01502"></a>01502 <span class="comment">        */</span>
+<a name="l01503"></a>01503         <span class="keywordflow">if</span> (<span class="keyword">self</span> == first) {
+<a name="l01504"></a>01504             <span class="keywordflow">if</span> (oldest == 1) {
+<a name="l01505"></a>01505                 messenger(cpl_func, <span class="stringliteral">"Dumping all %u error(s)%s:"</span>, newest,
+<a name="l01506"></a>01506                           revmsg);
+<a name="l01507"></a>01507             } <span class="keywordflow">else</span> {
+<a name="l01508"></a>01508                 messenger(cpl_func, <span class="stringliteral">"Dumping the %u most recent error(s) "</span>
+<a name="l01509"></a>01509                           <span class="stringliteral">"out of a total of %u errors%s:"</span>,
+<a name="l01510"></a>01510                           newest - oldest + 1, newest, revmsg);
+<a name="l01511"></a>01511             }
+<a name="l01512"></a>01512             cpl_msg_indent_more();
+<a name="l01513"></a>01513         }
+<a name="l01514"></a>01514 
+<a name="l01515"></a>01515         messenger(cpl_func, <span class="stringliteral">"[%u/%u] '%s' (%u) at %s"</span>, <span class="keyword">self</span>, newest,
+<a name="l01516"></a>01516                   cpl_error_get_message(), cpl_error_get_code(),
+<a name="l01517"></a>01517                   cpl_error_get_where());
+<a name="l01518"></a>01518 
+<a name="l01519"></a>01519         <span class="keywordflow">if</span> (<span class="keyword">self</span> == last) cpl_msg_indent_less();
+<a name="l01520"></a>01520     }
+<a name="l01521"></a>01521 }
+<a name="l01522"></a>01522 
+<a name="l01523"></a>01523 cpl_polynomial * irplib_polynomial_fit_1d_create_chiq(
+<a name="l01524"></a>01524         <span class="keyword">const</span> cpl_vector    *   x_pos,
+<a name="l01525"></a>01525         <span class="keyword">const</span> cpl_vector    *   values,
+<a name="l01526"></a>01526         <span class="keywordtype">int</span>                     degree,
+<a name="l01527"></a>01527         <span class="keywordtype">double</span>              *   rechisq
+<a name="l01528"></a>01528         )
+<a name="l01529"></a>01529  {
+<a name="l01530"></a>01530     <span class="keywordflow">return</span> irplib_polynomial_fit_1d_create_common(x_pos, values, degree, NULL, rechisq);
+<a name="l01531"></a>01531  }
+<a name="l01532"></a>01532 cpl_polynomial * irplib_polynomial_fit_1d_create(
+<a name="l01533"></a>01533         <span class="keyword">const</span> cpl_vector    *   x_pos,
+<a name="l01534"></a>01534         <span class="keyword">const</span> cpl_vector    *   values,
+<a name="l01535"></a>01535         <span class="keywordtype">int</span>                     degree,
+<a name="l01536"></a>01536         <span class="keywordtype">double</span>              *   mse
+<a name="l01537"></a>01537         )
+<a name="l01538"></a>01538 {
+<a name="l01539"></a>01539 
+<a name="l01540"></a>01540     <span class="keywordflow">return</span> irplib_polynomial_fit_1d_create_common(x_pos, values, degree, mse, NULL);
+<a name="l01541"></a>01541 }
+<a name="l01542"></a>01542 <span class="keyword">static</span> cpl_polynomial * irplib_polynomial_fit_1d_create_common(
+<a name="l01543"></a>01543         <span class="keyword">const</span> cpl_vector    *   x_pos,
+<a name="l01544"></a>01544         <span class="keyword">const</span> cpl_vector    *   values,
+<a name="l01545"></a>01545         <span class="keywordtype">int</span>                     degree,
+<a name="l01546"></a>01546         <span class="keywordtype">double</span>              *   mse,
+<a name="l01547"></a>01547         <span class="keywordtype">double</span>              *  rechisq
+<a name="l01548"></a>01548         )
+<a name="l01549"></a>01549 {
+<a name="l01550"></a>01550     cpl_polynomial * fit1d = NULL;
+<a name="l01551"></a>01551     cpl_size loc_degree = (cpl_size)degree ;
+<a name="l01552"></a>01552     <span class="keywordtype">int</span> x_size = 0;
+<a name="l01553"></a>01553     fit1d = cpl_polynomial_new(1);
+<a name="l01554"></a>01554     x_size = cpl_vector_get_size(x_pos);    
+<a name="l01555"></a>01555     <span class="keywordflow">if</span>(fit1d != NULL && x_size > 1)
+<a name="l01556"></a>01556     {
+<a name="l01557"></a>01557       cpl_matrix     * samppos = NULL;
+<a name="l01558"></a>01558       cpl_vector     * fitresidual = NULL;
+<a name="l01559"></a>01559         cpl_ensure(!cpl_error_get_code(), cpl_error_get_code(), NULL);
+<a name="l01560"></a>01560         samppos = cpl_matrix_wrap(1, x_size,
+<a name="l01561"></a>01561                                                    (<span class="keywordtype">double</span>*)cpl_vector_get_data_const(x_pos));
+<a name="l01562"></a>01562         cpl_ensure(!cpl_error_get_code(), cpl_error_get_code(), NULL);
+<a name="l01563"></a>01563         fitresidual = cpl_vector_new(x_size);
+<a name="l01564"></a>01564         cpl_ensure(!cpl_error_get_code(), cpl_error_get_code(), NULL);
+<a name="l01565"></a>01565         cpl_polynomial_fit(fit1d, samppos, NULL, values, NULL,
+<a name="l01566"></a>01566                            CPL_FALSE, NULL, &loc_degree);
+<a name="l01567"></a>01567         cpl_ensure(!cpl_error_get_code(), cpl_error_get_code(), NULL);
+<a name="l01568"></a>01568         cpl_vector_fill_polynomial_fit_residual(fitresidual, values, NULL, fit1d,
+<a name="l01569"></a>01569                                                 samppos, rechisq);
+<a name="l01570"></a>01570         cpl_ensure(!cpl_error_get_code(), cpl_error_get_code(), NULL);
+<a name="l01571"></a>01571         <span class="keywordflow">if</span> (mse)
+<a name="l01572"></a>01572         {
+<a name="l01573"></a>01573             *mse = cpl_vector_product(fitresidual, fitresidual)
+<a name="l01574"></a>01574                 / cpl_vector_get_size(fitresidual);
+<a name="l01575"></a>01575         }
+<a name="l01576"></a>01576         cpl_matrix_unwrap(samppos);
+<a name="l01577"></a>01577         cpl_vector_delete(fitresidual);
+<a name="l01578"></a>01578     }
+<a name="l01579"></a>01579     <span class="keywordflow">return</span> fit1d;
+<a name="l01580"></a>01580 }
+<a name="l01581"></a>01581 
+<a name="l01582"></a>01582 <span class="keyword">static</span> <span class="keywordtype">void</span> quicksort(<span class="keywordtype">int</span>* iindex, <span class="keywordtype">double</span>* exptime, <span class="keywordtype">int</span> left, <span class="keywordtype">int</span> right)
+<a name="l01583"></a>01583 {
+<a name="l01584"></a>01584     <span class="keywordtype">int</span> i = left;
+<a name="l01585"></a>01585     <span class="keywordtype">int</span> j = right;
+<a name="l01586"></a>01586     <span class="keywordtype">int</span> pivot = (i + j) / 2;
+<a name="l01587"></a>01587     <span class="keywordtype">double</span> index_value = exptime[pivot];
+<a name="l01588"></a>01588     <span class="keywordflow">do</span>
+<a name="l01589"></a>01589     {
+<a name="l01590"></a>01590         <span class="keywordflow">while</span>(exptime[i] < index_value) i++;
+<a name="l01591"></a>01591         <span class="keywordflow">while</span>(exptime[j] > index_value) j--;
+<a name="l01592"></a>01592         <span class="keywordflow">if</span> (i <= j)
+<a name="l01593"></a>01593         {
+<a name="l01594"></a>01594             <span class="keywordflow">if</span>(i < j)
+<a name="l01595"></a>01595             {
+<a name="l01596"></a>01596                 <span class="keywordtype">int</span> tmp = iindex[i];
+<a name="l01597"></a>01597                 <span class="keywordtype">double</span> dtmp = exptime[i];
+<a name="l01598"></a>01598                 iindex[i]=iindex[j];
+<a name="l01599"></a>01599                 iindex[j]=tmp;
+<a name="l01600"></a>01600                 exptime[i] = exptime[j];
+<a name="l01601"></a>01601                 exptime[j] = dtmp;
+<a name="l01602"></a>01602             }
+<a name="l01603"></a>01603             i++;
+<a name="l01604"></a>01604             j--;
+<a name="l01605"></a>01605         }
+<a name="l01606"></a>01606     } <span class="keywordflow">while</span> (i <= j);
+<a name="l01607"></a>01607 
+<a name="l01608"></a>01608     <span class="keywordflow">if</span> (i < right)
+<a name="l01609"></a>01609     {
+<a name="l01610"></a>01610         quicksort(iindex, exptime, i, right);
+<a name="l01611"></a>01611     }
+<a name="l01612"></a>01612     <span class="keywordflow">if</span> (left < j)
+<a name="l01613"></a>01613     {
+<a name="l01614"></a>01614         quicksort(iindex, exptime,left, j);
+<a name="l01615"></a>01615     }
+<a name="l01616"></a>01616 }
+<a name="l01617"></a>01617 cpl_error_code irplib_frameset_sort(<span class="keyword">const</span> cpl_frameset *  <span class="keyword">self</span>, <span class="keywordtype">int</span>* iindex, <span class="keywordtype">double</span>* exptime)
+<a name="l01618"></a>01618 {
+<a name="l01619"></a>01619     <span class="keywordtype">int</span> sz = 0;
+<a name="l01620"></a>01620     <span class="keywordtype">int</span> i = 0;
+<a name="l01621"></a>01621     <span class="keyword">const</span> cpl_frame* tmp_frame = 0;
+<a name="l01622"></a>01622     cpl_error_code error = CPL_ERROR_NONE;
+<a name="l01623"></a>01623     sz = cpl_frameset_get_size(<span class="keyword">self</span>);
+<a name="l01624"></a>01624 
+<a name="l01625"></a>01625     <span class="comment">/* 1. get an array of frames */</span>
+<a name="l01626"></a>01626     tmp_frame = cpl_frameset_get_first_const(<span class="keyword">self</span>);
+<a name="l01627"></a>01627     <span class="keywordflow">while</span>(tmp_frame)
+<a name="l01628"></a>01628     {
+<a name="l01629"></a>01629         exptime[i] = frame_get_exptime(tmp_frame);
+<a name="l01630"></a>01630         iindex[i] = i;
+<a name="l01631"></a>01631         tmp_frame = cpl_frameset_get_next_const(<span class="keyword">self</span>);
+<a name="l01632"></a>01632         i++;
+<a name="l01633"></a>01633     }
+<a name="l01634"></a>01634     <span class="comment">/* 2.sort */</span>
+<a name="l01635"></a>01635     quicksort(iindex, exptime, 0, sz - 1);
+<a name="l01636"></a>01636 
+<a name="l01637"></a>01637     <span class="keywordflow">return</span> error;
+<a name="l01638"></a>01638 }
+<a name="l01639"></a>01639 
+<a name="l01640"></a>01640 <span class="keyword">static</span> <span class="keywordtype">double</span> frame_get_exptime(<span class="keyword">const</span> cpl_frame * pframe)
+<a name="l01641"></a>01641 {
+<a name="l01642"></a>01642     cpl_propertylist       *plist = 0;
+<a name="l01643"></a>01643     <span class="keywordtype">double</span>                  dval = 0;
+<a name="l01644"></a>01644 
+<a name="l01645"></a>01645     plist = cpl_propertylist_load(cpl_frame_get_filename(pframe),0);
+<a name="l01646"></a>01646     <span class="keywordflow">if</span>(plist)
+<a name="l01647"></a>01647     {
+<a name="l01648"></a>01648       cpl_error_code err = CPL_ERROR_NONE;  
+<a name="l01649"></a>01649         dval = cpl_propertylist_get_double(plist, <span class="stringliteral">"EXPTIME"</span>);
+<a name="l01650"></a>01650        err = cpl_error_get_code();
+<a name="l01651"></a>01651        <span class="keywordflow">if</span> (err != CPL_ERROR_NONE)
+<a name="l01652"></a>01652        {
+<a name="l01653"></a>01653          cpl_msg_error(cpl_func, <span class="stringliteral">"error during reading EXPTIME key from the frame [%s]"</span>, cpl_frame_get_filename(pframe));
+<a name="l01654"></a>01654        }
+<a name="l01655"></a>01655     }
+<a name="l01656"></a>01656     <span class="comment">/* Free and return */</span>
+<a name="l01657"></a>01657     cpl_propertylist_delete(plist);
+<a name="l01658"></a>01658     <span class="keywordflow">return</span> dval;
+<a name="l01659"></a>01659 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/irplib__utils_8h_source.html b/html/irplib__utils_8h_source.html
new file mode 100644
index 0000000..4f64c44
--- /dev/null
+++ b/html/irplib__utils_8h_source.html
@@ -0,0 +1,433 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: irplib_utils.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>irplib_utils.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: irplib_utils.h,v 1.55 2011/06/01 06:47:56 llundin Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the irplib package</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: llundin $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2011/06/01 06:47:56 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.55 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> * $Log: irplib_utils.h,v $</span>
+<a name="l00027"></a>00027 <span class="comment"> * Revision 1.55  2011/06/01 06:47:56  llundin</span>
+<a name="l00028"></a>00028 <span class="comment"> * skip_if_lt(): Fix previous edits switch of A and B in error message</span>
+<a name="l00029"></a>00029 <span class="comment"> *</span>
+<a name="l00030"></a>00030 <span class="comment"> * Revision 1.54  2011/05/26 08:08:56  llundin</span>
+<a name="l00031"></a>00031 <span class="comment"> * skip_if_lt(): Support printf-style error message, name-space protect temporary variables</span>
+<a name="l00032"></a>00032 <span class="comment"> *</span>
+<a name="l00033"></a>00033 <span class="comment"> * Revision 1.53  2011/05/09 07:51:18  llundin</span>
+<a name="l00034"></a>00034 <span class="comment"> * irplib_dfs_save_image_(): Modified from cpl_dfs_save_image(). irplib_dfs_save_image(): Use irplib_dfs_save_image_()</span>
+<a name="l00035"></a>00035 <span class="comment"> *</span>
+<a name="l00036"></a>00036 <span class="comment"> * Revision 1.52  2010/03/23 07:57:59  kmirny</span>
+<a name="l00037"></a>00037 <span class="comment"> * DFS08552, Documentation for irplib_frameset_sort</span>
+<a name="l00038"></a>00038 <span class="comment"> *</span>
+<a name="l00039"></a>00039 <span class="comment"> * Revision 1.51  2009/12/16 14:59:30  cgarcia</span>
+<a name="l00040"></a>00040 <span class="comment"> * Avoid name clash with index function</span>
+<a name="l00041"></a>00041 <span class="comment"> *</span>
+<a name="l00042"></a>00042 <span class="comment"> * Revision 1.50  2009/08/17 15:10:16  kmirny</span>
+<a name="l00043"></a>00043 <span class="comment"> *</span>
+<a name="l00044"></a>00044 <span class="comment"> * DFS07454 DFS07437</span>
+<a name="l00045"></a>00045 <span class="comment"> *</span>
+<a name="l00046"></a>00046 <span class="comment"> */</span>
+<a name="l00047"></a>00047 
+<a name="l00048"></a>00048 <span class="preprocessor">#ifndef IRPLIB_UTILS_H</span>
+<a name="l00049"></a>00049 <span class="preprocessor"></span><span class="preprocessor">#define IRPLIB_UTILS_H</span>
+<a name="l00050"></a>00050 <span class="preprocessor"></span>
+<a name="l00051"></a>00051 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00052"></a>00052 <span class="comment">                                   Includes</span>
+<a name="l00053"></a>00053 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00054"></a>00054 
+<a name="l00055"></a>00055 <span class="preprocessor">#include <stdarg.h></span>
+<a name="l00056"></a>00056 
+<a name="l00057"></a>00057 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00058"></a>00058 
+<a name="l00059"></a>00059 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00060"></a>00060 <span class="comment">                                   Define</span>
+<a name="l00061"></a>00061 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00062"></a>00062 
+<a name="l00063"></a>00063 <span class="preprocessor">#define IRPLIB_XSTRINGIFY(TOSTRING) #TOSTRING</span>
+<a name="l00064"></a>00064 <span class="preprocessor"></span><span class="preprocessor">#define IRPLIB_STRINGIFY(TOSTRING) IRPLIB_XSTRINGIFY(TOSTRING)</span>
+<a name="l00065"></a>00065 <span class="preprocessor"></span>
+<a name="l00066"></a>00066 <span class="comment">/* FIXME: Remove when no longer used by any irplib-based pipelines */</span>
+<a name="l00067"></a>00067 <span class="comment">/* Useful for debugging */</span>
+<a name="l00068"></a>00068 <span class="preprocessor">#define irplib_trace()  do if (cpl_error_get_code()) { \</span>
+<a name="l00069"></a>00069 <span class="preprocessor">    cpl_msg_debug(cpl_func, __FILE__ " at line %d: ERROR '%s' at %s", \</span>
+<a name="l00070"></a>00070 <span class="preprocessor">         __LINE__, cpl_error_get_message(), cpl_error_get_where()); \</span>
+<a name="l00071"></a>00071 <span class="preprocessor">  } else { \</span>
+<a name="l00072"></a>00072 <span class="preprocessor">    cpl_msg_debug(cpl_func, __FILE__ " at line %d: OK", __LINE__); \</span>
+<a name="l00073"></a>00073 <span class="preprocessor">  } while (0)</span>
+<a name="l00074"></a>00074 <span class="preprocessor"></span>
+<a name="l00075"></a>00075 <span class="preprocessor">#define irplib_error_recover(ESTATE, ...)                                      \</span>
+<a name="l00076"></a>00076 <span class="preprocessor">    do if (!cpl_errorstate_is_equal(ESTATE)) {                                 \</span>
+<a name="l00077"></a>00077 <span class="preprocessor">        cpl_msg_warning(cpl_func, __VA_ARGS__);                                \</span>
+<a name="l00078"></a>00078 <span class="preprocessor">        cpl_msg_indent_more();                                                 \</span>
+<a name="l00079"></a>00079 <span class="preprocessor">        cpl_errorstate_dump(ESTATE, CPL_FALSE, irplib_errorstate_warning);     \</span>
+<a name="l00080"></a>00080 <span class="preprocessor">        cpl_msg_indent_less();                                                 \</span>
+<a name="l00081"></a>00081 <span class="preprocessor">        cpl_errorstate_set(ESTATE);                                            \</span>
+<a name="l00082"></a>00082 <span class="preprocessor">    } while (0)</span>
+<a name="l00083"></a>00083 <span class="preprocessor"></span>
+<a name="l00084"></a>00084 
+<a name="l00085"></a>00085 
+<a name="l00086"></a>00086 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00087"></a>00087 <span class="comment">/*</span>
+<a name="l00088"></a>00088 <span class="comment">  @brief Declare a function suitable for use with irplib_dfs_table_convert()</span>
+<a name="l00089"></a>00089 <span class="comment">  @param  table_set_row    The name of the function to declare</span>
+<a name="l00090"></a>00090 <span class="comment">  @see irplib_dfs_table_convert(), irplib_table_read_from_frameset()</span>
+<a name="l00091"></a>00091 <span class="comment"></span>
+<a name="l00092"></a>00092 <span class="comment">*/</span>
+<a name="l00093"></a>00093 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00094"></a>00094 <span class="preprocessor">#define IRPLIB_UTIL_SET_ROW(table_set_row)                      \</span>
+<a name="l00095"></a>00095 <span class="preprocessor">    cpl_boolean table_set_row(cpl_table *,                      \</span>
+<a name="l00096"></a>00096 <span class="preprocessor">                              const char *,                     \</span>
+<a name="l00097"></a>00097 <span class="preprocessor">                              int,                              \</span>
+<a name="l00098"></a>00098 <span class="preprocessor">                              const cpl_frame *,                \</span>
+<a name="l00099"></a>00099 <span class="preprocessor">                              const cpl_parameterlist *)</span>
+<a name="l00100"></a>00100 <span class="preprocessor"></span>
+<a name="l00101"></a>00101 
+<a name="l00102"></a>00102 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00103"></a>00103 <span class="comment">/*</span>
+<a name="l00104"></a>00104 <span class="comment">  @brief Declare a function suitable for use with irplib_dfs_table_convert()</span>
+<a name="l00105"></a>00105 <span class="comment">  @param  table_check    The name of the function to declare</span>
+<a name="l00106"></a>00106 <span class="comment">  @see irplib_dfs_table_convert()</span>
+<a name="l00107"></a>00107 <span class="comment"></span>
+<a name="l00108"></a>00108 <span class="comment">*/</span>
+<a name="l00109"></a>00109 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00110"></a>00110 <span class="preprocessor">#define IRPLIB_UTIL_CHECK(table_check)                          \</span>
+<a name="l00111"></a>00111 <span class="preprocessor">    cpl_error_code table_check(cpl_table *,                     \</span>
+<a name="l00112"></a>00112 <span class="preprocessor">                               const cpl_frameset *,            \</span>
+<a name="l00113"></a>00113 <span class="preprocessor">                               const cpl_parameterlist *)</span>
+<a name="l00114"></a>00114 <span class="preprocessor"></span>
+<a name="l00115"></a>00115 
+<a name="l00116"></a>00116 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00117"></a>00117 <span class="comment">/*</span>
+<a name="l00118"></a>00118 <span class="comment">  @brief   Conditional skip to the (unqiue) return point of the function</span>
+<a name="l00119"></a>00119 <span class="comment">  @param   CONDITION    The condition to check</span>
+<a name="l00120"></a>00120 <span class="comment">  @see cpl_error_ensure()</span>
+<a name="l00121"></a>00121 <span class="comment"></span>
+<a name="l00122"></a>00122 <span class="comment">  skip_if() takes one argument, which is a logical expression.</span>
+<a name="l00123"></a>00123 <span class="comment">  If the logical expression is false skip_if() takes no action and</span>
+<a name="l00124"></a>00124 <span class="comment">  program execution continues.</span>
+<a name="l00125"></a>00125 <span class="comment">  If the logical expression is true this indicates an error. In this case</span>
+<a name="l00126"></a>00126 <span class="comment">  skip_if() will set the location of the error to the point where it</span>
+<a name="l00127"></a>00127 <span class="comment">  was invoked in the recipe code (unless the error location is already in the</span>
+<a name="l00128"></a>00128 <span class="comment">  recipe code). If no error code had been set, then skip_if() will set one.</span>
+<a name="l00129"></a>00129 <span class="comment">  Finally, skip_if() causes program execution to skip to the macro 'end_skip'.</span>
+<a name="l00130"></a>00130 <span class="comment">  The macro end_skip is located towards the end of the function, after</span>
+<a name="l00131"></a>00131 <span class="comment">  which all resource deallocation and the function return is located.</span>
+<a name="l00132"></a>00132 <span class="comment"></span>
+<a name="l00133"></a>00133 <span class="comment">  The use of skip_if() assumes the following coding practice:</span>
+<a name="l00134"></a>00134 <span class="comment">  1) Pointers used for dynamically allocated memory that they "own" shall always</span>
+<a name="l00135"></a>00135 <span class="comment">     point to either NULL or to allocated memory (including CPL-objects).</span>
+<a name="l00136"></a>00136 <span class="comment">  2) Such pointers may not be reused to point to memory whose deallocation</span>
+<a name="l00137"></a>00137 <span class="comment">     requires calls to different functions.</span>
+<a name="l00138"></a>00138 <span class="comment">  3) Pointers of type FILE should be set NULL when not pointing to an open</span>
+<a name="l00139"></a>00139 <span class="comment">     stream and their closing calls (fclose(), freopen(), etc.) following the</span>
+<a name="l00140"></a>00140 <span class="comment">     'end_skip' should be guarded against such NULL pointers.</span>
+<a name="l00141"></a>00141 <span class="comment"></span>
+<a name="l00142"></a>00142 <span class="comment">  Error checking with skip_if() is encouraged due to the following advantages:</span>
+<a name="l00143"></a>00143 <span class="comment">  1) It ensures that a CPL-error code is set.</span>
+<a name="l00144"></a>00144 <span class="comment">  2) It ensures that the location of the error in the _recipe_ code is noted.</span>
+<a name="l00145"></a>00145 <span class="comment">  3) The error checking may be confined to a single concise line.</span>
+<a name="l00146"></a>00146 <span class="comment">  4) It is not necessary to replicate memory deallocation for every error</span>
+<a name="l00147"></a>00147 <span class="comment">     condition.</span>
+<a name="l00148"></a>00148 <span class="comment">  5) If more extensive error reporting/handling is required it is not precluded</span>
+<a name="l00149"></a>00149 <span class="comment">     by the use of skip_if().</span>
+<a name="l00150"></a>00150 <span class="comment">  6) It allows for a single point of function return.</span>
+<a name="l00151"></a>00151 <span class="comment">  7) It allows for optional, uniformly formatted debugging/tracing information</span>
+<a name="l00152"></a>00152 <span class="comment">     at each macro invocation.</span>
+<a name="l00153"></a>00153 <span class="comment"></span>
+<a name="l00154"></a>00154 <span class="comment">  The implementation of skip_if() uses a goto/label construction.</span>
+<a name="l00155"></a>00155 <span class="comment">  According to Kerningham & Ritchie, The C Programming Language, 2nd edition,</span>
+<a name="l00156"></a>00156 <span class="comment">  Section 3.8:</span>
+<a name="l00157"></a>00157 <span class="comment">  "This organization is handy if the error-handling code is non-trivial,</span>
+<a name="l00158"></a>00158 <span class="comment">  and if errors can occur in several places."</span>
+<a name="l00159"></a>00159 <span class="comment"></span>
+<a name="l00160"></a>00160 <span class="comment">  The use of goto for any other purpose should be avoided.</span>
+<a name="l00161"></a>00161 <span class="comment"></span>
+<a name="l00162"></a>00162 <span class="comment">*/</span>
+<a name="l00163"></a>00163 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00164"></a>00164 <span class="preprocessor">#define skip_if(CONDITION)                                                     \</span>
+<a name="l00165"></a>00165 <span class="preprocessor">    do {                                                                       \</span>
+<a name="l00166"></a>00166 <span class="preprocessor">        cpl_error_ensure(!cpl_error_get_code(), cpl_error_get_code(),          \</span>
+<a name="l00167"></a>00167 <span class="preprocessor">                         goto cleanup, "Propagating a pre-existing error");    \</span>
+<a name="l00168"></a>00168 <span class="preprocessor">        cpl_error_ensure(!(CONDITION), cpl_error_get_code(),                   \</span>
+<a name="l00169"></a>00169 <span class="preprocessor">                         goto cleanup, "Propagating error");\</span>
+<a name="l00170"></a>00170 <span class="preprocessor">    } while (0)</span>
+<a name="l00171"></a>00171 <span class="preprocessor"></span>
+<a name="l00172"></a>00172 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00173"></a>00173 <span class="comment">/*</span>
+<a name="l00174"></a>00174 <span class="comment">  @brief   Skip if A < B</span>
+<a name="l00175"></a>00175 <span class="comment">  @param   A   The 1st double to compare</span>
+<a name="l00176"></a>00176 <span class="comment">  @param   B   The 2nd double to compare</span>
+<a name="l00177"></a>00177 <span class="comment">  @param   MSG A printf-style error message, 1st arg should be a string literal</span>
+<a name="l00178"></a>00178 <span class="comment">  @see skip_if()</span>
+<a name="l00179"></a>00179 <span class="comment">  @note A and B are evaluated exactly once</span>
+<a name="l00180"></a>00180 <span class="comment"></span>
+<a name="l00181"></a>00181 <span class="comment">  If no CPL error is set, sets CPL_ERROR_DATA_NOT_FOUND on failure</span>
+<a name="l00182"></a>00182 <span class="comment">*/</span>
+<a name="l00183"></a>00183 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00184"></a>00184 <span class="preprocessor">#define skip_if_lt(A, B, ...)                                                  \</span>
+<a name="l00185"></a>00185 <span class="preprocessor">    do {                                                                       \</span>
+<a name="l00186"></a>00186 <span class="preprocessor">        </span><span class="comment">/* Name-space protected one-time only evaluation */</span>                    \
+<a name="l00187"></a>00187         const double irplib_utils_a = (double)(A);                             \
+<a name="l00188"></a>00188         const double irplib_utils_b = (double)(B);                             \
+<a name="l00189"></a>00189                                                                                \
+<a name="l00190"></a>00190         cpl_error_ensure(!cpl_error_get_code(), cpl_error_get_code(),          \
+<a name="l00191"></a>00191                          goto cleanup, "Propagating a pre-existing error");    \
+<a name="l00192"></a>00192         if (irplib_utils_a < irplib_utils_b) {                                 \
+<a name="l00193"></a>00193             char * irplib_utils_msg = cpl_sprintf(__VA_ARGS__);                \
+<a name="l00194"></a>00194             (void)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,    \
+<a name="l00195"></a>00195                                         "Need at least %g (not %g) %s",        \
+<a name="l00196"></a>00196                                         irplib_utils_b, irplib_utils_a,        \
+<a name="l00197"></a>00197                                         irplib_utils_msg);                     \
+<a name="l00198"></a>00198             cpl_free(irplib_utils_msg);                                        \
+<a name="l00199"></a>00199             goto cleanup;                                                      \
+<a name="l00200"></a>00200         }                                                                      \
+<a name="l00201"></a>00201     } while (0)
+<a name="l00202"></a>00202 
+<a name="l00203"></a>00203 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00204"></a>00204 <span class="comment">/*</span>
+<a name="l00205"></a>00205 <span class="comment">  @brief   Conditional skip on coding bug</span>
+<a name="l00206"></a>00206 <span class="comment">  @param   CONDITION    The condition to check</span>
+<a name="l00207"></a>00207 <span class="comment">  @see skip_if()</span>
+<a name="l00208"></a>00208 <span class="comment">  @note unlike assert() this check cannot be disabled</span>
+<a name="l00209"></a>00209 <span class="comment"> */</span>
+<a name="l00210"></a>00210 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00211"></a>00211 <span class="preprocessor">#define bug_if(CONDITION)                                                      \</span>
+<a name="l00212"></a>00212 <span class="preprocessor">    do {                                                                       \</span>
+<a name="l00213"></a>00213 <span class="preprocessor">        cpl_error_ensure(!cpl_error_get_code(), cpl_error_get_code(),          \</span>
+<a name="l00214"></a>00214 <span class="preprocessor">                         goto cleanup, "Propagating an unexpected error, "     \</span>
+<a name="l00215"></a>00215 <span class="preprocessor">                         "please report to " PACKAGE_BUGREPORT);               \</span>
+<a name="l00216"></a>00216 <span class="preprocessor">        cpl_error_ensure(!(CONDITION), CPL_ERROR_UNSPECIFIED,                  \</span>
+<a name="l00217"></a>00217 <span class="preprocessor">                         goto cleanup, "Internal error, please report to "     \</span>
+<a name="l00218"></a>00218 <span class="preprocessor">                         PACKAGE_BUGREPORT);                                   \</span>
+<a name="l00219"></a>00219 <span class="preprocessor">    } while (0)</span>
+<a name="l00220"></a>00220 <span class="preprocessor"></span>
+<a name="l00221"></a>00221 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00222"></a>00222 <span class="comment">/*</span>
+<a name="l00223"></a>00223 <span class="comment">  @brief   Conditional skip with error creation</span>
+<a name="l00224"></a>00224 <span class="comment">  @param   CONDITION    The condition to check</span>
+<a name="l00225"></a>00225 <span class="comment">  @param   ERROR        The error code to set</span>
+<a name="l00226"></a>00226 <span class="comment">  @param   MSG          A printf-style error message. As a matter of</span>
+<a name="l00227"></a>00227 <span class="comment">                        user-friendliness the message should mention any</span>
+<a name="l00228"></a>00228 <span class="comment">                        value that caused the @em CONDITION to fail.</span>
+<a name="l00229"></a>00229 <span class="comment">  @see skip_if()</span>
+<a name="l00230"></a>00230 <span class="comment">  @note unlike assert() this check cannot be disabled</span>
+<a name="l00231"></a>00231 <span class="comment"> */</span>
+<a name="l00232"></a>00232 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00233"></a>00233 <span class="preprocessor">#define error_if(CONDITION, ERROR, ...)                                 \</span>
+<a name="l00234"></a>00234 <span class="preprocessor">    cpl_error_ensure(cpl_error_get_code() == CPL_ERROR_NONE &&          \</span>
+<a name="l00235"></a>00235 <span class="preprocessor">                     !(CONDITION), ERROR, goto cleanup,  __VA_ARGS__)</span>
+<a name="l00236"></a>00236 <span class="preprocessor"></span>
+<a name="l00237"></a>00237 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00238"></a>00238 <span class="comment">/*</span>
+<a name="l00239"></a>00239 <span class="comment">  @brief   Propagate a preexisting error, if any</span>
+<a name="l00240"></a>00240 <span class="comment">  @param   MSG          A printf-style error message.</span>
+<a name="l00241"></a>00241 <span class="comment">  @see skip_if()</span>
+<a name="l00242"></a>00242 <span class="comment"> */</span>
+<a name="l00243"></a>00243 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00244"></a>00244 <span class="preprocessor">#define any_if(...)                                                     \</span>
+<a name="l00245"></a>00245 <span class="preprocessor">    cpl_error_ensure(!cpl_error_get_code(), cpl_error_get_code(),       \</span>
+<a name="l00246"></a>00246 <span class="preprocessor">                     goto cleanup,  __VA_ARGS__)</span>
+<a name="l00247"></a>00247 <span class="preprocessor"></span>
+<a name="l00248"></a>00248 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00249"></a>00249 <span class="comment">/*</span>
+<a name="l00250"></a>00250 <span class="comment">  @brief   Define the single point of resource deallocation and return</span>
+<a name="l00251"></a>00251 <span class="comment">  @see skip_if()</span>
+<a name="l00252"></a>00252 <span class="comment">  @note end_skip should be used exactly once in functions that use skip_if() etc</span>
+<a name="l00253"></a>00253 <span class="comment">*/</span>
+<a name="l00254"></a>00254 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00255"></a>00255 <span class="preprocessor">#define end_skip \</span>
+<a name="l00256"></a>00256 <span class="preprocessor">    do {                                                                     \</span>
+<a name="l00257"></a>00257 <span class="preprocessor">        cleanup:                                                             \</span>
+<a name="l00258"></a>00258 <span class="preprocessor">        if (cpl_error_get_code())                                            \</span>
+<a name="l00259"></a>00259 <span class="preprocessor">            cpl_msg_debug(cpl_func, "Cleanup in " __FILE__ " line %u with "  \</span>
+<a name="l00260"></a>00260 <span class="preprocessor">                          "error '%s' at %s", __LINE__,                      \</span>
+<a name="l00261"></a>00261 <span class="preprocessor">                          cpl_error_get_message(), cpl_error_get_where());   \</span>
+<a name="l00262"></a>00262 <span class="preprocessor">        else                                                                 \</span>
+<a name="l00263"></a>00263 <span class="preprocessor">            cpl_msg_debug(cpl_func, "Cleanup in " __FILE__ " line %u",       \</span>
+<a name="l00264"></a>00264 <span class="preprocessor">                          __LINE__);                                         \</span>
+<a name="l00265"></a>00265 <span class="preprocessor">    } while (0)</span>
+<a name="l00266"></a>00266 <span class="preprocessor"></span>
+<a name="l00267"></a>00267 
+<a name="l00268"></a>00268 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00280"></a>00280 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00281"></a>00281 <span class="preprocessor">#define irplib_ensure(CONDITION, ec, ...)                                      \</span>
+<a name="l00282"></a>00282 <span class="preprocessor">    cpl_error_ensure(CONDITION, ec, goto cleanup,  __VA_ARGS__)</span>
+<a name="l00283"></a>00283 <span class="preprocessor"></span>
+<a name="l00284"></a>00284 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00314"></a>00314 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00315"></a>00315 
+<a name="l00316"></a>00316 <span class="preprocessor">#define irplib_check(COMMAND, ...)                                             \</span>
+<a name="l00317"></a>00317 <span class="preprocessor">  do {                                                                         \</span>
+<a name="l00318"></a>00318 <span class="preprocessor">    cpl_errorstate irplib_check_prestate = cpl_errorstate_get();               \</span>
+<a name="l00319"></a>00319 <span class="preprocessor">    skip_if(0);                                                                \</span>
+<a name="l00320"></a>00320 <span class="preprocessor">    COMMAND;                                                                   \</span>
+<a name="l00321"></a>00321 <span class="preprocessor">        irplib_trace(); \</span>
+<a name="l00322"></a>00322 <span class="preprocessor">    irplib_ensure(cpl_errorstate_is_equal(irplib_check_prestate),              \</span>
+<a name="l00323"></a>00323 <span class="preprocessor">                  cpl_error_get_code(), __VA_ARGS__);                          \</span>
+<a name="l00324"></a>00324 <span class="preprocessor">        irplib_trace(); \</span>
+<a name="l00325"></a>00325 <span class="preprocessor">  } while (0)</span>
+<a name="l00326"></a>00326 <span class="preprocessor"></span>
+<a name="l00327"></a>00327 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00328"></a>00328 <span class="comment">                                   Function prototypes</span>
+<a name="l00329"></a>00329 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00330"></a>00330 
+<a name="l00331"></a>00331 cpl_error_code <a class="code" href="group__irplib__utils.html#ga346842d722834a2e6221ff2d86314b7e" title="Save an image as a DFS-compliant pipeline product.">irplib_dfs_save_image</a>(cpl_frameset            *,
+<a name="l00332"></a>00332                                      <span class="keyword">const</span> cpl_parameterlist *,
+<a name="l00333"></a>00333                                      <span class="keyword">const</span> cpl_frameset      *,
+<a name="l00334"></a>00334                                      <span class="keyword">const</span> cpl_image         *,
+<a name="l00335"></a>00335                                      cpl_type_bpp             ,
+<a name="l00336"></a>00336                                      <span class="keyword">const</span> <span class="keywordtype">char</span>              *,
+<a name="l00337"></a>00337                                      <span class="keyword">const</span> <span class="keywordtype">char</span>              *,
+<a name="l00338"></a>00338                                      <span class="keyword">const</span> cpl_propertylist  *,
+<a name="l00339"></a>00339                                      <span class="keyword">const</span> <span class="keywordtype">char</span>              *,
+<a name="l00340"></a>00340                                      <span class="keyword">const</span> <span class="keywordtype">char</span>              *,
+<a name="l00341"></a>00341                                      <span class="keyword">const</span> <span class="keywordtype">char</span>              *);
+<a name="l00342"></a>00342 
+<a name="l00343"></a>00343 
+<a name="l00344"></a>00344 cpl_error_code <a class="code" href="group__irplib__utils.html#ga4dc12f321e7aeb5e67ff19f815bfd7b7" title="Save a propertylist as a DFS-compliant pipeline product.">irplib_dfs_save_propertylist</a>(cpl_frameset            *,
+<a name="l00345"></a>00345                                             <span class="keyword">const</span> cpl_parameterlist *,
+<a name="l00346"></a>00346                                             <span class="keyword">const</span> cpl_frameset      *,
+<a name="l00347"></a>00347                                             <span class="keyword">const</span> <span class="keywordtype">char</span>              *,
+<a name="l00348"></a>00348                                             <span class="keyword">const</span> <span class="keywordtype">char</span>              *,
+<a name="l00349"></a>00349                                             <span class="keyword">const</span> cpl_propertylist  *,
+<a name="l00350"></a>00350                                             <span class="keyword">const</span> <span class="keywordtype">char</span>              *,
+<a name="l00351"></a>00351                                             <span class="keyword">const</span> <span class="keywordtype">char</span>              *,
+<a name="l00352"></a>00352                                             <span class="keyword">const</span> <span class="keywordtype">char</span>              *);
+<a name="l00353"></a>00353 
+<a name="l00354"></a>00354 cpl_error_code <a class="code" href="group__irplib__utils.html#ga66f7adc9e165b4e934e3d57a700f55c1" title="Save an imagelist as a DFS-compliant pipeline product.">irplib_dfs_save_imagelist</a>(cpl_frameset            *,
+<a name="l00355"></a>00355                                          <span class="keyword">const</span> cpl_parameterlist *,
+<a name="l00356"></a>00356                                          <span class="keyword">const</span> cpl_frameset      *,
+<a name="l00357"></a>00357                                          <span class="keyword">const</span> cpl_imagelist     *,
+<a name="l00358"></a>00358                                          cpl_type_bpp             ,
+<a name="l00359"></a>00359                                          <span class="keyword">const</span> <span class="keywordtype">char</span>              *,
+<a name="l00360"></a>00360                                          <span class="keyword">const</span> <span class="keywordtype">char</span>              *,
+<a name="l00361"></a>00361                                          <span class="keyword">const</span> cpl_propertylist  *,
+<a name="l00362"></a>00362                                          <span class="keyword">const</span> <span class="keywordtype">char</span>              *,
+<a name="l00363"></a>00363                                          <span class="keyword">const</span> <span class="keywordtype">char</span>              *,
+<a name="l00364"></a>00364                                          <span class="keyword">const</span> <span class="keywordtype">char</span>              *);
+<a name="l00365"></a>00365 
+<a name="l00366"></a>00366 cpl_error_code <a class="code" href="group__irplib__utils.html#ga62a91f8630af11164547c168660b2ade" title="Save a table as a DFS-compliant pipeline product.">irplib_dfs_save_table</a>(cpl_frameset            *,
+<a name="l00367"></a>00367                                      <span class="keyword">const</span> cpl_parameterlist *,
+<a name="l00368"></a>00368                                      <span class="keyword">const</span> cpl_frameset      *,
+<a name="l00369"></a>00369                                      <span class="keyword">const</span> cpl_table         *,
+<a name="l00370"></a>00370                                      <span class="keyword">const</span> cpl_propertylist  *,
+<a name="l00371"></a>00371                                      <span class="keyword">const</span> <span class="keywordtype">char</span>              *,
+<a name="l00372"></a>00372                                      <span class="keyword">const</span> <span class="keywordtype">char</span>              *,
+<a name="l00373"></a>00373                                      <span class="keyword">const</span> cpl_propertylist  *,
+<a name="l00374"></a>00374                                      <span class="keyword">const</span> <span class="keywordtype">char</span>              *,
+<a name="l00375"></a>00375                                      <span class="keyword">const</span> <span class="keywordtype">char</span>              *,
+<a name="l00376"></a>00376                                      <span class="keyword">const</span> <span class="keywordtype">char</span>              *);
+<a name="l00377"></a>00377 
+<a name="l00378"></a>00378 cpl_error_code <a class="code" href="group__irplib__utils.html#ga1fd7c2f4c00014049b0bf4bf6814b451" title="Save an image as a DFS-compliant pipeline product.">irplib_dfs_save_image_</a>(cpl_frameset            *,
+<a name="l00379"></a>00379                                       cpl_propertylist        *,
+<a name="l00380"></a>00380                                       <span class="keyword">const</span> cpl_parameterlist *,
+<a name="l00381"></a>00381                                       <span class="keyword">const</span> cpl_frameset      *,
+<a name="l00382"></a>00382                                       <span class="keyword">const</span> cpl_frame         *,
+<a name="l00383"></a>00383                                       <span class="keyword">const</span> cpl_image         *,
+<a name="l00384"></a>00384                                       cpl_type                 ,
+<a name="l00385"></a>00385                                       <span class="keyword">const</span> <span class="keywordtype">char</span>              *,
+<a name="l00386"></a>00386                                       <span class="keyword">const</span> cpl_propertylist  *,
+<a name="l00387"></a>00387                                       <span class="keyword">const</span> <span class="keywordtype">char</span>              *,
+<a name="l00388"></a>00388                                       <span class="keyword">const</span> <span class="keywordtype">char</span>              *,
+<a name="l00389"></a>00389                                       <span class="keyword">const</span> <span class="keywordtype">char</span>              *);
+<a name="l00390"></a>00390 
+<a name="l00391"></a>00391 <span class="keywordtype">void</span> <a class="code" href="group__irplib__utils.html#gaf9d392144014e2363054bc3f83c8e47e" title="Reset IRPLIB state.">irplib_reset</a>(<span class="keywordtype">void</span>);
+<a name="l00392"></a>00392 <span class="keywordtype">int</span> <a class="code" href="group__irplib__utils.html#gae13f0d6b24ade506a99ac9c4bb09efde" title="Comparison function to identify different input frames.">irplib_compare_tags</a>(cpl_frame *, cpl_frame *);
+<a name="l00393"></a>00393 <span class="keyword">const</span> <span class="keywordtype">char</span> * <a class="code" href="group__irplib__utils.html#ga9fe4dca85dee68061114e26fdc72a134" title="Find the filename with the given tag in a frame set.">irplib_frameset_find_file</a>(<span class="keyword">const</span> cpl_frameset *, <span class="keyword">const</span> <span class="keywordtype">char</span> *);
+<a name="l00394"></a>00394 <span class="keyword">const</span> cpl_frame * <a class="code" href="group__irplib__utils.html#ga5b20a00f315410b49b1db1dd2417fe68" title="Find the first frame belonging to the given group.">irplib_frameset_get_first_from_group</a>(<span class="keyword">const</span> cpl_frameset *,
+<a name="l00395"></a>00395                                                        cpl_frame_group);
+<a name="l00396"></a>00396 
+<a name="l00397"></a>00397 cpl_error_code <a class="code" href="group__irplib__utils.html#gac568c70a57ef8610f5fedc9f1943a3a1" title="Find the aperture(s) with the greatest flux.">irplib_apertures_find_max_flux</a>(<span class="keyword">const</span> cpl_apertures *, <span class="keywordtype">int</span> *,
+<a name="l00398"></a>00398                                               <span class="keywordtype">int</span>);
+<a name="l00399"></a>00399 
+<a name="l00400"></a>00400 <span class="keywordtype">int</span> <a class="code" href="group__irplib__utils.html#ga09a11edf52efa78ddafce0bb4fa3b71f" title="portable isinf">irplib_isinf</a>(<span class="keywordtype">double</span> value);
+<a name="l00401"></a>00401 <span class="keywordtype">int</span> <a class="code" href="group__irplib__utils.html#ga804bfc739b5d55f9797ab881b1034ae4" title="portable isnan">irplib_isnan</a>(<span class="keywordtype">double</span> value);
+<a name="l00402"></a>00402 
+<a name="l00403"></a>00403 <span class="keywordtype">void</span> <a class="code" href="group__irplib__utils.html#ga2dda571b0bbb3f7bf170210b38f95627" title="Dump a single CPL error.">irplib_errorstate_warning</a>(<span class="keywordtype">unsigned</span>, <span class="keywordtype">unsigned</span>, <span class="keywordtype">unsigned</span>);
+<a name="l00404"></a>00404 
+<a name="l00405"></a>00405 cpl_error_code
+<a name="l00406"></a>00406 <a class="code" href="group__irplib__utils.html#ga3d1a791b5dc870770611c7dbf60d02df" title="Create a DFS product with one table from one or more (ASCII) file(s).">irplib_dfs_table_convert</a>(cpl_table *, cpl_frameset *, <span class="keyword">const</span> cpl_frameset *,
+<a name="l00407"></a>00407                          <span class="keywordtype">int</span>, <span class="keywordtype">char</span>, <span class="keyword">const</span> <span class="keywordtype">char</span> *, <span class="keyword">const</span> <span class="keywordtype">char</span> *,
+<a name="l00408"></a>00408                          <span class="keyword">const</span> cpl_parameterlist *, <span class="keyword">const</span> <span class="keywordtype">char</span> *,
+<a name="l00409"></a>00409                          <span class="keyword">const</span> cpl_propertylist *, <span class="keyword">const</span> cpl_propertylist *,
+<a name="l00410"></a>00410                          <span class="keyword">const</span> <span class="keywordtype">char</span> *, <span class="keyword">const</span> <span class="keywordtype">char</span> *, <span class="keyword">const</span> <span class="keywordtype">char</span> *,
+<a name="l00411"></a>00411                          cpl_boolean (*)(cpl_table *, <span class="keyword">const</span> <span class="keywordtype">char</span> *, <span class="keywordtype">int</span>,
+<a name="l00412"></a>00412                                             <span class="keyword">const</span> cpl_frame *,
+<a name="l00413"></a>00413                                             <span class="keyword">const</span> cpl_parameterlist *),
+<a name="l00414"></a>00414                          cpl_error_code (*)(cpl_table *,
+<a name="l00415"></a>00415                                             <span class="keyword">const</span> cpl_frameset *,
+<a name="l00416"></a>00416                                             <span class="keyword">const</span> cpl_parameterlist *));
+<a name="l00417"></a>00417 
+<a name="l00418"></a>00418 cpl_error_code <a class="code" href="group__irplib__utils.html#ga59a68df1795523d4f7653875bd9fc01d" title="Set the rows of a table with data from one or more (ASCII) files.">irplib_table_read_from_frameset</a>(cpl_table *,
+<a name="l00419"></a>00419                                                <span class="keyword">const</span> cpl_frameset *,
+<a name="l00420"></a>00420                                                <span class="keywordtype">int</span>,
+<a name="l00421"></a>00421                                                <span class="keywordtype">char</span>,
+<a name="l00422"></a>00422                                                <span class="keyword">const</span> cpl_parameterlist *,
+<a name="l00423"></a>00423                                                cpl_boolean (*)
+<a name="l00424"></a>00424                                                (cpl_table *, <span class="keyword">const</span> <span class="keywordtype">char</span> *,
+<a name="l00425"></a>00425                                                 <span class="keywordtype">int</span>, <span class="keyword">const</span> cpl_frame *,
+<a name="l00426"></a>00426                                                 <span class="keyword">const</span> cpl_parameterlist *));
+<a name="l00427"></a>00427 
+<a name="l00428"></a>00428 cpl_error_code <a class="code" href="group__irplib__utils.html#ga832676f36ecd647b77f4bb373b2d1954" title="Split the values in an image in three according to two thresholds.">irplib_image_split</a>(<span class="keyword">const</span> cpl_image *,
+<a name="l00429"></a>00429                                   cpl_image *, cpl_image *, cpl_image *,
+<a name="l00430"></a>00430                                   <span class="keywordtype">double</span>, cpl_boolean,
+<a name="l00431"></a>00431                                   <span class="keywordtype">double</span>, cpl_boolean,
+<a name="l00432"></a>00432                                   <span class="keywordtype">double</span>, <span class="keywordtype">double</span>,
+<a name="l00433"></a>00433                                   cpl_boolean, cpl_boolean, cpl_boolean);
+<a name="l00434"></a>00434 
+<a name="l00435"></a>00435 <span class="keywordtype">void</span> <a class="code" href="group__irplib__utils.html#ga6b29dac884b62ab52f43dd670d4d8386" title="Dump a single CPL error at the CPL warning level.">irplib_errorstate_dump_warning</a>(<span class="keywordtype">unsigned</span>, <span class="keywordtype">unsigned</span>, <span class="keywordtype">unsigned</span>);
+<a name="l00436"></a>00436 <span class="keywordtype">void</span> <a class="code" href="group__irplib__utils.html#ga901ff52a1c9dcdfcf2d2632d31064bdb" title="Dump a single CPL error at the CPL info level.">irplib_errorstate_dump_info</a>(<span class="keywordtype">unsigned</span>, <span class="keywordtype">unsigned</span>, <span class="keywordtype">unsigned</span>);
+<a name="l00437"></a>00437 <span class="keywordtype">void</span> <a class="code" href="group__irplib__utils.html#ga26c6209e5df98978e2922a15b47b47d1" title="Dump a single CPL error at the CPL debug level.">irplib_errorstate_dump_debug</a>(<span class="keywordtype">unsigned</span>, <span class="keywordtype">unsigned</span>, <span class="keywordtype">unsigned</span>);
+<a name="l00438"></a>00438 <span class="comment">/* wrapper for replace deprecated function cpl_polynomial_fit_1d_create*/</span>
+<a name="l00439"></a>00439 cpl_polynomial * irplib_polynomial_fit_1d_create(
+<a name="l00440"></a>00440         <span class="keyword">const</span> cpl_vector    *   x_pos,
+<a name="l00441"></a>00441         <span class="keyword">const</span> cpl_vector    *   values,
+<a name="l00442"></a>00442         <span class="keywordtype">int</span>                     degree,
+<a name="l00443"></a>00443         <span class="keywordtype">double</span>              *   mse
+<a name="l00444"></a>00444         );
+<a name="l00445"></a>00445 cpl_polynomial * irplib_polynomial_fit_1d_create_chiq(
+<a name="l00446"></a>00446         <span class="keyword">const</span> cpl_vector    *   x_pos,
+<a name="l00447"></a>00447         <span class="keyword">const</span> cpl_vector    *   values,
+<a name="l00448"></a>00448         <span class="keywordtype">int</span>                     degree,
+<a name="l00449"></a>00449         <span class="keywordtype">double</span>              *   rechiq
+<a name="l00450"></a>00450         );
+<a name="l00451"></a>00451 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00459"></a>00459 cpl_error_code irplib_frameset_sort(
+<a name="l00460"></a>00460         <span class="keyword">const</span> cpl_frameset *  <span class="keyword">self</span>,
+<a name="l00461"></a>00461         <span class="keywordtype">int</span>* iindex,
+<a name="l00462"></a>00462         <span class="keywordtype">double</span>* exptime);
+<a name="l00463"></a>00463 
+<a name="l00464"></a>00464 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/irplib__wavecal_8c_source.html b/html/irplib__wavecal_8c_source.html
new file mode 100644
index 0000000..d53958c
--- /dev/null
+++ b/html/irplib__wavecal_8c_source.html
@@ -0,0 +1,1460 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: irplib_wavecal.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>irplib_wavecal.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: irplib_wavecal.c,v 1.46 2012/03/02 09:01:04 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the IRPLIB Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2012/03/02 09:01:04 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.46 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span>
+<a name="l00032"></a>00032 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                                   Includes</span>
+<a name="l00034"></a>00034 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 
+<a name="l00036"></a>00036 <span class="comment">/* TEMPORARY SUPPORT OF CPL 5.x */</span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00038"></a>00038 
+<a name="l00039"></a>00039 <span class="preprocessor">#ifndef CPL_SIZE_FORMAT</span>
+<a name="l00040"></a>00040 <span class="preprocessor"></span><span class="preprocessor">#define CPL_SIZE_FORMAT "d"</span>
+<a name="l00041"></a>00041 <span class="preprocessor"></span><span class="preprocessor">#define cpl_size int</span>
+<a name="l00042"></a>00042 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
+<a name="l00043"></a>00043 <span class="preprocessor"></span><span class="comment">/* END TEMPORARY SUPPORT OF CPL 5.x */</span>
+<a name="l00044"></a>00044 
+<a name="l00045"></a>00045 <span class="preprocessor">#include "irplib_wavecal_impl.h"</span>
+<a name="l00046"></a>00046 
+<a name="l00047"></a>00047 <span class="comment">/* Needed for irplib_errorstate_dump_debug() */</span>
+<a name="l00048"></a>00048 <span class="preprocessor">#include "irplib_utils.h"</span>
+<a name="l00049"></a>00049 
+<a name="l00050"></a>00050 <span class="preprocessor">#include <string.h></span>
+<a name="l00051"></a>00051 <span class="preprocessor">#include <math.h></span>
+<a name="l00052"></a>00052 
+<a name="l00053"></a>00053 <span class="preprocessor">#ifdef HAVE_GSL</span>
+<a name="l00054"></a>00054 <span class="preprocessor"></span><span class="preprocessor">#include <gsl/gsl_multimin.h></span>
+<a name="l00055"></a>00055 <span class="preprocessor">#endif</span>
+<a name="l00056"></a>00056 <span class="preprocessor"></span>
+<a name="l00057"></a>00057 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00058"></a>00058 <span class="comment">                               Private types</span>
+<a name="l00059"></a>00059 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00060"></a>00060 
+<a name="l00061"></a>00061 <span class="keyword">typedef</span> <span class="keyword">struct </span>{
+<a name="l00062"></a>00062 
+<a name="l00063"></a>00063     <span class="keyword">const</span> cpl_vector * observed;
+<a name="l00064"></a>00064     cpl_polynomial   * disp1d;
+<a name="l00065"></a>00065     cpl_vector       * spectrum;
+<a name="l00066"></a>00066     irplib_base_spectrum_model * param;
+<a name="l00067"></a>00067     cpl_error_code  (* filler)(cpl_vector *, <span class="keyword">const</span> cpl_polynomial *,
+<a name="l00068"></a>00068                                irplib_base_spectrum_model *, int);
+<a name="l00069"></a>00069     cpl_vector       * vxc;
+<a name="l00070"></a>00070     <span class="keywordtype">double</span>             xc;
+<a name="l00071"></a>00071     <span class="keywordtype">int</span>                maxxc;
+<a name="l00072"></a>00072     <span class="keywordtype">double</span>             mxc;
+<a name="l00073"></a>00073     cpl_polynomial   * mdisp;
+<a name="l00074"></a>00074     <span class="keywordtype">int</span>                ishift;
+<a name="l00075"></a>00075 
+<a name="l00076"></a>00076 } irplib_multimin;
+<a name="l00077"></a>00077 
+<a name="l00078"></a>00078 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00079"></a>00079 <span class="comment">                               Defines</span>
+<a name="l00080"></a>00080 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00081"></a>00081 
+<a name="l00082"></a>00082 <span class="preprocessor">#ifndef inline</span>
+<a name="l00083"></a>00083 <span class="preprocessor"></span><span class="preprocessor">#define inline </span><span class="comment">/* inline */</span>
+<a name="l00084"></a>00084 <span class="preprocessor">#endif</span>
+<a name="l00085"></a>00085 <span class="preprocessor"></span>
+<a name="l00086"></a>00086 <span class="preprocessor">#define IRPLIB_MAX(A,B) ((A) > (B) ? (A) : (B))</span>
+<a name="l00087"></a>00087 <span class="preprocessor"></span><span class="preprocessor">#define IRPLIB_MIN(A,B) ((A) < (B) ? (A) : (B))</span>
+<a name="l00088"></a>00088 <span class="preprocessor"></span>
+<a name="l00089"></a>00089 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00090"></a>00090 <span class="comment">                                   Private functions</span>
+<a name="l00091"></a>00091 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00092"></a>00092 
+<a name="l00093"></a>00093 <span class="preprocessor">#ifdef HAVE_GSL</span>
+<a name="l00094"></a>00094 <span class="preprocessor"></span><span class="keyword">static</span> <span class="keywordtype">double</span> irplib_gsl_correlation(<span class="keyword">const</span> gsl_vector *, <span class="keywordtype">void</span> *);
+<a name="l00095"></a>00095 <span class="preprocessor">#endif</span>
+<a name="l00096"></a>00096 <span class="preprocessor"></span>
+<a name="l00097"></a>00097 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00101"></a>00101 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00102"></a>00102 
+<a name="l00106"></a>00106 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00114"></a>00114 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00115"></a><a class="code" href="group__irplib__wavecal.html#ga03d7f038adc7e18e7a9071581fa47a25">00115</a> <span class="keywordtype">int</span> <a class="code" href="group__irplib__wavecal.html#ga03d7f038adc7e18e7a9071581fa47a25" title="Count the positive Y-entries in a given X-range.">irplib_bivector_count_positive</a>(<span class="keyword">const</span> cpl_bivector * <span class="keyword">self</span>,
+<a name="l00116"></a>00116                                   <span class="keywordtype">double</span>               x_min,
+<a name="l00117"></a>00117                                   <span class="keywordtype">double</span>               x_max)
+<a name="l00118"></a>00118 {
+<a name="l00119"></a>00119 
+<a name="l00120"></a>00120     <span class="keyword">const</span> <span class="keywordtype">int</span>      nself = cpl_bivector_get_size(<span class="keyword">self</span>);
+<a name="l00121"></a>00121     <span class="keyword">const</span> <span class="keywordtype">double</span> * px    = cpl_bivector_get_x_data_const(<span class="keyword">self</span>);
+<a name="l00122"></a>00122     <span class="keyword">const</span> <span class="keywordtype">double</span> * py    = cpl_bivector_get_y_data_const(<span class="keyword">self</span>);
+<a name="l00123"></a>00123     <span class="keywordtype">int</span>            npos  = 0;
+<a name="l00124"></a>00124     <span class="keywordtype">int</span>            i     = 0;
+<a name="l00125"></a>00125 
+<a name="l00126"></a>00126     cpl_ensure(<span class="keyword">self</span> != NULL, CPL_ERROR_NULL_INPUT, -1);
+<a name="l00127"></a>00127     cpl_ensure(x_min <= x_max, CPL_ERROR_ILLEGAL_INPUT, -2);
+<a name="l00128"></a>00128     
+<a name="l00129"></a>00129     <span class="comment">/* FIXME: Use cpl_vector_find() */</span>
+<a name="l00130"></a>00130     <span class="keywordflow">while</span> (i < nself && px[i] < x_min) i++;
+<a name="l00131"></a>00131     <span class="keywordflow">while</span> (i < nself && px[i] < x_max)
+<a name="l00132"></a>00132         <span class="keywordflow">if</span> (py[i++] > 0) npos++;
+<a name="l00133"></a>00133 
+<a name="l00134"></a>00134     <span class="keywordflow">return</span> npos;
+<a name="l00135"></a>00135 }
+<a name="l00136"></a>00136 
+<a name="l00137"></a>00137 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00147"></a>00147 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00148"></a><a class="code" href="group__irplib__wavecal.html#ga2dd3251367e2ee8b8bd5ce080e9f31bb">00148</a> cpl_error_code <a class="code" href="group__irplib__wavecal.html#ga2dd3251367e2ee8b8bd5ce080e9f31bb" title="Fit a 2D-dispersion from an image of wavelengths.">irplib_polynomial_fit_2d_dispersion</a>(cpl_polynomial * <span class="keyword">self</span>,
+<a name="l00149"></a>00149                                                    <span class="keyword">const</span> cpl_image * imgwave,
+<a name="l00150"></a>00150                                                    <span class="keywordtype">int</span> fitdeg, <span class="keywordtype">double</span> * presid)
+<a name="l00151"></a>00151 {
+<a name="l00152"></a>00152 
+<a name="l00153"></a>00153     <span class="keyword">const</span> <span class="keywordtype">int</span>        nx = cpl_image_get_size_x(imgwave);
+<a name="l00154"></a>00154     <span class="keyword">const</span> <span class="keywordtype">int</span>        ny = cpl_image_get_size_y(imgwave);
+<a name="l00155"></a>00155     <span class="keyword">const</span> <span class="keywordtype">int</span>        nbad = cpl_image_count_rejected(imgwave);
+<a name="l00156"></a>00156     <span class="keyword">const</span> <span class="keywordtype">int</span>        nsamp = nx * ny - nbad;
+<a name="l00157"></a>00157     cpl_matrix     * xy_pos;
+<a name="l00158"></a>00158     <span class="keywordtype">double</span>         * xdata;
+<a name="l00159"></a>00159     <span class="keywordtype">double</span>         * ydata;
+<a name="l00160"></a>00160     cpl_vector     * wlen;
+<a name="l00161"></a>00161     <span class="keywordtype">double</span>         * dwlen;
+<a name="l00162"></a>00162     <span class="keyword">const</span> cpl_size   nfitdeg = (cpl_size)fitdeg;
+<a name="l00163"></a>00163     <span class="keywordtype">int</span> i, j;
+<a name="l00164"></a>00164     <span class="keywordtype">int</span> k = 0;
+<a name="l00165"></a>00165 
+<a name="l00166"></a>00166     cpl_ensure_code(<span class="keyword">self</span>    != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00167"></a>00167     cpl_ensure_code(imgwave != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00168"></a>00168     cpl_ensure_code(presid  != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00169"></a>00169     cpl_ensure_code(fitdeg > 0,      CPL_ERROR_ILLEGAL_INPUT);
+<a name="l00170"></a>00170 
+<a name="l00171"></a>00171     cpl_ensure_code(cpl_polynomial_get_dimension(<span class="keyword">self</span>) == 2,
+<a name="l00172"></a>00172                     CPL_ERROR_ILLEGAL_INPUT);
+<a name="l00173"></a>00173 
+<a name="l00174"></a>00174     xy_pos = cpl_matrix_new(2, nsamp);
+<a name="l00175"></a>00175     xdata = cpl_matrix_get_data(xy_pos);
+<a name="l00176"></a>00176     ydata = xdata + nsamp;
+<a name="l00177"></a>00177 
+<a name="l00178"></a>00178     dwlen = (<span class="keywordtype">double</span>*)cpl_malloc(nsamp * <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>));
+<a name="l00179"></a>00179     wlen = cpl_vector_wrap(nsamp, dwlen);
+<a name="l00180"></a>00180 
+<a name="l00181"></a>00181     <span class="keywordflow">for</span> (i=1; i <= nx; i++) {
+<a name="l00182"></a>00182         <span class="keywordflow">for</span> (j=1; j <= ny; j++) {
+<a name="l00183"></a>00183             <span class="keywordtype">int</span> is_bad;
+<a name="l00184"></a>00184             <span class="keyword">const</span> <span class="keywordtype">double</span> value = cpl_image_get(imgwave, i, j, &is_bad);
+<a name="l00185"></a>00185             <span class="keywordflow">if</span> (!is_bad) {
+<a name="l00186"></a>00186                 xdata[k] = i;
+<a name="l00187"></a>00187                 ydata[k] = j;
+<a name="l00188"></a>00188                 dwlen[k] = value;
+<a name="l00189"></a>00189                 k++;
+<a name="l00190"></a>00190             }
+<a name="l00191"></a>00191         }
+<a name="l00192"></a>00192     }
+<a name="l00193"></a>00193 
+<a name="l00194"></a>00194     cpl_msg_info(cpl_func, <span class="stringliteral">"Fitting 2D polynomial to %d X %d image, ignoring "</span>
+<a name="l00195"></a>00195                  <span class="stringliteral">"%d poorly calibrated pixels"</span>, nx, ny, nbad);
+<a name="l00196"></a>00196 
+<a name="l00197"></a>00197     <span class="keywordflow">if</span> (cpl_polynomial_fit(<span class="keyword">self</span>, xy_pos, NULL, wlen, NULL, CPL_FALSE, NULL,
+<a name="l00198"></a>00198                            &nfitdeg) == CPL_ERROR_NONE && presid != NULL) {
+<a name="l00199"></a>00199         cpl_vector_fill_polynomial_fit_residual(wlen, wlen, NULL, <span class="keyword">self</span>, xy_pos,
+<a name="l00200"></a>00200                                                 NULL);
+<a name="l00201"></a>00201         *presid = cpl_vector_product(wlen, wlen)/nsamp;
+<a name="l00202"></a>00202     }
+<a name="l00203"></a>00203     cpl_matrix_delete(xy_pos);
+<a name="l00204"></a>00204     cpl_vector_delete(wlen);
+<a name="l00205"></a>00205 
+<a name="l00206"></a>00206     cpl_ensure_code(k == nsamp, CPL_ERROR_UNSPECIFIED);
+<a name="l00207"></a>00207 
+<a name="l00208"></a>00208     <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l00209"></a>00209 }
+<a name="l00210"></a>00210 
+<a name="l00211"></a>00211 
+<a name="l00212"></a>00212 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00230"></a>00230 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00231"></a>00231 cpl_error_code
+<a name="l00232"></a><a class="code" href="group__irplib__wavecal.html#gaaa889f20c9483965ff6bab186d4f9972">00232</a> <a class="code" href="group__irplib__wavecal.html#gaaa889f20c9483965ff6bab186d4f9972" title="Modify self by maximizing the cross-correlation.">irplib_polynomial_find_1d_from_correlation</a>(cpl_polynomial * <span class="keyword">self</span>,
+<a name="l00233"></a>00233                                            <span class="keywordtype">int</span> maxdeg,
+<a name="l00234"></a>00234                                            <span class="keyword">const</span> cpl_vector * obs,
+<a name="l00235"></a>00235                                            irplib_base_spectrum_model * model,
+<a name="l00236"></a>00236                                            cpl_error_code (* filler)
+<a name="l00237"></a>00237                                            (cpl_vector *,
+<a name="l00238"></a>00238                                             <span class="keyword">const</span> cpl_polynomial *,
+<a name="l00239"></a>00239                                             irplib_base_spectrum_model *, <span class="keywordtype">int</span>),
+<a name="l00240"></a>00240                                            <span class="keywordtype">double</span> pixtol,
+<a name="l00241"></a>00241                                            <span class="keywordtype">double</span> pixstep,
+<a name="l00242"></a>00242                                            <span class="keywordtype">int</span> hsize,
+<a name="l00243"></a>00243                                            <span class="keywordtype">int</span> maxite,
+<a name="l00244"></a>00244                                            <span class="keywordtype">double</span> * pxc)
+<a name="l00245"></a>00245 {
+<a name="l00246"></a>00246 
+<a name="l00247"></a>00247 <span class="preprocessor">#ifdef HAVE_GSL</span>
+<a name="l00248"></a>00248 <span class="preprocessor"></span>    <span class="keyword">const</span> gsl_multimin_fminimizer_type * T = gsl_multimin_fminimizer_nmsimplex;
+<a name="l00249"></a>00249     gsl_multimin_fminimizer * minimizer;
+<a name="l00250"></a>00250     gsl_multimin_function my_func;
+<a name="l00251"></a>00251     irplib_multimin data;
+<a name="l00252"></a>00252     gsl_vector * dispgsl;
+<a name="l00253"></a>00253     gsl_vector * stepsize;
+<a name="l00254"></a>00254     gsl_vector * dispprev;
+<a name="l00255"></a>00255     <span class="keywordtype">int</span> status = GSL_CONTINUE;
+<a name="l00256"></a>00256     <span class="keyword">const</span> <span class="keywordtype">int</span> nobs = cpl_vector_get_size(obs);
+<a name="l00257"></a>00257     <span class="keyword">const</span> cpl_size nfit = maxdeg + 1;
+<a name="l00258"></a>00258     cpl_errorstate prestate = cpl_errorstate_get();
+<a name="l00259"></a>00259     <span class="comment">/* Convert pixel step to wavelength step on detector center */</span>
+<a name="l00260"></a>00260     <span class="keyword">const</span> <span class="keywordtype">double</span> wlstep =
+<a name="l00261"></a>00261         cpl_polynomial_eval_1d_diff(<span class="keyword">self</span>, 0.5 * (nobs + pixstep),
+<a name="l00262"></a>00262                                     0.5 * (nobs - pixstep), NULL);
+<a name="l00263"></a>00263     <span class="keywordtype">double</span> wlstepi = wlstep;
+<a name="l00264"></a>00264     <span class="keywordtype">double</span> size;
+<a name="l00265"></a>00265     <span class="keywordtype">int</span> iter;
+<a name="l00266"></a>00266     cpl_size i;
+<a name="l00267"></a>00267 
+<a name="l00268"></a>00268 <span class="preprocessor">#endif</span>
+<a name="l00269"></a>00269 <span class="preprocessor"></span>
+<a name="l00270"></a>00270     cpl_ensure_code(<span class="keyword">self</span>   != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00271"></a>00271     cpl_ensure_code(obs    != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00272"></a>00272     cpl_ensure_code(model  != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00273"></a>00273     cpl_ensure_code(filler != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00274"></a>00274     cpl_ensure_code(pxc    != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00275"></a>00275 
+<a name="l00276"></a>00276     cpl_ensure_code(cpl_polynomial_get_dimension(<span class="keyword">self</span>) == 1,
+<a name="l00277"></a>00277                     CPL_ERROR_ILLEGAL_INPUT);
+<a name="l00278"></a>00278 
+<a name="l00279"></a>00279     cpl_ensure_code(cpl_polynomial_get_degree(<span class="keyword">self</span>) > 0,
+<a name="l00280"></a>00280                     CPL_ERROR_ILLEGAL_INPUT);
+<a name="l00281"></a>00281 
+<a name="l00282"></a>00282     cpl_ensure_code(maxdeg  >=  0, CPL_ERROR_ILLEGAL_INPUT);
+<a name="l00283"></a>00283     cpl_ensure_code(pixtol  > 0.0, CPL_ERROR_ILLEGAL_INPUT);
+<a name="l00284"></a>00284     cpl_ensure_code(pixstep > 0.0, CPL_ERROR_ILLEGAL_INPUT);
+<a name="l00285"></a>00285     cpl_ensure_code(hsize   >=  0, CPL_ERROR_ILLEGAL_INPUT);
+<a name="l00286"></a>00286     cpl_ensure_code(maxite  >=  0, CPL_ERROR_ILLEGAL_INPUT);
+<a name="l00287"></a>00287 
+<a name="l00288"></a>00288 <span class="preprocessor">#ifndef HAVE_GSL</span>
+<a name="l00289"></a>00289 <span class="preprocessor"></span>    <span class="keywordflow">return</span> cpl_error_set_message(cpl_func, CPL_ERROR_UNSUPPORTED_MODE,
+<a name="l00290"></a>00290                                  <span class="stringliteral">"GSL is not available"</span>);
+<a name="l00291"></a>00291 <span class="preprocessor">#else</span>
+<a name="l00292"></a>00292 <span class="preprocessor"></span>
+<a name="l00293"></a>00293     minimizer = gsl_multimin_fminimizer_alloc(T, (<span class="keywordtype">size_t</span>)nfit);
+<a name="l00294"></a>00294 
+<a name="l00295"></a>00295     cpl_ensure_code(minimizer != NULL, CPL_ERROR_ILLEGAL_OUTPUT);
+<a name="l00296"></a>00296        
+<a name="l00297"></a>00297     dispgsl  = gsl_vector_alloc((<span class="keywordtype">size_t</span>)nfit);
+<a name="l00298"></a>00298     stepsize = gsl_vector_alloc((<span class="keywordtype">size_t</span>)nfit);
+<a name="l00299"></a>00299     dispprev = gsl_vector_alloc((<span class="keywordtype">size_t</span>)nfit);
+<a name="l00300"></a>00300 
+<a name="l00301"></a>00301     <span class="keywordflow">for</span> (i=0; i < nfit; i++) {
+<a name="l00302"></a>00302         <span class="keyword">const</span> <span class="keywordtype">double</span> value = cpl_polynomial_get_coeff(<span class="keyword">self</span>, &i);
+<a name="l00303"></a>00303         gsl_vector_set(dispgsl, (<span class="keywordtype">size_t</span>)i, value);
+<a name="l00304"></a>00304         gsl_vector_set(stepsize, (<span class="keywordtype">size_t</span>)i, wlstepi);
+<a name="l00305"></a>00305         wlstepi /= (double)nobs;
+<a name="l00306"></a>00306     }
+<a name="l00307"></a>00307 
+<a name="l00308"></a>00308     my_func.n = nfit;
+<a name="l00309"></a>00309     my_func.f = &irplib_gsl_correlation;
+<a name="l00310"></a>00310     my_func.params = (<span class="keywordtype">void</span> *)(&data);
+<a name="l00311"></a>00311 
+<a name="l00312"></a>00312     data.observed = obs;
+<a name="l00313"></a>00313     data.disp1d   = <span class="keyword">self</span>;
+<a name="l00314"></a>00314     data.spectrum = cpl_vector_new(nobs + 2 * hsize);
+<a name="l00315"></a>00315     data.vxc      = cpl_vector_new(1 + 2 * hsize);
+<a name="l00316"></a>00316     data.param    = model;
+<a name="l00317"></a>00317     data.filler   = filler;
+<a name="l00318"></a>00318     data.maxxc    = 0; <span class="comment">/* Output */</span>
+<a name="l00319"></a>00319     data.ishift   = 0; <span class="comment">/* Output */</span>
+<a name="l00320"></a>00320     data.mxc      = -1.0; <span class="comment">/* Output */</span>
+<a name="l00321"></a>00321     data.mdisp    = NULL; <span class="comment">/* Output */</span>
+<a name="l00322"></a>00322 
+<a name="l00323"></a>00323     gsl_multimin_fminimizer_set (minimizer, &my_func, dispgsl, stepsize);
+<a name="l00324"></a>00324 
+<a name="l00325"></a>00325     <span class="keywordflow">for</span> (iter = 0; status == GSL_CONTINUE && iter < maxite; iter++) {
+<a name="l00326"></a>00326 
+<a name="l00327"></a>00327         <span class="keyword">const</span> <span class="keywordtype">double</span> fprev = minimizer->fval;
+<a name="l00328"></a>00328 
+<a name="l00329"></a>00329         gsl_vector_memcpy(dispprev, minimizer->x);
+<a name="l00330"></a>00330         status = gsl_multimin_fminimizer_iterate(minimizer);
+<a name="l00331"></a>00331 
+<a name="l00332"></a>00332         <span class="keywordflow">if</span> (status || !cpl_errorstate_is_equal(prestate)) <span class="keywordflow">break</span>;
+<a name="l00333"></a>00333 
+<a name="l00334"></a>00334         size = gsl_multimin_fminimizer_size (minimizer);
+<a name="l00335"></a>00335         status = gsl_multimin_test_size (size, pixtol);
+<a name="l00336"></a>00336      
+<a name="l00337"></a>00337         <span class="keywordflow">if</span> (status == GSL_SUCCESS) {
+<a name="l00338"></a>00338             cpl_msg_debug(cpl_func, <span class="stringliteral">"converged to minimum at"</span>);
+<a name="l00339"></a>00339 
+<a name="l00340"></a>00340             <span class="keywordflow">if</span> (nfit == 0) {
+<a name="l00341"></a>00341                 cpl_msg_debug(cpl_func, <span class="stringliteral">"%5d %g df() = %g size = %g"</span>, 
+<a name="l00342"></a>00342                               iter,
+<a name="l00343"></a>00343                               gsl_vector_get (minimizer->x, 0)
+<a name="l00344"></a>00344                               - gsl_vector_get (dispprev, 0), 
+<a name="l00345"></a>00345                               minimizer->fval - fprev, size);
+<a name="l00346"></a>00346             } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (nfit == 1) {
+<a name="l00347"></a>00347                 cpl_msg_debug(cpl_func, <span class="stringliteral">"%5d %g %g df() = %g size = %g"</span>, 
+<a name="l00348"></a>00348                               iter,
+<a name="l00349"></a>00349                               gsl_vector_get (minimizer->x, 0)
+<a name="l00350"></a>00350                               - gsl_vector_get (dispprev, 0), 
+<a name="l00351"></a>00351                               gsl_vector_get (minimizer->x, 1)
+<a name="l00352"></a>00352                               - gsl_vector_get (dispprev, 1), 
+<a name="l00353"></a>00353                               minimizer->fval - fprev, size);
+<a name="l00354"></a>00354             } <span class="keywordflow">else</span> {
+<a name="l00355"></a>00355                 cpl_msg_debug(cpl_func, <span class="stringliteral">"%5d %g %g %g df() = %g size = %g"</span>, 
+<a name="l00356"></a>00356                               iter,
+<a name="l00357"></a>00357                               gsl_vector_get (minimizer->x, 0)
+<a name="l00358"></a>00358                               - gsl_vector_get (dispprev, 0), 
+<a name="l00359"></a>00359                               gsl_vector_get (minimizer->x, 1)
+<a name="l00360"></a>00360                               - gsl_vector_get (dispprev, 1), 
+<a name="l00361"></a>00361                               gsl_vector_get (minimizer->x, 2)
+<a name="l00362"></a>00362                               - gsl_vector_get (dispprev, 2), 
+<a name="l00363"></a>00363                               minimizer->fval - fprev, size);
+<a name="l00364"></a>00364             }
+<a name="l00365"></a>00365         }
+<a name="l00366"></a>00366     }
+<a name="l00367"></a>00367 
+<a name="l00368"></a>00368     <span class="keywordflow">if</span> (status == GSL_SUCCESS && cpl_errorstate_is_equal(prestate)) {
+<a name="l00369"></a>00369         <span class="keywordflow">if</span> (data.mxc > -minimizer->fval) {
+<a name="l00370"></a>00370             *pxc = data.mxc;
+<a name="l00371"></a>00371             cpl_msg_warning(cpl_func, <span class="stringliteral">"Local maximum: %g(%d) > %g"</span>,
+<a name="l00372"></a>00372                             data.mxc, data.ishift, -minimizer->fval);
+<a name="l00373"></a>00373             cpl_polynomial_shift_1d(data.mdisp, 0, (<span class="keywordtype">double</span>)data.ishift);
+<a name="l00374"></a>00374             cpl_polynomial_copy(<span class="keyword">self</span>, data.mdisp);
+<a name="l00375"></a>00375             status = GSL_CONTINUE;
+<a name="l00376"></a>00376         } <span class="keywordflow">else</span> {
+<a name="l00377"></a>00377             *pxc = -minimizer->fval;
+<a name="l00378"></a>00378             <span class="keywordflow">for</span> (i=0; i < nfit; i++) {
+<a name="l00379"></a>00379                 <span class="keyword">const</span> <span class="keywordtype">double</span> value = gsl_vector_get(minimizer->x, i);
+<a name="l00380"></a>00380                 cpl_polynomial_set_coeff(<span class="keyword">self</span>, &i, value);
+<a name="l00381"></a>00381             }
+<a name="l00382"></a>00382         }
+<a name="l00383"></a>00383     }
+<a name="l00384"></a>00384 
+<a name="l00385"></a>00385     cpl_vector_delete(data.spectrum);
+<a name="l00386"></a>00386     cpl_vector_delete(data.vxc);
+<a name="l00387"></a>00387     cpl_polynomial_delete(data.mdisp);
+<a name="l00388"></a>00388     gsl_multimin_fminimizer_free(minimizer);
+<a name="l00389"></a>00389     gsl_vector_free(dispgsl);
+<a name="l00390"></a>00390     gsl_vector_free(dispprev);
+<a name="l00391"></a>00391     gsl_vector_free(stepsize);
+<a name="l00392"></a>00392 
+<a name="l00393"></a>00393     cpl_ensure_code(status != GSL_CONTINUE, CPL_ERROR_CONTINUE);
+<a name="l00394"></a>00394     cpl_ensure_code(status == GSL_SUCCESS, CPL_ERROR_DATA_NOT_FOUND);
+<a name="l00395"></a>00395     cpl_ensure_code(cpl_errorstate_is_equal(prestate), cpl_error_get_code());
+<a name="l00396"></a>00396 
+<a name="l00397"></a>00397     <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l00398"></a>00398 <span class="preprocessor">#endif</span>
+<a name="l00399"></a>00399 <span class="preprocessor"></span>}
+<a name="l00400"></a>00400 
+<a name="l00401"></a>00401 
+<a name="l00402"></a>00402 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00431"></a>00431 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00432"></a>00432 cpl_error_code
+<a name="l00433"></a><a class="code" href="group__irplib__wavecal.html#ga44aa21cb1fc1459ab3b360748a737974">00433</a> <a class="code" href="group__irplib__wavecal.html#ga44aa21cb1fc1459ab3b360748a737974" title="Generate a 1D spectrum from a model and a dispersion relation.">irplib_vector_fill_line_spectrum</a>(cpl_vector * <span class="keyword">self</span>,
+<a name="l00434"></a>00434                                  <span class="keyword">const</span> cpl_polynomial * disp,
+<a name="l00435"></a>00435                                  irplib_base_spectrum_model * lsslamp,
+<a name="l00436"></a>00436                                  <span class="keywordtype">int</span> hsize)
+<a name="l00437"></a>00437 {
+<a name="l00438"></a>00438 
+<a name="l00439"></a>00439     irplib_line_spectrum_model * arclamp
+<a name="l00440"></a>00440         = (irplib_line_spectrum_model *)lsslamp;
+<a name="l00441"></a>00441     cpl_error_code error;
+<a name="l00442"></a>00442 
+<a name="l00443"></a>00443     cpl_ensure_code(arclamp != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00444"></a>00444 
+<a name="l00445"></a>00445     arclamp->cost++;
+<a name="l00446"></a>00446 
+<a name="l00447"></a>00447     error = <a class="code" href="group__irplib__wavecal.html#ga0db5e24244f88b41627d5a385af81b33" title="Generate a 1D spectrum from (arc) lines and a dispersion relation.">irplib_vector_fill_line_spectrum_model</a>(<span class="keyword">self</span>,
+<a name="l00448"></a>00448                                                    arclamp->linepix,
+<a name="l00449"></a>00449                                                    arclamp->erftmp,
+<a name="l00450"></a>00450                                                    disp,
+<a name="l00451"></a>00451                                                    arclamp->lines,
+<a name="l00452"></a>00452                                                    arclamp->wslit,
+<a name="l00453"></a>00453                                                    arclamp->wfwhm,
+<a name="l00454"></a>00454                                                    arclamp->xtrunc,
+<a name="l00455"></a>00455                                                    hsize, CPL_FALSE, CPL_FALSE,
+<a name="l00456"></a>00456                                                    &(arclamp->ulines));
+<a name="l00457"></a>00457     cpl_ensure_code(!error, error);
+<a name="l00458"></a>00458 
+<a name="l00459"></a>00459     arclamp->xcost++;
+<a name="l00460"></a>00460 
+<a name="l00461"></a>00461     <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l00462"></a>00462 }
+<a name="l00463"></a>00463 
+<a name="l00464"></a>00464 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00478"></a>00478 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00479"></a>00479 cpl_error_code
+<a name="l00480"></a><a class="code" href="group__irplib__wavecal.html#ga631e29d63bc65109f458915b5d1c8bb9">00480</a> <a class="code" href="group__irplib__wavecal.html#ga631e29d63bc65109f458915b5d1c8bb9" title="Generate a 1D spectrum from a model and a dispersion relation.">irplib_vector_fill_logline_spectrum</a>(cpl_vector * <span class="keyword">self</span>,
+<a name="l00481"></a>00481                                     <span class="keyword">const</span> cpl_polynomial * disp,
+<a name="l00482"></a>00482                                     irplib_base_spectrum_model * lsslamp,
+<a name="l00483"></a>00483                                     <span class="keywordtype">int</span> hsize)
+<a name="l00484"></a>00484 {
+<a name="l00485"></a>00485 
+<a name="l00486"></a>00486     irplib_line_spectrum_model * arclamp
+<a name="l00487"></a>00487         = (irplib_line_spectrum_model *)lsslamp;
+<a name="l00488"></a>00488     cpl_error_code error;
+<a name="l00489"></a>00489 
+<a name="l00490"></a>00490     cpl_ensure_code(arclamp != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00491"></a>00491 
+<a name="l00492"></a>00492     arclamp->cost++;
+<a name="l00493"></a>00493 
+<a name="l00494"></a>00494     error = <a class="code" href="group__irplib__wavecal.html#ga0db5e24244f88b41627d5a385af81b33" title="Generate a 1D spectrum from (arc) lines and a dispersion relation.">irplib_vector_fill_line_spectrum_model</a>(<span class="keyword">self</span>,
+<a name="l00495"></a>00495                                                    arclamp->linepix,
+<a name="l00496"></a>00496                                                    arclamp->erftmp,
+<a name="l00497"></a>00497                                                    disp,
+<a name="l00498"></a>00498                                                    arclamp->lines,
+<a name="l00499"></a>00499                                                    arclamp->wslit,
+<a name="l00500"></a>00500                                                    arclamp->wfwhm,
+<a name="l00501"></a>00501                                                    arclamp->xtrunc,
+<a name="l00502"></a>00502                                                    hsize, CPL_FALSE, CPL_TRUE,
+<a name="l00503"></a>00503                                                    &(arclamp->ulines));
+<a name="l00504"></a>00504     cpl_ensure_code(!error, error);
+<a name="l00505"></a>00505 
+<a name="l00506"></a>00506     arclamp->xcost++;
+<a name="l00507"></a>00507 
+<a name="l00508"></a>00508     <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l00509"></a>00509 }
+<a name="l00510"></a>00510 
+<a name="l00511"></a>00511 
+<a name="l00512"></a>00512 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00526"></a>00526 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00527"></a>00527 cpl_error_code
+<a name="l00528"></a><a class="code" href="group__irplib__wavecal.html#gae8e236a419dedc99eab52690f4a33901">00528</a> <a class="code" href="group__irplib__wavecal.html#gae8e236a419dedc99eab52690f4a33901" title="Generate a 1D spectrum from a model and a dispersion relation.">irplib_vector_fill_line_spectrum_fast</a>(cpl_vector * <span class="keyword">self</span>,
+<a name="l00529"></a>00529                                       <span class="keyword">const</span> cpl_polynomial * disp,
+<a name="l00530"></a>00530                                       irplib_base_spectrum_model * lsslamp,
+<a name="l00531"></a>00531                                       <span class="keywordtype">int</span> hsize)
+<a name="l00532"></a>00532 {
+<a name="l00533"></a>00533 
+<a name="l00534"></a>00534     irplib_line_spectrum_model * arclamp
+<a name="l00535"></a>00535         = (irplib_line_spectrum_model *)lsslamp;
+<a name="l00536"></a>00536     cpl_error_code error;
+<a name="l00537"></a>00537 
+<a name="l00538"></a>00538     cpl_ensure_code(arclamp != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00539"></a>00539 
+<a name="l00540"></a>00540     arclamp->cost++;
+<a name="l00541"></a>00541 
+<a name="l00542"></a>00542     error = <a class="code" href="group__irplib__wavecal.html#ga0db5e24244f88b41627d5a385af81b33" title="Generate a 1D spectrum from (arc) lines and a dispersion relation.">irplib_vector_fill_line_spectrum_model</a>(<span class="keyword">self</span>,
+<a name="l00543"></a>00543                                                    arclamp->linepix,
+<a name="l00544"></a>00544                                                    arclamp->erftmp,
+<a name="l00545"></a>00545                                                    disp,
+<a name="l00546"></a>00546                                                    arclamp->lines,
+<a name="l00547"></a>00547                                                    arclamp->wslit,
+<a name="l00548"></a>00548                                                    arclamp->wfwhm,
+<a name="l00549"></a>00549                                                    arclamp->xtrunc,
+<a name="l00550"></a>00550                                                    hsize, CPL_TRUE, CPL_FALSE,
+<a name="l00551"></a>00551                                                    &(arclamp->ulines));
+<a name="l00552"></a>00552     cpl_ensure_code(!error, error);
+<a name="l00553"></a>00553 
+<a name="l00554"></a>00554     arclamp->xcost++;
+<a name="l00555"></a>00555 
+<a name="l00556"></a>00556     <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l00557"></a>00557 }
+<a name="l00558"></a>00558 
+<a name="l00559"></a>00559 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00573"></a>00573 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00574"></a>00574 cpl_error_code
+<a name="l00575"></a><a class="code" href="group__irplib__wavecal.html#gaa0000d5a34e290fc93dfcc936e631eb7">00575</a> <a class="code" href="group__irplib__wavecal.html#gaa0000d5a34e290fc93dfcc936e631eb7" title="Generate a 1D spectrum from a model and a dispersion relation.">irplib_vector_fill_logline_spectrum_fast</a>(cpl_vector * <span class="keyword">self</span>,
+<a name="l00576"></a>00576                                          <span class="keyword">const</span> cpl_polynomial * disp,
+<a name="l00577"></a>00577                                          irplib_base_spectrum_model * lsslamp,
+<a name="l00578"></a>00578                                          <span class="keywordtype">int</span> hsize)
+<a name="l00579"></a>00579 {
+<a name="l00580"></a>00580 
+<a name="l00581"></a>00581     irplib_line_spectrum_model * arclamp
+<a name="l00582"></a>00582         = (irplib_line_spectrum_model *)lsslamp;
+<a name="l00583"></a>00583     cpl_error_code error;
+<a name="l00584"></a>00584 
+<a name="l00585"></a>00585     cpl_ensure_code(arclamp != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00586"></a>00586 
+<a name="l00587"></a>00587     arclamp->cost++;
+<a name="l00588"></a>00588 
+<a name="l00589"></a>00589     error = <a class="code" href="group__irplib__wavecal.html#ga0db5e24244f88b41627d5a385af81b33" title="Generate a 1D spectrum from (arc) lines and a dispersion relation.">irplib_vector_fill_line_spectrum_model</a>(<span class="keyword">self</span>,
+<a name="l00590"></a>00590                                                    arclamp->linepix,
+<a name="l00591"></a>00591                                                    arclamp->erftmp,
+<a name="l00592"></a>00592                                                    disp,
+<a name="l00593"></a>00593                                                    arclamp->lines,
+<a name="l00594"></a>00594                                                    arclamp->wslit,
+<a name="l00595"></a>00595                                                    arclamp->wfwhm,
+<a name="l00596"></a>00596                                                    arclamp->xtrunc,
+<a name="l00597"></a>00597                                                    hsize, CPL_TRUE, CPL_TRUE,
+<a name="l00598"></a>00598                                                    &(arclamp->ulines));
+<a name="l00599"></a>00599     cpl_ensure_code(!error, error);
+<a name="l00600"></a>00600 
+<a name="l00601"></a>00601     arclamp->xcost++;
+<a name="l00602"></a>00602 
+<a name="l00603"></a>00603     <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l00604"></a>00604 }
+<a name="l00605"></a>00605 
+<a name="l00606"></a>00606 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00617"></a>00617 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00618"></a><a class="code" href="group__irplib__wavecal.html#ga7eec8e48f4888aba01b98d9e0dc2acc5">00618</a> cpl_error_code <a class="code" href="group__irplib__wavecal.html#ga7eec8e48f4888aba01b98d9e0dc2acc5" title="Plot a 1D spectrum and one from a model.">irplib_plot_spectrum_and_model</a>(<span class="keyword">const</span> cpl_vector * <span class="keyword">self</span>,
+<a name="l00619"></a>00619                                               <span class="keyword">const</span> cpl_polynomial * disp1d,
+<a name="l00620"></a>00620                                               irplib_base_spectrum_model * model,
+<a name="l00621"></a>00621                                               cpl_error_code (* filler)
+<a name="l00622"></a>00622                                               (cpl_vector *,
+<a name="l00623"></a>00623                                                <span class="keyword">const</span> cpl_polynomial *,
+<a name="l00624"></a>00624                                                irplib_base_spectrum_model *,
+<a name="l00625"></a>00625                                                <span class="keywordtype">int</span>))
+<a name="l00626"></a>00626 {
+<a name="l00627"></a>00627 
+<a name="l00628"></a>00628     cpl_errorstate prestate = cpl_errorstate_get();
+<a name="l00629"></a>00629     cpl_vector * wl;
+<a name="l00630"></a>00630     cpl_vector * spectrum;
+<a name="l00631"></a>00631     cpl_vector * vxc;
+<a name="l00632"></a>00632     <span class="keyword">const</span> <span class="keywordtype">int</span> len = cpl_vector_get_size(<span class="keyword">self</span>);
+<a name="l00633"></a>00633     <span class="keywordtype">double</span> maxval, xc;
+<a name="l00634"></a>00634     <span class="keywordtype">int</span> ixc;
+<a name="l00635"></a>00635     <span class="keywordtype">int</span> error = 0;
+<a name="l00636"></a>00636 
+<a name="l00637"></a>00637     cpl_ensure_code(<span class="keyword">self</span>   != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00638"></a>00638     cpl_ensure_code(disp1d != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00639"></a>00639     cpl_ensure_code(model  != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00640"></a>00640     cpl_ensure_code(filler != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00641"></a>00641 
+<a name="l00642"></a>00642     cpl_ensure_code(cpl_polynomial_get_dimension(disp1d) == 1,
+<a name="l00643"></a>00643                     CPL_ERROR_ILLEGAL_INPUT);
+<a name="l00644"></a>00644 
+<a name="l00645"></a>00645     cpl_ensure_code(cpl_polynomial_get_degree(disp1d) > 0,
+<a name="l00646"></a>00646                     CPL_ERROR_ILLEGAL_INPUT);
+<a name="l00647"></a>00647 
+<a name="l00648"></a>00648     wl = cpl_vector_new(len);
+<a name="l00649"></a>00649     spectrum = cpl_vector_new(len);
+<a name="l00650"></a>00650     vxc = cpl_vector_new(1);
+<a name="l00651"></a>00651 
+<a name="l00652"></a>00652     error |= (int)cpl_vector_fill_polynomial(wl, disp1d, 1.0, 1.0);
+<a name="l00653"></a>00653     error |= filler(spectrum, disp1d, model, 0);
+<a name="l00654"></a>00654 
+<a name="l00655"></a>00655     ixc = cpl_vector_correlate(vxc, <span class="keyword">self</span>, spectrum);
+<a name="l00656"></a>00656     xc = cpl_vector_get(vxc, ixc);
+<a name="l00657"></a>00657 
+<a name="l00658"></a>00658     maxval = cpl_vector_get_max(spectrum);
+<a name="l00659"></a>00659     <span class="keywordflow">if</span> (maxval != 0.0) 
+<a name="l00660"></a>00660         error |= cpl_vector_multiply_scalar(spectrum,
+<a name="l00661"></a>00661                                              cpl_vector_get_max(<span class="keyword">self</span>)/maxval);
+<a name="l00662"></a>00662     <span class="keywordflow">if</span> (!error) {
+<a name="l00663"></a>00663         <span class="keyword">const</span> cpl_vector * spair[] = {wl, <span class="keyword">self</span>, spectrum};
+<a name="l00664"></a>00664         <span class="keywordtype">char</span> * pre = cpl_sprintf(<span class="stringliteral">"set grid;set xlabel 'Wavelength (%g -> %g)'; "</span>
+<a name="l00665"></a>00665                                  <span class="stringliteral">"set ylabel 'Intensity';"</span>, cpl_vector_get(wl, 0),
+<a name="l00666"></a>00666                                  cpl_vector_get(wl, len-1));
+<a name="l00667"></a>00667         <span class="keywordtype">char</span> * title = cpl_sprintf(<span class="stringliteral">"t 'Observed and modelled spectra (%d pixel "</span>
+<a name="l00668"></a>00668                                    <span class="stringliteral">"XC=%g) ' w linespoints"</span>, len, xc);
+<a name="l00669"></a>00669 
+<a name="l00670"></a>00670         (void)cpl_plot_vectors(pre, title, <span class="stringliteral">""</span>, spair, 3);
+<a name="l00671"></a>00671         cpl_free(pre);
+<a name="l00672"></a>00672         cpl_free(title);
+<a name="l00673"></a>00673     }
+<a name="l00674"></a>00674 
+<a name="l00675"></a>00675     cpl_vector_delete(wl);
+<a name="l00676"></a>00676     cpl_vector_delete(spectrum);
+<a name="l00677"></a>00677     cpl_vector_delete(vxc);
+<a name="l00678"></a>00678 
+<a name="l00679"></a>00679     cpl_errorstate_set(prestate);
+<a name="l00680"></a>00680 
+<a name="l00681"></a>00681     <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l00682"></a>00682 }
+<a name="l00683"></a>00683 
+<a name="l00684"></a>00684 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00702"></a>00702 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00703"></a>00703 cpl_error_code
+<a name="l00704"></a><a class="code" href="group__irplib__wavecal.html#gae027096b411661b9584c72ab3e8e6547">00704</a> <a class="code" href="group__irplib__wavecal.html#gae027096b411661b9584c72ab3e8e6547" title="Find shift(s) that maximizes (locally) the cross-correlation.">irplib_bivector_find_shift_from_correlation</a>(cpl_bivector * <span class="keyword">self</span>,
+<a name="l00705"></a>00705                                             <span class="keyword">const</span> cpl_polynomial * disp,
+<a name="l00706"></a>00706                                             <span class="keyword">const</span> cpl_vector * obs,
+<a name="l00707"></a>00707                                             irplib_base_spectrum_model * model,
+<a name="l00708"></a>00708                                             cpl_error_code (*filler)
+<a name="l00709"></a>00709                                             (cpl_vector *,
+<a name="l00710"></a>00710                                              <span class="keyword">const</span> cpl_polynomial *,
+<a name="l00711"></a>00711                                              irplib_base_spectrum_model *, <span class="keywordtype">int</span>),
+<a name="l00712"></a>00712                                             <span class="keywordtype">int</span> hsize,
+<a name="l00713"></a>00713                                             cpl_boolean doplot,
+<a name="l00714"></a>00714                                             <span class="keywordtype">double</span> *pxc)
+<a name="l00715"></a>00715 {
+<a name="l00716"></a>00716 
+<a name="l00717"></a>00717     <span class="keyword">const</span> <span class="keywordtype">int</span>      nobs   = cpl_vector_get_size(obs);
+<a name="l00718"></a>00718     <span class="keyword">const</span> <span class="keywordtype">int</span>      nmodel = 2 * hsize + nobs;
+<a name="l00719"></a>00719     cpl_vector   * xself = cpl_bivector_get_x(<span class="keyword">self</span>);
+<a name="l00720"></a>00720     cpl_vector   * yself = cpl_bivector_get_y(<span class="keyword">self</span>);
+<a name="l00721"></a>00721     cpl_vector   * mspec1d;
+<a name="l00722"></a>00722     cpl_vector   * xcorr;
+<a name="l00723"></a>00723     cpl_error_code error = CPL_ERROR_NONE;
+<a name="l00724"></a>00724     <span class="keywordtype">double</span>         xcprev, xcnext;
+<a name="l00725"></a>00725     <span class="keywordtype">int</span>            ixc, imax = 0;
+<a name="l00726"></a>00726     <span class="keywordtype">int</span> i;
+<a name="l00727"></a>00727 
+<a name="l00728"></a>00728     cpl_ensure_code(<span class="keyword">self</span>   != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00729"></a>00729     cpl_ensure_code(disp   != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00730"></a>00730     cpl_ensure_code(obs    != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00731"></a>00731     cpl_ensure_code(model  != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00732"></a>00732     cpl_ensure_code(filler != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00733"></a>00733     cpl_ensure_code(hsize  >  0,    CPL_ERROR_ILLEGAL_INPUT);
+<a name="l00734"></a>00734 
+<a name="l00735"></a>00735     mspec1d = cpl_vector_new(nmodel);
+<a name="l00736"></a>00736 
+<a name="l00737"></a>00737     <span class="keywordflow">if</span> (filler(mspec1d, disp, model, hsize)) {
+<a name="l00738"></a>00738         cpl_vector_delete(mspec1d);
+<a name="l00739"></a>00739         <span class="keywordflow">return</span> cpl_error_set_where(cpl_func);
+<a name="l00740"></a>00740     }
+<a name="l00741"></a>00741 
+<a name="l00742"></a>00742     <span class="comment">/* Should not be able to fail now */</span>
+<a name="l00743"></a>00743     xcorr = cpl_vector_new(1 + 2 * hsize);
+<a name="l00744"></a>00744     ixc = cpl_vector_correlate(xcorr, mspec1d, obs);
+<a name="l00745"></a>00745 
+<a name="l00746"></a>00746 <span class="preprocessor">#ifdef IRPLIB_SPC_DUMP</span>
+<a name="l00747"></a>00747 <span class="preprocessor"></span>    <span class="comment">/* Need irplib_wavecal.c rev. 1.12 through 1.15 */</span>
+<a name="l00748"></a>00748     irplib_polynomial_dump_corr_step(disp, xcorr, <span class="stringliteral">"Shift"</span>);
+<a name="l00749"></a>00749 <span class="preprocessor">#endif</span>
+<a name="l00750"></a>00750 <span class="preprocessor"></span>
+<a name="l00751"></a>00751     cpl_vector_delete(mspec1d);
+<a name="l00752"></a>00752 
+<a name="l00753"></a>00753     <span class="comment">/* Find local maxima. */</span>
+<a name="l00754"></a>00754     <span class="comment">/* FIXME(?): Also include stationary points */</span>
+<a name="l00755"></a>00755     i = 0;
+<a name="l00756"></a>00756     xcprev = cpl_vector_get(xcorr, i);
+<a name="l00757"></a>00757     xcnext = cpl_vector_get(xcorr, i+1);
+<a name="l00758"></a>00758 
+<a name="l00759"></a>00759     <span class="keywordflow">if</span> (xcprev >= xcnext) {
+<a name="l00760"></a>00760         <span class="comment">/* 1st data point is an extreme */</span>
+<a name="l00761"></a>00761         <span class="comment">/* FIXME: This could also be an error, recoverable by caller by</span>
+<a name="l00762"></a>00762 <span class="comment">           increasing hsize */</span>
+<a name="l00763"></a>00763         imax++;
+<a name="l00764"></a>00764 
+<a name="l00765"></a>00765         cpl_vector_set(xself, 0, i - hsize);
+<a name="l00766"></a>00766         cpl_vector_set(yself, 0, xcprev);
+<a name="l00767"></a>00767 
+<a name="l00768"></a>00768     }
+<a name="l00769"></a>00769 
+<a name="l00770"></a>00770     <span class="keywordflow">for</span> (i = 1; i < 2 * hsize; i++) {
+<a name="l00771"></a>00771         <span class="keyword">const</span> <span class="keywordtype">double</span> xc = xcnext;
+<a name="l00772"></a>00772         xcnext = cpl_vector_get(xcorr, i+1);
+<a name="l00773"></a>00773         <span class="keywordflow">if</span> (xc >= xcprev && xc >= xcnext) {
+<a name="l00774"></a>00774             <span class="comment">/* Found (local) maximum at shift i - hsize */</span>
+<a name="l00775"></a>00775             <span class="keywordtype">int</span> j;
+<a name="l00776"></a>00776 
+<a name="l00777"></a>00777             imax++;
+<a name="l00778"></a>00778 
+<a name="l00779"></a>00779             <span class="keywordflow">if</span> (cpl_bivector_get_size(<span class="keyword">self</span>) < imax) {
+<a name="l00780"></a>00780                 cpl_vector_set_size(xself, imax);
+<a name="l00781"></a>00781                 cpl_vector_set_size(yself, imax);
+<a name="l00782"></a>00782             }
+<a name="l00783"></a>00783 
+<a name="l00784"></a>00784             <span class="keywordflow">for</span> (j = imax-1; j > 0; j--) {
+<a name="l00785"></a>00785                 <span class="keywordflow">if</span> (xc <= cpl_vector_get(yself, j-1)) <span class="keywordflow">break</span>;
+<a name="l00786"></a>00786                 cpl_vector_set(xself, j, cpl_vector_get(xself, j-1));
+<a name="l00787"></a>00787                 cpl_vector_set(yself, j, cpl_vector_get(yself, j-1));
+<a name="l00788"></a>00788             }
+<a name="l00789"></a>00789             cpl_vector_set(xself, j, i - hsize);
+<a name="l00790"></a>00790             cpl_vector_set(yself, j, xc);
+<a name="l00791"></a>00791         }
+<a name="l00792"></a>00792         xcprev = xc;
+<a name="l00793"></a>00793     }
+<a name="l00794"></a>00794 
+<a name="l00795"></a>00795     <span class="comment">/* assert( i == 2 * hsize ); */</span>
+<a name="l00796"></a>00796 
+<a name="l00797"></a>00797     <span class="keywordflow">if</span> (xcnext >= xcprev) {
+<a name="l00798"></a>00798         <span class="comment">/* Last data point is an extreme */</span>
+<a name="l00799"></a>00799         <span class="comment">/* FIXME: This could also be an error, recoverable by caller by</span>
+<a name="l00800"></a>00800 <span class="comment">           increasing hsize */</span>
+<a name="l00801"></a>00801         <span class="keywordtype">int</span> j;
+<a name="l00802"></a>00802 
+<a name="l00803"></a>00803         imax++;
+<a name="l00804"></a>00804 
+<a name="l00805"></a>00805         <span class="keywordflow">if</span> (cpl_bivector_get_size(<span class="keyword">self</span>) < imax) {
+<a name="l00806"></a>00806             cpl_vector_set_size(xself, imax);
+<a name="l00807"></a>00807             cpl_vector_set_size(yself, imax);
+<a name="l00808"></a>00808         }
+<a name="l00809"></a>00809 
+<a name="l00810"></a>00810         <span class="keywordflow">for</span> (j = imax-1; j > 0; j--) {
+<a name="l00811"></a>00811             <span class="keywordflow">if</span> (xcnext <= cpl_vector_get(yself, j-1)) <span class="keywordflow">break</span>;
+<a name="l00812"></a>00812             cpl_vector_set(xself, j, cpl_vector_get(xself, j-1));
+<a name="l00813"></a>00813             cpl_vector_set(yself, j, cpl_vector_get(yself, j-1));
+<a name="l00814"></a>00814         }
+<a name="l00815"></a>00815         cpl_vector_set(xself, j, i - hsize);
+<a name="l00816"></a>00816         cpl_vector_set(yself, j, xcnext);
+<a name="l00817"></a>00817 
+<a name="l00818"></a>00818     }
+<a name="l00819"></a>00819 
+<a name="l00820"></a>00820     <span class="keywordflow">if</span> (doplot) {
+<a name="l00821"></a>00821         cpl_vector * xvals = cpl_vector_new(1 + 2 * hsize);
+<a name="l00822"></a>00822         cpl_bivector * bcorr = cpl_bivector_wrap_vectors(xvals, xcorr);
+<a name="l00823"></a>00823         <span class="keywordtype">double</span> x = (double)-hsize;
+<a name="l00824"></a>00824         <span class="keywordtype">char</span> * title = cpl_sprintf(<span class="stringliteral">"t 'Cross-correlation of shifted %d-pixel "</span>
+<a name="l00825"></a>00825                                    <span class="stringliteral">"spectrum (XCmax=%g at %d)' w linespoints"</span>,
+<a name="l00826"></a>00826                                    nobs, cpl_vector_get(xcorr, ixc),
+<a name="l00827"></a>00827                                    ixc - hsize);
+<a name="l00828"></a>00828 
+<a name="l00829"></a>00829         <span class="keywordflow">for</span> (i = 0; i < 1 + 2 * hsize; i++, x += 1.0) {
+<a name="l00830"></a>00830             cpl_vector_set(xvals, i, x);
+<a name="l00831"></a>00831         }
+<a name="l00832"></a>00832 
+<a name="l00833"></a>00833         cpl_plot_bivector(<span class="stringliteral">"set grid;set xlabel 'Offset [pixel]';"</span>, title,
+<a name="l00834"></a>00834                              <span class="stringliteral">""</span>, bcorr);
+<a name="l00835"></a>00835         cpl_bivector_unwrap_vectors(bcorr);
+<a name="l00836"></a>00836         cpl_vector_delete(xvals);
+<a name="l00837"></a>00837         cpl_free(title);
+<a name="l00838"></a>00838     }
+<a name="l00839"></a>00839 
+<a name="l00840"></a>00840     <span class="keywordflow">if</span> (pxc != NULL) *pxc = cpl_vector_get(xcorr, hsize);
+<a name="l00841"></a>00841 
+<a name="l00842"></a>00842     cpl_vector_delete(xcorr);
+<a name="l00843"></a>00843 
+<a name="l00844"></a>00844     <span class="keywordflow">if</span> (imax < 1) {
+<a name="l00845"></a>00845         error = CPL_ERROR_DATA_NOT_FOUND;
+<a name="l00846"></a>00846     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (cpl_bivector_get_size(<span class="keyword">self</span>) > imax) {
+<a name="l00847"></a>00847         cpl_vector_set_size(xself, imax);
+<a name="l00848"></a>00848         cpl_vector_set_size(yself, imax);
+<a name="l00849"></a>00849     }
+<a name="l00850"></a>00850 
+<a name="l00851"></a>00851     <span class="comment">/* Propagate error, if any */</span>
+<a name="l00852"></a>00852     <span class="keywordflow">return</span> cpl_error_set(cpl_func, error);
+<a name="l00853"></a>00853 }
+<a name="l00854"></a>00854 
+<a name="l00855"></a>00855 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00868"></a>00868 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00869"></a>00869 cpl_error_code
+<a name="l00870"></a><a class="code" href="group__irplib__wavecal.html#gabaec991ebc1b856766bf66768c4a6a19">00870</a> <a class="code" href="group__irplib__wavecal.html#gabaec991ebc1b856766bf66768c4a6a19" title="Shift self by the amount that maximizes the cross-correlation.">irplib_polynomial_shift_1d_from_correlation</a>(cpl_polynomial * <span class="keyword">self</span>,
+<a name="l00871"></a>00871                                             <span class="keyword">const</span> cpl_vector * obs,
+<a name="l00872"></a>00872                                             irplib_base_spectrum_model * model,
+<a name="l00873"></a>00873                                             cpl_error_code (*filler)
+<a name="l00874"></a>00874                                             (cpl_vector *,
+<a name="l00875"></a>00875                                              <span class="keyword">const</span> cpl_polynomial *,
+<a name="l00876"></a>00876                                              irplib_base_spectrum_model *, <span class="keywordtype">int</span>),
+<a name="l00877"></a>00877                                             <span class="keywordtype">int</span> hsize,
+<a name="l00878"></a>00878                                             cpl_boolean doplot,
+<a name="l00879"></a>00879                                             <span class="keywordtype">double</span> * pxc)
+<a name="l00880"></a>00880 {
+<a name="l00881"></a>00881 
+<a name="l00882"></a>00882     <span class="keyword">const</span> <span class="keywordtype">int</span>      nobs   = cpl_vector_get_size(obs);
+<a name="l00883"></a>00883     <span class="keyword">const</span> <span class="keywordtype">int</span>      nmodel = 2 * hsize + nobs;
+<a name="l00884"></a>00884     cpl_vector   * mspec1d;
+<a name="l00885"></a>00885     cpl_vector   * xcorr;
+<a name="l00886"></a>00886     cpl_error_code error;
+<a name="l00887"></a>00887     <span class="keywordtype">int</span>            ixc, xxc;
+<a name="l00888"></a>00888     <span class="keywordtype">double</span>         xc;
+<a name="l00889"></a>00889 
+<a name="l00890"></a>00890     cpl_ensure_code(<span class="keyword">self</span>   != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00891"></a>00891     cpl_ensure_code(obs    != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00892"></a>00892     cpl_ensure_code(model  != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00893"></a>00893     cpl_ensure_code(filler != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00894"></a>00894     cpl_ensure_code(hsize  >  0,    CPL_ERROR_ILLEGAL_INPUT);
+<a name="l00895"></a>00895 
+<a name="l00896"></a>00896     mspec1d = cpl_vector_new(nmodel);
+<a name="l00897"></a>00897 
+<a name="l00898"></a>00898     <span class="keywordflow">if</span> (filler(mspec1d, <span class="keyword">self</span>, model, hsize)) {
+<a name="l00899"></a>00899         cpl_vector_delete(mspec1d);
+<a name="l00900"></a>00900         cpl_ensure_code(0, cpl_error_get_code());
+<a name="l00901"></a>00901     }
+<a name="l00902"></a>00902 
+<a name="l00903"></a>00903     <span class="comment">/* Should not be able to fail now */</span>
+<a name="l00904"></a>00904     xcorr = cpl_vector_new(1 + 2 * hsize);
+<a name="l00905"></a>00905     ixc = cpl_vector_correlate(xcorr, mspec1d, obs);
+<a name="l00906"></a>00906 
+<a name="l00907"></a>00907 <span class="preprocessor">#ifdef IRPLIB_SPC_DUMP</span>
+<a name="l00908"></a>00908 <span class="preprocessor"></span>    <span class="comment">/* Need irplib_wavecal.c rev. 1.12 through 1.15 */</span>
+<a name="l00909"></a>00909     irplib_polynomial_dump_corr_step(<span class="keyword">self</span>, xcorr, <span class="stringliteral">"Shift"</span>);
+<a name="l00910"></a>00910 <span class="preprocessor">#endif</span>
+<a name="l00911"></a>00911 <span class="preprocessor"></span>
+<a name="l00912"></a>00912     cpl_vector_delete(mspec1d);
+<a name="l00913"></a>00913 
+<a name="l00914"></a>00914     xxc = ixc - hsize;
+<a name="l00915"></a>00915 
+<a name="l00916"></a>00916     error = cpl_polynomial_shift_1d(<span class="keyword">self</span>, 0, (<span class="keywordtype">double</span>)xxc);
+<a name="l00917"></a>00917 
+<a name="l00918"></a>00918     xc = cpl_vector_get(xcorr, ixc);
+<a name="l00919"></a>00919 
+<a name="l00920"></a>00920     cpl_msg_info(cpl_func, <span class="stringliteral">"Shifting %d pixels (%g < %g)"</span>, xxc,
+<a name="l00921"></a>00921                  cpl_vector_get(xcorr, hsize), xc);
+<a name="l00922"></a>00922 
+<a name="l00923"></a>00923     <span class="keywordflow">if</span> (doplot) {
+<a name="l00924"></a>00924         cpl_vector * xvals = cpl_vector_new(1 + 2 * hsize);
+<a name="l00925"></a>00925         cpl_bivector * bcorr = cpl_bivector_wrap_vectors(xvals, xcorr);
+<a name="l00926"></a>00926         <span class="keywordtype">int</span> i;
+<a name="l00927"></a>00927         <span class="keywordtype">double</span> x = (double)-hsize;
+<a name="l00928"></a>00928         <span class="keywordtype">char</span> * title = cpl_sprintf(<span class="stringliteral">"t 'Cross-correlation of shifted %d-pixel "</span>
+<a name="l00929"></a>00929                                    <span class="stringliteral">"spectrum (XCmax=%g at %d)' w linespoints"</span>,
+<a name="l00930"></a>00930                                    nobs, cpl_vector_get(xcorr, ixc), xxc);
+<a name="l00931"></a>00931 
+<a name="l00932"></a>00932         <span class="keywordflow">for</span> (i = 0; i < 1 + 2 * hsize; i++, x += 1.0) {
+<a name="l00933"></a>00933             cpl_vector_set(xvals, i, x);
+<a name="l00934"></a>00934         }
+<a name="l00935"></a>00935 
+<a name="l00936"></a>00936         cpl_plot_bivector(<span class="stringliteral">"set grid;set xlabel 'Offset [pixel]';"</span>, title,
+<a name="l00937"></a>00937                              <span class="stringliteral">""</span>, bcorr);
+<a name="l00938"></a>00938         cpl_bivector_unwrap_vectors(bcorr);
+<a name="l00939"></a>00939         cpl_vector_delete(xvals);
+<a name="l00940"></a>00940         cpl_free(title);
+<a name="l00941"></a>00941     }
+<a name="l00942"></a>00942 
+<a name="l00943"></a>00943     cpl_vector_delete(xcorr);
+<a name="l00944"></a>00944 
+<a name="l00945"></a>00945     cpl_ensure_code(!error, error);
+<a name="l00946"></a>00946 
+<a name="l00947"></a>00947     <span class="keywordflow">if</span> (pxc != NULL) *pxc = xc;
+<a name="l00948"></a>00948 
+<a name="l00949"></a>00949     <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l00950"></a>00950 
+<a name="l00951"></a>00951 }
+<a name="l00952"></a>00952 
+<a name="l00953"></a>00953 
+<a name="l00954"></a>00954 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00974"></a>00974 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00975"></a>00975 cpl_error_code
+<a name="l00976"></a><a class="code" href="group__irplib__wavecal.html#ga0db5e24244f88b41627d5a385af81b33">00976</a> <a class="code" href="group__irplib__wavecal.html#ga0db5e24244f88b41627d5a385af81b33" title="Generate a 1D spectrum from (arc) lines and a dispersion relation.">irplib_vector_fill_line_spectrum_model</a>(cpl_vector * <span class="keyword">self</span>,
+<a name="l00977"></a>00977                                        cpl_vector * linepix,
+<a name="l00978"></a>00978                                        cpl_vector * erftmp,
+<a name="l00979"></a>00979                                        <span class="keyword">const</span> cpl_polynomial * disp,
+<a name="l00980"></a>00980                                        <span class="keyword">const</span> cpl_bivector * lines,
+<a name="l00981"></a>00981                                        <span class="keywordtype">double</span> wslit,
+<a name="l00982"></a>00982                                        <span class="keywordtype">double</span> wfwhm,
+<a name="l00983"></a>00983                                        <span class="keywordtype">double</span> xtrunc,
+<a name="l00984"></a>00984                                        <span class="keywordtype">int</span> hsize,
+<a name="l00985"></a>00985                                        cpl_boolean dofast,
+<a name="l00986"></a>00986                                        cpl_boolean dolog,
+<a name="l00987"></a>00987                                        <span class="keywordtype">unsigned</span> * pulines)
+<a name="l00988"></a>00988 {
+<a name="l00989"></a>00989 
+<a name="l00990"></a>00990     cpl_errorstate     prestate;
+<a name="l00991"></a>00991     <span class="keyword">const</span> <span class="keywordtype">double</span>       sigma = wfwhm * CPL_MATH_SIG_FWHM;
+<a name="l00992"></a>00992     <span class="keyword">const</span> cpl_vector * xlines  = cpl_bivector_get_x_const(lines);
+<a name="l00993"></a>00993     <span class="keyword">const</span> <span class="keywordtype">double</span>     * dxlines = cpl_vector_get_data_const(xlines);
+<a name="l00994"></a>00994     <span class="keyword">const</span> <span class="keywordtype">double</span>     * dylines = cpl_bivector_get_y_data_const(lines);
+<a name="l00995"></a>00995     <span class="keywordtype">double</span>           * plinepix
+<a name="l00996"></a>00996         = linepix ? cpl_vector_get_data(linepix) : NULL;
+<a name="l00997"></a>00997     <span class="keyword">const</span> <span class="keywordtype">int</span>          nlines  = cpl_vector_get_size(xlines);
+<a name="l00998"></a>00998     <span class="keyword">const</span> <span class="keywordtype">int</span>          nself   = cpl_vector_get_size(<span class="keyword">self</span>);
+<a name="l00999"></a>00999     <span class="keywordtype">double</span>           * dself   = cpl_vector_get_data(<span class="keyword">self</span>);
+<a name="l01000"></a>01000     cpl_polynomial   * dispi;
+<a name="l01001"></a>01001     <span class="keywordtype">double</span>           * profile = NULL;
+<a name="l01002"></a>01002     <span class="keyword">const</span> cpl_size     i0 = 0;
+<a name="l01003"></a>01003     <span class="keyword">const</span> <span class="keywordtype">double</span>       p0 = cpl_polynomial_get_coeff(disp, &i0);
+<a name="l01004"></a>01004     <span class="keywordtype">double</span>             wl;
+<a name="l01005"></a>01005     <span class="keywordtype">double</span>             xpos = (double)(1-hsize)-xtrunc;
+<a name="l01006"></a>01006     <span class="keyword">const</span> <span class="keywordtype">double</span>       xmax = (double)(nself-hsize)+xtrunc;
+<a name="l01007"></a>01007     <span class="keywordtype">double</span>             xderiv, xextreme;
+<a name="l01008"></a>01008     cpl_error_code     error = CPL_ERROR_NONE;
+<a name="l01009"></a>01009     <span class="keywordtype">int</span>                iline;
+<a name="l01010"></a>01010     <span class="keywordtype">unsigned</span>           ulines = 0;
+<a name="l01011"></a>01011 
+<a name="l01012"></a>01012     cpl_ensure_code(<span class="keyword">self</span>    != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l01013"></a>01013     cpl_ensure_code(disp    != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l01014"></a>01014     cpl_ensure_code(lines   != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l01015"></a>01015 
+<a name="l01016"></a>01016     cpl_ensure_code(wslit  >  0.0, CPL_ERROR_ILLEGAL_INPUT);
+<a name="l01017"></a>01017     cpl_ensure_code(wfwhm  >  0.0, CPL_ERROR_ILLEGAL_INPUT);
+<a name="l01018"></a>01018     cpl_ensure_code(hsize  >= 0,   CPL_ERROR_ILLEGAL_INPUT);
+<a name="l01019"></a>01019     cpl_ensure_code(xtrunc >  0.0, CPL_ERROR_ILLEGAL_INPUT);
+<a name="l01020"></a>01020     cpl_ensure_code(nself  > 2 * hsize, CPL_ERROR_ILLEGAL_INPUT);
+<a name="l01021"></a>01021 
+<a name="l01022"></a>01022     cpl_ensure_code(cpl_polynomial_get_dimension(disp) == 1,
+<a name="l01023"></a>01023                     CPL_ERROR_ILLEGAL_INPUT);
+<a name="l01024"></a>01024     cpl_ensure_code(cpl_polynomial_get_degree(disp) > 0,
+<a name="l01025"></a>01025                     CPL_ERROR_ILLEGAL_INPUT);
+<a name="l01026"></a>01026 
+<a name="l01027"></a>01027     <span class="comment">/* The smallest wavelength contributing to the spectrum. */</span>
+<a name="l01028"></a>01028     wl = cpl_polynomial_eval_1d(disp, xpos, &xderiv);
+<a name="l01029"></a>01029 
+<a name="l01030"></a>01030     <span class="keywordflow">if</span> (wl <= 0.0) <span class="keywordflow">return</span>
+<a name="l01031"></a>01031         cpl_error_set_message_macro(cpl_func, CPL_ERROR_ILLEGAL_INPUT, __FILE__,
+<a name="l01032"></a>01032                                     __LINE__, <span class="stringliteral">"Non-positive wavelength at x=%g: "</span>
+<a name="l01033"></a>01033                                     <span class="stringliteral">"P(x)=%g, P'(x)=%g"</span>, xpos, wl, xderiv);
+<a name="l01034"></a>01034 
+<a name="l01035"></a>01035     <span class="keywordflow">if</span> (xderiv <= 0.0) <span class="keywordflow">return</span>
+<a name="l01036"></a>01036         cpl_error_set_message_macro(cpl_func, CPL_ERROR_ILLEGAL_INPUT, __FILE__,
+<a name="l01037"></a>01037                                     __LINE__, <span class="stringliteral">"Non-increasing dispersion at "</span>
+<a name="l01038"></a>01038                                     <span class="stringliteral">"x=%g: P'(x)=%g, P(x)=%g"</span>, xpos, xderiv, wl);
+<a name="l01039"></a>01039 
+<a name="l01040"></a>01040     <span class="comment">/* Find the 1st line */</span>
+<a name="l01041"></a>01041     iline = cpl_vector_find(xlines, wl);
+<a name="l01042"></a>01042 
+<a name="l01043"></a>01043     <span class="comment">/* The first line must be at least at wl */</span>
+<a name="l01044"></a>01044     <span class="keywordflow">if</span> (dxlines[iline] < wl) iline++;
+<a name="l01045"></a>01045 
+<a name="l01046"></a>01046     <span class="keywordflow">if</span> (iline >= nlines) <span class="keywordflow">return</span>
+<a name="l01047"></a>01047         cpl_error_set_message_macro(cpl_func, CPL_ERROR_DATA_NOT_FOUND, __FILE__,
+<a name="l01048"></a>01048                                     __LINE__, <span class="stringliteral">"The %d-line catalogue has only "</span>
+<a name="l01049"></a>01049                                     <span class="stringliteral">"lines below P(%g)=%g > %g"</span>, nlines, xpos,
+<a name="l01050"></a>01050                                     wl, dxlines[nlines-1]);
+<a name="l01051"></a>01051 
+<a name="l01052"></a>01052     memset(dself, 0, nself * <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>));
+<a name="l01053"></a>01053 
+<a name="l01054"></a>01054     dispi = cpl_polynomial_duplicate(disp);
+<a name="l01055"></a>01055 
+<a name="l01056"></a>01056     <span class="comment">/* Verify monotony of dispersion */</span>
+<a name="l01057"></a>01057     cpl_polynomial_derivative(dispi, 0);
+<a name="l01058"></a>01058 
+<a name="l01059"></a>01059     prestate = cpl_errorstate_get();
+<a name="l01060"></a>01060 
+<a name="l01061"></a>01061     <span class="keywordflow">if</span> (cpl_polynomial_solve_1d(dispi, 0.5*(nlines+1), &xextreme, 1)) {
+<a name="l01062"></a>01062         cpl_errorstate_set(prestate);
+<a name="l01063"></a>01063     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (xpos < xextreme && xextreme < xmax) {
+<a name="l01064"></a>01064         cpl_polynomial_delete(dispi);
+<a name="l01065"></a>01065         <span class="keywordflow">return</span> cpl_error_set_message_macro(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
+<a name="l01066"></a>01066                                            __FILE__, __LINE__, <span class="stringliteral">"Non-monotone "</span>
+<a name="l01067"></a>01067                                            <span class="stringliteral">"dispersion at x=%g: P'(x)=0, "</span>
+<a name="l01068"></a>01068                                            <span class="stringliteral">"P(x)=%g"</span>, xextreme,
+<a name="l01069"></a>01069                                            cpl_polynomial_eval_1d(disp, xextreme,
+<a name="l01070"></a>01070                                                                   NULL));
+<a name="l01071"></a>01071     }
+<a name="l01072"></a>01072 
+<a name="l01073"></a>01073     <span class="keywordflow">if</span> (dofast) {
+<a name="l01074"></a>01074         <span class="keyword">const</span> <span class="keywordtype">int</span> npix = 1+(int)xtrunc;
+<a name="l01075"></a>01075 
+<a name="l01076"></a>01076         <span class="keywordflow">if</span> (erftmp != NULL && cpl_vector_get_size(erftmp) == npix &&
+<a name="l01077"></a>01077             cpl_vector_get(erftmp, 0) > 0.0) {
+<a name="l01078"></a>01078             profile = cpl_vector_get_data(erftmp);
+<a name="l01079"></a>01079         } <span class="keywordflow">else</span> {
+<a name="l01080"></a>01080 
+<a name="l01081"></a>01081             <span class="keyword">const</span> <span class="keywordtype">double</span> yval =  0.5 / wslit;
+<a name="l01082"></a>01082             <span class="keyword">const</span> <span class="keywordtype">double</span> x0p  =  0.5 * wslit + 0.5;
+<a name="l01083"></a>01083             <span class="keyword">const</span> <span class="keywordtype">double</span> x0n  = -0.5 * wslit + 0.5;
+<a name="l01084"></a>01084             <span class="keywordtype">double</span>       x1diff
+<a name="l01085"></a>01085                 = <a class="code" href="group__irplib__wavecal.html#ga2da9c21054a19322705de2d4f48d1d3f" title="The antiderivative of erx(x/sigma/sqrt(2)) with respect to x.">irplib_erf_antideriv</a>(x0p, sigma)
+<a name="l01086"></a>01086                 - <a class="code" href="group__irplib__wavecal.html#ga2da9c21054a19322705de2d4f48d1d3f" title="The antiderivative of erx(x/sigma/sqrt(2)) with respect to x.">irplib_erf_antideriv</a>(x0n, sigma);
+<a name="l01087"></a>01087             <span class="keywordtype">int</span>          ipix;
+<a name="l01088"></a>01088 
+<a name="l01089"></a>01089             <span class="keywordflow">if</span> (erftmp == NULL) {
+<a name="l01090"></a>01090                 profile = (<span class="keywordtype">double</span>*)cpl_malloc(<span class="keyword">sizeof</span>(<span class="keywordtype">double</span>)*(size_t)npix);
+<a name="l01091"></a>01091             } <span class="keywordflow">else</span> {
+<a name="l01092"></a>01092                 cpl_vector_set_size(erftmp, npix);
+<a name="l01093"></a>01093                 profile = cpl_vector_get_data(erftmp);
+<a name="l01094"></a>01094             }
+<a name="l01095"></a>01095 
+<a name="l01096"></a>01096             profile[0] = 2.0 * yval * x1diff;
+<a name="l01097"></a>01097 
+<a name="l01098"></a>01098             <span class="keywordflow">for</span> (ipix = 1; ipix < npix; ipix++) {
+<a name="l01099"></a>01099                 <span class="keyword">const</span> <span class="keywordtype">double</span> x1 = (double)ipix;
+<a name="l01100"></a>01100                 <span class="keyword">const</span> <span class="keywordtype">double</span> x1p = x1 + 0.5 * wslit + 0.5;
+<a name="l01101"></a>01101                 <span class="keyword">const</span> <span class="keywordtype">double</span> x1n = x1 - 0.5 * wslit + 0.5;
+<a name="l01102"></a>01102                 <span class="keyword">const</span> <span class="keywordtype">double</span> x0diff = x1diff;
+<a name="l01103"></a>01103 
+<a name="l01104"></a>01104                 x1diff = <a class="code" href="group__irplib__wavecal.html#ga2da9c21054a19322705de2d4f48d1d3f" title="The antiderivative of erx(x/sigma/sqrt(2)) with respect to x.">irplib_erf_antideriv</a>(x1p, sigma)
+<a name="l01105"></a>01105                     - <a class="code" href="group__irplib__wavecal.html#ga2da9c21054a19322705de2d4f48d1d3f" title="The antiderivative of erx(x/sigma/sqrt(2)) with respect to x.">irplib_erf_antideriv</a>(x1n, sigma);
+<a name="l01106"></a>01106 
+<a name="l01107"></a>01107                 profile[ipix] = yval * (x1diff - x0diff);
+<a name="l01108"></a>01108 
+<a name="l01109"></a>01109             }
+<a name="l01110"></a>01110         }
+<a name="l01111"></a>01111     }
+<a name="l01112"></a>01112 
+<a name="l01113"></a>01113     cpl_polynomial_copy(dispi, disp);
+<a name="l01114"></a>01114 
+<a name="l01115"></a>01115     <span class="comment">/* FIXME: A custom version of cpl_polynomial_solve_1d() which returns</span>
+<a name="l01116"></a>01116 <span class="comment">       P'(xpos) can be used for the 1st NR-iteration. */</span>
+<a name="l01117"></a>01117     <span class="comment">/* Further, the sign of P'(xpos) could be checked for all lines. */</span>
+<a name="l01118"></a>01118     <span class="comment">/* Perform 1st NR-iteration in solving for P(xpos) = dxlines[iline] */</span>
+<a name="l01119"></a>01119     xpos -= (wl - dxlines[iline]) / xderiv;
+<a name="l01120"></a>01120 
+<a name="l01121"></a>01121     <span class="comment">/* Iterate through the lines */</span>
+<a name="l01122"></a>01122     <span class="keywordflow">for</span> (; !error && iline < nlines; iline++) {
+<a name="l01123"></a>01123 
+<a name="l01124"></a>01124         <span class="comment">/* Lines may have a non-physical intensity (e.g. zero) to indicate some</span>
+<a name="l01125"></a>01125 <span class="comment">           property of the line, e.g. unknown intensity due to blending */</span>
+<a name="l01126"></a>01126         <span class="keywordflow">if</span> (dylines[iline] <= 0.0) <span class="keywordflow">continue</span>;
+<a name="l01127"></a>01127 
+<a name="l01128"></a>01128         <span class="comment">/* Use 1st guess, if available (Use 0.0 to flag unavailable) */</span>
+<a name="l01129"></a>01129         <span class="keywordflow">if</span> (plinepix != NULL && plinepix[iline] > 0.0) xpos = plinepix[iline];
+<a name="l01130"></a>01130 
+<a name="l01131"></a>01131         <span class="keywordflow">if</span> (xpos > xmax) xpos = xmax; <span class="comment">/* FIXME: Better to limit xpos ? */</span>
+<a name="l01132"></a>01132 
+<a name="l01133"></a>01133         <span class="comment">/* Find the (sub-) pixel position of the line */</span>
+<a name="l01134"></a>01134         error = cpl_polynomial_set_coeff(dispi, &i0, p0 - dxlines[iline]) ||
+<a name="l01135"></a>01135             cpl_polynomial_solve_1d(dispi, xpos, &xpos, 1);
+<a name="l01136"></a>01136 
+<a name="l01137"></a>01137         <span class="keywordflow">if</span> (xpos > xmax) {
+<a name="l01138"></a>01138             <span class="keywordflow">if</span> (error) {
+<a name="l01139"></a>01139                 error = 0;
+<a name="l01140"></a>01140                 cpl_msg_debug(cpl_func, <span class="stringliteral">"Stopping spectrum fill at line %d/%d "</span>
+<a name="l01141"></a>01141                              <span class="stringliteral">"at xpos=%g > xmax=%g"</span>,
+<a name="l01142"></a>01142                              iline, nlines, xpos, xmax);
+<a name="l01143"></a>01143                 cpl_errorstate_dump(prestate, CPL_FALSE,
+<a name="l01144"></a>01144                                     <a class="code" href="group__irplib__utils.html#ga26c6209e5df98978e2922a15b47b47d1" title="Dump a single CPL error at the CPL debug level.">irplib_errorstate_dump_debug</a>);
+<a name="l01145"></a>01145                 cpl_errorstate_set(prestate);
+<a name="l01146"></a>01146             }
+<a name="l01147"></a>01147             <span class="keywordflow">break</span>;
+<a name="l01148"></a>01148         } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (error) {
+<a name="l01149"></a>01149             <span class="keywordflow">if</span> (linepix != NULL && ulines) (void)cpl_vector_fill(linepix, 0.0);
+<a name="l01150"></a>01150             (void)cpl_error_set_message_macro(cpl_func, cpl_error_get_code(),
+<a name="l01151"></a>01151                                               __FILE__, __LINE__,
+<a name="l01152"></a>01152                                               <span class="stringliteral">"Could not find pixel-position "</span>
+<a name="l01153"></a>01153                                               <span class="stringliteral">"of line %d/%d at wavelength=%g."</span>
+<a name="l01154"></a>01154                                               <span class="stringliteral">" xpos=%g, xmax=%g"</span>,
+<a name="l01155"></a>01155                                               iline, nlines, dxlines[iline],
+<a name="l01156"></a>01156                                               xpos, xmax);
+<a name="l01157"></a>01157             <span class="keywordflow">break</span>;
+<a name="l01158"></a>01158         } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (dofast) {
+<a name="l01159"></a>01159             <span class="keyword">const</span> <span class="keywordtype">double</span> frac  = fabs(xpos - floor(xpos));
+<a name="l01160"></a>01160 <span class="preprocessor">#ifdef IRPLIB_WAVECAL_FAST_FAST</span>
+<a name="l01161"></a>01161 <span class="preprocessor"></span>            <span class="keyword">const</span> <span class="keywordtype">double</span> frac0 = 1.0 - frac; <span class="comment">/* Weight opposite of distance */</span>
+<a name="l01162"></a>01162 <span class="preprocessor">#else</span>
+<a name="l01163"></a>01163 <span class="preprocessor"></span>            <span class="comment">/* Center intensity correctly */</span>
+<a name="l01164"></a>01164             <span class="keyword">const</span> <span class="keywordtype">double</span> ep1pw = <a class="code" href="group__irplib__wavecal.html#ga2da9c21054a19322705de2d4f48d1d3f" title="The antiderivative of erx(x/sigma/sqrt(2)) with respect to x.">irplib_erf_antideriv</a>(frac + 0.5 * wslit, sigma);
+<a name="l01165"></a>01165             <span class="keyword">const</span> <span class="keywordtype">double</span> en1pw = <a class="code" href="group__irplib__wavecal.html#ga2da9c21054a19322705de2d4f48d1d3f" title="The antiderivative of erx(x/sigma/sqrt(2)) with respect to x.">irplib_erf_antideriv</a>(frac + 0.5 * wslit - 1.0,
+<a name="l01166"></a>01166                                                       sigma);
+<a name="l01167"></a>01167             <span class="keyword">const</span> <span class="keywordtype">double</span> ep1nw = <a class="code" href="group__irplib__wavecal.html#ga2da9c21054a19322705de2d4f48d1d3f" title="The antiderivative of erx(x/sigma/sqrt(2)) with respect to x.">irplib_erf_antideriv</a>(frac - 0.5 * wslit, sigma);
+<a name="l01168"></a>01168             <span class="keyword">const</span> <span class="keywordtype">double</span> en1nw = <a class="code" href="group__irplib__wavecal.html#ga2da9c21054a19322705de2d4f48d1d3f" title="The antiderivative of erx(x/sigma/sqrt(2)) with respect to x.">irplib_erf_antideriv</a>(frac - 0.5 * wslit - 1.0,
+<a name="l01169"></a>01169                                                       sigma);
+<a name="l01170"></a>01170             <span class="keyword">const</span> <span class="keywordtype">double</span> frac0
+<a name="l01171"></a>01171                 = (en1nw - en1pw) / (ep1pw - en1pw - ep1nw + en1nw);
+<a name="l01172"></a>01172 
+<a name="l01173"></a>01173 <span class="preprocessor">#endif</span>
+<a name="l01174"></a>01174 <span class="preprocessor"></span>            <span class="keyword">const</span> <span class="keywordtype">double</span> frac1 = 1.0 - frac0;
+<a name="l01175"></a>01175             <span class="keyword">const</span> <span class="keywordtype">double</span> yval0 = frac0 * dylines[iline];
+<a name="l01176"></a>01176             <span class="keyword">const</span> <span class="keywordtype">double</span> yval1 = frac1 * dylines[iline];
+<a name="l01177"></a>01177             <span class="keyword">const</span> <span class="keywordtype">int</span>    npix  = 1+(int)xtrunc;
+<a name="l01178"></a>01178             <span class="keywordtype">int</span>          ipix;
+<a name="l01179"></a>01179             <span class="keywordtype">int</span>          i0n    = hsize - 1 + floor(xpos);
+<a name="l01180"></a>01180             <span class="keywordtype">int</span>          i0p    = i0n;
+<a name="l01181"></a>01181             <span class="keywordtype">int</span>          i1n    = i0n + 1;
+<a name="l01182"></a>01182             <span class="keywordtype">int</span>          i1p    = i1n;
+<a name="l01183"></a>01183             cpl_boolean  didline = CPL_FALSE;
+<a name="l01184"></a>01184 
+<a name="l01185"></a>01185 
+<a name="l01186"></a>01186             <span class="comment">/* Update 1st guess for next time, if available */</span>
+<a name="l01187"></a>01187             <span class="keywordflow">if</span> (plinepix != NULL) plinepix[iline] =  xpos;
+<a name="l01188"></a>01188 
+<a name="l01189"></a>01189             <span class="keywordflow">if</span> (frac0 < 0.0) {
+<a name="l01190"></a>01190                 (void)cpl_error_set_message_macro(cpl_func,
+<a name="l01191"></a>01191                                                   CPL_ERROR_UNSPECIFIED,
+<a name="l01192"></a>01192                                                   __FILE__, __LINE__,
+<a name="l01193"></a>01193                                                   <span class="stringliteral">"Illegal split at x=%g: %g + "</span>
+<a name="l01194"></a>01194                                                   <span class="stringliteral">"%g = 1"</span>, xpos, frac0, frac1);
+<a name="l01195"></a>01195 <span class="preprocessor">#ifdef IRPLIB_WAVEVAL_DEBUG</span>
+<a name="l01196"></a>01196 <span class="preprocessor"></span>            } <span class="keywordflow">else</span> {
+<a name="l01197"></a>01197                 cpl_msg_warning(cpl_func,<span class="stringliteral">"profile split at x=%g: %g + %g = 1"</span>,
+<a name="l01198"></a>01198                                 xpos, frac0, frac1);
+<a name="l01199"></a>01199 <span class="preprocessor">#endif</span>
+<a name="l01200"></a>01200 <span class="preprocessor"></span>            }
+<a name="l01201"></a>01201 
+<a name="l01202"></a>01202             <span class="keywordflow">for</span> (ipix = 0; ipix < npix; ipix++, i0n--, i0p++, i1n--, i1p++) {
+<a name="l01203"></a>01203 
+<a name="l01204"></a>01204                 <span class="keywordflow">if</span> (i0n >= 0 && i0n < nself) {
+<a name="l01205"></a>01205                     dself[i0n] += yval0 * profile[ipix];
+<a name="l01206"></a>01206                     didline = CPL_TRUE;
+<a name="l01207"></a>01207                 }
+<a name="l01208"></a>01208                 <span class="keywordflow">if</span> (i1n >= 0 && i1n < nself && ipix + 1 < npix) {
+<a name="l01209"></a>01209                     dself[i1n] += yval1 * profile[ipix+1];
+<a name="l01210"></a>01210                     didline = CPL_TRUE;
+<a name="l01211"></a>01211                 }
+<a name="l01212"></a>01212 
+<a name="l01213"></a>01213                 <span class="keywordflow">if</span> (ipix == 0) <span class="keywordflow">continue</span>;
+<a name="l01214"></a>01214 
+<a name="l01215"></a>01215                 <span class="keywordflow">if</span> (i0p >= 0 && i0p < nself) {
+<a name="l01216"></a>01216                     dself[i0p] += yval0 * profile[ipix];
+<a name="l01217"></a>01217                     didline = CPL_TRUE;
+<a name="l01218"></a>01218                 }
+<a name="l01219"></a>01219                 <span class="keywordflow">if</span> (i1p >= 0 && i1p < nself && ipix + 1 < npix) {
+<a name="l01220"></a>01220                     dself[i1p] += yval1 * profile[ipix+1];
+<a name="l01221"></a>01221                     didline = CPL_TRUE;
+<a name="l01222"></a>01222                 }
+<a name="l01223"></a>01223             }
+<a name="l01224"></a>01224 
+<a name="l01225"></a>01225             <span class="keywordflow">if</span> (didline) ulines++;
+<a name="l01226"></a>01226 
+<a name="l01227"></a>01227         } <span class="keywordflow">else</span> {
+<a name="l01228"></a>01228             <span class="keyword">const</span> <span class="keywordtype">double</span> yval = 0.5 * dylines[iline] / wslit;
+<a name="l01229"></a>01229             <span class="keyword">const</span> <span class="keywordtype">int</span>    ifirst = IRPLIB_MAX((<span class="keywordtype">int</span>)(xpos-xtrunc+0.5), 1-hsize);
+<a name="l01230"></a>01230             <span class="keyword">const</span> <span class="keywordtype">int</span>    ilast  = IRPLIB_MIN((<span class="keywordtype">int</span>)(xpos+xtrunc), nself-hsize);
+<a name="l01231"></a>01231             <span class="keywordtype">int</span>          ipix;
+<a name="l01232"></a>01232             <span class="keyword">const</span> <span class="keywordtype">double</span> x0 = (double)ifirst - xpos;
+<a name="l01233"></a>01233             <span class="keyword">const</span> <span class="keywordtype">double</span> x0p = x0 + 0.5*wslit - 0.5;
+<a name="l01234"></a>01234             <span class="keyword">const</span> <span class="keywordtype">double</span> x0n = x0 - 0.5*wslit - 0.5;
+<a name="l01235"></a>01235             <span class="keywordtype">double</span>       x1diff
+<a name="l01236"></a>01236                 = <a class="code" href="group__irplib__wavecal.html#ga2da9c21054a19322705de2d4f48d1d3f" title="The antiderivative of erx(x/sigma/sqrt(2)) with respect to x.">irplib_erf_antideriv</a>(x0p, sigma)
+<a name="l01237"></a>01237                 - <a class="code" href="group__irplib__wavecal.html#ga2da9c21054a19322705de2d4f48d1d3f" title="The antiderivative of erx(x/sigma/sqrt(2)) with respect to x.">irplib_erf_antideriv</a>(x0n, sigma);
+<a name="l01238"></a>01238 
+<a name="l01239"></a>01239             <span class="comment">/* Update 1st guess for next time, if available */</span>
+<a name="l01240"></a>01240             <span class="keywordflow">if</span> (plinepix != NULL) plinepix[iline] =  xpos;
+<a name="l01241"></a>01241 
+<a name="l01242"></a>01242             <span class="keywordflow">if</span> (ilast >= ifirst) ulines++;
+<a name="l01243"></a>01243 
+<a name="l01244"></a>01244             <span class="keywordflow">for</span> (ipix = ifirst; ipix <= ilast; ipix++) {
+<a name="l01245"></a>01245                 <span class="keyword">const</span> <span class="keywordtype">double</span> x1 = (double)ipix - xpos;
+<a name="l01246"></a>01246                 <span class="keyword">const</span> <span class="keywordtype">double</span> x1p = x1 + 0.5*wslit + 0.5;
+<a name="l01247"></a>01247                 <span class="keyword">const</span> <span class="keywordtype">double</span> x1n = x1 - 0.5*wslit + 0.5;
+<a name="l01248"></a>01248                 <span class="keyword">const</span> <span class="keywordtype">double</span> x0diff = x1diff;
+<a name="l01249"></a>01249 
+<a name="l01250"></a>01250                 x1diff = <a class="code" href="group__irplib__wavecal.html#ga2da9c21054a19322705de2d4f48d1d3f" title="The antiderivative of erx(x/sigma/sqrt(2)) with respect to x.">irplib_erf_antideriv</a>(x1p, sigma)
+<a name="l01251"></a>01251                     - <a class="code" href="group__irplib__wavecal.html#ga2da9c21054a19322705de2d4f48d1d3f" title="The antiderivative of erx(x/sigma/sqrt(2)) with respect to x.">irplib_erf_antideriv</a>(x1n, sigma);
+<a name="l01252"></a>01252 
+<a name="l01253"></a>01253                 dself[ipix+hsize-1] += yval * (x1diff - x0diff);
+<a name="l01254"></a>01254 
+<a name="l01255"></a>01255             }
+<a name="l01256"></a>01256         }
+<a name="l01257"></a>01257     }
+<a name="l01258"></a>01258 
+<a name="l01259"></a>01259     cpl_polynomial_delete(dispi);
+<a name="l01260"></a>01260     <span class="keywordflow">if</span> (erftmp == NULL) cpl_free(profile);
+<a name="l01261"></a>01261 
+<a name="l01262"></a>01262     cpl_ensure_code(!error, cpl_error_get_code());
+<a name="l01263"></a>01263 
+<a name="l01264"></a>01264     <span class="keywordflow">if</span> (dolog) {
+<a name="l01265"></a>01265         <span class="keywordtype">int</span> i;
+<a name="l01266"></a>01266         <span class="keywordflow">for</span> (i = 0; i < nself; i++) {
+<a name="l01267"></a>01267             dself[i] = dself[i] > 0.0 ? log(1.0 + dself[i]) : 0.0;
+<a name="l01268"></a>01268         }
+<a name="l01269"></a>01269     }
+<a name="l01270"></a>01270 
+<a name="l01271"></a>01271     <span class="keywordflow">if</span> (!ulines) <span class="keywordflow">return</span>
+<a name="l01272"></a>01272         cpl_error_set_message_macro(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
+<a name="l01273"></a>01273                                     __FILE__, __LINE__, <span class="stringliteral">"The %d-line "</span>
+<a name="l01274"></a>01274                                     <span class="stringliteral">"catalogue has no lines in the range "</span>
+<a name="l01275"></a>01275                                     <span class="stringliteral">"%g -> P(%g)=%g"</span>, nlines, wl, xmax,
+<a name="l01276"></a>01276                                     cpl_polynomial_eval_1d(disp, xmax, NULL));
+<a name="l01277"></a>01277 
+<a name="l01278"></a>01278     <span class="keywordflow">if</span> (pulines != NULL) *pulines = ulines;
+<a name="l01279"></a>01279 
+<a name="l01280"></a>01280     <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l01281"></a>01281 }
+<a name="l01282"></a>01282 
+<a name="l01283"></a>01283 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01292"></a>01292 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01293"></a><a class="code" href="group__irplib__wavecal.html#ga2da9c21054a19322705de2d4f48d1d3f">01293</a> <span class="keyword">inline</span> <span class="keywordtype">double</span> <a class="code" href="group__irplib__wavecal.html#ga2da9c21054a19322705de2d4f48d1d3f" title="The antiderivative of erx(x/sigma/sqrt(2)) with respect to x.">irplib_erf_antideriv</a>(<span class="keywordtype">double</span> x, <span class="keywordtype">double</span> sigma)
+<a name="l01294"></a>01294 {
+<a name="l01295"></a>01295     <span class="keywordflow">return</span> x * erf( x / (sigma * CPL_MATH_SQRT2))
+<a name="l01296"></a>01296        + 2.0 * sigma/CPL_MATH_SQRT2PI * exp(-0.5 * x * x / (sigma * sigma));
+<a name="l01297"></a>01297 }
+<a name="l01298"></a>01298 
+<a name="l01299"></a>01299 
+<a name="l01300"></a>01300 <span class="preprocessor">#ifdef HAVE_GSL</span>
+<a name="l01301"></a>01301 <span class="preprocessor"></span>
+<a name="l01302"></a>01302 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01310"></a>01310 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01311"></a>01311 <span class="keyword">static</span> <span class="keywordtype">double</span> irplib_gsl_correlation(<span class="keyword">const</span> gsl_vector * <span class="keyword">self</span>, <span class="keywordtype">void</span> * data)
+<a name="l01312"></a>01312 {
+<a name="l01313"></a>01313 
+<a name="l01314"></a>01314     irplib_multimin * mindata = (irplib_multimin *)data;
+<a name="l01315"></a>01315     cpl_errorstate prestate = cpl_errorstate_get();
+<a name="l01316"></a>01316     <span class="keywordtype">int</span> nobs, nmodel, ndiff;
+<a name="l01317"></a>01317     cpl_size i;
+<a name="l01318"></a>01318 
+<a name="l01319"></a>01319     cpl_ensure(<span class="keyword">self</span> != NULL, CPL_ERROR_NULL_INPUT, GSL_NAN);
+<a name="l01320"></a>01320     cpl_ensure(data != NULL, CPL_ERROR_NULL_INPUT, GSL_NAN);
+<a name="l01321"></a>01321 
+<a name="l01322"></a>01322     cpl_ensure(mindata->filler   != NULL, CPL_ERROR_NULL_INPUT, GSL_NAN);
+<a name="l01323"></a>01323     cpl_ensure(mindata->observed != NULL, CPL_ERROR_NULL_INPUT, GSL_NAN);
+<a name="l01324"></a>01324     cpl_ensure(mindata->spectrum != NULL, CPL_ERROR_NULL_INPUT, GSL_NAN);
+<a name="l01325"></a>01325 
+<a name="l01326"></a>01326     nobs   = cpl_vector_get_size(mindata->observed);
+<a name="l01327"></a>01327     nmodel = cpl_vector_get_size(mindata->spectrum);
+<a name="l01328"></a>01328     ndiff  = nmodel - nobs;
+<a name="l01329"></a>01329 
+<a name="l01330"></a>01330     cpl_ensure((ndiff & 1) == 0, CPL_ERROR_ILLEGAL_INPUT, GSL_NAN);
+<a name="l01331"></a>01331 
+<a name="l01332"></a>01332     cpl_ensure(cpl_vector_get_size(mindata->vxc) == 1 + ndiff,
+<a name="l01333"></a>01333                CPL_ERROR_ILLEGAL_INPUT, GSL_NAN);
+<a name="l01334"></a>01334 
+<a name="l01335"></a>01335     ndiff /= 2;
+<a name="l01336"></a>01336 
+<a name="l01337"></a>01337     <span class="keywordflow">for</span> (i=0; i < (cpl_size)self->size; i++) {
+<a name="l01338"></a>01338         <span class="keyword">const</span> <span class="keywordtype">double</span> value = gsl_vector_get(<span class="keyword">self</span>, (<span class="keywordtype">size_t</span>)i);
+<a name="l01339"></a>01339         cpl_polynomial_set_coeff(mindata->disp1d, &i, value);
+<a name="l01340"></a>01340     }
+<a name="l01341"></a>01341 
+<a name="l01342"></a>01342     <span class="keywordflow">if</span> (mindata->filler(mindata->spectrum, mindata->disp1d,
+<a name="l01343"></a>01343                         mindata->param, ndiff)
+<a name="l01344"></a>01344         || !cpl_errorstate_is_equal(prestate)) {
+<a name="l01345"></a>01345 
+<a name="l01346"></a>01346         <span class="comment">/* The fill failed. Ensure the discarding of this candidate by</span>
+<a name="l01347"></a>01347 <span class="comment">           setting the cross-correlation to its minimum possible value. */</span>
+<a name="l01348"></a>01348 
+<a name="l01349"></a>01349         (void)cpl_vector_fill(mindata->vxc, -1.0);
+<a name="l01350"></a>01350 
+<a name="l01351"></a>01351         mindata->maxxc = ndiff;
+<a name="l01352"></a>01352 
+<a name="l01353"></a>01353         <span class="keywordflow">if</span> (!cpl_errorstate_is_equal(prestate)) {
+<a name="l01354"></a>01354                 cpl_msg_debug(cpl_func, <span class="stringliteral">"Spectrum fill failed:"</span>);
+<a name="l01355"></a>01355                 cpl_errorstate_dump(prestate, CPL_FALSE,
+<a name="l01356"></a>01356                                     <a class="code" href="group__irplib__utils.html#ga26c6209e5df98978e2922a15b47b47d1" title="Dump a single CPL error at the CPL debug level.">irplib_errorstate_dump_debug</a>);
+<a name="l01357"></a>01357                 cpl_errorstate_set(prestate);
+<a name="l01358"></a>01358         }
+<a name="l01359"></a>01359     } <span class="keywordflow">else</span> {
+<a name="l01360"></a>01360 
+<a name="l01361"></a>01361         mindata->maxxc = cpl_vector_correlate(mindata->vxc,
+<a name="l01362"></a>01362                                               mindata->spectrum,
+<a name="l01363"></a>01363                                               mindata->observed);
+<a name="l01364"></a>01364     }
+<a name="l01365"></a>01365 
+<a name="l01366"></a>01366 <span class="preprocessor">#ifdef IRPLIB_SPC_DUMP</span>
+<a name="l01367"></a>01367 <span class="preprocessor"></span>    <span class="comment">/* Need irplib_wavecal.c rev. 1.12 through 1.15 */</span>
+<a name="l01368"></a>01368     irplib_polynomial_dump_corr_step(mindata->disp1d, mindata->vxc,
+<a name="l01369"></a>01369                                      <span class="stringliteral">"Optimize"</span>);
+<a name="l01370"></a>01370 <span class="preprocessor">#endif</span>
+<a name="l01371"></a>01371 <span class="preprocessor"></span>
+<a name="l01372"></a>01372     mindata->xc = cpl_vector_get(mindata->vxc, ndiff);
+<a name="l01373"></a>01373 
+<a name="l01374"></a>01374     <span class="keywordflow">if</span> (mindata->maxxc != ndiff &&
+<a name="l01375"></a>01375         cpl_vector_get(mindata->vxc, mindata->maxxc) > mindata->mxc) {
+<a name="l01376"></a>01376         <span class="keyword">const</span> irplib_base_spectrum_model * arclamp
+<a name="l01377"></a>01377             = (<span class="keyword">const</span> irplib_base_spectrum_model *)mindata->param;
+<a name="l01378"></a>01378 
+<a name="l01379"></a>01379         if (mindata->mdisp == NULL) {
+<a name="l01380"></a>01380             mindata->mdisp = cpl_polynomial_duplicate(mindata->disp1d);
+<a name="l01381"></a>01381         } <span class="keywordflow">else</span> {
+<a name="l01382"></a>01382             cpl_polynomial_copy(mindata->mdisp, mindata->disp1d);
+<a name="l01383"></a>01383         }
+<a name="l01384"></a>01384         mindata->mxc = cpl_vector_get(mindata->vxc, mindata->maxxc);
+<a name="l01385"></a>01385         mindata->ishift = mindata->maxxc - ndiff;
+<a name="l01386"></a>01386         cpl_msg_debug(cpl_func, <span class="stringliteral">"Local maximum: %g(%d) > %g(%d) (cost=%u:%u. "</span>
+<a name="l01387"></a>01387                       <span class="stringliteral">"lines=%u)"</span>, mindata->mxc, mindata->maxxc, mindata->xc,
+<a name="l01388"></a>01388                       ndiff, arclamp->cost, arclamp->xcost, arclamp->ulines);
+<a name="l01389"></a>01389     }
+<a name="l01390"></a>01390 
+<a name="l01391"></a>01391     <span class="keywordflow">return</span> -mindata->xc;
+<a name="l01392"></a>01392 }
+<a name="l01393"></a>01393 
+<a name="l01394"></a>01394 <span class="preprocessor">#endif</span>
+<a name="l01395"></a>01395 <span class="preprocessor"></span>
+<a name="l01396"></a>01396 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01419"></a>01419 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01420"></a>01420 cpl_error_code
+<a name="l01421"></a><a class="code" href="group__irplib__wavecal.html#ga0adf260c4d27fc50bc8b4cbcc0264a4e">01421</a> <a class="code" href="group__irplib__wavecal.html#ga0adf260c4d27fc50bc8b4cbcc0264a4e" title="Modify self by maximizing the cross-correlation across all maxima.">irplib_polynomial_find_1d_from_correlation_all</a>(cpl_polynomial * <span class="keyword">self</span>,
+<a name="l01422"></a>01422                                                <span class="keywordtype">int</span> maxdeg,
+<a name="l01423"></a>01423                                                <span class="keyword">const</span> cpl_vector * obs,
+<a name="l01424"></a>01424                                                <span class="keywordtype">int</span> nmaxima,
+<a name="l01425"></a>01425                                                <span class="keywordtype">int</span> linelim,
+<a name="l01426"></a>01426                                                irplib_base_spectrum_model* model,
+<a name="l01427"></a>01427                                                cpl_error_code (* filler)
+<a name="l01428"></a>01428                                                (cpl_vector *,
+<a name="l01429"></a>01429                                                 <span class="keyword">const</span> cpl_polynomial *,
+<a name="l01430"></a>01430                                                 irplib_base_spectrum_model *,
+<a name="l01431"></a>01431                                                 <span class="keywordtype">int</span>),
+<a name="l01432"></a>01432                                                <span class="keywordtype">double</span> pixtol,
+<a name="l01433"></a>01433                                                <span class="keywordtype">double</span> pixstep,
+<a name="l01434"></a>01434                                                <span class="keywordtype">int</span> hsize,
+<a name="l01435"></a>01435                                                <span class="keywordtype">int</span> maxite,
+<a name="l01436"></a>01436                                                <span class="keywordtype">int</span> maxfail,
+<a name="l01437"></a>01437                                                <span class="keywordtype">int</span> maxcont,
+<a name="l01438"></a>01438                                                cpl_boolean doplot,
+<a name="l01439"></a>01439                                                <span class="keywordtype">double</span> * pxc)
+<a name="l01440"></a>01440 {
+<a name="l01441"></a>01441 
+<a name="l01442"></a>01442 <span class="preprocessor">#ifdef HAVE_GSL</span>
+<a name="l01443"></a>01443 <span class="preprocessor"></span>
+<a name="l01444"></a>01444     cpl_errorstate     prestate = cpl_errorstate_get();
+<a name="l01445"></a>01445     cpl_polynomial   * start;
+<a name="l01446"></a>01446     cpl_polynomial   * cand;
+<a name="l01447"></a>01447     cpl_polynomial   * backup;
+<a name="l01448"></a>01448     cpl_error_code     error = CPL_ERROR_NONE;
+<a name="l01449"></a>01449     <span class="keywordtype">double</span>             xc;
+<a name="l01450"></a>01450     cpl_bivector     * xtshift = cpl_bivector_new(nmaxima ? nmaxima : 1);
+<a name="l01451"></a>01451     <span class="keyword">const</span> cpl_vector * xtshiftx = cpl_bivector_get_x_const(xtshift);
+<a name="l01452"></a>01452     <span class="keyword">const</span> cpl_vector * xtshifty = cpl_bivector_get_y_const(xtshift);
+<a name="l01453"></a>01453     <span class="keywordtype">int</span>                nshift;
+<a name="l01454"></a>01454     <span class="keywordtype">int</span>                imaximum = -1;
+<a name="l01455"></a>01455     <span class="keywordtype">int</span>                imaxima;
+<a name="l01456"></a>01456 
+<a name="l01457"></a>01457 <span class="preprocessor">#endif</span>
+<a name="l01458"></a>01458 <span class="preprocessor"></span>
+<a name="l01459"></a>01459     cpl_ensure_code(<span class="keyword">self</span>   != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l01460"></a>01460     cpl_ensure_code(obs    != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l01461"></a>01461     cpl_ensure_code(model  != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l01462"></a>01462     cpl_ensure_code(filler != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l01463"></a>01463     cpl_ensure_code(pxc    != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l01464"></a>01464 
+<a name="l01465"></a>01465     cpl_ensure_code(cpl_polynomial_get_dimension(<span class="keyword">self</span>) == 1,
+<a name="l01466"></a>01466                     CPL_ERROR_ILLEGAL_INPUT);
+<a name="l01467"></a>01467 
+<a name="l01468"></a>01468     cpl_ensure_code(cpl_polynomial_get_degree(<span class="keyword">self</span>) > 0,
+<a name="l01469"></a>01469                     CPL_ERROR_ILLEGAL_INPUT);
+<a name="l01470"></a>01470 
+<a name="l01471"></a>01471     cpl_ensure_code(maxdeg  >=  0, CPL_ERROR_ILLEGAL_INPUT);
+<a name="l01472"></a>01472     cpl_ensure_code(pixtol  > 0.0, CPL_ERROR_ILLEGAL_INPUT);
+<a name="l01473"></a>01473     cpl_ensure_code(pixstep > 0.0, CPL_ERROR_ILLEGAL_INPUT);
+<a name="l01474"></a>01474     cpl_ensure_code(hsize   >=  0, CPL_ERROR_ILLEGAL_INPUT);
+<a name="l01475"></a>01475     cpl_ensure_code(maxite  >=  0, CPL_ERROR_ILLEGAL_INPUT);
+<a name="l01476"></a>01476     cpl_ensure_code(nmaxima >=  0, CPL_ERROR_ILLEGAL_INPUT);
+<a name="l01477"></a>01477     cpl_ensure_code(maxfail >   0, CPL_ERROR_ILLEGAL_INPUT);
+<a name="l01478"></a>01478     cpl_ensure_code(maxcont >   0, CPL_ERROR_ILLEGAL_INPUT);
+<a name="l01479"></a>01479     cpl_ensure_code(linelim >=  0, CPL_ERROR_ILLEGAL_INPUT);
+<a name="l01480"></a>01480 
+<a name="l01481"></a>01481 <span class="preprocessor">#ifndef HAVE_GSL</span>
+<a name="l01482"></a>01482 <span class="preprocessor"></span>    <span class="comment">/* Avoid unused variable warning */</span>
+<a name="l01483"></a>01483     cpl_ensure_code(doplot == CPL_TRUE || doplot == CPL_FALSE,
+<a name="l01484"></a>01484                     CPL_ERROR_ILLEGAL_INPUT);
+<a name="l01485"></a>01485     <span class="keywordflow">return</span> cpl_error_set_message(cpl_func, CPL_ERROR_UNSUPPORTED_MODE,
+<a name="l01486"></a>01486                                  <span class="stringliteral">"GSL is not available"</span>);
+<a name="l01487"></a>01487 <span class="preprocessor">#else</span>
+<a name="l01488"></a>01488 <span class="preprocessor"></span>
+<a name="l01489"></a>01489     <span class="keywordflow">if</span> (<a class="code" href="group__irplib__wavecal.html#gae027096b411661b9584c72ab3e8e6547" title="Find shift(s) that maximizes (locally) the cross-correlation.">irplib_bivector_find_shift_from_correlation</a>(xtshift, <span class="keyword">self</span>, obs,
+<a name="l01490"></a>01490                                                     model, filler,
+<a name="l01491"></a>01491                                                     hsize, doplot, &xc)) {
+<a name="l01492"></a>01492         cpl_bivector_delete(xtshift);
+<a name="l01493"></a>01493         <span class="keywordflow">return</span> cpl_error_set_where(cpl_func);
+<a name="l01494"></a>01494     }
+<a name="l01495"></a>01495 
+<a name="l01496"></a>01496     <span class="keywordflow">if</span> (model->ulines > (<span class="keywordtype">unsigned</span>)linelim) {
+<a name="l01497"></a>01497         <span class="comment">/* The initial, optimal (integer) shift */</span>
+<a name="l01498"></a>01498         <span class="keyword">const</span> <span class="keywordtype">double</span> xxc = cpl_vector_get(xtshiftx, 0);
+<a name="l01499"></a>01499         <span class="keyword">const</span> <span class="keywordtype">double</span> xc0 = cpl_vector_get(xtshifty, 0);
+<a name="l01500"></a>01500 
+<a name="l01501"></a>01501         cpl_msg_warning(cpl_func, <span class="stringliteral">"Doing only shift=%g pixels with lines=%u > "</span>
+<a name="l01502"></a>01502                         <span class="stringliteral">"%d and XC=%g"</span>, xxc, model->ulines, linelim, xc0);
+<a name="l01503"></a>01503 
+<a name="l01504"></a>01504         cpl_polynomial_shift_1d(<span class="keyword">self</span>, 0, xxc);
+<a name="l01505"></a>01505 
+<a name="l01506"></a>01506         *pxc = xc0;
+<a name="l01507"></a>01507 
+<a name="l01508"></a>01508         cpl_bivector_delete(xtshift);
+<a name="l01509"></a>01509 
+<a name="l01510"></a>01510         <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l01511"></a>01511     }
+<a name="l01512"></a>01512 
+<a name="l01513"></a>01513     start  = cpl_polynomial_duplicate(<span class="keyword">self</span>);
+<a name="l01514"></a>01514     cand   = cpl_polynomial_new(1);
+<a name="l01515"></a>01515     backup = cpl_polynomial_new(1);
+<a name="l01516"></a>01516 
+<a name="l01517"></a>01517     <span class="comment">/* Number of (local) maxima to use as starting point of the optimization */</span>
+<a name="l01518"></a>01518     nshift = cpl_bivector_get_size(xtshift);
+<a name="l01519"></a>01519     <span class="keywordflow">if</span> (nmaxima == 0 || nmaxima > nshift) nmaxima = nshift;
+<a name="l01520"></a>01520 
+<a name="l01521"></a>01521     cpl_msg_info(cpl_func, <span class="stringliteral">"Optimizing %d/%d local shift-maxima "</span>
+<a name="l01522"></a>01522                  <span class="stringliteral">"(no-shift xc=%g. linelim=%d)"</span>, nmaxima, nshift, xc, linelim);
+<a name="l01523"></a>01523     <span class="keywordflow">if</span> (cpl_msg_get_level() <= CPL_MSG_DEBUG)
+<a name="l01524"></a>01524         cpl_bivector_dump(xtshift, stdout);
+<a name="l01525"></a>01525 
+<a name="l01526"></a>01526     <span class="keywordflow">for</span> (imaxima = 0; imaxima < nmaxima; imaxima++) {
+<a name="l01527"></a>01527         <span class="comment">/* The initial, optimal (integer) shift */</span>
+<a name="l01528"></a>01528         <span class="keyword">const</span> <span class="keywordtype">double</span> xxc = cpl_vector_get(xtshiftx, imaxima);
+<a name="l01529"></a>01529         <span class="keywordtype">double</span> xtpixstep = pixstep;
+<a name="l01530"></a>01530         <span class="keywordtype">double</span> xtpixtol  = pixtol;
+<a name="l01531"></a>01531         <span class="keywordtype">double</span> xtxc;
+<a name="l01532"></a>01532         cpl_boolean ok = CPL_FALSE;
+<a name="l01533"></a>01533         <span class="keywordtype">int</span> nfail;
+<a name="l01534"></a>01534 
+<a name="l01535"></a>01535 
+<a name="l01536"></a>01536         cpl_polynomial_copy(cand, start);
+<a name="l01537"></a>01537         cpl_polynomial_shift_1d(cand, 0, xxc);
+<a name="l01538"></a>01538         cpl_polynomial_copy(backup, cand);
+<a name="l01539"></a>01539 
+<a name="l01540"></a>01540         <span class="comment">/* Increase tolerance until convergence */</span>
+<a name="l01541"></a>01541         <span class="keywordflow">for</span> (nfail = 0; nfail < maxfail; nfail++, xtpixtol *= 2.0,
+<a name="l01542"></a>01542                  xtpixstep *= 2.0) {
+<a name="l01543"></a>01543             <span class="keywordtype">int</span> restart = maxcont;
+<a name="l01544"></a>01544             <span class="keywordflow">do</span> {
+<a name="l01545"></a>01545                 error = <a class="code" href="group__irplib__wavecal.html#gaaa889f20c9483965ff6bab186d4f9972" title="Modify self by maximizing the cross-correlation.">irplib_polynomial_find_1d_from_correlation</a>
+<a name="l01546"></a>01546                     (cand, maxdeg, obs, model,
+<a name="l01547"></a>01547                      filler, xtpixtol, xtpixstep, 2,
+<a name="l01548"></a>01548                      maxite, &xtxc);
+<a name="l01549"></a>01549             } <span class="keywordflow">while</span> (error == CPL_ERROR_CONTINUE && --restart);
+<a name="l01550"></a>01550 
+<a name="l01551"></a>01551             <span class="keywordflow">if</span> (!error) {
+<a name="l01552"></a>01552                 cpl_msg_debug(cpl_func, <span class="stringliteral">"XC(imax=%d/%d:xtpixtol=%g): %g "</span>
+<a name="l01553"></a>01553                               <span class="stringliteral">"(cost=%u:%u)"</span>, 1+imaxima, nmaxima, xtpixtol,
+<a name="l01554"></a>01554                               xtxc, model->cost, model->xcost);
+<a name="l01555"></a>01555                 <span class="keywordflow">break</span>;
+<a name="l01556"></a>01556             }
+<a name="l01557"></a>01557             cpl_msg_warning(cpl_func, <span class="stringliteral">"Increasing xtpixtol from %g (%g, imax="</span>
+<a name="l01558"></a>01558                             <span class="stringliteral">"%d/%d)"</span>, xtpixtol, xtpixstep, 1+imaxima, nmaxima);
+<a name="l01559"></a>01559             <span class="keywordflow">if</span> (model->ulines > (<span class="keywordtype">unsigned</span>)linelim) {
+<a name="l01560"></a>01560                 cpl_msg_warning(cpl_func, <span class="stringliteral">"Stopping search-refinement via "</span>
+<a name="l01561"></a>01561                                 <span class="stringliteral">"catalogue with %u lines > %u"</span>, model->ulines,
+<a name="l01562"></a>01562                                 linelim);
+<a name="l01563"></a>01563                 <span class="keywordflow">break</span>;
+<a name="l01564"></a>01564             }
+<a name="l01565"></a>01565             cpl_polynomial_copy(cand, start);
+<a name="l01566"></a>01566         }
+<a name="l01567"></a>01567 
+<a name="l01568"></a>01568         <span class="comment">/* Decrease tolerance until inconvergence, keep previous */</span>
+<a name="l01569"></a>01569         <span class="keywordflow">for</span> (; !error && xtpixtol > 0.0; xtpixtol *= 0.25, xtpixstep *= 0.5) {
+<a name="l01570"></a>01570             <span class="keywordtype">int</span> restart = maxcont;
+<a name="l01571"></a>01571 
+<a name="l01572"></a>01572             cpl_polynomial_copy(backup, cand);
+<a name="l01573"></a>01573             <span class="keywordflow">do</span> {
+<a name="l01574"></a>01574                 error = <a class="code" href="group__irplib__wavecal.html#gaaa889f20c9483965ff6bab186d4f9972" title="Modify self by maximizing the cross-correlation.">irplib_polynomial_find_1d_from_correlation</a>
+<a name="l01575"></a>01575                     (cand, maxdeg, obs, model, filler,
+<a name="l01576"></a>01576                      xtpixtol, xtpixstep, 2, maxite, &xtxc);
+<a name="l01577"></a>01577             } <span class="keywordflow">while</span> (error == CPL_ERROR_CONTINUE && --restart);
+<a name="l01578"></a>01578             <span class="keywordflow">if</span> (error) <span class="keywordflow">break</span>;
+<a name="l01579"></a>01579             ok = CPL_TRUE;
+<a name="l01580"></a>01580             cpl_msg_debug(cpl_func, <span class="stringliteral">"XC(imax=%d/%d:xtpixtol=%g): %g (cost=%u:%u"</span>
+<a name="l01581"></a>01581                           <span class="stringliteral">". ulines=%u)"</span>, 1+imaxima, nmaxima, xtpixtol, xtxc,
+<a name="l01582"></a>01582                           model->cost, model->xcost, model->ulines);
+<a name="l01583"></a>01583             <span class="keywordflow">if</span> (model->ulines > (<span class="keywordtype">unsigned</span>)linelim) {
+<a name="l01584"></a>01584                 cpl_msg_info(cpl_func, <span class="stringliteral">"Stopping search-refinement via "</span>
+<a name="l01585"></a>01585                              <span class="stringliteral">"catalogue with %u lines > %u"</span>, model->ulines,
+<a name="l01586"></a>01586                              linelim);
+<a name="l01587"></a>01587                 <span class="keywordflow">break</span>;
+<a name="l01588"></a>01588             }
+<a name="l01589"></a>01589         }
+<a name="l01590"></a>01590 
+<a name="l01591"></a>01591         <span class="keywordflow">if</span> (error) {
+<a name="l01592"></a>01592             error = 0;
+<a name="l01593"></a>01593             cpl_errorstate_dump(prestate, CPL_FALSE,
+<a name="l01594"></a>01594                                 <a class="code" href="group__irplib__utils.html#ga26c6209e5df98978e2922a15b47b47d1" title="Dump a single CPL error at the CPL debug level.">irplib_errorstate_dump_debug</a>);
+<a name="l01595"></a>01595             cpl_errorstate_set(prestate);
+<a name="l01596"></a>01596             cpl_polynomial_copy(cand, backup);
+<a name="l01597"></a>01597         }
+<a name="l01598"></a>01598         <span class="keywordflow">if</span> (ok && xtxc > xc) {
+<a name="l01599"></a>01599             imaximum = imaxima;
+<a name="l01600"></a>01600             cpl_polynomial_copy(<span class="keyword">self</span>, cand);
+<a name="l01601"></a>01601             xc = xtxc;
+<a name="l01602"></a>01602 
+<a name="l01603"></a>01603             cpl_msg_info(cpl_func, <span class="stringliteral">"XC(imax=%d/%d): %g -> %g (initial-shift=%g. "</span>
+<a name="l01604"></a>01604                          <span class="stringliteral">"cost=%u:%u. lines=%u)"</span>, 1+imaxima, nmaxima,
+<a name="l01605"></a>01605                          cpl_vector_get(xtshifty, imaxima), xtxc,
+<a name="l01606"></a>01606                          cpl_vector_get(xtshiftx, imaxima), model->cost,
+<a name="l01607"></a>01607                          model->xcost, model->ulines);
+<a name="l01608"></a>01608         } <span class="keywordflow">else</span> {
+<a name="l01609"></a>01609             cpl_msg_info(cpl_func, <span class="stringliteral">"xc(imax=%d/%d): %g -> %g (initial-shift=%g. "</span>
+<a name="l01610"></a>01610                          <span class="stringliteral">"cost=%u:%u. lines=%u)"</span>, 1+imaxima, nmaxima,
+<a name="l01611"></a>01611                          cpl_vector_get(xtshifty, imaxima), xtxc,
+<a name="l01612"></a>01612                          cpl_vector_get(xtshiftx, imaxima),
+<a name="l01613"></a>01613                          model->cost, model->xcost, model->ulines);
+<a name="l01614"></a>01614         }
+<a name="l01615"></a>01615     }
+<a name="l01616"></a>01616 
+<a name="l01617"></a>01617     cpl_polynomial_delete(start);
+<a name="l01618"></a>01618     cpl_polynomial_delete(backup);
+<a name="l01619"></a>01619     cpl_polynomial_delete(cand);
+<a name="l01620"></a>01620 
+<a name="l01621"></a>01621     <span class="keywordflow">if</span> (imaximum < 0) {
+<a name="l01622"></a>01622         error = cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
+<a name="l01623"></a>01623                                       <span class="stringliteral">"XC could not be optimized over %d "</span>
+<a name="l01624"></a>01624                                       <span class="stringliteral">"local shift-maxima (xc=%g)"</span>, nmaxima, xc);
+<a name="l01625"></a>01625     } <span class="keywordflow">else</span> {
+<a name="l01626"></a>01626         cpl_msg_info(cpl_func, <span class="stringliteral">"Maximal XC=%g (up from %g, with initial pixel-"</span>
+<a name="l01627"></a>01627                      <span class="stringliteral">"shift of %g) at %d/%d local shift-maximi"</span>, xc,
+<a name="l01628"></a>01628                      cpl_vector_get(xtshifty, imaximum),
+<a name="l01629"></a>01629                      cpl_vector_get(xtshiftx, imaximum),
+<a name="l01630"></a>01630                      1+imaximum, nmaxima);
+<a name="l01631"></a>01631 
+<a name="l01632"></a>01632         <span class="keywordflow">if</span> (doplot) {
+<a name="l01633"></a>01633             <a class="code" href="group__irplib__wavecal.html#ga7eec8e48f4888aba01b98d9e0dc2acc5" title="Plot a 1D spectrum and one from a model.">irplib_plot_spectrum_and_model</a>(obs, <span class="keyword">self</span>, model, filler);
+<a name="l01634"></a>01634         }
+<a name="l01635"></a>01635 
+<a name="l01636"></a>01636         *pxc = xc;
+<a name="l01637"></a>01637     }
+<a name="l01638"></a>01638 
+<a name="l01639"></a>01639     cpl_bivector_delete(xtshift);
+<a name="l01640"></a>01640 
+<a name="l01641"></a>01641     <span class="keywordflow">return</span> error;
+<a name="l01642"></a>01642 
+<a name="l01643"></a>01643 <span class="preprocessor">#endif</span>
+<a name="l01644"></a>01644 <span class="preprocessor"></span>
+<a name="l01645"></a>01645 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/irplib__wavecal_8h_source.html b/html/irplib__wavecal_8h_source.html
new file mode 100644
index 0000000..c60731e
--- /dev/null
+++ b/html/irplib__wavecal_8h_source.html
@@ -0,0 +1,200 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: irplib_wavecal.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>irplib_wavecal.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: irplib_wavecal.h,v 1.16 2009/10/21 14:49:42 llundin Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the IRPLIB Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: llundin $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2009/10/21 14:49:42 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.16 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifndef IRPLIB_WAVECAL_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#define IRPLIB_WAVECAL_H</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span>
+<a name="l00031"></a>00031 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00032"></a>00032 <span class="comment">                                   Includes</span>
+<a name="l00033"></a>00033 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00034"></a>00034 
+<a name="l00035"></a>00035 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 
+<a name="l00038"></a>00038 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00039"></a>00039 <span class="comment">                                   Define</span>
+<a name="l00040"></a>00040 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00041"></a>00041 
+<a name="l00042"></a>00042 <span class="preprocessor">#define IRPLIB_WAVECAL_MODEL_COEFFS       4</span>
+<a name="l00043"></a>00043 <span class="preprocessor"></span><span class="comment">/* The number of columns is 5 + IRPLIB_WAVECAL_MODEL_COEFFS */</span>
+<a name="l00044"></a>00044 <span class="preprocessor">#define IRPLIB_WAVECAL_MODEL_COLS         9</span>
+<a name="l00045"></a>00045 <span class="preprocessor"></span>
+<a name="l00046"></a>00046 <span class="preprocessor">#define IRPLIB_WAVECAL_LAB_MODE           "SpecMode"</span>
+<a name="l00047"></a>00047 <span class="preprocessor"></span><span class="preprocessor">#define IRPLIB_WAVECAL_LAB_RESID          "Residual"</span>
+<a name="l00048"></a>00048 <span class="preprocessor"></span><span class="preprocessor">#define IRPLIB_WAVECAL_LAB_ORDER          "Fit_Order"</span>
+<a name="l00049"></a>00049 <span class="preprocessor"></span><span class="preprocessor">#define IRPLIB_WAVECAL_LAB_XMIN           "XMin"</span>
+<a name="l00050"></a>00050 <span class="preprocessor"></span><span class="preprocessor">#define IRPLIB_WAVECAL_LAB_XMAX           "XMax"</span>
+<a name="l00051"></a>00051 <span class="preprocessor"></span><span class="preprocessor">#define IRPLIB_WAVECAL_LAB_C1             "C_1"</span>
+<a name="l00052"></a>00052 <span class="preprocessor"></span><span class="preprocessor">#define IRPLIB_WAVECAL_LAB_C2             "C_2"</span>
+<a name="l00053"></a>00053 <span class="preprocessor"></span><span class="preprocessor">#define IRPLIB_WAVECAL_LAB_C3             "C_3"</span>
+<a name="l00054"></a>00054 <span class="preprocessor"></span><span class="preprocessor">#define IRPLIB_WAVECAL_LAB_C4             "C_4"</span>
+<a name="l00055"></a>00055 <span class="preprocessor"></span>
+<a name="l00056"></a>00056 <span class="preprocessor">#define IRPLIB_WAVECAL_LAB_WAVE           "WAVELENGTH"</span>
+<a name="l00057"></a>00057 <span class="preprocessor"></span><span class="preprocessor">#define IRPLIB_WAVECAL_LAB_INTENS         "INTENSITY"</span>
+<a name="l00058"></a>00058 <span class="preprocessor"></span>
+<a name="l00059"></a>00059 
+<a name="l00060"></a>00060 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00061"></a>00061 <span class="comment">                               New Types</span>
+<a name="l00062"></a>00062 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00063"></a>00063 
+<a name="l00064"></a>00064 <span class="comment">/* Any spectrum model must have these members first! */</span>
+<a name="l00065"></a>00065 <span class="keyword">typedef</span> <span class="keyword">struct </span>{
+<a name="l00066"></a>00066     <span class="keywordtype">unsigned</span>             cost;    <span class="comment">/* May be incremented for cost counting */</span>
+<a name="l00067"></a>00067     <span class="keywordtype">unsigned</span>             xcost;   <span class="comment">/* Ditto (can exclude failed fills) */</span>
+<a name="l00068"></a>00068     <span class="keywordtype">unsigned</span>             ulines;  <span class="comment">/* May be set to number of lines used */</span>
+<a name="l00069"></a>00069 
+<a name="l00070"></a>00070 } irplib_base_spectrum_model;
+<a name="l00071"></a>00071 
+<a name="l00072"></a>00072 <span class="keyword">typedef</span> <span class="keyword">struct </span>{
+<a name="l00073"></a>00073     <span class="keywordtype">unsigned</span>             cost;    <span class="comment">/* May be incremented for cost counting */</span>
+<a name="l00074"></a>00074     <span class="keywordtype">unsigned</span>             xcost;   <span class="comment">/* Ditto (can exclude failed fills) */</span>
+<a name="l00075"></a>00075     <span class="keywordtype">unsigned</span>             ulines;  <span class="comment">/* May be set to number of lines used */</span>
+<a name="l00076"></a>00076 
+<a name="l00077"></a>00077     <span class="keywordtype">double</span>               wslit;  <span class="comment">/* Slit Width */</span>
+<a name="l00078"></a>00078     <span class="keywordtype">double</span>               wfwhm;  <span class="comment">/* FWHM of transfer function */</span>
+<a name="l00079"></a>00079     <span class="keywordtype">double</span>               xtrunc; <span class="comment">/* Truncate transfer function beyond xtrunc,</span>
+<a name="l00080"></a>00080 <span class="comment">                                    xtrunc > 0 */</span>
+<a name="l00081"></a>00081     <span class="keyword">const</span> cpl_bivector * lines;  <span class="comment">/* Catalogue of intensities, with</span>
+<a name="l00082"></a>00082 <span class="comment">                                    increasing X-vector elements */</span>
+<a name="l00083"></a>00083     cpl_vector         * linepix;  <span class="comment">/* Catalogue of line pixel positions</span>
+<a name="l00084"></a>00084 <span class="comment">                                      - zero for uninitialized */</span>
+<a name="l00085"></a>00085     cpl_vector         * erftmp;  <span class="comment">/* Temporary storage for erf() values</span>
+<a name="l00086"></a>00086 <span class="comment">                                      - zero for uninitialized */</span>
+<a name="l00087"></a>00087 } irplib_line_spectrum_model;
+<a name="l00088"></a>00088 
+<a name="l00089"></a>00089 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00090"></a>00090 <span class="comment">                                   Function Prototypes</span>
+<a name="l00091"></a>00091 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00092"></a>00092 
+<a name="l00093"></a>00093 cpl_error_code
+<a name="l00094"></a>00094 <a class="code" href="group__irplib__wavecal.html#ga0adf260c4d27fc50bc8b4cbcc0264a4e" title="Modify self by maximizing the cross-correlation across all maxima.">irplib_polynomial_find_1d_from_correlation_all</a>(cpl_polynomial *,
+<a name="l00095"></a>00095                                                <span class="keywordtype">int</span>,
+<a name="l00096"></a>00096                                                <span class="keyword">const</span> cpl_vector *,
+<a name="l00097"></a>00097                                                <span class="keywordtype">int</span>, <span class="keywordtype">int</span>,
+<a name="l00098"></a>00098                                                irplib_base_spectrum_model *,
+<a name="l00099"></a>00099                                                cpl_error_code (*)
+<a name="l00100"></a>00100                                                (cpl_vector *,
+<a name="l00101"></a>00101                                                 <span class="keyword">const</span> cpl_polynomial *,
+<a name="l00102"></a>00102                                                 irplib_base_spectrum_model *,
+<a name="l00103"></a>00103                                                 <span class="keywordtype">int</span>),
+<a name="l00104"></a>00104                                                <span class="keywordtype">double</span>,
+<a name="l00105"></a>00105                                                <span class="keywordtype">double</span>,
+<a name="l00106"></a>00106                                                <span class="keywordtype">int</span>,
+<a name="l00107"></a>00107                                                <span class="keywordtype">int</span>,
+<a name="l00108"></a>00108                                                <span class="keywordtype">int</span>,
+<a name="l00109"></a>00109                                                <span class="keywordtype">int</span>,
+<a name="l00110"></a>00110                                                cpl_boolean,
+<a name="l00111"></a>00111                                                <span class="keywordtype">double</span> *);
+<a name="l00112"></a>00112 
+<a name="l00113"></a>00113 cpl_error_code
+<a name="l00114"></a>00114 <a class="code" href="group__irplib__wavecal.html#gae027096b411661b9584c72ab3e8e6547" title="Find shift(s) that maximizes (locally) the cross-correlation.">irplib_bivector_find_shift_from_correlation</a>(cpl_bivector *,
+<a name="l00115"></a>00115                                             <span class="keyword">const</span> cpl_polynomial *,
+<a name="l00116"></a>00116                                             <span class="keyword">const</span> cpl_vector *,
+<a name="l00117"></a>00117                                             irplib_base_spectrum_model *,
+<a name="l00118"></a>00118                                             cpl_error_code (*)
+<a name="l00119"></a>00119                                             (cpl_vector *,
+<a name="l00120"></a>00120                                              <span class="keyword">const</span> cpl_polynomial *,
+<a name="l00121"></a>00121                                              irplib_base_spectrum_model *, <span class="keywordtype">int</span>),
+<a name="l00122"></a>00122                                             <span class="keywordtype">int</span>,
+<a name="l00123"></a>00123                                             cpl_boolean,
+<a name="l00124"></a>00124                                             <span class="keywordtype">double</span> *);
+<a name="l00125"></a>00125 
+<a name="l00126"></a>00126 cpl_error_code
+<a name="l00127"></a>00127 <a class="code" href="group__irplib__wavecal.html#gabaec991ebc1b856766bf66768c4a6a19" title="Shift self by the amount that maximizes the cross-correlation.">irplib_polynomial_shift_1d_from_correlation</a>(cpl_polynomial *,
+<a name="l00128"></a>00128                                             <span class="keyword">const</span> cpl_vector *,
+<a name="l00129"></a>00129                                             irplib_base_spectrum_model *,
+<a name="l00130"></a>00130                                             cpl_error_code (*)
+<a name="l00131"></a>00131                                             (cpl_vector *,
+<a name="l00132"></a>00132                                              <span class="keyword">const</span> cpl_polynomial *,
+<a name="l00133"></a>00133                                              irplib_base_spectrum_model *, <span class="keywordtype">int</span>),
+<a name="l00134"></a>00134                                             <span class="keywordtype">int</span>, cpl_boolean, <span class="keywordtype">double</span> *);
+<a name="l00135"></a>00135 
+<a name="l00136"></a>00136 cpl_error_code
+<a name="l00137"></a>00137 <a class="code" href="group__irplib__wavecal.html#gaaa889f20c9483965ff6bab186d4f9972" title="Modify self by maximizing the cross-correlation.">irplib_polynomial_find_1d_from_correlation</a>(cpl_polynomial *, <span class="keywordtype">int</span>,
+<a name="l00138"></a>00138                                            <span class="keyword">const</span> cpl_vector *,
+<a name="l00139"></a>00139                                            irplib_base_spectrum_model *,
+<a name="l00140"></a>00140                                            cpl_error_code (*)
+<a name="l00141"></a>00141                                            (cpl_vector *,
+<a name="l00142"></a>00142                                             <span class="keyword">const</span> cpl_polynomial *,
+<a name="l00143"></a>00143                                             irplib_base_spectrum_model *, <span class="keywordtype">int</span>),
+<a name="l00144"></a>00144                                            <span class="keywordtype">double</span>, <span class="keywordtype">double</span>,
+<a name="l00145"></a>00145                                            <span class="keywordtype">int</span>, <span class="keywordtype">int</span>, <span class="keywordtype">double</span> *);
+<a name="l00146"></a>00146 
+<a name="l00147"></a>00147 cpl_error_code <a class="code" href="group__irplib__wavecal.html#ga44aa21cb1fc1459ab3b360748a737974" title="Generate a 1D spectrum from a model and a dispersion relation.">irplib_vector_fill_line_spectrum</a>(cpl_vector *,
+<a name="l00148"></a>00148                                                 <span class="keyword">const</span> cpl_polynomial *,
+<a name="l00149"></a>00149                                                 irplib_base_spectrum_model *,
+<a name="l00150"></a>00150                                                 <span class="keywordtype">int</span>);
+<a name="l00151"></a>00151 
+<a name="l00152"></a>00152 cpl_error_code <a class="code" href="group__irplib__wavecal.html#ga631e29d63bc65109f458915b5d1c8bb9" title="Generate a 1D spectrum from a model and a dispersion relation.">irplib_vector_fill_logline_spectrum</a>(cpl_vector *,
+<a name="l00153"></a>00153                                                    <span class="keyword">const</span> cpl_polynomial *,
+<a name="l00154"></a>00154                                                    irplib_base_spectrum_model *,
+<a name="l00155"></a>00155                                                    <span class="keywordtype">int</span>);
+<a name="l00156"></a>00156 
+<a name="l00157"></a>00157 cpl_error_code
+<a name="l00158"></a>00158 <a class="code" href="group__irplib__wavecal.html#gae8e236a419dedc99eab52690f4a33901" title="Generate a 1D spectrum from a model and a dispersion relation.">irplib_vector_fill_line_spectrum_fast</a>(cpl_vector *,
+<a name="l00159"></a>00159                                       <span class="keyword">const</span> cpl_polynomial *,
+<a name="l00160"></a>00160                                       irplib_base_spectrum_model *,
+<a name="l00161"></a>00161                                       <span class="keywordtype">int</span>);
+<a name="l00162"></a>00162 
+<a name="l00163"></a>00163 cpl_error_code
+<a name="l00164"></a>00164 <a class="code" href="group__irplib__wavecal.html#gaa0000d5a34e290fc93dfcc936e631eb7" title="Generate a 1D spectrum from a model and a dispersion relation.">irplib_vector_fill_logline_spectrum_fast</a>(cpl_vector *,
+<a name="l00165"></a>00165                                          <span class="keyword">const</span> cpl_polynomial *,
+<a name="l00166"></a>00166                                          irplib_base_spectrum_model *,
+<a name="l00167"></a>00167                                          <span class="keywordtype">int</span>);
+<a name="l00168"></a>00168 
+<a name="l00169"></a>00169 cpl_error_code <a class="code" href="group__irplib__wavecal.html#ga7eec8e48f4888aba01b98d9e0dc2acc5" title="Plot a 1D spectrum and one from a model.">irplib_plot_spectrum_and_model</a>(<span class="keyword">const</span> cpl_vector *,
+<a name="l00170"></a>00170                                               <span class="keyword">const</span> cpl_polynomial *,
+<a name="l00171"></a>00171                                               irplib_base_spectrum_model *,
+<a name="l00172"></a>00172                                               cpl_error_code (*)
+<a name="l00173"></a>00173                                               (cpl_vector *,
+<a name="l00174"></a>00174                                                <span class="keyword">const</span> cpl_polynomial *,
+<a name="l00175"></a>00175                                                irplib_base_spectrum_model *,
+<a name="l00176"></a>00176                                                <span class="keywordtype">int</span>));
+<a name="l00177"></a>00177 
+<a name="l00178"></a>00178 cpl_error_code <a class="code" href="group__irplib__wavecal.html#ga2dd3251367e2ee8b8bd5ce080e9f31bb" title="Fit a 2D-dispersion from an image of wavelengths.">irplib_polynomial_fit_2d_dispersion</a>(cpl_polynomial *,
+<a name="l00179"></a>00179                                                    <span class="keyword">const</span> cpl_image *,
+<a name="l00180"></a>00180                                                    <span class="keywordtype">int</span>, <span class="keywordtype">double</span> *);
+<a name="l00181"></a>00181 
+<a name="l00182"></a>00182 <span class="keywordtype">int</span> <a class="code" href="group__irplib__wavecal.html#ga03d7f038adc7e18e7a9071581fa47a25" title="Count the positive Y-entries in a given X-range.">irplib_bivector_count_positive</a>(<span class="keyword">const</span> cpl_bivector *, <span class="keywordtype">double</span>, <span class="keywordtype">double</span>);
+<a name="l00183"></a>00183 
+<a name="l00184"></a>00184 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/irplib__wavecal__impl_8h_source.html b/html/irplib__wavecal__impl_8h_source.html
new file mode 100644
index 0000000..16b4904
--- /dev/null
+++ b/html/irplib__wavecal__impl_8h_source.html
@@ -0,0 +1,72 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: irplib_wavecal_impl.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>irplib_wavecal_impl.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: irplib_wavecal_impl.h,v 1.6 2009/10/21 14:49:42 llundin Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the IRPLIB Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: llundin $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2009/10/21 14:49:42 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.6 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifndef IRPLIB_WAVECAL_IMPL_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#define IRPLIB_WAVECAL_IMPL_H</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span>
+<a name="l00031"></a>00031 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00032"></a>00032 <span class="comment">                                   Includes</span>
+<a name="l00033"></a>00033 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00034"></a>00034 
+<a name="l00035"></a>00035 <span class="preprocessor">#include "irplib_wavecal.h"</span>
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00038"></a>00038 <span class="comment">                             Private Function Prototypes</span>
+<a name="l00039"></a>00039 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00040"></a>00040 
+<a name="l00041"></a>00041 cpl_error_code <a class="code" href="group__irplib__wavecal.html#ga0db5e24244f88b41627d5a385af81b33" title="Generate a 1D spectrum from (arc) lines and a dispersion relation.">irplib_vector_fill_line_spectrum_model</a>(cpl_vector *,
+<a name="l00042"></a>00042                                                       cpl_vector *,
+<a name="l00043"></a>00043                                                       cpl_vector *,
+<a name="l00044"></a>00044                                                       <span class="keyword">const</span> cpl_polynomial *,
+<a name="l00045"></a>00045                                                       <span class="keyword">const</span> cpl_bivector *,
+<a name="l00046"></a>00046                                                       <span class="keywordtype">double</span>,
+<a name="l00047"></a>00047                                                       <span class="keywordtype">double</span>,
+<a name="l00048"></a>00048                                                       <span class="keywordtype">double</span>,
+<a name="l00049"></a>00049                                                       <span class="keywordtype">int</span>,
+<a name="l00050"></a>00050                                                       cpl_boolean,
+<a name="l00051"></a>00051                                                       cpl_boolean,
+<a name="l00052"></a>00052                                                       <span class="keywordtype">unsigned</span> *);
+<a name="l00053"></a>00053 
+<a name="l00054"></a>00054 <span class="keywordtype">double</span> <a class="code" href="group__irplib__wavecal.html#ga2da9c21054a19322705de2d4f48d1d3f" title="The antiderivative of erx(x/sigma/sqrt(2)) with respect to x.">irplib_erf_antideriv</a>(<span class="keywordtype">double</span>, <span class="keywordtype">double</span>);
+<a name="l00055"></a>00055 
+<a name="l00056"></a>00056 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/irplib__wcs_8c_source.html b/html/irplib__wcs_8c_source.html
new file mode 100644
index 0000000..4955752
--- /dev/null
+++ b/html/irplib__wcs_8c_source.html
@@ -0,0 +1,311 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: irplib_wcs.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>irplib_wcs.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: irplib_wcs.c,v 1.8 2010/10/07 14:10:55 llundin Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the irplib package</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: llundin $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2010/10/07 14:10:55 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.8 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span>
+<a name="l00032"></a>00032 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                                   Includes</span>
+<a name="l00034"></a>00034 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 
+<a name="l00036"></a>00036 <span class="preprocessor">#include <math.h></span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00038"></a>00038 
+<a name="l00039"></a>00039 <span class="preprocessor">#include "irplib_wcs.h"</span>
+<a name="l00040"></a>00040 
+<a name="l00041"></a>00041 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00045"></a>00045 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00046"></a>00046 
+<a name="l00047"></a>00047 <span class="keyword">static</span> cpl_error_code irplib_wcs_is_iso8601(<span class="keywordtype">int</span>, <span class="keywordtype">int</span>, <span class="keywordtype">int</span>, <span class="keywordtype">int</span>, <span class="keywordtype">int</span>, <span class="keywordtype">double</span>);
+<a name="l00048"></a>00048 
+<a name="l00051"></a>00051 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00062"></a>00062 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00063"></a>00063 cpl_error_code irplib_wcs_xytoradec(<span class="keyword">const</span> cpl_wcs *wcs,
+<a name="l00064"></a>00064                                     <span class="keywordtype">double</span>         x,
+<a name="l00065"></a>00065                                     <span class="keywordtype">double</span>         y,
+<a name="l00066"></a>00066                                     <span class="keywordtype">double</span>        *ra,
+<a name="l00067"></a>00067                                     <span class="keywordtype">double</span>        *dec)
+<a name="l00068"></a>00068 {
+<a name="l00069"></a>00069     cpl_matrix   * xy;
+<a name="l00070"></a>00070     cpl_matrix   * radec  = NULL;
+<a name="l00071"></a>00071     cpl_array    * status = NULL;
+<a name="l00072"></a>00072     cpl_error_code error;
+<a name="l00073"></a>00073 
+<a name="l00074"></a>00074     cpl_ensure_code(ra  != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00075"></a>00075     cpl_ensure_code(dec != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00076"></a>00076 
+<a name="l00077"></a>00077     <span class="comment">/* Load up the information */</span>
+<a name="l00078"></a>00078     xy = cpl_matrix_new(1, 2);
+<a name="l00079"></a>00079     cpl_matrix_set(xy, 0, 0, x);
+<a name="l00080"></a>00080     cpl_matrix_set(xy, 0, 1, y);
+<a name="l00081"></a>00081 
+<a name="l00082"></a>00082     <span class="comment">/* Call the conversion routine */</span>
+<a name="l00083"></a>00083     error = cpl_wcs_convert(wcs, xy, &radec, &status, CPL_WCS_PHYS2WORLD);
+<a name="l00084"></a>00084 
+<a name="l00085"></a>00085     cpl_matrix_delete(xy);
+<a name="l00086"></a>00086 
+<a name="l00087"></a>00087     <span class="keywordflow">if</span> (!error) {
+<a name="l00088"></a>00088 
+<a name="l00089"></a>00089         <span class="comment">/* Pass it back now */</span>
+<a name="l00090"></a>00090         *ra  = cpl_matrix_get(radec, 0, 0);
+<a name="l00091"></a>00091         *dec = cpl_matrix_get(radec, 0, 1);
+<a name="l00092"></a>00092 
+<a name="l00093"></a>00093     }
+<a name="l00094"></a>00094 
+<a name="l00095"></a>00095     <span class="comment">/* Tidy and propagate error, if any */</span>
+<a name="l00096"></a>00096     cpl_matrix_delete(radec);
+<a name="l00097"></a>00097     cpl_array_delete(status);
+<a name="l00098"></a>00098 
+<a name="l00099"></a>00099     <span class="keywordflow">return</span> cpl_error_set_where(cpl_func);
+<a name="l00100"></a>00100 }
+<a name="l00101"></a>00101 
+<a name="l00102"></a>00102 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00113"></a>00113 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00114"></a>00114 cpl_error_code irplib_wcs_radectoxy(<span class="keyword">const</span> cpl_wcs * wcs,
+<a name="l00115"></a>00115                                     <span class="keywordtype">double</span>          ra,
+<a name="l00116"></a>00116                                     <span class="keywordtype">double</span>          dec,
+<a name="l00117"></a>00117                                     <span class="keywordtype">double</span>        * x,
+<a name="l00118"></a>00118                                     <span class="keywordtype">double</span>        * y)
+<a name="l00119"></a>00119 {
+<a name="l00120"></a>00120     cpl_matrix   * radec;
+<a name="l00121"></a>00121     cpl_matrix   * xy = NULL;
+<a name="l00122"></a>00122     cpl_array    * status   = NULL;
+<a name="l00123"></a>00123     cpl_error_code error;
+<a name="l00124"></a>00124 
+<a name="l00125"></a>00125     cpl_ensure_code(x != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00126"></a>00126     cpl_ensure_code(y != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00127"></a>00127 
+<a name="l00128"></a>00128     <span class="comment">/* Feed the matrix with RA, DEC */</span>
+<a name="l00129"></a>00129     radec = cpl_matrix_new(1, 2);
+<a name="l00130"></a>00130     cpl_matrix_set(radec, 0, 0, ra);
+<a name="l00131"></a>00131     cpl_matrix_set(radec, 0, 1, dec);
+<a name="l00132"></a>00132 
+<a name="l00133"></a>00133     error = cpl_wcs_convert(wcs, radec, &xy, &status, CPL_WCS_WORLD2PHYS);
+<a name="l00134"></a>00134 
+<a name="l00135"></a>00135     cpl_matrix_delete(radec);
+<a name="l00136"></a>00136 
+<a name="l00137"></a>00137     <span class="keywordflow">if</span> (!error) {
+<a name="l00138"></a>00138 
+<a name="l00139"></a>00139         *x  = cpl_matrix_get(xy, 0, 0);
+<a name="l00140"></a>00140         *y  = cpl_matrix_get(xy, 0, 1);
+<a name="l00141"></a>00141 
+<a name="l00142"></a>00142     }
+<a name="l00143"></a>00143 
+<a name="l00144"></a>00144     <span class="comment">/* Tidy and propagate error, if any */</span>
+<a name="l00145"></a>00145     cpl_array_delete(status);
+<a name="l00146"></a>00146     cpl_matrix_delete(xy);
+<a name="l00147"></a>00147 
+<a name="l00148"></a>00148     <span class="keywordflow">return</span> cpl_error_set_where(cpl_func);
+<a name="l00149"></a>00149 
+<a name="l00150"></a>00150 }
+<a name="l00151"></a>00151 
+<a name="l00152"></a>00152 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00162"></a>00162 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00163"></a>00163 <span class="keywordtype">double</span> irplib_wcs_great_circle_dist(<span class="keywordtype">double</span> ra1,
+<a name="l00164"></a>00164                                     <span class="keywordtype">double</span> dec1,
+<a name="l00165"></a>00165                                     <span class="keywordtype">double</span> ra2,
+<a name="l00166"></a>00166                                     <span class="keywordtype">double</span> dec2)
+<a name="l00167"></a>00167 {
+<a name="l00168"></a>00168 
+<a name="l00169"></a>00169     <span class="comment">/* Convert all input from degrees to radian - and back for the result */</span>
+<a name="l00170"></a>00170     <span class="keyword">const</span> <span class="keywordtype">double</span> dra  = sin( CPL_MATH_RAD_DEG * (ra2  - ra1 )/2.0 );
+<a name="l00171"></a>00171     <span class="keyword">const</span> <span class="keywordtype">double</span> ddec = sin( CPL_MATH_RAD_DEG * (dec2 - dec1)/2.0 );
+<a name="l00172"></a>00172 
+<a name="l00173"></a>00173     dec1 *= CPL_MATH_RAD_DEG;
+<a name="l00174"></a>00174     dec2 *= CPL_MATH_RAD_DEG;
+<a name="l00175"></a>00175 
+<a name="l00176"></a>00176     <span class="keywordflow">return</span> 2.0 * asin(sqrt( ddec*ddec + cos(dec1)*cos(dec2)*dra*dra))
+<a name="l00177"></a>00177         * CPL_MATH_DEG_RAD;
+<a name="l00178"></a>00178 }
+<a name="l00179"></a>00179 
+<a name="l00180"></a>00180 
+<a name="l00181"></a>00181 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00195"></a>00195 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00196"></a>00196 cpl_error_code irplib_wcs_mjd_from_iso8601(<span class="keywordtype">double</span> * pmjd, <span class="keywordtype">int</span> year, <span class="keywordtype">int</span> month,
+<a name="l00197"></a>00197                                            <span class="keywordtype">int</span> day, <span class="keywordtype">int</span> hour, <span class="keywordtype">int</span> minute,
+<a name="l00198"></a>00198                                            <span class="keywordtype">double</span> second)
+<a name="l00199"></a>00199 {
+<a name="l00200"></a>00200 
+<a name="l00201"></a>00201     cpl_ensure_code(pmjd  != NULL,        CPL_ERROR_NULL_INPUT);
+<a name="l00202"></a>00202     cpl_ensure_code(!irplib_wcs_is_iso8601(year, month, day, hour, minute,
+<a name="l00203"></a>00203                                            second), cpl_error_get_code());
+<a name="l00204"></a>00204 
+<a name="l00205"></a>00205     <span class="comment">/* Compute MJD. */</span>
+<a name="l00206"></a>00206     *pmjd = (double)((1461*(year - (12-month)/10 + 4712))/4
+<a name="l00207"></a>00207                      + (306*((month+9)%12) + 5)/10
+<a name="l00208"></a>00208                      - (3*((year - (12-month)/10 + 4900)/100))/4
+<a name="l00209"></a>00209                      + day - 2399904)
+<a name="l00210"></a>00210         + (hour + (minute + second/60.0)/60.0)/24.0;
+<a name="l00211"></a>00211 
+<a name="l00212"></a>00212     <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l00213"></a>00213 
+<a name="l00214"></a>00214 }
+<a name="l00215"></a>00215 
+<a name="l00216"></a>00216 
+<a name="l00217"></a>00217 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00233"></a>00233 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00234"></a>00234 cpl_error_code irplib_wcs_iso8601_from_string(<span class="keywordtype">int</span> * pyear, <span class="keywordtype">int</span> * pmonth,
+<a name="l00235"></a>00235                                               <span class="keywordtype">int</span> * pday, <span class="keywordtype">int</span> * phour,
+<a name="l00236"></a>00236                                               <span class="keywordtype">int</span> * pminute, <span class="keywordtype">double</span> * psecond,
+<a name="l00237"></a>00237                                               <span class="keyword">const</span> <span class="keywordtype">char</span> * iso8601)
+<a name="l00238"></a>00238 {
+<a name="l00239"></a>00239 
+<a name="l00240"></a>00240     <span class="comment">/* Standard year-2000 form: CCYY-MM-DD[Thh:mm:ss[.sss...]] */</span>
+<a name="l00241"></a>00241     <span class="keyword">const</span> <span class="keywordtype">char</span> * iso8601format = <span class="stringliteral">"%4d-%2d-%2dT%2d:%2d:%lf"</span>;
+<a name="l00242"></a>00242 
+<a name="l00243"></a>00243     cpl_ensure_code(pyear   != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00244"></a>00244     cpl_ensure_code(pmonth  != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00245"></a>00245     cpl_ensure_code(pday    != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00246"></a>00246     cpl_ensure_code(phour   != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00247"></a>00247     cpl_ensure_code(pminute != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00248"></a>00248     cpl_ensure_code(psecond != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00249"></a>00249     cpl_ensure_code(iso8601 != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00250"></a>00250 
+<a name="l00251"></a>00251     cpl_error_ensure(sscanf(iso8601, iso8601format, pyear, pmonth,
+<a name="l00252"></a>00252                             pday, phour, pminute, psecond) == 6,
+<a name="l00253"></a>00253                      CPL_ERROR_ILLEGAL_INPUT, <span class="keywordflow">return</span> cpl_error_get_code(),
+<a name="l00254"></a>00254                      <span class="stringliteral">"%s is not formatted as %s"</span>, iso8601, iso8601format);
+<a name="l00255"></a>00255 
+<a name="l00256"></a>00256     cpl_ensure_code(!irplib_wcs_is_iso8601(*pyear, *pmonth, *pday, *phour,
+<a name="l00257"></a>00257                                            *pminute, *psecond),
+<a name="l00258"></a>00258                     cpl_error_get_code());
+<a name="l00259"></a>00259 
+<a name="l00260"></a>00260     <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l00261"></a>00261 }
+<a name="l00262"></a>00262 
+<a name="l00263"></a>00263 
+<a name="l00264"></a>00264 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00273"></a>00273 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00274"></a>00274 cpl_error_code irplib_wcs_mjd_from_string(<span class="keywordtype">double</span> * pmjd, <span class="keyword">const</span> <span class="keywordtype">char</span> * iso8601)
+<a name="l00275"></a>00275 {
+<a name="l00276"></a>00276 
+<a name="l00277"></a>00277 
+<a name="l00278"></a>00278     <span class="keywordtype">int</span> year, day, month, hour, minute;
+<a name="l00279"></a>00279     <span class="keywordtype">double</span> second;
+<a name="l00280"></a>00280 
+<a name="l00281"></a>00281     <span class="keywordflow">return</span> irplib_wcs_iso8601_from_string(&year, &month, &day, &hour,
+<a name="l00282"></a>00282                                           &minute, &second, iso8601)
+<a name="l00283"></a>00283         || irplib_wcs_mjd_from_iso8601(pmjd, year, month, day, hour, minute,
+<a name="l00284"></a>00284                                        second)
+<a name="l00285"></a>00285         ? cpl_error_set_where(cpl_func) : CPL_ERROR_NONE;
+<a name="l00286"></a>00286 }
+<a name="l00287"></a>00287 
+<a name="l00288"></a>00288 
+<a name="l00289"></a>00289 
+<a name="l00290"></a>00290 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00304"></a>00304 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00305"></a>00305 cpl_error_code irplib_wcs_iso8601_from_mjd(<span class="keywordtype">int</span> * pyear, <span class="keywordtype">int</span> * pmonth,
+<a name="l00306"></a>00306                                            <span class="keywordtype">int</span> * pday, <span class="keywordtype">int</span> * phour,
+<a name="l00307"></a>00307                                            <span class="keywordtype">int</span> * pminute, <span class="keywordtype">double</span> * psecond,
+<a name="l00308"></a>00308                                            <span class="keywordtype">double</span> mjd)
+<a name="l00309"></a>00309 {
+<a name="l00310"></a>00310 
+<a name="l00311"></a>00311     <span class="keywordtype">int</span> jd, n4, dd;
+<a name="l00312"></a>00312     <span class="keywordtype">double</span> t;
+<a name="l00313"></a>00313 
+<a name="l00314"></a>00314     cpl_ensure_code(pyear   != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00315"></a>00315     cpl_ensure_code(pmonth  != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00316"></a>00316     cpl_ensure_code(pday    != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00317"></a>00317     cpl_ensure_code(phour   != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00318"></a>00318     cpl_ensure_code(pminute != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00319"></a>00319     cpl_ensure_code(psecond != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00320"></a>00320 
+<a name="l00321"></a>00321     <span class="comment">/* Copied from datfix() in wcslib (v. 4.4.4) */</span>
+<a name="l00322"></a>00322 
+<a name="l00323"></a>00323     jd = 2400001 + (int)mjd;
+<a name="l00324"></a>00324 
+<a name="l00325"></a>00325     n4 =  4*(jd + ((2*((4*jd - 17918)/146097)*3)/4 + 1)/2 - 37);
+<a name="l00326"></a>00326     dd = 10*(((n4-237)%1461)/4) + 5;
+<a name="l00327"></a>00327 
+<a name="l00328"></a>00328     *pyear  = n4/1461 - 4712;
+<a name="l00329"></a>00329     *pmonth = (2 + dd/306)%12 + 1;
+<a name="l00330"></a>00330     *pday   = (dd%306)/10 + 1;
+<a name="l00331"></a>00331 
+<a name="l00332"></a>00332     t = mjd - (int)mjd; <span class="comment">/* t is now days */</span>
+<a name="l00333"></a>00333 
+<a name="l00334"></a>00334     t *= 24.0; <span class="comment">/* t is now hours */</span>
+<a name="l00335"></a>00335     *phour = (int)t;
+<a name="l00336"></a>00336     t = 60.0 * (t - *phour); <span class="comment">/* t is now minutes */</span>
+<a name="l00337"></a>00337     *pminute = (int)t;
+<a name="l00338"></a>00338     *psecond = 60.0 * (t - *pminute);
+<a name="l00339"></a>00339 
+<a name="l00340"></a>00340     <span class="comment">/* A failure here implies that this code has a bug */</span>
+<a name="l00341"></a>00341     cpl_ensure_code(!irplib_wcs_is_iso8601(*pyear, *pmonth, *pday, *phour,
+<a name="l00342"></a>00342                                            *pminute, *psecond),
+<a name="l00343"></a>00343                     CPL_ERROR_UNSPECIFIED);
+<a name="l00344"></a>00344 
+<a name="l00345"></a>00345     <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l00346"></a>00346 }
+<a name="l00347"></a>00347 
+<a name="l00348"></a>00348 
+<a name="l00351"></a>00351 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00363"></a>00363 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00364"></a>00364 <span class="keyword">static</span> cpl_error_code irplib_wcs_is_iso8601(<span class="keywordtype">int</span> year, <span class="keywordtype">int</span> month,
+<a name="l00365"></a>00365                                             <span class="keywordtype">int</span> day, <span class="keywordtype">int</span> hour,
+<a name="l00366"></a>00366                                             <span class="keywordtype">int</span> minute, <span class="keywordtype">double</span> second)
+<a name="l00367"></a>00367 {
+<a name="l00368"></a>00368 
+<a name="l00369"></a>00369     <span class="keyword">const</span> cpl_boolean is_leap = year % 4 ? CPL_FALSE : CPL_TRUE;
+<a name="l00370"></a>00370     <span class="keyword">const</span> <span class="keywordtype">int</span> mlen[] = {0, 31, is_leap ? 29 : 28, 31, 30, 31, 30, 31, 31, 30,
+<a name="l00371"></a>00371                         31, 30, 31};
+<a name="l00372"></a>00372 
+<a name="l00373"></a>00373     cpl_ensure_code(month > 0,            CPL_ERROR_ILLEGAL_INPUT);
+<a name="l00374"></a>00374     cpl_ensure_code(month <= 12,          CPL_ERROR_ILLEGAL_INPUT);
+<a name="l00375"></a>00375 
+<a name="l00376"></a>00376     cpl_ensure_code(day   > 0,            CPL_ERROR_ILLEGAL_INPUT);
+<a name="l00377"></a>00377     cpl_ensure_code(day   <= mlen[month], CPL_ERROR_ILLEGAL_INPUT);
+<a name="l00378"></a>00378 
+<a name="l00379"></a>00379     cpl_ensure_code(minute  < 60,         CPL_ERROR_ILLEGAL_INPUT);
+<a name="l00380"></a>00380     cpl_ensure_code(minute  >= 0,         CPL_ERROR_ILLEGAL_INPUT);
+<a name="l00381"></a>00381 
+<a name="l00382"></a>00382     cpl_ensure_code(second  < 60.0,       CPL_ERROR_ILLEGAL_INPUT);
+<a name="l00383"></a>00383     cpl_ensure_code(second  >= 0.0,       CPL_ERROR_ILLEGAL_INPUT);
+<a name="l00384"></a>00384 
+<a name="l00385"></a>00385     cpl_ensure_code(hour  >= 0,           CPL_ERROR_ILLEGAL_INPUT);
+<a name="l00386"></a>00386     <span class="comment">/* 24:00:00 is valid ISO-8601 */</span>
+<a name="l00387"></a>00387     cpl_ensure_code(hour  <= (minute > 0 || second > 0.0 ? 23 : 24),
+<a name="l00388"></a>00388                     CPL_ERROR_ILLEGAL_INPUT);
+<a name="l00389"></a>00389 
+<a name="l00390"></a>00390     <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l00391"></a>00391 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/irplib__wcs_8h_source.html b/html/irplib__wcs_8h_source.html
new file mode 100644
index 0000000..72a1816
--- /dev/null
+++ b/html/irplib__wcs_8h_source.html
@@ -0,0 +1,82 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: irplib_wcs.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>irplib_wcs.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: irplib_wcs.h,v 1.7 2010/10/07 14:10:55 llundin Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the irplib package</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: llundin $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2010/10/07 14:10:55 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.7 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifndef IRPLIB_WCS_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#define IRPLIB_WCS_H</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span>
+<a name="l00031"></a>00031 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00032"></a>00032 <span class="comment">                                   Includes</span>
+<a name="l00033"></a>00033 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00034"></a>00034 
+<a name="l00035"></a>00035 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 cpl_error_code irplib_wcs_xytoradec(<span class="keyword">const</span> cpl_wcs * wcs,
+<a name="l00038"></a>00038                                     <span class="keywordtype">double</span>          x,
+<a name="l00039"></a>00039                                     <span class="keywordtype">double</span>          y,
+<a name="l00040"></a>00040                                     <span class="keywordtype">double</span>        * ra,
+<a name="l00041"></a>00041                                     <span class="keywordtype">double</span>        * dec);
+<a name="l00042"></a>00042 
+<a name="l00043"></a>00043 cpl_error_code irplib_wcs_radectoxy(<span class="keyword">const</span> cpl_wcs * wcs,
+<a name="l00044"></a>00044                                     <span class="keywordtype">double</span>          ra,
+<a name="l00045"></a>00045                                     <span class="keywordtype">double</span>          dec,
+<a name="l00046"></a>00046                                     <span class="keywordtype">double</span>        * x,
+<a name="l00047"></a>00047                                     <span class="keywordtype">double</span>        * y);
+<a name="l00048"></a>00048 
+<a name="l00049"></a>00049 <span class="keywordtype">double</span> irplib_wcs_great_circle_dist(<span class="keywordtype">double</span> ra1,
+<a name="l00050"></a>00050                                     <span class="keywordtype">double</span> dec1,
+<a name="l00051"></a>00051                                     <span class="keywordtype">double</span> ra2,
+<a name="l00052"></a>00052                                     <span class="keywordtype">double</span> dec2);
+<a name="l00053"></a>00053 
+<a name="l00054"></a>00054 
+<a name="l00055"></a>00055 cpl_error_code irplib_wcs_iso8601_from_string(<span class="keywordtype">int</span> *, <span class="keywordtype">int</span> *, <span class="keywordtype">int</span> *, <span class="keywordtype">int</span> *, <span class="keywordtype">int</span> *,
+<a name="l00056"></a>00056                                               <span class="keywordtype">double</span> *, <span class="keyword">const</span> <span class="keywordtype">char</span> *);
+<a name="l00057"></a>00057 
+<a name="l00058"></a>00058 cpl_error_code irplib_wcs_mjd_from_iso8601(<span class="keywordtype">double</span> *, <span class="keywordtype">int</span>, <span class="keywordtype">int</span>, <span class="keywordtype">int</span>, <span class="keywordtype">int</span>, <span class="keywordtype">int</span>,
+<a name="l00059"></a>00059                                            <span class="keywordtype">double</span>);
+<a name="l00060"></a>00060 
+<a name="l00061"></a>00061 cpl_error_code irplib_wcs_mjd_from_string(<span class="keywordtype">double</span> *, <span class="keyword">const</span> <span class="keywordtype">char</span> *);
+<a name="l00062"></a>00062 
+<a name="l00063"></a>00063 cpl_error_code irplib_wcs_iso8601_from_mjd(<span class="keywordtype">int</span> *, <span class="keywordtype">int</span> *, <span class="keywordtype">int</span> *, <span class="keywordtype">int</span> *, <span class="keywordtype">int</span> *,
+<a name="l00064"></a>00064                                            <span class="keywordtype">double</span> *, <span class="keywordtype">double</span>);
+<a name="l00065"></a>00065 
+<a name="l00066"></a>00066 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/irplib__wlxcorr_8c_source.html b/html/irplib__wlxcorr_8c_source.html
new file mode 100644
index 0000000..9887138
--- /dev/null
+++ b/html/irplib__wlxcorr_8c_source.html
@@ -0,0 +1,1084 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: irplib_wlxcorr.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>irplib_wlxcorr.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: irplib_wlxcorr.c,v 1.55 2012/01/12 11:50:41 llundin Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the IRPLIB package</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: llundin $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2012/01/12 11:50:41 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.55 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span>
+<a name="l00032"></a>00032 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                                Includes</span>
+<a name="l00034"></a>00034 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 
+<a name="l00036"></a>00036 <span class="preprocessor">#include <math.h></span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include <string.h></span>
+<a name="l00038"></a>00038 
+<a name="l00039"></a>00039 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00040"></a>00040 
+<a name="l00041"></a>00041 <span class="preprocessor">#include "irplib_wavecal_impl.h"</span>
+<a name="l00042"></a>00042 
+<a name="l00043"></a>00043 <span class="preprocessor">#include "irplib_wlxcorr.h"</span>
+<a name="l00044"></a>00044 
+<a name="l00045"></a>00045 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00055"></a>00055 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00056"></a>00056 
+<a name="l00057"></a>00057 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00058"></a>00058 <span class="comment">                           Defines</span>
+<a name="l00059"></a>00059 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00060"></a>00060 
+<a name="l00061"></a>00061 <span class="comment">/* TEMPORARY SUPPORT OF CPL 5.x */</span>
+<a name="l00062"></a>00062 <span class="preprocessor">#ifndef CPL_SIZE_FORMAT</span>
+<a name="l00063"></a>00063 <span class="preprocessor"></span><span class="preprocessor">#define CPL_SIZE_FORMAT "d"</span>
+<a name="l00064"></a>00064 <span class="preprocessor"></span><span class="preprocessor">#define cpl_size int</span>
+<a name="l00065"></a>00065 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
+<a name="l00066"></a>00066 <span class="preprocessor"></span><span class="comment">/* END TEMPORARY SUPPORT OF CPL 5.x */</span>
+<a name="l00067"></a>00067 
+<a name="l00068"></a>00068 <span class="preprocessor">#ifndef inline</span>
+<a name="l00069"></a>00069 <span class="preprocessor"></span><span class="preprocessor">#define inline </span><span class="comment">/* inline */</span>
+<a name="l00070"></a>00070 <span class="preprocessor">#endif</span>
+<a name="l00071"></a>00071 <span class="preprocessor"></span>
+<a name="l00072"></a>00072 <span class="preprocessor">#define IRPLIB_MAX(A,B) ((A) > (B) ? (A) : (B))</span>
+<a name="l00073"></a>00073 <span class="preprocessor"></span><span class="preprocessor">#define IRPLIB_MIN(A,B) ((A) < (B) ? (A) : (B))</span>
+<a name="l00074"></a>00074 <span class="preprocessor"></span>
+<a name="l00075"></a>00075 <span class="preprocessor">#define IRPLIB_PTR_SWAP(a,b)                                               \</span>
+<a name="l00076"></a>00076 <span class="preprocessor">    do { void * irplib_ptr_swap =(a);(a)=(b);(b)=irplib_ptr_swap; } while (0)</span>
+<a name="l00077"></a>00077 <span class="preprocessor"></span>
+<a name="l00078"></a>00078 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00079"></a>00079 <span class="comment">                           Private functions</span>
+<a name="l00080"></a>00080 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00081"></a>00081 
+<a name="l00082"></a>00082 <span class="keyword">static</span> <span class="keywordtype">void</span> irplib_wlxcorr_estimate(cpl_vector *, cpl_vector *,
+<a name="l00083"></a>00083                                     <span class="keyword">const</span> cpl_vector *,
+<a name="l00084"></a>00084                                     <span class="keyword">const</span> cpl_bivector *,
+<a name="l00085"></a>00085                                     <span class="keyword">const</span> cpl_vector *,
+<a name="l00086"></a>00086                                     <span class="keyword">const</span> cpl_polynomial *,
+<a name="l00087"></a>00087                                     <span class="keywordtype">double</span>, <span class="keywordtype">double</span>);
+<a name="l00088"></a>00088 
+<a name="l00089"></a>00089 <span class="keyword">static</span> <span class="keywordtype">int</span> irplib_wlxcorr_signal_resample(cpl_vector *, <span class="keyword">const</span> cpl_vector *, 
+<a name="l00090"></a>00090         <span class="keyword">const</span> cpl_bivector *) ;
+<a name="l00091"></a>00091 <span class="keyword">static</span> cpl_error_code cpl_vector_fill_lss_profile_symmetric(cpl_vector *,
+<a name="l00092"></a>00092                                                             <span class="keywordtype">double</span>, <span class="keywordtype">double</span>);
+<a name="l00093"></a>00093 <span class="keyword">static</span> cpl_error_code irplib_wlcalib_fill_spectrum(cpl_vector *,
+<a name="l00094"></a>00094                                                 <span class="keyword">const</span> cpl_bivector *,
+<a name="l00095"></a>00095                                                 <span class="keyword">const</span> cpl_vector *,
+<a name="l00096"></a>00096                                                 <span class="keyword">const</span> cpl_polynomial *, <span class="keywordtype">int</span>);
+<a name="l00097"></a>00097 
+<a name="l00098"></a>00098 <span class="keyword">static</span> cpl_boolean irplib_wlcalib_is_lines(<span class="keyword">const</span> cpl_vector *,
+<a name="l00099"></a>00099                                         <span class="keyword">const</span> cpl_polynomial *,
+<a name="l00100"></a>00100                                         <span class="keywordtype">int</span>, <span class="keywordtype">double</span>);
+<a name="l00101"></a>00101 
+<a name="l00105"></a>00105 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00141"></a>00141 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00142"></a>00142 cpl_polynomial * irplib_wlxcorr_best_poly(<span class="keyword">const</span> cpl_vector     * spectrum,
+<a name="l00143"></a>00143                                           <span class="keyword">const</span> cpl_bivector   * lines_catalog,
+<a name="l00144"></a>00144                                           <span class="keywordtype">int</span>                    degree,
+<a name="l00145"></a>00145                                           <span class="keyword">const</span> cpl_polynomial * guess_poly,
+<a name="l00146"></a>00146                                           <span class="keyword">const</span> cpl_vector     * wl_error,
+<a name="l00147"></a>00147                                           <span class="keywordtype">int</span>                    nsamples,
+<a name="l00148"></a>00148                                           <span class="keywordtype">double</span>                 slitw,
+<a name="l00149"></a>00149                                           <span class="keywordtype">double</span>                 fwhm,
+<a name="l00150"></a>00150                                           <span class="keywordtype">double</span>               * xc,
+<a name="l00151"></a>00151                                           cpl_table           ** wlres,
+<a name="l00152"></a>00152                                           cpl_vector          ** xcorrs)
+<a name="l00153"></a>00153 {
+<a name="l00154"></a>00154     <span class="keyword">const</span> <span class="keywordtype">int</span>         spec_sz = cpl_vector_get_size(spectrum);
+<a name="l00155"></a>00155     <span class="keyword">const</span> <span class="keywordtype">int</span>         nfree   = cpl_vector_get_size(wl_error);
+<a name="l00156"></a>00156     <span class="keywordtype">int</span>               ntests  = 1;
+<a name="l00157"></a>00157     cpl_vector      * model;
+<a name="l00158"></a>00158     cpl_vector      * vxc;
+<a name="l00159"></a>00159     cpl_vector      * init_pts_wl;
+<a name="l00160"></a>00160     cpl_matrix      * init_pts_x;
+<a name="l00161"></a>00161     cpl_vector      * pts_wl;
+<a name="l00162"></a>00162     cpl_vector      * vxcorrs;
+<a name="l00163"></a>00163     cpl_vector      * conv_kernel = NULL;    
+<a name="l00164"></a>00164     cpl_polynomial  * poly_sol;
+<a name="l00165"></a>00165     cpl_polynomial  * poly_candi;
+<a name="l00166"></a>00166     <span class="keyword">const</span> <span class="keywordtype">double</span>    * pwl_error = cpl_vector_get_data_const(wl_error); 
+<a name="l00167"></a>00167     <span class="keyword">const</span> <span class="keywordtype">double</span>    * dxc;
+<a name="l00168"></a>00168     cpl_size          degree_loc ;
+<a name="l00169"></a>00169     <span class="keyword">const</span> cpl_boolean symsamp = CPL_TRUE; <span class="comment">/* init_pts_x is symmetric */</span>
+<a name="l00170"></a>00170     <span class="keyword">const</span> cpl_boolean is_lines
+<a name="l00171"></a>00171         = irplib_wlcalib_is_lines(cpl_bivector_get_x_const(lines_catalog),
+<a name="l00172"></a>00172                                guess_poly, spec_sz, 1.0);
+<a name="l00173"></a>00173     <span class="keywordtype">int</span>               i;
+<a name="l00174"></a>00174 
+<a name="l00175"></a>00175     <span class="comment">/* FIXME: Need mode parameter for catalogue type (lines <=> profile) */</span>
+<a name="l00176"></a>00176 
+<a name="l00177"></a>00177     <span class="comment">/* In case of failure */</span>
+<a name="l00178"></a>00178     <span class="keywordflow">if</span> (wlres  != NULL) *wlres  = NULL;
+<a name="l00179"></a>00179     <span class="keywordflow">if</span> (xcorrs != NULL) *xcorrs = NULL;
+<a name="l00180"></a>00180 
+<a name="l00181"></a>00181     <span class="comment">/* Useful for knowing if resampling is used */</span>
+<a name="l00182"></a>00182     cpl_msg_debug(cpl_func, <span class="stringliteral">"Checking %d^%d dispersion polynomials (slitw=%g, "</span>
+<a name="l00183"></a>00183                   <span class="stringliteral">"fwhm=%g) against %d-point observed spectrum with%s "</span>
+<a name="l00184"></a>00184                   <span class="stringliteral">"catalog resampling"</span>, nsamples, nfree, slitw, fwhm, spec_sz,
+<a name="l00185"></a>00185                   is_lines ? <span class="stringliteral">"out"</span> : <span class="stringliteral">""</span>);
+<a name="l00186"></a>00186 
+<a name="l00187"></a>00187     cpl_ensure(xc            != NULL, CPL_ERROR_NULL_INPUT,    NULL);
+<a name="l00188"></a>00188     *xc = -1.0;
+<a name="l00189"></a>00189     cpl_ensure(spectrum      != NULL,  CPL_ERROR_NULL_INPUT,    NULL);
+<a name="l00190"></a>00190     cpl_ensure(lines_catalog != NULL, CPL_ERROR_NULL_INPUT,    NULL);
+<a name="l00191"></a>00191     cpl_ensure(guess_poly    != NULL, CPL_ERROR_NULL_INPUT,    NULL);
+<a name="l00192"></a>00192     cpl_ensure(wl_error      != NULL, CPL_ERROR_NULL_INPUT,    NULL);
+<a name="l00193"></a>00193     cpl_ensure(nfree         >= 2,    CPL_ERROR_ILLEGAL_INPUT, NULL);
+<a name="l00194"></a>00194     cpl_ensure(nsamples      >  0,    CPL_ERROR_ILLEGAL_INPUT, NULL);
+<a name="l00195"></a>00195     <span class="comment">/* FIXME: degree is redundant */</span>
+<a name="l00196"></a>00196     cpl_ensure(1 + degree   == nfree, CPL_ERROR_ILLEGAL_INPUT, NULL);
+<a name="l00197"></a>00197 
+<a name="l00198"></a>00198     cpl_ensure(cpl_polynomial_get_dimension(guess_poly) == 1,
+<a name="l00199"></a>00199                CPL_ERROR_ILLEGAL_INPUT, NULL);
+<a name="l00200"></a>00200 
+<a name="l00201"></a>00201     <span class="keywordflow">if</span> (nsamples > 1) {
+<a name="l00202"></a>00202         <span class="comment">/* Search place must consist of more than one point */</span>
+<a name="l00203"></a>00203         <span class="comment">/* FIXME: The bounds should probably not be negative */</span>
+<a name="l00204"></a>00204         <span class="keywordflow">for</span> (i = 0; i < nfree; i++) {
+<a name="l00205"></a>00205             <span class="keywordflow">if</span> (pwl_error[i] != 0.0) <span class="keywordflow">break</span>;
+<a name="l00206"></a>00206         }
+<a name="l00207"></a>00207         cpl_ensure(i < nfree, CPL_ERROR_ILLEGAL_INPUT, NULL);
+<a name="l00208"></a>00208     }
+<a name="l00209"></a>00209  
+<a name="l00210"></a>00210     <span class="keywordflow">if</span> (!is_lines) {
+<a name="l00211"></a>00211         <span class="comment">/* Create the convolution kernel */</span>
+<a name="l00212"></a>00212         conv_kernel = irplib_wlxcorr_convolve_create_kernel(slitw, fwhm);
+<a name="l00213"></a>00213         cpl_ensure(conv_kernel   != NULL, CPL_ERROR_ILLEGAL_INPUT, NULL);
+<a name="l00214"></a>00214     }
+<a name="l00215"></a>00215 
+<a name="l00216"></a>00216     <span class="comment">/* Create initial test points */</span>
+<a name="l00217"></a>00217     init_pts_x  = cpl_matrix_new(1, nfree);
+<a name="l00218"></a>00218     init_pts_wl = cpl_vector_new(nfree);
+<a name="l00219"></a>00219     pts_wl      = cpl_vector_new(nfree);
+<a name="l00220"></a>00220     <span class="keywordflow">for</span> (i = 0; i < nfree; i++) {
+<a name="l00221"></a>00221         <span class="keyword">const</span> <span class="keywordtype">double</span> xpos  = spec_sz * i / (double)degree;
+<a name="l00222"></a>00222         <span class="keyword">const</span> <span class="keywordtype">double</span> wlpos = cpl_polynomial_eval_1d(guess_poly, xpos, NULL)
+<a name="l00223"></a>00223             - 0.5 * pwl_error[i];
+<a name="l00224"></a>00224 
+<a name="l00225"></a>00225         cpl_matrix_set(init_pts_x, 0, i, xpos);
+<a name="l00226"></a>00226         cpl_vector_set(init_pts_wl,   i, wlpos);
+<a name="l00227"></a>00227 
+<a name="l00228"></a>00228         ntests *= nsamples; <span class="comment">/* Count number of tests */</span>
+<a name="l00229"></a>00229 
+<a name="l00230"></a>00230     }
+<a name="l00231"></a>00231 
+<a name="l00232"></a>00232     vxcorrs = xcorrs != NULL ? cpl_vector_new(ntests) : NULL;
+<a name="l00233"></a>00233 
+<a name="l00234"></a>00234     poly_sol   = cpl_polynomial_new(1);
+<a name="l00235"></a>00235     poly_candi = cpl_polynomial_new(1);
+<a name="l00236"></a>00236     model = cpl_vector_new(spec_sz);
+<a name="l00237"></a>00237     vxc = cpl_vector_new(1);
+<a name="l00238"></a>00238     dxc = cpl_vector_get_data_const(vxc);
+<a name="l00239"></a>00239    
+<a name="l00240"></a>00240     <span class="comment">/* Create the polynomial candidates and estimate them */</span>
+<a name="l00241"></a>00241     <span class="keywordflow">for</span> (i=0; i < ntests; i++) {
+<a name="l00242"></a>00242         <span class="keywordtype">int</span>    idiv = i;
+<a name="l00243"></a>00243         <span class="keywordtype">int</span>    deg;
+<a name="l00244"></a>00244 
+<a name="l00245"></a>00245         <span class="comment">/* Update wavelength at one anchor point - and reset wavelengths</span>
+<a name="l00246"></a>00246 <span class="comment">           to their default for any anchor point(s) at higher wavelengths */</span>
+<a name="l00247"></a>00247         <span class="keywordflow">for</span> (deg = degree; deg >= 0; deg--, idiv /= nsamples) {
+<a name="l00248"></a>00248             <span class="keyword">const</span> <span class="keywordtype">int</span> imod = idiv % nsamples;
+<a name="l00249"></a>00249             <span class="keyword">const</span> <span class="keywordtype">double</span> wlpos = cpl_vector_get(init_pts_wl, deg)
+<a name="l00250"></a>00250                                + imod * pwl_error[deg] / nsamples;
+<a name="l00251"></a>00251 
+<a name="l00252"></a>00252             <span class="comment">/* FIXME: If wlpos causes pts_wl to be non-increasing, the</span>
+<a name="l00253"></a>00253 <span class="comment">               solution will be non-physical with no need for evaluation.</span>
+<a name="l00254"></a>00254 <span class="comment">               (*xc could be set to -1 in this case). */</span>
+<a name="l00255"></a>00255             cpl_vector_set(pts_wl, deg, wlpos);
+<a name="l00256"></a>00256 
+<a name="l00257"></a>00257             <span class="keywordflow">if</span> (imod > 0) <span class="keywordflow">break</span>;
+<a name="l00258"></a>00258         }
+<a name="l00259"></a>00259 
+<a name="l00260"></a>00260         <span class="comment">/* Generate */</span>
+<a name="l00261"></a>00261         degree_loc = (cpl_size)degree ;
+<a name="l00262"></a>00262         cpl_polynomial_fit(poly_candi, init_pts_x, &symsamp, pts_wl,
+<a name="l00263"></a>00263                            NULL, CPL_FALSE, NULL, &degree_loc);
+<a name="l00264"></a>00264         <span class="comment">/* *** Estimate *** */</span>
+<a name="l00265"></a>00265         irplib_wlxcorr_estimate(vxc, model, spectrum, lines_catalog,
+<a name="l00266"></a>00266                                 conv_kernel, poly_candi, slitw, fwhm);
+<a name="l00267"></a>00267         <span class="keywordflow">if</span> (vxcorrs != NULL) cpl_vector_set(vxcorrs, i, *dxc);
+<a name="l00268"></a>00268         <span class="keywordflow">if</span> (*dxc > *xc) {
+<a name="l00269"></a>00269             <span class="comment">/* Found a better solution */</span>
+<a name="l00270"></a>00270             *xc = *dxc;
+<a name="l00271"></a>00271             IRPLIB_PTR_SWAP(poly_sol, poly_candi);
+<a name="l00272"></a>00272         }
+<a name="l00273"></a>00273     }
+<a name="l00274"></a>00274 
+<a name="l00275"></a>00275     cpl_vector_delete(model);
+<a name="l00276"></a>00276     cpl_vector_delete(vxc);
+<a name="l00277"></a>00277     cpl_vector_delete(conv_kernel);
+<a name="l00278"></a>00278     cpl_vector_delete(pts_wl);
+<a name="l00279"></a>00279     cpl_matrix_delete(init_pts_x);
+<a name="l00280"></a>00280     cpl_vector_delete(init_pts_wl);
+<a name="l00281"></a>00281     cpl_polynomial_delete(poly_candi);
+<a name="l00282"></a>00282 
+<a name="l00283"></a>00283 <span class="preprocessor">#ifdef CPL_WLCALIB_FAIL_ON_CONSTANT</span>
+<a name="l00284"></a>00284 <span class="preprocessor"></span>    <span class="comment">/* FIXME: */</span>
+<a name="l00285"></a>00285     <span class="keywordflow">if</span> (cpl_polynomial_get_degree(poly_sol) == 0) {
+<a name="l00286"></a>00286         cpl_polynomial_delete(poly_sol);
+<a name="l00287"></a>00287         cpl_vector_delete(vxcorrs);
+<a name="l00288"></a>00288         *xc = 0.0;
+<a name="l00289"></a>00289         cpl_error_set_message_macro(cpl_func, CPL_ERROR_ILLEGAL_OUTPUT,
+<a name="l00290"></a>00290                                     __FILE__, __LINE__, <span class="stringliteral">"Found a constant "</span>
+<a name="l00291"></a>00291                                     <span class="stringliteral">"dispersion"</span>);
+<a name="l00292"></a>00292             cpl_errorstate_dump(prestate, CPL_FALSE, NULL);
+<a name="l00293"></a>00293         <span class="keywordflow">return</span> NULL;
+<a name="l00294"></a>00294     }
+<a name="l00295"></a>00295 <span class="preprocessor">#endif</span>
+<a name="l00296"></a>00296 <span class="preprocessor"></span>    
+<a name="l00297"></a>00297     <span class="keywordflow">if</span> (wlres != NULL) {
+<a name="l00298"></a>00298         <span class="comment">/* FIXME: A failure in the table creation is not considered a failure</span>
+<a name="l00299"></a>00299 <span class="comment">           of the whole function call (although all outputs may be useless) */</span>
+<a name="l00300"></a>00300 
+<a name="l00301"></a>00301         cpl_errorstate prestate = cpl_errorstate_get();
+<a name="l00302"></a>00302         <span class="comment">/* Create the spc_table  */</span>
+<a name="l00303"></a>00303         *wlres = irplib_wlxcorr_gen_spc_table(spectrum, lines_catalog, slitw,
+<a name="l00304"></a>00304                                               fwhm, guess_poly, poly_sol);
+<a name="l00305"></a>00305         <span class="keywordflow">if</span> (*wlres == NULL) {
+<a name="l00306"></a>00306             cpl_polynomial_delete(poly_sol);
+<a name="l00307"></a>00307             cpl_vector_delete(vxcorrs);
+<a name="l00308"></a>00308             *xc = -1.0;
+<a name="l00309"></a>00309             cpl_error_set_message_macro(cpl_func, CPL_ERROR_ILLEGAL_OUTPUT,
+<a name="l00310"></a>00310                                         __FILE__, __LINE__, <span class="stringliteral">"Cannot generate "</span>
+<a name="l00311"></a>00311                                         <span class="stringliteral">"infos table"</span>);
+<a name="l00312"></a>00312             <span class="comment">/* cpl_errorstate_dump(prestate, CPL_FALSE, NULL); */</span>
+<a name="l00313"></a>00313             cpl_errorstate_set(prestate);
+<a name="l00314"></a>00314             <span class="keywordflow">return</span> NULL;
+<a name="l00315"></a>00315         }
+<a name="l00316"></a>00316     } 
+<a name="l00317"></a>00317     
+<a name="l00318"></a>00318     <span class="keywordflow">if</span> (xcorrs != NULL) {
+<a name="l00319"></a>00319         *xcorrs = vxcorrs;
+<a name="l00320"></a>00320     } <span class="keywordflow">else</span> {
+<a name="l00321"></a>00321         <span class="comment">/* assert(vxcorrs == NULL); */</span>
+<a name="l00322"></a>00322     }
+<a name="l00323"></a>00323 
+<a name="l00324"></a>00324     <span class="keywordflow">return</span> poly_sol;
+<a name="l00325"></a>00325 }
+<a name="l00326"></a>00326 
+<a name="l00327"></a>00327 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00345"></a>00345 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00346"></a>00346 cpl_table * irplib_wlxcorr_gen_spc_table(
+<a name="l00347"></a>00347         <span class="keyword">const</span> cpl_vector        *   spectrum,
+<a name="l00348"></a>00348         <span class="keyword">const</span> cpl_bivector      *   lines_catalog,
+<a name="l00349"></a>00349         <span class="keywordtype">double</span>                      slitw,
+<a name="l00350"></a>00350         <span class="keywordtype">double</span>                      fwhm,
+<a name="l00351"></a>00351         <span class="keyword">const</span> cpl_polynomial    *   guess_poly,
+<a name="l00352"></a>00352         <span class="keyword">const</span> cpl_polynomial    *   corr_poly)
+<a name="l00353"></a>00353 {
+<a name="l00354"></a>00354 
+<a name="l00355"></a>00355     cpl_vector      *   conv_kernel = NULL;
+<a name="l00356"></a>00356     cpl_bivector    *   gen_init ;
+<a name="l00357"></a>00357     cpl_bivector    *   gen_corr ;
+<a name="l00358"></a>00358     cpl_table       *   spc_table ;
+<a name="l00359"></a>00359     <span class="keyword">const</span> <span class="keywordtype">double</span>    *   pgen ;
+<a name="l00360"></a>00360     <span class="keyword">const</span> <span class="keywordtype">double</span>        xtrunc = 0.5 * slitw + 5.0 * fwhm * CPL_MATH_SIG_FWHM;
+<a name="l00361"></a>00361     <span class="keyword">const</span> <span class="keywordtype">int</span>           spec_sz = cpl_vector_get_size(spectrum);
+<a name="l00362"></a>00362     <span class="keyword">const</span> cpl_boolean   guess_resamp
+<a name="l00363"></a>00363         = !irplib_wlcalib_is_lines(cpl_bivector_get_x_const(lines_catalog),
+<a name="l00364"></a>00364                                 guess_poly, spec_sz, 1.0);
+<a name="l00365"></a>00365     <span class="keyword">const</span> cpl_boolean   corr_resamp
+<a name="l00366"></a>00366         = !irplib_wlcalib_is_lines(cpl_bivector_get_x_const(lines_catalog),
+<a name="l00367"></a>00367                                 corr_poly, spec_sz, 1.0);
+<a name="l00368"></a>00368     cpl_error_code      error;
+<a name="l00369"></a>00369 
+<a name="l00370"></a>00370     cpl_msg_debug(cpl_func, <span class="stringliteral">"Tabel for guess dispersion polynomial (slitw=%g, "</span>
+<a name="l00371"></a>00371                   <span class="stringliteral">"fwhm=%g) with %d-point observed spectrum with%s catalog re"</span>
+<a name="l00372"></a>00372                   <span class="stringliteral">"sampling"</span>, slitw, fwhm, spec_sz, guess_resamp ? <span class="stringliteral">"out"</span> : <span class="stringliteral">""</span>);
+<a name="l00373"></a>00373     cpl_msg_debug(cpl_func, <span class="stringliteral">"Tabel for corr. dispersion polynomial (slitw=%g, "</span>
+<a name="l00374"></a>00374                   <span class="stringliteral">"fwhm=%g) with %d-point observed spectrum with%s catalog re"</span>
+<a name="l00375"></a>00375                   <span class="stringliteral">"sampling"</span>, slitw, fwhm, spec_sz, corr_resamp ? <span class="stringliteral">"out"</span> : <span class="stringliteral">""</span>);
+<a name="l00376"></a>00376 
+<a name="l00377"></a>00377     <span class="comment">/* Test inputs */</span>
+<a name="l00378"></a>00378     cpl_ensure(spectrum, CPL_ERROR_NULL_INPUT, NULL) ;
+<a name="l00379"></a>00379     cpl_ensure(lines_catalog, CPL_ERROR_NULL_INPUT, NULL) ;
+<a name="l00380"></a>00380     cpl_ensure(guess_poly, CPL_ERROR_NULL_INPUT, NULL) ;
+<a name="l00381"></a>00381     cpl_ensure(corr_poly, CPL_ERROR_NULL_INPUT, NULL) ;
+<a name="l00382"></a>00382 
+<a name="l00383"></a>00383     <span class="comment">/* Create the convolution kernel */</span>
+<a name="l00384"></a>00384     <span class="keywordflow">if</span> (guess_resamp || corr_resamp) {
+<a name="l00385"></a>00385         conv_kernel = irplib_wlxcorr_convolve_create_kernel(slitw, fwhm);
+<a name="l00386"></a>00386 
+<a name="l00387"></a>00387         <span class="keywordflow">if</span> (conv_kernel == NULL) {
+<a name="l00388"></a>00388             cpl_error_set_message_macro(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
+<a name="l00389"></a>00389                                         __FILE__, __LINE__, <span class="stringliteral">"Cannot create "</span>
+<a name="l00390"></a>00390                                         <span class="stringliteral">"convolution kernel"</span>) ;
+<a name="l00391"></a>00391             <span class="keywordflow">return</span> NULL ;
+<a name="l00392"></a>00392         }
+<a name="l00393"></a>00393     }
+<a name="l00394"></a>00394 
+<a name="l00395"></a>00395     <span class="comment">/* Get the emission at initial wavelengths */</span>
+<a name="l00396"></a>00396     gen_init = cpl_bivector_new(spec_sz);
+<a name="l00397"></a>00397     <span class="keywordflow">if</span> (guess_resamp) {
+<a name="l00398"></a>00398         error = irplib_wlcalib_fill_spectrum(cpl_bivector_get_y(gen_init),
+<a name="l00399"></a>00399                                           lines_catalog, conv_kernel,
+<a name="l00400"></a>00400                                           guess_poly, 0);
+<a name="l00401"></a>00401     } <span class="keywordflow">else</span> {
+<a name="l00402"></a>00402         error = <a class="code" href="group__irplib__wavecal.html#ga0db5e24244f88b41627d5a385af81b33" title="Generate a 1D spectrum from (arc) lines and a dispersion relation.">irplib_vector_fill_line_spectrum_model</a>
+<a name="l00403"></a>00403             (cpl_bivector_get_y(gen_init), NULL, NULL,
+<a name="l00404"></a>00404              guess_poly, lines_catalog,
+<a name="l00405"></a>00405              slitw, fwhm, xtrunc, 0, CPL_FALSE, CPL_FALSE, NULL);
+<a name="l00406"></a>00406     }
+<a name="l00407"></a>00407 
+<a name="l00408"></a>00408     <span class="keywordflow">if</span> (error || cpl_vector_fill_polynomial(cpl_bivector_get_x(gen_init),
+<a name="l00409"></a>00409                                             guess_poly, 1, 1)) {
+<a name="l00410"></a>00410         cpl_vector_delete(conv_kernel);
+<a name="l00411"></a>00411         cpl_bivector_delete(gen_init);
+<a name="l00412"></a>00412         cpl_error_set_message_macro(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
+<a name="l00413"></a>00413                                     __FILE__, __LINE__, <span class="stringliteral">"Cannot get the "</span>
+<a name="l00414"></a>00414                                     <span class="stringliteral">"emission spectrum"</span>);
+<a name="l00415"></a>00415         <span class="keywordflow">return</span> NULL;
+<a name="l00416"></a>00416     }
+<a name="l00417"></a>00417  
+<a name="l00418"></a>00418     <span class="comment">/* Get the emission at corrected wavelengths */</span>
+<a name="l00419"></a>00419     gen_corr = cpl_bivector_new(spec_sz);
+<a name="l00420"></a>00420     <span class="keywordflow">if</span> (corr_resamp) {
+<a name="l00421"></a>00421         error = irplib_wlcalib_fill_spectrum(cpl_bivector_get_y(gen_corr),
+<a name="l00422"></a>00422                                           lines_catalog, conv_kernel,
+<a name="l00423"></a>00423                                           corr_poly, 0);
+<a name="l00424"></a>00424     } <span class="keywordflow">else</span> {
+<a name="l00425"></a>00425         error = <a class="code" href="group__irplib__wavecal.html#ga0db5e24244f88b41627d5a385af81b33" title="Generate a 1D spectrum from (arc) lines and a dispersion relation.">irplib_vector_fill_line_spectrum_model</a>
+<a name="l00426"></a>00426             (cpl_bivector_get_y(gen_corr), NULL, NULL,
+<a name="l00427"></a>00427              corr_poly, lines_catalog,
+<a name="l00428"></a>00428              slitw, fwhm, xtrunc, 0, CPL_FALSE, CPL_FALSE, NULL);
+<a name="l00429"></a>00429     }
+<a name="l00430"></a>00430 
+<a name="l00431"></a>00431     <span class="keywordflow">if</span> (error || cpl_vector_fill_polynomial(cpl_bivector_get_x(gen_corr),
+<a name="l00432"></a>00432                                             corr_poly, 1, 1)) {
+<a name="l00433"></a>00433         cpl_vector_delete(conv_kernel);
+<a name="l00434"></a>00434         cpl_bivector_delete(gen_init);
+<a name="l00435"></a>00435         cpl_bivector_delete(gen_corr) ;
+<a name="l00436"></a>00436         cpl_error_set_message_macro(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
+<a name="l00437"></a>00437                                     __FILE__, __LINE__, <span class="stringliteral">"Cannot get the "</span>
+<a name="l00438"></a>00438                                     <span class="stringliteral">"emission spectrum"</span>);
+<a name="l00439"></a>00439         <span class="keywordflow">return</span> NULL;
+<a name="l00440"></a>00440     }
+<a name="l00441"></a>00441     cpl_vector_delete(conv_kernel) ;
+<a name="l00442"></a>00442 
+<a name="l00443"></a>00443     <span class="comment">/* Create the ouput table */</span>
+<a name="l00444"></a>00444     spc_table = cpl_table_new(spec_sz);
+<a name="l00445"></a>00445     cpl_table_new_column(spc_table, IRPLIB_WLXCORR_COL_WAVELENGTH, 
+<a name="l00446"></a>00446             CPL_TYPE_DOUBLE);
+<a name="l00447"></a>00447     cpl_table_new_column(spc_table, IRPLIB_WLXCORR_COL_CAT_INIT, 
+<a name="l00448"></a>00448             CPL_TYPE_DOUBLE);
+<a name="l00449"></a>00449     cpl_table_new_column(spc_table, IRPLIB_WLXCORR_COL_CAT_FINAL, 
+<a name="l00450"></a>00450             CPL_TYPE_DOUBLE);
+<a name="l00451"></a>00451     cpl_table_new_column(spc_table, IRPLIB_WLXCORR_COL_OBS, CPL_TYPE_DOUBLE);
+<a name="l00452"></a>00452     
+<a name="l00453"></a>00453     <span class="comment">/* Update table */</span>
+<a name="l00454"></a>00454     pgen = cpl_bivector_get_x_data_const(gen_corr) ;
+<a name="l00455"></a>00455     cpl_table_copy_data_double(spc_table, IRPLIB_WLXCORR_COL_WAVELENGTH, pgen) ;
+<a name="l00456"></a>00456     pgen = cpl_bivector_get_y_data_const(gen_corr) ;
+<a name="l00457"></a>00457     cpl_table_copy_data_double(spc_table, IRPLIB_WLXCORR_COL_CAT_FINAL, pgen) ;
+<a name="l00458"></a>00458     pgen = cpl_vector_get_data_const(spectrum) ;
+<a name="l00459"></a>00459     cpl_table_copy_data_double(spc_table, IRPLIB_WLXCORR_COL_OBS, pgen) ;
+<a name="l00460"></a>00460     pgen = cpl_bivector_get_y_data_const(gen_init) ;
+<a name="l00461"></a>00461     cpl_table_copy_data_double(spc_table, IRPLIB_WLXCORR_COL_CAT_INIT, pgen);
+<a name="l00462"></a>00462     cpl_bivector_delete(gen_init);
+<a name="l00463"></a>00463     cpl_bivector_delete(gen_corr);
+<a name="l00464"></a>00464 
+<a name="l00465"></a>00465     <span class="keywordflow">return</span> spc_table ;
+<a name="l00466"></a>00466 }
+<a name="l00467"></a>00467 
+<a name="l00468"></a>00468 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00480"></a>00480 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00481"></a>00481 cpl_bivector * irplib_wlxcorr_cat_extract(
+<a name="l00482"></a>00482         <span class="keyword">const</span> cpl_bivector  *   lines_catalog,
+<a name="l00483"></a>00483         <span class="keywordtype">double</span>                  wave_min,
+<a name="l00484"></a>00484         <span class="keywordtype">double</span>                  wave_max)
+<a name="l00485"></a>00485 {
+<a name="l00486"></a>00486     <span class="keyword">const</span> <span class="keywordtype">int</span>           nlines = cpl_bivector_get_size(lines_catalog);
+<a name="l00487"></a>00487     <span class="keywordtype">int</span>                 wave_min_id, wave_max_id ;
+<a name="l00488"></a>00488     cpl_vector       *  sub_cat_wl ;
+<a name="l00489"></a>00489     cpl_vector       *  sub_cat_int ;
+<a name="l00490"></a>00490     <span class="keyword">const</span> cpl_vector *  xlines  = cpl_bivector_get_x_const(lines_catalog);
+<a name="l00491"></a>00491     <span class="keyword">const</span> <span class="keywordtype">double</span>     *  dxlines = cpl_vector_get_data_const(xlines);
+<a name="l00492"></a>00492 
+<a name="l00493"></a>00493     cpl_ensure(lines_catalog != NULL, CPL_ERROR_NULL_INPUT,    NULL);
+<a name="l00494"></a>00494 
+<a name="l00495"></a>00495     <span class="comment">/* Find the 1st line */</span>
+<a name="l00496"></a>00496     wave_min_id = cpl_vector_find(xlines, wave_min);
+<a name="l00497"></a>00497     <span class="comment">/* The first line must be greater than (at least?) wave_min */</span>
+<a name="l00498"></a>00498     <span class="keywordflow">if</span> (dxlines[wave_min_id] <= wave_min) wave_min_id++;
+<a name="l00499"></a>00499 
+<a name="l00500"></a>00500     <span class="comment">/* Find the last line */</span>
+<a name="l00501"></a>00501     wave_max_id = cpl_vector_find(xlines, wave_max);
+<a name="l00502"></a>00502     <span class="comment">/* The last line must be less than wave_max */</span>
+<a name="l00503"></a>00503     <span class="keywordflow">if</span> (dxlines[wave_max_id] >= wave_min) wave_max_id--;
+<a name="l00504"></a>00504 
+<a name="l00505"></a>00505     <span class="comment">/* Checking the wavelength range at this point via the indices also</span>
+<a name="l00506"></a>00506 <span class="comment">       verifies that they were not found using non-increasing wavelengths */</span>
+<a name="l00507"></a>00507     cpl_ensure(wave_min_id <= wave_max_id, CPL_ERROR_ILLEGAL_INPUT, NULL);
+<a name="l00508"></a>00508 
+<a name="l00509"></a>00509     <span class="keywordflow">if</span> (wave_min_id < 0 || wave_max_id == nlines) {
+<a name="l00510"></a>00510         cpl_error_set_message_macro(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
+<a name="l00511"></a>00511                                     __FILE__, __LINE__, <span class="stringliteral">"The %d-line catalogue "</span>
+<a name="l00512"></a>00512                                     <span class="stringliteral">"has no lines in the range %g -> %g"</span>,
+<a name="l00513"></a>00513                                     nlines, wave_min, wave_max);
+<a name="l00514"></a>00514         <span class="keywordflow">return</span> NULL ;
+<a name="l00515"></a>00515     }
+<a name="l00516"></a>00516 
+<a name="l00517"></a>00517     sub_cat_wl = cpl_vector_extract(xlines, wave_min_id, wave_max_id, 1);
+<a name="l00518"></a>00518     sub_cat_int = cpl_vector_extract(cpl_bivector_get_y_const(lines_catalog), 
+<a name="l00519"></a>00519                                      wave_min_id, wave_max_id, 1);
+<a name="l00520"></a>00520  
+<a name="l00521"></a>00521     <span class="keywordflow">return</span> cpl_bivector_wrap_vectors(sub_cat_wl, sub_cat_int);
+<a name="l00522"></a>00522 }
+<a name="l00523"></a>00523 
+<a name="l00524"></a>00524 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00541"></a>00541 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00542"></a>00542 cpl_vector * irplib_wlxcorr_convolve_create_kernel(<span class="keywordtype">double</span>  slitw,
+<a name="l00543"></a>00543                                                    <span class="keywordtype">double</span>  fwhm)
+<a name="l00544"></a>00544 {
+<a name="l00545"></a>00545     <span class="keyword">const</span> <span class="keywordtype">double</span>  sigma  = fwhm * CPL_MATH_SIG_FWHM;
+<a name="l00546"></a>00546     <span class="keyword">const</span> <span class="keywordtype">int</span>     size   = 1 + (int)(5.0 * sigma + 0.5*slitw);
+<a name="l00547"></a>00547     cpl_vector  * kernel = cpl_vector_new(size);
+<a name="l00548"></a>00548 
+<a name="l00549"></a>00549 
+<a name="l00550"></a>00550     <span class="keywordflow">if</span> (cpl_vector_fill_lss_profile_symmetric(kernel, slitw, fwhm)) {
+<a name="l00551"></a>00551         cpl_vector_delete(kernel);
+<a name="l00552"></a>00552         cpl_ensure(0, cpl_error_get_code(), NULL);
+<a name="l00553"></a>00553     }
+<a name="l00554"></a>00554 
+<a name="l00555"></a>00555     <span class="keywordflow">return</span> kernel;
+<a name="l00556"></a>00556 }
+<a name="l00557"></a>00557 
+<a name="l00558"></a>00558 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00571"></a>00571 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00572"></a>00572 <span class="keywordtype">int</span> irplib_wlxcorr_convolve(
+<a name="l00573"></a>00573         cpl_vector          *   smoothed,
+<a name="l00574"></a>00574         <span class="keyword">const</span> cpl_vector    *   conv_kernel)
+<a name="l00575"></a>00575 {
+<a name="l00576"></a>00576     <span class="keywordtype">int</span>             nsamples ;
+<a name="l00577"></a>00577     <span class="keywordtype">int</span>             ihwidth ;
+<a name="l00578"></a>00578     cpl_vector  *   raw ;
+<a name="l00579"></a>00579     <span class="keywordtype">double</span>      *   psmoothe ;
+<a name="l00580"></a>00580     <span class="keywordtype">double</span>      *   praw ;
+<a name="l00581"></a>00581     <span class="keyword">const</span> <span class="keywordtype">double</span>*   psymm ;
+<a name="l00582"></a>00582     <span class="keywordtype">int</span>             i, j ;
+<a name="l00583"></a>00583 
+<a name="l00584"></a>00584     <span class="comment">/* Test entries */</span>
+<a name="l00585"></a>00585     cpl_ensure(smoothed, CPL_ERROR_NULL_INPUT, -1) ;
+<a name="l00586"></a>00586     cpl_ensure(conv_kernel, CPL_ERROR_NULL_INPUT, -1) ;
+<a name="l00587"></a>00587 
+<a name="l00588"></a>00588     <span class="comment">/* Initialise */</span>
+<a name="l00589"></a>00589     nsamples = cpl_vector_get_size(smoothed) ;
+<a name="l00590"></a>00590     ihwidth = cpl_vector_get_size(conv_kernel) - 1 ;
+<a name="l00591"></a>00591     cpl_ensure(ihwidth<nsamples, CPL_ERROR_ILLEGAL_INPUT, -1) ;
+<a name="l00592"></a>00592     psymm = cpl_vector_get_data_const(conv_kernel) ;
+<a name="l00593"></a>00593     psmoothe = cpl_vector_get_data(smoothed) ;
+<a name="l00594"></a>00594     
+<a name="l00595"></a>00595     <span class="comment">/* Create raw vector */</span>
+<a name="l00596"></a>00596     raw = cpl_vector_duplicate(smoothed) ;
+<a name="l00597"></a>00597     praw = cpl_vector_get_data(raw) ;
+<a name="l00598"></a>00598 
+<a name="l00599"></a>00599     <span class="comment">/* Convolve with the symmetric function */</span>
+<a name="l00600"></a>00600     <span class="keywordflow">for</span> (i=0 ; i<ihwidth ; i++) {
+<a name="l00601"></a>00601         psmoothe[i] = praw[i] * psymm[0];
+<a name="l00602"></a>00602         <span class="keywordflow">for</span> (j=1 ; j <= ihwidth ; j++) {
+<a name="l00603"></a>00603             <span class="keyword">const</span> <span class="keywordtype">int</span> k = i-j < 0 ? 0 : i-j;
+<a name="l00604"></a>00604             psmoothe[i] += (praw[k]+praw[i+j]) * psymm[j];
+<a name="l00605"></a>00605         }
+<a name="l00606"></a>00606     }
+<a name="l00607"></a>00607 
+<a name="l00608"></a>00608     <span class="keywordflow">for</span> (i=ihwidth ; i<nsamples-ihwidth ; i++) {
+<a name="l00609"></a>00609         psmoothe[i] = praw[i] * psymm[0];
+<a name="l00610"></a>00610         <span class="keywordflow">for</span> (j=1 ; j<=ihwidth ; j++)
+<a name="l00611"></a>00611             psmoothe[i] += (praw[i-j]+praw[i+j]) * psymm[j];
+<a name="l00612"></a>00612     }
+<a name="l00613"></a>00613     <span class="keywordflow">for</span> (i=nsamples-ihwidth ; i<nsamples ; i++) {
+<a name="l00614"></a>00614         psmoothe[i] = praw[i] * psymm[0];
+<a name="l00615"></a>00615         <span class="keywordflow">for</span> (j=1 ; j<=ihwidth ; j++) {
+<a name="l00616"></a>00616             <span class="keyword">const</span> <span class="keywordtype">int</span> k = i+j > nsamples-1 ? nsamples - 1 : i+j;
+<a name="l00617"></a>00617             psmoothe[i] += (praw[k]+praw[i-j]) * psymm[j];
+<a name="l00618"></a>00618         }
+<a name="l00619"></a>00619     }
+<a name="l00620"></a>00620     cpl_vector_delete(raw) ;
+<a name="l00621"></a>00621     <span class="keywordflow">return</span> 0 ;
+<a name="l00622"></a>00622 }
+<a name="l00623"></a>00623 
+<a name="l00624"></a>00624 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00634"></a>00634 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00635"></a>00635 <span class="keywordtype">int</span> irplib_wlxcorr_plot_solution(
+<a name="l00636"></a>00636         <span class="keyword">const</span> cpl_polynomial    *   init,
+<a name="l00637"></a>00637         <span class="keyword">const</span> cpl_polynomial    *   comp,
+<a name="l00638"></a>00638         <span class="keyword">const</span> cpl_polynomial    *   sol,
+<a name="l00639"></a>00639         <span class="keywordtype">int</span>                         pix_start,
+<a name="l00640"></a>00640         <span class="keywordtype">int</span>                         pix_stop) 
+<a name="l00641"></a>00641 {
+<a name="l00642"></a>00642     <span class="keywordtype">int</span>                 nsamples, nplots ;
+<a name="l00643"></a>00643     cpl_vector      **  vectors ;
+<a name="l00644"></a>00644     cpl_bivector    *   bivector ;
+<a name="l00645"></a>00645     <span class="keywordtype">double</span>              diff ;
+<a name="l00646"></a>00646     <span class="keywordtype">int</span>                 i ;
+<a name="l00647"></a>00647     
+<a name="l00648"></a>00648     <span class="comment">/* Test entries */</span>
+<a name="l00649"></a>00649     <span class="keywordflow">if</span> (init == NULL || comp == NULL) <span class="keywordflow">return</span> -1 ;
+<a name="l00650"></a>00650     
+<a name="l00651"></a>00651     <span class="comment">/* Initialise */</span>
+<a name="l00652"></a>00652     nsamples = pix_stop - pix_start + 1 ;
+<a name="l00653"></a>00653     <span class="keywordflow">if</span> (sol != NULL)    nplots = 3 ;
+<a name="l00654"></a>00654     <span class="keywordflow">else</span>                nplots = 2 ;
+<a name="l00655"></a>00655     
+<a name="l00656"></a>00656     <span class="comment">/* Create vectors */</span>
+<a name="l00657"></a>00657     vectors = cpl_malloc((nplots+1)*<span class="keyword">sizeof</span>(cpl_vector*)) ;
+<a name="l00658"></a>00658     <span class="keywordflow">for</span> (i=0 ; i<nplots+1 ; i++) vectors[i] = cpl_vector_new(nsamples) ;
+<a name="l00659"></a>00659 
+<a name="l00660"></a>00660     <span class="comment">/* First plot with the lambda/pixel relation */</span>
+<a name="l00661"></a>00661     <span class="comment">/* Fill vectors */</span>
+<a name="l00662"></a>00662     <span class="keywordflow">for</span> (i=0 ; i<nsamples ; i++) {
+<a name="l00663"></a>00663         cpl_vector_set(vectors[0], i, pix_start+i) ;
+<a name="l00664"></a>00664         cpl_vector_set(vectors[1], i, 
+<a name="l00665"></a>00665                 cpl_polynomial_eval_1d(init, (<span class="keywordtype">double</span>)(pix_start+i), NULL)) ;
+<a name="l00666"></a>00666         cpl_vector_set(vectors[2], i, 
+<a name="l00667"></a>00667                 cpl_polynomial_eval_1d(comp, (<span class="keywordtype">double</span>)(pix_start+i), NULL)) ;
+<a name="l00668"></a>00668         <span class="keywordflow">if</span> (sol != NULL) 
+<a name="l00669"></a>00669             cpl_vector_set(vectors[3], i, 
+<a name="l00670"></a>00670                     cpl_polynomial_eval_1d(sol, (<span class="keywordtype">double</span>)(pix_start+i), NULL)) ;
+<a name="l00671"></a>00671     }
+<a name="l00672"></a>00672 
+<a name="l00673"></a>00673     <span class="comment">/* Plot */</span>
+<a name="l00674"></a>00674     cpl_plot_vectors(<span class="stringliteral">"set grid;set xlabel 'Position (pixels)';"</span>, 
+<a name="l00675"></a>00675         <span class="stringliteral">"t '1-Initial / 2-Computed / 3-Solution' w lines"</span>, 
+<a name="l00676"></a>00676         <span class="stringliteral">""</span>, (<span class="keyword">const</span> cpl_vector **)vectors, nplots+1);
+<a name="l00677"></a>00677 
+<a name="l00678"></a>00678     <span class="comment">/* Free vectors */</span>
+<a name="l00679"></a>00679     <span class="keywordflow">for</span> (i=0 ; i<nplots+1 ; i++) cpl_vector_delete(vectors[i]) ;
+<a name="l00680"></a>00680     cpl_free(vectors) ;
+<a name="l00681"></a>00681 
+<a name="l00682"></a>00682     <span class="comment">/* Allocate vectors */</span>
+<a name="l00683"></a>00683     nplots -- ;
+<a name="l00684"></a>00684     vectors = cpl_malloc((nplots+1)*<span class="keyword">sizeof</span>(cpl_vector*)) ;
+<a name="l00685"></a>00685     <span class="keywordflow">for</span> (i=0 ; i<nplots+1 ; i++) vectors[i] = cpl_vector_new(nsamples) ;
+<a name="l00686"></a>00686     
+<a name="l00687"></a>00687     <span class="comment">/* Second plot with the delta-lambda/pixel relation */</span>
+<a name="l00688"></a>00688     <span class="comment">/* Fill vectors */</span>
+<a name="l00689"></a>00689     <span class="keywordflow">for</span> (i=0 ; i<nsamples ; i++) {
+<a name="l00690"></a>00690         cpl_vector_set(vectors[0], i, pix_start+i) ;
+<a name="l00691"></a>00691         diff = cpl_polynomial_eval_1d(comp, (<span class="keywordtype">double</span>)(pix_start+i), NULL) -
+<a name="l00692"></a>00692             cpl_polynomial_eval_1d(init, (<span class="keywordtype">double</span>)(pix_start+i), NULL) ;
+<a name="l00693"></a>00693         cpl_vector_set(vectors[1], i, diff) ;
+<a name="l00694"></a>00694         <span class="keywordflow">if</span> (sol != NULL) {
+<a name="l00695"></a>00695             diff = cpl_polynomial_eval_1d(sol, (<span class="keywordtype">double</span>)(pix_start+i), NULL) -
+<a name="l00696"></a>00696                 cpl_polynomial_eval_1d(init, (<span class="keywordtype">double</span>)(pix_start+i), NULL) ;
+<a name="l00697"></a>00697             cpl_vector_set(vectors[2], i, diff) ;
+<a name="l00698"></a>00698         }
+<a name="l00699"></a>00699     }
+<a name="l00700"></a>00700 
+<a name="l00701"></a>00701     <span class="comment">/* Plot */</span>
+<a name="l00702"></a>00702     <span class="keywordflow">if</span> (sol == NULL) {
+<a name="l00703"></a>00703         bivector = cpl_bivector_wrap_vectors(vectors[0], vectors[1]) ;
+<a name="l00704"></a>00704         cpl_plot_bivector(
+<a name="l00705"></a>00705 <span class="stringliteral">"set grid;set xlabel 'Position (pixels)';set ylabel 'Wavelength difference';"</span>, 
+<a name="l00706"></a>00706             <span class="stringliteral">"t 'Computed-Initial wavelenth' w lines"</span>, <span class="stringliteral">""</span>, bivector);
+<a name="l00707"></a>00707         cpl_bivector_unwrap_vectors(bivector) ;
+<a name="l00708"></a>00708     } <span class="keywordflow">else</span> {
+<a name="l00709"></a>00709         cpl_plot_vectors(<span class="stringliteral">"set grid;set xlabel 'Position (pixels)';"</span>, 
+<a name="l00710"></a>00710             <span class="stringliteral">"t '1-Computed - Initial / 2--Solution - Initial' w lines"</span>, 
+<a name="l00711"></a>00711             <span class="stringliteral">""</span>, (<span class="keyword">const</span> cpl_vector **)vectors, nplots+1);
+<a name="l00712"></a>00712     }
+<a name="l00713"></a>00713     
+<a name="l00714"></a>00714     <span class="comment">/* Free vectors */</span>
+<a name="l00715"></a>00715     <span class="keywordflow">for</span> (i=0 ; i<nplots+1 ; i++) cpl_vector_delete(vectors[i]) ;
+<a name="l00716"></a>00716     cpl_free(vectors) ;
+<a name="l00717"></a>00717 
+<a name="l00718"></a>00718     <span class="comment">/* Return */</span>
+<a name="l00719"></a>00719     <span class="keywordflow">return</span> 0 ;
+<a name="l00720"></a>00720 }
+<a name="l00721"></a>00721 
+<a name="l00722"></a>00722 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00729"></a>00729 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00730"></a>00730 <span class="keywordtype">int</span> irplib_wlxcorr_plot_spc_table(
+<a name="l00731"></a>00731         <span class="keyword">const</span> cpl_table     *   spc_table, 
+<a name="l00732"></a>00732         <span class="keyword">const</span> <span class="keywordtype">char</span>          *   title) 
+<a name="l00733"></a>00733 {
+<a name="l00734"></a>00734     <span class="keywordtype">char</span>                title_loc[1024] ;
+<a name="l00735"></a>00735     cpl_vector      **  vectors ;
+<a name="l00736"></a>00736     cpl_vector      **  sub_vectors ;
+<a name="l00737"></a>00737     cpl_vector      *   tmp_vec ;
+<a name="l00738"></a>00738     <span class="keywordtype">int</span>                 nsamples ;
+<a name="l00739"></a>00739     <span class="keywordtype">double</span>              max, mean1, mean3 ;
+<a name="l00740"></a>00740     <span class="keywordtype">int</span>                 start_ind, stop_ind, nblines, hsize_pix ;
+<a name="l00741"></a>00741     <span class="keywordtype">int</span>                 i, j ;
+<a name="l00742"></a>00742 
+<a name="l00743"></a>00743     <span class="comment">/* Test entries */</span>
+<a name="l00744"></a>00744     <span class="keywordflow">if</span> (spc_table == NULL) <span class="keywordflow">return</span> -1 ;
+<a name="l00745"></a>00745     
+<a name="l00746"></a>00746     <span class="comment">/* Initialise */</span>
+<a name="l00747"></a>00747     nsamples = cpl_table_get_nrow(spc_table) ;
+<a name="l00748"></a>00748     hsize_pix = 10 ;
+<a name="l00749"></a>00749     nblines = 0 ;
+<a name="l00750"></a>00750     sprintf(title_loc, 
+<a name="l00751"></a>00751         <span class="stringliteral">"t '%s - 1-Initial catalog/2-Corrected catalog/3-Observed' w lines"</span>,
+<a name="l00752"></a>00752         title) ;
+<a name="l00753"></a>00753     title_loc[1023] = (char)0 ;
+<a name="l00754"></a>00754     
+<a name="l00755"></a>00755     vectors = cpl_malloc(4*<span class="keyword">sizeof</span>(cpl_vector*)) ;
+<a name="l00756"></a>00756     vectors[0] = cpl_vector_wrap(nsamples, 
+<a name="l00757"></a>00757             cpl_table_get_data_double((cpl_table*)spc_table,
+<a name="l00758"></a>00758                 IRPLIB_WLXCORR_COL_WAVELENGTH));
+<a name="l00759"></a>00759     vectors[1] = cpl_vector_wrap(nsamples, 
+<a name="l00760"></a>00760             cpl_table_get_data_double((cpl_table*)spc_table, 
+<a name="l00761"></a>00761                 IRPLIB_WLXCORR_COL_CAT_INIT));
+<a name="l00762"></a>00762     vectors[2] = cpl_vector_wrap(nsamples, 
+<a name="l00763"></a>00763             cpl_table_get_data_double((cpl_table*)spc_table, 
+<a name="l00764"></a>00764                 IRPLIB_WLXCORR_COL_CAT_FINAL));
+<a name="l00765"></a>00765     vectors[3] = cpl_vector_wrap(nsamples, 
+<a name="l00766"></a>00766             cpl_table_get_data_double((cpl_table*)spc_table, 
+<a name="l00767"></a>00767                 IRPLIB_WLXCORR_COL_OBS)) ;
+<a name="l00768"></a>00768 
+<a name="l00769"></a>00769     <span class="comment">/* Scale the signal for a bettre display */</span>
+<a name="l00770"></a>00770     mean1 = cpl_vector_get_mean(vectors[1]) ;
+<a name="l00771"></a>00771     mean3 = cpl_vector_get_mean(vectors[3]) ;
+<a name="l00772"></a>00772     <span class="keywordflow">if</span> (fabs(mean3) > 1)
+<a name="l00773"></a>00773         cpl_vector_multiply_scalar(vectors[3], fabs(mean1/mean3)) ;
+<a name="l00774"></a>00774 
+<a name="l00775"></a>00775     cpl_plot_vectors(<span class="stringliteral">"set grid;set xlabel 'Wavelength (nm)';"</span>, title_loc,
+<a name="l00776"></a>00776         <span class="stringliteral">""</span>, (<span class="keyword">const</span> cpl_vector **)vectors, 4);
+<a name="l00777"></a>00777 
+<a name="l00778"></a>00778     <span class="comment">/* Unscale the signal */</span>
+<a name="l00779"></a>00779     <span class="keywordflow">if</span> (fabs(mean3) > 1)
+<a name="l00780"></a>00780         cpl_vector_multiply_scalar(vectors[3], mean3/mean1) ;
+<a name="l00781"></a>00781 
+<a name="l00782"></a>00782     <span class="comment">/* Loop on the brightest lines and zoom on them */</span>
+<a name="l00783"></a>00783     sprintf(title_loc, 
+<a name="l00784"></a>00784 <span class="stringliteral">"t '%s - 1-Initial catalog/2-Corrected catalog/3-Observed (ZOOMED)' w lines"</span>,
+<a name="l00785"></a>00785         title) ;
+<a name="l00786"></a>00786     title_loc[1023] = (char)0 ;
+<a name="l00787"></a>00787     tmp_vec = cpl_vector_duplicate(vectors[2]) ;
+<a name="l00788"></a>00788     <span class="keywordflow">for</span> (i=0 ; i<nblines ; i++) {
+<a name="l00789"></a>00789         <span class="comment">/* Find the brightest line */</span>
+<a name="l00790"></a>00790         <span class="keywordflow">if</span> ((max = cpl_vector_get_max(tmp_vec)) <= 0.0) break ;
+<a name="l00791"></a>00791         <span class="keywordflow">for</span> (j=0 ; i<nsamples ; j++) {
+<a name="l00792"></a>00792             <span class="keywordflow">if</span> (cpl_vector_get(tmp_vec, j) == max) break ;
+<a name="l00793"></a>00793         }
+<a name="l00794"></a>00794         <span class="keywordflow">if</span> (j-hsize_pix < 0) start_ind = 0 ;
+<a name="l00795"></a>00795         <span class="keywordflow">else</span> start_ind = j-hsize_pix ;
+<a name="l00796"></a>00796         <span class="keywordflow">if</span> (j+hsize_pix > nsamples-1) stop_ind = nsamples-1 ;
+<a name="l00797"></a>00797         <span class="keywordflow">else</span> stop_ind = j+hsize_pix ;
+<a name="l00798"></a>00798         <span class="keywordflow">for</span> (j=start_ind ; j<=stop_ind ; j++) cpl_vector_set(tmp_vec, j, 0.0) ;
+<a name="l00799"></a>00799 
+<a name="l00800"></a>00800         sub_vectors = cpl_malloc(4*<span class="keyword">sizeof</span>(cpl_vector*)) ;
+<a name="l00801"></a>00801         sub_vectors[0]=cpl_vector_extract(vectors[0],start_ind,stop_ind,1);
+<a name="l00802"></a>00802         sub_vectors[1]=cpl_vector_extract(vectors[1],start_ind,stop_ind,1);
+<a name="l00803"></a>00803         sub_vectors[2]=cpl_vector_extract(vectors[2],start_ind,stop_ind,1);
+<a name="l00804"></a>00804         sub_vectors[3]=cpl_vector_extract(vectors[3],start_ind,stop_ind,1);
+<a name="l00805"></a>00805 
+<a name="l00806"></a>00806         cpl_plot_vectors(<span class="stringliteral">"set grid;set xlabel 'Wavelength (nm)';"</span>, title_loc,
+<a name="l00807"></a>00807             <span class="stringliteral">""</span>, (<span class="keyword">const</span> cpl_vector **)sub_vectors, 4);
+<a name="l00808"></a>00808 
+<a name="l00809"></a>00809         cpl_vector_delete(sub_vectors[0]) ;
+<a name="l00810"></a>00810         cpl_vector_delete(sub_vectors[1]) ;
+<a name="l00811"></a>00811         cpl_vector_delete(sub_vectors[2]) ;
+<a name="l00812"></a>00812         cpl_vector_delete(sub_vectors[3]) ;
+<a name="l00813"></a>00813         cpl_free(sub_vectors) ;
+<a name="l00814"></a>00814     }
+<a name="l00815"></a>00815     cpl_vector_delete(tmp_vec) ;
+<a name="l00816"></a>00816     
+<a name="l00817"></a>00817     cpl_vector_unwrap(vectors[0]) ;
+<a name="l00818"></a>00818     cpl_vector_unwrap(vectors[1]) ;
+<a name="l00819"></a>00819     cpl_vector_unwrap(vectors[2]) ;
+<a name="l00820"></a>00820     cpl_vector_unwrap(vectors[3]) ;
+<a name="l00821"></a>00821     cpl_free(vectors) ;
+<a name="l00822"></a>00822 
+<a name="l00823"></a>00823     <span class="keywordflow">return</span> 0 ;
+<a name="l00824"></a>00824 }
+<a name="l00825"></a>00825 
+<a name="l00826"></a>00826 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00834"></a>00834 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00835"></a>00835 <span class="keywordtype">int</span> irplib_wlxcorr_catalog_plot(
+<a name="l00836"></a>00836         <span class="keyword">const</span> cpl_bivector      *   cat,
+<a name="l00837"></a>00837         <span class="keywordtype">double</span>                      wmin,
+<a name="l00838"></a>00838         <span class="keywordtype">double</span>                      wmax) 
+<a name="l00839"></a>00839 {
+<a name="l00840"></a>00840     <span class="keywordtype">int</span>                 start, stop ;
+<a name="l00841"></a>00841     cpl_bivector    *   subcat ;
+<a name="l00842"></a>00842     cpl_vector      *   subcat_x ;
+<a name="l00843"></a>00843     cpl_vector      *   subcat_y ;
+<a name="l00844"></a>00844     <span class="keyword">const</span> <span class="keywordtype">double</span>    *   pwave ;
+<a name="l00845"></a>00845     <span class="keywordtype">int</span>                 nvals, nvals_tot ;
+<a name="l00846"></a>00846     <span class="keywordtype">int</span>                 i ;
+<a name="l00847"></a>00847 
+<a name="l00848"></a>00848     <span class="comment">/* Test entries */</span>
+<a name="l00849"></a>00849     <span class="keywordflow">if</span> (cat == NULL) <span class="keywordflow">return</span> -1 ;
+<a name="l00850"></a>00850     <span class="keywordflow">if</span> (wmax <= wmin) <span class="keywordflow">return</span> -1 ;
+<a name="l00851"></a>00851 
+<a name="l00852"></a>00852     <span class="comment">/* Initialise */</span>
+<a name="l00853"></a>00853     nvals_tot = cpl_bivector_get_size(cat) ;
+<a name="l00854"></a>00854 
+<a name="l00855"></a>00855     <span class="comment">/* Count the nb of values */</span>
+<a name="l00856"></a>00856     pwave = cpl_bivector_get_x_data_const(cat) ;
+<a name="l00857"></a>00857     <span class="keywordflow">if</span> (pwave[0] >= wmin) start = 0 ;
+<a name="l00858"></a>00858     <span class="keywordflow">else</span> start = -1 ;
+<a name="l00859"></a>00859     <span class="keywordflow">if</span> (pwave[nvals_tot-1] <= wmax) stop = nvals_tot-1 ;
+<a name="l00860"></a>00860     <span class="keywordflow">else</span> stop = -1 ;
+<a name="l00861"></a>00861     i=0 ;
+<a name="l00862"></a>00862     <span class="keywordflow">while</span> ((pwave[i] < wmin) && (i<nvals_tot-1)) i++ ;
+<a name="l00863"></a>00863     start = i ;
+<a name="l00864"></a>00864     i= nvals_tot-1 ;
+<a name="l00865"></a>00865     <span class="keywordflow">while</span> ((pwave[i] > wmax) && (i>0)) i-- ;
+<a name="l00866"></a>00866     stop = i ;
+<a name="l00867"></a>00867 
+<a name="l00868"></a>00868     <span class="keywordflow">if</span> (start>=stop) {
+<a name="l00869"></a>00869         cpl_msg_error(cpl_func, <span class="stringliteral">"Cannot plot the catalog"</span>) ;
+<a name="l00870"></a>00870         <span class="keywordflow">return</span> -1 ;
+<a name="l00871"></a>00871     }
+<a name="l00872"></a>00872     nvals = start - stop + 1 ;
+<a name="l00873"></a>00873 
+<a name="l00874"></a>00874     <span class="comment">/* Create the bivector to plot */</span>
+<a name="l00875"></a>00875     subcat_x = cpl_vector_extract(cpl_bivector_get_x_const(cat),start,stop, 1) ;
+<a name="l00876"></a>00876     subcat_y = cpl_vector_extract(cpl_bivector_get_y_const(cat),start,stop, 1) ;
+<a name="l00877"></a>00877     subcat = cpl_bivector_wrap_vectors(subcat_x, subcat_y) ;
+<a name="l00878"></a>00878 
+<a name="l00879"></a>00879     <span class="comment">/* Plot */</span>
+<a name="l00880"></a>00880     <span class="keywordflow">if</span> (nvals > 500) {
+<a name="l00881"></a>00881         cpl_plot_bivector(
+<a name="l00882"></a>00882                 <span class="stringliteral">"set grid;set xlabel 'Wavelength (nm)';set ylabel 'Emission';"</span>,
+<a name="l00883"></a>00883                 <span class="stringliteral">"t 'Catalog Spectrum' w lines"</span>, <span class="stringliteral">""</span>, subcat);
+<a name="l00884"></a>00884     } <span class="keywordflow">else</span> {
+<a name="l00885"></a>00885         cpl_plot_bivector(
+<a name="l00886"></a>00886                 <span class="stringliteral">"set grid;set xlabel 'Wavelength (nm)';set ylabel 'Emission';"</span>,
+<a name="l00887"></a>00887                 <span class="stringliteral">"t 'Catalog Spectrum' w impulses"</span>, <span class="stringliteral">""</span>, subcat);
+<a name="l00888"></a>00888     }
+<a name="l00889"></a>00889     cpl_bivector_unwrap_vectors(subcat) ;
+<a name="l00890"></a>00890     cpl_vector_delete(subcat_x) ;
+<a name="l00891"></a>00891     cpl_vector_delete(subcat_y) ;
+<a name="l00892"></a>00892 
+<a name="l00893"></a>00893     <span class="keywordflow">return</span> 0 ;
+<a name="l00894"></a>00894 }
+<a name="l00895"></a>00895    
+<a name="l00898"></a>00898 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00913"></a>00913 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00914"></a>00914 <span class="keyword">static</span> <span class="keywordtype">void</span> irplib_wlxcorr_estimate(cpl_vector           * vxc,
+<a name="l00915"></a>00915                                     cpl_vector           * model,
+<a name="l00916"></a>00916                                     <span class="keyword">const</span> cpl_vector     * spectrum,
+<a name="l00917"></a>00917                                     <span class="keyword">const</span> cpl_bivector   * lines_catalog,
+<a name="l00918"></a>00918                                     <span class="keyword">const</span> cpl_vector     * conv_kernel,
+<a name="l00919"></a>00919                                     <span class="keyword">const</span> cpl_polynomial * poly_candi,
+<a name="l00920"></a>00920                                     <span class="keywordtype">double</span>                 slitw,
+<a name="l00921"></a>00921                                     <span class="keywordtype">double</span>                 fwhm)
+<a name="l00922"></a>00922 {
+<a name="l00923"></a>00923     cpl_errorstate prestate = cpl_errorstate_get();
+<a name="l00924"></a>00924     <span class="keyword">const</span> <span class="keywordtype">int</span> hsize = cpl_vector_get_size(vxc) / 2;
+<a name="l00925"></a>00925 
+<a name="l00926"></a>00926     <span class="keywordflow">if</span> (conv_kernel != NULL) {
+<a name="l00927"></a>00927         irplib_wlcalib_fill_spectrum(model, lines_catalog, conv_kernel,
+<a name="l00928"></a>00928                                   poly_candi, hsize);
+<a name="l00929"></a>00929     } <span class="keywordflow">else</span> {
+<a name="l00930"></a>00930         <span class="keyword">const</span> <span class="keywordtype">double</span> xtrunc = 0.5 * slitw + 5.0 * fwhm * CPL_MATH_SIG_FWHM;
+<a name="l00931"></a>00931 
+<a name="l00932"></a>00932         <a class="code" href="group__irplib__wavecal.html#ga0db5e24244f88b41627d5a385af81b33" title="Generate a 1D spectrum from (arc) lines and a dispersion relation.">irplib_vector_fill_line_spectrum_model</a>(model, NULL, NULL, poly_candi,
+<a name="l00933"></a>00933                                                lines_catalog, slitw, fwhm,
+<a name="l00934"></a>00934                                                xtrunc, 0, CPL_FALSE, CPL_FALSE,
+<a name="l00935"></a>00935                                                NULL);
+<a name="l00936"></a>00936     }
+<a name="l00937"></a>00937 
+<a name="l00938"></a>00938     <span class="keywordflow">if</span> (cpl_errorstate_is_equal(prestate))
+<a name="l00939"></a>00939         cpl_vector_correlate(vxc, model, spectrum);
+<a name="l00940"></a>00940 
+<a name="l00941"></a>00941     <span class="keywordflow">if</span> (!cpl_errorstate_is_equal(prestate)) {
+<a name="l00942"></a>00942         cpl_vector_fill(vxc, 0.0);
+<a name="l00943"></a>00943 
+<a name="l00944"></a>00944         <span class="comment">/* cpl_errorstate_dump(prestate, CPL_FALSE, NULL); */</span>
+<a name="l00945"></a>00945         cpl_errorstate_set(prestate);
+<a name="l00946"></a>00946 
+<a name="l00947"></a>00947     }
+<a name="l00948"></a>00948 
+<a name="l00949"></a>00949     <span class="keywordflow">return</span>;
+<a name="l00950"></a>00950 }
+<a name="l00951"></a>00951 
+<a name="l00952"></a>00952 
+<a name="l00953"></a>00953 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00963"></a>00963 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00964"></a>00964 <span class="keyword">static</span> cpl_boolean irplib_wlcalib_is_lines(<span class="keyword">const</span> cpl_vector * wavelengths,
+<a name="l00965"></a>00965                                         <span class="keyword">const</span> cpl_polynomial * disp1d,
+<a name="l00966"></a>00966                                         <span class="keywordtype">int</span> spec_sz,
+<a name="l00967"></a>00967                                         <span class="keywordtype">double</span> tol)
+<a name="l00968"></a>00968 {
+<a name="l00969"></a>00969     <span class="keyword">const</span> <span class="keywordtype">int</span> nlines = cpl_vector_get_size(wavelengths);
+<a name="l00970"></a>00970     <span class="comment">/* The dispersion on the detector center */</span>
+<a name="l00971"></a>00971     <span class="keyword">const</span> <span class="keywordtype">double</span> dispersion = cpl_polynomial_eval_1d_diff(disp1d,
+<a name="l00972"></a>00972                                                           0.5 * spec_sz + 1.0,
+<a name="l00973"></a>00973                                                           0.5 * spec_sz,
+<a name="l00974"></a>00974                                                           NULL);
+<a name="l00975"></a>00975     <span class="keyword">const</span> <span class="keywordtype">double</span> range = cpl_vector_get(wavelengths, nlines-1)
+<a name="l00976"></a>00976         - cpl_vector_get(wavelengths, 0);
+<a name="l00977"></a>00977 
+<a name="l00978"></a>00978     cpl_ensure(wavelengths != NULL, CPL_ERROR_NULL_INPUT,    CPL_FALSE);
+<a name="l00979"></a>00979     cpl_ensure(disp1d      != NULL, CPL_ERROR_NULL_INPUT,    CPL_FALSE);
+<a name="l00980"></a>00980     cpl_ensure(cpl_polynomial_get_dimension(disp1d) == 1,
+<a name="l00981"></a>00981                CPL_ERROR_ILLEGAL_INPUT, CPL_FALSE);
+<a name="l00982"></a>00982     cpl_ensure(range > 0.0,      CPL_ERROR_ILLEGAL_INPUT, CPL_FALSE);
+<a name="l00983"></a>00983 
+<a name="l00984"></a>00984     <span class="keywordflow">return</span> nlines * fabs(dispersion) <= tol * fabs(range) ? CPL_TRUE
+<a name="l00985"></a>00985         : CPL_FALSE;
+<a name="l00986"></a>00986 
+<a name="l00987"></a>00987 }
+<a name="l00988"></a>00988 
+<a name="l00989"></a>00989 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01004"></a>01004 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01005"></a>01005 <span class="keyword">static</span>
+<a name="l01006"></a>01006 cpl_error_code irplib_wlcalib_fill_spectrum(cpl_vector           * <span class="keyword">self</span>,
+<a name="l01007"></a>01007                                          <span class="keyword">const</span> cpl_bivector   * lines_catalog,
+<a name="l01008"></a>01008                                          <span class="keyword">const</span> cpl_vector     * conv_kernel,
+<a name="l01009"></a>01009                                          <span class="keyword">const</span> cpl_polynomial * poly,
+<a name="l01010"></a>01010                                          <span class="keywordtype">int</span>                    search_hs)
+<a name="l01011"></a>01011 {
+<a name="l01012"></a>01012 
+<a name="l01013"></a>01013 
+<a name="l01014"></a>01014     <span class="keyword">const</span> <span class="keywordtype">int</span>          size = cpl_vector_get_size(<span class="keyword">self</span>);
+<a name="l01015"></a>01015     <span class="keyword">const</span> <span class="keywordtype">int</span>          nlines = cpl_bivector_get_size(lines_catalog);
+<a name="l01016"></a>01016     <span class="keyword">const</span> cpl_vector * xlines  = cpl_bivector_get_x_const(lines_catalog);
+<a name="l01017"></a>01017     <span class="keyword">const</span> <span class="keywordtype">double</span>     * dxlines = cpl_vector_get_data_const(xlines);
+<a name="l01018"></a>01018     cpl_bivector     * sub_cat ;
+<a name="l01019"></a>01019     cpl_vector       * sub_cat_x;
+<a name="l01020"></a>01020     cpl_vector       * sub_cat_y;
+<a name="l01021"></a>01021     cpl_vector       * wl_limits;
+<a name="l01022"></a>01022     <span class="keywordtype">double</span>             wave_min, wave_max;
+<a name="l01023"></a>01023     <span class="keywordtype">int</span>                wave_min_id, wave_max_id;
+<a name="l01024"></a>01024     <span class="keywordtype">int</span>                nsub;
+<a name="l01025"></a>01025     <span class="keywordtype">int</span>                error;
+<a name="l01026"></a>01026 
+<a name="l01027"></a>01027     cpl_ensure_code(<span class="keyword">self</span>          != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l01028"></a>01028     cpl_ensure_code(lines_catalog != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l01029"></a>01029     cpl_ensure_code(conv_kernel   != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l01030"></a>01030     cpl_ensure_code(poly          != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l01031"></a>01031     cpl_ensure_code(size > 0,              CPL_ERROR_ILLEGAL_INPUT);
+<a name="l01032"></a>01032 
+<a name="l01033"></a>01033 
+<a name="l01034"></a>01034     <span class="comment">/* Resample the spectrum */</span>
+<a name="l01035"></a>01035     wl_limits = cpl_vector_new(size + 1);
+<a name="l01036"></a>01036     cpl_vector_fill_polynomial(wl_limits, poly, 0.5 - search_hs, 1);
+<a name="l01037"></a>01037 
+<a name="l01038"></a>01038     <span class="comment">/* The spectrum wavelength bounds */</span>
+<a name="l01039"></a>01039     wave_min = cpl_vector_get(wl_limits, 0);
+<a name="l01040"></a>01040     wave_max = cpl_vector_get(wl_limits, size);
+<a name="l01041"></a>01041 
+<a name="l01042"></a>01042     <span class="comment">/* Find the 1st line */</span>
+<a name="l01043"></a>01043     wave_min_id = cpl_vector_find(xlines, wave_min);
+<a name="l01044"></a>01044     <span class="comment">/* The first line must be less than or equal to wave_min */</span>
+<a name="l01045"></a>01045     <span class="keywordflow">if</span> (dxlines[wave_min_id] > wave_min) wave_min_id--;
+<a name="l01046"></a>01046 
+<a name="l01047"></a>01047     <span class="keywordflow">if</span> (wave_min_id < 0) {
+<a name="l01048"></a>01048         cpl_vector_delete(wl_limits);
+<a name="l01049"></a>01049         <span class="keywordflow">return</span> cpl_error_set_message_macro(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
+<a name="l01050"></a>01050                                            __FILE__, __LINE__, <span class="stringliteral">"The %d-line "</span>
+<a name="l01051"></a>01051                                            <span class="stringliteral">"catalogue only has lines above %g"</span>,
+<a name="l01052"></a>01052                                            nlines, wave_min);
+<a name="l01053"></a>01053     }
+<a name="l01054"></a>01054 
+<a name="l01055"></a>01055     <span class="comment">/* Find the last line */</span>
+<a name="l01056"></a>01056     wave_max_id = cpl_vector_find(xlines, wave_max);
+<a name="l01057"></a>01057     <span class="comment">/* The last line must be greater than or equal to wave_max */</span>
+<a name="l01058"></a>01058     <span class="keywordflow">if</span> (dxlines[wave_max_id] < wave_max) wave_max_id++;
+<a name="l01059"></a>01059 
+<a name="l01060"></a>01060     <span class="keywordflow">if</span> (wave_max_id == nlines) {
+<a name="l01061"></a>01061         cpl_vector_delete(wl_limits);
+<a name="l01062"></a>01062         <span class="keywordflow">return</span> cpl_error_set_message_macro(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
+<a name="l01063"></a>01063                                            __FILE__, __LINE__, <span class="stringliteral">"The %d-line "</span>
+<a name="l01064"></a>01064                                            <span class="stringliteral">"catalogue only has lines below %g"</span>,
+<a name="l01065"></a>01065                                            nlines, wave_max);
+<a name="l01066"></a>01066     }
+<a name="l01067"></a>01067 
+<a name="l01068"></a>01068     <span class="comment">/* Checking the wavelength range at this point via the indices also</span>
+<a name="l01069"></a>01069 <span class="comment">       verifies that they were not found using non-increasing wavelengths */</span>
+<a name="l01070"></a>01070     nsub = 1 + wave_max_id - wave_min_id;
+<a name="l01071"></a>01071     cpl_ensure_code(nsub > 1, CPL_ERROR_ILLEGAL_INPUT);
+<a name="l01072"></a>01072 
+<a name="l01073"></a>01073     <span class="comment">/* Wrap a new bivector around the relevant part of the catalog */</span>
+<a name="l01074"></a>01074     <span class="comment">/* The data is _not_ modified */</span>
+<a name="l01075"></a>01075     sub_cat_x = cpl_vector_wrap(nsub, wave_min_id + (<span class="keywordtype">double</span>*)dxlines);
+<a name="l01076"></a>01076     sub_cat_y = cpl_vector_wrap(nsub, wave_min_id + (<span class="keywordtype">double</span>*)
+<a name="l01077"></a>01077                                 cpl_bivector_get_y_data_const(lines_catalog));
+<a name="l01078"></a>01078     sub_cat = cpl_bivector_wrap_vectors(sub_cat_x, sub_cat_y);
+<a name="l01079"></a>01079 
+<a name="l01080"></a>01080     <span class="comment">/* High resolution catalog */</span>
+<a name="l01081"></a>01081     error = irplib_wlxcorr_signal_resample(<span class="keyword">self</span>, wl_limits, sub_cat);
+<a name="l01082"></a>01082 
+<a name="l01083"></a>01083     cpl_vector_delete(wl_limits);
+<a name="l01084"></a>01084     cpl_bivector_unwrap_vectors(sub_cat);
+<a name="l01085"></a>01085     (void)cpl_vector_unwrap(sub_cat_x);
+<a name="l01086"></a>01086     (void)cpl_vector_unwrap(sub_cat_y);
+<a name="l01087"></a>01087 
+<a name="l01088"></a>01088     cpl_ensure_code(!error, CPL_ERROR_ILLEGAL_INPUT);
+<a name="l01089"></a>01089 
+<a name="l01090"></a>01090     <span class="comment">/* Smooth the instrument resolution */</span>
+<a name="l01091"></a>01091     cpl_ensure_code(!irplib_wlxcorr_convolve(<span class="keyword">self</span>, conv_kernel),
+<a name="l01092"></a>01092                     cpl_error_get_code());
+<a name="l01093"></a>01093 
+<a name="l01094"></a>01094     <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l01095"></a>01095 }
+<a name="l01096"></a>01096 
+<a name="l01097"></a>01097 
+<a name="l01098"></a>01098 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01108"></a>01108 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01109"></a>01109 <span class="keyword">static</span> <span class="keywordtype">int</span> irplib_wlxcorr_signal_resample(
+<a name="l01110"></a>01110         cpl_vector          *   resampled, 
+<a name="l01111"></a>01111         <span class="keyword">const</span> cpl_vector    *   xbounds,
+<a name="l01112"></a>01112         <span class="keyword">const</span> cpl_bivector  *   hires)
+<a name="l01113"></a>01113 {
+<a name="l01114"></a>01114     <span class="keyword">const</span> <span class="keywordtype">int</span>           hrsize = cpl_bivector_get_size(hires);
+<a name="l01115"></a>01115     <span class="keyword">const</span> cpl_vector*   xhires ;
+<a name="l01116"></a>01116     <span class="keyword">const</span> cpl_vector*   yhires ;
+<a name="l01117"></a>01117     <span class="keyword">const</span> <span class="keywordtype">double</span>    *   pxhires ;
+<a name="l01118"></a>01118     <span class="keyword">const</span> <span class="keywordtype">double</span>    *   pyhires ;
+<a name="l01119"></a>01119     <span class="keyword">const</span> <span class="keywordtype">double</span>    *   pxbounds ;
+<a name="l01120"></a>01120     cpl_vector      *   ybounds ;
+<a name="l01121"></a>01121     cpl_bivector    *   boundary ;
+<a name="l01122"></a>01122     <span class="keywordtype">double</span>          *   pybounds ;
+<a name="l01123"></a>01123     <span class="keywordtype">double</span>          *   presampled ;
+<a name="l01124"></a>01124     <span class="keywordtype">int</span>                 nsamples ;
+<a name="l01125"></a>01125     <span class="keywordtype">int</span>                 i, itt ;
+<a name="l01126"></a>01126    
+<a name="l01127"></a>01127     <span class="comment">/* Test entries */</span>
+<a name="l01128"></a>01128     <span class="keywordflow">if</span> ((!resampled) || (!xbounds) || (!hires)) <span class="keywordflow">return</span> -1 ;
+<a name="l01129"></a>01129 
+<a name="l01130"></a>01130     <span class="comment">/* Initialise */</span>
+<a name="l01131"></a>01131     nsamples = cpl_vector_get_size(resampled) ;
+<a name="l01132"></a>01132 
+<a name="l01133"></a>01133     <span class="comment">/* Initialise */</span>
+<a name="l01134"></a>01134     presampled = cpl_vector_get_data(resampled) ;
+<a name="l01135"></a>01135     pxbounds = cpl_vector_get_data_const(xbounds) ;
+<a name="l01136"></a>01136     xhires = cpl_bivector_get_x_const(hires) ;
+<a name="l01137"></a>01137     yhires = cpl_bivector_get_y_const(hires) ;
+<a name="l01138"></a>01138     pxhires = cpl_vector_get_data_const(xhires) ;
+<a name="l01139"></a>01139     pyhires = cpl_vector_get_data_const(yhires) ;
+<a name="l01140"></a>01140     
+<a name="l01141"></a>01141     <span class="comment">/* Create a new vector */</span>
+<a name="l01142"></a>01142     ybounds = cpl_vector_new(cpl_vector_get_size(xbounds)) ;
+<a name="l01143"></a>01143     boundary = cpl_bivector_wrap_vectors((cpl_vector*)xbounds,ybounds) ;
+<a name="l01144"></a>01144     pybounds = cpl_vector_get_data(ybounds) ;
+<a name="l01145"></a>01145 
+<a name="l01146"></a>01146     <span class="comment">/* Test entries */</span>
+<a name="l01147"></a>01147     <span class="keywordflow">if</span> (cpl_bivector_get_size(boundary) != nsamples + 1) {
+<a name="l01148"></a>01148         cpl_bivector_unwrap_vectors(boundary) ;
+<a name="l01149"></a>01149         cpl_vector_delete(ybounds) ;
+<a name="l01150"></a>01150         <span class="keywordflow">return</span> -1 ;
+<a name="l01151"></a>01151     }
+<a name="l01152"></a>01152 
+<a name="l01153"></a>01153     <span class="comment">/* Get the ind  */</span>
+<a name="l01154"></a>01154     itt = cpl_vector_find(xhires, pxbounds[0]);
+<a name="l01155"></a>01155 
+<a name="l01156"></a>01156     <span class="comment">/* Interpolate the signal */</span>
+<a name="l01157"></a>01157     <span class="keywordflow">if</span> (cpl_bivector_interpolate_linear(boundary, hires)) {
+<a name="l01158"></a>01158         cpl_bivector_unwrap_vectors(boundary) ;
+<a name="l01159"></a>01159         cpl_vector_delete(ybounds) ;
+<a name="l01160"></a>01160         <span class="keywordflow">return</span> -1 ;
+<a name="l01161"></a>01161     }
+<a name="l01162"></a>01162 
+<a name="l01163"></a>01163     <span class="comment">/* At this point itt most likely points to element just below</span>
+<a name="l01164"></a>01164 <span class="comment">       pxbounds[0] */</span>
+<a name="l01165"></a>01165     <span class="keywordflow">while</span> (pxhires[itt] < pxbounds[0]) itt++;
+<a name="l01166"></a>01166 
+<a name="l01167"></a>01167     <span class="keywordflow">for</span> (i=0; i < nsamples; i++) {
+<a name="l01168"></a>01168         <span class="comment">/* The i'th signal is the weighted average of the two interpolated</span>
+<a name="l01169"></a>01169 <span class="comment">           signals at the pixel boundaries and those table signals in</span>
+<a name="l01170"></a>01170 <span class="comment">           between */</span>
+<a name="l01171"></a>01171 
+<a name="l01172"></a>01172         <span class="keywordtype">double</span> xlow  = pxbounds[i];
+<a name="l01173"></a>01173         <span class="keywordtype">double</span> x     = pxhires[itt];
+<a name="l01174"></a>01174 
+<a name="l01175"></a>01175         <span class="keywordflow">if</span> (x > pxbounds[i+1]) x = pxbounds[i+1];
+<a name="l01176"></a>01176         <span class="comment">/* Contribution from interpolated value at wavelength at lower pixel</span>
+<a name="l01177"></a>01177 <span class="comment">           boundary */</span>
+<a name="l01178"></a>01178         presampled[i] = pybounds[i] * (x - xlow);
+<a name="l01179"></a>01179 
+<a name="l01180"></a>01180         <span class="comment">/* Contribution from table values in between pixel boundaries */</span>
+<a name="l01181"></a>01181         <span class="keywordflow">while</span> ((pxhires[itt] < pxbounds[i+1]) && (itt < hrsize)) {
+<a name="l01182"></a>01182             <span class="keyword">const</span> <span class="keywordtype">double</span> xprev = x;
+<a name="l01183"></a>01183             x = pxhires[itt+1];
+<a name="l01184"></a>01184             <span class="keywordflow">if</span> (x > pxbounds[i+1]) x = pxbounds[i+1];
+<a name="l01185"></a>01185             presampled[i] += pyhires[itt] * (x - xlow);
+<a name="l01186"></a>01186             xlow = xprev;
+<a name="l01187"></a>01187             itt++;
+<a name="l01188"></a>01188         }
+<a name="l01189"></a>01189 
+<a name="l01190"></a>01190         <span class="comment">/* Contribution from interpolated value at wavelength at upper pixel</span>
+<a name="l01191"></a>01191 <span class="comment">           boundary */</span>
+<a name="l01192"></a>01192         presampled[i] += pybounds[i+1] * (pxbounds[i+1] - xlow);
+<a name="l01193"></a>01193 
+<a name="l01194"></a>01194         <span class="comment">/* Compute average by dividing integral by length of pixel range</span>
+<a name="l01195"></a>01195 <span class="comment">           (the factor 2 comes from the contributions) */</span>
+<a name="l01196"></a>01196         presampled[i] /= 2 * (pxbounds[i+1] - pxbounds[i]);
+<a name="l01197"></a>01197     }
+<a name="l01198"></a>01198     cpl_bivector_unwrap_vectors(boundary) ;
+<a name="l01199"></a>01199     cpl_vector_delete(ybounds) ;
+<a name="l01200"></a>01200     <span class="keywordflow">return</span> 0 ;
+<a name="l01201"></a>01201 }
+<a name="l01202"></a>01202 
+<a name="l01203"></a>01203 
+<a name="l01204"></a>01204 
+<a name="l01205"></a>01205 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01226"></a>01226 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01227"></a>01227 <span class="keyword">static</span> cpl_error_code cpl_vector_fill_lss_profile_symmetric(cpl_vector * <span class="keyword">self</span>,
+<a name="l01228"></a>01228                                                             <span class="keywordtype">double</span>  slitw,
+<a name="l01229"></a>01229                                                             <span class="keywordtype">double</span>  fwhm)
+<a name="l01230"></a>01230 {
+<a name="l01231"></a>01231 
+<a name="l01232"></a>01232     <span class="keyword">const</span> <span class="keywordtype">double</span> sigma = fwhm * CPL_MATH_SIG_FWHM;
+<a name="l01233"></a>01233     <span class="keyword">const</span> <span class="keywordtype">int</span>    n     = cpl_vector_get_size(<span class="keyword">self</span>);
+<a name="l01234"></a>01234     <span class="keywordtype">int</span>          i;
+<a name="l01235"></a>01235 
+<a name="l01236"></a>01236 
+<a name="l01237"></a>01237     cpl_ensure_code(<span class="keyword">self</span> != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l01238"></a>01238     cpl_ensure_code(slitw > 0.0,  CPL_ERROR_ILLEGAL_INPUT);
+<a name="l01239"></a>01239     cpl_ensure_code(fwhm  > 0.0,  CPL_ERROR_ILLEGAL_INPUT);
+<a name="l01240"></a>01240 
+<a name="l01241"></a>01241     <span class="comment">/* Cannot fail now */</span>
+<a name="l01242"></a>01242 
+<a name="l01243"></a>01243     <span class="comment">/* Special case for i = 0 */</span>
+<a name="l01244"></a>01244     (void)cpl_vector_set(<span class="keyword">self</span>, 0,
+<a name="l01245"></a>01245                          (<a class="code" href="group__irplib__wavecal.html#ga2da9c21054a19322705de2d4f48d1d3f" title="The antiderivative of erx(x/sigma/sqrt(2)) with respect to x.">irplib_erf_antideriv</a>(0.5*slitw + 0.5, sigma) -
+<a name="l01246"></a>01246                           <a class="code" href="group__irplib__wavecal.html#ga2da9c21054a19322705de2d4f48d1d3f" title="The antiderivative of erx(x/sigma/sqrt(2)) with respect to x.">irplib_erf_antideriv</a>(0.5*slitw - 0.5, sigma)) / slitw);
+<a name="l01247"></a>01247 
+<a name="l01248"></a>01248     <span class="keywordflow">for</span> (i = 1; i < n; i++) {
+<a name="l01249"></a>01249         <span class="comment">/* FIXME: Reuse two irplib_erf_antideriv() calls from previous value */</span>
+<a name="l01250"></a>01250         <span class="keyword">const</span> <span class="keywordtype">double</span> x1p = i + 0.5*slitw + 0.5;
+<a name="l01251"></a>01251         <span class="keyword">const</span> <span class="keywordtype">double</span> x1n = i - 0.5*slitw + 0.5;
+<a name="l01252"></a>01252         <span class="keyword">const</span> <span class="keywordtype">double</span> x0p = i + 0.5*slitw - 0.5;
+<a name="l01253"></a>01253         <span class="keyword">const</span> <span class="keywordtype">double</span> x0n = i - 0.5*slitw - 0.5;
+<a name="l01254"></a>01254         <span class="keyword">const</span> <span class="keywordtype">double</span> val = 0.5/slitw *
+<a name="l01255"></a>01255             (<a class="code" href="group__irplib__wavecal.html#ga2da9c21054a19322705de2d4f48d1d3f" title="The antiderivative of erx(x/sigma/sqrt(2)) with respect to x.">irplib_erf_antideriv</a>(x1p, sigma) - <a class="code" href="group__irplib__wavecal.html#ga2da9c21054a19322705de2d4f48d1d3f" title="The antiderivative of erx(x/sigma/sqrt(2)) with respect to x.">irplib_erf_antideriv</a>(x1n, sigma) -
+<a name="l01256"></a>01256              <a class="code" href="group__irplib__wavecal.html#ga2da9c21054a19322705de2d4f48d1d3f" title="The antiderivative of erx(x/sigma/sqrt(2)) with respect to x.">irplib_erf_antideriv</a>(x0p, sigma) + <a class="code" href="group__irplib__wavecal.html#ga2da9c21054a19322705de2d4f48d1d3f" title="The antiderivative of erx(x/sigma/sqrt(2)) with respect to x.">irplib_erf_antideriv</a>(x0n, sigma));
+<a name="l01257"></a>01257         (void)cpl_vector_set(<span class="keyword">self</span>, i, val);
+<a name="l01258"></a>01258     }
+<a name="l01259"></a>01259 
+<a name="l01260"></a>01260     <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l01261"></a>01261 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/irplib__wlxcorr_8h_source.html b/html/irplib__wlxcorr_8h_source.html
new file mode 100644
index 0000000..7e96a50
--- /dev/null
+++ b/html/irplib__wlxcorr_8h_source.html
@@ -0,0 +1,89 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: irplib_wlxcorr.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>irplib_wlxcorr.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: irplib_wlxcorr.h,v 1.20 2008/11/06 12:45:28 llundin Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the IRPLIB package</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: llundin $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2008/11/06 12:45:28 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.20 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifndef IRPLIB_WLXCORR_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#define IRPLIB_WLXCORR_H</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span>
+<a name="l00031"></a>00031 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00032"></a>00032 <span class="comment">                                Include</span>
+<a name="l00033"></a>00033 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00034"></a>00034 
+<a name="l00035"></a>00035 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00038"></a>00038 <span class="comment">                                    Define</span>
+<a name="l00039"></a>00039 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00040"></a>00040 
+<a name="l00041"></a>00041 <span class="comment">/* The 4 columns of the table */</span>
+<a name="l00042"></a>00042 <span class="preprocessor">#define IRPLIB_WLXCORR_COL_WAVELENGTH   "Wavelength"</span>
+<a name="l00043"></a>00043 <span class="preprocessor"></span><span class="preprocessor">#define IRPLIB_WLXCORR_COL_CAT_INIT     "Catalog Initial"</span>
+<a name="l00044"></a>00044 <span class="preprocessor"></span><span class="preprocessor">#define IRPLIB_WLXCORR_COL_CAT_FINAL    "Catalog Corrected"</span>
+<a name="l00045"></a>00045 <span class="preprocessor"></span><span class="preprocessor">#define IRPLIB_WLXCORR_COL_OBS          "Observed"</span>
+<a name="l00046"></a>00046 <span class="preprocessor"></span>
+<a name="l00047"></a>00047 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00048"></a>00048 <span class="comment">                                Functions prototypes</span>
+<a name="l00049"></a>00049 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00050"></a>00050 
+<a name="l00051"></a>00051 <span class="keywordtype">int</span> irplib_wlxcorr_plot_spc_table(<span class="keyword">const</span> cpl_table *, <span class="keyword">const</span> <span class="keywordtype">char</span> *) ;
+<a name="l00052"></a>00052 <span class="keywordtype">int</span> irplib_wlxcorr_catalog_plot(<span class="keyword">const</span> cpl_bivector *, <span class="keywordtype">double</span>, <span class="keywordtype">double</span>) ;
+<a name="l00053"></a>00053 <span class="keywordtype">int</span> irplib_wlxcorr_plot_solution(<span class="keyword">const</span> cpl_polynomial *, <span class="keyword">const</span> cpl_polynomial *,
+<a name="l00054"></a>00054         <span class="keyword">const</span> cpl_polynomial *, <span class="keywordtype">int</span>, <span class="keywordtype">int</span>) ;
+<a name="l00055"></a>00055 
+<a name="l00056"></a>00056 cpl_polynomial * irplib_wlxcorr_best_poly(<span class="keyword">const</span> cpl_vector *, 
+<a name="l00057"></a>00057         <span class="keyword">const</span> cpl_bivector *, <span class="keywordtype">int</span>, <span class="keyword">const</span> cpl_polynomial *, <span class="keyword">const</span> cpl_vector *, 
+<a name="l00058"></a>00058         <span class="keywordtype">int</span>, <span class="keywordtype">double</span>, <span class="keywordtype">double</span>, <span class="keywordtype">double</span> *, cpl_table **, cpl_vector **) ;
+<a name="l00059"></a>00059 cpl_table * irplib_wlxcorr_gen_spc_table(<span class="keyword">const</span> cpl_vector *, 
+<a name="l00060"></a>00060         <span class="keyword">const</span> cpl_bivector *, <span class="keywordtype">double</span>, <span class="keywordtype">double</span>, <span class="keyword">const</span> cpl_polynomial *,
+<a name="l00061"></a>00061         <span class="keyword">const</span> cpl_polynomial *) ;
+<a name="l00062"></a>00062 cpl_bivector * irplib_wlxcorr_cat_extract(<span class="keyword">const</span> cpl_bivector *, <span class="keywordtype">double</span>, <span class="keywordtype">double</span>);
+<a name="l00063"></a>00063 cpl_vector * irplib_wlxcorr_convolve_create_kernel(<span class="keywordtype">double</span>, <span class="keywordtype">double</span>) ;
+<a name="l00064"></a>00064 <span class="keywordtype">int</span> irplib_wlxcorr_convolve(cpl_vector *,<span class="keyword">const</span> cpl_vector *) ;
+<a name="l00065"></a>00065 
+<a name="l00066"></a>00066 
+<a name="l00067"></a>00067 cpl_error_code irplib_wlxcorr_vector_fill_line_spectrum(cpl_vector *,
+<a name="l00068"></a>00068                                                 <span class="keyword">const</span> cpl_polynomial *,
+<a name="l00069"></a>00069                                                 <span class="keyword">const</span> cpl_bivector *,
+<a name="l00070"></a>00070                                                 <span class="keywordtype">double</span>, <span class="keywordtype">double</span>, <span class="keywordtype">double</span>,
+<a name="l00071"></a>00071                                                 <span class="keywordtype">int</span>);
+<a name="l00072"></a>00072 
+<a name="l00073"></a>00073 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/modules.html b/html/modules.html
new file mode 100644
index 0000000..62ec186
--- /dev/null
+++ b/html/modules.html
@@ -0,0 +1,122 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: Module Index</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<div class="contents">
+<h1>Modules</h1>Here is a list of all modules:<ul>
+<li><a class="el" href="group__sinfo__absolute__utils.html">routines to determine the absolute positions</a></li>
+<li><a class="el" href="group__sinfo__bad__pix__search.html">Bad Pixel Search</a></li>
+<li><a class="el" href="group__sinfo__balance.html">To be removed</a></li>
+<li><a class="el" href="group__sinfo__baryvel.html">Velocity correction</a></li>
+<li><a class="el" href="group__sinfo__boltzmann.html">Boltzmann function operations</a></li>
+<li><a class="el" href="group__sinfo__coltilt.html">Column tilt computation</a></li>
+<li><a class="el" href="group__sinfo__companion.html">To be removed</a></li>
+<li><a class="el" href="group__sinfo__cube__construct.html">Cube generation functions</a></li>
+<li><a class="el" href="group__sinfo__dark__cfg.html">Dark manipulation functions</a></li>
+<li><a class="el" href="group__sinfo__detlin.html">Detector Linearity Determination Functions</a></li>
+<li><a class="el" href="group__sinfo__dfs.html">DFS related Utilities</a></li>
+<li><a class="el" href="group__sinfo__distortion.html">Distortion correction functions</a></li>
+<li><a class="el" href="group__sinfo__dump.html">Print CPL objects</a></li>
+<li><a class="el" href="group__sinfo__error.html">Error handling</a></li>
+<li><a class="el" href="group__sinfo__finddist__cfg.html">functions to determine slitlets distances</a></li>
+<li><a class="el" href="group__sinfo__fit.html">Fit functions</a></li>
+<li><a class="el" href="group__sinfo__flat__cfg.html">Flat manipulation functions</a></li>
+<li><a class="el" href="group__sinfo__focus.html">Focus determination functions</a></li>
+<li><a class="el" href="group__sinfo__function__1d.html">1d functions</a></li>
+<li><a class="el" href="group__spiffi__general__config.html">General configuration parameters</a></li>
+<li><a class="el" href="group__sinfo__globals.html">global functions</a></li>
+<li><a class="el" href="group__sinfo__image__ops.html">Image operations</a></li>
+<li><a class="el" href="group__sinfo__lamp__cfg.html">Flat frame manipulation functions</a></li>
+<li><a class="el" href="group__sinfo__lamp__spec__config.html">Spectroscopic flats manipulation</a></li>
+<li><a class="el" href="group__sinfo__msg.html">Messaging</a></li>
+<li><a class="el" href="group__sinfo__new__cube__ops.html">Cube operations</a></li>
+<li><a class="el" href="group__sinfo__new__resampling.html">Image resampling</a></li>
+<li><a class="el" href="group__sinfo__new__slit__pos.html">Slitlets position determination</a></li>
+<li><a class="el" href="group__sinfo__pfits.html">In/Out on propertylist cards</a></li>
+<li><a class="el" href="group__sinfo__pro__save.html">Functions to save a product</a></li>
+<li><a class="el" href="group__sinfo__produc__config.html">.c Pipeline products configurations</a></li>
+<li><a class="el" href="group__sinfo__qr__companion.html">functions for polynomial solution</a></li>
+<li><a class="el" href="group__sinfo__rec__utils.html">Recipe utilities</a></li>
+<li><a class="el" href="group__sinfo__remove__crh__single.html">Remove Cosmic Rays single (sinfo_remove_crh_single)</a></li>
+<li><a class="el" href="group__sinfo__shift__images.html">Functions to shift images</a></li>
+<li><a class="el" href="group__sinfo__skycor__config.html">Sky residuals corrections configuration</a></li>
+<li><a class="el" href="group__sinfo__spectrum__ops.html">Operations on spectra</a></li>
+<li><a class="el" href="group__sinfo__tilt__cfg.html">tilt computation</a></li>
+<li><a class="el" href="group__sinfo__time.html">Get date/time, possibly in ISO8601 format</a></li>
+<li><a class="el" href="group__sinfo__tpl__dfs.html">DFS related functions</a></li>
+<li><a class="el" href="group__sinfo__tpl__utils.html">Miscellaneous Utilities</a></li>
+<li><a class="el" href="group__sinfo__utilities.html">utilities</a></li>
+<li><a class="el" href="group__sinfo__utils.html">Utility functions</a></li>
+<li><a class="el" href="group__sinfo__utils__wrappers.html">Utility functions (wrappers)</a></li>
+<li><a class="el" href="group__sinfo__img__noise.html">Recipe to determine detector noise</a></li>
+<li><a class="el" href="group__sinfo__rec__detlin.html">Recipe to determine detector linearity</a></li>
+<li><a class="el" href="group__sinfo__rec__distortion.html">Recipe to compute optical distortions</a></li>
+<li><a class="el" href="group__sinfo__rec__jitter.html">Recipe to reduce science, PSF, telluric standards</a></li>
+<li><a class="el" href="group__sinfo__rec__lingain.html">Recipe to monitor detector's linearity and gain</a></li>
+<li><a class="el" href="group__sinfo__rec__mdark.html">Recipe to compute master dark</a></li>
+<li><a class="el" href="group__sinfo__rec__mflat.html">Recipe to compute master flat</a></li>
+<li><a class="el" href="group__sinfo__rec__objnod.html">Recipe to reduce science data</a></li>
+<li><a class="el" href="group__sinfo__rec__psf.html">Recipe to reduce PSF standard star data</a></li>
+<li><a class="el" href="group__sinfo__rec__pupil.html">Recipe to reduce pupil data</a></li>
+<li><a class="el" href="group__sinfo__rec__stdstar.html">Recipe to reduce telluric standard star data</a></li>
+<li><a class="el" href="group__sinfo__rec__wavecal.html">Recipe to reduce arc lamp data</a></li>
+<li><a class="el" href="group__sinfo__step__distortion.html">Recipe to compute optical distortions</a></li>
+<li><a class="el" href="group__sinfo__step__jitter.html">Recipe to reduce science, PSF or telluric standard data</a></li>
+<li><a class="el" href="group__sinfo__step__objnod.html">Recipe to reduce science data</a></li>
+<li><a class="el" href="group__sinfo__step__psf.html">Recipe to reduce PSF data</a></li>
+<li><a class="el" href="group__sinfo__step__stdstar.html">Recipe to reduce telluric standard data</a></li>
+<li><a class="el" href="group__sinfo__utl__bp__mask__add.html">Recipe to coadd bad pixel masks</a></li>
+<li><a class="el" href="group__sinfo__utl__cube2ima.html">Recipe to collapse a cube in an image</a></li>
+<li><a class="el" href="group__sinfo__utl__cube2spectrum.html">Recipe to collapse a cube in a spectrum</a></li>
+<li><a class="el" href="group__sinfo__utl__cube__arith.html">Recipe for cube arithmetics</a></li>
+<li><a class="el" href="group__sinfo__utl__cube__combine.html">Recipe to coadd cubes</a></li>
+<li><a class="el" href="group__sinfo__utl__cube__create.html">Recipe to coadd cubes</a></li>
+<li><a class="el" href="group__sinfo__utl__cube__test.html">Recipe to test cube operations</a></li>
+<li><a class="el" href="group__sinfo__utl__eff.html">Recipe to do operations on an image</a></li>
+<li><a class="el" href="group__sinfo__utl__illumcorr.html">Recipe to correct for slitlet illumination</a></li>
+<li><a class="el" href="group__sinfo__utl__ima__arith.html">Recipe to do operations on an image</a></li>
+<li><a class="el" href="group__sinfo__utl__ima__cube__ks__test.html">Recipe to do operations on an image</a></li>
+<li><a class="el" href="group__sinfo__utl__ima__gauss.html">Recipe to do operations on an image</a></li>
+<li><a class="el" href="group__sinfo__utl__ima__line__corr.html">Recipe to do operations on an image</a></li>
+<li><a class="el" href="group__sinfo__utl__remove__crh__single.html">Recipe to remove CRHs from an image</a></li>
+<li><a class="el" href="group__sinfo__utl__skycor.html">Recipe to correct sky residuals on science cubes</a></li>
+<li><a class="el" href="group__sinfo__utl__skymap.html">Recipe to generate a sky map for SINFONI SRTD</a></li>
+<li><a class="el" href="group__sinfo__utl__spectrum__divide__by__blackbody.html">Recipe to correct a spectrum from the blackbody thermal emission</a></li>
+<li><a class="el" href="group__sinfo__utl__spectrum__wavelength__shift.html">Recipe to shift a spectrum in wavelength</a></li>
+<li><a class="el" href="group__sinfo__utl__stdstars.html">Recipe to generate standard stars catalogs</a></li>
+<li><a class="el" href="group__sinfo__utl__table__ex.html">Recipe to do operations on an image</a></li>
+<li><a class="el" href="group__sinfo__utl__table__test.html">Utility to test column table shift</a></li>
+<li><a class="el" href="group__irplib__calib.html">Functions for calibrations</a></li>
+<li><a class="el" href="group__irplib__cat.html">Functions for accessing catalogues</a></li>
+<li><a class="el" href="group__irplib__distortion.html">Distortion correction functions</a></li>
+<li><a class="el" href="group__irplib__flat.html">Functions for flatfielding</a></li>
+<li><a class="el" href="group__irplib__framelist.html">Lists of frames with properties.</a></li>
+<li><a class="el" href="group__irplib__oddeven.html">Odd/Even column effect correction</a></li>
+<li><a class="el" href="group__irplib__plugin.html">Irplib plugin functionality</a></li>
+<li><a class="el" href="group__irplib__polynomial.html">1D-Polynomial roots</a></li>
+<li><a class="el" href="group__irplib__ppm.html">Point pattern matching</a></li>
+<li><a class="el" href="group__irplib__slitpos.html">Functions for slit position</a></li>
+<li><a class="el" href="group__irplib__spectrum.html">Functions for LSS spectra</a></li>
+<li><a class="el" href="group__irplib__stdstar.html">Functions for standard stars</a></li>
+<li><a class="el" href="group__irplib__strehl.html">Functions to compute the Strehl</a></li>
+<li><a class="el" href="group__irplib__utils.html">Miscellaneous Utilities</a></li>
+<li><a class="el" href="group__irplib__wavecal.html">Spectro functionality</a></li>
+<li><a class="el" href="group__irplib__wcs.html">Functions related to WCS</a></li>
+<li><a class="el" href="group__irplib__wlxcorr.html">Wavelength Cross correlation w. plotting</a></li>
+<li><a class="el" href="group__sinfo__absolute.html">Sinfo_absolute</a></li>
+<li><a class="el" href="group__sinfo__flat__ini__file.html">Flat manipulation functions</a></li>
+<li><a class="el" href="group__sinfo__new__bezier.html">Bezier Functions</a></li>
+<li><a class="el" href="group__sinfo__recipes.html">Recipe utilities</a></li>
+</ul>
+</div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/recipes_2sinfo__utl__cube2ima_8c_source.html b/html/recipes_2sinfo__utl__cube2ima_8c_source.html
new file mode 100644
index 0000000..ba79842
--- /dev/null
+++ b/html/recipes_2sinfo__utl__cube2ima_8c_source.html
@@ -0,0 +1,201 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_utl_cube2ima.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_utl_cube2ima.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_utl_cube2ima.c,v 1.10 2007/10/26 09:40:28 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the SINFONI Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2007/10/26 09:40:28 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.10 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span>
+<a name="l00032"></a>00032 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                                Includes</span>
+<a name="l00034"></a>00034 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 <span class="comment">/* cpl */</span>
+<a name="l00036"></a>00036 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00037"></a>00037  
+<a name="l00038"></a>00038 <span class="comment">/* irplib */</span>
+<a name="l00039"></a>00039 <span class="preprocessor">#include <irplib_utils.h></span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include <sinfo_msg.h></span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include <sinfo_tpl_utils.h></span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include <sinfo_pfits.h></span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include <sinfo_tpl_dfs.h></span>
+<a name="l00044"></a>00044 <span class="preprocessor">#include <sinfo_utl_cube2ima.h></span>
+<a name="l00045"></a>00045 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00046"></a>00046 <span class="comment">                            Functions prototypes</span>
+<a name="l00047"></a>00047 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00048"></a>00048 
+<a name="l00049"></a>00049 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_cube2ima_create(cpl_plugin *) ;
+<a name="l00050"></a>00050 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_cube2ima_exec(cpl_plugin *) ;
+<a name="l00051"></a>00051 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_cube2ima_destroy(cpl_plugin *) ;
+<a name="l00052"></a>00052 
+<a name="l00053"></a>00053 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00054"></a>00054 <span class="comment">                            Static variables</span>
+<a name="l00055"></a>00055 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00056"></a>00056 
+<a name="l00057"></a>00057 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_utl_cube2ima_description[] =
+<a name="l00058"></a>00058 <span class="stringliteral">"This recipe performs cube to image comversion.\n"</span>
+<a name="l00059"></a>00059 <span class="stringliteral">"The input file is a cube which is contained in the sof file\n"</span>
+<a name="l00060"></a>00060 <span class="stringliteral">"Its tag should be CUBE.\n"</span>
+<a name="l00061"></a>00061 <span class="stringliteral">"The output is an image resulting from the average of the \n"</span>
+<a name="l00062"></a>00062 <span class="stringliteral">"cube over a  wavelength rage which can be set by parameters \n"</span>
+<a name="l00063"></a>00063 <span class="stringliteral">"sinfoni.sinfo_utl_cube2ima.ws sinfoni.sinfo_utl_cube2ima.we\n"</span>
+<a name="l00064"></a>00064 <span class="stringliteral">"having aliases 'ws' 'we'\n"</span>
+<a name="l00065"></a>00065 <span class="stringliteral">"Information on relevant parameters can be found with\n"</span>
+<a name="l00066"></a>00066 <span class="stringliteral">"esorex --params sinfo_utl_cube2ima\n"</span>
+<a name="l00067"></a>00067 <span class="stringliteral">"esorex --help sinfo_utl_cube2ima\n"</span>
+<a name="l00068"></a>00068 <span class="stringliteral">"\n"</span>;
+<a name="l00069"></a>00069 
+<a name="l00070"></a>00070 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00071"></a>00071 <span class="comment">                                Functions code</span>
+<a name="l00072"></a>00072 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00073"></a>00073 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00077"></a>00077 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00079"></a>00079 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00087"></a>00087 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00088"></a><a class="code" href="group__sinfo__utl__cube2ima.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693">00088</a> <span class="keywordtype">int</span> <a class="code" href="group__sinfo__rec__detlin.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693" title="Build the list of available plugins, for this module.">cpl_plugin_get_info</a>(cpl_pluginlist * list)
+<a name="l00089"></a>00089 {
+<a name="l00090"></a>00090     cpl_recipe  *   recipe = cpl_calloc(1, <span class="keyword">sizeof</span> *recipe ) ;
+<a name="l00091"></a>00091     cpl_plugin  *   plugin = &recipe->interface ;
+<a name="l00092"></a>00092 
+<a name="l00093"></a>00093     cpl_plugin_init(plugin,
+<a name="l00094"></a>00094                     CPL_PLUGIN_API,
+<a name="l00095"></a>00095                     SINFONI_BINARY_VERSION,
+<a name="l00096"></a>00096                     CPL_PLUGIN_TYPE_RECIPE,
+<a name="l00097"></a>00097                     <span class="stringliteral">"sinfo_utl_cube2ima"</span>,
+<a name="l00098"></a>00098                     <span class="stringliteral">"Cube to image conversion"</span>,
+<a name="l00099"></a>00099                     sinfo_utl_cube2ima_description,
+<a name="l00100"></a>00100                     <span class="stringliteral">"Andrea Modigliani"</span>,
+<a name="l00101"></a>00101                     <span class="stringliteral">"Andrea.Modigliani at eso.org"</span>,
+<a name="l00102"></a>00102                     sinfo_get_license(),
+<a name="l00103"></a>00103                     sinfo_utl_cube2ima_create,
+<a name="l00104"></a>00104                     sinfo_utl_cube2ima_exec,
+<a name="l00105"></a>00105                     sinfo_utl_cube2ima_destroy) ;
+<a name="l00106"></a>00106 
+<a name="l00107"></a>00107     cpl_pluginlist_append(list, plugin) ;
+<a name="l00108"></a>00108     
+<a name="l00109"></a>00109     <span class="keywordflow">return</span> 0;
+<a name="l00110"></a>00110 }
+<a name="l00111"></a>00111 
+<a name="l00112"></a>00112 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00121"></a>00121 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00122"></a>00122 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_cube2ima_create(cpl_plugin * plugin)
+<a name="l00123"></a>00123 {
+<a name="l00124"></a>00124     cpl_recipe      * recipe ;
+<a name="l00125"></a>00125     cpl_parameter   * p ;
+<a name="l00126"></a>00126 
+<a name="l00127"></a>00127     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00128"></a>00128     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00129"></a>00129         recipe = (cpl_recipe *)plugin ;
+<a name="l00130"></a>00130     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00131"></a>00131     cpl_error_reset();
+<a name="l00132"></a>00132     <a class="code" href="group__irplib__utils.html#gaf9d392144014e2363054bc3f83c8e47e" title="Reset IRPLIB state.">irplib_reset</a>();
+<a name="l00133"></a>00133 
+<a name="l00134"></a>00134     <span class="comment">/* Create the parameters list in the cpl_recipe object */</span>
+<a name="l00135"></a>00135     recipe->parameters = cpl_parameterlist_new() ; 
+<a name="l00136"></a>00136 
+<a name="l00137"></a>00137     <span class="comment">/* Fill the parameters list */</span>
+<a name="l00138"></a>00138     <span class="comment">/* --stropt */</span>
+<a name="l00139"></a>00139 
+<a name="l00140"></a>00140     <span class="comment">/* --doubleopt */</span>
+<a name="l00141"></a>00141     p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.sinfo_utl_cube2ima.ws"</span>, 
+<a name="l00142"></a>00142                                 CPL_TYPE_DOUBLE, 
+<a name="l00143"></a>00143                                 <span class="stringliteral">"starting wavelength"</span>, 
+<a name="l00144"></a>00144                                 <span class="stringliteral">"sinfoni.sinfo_utl_cube2ima"</span>, 
+<a name="l00145"></a>00145                                 0.9999) ;
+<a name="l00146"></a>00146     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"ws"</span>) ;
+<a name="l00147"></a>00147     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00148"></a>00148 
+<a name="l00149"></a>00149 
+<a name="l00150"></a>00150     <span class="comment">/* --doubleopt */</span>
+<a name="l00151"></a>00151     p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.sinfo_utl_cube2ima.we"</span>, 
+<a name="l00152"></a>00152                                 CPL_TYPE_DOUBLE, 
+<a name="l00153"></a>00153                                 <span class="stringliteral">"starting wavelength"</span>, 
+<a name="l00154"></a>00154                                 <span class="stringliteral">"sinfoni.sinfo_utl_cube2ima"</span>, 
+<a name="l00155"></a>00155                                 2.999) ;
+<a name="l00156"></a>00156     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"we"</span>) ;
+<a name="l00157"></a>00157     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00158"></a>00158 
+<a name="l00159"></a>00159     <span class="comment">/* Return */</span>
+<a name="l00160"></a>00160     <span class="keywordflow">return</span> 0;
+<a name="l00161"></a>00161 }
+<a name="l00162"></a>00162 
+<a name="l00163"></a>00163 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00169"></a>00169 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00170"></a>00170 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_cube2ima_exec(cpl_plugin * plugin)
+<a name="l00171"></a>00171 {
+<a name="l00172"></a>00172     cpl_recipe  *   recipe ;
+<a name="l00173"></a>00173     <span class="keywordtype">int</span> result=0;
+<a name="l00174"></a>00174     cpl_errorstate initial_errorstate = cpl_errorstate_get();
+<a name="l00175"></a>00175 
+<a name="l00176"></a>00176     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00177"></a>00177     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00178"></a>00178         recipe = (cpl_recipe *)plugin ;
+<a name="l00179"></a>00179     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00180"></a>00180 
+<a name="l00181"></a>00181       sinfo_msg(<span class="stringliteral">"Welcome to SINFONI Pipeline release %d.%d.%d"</span>,
+<a name="l00182"></a>00182         SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
+<a name="l00183"></a>00183 
+<a name="l00184"></a>00184     result=sinfo_utl_cube2ima(recipe->parameters, recipe->frames) ;
+<a name="l00185"></a>00185 
+<a name="l00186"></a>00186     <span class="keywordflow">if</span> (!cpl_errorstate_is_equal(initial_errorstate)) {                      
+<a name="l00187"></a>00187         <span class="comment">/* Dump the error history since recipe execution start.                </span>
+<a name="l00188"></a>00188 <span class="comment">           At this point the recipe cannot recover from the error */</span>           
+<a name="l00189"></a>00189         cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);              
+<a name="l00190"></a>00190     } 
+<a name="l00191"></a>00191 
+<a name="l00192"></a>00192     <span class="keywordflow">return</span> result ;
+<a name="l00193"></a>00193 }
+<a name="l00194"></a>00194 
+<a name="l00195"></a>00195 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00201"></a>00201 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00202"></a>00202 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_cube2ima_destroy(cpl_plugin * plugin)
+<a name="l00203"></a>00203 {
+<a name="l00204"></a>00204     cpl_recipe  *   recipe ;
+<a name="l00205"></a>00205 
+<a name="l00206"></a>00206     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00207"></a>00207     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00208"></a>00208         recipe = (cpl_recipe *)plugin ;
+<a name="l00209"></a>00209     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00210"></a>00210 
+<a name="l00211"></a>00211     cpl_parameterlist_delete(recipe->parameters) ; 
+<a name="l00212"></a>00212     <span class="keywordflow">return</span> 0 ;
+<a name="l00213"></a>00213 }
+<a name="l00214"></a>00214 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/recipes_2sinfo__utl__cube2spectrum_8c_source.html b/html/recipes_2sinfo__utl__cube2spectrum_8c_source.html
new file mode 100644
index 0000000..5ef6332
--- /dev/null
+++ b/html/recipes_2sinfo__utl__cube2spectrum_8c_source.html
@@ -0,0 +1,275 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_utl_cube2spectrum.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_utl_cube2spectrum.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_utl_cube2spectrum.c,v 1.12 2007/10/26 08:33:11 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the SINFONI Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2007/10/26 08:33:11 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.12 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span>
+<a name="l00032"></a>00032 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                                Includes</span>
+<a name="l00034"></a>00034 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 
+<a name="l00036"></a>00036 <span class="comment">/* cpl */</span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00038"></a>00038 <span class="comment">/* irplib */</span>
+<a name="l00039"></a>00039 <span class="preprocessor">#include <irplib_utils.h></span>
+<a name="l00040"></a>00040 
+<a name="l00041"></a>00041 <span class="preprocessor">#include <sinfo_tpl_utils.h></span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include <sinfo_pfits.h></span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include <sinfo_tpl_dfs.h></span>
+<a name="l00044"></a>00044 <span class="preprocessor">#include <sinfo_utl_cube2spectrum.h></span>
+<a name="l00045"></a>00045 <span class="preprocessor">#include <sinfo_msg.h></span>
+<a name="l00046"></a>00046 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00047"></a>00047 <span class="comment">                            Functions prototypes</span>
+<a name="l00048"></a>00048 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00049"></a>00049 
+<a name="l00050"></a>00050 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_cube2spectrum_create(cpl_plugin *) ;
+<a name="l00051"></a>00051 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_cube2spectrum_exec(cpl_plugin *) ;
+<a name="l00052"></a>00052 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_cube2spectrum_destroy(cpl_plugin *) ;
+<a name="l00053"></a>00053 
+<a name="l00054"></a>00054 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00055"></a>00055 <span class="comment">                            Static variables</span>
+<a name="l00056"></a>00056 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00057"></a>00057 
+<a name="l00058"></a>00058 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_utl_cube2spectrum_description[] =
+<a name="l00059"></a>00059 <span class="stringliteral">"This recipe performs cube to 1D spectrum image conversion.\n"</span>
+<a name="l00060"></a>00060 <span class="stringliteral">"The input files is a cube\n"</span>
+<a name="l00061"></a>00061 <span class="stringliteral">"Its associated tag should be CUBE.\n"</span>
+<a name="l00062"></a>00062 <span class="stringliteral">"The output is an image resulting from the cube manipulated \n"</span>
+<a name="l00063"></a>00063 <span class="stringliteral">"according to the value of op\n"</span>
+<a name="l00064"></a>00064 <span class="stringliteral">"Over an aperture as specified by the parameter \n"</span>
+<a name="l00065"></a>00065 <span class="stringliteral">"sinfoni.sinfo_utl_cube2spectrum.aperture having alias 'op', 'ap'"</span>
+<a name="l00066"></a>00066 <span class="stringliteral">"Information on relevant parameters can be found with\n"</span>
+<a name="l00067"></a>00067 <span class="stringliteral">"esorex --params sinfo_utl_cube2spectrum\n"</span>
+<a name="l00068"></a>00068 <span class="stringliteral">"esorex --help sinfo_utl_cube2spectrum\n"</span>
+<a name="l00069"></a>00069 <span class="stringliteral">"\n"</span>;
+<a name="l00070"></a>00070 
+<a name="l00071"></a>00071 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00072"></a>00072 <span class="comment">                                Functions code</span>
+<a name="l00073"></a>00073 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00074"></a>00074 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00078"></a>00078 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00079"></a>00079 
+<a name="l00081"></a>00081 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00089"></a>00089 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00090"></a><a class="code" href="group__sinfo__utl__cube2spectrum.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693">00090</a> <span class="keywordtype">int</span> <a class="code" href="group__sinfo__rec__detlin.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693" title="Build the list of available plugins, for this module.">cpl_plugin_get_info</a>(cpl_pluginlist * list)
+<a name="l00091"></a>00091 {
+<a name="l00092"></a>00092     cpl_recipe  *   recipe = cpl_calloc(1, <span class="keyword">sizeof</span> *recipe ) ;
+<a name="l00093"></a>00093     cpl_plugin  *   plugin = &recipe->interface ;
+<a name="l00094"></a>00094 
+<a name="l00095"></a>00095     cpl_plugin_init(plugin,
+<a name="l00096"></a>00096                     CPL_PLUGIN_API,
+<a name="l00097"></a>00097                     SINFONI_BINARY_VERSION,
+<a name="l00098"></a>00098                     CPL_PLUGIN_TYPE_RECIPE,
+<a name="l00099"></a>00099                     <span class="stringliteral">"sinfo_utl_cube2spectrum"</span>,
+<a name="l00100"></a>00100                     <span class="stringliteral">"Collapse a cube to an image over an aperture"</span>,
+<a name="l00101"></a>00101                     sinfo_utl_cube2spectrum_description,
+<a name="l00102"></a>00102                     <span class="stringliteral">"Andrea Modigliani"</span>,
+<a name="l00103"></a>00103                     <span class="stringliteral">"Andrea.Modigliani at eso.org"</span>,
+<a name="l00104"></a>00104                     sinfo_get_license(),
+<a name="l00105"></a>00105                     sinfo_utl_cube2spectrum_create,
+<a name="l00106"></a>00106                     sinfo_utl_cube2spectrum_exec,
+<a name="l00107"></a>00107                     sinfo_utl_cube2spectrum_destroy) ;
+<a name="l00108"></a>00108 
+<a name="l00109"></a>00109     cpl_pluginlist_append(list, plugin) ;
+<a name="l00110"></a>00110     
+<a name="l00111"></a>00111     <span class="keywordflow">return</span> 0;
+<a name="l00112"></a>00112 }
+<a name="l00113"></a>00113 
+<a name="l00114"></a>00114 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00123"></a>00123 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00124"></a>00124 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_cube2spectrum_create(cpl_plugin * plugin)
+<a name="l00125"></a>00125 {
+<a name="l00126"></a>00126     cpl_recipe      * recipe ;
+<a name="l00127"></a>00127     cpl_parameter   * p ;
+<a name="l00128"></a>00128 
+<a name="l00129"></a>00129     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00130"></a>00130     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00131"></a>00131         recipe = (cpl_recipe *)plugin ;
+<a name="l00132"></a>00132     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00133"></a>00133     cpl_error_reset();
+<a name="l00134"></a>00134     <a class="code" href="group__irplib__utils.html#gaf9d392144014e2363054bc3f83c8e47e" title="Reset IRPLIB state.">irplib_reset</a>();
+<a name="l00135"></a>00135 
+<a name="l00136"></a>00136     <span class="comment">/* Create the parameters list in the cpl_recipe object */</span>
+<a name="l00137"></a>00137     recipe->parameters = cpl_parameterlist_new() ; 
+<a name="l00138"></a>00138 
+<a name="l00139"></a>00139     <span class="comment">/* Fill the parameters list */</span>
+<a name="l00140"></a>00140     <span class="comment">/* --stropt */</span>
+<a name="l00141"></a>00141     p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.sinfo_utl_cube2spectrum.op"</span>, 
+<a name="l00142"></a>00142             CPL_TYPE_STRING, <span class="stringliteral">"A possible operation:"</span>
+<a name="l00143"></a>00143             <span class="stringliteral">" average, clean_mean, median, sum"</span>, 
+<a name="l00144"></a>00144             <span class="stringliteral">"sinfoni.sinfo_utl_cube2spectrum"</span>,<span class="stringliteral">"average"</span>);
+<a name="l00145"></a>00145     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"op"</span>) ;
+<a name="l00146"></a>00146     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00147"></a>00147 
+<a name="l00148"></a>00148 
+<a name="l00149"></a>00149      <span class="comment">/* --stropt */</span>
+<a name="l00150"></a>00150     p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.sinfo_utl_cube2spectrum.ap"</span>, 
+<a name="l00151"></a>00151             CPL_TYPE_STRING, <span class="stringliteral">"A possible aperture: rectangle, circle"</span>, 
+<a name="l00152"></a>00152             <span class="stringliteral">"sinfoni.sinfo_utl_cube2spectrum"</span>,<span class="stringliteral">"rectangle"</span>);
+<a name="l00153"></a>00153     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"ap"</span>) ;
+<a name="l00154"></a>00154     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00155"></a>00155 
+<a name="l00156"></a>00156 
+<a name="l00157"></a>00157     <span class="comment">/* --doubleopt */</span>
+<a name="l00158"></a>00158     p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.sinfo_utl_cube2spectrum.llx"</span>, 
+<a name="l00159"></a>00159                                 CPL_TYPE_INT, 
+<a name="l00160"></a>00160                                 <span class="stringliteral">"Lower left X rectangle coordinate"</span>, 
+<a name="l00161"></a>00161                                 <span class="stringliteral">"sinfoni.sinfo_utl_cube2spectrum"</span>, 2) ;
+<a name="l00162"></a>00162     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"llx"</span>) ;
+<a name="l00163"></a>00163     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00164"></a>00164 
+<a name="l00165"></a>00165 
+<a name="l00166"></a>00166     p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.sinfo_utl_cube2spectrum.lly"</span>, 
+<a name="l00167"></a>00167                                 CPL_TYPE_INT, 
+<a name="l00168"></a>00168                                 <span class="stringliteral">"Lower left Y rectangle coordinate"</span>, 
+<a name="l00169"></a>00169                                 <span class="stringliteral">"sinfoni.sinfo_utl_cube2spectrum"</span>, 2) ;
+<a name="l00170"></a>00170     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"lly"</span>) ;
+<a name="l00171"></a>00171     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00172"></a>00172 
+<a name="l00173"></a>00173 
+<a name="l00174"></a>00174     p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.sinfo_utl_cube2spectrum.urx"</span>, 
+<a name="l00175"></a>00175             CPL_TYPE_INT, <span class="stringliteral">"Upper right X rectangle coordinate"</span>, 
+<a name="l00176"></a>00176                                 <span class="stringliteral">"sinfoni.sinfo_utl_cube2spectrum"</span>, 28) ;
+<a name="l00177"></a>00177     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"urx"</span>) ;
+<a name="l00178"></a>00178     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00179"></a>00179 
+<a name="l00180"></a>00180 
+<a name="l00181"></a>00181     p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.sinfo_utl_cube2spectrum.ury"</span>, 
+<a name="l00182"></a>00182                                 CPL_TYPE_INT, 
+<a name="l00183"></a>00183                                 <span class="stringliteral">"Upper right Y rectangle coordinate"</span>, 
+<a name="l00184"></a>00184                                 <span class="stringliteral">"sinfoni.sinfo_utl_cube2spectrum"</span>, 28) ;
+<a name="l00185"></a>00185     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"ury"</span>) ;
+<a name="l00186"></a>00186     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00187"></a>00187 
+<a name="l00188"></a>00188 
+<a name="l00189"></a>00189 
+<a name="l00190"></a>00190     p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.sinfo_utl_cube2spectrum.lo_rej"</span>, 
+<a name="l00191"></a>00191                                 CPL_TYPE_INT, 
+<a name="l00192"></a>00192                                 <span class="stringliteral">"Clean mean low rejection"</span>, 
+<a name="l00193"></a>00193                                 <span class="stringliteral">"sinfoni.sinfo_utl_cube2spectrum"</span>, 10) ;
+<a name="l00194"></a>00194     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"lo_rej"</span>) ;
+<a name="l00195"></a>00195     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00196"></a>00196 
+<a name="l00197"></a>00197 
+<a name="l00198"></a>00198     p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.sinfo_utl_cube2spectrum.hi_rej"</span>, 
+<a name="l00199"></a>00199                                 CPL_TYPE_INT, 
+<a name="l00200"></a>00200                                 <span class="stringliteral">"Clean mean low rejection"</span>, 
+<a name="l00201"></a>00201                                 <span class="stringliteral">"sinfoni.sinfo_utl_cube2spectrum"</span>, 10) ;
+<a name="l00202"></a>00202     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"hi_rej"</span>) ;
+<a name="l00203"></a>00203     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00204"></a>00204 
+<a name="l00205"></a>00205 
+<a name="l00206"></a>00206 
+<a name="l00207"></a>00207     p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.sinfo_utl_cube2spectrum.centerx"</span>, 
+<a name="l00208"></a>00208                                 CPL_TYPE_INT, 
+<a name="l00209"></a>00209                                 <span class="stringliteral">"Circle center X coordinate"</span>, 
+<a name="l00210"></a>00210                                 <span class="stringliteral">"sinfoni.sinfo_utl_cube2spectrum"</span>, 16) ;
+<a name="l00211"></a>00211     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"centerx"</span>) ;
+<a name="l00212"></a>00212     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00213"></a>00213 
+<a name="l00214"></a>00214 
+<a name="l00215"></a>00215     p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.sinfo_utl_cube2spectrum.centery"</span>, 
+<a name="l00216"></a>00216                                 CPL_TYPE_INT, 
+<a name="l00217"></a>00217                                 <span class="stringliteral">"Circle center Y coordinate"</span>, 
+<a name="l00218"></a>00218                                 <span class="stringliteral">"sinfoni.sinfo_utl_cube2spectrum"</span>, 16) ;
+<a name="l00219"></a>00219     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"centery"</span>) ;
+<a name="l00220"></a>00220     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00221"></a>00221 
+<a name="l00222"></a>00222 
+<a name="l00223"></a>00223     p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.sinfo_utl_cube2spectrum.radius"</span>, 
+<a name="l00224"></a>00224                                 CPL_TYPE_INT, <span class="stringliteral">"Circle radii"</span>, 
+<a name="l00225"></a>00225                                 <span class="stringliteral">"sinfoni.sinfo_utl_cube2spectrum"</span>, 5) ;
+<a name="l00226"></a>00226     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"radius"</span>) ;
+<a name="l00227"></a>00227     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00228"></a>00228 
+<a name="l00229"></a>00229  
+<a name="l00230"></a>00230     <span class="comment">/* Return */</span>
+<a name="l00231"></a>00231     <span class="keywordflow">return</span> 0;
+<a name="l00232"></a>00232 }
+<a name="l00233"></a>00233 
+<a name="l00234"></a>00234 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00240"></a>00240 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00241"></a>00241 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_cube2spectrum_exec(cpl_plugin * plugin)
+<a name="l00242"></a>00242 {
+<a name="l00243"></a>00243     cpl_recipe  *   recipe ;
+<a name="l00244"></a>00244     <span class="keywordtype">int</span> result=0;
+<a name="l00245"></a>00245     cpl_errorstate initial_errorstate = cpl_errorstate_get();
+<a name="l00246"></a>00246 
+<a name="l00247"></a>00247     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00248"></a>00248     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00249"></a>00249         recipe = (cpl_recipe *)plugin ;
+<a name="l00250"></a>00250     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00251"></a>00251 
+<a name="l00252"></a>00252     <span class="keywordflow">if</span>(sinfo_dfs_set_groups(recipe->frames)) {
+<a name="l00253"></a>00253        <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>( <span class="stringliteral">"Cannot indentify RAW and CALIB frames"</span>) ;
+<a name="l00254"></a>00254        <span class="keywordflow">return</span> -1;
+<a name="l00255"></a>00255     }
+<a name="l00256"></a>00256       sinfo_msg(<span class="stringliteral">"Welcome to SINFONI Pipeline release %d.%d.%d"</span>,
+<a name="l00257"></a>00257         SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
+<a name="l00258"></a>00258 
+<a name="l00259"></a>00259     result = sinfo_utl_cube2spectrum(recipe->parameters, recipe->frames,NULL);
+<a name="l00260"></a>00260     <span class="keywordflow">if</span> (!cpl_errorstate_is_equal(initial_errorstate)) {                      
+<a name="l00261"></a>00261         <span class="comment">/* Dump the error history since recipe execution start.                </span>
+<a name="l00262"></a>00262 <span class="comment">           At this point the recipe cannot recover from the error */</span>           
+<a name="l00263"></a>00263         cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);              
+<a name="l00264"></a>00264     } 
+<a name="l00265"></a>00265 
+<a name="l00266"></a>00266     <span class="keywordflow">return</span> result;
+<a name="l00267"></a>00267 }
+<a name="l00268"></a>00268 
+<a name="l00269"></a>00269 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00275"></a>00275 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00276"></a>00276 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_cube2spectrum_destroy(cpl_plugin * plugin)
+<a name="l00277"></a>00277 {
+<a name="l00278"></a>00278     cpl_recipe  *   recipe ;
+<a name="l00279"></a>00279 
+<a name="l00280"></a>00280     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00281"></a>00281     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00282"></a>00282         recipe = (cpl_recipe *)plugin ;
+<a name="l00283"></a>00283     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00284"></a>00284 
+<a name="l00285"></a>00285     cpl_parameterlist_delete(recipe->parameters) ; 
+<a name="l00286"></a>00286     <span class="keywordflow">return</span> 0 ;
+<a name="l00287"></a>00287 }
+<a name="l00288"></a>00288 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/recipes_2sinfo__utl__cube__arith_8c_source.html b/html/recipes_2sinfo__utl__cube__arith_8c_source.html
new file mode 100644
index 0000000..0f0e0a6
--- /dev/null
+++ b/html/recipes_2sinfo__utl__cube__arith_8c_source.html
@@ -0,0 +1,217 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_utl_cube_arith.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_utl_cube_arith.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_utl_cube_arith.c,v 1.10 2007/10/26 09:40:28 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the SINFONI Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2007/10/26 09:40:28 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.10 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span>
+<a name="l00032"></a>00032 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                                Includes</span>
+<a name="l00034"></a>00034 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 <span class="preprocessor">#include <string.h></span>
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="comment">/* cpl */</span>
+<a name="l00038"></a>00038 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00039"></a>00039 <span class="comment">/* irplib */</span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include <irplib_utils.h></span>
+<a name="l00041"></a>00041 
+<a name="l00042"></a>00042 <span class="preprocessor">#include <sinfo_tpl_utils.h></span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include <sinfo_pfits.h></span>
+<a name="l00044"></a>00044 <span class="preprocessor">#include <sinfo_tpl_dfs.h></span>
+<a name="l00045"></a>00045 <span class="preprocessor">#include <sinfo_utl_cube_arith.h></span>
+<a name="l00046"></a>00046 <span class="preprocessor">#include <sinfo_msg.h></span>
+<a name="l00047"></a>00047 
+<a name="l00048"></a>00048 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00049"></a>00049 <span class="comment">                            Functions prototypes</span>
+<a name="l00050"></a>00050 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00051"></a>00051 
+<a name="l00052"></a>00052 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_cube_arith_create(cpl_plugin *) ;
+<a name="l00053"></a>00053 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_cube_arith_exec(cpl_plugin *) ;
+<a name="l00054"></a>00054 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_cube_arith_destroy(cpl_plugin *) ;
+<a name="l00055"></a>00055 
+<a name="l00056"></a>00056 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00057"></a>00057 <span class="comment">                            Static variables</span>
+<a name="l00058"></a>00058 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00059"></a>00059 
+<a name="l00060"></a>00060 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_utl_cube_arith_description1[] =
+<a name="l00061"></a>00061 <span class="stringliteral">"This recipe perform cube arithmetics.\n"</span>
+<a name="l00062"></a>00062 <span class="stringliteral">"If parameter value is specified the input frame is a cube \n"</span>
+<a name="l00063"></a>00063 <span class="stringliteral">"in a sof file with tag CUBE\n"</span>
+<a name="l00064"></a>00064 <span class="stringliteral">"Else the input files are a cube and an images or a spectrum\n"</span>
+<a name="l00065"></a>00065 <span class="stringliteral">"their associated tags should be respectively CUBE, IMA or SPECTRUM.\n"</span>
+<a name="l00066"></a>00066 <span class="stringliteral">"The output is a cube with tag PRO_CUBE resulting from the operation \n"</span>
+<a name="l00067"></a>00067 <span class="stringliteral">"CUBE op IMA or \n"</span>
+<a name="l00068"></a>00068 <span class="stringliteral">"CUBE op SPECTRUM or\n"</span>
+<a name="l00069"></a>00069 <span class="stringliteral">"CUBE op value where op indicates\n"</span>
+<a name="l00070"></a>00070 <span class="stringliteral">"the operation to be performed\n"</span>;
+<a name="l00071"></a>00071 
+<a name="l00072"></a>00072 
+<a name="l00073"></a>00073 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_utl_cube_arith_description2[] =
+<a name="l00074"></a>00074 <span class="stringliteral">"Information on relevant parameters can be found with\n"</span>
+<a name="l00075"></a>00075 <span class="stringliteral">"esorex --params sinfo_utl_cube_arith\n"</span>
+<a name="l00076"></a>00076 <span class="stringliteral">"esorex --help sinfo_utl_cube_arith\n"</span>
+<a name="l00077"></a>00077 <span class="stringliteral">"\n"</span>;
+<a name="l00078"></a>00078 
+<a name="l00079"></a>00079 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_utl_cube_arith_description[600];
+<a name="l00080"></a>00080 
+<a name="l00081"></a>00081 
+<a name="l00082"></a>00082 
+<a name="l00083"></a>00083 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00084"></a>00084 <span class="comment">                                Functions code</span>
+<a name="l00085"></a>00085 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00086"></a>00086 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00090"></a>00090 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00092"></a>00092 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00100"></a>00100 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00101"></a><a class="code" href="group__sinfo__utl__cube__arith.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693">00101</a> <span class="keywordtype">int</span> <a class="code" href="group__sinfo__rec__detlin.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693" title="Build the list of available plugins, for this module.">cpl_plugin_get_info</a>(cpl_pluginlist * list)
+<a name="l00102"></a>00102 {
+<a name="l00103"></a>00103     cpl_recipe  *   recipe = cpl_calloc(1, <span class="keyword">sizeof</span> *recipe ) ;
+<a name="l00104"></a>00104     cpl_plugin  *   plugin = &recipe->interface ;
+<a name="l00105"></a>00105 
+<a name="l00106"></a>00106     strcpy(sinfo_utl_cube_arith_description,sinfo_utl_cube_arith_description1);
+<a name="l00107"></a>00107     strcat(sinfo_utl_cube_arith_description,sinfo_utl_cube_arith_description2);
+<a name="l00108"></a>00108 
+<a name="l00109"></a>00109     cpl_plugin_init(plugin,
+<a name="l00110"></a>00110                     CPL_PLUGIN_API,
+<a name="l00111"></a>00111                     SINFONI_BINARY_VERSION,
+<a name="l00112"></a>00112                     CPL_PLUGIN_TYPE_RECIPE,
+<a name="l00113"></a>00113                     <span class="stringliteral">"sinfo_utl_cube_arith"</span>,
+<a name="l00114"></a>00114                     <span class="stringliteral">"Cube arithmetics"</span>,
+<a name="l00115"></a>00115                     sinfo_utl_cube_arith_description,
+<a name="l00116"></a>00116                     <span class="stringliteral">"Andrea Modigliani"</span>,
+<a name="l00117"></a>00117                     <span class="stringliteral">"Andrea.Modigliani at eso.org"</span>,
+<a name="l00118"></a>00118                     sinfo_get_license(),
+<a name="l00119"></a>00119                     sinfo_utl_cube_arith_create,
+<a name="l00120"></a>00120                     sinfo_utl_cube_arith_exec,
+<a name="l00121"></a>00121                     sinfo_utl_cube_arith_destroy) ;
+<a name="l00122"></a>00122 
+<a name="l00123"></a>00123     cpl_pluginlist_append(list, plugin) ;
+<a name="l00124"></a>00124     
+<a name="l00125"></a>00125     <span class="keywordflow">return</span> 0;
+<a name="l00126"></a>00126 }
+<a name="l00127"></a>00127 
+<a name="l00128"></a>00128 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00137"></a>00137 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00138"></a>00138 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_cube_arith_create(cpl_plugin * plugin)
+<a name="l00139"></a>00139 {
+<a name="l00140"></a>00140     cpl_recipe      * recipe ;
+<a name="l00141"></a>00141     cpl_parameter   * p ;
+<a name="l00142"></a>00142 
+<a name="l00143"></a>00143     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00144"></a>00144     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00145"></a>00145         recipe = (cpl_recipe *)plugin ;
+<a name="l00146"></a>00146     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00147"></a>00147     cpl_error_reset();
+<a name="l00148"></a>00148     <a class="code" href="group__irplib__utils.html#gaf9d392144014e2363054bc3f83c8e47e" title="Reset IRPLIB state.">irplib_reset</a>();
+<a name="l00149"></a>00149     <span class="comment">/* Create the parameters list in the cpl_recipe object */</span>
+<a name="l00150"></a>00150     recipe->parameters = cpl_parameterlist_new() ; 
+<a name="l00151"></a>00151 
+<a name="l00152"></a>00152     <span class="comment">/* Fill the parameters list */</span>
+<a name="l00153"></a>00153     <span class="comment">/* --stropt */</span>
+<a name="l00154"></a>00154     p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.sinfo_utl_cube_arith.op"</span>, 
+<a name="l00155"></a>00155                                 CPL_TYPE_STRING, 
+<a name="l00156"></a>00156                                 <span class="stringliteral">"A possible operation: "</span>
+<a name="l00157"></a>00157                                 <span class="stringliteral">"`/','*','+' or `-'"</span>, 
+<a name="l00158"></a>00158                                 <span class="stringliteral">"sinfoni.sinfo_utl_cube_arith"</span>,<span class="stringliteral">"/"</span>);
+<a name="l00159"></a>00159     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"op"</span>) ;
+<a name="l00160"></a>00160     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00161"></a>00161 
+<a name="l00162"></a>00162 
+<a name="l00163"></a>00163     <span class="comment">/* --doubleopt */</span>
+<a name="l00164"></a>00164     <span class="comment">/*</span>
+<a name="l00165"></a>00165 <span class="comment">    p = cpl_parameter_new_value("sinfoni.sinfo_utl_cube_arith.temperature", </span>
+<a name="l00166"></a>00166 <span class="comment">                                 CPL_TYPE_DOUBLE, "Black Body Temperature", </span>
+<a name="l00167"></a>00167 <span class="comment">                                 "sinfoni.sinfo_utl_cube_arith", 100000.) ;</span>
+<a name="l00168"></a>00168 <span class="comment">    cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "temp") ;</span>
+<a name="l00169"></a>00169 <span class="comment">    cpl_parameterlist_append(recipe->parameters, p) ;</span>
+<a name="l00170"></a>00170 <span class="comment">    */</span>
+<a name="l00171"></a>00171 
+<a name="l00172"></a>00172     p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.sinfo_utl_cube_arith.value"</span>, 
+<a name="l00173"></a>00173                                 CPL_TYPE_DOUBLE, <span class="stringliteral">"A constant to add"</span>, 
+<a name="l00174"></a>00174                                 <span class="stringliteral">"sinfoni.sinfo_utl_cube_arith"</span>, 99999.0) ;
+<a name="l00175"></a>00175     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"value"</span>) ;
+<a name="l00176"></a>00176     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00177"></a>00177  
+<a name="l00178"></a>00178     <span class="comment">/* Return */</span>
+<a name="l00179"></a>00179     <span class="keywordflow">return</span> 0;
+<a name="l00180"></a>00180 }
+<a name="l00181"></a>00181 
+<a name="l00182"></a>00182 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00188"></a>00188 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00189"></a>00189 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_cube_arith_exec(cpl_plugin * plugin)
+<a name="l00190"></a>00190 {
+<a name="l00191"></a>00191     cpl_recipe  *   recipe ;
+<a name="l00192"></a>00192     <span class="keywordtype">int</span> code=0;
+<a name="l00193"></a>00193     cpl_errorstate initial_errorstate = cpl_errorstate_get();
+<a name="l00194"></a>00194 
+<a name="l00195"></a>00195     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00196"></a>00196     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00197"></a>00197         recipe = (cpl_recipe *)plugin ;
+<a name="l00198"></a>00198     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00199"></a>00199       sinfo_msg(<span class="stringliteral">"Welcome to SINFONI Pipeline release %d.%d.%d"</span>,
+<a name="l00200"></a>00200         SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
+<a name="l00201"></a>00201 
+<a name="l00202"></a>00202     code = sinfo_utl_cube_arith(recipe->parameters, recipe->frames) ;
+<a name="l00203"></a>00203 
+<a name="l00204"></a>00204     <span class="keywordflow">if</span> (!cpl_errorstate_is_equal(initial_errorstate)) {                      
+<a name="l00205"></a>00205         <span class="comment">/* Dump the error history since recipe execution start.                </span>
+<a name="l00206"></a>00206 <span class="comment">           At this point the recipe cannot recover from the error */</span>           
+<a name="l00207"></a>00207         cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);              
+<a name="l00208"></a>00208     } 
+<a name="l00209"></a>00209     <span class="keywordflow">return</span> code;
+<a name="l00210"></a>00210 }
+<a name="l00211"></a>00211 
+<a name="l00212"></a>00212 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00218"></a>00218 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00219"></a>00219 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_cube_arith_destroy(cpl_plugin * plugin)
+<a name="l00220"></a>00220 {
+<a name="l00221"></a>00221     cpl_recipe  *   recipe ;
+<a name="l00222"></a>00222 
+<a name="l00223"></a>00223     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00224"></a>00224     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00225"></a>00225         recipe = (cpl_recipe *)plugin ;
+<a name="l00226"></a>00226     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00227"></a>00227 
+<a name="l00228"></a>00228     cpl_parameterlist_delete(recipe->parameters) ; 
+<a name="l00229"></a>00229     <span class="keywordflow">return</span> 0 ;
+<a name="l00230"></a>00230 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/recipes_2sinfo__utl__cube__combine_8c_source.html b/html/recipes_2sinfo__utl__cube__combine_8c_source.html
new file mode 100644
index 0000000..de2d6af
--- /dev/null
+++ b/html/recipes_2sinfo__utl__cube__combine_8c_source.html
@@ -0,0 +1,234 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_utl_cube_combine.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_utl_cube_combine.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_utl_cube_combine.c,v 1.12 2007/10/26 09:40:28 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the SINFONI Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2007/10/26 09:40:28 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.12 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span>
+<a name="l00032"></a>00032 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                                Includes</span>
+<a name="l00034"></a>00034 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 
+<a name="l00036"></a>00036 <span class="comment">/* cpl */</span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00038"></a>00038 
+<a name="l00039"></a>00039 <span class="comment">/* irplib */</span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include <irplib_utils.h></span>
+<a name="l00041"></a>00041 
+<a name="l00042"></a>00042 <span class="preprocessor">#include <sinfo_tpl_utils.h></span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include <sinfo_pfits.h></span>
+<a name="l00044"></a>00044 <span class="preprocessor">#include <sinfo_tpl_dfs.h></span>
+<a name="l00045"></a>00045 <span class="preprocessor">#include <sinfo_msg.h></span>
+<a name="l00046"></a>00046 <span class="preprocessor">#include <sinfo_utl_cube_combine.h></span>
+<a name="l00047"></a>00047 
+<a name="l00048"></a>00048 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00049"></a>00049 <span class="comment">                            Functions prototypes</span>
+<a name="l00050"></a>00050 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00051"></a>00051 
+<a name="l00052"></a>00052 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_cube_combine_create(cpl_plugin *) ;
+<a name="l00053"></a>00053 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_cube_combine_exec(cpl_plugin *) ;
+<a name="l00054"></a>00054 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_cube_combine_destroy(cpl_plugin *) ;
+<a name="l00055"></a>00055 
+<a name="l00056"></a>00056 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00057"></a>00057 <span class="comment">                            Static variables</span>
+<a name="l00058"></a>00058 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00059"></a>00059 
+<a name="l00060"></a>00060 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_utl_cube_combine_description[] =
+<a name="l00061"></a>00061 <span class="stringliteral">"This recipe perform cubes combination.\n"</span>
+<a name="l00062"></a>00062 <span class="stringliteral">"The input files are several cubeses\n"</span>
+<a name="l00063"></a>00063 <span class="stringliteral">"their associated tags should be the same that is supported by the \n"</span>
+<a name="l00064"></a>00064 <span class="stringliteral">"recipe sinfo_rec_jitter: OBS_OBJ, OBS_STD, OBS_PSF.\n"</span>
+<a name="l00065"></a>00065 <span class="stringliteral">"The output is a cube PRO_CUBE resulting from the input cubes accurding \n"</span>
+<a name="l00066"></a>00066 <span class="stringliteral">"to the value of op, where op indicates\n"</span>
+<a name="l00067"></a>00067 <span class="stringliteral">"the operation to be performed specified by the parameter \n"</span>
+<a name="l00068"></a>00068 <span class="stringliteral">"sinfoni.sinfo_utl_cube_combine.op\n"</span>
+<a name="l00069"></a>00069 <span class="stringliteral">" having alias 'op'\n"</span>
+<a name="l00070"></a>00070 <span class="stringliteral">"Information on relevant parameters can be found with\n"</span>
+<a name="l00071"></a>00071 <span class="stringliteral">"esorex --params sinfo_utl_cube_combine\n"</span>
+<a name="l00072"></a>00072 <span class="stringliteral">"esorex --help sinfo_utl_cube_combine\n"</span>
+<a name="l00073"></a>00073 <span class="stringliteral">"\n"</span>;
+<a name="l00074"></a>00074 
+<a name="l00075"></a>00075 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00076"></a>00076 <span class="comment">                                Functions code</span>
+<a name="l00077"></a>00077 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00078"></a>00078 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00082"></a>00082 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00083"></a>00083 
+<a name="l00085"></a>00085 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00093"></a>00093 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00094"></a><a class="code" href="group__sinfo__utl__cube__combine.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693">00094</a> <span class="keywordtype">int</span> <a class="code" href="group__sinfo__rec__detlin.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693" title="Build the list of available plugins, for this module.">cpl_plugin_get_info</a>(cpl_pluginlist * list)
+<a name="l00095"></a>00095 {
+<a name="l00096"></a>00096     cpl_recipe  *   recipe = cpl_calloc(1, <span class="keyword">sizeof</span> *recipe ) ;
+<a name="l00097"></a>00097     cpl_plugin  *   plugin = &recipe->interface ;
+<a name="l00098"></a>00098 
+<a name="l00099"></a>00099     cpl_plugin_init(plugin,
+<a name="l00100"></a>00100                     CPL_PLUGIN_API,
+<a name="l00101"></a>00101                     SINFONI_BINARY_VERSION,
+<a name="l00102"></a>00102                     CPL_PLUGIN_TYPE_RECIPE,
+<a name="l00103"></a>00103                     <span class="stringliteral">"sinfo_utl_cube_combine"</span>,
+<a name="l00104"></a>00104                     <span class="stringliteral">"Coadd cubes in an output cube according "</span>
+<a name="l00105"></a>00105                     <span class="stringliteral">"to user defined offsets"</span>,
+<a name="l00106"></a>00106                     sinfo_utl_cube_combine_description,
+<a name="l00107"></a>00107                     <span class="stringliteral">"Andrea Modigliani"</span>,
+<a name="l00108"></a>00108                     <span class="stringliteral">"Andrea.Modigliani at eso.org"</span>,
+<a name="l00109"></a>00109                     sinfo_get_license(),
+<a name="l00110"></a>00110                     sinfo_utl_cube_combine_create,
+<a name="l00111"></a>00111                     sinfo_utl_cube_combine_exec,
+<a name="l00112"></a>00112                     sinfo_utl_cube_combine_destroy) ;
+<a name="l00113"></a>00113 
+<a name="l00114"></a>00114     cpl_pluginlist_append(list, plugin) ;
+<a name="l00115"></a>00115     
+<a name="l00116"></a>00116     <span class="keywordflow">return</span> 0;
+<a name="l00117"></a>00117 }
+<a name="l00118"></a>00118 
+<a name="l00119"></a>00119 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00128"></a>00128 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00129"></a>00129 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_cube_combine_create(cpl_plugin * plugin)
+<a name="l00130"></a>00130 {
+<a name="l00131"></a>00131     cpl_recipe      * recipe ;
+<a name="l00132"></a>00132     cpl_parameter   * p ;
+<a name="l00133"></a>00133 
+<a name="l00134"></a>00134     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00135"></a>00135     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00136"></a>00136         recipe = (cpl_recipe *)plugin ;
+<a name="l00137"></a>00137     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00138"></a>00138     cpl_error_reset();
+<a name="l00139"></a>00139     <a class="code" href="group__irplib__utils.html#gaf9d392144014e2363054bc3f83c8e47e" title="Reset IRPLIB state.">irplib_reset</a>();
+<a name="l00140"></a>00140 
+<a name="l00141"></a>00141     <span class="comment">/* Create the parameters list in the cpl_recipe object */</span>
+<a name="l00142"></a>00142     recipe->parameters = cpl_parameterlist_new() ; 
+<a name="l00143"></a>00143 
+<a name="l00144"></a>00144     <span class="comment">/* Fill the parameters list */</span>
+<a name="l00145"></a>00145     <span class="comment">/* --stropt */</span>
+<a name="l00146"></a>00146     p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.sinfo_utl_cube_combine.name_i"</span>, 
+<a name="l00147"></a>00147             CPL_TYPE_STRING, 
+<a name="l00148"></a>00148          <span class="stringliteral">"Input filename. This must be provided and allow the user to set X "</span>
+<a name="l00149"></a>00149          <span class="stringliteral">"and Y cumulative offsets in a two column format"</span>, 
+<a name="l00150"></a>00150          <span class="stringliteral">"sinfoni.sinfo_utl_cube_combine"</span>,<span class="stringliteral">"offset.list"</span>);
+<a name="l00151"></a>00151     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"name_i"</span>) ;
+<a name="l00152"></a>00152     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00153"></a>00153 
+<a name="l00154"></a>00154     p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.sinfo_utl_cube_combine.name_o"</span>, 
+<a name="l00155"></a>00155             CPL_TYPE_STRING, <span class="stringliteral">"Output filename"</span>, 
+<a name="l00156"></a>00156              <span class="stringliteral">"sinfoni.sinfo_utl_cube_combine"</span>,<span class="stringliteral">"out_coadd_cube.fits"</span>);
+<a name="l00157"></a>00157     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"name_o"</span>) ;
+<a name="l00158"></a>00158     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00159"></a>00159 
+<a name="l00160"></a>00160 
+<a name="l00161"></a>00161     p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.sinfo_utl_cube_combine.ks_clip"</span>, 
+<a name="l00162"></a>00162             CPL_TYPE_BOOL, <span class="stringliteral">"Kappa sigma clipping"</span>, 
+<a name="l00163"></a>00163             <span class="stringliteral">"sinfoni.sinfo_utl_cube_combine"</span>,FALSE);
+<a name="l00164"></a>00164     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"ks_clip"</span>) ;
+<a name="l00165"></a>00165     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00166"></a>00166 
+<a name="l00167"></a>00167     p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.sinfo_utl_cube_combine.scale_sky"</span>, 
+<a name="l00168"></a>00168             CPL_TYPE_BOOL, <span class="stringliteral">"Scale spatial mean"</span>, 
+<a name="l00169"></a>00169             <span class="stringliteral">"sinfoni.sinfo_utl_cube_combine"</span>,FALSE);
+<a name="l00170"></a>00170     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"scale_sky"</span>) ;
+<a name="l00171"></a>00171     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00172"></a>00172 
+<a name="l00173"></a>00173     p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.sinfo_utl_cube_combine.kappa"</span>, 
+<a name="l00174"></a>00174             CPL_TYPE_DOUBLE, <span class="stringliteral">"Kappa value for sigma clip"</span>, 
+<a name="l00175"></a>00175             <span class="stringliteral">"sinfoni.sinfo_utl_cube_combine"</span>,2.);
+<a name="l00176"></a>00176     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"kappa"</span>) ;
+<a name="l00177"></a>00177     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00178"></a>00178 
+<a name="l00179"></a>00179 
+<a name="l00180"></a>00180     <span class="comment">/* --doubleopt */</span>
+<a name="l00181"></a>00181     p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.sinfo_utl_cube_combine.xsize"</span>, 
+<a name="l00182"></a>00182             CPL_TYPE_INT, <span class="stringliteral">"Output cube X size"</span>, 
+<a name="l00183"></a>00183             <span class="stringliteral">"sinfoni.sinfo_utl_cube_combine"</span>, 80) ;
+<a name="l00184"></a>00184     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"xsize"</span>) ;
+<a name="l00185"></a>00185     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00186"></a>00186 
+<a name="l00187"></a>00187 
+<a name="l00188"></a>00188     p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.sinfo_utl_cube_combine.ysize"</span>, 
+<a name="l00189"></a>00189             CPL_TYPE_INT, <span class="stringliteral">"Output cube Y size"</span>, 
+<a name="l00190"></a>00190             <span class="stringliteral">"sinfoni.sinfo_utl_cube_combine"</span>, 80) ;
+<a name="l00191"></a>00191     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"ysize"</span>) ;
+<a name="l00192"></a>00192     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00193"></a>00193 
+<a name="l00194"></a>00194   
+<a name="l00195"></a>00195     <span class="comment">/* Return */</span>
+<a name="l00196"></a>00196     <span class="keywordflow">return</span> 0;
+<a name="l00197"></a>00197 }
+<a name="l00198"></a>00198 
+<a name="l00199"></a>00199 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00205"></a>00205 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00206"></a>00206 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_cube_combine_exec(cpl_plugin * plugin)
+<a name="l00207"></a>00207 {
+<a name="l00208"></a>00208     cpl_recipe  *   recipe ;
+<a name="l00209"></a>00209     <span class="keywordtype">int</span> result=0;    
+<a name="l00210"></a>00210     cpl_errorstate initial_errorstate = cpl_errorstate_get();
+<a name="l00211"></a>00211 
+<a name="l00212"></a>00212     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00213"></a>00213     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00214"></a>00214         recipe = (cpl_recipe *)plugin ;
+<a name="l00215"></a>00215     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00216"></a>00216        sinfo_msg(<span class="stringliteral">"Welcome to SINFONI Pipeline release %d.%d.%d"</span>,
+<a name="l00217"></a>00217         SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
+<a name="l00218"></a>00218 
+<a name="l00219"></a>00219     result=sinfo_utl_cube_combine(recipe->parameters, recipe->frames) ;
+<a name="l00220"></a>00220     <span class="keywordflow">if</span> (!cpl_errorstate_is_equal(initial_errorstate)) {                      
+<a name="l00221"></a>00221         <span class="comment">/* Dump the error history since recipe execution start.                </span>
+<a name="l00222"></a>00222 <span class="comment">           At this point the recipe cannot recover from the error */</span>           
+<a name="l00223"></a>00223         cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);              
+<a name="l00224"></a>00224     } 
+<a name="l00225"></a>00225     <span class="keywordflow">return</span> result;
+<a name="l00226"></a>00226 }
+<a name="l00227"></a>00227 
+<a name="l00228"></a>00228 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00234"></a>00234 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00235"></a>00235 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_cube_combine_destroy(cpl_plugin * plugin)
+<a name="l00236"></a>00236 {
+<a name="l00237"></a>00237     cpl_recipe  *   recipe ;
+<a name="l00238"></a>00238     
+<a name="l00239"></a>00239     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00240"></a>00240     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00241"></a>00241         recipe = (cpl_recipe *)plugin ;
+<a name="l00242"></a>00242     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00243"></a>00243 
+<a name="l00244"></a>00244     cpl_parameterlist_delete(recipe->parameters) ; 
+<a name="l00245"></a>00245     <span class="keywordflow">return</span> 0 ;
+<a name="l00246"></a>00246 }
+<a name="l00247"></a>00247 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/recipes_2sinfo__utl__spectrum__divide__by__blackbody_8c_source.html b/html/recipes_2sinfo__utl__spectrum__divide__by__blackbody_8c_source.html
new file mode 100644
index 0000000..e76cd9b
--- /dev/null
+++ b/html/recipes_2sinfo__utl__spectrum__divide__by__blackbody_8c_source.html
@@ -0,0 +1,192 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_utl_spectrum_divide_by_blackbody.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_utl_spectrum_divide_by_blackbody.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_utl_spectrum_divide_by_blackbody.c,v 1.10 2007/10/26 09:40:28 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the SINFONI Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2007/10/26 09:40:28 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.10 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span>
+<a name="l00032"></a>00032 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                                Includes</span>
+<a name="l00034"></a>00034 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 
+<a name="l00036"></a>00036 <span class="comment">/* cpl */</span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00038"></a>00038  
+<a name="l00039"></a>00039 <span class="comment">/* irplib */</span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include <irplib_utils.h></span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include <string.h></span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include <sinfo_tpl_utils.h></span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include <sinfo_pfits.h></span>
+<a name="l00044"></a>00044 <span class="preprocessor">#include <sinfo_tpl_dfs.h></span>
+<a name="l00045"></a>00045 <span class="preprocessor">#include <sinfo_msg.h></span>
+<a name="l00046"></a>00046 <span class="preprocessor">#include <sinfo_utl_spectrum_divide_by_blackbody.h></span>
+<a name="l00047"></a>00047 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00048"></a>00048 <span class="comment">                            Functions prototypes</span>
+<a name="l00049"></a>00049 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00050"></a>00050 
+<a name="l00051"></a>00051 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_spectrum_divide_by_blackbody_create(cpl_plugin *) ;
+<a name="l00052"></a>00052 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_spectrum_divide_by_blackbody_exec(cpl_plugin *) ;
+<a name="l00053"></a>00053 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_spectrum_divide_by_blackbody_destroy(cpl_plugin *) ;
+<a name="l00054"></a>00054 
+<a name="l00055"></a>00055 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00056"></a>00056 <span class="comment">                            Static variables</span>
+<a name="l00057"></a>00057 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00058"></a>00058 
+<a name="l00059"></a>00059 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_utl_spectrum_divide_by_blackbody_description1[] =
+<a name="l00060"></a>00060 <span class="stringliteral">"This recipe divides a spectrum by a black body "</span>
+<a name="l00061"></a>00061 <span class="stringliteral">"spectrum of given temperature.\n"</span>
+<a name="l00062"></a>00062 <span class="stringliteral">"The input file is a spectrum. Its associated tag must be SPECTRUM.\n"</span>
+<a name="l00063"></a>00063 <span class="stringliteral">"The output is a spectrum\n"</span>;
+<a name="l00064"></a>00064 
+<a name="l00065"></a>00065 
+<a name="l00066"></a>00066 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_utl_spectrum_divide_by_blackbody_description2[] =
+<a name="l00067"></a>00067 <span class="stringliteral">"Parameter is \n"</span>
+<a name="l00068"></a>00068 <span class="stringliteral">"sinfoni.sinfo_utl_spectrum_divide_by_blackbody.temperature\n"</span>
+<a name="l00069"></a>00069 <span class="stringliteral">"having aliases 'temp' \n"</span>
+<a name="l00070"></a>00070 <span class="stringliteral">"Information on relevant parameters can be found with\n"</span>
+<a name="l00071"></a>00071 <span class="stringliteral">"esorex --params sinfo_utl_spectrum_divide_by_blackbody\n"</span>
+<a name="l00072"></a>00072 <span class="stringliteral">"esorex --help sinfo_utl_spectrum_divide_by_blackbody\n"</span>
+<a name="l00073"></a>00073 <span class="stringliteral">"\n"</span>;
+<a name="l00074"></a>00074 
+<a name="l00075"></a>00075 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_utl_spectrum_divide_by_blackbody_description[900];
+<a name="l00076"></a>00076 
+<a name="l00077"></a>00077 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00078"></a>00078 <span class="comment">                                Functions code</span>
+<a name="l00079"></a>00079 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00080"></a>00080 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00085"></a>00085 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00088"></a>00088 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00096"></a>00096 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00097"></a><a class="code" href="group__sinfo__utl__spectrum__divide__by__blackbody.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693">00097</a> <span class="keywordtype">int</span> <a class="code" href="group__sinfo__rec__detlin.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693" title="Build the list of available plugins, for this module.">cpl_plugin_get_info</a>(cpl_pluginlist * list)
+<a name="l00098"></a>00098 {
+<a name="l00099"></a>00099     cpl_recipe  *   recipe = cpl_calloc(1, <span class="keyword">sizeof</span> *recipe ) ;
+<a name="l00100"></a>00100     cpl_plugin  *   plugin = &recipe->interface ;
+<a name="l00101"></a>00101 
+<a name="l00102"></a>00102     strcpy(sinfo_utl_spectrum_divide_by_blackbody_description,
+<a name="l00103"></a>00103            sinfo_utl_spectrum_divide_by_blackbody_description1);
+<a name="l00104"></a>00104     strcat(sinfo_utl_spectrum_divide_by_blackbody_description,
+<a name="l00105"></a>00105            sinfo_utl_spectrum_divide_by_blackbody_description2);
+<a name="l00106"></a>00106 
+<a name="l00107"></a>00107     cpl_plugin_init(plugin,
+<a name="l00108"></a>00108                     CPL_PLUGIN_API,
+<a name="l00109"></a>00109                     SINFONI_BINARY_VERSION,
+<a name="l00110"></a>00110                     CPL_PLUGIN_TYPE_RECIPE,
+<a name="l00111"></a>00111                     <span class="stringliteral">"sinfo_utl_spectrum_divide_by_blackbody"</span>,
+<a name="l00112"></a>00112                     <span class="stringliteral">"Spectrum normalization by a blackbody"</span>,
+<a name="l00113"></a>00113                     sinfo_utl_spectrum_divide_by_blackbody_description,
+<a name="l00114"></a>00114                     <span class="stringliteral">"Andrea Modigliani"</span>,
+<a name="l00115"></a>00115                     <span class="stringliteral">"Andrea.Modigliani at eso.org"</span>,
+<a name="l00116"></a>00116                     sinfo_get_license(),
+<a name="l00117"></a>00117                     sinfo_utl_spectrum_divide_by_blackbody_create,
+<a name="l00118"></a>00118                     sinfo_utl_spectrum_divide_by_blackbody_exec,
+<a name="l00119"></a>00119                     sinfo_utl_spectrum_divide_by_blackbody_destroy) ;
+<a name="l00120"></a>00120 
+<a name="l00121"></a>00121     cpl_pluginlist_append(list, plugin) ;
+<a name="l00122"></a>00122     
+<a name="l00123"></a>00123     <span class="keywordflow">return</span> 0;
+<a name="l00124"></a>00124 }
+<a name="l00125"></a>00125 
+<a name="l00126"></a>00126 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00135"></a>00135 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00136"></a>00136 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_spectrum_divide_by_blackbody_create(cpl_plugin * plugin)
+<a name="l00137"></a>00137 {
+<a name="l00138"></a>00138     cpl_recipe      * recipe ;
+<a name="l00139"></a>00139     cpl_parameter   * p ;
+<a name="l00140"></a>00140 
+<a name="l00141"></a>00141     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00142"></a>00142     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00143"></a>00143         recipe = (cpl_recipe *)plugin ;
+<a name="l00144"></a>00144     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00145"></a>00145 
+<a name="l00146"></a>00146     cpl_error_reset();
+<a name="l00147"></a>00147     <a class="code" href="group__irplib__utils.html#gaf9d392144014e2363054bc3f83c8e47e" title="Reset IRPLIB state.">irplib_reset</a>();
+<a name="l00148"></a>00148     <span class="comment">/* Create the parameters list in the cpl_recipe object */</span>
+<a name="l00149"></a>00149     recipe->parameters = cpl_parameterlist_new() ; 
+<a name="l00150"></a>00150 
+<a name="l00151"></a>00151     <span class="comment">/* Fill the parameters list */</span>
+<a name="l00152"></a>00152     <span class="comment">/* --stropt */</span>
+<a name="l00153"></a>00153     <span class="comment">/* --doubleopt */</span>
+<a name="l00154"></a>00154     p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.sinfo_utl_spectrum_divide_by_blackbody.temperature"</span>, 
+<a name="l00155"></a>00155             CPL_TYPE_DOUBLE, <span class="stringliteral">"Black Body Temperature"</span>, 
+<a name="l00156"></a>00156             <span class="stringliteral">"sinfoni.sinfo_utl_spectrum_divide_by_blackbody"</span>, 100000.) ;
+<a name="l00157"></a>00157     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"temp"</span>) ;
+<a name="l00158"></a>00158     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00159"></a>00159 
+<a name="l00160"></a>00160     <span class="comment">/* Return */</span>
+<a name="l00161"></a>00161     <span class="keywordflow">return</span> 0;
+<a name="l00162"></a>00162 }
+<a name="l00163"></a>00163 
+<a name="l00164"></a>00164 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00170"></a>00170 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00171"></a>00171 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_spectrum_divide_by_blackbody_exec(cpl_plugin * plugin)
+<a name="l00172"></a>00172 {
+<a name="l00173"></a>00173     cpl_recipe  *   recipe ;
+<a name="l00174"></a>00174     <span class="keywordtype">int</span> code=0;
+<a name="l00175"></a>00175 
+<a name="l00176"></a>00176     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00177"></a>00177     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00178"></a>00178         recipe = (cpl_recipe *)plugin ;
+<a name="l00179"></a>00179     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00180"></a>00180  
+<a name="l00181"></a>00181        sinfo_msg(<span class="stringliteral">"Welcome to SINFONI Pipeline release %d.%d.%d"</span>,
+<a name="l00182"></a>00182         SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
+<a name="l00183"></a>00183     code=sinfo_utl_spectrum_divide_by_blackbody(recipe->parameters, 
+<a name="l00184"></a>00184                                                   recipe->frames) ;
+<a name="l00185"></a>00185     <span class="keywordflow">return</span> code;
+<a name="l00186"></a>00186 }
+<a name="l00187"></a>00187 
+<a name="l00188"></a>00188 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00194"></a>00194 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00195"></a>00195 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_spectrum_divide_by_blackbody_destroy(cpl_plugin * plugin)
+<a name="l00196"></a>00196 {
+<a name="l00197"></a>00197     cpl_recipe  *   recipe ;
+<a name="l00198"></a>00198     
+<a name="l00199"></a>00199     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00200"></a>00200     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00201"></a>00201         recipe = (cpl_recipe *)plugin ;
+<a name="l00202"></a>00202     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00203"></a>00203 
+<a name="l00204"></a>00204     cpl_parameterlist_delete(recipe->parameters) ; 
+<a name="l00205"></a>00205     <span class="keywordflow">return</span> 0 ;
+<a name="l00206"></a>00206 }
+<a name="l00207"></a>00207 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/recipes_2sinfo__utl__spectrum__wavelength__shift_8c_source.html b/html/recipes_2sinfo__utl__spectrum__wavelength__shift_8c_source.html
new file mode 100644
index 0000000..590da74
--- /dev/null
+++ b/html/recipes_2sinfo__utl__spectrum__wavelength__shift_8c_source.html
@@ -0,0 +1,207 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_utl_spectrum_wavelength_shift.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_utl_spectrum_wavelength_shift.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_utl_spectrum_wavelength_shift.c,v 1.11 2007/10/26 09:40:28 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the SINFONI Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2007/10/26 09:40:28 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.11 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span>
+<a name="l00032"></a>00032 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                                Includes</span>
+<a name="l00034"></a>00034 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 <span class="preprocessor">#include <string.h></span>
+<a name="l00036"></a>00036 <span class="comment">/* irplib */</span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00038"></a>00038  
+<a name="l00039"></a>00039 <span class="comment">/* irplib */</span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include <irplib_utils.h></span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include <sinfo_msg.h></span>
+<a name="l00042"></a>00042 
+<a name="l00043"></a>00043 <span class="preprocessor">#include <sinfo_tpl_utils.h></span>
+<a name="l00044"></a>00044 <span class="preprocessor">#include <sinfo_pfits.h></span>
+<a name="l00045"></a>00045 <span class="preprocessor">#include <sinfo_tpl_dfs.h></span>
+<a name="l00046"></a>00046 <span class="preprocessor">#include <sinfo_utl_spectrum_wavelength_shift.h></span>
+<a name="l00047"></a>00047 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00048"></a>00048 <span class="comment">                            Functions prototypes</span>
+<a name="l00049"></a>00049 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00050"></a>00050 
+<a name="l00051"></a>00051 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_spectrum_wavelength_shift_create(cpl_plugin *) ;
+<a name="l00052"></a>00052 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_spectrum_wavelength_shift_exec(cpl_plugin *) ;
+<a name="l00053"></a>00053 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_spectrum_wavelength_shift_destroy(cpl_plugin *) ;
+<a name="l00054"></a>00054 
+<a name="l00055"></a>00055 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00056"></a>00056 <span class="comment">                            Static variables</span>
+<a name="l00057"></a>00057 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00058"></a>00058 
+<a name="l00059"></a>00059 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_utl_spectrum_wavelength_shift_description1[] =
+<a name="l00060"></a>00060 <span class="stringliteral">"This recipe shifts a spectrum in wavelength using a given \n"</span>
+<a name="l00061"></a>00061 <span class="stringliteral">"interpolation method. The input file is a spectrum.\n"</span>
+<a name="l00062"></a>00062 <span class="stringliteral">"Its associated tag should be SPECTRUM.\n"</span>
+<a name="l00063"></a>00063 <span class="stringliteral">"The output is a spectrum shifted by a given amount. \n"</span>;
+<a name="l00064"></a>00064 
+<a name="l00065"></a>00065 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_utl_spectrum_wavelength_shift_description2[] =
+<a name="l00066"></a>00066 <span class="stringliteral">"Parameters are \n"</span>
+<a name="l00067"></a>00067 <span class="stringliteral">"sinfoni.sinfo_utl_spectrum_arith.method\n"</span>
+<a name="l00068"></a>00068 <span class="stringliteral">"sinfoni.sinfo_utl_spectrum_wavelength_shift.shift\n"</span>
+<a name="l00069"></a>00069 <span class="stringliteral">"having aliases 'method' and 'shift' \n"</span>
+<a name="l00070"></a>00070 <span class="stringliteral">"Information on relevant parameters can be found with\n"</span>
+<a name="l00071"></a>00071 <span class="stringliteral">"esorex --params sinfo_utl_spectrum_wavelength_shift\n"</span>
+<a name="l00072"></a>00072 <span class="stringliteral">"esorex --help sinfo_utl_spectrum_wavelength_shift\n"</span>
+<a name="l00073"></a>00073 <span class="stringliteral">"\n"</span>;
+<a name="l00074"></a>00074 
+<a name="l00075"></a>00075 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_utl_spectrum_wavelength_shift_description[900];
+<a name="l00076"></a>00076 
+<a name="l00077"></a>00077 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00078"></a>00078 <span class="comment">                                Functions code</span>
+<a name="l00079"></a>00079 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00080"></a>00080 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00085"></a>00085 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00088"></a>00088 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00096"></a>00096 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00097"></a><a class="code" href="group__sinfo__utl__spectrum__wavelength__shift.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693">00097</a> <span class="keywordtype">int</span> <a class="code" href="group__sinfo__rec__detlin.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693" title="Build the list of available plugins, for this module.">cpl_plugin_get_info</a>(cpl_pluginlist * list)
+<a name="l00098"></a>00098 {
+<a name="l00099"></a>00099     cpl_recipe  *   recipe = cpl_calloc(1, <span class="keyword">sizeof</span> *recipe ) ;
+<a name="l00100"></a>00100     cpl_plugin  *   plugin = &recipe->interface ;
+<a name="l00101"></a>00101 
+<a name="l00102"></a>00102     strcpy(sinfo_utl_spectrum_wavelength_shift_description,
+<a name="l00103"></a>00103            sinfo_utl_spectrum_wavelength_shift_description1);
+<a name="l00104"></a>00104     strcat(sinfo_utl_spectrum_wavelength_shift_description,
+<a name="l00105"></a>00105            sinfo_utl_spectrum_wavelength_shift_description2);
+<a name="l00106"></a>00106 
+<a name="l00107"></a>00107     cpl_plugin_init(plugin,
+<a name="l00108"></a>00108                     CPL_PLUGIN_API,
+<a name="l00109"></a>00109                     SINFONI_BINARY_VERSION,
+<a name="l00110"></a>00110                     CPL_PLUGIN_TYPE_RECIPE,
+<a name="l00111"></a>00111                     <span class="stringliteral">"sinfo_utl_spectrum_wavelength_shift"</span>,
+<a name="l00112"></a>00112                     <span class="stringliteral">"Spectrum wavelength shift"</span>,
+<a name="l00113"></a>00113                     sinfo_utl_spectrum_wavelength_shift_description,
+<a name="l00114"></a>00114                     <span class="stringliteral">"Andrea Modigliani"</span>,
+<a name="l00115"></a>00115                     <span class="stringliteral">"Andrea.Modigliani at eso.org"</span>,
+<a name="l00116"></a>00116                     sinfo_get_license(),
+<a name="l00117"></a>00117                     sinfo_utl_spectrum_wavelength_shift_create,
+<a name="l00118"></a>00118                     sinfo_utl_spectrum_wavelength_shift_exec,
+<a name="l00119"></a>00119                     sinfo_utl_spectrum_wavelength_shift_destroy) ;
+<a name="l00120"></a>00120 
+<a name="l00121"></a>00121     cpl_pluginlist_append(list, plugin) ;
+<a name="l00122"></a>00122     
+<a name="l00123"></a>00123     <span class="keywordflow">return</span> 0;
+<a name="l00124"></a>00124 }
+<a name="l00125"></a>00125 
+<a name="l00126"></a>00126 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00135"></a>00135 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00136"></a>00136 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_spectrum_wavelength_shift_create(cpl_plugin * plugin)
+<a name="l00137"></a>00137 {
+<a name="l00138"></a>00138     cpl_recipe      * recipe ;
+<a name="l00139"></a>00139     cpl_parameter   * p ;
+<a name="l00140"></a>00140 
+<a name="l00141"></a>00141     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00142"></a>00142     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00143"></a>00143         recipe = (cpl_recipe *)plugin ;
+<a name="l00144"></a>00144     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00145"></a>00145     cpl_error_reset();
+<a name="l00146"></a>00146     <a class="code" href="group__irplib__utils.html#gaf9d392144014e2363054bc3f83c8e47e" title="Reset IRPLIB state.">irplib_reset</a>();
+<a name="l00147"></a>00147 
+<a name="l00148"></a>00148     <span class="comment">/* Create the parameters list in the cpl_recipe object */</span>
+<a name="l00149"></a>00149     recipe->parameters = cpl_parameterlist_new() ; 
+<a name="l00150"></a>00150 
+<a name="l00151"></a>00151     <span class="comment">/* Fill the parameters list */</span>
+<a name="l00152"></a>00152      <span class="comment">/* --stropt */</span>
+<a name="l00153"></a>00153     p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.sinfo_utl_spectrum_arith.method"</span>, 
+<a name="l00154"></a>00154                                 CPL_TYPE_STRING, 
+<a name="l00155"></a>00155                                 <span class="stringliteral">"A spectral shift method: "</span>
+<a name="l00156"></a>00156                                 <span class="stringliteral">"'S' (Spline),'P' (Polynomial)"</span>, 
+<a name="l00157"></a>00157                                 <span class="stringliteral">"sinfoni.sinfo_utl_spectrum_arith"</span>,<span class="stringliteral">"S"</span>);
+<a name="l00158"></a>00158     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"method"</span>) ;
+<a name="l00159"></a>00159     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00160"></a>00160 
+<a name="l00161"></a>00161     <span class="comment">/* --doubleopt */</span>
+<a name="l00162"></a>00162     p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.sinfo_utl_spectrum_wavelength_shift.shift"</span>, 
+<a name="l00163"></a>00163                                 CPL_TYPE_DOUBLE, 
+<a name="l00164"></a>00164                                 <span class="stringliteral">"wavelength shift in micron"</span>, 
+<a name="l00165"></a>00165                                 <span class="stringliteral">"sinfoni.sinfo_utl_spectrum_wavelength_shift"</span>, 
+<a name="l00166"></a>00166                                 0.1) ;
+<a name="l00167"></a>00167     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"shift"</span>) ;
+<a name="l00168"></a>00168     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00169"></a>00169 
+<a name="l00170"></a>00170     <span class="comment">/* Return */</span>
+<a name="l00171"></a>00171     <span class="keywordflow">return</span> 0;
+<a name="l00172"></a>00172 }
+<a name="l00173"></a>00173 
+<a name="l00174"></a>00174 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00180"></a>00180 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00181"></a>00181 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_spectrum_wavelength_shift_exec(cpl_plugin * plugin)
+<a name="l00182"></a>00182 {
+<a name="l00183"></a>00183     cpl_recipe  *   recipe ;
+<a name="l00184"></a>00184     <span class="keywordtype">int</span> code=0;
+<a name="l00185"></a>00185     cpl_errorstate initial_errorstate = cpl_errorstate_get();
+<a name="l00186"></a>00186 
+<a name="l00187"></a>00187     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00188"></a>00188     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00189"></a>00189         recipe = (cpl_recipe *)plugin ;
+<a name="l00190"></a>00190     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00191"></a>00191       sinfo_msg(<span class="stringliteral">"Welcome to SINFONI Pipeline release %d.%d.%d"</span>,
+<a name="l00192"></a>00192        SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
+<a name="l00193"></a>00193     code = sinfo_utl_spectrum_wavelength_shift(recipe->parameters, 
+<a name="l00194"></a>00194                                                recipe->frames) ;
+<a name="l00195"></a>00195     <span class="keywordflow">if</span> (!cpl_errorstate_is_equal(initial_errorstate)) {                      
+<a name="l00196"></a>00196         <span class="comment">/* Dump the error history since recipe execution start.                </span>
+<a name="l00197"></a>00197 <span class="comment">           At this point the recipe cannot recover from the error */</span>           
+<a name="l00198"></a>00198         cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);              
+<a name="l00199"></a>00199     } 
+<a name="l00200"></a>00200     <span class="keywordflow">return</span> code ;
+<a name="l00201"></a>00201 }
+<a name="l00202"></a>00202 
+<a name="l00203"></a>00203 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00209"></a>00209 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00210"></a>00210 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_spectrum_wavelength_shift_destroy(cpl_plugin * plugin)
+<a name="l00211"></a>00211 {
+<a name="l00212"></a>00212     cpl_recipe  *   recipe ;
+<a name="l00213"></a>00213     
+<a name="l00214"></a>00214     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00215"></a>00215     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00216"></a>00216         recipe = (cpl_recipe *)plugin ;
+<a name="l00217"></a>00217     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00218"></a>00218 
+<a name="l00219"></a>00219     cpl_parameterlist_delete(recipe->parameters) ; 
+<a name="l00220"></a>00220     <span class="keywordflow">return</span> 0 ;
+<a name="l00221"></a>00221 }
+<a name="l00222"></a>00222 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__absolute_8c_source.html b/html/sinfo__absolute_8c_source.html
new file mode 100644
index 0000000..345952a
--- /dev/null
+++ b/html/sinfo__absolute_8c_source.html
@@ -0,0 +1,3214 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_absolute.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_absolute.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*****************************************************************************</span>
+<a name="l00020"></a>00020 <span class="comment">* E.S.O. - VLT project</span>
+<a name="l00021"></a>00021 <span class="comment">*</span>
+<a name="l00022"></a>00022 <span class="comment">*</span>
+<a name="l00023"></a>00023 <span class="comment">*</span>
+<a name="l00024"></a>00024 <span class="comment">* who       when      what</span>
+<a name="l00025"></a>00025 <span class="comment">* --------  --------  ----------------------------------------------</span>
+<a name="l00026"></a>00026 <span class="comment">* schreib  14/11/00  created</span>
+<a name="l00027"></a>00027 <span class="comment">*/</span>
+<a name="l00029"></a>00029 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00034"></a>00034 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="comment">/************************************************************************</span>
+<a name="l00038"></a>00038 <span class="comment">*   NAME</span>
+<a name="l00039"></a>00039 <span class="comment">*        sinfo_absolute.c - routines to determine the absolute positions </span>
+<a name="l00040"></a>00040 <span class="comment">*        of the slitlets out of an emission line frame</span>
+<a name="l00041"></a>00041 <span class="comment">*</span>
+<a name="l00042"></a>00042 <span class="comment">*   SYNOPSIS</span>
+<a name="l00043"></a>00043 <span class="comment">*   #include "absolute.h"</span>
+<a name="l00044"></a>00044 <span class="comment">*</span>
+<a name="l00045"></a>00045 <span class="comment">*   1) float sinfo_new_edge( float * xdat, float * parlist, </span>
+<a name="l00046"></a>00046 <span class="comment">                             int * npar, int * ndat )</span>
+<a name="l00047"></a>00047 <span class="comment">*   2) void sinfo_new_edge_deriv( float * xdat, float * parlist, </span>
+<a name="l00048"></a>00048 <span class="comment">                                  float * dervs, int * npar )</span>
+<a name="l00049"></a>00049 <span class="comment">*   3) static int sinfo_new_inv_mat_edge (void)</span>
+<a name="l00050"></a>00050 <span class="comment">*   4) static new_void sinfo_get_mat_edge ( float * xdat,</span>
+<a name="l00051"></a>00051 <span class="comment">*                                 int   * xdim,</span>
+<a name="l00052"></a>00052 <span class="comment">*                                 float * ydat,</span>
+<a name="l00053"></a>00053 <span class="comment">*                                 float * wdat,</span>
+<a name="l00054"></a>00054 <span class="comment">*                                 int   * ndat,</span>
+<a name="l00055"></a>00055 <span class="comment">*                                 float * fpar,</span>
+<a name="l00056"></a>00056 <span class="comment">*                                 float * epar,</span>
+<a name="l00057"></a>00057 <span class="comment">*                                 int   * npar )</span>
+<a name="l00058"></a>00058 <span class="comment">*   5) static int sinfo_new_get_vec_edge ( float * xdat,</span>
+<a name="l00059"></a>00059 <span class="comment">*                                int   * xdim,</span>
+<a name="l00060"></a>00060 <span class="comment">*                                float * ydat,</span>
+<a name="l00061"></a>00061 <span class="comment">*                                float * wdat,</span>
+<a name="l00062"></a>00062 <span class="comment">*                                int   * ndat,</span>
+<a name="l00063"></a>00063 <span class="comment">*                                float * fpar,</span>
+<a name="l00064"></a>00064 <span class="comment">*                                float * epar,</span>
+<a name="l00065"></a>00065 <span class="comment">*                                int   * npar )</span>
+<a name="l00066"></a>00066 <span class="comment">*   6) int sinfo_new_lsqfit_edge ( float * xdat,</span>
+<a name="l00067"></a>00067 <span class="comment">*                        int   * xdim,</span>
+<a name="l00068"></a>00068 <span class="comment">*                        float * ydat,</span>
+<a name="l00069"></a>00069 <span class="comment">*                        float * wdat,</span>
+<a name="l00070"></a>00070 <span class="comment">*                        int   * ndat,</span>
+<a name="l00071"></a>00071 <span class="comment">*                        float * fpar,</span>
+<a name="l00072"></a>00072 <span class="comment">*                        float * epar,</span>
+<a name="l00073"></a>00073 <span class="comment">*                        int   * mpar,</span>
+<a name="l00074"></a>00074 <span class="comment">*                        int   * npar,</span>
+<a name="l00075"></a>00075 <span class="comment">*                        float * tol ,</span>
+<a name="l00076"></a>00076 <span class="comment">*                        int   * its ,</span>
+<a name="l00077"></a>00077 <span class="comment">*                        float * lab  )</span>
+<a name="l00078"></a>00078 <span class="comment">*   7) int sinfo_new_fit_slits_edge( cpl_image   * lineImage, </span>
+<a name="l00079"></a>00079 <span class="comment">*                        FitParams ** par,</span>
+<a name="l00080"></a>00080 <span class="comment">*                        float     ** sinfo_slit_pos,</span>
+<a name="l00081"></a>00081 <span class="comment">*                        int          box_length,</span>
+<a name="l00082"></a>00082 <span class="comment">*                        float        y_box,</span>
+<a name="l00083"></a>00083 <span class="comment">*                        float        diff_tol )</span>
+<a name="l00084"></a>00084 <span class="comment">*   8) int sinfo_new_fit_slits_edge_with_estimate ( cpl_image   * lineImage,</span>
+<a name="l00085"></a>00085 <span class="comment">*                                     float     ** sinfo_slit_pos,</span>
+<a name="l00086"></a>00086 <span class="comment">*                                     int          box_length,</span>
+<a name="l00087"></a>00087 <span class="comment">*                                     float        y_box,</span>
+<a name="l00088"></a>00088 <span class="comment">*                                     float        diff_tol,</span>
+<a name="l00089"></a>00089 <span class="comment">*                                     int          low_pos,</span>
+<a name="l00090"></a>00090 <span class="comment">*                                     int          high_pos )</span>
+<a name="l00091"></a>00091 <span class="comment">*</span>
+<a name="l00092"></a>00092 <span class="comment">*   DESCRIPTION</span>
+<a name="l00093"></a>00093 <span class="comment">*   1) calculates the value of a slope function with parameters </span>
+<a name="l00094"></a>00094 <span class="comment">*      parlist at the position xdat </span>
+<a name="l00095"></a>00095 <span class="comment">*   2) calculates the partial derivatives for a slope function with</span>
+<a name="l00096"></a>00096 <span class="comment">*      parameters parlist at position xdat </span>
+<a name="l00097"></a>00097 <span class="comment">*   3) calculates the inverse of matrix2. The algorithm used </span>
+<a name="l00098"></a>00098 <span class="comment">*      is the Gauss-Jordan algorithm described in Stoer,</span>
+<a name="l00099"></a>00099 <span class="comment">*      Numerische Mathematik, 1. Teil.</span>
+<a name="l00100"></a>00100 <span class="comment">*   4) builds the sinfo_matrix </span>
+<a name="l00101"></a>00101 <span class="comment">*   5) calculates the correction sinfo_vector. The sinfo_matrix has been</span>
+<a name="l00102"></a>00102 <span class="comment">*      built by get_mat_edge(), we only have to rescale it for the </span>
+<a name="l00103"></a>00103 <span class="comment">*      current value of labda. The sinfo_matrix is rescaled so that</span>
+<a name="l00104"></a>00104 <span class="comment">*      the diagonal gets the value 1 + labda.</span>
+<a name="l00105"></a>00105 <span class="comment">*      Next we calculate the inverse of the sinfo_matrix and then</span>
+<a name="l00106"></a>00106 <span class="comment">*      the correction sinfo_vector.</span>
+<a name="l00107"></a>00107 <span class="comment">*   6) this is a routine for making a least-squares fit of a</span>
+<a name="l00108"></a>00108 <span class="comment">*      function to a set of data points. The method used is</span>
+<a name="l00109"></a>00109 <span class="comment">*      described in: Marquardt, J.Soc.Ind.Appl.Math. 11. 431 (1963).</span>
+<a name="l00110"></a>00110 <span class="comment">*      This method is a mixture of the steepest descent method </span>
+<a name="l00111"></a>00111 <span class="comment">*      and the Taylor method.</span>
+<a name="l00112"></a>00112 <span class="comment">*   7) fits the beginning and end position of the slitlets</span>
+<a name="l00113"></a>00113 <span class="comment">*      by using non-linear least square fitting of a step function</span>
+<a name="l00114"></a>00114 <span class="comment">*      fits a step function to the slitlet edges exposed and indicated</span>
+<a name="l00115"></a>00115 <span class="comment">*      by the brightest emission lines. To achieve this, the fit</span>
+<a name="l00116"></a>00116 <span class="comment">*      parameters are used to find the brightest emission line</span>
+<a name="l00117"></a>00117 <span class="comment">*      and to get its position for each column.</span>
+<a name="l00118"></a>00118 <span class="comment">*      The least squares fit is done by using a box smaller than</span>
+<a name="l00119"></a>00119 <span class="comment">*      the size of two slitlets</span>
+<a name="l00120"></a>00120 <span class="comment">*   8) fits the beginning and end position of the slitlets</span>
+<a name="l00121"></a>00121 <span class="comment">*      by using non-linear least square fitting of an sinfo_edge  function</span>
+<a name="l00122"></a>00122 <span class="comment">*      fits a linear edge function to the slitlet edges exposed and indicated</span>
+<a name="l00123"></a>00123 <span class="comment">*      by the brightest emission lines. The slitlet is searched within</span>
+<a name="l00124"></a>00124 <span class="comment">*      user given positions.</span>
+<a name="l00125"></a>00125 <span class="comment">*      The least squares fit is done by using a box smaller than</span>
+<a name="l00126"></a>00126 <span class="comment">*      the size of two slitlets </span>
+<a name="l00127"></a>00127 <span class="comment">*</span>
+<a name="l00128"></a>00128 <span class="comment">*   FILES</span>
+<a name="l00129"></a>00129 <span class="comment">*</span>
+<a name="l00130"></a>00130 <span class="comment">*   ENVIRONMENT</span>
+<a name="l00131"></a>00131 <span class="comment">*</span>
+<a name="l00132"></a>00132 <span class="comment">*   RETURN VALUES</span>
+<a name="l00133"></a>00133 <span class="comment">*</span>
+<a name="l00134"></a>00134 <span class="comment">*   CAUTIONS</span>
+<a name="l00135"></a>00135 <span class="comment">*</span>
+<a name="l00136"></a>00136 <span class="comment">*   EXAMPLES</span>
+<a name="l00137"></a>00137 <span class="comment">*</span>
+<a name="l00138"></a>00138 <span class="comment">*   SEE ALSO</span>
+<a name="l00139"></a>00139 <span class="comment">*</span>
+<a name="l00140"></a>00140 <span class="comment">*   BUGS</span>
+<a name="l00141"></a>00141 <span class="comment">*</span>
+<a name="l00142"></a>00142 <span class="comment">*------------------------------------------------------------------------</span>
+<a name="l00143"></a>00143 <span class="comment">*/</span>
+<a name="l00144"></a>00144 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00145"></a>00145 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00146"></a>00146 <span class="preprocessor">#endif</span>
+<a name="l00147"></a>00147 <span class="preprocessor"></span><span class="preprocessor">#include "sinfo_vltPort.h"</span>
+<a name="l00148"></a>00148 <span class="comment">/*</span>
+<a name="l00149"></a>00149 <span class="comment"> * System Headers</span>
+<a name="l00150"></a>00150 <span class="comment"> */</span>
+<a name="l00151"></a>00151 
+<a name="l00152"></a>00152 <span class="comment">/*</span>
+<a name="l00153"></a>00153 <span class="comment"> * Local Headers</span>
+<a name="l00154"></a>00154 <span class="comment"> */</span>
+<a name="l00155"></a>00155 
+<a name="l00156"></a>00156 <span class="preprocessor">#include "sinfo_absolute.h"</span>
+<a name="l00157"></a>00157 <span class="preprocessor">#include "sinfo_recipes.h"</span>
+<a name="l00158"></a>00158 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00159"></a>00159 <span class="comment"> *                                 Defines</span>
+<a name="l00160"></a>00160 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00161"></a>00161 <span class="keyword">static</span> <span class="keywordtype">float</span>  sqrarg ;
+<a name="l00162"></a>00162 <span class="preprocessor">#define SQR(a) (sqrarg = (a) , sqrarg*sqrarg)</span>
+<a name="l00163"></a>00163 <span class="preprocessor"></span>
+<a name="l00164"></a>00164 <span class="preprocessor">#define XDIMA         1         </span><span class="comment">/* dimension of the x values */</span>
+<a name="l00165"></a>00165 <span class="preprocessor">#define TOLA          0.001     </span><span class="comment">/* fitting tolerance */</span>
+<a name="l00166"></a>00166 <span class="preprocessor">#define LABA          0.1       </span><span class="comment">/* labda parameter */</span>
+<a name="l00167"></a>00167 <span class="preprocessor">#define ITSA          200       </span><span class="comment">/* maximum number of iterations */</span>
+<a name="l00168"></a>00168 <span class="preprocessor">#define LABFACA       10.0      </span><span class="comment">/* labda step factor */</span>
+<a name="l00169"></a>00169 <span class="preprocessor">#define LABMAXA       1.0e+10   </span><span class="comment">/* maximum value for labda */</span>
+<a name="l00170"></a>00170 <span class="preprocessor">#define LABMINA       1.0e-10   </span><span class="comment">/* minimum value for labda */</span>
+<a name="l00171"></a>00171 <span class="preprocessor">#define NPAR          4         </span><span class="comment">/* number of fit parameters */</span>
+<a name="l00172"></a>00172 
+<a name="l00173"></a>00173 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00174"></a>00174 <span class="comment"> *                                    Local variables</span>
+<a name="l00175"></a>00175 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00176"></a>00176 
+<a name="l00177"></a>00177 <span class="keyword">static</span> <span class="keywordtype">double</span> chi1 ;                    <span class="comment">/* old reduced chi-squared */</span>
+<a name="l00178"></a>00178 <span class="keyword">static</span> <span class="keywordtype">double</span> chi2 ;                    <span class="comment">/* new reduced chi-squared */</span>
+<a name="l00179"></a>00179 <span class="keyword">static</span> <span class="keywordtype">double</span> labda ;                   <span class="comment">/* mixing parameter */</span>
+<a name="l00180"></a>00180 <span class="keyword">static</span> <span class="keywordtype">double</span> vec[NPAR] ;               <span class="comment">/* correction sinfo_vector */</span>
+<a name="l00181"></a>00181 <span class="keyword">static</span> <span class="keywordtype">double</span> matrix1[NPAR][NPAR] ;     <span class="comment">/* original sinfo_matrix */</span>
+<a name="l00182"></a>00182 <span class="keyword">static</span> <span class="keywordtype">double</span> matrix2[NPAR][NPAR] ;     <span class="comment">/* inverse of matrix1 */</span>
+<a name="l00183"></a>00183 <span class="keyword">static</span> <span class="keywordtype">int</span>    nfree ;                   <span class="comment">/* number of free parameters */</span>
+<a name="l00184"></a>00184 <span class="keyword">static</span> <span class="keywordtype">int</span>    parptr[NPAR] ;            <span class="comment">/* parameter pointer */</span>
+<a name="l00185"></a>00185 <span class="keyword">static</span> <span class="keywordtype">float</span>  slopewidth ;              <span class="comment">/* initial value for fit parameter 5: </span>
+<a name="l00186"></a>00186 <span class="comment">                                           width of linear slope */</span>
+<a name="l00187"></a>00187 
+<a name="l00188"></a>00188 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00189"></a>00189 <span class="comment"> *                    Functions private to this module</span>
+<a name="l00190"></a>00190 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00191"></a>00191 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_new_inv_mat_edge (<span class="keywordtype">void</span>) ;
+<a name="l00192"></a>00192 
+<a name="l00193"></a>00193 <span class="keyword">static</span> <span class="keywordtype">void</span> sinfo_new_get_mat_edge ( <span class="keywordtype">float</span> * xdat,
+<a name="l00194"></a>00194                            <span class="keywordtype">int</span>   * xdim,
+<a name="l00195"></a>00195                            <span class="keywordtype">float</span> * ydat,
+<a name="l00196"></a>00196                            <span class="keywordtype">float</span> * wdat,
+<a name="l00197"></a>00197                            <span class="keywordtype">int</span>   * ndat,
+<a name="l00198"></a>00198                            <span class="keywordtype">float</span> * fpar,
+<a name="l00199"></a>00199                            <span class="keywordtype">float</span> * epar<span class="comment">/*,</span>
+<a name="l00200"></a>00200 <span class="comment">                           int   * npar*/</span> ) ;
+<a name="l00201"></a>00201 
+<a name="l00202"></a>00202 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_new_get_vec_edge ( <span class="keywordtype">float</span> * xdat,
+<a name="l00203"></a>00203                           <span class="keywordtype">int</span>   * xdim,
+<a name="l00204"></a>00204                           <span class="keywordtype">float</span> * ydat,
+<a name="l00205"></a>00205                           <span class="keywordtype">float</span> * wdat,
+<a name="l00206"></a>00206                           <span class="keywordtype">int</span>   * ndat,
+<a name="l00207"></a>00207                           <span class="keywordtype">float</span> * fpar,
+<a name="l00208"></a>00208                           <span class="keywordtype">float</span> * epar,
+<a name="l00209"></a>00209                           <span class="keywordtype">int</span>   * npar ) ;
+<a name="l00210"></a>00210 <span class="keywordtype">float</span> 
+<a name="l00211"></a>00211 sinfo_new_hat2 ( <span class="keywordtype">float</span> * xdat, <span class="keywordtype">float</span> * parlist<span class="comment">/*, int * npar, int * ndat*/</span> );
+<a name="l00212"></a>00212 
+<a name="l00213"></a>00213 <span class="keywordtype">float</span> 
+<a name="l00214"></a>00214 sinfo_new_hat1 ( <span class="keywordtype">float</span> * xdat, <span class="keywordtype">float</span> * parlist<span class="comment">/*, int * npar, int * ndat*/</span> );
+<a name="l00215"></a>00215 
+<a name="l00216"></a>00216 <span class="keywordtype">void</span> 
+<a name="l00217"></a>00217 sinfo_new_hat_deriv2(<span class="keywordtype">float</span> * xdat, <span class="keywordtype">float</span> * parlist, 
+<a name="l00218"></a>00218                      <span class="keywordtype">float</span> * dervs<span class="comment">/*, int * npar*/</span> );
+<a name="l00219"></a>00219 
+<a name="l00220"></a>00220 <span class="keywordtype">void</span> 
+<a name="l00221"></a>00221 sinfo_new_hat_deriv1( <span class="keywordtype">float</span> * xdat, <span class="keywordtype">float</span> * parlist, 
+<a name="l00222"></a>00222                       <span class="keywordtype">float</span> * dervs<span class="comment">/*, int * npar*/</span> );
+<a name="l00223"></a>00223 
+<a name="l00224"></a>00224 <span class="keywordtype">int</span> 
+<a name="l00225"></a>00225 sinfo_new_fit_slits1( cpl_image   * lineImage, 
+<a name="l00226"></a>00226                FitParams ** par,
+<a name="l00227"></a>00227                <span class="keywordtype">float</span>     ** sinfo_slit_pos,
+<a name="l00228"></a>00228                <span class="keywordtype">int</span>          box_length,
+<a name="l00229"></a>00229               <span class="keywordtype">float</span>        y_box );
+<a name="l00230"></a>00230 
+<a name="l00231"></a>00231 <span class="keywordtype">int</span> 
+<a name="l00232"></a>00232 sinfo_new_fit_slits( cpl_image   * lineImage, 
+<a name="l00233"></a>00233               FitParams ** par,
+<a name="l00234"></a>00234               <span class="keywordtype">float</span>     ** sinfo_slit_pos,
+<a name="l00235"></a>00235               <span class="keywordtype">int</span>          box_length,
+<a name="l00236"></a>00236               <span class="keywordtype">float</span>        y_box,
+<a name="l00237"></a>00237              <span class="keywordtype">float</span>        slope_width );
+<a name="l00238"></a>00238 
+<a name="l00239"></a>00239 
+<a name="l00240"></a>00240 
+<a name="l00241"></a>00241 <span class="keywordtype">int</span> 
+<a name="l00242"></a>00242 sinfo_new_fit_slits2( cpl_image   * lineImage, 
+<a name="l00243"></a>00243                FitParams ** par,
+<a name="l00244"></a>00244                <span class="keywordtype">float</span>     ** sinfo_slit_pos,
+<a name="l00245"></a>00245                <span class="keywordtype">int</span>          box_length,
+<a name="l00246"></a>00246                <span class="keywordtype">float</span>        y_box,
+<a name="l00247"></a>00247               <span class="keywordtype">float</span>        diff_tol );
+<a name="l00248"></a>00248 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00249"></a>00249 <span class="comment"> *                            Function codes</span>
+<a name="l00250"></a>00250 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00251"></a>00251 
+<a name="l00270"></a>00270 <span class="keywordtype">float</span> 
+<a name="l00271"></a>00271 sinfo_new_edge ( <span class="keywordtype">float</span> * xdat, <span class="keywordtype">float</span> * parlist<span class="comment">/*, int * npar, int * ndat*/</span> )
+<a name="l00272"></a>00272 {
+<a name="l00273"></a>00273     <span class="keywordtype">float</span> return_value ;
+<a name="l00274"></a>00274     <span class="keywordtype">float</span> slope1 ;
+<a name="l00275"></a>00275 
+<a name="l00276"></a>00276     <span class="comment">/* compute the slopes */</span>
+<a name="l00277"></a>00277     slope1 = ( parlist[3] - parlist[2] ) / ( parlist[1] - parlist[0] ) ;
+<a name="l00278"></a>00278 
+<a name="l00279"></a>00279     <span class="comment">/* now build the hat function out of the parameters */</span>
+<a name="l00280"></a>00280     <span class="keywordflow">if</span> ( xdat[0] <= parlist[0] )
+<a name="l00281"></a>00281     {
+<a name="l00282"></a>00282         return_value = parlist[2] ;
+<a name="l00283"></a>00283     }
+<a name="l00284"></a>00284     <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( xdat[0] > parlist[0] && xdat[0] <= parlist[1] )
+<a name="l00285"></a>00285     {
+<a name="l00286"></a>00286         return_value = (xdat[0] - parlist[0]) * slope1 + parlist[2] ;
+<a name="l00287"></a>00287     }
+<a name="l00288"></a>00288     <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( xdat[0] > parlist[1] )
+<a name="l00289"></a>00289     {
+<a name="l00290"></a>00290         return_value = parlist[3] ;
+<a name="l00291"></a>00291     }
+<a name="l00292"></a>00292     <span class="keywordflow">else</span>
+<a name="l00293"></a>00293     {
+<a name="l00294"></a>00294         return_value = 0. ;
+<a name="l00295"></a>00295     }
+<a name="l00296"></a>00296     
+<a name="l00297"></a>00297     <span class="keywordflow">return</span> return_value ;
+<a name="l00298"></a>00298 }
+<a name="l00299"></a>00299 
+<a name="l00329"></a>00329 <span class="keywordtype">float</span> 
+<a name="l00330"></a>00330 sinfo_new_hat2 ( <span class="keywordtype">float</span> * xdat, <span class="keywordtype">float</span> * parlist<span class="comment">/*, int * npar, int * ndat*/</span> )
+<a name="l00331"></a>00331 {
+<a name="l00332"></a>00332     <span class="keywordtype">float</span> return_value ;
+<a name="l00333"></a>00333     <span class="keywordtype">float</span> slope1, slope2, slope3 ;
+<a name="l00334"></a>00334 
+<a name="l00335"></a>00335     <span class="comment">/* compute the slopes */</span>
+<a name="l00336"></a>00336     slope1 = ( parlist[6] - parlist[4] ) / ( parlist[1] - parlist[0] ) ;
+<a name="l00337"></a>00337     slope2 = ( parlist[7] - parlist[5] ) / ( parlist[3] - parlist[2] ) ;
+<a name="l00338"></a>00338     slope3 = ( parlist[7] - parlist[6] ) / ( parlist[2] - parlist[1] ) ;
+<a name="l00339"></a>00339 
+<a name="l00340"></a>00340     <span class="comment">/* now build the hat function out of the parameters */</span>
+<a name="l00341"></a>00341     <span class="keywordflow">if</span> ( xdat[0] <= parlist[0] )
+<a name="l00342"></a>00342     {
+<a name="l00343"></a>00343         return_value = parlist[4] ;
+<a name="l00344"></a>00344     }
+<a name="l00345"></a>00345     <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( xdat[0] > parlist[0] && xdat[0] <= parlist[1] )
+<a name="l00346"></a>00346     {
+<a name="l00347"></a>00347         return_value = (xdat[0] - parlist[0]) * slope1 + parlist[4] ;
+<a name="l00348"></a>00348     }
+<a name="l00349"></a>00349     <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( xdat[0] > parlist[1] && xdat[0] <= parlist[2] )
+<a name="l00350"></a>00350     {
+<a name="l00351"></a>00351         return_value = (xdat[0] - parlist[1]) * slope3 + parlist[6] ;
+<a name="l00352"></a>00352     }
+<a name="l00353"></a>00353     <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( xdat[0] > parlist[2] && xdat[0] <= parlist[3] )
+<a name="l00354"></a>00354     {
+<a name="l00355"></a>00355         return_value = (parlist[3] - xdat[0]) * slope2 + parlist[5] ;
+<a name="l00356"></a>00356     }
+<a name="l00357"></a>00357     <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( xdat[0] > parlist[3] )
+<a name="l00358"></a>00358     {
+<a name="l00359"></a>00359         return_value = parlist[5] ;
+<a name="l00360"></a>00360     }
+<a name="l00361"></a>00361     <span class="keywordflow">else</span>
+<a name="l00362"></a>00362     {
+<a name="l00363"></a>00363         return_value = 0. ;
+<a name="l00364"></a>00364     }
+<a name="l00365"></a>00365     
+<a name="l00366"></a>00366     <span class="keywordflow">return</span> return_value ;
+<a name="l00367"></a>00367 }
+<a name="l00368"></a>00368 
+<a name="l00369"></a>00369 
+<a name="l00399"></a>00399 <span class="keywordtype">float</span> 
+<a name="l00400"></a>00400 sinfo_new_hat1 ( <span class="keywordtype">float</span> * xdat, <span class="keywordtype">float</span> * parlist<span class="comment">/*, int * npar, int * ndat*/</span> )
+<a name="l00401"></a>00401 {
+<a name="l00402"></a>00402     <span class="keywordtype">float</span> return_value=0 ;
+<a name="l00403"></a>00403     <span class="keywordtype">float</span> slope1, slope2 ;
+<a name="l00404"></a>00404 
+<a name="l00405"></a>00405    <span class="comment">/* take only positive values for the fit parameters */</span>
+<a name="l00406"></a>00406 
+<a name="l00407"></a>00407     <span class="comment">/* compute the slopes */</span>
+<a name="l00408"></a>00408     slope1 = (parlist[4] - parlist[2]) / slopewidth ;
+<a name="l00409"></a>00409     slope2 = (parlist[4] - parlist[3]) / slopewidth ;
+<a name="l00410"></a>00410 
+<a name="l00411"></a>00411     <span class="comment">/* now build the hat function out of the parameters */</span>
+<a name="l00412"></a>00412     <span class="keywordflow">if</span> ( xdat[0] <= parlist[0] )
+<a name="l00413"></a>00413     {
+<a name="l00414"></a>00414         return_value = parlist[2] ;
+<a name="l00415"></a>00415     }
+<a name="l00416"></a>00416     <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( xdat[0] > parlist[0] && xdat[0] <= parlist[0] + slopewidth )
+<a name="l00417"></a>00417     {
+<a name="l00418"></a>00418         return_value = (xdat[0] - parlist[0]) * slope1 + parlist[2] ;
+<a name="l00419"></a>00419     }
+<a name="l00420"></a>00420     <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( xdat[0] > parlist[0] + slopewidth && 
+<a name="l00421"></a>00421               xdat[0] <= parlist[1] - slopewidth )
+<a name="l00422"></a>00422     {
+<a name="l00423"></a>00423         return_value = parlist[4] ;
+<a name="l00424"></a>00424     }
+<a name="l00425"></a>00425     <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( xdat[0] > parlist[1] - slopewidth && xdat[0] <= parlist[1] )
+<a name="l00426"></a>00426     {
+<a name="l00427"></a>00427         return_value = (parlist[1] - xdat[0]) * slope2 + parlist[3] ;
+<a name="l00428"></a>00428     }
+<a name="l00429"></a>00429     <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( xdat[0] > parlist[1] )
+<a name="l00430"></a>00430     {
+<a name="l00431"></a>00431         return_value = parlist[3] ;
+<a name="l00432"></a>00432     }
+<a name="l00433"></a>00433     
+<a name="l00434"></a>00434     <span class="keywordflow">return</span> return_value ;
+<a name="l00435"></a>00435 }
+<a name="l00436"></a>00436        
+<a name="l00437"></a>00437 
+<a name="l00464"></a>00464 <span class="keywordtype">void</span> 
+<a name="l00465"></a>00465 sinfo_new_edge_deriv( <span class="keywordtype">float</span> * xdat, <span class="keywordtype">float</span> * parlist, 
+<a name="l00466"></a>00466                       <span class="keywordtype">float</span> * dervs<span class="comment">/*, int * npar*/</span> )
+<a name="l00467"></a>00467 {
+<a name="l00468"></a>00468     <span class="keywordtype">float</span> deriv1_slope1 ;
+<a name="l00469"></a>00469 
+<a name="l00470"></a>00470     <span class="comment">/* compute the slopes */</span>
+<a name="l00471"></a>00471     deriv1_slope1 =( parlist[3] - parlist[2] ) / SQR(parlist[1] - parlist[0]) ;
+<a name="l00472"></a>00472 
+<a name="l00473"></a>00473     <span class="comment">/* now build the hat derivatives out of the parameters */</span>
+<a name="l00474"></a>00474     <span class="keywordflow">if</span> ( xdat[0] <= parlist[0] )
+<a name="l00475"></a>00475     {
+<a name="l00476"></a>00476         dervs[0] = 0. ;
+<a name="l00477"></a>00477         dervs[1] = 0. ;
+<a name="l00478"></a>00478         dervs[2] = 1. ;
+<a name="l00479"></a>00479         dervs[3] = 0. ;
+<a name="l00480"></a>00480     }
+<a name="l00481"></a>00481     <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( xdat[0] > parlist[0] && xdat[0] <= parlist[1] )
+<a name="l00482"></a>00482     {
+<a name="l00483"></a>00483         dervs[0] = ( xdat[0] - parlist[1] ) * deriv1_slope1  ;
+<a name="l00484"></a>00484         dervs[1] = ( parlist[0] - xdat[0] ) * deriv1_slope1 ;
+<a name="l00485"></a>00485         dervs[2] = ( parlist[0] - xdat[0] ) / ( parlist[1] - parlist[0] ) + 1.;
+<a name="l00486"></a>00486         dervs[3] = ( xdat[0] - parlist[0] ) / ( parlist[1] - parlist[0] ) ;
+<a name="l00487"></a>00487     }
+<a name="l00488"></a>00488     <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( xdat[0] > parlist[1] )
+<a name="l00489"></a>00489     {
+<a name="l00490"></a>00490         dervs[0] = 0. ;
+<a name="l00491"></a>00491         dervs[1] = 0. ;
+<a name="l00492"></a>00492         dervs[2] = 0. ;
+<a name="l00493"></a>00493         dervs[3] = 1. ;
+<a name="l00494"></a>00494     }
+<a name="l00495"></a>00495 }
+<a name="l00530"></a>00530 <span class="keywordtype">void</span> 
+<a name="l00531"></a>00531 sinfo_new_hat_deriv2(<span class="keywordtype">float</span> * xdat, <span class="keywordtype">float</span> * parlist, 
+<a name="l00532"></a>00532                      <span class="keywordtype">float</span> * dervs<span class="comment">/*, int * npar*/</span> )
+<a name="l00533"></a>00533 {
+<a name="l00534"></a>00534     <span class="keywordtype">float</span> deriv1_slope1 ;
+<a name="l00535"></a>00535     <span class="keywordtype">float</span> deriv1_slope2 ;
+<a name="l00536"></a>00536     <span class="keywordtype">float</span> deriv1_slope3 ;
+<a name="l00537"></a>00537 
+<a name="l00538"></a>00538     <span class="comment">/* compute the slopes */</span>
+<a name="l00539"></a>00539     deriv1_slope1 = ( parlist[6] - parlist[4] ) / SQR(parlist[1] - parlist[0]);
+<a name="l00540"></a>00540     deriv1_slope2 = ( parlist[7] - parlist[5] ) / SQR(parlist[3] - parlist[2]);
+<a name="l00541"></a>00541     deriv1_slope3 = ( parlist[7] - parlist[6] ) / SQR(parlist[2] - parlist[1]);
+<a name="l00542"></a>00542 
+<a name="l00543"></a>00543     <span class="comment">/* now build the hat derivatives out of the parameters */</span>
+<a name="l00544"></a>00544     <span class="keywordflow">if</span> ( xdat[0] <= parlist[0] )
+<a name="l00545"></a>00545     {
+<a name="l00546"></a>00546         dervs[0] = 0. ;
+<a name="l00547"></a>00547         dervs[1] = 0. ;
+<a name="l00548"></a>00548         dervs[2] = 0. ;
+<a name="l00549"></a>00549         dervs[3] = 0. ;
+<a name="l00550"></a>00550         dervs[4] = 1. ;
+<a name="l00551"></a>00551         dervs[5] = 0. ;
+<a name="l00552"></a>00552         dervs[6] = 0. ;
+<a name="l00553"></a>00553         dervs[7] = 0. ;
+<a name="l00554"></a>00554     }
+<a name="l00555"></a>00555     <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( xdat[0] > parlist[0] && xdat[0] <= parlist[1] )
+<a name="l00556"></a>00556     {
+<a name="l00557"></a>00557         dervs[0] = ( xdat[0] - parlist[1] ) * deriv1_slope1  ;
+<a name="l00558"></a>00558         dervs[1] = ( parlist[0] - xdat[0] ) * deriv1_slope1 ;
+<a name="l00559"></a>00559         dervs[2] = 0. ;
+<a name="l00560"></a>00560         dervs[3] = 0. ;
+<a name="l00561"></a>00561         dervs[4] = ( parlist[0] - xdat[0] ) / ( parlist[1] - parlist[0] ) + 1.;
+<a name="l00562"></a>00562         dervs[5] = 0. ;
+<a name="l00563"></a>00563         dervs[6] = ( xdat[0] - parlist[0] ) / ( parlist[1] - parlist[0] ) ;
+<a name="l00564"></a>00564         dervs[7] = 0. ;
+<a name="l00565"></a>00565     }
+<a name="l00566"></a>00566     <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( xdat[0] > parlist[1] && xdat[0] <= parlist[2] )
+<a name="l00567"></a>00567     {
+<a name="l00568"></a>00568         dervs[0] = 0. ;
+<a name="l00569"></a>00569         dervs[1] = (xdat[0] - parlist[2]) * deriv1_slope3 ;
+<a name="l00570"></a>00570         dervs[2] = (parlist[1] - xdat[0]) * deriv1_slope3 ;
+<a name="l00571"></a>00571         dervs[3] = 0. ;
+<a name="l00572"></a>00572         dervs[4] = 0. ;
+<a name="l00573"></a>00573         dervs[5] = 0. ;
+<a name="l00574"></a>00574         dervs[6] = (parlist[1] - xdat[0]) / (parlist[2] - parlist[1]) + 1. ;
+<a name="l00575"></a>00575         dervs[7] = (xdat[0] - parlist[1]) / (parlist[2] - parlist[1]) ;
+<a name="l00576"></a>00576     }
+<a name="l00577"></a>00577     <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( xdat[0] > parlist[2] && xdat[0] <= parlist[3] )
+<a name="l00578"></a>00578     {
+<a name="l00579"></a>00579         dervs[0] = 0. ;
+<a name="l00580"></a>00580         dervs[1] = 0. ;
+<a name="l00581"></a>00581         dervs[2] = ( parlist[3] - xdat[0] ) * deriv1_slope2 ;
+<a name="l00582"></a>00582         dervs[3] = ( xdat[0] - parlist[2] ) * deriv1_slope2 ;
+<a name="l00583"></a>00583         dervs[4] = 0. ; 
+<a name="l00584"></a>00584         dervs[5] = ( xdat[0] - parlist[3] ) / ( parlist[3] - parlist[2] ) + 1.;
+<a name="l00585"></a>00585         dervs[6] = 0. ;
+<a name="l00586"></a>00586         dervs[7] = ( parlist[3] - xdat[0] ) / ( parlist[3] - parlist[2] ) ;
+<a name="l00587"></a>00587     }
+<a name="l00588"></a>00588     <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( xdat[0] > parlist[3] )
+<a name="l00589"></a>00589     {
+<a name="l00590"></a>00590         dervs[0] = 0. ;
+<a name="l00591"></a>00591         dervs[1] = 0. ;
+<a name="l00592"></a>00592         dervs[2] = 0. ;
+<a name="l00593"></a>00593         dervs[3] = 0. ;
+<a name="l00594"></a>00594         dervs[4] = 0. ;
+<a name="l00595"></a>00595         dervs[5] = 1. ;
+<a name="l00596"></a>00596         dervs[6] = 0. ;
+<a name="l00597"></a>00597         dervs[7] = 0. ;
+<a name="l00598"></a>00598     }
+<a name="l00599"></a>00599 }
+<a name="l00600"></a>00600 
+<a name="l00629"></a>00629 <span class="keywordtype">void</span> 
+<a name="l00630"></a>00630 sinfo_new_hat_deriv1( <span class="keywordtype">float</span> * xdat, <span class="keywordtype">float</span> * parlist, 
+<a name="l00631"></a>00631                       <span class="keywordtype">float</span> * dervs<span class="comment">/*, int * npar*/</span> )
+<a name="l00632"></a>00632 {
+<a name="l00633"></a>00633     <span class="comment">/* now build the hat derivatives out of the parameters */</span>
+<a name="l00634"></a>00634     <span class="keywordflow">if</span> ( xdat[0] <= parlist[0] )
+<a name="l00635"></a>00635     {
+<a name="l00636"></a>00636         dervs[0] = 0. ;
+<a name="l00637"></a>00637         dervs[1] = 0. ;
+<a name="l00638"></a>00638         dervs[2] = 1. ;
+<a name="l00639"></a>00639         dervs[3] = 0. ;
+<a name="l00640"></a>00640         dervs[4] = 0. ;
+<a name="l00641"></a>00641     }
+<a name="l00642"></a>00642     <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( xdat[0] > parlist[0] && xdat[0] <= parlist[0] + slopewidth )
+<a name="l00643"></a>00643     {
+<a name="l00644"></a>00644         dervs[0] = ( parlist[2] - parlist[4] ) / slopewidth ;
+<a name="l00645"></a>00645         dervs[1] = 0. ;
+<a name="l00646"></a>00646         dervs[2] = (( parlist[0] - xdat[0] ) / slopewidth ) + 1. ;
+<a name="l00647"></a>00647         dervs[3] = 0. ;
+<a name="l00648"></a>00648         dervs[4] = ( xdat[0] - parlist[0] ) / slopewidth ;
+<a name="l00649"></a>00649     }
+<a name="l00650"></a>00650     <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( xdat[0] > parlist[0] + slopewidth && xdat[0] <= 
+<a name="l00651"></a>00651               parlist[1] - slopewidth )
+<a name="l00652"></a>00652     {
+<a name="l00653"></a>00653         dervs[0] = 0. ;
+<a name="l00654"></a>00654         dervs[1] = 0. ;
+<a name="l00655"></a>00655         dervs[2] = 0. ;
+<a name="l00656"></a>00656         dervs[3] = 0. ;
+<a name="l00657"></a>00657         dervs[4] = 1. ;
+<a name="l00658"></a>00658     }
+<a name="l00659"></a>00659     <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( xdat[0] > parlist[1] - slopewidth && xdat[0] <= parlist[1] )
+<a name="l00660"></a>00660     {
+<a name="l00661"></a>00661         dervs[0] = 0. ;
+<a name="l00662"></a>00662         dervs[1] = ( parlist[4] - parlist[3] ) / slopewidth ;
+<a name="l00663"></a>00663         dervs[2] = 0. ;
+<a name="l00664"></a>00664         dervs[3] = (( xdat[0] - parlist[1] ) / slopewidth ) + 1. ;
+<a name="l00665"></a>00665         dervs[4] = ( parlist[1] - xdat[0] ) / slopewidth ; 
+<a name="l00666"></a>00666     }
+<a name="l00667"></a>00667     <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( xdat[0] > parlist[1] )
+<a name="l00668"></a>00668     {
+<a name="l00669"></a>00669         dervs[0] = 0. ;
+<a name="l00670"></a>00670         dervs[1] = 0. ;
+<a name="l00671"></a>00671         dervs[2] = 0. ;
+<a name="l00672"></a>00672         dervs[3] = 1. ;
+<a name="l00673"></a>00673         dervs[4] = 0. ;
+<a name="l00674"></a>00674     }
+<a name="l00675"></a>00675 }
+<a name="l00676"></a>00676    
+<a name="l00688"></a>00688 <span class="keyword">static</span> <span class="keywordtype">int</span> 
+<a name="l00689"></a>00689 sinfo_new_inv_mat_edge (<span class="keywordtype">void</span>)
+<a name="l00690"></a>00690 {
+<a name="l00691"></a>00691     <span class="keywordtype">double</span> even ;
+<a name="l00692"></a>00692     <span class="keywordtype">double</span> hv[NPAR] ;
+<a name="l00693"></a>00693     <span class="keywordtype">double</span> mjk ;
+<a name="l00694"></a>00694     <span class="keywordtype">double</span> rowmax ;
+<a name="l00695"></a>00695     <span class="keywordtype">int</span> evin ;
+<a name="l00696"></a>00696     <span class="keywordtype">int</span> i, j, k, row ;
+<a name="l00697"></a>00697     <span class="keywordtype">int</span> per[NPAR] ;
+<a name="l00698"></a>00698    
+<a name="l00699"></a>00699     <span class="comment">/* set permutation array */</span>
+<a name="l00700"></a>00700     <span class="keywordflow">for</span> ( i = 0 ; i < nfree ; i++ )
+<a name="l00701"></a>00701     {
+<a name="l00702"></a>00702         per[i] = i ;
+<a name="l00703"></a>00703     }
+<a name="l00704"></a>00704     
+<a name="l00705"></a>00705     <span class="keywordflow">for</span> ( j = 0 ; j < nfree ; j++ ) <span class="comment">/* in j-th column */</span>
+<a name="l00706"></a>00706     {
+<a name="l00707"></a>00707         <span class="comment">/* determine largest element of a row */</span>                           
+<a name="l00708"></a>00708         rowmax = fabs ( matrix2[j][j] ) ;
+<a name="l00709"></a>00709         row = j ;                         
+<a name="l00710"></a>00710 
+<a name="l00711"></a>00711         <span class="keywordflow">for</span> ( i = j + 1 ; i < nfree ; i++ )
+<a name="l00712"></a>00712         {
+<a name="l00713"></a>00713             <span class="keywordflow">if</span> ( fabs ( matrix2[i][j] ) > rowmax )
+<a name="l00714"></a>00714             {
+<a name="l00715"></a>00715                 rowmax = fabs( matrix2[i][j] ) ;
+<a name="l00716"></a>00716                 row = i ;
+<a name="l00717"></a>00717             }
+<a name="l00718"></a>00718         }
+<a name="l00719"></a>00719 
+<a name="l00720"></a>00720         <span class="comment">/* determinant is zero! */</span>
+<a name="l00721"></a>00721         <span class="keywordflow">if</span> ( matrix2[row][j] == 0.0 )
+<a name="l00722"></a>00722         {
+<a name="l00723"></a>00723             <span class="keywordflow">return</span> -6 ;
+<a name="l00724"></a>00724         }
+<a name="l00725"></a>00725         
+<a name="l00726"></a>00726         <span class="comment">/* if the largest element is not on the diagonal, then permutate rows */</span>
+<a name="l00727"></a>00727         <span class="keywordflow">if</span> ( row > j )
+<a name="l00728"></a>00728         {
+<a name="l00729"></a>00729             <span class="keywordflow">for</span> ( k = 0 ; k < nfree ; k++ )
+<a name="l00730"></a>00730             {
+<a name="l00731"></a>00731                 even = matrix2[j][k] ;
+<a name="l00732"></a>00732                 matrix2[j][k] = matrix2[row][k] ;
+<a name="l00733"></a>00733                 matrix2[row][k] = even ;
+<a name="l00734"></a>00734             }
+<a name="l00735"></a>00735             <span class="comment">/* keep track of permutation */</span>
+<a name="l00736"></a>00736             evin = per[j] ;
+<a name="l00737"></a>00737             per[j] = per[row] ;
+<a name="l00738"></a>00738             per[row] = evin ;
+<a name="l00739"></a>00739         }
+<a name="l00740"></a>00740         
+<a name="l00741"></a>00741         <span class="comment">/* modify column */</span>
+<a name="l00742"></a>00742         even = 1.0 / matrix2[j][j] ;
+<a name="l00743"></a>00743         <span class="keywordflow">for</span> ( i = 0 ; i < nfree ; i++ )
+<a name="l00744"></a>00744         {
+<a name="l00745"></a>00745             matrix2[i][j] *= even ;
+<a name="l00746"></a>00746         }
+<a name="l00747"></a>00747         matrix2[j][j] = even ;
+<a name="l00748"></a>00748         
+<a name="l00749"></a>00749         <span class="keywordflow">for</span> ( k = 0 ; k < j ; k++ )
+<a name="l00750"></a>00750         {
+<a name="l00751"></a>00751             mjk = matrix2[j][k] ;
+<a name="l00752"></a>00752             <span class="keywordflow">for</span> ( i = 0 ; i < j ; i++ )
+<a name="l00753"></a>00753             {
+<a name="l00754"></a>00754                 matrix2[i][k] -= matrix2[i][j] * mjk ;
+<a name="l00755"></a>00755             }
+<a name="l00756"></a>00756             <span class="keywordflow">for</span> ( i = j + 1 ; i < nfree ; i++ )
+<a name="l00757"></a>00757             {
+<a name="l00758"></a>00758                 matrix2[i][k] -= matrix2[i][j] * mjk ;
+<a name="l00759"></a>00759             }
+<a name="l00760"></a>00760             matrix2[j][k] = -even * mjk ;
+<a name="l00761"></a>00761         }
+<a name="l00762"></a>00762     
+<a name="l00763"></a>00763         <span class="keywordflow">for</span> ( k = j + 1 ; k < nfree ; k++ )
+<a name="l00764"></a>00764         {
+<a name="l00765"></a>00765             mjk = matrix2[j][k] ;
+<a name="l00766"></a>00766             <span class="keywordflow">for</span> ( i = 0 ; i < j ; i++ )
+<a name="l00767"></a>00767             {
+<a name="l00768"></a>00768                 matrix2[i][k]  -= matrix2[i][j] * mjk ;
+<a name="l00769"></a>00769             }
+<a name="l00770"></a>00770             <span class="keywordflow">for</span> ( i = j + 1 ; i < nfree ; i++ )
+<a name="l00771"></a>00771             {
+<a name="l00772"></a>00772                 matrix2[i][k]  -= matrix2[i][j] * mjk ;
+<a name="l00773"></a>00773             }
+<a name="l00774"></a>00774             matrix2[j][k] = -even * mjk ;
+<a name="l00775"></a>00775         }
+<a name="l00776"></a>00776     }
+<a name="l00777"></a>00777     
+<a name="l00778"></a>00778     <span class="comment">/* finally, repermute the columns */</span>
+<a name="l00779"></a>00779     <span class="keywordflow">for</span> ( i = 0 ; i < nfree ; i++ )
+<a name="l00780"></a>00780     {
+<a name="l00781"></a>00781         <span class="keywordflow">for</span> ( k = 0 ; k < nfree ; k++ )
+<a name="l00782"></a>00782         {
+<a name="l00783"></a>00783             hv[per[k]] = matrix2[i][k] ;
+<a name="l00784"></a>00784         }
+<a name="l00785"></a>00785         <span class="keywordflow">for</span> ( k = 0 ; k < nfree ; k++ )
+<a name="l00786"></a>00786         {
+<a name="l00787"></a>00787             matrix2[i][k] = hv[k] ;
+<a name="l00788"></a>00788         }
+<a name="l00789"></a>00789     }
+<a name="l00790"></a>00790         
+<a name="l00791"></a>00791     <span class="comment">/* all is well */</span>
+<a name="l00792"></a>00792     <span class="keywordflow">return</span> 0 ;
+<a name="l00793"></a>00793 }
+<a name="l00794"></a>00794     
+<a name="l00813"></a>00813 <span class="keyword">static</span> <span class="keywordtype">void</span> 
+<a name="l00814"></a>00814 sinfo_new_get_mat_edge ( <span class="keywordtype">float</span> * xdat,
+<a name="l00815"></a>00815                            <span class="keywordtype">int</span>   * xdim,
+<a name="l00816"></a>00816                            <span class="keywordtype">float</span> * ydat,
+<a name="l00817"></a>00817                            <span class="keywordtype">float</span> * wdat,
+<a name="l00818"></a>00818                            <span class="keywordtype">int</span>   * ndat,
+<a name="l00819"></a>00819                            <span class="keywordtype">float</span> * fpar,
+<a name="l00820"></a>00820                            <span class="keywordtype">float</span> * epar<span class="comment">/*,</span>
+<a name="l00821"></a>00821 <span class="comment">                           int   * npar*/</span> )
+<a name="l00822"></a>00822 {
+<a name="l00823"></a>00823     <span class="keywordtype">double</span> wd ;
+<a name="l00824"></a>00824     <span class="keywordtype">double</span> wn ;
+<a name="l00825"></a>00825     <span class="keywordtype">double</span> yd ;
+<a name="l00826"></a>00826     <span class="keywordtype">int</span> i, j, n ;
+<a name="l00827"></a>00827 
+<a name="l00828"></a>00828     <span class="keywordflow">for</span> ( j = 0 ; j < nfree ; j++ )
+<a name="l00829"></a>00829     {
+<a name="l00830"></a>00830         vec[j] = 0.0 ; <span class="comment">/* zero sinfo_vector */</span>
+<a name="l00831"></a>00831         <span class="keywordflow">for</span> ( i = 0 ; i<= j ; i++ )   <span class="comment">/* zero matrix only on and </span>
+<a name="l00832"></a>00832 <span class="comment">                                         below diagonal */</span>
+<a name="l00833"></a>00833         {
+<a name="l00834"></a>00834             matrix1[j][i] = 0.0 ;
+<a name="l00835"></a>00835         }
+<a name="l00836"></a>00836     }
+<a name="l00837"></a>00837     chi2 = 0.0 ;  <span class="comment">/* reset reduced chi-squared */</span>
+<a name="l00838"></a>00838     
+<a name="l00839"></a>00839     <span class="comment">/* loop through data points */</span>
+<a name="l00840"></a>00840     <span class="keywordflow">for</span> ( n = 0 ; n < (*ndat) ; n++ )
+<a name="l00841"></a>00841     {
+<a name="l00842"></a>00842         wn = wdat[n] ;
+<a name="l00843"></a>00843         <span class="keywordflow">if</span> ( wn > 0.0 )  <span class="comment">/* legal weight ? */</span>
+<a name="l00844"></a>00844         {
+<a name="l00845"></a>00845             yd = ydat[n] - sinfo_new_edge( &xdat[(*xdim) * n], 
+<a name="l00846"></a>00846                                            fpar<span class="comment">/*, npar, ndat*/</span> ) ;
+<a name="l00847"></a>00847             sinfo_new_edge_deriv( &xdat[(*xdim) * n], fpar, epar<span class="comment">/*, npar */</span>) ;
+<a name="l00848"></a>00848             chi2 += yd * yd * wn ; <span class="comment">/* add to chi-squared */</span>
+<a name="l00849"></a>00849             <span class="keywordflow">for</span> ( j = 0 ; j < nfree ; j++ )
+<a name="l00850"></a>00850             {
+<a name="l00851"></a>00851                 wd = epar[parptr[j]] * wn ;  <span class="comment">/* weighted derivative */</span>
+<a name="l00852"></a>00852                 vec[j] += yd * wd ;       <span class="comment">/* fill sinfo_vector */</span>
+<a name="l00853"></a>00853                 <span class="keywordflow">for</span> ( i = 0 ; i <= j ; i++ ) <span class="comment">/* fill sinfo_matrix */</span>
+<a name="l00854"></a>00854                 {
+<a name="l00855"></a>00855                     matrix1[j][i] += epar[parptr[i]] * wd ;
+<a name="l00856"></a>00856                 }
+<a name="l00857"></a>00857             }
+<a name="l00858"></a>00858         }
+<a name="l00859"></a>00859     }                   
+<a name="l00860"></a>00860 }  
+<a name="l00861"></a>00861                 
+<a name="l00862"></a>00862             
+<a name="l00863"></a>00863 
+<a name="l00893"></a>00893 <span class="keyword">static</span> <span class="keywordtype">int</span> 
+<a name="l00894"></a>00894 sinfo_new_get_vec_edge ( <span class="keywordtype">float</span> * xdat,
+<a name="l00895"></a>00895                           <span class="keywordtype">int</span>   * xdim,
+<a name="l00896"></a>00896                           <span class="keywordtype">float</span> * ydat,
+<a name="l00897"></a>00897                           <span class="keywordtype">float</span> * wdat,
+<a name="l00898"></a>00898                           <span class="keywordtype">int</span>   * ndat,
+<a name="l00899"></a>00899                           <span class="keywordtype">float</span> * fpar,
+<a name="l00900"></a>00900                           <span class="keywordtype">float</span> * epar,
+<a name="l00901"></a>00901                           <span class="keywordtype">int</span>   * npar )
+<a name="l00902"></a>00902 {
+<a name="l00903"></a>00903     <span class="keywordtype">double</span> dj ;
+<a name="l00904"></a>00904     <span class="keywordtype">double</span> dy ;
+<a name="l00905"></a>00905     <span class="keywordtype">double</span> mii ;
+<a name="l00906"></a>00906     <span class="keywordtype">double</span> mji ;
+<a name="l00907"></a>00907     <span class="keywordtype">double</span> mjj ;
+<a name="l00908"></a>00908     <span class="keywordtype">double</span> wn ;
+<a name="l00909"></a>00909     <span class="keywordtype">int</span> i, j, n, r ;
+<a name="l00910"></a>00910 
+<a name="l00911"></a>00911     <span class="comment">/* loop to modify and scale the sinfo_matrix */</span>
+<a name="l00912"></a>00912     <span class="keywordflow">for</span> ( j = 0 ; j < nfree ; j++ )
+<a name="l00913"></a>00913     {
+<a name="l00914"></a>00914         mjj = matrix1[j][j] ;
+<a name="l00915"></a>00915         <span class="keywordflow">if</span> ( mjj <= 0.0 )             <span class="comment">/* diagonal element wrong */</span>
+<a name="l00916"></a>00916         {
+<a name="l00917"></a>00917             <span class="keywordflow">return</span> -5 ;
+<a name="l00918"></a>00918         }
+<a name="l00919"></a>00919         mjj = sqrt( mjj ) ;
+<a name="l00920"></a>00920         <span class="keywordflow">for</span> ( i = 0 ; i < j ; i++ )
+<a name="l00921"></a>00921         {
+<a name="l00922"></a>00922             mji = matrix1[j][i] / mjj / sqrt( matrix1[i][i] ) ;
+<a name="l00923"></a>00923             matrix2[i][j] = matrix2[j][i] = mji ;
+<a name="l00924"></a>00924         }
+<a name="l00925"></a>00925         matrix2[j][j] = 1.0 + labda ;  <span class="comment">/* scaled value on diagonal */</span>
+<a name="l00926"></a>00926     }    
+<a name="l00927"></a>00927     
+<a name="l00928"></a>00928     <span class="keywordflow">if</span> ( (r = sinfo_new_inv_mat_edge()) ) <span class="comment">/* sinfo_invert sinfo_matrix inlace */</span>
+<a name="l00929"></a>00929     {
+<a name="l00930"></a>00930         <span class="keywordflow">return</span> r ;
+<a name="l00931"></a>00931     }
+<a name="l00932"></a>00932     
+<a name="l00933"></a>00933     <span class="keywordflow">for</span> ( i = 0 ; i < (*npar) ; i ++ )
+<a name="l00934"></a>00934     {
+<a name="l00935"></a>00935         epar[i] = fpar[i] ;
+<a name="l00936"></a>00936     }
+<a name="l00937"></a>00937     
+<a name="l00938"></a>00938     <span class="comment">/* loop to calculate correction sinfo_vector */</span>
+<a name="l00939"></a>00939     <span class="keywordflow">for</span> ( j = 0 ; j < nfree ; j++ )
+<a name="l00940"></a>00940     {
+<a name="l00941"></a>00941         dj = 0.0 ;
+<a name="l00942"></a>00942         mjj = matrix1[j][j] ;
+<a name="l00943"></a>00943         <span class="keywordflow">if</span> ( mjj <= 0.0)               <span class="comment">/* not allowed */</span>
+<a name="l00944"></a>00944         {
+<a name="l00945"></a>00945             <span class="keywordflow">return</span> -7 ;
+<a name="l00946"></a>00946         }
+<a name="l00947"></a>00947         mjj = sqrt ( mjj ) ;
+<a name="l00948"></a>00948         <span class="keywordflow">for</span> ( i = 0 ; i < nfree ; i++ )
+<a name="l00949"></a>00949         {
+<a name="l00950"></a>00950             mii = matrix1[i][i] ;
+<a name="l00951"></a>00951             <span class="keywordflow">if</span> ( mii <= 0.0 )
+<a name="l00952"></a>00952             {
+<a name="l00953"></a>00953                 <span class="keywordflow">return</span> -7 ;
+<a name="l00954"></a>00954             }
+<a name="l00955"></a>00955             mii = sqrt( mii ) ;
+<a name="l00956"></a>00956             dj += vec[i] * matrix2[j][i] / mjj / mii ;
+<a name="l00957"></a>00957         }
+<a name="l00958"></a>00958         epar[parptr[j]] += dj ;       <span class="comment">/* new parameters */</span>
+<a name="l00959"></a>00959     }    
+<a name="l00960"></a>00960     chi1 = 0.0 ;                      <span class="comment">/* reset reduced chi-squared */</span>
+<a name="l00961"></a>00961  
+<a name="l00962"></a>00962     <span class="comment">/* loop through the data points */</span>
+<a name="l00963"></a>00963     <span class="keywordflow">for</span> ( n = 0 ; n < (*ndat) ; n++ )
+<a name="l00964"></a>00964     {
+<a name="l00965"></a>00965         wn = wdat[n] ;               <span class="comment">/* get weight */</span>
+<a name="l00966"></a>00966         <span class="keywordflow">if</span> ( wn > 0.0 )              <span class="comment">/* legal weight */</span>
+<a name="l00967"></a>00967         {
+<a name="l00968"></a>00968             dy = ydat[n] - sinfo_new_edge( &xdat[(*xdim) * n], epar
+<a name="l00969"></a>00969                                                 <span class="comment">/*, npar, ndat*/</span>) ;
+<a name="l00970"></a>00970             chi1 += wdat[n] * dy * dy ;
+<a name="l00971"></a>00971         }
+<a name="l00972"></a>00972     }
+<a name="l00973"></a>00973     <span class="keywordflow">return</span> 0 ;
+<a name="l00974"></a>00974 }   
+<a name="l00975"></a>00975     
+<a name="l00976"></a>00976         
+<a name="l01030"></a>01030 <span class="keywordtype">int</span> 
+<a name="l01031"></a>01031 sinfo_new_lsqfit_edge ( <span class="keywordtype">float</span> * xdat,
+<a name="l01032"></a>01032                   <span class="keywordtype">int</span>   * xdim,
+<a name="l01033"></a>01033                   <span class="keywordtype">float</span> * ydat,
+<a name="l01034"></a>01034                   <span class="keywordtype">float</span> * wdat,
+<a name="l01035"></a>01035                   <span class="keywordtype">int</span>   * ndat,
+<a name="l01036"></a>01036                   <span class="keywordtype">float</span> * fpar,
+<a name="l01037"></a>01037                   <span class="keywordtype">float</span> * epar,
+<a name="l01038"></a>01038                   <span class="keywordtype">int</span>   * mpar,
+<a name="l01039"></a>01039                   <span class="keywordtype">int</span>   * npar,
+<a name="l01040"></a>01040                   <span class="keywordtype">float</span> * tol ,
+<a name="l01041"></a>01041                   <span class="keywordtype">int</span>   * its ,
+<a name="l01042"></a>01042                   <span class="keywordtype">float</span> * lab  )
+<a name="l01043"></a>01043 {
+<a name="l01044"></a>01044     <span class="keywordtype">int</span> i, n, r ;
+<a name="l01045"></a>01045     <span class="keywordtype">int</span> itc ;                      <span class="comment">/* fate of fit */</span>
+<a name="l01046"></a>01046     <span class="keywordtype">int</span> found ;                    <span class="comment">/* fit converged: 1, not yet converged: 0 */</span>
+<a name="l01047"></a>01047     <span class="keywordtype">int</span>  nuse ;                    <span class="comment">/* number of useable data points */</span>
+<a name="l01048"></a>01048     <span class="keywordtype">double</span> tolerance ;             <span class="comment">/* accuracy */</span>
+<a name="l01049"></a>01049 
+<a name="l01050"></a>01050     itc   = 0 ;                    <span class="comment">/* fate of fit */</span>
+<a name="l01051"></a>01051     found = 0 ;                    <span class="comment">/* reset */</span>
+<a name="l01052"></a>01052     nfree = 0 ;                    <span class="comment">/* number of free parameters */</span>
+<a name="l01053"></a>01053     nuse  = 0 ;                    <span class="comment">/* number of legal data points */</span>
+<a name="l01054"></a>01054 
+<a name="l01055"></a>01055     <span class="keywordflow">if</span> ( *tol < (FLT_EPSILON * 10.0 ) )
+<a name="l01056"></a>01056     {
+<a name="l01057"></a>01057         tolerance = FLT_EPSILON * 10.0 ;  <span class="comment">/* default tolerance */</span>
+<a name="l01058"></a>01058     }
+<a name="l01059"></a>01059     <span class="keywordflow">else</span>
+<a name="l01060"></a>01060     {
+<a name="l01061"></a>01061         tolerance = *tol ;                <span class="comment">/* tolerance */</span>
+<a name="l01062"></a>01062     }
+<a name="l01063"></a>01063     
+<a name="l01064"></a>01064     labda = fabs( *lab ) * LABFACA ;      <span class="comment">/* start value for mixing parameter */</span>
+<a name="l01065"></a>01065     <span class="keywordflow">for</span> ( i = 0 ; i < (*npar) ; i++ )
+<a name="l01066"></a>01066     {
+<a name="l01067"></a>01067         <span class="keywordflow">if</span> ( mpar[i] )
+<a name="l01068"></a>01068         {
+<a name="l01069"></a>01069             <span class="keywordflow">if</span> ( nfree > NPAR )         <span class="comment">/* too many free parameters */</span>
+<a name="l01070"></a>01070             {
+<a name="l01071"></a>01071                 <span class="keywordflow">return</span> -1 ;
+<a name="l01072"></a>01072             }
+<a name="l01073"></a>01073             parptr[nfree++] = i ;         <span class="comment">/* a free parameter */</span>
+<a name="l01074"></a>01074         }
+<a name="l01075"></a>01075     }
+<a name="l01076"></a>01076     
+<a name="l01077"></a>01077     <span class="keywordflow">if</span> (nfree == 0)                       <span class="comment">/* no free parameters */</span>     
+<a name="l01078"></a>01078     {
+<a name="l01079"></a>01079         <span class="keywordflow">return</span> -2 ;
+<a name="l01080"></a>01080     }
+<a name="l01081"></a>01081     
+<a name="l01082"></a>01082     <span class="keywordflow">for</span> ( n = 0 ; n < (*ndat) ; n++ )
+<a name="l01083"></a>01083     {
+<a name="l01084"></a>01084         <span class="keywordflow">if</span> ( wdat[n] > 0.0 )              <span class="comment">/* legal weight */</span>
+<a name="l01085"></a>01085         {
+<a name="l01086"></a>01086             nuse ++ ;
+<a name="l01087"></a>01087         }
+<a name="l01088"></a>01088     }
+<a name="l01089"></a>01089     
+<a name="l01090"></a>01090     <span class="keywordflow">if</span> ( nfree >= nuse )
+<a name="l01091"></a>01091     {
+<a name="l01092"></a>01092         <span class="keywordflow">return</span> -3 ;                       <span class="comment">/* no degrees of freedom */</span>
+<a name="l01093"></a>01093     }
+<a name="l01094"></a>01094     <span class="keywordflow">if</span> ( labda == 0.0 )                   <span class="comment">/* linear fit */</span>
+<a name="l01095"></a>01095     {
+<a name="l01096"></a>01096         <span class="comment">/* initialize fpar array */</span>
+<a name="l01097"></a>01097         <span class="keywordflow">for</span> ( i = 0 ; i < nfree ; fpar[parptr[i++]] = 0.0 ) ; 
+<a name="l01098"></a>01098         sinfo_new_get_mat_edge(xdat,xdim,ydat,wdat,ndat,fpar,epar<span class="comment">/*, npar */</span>) ;
+<a name="l01099"></a>01099         r =  sinfo_new_get_vec_edge ( xdat, xdim, ydat, wdat, ndat, 
+<a name="l01100"></a>01100                                       fpar, epar, npar ) ;
+<a name="l01101"></a>01101         <span class="keywordflow">if</span> ( r )                         <span class="comment">/* error */</span>
+<a name="l01102"></a>01102         {
+<a name="l01103"></a>01103             <span class="keywordflow">return</span> r ;
+<a name="l01104"></a>01104         }
+<a name="l01105"></a>01105         <span class="keywordflow">for</span> ( i = 0 ; i < (*npar) ; i++ )
+<a name="l01106"></a>01106         {
+<a name="l01107"></a>01107             fpar[i] = epar[i] ;           <span class="comment">/* save new parameters */</span>
+<a name="l01108"></a>01108             epar[i] = 0.0 ;               <span class="comment">/* and set errors to zero */</span>
+<a name="l01109"></a>01109         }
+<a name="l01110"></a>01110         chi1 = sqrt( chi1 / (<span class="keywordtype">double</span>) (nuse - nfree) ) ;
+<a name="l01111"></a>01111         <span class="keywordflow">for</span> ( i = 0 ; i < nfree ; i++ )
+<a name="l01112"></a>01112         {
+<a name="l01113"></a>01113             <span class="keywordflow">if</span> ( (matrix1[i][i] <= 0.0 ) || (matrix2[i][i] <= 0.0) )
+<a name="l01114"></a>01114             {
+<a name="l01115"></a>01115                 <span class="keywordflow">return</span> -7 ;
+<a name="l01116"></a>01116             }
+<a name="l01117"></a>01117             epar[parptr[i]] = chi1 * sqrt( matrix2[i][i] ) / 
+<a name="l01118"></a>01118                                      sqrt( matrix1[i][i] ) ;
+<a name="l01119"></a>01119         }
+<a name="l01120"></a>01120     }
+<a name="l01121"></a>01121     <span class="keywordflow">else</span>                                  <span class="comment">/* non-linear fit */</span>
+<a name="l01122"></a>01122     {
+<a name="l01123"></a>01123         <span class="comment">/*----------------------------------------------------------------</span>
+<a name="l01124"></a>01124 <span class="comment">         * the non-linear fit uses the steepest descent method in combination</span>
+<a name="l01125"></a>01125 <span class="comment">         * with the Taylor method. The mixing of these methods is controlled</span>
+<a name="l01126"></a>01126 <span class="comment">         * by labda. In the outer loop ( called the iteration loop ) we build</span>
+<a name="l01127"></a>01127 <span class="comment">         * the sinfo_matrix and calculate the correction sinfo_vector. In the </span>
+<a name="l01128"></a>01128 <span class="comment">         * inner loop</span>
+<a name="l01129"></a>01129 <span class="comment">         * (called the interpolation loop) we check whether we have obtained a</span>
+<a name="l01130"></a>01130 <span class="comment">         * better solution than the previous one. If so, we leave the inner loop</span>
+<a name="l01131"></a>01131 <span class="comment">         * else we increase labda ( give more weight to the steepest descent </span>
+<a name="l01132"></a>01132 <span class="comment">         * method) calculate the correction sinfo_vector and check again. </span>
+<a name="l01133"></a>01133 <span class="comment">         * After the inner loop</span>
+<a name="l01134"></a>01134 <span class="comment">         * we do a final check on the goodness of the fit and if this satisfies</span>
+<a name="l01135"></a>01135 <span class="comment">         * the tolerance we calculate the errors of the fitted parameters.</span>
+<a name="l01136"></a>01136 <span class="comment">         */</span>
+<a name="l01137"></a>01137         <span class="keywordflow">while</span> ( !found )                  <span class="comment">/* iteration loop */</span>
+<a name="l01138"></a>01138         {      
+<a name="l01139"></a>01139             <span class="keywordflow">if</span> ( itc++ == (*its) )        <span class="comment">/* increase iteration counter */</span>
+<a name="l01140"></a>01140             {
+<a name="l01141"></a>01141                 <span class="keywordflow">return</span> -4 ;               
+<a name="l01142"></a>01142             }
+<a name="l01143"></a>01143             sinfo_new_get_mat_edge( xdat, xdim, ydat, wdat, ndat, 
+<a name="l01144"></a>01144                                     fpar, epar<span class="comment">/*, npar*/</span> ) ;
+<a name="l01145"></a>01145             
+<a name="l01146"></a>01146             <span class="comment">/*-------------------------------------------------------------</span>
+<a name="l01147"></a>01147 <span class="comment">             * here we decrease labda since we may assume that each iteration</span>
+<a name="l01148"></a>01148 <span class="comment">             * brings us closer to the answer.</span>
+<a name="l01149"></a>01149 <span class="comment">             */</span>
+<a name="l01150"></a>01150             <span class="keywordflow">if</span> ( labda > LABMINA )
+<a name="l01151"></a>01151             {
+<a name="l01152"></a>01152                 labda = labda / LABFACA ;         <span class="comment">/* decrease labda */</span>
+<a name="l01153"></a>01153             }
+<a name="l01154"></a>01154             r = sinfo_new_get_vec_edge ( xdat, xdim, ydat, wdat, ndat, 
+<a name="l01155"></a>01155                                          fpar, epar, npar ) ;
+<a name="l01156"></a>01156             <span class="keywordflow">if</span> ( (<span class="keywordtype">int</span>)fpar[1] - (<span class="keywordtype">int</span>)fpar[0] <= 0 && fpar[1] / fpar[0] > 0. )
+<a name="l01157"></a>01157             {
+<a name="l01158"></a>01158                 fpar[1] += 1. ;
+<a name="l01159"></a>01159                 continue ;
+<a name="l01160"></a>01160             } 
+<a name="l01161"></a>01161             <span class="keywordflow">if</span> ( r )                      <span class="comment">/* error */</span>
+<a name="l01162"></a>01162             {
+<a name="l01163"></a>01163                 <span class="keywordflow">return</span> r ;
+<a name="l01164"></a>01164             }
+<a name="l01165"></a>01165 
+<a name="l01166"></a>01166             <span class="keywordflow">while</span> ( chi1 >= chi2 )        <span class="comment">/* interpolation loop */</span>
+<a name="l01167"></a>01167             {
+<a name="l01168"></a>01168                 <span class="comment">/*-----------------------------------------------------------</span>
+<a name="l01169"></a>01169 <span class="comment">                 * The next statement is based on experience, not on the </span>
+<a name="l01170"></a>01170 <span class="comment">                 * mathematics of the problem. It is assumed that we have </span>
+<a name="l01171"></a>01171 <span class="comment">                 * reached convergence when the pure steepest descent method </span>
+<a name="l01172"></a>01172 <span class="comment">                 * does not produce a better solution.</span>
+<a name="l01173"></a>01173 <span class="comment">                 */</span>
+<a name="l01174"></a>01174                 <span class="keywordflow">if</span> ( labda > LABMAXA )    <span class="comment">/* assume solution found */</span>
+<a name="l01175"></a>01175                 {
+<a name="l01176"></a>01176                     break ;
+<a name="l01177"></a>01177                 }
+<a name="l01178"></a>01178                 labda = labda * LABFACA ;   <span class="comment">/* increase mixing parameter */</span>
+<a name="l01179"></a>01179                 r = sinfo_new_get_vec_edge ( xdat, xdim, ydat, wdat, 
+<a name="l01180"></a>01180                                              ndat, fpar, epar, npar ) ;
+<a name="l01181"></a>01181                 <span class="keywordflow">if</span> ( (<span class="keywordtype">int</span>)fpar[1] - (<span class="keywordtype">int</span>)fpar[0] <= 0 && 
+<a name="l01182"></a>01182                      fpar[1] / fpar[0] > 0. )
+<a name="l01183"></a>01183                 {
+<a name="l01184"></a>01184                     fpar[1] += 1. ;
+<a name="l01185"></a>01185                     continue ;
+<a name="l01186"></a>01186                 } 
+<a name="l01187"></a>01187                 <span class="keywordflow">if</span> ( r )                  <span class="comment">/* error */</span>
+<a name="l01188"></a>01188                 {
+<a name="l01189"></a>01189                     <span class="keywordflow">return</span> r ;
+<a name="l01190"></a>01190                 }
+<a name="l01191"></a>01191             }
+<a name="l01192"></a>01192 
+<a name="l01193"></a>01193             <span class="keywordflow">if</span> ( labda <= LABMAXA )        <span class="comment">/* save old parameters */</span>
+<a name="l01194"></a>01194             {
+<a name="l01195"></a>01195                 <span class="keywordflow">for</span> ( i = 0 ; i < *npar ; i++ )
+<a name="l01196"></a>01196                 {
+<a name="l01197"></a>01197                     fpar[i] = epar[i] ;
+<a name="l01198"></a>01198                 }
+<a name="l01199"></a>01199             }
+<a name="l01200"></a>01200             <span class="keywordflow">if</span> ( (fabs( chi2 - chi1 ) <= (tolerance * chi1)) || 
+<a name="l01201"></a>01201                   (labda > LABMAXA) )
+<a name="l01202"></a>01202             {
+<a name="l01203"></a>01203                 <span class="comment">/*------------------------------------------------------------</span>
+<a name="l01204"></a>01204 <span class="comment">                 * we have a satisfying solution, so now we need to calculate </span>
+<a name="l01205"></a>01205 <span class="comment">                 * the correct errors of the fitted parameters. This we do by </span>
+<a name="l01206"></a>01206 <span class="comment">                 * using the pure Taylor method because we are very close to </span>
+<a name="l01207"></a>01207 <span class="comment">                 * the real solution.</span>
+<a name="l01208"></a>01208 <span class="comment">                 */</span>
+<a name="l01209"></a>01209                 labda = LABMINA ;              <span class="comment">/* for Taylor solution */</span>
+<a name="l01210"></a>01210                 sinfo_new_get_mat_edge ( xdat, xdim, ydat, wdat, ndat, 
+<a name="l01211"></a>01211                                          fpar, epar<span class="comment">/*, npar */</span>) ;
+<a name="l01212"></a>01212                 r = sinfo_new_get_vec_edge ( xdat, xdim, ydat, wdat, 
+<a name="l01213"></a>01213                                              ndat, fpar, epar, npar ) ;
+<a name="l01214"></a>01214 
+<a name="l01215"></a>01215                 <span class="keywordflow">if</span> ( r )                    <span class="comment">/* error */</span>
+<a name="l01216"></a>01216                 {
+<a name="l01217"></a>01217                     <span class="keywordflow">return</span> r ;
+<a name="l01218"></a>01218                 }
+<a name="l01219"></a>01219                 <span class="keywordflow">for</span> ( i = 0 ; i < (*npar) ; i++ )
+<a name="l01220"></a>01220                 {
+<a name="l01221"></a>01221                     epar[i] = 0.0 ;          <span class="comment">/* set error to zero */</span>
+<a name="l01222"></a>01222                 }
+<a name="l01223"></a>01223                 chi2 = sqrt ( chi2 / (<span class="keywordtype">double</span>) (nuse - nfree) ) ;
+<a name="l01224"></a>01224 
+<a name="l01225"></a>01225                 <span class="keywordflow">for</span> ( i = 0 ; i < nfree ; i++ )
+<a name="l01226"></a>01226                 {
+<a name="l01227"></a>01227                     <span class="keywordflow">if</span> ( (matrix1[i][i] <= 0.0) || (matrix2[i][i] <= 0.0) )
+<a name="l01228"></a>01228                     {
+<a name="l01229"></a>01229                         <span class="keywordflow">return</span> -7 ;
+<a name="l01230"></a>01230                     }
+<a name="l01231"></a>01231                     epar[parptr[i]] = chi2 * sqrt( matrix2[i][i] ) / 
+<a name="l01232"></a>01232                                              sqrt( matrix1[i][i] ) ;
+<a name="l01233"></a>01233                 }
+<a name="l01234"></a>01234                 found = 1 ;                  <span class="comment">/* we found a solution */</span>
+<a name="l01235"></a>01235             }
+<a name="l01236"></a>01236         }
+<a name="l01237"></a>01237     }
+<a name="l01238"></a>01238     <span class="keywordflow">return</span> itc ;                             <span class="comment">/* return number of iterations */</span>
+<a name="l01239"></a>01239 }
+<a name="l01268"></a>01268 <span class="keywordtype">int</span> 
+<a name="l01269"></a>01269 sinfo_new_fit_slits1( cpl_image   * lineImage, 
+<a name="l01270"></a>01270                FitParams ** par,
+<a name="l01271"></a>01271                <span class="keywordtype">float</span>     ** sinfo_slit_pos,
+<a name="l01272"></a>01272                <span class="keywordtype">int</span>          box_length,
+<a name="l01273"></a>01273                <span class="keywordtype">float</span>        y_box )
+<a name="l01274"></a>01274 {
+<a name="l01275"></a>01275     <span class="keywordtype">float</span>* position=NULL ;
+<a name="l01276"></a>01276     <span class="keywordtype">int</span>   * sinfo_edge, * edgeclean ;
+<a name="l01277"></a>01277     <span class="keywordtype">int</span>   * dummyedge ;
+<a name="l01278"></a>01278     <span class="keywordtype">int</span>   * pos_row, * pos_rowclean ;
+<a name="l01279"></a>01279     Vector * box_buffer ;
+<a name="l01280"></a>01280     <span class="keywordtype">float</span> max_intensity ;
+<a name="l01281"></a>01281     <span class="keywordtype">float</span> row_pos ;
+<a name="l01282"></a>01282     <span class="keywordtype">int</span>   col ;
+<a name="l01283"></a>01283     <span class="keywordtype">int</span>   i, j, k, m, n, ed ;
+<a name="l01284"></a>01284     <span class="keywordtype">int</span>   found, init1, init2 ;
+<a name="l01285"></a>01285     <span class="keywordtype">int</span>   line ; 
+<a name="l01286"></a>01286     <span class="keywordtype">int</span>   column ;
+<a name="l01287"></a>01287     <span class="keywordtype">int</span>   slit_length ;
+<a name="l01288"></a>01288     <span class="keywordtype">int</span>   agreed ;
+<a name="l01289"></a>01289     <span class="keywordtype">int</span>   bad_line ;
+<a name="l01290"></a>01290     <span class="keywordtype">int</span>   margin ;
+<a name="l01291"></a>01291     <span class="keywordtype">int</span>   iters, xdim, ndat ;
+<a name="l01292"></a>01292     <span class="keywordtype">int</span>   numpar, its ;
+<a name="l01293"></a>01293     <span class="keywordtype">int</span>   * mpar ;
+<a name="l01294"></a>01294     <span class="keywordtype">float</span> * xdat, * wdat ;
+<a name="l01295"></a>01295     <span class="keywordtype">float</span> tol, lab ;
+<a name="l01296"></a>01296     <span class="keywordtype">float</span> fitpar[2*NPAR] ;
+<a name="l01297"></a>01297     <span class="keywordtype">float</span> dervpar[NPAR] ;
+<a name="l01298"></a>01298     <span class="keywordtype">float</span> minval, maxval ;
+<a name="l01299"></a>01299     <span class="keywordtype">int</span> ilx=0;
+<a name="l01300"></a>01300     <span class="keywordtype">int</span> ily=0;
+<a name="l01301"></a>01301     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l01302"></a>01302 
+<a name="l01303"></a>01303 
+<a name="l01304"></a>01304     <span class="keywordflow">if</span> ( NULL == lineImage )
+<a name="l01305"></a>01305     {
+<a name="l01306"></a>01306         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no line image given!"</span> ) ;
+<a name="l01307"></a>01307         <span class="keywordflow">return</span> -1 ;
+<a name="l01308"></a>01308     }
+<a name="l01309"></a>01309     ilx=cpl_image_get_size_x(lineImage);
+<a name="l01310"></a>01310     ily=cpl_image_get_size_y(lineImage);
+<a name="l01311"></a>01311     pidata=cpl_image_get_data_float(lineImage);
+<a name="l01312"></a>01312 
+<a name="l01313"></a>01313     slit_length = (int) sqrt (ilx) ;
+<a name="l01314"></a>01314     <span class="keywordflow">if</span> ( NULL == par )
+<a name="l01315"></a>01315     {
+<a name="l01316"></a>01316         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no line fit parameters given!"</span>) ;
+<a name="l01317"></a>01317         <span class="keywordflow">return</span> -2 ;
+<a name="l01318"></a>01318     }
+<a name="l01319"></a>01319 
+<a name="l01320"></a>01320     <span class="keywordflow">if</span> ( NULL == sinfo_slit_pos )
+<a name="l01321"></a>01321     {
+<a name="l01322"></a>01322         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no position array allocated!"</span>) ;
+<a name="l01323"></a>01323         <span class="keywordflow">return</span> -3 ;
+<a name="l01324"></a>01324     }
+<a name="l01325"></a>01325 
+<a name="l01326"></a>01326     <span class="keywordflow">if</span> ( box_length <  slit_length ||
+<a name="l01327"></a>01327          box_length >= 3*slit_length )
+<a name="l01328"></a>01328     {
+<a name="l01329"></a>01329         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"wrong fitting box length given!"</span> ) ;
+<a name="l01330"></a>01330         <span class="keywordflow">return</span> -4 ;
+<a name="l01331"></a>01331     }
+<a name="l01332"></a>01332 
+<a name="l01333"></a>01333     <span class="keywordflow">if</span> ( y_box <= 0.  || y_box > 3. )
+<a name="l01334"></a>01334     {
+<a name="l01335"></a>01335         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"wrong y box length given!"</span> ) ;
+<a name="l01336"></a>01336         <span class="keywordflow">return</span> -5 ;
+<a name="l01337"></a>01337     }
+<a name="l01338"></a>01338 
+<a name="l01339"></a>01339     <span class="comment">/* allocate memory for the edges and the row positon of the slitlets */</span>
+<a name="l01340"></a>01340     sinfo_edge         = (<span class="keywordtype">int</span>*) cpl_calloc( 3*slit_length, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>) ) ;
+<a name="l01341"></a>01341     dummyedge    = (<span class="keywordtype">int</span>*) cpl_calloc( 3*slit_length, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>) ) ;
+<a name="l01342"></a>01342     edgeclean    = (<span class="keywordtype">int</span>*) cpl_calloc( slit_length-1, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>) ) ;
+<a name="l01343"></a>01343     pos_row      = (<span class="keywordtype">int</span>*) cpl_calloc( 3*slit_length, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>) ) ;
+<a name="l01344"></a>01344     pos_rowclean = (<span class="keywordtype">int</span>*) cpl_calloc( slit_length, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>) ) ;
+<a name="l01345"></a>01345 
+<a name="l01346"></a>01346     <span class="comment">/* ------------------------------------------------------------------------</span>
+<a name="l01347"></a>01347 <span class="comment">     * go through the first image columns and the fit parameters and find </span>
+<a name="l01348"></a>01348 <span class="comment">     *  the line with the highest intensity </span>
+<a name="l01349"></a>01349 <span class="comment">     */</span>
+<a name="l01350"></a>01350     agreed = -1 ;
+<a name="l01351"></a>01351     bad_line = -1 ;
+<a name="l01352"></a>01352     <span class="keywordflow">while</span>( agreed == -1 )
+<a name="l01353"></a>01353     {
+<a name="l01354"></a>01354         found = -1 ;
+<a name="l01355"></a>01355         max_intensity = -FLT_MAX ;
+<a name="l01356"></a>01356         <span class="keywordflow">for</span> ( col = 0 ; col < box_length ; col++ )
+<a name="l01357"></a>01357         {
+<a name="l01358"></a>01358             <span class="keywordflow">for</span> ( i = 0 ; i < par[0]->n_params ; i++ )
+<a name="l01359"></a>01359             {
+<a name="l01360"></a>01360                 <span class="keywordflow">if</span> ( par[i]->column == col && par[i]->line != bad_line )
+<a name="l01361"></a>01361                 {
+<a name="l01362"></a>01362                     <span class="keywordflow">if</span> ( par[i]->fit_par[0] > max_intensity )
+<a name="l01363"></a>01363                     {
+<a name="l01364"></a>01364                         <span class="keywordflow">if</span> ( par[i]->fit_par[1] > 0. )
+<a name="l01365"></a>01365                         {
+<a name="l01366"></a>01366                             max_intensity = par[i]->fit_par[0] ;
+<a name="l01367"></a>01367                             found = i ;
+<a name="l01368"></a>01368                         }
+<a name="l01369"></a>01369                     }
+<a name="l01370"></a>01370                 }
+<a name="l01371"></a>01371             }  
+<a name="l01372"></a>01372         }
+<a name="l01373"></a>01373 
+<a name="l01374"></a>01374         <span class="comment">/* --------------------------------------------------------------------</span>
+<a name="l01375"></a>01375 <span class="comment">         * check if the found line is usable and if the neighbouring line </span>
+<a name="l01376"></a>01376 <span class="comment">         * have intensity on near rows in neighbouring slitlets </span>
+<a name="l01377"></a>01377 <span class="comment">         */</span>
+<a name="l01378"></a>01378         line    = par[found]->line ;
+<a name="l01379"></a>01379         column  = par[found]->column ;
+<a name="l01380"></a>01380         row_pos = par[found]->fit_par[2] ;
+<a name="l01381"></a>01381         <span class="keywordflow">if</span> ( found >= 0 && max_intensity > 0. )
+<a name="l01382"></a>01382         {
+<a name="l01383"></a>01383             <span class="keywordflow">for</span> ( i = 0 ; i < par[0]->n_params ; i++ )
+<a name="l01384"></a>01384             {
+<a name="l01385"></a>01385                 <span class="keywordflow">if</span> ( par[i]->line == line-1 && 
+<a name="l01386"></a>01386                      par[i]->column == column + slit_length )
+<a name="l01387"></a>01387                 {
+<a name="l01388"></a>01388                     <span class="keywordflow">if</span> ( par[i]->fit_par[2] <= (row_pos + y_box) &&
+<a name="l01389"></a>01389                          par[i]->fit_par[2] >= (row_pos - y_box) )
+<a name="l01390"></a>01390                     {
+<a name="l01391"></a>01391                         bad_line = line ;
+<a name="l01392"></a>01392                     } 
+<a name="l01393"></a>01393                 }
+<a name="l01394"></a>01394             }
+<a name="l01395"></a>01395             <span class="keywordflow">if</span> ( bad_line != line )
+<a name="l01396"></a>01396             {
+<a name="l01397"></a>01397                 agreed = 1 ;
+<a name="l01398"></a>01398                 break ;
+<a name="l01399"></a>01399             }
+<a name="l01400"></a>01400         }
+<a name="l01401"></a>01401         <span class="keywordflow">else</span> 
+<a name="l01402"></a>01402         {
+<a name="l01403"></a>01403           <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no emission line found in the first image columns"</span>);
+<a name="l01404"></a>01404           <span class="keywordflow">return</span> -6 ;
+<a name="l01405"></a>01405         }    
+<a name="l01406"></a>01406     }
+<a name="l01407"></a>01407 
+<a name="l01408"></a>01408  
+<a name="l01409"></a>01409     <span class="keywordflow">if</span> ( agreed == -1 )
+<a name="l01410"></a>01410     {
+<a name="l01411"></a>01411         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no emission line found in the first image columns"</span>) ;
+<a name="l01412"></a>01412         <span class="keywordflow">return</span> -6 ;
+<a name="l01413"></a>01413     }    
+<a name="l01414"></a>01414  
+<a name="l01415"></a>01415     <span class="comment">/* now find and store the raw sinfo_edge positions of the found slitlet */</span> 
+<a name="l01416"></a>01416     n  = 0 ;
+<a name="l01417"></a>01417     ed = 0 ;
+<a name="l01418"></a>01418   
+<a name="l01419"></a>01419 
+<a name="l01420"></a>01420     position=cpl_calloc(ilx,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>));
+<a name="l01421"></a>01421     <span class="keywordflow">for</span> ( col = 0 ; col < ilx ; col++ )
+<a name="l01422"></a>01422     {
+<a name="l01423"></a>01423         <span class="keywordflow">for</span> ( i = 0 ; i < par[0]->n_params ; i++ )
+<a name="l01424"></a>01424         {
+<a name="l01425"></a>01425             <span class="keywordflow">if</span> ( par[i]->column == col && par[i] -> line == line )
+<a name="l01426"></a>01426             {
+<a name="l01427"></a>01427                 <span class="keywordflow">if</span> ( par[i]->fit_par[0] > 0. && par[i]->fit_par[1] > 0. )
+<a name="l01428"></a>01428                 {
+<a name="l01429"></a>01429                     position[n] = par[i]->fit_par[2] ;
+<a name="l01430"></a>01430                     <span class="keywordflow">if</span> ( n > 0 && fabs(position[n] - position[n-1]) > y_box )
+<a name="l01431"></a>01431                     {
+<a name="l01432"></a>01432                         sinfo_edge[ed] = col ; 
+<a name="l01433"></a>01433                         pos_row[ed] = sinfo_new_nint( position[n-1] ) ;
+<a name="l01434"></a>01434                         ed++ ;
+<a name="l01435"></a>01435                         <span class="keywordflow">if</span> ( col >= ilx - slit_length - 5 ) 
+<a name="l01436"></a>01436                         {
+<a name="l01437"></a>01437                             pos_row[ed] =  sinfo_new_nint( position[n] ) ;
+<a name="l01438"></a>01438                         }
+<a name="l01439"></a>01439                     }
+<a name="l01440"></a>01440                     n++ ;
+<a name="l01441"></a>01441                 }
+<a name="l01442"></a>01442             }
+<a name="l01443"></a>01443         }
+<a name="l01444"></a>01444     }
+<a name="l01445"></a>01445     <span class="keywordflow">if</span> ( ed < (slit_length - 1) )
+<a name="l01446"></a>01446     {
+<a name="l01447"></a>01447         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"not enough slitlets found"</span>) ;
+<a name="l01448"></a>01448         <span class="keywordflow">return</span> -7 ;
+<a name="l01449"></a>01449     } 
+<a name="l01450"></a>01450 
+<a name="l01451"></a>01451     <span class="comment">/* now find the clean sinfo_edge and row positions of the slitlets */</span>
+<a name="l01452"></a>01452     <span class="keywordflow">for</span> ( i = 1 ; i <= ed ; i ++ )
+<a name="l01453"></a>01453     {
+<a name="l01454"></a>01454         <span class="keywordflow">if</span> (dummyedge[i-1] != -1)
+<a name="l01455"></a>01455         {
+<a name="l01456"></a>01456             dummyedge[i-1] = sinfo_edge[i-1] ;
+<a name="l01457"></a>01457         }
+<a name="l01458"></a>01458         <span class="keywordflow">if</span> ( (sinfo_edge[i] - sinfo_edge[i-1]) < slit_length - 3 ||
+<a name="l01459"></a>01459              (sinfo_edge[i] - sinfo_edge[i-1]) > slit_length + 3 )
+<a name="l01460"></a>01460         {
+<a name="l01461"></a>01461             dummyedge[i]   = -1 ;
+<a name="l01462"></a>01462         }
+<a name="l01463"></a>01463         <span class="keywordflow">if</span> ( (sinfo_edge[i+1] - sinfo_edge[i]) < slit_length - 3 ||
+<a name="l01464"></a>01464              (sinfo_edge[i+1] - sinfo_edge[i]) > slit_length + 3 )
+<a name="l01465"></a>01465         {
+<a name="l01466"></a>01466             dummyedge[i+1] = -1 ; 
+<a name="l01467"></a>01467         }
+<a name="l01468"></a>01468     }
+<a name="l01469"></a>01469     
+<a name="l01470"></a>01470     k = 0 ;
+<a name="l01471"></a>01471     <span class="keywordflow">for</span> ( i = 0 ; i < ed ; i++ )
+<a name="l01472"></a>01472     {
+<a name="l01473"></a>01473         <span class="keywordflow">if</span> ( dummyedge[i] != -1 && dummyedge[i] != 0 )
+<a name="l01474"></a>01474         {
+<a name="l01475"></a>01475             edgeclean[k] = dummyedge[i] ;
+<a name="l01476"></a>01476             pos_rowclean[k] = pos_row[i] ;
+<a name="l01477"></a>01477             k++ ;
+<a name="l01478"></a>01478             <span class="keywordflow">if</span>( edgeclean[k-1] > (ilx - slit_length - 6 ) )
+<a name="l01479"></a>01479             {
+<a name="l01480"></a>01480                 pos_rowclean[k] = pos_row[ed] ;
+<a name="l01481"></a>01481             }
+<a name="l01482"></a>01482         }
+<a name="l01483"></a>01483     }
+<a name="l01484"></a>01484 
+<a name="l01485"></a>01485     <span class="keywordflow">if</span> ( k != slit_length - 1 )
+<a name="l01486"></a>01486     {
+<a name="l01487"></a>01487         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"not enough clean slitlets found"</span>) ;
+<a name="l01488"></a>01488         <span class="keywordflow">return</span> -7 ;
+<a name="l01489"></a>01489     } 
+<a name="l01490"></a>01490 
+<a name="l01491"></a>01491     <span class="comment">/* determine the margins of the fitting box outside the slitlets */</span>
+<a name="l01492"></a>01492     margin = ( box_length - slit_length ) / 2 ;
+<a name="l01493"></a>01493 
+<a name="l01494"></a>01494     <span class="comment">/* now go through the slitlets and store the intensity in a </span>
+<a name="l01495"></a>01495 <span class="comment">       buffer sinfo_vector */</span>
+<a name="l01496"></a>01496     <span class="keywordflow">for</span> ( j = 0 ; j < k ; j++ )
+<a name="l01497"></a>01497     {
+<a name="l01498"></a>01498         m = 0 ;
+<a name="l01499"></a>01499         <span class="keywordflow">if</span> ( j == 0 )
+<a name="l01500"></a>01500         {
+<a name="l01501"></a>01501             box_buffer = sinfo_new_vector( edgeclean[0] + margin ) ;
+<a name="l01502"></a>01502             <span class="keywordflow">for</span>( col = 0 ; col < edgeclean[0] + margin ; col++ )
+<a name="l01503"></a>01503             {
+<a name="l01504"></a>01504                 box_buffer->data[m] = pidata[col + ilx*pos_rowclean[0]] ;
+<a name="l01505"></a>01505                 m++ ;
+<a name="l01506"></a>01506             }
+<a name="l01507"></a>01507             fitpar[0] = 3. ;
+<a name="l01508"></a>01508             fitpar[1] = 5. ;
+<a name="l01509"></a>01509             fitpar[2] = (float) edgeclean[0] - 1. ;
+<a name="l01510"></a>01510             fitpar[3] = (float) edgeclean[0] + 1. ;
+<a name="l01511"></a>01511           
+<a name="l01512"></a>01512         }
+<a name="l01513"></a>01513         <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( j < k - 1 )
+<a name="l01514"></a>01514         {
+<a name="l01515"></a>01515             box_buffer = sinfo_new_vector( edgeclean[j] - 
+<a name="l01516"></a>01516                                            edgeclean[j-1] + 2*margin ) ;
+<a name="l01517"></a>01517             <span class="keywordflow">for</span> ( col = edgeclean[j - 1] - margin ; 
+<a name="l01518"></a>01518                   col < edgeclean[j] + margin ; col++ )
+<a name="l01519"></a>01519             {
+<a name="l01520"></a>01520                 box_buffer->data[m] = pidata[col + ilx*pos_rowclean[j]] ;
+<a name="l01521"></a>01521                 m++ ;
+<a name="l01522"></a>01522             }
+<a name="l01523"></a>01523             fitpar[0] = (float) margin - 1. ;
+<a name="l01524"></a>01524             fitpar[1] = (float) margin + 1. ;
+<a name="l01525"></a>01525             fitpar[2] = (float) (edgeclean[j] - edgeclean[j-1] + margin) - 1. ;
+<a name="l01526"></a>01526             fitpar[3] = (float) (edgeclean[j] - edgeclean[j-1] + margin) + 1. ;
+<a name="l01527"></a>01527         }
+<a name="l01528"></a>01528         <span class="comment">/*else if ( j == k - 1 )*/</span>
+<a name="l01529"></a>01529         <span class="keywordflow">else</span>
+<a name="l01530"></a>01530         {
+<a name="l01531"></a>01531             box_buffer = sinfo_new_vector( ilx - edgeclean[k-1] + margin ) ;
+<a name="l01532"></a>01532             <span class="keywordflow">for</span> ( col = edgeclean[k - 1] - margin ; col < ilx ; col++ )
+<a name="l01533"></a>01533             {
+<a name="l01534"></a>01534                 box_buffer->data[m] = pidata[col + ilx*pos_rowclean[k]] ;
+<a name="l01535"></a>01535                 m++ ;
+<a name="l01536"></a>01536             }
+<a name="l01537"></a>01537             fitpar[0] = (float) margin - 1. ;
+<a name="l01538"></a>01538             fitpar[1] = (float) margin + 1. ;
+<a name="l01539"></a>01539             fitpar[2] = (float) (ilx - edgeclean[k-1] + margin) - 3. ;
+<a name="l01540"></a>01540             fitpar[3] = (float) (ilx - edgeclean[k-1] + margin) - 1. ;
+<a name="l01541"></a>01541         }
+<a name="l01542"></a>01542 
+<a name="l01543"></a>01543         xdat = (<span class="keywordtype">float</span> *) cpl_calloc(box_buffer -> n_elements,<span class="keyword">sizeof</span> (<span class="keywordtype">float</span>) ) ;
+<a name="l01544"></a>01544         wdat = (<span class="keywordtype">float</span> *) cpl_calloc(box_buffer -> n_elements,<span class="keyword">sizeof</span> (<span class="keywordtype">float</span>) ) ;
+<a name="l01545"></a>01545         mpar = (<span class="keywordtype">int</span> *)   cpl_calloc(NPAR, <span class="keyword">sizeof</span> (<span class="keywordtype">int</span>) ) ;
+<a name="l01546"></a>01546 
+<a name="l01547"></a>01547         <span class="comment">/* set initial values for the fitting routine */</span>
+<a name="l01548"></a>01548         minval =  FLT_MAX ;
+<a name="l01549"></a>01549         maxval = -FLT_MAX ;
+<a name="l01550"></a>01550         <span class="keywordflow">for</span> ( i = 0 ; i < box_buffer->n_elements ; i++ )
+<a name="l01551"></a>01551         {
+<a name="l01552"></a>01552             xdat[i] = i ;
+<a name="l01553"></a>01553             wdat[i] = 1.0 ;
+<a name="l01554"></a>01554             <span class="keywordflow">if</span> ( box_buffer -> data[i] < minval )
+<a name="l01555"></a>01555             {
+<a name="l01556"></a>01556                 minval = box_buffer -> data[i] ;
+<a name="l01557"></a>01557             }
+<a name="l01558"></a>01558             <span class="keywordflow">if</span> ( box_buffer -> data[i] > maxval )
+<a name="l01559"></a>01559             {
+<a name="l01560"></a>01560                 maxval = box_buffer -> data[i] ;
+<a name="l01561"></a>01561             }
+<a name="l01562"></a>01562         }
+<a name="l01563"></a>01563 
+<a name="l01564"></a>01564         fitpar[4] = minval ;
+<a name="l01565"></a>01565         fitpar[5] = minval ;
+<a name="l01566"></a>01566         fitpar[6] = maxval ; 
+<a name="l01567"></a>01567         fitpar[7] = maxval ;
+<a name="l01568"></a>01568 
+<a name="l01569"></a>01569         <span class="comment">/* search for both positions of the half intensity of the </span>
+<a name="l01570"></a>01570 <span class="comment">           hat within the buffer */</span>
+<a name="l01571"></a>01571         init1 = -1 ; 
+<a name="l01572"></a>01572         init2 = -1 ;
+<a name="l01573"></a>01573         <span class="keywordflow">for</span> ( i = 0 ; i < box_buffer->n_elements ; i++ )
+<a name="l01574"></a>01574         {
+<a name="l01575"></a>01575             <span class="keywordflow">if</span> ( box_buffer -> data[i] >= ( maxval - minval ) / 2. )
+<a name="l01576"></a>01576             {
+<a name="l01577"></a>01577                 init1 = i ;
+<a name="l01578"></a>01578                 break ;
+<a name="l01579"></a>01579             }
+<a name="l01580"></a>01580         }
+<a name="l01581"></a>01581 
+<a name="l01582"></a>01582         <span class="keywordflow">for</span> ( i = box_buffer->n_elements - 1 ; i >= 0  ; i-- )
+<a name="l01583"></a>01583         {
+<a name="l01584"></a>01584             <span class="keywordflow">if</span> ( box_buffer -> data[i] >= ( maxval + minval ) / 2. )
+<a name="l01585"></a>01585             {
+<a name="l01586"></a>01586                 init2 = i ;
+<a name="l01587"></a>01587                 break ;
+<a name="l01588"></a>01588             }
+<a name="l01589"></a>01589         }
+<a name="l01590"></a>01590   
+<a name="l01591"></a>01591         <span class="comment">/* determine the initial positions from the found values */</span>
+<a name="l01592"></a>01592       <span class="comment">/*  if ( init1 != -1 )</span>
+<a name="l01593"></a>01593 <span class="comment">        {</span>
+<a name="l01594"></a>01594 <span class="comment">            fitpar[0] = init1 - 1. ;</span>
+<a name="l01595"></a>01595 <span class="comment">            fitpar[1] = init1 + 1. ;</span>
+<a name="l01596"></a>01596 <span class="comment">        }</span>
+<a name="l01597"></a>01597 <span class="comment">        if ( init2 != -1 )</span>
+<a name="l01598"></a>01598 <span class="comment">        {</span>
+<a name="l01599"></a>01599 <span class="comment">            fitpar[2] = init2 - 1. ;</span>
+<a name="l01600"></a>01600 <span class="comment">            fitpar[3] = init2 + 1. ;</span>
+<a name="l01601"></a>01601 <span class="comment">        } */</span>
+<a name="l01602"></a>01602 
+<a name="l01603"></a>01603         <span class="keywordflow">for</span> ( i = 0 ; i < NPAR ; i++ )
+<a name="l01604"></a>01604         {
+<a name="l01605"></a>01605             mpar[i] = 1 ;
+<a name="l01606"></a>01606             dervpar[i] = 0. ;
+<a name="l01607"></a>01607         }
+<a name="l01608"></a>01608      
+<a name="l01609"></a>01609         xdim     = XDIMA ;
+<a name="l01610"></a>01610         ndat     = box_buffer -> n_elements ;
+<a name="l01611"></a>01611         numpar   = NPAR ;
+<a name="l01612"></a>01612         tol      = TOLA ;
+<a name="l01613"></a>01613         lab      = LABA ;
+<a name="l01614"></a>01614         its      = ITSA ;
+<a name="l01615"></a>01615         
+<a name="l01616"></a>01616         <span class="comment">/* finally, do the least squares fit over the buffer data */</span>
+<a name="l01617"></a>01617         <span class="keywordflow">if</span> ( 0 > ( iters = sinfo_new_lsqfit_edge( xdat, &xdim, 
+<a name="l01618"></a>01618                                                   box_buffer -> data, 
+<a name="l01619"></a>01619                                                   wdat, &ndat, fitpar,
+<a name="l01620"></a>01620                                                   dervpar, mpar, 
+<a name="l01621"></a>01621                                                   &numpar, &tol, 
+<a name="l01622"></a>01622                                                   &its, &lab )) )
+<a name="l01623"></a>01623         {
+<a name="l01624"></a>01624             <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"least squares fit failed, error no.: %d"</span>, 
+<a name="l01625"></a>01625                   iters) ;
+<a name="l01626"></a>01626             <span class="keywordflow">return</span> -8 ;
+<a name="l01627"></a>01627         }
+<a name="l01628"></a>01628 
+<a name="l01629"></a>01629 
+<a name="l01630"></a>01630         <span class="comment">/* take care of the column position of the fit boxes to get </span>
+<a name="l01631"></a>01631 <span class="comment">           the absolute positions */</span>
+<a name="l01632"></a>01632         <span class="keywordflow">if</span> ( j == 0 )
+<a name="l01633"></a>01633         {
+<a name="l01634"></a>01634             sinfo_slit_pos[0][0] = (fitpar[0] + fitpar[1]) / 2. ;
+<a name="l01635"></a>01635             sinfo_slit_pos[0][1] = (fitpar[2] + fitpar[3]) / 2. ;
+<a name="l01636"></a>01636         }
+<a name="l01637"></a>01637         <span class="keywordflow">else</span>
+<a name="l01638"></a>01638         {
+<a name="l01639"></a>01639             sinfo_slit_pos[j][0] = (fitpar[0] + fitpar[1]) / 2. + 
+<a name="l01640"></a>01640                                    (<span class="keywordtype">float</span>)edgeclean[j-1] - (float)margin ;
+<a name="l01641"></a>01641             sinfo_slit_pos[j][1] = (fitpar[2] + fitpar[3]) / 2. + 
+<a name="l01642"></a>01642                                    (<span class="keywordtype">float</span>)edgeclean[j-1] - (float)margin ;
+<a name="l01643"></a>01643         }
+<a name="l01644"></a>01644      
+<a name="l01645"></a>01645         sinfo_slit_pos[k][0] = (fitpar[0] + fitpar[1]) / 2.  + 
+<a name="l01646"></a>01646                                (<span class="keywordtype">float</span>)edgeclean[k-1] - (float)margin ;
+<a name="l01647"></a>01647         sinfo_slit_pos[k][1] = (fitpar[2] + fitpar[3]) / 2. + 
+<a name="l01648"></a>01648                                (<span class="keywordtype">float</span>)edgeclean[k-1] - (float)margin ;
+<a name="l01649"></a>01649 
+<a name="l01650"></a>01650         sinfo_new_destroy_vector ( box_buffer ) ;
+<a name="l01651"></a>01651         cpl_free( xdat ) ;
+<a name="l01652"></a>01652         cpl_free( wdat ) ;
+<a name="l01653"></a>01653         cpl_free( mpar ) ;
+<a name="l01654"></a>01654     }
+<a name="l01655"></a>01655         
+<a name="l01656"></a>01656     cpl_free( sinfo_edge ) ;
+<a name="l01657"></a>01657     cpl_free( pos_row ) ;
+<a name="l01658"></a>01658     cpl_free( edgeclean ) ;
+<a name="l01659"></a>01659     cpl_free( dummyedge ) ;
+<a name="l01660"></a>01660     cpl_free( pos_rowclean ) ;
+<a name="l01661"></a>01661     cpl_free( position );
+<a name="l01662"></a>01662 
+<a name="l01663"></a>01663     <span class="keywordflow">return</span> 0 ;
+<a name="l01664"></a>01664 }
+<a name="l01665"></a>01665                               
+<a name="l01697"></a>01697 <span class="keywordtype">int</span> 
+<a name="l01698"></a>01698 sinfo_new_fit_slits( cpl_image   * lineImage, 
+<a name="l01699"></a>01699               FitParams ** par,
+<a name="l01700"></a>01700               <span class="keywordtype">float</span>     ** sinfo_slit_pos,
+<a name="l01701"></a>01701               <span class="keywordtype">int</span>          box_length,
+<a name="l01702"></a>01702               <span class="keywordtype">float</span>        y_box,
+<a name="l01703"></a>01703               <span class="keywordtype">float</span>        slope_width )
+<a name="l01704"></a>01704 {
+<a name="l01705"></a>01705     <span class="keywordtype">float</span>* position=NULL ;
+<a name="l01706"></a>01706 
+<a name="l01707"></a>01707     <span class="keywordtype">int</span>   * sinfo_edge, * edgeclean ;
+<a name="l01708"></a>01708     <span class="keywordtype">int</span>   * dummyedge ;
+<a name="l01709"></a>01709     <span class="keywordtype">int</span>   * pos_row, * pos_rowclean ;
+<a name="l01710"></a>01710     Vector * box_buffer ;
+<a name="l01711"></a>01711     <span class="keywordtype">float</span> max_intensity ;
+<a name="l01712"></a>01712     <span class="keywordtype">float</span> row_pos ;
+<a name="l01713"></a>01713     <span class="keywordtype">int</span>   col ;
+<a name="l01714"></a>01714     <span class="keywordtype">int</span>   i, j, k, m, n, ed ;
+<a name="l01715"></a>01715     <span class="keywordtype">int</span>   found ;
+<a name="l01716"></a>01716     <span class="keywordtype">int</span>   line ; 
+<a name="l01717"></a>01717     <span class="keywordtype">int</span>   column ;
+<a name="l01718"></a>01718     <span class="keywordtype">int</span>   slit_length ;
+<a name="l01719"></a>01719     <span class="keywordtype">int</span>   agreed ;
+<a name="l01720"></a>01720     <span class="keywordtype">int</span>   bad_line ;
+<a name="l01721"></a>01721     <span class="keywordtype">int</span>   margin ;
+<a name="l01722"></a>01722     <span class="keywordtype">int</span>   iters, xdim, ndat ;
+<a name="l01723"></a>01723     <span class="keywordtype">int</span>   numpar, its ;
+<a name="l01724"></a>01724     <span class="keywordtype">int</span>   * mpar ;
+<a name="l01725"></a>01725     <span class="keywordtype">float</span> * xdat, * wdat ;
+<a name="l01726"></a>01726     <span class="keywordtype">float</span> tol, lab ;
+<a name="l01727"></a>01727     <span class="keywordtype">float</span> fitpar[NPAR] ;
+<a name="l01728"></a>01728     <span class="keywordtype">float</span> dervpar[NPAR] ;
+<a name="l01729"></a>01729     <span class="keywordtype">float</span> minval, maxval ;
+<a name="l01730"></a>01730     <span class="keywordtype">int</span> ilx=0;
+<a name="l01731"></a>01731     <span class="keywordtype">int</span> ily=0;
+<a name="l01732"></a>01732     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l01733"></a>01733 
+<a name="l01734"></a>01734 
+<a name="l01735"></a>01735     <span class="keywordflow">if</span> ( NULL == lineImage )
+<a name="l01736"></a>01736     {
+<a name="l01737"></a>01737         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no line image given!"</span> ) ;
+<a name="l01738"></a>01738         <span class="keywordflow">return</span> -1 ;
+<a name="l01739"></a>01739     }
+<a name="l01740"></a>01740     ilx=cpl_image_get_size_x(lineImage);
+<a name="l01741"></a>01741     ily=cpl_image_get_size_y(lineImage);
+<a name="l01742"></a>01742     pidata=cpl_image_get_data_float(lineImage);
+<a name="l01743"></a>01743 
+<a name="l01744"></a>01744     slit_length = (int) sqrt (ilx) ;
+<a name="l01745"></a>01745     <span class="keywordflow">if</span> ( NULL == par )
+<a name="l01746"></a>01746     {
+<a name="l01747"></a>01747         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no line fit parameters given!"</span> ) ;
+<a name="l01748"></a>01748         <span class="keywordflow">return</span> -2 ;
+<a name="l01749"></a>01749     }
+<a name="l01750"></a>01750 
+<a name="l01751"></a>01751     <span class="keywordflow">if</span> ( NULL == sinfo_slit_pos )
+<a name="l01752"></a>01752     {
+<a name="l01753"></a>01753         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no position array allocated!"</span> ) ;
+<a name="l01754"></a>01754         <span class="keywordflow">return</span> -3 ;
+<a name="l01755"></a>01755     }
+<a name="l01756"></a>01756 
+<a name="l01757"></a>01757     <span class="keywordflow">if</span> ( box_length <  slit_length ||
+<a name="l01758"></a>01758          box_length >= 3*slit_length )
+<a name="l01759"></a>01759     {
+<a name="l01760"></a>01760         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"wrong fitting box length given!"</span> ) ;
+<a name="l01761"></a>01761         <span class="keywordflow">return</span> -4 ;
+<a name="l01762"></a>01762     }
+<a name="l01763"></a>01763 
+<a name="l01764"></a>01764     <span class="keywordflow">if</span> ( y_box <= 0.  || y_box > 3. )
+<a name="l01765"></a>01765     {
+<a name="l01766"></a>01766         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"wrong y box length given!"</span> ) ;
+<a name="l01767"></a>01767         <span class="keywordflow">return</span> -5 ;
+<a name="l01768"></a>01768     }
+<a name="l01769"></a>01769 
+<a name="l01770"></a>01770     <span class="keywordflow">if</span> ( slope_width <= 0. )
+<a name="l01771"></a>01771     {
+<a name="l01772"></a>01772         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"wrong width of linear slope given!"</span>) ;
+<a name="l01773"></a>01773         <span class="keywordflow">return</span> -6 ;
+<a name="l01774"></a>01774     }
+<a name="l01775"></a>01775 
+<a name="l01776"></a>01776     <span class="comment">/* initialize module global variable slopewidth */</span>
+<a name="l01777"></a>01777     slopewidth = slope_width ;
+<a name="l01778"></a>01778 
+<a name="l01779"></a>01779     <span class="comment">/* allocate memory for the edges and the row positon of the slitlets */</span>
+<a name="l01780"></a>01780     sinfo_edge         = (<span class="keywordtype">int</span>*) cpl_calloc( 3*slit_length, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>) ) ;
+<a name="l01781"></a>01781     dummyedge    = (<span class="keywordtype">int</span>*) cpl_calloc( 3*slit_length, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>) ) ;
+<a name="l01782"></a>01782     edgeclean    = (<span class="keywordtype">int</span>*) cpl_calloc( slit_length-1, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>) ) ;
+<a name="l01783"></a>01783     pos_row      = (<span class="keywordtype">int</span>*) cpl_calloc( 3*slit_length, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>) ) ;
+<a name="l01784"></a>01784     pos_rowclean = (<span class="keywordtype">int</span>*) cpl_calloc( slit_length, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>) ) ;
+<a name="l01785"></a>01785 
+<a name="l01786"></a>01786     <span class="comment">/* ------------------------------------------------------------------------</span>
+<a name="l01787"></a>01787 <span class="comment">     * go through the first image columns and the fit parameters and find </span>
+<a name="l01788"></a>01788 <span class="comment">     * the line with the highest intensity </span>
+<a name="l01789"></a>01789 <span class="comment">     */</span>
+<a name="l01790"></a>01790     agreed = -1 ;
+<a name="l01791"></a>01791     bad_line = -1 ;
+<a name="l01792"></a>01792     <span class="keywordflow">while</span>( agreed == -1 )
+<a name="l01793"></a>01793     {
+<a name="l01794"></a>01794         found = -1 ;
+<a name="l01795"></a>01795         max_intensity = -FLT_MAX ;
+<a name="l01796"></a>01796         <span class="keywordflow">for</span> ( col = 0 ; col < box_length ; col++ )
+<a name="l01797"></a>01797         {
+<a name="l01798"></a>01798             <span class="keywordflow">for</span> ( i = 0 ; i < par[0]->n_params ; i++ )
+<a name="l01799"></a>01799             {
+<a name="l01800"></a>01800                 <span class="keywordflow">if</span> ( par[i]->column == col && par[i]->line != bad_line )
+<a name="l01801"></a>01801                 {
+<a name="l01802"></a>01802                     <span class="keywordflow">if</span> ( par[i]->fit_par[0] > max_intensity )
+<a name="l01803"></a>01803                     {
+<a name="l01804"></a>01804                         <span class="keywordflow">if</span> ( par[i]->fit_par[1] > 0. )
+<a name="l01805"></a>01805                         {
+<a name="l01806"></a>01806                             max_intensity = par[i]->fit_par[0] ;
+<a name="l01807"></a>01807                             found = i ;
+<a name="l01808"></a>01808                         }
+<a name="l01809"></a>01809                     }
+<a name="l01810"></a>01810                 }
+<a name="l01811"></a>01811             }  
+<a name="l01812"></a>01812         }
+<a name="l01813"></a>01813 
+<a name="l01814"></a>01814         <span class="comment">/* --------------------------------------------------------------------</span>
+<a name="l01815"></a>01815 <span class="comment">         * check if the found line is usable and if the neighbouring line </span>
+<a name="l01816"></a>01816 <span class="comment">         * have intensity on near rows in neighbouring slitlets </span>
+<a name="l01817"></a>01817 <span class="comment">         */</span>
+<a name="l01818"></a>01818         line    = par[found]->line ;
+<a name="l01819"></a>01819         column  = par[found]->column ;
+<a name="l01820"></a>01820         row_pos = par[found]->fit_par[2] ;
+<a name="l01821"></a>01821         <span class="keywordflow">if</span> ( found >= 0 && max_intensity > 0. )
+<a name="l01822"></a>01822         {
+<a name="l01823"></a>01823             <span class="keywordflow">for</span> ( i = 0 ; i < par[0]->n_params ; i++ )
+<a name="l01824"></a>01824             {
+<a name="l01825"></a>01825                 <span class="keywordflow">if</span> ( par[i]->line == line-1 && 
+<a name="l01826"></a>01826                      par[i]->column == column + slit_length )
+<a name="l01827"></a>01827                 {
+<a name="l01828"></a>01828                     <span class="keywordflow">if</span> ( par[i]->fit_par[2] <= (row_pos + y_box) &&
+<a name="l01829"></a>01829                          par[i]->fit_par[2] >= (row_pos - y_box) )
+<a name="l01830"></a>01830                     {
+<a name="l01831"></a>01831                         bad_line = line ;
+<a name="l01832"></a>01832                     } 
+<a name="l01833"></a>01833                 }
+<a name="l01834"></a>01834             }
+<a name="l01835"></a>01835             <span class="keywordflow">if</span> ( bad_line != line )
+<a name="l01836"></a>01836             {
+<a name="l01837"></a>01837                 agreed = 1 ;
+<a name="l01838"></a>01838                 break ;
+<a name="l01839"></a>01839             }
+<a name="l01840"></a>01840         }
+<a name="l01841"></a>01841         <span class="keywordflow">else</span> 
+<a name="l01842"></a>01842         {
+<a name="l01843"></a>01843           <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no emission line found in the first image columns"</span>);
+<a name="l01844"></a>01844           <span class="keywordflow">return</span> -7 ;
+<a name="l01845"></a>01845         }    
+<a name="l01846"></a>01846     }
+<a name="l01847"></a>01847 
+<a name="l01848"></a>01848  
+<a name="l01849"></a>01849     <span class="keywordflow">if</span> ( agreed == -1 )
+<a name="l01850"></a>01850     {
+<a name="l01851"></a>01851         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no emission line found in the first image columns"</span>) ;
+<a name="l01852"></a>01852         <span class="keywordflow">return</span> -7 ;
+<a name="l01853"></a>01853     }    
+<a name="l01854"></a>01854  
+<a name="l01855"></a>01855     <span class="comment">/* now find and store the raw sinfo_edge positions of the found slitlet */</span> 
+<a name="l01856"></a>01856     n  = 0 ;
+<a name="l01857"></a>01857     ed = 0 ;
+<a name="l01858"></a>01858     position=cpl_calloc(ilx,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l01859"></a>01859 
+<a name="l01860"></a>01860     <span class="keywordflow">for</span> ( col = 0 ; col < ilx ; col++ )
+<a name="l01861"></a>01861     {
+<a name="l01862"></a>01862         <span class="keywordflow">for</span> ( i = 0 ; i < par[0]->n_params ; i++ )
+<a name="l01863"></a>01863         {
+<a name="l01864"></a>01864             <span class="keywordflow">if</span> ( par[i]->column == col && par[i] -> line == line )
+<a name="l01865"></a>01865             {
+<a name="l01866"></a>01866                 <span class="keywordflow">if</span> ( par[i]->fit_par[0] > 0. && par[i]->fit_par[1] > 0. )
+<a name="l01867"></a>01867                 {
+<a name="l01868"></a>01868                     position[n] = par[i]->fit_par[2] ;
+<a name="l01869"></a>01869                     <span class="keywordflow">if</span> ( n > 0 && fabs(position[n] - position[n-1]) > y_box )
+<a name="l01870"></a>01870                     {
+<a name="l01871"></a>01871                         sinfo_edge[ed] = col ; 
+<a name="l01872"></a>01872                         pos_row[ed] = sinfo_new_nint( position[n-1] ) ;
+<a name="l01873"></a>01873                         ed++ ;
+<a name="l01874"></a>01874                         <span class="keywordflow">if</span> ( col >= ilx - slit_length - 5 ) 
+<a name="l01875"></a>01875                         {
+<a name="l01876"></a>01876                             pos_row[ed] =  sinfo_new_nint( position[n] ) ;
+<a name="l01877"></a>01877                         }
+<a name="l01878"></a>01878                     }
+<a name="l01879"></a>01879                     n++ ;
+<a name="l01880"></a>01880                 }
+<a name="l01881"></a>01881             }
+<a name="l01882"></a>01882         }
+<a name="l01883"></a>01883     }
+<a name="l01884"></a>01884     <span class="keywordflow">if</span> ( ed < (slit_length - 1) )
+<a name="l01885"></a>01885     {
+<a name="l01886"></a>01886         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"not enough slitlets found"</span>) ;
+<a name="l01887"></a>01887         <span class="keywordflow">return</span> -8 ;
+<a name="l01888"></a>01888     } 
+<a name="l01889"></a>01889 
+<a name="l01890"></a>01890     <span class="comment">/* now find the clean sinfo_edge and row positions of the slitlets */</span>
+<a name="l01891"></a>01891     <span class="keywordflow">for</span> ( i = 1 ; i <= ed ; i ++ )
+<a name="l01892"></a>01892     {
+<a name="l01893"></a>01893         <span class="keywordflow">if</span> (dummyedge[i-1] != -1)
+<a name="l01894"></a>01894         {
+<a name="l01895"></a>01895             dummyedge[i-1] = sinfo_edge[i-1] ;
+<a name="l01896"></a>01896         }
+<a name="l01897"></a>01897         <span class="keywordflow">if</span> ( (sinfo_edge[i] - sinfo_edge[i-1]) < slit_length - 3 ||
+<a name="l01898"></a>01898              (sinfo_edge[i] - sinfo_edge[i-1]) > slit_length + 3 )
+<a name="l01899"></a>01899         {
+<a name="l01900"></a>01900             dummyedge[i]   = -1 ;
+<a name="l01901"></a>01901         }
+<a name="l01902"></a>01902         <span class="keywordflow">if</span> ( (sinfo_edge[i+1] - sinfo_edge[i]) < slit_length - 3 ||
+<a name="l01903"></a>01903              (sinfo_edge[i+1] - sinfo_edge[i]) > slit_length + 3 )
+<a name="l01904"></a>01904         {
+<a name="l01905"></a>01905             dummyedge[i+1] = -1 ; 
+<a name="l01906"></a>01906         }
+<a name="l01907"></a>01907     }
+<a name="l01908"></a>01908     
+<a name="l01909"></a>01909     k = 0 ;
+<a name="l01910"></a>01910     <span class="keywordflow">for</span> ( i = 0 ; i < ed ; i++ )
+<a name="l01911"></a>01911     {
+<a name="l01912"></a>01912         <span class="keywordflow">if</span> ( dummyedge[i] != -1 && dummyedge[i] != 0 )
+<a name="l01913"></a>01913         {
+<a name="l01914"></a>01914             edgeclean[k] = dummyedge[i] ;
+<a name="l01915"></a>01915             pos_rowclean[k] = pos_row[i] ;
+<a name="l01916"></a>01916             k++ ;
+<a name="l01917"></a>01917             <span class="keywordflow">if</span>( edgeclean[k-1] > (ilx - slit_length - 6 ) )
+<a name="l01918"></a>01918             {
+<a name="l01919"></a>01919                 pos_rowclean[k] = pos_row[ed] ;
+<a name="l01920"></a>01920             }
+<a name="l01921"></a>01921         }
+<a name="l01922"></a>01922     }
+<a name="l01923"></a>01923 
+<a name="l01924"></a>01924     <span class="keywordflow">if</span> ( k != slit_length - 1 )
+<a name="l01925"></a>01925     {
+<a name="l01926"></a>01926         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"not enough clean slitlets found"</span>) ;
+<a name="l01927"></a>01927         <span class="keywordflow">return</span> -7 ;
+<a name="l01928"></a>01928     } 
+<a name="l01929"></a>01929 
+<a name="l01930"></a>01930     <span class="comment">/* determine the margins of the fitting box outside the slitlets */</span>
+<a name="l01931"></a>01931     margin = ( box_length - slit_length ) / 2 ;
+<a name="l01932"></a>01932 
+<a name="l01933"></a>01933     <span class="comment">/* now go through the slitlets and store the intensity in a buffer </span>
+<a name="l01934"></a>01934 <span class="comment">       sinfo_vector */</span>
+<a name="l01935"></a>01935     <span class="keywordflow">for</span> ( j = 0 ; j < k ; j++ )
+<a name="l01936"></a>01936     {
+<a name="l01937"></a>01937         m = 0 ;
+<a name="l01938"></a>01938         <span class="keywordflow">if</span> ( j == 0 )
+<a name="l01939"></a>01939         {
+<a name="l01940"></a>01940             box_buffer = sinfo_new_vector( edgeclean[0] + margin ) ;
+<a name="l01941"></a>01941             <span class="keywordflow">for</span>( col = 0 ; col < edgeclean[0] + margin ; col++ )
+<a name="l01942"></a>01942             {
+<a name="l01943"></a>01943                 box_buffer->data[m] = pidata[col + ilx*pos_rowclean[0]] ;
+<a name="l01944"></a>01944                 m++ ;
+<a name="l01945"></a>01945             }
+<a name="l01946"></a>01946             <span class="comment">/* initial values for the fitted positions */</span>
+<a name="l01947"></a>01947             fitpar[0] = 1. ;
+<a name="l01948"></a>01948             fitpar[1] = (float)edgeclean[0] ;
+<a name="l01949"></a>01949           
+<a name="l01950"></a>01950         }
+<a name="l01951"></a>01951         <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( j < k - 1 )
+<a name="l01952"></a>01952         {
+<a name="l01953"></a>01953             box_buffer = sinfo_new_vector( edgeclean[j] - 
+<a name="l01954"></a>01954                                            edgeclean[j-1] + 2*margin ) ;
+<a name="l01955"></a>01955             <span class="keywordflow">for</span> ( col = edgeclean[j - 1] - margin ; 
+<a name="l01956"></a>01956                   col < edgeclean[j] + margin ; col++ )
+<a name="l01957"></a>01957             {
+<a name="l01958"></a>01958                 box_buffer->data[m] = pidata[col + ilx*pos_rowclean[j]] ;
+<a name="l01959"></a>01959                 m++ ;
+<a name="l01960"></a>01960             }
+<a name="l01961"></a>01961             <span class="comment">/* initial values for the fitted positions */</span>
+<a name="l01962"></a>01962             fitpar[0] = (float)margin ;
+<a name="l01963"></a>01963             fitpar[1] = (float)(edgeclean[j] - edgeclean[j-1] + margin ) ;
+<a name="l01964"></a>01964         }
+<a name="l01965"></a>01965         <span class="comment">/*else if ( j == k - 1 )*/</span>
+<a name="l01966"></a>01966         <span class="keywordflow">else</span>
+<a name="l01967"></a>01967         {
+<a name="l01968"></a>01968             box_buffer = sinfo_new_vector( ilx - edgeclean[k-1] + margin ) ;
+<a name="l01969"></a>01969             <span class="keywordflow">for</span> ( col = edgeclean[k - 1] - margin ; col < ilx ; col++ )
+<a name="l01970"></a>01970             {
+<a name="l01971"></a>01971                 box_buffer->data[m] = pidata[col + ilx*pos_rowclean[k]] ;
+<a name="l01972"></a>01972                 m++ ;
+<a name="l01973"></a>01973             }
+<a name="l01974"></a>01974             <span class="comment">/* initial values for the fitted positions */</span>
+<a name="l01975"></a>01975             fitpar[0] = (float)margin ;
+<a name="l01976"></a>01976             fitpar[1] = (float)(m - 1) ;
+<a name="l01977"></a>01977         }
+<a name="l01978"></a>01978 
+<a name="l01979"></a>01979         xdat=(<span class="keywordtype">float</span> *) cpl_calloc( box_buffer -> n_elements, <span class="keyword">sizeof</span> (<span class="keywordtype">float</span>) ) ;
+<a name="l01980"></a>01980         wdat=(<span class="keywordtype">float</span> *) cpl_calloc( box_buffer -> n_elements, <span class="keyword">sizeof</span> (<span class="keywordtype">float</span>) ) ;
+<a name="l01981"></a>01981         mpar=(<span class="keywordtype">int</span> *)   cpl_calloc( NPAR, <span class="keyword">sizeof</span> (<span class="keywordtype">int</span>) ) ;
+<a name="l01982"></a>01982 
+<a name="l01983"></a>01983         <span class="comment">/* set initial values for the fitting routine */</span>
+<a name="l01984"></a>01984         minval =  FLT_MAX ;
+<a name="l01985"></a>01985         maxval = -FLT_MAX ;
+<a name="l01986"></a>01986         <span class="keywordflow">for</span> ( i = 0 ; i < box_buffer->n_elements ; i++ )
+<a name="l01987"></a>01987         {
+<a name="l01988"></a>01988             xdat[i] = i ;
+<a name="l01989"></a>01989             wdat[i] = 1.0 ;
+<a name="l01990"></a>01990             <span class="keywordflow">if</span> ( box_buffer -> data[i] < minval )
+<a name="l01991"></a>01991             {
+<a name="l01992"></a>01992                 minval = box_buffer -> data[i] ;
+<a name="l01993"></a>01993             }
+<a name="l01994"></a>01994             <span class="keywordflow">if</span> ( box_buffer -> data[i] > maxval )
+<a name="l01995"></a>01995             {
+<a name="l01996"></a>01996                 maxval = box_buffer -> data[i] ;
+<a name="l01997"></a>01997             }
+<a name="l01998"></a>01998         }
+<a name="l01999"></a>01999 
+<a name="l02000"></a>02000         <span class="keywordflow">for</span> ( i = 0 ; i < NPAR ; i++ )
+<a name="l02001"></a>02001         {
+<a name="l02002"></a>02002             mpar[i] = 1 ;
+<a name="l02003"></a>02003             dervpar[i] = 0. ;
+<a name="l02004"></a>02004         }
+<a name="l02005"></a>02005      
+<a name="l02006"></a>02006         xdim     = XDIMA ;
+<a name="l02007"></a>02007         ndat     = box_buffer -> n_elements ;
+<a name="l02008"></a>02008         numpar   = NPAR ;
+<a name="l02009"></a>02009         tol      = TOLA ;
+<a name="l02010"></a>02010         lab      = LABA ;
+<a name="l02011"></a>02011         its      = ITSA ;
+<a name="l02012"></a>02012         
+<a name="l02013"></a>02013         fitpar[2] = minval ;
+<a name="l02014"></a>02014         fitpar[3] = minval ;
+<a name="l02015"></a>02015         fitpar[4] = maxval ;
+<a name="l02016"></a>02016 
+<a name="l02017"></a>02017         <span class="comment">/* finally, do the least squares fit over the buffer data */</span>
+<a name="l02018"></a>02018         <span class="keywordflow">if</span> ( 0 > ( iters = sinfo_new_lsqfit_edge( xdat, &xdim, 
+<a name="l02019"></a>02019                                                   box_buffer -> data, 
+<a name="l02020"></a>02020                                                   wdat, &ndat, fitpar,
+<a name="l02021"></a>02021                                                   dervpar, mpar, &numpar, 
+<a name="l02022"></a>02022                                                   &tol, &its, &lab )) )
+<a name="l02023"></a>02023         {
+<a name="l02024"></a>02024             <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"least squares fit failed, error no.: %d"</span>, 
+<a name="l02025"></a>02025                   iters) ;
+<a name="l02026"></a>02026             <span class="keywordflow">return</span> -9 ;
+<a name="l02027"></a>02027         }
+<a name="l02028"></a>02028 
+<a name="l02029"></a>02029 
+<a name="l02030"></a>02030         <span class="comment">/* take care of the column position of the fit boxes </span>
+<a name="l02031"></a>02031 <span class="comment">           to get the absolute positions */</span>
+<a name="l02032"></a>02032         <span class="keywordflow">if</span> ( j == 0 )
+<a name="l02033"></a>02033         {
+<a name="l02034"></a>02034             sinfo_slit_pos[0][0] = fitpar[0] + slopewidth/2. ;
+<a name="l02035"></a>02035             sinfo_slit_pos[0][1] = fitpar[1] - slopewidth/2. ;
+<a name="l02036"></a>02036         }
+<a name="l02037"></a>02037         <span class="keywordflow">else</span>
+<a name="l02038"></a>02038         {
+<a name="l02039"></a>02039             sinfo_slit_pos[j][0] = fitpar[0] + slopewidth/2. + 
+<a name="l02040"></a>02040                                    (float)edgeclean[j-1] - (<span class="keywordtype">float</span>)margin ;
+<a name="l02041"></a>02041             sinfo_slit_pos[j][1] = fitpar[1] - slopewidth/2. + 
+<a name="l02042"></a>02042                                    (float)edgeclean[j-1] - (<span class="keywordtype">float</span>)margin ;
+<a name="l02043"></a>02043         }
+<a name="l02044"></a>02044 
+<a name="l02045"></a>02045         sinfo_slit_pos[k][0] = fitpar[0] + slopewidth/2. + 
+<a name="l02046"></a>02046                                (float)edgeclean[k-1] - (<span class="keywordtype">float</span>)margin ;
+<a name="l02047"></a>02047         sinfo_slit_pos[k][1] = fitpar[1] - slopewidth/2. + 
+<a name="l02048"></a>02048                                (float)edgeclean[k-1] - (<span class="keywordtype">float</span>)margin ;
+<a name="l02049"></a>02049      
+<a name="l02050"></a>02050         sinfo_new_destroy_vector ( box_buffer ) ;
+<a name="l02051"></a>02051         cpl_free( xdat ) ;
+<a name="l02052"></a>02052         cpl_free( wdat ) ;
+<a name="l02053"></a>02053         cpl_free( mpar ) ;
+<a name="l02054"></a>02054     }
+<a name="l02055"></a>02055         
+<a name="l02056"></a>02056 
+<a name="l02057"></a>02057     cpl_free( sinfo_edge ) ;
+<a name="l02058"></a>02058     cpl_free( pos_row ) ;
+<a name="l02059"></a>02059     cpl_free( edgeclean ) ;
+<a name="l02060"></a>02060     cpl_free( dummyedge ) ;
+<a name="l02061"></a>02061     cpl_free( pos_rowclean ) ;
+<a name="l02062"></a>02062     cpl_free( position );
+<a name="l02063"></a>02063     <span class="keywordflow">return</span> 0 ;
+<a name="l02064"></a>02064 }
+<a name="l02065"></a>02065                               
+<a name="l02110"></a>02110 <span class="keywordtype">int</span> 
+<a name="l02111"></a>02111 sinfo_new_fit_slits2( cpl_image   * lineImage, 
+<a name="l02112"></a>02112                FitParams ** par,
+<a name="l02113"></a>02113                <span class="keywordtype">float</span>     ** sinfo_slit_pos,
+<a name="l02114"></a>02114                <span class="keywordtype">int</span>          box_length,
+<a name="l02115"></a>02115                <span class="keywordtype">float</span>        y_box,
+<a name="l02116"></a>02116                <span class="keywordtype">float</span>        diff_tol )
+<a name="l02117"></a>02117 {
+<a name="l02118"></a>02118     <span class="keywordtype">float</span>* position=NULL ;
+<a name="l02119"></a>02119     <span class="keywordtype">int</span>   * sinfo_edge, * edgeclean ;
+<a name="l02120"></a>02120     <span class="keywordtype">int</span>   * dummyedge ;
+<a name="l02121"></a>02121     <span class="keywordtype">int</span>   * pos_row, * pos_rowclean ;
+<a name="l02122"></a>02122     Vector * box_buffer ;
+<a name="l02123"></a>02123     Vector * half_buffer ;
+<a name="l02124"></a>02124     <span class="keywordtype">float</span> max_intensity ;
+<a name="l02125"></a>02125     <span class="keywordtype">float</span> row_pos ;
+<a name="l02126"></a>02126     <span class="keywordtype">int</span>   col ;
+<a name="l02127"></a>02127     <span class="keywordtype">int</span>   i, j, k, m, n, ed ;
+<a name="l02128"></a>02128     <span class="keywordtype">int</span>   found, init1 ;
+<a name="l02129"></a>02129     <span class="keywordtype">int</span>   line ; 
+<a name="l02130"></a>02130     <span class="keywordtype">int</span>   nel, n_right, left_right ;
+<a name="l02131"></a>02131     <span class="keywordtype">int</span>   column ;
+<a name="l02132"></a>02132     <span class="keywordtype">int</span>   slit_length ;
+<a name="l02133"></a>02133     <span class="keywordtype">int</span>   agreed ;
+<a name="l02134"></a>02134     <span class="keywordtype">int</span>   bad_line ;
+<a name="l02135"></a>02135     <span class="keywordtype">int</span>   margin ;
+<a name="l02136"></a>02136     <span class="keywordtype">int</span>   iters, xdim, ndat ;
+<a name="l02137"></a>02137     <span class="keywordtype">int</span>   numpar, its ;
+<a name="l02138"></a>02138     <span class="keywordtype">int</span>   * mpar ;
+<a name="l02139"></a>02139     <span class="keywordtype">float</span> * xdat, * wdat ;
+<a name="l02140"></a>02140     <span class="keywordtype">float</span> tol, lab ;
+<a name="l02141"></a>02141     <span class="keywordtype">float</span> fitpar[NPAR] ;
+<a name="l02142"></a>02142     <span class="keywordtype">float</span> dervpar[NPAR] ;
+<a name="l02143"></a>02143     <span class="keywordtype">float</span> minval, maxval ;
+<a name="l02144"></a>02144     <span class="keywordtype">float</span> pos, last_pos ;
+<a name="l02145"></a>02145     <span class="keywordtype">int</span> ilx=0;
+<a name="l02146"></a>02146     <span class="keywordtype">int</span> ily=0;
+<a name="l02147"></a>02147     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l02148"></a>02148 
+<a name="l02149"></a>02149 
+<a name="l02150"></a>02150     <span class="keywordflow">if</span> ( NULL == lineImage )
+<a name="l02151"></a>02151     {
+<a name="l02152"></a>02152         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no line image given!"</span> ) ;
+<a name="l02153"></a>02153         <span class="keywordflow">return</span> -1 ;
+<a name="l02154"></a>02154     }
+<a name="l02155"></a>02155     ilx=cpl_image_get_size_x(lineImage);
+<a name="l02156"></a>02156     ily=cpl_image_get_size_y(lineImage);
+<a name="l02157"></a>02157     pidata=cpl_image_get_data_float(lineImage);
+<a name="l02158"></a>02158 
+<a name="l02159"></a>02159     slit_length = (int) sqrt (ilx) ;
+<a name="l02160"></a>02160 
+<a name="l02161"></a>02161     <span class="keywordflow">if</span> ( NULL == par )
+<a name="l02162"></a>02162     {
+<a name="l02163"></a>02163         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no line fit parameters given!"</span> ) ;
+<a name="l02164"></a>02164         <span class="keywordflow">return</span> -2 ;
+<a name="l02165"></a>02165     }
+<a name="l02166"></a>02166 
+<a name="l02167"></a>02167     <span class="keywordflow">if</span> ( NULL == sinfo_slit_pos )
+<a name="l02168"></a>02168     {
+<a name="l02169"></a>02169         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no position array allocated!"</span> ) ;
+<a name="l02170"></a>02170         <span class="keywordflow">return</span> -3 ;
+<a name="l02171"></a>02171     }
+<a name="l02172"></a>02172 
+<a name="l02173"></a>02173     <span class="keywordflow">if</span> ( box_length <  slit_length ||
+<a name="l02174"></a>02174          box_length >= 3*slit_length )
+<a name="l02175"></a>02175     {
+<a name="l02176"></a>02176         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"wrong fitting box length given!"</span> ) ;
+<a name="l02177"></a>02177         <span class="keywordflow">return</span> -4 ;
+<a name="l02178"></a>02178     }
+<a name="l02179"></a>02179 
+<a name="l02180"></a>02180     <span class="keywordflow">if</span> ( y_box <= 0.  || y_box > 3. )
+<a name="l02181"></a>02181     {
+<a name="l02182"></a>02182         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"wrong y box length given!"</span> ) ;
+<a name="l02183"></a>02183         <span class="keywordflow">return</span> -5 ;
+<a name="l02184"></a>02184     }
+<a name="l02185"></a>02185 
+<a name="l02186"></a>02186     <span class="keywordflow">if</span> ( diff_tol < 1. )
+<a name="l02187"></a>02187     {
+<a name="l02188"></a>02188         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"diff_tol too small!"</span> ) ;
+<a name="l02189"></a>02189         <span class="keywordflow">return</span> -6 ;
+<a name="l02190"></a>02190     }
+<a name="l02191"></a>02191 
+<a name="l02192"></a>02192     <span class="comment">/* allocate memory for the edges and the row positon of the slitlets */</span>
+<a name="l02193"></a>02193     sinfo_edge         = (<span class="keywordtype">int</span>*) cpl_calloc( 3*slit_length, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>) ) ;
+<a name="l02194"></a>02194     dummyedge    = (<span class="keywordtype">int</span>*) cpl_calloc( 3*slit_length, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>) ) ;
+<a name="l02195"></a>02195     edgeclean    = (<span class="keywordtype">int</span>*) cpl_calloc( slit_length-1, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>) ) ;
+<a name="l02196"></a>02196     pos_row      = (<span class="keywordtype">int</span>*) cpl_calloc( 3*slit_length, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>) ) ;
+<a name="l02197"></a>02197     pos_rowclean = (<span class="keywordtype">int</span>*) cpl_calloc( slit_length, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>) ) ;
+<a name="l02198"></a>02198 
+<a name="l02199"></a>02199     <span class="comment">/* ------------------------------------------------------------------------</span>
+<a name="l02200"></a>02200 <span class="comment">     * go through the first image columns and the fit parameters and find </span>
+<a name="l02201"></a>02201 <span class="comment">     * the line with the highest intensity </span>
+<a name="l02202"></a>02202 <span class="comment">     */</span>
+<a name="l02203"></a>02203     agreed = -1 ;
+<a name="l02204"></a>02204     bad_line = -1 ;
+<a name="l02205"></a>02205     <span class="keywordflow">while</span>( agreed == -1 )
+<a name="l02206"></a>02206     {
+<a name="l02207"></a>02207         found = -1 ;
+<a name="l02208"></a>02208         max_intensity = -FLT_MAX ;
+<a name="l02209"></a>02209         <span class="keywordflow">for</span> ( col = 0 ; col < box_length ; col++ )
+<a name="l02210"></a>02210         {
+<a name="l02211"></a>02211             <span class="keywordflow">for</span> ( i = 0 ; i < par[0]->n_params ; i++ )
+<a name="l02212"></a>02212             {
+<a name="l02213"></a>02213                 <span class="keywordflow">if</span> ( par[i]->column == col && par[i]->line != bad_line )
+<a name="l02214"></a>02214                 {
+<a name="l02215"></a>02215                     <span class="keywordflow">if</span> ( par[i]->fit_par[0] > max_intensity )
+<a name="l02216"></a>02216                     {
+<a name="l02217"></a>02217                         <span class="keywordflow">if</span> ( par[i]->fit_par[1] > 0. )
+<a name="l02218"></a>02218                         {
+<a name="l02219"></a>02219                             max_intensity = par[i]->fit_par[0] ;
+<a name="l02220"></a>02220                             found = i ;
+<a name="l02221"></a>02221                         }
+<a name="l02222"></a>02222                     }
+<a name="l02223"></a>02223                 }
+<a name="l02224"></a>02224             }  
+<a name="l02225"></a>02225         }
+<a name="l02226"></a>02226 
+<a name="l02227"></a>02227         <span class="comment">/* --------------------------------------------------------------------</span>
+<a name="l02228"></a>02228 <span class="comment">         * check if the found line is usable and if the neighbouring line </span>
+<a name="l02229"></a>02229 <span class="comment">         * have intensity on near rows in neighbouring slitlets </span>
+<a name="l02230"></a>02230 <span class="comment">         */</span>
+<a name="l02231"></a>02231         line    = par[found]->line ;
+<a name="l02232"></a>02232         column  = par[found]->column ;
+<a name="l02233"></a>02233         row_pos = par[found]->fit_par[2] ;
+<a name="l02234"></a>02234         <span class="keywordflow">if</span> ( found >= 0 && max_intensity > 0. )
+<a name="l02235"></a>02235         {
+<a name="l02236"></a>02236             <span class="keywordflow">for</span> ( i = 0 ; i < par[0]->n_params ; i++ )
+<a name="l02237"></a>02237             {
+<a name="l02238"></a>02238                 <span class="keywordflow">if</span> ( par[i]->line == line-1 && 
+<a name="l02239"></a>02239                      par[i]->column == column + slit_length )
+<a name="l02240"></a>02240                 {
+<a name="l02241"></a>02241                     <span class="keywordflow">if</span> ( par[i]->fit_par[2] <= (row_pos + y_box) &&
+<a name="l02242"></a>02242                          par[i]->fit_par[2] >= (row_pos - y_box) )
+<a name="l02243"></a>02243                     {
+<a name="l02244"></a>02244                         bad_line = line ;
+<a name="l02245"></a>02245                     } 
+<a name="l02246"></a>02246                 }
+<a name="l02247"></a>02247             }
+<a name="l02248"></a>02248             <span class="keywordflow">if</span> ( bad_line != line )
+<a name="l02249"></a>02249             {
+<a name="l02250"></a>02250                 agreed = 1 ;
+<a name="l02251"></a>02251                 break ;
+<a name="l02252"></a>02252             }
+<a name="l02253"></a>02253         }
+<a name="l02254"></a>02254         <span class="keywordflow">else</span> 
+<a name="l02255"></a>02255         {
+<a name="l02256"></a>02256           <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no emission line found in the first image columns"</span>);
+<a name="l02257"></a>02257           <span class="keywordflow">return</span> -7 ;
+<a name="l02258"></a>02258         }    
+<a name="l02259"></a>02259     }
+<a name="l02260"></a>02260 
+<a name="l02261"></a>02261  
+<a name="l02262"></a>02262     <span class="keywordflow">if</span> ( agreed == -1 )
+<a name="l02263"></a>02263     {
+<a name="l02264"></a>02264         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no emission line found in the first image columns"</span>) ;
+<a name="l02265"></a>02265         <span class="keywordflow">return</span> -7 ;
+<a name="l02266"></a>02266     }    
+<a name="l02267"></a>02267  
+<a name="l02268"></a>02268     <span class="comment">/* now find and store the raw sinfo_edge positions of the found slitlet */</span> 
+<a name="l02269"></a>02269     n  = 0 ;
+<a name="l02270"></a>02270     ed = 0 ;
+<a name="l02271"></a>02271     position=cpl_calloc(ilx,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l02272"></a>02272 
+<a name="l02273"></a>02273     <span class="keywordflow">for</span> ( col = 0 ; col < ilx ; col++ )
+<a name="l02274"></a>02274     {
+<a name="l02275"></a>02275         <span class="keywordflow">for</span> ( i = 0 ; i < par[0]->n_params ; i++ )
+<a name="l02276"></a>02276         {
+<a name="l02277"></a>02277             <span class="keywordflow">if</span> ( par[i]->column == col && par[i]->line == line )
+<a name="l02278"></a>02278             {
+<a name="l02279"></a>02279                 <span class="keywordflow">if</span> ( par[i]->fit_par[0] > 0. && par[i]->fit_par[1] > 0. )
+<a name="l02280"></a>02280                 {
+<a name="l02281"></a>02281                     position[n] = par[i]->fit_par[2] ;
+<a name="l02282"></a>02282                     <span class="keywordflow">if</span> ( n > 0 && fabs(position[n] - position[n-1]) > y_box )
+<a name="l02283"></a>02283                     {
+<a name="l02284"></a>02284                         sinfo_edge[ed] = col ; 
+<a name="l02285"></a>02285                         pos_row[ed] = sinfo_new_nint( position[n-1] ) ;
+<a name="l02286"></a>02286                         ed++ ;
+<a name="l02287"></a>02287                         <span class="keywordflow">if</span> ( col >= ilx - slit_length - 5 ) 
+<a name="l02288"></a>02288                         {
+<a name="l02289"></a>02289                             pos_row[ed] =  sinfo_new_nint( position[n] ) ;
+<a name="l02290"></a>02290                         }
+<a name="l02291"></a>02291                     }
+<a name="l02292"></a>02292                     n++ ;
+<a name="l02293"></a>02293                 }
+<a name="l02294"></a>02294             }
+<a name="l02295"></a>02295         }
+<a name="l02296"></a>02296     }
+<a name="l02297"></a>02297     <span class="keywordflow">if</span> ( ed < (slit_length - 1) )
+<a name="l02298"></a>02298     {
+<a name="l02299"></a>02299         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"not enough slitlets found"</span>) ;
+<a name="l02300"></a>02300         <span class="keywordflow">return</span> -8 ;
+<a name="l02301"></a>02301     } 
+<a name="l02302"></a>02302 
+<a name="l02303"></a>02303     <span class="comment">/* now find the clean sinfo_edge and row positions of the slitlets */</span>
+<a name="l02304"></a>02304     <span class="keywordflow">for</span> ( i = 1 ; i <= ed ; i ++ )
+<a name="l02305"></a>02305     {
+<a name="l02306"></a>02306         <span class="keywordflow">if</span> (dummyedge[i-1] != -1)
+<a name="l02307"></a>02307         {
+<a name="l02308"></a>02308             dummyedge[i-1] = sinfo_edge[i-1] ;
+<a name="l02309"></a>02309         }
+<a name="l02310"></a>02310         <span class="keywordflow">if</span> ( (sinfo_edge[i] - sinfo_edge[i-1]) < slit_length - 3 ||
+<a name="l02311"></a>02311              (sinfo_edge[i] - sinfo_edge[i-1]) > slit_length + 3 )
+<a name="l02312"></a>02312         {
+<a name="l02313"></a>02313             dummyedge[i]   = -1 ;
+<a name="l02314"></a>02314         }
+<a name="l02315"></a>02315         <span class="keywordflow">if</span> ( (sinfo_edge[i+1] - sinfo_edge[i]) < slit_length - 3 ||
+<a name="l02316"></a>02316              (sinfo_edge[i+1] - sinfo_edge[i]) > slit_length + 3 )
+<a name="l02317"></a>02317         {
+<a name="l02318"></a>02318             dummyedge[i+1] = -1 ; 
+<a name="l02319"></a>02319         }
+<a name="l02320"></a>02320     }
+<a name="l02321"></a>02321     
+<a name="l02322"></a>02322     k = 0 ;
+<a name="l02323"></a>02323     <span class="keywordflow">for</span> ( i = 0 ; i < ed ; i++ )
+<a name="l02324"></a>02324     {
+<a name="l02325"></a>02325         <span class="keywordflow">if</span> ( dummyedge[i] != -1 && dummyedge[i] != 0 )
+<a name="l02326"></a>02326         {
+<a name="l02327"></a>02327             edgeclean[k] = dummyedge[i] ;
+<a name="l02328"></a>02328             pos_rowclean[k] = pos_row[i] ;
+<a name="l02329"></a>02329             k++ ;
+<a name="l02330"></a>02330             <span class="keywordflow">if</span>( edgeclean[k-1] > (ilx - slit_length - 6 ) )
+<a name="l02331"></a>02331             {
+<a name="l02332"></a>02332                 pos_rowclean[k] = pos_row[ed] ;
+<a name="l02333"></a>02333             }
+<a name="l02334"></a>02334         }
+<a name="l02335"></a>02335     }
+<a name="l02336"></a>02336 
+<a name="l02337"></a>02337     <span class="keywordflow">if</span> ( k != slit_length - 1 )
+<a name="l02338"></a>02338     {
+<a name="l02339"></a>02339         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"not enough clean slitlets found"</span>) ;
+<a name="l02340"></a>02340         <span class="keywordflow">return</span> -7 ;
+<a name="l02341"></a>02341     } 
+<a name="l02342"></a>02342 
+<a name="l02343"></a>02343     <span class="comment">/* determine the margins of the fitting box outside the slitlets */</span>
+<a name="l02344"></a>02344     margin = ( box_length - slit_length ) / 2 ;
+<a name="l02345"></a>02345 
+<a name="l02346"></a>02346     <span class="comment">/* now go through the slitlets and store the intensity in a </span>
+<a name="l02347"></a>02347 <span class="comment">       buffer sinfo_vector */</span>
+<a name="l02348"></a>02348     <span class="keywordflow">for</span> ( j = 0 ; j <= k ; j++ )
+<a name="l02349"></a>02349     {
+<a name="l02350"></a>02350         m = 0 ;
+<a name="l02351"></a>02351         <span class="keywordflow">if</span> ( j == 0 )
+<a name="l02352"></a>02352         {
+<a name="l02353"></a>02353             box_buffer = sinfo_new_vector( edgeclean[0] + margin ) ;
+<a name="l02354"></a>02354             <span class="keywordflow">for</span>( col = 0 ; col < edgeclean[0] + margin ; col++ )
+<a name="l02355"></a>02355             {
+<a name="l02356"></a>02356                 box_buffer->data[m] = pidata[col +ilx*pos_rowclean[0]] ;
+<a name="l02357"></a>02357                 m++ ;
+<a name="l02358"></a>02358             }
+<a name="l02359"></a>02359         }
+<a name="l02360"></a>02360         <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( j < k )
+<a name="l02361"></a>02361         {
+<a name="l02362"></a>02362             box_buffer = sinfo_new_vector( edgeclean[j] - 
+<a name="l02363"></a>02363                                            edgeclean[j-1] + 2*margin ) ;
+<a name="l02364"></a>02364             <span class="keywordflow">for</span> ( col = edgeclean[j - 1] - margin ; 
+<a name="l02365"></a>02365                   col < edgeclean[j] + margin ; col++ )
+<a name="l02366"></a>02366             {
+<a name="l02367"></a>02367                 box_buffer->data[m] = pidata[col + ilx*pos_rowclean[j]] ;
+<a name="l02368"></a>02368                 m++ ;
+<a name="l02369"></a>02369             }
+<a name="l02370"></a>02370         }
+<a name="l02371"></a>02371         <span class="keywordflow">else</span> 
+<a name="l02372"></a>02372         {
+<a name="l02373"></a>02373             box_buffer = sinfo_new_vector( ilx - edgeclean[k-1] + margin ) ;
+<a name="l02374"></a>02374             <span class="keywordflow">for</span> ( col = edgeclean[k - 1] - margin ; col < ilx ; col++ )
+<a name="l02375"></a>02375             {
+<a name="l02376"></a>02376                 box_buffer->data[m] = pidata[col + ilx*pos_rowclean[k]] ;
+<a name="l02377"></a>02377                 m++ ;
+<a name="l02378"></a>02378             }
+<a name="l02379"></a>02379         }
+<a name="l02380"></a>02380 
+<a name="l02381"></a>02381         <span class="keywordflow">for</span> ( left_right = 0 ; left_right <= 1 ; left_right++ )
+<a name="l02382"></a>02382         { 
+<a name="l02383"></a>02383             nel = 0 ;
+<a name="l02384"></a>02384             <span class="keywordflow">if</span> ( left_right == 0 )
+<a name="l02385"></a>02385             {
+<a name="l02386"></a>02386                 nel = box_buffer -> n_elements / 2 ;
+<a name="l02387"></a>02387             }
+<a name="l02388"></a>02388             <span class="keywordflow">else</span>
+<a name="l02389"></a>02389             {
+<a name="l02390"></a>02390                 <span class="keywordflow">if</span> ( box_buffer -> n_elements % 2 == 0 )
+<a name="l02391"></a>02391                 {
+<a name="l02392"></a>02392                     nel = box_buffer -> n_elements / 2 ;
+<a name="l02393"></a>02393                 }
+<a name="l02394"></a>02394                 <span class="keywordflow">else</span>
+<a name="l02395"></a>02395                 {
+<a name="l02396"></a>02396                     nel = box_buffer -> n_elements / 2 + 1 ;
+<a name="l02397"></a>02397                 }
+<a name="l02398"></a>02398             }
+<a name="l02399"></a>02399 
+<a name="l02400"></a>02400             <span class="comment">/* now split the buffer in the midth in a left and right </span>
+<a name="l02401"></a>02401 <span class="comment">               part for fitting */</span>
+<a name="l02402"></a>02402             half_buffer = sinfo_new_vector( nel ) ;
+<a name="l02403"></a>02403             <span class="keywordflow">if</span> ( left_right == 0 )
+<a name="l02404"></a>02404             {
+<a name="l02405"></a>02405                 <span class="keywordflow">for</span> ( i = 0 ; i < nel ; i++ )
+<a name="l02406"></a>02406                 {
+<a name="l02407"></a>02407                     half_buffer -> data[i] = box_buffer -> data[i] ;
+<a name="l02408"></a>02408                 }
+<a name="l02409"></a>02409             }
+<a name="l02410"></a>02410             <span class="keywordflow">else</span>
+<a name="l02411"></a>02411             {
+<a name="l02412"></a>02412                 n_right = 0 ;
+<a name="l02413"></a>02413                 <span class="keywordflow">for</span> ( i = box_buffer -> n_elements - 1 ; 
+<a name="l02414"></a>02414                       i >= box_buffer -> n_elements - nel ; i-- )
+<a name="l02415"></a>02415                 {
+<a name="l02416"></a>02416                     half_buffer -> data[n_right] = box_buffer -> data[i] ;
+<a name="l02417"></a>02417                     n_right++ ;
+<a name="l02418"></a>02418                 }
+<a name="l02419"></a>02419             }
+<a name="l02420"></a>02420 
+<a name="l02421"></a>02421             xdat = (<span class="keywordtype">float</span> *) cpl_calloc( nel, <span class="keyword">sizeof</span> (<span class="keywordtype">float</span>) ) ;
+<a name="l02422"></a>02422             wdat = (<span class="keywordtype">float</span> *) cpl_calloc( nel, <span class="keyword">sizeof</span> (<span class="keywordtype">float</span>) ) ;
+<a name="l02423"></a>02423             mpar = (<span class="keywordtype">int</span> *)   cpl_calloc( NPAR, <span class="keyword">sizeof</span> (<span class="keywordtype">int</span>) ) ;
+<a name="l02424"></a>02424 
+<a name="l02425"></a>02425             <span class="comment">/* set initial values for the fitting routine */</span>
+<a name="l02426"></a>02426             minval =  FLT_MAX ;
+<a name="l02427"></a>02427             maxval = -FLT_MAX ;
+<a name="l02428"></a>02428             <span class="keywordflow">for</span> ( i = 0 ; i < nel ; i++ )
+<a name="l02429"></a>02429             {
+<a name="l02430"></a>02430                 xdat[i] = i ;
+<a name="l02431"></a>02431                 wdat[i] = 1.0 ;
+<a name="l02432"></a>02432                 <span class="keywordflow">if</span> ( half_buffer -> data[i] < minval )
+<a name="l02433"></a>02433                 {
+<a name="l02434"></a>02434                     minval = half_buffer -> data[i] ;
+<a name="l02435"></a>02435                 }
+<a name="l02436"></a>02436                 <span class="keywordflow">if</span> ( half_buffer -> data[i] > maxval )
+<a name="l02437"></a>02437                 {
+<a name="l02438"></a>02438                     maxval = half_buffer -> data[i] ;
+<a name="l02439"></a>02439                 }
+<a name="l02440"></a>02440             }
+<a name="l02441"></a>02441 
+<a name="l02442"></a>02442             fitpar[2] = minval ;
+<a name="l02443"></a>02443             fitpar[3] = maxval ; 
+<a name="l02444"></a>02444 
+<a name="l02445"></a>02445             <span class="comment">/* search for both positions of the half intensity of </span>
+<a name="l02446"></a>02446 <span class="comment">               the hat within the buffer */</span>
+<a name="l02447"></a>02447             init1 = -1 ; 
+<a name="l02448"></a>02448             <span class="keywordflow">for</span> ( i = 0 ; i < nel ; i++ )
+<a name="l02449"></a>02449             {
+<a name="l02450"></a>02450                 <span class="keywordflow">if</span> ( half_buffer -> data[i] >= ( maxval + minval ) / 2. )
+<a name="l02451"></a>02451                 {
+<a name="l02452"></a>02452                     init1 = i ;
+<a name="l02453"></a>02453                     break ;
+<a name="l02454"></a>02454                 }
+<a name="l02455"></a>02455             }
+<a name="l02456"></a>02456 
+<a name="l02457"></a>02457             <span class="comment">/* determine the initial positions from the found values */</span>
+<a name="l02458"></a>02458             <span class="keywordflow">if</span> ( init1 != -1 )
+<a name="l02459"></a>02459             {
+<a name="l02460"></a>02460                 fitpar[0] = ((float)init1 - 1.) ;
+<a name="l02461"></a>02461                 fitpar[1] = ((float)init1 + 1.) ;
+<a name="l02462"></a>02462             }
+<a name="l02463"></a>02463 
+<a name="l02464"></a>02464             <span class="keywordflow">for</span> ( i = 0 ; i < NPAR ; i++ )
+<a name="l02465"></a>02465             {
+<a name="l02466"></a>02466                 mpar[i] = 1 ;
+<a name="l02467"></a>02467                 dervpar[i] = 0. ;
+<a name="l02468"></a>02468             }
+<a name="l02469"></a>02469       
+<a name="l02470"></a>02470             xdim     = XDIMA ;
+<a name="l02471"></a>02471             ndat     = nel ;
+<a name="l02472"></a>02472             numpar   = NPAR ;
+<a name="l02473"></a>02473             tol      = TOLA ;
+<a name="l02474"></a>02474             lab      = LABA ;
+<a name="l02475"></a>02475             its      = ITSA ;
+<a name="l02476"></a>02476          
+<a name="l02477"></a>02477             <span class="comment">/* finally, do the least squares fit over the buffer data */</span>
+<a name="l02478"></a>02478             <span class="keywordflow">if</span> ( 0 > ( iters = sinfo_new_lsqfit_edge( xdat, &xdim, 
+<a name="l02479"></a>02479                                                       half_buffer -> data, 
+<a name="l02480"></a>02480                                                       wdat, &ndat, fitpar,
+<a name="l02481"></a>02481                                                       dervpar, mpar, &numpar, 
+<a name="l02482"></a>02482                                                       &tol, &its, &lab )) )
+<a name="l02483"></a>02483             { 
+<a name="l02484"></a>02484                 <span class="comment">/* if the fit doesn't succeed the initial values are taken */</span>
+<a name="l02485"></a>02485                 <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a> (<span class="stringliteral">" least squares fit failed, error"</span>
+<a name="l02486"></a>02486                                    <span class="stringliteral">" no.: %d in slitlet: %d\n"</span>, iters, j) ;
+<a name="l02487"></a>02487                 fitpar[0] = ((float)init1 - 1.) ;
+<a name="l02488"></a>02488                 fitpar[1] = ((float)init1 + 1.) ;
+<a name="l02489"></a>02489             }
+<a name="l02490"></a>02490 
+<a name="l02491"></a>02491             pos = (fitpar[0] + fitpar[1]) / 2. ;
+<a name="l02492"></a>02492 
+<a name="l02493"></a>02493             <span class="comment">/*---------------------------------------------------------------- </span>
+<a name="l02494"></a>02494 <span class="comment">             * now discern the left and the right sinfo_edge fit of the </span>
+<a name="l02495"></a>02495 <span class="comment">             * slitlets and associate the fit results with the absolute </span>
+<a name="l02496"></a>02496 <span class="comment">             * positions in the image consider the difference of the fitted </span>
+<a name="l02497"></a>02497 <span class="comment">             * slit position to the expected position and decide wether the </span>
+<a name="l02498"></a>02498 <span class="comment">             * fit is taken or the expected value is taken.</span>
+<a name="l02499"></a>02499 <span class="comment">             */</span>
+<a name="l02500"></a>02500             <span class="keywordflow">if</span> ( left_right == 0 )
+<a name="l02501"></a>02501             {
+<a name="l02502"></a>02502                 <span class="comment">/* take care of the column position of the fit boxes </span>
+<a name="l02503"></a>02503 <span class="comment">                   to get the absolute positions */</span>
+<a name="l02504"></a>02504                 <span class="keywordflow">if</span> ( j == 0 )
+<a name="l02505"></a>02505                 {
+<a name="l02506"></a>02506                     <span class="keywordflow">if</span> ( fabs(pos - ((<span class="keywordtype">float</span>)edgeclean[0] - 1. - 
+<a name="l02507"></a>02507                          (float)slit_length)) < diff_tol )
+<a name="l02508"></a>02508                     {
+<a name="l02509"></a>02509                         sinfo_slit_pos[0][0] = pos ;
+<a name="l02510"></a>02510                     }
+<a name="l02511"></a>02511                     <span class="keywordflow">else</span>
+<a name="l02512"></a>02512                     {
+<a name="l02513"></a>02513                         <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"something wrong with fitted left"</span>
+<a name="l02514"></a>02514                                           <span class="stringliteral">" position of slitlet 0"</span>) ;
+<a name="l02515"></a>02515                         <span class="keywordflow">if</span> ( (<span class="keywordtype">float</span>) edgeclean[0] - 1. - 
+<a name="l02516"></a>02516                              (<span class="keywordtype">float</span>)slit_length < 0. )
+<a name="l02517"></a>02517                         {
+<a name="l02518"></a>02518                             sinfo_slit_pos[0][0] = 0. ;
+<a name="l02519"></a>02519                         }
+<a name="l02520"></a>02520                         <span class="keywordflow">else</span>
+<a name="l02521"></a>02521                         {
+<a name="l02522"></a>02522                             sinfo_slit_pos[0][0] = (float)edgeclean[0] - 1. - 
+<a name="l02523"></a>02523                             (<span class="keywordtype">float</span>)slit_length ;
+<a name="l02524"></a>02524                         }
+<a name="l02525"></a>02525                     }
+<a name="l02526"></a>02526                 }
+<a name="l02527"></a>02527                 <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( j < k )
+<a name="l02528"></a>02528                 {
+<a name="l02529"></a>02529                     <span class="keywordflow">if</span> ( fabs( pos - (<span class="keywordtype">float</span>)margin ) < diff_tol )
+<a name="l02530"></a>02530                     {
+<a name="l02531"></a>02531                         sinfo_slit_pos[j][0] = pos + (float)edgeclean[j-1] - 
+<a name="l02532"></a>02532                                                (<span class="keywordtype">float</span>)margin ;
+<a name="l02533"></a>02533                     }
+<a name="l02534"></a>02534                     else
+<a name="l02535"></a>02535                     {
+<a name="l02536"></a>02536                         <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"something wrong with fitted left"</span>
+<a name="l02537"></a>02537                                           <span class="stringliteral">" position of slitlet %d"</span>, j) ;
+<a name="l02538"></a>02538                         sinfo_slit_pos[j][0] = (float)edgeclean[j-1] - 1. ;
+<a name="l02539"></a>02539                     }
+<a name="l02540"></a>02540                 }
+<a name="l02541"></a>02541                 <span class="keywordflow">else</span>
+<a name="l02542"></a>02542                 {
+<a name="l02543"></a>02543                     <span class="keywordflow">if</span> ( fabs( pos - (<span class="keywordtype">float</span>)margin ) < diff_tol )
+<a name="l02544"></a>02544                     {
+<a name="l02545"></a>02545                         sinfo_slit_pos[k][0] = pos + (float)edgeclean[k-1] - 
+<a name="l02546"></a>02546                                                (<span class="keywordtype">float</span>)margin ;
+<a name="l02547"></a>02547                     }
+<a name="l02548"></a>02548                     else
+<a name="l02549"></a>02549                     {
+<a name="l02550"></a>02550                         <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"something wrong with fitted left"</span>
+<a name="l02551"></a>02551                                           <span class="stringliteral">" position of slitlet %d"</span>, j) ;
+<a name="l02552"></a>02552                         sinfo_slit_pos[k][0] = (float)edgeclean[k-1] - 1. ;
+<a name="l02553"></a>02553                     }
+<a name="l02554"></a>02554                 }
+<a name="l02555"></a>02555             }
+<a name="l02556"></a>02556             <span class="keywordflow">else</span>
+<a name="l02557"></a>02557             {
+<a name="l02558"></a>02558                 <span class="comment">/* take care of the column position of the fit boxes </span>
+<a name="l02559"></a>02559 <span class="comment">                   to get the absolute positions */</span>
+<a name="l02560"></a>02560                 <span class="keywordflow">if</span> ( j == 0 )
+<a name="l02561"></a>02561                 {
+<a name="l02562"></a>02562                     <span class="keywordflow">if</span> ( fabs( (<span class="keywordtype">float</span>)box_buffer->n_elements - pos - 
+<a name="l02563"></a>02563                                (<span class="keywordtype">float</span>)edgeclean[0] ) < diff_tol )
+<a name="l02564"></a>02564                     {
+<a name="l02565"></a>02565                         sinfo_slit_pos[0][1] = (float)(box_buffer->n_elements - 
+<a name="l02566"></a>02566                                                 1) - pos ;
+<a name="l02567"></a>02567                     }
+<a name="l02568"></a>02568                     <span class="keywordflow">else</span>
+<a name="l02569"></a>02569                     {
+<a name="l02570"></a>02570                         <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"something wrong with fitted "</span>
+<a name="l02571"></a>02571                                           <span class="stringliteral">"right position of slitlet 0"</span>) ;
+<a name="l02572"></a>02572                         sinfo_slit_pos[0][1] = (float)edgeclean[0] - 1. ;
+<a name="l02573"></a>02573                     }
+<a name="l02574"></a>02574                 }
+<a name="l02575"></a>02575                 <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( j < k )
+<a name="l02576"></a>02576                 {
+<a name="l02577"></a>02577                     <span class="keywordflow">if</span> ( fabs( (<span class="keywordtype">float</span>)box_buffer->n_elements - pos
+<a name="l02578"></a>02578                              + (<span class="keywordtype">float</span>)edgeclean[j-1] - (<span class="keywordtype">float</span>)margin - 
+<a name="l02579"></a>02579                                (<span class="keywordtype">float</span>)edgeclean[j] ) < diff_tol )
+<a name="l02580"></a>02580                     {
+<a name="l02581"></a>02581                         sinfo_slit_pos[j][1] = (float)(box_buffer->n_elements -
+<a name="l02582"></a>02582                                         1) - pos
+<a name="l02583"></a>02583                                        + (float)edgeclean[j-1] - (<span class="keywordtype">float</span>)margin ;
+<a name="l02584"></a>02584                     }
+<a name="l02585"></a>02585                     else
+<a name="l02586"></a>02586                     {
+<a name="l02587"></a>02587                         <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"something wrong with fitted right "</span>
+<a name="l02588"></a>02588                                           <span class="stringliteral">"position of slitlet %d"</span>, j) ;
+<a name="l02589"></a>02589                         sinfo_slit_pos[j][1] = (float)edgeclean[j] - 1. ;
+<a name="l02590"></a>02590                     }
+<a name="l02591"></a>02591                 }
+<a name="l02592"></a>02592                 <span class="keywordflow">else</span>
+<a name="l02593"></a>02593                 {
+<a name="l02594"></a>02594                     <span class="keywordflow">if</span> ( edgeclean[k-1] + slit_length > ilx )
+<a name="l02595"></a>02595                     {
+<a name="l02596"></a>02596                         last_pos = (float)(ilx - 1) ;
+<a name="l02597"></a>02597                     }
+<a name="l02598"></a>02598                     <span class="keywordflow">else</span>
+<a name="l02599"></a>02599                     {
+<a name="l02600"></a>02600                         last_pos = (float)(edgeclean[k-1] - 1 + slit_length) ;
+<a name="l02601"></a>02601                     }
+<a name="l02602"></a>02602                     <span class="keywordflow">if</span> ( fabs( (<span class="keywordtype">float</span>)(box_buffer->n_elements - 1) - pos
+<a name="l02603"></a>02603                              + (<span class="keywordtype">float</span>)edgeclean[k-1] - (float)margin - 
+<a name="l02604"></a>02604                                last_pos ) < diff_tol )
+<a name="l02605"></a>02605                     {
+<a name="l02606"></a>02606                         sinfo_slit_pos[k][1] = (float)(box_buffer->n_elements -
+<a name="l02607"></a>02607                                                1) - pos
+<a name="l02608"></a>02608                                        + (float)edgeclean[k-1] - (<span class="keywordtype">float</span>)margin ;
+<a name="l02609"></a>02609                     }
+<a name="l02610"></a>02610                     else
+<a name="l02611"></a>02611                     {
+<a name="l02612"></a>02612                         <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"something wrong with fitted right "</span>
+<a name="l02613"></a>02613                                           <span class="stringliteral">"position of slitlet %d\n"</span>, j) ;
+<a name="l02614"></a>02614                         sinfo_slit_pos[k][1] = last_pos ;
+<a name="l02615"></a>02615                     }
+<a name="l02616"></a>02616                 }
+<a name="l02617"></a>02617             }
+<a name="l02618"></a>02618 
+<a name="l02619"></a>02619             sinfo_new_destroy_vector ( half_buffer ) ;
+<a name="l02620"></a>02620             cpl_free( xdat ) ;
+<a name="l02621"></a>02621             cpl_free( wdat ) ;
+<a name="l02622"></a>02622             cpl_free( mpar ) ;
+<a name="l02623"></a>02623         }
+<a name="l02624"></a>02624         sinfo_new_destroy_vector ( box_buffer ) ;
+<a name="l02625"></a>02625     }
+<a name="l02626"></a>02626         
+<a name="l02627"></a>02627     cpl_free( sinfo_edge ) ;
+<a name="l02628"></a>02628     cpl_free( pos_row ) ;
+<a name="l02629"></a>02629     cpl_free( edgeclean ) ;
+<a name="l02630"></a>02630     cpl_free( dummyedge ) ;
+<a name="l02631"></a>02631     cpl_free( pos_rowclean ) ;
+<a name="l02632"></a>02632     cpl_free(position);
+<a name="l02633"></a>02633     <span class="keywordflow">return</span> 0 ;
+<a name="l02634"></a>02634 }
+<a name="l02635"></a>02635                               
+<a name="l02670"></a>02670 <span class="keywordtype">int</span> 
+<a name="l02671"></a>02671 sinfo_new_fit_slits_edge( cpl_image   * lineImage, 
+<a name="l02672"></a>02672                   FitParams ** par,
+<a name="l02673"></a>02673                   <span class="keywordtype">float</span>     ** sinfo_slit_pos,
+<a name="l02674"></a>02674                   <span class="keywordtype">int</span>          box_length,
+<a name="l02675"></a>02675                   <span class="keywordtype">float</span>        y_box,
+<a name="l02676"></a>02676                   <span class="keywordtype">float</span>        diff_tol )
+<a name="l02677"></a>02677 {
+<a name="l02678"></a>02678     <span class="keywordtype">float</span>* position=NULL ;
+<a name="l02679"></a>02679     <span class="keywordtype">int</span>   * sinfo_edge, * edgeclean ;
+<a name="l02680"></a>02680     <span class="keywordtype">int</span>   * dummyedge ;
+<a name="l02681"></a>02681     <span class="keywordtype">int</span>   * pos_row, * pos_rowclean ;
+<a name="l02682"></a>02682     Vector * box_buffer ;
+<a name="l02683"></a>02683     Vector * half_buffer ;
+<a name="l02684"></a>02684     <span class="keywordtype">float</span> max_intensity ;
+<a name="l02685"></a>02685     <span class="keywordtype">float</span> row_pos ;
+<a name="l02686"></a>02686     <span class="keywordtype">int</span>   row, col ;
+<a name="l02687"></a>02687     <span class="keywordtype">int</span>   i, j, k, m, n, ed ;
+<a name="l02688"></a>02688     <span class="keywordtype">int</span>   found, init1 ;
+<a name="l02689"></a>02689     <span class="keywordtype">int</span>   line ; 
+<a name="l02690"></a>02690     <span class="keywordtype">int</span>   nel, n_right, left_right ;
+<a name="l02691"></a>02691     <span class="keywordtype">int</span>   column ;
+<a name="l02692"></a>02692     <span class="keywordtype">int</span>   slit_length ;
+<a name="l02693"></a>02693     <span class="keywordtype">int</span>   agreed ;
+<a name="l02694"></a>02694     <span class="keywordtype">int</span>   bad_line ;
+<a name="l02695"></a>02695     <span class="keywordtype">int</span>   margin ;
+<a name="l02696"></a>02696     <span class="keywordtype">int</span>   iters, xdim, ndat ;
+<a name="l02697"></a>02697     <span class="keywordtype">int</span>   numpar, its ;
+<a name="l02698"></a>02698     <span class="keywordtype">int</span>   * mpar ;
+<a name="l02699"></a>02699     <span class="keywordtype">float</span> * xdat, * wdat ;
+<a name="l02700"></a>02700     <span class="keywordtype">float</span> tol, lab ;
+<a name="l02701"></a>02701     <span class="keywordtype">float</span> fitpar[NPAR] ;
+<a name="l02702"></a>02702     <span class="keywordtype">float</span> dervpar[NPAR] ;
+<a name="l02703"></a>02703     <span class="keywordtype">float</span> minval, maxval ;
+<a name="l02704"></a>02704     <span class="keywordtype">float</span> pos, last_pos ;
+<a name="l02705"></a>02705     <span class="keywordtype">int</span> ilx=0;
+<a name="l02706"></a>02706     <span class="keywordtype">int</span> ily=0;
+<a name="l02707"></a>02707     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l02708"></a>02708 
+<a name="l02709"></a>02709 
+<a name="l02710"></a>02710     <span class="keywordflow">if</span> ( NULL == lineImage )
+<a name="l02711"></a>02711     {
+<a name="l02712"></a>02712         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" no line image given!"</span> ) ;
+<a name="l02713"></a>02713         <span class="keywordflow">return</span> -1 ;
+<a name="l02714"></a>02714     }
+<a name="l02715"></a>02715     ilx=cpl_image_get_size_x(lineImage);
+<a name="l02716"></a>02716     ily=cpl_image_get_size_y(lineImage);
+<a name="l02717"></a>02717     pidata=cpl_image_get_data_float(lineImage);
+<a name="l02718"></a>02718 
+<a name="l02719"></a>02719     slit_length = (int) sqrt (ilx) ;
+<a name="l02720"></a>02720 
+<a name="l02721"></a>02721     <span class="keywordflow">if</span> ( NULL == par )
+<a name="l02722"></a>02722     {
+<a name="l02723"></a>02723         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" no line fit parameters given!"</span> ) ;
+<a name="l02724"></a>02724         <span class="keywordflow">return</span> -2 ;
+<a name="l02725"></a>02725     }
+<a name="l02726"></a>02726 
+<a name="l02727"></a>02727     <span class="keywordflow">if</span> ( NULL == sinfo_slit_pos )
+<a name="l02728"></a>02728     {
+<a name="l02729"></a>02729         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" no position array allocated!"</span> ) ;
+<a name="l02730"></a>02730         <span class="keywordflow">return</span> -3 ;
+<a name="l02731"></a>02731     }
+<a name="l02732"></a>02732 
+<a name="l02733"></a>02733     <span class="keywordflow">if</span> ( box_length <  4 ||
+<a name="l02734"></a>02734          box_length >= 2*slit_length )
+<a name="l02735"></a>02735     {
+<a name="l02736"></a>02736         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" wrong fitting box length given!"</span> ) ;
+<a name="l02737"></a>02737         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" Must be 4 <= box_length < %d "</span>,2*slit_length ) ;
+<a name="l02738"></a>02738         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" You have chosen box_length = %d "</span>,box_length);
+<a name="l02739"></a>02739         <span class="keywordflow">return</span> -4 ;
+<a name="l02740"></a>02740     }
+<a name="l02741"></a>02741 
+<a name="l02742"></a>02742     <span class="keywordflow">if</span> ( y_box <= 0.  || y_box > 3. )
+<a name="l02743"></a>02743     {
+<a name="l02744"></a>02744         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" wrong y box length given!"</span> ) ;
+<a name="l02745"></a>02745         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" y_box=%f not in range (0,3]!"</span>,y_box);
+<a name="l02746"></a>02746         <span class="keywordflow">return</span> -5 ;
+<a name="l02747"></a>02747     }
+<a name="l02748"></a>02748 
+<a name="l02749"></a>02749     <span class="keywordflow">if</span> ( diff_tol < 1. )
+<a name="l02750"></a>02750     {
+<a name="l02751"></a>02751         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" diff_tol too small!"</span> ) ;
+<a name="l02752"></a>02752         <span class="keywordflow">return</span> -6 ;
+<a name="l02753"></a>02753     }
+<a name="l02754"></a>02754 
+<a name="l02755"></a>02755     <span class="comment">/* allocate memory for the edges and the row positon of the slitlets */</span>
+<a name="l02756"></a>02756     sinfo_edge         = (<span class="keywordtype">int</span>*) cpl_calloc( 3*slit_length, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>) ) ;
+<a name="l02757"></a>02757     dummyedge    = (<span class="keywordtype">int</span>*) cpl_calloc( 3*slit_length, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>) ) ;
+<a name="l02758"></a>02758     edgeclean    = (<span class="keywordtype">int</span>*) cpl_calloc( slit_length-1, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>) ) ;
+<a name="l02759"></a>02759     pos_row      = (<span class="keywordtype">int</span>*) cpl_calloc( 3*slit_length, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>) ) ;
+<a name="l02760"></a>02760     pos_rowclean = (<span class="keywordtype">int</span>*) cpl_calloc( slit_length, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>) ) ;
+<a name="l02761"></a>02761 
+<a name="l02762"></a>02762     <span class="comment">/* ------------------------------------------------------------------------</span>
+<a name="l02763"></a>02763 <span class="comment">     * go through the first image columns and the fit parameters and find </span>
+<a name="l02764"></a>02764 <span class="comment">     * the line with the highest intensity </span>
+<a name="l02765"></a>02765 <span class="comment">     */</span>
+<a name="l02766"></a>02766     agreed = -1 ;
+<a name="l02767"></a>02767     bad_line = -1 ;
+<a name="l02768"></a>02768     <span class="keywordflow">while</span>( agreed == -1 )
+<a name="l02769"></a>02769     {
+<a name="l02770"></a>02770         found = -1 ;
+<a name="l02771"></a>02771         max_intensity = -FLT_MAX ;
+<a name="l02772"></a>02772         <span class="keywordflow">for</span> ( col = 0 ; col < slit_length ; col++ )
+<a name="l02773"></a>02773         {
+<a name="l02774"></a>02774             <span class="keywordflow">for</span> ( i = 0 ; i < par[0]->n_params ; i++ )
+<a name="l02775"></a>02775             {
+<a name="l02776"></a>02776                 <span class="keywordflow">if</span> ( par[i]->column == col && par[i] -> line != bad_line )
+<a name="l02777"></a>02777                 {
+<a name="l02778"></a>02778                     <span class="keywordflow">if</span> ( par[i]->fit_par[0] > max_intensity )
+<a name="l02779"></a>02779                     {
+<a name="l02780"></a>02780                         <span class="keywordflow">if</span> ( par[i]->fit_par[1] >= 1. && 
+<a name="l02781"></a>02781                              par[i]->fit_par[2] > 0. )
+<a name="l02782"></a>02782                         {
+<a name="l02783"></a>02783                             max_intensity = par[i]->fit_par[0] ;
+<a name="l02784"></a>02784                             found = i ;
+<a name="l02785"></a>02785                         }
+<a name="l02786"></a>02786                     }
+<a name="l02787"></a>02787                 }
+<a name="l02788"></a>02788             }  
+<a name="l02789"></a>02789         }
+<a name="l02790"></a>02790 
+<a name="l02791"></a>02791         <span class="comment">/* --------------------------------------------------------------------</span>
+<a name="l02792"></a>02792 <span class="comment">         * check if the found line is usable and if the neighbouring line </span>
+<a name="l02793"></a>02793 <span class="comment">         * have intensity on near rows in neighbouring slitlets </span>
+<a name="l02794"></a>02794 <span class="comment">         */</span>
+<a name="l02795"></a>02795         line    = par[found]->line ;
+<a name="l02796"></a>02796         column  = par[found]->column ;
+<a name="l02797"></a>02797         row_pos = par[found]->fit_par[2] ;
+<a name="l02798"></a>02798         <span class="keywordflow">if</span> ( found >= 0 && max_intensity > 0. )
+<a name="l02799"></a>02799         {
+<a name="l02800"></a>02800             <span class="keywordflow">for</span> ( i = 0 ; i < par[0]->n_params ; i++ )
+<a name="l02801"></a>02801             {
+<a name="l02802"></a>02802                 <span class="keywordflow">if</span> ( par[i]->line == line-1 && 
+<a name="l02803"></a>02803                      par[i]->column == column + slit_length )
+<a name="l02804"></a>02804                 {
+<a name="l02805"></a>02805                     <span class="keywordflow">if</span> ( par[i]->fit_par[2] <= (row_pos + y_box) &&
+<a name="l02806"></a>02806                          par[i]->fit_par[2] >= (row_pos - y_box) )
+<a name="l02807"></a>02807                     {
+<a name="l02808"></a>02808                         bad_line = line ;
+<a name="l02809"></a>02809                     } 
+<a name="l02810"></a>02810                 }
+<a name="l02811"></a>02811             }
+<a name="l02812"></a>02812             <span class="keywordflow">if</span> ( bad_line != line )
+<a name="l02813"></a>02813             {
+<a name="l02814"></a>02814                 agreed = 1 ;
+<a name="l02815"></a>02815                 break ;
+<a name="l02816"></a>02816             }
+<a name="l02817"></a>02817         }
+<a name="l02818"></a>02818         <span class="keywordflow">else</span> 
+<a name="l02819"></a>02819         {
+<a name="l02820"></a>02820             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no emission line found in "</span>
+<a name="l02821"></a>02821                             <span class="stringliteral">"the first image columns"</span>) ;
+<a name="l02822"></a>02822             cpl_free( sinfo_edge ) ;
+<a name="l02823"></a>02823             cpl_free( pos_row ) ;
+<a name="l02824"></a>02824             cpl_free( edgeclean ) ;
+<a name="l02825"></a>02825             cpl_free( dummyedge ) ;
+<a name="l02826"></a>02826             cpl_free( pos_rowclean ) ;
+<a name="l02827"></a>02827             <span class="keywordflow">return</span> -7 ;
+<a name="l02828"></a>02828         }    
+<a name="l02829"></a>02829     }
+<a name="l02830"></a>02830 
+<a name="l02831"></a>02831  
+<a name="l02832"></a>02832     <span class="keywordflow">if</span> ( agreed == -1 )
+<a name="l02833"></a>02833     {
+<a name="l02834"></a>02834         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" no emission line found in the first image columns"</span>) ;
+<a name="l02835"></a>02835         cpl_free( sinfo_edge ) ;
+<a name="l02836"></a>02836         cpl_free( pos_row ) ;
+<a name="l02837"></a>02837         cpl_free( edgeclean ) ;
+<a name="l02838"></a>02838         cpl_free( dummyedge ) ;
+<a name="l02839"></a>02839         cpl_free( pos_rowclean ) ;
+<a name="l02840"></a>02840         <span class="keywordflow">return</span> -7 ;
+<a name="l02841"></a>02841     }    
+<a name="l02842"></a>02842  
+<a name="l02843"></a>02843     <span class="comment">/* now find and store the raw sinfo_edge positions of the found slitlet */</span> 
+<a name="l02844"></a>02844     n  = 0 ;
+<a name="l02845"></a>02845     ed = 0 ;
+<a name="l02846"></a>02846     position=cpl_calloc(ilx,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l02847"></a>02847 
+<a name="l02848"></a>02848     <span class="keywordflow">for</span> ( col = 0 ; col < ilx ; col++ )
+<a name="l02849"></a>02849     {
+<a name="l02850"></a>02850         <span class="keywordflow">for</span> ( i = 0 ; i < par[0]->n_params ; i++ )
+<a name="l02851"></a>02851         {
+<a name="l02852"></a>02852             <span class="keywordflow">if</span> ( par[i]->column == col && par[i]->line == line )
+<a name="l02853"></a>02853             {
+<a name="l02854"></a>02854                 <span class="keywordflow">if</span> ( par[i]->fit_par[0] > 0. && 
+<a name="l02855"></a>02855                      par[i]->fit_par[1] >= 1.  && 
+<a name="l02856"></a>02856                      par[i]->fit_par[2] > 0. )
+<a name="l02857"></a>02857                 {
+<a name="l02858"></a>02858                     position[n] = par[i]->fit_par[2] ;
+<a name="l02859"></a>02859                     <span class="keywordflow">if</span> ( n > 0 && fabs(position[n] - position[n-1]) > y_box )
+<a name="l02860"></a>02860                     {
+<a name="l02861"></a>02861                         sinfo_edge[ed] = col ; 
+<a name="l02862"></a>02862                         pos_row[ed] = sinfo_new_nint( position[n-1] ) ;
+<a name="l02863"></a>02863                         ed++ ;
+<a name="l02864"></a>02864                         <span class="keywordflow">if</span> ( col >= ilx - slit_length - 5 ) 
+<a name="l02865"></a>02865                         {
+<a name="l02866"></a>02866                             pos_row[ed] =  sinfo_new_nint( position[n] ) ;
+<a name="l02867"></a>02867                         }
+<a name="l02868"></a>02868                     }
+<a name="l02869"></a>02869                     n++ ;
+<a name="l02870"></a>02870                 }
+<a name="l02871"></a>02871             }
+<a name="l02872"></a>02872         }
+<a name="l02873"></a>02873     }
+<a name="l02874"></a>02874     <span class="keywordflow">if</span> ( ed < (slit_length - 1) )
+<a name="l02875"></a>02875     {
+<a name="l02876"></a>02876         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" not enough slitlets found"</span>) ;
+<a name="l02877"></a>02877         cpl_free( sinfo_edge ) ;
+<a name="l02878"></a>02878         cpl_free( pos_row ) ;
+<a name="l02879"></a>02879         cpl_free( edgeclean ) ;
+<a name="l02880"></a>02880         cpl_free( dummyedge ) ;
+<a name="l02881"></a>02881         cpl_free( pos_rowclean ) ;
+<a name="l02882"></a>02882         <span class="keywordflow">return</span> -8 ;
+<a name="l02883"></a>02883     } 
+<a name="l02884"></a>02884 
+<a name="l02885"></a>02885     <span class="comment">/* now find the clean sinfo_edge and row positions of the slitlets */</span>
+<a name="l02886"></a>02886     <span class="keywordflow">for</span> ( i = 1 ; i <= ed ; i ++ )
+<a name="l02887"></a>02887     {
+<a name="l02888"></a>02888         <span class="keywordflow">if</span> ( i == ed )
+<a name="l02889"></a>02889         {
+<a name="l02890"></a>02890             <span class="keywordflow">if</span> ( (sinfo_edge[i-1] - sinfo_edge[i-2]) < slit_length - 3 ||
+<a name="l02891"></a>02891                  (sinfo_edge[i-1] - sinfo_edge[i-2]) > slit_length + 3 )
+<a name="l02892"></a>02892             {
+<a name="l02893"></a>02893                 dummyedge[i-1]   = -1 ;
+<a name="l02894"></a>02894             }
+<a name="l02895"></a>02895             
+<a name="l02896"></a>02896         }
+<a name="l02897"></a>02897         <span class="keywordflow">if</span> (dummyedge[i-1] != -1)
+<a name="l02898"></a>02898         {
+<a name="l02899"></a>02899             dummyedge[i-1] = sinfo_edge[i-1] ;
+<a name="l02900"></a>02900         }
+<a name="l02901"></a>02901         <span class="keywordflow">else</span>
+<a name="l02902"></a>02902         {
+<a name="l02903"></a>02903             continue ;
+<a name="l02904"></a>02904         }
+<a name="l02905"></a>02905         <span class="keywordflow">if</span> ( i < ed )
+<a name="l02906"></a>02906         {
+<a name="l02907"></a>02907             <span class="keywordflow">if</span> ( (sinfo_edge[i] - sinfo_edge[i-1]) < slit_length - 3 ||
+<a name="l02908"></a>02908                  (sinfo_edge[i] - sinfo_edge[i-1]) > slit_length + 3 )
+<a name="l02909"></a>02909             {
+<a name="l02910"></a>02910                 dummyedge[i]   = -1 ;
+<a name="l02911"></a>02911             }
+<a name="l02912"></a>02912         }
+<a name="l02913"></a>02913         <span class="keywordflow">if</span> ( i + 1 < ed && dummyedge[i] != -1 )
+<a name="l02914"></a>02914         {
+<a name="l02915"></a>02915             <span class="keywordflow">if</span> ( (sinfo_edge[i+1] - sinfo_edge[i]) < slit_length - 3 ||
+<a name="l02916"></a>02916                  (sinfo_edge[i+1] - sinfo_edge[i]) > slit_length + 3 )
+<a name="l02917"></a>02917             {
+<a name="l02918"></a>02918                 dummyedge[i+1] = -1 ; 
+<a name="l02919"></a>02919             }
+<a name="l02920"></a>02920         }
+<a name="l02921"></a>02921     }
+<a name="l02922"></a>02922     
+<a name="l02923"></a>02923     k = 0 ;
+<a name="l02924"></a>02924     <span class="keywordflow">for</span> ( i = 0 ; i < ed ; i++ )
+<a name="l02925"></a>02925     {
+<a name="l02926"></a>02926         <span class="keywordflow">if</span> ( dummyedge[i] != -1 && dummyedge[i] != 0 )
+<a name="l02927"></a>02927         {
+<a name="l02928"></a>02928             edgeclean[k] = dummyedge[i] ;
+<a name="l02929"></a>02929             pos_rowclean[k] = pos_row[i] ;
+<a name="l02930"></a>02930             k++ ;
+<a name="l02931"></a>02931             <span class="keywordflow">if</span>( edgeclean[k-1] > (ilx - slit_length - 6 ) )
+<a name="l02932"></a>02932             {
+<a name="l02933"></a>02933                 pos_rowclean[k] = pos_row[ed] ;
+<a name="l02934"></a>02934             }
+<a name="l02935"></a>02935         }
+<a name="l02936"></a>02936     }
+<a name="l02937"></a>02937 
+<a name="l02938"></a>02938     <span class="keywordflow">if</span> ( k != slit_length - 1 )
+<a name="l02939"></a>02939     {
+<a name="l02940"></a>02940         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" not enough clean slitlets found"</span>) ;
+<a name="l02941"></a>02941         cpl_free( sinfo_edge ) ;
+<a name="l02942"></a>02942         cpl_free( pos_row ) ;
+<a name="l02943"></a>02943         cpl_free( edgeclean ) ;
+<a name="l02944"></a>02944         cpl_free( dummyedge ) ;
+<a name="l02945"></a>02945         cpl_free( pos_rowclean ) ;
+<a name="l02946"></a>02946         <span class="keywordflow">return</span> -8 ;
+<a name="l02947"></a>02947     } 
+<a name="l02948"></a>02948 
+<a name="l02949"></a>02949     <span class="comment">/* determine the margins of the fitting box outside the slitlets */</span>
+<a name="l02950"></a>02950     margin = box_length / 2 ;
+<a name="l02951"></a>02951 
+<a name="l02952"></a>02952     <span class="comment">/* ------------------------------------------------------------------------</span>
+<a name="l02953"></a>02953 <span class="comment">     * now go through the slitlets, search along each column within a box with </span>
+<a name="l02954"></a>02954 <span class="comment">     * half width y_box the maximum value and store these found values in a </span>
+<a name="l02955"></a>02955 <span class="comment">     * buffer</span>
+<a name="l02956"></a>02956 <span class="comment">     */</span>
+<a name="l02957"></a>02957     <span class="keywordflow">for</span> ( j = 0 ; j <= k ; j++ )
+<a name="l02958"></a>02958     {
+<a name="l02959"></a>02959         m = 0 ;
+<a name="l02960"></a>02960         <span class="keywordflow">if</span> ( j == 0 )
+<a name="l02961"></a>02961         {
+<a name="l02962"></a>02962             box_buffer = sinfo_new_vector( edgeclean[0] + margin ) ;
+<a name="l02963"></a>02963             <span class="keywordflow">for</span>( col = 0 ; col < edgeclean[0] + margin ; col++ )
+<a name="l02964"></a>02964             {
+<a name="l02965"></a>02965                 maxval = -FLT_MAX ;
+<a name="l02966"></a>02966                 <span class="keywordflow">for</span> ( row = pos_rowclean[0] - sinfo_new_nint(y_box) ; 
+<a name="l02967"></a>02967                       row <= pos_rowclean[0] + sinfo_new_nint(y_box) ; row++ )
+<a name="l02968"></a>02968                 {
+<a name="l02969"></a>02969                     <span class="keywordflow">if</span> ( maxval < pidata[col + ilx*row] )
+<a name="l02970"></a>02970                     {
+<a name="l02971"></a>02971                         maxval = pidata[col + ilx*row] ;
+<a name="l02972"></a>02972                     }
+<a name="l02973"></a>02973                 }
+<a name="l02974"></a>02974                 box_buffer->data[m] = maxval ;
+<a name="l02975"></a>02975                 m++ ;
+<a name="l02976"></a>02976             }
+<a name="l02977"></a>02977         }
+<a name="l02978"></a>02978         <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( j < k )
+<a name="l02979"></a>02979         {
+<a name="l02980"></a>02980             box_buffer = sinfo_new_vector( edgeclean[j] - 
+<a name="l02981"></a>02981                                            edgeclean[j-1] + 2*margin ) ;
+<a name="l02982"></a>02982             <span class="keywordflow">for</span> ( col = edgeclean[j - 1] - margin ; 
+<a name="l02983"></a>02983                   col < edgeclean[j] + margin ; col++ )
+<a name="l02984"></a>02984             {
+<a name="l02985"></a>02985                 maxval = -FLT_MAX ;
+<a name="l02986"></a>02986                 <span class="keywordflow">for</span> ( row = pos_rowclean[j] - sinfo_new_nint(y_box) ; 
+<a name="l02987"></a>02987                       row <= pos_rowclean[j] + sinfo_new_nint(y_box) ; row++ )
+<a name="l02988"></a>02988                 {
+<a name="l02989"></a>02989                     <span class="keywordflow">if</span> ( maxval < pidata[col + ilx*row] )
+<a name="l02990"></a>02990                     {
+<a name="l02991"></a>02991                         maxval = pidata[col + ilx*row] ;
+<a name="l02992"></a>02992                     }
+<a name="l02993"></a>02993                 }
+<a name="l02994"></a>02994                 box_buffer->data[m] = maxval ;
+<a name="l02995"></a>02995                 m++ ;
+<a name="l02996"></a>02996             }
+<a name="l02997"></a>02997         }
+<a name="l02998"></a>02998         <span class="keywordflow">else</span> 
+<a name="l02999"></a>02999         {
+<a name="l03000"></a>03000             box_buffer = sinfo_new_vector( ilx - edgeclean[k-1] + margin ) ;
+<a name="l03001"></a>03001             <span class="keywordflow">for</span> ( col = edgeclean[k - 1] - margin ; col < ilx ; col++ )
+<a name="l03002"></a>03002             {
+<a name="l03003"></a>03003                 maxval = -FLT_MAX ;
+<a name="l03004"></a>03004                 <span class="keywordflow">for</span> ( row = pos_rowclean[k] - sinfo_new_nint(y_box) ; 
+<a name="l03005"></a>03005                       row <= pos_rowclean[k] + sinfo_new_nint(y_box) ; row++ )
+<a name="l03006"></a>03006                 {
+<a name="l03007"></a>03007                     <span class="keywordflow">if</span> ( maxval < pidata[col + ilx*row] )
+<a name="l03008"></a>03008                     {
+<a name="l03009"></a>03009                         maxval = pidata[col + ilx*row] ;
+<a name="l03010"></a>03010                     }
+<a name="l03011"></a>03011                 }
+<a name="l03012"></a>03012                 box_buffer->data[m] = maxval ;
+<a name="l03013"></a>03013                 m++ ;
+<a name="l03014"></a>03014             }
+<a name="l03015"></a>03015         }
+<a name="l03016"></a>03016 
+<a name="l03017"></a>03017         <span class="keywordflow">for</span> ( left_right = 0 ; left_right <= 1 ; left_right++ )
+<a name="l03018"></a>03018         { 
+<a name="l03019"></a>03019             nel = 0 ;
+<a name="l03020"></a>03020             <span class="keywordflow">if</span> ( left_right == 0 )
+<a name="l03021"></a>03021             {
+<a name="l03022"></a>03022                 nel = box_buffer -> n_elements / 2 ;
+<a name="l03023"></a>03023             }
+<a name="l03024"></a>03024             <span class="keywordflow">else</span>
+<a name="l03025"></a>03025             {
+<a name="l03026"></a>03026                 <span class="keywordflow">if</span> ( box_buffer -> n_elements % 2 == 0 )
+<a name="l03027"></a>03027                 {
+<a name="l03028"></a>03028                     nel = box_buffer -> n_elements / 2 ;
+<a name="l03029"></a>03029                 }
+<a name="l03030"></a>03030                 <span class="keywordflow">else</span>
+<a name="l03031"></a>03031                 {
+<a name="l03032"></a>03032                     nel = box_buffer -> n_elements / 2 + 1 ;
+<a name="l03033"></a>03033                 }
+<a name="l03034"></a>03034             }
+<a name="l03035"></a>03035 
+<a name="l03036"></a>03036             <span class="comment">/* now split the buffer in the midth in a left and right </span>
+<a name="l03037"></a>03037 <span class="comment">               part for fitting */</span>
+<a name="l03038"></a>03038             half_buffer = sinfo_new_vector( nel ) ;
+<a name="l03039"></a>03039             <span class="keywordflow">if</span> ( left_right == 0 )
+<a name="l03040"></a>03040             {
+<a name="l03041"></a>03041                 <span class="keywordflow">for</span> ( i = 0 ; i < nel ; i++ )
+<a name="l03042"></a>03042                 {
+<a name="l03043"></a>03043                     half_buffer -> data[i] = box_buffer -> data[i] ;
+<a name="l03044"></a>03044                 }
+<a name="l03045"></a>03045             }
+<a name="l03046"></a>03046             <span class="keywordflow">else</span>
+<a name="l03047"></a>03047             {
+<a name="l03048"></a>03048                 n_right = 0 ;
+<a name="l03049"></a>03049                 <span class="keywordflow">for</span> ( i = box_buffer -> n_elements - 1 ; 
+<a name="l03050"></a>03050                       i >= box_buffer -> n_elements - nel ; i-- )
+<a name="l03051"></a>03051                 {
+<a name="l03052"></a>03052                     half_buffer -> data[n_right] = box_buffer -> data[i] ;
+<a name="l03053"></a>03053                     n_right++ ;
+<a name="l03054"></a>03054                 }
+<a name="l03055"></a>03055             }
+<a name="l03056"></a>03056 
+<a name="l03057"></a>03057             xdat = (<span class="keywordtype">float</span> *) cpl_calloc( nel, <span class="keyword">sizeof</span> (<span class="keywordtype">float</span>) ) ;
+<a name="l03058"></a>03058             wdat = (<span class="keywordtype">float</span> *) cpl_calloc( nel, <span class="keyword">sizeof</span> (<span class="keywordtype">float</span>) ) ;
+<a name="l03059"></a>03059             mpar = (<span class="keywordtype">int</span> *)   cpl_calloc( NPAR, <span class="keyword">sizeof</span> (<span class="keywordtype">int</span>) ) ;
+<a name="l03060"></a>03060 
+<a name="l03061"></a>03061             <span class="comment">/* set initial values for the fitting routine */</span>
+<a name="l03062"></a>03062             minval =  FLT_MAX ;
+<a name="l03063"></a>03063             maxval = -FLT_MAX ;
+<a name="l03064"></a>03064             <span class="keywordflow">for</span> ( i = 0 ; i < nel ; i++ )
+<a name="l03065"></a>03065             {
+<a name="l03066"></a>03066                 xdat[i] = i ;
+<a name="l03067"></a>03067                 wdat[i] = 1.0 ;
+<a name="l03068"></a>03068                 <span class="keywordflow">if</span> ( half_buffer -> data[i] < minval )
+<a name="l03069"></a>03069                 {
+<a name="l03070"></a>03070                     minval = half_buffer -> data[i] ;
+<a name="l03071"></a>03071                 }
+<a name="l03072"></a>03072                 <span class="keywordflow">if</span> ( half_buffer -> data[i] > maxval )
+<a name="l03073"></a>03073                 {
+<a name="l03074"></a>03074                     maxval = half_buffer -> data[i] ;
+<a name="l03075"></a>03075                 }
+<a name="l03076"></a>03076             }
+<a name="l03077"></a>03077 
+<a name="l03078"></a>03078             fitpar[2] = minval ;
+<a name="l03079"></a>03079             fitpar[3] = maxval ; 
+<a name="l03080"></a>03080 
+<a name="l03081"></a>03081             <span class="comment">/* search for both positions of the half intensity of </span>
+<a name="l03082"></a>03082 <span class="comment">               the hat within the buffer */</span>
+<a name="l03083"></a>03083             init1 = -1 ; 
+<a name="l03084"></a>03084             <span class="keywordflow">for</span> ( i = 0 ; i < nel ; i++ )
+<a name="l03085"></a>03085             {
+<a name="l03086"></a>03086                 <span class="keywordflow">if</span> ( half_buffer -> data[i] >= ( maxval + minval ) / 2. )
+<a name="l03087"></a>03087                 {
+<a name="l03088"></a>03088                     init1 = i ;
+<a name="l03089"></a>03089                     break ;
+<a name="l03090"></a>03090                 }
+<a name="l03091"></a>03091             }
+<a name="l03092"></a>03092 
+<a name="l03093"></a>03093             <span class="comment">/* determine the initial positions from the found values */</span>
+<a name="l03094"></a>03094             <span class="keywordflow">if</span> ( init1 != -1 )
+<a name="l03095"></a>03095             {
+<a name="l03096"></a>03096                 fitpar[0] = ((float)init1 - 1.) ;
+<a name="l03097"></a>03097                 fitpar[1] = ((float)init1 + 1.) ;
+<a name="l03098"></a>03098             }
+<a name="l03099"></a>03099 
+<a name="l03100"></a>03100             <span class="keywordflow">for</span> ( i = 0 ; i < NPAR ; i++ )
+<a name="l03101"></a>03101             {
+<a name="l03102"></a>03102                 mpar[i] = 1 ;
+<a name="l03103"></a>03103                 dervpar[i] = 0. ;
+<a name="l03104"></a>03104             }
+<a name="l03105"></a>03105       
+<a name="l03106"></a>03106             xdim     = XDIMA ;
+<a name="l03107"></a>03107             ndat     = nel ;
+<a name="l03108"></a>03108             numpar   = NPAR ;
+<a name="l03109"></a>03109             tol      = TOLA ;
+<a name="l03110"></a>03110             lab      = LABA ;
+<a name="l03111"></a>03111             its      = ITSA ;
+<a name="l03112"></a>03112          
+<a name="l03113"></a>03113             <span class="comment">/* finally, do the least squares fit over the buffer data */</span>
+<a name="l03114"></a>03114             <span class="keywordflow">if</span> ( 0 > ( iters = sinfo_new_lsqfit_edge( xdat, &xdim, 
+<a name="l03115"></a>03115                                                       half_buffer -> data, 
+<a name="l03116"></a>03116                                                       wdat, &ndat, fitpar,
+<a name="l03117"></a>03117                                                       dervpar, mpar, &numpar, 
+<a name="l03118"></a>03118                                                       &tol, &its, &lab )) )
+<a name="l03119"></a>03119             { 
+<a name="l03120"></a>03120                 <span class="comment">/* if the fit doesn't succeed the initial values are taken */</span>
+<a name="l03121"></a>03121                 <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a> (<span class="stringliteral">"least squares fit failed, error "</span>
+<a name="l03122"></a>03122                                    <span class="stringliteral">"no.: %d in slitlet: %d"</span>, iters, j) ;
+<a name="l03123"></a>03123                 fitpar[0] = ((float)init1 - 1.) ;
+<a name="l03124"></a>03124                 fitpar[1] = ((float)init1 + 1.) ;
+<a name="l03125"></a>03125             }
+<a name="l03126"></a>03126 
+<a name="l03127"></a>03127             pos = (fitpar[0] + fitpar[1]) / 2. ;
+<a name="l03128"></a>03128 
+<a name="l03129"></a>03129             <span class="comment">/*----------------------------------------------------------------- </span>
+<a name="l03130"></a>03130 <span class="comment">             * now discern the left and the right sinfo_edge fit of the </span>
+<a name="l03131"></a>03131 <span class="comment">             * slitlets and associate the fit results with the absolute </span>
+<a name="l03132"></a>03132 <span class="comment">             * positions in the image consider the difference of the fitted </span>
+<a name="l03133"></a>03133 <span class="comment">             * slit position to the expected position and decide wether the </span>
+<a name="l03134"></a>03134 <span class="comment">             * fit is taken or the expected value is taken.</span>
+<a name="l03135"></a>03135 <span class="comment">             */</span>
+<a name="l03136"></a>03136             <span class="keywordflow">if</span> ( left_right == 0 )
+<a name="l03137"></a>03137             {
+<a name="l03138"></a>03138                 <span class="comment">/* take care of the column position of the fit boxes to get </span>
+<a name="l03139"></a>03139 <span class="comment">                   the absolute positions */</span>
+<a name="l03140"></a>03140                 <span class="keywordflow">if</span> ( j == 0 )
+<a name="l03141"></a>03141                 {
+<a name="l03142"></a>03142                     <span class="keywordflow">if</span> ( fabs(pos - ((<span class="keywordtype">float</span>)edgeclean[0] - 1. - 
+<a name="l03143"></a>03143                          (float)slit_length)) < diff_tol )
+<a name="l03144"></a>03144                     {
+<a name="l03145"></a>03145                         sinfo_slit_pos[0][0] = pos ;
+<a name="l03146"></a>03146                     }
+<a name="l03147"></a>03147                     <span class="keywordflow">else</span>
+<a name="l03148"></a>03148                     {
+<a name="l03149"></a>03149                         <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"something wrong with fitted "</span>
+<a name="l03150"></a>03150                                           <span class="stringliteral">"left position of slitlet 0"</span>) ;
+<a name="l03151"></a>03151                         <span class="keywordflow">if</span> ((<span class="keywordtype">float</span>) edgeclean[0] - 1. - 
+<a name="l03152"></a>03152                             (<span class="keywordtype">float</span>)slit_length < 0. )
+<a name="l03153"></a>03153                         {
+<a name="l03154"></a>03154                             sinfo_slit_pos[0][0] = 0. ;
+<a name="l03155"></a>03155                         }
+<a name="l03156"></a>03156                         <span class="keywordflow">else</span>
+<a name="l03157"></a>03157                         {
+<a name="l03158"></a>03158                             sinfo_slit_pos[0][0] = (float)edgeclean[0] - 1. - 
+<a name="l03159"></a>03159                                                    (<span class="keywordtype">float</span>)slit_length ;
+<a name="l03160"></a>03160                         }
+<a name="l03161"></a>03161                     }
+<a name="l03162"></a>03162                 }
+<a name="l03163"></a>03163                 <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( j < k )
+<a name="l03164"></a>03164                 {
+<a name="l03165"></a>03165                     <span class="keywordflow">if</span> ( fabs( pos - (<span class="keywordtype">float</span>)margin ) < diff_tol )
+<a name="l03166"></a>03166                     {
+<a name="l03167"></a>03167                         sinfo_slit_pos[j][0] = pos + (float)edgeclean[j-1] - 
+<a name="l03168"></a>03168                                                      (<span class="keywordtype">float</span>)margin ;
+<a name="l03169"></a>03169                     }
+<a name="l03170"></a>03170                     else
+<a name="l03171"></a>03171                     {
+<a name="l03172"></a>03172                         <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"something wrong with fitted "</span>
+<a name="l03173"></a>03173                                           <span class="stringliteral">"left position of slitlet %d"</span>, j) ;
+<a name="l03174"></a>03174                         sinfo_slit_pos[j][0] = (float)edgeclean[j-1] - 1. ;
+<a name="l03175"></a>03175                     }
+<a name="l03176"></a>03176                 }
+<a name="l03177"></a>03177                 <span class="keywordflow">else</span>
+<a name="l03178"></a>03178                 {
+<a name="l03179"></a>03179                     <span class="keywordflow">if</span> ( fabs( pos - (<span class="keywordtype">float</span>)margin ) < diff_tol )
+<a name="l03180"></a>03180                     {
+<a name="l03181"></a>03181                         sinfo_slit_pos[k][0] = pos + (float)edgeclean[k-1] - 
+<a name="l03182"></a>03182                                                      (<span class="keywordtype">float</span>)margin ;
+<a name="l03183"></a>03183                     }
+<a name="l03184"></a>03184                     else
+<a name="l03185"></a>03185                     {
+<a name="l03186"></a>03186                         <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"something wrong with fitted left "</span>
+<a name="l03187"></a>03187                                           <span class="stringliteral">"position of slitlet %d"</span>, j) ;
+<a name="l03188"></a>03188                         sinfo_slit_pos[k][0] = (float)edgeclean[k-1] - 1. ;
+<a name="l03189"></a>03189                     }
+<a name="l03190"></a>03190                 }
+<a name="l03191"></a>03191             }
+<a name="l03192"></a>03192             <span class="keywordflow">else</span>
+<a name="l03193"></a>03193             {
+<a name="l03194"></a>03194                 <span class="comment">/* take care of the column position of the fit boxes to </span>
+<a name="l03195"></a>03195 <span class="comment">                   get the absolute positions */</span>
+<a name="l03196"></a>03196                 <span class="keywordflow">if</span> ( j == 0 )
+<a name="l03197"></a>03197                 {
+<a name="l03198"></a>03198                     <span class="keywordflow">if</span> ( fabs( (<span class="keywordtype">float</span>)box_buffer->n_elements - pos - 
+<a name="l03199"></a>03199                                (<span class="keywordtype">float</span>)edgeclean[0] ) < diff_tol )
+<a name="l03200"></a>03200                     {
+<a name="l03201"></a>03201                        sinfo_slit_pos[0][1] = (float)(box_buffer->n_elements - 
+<a name="l03202"></a>03202                                                1) - pos ;
+<a name="l03203"></a>03203                     }
+<a name="l03204"></a>03204                     <span class="keywordflow">else</span>
+<a name="l03205"></a>03205                     {
+<a name="l03206"></a>03206                         <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"something wrong with fitted "</span>
+<a name="l03207"></a>03207                                           <span class="stringliteral">"right position of slitlet 0"</span>) ;
+<a name="l03208"></a>03208                         sinfo_slit_pos[0][1] = (float)edgeclean[0] - 1. ;
+<a name="l03209"></a>03209                     }
+<a name="l03210"></a>03210                 }
+<a name="l03211"></a>03211                 <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( j < k )
+<a name="l03212"></a>03212                 {
+<a name="l03213"></a>03213                     <span class="keywordflow">if</span> ( fabs( (<span class="keywordtype">float</span>)box_buffer->n_elements - pos
+<a name="l03214"></a>03214                              + (<span class="keywordtype">float</span>)edgeclean[j-1] - (<span class="keywordtype">float</span>)margin - 
+<a name="l03215"></a>03215                                (<span class="keywordtype">float</span>)edgeclean[j] ) < diff_tol )
+<a name="l03216"></a>03216                     {
+<a name="l03217"></a>03217                         sinfo_slit_pos[j][1] = (float)(box_buffer->n_elements -
+<a name="l03218"></a>03218                                                1) - pos
+<a name="l03219"></a>03219                                        + (float)edgeclean[j-1] - (<span class="keywordtype">float</span>)margin;
+<a name="l03220"></a>03220                     }
+<a name="l03221"></a>03221                     else
+<a name="l03222"></a>03222                     {
+<a name="l03223"></a>03223                         <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"something wrong with fitted "</span>
+<a name="l03224"></a>03224                                           <span class="stringliteral">"right position of slitlet %d"</span>, j) ;
+<a name="l03225"></a>03225                         sinfo_slit_pos[j][1] = (float)edgeclean[j] - 1. ;
+<a name="l03226"></a>03226                     }
+<a name="l03227"></a>03227                 }
+<a name="l03228"></a>03228                 <span class="keywordflow">else</span>
+<a name="l03229"></a>03229                 {
+<a name="l03230"></a>03230                     <span class="keywordflow">if</span> ( edgeclean[k-1] + slit_length > ilx )
+<a name="l03231"></a>03231                     {
+<a name="l03232"></a>03232                         last_pos = (float)(ilx - 1) ;
+<a name="l03233"></a>03233                     }
+<a name="l03234"></a>03234                     <span class="keywordflow">else</span>
+<a name="l03235"></a>03235                     {
+<a name="l03236"></a>03236                         last_pos = (float)(edgeclean[k-1] - 1 + slit_length) ;
+<a name="l03237"></a>03237                     }
+<a name="l03238"></a>03238                     <span class="keywordflow">if</span> ( fabs( (<span class="keywordtype">float</span>)(box_buffer->n_elements - 1) - pos
+<a name="l03239"></a>03239                              + (<span class="keywordtype">float</span>)edgeclean[k-1] - (float)margin - 
+<a name="l03240"></a>03240                                last_pos ) < diff_tol )
+<a name="l03241"></a>03241                     {
+<a name="l03242"></a>03242                         sinfo_slit_pos[k][1] = (float)(box_buffer->n_elements -
+<a name="l03243"></a>03243                                                1) - pos
+<a name="l03244"></a>03244                                        + (float)edgeclean[k-1] - (<span class="keywordtype">float</span>)margin ;
+<a name="l03245"></a>03245                     }
+<a name="l03246"></a>03246                     else
+<a name="l03247"></a>03247                     {
+<a name="l03248"></a>03248                         <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"something wrong with fitted "</span>
+<a name="l03249"></a>03249                                           <span class="stringliteral">"right position of slitlet %d"</span>, j) ;
+<a name="l03250"></a>03250                         sinfo_slit_pos[k][1] = last_pos ;
+<a name="l03251"></a>03251                     }
+<a name="l03252"></a>03252                 }
+<a name="l03253"></a>03253             }
+<a name="l03254"></a>03254 
+<a name="l03255"></a>03255             sinfo_new_destroy_vector ( half_buffer ) ;
+<a name="l03256"></a>03256             cpl_free( xdat ) ;
+<a name="l03257"></a>03257             cpl_free( wdat ) ;
+<a name="l03258"></a>03258             cpl_free( mpar ) ;
+<a name="l03259"></a>03259         }
+<a name="l03260"></a>03260         sinfo_new_destroy_vector ( box_buffer ) ;
+<a name="l03261"></a>03261     }
+<a name="l03262"></a>03262         
+<a name="l03263"></a>03263     cpl_free( sinfo_edge ) ;
+<a name="l03264"></a>03264     cpl_free( pos_row ) ;
+<a name="l03265"></a>03265     cpl_free( edgeclean ) ;
+<a name="l03266"></a>03266     cpl_free( dummyedge ) ;
+<a name="l03267"></a>03267     cpl_free( pos_rowclean ) ;
+<a name="l03268"></a>03268     cpl_free( position );
+<a name="l03269"></a>03269     <span class="keywordflow">return</span> 0 ;
+<a name="l03270"></a>03270 }
+<a name="l03271"></a>03271 
+<a name="l03294"></a>03294 <span class="keywordtype">int</span> 
+<a name="l03295"></a>03295 sinfo_new_fit_slits_edge_with_estimate ( cpl_image   * lineImage,
+<a name="l03296"></a>03296                                <span class="keywordtype">float</span>     ** sinfo_slit_pos,
+<a name="l03297"></a>03297                                <span class="keywordtype">int</span>          box_length,
+<a name="l03298"></a>03298                                <span class="keywordtype">float</span>        y_box,
+<a name="l03299"></a>03299                                <span class="keywordtype">float</span>        diff_tol,
+<a name="l03300"></a>03300                                <span class="keywordtype">int</span>          low_pos,
+<a name="l03301"></a>03301                                <span class="keywordtype">int</span>          high_pos )
+<a name="l03302"></a>03302 {
+<a name="l03303"></a>03303     <span class="keywordtype">int</span>*   position=NULL ;
+<a name="l03304"></a>03304     Vector * box_buffer ;
+<a name="l03305"></a>03305     Vector * in_buffer ;
+<a name="l03306"></a>03306     <span class="keywordtype">int</span>   found_row ;
+<a name="l03307"></a>03307     <span class="keywordtype">int</span>   row, col ;
+<a name="l03308"></a>03308     <span class="keywordtype">int</span>   col_first, col_last ;
+<a name="l03309"></a>03309     <span class="keywordtype">int</span>   row_first, row_last ;
+<a name="l03310"></a>03310     <span class="keywordtype">int</span>   i, j, m, n ;
+<a name="l03311"></a>03311     <span class="keywordtype">int</span>   init1 ;
+<a name="l03312"></a>03312     <span class="keywordtype">int</span>   left_right ;
+<a name="l03313"></a>03313     <span class="keywordtype">int</span>   n_buf, shift ;
+<a name="l03314"></a>03314     <span class="keywordtype">int</span>   slit_length ;
+<a name="l03315"></a>03315     <span class="keywordtype">int</span>   iters, xdim, ndat ;
+<a name="l03316"></a>03316     <span class="keywordtype">int</span>   numpar, its ;
+<a name="l03317"></a>03317     <span class="keywordtype">int</span>   * mpar ;
+<a name="l03318"></a>03318     <span class="keywordtype">float</span> * xdat, * wdat ;
+<a name="l03319"></a>03319     <span class="keywordtype">float</span> tol, lab ;
+<a name="l03320"></a>03320     <span class="keywordtype">float</span> fitpar[NPAR] ;
+<a name="l03321"></a>03321     <span class="keywordtype">float</span> dervpar[NPAR] ;
+<a name="l03322"></a>03322     <span class="keywordtype">float</span> minval, maxval ;
+<a name="l03323"></a>03323     <span class="keywordtype">float</span> pos ;
+<a name="l03324"></a>03324     <span class="keywordtype">float</span> new_pos ;
+<a name="l03325"></a>03325     <span class="keywordtype">int</span>   slitposition[SLITLENGTH] ;
+<a name="l03326"></a>03326     pixelvalue rowpos[SLITLENGTH] ;
+<a name="l03327"></a>03327     <span class="keywordtype">int</span> ilx=0;
+<a name="l03328"></a>03328     <span class="keywordtype">int</span> ily=0;
+<a name="l03329"></a>03329     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l03330"></a>03330 
+<a name="l03331"></a>03331     slit_length = SLITLENGTH ; <span class="comment">/* this is too high: 64 */</span>
+<a name="l03332"></a>03332     slit_length = N_SLITLETS ; <span class="comment">/* this is better: 32 */</span>
+<a name="l03333"></a>03333 
+<a name="l03334"></a>03334 
+<a name="l03335"></a>03335     <span class="keywordflow">if</span> ( NULL == lineImage )
+<a name="l03336"></a>03336     {
+<a name="l03337"></a>03337         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" no line image given!"</span> ) ;
+<a name="l03338"></a>03338         <span class="keywordflow">return</span> -1 ;
+<a name="l03339"></a>03339     }
+<a name="l03340"></a>03340     ilx=cpl_image_get_size_x(lineImage);
+<a name="l03341"></a>03341     ily=cpl_image_get_size_y(lineImage);
+<a name="l03342"></a>03342     pidata=cpl_image_get_data_float(lineImage);
+<a name="l03343"></a>03343 
+<a name="l03344"></a>03344     <span class="keywordflow">if</span> ( NULL == sinfo_slit_pos )
+<a name="l03345"></a>03345     {
+<a name="l03346"></a>03346         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" no position array allocated!"</span> ) ;
+<a name="l03347"></a>03347         <span class="keywordflow">return</span> -1 ;
+<a name="l03348"></a>03348     }
+<a name="l03349"></a>03349 
+<a name="l03350"></a>03350     <span class="keywordflow">if</span> ( box_length < 4 ||
+<a name="l03351"></a>03351          box_length > 2*slit_length )
+<a name="l03352"></a>03352     {
+<a name="l03353"></a>03353         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" wrong fitting box length given!"</span> ) ;
+<a name="l03354"></a>03354         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" Must be 4 <= box_length < %d "</span>,2*slit_length ) ;
+<a name="l03355"></a>03355         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" You have chosen box_length = %d"</span>,box_length);
+<a name="l03356"></a>03356 
+<a name="l03357"></a>03357 
+<a name="l03358"></a>03358         <span class="keywordflow">return</span> -1 ;
+<a name="l03359"></a>03359     }
+<a name="l03360"></a>03360 
+<a name="l03361"></a>03361     <span class="keywordflow">if</span> ( y_box <= 0. || y_box > 6. )
+<a name="l03362"></a>03362     {
+<a name="l03363"></a>03363         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"wrong y box length given!"</span> ) ;
+<a name="l03364"></a>03364         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"You have chosen y_box=%f not in range (0,6]!"</span>,y_box);
+<a name="l03365"></a>03365         <span class="keywordflow">return</span> -1 ;
+<a name="l03366"></a>03366     }
+<a name="l03367"></a>03367     <span class="keywordflow">if</span> ( diff_tol <= 0. )
+<a name="l03368"></a>03368     {
+<a name="l03369"></a>03369         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" wrong diff_tol given!"</span> ) ;
+<a name="l03370"></a>03370         <span class="keywordflow">return</span> -1 ;
+<a name="l03371"></a>03371     }
+<a name="l03372"></a>03372 
+<a name="l03373"></a>03373         <span class="keywordflow">if</span> ( low_pos >= high_pos || low_pos < 0 || 
+<a name="l03374"></a>03374              high_pos <= 0 || high_pos > ily )
+<a name="l03375"></a>03375     {
+<a name="l03376"></a>03376         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" wrong user given search positions!"</span> ) ;
+<a name="l03377"></a>03377         <span class="keywordflow">return</span> -1 ;
+<a name="l03378"></a>03378     }
+<a name="l03379"></a>03379 
+<a name="l03380"></a>03380     <span class="comment">/* now search for the maximum between the given positions for each col */</span>
+<a name="l03381"></a>03381     position=cpl_calloc(ilx,<span class="keyword">sizeof</span>(<span class="keywordtype">int</span>)) ;
+<a name="l03382"></a>03382 
+<a name="l03383"></a>03383     <span class="keywordflow">for</span> ( col = 0 ; col < ilx ; col++ )
+<a name="l03384"></a>03384     {
+<a name="l03385"></a>03385         found_row = -1 ;
+<a name="l03386"></a>03386         maxval = -FLT_MAX ;
+<a name="l03387"></a>03387         <span class="keywordflow">for</span> ( row = low_pos ; row <= high_pos ; row++ )
+<a name="l03388"></a>03388         {
+<a name="l03389"></a>03389             <span class="keywordflow">if</span> ( maxval < pidata[col+row*ilx] )
+<a name="l03390"></a>03390             {
+<a name="l03391"></a>03391                 maxval = pidata[col+row*ilx] ;
+<a name="l03392"></a>03392                 found_row = row ;
+<a name="l03393"></a>03393             }
+<a name="l03394"></a>03394         }
+<a name="l03395"></a>03395         <span class="keywordflow">if</span> ( maxval > -FLT_MAX && found_row > low_pos )
+<a name="l03396"></a>03396         {
+<a name="l03397"></a>03397             position[col] = found_row ;
+<a name="l03398"></a>03398         }
+<a name="l03399"></a>03399         <span class="keywordflow">else</span>
+<a name="l03400"></a>03400         {
+<a name="l03401"></a>03401             position[col] = 0 ;
+<a name="l03402"></a>03402         }
+<a name="l03403"></a>03403     }
+<a name="l03404"></a>03404 
+<a name="l03405"></a>03405     <span class="comment">/* ------------------------------------------------------------------------</span>
+<a name="l03406"></a>03406 <span class="comment">     * now go through the slitlets, search along each column within a box with</span>
+<a name="l03407"></a>03407 <span class="comment">     * half width y_box the maximum value and store these found values in a </span>
+<a name="l03408"></a>03408 <span class="comment">     * buffer</span>
+<a name="l03409"></a>03409 <span class="comment">     */</span>
+<a name="l03410"></a>03410     <span class="keywordflow">for</span> ( j = 0 ; j < slit_length ; j++ )
+<a name="l03411"></a>03411     {
+<a name="l03412"></a>03412         <span class="comment">/* now go through the columns and determine the slitlet positions by</span>
+<a name="l03413"></a>03413 <span class="comment">         * calculating the sinfo_median of the found positions</span>
+<a name="l03414"></a>03414 <span class="comment">         */</span>
+<a name="l03415"></a>03415         n = 0 ;
+<a name="l03416"></a>03416         <span class="keywordflow">for</span> ( col = sinfo_new_nint(sinfo_slit_pos[j][0])+ 1 ; 
+<a name="l03417"></a>03417               col < sinfo_new_nint(sinfo_slit_pos[j][1]) -1 ; col++ )
+<a name="l03418"></a>03418         {
+<a name="l03419"></a>03419             rowpos[n] = (pixelvalue)position[col] ;
+<a name="l03420"></a>03420             n++ ;
+<a name="l03421"></a>03421         }
+<a name="l03422"></a>03422         slitposition[j] = (int)sinfo_new_median(rowpos, n) ;
+<a name="l03423"></a>03423         <span class="keywordflow">for</span> ( left_right = 0 ; left_right <= 1 ; left_right++ )
+<a name="l03424"></a>03424 
+<a name="l03425"></a>03425         {
+<a name="l03426"></a>03426             init1 = 0 ;
+<a name="l03427"></a>03427             col_first = sinfo_new_nint( sinfo_slit_pos[j][left_right] ) - 
+<a name="l03428"></a>03428                                         box_length/2 ;
+<a name="l03429"></a>03429             col_last  = sinfo_new_nint( sinfo_slit_pos[j][left_right] ) + 
+<a name="l03430"></a>03430                         box_length/2 ;
+<a name="l03431"></a>03431             <span class="keywordflow">if</span> ( col_first < 0 )
+<a name="l03432"></a>03432             {
+<a name="l03433"></a>03433                 col_first = 0 ;
+<a name="l03434"></a>03434                 init1 = 1 ;
+<a name="l03435"></a>03435             }
+<a name="l03436"></a>03436             <span class="keywordflow">if</span> ( col_last > ilx )
+<a name="l03437"></a>03437             {
+<a name="l03438"></a>03438                 col_last = ilx ;
+<a name="l03439"></a>03439                 init1 = 1 ;
+<a name="l03440"></a>03440             }
+<a name="l03441"></a>03441             <span class="keywordflow">if</span> ( col_last - col_first <= 0 )
+<a name="l03442"></a>03442             {
+<a name="l03443"></a>03443                 <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" first and last column wrong!"</span> ) ;
+<a name="l03444"></a>03444                 <span class="keywordflow">return</span> -1 ;
+<a name="l03445"></a>03445             }
+<a name="l03446"></a>03446             box_buffer = sinfo_new_vector( col_last - col_first ) ;
+<a name="l03447"></a>03447             m = 0 ;
+<a name="l03448"></a>03448             <span class="keywordflow">if</span> ( left_right == 0 )
+<a name="l03449"></a>03449             {
+<a name="l03450"></a>03450                 <span class="keywordflow">for</span>( col = col_first ; col < col_last ; col++ )
+<a name="l03451"></a>03451                 {
+<a name="l03452"></a>03452                     row_first = slitposition[j] - sinfo_new_nint(y_box) ;
+<a name="l03453"></a>03453                     row_last  = slitposition[j] + sinfo_new_nint(y_box) ;
+<a name="l03454"></a>03454                     <span class="keywordflow">if</span> ( row_first < 0 )
+<a name="l03455"></a>03455                     {
+<a name="l03456"></a>03456                         row_first = 0 ;
+<a name="l03457"></a>03457                     }
+<a name="l03458"></a>03458                     <span class="keywordflow">if</span> ( row_last >= ily  )
+<a name="l03459"></a>03459                     {
+<a name="l03460"></a>03460                         row_last = ily - 1 ;
+<a name="l03461"></a>03461                     }
+<a name="l03462"></a>03462                     maxval = -FLT_MAX ;
+<a name="l03463"></a>03463                     <span class="keywordflow">for</span> ( row = row_first ; row <= row_last ; row++ )
+<a name="l03464"></a>03464                     {
+<a name="l03465"></a>03465                         <span class="keywordflow">if</span> ( maxval < pidata[col + ilx*row] )
+<a name="l03466"></a>03466                         {
+<a name="l03467"></a>03467                             maxval = pidata[col + ilx*row] ;
+<a name="l03468"></a>03468                         }
+<a name="l03469"></a>03469                     }
+<a name="l03470"></a>03470                     box_buffer->data[m] = maxval ;
+<a name="l03471"></a>03471                     m++ ;
+<a name="l03472"></a>03472                 }
+<a name="l03473"></a>03473             }
+<a name="l03474"></a>03474             <span class="keywordflow">else</span>
+<a name="l03475"></a>03475             {
+<a name="l03476"></a>03476                 <span class="keywordflow">for</span>( col = col_last-1 ; col >= col_first ; col-- )
+<a name="l03477"></a>03477                 {
+<a name="l03478"></a>03478                     row_first = slitposition[j] - sinfo_new_nint(y_box) ;
+<a name="l03479"></a>03479                     row_last  = slitposition[j] + sinfo_new_nint(y_box) ;
+<a name="l03480"></a>03480                     <span class="keywordflow">if</span> ( row_first < 0 )
+<a name="l03481"></a>03481                     {
+<a name="l03482"></a>03482                         row_first = 0 ;
+<a name="l03483"></a>03483                     }
+<a name="l03484"></a>03484                     <span class="keywordflow">if</span> ( row_last >= ily  )
+<a name="l03485"></a>03485                     {
+<a name="l03486"></a>03486                         row_last = ily - 1 ;
+<a name="l03487"></a>03487                     }
+<a name="l03488"></a>03488                     maxval = -FLT_MAX ;
+<a name="l03489"></a>03489                     <span class="keywordflow">for</span> ( row = row_first ; row <= row_last ; row++ )
+<a name="l03490"></a>03490                     {
+<a name="l03491"></a>03491                         <span class="keywordflow">if</span> ( maxval < pidata[col + ilx*row] )
+<a name="l03492"></a>03492                         {
+<a name="l03493"></a>03493                             maxval = pidata[col + ilx*row] ;
+<a name="l03494"></a>03494                         }
+<a name="l03495"></a>03495                     }
+<a name="l03496"></a>03496                     box_buffer->data[m] = maxval ;
+<a name="l03497"></a>03497                     m++ ;
+<a name="l03498"></a>03498                 }
+<a name="l03499"></a>03499             }
+<a name="l03500"></a>03500 
+<a name="l03501"></a>03501             xdat=(<span class="keywordtype">float</span> *)cpl_calloc( box_buffer->n_elements, sizeof (<span class="keywordtype">float</span>));
+<a name="l03502"></a>03502             wdat=(<span class="keywordtype">float</span> *)cpl_calloc( box_buffer->n_elements, sizeof (<span class="keywordtype">float</span>));
+<a name="l03503"></a>03503             mpar=(<span class="keywordtype">int</span> *)  cpl_calloc( NPAR, <span class="keyword">sizeof</span> (<span class="keywordtype">int</span>) ) ;
+<a name="l03504"></a>03504 
+<a name="l03505"></a>03505             <span class="comment">/* set initial values for the fitting routine */</span>
+<a name="l03506"></a>03506             minval =  FLT_MAX ;
+<a name="l03507"></a>03507             maxval = -FLT_MAX ;
+<a name="l03508"></a>03508             <span class="keywordflow">for</span> ( i = 0 ; i < box_buffer->n_elements ; i++ )
+<a name="l03509"></a>03509             {
+<a name="l03510"></a>03510                 xdat[i] = i ;
+<a name="l03511"></a>03511                 wdat[i] = 1.0 ;
+<a name="l03512"></a>03512                 <span class="keywordflow">if</span> ( box_buffer -> data[i] < minval )
+<a name="l03513"></a>03513                 {
+<a name="l03514"></a>03514                     minval = box_buffer -> data[i] ;
+<a name="l03515"></a>03515                 }
+<a name="l03516"></a>03516                 <span class="keywordflow">if</span> ( box_buffer -> data[i] > maxval )
+<a name="l03517"></a>03517                 {
+<a name="l03518"></a>03518                     maxval = box_buffer -> data[i] ;
+<a name="l03519"></a>03519                 }
+<a name="l03520"></a>03520             }
+<a name="l03521"></a>03521             fitpar[2] = minval ;
+<a name="l03522"></a>03522             fitpar[3] = maxval ;
+<a name="l03523"></a>03523             <span class="comment">/*----------------------------------------------------------------</span>
+<a name="l03524"></a>03524 <span class="comment">             * if we have too few left background values (at the image edges)</span>
+<a name="l03525"></a>03525 <span class="comment">             * the left margin of the buffer to fit is filled with the minimal</span>
+<a name="l03526"></a>03526 <span class="comment">             * values in order to get a good fit</span>
+<a name="l03527"></a>03527 <span class="comment">             */</span>
+<a name="l03528"></a>03528 
+<a name="l03529"></a>03529             <span class="keywordflow">if</span> ( init1 == 1 )
+<a name="l03530"></a>03530             {
+<a name="l03531"></a>03531                 n_buf = box_buffer->n_elements + box_length/2 ;
+<a name="l03532"></a>03532                 in_buffer = sinfo_new_vector( n_buf ) ;
+<a name="l03533"></a>03533                 <span class="keywordflow">for</span> ( i = 0 ; i < box_length/2 ; i++ )
+<a name="l03534"></a>03534                 {
+<a name="l03535"></a>03535                     in_buffer -> data[i] = minval ;
+<a name="l03536"></a>03536                 }
+<a name="l03537"></a>03537                 shift = 0 ;
+<a name="l03538"></a>03538                 <span class="keywordflow">for</span> ( i = box_length/2 ; i < n_buf ; i++ )
+<a name="l03539"></a>03539                 {
+<a name="l03540"></a>03540                     in_buffer -> data[i] = box_buffer -> data[shift] ;
+<a name="l03541"></a>03541                     shift++ ;
+<a name="l03542"></a>03542                 }
+<a name="l03543"></a>03543                 sinfo_new_destroy_vector ( box_buffer ) ;
+<a name="l03544"></a>03544                 box_buffer = sinfo_new_vector ( n_buf ) ;
+<a name="l03545"></a>03545                 <span class="keywordflow">for</span> ( i = 0 ; i < n_buf ; i++ )
+<a name="l03546"></a>03546                 {
+<a name="l03547"></a>03547                     box_buffer -> data[i] = in_buffer -> data[i] ;
+<a name="l03548"></a>03548                 }
+<a name="l03549"></a>03549                 sinfo_new_destroy_vector ( in_buffer ) ;
+<a name="l03550"></a>03550             }
+<a name="l03551"></a>03551             <span class="comment">/* determine the initial positions from the found values */</span>
+<a name="l03552"></a>03552             fitpar[0] = (float)box_buffer->n_elements/2. - 1. ;
+<a name="l03553"></a>03553             fitpar[1] = (<span class="keywordtype">float</span>)box_buffer->n_elements/2. + 1. ;
+<a name="l03554"></a>03554 
+<a name="l03555"></a>03555             <span class="keywordflow">for</span> ( i = 0 ; i < NPAR ; i++ )
+<a name="l03556"></a>03556             {
+<a name="l03557"></a>03557                 mpar[i] = 1 ;
+<a name="l03558"></a>03558                 dervpar[i] = 0. ;
+<a name="l03559"></a>03559             }
+<a name="l03560"></a>03560 
+<a name="l03561"></a>03561             xdim     = XDIMA ;
+<a name="l03562"></a>03562             ndat     = box_buffer->n_elements ;
+<a name="l03563"></a>03563             numpar   = NPAR ;
+<a name="l03564"></a>03564             tol      = TOLA ;
+<a name="l03565"></a>03565             lab      = LABA ;
+<a name="l03566"></a>03566             its      = ITSA ;
+<a name="l03567"></a>03567 
+<a name="l03568"></a>03568             <span class="comment">/* finally, do the least squares fit over the buffer data */</span>
+<a name="l03569"></a>03569             <span class="keywordflow">if</span> ( 0 > ( iters = sinfo_new_lsqfit_edge( xdat, &xdim, 
+<a name="l03570"></a>03570                                                       box_buffer -> data, 
+<a name="l03571"></a>03571                                                       wdat, &ndat, fitpar,
+<a name="l03572"></a>03572                                                       dervpar, mpar, &numpar, 
+<a name="l03573"></a>03573                                                       &tol, &its, &lab )) )
+<a name="l03574"></a>03574             {
+<a name="l03575"></a>03575                 <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a> (<span class="stringliteral">" least squares fit failed, error "</span>
+<a name="l03576"></a>03576                                    <span class="stringliteral">"no.: %d in slitlet: %d\n"</span>, iters, j) ;
+<a name="l03577"></a>03577                 sinfo_new_destroy_vector(box_buffer) ;
+<a name="l03578"></a>03578                 cpl_free( xdat ) ;
+<a name="l03579"></a>03579                 cpl_free( wdat ) ;
+<a name="l03580"></a>03580                 cpl_free( mpar ) ;
+<a name="l03581"></a>03581                 continue ;
+<a name="l03582"></a>03582             }
+<a name="l03583"></a>03583             <span class="keywordflow">if</span> ( fitpar[1] <= fitpar[0] )
+<a name="l03584"></a>03584             {
+<a name="l03585"></a>03585                 <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a> (<span class="stringliteral">"fit failed due to negative slope of "</span>
+<a name="l03586"></a>03586                                    <span class="stringliteral">"sinfo_new_edge function in slitlet: %d"</span>,j);
+<a name="l03587"></a>03587                 sinfo_new_destroy_vector(box_buffer) ;
+<a name="l03588"></a>03588                 cpl_free( xdat ) ;
+<a name="l03589"></a>03589                 cpl_free( wdat ) ;
+<a name="l03590"></a>03590                 cpl_free( mpar ) ;
+<a name="l03591"></a>03591                 continue ;
+<a name="l03592"></a>03592             }
+<a name="l03593"></a>03593 
+<a name="l03594"></a>03594             pos = (fitpar[0] + fitpar[1])/2. ;
+<a name="l03595"></a>03595             <span class="keywordflow">if</span> ( init1 == 1 )
+<a name="l03596"></a>03596             {
+<a name="l03597"></a>03597                 pos -= (float)box_length/2. ;
+<a name="l03598"></a>03598             }
+<a name="l03599"></a>03599 
+<a name="l03600"></a>03600             <span class="comment">/*-------------------------------------------------------------</span>
+<a name="l03601"></a>03601 <span class="comment">             * now compute the real slit positions using the guess positions</span>
+<a name="l03602"></a>03602 <span class="comment">             * if the fit did not work the guess positions are taken</span>
+<a name="l03603"></a>03603 <span class="comment">             * the same is done if the deviations are too big.</span>
+<a name="l03604"></a>03604 <span class="comment">             */</span>
+<a name="l03605"></a>03605             <span class="keywordflow">if</span> ( pos != 0. )
+<a name="l03606"></a>03606             {
+<a name="l03607"></a>03607                 <span class="keywordflow">if</span> ( left_right == 0 )
+<a name="l03608"></a>03608                 {
+<a name="l03609"></a>03609                     new_pos = (float)col_first + pos ;
+<a name="l03610"></a>03610                 }
+<a name="l03611"></a>03611                 <span class="keywordflow">else</span>
+<a name="l03612"></a>03612                 {
+<a name="l03613"></a>03613                     new_pos = (float)col_last-1 - pos ;
+<a name="l03614"></a>03614                 }
+<a name="l03615"></a>03615                 <span class="keywordflow">if</span> ( fabs(new_pos - sinfo_slit_pos[j][left_right]) < diff_tol )
+<a name="l03616"></a>03616                 {
+<a name="l03617"></a>03617                     sinfo_slit_pos[j][left_right] = new_pos ;
+<a name="l03618"></a>03618                 }
+<a name="l03619"></a>03619                 <span class="keywordflow">else</span>
+<a name="l03620"></a>03620                 {
+<a name="l03621"></a>03621                     <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a> (<span class="stringliteral">" deviation bigger than tolerance,"</span>
+<a name="l03622"></a>03622                                        <span class="stringliteral">" take the estimated slitlet positiona"</span>
+<a name="l03623"></a>03623                                        <span class="stringliteral">" in slitlet: %d\n"</span>, j) ;
+<a name="l03624"></a>03624                 }
+<a name="l03625"></a>03625             }
+<a name="l03626"></a>03626 
+<a name="l03627"></a>03627             cpl_free( xdat ) ;
+<a name="l03628"></a>03628             cpl_free( wdat ) ;
+<a name="l03629"></a>03629             cpl_free( mpar ) ;
+<a name="l03630"></a>03630             sinfo_new_destroy_vector ( box_buffer ) ;
+<a name="l03631"></a>03631         }
+<a name="l03632"></a>03632     }
+<a name="l03633"></a>03633     cpl_free(position);
+<a name="l03634"></a>03634     <span class="keywordflow">return</span> 0 ;
+<a name="l03635"></a>03635 }
+<a name="l03636"></a>03636 
+<a name="l03637"></a>03637 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__absolute_8h_source.html b/html/sinfo__absolute_8h_source.html
new file mode 100644
index 0000000..bab544c
--- /dev/null
+++ b/html/sinfo__absolute_8h_source.html
@@ -0,0 +1,155 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_absolute.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_absolute.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*****************************************************************************</span>
+<a name="l00020"></a>00020 <span class="comment">* E.S.O. - VLT project</span>
+<a name="l00021"></a>00021 <span class="comment">*</span>
+<a name="l00022"></a>00022 <span class="comment">* "@(#) $Id: sinfo_absolute.h,v 1.3 2007/08/20 10:01:05 amodigli Exp $"</span>
+<a name="l00023"></a>00023 <span class="comment">*</span>
+<a name="l00024"></a>00024 <span class="comment">* who       when      what</span>
+<a name="l00025"></a>00025 <span class="comment">* --------  --------  ----------------------------------------------</span>
+<a name="l00026"></a>00026 <span class="comment">* schreib  14/11/00  created</span>
+<a name="l00027"></a>00027 <span class="comment">*/</span>
+<a name="l00028"></a>00028 <span class="preprocessor">#ifndef SINFO_ABSOLUTE_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_ABSOLUTE_H</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span>
+<a name="l00034"></a>00034 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="comment">/************************************************************************</span>
+<a name="l00038"></a>00038 <span class="comment"> * absolute.h</span>
+<a name="l00039"></a>00039 <span class="comment"> * routines to determine the absolute positions of the slitlets out of </span>
+<a name="l00040"></a>00040 <span class="comment"> * an emission line frame</span>
+<a name="l00041"></a>00041 <span class="comment"> *----------------------------------------------------------------------</span>
+<a name="l00042"></a>00042 <span class="comment"> */</span>
+<a name="l00043"></a>00043 
+<a name="l00044"></a>00044 <span class="comment">/*</span>
+<a name="l00045"></a>00045 <span class="comment"> * header files</span>
+<a name="l00046"></a>00046 <span class="comment"> */</span>
+<a name="l00047"></a>00047 
+<a name="l00048"></a>00048 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00049"></a>00049 <span class="preprocessor">#include "sinfo_spectrum_ops.h"</span>
+<a name="l00050"></a>00050 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00051"></a>00051 <span class="preprocessor">#include "sinfo_recipes.h"</span>
+<a name="l00052"></a>00052 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00053"></a>00053 <span class="comment"> *                        Function ANSI C prototypes</span>
+<a name="l00054"></a>00054 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00055"></a>00055 
+<a name="l00074"></a>00074 <span class="keywordtype">float</span> 
+<a name="l00075"></a>00075 sinfo_new_edge(<span class="keywordtype">float</span> * xdat, <span class="keywordtype">float</span> * parlist<span class="comment">/*, int * npar, int * ndat */</span>) ;
+<a name="l00076"></a>00076 
+<a name="l00090"></a>00090 <span class="keywordtype">float</span> 
+<a name="l00091"></a>00091 <a class="code" href="group__sinfo__boltzmann.html#ga858ad4d37da835f1ff4740d0f23920c1" title="calculates the value of a Boltzmann function with parameters parlist at the position...">sinfo_new_boltz</a> ( <span class="keywordtype">float</span> * xdat, <span class="keywordtype">float</span> * parlist ) ;
+<a name="l00092"></a>00092 
+<a name="l00111"></a>00111 <span class="keywordtype">void</span> 
+<a name="l00112"></a>00112 sinfo_new_edge_deriv(<span class="keywordtype">float</span> * xdat, 
+<a name="l00113"></a>00113                      <span class="keywordtype">float</span> * parlist, <span class="keywordtype">float</span> * dervs<span class="comment">/*, int * npar */</span>) ;
+<a name="l00114"></a>00114 
+<a name="l00132"></a>00132 <span class="keywordtype">void</span> 
+<a name="l00133"></a>00133 <a class="code" href="group__sinfo__boltzmann.html#ga72b3c6f0c971fb402bd68c8d0fcf5e30" title="calculates the partial derivatives for a Boltzmann function with parameters parlist...">sinfo_new_boltz_deriv</a>( <span class="keywordtype">float</span> * xdat, <span class="keywordtype">float</span> * parlist, <span class="keywordtype">float</span> * dervs ) ;
+<a name="l00134"></a>00134 
+<a name="l00182"></a>00182 <span class="keywordtype">int</span> <a class="code" href="group__sinfo__boltzmann.html#ga7e03e34851f7c367ab3827c58e8c81c5" title="makes a least-squares fit of a function to a set of data points.">sinfo_new_lsqfit</a> ( <span class="keywordtype">float</span> * xdat,
+<a name="l00183"></a>00183              <span class="keywordtype">int</span>   * xdim,
+<a name="l00184"></a>00184              <span class="keywordtype">float</span> * ydat,
+<a name="l00185"></a>00185              <span class="keywordtype">float</span> * wdat,
+<a name="l00186"></a>00186              <span class="keywordtype">int</span>   * ndat,
+<a name="l00187"></a>00187              <span class="keywordtype">float</span> * fpar,
+<a name="l00188"></a>00188              <span class="keywordtype">float</span> * epar,
+<a name="l00189"></a>00189              <span class="keywordtype">int</span>   * mpar,
+<a name="l00190"></a>00190              <span class="keywordtype">int</span>   * npar,
+<a name="l00191"></a>00191              <span class="keywordtype">float</span> * tol ,
+<a name="l00192"></a>00192              <span class="keywordtype">int</span>   * its ,
+<a name="l00193"></a>00193              <span class="keywordtype">float</span> * lab  ) ;
+<a name="l00194"></a>00194 
+<a name="l00240"></a>00240 <span class="keywordtype">int</span> 
+<a name="l00241"></a>00241 sinfo_new_lsqfit_edge ( <span class="keywordtype">float</span> * xdat,
+<a name="l00242"></a>00242                   <span class="keywordtype">int</span>   * xdim,
+<a name="l00243"></a>00243                   <span class="keywordtype">float</span> * ydat,
+<a name="l00244"></a>00244                   <span class="keywordtype">float</span> * wdat,
+<a name="l00245"></a>00245                   <span class="keywordtype">int</span>   * ndat,
+<a name="l00246"></a>00246                   <span class="keywordtype">float</span> * fpar,
+<a name="l00247"></a>00247                   <span class="keywordtype">float</span> * epar,
+<a name="l00248"></a>00248                   <span class="keywordtype">int</span>   * mpar,
+<a name="l00249"></a>00249                   <span class="keywordtype">int</span>   * npar,
+<a name="l00250"></a>00250                   <span class="keywordtype">float</span> * tol ,
+<a name="l00251"></a>00251                   <span class="keywordtype">int</span>   * its ,
+<a name="l00252"></a>00252                   <span class="keywordtype">float</span> * lab  ) ;
+<a name="l00253"></a>00253 
+<a name="l00288"></a>00288 <span class="keywordtype">int</span> 
+<a name="l00289"></a>00289 sinfo_new_fit_slits_edge( cpl_image   * lineImage,
+<a name="l00290"></a>00290                   FitParams ** par,
+<a name="l00291"></a>00291                   <span class="keywordtype">float</span>     ** sinfo_slit_pos,
+<a name="l00292"></a>00292                   <span class="keywordtype">int</span>          box_length,
+<a name="l00293"></a>00293                   <span class="keywordtype">float</span>        y_box,
+<a name="l00294"></a>00294                   <span class="keywordtype">float</span>        diff_tol ) ;
+<a name="l00295"></a>00295 
+<a name="l00329"></a>00329 <span class="keywordtype">int</span> 
+<a name="l00330"></a>00330 <a class="code" href="group__sinfo__boltzmann.html#gab3549f7bb876fb4091ba3c0bd64d267d" title="fits the beginning and end position of the slitlets by using non-linear least square...">sinfo_new_fit_slits_boltz</a>( cpl_image   * lineImage,
+<a name="l00331"></a>00331                    FitParams ** par,
+<a name="l00332"></a>00332                    <span class="keywordtype">float</span>     ** sinfo_slit_pos,
+<a name="l00333"></a>00333                    <span class="keywordtype">int</span>          box_length,
+<a name="l00334"></a>00334                    <span class="keywordtype">float</span>        y_box,
+<a name="l00335"></a>00335                    <span class="keywordtype">float</span>        diff_tol ) ;
+<a name="l00336"></a>00336 
+<a name="l00358"></a>00358 <span class="keywordtype">int</span> 
+<a name="l00359"></a>00359 <a class="code" href="group__sinfo__boltzmann.html#gafe44b4032a5b85ff4b88bf7518793b21" title="fits the beginning and end position of the slitlets by using non-linear least square...">sinfo_new_fit_slits_boltz_single_line</a> ( cpl_image   * lineImage,
+<a name="l00360"></a>00360                   <span class="keywordtype">float</span>     ** sinfo_slit_pos,
+<a name="l00361"></a>00361                   <span class="keywordtype">int</span>          box_length,
+<a name="l00362"></a>00362                   <span class="keywordtype">float</span>        y_box,
+<a name="l00363"></a>00363                   <span class="keywordtype">int</span>          low_pos,
+<a name="l00364"></a>00364                   <span class="keywordtype">int</span>          high_pos ) ;
+<a name="l00365"></a>00365 
+<a name="l00366"></a>00366 
+<a name="l00388"></a>00388 <span class="keywordtype">int</span> 
+<a name="l00389"></a>00389 <a class="code" href="group__sinfo__boltzmann.html#ga1851d695a240ae0d23d20657f02867bb" title="its the beginning and end position of the slitlets by using non-linear least square...">sinfo_new_fit_slits_boltz_with_estimate</a> ( cpl_image   * lineImage,
+<a name="l00390"></a>00390                                 <span class="keywordtype">float</span>     ** sinfo_slit_pos,
+<a name="l00391"></a>00391                                 <span class="keywordtype">int</span>          box_length,
+<a name="l00392"></a>00392                                 <span class="keywordtype">float</span>        y_box,
+<a name="l00393"></a>00393                                 <span class="keywordtype">float</span>        diff_tol,
+<a name="l00394"></a>00394                                 <span class="keywordtype">int</span>          low_pos,
+<a name="l00395"></a>00395                                 <span class="keywordtype">int</span>          high_pos ) ;
+<a name="l00396"></a>00396 
+<a name="l00397"></a>00397 
+<a name="l00420"></a>00420 <span class="keywordtype">int</span> 
+<a name="l00421"></a>00421 sinfo_new_fit_slits_edge_with_estimate ( cpl_image   * lineImage,
+<a name="l00422"></a>00422                                 <span class="keywordtype">float</span>    ** sinfo_slit_pos,
+<a name="l00423"></a>00423                                 <span class="keywordtype">int</span>         box_length,
+<a name="l00424"></a>00424                                 <span class="keywordtype">float</span>       y_box,
+<a name="l00425"></a>00425                                 <span class="keywordtype">float</span>       diff_tol,
+<a name="l00426"></a>00426                                 <span class="keywordtype">int</span>         low_pos,
+<a name="l00427"></a>00427                                 <span class="keywordtype">int</span>         high_pos ) ;
+<a name="l00428"></a>00428 
+<a name="l00429"></a>00429 
+<a name="l00430"></a>00430 
+<a name="l00431"></a>00431 <span class="preprocessor">#endif </span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__atmo__disp_8c_source.html b/html/sinfo__atmo__disp_8c_source.html
new file mode 100644
index 0000000..23a2e80
--- /dev/null
+++ b/html/sinfo__atmo__disp_8c_source.html
@@ -0,0 +1,344 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_atmo_disp.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_atmo_disp.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004-2009 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2011/12/08 16:15:40 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.7 $</span>
+<a name="l00024"></a>00024 <span class="comment"> */</span>
+<a name="l00025"></a>00025 
+<a name="l00026"></a>00026 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00027"></a>00027 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>          <span class="comment">/* allows the program compilation */</span>
+<a name="l00028"></a>00028 <span class="preprocessor">#endif</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00031"></a>00031 <span class="preprocessor">#include <string.h></span>
+<a name="l00032"></a>00032 <span class="preprocessor">#include <math.h></span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include <sinfo_msg.h></span>
+<a name="l00034"></a>00034 <span class="preprocessor">#include <sinfo_utils_wrappers.h></span>
+<a name="l00035"></a>00035 <span class="preprocessor">#include "sinfo_atmo_disp.h"</span>
+<a name="l00036"></a>00036 <span class="preprocessor">#include "sinfo_resampling.h"</span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include "sinfo_image_ops.h"</span>
+<a name="l00038"></a>00038 
+<a name="l00039"></a>00039 <span class="keyword">struct </span>_disp_data
+<a name="l00040"></a>00040 {
+<a name="l00041"></a>00041     <span class="keywordtype">double</span> p1;
+<a name="l00042"></a>00042     <span class="keywordtype">double</span> d1;
+<a name="l00043"></a>00043     <span class="keywordtype">double</span> d2;
+<a name="l00044"></a>00044     <span class="keywordtype">double</span> N0;
+<a name="l00045"></a>00045     <span class="keywordtype">double</span> predelta;
+<a name="l00046"></a>00046     <span class="keywordtype">double</span> parallactic_shiftX;
+<a name="l00047"></a>00047     <span class="keywordtype">double</span> parallactic_shiftY;
+<a name="l00048"></a>00048 };
+<a name="l00049"></a>00049 <span class="keyword">typedef</span> <span class="keyword">struct </span>_disp_data disp_data;
+<a name="l00050"></a>00050 <span class="keyword">static</span> <span class="keywordtype">double</span> sinfo_disp_calc_N(<span class="keyword">const</span> disp_data* pdata, <span class="keywordtype">double</span> lambda);
+<a name="l00051"></a>00051 <span class="keyword">static</span> <span class="keywordtype">void</span> 
+<a name="l00052"></a>00052 sinfo_disp_prepare_data(disp_data* pdata,
+<a name="l00053"></a>00053             <span class="keywordtype">double</span> lambda0,
+<a name="l00054"></a>00054             <span class="keywordtype">double</span> Tc,
+<a name="l00055"></a>00055             <span class="keywordtype">double</span> rh,
+<a name="l00056"></a>00056             <span class="keywordtype">double</span> airm,
+<a name="l00057"></a>00057             <span class="keywordtype">double</span> p,
+<a name="l00058"></a>00058             <span class="keywordtype">double</span> parallactic,
+<a name="l00059"></a>00059             <span class="keywordtype">double</span> pixelscale );
+<a name="l00060"></a>00060 
+<a name="l00061"></a>00061 <span class="keyword">static</span> <span class="keywordtype">void</span> 
+<a name="l00062"></a>00062 sinfo_disp_calc(disp_data* pdata, <span class="keywordtype">double</span> lambda, <span class="keywordtype">double</span> *shiftx, <span class="keywordtype">double</span> *shiftY);
+<a name="l00063"></a>00063 <span class="keyword">static</span> <span class="keywordtype">void</span> 
+<a name="l00064"></a>00064 sinfo_atmo_rotate_point(<span class="keywordtype">double</span>* x_value, <span class="keywordtype">double</span> * y_value, <span class="keywordtype">double</span> rot_angle);
+<a name="l00065"></a>00065 <span class="comment">/*------------------------------------------------------------------------------------*/</span>
+<a name="l00066"></a>00066 
+<a name="l00067"></a>00067 <span class="keyword">static</span> <span class="keywordtype">double</span> 
+<a name="l00068"></a>00068 sinfo_disp_calc_N(<span class="keyword">const</span> disp_data* pdata, <span class="keywordtype">double</span> lambda)
+<a name="l00069"></a>00069 {
+<a name="l00070"></a>00070     <span class="keywordtype">double</span> s = 1.0 /lambda;
+<a name="l00071"></a>00071     <span class="keywordtype">double</span> s2 = s  * s;
+<a name="l00072"></a>00072     <span class="keywordtype">double</span> s3 = s2 * s;
+<a name="l00073"></a>00073     <span class="keywordtype">double</span> s4 = s3 * s;
+<a name="l00074"></a>00074     <span class="keywordtype">double</span> s5 = s4 * s;
+<a name="l00075"></a>00075     <span class="keywordtype">double</span> s6 = s5 * s;
+<a name="l00076"></a>00076 
+<a name="l00077"></a>00077     <span class="keywordtype">double</span> a = 83939.7/(130   - s2);
+<a name="l00078"></a>00078     <span class="keywordtype">double</span> b =   4547.3/(38.99 - s2);
+<a name="l00079"></a>00079     <span class="keywordtype">double</span> c = 6487.31 + 58.058*s2 - 0.71150*s4 + 0.08851*s6;
+<a name="l00080"></a>00080     <span class="keywordtype">double</span> N =  1e-8 * ( ((2371.34 + a + b) * pdata->d1)  +  ( c * pdata->d2));
+<a name="l00081"></a>00081     <span class="keywordflow">return</span> N;
+<a name="l00082"></a>00082 
+<a name="l00083"></a>00083 }
+<a name="l00084"></a>00084 <span class="keyword">static</span> <span class="keywordtype">void</span> 
+<a name="l00085"></a>00085 sinfo_disp_prepare_data(disp_data* pdata,
+<a name="l00086"></a>00086         <span class="keywordtype">double</span> lambda0,
+<a name="l00087"></a>00087         <span class="keywordtype">double</span> Tc,
+<a name="l00088"></a>00088         <span class="keywordtype">double</span> rh,
+<a name="l00089"></a>00089         <span class="keywordtype">double</span> airm,
+<a name="l00090"></a>00090         <span class="keywordtype">double</span> p,
+<a name="l00091"></a>00091         <span class="keywordtype">double</span> parallactic,
+<a name="l00092"></a>00092         <span class="keywordtype">double</span> pixelscale )
+<a name="l00093"></a>00093 {
+<a name="l00094"></a>00094     <span class="keywordtype">double</span> ps,p2,p1,T,T2,T3;
+<a name="l00095"></a>00095     <span class="keywordtype">double</span> zenith;
+<a name="l00096"></a>00096 <span class="comment">//    const double PI_NUMBer = 3.1415926535;</span>
+<a name="l00097"></a>00097 
+<a name="l00098"></a>00098     T  = Tc + 273.15;T2 = T  * T; T3 = T2 * T;
+<a name="l00099"></a>00099     ps = -10474 + (116.43 * T) - (0.43284 *T2) + (0.00053840 * T3);
+<a name="l00100"></a>00100     p2 = (rh/100)*ps;
+<a name="l00101"></a>00101     p1 = p - p2;
+<a name="l00102"></a>00102     pdata->d1 = (p1/T)*(1+p1*( (57.90e-8) - ((9.3250e-4)/T) + (0.25844/T2)));
+<a name="l00103"></a>00103     pdata->d2 = (p2/T)*(1+p2*(1+3.7e-4*p2)*( (-2.37321e-3) + (2.23366/T) - (710.792/T2) + ((7.75141e-4)/T3) )) ;
+<a name="l00104"></a>00104     pdata->N0 = sinfo_disp_calc_N(pdata, lambda0);
+<a name="l00105"></a>00105     zenith     = acos(1/airm);
+<a name="l00106"></a>00106     pdata->predelta      = ((tan(zenith)) / (PI_NUMB/180)) * 3600;
+<a name="l00107"></a>00107     pdata->parallactic_shiftX = sin ( (parallactic)* (PI_NUMB/180) ) / pixelscale;
+<a name="l00108"></a>00108     pdata->parallactic_shiftY = cos ( (parallactic)* (PI_NUMB/180) ) / pixelscale;
+<a name="l00109"></a>00109     <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"atm disp N0[%f] d1[%f] d2[%f] pshiftX[%f] pshiftY[%f]"</span>,
+<a name="l00110"></a>00110             pdata->N0,pdata->d1, pdata->d2,  pdata->parallactic_shiftX ,
+<a name="l00111"></a>00111             pdata->parallactic_shiftY);
+<a name="l00112"></a>00112 }
+<a name="l00113"></a>00113 <span class="keyword">static</span> <span class="keywordtype">void</span> 
+<a name="l00114"></a>00114 sinfo_disp_calc(disp_data* pdata, <span class="keywordtype">double</span> lambda, <span class="keywordtype">double</span> *shiftx, <span class="keywordtype">double</span> *shifty)
+<a name="l00115"></a>00115 {
+<a name="l00116"></a>00116     <span class="keywordtype">double</span> n = sinfo_disp_calc_N(pdata, lambda);
+<a name="l00117"></a>00117     <span class="keywordtype">double</span> delta = pdata->predelta * (n - pdata->N0);
+<a name="l00118"></a>00118     *shiftx = -delta * pdata->parallactic_shiftX;
+<a name="l00119"></a>00119     *shifty = delta * pdata->parallactic_shiftY ;
+<a name="l00120"></a>00120 }
+<a name="l00121"></a>00121 
+<a name="l00122"></a>00122 cpl_error_code 
+<a name="l00123"></a>00123 sinfo_atm_dispersion_cube(cpl_imagelist* pCube,
+<a name="l00124"></a>00124         <span class="keywordtype">int</span> centpix, <span class="comment">// central plane in the cube CRPIX3</span>
+<a name="l00125"></a>00125         <span class="keywordtype">double</span> centlambda, <span class="comment">// wavelength of the central plane CRVAL3</span>
+<a name="l00126"></a>00126         <span class="keywordtype">double</span> Tc, <span class="comment">// temperature in Celsius TEL.AMBI.TEMP</span>
+<a name="l00127"></a>00127         <span class="keywordtype">double</span> Rh, <span class="comment">// relative humidity in % TEL.AMBI.RHUM</span>
+<a name="l00128"></a>00128         <span class="keywordtype">double</span> airm, <span class="comment">// airmass for the moment of observation TEL.AMBI.PRES</span>
+<a name="l00129"></a>00129         <span class="keywordtype">double</span> p, <span class="comment">// atmospheric pressure TEL.AMBI.PRES</span>
+<a name="l00130"></a>00130         <span class="keywordtype">double</span> parallactic, <span class="comment">// TEL.PARANG</span>
+<a name="l00131"></a>00131         <span class="keywordtype">double</span> pixelscale, <span class="comment">// could be for SINFONI 0.025, 0.100, 0.250</span>
+<a name="l00132"></a>00132         <span class="keywordtype">double</span> pixelsz <span class="comment">// microns per pixel CDELT3</span>
+<a name="l00133"></a>00133         )
+<a name="l00134"></a>00134 {
+<a name="l00135"></a>00135     cpl_error_code err = CPL_ERROR_NONE;
+<a name="l00136"></a>00136     <span class="keywordtype">int</span> cubesize = cpl_imagelist_get_size(pCube);
+<a name="l00137"></a>00137     <span class="keywordtype">double</span> * kernel = sinfo_generate_interpolation_kernel(<span class="stringliteral">"default"</span>);
+<a name="l00138"></a>00138     disp_data ddata;
+<a name="l00139"></a>00139     <span class="keywordtype">int</span> i = 0;
+<a name="l00140"></a>00140 
+<a name="l00141"></a>00141     sinfo_disp_prepare_data(&ddata, centlambda, Tc, Rh, airm, p, parallactic, pixelscale);
+<a name="l00142"></a>00142 
+<a name="l00143"></a>00143     <span class="keywordflow">for</span> (i = 0; i < cubesize; i++)
+<a name="l00144"></a>00144     {
+<a name="l00145"></a>00145         <span class="keywordtype">double</span> shiftx = 0;
+<a name="l00146"></a>00146         <span class="keywordtype">double</span> shifty = 0;
+<a name="l00147"></a>00147 
+<a name="l00148"></a>00148         cpl_image* pnewImage = 0;
+<a name="l00149"></a>00149         <span class="comment">// 1. get an image</span>
+<a name="l00150"></a>00150         cpl_image* plane = cpl_imagelist_get(pCube, i);
+<a name="l00151"></a>00151 
+<a name="l00152"></a>00152         <span class="comment">// 2. calculate dispersion and shift</span>
+<a name="l00153"></a>00153         <span class="keywordtype">double</span> lambda = centlambda - (centpix - i) * pixelsz;
+<a name="l00154"></a>00154         sinfo_disp_calc(&ddata, lambda, &shiftx, &shifty);
+<a name="l00155"></a>00155         <span class="comment">// 3. aplly shift</span>
+<a name="l00156"></a>00156 <span class="comment">//      int szx = cpl_image_get_size_x(plane);</span>
+<a name="l00157"></a>00157         <span class="comment">//int szy = cpl_image_get_size_y(plane);</span>
+<a name="l00158"></a>00158         <span class="comment">//if (i % 10 == 0)</span>
+<a name="l00159"></a>00159             <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">" shift image #%d, dx[%f] dy[%f]"</span>, i, shiftx, shifty);
+<a name="l00160"></a>00160         pnewImage = sinfo_new_shift_image(
+<a name="l00161"></a>00161             plane,
+<a name="l00162"></a>00162             shiftx,
+<a name="l00163"></a>00163             shifty,
+<a name="l00164"></a>00164             kernel);
+<a name="l00165"></a>00165         err = cpl_imagelist_set(pCube, pnewImage, i);
+<a name="l00166"></a>00166         <span class="keywordflow">if</span> (err != CPL_ERROR_NONE)
+<a name="l00167"></a>00167             <span class="keywordflow">break</span>;
+<a name="l00168"></a>00168     }
+<a name="l00169"></a>00169     cpl_free(kernel);
+<a name="l00170"></a>00170     <span class="keywordflow">return</span> err;
+<a name="l00171"></a>00171 
+<a name="l00172"></a>00172 }
+<a name="l00173"></a>00173 
+<a name="l00174"></a>00174 
+<a name="l00175"></a>00175 <span class="comment">/*----------------------------------------------------</span>
+<a name="l00176"></a>00176 <span class="comment"> * Atmospheric correction using polynomial fit</span>
+<a name="l00177"></a>00177 <span class="comment"> *----------------------------------------------------*/</span>
+<a name="l00178"></a>00178 cpl_polynomial* 
+<a name="l00179"></a>00179 sinfo_atmo_load_polynom(<span class="keyword">const</span> <span class="keywordtype">char</span>* filename)
+<a name="l00180"></a>00180 {
+<a name="l00181"></a>00181     <span class="keyword">const</span> <span class="keywordtype">char</span>* COL_NAME_TEMPLATE = <span class="stringliteral">"col_%d"</span>;
+<a name="l00182"></a>00182     <span class="keyword">const</span> <span class="keywordtype">char</span>* COL_NAME_VALUE = <span class="stringliteral">"value"</span>;
+<a name="l00183"></a>00183     cpl_polynomial* poly = NULL;
+<a name="l00184"></a>00184     cpl_table* ptable = NULL;
+<a name="l00185"></a>00185 
+<a name="l00186"></a>00186     ptable = cpl_table_load(filename, 1, 0);
+<a name="l00187"></a>00187     <span class="keywordflow">if</span> (ptable)
+<a name="l00188"></a>00188     {
+<a name="l00189"></a>00189         <span class="keywordtype">int</span> dim = 0;
+<a name="l00190"></a>00190         <span class="keywordtype">int</span> nrows = 0;
+<a name="l00191"></a>00191         <span class="keywordtype">int</span> i = 0;
+<a name="l00192"></a>00192         cpl_size* expo = NULL;
+<a name="l00193"></a>00193 
+<a name="l00194"></a>00194         dim = cpl_table_get_ncol(ptable) - 1;
+<a name="l00195"></a>00195         poly = cpl_polynomial_new(dim );
+<a name="l00196"></a>00196         nrows = cpl_table_get_nrow(ptable);
+<a name="l00197"></a>00197         expo = cpl_malloc(dim * <span class="keyword">sizeof</span>(expo[0]));
+<a name="l00198"></a>00198         memset(&expo[0], 0, dim * <span class="keyword">sizeof</span>(expo[0]));
+<a name="l00199"></a>00199         <span class="keywordflow">for</span> (i = 0; i < nrows; i++)
+<a name="l00200"></a>00200         {
+<a name="l00201"></a>00201             <span class="keywordtype">int</span> j = 0;
+<a name="l00202"></a>00202             <span class="keywordtype">int</span> inull = 0;
+<a name="l00203"></a>00203             <span class="keywordtype">double</span> value = 0;
+<a name="l00204"></a>00204             <span class="keywordflow">for</span> (j = 0; j < dim; j++)
+<a name="l00205"></a>00205             {
+<a name="l00206"></a>00206                 <span class="keywordtype">char</span> col_name[255];
+<a name="l00207"></a>00207                 sprintf(col_name, COL_NAME_TEMPLATE, j);
+<a name="l00208"></a>00208                 expo[j] = cpl_table_get_int(ptable, col_name, i, &inull);
+<a name="l00209"></a>00209             }
+<a name="l00210"></a>00210             value = cpl_table_get(ptable, COL_NAME_VALUE, i, &inull);
+<a name="l00211"></a>00211             cpl_polynomial_set_coeff(poly, expo, value);
+<a name="l00212"></a>00212             <span class="keywordflow">if</span> (cpl_error_get_code() != CPL_ERROR_NONE)
+<a name="l00213"></a>00213             {
+<a name="l00214"></a>00214                 <span class="keywordflow">if</span> (poly)
+<a name="l00215"></a>00215                 {
+<a name="l00216"></a>00216                     sinfo_free_polynomial(&poly);
+<a name="l00217"></a>00217                 }
+<a name="l00218"></a>00218                 <span class="keywordflow">break</span>;
+<a name="l00219"></a>00219             }
+<a name="l00220"></a>00220         }
+<a name="l00221"></a>00221         cpl_free(expo);
+<a name="l00222"></a>00222     }
+<a name="l00223"></a>00223     sinfo_free_table(&ptable);
+<a name="l00224"></a>00224     <span class="keywordflow">return</span> poly;
+<a name="l00225"></a>00225 }
+<a name="l00226"></a>00226 
+<a name="l00227"></a>00227 <span class="keyword">static</span> <span class="keywordtype">void</span> 
+<a name="l00228"></a>00228 sinfo_atmo_rotate_point(<span class="keywordtype">double</span>* x_value, <span class="keywordtype">double</span> * y_value, <span class="keywordtype">double</span> rot_angle)
+<a name="l00229"></a>00229 {
+<a name="l00230"></a>00230     <span class="keywordtype">double</span> newx = *x_value * cos(rot_angle) - *y_value * sin(rot_angle);
+<a name="l00231"></a>00231     <span class="keywordtype">double</span> newy = *x_value * sin(rot_angle) + *y_value * cos(rot_angle);
+<a name="l00232"></a>00232     *x_value = newx;
+<a name="l00233"></a>00233     *y_value = newy;
+<a name="l00234"></a>00234 }
+<a name="l00235"></a>00235 
+<a name="l00236"></a>00236 cpl_imagelist* 
+<a name="l00237"></a>00237 sinfo_atmo_apply_cube_polynomial_shift(
+<a name="l00238"></a>00238         cpl_polynomial* poly,
+<a name="l00239"></a>00239         cpl_imagelist* pCube,
+<a name="l00240"></a>00240         <span class="keywordtype">double</span> lambda0,
+<a name="l00241"></a>00241         <span class="keywordtype">double</span> airmass,
+<a name="l00242"></a>00242         <span class="keywordtype">double</span> parallactic, <span class="comment">// should be in radian</span>
+<a name="l00243"></a>00243         <span class="keywordtype">double</span> pixelsz,
+<a name="l00244"></a>00244         <span class="keywordtype">int</span> centpix)
+<a name="l00245"></a>00245 {
+<a name="l00246"></a>00246     cpl_imagelist* retcube = NULL;
+<a name="l00247"></a>00247     cpl_error_code  err = CPL_ERROR_NONE;
+<a name="l00248"></a>00248     cpl_vector* vparams = NULL;
+<a name="l00249"></a>00249     <span class="keywordtype">double</span> * kernel = sinfo_generate_interpolation_kernel(<span class="stringliteral">"default"</span>);
+<a name="l00250"></a>00250     <span class="keywordtype">int</span> cubesize = 0;
+<a name="l00251"></a>00251     <span class="keywordtype">int</span> i = 0;
+<a name="l00252"></a>00252     <span class="comment">// the following two parameters are necessary for computing the shift</span>
+<a name="l00253"></a>00253     <span class="comment">// in case when polynom for H+K band is used for H or K</span>
+<a name="l00254"></a>00254     <span class="keywordtype">double</span> l0_shift_x = 0; <span class="comment">// shift for the central point by X</span>
+<a name="l00255"></a>00255     <span class="keywordtype">double</span> l0_shift_y = 0; <span class="comment">// shift for the central point by Y</span>
+<a name="l00256"></a>00256 
+<a name="l00257"></a>00257     vparams = cpl_vector_new(2);
+<a name="l00258"></a>00258     cpl_vector_set(vparams, 0, airmass);
+<a name="l00259"></a>00259     cpl_vector_set(vparams, 1, lambda0);
+<a name="l00260"></a>00260     err = cpl_error_get_code();
+<a name="l00261"></a>00261     <span class="keywordflow">if</span> (err == CPL_ERROR_NONE)
+<a name="l00262"></a>00262     {
+<a name="l00263"></a>00263         l0_shift_y = cpl_polynomial_eval(poly, vparams); <span class="comment">// North - South</span>
+<a name="l00264"></a>00264         l0_shift_x = 0; <span class="comment">// (EAST-WEST direction)</span>
+<a name="l00265"></a>00265         <span class="comment">// rotate the shift</span>
+<a name="l00266"></a>00266         sinfo_atmo_rotate_point(&l0_shift_x, &l0_shift_y, parallactic);
+<a name="l00267"></a>00267         cubesize = cpl_imagelist_get_size(pCube);
+<a name="l00268"></a>00268         err =  cpl_error_get_code();
+<a name="l00269"></a>00269     }
+<a name="l00270"></a>00270     <span class="keywordflow">if</span> (err == CPL_ERROR_NONE)
+<a name="l00271"></a>00271     {
+<a name="l00272"></a>00272         retcube = cpl_imagelist_new();
+<a name="l00273"></a>00273         <span class="keywordflow">for</span> (i = 0; i < cubesize; i++)
+<a name="l00274"></a>00274         {
+<a name="l00275"></a>00275             <span class="comment">// calculate the wavelength</span>
+<a name="l00276"></a>00276             <span class="keywordtype">double</span> lambda = lambda0 - (centpix - i) * pixelsz;
+<a name="l00277"></a>00277             <span class="keywordtype">double</span> shift_y = 0;
+<a name="l00278"></a>00278             <span class="keywordtype">double</span> shift_x = 0;
+<a name="l00279"></a>00279 
+<a name="l00280"></a>00280             cpl_vector_set(vparams, 1, lambda);
+<a name="l00281"></a>00281             <span class="comment">// calc the shift</span>
+<a name="l00282"></a>00282             shift_y = cpl_polynomial_eval(poly, vparams); <span class="comment">// North - South</span>
+<a name="l00283"></a>00283             err = cpl_error_get_code();
+<a name="l00284"></a>00284             <span class="keywordflow">if</span> (err == CPL_ERROR_NONE)
+<a name="l00285"></a>00285             {
+<a name="l00286"></a>00286                 <span class="keywordtype">double</span> res_shift_x = -(shift_x - l0_shift_x);
+<a name="l00287"></a>00287                 <span class="keywordtype">double</span> res_shift_y = -(shift_y - l0_shift_y);
+<a name="l00288"></a>00288                 cpl_image* plane = NULL;
+<a name="l00289"></a>00289                 cpl_image* pimresult = NULL;
+<a name="l00290"></a>00290                 <span class="comment">// rotate the shift</span>
+<a name="l00291"></a>00291                 sinfo_atmo_rotate_point(&res_shift_x, &res_shift_y, parallactic);
+<a name="l00292"></a>00292                 plane = cpl_imagelist_get(pCube, i);
+<a name="l00293"></a>00293                 pimresult = sinfo_new_shift_image(
+<a name="l00294"></a>00294                         plane,
+<a name="l00295"></a>00295                         res_shift_x, <span class="comment">// x shift</span>
+<a name="l00296"></a>00296                         res_shift_y, <span class="comment">// y shift</span>
+<a name="l00297"></a>00297                         kernel);
+<a name="l00298"></a>00298                 <span class="keywordflow">if</span> (err == CPL_ERROR_NONE)
+<a name="l00299"></a>00299                 {
+<a name="l00300"></a>00300                     err = cpl_imagelist_set(retcube, pimresult, i);
+<a name="l00301"></a>00301                 }
+<a name="l00302"></a>00302                 <span class="keywordflow">else</span>
+<a name="l00303"></a>00303                 {
+<a name="l00304"></a>00304                     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Error sinfo_new_shift_image, %s"</span>,
+<a name="l00305"></a>00305                                         cpl_error_get_where());
+<a name="l00306"></a>00306                 }
+<a name="l00307"></a>00307                 <span class="keywordflow">if</span> (err != CPL_ERROR_NONE)
+<a name="l00308"></a>00308                     <span class="keywordflow">break</span>;
+<a name="l00309"></a>00309             }
+<a name="l00310"></a>00310             <span class="keywordflow">else</span>
+<a name="l00311"></a>00311             {
+<a name="l00312"></a>00312                 <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Error polynomial_eval, %s"</span>,
+<a name="l00313"></a>00313                         cpl_error_get_where());
+<a name="l00314"></a>00314             }
+<a name="l00315"></a>00315             <span class="keywordflow">if</span> (err != CPL_ERROR_NONE)
+<a name="l00316"></a>00316                 <span class="keywordflow">break</span>;
+<a name="l00317"></a>00317         }
+<a name="l00318"></a>00318     }
+<a name="l00319"></a>00319     <span class="keywordflow">if</span> (err != CPL_ERROR_NONE)
+<a name="l00320"></a>00320     {
+<a name="l00321"></a>00321         sinfo_free_imagelist(&retcube);
+<a name="l00322"></a>00322         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Error during shift planes in the cube, %s"</span>,
+<a name="l00323"></a>00323                 cpl_error_get_where());
+<a name="l00324"></a>00324     }
+<a name="l00325"></a>00325     sinfoni_free_vector(&vparams);
+<a name="l00326"></a>00326     cpl_free(kernel);
+<a name="l00327"></a>00327     <span class="keywordflow">return</span> retcube;
+<a name="l00328"></a>00328 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__atmo__disp_8h_source.html b/html/sinfo__atmo__disp_8h_source.html
new file mode 100644
index 0000000..f7a6b7a
--- /dev/null
+++ b/html/sinfo__atmo__disp_8h_source.html
@@ -0,0 +1,86 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_atmo_disp.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_atmo_disp.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004-2009 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2010/02/08 07:15:18 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.4 $</span>
+<a name="l00024"></a>00024 <span class="comment"> */</span>
+<a name="l00025"></a>00025 
+<a name="l00026"></a>00026 <span class="preprocessor">#ifndef SINFO_ATMO_DISP_H_</span>
+<a name="l00027"></a>00027 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_ATMO_DISP_H_</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span>
+<a name="l00029"></a>00029 cpl_error_code 
+<a name="l00030"></a>00030 sinfo_atm_dispersion_cube(cpl_imagelist* pCube,
+<a name="l00031"></a>00031         <span class="keywordtype">int</span> centpix, <span class="comment">// central plane in the cube CRPIX3</span>
+<a name="l00032"></a>00032         <span class="keywordtype">double</span> centlambda, <span class="comment">// wavelength of the central plane CRVAL3</span>
+<a name="l00033"></a>00033         <span class="keywordtype">double</span> Tc, <span class="comment">// temperature in Celsius TEL.AMBI.TEMP</span>
+<a name="l00034"></a>00034         <span class="keywordtype">double</span> Rh, <span class="comment">// relative humidity in % TEL.AMBI.RHUM</span>
+<a name="l00035"></a>00035         <span class="keywordtype">double</span> airm, <span class="comment">// airmass for the moment of observation TEL.AMBI.PRES</span>
+<a name="l00036"></a>00036         <span class="keywordtype">double</span> p, <span class="comment">// atmospheric pressure TEL.AMBI.PRES</span>
+<a name="l00037"></a>00037         <span class="keywordtype">double</span> parallactic, <span class="comment">// TEL.PARANG</span>
+<a name="l00038"></a>00038         <span class="keywordtype">double</span> pixelscale, <span class="comment">// could be for SINFONI 0.025, 0.100, 0.250</span>
+<a name="l00039"></a>00039         <span class="keywordtype">double</span> pixelsz <span class="comment">// microns per pixel CDELT3</span>
+<a name="l00040"></a>00040               );
+<a name="l00041"></a>00041 
+<a name="l00042"></a>00042 
+<a name="l00043"></a>00043 <span class="keywordtype">void</span> calcAtmosphericDispersion( <span class="keywordtype">double</span> lambda, <span class="keywordtype">double</span> lambda0, <span class="keywordtype">double</span> *shiftX, <span class="keywordtype">double</span> *shiftY, <span class="keywordtype">double</span> *deltaR,
+<a name="l00044"></a>00044                    <span class="keywordtype">double</span> Tc,
+<a name="l00045"></a>00045                    <span class="keywordtype">double</span> rh,
+<a name="l00046"></a>00046                    <span class="keywordtype">double</span> airm,
+<a name="l00047"></a>00047                    <span class="keywordtype">double</span> p,
+<a name="l00048"></a>00048                    <span class="keywordtype">double</span> parallactic,
+<a name="l00049"></a>00049                    <span class="keywordtype">double</span> pixelscale);
+<a name="l00050"></a>00050 cpl_error_code sinfo_atmo_dispersion_cube(cpl_imagelist* pCube,
+<a name="l00051"></a>00051         <span class="keywordtype">int</span> centpix, <span class="comment">// central plane in the cube</span>
+<a name="l00052"></a>00052         <span class="keywordtype">double</span> centlambda, <span class="comment">// wavelength of the central plane</span>
+<a name="l00053"></a>00053         <span class="keywordtype">double</span> Tc, <span class="comment">// temperature in Celsius TEL.AMBI.TEMP</span>
+<a name="l00054"></a>00054         <span class="keywordtype">double</span> Rh, <span class="comment">// relative humidity in % TEL.AMBI.RHUM</span>
+<a name="l00055"></a>00055         <span class="keywordtype">double</span> airm, <span class="comment">// airmass for the moment of observation TEL.AMBI.PRES</span>
+<a name="l00056"></a>00056         <span class="keywordtype">double</span> p, <span class="comment">// atmospheric pressure TEL.AMBI.PRES</span>
+<a name="l00057"></a>00057         <span class="keywordtype">double</span> parallactic, <span class="comment">// TEL.PARANG</span>
+<a name="l00058"></a>00058         <span class="keywordtype">double</span> pixelscale, <span class="comment">// could be for SINFONI 0.025, 0.100, 0.250</span>
+<a name="l00059"></a>00059         <span class="keywordtype">double</span> pixelsz <span class="comment">// microns per pixel CDELT3</span>
+<a name="l00060"></a>00060         );
+<a name="l00061"></a>00061 cpl_imagelist* sinfo_atmo_apply_cube_polynomial_shift(
+<a name="l00062"></a>00062         cpl_polynomial* poly,
+<a name="l00063"></a>00063         cpl_imagelist* pCube,
+<a name="l00064"></a>00064         <span class="keywordtype">double</span> lambda0,
+<a name="l00065"></a>00065         <span class="keywordtype">double</span> airmass,
+<a name="l00066"></a>00066         <span class="keywordtype">double</span> parallactic, <span class="comment">// should be in radian</span>
+<a name="l00067"></a>00067         <span class="keywordtype">double</span> pixelsz,
+<a name="l00068"></a>00068         <span class="keywordtype">int</span> centpix);
+<a name="l00069"></a>00069 cpl_polynomial* sinfo_atmo_load_polynom(<span class="keyword">const</span> <span class="keywordtype">char</span>* filename);
+<a name="l00070"></a>00070 <span class="preprocessor">#endif </span><span class="comment">/* SINFO_ATM_DISP_H_ */</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__bad__cfg_8c_source.html b/html/sinfo__bad__cfg_8c_source.html
new file mode 100644
index 0000000..14f2d59
--- /dev/null
+++ b/html/sinfo__bad__cfg_8c_source.html
@@ -0,0 +1,71 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_bad_cfg.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_bad_cfg.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name     :    sinfo_bad_cfg.c</span>
+<a name="l00022"></a>00022 <span class="comment">   Autor    :       Juergen Schreiber</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on    :    October 2001</span>
+<a name="l00024"></a>00024 <span class="comment">   Description    :    handles the data structure bad_config</span>
+<a name="l00025"></a>00025 <span class="comment"></span>
+<a name="l00026"></a>00026 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00032"></a>00032 <span class="comment">                                   Includes</span>
+<a name="l00033"></a>00033 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00034"></a>00034 
+<a name="l00035"></a>00035 <span class="preprocessor">#include "sinfo_bad_cfg.h"</span>
+<a name="l00043"></a>00043 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00044"></a>00044 <span class="comment">                              Function codes</span>
+<a name="l00045"></a>00045 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00053"></a>00053 bad_config * 
+<a name="l00054"></a>00054 sinfo_bad_cfg_create(<span class="keywordtype">void</span>)
+<a name="l00055"></a>00055 {
+<a name="l00056"></a>00056     <span class="keywordflow">return</span> cpl_calloc(1, <span class="keyword">sizeof</span>(bad_config));
+<a name="l00057"></a>00057 }
+<a name="l00064"></a>00064 <span class="keywordtype">void</span> 
+<a name="l00065"></a>00065 sinfo_bad_cfg_destroy(bad_config * sc)
+<a name="l00066"></a>00066 {
+<a name="l00067"></a>00067 
+<a name="l00068"></a>00068     <span class="keywordflow">if</span> (sc==NULL) return ;
+<a name="l00069"></a>00069    
+<a name="l00070"></a>00070     <span class="comment">/* Free main struct */</span>
+<a name="l00071"></a>00071     cpl_free(sc);
+<a name="l00072"></a>00072 
+<a name="l00073"></a>00073     return ;
+<a name="l00074"></a>00074 }
+<a name="l00075"></a>00075 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__bad__cfg_8h_source.html b/html/sinfo__bad__cfg_8h_source.html
new file mode 100644
index 0000000..5bef3ad
--- /dev/null
+++ b/html/sinfo__bad__cfg_8h_source.html
@@ -0,0 +1,127 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_bad_cfg.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_bad_cfg.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name     :    bad_cfg.h</span>
+<a name="l00022"></a>00022 <span class="comment">   Author         :    Juergen Schreiber</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on    :    October 2001</span>
+<a name="l00024"></a>00024 <span class="comment">   Description    :    bad_ini definitions + handling prototypes</span>
+<a name="l00025"></a>00025 <span class="comment"></span>
+<a name="l00026"></a>00026 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00027"></a>00027 <span class="preprocessor">#ifndef SINFO_BAD_CFG_H</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_BAD_CFG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00030"></a>00030 <span class="comment">                                   Includes</span>
+<a name="l00031"></a>00031 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00032"></a>00032 <span class="preprocessor">#include <stdlib.h></span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include "sinfo_globals.h"</span>
+<a name="l00034"></a>00034 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00035"></a>00035 
+<a name="l00036"></a>00036 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00037"></a>00037 <span class="comment">                                   Defines</span>
+<a name="l00038"></a>00038 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00039"></a>00039 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00040"></a>00040 <span class="comment">                                   New types</span>
+<a name="l00041"></a>00041 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00042"></a>00042 <span class="comment">/*</span>
+<a name="l00043"></a>00043 <span class="comment">  bad pixels search blackboard container</span>
+<a name="l00044"></a>00044 <span class="comment"></span>
+<a name="l00045"></a>00045 <span class="comment">  This structure holds all information related to the bad pixels search</span>
+<a name="l00046"></a>00046 <span class="comment">  routine. It is used as a container for the flux of ancillary data,</span>
+<a name="l00047"></a>00047 <span class="comment">  computed values, and algorithm status. Pixel flux is separated from</span>
+<a name="l00048"></a>00048 <span class="comment">  the blackboard.</span>
+<a name="l00049"></a>00049 <span class="comment">  */</span>
+<a name="l00050"></a>00050 
+<a name="l00051"></a>00051 <span class="keyword">typedef</span> <span class="keyword">struct </span>bad_config {
+<a name="l00052"></a>00052 <span class="comment">/*-------General---------*/</span>
+<a name="l00053"></a>00053         <span class="keywordtype">char</span> inFile[FILE_NAME_SZ] ; <span class="comment">/* file name of the file containing </span>
+<a name="l00054"></a>00054 <span class="comment">                                       the list of all input frames */</span>
+<a name="l00055"></a>00055         <span class="keywordtype">char</span> outName[FILE_NAME_SZ] ; <span class="comment">/* output name of resulting bad pixel </span>
+<a name="l00056"></a>00056 <span class="comment">                                        mask (fits file)*/</span>
+<a name="l00057"></a>00057         <span class="keywordtype">char</span> ** framelist ; <span class="comment">/* list of frames */</span>
+<a name="l00058"></a>00058         <span class="keywordtype">int</span>     nframes ; <span class="comment">/* number of frames in frame list */</span>
+<a name="l00059"></a>00059 
+<a name="l00060"></a>00060 <span class="comment">/*------ BadPix ------*/</span>
+<a name="l00061"></a>00061         <span class="comment">/* factor of noise within which the pixels are used to fit a </span>
+<a name="l00062"></a>00062 <span class="comment">           straight line to the column intensity */</span>
+<a name="l00063"></a>00063         <span class="keywordtype">float</span> sigmaFactor ;      
+<a name="l00064"></a>00064         <span class="comment">/* factor of calculated standard deviation beyond which the </span>
+<a name="l00065"></a>00065 <span class="comment">           deviation of a pixel value from the </span>
+<a name="l00066"></a>00066 <span class="comment">           median of the 8 nearest neighbors declares a pixel as bad */</span>
+<a name="l00067"></a>00067         <span class="keywordtype">float</span> factor ;
+<a name="l00068"></a>00068         <span class="comment">/* number of iterations of sinfo_median filter */</span>
+<a name="l00069"></a>00069         <span class="keywordtype">int</span> iterations ;
+<a name="l00070"></a>00070         <span class="comment">/* percentage of extreme pixel value to reject when calculating </span>
+<a name="l00071"></a>00071 <span class="comment">           the mean and stdev */</span>
+<a name="l00072"></a>00072         <span class="keywordtype">float</span> loReject ;
+<a name="l00073"></a>00073         <span class="keywordtype">float</span> hiReject ;
+<a name="l00074"></a>00074         <span class="comment">/* pixel coordinate of lower left edge of a rectangle zone from </span>
+<a name="l00075"></a>00075 <span class="comment">           which image statistics are computed */</span>
+<a name="l00076"></a>00076         <span class="keywordtype">int</span> llx ;
+<a name="l00077"></a>00077         <span class="keywordtype">int</span> lly ;
+<a name="l00078"></a>00078         <span class="comment">/* pixel coordinate of upper right edge of a rectangle zone from </span>
+<a name="l00079"></a>00079 <span class="comment">           which image statistics are computed */</span>
+<a name="l00080"></a>00080         <span class="keywordtype">int</span> urx ;
+<a name="l00081"></a>00081         <span class="keywordtype">int</span> ury ;
+<a name="l00082"></a>00082 <span class="comment">/*------ Thresh ------*/</span>
+<a name="l00083"></a>00083         <span class="comment">/* indicates if the values beyond threshold values should </span>
+<a name="l00084"></a>00084 <span class="comment">           be marked as bad before proceeding </span>
+<a name="l00085"></a>00085 <span class="comment">           to sinfo_median filtering */</span>
+<a name="l00086"></a>00086         <span class="keywordtype">int</span> threshInd ;
+<a name="l00087"></a>00087         <span class="comment">/* factor to the clean standard deviation to define the </span>
+<a name="l00088"></a>00088 <span class="comment">           threshold deviation from the clean mean */</span>
+<a name="l00089"></a>00089         <span class="keywordtype">float</span> meanfactor ;
+<a name="l00090"></a>00090         <span class="comment">/* minimum vlaue of good data */</span>
+<a name="l00091"></a>00091         <span class="keywordtype">float</span> mincut ;
+<a name="l00092"></a>00092         <span class="comment">/* maximum vlaue of good data */</span>
+<a name="l00093"></a>00093         <span class="keywordtype">float</span> maxcut ;
+<a name="l00094"></a>00094         <span class="comment">/* indicates which method will be used */</span>
+<a name="l00095"></a>00095         <span class="keywordtype">int</span> methodInd ;
+<a name="l00096"></a>00096 } bad_config ;
+<a name="l00097"></a>00097 
+<a name="l00098"></a>00098 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00099"></a>00099 <span class="comment">                               Function prototypes</span>
+<a name="l00100"></a>00100 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00101"></a>00101 
+<a name="l00102"></a>00102 
+<a name="l00110"></a>00110 bad_config * 
+<a name="l00111"></a>00111 sinfo_bad_cfg_create(<span class="keywordtype">void</span>);
+<a name="l00112"></a>00112 
+<a name="l00113"></a>00113 
+<a name="l00120"></a>00120 <span class="keywordtype">void</span> 
+<a name="l00121"></a>00121 sinfo_bad_cfg_destroy(bad_config * sc);
+<a name="l00122"></a>00122  
+<a name="l00123"></a>00123 
+<a name="l00124"></a>00124 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__bad__ini_8h_source.html b/html/sinfo__bad__ini_8h_source.html
new file mode 100644
index 0000000..b4bc71d
--- /dev/null
+++ b/html/sinfo__bad__ini_8h_source.html
@@ -0,0 +1,71 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_bad_ini.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_bad_ini.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name    :   bad_ini.h</span>
+<a name="l00022"></a>00022 <span class="comment">   Author       :   Juergen Schreiber</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on   :   Oct 25, 2001</span>
+<a name="l00024"></a>00024 <span class="comment">   Description  :   prepare handling of .ini file for the search for static </span>
+<a name="l00025"></a>00025 <span class="comment">                    bad pixels</span>
+<a name="l00026"></a>00026 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00027"></a>00027 <span class="preprocessor">#ifndef SINFO_BAD_INI_H</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_BAD_INI_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span>
+<a name="l00030"></a>00030 
+<a name="l00031"></a>00031 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00032"></a>00032 <span class="comment">                                Includes</span>
+<a name="l00033"></a>00033 <span class="comment">---------------------------------------------------------------------------*/</span>
+<a name="l00034"></a>00034 <span class="preprocessor">#include "sinfo_bad_cfg.h"</span>
+<a name="l00035"></a>00035 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00036"></a>00036 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00037"></a>00037 <span class="comment">                                Defines</span>
+<a name="l00038"></a>00038 <span class="comment">---------------------------------------------------------------------------*/</span>
+<a name="l00039"></a>00039  
+<a name="l00040"></a>00040 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00041"></a>00041 <span class="comment">                             Function prototypes </span>
+<a name="l00042"></a>00042 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00043"></a>00043 
+<a name="l00054"></a>00054 <span class="keywordtype">int</span> 
+<a name="l00055"></a>00055 generateBad_ini_file(
+<a name="l00056"></a>00056         <span class="keywordtype">char</span> * ini_name,
+<a name="l00057"></a>00057         <span class="keywordtype">char</span> * name_i,
+<a name="l00058"></a>00058         <span class="keywordtype">char</span> * name_o
+<a name="l00059"></a>00059 );
+<a name="l00060"></a>00060  
+<a name="l00061"></a>00061 
+<a name="l00072"></a>00072 bad_config * 
+<a name="l00073"></a>00073 parse_bad_ini_file(<span class="keywordtype">char</span> * ini_name) ;
+<a name="l00074"></a>00074 
+<a name="l00075"></a>00075 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__baddist__ini__by__cpl_8c_source.html b/html/sinfo__baddist__ini__by__cpl_8c_source.html
new file mode 100644
index 0000000..6b2c336
--- /dev/null
+++ b/html/sinfo__baddist__ini__by__cpl_8c_source.html
@@ -0,0 +1,271 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_baddist_ini_by_cpl.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_baddist_ini_by_cpl.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name    :   sinfo_baddist_ini_by_cpl.c</span>
+<a name="l00022"></a>00022 <span class="comment">   Author       :   Andrea Modigliani</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on   :   Jun 16, 2004</span>
+<a name="l00024"></a>00024 <span class="comment">   Description  :   parse cpl input for the search of static bad pixels</span>
+<a name="l00025"></a>00025 <span class="comment"></span>
+<a name="l00026"></a>00026 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00027"></a>00027 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00029"></a>00029 <span class="preprocessor">#endif</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00031"></a>00031 <span class="comment">                                Includes</span>
+<a name="l00032"></a>00032 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include <string.h></span>
+<a name="l00034"></a>00034 <span class="preprocessor">#include "sinfo_baddist_ini_by_cpl.h"</span>
+<a name="l00035"></a>00035 <span class="preprocessor">#include "sinfo_hidden.h"</span>
+<a name="l00036"></a>00036 <span class="preprocessor">#include "sinfo_pro_types.h"</span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include "sinfo_raw_types.h"</span>
+<a name="l00038"></a>00038 <span class="preprocessor">#include "sinfo_globals.h"</span>
+<a name="l00039"></a>00039 <span class="preprocessor">#include "sinfo_functions.h"</span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include "sinfo_file_handling.h"</span>
+<a name="l00041"></a>00041 
+<a name="l00042"></a>00042 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00043"></a>00043 <span class="comment">                    Functions private to this module</span>
+<a name="l00044"></a>00044 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00045"></a>00045 
+<a name="l00046"></a>00046 <span class="keyword">static</span> <span class="keywordtype">void</span>  parse_section_frames(bad_config * cfg, 
+<a name="l00047"></a>00047 cpl_frameset* sof, <span class="keyword">const</span> <span class="keywordtype">char</span>* procatg, cpl_frameset** raw, <span class="keywordtype">int</span>* status);
+<a name="l00048"></a>00048 <span class="keyword">static</span> <span class="keywordtype">void</span> parse_section_badpix(bad_config * cfg, cpl_parameterlist* cpl_cfg);
+<a name="l00049"></a>00049 <span class="keyword">static</span> <span class="keywordtype">void</span> parse_section_thresh(bad_config * cfg, cpl_parameterlist* cpl_cfg);
+<a name="l00050"></a>00050 
+<a name="l00072"></a>00072 bad_config * 
+<a name="l00073"></a>00073 sinfo_parse_cpl_input_baddist(cpl_parameterlist * cpl_cfg, 
+<a name="l00074"></a>00074                                      cpl_frameset* sof,
+<a name="l00075"></a>00075                                      <span class="keyword">const</span> <span class="keywordtype">char</span>* procatg,
+<a name="l00076"></a>00076                                      cpl_frameset** raw) 
+<a name="l00077"></a>00077 {
+<a name="l00078"></a>00078   bad_config    *       cfg ;
+<a name="l00079"></a>00079   <span class="keywordtype">int</span> status = 0;
+<a name="l00080"></a>00080         <span class="comment">/* Removed check on ini_file */</span>
+<a name="l00081"></a>00081         <span class="comment">/* Removed load of ini file */</span>
+<a name="l00082"></a>00082 
+<a name="l00083"></a>00083   cfg = sinfo_bad_cfg_create();
+<a name="l00084"></a>00084 
+<a name="l00085"></a>00085         <span class="comment">/*</span>
+<a name="l00086"></a>00086 <span class="comment">         * Perform sanity checks, fill up the structure with what was</span>
+<a name="l00087"></a>00087 <span class="comment">         * found in the ini file</span>
+<a name="l00088"></a>00088 <span class="comment">         */</span>
+<a name="l00089"></a>00089 
+<a name="l00090"></a>00090   parse_section_badpix   (cfg, cpl_cfg);
+<a name="l00091"></a>00091   parse_section_thresh   (cfg, cpl_cfg);
+<a name="l00092"></a>00092   parse_section_frames   (cfg, sof, procatg, raw,&status);
+<a name="l00093"></a>00093   <span class="keywordflow">if</span>(status>0) {
+<a name="l00094"></a>00094                <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"parsing cpl input"</span>);
+<a name="l00095"></a>00095                 sinfo_bad_cfg_destroy(cfg);
+<a name="l00096"></a>00096                 cfg = NULL ;
+<a name="l00097"></a>00097                 <span class="keywordflow">return</span> NULL ;
+<a name="l00098"></a>00098   }
+<a name="l00099"></a>00099   <span class="keywordflow">return</span> cfg ;
+<a name="l00100"></a>00100 
+<a name="l00101"></a>00101 }
+<a name="l00102"></a>00102 
+<a name="l00114"></a>00114 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00115"></a>00115 parse_section_frames(bad_config   * cfg,
+<a name="l00116"></a>00116                      cpl_frameset * sof,
+<a name="l00117"></a>00117                      <span class="keyword">const</span> <span class="keywordtype">char</span>    * procatg,          
+<a name="l00118"></a>00118                      cpl_frameset ** raw,
+<a name="l00119"></a>00119                      <span class="keywordtype">int</span>* status)
+<a name="l00120"></a>00120 {
+<a name="l00121"></a>00121    <span class="keywordtype">int</span>                i=0;
+<a name="l00122"></a>00122    <span class="keywordtype">int</span>                nraw = 0;
+<a name="l00123"></a>00123    <span class="keywordtype">char</span> *          tag=NULL;
+<a name="l00124"></a>00124 
+<a name="l00125"></a>00125    <span class="keywordtype">int</span>  nraw_good = 0;
+<a name="l00126"></a>00126    cpl_frame* frame=NULL;
+<a name="l00127"></a>00127    <span class="keywordtype">char</span> spat_res[FILE_NAME_SZ];
+<a name="l00128"></a>00128    <span class="keywordtype">char</span> lamp_status[FILE_NAME_SZ];
+<a name="l00129"></a>00129    <span class="keywordtype">char</span> band[FILE_NAME_SZ];
+<a name="l00130"></a>00130    <span class="keywordtype">int</span> ins_set=0;
+<a name="l00131"></a>00131 
+<a name="l00132"></a>00132 
+<a name="l00133"></a>00133      <span class="keywordflow">if</span>(strcmp(procatg,PRO_BP_MAP_DI) == 0 ) {
+<a name="l00134"></a>00134 
+<a name="l00135"></a>00135       sinfo_extract_raw_frames_type(sof,raw,PRO_MASTER_FLAT_LAMP);
+<a name="l00136"></a>00136       nraw=cpl_frameset_get_size(*raw);
+<a name="l00137"></a>00137 
+<a name="l00138"></a>00138    } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(strcmp(procatg,PRO_BP_MAP_NO) == 0 ) {
+<a name="l00139"></a>00139       
+<a name="l00140"></a>00140       sinfo_extract_raw_frames_type(sof,raw,PRO_MASTER_FLAT_LAMP);
+<a name="l00141"></a>00141       nraw=cpl_frameset_get_size(*raw);
+<a name="l00142"></a>00142 
+<a name="l00143"></a>00143    } <span class="keywordflow">else</span> {
+<a name="l00144"></a>00144       sinfo_extract_raw_frames_type(sof,raw,RAW_FLAT_LAMP);
+<a name="l00145"></a>00145       nraw=cpl_frameset_get_size(*raw);
+<a name="l00146"></a>00146 
+<a name="l00147"></a>00147       <span class="keywordflow">if</span> (nraw==0) {
+<a name="l00148"></a>00148          sinfo_extract_raw_frames_type(sof,raw,RAW_FLAT_NS);
+<a name="l00149"></a>00149          nraw=cpl_frameset_get_size(*raw);
+<a name="l00150"></a>00150       }   
+<a name="l00151"></a>00151 
+<a name="l00152"></a>00152    }
+<a name="l00153"></a>00153     <span class="keywordflow">if</span> (nraw==0) {
+<a name="l00154"></a>00154          sinfo_extract_raw_frames_type(sof,raw,RAW_FLAT_LAMP);
+<a name="l00155"></a>00155          nraw=cpl_frameset_get_size(*raw);
+<a name="l00156"></a>00156     }
+<a name="l00157"></a>00157 
+<a name="l00158"></a>00158     <span class="keywordflow">if</span> (nraw==0) {
+<a name="l00159"></a>00159          sinfo_extract_raw_frames_type(sof,raw,RAW_FLAT_NS);
+<a name="l00160"></a>00160          nraw=cpl_frameset_get_size(*raw);
+<a name="l00161"></a>00161     }
+<a name="l00162"></a>00162 
+<a name="l00163"></a>00163 
+<a name="l00164"></a>00164 
+<a name="l00165"></a>00165    nraw=cpl_frameset_get_size(*raw);
+<a name="l00166"></a>00166    <span class="keywordflow">if</span> (nraw < 1) {
+<a name="l00167"></a>00167       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Too few (%d) raw frames (%s or %s) present in"</span>
+<a name="l00168"></a>00168              <span class="stringliteral">"frameset!Aborting..."</span>,nraw,
+<a name="l00169"></a>00169                          RAW_FLAT_LAMP,RAW_FLAT_NS);
+<a name="l00170"></a>00170       (*status)++;
+<a name="l00171"></a>00171       <span class="keywordflow">return</span>;
+<a name="l00172"></a>00172    }
+<a name="l00173"></a>00173         
+<a name="l00174"></a>00174    <span class="comment">/* Removed: get "general:infile" read it, check input sinfo_matrix */</span>
+<a name="l00175"></a>00175    <span class="comment">/* Allocate structures to go into the blackboard */</span>
+<a name="l00176"></a>00176    cfg->framelist     = cpl_malloc(nraw * <span class="keyword">sizeof</span>(<span class="keywordtype">char</span>*));
+<a name="l00177"></a>00177 
+<a name="l00178"></a>00178    <span class="comment">/* read input frames */</span>
+<a name="l00179"></a>00179    <span class="keywordflow">for</span> (i=0 ; i<nraw ; i++) {
+<a name="l00180"></a>00180       frame = cpl_frameset_get_frame(*raw,i);
+<a name="l00181"></a>00181       tag = (<span class="keywordtype">char</span>*)cpl_frame_get_tag(frame) ;
+<a name="l00182"></a>00182       <span class="keywordflow">if</span>(sinfo_file_exists((<span class="keywordtype">char</span>*) cpl_frame_get_filename(frame))==1) 
+<a name="l00183"></a>00183     {
+<a name="l00184"></a>00184              <span class="comment">/* Store file name into framelist */</span>
+<a name="l00185"></a>00185              cfg->framelist[i]=(<span class="keywordtype">char</span>*) cpl_frame_get_filename(frame);
+<a name="l00186"></a>00186              nraw_good++;
+<a name="l00187"></a>00187     }
+<a name="l00188"></a>00188    }
+<a name="l00189"></a>00189    <span class="keywordflow">if</span>(nraw_good<1) {
+<a name="l00190"></a>00190      <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Error: no good raw frame in input, something wrong!"</span>);
+<a name="l00191"></a>00191      (*status)++;
+<a name="l00192"></a>00192      <span class="keywordflow">return</span>;
+<a name="l00193"></a>00193    }
+<a name="l00194"></a>00194 
+<a name="l00195"></a>00195    <span class="comment">/* Copy relevant information into the blackboard */</span>
+<a name="l00196"></a>00196    cfg->nframes         = nraw_good ;
+<a name="l00197"></a>00197 
+<a name="l00198"></a>00198    <span class="comment">/* Output */</span>
+<a name="l00199"></a>00199    strcpy(cfg -> outName, BP_DIST_OUT_FILENAME);
+<a name="l00200"></a>00200  
+<a name="l00201"></a>00201 
+<a name="l00202"></a>00202 
+<a name="l00203"></a>00203 
+<a name="l00204"></a>00204    frame = cpl_frameset_get_frame(*raw,0);
+<a name="l00205"></a>00205    sinfo_get_spatial_res(frame,spat_res);
+<a name="l00206"></a>00206  
+<a name="l00207"></a>00207     <span class="keywordflow">switch</span>(sinfo_frame_is_on(frame)) 
+<a name="l00208"></a>00208      {
+<a name="l00209"></a>00209    <span class="keywordflow">case</span> 0: 
+<a name="l00210"></a>00210       strcpy(lamp_status,<span class="stringliteral">"on"</span>);
+<a name="l00211"></a>00211       <span class="keywordflow">break</span>;
+<a name="l00212"></a>00212     <span class="keywordflow">case</span> 1: 
+<a name="l00213"></a>00213       strcpy(lamp_status,<span class="stringliteral">"off"</span>);
+<a name="l00214"></a>00214       <span class="keywordflow">break</span>;
+<a name="l00215"></a>00215     <span class="keywordflow">case</span> -1:
+<a name="l00216"></a>00216       strcpy(lamp_status,<span class="stringliteral">"undefined"</span>);
+<a name="l00217"></a>00217       <span class="keywordflow">break</span>;
+<a name="l00218"></a>00218     <span class="keywordflow">default</span>: 
+<a name="l00219"></a>00219       strcpy(lamp_status,<span class="stringliteral">"undefined"</span>);
+<a name="l00220"></a>00220       <span class="keywordflow">break</span>;
+<a name="l00221"></a>00221      }
+<a name="l00222"></a>00222 
+<a name="l00223"></a>00223     sinfo_get_band(frame,band);
+<a name="l00224"></a>00224    sinfo_msg(<span class="stringliteral">"Spatial resolution: %s lamp_status: %s band: %s \n"</span>,
+<a name="l00225"></a>00225                      spat_res,    lamp_status,    band);
+<a name="l00226"></a>00226    sinfo_get_ins_set(band,&ins_set);
+<a name="l00227"></a>00227 
+<a name="l00228"></a>00228    <span class="keywordflow">return</span>;
+<a name="l00229"></a>00229 
+<a name="l00230"></a>00230 }
+<a name="l00231"></a>00231 
+<a name="l00239"></a>00239 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00240"></a>00240 parse_section_badpix(bad_config    * cfg, cpl_parameterlist *   cpl_cfg)
+<a name="l00241"></a>00241 {
+<a name="l00242"></a>00242    cpl_parameter *p;     
+<a name="l00243"></a>00243 
+<a name="l00244"></a>00244    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.bp_dist.sigma_factor"</span>);
+<a name="l00245"></a>00245    cfg -> sigmaFactor = cpl_parameter_get_double(p);
+<a name="l00246"></a>00246 
+<a name="l00247"></a>00247    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.bp_dist.method_index"</span>);
+<a name="l00248"></a>00248    cfg -> methodInd = cpl_parameter_get_int(p);
+<a name="l00249"></a>00249 
+<a name="l00250"></a>00250    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.bp_dist.factor"</span>);
+<a name="l00251"></a>00251    cfg -> factor = cpl_parameter_get_double(p);
+<a name="l00252"></a>00252 
+<a name="l00253"></a>00253    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.bp_dist.iterations"</span>);
+<a name="l00254"></a>00254    cfg -> iterations = cpl_parameter_get_int(p);
+<a name="l00255"></a>00255 
+<a name="l00256"></a>00256    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.bp_dist.low_rejection"</span>);
+<a name="l00257"></a>00257    cfg -> loReject = cpl_parameter_get_double(p);
+<a name="l00258"></a>00258 
+<a name="l00259"></a>00259    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.bp_dist.high_rejection"</span>);
+<a name="l00260"></a>00260    cfg -> hiReject = cpl_parameter_get_double(p);
+<a name="l00261"></a>00261 
+<a name="l00262"></a>00262    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.bp_dist.llx"</span>);
+<a name="l00263"></a>00263    cfg -> llx = cpl_parameter_get_int(p);
+<a name="l00264"></a>00264 
+<a name="l00265"></a>00265    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.bp_dist.lly"</span>);
+<a name="l00266"></a>00266    cfg -> lly = cpl_parameter_get_int(p);
+<a name="l00267"></a>00267 
+<a name="l00268"></a>00268    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.bp_dist.urx"</span>);
+<a name="l00269"></a>00269    cfg -> urx = cpl_parameter_get_int(p);
+<a name="l00270"></a>00270 
+<a name="l00271"></a>00271    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.bp_dist.ury"</span>);
+<a name="l00272"></a>00272    cfg -> ury = cpl_parameter_get_int(p);
+<a name="l00273"></a>00273 
+<a name="l00274"></a>00274 }
+<a name="l00275"></a>00275 
+<a name="l00283"></a>00283 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00284"></a>00284 parse_section_thresh(bad_config    * cfg, cpl_parameterlist *   cpl_cfg)
+<a name="l00285"></a>00285 {
+<a name="l00286"></a>00286    cpl_parameter *p;     
+<a name="l00287"></a>00287 
+<a name="l00288"></a>00288    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.bp_dist.threshold_index"</span>);
+<a name="l00289"></a>00289    cfg -> threshInd  = cpl_parameter_get_bool(p);
+<a name="l00290"></a>00290 
+<a name="l00291"></a>00291    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.bp_dist.mean_factor"</span>);
+<a name="l00292"></a>00292    cfg -> meanfactor = cpl_parameter_get_double(p);
+<a name="l00293"></a>00293 
+<a name="l00294"></a>00294 
+<a name="l00295"></a>00295    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.bp_dist.min_cut"</span>);
+<a name="l00296"></a>00296    cfg -> mincut = cpl_parameter_get_double(p);
+<a name="l00297"></a>00297 
+<a name="l00298"></a>00298    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.bp_dist.max_cut"</span>);
+<a name="l00299"></a>00299    cfg -> maxcut = cpl_parameter_get_double(p);
+<a name="l00300"></a>00300 
+<a name="l00301"></a>00301 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__baddist__ini__by__cpl_8h_source.html b/html/sinfo__baddist__ini__by__cpl_8h_source.html
new file mode 100644
index 0000000..d565e29
--- /dev/null
+++ b/html/sinfo__baddist__ini__by__cpl_8h_source.html
@@ -0,0 +1,72 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_baddist_ini_by_cpl.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_baddist_ini_by_cpl.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name    :   sinfo_baddist_ini_by_cpl.h</span>
+<a name="l00022"></a>00022 <span class="comment">   Author       :   Andrea Modigliani</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on   :   Jun 16, 2004</span>
+<a name="l00024"></a>00024 <span class="comment">   Description  :   parse cpl input for the search for static bad pixels</span>
+<a name="l00025"></a>00025 <span class="comment"></span>
+<a name="l00026"></a>00026 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 
+<a name="l00029"></a>00029 <span class="preprocessor">#ifndef SINFO_BADDIST_INI_BY_CPL_H</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_BADDIST_INI_BY_CPL_H</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span>
+<a name="l00032"></a>00032 
+<a name="l00033"></a>00033 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00034"></a>00034 <span class="comment">                                Includes</span>
+<a name="l00035"></a>00035 <span class="comment">---------------------------------------------------------------------------*/</span>
+<a name="l00036"></a>00036 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00038"></a>00038 <span class="preprocessor">#include "sinfo_bad_cfg.h"</span>
+<a name="l00039"></a>00039 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00040"></a>00040 <span class="comment">                                Defines</span>
+<a name="l00041"></a>00041 <span class="comment">---------------------------------------------------------------------------*/</span>
+<a name="l00042"></a>00042  
+<a name="l00043"></a>00043 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00044"></a>00044 <span class="comment">                             Function prototypes </span>
+<a name="l00045"></a>00045 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00046"></a>00046 
+<a name="l00053"></a>00053 <span class="keywordtype">void</span> 
+<a name="l00054"></a>00054 sinfo_bad_free(bad_config * cfg);
+<a name="l00055"></a>00055 
+<a name="l00069"></a>00069 bad_config * 
+<a name="l00070"></a>00070 sinfo_parse_cpl_input_baddist(cpl_parameterlist * cpl_cfg, 
+<a name="l00071"></a>00071                               cpl_frameset* sof, 
+<a name="l00072"></a>00072                               <span class="keyword">const</span> <span class="keywordtype">char</span>* procatg, 
+<a name="l00073"></a>00073                               cpl_frameset** raw);
+<a name="l00074"></a>00074 
+<a name="l00075"></a>00075 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__badnorm__ini__by__cpl_8c_source.html b/html/sinfo__badnorm__ini__by__cpl_8c_source.html
new file mode 100644
index 0000000..64fae37
--- /dev/null
+++ b/html/sinfo__badnorm__ini__by__cpl_8c_source.html
@@ -0,0 +1,295 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_badnorm_ini_by_cpl.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_badnorm_ini_by_cpl.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name    :   sinfo_badnorm_ini_by_cpl.c</span>
+<a name="l00022"></a>00022 <span class="comment">   Author       :   Andrea Modigliani</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on   :   Jun 16, 2004</span>
+<a name="l00024"></a>00024 <span class="comment">   Description  :   parse cpl input for the search of static bad pixels</span>
+<a name="l00025"></a>00025 <span class="comment"></span>
+<a name="l00026"></a>00026 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00027"></a>00027 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00029"></a>00029 <span class="preprocessor">#endif</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00031"></a>00031 <span class="comment">                                Includes</span>
+<a name="l00032"></a>00032 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00033"></a>00033 
+<a name="l00034"></a>00034 <span class="preprocessor">#include <string.h></span>
+<a name="l00035"></a>00035 <span class="preprocessor">#include "sinfo_badnorm_ini_by_cpl.h"</span>
+<a name="l00036"></a>00036 <span class="preprocessor">#include "sinfo_raw_types.h"</span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include "sinfo_pro_types.h"</span>
+<a name="l00038"></a>00038 <span class="preprocessor">#include "sinfo_hidden.h"</span>
+<a name="l00039"></a>00039 <span class="preprocessor">#include "sinfo_globals.h"</span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include "sinfo_functions.h"</span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include "sinfo_file_handling.h"</span>
+<a name="l00042"></a>00042 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00043"></a>00043 <span class="comment">                    Functions private to this module</span>
+<a name="l00044"></a>00044 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00045"></a>00045 
+<a name="l00046"></a>00046 <span class="keyword">static</span> <span class="keywordtype">void</span>  parse_section_frames(bad_config * cfg, 
+<a name="l00047"></a>00047 cpl_frameset* sof, <span class="keyword">const</span> <span class="keywordtype">char</span>* procatg, cpl_frameset** raw, <span class="keywordtype">int</span>* status);
+<a name="l00048"></a>00048 <span class="keyword">static</span> <span class="keywordtype">void</span> parse_section_badpix(bad_config * cfg, cpl_parameterlist* cpl_cfg);
+<a name="l00049"></a>00049 <span class="keyword">static</span> <span class="keywordtype">void</span> parse_section_thresh(bad_config * cfg, cpl_parameterlist* cpl_cfg);
+<a name="l00050"></a>00050 
+<a name="l00071"></a>00071 bad_config * 
+<a name="l00072"></a>00072 sinfo_parse_cpl_input_badnorm(cpl_parameterlist * cpl_cfg, 
+<a name="l00073"></a>00073                                      cpl_frameset* sof,
+<a name="l00074"></a>00074                                      <span class="keyword">const</span> <span class="keywordtype">char</span>* procatg,
+<a name="l00075"></a>00075                                      cpl_frameset** raw) 
+<a name="l00076"></a>00076 {
+<a name="l00077"></a>00077   bad_config    *       cfg ;
+<a name="l00078"></a>00078   <span class="keywordtype">int</span> status = 0;
+<a name="l00079"></a>00079         <span class="comment">/* Removed check on ini_file */</span>
+<a name="l00080"></a>00080         <span class="comment">/* Removed load of ini file */</span>
+<a name="l00081"></a>00081 
+<a name="l00082"></a>00082   cfg = sinfo_bad_cfg_create();
+<a name="l00083"></a>00083 
+<a name="l00084"></a>00084         <span class="comment">/*</span>
+<a name="l00085"></a>00085 <span class="comment">         * Perform sanity checks, fill up the structure with what was</span>
+<a name="l00086"></a>00086 <span class="comment">         * found in the ini file</span>
+<a name="l00087"></a>00087 <span class="comment">         */</span>
+<a name="l00088"></a>00088 
+<a name="l00089"></a>00089   parse_section_badpix   (cfg, cpl_cfg);
+<a name="l00090"></a>00090   parse_section_thresh   (cfg, cpl_cfg);
+<a name="l00091"></a>00091   parse_section_frames   (cfg, sof, procatg, raw,&status);
+<a name="l00092"></a>00092   <span class="keywordflow">if</span>(status>0) {
+<a name="l00093"></a>00093                <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"parsing cpl input"</span>);
+<a name="l00094"></a>00094                 sinfo_bad_cfg_destroy(cfg);
+<a name="l00095"></a>00095                 cfg = NULL ;
+<a name="l00096"></a>00096                 <span class="keywordflow">return</span> NULL ;
+<a name="l00097"></a>00097   }
+<a name="l00098"></a>00098   <span class="keywordflow">return</span> cfg ;
+<a name="l00099"></a>00099 
+<a name="l00100"></a>00100 }
+<a name="l00101"></a>00101 
+<a name="l00102"></a>00102 
+<a name="l00115"></a>00115 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00116"></a>00116 parse_section_frames(bad_config   * cfg,
+<a name="l00117"></a>00117                      cpl_frameset * sof,
+<a name="l00118"></a>00118                      <span class="keyword">const</span> <span class="keywordtype">char</span>         * procatg,          
+<a name="l00119"></a>00119                      cpl_frameset ** raw,
+<a name="l00120"></a>00120                      <span class="keywordtype">int</span>* status)
+<a name="l00121"></a>00121 {
+<a name="l00122"></a>00122    <span class="keywordtype">int</span>                i=0;
+<a name="l00123"></a>00123    <span class="keywordtype">int</span>                nraw = 0;
+<a name="l00124"></a>00124    <span class="keywordtype">char</span> *          tag=NULL;
+<a name="l00125"></a>00125 
+<a name="l00126"></a>00126    <span class="keywordtype">int</span>  nraw_good = 0;
+<a name="l00127"></a>00127    cpl_frame* frame=NULL;
+<a name="l00128"></a>00128    <span class="keywordtype">char</span> spat_res[FILE_NAME_SZ];
+<a name="l00129"></a>00129    <span class="keywordtype">char</span> lamp_status[FILE_NAME_SZ];
+<a name="l00130"></a>00130    <span class="keywordtype">char</span> band[FILE_NAME_SZ];
+<a name="l00131"></a>00131    <span class="keywordtype">int</span> ins_set=0;
+<a name="l00132"></a>00132      <span class="keywordflow">if</span>(strcmp(procatg,PRO_BP_MAP_DI) == 0 ) {
+<a name="l00133"></a>00133 
+<a name="l00134"></a>00134       sinfo_extract_raw_frames_type(sof,raw,PRO_MASTER_FLAT_LAMP);
+<a name="l00135"></a>00135       nraw=cpl_frameset_get_size(*raw);
+<a name="l00136"></a>00136 
+<a name="l00137"></a>00137    } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(strcmp(procatg,PRO_BP_MAP_NO) == 0 ) {
+<a name="l00138"></a>00138       
+<a name="l00139"></a>00139       sinfo_extract_raw_frames_type(sof,raw,PRO_MASTER_FLAT_LAMP);
+<a name="l00140"></a>00140       nraw=cpl_frameset_get_size(*raw);
+<a name="l00141"></a>00141 
+<a name="l00142"></a>00142    } <span class="keywordflow">else</span> {
+<a name="l00143"></a>00143       sinfo_extract_raw_frames_type(sof,raw,RAW_FLAT_LAMP);
+<a name="l00144"></a>00144       nraw=cpl_frameset_get_size(*raw);
+<a name="l00145"></a>00145 
+<a name="l00146"></a>00146       <span class="keywordflow">if</span> (nraw==0) {
+<a name="l00147"></a>00147          sinfo_extract_raw_frames_type(sof,raw,RAW_FLAT_NS);
+<a name="l00148"></a>00148          nraw=cpl_frameset_get_size(*raw);
+<a name="l00149"></a>00149       }   
+<a name="l00150"></a>00150 
+<a name="l00151"></a>00151    }
+<a name="l00152"></a>00152     <span class="keywordflow">if</span> (nraw==0) {
+<a name="l00153"></a>00153          sinfo_extract_raw_frames_type(sof,raw,RAW_FLAT_LAMP);
+<a name="l00154"></a>00154          nraw=cpl_frameset_get_size(*raw);
+<a name="l00155"></a>00155     }
+<a name="l00156"></a>00156 
+<a name="l00157"></a>00157     <span class="keywordflow">if</span> (nraw==0) {
+<a name="l00158"></a>00158          sinfo_extract_raw_frames_type(sof,raw,RAW_FLAT_NS);
+<a name="l00159"></a>00159          nraw=cpl_frameset_get_size(*raw);
+<a name="l00160"></a>00160     }
+<a name="l00161"></a>00161 
+<a name="l00162"></a>00162 
+<a name="l00163"></a>00163    <span class="keywordflow">if</span> (nraw < 1) {
+<a name="l00164"></a>00164       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Too few (%d) raw frames (%s or %s or %s) present in"</span>
+<a name="l00165"></a>00165              <span class="stringliteral">"frameset!Aborting..."</span>,nraw,
+<a name="l00166"></a>00166                          PRO_MASTER_FLAT_LAMP,RAW_FLAT_LAMP,RAW_FLAT_NS);
+<a name="l00167"></a>00167       (*status)++;
+<a name="l00168"></a>00168       <span class="keywordflow">return</span>;
+<a name="l00169"></a>00169    }
+<a name="l00170"></a>00170         
+<a name="l00171"></a>00171    <span class="comment">/* Removed: get "general:infile" read it, check input sinfo_matrix */</span>
+<a name="l00172"></a>00172    <span class="comment">/* Allocate structures to go into the blackboard */</span>
+<a name="l00173"></a>00173    cfg->framelist     = cpl_malloc(nraw * <span class="keyword">sizeof</span>(<span class="keywordtype">char</span>*));
+<a name="l00174"></a>00174 
+<a name="l00175"></a>00175    <span class="comment">/* read input frames */</span>
+<a name="l00176"></a>00176    <span class="keywordflow">for</span> (i=0 ; i<nraw ; i++) {
+<a name="l00177"></a>00177       frame = cpl_frameset_get_frame(*raw,i);
+<a name="l00178"></a>00178       tag = (<span class="keywordtype">char</span>*)cpl_frame_get_tag(frame) ;
+<a name="l00179"></a>00179       <span class="keywordflow">if</span>(sinfo_file_exists((<span class="keywordtype">char</span>*) cpl_frame_get_filename(frame))==1) 
+<a name="l00180"></a>00180     {
+<a name="l00181"></a>00181              <span class="comment">/* Store file name into framelist */</span>
+<a name="l00182"></a>00182              cfg->framelist[i]=(<span class="keywordtype">char</span>*) cpl_frame_get_filename(frame);
+<a name="l00183"></a>00183              nraw_good++;
+<a name="l00184"></a>00184     }
+<a name="l00185"></a>00185    }
+<a name="l00186"></a>00186 
+<a name="l00187"></a>00187    <span class="keywordflow">if</span>(nraw_good<1) {
+<a name="l00188"></a>00188      <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Error: no good raw frame in input, something wrong!"</span>);
+<a name="l00189"></a>00189      (*status)++;
+<a name="l00190"></a>00190      <span class="keywordflow">return</span>;
+<a name="l00191"></a>00191    }
+<a name="l00192"></a>00192 
+<a name="l00193"></a>00193    <span class="comment">/* Copy relevant information into the blackboard */</span>
+<a name="l00194"></a>00194    cfg->nframes         = nraw_good ;
+<a name="l00195"></a>00195 
+<a name="l00196"></a>00196    <span class="comment">/* Output */</span>
+<a name="l00197"></a>00197           <span class="keywordflow">if</span> (strcmp(procatg,PRO_BP_MAP_NO) == 0) {
+<a name="l00198"></a>00198       strcpy(cfg -> outName, BP_NORM_OUT_FILENAME);
+<a name="l00199"></a>00199    } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(procatg,PRO_BP_MAP_DI) == 0) {
+<a name="l00200"></a>00200       strcpy(cfg -> outName, BP_DIST_OUT_FILENAME);
+<a name="l00201"></a>00201    } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(procatg,PRO_DEFAULT) == 0) {
+<a name="l00202"></a>00202       strcpy(cfg -> outName, BP_NORM_OUT_FILENAME);
+<a name="l00203"></a>00203    } <span class="keywordflow">else</span> {
+<a name="l00204"></a>00204       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Error: PRO.CATG %s, not supported!"</span>,procatg);
+<a name="l00205"></a>00205       (*status)++;
+<a name="l00206"></a>00206       <span class="keywordflow">return</span>;
+<a name="l00207"></a>00207    }
+<a name="l00208"></a>00208 
+<a name="l00209"></a>00209 
+<a name="l00210"></a>00210 
+<a name="l00211"></a>00211    frame = cpl_frameset_get_frame(*raw,0);
+<a name="l00212"></a>00212    sinfo_get_spatial_res(frame,spat_res);
+<a name="l00213"></a>00213  
+<a name="l00214"></a>00214  
+<a name="l00215"></a>00215    <span class="keywordflow">switch</span>(sinfo_frame_is_on(frame)) 
+<a name="l00216"></a>00216      {
+<a name="l00217"></a>00217    <span class="keywordflow">case</span> 0: 
+<a name="l00218"></a>00218       strcpy(lamp_status,<span class="stringliteral">"on"</span>);
+<a name="l00219"></a>00219       <span class="keywordflow">break</span>;
+<a name="l00220"></a>00220     <span class="keywordflow">case</span> 1: 
+<a name="l00221"></a>00221       strcpy(lamp_status,<span class="stringliteral">"off"</span>);
+<a name="l00222"></a>00222       <span class="keywordflow">break</span>;
+<a name="l00223"></a>00223     <span class="keywordflow">case</span> -1:
+<a name="l00224"></a>00224       strcpy(lamp_status,<span class="stringliteral">"undefined"</span>);
+<a name="l00225"></a>00225       <span class="keywordflow">break</span>;
+<a name="l00226"></a>00226     <span class="keywordflow">default</span>: 
+<a name="l00227"></a>00227       strcpy(lamp_status,<span class="stringliteral">"undefined"</span>);
+<a name="l00228"></a>00228       <span class="keywordflow">break</span>;
+<a name="l00229"></a>00229      }
+<a name="l00230"></a>00230 
+<a name="l00231"></a>00231    sinfo_get_band(frame,band);
+<a name="l00232"></a>00232    sinfo_msg(<span class="stringliteral">"Spatial resolution: %s lamp status: %s band: %s \n"</span>,
+<a name="l00233"></a>00233                      spat_res,              lamp_status,    band);
+<a name="l00234"></a>00234 
+<a name="l00235"></a>00235 
+<a name="l00236"></a>00236    sinfo_get_ins_set(band,&ins_set);
+<a name="l00237"></a>00237 
+<a name="l00238"></a>00238    <span class="keywordflow">return</span>;
+<a name="l00239"></a>00239 
+<a name="l00240"></a>00240 }
+<a name="l00241"></a>00241 
+<a name="l00251"></a>00251 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00252"></a>00252 parse_section_badpix(bad_config    * cfg, cpl_parameterlist *   cpl_cfg)
+<a name="l00253"></a>00253 {
+<a name="l00254"></a>00254    cpl_parameter *p;     
+<a name="l00255"></a>00255 
+<a name="l00256"></a>00256    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.bp_norm.sigma_factor"</span>);
+<a name="l00257"></a>00257    cfg -> sigmaFactor = cpl_parameter_get_double(p);
+<a name="l00258"></a>00258 
+<a name="l00259"></a>00259    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.bp_norm.method_index"</span>);
+<a name="l00260"></a>00260    cfg -> methodInd = cpl_parameter_get_int(p);
+<a name="l00261"></a>00261 
+<a name="l00262"></a>00262    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.bp_norm.factor"</span>);
+<a name="l00263"></a>00263    cfg -> factor = cpl_parameter_get_double(p);
+<a name="l00264"></a>00264 
+<a name="l00265"></a>00265    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.bp_norm.iterations"</span>);
+<a name="l00266"></a>00266    cfg -> iterations = cpl_parameter_get_int(p);
+<a name="l00267"></a>00267 
+<a name="l00268"></a>00268    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.bp_norm.low_rejection"</span>);
+<a name="l00269"></a>00269    cfg -> loReject = cpl_parameter_get_double(p);
+<a name="l00270"></a>00270 
+<a name="l00271"></a>00271    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.bp_norm.high_rejection"</span>);
+<a name="l00272"></a>00272    cfg -> hiReject = cpl_parameter_get_double(p);
+<a name="l00273"></a>00273 
+<a name="l00274"></a>00274    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.bp_norm.llx"</span>);
+<a name="l00275"></a>00275    cfg -> llx = cpl_parameter_get_int(p);
+<a name="l00276"></a>00276 
+<a name="l00277"></a>00277    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.bp_norm.lly"</span>);
+<a name="l00278"></a>00278    cfg -> lly = cpl_parameter_get_int(p);
+<a name="l00279"></a>00279 
+<a name="l00280"></a>00280    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.bp_norm.urx"</span>);
+<a name="l00281"></a>00281    cfg -> urx = cpl_parameter_get_int(p);
+<a name="l00282"></a>00282 
+<a name="l00283"></a>00283    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.bp_norm.ury"</span>);
+<a name="l00284"></a>00284    cfg -> ury = cpl_parameter_get_int(p);
+<a name="l00285"></a>00285 
+<a name="l00286"></a>00286 }
+<a name="l00287"></a>00287 
+<a name="l00297"></a>00297 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00298"></a>00298 parse_section_thresh(bad_config    * cfg, cpl_parameterlist *   cpl_cfg)
+<a name="l00299"></a>00299 {
+<a name="l00300"></a>00300    cpl_parameter *p;     
+<a name="l00301"></a>00301 
+<a name="l00302"></a>00302    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.bp_norm.threshold_index"</span>);
+<a name="l00303"></a>00303    cfg -> threshInd  = cpl_parameter_get_bool(p);
+<a name="l00304"></a>00304 
+<a name="l00305"></a>00305    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.bp_norm.mean_factor"</span>);
+<a name="l00306"></a>00306    cfg -> meanfactor = cpl_parameter_get_double(p);
+<a name="l00307"></a>00307 
+<a name="l00308"></a>00308 
+<a name="l00309"></a>00309    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.bp_norm.min_cut"</span>);
+<a name="l00310"></a>00310    cfg -> mincut = cpl_parameter_get_double(p);
+<a name="l00311"></a>00311 
+<a name="l00312"></a>00312    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.bp_norm.max_cut"</span>);
+<a name="l00313"></a>00313    cfg -> maxcut = cpl_parameter_get_double(p);
+<a name="l00314"></a>00314 
+<a name="l00315"></a>00315 }
+<a name="l00323"></a>00323 <span class="keywordtype">void</span>
+<a name="l00324"></a>00324 sinfo_badnorm_free(bad_config ** cfg)
+<a name="l00325"></a>00325 {  
+<a name="l00326"></a>00326   <span class="keywordflow">if</span>((*cfg) != NULL) {
+<a name="l00327"></a>00327     <span class="keywordflow">if</span>((*cfg)->framelist != NULL) {
+<a name="l00328"></a>00328        cpl_free((*cfg)->framelist);
+<a name="l00329"></a>00329        (*cfg)->framelist=NULL;
+<a name="l00330"></a>00330     }
+<a name="l00331"></a>00331     sinfo_bad_cfg_destroy((*cfg));
+<a name="l00332"></a>00332     *cfg =NULL;
+<a name="l00333"></a>00333   }
+<a name="l00334"></a>00334   <span class="keywordflow">return</span>;
+<a name="l00335"></a>00335 
+<a name="l00336"></a>00336 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__badnorm__ini__by__cpl_8h_source.html b/html/sinfo__badnorm__ini__by__cpl_8h_source.html
new file mode 100644
index 0000000..297c6ab
--- /dev/null
+++ b/html/sinfo__badnorm__ini__by__cpl_8h_source.html
@@ -0,0 +1,66 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_badnorm_ini_by_cpl.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_badnorm_ini_by_cpl.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name    :   sinfo_badnorm_ini_by_cpl.h</span>
+<a name="l00022"></a>00022 <span class="comment">   Author       :   Andrea Modigliani</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on   :   Jun 16, 2004</span>
+<a name="l00024"></a>00024 <span class="comment">   Description  :   parse cpl input for the search for static bad pixels</span>
+<a name="l00025"></a>00025 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00026"></a>00026 <span class="preprocessor">#ifndef SINFO_BADNORM_INI_BY_CPL_H</span>
+<a name="l00027"></a>00027 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_BADNORM_INI_BY_CPL_H</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00029"></a>00029 <span class="comment">                                Includes</span>
+<a name="l00030"></a>00030 <span class="comment">---------------------------------------------------------------------------*/</span>
+<a name="l00031"></a>00031 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00032"></a>00032 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include "sinfo_bad_cfg.h"</span>
+<a name="l00034"></a>00034 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00035"></a>00035 <span class="comment">                                Defines</span>
+<a name="l00036"></a>00036 <span class="comment">---------------------------------------------------------------------------*/</span>
+<a name="l00037"></a>00037 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00038"></a>00038 <span class="comment">                             Function prototypes </span>
+<a name="l00039"></a>00039 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00050"></a>00050 bad_config * 
+<a name="l00051"></a>00051 sinfo_parse_cpl_input_badnorm(cpl_parameterlist * cpl_cfg, 
+<a name="l00052"></a>00052                               cpl_frameset* sof, 
+<a name="l00053"></a>00053                               <span class="keyword">const</span> <span class="keywordtype">char</span>* procatg, 
+<a name="l00054"></a>00054                               cpl_frameset** raw);
+<a name="l00055"></a>00055 
+<a name="l00056"></a>00056 
+<a name="l00063"></a>00063 <span class="keywordtype">void</span> 
+<a name="l00064"></a>00064 sinfo_badnorm_free(bad_config ** cfg);
+<a name="l00065"></a>00065 
+<a name="l00066"></a>00066 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__badsky__cfg_8c_source.html b/html/sinfo__badsky__cfg_8c_source.html
new file mode 100644
index 0000000..ed5287c
--- /dev/null
+++ b/html/sinfo__badsky__cfg_8c_source.html
@@ -0,0 +1,69 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_badsky_cfg.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_badsky_cfg.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name     :    sinfo_badsky_cfg.c</span>
+<a name="l00022"></a>00022 <span class="comment">   Autor    :       Juergen Schreiber</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on    :    October 2001</span>
+<a name="l00024"></a>00024 <span class="comment">   Description    :    handles the data structure bad_config</span>
+<a name="l00025"></a>00025 <span class="comment"></span>
+<a name="l00026"></a>00026 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00027"></a>00027 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00029"></a>00029 <span class="preprocessor">#endif</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span>
+<a name="l00031"></a>00031 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00032"></a>00032 <span class="comment">                                   Includes</span>
+<a name="l00033"></a>00033 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00034"></a>00034 
+<a name="l00035"></a>00035 <span class="preprocessor">#include "sinfo_badsky_cfg.h"</span>
+<a name="l00043"></a>00043 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00044"></a>00044 <span class="comment">                              Function codes</span>
+<a name="l00045"></a>00045 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00053"></a>00053 badsky_config * sinfo_badsky_cfg_create(<span class="keywordtype">void</span>)
+<a name="l00054"></a>00054 {
+<a name="l00055"></a>00055     <span class="keywordflow">return</span> cpl_calloc(1, <span class="keyword">sizeof</span>(badsky_config));
+<a name="l00056"></a>00056 }
+<a name="l00064"></a>00064 <span class="keywordtype">void</span> sinfo_badsky_cfg_destroy(badsky_config * sc)
+<a name="l00065"></a>00065 {
+<a name="l00066"></a>00066 
+<a name="l00067"></a>00067     <span class="keywordflow">if</span> (sc==NULL) return ;
+<a name="l00068"></a>00068    
+<a name="l00069"></a>00069     <span class="comment">/* Free main struct */</span>
+<a name="l00070"></a>00070     cpl_free(sc);
+<a name="l00071"></a>00071 
+<a name="l00072"></a>00072     return ;
+<a name="l00073"></a>00073 }
+<a name="l00074"></a>00074 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__badsky__cfg_8h_source.html b/html/sinfo__badsky__cfg_8h_source.html
new file mode 100644
index 0000000..5fe703a
--- /dev/null
+++ b/html/sinfo__badsky__cfg_8h_source.html
@@ -0,0 +1,123 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_badsky_cfg.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_badsky_cfg.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name     :    sinfo_badsky_cfg.h</span>
+<a name="l00022"></a>00022 <span class="comment">   Author         :    Juergen Schreiber</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on    :    October 2001</span>
+<a name="l00024"></a>00024 <span class="comment">   Description    :    bad_ini definitions + handling prototypes</span>
+<a name="l00025"></a>00025 <span class="comment"></span>
+<a name="l00026"></a>00026 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00027"></a>00027 <span class="preprocessor">#ifndef SINFO_BADSKY_CFG_H</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_BADSKY_CFG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00030"></a>00030 <span class="comment">                                   Includes</span>
+<a name="l00031"></a>00031 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00032"></a>00032 <span class="preprocessor">#include <stdlib.h></span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include "sinfo_globals.h"</span>
+<a name="l00034"></a>00034 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00035"></a>00035 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00036"></a>00036 <span class="comment">                                   Defines</span>
+<a name="l00037"></a>00037 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00038"></a>00038 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00039"></a>00039 <span class="comment">                                   New types</span>
+<a name="l00040"></a>00040 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00041"></a>00041 <span class="comment">/*</span>
+<a name="l00042"></a>00042 <span class="comment">  bad pixels search blackboard container</span>
+<a name="l00043"></a>00043 <span class="comment"></span>
+<a name="l00044"></a>00044 <span class="comment">  This structure holds all information related to the bad pixels search</span>
+<a name="l00045"></a>00045 <span class="comment">  routine. It is used as a container for the flux of ancillary data,</span>
+<a name="l00046"></a>00046 <span class="comment">  computed values, and algorithm status. Pixel flux is separated from</span>
+<a name="l00047"></a>00047 <span class="comment">  the blackboard.</span>
+<a name="l00048"></a>00048 <span class="comment">  */</span>
+<a name="l00049"></a>00049 
+<a name="l00050"></a>00050 <span class="keyword">typedef</span> <span class="keyword">struct </span>badsky_config {
+<a name="l00051"></a>00051 <span class="comment">/*-------General---------*/</span>
+<a name="l00052"></a>00052         <span class="keywordtype">char</span> inFile[FILE_NAME_SZ] ; <span class="comment">/* file name of the </span>
+<a name="l00053"></a>00053 <span class="comment">                                       file containing the list of </span>
+<a name="l00054"></a>00054 <span class="comment">                                       all input frames */</span>
+<a name="l00055"></a>00055         <span class="keywordtype">char</span> sinfo_dark[FILE_NAME_SZ] ; <span class="comment">/* Input sinfo_dark */</span>
+<a name="l00056"></a>00056         <span class="keywordtype">char</span> outName[FILE_NAME_SZ] ; <span class="comment">/* output name of resulting </span>
+<a name="l00057"></a>00057 <span class="comment">                                        bad pixel mask (fits file)*/</span>
+<a name="l00058"></a>00058         <span class="keywordtype">char</span> ** framelist ; <span class="comment">/* list of frames */</span>
+<a name="l00059"></a>00059         <span class="keywordtype">int</span>     nframes ; <span class="comment">/* number of frames in frame list */</span>
+<a name="l00060"></a>00060 
+<a name="l00061"></a>00061 <span class="comment">/*------ BadPix ------*/</span>
+<a name="l00062"></a>00062         <span class="comment">/* factor of noise within which the pixels are used to fit a </span>
+<a name="l00063"></a>00063 <span class="comment">           straight line to the column intensity */</span>
+<a name="l00064"></a>00064         <span class="keywordtype">float</span> sigmaFactor ;      
+<a name="l00065"></a>00065         <span class="comment">/* factor of calculated standard deviation beyond </span>
+<a name="l00066"></a>00066 <span class="comment">           which the deviation of a pixel value from the </span>
+<a name="l00067"></a>00067 <span class="comment">           median of the 8 nearest neighbors declares a pixel as bad */</span>
+<a name="l00068"></a>00068         <span class="keywordtype">float</span> factor ;
+<a name="l00069"></a>00069         <span class="comment">/* number of iterations of sinfo_median filter */</span>
+<a name="l00070"></a>00070         <span class="keywordtype">int</span> iterations ;
+<a name="l00071"></a>00071         <span class="comment">/* percentage of extreme pixel value to reject </span>
+<a name="l00072"></a>00072 <span class="comment">           when calculating the mean and stdev */</span>
+<a name="l00073"></a>00073         <span class="keywordtype">float</span> loReject ;
+<a name="l00074"></a>00074         <span class="keywordtype">float</span> hiReject ;
+<a name="l00075"></a>00075         <span class="comment">/* pixel coordinate of lower left sinfo_edge of a </span>
+<a name="l00076"></a>00076 <span class="comment">           rectangle zone from which image statistics are computed */</span>
+<a name="l00077"></a>00077         <span class="keywordtype">int</span> llx ;
+<a name="l00078"></a>00078         <span class="keywordtype">int</span> lly ;
+<a name="l00079"></a>00079         <span class="comment">/* pixel coordinate of upper right sinfo_edge of a rectangle </span>
+<a name="l00080"></a>00080 <span class="comment">           zone from which image statistics are computed */</span>
+<a name="l00081"></a>00081         <span class="keywordtype">int</span> urx ;
+<a name="l00082"></a>00082         <span class="keywordtype">int</span> ury ;
+<a name="l00083"></a>00083 <span class="comment">/*------ Thresh ------*/</span>
+<a name="l00084"></a>00084         <span class="comment">/* indicates if the values beyond threshold values should be </span>
+<a name="l00085"></a>00085 <span class="comment">           marked as bad before proceeding </span>
+<a name="l00086"></a>00086 <span class="comment">           to sinfo_median filtering */</span>
+<a name="l00087"></a>00087         <span class="keywordtype">int</span> threshInd ;
+<a name="l00088"></a>00088         <span class="comment">/* factor to the clean standard deviation to define the </span>
+<a name="l00089"></a>00089 <span class="comment">           threshold deviation from the clean mean */</span>
+<a name="l00090"></a>00090         <span class="keywordtype">float</span> meanfactor ;
+<a name="l00091"></a>00091         <span class="comment">/* minimum vlaue of good data */</span>
+<a name="l00092"></a>00092         <span class="keywordtype">float</span> mincut ;
+<a name="l00093"></a>00093         <span class="comment">/* maximum vlaue of good data */</span>
+<a name="l00094"></a>00094         <span class="keywordtype">float</span> maxcut ;
+<a name="l00095"></a>00095         <span class="comment">/* indicates which method will be used */</span>
+<a name="l00096"></a>00096         <span class="keywordtype">int</span> methodInd ;
+<a name="l00097"></a>00097 } badsky_config ;
+<a name="l00098"></a>00098 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00099"></a>00099 <span class="comment">                               Function prototypes</span>
+<a name="l00100"></a>00100 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00101"></a>00101 
+<a name="l00109"></a>00109 badsky_config * 
+<a name="l00110"></a>00110 sinfo_badsky_cfg_create(<span class="keywordtype">void</span>);
+<a name="l00117"></a>00117 <span class="keywordtype">void</span> 
+<a name="l00118"></a>00118 sinfo_badsky_cfg_destroy(badsky_config * sc);
+<a name="l00119"></a>00119 
+<a name="l00120"></a>00120 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__badsky__ini__by__cpl_8c_source.html b/html/sinfo__badsky__ini__by__cpl_8c_source.html
new file mode 100644
index 0000000..400330a
--- /dev/null
+++ b/html/sinfo__badsky__ini__by__cpl_8c_source.html
@@ -0,0 +1,260 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_badsky_ini_by_cpl.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_badsky_ini_by_cpl.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 
+<a name="l00020"></a>00020 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00021"></a>00021 <span class="comment">   </span>
+<a name="l00022"></a>00022 <span class="comment">   File name    :   sinfo_badsky_ini_by_cpl.c</span>
+<a name="l00023"></a>00023 <span class="comment">   Author       :   Andrea Modigliani</span>
+<a name="l00024"></a>00024 <span class="comment">   Created on   :   Jun 16, 2004</span>
+<a name="l00025"></a>00025 <span class="comment">   Description  :   parse cpl input for the search of static bad pixels</span>
+<a name="l00026"></a>00026 <span class="comment"></span>
+<a name="l00027"></a>00027 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00028"></a>00028 
+<a name="l00029"></a>00029 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00031"></a>00031 <span class="preprocessor">#endif</span>
+<a name="l00032"></a>00032 <span class="preprocessor"></span>
+<a name="l00033"></a>00033 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00034"></a>00034 <span class="comment">                                Includes</span>
+<a name="l00035"></a>00035 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00036"></a>00036 <span class="preprocessor">#include <string.h></span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include "sinfo_badsky_ini_by_cpl.h"</span>
+<a name="l00038"></a>00038 <span class="preprocessor">#include "sinfo_raw_types.h"</span>
+<a name="l00039"></a>00039 <span class="preprocessor">#include "sinfo_pro_types.h"</span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include "sinfo_hidden.h"</span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include "sinfo_globals.h"</span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include "sinfo_functions.h"</span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include "sinfo_file_handling.h"</span>
+<a name="l00044"></a>00044 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00045"></a>00045 <span class="comment">                    Functions private to this module</span>
+<a name="l00046"></a>00046 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00047"></a>00047 
+<a name="l00048"></a>00048 <span class="keyword">static</span> <span class="keywordtype">void</span>  
+<a name="l00049"></a>00049 parse_section_frames(badsky_config * cfg, cpl_parameterlist* cpl_cfg, 
+<a name="l00050"></a>00050 cpl_frameset* sof, cpl_frameset** raw, <span class="keywordtype">int</span>* status);
+<a name="l00051"></a>00051 <span class="keyword">static</span> <span class="keywordtype">void</span> 
+<a name="l00052"></a>00052 parse_section_badpix(badsky_config * cfg, cpl_parameterlist* cpl_cfg);
+<a name="l00053"></a>00053 <span class="keyword">static</span> <span class="keywordtype">void</span> 
+<a name="l00054"></a>00054 parse_section_thresh(badsky_config * cfg, cpl_parameterlist* cpl_cfg);
+<a name="l00060"></a>00060 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00061"></a>00061 <span class="comment">                              Function codes</span>
+<a name="l00062"></a>00062 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00074"></a>00074 badsky_config * 
+<a name="l00075"></a>00075 sinfo_parse_cpl_input_badsky(cpl_parameterlist * cpl_cfg, 
+<a name="l00076"></a>00076                                      cpl_frameset* sof,
+<a name="l00077"></a>00077                                      cpl_frameset** raw) 
+<a name="l00078"></a>00078 {
+<a name="l00079"></a>00079   badsky_config    *       cfg ;
+<a name="l00080"></a>00080   <span class="keywordtype">int</span> status = 0;
+<a name="l00081"></a>00081 
+<a name="l00082"></a>00082   cfg = sinfo_badsky_cfg_create();
+<a name="l00083"></a>00083   parse_section_badpix   (cfg, cpl_cfg);
+<a name="l00084"></a>00084   parse_section_thresh   (cfg, cpl_cfg);
+<a name="l00085"></a>00085   parse_section_frames   (cfg, cpl_cfg, sof, raw,&status);
+<a name="l00086"></a>00086   <span class="keywordflow">if</span>(status>0) {
+<a name="l00087"></a>00087     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"parsing cpl input"</span>);
+<a name="l00088"></a>00088     sinfo_badsky_cfg_destroy(cfg);
+<a name="l00089"></a>00089     cfg = NULL ;
+<a name="l00090"></a>00090     <span class="keywordflow">return</span> NULL ;
+<a name="l00091"></a>00091   }
+<a name="l00092"></a>00092   <span class="keywordflow">return</span> cfg ;
+<a name="l00093"></a>00093 
+<a name="l00094"></a>00094 }
+<a name="l00095"></a>00095 
+<a name="l00107"></a>00107 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00108"></a>00108 parse_section_frames(badsky_config   * cfg,
+<a name="l00109"></a>00109                      cpl_parameterlist  * cpl_cfg,
+<a name="l00110"></a>00110                      cpl_frameset * sof,          
+<a name="l00111"></a>00111                      cpl_frameset ** raw,
+<a name="l00112"></a>00112                      <span class="keywordtype">int</span>* status)
+<a name="l00113"></a>00113 {
+<a name="l00114"></a>00114    <span class="keywordtype">int</span>                i=0;
+<a name="l00115"></a>00115    <span class="keywordtype">int</span>                nraw = 0;
+<a name="l00116"></a>00116    <span class="keywordtype">char</span> *          tag=NULL;
+<a name="l00117"></a>00117 
+<a name="l00118"></a>00118    <span class="keywordtype">int</span>  nraw_good = 0;
+<a name="l00119"></a>00119    cpl_frame* frame=NULL;
+<a name="l00120"></a>00120    cpl_parameter *p;     
+<a name="l00121"></a>00121    <span class="keywordtype">char</span> spat_res[FILE_NAME_SZ];
+<a name="l00122"></a>00122    <span class="keywordtype">char</span> lamp_status[FILE_NAME_SZ];
+<a name="l00123"></a>00123    <span class="keywordtype">char</span> band[FILE_NAME_SZ];
+<a name="l00124"></a>00124    <span class="keywordtype">int</span> ins_set=0;
+<a name="l00125"></a>00125 
+<a name="l00126"></a>00126    *raw=cpl_frameset_new();
+<a name="l00127"></a>00127 
+<a name="l00128"></a>00128 
+<a name="l00129"></a>00129    sinfo_contains_frames_type(sof,raw,RAW_SKY);
+<a name="l00130"></a>00130    nraw=cpl_frameset_get_size(*raw);
+<a name="l00131"></a>00131    <span class="keywordflow">if</span> (nraw < 1) {
+<a name="l00132"></a>00132       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Too few (%d) raw frames %s  present in"</span>
+<a name="l00133"></a>00133              <span class="stringliteral">"frameset!Aborting..."</span>,nraw,RAW_SKY);
+<a name="l00134"></a>00134       (*status)++;
+<a name="l00135"></a>00135       <span class="keywordflow">return</span>;
+<a name="l00136"></a>00136    }
+<a name="l00137"></a>00137         
+<a name="l00138"></a>00138    <span class="comment">/* Removed: get "general:infile" read it, check input sinfo_matrix */</span>
+<a name="l00139"></a>00139    <span class="comment">/* Allocate structures to go into the blackboard */</span>
+<a name="l00140"></a>00140    cfg->framelist     = cpl_malloc(nraw * <span class="keyword">sizeof</span>(<span class="keywordtype">char</span>*));
+<a name="l00141"></a>00141 
+<a name="l00142"></a>00142    <span class="comment">/* read input frames */</span>
+<a name="l00143"></a>00143    <span class="keywordflow">for</span> (i=0 ; i<nraw ; i++) {
+<a name="l00144"></a>00144       frame = cpl_frameset_get_frame(*raw,i);
+<a name="l00145"></a>00145       tag = (<span class="keywordtype">char</span>*)cpl_frame_get_tag(frame) ;
+<a name="l00146"></a>00146       <span class="keywordflow">if</span>(sinfo_file_exists((<span class="keywordtype">char</span>*) cpl_frame_get_filename(frame))==1) 
+<a name="l00147"></a>00147     {
+<a name="l00148"></a>00148              <span class="comment">/* Store file name into framelist */</span>
+<a name="l00149"></a>00149              cfg->framelist[i]=cpl_strdup(cpl_frame_get_filename(frame));
+<a name="l00150"></a>00150              nraw_good++;
+<a name="l00151"></a>00151     }
+<a name="l00152"></a>00152    }
+<a name="l00153"></a>00153 
+<a name="l00154"></a>00154    <span class="keywordflow">if</span>(nraw_good<1) {
+<a name="l00155"></a>00155      <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Error: no good raw frame in input, something wrong!"</span>);
+<a name="l00156"></a>00156      (*status)++;
+<a name="l00157"></a>00157      <span class="keywordflow">return</span>;
+<a name="l00158"></a>00158    }
+<a name="l00159"></a>00159 
+<a name="l00160"></a>00160 
+<a name="l00161"></a>00161         <span class="keywordflow">if</span>(NULL != cpl_frameset_find(sof,PRO_MASTER_DARK)) {
+<a name="l00162"></a>00162             frame = cpl_frameset_find(sof,PRO_MASTER_DARK);
+<a name="l00163"></a>00163             strcpy(cfg -> sinfo_dark, 
+<a name="l00164"></a>00164            cpl_strdup(cpl_frame_get_filename(frame)));
+<a name="l00165"></a>00165          } <span class="keywordflow">else</span> {
+<a name="l00166"></a>00166             <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"Frame %s not found!"</span>, PRO_MASTER_DARK);
+<a name="l00167"></a>00167          }
+<a name="l00168"></a>00168 
+<a name="l00169"></a>00169    <span class="comment">/* Copy relevant information into the blackboard */</span>
+<a name="l00170"></a>00170    cfg->nframes         = nraw_good ;
+<a name="l00171"></a>00171 
+<a name="l00172"></a>00172    <span class="comment">/* Output */</span>
+<a name="l00173"></a>00173    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.bp_sky.out_filename"</span>);
+<a name="l00174"></a>00174    strcpy(cfg -> outName, cpl_parameter_get_string(p));
+<a name="l00175"></a>00175 
+<a name="l00176"></a>00176    frame = cpl_frameset_get_frame(*raw,0);
+<a name="l00177"></a>00177    sinfo_get_spatial_res(frame,spat_res);
+<a name="l00178"></a>00178  
+<a name="l00179"></a>00179 
+<a name="l00180"></a>00180    <span class="keywordflow">switch</span>(sinfo_frame_is_on(frame)) 
+<a name="l00181"></a>00181      {
+<a name="l00182"></a>00182    <span class="keywordflow">case</span> 0: 
+<a name="l00183"></a>00183       strcpy(lamp_status,<span class="stringliteral">"on"</span>);
+<a name="l00184"></a>00184       <span class="keywordflow">break</span>;
+<a name="l00185"></a>00185     <span class="keywordflow">case</span> 1: 
+<a name="l00186"></a>00186       strcpy(lamp_status,<span class="stringliteral">"off"</span>);
+<a name="l00187"></a>00187       <span class="keywordflow">break</span>;
+<a name="l00188"></a>00188     <span class="keywordflow">case</span> -1:
+<a name="l00189"></a>00189       strcpy(lamp_status,<span class="stringliteral">"undefined"</span>);
+<a name="l00190"></a>00190       <span class="keywordflow">break</span>;
+<a name="l00191"></a>00191     <span class="keywordflow">default</span>: 
+<a name="l00192"></a>00192       strcpy(lamp_status,<span class="stringliteral">"undefined"</span>);
+<a name="l00193"></a>00193       <span class="keywordflow">break</span>;
+<a name="l00194"></a>00194      }
+<a name="l00195"></a>00195 
+<a name="l00196"></a>00196    sinfo_get_band(frame,band);
+<a name="l00197"></a>00197    sinfo_msg(<span class="stringliteral">"Spatial resolution: %s lamp status: %s band: %s \n"</span>,
+<a name="l00198"></a>00198                      spat_res,              lamp_status,    band);
+<a name="l00199"></a>00199 
+<a name="l00200"></a>00200 
+<a name="l00201"></a>00201    sinfo_get_ins_set(band,&ins_set);
+<a name="l00202"></a>00202    <span class="keywordflow">return</span>;
+<a name="l00203"></a>00203 
+<a name="l00204"></a>00204 }
+<a name="l00205"></a>00205 
+<a name="l00214"></a>00214 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00215"></a>00215 parse_section_badpix(badsky_config    * cfg, cpl_parameterlist *   cpl_cfg)
+<a name="l00216"></a>00216 {
+<a name="l00217"></a>00217    cpl_parameter *p;     
+<a name="l00218"></a>00218 
+<a name="l00219"></a>00219    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.bp_sky.sigma_factor"</span>);
+<a name="l00220"></a>00220    cfg -> sigmaFactor = cpl_parameter_get_double(p);
+<a name="l00221"></a>00221 
+<a name="l00222"></a>00222    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.bp_sky.method_index"</span>);
+<a name="l00223"></a>00223    cfg -> methodInd = cpl_parameter_get_int(p);
+<a name="l00224"></a>00224 
+<a name="l00225"></a>00225    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.bp_sky.factor"</span>);
+<a name="l00226"></a>00226    cfg -> factor = cpl_parameter_get_double(p);
+<a name="l00227"></a>00227 
+<a name="l00228"></a>00228    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.bp_sky.iterations"</span>);
+<a name="l00229"></a>00229    cfg -> iterations = cpl_parameter_get_int(p);
+<a name="l00230"></a>00230 
+<a name="l00231"></a>00231    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.bp_sky.low_rejection"</span>);
+<a name="l00232"></a>00232    cfg -> loReject = cpl_parameter_get_double(p);
+<a name="l00233"></a>00233 
+<a name="l00234"></a>00234    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.bp_sky.high_rejection"</span>);
+<a name="l00235"></a>00235    cfg -> hiReject = cpl_parameter_get_double(p);
+<a name="l00236"></a>00236 
+<a name="l00237"></a>00237    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.bp_sky.llx"</span>);
+<a name="l00238"></a>00238    cfg -> llx = cpl_parameter_get_int(p);
+<a name="l00239"></a>00239 
+<a name="l00240"></a>00240    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.bp_sky.lly"</span>);
+<a name="l00241"></a>00241    cfg -> lly = cpl_parameter_get_int(p);
+<a name="l00242"></a>00242 
+<a name="l00243"></a>00243    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.bp_sky.urx"</span>);
+<a name="l00244"></a>00244    cfg -> urx = cpl_parameter_get_int(p);
+<a name="l00245"></a>00245 
+<a name="l00246"></a>00246    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.bp_sky.ury"</span>);
+<a name="l00247"></a>00247    cfg -> ury = cpl_parameter_get_int(p);
+<a name="l00248"></a>00248 
+<a name="l00249"></a>00249 }
+<a name="l00250"></a>00250 
+<a name="l00259"></a>00259 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00260"></a>00260 parse_section_thresh(badsky_config    * cfg, cpl_parameterlist *   cpl_cfg)
+<a name="l00261"></a>00261 {
+<a name="l00262"></a>00262    cpl_parameter *p;     
+<a name="l00263"></a>00263 
+<a name="l00264"></a>00264    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.bp_sky.threshold_index"</span>);
+<a name="l00265"></a>00265    cfg -> threshInd  = cpl_parameter_get_bool(p);
+<a name="l00266"></a>00266 
+<a name="l00267"></a>00267    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.bp_sky.mean_factor"</span>);
+<a name="l00268"></a>00268    cfg -> meanfactor = cpl_parameter_get_double(p);
+<a name="l00269"></a>00269 
+<a name="l00270"></a>00270 
+<a name="l00271"></a>00271    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.bp_sky.min_cut"</span>);
+<a name="l00272"></a>00272    cfg -> mincut = cpl_parameter_get_double(p);
+<a name="l00273"></a>00273 
+<a name="l00274"></a>00274    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.bp_sky.max_cut"</span>);
+<a name="l00275"></a>00275    cfg -> maxcut = cpl_parameter_get_double(p);
+<a name="l00276"></a>00276 
+<a name="l00277"></a>00277 }
+<a name="l00278"></a>00278 
+<a name="l00286"></a>00286 <span class="keywordtype">void</span>
+<a name="l00287"></a>00287 sinfo_badsky_free(badsky_config * cfg)
+<a name="l00288"></a>00288 {  
+<a name="l00289"></a>00289   cpl_free(cfg->framelist);
+<a name="l00290"></a>00290   sinfo_badsky_cfg_destroy(cfg);
+<a name="l00291"></a>00291  
+<a name="l00292"></a>00292   <span class="keywordflow">return</span>;
+<a name="l00293"></a>00293 
+<a name="l00294"></a>00294 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__badsky__ini__by__cpl_8h_source.html b/html/sinfo__badsky__ini__by__cpl_8h_source.html
new file mode 100644
index 0000000..58d8597
--- /dev/null
+++ b/html/sinfo__badsky__ini__by__cpl_8h_source.html
@@ -0,0 +1,66 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_badsky_ini_by_cpl.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_badsky_ini_by_cpl.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name    :   sinfo_badnorm_ini_by_cpl.h</span>
+<a name="l00022"></a>00022 <span class="comment">   Author       :   Andrea Modigliani</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on   :   Jun 16, 2004</span>
+<a name="l00024"></a>00024 <span class="comment">   Description  :   parse cpl input for the search for static bad pixels</span>
+<a name="l00025"></a>00025 <span class="comment"></span>
+<a name="l00026"></a>00026 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00027"></a>00027 <span class="preprocessor">#ifndef SINFO_BADSKY_INI_BY_CPL_H</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_BADSKY_INI_BY_CPL_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00030"></a>00030 <span class="comment">                                Includes</span>
+<a name="l00031"></a>00031 <span class="comment">---------------------------------------------------------------------------*/</span>
+<a name="l00032"></a>00032 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include "sinfo_badsky_cfg.h"</span>
+<a name="l00034"></a>00034 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00035"></a>00035 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00036"></a>00036 <span class="comment">                                Defines</span>
+<a name="l00037"></a>00037 <span class="comment">---------------------------------------------------------------------------*/</span>
+<a name="l00038"></a>00038 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00039"></a>00039 <span class="comment">                             Function prototypes </span>
+<a name="l00040"></a>00040 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00041"></a>00041 
+<a name="l00042"></a>00042 badsky_config * 
+<a name="l00043"></a>00043 sinfo_parse_cpl_input_badsky(cpl_parameterlist * cpl_cfg, 
+<a name="l00044"></a>00044                              cpl_frameset* sof, 
+<a name="l00045"></a>00045                              cpl_frameset** raw);
+<a name="l00046"></a>00046 
+<a name="l00047"></a>00047 <span class="keywordtype">void</span> 
+<a name="l00048"></a>00048 sinfo_badsky_free(badsky_config * cfg);
+<a name="l00049"></a>00049 
+<a name="l00050"></a>00050 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__balance_8c_source.html b/html/sinfo__balance_8c_source.html
new file mode 100644
index 0000000..0df5afa
--- /dev/null
+++ b/html/sinfo__balance_8c_source.html
@@ -0,0 +1,146 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_balance.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_balance.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00020"></a>00020 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00021"></a>00021 <span class="preprocessor">#endif</span>
+<a name="l00022"></a>00022 <span class="preprocessor"></span><span class="preprocessor">#include "sinfo_solve_poly_root.h"</span>
+<a name="l00023"></a>00023 
+<a name="l00024"></a>00024 
+<a name="l00025"></a>00025 <span class="preprocessor">#define RADIX 2</span>
+<a name="l00026"></a>00026 <span class="preprocessor"></span><span class="preprocessor">#define RADIX2 (RADIX*RADIX)</span>
+<a name="l00027"></a>00027 <span class="preprocessor"></span>
+<a name="l00042"></a>00042 <span class="keywordtype">void</span>
+<a name="l00043"></a>00043 sinfo_balance_companion_matrix (<span class="keywordtype">double</span> *m, <span class="keywordtype">size_t</span> nc)
+<a name="l00044"></a>00044 {
+<a name="l00045"></a>00045   <span class="keywordtype">int</span> not_converged = 1;
+<a name="l00046"></a>00046 
+<a name="l00047"></a>00047   <span class="keywordtype">double</span> row_norm = 0;
+<a name="l00048"></a>00048   <span class="keywordtype">double</span> col_norm = 0;
+<a name="l00049"></a>00049 
+<a name="l00050"></a>00050   <span class="keywordflow">while</span> (not_converged)
+<a name="l00051"></a>00051     {
+<a name="l00052"></a>00052       <span class="keywordtype">size_t</span> i, j;
+<a name="l00053"></a>00053       <span class="keywordtype">double</span> g, f, s;
+<a name="l00054"></a>00054 
+<a name="l00055"></a>00055       not_converged = 0;
+<a name="l00056"></a>00056 
+<a name="l00057"></a>00057       <span class="keywordflow">for</span> (i = 0; i < nc; i++)
+<a name="l00058"></a>00058     {
+<a name="l00059"></a>00059       <span class="comment">/* column norm, excluding the diagonal */</span>
+<a name="l00060"></a>00060 
+<a name="l00061"></a>00061       <span class="keywordflow">if</span> (i != nc - 1)
+<a name="l00062"></a>00062         {
+<a name="l00063"></a>00063           col_norm = fabs (MAT (m, i + 1, i, nc));
+<a name="l00064"></a>00064         }
+<a name="l00065"></a>00065       <span class="keywordflow">else</span>
+<a name="l00066"></a>00066         {
+<a name="l00067"></a>00067           col_norm = 0;
+<a name="l00068"></a>00068 
+<a name="l00069"></a>00069           <span class="keywordflow">for</span> (j = 0; j < nc - 1; j++)
+<a name="l00070"></a>00070         {
+<a name="l00071"></a>00071           col_norm += fabs (MAT (m, j, nc - 1, nc));
+<a name="l00072"></a>00072         }
+<a name="l00073"></a>00073         }
+<a name="l00074"></a>00074 
+<a name="l00075"></a>00075       <span class="comment">/* row norm, excluding the diagonal */</span>
+<a name="l00076"></a>00076 
+<a name="l00077"></a>00077       <span class="keywordflow">if</span> (i == 0)
+<a name="l00078"></a>00078         {
+<a name="l00079"></a>00079           row_norm = fabs (MAT (m, 0, nc - 1, nc));
+<a name="l00080"></a>00080         }
+<a name="l00081"></a>00081       <span class="keywordflow">else</span> <span class="keywordflow">if</span> (i == nc - 1)
+<a name="l00082"></a>00082         {
+<a name="l00083"></a>00083           row_norm = fabs (MAT (m, i, i - 1, nc));
+<a name="l00084"></a>00084         }
+<a name="l00085"></a>00085       <span class="keywordflow">else</span>
+<a name="l00086"></a>00086         {
+<a name="l00087"></a>00087           row_norm = (fabs (MAT (m, i, i - 1, nc)) 
+<a name="l00088"></a>00088                           + fabs (MAT (m, i, nc - 1, nc)));
+<a name="l00089"></a>00089         }
+<a name="l00090"></a>00090 
+<a name="l00091"></a>00091       <span class="keywordflow">if</span> (col_norm == 0 || row_norm == 0)
+<a name="l00092"></a>00092         {
+<a name="l00093"></a>00093           <span class="keywordflow">continue</span>;
+<a name="l00094"></a>00094         }
+<a name="l00095"></a>00095 
+<a name="l00096"></a>00096       g = row_norm / RADIX;
+<a name="l00097"></a>00097       f = 1;
+<a name="l00098"></a>00098       s = col_norm + row_norm;
+<a name="l00099"></a>00099 
+<a name="l00100"></a>00100       <span class="keywordflow">while</span> (col_norm < g)
+<a name="l00101"></a>00101         {
+<a name="l00102"></a>00102           f *= RADIX;
+<a name="l00103"></a>00103           col_norm *= RADIX2;
+<a name="l00104"></a>00104         }
+<a name="l00105"></a>00105 
+<a name="l00106"></a>00106       g = row_norm * RADIX;
+<a name="l00107"></a>00107 
+<a name="l00108"></a>00108       <span class="keywordflow">while</span> (col_norm > g)
+<a name="l00109"></a>00109         {
+<a name="l00110"></a>00110           f /= RADIX;
+<a name="l00111"></a>00111           col_norm /= RADIX2;
+<a name="l00112"></a>00112         }
+<a name="l00113"></a>00113 
+<a name="l00114"></a>00114       <span class="keywordflow">if</span> ((row_norm + col_norm) < 0.95 * s * f)
+<a name="l00115"></a>00115         {
+<a name="l00116"></a>00116           not_converged = 1;
+<a name="l00117"></a>00117 
+<a name="l00118"></a>00118           g = 1 / f;
+<a name="l00119"></a>00119 
+<a name="l00120"></a>00120           <span class="keywordflow">if</span> (i == 0)
+<a name="l00121"></a>00121         {
+<a name="l00122"></a>00122           MAT (m, 0, nc - 1, nc) *= g;
+<a name="l00123"></a>00123         }
+<a name="l00124"></a>00124           <span class="keywordflow">else</span>
+<a name="l00125"></a>00125         {
+<a name="l00126"></a>00126           MAT (m, i, i - 1, nc) *= g;
+<a name="l00127"></a>00127           MAT (m, i, nc - 1, nc) *= g;
+<a name="l00128"></a>00128         }
+<a name="l00129"></a>00129 
+<a name="l00130"></a>00130           <span class="keywordflow">if</span> (i == nc - 1)
+<a name="l00131"></a>00131         {
+<a name="l00132"></a>00132           <span class="keywordflow">for</span> (j = 0; j < nc; j++)
+<a name="l00133"></a>00133             {
+<a name="l00134"></a>00134               MAT (m, j, i, nc) *= f;
+<a name="l00135"></a>00135             }
+<a name="l00136"></a>00136         }
+<a name="l00137"></a>00137           <span class="keywordflow">else</span>
+<a name="l00138"></a>00138         {
+<a name="l00139"></a>00139           MAT (m, i + 1, i, nc) *= f;
+<a name="l00140"></a>00140         }
+<a name="l00141"></a>00141         }
+<a name="l00142"></a>00142     }
+<a name="l00143"></a>00143     }
+<a name="l00144"></a>00144 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__baryvel_8c_source.html b/html/sinfo__baryvel_8c_source.html
new file mode 100644
index 0000000..53786f0
--- /dev/null
+++ b/html/sinfo__baryvel_8c_source.html
@@ -0,0 +1,1041 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_baryvel.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_baryvel.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*                                                                            *</span>
+<a name="l00002"></a>00002 <span class="comment"> *   This file is part of the ESO SINFONI Pipeline                            *</span>
+<a name="l00003"></a>00003 <span class="comment"> *   Copyright (C) 2004,2005 European Southern Observatory                    *</span>
+<a name="l00004"></a>00004 <span class="comment"> *                                                                            *</span>
+<a name="l00005"></a>00005 <span class="comment"> *   This library is free software; you can redistribute it and/or modify     *</span>
+<a name="l00006"></a>00006 <span class="comment"> *   it under the terms of the GNU General Public License as published by     *</span>
+<a name="l00007"></a>00007 <span class="comment"> *   the Free Software Foundation; either version 2 of the License, or        *</span>
+<a name="l00008"></a>00008 <span class="comment"> *   (at your option) any later version.                                      *</span>
+<a name="l00009"></a>00009 <span class="comment"> *                                                                            *</span>
+<a name="l00010"></a>00010 <span class="comment"> *   This program is distributed in the hope that it will be useful,          *</span>
+<a name="l00011"></a>00011 <span class="comment"> *   but WITHOUT ANY WARRANTY; without even the implied warranty of           *</span>
+<a name="l00012"></a>00012 <span class="comment"> *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *</span>
+<a name="l00013"></a>00013 <span class="comment"> *   GNU General Public License for more details.                             *</span>
+<a name="l00014"></a>00014 <span class="comment"> *                                                                            *</span>
+<a name="l00015"></a>00015 <span class="comment"> *   You should have received a copy of the GNU General Public License        *</span>
+<a name="l00016"></a>00016 <span class="comment"> *   along with this program; if not, write to the Free Software              *</span>
+<a name="l00017"></a>00017 <span class="comment"> *   Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA     *</span>
+<a name="l00018"></a>00018 <span class="comment"> *                                                                            */</span>
+<a name="l00019"></a>00019 
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2012/03/02 08:42:20 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.3 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Log: sinfo_baryvel.c,v $</span>
+<a name="l00026"></a>00026 <span class="comment"> * Revision 1.3  2012/03/02 08:42:20  amodigli</span>
+<a name="l00027"></a>00027 <span class="comment"> * fixed some typos on doxygen</span>
+<a name="l00028"></a>00028 <span class="comment"> *</span>
+<a name="l00029"></a>00029 <span class="comment"> * Revision 1.2  2009/04/28 11:42:18  amodigli</span>
+<a name="l00030"></a>00030 <span class="comment"> * now return cpl_error_code</span>
+<a name="l00031"></a>00031 <span class="comment"> *</span>
+<a name="l00032"></a>00032 <span class="comment"> * Revision 1.1  2009/01/02 08:27:58  amodigli</span>
+<a name="l00033"></a>00033 <span class="comment"> * added to repository</span>
+<a name="l00034"></a>00034 <span class="comment"> *</span>
+<a name="l00035"></a>00035 <span class="comment"> * Revision 1.8  2007/06/06 08:17:33  amodigli</span>
+<a name="l00036"></a>00036 <span class="comment"> * replace tab with 4 spaces</span>
+<a name="l00037"></a>00037 <span class="comment"> *</span>
+<a name="l00038"></a>00038 <span class="comment"> */</span>
+<a name="l00039"></a>00039 
+<a name="l00040"></a>00040 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00041"></a>00041 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00042"></a>00042 <span class="preprocessor">#endif</span>
+<a name="l00043"></a>00043 <span class="preprocessor"></span>
+<a name="l00044"></a>00044 
+<a name="l00046"></a>00046 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00060"></a>00060 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00061"></a>00061 
+<a name="l00062"></a>00062 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00063"></a>00063 <span class="comment">  Includes</span>
+<a name="l00064"></a>00064 <span class="comment">  ---------------------------------------------------------------------------*/</span>
+<a name="l00065"></a>00065 
+<a name="l00066"></a>00066 <span class="preprocessor">#include <sinfo_baryvel.h></span>
+<a name="l00067"></a>00067 
+<a name="l00068"></a>00068 <span class="preprocessor">#include <sinfo_pfits.h></span>
+<a name="l00069"></a>00069 <span class="preprocessor">#include <sinfo_utils.h></span>
+<a name="l00070"></a>00070 <span class="preprocessor">#include <sinfo_error.h></span>
+<a name="l00071"></a>00071 <span class="preprocessor">#include <sinfo_msg.h></span>
+<a name="l00072"></a>00072 <span class="preprocessor">#include <sinfo_functions.h></span>
+<a name="l00073"></a>00073 
+<a name="l00074"></a>00074 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00075"></a>00075 
+<a name="l00076"></a>00076 <span class="preprocessor">#include <math.h></span>
+<a name="l00077"></a>00077 
+<a name="l00078"></a>00078 <span class="preprocessor">#define H_GEOLAT "ESO TEL GEOLAT"</span>
+<a name="l00079"></a>00079 <span class="preprocessor"></span><span class="preprocessor">#define H_GEOLON "ESO TEL GEOLON"</span>
+<a name="l00080"></a>00080 <span class="preprocessor"></span><span class="preprocessor">#define H_UTC "UTC"</span>
+<a name="l00081"></a>00081 <span class="preprocessor"></span>
+<a name="l00082"></a>00082 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00083"></a>00083 <span class="comment">  Local functions</span>
+<a name="l00084"></a>00084 <span class="comment">  ---------------------------------------------------------------------------*/</span>
+<a name="l00085"></a>00085 
+<a name="l00086"></a>00086 <span class="keyword">static</span> <span class="keywordtype">double</span> sinfo_pfits_get_geolat(<span class="keyword">const</span> cpl_propertylist * plist);
+<a name="l00087"></a>00087 <span class="keyword">static</span> <span class="keywordtype">double</span> sinfo_pfits_get_geolon(<span class="keyword">const</span> cpl_propertylist * plist);
+<a name="l00088"></a>00088 <span class="keyword">static</span> <span class="keywordtype">double</span> sinfo_pfits_get_utc(<span class="keyword">const</span> cpl_propertylist * plist);
+<a name="l00089"></a>00089 
+<a name="l00090"></a>00090 
+<a name="l00091"></a>00091 
+<a name="l00092"></a>00092 <span class="keyword">static</span> <span class="keywordtype">void</span> deg2dms(<span class="keywordtype">double</span> in_val, 
+<a name="l00093"></a>00093             <span class="keywordtype">double</span> *degs,
+<a name="l00094"></a>00094             <span class="keywordtype">double</span> *minutes,
+<a name="l00095"></a>00095             <span class="keywordtype">double</span> *seconds);
+<a name="l00096"></a>00096 
+<a name="l00097"></a>00097 <span class="keyword">static</span> <span class="keywordtype">void</span> deg2hms(<span class="keywordtype">double</span> in_val, 
+<a name="l00098"></a>00098             <span class="keywordtype">double</span> *hour,
+<a name="l00099"></a>00099             <span class="keywordtype">double</span> *min,
+<a name="l00100"></a>00100             <span class="keywordtype">double</span> *sec);
+<a name="l00101"></a>00101 
+<a name="l00102"></a>00102 <span class="keyword">static</span> <span class="keywordtype">void</span> compxy(<span class="keywordtype">double</span> inputr[19], <span class="keywordtype">char</span> inputc[4],
+<a name="l00103"></a>00103            <span class="keywordtype">double</span> outputr[4],
+<a name="l00104"></a>00104            <span class="keywordtype">double</span> utr, <span class="keywordtype">double</span> mod_juldat);
+<a name="l00105"></a>00105 
+<a name="l00106"></a>00106 <span class="keyword">static</span> <span class="keywordtype">void</span> barvel(<span class="keywordtype">double</span> DJE, <span class="keywordtype">double</span> DEQ,
+<a name="l00107"></a>00107            <span class="keywordtype">double</span> DVELH[4], <span class="keywordtype">double</span> DVELB[4]);
+<a name="l00108"></a>00108 
+<a name="l00109"></a>00109 
+<a name="l00110"></a>00110 
+<a name="l00111"></a>00111 
+<a name="l00112"></a>00112 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00113"></a>00113 
+<a name="l00114"></a>00114 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00120"></a>00120 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00121"></a>00121 <span class="keyword">static</span> <span class="keywordtype">double</span> sinfo_pfits_get_geolat(<span class="keyword">const</span> cpl_propertylist * plist)
+<a name="l00122"></a>00122 {
+<a name="l00123"></a>00123     <span class="keywordtype">double</span> returnvalue = 0;
+<a name="l00124"></a>00124     
+<a name="l00125"></a>00125     check(returnvalue=cpl_propertylist_get_double(plist, H_GEOLAT), 
+<a name="l00126"></a>00126        <span class="stringliteral">"Error reading keyword '%s'"</span>, H_GEOLAT);
+<a name="l00127"></a>00127     
+<a name="l00128"></a>00128   cleanup:
+<a name="l00129"></a>00129     <span class="keywordflow">return</span> returnvalue;
+<a name="l00130"></a>00130 }
+<a name="l00131"></a>00131 
+<a name="l00132"></a>00132 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00138"></a>00138 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00139"></a>00139 <span class="keyword">static</span> <span class="keywordtype">double</span> sinfo_pfits_get_geolon(<span class="keyword">const</span> cpl_propertylist * plist)
+<a name="l00140"></a>00140 {
+<a name="l00141"></a>00141     <span class="keywordtype">double</span> returnvalue = 0;
+<a name="l00142"></a>00142 
+<a name="l00143"></a>00143     check(returnvalue=cpl_propertylist_get_double(plist, H_GEOLON), 
+<a name="l00144"></a>00144        <span class="stringliteral">"Error reading keyword '%s'"</span>, H_GEOLON);
+<a name="l00145"></a>00145       
+<a name="l00146"></a>00146   cleanup:
+<a name="l00147"></a>00147     <span class="keywordflow">return</span> returnvalue;
+<a name="l00148"></a>00148 }
+<a name="l00149"></a>00149 
+<a name="l00150"></a>00150 
+<a name="l00151"></a>00151 
+<a name="l00152"></a>00152 
+<a name="l00153"></a>00153 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00159"></a>00159 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00160"></a>00160 <span class="keyword">static</span> <span class="keywordtype">double</span> sinfo_pfits_get_utc(<span class="keyword">const</span> cpl_propertylist * plist)
+<a name="l00161"></a>00161 {
+<a name="l00162"></a>00162     <span class="keywordtype">double</span> returnvalue = 0;
+<a name="l00163"></a>00163 
+<a name="l00164"></a>00164     check(returnvalue=cpl_propertylist_get_double(plist, H_UTC), 
+<a name="l00165"></a>00165        <span class="stringliteral">"Error reading keyword '%s'"</span>, H_UTC);
+<a name="l00166"></a>00166      
+<a name="l00167"></a>00167   cleanup:
+<a name="l00168"></a>00168     <span class="keywordflow">return</span> returnvalue;
+<a name="l00169"></a>00169 }
+<a name="l00170"></a>00170 
+<a name="l00171"></a>00171 
+<a name="l00172"></a>00172 
+<a name="l00173"></a>00173 <span class="preprocessor">#if 0   </span><span class="comment">/* Not used / needed.</span>
+<a name="l00174"></a>00174 <span class="comment">       We simply get the julian date from the input FITS header */</span>
+<a name="l00175"></a>00175 
+<a name="l00176"></a>00176 <span class="comment">//      SUBROUTINE JULDAT(INDATE,UTR,JD)</span>
+<a name="l00177"></a>00177 <span class="comment">//C++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++</span>
+<a name="l00178"></a>00178 <span class="comment">//C</span>
+<a name="l00179"></a>00179 <span class="comment">//C.IDENTIFICATION</span>
+<a name="l00180"></a>00180 <span class="comment">//C  FORTRAN subroutine                    JULDAT     version 1.0       870102</span>
+<a name="l00181"></a>00181 <span class="comment">//C  original coding:                      D. Gillet        ESO - Garching</span>
+<a name="l00182"></a>00182 <span class="comment">//C  variables renamed and restructured:   D. Baade         ST-ECF, Garching</span>
+<a name="l00183"></a>00183 <span class="comment">//C</span>
+<a name="l00184"></a>00184 <span class="comment">//C.KEYWORDS</span>
+<a name="l00185"></a>00185 <span class="comment">//C  geocentric Julian date</span>
+<a name="l00186"></a>00186 <span class="comment">//C</span>
+<a name="l00187"></a>00187 <span class="comment">//C.PURPOSE</span>
+<a name="l00188"></a>00188 <span class="comment">//C  calculate geocentric Julian date for any civil date (time in UT)</span>
+<a name="l00189"></a>00189 <span class="comment">//C</span>
+<a name="l00190"></a>00190 <span class="comment">//C.ALGORITHM</span>
+<a name="l00191"></a>00191 <span class="comment">//C adapted from MEEUS J.,1980, ASTRONOMICAL FORMULAE FOR CALCULATORS</span>
+<a name="l00192"></a>00192 <span class="comment">//C</span>
+<a name="l00193"></a>00193 <span class="comment">//C.INPUT/OUTPUT</span>
+<a name="l00194"></a>00194 <span class="comment">//C the following are passed from and to the calling program:</span>
+<a name="l00195"></a>00195 <span class="comment">//C  INDATE(3)    :         civil date as year,month,day OR year.fraction</span>
+<a name="l00196"></a>00196 <span class="comment">//C  UT           :         universal time expressed in real hours</span>
+<a name="l00197"></a>00197 <span class="comment">//C  JD           :         real geocentric Julian date</span>
+<a name="l00198"></a>00198 <span class="comment">//C</span>
+<a name="l00199"></a>00199 <span class="comment">//C.REVISIONS</span>
+<a name="l00200"></a>00200 <span class="comment">//C made to accept also REAL dates         D. Baade             910408</span>
+<a name="l00201"></a>00201 <span class="comment">//C</span>
+<a name="l00202"></a>00202 <span class="comment">//C---------------------------------------------------------------------------</span>
+<a name="l00203"></a>00203 <span class="comment">//C</span>
+<a name="l00204"></a>00204 
+<a name="l00205"></a>00205 <span class="keyword">static</span> <span class="keywordtype">void</span> 
+<a name="l00206"></a>00206 juldat(<span class="keywordtype">double</span> *INDATE,
+<a name="l00207"></a>00207        <span class="keywordtype">double</span> UTR,
+<a name="l00208"></a>00208        <span class="keywordtype">double</span> *JD)
+<a name="l00209"></a>00209 {
+<a name="l00210"></a>00210   <span class="keywordtype">double</span> UT;
+<a name="l00211"></a>00211 
+<a name="l00212"></a>00212   <span class="keywordtype">int</span> DATE[4];
+<a name="l00213"></a>00213 
+<a name="l00214"></a>00214   UT=UTR / 24.0;
+<a name="l00215"></a>00215 
+<a name="l00216"></a>00216   <span class="comment">/*</span>
+<a name="l00217"></a>00217 <span class="comment">    CHECK FORMAT OF DATE: may be either year,month,date OR year.fraction,0,0 </span>
+<a name="l00218"></a>00218 <span class="comment">    (Note that the fraction of the year must NOT include fractions of a day.)</span>
+<a name="l00219"></a>00219 <span class="comment">    For all other formats exit and terminate also calling command sequence.</span>
+<a name="l00220"></a>00220 <span class="comment">  </span>
+<a name="l00221"></a>00221 <span class="comment">    IF ((INDATE(1)-INT(INDATE(1))).GT.1.0E-6) THEN </span>
+<a name="l00222"></a>00222 <span class="comment">    IF ((INDATE(2).GT.1.0E-6).OR.(INDATE(3).GT.1.0E-6)) </span>
+<a name="l00223"></a>00223 <span class="comment">    +       CALL   STETER(1,'Error: Date was entered in wrong format.')</span>
+<a name="l00224"></a>00224 <span class="comment"></span>
+<a name="l00225"></a>00225 <span class="comment">    copy date input buffer copy to other buffer so that calling program </span>
+<a name="l00226"></a>00226 <span class="comment">    does not notice any changes</span>
+<a name="l00227"></a>00227 <span class="comment"></span>
+<a name="l00228"></a>00228 <span class="comment">    FIRST CASE: format was year.fraction</span>
+<a name="l00229"></a>00229 <span class="comment"></span>
+<a name="l00230"></a>00230 <span class="comment">    DATE(1)=INT(INDATE(1))</span>
+<a name="l00231"></a>00231 <span class="comment">    FRAC=INDATE(1)-DATE(1)</span>
+<a name="l00232"></a>00232 <span class="comment">    DATE(2)=1</span>
+<a name="l00233"></a>00233 <span class="comment">    DATE(3)=1</span>
+<a name="l00234"></a>00234 <span class="comment">    ELSE</span>
+<a name="l00235"></a>00235 <span class="comment">  </span>
+<a name="l00236"></a>00236 <span class="comment">    SECOND CASE: format was year,month,day</span>
+<a name="l00237"></a>00237 <span class="comment">  */</span>
+<a name="l00238"></a>00238 
+<a name="l00239"></a>00239   DATE[1]=sinfo_round_double(INDATE[1]);
+<a name="l00240"></a>00240 
+<a name="l00241"></a>00241   FRAC = 0;
+<a name="l00242"></a>00242 
+<a name="l00243"></a>00243   DATE[2]=sinfo_round_double(INDATE[2]);
+<a name="l00244"></a>00244 
+<a name="l00245"></a>00245   DATE[3]=sinfo_round_double(INDATE[3]);
+<a name="l00246"></a>00246 
+<a name="l00247"></a>00247   <span class="keywordflow">if</span> ((DATE[2] == 0) &&  (DATE[3] == 0)) {
+<a name="l00248"></a>00248 
+<a name="l00249"></a>00249     DATE[2]=1;
+<a name="l00250"></a>00250 
+<a name="l00251"></a>00251     DATE[3]=1;
+<a name="l00252"></a>00252 
+<a name="l00253"></a>00253   }
+<a name="l00254"></a>00254 
+<a name="l00255"></a>00255   <span class="comment">/*</span>
+<a name="l00256"></a>00256 <span class="comment">    from here on, the normal procedure applies which is based on the </span>
+<a name="l00257"></a>00257 <span class="comment">    format year,month,day:</span>
+<a name="l00258"></a>00258 <span class="comment">  */</span>
+<a name="l00259"></a>00259   <span class="keywordflow">if</span> (DATE[2] > 2) {
+<a name="l00260"></a>00260     YP=DATE[1];
+<a name="l00261"></a>00261     P=DATE[2];
+<a name="l00262"></a>00262   } <span class="keywordflow">else</span> {
+<a name="l00263"></a>00263     YP=DATE[1]-1;
+<a name="l00264"></a>00264     P=DATE(2)+12.0;
+<a name="l00265"></a>00265   }
+<a name="l00266"></a>00266 
+<a name="l00267"></a>00267   C = DATE[1] + DATE[2]*1.E-2 + DATE[3]*1.E-4 + UT*1.E-6;
+<a name="l00268"></a>00268 
+<a name="l00269"></a>00269   <span class="keywordflow">if</span> (C  >   1582.1015E0) {
+<a name="l00270"></a>00270     IA=(int) (YP/100.D0);
+<a name="l00271"></a>00271     A=IA;
+<a name="l00272"></a>00272     IB=2-IA+((int)(A/4.D0));
+<a name="l00273"></a>00273   } <span class="keywordflow">else</span> {
+<a name="l00274"></a>00274     IB=0;
+<a name="l00275"></a>00275   }
+<a name="l00276"></a>00276 
+<a name="l00277"></a>00277   *JD = ((int) (365.25E0*YP)) + ((<span class="keywordtype">int</span>)(30.6001D0*(P+1.D0))) + DATE[3] + UT
+<a name="l00278"></a>00278     + IB + 1720994.5E0;
+<a name="l00279"></a>00279 
+<a name="l00280"></a>00280   <span class="comment">/*</span>
+<a name="l00281"></a>00281 <span class="comment">    finally, take into account fraction of year (if any), respect leap</span>
+<a name="l00282"></a>00282 <span class="comment">    year conventions</span>
+<a name="l00283"></a>00283 <span class="comment">  */</span>
+<a name="l00284"></a>00284   <span class="keywordflow">if</span> (FRAC > 1.0E-6) {
+<a name="l00285"></a>00285     ND=365;
+<a name="l00286"></a>00286 
+<a name="l00287"></a>00287     IF (C >= 1582.1015E0) {
+<a name="l00288"></a>00288       IC = DATE[1] % 4;
+<a name="l00289"></a>00289       <span class="keywordflow">if</span> (IC == 0) {
+<a name="l00290"></a>00290         ND=366;
+<a name="l00291"></a>00291         IC = DATE[1] % 100;
+<a name="l00292"></a>00292         <span class="keywordflow">if</span> (IC == 0) {
+<a name="l00293"></a>00293       IC = DATE[1] % 400;
+<a name="l00294"></a>00294       <span class="keywordflow">if</span> (IC != 0) ND=365;
+<a name="l00295"></a>00295         }
+<a name="l00296"></a>00296       }
+<a name="l00297"></a>00297     }
+<a name="l00298"></a>00298 
+<a name="l00299"></a>00299     <span class="keywordflow">if</span> (fabs(FRAC*ND-sinfo_round_double(FRAC*ND)) > 0.3) {
+<a name="l00300"></a>00300       <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"Fraction of year MAY not correspond to "</span>
+<a name="l00301"></a>00301             <span class="stringliteral">"integer number of days"</span>);
+<a name="l00302"></a>00302     }
+<a name="l00303"></a>00303 
+<a name="l00304"></a>00304     *JD = *JD+sinfo_round_double(FRAC*ND);
+<a name="l00305"></a>00305   }
+<a name="l00306"></a>00306 
+<a name="l00307"></a>00307   <span class="keywordflow">return</span>;
+<a name="l00308"></a>00308 }
+<a name="l00309"></a>00309 
+<a name="l00310"></a>00310 <span class="preprocessor">#endif</span>
+<a name="l00311"></a>00311 <span class="preprocessor"></span>
+<a name="l00315"></a>00315 <span class="preprocessor">#define MIDAS_BUG 0</span>
+<a name="l00316"></a>00316 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00324"></a>00324 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00325"></a>00325 
+<a name="l00326"></a>00326 <span class="keyword">static</span> <span class="keywordtype">void</span>
+<a name="l00327"></a>00327 deg2hms(<span class="keywordtype">double</span> in_val, 
+<a name="l00328"></a>00328     <span class="keywordtype">double</span> *hours,
+<a name="l00329"></a>00329     <span class="keywordtype">double</span> *minutes,
+<a name="l00330"></a>00330     <span class="keywordtype">double</span> *seconds)
+<a name="l00331"></a>00331 {
+<a name="l00332"></a>00332   <span class="keywordtype">double</span> tmp;
+<a name="l00333"></a>00333   <span class="keywordtype">char</span> sign;
+<a name="l00334"></a>00334   <span class="keywordflow">if</span> (in_val < 0) {
+<a name="l00335"></a>00335     in_val = fabs(in_val);
+<a name="l00336"></a>00336     sign = <span class="charliteral">'-'</span>;
+<a name="l00337"></a>00337   }
+<a name="l00338"></a>00338   <span class="keywordflow">else</span> {
+<a name="l00339"></a>00339     sign = <span class="charliteral">'+'</span>;
+<a name="l00340"></a>00340   }
+<a name="l00341"></a>00341 
+<a name="l00342"></a>00342   tmp   = in_val / 15;
+<a name="l00343"></a>00343 
+<a name="l00344"></a>00344   <span class="comment">/* takes the integer part = hours */</span>
+<a name="l00345"></a>00345 <span class="preprocessor">#if MIDAS_BUG</span>
+<a name="l00346"></a>00346 <span class="preprocessor"></span>  *hours= sinfo_round_double(tmp);
+<a name="l00347"></a>00347 <span class="preprocessor">#else</span>
+<a name="l00348"></a>00348 <span class="preprocessor"></span>  *hours= (int) tmp;
+<a name="l00349"></a>00349 <span class="preprocessor">#endif</span>
+<a name="l00350"></a>00350 <span class="preprocessor"></span>
+<a name="l00351"></a>00351   <span class="comment">/* takes the mantissa */</span>
+<a name="l00352"></a>00352   tmp   = tmp - *hours;
+<a name="l00353"></a>00353   <span class="comment">/* converts the mantissa in minutes */</span>
+<a name="l00354"></a>00354   tmp   = tmp * 60;
+<a name="l00355"></a>00355 
+<a name="l00356"></a>00356   <span class="comment">/* takes the integer part = minutes */</span>
+<a name="l00357"></a>00357 <span class="preprocessor">#if MIDAS_BUG</span>
+<a name="l00358"></a>00358 <span class="preprocessor"></span>  *minutes= sinfo_round_double(tmp);
+<a name="l00359"></a>00359 <span class="preprocessor">#else</span>
+<a name="l00360"></a>00360 <span class="preprocessor"></span>  *minutes= (int) tmp;
+<a name="l00361"></a>00361 <span class="preprocessor">#endif</span>
+<a name="l00362"></a>00362 <span class="preprocessor"></span>
+<a name="l00363"></a>00363   <span class="comment">/* takes the mantissa */</span>
+<a name="l00364"></a>00364   tmp   = tmp - *minutes;
+<a name="l00365"></a>00365 
+<a name="l00366"></a>00366   <span class="comment">/* converts the mantissa in seconds = seconds (with decimal) */</span>
+<a name="l00367"></a>00367   *seconds= tmp * 60;
+<a name="l00368"></a>00368 
+<a name="l00369"></a>00369   <span class="comment">/* Rather than returning it explicitly, just  attach sign to hours */</span>
+<a name="l00370"></a>00370   <span class="keywordflow">if</span> (sign == <span class="charliteral">'-'</span>) *hours = -(*hours);
+<a name="l00371"></a>00371 
+<a name="l00372"></a>00372   <span class="keywordflow">return</span>;
+<a name="l00373"></a>00373 }
+<a name="l00374"></a>00374 
+<a name="l00375"></a>00375 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00383"></a>00383 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00384"></a>00384 
+<a name="l00385"></a>00385 <span class="keyword">static</span> <span class="keywordtype">void</span>
+<a name="l00386"></a>00386 deg2dms(<span class="keywordtype">double</span> in_val, 
+<a name="l00387"></a>00387     <span class="keywordtype">double</span> *degs,
+<a name="l00388"></a>00388     <span class="keywordtype">double</span> *minutes,
+<a name="l00389"></a>00389     <span class="keywordtype">double</span> *seconds)
+<a name="l00390"></a>00390 {
+<a name="l00391"></a>00391   deg2hms(in_val*15, degs, minutes, seconds);
+<a name="l00392"></a>00392 }
+<a name="l00393"></a>00393 
+<a name="l00394"></a>00394 
+<a name="l00395"></a>00395 
+<a name="l00396"></a>00396 
+<a name="l00397"></a>00397 
+<a name="l00398"></a>00398 <span class="comment">/* @cond Convert FORTRAN indexing -> C indexing */</span>
+<a name="l00399"></a>00399 <span class="preprocessor">#define DCFEL(x,y)  dcfel[y][x]</span>
+<a name="l00400"></a>00400 <span class="preprocessor"></span><span class="preprocessor">#define DCFEPS(x,y) dcfeps[y][x]</span>
+<a name="l00401"></a>00401 <span class="preprocessor"></span><span class="preprocessor">#define CCSEL(x,y)  ccsel[y][x]</span>
+<a name="l00402"></a>00402 <span class="preprocessor"></span><span class="preprocessor">#define DCARGS(x,y) dcargs[y][x]</span>
+<a name="l00403"></a>00403 <span class="preprocessor"></span><span class="preprocessor">#define CCAMPS(x,y) ccamps[y][x]</span>
+<a name="l00404"></a>00404 <span class="preprocessor"></span><span class="preprocessor">#define CCSEC(x,y)  ccsec[y][x]</span>
+<a name="l00405"></a>00405 <span class="preprocessor"></span><span class="preprocessor">#define DCARGM(x,y) dcargm[y][x]</span>
+<a name="l00406"></a>00406 <span class="preprocessor"></span><span class="preprocessor">#define CCAMPM(x,y) ccampm[y][x]</span>
+<a name="l00407"></a>00407 <span class="preprocessor"></span><span class="preprocessor">#define DCEPS(x)    dceps[x]</span>
+<a name="l00408"></a>00408 <span class="preprocessor"></span><span class="preprocessor">#define FORBEL(x)   forbel[x]</span>
+<a name="l00409"></a>00409 <span class="preprocessor"></span><span class="preprocessor">#define SORBEL(x)   sorbel[x]</span>
+<a name="l00410"></a>00410 <span class="preprocessor"></span><span class="preprocessor">#define SN(x)       sn[x]</span>
+<a name="l00411"></a>00411 <span class="preprocessor"></span><span class="preprocessor">#define SINLP(x)    sinlp[x]</span>
+<a name="l00412"></a>00412 <span class="preprocessor"></span><span class="preprocessor">#define COSLP(x)    coslp[x]</span>
+<a name="l00413"></a>00413 <span class="preprocessor"></span><span class="preprocessor">#define CCPAMV(x)   ccpamv[x]</span>
+<a name="l00414"></a>00414 <span class="preprocessor"></span><span class="comment">/* @endcond */</span>
+<a name="l00415"></a>00415 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00428"></a>00428 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00429"></a>00429 
+<a name="l00430"></a>00430 
+<a name="l00431"></a>00431 <span class="keyword">static</span> 
+<a name="l00432"></a>00432 <span class="keywordtype">void</span> barvel(<span class="keywordtype">double</span> DJE, <span class="keywordtype">double</span> DEQ,
+<a name="l00433"></a>00433         <span class="keywordtype">double</span> DVELH[4], <span class="keywordtype">double</span> DVELB[4])
+<a name="l00434"></a>00434 {
+<a name="l00435"></a>00435   <span class="keywordtype">double</span> sn[5];
+<a name="l00436"></a>00436   <span class="keywordtype">double</span> DT,DTL,DTSQ,DLOCAL;
+<a name="l00437"></a>00437   <span class="keywordtype">double</span> DRD,DRLD;
+<a name="l00438"></a>00438   <span class="keywordtype">double</span> DXBD,DYBD,DZBD,DZHD,DXHD,DYHD;
+<a name="l00439"></a>00439   <span class="keywordtype">double</span> DYAHD,DZAHD,DYABD,DZABD;
+<a name="l00440"></a>00440   <span class="keywordtype">double</span> DML,DEPS,PHI,PHID,PSID,DPARAM,PARAM;
+<a name="l00441"></a>00441   <span class="keywordtype">double</span> PLON,POMG,PECC;
+<a name="l00442"></a>00442   <span class="keywordtype">double</span> PERTL,PERTLD,PERTRD,PERTP,PERTR,PERTPD;
+<a name="l00443"></a>00443   <span class="keywordtype">double</span> SINA,TL;
+<a name="l00444"></a>00444   <span class="keywordtype">double</span> COSA,ESQ;
+<a name="l00445"></a>00445   <span class="keywordtype">double</span> A,B,F,SINF,COSF,T,TSQ,TWOE,TWOG;
+<a name="l00446"></a>00446 
+<a name="l00447"></a>00447   <span class="keywordtype">double</span> DPSI,D1PDRO,DSINLS;
+<a name="l00448"></a>00448   <span class="keywordtype">double</span> DCOSLS,DSINEP,DCOSEP;
+<a name="l00449"></a>00449   <span class="keywordtype">double</span> forbel[8], sorbel[18], sinlp[5], coslp[5];
+<a name="l00450"></a>00450   <span class="keywordtype">double</span> SINLM,COSLM,SIGMA;
+<a name="l00451"></a>00451   <span class="keywordtype">int</span> IDEQ,K,N;
+<a name="l00452"></a>00452 
+<a name="l00453"></a>00453   <span class="keywordtype">double</span> *E = sorbel + 1 - 1;
+<a name="l00454"></a>00454   <span class="keywordtype">double</span> *G = forbel + 1 - 1;
+<a name="l00455"></a>00455   <span class="keywordtype">double</span> DC2PI = 6.2831853071796E0;
+<a name="l00456"></a>00456   <span class="keywordtype">double</span> CC2PI = 6.283185;             <span class="comment">/* ??? */</span>
+<a name="l00457"></a>00457 
+<a name="l00458"></a>00458   <span class="keywordtype">double</span> DC1 = 1.0;
+<a name="l00459"></a>00459   <span class="keywordtype">double</span> DCT0 = 2415020.0E0;
+<a name="l00460"></a>00460   <span class="keywordtype">double</span> DCJUL = 36525.0E0;
+<a name="l00461"></a>00461 
+<a name="l00462"></a>00462   <span class="keywordtype">double</span> dcfel[][4] = { {0, 0, 0, 0},
+<a name="l00463"></a>00463             {0, 1.7400353E+00, 6.2833195099091E+02, 5.2796E-06},
+<a name="l00464"></a>00464             {0, 6.2565836E+00, 6.2830194572674E+02,-2.6180E-06},
+<a name="l00465"></a>00465             {0, 4.7199666E+00, 8.3997091449254E+03,-1.9780E-05},
+<a name="l00466"></a>00466             {0, 1.9636505E-01, 8.4334662911720E+03,-5.6044E-05},
+<a name="l00467"></a>00467             {0, 4.1547339E+00, 5.2993466764997E+01, 5.8845E-06},
+<a name="l00468"></a>00468             {0, 4.6524223E+00, 2.1354275911213E+01, 5.6797E-06},
+<a name="l00469"></a>00469             {0, 4.2620486E+00, 7.5025342197656E+00, 5.5317E-06},
+<a name="l00470"></a>00470             {0, 1.4740694E+00, 3.8377331909193E+00, 5.6093E-06} };
+<a name="l00471"></a>00471     
+<a name="l00472"></a>00472   <span class="keywordtype">double</span> dceps[4] = {0, 4.093198E-01,-2.271110E-04,-2.860401E-08};
+<a name="l00473"></a>00473 
+<a name="l00474"></a>00474   <span class="keywordtype">double</span> ccsel[][4] = { {0, 0, 0, 0},
+<a name="l00475"></a>00475             {0, 1.675104E-02, -4.179579E-05, -1.260516E-07},
+<a name="l00476"></a>00476             {0, 2.220221E-01,  2.809917E-02,  1.852532E-05},
+<a name="l00477"></a>00477             {0, 1.589963E+00,  3.418075E-02,  1.430200E-05},
+<a name="l00478"></a>00478             {0, 2.994089E+00,  2.590824E-02,  4.155840E-06},
+<a name="l00479"></a>00479             {0, 8.155457E-01,  2.486352E-02,  6.836840E-06},
+<a name="l00480"></a>00480             {0, 1.735614E+00,  1.763719E-02,  6.370440E-06},
+<a name="l00481"></a>00481             {0, 1.968564E+00,  1.524020E-02, -2.517152E-06},
+<a name="l00482"></a>00482             {0, 1.282417E+00,  8.703393E-03,  2.289292E-05},
+<a name="l00483"></a>00483             {0, 2.280820E+00,  1.918010E-02,  4.484520E-06},
+<a name="l00484"></a>00484             {0, 4.833473E-02,  1.641773E-04, -4.654200E-07},
+<a name="l00485"></a>00485             {0, 5.589232E-02, -3.455092E-04, -7.388560E-07},
+<a name="l00486"></a>00486             {0, 4.634443E-02, -2.658234E-05,  7.757000E-08},
+<a name="l00487"></a>00487             {0, 8.997041E-03,  6.329728E-06, -1.939256E-09},
+<a name="l00488"></a>00488             {0, 2.284178E-02, -9.941590E-05,  6.787400E-08},
+<a name="l00489"></a>00489             {0, 4.350267E-02, -6.839749E-05, -2.714956E-07},
+<a name="l00490"></a>00490             {0, 1.348204E-02,  1.091504E-05,  6.903760E-07},
+<a name="l00491"></a>00491             {0, 3.106570E-02, -1.665665E-04, -1.590188E-07} };
+<a name="l00492"></a>00492 
+<a name="l00493"></a>00493 
+<a name="l00494"></a>00494   <span class="keywordtype">double</span> dcargs[][3] = { {0, 0, 0},
+<a name="l00495"></a>00495              {0, 5.0974222E+00, -7.8604195454652E+02},
+<a name="l00496"></a>00496              {0, 3.9584962E+00, -5.7533848094674E+02},
+<a name="l00497"></a>00497              {0, 1.6338070E+00, -1.1506769618935E+03},
+<a name="l00498"></a>00498              {0, 2.5487111E+00, -3.9302097727326E+02},
+<a name="l00499"></a>00499              {0, 4.9255514E+00, -5.8849265665348E+02},
+<a name="l00500"></a>00500              {0, 1.3363463E+00, -5.5076098609303E+02},
+<a name="l00501"></a>00501              {0, 1.6072053E+00, -5.2237501616674E+02},
+<a name="l00502"></a>00502              {0, 1.3629480E+00, -1.1790629318198E+03},
+<a name="l00503"></a>00503              {0, 5.5657014E+00, -1.0977134971135E+03},
+<a name="l00504"></a>00504              {0, 5.0708205E+00, -1.5774000881978E+02},
+<a name="l00505"></a>00505              {0, 3.9318944E+00,  5.2963464780000E+01},
+<a name="l00506"></a>00506              {0, 4.8989497E+00,  3.9809289073258E+01},
+<a name="l00507"></a>00507              {0, 1.3097446E+00,  7.7540959633708E+01},
+<a name="l00508"></a>00508              {0, 3.5147141E+00,  7.9618578146517E+01},
+<a name="l00509"></a>00509              {0, 3.5413158E+00, -5.4868336758022E+02} };
+<a name="l00510"></a>00510 
+<a name="l00511"></a>00511 
+<a name="l00512"></a>00512   <span class="keywordtype">double</span> ccamps[][6] = 
+<a name="l00513"></a>00513     {{0, 0, 0, 0, 0, 0},
+<a name="l00514"></a>00514      {0, -2.279594E-5,  1.407414E-5,  8.273188E-6,  1.340565E-5, -2.490817E-7},
+<a name="l00515"></a>00515      {0, -3.494537E-5,  2.860401E-7,  1.289448E-7,  1.627237E-5, -1.823138E-7},
+<a name="l00516"></a>00516      {0,  6.593466E-7,  1.322572E-5,  9.258695E-6, -4.674248E-7, -3.646275E-7},
+<a name="l00517"></a>00517      {0,  1.140767E-5, -2.049792E-5, -4.747930E-6, -2.638763E-6, -1.245408E-7},
+<a name="l00518"></a>00518      {0,  9.516893E-6, -2.748894E-6, -1.319381E-6, -4.549908E-6, -1.864821E-7},
+<a name="l00519"></a>00519      {0,  7.310990E-6, -1.924710E-6, -8.772849E-7, -3.334143E-6, -1.745256E-7},
+<a name="l00520"></a>00520      {0, -2.603449E-6,  7.359472E-6,  3.168357E-6,  1.119056E-6, -1.655307E-7},
+<a name="l00521"></a>00521      {0, -3.228859E-6,  1.308997E-7,  1.013137E-7,  2.403899E-6, -3.736225E-7},
+<a name="l00522"></a>00522      {0,  3.442177E-7,  2.671323E-6,  1.832858E-6, -2.394688E-7, -3.478444E-7},
+<a name="l00523"></a>00523      {0,  8.702406E-6, -8.421214E-6, -1.372341E-6, -1.455234E-6, -4.998479E-8},
+<a name="l00524"></a>00524      {0, -1.488378E-6, -1.251789E-5,  5.226868E-7, -2.049301E-7,  0.0E0},
+<a name="l00525"></a>00525      {0, -8.043059E-6, -2.991300E-6,  1.473654E-7, -3.154542E-7,  0.0E0},
+<a name="l00526"></a>00526      {0,  3.699128E-6, -3.316126E-6,  2.901257E-7,  3.407826E-7,  0.0E0},
+<a name="l00527"></a>00527      {0,  2.550120E-6, -1.241123E-6,  9.901116E-8,  2.210482E-7,  0.0E0},
+<a name="l00528"></a>00528      {0, -6.351059E-7,  2.341650E-6,  1.061492E-6,  2.878231E-7,  0.0E0}};
+<a name="l00529"></a>00529 
+<a name="l00530"></a>00530 
+<a name="l00531"></a>00531 
+<a name="l00532"></a>00532   <span class="keywordtype">double</span> CCSEC3 = -7.757020E-08;
+<a name="l00533"></a>00533 
+<a name="l00534"></a>00534   <span class="keywordtype">double</span> ccsec[][4] = { {0, 0, 0, 0},
+<a name="l00535"></a>00535             {0, 1.289600E-06,  5.550147E-01,  2.076942E+00},
+<a name="l00536"></a>00536             {0, 3.102810E-05,  4.035027E+00,  3.525565E-01},
+<a name="l00537"></a>00537             {0, 9.124190E-06,  9.990265E-01,  2.622706E+00},
+<a name="l00538"></a>00538             {0, 9.793240E-07,  5.508259E+00,  1.559103E+01}};
+<a name="l00539"></a>00539 
+<a name="l00540"></a>00540   <span class="keywordtype">double</span> DCSLD =  1.990987E-07, CCSGD = 1.990969E-07;
+<a name="l00541"></a>00541 
+<a name="l00542"></a>00542   <span class="keywordtype">double</span> CCKM = 3.122140E-05, CCMLD = 2.661699E-06, CCFDI = 2.399485E-07;
+<a name="l00543"></a>00543 
+<a name="l00544"></a>00544   <span class="keywordtype">double</span> dcargm[][3] = {{0, 0, 0},
+<a name="l00545"></a>00545             {0, 5.1679830E+00,  8.3286911095275E+03},
+<a name="l00546"></a>00546             {0, 5.4913150E+00, -7.2140632838100E+03},
+<a name="l00547"></a>00547             {0, 5.9598530E+00,  1.5542754389685E+04}};
+<a name="l00548"></a>00548 
+<a name="l00549"></a>00549   <span class="keywordtype">double</span> ccampm[][5] = {{0, 0, 0, 0, 0},
+<a name="l00550"></a>00550             {0,  1.097594E-01,  2.896773E-07,  5.450474E-02,  1.438491E-07},
+<a name="l00551"></a>00551             {0, -2.223581E-02,  5.083103E-08,  1.002548E-02, -2.291823E-08},
+<a name="l00552"></a>00552             {0,  1.148966E-02,  5.658888E-08,  8.249439E-03,  4.063015E-08} };
+<a name="l00553"></a>00553 
+<a name="l00554"></a>00554   <span class="keywordtype">double</span> ccpamv[] = {0, 8.326827E-11, 1.843484E-11, 1.988712E-12, 1.881276E-12};
+<a name="l00555"></a>00555 
+<a name="l00556"></a>00556   <span class="keywordtype">double</span> DC1MME = 0.99999696E0;
+<a name="l00557"></a>00557 
+<a name="l00558"></a>00558   IDEQ=DEQ;
+<a name="l00559"></a>00559 
+<a name="l00560"></a>00560   DT=(DJE-DCT0)/DCJUL;
+<a name="l00561"></a>00561 
+<a name="l00562"></a>00562   T=DT;
+<a name="l00563"></a>00563 
+<a name="l00564"></a>00564   DTSQ=DT*DT;
+<a name="l00565"></a>00565 
+<a name="l00566"></a>00566   TSQ=DTSQ;
+<a name="l00567"></a>00567 
+<a name="l00568"></a>00568   DML = 0;  <span class="comment">/* Suppress warning */</span>
+<a name="l00569"></a>00569   <span class="keywordflow">for</span> (K = 1; K <= 8; K++) {
+<a name="l00570"></a>00570 
+<a name="l00571"></a>00571     DLOCAL=fmod(DCFEL(1,K)+DT*DCFEL(2,K)+DTSQ*DCFEL(3,K),DC2PI);
+<a name="l00572"></a>00572 
+<a name="l00573"></a>00573     <span class="keywordflow">if</span> (K == 1)  DML=DLOCAL;
+<a name="l00574"></a>00574 
+<a name="l00575"></a>00575     <span class="keywordflow">if</span> (K != 1)  FORBEL(K-1)=DLOCAL;
+<a name="l00576"></a>00576   }
+<a name="l00577"></a>00577 
+<a name="l00578"></a>00578   DEPS=fmod(DCEPS(1)+DT*DCEPS(2)+DTSQ*DCEPS(3), DC2PI);
+<a name="l00579"></a>00579 
+<a name="l00580"></a>00580   <span class="keywordflow">for</span> (K = 1; K <= 17; K++) {
+<a name="l00581"></a>00581 
+<a name="l00582"></a>00582     SORBEL(K)=fmod(CCSEL(1,K)+T*CCSEL(2,K)+TSQ*CCSEL(3,K),CC2PI);
+<a name="l00583"></a>00583 
+<a name="l00584"></a>00584   }
+<a name="l00585"></a>00585 
+<a name="l00586"></a>00586   <span class="keywordflow">for</span> (K = 1; K <= 4; K++) {
+<a name="l00587"></a>00587 
+<a name="l00588"></a>00588     A=fmod(CCSEC(2,K)+T*CCSEC(3,K),CC2PI);
+<a name="l00589"></a>00589 
+<a name="l00590"></a>00590     SN(K)=sin(A);
+<a name="l00591"></a>00591 
+<a name="l00592"></a>00592   }
+<a name="l00593"></a>00593 
+<a name="l00594"></a>00594   PERTL =  CCSEC(1,1)          *SN(1) +CCSEC(1,2)*SN(2)
+<a name="l00595"></a>00595     +(CCSEC(1,3)+T*CCSEC3)*SN(3) +CCSEC(1,4)*SN(4);
+<a name="l00596"></a>00596 
+<a name="l00597"></a>00597   PERTLD=0.0;
+<a name="l00598"></a>00598   PERTR =0.0;
+<a name="l00599"></a>00599   PERTRD=0.0;
+<a name="l00600"></a>00600 
+<a name="l00601"></a>00601   <span class="keywordflow">for</span> (K = 1; K <= 15; K++) {
+<a name="l00602"></a>00602 
+<a name="l00603"></a>00603     A=fmod(DCARGS(1,K)+DT*DCARGS(2,K), DC2PI);
+<a name="l00604"></a>00604 
+<a name="l00605"></a>00605     COSA=cos(A);
+<a name="l00606"></a>00606 
+<a name="l00607"></a>00607     SINA=sin(A);
+<a name="l00608"></a>00608 
+<a name="l00609"></a>00609     PERTL =PERTL+CCAMPS(1,K)*COSA+CCAMPS(2,K)*SINA;
+<a name="l00610"></a>00610 
+<a name="l00611"></a>00611     PERTR =PERTR+CCAMPS(3,K)*COSA+CCAMPS(4,K)*SINA;
+<a name="l00612"></a>00612 
+<a name="l00613"></a>00613     <span class="keywordflow">if</span> (K >= 11) <span class="keywordflow">break</span>;
+<a name="l00614"></a>00614 
+<a name="l00615"></a>00615     PERTLD=PERTLD+(CCAMPS(2,K)*COSA-CCAMPS(1,K)*SINA)*CCAMPS(5,K);
+<a name="l00616"></a>00616 
+<a name="l00617"></a>00617     PERTRD=PERTRD+(CCAMPS(4,K)*COSA-CCAMPS(3,K)*SINA)*CCAMPS(5,K);
+<a name="l00618"></a>00618 
+<a name="l00619"></a>00619   }
+<a name="l00620"></a>00620 
+<a name="l00621"></a>00621 
+<a name="l00622"></a>00622   ESQ=E[1]*E[1];
+<a name="l00623"></a>00623 
+<a name="l00624"></a>00624   DPARAM=DC1-ESQ;
+<a name="l00625"></a>00625 
+<a name="l00626"></a>00626   PARAM=DPARAM;
+<a name="l00627"></a>00627 
+<a name="l00628"></a>00628   TWOE=E[1]+E[1];
+<a name="l00629"></a>00629 
+<a name="l00630"></a>00630   TWOG=G[1]+G[1];
+<a name="l00631"></a>00631 
+<a name="l00632"></a>00632   PHI=TWOE*((1.0-ESQ*0.125  )*sin(G[1])+E[1]*0.625  *sin(TWOG)
+<a name="l00633"></a>00633         +ESQ*0.5416667  *sin(G[1]+TWOG) ) ;
+<a name="l00634"></a>00634     
+<a name="l00635"></a>00635   F=G[1]+PHI;
+<a name="l00636"></a>00636 
+<a name="l00637"></a>00637   SINF=sin(F);
+<a name="l00638"></a>00638 
+<a name="l00639"></a>00639   COSF=cos(F);
+<a name="l00640"></a>00640 
+<a name="l00641"></a>00641   DPSI=DPARAM/(DC1+E[1]*COSF);
+<a name="l00642"></a>00642 
+<a name="l00643"></a>00643   PHID=TWOE*CCSGD*((1.0+ESQ*1.5  )*COSF+E[1]*(1.25  -SINF*SINF*0.5  ));
+<a name="l00644"></a>00644 
+<a name="l00645"></a>00645   PSID=CCSGD*E[1]*SINF/sqrt(PARAM);
+<a name="l00646"></a>00646 
+<a name="l00647"></a>00647   D1PDRO=(DC1+PERTR);
+<a name="l00648"></a>00648 
+<a name="l00649"></a>00649   DRD=D1PDRO*(PSID+DPSI*PERTRD);
+<a name="l00650"></a>00650 
+<a name="l00651"></a>00651   DRLD=D1PDRO*DPSI*(DCSLD+PHID+PERTLD);
+<a name="l00652"></a>00652 
+<a name="l00653"></a>00653   DTL=fmod(DML+PHI+PERTL, DC2PI);
+<a name="l00654"></a>00654 
+<a name="l00655"></a>00655   DSINLS=sin(DTL);
+<a name="l00656"></a>00656 
+<a name="l00657"></a>00657   DCOSLS=cos(DTL);
+<a name="l00658"></a>00658 
+<a name="l00659"></a>00659   DXHD = DRD*DCOSLS-DRLD*DSINLS;
+<a name="l00660"></a>00660 
+<a name="l00661"></a>00661   DYHD = DRD*DSINLS+DRLD*DCOSLS;
+<a name="l00662"></a>00662 
+<a name="l00663"></a>00663   PERTL =0.0;
+<a name="l00664"></a>00664 
+<a name="l00665"></a>00665   PERTLD=0.0;
+<a name="l00666"></a>00666 
+<a name="l00667"></a>00667   PERTP =0.0;
+<a name="l00668"></a>00668 
+<a name="l00669"></a>00669   PERTPD=0.0;
+<a name="l00670"></a>00670 
+<a name="l00671"></a>00671   <span class="keywordflow">for</span> (K = 1; K <= 3; K++) {
+<a name="l00672"></a>00672     A=fmod(DCARGM(1,K)+DT*DCARGM(2,K), DC2PI);
+<a name="l00673"></a>00673 
+<a name="l00674"></a>00674     SINA  =sin(A);
+<a name="l00675"></a>00675 
+<a name="l00676"></a>00676     COSA  =cos(A);
+<a name="l00677"></a>00677 
+<a name="l00678"></a>00678     PERTL =PERTL +CCAMPM(1,K)*SINA;
+<a name="l00679"></a>00679 
+<a name="l00680"></a>00680     PERTLD=PERTLD+CCAMPM(2,K)*COSA;
+<a name="l00681"></a>00681 
+<a name="l00682"></a>00682     PERTP =PERTP +CCAMPM(3,K)*COSA;
+<a name="l00683"></a>00683 
+<a name="l00684"></a>00684     PERTPD=PERTPD-CCAMPM(4,K)*SINA;
+<a name="l00685"></a>00685   }
+<a name="l00686"></a>00686     
+<a name="l00687"></a>00687   TL=FORBEL(2)+PERTL;
+<a name="l00688"></a>00688 
+<a name="l00689"></a>00689   SINLM=sin(TL);
+<a name="l00690"></a>00690 
+<a name="l00691"></a>00691   COSLM=cos(TL);
+<a name="l00692"></a>00692 
+<a name="l00693"></a>00693   SIGMA=CCKM/(1.0+PERTP);
+<a name="l00694"></a>00694 
+<a name="l00695"></a>00695   A=SIGMA*(CCMLD+PERTLD);
+<a name="l00696"></a>00696 
+<a name="l00697"></a>00697   B=SIGMA*PERTPD;
+<a name="l00698"></a>00698 
+<a name="l00699"></a>00699   DXHD=DXHD+A*SINLM+B*COSLM;
+<a name="l00700"></a>00700 
+<a name="l00701"></a>00701   DYHD=DYHD-A*COSLM+B*SINLM;
+<a name="l00702"></a>00702 
+<a name="l00703"></a>00703   DZHD=    -SIGMA*CCFDI* cos(FORBEL(3));
+<a name="l00704"></a>00704 
+<a name="l00705"></a>00705   DXBD=DXHD*DC1MME;
+<a name="l00706"></a>00706 
+<a name="l00707"></a>00707   DYBD=DYHD*DC1MME;
+<a name="l00708"></a>00708 
+<a name="l00709"></a>00709   DZBD=DZHD*DC1MME;
+<a name="l00710"></a>00710 
+<a name="l00711"></a>00711   <span class="keywordflow">for</span> (K = 1; K <= 4; K++) {
+<a name="l00712"></a>00712 
+<a name="l00713"></a>00713     PLON=FORBEL(K+3);
+<a name="l00714"></a>00714 
+<a name="l00715"></a>00715     POMG=SORBEL(K+1);
+<a name="l00716"></a>00716 
+<a name="l00717"></a>00717     PECC=SORBEL(K+9);
+<a name="l00718"></a>00718 
+<a name="l00719"></a>00719     TL=fmod(PLON+2.0*PECC* sin(PLON-POMG), CC2PI);
+<a name="l00720"></a>00720 
+<a name="l00721"></a>00721     SINLP(K)= sin(TL);
+<a name="l00722"></a>00722 
+<a name="l00723"></a>00723     COSLP(K)= cos(TL);
+<a name="l00724"></a>00724 
+<a name="l00725"></a>00725     DXBD=DXBD+CCPAMV(K)*(SINLP(K)+PECC*sin(POMG));
+<a name="l00726"></a>00726 
+<a name="l00727"></a>00727     DYBD=DYBD-CCPAMV(K)*(COSLP(K)+PECC*cos(POMG));
+<a name="l00728"></a>00728 
+<a name="l00729"></a>00729     DZBD=DZBD-CCPAMV(K)*SORBEL(K+13)*cos(PLON-SORBEL(K+5));
+<a name="l00730"></a>00730 
+<a name="l00731"></a>00731   }
+<a name="l00732"></a>00732     
+<a name="l00733"></a>00733   DCOSEP=cos(DEPS);
+<a name="l00734"></a>00734   DSINEP=sin(DEPS);
+<a name="l00735"></a>00735   DYAHD=DCOSEP*DYHD-DSINEP*DZHD;
+<a name="l00736"></a>00736   DZAHD=DSINEP*DYHD+DCOSEP*DZHD;
+<a name="l00737"></a>00737   DYABD=DCOSEP*DYBD-DSINEP*DZBD;
+<a name="l00738"></a>00738   DZABD=DSINEP*DYBD+DCOSEP*DZBD;
+<a name="l00739"></a>00739 
+<a name="l00740"></a>00740   DVELH[1]=DXHD;
+<a name="l00741"></a>00741   DVELH[2]=DYAHD;
+<a name="l00742"></a>00742   DVELH[3]=DZAHD;
+<a name="l00743"></a>00743 
+<a name="l00744"></a>00744   DVELB[1]=DXBD;
+<a name="l00745"></a>00745   DVELB[2]=DYABD;
+<a name="l00746"></a>00746   DVELB[3]=DZABD;
+<a name="l00747"></a>00747 
+<a name="l00748"></a>00748   <span class="keywordflow">for</span> (N = 1; N <= 3; N++) {
+<a name="l00749"></a>00749     DVELH[N]=DVELH[N]*1.4959787E8;
+<a name="l00750"></a>00750     DVELB[N]=DVELB[N]*1.4959787E8;
+<a name="l00751"></a>00751   }
+<a name="l00752"></a>00752   <span class="keywordflow">return</span>;
+<a name="l00753"></a>00753 }
+<a name="l00754"></a>00754 
+<a name="l00755"></a>00755 
+<a name="l00756"></a>00756 
+<a name="l00757"></a>00757 
+<a name="l00758"></a>00758 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00780"></a>00780 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00781"></a>00781 <span class="keyword">static</span> <span class="keywordtype">void</span>
+<a name="l00782"></a>00782 compxy(<span class="keywordtype">double</span> inputr[19], <span class="keywordtype">char</span> inputc[4],
+<a name="l00783"></a>00783        <span class="keywordtype">double</span> outputr[4],
+<a name="l00784"></a>00784        <span class="keywordtype">double</span> utr, <span class="keywordtype">double</span> mod_juldat)
+<a name="l00785"></a>00785 {
+<a name="l00786"></a>00786   <span class="keywordtype">double</span> STR;
+<a name="l00787"></a>00787   <span class="keywordtype">double</span> t0, dl, theta0, pe, st0hg, stg;
+<a name="l00788"></a>00788   <span class="keywordtype">double</span> jd, jd0h;
+<a name="l00789"></a>00789   <span class="keywordtype">double</span> dvelb[4], dvelh[4];
+<a name="l00790"></a>00790   <span class="keywordtype">double</span> alp, del, beov, berv, EDV;
+<a name="l00791"></a>00791   <span class="keywordtype">double</span> HAR, phi, heov, herv;
+<a name="l00792"></a>00792   <span class="keywordtype">double</span> *rbuf;
+<a name="l00793"></a>00793   <span class="keywordtype">char</span> inpsgn[4];
+<a name="l00794"></a>00794   <span class="keywordtype">double</span> *olong, *olat, *alpha, *delta;
+<a name="l00795"></a>00795   <span class="keywordtype">char</span> signs[] = <span class="stringliteral">"+++"</span>;
+<a name="l00796"></a>00796   rbuf = inputr;
+<a name="l00797"></a>00797   inpsgn[1] = inputc[1];
+<a name="l00798"></a>00798   inpsgn[2] = inputc[2];
+<a name="l00799"></a>00799   inpsgn[3] = inputc[3];
+<a name="l00800"></a>00800   olong = rbuf + 7 - 1;
+<a name="l00801"></a>00801   olat  = rbuf + 10 - 1;
+<a name="l00802"></a>00802   alpha = rbuf + 13 - 1;
+<a name="l00803"></a>00803   delta = rbuf + 16 - 1;
+<a name="l00804"></a>00804   <span class="comment">// ... convert UT to real hours, calculate Julian date</span>
+<a name="l00805"></a>00805   <span class="comment">/* We know this one already but convert seconds -> hours */</span>
+<a name="l00806"></a>00806   utr /= 3600;
+<a name="l00807"></a>00807 
+<a name="l00808"></a>00808 
+<a name="l00809"></a>00809   jd = mod_juldat + 2400000.5;
+<a name="l00810"></a>00810   
+<a name="l00811"></a>00811   <span class="comment">// ... likewise convert longitude and latitude of observatory to real hours</span>
+<a name="l00812"></a>00812   <span class="comment">// ... and degrees, respectively; take care of signs</span>
+<a name="l00813"></a>00813   <span class="comment">// ... NOTE: east longitude is assumed for input !!</span>
+<a name="l00814"></a>00814 
+<a name="l00815"></a>00815   <span class="keywordflow">if</span> (olong[1] < 0 || olong[2] < 0 ||
+<a name="l00816"></a>00816       olong[3] < 0 || inpsgn[1] == <span class="charliteral">'-'</span>) {
+<a name="l00817"></a>00817     signs[1] = <span class="charliteral">'-'</span>;
+<a name="l00818"></a>00818     olong[1] = fabs(olong[1]);
+<a name="l00819"></a>00819     olong[2] = fabs(olong[2]);
+<a name="l00820"></a>00820     olong[3] = fabs(olong[3]);
+<a name="l00821"></a>00821   }
+<a name="l00822"></a>00822   dl = olong[1]+olong[2]/60.  +olong[3]/3600.;
+<a name="l00823"></a>00823   <span class="keywordflow">if</span> (signs[1]   == <span class="charliteral">'-'</span>) dl = -dl;
+<a name="l00824"></a>00824   dl = -dl*24.  /360.;
+<a name="l00825"></a>00825 
+<a name="l00826"></a>00826   <span class="keywordflow">if</span> (olat[1] < 0 || olat[2] < 0 ||
+<a name="l00827"></a>00827       olat[3] < 0 || inpsgn[2] == <span class="charliteral">'-'</span>) {
+<a name="l00828"></a>00828     signs[2] = <span class="charliteral">'-'</span>;
+<a name="l00829"></a>00829  
+<a name="l00830"></a>00830     olat[1] = fabs(olat[1]);
+<a name="l00831"></a>00831     olat[2] = fabs(olat[2]);
+<a name="l00832"></a>00832     olat[3] = fabs(olat[3]);
+<a name="l00833"></a>00833 
+<a name="l00834"></a>00834   }
+<a name="l00835"></a>00835 
+<a name="l00836"></a>00836   phi = olat[1]+olat[2]/60.  +olat[3]/3600.;
+<a name="l00837"></a>00837 
+<a name="l00838"></a>00838   <span class="keywordflow">if</span> (signs[2]   == <span class="charliteral">'-'</span>) phi = -phi;
+<a name="l00839"></a>00839 
+<a name="l00840"></a>00840   phi = phi*M_PI/180. ;
+<a name="l00841"></a>00841 
+<a name="l00842"></a>00842   <span class="comment">// ... convert right ascension and declination to real radians</span>
+<a name="l00843"></a>00843 
+<a name="l00844"></a>00844   alp = (alpha[1]*3600. +alpha[2]*60. +alpha[3])*M_PI/(12.  *3600.  );
+<a name="l00845"></a>00845 
+<a name="l00846"></a>00846   <span class="keywordflow">if</span> (delta[1] < 0 || delta[2] < 0 ||
+<a name="l00847"></a>00847       delta[3] < 0 || inpsgn[3] == <span class="charliteral">'-'</span>) {
+<a name="l00848"></a>00848 
+<a name="l00849"></a>00849     signs[3] = <span class="charliteral">'-'</span>;
+<a name="l00850"></a>00850 
+<a name="l00851"></a>00851     delta[1] = fabs(delta[1]);
+<a name="l00852"></a>00852     delta[2] = fabs(delta[2]);
+<a name="l00853"></a>00853     delta[3] = fabs(delta[3]);
+<a name="l00854"></a>00854 
+<a name="l00855"></a>00855   }
+<a name="l00856"></a>00856 
+<a name="l00857"></a>00857   del = (delta[1]*3600.0  + delta[2]*60.   + delta[3])
+<a name="l00858"></a>00858     * M_PI/(3600. *180. );
+<a name="l00859"></a>00859 
+<a name="l00860"></a>00860 
+<a name="l00861"></a>00861 
+<a name="l00862"></a>00862   <span class="keywordflow">if</span> (signs[3]   == <span class="charliteral">'-'</span>) del = - del;
+<a name="l00863"></a>00863 
+<a name="l00864"></a>00864   <span class="comment">// ... calculate earth's orbital velocity in rectangular coordinates X,Y,Z</span>
+<a name="l00865"></a>00865   <span class="comment">// ... for both heliocentric and barycentric frames (DVELH, DVELB)</span>
+<a name="l00866"></a>00866   <span class="comment">// ... Note that setting the second argument of BARVEL to zero as done below</span>
+<a name="l00867"></a>00867   <span class="comment">// ... means that the input coordinates will not be corrected for precession.</span>
+<a name="l00868"></a>00868 
+<a name="l00869"></a>00869 
+<a name="l00870"></a>00870   barvel(jd, 0.0, dvelh, dvelb);
+<a name="l00871"></a>00871 
+<a name="l00872"></a>00872   <span class="comment">// ... with the rectangular velocity components known, the respective projections</span>
+<a name="l00873"></a>00873   <span class="comment">// ... HEOV and BEOV on a given line of sight (ALP,DEL) can be determined:</span>
+<a name="l00874"></a>00874 
+<a name="l00875"></a>00875   <span class="comment">// ... REFERENCE: THE ASTRONOMICAL ALMANAC 1982 PAGE:B17</span>
+<a name="l00876"></a>00876 
+<a name="l00877"></a>00877   beov =
+<a name="l00878"></a>00878     dvelb[1]*cos(alp)*cos(del)+
+<a name="l00879"></a>00879     dvelb[2]*sin(alp)*cos(del)+
+<a name="l00880"></a>00880     dvelb[3]*sin(del);
+<a name="l00881"></a>00881       
+<a name="l00882"></a>00882   heov =
+<a name="l00883"></a>00883     dvelh[1]*cos(alp)*cos(del)+
+<a name="l00884"></a>00884     dvelh[2]*sin(alp)*cos(del)+
+<a name="l00885"></a>00885     dvelh[3]*sin(del);
+<a name="l00886"></a>00886       
+<a name="l00887"></a>00887 
+<a name="l00888"></a>00888   <span class="comment">// ... For determination also of the contribution due to the diurnal rotation of</span>
+<a name="l00889"></a>00889   <span class="comment">// ... the earth (EDV), the hour angle (HAR) is needed at which the observation</span>
+<a name="l00890"></a>00890   <span class="comment">// ... was made which requires conversion of UT to sidereal time (ST).</span>
+<a name="l00891"></a>00891 
+<a name="l00892"></a>00892   <span class="comment">// ... Therefore, first compute ST at 0 hours UT (ST0HG)</span>
+<a name="l00893"></a>00893 
+<a name="l00894"></a>00894   <span class="comment">// ... REFERENCE : MEEUS J.,1980,ASTRONOMICAL FORMULAE FOR CALCULATORS</span>
+<a name="l00895"></a>00895 
+<a name="l00896"></a>00896 
+<a name="l00897"></a>00897   jd0h = jd - (utr/24.0);
+<a name="l00898"></a>00898       
+<a name="l00899"></a>00899   t0 = (jd0h-2415020.  )/36525. ;
+<a name="l00900"></a>00900       
+<a name="l00901"></a>00901 
+<a name="l00902"></a>00902   theta0 = 0.276919398  +100.0021359  *t0+0.000001075  *t0*t0 ;
+<a name="l00903"></a>00903 
+<a name="l00904"></a>00904   pe = (int) theta0;
+<a name="l00905"></a>00905 
+<a name="l00906"></a>00906   theta0 = theta0 - pe;
+<a name="l00907"></a>00907 
+<a name="l00908"></a>00908   st0hg = theta0*24. ;
+<a name="l00909"></a>00909 
+<a name="l00910"></a>00910   <span class="comment">// ... now do the conversion UT -> ST (MEAN SIDEREAL TIME)</span>
+<a name="l00911"></a>00911 
+<a name="l00912"></a>00912   <span class="comment">// ... REFERENCE : THE ASTRONOMICAL ALMANAC 1983, P B7</span>
+<a name="l00913"></a>00913   <span class="comment">// ... IN 1983: 1 MEAN SOLAR DAY = 1.00273790931 MEAN SIDEREAL DAYS</span>
+<a name="l00914"></a>00914   <span class="comment">// ... ST WITHOUT EQUATION OF EQUINOXES CORRECTION => ACCURACY +/- 1 SEC</span>
+<a name="l00915"></a>00915   <span class="comment">//</span>
+<a name="l00916"></a>00916   stg = st0hg+utr*1.00273790931 ;
+<a name="l00917"></a>00917       
+<a name="l00918"></a>00918   <span class="keywordflow">if</span> (stg < dl) stg = stg +24. ;
+<a name="l00919"></a>00919 
+<a name="l00920"></a>00920   STR = stg-dl;
+<a name="l00921"></a>00921 
+<a name="l00922"></a>00922 
+<a name="l00923"></a>00923   <span class="keywordflow">if</span> (STR >= 24. ) STR = STR-24. ;
+<a name="l00924"></a>00924 
+<a name="l00925"></a>00925   STR = STR*M_PI/12. ;
+<a name="l00926"></a>00926 
+<a name="l00927"></a>00927   HAR = STR-alp;
+<a name="l00928"></a>00928       
+<a name="l00929"></a>00929 
+<a name="l00930"></a>00930   EDV = -0.4654  * sin(HAR)* cos(del)* cos(phi);
+<a name="l00931"></a>00931 
+<a name="l00932"></a>00932   <span class="comment">// ... the total correction (in km/s) is the sum of orbital and diurnal components</span>
+<a name="l00933"></a>00933 
+<a name="l00934"></a>00934 
+<a name="l00935"></a>00935   herv=heov+EDV;
+<a name="l00936"></a>00936   berv=beov+EDV;
+<a name="l00937"></a>00937 
+<a name="l00938"></a>00938   <span class="comment">/* The following is not needed. Do not translate */</span>
+<a name="l00939"></a>00939 
+<a name="l00940"></a>00940 <span class="preprocessor">#if 0</span>
+<a name="l00941"></a>00941 <span class="preprocessor"></span>  <span class="comment">// ... Calculation of the barycentric and heliocentric correction times</span>
+<a name="l00942"></a>00942   <span class="comment">// ... (BCT and HCT) requires knowledge of the earth's position in its</span>
+<a name="l00943"></a>00943   <span class="comment">// ... orbit. Subroutine BARCOR returns the rectangular barycentric (DCORB)</span>
+<a name="l00944"></a>00944   <span class="comment">// ... and heliocentric (DCORH) coordinates.</span>
+<a name="l00945"></a>00945 
+<a name="l00946"></a>00946   <span class="comment">//      CALL BARCOR(DCORH,DCORB)</span>
+<a name="l00947"></a>00947 
+<a name="l00948"></a>00948   <span class="comment">// ... from this, the correction times (in days) can be determined:</span>
+<a name="l00949"></a>00949   <span class="comment">// ... (REFERENCE: THE ASTRONOMICAL ALMANAC 1982 PAGE:B16)</span>
+<a name="l00950"></a>00950 
+<a name="l00951"></a>00951   <span class="comment">//      BCT=+0.0057756D0*(DCORB(1)*DCOS(ALP)*DCOS(DEL)+</span>
+<a name="l00952"></a>00952   <span class="comment">//     1                DCORB(2)*DSIN(ALP)*DCOS(DEL)+</span>
+<a name="l00953"></a>00953   <span class="comment">//     2                DCORB(3)*          DSIN(DEL))</span>
+<a name="l00954"></a>00954   <span class="comment">//      HCT=+0.0057756D0*(DCORH(1)*DCOS(ALP)*DCOS(DEL)+</span>
+<a name="l00955"></a>00955   <span class="comment">//     1                DCORH(2)*DSIN(ALP)*DCOS(DEL)+</span>
+<a name="l00956"></a>00956   <span class="comment">//     2                DCORH(3)*          DSIN(DEL))</span>
+<a name="l00957"></a>00957 
+<a name="l00958"></a>00958   <span class="comment">//... write results to keywords</span>
+<a name="l00959"></a>00959 
+<a name="l00960"></a>00960   <span class="comment">//      CALL STKWRD('OUTPUTD',BCT,1,1,KUN,STAT)    ! barycentric correction time</span>
+<a name="l00961"></a>00961   <span class="comment">//      CALL STKWRD('OUTPUTD',HCT,2,1,KUN,STAT)    ! heliocentric correction time</span>
+<a name="l00962"></a>00962 <span class="preprocessor">#endif</span>
+<a name="l00963"></a>00963 <span class="preprocessor"></span>
+<a name="l00964"></a>00964   rbuf[1] = berv;   <span class="comment">/* barocentric RV correction */</span>
+<a name="l00965"></a>00965   rbuf[2] = herv;   <span class="comment">/* heliocentric RV correction */</span>
+<a name="l00966"></a>00966   rbuf[3] = EDV;    <span class="comment">/* diurnal RV correction */</span>
+<a name="l00967"></a>00967 
+<a name="l00968"></a>00968 
+<a name="l00969"></a>00969   outputr[1] = rbuf[1];
+<a name="l00970"></a>00970   outputr[2] = rbuf[2];
+<a name="l00971"></a>00971   outputr[3] = rbuf[3];
+<a name="l00972"></a>00972 
+<a name="l00973"></a>00973   <span class="keywordflow">return</span>;
+<a name="l00974"></a>00974 }
+<a name="l00975"></a>00975 
+<a name="l00976"></a>00976 
+<a name="l00977"></a>00977 
+<a name="l00978"></a>00978 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00985"></a>00985 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00986"></a>00986 cpl_error_code
+<a name="l00987"></a>00987 sinfo_baryvel(<span class="keyword">const</span> cpl_propertylist *raw_header,
+<a name="l00988"></a>00988          <span class="keywordtype">double</span> *bary_corr,
+<a name="l00989"></a>00989          <span class="keywordtype">double</span> *helio_corr)
+<a name="l00990"></a>00990 {
+<a name="l00991"></a>00991 
+<a name="l00992"></a>00992     <span class="keywordtype">double</span> outputr[4];
+<a name="l00993"></a>00993 
+<a name="l00994"></a>00994     <span class="keywordtype">char</span> inputc[] = <span class="stringliteral">"X+++"</span>;       <span class="comment">/* 0th index not used */</span>
+<a name="l00995"></a>00995 
+<a name="l00996"></a>00996     <span class="keywordtype">double</span> rneg = 1.0;
+<a name="l00997"></a>00997 
+<a name="l00998"></a>00998     <span class="keywordtype">double</span> inputr[19];                  <span class="comment">/* Do not use the zeroth element */</span>
+<a name="l00999"></a>00999 
+<a name="l01000"></a>01000 
+<a name="l01001"></a>01001 <span class="comment">/*</span>
+<a name="l01002"></a>01002 <span class="comment">  qc_ra       = m$value({p1},O_POS(1))</span>
+<a name="l01003"></a>01003 <span class="comment">  qc_dec      = m$value({p1},O_POS(2))</span>
+<a name="l01004"></a>01004 <span class="comment">  qc_geolat   = m$value({p1},{h_geolat})</span>
+<a name="l01005"></a>01005 <span class="comment">  qc_geolon   = m$value({p1},{h_geolon})</span>
+<a name="l01006"></a>01006 <span class="comment">  qc_obs_time = m$value({p1},O_TIME(7))  !using an image as input it take the</span>
+<a name="l01007"></a>01007 <span class="comment">                                         !date from the descriptor O_TIME(1,2,3)</span>
+<a name="l01008"></a>01008 <span class="comment">                                         !and the UT from O_TIME(5)</span>
+<a name="l01009"></a>01009 <span class="comment">*/</span>
+<a name="l01010"></a>01010     <span class="keywordtype">double</span> qc_ra;
+<a name="l01011"></a>01011     <span class="keywordtype">double</span> qc_dec;
+<a name="l01012"></a>01012     <span class="keywordtype">double</span> qc_geolat;
+<a name="l01013"></a>01013     <span class="keywordtype">double</span> qc_geolon;
+<a name="l01014"></a>01014 
+<a name="l01015"></a>01015     <span class="keywordtype">double</span> utr;
+<a name="l01016"></a>01016     <span class="keywordtype">double</span> mod_juldat;
+<a name="l01017"></a>01017 
+<a name="l01018"></a>01018     <span class="keywordtype">double</span> ra_hour, ra_min, ra_sec;
+<a name="l01019"></a>01019     <span class="keywordtype">double</span> dec_deg, dec_min, dec_sec;
+<a name="l01020"></a>01020     <span class="keywordtype">double</span> lat_deg, lat_min, lat_sec;
+<a name="l01021"></a>01021     <span class="keywordtype">double</span> lon_deg, lon_min, lon_sec;
+<a name="l01022"></a>01022 
+<a name="l01023"></a>01023     check( qc_ra       = sinfo_pfits_get_ra(raw_header),  <span class="comment">/* in degrees */</span>
+<a name="l01024"></a>01024        <span class="stringliteral">"Error getting object right ascension"</span>);
+<a name="l01025"></a>01025     check( qc_dec      = sinfo_pfits_get_dec(raw_header),
+<a name="l01026"></a>01026        <span class="stringliteral">"Error getting object declination"</span>);
+<a name="l01027"></a>01027 
+<a name="l01028"></a>01028     check( qc_geolat   = sinfo_pfits_get_geolat(raw_header),
+<a name="l01029"></a>01029        <span class="stringliteral">"Error getting telescope latitude"</span>);
+<a name="l01030"></a>01030     check( qc_geolon   = sinfo_pfits_get_geolon(raw_header),
+<a name="l01031"></a>01031        <span class="stringliteral">"Error getting telescope longitude"</span>);
+<a name="l01032"></a>01032 
+<a name="l01033"></a>01033     <span class="comment">/* double qc_obs_time = sinfo_pfits_get_exptime(raw_header);   Not used! */</span>
+<a name="l01034"></a>01034 
+<a name="l01035"></a>01035     check( utr         = sinfo_pfits_get_utc(raw_header),
+<a name="l01036"></a>01036        <span class="stringliteral">"Error reading UTC"</span>);
+<a name="l01037"></a>01037     check( mod_juldat  = sinfo_pfits_get_mjdobs(raw_header),
+<a name="l01038"></a>01038        <span class="stringliteral">"Error julian date"</span>);
+<a name="l01039"></a>01039 
+<a name="l01040"></a>01040     deg2hms(qc_ra,     &ra_hour, &ra_min, &ra_sec);
+<a name="l01041"></a>01041     deg2dms(qc_dec,    &dec_deg, &dec_min, &dec_sec);
+<a name="l01042"></a>01042     deg2dms(qc_geolat, &lat_deg, &lat_min, &lat_sec);
+<a name="l01043"></a>01043     deg2dms(qc_geolon, &lon_deg, &lon_min, &lon_sec);
+<a name="l01044"></a>01044 
+<a name="l01045"></a>01045 
+<a name="l01046"></a>01046     inputr[7] = lon_deg;
+<a name="l01047"></a>01047     inputr[8] = lon_min;
+<a name="l01048"></a>01048     inputr[9] = lon_sec;
+<a name="l01049"></a>01049 
+<a name="l01050"></a>01050 
+<a name="l01051"></a>01051     rneg = (inputr[7]*3600.)+(inputr[8]*60.)+inputr[9];
+<a name="l01052"></a>01052 
+<a name="l01053"></a>01053     inputc[1] = (lon_deg >= 0) ? <span class="charliteral">'+'</span> : <span class="charliteral">'-'</span>;
+<a name="l01054"></a>01054 
+<a name="l01055"></a>01055     <span class="keywordflow">if</span> (rneg < 0) inputc[1] = <span class="charliteral">'-'</span>;
+<a name="l01056"></a>01056 
+<a name="l01057"></a>01057 
+<a name="l01058"></a>01058     inputr[10] = lat_deg;
+<a name="l01059"></a>01059     inputr[11] = lat_min;
+<a name="l01060"></a>01060     inputr[12] = lat_sec;
+<a name="l01061"></a>01061 
+<a name="l01062"></a>01062 
+<a name="l01063"></a>01063     rneg = (inputr[10]*3600.)+(inputr[11]*60.)+inputr[12];
+<a name="l01064"></a>01064 
+<a name="l01065"></a>01065     inputc[2] = (lat_deg >= 0) ? <span class="charliteral">'+'</span> : <span class="charliteral">'-'</span>;
+<a name="l01066"></a>01066 
+<a name="l01067"></a>01067     <span class="keywordflow">if</span> (rneg < 0) inputc[2] = <span class="charliteral">'-'</span>;
+<a name="l01068"></a>01068 
+<a name="l01069"></a>01069 
+<a name="l01070"></a>01070     inputr[13] = ra_hour;
+<a name="l01071"></a>01071     inputr[14] = ra_min;
+<a name="l01072"></a>01072     inputr[15] = ra_sec;
+<a name="l01073"></a>01073 
+<a name="l01074"></a>01074 
+<a name="l01075"></a>01075     inputr[16] = dec_deg;
+<a name="l01076"></a>01076     inputr[17] = dec_min;
+<a name="l01077"></a>01077     inputr[18] = dec_sec;
+<a name="l01078"></a>01078 
+<a name="l01079"></a>01079 
+<a name="l01080"></a>01080     inputc[3] = (dec_deg >= 0) ? <span class="charliteral">'+'</span> : <span class="charliteral">'-'</span>;
+<a name="l01081"></a>01081 
+<a name="l01082"></a>01082     rneg = (inputr[16]*3600.)+(inputr[17]*60.)+inputr[18];
+<a name="l01083"></a>01083 
+<a name="l01084"></a>01084     <span class="keywordflow">if</span> (rneg < 0) inputc[3] = <span class="charliteral">'-'</span>;
+<a name="l01085"></a>01085     
+<a name="l01086"></a>01086 
+<a name="l01087"></a>01087 <span class="comment">//C  INPUTR/R/1/3    date: year,month,day</span>
+<a name="l01088"></a>01088 <span class="comment">//C  INPUTR/R/4/3    universal time: hour,min,sec</span>
+<a name="l01089"></a>01089 <span class="comment">//C  INPUTR/R/7/3    EAST longitude of observatory: degree,min,sec  !! NOTE</span>
+<a name="l01090"></a>01090 <span class="comment">//C  INPUTR/R/10/3   latitude of observatory: degree,min,sec</span>
+<a name="l01091"></a>01091 <span class="comment">//C  INPUTR/R/13/3   right ascension: hour,min,sec</span>
+<a name="l01092"></a>01092 <span class="comment">//C  INPUTR/R/16/3   declination: degree,min,sec</span>
+<a name="l01093"></a>01093 
+<a name="l01094"></a>01094     <span class="comment">/* compute the corrections */</span>
+<a name="l01095"></a>01095     compxy(inputr, inputc, outputr, utr, mod_juldat);
+<a name="l01096"></a>01096 
+<a name="l01097"></a>01097    <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"        Total barycentric RV correction:  %f km/s"</span>, outputr[1]);
+<a name="l01098"></a>01098    <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"        Total heliocentric RV correction: %f km/s"</span>, outputr[2]);
+<a name="l01099"></a>01099    <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"          (incl. diurnal RV correction of %f km/s)"</span>, outputr[3]);
+<a name="l01100"></a>01100 
+<a name="l01101"></a>01101 
+<a name="l01102"></a>01102    *bary_corr = outputr[1];
+<a name="l01103"></a>01103    *helio_corr = outputr[2];
+<a name="l01104"></a>01104 
+<a name="l01105"></a>01105   cleanup:
+<a name="l01106"></a>01106     <span class="keywordflow">if</span> (cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l01107"></a>01107        sinfo_check_rec_status(0);
+<a name="l01108"></a>01108     }
+<a name="l01109"></a>01109     <span class="keywordflow">return</span> cpl_error_get_code();
+<a name="l01110"></a>01110 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__baryvel_8h_source.html b/html/sinfo__baryvel_8h_source.html
new file mode 100644
index 0000000..a6eb1f0
--- /dev/null
+++ b/html/sinfo__baryvel_8h_source.html
@@ -0,0 +1,77 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_baryvel.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_baryvel.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO UVES Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2009/04/28 11:42:18 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.2 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Log: sinfo_baryvel.h,v $</span>
+<a name="l00026"></a>00026 <span class="comment"> * Revision 1.2  2009/04/28 11:42:18  amodigli</span>
+<a name="l00027"></a>00027 <span class="comment"> * now return cpl_error_code</span>
+<a name="l00028"></a>00028 <span class="comment"> *</span>
+<a name="l00029"></a>00029 <span class="comment"> * Revision 1.1  2009/01/02 08:38:07  amodigli</span>
+<a name="l00030"></a>00030 <span class="comment"> * added to CVS</span>
+<a name="l00031"></a>00031 <span class="comment"> *</span>
+<a name="l00032"></a>00032 <span class="comment"> * Revision 1.3  2007/06/06 08:17:33  amodigli</span>
+<a name="l00033"></a>00033 <span class="comment"> * replace tab with 4 spaces</span>
+<a name="l00034"></a>00034 <span class="comment"> *</span>
+<a name="l00035"></a>00035 <span class="comment"> * Revision 1.2  2007/04/24 12:50:29  jmlarsen</span>
+<a name="l00036"></a>00036 <span class="comment"> * Replaced cpl_propertylist -> uves_propertylist which is much faster</span>
+<a name="l00037"></a>00037 <span class="comment"> *</span>
+<a name="l00038"></a>00038 <span class="comment"> * Revision 1.1  2006/10/04 11:03:08  jmlarsen</span>
+<a name="l00039"></a>00039 <span class="comment"> * Implemented QC.VRAD parameters</span>
+<a name="l00040"></a>00040 <span class="comment"> *</span>
+<a name="l00041"></a>00041 <span class="comment"> * Revision 1.4  2006/08/17 13:56:52  jmlarsen</span>
+<a name="l00042"></a>00042 <span class="comment"> * Reduced max line length</span>
+<a name="l00043"></a>00043 <span class="comment"> *</span>
+<a name="l00044"></a>00044 <span class="comment"> * Revision 1.3  2006/02/28 09:15:22  jmlarsen</span>
+<a name="l00045"></a>00045 <span class="comment"> * Minor update</span>
+<a name="l00046"></a>00046 <span class="comment"> *</span>
+<a name="l00047"></a>00047 <span class="comment"> * Revision 1.2  2005/12/19 16:17:56  jmlarsen</span>
+<a name="l00048"></a>00048 <span class="comment"> * Replaced bool -> int</span>
+<a name="l00049"></a>00049 <span class="comment"> *</span>
+<a name="l00050"></a>00050 <span class="comment"> */</span>
+<a name="l00051"></a>00051 <span class="preprocessor">#ifndef SINFO_BARYVEL_H</span>
+<a name="l00052"></a>00052 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_BARYVEL_H</span>
+<a name="l00053"></a>00053 <span class="preprocessor"></span>
+<a name="l00054"></a>00054 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00055"></a>00055 
+<a name="l00056"></a>00056 cpl_error_code
+<a name="l00057"></a>00057 sinfo_baryvel(<span class="keyword">const</span> cpl_propertylist *raw_header,
+<a name="l00058"></a>00058          <span class="keywordtype">double</span> *barycor,
+<a name="l00059"></a>00059          <span class="keywordtype">double</span> *helicor);
+<a name="l00060"></a>00060 
+<a name="l00061"></a>00061 <span class="preprocessor">#endif  </span><span class="comment">/* SINFO_BARYVEL_H */</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__boltzmann_8c_source.html b/html/sinfo__boltzmann_8c_source.html
new file mode 100644
index 0000000..fa12790
--- /dev/null
+++ b/html/sinfo__boltzmann_8c_source.html
@@ -0,0 +1,2292 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_boltzmann.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_boltzmann.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*************************************************************************</span>
+<a name="l00020"></a>00020 <span class="comment">* E.S.O. - VLT project</span>
+<a name="l00021"></a>00021 <span class="comment">*</span>
+<a name="l00022"></a>00022 <span class="comment">*</span>
+<a name="l00023"></a>00023 <span class="comment">*</span>
+<a name="l00024"></a>00024 <span class="comment">* who       when      what</span>
+<a name="l00025"></a>00025 <span class="comment">* --------  --------  ----------------------------------------------</span>
+<a name="l00026"></a>00026 <span class="comment">* schreib  27/02/01  created</span>
+<a name="l00027"></a>00027 <span class="comment">*/</span>
+<a name="l00028"></a>00028 
+<a name="l00029"></a>00029 <span class="comment">/************************************************************************</span>
+<a name="l00030"></a>00030 <span class="comment">*   NAME</span>
+<a name="l00031"></a>00031 <span class="comment">*        new_boltzmann.c -</span>
+<a name="l00032"></a>00032 <span class="comment">*        routines to determine the absolute positions of the slitlets out</span>
+<a name="l00033"></a>00033 <span class="comment">*        of an emission line frame</span>
+<a name="l00034"></a>00034 <span class="comment">*</span>
+<a name="l00035"></a>00035 <span class="comment">*   SYNOPSIS</span>
+<a name="l00036"></a>00036 <span class="comment">*   #include "absolute.h"</span>
+<a name="l00037"></a>00037 <span class="comment">*</span>
+<a name="l00038"></a>00038 <span class="comment">*   1) float sinfo_new_boltz ( float * xdat, float * parlist )</span>
+<a name="l00039"></a>00039 <span class="comment">*   2) void sinfo_new_boltz_deriv( float * xdat, float * parlist, </span>
+<a name="l00040"></a>00040 <span class="comment">                                   float * dervs )</span>
+<a name="l00041"></a>00041 <span class="comment">*   3) static int sinfo_new_inv_mat (void)</span>
+<a name="l00042"></a>00042 <span class="comment">*   4) static void sinfo_new_get_mat ( float * xdat,</span>
+<a name="l00043"></a>00043 <span class="comment">*                            int   * xdim,</span>
+<a name="l00044"></a>00044 <span class="comment">*                            float * ydat,</span>
+<a name="l00045"></a>00045 <span class="comment">*                            float * wdat,</span>
+<a name="l00046"></a>00046 <span class="comment">*                            int   * ndat,</span>
+<a name="l00047"></a>00047 <span class="comment">*                            float * fpar,</span>
+<a name="l00048"></a>00048 <span class="comment">*                            float * epar,</span>
+<a name="l00049"></a>00049 <span class="comment">*                            int   * npar )</span>
+<a name="l00050"></a>00050 <span class="comment">*   5) static int sinfo_new_get_vec ( float * xdat,</span>
+<a name="l00051"></a>00051 <span class="comment">*                           int   * xdim,</span>
+<a name="l00052"></a>00052 <span class="comment">*                           float * ydat,</span>
+<a name="l00053"></a>00053 <span class="comment">*                           float * wdat,</span>
+<a name="l00054"></a>00054 <span class="comment">*                           int   * ndat,</span>
+<a name="l00055"></a>00055 <span class="comment">*                           float * fpar,</span>
+<a name="l00056"></a>00056 <span class="comment">*                           float * epar,</span>
+<a name="l00057"></a>00057 <span class="comment">*                           int   * npar )</span>
+<a name="l00058"></a>00058 <span class="comment">*   6) int sinfo_new_lsqfit ( float * xdat,</span>
+<a name="l00059"></a>00059 <span class="comment">*                   int   * xdim,</span>
+<a name="l00060"></a>00060 <span class="comment">*                   float * ydat,</span>
+<a name="l00061"></a>00061 <span class="comment">*                   float * wdat,</span>
+<a name="l00062"></a>00062 <span class="comment">*                   int   * ndat,</span>
+<a name="l00063"></a>00063 <span class="comment">*                   float * fpar,</span>
+<a name="l00064"></a>00064 <span class="comment">*                   float * epar,</span>
+<a name="l00065"></a>00065 <span class="comment">*                   int   * mpar,</span>
+<a name="l00066"></a>00066 <span class="comment">*                   int   * npar,</span>
+<a name="l00067"></a>00067 <span class="comment">*                   float * tol ,</span>
+<a name="l00068"></a>00068 <span class="comment">*                   int   * its ,</span>
+<a name="l00069"></a>00069 <span class="comment">*                   float * lab  )</span>
+<a name="l00070"></a>00070 <span class="comment">*   7) int sinfo_new_fit_slits_boltz( cpl_image   * lineImage, </span>
+<a name="l00071"></a>00071 <span class="comment">*                         FitParams ** par,</span>
+<a name="l00072"></a>00072 <span class="comment">*                         float     ** slit_pos,</span>
+<a name="l00073"></a>00073 <span class="comment">*                         int          box_length,</span>
+<a name="l00074"></a>00074 <span class="comment">*                         float        y_box,</span>
+<a name="l00075"></a>00075 <span class="comment">*                         float        diff_tol )</span>
+<a name="l00076"></a>00076 <span class="comment">*   8) int sinfo_new_fit_slits_boltz_single_line ( cpl_image   * lineImage, </span>
+<a name="l00077"></a>00077 <span class="comment">*                                    float     ** slit_pos,</span>
+<a name="l00078"></a>00078 <span class="comment">*                                    int          box_length,</span>
+<a name="l00079"></a>00079 <span class="comment">*                                    float        y_box,</span>
+<a name="l00080"></a>00080 <span class="comment">*                                int          low_pos,</span>
+<a name="l00081"></a>00081 <span class="comment">*                                    int          high_pos )</span>
+<a name="l00082"></a>00082 <span class="comment">*   9) int sinfo_new_fit_slits_boltz_with_estimate ( cpl_image   * lineImage, </span>
+<a name="l00083"></a>00083 <span class="comment">*                                      float     ** slit_pos,</span>
+<a name="l00084"></a>00084 <span class="comment">*                                      int          box_length,</span>
+<a name="l00085"></a>00085 <span class="comment">*                                      float        y_box,</span>
+<a name="l00086"></a>00086 <span class="comment">*                                      float        diff_tol,</span>
+<a name="l00087"></a>00087 <span class="comment">*                                      int          low_pos,</span>
+<a name="l00088"></a>00088 <span class="comment">*                           int          high_pos )</span>
+<a name="l00089"></a>00089 <span class="comment">*</span>
+<a name="l00090"></a>00090 <span class="comment">*   DESCRIPTION</span>
+<a name="l00091"></a>00091 <span class="comment">*   1) calculates the value of a Boltzmann function with parameters </span>
+<a name="l00092"></a>00092 <span class="comment">*      parlist at the position xdat </span>
+<a name="l00093"></a>00093 <span class="comment">*   2) calculates the partial derivatives for a Boltzmann function with</span>
+<a name="l00094"></a>00094 <span class="comment">*      parameters parlist at position xdat </span>
+<a name="l00095"></a>00095 <span class="comment">*   3) calculates the inverse of matrix2. The algorithm used </span>
+<a name="l00096"></a>00096 <span class="comment">*      is the Gauss-Jordan algorithm described in Stoer,</span>
+<a name="l00097"></a>00097 <span class="comment">*      Numerische Mathematik, 1. Teil.</span>
+<a name="l00098"></a>00098 <span class="comment">*   4) builds the sinfo_matrix </span>
+<a name="l00099"></a>00099 <span class="comment">*   5) calculates the correction sinfo_vector. The sinfo_matrix has been</span>
+<a name="l00100"></a>00100 <span class="comment">*      built by get_mat(), we only have to rescale it for the </span>
+<a name="l00101"></a>00101 <span class="comment">*      current value of labda. The sinfo_matrix is rescaled so that</span>
+<a name="l00102"></a>00102 <span class="comment">*      the diagonal gets the value 1 + labda.</span>
+<a name="l00103"></a>00103 <span class="comment">*      Next we calculate the inverse of the sinfo_matrix and then</span>
+<a name="l00104"></a>00104 <span class="comment">*      the correction sinfo_vector.</span>
+<a name="l00105"></a>00105 <span class="comment">*   6) this is a routine for making a least-squares fit of a</span>
+<a name="l00106"></a>00106 <span class="comment">*      function to a set of data points. The method used is</span>
+<a name="l00107"></a>00107 <span class="comment">*      described in: Marquardt, J.Soc.Ind.Appl.Math. 11. 431 (1963).</span>
+<a name="l00108"></a>00108 <span class="comment">*      This method is a mixture of the steepest descent method </span>
+<a name="l00109"></a>00109 <span class="comment">*      and the Taylor method.</span>
+<a name="l00110"></a>00110 <span class="comment">*   7) fits the beginning and end position of the slitlets</span>
+<a name="l00111"></a>00111 <span class="comment">*      by using non-linear least square fitting of Boltzmann function</span>
+<a name="l00112"></a>00112 <span class="comment">*      fits a Boltzmann function to the slitlet edges exposed and indicated</span>
+<a name="l00113"></a>00113 <span class="comment">*      by the brightest emission lines. To achieve this, the fit</span>
+<a name="l00114"></a>00114 <span class="comment">*      parameters are used to find the brightest emission line</span>
+<a name="l00115"></a>00115 <span class="comment">*      and to get its position for each column.</span>
+<a name="l00116"></a>00116 <span class="comment">*      The least squares fit is done by using a box smaller than</span>
+<a name="l00117"></a>00117 <span class="comment">*      the size of two slitlets</span>
+<a name="l00118"></a>00118 <span class="comment">*   8) fits the beginning and end position of the slitlets</span>
+<a name="l00119"></a>00119 <span class="comment">*      by using non-linear least square fitting of a Boltzmann function</span>
+<a name="l00120"></a>00120 <span class="comment">*      fits a Boltzmann function to the slitlet edges exposed and indicated</span>
+<a name="l00121"></a>00121 <span class="comment">*      by the brightest emission lines. The slitlet is searched within</span>
+<a name="l00122"></a>00122 <span class="comment">*      user given positions.</span>
+<a name="l00123"></a>00123 <span class="comment">*      The least squares fit is done by using a box smaller than</span>
+<a name="l00124"></a>00124 <span class="comment">*      the size of two slitlets </span>
+<a name="l00125"></a>00125 <span class="comment">*   9) fits the beginning and end position of the slitlets</span>
+<a name="l00126"></a>00126 <span class="comment">*      by using non-linear least square fitting of a Boltzmann function</span>
+<a name="l00127"></a>00127 <span class="comment">*      fits a Boltzmann function to the slitlet edges exposed and indicated</span>
+<a name="l00128"></a>00128 <span class="comment">*      by the brightest emission lines. The slitlet is searched within</span>
+<a name="l00129"></a>00129 <span class="comment">*      user given positions.</span>
+<a name="l00130"></a>00130 <span class="comment">*      The least squares fit is done by using a box smaller than</span>
+<a name="l00131"></a>00131 <span class="comment">*      the size of two slitlets </span>
+<a name="l00132"></a>00132 <span class="comment">*</span>
+<a name="l00133"></a>00133 <span class="comment">*   FILES</span>
+<a name="l00134"></a>00134 <span class="comment">*</span>
+<a name="l00135"></a>00135 <span class="comment">*   ENVIRONMENT</span>
+<a name="l00136"></a>00136 <span class="comment">*</span>
+<a name="l00137"></a>00137 <span class="comment">*   RETURN VALUES</span>
+<a name="l00138"></a>00138 <span class="comment">*</span>
+<a name="l00139"></a>00139 <span class="comment">*   CAUTIONS</span>
+<a name="l00140"></a>00140 <span class="comment">*</span>
+<a name="l00141"></a>00141 <span class="comment">*   EXAMPLES</span>
+<a name="l00142"></a>00142 <span class="comment">*</span>
+<a name="l00143"></a>00143 <span class="comment">*   SEE ALSO</span>
+<a name="l00144"></a>00144 <span class="comment">*</span>
+<a name="l00145"></a>00145 <span class="comment">*   BUGS</span>
+<a name="l00146"></a>00146 <span class="comment">*</span>
+<a name="l00147"></a>00147 <span class="comment">*------------------------------------------------------------------------</span>
+<a name="l00148"></a>00148 <span class="comment">*/</span>
+<a name="l00149"></a>00149 
+<a name="l00150"></a>00150 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00151"></a>00151 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00152"></a>00152 <span class="preprocessor">#endif</span>
+<a name="l00153"></a>00153 <span class="preprocessor"></span><span class="preprocessor">#include "sinfo_vltPort.h"</span>
+<a name="l00154"></a>00154 
+<a name="l00155"></a>00155 <span class="comment">/*</span>
+<a name="l00156"></a>00156 <span class="comment"> * System Headers</span>
+<a name="l00157"></a>00157 <span class="comment"> */</span>
+<a name="l00158"></a>00158 
+<a name="l00159"></a>00159 <span class="comment">/*</span>
+<a name="l00160"></a>00160 <span class="comment"> * Local Headers</span>
+<a name="l00161"></a>00161 <span class="comment"> */</span>
+<a name="l00162"></a>00162 
+<a name="l00163"></a>00163 <span class="preprocessor">#include "sinfo_absolute.h"</span>
+<a name="l00164"></a>00164 <span class="preprocessor">#include "sinfo_recipes.h"</span>
+<a name="l00165"></a>00165 
+<a name="l00166"></a>00166 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00167"></a>00167 <span class="comment"> *                                 Defines</span>
+<a name="l00168"></a>00168 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00169"></a>00169 
+<a name="l00170"></a>00170 <span class="preprocessor">#define XDIMA         1         </span><span class="comment">/* dimension of the x values */</span>
+<a name="l00171"></a>00171 <span class="preprocessor">#define TOLA          0.001     </span><span class="comment">/* fitting tolerance */</span>
+<a name="l00172"></a>00172 <span class="preprocessor">#define LABA          0.1       </span><span class="comment">/* labda parameter */</span>
+<a name="l00173"></a>00173 <span class="preprocessor">#define ITSA          200       </span><span class="comment">/* maximum number of iterations */</span>
+<a name="l00174"></a>00174 <span class="preprocessor">#define LABFACA       10.0      </span><span class="comment">/* labda step factor */</span>
+<a name="l00175"></a>00175 <span class="preprocessor">#define LABMAXA       1.0e+10   </span><span class="comment">/* maximum value for labda */</span>
+<a name="l00176"></a>00176 <span class="preprocessor">#define LABMINA       1.0e-10   </span><span class="comment">/* minimum value for labda */</span>
+<a name="l00177"></a>00177 <span class="preprocessor">#define NPAR          4         </span><span class="comment">/* number of fit parameters */</span>
+<a name="l00178"></a>00178 
+<a name="l00179"></a>00179 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00180"></a>00180 <span class="comment"> *                                    Local variables</span>
+<a name="l00181"></a>00181 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00182"></a>00182 
+<a name="l00183"></a>00183 <span class="keyword">static</span> <span class="keywordtype">double</span> chi1 ;                    <span class="comment">/* old reduced chi-squared */</span>
+<a name="l00184"></a>00184 <span class="keyword">static</span> <span class="keywordtype">double</span> chi2 ;                    <span class="comment">/* new reduced chi-squared */</span>
+<a name="l00185"></a>00185 <span class="keyword">static</span> <span class="keywordtype">double</span> labda ;                   <span class="comment">/* mixing parameter */</span>
+<a name="l00186"></a>00186 <span class="keyword">static</span> <span class="keywordtype">double</span> vec[NPAR] ;               <span class="comment">/* correction sinfo_vector */</span>
+<a name="l00187"></a>00187 <span class="keyword">static</span> <span class="keywordtype">double</span> matrix1[NPAR][NPAR] ;     <span class="comment">/* original sinfo_matrix */</span>
+<a name="l00188"></a>00188 <span class="keyword">static</span> <span class="keywordtype">double</span> matrix2[NPAR][NPAR] ;     <span class="comment">/* inverse of matrix1 */</span>
+<a name="l00189"></a>00189 <span class="keyword">static</span> <span class="keywordtype">int</span>    nfree ;                   <span class="comment">/* number of free parameters */</span>
+<a name="l00190"></a>00190 <span class="keyword">static</span> <span class="keywordtype">int</span>    parptr[NPAR] ;            <span class="comment">/* parameter pointer */</span>
+<a name="l00191"></a>00191 
+<a name="l00192"></a>00192 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00193"></a>00193 <span class="comment"> *                    Functions private to this module</span>
+<a name="l00194"></a>00194 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00195"></a>00195 
+<a name="l00196"></a>00196 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_new_inv_mat (<span class="keywordtype">void</span>) ;
+<a name="l00197"></a>00197 
+<a name="l00198"></a>00198 <span class="keyword">static</span> <span class="keywordtype">void</span> sinfo_new_get_mat ( <span class="keywordtype">float</span> * xdat,
+<a name="l00199"></a>00199                       <span class="keywordtype">int</span>   * xdim,
+<a name="l00200"></a>00200                       <span class="keywordtype">float</span> * ydat,
+<a name="l00201"></a>00201                       <span class="keywordtype">float</span> * wdat,
+<a name="l00202"></a>00202                       <span class="keywordtype">int</span>   * ndat,
+<a name="l00203"></a>00203                       <span class="keywordtype">float</span> * fpar,
+<a name="l00204"></a>00204                       <span class="keywordtype">float</span> * epar<span class="comment">/*,</span>
+<a name="l00205"></a>00205 <span class="comment">                      int   * npar*/</span> ) ;
+<a name="l00206"></a>00206 
+<a name="l00207"></a>00207 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_new_get_vec ( <span class="keywordtype">float</span> * xdat,
+<a name="l00208"></a>00208                      <span class="keywordtype">int</span>   * xdim,
+<a name="l00209"></a>00209                      <span class="keywordtype">float</span> * ydat,
+<a name="l00210"></a>00210                      <span class="keywordtype">float</span> * wdat,
+<a name="l00211"></a>00211                      <span class="keywordtype">int</span>   * ndat,
+<a name="l00212"></a>00212                      <span class="keywordtype">float</span> * fpar,
+<a name="l00213"></a>00213                      <span class="keywordtype">float</span> * epar,
+<a name="l00214"></a>00214                      <span class="keywordtype">int</span>   * npar ) ;
+<a name="l00222"></a>00222 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00223"></a>00223 <span class="comment"> *                            Function codes</span>
+<a name="l00224"></a>00224 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00225"></a>00225 
+<a name="l00245"></a><a class="code" href="group__sinfo__boltzmann.html#ga858ad4d37da835f1ff4740d0f23920c1">00245</a> <span class="keywordtype">float</span> <a class="code" href="group__sinfo__boltzmann.html#ga858ad4d37da835f1ff4740d0f23920c1" title="calculates the value of a Boltzmann function with parameters parlist at the position...">sinfo_new_boltz</a> ( <span class="keywordtype">float</span> * xdat, <span class="keywordtype">float</span> * parlist )
+<a name="l00246"></a>00246 {
+<a name="l00247"></a>00247     <span class="keywordtype">float</span> return_value ;
+<a name="l00248"></a>00248 
+<a name="l00249"></a>00249     <span class="comment">/* now build the boltzman function out of the parameters */</span>
+<a name="l00250"></a>00250     return_value = 
+<a name="l00251"></a>00251     (parlist[0] - parlist[1]) / (1 + exp(( xdat[0] - parlist[2] ) / 
+<a name="l00252"></a>00252      parlist[3])) + parlist[1] ;
+<a name="l00253"></a>00253     
+<a name="l00254"></a>00254     <span class="keywordflow">return</span> return_value ;
+<a name="l00255"></a>00255 }
+<a name="l00256"></a>00256        
+<a name="l00278"></a><a class="code" href="group__sinfo__boltzmann.html#ga72b3c6f0c971fb402bd68c8d0fcf5e30">00278</a> <span class="keywordtype">void</span> <a class="code" href="group__sinfo__boltzmann.html#ga72b3c6f0c971fb402bd68c8d0fcf5e30" title="calculates the partial derivatives for a Boltzmann function with parameters parlist...">sinfo_new_boltz_deriv</a>( <span class="keywordtype">float</span> * xdat, <span class="keywordtype">float</span> * parlist, <span class="keywordtype">floa [...]
+<a name="l00279"></a>00279 {
+<a name="l00280"></a>00280     <span class="keywordtype">float</span> subst ;
+<a name="l00281"></a>00281  
+<a name="l00282"></a>00282     subst = (xdat[0] - parlist[2]) / parlist[3] ;
+<a name="l00283"></a>00283 
+<a name="l00284"></a>00284     dervs[0] = 1. / ( 1. + exp(subst) ) ;
+<a name="l00285"></a>00285 
+<a name="l00286"></a>00286     dervs[1] = -1. / ( 1. + exp(subst) ) + 1. ;
+<a name="l00287"></a>00287 
+<a name="l00288"></a>00288     dervs[2] = ( (parlist[0] - parlist[1]) / parlist[3] * exp(subst) ) /
+<a name="l00289"></a>00289                ( (1. + exp(subst)) * (1. + exp(subst)) ) ;
+<a name="l00290"></a>00290 
+<a name="l00291"></a>00291     dervs[3] = ( (parlist[0] - parlist[1]) * (xdat[0] - parlist[2]) /
+<a name="l00292"></a>00292                (parlist[3]*parlist[3]) * exp(subst) ) /
+<a name="l00293"></a>00293                ( (1. + exp(subst)) * (1. + exp(subst)) ) ;
+<a name="l00294"></a>00294 }
+<a name="l00295"></a>00295 
+<a name="l00306"></a>00306 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_new_inv_mat (<span class="keywordtype">void</span>)
+<a name="l00307"></a>00307 {
+<a name="l00308"></a>00308     <span class="keywordtype">double</span> even ;
+<a name="l00309"></a>00309     <span class="keywordtype">double</span> hv[NPAR] ;
+<a name="l00310"></a>00310     <span class="keywordtype">double</span> mjk ;
+<a name="l00311"></a>00311     <span class="keywordtype">double</span> rowmax ;
+<a name="l00312"></a>00312     <span class="keywordtype">int</span> evin ;
+<a name="l00313"></a>00313     <span class="keywordtype">int</span> i, j, k, row ;
+<a name="l00314"></a>00314     <span class="keywordtype">int</span> per[NPAR] ;
+<a name="l00315"></a>00315    
+<a name="l00316"></a>00316     <span class="comment">/* set permutation array */</span>
+<a name="l00317"></a>00317     <span class="keywordflow">for</span> ( i = 0 ; i < nfree ; i++ )
+<a name="l00318"></a>00318     {
+<a name="l00319"></a>00319         per[i] = i ;
+<a name="l00320"></a>00320     }
+<a name="l00321"></a>00321     
+<a name="l00322"></a>00322     <span class="keywordflow">for</span> ( j = 0 ; j < nfree ; j++ ) <span class="comment">/* in j-th column */</span>
+<a name="l00323"></a>00323     {
+<a name="l00324"></a>00324         <span class="comment">/* determine largest element of a row */</span>                                
+<a name="l00325"></a>00325         rowmax = fabs ( matrix2[j][j] ) ;
+<a name="l00326"></a>00326         row = j ;                         
+<a name="l00327"></a>00327 
+<a name="l00328"></a>00328         <span class="keywordflow">for</span> ( i = j + 1 ; i < nfree ; i++ )
+<a name="l00329"></a>00329         {
+<a name="l00330"></a>00330             <span class="keywordflow">if</span> ( fabs ( matrix2[i][j] ) > rowmax )
+<a name="l00331"></a>00331             {
+<a name="l00332"></a>00332                 rowmax = fabs( matrix2[i][j] ) ;
+<a name="l00333"></a>00333                 row = i ;
+<a name="l00334"></a>00334             }
+<a name="l00335"></a>00335         }
+<a name="l00336"></a>00336 
+<a name="l00337"></a>00337         <span class="comment">/* determinant is zero! */</span>
+<a name="l00338"></a>00338         <span class="keywordflow">if</span> ( matrix2[row][j] == 0.0 )
+<a name="l00339"></a>00339         {
+<a name="l00340"></a>00340             <span class="keywordflow">return</span> -6 ;
+<a name="l00341"></a>00341         }
+<a name="l00342"></a>00342         
+<a name="l00343"></a>00343         <span class="comment">/* if the largest element is not on the diagonal, then permutate rows */</span>
+<a name="l00344"></a>00344         <span class="keywordflow">if</span> ( row > j )
+<a name="l00345"></a>00345         {
+<a name="l00346"></a>00346             <span class="keywordflow">for</span> ( k = 0 ; k < nfree ; k++ )
+<a name="l00347"></a>00347             {
+<a name="l00348"></a>00348                 even = matrix2[j][k] ;
+<a name="l00349"></a>00349                 matrix2[j][k] = matrix2[row][k] ;
+<a name="l00350"></a>00350                 matrix2[row][k] = even ;
+<a name="l00351"></a>00351             }
+<a name="l00352"></a>00352             <span class="comment">/* keep track of permutation */</span>
+<a name="l00353"></a>00353             evin = per[j] ;
+<a name="l00354"></a>00354             per[j] = per[row] ;
+<a name="l00355"></a>00355             per[row] = evin ;
+<a name="l00356"></a>00356         }
+<a name="l00357"></a>00357         
+<a name="l00358"></a>00358         <span class="comment">/* modify column */</span>
+<a name="l00359"></a>00359         even = 1.0 / matrix2[j][j] ;
+<a name="l00360"></a>00360         <span class="keywordflow">for</span> ( i = 0 ; i < nfree ; i++ )
+<a name="l00361"></a>00361         {
+<a name="l00362"></a>00362             matrix2[i][j] *= even ;
+<a name="l00363"></a>00363         }
+<a name="l00364"></a>00364         matrix2[j][j] = even ;
+<a name="l00365"></a>00365         
+<a name="l00366"></a>00366         <span class="keywordflow">for</span> ( k = 0 ; k < j ; k++ )
+<a name="l00367"></a>00367         {
+<a name="l00368"></a>00368             mjk = matrix2[j][k] ;
+<a name="l00369"></a>00369             <span class="keywordflow">for</span> ( i = 0 ; i < j ; i++ )
+<a name="l00370"></a>00370             {
+<a name="l00371"></a>00371                 matrix2[i][k] -= matrix2[i][j] * mjk ;
+<a name="l00372"></a>00372             }
+<a name="l00373"></a>00373             <span class="keywordflow">for</span> ( i = j + 1 ; i < nfree ; i++ )
+<a name="l00374"></a>00374             {
+<a name="l00375"></a>00375                 matrix2[i][k] -= matrix2[i][j] * mjk ;
+<a name="l00376"></a>00376             }
+<a name="l00377"></a>00377             matrix2[j][k] = -even * mjk ;
+<a name="l00378"></a>00378         }
+<a name="l00379"></a>00379     
+<a name="l00380"></a>00380         <span class="keywordflow">for</span> ( k = j + 1 ; k < nfree ; k++ )
+<a name="l00381"></a>00381         {
+<a name="l00382"></a>00382             mjk = matrix2[j][k] ;
+<a name="l00383"></a>00383             <span class="keywordflow">for</span> ( i = 0 ; i < j ; i++ )
+<a name="l00384"></a>00384             {
+<a name="l00385"></a>00385                 matrix2[i][k]  -= matrix2[i][j] * mjk ;
+<a name="l00386"></a>00386             }
+<a name="l00387"></a>00387             <span class="keywordflow">for</span> ( i = j + 1 ; i < nfree ; i++ )
+<a name="l00388"></a>00388             {
+<a name="l00389"></a>00389                 matrix2[i][k]  -= matrix2[i][j] * mjk ;
+<a name="l00390"></a>00390             }
+<a name="l00391"></a>00391             matrix2[j][k] = -even * mjk ;
+<a name="l00392"></a>00392         }
+<a name="l00393"></a>00393     }
+<a name="l00394"></a>00394     
+<a name="l00395"></a>00395     <span class="comment">/* finally, repermute the columns */</span>
+<a name="l00396"></a>00396     <span class="keywordflow">for</span> ( i = 0 ; i < nfree ; i++ )
+<a name="l00397"></a>00397     {
+<a name="l00398"></a>00398         <span class="keywordflow">for</span> ( k = 0 ; k < nfree ; k++ )
+<a name="l00399"></a>00399         {
+<a name="l00400"></a>00400             hv[per[k]] = matrix2[i][k] ;
+<a name="l00401"></a>00401         }
+<a name="l00402"></a>00402         <span class="keywordflow">for</span> ( k = 0 ; k < nfree ; k++ )
+<a name="l00403"></a>00403         {
+<a name="l00404"></a>00404             matrix2[i][k] = hv[k] ;
+<a name="l00405"></a>00405         }
+<a name="l00406"></a>00406     }
+<a name="l00407"></a>00407         
+<a name="l00408"></a>00408     <span class="comment">/* all is well */</span>
+<a name="l00409"></a>00409     <span class="keywordflow">return</span> 0 ;
+<a name="l00410"></a>00410 }
+<a name="l00411"></a>00411     
+<a name="l00426"></a>00426 <span class="keyword">static</span> <span class="keywordtype">void</span> sinfo_new_get_mat ( <span class="keywordtype">float</span> * xdat,
+<a name="l00427"></a>00427                       <span class="keywordtype">int</span>   * xdim,
+<a name="l00428"></a>00428                       <span class="keywordtype">float</span> * ydat,
+<a name="l00429"></a>00429                       <span class="keywordtype">float</span> * wdat,
+<a name="l00430"></a>00430                       <span class="keywordtype">int</span>   * ndat,
+<a name="l00431"></a>00431                       <span class="keywordtype">float</span> * fpar,
+<a name="l00432"></a>00432                       <span class="keywordtype">float</span> * epar<span class="comment">/*,</span>
+<a name="l00433"></a>00433 <span class="comment">                      int   * npar*/</span> )
+<a name="l00434"></a>00434 {
+<a name="l00435"></a>00435     <span class="keywordtype">double</span> wd ;
+<a name="l00436"></a>00436     <span class="keywordtype">double</span> wn ;
+<a name="l00437"></a>00437     <span class="keywordtype">double</span> yd ;
+<a name="l00438"></a>00438     <span class="keywordtype">int</span> i, j, n ;
+<a name="l00439"></a>00439 
+<a name="l00440"></a>00440     <span class="keywordflow">for</span> ( j = 0 ; j < nfree ; j++ )
+<a name="l00441"></a>00441     {
+<a name="l00442"></a>00442         vec[j] = 0.0 ; <span class="comment">/* zero sinfo_vector */</span>
+<a name="l00443"></a>00443         <span class="keywordflow">for</span> ( i = 0 ; i<= j ; i++ ) <span class="comment">/* zero sinfo_matrix only </span>
+<a name="l00444"></a>00444 <span class="comment">                                       on and below diagonal */</span>
+<a name="l00445"></a>00445         {
+<a name="l00446"></a>00446             matrix1[j][i] = 0.0 ;
+<a name="l00447"></a>00447         }
+<a name="l00448"></a>00448     }
+<a name="l00449"></a>00449     chi2 = 0.0 ;  <span class="comment">/* reset reduced chi-squared */</span>
+<a name="l00450"></a>00450     
+<a name="l00451"></a>00451     <span class="comment">/* loop through data points */</span>
+<a name="l00452"></a>00452     <span class="keywordflow">for</span> ( n = 0 ; n < (*ndat) ; n++ )
+<a name="l00453"></a>00453     {
+<a name="l00454"></a>00454         wn = wdat[n] ;
+<a name="l00455"></a>00455         <span class="keywordflow">if</span> ( wn > 0.0 )  <span class="comment">/* legal weight ? */</span>
+<a name="l00456"></a>00456         {
+<a name="l00457"></a>00457             yd = ydat[n] - <a class="code" href="group__sinfo__boltzmann.html#ga858ad4d37da835f1ff4740d0f23920c1" title="calculates the value of a Boltzmann function with parameters parlist at the position...">sinfo_new_boltz</a>( &xdat[(*xdim) * n], fpar ) ;
+<a name="l00458"></a>00458             <a class="code" href="group__sinfo__boltzmann.html#ga72b3c6f0c971fb402bd68c8d0fcf5e30" title="calculates the partial derivatives for a Boltzmann function with parameters parlist...">sinfo_new_boltz_deriv</a>( &xdat[(*xdim) * n], fpar, epar ) ;
+<a name="l00459"></a>00459             chi2 += yd * yd * wn ; <span class="comment">/* add to chi-squared */</span>
+<a name="l00460"></a>00460             <span class="keywordflow">for</span> ( j = 0 ; j < nfree ; j++ )
+<a name="l00461"></a>00461             {
+<a name="l00462"></a>00462                 wd = epar[parptr[j]] * wn ;  <span class="comment">/* weighted derivative */</span>
+<a name="l00463"></a>00463                 vec[j] += yd * wd ;       <span class="comment">/* fill sinfo_vector */</span>
+<a name="l00464"></a>00464                 <span class="keywordflow">for</span> ( i = 0 ; i <= j ; i++ ) <span class="comment">/* fill sinfo_matrix */</span>
+<a name="l00465"></a>00465                 {
+<a name="l00466"></a>00466                     matrix1[j][i] += epar[parptr[i]] * wd ;
+<a name="l00467"></a>00467                 }
+<a name="l00468"></a>00468             }
+<a name="l00469"></a>00469         }
+<a name="l00470"></a>00470     }                   
+<a name="l00471"></a>00471 }  
+<a name="l00472"></a>00472                 
+<a name="l00473"></a>00473             
+<a name="l00495"></a>00495 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_new_get_vec ( <span class="keywordtype">float</span> * xdat,
+<a name="l00496"></a>00496                      <span class="keywordtype">int</span>   * xdim,
+<a name="l00497"></a>00497                      <span class="keywordtype">float</span> * ydat,
+<a name="l00498"></a>00498                      <span class="keywordtype">float</span> * wdat,
+<a name="l00499"></a>00499                      <span class="keywordtype">int</span>   * ndat,
+<a name="l00500"></a>00500                      <span class="keywordtype">float</span> * fpar,
+<a name="l00501"></a>00501                      <span class="keywordtype">float</span> * epar,
+<a name="l00502"></a>00502                      <span class="keywordtype">int</span>   * npar )
+<a name="l00503"></a>00503 {
+<a name="l00504"></a>00504     <span class="keywordtype">double</span> dj ;
+<a name="l00505"></a>00505     <span class="keywordtype">double</span> dy ;
+<a name="l00506"></a>00506     <span class="keywordtype">double</span> mii ;
+<a name="l00507"></a>00507     <span class="keywordtype">double</span> mji ;
+<a name="l00508"></a>00508     <span class="keywordtype">double</span> mjj ;
+<a name="l00509"></a>00509     <span class="keywordtype">double</span> wn ;
+<a name="l00510"></a>00510     <span class="keywordtype">int</span> i, j, n, r ;
+<a name="l00511"></a>00511 
+<a name="l00512"></a>00512     <span class="comment">/* loop to modify and scale the sinfo_matrix */</span>
+<a name="l00513"></a>00513     <span class="keywordflow">for</span> ( j = 0 ; j < nfree ; j++ )
+<a name="l00514"></a>00514     {
+<a name="l00515"></a>00515         mjj = matrix1[j][j] ;
+<a name="l00516"></a>00516         <span class="keywordflow">if</span> ( mjj <= 0.0 )             <span class="comment">/* diagonal element wrong */</span>
+<a name="l00517"></a>00517         {
+<a name="l00518"></a>00518             <span class="keywordflow">return</span> -5 ;
+<a name="l00519"></a>00519         }
+<a name="l00520"></a>00520         mjj = sqrt( mjj ) ;
+<a name="l00521"></a>00521         <span class="keywordflow">for</span> ( i = 0 ; i < j ; i++ )
+<a name="l00522"></a>00522         {
+<a name="l00523"></a>00523             mji = matrix1[j][i] / mjj / sqrt( matrix1[i][i] ) ;
+<a name="l00524"></a>00524             matrix2[i][j] = matrix2[j][i] = mji ;
+<a name="l00525"></a>00525         }
+<a name="l00526"></a>00526         matrix2[j][j] = 1.0 + labda ;  <span class="comment">/* scaled value on diagonal */</span>
+<a name="l00527"></a>00527     }    
+<a name="l00528"></a>00528     
+<a name="l00529"></a>00529     <span class="keywordflow">if</span> ( (r = sinfo_new_inv_mat()) ) <span class="comment">/* sinfo_invert sinfo_matrix inlace */</span>
+<a name="l00530"></a>00530     {
+<a name="l00531"></a>00531         <span class="keywordflow">return</span> r ;
+<a name="l00532"></a>00532     }
+<a name="l00533"></a>00533     
+<a name="l00534"></a>00534     <span class="keywordflow">for</span> ( i = 0 ; i < (*npar) ; i ++ )
+<a name="l00535"></a>00535     {
+<a name="l00536"></a>00536         epar[i] = fpar[i] ;
+<a name="l00537"></a>00537     }
+<a name="l00538"></a>00538     
+<a name="l00539"></a>00539     <span class="comment">/* loop to calculate correction sinfo_vector */</span>
+<a name="l00540"></a>00540     <span class="keywordflow">for</span> ( j = 0 ; j < nfree ; j++ )
+<a name="l00541"></a>00541     {
+<a name="l00542"></a>00542         dj = 0.0 ;
+<a name="l00543"></a>00543         mjj = matrix1[j][j] ;
+<a name="l00544"></a>00544         <span class="keywordflow">if</span> ( mjj <= 0.0)               <span class="comment">/* not allowed */</span>
+<a name="l00545"></a>00545         {
+<a name="l00546"></a>00546             <span class="keywordflow">return</span> -7 ;
+<a name="l00547"></a>00547         }
+<a name="l00548"></a>00548         mjj = sqrt ( mjj ) ;
+<a name="l00549"></a>00549         <span class="keywordflow">for</span> ( i = 0 ; i < nfree ; i++ )
+<a name="l00550"></a>00550         {
+<a name="l00551"></a>00551             mii = matrix1[i][i] ;
+<a name="l00552"></a>00552             <span class="keywordflow">if</span> ( mii <= 0.0 )
+<a name="l00553"></a>00553             {
+<a name="l00554"></a>00554                 <span class="keywordflow">return</span> -7 ;
+<a name="l00555"></a>00555             }
+<a name="l00556"></a>00556             mii = sqrt( mii ) ;
+<a name="l00557"></a>00557             dj += vec[i] * matrix2[j][i] / mjj / mii ;
+<a name="l00558"></a>00558         }
+<a name="l00559"></a>00559         epar[parptr[j]] += dj ;       <span class="comment">/* new parameters */</span>
+<a name="l00560"></a>00560     }    
+<a name="l00561"></a>00561     chi1 = 0.0 ;                      <span class="comment">/* reset reduced chi-squared */</span>
+<a name="l00562"></a>00562  
+<a name="l00563"></a>00563     <span class="comment">/* loop through the data points */</span>
+<a name="l00564"></a>00564     <span class="keywordflow">for</span> ( n = 0 ; n < (*ndat) ; n++ )
+<a name="l00565"></a>00565     {
+<a name="l00566"></a>00566         wn = wdat[n] ;               <span class="comment">/* get weight */</span>
+<a name="l00567"></a>00567         <span class="keywordflow">if</span> ( wn > 0.0 )              <span class="comment">/* legal weight */</span>
+<a name="l00568"></a>00568         {
+<a name="l00569"></a>00569             dy = ydat[n] - <a class="code" href="group__sinfo__boltzmann.html#ga858ad4d37da835f1ff4740d0f23920c1" title="calculates the value of a Boltzmann function with parameters parlist at the position...">sinfo_new_boltz</a>( &xdat[(*xdim) * n], epar) ;
+<a name="l00570"></a>00570             chi1 += wdat[n] * dy * dy ;
+<a name="l00571"></a>00571         }
+<a name="l00572"></a>00572     }
+<a name="l00573"></a>00573     <span class="keywordflow">return</span> 0 ;
+<a name="l00574"></a>00574 }   
+<a name="l00575"></a>00575     
+<a name="l00576"></a>00576         
+<a name="l00577"></a>00577 
+<a name="l00627"></a><a class="code" href="group__sinfo__boltzmann.html#ga7e03e34851f7c367ab3827c58e8c81c5">00627</a> <span class="keywordtype">int</span> <a class="code" href="group__sinfo__boltzmann.html#ga7e03e34851f7c367ab3827c58e8c81c5" title="makes a least-squares fit of a function to a set of data points.">sinfo_new_lsqfit</a> ( <span class="keywordtype">float</span> * xdat,
+<a name="l00628"></a>00628              <span class="keywordtype">int</span>   * xdim,
+<a name="l00629"></a>00629              <span class="keywordtype">float</span> * ydat,
+<a name="l00630"></a>00630              <span class="keywordtype">float</span> * wdat,
+<a name="l00631"></a>00631              <span class="keywordtype">int</span>   * ndat,
+<a name="l00632"></a>00632              <span class="keywordtype">float</span> * fpar,
+<a name="l00633"></a>00633              <span class="keywordtype">float</span> * epar,
+<a name="l00634"></a>00634              <span class="keywordtype">int</span>   * mpar,
+<a name="l00635"></a>00635              <span class="keywordtype">int</span>   * npar,
+<a name="l00636"></a>00636              <span class="keywordtype">float</span> * tol ,
+<a name="l00637"></a>00637              <span class="keywordtype">int</span>   * its ,
+<a name="l00638"></a>00638              <span class="keywordtype">float</span> * lab  )
+<a name="l00639"></a>00639 {
+<a name="l00640"></a>00640     <span class="keywordtype">int</span> i, n, r ;
+<a name="l00641"></a>00641     <span class="keywordtype">int</span> itc ;                      <span class="comment">/* fate of fit */</span>
+<a name="l00642"></a>00642     <span class="keywordtype">int</span> found ;                    <span class="comment">/* fit converged: 1, not yet converged: 0 */</span>
+<a name="l00643"></a>00643     <span class="keywordtype">int</span>  nuse ;                    <span class="comment">/* number of useable data points */</span>
+<a name="l00644"></a>00644     <span class="keywordtype">double</span> tolerance ;             <span class="comment">/* accuracy */</span>
+<a name="l00645"></a>00645 
+<a name="l00646"></a>00646     itc   = 0 ;                    <span class="comment">/* fate of fit */</span>
+<a name="l00647"></a>00647     found = 0 ;                    <span class="comment">/* reset */</span>
+<a name="l00648"></a>00648     nfree = 0 ;                    <span class="comment">/* number of free parameters */</span>
+<a name="l00649"></a>00649     nuse  = 0 ;                    <span class="comment">/* number of legal data points */</span>
+<a name="l00650"></a>00650 
+<a name="l00651"></a>00651     <span class="keywordflow">if</span> ( *tol < (FLT_EPSILON * 10.0 ) )
+<a name="l00652"></a>00652     {
+<a name="l00653"></a>00653         tolerance = FLT_EPSILON * 10.0 ;  <span class="comment">/* default tolerance */</span>
+<a name="l00654"></a>00654     }
+<a name="l00655"></a>00655     <span class="keywordflow">else</span>
+<a name="l00656"></a>00656     {
+<a name="l00657"></a>00657         tolerance = *tol ;                <span class="comment">/* tolerance */</span>
+<a name="l00658"></a>00658     }
+<a name="l00659"></a>00659     
+<a name="l00660"></a>00660     labda = fabs( *lab ) * LABFACA ;   <span class="comment">/* start value for mixing parameter */</span>
+<a name="l00661"></a>00661     <span class="keywordflow">for</span> ( i = 0 ; i < (*npar) ; i++ )
+<a name="l00662"></a>00662     {
+<a name="l00663"></a>00663         <span class="keywordflow">if</span> ( mpar[i] )
+<a name="l00664"></a>00664         {
+<a name="l00665"></a>00665             <span class="keywordflow">if</span> ( nfree > NPAR )         <span class="comment">/* too many free parameters */</span>
+<a name="l00666"></a>00666             {
+<a name="l00667"></a>00667                 <span class="keywordflow">return</span> -1 ;
+<a name="l00668"></a>00668             }
+<a name="l00669"></a>00669             parptr[nfree++] = i ;         <span class="comment">/* a free parameter */</span>
+<a name="l00670"></a>00670         }
+<a name="l00671"></a>00671     }
+<a name="l00672"></a>00672     
+<a name="l00673"></a>00673     <span class="keywordflow">if</span> (nfree == 0)                       <span class="comment">/* no free parameters */</span>     
+<a name="l00674"></a>00674     {
+<a name="l00675"></a>00675         <span class="keywordflow">return</span> -2 ;
+<a name="l00676"></a>00676     }
+<a name="l00677"></a>00677     
+<a name="l00678"></a>00678     <span class="keywordflow">for</span> ( n = 0 ; n < (*ndat) ; n++ )
+<a name="l00679"></a>00679     {
+<a name="l00680"></a>00680         <span class="keywordflow">if</span> ( wdat[n] > 0.0 )              <span class="comment">/* legal weight */</span>
+<a name="l00681"></a>00681         {
+<a name="l00682"></a>00682             nuse ++ ;
+<a name="l00683"></a>00683         }
+<a name="l00684"></a>00684     }
+<a name="l00685"></a>00685     
+<a name="l00686"></a>00686     <span class="keywordflow">if</span> ( nfree >= nuse )
+<a name="l00687"></a>00687     {
+<a name="l00688"></a>00688         <span class="keywordflow">return</span> -3 ;                       <span class="comment">/* no degrees of freedom */</span>
+<a name="l00689"></a>00689     }
+<a name="l00690"></a>00690     <span class="keywordflow">if</span> ( labda == 0.0 )                   <span class="comment">/* linear fit */</span>
+<a name="l00691"></a>00691     {
+<a name="l00692"></a>00692         <span class="comment">/* initialize fpar array */</span>
+<a name="l00693"></a>00693         <span class="keywordflow">for</span> ( i = 0 ; i < nfree ; fpar[parptr[i++]] = 0.0 ) ;  
+<a name="l00694"></a>00694         sinfo_new_get_mat(xdat,xdim,ydat,wdat,ndat,fpar,epar<span class="comment">/*, npar*/</span> ) ;
+<a name="l00695"></a>00695         r =  sinfo_new_get_vec(xdat,xdim,ydat,wdat,ndat,fpar,epar,npar) ;
+<a name="l00696"></a>00696         <span class="keywordflow">if</span> ( r )                         <span class="comment">/* error */</span>
+<a name="l00697"></a>00697         {
+<a name="l00698"></a>00698             <span class="keywordflow">return</span> r ;
+<a name="l00699"></a>00699         }
+<a name="l00700"></a>00700         <span class="keywordflow">for</span> ( i = 0 ; i < (*npar) ; i++ )
+<a name="l00701"></a>00701         {
+<a name="l00702"></a>00702             fpar[i] = epar[i] ;           <span class="comment">/* save new parameters */</span>
+<a name="l00703"></a>00703             epar[i] = 0.0 ;               <span class="comment">/* and set errors to zero */</span>
+<a name="l00704"></a>00704         }
+<a name="l00705"></a>00705         chi1 = sqrt( chi1 / (<span class="keywordtype">double</span>) (nuse - nfree) ) ;
+<a name="l00706"></a>00706         <span class="keywordflow">for</span> ( i = 0 ; i < nfree ; i++ )
+<a name="l00707"></a>00707         {
+<a name="l00708"></a>00708             <span class="keywordflow">if</span> ( (matrix1[i][i] <= 0.0 ) || (matrix2[i][i] <= 0.0) )
+<a name="l00709"></a>00709             {
+<a name="l00710"></a>00710                 <span class="keywordflow">return</span> -7 ;
+<a name="l00711"></a>00711             }
+<a name="l00712"></a>00712             epar[parptr[i]] = chi1 * sqrt( matrix2[i][i] ) / 
+<a name="l00713"></a>00713                                      sqrt( matrix1[i][i] ) ;
+<a name="l00714"></a>00714         }
+<a name="l00715"></a>00715     }
+<a name="l00716"></a>00716     <span class="keywordflow">else</span>                                  <span class="comment">/* non-linear fit */</span>
+<a name="l00717"></a>00717     {
+<a name="l00718"></a>00718         <span class="comment">/*----------------------------------------------------------------</span>
+<a name="l00719"></a>00719 <span class="comment">         * the non-linear fit uses the steepest descent method in combination</span>
+<a name="l00720"></a>00720 <span class="comment">         * with the Taylor method. The mixing of these methods is controlled</span>
+<a name="l00721"></a>00721 <span class="comment">         * by labda. In the outer loop ( called the iteration loop ) we build</span>
+<a name="l00722"></a>00722 <span class="comment">         * the sinfo_matrix and calculate the correction sinfo_vector. </span>
+<a name="l00723"></a>00723 <span class="comment">         * In the inner loop</span>
+<a name="l00724"></a>00724 <span class="comment">         * (called the interpolation loop) we check whether we have obtained a</span>
+<a name="l00725"></a>00725 <span class="comment">         * better solution than the previous one. If so, we leave the inner </span>
+<a name="l00726"></a>00726 <span class="comment">         * loop</span>
+<a name="l00727"></a>00727 <span class="comment">         * else we increase labda ( give more weight to the steepest descent </span>
+<a name="l00728"></a>00728 <span class="comment">         * method) calculate the correction sinfo_vector and check again. </span>
+<a name="l00729"></a>00729 <span class="comment">         * After the inner loop</span>
+<a name="l00730"></a>00730 <span class="comment">         * we do a final check on the goodness of the fit and if this satisfies</span>
+<a name="l00731"></a>00731 <span class="comment">         * the tolerance we calculate the errors of the fitted parameters.</span>
+<a name="l00732"></a>00732 <span class="comment">         */</span>
+<a name="l00733"></a>00733         <span class="keywordflow">while</span> ( !found )                  <span class="comment">/* iteration loop */</span>
+<a name="l00734"></a>00734         {      
+<a name="l00735"></a>00735             <span class="keywordflow">if</span> ( itc++ == (*its) )        <span class="comment">/* increase iteration counter */</span>
+<a name="l00736"></a>00736             {
+<a name="l00737"></a>00737                 <span class="keywordflow">return</span> -4 ;               
+<a name="l00738"></a>00738             }
+<a name="l00739"></a>00739             sinfo_new_get_mat(xdat,xdim,ydat,wdat,ndat,fpar,epar<span class="comment">/*, npar */</span>) ;
+<a name="l00740"></a>00740             
+<a name="l00741"></a>00741             <span class="comment">/*-------------------------------------------------------------</span>
+<a name="l00742"></a>00742 <span class="comment">             * here we decrease labda since we may assume that each iteration</span>
+<a name="l00743"></a>00743 <span class="comment">             * brings us closer to the answer.</span>
+<a name="l00744"></a>00744 <span class="comment">             */</span>
+<a name="l00745"></a>00745             <span class="keywordflow">if</span> ( labda > LABMINA )
+<a name="l00746"></a>00746             {
+<a name="l00747"></a>00747                 labda = labda / LABFACA ;         <span class="comment">/* decrease labda */</span>
+<a name="l00748"></a>00748             }
+<a name="l00749"></a>00749             r = sinfo_new_get_vec ( xdat, xdim, ydat, wdat, 
+<a name="l00750"></a>00750                                     ndat, fpar, epar, npar ) ;
+<a name="l00751"></a>00751 
+<a name="l00752"></a>00752             <span class="keywordflow">if</span> ( r )                      <span class="comment">/* error */</span>
+<a name="l00753"></a>00753             {
+<a name="l00754"></a>00754                 <span class="keywordflow">return</span> r ;
+<a name="l00755"></a>00755             }
+<a name="l00756"></a>00756 
+<a name="l00757"></a>00757             <span class="keywordflow">while</span> ( chi1 >= chi2 )        <span class="comment">/* interpolation loop */</span>
+<a name="l00758"></a>00758             {
+<a name="l00759"></a>00759                 <span class="comment">/*-----------------------------------------------------------</span>
+<a name="l00760"></a>00760 <span class="comment">                 * The next statement is based on experience, not on the </span>
+<a name="l00761"></a>00761 <span class="comment">                 * mathematics of the problem. It is assumed that we have </span>
+<a name="l00762"></a>00762 <span class="comment">                 * reached convergence when the pure steepest descent method </span>
+<a name="l00763"></a>00763 <span class="comment">                 * does not produce a better solution.</span>
+<a name="l00764"></a>00764 <span class="comment">                 */</span>
+<a name="l00765"></a>00765                 <span class="keywordflow">if</span> ( labda > LABMAXA )    <span class="comment">/* assume solution found */</span>
+<a name="l00766"></a>00766                 {
+<a name="l00767"></a>00767                     break ;
+<a name="l00768"></a>00768                 }
+<a name="l00769"></a>00769                 labda = labda * LABFACA ;  <span class="comment">/* increase mixing parameter */</span>
+<a name="l00770"></a>00770                 r = sinfo_new_get_vec ( xdat, xdim, ydat, wdat, 
+<a name="l00771"></a>00771                                         ndat, fpar, epar, npar ) ;
+<a name="l00772"></a>00772 
+<a name="l00773"></a>00773                 <span class="keywordflow">if</span> ( r )                  <span class="comment">/* error */</span>
+<a name="l00774"></a>00774                 {
+<a name="l00775"></a>00775                     <span class="keywordflow">return</span> r ;
+<a name="l00776"></a>00776                 }
+<a name="l00777"></a>00777             }
+<a name="l00778"></a>00778 
+<a name="l00779"></a>00779             <span class="keywordflow">if</span> ( labda <= LABMAXA )        <span class="comment">/* save old parameters */</span>
+<a name="l00780"></a>00780             {
+<a name="l00781"></a>00781                 <span class="keywordflow">for</span> ( i = 0 ; i < *npar ; i++ )
+<a name="l00782"></a>00782                 {
+<a name="l00783"></a>00783                     fpar[i] = epar[i] ;
+<a name="l00784"></a>00784                 }
+<a name="l00785"></a>00785             }
+<a name="l00786"></a>00786             <span class="keywordflow">if</span> ( (fabs( chi2 - chi1 ) <= (tolerance * chi1)) || 
+<a name="l00787"></a>00787                  (labda > LABMAXA) )
+<a name="l00788"></a>00788             {
+<a name="l00789"></a>00789                 <span class="comment">/*---------------------------------------------------------</span>
+<a name="l00790"></a>00790 <span class="comment">                 * we have a satisfying solution, so now we need to calculate </span>
+<a name="l00791"></a>00791 <span class="comment">                 * the correct errors of the fitted parameters. This we do by </span>
+<a name="l00792"></a>00792 <span class="comment">                 * using the pure Taylor method because we are very close to </span>
+<a name="l00793"></a>00793 <span class="comment">                 * the real solution.</span>
+<a name="l00794"></a>00794 <span class="comment">                 */</span>
+<a name="l00795"></a>00795                 labda = LABMINA ;              <span class="comment">/* for Taylor solution */</span>
+<a name="l00796"></a>00796                 sinfo_new_get_mat(xdat,xdim,ydat,wdat,ndat,fpar,epar<span class="comment">/*,npar*/</span>);
+<a name="l00797"></a>00797                 r = sinfo_new_get_vec(xdat,xdim,ydat,wdat,ndat,fpar,epar,npar);
+<a name="l00798"></a>00798 
+<a name="l00799"></a>00799                 <span class="keywordflow">if</span> ( r )                    <span class="comment">/* error */</span>
+<a name="l00800"></a>00800                 {
+<a name="l00801"></a>00801                     <span class="keywordflow">return</span> r ;
+<a name="l00802"></a>00802                 }
+<a name="l00803"></a>00803                 <span class="keywordflow">for</span> ( i = 0 ; i < (*npar) ; i++ )
+<a name="l00804"></a>00804                 {
+<a name="l00805"></a>00805                     epar[i] = 0.0 ;          <span class="comment">/* set error to zero */</span>
+<a name="l00806"></a>00806                 }
+<a name="l00807"></a>00807                 chi2 = sqrt ( chi2 / (<span class="keywordtype">double</span>) (nuse - nfree) ) ;
+<a name="l00808"></a>00808 
+<a name="l00809"></a>00809                 <span class="keywordflow">for</span> ( i = 0 ; i < nfree ; i++ )
+<a name="l00810"></a>00810                 {
+<a name="l00811"></a>00811                     <span class="keywordflow">if</span> ( (matrix1[i][i] <= 0.0) || (matrix2[i][i] <= 0.0) )
+<a name="l00812"></a>00812                     {
+<a name="l00813"></a>00813                         <span class="keywordflow">return</span> -7 ;
+<a name="l00814"></a>00814                     }
+<a name="l00815"></a>00815                     epar[parptr[i]] = chi2 * sqrt( matrix2[i][i] ) / 
+<a name="l00816"></a>00816                                              sqrt( matrix1[i][i] ) ;
+<a name="l00817"></a>00817                 }
+<a name="l00818"></a>00818                 found = 1 ;                  <span class="comment">/* we found a solution */</span>
+<a name="l00819"></a>00819             }
+<a name="l00820"></a>00820         }
+<a name="l00821"></a>00821     }
+<a name="l00822"></a>00822     <span class="keywordflow">return</span> itc ;                             <span class="comment">/* return number of iterations */</span>
+<a name="l00823"></a>00823 }
+<a name="l00824"></a>00824 
+<a name="l00865"></a><a class="code" href="group__sinfo__boltzmann.html#gab3549f7bb876fb4091ba3c0bd64d267d">00865</a> <span class="keywordtype">int</span> <a class="code" href="group__sinfo__boltzmann.html#gab3549f7bb876fb4091ba3c0bd64d267d" title="fits the beginning and end position of the slitlets by using non-linear least square...">sinfo_new_fit_slits_boltz</a> ( cpl_image   * lineImage, 
+<a name="l00866"></a>00866                     FitParams ** par,
+<a name="l00867"></a>00867                     <span class="keywordtype">float</span>     ** slit_pos,
+<a name="l00868"></a>00868                     <span class="keywordtype">int</span>          box_length,
+<a name="l00869"></a>00869                     <span class="keywordtype">float</span>        y_box,
+<a name="l00870"></a>00870                     <span class="keywordtype">float</span>        diff_tol )
+<a name="l00871"></a>00871 {
+<a name="l00872"></a>00872     <span class="keywordtype">float</span>* position=NULL ;
+<a name="l00873"></a>00873     <span class="keywordtype">int</span>   * sinfo_edge, * edgeclean ;
+<a name="l00874"></a>00874     <span class="keywordtype">int</span>   * dummyedge ;
+<a name="l00875"></a>00875     <span class="keywordtype">int</span>   * pos_row, * pos_rowclean ;
+<a name="l00876"></a>00876     Vector * box_buffer ;
+<a name="l00877"></a>00877     Vector * half_buffer ;
+<a name="l00878"></a>00878     Vector * in_buffer ;
+<a name="l00879"></a>00879     <span class="keywordtype">float</span> max_intensity ;
+<a name="l00880"></a>00880     <span class="keywordtype">float</span> row_pos ;
+<a name="l00881"></a>00881     <span class="keywordtype">int</span>   row, col ;
+<a name="l00882"></a>00882     <span class="keywordtype">int</span>   i, j, k, m, n, ed ;
+<a name="l00883"></a>00883     <span class="keywordtype">int</span>   found, init1 ;
+<a name="l00884"></a>00884     <span class="keywordtype">int</span>   line ; 
+<a name="l00885"></a>00885     <span class="keywordtype">int</span>   nel, n_right, left_right ;
+<a name="l00886"></a>00886     <span class="keywordtype">int</span>   n_buf, edge_ind, shift ;
+<a name="l00887"></a>00887     <span class="keywordtype">int</span>   column ;
+<a name="l00888"></a>00888     <span class="keywordtype">int</span>   slit_length ;
+<a name="l00889"></a>00889     <span class="keywordtype">int</span>   agreed ;
+<a name="l00890"></a>00890     <span class="keywordtype">int</span>   bad_line ;
+<a name="l00891"></a>00891     <span class="keywordtype">int</span>   margin ;
+<a name="l00892"></a>00892     <span class="keywordtype">int</span>   iters, xdim, ndat ;
+<a name="l00893"></a>00893     <span class="keywordtype">int</span>   numpar, its ;
+<a name="l00894"></a>00894     <span class="keywordtype">int</span>   * mpar ;
+<a name="l00895"></a>00895     <span class="keywordtype">float</span> * xdat, * wdat ;
+<a name="l00896"></a>00896     <span class="keywordtype">float</span> tol, lab ;
+<a name="l00897"></a>00897     <span class="keywordtype">float</span> fitpar[NPAR] ;
+<a name="l00898"></a>00898     <span class="keywordtype">float</span> dervpar[NPAR] ;
+<a name="l00899"></a>00899     <span class="keywordtype">float</span> minval, maxval ;
+<a name="l00900"></a>00900     <span class="keywordtype">float</span> min ;
+<a name="l00901"></a>00901     <span class="keywordtype">float</span> pos, last_pos ;
+<a name="l00902"></a>00902     <span class="keywordtype">int</span> old_col=0;
+<a name="l00903"></a>00903     <span class="keywordtype">int</span> old_pos=0;
+<a name="l00904"></a>00904     <span class="keywordtype">int</span> ilx=0;
+<a name="l00905"></a>00905     <span class="keywordtype">int</span> ily=0;
+<a name="l00906"></a>00906     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l00907"></a>00907 
+<a name="l00908"></a>00908 
+<a name="l00909"></a>00909     slit_length = SLITLENGTH ;
+<a name="l00910"></a>00910     <span class="keywordflow">if</span> ( NULL == lineImage )
+<a name="l00911"></a>00911     {
+<a name="l00912"></a>00912         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" no line image given!"</span> ) ;
+<a name="l00913"></a>00913         <span class="keywordflow">return</span> -1 ;
+<a name="l00914"></a>00914     }
+<a name="l00915"></a>00915 
+<a name="l00916"></a>00916     <span class="keywordflow">if</span> ( NULL == par )
+<a name="l00917"></a>00917     {
+<a name="l00918"></a>00918         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" no line fit parameters given!"</span> ) ;
+<a name="l00919"></a>00919         <span class="keywordflow">return</span> -2 ;
+<a name="l00920"></a>00920     }
+<a name="l00921"></a>00921 
+<a name="l00922"></a>00922     <span class="keywordflow">if</span> ( NULL == slit_pos )
+<a name="l00923"></a>00923     {
+<a name="l00924"></a>00924         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" no position array allocated!"</span> ) ;
+<a name="l00925"></a>00925         <span class="keywordflow">return</span> -3 ;
+<a name="l00926"></a>00926     }
+<a name="l00927"></a>00927 
+<a name="l00928"></a>00928     <span class="keywordflow">if</span> ( box_length <  4 ||
+<a name="l00929"></a>00929          box_length > 2*slit_length )
+<a name="l00930"></a>00930     {
+<a name="l00931"></a>00931         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" wrong fitting box length given!"</span> ) ;
+<a name="l00932"></a>00932         <span class="keywordflow">return</span> -4 ;
+<a name="l00933"></a>00933     }
+<a name="l00934"></a>00934 
+<a name="l00935"></a>00935     <span class="keywordflow">if</span> ( y_box <= 0.  || y_box > 6. )
+<a name="l00936"></a>00936     {
+<a name="l00937"></a>00937         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" wrong y box length given!"</span> ) ;
+<a name="l00938"></a>00938         <span class="keywordflow">return</span> -5 ;
+<a name="l00939"></a>00939     }
+<a name="l00940"></a>00940 
+<a name="l00941"></a>00941     <span class="keywordflow">if</span> ( diff_tol < 1. )
+<a name="l00942"></a>00942     {
+<a name="l00943"></a>00943         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" diff_tol too small!"</span> ) ;
+<a name="l00944"></a>00944         <span class="keywordflow">return</span> -6 ;
+<a name="l00945"></a>00945     }
+<a name="l00946"></a>00946  
+<a name="l00947"></a>00947     <span class="comment">/* allocate memory for the edges and the row positon of the slitlets */</span>
+<a name="l00948"></a>00948     sinfo_edge         = (<span class="keywordtype">int</span>*) cpl_calloc( 3*slit_length, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>) ) ;
+<a name="l00949"></a>00949     dummyedge    = (<span class="keywordtype">int</span>*) cpl_calloc( 3*slit_length, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>) ) ;
+<a name="l00950"></a>00950     edgeclean    = (<span class="keywordtype">int</span>*) cpl_calloc( slit_length-1, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>) ) ;
+<a name="l00951"></a>00951     pos_row      = (<span class="keywordtype">int</span>*) cpl_calloc( 3*slit_length, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>) ) ;
+<a name="l00952"></a>00952     pos_rowclean = (<span class="keywordtype">int</span>*) cpl_calloc( slit_length, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>) ) ;
+<a name="l00953"></a>00953 
+<a name="l00954"></a>00954 
+<a name="l00955"></a>00955     <span class="comment">/* -----------------------------------------------------------------------</span>
+<a name="l00956"></a>00956 <span class="comment">     * go through the first image columns and the fit parameters and find the </span>
+<a name="l00957"></a>00957 <span class="comment">       line with the highest intensity </span>
+<a name="l00958"></a>00958 <span class="comment">     */</span>
+<a name="l00959"></a>00959     agreed = -1 ;
+<a name="l00960"></a>00960     bad_line = -1 ;
+<a name="l00961"></a>00961     <span class="keywordflow">while</span>( agreed == -1 )
+<a name="l00962"></a>00962     {
+<a name="l00963"></a>00963         found = -1 ;
+<a name="l00964"></a>00964         max_intensity = -FLT_MAX ;
+<a name="l00965"></a>00965         <span class="keywordflow">for</span> ( col = 0 ; col < slit_length ; col++ )
+<a name="l00966"></a>00966         {
+<a name="l00967"></a>00967             <span class="keywordflow">for</span> ( i = 0 ; i < par[0]->n_params ; i++ )
+<a name="l00968"></a>00968             {
+<a name="l00969"></a>00969                 <span class="keywordflow">if</span> ( par[i]->column == col && par[i]->line != bad_line )
+<a name="l00970"></a>00970                 {
+<a name="l00971"></a>00971                     <span class="keywordflow">if</span> ( par[i]->fit_par[0] > max_intensity )
+<a name="l00972"></a>00972                     {
+<a name="l00973"></a>00973                         <span class="keywordflow">if</span> ( par[i]->fit_par[1] >= 1. && 
+<a name="l00974"></a>00974                              par[i]->fit_par[2] > 0. )
+<a name="l00975"></a>00975                         {
+<a name="l00976"></a>00976                             max_intensity = par[i]->fit_par[0] ;
+<a name="l00977"></a>00977                             found = i ;
+<a name="l00978"></a>00978                         }
+<a name="l00979"></a>00979                     }
+<a name="l00980"></a>00980                 }
+<a name="l00981"></a>00981             }  
+<a name="l00982"></a>00982         }
+<a name="l00983"></a>00983 
+<a name="l00984"></a>00984         <span class="comment">/* --------------------------------------------------------------------</span>
+<a name="l00985"></a>00985 <span class="comment">         * check if the found line is usable and if the neighbouring line </span>
+<a name="l00986"></a>00986 <span class="comment">         * have intensity on near rows in neighbouring slitlets </span>
+<a name="l00987"></a>00987 <span class="comment">         */</span>
+<a name="l00988"></a>00988         line    = par[found]->line ;
+<a name="l00989"></a>00989         column  = par[found]->column ;
+<a name="l00990"></a>00990         row_pos = par[found]->fit_par[2] ;
+<a name="l00991"></a>00991         <span class="keywordflow">if</span> ( found >= 0 && max_intensity > 0. )
+<a name="l00992"></a>00992         {
+<a name="l00993"></a>00993             <span class="keywordflow">for</span> ( i = 0 ; i < par[0]->n_params ; i++ )
+<a name="l00994"></a>00994             {
+<a name="l00995"></a>00995                 <span class="keywordflow">if</span> ( par[i]->line == line-1 && 
+<a name="l00996"></a>00996                      par[i]->column == column + slit_length )
+<a name="l00997"></a>00997                 {
+<a name="l00998"></a>00998                     <span class="keywordflow">if</span> ( par[i]->fit_par[2] <= (row_pos + y_box) &&
+<a name="l00999"></a>00999                          par[i]->fit_par[2] >= (row_pos - y_box) )
+<a name="l01000"></a>01000                     {
+<a name="l01001"></a>01001                         bad_line = line ;
+<a name="l01002"></a>01002                     } 
+<a name="l01003"></a>01003                 }
+<a name="l01004"></a>01004             }
+<a name="l01005"></a>01005             <span class="keywordflow">if</span> ( bad_line != line )
+<a name="l01006"></a>01006             {
+<a name="l01007"></a>01007                 agreed = 1 ;
+<a name="l01008"></a>01008                 break ;
+<a name="l01009"></a>01009             }
+<a name="l01010"></a>01010         }
+<a name="l01011"></a>01011         <span class="keywordflow">else</span> 
+<a name="l01012"></a>01012         {
+<a name="l01013"></a>01013           <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no emission line found in the first image columns"</span>) ;
+<a name="l01014"></a>01014             cpl_free( sinfo_edge ) ;
+<a name="l01015"></a>01015             cpl_free( pos_row ) ;
+<a name="l01016"></a>01016             cpl_free( edgeclean ) ;
+<a name="l01017"></a>01017             cpl_free( dummyedge ) ;
+<a name="l01018"></a>01018             cpl_free( pos_rowclean ) ;
+<a name="l01019"></a>01019             <span class="keywordflow">return</span> -7 ;
+<a name="l01020"></a>01020         }    
+<a name="l01021"></a>01021     }
+<a name="l01022"></a>01022 
+<a name="l01023"></a>01023 
+<a name="l01024"></a>01024 
+<a name="l01025"></a>01025     <span class="keywordflow">if</span> ( agreed == -1 )
+<a name="l01026"></a>01026     {
+<a name="l01027"></a>01027         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" no emission line found in the first image columns"</span>) ;
+<a name="l01028"></a>01028         cpl_free( sinfo_edge ) ;
+<a name="l01029"></a>01029         cpl_free( pos_row ) ;
+<a name="l01030"></a>01030         cpl_free( edgeclean ) ;
+<a name="l01031"></a>01031         cpl_free( dummyedge ) ;
+<a name="l01032"></a>01032         cpl_free( pos_rowclean ) ;
+<a name="l01033"></a>01033         <span class="keywordflow">return</span> -7 ;
+<a name="l01034"></a>01034     }    
+<a name="l01035"></a>01035 
+<a name="l01036"></a>01036     ilx=cpl_image_get_size_x(lineImage);
+<a name="l01037"></a>01037     ily=cpl_image_get_size_y(lineImage);
+<a name="l01038"></a>01038     pidata=cpl_image_get_data_float(lineImage);
+<a name="l01039"></a>01039 
+<a name="l01040"></a>01040     <span class="comment">/* now find and store the raw sinfo_edge positions of the found slitlet */</span> 
+<a name="l01041"></a>01041     n  = 0 ;
+<a name="l01042"></a>01042     ed = 0 ;
+<a name="l01043"></a>01043     position=cpl_calloc(ilx,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l01044"></a>01044 
+<a name="l01045"></a>01045     <span class="comment">/* was for ( col = 0 ; col < ilx - slit_length/2 ; col++ ) */</span>
+<a name="l01046"></a>01046     <span class="keywordflow">for</span> ( col = slit_length/2 ; col < ilx - slit_length/2 ; col++ )
+<a name="l01047"></a>01047     {
+<a name="l01048"></a>01048         <span class="keywordflow">for</span> ( i = 0 ; i < par[0]->n_params ; i++ )
+<a name="l01049"></a>01049       {   
+<a name="l01050"></a>01050         <span class="comment">/*</span>
+<a name="l01051"></a>01051 <span class="comment">              printf("p1=%f p2=%f p3=%f\n",</span>
+<a name="l01052"></a>01052 <span class="comment">              par[i]->fit_par[0],par[i]->fit_par[1],par[i]->fit_par[2]);</span>
+<a name="l01053"></a>01053 <span class="comment">        */</span>
+<a name="l01054"></a>01054             <span class="keywordflow">if</span> ( par[i]->column == col && par[i]->line == line )
+<a name="l01055"></a>01055             {
+<a name="l01056"></a>01056                 <span class="keywordflow">if</span> ( par[i]->fit_par[0] > 0.  && 
+<a name="l01057"></a>01057                      par[i]->fit_par[1] >= 1. && 
+<a name="l01058"></a>01058                      par[i]->fit_par[2] > 0. )
+<a name="l01059"></a>01059                 {
+<a name="l01060"></a>01060                     position[n] = par[i]->fit_par[2] ;
+<a name="l01061"></a>01061                     old_pos=position[n];
+<a name="l01062"></a>01062                     <span class="keywordflow">if</span> ( n > 0 && 
+<a name="l01063"></a>01063                          fabs(position[n] - position[n-1]) > y_box && 
+<a name="l01064"></a>01064                          (col-old_col) > (slit_length-SLIT_POS_ERR) )
+<a name="l01065"></a>01065                     {
+<a name="l01066"></a>01066 
+<a name="l01067"></a>01067               old_col=col;
+<a name="l01068"></a>01068               sinfo_edge[ed] = col ; 
+<a name="l01069"></a>01069               pos_row[ed] = sinfo_new_nint( position[n-1] ) ;
+<a name="l01070"></a>01070                       <span class="comment">/* printf("sinfo_edge[%d]=%d , pos_row=%d\n",</span>
+<a name="l01071"></a>01071 <span class="comment">                                 ed,sinfo_edge[ed],pos_row[ed]); */</span> 
+<a name="l01072"></a>01072               ed++ ;
+<a name="l01073"></a>01073               <span class="keywordflow">if</span> ( col >= ilx - slit_length - SLIT_POS_ERR ) {
+<a name="l01074"></a>01074               pos_row[ed] =  sinfo_new_nint( position[n] ) ;
+<a name="l01075"></a>01075               } 
+<a name="l01076"></a>01076             } <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( ((col-old_col) > 
+<a name="l01077"></a>01077                                   (slit_length+SLIT_POS_ERR)) &&
+<a name="l01078"></a>01078                                   (col>120) ) {
+<a name="l01079"></a>01079               old_col=col;
+<a name="l01080"></a>01080               sinfo_edge[ed] = col ; 
+<a name="l01081"></a>01081               pos_row[ed] = sinfo_new_nint( position[n-1] ) ;
+<a name="l01082"></a>01082                       <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"add1 slitlet edge[%d]=%d, pos_row=%d"</span>,
+<a name="l01083"></a>01083                      ed,sinfo_edge[ed],pos_row[ed]);
+<a name="l01084"></a>01084               ed++ ;
+<a name="l01085"></a>01085               <span class="keywordflow">if</span> ( col >= ilx - slit_length - SLIT_POS_ERR ) {
+<a name="l01086"></a>01086               pos_row[ed] =  sinfo_new_nint( position[n] ) ;
+<a name="l01087"></a>01087               } 
+<a name="l01088"></a>01088             }
+<a name="l01089"></a>01089                     n++ ;
+<a name="l01090"></a>01090                 }
+<a name="l01091"></a>01091             } <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( ((col-old_col) > (slit_length+SLIT_POS_ERR)) && 
+<a name="l01092"></a>01092                         (col>120) ) {
+<a name="l01093"></a>01093           <span class="comment">/*</span>
+<a name="l01094"></a>01094 <span class="comment">              printf("check col=%d col-old_col=%d check=%d\n",</span>
+<a name="l01095"></a>01095 <span class="comment">                     col,(col-old_col),(slit_length+SLIT_POS_ERR));</span>
+<a name="l01096"></a>01096 <span class="comment">          */</span>
+<a name="l01097"></a>01097           position[n] = old_pos ;
+<a name="l01098"></a>01098              
+<a name="l01099"></a>01099           old_col+=slit_length;
+<a name="l01100"></a>01100           sinfo_edge[ed] = old_col; ; 
+<a name="l01101"></a>01101           pos_row[ed] = sinfo_new_nint( position[n-1] ) ;
+<a name="l01102"></a>01102 
+<a name="l01103"></a>01103 
+<a name="l01104"></a>01104           <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"added2 slitlet sinfo_edge[%d]=%d, pos_row=%d"</span>,
+<a name="l01105"></a>01105                   ed,sinfo_edge[ed],pos_row[ed]);
+<a name="l01106"></a>01106           ed++ ;
+<a name="l01107"></a>01107           <span class="keywordflow">if</span> ( old_col >= ilx - slit_length - SLIT_POS_ERR ) {
+<a name="l01108"></a>01108         pos_row[ed] =  old_pos ;
+<a name="l01109"></a>01109           }
+<a name="l01110"></a>01110           n++;
+<a name="l01111"></a>01111         }
+<a name="l01112"></a>01112         }
+<a name="l01113"></a>01113     }
+<a name="l01114"></a>01114 
+<a name="l01115"></a>01115 
+<a name="l01116"></a>01116     <span class="keywordflow">if</span> ( ed < (N_SLITLETS - 1) )
+<a name="l01117"></a>01117     {
+<a name="l01118"></a>01118         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" not enough slitlets, found: %d"</span>, ed) ;
+<a name="l01119"></a>01119         cpl_free( sinfo_edge ) ;
+<a name="l01120"></a>01120         cpl_free( pos_row ) ;
+<a name="l01121"></a>01121         cpl_free( edgeclean ) ;
+<a name="l01122"></a>01122         cpl_free( dummyedge ) ;
+<a name="l01123"></a>01123         cpl_free( pos_rowclean ) ;
+<a name="l01124"></a>01124         <span class="keywordflow">return</span> -8 ;
+<a name="l01125"></a>01125     } 
+<a name="l01126"></a>01126 
+<a name="l01127"></a>01127     <span class="comment">/* now find the clean sinfo_edge and row positions of the slitlets */</span>
+<a name="l01128"></a>01128     <span class="comment">/* printf("ed=%d\n",ed); */</span>
+<a name="l01129"></a>01129     <span class="keywordflow">for</span> ( i = 1 ; i <= ed ; i ++ )
+<a name="l01130"></a>01130     {
+<a name="l01131"></a>01131         <span class="keywordflow">if</span> ( i == ed )
+<a name="l01132"></a>01132         {
+<a name="l01133"></a>01133             <span class="keywordflow">if</span> ( (sinfo_edge[i-1] - sinfo_edge[i-2]) < 
+<a name="l01134"></a>01134                   slit_length - SLIT_LEN_ERR ||
+<a name="l01135"></a>01135                  (sinfo_edge[i-1] - sinfo_edge[i-2]) > 
+<a name="l01136"></a>01136                   slit_length + SLIT_LEN_ERR )
+<a name="l01137"></a>01137             {
+<a name="l01138"></a>01138         <span class="comment">/* printf("e(i-1)=%d e(i-2)=%d i=%d\n",</span>
+<a name="l01139"></a>01139 <span class="comment">                       edge[i-1], edge[i-2],i); */</span>
+<a name="l01140"></a>01140                 dummyedge[i-1]   = -1 ;
+<a name="l01141"></a>01141             }
+<a name="l01142"></a>01142         }
+<a name="l01143"></a>01143         <span class="keywordflow">if</span> (dummyedge[i-1] != -1)
+<a name="l01144"></a>01144         {
+<a name="l01145"></a>01145             dummyedge[i-1] = sinfo_edge[i-1] ;
+<a name="l01146"></a>01146         }
+<a name="l01147"></a>01147         <span class="keywordflow">else</span>
+<a name="l01148"></a>01148         {
+<a name="l01149"></a>01149             continue ;
+<a name="l01150"></a>01150         }
+<a name="l01151"></a>01151         <span class="keywordflow">if</span> ( i < ed )
+<a name="l01152"></a>01152         {
+<a name="l01153"></a>01153             <span class="keywordflow">if</span> ( (sinfo_edge[i] - sinfo_edge[i-1]) < 
+<a name="l01154"></a>01154                   slit_length - SLIT_LEN_ERR ||
+<a name="l01155"></a>01155                  (sinfo_edge[i] - sinfo_edge[i-1]) > 
+<a name="l01156"></a>01156                   slit_length + SLIT_LEN_ERR )
+<a name="l01157"></a>01157             {
+<a name="l01158"></a>01158         <span class="comment">/* printf("e(i)=%d e(i-1)=%d i=%d\n",edge[i], edge[i-1],i); */</span>
+<a name="l01159"></a>01159                 dummyedge[i]   = -1 ;
+<a name="l01160"></a>01160             }
+<a name="l01161"></a>01161         }
+<a name="l01162"></a>01162         <span class="keywordflow">if</span> ( i+1 < ed && dummyedge[i] != -1 )
+<a name="l01163"></a>01163         {
+<a name="l01164"></a>01164             <span class="keywordflow">if</span> ( (sinfo_edge[i+1] - sinfo_edge[i]) < 
+<a name="l01165"></a>01165                   slit_length - SLIT_LEN_ERR ||
+<a name="l01166"></a>01166                  (sinfo_edge[i+1] - sinfo_edge[i]) > 
+<a name="l01167"></a>01167                   slit_length + SLIT_LEN_ERR )
+<a name="l01168"></a>01168             {
+<a name="l01169"></a>01169         <span class="comment">/* printf("e(i+1)=%d e(i)=%d i=%d\n",edge[i+1], edge[i],i); */</span>
+<a name="l01170"></a>01170                 dummyedge[i+1] = -1 ; 
+<a name="l01171"></a>01171             }
+<a name="l01172"></a>01172         }
+<a name="l01173"></a>01173     }
+<a name="l01174"></a>01174 
+<a name="l01175"></a>01175     k = 0 ;
+<a name="l01176"></a>01176     <span class="keywordflow">for</span> ( i = 0 ; i < ed ; i++ )
+<a name="l01177"></a>01177     {
+<a name="l01178"></a>01178         <span class="keywordflow">if</span> ( dummyedge[i] != -1 && dummyedge[i] != 0 )
+<a name="l01179"></a>01179         {
+<a name="l01180"></a>01180             edgeclean[k] = dummyedge[i] ;
+<a name="l01181"></a>01181             pos_rowclean[k] = pos_row[i] ;
+<a name="l01182"></a>01182             k++ ;
+<a name="l01183"></a>01183             <span class="keywordflow">if</span>( edgeclean[k-1] > (ilx - slit_length -2*SLIT_LEN_ERR ) )
+<a name="l01184"></a>01184             {
+<a name="l01185"></a>01185                 pos_rowclean[k] = pos_row[ed] ;
+<a name="l01186"></a>01186             } 
+<a name="l01187"></a>01187         }
+<a name="l01188"></a>01188     }
+<a name="l01189"></a>01189     <span class="comment">/*</span>
+<a name="l01190"></a>01190 <span class="comment">    for ( i = 0 ; i < k ; i++ )</span>
+<a name="l01191"></a>01191 <span class="comment">    {</span>
+<a name="l01192"></a>01192 <span class="comment">      sinfo_msg_warning("%d %d", edgeclean[i], pos_rowclean[i]);</span>
+<a name="l01193"></a>01193 <span class="comment">    }</span>
+<a name="l01194"></a>01194 <span class="comment">    */</span>
+<a name="l01195"></a>01195     <span class="keywordflow">if</span> ( k != N_SLITLETS - 1 )
+<a name="l01196"></a>01196     {
+<a name="l01197"></a>01197         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" wrong number of clean slitlets found: %d"</span>, k+1) ;
+<a name="l01198"></a>01198         cpl_free( sinfo_edge ) ;
+<a name="l01199"></a>01199         cpl_free( pos_row ) ;
+<a name="l01200"></a>01200         cpl_free( edgeclean ) ;
+<a name="l01201"></a>01201         cpl_free( dummyedge ) ;
+<a name="l01202"></a>01202         cpl_free( pos_rowclean ) ;
+<a name="l01203"></a>01203         <span class="keywordflow">return</span> -7 ;
+<a name="l01204"></a>01204     } 
+<a name="l01205"></a>01205 
+<a name="l01206"></a>01206     <span class="comment">/* determine the margins of the fitting box outside the slitlets */</span>
+<a name="l01207"></a>01207     margin = box_length / 2 ;
+<a name="l01208"></a>01208 
+<a name="l01209"></a>01209     <span class="comment">/* ----------------------------------------------------------------------</span>
+<a name="l01210"></a>01210 <span class="comment">     * now go through the slitlets, search along each column within a box with </span>
+<a name="l01211"></a>01211 <span class="comment">     * half width y_box the maximum value and store these found values </span>
+<a name="l01212"></a>01212 <span class="comment">     * in a buffer</span>
+<a name="l01213"></a>01213 <span class="comment">     */</span>
+<a name="l01214"></a>01214      <span class="keywordflow">if</span>(
+<a name="l01215"></a>01215          ( (pos_rowclean[0]-sinfo_new_nint(y_box)) < 0 ) ||
+<a name="l01216"></a>01216          ( (pos_rowclean[0]+sinfo_new_nint(y_box)) >ily )
+<a name="l01217"></a>01217        ) {
+<a name="l01218"></a>01218 
+<a name="l01219"></a>01219              <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"pos_rowclean[0] <0 something wrong!"</span>) ;
+<a name="l01220"></a>01220              cpl_free( sinfo_edge ) ;
+<a name="l01221"></a>01221              cpl_free( pos_row ) ;
+<a name="l01222"></a>01222              cpl_free( edgeclean ) ;
+<a name="l01223"></a>01223              cpl_free( dummyedge ) ;
+<a name="l01224"></a>01224              cpl_free( pos_rowclean ) ;
+<a name="l01225"></a>01225              <span class="keywordflow">return</span> -7 ;
+<a name="l01226"></a>01226 
+<a name="l01227"></a>01227     }
+<a name="l01228"></a>01228 
+<a name="l01229"></a>01229     <span class="keywordflow">for</span> ( j = 0 ; j <= k ; j++ )
+<a name="l01230"></a>01230     {
+<a name="l01231"></a>01231         m = 0 ;
+<a name="l01232"></a>01232         <span class="keywordflow">if</span> ( j == 0 )
+<a name="l01233"></a>01233         {
+<a name="l01234"></a>01234             box_buffer = sinfo_new_vector( edgeclean[0] + margin ) ;
+<a name="l01235"></a>01235             <span class="keywordflow">for</span>( col = 0 ; col < edgeclean[0] + margin ; col++ )
+<a name="l01236"></a>01236             {
+<a name="l01237"></a>01237                 maxval = -FLT_MAX ;
+<a name="l01238"></a>01238                 <span class="keywordflow">for</span> ( row = pos_rowclean[0] - sinfo_new_nint(y_box) ; 
+<a name="l01239"></a>01239                       row <= pos_rowclean[0] + sinfo_new_nint(y_box) ; row++ )
+<a name="l01240"></a>01240                 {
+<a name="l01241"></a>01241                     <span class="keywordflow">if</span> ( maxval < pidata[col + ilx*row] )
+<a name="l01242"></a>01242                     {
+<a name="l01243"></a>01243                         maxval = pidata[col + ilx*row] ;
+<a name="l01244"></a>01244                     }
+<a name="l01245"></a>01245                 }
+<a name="l01246"></a>01246                 box_buffer->data[m] = maxval ;
+<a name="l01247"></a>01247                 m++ ;
+<a name="l01248"></a>01248             }
+<a name="l01249"></a>01249         }
+<a name="l01250"></a>01250         <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( j < k )
+<a name="l01251"></a>01251         {
+<a name="l01252"></a>01252             box_buffer = sinfo_new_vector( edgeclean[j] - 
+<a name="l01253"></a>01253                                            edgeclean[j-1] + 2*margin ) ;
+<a name="l01254"></a>01254             <span class="keywordflow">for</span> ( col = edgeclean[j - 1] - margin ; 
+<a name="l01255"></a>01255                   col < edgeclean[j] + margin ; col++ )
+<a name="l01256"></a>01256             {
+<a name="l01257"></a>01257                 maxval = -FLT_MAX ;
+<a name="l01258"></a>01258                 <span class="keywordflow">for</span> ( row = pos_rowclean[j] - sinfo_new_nint(y_box) ; 
+<a name="l01259"></a>01259                       row <= pos_rowclean[j] + sinfo_new_nint(y_box) ; row++ )
+<a name="l01260"></a>01260                 {
+<a name="l01261"></a>01261                     <span class="keywordflow">if</span> ( maxval < pidata[col + ilx*row] )
+<a name="l01262"></a>01262                     {
+<a name="l01263"></a>01263                         maxval = pidata[col + ilx*row] ;
+<a name="l01264"></a>01264                     }
+<a name="l01265"></a>01265                 }
+<a name="l01266"></a>01266                 box_buffer->data[m] = maxval ;
+<a name="l01267"></a>01267                 m++ ;
+<a name="l01268"></a>01268             }
+<a name="l01269"></a>01269         }
+<a name="l01270"></a>01270         <span class="keywordflow">else</span> 
+<a name="l01271"></a>01271         {
+<a name="l01272"></a>01272             box_buffer = sinfo_new_vector( ilx - edgeclean[k-1] + margin ) ;
+<a name="l01273"></a>01273             <span class="keywordflow">for</span> ( col = edgeclean[k - 1] - margin ; col < ilx ; col++ )
+<a name="l01274"></a>01274             {
+<a name="l01275"></a>01275                 maxval = -FLT_MAX ;
+<a name="l01276"></a>01276                 <span class="keywordflow">for</span> ( row = pos_rowclean[k-2] - sinfo_new_nint(y_box) ; 
+<a name="l01277"></a>01277                       row <= pos_rowclean[k-2] + sinfo_new_nint(y_box) ; row++ )
+<a name="l01278"></a>01278                 {
+<a name="l01279"></a>01279                     <span class="keywordflow">if</span> ( maxval < pidata[col + ilx*row] )
+<a name="l01280"></a>01280                     {
+<a name="l01281"></a>01281                         maxval = pidata[col + ilx*row] ;
+<a name="l01282"></a>01282                     }
+<a name="l01283"></a>01283                 }
+<a name="l01284"></a>01284                 <span class="keywordflow">if</span>(maxval>0) box_buffer->data[m] = maxval ;
+<a name="l01285"></a>01285         <span class="keywordflow">else</span> box_buffer->data[m] = 0;
+<a name="l01286"></a>01286         m++ ;
+<a name="l01287"></a>01287             }
+<a name="l01288"></a>01288         }
+<a name="l01289"></a>01289 
+<a name="l01290"></a>01290         <span class="comment">/* determine the minimum value in the box to get background1 </span>
+<a name="l01291"></a>01291 <span class="comment">           value for the sinfo_edge slitlets */</span>
+<a name="l01292"></a>01292         min = FLT_MAX ;
+<a name="l01293"></a>01293         <span class="keywordflow">for</span> ( i = 0 ; i < box_buffer->n_elements ; i++ )
+<a name="l01294"></a>01294         {
+<a name="l01295"></a>01295             <span class="keywordflow">if</span> ( box_buffer -> data[i] < min )
+<a name="l01296"></a>01296             {
+<a name="l01297"></a>01297                 min = box_buffer -> data[i] ;
+<a name="l01298"></a>01298             }
+<a name="l01299"></a>01299         }
+<a name="l01300"></a>01300 
+<a name="l01301"></a>01301         <span class="keywordflow">for</span> ( left_right = 0 ; left_right <= 1 ; left_right++ )
+<a name="l01302"></a>01302         { 
+<a name="l01303"></a>01303             nel = 0 ;
+<a name="l01304"></a>01304             <span class="keywordflow">if</span> ( left_right == 0 )
+<a name="l01305"></a>01305             {
+<a name="l01306"></a>01306                 nel = box_buffer -> n_elements / 2 ;
+<a name="l01307"></a>01307             }
+<a name="l01308"></a>01308             <span class="keywordflow">else</span>
+<a name="l01309"></a>01309             {
+<a name="l01310"></a>01310                 <span class="keywordflow">if</span> ( box_buffer -> n_elements % 2 == 0 )
+<a name="l01311"></a>01311                 {
+<a name="l01312"></a>01312                     nel = box_buffer -> n_elements / 2 ;
+<a name="l01313"></a>01313                 }
+<a name="l01314"></a>01314                 <span class="keywordflow">else</span>
+<a name="l01315"></a>01315                 {
+<a name="l01316"></a>01316                     nel = box_buffer -> n_elements / 2 + 1 ;
+<a name="l01317"></a>01317                 }
+<a name="l01318"></a>01318             }
+<a name="l01319"></a>01319 
+<a name="l01320"></a>01320             <span class="comment">/* now split the buffer in the midth in a left and right </span>
+<a name="l01321"></a>01321 <span class="comment">               part for fitting */</span>
+<a name="l01322"></a>01322             half_buffer = sinfo_new_vector( nel ) ;
+<a name="l01323"></a>01323             <span class="keywordflow">if</span> ( left_right == 0 )
+<a name="l01324"></a>01324             {
+<a name="l01325"></a>01325                 <span class="keywordflow">for</span> ( i = 0 ; i < nel ; i++ )
+<a name="l01326"></a>01326                 {
+<a name="l01327"></a>01327                     half_buffer -> data[i] = box_buffer -> data[i] ;
+<a name="l01328"></a>01328                 }
+<a name="l01329"></a>01329             }
+<a name="l01330"></a>01330             <span class="keywordflow">else</span>
+<a name="l01331"></a>01331             {
+<a name="l01332"></a>01332                 n_right = 0 ;
+<a name="l01333"></a>01333                 <span class="keywordflow">for</span> ( i = box_buffer -> n_elements - 1 ; 
+<a name="l01334"></a>01334                       i >= box_buffer -> n_elements - nel ; i-- )
+<a name="l01335"></a>01335                 {
+<a name="l01336"></a>01336                     half_buffer -> data[n_right] = box_buffer -> data[i] ;
+<a name="l01337"></a>01337                     n_right++ ;
+<a name="l01338"></a>01338                 }
+<a name="l01339"></a>01339             }
+<a name="l01340"></a>01340 
+<a name="l01341"></a>01341             xdat = (<span class="keywordtype">float</span> *) cpl_calloc( nel, <span class="keyword">sizeof</span> (<span class="keywordtype">float</span>) ) ;
+<a name="l01342"></a>01342             wdat = (<span class="keywordtype">float</span> *) cpl_calloc( nel, <span class="keyword">sizeof</span> (<span class="keywordtype">float</span>) ) ;
+<a name="l01343"></a>01343             mpar = (<span class="keywordtype">int</span> *)   cpl_calloc( NPAR, <span class="keyword">sizeof</span> (<span class="keywordtype">int</span>) ) ;
+<a name="l01344"></a>01344 
+<a name="l01345"></a>01345             <span class="comment">/* set initial values for the fitting routine */</span>
+<a name="l01346"></a>01346             minval =  FLT_MAX ;
+<a name="l01347"></a>01347             maxval = -FLT_MAX ;
+<a name="l01348"></a>01348             <span class="keywordflow">for</span> ( i = 0 ; i < nel ; i++ )
+<a name="l01349"></a>01349             {
+<a name="l01350"></a>01350                 xdat[i] = i ;
+<a name="l01351"></a>01351                 wdat[i] = 1.0 ;
+<a name="l01352"></a>01352                 <span class="keywordflow">if</span> ( half_buffer -> data[i] < minval )
+<a name="l01353"></a>01353                 {
+<a name="l01354"></a>01354                     minval = half_buffer -> data[i] ;
+<a name="l01355"></a>01355                 }
+<a name="l01356"></a>01356                 <span class="keywordflow">if</span> ( half_buffer -> data[i] > maxval )
+<a name="l01357"></a>01357                 {
+<a name="l01358"></a>01358                     maxval = half_buffer -> data[i] ;
+<a name="l01359"></a>01359                 }
+<a name="l01360"></a>01360             }
+<a name="l01361"></a>01361 
+<a name="l01362"></a>01362             fitpar[0] = minval ;
+<a name="l01363"></a>01363             fitpar[1] = maxval ; 
+<a name="l01364"></a>01364 
+<a name="l01365"></a>01365             <span class="comment">/* search for both positions of the half intensity </span>
+<a name="l01366"></a>01366 <span class="comment">               of the hat within the buffer */</span>
+<a name="l01367"></a>01367             init1 = -1 ; 
+<a name="l01368"></a>01368             <span class="keywordflow">for</span> ( i = 0 ; i < nel ; i++ )
+<a name="l01369"></a>01369             {
+<a name="l01370"></a>01370                 <span class="keywordflow">if</span> ( half_buffer -> data[i] >= ( maxval + minval ) / 2. )
+<a name="l01371"></a>01371                 {
+<a name="l01372"></a>01372                     init1 = i ;
+<a name="l01373"></a>01373                     break ;
+<a name="l01374"></a>01374                 }
+<a name="l01375"></a>01375             }
+<a name="l01376"></a>01376 
+<a name="l01377"></a>01377             <span class="comment">/*----------------------------------------------------------------</span>
+<a name="l01378"></a>01378 <span class="comment">             * if we have too few left background values (at the image edges)</span>
+<a name="l01379"></a>01379 <span class="comment">             * the left margin of the buffer to fit is filled with the minimal</span>
+<a name="l01380"></a>01380 <span class="comment">             * values in order to get a good fit</span>
+<a name="l01381"></a>01381 <span class="comment">             */</span>
+<a name="l01382"></a>01382               
+<a name="l01383"></a>01383             edge_ind = 0 ;
+<a name="l01384"></a>01384             <span class="keywordflow">if</span> ( init1 < 3 )
+<a name="l01385"></a>01385             {
+<a name="l01386"></a>01386                 n_buf = half_buffer->n_elements + margin ;
+<a name="l01387"></a>01387                 in_buffer = sinfo_new_vector( n_buf ) ;     
+<a name="l01388"></a>01388                 <span class="keywordflow">for</span> ( i = 0 ; i < margin ; i++ )
+<a name="l01389"></a>01389                 {
+<a name="l01390"></a>01390                     in_buffer -> data[i] = min ;
+<a name="l01391"></a>01391                 }
+<a name="l01392"></a>01392                 shift = 0 ;
+<a name="l01393"></a>01393                 <span class="keywordflow">for</span> ( i = margin ; i < n_buf ; i++ )
+<a name="l01394"></a>01394                 {
+<a name="l01395"></a>01395                     in_buffer -> data[i] = half_buffer -> data[shift] ;
+<a name="l01396"></a>01396                     shift++ ;
+<a name="l01397"></a>01397                 }
+<a name="l01398"></a>01398                 sinfo_new_destroy_vector ( half_buffer ) ;
+<a name="l01399"></a>01399                 half_buffer = sinfo_new_vector ( n_buf ) ;
+<a name="l01400"></a>01400                 <span class="keywordflow">for</span> ( i = 0 ; i < n_buf ; i++ )
+<a name="l01401"></a>01401                 {
+<a name="l01402"></a>01402                     half_buffer -> data[i] = in_buffer -> data[i] ;
+<a name="l01403"></a>01403                 }
+<a name="l01404"></a>01404                 edge_ind = 1 ;
+<a name="l01405"></a>01405                 init1 += margin ;
+<a name="l01406"></a>01406                 sinfo_new_destroy_vector ( in_buffer ) ;
+<a name="l01407"></a>01407             }
+<a name="l01408"></a>01408 
+<a name="l01409"></a>01409             <span class="comment">/* determine the initial positions from the found values */</span>
+<a name="l01410"></a>01410             <span class="keywordflow">if</span> ( init1 != -1 )
+<a name="l01411"></a>01411             {
+<a name="l01412"></a>01412                 fitpar[2] = (float)init1 ;
+<a name="l01413"></a>01413             }
+<a name="l01414"></a>01414             fitpar[3] = 1. ;
+<a name="l01415"></a>01415 
+<a name="l01416"></a>01416             <span class="keywordflow">for</span> ( i = 0 ; i < NPAR ; i++ )
+<a name="l01417"></a>01417             {
+<a name="l01418"></a>01418                 mpar[i] = 1 ;
+<a name="l01419"></a>01419                 dervpar[i] = 0. ;
+<a name="l01420"></a>01420             }
+<a name="l01421"></a>01421       
+<a name="l01422"></a>01422             xdim     = XDIMA ;
+<a name="l01423"></a>01423             ndat     = nel ;
+<a name="l01424"></a>01424             numpar   = NPAR ;
+<a name="l01425"></a>01425             tol      = TOLA ;
+<a name="l01426"></a>01426             lab      = LABA ;
+<a name="l01427"></a>01427             its      = ITSA ;
+<a name="l01428"></a>01428          
+<a name="l01429"></a>01429             <span class="comment">/* finally, do the least squares fit over the buffer data */</span>
+<a name="l01430"></a>01430             <span class="keywordflow">if</span> ( 0 > ( iters = <a class="code" href="group__sinfo__boltzmann.html#ga7e03e34851f7c367ab3827c58e8c81c5" title="makes a least-squares fit of a function to a set of data points.">sinfo_new_lsqfit</a>( xdat, &xdim, 
+<a name="l01431"></a>01431                                                  half_buffer -> data, 
+<a name="l01432"></a>01432                                                  wdat, &ndat, fitpar,
+<a name="l01433"></a>01433                                                  dervpar, mpar, &numpar, 
+<a name="l01434"></a>01434                                                  &tol, &its, &lab )) )
+<a name="l01435"></a>01435             { 
+<a name="l01436"></a>01436                 <span class="comment">/* if the fit doesn't succeed the initial values are taken */</span>
+<a name="l01437"></a>01437                 <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a> (<span class="stringliteral">" least squares fit failed,"</span>
+<a name="l01438"></a>01438                                    <span class="stringliteral">" error no.: %d in slitlet: %d"</span>, iters, j) ;
+<a name="l01439"></a>01439                 fitpar[2] = (float)init1 ;
+<a name="l01440"></a>01440             }
+<a name="l01441"></a>01441 
+<a name="l01442"></a>01442             pos = fitpar[2] ;
+<a name="l01443"></a>01443             <span class="keywordflow">if</span> ( edge_ind == 1 )
+<a name="l01444"></a>01444             {
+<a name="l01445"></a>01445                 pos -= (float)margin ;
+<a name="l01446"></a>01446             }
+<a name="l01447"></a>01447 
+<a name="l01448"></a>01448             <span class="comment">/*---------------------------------------------------------------- </span>
+<a name="l01449"></a>01449 <span class="comment">             * now discern the left and the right sinfo_edge fit of the </span>
+<a name="l01450"></a>01450 <span class="comment">             * slitlets and associate the fit results with the absolute </span>
+<a name="l01451"></a>01451 <span class="comment">             * positions in the image consider the difference of the fitted </span>
+<a name="l01452"></a>01452 <span class="comment">             * slit position to the expected position and decide wether the </span>
+<a name="l01453"></a>01453 <span class="comment">             * fit is taken or the expected value is taken.</span>
+<a name="l01454"></a>01454 <span class="comment">             */</span>
+<a name="l01455"></a>01455             <span class="keywordflow">if</span> ( left_right == 0 )
+<a name="l01456"></a>01456             {
+<a name="l01457"></a>01457                 <span class="comment">/* take care of the column position of the fit boxes to get </span>
+<a name="l01458"></a>01458 <span class="comment">                   the absolute positions */</span>
+<a name="l01459"></a>01459                 <span class="keywordflow">if</span> ( j == 0 )
+<a name="l01460"></a>01460                 {
+<a name="l01461"></a>01461                     <span class="keywordflow">if</span> ( fabs(pos - ((<span class="keywordtype">float</span>)edgeclean[0] - 1. - 
+<a name="l01462"></a>01462                                      (<span class="keywordtype">float</span>)slit_length)) < diff_tol )
+<a name="l01463"></a>01463                     {
+<a name="l01464"></a>01464                         slit_pos[0][0] = pos ;
+<a name="l01465"></a>01465                     }
+<a name="l01466"></a>01466                     <span class="keywordflow">else</span>
+<a name="l01467"></a>01467                     {
+<a name="l01468"></a>01468                         <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"something wrong with fitted "</span>
+<a name="l01469"></a>01469                                           <span class="stringliteral">"left position of slitlet 0"</span>) ;
+<a name="l01470"></a>01470                         <span class="keywordflow">if</span> ( (<span class="keywordtype">float</span>) edgeclean[0] - 1. - 
+<a name="l01471"></a>01471                              (<span class="keywordtype">float</span>)slit_length < 0. )
+<a name="l01472"></a>01472                         {
+<a name="l01473"></a>01473                             slit_pos[0][0] = 0. ;
+<a name="l01474"></a>01474                         }
+<a name="l01475"></a>01475                         <span class="keywordflow">else</span>
+<a name="l01476"></a>01476                         {
+<a name="l01477"></a>01477                             slit_pos[0][0] = (float)edgeclean[0] - 1. - 
+<a name="l01478"></a>01478                                              (<span class="keywordtype">float</span>)slit_length ;
+<a name="l01479"></a>01479                         }
+<a name="l01480"></a>01480                     }
+<a name="l01481"></a>01481                 }
+<a name="l01482"></a>01482                 <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( j < k )
+<a name="l01483"></a>01483                 {
+<a name="l01484"></a>01484                     <span class="keywordflow">if</span> ( fabs( pos - (<span class="keywordtype">float</span>)margin ) < diff_tol )
+<a name="l01485"></a>01485                     {
+<a name="l01486"></a>01486                         slit_pos[j][0] = pos + (float)edgeclean[j-1] - 
+<a name="l01487"></a>01487                                                (<span class="keywordtype">float</span>)margin ;
+<a name="l01488"></a>01488                     }
+<a name="l01489"></a>01489                     <span class="keywordflow">else</span>
+<a name="l01490"></a>01490                     {
+<a name="l01491"></a>01491                         <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"something wrong with fitted "</span>
+<a name="l01492"></a>01492                                           <span class="stringliteral">"left position of slitlet %d"</span>, j) ;
+<a name="l01493"></a>01493                         slit_pos[j][0] = (float)edgeclean[j-1] - 1. ;
+<a name="l01494"></a>01494                     }
+<a name="l01495"></a>01495                 }
+<a name="l01496"></a>01496                 <span class="keywordflow">else</span>
+<a name="l01497"></a>01497                 {
+<a name="l01498"></a>01498                     <span class="keywordflow">if</span> ( fabs( pos - (<span class="keywordtype">float</span>)margin ) < diff_tol )
+<a name="l01499"></a>01499                     {
+<a name="l01500"></a>01500                         slit_pos[k][0] = pos + (float)edgeclean[k-1] - 
+<a name="l01501"></a>01501                                                (<span class="keywordtype">float</span>)margin ;
+<a name="l01502"></a>01502                     }
+<a name="l01503"></a>01503                     <span class="keywordflow">else</span>
+<a name="l01504"></a>01504                     {
+<a name="l01505"></a>01505                         <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"something wrong with fitted "</span>
+<a name="l01506"></a>01506                                           <span class="stringliteral">"left position of slitlet %d"</span>, j) ;
+<a name="l01507"></a>01507                         slit_pos[k][0] = (float)edgeclean[k-1] - 1. ;
+<a name="l01508"></a>01508                     }
+<a name="l01509"></a>01509                 }
+<a name="l01510"></a>01510             }
+<a name="l01511"></a>01511             <span class="keywordflow">else</span>
+<a name="l01512"></a>01512             {
+<a name="l01513"></a>01513                 <span class="comment">/* take care of the column position of the fit boxes to </span>
+<a name="l01514"></a>01514 <span class="comment">                   get the absolute positions */</span>
+<a name="l01515"></a>01515                 <span class="keywordflow">if</span> ( j == 0 )
+<a name="l01516"></a>01516                 {
+<a name="l01517"></a>01517                     <span class="keywordflow">if</span> ( fabs( (<span class="keywordtype">float</span>)box_buffer->n_elements - pos - 
+<a name="l01518"></a>01518                                (<span class="keywordtype">float</span>)edgeclean[0] ) < diff_tol )
+<a name="l01519"></a>01519                     {
+<a name="l01520"></a>01520                         slit_pos[0][1] = (float)(box_buffer->n_elements - 1) - 
+<a name="l01521"></a>01521                                          pos ;
+<a name="l01522"></a>01522                     }
+<a name="l01523"></a>01523                     <span class="keywordflow">else</span>
+<a name="l01524"></a>01524                     {
+<a name="l01525"></a>01525                         <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"something wrong with fitted "</span>
+<a name="l01526"></a>01526                                           <span class="stringliteral">"right position of slitlet 0"</span>) ;
+<a name="l01527"></a>01527                         slit_pos[0][1] = (float)edgeclean[0] - 1. ;
+<a name="l01528"></a>01528                     }
+<a name="l01529"></a>01529                 }
+<a name="l01530"></a>01530                 <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( j < k )
+<a name="l01531"></a>01531                 {
+<a name="l01532"></a>01532                     <span class="keywordflow">if</span> ( fabs( (<span class="keywordtype">float</span>)box_buffer->n_elements - pos
+<a name="l01533"></a>01533                              + (<span class="keywordtype">float</span>)edgeclean[j-1] - (<span class="keywordtype">float</span>)margin - 
+<a name="l01534"></a>01534                                (<span class="keywordtype">float</span>)edgeclean[j] ) < diff_tol )
+<a name="l01535"></a>01535                     {
+<a name="l01536"></a>01536                         slit_pos[j][1] = (float)(box_buffer->n_elements - 1) - 
+<a name="l01537"></a>01537                                          pos
+<a name="l01538"></a>01538                                        + (float)edgeclean[j-1] - (<span class="keywordtype">float</span>)margin ;
+<a name="l01539"></a>01539                     }
+<a name="l01540"></a>01540                     <span class="keywordflow">else</span>
+<a name="l01541"></a>01541                     {
+<a name="l01542"></a>01542                         <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"something wrong with fitted "</span>
+<a name="l01543"></a>01543                                           <span class="stringliteral">"right position of slitlet %d"</span>, j) ;
+<a name="l01544"></a>01544                         slit_pos[j][1] = (float)edgeclean[j] - 1. ;
+<a name="l01545"></a>01545                     }
+<a name="l01546"></a>01546                 }
+<a name="l01547"></a>01547                 <span class="keywordflow">else</span>
+<a name="l01548"></a>01548                 {
+<a name="l01549"></a>01549                     <span class="keywordflow">if</span> ( edgeclean[k-1] + slit_length > ilx )
+<a name="l01550"></a>01550                     {
+<a name="l01551"></a>01551                         last_pos = (float)(ilx - 1) ;
+<a name="l01552"></a>01552                     }
+<a name="l01553"></a>01553                     <span class="keywordflow">else</span>
+<a name="l01554"></a>01554                     {
+<a name="l01555"></a>01555                         last_pos = (float)(edgeclean[k-1] - 1 + slit_length) ;
+<a name="l01556"></a>01556                     }
+<a name="l01557"></a>01557                     <span class="keywordflow">if</span> ( fabs( (<span class="keywordtype">float</span>)(box_buffer->n_elements - 1) - pos
+<a name="l01558"></a>01558                              + (<span class="keywordtype">float</span>)edgeclean[k-1] - (float)margin - 
+<a name="l01559"></a>01559                                last_pos ) < diff_tol )
+<a name="l01560"></a>01560                     {
+<a name="l01561"></a>01561                         slit_pos[k][1] = (float)(box_buffer->n_elements - 1) - 
+<a name="l01562"></a>01562                                          pos
+<a name="l01563"></a>01563                                        + (float)edgeclean[k-1] - (<span class="keywordtype">float</span>)margin ;
+<a name="l01564"></a>01564                     }
+<a name="l01565"></a>01565                     <span class="keywordflow">else</span>
+<a name="l01566"></a>01566                     {
+<a name="l01567"></a>01567                         <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"something wrong with fitted "</span>
+<a name="l01568"></a>01568                                           <span class="stringliteral">"right position of slitlet %d"</span>, j) ;
+<a name="l01569"></a>01569                         slit_pos[k][1] = last_pos ;
+<a name="l01570"></a>01570                     }
+<a name="l01571"></a>01571                 }
+<a name="l01572"></a>01572             }
+<a name="l01573"></a>01573 
+<a name="l01574"></a>01574             sinfo_new_destroy_vector ( half_buffer ) ;
+<a name="l01575"></a>01575             cpl_free( xdat ) ;
+<a name="l01576"></a>01576             cpl_free( wdat ) ;
+<a name="l01577"></a>01577             cpl_free( mpar ) ;
+<a name="l01578"></a>01578         }
+<a name="l01579"></a>01579         sinfo_new_destroy_vector ( box_buffer ) ;
+<a name="l01580"></a>01580     }
+<a name="l01581"></a>01581      
+<a name="l01582"></a>01582 
+<a name="l01583"></a>01583     cpl_free( sinfo_edge ) ;
+<a name="l01584"></a>01584     cpl_free( pos_row ) ;
+<a name="l01585"></a>01585     cpl_free( edgeclean ) ;
+<a name="l01586"></a>01586     cpl_free( dummyedge ) ;
+<a name="l01587"></a>01587     cpl_free( pos_rowclean ) ;
+<a name="l01588"></a>01588     cpl_free( position);
+<a name="l01589"></a>01589     <span class="keywordflow">return</span> 0 ;
+<a name="l01590"></a>01590 }
+<a name="l01591"></a>01591 
+<a name="l01619"></a>01619 <span class="keywordtype">int</span> 
+<a name="l01620"></a><a class="code" href="group__sinfo__boltzmann.html#gafe44b4032a5b85ff4b88bf7518793b21">01620</a> <a class="code" href="group__sinfo__boltzmann.html#gafe44b4032a5b85ff4b88bf7518793b21" title="fits the beginning and end position of the slitlets by using non-linear least square...">sinfo_new_fit_slits_boltz_single_line</a> ( cpl_image   * lineImage, 
+<a name="l01621"></a>01621                               <span class="keywordtype">float</span>     ** slit_pos,
+<a name="l01622"></a>01622                               <span class="keywordtype">int</span>          box_length,
+<a name="l01623"></a>01623                               <span class="keywordtype">float</span>        y_box,
+<a name="l01624"></a>01624                   <span class="keywordtype">int</span>          low_pos,
+<a name="l01625"></a>01625                   <span class="keywordtype">int</span>          high_pos )
+<a name="l01626"></a>01626 {
+<a name="l01627"></a>01627     <span class="keywordtype">int</span>*     position=NULL ;
+<a name="l01628"></a>01628     <span class="keywordtype">int</span>   * sinfo_edge, * edgeclean ;
+<a name="l01629"></a>01629     <span class="keywordtype">int</span>   * dummyedge ;
+<a name="l01630"></a>01630     <span class="keywordtype">int</span>   * pos_row, * pos_rowclean ;
+<a name="l01631"></a>01631     Vector * box_buffer ;
+<a name="l01632"></a>01632     Vector * half_buffer ;
+<a name="l01633"></a>01633     Vector * in_buffer ;
+<a name="l01634"></a>01634     <span class="keywordtype">int</span>   found_row ;
+<a name="l01635"></a>01635     <span class="keywordtype">int</span>   row, col ;
+<a name="l01636"></a>01636     <span class="keywordtype">int</span>   i, j, k, m, ed ;
+<a name="l01637"></a>01637     <span class="keywordtype">int</span>   init1 ;
+<a name="l01638"></a>01638     <span class="keywordtype">int</span>   nel, n_right, left_right ;
+<a name="l01639"></a>01639     <span class="keywordtype">int</span>   n_buf, edge_ind, shift ;
+<a name="l01640"></a>01640     <span class="keywordtype">int</span>   slit_length ;
+<a name="l01641"></a>01641     <span class="keywordtype">int</span>   margin ;
+<a name="l01642"></a>01642     <span class="keywordtype">int</span>   iters, xdim, ndat ;
+<a name="l01643"></a>01643     <span class="keywordtype">int</span>   numpar, its ;
+<a name="l01644"></a>01644     <span class="keywordtype">int</span>   * mpar ;
+<a name="l01645"></a>01645     <span class="keywordtype">float</span> * xdat, * wdat ;
+<a name="l01646"></a>01646     <span class="keywordtype">float</span> tol, lab ;
+<a name="l01647"></a>01647     <span class="keywordtype">float</span> fitpar[NPAR] ;
+<a name="l01648"></a>01648     <span class="keywordtype">float</span> dervpar[NPAR] ;
+<a name="l01649"></a>01649     <span class="keywordtype">float</span> minval, maxval ;
+<a name="l01650"></a>01650     <span class="keywordtype">float</span> min ;
+<a name="l01651"></a>01651     <span class="keywordtype">float</span> pos, last_pos ;
+<a name="l01652"></a>01652     <span class="keywordtype">int</span> ilx=0;
+<a name="l01653"></a>01653     <span class="keywordtype">int</span> ily=0;
+<a name="l01654"></a>01654     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l01655"></a>01655 
+<a name="l01656"></a>01656     slit_length = SLITLENGTH ;
+<a name="l01657"></a>01657 
+<a name="l01658"></a>01658     <span class="keywordflow">if</span> ( NULL == lineImage )
+<a name="l01659"></a>01659     {
+<a name="l01660"></a>01660         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" no line image given!"</span> ) ;
+<a name="l01661"></a>01661         <span class="keywordflow">return</span> -1 ;
+<a name="l01662"></a>01662     }
+<a name="l01663"></a>01663 
+<a name="l01664"></a>01664     <span class="keywordflow">if</span> ( NULL == slit_pos )
+<a name="l01665"></a>01665     {
+<a name="l01666"></a>01666         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" no position array allocated!"</span> ) ;
+<a name="l01667"></a>01667         <span class="keywordflow">return</span> -1 ;
+<a name="l01668"></a>01668     }
+<a name="l01669"></a>01669 
+<a name="l01670"></a>01670     <span class="keywordflow">if</span> ( box_length <  4 ||
+<a name="l01671"></a>01671          box_length >  2*slit_length )
+<a name="l01672"></a>01672     {
+<a name="l01673"></a>01673         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" wrong fitting box length given!"</span> ) ;
+<a name="l01674"></a>01674         <span class="keywordflow">return</span> -1 ;
+<a name="l01675"></a>01675     }
+<a name="l01676"></a>01676 
+<a name="l01677"></a>01677     <span class="keywordflow">if</span> ( y_box <= 0. || y_box > 6. )
+<a name="l01678"></a>01678     {
+<a name="l01679"></a>01679         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" wrong y box length given!"</span> ) ;
+<a name="l01680"></a>01680         <span class="keywordflow">return</span> -1 ;
+<a name="l01681"></a>01681     }
+<a name="l01682"></a>01682 
+<a name="l01683"></a>01683     ilx=cpl_image_get_size_x(lineImage);
+<a name="l01684"></a>01684     ily=cpl_image_get_size_y(lineImage);
+<a name="l01685"></a>01685     pidata=cpl_image_get_data_float(lineImage);
+<a name="l01686"></a>01686 
+<a name="l01687"></a>01687     <span class="keywordflow">if</span> ( low_pos >= high_pos || low_pos < 0 || 
+<a name="l01688"></a>01688          high_pos <= 0 || high_pos >= ilx )
+<a name="l01689"></a>01689     {
+<a name="l01690"></a>01690         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" wrong user given search positions!"</span> ) ;
+<a name="l01691"></a>01691         <span class="keywordflow">return</span> -1 ;
+<a name="l01692"></a>01692     }
+<a name="l01693"></a>01693 
+<a name="l01694"></a>01694     <span class="comment">/* allocate memory for the edges and the row position of the slitlets */</span>
+<a name="l01695"></a>01695     sinfo_edge         = (<span class="keywordtype">int</span>*) cpl_calloc( ilx/2, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>) ) ;
+<a name="l01696"></a>01696     dummyedge    = (<span class="keywordtype">int</span>*) cpl_calloc( ilx/2, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>) ) ;
+<a name="l01697"></a>01697     edgeclean    = (<span class="keywordtype">int</span>*) cpl_calloc( ilx/2, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>) ) ;
+<a name="l01698"></a>01698     pos_row      = (<span class="keywordtype">int</span>*) cpl_calloc( ilx/2, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>) ) ;
+<a name="l01699"></a>01699     pos_rowclean = (<span class="keywordtype">int</span>*) cpl_calloc( ilx/2, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>) ) ;
+<a name="l01700"></a>01700 
+<a name="l01701"></a>01701     <span class="comment">/* now search for the maximum between the given positions for each col */</span>
+<a name="l01702"></a>01702     position=cpl_calloc(ilx,<span class="keyword">sizeof</span>(<span class="keywordtype">int</span>)); ;
+<a name="l01703"></a>01703 
+<a name="l01704"></a>01704     <span class="keywordflow">for</span> ( col = 0 ; col < ilx ; col++ )
+<a name="l01705"></a>01705     {
+<a name="l01706"></a>01706         found_row = -1 ;
+<a name="l01707"></a>01707         maxval = -FLT_MAX ;
+<a name="l01708"></a>01708     <span class="keywordflow">for</span> ( row = low_pos ; row <= high_pos ; row++ )
+<a name="l01709"></a>01709     {
+<a name="l01710"></a>01710         <span class="keywordflow">if</span> ( maxval < pidata[col+row*ilx] )
+<a name="l01711"></a>01711             {
+<a name="l01712"></a>01712         maxval = pidata[col+row*ilx] ;
+<a name="l01713"></a>01713                 found_row = row ;
+<a name="l01714"></a>01714         }
+<a name="l01715"></a>01715     }
+<a name="l01716"></a>01716     <span class="keywordflow">if</span> ( maxval > -FLT_MAX && found_row > low_pos )
+<a name="l01717"></a>01717     {
+<a name="l01718"></a>01718             position[col] = found_row ;
+<a name="l01719"></a>01719         }
+<a name="l01720"></a>01720     <span class="keywordflow">else</span>
+<a name="l01721"></a>01721     {
+<a name="l01722"></a>01722         position[col] = 0 ;
+<a name="l01723"></a>01723         }
+<a name="l01724"></a>01724     }
+<a name="l01725"></a>01725 
+<a name="l01726"></a>01726     <span class="comment">/* now find and store the raw sinfo_edge positions of the found slitlet */</span> 
+<a name="l01727"></a>01727     ed = 0 ;
+<a name="l01728"></a>01728     <span class="keywordflow">for</span> ( col = 0 ; col < (ilx) - 1 ; col++ )
+<a name="l01729"></a>01729     {
+<a name="l01730"></a>01730         <span class="keywordflow">if</span> ( position[col] > 0 && position[col+1] > 0 &&
+<a name="l01731"></a>01731          abs(position[col+1] - position[col]) > 10 ) 
+<a name="l01732"></a>01732         {
+<a name="l01733"></a>01733             sinfo_edge[ed] = col ; 
+<a name="l01734"></a>01734             pos_row[ed] = position[col] ;
+<a name="l01735"></a>01735             ed++ ;
+<a name="l01736"></a>01736         }
+<a name="l01737"></a>01737 
+<a name="l01738"></a>01738     }
+<a name="l01739"></a>01739     <span class="keywordflow">if</span> (ed <= 1)
+<a name="l01740"></a>01740     {
+<a name="l01741"></a>01741         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" no slitlets found!"</span> ) ;
+<a name="l01742"></a>01742         cpl_free( sinfo_edge ) ;
+<a name="l01743"></a>01743         cpl_free( pos_row ) ;
+<a name="l01744"></a>01744         cpl_free( edgeclean ) ;
+<a name="l01745"></a>01745         cpl_free( dummyedge ) ;
+<a name="l01746"></a>01746         cpl_free( pos_rowclean ) ;
+<a name="l01747"></a>01747         <span class="keywordflow">return</span> -1 ;
+<a name="l01748"></a>01748     }
+<a name="l01749"></a>01749 
+<a name="l01750"></a>01750     <span class="comment">/* now find the clean sinfo_edge and row positions of the slitlets */</span>
+<a name="l01751"></a>01751     <span class="keywordflow">for</span> ( i = 1 ; i <= ed ; i ++ )
+<a name="l01752"></a>01752     {
+<a name="l01753"></a>01753         <span class="keywordflow">if</span> ( i == ed )
+<a name="l01754"></a>01754         {
+<a name="l01755"></a>01755             <span class="keywordflow">if</span> ( (sinfo_edge[i-1] - sinfo_edge[i-2]) < 
+<a name="l01756"></a>01756                   slit_length - SLIT_LEN_ERR ||
+<a name="l01757"></a>01757                  (sinfo_edge[i-1] - sinfo_edge[i-2]) > 
+<a name="l01758"></a>01758                   slit_length + SLIT_LEN_ERR )
+<a name="l01759"></a>01759             {
+<a name="l01760"></a>01760                 dummyedge[i-1]   = -1 ;
+<a name="l01761"></a>01761             }
+<a name="l01762"></a>01762         }
+<a name="l01763"></a>01763         <span class="keywordflow">if</span> (dummyedge[i-1] != -1)
+<a name="l01764"></a>01764         {
+<a name="l01765"></a>01765             dummyedge[i-1] = sinfo_edge[i-1] ;
+<a name="l01766"></a>01766         }
+<a name="l01767"></a>01767         <span class="keywordflow">else</span>
+<a name="l01768"></a>01768         {
+<a name="l01769"></a>01769             continue ;
+<a name="l01770"></a>01770         }
+<a name="l01771"></a>01771         <span class="keywordflow">if</span> ( i < ed )
+<a name="l01772"></a>01772         {
+<a name="l01773"></a>01773             <span class="keywordflow">if</span> ( (sinfo_edge[i] - sinfo_edge[i-1]) < 
+<a name="l01774"></a>01774                   slit_length - SLIT_LEN_ERR ||
+<a name="l01775"></a>01775                  (sinfo_edge[i] - sinfo_edge[i-1]) > 
+<a name="l01776"></a>01776                   slit_length + SLIT_LEN_ERR )
+<a name="l01777"></a>01777             {
+<a name="l01778"></a>01778                 dummyedge[i]   = -1 ;
+<a name="l01779"></a>01779             }
+<a name="l01780"></a>01780         }
+<a name="l01781"></a>01781         <span class="keywordflow">if</span> ( i+1 < ed && dummyedge[i] != -1 )
+<a name="l01782"></a>01782         {
+<a name="l01783"></a>01783             <span class="keywordflow">if</span> ( (sinfo_edge[i+1] - sinfo_edge[i]) < 
+<a name="l01784"></a>01784                   slit_length - SLIT_LEN_ERR ||
+<a name="l01785"></a>01785                  (sinfo_edge[i+1] - sinfo_edge[i]) > 
+<a name="l01786"></a>01786                   slit_length + SLIT_LEN_ERR )
+<a name="l01787"></a>01787             {
+<a name="l01788"></a>01788                 dummyedge[i+1] = -1 ; 
+<a name="l01789"></a>01789             }
+<a name="l01790"></a>01790         }
+<a name="l01791"></a>01791     }
+<a name="l01792"></a>01792     
+<a name="l01793"></a>01793     k = 0 ;
+<a name="l01794"></a>01794     <span class="keywordflow">for</span> ( i = 0 ; i < ed ; i++ )
+<a name="l01795"></a>01795     {
+<a name="l01796"></a>01796         <span class="keywordflow">if</span> ( dummyedge[i] != -1 && dummyedge[i] != 0 )
+<a name="l01797"></a>01797         {
+<a name="l01798"></a>01798             edgeclean[k] = dummyedge[i] ;
+<a name="l01799"></a>01799             pos_rowclean[k] = pos_row[i] ;
+<a name="l01800"></a>01800             k++ ;
+<a name="l01801"></a>01801             <span class="keywordflow">if</span>( edgeclean[k-1] > (ilx - slit_length - 2*SLIT_LEN_ERR ) )
+<a name="l01802"></a>01802             {
+<a name="l01803"></a>01803                 pos_rowclean[k] = pos_row[ed] ;
+<a name="l01804"></a>01804             }
+<a name="l01805"></a>01805         }
+<a name="l01806"></a>01806     }
+<a name="l01807"></a>01807 
+<a name="l01808"></a>01808     <span class="comment">/* determine the margins of the fitting box outside the slitlets */</span>
+<a name="l01809"></a>01809     margin = box_length / 2 ;
+<a name="l01810"></a>01810 
+<a name="l01811"></a>01811     <span class="comment">/* ------------------------------------------------------------------------</span>
+<a name="l01812"></a>01812 <span class="comment">     * now go through the slitlets, search along each column within a box with </span>
+<a name="l01813"></a>01813 <span class="comment">     * half width y_box the maximum value and store these found values in a </span>
+<a name="l01814"></a>01814 <span class="comment">     * buffer</span>
+<a name="l01815"></a>01815 <span class="comment">     */</span>
+<a name="l01816"></a>01816     <span class="keywordflow">for</span> ( j = 0 ; j <= k ; j++ )
+<a name="l01817"></a>01817     {
+<a name="l01818"></a>01818         m = 0 ;
+<a name="l01819"></a>01819         <span class="keywordflow">if</span> ( j == 0 )
+<a name="l01820"></a>01820         {
+<a name="l01821"></a>01821             box_buffer = sinfo_new_vector( edgeclean[0] + margin ) ;
+<a name="l01822"></a>01822             <span class="keywordflow">for</span>( col = 0 ; col < edgeclean[0] + margin ; col++ )
+<a name="l01823"></a>01823             {
+<a name="l01824"></a>01824                 maxval = -FLT_MAX ;
+<a name="l01825"></a>01825                 <span class="keywordflow">for</span> ( row = pos_rowclean[0] - sinfo_new_nint(y_box) ; 
+<a name="l01826"></a>01826                       row <= pos_rowclean[0] + sinfo_new_nint(y_box) ; row++ )
+<a name="l01827"></a>01827                 {
+<a name="l01828"></a>01828                     <span class="keywordflow">if</span> ( maxval < pidata[col + ilx*row] )
+<a name="l01829"></a>01829                     {
+<a name="l01830"></a>01830                         maxval = pidata[col + ilx*row] ;
+<a name="l01831"></a>01831                     }
+<a name="l01832"></a>01832                 }
+<a name="l01833"></a>01833                 box_buffer->data[m] = maxval ;
+<a name="l01834"></a>01834                 m++ ;
+<a name="l01835"></a>01835             }
+<a name="l01836"></a>01836         }
+<a name="l01837"></a>01837         <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( j < k )
+<a name="l01838"></a>01838         {
+<a name="l01839"></a>01839             box_buffer = sinfo_new_vector( edgeclean[j] - 
+<a name="l01840"></a>01840                                            edgeclean[j-1] + 2*margin ) ;
+<a name="l01841"></a>01841             <span class="keywordflow">for</span> ( col = edgeclean[j - 1] - margin ; 
+<a name="l01842"></a>01842                   col < edgeclean[j] + margin ; col++ )
+<a name="l01843"></a>01843             {
+<a name="l01844"></a>01844                 maxval = -FLT_MAX ;
+<a name="l01845"></a>01845                 <span class="keywordflow">for</span> ( row = pos_rowclean[j] - sinfo_new_nint(y_box) ; 
+<a name="l01846"></a>01846                       row <= pos_rowclean[j] + sinfo_new_nint(y_box) ; row++ )
+<a name="l01847"></a>01847                 {
+<a name="l01848"></a>01848                     <span class="keywordflow">if</span> ( maxval < pidata[col + ilx*row] )
+<a name="l01849"></a>01849                     {
+<a name="l01850"></a>01850                         maxval = pidata[col + ilx*row] ;
+<a name="l01851"></a>01851                     }
+<a name="l01852"></a>01852                 }
+<a name="l01853"></a>01853                 box_buffer->data[m] = maxval ;
+<a name="l01854"></a>01854                 m++ ;
+<a name="l01855"></a>01855             }
+<a name="l01856"></a>01856         }
+<a name="l01857"></a>01857         <span class="keywordflow">else</span> 
+<a name="l01858"></a>01858         {
+<a name="l01859"></a>01859             box_buffer = sinfo_new_vector( ilx - edgeclean[k-1] + margin ) ;
+<a name="l01860"></a>01860             <span class="keywordflow">for</span> ( col = edgeclean[k - 1] - margin ; col < ilx ; col++ )
+<a name="l01861"></a>01861             {
+<a name="l01862"></a>01862         <span class="keywordflow">if</span> ( col < 0 )
+<a name="l01863"></a>01863         {
+<a name="l01864"></a>01864             col = 0 ;
+<a name="l01865"></a>01865                 }
+<a name="l01866"></a>01866 
+<a name="l01867"></a>01867                 maxval = -FLT_MAX ;
+<a name="l01868"></a>01868                 <span class="keywordflow">for</span> ( row = pos_rowclean[k] - sinfo_new_nint(y_box) ; 
+<a name="l01869"></a>01869                       row <= pos_rowclean[k] + sinfo_new_nint(y_box) ; row++ )
+<a name="l01870"></a>01870                 {
+<a name="l01871"></a>01871             <span class="keywordflow">if</span> ( row < 0 )
+<a name="l01872"></a>01872                     {
+<a name="l01873"></a>01873             continue ;
+<a name="l01874"></a>01874                     }
+<a name="l01875"></a>01875                     <span class="keywordflow">if</span> ( maxval < pidata[col + row * ilx] )
+<a name="l01876"></a>01876                     {
+<a name="l01877"></a>01877                         maxval = pidata[col + row * ilx] ;
+<a name="l01878"></a>01878                     }
+<a name="l01879"></a>01879                 }
+<a name="l01880"></a>01880                 box_buffer->data[m] = maxval ;
+<a name="l01881"></a>01881                 m++ ;
+<a name="l01882"></a>01882             }
+<a name="l01883"></a>01883         }
+<a name="l01884"></a>01884 
+<a name="l01885"></a>01885         <span class="comment">/* determine the minimum value in the box to get background1 </span>
+<a name="l01886"></a>01886 <span class="comment">           value for the sinfo_edge slitlets */</span>
+<a name="l01887"></a>01887         min = FLT_MAX ;
+<a name="l01888"></a>01888         <span class="keywordflow">for</span> ( i = 0 ; i < box_buffer->n_elements ; i++ )
+<a name="l01889"></a>01889         {
+<a name="l01890"></a>01890             <span class="keywordflow">if</span> ( box_buffer -> data[i] < min )
+<a name="l01891"></a>01891             {
+<a name="l01892"></a>01892                 min = box_buffer -> data[i] ;
+<a name="l01893"></a>01893             }
+<a name="l01894"></a>01894         }
+<a name="l01895"></a>01895 
+<a name="l01896"></a>01896         <span class="keywordflow">for</span> ( left_right = 0 ; left_right <= 1 ; left_right++ )
+<a name="l01897"></a>01897         { 
+<a name="l01898"></a>01898             nel = 0 ;
+<a name="l01899"></a>01899             <span class="keywordflow">if</span> ( left_right == 0 )
+<a name="l01900"></a>01900             {
+<a name="l01901"></a>01901                 nel = box_buffer -> n_elements / 2 ;
+<a name="l01902"></a>01902             }
+<a name="l01903"></a>01903             <span class="keywordflow">else</span>
+<a name="l01904"></a>01904             {
+<a name="l01905"></a>01905                 <span class="keywordflow">if</span> ( box_buffer -> n_elements % 2 == 0 )
+<a name="l01906"></a>01906                 {
+<a name="l01907"></a>01907                     nel = box_buffer -> n_elements / 2 ;
+<a name="l01908"></a>01908                 }
+<a name="l01909"></a>01909                 <span class="keywordflow">else</span>
+<a name="l01910"></a>01910                 {
+<a name="l01911"></a>01911                     nel = box_buffer -> n_elements / 2 + 1 ;
+<a name="l01912"></a>01912                 }
+<a name="l01913"></a>01913             }
+<a name="l01914"></a>01914 
+<a name="l01915"></a>01915             <span class="comment">/* now split the buffer in the midth in a left and </span>
+<a name="l01916"></a>01916 <span class="comment">               right part for fitting */</span>
+<a name="l01917"></a>01917             half_buffer = sinfo_new_vector( nel ) ;
+<a name="l01918"></a>01918             <span class="keywordflow">if</span> ( left_right == 0 )
+<a name="l01919"></a>01919             {
+<a name="l01920"></a>01920                 <span class="keywordflow">for</span> ( i = 0 ; i < nel ; i++ )
+<a name="l01921"></a>01921                 {
+<a name="l01922"></a>01922                     half_buffer -> data[i] = box_buffer -> data[i] ;
+<a name="l01923"></a>01923                 }
+<a name="l01924"></a>01924             }
+<a name="l01925"></a>01925             <span class="keywordflow">else</span>
+<a name="l01926"></a>01926             {
+<a name="l01927"></a>01927                 n_right = 0 ;
+<a name="l01928"></a>01928                 <span class="keywordflow">for</span> ( i = box_buffer -> n_elements - 1 ; 
+<a name="l01929"></a>01929                       i >= box_buffer -> n_elements - nel ; i-- )
+<a name="l01930"></a>01930                 {
+<a name="l01931"></a>01931                     half_buffer -> data[n_right] = box_buffer -> data[i] ;
+<a name="l01932"></a>01932                     n_right++ ;
+<a name="l01933"></a>01933                 }
+<a name="l01934"></a>01934             }
+<a name="l01935"></a>01935 
+<a name="l01936"></a>01936             xdat = (<span class="keywordtype">float</span> *) cpl_calloc( nel, <span class="keyword">sizeof</span> (<span class="keywordtype">float</span>) ) ;
+<a name="l01937"></a>01937             wdat = (<span class="keywordtype">float</span> *) cpl_calloc( nel, <span class="keyword">sizeof</span> (<span class="keywordtype">float</span>) ) ;
+<a name="l01938"></a>01938             mpar = (<span class="keywordtype">int</span> *)   cpl_calloc( NPAR, <span class="keyword">sizeof</span> (<span class="keywordtype">int</span>) ) ;
+<a name="l01939"></a>01939 
+<a name="l01940"></a>01940             <span class="comment">/* set initial values for the fitting routine */</span>
+<a name="l01941"></a>01941             minval =  FLT_MAX ;
+<a name="l01942"></a>01942             maxval = -FLT_MAX ;
+<a name="l01943"></a>01943             <span class="keywordflow">for</span> ( i = 0 ; i < nel ; i++ )
+<a name="l01944"></a>01944             {
+<a name="l01945"></a>01945                 xdat[i] = i ;
+<a name="l01946"></a>01946                 wdat[i] = 1.0 ;
+<a name="l01947"></a>01947                 <span class="keywordflow">if</span> ( half_buffer -> data[i] < minval )
+<a name="l01948"></a>01948                 {
+<a name="l01949"></a>01949                     minval = half_buffer -> data[i] ;
+<a name="l01950"></a>01950                 }
+<a name="l01951"></a>01951                 <span class="keywordflow">if</span> ( half_buffer -> data[i] > maxval )
+<a name="l01952"></a>01952                 {
+<a name="l01953"></a>01953                     maxval = half_buffer -> data[i] ;
+<a name="l01954"></a>01954                 }
+<a name="l01955"></a>01955             }
+<a name="l01956"></a>01956             fitpar[0] = minval ;
+<a name="l01957"></a>01957             fitpar[1] = maxval ; 
+<a name="l01958"></a>01958 
+<a name="l01959"></a>01959             <span class="comment">/* search for both positions of the half intensity of </span>
+<a name="l01960"></a>01960 <span class="comment">               the hat within the buffer */</span>
+<a name="l01961"></a>01961             init1 = -1 ; 
+<a name="l01962"></a>01962             <span class="keywordflow">for</span> ( i = 0 ; i < nel ; i++ )
+<a name="l01963"></a>01963             {
+<a name="l01964"></a>01964                 <span class="keywordflow">if</span> ( half_buffer -> data[i] >= ( maxval + minval ) / 2. )
+<a name="l01965"></a>01965                 {
+<a name="l01966"></a>01966                     init1 = i ;
+<a name="l01967"></a>01967                     break ;
+<a name="l01968"></a>01968                 }
+<a name="l01969"></a>01969             }
+<a name="l01970"></a>01970 
+<a name="l01971"></a>01971             <span class="comment">/*---------------------------------------------------------------</span>
+<a name="l01972"></a>01972 <span class="comment">             * if we have too few left background values (at the image edges)</span>
+<a name="l01973"></a>01973 <span class="comment">             * the left margin of the buffer to fit is filled with the minimal</span>
+<a name="l01974"></a>01974 <span class="comment">             * values in order to get a good fit</span>
+<a name="l01975"></a>01975 <span class="comment">             */</span>
+<a name="l01976"></a>01976               
+<a name="l01977"></a>01977             edge_ind = 0 ;
+<a name="l01978"></a>01978             <span class="keywordflow">if</span> ( init1 < 3 )
+<a name="l01979"></a>01979             {
+<a name="l01980"></a>01980                 n_buf = half_buffer->n_elements + margin ;
+<a name="l01981"></a>01981                 in_buffer = sinfo_new_vector( n_buf ) ;     
+<a name="l01982"></a>01982                 <span class="keywordflow">for</span> ( i = 0 ; i < margin ; i++ )
+<a name="l01983"></a>01983                 {
+<a name="l01984"></a>01984                     in_buffer -> data[i] = min ;
+<a name="l01985"></a>01985                 }
+<a name="l01986"></a>01986                 shift = 0 ;
+<a name="l01987"></a>01987                 <span class="keywordflow">for</span> ( i = margin ; i < n_buf ; i++ )
+<a name="l01988"></a>01988                 {
+<a name="l01989"></a>01989                     in_buffer -> data[i] = half_buffer -> data[shift] ;
+<a name="l01990"></a>01990                     shift++ ;
+<a name="l01991"></a>01991                 }
+<a name="l01992"></a>01992                 sinfo_new_destroy_vector ( half_buffer ) ;
+<a name="l01993"></a>01993                 half_buffer = sinfo_new_vector ( n_buf ) ;
+<a name="l01994"></a>01994                 <span class="keywordflow">for</span> ( i = 0 ; i < n_buf ; i++ )
+<a name="l01995"></a>01995                 {
+<a name="l01996"></a>01996                     half_buffer -> data[i] = in_buffer -> data[i] ;
+<a name="l01997"></a>01997                 }
+<a name="l01998"></a>01998                 edge_ind = 1 ;
+<a name="l01999"></a>01999                 init1 += margin ;
+<a name="l02000"></a>02000                 sinfo_new_destroy_vector ( in_buffer ) ;
+<a name="l02001"></a>02001             }
+<a name="l02002"></a>02002 
+<a name="l02003"></a>02003             <span class="comment">/* determine the initial positions from the found values */</span>
+<a name="l02004"></a>02004             <span class="keywordflow">if</span> ( init1 != -1 )
+<a name="l02005"></a>02005             {
+<a name="l02006"></a>02006                 fitpar[2] = (float)init1 ;
+<a name="l02007"></a>02007             }
+<a name="l02008"></a>02008             fitpar[3] = 1. ;
+<a name="l02009"></a>02009 
+<a name="l02010"></a>02010             <span class="keywordflow">for</span> ( i = 0 ; i < NPAR ; i++ )
+<a name="l02011"></a>02011             {
+<a name="l02012"></a>02012                 mpar[i] = 1 ;
+<a name="l02013"></a>02013                 dervpar[i] = 0. ;
+<a name="l02014"></a>02014             }
+<a name="l02015"></a>02015       
+<a name="l02016"></a>02016             xdim     = XDIMA ;
+<a name="l02017"></a>02017             ndat     = nel ;
+<a name="l02018"></a>02018             numpar   = NPAR ;
+<a name="l02019"></a>02019             tol      = TOLA ;
+<a name="l02020"></a>02020             lab      = LABA ;
+<a name="l02021"></a>02021             its      = ITSA ;
+<a name="l02022"></a>02022          
+<a name="l02023"></a>02023             <span class="comment">/* finally, do the least squares fit over the buffer data */</span>
+<a name="l02024"></a>02024             <span class="keywordflow">if</span> ( 0 > ( iters = <a class="code" href="group__sinfo__boltzmann.html#ga7e03e34851f7c367ab3827c58e8c81c5" title="makes a least-squares fit of a function to a set of data points.">sinfo_new_lsqfit</a>( xdat, &xdim, 
+<a name="l02025"></a>02025                                                  half_buffer -> data, 
+<a name="l02026"></a>02026                                                  wdat, &ndat, fitpar,
+<a name="l02027"></a>02027                                                  dervpar, mpar, &numpar, 
+<a name="l02028"></a>02028                                                  &tol, &its, &lab )) )
+<a name="l02029"></a>02029             { 
+<a name="l02030"></a>02030                 <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a> (<span class="stringliteral">" least squares fit failed, error "</span>
+<a name="l02031"></a>02031                                    <span class="stringliteral">"no.: %d in slitlet: %d"</span>, iters, j) ;
+<a name="l02032"></a>02032                 fitpar[2] = 0. ;
+<a name="l02033"></a>02033             }
+<a name="l02034"></a>02034         <span class="keywordflow">if</span> ( fitpar[3] <=0. )
+<a name="l02035"></a>02035             { 
+<a name="l02036"></a>02036                 <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">" fit failed due to negative width"</span>
+<a name="l02037"></a>02037                                   <span class="stringliteral">" of boltzmann function in slitlet: %d"</span>, j) ;
+<a name="l02038"></a>02038                 fitpar[2] = 0. ;
+<a name="l02039"></a>02039             }
+<a name="l02040"></a>02040 
+<a name="l02041"></a>02041             pos = fitpar[2] ;
+<a name="l02042"></a>02042             <span class="keywordflow">if</span> ( edge_ind == 1 )
+<a name="l02043"></a>02043             {
+<a name="l02044"></a>02044                 pos -= (float)margin ;
+<a name="l02045"></a>02045             }
+<a name="l02046"></a>02046 
+<a name="l02047"></a>02047             <span class="comment">/*------------------------------------------------------------- </span>
+<a name="l02048"></a>02048 <span class="comment">             * now discern the left and the right sinfo_edge fit of the </span>
+<a name="l02049"></a>02049 <span class="comment">             * slitlets and associate the fit results with the absolute </span>
+<a name="l02050"></a>02050 <span class="comment">             * positions in the image consider the difference of the fitted </span>
+<a name="l02051"></a>02051 <span class="comment">             * slit position to the expected position and decide wether the </span>
+<a name="l02052"></a>02052 <span class="comment">             * fit is taken or the expected value is taken.</span>
+<a name="l02053"></a>02053 <span class="comment">             */</span>
+<a name="l02054"></a>02054             <span class="keywordflow">if</span> ( left_right == 0 )
+<a name="l02055"></a>02055             {
+<a name="l02056"></a>02056                 <span class="comment">/* take care of the column position of the fit boxes to </span>
+<a name="l02057"></a>02057 <span class="comment">                   get the absolute positions */</span>
+<a name="l02058"></a>02058                 <span class="keywordflow">if</span> ( j == 0 )
+<a name="l02059"></a>02059                 {
+<a name="l02060"></a>02060                     slit_pos[0][0] = pos ;
+<a name="l02061"></a>02061             <span class="keywordflow">if</span> ( slit_pos[0][0] - (<span class="keywordtype">int</span>) slit_pos[0][0] == 0.)
+<a name="l02062"></a>02062             {
+<a name="l02063"></a>02063                         slit_pos[0][0] = 0. ;
+<a name="l02064"></a>02064                     }
+<a name="l02065"></a>02065                 }
+<a name="l02066"></a>02066                 <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( j < k )
+<a name="l02067"></a>02067                 {
+<a name="l02068"></a>02068                     slit_pos[j][0] = pos + (float)edgeclean[j-1] - 
+<a name="l02069"></a>02069                                            (<span class="keywordtype">float</span>)margin ;
+<a name="l02070"></a>02070             <span class="keywordflow">if</span> ( slit_pos[j][0] - (<span class="keywordtype">int</span>) slit_pos[j][0] == 0.)
+<a name="l02071"></a>02071             {
+<a name="l02072"></a>02072                         slit_pos[j][0] = 0. ;
+<a name="l02073"></a>02073                     }
+<a name="l02074"></a>02074                 }
+<a name="l02075"></a>02075                 <span class="keywordflow">else</span>
+<a name="l02076"></a>02076                 {
+<a name="l02077"></a>02077                     slit_pos[k][0] = pos + (float)edgeclean[k-1] - 
+<a name="l02078"></a>02078                                            (<span class="keywordtype">float</span>)margin ;
+<a name="l02079"></a>02079             <span class="keywordflow">if</span> ( slit_pos[k][0] - (<span class="keywordtype">int</span>) slit_pos[k][0] == 0.)
+<a name="l02080"></a>02080             {
+<a name="l02081"></a>02081                         slit_pos[k][0] = 0. ;
+<a name="l02082"></a>02082                     }
+<a name="l02083"></a>02083                 }
+<a name="l02084"></a>02084             }
+<a name="l02085"></a>02085             <span class="keywordflow">else</span>
+<a name="l02086"></a>02086             {
+<a name="l02087"></a>02087                 <span class="comment">/* take care of the column position of the fit boxes to </span>
+<a name="l02088"></a>02088 <span class="comment">                   get the absolute positions */</span>
+<a name="l02089"></a>02089                 <span class="keywordflow">if</span> ( j == 0 )
+<a name="l02090"></a>02090                 {
+<a name="l02091"></a>02091                     slit_pos[0][1] = (float)(box_buffer->n_elements - 1) - pos;
+<a name="l02092"></a>02092             <span class="keywordflow">if</span> ( slit_pos[0][1] - (<span class="keywordtype">int</span>) slit_pos[0][1] == 0.)
+<a name="l02093"></a>02093             {
+<a name="l02094"></a>02094                         slit_pos[0][1] = 0. ;
+<a name="l02095"></a>02095                     }
+<a name="l02096"></a>02096                 }
+<a name="l02097"></a>02097                 <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( j < k )
+<a name="l02098"></a>02098                 {
+<a name="l02099"></a>02099                     slit_pos[j][1] = (float)(box_buffer->n_elements - 1) - pos
+<a name="l02100"></a>02100                                      + (float)edgeclean[j-1] - (<span class="keywordtype">float</span>)margin ;
+<a name="l02101"></a>02101             <span class="keywordflow">if</span> ( slit_pos[j][1] - (<span class="keywordtype">int</span>) slit_pos[j][1] == 0.)
+<a name="l02102"></a>02102             {
+<a name="l02103"></a>02103                         slit_pos[j][1] = 0. ;
+<a name="l02104"></a>02104                     }
+<a name="l02105"></a>02105                 }
+<a name="l02106"></a>02106                 <span class="keywordflow">else</span>
+<a name="l02107"></a>02107                 {
+<a name="l02108"></a>02108                     last_pos = (float)(edgeclean[k-1] - 1 + slit_length) ;
+<a name="l02109"></a>02109                     slit_pos[k][1] = (float)(box_buffer->n_elements - 1) - pos
+<a name="l02110"></a>02110                                      + (float)edgeclean[k-1] - (<span class="keywordtype">float</span>)margin ;
+<a name="l02111"></a>02111             <span class="keywordflow">if</span> ( slit_pos[k][1] - (<span class="keywordtype">int</span>) slit_pos[k][1] == 0.)
+<a name="l02112"></a>02112             {
+<a name="l02113"></a>02113                         slit_pos[k][1] = 0. ;
+<a name="l02114"></a>02114                     }
+<a name="l02115"></a>02115                 }
+<a name="l02116"></a>02116             }
+<a name="l02117"></a>02117 
+<a name="l02118"></a>02118             sinfo_new_destroy_vector ( half_buffer ) ;
+<a name="l02119"></a>02119             cpl_free( xdat ) ;
+<a name="l02120"></a>02120             cpl_free( wdat ) ;
+<a name="l02121"></a>02121             cpl_free( mpar ) ;
+<a name="l02122"></a>02122         }
+<a name="l02123"></a>02123         sinfo_new_destroy_vector ( box_buffer ) ;
+<a name="l02124"></a>02124     }
+<a name="l02125"></a>02125         
+<a name="l02126"></a>02126     cpl_free( sinfo_edge ) ;
+<a name="l02127"></a>02127     cpl_free( pos_row ) ;
+<a name="l02128"></a>02128     cpl_free( edgeclean ) ;
+<a name="l02129"></a>02129     cpl_free( dummyedge ) ;
+<a name="l02130"></a>02130     cpl_free( pos_rowclean ) ;
+<a name="l02131"></a>02131     cpl_free( position );
+<a name="l02132"></a>02132     <span class="keywordflow">return</span> 0 ;
+<a name="l02133"></a>02133 }
+<a name="l02134"></a>02134 
+<a name="l02163"></a>02163 <span class="keywordtype">int</span> 
+<a name="l02164"></a><a class="code" href="group__sinfo__boltzmann.html#ga1851d695a240ae0d23d20657f02867bb">02164</a> <a class="code" href="group__sinfo__boltzmann.html#ga1851d695a240ae0d23d20657f02867bb" title="its the beginning and end position of the slitlets by using non-linear least square...">sinfo_new_fit_slits_boltz_with_estimate</a> ( cpl_image   * lineImage, 
+<a name="l02165"></a>02165                                 <span class="keywordtype">float</span>     ** slit_pos,
+<a name="l02166"></a>02166                                 <span class="keywordtype">int</span>          box_length,
+<a name="l02167"></a>02167                                 <span class="keywordtype">float</span>        y_box,
+<a name="l02168"></a>02168                                 <span class="keywordtype">float</span>        diff_tol,
+<a name="l02169"></a>02169                     <span class="keywordtype">int</span>          low_pos,
+<a name="l02170"></a>02170                     <span class="keywordtype">int</span>          high_pos )
+<a name="l02171"></a>02171 {
+<a name="l02172"></a>02172     <span class="keywordtype">int</span>*     position=NULL ;
+<a name="l02173"></a>02173     Vector * box_buffer ;
+<a name="l02174"></a>02174     Vector * in_buffer ;
+<a name="l02175"></a>02175     <span class="keywordtype">int</span>   found_row ;
+<a name="l02176"></a>02176     <span class="keywordtype">int</span>   row, col ;
+<a name="l02177"></a>02177     <span class="keywordtype">int</span>   col_first, col_last ;
+<a name="l02178"></a>02178     <span class="keywordtype">int</span>   row_first, row_last ;
+<a name="l02179"></a>02179     <span class="keywordtype">int</span>   i, j, m, n ;
+<a name="l02180"></a>02180     <span class="keywordtype">int</span>   init1 ;
+<a name="l02181"></a>02181     <span class="keywordtype">int</span>   left_right ;
+<a name="l02182"></a>02182     <span class="keywordtype">int</span>   n_buf, shift ;
+<a name="l02183"></a>02183     <span class="keywordtype">int</span>   slit_length ;
+<a name="l02184"></a>02184     <span class="keywordtype">int</span>   iters, xdim, ndat ;
+<a name="l02185"></a>02185     <span class="keywordtype">int</span>   numpar, its ;
+<a name="l02186"></a>02186     <span class="keywordtype">int</span>   * mpar ;
+<a name="l02187"></a>02187     <span class="keywordtype">float</span> * xdat, * wdat ;
+<a name="l02188"></a>02188     <span class="keywordtype">float</span> tol, lab ;
+<a name="l02189"></a>02189     <span class="keywordtype">float</span> fitpar[NPAR] ;
+<a name="l02190"></a>02190     <span class="keywordtype">float</span> dervpar[NPAR] ;
+<a name="l02191"></a>02191     <span class="keywordtype">float</span> minval, maxval ;
+<a name="l02192"></a>02192     <span class="keywordtype">float</span> pos ;
+<a name="l02193"></a>02193     <span class="keywordtype">float</span> new_pos ;
+<a name="l02194"></a>02194     <span class="keywordtype">int</span>   slitposition[SLITLENGTH] ;
+<a name="l02195"></a>02195     pixelvalue rowpos[SLITLENGTH] ;
+<a name="l02196"></a>02196 
+<a name="l02197"></a>02197     <span class="keywordtype">int</span> ilx=0;
+<a name="l02198"></a>02198     <span class="keywordtype">int</span> ily=0;
+<a name="l02199"></a>02199     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l02200"></a>02200 
+<a name="l02201"></a>02201     slit_length = SLITLENGTH ; <span class="comment">/* this setting is too much 64 */</span>
+<a name="l02202"></a>02202     slit_length = N_SLITLETS ; <span class="comment">/* this setting is better: 32 */</span>
+<a name="l02203"></a>02203 
+<a name="l02204"></a>02204     <span class="keywordflow">if</span> ( NULL == lineImage )
+<a name="l02205"></a>02205     {
+<a name="l02206"></a>02206         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" no line image given!"</span> ) ;
+<a name="l02207"></a>02207         <span class="keywordflow">return</span> -1 ;
+<a name="l02208"></a>02208     }
+<a name="l02209"></a>02209 
+<a name="l02210"></a>02210     <span class="keywordflow">if</span> ( NULL == slit_pos )
+<a name="l02211"></a>02211     {
+<a name="l02212"></a>02212         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" no position array allocated!"</span> ) ;
+<a name="l02213"></a>02213         <span class="keywordflow">return</span> -1 ;
+<a name="l02214"></a>02214     }
+<a name="l02215"></a>02215 
+<a name="l02216"></a>02216     <span class="keywordflow">if</span> ( box_length < 4 ||
+<a name="l02217"></a>02217          box_length > 2*slit_length )
+<a name="l02218"></a>02218     {
+<a name="l02219"></a>02219         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" wrong fitting box length given!"</span> ) ;
+<a name="l02220"></a>02220         <span class="keywordflow">return</span> -1 ;
+<a name="l02221"></a>02221     }
+<a name="l02222"></a>02222 
+<a name="l02223"></a>02223     <span class="keywordflow">if</span> ( y_box <= 0. || y_box > 6. )
+<a name="l02224"></a>02224     {
+<a name="l02225"></a>02225         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" wrong y box length given!"</span> ) ;
+<a name="l02226"></a>02226         <span class="keywordflow">return</span> -1 ;
+<a name="l02227"></a>02227     }
+<a name="l02228"></a>02228     <span class="keywordflow">if</span> ( diff_tol <= 0. )
+<a name="l02229"></a>02229     {
+<a name="l02230"></a>02230         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" wrong diff_tol given!"</span> ) ;
+<a name="l02231"></a>02231         <span class="keywordflow">return</span> -1 ;
+<a name="l02232"></a>02232     }
+<a name="l02233"></a>02233 
+<a name="l02234"></a>02234     ilx=cpl_image_get_size_x(lineImage);
+<a name="l02235"></a>02235     ily=cpl_image_get_size_y(lineImage);
+<a name="l02236"></a>02236     pidata=cpl_image_get_data_float(lineImage);
+<a name="l02237"></a>02237 
+<a name="l02238"></a>02238     <span class="keywordflow">if</span> ( low_pos >= high_pos || low_pos < 0 || 
+<a name="l02239"></a>02239          high_pos <= 0 || high_pos > ily )
+<a name="l02240"></a>02240     {
+<a name="l02241"></a>02241         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" wrong user given search positions!"</span> ) ;
+<a name="l02242"></a>02242         <span class="keywordflow">return</span> -1 ;
+<a name="l02243"></a>02243     }
+<a name="l02244"></a>02244 
+<a name="l02245"></a>02245     <span class="comment">/* now search for the maximum between the given positions for each col */</span>
+<a name="l02246"></a>02246     position=cpl_calloc(ilx,<span class="keyword">sizeof</span>(<span class="keywordtype">int</span>)) ;
+<a name="l02247"></a>02247     <span class="keywordflow">for</span> ( col = 0 ; col < ilx ; col++ )
+<a name="l02248"></a>02248     {
+<a name="l02249"></a>02249         found_row = -1 ;
+<a name="l02250"></a>02250         maxval = -FLT_MAX ;
+<a name="l02251"></a>02251     <span class="keywordflow">for</span> ( row = low_pos ; row <= high_pos ; row++ )
+<a name="l02252"></a>02252     {
+<a name="l02253"></a>02253         <span class="keywordflow">if</span> ( maxval < pidata[col+row*ilx] )
+<a name="l02254"></a>02254             {
+<a name="l02255"></a>02255         maxval = pidata[col+row*ilx] ;
+<a name="l02256"></a>02256                 found_row = row ;
+<a name="l02257"></a>02257         }
+<a name="l02258"></a>02258     }
+<a name="l02259"></a>02259     <span class="keywordflow">if</span> ( maxval > -FLT_MAX && found_row > low_pos )
+<a name="l02260"></a>02260     {
+<a name="l02261"></a>02261             position[col] = found_row ;
+<a name="l02262"></a>02262         }
+<a name="l02263"></a>02263     <span class="keywordflow">else</span>
+<a name="l02264"></a>02264     {
+<a name="l02265"></a>02265         position[col] = 0 ;
+<a name="l02266"></a>02266         }
+<a name="l02267"></a>02267     }
+<a name="l02268"></a>02268     
+<a name="l02269"></a>02269     <span class="comment">/* ------------------------------------------------------------------------</span>
+<a name="l02270"></a>02270 <span class="comment">     * now go through the slitlets, search along each column within a box with </span>
+<a name="l02271"></a>02271 <span class="comment">     * half width y_box the maximum value and store these found values in a </span>
+<a name="l02272"></a>02272 <span class="comment">     * buffer</span>
+<a name="l02273"></a>02273 <span class="comment">     */</span>
+<a name="l02274"></a>02274     <span class="keywordflow">for</span> ( j = 0 ; j < slit_length ; j++ )
+<a name="l02275"></a>02275     {
+<a name="l02276"></a>02276         <span class="comment">/* now go through the columns and determine the slitlet positions by</span>
+<a name="l02277"></a>02277 <span class="comment">         * calculating the median of the found positions </span>
+<a name="l02278"></a>02278 <span class="comment">         */</span>
+<a name="l02279"></a>02279         n = 0 ;
+<a name="l02280"></a>02280         
+<a name="l02281"></a>02281         <span class="keywordflow">for</span> ( col = sinfo_new_nint(slit_pos[j][0])+ 1 ; 
+<a name="l02282"></a>02282               col < sinfo_new_nint(slit_pos[j][1]) -1 ; col++ )
+<a name="l02283"></a>02283         {
+<a name="l02284"></a>02284             rowpos[n] = (pixelvalue)position[col] ;
+<a name="l02285"></a>02285             n++ ;
+<a name="l02286"></a>02286         }
+<a name="l02287"></a>02287 
+<a name="l02288"></a>02288         slitposition[j] = (int)sinfo_new_median(rowpos, n) ;
+<a name="l02289"></a>02289         <span class="keywordflow">for</span> ( left_right = 0 ; left_right <= 1 ; left_right++ )
+<a name="l02290"></a>02290         {
+<a name="l02291"></a>02291             init1 = 0 ;
+<a name="l02292"></a>02292             col_first = sinfo_new_nint( slit_pos[j][left_right] ) - 
+<a name="l02293"></a>02293                                         box_length/2 ;
+<a name="l02294"></a>02294             col_last  = sinfo_new_nint( slit_pos[j][left_right] ) + 
+<a name="l02295"></a>02295                                         box_length/2 ;
+<a name="l02296"></a>02296             <span class="keywordflow">if</span> ( col_first < 0 )
+<a name="l02297"></a>02297             {
+<a name="l02298"></a>02298                 col_first = 0 ;
+<a name="l02299"></a>02299                 init1 = 1 ;
+<a name="l02300"></a>02300             }
+<a name="l02301"></a>02301             <span class="keywordflow">if</span> ( col_last > ilx )
+<a name="l02302"></a>02302             {
+<a name="l02303"></a>02303                 col_last = ilx ;
+<a name="l02304"></a>02304                 init1 = 1 ;
+<a name="l02305"></a>02305             }
+<a name="l02306"></a>02306             <span class="keywordflow">if</span> ( col_last - col_first <= 0 )
+<a name="l02307"></a>02307             {
+<a name="l02308"></a>02308                 <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" first and last column wrong!"</span> ) ;
+<a name="l02309"></a>02309                 <span class="keywordflow">return</span> -1 ;
+<a name="l02310"></a>02310             }
+<a name="l02311"></a>02311             box_buffer = sinfo_new_vector( col_last - col_first ) ;
+<a name="l02312"></a>02312             m = 0 ;
+<a name="l02313"></a>02313 
+<a name="l02314"></a>02314 
+<a name="l02315"></a>02315             <span class="keywordflow">if</span> ( left_right == 0 )
+<a name="l02316"></a>02316             {
+<a name="l02317"></a>02317                 <span class="keywordflow">for</span>( col = col_first ; col < col_last ; col++ )
+<a name="l02318"></a>02318                 {
+<a name="l02319"></a>02319                     row_first = slitposition[j] - sinfo_new_nint(y_box) ;
+<a name="l02320"></a>02320                     row_last  = slitposition[j] + sinfo_new_nint(y_box) ;
+<a name="l02321"></a>02321                     <span class="keywordflow">if</span> ( row_first < 0 )
+<a name="l02322"></a>02322                     {
+<a name="l02323"></a>02323                         row_first = 0 ;
+<a name="l02324"></a>02324                     }
+<a name="l02325"></a>02325                     <span class="keywordflow">if</span> ( row_last >= ily  )
+<a name="l02326"></a>02326                     {
+<a name="l02327"></a>02327                         row_last = ily - 1 ;
+<a name="l02328"></a>02328                     }
+<a name="l02329"></a>02329                     maxval = -FLT_MAX ;
+<a name="l02330"></a>02330                     <span class="keywordflow">for</span> ( row = row_first ; row <= row_last ; row++ )
+<a name="l02331"></a>02331                     {
+<a name="l02332"></a>02332                         <span class="keywordflow">if</span> ( maxval < pidata[col + ilx*row] )
+<a name="l02333"></a>02333                         {
+<a name="l02334"></a>02334                             maxval = pidata[col + ilx*row] ;
+<a name="l02335"></a>02335                         }
+<a name="l02336"></a>02336                     }
+<a name="l02337"></a>02337                     box_buffer->data[m] = maxval ;
+<a name="l02338"></a>02338                     m++ ;
+<a name="l02339"></a>02339                 }
+<a name="l02340"></a>02340 
+<a name="l02341"></a>02341             }
+<a name="l02342"></a>02342             <span class="keywordflow">else</span> 
+<a name="l02343"></a>02343             {
+<a name="l02344"></a>02344 
+<a name="l02345"></a>02345                 <span class="keywordflow">for</span>( col = col_last-1 ; col >= col_first ; col-- )
+<a name="l02346"></a>02346                 {
+<a name="l02347"></a>02347                     row_first = slitposition[j] - sinfo_new_nint(y_box) ;
+<a name="l02348"></a>02348                     row_last  = slitposition[j] + sinfo_new_nint(y_box) ;
+<a name="l02349"></a>02349                     <span class="keywordflow">if</span> ( row_first < 0 )
+<a name="l02350"></a>02350                     {
+<a name="l02351"></a>02351                         row_first = 0 ;
+<a name="l02352"></a>02352                     }
+<a name="l02353"></a>02353                     <span class="keywordflow">if</span> ( row_last >= ily  )
+<a name="l02354"></a>02354                     {
+<a name="l02355"></a>02355                         row_last = ily - 1 ;
+<a name="l02356"></a>02356                     }
+<a name="l02357"></a>02357                     maxval = -FLT_MAX ;
+<a name="l02358"></a>02358                     <span class="keywordflow">for</span> ( row = row_first ; row <= row_last ; row++ )
+<a name="l02359"></a>02359                     {
+<a name="l02360"></a>02360                         <span class="keywordflow">if</span> ( maxval < pidata[col + ilx*row] )
+<a name="l02361"></a>02361                         {
+<a name="l02362"></a>02362                             maxval = pidata[col + ilx*row] ;
+<a name="l02363"></a>02363                         }
+<a name="l02364"></a>02364                     }
+<a name="l02365"></a>02365                     box_buffer->data[m] = maxval ;
+<a name="l02366"></a>02366                     m++ ;
+<a name="l02367"></a>02367                 }
+<a name="l02368"></a>02368 
+<a name="l02369"></a>02369             }
+<a name="l02370"></a>02370 
+<a name="l02371"></a>02371             xdat=(<span class="keywordtype">float</span> *) cpl_calloc(box_buffer->n_elements, sizeof (<span class="keywordtype">float</span>) );
+<a name="l02372"></a>02372             wdat=(<span class="keywordtype">float</span> *) cpl_calloc(box_buffer->n_elements, sizeof (<span class="keywordtype">float</span>) );
+<a name="l02373"></a>02373             mpar=(<span class="keywordtype">int</span> *)   cpl_calloc(NPAR, <span class="keyword">sizeof</span> (<span class="keywordtype">int</span>) ) ;
+<a name="l02374"></a>02374 
+<a name="l02375"></a>02375             <span class="comment">/* set initial values for the fitting routine */</span>
+<a name="l02376"></a>02376             minval =  FLT_MAX ;
+<a name="l02377"></a>02377             maxval = -FLT_MAX ;
+<a name="l02378"></a>02378 
+<a name="l02379"></a>02379             <span class="keywordflow">for</span> ( i = 0 ; i < box_buffer->n_elements ; i++ )
+<a name="l02380"></a>02380             {
+<a name="l02381"></a>02381                 xdat[i] = i ;
+<a name="l02382"></a>02382                 wdat[i] = 1.0 ;
+<a name="l02383"></a>02383                 <span class="keywordflow">if</span> ( box_buffer -> data[i] < minval )
+<a name="l02384"></a>02384                 {
+<a name="l02385"></a>02385                     minval = box_buffer -> data[i] ;
+<a name="l02386"></a>02386                 }
+<a name="l02387"></a>02387                 <span class="keywordflow">if</span> ( box_buffer -> data[i] > maxval )
+<a name="l02388"></a>02388                 {
+<a name="l02389"></a>02389                     maxval = box_buffer -> data[i] ;
+<a name="l02390"></a>02390                 }
+<a name="l02391"></a>02391             }
+<a name="l02392"></a>02392             fitpar[0] = minval ;
+<a name="l02393"></a>02393             fitpar[1] = maxval ; 
+<a name="l02394"></a>02394 
+<a name="l02395"></a>02395             <span class="comment">/*-----------------------------------------------------------------</span>
+<a name="l02396"></a>02396 <span class="comment">             * if we have too few left background values (at the image edges)</span>
+<a name="l02397"></a>02397 <span class="comment">             * the left margin of the buffer to fit is filled with the minimal</span>
+<a name="l02398"></a>02398 <span class="comment">             * values in order to get a good fit</span>
+<a name="l02399"></a>02399 <span class="comment">             */</span>
+<a name="l02400"></a>02400             
+<a name="l02401"></a>02401   
+<a name="l02402"></a>02402             <span class="keywordflow">if</span> ( init1 == 1 )
+<a name="l02403"></a>02403             {
+<a name="l02404"></a>02404                 n_buf = box_buffer->n_elements + box_length/2 ;
+<a name="l02405"></a>02405                 in_buffer = sinfo_new_vector( n_buf ) ;     
+<a name="l02406"></a>02406                 <span class="keywordflow">for</span> ( i = 0 ; i < box_length/2 ; i++ )
+<a name="l02407"></a>02407                 {
+<a name="l02408"></a>02408                     in_buffer -> data[i] = minval ;
+<a name="l02409"></a>02409                 }
+<a name="l02410"></a>02410                 shift = 0 ;
+<a name="l02411"></a>02411                 <span class="keywordflow">for</span> ( i = box_length/2 ; i < n_buf ; i++ )
+<a name="l02412"></a>02412                 {
+<a name="l02413"></a>02413                     in_buffer -> data[i] = box_buffer -> data[shift] ;
+<a name="l02414"></a>02414                     shift++ ;
+<a name="l02415"></a>02415                 }
+<a name="l02416"></a>02416                 sinfo_new_destroy_vector ( box_buffer ) ;
+<a name="l02417"></a>02417                 box_buffer = sinfo_new_vector ( n_buf ) ;
+<a name="l02418"></a>02418                 <span class="keywordflow">for</span> ( i = 0 ; i < n_buf ; i++ )
+<a name="l02419"></a>02419                 {
+<a name="l02420"></a>02420                     box_buffer -> data[i] = in_buffer -> data[i] ;
+<a name="l02421"></a>02421                 }
+<a name="l02422"></a>02422                 sinfo_new_destroy_vector ( in_buffer ) ;
+<a name="l02423"></a>02423             }
+<a name="l02424"></a>02424 
+<a name="l02425"></a>02425             <span class="comment">/* determine the initial positions from the found values */</span>
+<a name="l02426"></a>02426             fitpar[2] = (float)box_buffer->n_elements/2.  ;
+<a name="l02427"></a>02427             fitpar[3] = 1. ;
+<a name="l02428"></a>02428 
+<a name="l02429"></a>02429             for ( i = 0 ; i < NPAR ; i++ )
+<a name="l02430"></a>02430             {
+<a name="l02431"></a>02431                 mpar[i] = 1 ;
+<a name="l02432"></a>02432                 dervpar[i] = 0. ;
+<a name="l02433"></a>02433             }
+<a name="l02434"></a>02434       
+<a name="l02435"></a>02435             xdim     = XDIMA ;
+<a name="l02436"></a>02436             ndat     = box_buffer->n_elements ;
+<a name="l02437"></a>02437             numpar   = NPAR ;
+<a name="l02438"></a>02438             tol      = TOLA ;
+<a name="l02439"></a>02439             lab      = LABA ;
+<a name="l02440"></a>02440             its      = ITSA ;
+<a name="l02441"></a>02441          
+<a name="l02442"></a>02442             <span class="comment">/* finally, do the least squares fit over the buffer data */</span>
+<a name="l02443"></a>02443             <span class="keywordflow">if</span> ( 0 > ( iters = <a class="code" href="group__sinfo__boltzmann.html#ga7e03e34851f7c367ab3827c58e8c81c5" title="makes a least-squares fit of a function to a set of data points.">sinfo_new_lsqfit</a>( xdat, &xdim, 
+<a name="l02444"></a>02444                                                  box_buffer -> data, 
+<a name="l02445"></a>02445                                                  wdat, &ndat, fitpar,
+<a name="l02446"></a>02446                                                  dervpar, mpar, &numpar, 
+<a name="l02447"></a>02447                                                  &tol, &its, &lab )) )
+<a name="l02448"></a>02448             { 
+<a name="l02449"></a>02449                 <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a> (<span class="stringliteral">"least squares fit failed, error "</span>
+<a name="l02450"></a>02450                                    <span class="stringliteral">"no.: %d in slitlet: %d\n"</span>, iters, j) ;
+<a name="l02451"></a>02451                 sinfo_new_destroy_vector(box_buffer) ;
+<a name="l02452"></a>02452                 cpl_free( xdat ) ;
+<a name="l02453"></a>02453                 cpl_free( wdat ) ;
+<a name="l02454"></a>02454                 cpl_free( mpar ) ;
+<a name="l02455"></a>02455                 continue ;
+<a name="l02456"></a>02456             }
+<a name="l02457"></a>02457 
+<a name="l02458"></a>02458         <span class="keywordflow">if</span> ( fitpar[3] <=0. )
+<a name="l02459"></a>02459             { 
+<a name="l02460"></a>02460                 <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a> (<span class="stringliteral">"fit failed due to negative width of "</span>
+<a name="l02461"></a>02461                                    <span class="stringliteral">"boltzmann function in slitlet: %d\n"</span>, j) ;
+<a name="l02462"></a>02462                 sinfo_new_destroy_vector(box_buffer) ;
+<a name="l02463"></a>02463                 cpl_free( xdat ) ;
+<a name="l02464"></a>02464                 cpl_free( wdat ) ;
+<a name="l02465"></a>02465                 cpl_free( mpar ) ;
+<a name="l02466"></a>02466                 continue ;
+<a name="l02467"></a>02467             }
+<a name="l02468"></a>02468             pos = fitpar[2] ;
+<a name="l02469"></a>02469             <span class="keywordflow">if</span> ( init1 == 1 )
+<a name="l02470"></a>02470             {
+<a name="l02471"></a>02471                 pos -= (float)box_length/2. ;
+<a name="l02472"></a>02472             }
+<a name="l02473"></a>02473 
+<a name="l02474"></a>02474             <span class="comment">/*-------------------------------------------------------------</span>
+<a name="l02475"></a>02475 <span class="comment">             * now compute the real slit positions using the guess positions</span>
+<a name="l02476"></a>02476 <span class="comment">             * if the fit did not work the guess positions are taken</span>
+<a name="l02477"></a>02477 <span class="comment">             * the same is done if the deviations are too big.</span>
+<a name="l02478"></a>02478 <span class="comment">             */</span>
+<a name="l02479"></a>02479             <span class="keywordflow">if</span> ( pos != 0. )  
+<a name="l02480"></a>02480             {
+<a name="l02481"></a>02481                 <span class="keywordflow">if</span> ( left_right == 0 )
+<a name="l02482"></a>02482                 {
+<a name="l02483"></a>02483                     new_pos = (float)col_first + pos ;
+<a name="l02484"></a>02484                 }
+<a name="l02485"></a>02485                 <span class="keywordflow">else</span>
+<a name="l02486"></a>02486                 {
+<a name="l02487"></a>02487                     new_pos = (float)col_last-1 - pos ;
+<a name="l02488"></a>02488                 }
+<a name="l02489"></a>02489                 <span class="keywordflow">if</span> ( fabs(new_pos - slit_pos[j][left_right]) < diff_tol )
+<a name="l02490"></a>02490                 {
+<a name="l02491"></a>02491                     slit_pos[j][left_right] = new_pos ;
+<a name="l02492"></a>02492                 }
+<a name="l02493"></a>02493                 <span class="keywordflow">else</span>
+<a name="l02494"></a>02494                 {
+<a name="l02495"></a>02495                     <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a> (<span class="stringliteral">" deviation bigger than tolerance,"</span>
+<a name="l02496"></a>02496                                        <span class="stringliteral">" take the estimated slitlet position "</span>
+<a name="l02497"></a>02497                                        <span class="stringliteral">" in slitlet: %d\n"</span>, j) ;
+<a name="l02498"></a>02498                 }
+<a name="l02499"></a>02499             }
+<a name="l02500"></a>02500 
+<a name="l02501"></a>02501             cpl_free( xdat ) ;
+<a name="l02502"></a>02502             cpl_free( wdat ) ;
+<a name="l02503"></a>02503             cpl_free( mpar ) ;
+<a name="l02504"></a>02504             sinfo_new_destroy_vector ( box_buffer ) ;
+<a name="l02505"></a>02505 
+<a name="l02506"></a>02506         }
+<a name="l02507"></a>02507     }
+<a name="l02508"></a>02508     cpl_free(position);
+<a name="l02509"></a>02509     <span class="keywordflow">return</span> 0 ;
+<a name="l02510"></a>02510 }
+<a name="l02511"></a>02511                               
+<a name="l02512"></a>02512 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__bp__config_8c_source.html b/html/sinfo__bp__config_8c_source.html
new file mode 100644
index 0000000..8900531
--- /dev/null
+++ b/html/sinfo__bp__config_8c_source.html
@@ -0,0 +1,78 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_bp_config.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_bp_config.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_bp_config.c,v 1.5 2012/03/02 08:42:20 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the CPL (Common Pipeline Library)</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
+<a name="l00007"></a>00007 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span>
+<a name="l00008"></a>00008 <span class="comment"> * License as published by the Free Software Foundation; either</span>
+<a name="l00009"></a>00009 <span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
+<a name="l00014"></a>00014 <span class="comment"> * Lesser General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
+<a name="l00017"></a>00017 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2012/03/02 08:42:20 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.5 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> */</span>
+<a name="l00026"></a>00026 
+<a name="l00027"></a>00027 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00029"></a>00029 <span class="preprocessor">#endif</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span> <span class="comment">/****************************************************************</span>
+<a name="l00031"></a>00031 <span class="comment">  *           Bad pixel search                                   *</span>
+<a name="l00032"></a>00032 <span class="comment">  ****************************************************************/</span>
+<a name="l00033"></a>00033 
+<a name="l00034"></a>00034 <span class="preprocessor">#include "sinfo_bp_config.h"</span>
+<a name="l00053"></a>00053   <span class="comment">/* Bad pixel parameters */</span>
+<a name="l00054"></a>00054 
+<a name="l00055"></a>00055 <span class="keywordtype">void</span>
+<a name="l00056"></a>00056  sinfo_bp_config_add(cpl_parameterlist *list)
+<a name="l00057"></a>00057 {
+<a name="l00058"></a>00058 
+<a name="l00059"></a>00059   cpl_parameter *p;
+<a name="l00060"></a>00060 
+<a name="l00061"></a>00061   <span class="keywordflow">if</span> (!list) {
+<a name="l00062"></a>00062     <span class="keywordflow">return</span>;
+<a name="l00063"></a>00063   }
+<a name="l00064"></a>00064 
+<a name="l00065"></a>00065   <span class="comment">/* indicates which method will be used */</span>
+<a name="l00066"></a>00066   p = cpl_parameter_new_enum(<span class="stringliteral">"sinfoni.bp.method"</span>,
+<a name="l00067"></a>00067                   CPL_TYPE_STRING,
+<a name="l00068"></a>00068                               <span class="stringliteral">"Data reduction method: "</span>,
+<a name="l00069"></a>00069                               <span class="stringliteral">"sinfoni.general_noise"</span>,
+<a name="l00070"></a>00070                               <span class="stringliteral">"Normal"</span>,
+<a name="l00071"></a>00071                               3,
+<a name="l00072"></a>00072                               <span class="stringliteral">"Normal"</span>,<span class="stringliteral">"Linear"</span>,<span class="stringliteral">"Noise"</span>);
+<a name="l00073"></a>00073 
+<a name="l00074"></a>00074 
+<a name="l00075"></a>00075   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"bp-method"</span>);
+<a name="l00076"></a>00076   cpl_parameterlist_append(list, p);
+<a name="l00077"></a>00077 
+<a name="l00078"></a>00078   <span class="keywordflow">return</span>;
+<a name="l00079"></a>00079 
+<a name="l00080"></a>00080 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__bp__config_8h_source.html b/html/sinfo__bp__config_8h_source.html
new file mode 100644
index 0000000..e3778b5
--- /dev/null
+++ b/html/sinfo__bp__config_8h_source.html
@@ -0,0 +1,53 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_bp_config.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_bp_config.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_bp_config.h,v 1.1 2006/10/20 08:06:32 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the CPL (Common Pipeline Library)</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
+<a name="l00007"></a>00007 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span>
+<a name="l00008"></a>00008 <span class="comment"> * License as published by the Free Software Foundation; either</span>
+<a name="l00009"></a>00009 <span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
+<a name="l00014"></a>00014 <span class="comment"> * Lesser General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
+<a name="l00017"></a>00017 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2006/10/20 08:06:32 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.1 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> */</span>
+<a name="l00026"></a>00026 
+<a name="l00027"></a>00027  <span class="comment">/****************************************************************</span>
+<a name="l00028"></a>00028 <span class="comment">  *           Bad pixel search  (normal method)                  *</span>
+<a name="l00029"></a>00029 <span class="comment">  ****************************************************************/</span>
+<a name="l00030"></a>00030 <span class="preprocessor">#ifndef SINFO_BP_CONFIG_H</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_BP_CONFIG_H</span>
+<a name="l00032"></a>00032 <span class="preprocessor"></span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include "cpl.h"</span>  
+<a name="l00034"></a>00034 
+<a name="l00035"></a>00035 <span class="keywordtype">void</span> sinfo_bp_config_add(cpl_parameterlist *list);
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__bp__dist__config_8c_source.html b/html/sinfo__bp__dist__config_8c_source.html
new file mode 100644
index 0000000..e80c5e9
--- /dev/null
+++ b/html/sinfo__bp__dist__config_8c_source.html
@@ -0,0 +1,270 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_bp_dist_config.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_bp_dist_config.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_bp_dist_config.c,v 1.4 2007/06/06 07:10:45 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the CPL (Common Pipeline Library)</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
+<a name="l00007"></a>00007 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span>
+<a name="l00008"></a>00008 <span class="comment"> * License as published by the Free Software Foundation; either</span>
+<a name="l00009"></a>00009 <span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
+<a name="l00014"></a>00014 <span class="comment"> * Lesser General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
+<a name="l00017"></a>00017 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2007/06/06 07:10:45 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.4 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> */</span>
+<a name="l00026"></a>00026 
+<a name="l00027"></a>00027 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00029"></a>00029 <span class="preprocessor">#endif</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span> <span class="comment">/****************************************************************</span>
+<a name="l00031"></a>00031 <span class="comment">  *           Bad pixel search  (normal method)                  *</span>
+<a name="l00032"></a>00032 <span class="comment">  ****************************************************************/</span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include "sinfo_bp_dist_config.h"</span>
+<a name="l00052"></a>00052   <span class="comment">/* Bad pixel parameters */</span>
+<a name="l00053"></a>00053 
+<a name="l00054"></a>00054 <span class="keywordtype">void</span>
+<a name="l00055"></a><a class="code" href="group__sinfo__bad__pix__search.html#ga4f320ea65a00f127ece79fd2c6416a15">00055</a>  <a class="code" href="group__sinfo__bad__pix__search.html#ga4f320ea65a00f127ece79fd2c6416a15" title="Adds parameters for the spectrum extraction.">sinfo_bp_dist_config_add</a>(cpl_parameterlist *list)
+<a name="l00056"></a>00056 {
+<a name="l00057"></a>00057   cpl_parameter *p;
+<a name="l00058"></a>00058 
+<a name="l00059"></a>00059   <span class="keywordflow">if</span> (!list) {
+<a name="l00060"></a>00060     <span class="keywordflow">return</span>;
+<a name="l00061"></a>00061   }
+<a name="l00062"></a>00062 
+<a name="l00063"></a>00063 
+<a name="l00064"></a>00064 
+<a name="l00065"></a>00065 <span class="comment">/* factor of noise within which the pixels are used to fit a straight line </span>
+<a name="l00066"></a>00066 <span class="comment">   to the column intensity */</span>
+<a name="l00067"></a>00067   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.bp_dist.sigma_factor"</span>,
+<a name="l00068"></a>00068                   CPL_TYPE_DOUBLE,
+<a name="l00069"></a>00069                               <span class="stringliteral">"Threshold Sigma Factor: "</span>
+<a name="l00070"></a>00070                               <span class="stringliteral">"to remove the column intensity tilt only "</span>
+<a name="l00071"></a>00071                               <span class="stringliteral">"pixels which lie within a defined noise"</span>
+<a name="l00072"></a>00072                               <span class="stringliteral">"limit are used to fit a straight line"</span>,
+<a name="l00073"></a>00073                               <span class="stringliteral">"sinfoni.bp_dist"</span>,
+<a name="l00074"></a>00074                               2.0);
+<a name="l00075"></a>00075 
+<a name="l00076"></a>00076   cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"bp_dist-s_factor"</span>);
+<a name="l00077"></a>00077   cpl_parameterlist_append(list, p);
+<a name="l00078"></a>00078 
+<a name="l00079"></a>00079   <span class="comment">/* bad pixel search determination method */</span>
+<a name="l00080"></a>00080  p = cpl_parameter_new_enum(<span class="stringliteral">"sinfoni.bp_dist.method_index"</span>,
+<a name="l00081"></a>00081                   CPL_TYPE_INT,
+<a name="l00082"></a>00082                               <span class="stringliteral">"Bad pixel Method Index"</span>
+<a name="l00083"></a>00083                               <span class="stringliteral">"1: median of nearest neighbors,"</span>
+<a name="l00084"></a>00084                               <span class="stringliteral">"2: absolute distances check, "</span>
+<a name="l00085"></a>00085                               <span class="stringliteral">"3: mean of nearest spectral neighbors"</span>,
+<a name="l00086"></a>00086                               <span class="stringliteral">"sinfoni.bp_dist"</span>,
+<a name="l00087"></a>00087                               1,
+<a name="l00088"></a>00088                               3,1,2,3);
+<a name="l00089"></a>00089 
+<a name="l00090"></a>00090   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"bp_dist-method_ind"</span>);
+<a name="l00091"></a>00091   cpl_parameterlist_append(list, p);
+<a name="l00092"></a>00092 
+<a name="l00093"></a>00093   <span class="comment">/* factor of calculated standard deviation beyond which the deviation </span>
+<a name="l00094"></a>00094 <span class="comment">     of a pixel value from the median of the 8 nearest neighbors declares </span>
+<a name="l00095"></a>00095 <span class="comment">     a pixel as bad */</span>
+<a name="l00096"></a>00096   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.bp_dist.factor"</span>,
+<a name="l00097"></a>00097                   CPL_TYPE_DOUBLE,
+<a name="l00098"></a>00098                               <span class="stringliteral">"Factor: "</span>
+<a name="l00099"></a>00099            <span class="stringliteral">"if |pixel - sinfo_median| > factor * standard deviation -> "</span>
+<a name="l00100"></a>00100                               <span class="stringliteral">"then the pixel value is replaced by "</span>
+<a name="l00101"></a>00101                               <span class="stringliteral">"the median of the 8 nearest neighbors"</span>,
+<a name="l00102"></a>00102                               <span class="stringliteral">"sinfoni.bp_dist"</span>,
+<a name="l00103"></a>00103                               999.0);
+<a name="l00104"></a>00104 
+<a name="l00105"></a>00105   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"bp_dist-fct"</span>);
+<a name="l00106"></a>00106   cpl_parameterlist_append(list, p);
+<a name="l00107"></a>00107 
+<a name="l00108"></a>00108  <span class="comment">/* no of iterations to find bad pix clusters */</span>
+<a name="l00109"></a>00109   <span class="comment">/* number of iterations of sinfo_median filter */</span>
+<a name="l00110"></a>00110   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.bp_dist.iterations"</span>,
+<a name="l00111"></a>00111                   CPL_TYPE_INT,
+<a name="l00112"></a>00112                               <span class="stringliteral">"Iterations: number of iterations to of median"</span>
+<a name="l00113"></a>00113                               <span class="stringliteral">" filtering to find bad pixel clusters"</span>,
+<a name="l00114"></a>00114                               <span class="stringliteral">"sinfoni.bp_dist"</span>,
+<a name="l00115"></a>00115                               8);
+<a name="l00116"></a>00116 
+<a name="l00117"></a>00117   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"bp_dist-it"</span>);
+<a name="l00118"></a>00118   cpl_parameterlist_append(list, p);
+<a name="l00119"></a>00119 
+<a name="l00120"></a>00120   <span class="comment">/* float </span>
+<a name="l00121"></a>00121 <span class="comment">     threshold used in the clean mean percentage of rejection used to reject </span>
+<a name="l00122"></a>00122 <span class="comment">     low and high frame */</span>
+<a name="l00123"></a>00123  <span class="comment">/* percentage of extreme pixel value to reject when calculating the mean </span>
+<a name="l00124"></a>00124 <span class="comment">    and stdev */</span>
+<a name="l00125"></a>00125   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.bp_dist.low_rejection"</span>,
+<a name="l00126"></a>00126                   CPL_TYPE_DOUBLE,
+<a name="l00127"></a>00127                               <span class="stringliteral">"low_rejection: "</span>
+<a name="l00128"></a>00128                               <span class="stringliteral">"percentage of rejected low intensity "</span>
+<a name="l00129"></a>00129                               <span class="stringliteral">"pixels before averaging"</span>,
+<a name="l00130"></a>00130                               <span class="stringliteral">"sinfoni.bp_dist"</span>,
+<a name="l00131"></a>00131                               0.1,0.0,1.0);
+<a name="l00132"></a>00132 
+<a name="l00133"></a>00133   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"bp_dist-lo_rej"</span>);
+<a name="l00134"></a>00134   cpl_parameterlist_append(list, p);
+<a name="l00135"></a>00135 
+<a name="l00136"></a>00136   <span class="comment">/* float </span>
+<a name="l00137"></a>00137 <span class="comment">     threshold used in the clean mean percentage of rejection used to reject </span>
+<a name="l00138"></a>00138 <span class="comment">     low and high frame */</span>
+<a name="l00139"></a>00139  <span class="comment">/* percentage of extreme pixel value to reject when calculating the mean </span>
+<a name="l00140"></a>00140 <span class="comment">    and stdev */</span>
+<a name="l00141"></a>00141   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.bp_dist.high_rejection"</span>,
+<a name="l00142"></a>00142                   CPL_TYPE_DOUBLE,
+<a name="l00143"></a>00143                               <span class="stringliteral">"high_rejection: "</span>
+<a name="l00144"></a>00144                               <span class="stringliteral">"percentage of rejected high intensity "</span>
+<a name="l00145"></a>00145                               <span class="stringliteral">"pixels before averaging"</span>,
+<a name="l00146"></a>00146                               <span class="stringliteral">"sinfoni.bp_dist"</span>,
+<a name="l00147"></a>00147                               0.1,0.0,1.0);
+<a name="l00148"></a>00148 
+<a name="l00149"></a>00149   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"bp_dist-hi_rej"</span>);
+<a name="l00150"></a>00150   cpl_parameterlist_append(list, p);
+<a name="l00151"></a>00151 
+<a name="l00152"></a>00152 
+<a name="l00153"></a>00153   <span class="comment">/* position in the frame lower left in X */</span>
+<a name="l00154"></a>00154   <span class="comment">/* pixel coordinate of lower left sinfo_edge of a rectangle zone from which </span>
+<a name="l00155"></a>00155 <span class="comment">     image statistics are computed */</span>
+<a name="l00156"></a>00156   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.bp_dist.llx"</span>,
+<a name="l00157"></a>00157                   CPL_TYPE_INT,
+<a name="l00158"></a>00158                               <span class="stringliteral">"llx: "</span>
+<a name="l00159"></a>00159                               <span class="stringliteral">"to compute image statistics on a rectangular"</span>
+<a name="l00160"></a>00160                               <span class="stringliteral">"zone of the image the coordinates of the "</span>
+<a name="l00161"></a>00161                               <span class="stringliteral">"rectangle are needed:"</span> 
+<a name="l00162"></a>00162                               <span class="stringliteral">"lower left x coordinate"</span>,
+<a name="l00163"></a>00163                               <span class="stringliteral">"sinfoni.bp_dist"</span>,
+<a name="l00164"></a>00164                               1350,DET_PIX_MIN,DET_PIX_MAX);
+<a name="l00165"></a>00165   <span class="comment">/* 1000 */</span>
+<a name="l00166"></a>00166   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"bp_dist-llx"</span>);
+<a name="l00167"></a>00167   cpl_parameterlist_append(list, p);
+<a name="l00168"></a>00168 
+<a name="l00169"></a>00169 
+<a name="l00170"></a>00170 
+<a name="l00171"></a>00171   <span class="comment">/* position in the frame lower left in Y */</span>
+<a name="l00172"></a>00172   <span class="comment">/* pixel coordinate of lower left sinfo_edge of a rectangle zone from which </span>
+<a name="l00173"></a>00173 <span class="comment">     image statistics are computed */</span>
+<a name="l00174"></a>00174   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.bp_dist.lly"</span>,
+<a name="l00175"></a>00175                   CPL_TYPE_INT,
+<a name="l00176"></a>00176                               <span class="stringliteral">"lly: "</span>
+<a name="l00177"></a>00177                               <span class="stringliteral">"to compute image statistics on a rectangular"</span>
+<a name="l00178"></a>00178                               <span class="stringliteral">"zone of the image the coordinates of the "</span>
+<a name="l00179"></a>00179                               <span class="stringliteral">"rectangle are needed:"</span> 
+<a name="l00180"></a>00180                               <span class="stringliteral">"lower left y coordinate"</span>,
+<a name="l00181"></a>00181                               <span class="stringliteral">"sinfoni.bp_dist"</span>,
+<a name="l00182"></a>00182                               1000,DET_PIX_MIN,DET_PIX_MAX);
+<a name="l00183"></a>00183   <span class="comment">/* 1000 */</span>
+<a name="l00184"></a>00184   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"bp_dist-lly"</span>);
+<a name="l00185"></a>00185   cpl_parameterlist_append(list, p);
+<a name="l00186"></a>00186 
+<a name="l00187"></a>00187   <span class="comment">/* Upper right position in CCD : should be urx */</span>
+<a name="l00188"></a>00188   <span class="comment">/* pixel coordinate of upper right sinfo_edge of a rectangle zone from which </span>
+<a name="l00189"></a>00189 <span class="comment">    image statistics are computed */</span>
+<a name="l00190"></a>00190   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.bp_dist.urx"</span>,
+<a name="l00191"></a>00191                   CPL_TYPE_INT,
+<a name="l00192"></a>00192                               <span class="stringliteral">"urx: "</span>
+<a name="l00193"></a>00193                               <span class="stringliteral">"to compute image statistics on a rectangular"</span>
+<a name="l00194"></a>00194                               <span class="stringliteral">"zone of the image the coordinates of the "</span>
+<a name="l00195"></a>00195                               <span class="stringliteral">"rectangle are needed:"</span> 
+<a name="l00196"></a>00196                               <span class="stringliteral">"upper right x coordinate"</span>,
+<a name="l00197"></a>00197                               <span class="stringliteral">"sinfoni.bp_dist"</span>,
+<a name="l00198"></a>00198                               1390,DET_PIX_MIN,DET_PIX_MAX);
+<a name="l00199"></a>00199   <span class="comment">/* 1350*/</span>
+<a name="l00200"></a>00200   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"bp_dist-urx"</span>);
+<a name="l00201"></a>00201   cpl_parameterlist_append(list, p);
+<a name="l00202"></a>00202 
+<a name="l00203"></a>00203   <span class="comment">/* Upper right position in CCD : should be ury */</span>
+<a name="l00204"></a>00204   <span class="comment">/* pixel coordinate of upper right sinfo_edge of a rectangle zone from which </span>
+<a name="l00205"></a>00205 <span class="comment">    image statistics are computed */</span>
+<a name="l00206"></a>00206   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.bp_dist.ury"</span>,
+<a name="l00207"></a>00207                   CPL_TYPE_INT,
+<a name="l00208"></a>00208                               <span class="stringliteral">"ury: "</span>
+<a name="l00209"></a>00209                               <span class="stringliteral">"to compute image statistics on a rectangular"</span>
+<a name="l00210"></a>00210                               <span class="stringliteral">"zone of the image the coordinates of the "</span>
+<a name="l00211"></a>00211                               <span class="stringliteral">"rectangle are needed:"</span> 
+<a name="l00212"></a>00212                               <span class="stringliteral">"upper right y coordinate"</span>,
+<a name="l00213"></a>00213                               <span class="stringliteral">"sinfoni.bp_dist"</span>,
+<a name="l00214"></a>00214                               1200,DET_PIX_MIN,DET_PIX_MAX);
+<a name="l00215"></a>00215   <span class="comment">/* 1390 */</span>
+<a name="l00216"></a>00216   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"bp_dist-ury"</span>);
+<a name="l00217"></a>00217   cpl_parameterlist_append(list, p);
+<a name="l00218"></a>00218 
+<a name="l00219"></a>00219   <span class="comment">/* boolean (implemented as integer) useda s a switch */</span>
+<a name="l00220"></a>00220   <span class="comment">/* indicates if the values beyond threshold values should be marked </span>
+<a name="l00221"></a>00221 <span class="comment">     as bad before proceeding to sinfo_median filtering */</span>
+<a name="l00222"></a>00222   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.bp_dist.threshold_index"</span>,
+<a name="l00223"></a>00223                   CPL_TYPE_BOOL,
+<a name="l00224"></a>00224                               <span class="stringliteral">"Threshold Index: "</span>
+<a name="l00225"></a>00225                               <span class="stringliteral">"indicator that indicates if the values "</span>
+<a name="l00226"></a>00226                               <span class="stringliteral">"beyond a threshold deviation from the mean "</span>
+<a name="l00227"></a>00227                               <span class="stringliteral">"are flagged as bad pixels"</span>,
+<a name="l00228"></a>00228                               <span class="stringliteral">"sinfoni.bp_dist"</span>,
+<a name="l00229"></a>00229                               TRUE);
+<a name="l00230"></a>00230 
+<a name="l00231"></a>00231   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"bp_dist-thr_ind"</span>);
+<a name="l00232"></a>00232   cpl_parameterlist_append(list, p);
+<a name="l00233"></a>00233 
+<a name="l00234"></a>00234   <span class="comment">/* threshold value. Float. Threshold used to find bad pixel */</span>
+<a name="l00235"></a>00235   <span class="comment">/* factor to the clean standard deviation to define the threshold </span>
+<a name="l00236"></a>00236 <span class="comment">     deviation from the clean mean */</span>
+<a name="l00237"></a>00237   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.bp_dist.mean_factor"</span>,
+<a name="l00238"></a>00238                   CPL_TYPE_DOUBLE,
+<a name="l00239"></a>00239                               <span class="stringliteral">"Mean Factor: "</span>
+<a name="l00240"></a>00240                               <span class="stringliteral">"factor to the clean standard deviation to "</span>
+<a name="l00241"></a>00241                               <span class="stringliteral">"define the threshold deviation from the "</span>
+<a name="l00242"></a>00242                               <span class="stringliteral">"clean mean"</span>,
+<a name="l00243"></a>00243                               <span class="stringliteral">"sinfoni.bp_dist"</span>,
+<a name="l00244"></a>00244                               999.,0.1,1.e10);
+<a name="l00245"></a>00245 
+<a name="l00246"></a>00246   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"bp_dist-mean_fct"</span>);
+<a name="l00247"></a>00247   cpl_parameterlist_append(list, p);
+<a name="l00248"></a>00248 
+<a name="l00249"></a>00249 
+<a name="l00250"></a>00250 
+<a name="l00251"></a>00251   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.bp_dist.min_cut"</span>,
+<a name="l00252"></a>00252                   CPL_TYPE_DOUBLE,
+<a name="l00253"></a>00253                               <span class="stringliteral">"the minimum value of real data"</span>,
+<a name="l00254"></a>00254                               <span class="stringliteral">"sinfoni.bp_dist"</span>,
+<a name="l00255"></a>00255                               0.1);
+<a name="l00256"></a>00256 
+<a name="l00257"></a>00257   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"bp_dist-min_cut"</span>);
+<a name="l00258"></a>00258   cpl_parameterlist_append(list, p);
+<a name="l00259"></a>00259 
+<a name="l00260"></a>00260 
+<a name="l00261"></a>00261   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.bp_dist.max_cut"</span>,
+<a name="l00262"></a>00262                   CPL_TYPE_DOUBLE,
+<a name="l00263"></a>00263                               <span class="stringliteral">"the minimum value of real data"</span>,
+<a name="l00264"></a>00264                               <span class="stringliteral">"sinfoni.bp_dist"</span>,
+<a name="l00265"></a>00265                               50000.);
+<a name="l00266"></a>00266 
+<a name="l00267"></a>00267   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"bp_dist-max_cut"</span>);
+<a name="l00268"></a>00268   cpl_parameterlist_append(list, p);
+<a name="l00269"></a>00269 
+<a name="l00270"></a>00270   <span class="keywordflow">return</span>;
+<a name="l00271"></a>00271 
+<a name="l00272"></a>00272 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__bp__dist__config_8h_source.html b/html/sinfo__bp__dist__config_8h_source.html
new file mode 100644
index 0000000..f1e38f2
--- /dev/null
+++ b/html/sinfo__bp__dist__config_8h_source.html
@@ -0,0 +1,57 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_bp_dist_config.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_bp_dist_config.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_bp_dist_config.h,v 1.1 2006/10/20 08:06:32 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the CPL (Common Pipeline Library)</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
+<a name="l00007"></a>00007 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span>
+<a name="l00008"></a>00008 <span class="comment"> * License as published by the Free Software Foundation; either</span>
+<a name="l00009"></a>00009 <span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
+<a name="l00014"></a>00014 <span class="comment"> * Lesser General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
+<a name="l00017"></a>00017 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2006/10/20 08:06:32 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.1 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> */</span>
+<a name="l00026"></a>00026 
+<a name="l00027"></a>00027  <span class="comment">/****************************************************************</span>
+<a name="l00028"></a>00028 <span class="comment">  *           Bad pixel search  (normal method)                  *</span>
+<a name="l00029"></a>00029 <span class="comment">  ****************************************************************/</span>
+<a name="l00030"></a>00030 <span class="preprocessor">#ifndef SINFO_BP_DIST_CONFIG_H</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_BP_DIST_CONFIG_H</span>
+<a name="l00032"></a>00032 <span class="preprocessor"></span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include "cpl.h"</span>  
+<a name="l00034"></a>00034 <span class="comment">/*</span>
+<a name="l00035"></a>00035 <span class="comment">#include "sinfo_dfs.h"</span>
+<a name="l00036"></a>00036 <span class="comment">*/</span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include "sinfo_globals.h"</span>
+<a name="l00038"></a>00038 
+<a name="l00039"></a>00039 <span class="keywordtype">void</span> <a class="code" href="group__sinfo__bad__pix__search.html#ga4f320ea65a00f127ece79fd2c6416a15" title="Adds parameters for the spectrum extraction.">sinfo_bp_dist_config_add</a>(cpl_parameterlist *list);
+<a name="l00040"></a>00040 
+<a name="l00041"></a>00041 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__bp__lin_8c_source.html b/html/sinfo__bp__lin_8c_source.html
new file mode 100644
index 0000000..5bb8013
--- /dev/null
+++ b/html/sinfo__bp__lin_8c_source.html
@@ -0,0 +1,369 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_bp_lin.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_bp_lin.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment"></span>
+<a name="l00021"></a>00021 <span class="comment">   File name    :       sinfo_bp_lin.c</span>
+<a name="l00022"></a>00022 <span class="comment">   Author       :    J. Schreiber</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on   :    May 5, 2003</span>
+<a name="l00024"></a>00024 <span class="comment">   Description  :    Different methods for searching for bad pixels</span>
+<a name="l00025"></a>00025 <span class="comment">                        used in the recipe spiffi_badsearch</span>
+<a name="l00026"></a>00026 <span class="comment"></span>
+<a name="l00027"></a>00027 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span>
+<a name="l00032"></a>00032 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                                Includes</span>
+<a name="l00034"></a>00034 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 <span class="comment">//#include <cpl_imagelist_basic.h></span>
+<a name="l00036"></a>00036 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include "sinfo_bp_lin.h"</span>
+<a name="l00038"></a>00038 <span class="preprocessor">#include "sinfo_detlin.h"</span>
+<a name="l00039"></a>00039 <span class="preprocessor">#include "sinfo_detlin_ini_by_cpl.h"</span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include "sinfo_pro_save.h"</span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include "sinfo_pro_types.h"</span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include "sinfo_functions.h"</span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include "sinfo_hidden.h"</span>
+<a name="l00044"></a>00044 <span class="preprocessor">#include "sinfo_error.h"</span>
+<a name="l00045"></a>00045 <span class="preprocessor">#include "sinfo_utils_wrappers.h"</span>
+<a name="l00046"></a>00046 
+<a name="l00047"></a>00047 
+<a name="l00054"></a>00054 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00055"></a>00055 <span class="comment">                                Defines</span>
+<a name="l00056"></a>00056 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00057"></a>00057 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00058"></a>00058 <span class="comment">                             Function Definitions</span>
+<a name="l00059"></a>00059 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00086"></a>00086 <span class="keywordtype">int</span>
+<a name="l00087"></a>00087 sinfo_new_bp_search_lin(<span class="keyword">const</span> <span class="keywordtype">char</span>* plugin_id,
+<a name="l00088"></a>00088                         cpl_parameterlist* config,
+<a name="l00089"></a>00089                         cpl_frameset* sof)
+<a name="l00090"></a>00090 {
+<a name="l00091"></a>00091   detlin_config * cfg=NULL;
+<a name="l00092"></a>00092   cpl_imagelist * imgl=NULL ;
+<a name="l00093"></a>00093   cpl_imagelist * coeffs_imgl=NULL;
+<a name="l00094"></a>00094   cpl_image * img_tmp=NULL ;
+<a name="l00095"></a>00095   cpl_image * mask=NULL;
+<a name="l00096"></a>00096   cpl_vector* cube_mean=NULL;
+<a name="l00097"></a>00097   cpl_frameset* raw=NULL;
+<a name="l00098"></a>00098   cpl_frameset* raw_on=NULL;
+<a name="l00099"></a>00099   cpl_frameset* raw_of=NULL;
+<a name="l00100"></a>00100   cpl_frame* frm=NULL;
+<a name="l00101"></a>00101   cpl_frame* frm_dup=NULL;
+<a name="l00102"></a>00102 
+<a name="l00103"></a>00103   cpl_table* qclog_tbl=NULL;
+<a name="l00104"></a>00104 
+<a name="l00105"></a>00105   cpl_parameter *p=NULL;
+<a name="l00106"></a>00106   cpl_polynomial *pol=NULL;
+<a name="l00107"></a>00107   cpl_vector* vec_adl=NULL;
+<a name="l00108"></a>00108   cpl_vector* vec_med=NULL;
+<a name="l00109"></a>00109   <span class="keywordtype">double</span>* mse=NULL;
+<a name="l00110"></a>00110   <span class="keywordtype">int</span> i=0;
+<a name="l00111"></a>00111   <span class="keywordtype">int</span> n_bad=0 ;
+<a name="l00112"></a>00112   <span class="keywordtype">int</span> nff=0;
+<a name="l00113"></a>00113   <span class="keywordtype">char</span> key_value[FILE_NAME_SZ];
+<a name="l00114"></a>00114   <span class="keywordtype">char</span> key_name[FILE_NAME_SZ];
+<a name="l00115"></a>00115   cpl_table* det_lin=NULL;
+<a name="l00116"></a>00116   <span class="keywordtype">int</span> nraw=0;
+<a name="l00117"></a>00117   <span class="keywordtype">int</span>* status=NULL;
+<a name="l00118"></a>00118   cpl_table* gain=NULL;
+<a name="l00119"></a>00119   <span class="keywordtype">int</span> ngain=0;
+<a name="l00120"></a>00120   <span class="keywordtype">int</span> sz_imgl=0;
+<a name="l00121"></a>00121 
+<a name="l00122"></a>00122   <span class="keywordtype">int</span> llx=270;
+<a name="l00123"></a>00123   <span class="keywordtype">int</span> lly=1030;
+<a name="l00124"></a>00124   <span class="keywordtype">int</span> urx=310;
+<a name="l00125"></a>00125   <span class="keywordtype">int</span> ury=1060;
+<a name="l00126"></a>00126   <span class="keywordtype">int</span> zone[4];
+<a name="l00127"></a>00127   <span class="comment">//int kappa=5;</span>
+<a name="l00128"></a>00128   <span class="comment">//int nclip=25;</span>
+<a name="l00129"></a>00129   <span class="keywordtype">int</span> pdensity=0;
+<a name="l00130"></a>00130 
+<a name="l00131"></a>00131 
+<a name="l00132"></a>00132   check_nomsg(p=cpl_parameterlist_find(config,<span class="stringliteral">"sinfoni.product.density"</span>));
+<a name="l00133"></a>00133   check_nomsg(pdensity=cpl_parameter_get_int(p));
+<a name="l00134"></a>00134 
+<a name="l00135"></a>00135 
+<a name="l00136"></a>00136   <span class="comment">/* parse the file names and parameters to the bad_config</span>
+<a name="l00137"></a>00137 <span class="comment">     data structure cfg */</span>
+<a name="l00138"></a>00138   check_nomsg(raw=cpl_frameset_new());
+<a name="l00139"></a>00139   cknull(cfg = sinfo_parse_cpl_input_detlin(config,sof,&raw),
+<a name="l00140"></a>00140      <span class="stringliteral">"could not parse .ini file!"</span>);
+<a name="l00141"></a>00141 
+<a name="l00142"></a>00142   <span class="comment">/* ======================================================================</span>
+<a name="l00143"></a>00143 <span class="comment">     DETERMINES LINEARITY COEFF AS DFO DOES</span>
+<a name="l00144"></a>00144 <span class="comment">     ======================================================================</span>
+<a name="l00145"></a>00145 <span class="comment">  */</span>
+<a name="l00146"></a>00146   nff=cpl_frameset_get_size(raw);
+<a name="l00147"></a>00147   raw_on=cpl_frameset_new();
+<a name="l00148"></a>00148   raw_of=cpl_frameset_new();
+<a name="l00149"></a>00149   <span class="comment">/* separates on and off frames */</span>
+<a name="l00150"></a>00150 
+<a name="l00151"></a>00151   <span class="keywordflow">for</span>(i=0;i<nff;i++) {
+<a name="l00152"></a>00152     frm=cpl_frameset_get_frame(raw,i);
+<a name="l00153"></a>00153     frm_dup=cpl_frame_duplicate(frm);
+<a name="l00154"></a>00154     <span class="keywordflow">if</span>(sinfo_frame_is_on(frm)) {
+<a name="l00155"></a>00155       cpl_frameset_insert(raw_on,frm_dup);
+<a name="l00156"></a>00156     } <span class="keywordflow">else</span> {
+<a name="l00157"></a>00157       cpl_frameset_insert(raw_of,frm_dup);
+<a name="l00158"></a>00158     }
+<a name="l00159"></a>00159   }
+<a name="l00160"></a>00160   <span class="comment">/*</span>
+<a name="l00161"></a>00161 <span class="comment">    cknull(det_lin=sinfo_get_linearity(raw_on,raw_of),</span>
+<a name="l00162"></a>00162 <span class="comment">    "Error computing linearity");</span>
+<a name="l00163"></a>00163 <span class="comment">  */</span>
+<a name="l00164"></a>00164   zone[0]=llx;
+<a name="l00165"></a>00165   zone[1]=lly;
+<a name="l00166"></a>00166   zone[2]=urx;
+<a name="l00167"></a>00167   zone[3]=ury;
+<a name="l00168"></a>00168 
+<a name="l00169"></a>00169   <span class="comment">//If one refers to a larger area</span>
+<a name="l00170"></a>00170   zone[0]=20;
+<a name="l00171"></a>00171   zone[1]=2028;
+<a name="l00172"></a>00172   zone[2]=20;
+<a name="l00173"></a>00173   zone[3]=2028;
+<a name="l00174"></a>00174 
+<a name="l00175"></a>00175   <span class="comment">/*</span>
+<a name="l00176"></a>00176 <span class="comment">    cknull(det_lin=irplib_compute_linearity(raw_on,raw_of),</span>
+<a name="l00177"></a>00177 <span class="comment">    "Error computing linearity");</span>
+<a name="l00178"></a>00178 <span class="comment">  */</span>
+<a name="l00179"></a>00179 
+<a name="l00180"></a>00180   <span class="keywordflow">if</span>(pdensity > 1 ) {
+<a name="l00181"></a>00181 
+<a name="l00182"></a>00182     sinfo_msg(<span class="stringliteral">"Computes linearity"</span>);
+<a name="l00183"></a>00183     cknull(det_lin=sinfo_compute_linearity(raw_on,raw_of),
+<a name="l00184"></a>00184        <span class="stringliteral">"Error computing linearity"</span>);
+<a name="l00185"></a>00185 
+<a name="l00186"></a>00186     check_nomsg(nraw=cpl_table_get_nrow(det_lin));
+<a name="l00187"></a>00187     check_nomsg(vec_adl=cpl_vector_new(nraw));
+<a name="l00188"></a>00188     check_nomsg(vec_med=cpl_vector_new(nraw));
+<a name="l00189"></a>00189 
+<a name="l00190"></a>00190     <span class="keywordflow">for</span>(i=0;i<nraw;i++) {
+<a name="l00191"></a>00191       cpl_vector_set(vec_adl,i,cpl_table_get_double(det_lin,<span class="stringliteral">"adl"</span>,i,status));
+<a name="l00192"></a>00192       cpl_vector_set(vec_med,i,cpl_table_get_double(det_lin,<span class="stringliteral">"med"</span>,i,status));
+<a name="l00193"></a>00193     }
+<a name="l00194"></a>00194     check_nomsg(pol=sinfo_polynomial_fit_1d_create(vec_adl,vec_med,
+<a name="l00195"></a>00195                          cfg->order,mse));
+<a name="l00196"></a>00196     sinfo_free_my_vector(&vec_adl);
+<a name="l00197"></a>00197     sinfo_free_my_vector(&vec_med);
+<a name="l00198"></a>00198 
+<a name="l00199"></a>00199     cknull_nomsg(qclog_tbl=sinfo_qclog_init());
+<a name="l00200"></a>00200     cpl_size deg=0;
+<a name="l00201"></a>00201     <span class="keywordflow">for</span>(deg=0;deg<cfg->order+1;deg++) {
+<a name="l00202"></a>00202 
+<a name="l00203"></a>00203       snprintf(key_name,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%"</span> CPL_SIZE_FORMAT <span class="stringliteral">"%s"</span>,<span class="stringliteral">"QC BP-MAP LIN"</span>,deg,<span class="stringliteral">" MED"</span>);
+<a name="l00204"></a>00204       sinfo_qclog_add_double(qclog_tbl,key_name,
+<a name="l00205"></a>00205                  cpl_polynomial_get_coeff(pol,&deg),
+<a name="l00206"></a>00206                  <span class="stringliteral">"Linearity Polynomial Coeff"</span>,<span class="stringliteral">"%g"</span>);
+<a name="l00207"></a>00207     }
+<a name="l00208"></a>00208     sinfo_free_polynomial(&pol);
+<a name="l00209"></a>00209 
+<a name="l00210"></a>00210     check_nomsg(p = cpl_parameterlist_find(config, <span class="stringliteral">"sinfoni.bp.method"</span>));
+<a name="l00211"></a>00211     snprintf(key_value, MAX_NAME_SIZE-1,<span class="stringliteral">"%s"</span>,cpl_parameter_get_string(p));
+<a name="l00212"></a>00212     ck0_nomsg(sinfo_qclog_add_string(qclog_tbl,<span class="stringliteral">"QC BP-MAP METHOD"</span>,key_value,
+<a name="l00213"></a>00213                      <span class="stringliteral">"BP search method"</span>,<span class="stringliteral">"%s"</span>));
+<a name="l00214"></a>00214 
+<a name="l00215"></a>00215     ck0(sinfo_pro_save_tbl(det_lin,raw,sof,BP_LIN_LIN_DET_INFO_OUT_FILENAME,
+<a name="l00216"></a>00216                PRO_LIN_DET_INFO,qclog_tbl,plugin_id,config),
+<a name="l00217"></a>00217     <span class="stringliteral">"cannot dump ims %s"</span>,BP_LIN_LIN_DET_INFO_OUT_FILENAME);
+<a name="l00218"></a>00218 
+<a name="l00219"></a>00219     sinfo_free_table(&det_lin);
+<a name="l00220"></a>00220     sinfo_free_table(&qclog_tbl);
+<a name="l00221"></a>00221   }
+<a name="l00222"></a>00222 
+<a name="l00223"></a>00223   <span class="comment">/*=======================================================*/</span>
+<a name="l00224"></a>00224   <span class="keywordflow">if</span>(pdensity > 1 ) {
+<a name="l00225"></a>00225     sinfo_msg(<span class="stringliteral">"Computes gain"</span>);
+<a name="l00226"></a>00226 
+<a name="l00227"></a>00227     cknull(gain=sinfo_compute_gain(raw_on,raw_of),<span class="stringliteral">"Error computing gain"</span>);
+<a name="l00228"></a>00228 
+<a name="l00229"></a>00229     <span class="comment">//cknull(gain=irplib_compute_gain(raw_on,raw_of,zone,kappa,nclip),</span>
+<a name="l00230"></a>00230     <span class="comment">//         "Error computing gain");</span>
+<a name="l00231"></a>00231 
+<a name="l00232"></a>00232     sinfo_free_frameset(&raw_on);
+<a name="l00233"></a>00233     sinfo_free_frameset(&raw_of);
+<a name="l00234"></a>00234 
+<a name="l00235"></a>00235     check_nomsg(ngain=cpl_table_get_nrow(gain));
+<a name="l00236"></a>00236     cknull_nomsg(qclog_tbl=sinfo_qclog_init());
+<a name="l00237"></a>00237 
+<a name="l00238"></a>00238     <span class="keywordflow">for</span>(i=0;i<ngain;i++) {
+<a name="l00239"></a>00239       snprintf(key_name,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%i"</span>,<span class="stringliteral">"QC GAIN"</span>,i);
+<a name="l00240"></a>00240       ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,key_name,
+<a name="l00241"></a>00241                        cpl_table_get_double(gain,<span class="stringliteral">"gain"</span>,i,status),
+<a name="l00242"></a>00242                        <span class="stringliteral">"Detector gain"</span>,<span class="stringliteral">"%g"</span>));
+<a name="l00243"></a>00243     }
+<a name="l00244"></a>00244 
+<a name="l00245"></a>00245     ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,<span class="stringliteral">"QC GAIN"</span>,
+<a name="l00246"></a>00246                      cpl_table_get_column_median(gain,<span class="stringliteral">"gain"</span>),<span class="stringliteral">"Detector gain median"</span>,<span class="stringliteral">"%g"</span>));
+<a name="l00247"></a>00247     ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,<span class="stringliteral">"QC GAINERR"</span>,
+<a name="l00248"></a>00248                      cpl_table_get_column_stdev(gain,<span class="stringliteral">"gain"</span>),<span class="stringliteral">"Detector gain error"</span>,<span class="stringliteral">"%g"</span>));
+<a name="l00249"></a>00249 
+<a name="l00250"></a>00250     ck0(sinfo_pro_save_tbl(gain,raw,sof,BP_LIN_GAIN_OUT_FILENAME,PRO_GAIN_INFO,
+<a name="l00251"></a>00251                qclog_tbl,plugin_id,config),
+<a name="l00252"></a>00252     <span class="stringliteral">"cannot dump tbl %s"</span>, BP_LIN_GAIN_OUT_FILENAME);
+<a name="l00253"></a>00253 
+<a name="l00254"></a>00254     sinfo_free_table(&gain);
+<a name="l00255"></a>00255     sinfo_free_table(&qclog_tbl);
+<a name="l00256"></a>00256   }
+<a name="l00257"></a>00257 
+<a name="l00258"></a>00258   <span class="comment">/* =======================================================================</span>
+<a name="l00259"></a>00259 <span class="comment">     DETERMINES LINEARITY COEFF AS MPE DOES</span>
+<a name="l00260"></a>00260 <span class="comment">     =======================================================================</span>
+<a name="l00261"></a>00261 <span class="comment">  */</span>
+<a name="l00262"></a>00262 
+<a name="l00263"></a>00263 
+<a name="l00264"></a>00264   check_nomsg(imgl = cpl_imagelist_new());
+<a name="l00265"></a>00265   <span class="keywordflow">for</span> ( i = 0 ; i < cfg->nframes ; i++ )
+<a name="l00266"></a>00266     {
+<a name="l00267"></a>00267       <span class="keywordflow">if</span>(sinfo_is_fits_file (cfg->framelist[i]) != 1) {
+<a name="l00268"></a>00268     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Input file %s is not FITS"</span>,cfg->framelist[i] );
+<a name="l00269"></a>00269     <span class="keywordflow">return</span> -1;
+<a name="l00270"></a>00270       }
+<a name="l00271"></a>00271       check_nomsg(img_tmp=cpl_image_load(cfg->framelist[i],CPL_TYPE_FLOAT,0,0));
+<a name="l00272"></a>00272       check_nomsg(cpl_imagelist_set(imgl,img_tmp,i));
+<a name="l00273"></a>00273     }
+<a name="l00274"></a>00274 
+<a name="l00275"></a>00275   <span class="comment">/*----------------------------------------------------------------</span>
+<a name="l00276"></a>00276 <span class="comment">   *---------------------- SEARCH FOR BAD PIXELS---------------------</span>
+<a name="l00277"></a>00277 <span class="comment">   *--------------------------------------------------------------*/</span>
+<a name="l00278"></a>00278   sinfo_msg(<span class="stringliteral">"Search for bad pixels"</span>);
+<a name="l00279"></a>00279   cknull(coeffs_imgl=sinfo_new_fit_intensity_course(imgl,
+<a name="l00280"></a>00280                             cfg->order,
+<a name="l00281"></a>00281                             cfg->loReject,
+<a name="l00282"></a>00282                             cfg->hiReject),
+<a name="l00283"></a>00283      <span class="stringliteral">"could not fit polynomial and store coeffs in a data cube!"</span>);
+<a name="l00284"></a>00284 
+<a name="l00285"></a>00285   sinfo_free_imagelist(&imgl) ;
+<a name="l00286"></a>00286   check_nomsg(sz_imgl=cpl_imagelist_get_size(coeffs_imgl));
+<a name="l00287"></a>00287 
+<a name="l00288"></a>00288 
+<a name="l00289"></a>00289   <span class="comment">/*---store the polynomial fit coefficients in a data cube----*/</span>
+<a name="l00290"></a>00290   <span class="comment">/* CUBE NOT DUMPED BECAUSE PROBLEMS ON LAST PLANE */</span>
+<a name="l00291"></a>00291   cube_mean=cpl_vector_new(sz_imgl);
+<a name="l00292"></a>00292 
+<a name="l00293"></a>00293   <span class="comment">/* QC LOG */</span>
+<a name="l00294"></a>00294   cknull_nomsg(qclog_tbl=sinfo_qclog_init());
+<a name="l00295"></a>00295   <span class="keywordflow">for</span>(i=0;i<sz_imgl;i++) {
+<a name="l00296"></a>00296     cpl_vector_set(cube_mean,i,
+<a name="l00297"></a>00297            cpl_image_get_median(cpl_imagelist_get(coeffs_imgl,i)));
+<a name="l00298"></a>00298 
+<a name="l00299"></a>00299     snprintf(key_name,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%i%s"</span>,<span class="stringliteral">"QC BP-MAP LIN"</span>,i,<span class="stringliteral">" MEAN"</span>);
+<a name="l00300"></a>00300     snprintf(key_value,MAX_NAME_SIZE-1,<span class="stringliteral">"%g"</span>,cpl_vector_get(cube_mean,i));
+<a name="l00301"></a>00301     ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,key_name,
+<a name="l00302"></a>00302                      cpl_vector_get(cube_mean,i),
+<a name="l00303"></a>00303                      <span class="stringliteral">"Linearity Polynomial Coeff"</span>,<span class="stringliteral">"%g"</span>));
+<a name="l00304"></a>00304 
+<a name="l00305"></a>00305   }
+<a name="l00306"></a>00306   sinfo_free_my_vector(&cube_mean);
+<a name="l00307"></a>00307   check_nomsg(p = cpl_parameterlist_find(config, <span class="stringliteral">"sinfoni.bp.method"</span>));
+<a name="l00308"></a>00308   snprintf(key_value, MAX_NAME_SIZE-1,<span class="stringliteral">"%s"</span>,cpl_parameter_get_string(p));
+<a name="l00309"></a>00309   ck0_nomsg(sinfo_qclog_add_string(qclog_tbl,<span class="stringliteral">"QC BP-MAP METHOD"</span>,key_value,
+<a name="l00310"></a>00310                    <span class="stringliteral">"BP search method"</span>,<span class="stringliteral">"%s"</span>));
+<a name="l00311"></a>00311 
+<a name="l00312"></a>00312 
+<a name="l00313"></a>00313   ck0(sinfo_pro_save_ims(coeffs_imgl,raw,sof,cfg->coeffsCubeName,
+<a name="l00314"></a>00314              PRO_BP_COEFF,qclog_tbl,plugin_id,config),
+<a name="l00315"></a>00315       <span class="stringliteral">"cannot dump ims %s"</span>, cfg->coeffsCubeName);
+<a name="l00316"></a>00316 
+<a name="l00317"></a>00317   sinfo_free_table(&qclog_tbl);
+<a name="l00318"></a>00318 
+<a name="l00319"></a>00319   <span class="comment">/* =======================================================================</span>
+<a name="l00320"></a>00320 <span class="comment">     DETERMINES BAD PIXEL MAP</span>
+<a name="l00321"></a>00321 <span class="comment">     =======================================================================</span>
+<a name="l00322"></a>00322 <span class="comment">  */</span>
+<a name="l00323"></a>00323   sinfo_msg(<span class="stringliteral">"Generates bad pixel map"</span>);
+<a name="l00324"></a>00324   cknull(mask = sinfo_new_search_bad_pixels (coeffs_imgl,
+<a name="l00325"></a>00325                          cfg->threshSigmaFactor,
+<a name="l00326"></a>00326                          cfg->nonlinearThresh,
+<a name="l00327"></a>00327                          cfg->loReject,
+<a name="l00328"></a>00328                          cfg->hiReject),
+<a name="l00329"></a>00329      <span class="stringliteral">"could not create bad pixel mask!"</span>) ;
+<a name="l00330"></a>00330 
+<a name="l00331"></a>00331   sinfo_free_imagelist(&coeffs_imgl) ;
+<a name="l00332"></a>00332 
+<a name="l00333"></a>00333   check_nomsg(n_bad = sinfo_new_count_bad_pixels(mask)) ;
+<a name="l00334"></a>00334   sinfo_msg( <span class="stringliteral">"No of bad pixels: %d"</span>, n_bad ) ;
+<a name="l00335"></a>00335 
+<a name="l00336"></a>00336   <span class="comment">/* QC LOG */</span>
+<a name="l00337"></a>00337   cknull_nomsg(qclog_tbl=sinfo_qclog_init());
+<a name="l00338"></a>00338   check_nomsg(p = cpl_parameterlist_find(config, <span class="stringliteral">"sinfoni.bp.method"</span>));
+<a name="l00339"></a>00339   snprintf(key_value, MAX_NAME_SIZE-1,<span class="stringliteral">"%s"</span>,cpl_parameter_get_string(p));
+<a name="l00340"></a>00340   ck0_nomsg(sinfo_qclog_add_string(qclog_tbl,<span class="stringliteral">"QC BP-MAP METHOD"</span>,key_value,
+<a name="l00341"></a>00341                    <span class="stringliteral">"BP search method"</span>,<span class="stringliteral">"%s"</span>));
+<a name="l00342"></a>00342 
+<a name="l00343"></a>00343   ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,<span class="stringliteral">"QC BP-MAP NBADPIX"</span>,n_bad,
+<a name="l00344"></a>00344                 <span class="stringliteral">"No of bad pixels"</span>,<span class="stringliteral">"%d"</span>));
+<a name="l00345"></a>00345 
+<a name="l00346"></a>00346   ck0(sinfo_pro_save_ima(mask,raw,sof,cfg->outName,PRO_BP_MAP_NL,qclog_tbl,
+<a name="l00347"></a>00347              plugin_id,config),
+<a name="l00348"></a>00348       <span class="stringliteral">"cannot save ima %s"</span>, cfg->outName);
+<a name="l00349"></a>00349 
+<a name="l00350"></a>00350 
+<a name="l00351"></a>00351   <span class="comment">/* ======================================================================</span>
+<a name="l00352"></a>00352 <span class="comment">     FREE MEMORY</span>
+<a name="l00353"></a>00353 <span class="comment">     ======================================================================</span>
+<a name="l00354"></a>00354 <span class="comment">  */</span>
+<a name="l00355"></a>00355 
+<a name="l00356"></a>00356 
+<a name="l00357"></a>00357 
+<a name="l00358"></a>00358   sinfo_free_table(&qclog_tbl);
+<a name="l00359"></a>00359   sinfo_free_image(&mask);
+<a name="l00360"></a>00360   sinfo_free_frameset(&raw);
+<a name="l00361"></a>00361   sinfo_detlin_free(&cfg);
+<a name="l00362"></a>00362 
+<a name="l00363"></a>00363   <span class="keywordflow">return</span> 0;
+<a name="l00364"></a>00364 
+<a name="l00365"></a>00365  cleanup:
+<a name="l00366"></a>00366   sinfo_free_frameset(&raw_on);
+<a name="l00367"></a>00367   sinfo_free_frameset(&raw_of);
+<a name="l00368"></a>00368 
+<a name="l00369"></a>00369   sinfo_free_image(&mask) ;
+<a name="l00370"></a>00370   sinfo_free_my_vector(&cube_mean);
+<a name="l00371"></a>00371   sinfo_free_imagelist(&imgl);
+<a name="l00372"></a>00372   sinfo_free_imagelist(&coeffs_imgl);
+<a name="l00373"></a>00373   sinfo_free_table(&gain);
+<a name="l00374"></a>00374   sinfo_free_table(&qclog_tbl);
+<a name="l00375"></a>00375   sinfo_free_table(&det_lin);
+<a name="l00376"></a>00376   sinfo_free_my_vector(&vec_adl);
+<a name="l00377"></a>00377   sinfo_free_my_vector(&vec_med);
+<a name="l00378"></a>00378   sinfo_free_polynomial(&pol);
+<a name="l00379"></a>00379   sinfo_detlin_free(&cfg);
+<a name="l00380"></a>00380   sinfo_free_frameset(&raw);
+<a name="l00381"></a>00381 
+<a name="l00382"></a>00382   <span class="keywordflow">return</span> -1;
+<a name="l00383"></a>00383 
+<a name="l00384"></a>00384 
+<a name="l00385"></a>00385 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__bp__lin_8h_source.html b/html/sinfo__bp__lin_8h_source.html
new file mode 100644
index 0000000..2f5ae6d
--- /dev/null
+++ b/html/sinfo__bp__lin_8h_source.html
@@ -0,0 +1,67 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_bp_lin.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_bp_lin.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#ifndef SINFO_BP_LIN_H</span>
+<a name="l00002"></a>00002 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_BP_LIN_H</span>
+<a name="l00003"></a>00003 <span class="preprocessor"></span><span class="comment">/*</span>
+<a name="l00004"></a>00004 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00005"></a>00005 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00006"></a>00006 <span class="comment"> *</span>
+<a name="l00007"></a>00007 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00008"></a>00008 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00009"></a>00009 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00010"></a>00010 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00011"></a>00011 <span class="comment"> *</span>
+<a name="l00012"></a>00012 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00013"></a>00013 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00014"></a>00014 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00015"></a>00015 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00016"></a>00016 <span class="comment"> *</span>
+<a name="l00017"></a>00017 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00018"></a>00018 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00019"></a>00019 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00020"></a>00020 <span class="comment"> */</span>
+<a name="l00021"></a>00021 <span class="comment">/*******************************************************************************</span>
+<a name="l00022"></a>00022 <span class="comment">* E.S.O. - VLT project</span>
+<a name="l00023"></a>00023 <span class="comment">*</span>
+<a name="l00024"></a>00024 <span class="comment">* "@(#) $Id: sinfo_bp_lin.h,v 1.2 2007/06/06 07:10:45 amodigli Exp $"</span>
+<a name="l00025"></a>00025 <span class="comment">*</span>
+<a name="l00026"></a>00026 <span class="comment">* who       when      what</span>
+<a name="l00027"></a>00027 <span class="comment">* --------  --------  ----------------------------------------------</span>
+<a name="l00028"></a>00028 <span class="comment">* schreib  06/05/03  created</span>
+<a name="l00029"></a>00029 <span class="comment">*/</span>
+<a name="l00030"></a>00030 
+<a name="l00031"></a>00031 <span class="comment">/************************************************************************</span>
+<a name="l00032"></a>00032 <span class="comment"> * bp_lin.h</span>
+<a name="l00033"></a>00033 <span class="comment"> * routines to search for bad pixels</span>
+<a name="l00034"></a>00034 <span class="comment"> *----------------------------------------------------------------------</span>
+<a name="l00035"></a>00035 <span class="comment"> */</span>
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="comment">/*</span>
+<a name="l00038"></a>00038 <span class="comment"> * header files</span>
+<a name="l00039"></a>00039 <span class="comment"> */</span>
+<a name="l00040"></a>00040 
+<a name="l00041"></a>00041 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00043"></a>00043 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00044"></a>00044 <span class="comment"> *                        Function ANSI C prototypes</span>
+<a name="l00045"></a>00045 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00054"></a>00054 <span class="keywordtype">int</span> 
+<a name="l00055"></a>00055 sinfo_new_bp_search_lin (<span class="keyword">const</span> <span class="keywordtype">char</span>* plugin_id, 
+<a name="l00056"></a>00056                          cpl_parameterlist* config, 
+<a name="l00057"></a>00057                          cpl_frameset* <span class="keyword">set</span>);
+<a name="l00058"></a>00058 <span class="preprocessor">#endif </span>
+<a name="l00059"></a>00059 <span class="preprocessor"></span><span class="comment">/*--------------------------------------------------------------------------*/</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__bp__lin__config_8c_source.html b/html/sinfo__bp__lin__config_8c_source.html
new file mode 100644
index 0000000..a8a72ca
--- /dev/null
+++ b/html/sinfo__bp__lin__config_8c_source.html
@@ -0,0 +1,145 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_bp_lin_config.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_bp_lin_config.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_bp_lin_config.c,v 1.5 2012/03/02 08:42:20 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the CPL (Common Pipeline Library)</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
+<a name="l00007"></a>00007 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span>
+<a name="l00008"></a>00008 <span class="comment"> * License as published by the Free Software Foundation; either</span>
+<a name="l00009"></a>00009 <span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
+<a name="l00014"></a>00014 <span class="comment"> * Lesser General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
+<a name="l00017"></a>00017 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2012/03/02 08:42:20 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.5 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> */</span>
+<a name="l00026"></a>00026 
+<a name="l00027"></a>00027 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00029"></a>00029 <span class="preprocessor">#endif</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span> <span class="comment">/****************************************************************</span>
+<a name="l00031"></a>00031 <span class="comment">  *           Bad pixel search  (Linear method)                  *</span>
+<a name="l00032"></a>00032 <span class="comment">  ****************************************************************/</span>
+<a name="l00033"></a>00033 
+<a name="l00034"></a>00034 <span class="preprocessor">#include "sinfo_bp_lin_config.h"</span>  
+<a name="l00035"></a>00035 
+<a name="l00054"></a>00054   <span class="comment">/* Bad pixel parameters */</span>
+<a name="l00055"></a>00055 
+<a name="l00056"></a>00056 <span class="keywordtype">void</span>
+<a name="l00057"></a>00057  sinfo_bp_lin_config_add(cpl_parameterlist *list)
+<a name="l00058"></a>00058 {
+<a name="l00059"></a>00059 
+<a name="l00060"></a>00060   cpl_parameter *p;
+<a name="l00061"></a>00061 
+<a name="l00062"></a>00062   <span class="keywordflow">if</span> (!list) {
+<a name="l00063"></a>00063     <span class="keywordflow">return</span>;
+<a name="l00064"></a>00064   }
+<a name="l00065"></a>00065 
+<a name="l00066"></a>00066 
+<a name="l00067"></a>00067 
+<a name="l00068"></a>00068   <span class="comment">/* order of the fit polynomial = number of coefficents - 1 */</span>
+<a name="l00069"></a>00069   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.bp_lin.order"</span>,
+<a name="l00070"></a>00070                   CPL_TYPE_INT,
+<a name="l00071"></a>00071                               <span class="stringliteral">"Order: "</span>
+<a name="l00072"></a>00072                               <span class="stringliteral">"order of the fit polynomial = "</span>
+<a name="l00073"></a>00073                               <span class="stringliteral">"number of coefficents - 1"</span>,
+<a name="l00074"></a>00074                               <span class="stringliteral">"sinfoni.bp_lin"</span>,
+<a name="l00075"></a>00075                               2);
+<a name="l00076"></a>00076 
+<a name="l00077"></a>00077   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"bp_lin-order"</span>);
+<a name="l00078"></a>00078   cpl_parameterlist_append(list, p);
+<a name="l00079"></a>00079 
+<a name="l00080"></a>00080 
+<a name="l00081"></a>00081 
+<a name="l00082"></a>00082  p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.bp_lin.thresh_sigma_factor"</span>,
+<a name="l00083"></a>00083                   CPL_TYPE_DOUBLE,
+<a name="l00084"></a>00084                               <span class="stringliteral">"Threshold Sigma Factor: "</span>
+<a name="l00085"></a>00085                               <span class="stringliteral">"threshold factor of the clean standard "</span>
+<a name="l00086"></a>00086                               <span class="stringliteral">"deviation. If the deviations of the linear "</span>
+<a name="l00087"></a>00087                               <span class="stringliteral">"polynomial coefficients exceed this threshold "</span>
+<a name="l00088"></a>00088                  <span class="stringliteral">"the corresponding pixels are declared as bad "</span>,
+<a name="l00089"></a>00089                               <span class="stringliteral">"sinfoni.bp_noise"</span>,
+<a name="l00090"></a>00090                               10.);
+<a name="l00091"></a>00091 
+<a name="l00092"></a>00092   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"bp_lin-thresh_sigma_fct"</span>);
+<a name="l00093"></a>00093   cpl_parameterlist_append(list, p);
+<a name="l00094"></a>00094 
+<a name="l00095"></a>00095 
+<a name="l00096"></a>00096 
+<a name="l00097"></a>00097   <span class="comment">/* if a non-linear coefficient exceeds this value the </span>
+<a name="l00098"></a>00098 <span class="comment">     corresponding pixel is declared as bad</span>
+<a name="l00099"></a>00099 <span class="comment">  */</span>
+<a name="l00100"></a>00100   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.bp_lin.nlin_threshold"</span>,
+<a name="l00101"></a>00101                   CPL_TYPE_DOUBLE,
+<a name="l00102"></a>00102                               <span class="stringliteral">"Non Linear Threshold"</span>,
+<a name="l00103"></a>00103                               <span class="stringliteral">"sinfoni.bp_lin"</span>,
+<a name="l00104"></a>00104                               0.5);
+<a name="l00105"></a>00105 
+<a name="l00106"></a>00106   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"bp_lin-nlin_threshold"</span>);
+<a name="l00107"></a>00107   cpl_parameterlist_append(list, p);
+<a name="l00108"></a>00108 
+<a name="l00109"></a>00109 
+<a name="l00110"></a>00110  <span class="comment">/* float </span>
+<a name="l00111"></a>00111 <span class="comment">     threshold used in the clean mean percentage of rejection used to reject </span>
+<a name="l00112"></a>00112 <span class="comment">     low and high frame */</span>
+<a name="l00113"></a>00113  <span class="comment">/* percentage of extreme pixel value to reject when calculating the mean </span>
+<a name="l00114"></a>00114 <span class="comment">    and stdev */</span>
+<a name="l00115"></a>00115   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.bp_lin.low_rejection"</span>,
+<a name="l00116"></a>00116                   CPL_TYPE_DOUBLE,
+<a name="l00117"></a>00117                               <span class="stringliteral">"low_rejection: "</span>
+<a name="l00118"></a>00118                               <span class="stringliteral">"percentage of rejected low intensity "</span>
+<a name="l00119"></a>00119                               <span class="stringliteral">"pixels before averaging"</span>,
+<a name="l00120"></a>00120                               <span class="stringliteral">"sinfoni.bp_lin"</span>,
+<a name="l00121"></a>00121                               10.,
+<a name="l00122"></a>00122                               0.,
+<a name="l00123"></a>00123                               100.);
+<a name="l00124"></a>00124 
+<a name="l00125"></a>00125   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"bp_lin-lo_rej"</span>);
+<a name="l00126"></a>00126   cpl_parameterlist_append(list, p);
+<a name="l00127"></a>00127 
+<a name="l00128"></a>00128   <span class="comment">/* float </span>
+<a name="l00129"></a>00129 <span class="comment">     threshold used in the clean mean percentage of rejection used to reject </span>
+<a name="l00130"></a>00130 <span class="comment">     low and high frame */</span>
+<a name="l00131"></a>00131  <span class="comment">/* percentage of extreme pixel value to reject when calculating the mean </span>
+<a name="l00132"></a>00132 <span class="comment">    and stdev */</span>
+<a name="l00133"></a>00133   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.bp_lin.high_rejection"</span>,
+<a name="l00134"></a>00134                   CPL_TYPE_DOUBLE,
+<a name="l00135"></a>00135                               <span class="stringliteral">"high_rejection: "</span>
+<a name="l00136"></a>00136                               <span class="stringliteral">"percentage of rejected high intensity "</span>
+<a name="l00137"></a>00137                               <span class="stringliteral">"pixels before averaging"</span>,
+<a name="l00138"></a>00138                               <span class="stringliteral">"sinfoni.bp_lin"</span>,
+<a name="l00139"></a>00139                               10.,0.,100.);
+<a name="l00140"></a>00140 
+<a name="l00141"></a>00141   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"bp_lin-hi_rej"</span>);
+<a name="l00142"></a>00142   cpl_parameterlist_append(list, p);
+<a name="l00143"></a>00143 
+<a name="l00144"></a>00144 
+<a name="l00145"></a>00145   <span class="keywordflow">return</span>;
+<a name="l00146"></a>00146 
+<a name="l00147"></a>00147 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__bp__lin__config_8h_source.html b/html/sinfo__bp__lin__config_8h_source.html
new file mode 100644
index 0000000..c05d5a5
--- /dev/null
+++ b/html/sinfo__bp__lin__config_8h_source.html
@@ -0,0 +1,53 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_bp_lin_config.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_bp_lin_config.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_bp_lin_config.h,v 1.2 2006/10/22 14:12:27 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the CPL (Common Pipeline Library)</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
+<a name="l00007"></a>00007 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span>
+<a name="l00008"></a>00008 <span class="comment"> * License as published by the Free Software Foundation; either</span>
+<a name="l00009"></a>00009 <span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
+<a name="l00014"></a>00014 <span class="comment"> * Lesser General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
+<a name="l00017"></a>00017 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2006/10/22 14:12:27 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.2 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> */</span>
+<a name="l00026"></a>00026 
+<a name="l00027"></a>00027  <span class="comment">/****************************************************************</span>
+<a name="l00028"></a>00028 <span class="comment">  *           Bad pixel search  (normal method)                  *</span>
+<a name="l00029"></a>00029 <span class="comment">  ****************************************************************/</span>
+<a name="l00030"></a>00030 <span class="preprocessor">#ifndef SINFO_BP_LIN_CONFIG_H</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_BP_LIN_CONFIG_H</span>
+<a name="l00032"></a>00032 <span class="preprocessor"></span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include "cpl.h"</span>  
+<a name="l00034"></a>00034 
+<a name="l00035"></a>00035 <span class="keywordtype">void</span> sinfo_bp_lin_config_add(cpl_parameterlist *list);
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__bp__noise_8c_source.html b/html/sinfo__bp__noise_8c_source.html
new file mode 100644
index 0000000..8413a25
--- /dev/null
+++ b/html/sinfo__bp__noise_8c_source.html
@@ -0,0 +1,151 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_bp_noise.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_bp_noise.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name    :       sinfo_bp_noise.c</span>
+<a name="l00022"></a>00022 <span class="comment">   Author       :    J. Schreiber</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on   :    May 5, 2003</span>
+<a name="l00024"></a>00024 <span class="comment">   Description  :    Different methods for searching for bad pixels</span>
+<a name="l00025"></a>00025 <span class="comment">                        used in the recipe spiffi_bp_noise </span>
+<a name="l00026"></a>00026 <span class="comment"></span>
+<a name="l00027"></a>00027 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span>
+<a name="l00032"></a>00032 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                                Includes</span>
+<a name="l00034"></a>00034 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 <span class="preprocessor">#include "sinfo_bp_noise.h"</span>
+<a name="l00036"></a>00036 <span class="preprocessor">#include "sinfo_detnoise_ini_by_cpl.h"</span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include "sinfo_pro_save.h"</span>
+<a name="l00038"></a>00038 <span class="preprocessor">#include "sinfo_pro_types.h"</span>
+<a name="l00039"></a>00039 <span class="preprocessor">#include "sinfo_raw_types.h"</span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include "sinfo_functions.h"</span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include "sinfo_detlin.h"</span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include "sinfo_error.h"</span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include "sinfo_utils_wrappers.h"</span>
+<a name="l00044"></a>00044 
+<a name="l00050"></a>00050 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00051"></a>00051 <span class="comment">                                Defines</span>
+<a name="l00052"></a>00052 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00053"></a>00053 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00054"></a>00054 <span class="comment">                             Function Definitions</span>
+<a name="l00055"></a>00055 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00056"></a>00056 
+<a name="l00074"></a>00074 <span class="keywordtype">int</span> 
+<a name="l00075"></a>00075 sinfo_new_bp_search_noise (<span class="keyword">const</span> <span class="keywordtype">char</span>* plugin_id,
+<a name="l00076"></a>00076                                cpl_parameterlist* config, 
+<a name="l00077"></a>00077                                cpl_frameset* sof, 
+<a name="l00078"></a>00078                                <span class="keyword">const</span> <span class="keywordtype">char</span>* out_name )
+<a name="l00079"></a>00079 {
+<a name="l00080"></a>00080 
+<a name="l00081"></a>00081     detnoise_config * cfg =NULL;
+<a name="l00082"></a>00082 
+<a name="l00083"></a>00083     cpl_imagelist * image_list=NULL ;
+<a name="l00084"></a>00084     cpl_image * img_tmp=NULL ;
+<a name="l00085"></a>00085     cpl_image       *  mask=NULL ;
+<a name="l00086"></a>00086     cpl_parameter *p=NULL;
+<a name="l00087"></a>00087     cpl_frameset* raw=NULL;
+<a name="l00088"></a>00088     cpl_table* qclog_tbl=NULL;
+<a name="l00089"></a>00089     <span class="keywordtype">char</span> key_value[FILE_NAME_SZ];
+<a name="l00090"></a>00090     <span class="keywordtype">int</span> i=0;
+<a name="l00091"></a>00091     <span class="keywordtype">int</span> n_bad =0;
+<a name="l00092"></a>00092 
+<a name="l00093"></a>00093     <span class="comment">/*parse the file names and parameters to the detnoise_config data </span>
+<a name="l00094"></a>00094 <span class="comment">      structure cfg*/</span>
+<a name="l00095"></a>00095     check_nomsg(raw=cpl_frameset_new());
+<a name="l00096"></a>00096     ck0(sinfo_extract_raw_frames_type1(sof,raw,RAW_DARK),
+<a name="l00097"></a>00097         <span class="stringliteral">"Error extracting %s frames"</span>,RAW_DARK);
+<a name="l00098"></a>00098     cknull(cfg = sinfo_parse_cpl_input_detnoise(config,sof,&raw),
+<a name="l00099"></a>00099            <span class="stringliteral">" could not parse .ini file!"</span>) ;
+<a name="l00100"></a>00100     check_nomsg(image_list = cpl_imagelist_new());
+<a name="l00101"></a>00101     <span class="keywordflow">for</span> ( i = 0 ; i < cfg->nframes ; i++ )
+<a name="l00102"></a>00102     {
+<a name="l00103"></a>00103       <span class="keywordflow">if</span>(sinfo_is_fits_file (cfg->framelist[i]) != 1) {
+<a name="l00104"></a>00104     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Input file %s is not FITS"</span>,cfg->framelist[i] );
+<a name="l00105"></a>00105     <span class="keywordflow">goto</span> cleanup;
+<a name="l00106"></a>00106       }
+<a name="l00107"></a>00107       check_nomsg(img_tmp=cpl_image_load(cfg->framelist[i],
+<a name="l00108"></a>00108                                          CPL_TYPE_FLOAT,0,0));
+<a name="l00109"></a>00109 
+<a name="l00110"></a>00110       check_nomsg(cpl_imagelist_set(image_list,img_tmp,i));
+<a name="l00111"></a>00111     }
+<a name="l00112"></a>00112 
+<a name="l00113"></a>00113     <span class="comment">/*-----------------------------------------------------------------</span>
+<a name="l00114"></a>00114 <span class="comment">     *---------------------- SEARCH FOR BAD PIXELS---------------------</span>
+<a name="l00115"></a>00115 <span class="comment">     *-----------------------------------------------------------------*/</span>
+<a name="l00116"></a>00116     sinfo_msg(<span class="stringliteral">"Noise Search for bad pixels"</span>);
+<a name="l00117"></a>00117     <span class="comment">/*---generate the bad pixel mask-------------*/</span>
+<a name="l00118"></a>00118     cknull(mask=sinfo_new_search_bad_pixels_via_noise (image_list, 
+<a name="l00119"></a>00119                                cfg->threshSigmaFactor,
+<a name="l00120"></a>00120                                cfg->loReject,
+<a name="l00121"></a>00121                                cfg->hiReject),
+<a name="l00122"></a>00122        <span class="stringliteral">" could not create bad pixel mask!"</span>) ;
+<a name="l00123"></a>00123     
+<a name="l00124"></a>00124     n_bad = sinfo_new_count_bad_pixels(mask) ;
+<a name="l00125"></a>00125     sinfo_msg (<span class="stringliteral">"number of bad pixels: %d\n"</span>, n_bad) ;
+<a name="l00126"></a>00126 
+<a name="l00127"></a>00127     <span class="comment">/* QC LOG */</span>
+<a name="l00128"></a>00128     cknull_nomsg(qclog_tbl = sinfo_qclog_init());
+<a name="l00129"></a>00129     check_nomsg(p = cpl_parameterlist_find(config, <span class="stringliteral">"sinfoni.bp.method"</span>));
+<a name="l00130"></a>00130     snprintf(key_value, MAX_NAME_SIZE-1,<span class="stringliteral">"%s"</span>,cpl_parameter_get_string(p));
+<a name="l00131"></a>00131     ck0_nomsg(sinfo_qclog_add_string(qclog_tbl,<span class="stringliteral">"QC BP-MAP METHOD"</span>,key_value,
+<a name="l00132"></a>00132                                      <span class="stringliteral">"BP search method"</span>,<span class="stringliteral">"%s"</span>));
+<a name="l00133"></a>00133     ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,<span class="stringliteral">"QC BP-MAP NBADPIX"</span>,n_bad,
+<a name="l00134"></a>00134                                      <span class="stringliteral">"No of bad pixels"</span>,<span class="stringliteral">"%d"</span>));
+<a name="l00135"></a>00135 
+<a name="l00136"></a>00136     ck0(sinfo_pro_save_ima(mask,raw,sof,(<span class="keywordtype">char</span> *) out_name,
+<a name="l00137"></a>00137                PRO_BP_MAP_HP,qclog_tbl,plugin_id,config),
+<a name="l00138"></a>00138                            <span class="stringliteral">"cannot save ima %s"</span>, out_name);
+<a name="l00139"></a>00139 
+<a name="l00140"></a>00140     sinfo_free_image(&mask);
+<a name="l00141"></a>00141     sinfo_free_table(&qclog_tbl);
+<a name="l00142"></a>00142     sinfo_free_imagelist(&image_list) ;
+<a name="l00143"></a>00143     sinfo_detnoise_free(cfg);
+<a name="l00144"></a>00144     sinfo_free_frameset(&raw);
+<a name="l00145"></a>00145 
+<a name="l00146"></a>00146     <span class="keywordflow">return</span> 0 ;
+<a name="l00147"></a>00147 
+<a name="l00148"></a>00148  cleanup:
+<a name="l00149"></a>00149 
+<a name="l00150"></a>00150     sinfo_free_table(&qclog_tbl);
+<a name="l00151"></a>00151     sinfo_free_imagelist(&image_list) ;
+<a name="l00152"></a>00152     sinfo_free_image(&mask) ;
+<a name="l00153"></a>00153     sinfo_detnoise_free(cfg);
+<a name="l00154"></a>00154     sinfo_free_frameset(&raw);
+<a name="l00155"></a>00155    <span class="keywordflow">return</span> -1 ;
+<a name="l00156"></a>00156 
+<a name="l00157"></a>00157 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__bp__noise_8h_source.html b/html/sinfo__bp__noise_8h_source.html
new file mode 100644
index 0000000..4c42705
--- /dev/null
+++ b/html/sinfo__bp__noise_8h_source.html
@@ -0,0 +1,67 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_bp_noise.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_bp_noise.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#ifndef SINFO_BP_NOISE_H</span>
+<a name="l00002"></a>00002 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_BP_NOISE_H</span>
+<a name="l00003"></a>00003 <span class="preprocessor"></span><span class="comment">/*</span>
+<a name="l00004"></a>00004 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00005"></a>00005 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00006"></a>00006 <span class="comment"> *</span>
+<a name="l00007"></a>00007 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00008"></a>00008 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00009"></a>00009 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00010"></a>00010 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00011"></a>00011 <span class="comment"> *</span>
+<a name="l00012"></a>00012 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00013"></a>00013 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00014"></a>00014 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00015"></a>00015 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00016"></a>00016 <span class="comment"> *</span>
+<a name="l00017"></a>00017 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00018"></a>00018 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00019"></a>00019 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00020"></a>00020 <span class="comment"> */</span>
+<a name="l00021"></a>00021 <span class="comment">/*******************************************************************************</span>
+<a name="l00022"></a>00022 <span class="comment">* E.S.O. - VLT project</span>
+<a name="l00023"></a>00023 <span class="comment">*</span>
+<a name="l00024"></a>00024 <span class="comment">* "@(#) $Id: sinfo_bp_noise.h,v 1.3 2007/06/06 07:10:45 amodigli Exp $"</span>
+<a name="l00025"></a>00025 <span class="comment">*</span>
+<a name="l00026"></a>00026 <span class="comment">* who       when      what</span>
+<a name="l00027"></a>00027 <span class="comment">* --------  --------  ----------------------------------------------</span>
+<a name="l00028"></a>00028 <span class="comment">* schreib  06/05/03  created</span>
+<a name="l00029"></a>00029 <span class="comment">*/</span>
+<a name="l00030"></a>00030 
+<a name="l00031"></a>00031 <span class="comment">/************************************************************************</span>
+<a name="l00032"></a>00032 <span class="comment"> * bp_noise.h</span>
+<a name="l00033"></a>00033 <span class="comment"> * routine to search for bad pixels</span>
+<a name="l00034"></a>00034 <span class="comment"> *----------------------------------------------------------------------</span>
+<a name="l00035"></a>00035 <span class="comment"> */</span>
+<a name="l00036"></a>00036 <span class="comment">/*</span>
+<a name="l00037"></a>00037 <span class="comment"> * header files</span>
+<a name="l00038"></a>00038 <span class="comment"> */</span>
+<a name="l00039"></a>00039 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00041"></a>00041 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00042"></a>00042 <span class="comment"> *                        Function ANSI C prototypes</span>
+<a name="l00043"></a>00043 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00044"></a>00044 
+<a name="l00045"></a>00045 <span class="keywordtype">int</span> 
+<a name="l00046"></a>00046 sinfo_new_bp_search_noise (<span class="keyword">const</span> <span class="keywordtype">char</span>* plugin_id, 
+<a name="l00047"></a>00047                            cpl_parameterlist* config, 
+<a name="l00048"></a>00048                            cpl_frameset* <span class="keyword">set</span>, 
+<a name="l00049"></a>00049                            <span class="keyword">const</span> <span class="keywordtype">char</span>* out_name);
+<a name="l00050"></a>00050 
+<a name="l00051"></a>00051 <span class="preprocessor">#endif </span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__bp__noise__config_8c_source.html b/html/sinfo__bp__noise__config_8c_source.html
new file mode 100644
index 0000000..7018557
--- /dev/null
+++ b/html/sinfo__bp__noise__config_8c_source.html
@@ -0,0 +1,114 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_bp_noise_config.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_bp_noise_config.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_bp_noise_config.c,v 1.5 2008/01/17 07:54:04 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the CPL (Common Pipeline Library)</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
+<a name="l00007"></a>00007 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span>
+<a name="l00008"></a>00008 <span class="comment"> * License as published by the Free Software Foundation; either</span>
+<a name="l00009"></a>00009 <span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
+<a name="l00014"></a>00014 <span class="comment"> * Lesser General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
+<a name="l00017"></a>00017 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2008/01/17 07:54:04 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.5 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> */</span>
+<a name="l00026"></a>00026 
+<a name="l00027"></a>00027 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00029"></a>00029 <span class="preprocessor">#endif</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span> <span class="comment">/****************************************************************</span>
+<a name="l00031"></a>00031 <span class="comment">  *           Bad pixel search  (noise method)                  *</span>
+<a name="l00032"></a>00032 <span class="comment">  ****************************************************************/</span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include "sinfo_bp_noise_config.h"</span>
+<a name="l00052"></a>00052   <span class="comment">/* Bad pixel parameters */</span>
+<a name="l00053"></a>00053 
+<a name="l00054"></a>00054 <span class="keywordtype">void</span>
+<a name="l00055"></a><a class="code" href="group__sinfo__bad__pix__search.html#gaa86bb476f2328523607038df849c2beb">00055</a>  <a class="code" href="group__sinfo__bad__pix__search.html#gaa86bb476f2328523607038df849c2beb" title="Adds parameters for the spectrum extraction.">sinfo_bp_noise_config_add</a>(cpl_parameterlist *list)
+<a name="l00056"></a>00056 {
+<a name="l00057"></a>00057 
+<a name="l00058"></a>00058   cpl_parameter *p;
+<a name="l00059"></a>00059 
+<a name="l00060"></a>00060   <span class="keywordflow">if</span> (!list) {
+<a name="l00061"></a>00061     <span class="keywordflow">return</span>;
+<a name="l00062"></a>00062   }
+<a name="l00063"></a>00063 
+<a name="l00064"></a>00064 
+<a name="l00065"></a>00065 
+<a name="l00066"></a>00066 <span class="comment">/* factor of noise within which the pixels are used to fit a straight line </span>
+<a name="l00067"></a>00067 <span class="comment">   to the column intensity */</span>
+<a name="l00068"></a>00068   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.bp_noise.thresh_sigma_factor"</span>,
+<a name="l00069"></a>00069                   CPL_TYPE_DOUBLE,
+<a name="l00070"></a>00070                               <span class="stringliteral">"Threshold Sigma Factor: "</span>
+<a name="l00071"></a>00071                               <span class="stringliteral">"If the mean noise exceeds this "</span>
+<a name="l00072"></a>00072                               <span class="stringliteral">"threshold times the clean standard deviation "</span>
+<a name="l00073"></a>00073                               <span class="stringliteral">"of the clean mean the corresponding pixels "</span>
+<a name="l00074"></a>00074                               <span class="stringliteral">"are declared as bad "</span>,
+<a name="l00075"></a>00075                               <span class="stringliteral">"sinfoni.bp_noise"</span>,
+<a name="l00076"></a>00076                               10.);
+<a name="l00077"></a>00077 
+<a name="l00078"></a>00078   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
+<a name="l00079"></a>00079               <span class="stringliteral">"bp_noise-thresh_sigma_fct"</span>);
+<a name="l00080"></a>00080   cpl_parameterlist_append(list, p);
+<a name="l00081"></a>00081 
+<a name="l00082"></a>00082 <span class="comment">/* float </span>
+<a name="l00083"></a>00083 <span class="comment">     threshold used in the clean mean percentage of rejection used to reject </span>
+<a name="l00084"></a>00084 <span class="comment">     low and high frame */</span>
+<a name="l00085"></a>00085  <span class="comment">/* percentage of extreme pixel value to reject when calculating the mean </span>
+<a name="l00086"></a>00086 <span class="comment">    and stdev */</span>
+<a name="l00087"></a>00087   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.bp_noise.low_rejection"</span>,
+<a name="l00088"></a>00088                   CPL_TYPE_DOUBLE,
+<a name="l00089"></a>00089                               <span class="stringliteral">"low_rejection: "</span>
+<a name="l00090"></a>00090                               <span class="stringliteral">"percentage of rejected low intensity "</span>
+<a name="l00091"></a>00091                               <span class="stringliteral">"pixels before averaging"</span>,
+<a name="l00092"></a>00092                               <span class="stringliteral">"sinfoni.bp_noise"</span>,
+<a name="l00093"></a>00093                               10.,0.,100.);
+<a name="l00094"></a>00094 
+<a name="l00095"></a>00095   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"bp_noise-lo_rej"</span>);
+<a name="l00096"></a>00096   cpl_parameterlist_append(list, p);
+<a name="l00097"></a>00097 
+<a name="l00098"></a>00098   <span class="comment">/* float </span>
+<a name="l00099"></a>00099 <span class="comment">     threshold used in the clean mean percentage of rejection used to reject </span>
+<a name="l00100"></a>00100 <span class="comment">     low and high frame */</span>
+<a name="l00101"></a>00101  <span class="comment">/* percentage of extreme pixel value to reject when calculating the mean </span>
+<a name="l00102"></a>00102 <span class="comment">    and stdev */</span>
+<a name="l00103"></a>00103   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.bp_noise.high_rejection"</span>,
+<a name="l00104"></a>00104                   CPL_TYPE_DOUBLE,
+<a name="l00105"></a>00105                               <span class="stringliteral">"high_rejection: "</span>
+<a name="l00106"></a>00106                               <span class="stringliteral">"percentage of rejected high intensity "</span>
+<a name="l00107"></a>00107                               <span class="stringliteral">"pixels before averaging"</span>,
+<a name="l00108"></a>00108                               <span class="stringliteral">"sinfoni.bp_noise"</span>,
+<a name="l00109"></a>00109                               10.,0.,100.);
+<a name="l00110"></a>00110 
+<a name="l00111"></a>00111   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"bp_noise-hi_rej"</span>);
+<a name="l00112"></a>00112   cpl_parameterlist_append(list, p);
+<a name="l00113"></a>00113 
+<a name="l00114"></a>00114   <span class="keywordflow">return</span>;
+<a name="l00115"></a>00115 
+<a name="l00116"></a>00116 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__bp__noise__config_8h_source.html b/html/sinfo__bp__noise__config_8h_source.html
new file mode 100644
index 0000000..bf52879
--- /dev/null
+++ b/html/sinfo__bp__noise__config_8h_source.html
@@ -0,0 +1,53 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_bp_noise_config.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_bp_noise_config.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_bp_noise_config.h,v 1.2 2006/10/22 14:12:27 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the CPL (Common Pipeline Library)</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
+<a name="l00007"></a>00007 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span>
+<a name="l00008"></a>00008 <span class="comment"> * License as published by the Free Software Foundation; either</span>
+<a name="l00009"></a>00009 <span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
+<a name="l00014"></a>00014 <span class="comment"> * Lesser General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
+<a name="l00017"></a>00017 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2006/10/22 14:12:27 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.2 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> */</span>
+<a name="l00026"></a>00026 
+<a name="l00027"></a>00027  <span class="comment">/****************************************************************</span>
+<a name="l00028"></a>00028 <span class="comment">  *           Bad pixel search  (noise method)                  *</span>
+<a name="l00029"></a>00029 <span class="comment">  ****************************************************************/</span>
+<a name="l00030"></a>00030 <span class="preprocessor">#ifndef SINFO_BP_NOISE_CONFIG_H</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_BP_NOISE_CONFIG_H</span>
+<a name="l00032"></a>00032 <span class="preprocessor"></span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include "cpl.h"</span>   
+<a name="l00034"></a>00034 
+<a name="l00035"></a>00035 <span class="keywordtype">void</span> <a class="code" href="group__sinfo__bad__pix__search.html#gaa86bb476f2328523607038df849c2beb" title="Adds parameters for the spectrum extraction.">sinfo_bp_noise_config_add</a>(cpl_parameterlist *list);
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__bp__norm_8c_source.html b/html/sinfo__bp__norm_8c_source.html
new file mode 100644
index 0000000..f66d7fa
--- /dev/null
+++ b/html/sinfo__bp__norm_8c_source.html
@@ -0,0 +1,363 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_bp_norm.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_bp_norm.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name    :       sinfo_bp_norm.c</span>
+<a name="l00022"></a>00022 <span class="comment">   Author       :    J. Schreiber</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on   :    May 5, 2003</span>
+<a name="l00024"></a>00024 <span class="comment">   Description  :    Different methods for searching for bad pixels</span>
+<a name="l00025"></a>00025 <span class="comment">                        used in the recipe sinfo_rec_mflat </span>
+<a name="l00026"></a>00026 <span class="comment"></span>
+<a name="l00027"></a>00027 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00028"></a>00028 
+<a name="l00029"></a>00029 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00031"></a>00031 <span class="preprocessor">#endif</span>
+<a name="l00032"></a>00032 <span class="preprocessor"></span><span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                                Includes</span>
+<a name="l00034"></a>00034 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 <span class="preprocessor">#include "sinfo_bp_norm.h"</span>
+<a name="l00036"></a>00036 <span class="preprocessor">#include "sinfo_image_ops.h"</span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include "sinfo_detlin.h"</span>
+<a name="l00038"></a>00038 <span class="preprocessor">#include "sinfo_badnorm_ini_by_cpl.h"</span>
+<a name="l00039"></a>00039 <span class="preprocessor">#include "sinfo_baddist_ini_by_cpl.h"</span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include "sinfo_pro_save.h"</span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include "sinfo_functions.h"</span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include "sinfo_pro_types.h"</span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include "sinfo_hidden.h"</span>
+<a name="l00044"></a>00044 <span class="preprocessor">#include "sinfo_error.h"</span>
+<a name="l00045"></a>00045 <span class="preprocessor">#include "sinfo_utils_wrappers.h"</span>
+<a name="l00052"></a>00052 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00053"></a>00053 <span class="comment">                                Defines</span>
+<a name="l00054"></a>00054 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00055"></a>00055 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00056"></a>00056 <span class="comment">                             Function Definitions</span>
+<a name="l00057"></a>00057 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00096"></a>00096 <span class="keywordtype">int</span> 
+<a name="l00097"></a>00097 sinfo_new_bp_search_normal (<span class="keyword">const</span> <span class="keywordtype">char</span>* plugin_id,
+<a name="l00098"></a>00098                      cpl_parameterlist* config, 
+<a name="l00099"></a>00099                      cpl_frameset* sof, 
+<a name="l00100"></a>00100                      cpl_frameset* ref_set, 
+<a name="l00101"></a>00101                      <span class="keyword">const</span> <span class="keywordtype">char</span>* procatg)
+<a name="l00102"></a>00102 {
+<a name="l00103"></a>00103   bad_config * cfg =NULL;
+<a name="l00104"></a>00104   cpl_imagelist * image_list =NULL;
+<a name="l00105"></a>00105   cpl_image ** med=NULL ;
+<a name="l00106"></a>00106   cpl_image * medImage =NULL;
+<a name="l00107"></a>00107   cpl_image * medIm =NULL;
+<a name="l00108"></a>00108   cpl_image * colImage =NULL;
+<a name="l00109"></a>00109   cpl_image * compImage =NULL;
+<a name="l00110"></a>00110   cpl_image * maskImage =NULL;
+<a name="l00111"></a>00111   cpl_image * threshIm =NULL;
+<a name="l00112"></a>00112 
+<a name="l00113"></a>00113 
+<a name="l00114"></a>00114   Stats * stats =NULL;
+<a name="l00115"></a>00115 
+<a name="l00116"></a>00116   cpl_parameter *p=NULL;             
+<a name="l00117"></a>00117 
+<a name="l00118"></a>00118   <span class="keywordtype">int</span> no=0;
+<a name="l00119"></a>00119   <span class="keywordtype">float</span> lo_cut=0.;
+<a name="l00120"></a>00120   <span class="keywordtype">float</span> hi_cut=0.;
+<a name="l00121"></a>00121 
+<a name="l00122"></a>00122   <span class="keywordtype">int</span> i=0;
+<a name="l00123"></a>00123   <span class="keywordtype">int</span> n=0;
+<a name="l00124"></a>00124   <span class="keywordtype">int</span> half_box_size=0 ;
+<a name="l00125"></a>00125 
+<a name="l00126"></a>00126   cpl_frameset* raw=NULL;
+<a name="l00127"></a>00127   cpl_table* qclog_tbl=NULL;
+<a name="l00128"></a>00128   <span class="keywordtype">char</span> key_value[FILE_NAME_SZ];
+<a name="l00129"></a>00129 
+<a name="l00130"></a>00130   <span class="comment">/* parse the file names and parameters to the bad_config data structure </span>
+<a name="l00131"></a>00131 <span class="comment">       cfg */</span>
+<a name="l00132"></a>00132  
+<a name="l00133"></a>00133   sinfo_check_rec_status(0);
+<a name="l00134"></a>00134   check_nomsg(raw=cpl_frameset_new());
+<a name="l00135"></a>00135   sinfo_check_rec_status(1);
+<a name="l00136"></a>00136   <span class="keywordflow">if</span> (strcmp(procatg,PRO_BP_MAP_NO) == 0) {
+<a name="l00137"></a>00137     cknull(cfg = sinfo_parse_cpl_input_badnorm(config,sof,procatg,&raw),
+<a name="l00138"></a>00138        <span class="stringliteral">"could not parse cpl input!"</span>);
+<a name="l00139"></a>00139   } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(procatg,PRO_BP_MAP_DI) == 0) {
+<a name="l00140"></a>00140     cknull(cfg = sinfo_parse_cpl_input_baddist(config,sof,procatg,&raw),
+<a name="l00141"></a>00141        <span class="stringliteral">"could not parse cpl input!"</span>);
+<a name="l00142"></a>00142   } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(procatg,PRO_DEFAULT) == 0) {
+<a name="l00143"></a>00143     cknull(cfg = sinfo_parse_cpl_input_badnorm(config,sof,procatg,&raw),
+<a name="l00144"></a>00144        <span class="stringliteral">"could not parse cpl input!"</span>);
+<a name="l00145"></a>00145   } <span class="keywordflow">else</span> {
+<a name="l00146"></a>00146     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Error: PRO.CATG %s, not supported!"</span>,procatg);
+<a name="l00147"></a>00147     <span class="keywordflow">goto</span> cleanup;
+<a name="l00148"></a>00148   }
+<a name="l00149"></a>00149   sinfo_check_rec_status(2);
+<a name="l00150"></a>00150   <span class="comment">/* take a clean mean of the frames */</span>
+<a name="l00151"></a>00151   sinfo_msg(<span class="stringliteral">"Takes a clean mean of the frames"</span>);
+<a name="l00152"></a>00152 
+<a name="l00153"></a>00153   check_nomsg(image_list = cpl_imagelist_new());
+<a name="l00154"></a>00154   sinfo_check_rec_status(3);
+<a name="l00155"></a>00155 
+<a name="l00156"></a>00156   <span class="keywordflow">for</span> ( i = 0 ; i < cfg->nframes ; i++ ){
+<a name="l00157"></a>00157     <span class="keywordflow">if</span>(sinfo_is_fits_file (cfg->framelist[i]) != 1) {
+<a name="l00158"></a>00158       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Input file %s is not FITS"</span>,cfg->framelist[i] );
+<a name="l00159"></a>00159       <span class="keywordflow">goto</span> cleanup;
+<a name="l00160"></a>00160     }
+<a name="l00161"></a>00161 
+<a name="l00162"></a>00162     check_nomsg(cpl_imagelist_set(image_list, 
+<a name="l00163"></a>00163                 cpl_image_load(cfg->framelist[i],CPL_TYPE_FLOAT,0,0),i));
+<a name="l00164"></a>00164 
+<a name="l00165"></a>00165   }
+<a name="l00166"></a>00166 
+<a name="l00167"></a>00167   <span class="comment">/* finally take the average image of the cube by </span>
+<a name="l00168"></a>00168 <span class="comment">     rejecting the extreme values */</span>
+<a name="l00169"></a>00169 
+<a name="l00170"></a>00170   check_nomsg(no=cpl_imagelist_get_size(image_list));
+<a name="l00171"></a>00171   lo_cut=(floor)(cfg->loReject*no+0.5);
+<a name="l00172"></a>00172   hi_cut=(floor)(cfg->hiReject*no+0.5);
+<a name="l00173"></a>00173   cknull(medImage=cpl_imagelist_collapse_minmax_create(image_list,
+<a name="l00174"></a>00174                                                        lo_cut,
+<a name="l00175"></a>00175                                                        hi_cut),
+<a name="l00176"></a>00176      <span class="stringliteral">"error in sinfo_average_with_rejection"</span>) ;
+<a name="l00177"></a>00177  
+<a name="l00178"></a>00178   <span class="comment">/* free memory */</span>
+<a name="l00179"></a>00179   sinfo_free_imagelist(&image_list) ;
+<a name="l00180"></a>00180 
+<a name="l00181"></a>00181   <span class="comment">/*----------------------------------------------</span>
+<a name="l00182"></a>00182 <span class="comment">   * remove the intensity tilt from every column</span>
+<a name="l00183"></a>00183 <span class="comment">   * and compute the standard deviation on a rectangular zone</span>
+<a name="l00184"></a>00184 <span class="comment">   */</span>
+<a name="l00185"></a>00185   cknull(medIm = sinfo_new_thresh_image(medImage, cfg->mincut, cfg->maxcut),
+<a name="l00186"></a>00186       <span class="stringliteral">"error sinfo_new_thresh_image"</span>);
+<a name="l00187"></a>00187   cknull(colImage  = sinfo_new_col_tilt( medIm, cfg->sigmaFactor ),
+<a name="l00188"></a>00188         <span class="stringliteral">"sinfo_colTilt failed"</span> ) ;
+<a name="l00189"></a>00189 
+<a name="l00190"></a>00190 
+<a name="l00191"></a>00191   cknull(stats = sinfo_new_image_stats_on_rectangle(colImage, 
+<a name="l00192"></a>00192                             cfg->loReject, 
+<a name="l00193"></a>00193                             cfg->hiReject,
+<a name="l00194"></a>00194                             cfg->llx,
+<a name="l00195"></a>00195                             cfg->lly,
+<a name="l00196"></a>00196                             cfg->urx,
+<a name="l00197"></a>00197                             cfg->ury),
+<a name="l00198"></a>00198      <span class="stringliteral">" sinfo_get_image_stats_on_vig failed"</span>) ;
+<a name="l00199"></a>00199   <span class="keywordflow">if</span>(stats!=NULL) {
+<a name="l00200"></a>00200      sinfo_msg(<span class="stringliteral">"Clean stdev: %f\n"</span>, stats->cleanstdev ) ;
+<a name="l00201"></a>00201      sinfo_msg(<span class="stringliteral">"Clean mean: %f\n"</span>,  stats->cleanmean ) ;
+<a name="l00202"></a>00202   }
+<a name="l00203"></a>00203     
+<a name="l00204"></a>00204 
+<a name="l00205"></a>00205 
+<a name="l00206"></a>00206   <span class="comment">/*</span>
+<a name="l00207"></a>00207 <span class="comment">    cknull_nomsg(qclog_tbl = sinfo_qclog_init());</span>
+<a name="l00208"></a>00208 <span class="comment">    ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC ICTILT STDEV",</span>
+<a name="l00209"></a>00209 <span class="comment">                                     stats->cleanstdev,</span>
+<a name="l00210"></a>00210 <span class="comment">                                     "Intensity column clean stdev","%g"));</span>
+<a name="l00211"></a>00211 <span class="comment"> </span>
+<a name="l00212"></a>00212 <span class="comment">    ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC ICTILT MEAN",</span>
+<a name="l00213"></a>00213 <span class="comment">                                     stats->cleanmean,</span>
+<a name="l00214"></a>00214 <span class="comment">                                     "Intensity column clean mean","%g"));</span>
+<a name="l00215"></a>00215 <span class="comment"></span>
+<a name="l00216"></a>00216 <span class="comment">    ck0(sinfo_pro_save_ima(colImage,raw,sof,</span>
+<a name="l00217"></a>00217 <span class="comment">                           (char*) BP_NORM_INT_COL_TILT_CORR_OUT_FILENAME,</span>
+<a name="l00218"></a>00218 <span class="comment">                           PRO_INT_COL_TILT_COR,qclog_tbl,plugin_id,config),</span>
+<a name="l00219"></a>00219 <span class="comment">                           "cannot save ima %s",</span>
+<a name="l00220"></a>00220 <span class="comment">                           BP_NORM_INT_COL_TILT_CORR_OUT_FILENAME);</span>
+<a name="l00221"></a>00221 <span class="comment"></span>
+<a name="l00222"></a>00222 <span class="comment">    sinfo_free_table(&qclog_tbl);</span>
+<a name="l00223"></a>00223 <span class="comment">  */</span>
+<a name="l00224"></a>00224     
+<a name="l00225"></a>00225   <span class="comment">/* indicate pixels with great deviations from the clean mean as bad */</span>
+<a name="l00226"></a>00226   <span class="keywordflow">if</span> (cfg->threshInd == 1) {
+<a name="l00227"></a>00227     cknull(threshIm = sinfo_new_thresh_image(colImage, 
+<a name="l00228"></a>00228                       stats->cleanmean-cfg->meanfactor*stats->cleanstdev, 
+<a name="l00229"></a>00229                       stats->cleanmean+cfg->meanfactor*stats->cleanstdev),
+<a name="l00230"></a>00230        <span class="stringliteral">" sinfo_threshImage failed"</span> ) ;
+<a name="l00231"></a>00231 
+<a name="l00232"></a>00232   }
+<a name="l00233"></a>00233 
+<a name="l00234"></a>00234   <span class="keywordflow">if</span> (cfg->threshInd == 0 ) {
+<a name="l00235"></a>00235     threshIm = colImage ;
+<a name="l00236"></a>00236   }
+<a name="l00237"></a>00237   <span class="comment">/* AMO here invalid fread? */</span>
+<a name="l00238"></a>00238   med = (cpl_image**) cpl_calloc (cfg -> iterations, <span class="keyword">sizeof</span>(cpl_image*)) ;
+<a name="l00239"></a>00239     
+<a name="l00240"></a>00240 
+<a name="l00241"></a>00241   <span class="comment">/* filter iteratively the images by a sinfo_median filter of the nearest </span>
+<a name="l00242"></a>00242 <span class="comment">     neighbors under the condition of a deviation greater than a factor </span>
+<a name="l00243"></a>00243 <span class="comment">     times the standard deviation */</span>
+<a name="l00244"></a>00244   sinfo_msg(<span class="stringliteral">"Apply sinfo_median filter on pixel nearest neighbors"</span>);
+<a name="l00245"></a>00245   <span class="keywordflow">if</span> (cfg->methodInd == 1) {
+<a name="l00246"></a>00246     <span class="keywordflow">if</span> (cfg->factor>0) {
+<a name="l00247"></a>00247       cknull(med[0]=sinfo_new_median_image(threshIm,
+<a name="l00248"></a>00248                                            -cfg->factor*stats->cleanstdev),
+<a name="l00249"></a>00249                                            <span class="stringliteral">" sinfo_medianImage failed (1)"</span> ) ;
+<a name="l00250"></a>00250 
+<a name="l00251"></a>00251       <span class="keywordflow">for</span> ( i = 0 ; i < cfg->iterations - 1 ; i++ ) {
+<a name="l00252"></a>00252     cknull(med[i+1]=sinfo_new_median_image(med[i], 
+<a name="l00253"></a>00253                                                -cfg->factor*stats->cleanstdev),
+<a name="l00254"></a>00254                                                <span class="stringliteral">"sinfo_medianImage failed (2)"</span>);
+<a name="l00255"></a>00255       }
+<a name="l00256"></a>00256 
+<a name="l00257"></a>00257     } <span class="keywordflow">else</span> {
+<a name="l00258"></a>00258       cknull(med[0] = sinfo_new_median_image(threshIm, -cfg->factor),
+<a name="l00259"></a>00259          <span class="stringliteral">" sinfo_medianImage failed (1)"</span> ) ;
+<a name="l00260"></a>00260 
+<a name="l00261"></a>00261       <span class="keywordflow">for</span> ( i = 0 ; i < cfg->iterations - 1 ; i++ ) {
+<a name="l00262"></a>00262     cknull(med[i+1] = sinfo_new_median_image(med[i], -cfg->factor),
+<a name="l00263"></a>00263            <span class="stringliteral">" sinfo_medianImage failed (%d)"</span>,i ) ;
+<a name="l00264"></a>00264       }
+<a name="l00265"></a>00265     }
+<a name="l00266"></a>00266   } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (cfg->methodInd == 2) {
+<a name="l00267"></a>00267 
+<a name="l00268"></a>00268     cknull(med[0] = sinfo_new_abs_dist_image(threshIm, -cfg->factor),
+<a name="l00269"></a>00269        <span class="stringliteral">" sinfo_absDistImage failed (1)"</span> ) ;
+<a name="l00270"></a>00270 
+<a name="l00271"></a>00271     <span class="keywordflow">for</span> ( i = 0 ; i < cfg->iterations -1 ; i++ ) {
+<a name="l00272"></a>00272       cknull(med[i+1] = sinfo_new_abs_dist_image(med[i], -cfg->factor),
+<a name="l00273"></a>00273          <span class="stringliteral">" sinfo_absDistImage failed (2)"</span> ) ;
+<a name="l00274"></a>00274     }
+<a name="l00275"></a>00275   } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (cfg->methodInd == 3) {
+<a name="l00276"></a>00276     cknull(med[0] = sinfo_new_mean_image_in_spec(threshIm, 
+<a name="l00277"></a>00277                                            -cfg->factor*stats->cleanstdev),
+<a name="l00278"></a>00278                                        <span class="stringliteral">"sinfo_meanImageInSpec failed (1)"</span>);
+<a name="l00279"></a>00279     <span class="keywordflow">for</span> ( i = 0 ; i < cfg->iterations - 1 ; i++ ) {
+<a name="l00280"></a>00280       cknull(med[i+1] = sinfo_new_mean_image_in_spec(med[i], 
+<a name="l00281"></a>00281                                                -cfg->factor*stats->cleanstdev),
+<a name="l00282"></a>00282                                          <span class="stringliteral">" sinfo_meanImageInSpec failed (2)"</span>);
+<a name="l00283"></a>00283     }
+<a name="l00284"></a>00284   } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (cfg->methodInd == 4) {
+<a name="l00285"></a>00285     half_box_size = (cfg->urx - cfg->llx) / 2 ;
+<a name="l00286"></a>00286     cknull(med[0] = sinfo_new_local_median_image(threshIm, 
+<a name="l00287"></a>00287                        -cfg->factor,
+<a name="l00288"></a>00288                        cfg->loReject,
+<a name="l00289"></a>00289                        cfg->hiReject,
+<a name="l00290"></a>00290                        half_box_size),
+<a name="l00291"></a>00291        <span class="stringliteral">" sinfo_localMedianImage failed (1)"</span> ) ;
+<a name="l00292"></a>00292 
+<a name="l00293"></a>00293     <span class="keywordflow">for</span> ( i = 0 ; i < cfg->iterations - 1 ; i++ ) {
+<a name="l00294"></a>00294       cknull(med[i+1] = sinfo_new_local_median_image(med[i],
+<a name="l00295"></a>00295                            -cfg->factor,
+<a name="l00296"></a>00296                            cfg->loReject,
+<a name="l00297"></a>00297                            cfg->hiReject,
+<a name="l00298"></a>00298                            half_box_size),
+<a name="l00299"></a>00299          <span class="stringliteral">" sinfo_localMedianImage failed (2)"</span> ) ;
+<a name="l00300"></a>00300     }
+<a name="l00301"></a>00301   } <span class="keywordflow">else</span> {
+<a name="l00302"></a>00302     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" wrong indicator methodInd !"</span> ) ;
+<a name="l00303"></a>00303     <span class="keywordflow">goto</span> cleanup ;
+<a name="l00304"></a>00304   }
+<a name="l00305"></a>00305 
+<a name="l00306"></a>00306   <span class="comment">/* compare the filtered image with the input image */</span>
+<a name="l00307"></a>00307   cknull(compImage = sinfo_new_compare_images(threshIm, 
+<a name="l00308"></a>00308                                               med[cfg->iterations - 1], 
+<a name="l00309"></a>00309                                               medImage),
+<a name="l00310"></a>00310                                               <span class="stringliteral">" sinfo_compareImages failed"</span> ) ;
+<a name="l00311"></a>00311     
+<a name="l00312"></a>00312   <span class="comment">/* generate the bad pixel mask */</span>
+<a name="l00313"></a>00313   sinfo_msg(<span class="stringliteral">"Generates bad pixel map"</span>);
+<a name="l00314"></a>00314   cknull(maskImage = sinfo_new_promote_image_to_mask( compImage, &n ),
+<a name="l00315"></a>00315      <span class="stringliteral">" error in sinfo_promoteImageToMask"</span> ) ;
+<a name="l00316"></a>00316   sinfo_msg(<span class="stringliteral">"No of bad pixels:  %d\n"</span>, n ) ;
+<a name="l00317"></a>00317 
+<a name="l00318"></a>00318   cknull_nomsg(qclog_tbl = sinfo_qclog_init());
+<a name="l00319"></a>00319   check_nomsg(p = cpl_parameterlist_find(config, <span class="stringliteral">"sinfoni.bp.method"</span>));
+<a name="l00320"></a>00320   snprintf(key_value, MAX_NAME_SIZE-1,<span class="stringliteral">"%s"</span>, cpl_parameter_get_string(p));
+<a name="l00321"></a>00321 
+<a name="l00322"></a>00322   ck0_nomsg(sinfo_qclog_add_string(qclog_tbl,<span class="stringliteral">"QC BP-MAP METHOD"</span>,
+<a name="l00323"></a>00323                                    key_value,<span class="stringliteral">"BP search method"</span>,<span class="stringliteral">"%s"</span>));
+<a name="l00324"></a>00324 
+<a name="l00325"></a>00325   ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,<span class="stringliteral">"QC BP-MAP NBADPIX"</span>,n,
+<a name="l00326"></a>00326                                            <span class="stringliteral">"No of bad pixels"</span>,<span class="stringliteral">"%d"</span>));
+<a name="l00327"></a>00327 
+<a name="l00328"></a>00328     ck0(sinfo_pro_save_ima(maskImage,ref_set,sof,cfg->outName,
+<a name="l00329"></a>00329                procatg,qclog_tbl,plugin_id,config),
+<a name="l00330"></a>00330     <span class="stringliteral">"cannot save ima %s"</span>, cfg->outName);
+<a name="l00331"></a>00331 
+<a name="l00332"></a>00332   sinfo_free_table(&qclog_tbl);
+<a name="l00333"></a>00333   sinfo_free_image(&maskImage);
+<a name="l00334"></a>00334   sinfo_free_image(&compImage);
+<a name="l00335"></a>00335   <span class="keywordflow">if</span> (med != NULL) {
+<a name="l00336"></a>00336     <span class="keywordflow">for</span> ( i = 0 ; i < cfg->iterations ; i++ ) {
+<a name="l00337"></a>00337       <span class="keywordflow">if</span>(med[i] != NULL) {
+<a name="l00338"></a>00338     cpl_image_delete(med[i]) ;
+<a name="l00339"></a>00339     med[i]=NULL;
+<a name="l00340"></a>00340       }
+<a name="l00341"></a>00341     }
+<a name="l00342"></a>00342     cpl_free(med) ; 
+<a name="l00343"></a>00343     med=NULL;
+<a name="l00344"></a>00344   }
+<a name="l00345"></a>00345   <span class="keywordflow">if</span> (stats != NULL) {
+<a name="l00346"></a>00346     cpl_free(stats) ;
+<a name="l00347"></a>00347     stats=NULL;
+<a name="l00348"></a>00348   }
+<a name="l00349"></a>00349   sinfo_free_image(&medIm);
+<a name="l00350"></a>00350   sinfo_free_image(&medImage);
+<a name="l00351"></a>00351   sinfo_free_image(&colImage);
+<a name="l00352"></a>00352   <span class="keywordflow">if</span> (cfg->threshInd == 1 ) {
+<a name="l00353"></a>00353     sinfo_free_image(&threshIm);
+<a name="l00354"></a>00354   }
+<a name="l00355"></a>00355   sinfo_badnorm_free(&cfg) ;
+<a name="l00356"></a>00356   sinfo_free_frameset(&raw);
+<a name="l00357"></a>00357   <span class="keywordflow">return</span> 0;
+<a name="l00358"></a>00358 
+<a name="l00359"></a>00359  cleanup:
+<a name="l00360"></a>00360 
+<a name="l00361"></a>00361 
+<a name="l00362"></a>00362   <span class="keywordflow">if</span> (med != NULL) {
+<a name="l00363"></a>00363     <span class="keywordflow">for</span> ( i = 0 ; i < cfg->iterations ; i++ ) {
+<a name="l00364"></a>00364       <span class="keywordflow">if</span>(med[i] != NULL) {
+<a name="l00365"></a>00365     cpl_image_delete(med[i]) ;
+<a name="l00366"></a>00366     med[i]=NULL;
+<a name="l00367"></a>00367       }
+<a name="l00368"></a>00368     }
+<a name="l00369"></a>00369     cpl_free(med) ; 
+<a name="l00370"></a>00370          med=NULL;
+<a name="l00371"></a>00371   }
+<a name="l00372"></a>00372   sinfo_free_image(&compImage) ;
+<a name="l00373"></a>00373   sinfo_free_image(&maskImage) ;
+<a name="l00374"></a>00374   sinfo_free_image(&threshIm) ;
+<a name="l00375"></a>00375   sinfo_free_table(&qclog_tbl);
+<a name="l00376"></a>00376   sinfo_free_image(&threshIm) ;
+<a name="l00377"></a>00377   <span class="keywordflow">if</span> (stats != NULL) {
+<a name="l00378"></a>00378     cpl_free(stats) ;
+<a name="l00379"></a>00379     stats=NULL;
+<a name="l00380"></a>00380   }
+<a name="l00381"></a>00381   sinfo_free_image(&medIm);
+<a name="l00382"></a>00382   sinfo_free_image(&medImage);
+<a name="l00383"></a>00383   sinfo_free_image(&colImage);
+<a name="l00384"></a>00384   sinfo_free_imagelist(&image_list) ;
+<a name="l00385"></a>00385   sinfo_free_frameset(&raw);
+<a name="l00386"></a>00386   sinfo_badnorm_free(&cfg);
+<a name="l00387"></a>00387 
+<a name="l00388"></a>00388   <span class="keywordflow">return</span> -1;
+<a name="l00389"></a>00389 
+<a name="l00390"></a>00390 }
+<a name="l00391"></a>00391 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__bp__norm_8h_source.html b/html/sinfo__bp__norm_8h_source.html
new file mode 100644
index 0000000..47b5143
--- /dev/null
+++ b/html/sinfo__bp__norm_8h_source.html
@@ -0,0 +1,70 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_bp_norm.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_bp_norm.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#ifndef SINFO_BP_NORM_H</span>
+<a name="l00002"></a>00002 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_BP_NORM_H</span>
+<a name="l00003"></a>00003 <span class="preprocessor"></span><span class="comment">/*</span>
+<a name="l00004"></a>00004 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00005"></a>00005 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00006"></a>00006 <span class="comment"> *</span>
+<a name="l00007"></a>00007 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00008"></a>00008 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00009"></a>00009 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00010"></a>00010 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00011"></a>00011 <span class="comment"> *</span>
+<a name="l00012"></a>00012 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00013"></a>00013 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00014"></a>00014 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00015"></a>00015 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00016"></a>00016 <span class="comment"> *</span>
+<a name="l00017"></a>00017 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00018"></a>00018 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00019"></a>00019 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00020"></a>00020 <span class="comment"> */</span>
+<a name="l00021"></a>00021 <span class="comment">/*******************************************************************************</span>
+<a name="l00022"></a>00022 <span class="comment">* E.S.O. - VLT project</span>
+<a name="l00023"></a>00023 <span class="comment">*</span>
+<a name="l00024"></a>00024 <span class="comment">* "@(#) $Id: sinfo_bp_norm.h,v 1.4 2007/09/21 14:13:43 amodigli Exp $"</span>
+<a name="l00025"></a>00025 <span class="comment">*</span>
+<a name="l00026"></a>00026 <span class="comment">* who       when      what</span>
+<a name="l00027"></a>00027 <span class="comment">* --------  --------  ----------------------------------------------</span>
+<a name="l00028"></a>00028 <span class="comment">* schreib  06/05/03  created</span>
+<a name="l00029"></a>00029 <span class="comment">*/</span>
+<a name="l00030"></a>00030 
+<a name="l00031"></a>00031 <span class="comment">/************************************************************************</span>
+<a name="l00032"></a>00032 <span class="comment"> * bp_norm.h</span>
+<a name="l00033"></a>00033 <span class="comment"> * routine to search for bad pixels</span>
+<a name="l00034"></a>00034 <span class="comment"> *----------------------------------------------------------------------</span>
+<a name="l00035"></a>00035 <span class="comment"> */</span>
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="comment">/*</span>
+<a name="l00038"></a>00038 <span class="comment"> * header files</span>
+<a name="l00039"></a>00039 <span class="comment"> */</span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00042"></a>00042 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00043"></a>00043 <span class="comment"> *                        Function ANSI C prototypes</span>
+<a name="l00044"></a>00044 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00045"></a>00045 
+<a name="l00046"></a>00046 <span class="keywordtype">int</span> 
+<a name="l00047"></a>00047 sinfo_new_bp_search_normal (<span class="keyword">const</span> <span class="keywordtype">char</span>* plugin_id, 
+<a name="l00048"></a>00048                             cpl_parameterlist* config, 
+<a name="l00049"></a>00049                             cpl_frameset* <span class="keyword">set</span>, 
+<a name="l00050"></a>00050                             cpl_frameset* ref_set, 
+<a name="l00051"></a>00051                             <span class="keyword">const</span> <span class="keywordtype">char</span>* procatg);
+<a name="l00052"></a>00052 <span class="preprocessor">#endif</span>
+<a name="l00053"></a>00053 <span class="preprocessor"></span>
+<a name="l00054"></a>00054 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__bp__norm__config_8c_source.html b/html/sinfo__bp__norm__config_8c_source.html
new file mode 100644
index 0000000..59cb143
--- /dev/null
+++ b/html/sinfo__bp__norm__config_8c_source.html
@@ -0,0 +1,271 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_bp_norm_config.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_bp_norm_config.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_bp_norm_config.c,v 1.4 2007/06/06 07:10:45 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the CPL (Common Pipeline Library)</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
+<a name="l00007"></a>00007 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span>
+<a name="l00008"></a>00008 <span class="comment"> * License as published by the Free Software Foundation; either</span>
+<a name="l00009"></a>00009 <span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
+<a name="l00014"></a>00014 <span class="comment"> * Lesser General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
+<a name="l00017"></a>00017 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2007/06/06 07:10:45 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.4 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> */</span>
+<a name="l00026"></a>00026 
+<a name="l00027"></a>00027 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00029"></a>00029 <span class="preprocessor">#endif</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span> <span class="comment">/****************************************************************</span>
+<a name="l00031"></a>00031 <span class="comment">  *           Bad pixel search  (normal method)                  *</span>
+<a name="l00032"></a>00032 <span class="comment">  ****************************************************************/</span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include "sinfo_bp_norm_config.h"</span>
+<a name="l00052"></a>00052   <span class="comment">/* Bad pixel parameters */</span>
+<a name="l00053"></a>00053 
+<a name="l00054"></a>00054 <span class="keywordtype">void</span>
+<a name="l00055"></a><a class="code" href="group__sinfo__bad__pix__search.html#ga6f49eed82217a86089ff7f23465ae3e0">00055</a>  <a class="code" href="group__sinfo__bad__pix__search.html#ga6f49eed82217a86089ff7f23465ae3e0" title="Adds parameters for the spectrum extraction.">sinfo_bp_norm_config_add</a>(cpl_parameterlist *list)
+<a name="l00056"></a>00056 {
+<a name="l00057"></a>00057   cpl_parameter *p;
+<a name="l00058"></a>00058 
+<a name="l00059"></a>00059   <span class="keywordflow">if</span> (!list) {
+<a name="l00060"></a>00060     <span class="keywordflow">return</span>;
+<a name="l00061"></a>00061   }
+<a name="l00062"></a>00062 
+<a name="l00063"></a>00063 
+<a name="l00064"></a>00064  
+<a name="l00065"></a>00065 
+<a name="l00066"></a>00066 <span class="comment">/* factor of noise within which the pixels are used to fit a straight line </span>
+<a name="l00067"></a>00067 <span class="comment">   to the column intensity */</span>
+<a name="l00068"></a>00068   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.bp_norm.sigma_factor"</span>,
+<a name="l00069"></a>00069                   CPL_TYPE_DOUBLE,
+<a name="l00070"></a>00070                               <span class="stringliteral">"Threshold Sigma Factor: "</span>
+<a name="l00071"></a>00071                               <span class="stringliteral">"to remove the column intensity tilt only "</span>
+<a name="l00072"></a>00072                               <span class="stringliteral">"pixels which lie within a defined noise"</span>
+<a name="l00073"></a>00073                               <span class="stringliteral">"limit are used to fit a straight line"</span>,
+<a name="l00074"></a>00074                               <span class="stringliteral">"sinfoni.bp_noise"</span>,
+<a name="l00075"></a>00075                               5.0);
+<a name="l00076"></a>00076 
+<a name="l00077"></a>00077   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"bp_norm-s_factor"</span>);
+<a name="l00078"></a>00078   cpl_parameterlist_append(list, p);
+<a name="l00079"></a>00079 
+<a name="l00080"></a>00080   <span class="comment">/* bad pixel search determination method */</span>
+<a name="l00081"></a>00081  p = cpl_parameter_new_enum(<span class="stringliteral">"sinfoni.bp_norm.method_index"</span>,
+<a name="l00082"></a>00082                   CPL_TYPE_INT,
+<a name="l00083"></a>00083                               <span class="stringliteral">"Bad pixel Method Index"</span>
+<a name="l00084"></a>00084                               <span class="stringliteral">"1: median of nearest neighbors,"</span>
+<a name="l00085"></a>00085                               <span class="stringliteral">"2: absolute distances check, "</span>
+<a name="l00086"></a>00086                               <span class="stringliteral">"3: mean of nearest spectral neighbors"</span>,
+<a name="l00087"></a>00087                               <span class="stringliteral">"sinfoni.bp_norm"</span>,
+<a name="l00088"></a>00088                               1,
+<a name="l00089"></a>00089                               3,1,2,3);
+<a name="l00090"></a>00090 
+<a name="l00091"></a>00091   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"bp_norm-method_ind"</span>);
+<a name="l00092"></a>00092   cpl_parameterlist_append(list, p);
+<a name="l00093"></a>00093 
+<a name="l00094"></a>00094   <span class="comment">/* factor of calculated standard deviation beyond which the deviation </span>
+<a name="l00095"></a>00095 <span class="comment">     of a pixel value from the median of the 8 nearest neighbors declares </span>
+<a name="l00096"></a>00096 <span class="comment">     a pixel as bad */</span>
+<a name="l00097"></a>00097   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.bp_norm.factor"</span>,
+<a name="l00098"></a>00098                   CPL_TYPE_DOUBLE,
+<a name="l00099"></a>00099                               <span class="stringliteral">"Factor: "</span>
+<a name="l00100"></a>00100            <span class="stringliteral">"if |pixel - median| > factor * standard deviation -> "</span>
+<a name="l00101"></a>00101                               <span class="stringliteral">"then the pixel value is replaced by "</span>
+<a name="l00102"></a>00102                               <span class="stringliteral">"the median of the 8 nearest neighbors"</span>,
+<a name="l00103"></a>00103                               <span class="stringliteral">"sinfoni.bp_norm"</span>,
+<a name="l00104"></a>00104                               10.0);
+<a name="l00105"></a>00105 
+<a name="l00106"></a>00106   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"bp_norm-fct"</span>);
+<a name="l00107"></a>00107   cpl_parameterlist_append(list, p);
+<a name="l00108"></a>00108 
+<a name="l00109"></a>00109  <span class="comment">/* no of iterations to find bad pix clusters */</span>
+<a name="l00110"></a>00110   <span class="comment">/* number of iterations of sinfo_median filter */</span>
+<a name="l00111"></a>00111   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.bp_norm.iterations"</span>,
+<a name="l00112"></a>00112                   CPL_TYPE_INT,
+<a name="l00113"></a>00113                               <span class="stringliteral">"Iterations: number of iterations to of median"</span>
+<a name="l00114"></a>00114                               <span class="stringliteral">" filtering to find bad pixel clusters"</span>,
+<a name="l00115"></a>00115                               <span class="stringliteral">"sinfoni.bp_norm"</span>,
+<a name="l00116"></a>00116                               8);
+<a name="l00117"></a>00117 
+<a name="l00118"></a>00118   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"bp_norm-it"</span>);
+<a name="l00119"></a>00119   cpl_parameterlist_append(list, p);
+<a name="l00120"></a>00120 
+<a name="l00121"></a>00121   <span class="comment">/* float </span>
+<a name="l00122"></a>00122 <span class="comment">     threshold used in the clean mean percentage of rejection used to reject </span>
+<a name="l00123"></a>00123 <span class="comment">     low and high frame */</span>
+<a name="l00124"></a>00124  <span class="comment">/* percentage of extreme pixel value to reject when calculating the mean </span>
+<a name="l00125"></a>00125 <span class="comment">    and stdev */</span>
+<a name="l00126"></a>00126   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.bp_norm.low_rejection"</span>,
+<a name="l00127"></a>00127                   CPL_TYPE_DOUBLE,
+<a name="l00128"></a>00128                               <span class="stringliteral">"low_rejection: "</span>
+<a name="l00129"></a>00129                               <span class="stringliteral">"percentage of rejected low intensity "</span>
+<a name="l00130"></a>00130                               <span class="stringliteral">"pixels before averaging"</span>,
+<a name="l00131"></a>00131                               <span class="stringliteral">"sinfoni.bp_norm"</span>,
+<a name="l00132"></a>00132                               0.1,0.0,1.0);
+<a name="l00133"></a>00133 
+<a name="l00134"></a>00134   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"bp_norm-lo_rej"</span>);
+<a name="l00135"></a>00135   cpl_parameterlist_append(list, p);
+<a name="l00136"></a>00136 
+<a name="l00137"></a>00137   <span class="comment">/* float </span>
+<a name="l00138"></a>00138 <span class="comment">     threshold used in the clean mean percentage of rejection used to reject </span>
+<a name="l00139"></a>00139 <span class="comment">     low and high frame */</span>
+<a name="l00140"></a>00140  <span class="comment">/* percentage of extreme pixel value to reject when calculating the mean </span>
+<a name="l00141"></a>00141 <span class="comment">    and stdev */</span>
+<a name="l00142"></a>00142   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.bp_norm.high_rejection"</span>,
+<a name="l00143"></a>00143                   CPL_TYPE_DOUBLE,
+<a name="l00144"></a>00144                               <span class="stringliteral">"high_rejection: "</span>
+<a name="l00145"></a>00145                               <span class="stringliteral">"percentage of rejected high intensity "</span>
+<a name="l00146"></a>00146                               <span class="stringliteral">"pixels before averaging"</span>,
+<a name="l00147"></a>00147                               <span class="stringliteral">"sinfoni.bp_norm"</span>,
+<a name="l00148"></a>00148                               0.1,0.0,1.0);
+<a name="l00149"></a>00149 
+<a name="l00150"></a>00150   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"bp_norm-hi_rej"</span>);
+<a name="l00151"></a>00151   cpl_parameterlist_append(list, p);
+<a name="l00152"></a>00152 
+<a name="l00153"></a>00153 
+<a name="l00154"></a>00154   <span class="comment">/* position in the frame lower left in X */</span>
+<a name="l00155"></a>00155   <span class="comment">/* pixel coordinate of lower left sinfo_edge of a rectangle zone from which </span>
+<a name="l00156"></a>00156 <span class="comment">     image statistics are computed */</span>
+<a name="l00157"></a>00157   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.bp_norm.llx"</span>,
+<a name="l00158"></a>00158                   CPL_TYPE_INT,
+<a name="l00159"></a>00159                               <span class="stringliteral">"llx: "</span>
+<a name="l00160"></a>00160                               <span class="stringliteral">"to compute image statistics on a rectangular"</span>
+<a name="l00161"></a>00161                               <span class="stringliteral">"zone of the image the coordinates of the "</span>
+<a name="l00162"></a>00162                               <span class="stringliteral">"rectangle are needed:"</span> 
+<a name="l00163"></a>00163                               <span class="stringliteral">"lower left x coordinate"</span>,
+<a name="l00164"></a>00164                               <span class="stringliteral">"sinfoni.bp_norm"</span>,
+<a name="l00165"></a>00165                               270,DET_PIX_MIN,DET_PIX_MAX);
+<a name="l00166"></a>00166 
+<a name="l00167"></a>00167   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"bp_norm-llx"</span>);
+<a name="l00168"></a>00168   cpl_parameterlist_append(list, p);
+<a name="l00169"></a>00169 
+<a name="l00170"></a>00170 
+<a name="l00171"></a>00171 
+<a name="l00172"></a>00172   <span class="comment">/* position in the frame lower left in Y */</span>
+<a name="l00173"></a>00173   <span class="comment">/* pixel coordinate of lower left sinfo_edge of a rectangle zone from which </span>
+<a name="l00174"></a>00174 <span class="comment">     image statistics are computed */</span>
+<a name="l00175"></a>00175   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.bp_norm.lly"</span>,
+<a name="l00176"></a>00176                   CPL_TYPE_INT,
+<a name="l00177"></a>00177                               <span class="stringliteral">"lly: "</span>
+<a name="l00178"></a>00178                               <span class="stringliteral">"to compute image statistics on a rectangular"</span>
+<a name="l00179"></a>00179                               <span class="stringliteral">"zone of the image the coordinates of the "</span>
+<a name="l00180"></a>00180                               <span class="stringliteral">"rectangle are needed:"</span> 
+<a name="l00181"></a>00181                               <span class="stringliteral">"lower left y coordinate"</span>,
+<a name="l00182"></a>00182                               <span class="stringliteral">"sinfoni.bp_norm"</span>,
+<a name="l00183"></a>00183                               LLY,DET_PIX_MIN,DET_PIX_MAX);
+<a name="l00184"></a>00184 
+<a name="l00185"></a>00185   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"bp_norm-lly"</span>);
+<a name="l00186"></a>00186   cpl_parameterlist_append(list, p);
+<a name="l00187"></a>00187 
+<a name="l00188"></a>00188   <span class="comment">/* Upper right position in CCD : should be urx */</span>
+<a name="l00189"></a>00189   <span class="comment">/* pixel coordinate of upper right sinfo_edge of a rectangle zone from which </span>
+<a name="l00190"></a>00190 <span class="comment">    image statistics are computed */</span>
+<a name="l00191"></a>00191   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.bp_norm.urx"</span>,
+<a name="l00192"></a>00192                   CPL_TYPE_INT,
+<a name="l00193"></a>00193                               <span class="stringliteral">"urx: "</span>
+<a name="l00194"></a>00194                               <span class="stringliteral">"to compute image statistics on a rectangular"</span>
+<a name="l00195"></a>00195                               <span class="stringliteral">"zone of the image the coordinates of the "</span>
+<a name="l00196"></a>00196                               <span class="stringliteral">"rectangle are needed:"</span> 
+<a name="l00197"></a>00197                               <span class="stringliteral">"upper right x coordinate"</span>,
+<a name="l00198"></a>00198                               <span class="stringliteral">"sinfoni.bp_norm"</span>,
+<a name="l00199"></a>00199                               310,DET_PIX_MIN,DET_PIX_MAX);
+<a name="l00200"></a>00200 
+<a name="l00201"></a>00201   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"bp_norm-urx"</span>);
+<a name="l00202"></a>00202   cpl_parameterlist_append(list, p);
+<a name="l00203"></a>00203 
+<a name="l00204"></a>00204   <span class="comment">/* Upper right position in CCD : should be ury */</span>
+<a name="l00205"></a>00205   <span class="comment">/* pixel coordinate of upper right sinfo_edge of a rectangle zone from which </span>
+<a name="l00206"></a>00206 <span class="comment">    image statistics are computed */</span>
+<a name="l00207"></a>00207   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.bp_norm.ury"</span>,
+<a name="l00208"></a>00208                   CPL_TYPE_INT,
+<a name="l00209"></a>00209                               <span class="stringliteral">"ury: "</span>
+<a name="l00210"></a>00210                               <span class="stringliteral">"to compute image statistics on a rectangular"</span>
+<a name="l00211"></a>00211                               <span class="stringliteral">"zone of the image the coordinates of the "</span>
+<a name="l00212"></a>00212                               <span class="stringliteral">"rectangle are needed:"</span> 
+<a name="l00213"></a>00213                               <span class="stringliteral">"upper right y coordinate"</span>,
+<a name="l00214"></a>00214                               <span class="stringliteral">"sinfoni.bp_norm"</span>,
+<a name="l00215"></a>00215                               URY,DET_PIX_MIN,DET_PIX_MAX);
+<a name="l00216"></a>00216 
+<a name="l00217"></a>00217   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"bp_norm-ury"</span>);
+<a name="l00218"></a>00218   cpl_parameterlist_append(list, p);
+<a name="l00219"></a>00219 
+<a name="l00220"></a>00220   <span class="comment">/* boolean (implemented as integer) useda s a switch */</span>
+<a name="l00221"></a>00221   <span class="comment">/* indicates if the values beyond threshold values should be marked </span>
+<a name="l00222"></a>00222 <span class="comment">     as bad before proceeding to sinfo_median filtering */</span>
+<a name="l00223"></a>00223   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.bp_norm.threshold_index"</span>,
+<a name="l00224"></a>00224                   CPL_TYPE_BOOL,
+<a name="l00225"></a>00225                               <span class="stringliteral">"Threshold Index: "</span>
+<a name="l00226"></a>00226                               <span class="stringliteral">"indicator that indicates if the values "</span>
+<a name="l00227"></a>00227                               <span class="stringliteral">"beyond a threshold deviation from the mean "</span>
+<a name="l00228"></a>00228                               <span class="stringliteral">"are flagged as bad pixels"</span>,
+<a name="l00229"></a>00229                               <span class="stringliteral">"sinfoni.bp_norm"</span>,
+<a name="l00230"></a>00230                               TRUE);
+<a name="l00231"></a>00231 
+<a name="l00232"></a>00232   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"bp_norm-thr_ind"</span>);
+<a name="l00233"></a>00233   cpl_parameterlist_append(list, p);
+<a name="l00234"></a>00234 
+<a name="l00235"></a>00235   <span class="comment">/* threshold value. Float. Threshold used to find bad pixel */</span>
+<a name="l00236"></a>00236   <span class="comment">/* factor to the clean standard deviation to define the threshold </span>
+<a name="l00237"></a>00237 <span class="comment">     deviation from the clean mean */</span>
+<a name="l00238"></a>00238   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.bp_norm.mean_factor"</span>,
+<a name="l00239"></a>00239                   CPL_TYPE_DOUBLE,
+<a name="l00240"></a>00240                               <span class="stringliteral">"Mean Factor: "</span>
+<a name="l00241"></a>00241                               <span class="stringliteral">"factor to the clean standard deviation to "</span>
+<a name="l00242"></a>00242                               <span class="stringliteral">"define the threshold deviation from the "</span>
+<a name="l00243"></a>00243                               <span class="stringliteral">"clean mean"</span>,
+<a name="l00244"></a>00244                               <span class="stringliteral">"sinfoni.bp_norm"</span>,
+<a name="l00245"></a>00245                               100.,0.1,1.e10);
+<a name="l00246"></a>00246 
+<a name="l00247"></a>00247   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"bp_norm-mean_fct"</span>);
+<a name="l00248"></a>00248   cpl_parameterlist_append(list, p);
+<a name="l00249"></a>00249 
+<a name="l00250"></a>00250 
+<a name="l00251"></a>00251 
+<a name="l00252"></a>00252   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.bp_norm.min_cut"</span>,
+<a name="l00253"></a>00253                   CPL_TYPE_DOUBLE,
+<a name="l00254"></a>00254                               <span class="stringliteral">"the minimum value of real data"</span>,
+<a name="l00255"></a>00255                               <span class="stringliteral">"sinfoni.bp_norm"</span>,
+<a name="l00256"></a>00256                               0.0);
+<a name="l00257"></a>00257 
+<a name="l00258"></a>00258   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"bp_norm-min_cut"</span>);
+<a name="l00259"></a>00259   cpl_parameterlist_append(list, p);
+<a name="l00260"></a>00260 
+<a name="l00261"></a>00261 
+<a name="l00262"></a>00262   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.bp_norm.max_cut"</span>,
+<a name="l00263"></a>00263                   CPL_TYPE_DOUBLE,
+<a name="l00264"></a>00264                               <span class="stringliteral">"the minimum value of real data"</span>,
+<a name="l00265"></a>00265                               <span class="stringliteral">"sinfoni.bp_norm"</span>,
+<a name="l00266"></a>00266                               50000.);
+<a name="l00267"></a>00267 
+<a name="l00268"></a>00268   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"bp_norm-max_cut"</span>);
+<a name="l00269"></a>00269   cpl_parameterlist_append(list, p);
+<a name="l00270"></a>00270 
+<a name="l00271"></a>00271   <span class="keywordflow">return</span>;
+<a name="l00272"></a>00272 
+<a name="l00273"></a>00273 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__bp__norm__config_8h_source.html b/html/sinfo__bp__norm__config_8h_source.html
new file mode 100644
index 0000000..83c2fa5
--- /dev/null
+++ b/html/sinfo__bp__norm__config_8h_source.html
@@ -0,0 +1,57 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_bp_norm_config.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_bp_norm_config.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_bp_norm_config.h,v 1.1 2006/10/20 08:06:32 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the CPL (Common Pipeline Library)</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
+<a name="l00007"></a>00007 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span>
+<a name="l00008"></a>00008 <span class="comment"> * License as published by the Free Software Foundation; either</span>
+<a name="l00009"></a>00009 <span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
+<a name="l00014"></a>00014 <span class="comment"> * Lesser General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
+<a name="l00017"></a>00017 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2006/10/20 08:06:32 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.1 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> */</span>
+<a name="l00026"></a>00026 
+<a name="l00027"></a>00027  <span class="comment">/****************************************************************</span>
+<a name="l00028"></a>00028 <span class="comment">  *           Bad pixel search  (normal method)                  *</span>
+<a name="l00029"></a>00029 <span class="comment">  ****************************************************************/</span>
+<a name="l00030"></a>00030 <span class="preprocessor">#ifndef SINFO_BP_NORM_CONFIG_H</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_BP_NORM_CONFIG_H</span>
+<a name="l00032"></a>00032 <span class="preprocessor"></span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include "cpl.h"</span>  
+<a name="l00034"></a>00034 <span class="comment">/*</span>
+<a name="l00035"></a>00035 <span class="comment">#include "sinfo_dfs.h"</span>
+<a name="l00036"></a>00036 <span class="comment">*/</span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include "sinfo_globals.h"</span>
+<a name="l00038"></a>00038 
+<a name="l00039"></a>00039 <span class="keywordtype">void</span> <a class="code" href="group__sinfo__bad__pix__search.html#ga6f49eed82217a86089ff7f23465ae3e0" title="Adds parameters for the spectrum extraction.">sinfo_bp_norm_config_add</a>(cpl_parameterlist *list);
+<a name="l00040"></a>00040 
+<a name="l00041"></a>00041 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__bp__sky__config_8c_source.html b/html/sinfo__bp__sky__config_8c_source.html
new file mode 100644
index 0000000..8d25066
--- /dev/null
+++ b/html/sinfo__bp__sky__config_8c_source.html
@@ -0,0 +1,281 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_bp_sky_config.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_bp_sky_config.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_bp_sky_config.c,v 1.4 2007/06/06 07:10:45 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the CPL (Common Pipeline Library)</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
+<a name="l00007"></a>00007 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span>
+<a name="l00008"></a>00008 <span class="comment"> * License as published by the Free Software Foundation; either</span>
+<a name="l00009"></a>00009 <span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
+<a name="l00014"></a>00014 <span class="comment"> * Lesser General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
+<a name="l00017"></a>00017 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2007/06/06 07:10:45 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.4 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> */</span>
+<a name="l00026"></a>00026 
+<a name="l00027"></a>00027 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00029"></a>00029 <span class="preprocessor">#endif</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span> <span class="comment">/****************************************************************</span>
+<a name="l00031"></a>00031 <span class="comment">  *           Bad pixel search  (normal method)                  *</span>
+<a name="l00032"></a>00032 <span class="comment">  ****************************************************************/</span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include "sinfo_bp_sky_config.h"</span>
+<a name="l00052"></a>00052   <span class="comment">/* Bad pixel parameters */</span>
+<a name="l00053"></a>00053 
+<a name="l00054"></a>00054 <span class="keywordtype">void</span>
+<a name="l00055"></a><a class="code" href="group__sinfo__bad__pix__search.html#gaba8d9bda2f23ab3e4218598434a3ceeb">00055</a>  <a class="code" href="group__sinfo__bad__pix__search.html#gaba8d9bda2f23ab3e4218598434a3ceeb" title="Adds parameters for the spectrum extraction.">sinfo_bp_sky_config_add</a>(cpl_parameterlist *list)
+<a name="l00056"></a>00056 {
+<a name="l00057"></a>00057   cpl_parameter *p;
+<a name="l00058"></a>00058 
+<a name="l00059"></a>00059   <span class="keywordflow">if</span> (!list) {
+<a name="l00060"></a>00060     <span class="keywordflow">return</span>;
+<a name="l00061"></a>00061   }
+<a name="l00062"></a>00062 
+<a name="l00063"></a>00063 
+<a name="l00064"></a>00064   <span class="comment">/* Output file name */</span>
+<a name="l00065"></a>00065   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.bp_sky.out_filename"</span>,
+<a name="l00066"></a>00066                   CPL_TYPE_STRING,
+<a name="l00067"></a>00067                               <span class="stringliteral">"Output File Name: "</span>,
+<a name="l00068"></a>00068                               <span class="stringliteral">"sinfoni.bp_sky"</span>,
+<a name="l00069"></a>00069                               <span class="stringliteral">"out_bp_sky.fits"</span>);
+<a name="l00070"></a>00070 
+<a name="l00071"></a>00071 
+<a name="l00072"></a>00072   cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"out-bp_sky_filename"</span>);
+<a name="l00073"></a>00073   cpl_parameterlist_append(list, p);
+<a name="l00074"></a>00074 
+<a name="l00075"></a>00075 
+<a name="l00076"></a>00076 <span class="comment">/* factor of noise within which the pixels are used to fit a straight line </span>
+<a name="l00077"></a>00077 <span class="comment">   to the column intensity */</span>
+<a name="l00078"></a>00078   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.bp_sky.sigma_factor"</span>,
+<a name="l00079"></a>00079                   CPL_TYPE_DOUBLE,
+<a name="l00080"></a>00080                               <span class="stringliteral">"Threshold Sigma Factor: "</span>
+<a name="l00081"></a>00081                               <span class="stringliteral">"to remove the column intensity tilt only "</span>
+<a name="l00082"></a>00082                               <span class="stringliteral">"pixels which lie within a defined noise"</span>
+<a name="l00083"></a>00083                               <span class="stringliteral">"limit are used to fit a straight line"</span>,
+<a name="l00084"></a>00084                               <span class="stringliteral">"sinfoni.bp_noise"</span>,
+<a name="l00085"></a>00085                               5.0);
+<a name="l00086"></a>00086 
+<a name="l00087"></a>00087   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"bp_sky-s_factor"</span>);
+<a name="l00088"></a>00088   cpl_parameterlist_append(list, p);
+<a name="l00089"></a>00089 
+<a name="l00090"></a>00090   <span class="comment">/* bad pixel search determination method */</span>
+<a name="l00091"></a>00091  p = cpl_parameter_new_enum(<span class="stringliteral">"sinfoni.bp_sky.method_index"</span>,
+<a name="l00092"></a>00092                   CPL_TYPE_INT,
+<a name="l00093"></a>00093                               <span class="stringliteral">"Bad pixel Method Index"</span>
+<a name="l00094"></a>00094                               <span class="stringliteral">"1: median of nearest neighbors,"</span>
+<a name="l00095"></a>00095                               <span class="stringliteral">"2: absolute distances check, "</span>
+<a name="l00096"></a>00096                               <span class="stringliteral">"3: mean of nearest spectral neighbors"</span>,
+<a name="l00097"></a>00097                               <span class="stringliteral">"sinfoni.bp_sky"</span>,
+<a name="l00098"></a>00098                               1,
+<a name="l00099"></a>00099                               3,1,2,3);
+<a name="l00100"></a>00100 
+<a name="l00101"></a>00101   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"bp_sky-method_ind"</span>);
+<a name="l00102"></a>00102   cpl_parameterlist_append(list, p);
+<a name="l00103"></a>00103 
+<a name="l00104"></a>00104   <span class="comment">/* factor of calculated standard deviation beyond which the deviation </span>
+<a name="l00105"></a>00105 <span class="comment">     of a pixel value from the median of the 8 nearest neighbors declares </span>
+<a name="l00106"></a>00106 <span class="comment">     a pixel as bad */</span>
+<a name="l00107"></a>00107   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.bp_sky.factor"</span>,
+<a name="l00108"></a>00108                   CPL_TYPE_DOUBLE,
+<a name="l00109"></a>00109                               <span class="stringliteral">"Factor: "</span>
+<a name="l00110"></a>00110            <span class="stringliteral">"if |pixel - sinfo_median| > factor * standard deviation -> "</span>
+<a name="l00111"></a>00111                               <span class="stringliteral">"then the pixel value is replaced by "</span>
+<a name="l00112"></a>00112                               <span class="stringliteral">"the median of the 8 nearest neighbors"</span>,
+<a name="l00113"></a>00113                               <span class="stringliteral">"sinfoni.bp_sky"</span>,
+<a name="l00114"></a>00114                               3.0);
+<a name="l00115"></a>00115 
+<a name="l00116"></a>00116   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"bp_sky-fct"</span>);
+<a name="l00117"></a>00117   cpl_parameterlist_append(list, p);
+<a name="l00118"></a>00118 
+<a name="l00119"></a>00119  <span class="comment">/* no of iterations to find bad pix clusters */</span>
+<a name="l00120"></a>00120   <span class="comment">/* number of iterations of sinfo_median filter */</span>
+<a name="l00121"></a>00121   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.bp_sky.iterations"</span>,
+<a name="l00122"></a>00122                   CPL_TYPE_INT,
+<a name="l00123"></a>00123                               <span class="stringliteral">"Iterations: number of iterations to of median"</span>
+<a name="l00124"></a>00124                               <span class="stringliteral">" filtering to find bad pixel clusters"</span>,
+<a name="l00125"></a>00125                               <span class="stringliteral">"sinfoni.bp_sky"</span>,
+<a name="l00126"></a>00126                               8);
+<a name="l00127"></a>00127 
+<a name="l00128"></a>00128   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"bp_sky-it"</span>);
+<a name="l00129"></a>00129   cpl_parameterlist_append(list, p);
+<a name="l00130"></a>00130 
+<a name="l00131"></a>00131   <span class="comment">/* float </span>
+<a name="l00132"></a>00132 <span class="comment">     threshold used in the clean mean percentage of rejection used to reject </span>
+<a name="l00133"></a>00133 <span class="comment">     low and high frame */</span>
+<a name="l00134"></a>00134  <span class="comment">/* percentage of extreme pixel value to reject when calculating the mean </span>
+<a name="l00135"></a>00135 <span class="comment">    and stdev */</span>
+<a name="l00136"></a>00136   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.bp_sky.low_rejection"</span>,
+<a name="l00137"></a>00137                   CPL_TYPE_DOUBLE,
+<a name="l00138"></a>00138                               <span class="stringliteral">"low_rejection: "</span>
+<a name="l00139"></a>00139                               <span class="stringliteral">"percentage of rejected low intensity "</span>
+<a name="l00140"></a>00140                               <span class="stringliteral">"pixels before averaging"</span>,
+<a name="l00141"></a>00141                               <span class="stringliteral">"sinfoni.bp_sky"</span>,
+<a name="l00142"></a>00142                               0.1,0.0,1.0);
+<a name="l00143"></a>00143 
+<a name="l00144"></a>00144   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"bp_sky-low_rej"</span>);
+<a name="l00145"></a>00145   cpl_parameterlist_append(list, p);
+<a name="l00146"></a>00146 
+<a name="l00147"></a>00147   <span class="comment">/* float </span>
+<a name="l00148"></a>00148 <span class="comment">     threshold used in the clean mean percentage of rejection used to reject </span>
+<a name="l00149"></a>00149 <span class="comment">     low and high frame */</span>
+<a name="l00150"></a>00150  <span class="comment">/* percentage of extreme pixel value to reject when calculating the mean </span>
+<a name="l00151"></a>00151 <span class="comment">    and stdev */</span>
+<a name="l00152"></a>00152   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.bp_sky.high_rejection"</span>,
+<a name="l00153"></a>00153                   CPL_TYPE_DOUBLE,
+<a name="l00154"></a>00154                               <span class="stringliteral">"high_rejection: "</span>
+<a name="l00155"></a>00155                               <span class="stringliteral">"percentage of rejected high intensity "</span>
+<a name="l00156"></a>00156                               <span class="stringliteral">"pixels before averaging"</span>,
+<a name="l00157"></a>00157                               <span class="stringliteral">"sinfoni.bp_sky"</span>,
+<a name="l00158"></a>00158                               0.1,0.0,1.0);
+<a name="l00159"></a>00159 
+<a name="l00160"></a>00160   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"bp_sky-upp_rej"</span>);
+<a name="l00161"></a>00161   cpl_parameterlist_append(list, p);
+<a name="l00162"></a>00162 
+<a name="l00163"></a>00163 
+<a name="l00164"></a>00164   <span class="comment">/* position in the frame lower left in X */</span>
+<a name="l00165"></a>00165   <span class="comment">/* pixel coordinate of lower left sinfo_edge of a rectangle zone from which </span>
+<a name="l00166"></a>00166 <span class="comment">     image statistics are computed */</span>
+<a name="l00167"></a>00167   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.bp_sky.llx"</span>,
+<a name="l00168"></a>00168                   CPL_TYPE_INT,
+<a name="l00169"></a>00169                               <span class="stringliteral">"llx: "</span>
+<a name="l00170"></a>00170                               <span class="stringliteral">"to compute image statistics on a rectangular"</span>
+<a name="l00171"></a>00171                               <span class="stringliteral">"zone of the image the coordinates of the "</span>
+<a name="l00172"></a>00172                               <span class="stringliteral">"rectangle are needed:"</span> 
+<a name="l00173"></a>00173                               <span class="stringliteral">"lower left x coordinate"</span>,
+<a name="l00174"></a>00174                               <span class="stringliteral">"sinfoni.bp_sky"</span>,
+<a name="l00175"></a>00175                               LLX,DET_PIX_MIN,DET_PIX_MAX);
+<a name="l00176"></a>00176 
+<a name="l00177"></a>00177   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"bp_sky-llx"</span>);
+<a name="l00178"></a>00178   cpl_parameterlist_append(list, p);
+<a name="l00179"></a>00179 
+<a name="l00180"></a>00180 
+<a name="l00181"></a>00181 
+<a name="l00182"></a>00182   <span class="comment">/* position in the frame lower left in Y */</span>
+<a name="l00183"></a>00183   <span class="comment">/* pixel coordinate of lower left sinfo_edge of a rectangle zone from which </span>
+<a name="l00184"></a>00184 <span class="comment">     image statistics are computed */</span>
+<a name="l00185"></a>00185   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.bp_sky.lly"</span>,
+<a name="l00186"></a>00186                   CPL_TYPE_INT,
+<a name="l00187"></a>00187                               <span class="stringliteral">"lly: "</span>
+<a name="l00188"></a>00188                               <span class="stringliteral">"to compute image statistics on a rectangular"</span>
+<a name="l00189"></a>00189                               <span class="stringliteral">"zone of the image the coordinates of the "</span>
+<a name="l00190"></a>00190                               <span class="stringliteral">"rectangle are needed:"</span> 
+<a name="l00191"></a>00191                               <span class="stringliteral">"lower left y coordinate"</span>,
+<a name="l00192"></a>00192                               <span class="stringliteral">"sinfoni.bp_sky"</span>,
+<a name="l00193"></a>00193                               LLY,DET_PIX_MIN,DET_PIX_MAX);
+<a name="l00194"></a>00194 
+<a name="l00195"></a>00195   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"bp_sky-lly"</span>);
+<a name="l00196"></a>00196   cpl_parameterlist_append(list, p);
+<a name="l00197"></a>00197 
+<a name="l00198"></a>00198   <span class="comment">/* Upper right position in CCD : should be urx */</span>
+<a name="l00199"></a>00199   <span class="comment">/* pixel coordinate of upper right sinfo_edge of a rectangle zone from which </span>
+<a name="l00200"></a>00200 <span class="comment">    image statistics are computed */</span>
+<a name="l00201"></a>00201   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.bp_sky.urx"</span>,
+<a name="l00202"></a>00202                   CPL_TYPE_INT,
+<a name="l00203"></a>00203                               <span class="stringliteral">"urx: "</span>
+<a name="l00204"></a>00204                               <span class="stringliteral">"to compute image statistics on a rectangular"</span>
+<a name="l00205"></a>00205                               <span class="stringliteral">"zone of the image the coordinates of the "</span>
+<a name="l00206"></a>00206                               <span class="stringliteral">"rectangle are needed:"</span> 
+<a name="l00207"></a>00207                               <span class="stringliteral">"upper right x coordinate"</span>,
+<a name="l00208"></a>00208                               <span class="stringliteral">"sinfoni.bp_sky"</span>,
+<a name="l00209"></a>00209                               URX,DET_PIX_MIN,DET_PIX_MAX);
+<a name="l00210"></a>00210 
+<a name="l00211"></a>00211   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"bp_sky-urx"</span>);
+<a name="l00212"></a>00212   cpl_parameterlist_append(list, p);
+<a name="l00213"></a>00213 
+<a name="l00214"></a>00214   <span class="comment">/* Upper right position in CCD : should be ury */</span>
+<a name="l00215"></a>00215   <span class="comment">/* pixel coordinate of upper right sinfo_edge of a rectangle zone from which </span>
+<a name="l00216"></a>00216 <span class="comment">    image statistics are computed */</span>
+<a name="l00217"></a>00217   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.bp_sky.ury"</span>,
+<a name="l00218"></a>00218                   CPL_TYPE_INT,
+<a name="l00219"></a>00219                               <span class="stringliteral">"ury: "</span>
+<a name="l00220"></a>00220                               <span class="stringliteral">"to compute image statistics on a rectangular"</span>
+<a name="l00221"></a>00221                               <span class="stringliteral">"zone of the image the coordinates of the "</span>
+<a name="l00222"></a>00222                               <span class="stringliteral">"rectangle are needed:"</span> 
+<a name="l00223"></a>00223                               <span class="stringliteral">"upper right y coordinate"</span>,
+<a name="l00224"></a>00224                               <span class="stringliteral">"sinfoni.bp_sky"</span>,
+<a name="l00225"></a>00225                               URY,DET_PIX_MIN,DET_PIX_MAX);
+<a name="l00226"></a>00226 
+<a name="l00227"></a>00227   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"bp_sky-ury"</span>);
+<a name="l00228"></a>00228   cpl_parameterlist_append(list, p);
+<a name="l00229"></a>00229 
+<a name="l00230"></a>00230   <span class="comment">/* boolean (implemented as integer) useda s a switch */</span>
+<a name="l00231"></a>00231   <span class="comment">/* indicates if the values beyond threshold values should be marked </span>
+<a name="l00232"></a>00232 <span class="comment">     as bad before proceeding to sinfo_median filtering */</span>
+<a name="l00233"></a>00233   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.bp_sky.threshold_index"</span>,
+<a name="l00234"></a>00234                   CPL_TYPE_BOOL,
+<a name="l00235"></a>00235                               <span class="stringliteral">"Threshold Index: "</span>
+<a name="l00236"></a>00236                               <span class="stringliteral">"indicator that indicates if the values "</span>
+<a name="l00237"></a>00237                               <span class="stringliteral">"beyond a threshold deviation from the mean "</span>
+<a name="l00238"></a>00238                               <span class="stringliteral">"are flagged as bad pixels"</span>,
+<a name="l00239"></a>00239                               <span class="stringliteral">"sinfoni.bp_sky"</span>,
+<a name="l00240"></a>00240                               TRUE);
+<a name="l00241"></a>00241 
+<a name="l00242"></a>00242   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"bp_sky-thr-ind"</span>);
+<a name="l00243"></a>00243   cpl_parameterlist_append(list, p);
+<a name="l00244"></a>00244 
+<a name="l00245"></a>00245   <span class="comment">/* threshold value. Float. Threshold used to find bad pixel */</span>
+<a name="l00246"></a>00246   <span class="comment">/* factor to the clean standard deviation to define the threshold </span>
+<a name="l00247"></a>00247 <span class="comment">     deviation from the clean mean */</span>
+<a name="l00248"></a>00248   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.bp_sky.mean_factor"</span>,
+<a name="l00249"></a>00249                   CPL_TYPE_DOUBLE,
+<a name="l00250"></a>00250                               <span class="stringliteral">"Mean Factor: "</span>
+<a name="l00251"></a>00251                               <span class="stringliteral">"factor to the clean standard deviation to "</span>
+<a name="l00252"></a>00252                               <span class="stringliteral">"define the threshold deviation from the "</span>
+<a name="l00253"></a>00253                               <span class="stringliteral">"clean mean"</span>,
+<a name="l00254"></a>00254                               <span class="stringliteral">"sinfoni.bp_sky"</span>,
+<a name="l00255"></a>00255                               10.,0.1,1.e10);
+<a name="l00256"></a>00256 
+<a name="l00257"></a>00257   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"bp_sky-mean-fct"</span>);
+<a name="l00258"></a>00258   cpl_parameterlist_append(list, p);
+<a name="l00259"></a>00259 
+<a name="l00260"></a>00260 
+<a name="l00261"></a>00261 
+<a name="l00262"></a>00262   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.bp_sky.min_cut"</span>,
+<a name="l00263"></a>00263                   CPL_TYPE_DOUBLE,
+<a name="l00264"></a>00264                               <span class="stringliteral">"the minimum value of real data"</span>,
+<a name="l00265"></a>00265                               <span class="stringliteral">"sinfoni.bp_sky"</span>,
+<a name="l00266"></a>00266                               0.1);
+<a name="l00267"></a>00267 
+<a name="l00268"></a>00268   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"bp_sky-min_cut"</span>);
+<a name="l00269"></a>00269   cpl_parameterlist_append(list, p);
+<a name="l00270"></a>00270 
+<a name="l00271"></a>00271 
+<a name="l00272"></a>00272   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.bp_sky.max_cut"</span>,
+<a name="l00273"></a>00273                   CPL_TYPE_DOUBLE,
+<a name="l00274"></a>00274                               <span class="stringliteral">"the minimum value of real data"</span>,
+<a name="l00275"></a>00275                               <span class="stringliteral">"sinfoni.bp_sky"</span>,
+<a name="l00276"></a>00276                               50000.);
+<a name="l00277"></a>00277 
+<a name="l00278"></a>00278   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"bp_sky-max_cut"</span>);
+<a name="l00279"></a>00279   cpl_parameterlist_append(list, p);
+<a name="l00280"></a>00280 
+<a name="l00281"></a>00281   <span class="keywordflow">return</span>;
+<a name="l00282"></a>00282 
+<a name="l00283"></a>00283 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__bp__sky__config_8h_source.html b/html/sinfo__bp__sky__config_8h_source.html
new file mode 100644
index 0000000..905db55
--- /dev/null
+++ b/html/sinfo__bp__sky__config_8h_source.html
@@ -0,0 +1,54 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_bp_sky_config.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_bp_sky_config.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_bp_sky_config.h,v 1.1 2006/10/20 08:06:32 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the CPL (Common Pipeline Library)</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
+<a name="l00007"></a>00007 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span>
+<a name="l00008"></a>00008 <span class="comment"> * License as published by the Free Software Foundation; either</span>
+<a name="l00009"></a>00009 <span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
+<a name="l00014"></a>00014 <span class="comment"> * Lesser General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
+<a name="l00017"></a>00017 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2006/10/20 08:06:32 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.1 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> */</span>
+<a name="l00026"></a>00026 
+<a name="l00027"></a>00027  <span class="comment">/****************************************************************</span>
+<a name="l00028"></a>00028 <span class="comment">  *           Bad pixel search  (normal method)                  *</span>
+<a name="l00029"></a>00029 <span class="comment">  ****************************************************************/</span>
+<a name="l00030"></a>00030 <span class="preprocessor">#ifndef SINFO_BP_SKY_CONFIG_H</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_BP_SKY_CONFIG_H</span>
+<a name="l00032"></a>00032 <span class="preprocessor"></span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include "cpl.h"</span>  
+<a name="l00034"></a>00034 <span class="preprocessor">#include "sinfo_globals.h"</span>
+<a name="l00035"></a>00035 
+<a name="l00036"></a>00036 <span class="keywordtype">void</span> <a class="code" href="group__sinfo__bad__pix__search.html#gaba8d9bda2f23ab3e4218598434a3ceeb" title="Adds parameters for the spectrum extraction.">sinfo_bp_sky_config_add</a>(cpl_parameterlist *list);
+<a name="l00037"></a>00037 
+<a name="l00038"></a>00038 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__coltilt_8c_source.html b/html/sinfo__coltilt_8c_source.html
new file mode 100644
index 0000000..12ae9bc
--- /dev/null
+++ b/html/sinfo__coltilt_8c_source.html
@@ -0,0 +1,1129 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_coltilt.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_coltilt.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*******************************************************************************</span>
+<a name="l00020"></a>00020 <span class="comment">* E.S.O. - VLT project</span>
+<a name="l00021"></a>00021 <span class="comment">*</span>
+<a name="l00022"></a>00022 <span class="comment">*</span>
+<a name="l00023"></a>00023 <span class="comment">*</span>
+<a name="l00024"></a>00024 <span class="comment">* who       when      what</span>
+<a name="l00025"></a>00025 <span class="comment">* --------  --------  ----------------------------------------------</span>
+<a name="l00026"></a>00026 <span class="comment">* schreib  19/12/00  created</span>
+<a name="l00027"></a>00027 <span class="comment">*/</span>
+<a name="l00028"></a>00028 
+<a name="l00029"></a>00029 <span class="comment">/************************************************************************</span>
+<a name="l00030"></a>00030 <span class="comment">*   NAME</span>
+<a name="l00031"></a>00031 <span class="comment">*        sinfo_coltilt.c -</span>
+<a name="l00032"></a>00032 <span class="comment">*        procedures to correct for tilted spectra </span>
+<a name="l00033"></a>00033 <span class="comment">*</span>
+<a name="l00034"></a>00034 <span class="comment">*   SYNOPSIS</span>
+<a name="l00035"></a>00035 <span class="comment">*   1) float sinfo_new_slope_of_spectrum(cpl_image * ns_image,</span>
+<a name="l00036"></a>00036 <span class="comment">*                             int        box_length,</span>
+<a name="l00037"></a>00037 <span class="comment">*                             float      fwhm,</span>
+<a name="l00038"></a>00038 <span class="comment">*                             float      minDiff )</span>
+<a name="l00039"></a>00039 <span class="comment">*   2) cpl_image * sinfo_new_shift_rows(cpl_image * image,</span>
+<a name="l00040"></a>00040 <span class="comment">*                            float      slope )</span>
+<a name="l00041"></a>00041 <span class="comment">*   3) void sinfo_new_parameter_to_ascii ( float * parameter, </span>
+<a name="l00042"></a>00042 <span class="comment">*                              int n,</span>
+<a name="l00043"></a>00043 <span class="comment">*                              char * filename )</span>
+<a name="l00044"></a>00044 <span class="comment">*   4) float * sinfo_new_ascii_to_parameter ( char * filename,</span>
+<a name="l00045"></a>00045 <span class="comment">*                                 int * n )</span>
+<a name="l00046"></a>00046 <span class="comment">*   5) double * sinfo_new_curvature_of_spectrum( cpl_image * ns_image,</span>
+<a name="l00047"></a>00047 <span class="comment">*                              int        order,</span>
+<a name="l00048"></a>00048 <span class="comment">*                                    int        box_length,</span>
+<a name="l00049"></a>00049 <span class="comment">*                                    int        left_pos,</span>
+<a name="l00050"></a>00050 <span class="comment">*                                    int        right_pos,</span>
+<a name="l00051"></a>00051 <span class="comment">*                                    float      fwhm,</span>
+<a name="l00052"></a>00052 <span class="comment">*                                    float      minDiff )</span>
+<a name="l00053"></a>00053 <span class="comment">*</span>
+<a name="l00054"></a>00054 <span class="comment">*</span>
+<a name="l00055"></a>00055 <span class="comment">*   DESCRIPTION</span>
+<a name="l00056"></a>00056 <span class="comment">*   1)  determines the sub-pixel shifts of each row by using</span>
+<a name="l00057"></a>00057 <span class="comment">*       an image with at least one continuum spectrum of a pinhole</span>
+<a name="l00058"></a>00058 <span class="comment">*       this is done by searching the spectrum within the image</span>
+<a name="l00059"></a>00059 <span class="comment">*       then fitting the spectrum along the rows within a given box</span>
+<a name="l00060"></a>00060 <span class="comment">*       by a sinfo_gaussian, so that the exact position is determined for</span>
+<a name="l00061"></a>00061 <span class="comment">*       each row. Afterwards, a straight line is fitted through the</span>
+<a name="l00062"></a>00062 <span class="comment">*       fitted positions. The slope of this linear fit is returned.</span>
+<a name="l00063"></a>00063 <span class="comment">*   2)  shifts the rows of a raw image by using the output of </span>
+<a name="l00064"></a>00064 <span class="comment">*       sinfo_slopeOfSpectrum and applying polynomial interpolation</span>
+<a name="l00065"></a>00065 <span class="comment">*   3)  stores parameters in an ASCII file </span>
+<a name="l00066"></a>00066 <span class="comment">*   4)  writes parameters stored in an ASCII file in an float array</span>
+<a name="l00067"></a>00067 <span class="comment">*   5)  this routine determines the curvature of a spectrum by fitting</span>
+<a name="l00068"></a>00068 <span class="comment">*       a polynomial to a continuum spectrum. This is done by using</span>
+<a name="l00069"></a>00069 <span class="comment">*       an image with at least one continuum spectrum of a pinhole.</span>
+<a name="l00070"></a>00070 <span class="comment">*       this is done by searching the spectrum within the image</span>
+<a name="l00071"></a>00071 <span class="comment">*       then fitting the spectrum along the rows within a given box</span>
+<a name="l00072"></a>00072 <span class="comment">*       by a sinfo_gaussian, so that the exact position is determined for</span>
+<a name="l00073"></a>00073 <span class="comment">*       each row. Afterwards, a polynomial is fitted through the</span>
+<a name="l00074"></a>00074 <span class="comment">*       found positions. The polynomial coefficients are returned.</span>
+<a name="l00075"></a>00075 <span class="comment">*</span>
+<a name="l00076"></a>00076 <span class="comment">*</span>
+<a name="l00077"></a>00077 <span class="comment">*   FILES</span>
+<a name="l00078"></a>00078 <span class="comment">*</span>
+<a name="l00079"></a>00079 <span class="comment">*   ENVIRONMENT</span>
+<a name="l00080"></a>00080 <span class="comment">*</span>
+<a name="l00081"></a>00081 <span class="comment">*   RETURN VALUES</span>
+<a name="l00082"></a>00082 <span class="comment">*</span>
+<a name="l00083"></a>00083 <span class="comment">*   CAUTIONS</span>
+<a name="l00084"></a>00084 <span class="comment">*</span>
+<a name="l00085"></a>00085 <span class="comment">*   EXAMPLES</span>
+<a name="l00086"></a>00086 <span class="comment">*</span>
+<a name="l00087"></a>00087 <span class="comment">*   SEE ALSO</span>
+<a name="l00088"></a>00088 <span class="comment">*</span>
+<a name="l00089"></a>00089 <span class="comment">*   BUGS</span>
+<a name="l00090"></a>00090 <span class="comment">*</span>
+<a name="l00091"></a>00091 <span class="comment">*------------------------------------------------------------------------</span>
+<a name="l00092"></a>00092 <span class="comment">*/</span>
+<a name="l00093"></a>00093 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00094"></a>00094 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00095"></a>00095 <span class="preprocessor">#endif</span>
+<a name="l00096"></a>00096 <span class="preprocessor"></span>
+<a name="l00097"></a>00097 <span class="preprocessor">#define POSIX_SOURCE 1</span>
+<a name="l00098"></a>00098 <span class="preprocessor"></span><span class="preprocessor">#include "sinfo_vltPort.h"</span>
+<a name="l00099"></a>00099 
+<a name="l00100"></a>00100 <span class="comment">/*</span>
+<a name="l00101"></a>00101 <span class="comment"> * System Headers</span>
+<a name="l00102"></a>00102 <span class="comment"> */</span>
+<a name="l00103"></a>00103 
+<a name="l00104"></a>00104 <span class="comment">/*</span>
+<a name="l00105"></a>00105 <span class="comment"> * Local Headers</span>
+<a name="l00106"></a>00106 <span class="comment"> */</span>
+<a name="l00107"></a>00107 
+<a name="l00108"></a>00108 <span class="preprocessor">#include "sinfo_coltilt.h"</span>
+<a name="l00109"></a>00109 <span class="preprocessor">#include "sinfo_new_resampling.h"</span>
+<a name="l00110"></a>00110 <span class="preprocessor">#include "sinfo_fit_curve.h"</span>
+<a name="l00111"></a>00111 <span class="preprocessor">#include "sinfo_functions.h"</span>
+<a name="l00119"></a>00119 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00120"></a>00120 <span class="comment"> *                            Function codes</span>
+<a name="l00121"></a>00121 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00122"></a>00122 
+<a name="l00143"></a>00143 <span class="keywordtype">float</span> 
+<a name="l00144"></a>00144 sinfo_new_slope_of_spectrum( cpl_image * ns_image,
+<a name="l00145"></a>00145                        <span class="keywordtype">int</span>        box_length,
+<a name="l00146"></a>00146                        <span class="keywordtype">float</span>      fwhm,
+<a name="l00147"></a>00147                        <span class="keywordtype">float</span>      minDiff )
+<a name="l00148"></a>00148 {
+<a name="l00149"></a>00149     <span class="keywordtype">int</span> i, k, row, col ;
+<a name="l00150"></a>00150     <span class="keywordtype">int</span> counter, iters ;
+<a name="l00151"></a>00151     <span class="keywordtype">int</span> xdim, ndat, its, numpar ;
+<a name="l00152"></a>00152     <span class="keywordtype">float</span> maxval ;
+<a name="l00153"></a>00153     <span class="keywordtype">float</span> tol, lab ;
+<a name="l00154"></a>00154     <span class="keywordtype">float</span>* col_value=NULL ;
+<a name="l00155"></a>00155     <span class="keywordtype">float</span>* column_value=NULL ;
+<a name="l00156"></a>00156     pixelvalue* col_position=NULL ;
+<a name="l00157"></a>00157     <span class="keywordtype">int</span>* column_position=NULL ;
+<a name="l00158"></a>00158     <span class="keywordtype">float</span>* x_position=NULL ;
+<a name="l00159"></a>00159 
+<a name="l00160"></a>00160 
+<a name="l00161"></a>00161     <span class="keywordtype">int</span> col_median ;
+<a name="l00162"></a>00162     <span class="keywordtype">float</span> * xdat, * wdat ;
+<a name="l00163"></a>00163     <span class="keywordtype">int</span> * mpar ;
+<a name="l00164"></a>00164     Vector * line ;
+<a name="l00165"></a>00165     FitParams ** dec_par ;
+<a name="l00166"></a>00166     FitParams *  par ;
+<a name="l00167"></a>00167 
+<a name="l00168"></a>00168     <span class="keywordtype">float</span>* x=NULL; 
+<a name="l00169"></a>00169     <span class="keywordtype">float</span>* y=NULL; 
+<a name="l00170"></a>00170     <span class="keywordtype">float</span>* sig=NULL ;
+<a name="l00171"></a>00171 
+<a name="l00172"></a>00172     <span class="keywordtype">int</span> position ;
+<a name="l00173"></a>00173     <span class="keywordtype">int</span> ndata, mwt ;
+<a name="l00174"></a>00174     <span class="keywordtype">float</span> a, b, siga, sigb, chi2, q ;
+<a name="l00175"></a>00175     <span class="keywordtype">int</span> bad_ind ;
+<a name="l00176"></a>00176     <span class="keywordtype">int</span> lx=0;
+<a name="l00177"></a>00177     <span class="keywordtype">int</span> ly=0;
+<a name="l00178"></a>00178     <span class="keywordtype">float</span>* pdata=NULL;
+<a name="l00179"></a>00179 
+<a name="l00180"></a>00180     <span class="keywordflow">if</span> ( ns_image == NULL )
+<a name="l00181"></a>00181     {
+<a name="l00182"></a>00182         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" sorry, no image given"</span>) ;
+<a name="l00183"></a>00183         <span class="keywordflow">return</span> FLAG ;
+<a name="l00184"></a>00184     }
+<a name="l00185"></a>00185     lx=cpl_image_get_size_x(ns_image);
+<a name="l00186"></a>00186     ly=cpl_image_get_size_x(ns_image);
+<a name="l00187"></a>00187 
+<a name="l00188"></a>00188 
+<a name="l00189"></a>00189     <span class="keywordflow">if</span> ( box_length <= 1 || box_length >= (<span class="keywordtype">int</span>) sqrt(lx) )
+<a name="l00190"></a>00190     {
+<a name="l00191"></a>00191         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" wrong box length given"</span>) ;
+<a name="l00192"></a>00192         <span class="keywordflow">return</span> FLAG ;
+<a name="l00193"></a>00193     }
+<a name="l00194"></a>00194     <span class="keywordflow">if</span> ( fwhm < 1. || fwhm > 10. )
+<a name="l00195"></a>00195     {
+<a name="l00196"></a>00196         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"wrong full width at half maximum given"</span>) ;
+<a name="l00197"></a>00197         <span class="keywordflow">return</span> FLAG ;
+<a name="l00198"></a>00198     }
+<a name="l00199"></a>00199     <span class="keywordflow">if</span> ( minDiff < 1. )
+<a name="l00200"></a>00200     {
+<a name="l00201"></a>00201         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"wrong amplitude threshold given"</span>) ;
+<a name="l00202"></a>00202         <span class="keywordflow">return</span> FLAG ;
+<a name="l00203"></a>00203     }
+<a name="l00204"></a>00204 
+<a name="l00205"></a>00205 
+<a name="l00206"></a>00206 
+<a name="l00207"></a>00207     col_value=cpl_calloc(ly,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l00208"></a>00208     column_value=cpl_calloc(ly,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l00209"></a>00209     col_position=(pixelvalue*)cpl_calloc(ly,<span class="keyword">sizeof</span>(pixelvalue)) ;
+<a name="l00210"></a>00210     column_position=cpl_calloc(ly,<span class="keyword">sizeof</span>(<span class="keywordtype">int</span>)) ;
+<a name="l00211"></a>00211     x_position=cpl_calloc(ly,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l00212"></a>00212 
+<a name="l00213"></a>00213 
+<a name="l00214"></a>00214 
+<a name="l00215"></a>00215     x=cpl_calloc(lx,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)); 
+<a name="l00216"></a>00216     y=cpl_calloc(lx,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)); 
+<a name="l00217"></a>00217     sig=cpl_calloc(lx,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l00218"></a>00218     pdata=cpl_image_get_data_float(ns_image);
+<a name="l00219"></a>00219     <span class="comment">/* go through the image rows */</span>
+<a name="l00220"></a>00220     <span class="keywordflow">for</span> ( row = 0 ; row < ly ; row++ )
+<a name="l00221"></a>00221     {
+<a name="l00222"></a>00222         col_value[row] = -FLT_MAX ;
+<a name="l00223"></a>00223         col_position[row] = -1. ;
+<a name="l00224"></a>00224         <span class="comment">/* find the maximum value in each row and store the found column */</span>
+<a name="l00225"></a>00225         <span class="keywordflow">for</span> ( col = 0 ; col < lx ; col++ )
+<a name="l00226"></a>00226         {
+<a name="l00227"></a>00227             <span class="keywordflow">if</span> ( pdata[col+row*lx] > col_value[row] )
+<a name="l00228"></a>00228             {
+<a name="l00229"></a>00229                 col_value[row]    = pdata[col+row*lx] ;
+<a name="l00230"></a>00230                 col_position[row] = (pixelvalue)col ;
+<a name="l00231"></a>00231             }
+<a name="l00232"></a>00232         }
+<a name="l00233"></a>00233     }
+<a name="l00234"></a>00234 
+<a name="l00235"></a>00235     <span class="comment">/* now determine the sinfo_new_median of the found columns to be sure </span>
+<a name="l00236"></a>00236 <span class="comment">       to have the brightest spectrum */</span>
+<a name="l00237"></a>00237     col_median = (int)sinfo_new_median(col_position, ly) ;
+<a name="l00238"></a>00238     sinfo_msg (<span class="stringliteral">"sinfo_new_median column position of brightest spectrum %d\n"</span>, 
+<a name="l00239"></a>00239               col_median) ;
+<a name="l00240"></a>00240 
+<a name="l00241"></a>00241     <span class="comment">/* now find the peaks around col_median over the whole spectral range */</span>
+<a name="l00242"></a>00242     <span class="keywordflow">for</span> ( row = 0 ; row < ly ; row++ )
+<a name="l00243"></a>00243     {
+<a name="l00244"></a>00244         x_position[row] = 0. ;
+<a name="l00245"></a>00245         column_value[row] = -FLT_MAX ;
+<a name="l00246"></a>00246         column_position[row] = -1 ;
+<a name="l00247"></a>00247         <span class="keywordflow">for</span> ( col = col_median - box_length ; 
+<a name="l00248"></a>00248               col <= col_median + box_length ; col++ )
+<a name="l00249"></a>00249         {
+<a name="l00250"></a>00250             <span class="keywordflow">if</span> ( pdata[col+row*lx] > column_value[row] )
+<a name="l00251"></a>00251             {
+<a name="l00252"></a>00252                 column_value[row] = pdata[col+row*lx] ; 
+<a name="l00253"></a>00253                 column_position[row] = col ;
+<a name="l00254"></a>00254             }
+<a name="l00255"></a>00255         }
+<a name="l00256"></a>00256 
+<a name="l00257"></a>00257         <span class="comment">/* allocate memory for the array where the line is fitted in */</span>
+<a name="l00258"></a>00258         <span class="keywordflow">if</span> ( NULL == (line = sinfo_new_vector (2*box_length + 1)) )
+<a name="l00259"></a>00259         {
+<a name="l00260"></a>00260             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"cannot allocate new Vector in row %d"</span>, row) ;
+<a name="l00261"></a>00261             <span class="keywordflow">return</span> FLAG ;
+<a name="l00262"></a>00262         }
+<a name="l00263"></a>00263 
+<a name="l00264"></a>00264         <span class="comment">/* allocate memory */</span>
+<a name="l00265"></a>00265         xdat = (<span class="keywordtype">float</span> *) cpl_calloc( line -> n_elements, <span class="keyword">sizeof</span> (<span class="keywordtype">float</span>) ) ;
+<a name="l00266"></a>00266         wdat = (<span class="keywordtype">float</span> *) cpl_calloc( line -> n_elements, <span class="keyword">sizeof</span> (<span class="keywordtype">float</span>) ) ;
+<a name="l00267"></a>00267         mpar = (<span class="keywordtype">int</span> *)   cpl_calloc( MAXPAR, <span class="keyword">sizeof</span> (<span class="keywordtype">int</span>) ) ;
+<a name="l00268"></a>00268         dec_par = sinfo_new_fit_params(1) ;
+<a name="l00269"></a>00269     par = dec_par[0];
+<a name="l00270"></a>00270 
+<a name="l00271"></a>00271         counter = 0 ;
+<a name="l00272"></a>00272         bad_ind = 0 ;
+<a name="l00273"></a>00273         <span class="comment">/* store the values to fit in a Vector object */</span>
+<a name="l00274"></a>00274         <span class="keywordflow">for</span> ( col = column_position[row] - box_length ; 
+<a name="l00275"></a>00275               col <= column_position[row] + box_length ; col++ )
+<a name="l00276"></a>00276         {
+<a name="l00277"></a>00277             <span class="keywordflow">if</span> ( col < 0 || col >= lx )
+<a name="l00278"></a>00278             {
+<a name="l00279"></a>00279                 <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"wrong spectrum position or box_length "</span>
+<a name="l00280"></a>00280                                  <span class="stringliteral">"given in row: %d"</span>, row) ;
+<a name="l00281"></a>00281                 cpl_free (xdat) ;
+<a name="l00282"></a>00282                 cpl_free (wdat) ;
+<a name="l00283"></a>00283                 cpl_free (mpar) ;
+<a name="l00284"></a>00284                 sinfo_new_destroy_fit_params(&dec_par) ;
+<a name="l00285"></a>00285                 sinfo_new_destroy_vector( line ) ;
+<a name="l00286"></a>00286                 <span class="keywordflow">return</span> FLAG ;
+<a name="l00287"></a>00287             }
+<a name="l00288"></a>00288             <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( isnan(pdata[col+row*lx]) )
+<a name="l00289"></a>00289             {
+<a name="l00290"></a>00290                 bad_ind = 1 ;
+<a name="l00291"></a>00291             }
+<a name="l00292"></a>00292             <span class="keywordflow">else</span>
+<a name="l00293"></a>00293             {
+<a name="l00294"></a>00294                 line -> data[counter] = pdata[col + row*lx] ;
+<a name="l00295"></a>00295                 counter++ ;
+<a name="l00296"></a>00296             }
+<a name="l00297"></a>00297         }
+<a name="l00298"></a>00298  
+<a name="l00299"></a>00299         <span class="comment">/* go to the next row if a bad pixel is inside the box */</span>
+<a name="l00300"></a>00300         <span class="keywordflow">if</span> ( bad_ind == 1 )
+<a name="l00301"></a>00301         {
+<a name="l00302"></a>00302             <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a> (<span class="stringliteral">"sorry, bad pixel inside fitting "</span>
+<a name="l00303"></a>00303                                <span class="stringliteral">"box in row: %d"</span>, row) ;
+<a name="l00304"></a>00304             cpl_free (xdat) ;
+<a name="l00305"></a>00305             cpl_free (wdat) ;
+<a name="l00306"></a>00306             cpl_free (mpar) ;
+<a name="l00307"></a>00307             sinfo_new_destroy_fit_params(&dec_par) ;
+<a name="l00308"></a>00308             sinfo_new_destroy_vector( line ) ;
+<a name="l00309"></a>00309             continue ;
+<a name="l00310"></a>00310         }
+<a name="l00311"></a>00311 
+<a name="l00312"></a>00312         <span class="comment">/*--------------------------------------------------------------------</span>
+<a name="l00313"></a>00313 <span class="comment">         * go through the line sinfo_vector</span>
+<a name="l00314"></a>00314 <span class="comment">         * determine the maximum pixel value in the line sinfo_vector</span>
+<a name="l00315"></a>00315 <span class="comment">         */</span>
+<a name="l00316"></a>00316         maxval = -FLT_MAX ;
+<a name="l00317"></a>00317         position = -INT32_MAX ;
+<a name="l00318"></a>00318         <span class="keywordflow">for</span> ( i = 0 ; i < counter ; i++ )
+<a name="l00319"></a>00319         {
+<a name="l00320"></a>00320             xdat[i] = i ;
+<a name="l00321"></a>00321             wdat[i] = 1.0 ;
+<a name="l00322"></a>00322             <span class="keywordflow">if</span> ( line -> data[i] >= maxval )
+<a name="l00323"></a>00323             {
+<a name="l00324"></a>00324                 maxval = line -> data[i] ;
+<a name="l00325"></a>00325                 position = i ;
+<a name="l00326"></a>00326             }
+<a name="l00327"></a>00327         }
+<a name="l00328"></a>00328 
+<a name="l00329"></a>00329         <span class="comment">/* set initial values for the fitting routine */</span>
+<a name="l00330"></a>00330         xdim     = XDIM ;
+<a name="l00331"></a>00331         ndat     = line -> n_elements ;
+<a name="l00332"></a>00332         numpar   = MAXPAR ;
+<a name="l00333"></a>00333         tol      = TOL ;
+<a name="l00334"></a>00334         lab      = LAB ;
+<a name="l00335"></a>00335         its      = ITS ;
+<a name="l00336"></a>00336         (*par).fit_par[1] = fwhm ;
+<a name="l00337"></a>00337         (*par).fit_par[2] = (float) position ;
+<a name="l00338"></a>00338         (*par).fit_par[3] = (float) (line -> data[0] + 
+<a name="l00339"></a>00339                             line -> data[line->n_elements - 1]) / 2.0 ;
+<a name="l00340"></a>00340 
+<a name="l00341"></a>00341         (*par).fit_par[0]  = maxval - ((*par).fit_par[3]) ;
+<a name="l00342"></a>00342         <span class="comment">/* exclude negative peaks and low signal cases */</span>
+<a name="l00343"></a>00343         <span class="keywordflow">if</span> ( (*par).fit_par[0] < minDiff )
+<a name="l00344"></a>00344         {
+<a name="l00345"></a>00345             <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a> (<span class="stringliteral">"sorry, negative peak or signal of line "</span>
+<a name="l00346"></a>00346                                <span class="stringliteral">"too low to fit in row: %d"</span>, row) ;
+<a name="l00347"></a>00347             cpl_free (xdat) ;
+<a name="l00348"></a>00348             cpl_free (wdat) ;
+<a name="l00349"></a>00349             cpl_free (mpar) ;
+<a name="l00350"></a>00350             sinfo_new_destroy_fit_params(&dec_par) ;
+<a name="l00351"></a>00351             sinfo_new_destroy_vector( line ) ;
+<a name="l00352"></a>00352             continue ;
+<a name="l00353"></a>00353         }
+<a name="l00354"></a>00354 
+<a name="l00355"></a>00355         <span class="keywordflow">for</span> ( k = 0 ; k < MAXPAR ; k++ )
+<a name="l00356"></a>00356         {
+<a name="l00357"></a>00357             (*par).derv_par[k] = 0.0 ;
+<a name="l00358"></a>00358             mpar[k] = 1 ;
+<a name="l00359"></a>00359         }
+<a name="l00360"></a>00360 
+<a name="l00361"></a>00361         <span class="comment">/* finally, do the least square fit using a sinfo_gaussian */</span>
+<a name="l00362"></a>00362         <span class="keywordflow">if</span> ( 0 > ( iters = sinfo_new_lsqfit_c( xdat, &xdim, 
+<a name="l00363"></a>00363                                                line -> data, wdat, 
+<a name="l00364"></a>00364                                                &ndat, (*par).fit_par,
+<a name="l00365"></a>00365                                                (*par).derv_par, mpar, 
+<a name="l00366"></a>00366                                                &numpar, &tol, &its, &lab )) )
+<a name="l00367"></a>00367         {
+<a name="l00368"></a>00368             <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a> (<span class="stringliteral">"sinfo_new_lsqfit_c: least squares fit "</span>
+<a name="l00369"></a>00369                                <span class="stringliteral">"failed in row: %d, error no.: %d"</span>,row,iters) ;
+<a name="l00370"></a>00370             cpl_free (xdat) ;
+<a name="l00371"></a>00371             cpl_free (wdat) ;
+<a name="l00372"></a>00372             cpl_free (mpar) ;
+<a name="l00373"></a>00373             sinfo_new_destroy_fit_params(&dec_par) ;
+<a name="l00374"></a>00374             sinfo_new_destroy_vector( line ) ;
+<a name="l00375"></a>00375             continue ;
+<a name="l00376"></a>00376         }
+<a name="l00377"></a>00377 
+<a name="l00378"></a>00378         <span class="comment">/* check for negative fit results */</span>
+<a name="l00379"></a>00379         <span class="keywordflow">if</span> ( (*par).fit_par[0] <= 0. || (*par).fit_par[1] <= 0. ||
+<a name="l00380"></a>00380              (*par).fit_par[2] <= 0. )
+<a name="l00381"></a>00381         {
+<a name="l00382"></a>00382             <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a> (<span class="stringliteral">"negative parameters as fit result, "</span>
+<a name="l00383"></a>00383                                <span class="stringliteral">"not used! in row: %d"</span>, row) ;
+<a name="l00384"></a>00384             cpl_free (xdat) ;
+<a name="l00385"></a>00385             cpl_free (wdat) ;
+<a name="l00386"></a>00386             cpl_free (mpar) ;
+<a name="l00387"></a>00387             sinfo_new_destroy_fit_params(&dec_par) ;
+<a name="l00388"></a>00388             sinfo_new_destroy_vector( line ) ;
+<a name="l00389"></a>00389             continue ;
+<a name="l00390"></a>00390         }
+<a name="l00391"></a>00391 
+<a name="l00392"></a>00392         <span class="comment">/* correct the fitted position for the given row of the line in </span>
+<a name="l00393"></a>00393 <span class="comment">           image coordinates */</span>
+<a name="l00394"></a>00394         x_position[row] =  (float) (column_position[row] - box_length) + 
+<a name="l00395"></a>00395                            (*par).fit_par[2] ;
+<a name="l00396"></a>00396 
+<a name="l00397"></a>00397         <span class="comment">/* store the fit errors of the positions as weights for the later </span>
+<a name="l00398"></a>00398 <span class="comment">           linear fit */</span>
+<a name="l00399"></a>00399         sig[row] = (*par).derv_par[2] ;
+<a name="l00400"></a>00400 
+<a name="l00401"></a>00401         <span class="comment">/* free memory */</span>
+<a name="l00402"></a>00402         sinfo_new_destroy_fit_params(&dec_par) ;
+<a name="l00403"></a>00403         sinfo_new_destroy_vector ( line ) ;
+<a name="l00404"></a>00404         cpl_free ( xdat ) ;
+<a name="l00405"></a>00405         cpl_free ( wdat ) ;
+<a name="l00406"></a>00406         cpl_free ( mpar ) ;
+<a name="l00407"></a>00407     }
+<a name="l00408"></a>00408 
+<a name="l00409"></a>00409     <span class="comment">/* -----------------------------------------------------------------------</span>
+<a name="l00410"></a>00410 <span class="comment">     * now that we have a sub-pixel resolved list of spectral maxima stored </span>
+<a name="l00411"></a>00411 <span class="comment">     * in x_position[row]</span>
+<a name="l00412"></a>00412 <span class="comment">     * We can fit a flux weighted straight line to the positions to determine </span>
+<a name="l00413"></a>00413 <span class="comment">     * the spectral column shifts.</span>
+<a name="l00414"></a>00414 <span class="comment">     */</span>
+<a name="l00415"></a>00415     ndata = 0 ;
+<a name="l00416"></a>00416     <span class="keywordflow">for</span> ( row = 0 ; row < lx ; row++ )
+<a name="l00417"></a>00417     {
+<a name="l00418"></a>00418         <span class="keywordflow">if</span> ( x_position[row] == 0. || sig[row] == 0. )
+<a name="l00419"></a>00419         {
+<a name="l00420"></a>00420             continue ;
+<a name="l00421"></a>00421         }
+<a name="l00422"></a>00422         <span class="keywordflow">else</span> 
+<a name="l00423"></a>00423         {
+<a name="l00424"></a>00424             y[ndata]   = x_position[row] ;
+<a name="l00425"></a>00425             x[ndata]   = (float)row ;
+<a name="l00426"></a>00426             sig[ndata] = sig[row] ;
+<a name="l00427"></a>00427             ndata++ ;
+<a name="l00428"></a>00428         }
+<a name="l00429"></a>00429     }
+<a name="l00430"></a>00430     <span class="keywordflow">if</span> ( ndata < 10 )
+<a name="l00431"></a>00431     {
+<a name="l00432"></a>00432         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"not enough positions to do the linear fit"</span>) ;
+<a name="l00433"></a>00433         <span class="keywordflow">return</span> FLAG ;
+<a name="l00434"></a>00434     }
+<a name="l00435"></a>00435 
+<a name="l00436"></a>00436     <span class="comment">/* now do the fit and return the slope of the straight line */</span>
+<a name="l00437"></a>00437     mwt = 0 ;
+<a name="l00438"></a>00438     sinfo_my_fit(x, y, ndata, sig, mwt, &a, &b, &siga, &sigb, &chi2, &q) ;
+<a name="l00439"></a>00439 
+<a name="l00440"></a>00440     cpl_free(col_value) ;
+<a name="l00441"></a>00441     cpl_free(column_value) ;
+<a name="l00442"></a>00442     cpl_free(col_position) ;
+<a name="l00443"></a>00443     cpl_free(column_position) ;
+<a name="l00444"></a>00444     cpl_free(x_position) ;
+<a name="l00445"></a>00445 
+<a name="l00446"></a>00446     cpl_free(x); 
+<a name="l00447"></a>00447     cpl_free(y); 
+<a name="l00448"></a>00448     cpl_free(sig) ;
+<a name="l00449"></a>00449 
+<a name="l00450"></a>00450     <span class="keywordflow">return</span> b ;
+<a name="l00451"></a>00451 }
+<a name="l00452"></a>00452 
+<a name="l00465"></a>00465 cpl_image * 
+<a name="l00466"></a>00466 sinfo_new_shift_rows( cpl_image * image,
+<a name="l00467"></a>00467                       <span class="keywordtype">float</span>      slope, 
+<a name="l00468"></a>00468                       <span class="keywordtype">int</span>        n_order )
+<a name="l00469"></a>00469 {
+<a name="l00470"></a>00470     cpl_image * returnImage=NULL ;
+<a name="l00471"></a>00471     <span class="keywordtype">float</span> xshift=0 ;
+<a name="l00472"></a>00472     <span class="keywordtype">int</span>   intshift = 0 ;
+<a name="l00473"></a>00473     <span class="keywordtype">float</span> sum=0;
+<a name="l00474"></a>00474     <span class="keywordtype">float</span> new_sum=0;
+<a name="l00475"></a>00475 
+<a name="l00476"></a>00476     <span class="keywordtype">float</span>* xnum=NULL ;
+<a name="l00477"></a>00477     <span class="keywordtype">float</span>* row_data=NULL ;
+<a name="l00478"></a>00478     <span class="keywordtype">float</span>* corrected_row_data=NULL ;
+<a name="l00479"></a>00479 
+<a name="l00480"></a>00480     <span class="keywordtype">float</span> eval=0 <span class="comment">/*, dy*/</span> ;
+<a name="l00481"></a>00481     <span class="keywordtype">float</span> * imageptr=NULL ;
+<a name="l00482"></a>00482     <span class="keywordtype">int</span> col=0;
+<a name="l00483"></a>00483     <span class="keywordtype">int</span> row=0;
+<a name="l00484"></a>00484     <span class="keywordtype">int</span> firstpos=0;
+<a name="l00485"></a>00485     <span class="keywordtype">int</span> n_points=0;
+<a name="l00486"></a>00486     <span class="keywordtype">int</span> i=0;
+<a name="l00487"></a>00487     <span class="keywordtype">int</span> flag=0;
+<a name="l00488"></a>00488     <span class="keywordtype">int</span> ilx=0;
+<a name="l00489"></a>00489     <span class="keywordtype">int</span> ily=0;
+<a name="l00490"></a>00490     <span class="keywordtype">int</span> olx=0;
+<a name="l00491"></a>00491     <span class="keywordtype">int</span> oly=0;
+<a name="l00492"></a>00492     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l00493"></a>00493     <span class="keywordtype">float</span>* podata=NULL;
+<a name="l00494"></a>00494 
+<a name="l00495"></a>00495     <span class="keywordflow">if</span> ( image == NULL )
+<a name="l00496"></a>00496     {
+<a name="l00497"></a>00497         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"sorry, no image given"</span>) ;
+<a name="l00498"></a>00498         <span class="keywordflow">return</span> NULL ;
+<a name="l00499"></a>00499     }
+<a name="l00500"></a>00500 
+<a name="l00501"></a>00501     <span class="keywordflow">if</span> ( slope == 0. )
+<a name="l00502"></a>00502     {
+<a name="l00503"></a>00503         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"there is no need to shift the image rows!"</span>) ;
+<a name="l00504"></a>00504         <span class="keywordflow">return</span> NULL ;
+<a name="l00505"></a>00505     }
+<a name="l00506"></a>00506 
+<a name="l00507"></a>00507     <span class="keywordflow">if</span> ( n_order <= 0 )
+<a name="l00508"></a>00508     {
+<a name="l00509"></a>00509         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"wrong order of interpolation polynom given!"</span>) ;
+<a name="l00510"></a>00510         <span class="keywordflow">return</span> NULL ;
+<a name="l00511"></a>00511     }
+<a name="l00512"></a>00512 
+<a name="l00513"></a>00513     returnImage = cpl_image_duplicate( image ) ;
+<a name="l00514"></a>00514     ilx=cpl_image_get_size_x(image);
+<a name="l00515"></a>00515     ily=cpl_image_get_size_y(image);
+<a name="l00516"></a>00516     olx=cpl_image_get_size_x(returnImage);
+<a name="l00517"></a>00517     oly=cpl_image_get_size_y(returnImage);
+<a name="l00518"></a>00518     pidata=cpl_image_get_data_float(image);
+<a name="l00519"></a>00519     podata=cpl_image_get_data_float(returnImage);
+<a name="l00520"></a>00520 
+<a name="l00521"></a>00521 
+<a name="l00522"></a>00522     n_points = n_order + 1 ;
+<a name="l00523"></a>00523     <span class="keywordflow">if</span> ( n_points % 2 == 0 )
+<a name="l00524"></a>00524     {
+<a name="l00525"></a>00525         firstpos = (int)(n_points/2) - 1 ;
+<a name="l00526"></a>00526     }
+<a name="l00527"></a>00527     <span class="keywordflow">else</span>
+<a name="l00528"></a>00528     {
+<a name="l00529"></a>00529         firstpos = (int)(n_points/2) ;
+<a name="l00530"></a>00530     }
+<a name="l00531"></a>00531 
+<a name="l00532"></a>00532 
+<a name="l00533"></a>00533     xnum=cpl_calloc(n_order + 1,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l00534"></a>00534     row_data=cpl_calloc(ilx,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l00535"></a>00535     corrected_row_data=cpl_calloc(ilx,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l00536"></a>00536 
+<a name="l00537"></a>00537     <span class="comment">/* fill the xa[] array for the polint function */</span>
+<a name="l00538"></a>00538     <span class="keywordflow">for</span> ( i = 0 ; i < n_points ; i++ )
+<a name="l00539"></a>00539     {
+<a name="l00540"></a>00540         xnum[i] = i ;
+<a name="l00541"></a>00541     }
+<a name="l00542"></a>00542 
+<a name="l00543"></a>00543     <span class="comment">/* go through the image rows */</span>
+<a name="l00544"></a>00544     <span class="keywordflow">for</span> ( row = 0 ; row < ily ; row++ )
+<a name="l00545"></a>00545     {
+<a name="l00546"></a>00546         <span class="comment">/* determine the shift for each row, the middle row is not shifted */</span>
+<a name="l00547"></a>00547         xshift = slope * (float)( (ily / 2) - row ) ;
+<a name="l00548"></a>00548 
+<a name="l00549"></a>00549         intshift = sinfo_new_nint(xshift) ;
+<a name="l00550"></a>00550         xshift = xshift - (float)intshift ;
+<a name="l00551"></a>00551 
+<a name="l00552"></a>00552         <span class="keywordflow">for</span> ( col = 0 ; col < ilx ; col++ )
+<a name="l00553"></a>00553         {
+<a name="l00554"></a>00554             corrected_row_data[col] = 0. ;
+<a name="l00555"></a>00555         }
+<a name="l00556"></a>00556         sum = 0. ; <span class="comment">/* initialize flux for later rescaling */</span>
+<a name="l00557"></a>00557         <span class="comment">/* go through the image columns */</span>
+<a name="l00558"></a>00558         <span class="keywordflow">for</span> ( col = 0 ; col < ilx ; col++ )
+<a name="l00559"></a>00559         {
+<a name="l00560"></a>00560         <span class="comment">/* consider integer pixel shifts */</span>
+<a name="l00561"></a>00561         <span class="keywordflow">if</span> ( intshift < 0 )
+<a name="l00562"></a>00562             {
+<a name="l00563"></a>00563         <span class="keywordflow">if</span> ( col - intshift < ilx )
+<a name="l00564"></a>00564         {
+<a name="l00565"></a>00565             row_data[col] = pidata[col-intshift+row*ilx] ;
+<a name="l00566"></a>00566                 }
+<a name="l00567"></a>00567         <span class="keywordflow">else</span>
+<a name="l00568"></a>00568         {
+<a name="l00569"></a>00569             row_data[col] = 0. ;
+<a name="l00570"></a>00570                 }
+<a name="l00571"></a>00571         }
+<a name="l00572"></a>00572         <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( intshift > 0 )
+<a name="l00573"></a>00573         {
+<a name="l00574"></a>00574         <span class="keywordflow">if</span> ( col - intshift >= 0 )
+<a name="l00575"></a>00575         {
+<a name="l00576"></a>00576             row_data[col] = pidata[col-intshift+row*ilx] ;
+<a name="l00577"></a>00577                 }
+<a name="l00578"></a>00578         <span class="keywordflow">else</span>
+<a name="l00579"></a>00579         {
+<a name="l00580"></a>00580             row_data[col] = 0. ;
+<a name="l00581"></a>00581         }
+<a name="l00582"></a>00582         }
+<a name="l00583"></a>00583         <span class="keywordflow">else</span>
+<a name="l00584"></a>00584         {
+<a name="l00585"></a>00585                row_data[col] = pidata[col+row*ilx] ;
+<a name="l00586"></a>00586         }
+<a name="l00587"></a>00587 
+<a name="l00588"></a>00588             <span class="comment">/* don't consider the sinfo_edge pixels for flux calculation */</span>
+<a name="l00589"></a>00589             <span class="keywordflow">if</span> ( col != 0 && col != ilx - 1 && !isnan(row_data[col]) )
+<a name="l00590"></a>00590             {
+<a name="l00591"></a>00591                 sum += row_data[col] ;
+<a name="l00592"></a>00592             }
+<a name="l00593"></a>00593             <span class="keywordflow">if</span> (isnan(row_data[col])) 
+<a name="l00594"></a>00594             {
+<a name="l00595"></a>00595                 row_data[col] = 0. ;
+<a name="l00596"></a>00596                 <span class="keywordflow">for</span> (i = col - firstpos ; i < col - firstpos + n_points ; i++ )
+<a name="l00597"></a>00597                 {
+<a name="l00598"></a>00598                     <span class="keywordflow">if</span> ( i < 0 ) continue ;
+<a name="l00599"></a>00599                     <span class="keywordflow">if</span> ( i >= ilx) continue ;
+<a name="l00600"></a>00600                     corrected_row_data[i] = ZERO ;
+<a name="l00601"></a>00601                 }
+<a name="l00602"></a>00602             }
+<a name="l00603"></a>00603         }
+<a name="l00604"></a>00604 
+<a name="l00605"></a>00605 
+<a name="l00606"></a>00606         <span class="comment">/* --------------------------------------------------------------------</span>
+<a name="l00607"></a>00607 <span class="comment">         * now we do the polynomial interpolation to achieve the fractional</span>
+<a name="l00608"></a>00608 <span class="comment">         * shift that means call polint</span>
+<a name="l00609"></a>00609 <span class="comment">         */</span>
+<a name="l00610"></a>00610         new_sum = 0. ;
+<a name="l00611"></a>00611         <span class="keywordflow">for</span> ( col = 0 ; col < ilx ; col++ )
+<a name="l00612"></a>00612         {
+<a name="l00613"></a>00613             <span class="comment">/* ---------------------------------------------------------------</span>
+<a name="l00614"></a>00614 <span class="comment">             * now determine the arrays of size n_points with which the</span>
+<a name="l00615"></a>00615 <span class="comment">             * polynom is determined and determine the position eval</span>
+<a name="l00616"></a>00616 <span class="comment">             * where the polynom is evaluated in polint of N.R..</span>
+<a name="l00617"></a>00617 <span class="comment">             * Take care of the points near the row edges!</span>
+<a name="l00618"></a>00618 <span class="comment">             */</span>
+<a name="l00619"></a>00619             <span class="keywordflow">if</span> ( isnan(corrected_row_data[col]) )
+<a name="l00620"></a>00620             {
+<a name="l00621"></a>00621                  continue ;
+<a name="l00622"></a>00622             }
+<a name="l00623"></a>00623             <span class="keywordflow">if</span> ( col - firstpos < 0 )
+<a name="l00624"></a>00624             {
+<a name="l00625"></a>00625                 imageptr = &row_data[0] ;
+<a name="l00626"></a>00626                 eval     = (float)col - xshift ;
+<a name="l00627"></a>00627             }
+<a name="l00628"></a>00628             <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( col - firstpos + n_points >= ilx )
+<a name="l00629"></a>00629             {
+<a name="l00630"></a>00630                 imageptr = &row_data[ilx - n_points] ;
+<a name="l00631"></a>00631                 eval     = (float)(col + n_points - ilx) - xshift ;
+<a name="l00632"></a>00632             }
+<a name="l00633"></a>00633             <span class="keywordflow">else</span>
+<a name="l00634"></a>00634             {
+<a name="l00635"></a>00635                 imageptr = &row_data[col-firstpos] ;
+<a name="l00636"></a>00636                 eval     = (float)firstpos - xshift ;
+<a name="l00637"></a>00637             }
+<a name="l00638"></a>00638 
+<a name="l00639"></a>00639         flag=0;
+<a name="l00640"></a>00640         corrected_row_data[col]=sinfo_new_nev_ille(xnum,imageptr,
+<a name="l00641"></a>00641                                                        n_order,eval,&flag);
+<a name="l00642"></a>00642             <span class="comment">/*polint( xnum - 1, imageptr, n_points, eval, </span>
+<a name="l00643"></a>00643 <span class="comment">                      &corrected_row_data[col], &dy ) ;*/</span>
+<a name="l00644"></a>00644 
+<a name="l00645"></a>00645             <span class="comment">/* don't take the sinfo_edge points to calculate </span>
+<a name="l00646"></a>00646 <span class="comment">               the scaling factor */</span>
+<a name="l00647"></a>00647             <span class="keywordflow">if</span> (col != 0 && col != ilx - 1 && !isnan(corrected_row_data[col]) )
+<a name="l00648"></a>00648             {
+<a name="l00649"></a>00649                 new_sum += corrected_row_data[col] ;
+<a name="l00650"></a>00650             }
+<a name="l00651"></a>00651         }
+<a name="l00652"></a>00652 
+<a name="l00653"></a>00653         <span class="keywordflow">if</span> ( new_sum == 0. )
+<a name="l00654"></a>00654         {
+<a name="l00655"></a>00655             new_sum = 1. ;
+<a name="l00656"></a>00656         }
+<a name="l00657"></a>00657         <span class="keywordflow">for</span> ( col = 0 ; col < ilx ; col++ )
+<a name="l00658"></a>00658         {
+<a name="l00659"></a>00659             <span class="keywordflow">if</span> ( isnan(corrected_row_data[col]))
+<a name="l00660"></a>00660             {
+<a name="l00661"></a>00661                 podata[col+row*ilx] = ZERO ;
+<a name="l00662"></a>00662             }
+<a name="l00663"></a>00663             <span class="keywordflow">else</span>
+<a name="l00664"></a>00664             {
+<a name="l00665"></a>00665               <span class="comment">/* rescale the row data and fill the returned image */</span>
+<a name="l00666"></a>00666               <span class="comment">/* This gives sometimes inconsistent results if </span>
+<a name="l00667"></a>00667 <span class="comment">                 bad pixels are around */</span>
+<a name="l00668"></a>00668               <span class="comment">/* rescaling is commented out because it delivers wrong results</span>
+<a name="l00669"></a>00669 <span class="comment">                 in case of appearance of blanks or bad pixels */</span>
+<a name="l00670"></a>00670              <span class="comment">/*   corrected_row_data[col] *= sum / new_sum ; */</span>
+<a name="l00671"></a>00671                 podata[col+row*ilx] = corrected_row_data[col] ;
+<a name="l00672"></a>00672             }
+<a name="l00673"></a>00673         }
+<a name="l00674"></a>00674     }      
+<a name="l00675"></a>00675 
+<a name="l00676"></a>00676     cpl_free(xnum) ;
+<a name="l00677"></a>00677     cpl_free(row_data) ;
+<a name="l00678"></a>00678     cpl_free(corrected_row_data);
+<a name="l00679"></a>00679 
+<a name="l00680"></a>00680     <span class="keywordflow">return</span> returnImage ;
+<a name="l00681"></a>00681 }
+<a name="l00682"></a>00682 
+<a name="l00683"></a>00683 
+<a name="l00694"></a>00694 <span class="keywordtype">void</span> 
+<a name="l00695"></a>00695 sinfo_new_parameter_to_ascii ( <span class="keywordtype">float</span> * parameter, 
+<a name="l00696"></a>00696                         <span class="keywordtype">int</span> n,
+<a name="l00697"></a>00697                         <span class="keywordtype">char</span> * filename )
+<a name="l00698"></a>00698 {
+<a name="l00699"></a>00699     FILE * fp ;
+<a name="l00700"></a>00700     <span class="keywordtype">int</span>     i=0 ;
+<a name="l00701"></a>00701 
+<a name="l00702"></a>00702     <span class="keywordflow">if</span> ( parameter == NULL || filename == NULL || n <= 0 )
+<a name="l00703"></a>00703     {
+<a name="l00704"></a>00704         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"input is missing or wrong!"</span>) ;
+<a name="l00705"></a>00705         return ;
+<a name="l00706"></a>00706     }
+<a name="l00707"></a>00707     
+<a name="l00708"></a>00708     <span class="keywordflow">if</span> ( NULL == (fp = fopen ( filename, <span class="stringliteral">"w"</span> ) ) )
+<a name="l00709"></a>00709     {
+<a name="l00710"></a>00710         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"cannot open %s"</span>, filename) ;
+<a name="l00711"></a>00711         return ;
+<a name="l00712"></a>00712     }
+<a name="l00713"></a>00713 
+<a name="l00714"></a>00714     <span class="keywordflow">for</span> ( i = 0 ; i < n ; i++ )
+<a name="l00715"></a>00715     {
+<a name="l00716"></a>00716         fprintf (fp, <span class="stringliteral">"%le\n"</span>, parameter[i] ) ;
+<a name="l00717"></a>00717     }
+<a name="l00718"></a>00718     fclose (fp ) ;
+<a name="l00719"></a>00719 }
+<a name="l00720"></a>00720 
+<a name="l00728"></a>00728 <span class="keywordtype">float</span> * 
+<a name="l00729"></a>00729 sinfo_new_ascii_to_parameter ( <span class="keywordtype">char</span> * filename,
+<a name="l00730"></a>00730                            <span class="keywordtype">int</span> * n )
+<a name="l00731"></a>00731 {
+<a name="l00732"></a>00732     FILE * fp ;
+<a name="l00733"></a>00733     <span class="keywordtype">float</span> * parameter=NULL ;
+<a name="l00734"></a>00734     <span class="keywordtype">int</span>     i=0 ;
+<a name="l00735"></a>00735 
+<a name="l00736"></a>00736     <span class="keywordflow">if</span> ( filename == NULL || n == NULL )
+<a name="l00737"></a>00737     {
+<a name="l00738"></a>00738         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"Input is missing or wrong"</span>) ;
+<a name="l00739"></a>00739         <span class="keywordflow">return</span> NULL ;
+<a name="l00740"></a>00740     }
+<a name="l00741"></a>00741     
+<a name="l00742"></a>00742     <span class="keywordflow">if</span> ( NULL == (fp = fopen ( filename, <span class="stringliteral">"r"</span> ) ) )
+<a name="l00743"></a>00743     {
+<a name="l00744"></a>00744         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"cannot open %s"</span>, filename) ;
+<a name="l00745"></a>00745         <span class="keywordflow">return</span> NULL ;
+<a name="l00746"></a>00746     }
+<a name="l00747"></a>00747 
+<a name="l00748"></a>00748     <span class="comment">/* allocate memory */</span>
+<a name="l00749"></a>00749 
+<a name="l00750"></a>00750     <span class="keywordflow">if</span> (NULL == ( parameter = (<span class="keywordtype">float</span>*) cpl_calloc (ESTIMATE, <span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ) )
+<a name="l00751"></a>00751     {
+<a name="l00752"></a>00752         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"cannot allocate memory"</span>) ;
+<a name="l00753"></a>00753         fclose (fp ) ;
+<a name="l00754"></a>00754         <span class="keywordflow">return</span> NULL ;
+<a name="l00755"></a>00755     }
+<a name="l00756"></a>00756 
+<a name="l00757"></a>00757     i = 0 ;
+<a name="l00758"></a>00758     <span class="keywordflow">while</span> ( fscanf(fp, <span class="stringliteral">"%g\n"</span>, &parameter[i]) != EOF )
+<a name="l00759"></a>00759     {
+<a name="l00760"></a>00760         i++ ;
+<a name="l00761"></a>00761     }
+<a name="l00762"></a>00762     *n = i ;
+<a name="l00763"></a>00763 
+<a name="l00764"></a>00764     fclose (fp ) ;
+<a name="l00765"></a>00765 
+<a name="l00766"></a>00766     <span class="keywordflow">return</span> parameter ;
+<a name="l00767"></a>00767 }
+<a name="l00768"></a>00768 
+<a name="l00769"></a>00769 
+<a name="l00792"></a>00792 <span class="keywordtype">double</span> * 
+<a name="l00793"></a>00793 sinfo_new_curvature_of_spectrum( cpl_image * ns_image,
+<a name="l00794"></a>00794                     <span class="keywordtype">int</span>        order,
+<a name="l00795"></a>00795                          <span class="keywordtype">int</span>        box_length,
+<a name="l00796"></a>00796                  <span class="keywordtype">int</span>        left_pos,
+<a name="l00797"></a>00797              <span class="keywordtype">int</span>        right_pos,
+<a name="l00798"></a>00798                          <span class="keywordtype">float</span>      fwhm,
+<a name="l00799"></a>00799                          <span class="keywordtype">float</span>      minDiff )
+<a name="l00800"></a>00800 {
+<a name="l00801"></a>00801     <span class="keywordtype">int</span> i=0;
+<a name="l00802"></a>00802     <span class="keywordtype">int</span> k=0;
+<a name="l00803"></a>00803     <span class="keywordtype">int</span> row=0;
+<a name="l00804"></a>00804     <span class="keywordtype">int</span> col=0;
+<a name="l00805"></a>00805     <span class="keywordtype">int</span> counter=0;
+<a name="l00806"></a>00806     <span class="keywordtype">int</span> iters=0;
+<a name="l00807"></a>00807     <span class="keywordtype">int</span> xdim=0;
+<a name="l00808"></a>00808     <span class="keywordtype">int</span> ndat=0;
+<a name="l00809"></a>00809     <span class="keywordtype">int</span> its=0;
+<a name="l00810"></a>00810     <span class="keywordtype">int</span> numpar=0;
+<a name="l00811"></a>00811     <span class="keywordtype">float</span> maxval=0 ;
+<a name="l00812"></a>00812     <span class="keywordtype">float</span> tol=0;
+<a name="l00813"></a>00813     <span class="keywordtype">float</span> lab=0;
+<a name="l00814"></a>00814 
+<a name="l00815"></a>00815     <span class="keywordtype">float</span>* col_value=NULL ;
+<a name="l00816"></a>00816     <span class="keywordtype">float</span>* column_value=NULL ;
+<a name="l00817"></a>00817     pixelvalue* col_position=NULL ;
+<a name="l00818"></a>00818     <span class="keywordtype">int</span>* column_position=NULL ;
+<a name="l00819"></a>00819     <span class="keywordtype">float</span>* x_position=NULL ;
+<a name="l00820"></a>00820 
+<a name="l00821"></a>00821     <span class="keywordtype">int</span> col_median=0;
+<a name="l00822"></a>00822     <span class="keywordtype">float</span> * xdat=NULL;
+<a name="l00823"></a>00823     <span class="keywordtype">float</span> * wdat=NULL;
+<a name="l00824"></a>00824     <span class="keywordtype">int</span> * mpar=NULL;
+<a name="l00825"></a>00825     Vector * line=NULL;
+<a name="l00826"></a>00826     FitParams ** dec_par=NULL ;
+<a name="l00827"></a>00827     FitParams * par=NULL ;
+<a name="l00828"></a>00828     <span class="keywordtype">int</span> position=0 ;
+<a name="l00829"></a>00829     <span class="keywordtype">int</span> ndata=0 ;
+<a name="l00830"></a>00830     <span class="keywordtype">int</span> bad_ind=0 ;
+<a name="l00831"></a>00831     dpoint * list=NULL ;
+<a name="l00832"></a>00832     <span class="keywordtype">double</span> * coeffs=NULL ;
+<a name="l00833"></a>00833     <span class="keywordtype">double</span> offset=0 ;
+<a name="l00834"></a>00834     <span class="keywordtype">int</span> lx=0;
+<a name="l00835"></a>00835     <span class="keywordtype">int</span> ly=0;
+<a name="l00836"></a>00836     <span class="keywordtype">float</span>* pdata=NULL;
+<a name="l00837"></a>00837 
+<a name="l00838"></a>00838     <span class="keywordflow">if</span> ( ns_image == NULL )
+<a name="l00839"></a>00839     {
+<a name="l00840"></a>00840         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"sorry, no image given"</span>) ;
+<a name="l00841"></a>00841         <span class="keywordflow">return</span> NULL ;
+<a name="l00842"></a>00842     }
+<a name="l00843"></a>00843     lx=cpl_image_get_size_x(ns_image);
+<a name="l00844"></a>00844     ly=cpl_image_get_size_y(ns_image);
+<a name="l00845"></a>00845 
+<a name="l00846"></a>00846     <span class="keywordflow">if</span> ( box_length <= 1 || box_length >= right_pos - left_pos )
+<a name="l00847"></a>00847     {
+<a name="l00848"></a>00848         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"wrong box length given"</span>) ;
+<a name="l00849"></a>00849         <span class="keywordflow">return</span> NULL ;
+<a name="l00850"></a>00850     }
+<a name="l00851"></a>00851     <span class="keywordflow">if</span> ( fwhm < 1. || fwhm > 10. )
+<a name="l00852"></a>00852     {
+<a name="l00853"></a>00853         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"wrong full width at half maximum given"</span>) ;
+<a name="l00854"></a>00854         <span class="keywordflow">return</span> NULL ;
+<a name="l00855"></a>00855     }
+<a name="l00856"></a>00856     <span class="keywordflow">if</span> ( left_pos < 0 || right_pos <= left_pos || right_pos > lx )
+<a name="l00857"></a>00857     {
+<a name="l00858"></a>00858         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"wrong left and right positions"</span>) ;
+<a name="l00859"></a>00859         <span class="keywordflow">return</span> NULL ;
+<a name="l00860"></a>00860     }
+<a name="l00861"></a>00861     <span class="keywordflow">if</span> ( minDiff < 1. )
+<a name="l00862"></a>00862     {
+<a name="l00863"></a>00863         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"wrong amplitude threshold given!"</span>) ;
+<a name="l00864"></a>00864         <span class="keywordflow">return</span> NULL ;
+<a name="l00865"></a>00865     }
+<a name="l00866"></a>00866 
+<a name="l00867"></a>00867 
+<a name="l00868"></a>00868 
+<a name="l00869"></a>00869     col_value=cpl_calloc(ly,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l00870"></a>00870     column_value=cpl_calloc(ly,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l00871"></a>00871     col_position=(pixelvalue*)cpl_calloc(ly,<span class="keyword">sizeof</span>(pixelvalue)) ;
+<a name="l00872"></a>00872     column_position=cpl_calloc(ly,<span class="keyword">sizeof</span>(<span class="keywordtype">int</span>)) ;
+<a name="l00873"></a>00873     x_position=cpl_calloc(ly,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l00874"></a>00874 
+<a name="l00875"></a>00875     <span class="comment">/* go through the image rows */</span>
+<a name="l00876"></a>00876     <span class="keywordflow">for</span> ( row = 0 ; row < ly ; row++ )
+<a name="l00877"></a>00877     {
+<a name="l00878"></a>00878         col_value[row] = -FLT_MAX ;
+<a name="l00879"></a>00879         col_position[row] = -1. ;
+<a name="l00880"></a>00880         <span class="comment">/* find the maximum value in each row and store the found column */</span>
+<a name="l00881"></a>00881         <span class="keywordflow">for</span> ( col = left_pos ; col < right_pos ; col++ )
+<a name="l00882"></a>00882         {
+<a name="l00883"></a>00883             <span class="keywordflow">if</span> ( pdata[col+row*lx] > col_value[row] )
+<a name="l00884"></a>00884             {
+<a name="l00885"></a>00885                 col_value[row]    = pdata[col+row*lx] ;
+<a name="l00886"></a>00886                 col_position[row] = (pixelvalue)col ;
+<a name="l00887"></a>00887             }
+<a name="l00888"></a>00888         }
+<a name="l00889"></a>00889     }
+<a name="l00890"></a>00890 
+<a name="l00891"></a>00891     <span class="comment">/* now determine the sinfo_new_median of the found columns to be sure </span>
+<a name="l00892"></a>00892 <span class="comment">       to have the brightest spectrum */</span>
+<a name="l00893"></a>00893     col_median = (int)sinfo_new_median(col_position, right_pos - left_pos) ;
+<a name="l00894"></a>00894 
+<a name="l00895"></a>00895     <span class="comment">/* now find the peaks around col_median over the whole spectral range */</span>
+<a name="l00896"></a>00896     <span class="keywordflow">for</span> ( row = 0 ; row < ly ; row++ )
+<a name="l00897"></a>00897     {
+<a name="l00898"></a>00898         x_position[row] = 0. ;
+<a name="l00899"></a>00899         column_value[row] = -FLT_MAX ;
+<a name="l00900"></a>00900         column_position[row] = -1 ;
+<a name="l00901"></a>00901         <span class="keywordflow">for</span> ( col = col_median - box_length ; 
+<a name="l00902"></a>00902               col <= col_median + box_length ; col++ )
+<a name="l00903"></a>00903         {
+<a name="l00904"></a>00904             <span class="keywordflow">if</span> ( pdata[col+row*lx] > column_value[row] )
+<a name="l00905"></a>00905             {
+<a name="l00906"></a>00906                 column_value[row] = pdata[col+row*lx] ; 
+<a name="l00907"></a>00907                 column_position[row] = col ;
+<a name="l00908"></a>00908             }
+<a name="l00909"></a>00909         }
+<a name="l00910"></a>00910 
+<a name="l00911"></a>00911         <span class="comment">/* allocate memory for the array where the line is fitted in */</span>
+<a name="l00912"></a>00912         <span class="keywordflow">if</span> ( NULL == (line = sinfo_new_vector (2*box_length + 1)) )
+<a name="l00913"></a>00913         {
+<a name="l00914"></a>00914             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"cannot allocate new Vector in row: %d"</span>, row) ;
+<a name="l00915"></a>00915             <span class="keywordflow">return</span> NULL ;
+<a name="l00916"></a>00916         }
+<a name="l00917"></a>00917 
+<a name="l00918"></a>00918         <span class="comment">/* allocate memory */</span>
+<a name="l00919"></a>00919         xdat = (<span class="keywordtype">float</span> *) cpl_calloc( line -> n_elements, <span class="keyword">sizeof</span> (<span class="keywordtype">float</span>) ) ;
+<a name="l00920"></a>00920         wdat = (<span class="keywordtype">float</span> *) cpl_calloc( line -> n_elements, <span class="keyword">sizeof</span> (<span class="keywordtype">float</span>) ) ;
+<a name="l00921"></a>00921         mpar = (<span class="keywordtype">int</span> *)   cpl_calloc( MAXPAR, <span class="keyword">sizeof</span> (<span class="keywordtype">int</span>) ) ;
+<a name="l00922"></a>00922         dec_par = sinfo_new_fit_params(1) ;
+<a name="l00923"></a>00923         par = dec_par[0];
+<a name="l00924"></a>00924     
+<a name="l00925"></a>00925         counter = 0 ;
+<a name="l00926"></a>00926         bad_ind = 0 ;
+<a name="l00927"></a>00927         <span class="comment">/* store the values to fit in a Vector object */</span>
+<a name="l00928"></a>00928         <span class="keywordflow">for</span> ( col = column_position[row] - box_length ; 
+<a name="l00929"></a>00929               col <= column_position[row] + box_length ; col++ )
+<a name="l00930"></a>00930         {
+<a name="l00931"></a>00931             <span class="keywordflow">if</span> ( col < 0 || col >= lx )
+<a name="l00932"></a>00932             {
+<a name="l00933"></a>00933                 <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"wrong spectrum position or box_length "</span>
+<a name="l00934"></a>00934                                  <span class="stringliteral">"given in row: %d"</span>, row) ;
+<a name="l00935"></a>00935                 cpl_free (xdat) ;
+<a name="l00936"></a>00936                 cpl_free (wdat) ;
+<a name="l00937"></a>00937                 cpl_free (mpar) ;
+<a name="l00938"></a>00938                 sinfo_new_destroy_fit_params(&dec_par) ;
+<a name="l00939"></a>00939                 sinfo_new_destroy_vector( line ) ;
+<a name="l00940"></a>00940                 <span class="keywordflow">return</span> NULL ;
+<a name="l00941"></a>00941             }
+<a name="l00942"></a>00942             <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( isnan(pdata[col+row*lx]) )
+<a name="l00943"></a>00943             {
+<a name="l00944"></a>00944                 bad_ind = 1 ;
+<a name="l00945"></a>00945             }
+<a name="l00946"></a>00946             <span class="keywordflow">else</span>
+<a name="l00947"></a>00947             {
+<a name="l00948"></a>00948                 line -> data[counter] = pdata[col + row*lx] ;
+<a name="l00949"></a>00949                 counter++ ;
+<a name="l00950"></a>00950             }
+<a name="l00951"></a>00951         }
+<a name="l00952"></a>00952  
+<a name="l00953"></a>00953         <span class="comment">/* go to the next row if a bad pixel is inside the box */</span>
+<a name="l00954"></a>00954         <span class="keywordflow">if</span> ( bad_ind == 1 )
+<a name="l00955"></a>00955         {
+<a name="l00956"></a>00956             <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a> (<span class="stringliteral">"sorry, bad pixel inside fitting box "</span>
+<a name="l00957"></a>00957                                <span class="stringliteral">"in row: %d"</span>, row) ;
+<a name="l00958"></a>00958             cpl_free (xdat) ;
+<a name="l00959"></a>00959             cpl_free (wdat) ;
+<a name="l00960"></a>00960             cpl_free (mpar) ;
+<a name="l00961"></a>00961             sinfo_new_destroy_fit_params(&dec_par) ;
+<a name="l00962"></a>00962             sinfo_new_destroy_vector( line ) ;
+<a name="l00963"></a>00963             continue ;
+<a name="l00964"></a>00964         }
+<a name="l00965"></a>00965 
+<a name="l00966"></a>00966         <span class="comment">/*--------------------------------------------------------------------</span>
+<a name="l00967"></a>00967 <span class="comment">         * go through the line sinfo_vector</span>
+<a name="l00968"></a>00968 <span class="comment">         * determine the maximum pixel value in the line sinfo_vector</span>
+<a name="l00969"></a>00969 <span class="comment">         */</span>
+<a name="l00970"></a>00970         maxval = -FLT_MAX ;
+<a name="l00971"></a>00971         position = -INT32_MAX ;
+<a name="l00972"></a>00972         <span class="keywordflow">for</span> ( i = 0 ; i < counter ; i++ )
+<a name="l00973"></a>00973         {
+<a name="l00974"></a>00974             xdat[i] = i ;
+<a name="l00975"></a>00975             wdat[i] = 1.0 ;
+<a name="l00976"></a>00976             <span class="keywordflow">if</span> ( line -> data[i] >= maxval )
+<a name="l00977"></a>00977             {
+<a name="l00978"></a>00978                 maxval = line -> data[i] ;
+<a name="l00979"></a>00979                 position = i ;
+<a name="l00980"></a>00980             }
+<a name="l00981"></a>00981         }
+<a name="l00982"></a>00982 
+<a name="l00983"></a>00983         <span class="comment">/* set initial values for the fitting routine */</span>
+<a name="l00984"></a>00984         xdim     = XDIM ;
+<a name="l00985"></a>00985         ndat     = line -> n_elements ;
+<a name="l00986"></a>00986         numpar   = MAXPAR ;
+<a name="l00987"></a>00987         tol      = TOL ;
+<a name="l00988"></a>00988         lab      = LAB ;
+<a name="l00989"></a>00989         its      = ITS ;
+<a name="l00990"></a>00990         (*par).fit_par[1] = fwhm ;
+<a name="l00991"></a>00991         (*par).fit_par[2] = (float) position ;
+<a name="l00992"></a>00992         (*par).fit_par[3] = (float) (line -> data[0] + 
+<a name="l00993"></a>00993                                      line -> data[line->n_elements - 1]) / 2.0;
+<a name="l00994"></a>00994 
+<a name="l00995"></a>00995         (*par).fit_par[0]  = maxval - ((*par).fit_par[3]) ;
+<a name="l00996"></a>00996         <span class="comment">/* exclude negative peaks and low signal cases */</span>
+<a name="l00997"></a>00997         <span class="keywordflow">if</span> ( (*par).fit_par[0] < minDiff )
+<a name="l00998"></a>00998         {
+<a name="l00999"></a>00999             <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a> (<span class="stringliteral">"sorry, negative peak or signal of line "</span>
+<a name="l01000"></a>01000                                <span class="stringliteral">"too low to fit in row: %d"</span>, row) ;
+<a name="l01001"></a>01001             cpl_free (xdat) ;
+<a name="l01002"></a>01002             cpl_free (wdat) ;
+<a name="l01003"></a>01003             cpl_free (mpar) ;
+<a name="l01004"></a>01004             sinfo_new_destroy_fit_params(&dec_par) ;
+<a name="l01005"></a>01005             sinfo_new_destroy_vector( line ) ;
+<a name="l01006"></a>01006             continue ;
+<a name="l01007"></a>01007         }
+<a name="l01008"></a>01008 
+<a name="l01009"></a>01009         <span class="keywordflow">for</span> ( k = 0 ; k < MAXPAR ; k++ )
+<a name="l01010"></a>01010         {
+<a name="l01011"></a>01011             (*par).derv_par[k] = 0.0 ;
+<a name="l01012"></a>01012             mpar[k] = 1 ;
+<a name="l01013"></a>01013         }
+<a name="l01014"></a>01014 
+<a name="l01015"></a>01015         <span class="comment">/* finally, do the least square fit using a sinfo_gaussian */</span>
+<a name="l01016"></a>01016         <span class="keywordflow">if</span> ( 0 > ( iters = sinfo_new_lsqfit_c( xdat, &xdim, 
+<a name="l01017"></a>01017                                                line -> data, wdat, 
+<a name="l01018"></a>01018                                                &ndat, (*par).fit_par,
+<a name="l01019"></a>01019                                                (*par).derv_par, mpar, 
+<a name="l01020"></a>01020                                                &numpar, &tol, &its, &lab )) )
+<a name="l01021"></a>01021         {
+<a name="l01022"></a>01022             <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a> (<span class="stringliteral">"least squares fit failed in row: "</span>
+<a name="l01023"></a>01023                                <span class="stringliteral">"%d, error no.: %d"</span>, row, iters) ;
+<a name="l01024"></a>01024             cpl_free (xdat) ;
+<a name="l01025"></a>01025             cpl_free (wdat) ;
+<a name="l01026"></a>01026             cpl_free (mpar) ;
+<a name="l01027"></a>01027             sinfo_new_destroy_fit_params(&dec_par) ;
+<a name="l01028"></a>01028             sinfo_new_destroy_vector( line ) ;
+<a name="l01029"></a>01029             continue ;
+<a name="l01030"></a>01030         }
+<a name="l01031"></a>01031 
+<a name="l01032"></a>01032         <span class="comment">/* check for negative fit results */</span>
+<a name="l01033"></a>01033         <span class="keywordflow">if</span> ( (*par).fit_par[0] <= 0. || (*par).fit_par[1] <= 1. ||
+<a name="l01034"></a>01034              (*par).fit_par[2] <= 0. )
+<a name="l01035"></a>01035         {
+<a name="l01036"></a>01036             <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a> (<span class="stringliteral">"negative parameters as fit result, "</span>
+<a name="l01037"></a>01037                                <span class="stringliteral">"not used! in row: %d"</span>, row) ;
+<a name="l01038"></a>01038             cpl_free (xdat) ;
+<a name="l01039"></a>01039             cpl_free (wdat) ;
+<a name="l01040"></a>01040             cpl_free (mpar) ;
+<a name="l01041"></a>01041             sinfo_new_destroy_fit_params(&dec_par) ;
+<a name="l01042"></a>01042             sinfo_new_destroy_vector( line ) ;
+<a name="l01043"></a>01043             continue ;
+<a name="l01044"></a>01044         }
+<a name="l01045"></a>01045 
+<a name="l01046"></a>01046         <span class="comment">/* correct the fitted position for the given row of the line </span>
+<a name="l01047"></a>01047 <span class="comment">           in image coordinates */</span>
+<a name="l01048"></a>01048         x_position[row] =  (float) (column_position[row] - box_length) + 
+<a name="l01049"></a>01049                                    (*par).fit_par[2] ;
+<a name="l01050"></a>01050         printf(<span class="stringliteral">"%d %f %f\n"</span>,row, (*par).fit_par[1], x_position[row] ) ;
+<a name="l01051"></a>01051 
+<a name="l01052"></a>01052         <span class="comment">/* free memory */</span>
+<a name="l01053"></a>01053         sinfo_new_destroy_fit_params(&dec_par) ;
+<a name="l01054"></a>01054         sinfo_new_destroy_vector ( line ) ;
+<a name="l01055"></a>01055         cpl_free ( xdat ) ;
+<a name="l01056"></a>01056         cpl_free ( wdat ) ;
+<a name="l01057"></a>01057         cpl_free ( mpar ) ;
+<a name="l01058"></a>01058     }
+<a name="l01059"></a>01059     <span class="comment">/* now allocate memory for the data to fit */</span>
+<a name="l01060"></a>01060     <span class="keywordflow">if</span> ( NULL == ( list = (dpoint*) cpl_calloc (ly, <span class="keyword">sizeof</span> (dpoint)) ) ) 
+<a name="l01061"></a>01061     {
+<a name="l01062"></a>01062         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"could not allocate memory!"</span>) ;
+<a name="l01063"></a>01063         <span class="keywordflow">return</span> NULL ;
+<a name="l01064"></a>01064     }
+<a name="l01065"></a>01065 
+<a name="l01066"></a>01066     <span class="comment">/* ------------------------------------------------------------------------</span>
+<a name="l01067"></a>01067 <span class="comment">     * now that we have a sub-pixel resolved list of spectral maxima stored </span>
+<a name="l01068"></a>01068 <span class="comment">     * in x_position[row] We can fit a flux weighted straight line to the </span>
+<a name="l01069"></a>01069 <span class="comment">     * positions to determine the spectral column shifts.</span>
+<a name="l01070"></a>01070 <span class="comment">     */</span>
+<a name="l01071"></a>01071     offset = (double) ly/2. ;
+<a name="l01072"></a>01072     ndata = 0 ;
+<a name="l01073"></a>01073     <span class="keywordflow">for</span> ( row = 0 ; row < ly ; row++ )
+<a name="l01074"></a>01074     {
+<a name="l01075"></a>01075         <span class="keywordflow">if</span> ( x_position[row] == 0. )
+<a name="l01076"></a>01076         {
+<a name="l01077"></a>01077             continue ;
+<a name="l01078"></a>01078         }
+<a name="l01079"></a>01079         <span class="keywordflow">else</span> 
+<a name="l01080"></a>01080         {
+<a name="l01081"></a>01081             list[ndata].y   = (double)x_position[row] ;
+<a name="l01082"></a>01082             list[ndata].x   = (double)row - offset ;
+<a name="l01083"></a>01083             ndata++ ;
+<a name="l01084"></a>01084         }
+<a name="l01085"></a>01085     }
+<a name="l01086"></a>01086     
+<a name="l01087"></a>01087 
+<a name="l01088"></a>01088     <span class="keywordflow">if</span> ( NULL == (coeffs = sinfo_fit_1d_poly(order, list, ndata, NULL)) )
+<a name="l01089"></a>01089     {
+<a name="l01090"></a>01090         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"eclipse function sinfo_fit_1d_poly() did not work!"</span>) ;
+<a name="l01091"></a>01091         <span class="keywordflow">return</span> NULL ;
+<a name="l01092"></a>01092     }
+<a name="l01093"></a>01093     cpl_free ( list ) ;
+<a name="l01094"></a>01094 
+<a name="l01095"></a>01095 
+<a name="l01096"></a>01096 
+<a name="l01097"></a>01097     cpl_free(col_value) ;
+<a name="l01098"></a>01098     cpl_free(column_value) ;
+<a name="l01099"></a>01099     cpl_free(col_position) ;
+<a name="l01100"></a>01100     cpl_free(column_position) ;
+<a name="l01101"></a>01101     cpl_free(x_position) ;
+<a name="l01102"></a>01102      
+<a name="l01103"></a>01103     <span class="keywordflow">return</span> coeffs ;
+<a name="l01104"></a>01104 }
+<a name="l01105"></a>01105 
+<a name="l01114"></a>01114 cpl_image * 
+<a name="l01115"></a>01115 sinfo_new_image_warp_fits( cpl_image * image,
+<a name="l01116"></a>01116                       <span class="keywordtype">char</span>      * kernel_type, 
+<a name="l01117"></a>01117                       <span class="keywordtype">char</span>      * poly_table )
+<a name="l01118"></a>01118 {
+<a name="l01119"></a>01119         cpl_image  * warped=NULL;
+<a name="l01120"></a>01120     <span class="comment">/* Following are for polynomial transforms */</span>
+<a name="l01121"></a>01121     cpl_polynomial    * poly_u=NULL;        <span class="comment">/* polynomial definition */</span>
+<a name="l01122"></a>01122     cpl_polynomial    * poly_v=NULL;        <span class="comment">/* polynomial definition */</span>
+<a name="l01123"></a>01123         cpl_table* poly_tbl=NULL;
+<a name="l01124"></a>01124     cpl_vector      *   profile=NULL ;
+<a name="l01125"></a>01125         cpl_size local_pow[2];
+<a name="l01126"></a>01126         <span class="keywordtype">int</span>             i=0;
+<a name="l01127"></a>01127 
+<a name="l01128"></a>01128     <span class="comment">/*fscanf(poly_in,"%s",poly_string);*/</span>
+<a name="l01129"></a>01129     <span class="comment">/* sinfo_msg("%s",poly_string); */</span>
+<a name="l01130"></a>01130     
+<a name="l01131"></a>01131     poly_u = cpl_polynomial_new(2);
+<a name="l01132"></a>01132         <span class="keywordflow">if</span> (poly_u == NULL) {
+<a name="l01133"></a>01133             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"cannot read 2D poly from arc table"</span>) ;
+<a name="l01134"></a>01134             <span class="keywordflow">return</span> NULL ;
+<a name="l01135"></a>01135         }
+<a name="l01136"></a>01136  
+<a name="l01137"></a>01137         <span class="keywordflow">if</span> (poly_u != NULL) {
+<a name="l01138"></a>01138       <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"Get the arc distortion from the file %s"</span>,
+<a name="l01139"></a>01139                           poly_table);
+<a name="l01140"></a>01140       <span class="keywordflow">if</span>(sinfo_is_fits_file(poly_table) != 1) {
+<a name="l01141"></a>01141         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Input file %s is not FITS"</span>,poly_table);
+<a name="l01142"></a>01142         <span class="keywordflow">return</span> NULL;
+<a name="l01143"></a>01143       }
+<a name="l01144"></a>01144 
+<a name="l01145"></a>01145       <span class="keywordflow">if</span>(NULL==(poly_tbl = cpl_table_load(poly_table,1,0))) {
+<a name="l01146"></a>01146         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"cannot load the arc table"</span>) ;
+<a name="l01147"></a>01147         cpl_polynomial_delete(poly_u) ;
+<a name="l01148"></a>01148         <span class="keywordflow">return</span> NULL ;
+<a name="l01149"></a>01149       }
+<a name="l01150"></a>01150 
+<a name="l01151"></a>01151       <span class="keywordflow">for</span> (i=0 ; i<cpl_table_get_nrow(poly_tbl) ; i++) {
+<a name="l01152"></a>01152             local_pow[0] = cpl_table_get_int(poly_tbl, <span class="stringliteral">"degx"</span>, i, NULL) ; 
+<a name="l01153"></a>01153             local_pow[1] = cpl_table_get_int(poly_tbl, <span class="stringliteral">"degy"</span>, i, NULL) ;
+<a name="l01154"></a>01154             cpl_polynomial_set_coeff(poly_u, local_pow,
+<a name="l01155"></a>01155            cpl_table_get_double(poly_tbl, <span class="stringliteral">"coeff"</span>, i, NULL)) ;
+<a name="l01156"></a>01156       }
+<a name="l01157"></a>01157 
+<a name="l01158"></a>01158       cpl_table_delete(poly_tbl) ;
+<a name="l01159"></a>01159     } <span class="keywordflow">else</span> {
+<a name="l01160"></a>01160       sinfo_msg(<span class="stringliteral">"Use the ID polynomial for the arc dist"</span>) ;
+<a name="l01161"></a>01161       local_pow[0] = 1 ;
+<a name="l01162"></a>01162       local_pow[1] = 0 ;
+<a name="l01163"></a>01163       cpl_polynomial_set_coeff(poly_u, local_pow, 1.0) ;
+<a name="l01164"></a>01164     }
+<a name="l01165"></a>01165 
+<a name="l01166"></a>01166         poly_v=cpl_polynomial_new(2);
+<a name="l01167"></a>01167         local_pow[0]=0;
+<a name="l01168"></a>01168         local_pow[1]=1;
+<a name="l01169"></a>01169 
+<a name="l01170"></a>01170         cpl_polynomial_set_coeff(poly_v,local_pow,1.0);
+<a name="l01171"></a>01171     profile = cpl_vector_new(CPL_KERNEL_DEF_SAMPLES) ;
+<a name="l01172"></a>01172     cpl_vector_fill_kernel_profile(profile, CPL_KERNEL_TANH,
+<a name="l01173"></a>01173                        CPL_KERNEL_DEF_WIDTH) ;
+<a name="l01174"></a>01174     warped=sinfo_new_warp_image_generic(image,kernel_type,poly_u,poly_v);
+<a name="l01175"></a>01175     <span class="comment">/* YVES WAY </span>
+<a name="l01176"></a>01176 <span class="comment">      warped = cpl_image_new(cpl_image_get_size_x(image),</span>
+<a name="l01177"></a>01177 <span class="comment">                                 cpl_image_get_size_y(image),</span>
+<a name="l01178"></a>01178 <span class="comment">                                 CPL_TYPE_FLOAT);</span>
+<a name="l01179"></a>01179 <span class="comment">       </span>
+<a name="l01180"></a>01180 <span class="comment">    if (cpl_image_warp_polynomial(warped, image, poly_u, poly_v, </span>
+<a name="l01181"></a>01181 <span class="comment">                      profile,CPL_KERNEL_DEF_WIDTH,</span>
+<a name="l01182"></a>01182 <span class="comment">                      profile,CPL_KERNEL_DEF_WIDTH)</span>
+<a name="l01183"></a>01183 <span class="comment">        != CPL_ERROR_NONE) {</span>
+<a name="l01184"></a>01184 <span class="comment">            sinfo_msg_error("cannot correct the distortion") ;</span>
+<a name="l01185"></a>01185 <span class="comment">            cpl_image_delete(warped) ;</span>
+<a name="l01186"></a>01186 <span class="comment">            cpl_polynomial_delete(poly_u) ;</span>
+<a name="l01187"></a>01187 <span class="comment">            cpl_polynomial_delete(poly_v) ;</span>
+<a name="l01188"></a>01188 <span class="comment">            cpl_vector_delete(profile) ;</span>
+<a name="l01189"></a>01189 <span class="comment">            return NULL;</span>
+<a name="l01190"></a>01190 <span class="comment">    }</span>
+<a name="l01191"></a>01191 <span class="comment">    */</span>
+<a name="l01192"></a>01192 
+<a name="l01193"></a>01193       cpl_vector_delete(profile) ;
+<a name="l01194"></a>01194       <span class="keywordflow">if</span> (poly_u!=NULL) cpl_polynomial_delete(poly_u);
+<a name="l01195"></a>01195       <span class="keywordflow">if</span> (poly_v!=NULL) cpl_polynomial_delete(poly_v);
+<a name="l01196"></a>01196     
+<a name="l01197"></a>01197       <span class="keywordflow">return</span> warped;
+<a name="l01198"></a>01198 }
+<a name="l01199"></a>01199     
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__coltilt_8h_source.html b/html/sinfo__coltilt_8h_source.html
new file mode 100644
index 0000000..3b2abc0
--- /dev/null
+++ b/html/sinfo__coltilt_8h_source.html
@@ -0,0 +1,118 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_coltilt.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_coltilt.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#ifndef SINFO_COLTILT_H</span>
+<a name="l00002"></a>00002 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_COLTILT_H</span>
+<a name="l00003"></a>00003 <span class="preprocessor"></span><span class="comment">/*</span>
+<a name="l00004"></a>00004 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00005"></a>00005 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00006"></a>00006 <span class="comment"> *</span>
+<a name="l00007"></a>00007 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00008"></a>00008 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00009"></a>00009 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00010"></a>00010 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00011"></a>00011 <span class="comment"> *</span>
+<a name="l00012"></a>00012 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00013"></a>00013 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00014"></a>00014 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00015"></a>00015 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00016"></a>00016 <span class="comment"> *</span>
+<a name="l00017"></a>00017 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00018"></a>00018 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00019"></a>00019 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00020"></a>00020 <span class="comment"> */</span>
+<a name="l00021"></a>00021 <span class="comment">/*******************************************************************************</span>
+<a name="l00022"></a>00022 <span class="comment">* E.S.O. - VLT project</span>
+<a name="l00023"></a>00023 <span class="comment">*</span>
+<a name="l00024"></a>00024 <span class="comment">* "@(#) $Id: sinfo_coltilt.h,v 1.4 2007/06/06 07:10:45 amodigli Exp $"</span>
+<a name="l00025"></a>00025 <span class="comment">*</span>
+<a name="l00026"></a>00026 <span class="comment">* who       when      what</span>
+<a name="l00027"></a>00027 <span class="comment">* --------  --------  ----------------------------------------------</span>
+<a name="l00028"></a>00028 <span class="comment">* schreib  20/12/00  created</span>
+<a name="l00029"></a>00029 <span class="comment">*/</span>
+<a name="l00030"></a>00030 
+<a name="l00031"></a>00031 <span class="comment">/************************************************************************</span>
+<a name="l00032"></a>00032 <span class="comment"> * sinfo_coltilt.h</span>
+<a name="l00033"></a>00033 <span class="comment"> * routines to calculate and correct the spatial tilt of spectra in raw images</span>
+<a name="l00034"></a>00034 <span class="comment"> *----------------------------------------------------------------------</span>
+<a name="l00035"></a>00035 <span class="comment"> */</span>
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="comment">/*</span>
+<a name="l00038"></a>00038 <span class="comment"> * header files</span>
+<a name="l00039"></a>00039 <span class="comment"> */</span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include <cpl.h></span> 
+<a name="l00041"></a>00041 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include "sinfo_recipes.h"</span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include "sinfo_wave_calibration.h"</span>
+<a name="l00044"></a>00044 <span class="preprocessor">#include "sinfo_spiffi_types.h"</span>
+<a name="l00045"></a>00045 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00046"></a>00046 <span class="comment"> *                        Function ANSI C prototypes</span>
+<a name="l00047"></a>00047 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00048"></a>00048 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00049"></a>00049 <span class="comment">   @name   sinfo_new_slope_of_spectrum()</span>
+<a name="l00050"></a>00050 <span class="comment">   @param  ns_image   image with at least one continuum spectrum of a pinhole</span>
+<a name="l00051"></a>00051 <span class="comment">   @param  box_length width of the box in which the lines are fit by a Gaussian</span>
+<a name="l00052"></a>00052 <span class="comment">   @param  fwhm       first guess of the full width at half maximum</span>
+<a name="l00053"></a>00053 <span class="comment">   @param  min_amplitude_factor factor peak/background below given threshold </span>
+<a name="l00054"></a>00054 <span class="comment">           the fit is not carried through</span>
+<a name="l00055"></a>00055 <span class="comment">   @return slope of a straight line fitted to the spectrum. -FLT_MAX if </span>
+<a name="l00056"></a>00056 <span class="comment">           something went wrong.</span>
+<a name="l00057"></a>00057 <span class="comment">   @doc    determines the sub-pixel shifts of each row by using an image with </span>
+<a name="l00058"></a>00058 <span class="comment">           at least one continuum spectrum of a pinhole this is done by </span>
+<a name="l00059"></a>00059 <span class="comment">           searching the spectrum within the image then fitting the spectrum </span>
+<a name="l00060"></a>00060 <span class="comment">           along the rows within a given box by a Gaussian, so that the exact </span>
+<a name="l00061"></a>00061 <span class="comment">           position is determined for each row. Afterwards, a straight line is </span>
+<a name="l00062"></a>00062 <span class="comment">           fitted through the fitted positions. The slope of this linear fit </span>
+<a name="l00063"></a>00063 <span class="comment">           is returned.</span>
+<a name="l00064"></a>00064 <span class="comment">*/</span>
+<a name="l00065"></a>00065 
+<a name="l00066"></a>00066 <span class="keywordtype">float</span> 
+<a name="l00067"></a>00067 sinfo_new_slope_of_spectrum(cpl_image * ns_image,
+<a name="l00068"></a>00068                        <span class="keywordtype">int</span>        box_length,
+<a name="l00069"></a>00069                        <span class="keywordtype">float</span>      fwhm,
+<a name="l00070"></a>00070                        <span class="keywordtype">float</span>      min_amplitude_factor ) ;
+<a name="l00071"></a>00071 
+<a name="l00084"></a>00084 cpl_image * 
+<a name="l00085"></a>00085 sinfo_new_shift_rows(cpl_image * image,
+<a name="l00086"></a>00086              <span class="keywordtype">float</span>      slope,
+<a name="l00087"></a>00087              <span class="keywordtype">int</span>        n_order ) ;
+<a name="l00088"></a>00088 
+<a name="l00089"></a>00089 
+<a name="l00100"></a>00100 <span class="keywordtype">void</span> 
+<a name="l00101"></a>00101 sinfo_new_parameter_to_ascii ( <span class="keywordtype">float</span> * parameter,
+<a name="l00102"></a>00102                         <span class="keywordtype">int</span> n,
+<a name="l00103"></a>00103                         <span class="keywordtype">char</span> * filename ) ;
+<a name="l00104"></a>00104 
+<a name="l00105"></a>00105 
+<a name="l00113"></a>00113 <span class="keywordtype">float</span> * 
+<a name="l00114"></a>00114 sinfo_new_ascii_to_parameter ( <span class="keywordtype">char</span> * filename,
+<a name="l00115"></a>00115                            <span class="keywordtype">int</span>  * n ) ;
+<a name="l00116"></a>00116 
+<a name="l00139"></a>00139 <span class="keywordtype">double</span> * 
+<a name="l00140"></a>00140 sinfo_new_curvature_of_spectrum(cpl_image * ns_image,
+<a name="l00141"></a>00141                 <span class="keywordtype">int</span>        order, 
+<a name="l00142"></a>00142              <span class="keywordtype">int</span>        box_length,
+<a name="l00143"></a>00143              <span class="keywordtype">int</span>        left_pos,
+<a name="l00144"></a>00144                          <span class="keywordtype">int</span>        right_pos,
+<a name="l00145"></a>00145                          <span class="keywordtype">float</span>      fwhm,
+<a name="l00146"></a>00146                          <span class="keywordtype">float</span>      min_amplitude_factor ) ;
+<a name="l00147"></a>00147 
+<a name="l00156"></a>00156 cpl_image * 
+<a name="l00157"></a>00157 sinfo_new_image_warp_fits(cpl_image * image,
+<a name="l00158"></a>00158                       <span class="keywordtype">char</span>      * kernel_type, 
+<a name="l00159"></a>00159                       <span class="keywordtype">char</span>      * poly_table );
+<a name="l00160"></a>00160 
+<a name="l00161"></a>00161 <span class="preprocessor">#endif </span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__companion_8c_source.html b/html/sinfo__companion_8c_source.html
new file mode 100644
index 0000000..d543741
--- /dev/null
+++ b/html/sinfo__companion_8c_source.html
@@ -0,0 +1,54 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_companion.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_companion.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00020"></a>00020 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00021"></a>00021 <span class="preprocessor">#endif</span>
+<a name="l00022"></a>00022 <span class="preprocessor"></span><span class="preprocessor">#include "sinfo_solve_poly_root.h"</span>
+<a name="l00023"></a>00023 
+<a name="l00039"></a>00039 <span class="keywordtype">void</span>
+<a name="l00040"></a>00040 sinfo_set_companion_matrix (<span class="keyword">const</span> <span class="keywordtype">double</span> *a, <span class="keywordtype">size_t</span> nc, <span class="keywordtype">double</span> *m)
+<a name="l00041"></a>00041 {
+<a name="l00042"></a>00042   <span class="keywordtype">size_t</span> i, j;
+<a name="l00043"></a>00043 
+<a name="l00044"></a>00044   <span class="keywordflow">for</span> (i = 0; i < nc; i++)
+<a name="l00045"></a>00045     <span class="keywordflow">for</span> (j = 0; j < nc; j++)
+<a name="l00046"></a>00046       MAT (m, i, j, nc) = 0.0;
+<a name="l00047"></a>00047 
+<a name="l00048"></a>00048   <span class="keywordflow">for</span> (i = 1; i < nc; i++)
+<a name="l00049"></a>00049     MAT (m, i, i - 1, nc) = 1.0;
+<a name="l00050"></a>00050 
+<a name="l00051"></a>00051   <span class="keywordflow">for</span> (i = 0; i < nc; i++)
+<a name="l00052"></a>00052     MAT (m, i, nc - 1, nc) = -a[i] / a[nc];
+<a name="l00053"></a>00053 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__compare__tags_8h_source.html b/html/sinfo__compare__tags_8h_source.html
new file mode 100644
index 0000000..fb41261
--- /dev/null
+++ b/html/sinfo__compare__tags_8h_source.html
@@ -0,0 +1,44 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_compare_tags.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_compare_tags.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="preprocessor">#ifndef SINFO_COMPARE_TAGS_H</span>
+<a name="l00020"></a>00020 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_COMPARE_TAGS_H</span>
+<a name="l00021"></a>00021 <span class="preprocessor"></span><span class="preprocessor">#include <cpl.h></span>
+<a name="l00022"></a>00022 <span class="preprocessor">#include <string.h></span>
+<a name="l00023"></a>00023 <span class="preprocessor">#include <strings.h></span>
+<a name="l00024"></a>00024 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00031"></a>00031 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00032"></a>00032 <span class="keywordtype">int</span> 
+<a name="l00033"></a>00033 compare_tags(cpl_frame   *   frame1,cpl_frame   *   frame2);
+<a name="l00034"></a>00034 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__cpl__size_8h_source.html b/html/sinfo__cpl__size_8h_source.html
new file mode 100644
index 0000000..c700b00
--- /dev/null
+++ b/html/sinfo__cpl__size_8h_source.html
@@ -0,0 +1,33 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_cpl_size.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_cpl_size.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * sinfo_cpl_size.h</span>
+<a name="l00003"></a>00003 <span class="comment"> *</span>
+<a name="l00004"></a>00004 <span class="comment"> *  Created on: Nov 23, 2011</span>
+<a name="l00005"></a>00005 <span class="comment"> *      Author: amodigli</span>
+<a name="l00006"></a>00006 <span class="comment"> */</span>
+<a name="l00007"></a>00007 
+<a name="l00008"></a>00008 <span class="preprocessor">#ifndef SINFO_CPL_SIZE_H_</span>
+<a name="l00009"></a>00009 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_CPL_SIZE_H_</span>
+<a name="l00010"></a>00010 <span class="preprocessor"></span>
+<a name="l00011"></a>00011 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00012"></a>00012 <span class="preprocessor">#if defined CPL_VERSION_CODE && CPL_VERSION_CODE <= CPL_VERSION(5, 5, 0)</span>
+<a name="l00013"></a>00013 <span class="preprocessor"></span><span class="keyword">typedef</span> <span class="keywordtype">int</span> cpl_size; <span class="comment">/* The type as is was up to CPL 5.3 */</span>
+<a name="l00014"></a>00014 <span class="preprocessor">#define CPL_SIZE_FORMAT "d"</span>
+<a name="l00015"></a>00015 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
+<a name="l00016"></a>00016 <span class="preprocessor"></span>
+<a name="l00017"></a>00017 <span class="preprocessor">#endif </span><span class="comment">/* SINFO_CPL_SIZE_H_ */</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__cube__construct_8c_source.html b/html/sinfo__cube__construct_8c_source.html
new file mode 100644
index 0000000..25e3ab0
--- /dev/null
+++ b/html/sinfo__cube__construct_8c_source.html
@@ -0,0 +1,3268 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_cube_construct.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_cube_construct.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/************************************************************************</span>
+<a name="l00020"></a>00020 <span class="comment">* E.S.O. - VLT project</span>
+<a name="l00021"></a>00021 <span class="comment">*</span>
+<a name="l00022"></a>00022 <span class="comment">*</span>
+<a name="l00023"></a>00023 <span class="comment">*</span>
+<a name="l00024"></a>00024 <span class="comment">* who       when      what</span>
+<a name="l00025"></a>00025 <span class="comment">* --------  --------  ----------------------------------------------</span>
+<a name="l00026"></a>00026 <span class="comment">* schreib  30/08/00  created</span>
+<a name="l00027"></a>00027 <span class="comment">*/</span>
+<a name="l00028"></a>00028 
+<a name="l00029"></a>00029 <span class="comment">/************************************************************************</span>
+<a name="l00030"></a>00030 <span class="comment">*   NAME</span>
+<a name="l00031"></a>00031 <span class="comment">*        sinfo_cube_construct.c -</span>
+<a name="l00032"></a>00032 <span class="comment">*        some procedures to construct a data cube</span>
+<a name="l00033"></a>00033 <span class="comment">*</span>
+<a name="l00034"></a>00034 <span class="comment">*   SYNOPSIS</span>
+<a name="l00035"></a>00035 <span class="comment">*</span>
+<a name="l00036"></a>00036 <span class="comment">*   1) cpl_image * sinfo_new_convolve_ns_image_by_gauss( cpl_image * lineImage,</span>
+<a name="l00037"></a>00037 <span class="comment">*                                         int        hw )</span>
+<a name="l00038"></a>00038 <span class="comment">*</span>
+<a name="l00039"></a>00039 <span class="comment">*   2) float * sinfo_north_south_test( cpl_image * ns_image,</span>
+<a name="l00040"></a>00040 <span class="comment">*                                int        n_slitlets,</span>
+<a name="l00041"></a>00041 <span class="comment">*                                int        halfWidth,</span>
+<a name="l00042"></a>00042 <span class="comment">*                                float      fwhm,</span>
+<a name="l00043"></a>00043 <span class="comment">*                                float      minDiff,</span>
+<a name="l00044"></a>00044 <span class="comment">*                                float      estimated_dist,</span>
+<a name="l00045"></a>00045 <span class="comment">*                                float      devtol )</span>
+<a name="l00046"></a>00046 <span class="comment">*</span>
+<a name="l00047"></a>00047 <span class="comment">*   3) cpl_imagelist * sinfo_new_make_cube ( cpl_image * calibImage,</span>
+<a name="l00048"></a>00048 <span class="comment">*                           float    * distances,</span>
+<a name="l00049"></a>00049 <span class="comment">*                           float    * correct_diff_dist )</span>
+<a name="l00050"></a>00050 <span class="comment">*</span>
+<a name="l00051"></a>00051 <span class="comment">*   4) cpl_imagelist * sinfo_new_make_cube_spi ( cpl_image *  calibImage,</span>
+<a name="l00052"></a>00052 <span class="comment">*                              float    ** slit_edges,</span>
+<a name="l00053"></a>00053 <span class="comment">*                              float    *  shift )</span>
+<a name="l00054"></a>00054 <span class="comment">*</span>
+<a name="l00055"></a>00055 <span class="comment">*   5) cpl_imagelist * sinfo_new_make_cube_dist ( cpl_image * calibImage,</span>
+<a name="l00056"></a>00056 <span class="comment">*                               float      firstCol,</span>
+<a name="l00057"></a>00057 <span class="comment">*                               float    * distances,</span>
+<a name="l00058"></a>00058 <span class="comment">*                               float    * shift )</span>
+<a name="l00059"></a>00059 <span class="comment">*</span>
+<a name="l00060"></a>00060 <span class="comment">*   6) cpl_imagelist * sinfo_new_make_3D_cube_dist ( cpl_image * calibImage,</span>
+<a name="l00061"></a>00061 <span class="comment">*                                 float      firstCol,</span>
+<a name="l00062"></a>00062 <span class="comment">*                                 float    * distances,</span>
+<a name="l00063"></a>00063 <span class="comment">*                                 float    * shift )</span>
+<a name="l00064"></a>00064 <span class="comment">*</span>
+<a name="l00065"></a>00065 <span class="comment">*   7) cpl_imagelist * sinfo_new_make_3D_cube ( cpl_image * calibImage,</span>
+<a name="l00066"></a>00066 <span class="comment">*                             int      * kpixshift,  </span>
+<a name="l00067"></a>00067 <span class="comment">*                             int        kpixfirst )</span>
+<a name="l00068"></a>00068 <span class="comment">*</span>
+<a name="l00069"></a>00069 <span class="comment">*   8) cpl_imagelist * </span>
+<a name="l00070"></a>00070 <span class="comment">       sinfo_new_determine_mask_cube(cpl_imagelist * sourceMaskCube,</span>
+<a name="l00071"></a>00071 <span class="comment">*                                    float     lowLimit,</span>
+<a name="l00072"></a>00072 <span class="comment">*                                    float     highLimit )</span>
+<a name="l00073"></a>00073 <span class="comment">*</span>
+<a name="l00074"></a>00074 <span class="comment">*   9) cpl_imagelist * sinfo_new_interpol_cube ( cpl_imagelist * sourceCube,</span>
+<a name="l00075"></a>00075 <span class="comment">*                               cpl_imagelist * maskCube,</span>
+<a name="l00076"></a>00076 <span class="comment">*                               int       n_neighbors, </span>
+<a name="l00077"></a>00077 <span class="comment">*                               int       max_radius )</span>
+<a name="l00078"></a>00078 <span class="comment">*</span>
+<a name="l00079"></a>00079 <span class="comment">*   10) cpl_imagelist * sinfo_new_fine_tune_cube( cpl_imagelist * cube,</span>
+<a name="l00080"></a>00080 <span class="comment">*                              float   * correct_diff_dist )</span>
+<a name="l00081"></a>00081 <span class="comment">*</span>
+<a name="l00082"></a>00082 <span class="comment">*   11) cpl_imagelist * sinfo_new_fine_tune_cube_by_FFT( cpl_imagelist * cube,</span>
+<a name="l00083"></a>00083 <span class="comment">*                                   float   * correct_diff_dist )</span>
+<a name="l00084"></a>00084 <span class="comment">*</span>
+<a name="l00085"></a>00085 <span class="comment">*   12) cpl_imagelist * sinfo_new_fine_tune_cube_by_spline(cpl_imagelist * cube,</span>
+<a name="l00086"></a>00086 <span class="comment">*                                        float   * correct_diff_dist )</span>
+<a name="l00087"></a>00087 <span class="comment">*</span>
+<a name="l00088"></a>00088 <span class="comment">*   DESCRIPTION</span>
+<a name="l00089"></a>00089 <span class="comment">*</span>
+<a name="l00090"></a>00090 <span class="comment">*   1) convolves a north-south-test image with a sinfo_gaussian</span>
+<a name="l00091"></a>00091 <span class="comment">*      with user given integer half width by using the eclipse</span>
+<a name="l00092"></a>00092 <span class="comment">*      routine sinfo_function1d_filter_lowpass().</span>
+<a name="l00093"></a>00093 <span class="comment">*   2) determines the distances of the slitlets</span>
+<a name="l00094"></a>00094 <span class="comment">*   3) makes a data cube out of a resampled source image</span>
+<a name="l00095"></a>00095 <span class="comment">*      this SPIFFI specific routine takes into account the</span>
+<a name="l00096"></a>00096 <span class="comment">*      Spiffi slitlet order on the detector.</span>
+<a name="l00097"></a>00097 <span class="comment">*      Also shifts the resulting image rows by one pixel if</span>
+<a name="l00098"></a>00098 <span class="comment">*      necessary according to the distances array gained from</span>
+<a name="l00099"></a>00099 <span class="comment">*      the north-south test routine.</span>
+<a name="l00100"></a>00100 <span class="comment">*      Can do the same with the bad pixel map image to generate a</span>
+<a name="l00101"></a>00101 <span class="comment">*      bad pixel mask cube.</span>
+<a name="l00102"></a>00102 <span class="comment">*   4) makes a data cube out of a resampled source image</span>
+<a name="l00103"></a>00103 <span class="comment">*      this SPIFFI specific routine takes into account the</span>
+<a name="l00104"></a>00104 <span class="comment">*      Spiffi slitlet order on the detector.</span>
+<a name="l00105"></a>00105 <span class="comment">*      This routine takes fitted slitlet positions into account.</span>
+<a name="l00106"></a>00106 <span class="comment">*      Can do the same with the bad pixel map image to generate a</span>
+<a name="l00107"></a>00107 <span class="comment">*      bad pixel mask cube.</span>
+<a name="l00108"></a>00108 <span class="comment">*   5) makes a data cube out of a resampled source image</span>
+<a name="l00109"></a>00109 <span class="comment">*      this SPIFFI specific routine takes into account the</span>
+<a name="l00110"></a>00110 <span class="comment">*      Spiffi slitlet order on the detector.</span>
+<a name="l00111"></a>00111 <span class="comment">*      Also shifts the resulting image rows by one pixel if</span>
+<a name="l00112"></a>00112 <span class="comment">*      necessary according to the distances array gained from</span>
+<a name="l00113"></a>00113 <span class="comment">*      the north-south test routine.</span>
+<a name="l00114"></a>00114 <span class="comment">*      Can do the same with the bad pixel map image to generate a</span>
+<a name="l00115"></a>00115 <span class="comment">*      bad pixel mask cube.</span>
+<a name="l00116"></a>00116 <span class="comment">*   6) makes a data cube out of a resampled source image</span>
+<a name="l00117"></a>00117 <span class="comment">*      this 3D specific routine takes into account the</span>
+<a name="l00118"></a>00118 <span class="comment">*      3D slitlet order on the detector.</span>
+<a name="l00119"></a>00119 <span class="comment">*      Also shifts the resulting image rows by one pixel if</span>
+<a name="l00120"></a>00120 <span class="comment">*      necessary according to the distances array gained from</span>
+<a name="l00121"></a>00121 <span class="comment">*      the north-south test routine.</span>
+<a name="l00122"></a>00122 <span class="comment">*      Can do the same with the bad pixel map image to generate a</span>
+<a name="l00123"></a>00123 <span class="comment">*      bad pixel mask cube.</span>
+<a name="l00124"></a>00124 <span class="comment">*   7) makes a data cube out of a resampled source image</span>
+<a name="l00125"></a>00125 <span class="comment">*      this MPE 3D specific routine takes into account the</span>
+<a name="l00126"></a>00126 <span class="comment">*      3D slitlet order on the detector.</span>
+<a name="l00127"></a>00127 <span class="comment">*      Also shifts the resulting image row by an integer pixel shift if</span>
+<a name="l00128"></a>00128 <span class="comment">*      necessary according to the input kpixshift array </span>
+<a name="l00129"></a>00129 <span class="comment">*      Can do the same with the bad pixel map image to generate a</span>
+<a name="l00130"></a>00130 <span class="comment">*      bad pixel mask cube.</span>
+<a name="l00131"></a>00131 <span class="comment">*   8) converts resampled bad pixels to real bad pixels in data cubes.</span>
+<a name="l00132"></a>00132 <span class="comment">*   9) Bad pixel interpolation 3D like (saturated pixels exist):</span>
+<a name="l00133"></a>00133 <span class="comment">*      interpolates the bad pixels of the source cube by</span>
+<a name="l00134"></a>00134 <span class="comment">*      using the nearest neighbors. </span>
+<a name="l00135"></a>00135 <span class="comment">*      first it is checked if the bad pixel is interpolatable:</span>
+<a name="l00136"></a>00136 <span class="comment">*      it is only interpolatable if the number of good pixels </span>
+<a name="l00137"></a>00137 <span class="comment">*      in its spectrum of length 2*n_neighbors+1 exceeds 3 and</span>
+<a name="l00138"></a>00138 <span class="comment">*      if there is at least one good pixel on either side of the</span>
+<a name="l00139"></a>00139 <span class="comment">*      central pixel.</span>
+<a name="l00140"></a>00140 <span class="comment">*      Afterwards good neighboring pixels are searched within the </span>
+<a name="l00141"></a>00141 <span class="comment">*      image plane of the bad pixel by using an increasing pixel radius. </span>
+<a name="l00142"></a>00142 <span class="comment">*      Good pixels mean, the corresponding spectral pixels of the </span>
+<a name="l00143"></a>00143 <span class="comment">*      bad pixel and its spatial neighboring pixel must have</span>
+<a name="l00144"></a>00144 <span class="comment">*      at least 2 valid pixel pairs to be able to be used for</span>
+<a name="l00145"></a>00145 <span class="comment">*      the interpolation. The search is stopped if 9 valid neighboring</span>
+<a name="l00146"></a>00146 <span class="comment">*      pixels are found. </span>
+<a name="l00147"></a>00147 <span class="comment">*      Now normalize the found spectral values, collect the valid pixels </span>
+<a name="l00148"></a>00148 <span class="comment">*      (there must be at least 18) and take the sinfo_median of the valid </span>
+<a name="l00149"></a>00149 <span class="comment">*      pixels with which the bad pixel is replaced.</span>
+<a name="l00150"></a>00150 <span class="comment">*   10) fine tunes each row in the right position according </span>
+<a name="l00151"></a>00151 <span class="comment">*      to the distances of the slitlets to each other</span>
+<a name="l00152"></a>00152 <span class="comment">*      (output of the north-south test).</span>
+<a name="l00153"></a>00153 <span class="comment">*      This means that the rows must be realigned by a </span>
+<a name="l00154"></a>00154 <span class="comment">*      fraction of a pixel to accomodate non-integer slit </span>
+<a name="l00155"></a>00155 <span class="comment">*      length. The fractional realignment is done by using</span>
+<a name="l00156"></a>00156 <span class="comment">*      the polynomial interpolation algorithm of N.R. </span>
+<a name="l00157"></a>00157 <span class="comment">*      Each row is rescaled so that the total flux is</span>
+<a name="l00158"></a>00158 <span class="comment">*      conserved.</span>
+<a name="l00159"></a>00159 <span class="comment">*  11) fine tunes each row in the right position according </span>
+<a name="l00160"></a>00160 <span class="comment">*      to the distances of the slitlets to each other</span>
+<a name="l00161"></a>00161 <span class="comment">*      (output of the north-south test).</span>
+<a name="l00162"></a>00162 <span class="comment">*      This means that the rows must be realigned by a </span>
+<a name="l00163"></a>00163 <span class="comment">*      fraction of a pixel to accomodate non-integer slit </span>
+<a name="l00164"></a>00164 <span class="comment">*      length. The fractional realignment is done by using</span>
+<a name="l00165"></a>00165 <span class="comment">*      the FFT algorithm four1() of N.R. </span>
+<a name="l00166"></a>00166 <span class="comment">*  12) fine tunes each row in the right position according </span>
+<a name="l00167"></a>00167 <span class="comment">*      to the distances of the slitlets to each other</span>
+<a name="l00168"></a>00168 <span class="comment">*      (output of the north-south test).</span>
+<a name="l00169"></a>00169 <span class="comment">*      This means that the rows must be realigned by a </span>
+<a name="l00170"></a>00170 <span class="comment">*      fraction of a pixel to accomodate non-integer slit </span>
+<a name="l00171"></a>00171 <span class="comment">*      length. The fractional realignment is done by using</span>
+<a name="l00172"></a>00172 <span class="comment">*      the spline interpolation algorithm splint in connection</span>
+<a name="l00173"></a>00173 <span class="comment">*      with the algorithm spline of N.R. </span>
+<a name="l00174"></a>00174 <span class="comment">*      This algorithms assume that each row is a tabulated</span>
+<a name="l00175"></a>00175 <span class="comment">*      function. The first derivatives of the interpolating</span>
+<a name="l00176"></a>00176 <span class="comment">*      function at the first and last point must be given.</span>
+<a name="l00177"></a>00177 <span class="comment">*      These are set higher than 1xe^30, so the routine</span>
+<a name="l00178"></a>00178 <span class="comment">*      sets the corresponding boundary condition for a natural</span>
+<a name="l00179"></a>00179 <span class="comment">*      spline, with zero second derivative on that boundary.</span>
+<a name="l00180"></a>00180 <span class="comment">*      Each row is rescaled so that the total flux is</span>
+<a name="l00181"></a>00181 <span class="comment">*      conserved.</span>
+<a name="l00182"></a>00182 <span class="comment">*</span>
+<a name="l00183"></a>00183 <span class="comment">*   FILES</span>
+<a name="l00184"></a>00184 <span class="comment">*</span>
+<a name="l00185"></a>00185 <span class="comment">*   ENVIRONMENT</span>
+<a name="l00186"></a>00186 <span class="comment">*</span>
+<a name="l00187"></a>00187 <span class="comment">*   RETURN VALUES</span>
+<a name="l00188"></a>00188 <span class="comment">*</span>
+<a name="l00189"></a>00189 <span class="comment">*   CAUTIONS</span>
+<a name="l00190"></a>00190 <span class="comment">*</span>
+<a name="l00191"></a>00191 <span class="comment">*   EXAMPLES</span>
+<a name="l00192"></a>00192 <span class="comment">*</span>
+<a name="l00193"></a>00193 <span class="comment">*   SEE ALSO</span>
+<a name="l00194"></a>00194 <span class="comment">*</span>
+<a name="l00195"></a>00195 <span class="comment">*   BUGS</span>
+<a name="l00196"></a>00196 <span class="comment">*</span>
+<a name="l00197"></a>00197 <span class="comment">*------------------------------------------------------------------------</span>
+<a name="l00198"></a>00198 <span class="comment">*/</span>
+<a name="l00199"></a>00199 
+<a name="l00200"></a>00200 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00201"></a>00201 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00202"></a>00202 <span class="preprocessor">#endif</span>
+<a name="l00203"></a>00203 <span class="preprocessor"></span><span class="preprocessor">#define POSIX_SOURCE 1</span>
+<a name="l00204"></a>00204 <span class="preprocessor"></span><span class="preprocessor">#include "sinfo_vltPort.h"</span>
+<a name="l00205"></a>00205 
+<a name="l00206"></a>00206 <span class="comment">/*</span>
+<a name="l00207"></a>00207 <span class="comment"> * System Headers</span>
+<a name="l00208"></a>00208 <span class="comment"> */</span>
+<a name="l00209"></a>00209 
+<a name="l00210"></a>00210 <span class="comment">/*</span>
+<a name="l00211"></a>00211 <span class="comment"> * Local Headers</span>
+<a name="l00212"></a>00212 <span class="comment"> */</span>
+<a name="l00213"></a>00213 <span class="preprocessor">#include "sinfo_function_1d.h"</span>
+<a name="l00214"></a>00214 <span class="preprocessor">#include "sinfo_cube_construct.h"</span>
+<a name="l00215"></a>00215 <span class="preprocessor">#include "sinfo_spectrum_ops.h"</span>
+<a name="l00216"></a>00216 <span class="preprocessor">#include "sinfo_wave_calibration.h"</span>
+<a name="l00217"></a>00217 <span class="preprocessor">#include "sinfo_utilities.h"</span>
+<a name="l00218"></a>00218 <span class="preprocessor">#include "sinfo_local_types.h"</span>
+<a name="l00219"></a>00219 <span class="preprocessor">#include "sinfo_fft_base.h"</span>
+<a name="l00220"></a>00220 
+<a name="l00221"></a>00221 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00222"></a>00222 sinfo_sort_slitlets(<span class="keyword">const</span> <span class="keywordtype">int</span> kslit);
+<a name="l00223"></a>00223 
+<a name="l00224"></a>00224 
+<a name="l00225"></a>00225 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00226"></a>00226 sinfo_sort_slitlets_array(<span class="keyword">const</span> <span class="keywordtype">int</span> slit, <span class="keywordtype">int</span>* row_index);
+<a name="l00227"></a>00227 
+<a name="l00235"></a>00235 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00236"></a>00236 <span class="comment"> *                            Function codes</span>
+<a name="l00237"></a>00237 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00248"></a>00248 cpl_image * 
+<a name="l00249"></a>00249 sinfo_new_convolve_ns_image_by_gauss( cpl_image * lineImage,
+<a name="l00250"></a>00250                                    <span class="keywordtype">int</span>        hw )
+<a name="l00251"></a>00251 {
+<a name="l00252"></a>00252     cpl_image * returnImage ;
+<a name="l00253"></a>00253     <span class="keywordtype">float</span>* row_buffer=NULL ;
+<a name="l00254"></a>00254     <span class="keywordtype">float</span> * filter ;
+<a name="l00255"></a>00255     <span class="keywordtype">int</span> col, row ;
+<a name="l00256"></a>00256     <span class="keywordtype">int</span> ilx=0;
+<a name="l00257"></a>00257     <span class="keywordtype">int</span> ily=0;
+<a name="l00258"></a>00258  
+<a name="l00259"></a>00259     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l00260"></a>00260     <span class="keywordtype">float</span>* podata=NULL;
+<a name="l00261"></a>00261 
+<a name="l00262"></a>00262     <span class="keywordflow">if</span> ( lineImage == NULL )
+<a name="l00263"></a>00263     {
+<a name="l00264"></a>00264         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no input image given!\n"</span>) ;
+<a name="l00265"></a>00265         <span class="keywordflow">return</span> NULL ;
+<a name="l00266"></a>00266     }
+<a name="l00267"></a>00267     ilx=cpl_image_get_size_x(lineImage);
+<a name="l00268"></a>00268     ily=cpl_image_get_size_y(lineImage);
+<a name="l00269"></a>00269     pidata=cpl_image_get_data_float(lineImage);
+<a name="l00270"></a>00270     <span class="keywordflow">if</span> ( hw < 1 )
+<a name="l00271"></a>00271     {
+<a name="l00272"></a>00272         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" wrong half width given!\n"</span>) ;
+<a name="l00273"></a>00273         <span class="keywordflow">return</span> NULL ;
+<a name="l00274"></a>00274     }
+<a name="l00275"></a>00275 
+<a name="l00276"></a>00276     <span class="comment">/* allocate memory for returned image */</span>
+<a name="l00277"></a>00277     <span class="keywordflow">if</span> ( NULL == ( returnImage = cpl_image_new(ilx,ily,CPL_TYPE_FLOAT ) ))
+<a name="l00278"></a>00278     {
+<a name="l00279"></a>00279         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"cannot allocate a new image\n"</span>);
+<a name="l00280"></a>00280         <span class="keywordflow">return</span> NULL ;
+<a name="l00281"></a>00281     }
+<a name="l00282"></a>00282     podata=cpl_image_get_data_float(returnImage);
+<a name="l00283"></a>00283 
+<a name="l00284"></a>00284     <span class="comment">/* go through the image rows and save them in a buffer */</span>
+<a name="l00285"></a>00285     row_buffer=cpl_calloc(ily,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l00286"></a>00286 
+<a name="l00287"></a>00287     <span class="keywordflow">for</span> ( row = 0 ; row < ily ; row++ )
+<a name="l00288"></a>00288     {
+<a name="l00289"></a>00289         <span class="keywordflow">for</span> ( col = 0 ; col < ilx ; col++ )
+<a name="l00290"></a>00290         {
+<a name="l00291"></a>00291             <span class="keywordflow">if</span> ( isnan(pidata[col+row*ilx]) )
+<a name="l00292"></a>00292             {
+<a name="l00293"></a>00293                 row_buffer[col] = 0. ;
+<a name="l00294"></a>00294             }
+<a name="l00295"></a>00295             <span class="keywordflow">else</span>
+<a name="l00296"></a>00296             {
+<a name="l00297"></a>00297                 row_buffer[col] = pidata[col + row*ilx] ;
+<a name="l00298"></a>00298             }
+<a name="l00299"></a>00299         }
+<a name="l00300"></a>00300 
+<a name="l00301"></a>00301         <span class="comment">/*--------------------------------------------------------------------</span>
+<a name="l00302"></a>00302 <span class="comment">         * now low pass filter the rows by the gaussian and fill the return</span>
+<a name="l00303"></a>00303 <span class="comment">         * image.</span>
+<a name="l00304"></a>00304 <span class="comment">         */</span>
+<a name="l00305"></a>00305         filter = sinfo_function1d_filter_lowpass( row_buffer,
+<a name="l00306"></a>00306                                             ilx,
+<a name="l00307"></a>00307                                             LOW_PASS_GAUSSIAN,
+<a name="l00308"></a>00308                                             hw ) ;
+<a name="l00309"></a>00309         <span class="keywordflow">for</span> ( col = 0 ; col < ily ; col++ )
+<a name="l00310"></a>00310         {
+<a name="l00311"></a>00311             podata[col + row*ilx] = filter[col] ;
+<a name="l00312"></a>00312         }
+<a name="l00313"></a>00313         <span class="comment">/* deallocate memory */</span>
+<a name="l00314"></a>00314         sinfo_function1d_del (filter) ;
+<a name="l00315"></a>00315     }
+<a name="l00316"></a>00316     cpl_free(row_buffer);    
+<a name="l00317"></a>00317     <span class="keywordflow">return</span> returnImage ;
+<a name="l00318"></a>00318 }
+<a name="l00319"></a>00319 
+<a name="l00336"></a>00336 <span class="keywordtype">float</span> * 
+<a name="l00337"></a>00337 sinfo_north_south_test( cpl_image * ns_image,
+<a name="l00338"></a>00338                           <span class="keywordtype">int</span>        n_slitlets,
+<a name="l00339"></a>00339                           <span class="keywordtype">int</span>        halfWidth,
+<a name="l00340"></a>00340                           <span class="keywordtype">float</span>      fwhm,
+<a name="l00341"></a>00341                           <span class="keywordtype">float</span>      minDiff,
+<a name="l00342"></a>00342                           <span class="keywordtype">float</span>      estimated_dist,
+<a name="l00343"></a>00343                           <span class="keywordtype">float</span>      devtol,
+<a name="l00344"></a>00344               <span class="keywordtype">int</span>         bottom,
+<a name="l00345"></a>00345               <span class="keywordtype">int</span>         top )
+<a name="l00346"></a>00346 {
+<a name="l00347"></a>00347     <span class="keywordtype">int</span> i, j, k, m, row, col, n, ni, na ;
+<a name="l00348"></a>00348     <span class="keywordtype">int</span> position, counter, iters ;
+<a name="l00349"></a>00349     <span class="keywordtype">int</span> xdim, ndat, its, numpar ;
+<a name="l00350"></a>00350     pixelvalue row_buf[cpl_image_get_size_x(ns_image)] ;
+<a name="l00351"></a>00351     <span class="keywordtype">float</span> sum, mean, maxval ;
+<a name="l00352"></a>00352     <span class="keywordtype">float</span> tol, lab ;
+<a name="l00353"></a>00353     <span class="keywordtype">float</span> * distances ;
+<a name="l00354"></a>00354     <span class="keywordtype">float</span> distances_buf[cpl_image_get_size_y(ns_image)][n_slitlets-1] ;
+<a name="l00355"></a>00355     <span class="keywordtype">float</span> x_position[n_slitlets] ;
+<a name="l00356"></a>00356     <span class="keywordtype">float</span> * xdat, * wdat ;
+<a name="l00357"></a>00357     <span class="keywordtype">int</span> * mpar ;
+<a name="l00358"></a>00358     <span class="keywordtype">int</span> found[3*n_slitlets], found_clean[3*n_slitlets] ;
+<a name="l00359"></a>00359     <span class="keywordtype">int</span> found_cleanit[3*n_slitlets] ;
+<a name="l00360"></a>00360     Vector * line ;
+<a name="l00361"></a>00361     FitParams ** par ;
+<a name="l00362"></a>00362     <span class="keywordtype">int</span> foundit, begin, end ;
+<a name="l00363"></a>00363     <span class="keywordtype">int</span> zeroindicator ;
+<a name="l00364"></a>00364     <span class="keywordtype">int</span> ilx=0;
+<a name="l00365"></a>00365     <span class="keywordtype">int</span> ily=0;
+<a name="l00366"></a>00366  
+<a name="l00367"></a>00367     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l00368"></a>00368  
+<a name="l00369"></a>00369     <span class="keywordflow">if</span> ( ns_image == NULL )
+<a name="l00370"></a>00370     {
+<a name="l00371"></a>00371         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"sorry, no image given\n"</span>) ;
+<a name="l00372"></a>00372         <span class="keywordflow">return</span> NULL ;
+<a name="l00373"></a>00373     }
+<a name="l00374"></a>00374     ilx=cpl_image_get_size_x(ns_image);
+<a name="l00375"></a>00375     ily=cpl_image_get_size_y(ns_image);
+<a name="l00376"></a>00376     pidata=cpl_image_get_data_float(ns_image);
+<a name="l00377"></a>00377 
+<a name="l00378"></a>00378 
+<a name="l00379"></a>00379     <span class="keywordflow">if</span> ( n_slitlets < 1 )
+<a name="l00380"></a>00380     {
+<a name="l00381"></a>00381         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"wrong number of slitlets given\n"</span>) ;
+<a name="l00382"></a>00382         <span class="keywordflow">return</span> NULL ;
+<a name="l00383"></a>00383     }
+<a name="l00384"></a>00384     <span class="keywordflow">if</span> ( halfWidth < 0 || halfWidth >= estimated_dist )
+<a name="l00385"></a>00385     {
+<a name="l00386"></a>00386         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"wrong half width given\n"</span>) ;
+<a name="l00387"></a>00387         <span class="keywordflow">return</span> NULL ;
+<a name="l00388"></a>00388     }
+<a name="l00389"></a>00389     <span class="keywordflow">if</span> ( fwhm <= 0. )
+<a name="l00390"></a>00390     {
+<a name="l00391"></a>00391         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"wrong fwhm given\n"</span>) ;
+<a name="l00392"></a>00392         <span class="keywordflow">return</span> NULL ;
+<a name="l00393"></a>00393     }
+<a name="l00394"></a>00394     <span class="keywordflow">if</span> ( minDiff < 1. )
+<a name="l00395"></a>00395     {
+<a name="l00396"></a>00396         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"wrong minDiff given\n"</span>) ;
+<a name="l00397"></a>00397         <span class="keywordflow">return</span> NULL ;
+<a name="l00398"></a>00398     }
+<a name="l00399"></a>00399 
+<a name="l00400"></a>00400     <span class="comment">/* allocate memory for output array */</span>
+<a name="l00401"></a>00401     <span class="keywordflow">if</span> (NULL == (distances = (<span class="keywordtype">float</span> *) cpl_calloc ( n_slitlets - 1 , 
+<a name="l00402"></a>00402                                                     <span class="keyword">sizeof</span> (<span class="keywordtype">float</span>) ))) 
+<a name="l00403"></a>00403     {
+<a name="l00404"></a>00404         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"could not allocate memory\n"</span>) ;
+<a name="l00405"></a>00405         <span class="keywordflow">return</span> NULL ;
+<a name="l00406"></a>00406     }
+<a name="l00407"></a>00407 
+<a name="l00408"></a>00408     <span class="comment">/* go through the image rows */</span>
+<a name="l00409"></a>00409     <span class="keywordflow">for</span> ( row = bottom ; row < top ; row++ )
+<a name="l00410"></a>00410     {
+<a name="l00411"></a>00411         zeroindicator = 0 ;
+<a name="l00412"></a>00412 
+<a name="l00413"></a>00413         <span class="comment">/* initialize the distance buffer */</span>
+<a name="l00414"></a>00414         <span class="keywordflow">for</span> ( i = 0 ; i < n_slitlets-1 ; i++ )
+<a name="l00415"></a>00415         {
+<a name="l00416"></a>00416             distances_buf[row][i] = ZERO ;
+<a name="l00417"></a>00417         }
+<a name="l00418"></a>00418 
+<a name="l00419"></a>00419         <span class="comment">/* fill the row buffer array with image data */</span>
+<a name="l00420"></a>00420         <span class="keywordflow">for</span> ( col = 0 ; col < ilx ; col++ )
+<a name="l00421"></a>00421         {
+<a name="l00422"></a>00422             row_buf[col] = pidata[col + row*ilx] ;
+<a name="l00423"></a>00423         }
+<a name="l00424"></a>00424 
+<a name="l00425"></a>00425         <span class="comment">/* determine the mean of the row data */</span>
+<a name="l00426"></a>00426         sum = 0. ;
+<a name="l00427"></a>00427         n = 0 ;
+<a name="l00428"></a>00428         <span class="keywordflow">for</span> ( i = 0 ; i < ilx ; i++ )
+<a name="l00429"></a>00429         {
+<a name="l00430"></a>00430             <span class="keywordflow">if</span> ( isnan(row_buf[i]) )
+<a name="l00431"></a>00431             {
+<a name="l00432"></a>00432                 continue ;
+<a name="l00433"></a>00433             }
+<a name="l00434"></a>00434             sum += row_buf[i] ;
+<a name="l00435"></a>00435             n++ ;
+<a name="l00436"></a>00436         }
+<a name="l00437"></a>00437         mean = sum / (float)n ;
+<a name="l00438"></a>00438 
+<a name="l00439"></a>00439 
+<a name="l00440"></a>00440         <span class="comment">/* store the positions of image values greater than the mean */</span>
+<a name="l00441"></a>00441         n = 0 ;
+<a name="l00442"></a>00442         <span class="keywordflow">for</span> ( i = 0 ; i < ilx ; i++ )
+<a name="l00443"></a>00443         {
+<a name="l00444"></a>00444             <span class="keywordflow">if</span> (isnan(row_buf[i]))
+<a name="l00445"></a>00445             {
+<a name="l00446"></a>00446                 continue ;
+<a name="l00447"></a>00447             }
+<a name="l00448"></a>00448             <span class="keywordflow">if</span> ( row_buf[i] >  sqrt(mean*mean*9) )
+<a name="l00449"></a>00449             {
+<a name="l00450"></a>00450                 found[n] = i ;
+<a name="l00451"></a>00451                 n++ ;
+<a name="l00452"></a>00452             } 
+<a name="l00453"></a>00453         }
+<a name="l00454"></a>00454        
+<a name="l00455"></a>00455         <span class="keywordflow">if</span> ( n < n_slitlets )
+<a name="l00456"></a>00456         {
+<a name="l00457"></a>00457             <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"t1 wrong number of intensity columns found "</span>
+<a name="l00458"></a>00458                               <span class="stringliteral">"in row: %d, found number: %d, mean: %g"</span>,
+<a name="l00459"></a>00459                               row, n, mean) ;
+<a name="l00460"></a>00460             continue ;
+<a name="l00461"></a>00461         }
+<a name="l00462"></a>00462         <span class="keywordflow">else</span>
+<a name="l00463"></a>00463         { 
+<a name="l00464"></a>00464             <span class="comment">/* find the maximum value position around the found columns */</span>
+<a name="l00465"></a>00465             na = 0 ;
+<a name="l00466"></a>00466             <span class="keywordflow">for</span> ( i = 1 ; i < n ; i ++ )
+<a name="l00467"></a>00467             {
+<a name="l00468"></a>00468                 <span class="keywordflow">if</span> ( found[i] - found[i-1] < halfWidth )
+<a name="l00469"></a>00469                 {
+<a name="l00470"></a>00470                     begin = found[i] - halfWidth ;
+<a name="l00471"></a>00471                     <span class="keywordflow">if</span> ( begin < 0 )
+<a name="l00472"></a>00472                     {
+<a name="l00473"></a>00473                         begin = 0 ;
+<a name="l00474"></a>00474                     }
+<a name="l00475"></a>00475                     end = found[i] + halfWidth ;
+<a name="l00476"></a>00476                     <span class="keywordflow">if</span> ( end >= ilx )
+<a name="l00477"></a>00477                     {
+<a name="l00478"></a>00478                         end = ilx - 1 ;
+<a name="l00479"></a>00479                     }
+<a name="l00480"></a>00480                     <span class="comment">/* find the maximum value inside the box </span>
+<a name="l00481"></a>00481 <span class="comment">                       around the found positions*/</span>
+<a name="l00482"></a>00482                     maxval = -FLT_MAX ;
+<a name="l00483"></a>00483                     foundit = 0 ;
+<a name="l00484"></a>00484                     <span class="keywordflow">for</span> ( j = begin ; j <= end ; j++ )
+<a name="l00485"></a>00485                     {
+<a name="l00486"></a>00486                         <span class="comment">/* do not consider boxes that contain bad pixels */</span>
+<a name="l00487"></a>00487                         <span class="keywordflow">if</span> (isnan(row_buf[j]))
+<a name="l00488"></a>00488                         {
+<a name="l00489"></a>00489                             continue ;
+<a name="l00490"></a>00490                         }
+<a name="l00491"></a>00491                         <span class="keywordflow">if</span> (row_buf[j] >= maxval )
+<a name="l00492"></a>00492                         {
+<a name="l00493"></a>00493                             maxval = row_buf[j] ;
+<a name="l00494"></a>00494                             foundit = j ;
+<a name="l00495"></a>00495                         }
+<a name="l00496"></a>00496                     }
+<a name="l00497"></a>00497                     <span class="keywordflow">if</span> (maxval == -FLT_MAX)
+<a name="l00498"></a>00498                     {
+<a name="l00499"></a>00499                         continue ;
+<a name="l00500"></a>00500                     }
+<a name="l00501"></a>00501                     <span class="keywordflow">for</span> ( k = 0 ; k < na ; k++ )
+<a name="l00502"></a>00502                     {
+<a name="l00503"></a>00503                         <span class="keywordflow">if</span> ( found_cleanit[k] >= begin && 
+<a name="l00504"></a>00504                              found_cleanit[k] < foundit )
+<a name="l00505"></a>00505                         {
+<a name="l00506"></a>00506                             na-- ;
+<a name="l00507"></a>00507                         }
+<a name="l00508"></a>00508                     }
+<a name="l00509"></a>00509                     <span class="keywordflow">for</span> ( k = 0 ; k < n ; k++ )
+<a name="l00510"></a>00510                     {
+<a name="l00511"></a>00511                         <span class="keywordflow">if</span> ( found[k] == foundit)
+<a name="l00512"></a>00512                         {
+<a name="l00513"></a>00513                  <span class="keywordflow">if</span> (na>0){
+<a name="l00514"></a>00514                             <span class="keywordflow">if</span> ( found_cleanit[na-1] != found[k] )
+<a name="l00515"></a>00515                             {
+<a name="l00516"></a>00516                                 found_cleanit[na] = found[k] ;
+<a name="l00517"></a>00517                                 na++ ;
+<a name="l00518"></a>00518                             }
+<a name="l00519"></a>00519              }
+<a name="l00520"></a>00520              <span class="keywordflow">else</span>{
+<a name="l00521"></a>00521                 found_cleanit[na] = found[k] ;  
+<a name="l00522"></a>00522                             na++ ;
+<a name="l00523"></a>00523              } 
+<a name="l00524"></a>00524                       }
+<a name="l00525"></a>00525                     }
+<a name="l00526"></a>00526                 }
+<a name="l00527"></a>00527                 <span class="keywordflow">else</span>
+<a name="l00528"></a>00528                 {
+<a name="l00529"></a>00529                     <span class="keywordflow">if</span> ( i == 1 )
+<a name="l00530"></a>00530                     {
+<a name="l00531"></a>00531                         found_cleanit[na] = found[0] ;
+<a name="l00532"></a>00532                         na++ ;
+<a name="l00533"></a>00533                         found_cleanit[na] = found[1] ;
+<a name="l00534"></a>00534                         na++ ;
+<a name="l00535"></a>00535                     }
+<a name="l00536"></a>00536                     <span class="keywordflow">else</span>
+<a name="l00537"></a>00537                     {   
+<a name="l00538"></a>00538                 <span class="keywordflow">if</span> (na>0){
+<a name="l00539"></a>00539                             <span class="keywordflow">if</span> ( found_cleanit[na-1] != found[i-1])
+<a name="l00540"></a>00540                             {
+<a name="l00541"></a>00541                                 found_cleanit[na] = found[i-1] ;
+<a name="l00542"></a>00542                                 na++ ;
+<a name="l00543"></a>00543                             }
+<a name="l00544"></a>00544                             <span class="keywordflow">if</span> ( found_cleanit[na-1] != found[i])
+<a name="l00545"></a>00545                             {
+<a name="l00546"></a>00546                                 found_cleanit[na] = found[i] ;
+<a name="l00547"></a>00547                                 na++ ;
+<a name="l00548"></a>00548                             }
+<a name="l00549"></a>00549                         }
+<a name="l00550"></a>00550             <span class="keywordflow">else</span>
+<a name="l00551"></a>00551                         {
+<a name="l00552"></a>00552                             found_cleanit[na] = found[i] ;
+<a name="l00553"></a>00553                             na++ ;
+<a name="l00554"></a>00554                         }
+<a name="l00555"></a>00555             }  
+<a name="l00556"></a>00556                 }
+<a name="l00557"></a>00557             }
+<a name="l00558"></a>00558             <span class="comment">/* determine only one pixel position for each slitlet intensity */</span>
+<a name="l00559"></a>00559             j = 1 ;
+<a name="l00560"></a>00560             <span class="keywordflow">for</span> ( i = 1 ; i < na ; i++ )
+<a name="l00561"></a>00561             {
+<a name="l00562"></a>00562                 <span class="keywordflow">if</span> ( (<span class="keywordtype">float</span>)(found_cleanit[i] - found_cleanit[i-1]) < 
+<a name="l00563"></a>00563                             (estimated_dist - devtol) ||
+<a name="l00564"></a>00564                      (<span class="keywordtype">float</span>)(found_cleanit[i] - found_cleanit[i-1]) > 
+<a name="l00565"></a>00565                             (estimated_dist + devtol) )
+<a name="l00566"></a>00566                 {
+<a name="l00567"></a>00567                     continue ;
+<a name="l00568"></a>00568                 }
+<a name="l00569"></a>00569                 <span class="keywordflow">else</span>
+<a name="l00570"></a>00570                 {
+<a name="l00571"></a>00571                     found_clean[j-1] = found_cleanit[i-1] ;
+<a name="l00572"></a>00572                     found_clean[j]   = found_cleanit[i] ;
+<a name="l00573"></a>00573                     j++ ;
+<a name="l00574"></a>00574                 }
+<a name="l00575"></a>00575             }
+<a name="l00576"></a>00576         }
+<a name="l00577"></a>00577         <span class="keywordflow">if</span> ( j > n_slitlets )
+<a name="l00578"></a>00578         {
+<a name="l00579"></a>00579             <span class="comment">/* check the distance again */</span>
+<a name="l00580"></a>00580             ni = 1 ;
+<a name="l00581"></a>00581             <span class="keywordflow">for</span> ( i = 1 ; i < j ; i++ )
+<a name="l00582"></a>00582             {
+<a name="l00583"></a>00583                 <span class="keywordflow">if</span> ( (<span class="keywordtype">float</span>)(found_clean[i] - found_clean[i-1]) < 
+<a name="l00584"></a>00584                             (estimated_dist - devtol ) ||
+<a name="l00585"></a>00585                      (<span class="keywordtype">float</span>)(found_clean[i] - found_clean[i-1]) > 
+<a name="l00586"></a>00586                             (estimated_dist + devtol ) )
+<a name="l00587"></a>00587                 { 
+<a name="l00588"></a>00588                     continue ;
+<a name="l00589"></a>00589                 }
+<a name="l00590"></a>00590                 <span class="keywordflow">else</span>
+<a name="l00591"></a>00591                 {
+<a name="l00592"></a>00592 
+<a name="l00593"></a>00593                     found_clean[ni-1] = found_clean[i-1] ;
+<a name="l00594"></a>00594                     found_clean[ni]   = found_clean[i] ;
+<a name="l00595"></a>00595                     ni++ ;
+<a name="l00596"></a>00596                 }
+<a name="l00597"></a>00597             }
+<a name="l00598"></a>00598             <span class="keywordflow">if</span> ( ni != n_slitlets )
+<a name="l00599"></a>00599             {
+<a name="l00600"></a>00600                 <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"t2 wrong number of intensity columns"</span>
+<a name="l00601"></a>00601                                   <span class="stringliteral">" found in row: %d,  found number: %d"</span>,
+<a name="l00602"></a>00602                                   row, ni) ;
+<a name="l00603"></a>00603                 continue ;
+<a name="l00604"></a>00604             }
+<a name="l00605"></a>00605             <span class="keywordflow">else</span> 
+<a name="l00606"></a>00606             {
+<a name="l00607"></a>00607                 j = ni ;
+<a name="l00608"></a>00608             }
+<a name="l00609"></a>00609         }
+<a name="l00610"></a>00610         <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( j < n_slitlets )
+<a name="l00611"></a>00611         {
+<a name="l00612"></a>00612             cpl_msg_debug (<span class="stringliteral">"north_south_test3:"</span>,
+<a name="l00613"></a>00613                             <span class="stringliteral">"t3 wrong number of intensity columns "</span>
+<a name="l00614"></a>00614                             <span class="stringliteral">"found in row: %d , found number: %d, mean: %g\n"</span>, 
+<a name="l00615"></a>00615                             row, j, mean) ;
+<a name="l00616"></a>00616             continue ;
+<a name="l00617"></a>00617         }
+<a name="l00618"></a>00618         counter = 0 ;
+<a name="l00619"></a>00619         <span class="comment">/* go through the found intensity pixels in one row */</span>
+<a name="l00620"></a>00620         <span class="keywordflow">for</span> ( i = 0 ; i < j ; i++ )
+<a name="l00621"></a>00621         {
+<a name="l00622"></a>00622             <span class="comment">/* allocate memory for the array where the line is fitted in */</span>
+<a name="l00623"></a>00623             <span class="keywordflow">if</span> ( NULL == (line = sinfo_new_vector (2*halfWidth + 1)) )
+<a name="l00624"></a>00624             {
+<a name="l00625"></a>00625                 <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"cannot allocate new Vector \n"</span>) ;
+<a name="l00626"></a>00626                 cpl_free(distances) ;
+<a name="l00627"></a>00627                 <span class="keywordflow">return</span> NULL ;
+<a name="l00628"></a>00628             }
+<a name="l00629"></a>00629 
+<a name="l00630"></a>00630             <span class="comment">/* allocate memory */</span>
+<a name="l00631"></a>00631             xdat = (<span class="keywordtype">float</span> *) cpl_calloc( line -> n_elements, <span class="keyword">sizeof</span> (<span class="keywordtype">float</span>) ) ;
+<a name="l00632"></a>00632             wdat = (<span class="keywordtype">float</span> *) cpl_calloc( line -> n_elements, <span class="keyword">sizeof</span> (<span class="keywordtype">float</span>) ) ;
+<a name="l00633"></a>00633             mpar = (<span class="keywordtype">int</span> *)   cpl_calloc( MAXPAR, <span class="keyword">sizeof</span> (<span class="keywordtype">int</span>) ) ;
+<a name="l00634"></a>00634             par = sinfo_new_fit_params(1) ;
+<a name="l00635"></a>00635 
+<a name="l00636"></a>00636             m = 0 ;
+<a name="l00637"></a>00637             <span class="keywordflow">for</span> ( k = found_clean[i]-halfWidth ; 
+<a name="l00638"></a>00638                   k <= found_clean[i]+halfWidth ; k++ )
+<a name="l00639"></a>00639             {
+<a name="l00640"></a>00640                 <span class="keywordflow">if</span> ( k < 0 )
+<a name="l00641"></a>00641                 {
+<a name="l00642"></a>00642                     k = 0. ;
+<a name="l00643"></a>00643                 }
+<a name="l00644"></a>00644                 <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( k >= ilx )
+<a name="l00645"></a>00645                 {
+<a name="l00646"></a>00646                     k = ilx - 1 ;
+<a name="l00647"></a>00647                 }
+<a name="l00648"></a>00648                 <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( isnan(row_buf[k]) )
+<a name="l00649"></a>00649                 {
+<a name="l00650"></a>00650                     zeroindicator = 1 ;
+<a name="l00651"></a>00651                     break ;
+<a name="l00652"></a>00652                 }
+<a name="l00653"></a>00653                 <span class="keywordflow">else</span>
+<a name="l00654"></a>00654                 {
+<a name="l00655"></a>00655                     line -> data[m] = row_buf[k] ;
+<a name="l00656"></a>00656                     m++ ;
+<a name="l00657"></a>00657                 }
+<a name="l00658"></a>00658             }
+<a name="l00659"></a>00659             <span class="keywordflow">if</span> ( zeroindicator == 1 )
+<a name="l00660"></a>00660             {
+<a name="l00661"></a>00661                 sinfo_new_destroy_vector(line) ;
+<a name="l00662"></a>00662                 cpl_free(xdat) ;
+<a name="l00663"></a>00663                 cpl_free(wdat) ;
+<a name="l00664"></a>00664                 cpl_free(mpar) ;
+<a name="l00665"></a>00665                 sinfo_new_destroy_fit_params(&par) ;
+<a name="l00666"></a>00666                 break ;
+<a name="l00667"></a>00667             }
+<a name="l00668"></a>00668 
+<a name="l00669"></a>00669             <span class="comment">/*----------------------------------------------------------------</span>
+<a name="l00670"></a>00670 <span class="comment">             * go through the spectral sinfo_vector</span>
+<a name="l00671"></a>00671 <span class="comment">             * determine the maximum pixel value in the spectral sinfo_vector</span>
+<a name="l00672"></a>00672 <span class="comment">             */</span>
+<a name="l00673"></a>00673             maxval = -FLT_MAX ;
+<a name="l00674"></a>00674             position = -INT32_MAX ;
+<a name="l00675"></a>00675             <span class="keywordflow">for</span> ( k = 0 ; k < m ; k++ )
+<a name="l00676"></a>00676             {
+<a name="l00677"></a>00677                 xdat[k] = k ;
+<a name="l00678"></a>00678                 wdat[k] = 1.0 ;
+<a name="l00679"></a>00679                 <span class="keywordflow">if</span> ( line -> data[k] >= maxval )
+<a name="l00680"></a>00680                 {
+<a name="l00681"></a>00681                     maxval = line -> data[k] ;
+<a name="l00682"></a>00682                     position = k ;
+<a name="l00683"></a>00683                 }
+<a name="l00684"></a>00684             }
+<a name="l00685"></a>00685 
+<a name="l00686"></a>00686             <span class="comment">/* set initial values for the fitting routine */</span>
+<a name="l00687"></a>00687             xdim     = XDIM ;
+<a name="l00688"></a>00688             ndat     = line -> n_elements ;
+<a name="l00689"></a>00689             numpar   = MAXPAR ;
+<a name="l00690"></a>00690             tol      = TOL ;
+<a name="l00691"></a>00691             lab      = LAB ;
+<a name="l00692"></a>00692             its      = ITS ;
+<a name="l00693"></a>00693             (*par) -> fit_par[1] = fwhm ;
+<a name="l00694"></a>00694             (*par) -> fit_par[2] = (float) position ;
+<a name="l00695"></a>00695             (*par) -> fit_par[3] = (float) (line -> data[0] + 
+<a name="l00696"></a>00696                                    line -> data[line->n_elements - 1]) / 2.0 ;
+<a name="l00697"></a>00697             (*par) -> fit_par[0]  = maxval - ((*par) -> fit_par[3]) ;
+<a name="l00698"></a>00698 
+<a name="l00699"></a>00699 
+<a name="l00700"></a>00700             <span class="comment">/* exclude negative peaks and low signal cases */</span>
+<a name="l00701"></a>00701             <span class="keywordflow">if</span> ( (*par) -> fit_par[0] < minDiff )
+<a name="l00702"></a>00702             {
+<a name="l00703"></a>00703                 <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a> (<span class="stringliteral">"sorry, signal of line too low to fit "</span>
+<a name="l00704"></a>00704                                    <span class="stringliteral">"in row: %d in slitlet %d\n"</span>, row, i) ;
+<a name="l00705"></a>00705                 sinfo_new_destroy_vector(line) ;
+<a name="l00706"></a>00706                 cpl_free(xdat) ;
+<a name="l00707"></a>00707                 cpl_free(wdat) ;
+<a name="l00708"></a>00708                 cpl_free(mpar) ;
+<a name="l00709"></a>00709                 sinfo_new_destroy_fit_params(&par) ;
+<a name="l00710"></a>00710                 continue ;
+<a name="l00711"></a>00711             }
+<a name="l00712"></a>00712 
+<a name="l00713"></a>00713             <span class="keywordflow">for</span> ( k = 0 ; k < MAXPAR ; k++ )
+<a name="l00714"></a>00714             {
+<a name="l00715"></a>00715                 (*par) -> derv_par[k] = 0.0 ;
+<a name="l00716"></a>00716                 mpar[k] = 1 ;
+<a name="l00717"></a>00717             }
+<a name="l00718"></a>00718             <span class="comment">/* finally, do the least square fit using a Gaussian */</span>
+<a name="l00719"></a>00719             <span class="keywordflow">if</span> ( 0 > ( iters = sinfo_new_lsqfit_c( xdat, &xdim, 
+<a name="l00720"></a>00720                                                    line -> data, wdat, &ndat, 
+<a name="l00721"></a>00721                                                    (*par) -> fit_par,
+<a name="l00722"></a>00722                                                    (*par) -> derv_par, mpar, 
+<a name="l00723"></a>00723                                                    &numpar, &tol, &its, &lab)) )
+<a name="l00724"></a>00724             {
+<a name="l00725"></a>00725           <span class="comment">/*</span>
+<a name="l00726"></a>00726 <span class="comment">                cpl_msg_debug ("north_south_test:",</span>
+<a name="l00727"></a>00727 <span class="comment">                               "sinfo_lsqfit_c: least squares fit failed,"</span>
+<a name="l00728"></a>00728 <span class="comment">                               " error no.: %d in row: %d in slitlet %d\n",</span>
+<a name="l00729"></a>00729 <span class="comment">                                iters, row, i) ;</span>
+<a name="l00730"></a>00730 <span class="comment">          */</span>
+<a name="l00731"></a>00731                 sinfo_new_destroy_vector(line) ;
+<a name="l00732"></a>00732                 cpl_free(xdat) ;
+<a name="l00733"></a>00733                 cpl_free(wdat) ;
+<a name="l00734"></a>00734                 cpl_free(mpar) ;
+<a name="l00735"></a>00735                 sinfo_new_destroy_fit_params(&par) ;
+<a name="l00736"></a>00736                 continue ;
+<a name="l00737"></a>00737             }
+<a name="l00738"></a>00738 
+<a name="l00739"></a>00739             <span class="comment">/* check for negative fit results */</span>
+<a name="l00740"></a>00740             <span class="keywordflow">if</span> ( (*par) -> fit_par[0] <= 0. || 
+<a name="l00741"></a>00741                  (*par) -> fit_par[1] <= 0. ||
+<a name="l00742"></a>00742                  (*par) -> fit_par[2] < 0. )
+<a name="l00743"></a>00743             {
+<a name="l00744"></a>00744                 <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a> (<span class="stringliteral">"negative parameters as fit result, "</span>
+<a name="l00745"></a>00745                                    <span class="stringliteral">"not used! in row %d in slitlet %d"</span>, 
+<a name="l00746"></a>00746                                    row, i) ;
+<a name="l00747"></a>00747                 sinfo_new_destroy_vector(line) ;
+<a name="l00748"></a>00748                 cpl_free(xdat) ;
+<a name="l00749"></a>00749                 cpl_free(wdat) ;
+<a name="l00750"></a>00750                 cpl_free(mpar) ;
+<a name="l00751"></a>00751                 sinfo_new_destroy_fit_params(&par) ;
+<a name="l00752"></a>00752                 continue ;
+<a name="l00753"></a>00753             }
+<a name="l00754"></a>00754 
+<a name="l00755"></a>00755             <span class="comment">/* correct the fitted position for the given row of the line </span>
+<a name="l00756"></a>00756 <span class="comment">               in image coordinates */</span>
+<a name="l00757"></a>00757             (*par) -> fit_par[2] =  (float) (found_clean[i] - halfWidth) + 
+<a name="l00758"></a>00758                                             (*par) -> fit_par[2] ;
+<a name="l00759"></a>00759             x_position[counter] = (*par) -> fit_par[2] ;
+<a name="l00760"></a>00760             counter ++ ;
+<a name="l00761"></a>00761 
+<a name="l00762"></a>00762             <span class="comment">/* free memory */</span>
+<a name="l00763"></a>00763             sinfo_new_destroy_fit_params(&par) ;
+<a name="l00764"></a>00764             sinfo_new_destroy_vector ( line ) ;
+<a name="l00765"></a>00765             cpl_free ( xdat ) ;
+<a name="l00766"></a>00766             cpl_free ( wdat ) ;
+<a name="l00767"></a>00767             cpl_free ( mpar ) ;
+<a name="l00768"></a>00768         }
+<a name="l00769"></a>00769         <span class="keywordflow">if</span> (zeroindicator == 1)
+<a name="l00770"></a>00770         {
+<a name="l00771"></a>00771             <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a> (<span class="stringliteral">"bad pixel in fitting box in row: %d\n"</span>, row) ;
+<a name="l00772"></a>00772             continue ;
+<a name="l00773"></a>00773         }
+<a name="l00774"></a>00774 
+<a name="l00775"></a>00775         <span class="keywordflow">if</span> ( counter != n_slitlets )
+<a name="l00776"></a>00776         {
+<a name="l00777"></a>00777             continue ;
+<a name="l00778"></a>00778             <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"wrong number of slitlets found in row: %d"</span>,row);
+<a name="l00779"></a>00779         }
+<a name="l00780"></a>00780         <span class="comment">/* store the distances between the sources in a buffer */</span>
+<a name="l00781"></a>00781         <span class="keywordflow">for</span> ( i = 1 ; i < n_slitlets ; i++ )
+<a name="l00782"></a>00782         {
+<a name="l00783"></a>00783             distances_buf[row][i-1] = x_position[i] - x_position[i-1] ;
+<a name="l00784"></a>00784         }
+<a name="l00785"></a>00785     }
+<a name="l00786"></a>00786 
+<a name="l00787"></a>00787     <span class="comment">/* ----------------------------------------------------------------</span>
+<a name="l00788"></a>00788 <span class="comment">     * go through the rows again and take the mean of the distances, </span>
+<a name="l00789"></a>00789 <span class="comment">     * throw away the runaways </span>
+<a name="l00790"></a>00790 <span class="comment">     */</span>
+<a name="l00791"></a>00791     <span class="keywordflow">for</span> ( i = 0 ; i < n_slitlets-1 ; i++ )
+<a name="l00792"></a>00792     {
+<a name="l00793"></a>00793         n   = 0 ;
+<a name="l00794"></a>00794         sum = 0. ;
+<a name="l00795"></a>00795         <span class="keywordflow">for</span> ( row = bottom ; row < top ; row++ )
+<a name="l00796"></a>00796         {
+<a name="l00797"></a>00797             <span class="keywordflow">if</span> ( fabs( distances_buf[row][i] - estimated_dist ) > devtol || 
+<a name="l00798"></a>00798                  isnan(distances_buf[row][i]) )
+<a name="l00799"></a>00799             {
+<a name="l00800"></a>00800             <span class="comment">/*</span>
+<a name="l00801"></a>00801 <span class="comment">          sinfo_msg("dist=%g devtol=%g isan=%d", </span>
+<a name="l00802"></a>00802 <span class="comment">            distances_buf[row][i],</span>
+<a name="l00803"></a>00803 <span class="comment">            devtol,</span>
+<a name="l00804"></a>00804 <span class="comment">            isnan(distances_buf[row][i]));</span>
+<a name="l00805"></a>00805 <span class="comment">            */</span>
+<a name="l00806"></a>00806                 continue ;
+<a name="l00807"></a>00807             }
+<a name="l00808"></a>00808             sum += distances_buf[row][i] ;
+<a name="l00809"></a>00809             n++ ;
+<a name="l00810"></a>00810         }
+<a name="l00811"></a>00811         <span class="keywordflow">if</span> ( n < 2 )
+<a name="l00812"></a>00812         {
+<a name="l00813"></a>00813             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"distances array could not be determined "</span>
+<a name="l00814"></a>00814                             <span class="stringliteral">"completely!, deviations of distances from number "</span>
+<a name="l00815"></a>00815                             <span class="stringliteral">"of slitlets too big\n"</span> ) ;
+<a name="l00816"></a>00816             cpl_free(distances) ;
+<a name="l00817"></a>00817             <span class="keywordflow">return</span> NULL ;
+<a name="l00818"></a>00818         }
+<a name="l00819"></a>00819         <span class="keywordflow">else</span>
+<a name="l00820"></a>00820         {
+<a name="l00821"></a>00821             distances[i] = sum / (float)n ;
+<a name="l00822"></a>00822         }
+<a name="l00823"></a>00823     }
+<a name="l00824"></a>00824     <span class="keywordflow">return</span> distances ; 
+<a name="l00825"></a>00825 }
+<a name="l00826"></a>00826 
+<a name="l00850"></a>00850 cpl_imagelist * 
+<a name="l00851"></a>00851 sinfo_new_make_cube ( cpl_image * calibImage,
+<a name="l00852"></a>00852                      <span class="keywordtype">float</span>    * distances,
+<a name="l00853"></a>00853                      <span class="keywordtype">float</span>    * correct_diff_dist )
+<a name="l00854"></a>00854 {
+<a name="l00855"></a>00855     cpl_imagelist * returnCube ;
+<a name="l00856"></a>00856     <span class="keywordtype">int</span> imsize, kslit, kpix ;
+<a name="l00857"></a>00857     <span class="keywordtype">int</span> slit_index ;
+<a name="l00858"></a>00858     <span class="keywordtype">int</span> z, col, recol ;
+<a name="l00859"></a>00859     <span class="keywordtype">int</span> ilx=0;
+<a name="l00860"></a>00860     <span class="keywordtype">int</span> ily=0;
+<a name="l00861"></a>00861 
+<a name="l00862"></a>00862     <span class="keywordtype">float</span>* podata=NULL;
+<a name="l00863"></a>00863     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l00864"></a>00864     cpl_image* o_img;
+<a name="l00865"></a>00865 
+<a name="l00866"></a>00866     <span class="keywordflow">if</span> ( NULL == calibImage )
+<a name="l00867"></a>00867     {
+<a name="l00868"></a>00868         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no resampled image given!\n"</span>) ;
+<a name="l00869"></a>00869         <span class="keywordflow">return</span> NULL ;
+<a name="l00870"></a>00870     }
+<a name="l00871"></a>00871     ilx=cpl_image_get_size_x(calibImage);
+<a name="l00872"></a>00872     ily=cpl_image_get_size_y(calibImage);
+<a name="l00873"></a>00873     pidata=cpl_image_get_data_float(calibImage);
+<a name="l00874"></a>00874 
+<a name="l00875"></a>00875     <span class="keywordflow">if</span> ( NULL == distances )
+<a name="l00876"></a>00876     {
+<a name="l00877"></a>00877         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no distances array from ns_test given!/n"</span>) ;
+<a name="l00878"></a>00878         <span class="keywordflow">return</span> NULL ;
+<a name="l00879"></a>00879     }
+<a name="l00880"></a>00880 
+<a name="l00881"></a>00881     <span class="keywordflow">if</span> ( NULL == correct_diff_dist )
+<a name="l00882"></a>00882     {
+<a name="l00883"></a>00883         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"correct_diff_dist array is not allocated!/n"</span>) ;
+<a name="l00884"></a>00884         <span class="keywordflow">return</span> NULL ;
+<a name="l00885"></a>00885     }
+<a name="l00886"></a>00886        
+<a name="l00887"></a>00887     <span class="keywordflow">if</span> ( N_SLITLETS != 32 )
+<a name="l00888"></a>00888     {
+<a name="l00889"></a>00889         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"wrong number of slitlets given \n"</span> ) ;
+<a name="l00890"></a>00890         <span class="keywordflow">return</span> NULL ;
+<a name="l00891"></a>00891     }
+<a name="l00892"></a>00892     imsize = ilx / N_SLITLETS ;
+<a name="l00893"></a>00893 
+<a name="l00894"></a>00894     <span class="comment">/* allocate memory */</span>  
+<a name="l00895"></a>00895     <span class="keywordflow">if</span> ( NULL == (returnCube = cpl_imagelist_new()) )
+<a name="l00896"></a>00896     {
+<a name="l00897"></a>00897         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"cannot allocate new cube \n"</span> ) ;
+<a name="l00898"></a>00898         <span class="keywordflow">return</span> NULL ;
+<a name="l00899"></a>00899     }
+<a name="l00900"></a>00900 
+<a name="l00901"></a>00901     <span class="comment">/* now build the data cube out of the resampled image */</span>
+<a name="l00902"></a>00902     <span class="keywordflow">for</span> ( z = 0 ; z < ily ; z++ ) <span class="comment">/* go through the z-axis */</span>
+<a name="l00903"></a>00903     {
+<a name="l00904"></a>00904 
+<a name="l00905"></a>00905       o_img=cpl_image_new(imsize,N_SLITLETS,CPL_TYPE_FLOAT);
+<a name="l00906"></a>00906       podata=cpl_image_get_data_float(o_img);
+<a name="l00907"></a>00907         kpix       = 0 ;
+<a name="l00908"></a>00908         kslit      = 0 ;
+<a name="l00909"></a>00909         slit_index = -1 ;
+<a name="l00910"></a>00910         recol      = -1 ;
+<a name="l00911"></a>00911         <span class="keywordflow">for</span> ( col = 0 ; col < ilx ; col++ ) <span class="comment">/* go through the image columns */</span>
+<a name="l00912"></a>00912         {
+<a name="l00913"></a>00913             <span class="keywordflow">if</span> ( col % imsize == 0 )
+<a name="l00914"></a>00914             {
+<a name="l00915"></a>00915                 recol = 0 ;
+<a name="l00916"></a>00916                 kslit = col/imsize ;
+<a name="l00917"></a>00917                 <span class="comment">/* sort the slitlets in the right spiffi specific way */</span>
+<a name="l00918"></a>00918                 <span class="keywordflow">if</span>((slit_index=sinfo_sort_slitlets(kslit)) == -1) {
+<a name="l00919"></a>00919                   <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"wrong slitlet index: couldn't be a "</span>
+<a name="l00920"></a>00920                                <span class="stringliteral">"spiffi image,  there must be 32 slitlets!"</span>) ;
+<a name="l00921"></a>00921                         cpl_imagelist_delete(returnCube) ;
+<a name="l00922"></a>00922                         <span class="keywordflow">return</span> NULL ;
+<a name="l00923"></a>00923                 }
+<a name="l00924"></a>00924 
+<a name="l00925"></a>00925                 <span class="keywordflow">if</span> ( kslit != 0 )
+<a name="l00926"></a>00926                 {
+<a name="l00927"></a>00927                     <span class="comment">/*-------------------------------------------------------- </span>
+<a name="l00928"></a>00928 <span class="comment">                     * shift the first pixel by an integer if the absolute </span>
+<a name="l00929"></a>00929 <span class="comment">                     * amount of distances[]</span>
+<a name="l00930"></a>00930 <span class="comment">                     * is bigger than 0.5 </span>
+<a name="l00931"></a>00931 <span class="comment">                     */</span>
+<a name="l00932"></a>00932                     kpix = sinfo_new_nint(distances[kslit-1]) ;
+<a name="l00933"></a>00933 
+<a name="l00934"></a>00934                     <span class="comment">/*----------------------------------------------- </span>
+<a name="l00935"></a>00935 <span class="comment">                     * now sort the distances array according to the row order </span>
+<a name="l00936"></a>00936 <span class="comment">                     * and add a 0 value for the first (reference) slitlet </span>
+<a name="l00937"></a>00937 <span class="comment">                     * that means row 8 </span>
+<a name="l00938"></a>00938 <span class="comment">                     */</span>
+<a name="l00939"></a>00939                     correct_diff_dist[slit_index] = distances[kslit-1] - 
+<a name="l00940"></a>00940                                                     (float)kpix ;
+<a name="l00941"></a>00941                 }
+<a name="l00942"></a>00942                 <span class="comment">/* refer all distances to the first slitlet */</span>
+<a name="l00943"></a>00943                 <span class="keywordflow">else</span>
+<a name="l00944"></a>00944                 {
+<a name="l00945"></a>00945                     correct_diff_dist[slit_index] = 0. ;
+<a name="l00946"></a>00946                 }
+<a name="l00947"></a>00947             }
+<a name="l00948"></a>00948 
+<a name="l00949"></a>00949             <span class="comment">/* fill each cube plane with one image row */</span>
+<a name="l00950"></a>00950             podata[recol+slit_index*imsize] = pidata[col+kpix+z*ilx];
+<a name="l00951"></a>00951             recol++ ;
+<a name="l00952"></a>00952 
+<a name="l00953"></a>00953             <span class="keywordflow">if</span> ( recol > imsize )
+<a name="l00954"></a>00954             {
+<a name="l00955"></a>00955                 <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"wrong column of reconstructed "</span>
+<a name="l00956"></a>00956                                 <span class="stringliteral">"image, shouldn't happen!\n"</span>) ; 
+<a name="l00957"></a>00957                 cpl_imagelist_delete(returnCube) ;
+<a name="l00958"></a>00958                 <span class="keywordflow">return</span> NULL ;
+<a name="l00959"></a>00959             }
+<a name="l00960"></a>00960         }
+<a name="l00961"></a>00961     }
+<a name="l00962"></a>00962     <span class="keywordflow">return</span> returnCube ;
+<a name="l00963"></a>00963 }
+<a name="l00964"></a>00964 
+<a name="l00965"></a>00965 
+<a name="l00966"></a>00966 
+<a name="l00974"></a>00974 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00975"></a>00975 sinfo_sort_slitlets(<span class="keyword">const</span> <span class="keywordtype">int</span> kslit)
+<a name="l00976"></a>00976 {
+<a name="l00977"></a>00977   <span class="keywordtype">int</span> slit_index=0;
+<a name="l00978"></a>00978 
+<a name="l00979"></a>00979   <span class="keywordflow">switch</span> (kslit)
+<a name="l00980"></a>00980     {
+<a name="l00981"></a>00981     <span class="keywordflow">case</span> 0:
+<a name="l00982"></a>00982       slit_index = 8 ;
+<a name="l00983"></a>00983       break ;
+<a name="l00984"></a>00984     <span class="keywordflow">case</span> 1:
+<a name="l00985"></a>00985       slit_index = 7 ;
+<a name="l00986"></a>00986       break ;
+<a name="l00987"></a>00987     <span class="keywordflow">case</span> 2:
+<a name="l00988"></a>00988       slit_index = 9 ;
+<a name="l00989"></a>00989       break ;
+<a name="l00990"></a>00990     <span class="keywordflow">case</span> 3:
+<a name="l00991"></a>00991       slit_index = 6 ;
+<a name="l00992"></a>00992       break ;
+<a name="l00993"></a>00993     <span class="keywordflow">case</span> 4:
+<a name="l00994"></a>00994       slit_index = 10 ;
+<a name="l00995"></a>00995       break ;
+<a name="l00996"></a>00996     <span class="keywordflow">case</span> 5:
+<a name="l00997"></a>00997       slit_index = 5 ;
+<a name="l00998"></a>00998       break ;
+<a name="l00999"></a>00999     <span class="keywordflow">case</span> 6:
+<a name="l01000"></a>01000       slit_index = 11 ;
+<a name="l01001"></a>01001       break ;
+<a name="l01002"></a>01002     <span class="keywordflow">case</span> 7:
+<a name="l01003"></a>01003       slit_index = 4 ;
+<a name="l01004"></a>01004       break ;
+<a name="l01005"></a>01005     <span class="keywordflow">case</span> 8:
+<a name="l01006"></a>01006       slit_index = 12 ;
+<a name="l01007"></a>01007       break ;
+<a name="l01008"></a>01008     <span class="keywordflow">case</span> 9:
+<a name="l01009"></a>01009       slit_index = 3 ;
+<a name="l01010"></a>01010       break ;
+<a name="l01011"></a>01011     <span class="keywordflow">case</span> 10:
+<a name="l01012"></a>01012       slit_index = 13 ;
+<a name="l01013"></a>01013       break ;
+<a name="l01014"></a>01014     <span class="keywordflow">case</span> 11:
+<a name="l01015"></a>01015       slit_index = 2 ;
+<a name="l01016"></a>01016       break ;
+<a name="l01017"></a>01017     <span class="keywordflow">case</span> 12:
+<a name="l01018"></a>01018       slit_index = 14 ;
+<a name="l01019"></a>01019       break ;
+<a name="l01020"></a>01020     <span class="keywordflow">case</span> 13:
+<a name="l01021"></a>01021       slit_index = 1 ;
+<a name="l01022"></a>01022       break ;
+<a name="l01023"></a>01023     <span class="keywordflow">case</span> 14:
+<a name="l01024"></a>01024       slit_index = 15 ;
+<a name="l01025"></a>01025       break ;
+<a name="l01026"></a>01026     <span class="keywordflow">case</span> 15:
+<a name="l01027"></a>01027       slit_index = 0 ;
+<a name="l01028"></a>01028       break ;
+<a name="l01029"></a>01029     <span class="keywordflow">case</span> 16:
+<a name="l01030"></a>01030       slit_index = 31 ;
+<a name="l01031"></a>01031       break ;
+<a name="l01032"></a>01032     <span class="keywordflow">case</span> 17:
+<a name="l01033"></a>01033       slit_index = 16 ;
+<a name="l01034"></a>01034       break ;
+<a name="l01035"></a>01035     <span class="keywordflow">case</span> 18:
+<a name="l01036"></a>01036       slit_index = 30 ;
+<a name="l01037"></a>01037       break ;
+<a name="l01038"></a>01038     <span class="keywordflow">case</span> 19:
+<a name="l01039"></a>01039       slit_index = 17 ;
+<a name="l01040"></a>01040       break ;
+<a name="l01041"></a>01041     <span class="keywordflow">case</span> 20:
+<a name="l01042"></a>01042       slit_index = 29 ;
+<a name="l01043"></a>01043       break ;
+<a name="l01044"></a>01044     <span class="keywordflow">case</span> 21:
+<a name="l01045"></a>01045       slit_index = 18 ;
+<a name="l01046"></a>01046       break ;
+<a name="l01047"></a>01047     <span class="keywordflow">case</span> 22:
+<a name="l01048"></a>01048       slit_index = 28 ;
+<a name="l01049"></a>01049       break ;
+<a name="l01050"></a>01050     <span class="keywordflow">case</span> 23:
+<a name="l01051"></a>01051       slit_index = 19 ;
+<a name="l01052"></a>01052       break ;
+<a name="l01053"></a>01053     <span class="keywordflow">case</span> 24:
+<a name="l01054"></a>01054       slit_index = 27 ;
+<a name="l01055"></a>01055       break ;
+<a name="l01056"></a>01056     <span class="keywordflow">case</span> 25:
+<a name="l01057"></a>01057       slit_index = 20 ;
+<a name="l01058"></a>01058       break ;
+<a name="l01059"></a>01059     <span class="keywordflow">case</span> 26:
+<a name="l01060"></a>01060       slit_index = 26 ;
+<a name="l01061"></a>01061       break ;
+<a name="l01062"></a>01062     <span class="keywordflow">case</span> 27:
+<a name="l01063"></a>01063       slit_index = 21 ;
+<a name="l01064"></a>01064       break ;
+<a name="l01065"></a>01065     <span class="keywordflow">case</span> 28:
+<a name="l01066"></a>01066       slit_index = 25 ;
+<a name="l01067"></a>01067       break ;
+<a name="l01068"></a>01068     <span class="keywordflow">case</span> 29:
+<a name="l01069"></a>01069       slit_index = 22 ;
+<a name="l01070"></a>01070       break ;
+<a name="l01071"></a>01071     <span class="keywordflow">case</span> 30:
+<a name="l01072"></a>01072       slit_index = 24 ;
+<a name="l01073"></a>01073       break ;
+<a name="l01074"></a>01074     <span class="keywordflow">case</span> 31:
+<a name="l01075"></a>01075       slit_index = 23 ;
+<a name="l01076"></a>01076       break ;
+<a name="l01077"></a>01077     <span class="keywordflow">default</span>:
+<a name="l01078"></a>01078       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"wrong slitlet index: couldn't be a "</span>
+<a name="l01079"></a>01079                       <span class="stringliteral">"spiffi image,  there must be 32 slitlets!"</span>) ;
+<a name="l01080"></a>01080       <span class="keywordflow">return</span> -1 ;
+<a name="l01081"></a>01081       break ;
+<a name="l01082"></a>01082                 
+<a name="l01083"></a>01083    }
+<a name="l01084"></a>01084    <span class="keywordflow">return</span> slit_index;
+<a name="l01085"></a>01085 
+<a name="l01086"></a>01086 }
+<a name="l01087"></a>01087 
+<a name="l01098"></a>01098 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l01099"></a>01099 sinfo_sort_slitlets_array(<span class="keyword">const</span> <span class="keywordtype">int</span> slit, <span class="keywordtype">int</span>* row_index)
+<a name="l01100"></a>01100 {
+<a name="l01101"></a>01101 
+<a name="l01102"></a>01102   <span class="keywordflow">switch</span> (slit)
+<a name="l01103"></a>01103     {
+<a name="l01104"></a>01104     <span class="keywordflow">case</span> 0:
+<a name="l01105"></a>01105       row_index[0] = 8 ;
+<a name="l01106"></a>01106       break ;
+<a name="l01107"></a>01107     <span class="keywordflow">case</span> 1:
+<a name="l01108"></a>01108       row_index[1] = 7 ;
+<a name="l01109"></a>01109       break ;
+<a name="l01110"></a>01110     <span class="keywordflow">case</span> 2:
+<a name="l01111"></a>01111       row_index[2] = 9 ;
+<a name="l01112"></a>01112       break ;
+<a name="l01113"></a>01113     <span class="keywordflow">case</span> 3:
+<a name="l01114"></a>01114       row_index[3] = 6 ;
+<a name="l01115"></a>01115       break ;
+<a name="l01116"></a>01116     <span class="keywordflow">case</span> 4:
+<a name="l01117"></a>01117       row_index[4] = 10 ;
+<a name="l01118"></a>01118       break ;
+<a name="l01119"></a>01119     <span class="keywordflow">case</span> 5:
+<a name="l01120"></a>01120       row_index[5] = 5 ;
+<a name="l01121"></a>01121       break ;
+<a name="l01122"></a>01122     <span class="keywordflow">case</span> 6:
+<a name="l01123"></a>01123       row_index[6] = 11 ;
+<a name="l01124"></a>01124       break ;
+<a name="l01125"></a>01125     <span class="keywordflow">case</span> 7:
+<a name="l01126"></a>01126       row_index[7] = 4 ;
+<a name="l01127"></a>01127       break ;
+<a name="l01128"></a>01128     <span class="keywordflow">case</span> 8:
+<a name="l01129"></a>01129       row_index[8] = 12 ;
+<a name="l01130"></a>01130       break ;
+<a name="l01131"></a>01131     <span class="keywordflow">case</span> 9:
+<a name="l01132"></a>01132       row_index[9] = 3 ;
+<a name="l01133"></a>01133       break ;
+<a name="l01134"></a>01134     <span class="keywordflow">case</span> 10:
+<a name="l01135"></a>01135       row_index[10] = 13 ;
+<a name="l01136"></a>01136       break ;
+<a name="l01137"></a>01137     <span class="keywordflow">case</span> 11:
+<a name="l01138"></a>01138       row_index[11] = 2 ;
+<a name="l01139"></a>01139       break ;
+<a name="l01140"></a>01140     <span class="keywordflow">case</span> 12:
+<a name="l01141"></a>01141       row_index[12] = 14 ;
+<a name="l01142"></a>01142       break ;
+<a name="l01143"></a>01143     <span class="keywordflow">case</span> 13:
+<a name="l01144"></a>01144       row_index[13] = 1 ;
+<a name="l01145"></a>01145       break ;
+<a name="l01146"></a>01146     <span class="keywordflow">case</span> 14:
+<a name="l01147"></a>01147       row_index[14] = 15 ;
+<a name="l01148"></a>01148       break ;
+<a name="l01149"></a>01149     <span class="keywordflow">case</span> 15:
+<a name="l01150"></a>01150       row_index[15] = 0 ;
+<a name="l01151"></a>01151       break ;
+<a name="l01152"></a>01152     <span class="keywordflow">case</span> 16:
+<a name="l01153"></a>01153       row_index[16] = 31 ;
+<a name="l01154"></a>01154       break ;
+<a name="l01155"></a>01155     <span class="keywordflow">case</span> 17:
+<a name="l01156"></a>01156       row_index[17] = 16 ;
+<a name="l01157"></a>01157       break ;
+<a name="l01158"></a>01158     <span class="keywordflow">case</span> 18:
+<a name="l01159"></a>01159       row_index[18] = 30 ;
+<a name="l01160"></a>01160       break ;
+<a name="l01161"></a>01161     <span class="keywordflow">case</span> 19:
+<a name="l01162"></a>01162       row_index[19] = 17 ;
+<a name="l01163"></a>01163       break ;
+<a name="l01164"></a>01164     <span class="keywordflow">case</span> 20:
+<a name="l01165"></a>01165       row_index[20] = 29 ;
+<a name="l01166"></a>01166       break ;
+<a name="l01167"></a>01167     <span class="keywordflow">case</span> 21:
+<a name="l01168"></a>01168       row_index[21] = 18 ;
+<a name="l01169"></a>01169       break ;
+<a name="l01170"></a>01170     <span class="keywordflow">case</span> 22:
+<a name="l01171"></a>01171       row_index[22] = 28 ;
+<a name="l01172"></a>01172       break ;
+<a name="l01173"></a>01173     <span class="keywordflow">case</span> 23:
+<a name="l01174"></a>01174       row_index[23] = 19 ;
+<a name="l01175"></a>01175       break ;
+<a name="l01176"></a>01176     <span class="keywordflow">case</span> 24:
+<a name="l01177"></a>01177       row_index[24] = 27 ;
+<a name="l01178"></a>01178       break ;
+<a name="l01179"></a>01179     <span class="keywordflow">case</span> 25:
+<a name="l01180"></a>01180       row_index[25] = 20 ;
+<a name="l01181"></a>01181       break ;
+<a name="l01182"></a>01182     <span class="keywordflow">case</span> 26:
+<a name="l01183"></a>01183       row_index[26] = 26 ;
+<a name="l01184"></a>01184       break ;
+<a name="l01185"></a>01185     <span class="keywordflow">case</span> 27:
+<a name="l01186"></a>01186       row_index[27] = 21 ;
+<a name="l01187"></a>01187       break ;
+<a name="l01188"></a>01188     <span class="keywordflow">case</span> 28:
+<a name="l01189"></a>01189       row_index[28] = 25 ;
+<a name="l01190"></a>01190       break ;
+<a name="l01191"></a>01191     <span class="keywordflow">case</span> 29:
+<a name="l01192"></a>01192       row_index[29] = 22 ;
+<a name="l01193"></a>01193       break ;
+<a name="l01194"></a>01194     <span class="keywordflow">case</span> 30:
+<a name="l01195"></a>01195       row_index[30] = 24 ;
+<a name="l01196"></a>01196       break ;
+<a name="l01197"></a>01197     <span class="keywordflow">case</span> 31:
+<a name="l01198"></a>01198       row_index[31] = 23 ;
+<a name="l01199"></a>01199       break ;
+<a name="l01200"></a>01200     <span class="keywordflow">default</span>:
+<a name="l01201"></a>01201       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"wrong slitlet index: couldn't be a spiffi "</span>
+<a name="l01202"></a>01202                       <span class="stringliteral">"image,  there must be 32 slitlets!\n"</span>) ;
+<a name="l01203"></a>01203       <span class="keywordflow">return</span> -1 ;
+<a name="l01204"></a>01204     }
+<a name="l01205"></a>01205 
+<a name="l01206"></a>01206   <span class="keywordflow">return</span> 0;
+<a name="l01207"></a>01207 
+<a name="l01208"></a>01208 }
+<a name="l01209"></a>01209 
+<a name="l01210"></a>01210 
+<a name="l01211"></a>01211 
+<a name="l01228"></a>01228 cpl_imagelist * 
+<a name="l01229"></a>01229 sinfo_new_make_cube_spi ( cpl_image *  calibImage,
+<a name="l01230"></a>01230                         <span class="keywordtype">float</span>    ** slit_edges,
+<a name="l01231"></a>01231                         <span class="keywordtype">float</span>    *  shift )
+<a name="l01232"></a>01232 {
+<a name="l01233"></a>01233     cpl_imagelist * returnCube ;
+<a name="l01234"></a>01234     <span class="keywordtype">float</span> diff, start ;
+<a name="l01235"></a>01235     <span class="keywordtype">float</span> * center ;
+<a name="l01236"></a>01236     <span class="keywordtype">int</span> * row_index ;
+<a name="l01237"></a>01237     <span class="keywordtype">int</span> slit ;
+<a name="l01238"></a>01238     <span class="keywordtype">int</span> col, z ;
+<a name="l01239"></a>01239     <span class="keywordtype">int</span> imsize ;
+<a name="l01240"></a>01240     <span class="keywordtype">int</span> * beginCol ;
+<a name="l01241"></a>01241     <span class="keywordtype">int</span> col_counter ;
+<a name="l01242"></a>01242     <span class="keywordtype">int</span> ilx=0;
+<a name="l01243"></a>01243     <span class="keywordtype">int</span> ily=0;
+<a name="l01244"></a>01244 
+<a name="l01245"></a>01245     <span class="keywordtype">float</span>* podata=NULL;
+<a name="l01246"></a>01246     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l01247"></a>01247     cpl_image* o_img;
+<a name="l01248"></a>01248 
+<a name="l01249"></a>01249 
+<a name="l01250"></a>01250     <span class="keywordflow">if</span> ( NULL == calibImage )
+<a name="l01251"></a>01251     {
+<a name="l01252"></a>01252         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no resampled image given!\n"</span>) ;
+<a name="l01253"></a>01253         <span class="keywordflow">return</span> NULL ;
+<a name="l01254"></a>01254     }
+<a name="l01255"></a>01255     ilx=cpl_image_get_size_x(calibImage);
+<a name="l01256"></a>01256     ily=cpl_image_get_size_y(calibImage);
+<a name="l01257"></a>01257     pidata=cpl_image_get_data_float(calibImage);
+<a name="l01258"></a>01258 
+<a name="l01259"></a>01259     <span class="keywordflow">if</span> ( NULL == slit_edges )
+<a name="l01260"></a>01260     {
+<a name="l01261"></a>01261         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no slit_edges array given from sinfo_fitSlits()!/n"</span>) ;
+<a name="l01262"></a>01262         <span class="keywordflow">return</span> NULL ;
+<a name="l01263"></a>01263     }
+<a name="l01264"></a>01264 
+<a name="l01265"></a>01265     <span class="keywordflow">if</span> ( N_SLITLETS != 32 )
+<a name="l01266"></a>01266     {
+<a name="l01267"></a>01267         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"wrong number of slitlets given \n"</span> ) ;
+<a name="l01268"></a>01268         <span class="keywordflow">return</span> NULL ;
+<a name="l01269"></a>01269     }
+<a name="l01270"></a>01270     imsize = ilx / N_SLITLETS ;
+<a name="l01271"></a>01271 
+<a name="l01272"></a>01272     <span class="comment">/* allocate memory */</span>  
+<a name="l01273"></a>01273     <span class="keywordflow">if</span> ( NULL == (row_index = (<span class="keywordtype">int</span>*) cpl_calloc(N_SLITLETS, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>)) ) )
+<a name="l01274"></a>01274     {
+<a name="l01275"></a>01275         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"cannot allocate memory \n"</span> ) ;
+<a name="l01276"></a>01276         <span class="keywordflow">return</span> NULL ;
+<a name="l01277"></a>01277     }
+<a name="l01278"></a>01278     <span class="keywordflow">if</span> ( NULL == (beginCol = (<span class="keywordtype">int</span>*) cpl_calloc(N_SLITLETS, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>)) ) )
+<a name="l01279"></a>01279     {
+<a name="l01280"></a>01280         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"cannot allocate memory \n"</span> ) ;
+<a name="l01281"></a>01281         cpl_free(row_index) ;
+<a name="l01282"></a>01282         <span class="keywordflow">return</span> NULL ;
+<a name="l01283"></a>01283     }
+<a name="l01284"></a>01284     <span class="keywordflow">if</span> ( NULL == (center = (<span class="keywordtype">float</span>*) cpl_calloc(N_SLITLETS, <span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ) )
+<a name="l01285"></a>01285     {
+<a name="l01286"></a>01286         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"cannot allocate memory \n"</span> ) ;
+<a name="l01287"></a>01287         cpl_free (row_index) ;
+<a name="l01288"></a>01288         cpl_free (beginCol) ;
+<a name="l01289"></a>01289         <span class="keywordflow">return</span> NULL ;
+<a name="l01290"></a>01290     }
+<a name="l01291"></a>01291     <span class="keywordflow">if</span> ( NULL == (returnCube = cpl_imagelist_new()) )
+<a name="l01292"></a>01292     {
+<a name="l01293"></a>01293         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"cannot allocate new cube \n"</span> ) ;
+<a name="l01294"></a>01294         cpl_free (row_index) ;
+<a name="l01295"></a>01295         cpl_free (beginCol) ;
+<a name="l01296"></a>01296         cpl_free (center) ;
+<a name="l01297"></a>01297         <span class="keywordflow">return</span> NULL ;
+<a name="l01298"></a>01298     }
+<a name="l01299"></a>01299     <span class="comment">/* determine the absolute center of the slitlets and the distances </span>
+<a name="l01300"></a>01300 <span class="comment">       inside the image*/</span>
+<a name="l01301"></a>01301     <span class="keywordflow">for</span> ( slit = 0 ; slit < N_SLITLETS ; slit++ ) 
+<a name="l01302"></a>01302     <span class="comment">/* go through the slitlets of each row of the resampled image */</span>
+<a name="l01303"></a>01303     {
+<a name="l01304"></a>01304         center[slit] = (slit_edges[slit][1] + slit_edges[slit][0]) / 2. ;
+<a name="l01305"></a>01305         <span class="comment">/* -------------------------------------------------------------</span>
+<a name="l01306"></a>01306 <span class="comment">         * sort the slitlets in the right spiffi specific way</span>
+<a name="l01307"></a>01307 <span class="comment">         * the row_index describes the row index of the current slitlet </span>
+<a name="l01308"></a>01308 <span class="comment">         * in the resulting cube images.</span>
+<a name="l01309"></a>01309 <span class="comment">         */</span>
+<a name="l01310"></a>01310         <span class="keywordflow">if</span>(-1 == sinfo_sort_slitlets_array(slit,row_index)) {
+<a name="l01311"></a>01311       cpl_imagelist_delete(returnCube) ;
+<a name="l01312"></a>01312       cpl_free (row_index) ;
+<a name="l01313"></a>01313           cpl_free (beginCol) ;
+<a name="l01314"></a>01314           cpl_free (center) ;
+<a name="l01315"></a>01315           <span class="keywordflow">return</span> NULL ;
+<a name="l01316"></a>01316         }
+<a name="l01317"></a>01317         <span class="comment">/* determine the integer column on which the slitlet starts, center the</span>
+<a name="l01318"></a>01318 <span class="comment">           slitlet on the image row */</span>
+<a name="l01319"></a>01319         start = center[slit] - (float) (imsize - 1)/2. ;
+<a name="l01320"></a>01320         beginCol[slit] = sinfo_new_nint (start) ;
+<a name="l01321"></a>01321         <span class="comment">/* determine the error of using integer pixels */</span>
+<a name="l01322"></a>01322         diff = start - (float)beginCol[slit] ;
+<a name="l01323"></a>01323 
+<a name="l01324"></a>01324         <span class="comment">/*-------------------------------------------------------------------- </span>
+<a name="l01325"></a>01325 <span class="comment">         * determine the output shift values by which the rows are finally </span>
+<a name="l01326"></a>01326 <span class="comment">           shifted, consider the integer pixel errors  </span>
+<a name="l01327"></a>01327 <span class="comment">         * resort shift array to get the row index </span>
+<a name="l01328"></a>01328 <span class="comment">         */</span>
+<a name="l01329"></a>01329         shift[row_index[slit]] = diff ;
+<a name="l01330"></a>01330     }   
+<a name="l01331"></a>01331 
+<a name="l01332"></a>01332     <span class="comment">/* now build the data cube out of the resampled image */</span>
+<a name="l01333"></a>01333     <span class="keywordflow">for</span> ( z = 0 ; z < ily ; z++ ) <span class="comment">/* go through the z-axis */</span>
+<a name="l01334"></a>01334     {
+<a name="l01335"></a>01335       o_img=cpl_image_new(imsize,N_SLITLETS,CPL_TYPE_FLOAT);
+<a name="l01336"></a>01336       podata=cpl_image_get_data_float(o_img);
+<a name="l01337"></a>01337       <span class="keywordflow">for</span> ( slit = 0 ; slit < N_SLITLETS ; slit++ )
+<a name="l01338"></a>01338         {
+<a name="l01339"></a>01339       col_counter = beginCol[slit] ;
+<a name="l01340"></a>01340       <span class="comment">/* each slitlet is centered on the final image row */</span>
+<a name="l01341"></a>01341       <span class="keywordflow">for</span> ( col = 0 ; col < imsize ; col++ )
+<a name="l01342"></a>01342             {
+<a name="l01343"></a>01343           <span class="keywordflow">if</span> ( col_counter > ilx-1 )
+<a name="l01344"></a>01344                 {
+<a name="l01345"></a>01345           col_counter-- ;
+<a name="l01346"></a>01346                 }
+<a name="l01347"></a>01347           <span class="keywordflow">if</span> ( col_counter + z*ilx < 0 )
+<a name="l01348"></a>01348                 {
+<a name="l01349"></a>01349           podata[col+row_index[slit]*imsize] = pidata[0] ;
+<a name="l01350"></a>01350                 }
+<a name="l01351"></a>01351               <span class="keywordflow">else</span>
+<a name="l01352"></a>01352                 {   
+<a name="l01353"></a>01353                   podata[col+row_index[slit]*imsize]=pidata[col_counter+z*ilx];
+<a name="l01354"></a>01354                 }
+<a name="l01355"></a>01355 
+<a name="l01356"></a>01356                 col_counter++ ;
+<a name="l01357"></a>01357             }
+<a name="l01358"></a>01358         }
+<a name="l01359"></a>01359       cpl_imagelist_set(returnCube,o_img,z);    
+<a name="l01360"></a>01360     }
+<a name="l01361"></a>01361     cpl_free (row_index) ;
+<a name="l01362"></a>01362     cpl_free (beginCol) ;
+<a name="l01363"></a>01363     cpl_free (center) ;
+<a name="l01364"></a>01364 
+<a name="l01365"></a>01365     <span class="keywordflow">return</span> returnCube ;
+<a name="l01366"></a>01366 }
+<a name="l01393"></a>01393 cpl_imagelist * 
+<a name="l01394"></a>01394 sinfo_new_make_cube_dist ( cpl_image * calibImage,
+<a name="l01395"></a>01395                          <span class="keywordtype">float</span>      firstCol,
+<a name="l01396"></a>01396                          <span class="keywordtype">float</span>    * distances,
+<a name="l01397"></a>01397                          <span class="keywordtype">float</span>    * shift )
+<a name="l01398"></a>01398 {
+<a name="l01399"></a>01399     cpl_imagelist * returnCube ;
+<a name="l01400"></a>01400     <span class="keywordtype">float</span> di ;
+<a name="l01401"></a>01401     <span class="keywordtype">float</span> diff, start ;
+<a name="l01402"></a>01402     <span class="keywordtype">int</span> * row_index ;
+<a name="l01403"></a>01403     <span class="keywordtype">int</span> slit ;
+<a name="l01404"></a>01404     <span class="keywordtype">int</span> col, z ;
+<a name="l01405"></a>01405     <span class="keywordtype">int</span> imsize ;
+<a name="l01406"></a>01406     <span class="keywordtype">int</span> * beginCol ;
+<a name="l01407"></a>01407     <span class="keywordtype">int</span> col_counter ;
+<a name="l01408"></a>01408     <span class="keywordtype">int</span> ilx=0;
+<a name="l01409"></a>01409     <span class="keywordtype">int</span> ily=0;
+<a name="l01410"></a>01410 
+<a name="l01411"></a>01411     <span class="keywordtype">float</span>* podata=NULL;
+<a name="l01412"></a>01412     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l01413"></a>01413     cpl_image* o_img;
+<a name="l01414"></a>01414 
+<a name="l01415"></a>01415     <span class="keywordflow">if</span> ( NULL == calibImage )
+<a name="l01416"></a>01416     {
+<a name="l01417"></a>01417         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" no resampled image given!\n"</span>) ;
+<a name="l01418"></a>01418         <span class="keywordflow">return</span> NULL ;
+<a name="l01419"></a>01419     }
+<a name="l01420"></a>01420     ilx=cpl_image_get_size_x(calibImage);
+<a name="l01421"></a>01421     ily=cpl_image_get_size_y(calibImage);
+<a name="l01422"></a>01422     pidata=cpl_image_get_data_float(calibImage);
+<a name="l01423"></a>01423 
+<a name="l01424"></a>01424     <span class="keywordflow">if</span> ( NULL == distances )
+<a name="l01425"></a>01425     {
+<a name="l01426"></a>01426         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no distances array given from north_south_test()!"</span>) ;
+<a name="l01427"></a>01427         <span class="keywordflow">return</span> NULL ;
+<a name="l01428"></a>01428     }
+<a name="l01429"></a>01429 
+<a name="l01430"></a>01430     <span class="keywordflow">if</span> ( N_SLITLETS != 32 )
+<a name="l01431"></a>01431     {
+<a name="l01432"></a>01432         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"wrong number of slitlets given \n"</span> ) ;
+<a name="l01433"></a>01433         <span class="keywordflow">return</span> NULL ;
+<a name="l01434"></a>01434     }
+<a name="l01435"></a>01435     imsize = ilx / N_SLITLETS ;
+<a name="l01436"></a>01436 
+<a name="l01437"></a>01437     <span class="comment">/* allocate memory */</span>  
+<a name="l01438"></a>01438     <span class="keywordflow">if</span> ( NULL == (row_index = (<span class="keywordtype">int</span>*) cpl_calloc(N_SLITLETS, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>)) ) )
+<a name="l01439"></a>01439     {
+<a name="l01440"></a>01440         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"cannot allocate memory \n"</span> ) ;
+<a name="l01441"></a>01441         <span class="keywordflow">return</span> NULL ;
+<a name="l01442"></a>01442     }
+<a name="l01443"></a>01443     <span class="keywordflow">if</span> ( NULL == (beginCol = (<span class="keywordtype">int</span>*) cpl_calloc(N_SLITLETS, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>)) ) )
+<a name="l01444"></a>01444     {
+<a name="l01445"></a>01445         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"cannot allocate memory \n"</span> ) ;
+<a name="l01446"></a>01446         cpl_free(row_index) ;
+<a name="l01447"></a>01447         <span class="keywordflow">return</span> NULL ;
+<a name="l01448"></a>01448     }
+<a name="l01449"></a>01449     <span class="keywordflow">if</span> ( NULL == (returnCube = cpl_imagelist_new()) )
+<a name="l01450"></a>01450     {
+<a name="l01451"></a>01451         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"cannot allocate new cube \n"</span> ) ;
+<a name="l01452"></a>01452         cpl_free(row_index) ;
+<a name="l01453"></a>01453         cpl_free(beginCol) ;
+<a name="l01454"></a>01454         <span class="keywordflow">return</span> NULL ;
+<a name="l01455"></a>01455     }
+<a name="l01456"></a>01456 
+<a name="l01457"></a>01457     di = 0. ;
+<a name="l01458"></a>01458     <span class="comment">/* determine the absolute beginning of the slitlets and the distances </span>
+<a name="l01459"></a>01459 <span class="comment">       inside the image*/</span>
+<a name="l01460"></a>01460     <span class="keywordflow">for</span> ( slit = 0 ; slit < N_SLITLETS ; slit++ ) 
+<a name="l01461"></a>01461     <span class="comment">/* go through the slitlets of each row of the resampled image */</span>
+<a name="l01462"></a>01462     {
+<a name="l01463"></a>01463 
+<a name="l01464"></a>01464         <span class="comment">/* -------------------------------------------------------------</span>
+<a name="l01465"></a>01465 <span class="comment">         * sort the slitlets in the right spiffi specific way</span>
+<a name="l01466"></a>01466 <span class="comment">         * the row_index describes the row index of the current slitlet </span>
+<a name="l01467"></a>01467 <span class="comment">         * in the resulting cube images.</span>
+<a name="l01468"></a>01468 <span class="comment">         */</span>
+<a name="l01469"></a>01469         <span class="keywordflow">if</span>(-1 == sinfo_sort_slitlets_array(slit,row_index)) {
+<a name="l01470"></a>01470       cpl_imagelist_delete(returnCube) ;
+<a name="l01471"></a>01471       cpl_free(row_index) ;
+<a name="l01472"></a>01472       cpl_free(beginCol) ;
+<a name="l01473"></a>01473       <span class="keywordflow">return</span> NULL ;
+<a name="l01474"></a>01474         }
+<a name="l01475"></a>01475 
+<a name="l01476"></a>01476         <span class="comment">/* determine the integer column on which the slitlet starts */</span>
+<a name="l01477"></a>01477         <span class="keywordflow">if</span> ( slit == 0 )
+<a name="l01478"></a>01478         {
+<a name="l01479"></a>01479             start = firstCol ;
+<a name="l01480"></a>01480         }
+<a name="l01481"></a>01481         <span class="keywordflow">else</span>
+<a name="l01482"></a>01482         {
+<a name="l01483"></a>01483             di += distances[slit-1] ;
+<a name="l01484"></a>01484             start = firstCol + di ;
+<a name="l01485"></a>01485         }
+<a name="l01486"></a>01486         beginCol[slit] = sinfo_new_nint(start) ;
+<a name="l01487"></a>01487 
+<a name="l01488"></a>01488         <span class="comment">/* determine the error of using integer pixels, its always smaller </span>
+<a name="l01489"></a>01489 <span class="comment">           than 1 */</span>
+<a name="l01490"></a>01490         diff = start - (float)beginCol[slit] ;
+<a name="l01491"></a>01491 
+<a name="l01492"></a>01492         <span class="comment">/*---------------------------------------------------------------- </span>
+<a name="l01493"></a>01493 <span class="comment">         * determine the output shift values by which the rows are finally </span>
+<a name="l01494"></a>01494 <span class="comment">         * shifted, consider the integer pixel errors and resort shift array </span>
+<a name="l01495"></a>01495 <span class="comment">         * to get the row index </span>
+<a name="l01496"></a>01496 <span class="comment">         */</span>
+<a name="l01497"></a>01497         shift[row_index[slit]] = diff ;
+<a name="l01498"></a>01498     }   
+<a name="l01499"></a>01499 
+<a name="l01500"></a>01500     <span class="comment">/* now build the data cube out of the resampled image */</span>
+<a name="l01501"></a>01501     <span class="keywordflow">for</span> ( z = 0 ; z < ily ; z++ ) <span class="comment">/* go through the z-axis */</span>
+<a name="l01502"></a>01502     {
+<a name="l01503"></a>01503       o_img=cpl_image_new(imsize,N_SLITLETS,CPL_TYPE_FLOAT);
+<a name="l01504"></a>01504       podata=cpl_image_get_data_float(o_img);
+<a name="l01505"></a>01505       <span class="keywordflow">for</span> ( slit = 0 ; slit < N_SLITLETS ; slit++ )
+<a name="l01506"></a>01506         {
+<a name="l01507"></a>01507       col_counter = beginCol[slit] ;
+<a name="l01508"></a>01508       <span class="comment">/* each slitlet is centered on the final image row */</span>
+<a name="l01509"></a>01509       <span class="keywordflow">for</span> ( col = 0 ; col < imsize ; col++ )
+<a name="l01510"></a>01510             {
+<a name="l01511"></a>01511           <span class="keywordflow">if</span> ( col_counter > ilx-1 )
+<a name="l01512"></a>01512                 {
+<a name="l01513"></a>01513           col_counter-- ;
+<a name="l01514"></a>01514                 }
+<a name="l01515"></a>01515                 <span class="keywordflow">if</span> ( col_counter + z*ilx < 0 )
+<a name="l01516"></a>01516                 {
+<a name="l01517"></a>01517           podata[col+row_index[slit]*imsize] = podata[0] ;
+<a name="l01518"></a>01518                 }
+<a name="l01519"></a>01519                 <span class="keywordflow">else</span>
+<a name="l01520"></a>01520                 {   
+<a name="l01521"></a>01521                   podata[col+row_index[slit]*imsize]=pidata[col_counter+z*ilx];
+<a name="l01522"></a>01522                 }
+<a name="l01523"></a>01523 
+<a name="l01524"></a>01524                 col_counter++ ;
+<a name="l01525"></a>01525             }
+<a name="l01526"></a>01526         }  
+<a name="l01527"></a>01527       cpl_imagelist_set(returnCube,o_img,z);  
+<a name="l01528"></a>01528     }
+<a name="l01529"></a>01529     cpl_free (row_index) ;
+<a name="l01530"></a>01530     cpl_free (beginCol) ;
+<a name="l01531"></a>01531 
+<a name="l01532"></a>01532     <span class="keywordflow">return</span> returnCube ;
+<a name="l01533"></a>01533 }
+<a name="l01560"></a>01560 cpl_imagelist * 
+<a name="l01561"></a>01561 sinfo_new_make_3D_cube_dist ( cpl_image * calibImage,
+<a name="l01562"></a>01562                            <span class="keywordtype">float</span>      firstCol,
+<a name="l01563"></a>01563                            <span class="keywordtype">float</span>    * distances,
+<a name="l01564"></a>01564                            <span class="keywordtype">float</span>    * shift )
+<a name="l01565"></a>01565 {
+<a name="l01566"></a>01566     cpl_imagelist * returnCube ;
+<a name="l01567"></a>01567     <span class="keywordtype">float</span> di ;
+<a name="l01568"></a>01568     <span class="keywordtype">float</span> diff, start ;
+<a name="l01569"></a>01569     <span class="keywordtype">int</span> * row_index ;
+<a name="l01570"></a>01570     <span class="keywordtype">int</span> slit ;
+<a name="l01571"></a>01571     <span class="keywordtype">int</span> col, z ;
+<a name="l01572"></a>01572     <span class="keywordtype">int</span> imsize ;
+<a name="l01573"></a>01573     <span class="keywordtype">int</span> * beginCol ;
+<a name="l01574"></a>01574     <span class="keywordtype">int</span> col_counter ;
+<a name="l01575"></a>01575     <span class="keywordtype">int</span> ilx=0;
+<a name="l01576"></a>01576     <span class="keywordtype">int</span> ily=0;
+<a name="l01577"></a>01577 
+<a name="l01578"></a>01578     <span class="keywordtype">float</span>* podata=NULL;
+<a name="l01579"></a>01579     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l01580"></a>01580     cpl_image* o_img;
+<a name="l01581"></a>01581 
+<a name="l01582"></a>01582     <span class="keywordflow">if</span> ( NULL == calibImage )
+<a name="l01583"></a>01583     {
+<a name="l01584"></a>01584         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" no resampled image given!\n"</span>) ;
+<a name="l01585"></a>01585         <span class="keywordflow">return</span> NULL ;
+<a name="l01586"></a>01586     }
+<a name="l01587"></a>01587     ilx=cpl_image_get_size_x(calibImage);
+<a name="l01588"></a>01588     ily=cpl_image_get_size_y(calibImage);
+<a name="l01589"></a>01589     pidata=cpl_image_get_data_float(calibImage);
+<a name="l01590"></a>01590 
+<a name="l01591"></a>01591     <span class="keywordflow">if</span> ( NULL == distances )
+<a name="l01592"></a>01592     {
+<a name="l01593"></a>01593         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no distances array given from north_south_test()!"</span>) ;
+<a name="l01594"></a>01594         <span class="keywordflow">return</span> NULL ;
+<a name="l01595"></a>01595     }
+<a name="l01596"></a>01596 
+<a name="l01597"></a>01597     <span class="keywordflow">if</span> ( N_SLITLETS != 16 )
+<a name="l01598"></a>01598     {
+<a name="l01599"></a>01599         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"wrong number of slitlets given \n"</span> ) ;
+<a name="l01600"></a>01600         <span class="keywordflow">return</span> NULL ;
+<a name="l01601"></a>01601     }
+<a name="l01602"></a>01602     imsize = ilx / N_SLITLETS ;
+<a name="l01603"></a>01603 
+<a name="l01604"></a>01604     <span class="comment">/* allocate memory */</span>  
+<a name="l01605"></a>01605     <span class="keywordflow">if</span> ( NULL == (row_index = (<span class="keywordtype">int</span>*) cpl_calloc(N_SLITLETS, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>)) ) )
+<a name="l01606"></a>01606     {
+<a name="l01607"></a>01607         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"cannot allocate memory \n"</span> ) ;
+<a name="l01608"></a>01608         <span class="keywordflow">return</span> NULL ;
+<a name="l01609"></a>01609     }
+<a name="l01610"></a>01610     <span class="keywordflow">if</span> ( NULL == (beginCol = (<span class="keywordtype">int</span>*) cpl_calloc(N_SLITLETS, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>)) ) )
+<a name="l01611"></a>01611     {
+<a name="l01612"></a>01612         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"cannot allocate memory \n"</span> ) ;
+<a name="l01613"></a>01613         cpl_free(row_index) ;
+<a name="l01614"></a>01614         <span class="keywordflow">return</span> NULL ;
+<a name="l01615"></a>01615     }
+<a name="l01616"></a>01616     <span class="keywordflow">if</span> ( NULL == (returnCube = cpl_imagelist_new()) )
+<a name="l01617"></a>01617     {
+<a name="l01618"></a>01618         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"cannot allocate new cube \n"</span> ) ;
+<a name="l01619"></a>01619         cpl_free(row_index) ;
+<a name="l01620"></a>01620         cpl_free(beginCol) ;
+<a name="l01621"></a>01621         <span class="keywordflow">return</span> NULL ;
+<a name="l01622"></a>01622     }
+<a name="l01623"></a>01623 
+<a name="l01624"></a>01624     di = 0. ;
+<a name="l01625"></a>01625     <span class="comment">/* determine the absolute beginning of the slitlets and the distances </span>
+<a name="l01626"></a>01626 <span class="comment">       inside the image*/</span>
+<a name="l01627"></a>01627     <span class="keywordflow">for</span> ( slit = 0 ; slit < N_SLITLETS ; slit++ ) 
+<a name="l01628"></a>01628     <span class="comment">/* go through the slitlets of each row of the resampled image */</span>
+<a name="l01629"></a>01629     {
+<a name="l01630"></a>01630 
+<a name="l01631"></a>01631         <span class="comment">/* --------------------------------------------------------------</span>
+<a name="l01632"></a>01632 <span class="comment">         * sort the slitlets in the right 3D specific way</span>
+<a name="l01633"></a>01633 <span class="comment">         * the row_index describes the row index of the current slitlet </span>
+<a name="l01634"></a>01634 <span class="comment">         * in the resulting cube images.</span>
+<a name="l01635"></a>01635 <span class="comment">         */</span>
+<a name="l01636"></a>01636         row_index[slit] = slit ;
+<a name="l01637"></a>01637 
+<a name="l01638"></a>01638         <span class="comment">/* determine the integer column on which the slitlet starts */</span>
+<a name="l01639"></a>01639         <span class="keywordflow">if</span> ( slit == 0 )
+<a name="l01640"></a>01640         {
+<a name="l01641"></a>01641             start = firstCol ;
+<a name="l01642"></a>01642         }
+<a name="l01643"></a>01643         <span class="keywordflow">else</span>
+<a name="l01644"></a>01644         {
+<a name="l01645"></a>01645             di += distances[slit-1] ;
+<a name="l01646"></a>01646             start = firstCol + di ;
+<a name="l01647"></a>01647         }
+<a name="l01648"></a>01648         beginCol[slit] = sinfo_new_nint(start) ;
+<a name="l01649"></a>01649 
+<a name="l01650"></a>01650         <span class="comment">/* determine the error of using integer pixels, </span>
+<a name="l01651"></a>01651 <span class="comment">           `its always smaller than 1 */</span>
+<a name="l01652"></a>01652         diff = start - (float)beginCol[slit] ;
+<a name="l01653"></a>01653 
+<a name="l01654"></a>01654         <span class="comment">/*---------------------------------------------------------------- </span>
+<a name="l01655"></a>01655 <span class="comment">         * determine the output shift values by which the rows are finally </span>
+<a name="l01656"></a>01656 <span class="comment">           shifted, consider the integer pixel errors and resort shift array </span>
+<a name="l01657"></a>01657 <span class="comment">           to get the row index </span>
+<a name="l01658"></a>01658 <span class="comment">         */</span>
+<a name="l01659"></a>01659         shift[row_index[slit]] = diff ;
+<a name="l01660"></a>01660     }   
+<a name="l01661"></a>01661 
+<a name="l01662"></a>01662     <span class="comment">/* now build the data cube out of the resampled image */</span>
+<a name="l01663"></a>01663     <span class="keywordflow">for</span> ( z = 0 ; z < ily ; z++ ) <span class="comment">/* go through the z-axis */</span>
+<a name="l01664"></a>01664     {
+<a name="l01665"></a>01665       o_img=cpl_image_new(imsize,N_SLITLETS,CPL_TYPE_FLOAT);
+<a name="l01666"></a>01666       podata=cpl_image_get_data_float(o_img);
+<a name="l01667"></a>01667         <span class="keywordflow">for</span> ( slit = 0 ; slit < N_SLITLETS ; slit++ )
+<a name="l01668"></a>01668         {
+<a name="l01669"></a>01669             col_counter = beginCol[slit] ;
+<a name="l01670"></a>01670             <span class="comment">/* each slitlet is centered on the final image row */</span>
+<a name="l01671"></a>01671             <span class="keywordflow">for</span> ( col = 0 ; col < imsize ; col++ )
+<a name="l01672"></a>01672             {
+<a name="l01673"></a>01673                 <span class="keywordflow">if</span> ( col_counter > ilx-1 )
+<a name="l01674"></a>01674                 {
+<a name="l01675"></a>01675                     col_counter-- ;
+<a name="l01676"></a>01676                 }
+<a name="l01677"></a>01677                 podata[col+row_index[slit]*imsize]=pidata[col_counter+z*ilx];
+<a name="l01678"></a>01678                 col_counter++ ;
+<a name="l01679"></a>01679             }
+<a name="l01680"></a>01680         } 
+<a name="l01681"></a>01681         cpl_imagelist_set(returnCube,o_img,z);   
+<a name="l01682"></a>01682     }
+<a name="l01683"></a>01683     cpl_free (row_index) ;
+<a name="l01684"></a>01684     cpl_free (beginCol) ;
+<a name="l01685"></a>01685 
+<a name="l01686"></a>01686     <span class="keywordflow">return</span> returnCube ;
+<a name="l01687"></a>01687 }
+<a name="l01688"></a>01688 
+<a name="l01706"></a>01706 cpl_imagelist * 
+<a name="l01707"></a>01707 sinfo_new_make_3D_cube ( cpl_image * calibImage,
+<a name="l01708"></a>01708                        <span class="keywordtype">int</span>      * kpixshift, 
+<a name="l01709"></a>01709                        <span class="keywordtype">int</span>        kpixfirst )
+<a name="l01710"></a>01710 {
+<a name="l01711"></a>01711     cpl_imagelist * returnCube ;
+<a name="l01712"></a>01712     <span class="keywordtype">int</span> imsize, kslit, kpix ;
+<a name="l01713"></a>01713     <span class="keywordtype">int</span> z, col, recol ;
+<a name="l01714"></a>01714     <span class="keywordtype">int</span> ilx=0;
+<a name="l01715"></a>01715     <span class="keywordtype">int</span> ily=0;
+<a name="l01716"></a>01716 
+<a name="l01717"></a>01717     <span class="keywordtype">float</span>* podata=NULL;
+<a name="l01718"></a>01718     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l01719"></a>01719     cpl_image* o_img;
+<a name="l01720"></a>01720 
+<a name="l01721"></a>01721     <span class="keywordflow">if</span> ( NULL == calibImage )
+<a name="l01722"></a>01722     {
+<a name="l01723"></a>01723         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no resampled image given!\n"</span>) ;
+<a name="l01724"></a>01724         <span class="keywordflow">return</span> NULL ;
+<a name="l01725"></a>01725     }
+<a name="l01726"></a>01726     ilx=cpl_image_get_size_x(calibImage);
+<a name="l01727"></a>01727     ily=cpl_image_get_size_y(calibImage);
+<a name="l01728"></a>01728     pidata=cpl_image_get_data_float(calibImage);
+<a name="l01729"></a>01729 
+<a name="l01730"></a>01730     <span class="keywordflow">if</span> ( NULL == kpixshift )
+<a name="l01731"></a>01731     {
+<a name="l01732"></a>01732         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no shift array given!/n"</span>) ;
+<a name="l01733"></a>01733         <span class="keywordflow">return</span> NULL ;
+<a name="l01734"></a>01734     }
+<a name="l01735"></a>01735 
+<a name="l01736"></a>01736     <span class="keywordflow">if</span> ( kpixfirst < 0 )
+<a name="l01737"></a>01737     {
+<a name="l01738"></a>01738         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"wrong first valid pixel given!/n"</span>) ;
+<a name="l01739"></a>01739         <span class="keywordflow">return</span> NULL ;
+<a name="l01740"></a>01740     }
+<a name="l01741"></a>01741 
+<a name="l01742"></a>01742     <span class="keywordflow">if</span> ( N_SLITLETS != 16 )
+<a name="l01743"></a>01743     {
+<a name="l01744"></a>01744         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"wrong number of slitlets given \n"</span> ) ;
+<a name="l01745"></a>01745         <span class="keywordflow">return</span> NULL ;
+<a name="l01746"></a>01746     }
+<a name="l01747"></a>01747     imsize = ilx / N_SLITLETS ;
+<a name="l01748"></a>01748 
+<a name="l01749"></a>01749     <span class="keywordflow">if</span> ( NULL == (returnCube = cpl_imagelist_new()) )
+<a name="l01750"></a>01750     {
+<a name="l01751"></a>01751         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"cannot allocate new cube \n"</span> ) ;
+<a name="l01752"></a>01752         <span class="keywordflow">return</span> NULL ;
+<a name="l01753"></a>01753     }
+<a name="l01754"></a>01754 
+<a name="l01755"></a>01755     <span class="comment">/* now build the data cube out of the resampled image */</span>
+<a name="l01756"></a>01756     <span class="keywordflow">for</span> ( z = 0 ; z < ily ; z++ ) <span class="comment">/* go through the z-axis */</span>
+<a name="l01757"></a>01757     {
+<a name="l01758"></a>01758       o_img=cpl_image_new(imsize,N_SLITLETS,CPL_TYPE_FLOAT);
+<a name="l01759"></a>01759       podata=cpl_image_get_data_float(o_img);
+<a name="l01760"></a>01760         kpix       = 0 ;
+<a name="l01761"></a>01761         kslit      = 0 ;
+<a name="l01762"></a>01762         recol      = -1 ;
+<a name="l01763"></a>01763         <span class="keywordflow">for</span> ( col = 0 ; col < ilx ; col++ ) <span class="comment">/* go through the image columns */</span>
+<a name="l01764"></a>01764         {
+<a name="l01765"></a>01765             <span class="keywordflow">if</span> ( col % imsize == 0 ) 
+<a name="l01766"></a>01766             {
+<a name="l01767"></a>01767                 recol = 0 ;
+<a name="l01768"></a>01768                 kslit = col/imsize ;
+<a name="l01769"></a>01769                 kpix  = kpixfirst + kpixshift[kslit] ;
+<a name="l01770"></a>01770             }
+<a name="l01771"></a>01771 
+<a name="l01772"></a>01772             <span class="comment">/* fill each cube plane with one image row */</span>
+<a name="l01773"></a>01773             podata[recol+kslit*imsize] = pidata[col+kpix+z*ilx] ;
+<a name="l01774"></a>01774             recol++ ;
+<a name="l01775"></a>01775             <span class="keywordflow">if</span> ( recol > imsize )
+<a name="l01776"></a>01776             {
+<a name="l01777"></a>01777                 <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"wrong column of reconstructed image, i"</span>
+<a name="l01778"></a>01778                                 <span class="stringliteral">"shouldn't happen!\n"</span>) ; 
+<a name="l01779"></a>01779                 cpl_imagelist_delete(returnCube) ;
+<a name="l01780"></a>01780                 <span class="keywordflow">return</span> NULL ;
+<a name="l01781"></a>01781             }
+<a name="l01782"></a>01782         }
+<a name="l01783"></a>01783         cpl_imagelist_set(returnCube,o_img,z);
+<a name="l01784"></a>01784     }
+<a name="l01785"></a>01785     <span class="keywordflow">return</span> returnCube ;
+<a name="l01786"></a>01786 }
+<a name="l01787"></a>01787 
+<a name="l01800"></a>01800 cpl_imagelist * 
+<a name="l01801"></a>01801 sinfo_new_determine_mask_cube ( cpl_imagelist * sourceMaskCube,
+<a name="l01802"></a>01802                               <span class="keywordtype">float</span>     lowLimit,
+<a name="l01803"></a>01803                               <span class="keywordtype">float</span>     highLimit )
+<a name="l01804"></a>01804 {
+<a name="l01805"></a>01805     cpl_imagelist * retCube ; 
+<a name="l01806"></a>01806     <span class="keywordtype">int</span> z, n ;
+<a name="l01807"></a>01807     <span class="keywordtype">int</span> ilx=0;
+<a name="l01808"></a>01808     <span class="keywordtype">int</span> ily=0;
+<a name="l01809"></a>01809     <span class="keywordtype">int</span> inp=0;
+<a name="l01810"></a>01810     <span class="keywordtype">int</span> olx=0;
+<a name="l01811"></a>01811     <span class="keywordtype">int</span> oly=0;
+<a name="l01812"></a>01812     <span class="keywordtype">int</span> onp=0;
+<a name="l01813"></a>01813     <span class="keywordtype">float</span>* podata=NULL;
+<a name="l01814"></a>01814     cpl_image* o_img;
+<a name="l01815"></a>01815 
+<a name="l01816"></a>01816     <span class="keywordflow">if</span> ( sourceMaskCube == NULL )
+<a name="l01817"></a>01817     {
+<a name="l01818"></a>01818         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no cube given!\n"</span>) ;
+<a name="l01819"></a>01819         <span class="keywordflow">return</span> NULL ;
+<a name="l01820"></a>01820     }
+<a name="l01821"></a>01821     ilx=cpl_image_get_size_x(cpl_imagelist_get(sourceMaskCube,0));
+<a name="l01822"></a>01822     ily=cpl_image_get_size_y(cpl_imagelist_get(sourceMaskCube,0));
+<a name="l01823"></a>01823     inp=cpl_imagelist_get_size(sourceMaskCube);
+<a name="l01824"></a>01824 
+<a name="l01825"></a>01825 
+<a name="l01826"></a>01826     <span class="keywordflow">if</span> ( lowLimit > 0. )
+<a name="l01827"></a>01827     {
+<a name="l01828"></a>01828         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"lowLimit wrong!\n"</span>) ;
+<a name="l01829"></a>01829         <span class="keywordflow">return</span> NULL ;
+<a name="l01830"></a>01830     }
+<a name="l01831"></a>01831     <span class="keywordflow">if</span> ( highLimit >= 1. || highLimit < 0. )
+<a name="l01832"></a>01832     {
+<a name="l01833"></a>01833         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"highLimit wrong!\n"</span>) ;
+<a name="l01834"></a>01834         <span class="keywordflow">return</span> NULL ;
+<a name="l01835"></a>01835     }
+<a name="l01836"></a>01836 
+<a name="l01837"></a>01837     retCube = cpl_imagelist_duplicate (sourceMaskCube) ;
+<a name="l01838"></a>01838     onp=inp;
+<a name="l01839"></a>01839     olx=ilx;
+<a name="l01840"></a>01840     oly=ily;
+<a name="l01841"></a>01841 
+<a name="l01842"></a>01842     <span class="keywordflow">for</span> ( z = 0 ; z < onp ; z++ )
+<a name="l01843"></a>01843     {
+<a name="l01844"></a>01844       o_img=cpl_imagelist_get(retCube,0);
+<a name="l01845"></a>01845       podata=cpl_image_get_data_float(o_img);
+<a name="l01846"></a>01846         <span class="keywordflow">for</span> ( n = 0 ; n < (int) olx*oly; n++ )
+<a name="l01847"></a>01847         {
+<a name="l01848"></a>01848             <span class="keywordflow">if</span> ( podata[n] == 0. )
+<a name="l01849"></a>01849             {
+<a name="l01850"></a>01850                continue ;
+<a name="l01851"></a>01851             }
+<a name="l01852"></a>01852             <span class="keywordflow">if</span> ( podata[n] == 1. )
+<a name="l01853"></a>01853             {
+<a name="l01854"></a>01854                continue ;
+<a name="l01855"></a>01855             }
+<a name="l01856"></a>01856             <span class="keywordflow">if</span> ( podata[n] >= lowLimit && 
+<a name="l01857"></a>01857                  podata[n] <= highLimit )
+<a name="l01858"></a>01858             {
+<a name="l01859"></a>01859                 podata[n] = 0. ;
+<a name="l01860"></a>01860             }
+<a name="l01861"></a>01861             <span class="keywordflow">else</span> 
+<a name="l01862"></a>01862             {
+<a name="l01863"></a>01863                 podata[n] = 1. ;
+<a name="l01864"></a>01864             }
+<a name="l01865"></a>01865         }
+<a name="l01866"></a>01866     }
+<a name="l01867"></a>01867     <span class="keywordflow">return</span> retCube ;
+<a name="l01868"></a>01868 }
+<a name="l01907"></a>01907 cpl_imagelist * 
+<a name="l01908"></a>01908 sinfo_new_interpol_cube ( cpl_imagelist * sourceCube,
+<a name="l01909"></a>01909                          cpl_imagelist * maskCube,
+<a name="l01910"></a>01910                          <span class="keywordtype">int</span>       n_neighbors, <span class="comment">/* 7 */</span>
+<a name="l01911"></a>01911                          <span class="keywordtype">int</span>       max_radius ) <span class="comment">/* 5 */</span>
+<a name="l01912"></a>01912 {
+<a name="l01913"></a>01913     cpl_imagelist  * returnCube ;
+<a name="l01914"></a>01914     <span class="keywordtype">float</span>** spec=NULL ;
+<a name="l01915"></a>01915     <span class="keywordtype">float</span>* spec1=NULL ;
+<a name="l01916"></a>01916     <span class="keywordtype">int</span> n_im, n_bad, n_bad1, n_bad2 ;
+<a name="l01917"></a>01917     <span class="keywordtype">int</span> n_planes, specn, nspec1 ;
+<a name="l01918"></a>01918     <span class="keywordtype">int</span> i, m, n, z, ni, kk, p ;
+<a name="l01919"></a>01919     <span class="keywordtype">int</span> dis, dismin, dismax ;
+<a name="l01920"></a>01920     <span class="keywordtype">int</span> agreed ;
+<a name="l01921"></a>01921     <span class="keywordtype">int</span> xcordi, ycordi, xcordm, ycordm ;
+<a name="l01922"></a>01922 
+<a name="l01923"></a>01923 
+<a name="l01924"></a>01924 
+<a name="l01925"></a>01925     <span class="keywordtype">int</span> ilx=0;
+<a name="l01926"></a>01926     <span class="keywordtype">int</span> ily=0;
+<a name="l01927"></a>01927     <span class="keywordtype">int</span> inp=0;
+<a name="l01928"></a>01928    
+<a name="l01929"></a>01929     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l01930"></a>01930     <span class="keywordtype">float</span>* pmdata=NULL;
+<a name="l01931"></a>01931     <span class="keywordtype">float</span>* podata=NULL;
+<a name="l01932"></a>01932     cpl_image* i_img=NULL;
+<a name="l01933"></a>01933     cpl_image* m_img=NULL;
+<a name="l01934"></a>01934     cpl_image* o_img=NULL;
+<a name="l01935"></a>01935 
+<a name="l01936"></a>01936     <span class="keywordflow">if</span> ( NULL == sourceCube )
+<a name="l01937"></a>01937     {
+<a name="l01938"></a>01938         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" no source cube given!\n"</span>) ;
+<a name="l01939"></a>01939         <span class="keywordflow">return</span> NULL ;
+<a name="l01940"></a>01940     }
+<a name="l01941"></a>01941 
+<a name="l01942"></a>01942 
+<a name="l01943"></a>01943     ilx=cpl_image_get_size_x(cpl_imagelist_get(sourceCube,0));
+<a name="l01944"></a>01944     ily=cpl_image_get_size_y(cpl_imagelist_get(sourceCube,0));
+<a name="l01945"></a>01945     inp=cpl_imagelist_get_size(sourceCube);
+<a name="l01946"></a>01946 
+<a name="l01947"></a>01947     <span class="keywordflow">if</span> ( NULL == maskCube )
+<a name="l01948"></a>01948     {
+<a name="l01949"></a>01949         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no bad pixel mask cube given!\n"</span>) ;
+<a name="l01950"></a>01950         <span class="keywordflow">return</span> NULL ;
+<a name="l01951"></a>01951     }
+<a name="l01952"></a>01952 
+<a name="l01953"></a>01953     <span class="keywordflow">if</span> ( n_neighbors <= 0 )
+<a name="l01954"></a>01954     {
+<a name="l01955"></a>01955         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"wrong number of neighbors in the spectral "</span>
+<a name="l01956"></a>01956                         <span class="stringliteral">"direction given!"</span>) ;
+<a name="l01957"></a>01957         <span class="keywordflow">return</span> NULL ;
+<a name="l01958"></a>01958     }
+<a name="l01959"></a>01959    
+<a name="l01960"></a>01960     <span class="keywordflow">if</span> ( max_radius <= 0 )
+<a name="l01961"></a>01961     {
+<a name="l01962"></a>01962         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"wrong maximal radius for interpolation inside "</span>
+<a name="l01963"></a>01963                         <span class="stringliteral">"an image plane given!"</span>) ;
+<a name="l01964"></a>01964         <span class="keywordflow">return</span> NULL ;
+<a name="l01965"></a>01965     }
+<a name="l01966"></a>01966 
+<a name="l01967"></a>01967     returnCube = cpl_imagelist_duplicate(sourceCube) ;
+<a name="l01968"></a>01968     
+<a name="l01969"></a>01969     n_im     = ilx * ily ;
+<a name="l01970"></a>01970     n_planes = inp ;
+<a name="l01971"></a>01971 
+<a name="l01972"></a>01972     spec1=cpl_calloc(300,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l01973"></a>01973     spec=sinfo_new_2Dfloatarray(100,2*n_neighbors+1) ;
+<a name="l01974"></a>01974 
+<a name="l01975"></a>01975     <span class="comment">/* loop over the image planes and look for bad pixels and correct them */</span>
+<a name="l01976"></a>01976     <span class="keywordflow">for</span> ( z = 0 ; z < n_planes ; z++ ) <span class="comment">/* go through image planes */</span>
+<a name="l01977"></a>01977     {
+<a name="l01978"></a>01978       m_img=cpl_imagelist_get(maskCube,z);
+<a name="l01979"></a>01979       pmdata=cpl_image_get_data_float(m_img);
+<a name="l01980"></a>01980       o_img=cpl_imagelist_get(returnCube,z);
+<a name="l01981"></a>01981       podata=cpl_image_get_data_float(o_img);
+<a name="l01982"></a>01982 
+<a name="l01983"></a>01983         <span class="comment">/*-------------------------------------------------------------------</span>
+<a name="l01984"></a>01984 <span class="comment">         * determine n, the length of one wing in one spectrum with which the </span>
+<a name="l01985"></a>01985 <span class="comment">         * bad pixel will be interpolated. The length of one wing is </span>
+<a name="l01986"></a>01986 <span class="comment">           n_neighbors but less at the edges of the cube. </span>
+<a name="l01987"></a>01987 <span class="comment">         */</span>
+<a name="l01988"></a>01988         <span class="keywordflow">if</span> ( z < n_neighbors )
+<a name="l01989"></a>01989         {
+<a name="l01990"></a>01990             n = z ;
+<a name="l01991"></a>01991         }
+<a name="l01992"></a>01992         <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( n_planes - z <= n_neighbors)
+<a name="l01993"></a>01993         {
+<a name="l01994"></a>01994             n = n_planes - z -1 ;
+<a name="l01995"></a>01995         }
+<a name="l01996"></a>01996         <span class="keywordflow">else</span>
+<a name="l01997"></a>01997         { 
+<a name="l01998"></a>01998             n = n_neighbors ;
+<a name="l01999"></a>01999         }
+<a name="l02000"></a>02000 
+<a name="l02001"></a>02001         <span class="keywordflow">for</span> ( i = 0 ; i < n_im ; i ++ ) <span class="comment">/* go through one image */</span>
+<a name="l02002"></a>02002         {
+<a name="l02003"></a>02003             <span class="comment">/* continue if the pixel is a good one */</span>
+<a name="l02004"></a>02004             <span class="keywordflow">if</span> ( pmdata[i] != 0. )
+<a name="l02005"></a>02005             {
+<a name="l02006"></a>02006                 continue ;
+<a name="l02007"></a>02007             }
+<a name="l02008"></a>02008         
+<a name="l02009"></a>02009             <span class="comment">/*-------------------------------------------------------------</span>
+<a name="l02010"></a>02010 <span class="comment">             * exclude pixels with too many bad neighbors in the spectrum.</span>
+<a name="l02011"></a>02011 <span class="comment">             * exit if: too few good pixels in the neighboring spectrum or </span>
+<a name="l02012"></a>02012 <span class="comment">             * good pixels are only on one side of the spectrum.</span>
+<a name="l02013"></a>02013 <span class="comment">             */</span>
+<a name="l02014"></a>02014             n_bad  = 0 ;
+<a name="l02015"></a>02015             n_bad1 = 0 ;
+<a name="l02016"></a>02016             n_bad2 = 0 ;
+<a name="l02017"></a>02017             <span class="comment">/* go through the neighbor spectral pixels */</span>
+<a name="l02018"></a>02018             <span class="keywordflow">for</span> ( ni = z-n ; ni <= z+n ; ni++ ) 
+<a name="l02019"></a>02019             {
+<a name="l02020"></a>02020                 <span class="keywordflow">if</span> ( pmdata[i] == 0. )
+<a name="l02021"></a>02021                 {
+<a name="l02022"></a>02022                     n_bad++ ;
+<a name="l02023"></a>02023                     <span class="comment">/* count bad pixels on either spectral side of </span>
+<a name="l02024"></a>02024 <span class="comment">                       the bad pixel to be interpolated */</span>
+<a name="l02025"></a>02025                     <span class="keywordflow">if</span> ( ni < z )
+<a name="l02026"></a>02026                     {
+<a name="l02027"></a>02027                         n_bad1++ ;
+<a name="l02028"></a>02028                     }
+<a name="l02029"></a>02029                     <span class="keywordflow">if</span> ( ni > z )
+<a name="l02030"></a>02030                     {
+<a name="l02031"></a>02031                         n_bad2++ ;
+<a name="l02032"></a>02032                     }
+<a name="l02033"></a>02033                 }
+<a name="l02034"></a>02034             }
+<a name="l02035"></a>02035          
+<a name="l02036"></a>02036             <span class="comment">/*--------------------------------------------------------------- </span>
+<a name="l02037"></a>02037 <span class="comment">             * now the criteria are checked which the neighborhood in the </span>
+<a name="l02038"></a>02038 <span class="comment">               spectral dimension has to match if the pixel is interpolatable.</span>
+<a name="l02039"></a>02039 <span class="comment">             * The total number of the good pixel in the spectrum must be more </span>
+<a name="l02040"></a>02040 <span class="comment">               than 3 and there must be at least one good pixel on either side </span>
+<a name="l02041"></a>02041 <span class="comment">               of the central pixel.</span>
+<a name="l02042"></a>02042 <span class="comment">             */</span>
+<a name="l02043"></a>02043             <span class="keywordflow">if</span> ( (2*n+1 - n_bad) < 3 || (n - n_bad1) < 1 || (n - n_bad2) < 1 )
+<a name="l02044"></a>02044             {
+<a name="l02045"></a>02045                 continue ;
+<a name="l02046"></a>02046             }
+<a name="l02047"></a>02047             
+<a name="l02048"></a>02048             <span class="comment">/* read the master spectrum into the first row of the array spec */</span>
+<a name="l02049"></a>02049             kk = 0 ;
+<a name="l02050"></a>02050             <span class="keywordflow">for</span> ( ni = z-n ; ni <= z+n ; ni++ )
+<a name="l02051"></a>02051             {
+<a name="l02052"></a>02052           i_img=cpl_imagelist_get(sourceCube,ni);
+<a name="l02053"></a>02053               pidata=cpl_image_get_data_float(i_img);
+<a name="l02054"></a>02054                 spec[1][kk] = pmdata[i] != 0. ? pidata[i] : ZERO ;
+<a name="l02055"></a>02055                 kk++ ; <span class="comment">/* length of spectrum */</span>
+<a name="l02056"></a>02056             }
+<a name="l02057"></a>02057             
+<a name="l02058"></a>02058             <span class="comment">/* look for appropriate neighbors in the x-y neighborhood */</span>
+<a name="l02059"></a>02059             agreed = 1 ; <span class="comment">/* loop guard */</span>
+<a name="l02060"></a>02060             specn  = 2 ; <span class="comment">/* number of spectra in spec. </span>
+<a name="l02061"></a>02061 <span class="comment">                            First is master spectrum */</span>
+<a name="l02062"></a>02062             dismin = 0 ; <span class="comment">/* x+y minimal distance to bad pixel */</span>
+<a name="l02063"></a>02063             dismax = 1 ; <span class="comment">/* x+y maximal distance to bad pixel */</span>
+<a name="l02064"></a>02064             <span class="keywordflow">do</span>
+<a name="l02065"></a>02065             {
+<a name="l02066"></a>02066                 <span class="keywordflow">for</span> ( m = 0 ; m < n_im ; m++ )
+<a name="l02067"></a>02067                 {
+<a name="l02068"></a>02068                     <span class="keywordflow">if</span> ( pmdata[m] == 0. )
+<a name="l02069"></a>02069                     {
+<a name="l02070"></a>02070                         continue ;
+<a name="l02071"></a>02071                     }
+<a name="l02072"></a>02072 
+<a name="l02073"></a>02073                     <span class="comment">/* --------------------------------------------------------</span>
+<a name="l02074"></a>02074 <span class="comment">                     * determine the x and y coordinates of the bad pixel (i)</span>
+<a name="l02075"></a>02075 <span class="comment">                     * and the pixels used to interpolate (m) </span>
+<a name="l02076"></a>02076 <span class="comment">                     */</span>
+<a name="l02077"></a>02077                     xcordi = i % ilx ;
+<a name="l02078"></a>02078                     xcordm = m % ilx ;
+<a name="l02079"></a>02079                     ycordi = i / ilx ;
+<a name="l02080"></a>02080                     ycordm = m / ilx ;
+<a name="l02081"></a>02081                     <span class="comment">/*----------------------------------------------------- </span>
+<a name="l02082"></a>02082 <span class="comment">                     * check the distance: take only close pixels</span>
+<a name="l02083"></a>02083 <span class="comment">                     * extension 'i' is coordinate of the bad pixel to be </span>
+<a name="l02084"></a>02084 <span class="comment">                       interpolated</span>
+<a name="l02085"></a>02085 <span class="comment">                     */</span>
+<a name="l02086"></a>02086                     dis = abs(xcordi-xcordm) + abs(ycordi-ycordm) ;
+<a name="l02087"></a>02087                     <span class="keywordflow">if</span> ( dis <= dismin || dis > dismax )
+<a name="l02088"></a>02088                     {
+<a name="l02089"></a>02089                         continue ;
+<a name="l02090"></a>02090                     }
+<a name="l02091"></a>02091                     <span class="comment">/*--------------------------------------------------------</span>
+<a name="l02092"></a>02092 <span class="comment">                     * check on number of bad pixels in the spectrum of a </span>
+<a name="l02093"></a>02093 <span class="comment">                     * neighbor pixel; reject it if it contains less than 2 </span>
+<a name="l02094"></a>02094 <span class="comment">                     * usable pixel pairs. a bit more explanation:</span>
+<a name="l02095"></a>02095 <span class="comment">                     * let this be a 15 pixel spectrum with the pixel to be </span>
+<a name="l02096"></a>02096 <span class="comment">                     * interpolated denoted by '0' and other bad pixels marked </span>
+<a name="l02097"></a>02097 <span class="comment">                     * with 'b'. Good pixels are marked with '1'. Below a </span>
+<a name="l02098"></a>02098 <span class="comment">                     * neighbor spectrum is drawn containing bad pixels as </span>
+<a name="l02099"></a>02099 <span class="comment">                     * well. The third line shows the position of the usable </span>
+<a name="l02100"></a>02100 <span class="comment">                     * pixel pairs, spectral</span>
+<a name="l02101"></a>02101 <span class="comment">                     * positions, where both spectra have valid pixels.</span>
+<a name="l02102"></a>02102 <span class="comment">                     *</span>
+<a name="l02103"></a>02103 <span class="comment">                     *   1 1 1 b b 1 1 0 b 1 b b 1 b b</span>
+<a name="l02104"></a>02104 <span class="comment">                     *   b 1 1 1 b b 1 1 1 1 1 1 b b 1</span>
+<a name="l02105"></a>02105 <span class="comment">                     *     ^ ^       ^     ^             4 good pixel pairs</span>
+<a name="l02106"></a>02106 <span class="comment">                     */</span>
+<a name="l02107"></a>02107       
+<a name="l02108"></a>02108                     n_bad = 0 ;
+<a name="l02109"></a>02109                     <span class="keywordflow">for</span> ( ni = z-n ; ni <= z+n ; ni++ )
+<a name="l02110"></a>02110                     {
+<a name="l02111"></a>02111                         <span class="keywordflow">if</span> ( pmdata[i] == 0. || pmdata[m] == 0. )
+<a name="l02112"></a>02112                         {
+<a name="l02113"></a>02113                             n_bad++ ;
+<a name="l02114"></a>02114                         }
+<a name="l02115"></a>02115                     }
+<a name="l02116"></a>02116                     <span class="keywordflow">if</span> ( n_bad > 2*n-1 ) 
+<a name="l02117"></a>02117                     <span class="comment">/* we need at least 2 usable pixel pairs */</span>
+<a name="l02118"></a>02118                     {
+<a name="l02119"></a>02119                         continue ;
+<a name="l02120"></a>02120                     }
+<a name="l02121"></a>02121                     
+<a name="l02122"></a>02122                     <span class="comment">/* transfer the spectrum to the next position </span>
+<a name="l02123"></a>02123 <span class="comment">                       of array spec */</span>
+<a name="l02124"></a>02124                     kk = 0 ;
+<a name="l02125"></a>02125                     <span class="keywordflow">for</span> ( ni = z-n ; ni <= z+n ; ni++ )
+<a name="l02126"></a>02126                     {
+<a name="l02127"></a>02127               i_img=cpl_imagelist_get(sourceCube,ni);
+<a name="l02128"></a>02128               pidata=cpl_image_get_data_float(i_img);
+<a name="l02129"></a>02129                         spec[specn][kk] = pmdata[m] != 0. ? pidata[m] : ZERO ;
+<a name="l02130"></a>02130                         kk++ ;
+<a name="l02131"></a>02131                     }
+<a name="l02132"></a>02132                     specn++ ;
+<a name="l02133"></a>02133                     <span class="keywordflow">if</span> ( specn > 10 ) <span class="comment">/* if we have 9 neighbors then break */</span>
+<a name="l02134"></a>02134                     {
+<a name="l02135"></a>02135                         agreed = 0 ;
+<a name="l02136"></a>02136                         break ;
+<a name="l02137"></a>02137                     }
+<a name="l02138"></a>02138                 }
+<a name="l02139"></a>02139                 <span class="comment">/* if no break, increase search radius and continue */</span>
+<a name="l02140"></a>02140                 dismin++ ;        
+<a name="l02141"></a>02141                 dismax++ ;
+<a name="l02142"></a>02142                 <span class="comment">/* if search radius is too big, exit with fewer </span>
+<a name="l02143"></a>02143 <span class="comment">                   good neighbors */</span>
+<a name="l02144"></a>02144                 <span class="keywordflow">if</span> ( dismax > max_radius )
+<a name="l02145"></a>02145                 {
+<a name="l02146"></a>02146                     agreed = 0 ;
+<a name="l02147"></a>02147                 }
+<a name="l02148"></a>02148             }   <span class="keywordflow">while</span>(agreed) ;    
+<a name="l02149"></a>02149                        
+<a name="l02150"></a>02150             specn-- ;
+<a name="l02151"></a>02151             dismax -= 2 ;
+<a name="l02152"></a>02152             <span class="comment">/* TODO: why compute dismax is later this is not used? */</span>
+<a name="l02153"></a>02153             <span class="comment">/* ---------------------------------------------------------------</span>
+<a name="l02154"></a>02154 <span class="comment">             * Take the master spectrum with the bad pixel in the middle and </span>
+<a name="l02155"></a>02155 <span class="comment">               divide it by each of the neighbor spectra and normalize the </span>
+<a name="l02156"></a>02156 <span class="comment">               division with the value in  the center position.</span>
+<a name="l02157"></a>02157 <span class="comment">             */</span>
+<a name="l02158"></a>02158             <span class="keywordflow">for</span> ( kk = 0 ; kk < 2*n+1 ; kk++ )
+<a name="l02159"></a>02159             {
+<a name="l02160"></a>02160                 <span class="keywordflow">if</span> ( kk == n )    <span class="comment">/* do not divide the master bad pixel */</span>
+<a name="l02161"></a>02161                 {
+<a name="l02162"></a>02162                     continue ;
+<a name="l02163"></a>02163                 }
+<a name="l02164"></a>02164 
+<a name="l02165"></a>02165                 <span class="comment">/* do not divide bad pixels in the master spectrum */</span>
+<a name="l02166"></a>02166                 <span class="keywordflow">if</span> ( isnan(spec[1][kk]) ) 
+<a name="l02167"></a>02167                 {
+<a name="l02168"></a>02168                     <span class="keywordflow">for</span> ( p = 2 ; p <= specn ; p++ )
+<a name="l02169"></a>02169                     {
+<a name="l02170"></a>02170                         spec[p][kk] = ZERO ;
+<a name="l02171"></a>02171                     }
+<a name="l02172"></a>02172                 }    
+<a name="l02173"></a>02173                 <span class="keywordflow">else</span>       <span class="comment">/* all is well, now divide */</span>
+<a name="l02174"></a>02174                 {
+<a name="l02175"></a>02175                     <span class="keywordflow">for</span> ( p = 2 ; p <= specn ; p++ )
+<a name="l02176"></a>02176                     {
+<a name="l02177"></a>02177                         <span class="keywordflow">if</span> ( !isnan(spec[p][kk]) && spec[p][kk] != 0. &&
+<a name="l02178"></a>02178                              !isnan(spec[p][n]) )
+<a name="l02179"></a>02179                         {
+<a name="l02180"></a>02180                             spec[p][kk] = spec[1][kk] / 
+<a name="l02181"></a>02181                                           spec[p][kk] * spec[p][n] ;
+<a name="l02182"></a>02182                         }
+<a name="l02183"></a>02183                         <span class="keywordflow">else</span>
+<a name="l02184"></a>02184                         {
+<a name="l02185"></a>02185                             spec[p][kk] = ZERO ;
+<a name="l02186"></a>02186                         }
+<a name="l02187"></a>02187                     }
+<a name="l02188"></a>02188                 }
+<a name="l02189"></a>02189             }
+<a name="l02190"></a>02190  
+<a name="l02191"></a>02191             <span class="comment">/*-----------------------------------------------------------------</span>
+<a name="l02192"></a>02192 <span class="comment">             * determine the sinfo_median of all values. With 9 good neighbors </span>
+<a name="l02193"></a>02193 <span class="comment">             * and at least 2 good values per neighbor we have between 18 and </span>
+<a name="l02194"></a>02194 <span class="comment">             * 9*14 values for the statistics. If there are not enough good </span>
+<a name="l02195"></a>02195 <span class="comment">             * neighbors available, only continue if we have collected at </span>
+<a name="l02196"></a>02196 <span class="comment">             * least 18 values.</span>
+<a name="l02197"></a>02197 <span class="comment">             */</span>
+<a name="l02198"></a>02198             nspec1 = 0 ;  
+<a name="l02199"></a>02199             <span class="comment">/* collect the good values in the array spec1 */</span> 
+<a name="l02200"></a>02200             <span class="keywordflow">for</span> ( p = 2 ; p <= specn ; p++ )
+<a name="l02201"></a>02201             {
+<a name="l02202"></a>02202                 <span class="keywordflow">for</span> ( kk = 0 ; kk < 2*n+1 ; kk++ )
+<a name="l02203"></a>02203                 {
+<a name="l02204"></a>02204                     <span class="keywordflow">if</span> ( !isnan(spec[p][kk]) && kk != n )
+<a name="l02205"></a>02205                     {
+<a name="l02206"></a>02206                         spec1[nspec1] = spec[p][kk] ;
+<a name="l02207"></a>02207                         nspec1++ ;
+<a name="l02208"></a>02208                     }
+<a name="l02209"></a>02209                 }
+<a name="l02210"></a>02210             }
+<a name="l02211"></a>02211             
+<a name="l02212"></a>02212             <span class="comment">/* now test if we have at least 18 values */</span>
+<a name="l02213"></a>02213             <span class="keywordflow">if</span> ( nspec1 < 18 )
+<a name="l02214"></a>02214             {
+<a name="l02215"></a>02215                 continue ;
+<a name="l02216"></a>02216             }
+<a name="l02217"></a>02217  
+<a name="l02218"></a>02218             <span class="comment">/* interpolate the bad pixel by the sinfo_median of spec1 */</span>
+<a name="l02219"></a>02219             podata[i] = sinfo_new_median(spec1, nspec1) ;
+<a name="l02220"></a>02220             pmdata[i] = 1 ;
+<a name="l02221"></a>02221         }
+<a name="l02222"></a>02222     }           
+<a name="l02223"></a>02223     sinfo_new_destroy_2Dfloatarray(&spec,2*n_neighbors+1) ;
+<a name="l02224"></a>02224     cpl_free(spec1);
+<a name="l02225"></a>02225     <span class="keywordflow">return</span> returnCube ;
+<a name="l02226"></a>02226 }
+<a name="l02247"></a>02247 cpl_imagelist * 
+<a name="l02248"></a>02248 sinfo_new_fine_tune_cube( cpl_imagelist * cube,
+<a name="l02249"></a>02249                                      <span class="keywordtype">float</span>   * correct_diff_dist,
+<a name="l02250"></a>02250                                      <span class="keywordtype">int</span>       n_order )
+<a name="l02251"></a>02251 {
+<a name="l02252"></a>02252     cpl_imagelist * returnCube ;
+<a name="l02253"></a>02253     <span class="keywordtype">float</span>* row_data=NULL ;
+<a name="l02254"></a>02254     <span class="keywordtype">float</span>* corrected_row_data=NULL ;
+<a name="l02255"></a>02255     <span class="keywordtype">float</span>* xnum=NULL ;
+<a name="l02256"></a>02256     <span class="keywordtype">float</span> sum, new_sum ;
+<a name="l02257"></a>02257     <span class="keywordtype">float</span> eval<span class="comment">/*, dy*/</span> ;
+<a name="l02258"></a>02258     <span class="keywordtype">float</span> * imageptr ;
+<a name="l02259"></a>02259     <span class="keywordtype">int</span> row, col ;
+<a name="l02260"></a>02260     <span class="keywordtype">int</span> i, z ;
+<a name="l02261"></a>02261     <span class="keywordtype">int</span> imsize, n_points ;
+<a name="l02262"></a>02262     <span class="keywordtype">int</span> firstpos ;
+<a name="l02263"></a>02263     <span class="keywordtype">int</span>  flag;
+<a name="l02264"></a>02264     <span class="keywordtype">int</span> ilx=0;
+<a name="l02265"></a>02265     <span class="keywordtype">int</span> ily=0;
+<a name="l02266"></a>02266     <span class="keywordtype">int</span> inp=0;
+<a name="l02267"></a>02267    
+<a name="l02268"></a>02268     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l02269"></a>02269     <span class="keywordtype">float</span>* podata=NULL;
+<a name="l02270"></a>02270     cpl_image* i_img=NULL;
+<a name="l02271"></a>02271     cpl_image* o_img=NULL;
+<a name="l02272"></a>02272 
+<a name="l02273"></a>02273 
+<a name="l02274"></a>02274     <span class="keywordflow">if</span> ( NULL == cube )
+<a name="l02275"></a>02275     {
+<a name="l02276"></a>02276         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no input cube given!\n"</span>) ;
+<a name="l02277"></a>02277         <span class="keywordflow">return</span> NULL ;
+<a name="l02278"></a>02278     }
+<a name="l02279"></a>02279     ilx=cpl_image_get_size_x(cpl_imagelist_get(cube,0));
+<a name="l02280"></a>02280     ily=cpl_image_get_size_y(cpl_imagelist_get(cube,0));
+<a name="l02281"></a>02281     inp=cpl_imagelist_get_size(cube);
+<a name="l02282"></a>02282 
+<a name="l02283"></a>02283     <span class="keywordflow">if</span> ( NULL == correct_diff_dist )
+<a name="l02284"></a>02284     {
+<a name="l02285"></a>02285         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no distances array from ns_test given!n"</span>) ;
+<a name="l02286"></a>02286         <span class="keywordflow">return</span> NULL ;
+<a name="l02287"></a>02287     }
+<a name="l02288"></a>02288   
+<a name="l02289"></a>02289     <span class="keywordflow">if</span> ( n_order <= 0 )
+<a name="l02290"></a>02290     {
+<a name="l02291"></a>02291         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"wrong order of interpolation polynom given!"</span>) ;
+<a name="l02292"></a>02292     returnCube = cpl_imagelist_duplicate(cube);
+<a name="l02293"></a>02293         <span class="keywordflow">return</span> returnCube ;
+<a name="l02294"></a>02294     }
+<a name="l02295"></a>02295 
+<a name="l02296"></a>02296     returnCube = cpl_imagelist_duplicate(cube);
+<a name="l02297"></a>02297     
+<a name="l02298"></a>02298     imsize = ily ;
+<a name="l02299"></a>02299     <span class="keywordflow">if</span> ( imsize != N_SLITLETS )
+<a name="l02300"></a>02300     {
+<a name="l02301"></a>02301         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"wrong image size\n"</span> ) ;
+<a name="l02302"></a>02302         <span class="keywordflow">return</span> NULL ;
+<a name="l02303"></a>02303     }
+<a name="l02304"></a>02304 
+<a name="l02305"></a>02305     n_points = n_order + 1 ;
+<a name="l02306"></a>02306     <span class="keywordflow">if</span> ( n_points % 2 == 0 )
+<a name="l02307"></a>02307     {
+<a name="l02308"></a>02308         firstpos = (int)(n_points/2) - 1 ;
+<a name="l02309"></a>02309     }
+<a name="l02310"></a>02310     <span class="keywordflow">else</span>
+<a name="l02311"></a>02311     {
+<a name="l02312"></a>02312         firstpos = (int)(n_points/2) ;
+<a name="l02313"></a>02313     }
+<a name="l02314"></a>02314     xnum=cpl_calloc(n_order+1,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l02315"></a>02315 
+<a name="l02316"></a>02316     <span class="keywordflow">for</span> ( i = 0 ; i < n_points ; i++ )
+<a name="l02317"></a>02317     {
+<a name="l02318"></a>02318         xnum[i] = i ;
+<a name="l02319"></a>02319     }    
+<a name="l02320"></a>02320 
+<a name="l02321"></a>02321     row_data=cpl_calloc(ilx,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l02322"></a>02322     corrected_row_data=cpl_calloc(ilx,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l02323"></a>02323 
+<a name="l02324"></a>02324     <span class="keywordflow">for</span> ( z = 0 ; z < inp ; z++ )
+<a name="l02325"></a>02325     {
+<a name="l02326"></a>02326       i_img=cpl_imagelist_get(cube,z);
+<a name="l02327"></a>02327       pidata=cpl_image_get_data_float(i_img);
+<a name="l02328"></a>02328       o_img=cpl_imagelist_get(returnCube,z);
+<a name="l02329"></a>02329       podata=cpl_image_get_data_float(o_img);
+<a name="l02330"></a>02330 
+<a name="l02331"></a>02331 
+<a name="l02332"></a>02332         <span class="keywordflow">for</span> ( row = 0 ; row < imsize ; row++ )
+<a name="l02333"></a>02333         {
+<a name="l02334"></a>02334             <span class="keywordflow">for</span> ( col = 0 ; col < ilx ; col++ )
+<a name="l02335"></a>02335             {
+<a name="l02336"></a>02336                 corrected_row_data[col] = 0. ;
+<a name="l02337"></a>02337             }
+<a name="l02338"></a>02338             sum = 0. ; 
+<a name="l02339"></a>02339             <span class="keywordflow">for</span> ( col = 0 ; col < ilx ; col++ )
+<a name="l02340"></a>02340             {
+<a name="l02341"></a>02341                 row_data[col] = pidata[col+row*ilx] ;
+<a name="l02342"></a>02342                 <span class="keywordflow">if</span> ( isnan(row_data[col]) )
+<a name="l02343"></a>02343                 {
+<a name="l02344"></a>02344                     row_data[col] = 0. ;
+<a name="l02345"></a>02345                     <span class="keywordflow">for</span> ( i = col - firstpos ; 
+<a name="l02346"></a>02346                           i < col -firstpos+n_points ; i++ )
+<a name="l02347"></a>02347                     {
+<a name="l02348"></a>02348                         <span class="keywordflow">if</span> ( i < 0 ) continue ;
+<a name="l02349"></a>02349                         <span class="keywordflow">if</span> ( i >= ilx) continue ; 
+<a name="l02350"></a>02350                         corrected_row_data[i] = ZERO ;
+<a name="l02351"></a>02351                     }
+<a name="l02352"></a>02352                 }
+<a name="l02353"></a>02353                 <span class="keywordflow">if</span> ( col != 0 && col != ilx - 1 )
+<a name="l02354"></a>02354                 {
+<a name="l02355"></a>02355                     sum += row_data[col] ;
+<a name="l02356"></a>02356                 }
+<a name="l02357"></a>02357             }
+<a name="l02358"></a>02358 
+<a name="l02359"></a>02359            
+<a name="l02360"></a>02360             new_sum = 0. ;
+<a name="l02361"></a>02361             <span class="keywordflow">for</span> ( col = 0 ; col < ilx ; col++ )
+<a name="l02362"></a>02362             {
+<a name="l02363"></a>02363                 
+<a name="l02364"></a>02364                 <span class="keywordflow">if</span> ( isnan(corrected_row_data[col]) )
+<a name="l02365"></a>02365                 {
+<a name="l02366"></a>02366                     continue ;
+<a name="l02367"></a>02367                 }
+<a name="l02368"></a>02368                 <span class="keywordflow">if</span> ( col - firstpos < 0 )
+<a name="l02369"></a>02369                 {
+<a name="l02370"></a>02370                     imageptr = &row_data[0] ;
+<a name="l02371"></a>02371                     eval     = correct_diff_dist[row] + col ;
+<a name="l02372"></a>02372                 }
+<a name="l02373"></a>02373                 <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( col - firstpos + n_points >= ilx )
+<a name="l02374"></a>02374                 {
+<a name="l02375"></a>02375                     imageptr = &row_data[ilx - n_points] ;
+<a name="l02376"></a>02376                     eval     = correct_diff_dist[row] + col + n_points - ilx ;
+<a name="l02377"></a>02377                 }
+<a name="l02378"></a>02378                 <span class="keywordflow">else</span>
+<a name="l02379"></a>02379                 {
+<a name="l02380"></a>02380                     imageptr = &row_data[col-firstpos] ;
+<a name="l02381"></a>02381                     eval     = correct_diff_dist[row] + firstpos ;
+<a name="l02382"></a>02382                 }
+<a name="l02383"></a>02383 
+<a name="l02384"></a>02384         
+<a name="l02385"></a>02385         flag = 0;
+<a name="l02386"></a>02386         corrected_row_data[col]=sinfo_new_nev_ille(xnum, imageptr, 
+<a name="l02387"></a>02387                                                        n_order, eval, &flag);
+<a name="l02388"></a>02388 
+<a name="l02389"></a>02389                
+<a name="l02390"></a>02390                 <span class="keywordflow">if</span> ( col != 0 && col != ilx - 1 )
+<a name="l02391"></a>02391                 {
+<a name="l02392"></a>02392                     new_sum += corrected_row_data[col] ;
+<a name="l02393"></a>02393                 }
+<a name="l02394"></a>02394             }
+<a name="l02395"></a>02395             <span class="keywordflow">for</span> ( col = 0 ; col < ilx ; col++ )
+<a name="l02396"></a>02396             {
+<a name="l02397"></a>02397                 
+<a name="l02398"></a>02398                 <span class="keywordflow">if</span> ( col == 0 )
+<a name="l02399"></a>02399                 {
+<a name="l02400"></a>02400                     podata[col+row*ilx] = ZERO ;
+<a name="l02401"></a>02401                 }
+<a name="l02402"></a>02402                 <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( col == ilx - 1 )
+<a name="l02403"></a>02403                 {
+<a name="l02404"></a>02404                     podata[col+row*ilx] = ZERO ;
+<a name="l02405"></a>02405                 }
+<a name="l02406"></a>02406                 <span class="keywordflow">else</span>
+<a name="l02407"></a>02407                 {
+<a name="l02408"></a>02408                     <span class="keywordflow">if</span> ( isnan(corrected_row_data[col]) ) 
+<a name="l02409"></a>02409                     {
+<a name="l02410"></a>02410                         podata[col+row*ilx] = ZERO ;
+<a name="l02411"></a>02411                     }
+<a name="l02412"></a>02412                     <span class="keywordflow">else</span>
+<a name="l02413"></a>02413                     {
+<a name="l02414"></a>02414                         <span class="keywordflow">if</span> ( new_sum == 0. ) new_sum = 1. ;
+<a name="l02415"></a>02415                      
+<a name="l02416"></a>02416                         podata[col+row*ilx] = corrected_row_data[col] ;
+<a name="l02417"></a>02417                     }
+<a name="l02418"></a>02418                 }
+<a name="l02419"></a>02419             }
+<a name="l02420"></a>02420         }
+<a name="l02421"></a>02421     }       
+<a name="l02422"></a>02422 
+<a name="l02423"></a>02423     cpl_free(xnum) ;
+<a name="l02424"></a>02424     cpl_free(row_data) ;
+<a name="l02425"></a>02425     cpl_free(corrected_row_data) ;
+<a name="l02426"></a>02426 
+<a name="l02427"></a>02427     <span class="keywordflow">return</span> returnCube ;
+<a name="l02428"></a>02428 }
+<a name="l02429"></a>02429 
+<a name="l02449"></a>02449 cpl_imagelist * 
+<a name="l02450"></a>02450 sinfo_new_fine_tune_cube_by_FFT( cpl_imagelist * cube,
+<a name="l02451"></a>02451                                            <span class="keywordtype">float</span>   * correct_diff_dist )
+<a name="l02452"></a>02452 {
+<a name="l02453"></a>02453     cpl_imagelist * returnCube ;
+<a name="l02454"></a>02454 
+<a name="l02455"></a>02455     <span class="keywordtype">float</span>* row_data=NULL ;
+<a name="l02456"></a>02456     dcomplex* data=NULL ;
+<a name="l02457"></a>02457     dcomplex* corrected_data=NULL ;
+<a name="l02458"></a>02458 
+<a name="l02459"></a>02459     <span class="keywordtype">unsigned</span> nn[2];
+<a name="l02460"></a>02460     <span class="comment">/*float corrected_row_data[cube->lx] ;*/</span>
+<a name="l02461"></a>02461     <span class="keywordtype">float</span> phi, pphi ;
+<a name="l02462"></a>02462     <span class="keywordtype">float</span> coph, siph ;
+<a name="l02463"></a>02463     <span class="keywordtype">int</span> row, col ;
+<a name="l02464"></a>02464     <span class="keywordtype">int</span> i, z ;
+<a name="l02465"></a>02465     <span class="keywordtype">int</span> imsize ;
+<a name="l02466"></a>02466     <span class="keywordtype">int</span> blank_indicator ;
+<a name="l02467"></a>02467 
+<a name="l02468"></a>02468 
+<a name="l02469"></a>02469     <span class="keywordtype">int</span> ilx=0;
+<a name="l02470"></a>02470     <span class="keywordtype">int</span> ily=0;
+<a name="l02471"></a>02471     <span class="keywordtype">int</span> inp=0;
+<a name="l02472"></a>02472    
+<a name="l02473"></a>02473     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l02474"></a>02474     <span class="keywordtype">float</span>* podata=NULL;
+<a name="l02475"></a>02475     cpl_image* i_img=NULL;
+<a name="l02476"></a>02476     cpl_image* o_img=NULL;
+<a name="l02477"></a>02477 
+<a name="l02478"></a>02478 
+<a name="l02479"></a>02479 
+<a name="l02480"></a>02480     <span class="keywordflow">if</span> ( NULL == cube )
+<a name="l02481"></a>02481     {
+<a name="l02482"></a>02482         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" no input cube given!\n"</span>) ;
+<a name="l02483"></a>02483         <span class="keywordflow">return</span> NULL ;
+<a name="l02484"></a>02484     }
+<a name="l02485"></a>02485     ilx=cpl_image_get_size_x(cpl_imagelist_get(cube,0));
+<a name="l02486"></a>02486     ily=cpl_image_get_size_y(cpl_imagelist_get(cube,0));
+<a name="l02487"></a>02487     inp=cpl_imagelist_get_size(cube);
+<a name="l02488"></a>02488 
+<a name="l02489"></a>02489     nn[1] = ilx ;
+<a name="l02490"></a>02490     <span class="keywordflow">if</span> ( NULL == correct_diff_dist )
+<a name="l02491"></a>02491     {
+<a name="l02492"></a>02492         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no distances array from ns_test given!"</span>) ;
+<a name="l02493"></a>02493         <span class="keywordflow">return</span> NULL ;
+<a name="l02494"></a>02494     }
+<a name="l02495"></a>02495 
+<a name="l02496"></a>02496     returnCube = cpl_imagelist_duplicate( cube ) ;
+<a name="l02497"></a>02497 
+<a name="l02498"></a>02498     imsize = ily ;
+<a name="l02499"></a>02499     <span class="keywordflow">if</span> ( imsize != N_SLITLETS )
+<a name="l02500"></a>02500     {
+<a name="l02501"></a>02501         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"wrong image size\n"</span> ) ;
+<a name="l02502"></a>02502         <span class="keywordflow">return</span> NULL ;
+<a name="l02503"></a>02503     }
+<a name="l02504"></a>02504 
+<a name="l02505"></a>02505     data=cpl_calloc(ilx,<span class="keyword">sizeof</span>(dcomplex)) ;
+<a name="l02506"></a>02506     corrected_data=cpl_calloc(ilx,<span class="keyword">sizeof</span>(dcomplex)) ;
+<a name="l02507"></a>02507 
+<a name="l02508"></a>02508     row_data=cpl_calloc(ilx,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l02509"></a>02509     <span class="comment">/* loop over the image planes */</span>
+<a name="l02510"></a>02510     <span class="keywordflow">for</span> ( z = 0 ; z < inp ; z++ )
+<a name="l02511"></a>02511     {
+<a name="l02512"></a>02512       i_img=cpl_imagelist_get(cube,z);
+<a name="l02513"></a>02513       pidata=cpl_image_get_data_float(i_img);
+<a name="l02514"></a>02514       o_img=cpl_imagelist_get(returnCube,z);
+<a name="l02515"></a>02515       podata=cpl_image_get_data_float(o_img);
+<a name="l02516"></a>02516         <span class="comment">/* consider one row at a time */</span>
+<a name="l02517"></a>02517         <span class="keywordflow">for</span> ( row = 0 ; row < imsize ; row++ )
+<a name="l02518"></a>02518         {
+<a name="l02519"></a>02519             blank_indicator = 1 ;
+<a name="l02520"></a>02520             <span class="keywordflow">for</span> ( col = 0 ; col < ilx ; col++ )
+<a name="l02521"></a>02521             {
+<a name="l02522"></a>02522                 <span class="comment">/* transfer the row data to a double sized array */</span>
+<a name="l02523"></a>02523                 row_data[col] = pidata[col+row*ilx] ;
+<a name="l02524"></a>02524         data[col].x = row_data[col] ;
+<a name="l02525"></a>02525         data[col].y = 0. ;
+<a name="l02526"></a>02526                 <span class="comment">/* if row contains a blank pixel proceed */</span>
+<a name="l02527"></a>02527                 <span class="keywordflow">if</span> ( isnan(row_data[col]) )
+<a name="l02528"></a>02528                 {
+<a name="l02529"></a>02529                     blank_indicator = 0 ; 
+<a name="l02530"></a>02530                 }
+<a name="l02531"></a>02531             }
+<a name="l02532"></a>02532 
+<a name="l02533"></a>02533             <span class="comment">/* if row contains a blank don't apply FFT but proceed */</span>
+<a name="l02534"></a>02534             <span class="keywordflow">if</span> ( blank_indicator == 0 )
+<a name="l02535"></a>02535             {
+<a name="l02536"></a>02536                 <span class="keywordflow">for</span> ( col = 0 ; col < ilx ; col++ )
+<a name="l02537"></a>02537                 {
+<a name="l02538"></a>02538                     podata[col+row*ilx] = ZERO ;
+<a name="l02539"></a>02539                 }
+<a name="l02540"></a>02540                 continue ;
+<a name="l02541"></a>02541             }
+<a name="l02542"></a>02542            
+<a name="l02543"></a>02543             <span class="comment">/* FFT algorithm of eclipse */</span>
+<a name="l02544"></a>02544             sinfo_fftn( data, nn, 1, 1 ) ;
+<a name="l02545"></a>02545  
+<a name="l02546"></a>02546             <span class="comment">/* calculate the corrected phase shift for each frequency */</span>
+<a name="l02547"></a>02547             phi = 2*PI_NUMB/(float)ilx * correct_diff_dist[row] ;
+<a name="l02548"></a>02548             <span class="keywordflow">for</span> ( i = 0 ; i < ilx ; i++ )
+<a name="l02549"></a>02549             {
+<a name="l02550"></a>02550                 <span class="comment">/* positive frequencies */</span>
+<a name="l02551"></a>02551                 <span class="keywordflow">if</span> ( i <= ilx/2 )
+<a name="l02552"></a>02552                 {
+<a name="l02553"></a>02553                     <span class="comment">/* phase shift */</span>
+<a name="l02554"></a>02554                     pphi = phi * (float)(i) ;
+<a name="l02555"></a>02555                     <span class="comment">/* Euler factor */</span>
+<a name="l02556"></a>02556                     coph = cos ( pphi ) ;
+<a name="l02557"></a>02557                     siph = sin ( pphi ) ;
+<a name="l02558"></a>02558                 }
+<a name="l02559"></a>02559                 <span class="keywordflow">else</span> <span class="comment">/* negative frequencies */</span>
+<a name="l02560"></a>02560                 {
+<a name="l02561"></a>02561                     <span class="comment">/* phase shift */</span>
+<a name="l02562"></a>02562                     pphi = phi * (float)(i - ilx/2) ;
+<a name="l02563"></a>02563                     <span class="comment">/* Euler factor */</span>
+<a name="l02564"></a>02564                     coph = cos ( pphi ) ;
+<a name="l02565"></a>02565                     siph = sin ( pphi ) ;
+<a name="l02566"></a>02566                 }
+<a name="l02567"></a>02567 
+<a name="l02568"></a>02568                 <span class="comment">/* ------------------------------------------------------------</span>
+<a name="l02569"></a>02569 <span class="comment">                 * now calculate the shift in the pixel space by multiplying</span>
+<a name="l02570"></a>02570 <span class="comment">                 * the fourier transform by the Euler factor of the phase shift</span>
+<a name="l02571"></a>02571 <span class="comment">                 * and inverse fourier transforming.</span>
+<a name="l02572"></a>02572 <span class="comment">                 * used Fourier pair: h(x-x0) <==> H(k)*exp(2*pi*i*k*x0) </span>
+<a name="l02573"></a>02573 <span class="comment">                 */</span>
+<a name="l02574"></a>02574                 <span class="comment">/* calculate real part */</span>
+<a name="l02575"></a>02575                 corrected_data[i].x   = data[i].x * coph - data[i].y * siph ; 
+<a name="l02576"></a>02576                 <span class="comment">/* calculate imaginary part */</span>
+<a name="l02577"></a>02577                 corrected_data[i].y = data[i].x * siph + data[i].y * coph ;
+<a name="l02578"></a>02578             }
+<a name="l02579"></a>02579  
+<a name="l02580"></a>02580             <span class="comment">/* transform back: inverse FFT */</span>
+<a name="l02581"></a>02581             sinfo_fftn( corrected_data, nn, 1, -1 ) ;
+<a name="l02582"></a>02582 
+<a name="l02583"></a>02583             <span class="comment">/* normalize */</span> 
+<a name="l02584"></a>02584             <span class="keywordflow">for</span> ( i = 0 ; i < ilx ; i++ )
+<a name="l02585"></a>02585             {
+<a name="l02586"></a>02586                 corrected_data[i].x /= ilx ;
+<a name="l02587"></a>02587         corrected_data[i].y /= ilx ;
+<a name="l02588"></a>02588             } 
+<a name="l02589"></a>02589 
+<a name="l02590"></a>02590             <span class="comment">/* now transfer row to output, leave the left-most </span>
+<a name="l02591"></a>02591 <span class="comment">               and right-most pixel column */</span>
+<a name="l02592"></a>02592             <span class="keywordflow">for</span> ( col = 0 ; col < ilx ; col++ )
+<a name="l02593"></a>02593             {
+<a name="l02594"></a>02594                 <span class="keywordflow">if</span> ( col == 0 )
+<a name="l02595"></a>02595                 {
+<a name="l02596"></a>02596                     podata[col+row*ilx] = ZERO ;
+<a name="l02597"></a>02597                 }
+<a name="l02598"></a>02598                 <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( col == ilx - 1 )
+<a name="l02599"></a>02599                 {
+<a name="l02600"></a>02600                     podata[col+row*ilx] = ZERO ;
+<a name="l02601"></a>02601                 }
+<a name="l02602"></a>02602                 <span class="keywordflow">else</span>
+<a name="l02603"></a>02603                 {
+<a name="l02604"></a>02604                     podata[col+row*ilx] = corrected_data[col].x ; 
+<a name="l02605"></a>02605                 }
+<a name="l02606"></a>02606             }
+<a name="l02607"></a>02607         }
+<a name="l02608"></a>02608     }
+<a name="l02609"></a>02609 
+<a name="l02610"></a>02610     cpl_free(data) ;
+<a name="l02611"></a>02611     cpl_free(corrected_data) ;
+<a name="l02612"></a>02612 
+<a name="l02613"></a>02613 
+<a name="l02614"></a>02614     cpl_free(row_data);
+<a name="l02615"></a>02615     <span class="keywordflow">return</span> returnCube ;
+<a name="l02616"></a>02616 }
+<a name="l02644"></a>02644 cpl_imagelist * sinfo_new_fine_tune_cube_by_spline ( cpl_imagelist * cube,
+<a name="l02645"></a>02645                                                <span class="keywordtype">float</span>   * correct_diff_dist )
+<a name="l02646"></a>02646 {
+<a name="l02647"></a>02647     cpl_imagelist * returnCube ;
+<a name="l02648"></a>02648 
+<a name="l02649"></a>02649     <span class="keywordtype">float</span>* row_data=NULL ;
+<a name="l02650"></a>02650     <span class="keywordtype">float</span>* corrected_row_data=NULL ;
+<a name="l02651"></a>02651     <span class="keywordtype">float</span>* xnum=NULL ;
+<a name="l02652"></a>02652     <span class="keywordtype">float</span>* eval=NULL ;
+<a name="l02653"></a>02653 
+<a name="l02654"></a>02654     <span class="keywordtype">float</span> sum, new_sum ;
+<a name="l02655"></a>02655     <span class="keywordtype">int</span> row, col ;
+<a name="l02656"></a>02656     <span class="keywordtype">int</span> i, z ;
+<a name="l02657"></a>02657     <span class="keywordtype">int</span> imsize ;
+<a name="l02658"></a>02658     <span class="keywordtype">int</span> ilx=0;
+<a name="l02659"></a>02659     <span class="keywordtype">int</span> ily=0;
+<a name="l02660"></a>02660     <span class="keywordtype">int</span> inp=0;
+<a name="l02661"></a>02661    
+<a name="l02662"></a>02662     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l02663"></a>02663     <span class="keywordtype">float</span>* podata=NULL;
+<a name="l02664"></a>02664     cpl_image* i_img=NULL;
+<a name="l02665"></a>02665     cpl_image* o_img=NULL;
+<a name="l02666"></a>02666 
+<a name="l02667"></a>02667  
+<a name="l02668"></a>02668     <span class="keywordflow">if</span> ( NULL == cube )
+<a name="l02669"></a>02669     {
+<a name="l02670"></a>02670         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no input cube given!\n"</span>) ;
+<a name="l02671"></a>02671         <span class="keywordflow">return</span> NULL ;
+<a name="l02672"></a>02672     }
+<a name="l02673"></a>02673     ilx=cpl_image_get_size_x(cpl_imagelist_get(cube,0));
+<a name="l02674"></a>02674     ily=cpl_image_get_size_y(cpl_imagelist_get(cube,0));
+<a name="l02675"></a>02675     inp=cpl_imagelist_get_size(cube);
+<a name="l02676"></a>02676 
+<a name="l02677"></a>02677     <span class="keywordflow">if</span> ( NULL == correct_diff_dist )
+<a name="l02678"></a>02678     {
+<a name="l02679"></a>02679         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no distances array from ns_test given!/n"</span>) ;
+<a name="l02680"></a>02680         <span class="keywordflow">return</span> NULL ;
+<a name="l02681"></a>02681     }
+<a name="l02682"></a>02682   
+<a name="l02683"></a>02683     imsize = ily ;
+<a name="l02684"></a>02684     <span class="keywordflow">if</span> ( imsize != N_SLITLETS )
+<a name="l02685"></a>02685     {
+<a name="l02686"></a>02686         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"wrong image size\n"</span> ) ;
+<a name="l02687"></a>02687         <span class="keywordflow">return</span> NULL ;
+<a name="l02688"></a>02688     }
+<a name="l02689"></a>02689   
+<a name="l02690"></a>02690     returnCube = cpl_imagelist_duplicate( cube ) ;
+<a name="l02691"></a>02691 
+<a name="l02692"></a>02692     row_data=cpl_calloc(ilx,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l02693"></a>02693     corrected_row_data=cpl_calloc(ilx,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l02694"></a>02694     xnum=cpl_calloc(ilx,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l02695"></a>02695     eval=cpl_calloc(ilx,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l02696"></a>02696   
+<a name="l02697"></a>02697     <span class="comment">/* fill the xa[] array for a polynomial interpolation */</span>
+<a name="l02698"></a>02698     <span class="keywordflow">for</span> ( i = 0 ; i < ilx ; i++ )
+<a name="l02699"></a>02699     {
+<a name="l02700"></a>02700         xnum[i] = i ;
+<a name="l02701"></a>02701     }    
+<a name="l02702"></a>02702 
+<a name="l02703"></a>02703     <span class="comment">/* loop over the image planes */</span>
+<a name="l02704"></a>02704     <span class="keywordflow">for</span> ( z = 0 ; z < inp ; z++ )
+<a name="l02705"></a>02705     {
+<a name="l02706"></a>02706       i_img=cpl_imagelist_get(cube,z);
+<a name="l02707"></a>02707       pidata=cpl_image_get_data_float(i_img);
+<a name="l02708"></a>02708       o_img=cpl_imagelist_get(returnCube,z);
+<a name="l02709"></a>02709       podata=cpl_image_get_data_float(o_img);
+<a name="l02710"></a>02710         <span class="comment">/* consider 1 row at a time */</span>
+<a name="l02711"></a>02711         <span class="keywordflow">for</span> ( row = 0 ; row < imsize ; row++ )
+<a name="l02712"></a>02712         {
+<a name="l02713"></a>02713             <span class="keywordflow">for</span> ( col = 0 ; col < ilx ; col++ )
+<a name="l02714"></a>02714             {
+<a name="l02715"></a>02715                 corrected_row_data[col] = 0. ;
+<a name="l02716"></a>02716             }
+<a name="l02717"></a>02717         sum = 0. ; <span class="comment">/* initialize flux for later rescaling */</span>
+<a name="l02718"></a>02718             <span class="comment">/* go through the columns and compute the flux for each </span>
+<a name="l02719"></a>02719 <span class="comment">               row (leave the sinfo_edge points) */</span>
+<a name="l02720"></a>02720             <span class="keywordflow">for</span> ( col = 0 ; col < ilx ; col++ )
+<a name="l02721"></a>02721             {   
+<a name="l02722"></a>02722             eval[col] = correct_diff_dist[row] + (float)col ;
+<a name="l02723"></a>02723                 row_data[col] = pidata[col+row*ilx] ;
+<a name="l02724"></a>02724                 <span class="keywordflow">if</span> (col != 0 && col != ilx - 1 && !isnan(row_data[col]) )
+<a name="l02725"></a>02725                 {
+<a name="l02726"></a>02726                     sum += row_data[col] ;
+<a name="l02727"></a>02727                 }
+<a name="l02728"></a>02728                 <span class="keywordflow">if</span> (isnan(row_data[col]) )
+<a name="l02729"></a>02729                 {
+<a name="l02730"></a>02730                     <span class="keywordflow">for</span> ( i = col -1 ; i <= col+1 ; i++ ) 
+<a name="l02731"></a>02731                     {
+<a name="l02732"></a>02732                         <span class="keywordflow">if</span> ( i < 0 ) continue ;
+<a name="l02733"></a>02733                         <span class="keywordflow">if</span> ( i >= ilx ) continue ;
+<a name="l02734"></a>02734                         corrected_row_data[i] = ZERO ; 
+<a name="l02735"></a>02735                     }
+<a name="l02736"></a>02736                     row_data[col] = 0. ;
+<a name="l02737"></a>02737                 }
+<a name="l02738"></a>02738         }
+<a name="l02739"></a>02739 
+<a name="l02740"></a>02740 
+<a name="l02741"></a>02741             <span class="comment">/* ---------------------------------------------------------------</span>
+<a name="l02742"></a>02742 <span class="comment">             * now we do the cubic spline interpolation to achieve the </span>
+<a name="l02743"></a>02743 <span class="comment">               fractional (see eclipse).</span>
+<a name="l02744"></a>02744 <span class="comment">             */</span>
+<a name="l02745"></a>02745             <span class="keywordflow">if</span> ( -1 == sinfo_function1d_natural_spline(xnum,row_data, ilx, 
+<a name="l02746"></a>02746                                                        eval,corrected_row_data,
+<a name="l02747"></a>02747                                                        ilx ) )
+<a name="l02748"></a>02748         {
+<a name="l02749"></a>02749             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"error in spline interpolation\n"</span>) ;
+<a name="l02750"></a>02750         cpl_imagelist_delete(returnCube) ;
+<a name="l02751"></a>02751         <span class="keywordflow">return</span> NULL ;
+<a name="l02752"></a>02752         }    
+<a name="l02753"></a>02753 
+<a name="l02754"></a>02754             new_sum = 0. ;
+<a name="l02755"></a>02755             <span class="keywordflow">for</span> ( col = 0 ; col < ilx ; col++ )
+<a name="l02756"></a>02756             {
+<a name="l02757"></a>02757                 <span class="keywordflow">if</span> (isnan(corrected_row_data[col])) continue ;
+<a name="l02758"></a>02758                 <span class="comment">/* don't take the sinfo_edge points to calculate </span>
+<a name="l02759"></a>02759 <span class="comment">                   the scaling factor */</span>
+<a name="l02760"></a>02760                 <span class="keywordflow">if</span> ( col != 0 && col != ilx - 1 )
+<a name="l02761"></a>02761                 {
+<a name="l02762"></a>02762                     new_sum += corrected_row_data[col] ;
+<a name="l02763"></a>02763                 }
+<a name="l02764"></a>02764             }
+<a name="l02765"></a>02765             <span class="keywordflow">for</span> ( col = 0 ; col < ilx ; col++ )
+<a name="l02766"></a>02766             {
+<a name="l02767"></a>02767                 <span class="comment">/* ----------------------------------------------------------</span>
+<a name="l02768"></a>02768 <span class="comment">                 * rescale the row data and fill the returned cube, </span>
+<a name="l02769"></a>02769 <span class="comment">                 * leave the left-most and right-most</span>
+<a name="l02770"></a>02770 <span class="comment">                 * pixel column </span>
+<a name="l02771"></a>02771 <span class="comment">                 */</span>
+<a name="l02772"></a>02772                 <span class="keywordflow">if</span> ( col == 0 )
+<a name="l02773"></a>02773                 {
+<a name="l02774"></a>02774                     podata[col+row*ilx] = ZERO ;
+<a name="l02775"></a>02775                 }
+<a name="l02776"></a>02776                 <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( col == ilx - 1 )
+<a name="l02777"></a>02777                 {
+<a name="l02778"></a>02778                     podata[col+row*ilx] = ZERO ;
+<a name="l02779"></a>02779                 }
+<a name="l02780"></a>02780                 <span class="keywordflow">else</span>
+<a name="l02781"></a>02781                 {
+<a name="l02782"></a>02782                     <span class="keywordflow">if</span> ( isnan(corrected_row_data[col]) ) 
+<a name="l02783"></a>02783                     {
+<a name="l02784"></a>02784                         podata[col+row*ilx] = ZERO ;
+<a name="l02785"></a>02785                     }
+<a name="l02786"></a>02786                     <span class="keywordflow">else</span>
+<a name="l02787"></a>02787                     {
+<a name="l02788"></a>02788                         <span class="keywordflow">if</span> (new_sum == 0.) new_sum = 1. ;
+<a name="l02789"></a>02789                      <span class="comment">/* rescaling is commented out because it delivers </span>
+<a name="l02790"></a>02790 <span class="comment">                        wrong results</span>
+<a name="l02791"></a>02791 <span class="comment">                        in case of appearance of blanks or bad pixels */</span>
+<a name="l02792"></a>02792                   <span class="comment">/*       corrected_row_data[col] *= sum / new_sum ; */</span>
+<a name="l02793"></a>02793                         podata[col+row*ilx] = corrected_row_data[col] ;
+<a name="l02794"></a>02794                     }
+<a name="l02795"></a>02795                 }
+<a name="l02796"></a>02796             }
+<a name="l02797"></a>02797         }
+<a name="l02798"></a>02798     }       
+<a name="l02799"></a>02799 
+<a name="l02800"></a>02800     cpl_free(row_data) ;
+<a name="l02801"></a>02801     cpl_free(corrected_row_data) ;
+<a name="l02802"></a>02802     cpl_free(xnum) ;
+<a name="l02803"></a>02803     cpl_free(eval) ;
+<a name="l02804"></a>02804 
+<a name="l02805"></a>02805     <span class="keywordflow">return</span> returnCube ;
+<a name="l02806"></a>02806 }
+<a name="l02807"></a>02807 
+<a name="l02829"></a>02829 <span class="keywordtype">float</span> * 
+<a name="l02830"></a>02830 sinfo_new_calibrate_ns_test( cpl_image * ns_image,
+<a name="l02831"></a>02831                            <span class="keywordtype">int</span>        n_slitlets,
+<a name="l02832"></a>02832                            <span class="keywordtype">int</span>        halfWidth,
+<a name="l02833"></a>02833                            <span class="keywordtype">float</span>      fwhm,
+<a name="l02834"></a>02834                            <span class="keywordtype">float</span>      minDiff,
+<a name="l02835"></a>02835                            <span class="keywordtype">float</span>      estimated_dist,
+<a name="l02836"></a>02836                            <span class="keywordtype">float</span>      devtol,
+<a name="l02837"></a>02837                <span class="keywordtype">int</span>        bottom,
+<a name="l02838"></a>02838                <span class="keywordtype">int</span>        top )
+<a name="l02839"></a>02839 {
+<a name="l02840"></a>02840     <span class="keywordtype">int</span> i, j, k, m, row, col, n, ni, na ;
+<a name="l02841"></a>02841     <span class="keywordtype">int</span> position, counter, iters ;
+<a name="l02842"></a>02842     <span class="keywordtype">int</span> xdim, ndat, its, numpar ;
+<a name="l02843"></a>02843     <span class="keywordtype">float</span> sum, mean, maxval ;
+<a name="l02844"></a>02844     <span class="keywordtype">float</span> tol, lab ;
+<a name="l02845"></a>02845     <span class="keywordtype">float</span> * distances ;
+<a name="l02846"></a>02846     <span class="keywordtype">float</span> * ret_distances ;
+<a name="l02847"></a>02847 
+<a name="l02848"></a>02848     <span class="keywordtype">float</span> * xdat, * wdat ;
+<a name="l02849"></a>02849     <span class="keywordtype">int</span> * mpar ;
+<a name="l02850"></a>02850 
+<a name="l02851"></a>02851     pixelvalue* row_buf=NULL ;
+<a name="l02852"></a>02852     <span class="keywordtype">float</span>** distances_buf=NULL ;
+<a name="l02853"></a>02853     <span class="keywordtype">float</span>* x_position=NULL ;
+<a name="l02854"></a>02854     <span class="keywordtype">int</span>* found=NULL;
+<a name="l02855"></a>02855     <span class="keywordtype">int</span>* found_clean=NULL ;
+<a name="l02856"></a>02856     <span class="keywordtype">int</span>* found_cleanit=NULL ;
+<a name="l02857"></a>02857 
+<a name="l02858"></a>02858     Vector * line ;
+<a name="l02859"></a>02859     FitParams ** par ;
+<a name="l02860"></a>02860     <span class="keywordtype">int</span> foundit, begin, end ;
+<a name="l02861"></a>02861     <span class="keywordtype">int</span> zeroindicator ;
+<a name="l02862"></a>02862     <span class="keywordtype">int</span> row_index ;
+<a name="l02863"></a>02863 
+<a name="l02864"></a>02864     <span class="keywordtype">int</span> ilx=0;
+<a name="l02865"></a>02865     <span class="keywordtype">int</span> ily=0;
+<a name="l02866"></a>02866     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l02867"></a>02867 
+<a name="l02868"></a>02868     <span class="keywordflow">if</span> ( ns_image == NULL )
+<a name="l02869"></a>02869     {
+<a name="l02870"></a>02870         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"sorry, no image given\n"</span>) ;
+<a name="l02871"></a>02871         <span class="keywordflow">return</span> NULL ;
+<a name="l02872"></a>02872     }
+<a name="l02873"></a>02873     <span class="keywordflow">if</span> ( n_slitlets < 1 )
+<a name="l02874"></a>02874     {
+<a name="l02875"></a>02875         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"wrong number of slitlets given\n"</span>) ;
+<a name="l02876"></a>02876         <span class="keywordflow">return</span> NULL ;
+<a name="l02877"></a>02877     }
+<a name="l02878"></a>02878     <span class="keywordflow">if</span> ( halfWidth < 0 || halfWidth >= estimated_dist )
+<a name="l02879"></a>02879     {
+<a name="l02880"></a>02880         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"wrong half width given\n"</span>) ;
+<a name="l02881"></a>02881         <span class="keywordflow">return</span> NULL ;
+<a name="l02882"></a>02882     }
+<a name="l02883"></a>02883     <span class="keywordflow">if</span> ( fwhm <= 0. )
+<a name="l02884"></a>02884     {
+<a name="l02885"></a>02885         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"wrong fwhm given\n"</span>) ;
+<a name="l02886"></a>02886         <span class="keywordflow">return</span> NULL ;
+<a name="l02887"></a>02887     }
+<a name="l02888"></a>02888     <span class="keywordflow">if</span> ( minDiff < 1. )
+<a name="l02889"></a>02889     {
+<a name="l02890"></a>02890         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"wrong minDiff given\n"</span>) ;
+<a name="l02891"></a>02891         <span class="keywordflow">return</span> NULL ;
+<a name="l02892"></a>02892     }
+<a name="l02893"></a>02893 
+<a name="l02894"></a>02894     <span class="comment">/* allocate memory for output array */</span>
+<a name="l02895"></a>02895     <span class="keywordflow">if</span> (NULL==(distances=(<span class="keywordtype">float</span> *)cpl_calloc( n_slitlets , <span class="keyword">sizeof</span> (<span class="keywordtype">float</span>) ))) 
+<a name="l02896"></a>02896     {
+<a name="l02897"></a>02897         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"could not allocate memory\n"</span>) ;
+<a name="l02898"></a>02898         <span class="keywordflow">return</span> NULL ;
+<a name="l02899"></a>02899     }
+<a name="l02900"></a>02900     <span class="comment">/* allocate memory for output array */</span>
+<a name="l02901"></a>02901     <span class="keywordflow">if</span> (NULL == (ret_distances = (<span class="keywordtype">float</span> *) cpl_calloc ( n_slitlets , 
+<a name="l02902"></a>02902                                            <span class="keyword">sizeof</span> (<span class="keywordtype">float</span>) ))) 
+<a name="l02903"></a>02903     {
+<a name="l02904"></a>02904         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"could not allocate memory\n"</span>) ;
+<a name="l02905"></a>02905         <span class="keywordflow">return</span> NULL ;
+<a name="l02906"></a>02906     }
+<a name="l02907"></a>02907 
+<a name="l02908"></a>02908     ilx=cpl_image_get_size_x(ns_image);
+<a name="l02909"></a>02909     ily=cpl_image_get_size_y(ns_image);
+<a name="l02910"></a>02910     pidata=cpl_image_get_data_float(ns_image);
+<a name="l02911"></a>02911 
+<a name="l02912"></a>02912     row_buf=(pixelvalue*)cpl_calloc(ilx,<span class="keyword">sizeof</span>(pixelvalue)) ;
+<a name="l02913"></a>02913     x_position=cpl_calloc(n_slitlets,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l02914"></a>02914     found=cpl_calloc(3*n_slitlets,<span class="keyword">sizeof</span>(<span class="keywordtype">int</span>));
+<a name="l02915"></a>02915     found_clean=cpl_calloc(3*n_slitlets,<span class="keyword">sizeof</span>(<span class="keywordtype">int</span>)) ;
+<a name="l02916"></a>02916     found_cleanit=cpl_calloc(3*n_slitlets,<span class="keyword">sizeof</span>(<span class="keywordtype">int</span>)) ;
+<a name="l02917"></a>02917     distances_buf=sinfo_new_2Dfloatarray(ily,n_slitlets) ;
+<a name="l02918"></a>02918 
+<a name="l02919"></a>02919     <span class="comment">/* go through the image rows */</span>
+<a name="l02920"></a>02920     <span class="keywordflow">for</span> ( row = 0 ; row < ily ; row++ )
+<a name="l02921"></a>02921     {
+<a name="l02922"></a>02922         zeroindicator = 0 ;
+<a name="l02923"></a>02923 
+<a name="l02924"></a>02924         <span class="comment">/* initialize the distance buffer */</span>
+<a name="l02925"></a>02925         <span class="keywordflow">for</span> ( i = 0 ; i < n_slitlets ; i++ )
+<a name="l02926"></a>02926         {
+<a name="l02927"></a>02927             distances_buf[row][i] = ZERO ;
+<a name="l02928"></a>02928         }
+<a name="l02929"></a>02929 
+<a name="l02930"></a>02930         <span class="comment">/* fill the row buffer array with image data */</span>
+<a name="l02931"></a>02931         <span class="keywordflow">for</span> ( col = 0 ; col < ilx ; col++ )
+<a name="l02932"></a>02932         {
+<a name="l02933"></a>02933             row_buf[col] = pidata[col + row*ilx] ;
+<a name="l02934"></a>02934         }
+<a name="l02935"></a>02935 
+<a name="l02936"></a>02936         <span class="comment">/* determine the mean of the row data */</span>
+<a name="l02937"></a>02937         sum = 0. ;
+<a name="l02938"></a>02938         n = 0 ;
+<a name="l02939"></a>02939         <span class="keywordflow">for</span> ( i = 0 ; i < ilx ; i++ )
+<a name="l02940"></a>02940         {
+<a name="l02941"></a>02941             <span class="keywordflow">if</span> ( isnan(row_buf[i]) )
+<a name="l02942"></a>02942             {
+<a name="l02943"></a>02943                 continue ;
+<a name="l02944"></a>02944             }
+<a name="l02945"></a>02945             sum += row_buf[i] ;
+<a name="l02946"></a>02946             n++ ;
+<a name="l02947"></a>02947         }
+<a name="l02948"></a>02948         mean = sum / (float)n ;
+<a name="l02949"></a>02949 
+<a name="l02950"></a>02950         <span class="comment">/* store the positions of image values greater than the mean */</span>
+<a name="l02951"></a>02951         n = 0 ;
+<a name="l02952"></a>02952         <span class="keywordflow">for</span> ( i = 0 ; i < ilx ; i++ )
+<a name="l02953"></a>02953         {
+<a name="l02954"></a>02954             <span class="keywordflow">if</span> (isnan(row_buf[i]))
+<a name="l02955"></a>02955             {
+<a name="l02956"></a>02956                 continue ;
+<a name="l02957"></a>02957             }
+<a name="l02958"></a>02958             <span class="keywordflow">if</span> ( row_buf[i] > mean + ESTIMATE )
+<a name="l02959"></a>02959             {
+<a name="l02960"></a>02960                 found[n] = i ;
+<a name="l02961"></a>02961                 n++ ;
+<a name="l02962"></a>02962             }
+<a name="l02963"></a>02963         }
+<a name="l02964"></a>02964        
+<a name="l02965"></a>02965         <span class="keywordflow">if</span> ( n < n_slitlets )
+<a name="l02966"></a>02966         {
+<a name="l02967"></a>02967             <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"t4 wrong number of intensity columns "</span>
+<a name="l02968"></a>02968                               <span class="stringliteral">"found in row: %d, found number: %d"</span>, row, n) ;
+<a name="l02969"></a>02969             continue ;
+<a name="l02970"></a>02970         }
+<a name="l02971"></a>02971         <span class="keywordflow">else</span>
+<a name="l02972"></a>02972         { 
+<a name="l02973"></a>02973             <span class="comment">/* find the maximum value position around the found columns */</span>
+<a name="l02974"></a>02974             na = 0 ;
+<a name="l02975"></a>02975             <span class="keywordflow">for</span> ( i = 1 ; i < n ; i ++ )
+<a name="l02976"></a>02976             {
+<a name="l02977"></a>02977                 <span class="keywordflow">if</span> ( found[i] - found[i-1] < halfWidth )
+<a name="l02978"></a>02978                 {
+<a name="l02979"></a>02979                     begin = found[i] - halfWidth ;
+<a name="l02980"></a>02980                     <span class="keywordflow">if</span> ( begin < 0 )
+<a name="l02981"></a>02981                     {
+<a name="l02982"></a>02982                         begin = 0 ;
+<a name="l02983"></a>02983                     }
+<a name="l02984"></a>02984                     end = found[i] + halfWidth ;
+<a name="l02985"></a>02985                     <span class="keywordflow">if</span> ( end >= ilx )
+<a name="l02986"></a>02986                     {
+<a name="l02987"></a>02987                         end = ilx - 1 ;
+<a name="l02988"></a>02988                     }
+<a name="l02989"></a>02989                     <span class="comment">/* find the maximum value inside the box around </span>
+<a name="l02990"></a>02990 <span class="comment">                       the found positions*/</span>
+<a name="l02991"></a>02991                     maxval = -FLT_MAX ;
+<a name="l02992"></a>02992                     foundit = 0 ;
+<a name="l02993"></a>02993                     <span class="keywordflow">for</span> ( j = begin ; j <= end ; j++ )
+<a name="l02994"></a>02994                     {
+<a name="l02995"></a>02995                         <span class="comment">/* do not consider boxes that contain bad pixels */</span>
+<a name="l02996"></a>02996                         <span class="keywordflow">if</span> (isnan(row_buf[j]))
+<a name="l02997"></a>02997                         {
+<a name="l02998"></a>02998                             continue ;
+<a name="l02999"></a>02999                         }
+<a name="l03000"></a>03000                         <span class="keywordflow">if</span> (row_buf[j] >= maxval )
+<a name="l03001"></a>03001                         {
+<a name="l03002"></a>03002                             maxval = row_buf[j] ;
+<a name="l03003"></a>03003                             foundit = j ;
+<a name="l03004"></a>03004                         }
+<a name="l03005"></a>03005                     }
+<a name="l03006"></a>03006                     <span class="keywordflow">if</span> (maxval == -FLT_MAX)
+<a name="l03007"></a>03007                     {
+<a name="l03008"></a>03008                         continue ;
+<a name="l03009"></a>03009                     }
+<a name="l03010"></a>03010                     <span class="keywordflow">for</span> ( k = 0 ; k < na ; k++ )
+<a name="l03011"></a>03011                     {
+<a name="l03012"></a>03012                         <span class="keywordflow">if</span> ( found_cleanit[k] >= begin && 
+<a name="l03013"></a>03013                              found_cleanit[k] < foundit )
+<a name="l03014"></a>03014                         {
+<a name="l03015"></a>03015                             na-- ;
+<a name="l03016"></a>03016                         }
+<a name="l03017"></a>03017                     }
+<a name="l03018"></a>03018                     <span class="keywordflow">for</span> ( k = 0 ; k < n ; k++ )
+<a name="l03019"></a>03019                     {
+<a name="l03020"></a>03020                         <span class="keywordflow">if</span> ( found[k] == foundit)
+<a name="l03021"></a>03021                         {
+<a name="l03022"></a>03022                             <span class="keywordflow">if</span> ( found_cleanit[na-1] != found[k] )
+<a name="l03023"></a>03023                             {
+<a name="l03024"></a>03024                                 found_cleanit[na] = found[k] ;
+<a name="l03025"></a>03025                                 na++ ;
+<a name="l03026"></a>03026                             }
+<a name="l03027"></a>03027                         }
+<a name="l03028"></a>03028                     }
+<a name="l03029"></a>03029                 }
+<a name="l03030"></a>03030                 <span class="keywordflow">else</span>
+<a name="l03031"></a>03031                 {
+<a name="l03032"></a>03032                     <span class="keywordflow">if</span> ( i == 1 )
+<a name="l03033"></a>03033                     {
+<a name="l03034"></a>03034                         found_cleanit[na] = found[0] ;
+<a name="l03035"></a>03035                         na++ ;
+<a name="l03036"></a>03036                         found_cleanit[na] = found[1] ;
+<a name="l03037"></a>03037                         na++ ;
+<a name="l03038"></a>03038                     }
+<a name="l03039"></a>03039                     <span class="keywordflow">else</span>
+<a name="l03040"></a>03040                     {
+<a name="l03041"></a>03041                         <span class="keywordflow">if</span> ( found_cleanit[na-1] != found[i-1])
+<a name="l03042"></a>03042                         {
+<a name="l03043"></a>03043                             found_cleanit[na] = found[i-1] ;
+<a name="l03044"></a>03044                             na++ ;
+<a name="l03045"></a>03045                         }
+<a name="l03046"></a>03046                         <span class="keywordflow">if</span> ( found_cleanit[na-1] != found[i])
+<a name="l03047"></a>03047                         {
+<a name="l03048"></a>03048                             found_cleanit[na] = found[i] ;
+<a name="l03049"></a>03049                             na++ ;
+<a name="l03050"></a>03050                         }
+<a name="l03051"></a>03051                     }
+<a name="l03052"></a>03052                 }
+<a name="l03053"></a>03053             }
+<a name="l03054"></a>03054 
+<a name="l03055"></a>03055             <span class="comment">/* determine only one pixel position for each slitlet intensity */</span>
+<a name="l03056"></a>03056             j = 1 ;
+<a name="l03057"></a>03057             <span class="keywordflow">for</span> ( i = 1 ; i < na ; i++ )
+<a name="l03058"></a>03058             {
+<a name="l03059"></a>03059                 <span class="keywordflow">if</span> ( (<span class="keywordtype">float</span>)(found_cleanit[i] - found_cleanit[i-1]) < 
+<a name="l03060"></a>03060                              (estimated_dist - devtol) ||
+<a name="l03061"></a>03061                      (<span class="keywordtype">float</span>)(found_cleanit[i] - found_cleanit[i-1]) > 
+<a name="l03062"></a>03062                              (estimated_dist + devtol) )
+<a name="l03063"></a>03063                 {
+<a name="l03064"></a>03064                     continue ;
+<a name="l03065"></a>03065                 }
+<a name="l03066"></a>03066                 <span class="keywordflow">else</span>
+<a name="l03067"></a>03067                 {
+<a name="l03068"></a>03068                     found_clean[j-1] = found_cleanit[i-1] ;
+<a name="l03069"></a>03069                     found_clean[j]   = found_cleanit[i] ;
+<a name="l03070"></a>03070                     j++ ;
+<a name="l03071"></a>03071                 }
+<a name="l03072"></a>03072             }
+<a name="l03073"></a>03073         }
+<a name="l03074"></a>03074         <span class="keywordflow">if</span> ( j > n_slitlets )
+<a name="l03075"></a>03075         {
+<a name="l03076"></a>03076             <span class="comment">/* check the distance again */</span>
+<a name="l03077"></a>03077             ni = 1 ;
+<a name="l03078"></a>03078             <span class="keywordflow">for</span> ( i = 1 ; i < j ; i++ )
+<a name="l03079"></a>03079             {
+<a name="l03080"></a>03080                 <span class="keywordflow">if</span> ( (<span class="keywordtype">float</span>)(found_clean[i] - found_clean[i-1]) < 
+<a name="l03081"></a>03081                             (estimated_dist - devtol ) ||
+<a name="l03082"></a>03082                      (<span class="keywordtype">float</span>)(found_clean[i] - found_clean[i-1]) > 
+<a name="l03083"></a>03083                             (estimated_dist + devtol ) )
+<a name="l03084"></a>03084                 { 
+<a name="l03085"></a>03085                     continue ;
+<a name="l03086"></a>03086                 }
+<a name="l03087"></a>03087                 <span class="keywordflow">else</span>
+<a name="l03088"></a>03088                 {
+<a name="l03089"></a>03089                     found_clean[ni-1] = found_clean[i-1] ;
+<a name="l03090"></a>03090                     found_clean[ni]   = found_clean[i] ;
+<a name="l03091"></a>03091                     ni++ ;
+<a name="l03092"></a>03092                 }
+<a name="l03093"></a>03093             }
+<a name="l03094"></a>03094             <span class="keywordflow">if</span> ( ni != n_slitlets )
+<a name="l03095"></a>03095             {
+<a name="l03096"></a>03096                 <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"t5 wrong number of intensity columns "</span>
+<a name="l03097"></a>03097                                   <span class="stringliteral">"found in row: %d, found number: %d"</span>,
+<a name="l03098"></a>03098                                   row,ni) ;
+<a name="l03099"></a>03099                 continue ;
+<a name="l03100"></a>03100             }
+<a name="l03101"></a>03101             <span class="keywordflow">else</span> 
+<a name="l03102"></a>03102             {
+<a name="l03103"></a>03103                 j = ni ;
+<a name="l03104"></a>03104             }
+<a name="l03105"></a>03105         }
+<a name="l03106"></a>03106         <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( j < n_slitlets )
+<a name="l03107"></a>03107         {
+<a name="l03108"></a>03108             <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"t6 wrong number of intensity columns found "</span>
+<a name="l03109"></a>03109                               <span class="stringliteral">"in row: %d , found number: %d\n"</span>, row, j) ;
+<a name="l03110"></a>03110             continue ;
+<a name="l03111"></a>03111         }
+<a name="l03112"></a>03112         counter = 0 ;
+<a name="l03113"></a>03113         <span class="comment">/* go through the found intensity pixels in one row */</span>
+<a name="l03114"></a>03114         <span class="keywordflow">for</span> ( i = 0 ; i < j ; i++ )
+<a name="l03115"></a>03115         {
+<a name="l03116"></a>03116             <span class="comment">/* allocate memory for the array where the line is fitted in */</span>
+<a name="l03117"></a>03117             <span class="keywordflow">if</span> ( NULL == (line = sinfo_new_vector (2*halfWidth + 1)) )
+<a name="l03118"></a>03118             {
+<a name="l03119"></a>03119                 <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"cannot allocate new Vector \n"</span>) ;
+<a name="l03120"></a>03120                 cpl_free(distances) ;
+<a name="l03121"></a>03121                 <span class="keywordflow">return</span> NULL ;
+<a name="l03122"></a>03122             }
+<a name="l03123"></a>03123 
+<a name="l03124"></a>03124             <span class="comment">/* allocate memory */</span>
+<a name="l03125"></a>03125             xdat = (<span class="keywordtype">float</span> *) cpl_calloc( line -> n_elements, <span class="keyword">sizeof</span> (<span class="keywordtype">float</span>) ) ;
+<a name="l03126"></a>03126             wdat = (<span class="keywordtype">float</span> *) cpl_calloc( line -> n_elements, <span class="keyword">sizeof</span> (<span class="keywordtype">float</span>) ) ;
+<a name="l03127"></a>03127             mpar = (<span class="keywordtype">int</span> *)   cpl_calloc( MAXPAR, <span class="keyword">sizeof</span> (<span class="keywordtype">int</span>) ) ;
+<a name="l03128"></a>03128             par = sinfo_new_fit_params(1) ;
+<a name="l03129"></a>03129 
+<a name="l03130"></a>03130             m = 0 ;
+<a name="l03131"></a>03131             <span class="keywordflow">for</span> ( k = found_clean[i]-halfWidth ; 
+<a name="l03132"></a>03132                   k <= found_clean[i]+halfWidth ; k++ )
+<a name="l03133"></a>03133             {
+<a name="l03134"></a>03134                 <span class="keywordflow">if</span> ( k < 0 )
+<a name="l03135"></a>03135                 {
+<a name="l03136"></a>03136                     k = 0. ;
+<a name="l03137"></a>03137                 }
+<a name="l03138"></a>03138                 <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( k >= ilx )
+<a name="l03139"></a>03139                 {
+<a name="l03140"></a>03140                     k = ilx - 1 ;
+<a name="l03141"></a>03141                 }
+<a name="l03142"></a>03142                 <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( isnan(row_buf[k]) )
+<a name="l03143"></a>03143                 {
+<a name="l03144"></a>03144                     zeroindicator = 1 ;
+<a name="l03145"></a>03145                     break ;
+<a name="l03146"></a>03146                 }
+<a name="l03147"></a>03147                 <span class="keywordflow">else</span>
+<a name="l03148"></a>03148                 {
+<a name="l03149"></a>03149                     line -> data[m] = row_buf[k] ;
+<a name="l03150"></a>03150                     m++ ;
+<a name="l03151"></a>03151                 }
+<a name="l03152"></a>03152             }
+<a name="l03153"></a>03153             <span class="keywordflow">if</span> ( zeroindicator == 1 )
+<a name="l03154"></a>03154             {
+<a name="l03155"></a>03155                 sinfo_new_destroy_vector(line) ;
+<a name="l03156"></a>03156                 cpl_free(xdat) ;
+<a name="l03157"></a>03157                 cpl_free(wdat) ;
+<a name="l03158"></a>03158                 cpl_free(mpar) ;
+<a name="l03159"></a>03159                 sinfo_new_destroy_fit_params(&par) ;
+<a name="l03160"></a>03160                 break ;
+<a name="l03161"></a>03161             }
+<a name="l03162"></a>03162 
+<a name="l03163"></a>03163             <span class="comment">/*-----------------------------------------------------------------</span>
+<a name="l03164"></a>03164 <span class="comment">             * go through the spectral sinfo_vector</span>
+<a name="l03165"></a>03165 <span class="comment">             * determine the maximum pixel value in the spectral sinfo_vector</span>
+<a name="l03166"></a>03166 <span class="comment">             */</span>
+<a name="l03167"></a>03167             maxval = -FLT_MAX ;
+<a name="l03168"></a>03168             position = -INT32_MAX ;
+<a name="l03169"></a>03169             <span class="keywordflow">for</span> ( k = 0 ; k < m ; k++ )
+<a name="l03170"></a>03170             {
+<a name="l03171"></a>03171                 xdat[k] = k ;
+<a name="l03172"></a>03172                 wdat[k] = 1.0 ;
+<a name="l03173"></a>03173                 <span class="keywordflow">if</span> ( line -> data[k] >= maxval )
+<a name="l03174"></a>03174                 {
+<a name="l03175"></a>03175                     maxval = line -> data[k] ;
+<a name="l03176"></a>03176                     position = k ;
+<a name="l03177"></a>03177                 }
+<a name="l03178"></a>03178             }
+<a name="l03179"></a>03179 
+<a name="l03180"></a>03180             <span class="comment">/* set initial values for the fitting routine */</span>
+<a name="l03181"></a>03181             xdim     = XDIM ;
+<a name="l03182"></a>03182             ndat     = line -> n_elements ;
+<a name="l03183"></a>03183             numpar   = MAXPAR ;
+<a name="l03184"></a>03184             tol      = TOL ;
+<a name="l03185"></a>03185             lab      = LAB ;
+<a name="l03186"></a>03186             its      = ITS ;
+<a name="l03187"></a>03187             (*par) -> fit_par[1] = fwhm ;
+<a name="l03188"></a>03188             (*par) -> fit_par[2] = (float) position ;
+<a name="l03189"></a>03189             (*par) -> fit_par[3] = (float) (line -> data[0] + 
+<a name="l03190"></a>03190                                     line -> data[line->n_elements - 1]) / 2.0 ;
+<a name="l03191"></a>03191             (*par) -> fit_par[0]  = maxval - ((*par) -> fit_par[3]) ;
+<a name="l03192"></a>03192 
+<a name="l03193"></a>03193 
+<a name="l03194"></a>03194             <span class="comment">/* exclude negative peaks and low signal cases */</span>
+<a name="l03195"></a>03195             <span class="keywordflow">if</span> ( (*par) -> fit_par[0] < minDiff )
+<a name="l03196"></a>03196             {
+<a name="l03197"></a>03197                 <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a> (<span class="stringliteral">"sorry, signal of line too low to fit "</span>
+<a name="l03198"></a>03198                                    <span class="stringliteral">"in row: %d in slitlet %d\n"</span>, row, i) ;
+<a name="l03199"></a>03199                 sinfo_new_destroy_vector(line) ;
+<a name="l03200"></a>03200                 cpl_free(xdat) ;
+<a name="l03201"></a>03201                 cpl_free(wdat) ;
+<a name="l03202"></a>03202                 cpl_free(mpar) ;
+<a name="l03203"></a>03203                 sinfo_new_destroy_fit_params(&par) ;
+<a name="l03204"></a>03204                 continue ;
+<a name="l03205"></a>03205             }
+<a name="l03206"></a>03206 
+<a name="l03207"></a>03207             <span class="keywordflow">for</span> ( k = 0 ; k < MAXPAR ; k++ )
+<a name="l03208"></a>03208             {
+<a name="l03209"></a>03209                 (*par) -> derv_par[k] = 0.0 ;
+<a name="l03210"></a>03210                 mpar[k] = 1 ;
+<a name="l03211"></a>03211             }
+<a name="l03212"></a>03212             <span class="comment">/* finally, do the least square fit using a sinfo_gaussian */</span>
+<a name="l03213"></a>03213             <span class="keywordflow">if</span> ( 0 > ( iters = sinfo_new_lsqfit_c(xdat, &xdim, 
+<a name="l03214"></a>03214                                                   line -> data, wdat, 
+<a name="l03215"></a>03215                                                   &ndat, (*par) -> fit_par,
+<a name="l03216"></a>03216                                                   (*par) -> derv_par, mpar, 
+<a name="l03217"></a>03217                                                   &numpar, &tol, 
+<a name="l03218"></a>03218                                                   &its, &lab )) )
+<a name="l03219"></a>03219             {
+<a name="l03220"></a>03220           <span class="comment">/*</span>
+<a name="l03221"></a>03221 <span class="comment">               cpl_msg_debug ("sinfo_calibrate_ns_test:",</span>
+<a name="l03222"></a>03222 <span class="comment">                              "sinfo_lsqfit_c: least squares fit failed,"</span>
+<a name="l03223"></a>03223 <span class="comment">                              " error no.: %d in row: %d in slitlet %d\n", </span>
+<a name="l03224"></a>03224 <span class="comment">                              iters, row, i) ;</span>
+<a name="l03225"></a>03225 <span class="comment">          */</span>
+<a name="l03226"></a>03226                 sinfo_new_destroy_vector(line) ;
+<a name="l03227"></a>03227                 cpl_free(xdat) ;
+<a name="l03228"></a>03228                 cpl_free(wdat) ;
+<a name="l03229"></a>03229                 cpl_free(mpar) ;
+<a name="l03230"></a>03230                 sinfo_new_destroy_fit_params(&par) ;
+<a name="l03231"></a>03231                 continue ;
+<a name="l03232"></a>03232             }
+<a name="l03233"></a>03233 
+<a name="l03234"></a>03234             <span class="comment">/* check for negative fit results */</span>
+<a name="l03235"></a>03235             <span class="keywordflow">if</span> ( (*par) -> fit_par[0] <= 0. || (*par) -> fit_par[1] <= 0. ||
+<a name="l03236"></a>03236                  (*par) -> fit_par[2] < 0. )
+<a name="l03237"></a>03237             {
+<a name="l03238"></a>03238                 <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a> (<span class="stringliteral">"negative parameters as fit result, not "</span>
+<a name="l03239"></a>03239                                    <span class="stringliteral">"used! in row %d in slitlet %d"</span>, row, i) ;
+<a name="l03240"></a>03240                 sinfo_new_destroy_vector(line) ;
+<a name="l03241"></a>03241                 cpl_free(xdat) ;
+<a name="l03242"></a>03242                 cpl_free(wdat) ;
+<a name="l03243"></a>03243                 cpl_free(mpar) ;
+<a name="l03244"></a>03244                 sinfo_new_destroy_fit_params(&par) ;
+<a name="l03245"></a>03245                 continue ;
+<a name="l03246"></a>03246             }
+<a name="l03247"></a>03247 
+<a name="l03248"></a>03248             <span class="comment">/* correct the fitted position for the given row of the line </span>
+<a name="l03249"></a>03249 <span class="comment">               in image coordinates */</span>
+<a name="l03250"></a>03250             (*par) -> fit_par[2] =  (float) (found_clean[i] - halfWidth) + 
+<a name="l03251"></a>03251                                     (*par) -> fit_par[2] ;
+<a name="l03252"></a>03252             x_position[counter] = (*par) -> fit_par[2] ;
+<a name="l03253"></a>03253             counter ++ ;
+<a name="l03254"></a>03254 
+<a name="l03255"></a>03255             <span class="comment">/* free memory */</span>
+<a name="l03256"></a>03256             sinfo_new_destroy_fit_params(&par) ;
+<a name="l03257"></a>03257             sinfo_new_destroy_vector ( line ) ;
+<a name="l03258"></a>03258             cpl_free ( xdat ) ;
+<a name="l03259"></a>03259             cpl_free ( wdat ) ;
+<a name="l03260"></a>03260             cpl_free ( mpar ) ;
+<a name="l03261"></a>03261         }
+<a name="l03262"></a>03262         <span class="keywordflow">if</span> (zeroindicator == 1)
+<a name="l03263"></a>03263         {
+<a name="l03264"></a>03264             <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a> (<span class="stringliteral">"bad pixel in fitting box in row: %d\n"</span>, row) ;
+<a name="l03265"></a>03265             continue ;
+<a name="l03266"></a>03266         }
+<a name="l03267"></a>03267 
+<a name="l03268"></a>03268         <span class="keywordflow">if</span> ( counter != n_slitlets )
+<a name="l03269"></a>03269         {
+<a name="l03270"></a>03270             <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"wrong number of slitlets found "</span>
+<a name="l03271"></a>03271                               <span class="stringliteral">"in row: %d"</span>, row) ;
+<a name="l03272"></a>03272             continue ;
+<a name="l03273"></a>03273         }
+<a name="l03274"></a>03274         <span class="comment">/* store the distances between the sources and the slitlet centers */</span>
+<a name="l03275"></a>03275         <span class="keywordflow">for</span> ( i = 0 ; i < n_slitlets ; i++ )
+<a name="l03276"></a>03276         {
+<a name="l03277"></a>03277             distances_buf[row][i] = x_position[i] - (15.5 + 32.*(float)i) ;
+<a name="l03278"></a>03278         }
+<a name="l03279"></a>03279     }
+<a name="l03280"></a>03280 
+<a name="l03281"></a>03281     <span class="comment">/* ----------------------------------------------------------------</span>
+<a name="l03282"></a>03282 <span class="comment">     * go through the rows again and take the mean of the distances, </span>
+<a name="l03283"></a>03283 <span class="comment">     * throw away the runaways </span>
+<a name="l03284"></a>03284 <span class="comment">     */</span>
+<a name="l03285"></a>03285     <span class="keywordflow">for</span> ( i = 0 ; i < n_slitlets ; i++ )
+<a name="l03286"></a>03286     {
+<a name="l03287"></a>03287         n   = 0 ;
+<a name="l03288"></a>03288         sum = 0. ;
+<a name="l03289"></a>03289         <span class="keywordflow">for</span> ( row = bottom ; row < top ; row++ )
+<a name="l03290"></a>03290         {
+<a name="l03291"></a>03291             <span class="keywordflow">if</span> ( fabs( distances_buf[row][i] ) > devtol || 
+<a name="l03292"></a>03292                  isnan(distances_buf[row][i]) )
+<a name="l03293"></a>03293             {
+<a name="l03294"></a>03294              <span class="comment">/*</span>
+<a name="l03295"></a>03295 <span class="comment">          sinfo_msg("dist=%g devtol=%g isan=%d", </span>
+<a name="l03296"></a>03296 <span class="comment">            distances_buf[row][i],</span>
+<a name="l03297"></a>03297 <span class="comment">            devtol,</span>
+<a name="l03298"></a>03298 <span class="comment">            isnan(distances_buf[row][i]));</span>
+<a name="l03299"></a>03299 <span class="comment">              */</span>              
+<a name="l03300"></a>03300                 continue ;
+<a name="l03301"></a>03301             }
+<a name="l03302"></a>03302             sum += distances_buf[row][i] ;
+<a name="l03303"></a>03303             n++ ;
+<a name="l03304"></a>03304         }
+<a name="l03305"></a>03305         <span class="keywordflow">if</span> ( n < 2 )
+<a name="l03306"></a>03306         {
+<a name="l03307"></a>03307             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"distances array could not be determined"</span>
+<a name="l03308"></a>03308                             <span class="stringliteral">" completely!, deviations of distances from"</span>
+<a name="l03309"></a>03309                             <span class="stringliteral">" devtol too big"</span> ) ;
+<a name="l03310"></a>03310             cpl_free(distances) ;
+<a name="l03311"></a>03311             <span class="keywordflow">return</span> NULL ;
+<a name="l03312"></a>03312         }
+<a name="l03313"></a>03313         <span class="keywordflow">else</span>
+<a name="l03314"></a>03314         {
+<a name="l03315"></a>03315             distances[i] = sum / (float)n ;
+<a name="l03316"></a>03316         }
+<a name="l03317"></a>03317     }
+<a name="l03318"></a>03318 
+<a name="l03319"></a>03319     <span class="comment">/* now sort the result according to the row sequence in the </span>
+<a name="l03320"></a>03320 <span class="comment">       reconstructed image*/</span>
+<a name="l03321"></a>03321     <span class="keywordflow">for</span> ( i = 0 ; i < n_slitlets ; i++ )
+<a name="l03322"></a>03322     {
+<a name="l03323"></a>03323       <span class="keywordflow">if</span>( (row_index=sinfo_sort_slitlets(i)) == -1) {
+<a name="l03324"></a>03324     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"wrong number of a slitlet\n"</span>) ;
+<a name="l03325"></a>03325     cpl_free (distances) ;
+<a name="l03326"></a>03326     <span class="keywordflow">return</span> NULL ;
+<a name="l03327"></a>03327       }
+<a name="l03328"></a>03328       ret_distances[row_index] = distances[i] ;
+<a name="l03329"></a>03329     }
+<a name="l03330"></a>03330     cpl_free(distances) ;
+<a name="l03331"></a>03331 
+<a name="l03332"></a>03332     cpl_free(row_buf) ;
+<a name="l03333"></a>03333     cpl_free(x_position) ;
+<a name="l03334"></a>03334     cpl_free(found);
+<a name="l03335"></a>03335     cpl_free(found_clean) ;
+<a name="l03336"></a>03336     cpl_free(found_cleanit) ;
+<a name="l03337"></a>03337     sinfo_new_destroy_2Dfloatarray(&distances_buf,n_slitlets) ;
+<a name="l03338"></a>03338 
+<a name="l03339"></a>03339 
+<a name="l03340"></a>03340     <span class="keywordflow">return</span> ret_distances ; 
+<a name="l03341"></a>03341 }
+<a name="l03366"></a>03366 cpl_image * 
+<a name="l03367"></a>03367 sinfo_new_make_true_resamp(cpl_image * calibImage, 
+<a name="l03368"></a>03368                            cpl_image * wavemap)
+<a name="l03369"></a>03369 {
+<a name="l03370"></a>03370     cpl_image * returnImage ;
+<a name="l03371"></a>03371     <span class="keywordtype">float</span> edges[33] ;
+<a name="l03372"></a>03372     <span class="keywordtype">int</span> imsize, kslit,i,j ;
+<a name="l03373"></a>03373     <span class="keywordtype">int</span> slit_index ;
+<a name="l03374"></a>03374     <span class="keywordtype">int</span> z, col, recol ;
+<a name="l03375"></a>03375     <span class="keywordtype">int</span> wlx=0;
+<a name="l03376"></a>03376     <span class="keywordtype">int</span> wly=0;
+<a name="l03377"></a>03377     <span class="keywordtype">int</span> clx=0;
+<a name="l03378"></a>03378     <span class="keywordtype">int</span> cly=0;
+<a name="l03379"></a>03379   
+<a name="l03380"></a>03380     <span class="keywordtype">float</span>* pcdata=NULL;
+<a name="l03381"></a>03381     <span class="keywordtype">float</span>* pwdata=NULL;
+<a name="l03382"></a>03382     <span class="keywordtype">float</span>* prdata=NULL;
+<a name="l03383"></a>03383 
+<a name="l03384"></a>03384 
+<a name="l03385"></a>03385     wlx=cpl_image_get_size_x(wavemap);
+<a name="l03386"></a>03386     wly=cpl_image_get_size_y(wavemap);
+<a name="l03387"></a>03387     pwdata=cpl_image_get_data_float(wavemap);
+<a name="l03388"></a>03388 
+<a name="l03389"></a>03389     edges[0]=0;
+<a name="l03390"></a>03390     j=1;
+<a name="l03391"></a>03391     <span class="keywordflow">for</span>(i=0;i<wlx-1;i++)
+<a name="l03392"></a>03392     {
+<a name="l03393"></a>03393         <span class="keywordflow">if</span>((pwdata[i]-pwdata[i+1])>0.0025 || (pwdata[i]-pwdata[i+1])<-0.0025)
+<a name="l03394"></a>03394     {
+<a name="l03395"></a>03395         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"wavemap sinfo_edge %d"</span>, i+1);
+<a name="l03396"></a>03396         edges[j]=i+1;
+<a name="l03397"></a>03397         j++;
+<a name="l03398"></a>03398     }
+<a name="l03399"></a>03399     }
+<a name="l03400"></a>03400     edges[32]=2048;
+<a name="l03401"></a>03401 
+<a name="l03402"></a>03402     clx=cpl_image_get_size_x(calibImage);
+<a name="l03403"></a>03403     cly=cpl_image_get_size_y(calibImage);
+<a name="l03404"></a>03404     pcdata=cpl_image_get_data_float(calibImage);
+<a name="l03405"></a>03405  
+<a name="l03406"></a>03406     imsize = clx / N_SLITLETS ;
+<a name="l03407"></a>03407 
+<a name="l03408"></a>03408     <span class="comment">/* allocate memory */</span>  
+<a name="l03409"></a>03409     returnImage = cpl_image_new(clx,cly,CPL_TYPE_FLOAT);
+<a name="l03410"></a>03410     prdata=cpl_image_get_data_float(returnImage);
+<a name="l03411"></a>03411     <span class="keywordflow">for</span> ( z = 0 ; z < cly ; z++ ) <span class="comment">/* go through the z-axis */</span>
+<a name="l03412"></a>03412     {
+<a name="l03413"></a>03413         <span class="keywordflow">for</span> ( col = 0 ; col < clx ; col++ ) <span class="comment">/* go through the image columns */</span>
+<a name="l03414"></a>03414         prdata[col+z*clx]=ZERO;
+<a name="l03415"></a>03415     }
+<a name="l03416"></a>03416     
+<a name="l03417"></a>03417 
+<a name="l03418"></a>03418     <span class="comment">/* now build the data cube out of the resampled image */</span>
+<a name="l03419"></a>03419     <span class="keywordflow">for</span> ( z = 0 ; z < cly ; z++ ) <span class="comment">/* go through the z-axis */</span>
+<a name="l03420"></a>03420     {
+<a name="l03421"></a>03421         kslit      = 0 ;
+<a name="l03422"></a>03422         slit_index = -1 ;
+<a name="l03423"></a>03423         recol      = -1 ;
+<a name="l03424"></a>03424         <span class="keywordflow">for</span> ( col = 0 ; col < clx ; col++ ) <span class="comment">/* go through the image columns */</span>
+<a name="l03425"></a>03425         {
+<a name="l03426"></a>03426             <span class="comment">/*if ( col % imsize == 0 )</span>
+<a name="l03427"></a>03427 <span class="comment">            {*/</span>
+<a name="l03428"></a>03428                 recol = 0 ;
+<a name="l03429"></a>03429                 <span class="comment">/*kslit = col/imsize ;*/</span>
+<a name="l03430"></a>03430         <span class="keywordflow">for</span>(i=0;i<32;i++)
+<a name="l03431"></a>03431         {
+<a name="l03432"></a>03432           <span class="keywordflow">if</span>(col>=sinfo_new_nint(edges[i]) && 
+<a name="l03433"></a>03433                      col<sinfo_new_nint(edges[i+1]))
+<a name="l03434"></a>03434             kslit=i;
+<a name="l03435"></a>03435         }
+<a name="l03436"></a>03436                 <span class="comment">/* sort the slitlets in the right spiffi specific way */</span>
+<a name="l03437"></a>03437     <span class="keywordflow">if</span>( (slit_index=sinfo_sort_slitlets(kslit)) == -1) {
+<a name="l03438"></a>03438             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"wrong slitlet index: couldn't be a "</span>
+<a name="l03439"></a>03439                              <span class="stringliteral">"spiffi image,  there must be 32 "</span>
+<a name="l03440"></a>03440                 <span class="stringliteral">"slitlets!"</span>) ;
+<a name="l03441"></a>03441         
+<a name="l03442"></a>03442     }
+<a name="l03443"></a>03443 
+<a name="l03444"></a>03444             <span class="comment">/*}*/</span>
+<a name="l03445"></a>03445 
+<a name="l03446"></a>03446             <span class="comment">/* fill each cube plane with one image row */</span>
+<a name="l03447"></a>03447         <span class="keywordflow">if</span>((col-sinfo_new_nint(edges[kslit]))>0 && 
+<a name="l03448"></a>03448                (col-sinfo_new_nint(edges[kslit]))<imsize-1 )
+<a name="l03449"></a>03449                 prdata[(col-sinfo_new_nint(edges[kslit]))+
+<a name="l03450"></a>03450                        slit_index*imsize+z*clx] = 
+<a name="l03451"></a>03451                       pcdata[col+z*clx] ;
+<a name="l03452"></a>03452             <span class="keywordflow">else</span>
+<a name="l03453"></a>03453             prdata[(col-sinfo_new_nint(edges[kslit]))+
+<a name="l03454"></a>03454                         slit_index*imsize+z*clx] = ZERO;
+<a name="l03455"></a>03455             <span class="comment">/*recol++ ;*/</span>
+<a name="l03456"></a>03456 
+<a name="l03457"></a>03457         }
+<a name="l03458"></a>03458     }
+<a name="l03459"></a>03459     <span class="keywordflow">return</span> returnImage ;
+<a name="l03460"></a>03460 }
+<a name="l03461"></a>03461 
+<a name="l03462"></a>03462 <span class="comment">/*The old slitlet order*/</span>
+<a name="l03463"></a>03463 <span class="comment">/*switch (kslit)</span>
+<a name="l03464"></a>03464 <span class="comment">                {</span>
+<a name="l03465"></a>03465 <span class="comment">                    case 0:</span>
+<a name="l03466"></a>03466 <span class="comment">                        slit_index = 23 ;</span>
+<a name="l03467"></a>03467 <span class="comment">                        break ;</span>
+<a name="l03468"></a>03468 <span class="comment">                    case 1:</span>
+<a name="l03469"></a>03469 <span class="comment">                        slit_index = 24 ;</span>
+<a name="l03470"></a>03470 <span class="comment">                        break ;</span>
+<a name="l03471"></a>03471 <span class="comment">                    case 2:</span>
+<a name="l03472"></a>03472 <span class="comment">                        slit_index = 22 ;</span>
+<a name="l03473"></a>03473 <span class="comment">                        break ;</span>
+<a name="l03474"></a>03474 <span class="comment">                    case 3:</span>
+<a name="l03475"></a>03475 <span class="comment">                        slit_index = 25 ;</span>
+<a name="l03476"></a>03476 <span class="comment">                        break ;</span>
+<a name="l03477"></a>03477 <span class="comment">                    case 4:</span>
+<a name="l03478"></a>03478 <span class="comment">                        slit_index = 21 ;</span>
+<a name="l03479"></a>03479 <span class="comment">                        break ;</span>
+<a name="l03480"></a>03480 <span class="comment">                    case 5:</span>
+<a name="l03481"></a>03481 <span class="comment">                        slit_index = 26 ;</span>
+<a name="l03482"></a>03482 <span class="comment">                        break ;</span>
+<a name="l03483"></a>03483 <span class="comment">                    case 6:</span>
+<a name="l03484"></a>03484 <span class="comment">                        slit_index = 20 ;</span>
+<a name="l03485"></a>03485 <span class="comment">                        break ;</span>
+<a name="l03486"></a>03486 <span class="comment">                    case 7:</span>
+<a name="l03487"></a>03487 <span class="comment">                        slit_index = 27 ;</span>
+<a name="l03488"></a>03488 <span class="comment">                        break ;</span>
+<a name="l03489"></a>03489 <span class="comment">                    case 8:</span>
+<a name="l03490"></a>03490 <span class="comment">                        slit_index = 19 ;</span>
+<a name="l03491"></a>03491 <span class="comment">                        break ;</span>
+<a name="l03492"></a>03492 <span class="comment">                    case 9:</span>
+<a name="l03493"></a>03493 <span class="comment">                        slit_index = 28 ;</span>
+<a name="l03494"></a>03494 <span class="comment">                        break ;</span>
+<a name="l03495"></a>03495 <span class="comment">                    case 10:</span>
+<a name="l03496"></a>03496 <span class="comment">                        slit_index = 18 ;</span>
+<a name="l03497"></a>03497 <span class="comment">                        break ;</span>
+<a name="l03498"></a>03498 <span class="comment">                    case 11:</span>
+<a name="l03499"></a>03499 <span class="comment">                        slit_index = 29 ;</span>
+<a name="l03500"></a>03500 <span class="comment">                        break ;</span>
+<a name="l03501"></a>03501 <span class="comment">                    case 12:</span>
+<a name="l03502"></a>03502 <span class="comment">                        slit_index = 17 ;</span>
+<a name="l03503"></a>03503 <span class="comment">                        break ;</span>
+<a name="l03504"></a>03504 <span class="comment">                    case 13:</span>
+<a name="l03505"></a>03505 <span class="comment">                        slit_index = 30 ;</span>
+<a name="l03506"></a>03506 <span class="comment">                        break ;</span>
+<a name="l03507"></a>03507 <span class="comment">                    case 14:</span>
+<a name="l03508"></a>03508 <span class="comment">                        slit_index = 16 ;</span>
+<a name="l03509"></a>03509 <span class="comment">                        break ;</span>
+<a name="l03510"></a>03510 <span class="comment">                    case 15:</span>
+<a name="l03511"></a>03511 <span class="comment">                        slit_index = 31 ;</span>
+<a name="l03512"></a>03512 <span class="comment">                        break ;</span>
+<a name="l03513"></a>03513 <span class="comment">                    case 16:</span>
+<a name="l03514"></a>03514 <span class="comment">                        slit_index = 0 ;</span>
+<a name="l03515"></a>03515 <span class="comment">                        break ;</span>
+<a name="l03516"></a>03516 <span class="comment">                    case 17:</span>
+<a name="l03517"></a>03517 <span class="comment">                        slit_index = 15 ;</span>
+<a name="l03518"></a>03518 <span class="comment">                        break ;</span>
+<a name="l03519"></a>03519 <span class="comment">                    case 18:</span>
+<a name="l03520"></a>03520 <span class="comment">                        slit_index = 1 ;</span>
+<a name="l03521"></a>03521 <span class="comment">                        break ;</span>
+<a name="l03522"></a>03522 <span class="comment">                    case 19:</span>
+<a name="l03523"></a>03523 <span class="comment">                        slit_index = 14 ;</span>
+<a name="l03524"></a>03524 <span class="comment">                        break ;</span>
+<a name="l03525"></a>03525 <span class="comment">                    case 20:</span>
+<a name="l03526"></a>03526 <span class="comment">                        slit_index = 2 ;</span>
+<a name="l03527"></a>03527 <span class="comment">                        break ;</span>
+<a name="l03528"></a>03528 <span class="comment">                    case 21:</span>
+<a name="l03529"></a>03529 <span class="comment">                        slit_index = 13 ;</span>
+<a name="l03530"></a>03530 <span class="comment">                        break ;</span>
+<a name="l03531"></a>03531 <span class="comment">                    case 22:</span>
+<a name="l03532"></a>03532 <span class="comment">                        slit_index = 3 ;</span>
+<a name="l03533"></a>03533 <span class="comment">                        break ;</span>
+<a name="l03534"></a>03534 <span class="comment">                    case 23:</span>
+<a name="l03535"></a>03535 <span class="comment">                        slit_index = 12 ;</span>
+<a name="l03536"></a>03536 <span class="comment">                        break ;</span>
+<a name="l03537"></a>03537 <span class="comment">                    case 24:</span>
+<a name="l03538"></a>03538 <span class="comment">                        slit_index = 4 ;</span>
+<a name="l03539"></a>03539 <span class="comment">                        break ;</span>
+<a name="l03540"></a>03540 <span class="comment">                    case 25:</span>
+<a name="l03541"></a>03541 <span class="comment">                        slit_index = 11 ;</span>
+<a name="l03542"></a>03542 <span class="comment">                        break ;</span>
+<a name="l03543"></a>03543 <span class="comment">                    case 26:</span>
+<a name="l03544"></a>03544 <span class="comment">                        slit_index = 5 ;</span>
+<a name="l03545"></a>03545 <span class="comment">                        break ;</span>
+<a name="l03546"></a>03546 <span class="comment">                    case 27:</span>
+<a name="l03547"></a>03547 <span class="comment">                        slit_index = 10 ;</span>
+<a name="l03548"></a>03548 <span class="comment">                        break ;</span>
+<a name="l03549"></a>03549 <span class="comment">                    case 28:</span>
+<a name="l03550"></a>03550 <span class="comment">                        slit_index = 6 ;</span>
+<a name="l03551"></a>03551 <span class="comment">                        break ;</span>
+<a name="l03552"></a>03552 <span class="comment">                    case 29:</span>
+<a name="l03553"></a>03553 <span class="comment">                        slit_index = 9 ;</span>
+<a name="l03554"></a>03554 <span class="comment">                        break ;</span>
+<a name="l03555"></a>03555 <span class="comment">                    case 30:</span>
+<a name="l03556"></a>03556 <span class="comment">                        slit_index = 7 ;</span>
+<a name="l03557"></a>03557 <span class="comment">                        break ;</span>
+<a name="l03558"></a>03558 <span class="comment">                    case 31:</span>
+<a name="l03559"></a>03559 <span class="comment">                        slit_index = 8 ;</span>
+<a name="l03560"></a>03560 <span class="comment">                        break ;</span>
+<a name="l03561"></a>03561 <span class="comment">                    default:</span>
+<a name="l03562"></a>03562 <span class="comment">                        sinfo_msg_error("wrong slitlet index: couldn't "</span>
+<a name="l03563"></a>03563 <span class="comment">                                        "be a spiffi image,  \</span>
+<a name="l03564"></a>03564 <span class="comment">                                 there must be 32 slitlets!\n") ;</span>
+<a name="l03565"></a>03565 <span class="comment">                        cpl_imagelist_delete(returnCube) ;</span>
+<a name="l03566"></a>03566 <span class="comment">                        return NULL ;</span>
+<a name="l03567"></a>03567 <span class="comment">                        break ;</span>
+<a name="l03568"></a>03568 <span class="comment">                }*/</span>
+<a name="l03569"></a>03569 
+<a name="l03570"></a>03570 
+<a name="l03571"></a>03571 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__cube__construct_8h_source.html b/html/sinfo__cube__construct_8h_source.html
new file mode 100644
index 0000000..a43fb92
--- /dev/null
+++ b/html/sinfo__cube__construct_8h_source.html
@@ -0,0 +1,152 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_cube_construct.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_cube_construct.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#ifndef SINFO_CUBE_CONSTRUCT_H</span>
+<a name="l00002"></a>00002 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_CUBE_CONSTRUCT_H</span>
+<a name="l00003"></a>00003 <span class="preprocessor"></span><span class="comment">/*</span>
+<a name="l00004"></a>00004 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00005"></a>00005 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00006"></a>00006 <span class="comment"> *</span>
+<a name="l00007"></a>00007 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00008"></a>00008 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00009"></a>00009 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00010"></a>00010 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00011"></a>00011 <span class="comment"> *</span>
+<a name="l00012"></a>00012 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00013"></a>00013 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00014"></a>00014 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00015"></a>00015 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00016"></a>00016 <span class="comment"> *</span>
+<a name="l00017"></a>00017 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00018"></a>00018 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00019"></a>00019 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00020"></a>00020 <span class="comment"> */</span>
+<a name="l00021"></a>00021 <span class="comment">/*******************************************************************************</span>
+<a name="l00022"></a>00022 <span class="comment">* E.S.O. - VLT project</span>
+<a name="l00023"></a>00023 <span class="comment">*</span>
+<a name="l00024"></a>00024 <span class="comment">* "@(#) $Id: sinfo_cube_construct.h,v 1.4 2007/06/06 07:10:45 amodigli Exp $"</span>
+<a name="l00025"></a>00025 <span class="comment">*</span>
+<a name="l00026"></a>00026 <span class="comment">* who       when      what</span>
+<a name="l00027"></a>00027 <span class="comment">* --------  --------  ----------------------------------------------</span>
+<a name="l00028"></a>00028 <span class="comment">* schreib  06/10/00  created</span>
+<a name="l00029"></a>00029 <span class="comment">*/</span>
+<a name="l00030"></a>00030 
+<a name="l00031"></a>00031 <span class="comment">/************************************************************************</span>
+<a name="l00032"></a>00032 <span class="comment"> * ned_cube_construct.h</span>
+<a name="l00033"></a>00033 <span class="comment"> * routines needed to construct a 3D-data cube</span>
+<a name="l00034"></a>00034 <span class="comment"> *----------------------------------------------------------------------</span>
+<a name="l00035"></a>00035 <span class="comment"> */</span>
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="comment">/*</span>
+<a name="l00038"></a>00038 <span class="comment"> * header files</span>
+<a name="l00039"></a>00039 <span class="comment"> */</span>
+<a name="l00040"></a>00040 
+<a name="l00041"></a>00041 <span class="preprocessor">#include "sinfo_new_cube_ops.h"</span>
+<a name="l00042"></a>00042 
+<a name="l00043"></a>00043 <span class="comment">/*</span>
+<a name="l00044"></a>00044 <span class="comment"> * function prototypes</span>
+<a name="l00045"></a>00045 <span class="comment"> */</span>
+<a name="l00046"></a>00046 
+<a name="l00057"></a>00057 cpl_image * 
+<a name="l00058"></a>00058 sinfo_new_convolve_ns_image_by_gauss( cpl_image * lineImage,<span class="keywordtype">int</span> hw);
+<a name="l00059"></a>00059 
+<a name="l00076"></a>00076 <span class="keywordtype">float</span> * 
+<a name="l00077"></a>00077 sinfo_north_south_test( cpl_image * ns_image,
+<a name="l00078"></a>00078                           <span class="keywordtype">int</span>        n_slitlets,
+<a name="l00079"></a>00079                           <span class="keywordtype">int</span>        halfWidth,
+<a name="l00080"></a>00080                           <span class="keywordtype">float</span>      fwhm,
+<a name="l00081"></a>00081                           <span class="keywordtype">float</span>      minDiff,
+<a name="l00082"></a>00082                           <span class="keywordtype">float</span>      estimated_dist,
+<a name="l00083"></a>00083                           <span class="keywordtype">float</span>      devtol,
+<a name="l00084"></a>00084               <span class="keywordtype">int</span>        top,
+<a name="l00085"></a>00085               <span class="keywordtype">int</span>        bottom ) ;
+<a name="l00086"></a>00086 
+<a name="l00087"></a>00087 
+<a name="l00111"></a>00111 cpl_imagelist * 
+<a name="l00112"></a>00112 sinfo_new_make_cube ( cpl_image * calibImage,
+<a name="l00113"></a>00113                      <span class="keywordtype">float</span>    * distances,
+<a name="l00114"></a>00114                      <span class="keywordtype">float</span>    * correct_diff_dist ) ;
+<a name="l00115"></a>00115 
+<a name="l00132"></a>00132 cpl_imagelist * 
+<a name="l00133"></a>00133 sinfo_new_make_cube_spi ( cpl_image *  calibImage,
+<a name="l00134"></a>00134                         <span class="keywordtype">float</span>    ** slit_edges,
+<a name="l00135"></a>00135                         <span class="keywordtype">float</span>    *  shift ) ;
+<a name="l00136"></a>00136 
+<a name="l00137"></a>00137 
+<a name="l00164"></a>00164 cpl_imagelist * 
+<a name="l00165"></a>00165 sinfo_new_make_cube_dist ( cpl_image * calibImage,
+<a name="l00166"></a>00166                          <span class="keywordtype">float</span>      firstCol,
+<a name="l00167"></a>00167                          <span class="keywordtype">float</span>    * distances,
+<a name="l00168"></a>00168                          <span class="keywordtype">float</span>    * shift ) ;
+<a name="l00169"></a>00169 
+<a name="l00170"></a>00170 
+<a name="l00196"></a>00196 cpl_imagelist * 
+<a name="l00197"></a>00197 sinfo_new_make_3D_cube_dist ( cpl_image * calibImage,
+<a name="l00198"></a>00198                            <span class="keywordtype">float</span>      firstCol,
+<a name="l00199"></a>00199                            <span class="keywordtype">float</span>    * distances,
+<a name="l00200"></a>00200                            <span class="keywordtype">float</span>    * shift ) ;
+<a name="l00201"></a>00201 
+<a name="l00202"></a>00202 
+<a name="l00219"></a>00219 cpl_imagelist * 
+<a name="l00220"></a>00220 sinfo_new_make_3D_cube ( cpl_image * calibImage,
+<a name="l00221"></a>00221                        <span class="keywordtype">int</span>      * kpixshift,
+<a name="l00222"></a>00222                        <span class="keywordtype">int</span>        kpixfirst ) ;
+<a name="l00223"></a>00223 
+<a name="l00224"></a>00224 
+<a name="l00237"></a>00237 cpl_imagelist * 
+<a name="l00238"></a>00238 sinfo_new_determine_mask_cube ( cpl_imagelist * sourceMaskCube,
+<a name="l00239"></a>00239                               <span class="keywordtype">float</span>     lowLimit,
+<a name="l00240"></a>00240                               <span class="keywordtype">float</span>     highLimit ) ;
+<a name="l00241"></a>00241 
+<a name="l00242"></a>00242 
+<a name="l00280"></a>00280 cpl_imagelist * 
+<a name="l00281"></a>00281 sinfo_new_interpol_cube ( cpl_imagelist * sourceCube,
+<a name="l00282"></a>00282                          cpl_imagelist * maskCube,
+<a name="l00283"></a>00283                          <span class="keywordtype">int</span>       n_neighbors,   <span class="comment">/* 7 */</span>
+<a name="l00284"></a>00284                          <span class="keywordtype">int</span>       max_radius ) ; <span class="comment">/* 5 */</span>
+<a name="l00285"></a>00285 
+<a name="l00286"></a>00286 
+<a name="l00308"></a>00308 cpl_imagelist * 
+<a name="l00309"></a>00309 sinfo_new_fine_tune_cube( cpl_imagelist * cube,
+<a name="l00310"></a>00310                          <span class="keywordtype">float</span>   * correct_diff_dist,
+<a name="l00311"></a>00311                          <span class="keywordtype">int</span>       n_order) ;
+<a name="l00312"></a>00312 
+<a name="l00313"></a>00313 
+<a name="l00334"></a>00334 cpl_imagelist * 
+<a name="l00335"></a>00335 sinfo_new_fine_tune_cube_by_FFT( cpl_imagelist * cube,
+<a name="l00336"></a>00336                                 <span class="keywordtype">float</span>   * correct_diff_dist ) ;
+<a name="l00337"></a>00337 
+<a name="l00367"></a>00367 cpl_imagelist * 
+<a name="l00368"></a>00368 sinfo_new_fine_tune_cube_by_spline ( cpl_imagelist * cube,
+<a name="l00369"></a>00369                                  <span class="keywordtype">float</span>   * correct_diff_dist ) ;
+<a name="l00370"></a>00370 
+<a name="l00390"></a>00390 <span class="keywordtype">float</span> * 
+<a name="l00391"></a>00391 sinfo_new_calibrate_ns_test( cpl_image * ns_image,
+<a name="l00392"></a>00392                            <span class="keywordtype">int</span>        n_slitlets,
+<a name="l00393"></a>00393                            <span class="keywordtype">int</span>        halfWidth,
+<a name="l00394"></a>00394                            <span class="keywordtype">float</span>      fwhm,
+<a name="l00395"></a>00395                            <span class="keywordtype">float</span>      minDiff,
+<a name="l00396"></a>00396                            <span class="keywordtype">float</span>      estimated_dist,
+<a name="l00397"></a>00397                            <span class="keywordtype">float</span>      devtol,
+<a name="l00398"></a>00398                <span class="keywordtype">int</span>        bottom,
+<a name="l00399"></a>00399                <span class="keywordtype">int</span>        top ) ;
+<a name="l00400"></a>00400 
+<a name="l00401"></a>00401 
+<a name="l00402"></a>00402 cpl_image * 
+<a name="l00403"></a>00403 sinfo_new_make_true_resamp(cpl_image * calibImage, cpl_image* wavemap);
+<a name="l00404"></a>00404 
+<a name="l00405"></a>00405 
+<a name="l00406"></a>00406 <span class="preprocessor">#endif </span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__cubecreate__ini_8h_source.html b/html/sinfo__cubecreate__ini_8h_source.html
new file mode 100644
index 0000000..a6a2702
--- /dev/null
+++ b/html/sinfo__cubecreate__ini_8h_source.html
@@ -0,0 +1,61 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_cubecreate_ini.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_cubecreate_ini.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name    :   cubecreate_ini.h</span>
+<a name="l00022"></a>00022 <span class="comment">   Author       :    Juergen Schreiber</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on   :    Nov 28, 2001</span>
+<a name="l00024"></a>00024 <span class="comment">   Description  :    ini file handling for SPIFFIs creation of a data cube</span>
+<a name="l00025"></a>00025 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00026"></a>00026 <span class="preprocessor">#ifndef SINFO_CUBECREATE_INI_H</span>
+<a name="l00027"></a>00027 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_CUBECREATE_INI_H</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00029"></a>00029 <span class="comment">                                Includes</span>
+<a name="l00030"></a>00030 <span class="comment">---------------------------------------------------------------------------*/</span>
+<a name="l00031"></a>00031 <span class="preprocessor">#include "sinfo_cubecreate_cfg.h"</span>
+<a name="l00032"></a>00032 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                             Function prototypes </span>
+<a name="l00034"></a>00034 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00050"></a>00050 <span class="keywordtype">int</span> 
+<a name="l00051"></a>00051 generateCube_ini_file(
+<a name="l00052"></a>00052         <span class="keywordtype">char</span> * ini_name,
+<a name="l00053"></a>00053         <span class="keywordtype">char</span> * name_i,
+<a name="l00054"></a>00054         <span class="keywordtype">char</span> * name_o,
+<a name="l00055"></a>00055         <span class="keywordtype">char</span> * name_c
+<a name="l00056"></a>00056 );
+<a name="l00067"></a>00067 cube_config * 
+<a name="l00068"></a>00068 parse_cube_ini_file(<span class="keywordtype">char</span> * ini_name) ;
+<a name="l00069"></a>00069 
+<a name="l00070"></a>00070 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__dark__cfg_8c_source.html b/html/sinfo__dark__cfg_8c_source.html
new file mode 100644
index 0000000..1865c8a
--- /dev/null
+++ b/html/sinfo__dark__cfg_8c_source.html
@@ -0,0 +1,69 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_dark_cfg.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_dark_cfg.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name     :    sinfo_dark_cfg.c</span>
+<a name="l00022"></a>00022 <span class="comment">   Author     :       Juergen Schreiber</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on    :    February 2002</span>
+<a name="l00024"></a>00024 <span class="comment">   Description    :    configuration handling tools for the generation of</span>
+<a name="l00025"></a>00025 <span class="comment">                        master sinfo_dark frames </span>
+<a name="l00026"></a>00026 <span class="comment"></span>
+<a name="l00027"></a>00027 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00032"></a>00032 <span class="comment">                                   Includes</span>
+<a name="l00033"></a>00033 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00034"></a>00034 <span class="preprocessor">#include "sinfo_dark_cfg.h"</span>
+<a name="l00042"></a>00042 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00043"></a>00043 <span class="comment">                              Function codes</span>
+<a name="l00044"></a>00044 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00052"></a>00052 dark_config * 
+<a name="l00053"></a>00053 sinfo_dark_cfg_create(<span class="keywordtype">void</span>)
+<a name="l00054"></a>00054 {
+<a name="l00055"></a>00055     <span class="keywordflow">return</span> cpl_calloc(1, <span class="keyword">sizeof</span>(dark_config));
+<a name="l00056"></a>00056 }
+<a name="l00057"></a>00057 
+<a name="l00065"></a>00065 <span class="keywordtype">void</span> sinfo_dark_cfg_destroy(dark_config * cc)
+<a name="l00066"></a>00066 {
+<a name="l00067"></a>00067     <span class="keywordflow">if</span> (cc==NULL) return ;
+<a name="l00068"></a>00068 
+<a name="l00069"></a>00069     <span class="comment">/* Free main struct */</span>
+<a name="l00070"></a>00070     cpl_free(cc);
+<a name="l00071"></a>00071 
+<a name="l00072"></a>00072     return ;
+<a name="l00073"></a>00073 }
+<a name="l00074"></a>00074 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__dark__cfg_8h_source.html b/html/sinfo__dark__cfg_8h_source.html
new file mode 100644
index 0000000..c0c9f42
--- /dev/null
+++ b/html/sinfo__dark__cfg_8h_source.html
@@ -0,0 +1,109 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_dark_cfg.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_dark_cfg.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   File name     :    sinfo_dark_cfg.h</span>
+<a name="l00021"></a>00021 <span class="comment">   Author    :    Juergen Schreiber</span>
+<a name="l00022"></a>00022 <span class="comment">   Created on    :    February 2002</span>
+<a name="l00023"></a>00023 <span class="comment">   Description    :    sinfo_dark_cfg.c definitions + handling prototypes</span>
+<a name="l00024"></a>00024 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00025"></a>00025 <span class="preprocessor">#ifndef SINFO_DARK_CFG_H</span>
+<a name="l00026"></a>00026 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_DARK_CFG_H</span>
+<a name="l00027"></a>00027 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00028"></a>00028 <span class="comment">                                   Includes</span>
+<a name="l00029"></a>00029 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00030"></a>00030 <span class="preprocessor">#include <stdlib.h></span>
+<a name="l00031"></a>00031 <span class="preprocessor">#include "sinfo_globals.h"</span>
+<a name="l00032"></a>00032 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00033"></a>00033 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00034"></a>00034 <span class="comment">                                   Defines</span>
+<a name="l00035"></a>00035 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00036"></a>00036 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00037"></a>00037 <span class="comment">                                   New types</span>
+<a name="l00038"></a>00038 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00039"></a>00039 <span class="comment">/*</span>
+<a name="l00040"></a>00040 <span class="comment">  master dark frame generation blackboard container</span>
+<a name="l00041"></a>00041 <span class="comment"></span>
+<a name="l00042"></a>00042 <span class="comment">  This structure holds all information related to the master dark </span>
+<a name="l00043"></a>00043 <span class="comment">  frame generation</span>
+<a name="l00044"></a>00044 <span class="comment">  routine. It is used as a container for the flux of ancillary data,</span>
+<a name="l00045"></a>00045 <span class="comment">  computed values, and algorithm status. Pixel flux is separated from</span>
+<a name="l00046"></a>00046 <span class="comment">  the blackboard.</span>
+<a name="l00047"></a>00047 <span class="comment">  */</span>
+<a name="l00048"></a>00048 
+<a name="l00049"></a>00049 <span class="keyword">typedef</span> <span class="keyword">struct </span>dark_config {
+<a name="l00050"></a>00050 <span class="comment">/*-------General---------*/</span>
+<a name="l00051"></a>00051         <span class="keywordtype">char</span> inFile[FILE_NAME_SZ] ;       <span class="comment">/* file name of frame list */</span>
+<a name="l00052"></a>00052         <span class="keywordtype">char</span> ** inFrameList ; <span class="comment">/* input averaged, bad pixel corrected, </span>
+<a name="l00053"></a>00053 <span class="comment">                                 off subtracted, flatfielded, spectral </span>
+<a name="l00054"></a>00054 <span class="comment">                                 tilt corrected list of frames */</span>
+<a name="l00055"></a>00055         <span class="keywordtype">int</span> nframes ;         <span class="comment">/* number of frames in the list */</span>
+<a name="l00056"></a>00056         <span class="keywordtype">char</span> outName[FILE_NAME_SZ] ; <span class="comment">/* output name of resulting fits </span>
+<a name="l00057"></a>00057 <span class="comment">                                        data cube */</span>
+<a name="l00058"></a>00058 
+<a name="l00059"></a>00059 <span class="comment">/*------ CleanMean ------*/</span>
+<a name="l00060"></a>00060         <span class="comment">/* the fraction [0...1] of rejected low intensity pixels when </span>
+<a name="l00061"></a>00061 <span class="comment">           taking the average of columns */</span>
+<a name="l00062"></a>00062         <span class="keywordtype">float</span> lo_reject ;
+<a name="l00063"></a>00063         <span class="comment">/* the fraction [0...1] of rejected high intensity pixels when </span>
+<a name="l00064"></a>00064 <span class="comment">           taking the average of columns */</span>
+<a name="l00065"></a>00065         <span class="keywordtype">float</span> hi_reject ;
+<a name="l00066"></a>00066 <span class="comment">/*------ QCLOG ------*/</span>
+<a name="l00067"></a>00067         <span class="comment">/* RON */</span>
+<a name="l00068"></a>00068         
+<a name="l00069"></a>00069   <span class="keywordtype">int</span> qc_ron_xmin;
+<a name="l00070"></a>00070   <span class="keywordtype">int</span> qc_ron_xmax;
+<a name="l00071"></a>00071   <span class="keywordtype">int</span> qc_ron_ymin;
+<a name="l00072"></a>00072   <span class="keywordtype">int</span> qc_ron_ymax;
+<a name="l00073"></a>00073   <span class="keywordtype">int</span> qc_ron_hsize;
+<a name="l00074"></a>00074   <span class="keywordtype">int</span> qc_ron_nsamp;
+<a name="l00075"></a>00075   <span class="comment">/* FPN */</span>
+<a name="l00076"></a>00076   <span class="keywordtype">int</span> qc_fpn_xmin;
+<a name="l00077"></a>00077   <span class="keywordtype">int</span> qc_fpn_xmax;
+<a name="l00078"></a>00078   <span class="keywordtype">int</span> qc_fpn_ymin;
+<a name="l00079"></a>00079   <span class="keywordtype">int</span> qc_fpn_ymax;
+<a name="l00080"></a>00080   <span class="keywordtype">int</span> qc_fpn_hsize;
+<a name="l00081"></a>00081   <span class="keywordtype">int</span> qc_fpn_nsamp;
+<a name="l00082"></a>00082 
+<a name="l00083"></a>00083 } dark_config ;
+<a name="l00084"></a>00084 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00085"></a>00085 <span class="comment">                               Function prototypes</span>
+<a name="l00086"></a>00086 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00094"></a>00094 dark_config * 
+<a name="l00095"></a>00095 sinfo_dark_cfg_create(<span class="keywordtype">void</span>);
+<a name="l00102"></a>00102 <span class="keywordtype">void</span> 
+<a name="l00103"></a>00103 sinfo_dark_cfg_destroy(dark_config * cc);
+<a name="l00104"></a>00104  
+<a name="l00105"></a>00105 
+<a name="l00106"></a>00106 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__dark__config_8c_source.html b/html/sinfo__dark__config_8c_source.html
new file mode 100644
index 0000000..87ab5bb
--- /dev/null
+++ b/html/sinfo__dark__config_8c_source.html
@@ -0,0 +1,215 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_dark_config.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_dark_config.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_dark_config.c,v 1.5 2012/03/02 08:42:20 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the CPL (Common Pipeline Library)</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
+<a name="l00007"></a>00007 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span>
+<a name="l00008"></a>00008 <span class="comment"> * License as published by the Free Software Foundation; either</span>
+<a name="l00009"></a>00009 <span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
+<a name="l00014"></a>00014 <span class="comment"> * Lesser General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
+<a name="l00017"></a>00017 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2012/03/02 08:42:20 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.5 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> */</span>
+<a name="l00026"></a>00026 
+<a name="l00027"></a>00027 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00029"></a>00029 <span class="preprocessor">#endif</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span> <span class="comment">/****************************************************************</span>
+<a name="l00031"></a>00031 <span class="comment">  *   Dark Frames Data Reduction Parameter Initialization        *</span>
+<a name="l00032"></a>00032 <span class="comment">  ****************************************************************/</span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include "sinfo_dark_config.h"</span>
+<a name="l00052"></a>00052   <span class="comment">/* Dark Frame Data Reduction parameters */</span>
+<a name="l00053"></a>00053    
+<a name="l00054"></a>00054 
+<a name="l00055"></a>00055 <span class="keywordtype">void</span>
+<a name="l00056"></a>00056  sinfo_dark_config_add(cpl_parameterlist *list)
+<a name="l00057"></a>00057 {
+<a name="l00058"></a>00058 
+<a name="l00059"></a>00059   cpl_parameter *p;
+<a name="l00060"></a>00060 
+<a name="l00061"></a>00061   <span class="keywordflow">if</span> (!list) {
+<a name="l00062"></a>00062     <span class="keywordflow">return</span>;
+<a name="l00063"></a>00063   }
+<a name="l00064"></a>00064 
+<a name="l00065"></a>00065   <span class="comment">/* float </span>
+<a name="l00066"></a>00066 <span class="comment">     threshold used in the clean mean percentage of rejection used to reject </span>
+<a name="l00067"></a>00067 <span class="comment">     low and high frame */</span>
+<a name="l00068"></a>00068  <span class="comment">/* percentage of extreme pixel value to reject when calculating the mean </span>
+<a name="l00069"></a>00069 <span class="comment">    and stdev */</span>
+<a name="l00070"></a>00070   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.dark.low_rejection"</span>,
+<a name="l00071"></a>00071                   CPL_TYPE_DOUBLE,
+<a name="l00072"></a>00072                               <span class="stringliteral">"lower rejection"</span>,
+<a name="l00073"></a>00073                               <span class="stringliteral">"sinfoni.dark"</span>,
+<a name="l00074"></a>00074                               0.1,0.0,1.0);
+<a name="l00075"></a>00075 
+<a name="l00076"></a>00076   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"dark-lo_rej"</span>);
+<a name="l00077"></a>00077   cpl_parameterlist_append(list, p);
+<a name="l00078"></a>00078 
+<a name="l00079"></a>00079   <span class="comment">/* float </span>
+<a name="l00080"></a>00080 <span class="comment">     threshold used in the clean mean percentage of rejection used to reject </span>
+<a name="l00081"></a>00081 <span class="comment">     low and high frame */</span>
+<a name="l00082"></a>00082  <span class="comment">/* percentage of extreme pixel value to reject when calculating the mean </span>
+<a name="l00083"></a>00083 <span class="comment">    and stdev */</span>
+<a name="l00084"></a>00084 
+<a name="l00085"></a>00085 
+<a name="l00086"></a>00086   <span class="comment">/* QC LOG */</span>
+<a name="l00087"></a>00087   <span class="comment">/* RON */</span>
+<a name="l00088"></a>00088 
+<a name="l00089"></a>00089   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.dark.high_rejection"</span>,
+<a name="l00090"></a>00090                   CPL_TYPE_DOUBLE,
+<a name="l00091"></a>00091                               <span class="stringliteral">"higher rejection"</span>,
+<a name="l00092"></a>00092                               <span class="stringliteral">"sinfoni.dark"</span>,
+<a name="l00093"></a>00093                               0.1,0.0,1.0);
+<a name="l00094"></a>00094 
+<a name="l00095"></a>00095   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"dark-hi_rej"</span>);
+<a name="l00096"></a>00096   cpl_parameterlist_append(list, p);
+<a name="l00097"></a>00097 
+<a name="l00098"></a>00098 
+<a name="l00099"></a>00099  
+<a name="l00100"></a>00100   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.dark.qc_ron_xmin"</span>,
+<a name="l00101"></a>00101                   CPL_TYPE_INT,
+<a name="l00102"></a>00102                               <span class="stringliteral">"qc_ron_xmin"</span>,
+<a name="l00103"></a>00103                               <span class="stringliteral">"sinfoni.dark"</span>,
+<a name="l00104"></a>00104                               1,DET_PIX_MIN,DET_PIX_MAX);
+<a name="l00105"></a>00105 
+<a name="l00106"></a>00106   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"dark-qc_ron_xmin"</span>);
+<a name="l00107"></a>00107   cpl_parameterlist_append(list, p);
+<a name="l00108"></a>00108   
+<a name="l00109"></a>00109  
+<a name="l00110"></a>00110   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.dark.qc_ron_xmax"</span>,
+<a name="l00111"></a>00111                   CPL_TYPE_INT,
+<a name="l00112"></a>00112                               <span class="stringliteral">"qc_ron_xmax"</span>,
+<a name="l00113"></a>00113                               <span class="stringliteral">"sinfoni.dark"</span>,
+<a name="l00114"></a>00114                               2048,DET_PIX_MIN,DET_PIX_MAX);
+<a name="l00115"></a>00115 
+<a name="l00116"></a>00116   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"dark-qc_ron_xmax"</span>);
+<a name="l00117"></a>00117   cpl_parameterlist_append(list, p);
+<a name="l00118"></a>00118 
+<a name="l00119"></a>00119   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.dark.qc_ron_ymin"</span>,
+<a name="l00120"></a>00120                   CPL_TYPE_INT,
+<a name="l00121"></a>00121                               <span class="stringliteral">"qc_ron_ymin"</span>,
+<a name="l00122"></a>00122                               <span class="stringliteral">"sinfoni.dark"</span>,
+<a name="l00123"></a>00123                               1,DET_PIX_MIN,DET_PIX_MAX);
+<a name="l00124"></a>00124 
+<a name="l00125"></a>00125   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"dark-qc_ron_ymin"</span>);
+<a name="l00126"></a>00126   cpl_parameterlist_append(list, p);
+<a name="l00127"></a>00127 
+<a name="l00128"></a>00128 
+<a name="l00129"></a>00129   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.dark.qc_ron_ymax"</span>,
+<a name="l00130"></a>00130                   CPL_TYPE_INT,
+<a name="l00131"></a>00131                               <span class="stringliteral">"qc_ron_ymax"</span>,
+<a name="l00132"></a>00132                               <span class="stringliteral">"sinfoni.dark"</span>,
+<a name="l00133"></a>00133                               2048,DET_PIX_MIN,DET_PIX_MAX);
+<a name="l00134"></a>00134 
+<a name="l00135"></a>00135   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"dark-qc_ron_ymax"</span>);
+<a name="l00136"></a>00136   cpl_parameterlist_append(list, p);
+<a name="l00137"></a>00137 
+<a name="l00138"></a>00138   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.dark.qc_ron_hsize"</span>,
+<a name="l00139"></a>00139                   CPL_TYPE_INT,
+<a name="l00140"></a>00140                               <span class="stringliteral">"qc_ron_hsize"</span>,
+<a name="l00141"></a>00141                               <span class="stringliteral">"sinfoni.dark"</span>,
+<a name="l00142"></a>00142                               4);
+<a name="l00143"></a>00143 
+<a name="l00144"></a>00144   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"dark-qc_ron_hsize"</span>);
+<a name="l00145"></a>00145   cpl_parameterlist_append(list, p);
+<a name="l00146"></a>00146  
+<a name="l00147"></a>00147   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.dark.qc_ron_nsamp"</span>,
+<a name="l00148"></a>00148                   CPL_TYPE_INT,
+<a name="l00149"></a>00149                               <span class="stringliteral">"qc_ron_nsamp"</span>,
+<a name="l00150"></a>00150                               <span class="stringliteral">"sinfoni.dark"</span>,
+<a name="l00151"></a>00151                               100);
+<a name="l00152"></a>00152 
+<a name="l00153"></a>00153   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"dark-qc_ron_nsamp"</span>);
+<a name="l00154"></a>00154   cpl_parameterlist_append(list, p);
+<a name="l00155"></a>00155  
+<a name="l00156"></a>00156   <span class="comment">/* FPN */</span>
+<a name="l00157"></a>00157 
+<a name="l00158"></a>00158 
+<a name="l00159"></a>00159  p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.dark.qc_fpn_xmin"</span>,
+<a name="l00160"></a>00160                   CPL_TYPE_INT,
+<a name="l00161"></a>00161                               <span class="stringliteral">"qc_fpn_xmin"</span>,
+<a name="l00162"></a>00162                               <span class="stringliteral">"sinfoni.dark"</span>,
+<a name="l00163"></a>00163                               1,DET_PIX_MIN,DET_PIX_MAX);
+<a name="l00164"></a>00164 
+<a name="l00165"></a>00165   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"dark-qc_fpn_xmin"</span>);
+<a name="l00166"></a>00166   cpl_parameterlist_append(list, p);
+<a name="l00167"></a>00167   
+<a name="l00168"></a>00168  
+<a name="l00169"></a>00169   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.dark.qc_fpn_xmax"</span>,
+<a name="l00170"></a>00170                   CPL_TYPE_INT,
+<a name="l00171"></a>00171                               <span class="stringliteral">"qc_fpn_xmax"</span>,
+<a name="l00172"></a>00172                               <span class="stringliteral">"sinfoni.dark"</span>,
+<a name="l00173"></a>00173                               2047,DET_PIX_MIN,DET_PIX_MAX);
+<a name="l00174"></a>00174 
+<a name="l00175"></a>00175   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"dark-qc_fpn_xmax"</span>);
+<a name="l00176"></a>00176   cpl_parameterlist_append(list, p);
+<a name="l00177"></a>00177 
+<a name="l00178"></a>00178   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.dark.qc_fpn_ymin"</span>,
+<a name="l00179"></a>00179                   CPL_TYPE_INT,
+<a name="l00180"></a>00180                               <span class="stringliteral">"qc_fpn_ymin"</span>,
+<a name="l00181"></a>00181                               <span class="stringliteral">"sinfoni.dark"</span>,
+<a name="l00182"></a>00182                               1,DET_PIX_MIN,DET_PIX_MAX);
+<a name="l00183"></a>00183 
+<a name="l00184"></a>00184   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"dark-qc_fpn_ymin"</span>);
+<a name="l00185"></a>00185   cpl_parameterlist_append(list, p);
+<a name="l00186"></a>00186 
+<a name="l00187"></a>00187 
+<a name="l00188"></a>00188   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.dark.qc_fpn_ymax"</span>,
+<a name="l00189"></a>00189                   CPL_TYPE_INT,
+<a name="l00190"></a>00190                               <span class="stringliteral">"qc_fpn_ymax"</span>,
+<a name="l00191"></a>00191                               <span class="stringliteral">"sinfoni.dark"</span>,
+<a name="l00192"></a>00192                               2047,DET_PIX_MIN,DET_PIX_MAX);
+<a name="l00193"></a>00193 
+<a name="l00194"></a>00194   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"dark-qc_fpn_ymax"</span>);
+<a name="l00195"></a>00195   cpl_parameterlist_append(list, p);
+<a name="l00196"></a>00196 
+<a name="l00197"></a>00197 
+<a name="l00198"></a>00198 
+<a name="l00199"></a>00199   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.dark.qc_fpn_hsize"</span>,
+<a name="l00200"></a>00200                   CPL_TYPE_INT,
+<a name="l00201"></a>00201                               <span class="stringliteral">"qc_fpn_hsize"</span>,
+<a name="l00202"></a>00202                               <span class="stringliteral">"sinfoni.dark"</span>,
+<a name="l00203"></a>00203                               2);
+<a name="l00204"></a>00204 
+<a name="l00205"></a>00205   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"dark-qc_fpn_hsize"</span>);
+<a name="l00206"></a>00206   cpl_parameterlist_append(list, p);
+<a name="l00207"></a>00207  
+<a name="l00208"></a>00208   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.dark.qc_fpn_nsamp"</span>,
+<a name="l00209"></a>00209                   CPL_TYPE_INT,
+<a name="l00210"></a>00210                               <span class="stringliteral">"qc_fpn_nsamp"</span>,
+<a name="l00211"></a>00211                               <span class="stringliteral">"sinfoni.dark"</span>,
+<a name="l00212"></a>00212                               1000);
+<a name="l00213"></a>00213 
+<a name="l00214"></a>00214   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"dark-qc_fpn_nsamp"</span>);
+<a name="l00215"></a>00215   cpl_parameterlist_append(list, p);
+<a name="l00216"></a>00216 
+<a name="l00217"></a>00217 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__dark__config_8h_source.html b/html/sinfo__dark__config_8h_source.html
new file mode 100644
index 0000000..52c94c5
--- /dev/null
+++ b/html/sinfo__dark__config_8h_source.html
@@ -0,0 +1,52 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_dark_config.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_dark_config.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_dark_config.h,v 1.1 2006/10/20 08:06:32 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the CPL (Common Pipeline Library)</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
+<a name="l00007"></a>00007 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span>
+<a name="l00008"></a>00008 <span class="comment"> * License as published by the Free Software Foundation; either</span>
+<a name="l00009"></a>00009 <span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
+<a name="l00014"></a>00014 <span class="comment"> * Lesser General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
+<a name="l00017"></a>00017 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2006/10/20 08:06:32 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.1 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> */</span>
+<a name="l00026"></a>00026 
+<a name="l00027"></a>00027  <span class="comment">/****************************************************************</span>
+<a name="l00028"></a>00028 <span class="comment">  *   Dark Frames Data Reduction Parameter Initialization        *</span>
+<a name="l00029"></a>00029 <span class="comment">  ****************************************************************/</span>
+<a name="l00030"></a>00030 <span class="preprocessor">#include <cpl.h></span>    <span class="comment">/* defines parlist structure */</span>
+<a name="l00031"></a>00031 <span class="comment">/*</span>
+<a name="l00032"></a>00032 <span class="comment">#include "sinfo_dfs.h"</span>
+<a name="l00033"></a>00033 <span class="comment">*/</span>
+<a name="l00034"></a>00034 <span class="preprocessor">#include "sinfo_globals.h"</span>
+<a name="l00035"></a>00035 <span class="keywordtype">void</span> sinfo_dark_config_add(cpl_parameterlist *list);
+<a name="l00036"></a>00036 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__dark__ini_8h_source.html b/html/sinfo__dark__ini_8h_source.html
new file mode 100644
index 0000000..e7e9833
--- /dev/null
+++ b/html/sinfo__dark__ini_8h_source.html
@@ -0,0 +1,63 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_dark_ini.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_dark_ini.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name    :   sinfo_dark_ini.h</span>
+<a name="l00022"></a>00022 <span class="comment">   Author       :    Juergen Schreiber</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on   :    Feb 13, 2002</span>
+<a name="l00024"></a>00024 <span class="comment">   Description  :    ini file handling for SPIFFIs sinfo_dark frame handling</span>
+<a name="l00025"></a>00025 <span class="comment"></span>
+<a name="l00026"></a>00026 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00027"></a>00027 <span class="preprocessor">#ifndef SINFO_DARK_INI_H</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_DARK_INI_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00030"></a>00030 <span class="comment">                                Includes</span>
+<a name="l00031"></a>00031 <span class="comment">---------------------------------------------------------------------------*/</span>
+<a name="l00032"></a>00032 <span class="preprocessor">#include "sinfo_fitshead.h"</span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include "sinfo_dark_cfg.h"</span>
+<a name="l00034"></a>00034 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00035"></a>00035 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00036"></a>00036 <span class="comment">                             Function prototypes </span>
+<a name="l00037"></a>00037 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00051"></a>00051 <span class="keywordtype">int</span> 
+<a name="l00052"></a>00052 generateDark_ini_file(
+<a name="l00053"></a>00053         <span class="keywordtype">char</span> * ini_name,
+<a name="l00054"></a>00054         <span class="keywordtype">char</span> * name_i,
+<a name="l00055"></a>00055         <span class="keywordtype">char</span> * name_o
+<a name="l00056"></a>00056 );
+<a name="l00065"></a>00065 dark_config * 
+<a name="l00066"></a>00066 parse_dark_ini_file(<span class="keywordtype">char</span> * ini_name) ;
+<a name="l00067"></a>00067 
+<a name="l00068"></a>00068 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__dark__ini__by__cpl_8c_source.html b/html/sinfo__dark__ini__by__cpl_8c_source.html
new file mode 100644
index 0000000..6f33253
--- /dev/null
+++ b/html/sinfo__dark__ini__by__cpl_8c_source.html
@@ -0,0 +1,259 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_dark_ini_by_cpl.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_dark_ini_by_cpl.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name    :   sinfo_dark_ini_by_cpl.c</span>
+<a name="l00022"></a>00022 <span class="comment">   Author       :   Andrea Modigliani</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on   :   May 18, 2004</span>
+<a name="l00024"></a>00024 <span class="comment">   Description  :   sinfo_dark cpl input file handling for SPIFFI</span>
+<a name="l00025"></a>00025 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00026"></a>00026 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00027"></a>00027 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00028"></a>00028 <span class="preprocessor">#endif</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00030"></a>00030 <span class="comment">                                Includes</span>
+<a name="l00031"></a>00031 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00032"></a>00032 <span class="preprocessor">#include <string.h></span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include "sinfo_dark_ini_by_cpl.h"</span>
+<a name="l00034"></a>00034 <span class="preprocessor">#include "sinfo_raw_types.h"</span>
+<a name="l00035"></a>00035 <span class="preprocessor">#include "sinfo_pro_types.h"</span>
+<a name="l00036"></a>00036 <span class="preprocessor">#include "sinfo_globals.h"</span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include "sinfo_hidden.h"</span>
+<a name="l00038"></a>00038 <span class="preprocessor">#include "sinfo_functions.h"</span>
+<a name="l00039"></a>00039 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00040"></a>00040 <span class="comment">                    Functions private to this module</span>
+<a name="l00041"></a>00041 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00042"></a>00042 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00043"></a>00043 parse_section_frames(dark_config *, cpl_frameset* sof, 
+<a name="l00044"></a>00044                      cpl_frameset** raw, <span class="keywordtype">int</span>* status);
+<a name="l00045"></a>00045 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00046"></a>00046 parse_section_cleanmean(dark_config *, cpl_parameterlist* cpl_cfg);
+<a name="l00047"></a>00047 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00048"></a>00048 parse_section_qclog(dark_config * cfg, cpl_parameterlist * cpl_cfg);
+<a name="l00049"></a>00049 
+<a name="l00050"></a>00050 <span class="keywordtype">void</span> sinfo_detnoise_free(dark_config * cfg);
+<a name="l00051"></a>00051 
+<a name="l00072"></a>00072 dark_config * 
+<a name="l00073"></a>00073 sinfo_parse_cpl_input_dark(cpl_parameterlist * cpl_cfg, 
+<a name="l00074"></a>00074                            cpl_frameset* sof, 
+<a name="l00075"></a>00075                            cpl_frameset** raw)
+<a name="l00076"></a>00076 {
+<a name="l00077"></a>00077  <span class="keywordtype">int</span> status=0;
+<a name="l00078"></a>00078 
+<a name="l00079"></a>00079         dark_config   *       cfg ;
+<a name="l00080"></a>00080 
+<a name="l00081"></a>00081         <span class="comment">/* Removed check on ini_file */</span>
+<a name="l00082"></a>00082         <span class="comment">/* Removed load of ini file */</span>
+<a name="l00083"></a>00083 
+<a name="l00084"></a>00084         cfg = sinfo_dark_cfg_create();
+<a name="l00085"></a>00085 
+<a name="l00086"></a>00086         <span class="comment">/*</span>
+<a name="l00087"></a>00087 <span class="comment">         * Perform sanity checks, fill up the structure with what was</span>
+<a name="l00088"></a>00088 <span class="comment">         * found in the ini file</span>
+<a name="l00089"></a>00089 <span class="comment">         */</span>
+<a name="l00090"></a>00090         parse_section_cleanmean    (cfg, cpl_cfg);
+<a name="l00091"></a>00091         parse_section_qclog    (cfg, cpl_cfg); 
+<a name="l00092"></a>00092         parse_section_frames       (cfg, sof, raw, &status);
+<a name="l00093"></a>00093         <span class="keywordflow">if</span> (status > 0) {
+<a name="l00094"></a>00094                 <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"parsing cpl input"</span>);
+<a name="l00095"></a>00095                 sinfo_dark_cfg_destroy(cfg);
+<a name="l00096"></a>00096                 cfg = NULL ;
+<a name="l00097"></a>00097                 <span class="keywordflow">return</span> NULL ;
+<a name="l00098"></a>00098         }
+<a name="l00099"></a>00099 
+<a name="l00100"></a>00100         <span class="keywordflow">return</span> cfg ;
+<a name="l00101"></a>00101 }
+<a name="l00102"></a>00102 
+<a name="l00113"></a>00113 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00114"></a>00114 parse_section_frames(dark_config * cfg,
+<a name="l00115"></a>00115              cpl_frameset * sof,
+<a name="l00116"></a>00116                      cpl_frameset** raw,
+<a name="l00117"></a>00117                      <span class="keywordtype">int</span>* status)
+<a name="l00118"></a>00118 {
+<a name="l00119"></a>00119 
+<a name="l00120"></a>00120    <span class="keywordtype">int</span>                     i;
+<a name="l00121"></a>00121    <span class="keywordtype">int</span>                   nraw=0;
+<a name="l00122"></a>00122    <span class="keywordtype">int</span>                   nraw_good=0;
+<a name="l00123"></a>00123    cpl_frame* frame=NULL;
+<a name="l00124"></a>00124 
+<a name="l00125"></a>00125    <span class="keywordtype">char</span> spat_res[FILE_NAME_SZ];
+<a name="l00126"></a>00126    <span class="keywordtype">char</span> lamp_status[FILE_NAME_SZ];
+<a name="l00127"></a>00127    <span class="keywordtype">char</span> band[FILE_NAME_SZ];
+<a name="l00128"></a>00128    <span class="keywordtype">int</span> ins_set=0;
+<a name="l00129"></a>00129    sinfo_extract_raw_frames_type(sof,raw,RAW_DARK);
+<a name="l00130"></a>00130 
+<a name="l00131"></a>00131    nraw=cpl_frameset_get_size(*raw);
+<a name="l00132"></a>00132    <span class="keywordflow">if</span> (nraw < 1) {
+<a name="l00133"></a>00133       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Too few (%d) raw frames (%s) present in"</span>
+<a name="l00134"></a>00134             <span class="stringliteral">"frameset!Aborting..."</span>,nraw,RAW_DARK);
+<a name="l00135"></a>00135           (*status)++;
+<a name="l00136"></a>00136           <span class="keywordflow">return</span>;
+<a name="l00137"></a>00137    }
+<a name="l00138"></a>00138 
+<a name="l00139"></a>00139 
+<a name="l00140"></a>00140 
+<a name="l00141"></a>00141    <span class="comment">/* Removed: get "general:infile" read it, check input sinfo_matrix */</span>
+<a name="l00142"></a>00142    <span class="comment">/* Allocate structures to go into the blackboard */</span>
+<a name="l00143"></a>00143    cfg->inFrameList     = cpl_malloc(nraw * <span class="keyword">sizeof</span>(<span class="keywordtype">char</span>*));
+<a name="l00144"></a>00144 
+<a name="l00145"></a>00145 
+<a name="l00146"></a>00146    <span class="comment">/* read input frames */</span>
+<a name="l00147"></a>00147    <span class="keywordflow">for</span> (i=0 ; i<nraw ; i++) {
+<a name="l00148"></a>00148       frame = cpl_frameset_get_frame(*raw,i);
+<a name="l00149"></a>00149       <span class="comment">/* Store file name into framelist */</span>
+<a name="l00150"></a>00150       cfg->inFrameList[i]=cpl_strdup(cpl_frame_get_filename(frame));
+<a name="l00151"></a>00151       nraw_good++;
+<a name="l00152"></a>00152    }
+<a name="l00153"></a>00153 
+<a name="l00154"></a>00154    <span class="keywordflow">if</span>(nraw_good<1) {
+<a name="l00155"></a>00155      <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no good raw frame in input, something wrong!"</span>);
+<a name="l00156"></a>00156      (*status)++;
+<a name="l00157"></a>00157      <span class="keywordflow">return</span>;
+<a name="l00158"></a>00158    }
+<a name="l00159"></a>00159    <span class="comment">/* Copy relevant information into the blackboard */</span>
+<a name="l00160"></a>00160    cfg->nframes         = nraw ;
+<a name="l00161"></a>00161 
+<a name="l00162"></a>00162    strcpy(cfg -> outName, DARK_OUT_FILENAME);
+<a name="l00163"></a>00163   
+<a name="l00164"></a>00164 
+<a name="l00165"></a>00165    frame = cpl_frameset_get_frame(*raw,0);
+<a name="l00166"></a>00166    sinfo_get_spatial_res(frame,spat_res);
+<a name="l00167"></a>00167  
+<a name="l00168"></a>00168    <span class="keywordflow">switch</span>(sinfo_frame_is_on(frame)) 
+<a name="l00169"></a>00169      {
+<a name="l00170"></a>00170    <span class="keywordflow">case</span> 0: 
+<a name="l00171"></a>00171       strcpy(lamp_status,<span class="stringliteral">"on"</span>);
+<a name="l00172"></a>00172       <span class="keywordflow">break</span>;
+<a name="l00173"></a>00173     <span class="keywordflow">case</span> 1: 
+<a name="l00174"></a>00174       strcpy(lamp_status,<span class="stringliteral">"off"</span>);
+<a name="l00175"></a>00175       <span class="keywordflow">break</span>;
+<a name="l00176"></a>00176     <span class="keywordflow">case</span> -1:
+<a name="l00177"></a>00177       strcpy(lamp_status,<span class="stringliteral">"undefined"</span>);
+<a name="l00178"></a>00178       <span class="keywordflow">break</span>;
+<a name="l00179"></a>00179     <span class="keywordflow">default</span>: 
+<a name="l00180"></a>00180       strcpy(lamp_status,<span class="stringliteral">"undefined"</span>);
+<a name="l00181"></a>00181       <span class="keywordflow">break</span>;
+<a name="l00182"></a>00182 
+<a name="l00183"></a>00183 
+<a name="l00184"></a>00184      }
+<a name="l00185"></a>00185 
+<a name="l00186"></a>00186    sinfo_get_band(frame,band);
+<a name="l00187"></a>00187    sinfo_msg(<span class="stringliteral">"Spatial resolution: %s lamp status: %s band: %s \n"</span>,
+<a name="l00188"></a>00188                      spat_res,    lamp_status,    band);
+<a name="l00189"></a>00189 
+<a name="l00190"></a>00190 
+<a name="l00191"></a>00191    sinfo_get_ins_set(band,&ins_set);
+<a name="l00192"></a>00192    return ;
+<a name="l00193"></a>00193 }
+<a name="l00194"></a>00194 
+<a name="l00203"></a>00203 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00204"></a>00204 parse_section_cleanmean(dark_config * cfg, cpl_parameterlist *   cpl_cfg)
+<a name="l00205"></a>00205 {
+<a name="l00206"></a>00206    cpl_parameter *p;  
+<a name="l00207"></a>00207    
+<a name="l00208"></a>00208    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.dark.low_rejection"</span>);
+<a name="l00209"></a>00209    cfg -> lo_reject = cpl_parameter_get_double(p);
+<a name="l00210"></a>00210 
+<a name="l00211"></a>00211    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.dark.high_rejection"</span>);
+<a name="l00212"></a>00212    cfg -> hi_reject = cpl_parameter_get_double(p);
+<a name="l00213"></a>00213 
+<a name="l00214"></a>00214 }
+<a name="l00215"></a>00215 
+<a name="l00223"></a>00223 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00224"></a>00224 parse_section_qclog(dark_config * cfg, cpl_parameterlist *   cpl_cfg)
+<a name="l00225"></a>00225 {
+<a name="l00226"></a>00226    cpl_parameter *p;  
+<a name="l00227"></a>00227    
+<a name="l00228"></a>00228    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.dark.qc_ron_xmin"</span>);
+<a name="l00229"></a>00229    cfg -> qc_ron_xmin = cpl_parameter_get_int(p);
+<a name="l00230"></a>00230    
+<a name="l00231"></a>00231    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.dark.qc_ron_xmax"</span>);
+<a name="l00232"></a>00232    cfg -> qc_ron_xmax = cpl_parameter_get_int(p);
+<a name="l00233"></a>00233 
+<a name="l00234"></a>00234    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.dark.qc_ron_ymin"</span>);
+<a name="l00235"></a>00235    cfg -> qc_ron_ymin = cpl_parameter_get_int(p);
+<a name="l00236"></a>00236 
+<a name="l00237"></a>00237    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.dark.qc_ron_ymax"</span>);
+<a name="l00238"></a>00238    cfg -> qc_ron_ymax = cpl_parameter_get_int(p);
+<a name="l00239"></a>00239 
+<a name="l00240"></a>00240    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.dark.qc_ron_hsize"</span>);
+<a name="l00241"></a>00241    cfg -> qc_ron_hsize = cpl_parameter_get_int(p);
+<a name="l00242"></a>00242    
+<a name="l00243"></a>00243    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.dark.qc_ron_nsamp"</span>);
+<a name="l00244"></a>00244    cfg -> qc_ron_nsamp = cpl_parameter_get_int(p);
+<a name="l00245"></a>00245 
+<a name="l00246"></a>00246 
+<a name="l00247"></a>00247 
+<a name="l00248"></a>00248    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.dark.qc_fpn_xmin"</span>);
+<a name="l00249"></a>00249    cfg -> qc_fpn_xmin = cpl_parameter_get_int(p);
+<a name="l00250"></a>00250    
+<a name="l00251"></a>00251    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.dark.qc_fpn_xmax"</span>);
+<a name="l00252"></a>00252    cfg -> qc_fpn_xmax = cpl_parameter_get_int(p);
+<a name="l00253"></a>00253 
+<a name="l00254"></a>00254    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.dark.qc_fpn_ymin"</span>);
+<a name="l00255"></a>00255    cfg -> qc_fpn_ymin = cpl_parameter_get_int(p);
+<a name="l00256"></a>00256 
+<a name="l00257"></a>00257    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.dark.qc_fpn_ymax"</span>);
+<a name="l00258"></a>00258    cfg -> qc_fpn_ymax = cpl_parameter_get_int(p);
+<a name="l00259"></a>00259 
+<a name="l00260"></a>00260    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.dark.qc_fpn_hsize"</span>);
+<a name="l00261"></a>00261    cfg -> qc_fpn_hsize = cpl_parameter_get_int(p);
+<a name="l00262"></a>00262    
+<a name="l00263"></a>00263    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.dark.qc_fpn_nsamp"</span>);
+<a name="l00264"></a>00264    cfg -> qc_fpn_nsamp = cpl_parameter_get_int(p);
+<a name="l00265"></a>00265 
+<a name="l00266"></a>00266    
+<a name="l00267"></a>00267 }
+<a name="l00268"></a>00268 
+<a name="l00275"></a>00275 <span class="keywordtype">void</span>
+<a name="l00276"></a>00276 sinfo_dark_free(dark_config ** cfg)
+<a name="l00277"></a>00277 {  
+<a name="l00278"></a>00278   <span class="keywordtype">int</span> i=0;
+<a name="l00279"></a>00279  
+<a name="l00280"></a>00280   <span class="keywordflow">if</span>((*cfg) != NULL) {
+<a name="l00281"></a>00281     <span class="keywordflow">for</span>(i=0;i<(*cfg)->nframes;i++) {
+<a name="l00282"></a>00282       <span class="keywordflow">if</span>((*cfg)->inFrameList[i] != NULL) {
+<a name="l00283"></a>00283     cpl_free((*cfg)->inFrameList[i]);
+<a name="l00284"></a>00284     (*cfg)->inFrameList[i]=NULL;
+<a name="l00285"></a>00285       }
+<a name="l00286"></a>00286     }
+<a name="l00287"></a>00287     cpl_free((*cfg)->inFrameList);
+<a name="l00288"></a>00288     (*cfg)->inFrameList=NULL;
+<a name="l00289"></a>00289     sinfo_dark_cfg_destroy((*cfg));
+<a name="l00290"></a>00290     *cfg = NULL;
+<a name="l00291"></a>00291   }
+<a name="l00292"></a>00292   <span class="keywordflow">return</span>;
+<a name="l00293"></a>00293 
+<a name="l00294"></a>00294 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__dark__ini__by__cpl_8h_source.html b/html/sinfo__dark__ini__by__cpl_8h_source.html
new file mode 100644
index 0000000..9edb6e1
--- /dev/null
+++ b/html/sinfo__dark__ini__by__cpl_8h_source.html
@@ -0,0 +1,63 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_dark_ini_by_cpl.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_dark_ini_by_cpl.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name    :   sinfo_dark_ini_by_cpl.h</span>
+<a name="l00022"></a>00022 <span class="comment">   Author       :   Andrea Modigliani</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on   :   May 18, 2004</span>
+<a name="l00024"></a>00024 <span class="comment">   Description  :   cpl input file handling for SINFONI </span>
+<a name="l00025"></a>00025 <span class="comment">                    dark frame handling</span>
+<a name="l00026"></a>00026 <span class="comment"></span>
+<a name="l00027"></a>00027 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00028"></a>00028 <span class="preprocessor">#ifndef SINFO_DARK_INI_BY_CPL_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_DARK_INI_BY_CPL_H</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00031"></a>00031 <span class="comment">                                Includes</span>
+<a name="l00032"></a>00032 <span class="comment">---------------------------------------------------------------------------*/</span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00034"></a>00034 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00035"></a>00035 <span class="preprocessor">#include "sinfo_dark_cfg.h"</span>
+<a name="l00036"></a>00036 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00037"></a>00037 <span class="comment">                             Function prototypes </span>
+<a name="l00038"></a>00038 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00051"></a>00051 dark_config * 
+<a name="l00052"></a>00052 sinfo_parse_cpl_input_dark(cpl_parameterlist * cpl_cfg, 
+<a name="l00053"></a>00053                            cpl_frameset* sof, 
+<a name="l00054"></a>00054                cpl_frameset** raw);
+<a name="l00055"></a>00055 
+<a name="l00062"></a>00062 <span class="keywordtype">void</span> 
+<a name="l00063"></a>00063 sinfo_dark_free(dark_config ** cfg);
+<a name="l00064"></a>00064 
+<a name="l00065"></a>00065 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__define__opt_8h_source.html b/html/sinfo__define__opt_8h_source.html
new file mode 100644
index 0000000..8eb8737
--- /dev/null
+++ b/html/sinfo__define__opt_8h_source.html
@@ -0,0 +1,45 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_define_opt.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_define_opt.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="preprocessor">#ifndef SINFO_DEFINE_OPT_H</span>
+<a name="l00020"></a>00020 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_DEFINE_OPT_H</span>
+<a name="l00021"></a>00021 <span class="preprocessor"></span><span class="preprocessor">#define OPT_FILE        1001</span>
+<a name="l00022"></a>00022 <span class="preprocessor"></span><span class="preprocessor">#define OPT_GENERATE            1002</span>
+<a name="l00023"></a>00023 <span class="preprocessor"></span><span class="preprocessor">#define OPT_RB            1003</span>
+<a name="l00024"></a>00024 <span class="preprocessor"></span><span class="preprocessor">#define OPT_SORT        1004</span>
+<a name="l00025"></a>00025 <span class="preprocessor"></span><span class="preprocessor">#define OPT_IN            2000</span>
+<a name="l00026"></a>00026 <span class="preprocessor"></span><span class="preprocessor">#define OPT_OUT            2001</span>
+<a name="l00027"></a>00027 <span class="preprocessor"></span><span class="preprocessor">#define OPT_CALIB        2002</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="preprocessor">#define OPT_CIN         2003</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__detlin_8c_source.html b/html/sinfo__detlin_8c_source.html
new file mode 100644
index 0000000..dc4658b
--- /dev/null
+++ b/html/sinfo__detlin_8c_source.html
@@ -0,0 +1,1126 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_detlin.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_detlin.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*******************************************************************************</span>
+<a name="l00020"></a>00020 <span class="comment">* E.S.O. - VLT project</span>
+<a name="l00021"></a>00021 <span class="comment">*</span>
+<a name="l00022"></a>00022 <span class="comment">*</span>
+<a name="l00023"></a>00023 <span class="comment">*</span>
+<a name="l00024"></a>00024 <span class="comment">* who       when      what</span>
+<a name="l00025"></a>00025 <span class="comment">* --------  --------  ----------------------------------------------</span>
+<a name="l00026"></a>00026 <span class="comment">* amodigli  18/04/02  created</span>
+<a name="l00027"></a>00027 <span class="comment">*/</span>
+<a name="l00028"></a>00028 
+<a name="l00029"></a>00029 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00031"></a>00031 <span class="preprocessor">#endif</span>
+<a name="l00032"></a>00032 <span class="preprocessor"></span><span class="preprocessor">#define POSIX_SOURCE 1</span>
+<a name="l00033"></a>00033 <span class="preprocessor"></span><span class="preprocessor">#include "sinfo_vltPort.h"</span>
+<a name="l00034"></a>00034 
+<a name="l00035"></a>00035 <span class="comment">/*</span>
+<a name="l00036"></a>00036 <span class="comment"> * System Headers</span>
+<a name="l00037"></a>00037 <span class="comment"> */</span>
+<a name="l00038"></a>00038 
+<a name="l00039"></a>00039 <span class="comment">/*</span>
+<a name="l00040"></a>00040 <span class="comment"> * Local Headers</span>
+<a name="l00041"></a>00041 <span class="comment"> */</span>
+<a name="l00042"></a>00042 
+<a name="l00043"></a>00043 <span class="preprocessor">#include "sinfo_detlin.h"</span>
+<a name="l00044"></a>00044 <span class="preprocessor">#include "sinfo_recipes.h"</span>
+<a name="l00045"></a>00045 <span class="preprocessor">#include "sinfo_fit_curve.h"</span>
+<a name="l00046"></a>00046 
+<a name="l00054"></a>00054 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00055"></a>00055 <span class="comment"> *                            Function codes</span>
+<a name="l00056"></a>00056 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00057"></a>00057 
+<a name="l00079"></a>00079 cpl_imagelist * 
+<a name="l00080"></a>00080 sinfo_new_fit_intensity_course(cpl_imagelist * flatStack,
+<a name="l00081"></a>00081                               <span class="keywordtype">int</span>       order,
+<a name="l00082"></a>00082                               <span class="keywordtype">float</span>     loReject,
+<a name="l00083"></a>00083                               <span class="keywordtype">float</span>     hiReject )
+<a name="l00084"></a>00084 {
+<a name="l00085"></a>00085     cpl_imagelist * ret_iml ;
+<a name="l00086"></a>00086     dpoint  * points ;
+<a name="l00087"></a>00087     <span class="keywordtype">int</span>       i, z ;
+<a name="l00088"></a>00088     <span class="keywordtype">double</span> * coeffs ;
+<a name="l00089"></a>00089     Stats  ** stats=NULL ;
+<a name="l00090"></a>00090     <span class="keywordtype">int</span> sx;
+<a name="l00091"></a>00091     <span class="keywordtype">int</span> sy;
+<a name="l00092"></a>00092     <span class="keywordtype">int</span> sz;
+<a name="l00093"></a>00093     <span class="keywordtype">float</span>* psrcdata;
+<a name="l00094"></a>00094     <span class="keywordtype">float</span>* presdata;
+<a name="l00095"></a>00095     cpl_image* img_tmp=NULL;
+<a name="l00096"></a>00096     sx=cpl_image_get_size_x(cpl_imagelist_get(flatStack,0));
+<a name="l00097"></a>00097     sy=cpl_image_get_size_y(cpl_imagelist_get(flatStack,0));
+<a name="l00098"></a>00098     sz=cpl_imagelist_get_size(flatStack);
+<a name="l00099"></a>00099 
+<a name="l00100"></a>00100     stats=(Stats**) cpl_calloc(sz,<span class="keyword">sizeof</span>(Stats*)) ;
+<a name="l00101"></a>00101   
+<a name="l00102"></a>00102     <span class="keywordflow">if</span> ( NULL == flatStack )
+<a name="l00103"></a>00103     {
+<a name="l00104"></a>00104         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no input cube given!"</span>) ;
+<a name="l00105"></a>00105         <span class="keywordflow">return</span> NULL ;
+<a name="l00106"></a>00106     }
+<a name="l00107"></a>00107     <span class="keywordflow">if</span> ( order <= 0 )
+<a name="l00108"></a>00108     {
+<a name="l00109"></a>00109         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"wrong order of polynomial given!"</span>) ;
+<a name="l00110"></a>00110         <span class="keywordflow">return</span> NULL ;
+<a name="l00111"></a>00111     }
+<a name="l00112"></a>00112     <span class="comment">/* allocate memory for returned cube */</span>
+<a name="l00113"></a>00113     ret_iml = cpl_imagelist_new();
+<a name="l00114"></a>00114     <span class="keywordflow">for</span> ( z = 0 ; z < order+1 ; z++ )
+<a name="l00115"></a>00115     {
+<a name="l00116"></a>00116       img_tmp=cpl_image_new(sx,sy,CPL_TYPE_FLOAT);
+<a name="l00117"></a>00117       cpl_imagelist_set(ret_iml,img_tmp,z);
+<a name="l00118"></a>00118     }
+<a name="l00119"></a>00119 
+<a name="l00120"></a>00120     <span class="keywordflow">for</span> ( z = 0 ; z < sz ; z++ )
+<a name="l00121"></a>00121     {
+<a name="l00122"></a>00122       stats[z]=
+<a name="l00123"></a>00123        sinfo_new_image_stats_on_rectangle(cpl_imagelist_get(flatStack,z), 
+<a name="l00124"></a>00124                                                 loReject, 
+<a name="l00125"></a>00125                                                 hiReject, 
+<a name="l00126"></a>00126                                                 0, 
+<a name="l00127"></a>00127                                                 0, 
+<a name="l00128"></a>00128                                                 sx-1, 
+<a name="l00129"></a>00129                                                 sy-1) ;
+<a name="l00130"></a>00130         <span class="keywordflow">if</span> ( stats[z] == NULL )
+<a name="l00131"></a>00131         {
+<a name="l00132"></a>00132             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"could not compute image statistics "</span>
+<a name="l00133"></a>00133                             <span class="stringliteral">"in plane: %d"</span>, z) ;
+<a name="l00134"></a>00134             cpl_imagelist_delete(ret_iml) ;
+<a name="l00135"></a>00135             <span class="keywordflow">return</span> NULL ;
+<a name="l00136"></a>00136         }
+<a name="l00137"></a>00137     }
+<a name="l00138"></a>00138 
+<a name="l00139"></a>00139     <span class="comment">/* go through the image plane and store the spectra in a double </span>
+<a name="l00140"></a>00140 <span class="comment">       points data structure */</span>
+<a name="l00141"></a>00141     
+<a name="l00142"></a>00142     <span class="keywordflow">for</span> ( i = 0 ; i < sx*sy ; i++ )
+<a name="l00143"></a>00143     {
+<a name="l00144"></a>00144       <span class="comment">/* allocate dpoint object */</span>
+<a name="l00145"></a>00145       <span class="keywordflow">if</span> ( NULL == ( points = (dpoint*) cpl_calloc(sz, <span class="keyword">sizeof</span>(dpoint)) ) )
+<a name="l00146"></a>00146     {
+<a name="l00147"></a>00147       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"could not allocate memory!\n"</span>) ;
+<a name="l00148"></a>00148       cpl_imagelist_delete(ret_iml) ;
+<a name="l00149"></a>00149       <span class="keywordflow">return</span> NULL ;
+<a name="l00150"></a>00150     }
+<a name="l00151"></a>00151 
+<a name="l00152"></a>00152       <span class="keywordflow">for</span> ( z = 0 ; z < sz ; z++ )
+<a name="l00153"></a>00153       {
+<a name="l00154"></a>00154       <span class="keywordflow">if</span>(NULL==(img_tmp = cpl_imagelist_get(flatStack,z))) {
+<a name="l00155"></a>00155         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"could not get image!"</span>);
+<a name="l00156"></a>00156           cpl_imagelist_delete(ret_iml) ;
+<a name="l00157"></a>00157             <span class="keywordflow">return</span> NULL;
+<a name="l00158"></a>00158       } <span class="keywordflow">else</span> {
+<a name="l00159"></a>00159         psrcdata=cpl_image_get_data_float(img_tmp);
+<a name="l00160"></a>00160         points[z].x = (double)stats[z]->cleanmean ;
+<a name="l00161"></a>00161         points[z].y = (double)psrcdata[i] ;
+<a name="l00162"></a>00162       }
+<a name="l00163"></a>00163       }
+<a name="l00164"></a>00164 
+<a name="l00165"></a>00165 
+<a name="l00166"></a>00166       <span class="keywordflow">if</span> ( NULL == ( coeffs = sinfo_fit_1d_poly(order, points, sz, NULL) ) )
+<a name="l00167"></a>00167       {
+<a name="l00168"></a>00168       <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"could not fit spectrum of pixel: %d\n"</span>, i) ;
+<a name="l00169"></a>00169       <span class="keywordflow">for</span> ( z = 0 ; z < order+1 ; z++ )
+<a name="l00170"></a>00170         {
+<a name="l00171"></a>00171           presdata=cpl_image_get_data_float(cpl_imagelist_get(ret_iml,z));
+<a name="l00172"></a>00172           presdata[i] = ZERO ;
+<a name="l00173"></a>00173         }
+<a name="l00174"></a>00174       }
+<a name="l00175"></a>00175       <span class="keywordflow">else</span>
+<a name="l00176"></a>00176       {
+<a name="l00177"></a>00177     <span class="keywordflow">for</span> ( z = 0 ; z < order+1 ; z++ )
+<a name="l00178"></a>00178         {
+<a name="l00179"></a>00179           <span class="keywordflow">if</span>(NULL==(img_tmp = cpl_imagelist_get(ret_iml,z))) {
+<a name="l00180"></a>00180         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"could not get image!"</span>);
+<a name="l00181"></a>00181         cpl_imagelist_delete(ret_iml) ;
+<a name="l00182"></a>00182         <span class="keywordflow">return</span> NULL;
+<a name="l00183"></a>00183           } <span class="keywordflow">else</span> {
+<a name="l00184"></a>00184         presdata=cpl_image_get_data_float(img_tmp);
+<a name="l00185"></a>00185         presdata[i] = coeffs[z] ;
+<a name="l00186"></a>00186           }
+<a name="l00187"></a>00187     }
+<a name="l00188"></a>00188       }
+<a name="l00189"></a>00189       cpl_free(points) ;
+<a name="l00190"></a>00190       cpl_free(coeffs) ;
+<a name="l00191"></a>00191     }
+<a name="l00192"></a>00192 
+<a name="l00193"></a>00193     <span class="keywordflow">for</span> ( z = 0 ; z < sz ; z++ )
+<a name="l00194"></a>00194     {
+<a name="l00195"></a>00195         cpl_free (stats[z]) ;
+<a name="l00196"></a>00196     }
+<a name="l00197"></a>00197     cpl_free(stats);
+<a name="l00198"></a>00198     <span class="keywordflow">return</span> ret_iml ;
+<a name="l00199"></a>00199 }
+<a name="l00200"></a>00200 
+<a name="l00201"></a>00201 
+<a name="l00225"></a>00225 cpl_image * sinfo_new_search_bad_pixels( cpl_imagelist *  coeffs,
+<a name="l00226"></a>00226                             <span class="keywordtype">double</span>     threshSigmaFactor,
+<a name="l00227"></a>00227                             <span class="keywordtype">double</span>     nonlinearThresh,
+<a name="l00228"></a>00228                             <span class="keywordtype">float</span>      loReject,
+<a name="l00229"></a>00229                             <span class="keywordtype">float</span>      hiReject )
+<a name="l00230"></a>00230 {
+<a name="l00231"></a>00231      <span class="keywordtype">int</span> i, z ;
+<a name="l00232"></a>00232     Stats * stats ;
+<a name="l00233"></a>00233     <span class="keywordtype">int</span> sx=0;
+<a name="l00234"></a>00234     <span class="keywordtype">int</span> sy=0;
+<a name="l00235"></a>00235     <span class="keywordtype">int</span> sz=0;
+<a name="l00236"></a>00236 
+<a name="l00237"></a>00237     cpl_image * img_res ;
+<a name="l00238"></a>00238     cpl_image* img_src=NULL;
+<a name="l00239"></a>00239 
+<a name="l00240"></a>00240     <span class="keywordtype">float</span>* psrcdata=NULL;
+<a name="l00241"></a>00241     <span class="keywordtype">float</span>* presdata=NULL;
+<a name="l00242"></a>00242 
+<a name="l00243"></a>00243     <span class="keywordflow">if</span> ( NULL == coeffs )
+<a name="l00244"></a>00244     {
+<a name="l00245"></a>00245         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no input cube given!\n"</span>) ;
+<a name="l00246"></a>00246         <span class="keywordflow">return</span> NULL ;
+<a name="l00247"></a>00247     }
+<a name="l00248"></a>00248     <span class="keywordflow">if</span> ( threshSigmaFactor <= 0. )
+<a name="l00249"></a>00249     {
+<a name="l00250"></a>00250         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"wrong sigma factor given, 0 or negativ!\n"</span>) ;
+<a name="l00251"></a>00251         <span class="keywordflow">return</span> NULL ;
+<a name="l00252"></a>00252     }
+<a name="l00253"></a>00253     <span class="keywordflow">if</span> ( nonlinearThresh <= 0. )
+<a name="l00254"></a>00254     {
+<a name="l00255"></a>00255         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"wrong nonlinear threshold value given, "</span>
+<a name="l00256"></a>00256                         <span class="stringliteral">"0 or negative!"</span>) ;
+<a name="l00257"></a>00257         <span class="keywordflow">return</span> NULL ;
+<a name="l00258"></a>00258     }
+<a name="l00259"></a>00259 
+<a name="l00260"></a>00260     sz=cpl_imagelist_get_size(coeffs);
+<a name="l00261"></a>00261 
+<a name="l00262"></a>00262     <span class="keywordflow">if</span> ( sz <= 1 )
+<a name="l00263"></a>00263     {
+<a name="l00264"></a>00264         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no cube given, only one plane!\n"</span>) ;
+<a name="l00265"></a>00265         <span class="keywordflow">return</span> NULL ;
+<a name="l00266"></a>00266     }
+<a name="l00267"></a>00267 
+<a name="l00268"></a>00268     <span class="comment">/* Note that we refer to image #1! */</span>
+<a name="l00269"></a>00269     img_src=cpl_imagelist_get(coeffs,1);
+<a name="l00270"></a>00270     sx=cpl_image_get_size_x(img_src);
+<a name="l00271"></a>00271     sy=cpl_image_get_size_y(img_src);
+<a name="l00272"></a>00272 
+<a name="l00273"></a>00273     <span class="comment">/* allocate memory for return image */</span>
+<a name="l00274"></a>00274     <span class="keywordflow">if</span> ( NULL == (img_res = cpl_image_new(sx, sy,CPL_TYPE_FLOAT)) )
+<a name="l00275"></a>00275     {
+<a name="l00276"></a>00276         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"could not allocate memory!\n"</span>) ;
+<a name="l00277"></a>00277         <span class="keywordflow">return</span> NULL ;
+<a name="l00278"></a>00278     }
+<a name="l00279"></a>00279 
+<a name="l00280"></a>00280 
+<a name="l00281"></a>00281     <span class="comment">/* first test the sensitivity deviations of each pixel */</span>
+<a name="l00282"></a>00282     <span class="comment">/* determine the clean mean and clean standard deviation </span>
+<a name="l00283"></a>00283 <span class="comment">       in the whole image frame */</span>
+<a name="l00284"></a>00284    
+<a name="l00285"></a>00285     stats = sinfo_new_image_stats_on_rectangle(img_src, 
+<a name="l00286"></a>00286                                                loReject, 
+<a name="l00287"></a>00287                                                hiReject, 0, 0, 
+<a name="l00288"></a>00288                                                sx-1, sy-1) ;
+<a name="l00289"></a>00289     <span class="keywordflow">if</span> ( NULL == stats )
+<a name="l00290"></a>00290     {
+<a name="l00291"></a>00291         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"could not determine image statistics!\n"</span>) ;
+<a name="l00292"></a>00292         cpl_image_delete(img_res) ;
+<a name="l00293"></a>00293         <span class="keywordflow">return</span> NULL ;
+<a name="l00294"></a>00294     }
+<a name="l00295"></a>00295     
+<a name="l00296"></a>00296 
+<a name="l00297"></a>00297     psrcdata=cpl_image_get_data_float(img_src);
+<a name="l00298"></a>00298     presdata=cpl_image_get_data_float(img_res);
+<a name="l00299"></a>00299     <span class="keywordflow">for</span> ( i = 0 ; i < (int) sx*sy ; i++ )
+<a name="l00300"></a>00300     {
+<a name="l00301"></a>00301 
+<a name="l00302"></a>00302         <span class="keywordflow">if</span> ( isnan(psrcdata[i]) )
+<a name="l00303"></a>00303         {
+<a name="l00304"></a>00304             presdata[i] = 0. ;
+<a name="l00305"></a>00305         }
+<a name="l00306"></a>00306         <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( stats->cleanmean - psrcdata[i] > 
+<a name="l00307"></a>00307                   threshSigmaFactor*stats->cleanstdev )
+<a name="l00308"></a>00308         {
+<a name="l00309"></a>00309             presdata[i] = 0. ;
+<a name="l00310"></a>00310         }
+<a name="l00311"></a>00311         <span class="keywordflow">else</span>
+<a name="l00312"></a>00312         {
+<a name="l00313"></a>00313            presdata[i] = 1. ;
+<a name="l00314"></a>00314         }
+<a name="l00315"></a>00315     }
+<a name="l00316"></a>00316     cpl_free(stats) ;
+<a name="l00317"></a>00317 
+<a name="l00318"></a>00318 
+<a name="l00319"></a>00319     <span class="comment">/* -----------------------------------------------------</span>
+<a name="l00320"></a>00320 <span class="comment">     * now test additionally the non-linearity if available. </span>
+<a name="l00321"></a>00321 <span class="comment">     * if a strong non-linearity occurs for pixels which are </span>
+<a name="l00322"></a>00322 <span class="comment">     * declared "good" so far (normal linear coefficients)</span>
+<a name="l00323"></a>00323 <span class="comment">     * these pixels will be declared bad.    </span>
+<a name="l00324"></a>00324 <span class="comment">     */</span>
+<a name="l00325"></a>00325     <span class="keywordflow">if</span> (sz > 1) 
+<a name="l00326"></a>00326     {
+<a name="l00327"></a>00327         <span class="keywordflow">for</span> ( z = 2 ; z < sz ; z++ )
+<a name="l00328"></a>00328         {
+<a name="l00329"></a>00329       img_src=cpl_imagelist_get(coeffs,z);
+<a name="l00330"></a>00330           sx=cpl_image_get_size_x(img_src);
+<a name="l00331"></a>00331           sy=cpl_image_get_size_y(img_src);
+<a name="l00332"></a>00332 
+<a name="l00333"></a>00333           psrcdata=cpl_image_get_data_float(img_src);
+<a name="l00334"></a>00334             stats = sinfo_new_image_stats_on_rectangle(img_src, loReject, 
+<a name="l00335"></a>00335                                                  hiReject, 0, 0, sx-1, sy-1) ;
+<a name="l00336"></a>00336             <span class="keywordflow">if</span> ( NULL == stats )
+<a name="l00337"></a>00337             {
+<a name="l00338"></a>00338                 <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"could not determine image statistics!\n"</span>) ;
+<a name="l00339"></a>00339                 cpl_image_delete(img_res) ;
+<a name="l00340"></a>00340                 <span class="keywordflow">return</span> NULL ;
+<a name="l00341"></a>00341             }
+<a name="l00342"></a>00342           presdata=cpl_image_get_data_float(img_res);
+<a name="l00343"></a>00343             <span class="keywordflow">for</span> ( i = 0 ; i < (int) sx*sy ; i++ )
+<a name="l00344"></a>00344             {
+<a name="l00345"></a>00345                 <span class="keywordflow">if</span> ( presdata[i] == 1. && 
+<a name="l00346"></a>00346                      (fabs(psrcdata[i] - stats->cleanmean) > 
+<a name="l00347"></a>00347                                      threshSigmaFactor*stats->cleanstdev ||
+<a name="l00348"></a>00348               fabs(psrcdata[i]) > nonlinearThresh ) ) 
+<a name="l00349"></a>00349                 {
+<a name="l00350"></a>00350                     presdata[i] = 0. ;
+<a name="l00351"></a>00351                 }
+<a name="l00352"></a>00352             }
+<a name="l00353"></a>00353             cpl_free(stats) ;
+<a name="l00354"></a>00354         }
+<a name="l00355"></a>00355     }
+<a name="l00356"></a>00356 
+<a name="l00357"></a>00357     <span class="keywordflow">return</span> img_res ;
+<a name="l00358"></a>00358 }
+<a name="l00359"></a>00359 
+<a name="l00360"></a>00360 
+<a name="l00361"></a>00361 
+<a name="l00362"></a>00362 
+<a name="l00383"></a>00383 cpl_image * sinfo_new_search_bad_pixels_via_noise(cpl_imagelist *  darks,
+<a name="l00384"></a>00384                                     <span class="keywordtype">float</span>      threshSigmaFactor,
+<a name="l00385"></a>00385                                     <span class="keywordtype">float</span>      loReject,
+<a name="l00386"></a>00386                                     <span class="keywordtype">float</span>      hiReject )
+<a name="l00387"></a>00387 {
+<a name="l00388"></a>00388     cpl_image * bp_map ;
+<a name="l00389"></a>00389     <span class="keywordtype">int</span>        z, n, i ;
+<a name="l00390"></a>00390     <span class="keywordtype">int</span>        lx, ly ;
+<a name="l00391"></a>00391     <span class="keywordtype">int</span>        row, col ;
+<a name="l00392"></a>00392     <span class="keywordtype">int</span>        low_n, high_n ;
+<a name="l00393"></a>00393     <span class="keywordtype">float</span>    * spectrum ;
+<a name="l00394"></a>00394     <span class="keywordtype">double</span>     pix_sum ;
+<a name="l00395"></a>00395     <span class="keywordtype">double</span>     sqr_sum ;
+<a name="l00396"></a>00396     Stats    * stats ;
+<a name="l00397"></a>00397     cpl_image* img_src=NULL;
+<a name="l00398"></a>00398 
+<a name="l00399"></a>00399     <span class="keywordtype">float</span>* psrcdata=NULL;
+<a name="l00400"></a>00400     <span class="keywordtype">float</span>* pbpdata=NULL;
+<a name="l00401"></a>00401 
+<a name="l00402"></a>00402     <span class="keywordtype">int</span> lz=0;
+<a name="l00403"></a>00403     
+<a name="l00404"></a>00404     <span class="keywordflow">if</span> ( NULL == darks )
+<a name="l00405"></a>00405     {
+<a name="l00406"></a>00406         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no input cube given!\n"</span>) ;
+<a name="l00407"></a>00407         <span class="keywordflow">return</span> NULL ;
+<a name="l00408"></a>00408     }
+<a name="l00409"></a>00409 
+<a name="l00410"></a>00410     <span class="keywordflow">if</span> ( threshSigmaFactor <= 0. )
+<a name="l00411"></a>00411     {
+<a name="l00412"></a>00412         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"factor is smaller or equal zero!\n"</span>) ;
+<a name="l00413"></a>00413         <span class="keywordflow">return</span> NULL ;
+<a name="l00414"></a>00414     }
+<a name="l00415"></a>00415     <span class="keywordflow">if</span> ( loReject < 0. || hiReject < 0. || (loReject + hiReject) >= 100.  )
+<a name="l00416"></a>00416     {
+<a name="l00417"></a>00417         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"wrong reject percentage values!\n"</span>) ;
+<a name="l00418"></a>00418         <span class="keywordflow">return</span> NULL ;
+<a name="l00419"></a>00419     }
+<a name="l00420"></a>00420 
+<a name="l00421"></a>00421     lz=cpl_imagelist_get_size(darks);
+<a name="l00422"></a>00422     <span class="keywordflow">if</span> ( lz < 1 )
+<a name="l00423"></a>00423     {
+<a name="l00424"></a>00424         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"not enough dark frames given for good statistics!"</span>) ;
+<a name="l00425"></a>00425         <span class="keywordflow">return</span> NULL ;
+<a name="l00426"></a>00426     }
+<a name="l00427"></a>00427     img_src=cpl_imagelist_get(darks,0);
+<a name="l00428"></a>00428     
+<a name="l00429"></a>00429     lx = cpl_image_get_size_x(img_src) ;
+<a name="l00430"></a>00430     ly = cpl_image_get_size_y(img_src) ;
+<a name="l00431"></a>00431   
+<a name="l00432"></a>00432     low_n  = (int)(loReject/100. *(<span class="keywordtype">float</span>)lz) ;
+<a name="l00433"></a>00433     high_n = (int)(hiReject/100. *(<span class="keywordtype">float</span>)lz) ;
+<a name="l00434"></a>00434     <span class="keywordflow">if</span> (NULL == (bp_map = cpl_image_new (lx, ly,CPL_TYPE_FLOAT) ) )
+<a name="l00435"></a>00435     {
+<a name="l00436"></a>00436         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"could not allocate new memory!\n"</span>) ;
+<a name="l00437"></a>00437         <span class="keywordflow">return</span> NULL ;
+<a name="l00438"></a>00438     }
+<a name="l00439"></a>00439     pbpdata=cpl_image_get_data(bp_map);
+<a name="l00440"></a>00440     <span class="keywordflow">if</span> (NULL == (spectrum = (<span class="keywordtype">float</span>*) cpl_calloc(lz, <span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ) )
+<a name="l00441"></a>00441     {
+<a name="l00442"></a>00442         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"could not allocate new memory!\n"</span>) ;
+<a name="l00443"></a>00443         <span class="keywordflow">return</span> NULL ;
+<a name="l00444"></a>00444     }
+<a name="l00445"></a>00445     <span class="keywordflow">for</span> ( row = 0 ; row < ly ; row++ ) {
+<a name="l00446"></a>00446 
+<a name="l00447"></a>00447       <span class="keywordflow">for</span> ( col = 0 ; col < lx ; col++ ) {
+<a name="l00448"></a>00448 
+<a name="l00449"></a>00449     <span class="keywordflow">for</span> ( z = 0 ; z < lz ; z++ ) {
+<a name="l00450"></a>00450       img_src=cpl_imagelist_get(darks,z);
+<a name="l00451"></a>00451       psrcdata=cpl_image_get_data(img_src);
+<a name="l00452"></a>00452       spectrum[z] = psrcdata[col+lx*row] ;
+<a name="l00453"></a>00453     }
+<a name="l00454"></a>00454     sinfo_pixel_qsort(spectrum, lz) ;
+<a name="l00455"></a>00455     n = 0  ;
+<a name="l00456"></a>00456     pix_sum = 0.; 
+<a name="l00457"></a>00457     sqr_sum = 0.; 
+<a name="l00458"></a>00458     <span class="keywordflow">for</span> ( i = low_n ; i < lz - high_n ; i++ ) {
+<a name="l00459"></a>00459       pix_sum += (double)spectrum[i] ;
+<a name="l00460"></a>00460       sqr_sum += ((double)spectrum[i]*(<span class="keywordtype">double</span>)spectrum[i]) ;
+<a name="l00461"></a>00461       n++ ;
+<a name="l00462"></a>00462     }
+<a name="l00463"></a>00463         <span class="comment">/* compute the noise in each pixel */</span>
+<a name="l00464"></a>00464     pix_sum /= (double)n ;
+<a name="l00465"></a>00465     sqr_sum /= (double)n ;
+<a name="l00466"></a>00466 
+<a name="l00467"></a>00467         pbpdata[col+lx*row] = (float)sqrt(sqr_sum - pix_sum*pix_sum) ;
+<a name="l00468"></a>00468       }
+<a name="l00469"></a>00469     }
+<a name="l00470"></a>00470     cpl_free(spectrum) ;
+<a name="l00471"></a>00471     <span class="keywordflow">if</span> ( NULL == (stats = sinfo_new_image_stats_on_rectangle (bp_map, loReject, 
+<a name="l00472"></a>00472                                        hiReject, 200, 200, 800, 800) ) )
+<a name="l00473"></a>00473     {
+<a name="l00474"></a>00474         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"could not get image statistics!\n"</span>) ;
+<a name="l00475"></a>00475         cpl_image_delete (bp_map) ;
+<a name="l00476"></a>00476         <span class="keywordflow">return</span> NULL ;
+<a name="l00477"></a>00477     }
+<a name="l00478"></a>00478  
+<a name="l00479"></a>00479 
+<a name="l00480"></a>00480     <span class="comment">/* now build the bad pixel mask */</span>
+<a name="l00481"></a>00481     <span class="keywordflow">for</span> ( row = 0 ; row < ly ; row++ ) {
+<a name="l00482"></a>00482       <span class="keywordflow">for</span> ( col = 0 ; col < lx ; col++ ) {
+<a name="l00483"></a>00483          <span class="keywordflow">if</span> (pbpdata[col+lx*row] >
+<a name="l00484"></a>00484              stats->cleanmean+threshSigmaFactor*stats->cleanstdev ||
+<a name="l00485"></a>00485              pbpdata[col+lx*row] < 
+<a name="l00486"></a>00486              stats->cleanmean-threshSigmaFactor*stats->cleanstdev) 
+<a name="l00487"></a>00487        {
+<a name="l00488"></a>00488              pbpdata[col+lx*row] = 0. ;
+<a name="l00489"></a>00489        }
+<a name="l00490"></a>00490            <span class="keywordflow">else</span>
+<a name="l00491"></a>00491            {
+<a name="l00492"></a>00492          pbpdata[col+lx*row] = 1. ;
+<a name="l00493"></a>00493            }
+<a name="l00494"></a>00494       }
+<a name="l00495"></a>00495     }
+<a name="l00496"></a>00496     cpl_free (stats) ;
+<a name="l00497"></a>00497     <span class="keywordflow">return</span> bp_map ;
+<a name="l00498"></a>00498 }
+<a name="l00499"></a>00499 
+<a name="l00500"></a>00500 
+<a name="l00501"></a>00501 
+<a name="l00510"></a>00510 <span class="keywordtype">int</span> sinfo_new_count_bad_pixels (cpl_image * bad )
+<a name="l00511"></a>00511 {
+<a name="l00512"></a>00512     <span class="keywordtype">int</span> i, n ;
+<a name="l00513"></a>00513     <span class="keywordtype">int</span> sx=cpl_image_get_size_x(bad);
+<a name="l00514"></a>00514     <span class="keywordtype">int</span> sy=cpl_image_get_size_y(bad);
+<a name="l00515"></a>00515     <span class="keywordtype">float</span>* pbpdata=cpl_image_get_data(bad);
+<a name="l00516"></a>00516 
+<a name="l00517"></a>00517     n = 0 ;
+<a name="l00518"></a>00518     <span class="keywordflow">for</span> ( i = 0 ; i < (int) sx*sy ; i++ )
+<a name="l00519"></a>00519     {
+<a name="l00520"></a>00520         <span class="keywordflow">if</span> ( pbpdata[i] == 0 || isnan(pbpdata[i]) )
+<a name="l00521"></a>00521         {
+<a name="l00522"></a>00522             n++ ;
+<a name="l00523"></a>00523         }
+<a name="l00524"></a>00524     }
+<a name="l00525"></a>00525     <span class="keywordflow">return</span> n ;
+<a name="l00526"></a>00526 }
+<a name="l00527"></a>00527 
+<a name="l00528"></a>00528 
+<a name="l00556"></a>00556 cpl_image * sinfo_new_abs_dist_image(cpl_image * im, <span class="keywordtype">float</span> fmedian )
+<a name="l00557"></a>00557 {
+<a name="l00558"></a>00558 
+<a name="l00559"></a>00559     cpl_image *   image       ;
+<a name="l00560"></a>00560     pixelvalue * value       ;
+<a name="l00561"></a>00561     pixelvalue   dist      ;
+<a name="l00562"></a>00562     pixelvalue   median_dist      ;
+<a name="l00563"></a>00563     pixelvalue*   pix_dist=NULL ;
+<a name="l00564"></a>00564     <span class="keywordtype">int</span>        * position    ;
+<a name="l00565"></a>00565     <span class="keywordtype">int</span>          nposition   ;
+<a name="l00566"></a>00566     <span class="keywordtype">int</span>          n, m, i, j ;
+<a name="l00567"></a>00567     <span class="keywordtype">double</span>       sum, sum2 ;
+<a name="l00568"></a>00568     <span class="keywordtype">double</span>       stdev ;
+<a name="l00569"></a>00569     <span class="keywordtype">float</span>* pdata=NULL;
+<a name="l00570"></a>00570     <span class="keywordtype">int</span> lx=0;
+<a name="l00571"></a>00571     <span class="keywordtype">int</span> ly=0;
+<a name="l00572"></a>00572 
+<a name="l00573"></a>00573     <span class="keywordflow">if</span> ( im == NULL )
+<a name="l00574"></a>00574      {
+<a name="l00575"></a>00575         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"no image input\n"</span>) ;
+<a name="l00576"></a>00576         <span class="keywordflow">return</span> NULL ;
+<a name="l00577"></a>00577     }
+<a name="l00578"></a>00578 
+<a name="l00579"></a>00579     image = cpl_image_duplicate ( im ) ;
+<a name="l00580"></a>00580 
+<a name="l00581"></a>00581     <span class="comment">/*----------------------------------------------------------------------</span>
+<a name="l00582"></a>00582 <span class="comment">     * go through all pixels</span>
+<a name="l00583"></a>00583 <span class="comment">     */</span>
+<a name="l00584"></a>00584 
+<a name="l00585"></a>00585     sum = 0. ;
+<a name="l00586"></a>00586     sum2 = 0. ;
+<a name="l00587"></a>00587     m = 0 ;
+<a name="l00588"></a>00588     
+<a name="l00589"></a>00589     pdata = cpl_image_get_data(im);
+<a name="l00590"></a>00590     lx=cpl_image_get_size_x(im);
+<a name="l00591"></a>00591     ly=cpl_image_get_size_y(im);
+<a name="l00592"></a>00592     pix_dist=(pixelvalue*)cpl_calloc(lx*ly,<span class="keyword">sizeof</span>(pixelvalue)) ;
+<a name="l00593"></a>00593 
+<a name="l00594"></a>00594     <span class="keywordflow">for</span> ( i = 0 ;  i < (int) lx*ly ; i++ )
+<a name="l00595"></a>00595     {
+<a name="l00596"></a>00596       <span class="comment">/* blank pixels are not replaced */</span>
+<a name="l00597"></a>00597       <span class="keywordflow">if</span> ( isnan(pdata[i]) )
+<a name="l00598"></a>00598         {
+<a name="l00599"></a>00599       continue ;
+<a name="l00600"></a>00600         }
+<a name="l00601"></a>00601 
+<a name="l00602"></a>00602         <span class="comment">/* initialize the buffer variables for the 8 nearest neighbors */</span>
+<a name="l00603"></a>00603         value = (pixelvalue * )cpl_calloc ( 8, <span class="keyword">sizeof</span> ( pixelvalue * ) ) ;
+<a name="l00604"></a>00604         position = ( <span class="keywordtype">int</span> * ) cpl_calloc ( 8, <span class="keyword">sizeof</span> ( <span class="keywordtype">int</span> * ) ) ;
+<a name="l00605"></a>00605 
+<a name="l00606"></a>00606         <span class="comment">/*--------------------------------------------------------------------</span>
+<a name="l00607"></a>00607 <span class="comment">         * determine the pixel position of the 8 nearest neighbors</span>
+<a name="l00608"></a>00608 <span class="comment">         */</span>
+<a name="l00609"></a>00609 
+<a name="l00610"></a>00610         position[0] = i + lx - 1 ; <span class="comment">/* upper left  */</span>
+<a name="l00611"></a>00611         position[1] = i + lx     ; <span class="comment">/* upper       */</span>
+<a name="l00612"></a>00612         position[2] = i + lx + 1 ; <span class="comment">/* upper right */</span>
+<a name="l00613"></a>00613         position[3] = i + 1      ; <span class="comment">/* right       */</span>
+<a name="l00614"></a>00614         position[4] = i - lx + 1 ; <span class="comment">/* lower right */</span>
+<a name="l00615"></a>00615         position[5] = i - lx     ; <span class="comment">/* lower       */</span>
+<a name="l00616"></a>00616         position[6] = i - lx - 1 ; <span class="comment">/* lower left  */</span>
+<a name="l00617"></a>00617         position[7] = i - 1      ; <span class="comment">/* left        */</span>
+<a name="l00618"></a>00618 
+<a name="l00619"></a>00619         <span class="comment">/*--------------------------------------------------------------------</span>
+<a name="l00620"></a>00620 <span class="comment">         * determine the positions of the image margins, top positions are </span>
+<a name="l00621"></a>00621 <span class="comment">         * changed to low positions and vice versa. Right positions are </span>
+<a name="l00622"></a>00622 <span class="comment">         * changed to left positions and vice versa.</span>
+<a name="l00623"></a>00623 <span class="comment">         */</span>
+<a name="l00624"></a>00624 
+<a name="l00625"></a>00625         <span class="keywordflow">if</span> ( i >= 0 && i < lx )    <span class="comment">/* bottom line */</span>
+<a name="l00626"></a>00626         {
+<a name="l00627"></a>00627             position[4] += 2 * lx ;
+<a name="l00628"></a>00628             position[5] += 2 * lx ;
+<a name="l00629"></a>00629             position[6] += 2 * lx ;
+<a name="l00630"></a>00630         }
+<a name="l00631"></a>00631         <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( i >= ((<span class="keywordtype">int</span>) lx*ly - lx ) && i < (<span class="keywordtype">int</span>) lx*ly ) <span class="comment">/* top line */</span>
+<a name="l00632"></a>00632         {
+<a name="l00633"></a>00633             position[0] -= 2 * lx ;
+<a name="l00634"></a>00634             position[1] -= 2 * lx ;
+<a name="l00635"></a>00635             position[2] -= 2 * lx ;
+<a name="l00636"></a>00636         }
+<a name="l00637"></a>00637         <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( i % lx == 0 )    <span class="comment">/* left side */</span>
+<a name="l00638"></a>00638         {
+<a name="l00639"></a>00639             position[0] += 2 ;
+<a name="l00640"></a>00640             position[6] += 2 ;
+<a name="l00641"></a>00641             position[7] += 2 ;
+<a name="l00642"></a>00642         }
+<a name="l00643"></a>00643         <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( i % lx == lx - 1 )    <span class="comment">/* right side */</span>
+<a name="l00644"></a>00644         {
+<a name="l00645"></a>00645             position[2] -= 2 ;
+<a name="l00646"></a>00646             position[3] -= 2 ;
+<a name="l00647"></a>00647             position[4] -= 2 ;
+<a name="l00648"></a>00648         }
+<a name="l00649"></a>00649 
+<a name="l00650"></a>00650         <span class="comment">/* -------------------------------------------------------------------</span>
+<a name="l00651"></a>00651 <span class="comment">         * read the pixel values of the neighboring pixels,</span>
+<a name="l00652"></a>00652 <span class="comment">         * blanks are not considered</span>
+<a name="l00653"></a>00653 <span class="comment">         */</span>
+<a name="l00654"></a>00654 
+<a name="l00655"></a>00655         nposition = 8 ;
+<a name="l00656"></a>00656         n = 0 ;
+<a name="l00657"></a>00657         <span class="keywordflow">for</span> ( j = 0 ; j < nposition ; j ++ )
+<a name="l00658"></a>00658         {
+<a name="l00659"></a>00659             <span class="keywordflow">if</span> ( !isnan(pdata[position[j]]) )
+<a name="l00660"></a>00660             {
+<a name="l00661"></a>00661                 value[n] = pdata[position[j]] ;
+<a name="l00662"></a>00662                 n ++ ;
+<a name="l00663"></a>00663             }
+<a name="l00664"></a>00664         }
+<a name="l00665"></a>00665         nposition = n ;
+<a name="l00666"></a>00666 
+<a name="l00667"></a>00667         <span class="keywordflow">if</span> ( nposition <= 1 )  <span class="comment">/* almost all neighbors are blank */</span>
+<a name="l00668"></a>00668         {
+<a name="l00669"></a>00669             pdata[i] = ZERO ;
+<a name="l00670"></a>00670             cpl_free(value) ;
+<a name="l00671"></a>00671             cpl_free(position) ;
+<a name="l00672"></a>00672             continue ;
+<a name="l00673"></a>00673         }
+<a name="l00674"></a>00674 
+<a name="l00675"></a>00675         <span class="comment">/* determine the absolute distances */</span>
+<a name="l00676"></a>00676         dist = 0. ;
+<a name="l00677"></a>00677         <span class="keywordflow">for</span> ( n = 0 ; n < nposition ; n++ )
+<a name="l00678"></a>00678         {
+<a name="l00679"></a>00679             dist += (pdata[i] - value[n])*(pdata[i] - value[n]) ;    
+<a name="l00680"></a>00680         }
+<a name="l00681"></a>00681         dist = sqrt(dist)/(float) nposition ;
+<a name="l00682"></a>00682         pix_dist[m] = dist ;
+<a name="l00683"></a>00683         m++ ;
+<a name="l00684"></a>00684         sum += (double)dist ;
+<a name="l00685"></a>00685         sum2 += (double)dist * (<span class="keywordtype">double</span>)dist ;
+<a name="l00686"></a>00686         cpl_free(value) ;
+<a name="l00687"></a>00687         cpl_free(position) ;
+<a name="l00688"></a>00688     }
+<a name="l00689"></a>00689     sum /= (double)m ;
+<a name="l00690"></a>00690     sum2 /= (double)m ;
+<a name="l00691"></a>00691     stdev = sqrt(sum2 - sum*sum) ;
+<a name="l00692"></a>00692 
+<a name="l00693"></a>00693     median_dist = sinfo_new_median(pix_dist, m) ;
+<a name="l00694"></a>00694 
+<a name="l00695"></a>00695     <span class="keywordflow">for</span> ( i = 0 ; i < (int) lx*ly ; i++ )
+<a name="l00696"></a>00696     {
+<a name="l00697"></a>00697         <span class="comment">/* blank pixels are not replaced */</span>
+<a name="l00698"></a>00698         <span class="keywordflow">if</span> ( isnan(pdata[i]) )
+<a name="l00699"></a>00699         {
+<a name="l00700"></a>00700             continue ;
+<a name="l00701"></a>00701         }
+<a name="l00702"></a>00702 
+<a name="l00703"></a>00703         <span class="comment">/* initialize the buffer variables for the 8 nearest neighbors */</span>
+<a name="l00704"></a>00704         value = (pixelvalue * )cpl_calloc ( 8, <span class="keyword">sizeof</span> ( pixelvalue * ) ) ;
+<a name="l00705"></a>00705         position = ( <span class="keywordtype">int</span> * ) cpl_calloc ( 8, <span class="keyword">sizeof</span> ( <span class="keywordtype">int</span> * ) ) ;
+<a name="l00706"></a>00706 
+<a name="l00707"></a>00707         <span class="comment">/*-------------------------------------------------------------------</span>
+<a name="l00708"></a>00708 <span class="comment">         * determine the pixel position of the 8 nearest neighbors</span>
+<a name="l00709"></a>00709 <span class="comment">         */</span>
+<a name="l00710"></a>00710 
+<a name="l00711"></a>00711         position[0] = i + lx - 1 ; <span class="comment">/* upper left  */</span>
+<a name="l00712"></a>00712         position[1] = i + lx     ; <span class="comment">/* upper       */</span>
+<a name="l00713"></a>00713         position[2] = i + lx + 1 ; <span class="comment">/* upper right */</span>
+<a name="l00714"></a>00714         position[3] = i + 1      ; <span class="comment">/* right       */</span>
+<a name="l00715"></a>00715         position[4] = i - lx + 1 ; <span class="comment">/* lower right */</span>
+<a name="l00716"></a>00716         position[5] = i - lx     ; <span class="comment">/* lower       */</span>
+<a name="l00717"></a>00717         position[6] = i - lx - 1 ; <span class="comment">/* lower left  */</span>
+<a name="l00718"></a>00718         position[7] = i - 1      ; <span class="comment">/* left        */</span>
+<a name="l00719"></a>00719 
+<a name="l00720"></a>00720         <span class="comment">/*-------------------------------------------------------------</span>
+<a name="l00721"></a>00721 <span class="comment">         * determine the positions of the image margins, top positions are </span>
+<a name="l00722"></a>00722 <span class="comment">         * changed to low positions and vice versa. Right positions are </span>
+<a name="l00723"></a>00723 <span class="comment">         * changed to left positions and vice versa.</span>
+<a name="l00724"></a>00724 <span class="comment">         */</span>
+<a name="l00725"></a>00725 
+<a name="l00726"></a>00726         <span class="keywordflow">if</span> ( i >= 0 && i < lx )    <span class="comment">/* bottom line */</span>
+<a name="l00727"></a>00727         {
+<a name="l00728"></a>00728             position[4] += 2 * lx ;
+<a name="l00729"></a>00729             position[5] += 2 * lx ;
+<a name="l00730"></a>00730             position[6] += 2 * lx ;
+<a name="l00731"></a>00731         }
+<a name="l00732"></a>00732         <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( i >= ((<span class="keywordtype">int</span>) lx*ly - lx ) && i < (<span class="keywordtype">int</span>) lx*ly ) <span class="comment">/* top line */</span>
+<a name="l00733"></a>00733         {
+<a name="l00734"></a>00734             position[0] -= 2 * lx ;
+<a name="l00735"></a>00735             position[1] -= 2 * lx ;
+<a name="l00736"></a>00736             position[2] -= 2 * lx ;
+<a name="l00737"></a>00737         }
+<a name="l00738"></a>00738         <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( i % lx == 0 )    <span class="comment">/* left side */</span>
+<a name="l00739"></a>00739         {
+<a name="l00740"></a>00740             position[0] += 2 ;
+<a name="l00741"></a>00741             position[6] += 2 ;
+<a name="l00742"></a>00742             position[7] += 2 ;
+<a name="l00743"></a>00743         }
+<a name="l00744"></a>00744         <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( i % lx == lx - 1 )    <span class="comment">/* right side */</span>
+<a name="l00745"></a>00745         {
+<a name="l00746"></a>00746             position[2] -= 2 ;
+<a name="l00747"></a>00747             position[3] -= 2 ;
+<a name="l00748"></a>00748             position[4] -= 2 ;
+<a name="l00749"></a>00749         }
+<a name="l00750"></a>00750 
+<a name="l00751"></a>00751         <span class="comment">/* -------------------------------------------------------------------</span>
+<a name="l00752"></a>00752 <span class="comment">         * read the pixel values of the neighboring pixels,</span>
+<a name="l00753"></a>00753 <span class="comment">         * blanks are not considered</span>
+<a name="l00754"></a>00754 <span class="comment">         */</span>
+<a name="l00755"></a>00755 
+<a name="l00756"></a>00756         nposition = 8 ;
+<a name="l00757"></a>00757         n = 0 ;
+<a name="l00758"></a>00758         <span class="keywordflow">for</span> ( j = 0 ; j < nposition ; j ++ )
+<a name="l00759"></a>00759         {
+<a name="l00760"></a>00760             <span class="keywordflow">if</span> ( !isnan(pdata[position[j]]) )
+<a name="l00761"></a>00761             {
+<a name="l00762"></a>00762                 value[n] = pdata[position[j]] ;
+<a name="l00763"></a>00763                 n ++ ;
+<a name="l00764"></a>00764             }
+<a name="l00765"></a>00765         }
+<a name="l00766"></a>00766         nposition = n ;
+<a name="l00767"></a>00767 
+<a name="l00768"></a>00768         <span class="keywordflow">if</span> ( nposition <= 1 )  <span class="comment">/* almost all neighbors are blank */</span>
+<a name="l00769"></a>00769         {
+<a name="l00770"></a>00770             pdata[i] = ZERO ;
+<a name="l00771"></a>00771             cpl_free(value) ;
+<a name="l00772"></a>00772             cpl_free(position) ;
+<a name="l00773"></a>00773             continue ;
+<a name="l00774"></a>00774         }
+<a name="l00775"></a>00775 
+<a name="l00776"></a>00776         <span class="comment">/* determine the absolute distances */</span>
+<a name="l00777"></a>00777         dist = 0. ;
+<a name="l00778"></a>00778         <span class="keywordflow">for</span> ( n = 0 ; n < nposition ; n++ )
+<a name="l00779"></a>00779         {
+<a name="l00780"></a>00780             dist += (pdata[i] - value[n])*(pdata[i] - value[n]) ;    
+<a name="l00781"></a>00781         }
+<a name="l00782"></a>00782         dist = sqrt(dist)/(float) nposition ;
+<a name="l00783"></a>00783 
+<a name="l00784"></a>00784 
+<a name="l00785"></a>00785         <span class="comment">/* -----------------------------------------------------------------</span>
+<a name="l00786"></a>00786 <span class="comment">         * replace the pixel value by the sinfo_median on conditions:</span>
+<a name="l00787"></a>00787 <span class="comment">         * fmedian = 0: always replace with sinfo_median.</span>
+<a name="l00788"></a>00788 <span class="comment">         * fmedian < 0: interpret as absolute condition:</span>
+<a name="l00789"></a>00789 <span class="comment">         *              if |pixel - sinfo_median| > -fmedian</span>
+<a name="l00790"></a>00790 <span class="comment">         *              replace with sinfo_median.</span>
+<a name="l00791"></a>00791 <span class="comment">         * fmedian > 0: replace by sinfo_median (fmedian as a factor of</span>
+<a name="l00792"></a>00792 <span class="comment">         *              the square root of the sinfo_median itself)</span>
+<a name="l00793"></a>00793 <span class="comment">         *              if |pixel - median| >= fmedian * sqrt ( median )</span>
+<a name="l00794"></a>00794 <span class="comment">         *              considers a dependence on the pixel value.</span>
+<a name="l00795"></a>00795 <span class="comment">         *              This can be used to consider photon noise.</span>
+<a name="l00796"></a>00796 <span class="comment">         */</span>
+<a name="l00797"></a>00797 
+<a name="l00798"></a>00798         <span class="keywordflow">if</span> ( fmedian == 0 )
+<a name="l00799"></a>00799         {
+<a name="l00800"></a>00800             pdata[i] = dist ;
+<a name="l00801"></a>00801         }
+<a name="l00802"></a>00802         <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( fmedian < 0 &&
+<a name="l00803"></a>00803                   fabs ( median_dist - dist ) >= -fmedian*stdev )
+<a name="l00804"></a>00804         {
+<a name="l00805"></a>00805             pdata[i] = dist ;
+<a name="l00806"></a>00806         }
+<a name="l00807"></a>00807         <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( fmedian > 0 &&
+<a name="l00808"></a>00808                   fabs ( median_dist - dist ) >= 
+<a name="l00809"></a>00809                   fmedian*stdev * sqrt(fabs(dist)) )
+<a name="l00810"></a>00810         {
+<a name="l00811"></a>00811             pdata[i] = dist ;
+<a name="l00812"></a>00812         }
+<a name="l00813"></a>00813         <span class="keywordflow">else</span>
+<a name="l00814"></a>00814         {
+<a name="l00815"></a>00815             cpl_free (value) ;
+<a name="l00816"></a>00816             cpl_free (position) ;
+<a name="l00817"></a>00817             continue ;
+<a name="l00818"></a>00818         }
+<a name="l00819"></a>00819 
+<a name="l00820"></a>00820         cpl_free (value) ;
+<a name="l00821"></a>00821         cpl_free (position) ;
+<a name="l00822"></a>00822     }
+<a name="l00823"></a>00823     cpl_free(pix_dist);
+<a name="l00824"></a>00824     <span class="keywordflow">return</span> image ;
+<a name="l00825"></a>00825 }
+<a name="l00826"></a>00826 
+<a name="l00827"></a>00827 
+<a name="l00828"></a>00828 
+<a name="l00829"></a>00829 
+<a name="l00830"></a>00830 
+<a name="l00831"></a>00831 
+<a name="l00832"></a>00832 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00833"></a>00833 <span class="comment">   Function:       sinfo_new_local_median_image()</span>
+<a name="l00834"></a>00834 <span class="comment">   In      :       im: input image</span>
+<a name="l00835"></a>00835 <span class="comment">                   fmedian:  a factor to the local standard deviation</span>
+<a name="l00836"></a>00836 <span class="comment">                   loReject, hiReject: fraction of rejected values to determine</span>
+<a name="l00837"></a>00837 <span class="comment">                                       a clean standard deviation</span>
+<a name="l00838"></a>00838 <span class="comment">                   half_box_size: integer half size of the running box to </span>
+<a name="l00839"></a>00839 <span class="comment">                              determine the local clean standard deviation</span>
+<a name="l00840"></a>00840 <span class="comment">   Out     :       resulting image</span>
+<a name="l00841"></a>00841 <span class="comment">   Job     :       filter, calculates the local stdev in a moving box</span>
+<a name="l00842"></a>00842 <span class="comment">                   Then it calculates the difference of the pixel to the median</span>
+<a name="l00843"></a>00843 <span class="comment">                   of the nearest neighbors</span>
+<a name="l00844"></a>00844 <span class="comment">                   by using the 8 closest pixels of every pixel.</span>
+<a name="l00845"></a>00845 <span class="comment">                   The values in the output image are determined according</span>
+<a name="l00846"></a>00846 <span class="comment">                   to the values of the input parameter.</span>
+<a name="l00847"></a>00847 <span class="comment">                   If fmedian = 0: always replace by median</span>
+<a name="l00848"></a>00848 <span class="comment">                   if fmedian < 0: replace median if |median_dist - dist| ></span>
+<a name="l00849"></a>00849 <span class="comment">                                   fmedian * stdev </span>
+<a name="l00850"></a>00850 <span class="comment">                   if fmedian > 0: replace by median (fmedian as a factor of</span>
+<a name="l00851"></a>00851 <span class="comment">                                   the square root of the median itself)</span>
+<a name="l00852"></a>00852 <span class="comment">                                   if |pixel - median| >= fmedian*sqrt(median)</span>
+<a name="l00853"></a>00853 <span class="comment">                   This can be used to consider photon noise.</span>
+<a name="l00854"></a>00854 <span class="comment">                   This considers a dependence of the differences on the</span>
+<a name="l00855"></a>00855 <span class="comment">                   pixel values themselves.</span>
+<a name="l00856"></a>00856 <span class="comment">   Notice       :  it is assumed that most of the 8 nearest neighbor pixels</span>
+<a name="l00857"></a>00857 <span class="comment">                   are not bad pixels!</span>
+<a name="l00858"></a>00858 <span class="comment">                   blank pixels are not replaced!</span>
+<a name="l00859"></a>00859 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00860"></a>00860 
+<a name="l00861"></a>00861 cpl_image * sinfo_new_local_median_image( cpl_image * im, 
+<a name="l00862"></a>00862                              <span class="keywordtype">float</span> fmedian, 
+<a name="l00863"></a>00863                              <span class="keywordtype">float</span> loReject,
+<a name="l00864"></a>00864                              <span class="keywordtype">float</span> hiReject,
+<a name="l00865"></a>00865                              <span class="keywordtype">int</span> half_box_size )
+<a name="l00866"></a>00866 {
+<a name="l00867"></a>00867     cpl_image *   image       ;
+<a name="l00868"></a>00868     pixelvalue * value       ;
+<a name="l00869"></a>00869     pixelvalue   median      ;
+<a name="l00870"></a>00870     <span class="keywordtype">int</span>        * position    ;
+<a name="l00871"></a>00871     <span class="keywordtype">int</span>          nposition   ;
+<a name="l00872"></a>00872     <span class="keywordtype">int</span>          n, i, j ;
+<a name="l00873"></a>00873     <span class="keywordtype">int</span>          llx, lly, urx, ury ;
+<a name="l00874"></a>00874     Stats *      stats ;
+<a name="l00875"></a>00875     <span class="keywordtype">int</span> lx=0;
+<a name="l00876"></a>00876     <span class="keywordtype">int</span> ly=0;
+<a name="l00877"></a>00877     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l00878"></a>00878     <span class="keywordtype">float</span>* podata=NULL;
+<a name="l00879"></a>00879 
+<a name="l00880"></a>00880     <span class="keywordflow">if</span> ( im == NULL )
+<a name="l00881"></a>00881     {
+<a name="l00882"></a>00882         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"no image input"</span>) ;
+<a name="l00883"></a>00883         <span class="keywordflow">return</span> NULL ;
+<a name="l00884"></a>00884     }
+<a name="l00885"></a>00885     <span class="keywordflow">if</span> ( half_box_size < 0 )
+<a name="l00886"></a>00886     {
+<a name="l00887"></a>00887         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"negativ box_size given"</span>) ;
+<a name="l00888"></a>00888         <span class="keywordflow">return</span> NULL ;
+<a name="l00889"></a>00889     }
+<a name="l00890"></a>00890 
+<a name="l00891"></a>00891     image = cpl_image_duplicate ( im ) ;
+<a name="l00892"></a>00892     lx=cpl_image_get_size_x(im);
+<a name="l00893"></a>00893     ly=cpl_image_get_size_y(im);
+<a name="l00894"></a>00894     pidata=cpl_image_get_data(im);
+<a name="l00895"></a>00895     podata=cpl_image_get_data(image);
+<a name="l00896"></a>00896     <span class="comment">/*----------------------------------------------------------------------</span>
+<a name="l00897"></a>00897 <span class="comment">     * go through all pixels</span>
+<a name="l00898"></a>00898 <span class="comment">     */</span>
+<a name="l00899"></a>00899 
+<a name="l00900"></a>00900     <span class="keywordflow">for</span> ( i = 0 ; i < (int) lx*ly ; i++ )
+<a name="l00901"></a>00901     {
+<a name="l00902"></a>00902         <span class="comment">/* blank pixels are not replaced */</span>
+<a name="l00903"></a>00903         <span class="keywordflow">if</span> ( isnan(pidata[i]) )
+<a name="l00904"></a>00904         {
+<a name="l00905"></a>00905             continue ;
+<a name="l00906"></a>00906         }
+<a name="l00907"></a>00907 
+<a name="l00908"></a>00908         <span class="comment">/* compute the image statistics in the box area */</span>
+<a name="l00909"></a>00909         llx = i%lx - half_box_size ; 
+<a name="l00910"></a>00910         <span class="keywordflow">if</span> ( llx < 0 ) llx = 0 ;
+<a name="l00911"></a>00911         lly = i%ly - half_box_size ;
+<a name="l00912"></a>00912         <span class="keywordflow">if</span> ( lly < 0 ) lly = 0 ;
+<a name="l00913"></a>00913         urx = i%lx + half_box_size ; 
+<a name="l00914"></a>00914         <span class="keywordflow">if</span> ( urx >= lx ) urx = lx - 1 ;
+<a name="l00915"></a>00915         ury = i%ly + half_box_size ;
+<a name="l00916"></a>00916         <span class="keywordflow">if</span> ( ury >= ly ) ury = ly - 1 ;
+<a name="l00917"></a>00917 
+<a name="l00918"></a>00918         <span class="keywordflow">if</span> ( NULL == (stats = sinfo_new_image_stats_on_rectangle (im, loReject,
+<a name="l00919"></a>00919                                hiReject, llx, lly, urx, ury)) ) 
+<a name="l00920"></a>00920         {
+<a name="l00921"></a>00921             <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"could not determine image statistics "</span>);
+<a name="l00922"></a>00922             <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"in pixel %d"</span>, i) ;
+<a name="l00923"></a>00923             continue ;
+<a name="l00924"></a>00924         }
+<a name="l00925"></a>00925 
+<a name="l00926"></a>00926         <span class="comment">/* initialize the buffer variables for the 8 nearest neighbors */</span>
+<a name="l00927"></a>00927         value = (pixelvalue * )cpl_calloc ( 8, <span class="keyword">sizeof</span> ( pixelvalue * ) ) ;
+<a name="l00928"></a>00928         position = ( <span class="keywordtype">int</span> * ) cpl_calloc ( 8, <span class="keyword">sizeof</span> ( <span class="keywordtype">int</span> * ) ) ;
+<a name="l00929"></a>00929 
+<a name="l00930"></a>00930         <span class="comment">/*----------------------------------------------------------------------</span>
+<a name="l00931"></a>00931 <span class="comment">         * determine the pixel position of the 8 nearest neighbors</span>
+<a name="l00932"></a>00932 <span class="comment">         */</span>
+<a name="l00933"></a>00933 
+<a name="l00934"></a>00934         position[0] = i + lx - 1 ; <span class="comment">/* upper left  */</span>
+<a name="l00935"></a>00935         position[1] = i + lx     ; <span class="comment">/* upper       */</span>
+<a name="l00936"></a>00936         position[2] = i + lx + 1 ; <span class="comment">/* upper right */</span>
+<a name="l00937"></a>00937         position[3] = i + 1            ; <span class="comment">/* right       */</span>
+<a name="l00938"></a>00938         position[4] = i - lx + 1 ; <span class="comment">/* lower right */</span>
+<a name="l00939"></a>00939         position[5] = i - lx     ; <span class="comment">/* lower       */</span>
+<a name="l00940"></a>00940         position[6] = i - lx - 1 ; <span class="comment">/* lower left  */</span>
+<a name="l00941"></a>00941         position[7] = i - 1            ; <span class="comment">/* left        */</span>
+<a name="l00942"></a>00942 
+<a name="l00943"></a>00943         <span class="comment">/*---------------------------------------------------------------------</span>
+<a name="l00944"></a>00944 <span class="comment">         * determine the positions of the image margins, top positions are </span>
+<a name="l00945"></a>00945 <span class="comment">         * changed to low positions and vice versa. Right positions are </span>
+<a name="l00946"></a>00946 <span class="comment">         * changed to left positions and vice versa.</span>
+<a name="l00947"></a>00947 <span class="comment">         */</span>
+<a name="l00948"></a>00948 
+<a name="l00949"></a>00949         <span class="keywordflow">if</span> ( i >= 0 && i < lx )    <span class="comment">/* bottom line */</span>
+<a name="l00950"></a>00950         {
+<a name="l00951"></a>00951             position[4] += 2 * lx ;
+<a name="l00952"></a>00952             position[5] += 2 * lx ;
+<a name="l00953"></a>00953             position[6] += 2 * lx ;
+<a name="l00954"></a>00954         }
+<a name="l00955"></a>00955         <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( i >= ((<span class="keywordtype">int</span>) lx*ly - lx ) && i < (<span class="keywordtype">int</span>) lx*ly ) <span class="comment">/* top line */</span>
+<a name="l00956"></a>00956         {
+<a name="l00957"></a>00957             position[0] -= 2 * lx ;
+<a name="l00958"></a>00958             position[1] -= 2 * lx ;
+<a name="l00959"></a>00959             position[2] -= 2 * lx ;
+<a name="l00960"></a>00960         }
+<a name="l00961"></a>00961         <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( i % lx == 0 )    <span class="comment">/* left side */</span>
+<a name="l00962"></a>00962         {
+<a name="l00963"></a>00963             position[0] += 2 ;
+<a name="l00964"></a>00964             position[6] += 2 ;
+<a name="l00965"></a>00965             position[7] += 2 ;
+<a name="l00966"></a>00966         }
+<a name="l00967"></a>00967         <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( i % lx == lx - 1 )    <span class="comment">/* right side */</span>
+<a name="l00968"></a>00968         {
+<a name="l00969"></a>00969             position[2] -= 2 ;
+<a name="l00970"></a>00970             position[3] -= 2 ;
+<a name="l00971"></a>00971             position[4] -= 2 ;
+<a name="l00972"></a>00972         }
+<a name="l00973"></a>00973 
+<a name="l00974"></a>00974         <span class="comment">/* ------------------------------------------------------------------</span>
+<a name="l00975"></a>00975 <span class="comment">         * read the pixel values of the neighboring pixels,</span>
+<a name="l00976"></a>00976 <span class="comment">         * blanks are not considered</span>
+<a name="l00977"></a>00977 <span class="comment">         */</span>
+<a name="l00978"></a>00978 
+<a name="l00979"></a>00979         nposition = 8 ;
+<a name="l00980"></a>00980         n = 0 ;
+<a name="l00981"></a>00981         <span class="keywordflow">for</span> ( j = 0 ; j < nposition ; j ++ )
+<a name="l00982"></a>00982         {
+<a name="l00983"></a>00983             <span class="keywordflow">if</span> ( !isnan(pidata[position[j]]) )
+<a name="l00984"></a>00984             {
+<a name="l00985"></a>00985                 value[n] = pidata[position[j]] ;
+<a name="l00986"></a>00986                 n ++ ;
+<a name="l00987"></a>00987             }
+<a name="l00988"></a>00988         }
+<a name="l00989"></a>00989         nposition = n ;
+<a name="l00990"></a>00990 
+<a name="l00991"></a>00991         <span class="keywordflow">if</span> ( nposition <= 1 )  <span class="comment">/* almost all neighbors are blank */</span>
+<a name="l00992"></a>00992         {
+<a name="l00993"></a>00993             podata[i] = ZERO ;
+<a name="l00994"></a>00994             cpl_free(value) ;
+<a name="l00995"></a>00995             cpl_free(position) ;
+<a name="l00996"></a>00996             cpl_free(stats) ;
+<a name="l00997"></a>00997             continue ;
+<a name="l00998"></a>00998         }
+<a name="l00999"></a>00999 
+<a name="l01000"></a>01000         <span class="comment">/* sort the values and determine the median */</span>
+<a name="l01001"></a>01001 
+<a name="l01002"></a>01002         sinfo_pixel_qsort( value, nposition ) ;
+<a name="l01003"></a>01003         <span class="keywordflow">if</span> ( nposition % 2 == 1 )
+<a name="l01004"></a>01004         {
+<a name="l01005"></a>01005             median = value [ nposition/2 ] ;
+<a name="l01006"></a>01006         }
+<a name="l01007"></a>01007         <span class="keywordflow">else</span>
+<a name="l01008"></a>01008         {
+<a name="l01009"></a>01009             median = ( value [nposition/2 - 1] + value [nposition/2] ) / 2. ;
+<a name="l01010"></a>01010         }
+<a name="l01011"></a>01011 
+<a name="l01012"></a>01012         <span class="comment">/* -----------------------------------------------------------------</span>
+<a name="l01013"></a>01013 <span class="comment">         * replace the pixel value by the median on conditions:</span>
+<a name="l01014"></a>01014 <span class="comment">         * fmedian = 0: always replace with median.</span>
+<a name="l01015"></a>01015 <span class="comment">         * fmedian > 0: replace by median (fmedian as a factor of</span>
+<a name="l01016"></a>01016 <span class="comment">         *              the square root of the median itself)</span>
+<a name="l01017"></a>01017 <span class="comment">         *              if |pixel - median| >= fmedian * sqrt ( median )</span>
+<a name="l01018"></a>01018 <span class="comment">         *              considers a dependence on the pixel value.</span>
+<a name="l01019"></a>01019 <span class="comment">         *              This can be used to consider photon noise.</span>
+<a name="l01020"></a>01020 <span class="comment">         */</span>
+<a name="l01021"></a>01021 
+<a name="l01022"></a>01022         <span class="keywordflow">if</span> ( fmedian == 0 )
+<a name="l01023"></a>01023         {
+<a name="l01024"></a>01024             podata[i] = median ;
+<a name="l01025"></a>01025         }
+<a name="l01026"></a>01026         <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( fmedian < 0 &&
+<a name="l01027"></a>01027                   fabs ( median - pidata[i] ) >= -fmedian * stats->cleanstdev)
+<a name="l01028"></a>01028         {
+<a name="l01029"></a>01029             podata[i] = median ;
+<a name="l01030"></a>01030         }
+<a name="l01031"></a>01031         <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( fmedian > 0 &&
+<a name="l01032"></a>01032                   fabs ( median - pidata[i] ) >= fmedian * sqrt(fabs(median)) )
+<a name="l01033"></a>01033         {
+<a name="l01034"></a>01034             podata[i] = median ;
+<a name="l01035"></a>01035         }
+<a name="l01036"></a>01036         <span class="keywordflow">else</span>
+<a name="l01037"></a>01037         {
+<a name="l01038"></a>01038             cpl_free (value) ;
+<a name="l01039"></a>01039             cpl_free (position) ;
+<a name="l01040"></a>01040             cpl_free (stats) ;
+<a name="l01041"></a>01041             continue ;
+<a name="l01042"></a>01042         }
+<a name="l01043"></a>01043 
+<a name="l01044"></a>01044         cpl_free (value) ;
+<a name="l01045"></a>01045         cpl_free (position) ;
+<a name="l01046"></a>01046         cpl_free (stats) ;
+<a name="l01047"></a>01047     }
+<a name="l01048"></a>01048     <span class="keywordflow">return</span> image ;
+<a name="l01049"></a>01049 }
+<a name="l01050"></a>01050 
+<a name="l01051"></a>01051 
+<a name="l01052"></a>01052 
+<a name="l01053"></a>01053 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l01054"></a>01054 <span class="comment">   Function:       sinfo_new_mean_image_in_spec()</span>
+<a name="l01055"></a>01055 <span class="comment">   In      :       image, a threshold parameter</span>
+<a name="l01056"></a>01056 <span class="comment">   Out     :       resulting image</span>
+<a name="l01057"></a>01057 <span class="comment">   Job     :       mean filter, calculates the mean for an image</span>
+<a name="l01058"></a>01058 <span class="comment">                   by using the 4 closest pixels of every pixel in spectral </span>
+<a name="l01059"></a>01059 <span class="comment">                   direction (column).</span>
+<a name="l01060"></a>01060 <span class="comment">                   The values in the output image are determined according</span>
+<a name="l01061"></a>01061 <span class="comment">                   to the values of the input parameter.</span>
+<a name="l01062"></a>01062 <span class="comment">                   If fmedian = 0: always replace by mean</span>
+<a name="l01063"></a>01063 <span class="comment">                   if fmedian < 0: replace by mean if |pixel - mean| ></span>
+<a name="l01064"></a>01064 <span class="comment">                                        -fmedian</span>
+<a name="l01065"></a>01065 <span class="comment">                   if fmedian > 0: replace by mean (fmedian as a factor of</span>
+<a name="l01066"></a>01066 <span class="comment">                                   the square root of the mean itself)</span>
+<a name="l01067"></a>01067 <span class="comment">                                   if |pixel - mean| >= fmedian * sqrt ( mean )</span>
+<a name="l01068"></a>01068 <span class="comment">                   This can be used to consider photon noise.</span>
+<a name="l01069"></a>01069 <span class="comment">                   This considers a dependence of the differences on the</span>
+<a name="l01070"></a>01070 <span class="comment">                   pixel values themselves.</span>
+<a name="l01071"></a>01071 <span class="comment">   Notice       :  it is assumed that most of the 4 nearest neighbor pixels</span>
+<a name="l01072"></a>01072 <span class="comment">                   are not bad pixels!</span>
+<a name="l01073"></a>01073 <span class="comment">                   blank pixels are not replaced!</span>
+<a name="l01074"></a>01074 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l01075"></a>01075 
+<a name="l01076"></a>01076 cpl_image * sinfo_new_mean_image_in_spec( cpl_image * im, <span class="keywordtype">float</span> fmedian )
+<a name="l01077"></a>01077 {
+<a name="l01078"></a>01078     cpl_image *   image       ;
+<a name="l01079"></a>01079     pixelvalue * value       ;
+<a name="l01080"></a>01080     pixelvalue   mean      ;
+<a name="l01081"></a>01081     <span class="keywordtype">int</span>        * position    ;
+<a name="l01082"></a>01082     <span class="keywordtype">int</span>          nposition   ;
+<a name="l01083"></a>01083     <span class="keywordtype">int</span>          n, i, j ;
+<a name="l01084"></a>01084     <span class="keywordtype">int</span> lx=0;
+<a name="l01085"></a>01085     <span class="keywordtype">int</span> ly=0;
+<a name="l01086"></a>01086     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l01087"></a>01087     <span class="keywordtype">float</span>* podata=NULL;
+<a name="l01088"></a>01088 
+<a name="l01089"></a>01089     <span class="keywordflow">if</span> ( im == NULL )
+<a name="l01090"></a>01090     {
+<a name="l01091"></a>01091         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"no image input"</span>) ;
+<a name="l01092"></a>01092         <span class="keywordflow">return</span> NULL ;
+<a name="l01093"></a>01093     }
+<a name="l01094"></a>01094 
+<a name="l01095"></a>01095     image = cpl_image_duplicate ( im ) ;
+<a name="l01096"></a>01096     lx=cpl_image_get_size_x(im);
+<a name="l01097"></a>01097     ly=cpl_image_get_size_y(im);
+<a name="l01098"></a>01098     pidata=cpl_image_get_data(im);
+<a name="l01099"></a>01099     podata=cpl_image_get_data(image);
+<a name="l01100"></a>01100 
+<a name="l01101"></a>01101     <span class="comment">/*----------------------------------------------------------------------</span>
+<a name="l01102"></a>01102 <span class="comment">     * go through all pixels</span>
+<a name="l01103"></a>01103 <span class="comment">     */</span>
+<a name="l01104"></a>01104 
+<a name="l01105"></a>01105     <span class="keywordflow">for</span> ( i = 0 ; i < (int) lx*ly ; i++ )
+<a name="l01106"></a>01106     {
+<a name="l01107"></a>01107         <span class="comment">/* blank pixels are not replaced */</span>
+<a name="l01108"></a>01108         <span class="keywordflow">if</span> ( isnan(pidata[i]) )
+<a name="l01109"></a>01109         {
+<a name="l01110"></a>01110             continue ;
+<a name="l01111"></a>01111         }
+<a name="l01112"></a>01112 
+<a name="l01113"></a>01113         <span class="comment">/* initialize the buffer variables for the 2 nearest </span>
+<a name="l01114"></a>01114 <span class="comment">           spectral neighbors */</span>
+<a name="l01115"></a>01115         value = (pixelvalue * )cpl_calloc ( 4, <span class="keyword">sizeof</span> ( pixelvalue * ) ) ;
+<a name="l01116"></a>01116         position = ( <span class="keywordtype">int</span> * ) cpl_calloc ( 4, <span class="keyword">sizeof</span> ( <span class="keywordtype">int</span> * ) ) ;
+<a name="l01117"></a>01117 
+<a name="l01118"></a>01118         <span class="comment">/*--------------------------------------------------------------------</span>
+<a name="l01119"></a>01119 <span class="comment">         * determine the pixel position of the 8 nearest neighbors</span>
+<a name="l01120"></a>01120 <span class="comment">         */</span>
+<a name="l01121"></a>01121 
+<a name="l01122"></a>01122         position[0] = i + lx     ; <span class="comment">/* upper       */</span>
+<a name="l01123"></a>01123         position[1] = i + 2*lx   ; <span class="comment">/* upper       */</span>
+<a name="l01124"></a>01124         position[2] = i - lx     ; <span class="comment">/* lower       */</span>
+<a name="l01125"></a>01125         position[3] = i - 2*lx   ; <span class="comment">/* lower       */</span>
+<a name="l01126"></a>01126 
+<a name="l01127"></a>01127         <span class="comment">/*-------------------------------------------------------------------</span>
+<a name="l01128"></a>01128 <span class="comment">         * determine the positions of the image margins, top positions are </span>
+<a name="l01129"></a>01129 <span class="comment">         * changed to low positions and vice versa. Right positions are changed</span>
+<a name="l01130"></a>01130 <span class="comment">         * to left positions and vice versa.</span>
+<a name="l01131"></a>01131 <span class="comment">         */</span>
+<a name="l01132"></a>01132 
+<a name="l01133"></a>01133         <span class="keywordflow">if</span> ( i >= 0 && i < lx )    <span class="comment">/* bottom line */</span>
+<a name="l01134"></a>01134         {
+<a name="l01135"></a>01135             position[2] += 2 * lx ;
+<a name="l01136"></a>01136             position[3] += 4 * lx ;
+<a name="l01137"></a>01137         }
+<a name="l01138"></a>01138         <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( i >= ((<span class="keywordtype">int</span>) lx*ly - lx ) && i < (<span class="keywordtype">int</span>) lx*ly ) <span class="comment">/* top line */</span>
+<a name="l01139"></a>01139         {
+<a name="l01140"></a>01140             position[0] -= 2 * lx ;
+<a name="l01141"></a>01141             position[1] -= 4 * lx ;
+<a name="l01142"></a>01142         }
+<a name="l01143"></a>01143 
+<a name="l01144"></a>01144         <span class="comment">/* -------------------------------------------------------------------</span>
+<a name="l01145"></a>01145 <span class="comment">         * read the pixel values of the neighboring pixels,</span>
+<a name="l01146"></a>01146 <span class="comment">         * blanks are not considered</span>
+<a name="l01147"></a>01147 <span class="comment">         */</span>
+<a name="l01148"></a>01148 
+<a name="l01149"></a>01149         nposition = 4 ;
+<a name="l01150"></a>01150         n = 0 ;
+<a name="l01151"></a>01151         <span class="keywordflow">for</span> ( j = 0 ; j < nposition ; j ++ )
+<a name="l01152"></a>01152         {
+<a name="l01153"></a>01153             <span class="keywordflow">if</span> ( !isnan(pidata[position[j]]) )
+<a name="l01154"></a>01154             {
+<a name="l01155"></a>01155                 value[n] = pidata[position[j]] ;
+<a name="l01156"></a>01156                 n ++ ;
+<a name="l01157"></a>01157             }
+<a name="l01158"></a>01158         }
+<a name="l01159"></a>01159         nposition = n ;
+<a name="l01160"></a>01160 
+<a name="l01161"></a>01161         <span class="keywordflow">if</span> ( nposition < 1 )  <span class="comment">/* all neighbors are blank */</span>
+<a name="l01162"></a>01162         {
+<a name="l01163"></a>01163             podata[i] = ZERO ;
+<a name="l01164"></a>01164             cpl_free(value) ;
+<a name="l01165"></a>01165             cpl_free(position) ;
+<a name="l01166"></a>01166             continue ;
+<a name="l01167"></a>01167         }
+<a name="l01168"></a>01168 
+<a name="l01169"></a>01169         <span class="comment">/* determine the mean */</span>
+<a name="l01170"></a>01170         mean = 0. ;
+<a name="l01171"></a>01171         <span class="keywordflow">for</span> ( n = 0 ; n < nposition ; n++ )
+<a name="l01172"></a>01172         {
+<a name="l01173"></a>01173             mean += value[n] ;
+<a name="l01174"></a>01174         }
+<a name="l01175"></a>01175         mean /= (float) nposition ;
+<a name="l01176"></a>01176 
+<a name="l01177"></a>01177         <span class="comment">/* -----------------------------------------------------------------</span>
+<a name="l01178"></a>01178 <span class="comment">         * replace the pixel value by the median on conditions:</span>
+<a name="l01179"></a>01179 <span class="comment">         * fmedian = 0:","always replace with mean.</span>
+<a name="l01180"></a>01180 <span class="comment">         * fmedian < 0: interpret as absolute condition:</span>
+<a name="l01181"></a>01181 <span class="comment">         *              if |pixel - mean| > -fmedian</span>
+<a name="l01182"></a>01182 <span class="comment">         *              replace with mean.</span>
+<a name="l01183"></a>01183 <span class="comment">         */</span>
+<a name="l01184"></a>01184 
+<a name="l01185"></a>01185         <span class="keywordflow">if</span> ( fmedian == 0 )
+<a name="l01186"></a>01186         {
+<a name="l01187"></a>01187             podata[i] = mean ;
+<a name="l01188"></a>01188         }
+<a name="l01189"></a>01189         <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( fmedian < 0 &&
+<a name="l01190"></a>01190                   fabs ( mean - pidata[i] ) >= -fmedian )
+<a name="l01191"></a>01191         {
+<a name="l01192"></a>01192             podata[i] = mean ;
+<a name="l01193"></a>01193         }
+<a name="l01194"></a>01194         <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( fmedian > 0 &&
+<a name="l01195"></a>01195                   fabs ( mean - pidata[i] ) >= fmedian * sqrt(fabs(mean)) )
+<a name="l01196"></a>01196         {
+<a name="l01197"></a>01197             podata[i] = mean ;
+<a name="l01198"></a>01198         }
+<a name="l01199"></a>01199         <span class="keywordflow">else</span>
+<a name="l01200"></a>01200         {
+<a name="l01201"></a>01201             cpl_free (value) ;
+<a name="l01202"></a>01202             cpl_free (position) ;
+<a name="l01203"></a>01203             continue ;
+<a name="l01204"></a>01204         }
+<a name="l01205"></a>01205 
+<a name="l01206"></a>01206         cpl_free (value) ;
+<a name="l01207"></a>01207         cpl_free (position) ;
+<a name="l01208"></a>01208     }
+<a name="l01209"></a>01209     <span class="keywordflow">return</span> image ;
+<a name="l01210"></a>01210 }
+<a name="l01211"></a>01211 
+<a name="l01212"></a>01212 
+<a name="l01213"></a>01213 
+<a name="l01214"></a>01214 
+<a name="l01215"></a>01215 
+<a name="l01216"></a>01216 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__detlin_8h_source.html b/html/sinfo__detlin_8h_source.html
new file mode 100644
index 0000000..b15fa84
--- /dev/null
+++ b/html/sinfo__detlin_8h_source.html
@@ -0,0 +1,133 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_detlin.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_detlin.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#ifndef SINFO_DETLIN_H</span>
+<a name="l00002"></a>00002 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_DETLIN_H</span>
+<a name="l00003"></a>00003 <span class="preprocessor"></span><span class="comment">/*</span>
+<a name="l00004"></a>00004 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00005"></a>00005 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00006"></a>00006 <span class="comment"> *</span>
+<a name="l00007"></a>00007 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00008"></a>00008 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00009"></a>00009 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00010"></a>00010 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00011"></a>00011 <span class="comment"> *</span>
+<a name="l00012"></a>00012 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00013"></a>00013 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00014"></a>00014 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00015"></a>00015 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00016"></a>00016 <span class="comment"> *</span>
+<a name="l00017"></a>00017 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00018"></a>00018 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00019"></a>00019 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00020"></a>00020 <span class="comment"> */</span>
+<a name="l00021"></a>00021 
+<a name="l00022"></a>00022 <span class="comment">/*******************************************************************************</span>
+<a name="l00023"></a>00023 <span class="comment">* E.S.O. - VLT project</span>
+<a name="l00024"></a>00024 <span class="comment">*</span>
+<a name="l00025"></a>00025 <span class="comment">* "@(#) $Id: sinfo_detlin.h,v 1.5 2007/06/06 07:10:45 amodigli Exp $"</span>
+<a name="l00026"></a>00026 <span class="comment">*</span>
+<a name="l00027"></a>00027 <span class="comment">* who       when      what</span>
+<a name="l00028"></a>00028 <span class="comment">* --------  --------  ----------------------------------------------</span>
+<a name="l00029"></a>00029 <span class="comment">* amodigli  04/01/06  created</span>
+<a name="l00030"></a>00030 <span class="comment">*/</span>
+<a name="l00031"></a>00031 
+<a name="l00032"></a>00032 <span class="comment">/************************************************************************</span>
+<a name="l00033"></a>00033 <span class="comment"> * sinfo_detlin.h</span>
+<a name="l00034"></a>00034 <span class="comment"> * detector linearity routines</span>
+<a name="l00035"></a>00035 <span class="comment"> * to search for static bad pixels</span>
+<a name="l00036"></a>00036 <span class="comment"> *----------------------------------------------------------------------</span>
+<a name="l00037"></a>00037 <span class="comment"> */</span>
+<a name="l00038"></a>00038 
+<a name="l00039"></a>00039 <span class="comment">/*</span>
+<a name="l00040"></a>00040 <span class="comment"> * header files</span>
+<a name="l00041"></a>00041 <span class="comment"> */</span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include "sinfo_image_ops.h"</span>
+<a name="l00043"></a>00043 
+<a name="l00044"></a>00044 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00045"></a>00045 <span class="comment"> *                        Function ANSI C prototypes</span>
+<a name="l00046"></a>00046 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00066"></a>00066 cpl_imagelist * 
+<a name="l00067"></a>00067 sinfo_new_fit_intensity_course(cpl_imagelist * flatStack,
+<a name="l00068"></a>00068                               <span class="keywordtype">int</span>       order,
+<a name="l00069"></a>00069                               <span class="keywordtype">float</span>     loReject,
+<a name="l00070"></a>00070                               <span class="keywordtype">float</span>     hiReject ) ;
+<a name="l00071"></a>00071 
+<a name="l00072"></a>00072 
+<a name="l00073"></a>00073 
+<a name="l00093"></a>00093 cpl_image * 
+<a name="l00094"></a>00094 sinfo_new_search_bad_pixels(cpl_imagelist *  coeffs,
+<a name="l00095"></a>00095                             <span class="keywordtype">double</span>     threshSigmaFactor,
+<a name="l00096"></a>00096                             <span class="keywordtype">double</span>     nonlinearThresh,
+<a name="l00097"></a>00097                             <span class="keywordtype">float</span>      loReject,
+<a name="l00098"></a>00098                             <span class="keywordtype">float</span>      hiReject ) ;
+<a name="l00099"></a>00099 
+<a name="l00117"></a>00117 cpl_image * 
+<a name="l00118"></a>00118 sinfo_new_search_bad_pixels_via_noise( cpl_imagelist *  darks,
+<a name="l00119"></a>00119                                     <span class="keywordtype">float</span>      threshSigmaFactor,
+<a name="l00120"></a>00120                                     <span class="keywordtype">float</span>      loReject,
+<a name="l00121"></a>00121                                     <span class="keywordtype">float</span>      hiReject ) ;
+<a name="l00122"></a>00122 
+<a name="l00123"></a>00123 
+<a name="l00124"></a>00124 <span class="comment">/*</span>
+<a name="l00125"></a>00125 <span class="comment">   @name   sinfo_new_count_bad_pixels()</span>
+<a name="l00126"></a>00126 <span class="comment">   @memo     this routine counts the number of bad pixels</span>
+<a name="l00127"></a>00127 <span class="comment">   @param  bad bad pixel mask</span>
+<a name="l00128"></a>00128 <span class="comment">   @return      number of bad pixels.</span>
+<a name="l00129"></a>00129 <span class="comment">*/</span>
+<a name="l00130"></a>00130 
+<a name="l00131"></a>00131 <span class="keywordtype">int</span> 
+<a name="l00132"></a>00132 sinfo_new_count_bad_pixels ( cpl_image * bad ) ;
+<a name="l00133"></a>00133 
+<a name="l00134"></a>00134 
+<a name="l00135"></a>00135 <span class="comment">/*</span>
+<a name="l00136"></a>00136 <span class="comment">   @name   sinfo_new_abs_dist_image()</span>
+<a name="l00137"></a>00137 <span class="comment">   @param  image, a threshold parameter</span>
+<a name="l00138"></a>00138 <span class="comment">   @result resulting image</span>
+<a name="l00139"></a>00139 <span class="comment">   @doc    filter, calculates the absolute distances of the nearest neighbors </span>
+<a name="l00140"></a>00140 <span class="comment">           for an image by using the 8 closest pixels of every pixel.</span>
+<a name="l00141"></a>00141 <span class="comment">           The values in the output image are determined according</span>
+<a name="l00142"></a>00142 <span class="comment">           to the values of the input parameter.</span>
+<a name="l00143"></a>00143 <span class="comment">           If fmedian = 0: always replace by abs. distances</span>
+<a name="l00144"></a>00144 <span class="comment">           if fmedian < 0: replace by abs. distances if |median_dist - dist| ></span>
+<a name="l00145"></a>00145 <span class="comment">                                        -fmedian</span>
+<a name="l00146"></a>00146 <span class="comment">           if fmedian > 0: replace by abs. distances (fmedian as a factor of</span>
+<a name="l00147"></a>00147 <span class="comment">                           the square root of the distance itself)</span>
+<a name="l00148"></a>00148 <span class="comment">           if |median_dist - dist| >= fmedian * sqrt ( dist )</span>
+<a name="l00149"></a>00149 <span class="comment">           This can be used to consider photon noise.</span>
+<a name="l00150"></a>00150 <span class="comment">           This considers a dependence of the differences on the</span>
+<a name="l00151"></a>00151 <span class="comment">           pixel values themselves.</span>
+<a name="l00152"></a>00152 <span class="comment">   @note   it is assumed that most of the 8 nearest neighbor pixels</span>
+<a name="l00153"></a>00153 <span class="comment">           are not bad pixels! blank pixels are not replaced!</span>
+<a name="l00154"></a>00154 <span class="comment">*/</span>
+<a name="l00155"></a>00155 
+<a name="l00156"></a>00156 
+<a name="l00157"></a>00157 cpl_image * 
+<a name="l00158"></a>00158 sinfo_new_abs_dist_image(cpl_image * im, <span class="keywordtype">float</span> fmedian ) ;
+<a name="l00159"></a>00159 
+<a name="l00160"></a>00160 
+<a name="l00183"></a>00183 cpl_image * 
+<a name="l00184"></a>00184 sinfo_new_mean_image_in_spec(cpl_image * im, <span class="keywordtype">float</span> fmedian ) ;
+<a name="l00185"></a>00185 
+<a name="l00208"></a>00208 cpl_image * 
+<a name="l00209"></a>00209 sinfo_new_local_median_image(cpl_image * im,
+<a name="l00210"></a>00210                              <span class="keywordtype">float</span> fmedian,
+<a name="l00211"></a>00211                              <span class="keywordtype">float</span> loReject,
+<a name="l00212"></a>00212                              <span class="keywordtype">float</span> hiReject,
+<a name="l00213"></a>00213                              <span class="keywordtype">int</span> half_box_size ) ;
+<a name="l00214"></a>00214 
+<a name="l00215"></a>00215 
+<a name="l00216"></a>00216 <span class="preprocessor">#endif </span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__detlin__cfg_8c_source.html b/html/sinfo__detlin__cfg_8c_source.html
new file mode 100644
index 0000000..5a90a6a
--- /dev/null
+++ b/html/sinfo__detlin__cfg_8c_source.html
@@ -0,0 +1,67 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_detlin_cfg.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_detlin_cfg.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name     :    sinfo_detlin_cfg.c</span>
+<a name="l00022"></a>00022 <span class="comment">   Autor    :       Juergen Schreiber</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on    :    April 2002</span>
+<a name="l00024"></a>00024 <span class="comment">   Description    :    handles the data structure detlin_config</span>
+<a name="l00025"></a>00025 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00026"></a>00026 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00027"></a>00027 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00028"></a>00028 <span class="preprocessor">#endif</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00030"></a>00030 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00031"></a>00031 <span class="preprocessor">#include "sinfo_detlin_cfg.h"</span>
+<a name="l00038"></a>00038 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00039"></a>00039 <span class="comment">                              Function codes</span>
+<a name="l00040"></a>00040 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00048"></a>00048 detlin_config * 
+<a name="l00049"></a>00049 sinfo_detlin_cfg_create(<span class="keywordtype">void</span>)
+<a name="l00050"></a>00050 {
+<a name="l00051"></a>00051     <span class="keywordflow">return</span> cpl_calloc(1, <span class="keyword">sizeof</span>(detlin_config));
+<a name="l00052"></a>00052 }
+<a name="l00053"></a>00053 
+<a name="l00060"></a>00060 <span class="keywordtype">void</span> sinfo_detlin_cfg_destroy(detlin_config * sc)
+<a name="l00061"></a>00061 {
+<a name="l00062"></a>00062 
+<a name="l00063"></a>00063     <span class="keywordflow">if</span> (sc==NULL) return ;
+<a name="l00064"></a>00064     <span class="comment">/* cpl_free(sc->framelist) ; */</span>
+<a name="l00065"></a>00065     <span class="comment">/* Free main struct */</span>
+<a name="l00066"></a>00066     cpl_free(sc);
+<a name="l00067"></a>00067 
+<a name="l00068"></a>00068     return ;
+<a name="l00069"></a>00069 }
+<a name="l00070"></a>00070 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__detlin__cfg_8h_source.html b/html/sinfo__detlin__cfg_8h_source.html
new file mode 100644
index 0000000..45e6875
--- /dev/null
+++ b/html/sinfo__detlin__cfg_8h_source.html
@@ -0,0 +1,103 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_detlin_cfg.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_detlin_cfg.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name     :    sinfo_detlin_cfg.h</span>
+<a name="l00022"></a>00022 <span class="comment">   Author         :    Juergen Schreiber</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on    :    April 2002</span>
+<a name="l00024"></a>00024 <span class="comment">   Description    :    sinfo_detlin_ini definitions + handling prototypes</span>
+<a name="l00025"></a>00025 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00026"></a>00026 <span class="preprocessor">#ifndef SINFO_DETLIN_CFG_H</span>
+<a name="l00027"></a>00027 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_DETLIN_CFG_H</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00029"></a>00029 <span class="comment">                                   Includes</span>
+<a name="l00030"></a>00030 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00031"></a>00031 <span class="preprocessor">#include <stdlib.h></span>
+<a name="l00032"></a>00032 <span class="preprocessor">#include "sinfo_globals.h"</span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00034"></a>00034 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00035"></a>00035 <span class="comment">                                   Defines</span>
+<a name="l00036"></a>00036 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00037"></a>00037 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00038"></a>00038 <span class="comment">                                   New types</span>
+<a name="l00039"></a>00039 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00040"></a>00040 <span class="comment">/*</span>
+<a name="l00041"></a>00041 <span class="comment">  bad pixels search blackboard container</span>
+<a name="l00042"></a>00042 <span class="comment"></span>
+<a name="l00043"></a>00043 <span class="comment">  This structure holds all information related to the bad pixels search</span>
+<a name="l00044"></a>00044 <span class="comment">  routine. It is used as a container for the flux of ancillary data,</span>
+<a name="l00045"></a>00045 <span class="comment">  computed values, and algorithm status. Pixel flux is separated from</span>
+<a name="l00046"></a>00046 <span class="comment">  the blackboard.</span>
+<a name="l00047"></a>00047 <span class="comment">  */</span>
+<a name="l00048"></a>00048 
+<a name="l00049"></a>00049 <span class="keyword">typedef</span> <span class="keyword">struct </span>detlin_config {
+<a name="l00050"></a>00050 <span class="comment">/*-------General---------*/</span>
+<a name="l00051"></a>00051         <span class="keywordtype">char</span> inFile[FILE_NAME_SZ] ; <span class="comment">/* file name of the file containing </span>
+<a name="l00052"></a>00052 <span class="comment">                                       the list of all input frames */</span>
+<a name="l00053"></a>00053         <span class="keywordtype">char</span> outName[FILE_NAME_SZ] ; <span class="comment">/* output name of resulting bad pixel </span>
+<a name="l00054"></a>00054 <span class="comment">                                        mask (fits file)*/</span>
+<a name="l00055"></a>00055         <span class="keywordtype">char</span> ** framelist ; <span class="comment">/* list of frames */</span>
+<a name="l00056"></a>00056         <span class="keywordtype">int</span>     nframes ; <span class="comment">/* number of frames in frame list */</span>
+<a name="l00057"></a>00057 
+<a name="l00058"></a>00058 <span class="comment">/*------ Response------*/</span>
+<a name="l00059"></a>00059         <span class="comment">/* order of the fit polynomial */</span>
+<a name="l00060"></a>00060         <span class="keywordtype">int</span> order ;      
+<a name="l00061"></a>00061         <span class="comment">/* factor to the standard deviation of the zero and slope polynomial </span>
+<a name="l00062"></a>00062 <span class="comment">           coefficient. if the deviation exceeds the resulting value the </span>
+<a name="l00063"></a>00063 <span class="comment">           corresponding pixel is declared as bad */</span> 
+<a name="l00064"></a>00064         <span class="keywordtype">double</span> threshSigmaFactor ;      
+<a name="l00065"></a>00065         <span class="comment">/*if a non-linear coefficient exceeds this value the corresponding </span>
+<a name="l00066"></a>00066 <span class="comment">          pixel is declared as bad*/</span>
+<a name="l00067"></a>00067         <span class="keywordtype">double</span> nonlinearThresh ;      
+<a name="l00068"></a>00068         <span class="comment">/* percentage of rejected low intensity pixels before determining</span>
+<a name="l00069"></a>00069 <span class="comment">           image statistics (mean and standard deviation)*/</span>
+<a name="l00070"></a>00070         <span class="keywordtype">float</span> loReject ;
+<a name="l00071"></a>00071         <span class="comment">/* percentage of rejected high intensity pixels before determining</span>
+<a name="l00072"></a>00072 <span class="comment">           image statistics (mean and standard deviation) */</span>
+<a name="l00073"></a>00073         <span class="keywordtype">float</span> hiReject ;
+<a name="l00074"></a>00074         <span class="comment">/*name of the data cube storing the found polynomial coefficients*/</span>
+<a name="l00075"></a>00075         <span class="keywordtype">char</span> coeffsCubeName[FILE_NAME_SZ] ;
+<a name="l00076"></a>00076 } detlin_config ;
+<a name="l00077"></a>00077 
+<a name="l00078"></a>00078 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00079"></a>00079 <span class="comment">                               Function prototypes</span>
+<a name="l00080"></a>00080 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00088"></a>00088 detlin_config * 
+<a name="l00089"></a>00089 sinfo_detlin_cfg_create(<span class="keywordtype">void</span>);
+<a name="l00090"></a>00090 
+<a name="l00097"></a>00097 <span class="keywordtype">void</span> 
+<a name="l00098"></a>00098 sinfo_detlin_cfg_destroy(detlin_config * sc);
+<a name="l00099"></a>00099 
+<a name="l00100"></a>00100 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__detlin__ini_8h_source.html b/html/sinfo__detlin__ini_8h_source.html
new file mode 100644
index 0000000..b8fd59a
--- /dev/null
+++ b/html/sinfo__detlin__ini_8h_source.html
@@ -0,0 +1,64 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_detlin_ini.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_detlin_ini.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name    :   sinfo_detlin_ini.h</span>
+<a name="l00022"></a>00022 <span class="comment">   Author       :    Juergen Schreiber</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on   :    April 19, 2002</span>
+<a name="l00024"></a>00024 <span class="comment">   Description  :    prepare handling of .ini file for the search for static </span>
+<a name="l00025"></a>00025 <span class="comment">                        bad pixels</span>
+<a name="l00026"></a>00026 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00027"></a>00027 <span class="preprocessor">#ifndef SINFO_DETLIN_INI_H</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_DETLIN_INI_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00030"></a>00030 <span class="comment">                                Includes</span>
+<a name="l00031"></a>00031 <span class="comment">---------------------------------------------------------------------------*/</span>
+<a name="l00032"></a>00032 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include "sinfo_detlin_cfg.h"</span>
+<a name="l00034"></a>00034 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00035"></a>00035 <span class="comment">                                Defines</span>
+<a name="l00036"></a>00036 <span class="comment">---------------------------------------------------------------------------*/</span>
+<a name="l00037"></a>00037 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00038"></a>00038 <span class="comment">                             Function prototypes </span>
+<a name="l00039"></a>00039 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00051"></a>00051 <span class="keywordtype">int</span> 
+<a name="l00052"></a>00052 generateDetlin_ini_file(
+<a name="l00053"></a>00053         <span class="keywordtype">char</span> * ini_name,
+<a name="l00054"></a>00054         <span class="keywordtype">char</span> * name_i,
+<a name="l00055"></a>00055         <span class="keywordtype">char</span> * name_o
+<a name="l00056"></a>00056 );
+<a name="l00065"></a>00065 detlin_config * 
+<a name="l00066"></a>00066 parse_detlin_ini_file(<span class="keywordtype">char</span> * ini_name) ;
+<a name="l00067"></a>00067 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__detlin__ini__by__cpl_8c_source.html b/html/sinfo__detlin__ini__by__cpl_8c_source.html
new file mode 100644
index 0000000..e953354
--- /dev/null
+++ b/html/sinfo__detlin__ini__by__cpl_8c_source.html
@@ -0,0 +1,234 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_detlin_ini_by_cpl.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_detlin_ini_by_cpl.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name    :   sinfo_detlin_ini_by_cpl.c</span>
+<a name="l00022"></a>00022 <span class="comment">   Author       :   Andrea Modigliani</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on   :    May 17, 2004</span>
+<a name="l00024"></a>00024 <span class="comment">   Description  :    produce and read an .ini file for the search of static</span>
+<a name="l00025"></a>00025 <span class="comment">                        bad pixels</span>
+<a name="l00026"></a>00026 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00027"></a>00027 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00029"></a>00029 <span class="preprocessor">#endif</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00031"></a>00031 <span class="comment">                                Includes</span>
+<a name="l00032"></a>00032 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include <string.h></span>
+<a name="l00034"></a>00034 <span class="preprocessor">#include "sinfo_detlin_ini_by_cpl.h"</span>
+<a name="l00035"></a>00035 <span class="preprocessor">#include "sinfo_error.h"</span>
+<a name="l00036"></a>00036 <span class="preprocessor">#include "sinfo_hidden.h"</span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include "sinfo_raw_types.h"</span>
+<a name="l00038"></a>00038 <span class="preprocessor">#include "sinfo_functions.h"</span>
+<a name="l00039"></a>00039 <span class="preprocessor">#include "sinfo_file_handling.h"</span>
+<a name="l00040"></a>00040 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00041"></a>00041 <span class="comment">                    Functions private to this module</span>
+<a name="l00042"></a>00042 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00043"></a>00043 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00044"></a>00044 parse_section_frames(detlin_config *, 
+<a name="l00045"></a>00045                 cpl_frameset* sof, cpl_frameset** raw,<span class="keywordtype">int</span>* status);
+<a name="l00046"></a>00046 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00047"></a>00047 parse_section_response(detlin_config *, cpl_parameterlist* cpl_cfg);
+<a name="l00048"></a>00048 
+<a name="l00068"></a>00068 detlin_config * 
+<a name="l00069"></a>00069 sinfo_parse_cpl_input_detlin(cpl_parameterlist * cpl_cfg, cpl_frameset* sof, 
+<a name="l00070"></a>00070  cpl_frameset** raw)
+<a name="l00071"></a>00071 {
+<a name="l00072"></a>00072 
+<a name="l00073"></a>00073         detlin_config    *    cfg ;
+<a name="l00074"></a>00074         <span class="keywordtype">int</span>                   status ;
+<a name="l00075"></a>00075 
+<a name="l00076"></a>00076         <span class="comment">/* check on input ini file removed */</span>
+<a name="l00077"></a>00077         <span class="comment">/* loading input ini file removed */</span>
+<a name="l00078"></a>00078 
+<a name="l00079"></a>00079 
+<a name="l00080"></a>00080         cfg = sinfo_detlin_cfg_create();
+<a name="l00081"></a>00081 
+<a name="l00082"></a>00082         <span class="comment">/*</span>
+<a name="l00083"></a>00083 <span class="comment">         * Perform sanity checks, fill up the structure with what was</span>
+<a name="l00084"></a>00084 <span class="comment">         * found in the ini file</span>
+<a name="l00085"></a>00085 <span class="comment">         */</span>
+<a name="l00086"></a>00086 
+<a name="l00087"></a>00087         status = 0 ;
+<a name="l00088"></a>00088         parse_section_response(cfg, cpl_cfg);
+<a name="l00089"></a>00089         parse_section_frames(cfg, sof, raw,  &status);
+<a name="l00090"></a>00090         <span class="keywordflow">if</span> (status > 0) {
+<a name="l00091"></a>00091                 <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"parsing cpl input"</span>);
+<a name="l00092"></a>00092                 sinfo_detlin_free(&cfg);
+<a name="l00093"></a>00093                 cfg = NULL ;
+<a name="l00094"></a>00094                 <span class="keywordflow">return</span> NULL ;
+<a name="l00095"></a>00095         }
+<a name="l00096"></a>00096         <span class="keywordflow">return</span> cfg ;
+<a name="l00097"></a>00097 }
+<a name="l00098"></a>00098 
+<a name="l00110"></a>00110 <span class="keyword">static</span> <span class="keywordtype">void</span>   
+<a name="l00111"></a>00111 parse_section_frames(detlin_config * cfg,
+<a name="l00112"></a>00112              cpl_frameset * sof,
+<a name="l00113"></a>00113                      cpl_frameset** raw,
+<a name="l00114"></a>00114                      <span class="keywordtype">int</span>* status)
+<a name="l00115"></a>00115 {
+<a name="l00116"></a>00116 
+<a name="l00117"></a>00117    <span class="keywordtype">int</span>                     i=0;
+<a name="l00118"></a>00118    <span class="keywordtype">char</span>* tag=NULL;
+<a name="l00119"></a>00119    <span class="keywordtype">int</span>  nraw = 0;
+<a name="l00120"></a>00120    <span class="keywordtype">int</span>  nraw_good = 0;
+<a name="l00121"></a>00121    cpl_frame* frame=NULL;
+<a name="l00122"></a>00122    <span class="keywordtype">char</span> spat_res[FILE_NAME_SZ];
+<a name="l00123"></a>00123    <span class="keywordtype">char</span> lamp_status[FILE_NAME_SZ];
+<a name="l00124"></a>00124    <span class="keywordtype">char</span> band[FILE_NAME_SZ];
+<a name="l00125"></a>00125    <span class="keywordtype">int</span> ins_set=0;
+<a name="l00126"></a>00126   
+<a name="l00127"></a>00127    sinfo_extract_raw_frames_type(sof,raw,RAW_LINEARITY_LAMP);
+<a name="l00128"></a>00128 
+<a name="l00129"></a>00129    nraw=cpl_frameset_get_size(*raw);
+<a name="l00130"></a>00130  
+<a name="l00131"></a>00131    <span class="keywordflow">if</span> (nraw < 1) {
+<a name="l00132"></a>00132       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>( <span class="stringliteral">"Too few (%d) raw frames (%s)  present in"</span>
+<a name="l00133"></a>00133              <span class="stringliteral">"frameset!Aborting..."</span>,nraw, RAW_LINEARITY_LAMP);
+<a name="l00134"></a>00134       (*status)++;
+<a name="l00135"></a>00135       <span class="keywordflow">return</span>;
+<a name="l00136"></a>00136    }
+<a name="l00137"></a>00137 
+<a name="l00138"></a>00138 
+<a name="l00139"></a>00139 
+<a name="l00140"></a>00140    <span class="comment">/* get "general:infile" read it, check input sinfo_matrix */</span>
+<a name="l00141"></a>00141    <span class="comment">/* Allocate structures to go into the blackboard */</span>
+<a name="l00142"></a>00142    cfg->framelist = cpl_malloc(nraw * <span class="keyword">sizeof</span>(<span class="keywordtype">char</span>*)); 
+<a name="l00143"></a>00143    
+<a name="l00144"></a>00144   <span class="comment">/* read input frames */</span>
+<a name="l00145"></a>00145    <span class="keywordflow">for</span> (i=0 ; i<nraw ; i++) {
+<a name="l00146"></a>00146      <span class="comment">/* cfg->framelist[i] = cpl_malloc(FILE_NAME_SZ * sizeof(char));  */</span>
+<a name="l00147"></a>00147       frame = cpl_frameset_get_frame(*raw,i);
+<a name="l00148"></a>00148      <span class="keywordflow">if</span>(sinfo_file_exists((<span class="keywordtype">char</span>*)cpl_frame_get_filename(frame))==1) 
+<a name="l00149"></a>00149     {
+<a name="l00150"></a>00150           tag = (<span class="keywordtype">char</span>*)cpl_frame_get_tag(frame) ;
+<a name="l00151"></a>00151       <span class="keywordflow">if</span>(sinfo_is_flat_lindet(tag) || sinfo_is_dark(tag)) {
+<a name="l00152"></a>00152           <span class="comment">/* Store file name into framelist */</span>
+<a name="l00153"></a>00153              cfg->framelist[i]=cpl_strdup(cpl_frame_get_filename(frame));
+<a name="l00154"></a>00154              nraw_good++;
+<a name="l00155"></a>00155       }
+<a name="l00156"></a>00156     }
+<a name="l00157"></a>00157    }
+<a name="l00158"></a>00158 
+<a name="l00159"></a>00159    <span class="comment">/* Copy relevant information into the blackboard */</span>
+<a name="l00160"></a>00160    cfg->nframes         = nraw_good ;
+<a name="l00161"></a>00161 
+<a name="l00162"></a>00162 
+<a name="l00163"></a>00163    <span class="keywordflow">if</span> (nraw_good < (cfg->order+1)) {
+<a name="l00164"></a>00164       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>( <span class="stringliteral">"Too few (%d) raw frames (%s)  present in"</span>
+<a name="l00165"></a>00165              <span class="stringliteral">"frameset as we do a %d order polymnomial fit"</span> 
+<a name="l00166"></a>00166                          <span class="stringliteral">"!Aborting..."</span>,nraw_good, 
+<a name="l00167"></a>00167                          RAW_LINEARITY_LAMP,cfg->order);
+<a name="l00168"></a>00168 
+<a name="l00169"></a>00169       (*status)++;
+<a name="l00170"></a>00170       <span class="keywordflow">return</span>;
+<a name="l00171"></a>00171    }
+<a name="l00172"></a>00172 
+<a name="l00173"></a>00173 
+<a name="l00174"></a>00174    strcpy(cfg -> outName, BP_LIN_OUT_FILENAME);
+<a name="l00175"></a>00175 
+<a name="l00176"></a>00176    check_nomsg(frame = cpl_frameset_get_frame(*raw,0));
+<a name="l00177"></a>00177    sinfo_get_spatial_res(frame,spat_res);
+<a name="l00178"></a>00178  
+<a name="l00179"></a>00179    <span class="keywordflow">switch</span>(sinfo_frame_is_on(frame)) 
+<a name="l00180"></a>00180      {
+<a name="l00181"></a>00181    <span class="keywordflow">case</span> 0: 
+<a name="l00182"></a>00182       strcpy(lamp_status,<span class="stringliteral">"on"</span>);
+<a name="l00183"></a>00183       <span class="keywordflow">break</span>;
+<a name="l00184"></a>00184     <span class="keywordflow">case</span> 1: 
+<a name="l00185"></a>00185       strcpy(lamp_status,<span class="stringliteral">"off"</span>);
+<a name="l00186"></a>00186       <span class="keywordflow">break</span>;
+<a name="l00187"></a>00187     <span class="keywordflow">case</span> -1:
+<a name="l00188"></a>00188       strcpy(lamp_status,<span class="stringliteral">"undefined"</span>);
+<a name="l00189"></a>00189       <span class="keywordflow">break</span>;
+<a name="l00190"></a>00190     <span class="keywordflow">default</span>: 
+<a name="l00191"></a>00191       strcpy(lamp_status,<span class="stringliteral">"undefined"</span>);
+<a name="l00192"></a>00192       <span class="keywordflow">break</span>;
+<a name="l00193"></a>00193 
+<a name="l00194"></a>00194 
+<a name="l00195"></a>00195      }
+<a name="l00196"></a>00196 
+<a name="l00197"></a>00197    sinfo_get_band(frame,band);
+<a name="l00198"></a>00198    sinfo_msg(<span class="stringliteral">"Spatial resolution: %s lamp status: %s band: %s \n"</span>,
+<a name="l00199"></a>00199                      spat_res,              lamp_status,    band);
+<a name="l00200"></a>00200 
+<a name="l00201"></a>00201 
+<a name="l00202"></a>00202    sinfo_get_ins_set(band,&ins_set);
+<a name="l00203"></a>00203 
+<a name="l00204"></a>00204   
+<a name="l00205"></a>00205   cleanup:
+<a name="l00206"></a>00206 
+<a name="l00207"></a>00207    <span class="keywordflow">return</span>;
+<a name="l00208"></a>00208 }
+<a name="l00217"></a>00217 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00218"></a>00218 parse_section_response(detlin_config * cfg,cpl_parameterlist *   cpl_cfg)
+<a name="l00219"></a>00219 {
+<a name="l00220"></a>00220    cpl_parameter *p;     
+<a name="l00221"></a>00221 
+<a name="l00222"></a>00222    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.bp_lin.order"</span>);
+<a name="l00223"></a>00223    cfg -> order = cpl_parameter_get_int(p);
+<a name="l00224"></a>00224  
+<a name="l00225"></a>00225    p = cpl_parameterlist_find(cpl_cfg,<span class="stringliteral">"sinfoni.bp_lin.thresh_sigma_factor"</span>);
+<a name="l00226"></a>00226    cfg->threshSigmaFactor = (float) cpl_parameter_get_double(p);
+<a name="l00227"></a>00227 
+<a name="l00228"></a>00228    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.bp_lin.low_rejection"</span>);
+<a name="l00229"></a>00229    cfg -> loReject = (float) cpl_parameter_get_double(p);
+<a name="l00230"></a>00230 
+<a name="l00231"></a>00231    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.bp_lin.high_rejection"</span>);
+<a name="l00232"></a>00232    cfg -> hiReject = (float) cpl_parameter_get_double(p);
+<a name="l00233"></a>00233 
+<a name="l00234"></a>00234    p = cpl_parameterlist_find(cpl_cfg,<span class="stringliteral">"sinfoni.bp_lin.nlin_threshold"</span>);
+<a name="l00235"></a>00235    cfg->nonlinearThresh = (float) cpl_parameter_get_double(p);
+<a name="l00236"></a>00236 
+<a name="l00237"></a>00237    <span class="comment">/* name of the data cube storing the found polynomial coefficients */</span>
+<a name="l00238"></a>00238    strcpy(cfg->coeffsCubeName, BP_LIN_COEFFS_CUBE_OUT_FILENAME);
+<a name="l00239"></a>00239 
+<a name="l00240"></a>00240    return ;
+<a name="l00241"></a>00241 }
+<a name="l00248"></a>00248 <span class="keywordtype">void</span>
+<a name="l00249"></a>00249 sinfo_detlin_free(detlin_config ** cfg)
+<a name="l00250"></a>00250 {  
+<a name="l00251"></a>00251   <span class="keywordtype">int</span> i=0;
+<a name="l00252"></a>00252   <span class="keywordflow">if</span>(*cfg!=NULL) {
+<a name="l00253"></a>00253     <span class="keywordflow">for</span>(i=0;i<(*cfg)->nframes; i++) {
+<a name="l00254"></a>00254       <span class="keywordflow">if</span>((*cfg)->framelist[i] != NULL) cpl_free((*cfg)->framelist[i]);
+<a name="l00255"></a>00255     }
+<a name="l00256"></a>00256     cpl_free((*cfg)->framelist);
+<a name="l00257"></a>00257     sinfo_detlin_cfg_destroy((*cfg));
+<a name="l00258"></a>00258     *cfg = NULL;
+<a name="l00259"></a>00259   }
+<a name="l00260"></a>00260   <span class="keywordflow">return</span>;
+<a name="l00261"></a>00261 
+<a name="l00262"></a>00262 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__detlin__ini__by__cpl_8h_source.html b/html/sinfo__detlin__ini__by__cpl_8h_source.html
new file mode 100644
index 0000000..50971f6
--- /dev/null
+++ b/html/sinfo__detlin__ini__by__cpl_8h_source.html
@@ -0,0 +1,65 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_detlin_ini_by_cpl.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_detlin_ini_by_cpl.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name    :   sinfo_detlin_ini_by_cpl.h</span>
+<a name="l00022"></a>00022 <span class="comment">   Author       :   Andrea Modigliani</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on   :   May 17, 2004</span>
+<a name="l00024"></a>00024 <span class="comment">   Description  :   prepare handling of .ini file for the search for static </span>
+<a name="l00025"></a>00025 <span class="comment">                    bad pixels</span>
+<a name="l00026"></a>00026 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00027"></a>00027 <span class="preprocessor">#ifndef SINFO_DETLIN_INI_BY_CPL_H</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_DETLIN_INI_BY_CPL_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00030"></a>00030 <span class="comment">                                Includes</span>
+<a name="l00031"></a>00031 <span class="comment">---------------------------------------------------------------------------*/</span>
+<a name="l00032"></a>00032 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include "sinfo_detlin_cfg.h"</span>
+<a name="l00034"></a>00034 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00035"></a>00035 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00036"></a>00036 <span class="comment">                                Defines</span>
+<a name="l00037"></a>00037 <span class="comment">---------------------------------------------------------------------------*/</span>
+<a name="l00038"></a>00038 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00039"></a>00039 <span class="comment">                             Function prototypes </span>
+<a name="l00040"></a>00040 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00052"></a>00052 detlin_config * 
+<a name="l00053"></a>00053 sinfo_parse_cpl_input_detlin(cpl_parameterlist * cpl_cfg, 
+<a name="l00054"></a>00054                              cpl_frameset* sof, 
+<a name="l00055"></a>00055                              cpl_frameset** raw);
+<a name="l00056"></a>00056 
+<a name="l00063"></a>00063 <span class="keywordtype">void</span> 
+<a name="l00064"></a>00064 sinfo_detlin_free(detlin_config ** cfg);
+<a name="l00065"></a>00065 
+<a name="l00066"></a>00066 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__detnoise__cfg_8c_source.html b/html/sinfo__detnoise__cfg_8c_source.html
new file mode 100644
index 0000000..76bf3f4
--- /dev/null
+++ b/html/sinfo__detnoise__cfg_8c_source.html
@@ -0,0 +1,69 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_detnoise_cfg.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_detnoise_cfg.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name     :    sinfo_detnoise_cfg.c</span>
+<a name="l00022"></a>00022 <span class="comment">   Autor    :       Juergen Schreiber</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on    :    September 2002</span>
+<a name="l00024"></a>00024 <span class="comment">   Description    :    handles the data structure detnoise_config</span>
+<a name="l00025"></a>00025 <span class="comment"></span>
+<a name="l00026"></a>00026 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00027"></a>00027 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00029"></a>00029 <span class="preprocessor">#endif</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span>
+<a name="l00031"></a>00031 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00032"></a>00032 <span class="comment">                                   Includes</span>
+<a name="l00033"></a>00033 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00034"></a>00034 <span class="preprocessor">#include "sinfo_detnoise_cfg.h"</span>
+<a name="l00042"></a>00042 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00043"></a>00043 <span class="comment">                              Function codes</span>
+<a name="l00044"></a>00044 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00051"></a>00051 detnoise_config * 
+<a name="l00052"></a>00052 sinfo_detnoise_cfg_create(<span class="keywordtype">void</span>)
+<a name="l00053"></a>00053 {
+<a name="l00054"></a>00054     <span class="keywordflow">return</span> cpl_calloc(1, <span class="keyword">sizeof</span>(detnoise_config));
+<a name="l00055"></a>00055 }
+<a name="l00056"></a>00056 
+<a name="l00063"></a>00063 <span class="keywordtype">void</span> 
+<a name="l00064"></a>00064 sinfo_detnoise_cfg_destroy(detnoise_config * sc)
+<a name="l00065"></a>00065 {
+<a name="l00066"></a>00066     <span class="keywordflow">if</span> (sc==NULL) return ;
+<a name="l00067"></a>00067     <span class="comment">/* Free main struct */</span>
+<a name="l00068"></a>00068     cpl_free(sc);
+<a name="l00069"></a>00069 
+<a name="l00070"></a>00070     return ;
+<a name="l00071"></a>00071 }
+<a name="l00072"></a>00072 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__detnoise__cfg_8h_source.html b/html/sinfo__detnoise__cfg_8h_source.html
new file mode 100644
index 0000000..c0376d8
--- /dev/null
+++ b/html/sinfo__detnoise__cfg_8h_source.html
@@ -0,0 +1,92 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_detnoise_cfg.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_detnoise_cfg.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name     :    sinfo_detnoise_cfg.h</span>
+<a name="l00022"></a>00022 <span class="comment">   Author         :    Juergen Schreiber</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on    :    September 2002</span>
+<a name="l00024"></a>00024 <span class="comment">   Description    :    sinfo_detnoise_ini definitions + handling prototypes</span>
+<a name="l00025"></a>00025 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00026"></a>00026 <span class="preprocessor">#ifndef SINFO_DETNOISE_CFG_H</span>
+<a name="l00027"></a>00027 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_DETNOISE_CFG_H</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00029"></a>00029 <span class="comment">                                   Includes</span>
+<a name="l00030"></a>00030 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00031"></a>00031 <span class="preprocessor">#include <stdlib.h></span>
+<a name="l00032"></a>00032 <span class="preprocessor">#include "sinfo_globals.h"</span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00034"></a>00034 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00035"></a>00035 <span class="comment">                                   Defines</span>
+<a name="l00036"></a>00036 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00037"></a>00037 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00038"></a>00038 <span class="comment">                                   New types</span>
+<a name="l00039"></a>00039 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00040"></a>00040 <span class="comment">/*</span>
+<a name="l00041"></a>00041 <span class="comment">  bad pixels search blackboard container</span>
+<a name="l00042"></a>00042 <span class="comment"></span>
+<a name="l00043"></a>00043 <span class="comment">  This structure holds all information related to the bad pixels search</span>
+<a name="l00044"></a>00044 <span class="comment">  routine. It is used as a container for the flux of ancillary data,</span>
+<a name="l00045"></a>00045 <span class="comment">  computed values, and algorithm status. Pixel flux is separated from</span>
+<a name="l00046"></a>00046 <span class="comment">  the blackboard.</span>
+<a name="l00047"></a>00047 <span class="comment">  */</span>
+<a name="l00048"></a>00048 
+<a name="l00049"></a>00049 <span class="keyword">typedef</span> <span class="keyword">struct </span>detnoise_config {
+<a name="l00050"></a>00050 <span class="comment">/*-------General---------*/</span>
+<a name="l00051"></a>00051         <span class="keywordtype">char</span> inFile[FILE_NAME_SZ] ; <span class="comment">/* file name of the file containing </span>
+<a name="l00052"></a>00052 <span class="comment">                                       the list of all input frames */</span>
+<a name="l00053"></a>00053         <span class="keywordtype">char</span> outName[FILE_NAME_SZ] ; <span class="comment">/* output name of resulting bad </span>
+<a name="l00054"></a>00054 <span class="comment">                                        pixel mask (fits file)*/</span>
+<a name="l00055"></a>00055         <span class="keywordtype">char</span> ** framelist ; <span class="comment">/* list of frames */</span>
+<a name="l00056"></a>00056         <span class="keywordtype">int</span>     nframes ; <span class="comment">/* number of frames in frame list */</span>
+<a name="l00057"></a>00057 
+<a name="l00058"></a>00058 <span class="comment">/*------searchBad------*/</span>
+<a name="l00059"></a>00059         <span class="comment">/* factor to the standard deviation of the mean standard deviation. */</span>
+<a name="l00060"></a>00060         <span class="keywordtype">double</span> threshSigmaFactor ;      
+<a name="l00061"></a>00061         <span class="comment">/* percentage of rejected low intensity pixels before determining</span>
+<a name="l00062"></a>00062 <span class="comment">           image statistics (mean and standard deviation)*/</span>
+<a name="l00063"></a>00063         <span class="keywordtype">float</span> loReject ;
+<a name="l00064"></a>00064         <span class="comment">/* percentage of rejected high intensity pixels before determining</span>
+<a name="l00065"></a>00065 <span class="comment">           image statistics (mean and standard deviation) */</span>
+<a name="l00066"></a>00066         <span class="keywordtype">float</span> hiReject ;
+<a name="l00067"></a>00067 } detnoise_config ;
+<a name="l00068"></a>00068 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00069"></a>00069 <span class="comment">                               Function prototypes</span>
+<a name="l00070"></a>00070 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00078"></a>00078 detnoise_config * 
+<a name="l00079"></a>00079 sinfo_detnoise_cfg_create(<span class="keywordtype">void</span>);
+<a name="l00086"></a>00086 <span class="keywordtype">void</span> 
+<a name="l00087"></a>00087 sinfo_detnoise_cfg_destroy(detnoise_config * sc);
+<a name="l00088"></a>00088 
+<a name="l00089"></a>00089 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__detnoise__ini_8h_source.html b/html/sinfo__detnoise__ini_8h_source.html
new file mode 100644
index 0000000..bbb9c5b
--- /dev/null
+++ b/html/sinfo__detnoise__ini_8h_source.html
@@ -0,0 +1,67 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_detnoise_ini.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_detnoise_ini.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name    :   sinfo_detnoise_ini.h</span>
+<a name="l00022"></a>00022 <span class="comment">   Author       :   Juergen Schreiber</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on   :   September 3, 2002</span>
+<a name="l00024"></a>00024 <span class="comment">   Description  :   prepare handling of .ini file for the search for static </span>
+<a name="l00025"></a>00025 <span class="comment">                    bad pixels</span>
+<a name="l00026"></a>00026 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00027"></a>00027 <span class="preprocessor">#ifndef SINFO_DETNOISE_INI_H</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_DETNOISE_INI_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00030"></a>00030 <span class="comment">                                Includes</span>
+<a name="l00031"></a>00031 <span class="comment">---------------------------------------------------------------------------*/</span>
+<a name="l00032"></a>00032 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include "sinfo_detnoise_cfg.h"</span>
+<a name="l00034"></a>00034 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00035"></a>00035 <span class="comment">                                Defines</span>
+<a name="l00036"></a>00036 <span class="comment">---------------------------------------------------------------------------*/</span>
+<a name="l00037"></a>00037 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00038"></a>00038 <span class="comment">                             Function prototypes </span>
+<a name="l00039"></a>00039 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00040"></a>00040 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l00052"></a>00052 <span class="keywordtype">int</span> 
+<a name="l00053"></a>00053 generateDetnoise_ini_file(
+<a name="l00054"></a>00054         <span class="keywordtype">char</span> * ini_name,
+<a name="l00055"></a>00055         <span class="keywordtype">char</span> * name_i,
+<a name="l00056"></a>00056         <span class="keywordtype">char</span> * name_o
+<a name="l00057"></a>00057 );
+<a name="l00066"></a>00066 detnoise_config * 
+<a name="l00067"></a>00067 parse_detnoise_ini_file(<span class="keywordtype">char</span> * ini_name) ;
+<a name="l00068"></a>00068  
+<a name="l00069"></a>00069 
+<a name="l00070"></a>00070 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__detnoise__ini__by__cpl_8c_source.html b/html/sinfo__detnoise__ini__by__cpl_8c_source.html
new file mode 100644
index 0000000..aabce02
--- /dev/null
+++ b/html/sinfo__detnoise__ini__by__cpl_8c_source.html
@@ -0,0 +1,199 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_detnoise_ini_by_cpl.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_detnoise_ini_by_cpl.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name    :   sinfo_detnoise_ini.c</span>
+<a name="l00022"></a>00022 <span class="comment">   Author       :   Andrea Modiglini</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on   :   May 17, 2004</span>
+<a name="l00024"></a>00024 <span class="comment">   Description  :   produce and read an .ini file for the search of static</span>
+<a name="l00025"></a>00025 <span class="comment">                    bad pixels</span>
+<a name="l00026"></a>00026 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00027"></a>00027 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00029"></a>00029 <span class="preprocessor">#endif</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00031"></a>00031 <span class="comment">                                Includes</span>
+<a name="l00032"></a>00032 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include <string.h></span>
+<a name="l00034"></a>00034 <span class="preprocessor">#include "sinfo_detnoise_ini_by_cpl.h"</span>
+<a name="l00035"></a>00035 <span class="preprocessor">#include "sinfo_raw_types.h"</span>
+<a name="l00036"></a>00036 <span class="preprocessor">#include "sinfo_globals.h"</span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include "sinfo_hidden.h"</span>
+<a name="l00038"></a>00038 <span class="preprocessor">#include "sinfo_functions.h"</span>
+<a name="l00039"></a>00039 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00040"></a>00040 <span class="comment">                    Functions private to this module</span>
+<a name="l00041"></a>00041 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00042"></a>00042 
+<a name="l00043"></a>00043 <span class="keyword">static</span> <span class="keywordtype">void</span>  
+<a name="l00044"></a>00044 parse_section_frames(detnoise_config * cfg, 
+<a name="l00045"></a>00045                      cpl_frameset* sof, 
+<a name="l00046"></a>00046                      cpl_frameset** raw, 
+<a name="l00047"></a>00047                      <span class="keywordtype">int</span>* status);
+<a name="l00048"></a>00048 <span class="keyword">static</span> <span class="keywordtype">void</span>  
+<a name="l00049"></a>00049 parse_section_badsearch(detnoise_config * cfg, cpl_parameterlist* cpl_cfg);
+<a name="l00050"></a>00050 
+<a name="l00058"></a>00058 <span class="comment">/****************************************************************************/</span>
+<a name="l00070"></a>00070 detnoise_config * 
+<a name="l00071"></a>00071 sinfo_parse_cpl_input_detnoise(cpl_parameterlist * cpl_cfg, 
+<a name="l00072"></a>00072                                cpl_frameset* sof, 
+<a name="l00073"></a>00073                                cpl_frameset** raw)
+<a name="l00074"></a>00074 {
+<a name="l00075"></a>00075 
+<a name="l00076"></a>00076   detnoise_config    *    cfg ;
+<a name="l00077"></a>00077   <span class="keywordtype">int</span> status=0;
+<a name="l00078"></a>00078   <span class="comment">/* Removed check on ini_file */</span>
+<a name="l00079"></a>00079   <span class="comment">/* Removed load of ini file */</span>
+<a name="l00080"></a>00080 
+<a name="l00081"></a>00081   cfg = sinfo_detnoise_cfg_create();
+<a name="l00082"></a>00082 
+<a name="l00083"></a>00083    <span class="comment">/*</span>
+<a name="l00084"></a>00084 <span class="comment">   * Perform sanity checks, fill up the structure with what was</span>
+<a name="l00085"></a>00085 <span class="comment">   * found in the ini file</span>
+<a name="l00086"></a>00086 <span class="comment">   */</span>
+<a name="l00087"></a>00087   parse_section_badsearch(cfg, cpl_cfg);
+<a name="l00088"></a>00088   parse_section_frames(cfg, sof, raw, &status);
+<a name="l00089"></a>00089 
+<a name="l00090"></a>00090          <span class="keywordflow">if</span> (status > 0) {
+<a name="l00091"></a>00091                 <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"parsing cpl input"</span>);
+<a name="l00092"></a>00092                 sinfo_detnoise_free(cfg);
+<a name="l00093"></a>00093                 cfg = NULL ;
+<a name="l00094"></a>00094                 <span class="keywordflow">return</span> NULL ;
+<a name="l00095"></a>00095         }
+<a name="l00096"></a>00096   <span class="keywordflow">return</span> cfg ;
+<a name="l00097"></a>00097 }
+<a name="l00098"></a>00098 
+<a name="l00099"></a>00099 
+<a name="l00110"></a>00110 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00111"></a>00111 parse_section_frames(detnoise_config * cfg,
+<a name="l00112"></a>00112              cpl_frameset * sof,
+<a name="l00113"></a>00113                      cpl_frameset** raw,
+<a name="l00114"></a>00114                      <span class="keywordtype">int</span>* status)
+<a name="l00115"></a>00115 {
+<a name="l00116"></a>00116    <span class="keywordtype">int</span>                     i;
+<a name="l00117"></a>00117 
+<a name="l00118"></a>00118    <span class="keywordtype">int</span>  nraw = 0;
+<a name="l00119"></a>00119    cpl_frame* frame=NULL;
+<a name="l00120"></a>00120 
+<a name="l00121"></a>00121     <span class="keywordtype">char</span> spat_res[FILE_NAME_SZ];
+<a name="l00122"></a>00122    <span class="keywordtype">char</span> lamp_status[FILE_NAME_SZ];
+<a name="l00123"></a>00123    <span class="keywordtype">char</span> band[FILE_NAME_SZ];
+<a name="l00124"></a>00124    <span class="keywordtype">int</span> ins_set=0;
+<a name="l00125"></a>00125 
+<a name="l00126"></a>00126 
+<a name="l00127"></a>00127 
+<a name="l00128"></a>00128    sinfo_extract_raw_frames_type2(sof,raw,RAW_DARK);
+<a name="l00129"></a>00129 
+<a name="l00130"></a>00130    nraw = cpl_frameset_get_size(*raw);
+<a name="l00131"></a>00131    <span class="keywordflow">if</span> (nraw < 1) {
+<a name="l00132"></a>00132       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Too few (%d) raw frames (%s) present in"</span>
+<a name="l00133"></a>00133             <span class="stringliteral">"frameset!Aborting..."</span>,nraw,RAW_DARK);
+<a name="l00134"></a>00134       (*status)++;
+<a name="l00135"></a>00135           <span class="keywordflow">return</span>;
+<a name="l00136"></a>00136    }
+<a name="l00137"></a>00137  
+<a name="l00138"></a>00138    <span class="comment">/* get "general:infile" read it, check input sinfo_matrix */</span>
+<a name="l00139"></a>00139    <span class="comment">/* Allocate structures to go into the blackboard */</span>
+<a name="l00140"></a>00140    <span class="comment">/* Copy relevant information into the blackboard */</span>
+<a name="l00141"></a>00141    cfg->nframes       = nraw ;
+<a name="l00142"></a>00142    cfg->framelist  =  cpl_malloc(nraw*<span class="keyword">sizeof</span>(<span class="keywordtype">char</span>*)); 
+<a name="l00143"></a>00143   <span class="comment">/* read input frames */</span>
+<a name="l00144"></a>00144    <span class="keywordflow">for</span> (i=0 ; i<nraw ; i++) {
+<a name="l00145"></a>00145       frame = cpl_frameset_get_frame(*raw,i);
+<a name="l00146"></a>00146       <span class="comment">/* Store file name into framelist */</span>
+<a name="l00147"></a>00147        cfg->framelist[i]=cpl_strdup(cpl_frame_get_filename(frame));
+<a name="l00148"></a>00148    }
+<a name="l00149"></a>00149  
+<a name="l00150"></a>00150    strcpy(cfg -> outName, BP_NOISE_OUT_FILENAME);
+<a name="l00151"></a>00151 
+<a name="l00152"></a>00152    frame = cpl_frameset_get_frame(*raw,0);
+<a name="l00153"></a>00153    sinfo_get_spatial_res(frame,spat_res);
+<a name="l00154"></a>00154    <span class="keywordflow">switch</span>(sinfo_frame_is_on(frame)) 
+<a name="l00155"></a>00155      {
+<a name="l00156"></a>00156    <span class="keywordflow">case</span> 0: 
+<a name="l00157"></a>00157       strcpy(lamp_status,<span class="stringliteral">"on"</span>);
+<a name="l00158"></a>00158       <span class="keywordflow">break</span>;
+<a name="l00159"></a>00159     <span class="keywordflow">case</span> 1: 
+<a name="l00160"></a>00160       strcpy(lamp_status,<span class="stringliteral">"off"</span>);
+<a name="l00161"></a>00161       <span class="keywordflow">break</span>;
+<a name="l00162"></a>00162     <span class="keywordflow">case</span> -1:
+<a name="l00163"></a>00163       strcpy(lamp_status,<span class="stringliteral">"undefined"</span>);
+<a name="l00164"></a>00164       <span class="keywordflow">break</span>;
+<a name="l00165"></a>00165     <span class="keywordflow">default</span>: 
+<a name="l00166"></a>00166       strcpy(lamp_status,<span class="stringliteral">"undefined"</span>);
+<a name="l00167"></a>00167       <span class="keywordflow">break</span>;
+<a name="l00168"></a>00168      }
+<a name="l00169"></a>00169 
+<a name="l00170"></a>00170    sinfo_get_band(frame,band);
+<a name="l00171"></a>00171    sinfo_msg(<span class="stringliteral">"Spatial resolution: %s lamp status: %s band: %s \n"</span>,
+<a name="l00172"></a>00172                      spat_res,    lamp_status,    band);
+<a name="l00173"></a>00173    
+<a name="l00174"></a>00174 
+<a name="l00175"></a>00175    sinfo_get_ins_set(band,&ins_set);
+<a name="l00176"></a>00176    <span class="keywordflow">return</span>;
+<a name="l00177"></a>00177 
+<a name="l00178"></a>00178 
+<a name="l00179"></a>00179 
+<a name="l00180"></a>00180 
+<a name="l00181"></a>00181 }
+<a name="l00182"></a>00182 
+<a name="l00190"></a>00190 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00191"></a>00191 parse_section_badsearch(detnoise_config * cfg,cpl_parameterlist *   cpl_cfg)
+<a name="l00192"></a>00192 {  
+<a name="l00193"></a>00193    cpl_parameter *p;   
+<a name="l00194"></a>00194 
+<a name="l00195"></a>00195    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.bp_noise.low_rejection"</span>);
+<a name="l00196"></a>00196    cfg -> loReject = cpl_parameter_get_double(p);
+<a name="l00197"></a>00197 
+<a name="l00198"></a>00198    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.bp_noise.high_rejection"</span>);
+<a name="l00199"></a>00199    cfg -> hiReject = cpl_parameter_get_double(p);
+<a name="l00200"></a>00200 
+<a name="l00201"></a>00201    p = cpl_parameterlist_find(cpl_cfg,<span class="stringliteral">"sinfoni.bp_noise.thresh_sigma_factor"</span>);
+<a name="l00202"></a>00202    cfg->threshSigmaFactor = cpl_parameter_get_double(p);
+<a name="l00203"></a>00203 
+<a name="l00204"></a>00204 }
+<a name="l00212"></a>00212 <span class="keywordtype">void</span>
+<a name="l00213"></a>00213 sinfo_detnoise_free(detnoise_config * cfg)
+<a name="l00214"></a>00214 {
+<a name="l00215"></a>00215   <span class="keywordtype">int</span> i=0;
+<a name="l00216"></a>00216   <span class="keywordflow">if</span>(cfg != NULL) {
+<a name="l00217"></a>00217     <span class="keywordflow">for</span>(i=0;i<cfg->nframes;i++){
+<a name="l00218"></a>00218       <span class="keywordflow">if</span>(cfg->framelist[i] != NULL) cpl_free(cfg->framelist[i]);
+<a name="l00219"></a>00219     }
+<a name="l00220"></a>00220     <span class="keywordflow">if</span>(cfg->framelist) {
+<a name="l00221"></a>00221       <span class="keywordflow">if</span>(cfg->framelist != NULL) cpl_free(cfg->framelist);
+<a name="l00222"></a>00222     }
+<a name="l00223"></a>00223     sinfo_detnoise_cfg_destroy(cfg);
+<a name="l00224"></a>00224   }
+<a name="l00225"></a>00225 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__detnoise__ini__by__cpl_8h_source.html b/html/sinfo__detnoise__ini__by__cpl_8h_source.html
new file mode 100644
index 0000000..44fd88c
--- /dev/null
+++ b/html/sinfo__detnoise__ini__by__cpl_8h_source.html
@@ -0,0 +1,66 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_detnoise_ini_by_cpl.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_detnoise_ini_by_cpl.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name    :   sinfo_detnoise_ini.h</span>
+<a name="l00022"></a>00022 <span class="comment">   Author       :    Juergen Schreiber</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on   :    September 3, 2002</span>
+<a name="l00024"></a>00024 <span class="comment">   Description  :   prepare handling of .ini file for the search for static </span>
+<a name="l00025"></a>00025 <span class="comment">                        bad pixels</span>
+<a name="l00026"></a>00026 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00027"></a>00027 <span class="preprocessor">#ifndef SINFO_DETNOISE_INI_BY_CPL_H</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_DETNOISE_INI_BY_CPL_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00030"></a>00030 <span class="comment">                                Includes</span>
+<a name="l00031"></a>00031 <span class="comment">---------------------------------------------------------------------------*/</span>
+<a name="l00032"></a>00032 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include "sinfo_detnoise_cfg.h"</span>
+<a name="l00034"></a>00034 <span class="preprocessor">#include "sinfo_msg.h"</span> 
+<a name="l00035"></a>00035 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00036"></a>00036 <span class="comment">                                Defines</span>
+<a name="l00037"></a>00037 <span class="comment">---------------------------------------------------------------------------*/</span>
+<a name="l00038"></a>00038 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00039"></a>00039 <span class="comment">                             Function prototypes </span>
+<a name="l00040"></a>00040 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00041"></a>00041 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l00053"></a>00053 detnoise_config * 
+<a name="l00054"></a>00054 sinfo_parse_cpl_input_detnoise(cpl_parameterlist * cpl_cfg, 
+<a name="l00055"></a>00055                                cpl_frameset* sof, 
+<a name="l00056"></a>00056                                cpl_frameset** raw);
+<a name="l00057"></a>00057 
+<a name="l00064"></a>00064 <span class="keywordtype">void</span> 
+<a name="l00065"></a>00065 sinfo_detnoise_free(detnoise_config * cfg);
+<a name="l00066"></a>00066 
+<a name="l00067"></a>00067 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__dfs_8c_source.html b/html/sinfo__dfs_8c_source.html
new file mode 100644
index 0000000..4cb5169
--- /dev/null
+++ b/html/sinfo__dfs_8c_source.html
@@ -0,0 +1,4220 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_dfs.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_dfs.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_dfs.c,v 1.41 2012/04/26 14:44:48 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the SINFONI Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2012/04/26 14:44:48 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.41 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span><span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00032"></a>00032 <span class="comment">  Macros</span>
+<a name="l00033"></a>00033 <span class="comment">  ----------------------------------------------------------------------------*/</span>
+<a name="l00034"></a>00034 
+<a name="l00035"></a>00035 
+<a name="l00036"></a>00036 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00037"></a>00037 <span class="comment">  Private to this module</span>
+<a name="l00038"></a>00038 <span class="comment">  ----------------------------------------------------------------------------*/</span>
+<a name="l00039"></a>00039 
+<a name="l00040"></a>00040 
+<a name="l00041"></a>00041 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00042"></a>00042 <span class="comment">  Includes</span>
+<a name="l00043"></a>00043 <span class="comment">  ----------------------------------------------------------------------------*/</span>
+<a name="l00044"></a>00044 <span class="preprocessor">#include "sinfo_dfs.h"</span>
+<a name="l00045"></a>00045 <span class="preprocessor">#include <assert.h></span>
+<a name="l00046"></a>00046 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00047"></a>00047 <span class="preprocessor">#include <math.h></span>
+<a name="l00048"></a>00048 <span class="preprocessor">#include "sinfo_error.h"</span>
+<a name="l00049"></a>00049 <span class="preprocessor">#include "sinfo_utilities.h"</span>
+<a name="l00050"></a>00050 <span class="preprocessor">#include "sinfo_utils_wrappers.h"</span>
+<a name="l00051"></a>00051 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00052"></a>00052 <span class="preprocessor">#include "sinfo_globals.h"</span>
+<a name="l00053"></a>00053 <span class="preprocessor">#include "sinfo_pro_save.h"</span>
+<a name="l00054"></a>00054 <span class="preprocessor">#include "sinfo_skycor.h"</span>
+<a name="l00055"></a>00055 <span class="preprocessor">#include "sinfo_file_handling.h"</span>
+<a name="l00056"></a>00056 <span class="preprocessor">#include <unistd.h></span>
+<a name="l00057"></a>00057 <span class="preprocessor">#include <stdio.h></span>
+<a name="l00059"></a>00059 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00065"></a>00065 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00066"></a>00066 
+<a name="l00067"></a>00067 <span class="comment">/* defines */</span>
+<a name="l00068"></a>00068 
+<a name="l00069"></a>00069 <span class="preprocessor">#define FITS_MAGIC_SZ      6</span>
+<a name="l00070"></a>00070 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_FIT_AMOEBA_NMAX 5000</span>
+<a name="l00071"></a>00071 <span class="preprocessor"></span>
+<a name="l00072"></a>00072 <span class="comment">/* function prototypes */</span>
+<a name="l00073"></a>00073 <span class="comment">/*</span>
+<a name="l00074"></a>00074 <span class="comment">  static int</span>
+<a name="l00075"></a>00075 <span class="comment">  sinfo_stat_rectangle(cpl_image* img,</span>
+<a name="l00076"></a>00076 <span class="comment">  const int kappa,</span>
+<a name="l00077"></a>00077 <span class="comment">  const int nclip,</span>
+<a name="l00078"></a>00078 <span class="comment">  double *mean,</span>
+<a name="l00079"></a>00079 <span class="comment">  double *stdev);</span>
+<a name="l00080"></a>00080 <span class="comment">*/</span>
+<a name="l00081"></a>00081 <span class="keyword">static</span> <span class="keywordtype">void</span>
+<a name="l00082"></a>00082 sinfo_fit_amoeba_get_psum(<span class="keywordtype">int</span> ndim, <span class="keywordtype">int</span> mpts, <span class="keywordtype">double</span>** p, <span class="keywordtype">double</span>* psum);
+<a name="l00083"></a>00083 
+<a name="l00084"></a>00084 
+<a name="l00085"></a>00085 <span class="keyword">static</span>  <span class="keywordtype">double</span>
+<a name="l00086"></a>00086 sinfo_fit_amotry(<span class="keywordtype">double</span>** p,
+<a name="l00087"></a>00087                  <span class="keywordtype">double</span> y[],
+<a name="l00088"></a>00088                  <span class="keywordtype">double</span> psum[],
+<a name="l00089"></a>00089                  <span class="keywordtype">int</span> ndim,
+<a name="l00090"></a>00090                  <span class="keywordtype">double</span> (*funk)(<span class="keywordtype">double</span>[]),
+<a name="l00091"></a>00091                  <span class="keywordtype">int</span> ihi,
+<a name="l00092"></a>00092                  <span class="keywordtype">double</span> fac);
+<a name="l00093"></a>00093 
+<a name="l00094"></a>00094 
+<a name="l00095"></a>00095 <span class="keyword">static</span> <span class="keywordtype">double</span>
+<a name="l00096"></a>00096 get_chisq(<span class="keywordtype">int</span> N, <span class="keywordtype">int</span> D,
+<a name="l00097"></a>00097           <span class="keywordtype">int</span> (*f)(<span class="keyword">const</span> <span class="keywordtype">double</span> x[], <span class="keyword">const</span> <span class="keywordtype">double</span> a[], <span class="keywordtype">double</span> *result),
+<a name="l00098"></a>00098           <span class="keyword">const</span> <span class="keywordtype">double</span> *a,
+<a name="l00099"></a>00099           <span class="keyword">const</span> <span class="keywordtype">double</span> *x,
+<a name="l00100"></a>00100           <span class="keyword">const</span> <span class="keywordtype">double</span> *y,
+<a name="l00101"></a>00101           <span class="keyword">const</span> <span class="keywordtype">double</span> *sigma);
+<a name="l00102"></a>00102 
+<a name="l00103"></a>00103 <span class="keyword">static</span> <span class="keywordtype">int</span> get_candidate(<span class="keyword">const</span> <span class="keywordtype">double</span> *a, <span class="keyword">const</span> <span class="keywordtype">int</span> ia[],
+<a name="l00104"></a>00104                          <span class="keywordtype">int</span> M, <span class="keywordtype">int</span> N, <span class="keywordtype">int</span> D,
+<a name="l00105"></a>00105                          <span class="keywordtype">double</span> lambda,
+<a name="l00106"></a>00106                          <span class="keywordtype">int</span>    (*f)(<span class="keyword">const</span> <span class="keywordtype">double</span> x[], <span class="keyword">const</span> <span class="keywordtype">double</span> a[],
+<a name="l00107"></a>00107                                      <span class="keywordtype">double</span> *result),
+<a name="l00108"></a>00108                          <span class="keywordtype">int</span> (*dfda)(<span class="keyword">const</span> <span class="keywordtype">double</span> x[], <span class="keyword">const</span> <span class="keywordtype">double</span> a[],
+<a name="l00109"></a>00109                                      <span class="keywordtype">double</span> result[]),
+<a name="l00110"></a>00110                          <span class="keyword">const</span> <span class="keywordtype">double</span> *x,
+<a name="l00111"></a>00111                          <span class="keyword">const</span> <span class="keywordtype">double</span> *y,
+<a name="l00112"></a>00112                          <span class="keyword">const</span> <span class="keywordtype">double</span> *sigma,
+<a name="l00113"></a>00113                          <span class="keywordtype">double</span> *partials,
+<a name="l00114"></a>00114                          cpl_matrix *alpha,
+<a name="l00115"></a>00115                          cpl_matrix *beta,
+<a name="l00116"></a>00116                          <span class="keywordtype">double</span> *a_da);
+<a name="l00117"></a>00117 
+<a name="l00118"></a>00118 
+<a name="l00119"></a>00119 
+<a name="l00120"></a>00120 <span class="keywordtype">int</span>
+<a name="l00121"></a>00121 sinfo_frame_is_raw_dark(<span class="keywordtype">char</span> * tag);
+<a name="l00122"></a>00122 
+<a name="l00128"></a>00128 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00135"></a>00135 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00136"></a>00136 cpl_frameset *
+<a name="l00137"></a>00137 sinfo_frameset_extract(<span class="keyword">const</span> cpl_frameset *frames,
+<a name="l00138"></a>00138                        <span class="keyword">const</span> <span class="keywordtype">char</span> *tag)
+<a name="l00139"></a>00139 {
+<a name="l00140"></a>00140    cpl_frameset *subset = NULL;
+<a name="l00141"></a>00141    <span class="keyword">const</span> cpl_frame *f;
+<a name="l00142"></a>00142 
+<a name="l00143"></a>00143 
+<a name="l00144"></a>00144 
+<a name="l00145"></a>00145    assure( frames != NULL, CPL_ERROR_ILLEGAL_INPUT, <span class="stringliteral">"Null frameset"</span> );
+<a name="l00146"></a>00146    assure( tag    != NULL, CPL_ERROR_ILLEGAL_INPUT, <span class="stringliteral">"Null tag"</span> );
+<a name="l00147"></a>00147 
+<a name="l00148"></a>00148    subset = cpl_frameset_new();
+<a name="l00149"></a>00149 
+<a name="l00150"></a>00150    <span class="keywordflow">for</span> (f = cpl_frameset_find_const(frames, tag);
+<a name="l00151"></a>00151         f != NULL;
+<a name="l00152"></a>00152         f = cpl_frameset_find_const(frames, NULL)) {
+<a name="l00153"></a>00153 
+<a name="l00154"></a>00154       cpl_frameset_insert(subset, cpl_frame_duplicate(f));
+<a name="l00155"></a>00155    }
+<a name="l00156"></a>00156   cleanup:
+<a name="l00157"></a>00157    <span class="keywordflow">return</span> subset;
+<a name="l00158"></a>00158 }
+<a name="l00159"></a>00159 
+<a name="l00160"></a>00160 
+<a name="l00161"></a>00161 
+<a name="l00167"></a>00167 <span class="keywordtype">int</span> sinfo_print_rec_status(<span class="keyword">const</span> <span class="keywordtype">int</span> val) {
+<a name="l00168"></a>00168    <span class="keywordflow">if</span>(cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l00169"></a>00169       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Recipe status at %d"</span>,val);
+<a name="l00170"></a>00170       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"%s"</span>,(<span class="keyword">const</span> <span class="keywordtype">char</span>*) cpl_error_get_message());
+<a name="l00171"></a>00171       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"%s"</span>,(<span class="keyword">const</span> <span class="keywordtype">char</span>*) cpl_error_get_where());
+<a name="l00172"></a>00172       <span class="keywordflow">return</span> -1;
+<a name="l00173"></a>00173    }
+<a name="l00174"></a>00174    <span class="keywordflow">return</span> 0;
+<a name="l00175"></a>00175 }
+<a name="l00176"></a>00176 
+<a name="l00177"></a>00177 
+<a name="l00194"></a>00194 cpl_vector*
+<a name="l00195"></a>00195 sinfo_vector_clip(<span class="keyword">const</span> cpl_vector* vinp,
+<a name="l00196"></a>00196                   <span class="keyword">const</span> <span class="keywordtype">double</span> kappa,
+<a name="l00197"></a>00197                   <span class="keyword">const</span> <span class="keywordtype">int</span> n,
+<a name="l00198"></a>00198                   <span class="keyword">const</span> <span class="keywordtype">int</span> method)
+<a name="l00199"></a>00199 {
+<a name="l00200"></a>00200    cpl_vector* vout=NULL;
+<a name="l00201"></a>00201    cpl_vector* vtmp=NULL;
+<a name="l00202"></a>00202    <span class="keywordtype">int</span> size=0;
+<a name="l00203"></a>00203    <span class="keywordtype">int</span> j=0;
+<a name="l00204"></a>00204    <span class="keyword">register</span> <span class="keywordtype">int</span> i=0;
+<a name="l00205"></a>00205 
+<a name="l00206"></a>00206    <span class="keywordtype">double</span> mean=0;
+<a name="l00207"></a>00207    <span class="keywordtype">double</span> median=0;
+<a name="l00208"></a>00208    <span class="keywordtype">double</span> stdev=0;
+<a name="l00209"></a>00209    <span class="keywordtype">double</span>* pt=NULL;
+<a name="l00210"></a>00210    <span class="keywordtype">double</span>* po=NULL;
+<a name="l00211"></a>00211 
+<a name="l00212"></a>00212    cknull(vinp,<span class="stringliteral">"Null input vector"</span>);
+<a name="l00213"></a>00213    check_nomsg(vout=cpl_vector_duplicate(vinp));
+<a name="l00214"></a>00214    check_nomsg(mean=cpl_vector_get_mean(vout));
+<a name="l00215"></a>00215    check_nomsg(median=cpl_vector_get_median_const(vout));
+<a name="l00216"></a>00216    check_nomsg(stdev=cpl_vector_get_stdev(vout));
+<a name="l00217"></a>00217    check_nomsg(pt=cpl_vector_get_data(vtmp));
+<a name="l00218"></a>00218 
+<a name="l00219"></a>00219    <span class="keywordflow">if</span>(method == 0) {
+<a name="l00220"></a>00220       <span class="comment">/*</span>
+<a name="l00221"></a>00221 <span class="comment">         are rejected</span>
+<a name="l00222"></a>00222 <span class="comment">         values ||val-mean|| > kappa*sigma</span>
+<a name="l00223"></a>00223 <span class="comment">      */</span>
+<a name="l00224"></a>00224       <span class="keywordflow">for</span>(j=0;j<n;j++) {
+<a name="l00225"></a>00225 
+<a name="l00226"></a>00226          check_nomsg(cpl_vector_sort(vout,1));  <span class="comment">/* sort by increasing data */</span>
+<a name="l00227"></a>00227          check_nomsg(po=cpl_vector_get_data(vout));
+<a name="l00228"></a>00228 
+<a name="l00229"></a>00229          <span class="keywordflow">if</span>( (size > 1) && (fabs(po[size-1]-mean) > kappa*stdev)) {
+<a name="l00230"></a>00230 
+<a name="l00231"></a>00231             size--;
+<a name="l00232"></a>00232             check_nomsg(vtmp=cpl_vector_new(size));
+<a name="l00233"></a>00233             check_nomsg(pt=cpl_vector_get_data(vtmp));
+<a name="l00234"></a>00234             <span class="keywordflow">for</span>(i=0;i<size;i++) {
+<a name="l00235"></a>00235                pt[i]=po[i];
+<a name="l00236"></a>00236             }
+<a name="l00237"></a>00237             check_nomsg(cpl_vector_delete(vout));
+<a name="l00238"></a>00238             check_nomsg(vout=cpl_vector_duplicate(vtmp));
+<a name="l00239"></a>00239             check_nomsg(cpl_vector_delete(vtmp));
+<a name="l00240"></a>00240 
+<a name="l00241"></a>00241             check_nomsg(mean=cpl_vector_get_mean(vout));
+<a name="l00242"></a>00242             check_nomsg(stdev=cpl_vector_get_stdev(vout));
+<a name="l00243"></a>00243 
+<a name="l00244"></a>00244          }
+<a name="l00245"></a>00245 
+<a name="l00246"></a>00246       }
+<a name="l00247"></a>00247 
+<a name="l00248"></a>00248    } <span class="keywordflow">else</span> {
+<a name="l00249"></a>00249       <span class="comment">/*</span>
+<a name="l00250"></a>00250 <span class="comment">         are rejected</span>
+<a name="l00251"></a>00251 <span class="comment">         values ||val-median|| > kappa*sigma</span>
+<a name="l00252"></a>00252 <span class="comment">      */</span>
+<a name="l00253"></a>00253 
+<a name="l00254"></a>00254 
+<a name="l00255"></a>00255       <span class="keywordflow">for</span>(j=0;j<n;j++) {
+<a name="l00256"></a>00256 
+<a name="l00257"></a>00257          check_nomsg(cpl_vector_sort(vout,1));  <span class="comment">/* sort by increasing data */</span>
+<a name="l00258"></a>00258          check_nomsg(po=cpl_vector_get_data(vout));
+<a name="l00259"></a>00259 
+<a name="l00260"></a>00260          <span class="keywordflow">if</span>( (size > 1) && (fabs(po[size-1]-median) > kappa*stdev)) {
+<a name="l00261"></a>00261 
+<a name="l00262"></a>00262             size--;
+<a name="l00263"></a>00263             check_nomsg(vtmp=cpl_vector_new(size));
+<a name="l00264"></a>00264             check_nomsg(pt=cpl_vector_get_data(vtmp));
+<a name="l00265"></a>00265             <span class="keywordflow">for</span>(i=0;i<size;i++) {
+<a name="l00266"></a>00266                pt[i]=po[i];
+<a name="l00267"></a>00267             }
+<a name="l00268"></a>00268             check_nomsg(cpl_vector_delete(vout));
+<a name="l00269"></a>00269             check_nomsg(vout=cpl_vector_duplicate(vtmp));
+<a name="l00270"></a>00270             check_nomsg(cpl_vector_delete(vtmp));
+<a name="l00271"></a>00271 
+<a name="l00272"></a>00272             check_nomsg(median=cpl_vector_get_median_const(vout));
+<a name="l00273"></a>00273             check_nomsg(stdev=cpl_vector_get_stdev(vout));
+<a name="l00274"></a>00274 
+<a name="l00275"></a>00275          }
+<a name="l00276"></a>00276 
+<a name="l00277"></a>00277       }
+<a name="l00278"></a>00278 
+<a name="l00279"></a>00279 
+<a name="l00280"></a>00280 
+<a name="l00281"></a>00281 
+<a name="l00282"></a>00282    }
+<a name="l00283"></a>00283    <span class="keywordflow">return</span> vout;
+<a name="l00284"></a>00284   cleanup:
+<a name="l00285"></a>00285    <span class="keywordflow">return</span> NULL;
+<a name="l00286"></a>00286 
+<a name="l00287"></a>00287 
+<a name="l00288"></a>00288 }
+<a name="l00289"></a>00289 
+<a name="l00290"></a>00290 
+<a name="l00291"></a>00291 
+<a name="l00292"></a>00292 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00326"></a>00326 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00327"></a>00327 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00328"></a>00328 get_candidate(<span class="keyword">const</span> <span class="keywordtype">double</span> *a, <span class="keyword">const</span> <span class="keywordtype">int</span> ia[],
+<a name="l00329"></a>00329               <span class="keywordtype">int</span> M, <span class="keywordtype">int</span> N, <span class="keywordtype">int</span> D,
+<a name="l00330"></a>00330               <span class="keywordtype">double</span> lambda,
+<a name="l00331"></a>00331               <span class="keywordtype">int</span>    (*f)(<span class="keyword">const</span> <span class="keywordtype">double</span> x[], <span class="keyword">const</span> <span class="keywordtype">double</span> a[], <span class="keywordtype">double</span> *result),
+<a name="l00332"></a>00332               <span class="keywordtype">int</span> (*dfda)(<span class="keyword">const</span> <span class="keywordtype">double</span> x[], <span class="keyword">const</span> <span class="keywordtype">double</span> a[], <span class="keywordtype">double</span> result[]),
+<a name="l00333"></a>00333               <span class="keyword">const</span> <span class="keywordtype">double</span> *x,
+<a name="l00334"></a>00334               <span class="keyword">const</span> <span class="keywordtype">double</span> *y,
+<a name="l00335"></a>00335               <span class="keyword">const</span> <span class="keywordtype">double</span> *sigma,
+<a name="l00336"></a>00336               <span class="keywordtype">double</span> *partials,
+<a name="l00337"></a>00337               cpl_matrix *alpha,
+<a name="l00338"></a>00338               cpl_matrix *beta,
+<a name="l00339"></a>00339               <span class="keywordtype">double</span> *a_da)
+<a name="l00340"></a>00340 {
+<a name="l00341"></a>00341    <span class="keywordtype">int</span> Mfit = 0;         <span class="comment">/* Number of non-constant fit parameters */</span>
+<a name="l00342"></a>00342    cpl_matrix *da;       <span class="comment">/* Solution of   alpha * da = beta */</span>
+<a name="l00343"></a>00343    <span class="keywordtype">double</span> *alpha_data;
+<a name="l00344"></a>00344    <span class="keywordtype">double</span> *beta_data;
+<a name="l00345"></a>00345    <span class="keywordtype">double</span> *da_data;
+<a name="l00346"></a>00346    <span class="keywordtype">int</span> i, imfit = 0;
+<a name="l00347"></a>00347    <span class="keywordtype">int</span> j, jmfit = 0;
+<a name="l00348"></a>00348    <span class="keywordtype">int</span> k = 0;
+<a name="l00349"></a>00349 
+<a name="l00350"></a>00350    <span class="comment">/* For efficiency, don't check input in this static function */</span>
+<a name="l00351"></a>00351 
+<a name="l00352"></a>00352    Mfit = cpl_matrix_get_nrow(alpha);
+<a name="l00353"></a>00353 
+<a name="l00354"></a>00354    alpha_data    = cpl_matrix_get_data(alpha);
+<a name="l00355"></a>00355    beta_data     = cpl_matrix_get_data(beta);
+<a name="l00356"></a>00356 
+<a name="l00357"></a>00357    <span class="comment">/* Build alpha, beta:</span>
+<a name="l00358"></a>00358 <span class="comment">    *</span>
+<a name="l00359"></a>00359 <span class="comment">    *  alpha[i,j] = sum_{k=1,N} (sigma_k)^-2 * df/da_i * df/da_j  *</span>
+<a name="l00360"></a>00360 <span class="comment">    *                           (1 + delta_ij lambda) ,</span>
+<a name="l00361"></a>00361 <span class="comment">    *</span>
+<a name="l00362"></a>00362 <span class="comment">    *   beta[i]   = sum_{k=1,N} (sigma_k)^-2 * ( y_k - f(x_k) ) * df/da_i</span>
+<a name="l00363"></a>00363 <span class="comment">    *</span>
+<a name="l00364"></a>00364 <span class="comment">    * where (i,j) loop over the non-constant parameters (0 to Mfit-1),</span>
+<a name="l00365"></a>00365 <span class="comment">    * delta is Kronecker's delta, and all df/da are evaluated in x_k</span>
+<a name="l00366"></a>00366 <span class="comment">    */</span>
+<a name="l00367"></a>00367 
+<a name="l00368"></a>00368    cpl_matrix_fill(alpha, 0.0);
+<a name="l00369"></a>00369    cpl_matrix_fill(beta , 0.0);
+<a name="l00370"></a>00370 
+<a name="l00371"></a>00371    <span class="keywordflow">for</span> (k = 0; k < N; k++)
+<a name="l00372"></a>00372    {
+<a name="l00373"></a>00373       <span class="keywordtype">double</span> sm2 = 0.0;                <span class="comment">/* (sigma_k)^-2 */</span>
+<a name="l00374"></a>00374       <span class="keywordtype">double</span> fx_k = 0.0;               <span class="comment">/* f(x_k)       */</span>
+<a name="l00375"></a>00375       <span class="keyword">const</span> <span class="keywordtype">double</span> *x_k = &(x[0+k*D]); <span class="comment">/* x_k          */</span>
+<a name="l00376"></a>00376 
+<a name="l00377"></a>00377       <span class="keywordflow">if</span> (sigma == NULL)
+<a name="l00378"></a>00378       {
+<a name="l00379"></a>00379          sm2 = 1.0;
+<a name="l00380"></a>00380       }
+<a name="l00381"></a>00381       <span class="keywordflow">else</span>
+<a name="l00382"></a>00382       {
+<a name="l00383"></a>00383          sm2 = 1.0 / (sigma[k] * sigma[k]);
+<a name="l00384"></a>00384       }
+<a name="l00385"></a>00385 
+<a name="l00386"></a>00386       <span class="comment">/* Evaluate f(x_k) */</span>
+<a name="l00387"></a>00387       cpl_ensure( f(x_k, a, &fx_k) == 0, CPL_ERROR_ILLEGAL_INPUT, -1);
+<a name="l00388"></a>00388 
+<a name="l00389"></a>00389       <span class="comment">/* Evaluate (all) df/da (x_k) */</span>
+<a name="l00390"></a>00390       cpl_ensure( dfda(x_k, a, partials) == 0,
+<a name="l00391"></a>00391                   CPL_ERROR_ILLEGAL_INPUT, -1);
+<a name="l00392"></a>00392 
+<a name="l00393"></a>00393       <span class="keywordflow">for</span> (i = 0, imfit = 0; i < M; i++)
+<a name="l00394"></a>00394       {
+<a name="l00395"></a>00395          <span class="keywordflow">if</span> (ia[i] != 0)
+<a name="l00396"></a>00396          {
+<a name="l00397"></a>00397             <span class="comment">/* Beta */</span>
+<a name="l00398"></a>00398             beta_data[imfit] +=
+<a name="l00399"></a>00399                sm2 * (y[k] - fx_k) * partials[i];
+<a name="l00400"></a>00400 
+<a name="l00401"></a>00401             <span class="comment">/* Alpha is symmetrical, so compute</span>
+<a name="l00402"></a>00402 <span class="comment">               only lower-left part */</span>
+<a name="l00403"></a>00403             <span class="keywordflow">for</span> (j = 0, jmfit = 0; j < i; j++)
+<a name="l00404"></a>00404             {
+<a name="l00405"></a>00405                <span class="keywordflow">if</span> (ia[j] != 0)
+<a name="l00406"></a>00406                {
+<a name="l00407"></a>00407                   alpha_data[jmfit + imfit*Mfit] +=
+<a name="l00408"></a>00408                      sm2 * partials[i] *
+<a name="l00409"></a>00409                      partials[j];
+<a name="l00410"></a>00410 
+<a name="l00411"></a>00411                   jmfit += 1;
+<a name="l00412"></a>00412                }
+<a name="l00413"></a>00413             }
+<a name="l00414"></a>00414 
+<a name="l00415"></a>00415             <span class="comment">/* Alpha, diagonal terms */</span>
+<a name="l00416"></a>00416             j = i;
+<a name="l00417"></a>00417             jmfit = imfit;
+<a name="l00418"></a>00418 
+<a name="l00419"></a>00419             alpha_data[jmfit + imfit*Mfit] +=
+<a name="l00420"></a>00420                sm2 * partials[i] *
+<a name="l00421"></a>00421                partials[j] * (1 + lambda);
+<a name="l00422"></a>00422 
+<a name="l00423"></a>00423             imfit += 1;
+<a name="l00424"></a>00424          }
+<a name="l00425"></a>00425       }
+<a name="l00426"></a>00426 
+<a name="l00427"></a>00427       assert( imfit == Mfit );
+<a name="l00428"></a>00428    }
+<a name="l00429"></a>00429 
+<a name="l00430"></a>00430    <span class="comment">/* Create upper-right part of alpha */</span>
+<a name="l00431"></a>00431    <span class="keywordflow">for</span> (i = 0, imfit = 0; i < M; i++) {
+<a name="l00432"></a>00432       <span class="keywordflow">if</span> (ia[i] != 0) {
+<a name="l00433"></a>00433          <span class="keywordflow">for</span> (j = i+1, jmfit = imfit+1; j < M; j++) {
+<a name="l00434"></a>00434             <span class="keywordflow">if</span> (ia[j] != 0) {
+<a name="l00435"></a>00435                alpha_data[jmfit+imfit*Mfit] = alpha_data[imfit+jmfit*Mfit];
+<a name="l00436"></a>00436                jmfit += 1;
+<a name="l00437"></a>00437             }
+<a name="l00438"></a>00438          }
+<a name="l00439"></a>00439          assert( jmfit == Mfit );
+<a name="l00440"></a>00440          imfit += 1;
+<a name="l00441"></a>00441       }
+<a name="l00442"></a>00442    }
+<a name="l00443"></a>00443    assert( imfit == Mfit );
+<a name="l00444"></a>00444 
+<a name="l00445"></a>00445    da = cpl_matrix_solve(alpha, beta);
+<a name="l00446"></a>00446 
+<a name="l00447"></a>00447    cpl_ensure(da != NULL, cpl_error_get_code(), -1);
+<a name="l00448"></a>00448 
+<a name="l00449"></a>00449    <span class="comment">/* Create a+da vector by adding a and da */</span>
+<a name="l00450"></a>00450    da_data   = cpl_matrix_get_data(da);
+<a name="l00451"></a>00451 
+<a name="l00452"></a>00452    <span class="keywordflow">for</span> (i = 0, imfit = 0; i < M; i++)
+<a name="l00453"></a>00453    {
+<a name="l00454"></a>00454       <span class="keywordflow">if</span> (ia[i] != 0)
+<a name="l00455"></a>00455       {
+<a name="l00456"></a>00456          a_da[i] = a[i] + da_data[0 + imfit*1];
+<a name="l00457"></a>00457 
+<a name="l00458"></a>00458          imfit += 1;
+<a name="l00459"></a>00459       }
+<a name="l00460"></a>00460       <span class="keywordflow">else</span>
+<a name="l00461"></a>00461       {
+<a name="l00462"></a>00462          a_da[i] = a[i];
+<a name="l00463"></a>00463       }
+<a name="l00464"></a>00464    }
+<a name="l00465"></a>00465 
+<a name="l00466"></a>00466    assert( imfit == Mfit );
+<a name="l00467"></a>00467 
+<a name="l00468"></a>00468    cpl_matrix_delete(da);
+<a name="l00469"></a>00469 
+<a name="l00470"></a>00470    <span class="keywordflow">return</span> 0;
+<a name="l00471"></a>00471 }
+<a name="l00472"></a>00472 
+<a name="l00473"></a>00473 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00474"></a>00474 
+<a name="l00475"></a>00475 
+<a name="l00476"></a>00476 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00497"></a>00497 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00498"></a>00498 
+<a name="l00499"></a>00499 <span class="keyword">static</span> <span class="keywordtype">double</span>
+<a name="l00500"></a>00500 get_chisq(<span class="keywordtype">int</span> N, <span class="keywordtype">int</span> D,
+<a name="l00501"></a>00501           <span class="keywordtype">int</span> (*f)(<span class="keyword">const</span> <span class="keywordtype">double</span> x[], <span class="keyword">const</span> <span class="keywordtype">double</span> a[], <span class="keywordtype">double</span> *result),
+<a name="l00502"></a>00502           <span class="keyword">const</span> <span class="keywordtype">double</span> *a,
+<a name="l00503"></a>00503           <span class="keyword">const</span> <span class="keywordtype">double</span> *x,
+<a name="l00504"></a>00504           <span class="keyword">const</span> <span class="keywordtype">double</span> *y,
+<a name="l00505"></a>00505           <span class="keyword">const</span> <span class="keywordtype">double</span> *sigma)
+<a name="l00506"></a>00506 {
+<a name="l00507"></a>00507    <span class="keywordtype">double</span> chi_sq;     <span class="comment">/* Result */</span>
+<a name="l00508"></a>00508    <span class="keywordtype">int</span> i = 0;
+<a name="l00509"></a>00509 
+<a name="l00510"></a>00510    <span class="comment">/* For efficiency, don't check input in this static function */</span>
+<a name="l00511"></a>00511    chi_sq = 0.0;
+<a name="l00512"></a>00512    <span class="keywordflow">for</span> (i = 0; i < N; i++)
+<a name="l00513"></a>00513    {
+<a name="l00514"></a>00514       <span class="keywordtype">double</span> fx_i;
+<a name="l00515"></a>00515       <span class="keywordtype">double</span> residual;                 <span class="comment">/* Residual in units of uncertainty */</span>
+<a name="l00516"></a>00516       <span class="keyword">const</span> <span class="keywordtype">double</span> *x_i = &(x[0+i*D]);
+<a name="l00517"></a>00517 
+<a name="l00518"></a>00518       <span class="comment">/* Evaluate */</span>
+<a name="l00519"></a>00519       cpl_ensure( f(x_i,
+<a name="l00520"></a>00520                     a,
+<a name="l00521"></a>00521                     &fx_i) == 0, CPL_ERROR_ILLEGAL_INPUT, -1.0);
+<a name="l00522"></a>00522 
+<a name="l00523"></a>00523       <span class="comment">/* Accumulate */</span>
+<a name="l00524"></a>00524       <span class="keywordflow">if</span> (sigma == NULL)
+<a name="l00525"></a>00525       {
+<a name="l00526"></a>00526          residual = (fx_i - y[i]);
+<a name="l00527"></a>00527       }
+<a name="l00528"></a>00528       <span class="keywordflow">else</span>
+<a name="l00529"></a>00529       {
+<a name="l00530"></a>00530          residual = (fx_i - y[i]) / sigma[i];
+<a name="l00531"></a>00531       }
+<a name="l00532"></a>00532 
+<a name="l00533"></a>00533       chi_sq += residual*residual;
+<a name="l00534"></a>00534 
+<a name="l00535"></a>00535    }
+<a name="l00536"></a>00536 
+<a name="l00537"></a>00537    <span class="keywordflow">return</span> chi_sq;
+<a name="l00538"></a>00538 }
+<a name="l00539"></a>00539 
+<a name="l00540"></a>00540 
+<a name="l00541"></a>00541 
+<a name="l00542"></a>00542 <span class="preprocessor">#ifndef CPL_VECTOR_FIT_MAXITER</span>
+<a name="l00543"></a>00543 <span class="preprocessor"></span><span class="preprocessor">#define CPL_VECTOR_FIT_MAXITER 1000</span>
+<a name="l00544"></a>00544 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
+<a name="l00545"></a>00545 <span class="preprocessor"></span><span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00612"></a>00612 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00613"></a>00613 cpl_error_code
+<a name="l00614"></a>00614 sinfo_fit_lm(<span class="keyword">const</span> cpl_matrix *x,
+<a name="l00615"></a>00615              <span class="keyword">const</span> cpl_matrix *sigma_x,
+<a name="l00616"></a>00616              <span class="keyword">const</span> cpl_vector *y,
+<a name="l00617"></a>00617              <span class="keyword">const</span> cpl_vector *sigma_y,
+<a name="l00618"></a>00618              cpl_vector *a,
+<a name="l00619"></a>00619              <span class="keyword">const</span> <span class="keywordtype">int</span> ia[],
+<a name="l00620"></a>00620              <span class="keywordtype">int</span>    (*f)(<span class="keyword">const</span> <span class="keywordtype">double</span> x[],
+<a name="l00621"></a>00621                          <span class="keyword">const</span> <span class="keywordtype">double</span> a[],
+<a name="l00622"></a>00622                          <span class="keywordtype">double</span> *result),
+<a name="l00623"></a>00623              <span class="keywordtype">int</span> (*dfda)(<span class="keyword">const</span> <span class="keywordtype">double</span> x[],
+<a name="l00624"></a>00624                          <span class="keyword">const</span> <span class="keywordtype">double</span> a[],
+<a name="l00625"></a>00625                          <span class="keywordtype">double</span> result[]),
+<a name="l00626"></a>00626              <span class="keywordtype">double</span> *mse,
+<a name="l00627"></a>00627              <span class="keywordtype">double</span> *red_chisq,
+<a name="l00628"></a>00628              cpl_matrix **covariance)
+<a name="l00629"></a>00629 {
+<a name="l00630"></a>00630    <span class="keyword">const</span> <span class="keywordtype">double</span> *x_data     = NULL; <span class="comment">/* Pointer to input data                  */</span>
+<a name="l00631"></a>00631    <span class="keyword">const</span> <span class="keywordtype">double</span> *y_data     = NULL; <span class="comment">/* Pointer to input data                  */</span>
+<a name="l00632"></a>00632    <span class="keyword">const</span> <span class="keywordtype">double</span> *sigma_data = NULL; <span class="comment">/* Pointer to input data                  */</span>
+<a name="l00633"></a>00633    <span class="keywordtype">int</span> N    = 0;                    <span class="comment">/* Number of data points                  */</span>
+<a name="l00634"></a>00634    <span class="keywordtype">int</span> D    = 0;                    <span class="comment">/* Dimension of x-points                  */</span>
+<a name="l00635"></a>00635    <span class="keywordtype">int</span> M    = 0;                    <span class="comment">/* Number of fit parameters               */</span>
+<a name="l00636"></a>00636    <span class="keywordtype">int</span> Mfit = 0;                    <span class="comment">/* Number of non-constant fit</span>
+<a name="l00637"></a>00637 <span class="comment">                                       parameters                             */</span>
+<a name="l00638"></a>00638 
+<a name="l00639"></a>00639    <span class="keywordtype">double</span> lambda    = 0.0;          <span class="comment">/* Lambda in L-M algorithm                */</span>
+<a name="l00640"></a>00640    <span class="keywordtype">double</span> MAXLAMBDA = 10e40;        <span class="comment">/* Parameter to control the graceful exit</span>
+<a name="l00641"></a>00641 <span class="comment">                                       if steepest descent unexpectedly fails */</span>
+<a name="l00642"></a>00642    <span class="keywordtype">double</span> chi_sq    = 0.0;          <span class="comment">/* Current  chi^2                         */</span>
+<a name="l00643"></a>00643    <span class="keywordtype">int</span> count        = 0;            <span class="comment">/* Number of successive small improvements</span>
+<a name="l00644"></a>00644 <span class="comment">                                       in chi^2 */</span>
+<a name="l00645"></a>00645    <span class="keywordtype">int</span> iterations   = 0;
+<a name="l00646"></a>00646 
+<a name="l00647"></a>00647    cpl_matrix *alpha  = NULL;       <span class="comment">/* The MxM ~curvature matrix used in L-M  */</span>
+<a name="l00648"></a>00648    cpl_matrix *beta   = NULL;       <span class="comment">/* Mx1 matrix = -.5 grad(chi^2)           */</span>
+<a name="l00649"></a>00649    <span class="keywordtype">double</span> *a_data     = NULL;       <span class="comment">/* Parameters, a                          */</span>
+<a name="l00650"></a>00650    <span class="keywordtype">double</span> *a_da       = NULL;       <span class="comment">/* Candidate position a+da                */</span>
+<a name="l00651"></a>00651    <span class="keywordtype">double</span> *part       = NULL;       <span class="comment">/* The partial derivatives df/da          */</span>
+<a name="l00652"></a>00652    <span class="keywordtype">int</span> *ia_local      = NULL;       <span class="comment">/* non-NULL version of ia                 */</span>
+<a name="l00653"></a>00653 
+<a name="l00654"></a>00654    <span class="comment">/* If covariance computation is requested, then either</span>
+<a name="l00655"></a>00655 <span class="comment">    * return the covariance matrix or return NULL.</span>
+<a name="l00656"></a>00656 <span class="comment">    */</span>
+<a name="l00657"></a>00657    <span class="keywordflow">if</span> (covariance != NULL) *covariance = NULL;
+<a name="l00658"></a>00658 
+<a name="l00659"></a>00659    <span class="comment">/* Validate input */</span>
+<a name="l00660"></a>00660    cpl_ensure_code(x       != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00661"></a>00661    cpl_ensure_code(sigma_x == NULL, CPL_ERROR_UNSUPPORTED_MODE);
+<a name="l00662"></a>00662    cpl_ensure_code(y       != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00663"></a>00663    cpl_ensure_code(a       != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00664"></a>00664    <span class="comment">/* ia may be NULL */</span>
+<a name="l00665"></a>00665    cpl_ensure_code(f       != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00666"></a>00666    cpl_ensure_code(dfda    != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l00667"></a>00667 
+<a name="l00668"></a>00668    <span class="comment">/* Chi^2 and covariance computations require sigmas to be known */</span>
+<a name="l00669"></a>00669    cpl_ensure_code( sigma_y != NULL ||
+<a name="l00670"></a>00670                     (red_chisq == NULL && covariance == NULL),
+<a name="l00671"></a>00671                     CPL_ERROR_INCOMPATIBLE_INPUT);
+<a name="l00672"></a>00672 
+<a name="l00673"></a>00673    D = cpl_matrix_get_ncol(x);
+<a name="l00674"></a>00674    N = cpl_matrix_get_nrow(x);
+<a name="l00675"></a>00675    M = cpl_vector_get_size(a);
+<a name="l00676"></a>00676    cpl_ensure_code(N > 0 && D > 0 && M > 0, CPL_ERROR_ILLEGAL_INPUT);
+<a name="l00677"></a>00677 
+<a name="l00678"></a>00678    cpl_ensure_code( cpl_vector_get_size(y) == N,
+<a name="l00679"></a>00679                     CPL_ERROR_INCOMPATIBLE_INPUT);
+<a name="l00680"></a>00680 
+<a name="l00681"></a>00681    x_data = cpl_matrix_get_data_const(x);
+<a name="l00682"></a>00682    y_data = cpl_vector_get_data_const(y);
+<a name="l00683"></a>00683    a_data = cpl_vector_get_data(a);
+<a name="l00684"></a>00684 
+<a name="l00685"></a>00685    <span class="keywordflow">if</span> (sigma_y != NULL)
+<a name="l00686"></a>00686    {
+<a name="l00687"></a>00687       cpl_ensure_code( cpl_vector_get_size(sigma_y) == N,
+<a name="l00688"></a>00688                        CPL_ERROR_INCOMPATIBLE_INPUT);
+<a name="l00689"></a>00689       <span class="comment">/* Sigmas must be positive */</span>
+<a name="l00690"></a>00690       cpl_ensure_code( cpl_vector_get_min (sigma_y) > 0,
+<a name="l00691"></a>00691                        CPL_ERROR_ILLEGAL_INPUT);
+<a name="l00692"></a>00692       sigma_data = cpl_vector_get_data_const(sigma_y);
+<a name="l00693"></a>00693    }
+<a name="l00694"></a>00694 
+<a name="l00695"></a>00695    ia_local = cpl_malloc(M * <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>));
+<a name="l00696"></a>00696    cpl_ensure_code(ia_local != NULL, CPL_ERROR_ILLEGAL_OUTPUT);
+<a name="l00697"></a>00697 
+<a name="l00698"></a>00698    <span class="comment">/* Count non-constant fit parameters, copy ia */</span>
+<a name="l00699"></a>00699    <span class="keywordflow">if</span> (ia != NULL)
+<a name="l00700"></a>00700    {
+<a name="l00701"></a>00701       <span class="keywordtype">int</span> i;
+<a name="l00702"></a>00702 
+<a name="l00703"></a>00703       Mfit = 0;
+<a name="l00704"></a>00704       <span class="keywordflow">for</span> (i = 0; i < M; i++)
+<a name="l00705"></a>00705       {
+<a name="l00706"></a>00706          ia_local[i] = ia[i];
+<a name="l00707"></a>00707 
+<a name="l00708"></a>00708          <span class="keywordflow">if</span> (ia[i] != 0)
+<a name="l00709"></a>00709          {
+<a name="l00710"></a>00710             Mfit += 1;
+<a name="l00711"></a>00711          }
+<a name="l00712"></a>00712       }
+<a name="l00713"></a>00713 
+<a name="l00714"></a>00714       <span class="keywordflow">if</span> (! (Mfit > 0))
+<a name="l00715"></a>00715       {
+<a name="l00716"></a>00716          cpl_free(ia_local);
+<a name="l00717"></a>00717          cpl_ensure_code( CPL_FALSE,
+<a name="l00718"></a>00718                           CPL_ERROR_ILLEGAL_INPUT);
+<a name="l00719"></a>00719       }
+<a name="l00720"></a>00720    }
+<a name="l00721"></a>00721    <span class="keywordflow">else</span>
+<a name="l00722"></a>00722    {
+<a name="l00723"></a>00723       <span class="comment">/* All parameters participate */</span>
+<a name="l00724"></a>00724       <span class="keywordtype">int</span> i;
+<a name="l00725"></a>00725 
+<a name="l00726"></a>00726       Mfit = M;
+<a name="l00727"></a>00727 
+<a name="l00728"></a>00728       <span class="keywordflow">for</span> (i = 0; i < M; i++)
+<a name="l00729"></a>00729       {
+<a name="l00730"></a>00730          ia_local[i] = 1;
+<a name="l00731"></a>00731       }
+<a name="l00732"></a>00732    }
+<a name="l00733"></a>00733 
+<a name="l00734"></a>00734    <span class="comment">/* To compute reduced chi^2, we need N > Mfit */</span>
+<a name="l00735"></a>00735    <span class="keywordflow">if</span> (! ( red_chisq == NULL || N > Mfit ) )
+<a name="l00736"></a>00736    {
+<a name="l00737"></a>00737       cpl_free(ia_local);
+<a name="l00738"></a>00738       cpl_ensure_code(
+<a name="l00739"></a>00739          CPL_FALSE,
+<a name="l00740"></a>00740          CPL_ERROR_ILLEGAL_INPUT);
+<a name="l00741"></a>00741    }
+<a name="l00742"></a>00742 
+<a name="l00743"></a>00743    <span class="comment">/* Create alpha, beta, a_da, part  work space */</span>
+<a name="l00744"></a>00744    alpha = cpl_matrix_new(Mfit, Mfit);
+<a name="l00745"></a>00745    <span class="keywordflow">if</span> (alpha == NULL)
+<a name="l00746"></a>00746    {
+<a name="l00747"></a>00747       cpl_free(ia_local);
+<a name="l00748"></a>00748       cpl_ensure_code(
+<a name="l00749"></a>00749          CPL_FALSE,
+<a name="l00750"></a>00750          CPL_ERROR_ILLEGAL_OUTPUT);
+<a name="l00751"></a>00751    }
+<a name="l00752"></a>00752 
+<a name="l00753"></a>00753    beta = cpl_matrix_new(Mfit, 1);
+<a name="l00754"></a>00754    <span class="keywordflow">if</span> (beta == NULL)
+<a name="l00755"></a>00755    {
+<a name="l00756"></a>00756       cpl_free(ia_local);
+<a name="l00757"></a>00757       cpl_matrix_delete(alpha);
+<a name="l00758"></a>00758       cpl_ensure_code(
+<a name="l00759"></a>00759          CPL_FALSE,
+<a name="l00760"></a>00760          CPL_ERROR_ILLEGAL_OUTPUT);
+<a name="l00761"></a>00761    }
+<a name="l00762"></a>00762 
+<a name="l00763"></a>00763    a_da = cpl_malloc(M * <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>));
+<a name="l00764"></a>00764    <span class="keywordflow">if</span> (a_da == NULL)
+<a name="l00765"></a>00765    {
+<a name="l00766"></a>00766       cpl_free(ia_local);
+<a name="l00767"></a>00767       cpl_matrix_delete(alpha);
+<a name="l00768"></a>00768       cpl_matrix_delete(beta);
+<a name="l00769"></a>00769       cpl_ensure_code(
+<a name="l00770"></a>00770          CPL_FALSE,
+<a name="l00771"></a>00771          CPL_ERROR_ILLEGAL_OUTPUT);
+<a name="l00772"></a>00772    }
+<a name="l00773"></a>00773 
+<a name="l00774"></a>00774    part = cpl_malloc(M * <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>));
+<a name="l00775"></a>00775    <span class="keywordflow">if</span> (part == NULL)
+<a name="l00776"></a>00776    {
+<a name="l00777"></a>00777       cpl_free(ia_local);
+<a name="l00778"></a>00778       cpl_matrix_delete(alpha);
+<a name="l00779"></a>00779       cpl_matrix_delete(beta);
+<a name="l00780"></a>00780       cpl_free(a_da);
+<a name="l00781"></a>00781       cpl_ensure_code(
+<a name="l00782"></a>00782          CPL_FALSE,
+<a name="l00783"></a>00783          CPL_ERROR_ILLEGAL_OUTPUT);
+<a name="l00784"></a>00784    }
+<a name="l00785"></a>00785 
+<a name="l00786"></a>00786    <span class="comment">/* Initialize loop variables */</span>
+<a name="l00787"></a>00787    lambda = 0.001;
+<a name="l00788"></a>00788    count = 0;
+<a name="l00789"></a>00789    iterations = 0;
+<a name="l00790"></a>00790    <span class="keywordflow">if</span>( (chi_sq = get_chisq(N, D, f, a_data, x_data, y_data, sigma_data)) < 0)
+<a name="l00791"></a>00791    {
+<a name="l00792"></a>00792       cpl_free(ia_local);
+<a name="l00793"></a>00793       cpl_matrix_delete(alpha);
+<a name="l00794"></a>00794       cpl_matrix_delete(beta);
+<a name="l00795"></a>00795       cpl_free(a_da);
+<a name="l00796"></a>00796       cpl_free(part);
+<a name="l00797"></a>00797       cpl_ensure_code(
+<a name="l00798"></a>00798          CPL_FALSE,
+<a name="l00799"></a>00799          cpl_error_get_code());
+<a name="l00800"></a>00800    }
+<a name="l00801"></a>00801 
+<a name="l00802"></a>00802    <span class="comment">/* uves_msg_debug("Initial chi^2 = %f", chi_sq); */</span>
+<a name="l00803"></a>00803 
+<a name="l00804"></a>00804    <span class="comment">/* Iterate until chi^2 didn't improve substantially many (say, 5)</span>
+<a name="l00805"></a>00805 <span class="comment">      times in a row */</span>
+<a name="l00806"></a>00806    <span class="keywordflow">while</span> (count < 5 &&
+<a name="l00807"></a>00807           lambda < MAXLAMBDA &&
+<a name="l00808"></a>00808           iterations < CPL_VECTOR_FIT_MAXITER)
+<a name="l00809"></a>00809    {
+<a name="l00810"></a>00810       <span class="comment">/* In each iteration lambda increases, or chi^2 decreases or</span>
+<a name="l00811"></a>00811 <span class="comment">         count increases. Because chi^2 is bounded from below</span>
+<a name="l00812"></a>00812 <span class="comment">         (and lambda and count from above), the loop will terminate */</span>
+<a name="l00813"></a>00813 
+<a name="l00814"></a>00814       <span class="keywordtype">double</span> chi_sq_candidate = 0.0;
+<a name="l00815"></a>00815       <span class="keywordtype">int</span> returncode = 0;
+<a name="l00816"></a>00816 
+<a name="l00817"></a>00817       <span class="comment">/* Get candidate position in parameter space = a+da,</span>
+<a name="l00818"></a>00818 <span class="comment">       * where  alpha * da = beta .</span>
+<a name="l00819"></a>00819 <span class="comment">       * Increase lambda until alpha is non-singular</span>
+<a name="l00820"></a>00820 <span class="comment">       */</span>
+<a name="l00821"></a>00821 
+<a name="l00822"></a>00822       <span class="keywordflow">while</span>( (returncode = get_candidate(a_data, ia_local,
+<a name="l00823"></a>00823                                          M, N, D,
+<a name="l00824"></a>00824                                          lambda, f, dfda,
+<a name="l00825"></a>00825                                          x_data, y_data, sigma_data,
+<a name="l00826"></a>00826                                          part, alpha, beta, a_da)
+<a name="l00827"></a>00827                 ) != 0
+<a name="l00828"></a>00828              && cpl_error_get_code() == CPL_ERROR_SINGULAR_MATRIX
+<a name="l00829"></a>00829              && lambda < MAXLAMBDA)
+<a name="l00830"></a>00830       {
+<a name="l00831"></a>00831          <span class="comment">/* uves_msg_debug("Singular matrix. lambda = %e", lambda); */</span>
+<a name="l00832"></a>00832          cpl_error_reset();
+<a name="l00833"></a>00833          lambda *= 9.0;
+<a name="l00834"></a>00834       }
+<a name="l00835"></a>00835 
+<a name="l00836"></a>00836       <span class="comment">/* Set error if lambda diverged */</span>
+<a name="l00837"></a>00837       <span class="keywordflow">if</span> ( !( lambda < MAXLAMBDA ) )
+<a name="l00838"></a>00838       {
+<a name="l00839"></a>00839          cpl_free(ia_local);
+<a name="l00840"></a>00840          cpl_matrix_delete(alpha);
+<a name="l00841"></a>00841          cpl_matrix_delete(beta);
+<a name="l00842"></a>00842          cpl_free(a_da);
+<a name="l00843"></a>00843          cpl_free(part);
+<a name="l00844"></a>00844          cpl_ensure_code(
+<a name="l00845"></a>00845             CPL_FALSE,
+<a name="l00846"></a>00846             CPL_ERROR_CONTINUE);
+<a name="l00847"></a>00847       }
+<a name="l00848"></a>00848 
+<a name="l00849"></a>00849       <span class="keywordflow">if</span> (returncode != 0)
+<a name="l00850"></a>00850       {
+<a name="l00851"></a>00851          cpl_free(ia_local);
+<a name="l00852"></a>00852          cpl_matrix_delete(alpha);
+<a name="l00853"></a>00853          cpl_matrix_delete(beta);
+<a name="l00854"></a>00854          cpl_free(a_da);
+<a name="l00855"></a>00855          cpl_free(part);
+<a name="l00856"></a>00856          cpl_ensure_code(
+<a name="l00857"></a>00857             CPL_FALSE,
+<a name="l00858"></a>00858             cpl_error_get_code());
+<a name="l00859"></a>00859       }
+<a name="l00860"></a>00860 
+<a name="l00861"></a>00861       <span class="comment">/* Get chi^2(a+da) */</span>
+<a name="l00862"></a>00862       <span class="keywordflow">if</span> ((chi_sq_candidate = get_chisq(N, D, f, a_da,
+<a name="l00863"></a>00863                                         x_data, y_data, sigma_data)) < 0)
+<a name="l00864"></a>00864       {
+<a name="l00865"></a>00865          cpl_free(ia_local);
+<a name="l00866"></a>00866          cpl_matrix_delete(alpha);
+<a name="l00867"></a>00867          cpl_matrix_delete(beta);
+<a name="l00868"></a>00868          cpl_free(a_da);
+<a name="l00869"></a>00869          cpl_free(part);
+<a name="l00870"></a>00870          cpl_ensure_code(
+<a name="l00871"></a>00871             CPL_FALSE,
+<a name="l00872"></a>00872             cpl_error_get_code());
+<a name="l00873"></a>00873       }
+<a name="l00874"></a>00874 
+<a name="l00875"></a>00875       <span class="comment">/* uves_msg_debug("Chi^2 = %f  Candidate = %f  Lambda = %e",</span>
+<a name="l00876"></a>00876 <span class="comment">         chi_sq, chi_sq_candidate, lambda);  */</span>
+<a name="l00877"></a>00877 
+<a name="l00878"></a>00878       <span class="keywordflow">if</span> (chi_sq_candidate > chi_sq)
+<a name="l00879"></a>00879       {
+<a name="l00880"></a>00880          <span class="comment">/* Move towards steepest descent */</span>
+<a name="l00881"></a>00881          lambda *= 9.0;
+<a name="l00882"></a>00882       }
+<a name="l00883"></a>00883       <span class="keywordflow">else</span>
+<a name="l00884"></a>00884       {
+<a name="l00885"></a>00885          <span class="comment">/* Move towards Newton's algorithm */</span>
+<a name="l00886"></a>00886          lambda /= 10.0;
+<a name="l00887"></a>00887 
+<a name="l00888"></a>00888          <span class="comment">/* Count the number of successive improvements in chi^2 of</span>
+<a name="l00889"></a>00889 <span class="comment">            less than 0.01 relative */</span>
+<a name="l00890"></a>00890          <span class="keywordflow">if</span> ( chi_sq == 0 ||
+<a name="l00891"></a>00891               (chi_sq - chi_sq_candidate)/chi_sq < .01)
+<a name="l00892"></a>00892          {
+<a name="l00893"></a>00893             count += 1;
+<a name="l00894"></a>00894          }
+<a name="l00895"></a>00895          <span class="keywordflow">else</span>
+<a name="l00896"></a>00896          {
+<a name="l00897"></a>00897             <span class="comment">/* Chi^2 improved by a significant amount,</span>
+<a name="l00898"></a>00898 <span class="comment">               reset counter */</span>
+<a name="l00899"></a>00899             count = 0;
+<a name="l00900"></a>00900          }
+<a name="l00901"></a>00901 
+<a name="l00902"></a>00902          <span class="comment">/* chi^2 improved, update a and chi^2 */</span>
+<a name="l00903"></a>00903          {
+<a name="l00904"></a>00904             <span class="keywordtype">int</span> i;
+<a name="l00905"></a>00905             <span class="keywordflow">for</span> (i = 0; i < M; i++) a_data[i] = a_da[i];
+<a name="l00906"></a>00906          }
+<a name="l00907"></a>00907          chi_sq = chi_sq_candidate;
+<a name="l00908"></a>00908       }
+<a name="l00909"></a>00909       iterations++;
+<a name="l00910"></a>00910    }
+<a name="l00911"></a>00911 
+<a name="l00912"></a>00912    <span class="comment">/* Set error if we didn't converge */</span>
+<a name="l00913"></a>00913    <span class="keywordflow">if</span> ( !( lambda < MAXLAMBDA && iterations < CPL_VECTOR_FIT_MAXITER ) )
+<a name="l00914"></a>00914    {
+<a name="l00915"></a>00915       cpl_free(ia_local);
+<a name="l00916"></a>00916       cpl_matrix_delete(alpha);
+<a name="l00917"></a>00917       cpl_matrix_delete(beta);
+<a name="l00918"></a>00918       cpl_free(a_da);
+<a name="l00919"></a>00919       cpl_free(part);
+<a name="l00920"></a>00920       cpl_ensure_code(
+<a name="l00921"></a>00921          CPL_FALSE,
+<a name="l00922"></a>00922          CPL_ERROR_CONTINUE);
+<a name="l00923"></a>00923    }
+<a name="l00924"></a>00924 
+<a name="l00925"></a>00925    <span class="comment">/* Compute mse if requested */</span>
+<a name="l00926"></a>00926    <span class="keywordflow">if</span> (mse != NULL)
+<a name="l00927"></a>00927    {
+<a name="l00928"></a>00928       <span class="keywordtype">int</span> i;
+<a name="l00929"></a>00929 
+<a name="l00930"></a>00930       *mse = 0.0;
+<a name="l00931"></a>00931 
+<a name="l00932"></a>00932       <span class="keywordflow">for</span>(i = 0; i < N; i++)
+<a name="l00933"></a>00933       {
+<a name="l00934"></a>00934          <span class="keywordtype">double</span> fx_i = 0.0;
+<a name="l00935"></a>00935          <span class="keywordtype">double</span> residual = 0.0;
+<a name="l00936"></a>00936 
+<a name="l00937"></a>00937          <span class="comment">/* Evaluate f(x_i) at the best fit parameters */</span>
+<a name="l00938"></a>00938          <span class="keywordflow">if</span>( f(&(x_data[i*D]),
+<a name="l00939"></a>00939                a_data,
+<a name="l00940"></a>00940                &fx_i) != 0)
+<a name="l00941"></a>00941          {
+<a name="l00942"></a>00942             cpl_free(ia_local);
+<a name="l00943"></a>00943             cpl_matrix_delete(alpha);
+<a name="l00944"></a>00944             cpl_matrix_delete(beta);
+<a name="l00945"></a>00945             cpl_free(a_da);
+<a name="l00946"></a>00946             cpl_free(part);
+<a name="l00947"></a>00947             cpl_ensure_code(
+<a name="l00948"></a>00948                CPL_FALSE,
+<a name="l00949"></a>00949                CPL_ERROR_ILLEGAL_INPUT);
+<a name="l00950"></a>00950          }
+<a name="l00951"></a>00951 
+<a name="l00952"></a>00952          residual = y_data[i] - fx_i;
+<a name="l00953"></a>00953          *mse += residual * residual;
+<a name="l00954"></a>00954       }
+<a name="l00955"></a>00955       *mse /= N;
+<a name="l00956"></a>00956    }
+<a name="l00957"></a>00957 
+<a name="l00958"></a>00958    <span class="comment">/* Compute reduced chi^2 if requested */</span>
+<a name="l00959"></a>00959    <span class="keywordflow">if</span> (red_chisq != NULL)
+<a name="l00960"></a>00960    {
+<a name="l00961"></a>00961       <span class="comment">/* We already know the optimal chi^2 (and that N > Mfit)*/</span>
+<a name="l00962"></a>00962       *red_chisq = chi_sq / (N-Mfit);
+<a name="l00963"></a>00963    }
+<a name="l00964"></a>00964 
+<a name="l00965"></a>00965    <span class="comment">/* Compute covariance matrix if requested</span>
+<a name="l00966"></a>00966 <span class="comment">    * cov = alpha(lambda=0)^-1</span>
+<a name="l00967"></a>00967 <span class="comment">    */</span>
+<a name="l00968"></a>00968    <span class="keywordflow">if</span> (covariance != NULL)
+<a name="l00969"></a>00969    {
+<a name="l00970"></a>00970       cpl_matrix *cov;
+<a name="l00971"></a>00971 
+<a name="l00972"></a>00972       <span class="keywordflow">if</span>( get_candidate(a_data, ia_local,
+<a name="l00973"></a>00973                         M, N, D, 0.0, f, dfda,
+<a name="l00974"></a>00974                         x_data, y_data, sigma_data,
+<a name="l00975"></a>00975                         part, alpha, beta, a_da)
+<a name="l00976"></a>00976           != 0)
+<a name="l00977"></a>00977       {
+<a name="l00978"></a>00978          cpl_free(ia_local);
+<a name="l00979"></a>00979          cpl_matrix_delete(alpha);
+<a name="l00980"></a>00980          cpl_matrix_delete(beta);
+<a name="l00981"></a>00981          cpl_free(a_da);
+<a name="l00982"></a>00982          cpl_free(part);
+<a name="l00983"></a>00983          cpl_ensure_code(
+<a name="l00984"></a>00984             CPL_FALSE,
+<a name="l00985"></a>00985             cpl_error_get_code());
+<a name="l00986"></a>00986       }
+<a name="l00987"></a>00987 
+<a name="l00988"></a>00988       cov = cpl_matrix_invert_create(alpha);
+<a name="l00989"></a>00989       <span class="keywordflow">if</span> (cov == NULL)
+<a name="l00990"></a>00990       {
+<a name="l00991"></a>00991          cpl_free(ia_local);
+<a name="l00992"></a>00992          cpl_matrix_delete(alpha);
+<a name="l00993"></a>00993          cpl_matrix_delete(beta);
+<a name="l00994"></a>00994          cpl_free(a_da);
+<a name="l00995"></a>00995          cpl_free(part);
+<a name="l00996"></a>00996          cpl_ensure_code(
+<a name="l00997"></a>00997             CPL_FALSE,
+<a name="l00998"></a>00998             cpl_error_get_code());
+<a name="l00999"></a>00999       }
+<a name="l01000"></a>01000 
+<a name="l01001"></a>01001       <span class="comment">/* Make sure that variances are positive */</span>
+<a name="l01002"></a>01002       {
+<a name="l01003"></a>01003          <span class="keywordtype">int</span> i;
+<a name="l01004"></a>01004          <span class="keywordflow">for</span> (i = 0; i < Mfit; i++)
+<a name="l01005"></a>01005          {
+<a name="l01006"></a>01006             <span class="keywordflow">if</span> ( !(cpl_matrix_get(cov, i, i) > 0) )
+<a name="l01007"></a>01007             {
+<a name="l01008"></a>01008                cpl_free(ia_local);
+<a name="l01009"></a>01009                cpl_matrix_delete(alpha);
+<a name="l01010"></a>01010                cpl_matrix_delete(beta);
+<a name="l01011"></a>01011                cpl_free(a_da);
+<a name="l01012"></a>01012                cpl_free(part);
+<a name="l01013"></a>01013                cpl_matrix_delete(cov);
+<a name="l01014"></a>01014                *covariance = NULL;
+<a name="l01015"></a>01015                cpl_ensure_code(
+<a name="l01016"></a>01016                   CPL_FALSE,
+<a name="l01017"></a>01017                   CPL_ERROR_SINGULAR_MATRIX);
+<a name="l01018"></a>01018             }
+<a name="l01019"></a>01019          }
+<a name="l01020"></a>01020       }
+<a name="l01021"></a>01021 
+<a name="l01022"></a>01022       <span class="comment">/* Expand covariance matrix from Mfit x Mfit</span>
+<a name="l01023"></a>01023 <span class="comment">         to M x M. Set rows/columns corresponding to fixed</span>
+<a name="l01024"></a>01024 <span class="comment">         parameters to zero */</span>
+<a name="l01025"></a>01025 
+<a name="l01026"></a>01026       *covariance = cpl_matrix_new(M, M);
+<a name="l01027"></a>01027       <span class="keywordflow">if</span> (*covariance == NULL)
+<a name="l01028"></a>01028       {
+<a name="l01029"></a>01029          cpl_free(ia_local);
+<a name="l01030"></a>01030          cpl_matrix_delete(alpha);
+<a name="l01031"></a>01031          cpl_matrix_delete(beta);
+<a name="l01032"></a>01032          cpl_free(a_da);
+<a name="l01033"></a>01033          cpl_free(part);
+<a name="l01034"></a>01034          cpl_matrix_delete(cov);
+<a name="l01035"></a>01035          cpl_ensure_code(
+<a name="l01036"></a>01036             CPL_FALSE,
+<a name="l01037"></a>01037             CPL_ERROR_ILLEGAL_OUTPUT);
+<a name="l01038"></a>01038       }
+<a name="l01039"></a>01039 
+<a name="l01040"></a>01040       {
+<a name="l01041"></a>01041          <span class="keywordtype">int</span> j, jmfit;
+<a name="l01042"></a>01042 
+<a name="l01043"></a>01043          <span class="keywordflow">for</span> (j = 0, jmfit = 0; j < M; j++)
+<a name="l01044"></a>01044             <span class="keywordflow">if</span> (ia_local[j] != 0)
+<a name="l01045"></a>01045             {
+<a name="l01046"></a>01046                <span class="keywordtype">int</span> i, imfit;
+<a name="l01047"></a>01047 
+<a name="l01048"></a>01048                <span class="keywordflow">for</span> (i = 0, imfit = 0; i < M; i++)
+<a name="l01049"></a>01049                   <span class="keywordflow">if</span> (ia_local[i] != 0)
+<a name="l01050"></a>01050                   {
+<a name="l01051"></a>01051                      cpl_matrix_set(*covariance, i, j,
+<a name="l01052"></a>01052                                     cpl_matrix_get(
+<a name="l01053"></a>01053                                        cov, imfit, jmfit));
+<a name="l01054"></a>01054                      imfit += 1;
+<a name="l01055"></a>01055                   }
+<a name="l01056"></a>01056 
+<a name="l01057"></a>01057                assert( imfit == Mfit );
+<a name="l01058"></a>01058 
+<a name="l01059"></a>01059                jmfit += 1;
+<a name="l01060"></a>01060             }
+<a name="l01061"></a>01061 
+<a name="l01062"></a>01062          assert( jmfit == Mfit );
+<a name="l01063"></a>01063       }
+<a name="l01064"></a>01064 
+<a name="l01065"></a>01065       cpl_matrix_delete(cov);
+<a name="l01066"></a>01066    }
+<a name="l01067"></a>01067 
+<a name="l01068"></a>01068    cpl_free(ia_local);
+<a name="l01069"></a>01069    cpl_matrix_delete(alpha);
+<a name="l01070"></a>01070    cpl_matrix_delete(beta);
+<a name="l01071"></a>01071    cpl_free(a_da);
+<a name="l01072"></a>01072    cpl_free(part);
+<a name="l01073"></a>01073 
+<a name="l01074"></a>01074    <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l01075"></a>01075 }
+<a name="l01076"></a>01076 
+<a name="l01077"></a>01077 
+<a name="l01078"></a>01078 
+<a name="l01079"></a>01079 
+<a name="l01080"></a>01080 
+<a name="l01081"></a>01081 
+<a name="l01082"></a>01082 
+<a name="l01083"></a>01083 
+<a name="l01084"></a>01084 
+<a name="l01085"></a>01085 
+<a name="l01086"></a>01086 
+<a name="l01087"></a>01087 
+<a name="l01088"></a>01088 
+<a name="l01089"></a>01089 
+<a name="l01090"></a>01090 
+<a name="l01091"></a>01091 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l01092"></a>01092 
+<a name="l01104"></a>01104 <span class="keyword">static</span> <span class="keywordtype">void</span>
+<a name="l01105"></a>01105 sinfo_fit_amoeba_get_psum(<span class="keywordtype">int</span> ndim, <span class="keywordtype">int</span> mpts, <span class="keywordtype">double</span>** p, <span class="keywordtype">double</span>* psum)
+<a name="l01106"></a>01106 {
+<a name="l01107"></a>01107    <span class="keywordtype">int</span> i=0;
+<a name="l01108"></a>01108    <span class="keywordtype">int</span> j=0;
+<a name="l01109"></a>01109    <span class="keywordtype">double</span> sum=0;
+<a name="l01110"></a>01110    <span class="keywordflow">for</span> (j=0;j<ndim;j++) {
+<a name="l01111"></a>01111       <span class="keywordflow">for</span> (sum=0.0,i=0;i<mpts;i++) {
+<a name="l01112"></a>01112          sum += p[i][j];
+<a name="l01113"></a>01113       }
+<a name="l01114"></a>01114       psum[j]=sum;
+<a name="l01115"></a>01115    }
+<a name="l01116"></a>01116 
+<a name="l01117"></a>01117 }
+<a name="l01118"></a>01118 
+<a name="l01119"></a>01119 
+<a name="l01120"></a>01120 <span class="preprocessor">#define SINFO_FIT_AMOEBA_SWAP(a,b) {swap=(a);(a)=(b);(b)=swap;}</span>
+<a name="l01121"></a>01121 <span class="preprocessor"></span>
+<a name="l01122"></a>01122 
+<a name="l01123"></a>01123 
+<a name="l01150"></a>01150 <span class="keywordtype">void</span>
+<a name="l01151"></a>01151 sinfo_fit_amoeba(
+<a name="l01152"></a>01152    <span class="keywordtype">double</span>**p,
+<a name="l01153"></a>01153    <span class="keywordtype">double</span> y[],
+<a name="l01154"></a>01154    <span class="keywordtype">int</span> ndim,
+<a name="l01155"></a>01155    <span class="keywordtype">double</span> ftol,
+<a name="l01156"></a>01156    <span class="keywordtype">double</span> (*funk)(<span class="keywordtype">double</span>[]),
+<a name="l01157"></a>01157    <span class="keywordtype">int</span>* nfunk)
+<a name="l01158"></a>01158 {
+<a name="l01159"></a>01159 
+<a name="l01160"></a>01160 
+<a name="l01161"></a>01161    <span class="keywordtype">int</span> i=0;
+<a name="l01162"></a>01162    <span class="keywordtype">int</span> ihi=0;
+<a name="l01163"></a>01163    <span class="keywordtype">int</span> ilo=0;
+<a name="l01164"></a>01164    <span class="keywordtype">int</span> inhi=0;
+<a name="l01165"></a>01165    <span class="keywordtype">int</span> j=0;
+<a name="l01166"></a>01166    <span class="keywordtype">int</span> mpts=ndim+1;
+<a name="l01167"></a>01167    <span class="keywordtype">double</span> rtol=0;
+<a name="l01168"></a>01168    <span class="keywordtype">double</span> swap=0;
+<a name="l01169"></a>01169    <span class="keywordtype">double</span> ysave=0;
+<a name="l01170"></a>01170    <span class="keywordtype">double</span> ytry=0;
+<a name="l01171"></a>01171    cpl_vector* sum=NULL;
+<a name="l01172"></a>01172    <span class="keywordtype">double</span>* psum=NULL;
+<a name="l01173"></a>01173 
+<a name="l01174"></a>01174    sum=cpl_vector_new(ndim);
+<a name="l01175"></a>01175    psum=cpl_vector_get_data(sum);
+<a name="l01176"></a>01176    *nfunk=0;
+<a name="l01177"></a>01177 
+<a name="l01178"></a>01178    sinfo_fit_amoeba_get_psum(ndim,mpts,p,psum);
+<a name="l01179"></a>01179 
+<a name="l01180"></a>01180    <span class="keywordflow">for</span>(;;) {
+<a name="l01181"></a>01181       ilo=0;
+<a name="l01182"></a>01182       <span class="comment">/*</span>
+<a name="l01183"></a>01183 <span class="comment">        First we must determine which point is the highest (worst),</span>
+<a name="l01184"></a>01184 <span class="comment">        next-highest, and lowest (best), by looping over the points</span>
+<a name="l01185"></a>01185 <span class="comment">        in the simplex</span>
+<a name="l01186"></a>01186 <span class="comment">      */</span>
+<a name="l01187"></a>01187       ihi=y[0]>y[1] ? (inhi=1,0) : (inhi=0,1);
+<a name="l01188"></a>01188 
+<a name="l01189"></a>01189       <span class="keywordflow">for</span> (i=0;i< mpts;i++) {
+<a name="l01190"></a>01190          <span class="keywordflow">if</span> (y[i] <= y[ilo]) ilo=i;
+<a name="l01191"></a>01191          <span class="keywordflow">if</span> (y[i] > y[ihi]) {
+<a name="l01192"></a>01192             inhi=ihi;
+<a name="l01193"></a>01193             ihi=i;
+<a name="l01194"></a>01194          } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (y[i] > y[inhi] && i != ihi) inhi=i;
+<a name="l01195"></a>01195       }
+<a name="l01196"></a>01196       rtol=2.0*fabs(y[ihi]-y[ilo])/(fabs(y[ihi])+fabs(y[ilo]));
+<a name="l01197"></a>01197 
+<a name="l01198"></a>01198       <span class="comment">/*</span>
+<a name="l01199"></a>01199 <span class="comment">        compute the fractional range from highest to lowest and return if</span>
+<a name="l01200"></a>01200 <span class="comment">        satisfactory</span>
+<a name="l01201"></a>01201 <span class="comment">      */</span>
+<a name="l01202"></a>01202       <span class="keywordflow">if</span>(rtol < ftol) { <span class="comment">// if returning, but best point and value is in slot 1</span>
+<a name="l01203"></a>01203          SINFO_FIT_AMOEBA_SWAP(y[0],y[ilo]);
+<a name="l01204"></a>01204          <span class="keywordflow">for</span> (i=0;i<ndim;i++) SINFO_FIT_AMOEBA_SWAP(p[1][i],p[ilo][i]);
+<a name="l01205"></a>01205          <span class="keywordflow">break</span>;
+<a name="l01206"></a>01206       }
+<a name="l01207"></a>01207       <span class="keywordflow">if</span> (*nfunk >= SINFO_FIT_AMOEBA_NMAX) {
+<a name="l01208"></a>01208          <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"NMAX exceeded"</span>);
+<a name="l01209"></a>01209          SINFO_FIT_AMOEBA_SWAP(y[0],y[ilo]);
+<a name="l01210"></a>01210          <span class="keywordflow">for</span> (i=0;i<ndim;i++) SINFO_FIT_AMOEBA_SWAP(p[1][i],p[ilo][i]);
+<a name="l01211"></a>01211          <span class="keywordflow">for</span> (i=0;i<ndim;i++) {
+<a name="l01212"></a>01212             sinfo_msg(<span class="stringliteral">"p[1][i]=%g p[ilo][i]=%g ilo=%d"</span>,p[1][i],p[ilo][i],ilo);
+<a name="l01213"></a>01213          }
+<a name="l01214"></a>01214          assure(*nfunk >= SINFO_FIT_AMOEBA_NMAX,CPL_ERROR_UNSPECIFIED,
+<a name="l01215"></a>01215                 <span class="stringliteral">"NMAX exceeded"</span>);
+<a name="l01216"></a>01216          <span class="keywordflow">break</span>;
+<a name="l01217"></a>01217 
+<a name="l01218"></a>01218       }
+<a name="l01219"></a>01219       *nfunk +=2;
+<a name="l01220"></a>01220       <span class="comment">/*</span>
+<a name="l01221"></a>01221 <span class="comment">        Begin a new iteration. First extrapolate by a Factor -1 through the face</span>
+<a name="l01222"></a>01222 <span class="comment">        of the simplex across the high point, i.e. reflect the simplex from the</span>
+<a name="l01223"></a>01223 <span class="comment">        high point</span>
+<a name="l01224"></a>01224 <span class="comment">      */</span>
+<a name="l01225"></a>01225       ytry=sinfo_fit_amotry(p,y,psum,ndim,funk,ihi,-1.0);
+<a name="l01226"></a>01226       <span class="keywordflow">if</span>(ytry <= y[ilo]) {
+<a name="l01227"></a>01227          <span class="comment">/*</span>
+<a name="l01228"></a>01228 <span class="comment">            Gives a result better than the best point, so try an additional</span>
+<a name="l01229"></a>01229 <span class="comment">            extrapolation by a factor 2</span>
+<a name="l01230"></a>01230 <span class="comment">         */</span>
+<a name="l01231"></a>01231          ytry=sinfo_fit_amotry(p,y,psum,ndim,funk,ihi,2.0);
+<a name="l01232"></a>01232       } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (ytry >= y[inhi]) {
+<a name="l01233"></a>01233 
+<a name="l01234"></a>01234          <span class="comment">/*</span>
+<a name="l01235"></a>01235 <span class="comment">           The reflected point is worse than the second highest, so look for an</span>
+<a name="l01236"></a>01236 <span class="comment">           intermediate lower point, i.e. do a one-dimensional contraction</span>
+<a name="l01237"></a>01237 <span class="comment">         */</span>
+<a name="l01238"></a>01238          ysave=y[ihi];
+<a name="l01239"></a>01239          ytry=sinfo_fit_amotry(p,y,psum,ndim,funk,ihi,0.5);
+<a name="l01240"></a>01240          <span class="keywordflow">if</span>(ytry >= ysave) {
+<a name="l01241"></a>01241             <span class="comment">/*</span>
+<a name="l01242"></a>01242 <span class="comment">               Can't seem to get rid of that high point.</span>
+<a name="l01243"></a>01243 <span class="comment">               Better contract around the lowest (best) point</span>
+<a name="l01244"></a>01244 <span class="comment">            */</span>
+<a name="l01245"></a>01245             <span class="keywordflow">for</span>(i=0;i<mpts;i++) {
+<a name="l01246"></a>01246                <span class="keywordflow">if</span>(i != ilo) {
+<a name="l01247"></a>01247                   <span class="keywordflow">for</span>( j=0;j<ndim;j++) {
+<a name="l01248"></a>01248                      p[i][j]=psum[j]=0.5*(p[i][j]+p[ilo][j]);
+<a name="l01249"></a>01249                   }
+<a name="l01250"></a>01250                   y[i]=(*funk)(psum);
+<a name="l01251"></a>01251                }
+<a name="l01252"></a>01252             }
+<a name="l01253"></a>01253             *nfunk += ndim; <span class="comment">/* Keep track of function evaluations */</span>
+<a name="l01254"></a>01254             sinfo_fit_amoeba_get_psum(ndim,mpts,p,psum);<span class="comment">/* Recomputes psum */</span>
+<a name="l01255"></a>01255          }
+<a name="l01256"></a>01256       } <span class="keywordflow">else</span> {
+<a name="l01257"></a>01257          --(*nfunk);
+<a name="l01258"></a>01258          <span class="comment">/* Go back for the test of doneness and the next iteration */</span>
+<a name="l01259"></a>01259       }
+<a name="l01260"></a>01260    }
+<a name="l01261"></a>01261   cleanup:
+<a name="l01262"></a>01262    cpl_vector_delete(sum);
+<a name="l01263"></a>01263 }
+<a name="l01264"></a>01264 
+<a name="l01265"></a>01265 
+<a name="l01266"></a>01266 <span class="keyword">static</span>  <span class="keywordtype">double</span>
+<a name="l01267"></a>01267 sinfo_fit_amotry(<span class="keywordtype">double</span>** p, <span class="keywordtype">double</span> y[], <span class="keywordtype">double</span> psum[], <span class="keywordtype">int</span> ndim,
+<a name="l01268"></a>01268                  <span class="keywordtype">double</span> (*funk)(<span class="keywordtype">double</span>[]),<span class="keywordtype">int</span> ihi, <span class="keywordtype">double</span> fac)
+<a name="l01269"></a>01269 {
+<a name="l01270"></a>01270    <span class="keywordtype">int</span> j;
+<a name="l01271"></a>01271    <span class="keywordtype">double</span> fac1=0;
+<a name="l01272"></a>01272    <span class="keywordtype">double</span> fac2=0;
+<a name="l01273"></a>01273    <span class="keywordtype">double</span> ytry=0;
+<a name="l01274"></a>01274    cpl_vector * vtry=NULL;
+<a name="l01275"></a>01275    <span class="keywordtype">double</span> *ptry=NULL;
+<a name="l01276"></a>01276 
+<a name="l01277"></a>01277    vtry=cpl_vector_new(ndim);
+<a name="l01278"></a>01278    ptry=cpl_vector_get_data(vtry);
+<a name="l01279"></a>01279 
+<a name="l01280"></a>01280    fac1=(1.0-fac)/ndim;
+<a name="l01281"></a>01281    fac2=fac1-fac;
+<a name="l01282"></a>01282 
+<a name="l01283"></a>01283    <span class="keywordflow">for</span> (j=0;j<ndim;j++) {
+<a name="l01284"></a>01284       ptry[j]=psum[j]*fac1-p[ihi][j]*fac2;
+<a name="l01285"></a>01285    }
+<a name="l01286"></a>01286    ytry=(*funk)(ptry);
+<a name="l01287"></a>01287    <span class="keywordflow">if</span> (ytry < y[ihi]) {
+<a name="l01288"></a>01288       y[ihi]=ytry;
+<a name="l01289"></a>01289       <span class="keywordflow">for</span> (j=0;j<ndim;j++) {
+<a name="l01290"></a>01290          psum[j] += ptry[j]-p[ihi][j];
+<a name="l01291"></a>01291          p[ihi][j]=ptry[j];
+<a name="l01292"></a>01292       }
+<a name="l01293"></a>01293    }
+<a name="l01294"></a>01294    sinfo_free_my_vector(&vtry);
+<a name="l01295"></a>01295    <span class="keywordflow">return</span> ytry;
+<a name="l01296"></a>01296 }
+<a name="l01297"></a>01297 
+<a name="l01298"></a>01298 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l01299"></a>01299 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l01309"></a>01309 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l01310"></a>01310 
+<a name="l01311"></a>01311 <span class="keywordtype">int</span> sinfo_vector_dindgen(cpl_vector** v)
+<a name="l01312"></a>01312 {
+<a name="l01313"></a>01313 
+<a name="l01314"></a>01314    <span class="keywordtype">int</span> sz=0;
+<a name="l01315"></a>01315    <span class="keywordtype">int</span> i=0;
+<a name="l01316"></a>01316 
+<a name="l01317"></a>01317    cknull(*v,<span class="stringliteral">"Null input vector"</span>);
+<a name="l01318"></a>01318    check(sz=cpl_vector_get_size(*v),<span class="stringliteral">"Getting size of a vector"</span>);
+<a name="l01319"></a>01319 
+<a name="l01320"></a>01320    <span class="keywordflow">for</span>(i=0;i<sz;i++) {
+<a name="l01321"></a>01321       cpl_vector_set(*v,i,(<span class="keywordtype">double</span>)i);
+<a name="l01322"></a>01322    }
+<a name="l01323"></a>01323 
+<a name="l01324"></a>01324    <span class="keywordflow">return</span> 0;
+<a name="l01325"></a>01325   cleanup:
+<a name="l01326"></a>01326    <span class="keywordflow">return</span> -1;
+<a name="l01327"></a>01327 
+<a name="l01328"></a>01328 }
+<a name="l01329"></a>01329 
+<a name="l01330"></a>01330 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l01341"></a>01341 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l01342"></a>01342 
+<a name="l01343"></a>01343 <span class="keywordtype">int</span> sinfo_is_fits_file(<span class="keyword">const</span> <span class="keywordtype">char</span> *filename)
+<a name="l01344"></a>01344 {
+<a name="l01345"></a>01345    FILE    *fp ;
+<a name="l01346"></a>01346    <span class="keywordtype">char</span>    *magic ;
+<a name="l01347"></a>01347    <span class="keywordtype">int</span>        isfits ;
+<a name="l01348"></a>01348 
+<a name="l01349"></a>01349    <span class="keywordflow">if</span> ((fp = fopen(filename, <span class="stringliteral">"r"</span>))==NULL) {
+<a name="l01350"></a>01350       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"cannot open file [%s]"</span>, filename) ;
+<a name="l01351"></a>01351       <span class="keywordflow">return</span> -1 ;
+<a name="l01352"></a>01352    }
+<a name="l01353"></a>01353 
+<a name="l01354"></a>01354    magic = cpl_calloc(FITS_MAGIC_SZ+1, <span class="keyword">sizeof</span>(<span class="keywordtype">char</span>)) ;
+<a name="l01355"></a>01355    (void)fread(magic, 1, FITS_MAGIC_SZ, fp) ;
+<a name="l01356"></a>01356    (void)fclose(fp) ;
+<a name="l01357"></a>01357    magic[FITS_MAGIC_SZ] = (char)0 ;
+<a name="l01358"></a>01358    <span class="keywordflow">if</span> (strstr(magic, <span class="stringliteral">"SIMPLE"</span>)!=NULL)
+<a name="l01359"></a>01359       isfits = 1 ;
+<a name="l01360"></a>01360    <span class="keywordflow">else</span>
+<a name="l01361"></a>01361       isfits = 0 ;
+<a name="l01362"></a>01362    cpl_free(magic) ;
+<a name="l01363"></a>01363    <span class="keywordflow">return</span> isfits ;
+<a name="l01364"></a>01364 }
+<a name="l01365"></a>01365 
+<a name="l01366"></a>01366 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l01372"></a>01372 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l01373"></a>01373 cpl_error_code
+<a name="l01374"></a>01374 sinfo_table_correl(cpl_table * t1, cpl_table* t2, cpl_table* range,<span class="keywordtype">double</span>* xcor)
+<a name="l01375"></a>01375 {
+<a name="l01376"></a>01376 
+<a name="l01377"></a>01377    <span class="keywordtype">double</span> wsr=0;
+<a name="l01378"></a>01378    <span class="keywordtype">double</span> wer=0;
+<a name="l01379"></a>01379    <span class="keywordtype">int</span> nr=0;
+<a name="l01380"></a>01380    <span class="keywordtype">int</span> i=0;
+<a name="l01381"></a>01381    <span class="keywordtype">int</span> status=0;
+<a name="l01382"></a>01382    <span class="keywordtype">int</span> nrows=0;
+<a name="l01383"></a>01383    <span class="keywordtype">double</span> mean=0;
+<a name="l01384"></a>01384    <span class="keywordtype">double</span> prod=0;
+<a name="l01385"></a>01385 
+<a name="l01386"></a>01386    cpl_table* tmp_t1=NULL;
+<a name="l01387"></a>01387    cpl_table* tmp_t2=NULL;
+<a name="l01388"></a>01388 
+<a name="l01389"></a>01389    check_nomsg(nr=cpl_table_get_nrow(range));
+<a name="l01390"></a>01390    <span class="keywordflow">for</span>(i=0;i<nr;i++) {
+<a name="l01391"></a>01391       wsr=cpl_table_get_double(range,<span class="stringliteral">"WSTART"</span>,i,&status);
+<a name="l01392"></a>01392       wer=cpl_table_get_double(range,<span class="stringliteral">"WEND"</span>,i,&status);
+<a name="l01393"></a>01393       cpl_table_and_selected_double(t1,<span class="stringliteral">"WAVE"</span>,CPL_NOT_LESS_THAN,wsr);
+<a name="l01394"></a>01394       cpl_table_and_selected_double(t1,<span class="stringliteral">"WAVE"</span>,CPL_NOT_GREATER_THAN,wer);
+<a name="l01395"></a>01395       tmp_t1=cpl_table_extract_selected(t1);
+<a name="l01396"></a>01396       cpl_table_and_selected_double(t2,<span class="stringliteral">"WAVE"</span>,CPL_NOT_LESS_THAN,wsr);
+<a name="l01397"></a>01397       cpl_table_and_selected_double(t2,<span class="stringliteral">"WAVE"</span>,CPL_NOT_GREATER_THAN,wer);
+<a name="l01398"></a>01398       tmp_t2=cpl_table_extract_selected(t2);
+<a name="l01399"></a>01399       cpl_table_duplicate_column(tmp_t1,<span class="stringliteral">"INT1"</span>,tmp_t1,<span class="stringliteral">"INT"</span>);
+<a name="l01400"></a>01400       cpl_table_duplicate_column(tmp_t1,<span class="stringliteral">"INT2"</span>,tmp_t2,<span class="stringliteral">"INT"</span>);
+<a name="l01401"></a>01401       cpl_table_multiply_columns(tmp_t1,<span class="stringliteral">"INT1"</span>,<span class="stringliteral">"INT2"</span>);
+<a name="l01402"></a>01402       mean=cpl_table_get_column_mean(tmp_t1,<span class="stringliteral">"INT1"</span>);
+<a name="l01403"></a>01403       nrows=cpl_table_get_nrow(tmp_t1);
+<a name="l01404"></a>01404       prod=mean*nrows;
+<a name="l01405"></a>01405       *xcor+=prod;
+<a name="l01406"></a>01406    }
+<a name="l01407"></a>01407 
+<a name="l01408"></a>01408   cleanup:
+<a name="l01409"></a>01409    <span class="keywordflow">return</span> cpl_error_get_code();
+<a name="l01410"></a>01410 }
+<a name="l01416"></a>01416 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01417"></a>01417 cpl_error_code
+<a name="l01418"></a>01418 sinfo_frameset_merge(cpl_frameset * set1, cpl_frameset* set2)
+<a name="l01419"></a>01419 {
+<a name="l01420"></a>01420 
+<a name="l01421"></a>01421    cpl_frame* frm_tmp=NULL;
+<a name="l01422"></a>01422    cpl_frame* frm_dup=NULL;
+<a name="l01423"></a>01423 
+<a name="l01424"></a>01424    passure(set1 != NULL, <span class="stringliteral">"Wrong input set"</span>);
+<a name="l01425"></a>01425 
+<a name="l01426"></a>01426    check_nomsg(frm_tmp = cpl_frameset_get_first(set2));
+<a name="l01427"></a>01427    <span class="keywordflow">while</span> (frm_tmp != NULL)
+<a name="l01428"></a>01428    {
+<a name="l01429"></a>01429       frm_dup=cpl_frame_duplicate(frm_tmp);
+<a name="l01430"></a>01430       cpl_frameset_insert(set1,frm_dup);
+<a name="l01431"></a>01431       frm_tmp = cpl_frameset_get_next(set2);
+<a name="l01432"></a>01432    }
+<a name="l01433"></a>01433 
+<a name="l01434"></a>01434   cleanup:
+<a name="l01435"></a>01435    <span class="keywordflow">return</span> cpl_error_get_code();
+<a name="l01436"></a>01436 }
+<a name="l01437"></a>01437 
+<a name="l01438"></a>01438 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01446"></a>01446 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01447"></a>01447 
+<a name="l01448"></a>01448 cpl_error_code
+<a name="l01449"></a>01449 sinfo_extract_frames_group_type(<span class="keyword">const</span> cpl_frameset * <span class="keyword">set</span>,
+<a name="l01450"></a>01450                                 cpl_frameset** ext,
+<a name="l01451"></a>01451                                 cpl_frame_group type)
+<a name="l01452"></a>01452 {
+<a name="l01453"></a>01453    <span class="keyword">const</span> cpl_frame* frm_tmp=NULL;
+<a name="l01454"></a>01454    cpl_frame* frm_dup=NULL;
+<a name="l01455"></a>01455    cpl_frame_group g;
+<a name="l01456"></a>01456 
+<a name="l01457"></a>01457    check_nomsg(*ext = cpl_frameset_new());
+<a name="l01458"></a>01458    check_nomsg(frm_tmp = cpl_frameset_get_first_const(<span class="keyword">set</span>));
+<a name="l01459"></a>01459    <span class="keywordflow">while</span> (frm_tmp != NULL)
+<a name="l01460"></a>01460    {
+<a name="l01461"></a>01461       g=cpl_frame_get_group(frm_tmp);
+<a name="l01462"></a>01462       <span class="keywordflow">if</span>(g == type) {
+<a name="l01463"></a>01463          frm_dup=cpl_frame_duplicate(frm_tmp);
+<a name="l01464"></a>01464          cpl_frameset_insert(*ext,frm_dup);
+<a name="l01465"></a>01465          <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"group %d insert file %s "</span>,
+<a name="l01466"></a>01466                          type,cpl_frame_get_filename(frm_dup));
+<a name="l01467"></a>01467       }
+<a name="l01468"></a>01468       frm_tmp = cpl_frameset_get_next_const(<span class="keyword">set</span>);
+<a name="l01469"></a>01469    }
+<a name="l01470"></a>01470 
+<a name="l01471"></a>01471   cleanup:
+<a name="l01472"></a>01472    <span class="keywordflow">return</span> cpl_error_get_code();
+<a name="l01473"></a>01473 }
+<a name="l01474"></a>01474 
+<a name="l01475"></a>01475 
+<a name="l01476"></a>01476 
+<a name="l01477"></a>01477 
+<a name="l01488"></a>01488 <span class="keywordtype">int</span>
+<a name="l01489"></a>01489 sinfo_get_pupil_shift(cpl_imagelist* iml,<span class="keyword">const</span> <span class="keywordtype">int</span> n,cpl_table** qclog_tbl)
+<a name="l01490"></a>01490 {
+<a name="l01491"></a>01491    cpl_size max_ima_x=0;
+<a name="l01492"></a>01492    cpl_size max_ima_y=0;
+<a name="l01493"></a>01493    <span class="keywordtype">int</span> nx=0;
+<a name="l01494"></a>01494    <span class="keywordtype">int</span> ny=0;
+<a name="l01495"></a>01495 
+<a name="l01496"></a>01496    <span class="keywordtype">double</span> xshift=0;
+<a name="l01497"></a>01497    <span class="keywordtype">double</span> yshift=0;
+<a name="l01498"></a>01498 
+<a name="l01499"></a>01499    <span class="keywordtype">double</span> max_ima_cx=0;
+<a name="l01500"></a>01500    <span class="keywordtype">double</span> max_ima_cy=0;
+<a name="l01501"></a>01501 
+<a name="l01502"></a>01502    cpl_image* img=NULL;
+<a name="l01503"></a>01503    cpl_image* img_dup=NULL;
+<a name="l01504"></a>01504 
+<a name="l01505"></a>01505    <span class="keywordtype">char</span> key_name[FILE_NAME_SZ];
+<a name="l01506"></a>01506 
+<a name="l01507"></a>01507    img=cpl_imagelist_collapse_median_create(iml);
+<a name="l01508"></a>01508    nx=cpl_image_get_size_x(img);
+<a name="l01509"></a>01509    ny=cpl_image_get_size_y(img);
+<a name="l01510"></a>01510 
+<a name="l01511"></a>01511    img_dup=cpl_image_duplicate(img);
+<a name="l01512"></a>01512    sinfo_clean_nan(&img_dup);
+<a name="l01513"></a>01513    cpl_image_get_maxpos(img_dup,&max_ima_x,&max_ima_y);
+<a name="l01514"></a>01514    max_ima_cx=cpl_image_get_centroid_x_window(img_dup,1,1,nx,ny);
+<a name="l01515"></a>01515    max_ima_cy=cpl_image_get_centroid_y_window(img_dup,1,1,nx,ny);
+<a name="l01516"></a>01516 
+<a name="l01517"></a>01517    cpl_image_delete(img_dup);
+<a name="l01518"></a>01518 
+<a name="l01519"></a>01519 
+<a name="l01520"></a>01520    xshift=max_ima_cx-(double)nx/2;
+<a name="l01521"></a>01521    yshift=max_ima_cy-(double)ny/2;
+<a name="l01522"></a>01522 
+<a name="l01523"></a>01523    snprintf(key_name,<span class="keyword">sizeof</span>(key_name),<span class="stringliteral">"%s%d%s"</span>,<span class="stringliteral">"QC PUPIL"</span>,n,<span class="stringliteral">" SHIFTX"</span>);
+<a name="l01524"></a>01524    sinfo_qclog_add_double(*qclog_tbl,key_name,xshift,
+<a name="l01525"></a>01525                           <span class="stringliteral">"X shift centroid - center image"</span>,<span class="stringliteral">"%f"</span>);
+<a name="l01526"></a>01526 
+<a name="l01527"></a>01527    snprintf(key_name,<span class="keyword">sizeof</span>(key_name),<span class="stringliteral">"%s%d%s"</span>,<span class="stringliteral">"QC PUPIL"</span>,n,<span class="stringliteral">" SHIFTY"</span>);
+<a name="l01528"></a>01528    sinfo_qclog_add_double(*qclog_tbl,key_name,yshift,
+<a name="l01529"></a>01529                           <span class="stringliteral">"Y shift centroid - center image"</span>,<span class="stringliteral">"%f"</span>);
+<a name="l01530"></a>01530    cpl_image_delete(img);
+<a name="l01531"></a>01531 
+<a name="l01532"></a>01532    <span class="keywordflow">return</span> 0;
+<a name="l01533"></a>01533 }
+<a name="l01534"></a>01534 
+<a name="l01535"></a>01535 
+<a name="l01536"></a>01536 
+<a name="l01543"></a>01543 <span class="keywordtype">int</span> sinfo_get_strehl_type(cpl_frameset* sof)
+<a name="l01544"></a>01544 {
+<a name="l01545"></a>01545    <span class="keywordtype">int</span> strehl_sw=0;
+<a name="l01546"></a>01546    <span class="keywordtype">int</span> nobs=0;
+<a name="l01547"></a>01547    <span class="keywordtype">int</span> i=0;
+<a name="l01548"></a>01548    cpl_frameset* obs=NULL;
+<a name="l01549"></a>01549 
+<a name="l01550"></a>01550    cpl_frame* frame=NULL;
+<a name="l01551"></a>01551    <span class="keywordtype">float</span>* pix_scale=NULL;
+<a name="l01552"></a>01552    cpl_propertylist* plist=NULL;
+<a name="l01553"></a>01553 
+<a name="l01554"></a>01554    obs = cpl_frameset_new();
+<a name="l01555"></a>01555 
+<a name="l01556"></a>01556    sinfo_contains_frames_kind(sof,obs,PRO_OBS_PSF);
+<a name="l01557"></a>01557 
+<a name="l01558"></a>01558    nobs=cpl_frameset_get_size(obs);
+<a name="l01559"></a>01559    <span class="keywordflow">if</span> (nobs < 1) {
+<a name="l01560"></a>01560       sinfo_contains_frames_kind(sof,obs,PRO_OBS_STD);
+<a name="l01561"></a>01561       nobs=cpl_frameset_get_size(obs);
+<a name="l01562"></a>01562    }
+<a name="l01563"></a>01563 
+<a name="l01564"></a>01564    nobs=cpl_frameset_get_size(obs);
+<a name="l01565"></a>01565 
+<a name="l01566"></a>01566    <span class="keywordflow">if</span> (nobs < 1) {
+<a name="l01567"></a>01567       <span class="keywordflow">return</span> 0;
+<a name="l01568"></a>01568    } <span class="keywordflow">else</span> {
+<a name="l01569"></a>01569       pix_scale=cpl_calloc(nobs,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>));
+<a name="l01570"></a>01570       <span class="keywordflow">for</span>(i=0;i<nobs;i++) {
+<a name="l01571"></a>01571          frame=cpl_frameset_get_frame(obs,i);
+<a name="l01572"></a>01572          plist=cpl_propertylist_load(cpl_frame_get_filename(frame),0);
+<a name="l01573"></a>01573          pix_scale[i]=sinfo_pfits_get_pixscale(plist);
+<a name="l01574"></a>01574          cpl_propertylist_delete(plist);
+<a name="l01575"></a>01575       }
+<a name="l01576"></a>01576       <span class="keywordflow">if</span>(sinfo_pix_scale_isnot_const(pix_scale,nobs)) {
+<a name="l01577"></a>01577          strehl_sw=1;
+<a name="l01578"></a>01578       }
+<a name="l01579"></a>01579       cpl_free(pix_scale);
+<a name="l01580"></a>01580    }
+<a name="l01581"></a>01581    cpl_frameset_delete(obs);
+<a name="l01582"></a>01582 
+<a name="l01583"></a>01583    <span class="keywordflow">return</span> strehl_sw;
+<a name="l01584"></a>01584 
+<a name="l01585"></a>01585 }
+<a name="l01586"></a>01586 
+<a name="l01587"></a>01587 
+<a name="l01588"></a>01588 
+<a name="l01595"></a>01595 <span class="keywordtype">double</span> sinfo_get_wave_cent(<span class="keyword">const</span> <span class="keywordtype">char</span>* band)
+<a name="l01596"></a>01596 {
+<a name="l01597"></a>01597    <span class="keywordtype">double</span> lam=0.;
+<a name="l01598"></a>01598    <span class="keywordflow">if</span> (strcmp(band,<span class="stringliteral">"H+K"</span>) == 0) {
+<a name="l01599"></a>01599       lam=1.950;
+<a name="l01600"></a>01600    } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(band,<span class="stringliteral">"K"</span>) == 0) {
+<a name="l01601"></a>01601       lam=2.175;
+<a name="l01602"></a>01602    } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(band,<span class="stringliteral">"J"</span>) == 0) {
+<a name="l01603"></a>01603       lam=1.225;
+<a name="l01604"></a>01604    } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(band,<span class="stringliteral">"H"</span>) == 0) {
+<a name="l01605"></a>01605       lam=1.675;
+<a name="l01606"></a>01606    }
+<a name="l01607"></a>01607    <span class="keywordflow">return</span> lam;
+<a name="l01608"></a>01608 
+<a name="l01609"></a>01609 }
+<a name="l01610"></a>01610 
+<a name="l01611"></a>01611 
+<a name="l01612"></a>01612 
+<a name="l01621"></a>01621 <span class="keywordtype">int</span> sinfo_pix_scale_isnot_const(<span class="keywordtype">float</span>* pix_scale, <span class="keyword">const</span> <span class="keywordtype">int</span> n) {
+<a name="l01622"></a>01622    <span class="keywordtype">int</span> i=0;
+<a name="l01623"></a>01623    <span class="keywordtype">float</span> eps=0.0001;
+<a name="l01624"></a>01624    <span class="keywordtype">float</span> ref=pix_scale[0];
+<a name="l01625"></a>01625 
+<a name="l01626"></a>01626    <span class="keywordflow">for</span>(i=1;i<n;i++) {
+<a name="l01627"></a>01627       <span class="keywordflow">if</span>(fabs(pix_scale[i]-ref) > eps) <span class="keywordflow">return</span> 1;
+<a name="l01628"></a>01628    }
+<a name="l01629"></a>01629    <span class="keywordflow">return</span> 0;
+<a name="l01630"></a>01630 }
+<a name="l01631"></a>01631 
+<a name="l01632"></a>01632 
+<a name="l01640"></a>01640 <span class="keyword">const</span> <span class="keywordtype">char</span>* sinfo_get_pix_scale(<span class="keywordtype">float</span> ps) {
+<a name="l01641"></a>01641 
+<a name="l01642"></a>01642    <span class="keyword">const</span> <span class="keywordtype">char</span>* key_value;
+<a name="l01643"></a>01643    <span class="keywordtype">float</span> eps=0.0001;
+<a name="l01644"></a>01644 
+<a name="l01645"></a>01645    <span class="keywordflow">if</span>(fabs(ps - 0.025) < eps) {
+<a name="l01646"></a>01646       key_value=<span class="stringliteral">"0.025"</span>;
+<a name="l01647"></a>01647    }
+<a name="l01648"></a>01648    <span class="keywordflow">else</span> <span class="keywordflow">if</span> (fabs(ps - 0.1) < eps) {
+<a name="l01649"></a>01649       key_value=<span class="stringliteral">"0.1"</span>;
+<a name="l01650"></a>01650    }
+<a name="l01651"></a>01651    <span class="keywordflow">else</span> <span class="keywordflow">if</span> (fabs(ps - 0.25) < eps) {
+<a name="l01652"></a>01652       key_value=<span class="stringliteral">"0.25"</span>;
+<a name="l01653"></a>01653    }
+<a name="l01654"></a>01654    <span class="keywordflow">else</span> <span class="keywordflow">if</span> (fabs(ps - 1.0) < eps) {
+<a name="l01655"></a>01655       key_value=<span class="stringliteral">"pupil"</span>;
+<a name="l01656"></a>01656    } <span class="keywordflow">else</span> {
+<a name="l01657"></a>01657       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"ps=%f. Failed to set pixel scale"</span>,ps);
+<a name="l01658"></a>01658       <span class="keywordflow">return</span> NULL;
+<a name="l01659"></a>01659    }
+<a name="l01660"></a>01660 
+<a name="l01661"></a>01661    <span class="keywordflow">return</span> key_value;
+<a name="l01662"></a>01662 }
+<a name="l01663"></a>01663 
+<a name="l01664"></a>01664 
+<a name="l01680"></a>01680 <span class="keywordtype">int</span>  sinfo_get_clean_mean_window(cpl_image* img,
+<a name="l01681"></a>01681                                  <span class="keywordtype">int</span> llx, <span class="keywordtype">int</span> lly, <span class="keywordtype">int</span> urx, <span class="keywordtype">int</span> ury,
+<a name="l01682"></a>01682                                  <span class="keyword">const</span> <span class="keywordtype">int</span> kappa, <span class="keyword">const</span> <span class="keywordtype">int</span> nclip,
+<a name="l01683"></a>01683                                  <span class="keywordtype">double</span>* local_clean_mean,
+<a name="l01684"></a>01684                                  <span class="keywordtype">double</span>* clean_stdev)
+<a name="l01685"></a>01685 {
+<a name="l01686"></a>01686 
+<a name="l01687"></a>01687    <span class="keywordtype">double</span> mean=0;
+<a name="l01688"></a>01688    <span class="keywordtype">double</span> stdev=0;
+<a name="l01689"></a>01689    <span class="keywordtype">double</span> threshold=0;
+<a name="l01690"></a>01690    <span class="keywordtype">double</span> lo_cut=0;
+<a name="l01691"></a>01691    <span class="keywordtype">double</span> hi_cut=0;
+<a name="l01692"></a>01692    cpl_mask* mask=NULL;
+<a name="l01693"></a>01693    cpl_image* tmp=NULL;
+<a name="l01694"></a>01694    cpl_stats* stats=NULL;
+<a name="l01695"></a>01695    <span class="keywordtype">int</span> i=0;
+<a name="l01696"></a>01696 
+<a name="l01697"></a>01697    tmp=cpl_image_extract(img,llx,lly,urx,ury);
+<a name="l01698"></a>01698    cpl_image_accept_all(tmp);
+<a name="l01699"></a>01699    <span class="keywordflow">for</span>(i=0;i<nclip;i++) {
+<a name="l01700"></a>01700 
+<a name="l01701"></a>01701 
+<a name="l01702"></a>01702       cpl_stats_delete(stats);
+<a name="l01703"></a>01703       stats = cpl_stats_new_from_image(tmp, CPL_STATS_MEAN | CPL_STATS_STDEV);
+<a name="l01704"></a>01704       mean = cpl_stats_get_mean(stats);
+<a name="l01705"></a>01705       stdev = cpl_stats_get_stdev(stats);
+<a name="l01706"></a>01706 
+<a name="l01707"></a>01707       threshold=kappa*stdev;
+<a name="l01708"></a>01708       lo_cut=mean-threshold;
+<a name="l01709"></a>01709       hi_cut=mean+threshold;
+<a name="l01710"></a>01710       cpl_image_accept_all(tmp);
+<a name="l01711"></a>01711       mask=cpl_mask_threshold_image_create(tmp,lo_cut,hi_cut);
+<a name="l01712"></a>01712 
+<a name="l01713"></a>01713       cpl_mask_not(mask);
+<a name="l01714"></a>01714       cpl_image_reject_from_mask(tmp,mask);
+<a name="l01715"></a>01715       cpl_mask_delete(mask);
+<a name="l01716"></a>01716 
+<a name="l01717"></a>01717 
+<a name="l01718"></a>01718    }
+<a name="l01719"></a>01719    *local_clean_mean=mean;
+<a name="l01720"></a>01720    *clean_stdev=stdev;
+<a name="l01721"></a>01721    cpl_image_delete(tmp);
+<a name="l01722"></a>01722    cpl_stats_delete(stats);
+<a name="l01723"></a>01723 
+<a name="l01724"></a>01724 
+<a name="l01725"></a>01725    <span class="keywordflow">return</span> 0;
+<a name="l01726"></a>01726 
+<a name="l01727"></a>01727 
+<a name="l01728"></a>01728 }
+<a name="l01734"></a>01734 <span class="keywordtype">int</span> sinfo_check_rec_status(<span class="keyword">const</span> <span class="keywordtype">int</span> val) {
+<a name="l01735"></a>01735    <span class="keywordflow">if</span>(cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l01736"></a>01736       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"error before %d"</span>,val);
+<a name="l01737"></a>01737       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>((<span class="keywordtype">char</span>* ) cpl_error_get_message());
+<a name="l01738"></a>01738       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>((<span class="keywordtype">char</span>* ) cpl_error_get_where());
+<a name="l01739"></a>01739       <span class="keywordflow">return</span> -1;
+<a name="l01740"></a>01740    }
+<a name="l01741"></a>01741    <span class="keywordflow">return</span> 0;
+<a name="l01742"></a>01742 }
+<a name="l01743"></a>01743 
+<a name="l01750"></a>01750 <span class="keywordtype">int</span>
+<a name="l01751"></a>01751 sinfo_clean_nan(cpl_image** im)
+<a name="l01752"></a>01752 {
+<a name="l01753"></a>01753    <span class="keywordtype">int</span> i=0;
+<a name="l01754"></a>01754    <span class="keywordtype">int</span> j=0;
+<a name="l01755"></a>01755    <span class="keywordtype">int</span> nx=0;
+<a name="l01756"></a>01756    <span class="keywordtype">int</span> ny=0;
+<a name="l01757"></a>01757    <span class="keywordtype">float</span>* data=NULL;
+<a name="l01758"></a>01758 
+<a name="l01759"></a>01759    nx=cpl_image_get_size_x(*im);
+<a name="l01760"></a>01760    ny=cpl_image_get_size_y(*im);
+<a name="l01761"></a>01761    data=cpl_image_get_data_float(*im);
+<a name="l01762"></a>01762 
+<a name="l01763"></a>01763    <span class="keywordflow">for</span>(j=0;j<ny;j++) {
+<a name="l01764"></a>01764       <span class="keywordflow">for</span>(i=0;i<nx;i++) {
+<a name="l01765"></a>01765          <span class="keywordflow">if</span>(isnan(data[j*nx+i]) != 0) {
+<a name="l01766"></a>01766             data[j*nx+i] = 0;
+<a name="l01767"></a>01767          }
+<a name="l01768"></a>01768       }
+<a name="l01769"></a>01769    }
+<a name="l01770"></a>01770    <span class="keywordflow">return</span> 0;
+<a name="l01771"></a>01771 }
+<a name="l01772"></a>01772 
+<a name="l01782"></a>01782 <span class="keywordtype">void</span>
+<a name="l01783"></a>01783 sinfo_add_pro_fits_key(cpl_propertylist * plist,
+<a name="l01784"></a>01784                        <span class="keywordtype">char</span>* pro_catg,
+<a name="l01785"></a>01785                        <span class="keywordtype">char</span>* file_name,
+<a name="l01786"></a>01786                        <span class="keywordtype">char</span>* out_name)
+<a name="l01787"></a>01787 {
+<a name="l01788"></a>01788 
+<a name="l01789"></a>01789    <span class="keywordtype">char</span>* date=NULL;
+<a name="l01790"></a>01790    date     = sinfo_get_datetime_iso8601() ;
+<a name="l01791"></a>01791 
+<a name="l01792"></a>01792    cpl_propertylist_insert_after_string(plist, <span class="stringliteral">"EXPTIME"</span>,
+<a name="l01793"></a>01793                                         KEY_NAME_PIPEFILE, out_name) ;
+<a name="l01794"></a>01794    cpl_propertylist_set_comment(plist, KEY_NAME_PIPEFILE,KEY_HELP_PIPEFILE) ;
+<a name="l01795"></a>01795 
+<a name="l01796"></a>01796    cpl_propertylist_insert_after_string(plist, <span class="stringliteral">"EXPTIME"</span>,
+<a name="l01797"></a>01797                                         KEY_NAME_HPRO_DID, KEY_VALUE_HPRO_DID) ;
+<a name="l01798"></a>01798    cpl_propertylist_set_comment(plist, KEY_NAME_HPRO_DID,KEY_HELP_HPRO_DID) ;
+<a name="l01799"></a>01799 
+<a name="l01800"></a>01800    cpl_propertylist_insert_after_string(plist, <span class="stringliteral">"EXPTIME"</span>,
+<a name="l01801"></a>01801                                         KEY_NAME_HPRO_TYPE, <span class="stringliteral">"REDUCED"</span>) ;
+<a name="l01802"></a>01802    cpl_propertylist_set_comment(plist, KEY_NAME_HPRO_TYPE, KEY_HELP_HPRO_TYPE) ;
+<a name="l01803"></a>01803 
+<a name="l01804"></a>01804    cpl_propertylist_insert_after_string(plist, <span class="stringliteral">"EXPTIME"</span>,
+<a name="l01805"></a>01805                                         KEY_NAME_HPRO_CATG, pro_catg) ;
+<a name="l01806"></a>01806    cpl_propertylist_set_comment(plist, KEY_NAME_HPRO_CATG,  KEY_HELP_HPRO_CATG);
+<a name="l01807"></a>01807 
+<a name="l01808"></a>01808    cpl_propertylist_insert_after_string(plist, <span class="stringliteral">"EXPTIME"</span>,
+<a name="l01809"></a>01809                                         KEY_NAME_HPRO_STATUS, <span class="stringliteral">"OK"</span>) ;
+<a name="l01810"></a>01810    cpl_propertylist_set_comment(plist, KEY_NAME_HPRO_STATUS,KEY_HELP_HPRO_CATG);
+<a name="l01811"></a>01811 
+<a name="l01812"></a>01812    cpl_propertylist_insert_after_string(plist, <span class="stringliteral">"EXPTIME"</span>,
+<a name="l01813"></a>01813                                         KEY_NAME_HPRO_DATE, date) ;
+<a name="l01814"></a>01814    cpl_propertylist_set_comment(plist, KEY_NAME_HPRO_DATE, KEY_HELP_HPRO_DATE);
+<a name="l01815"></a>01815 
+<a name="l01816"></a>01816    cpl_propertylist_insert_after_string(plist, <span class="stringliteral">"EXPTIME"</span>,
+<a name="l01817"></a>01817                                         KEY_NAME_HPRO_RECID, file_name) ;
+<a name="l01818"></a>01818    cpl_propertylist_set_comment(plist, KEY_NAME_HPRO_RECID,KEY_HELP_HPRO_RECID);
+<a name="l01819"></a>01819 
+<a name="l01820"></a>01820    cpl_propertylist_insert_after_string(plist, <span class="stringliteral">"EXPTIME"</span>,
+<a name="l01821"></a>01821                                         KEY_NAME_HPRO_DRSID, PACKAGE_VERSION);
+<a name="l01822"></a>01822    cpl_propertylist_set_comment(plist, KEY_NAME_HPRO_DRSID,KEY_HELP_HPRO_DRSID);
+<a name="l01823"></a>01823 
+<a name="l01824"></a>01824 
+<a name="l01825"></a>01825 }
+<a name="l01826"></a>01826 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l01833"></a>01833 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l01834"></a>01834 <span class="keywordtype">int</span>  sinfo_compare_tags(
+<a name="l01835"></a>01835    <span class="keyword">const</span> cpl_frame   *   frame1,
+<a name="l01836"></a>01836    <span class="keyword">const</span> cpl_frame   *   frame2)
+<a name="l01837"></a>01837 {
+<a name="l01838"></a>01838    <span class="keywordtype">char</span>            *   v1 ;
+<a name="l01839"></a>01839    <span class="keywordtype">char</span>            *   v2 ;
+<a name="l01840"></a>01840 
+<a name="l01841"></a>01841    <span class="comment">/* Test entries */</span>
+<a name="l01842"></a>01842    <span class="keywordflow">if</span> (frame1==NULL || frame2==NULL) <span class="keywordflow">return</span> -1 ;
+<a name="l01843"></a>01843 
+<a name="l01844"></a>01844    <span class="comment">/* Get the tags */</span>
+<a name="l01845"></a>01845    <span class="keywordflow">if</span> ((v1 = (<span class="keywordtype">char</span>*)cpl_frame_get_tag(frame1)) == NULL) <span class="keywordflow">return</span> -1 ;
+<a name="l01846"></a>01846    <span class="keywordflow">if</span> ((v2 = (<span class="keywordtype">char</span>*)cpl_frame_get_tag(frame2)) == NULL) <span class="keywordflow">return</span> -1 ;
+<a name="l01847"></a>01847 
+<a name="l01848"></a>01848    <span class="comment">/* Compare the tags */</span>
+<a name="l01849"></a>01849    <span class="keywordflow">if</span> (strcmp(v1, v2)) <span class="keywordflow">return</span> 0 ;
+<a name="l01850"></a>01850    <span class="keywordflow">else</span> <span class="keywordflow">return</span> 1 ;
+<a name="l01851"></a>01851 }
+<a name="l01852"></a>01852 
+<a name="l01861"></a>01861 <span class="keywordtype">int</span> sinfo_extract_raw_pinhole_frames(cpl_frameset * sof, cpl_frameset** raw)
+<a name="l01862"></a>01862 {
+<a name="l01863"></a>01863    <span class="keywordtype">char</span>* tag=NULL;
+<a name="l01864"></a>01864    <span class="keywordtype">char</span>* name=NULL;
+<a name="l01865"></a>01865    cpl_frame* frame   = NULL;
+<a name="l01866"></a>01866    <span class="keywordtype">int</span> nsof=0;
+<a name="l01867"></a>01867    <span class="keywordtype">int</span> i=0;
+<a name="l01868"></a>01868    nsof = cpl_frameset_get_size(sof);
+<a name="l01869"></a>01869    <span class="keywordflow">for</span> (i=0 ; i<nsof ; i++) {
+<a name="l01870"></a>01870       frame = cpl_frameset_get_frame(sof,i);
+<a name="l01871"></a>01871       name= (<span class="keywordtype">char</span>*) cpl_frame_get_filename(frame);
+<a name="l01872"></a>01872       <span class="keywordflow">if</span>(sinfo_is_fits_file(name) == 1) {
+<a name="l01873"></a>01873          <span class="comment">/* to go on the file must exist */</span>
+<a name="l01874"></a>01874          <span class="keywordflow">if</span>(cpl_frame_get_tag(frame) != NULL) {
+<a name="l01875"></a>01875             <span class="comment">/* If the frame has a tag we process it. Else it is an object */</span>
+<a name="l01876"></a>01876             tag= (<span class="keywordtype">char</span>*) cpl_frame_get_tag(frame);
+<a name="l01877"></a>01877             <span class="keywordflow">if</span>(sinfo_frame_is_pinhole_lamp(tag) == 1) {
+<a name="l01878"></a>01878                cpl_frameset_insert(*raw,frame);
+<a name="l01879"></a>01879             }
+<a name="l01880"></a>01880          }
+<a name="l01881"></a>01881       }
+<a name="l01882"></a>01882    }
+<a name="l01883"></a>01883    <span class="keywordflow">return</span> 0;
+<a name="l01884"></a>01884 }
+<a name="l01885"></a>01885 
+<a name="l01886"></a>01886 
+<a name="l01887"></a>01887 <span class="keywordtype">int</span> sinfo_get_ins_set(<span class="keywordtype">char</span>* band,<span class="keywordtype">int</span>* ins_set){
+<a name="l01888"></a>01888 
+<a name="l01889"></a>01889    <span class="keywordflow">if</span> (strcmp(band,<span class="stringliteral">"H"</span>) == 0) {
+<a name="l01890"></a>01890       *ins_set = 0;
+<a name="l01891"></a>01891    }
+<a name="l01892"></a>01892    <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(band,<span class="stringliteral">"H+K"</span>) == 0) {
+<a name="l01893"></a>01893       *ins_set = 1;
+<a name="l01894"></a>01894    }
+<a name="l01895"></a>01895    <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(band,<span class="stringliteral">"K"</span>) == 0) {
+<a name="l01896"></a>01896       *ins_set = 2;
+<a name="l01897"></a>01897    }
+<a name="l01898"></a>01898    <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(band,<span class="stringliteral">"J"</span>) == 0) {
+<a name="l01899"></a>01899       *ins_set = 3;
+<a name="l01900"></a>01900    }
+<a name="l01901"></a>01901    <span class="keywordflow">return</span> 0;
+<a name="l01902"></a>01902 
+<a name="l01903"></a>01903 
+<a name="l01904"></a>01904 }
+<a name="l01905"></a>01905 <span class="keywordtype">int</span> sinfo_extract_raw_frames(cpl_frameset * sof, cpl_frameset** raw)
+<a name="l01906"></a>01906 {
+<a name="l01907"></a>01907    <span class="keywordtype">char</span>* tag=NULL;
+<a name="l01908"></a>01908    <span class="keywordtype">char</span>* name=NULL;
+<a name="l01909"></a>01909    cpl_frame* frame   = NULL;
+<a name="l01910"></a>01910    <span class="keywordtype">int</span> nsof=0;
+<a name="l01911"></a>01911    <span class="keywordtype">int</span> i=0;
+<a name="l01912"></a>01912    nsof = cpl_frameset_get_size(sof);
+<a name="l01913"></a>01913    <span class="keywordflow">for</span> (i=0 ; i<nsof ; i++) {
+<a name="l01914"></a>01914       frame = cpl_frameset_get_frame(sof,i);
+<a name="l01915"></a>01915       name= (<span class="keywordtype">char</span>*) cpl_frame_get_filename(frame);
+<a name="l01916"></a>01916       <span class="keywordflow">if</span>(sinfo_is_fits_file(name) == 1) {
+<a name="l01917"></a>01917          <span class="comment">/* to go on the file must exist */</span>
+<a name="l01918"></a>01918          <span class="keywordflow">if</span>(cpl_frame_get_tag(frame) != NULL) {
+<a name="l01919"></a>01919             <span class="comment">/* If the frame has a tag we process it. Else it is an object */</span>
+<a name="l01920"></a>01920             tag= (<span class="keywordtype">char</span>*) cpl_frame_get_tag(frame);
+<a name="l01921"></a>01921             <span class="keywordflow">if</span>(sinfo_frame_is_raw(tag) == 1) {
+<a name="l01922"></a>01922                cpl_frameset_insert(*raw,frame);
+<a name="l01923"></a>01923             }
+<a name="l01924"></a>01924          }
+<a name="l01925"></a>01925       }
+<a name="l01926"></a>01926    }
+<a name="l01927"></a>01927    <span class="keywordflow">return</span> 0;
+<a name="l01928"></a>01928 }
+<a name="l01929"></a>01929 
+<a name="l01930"></a>01930 <span class="keywordtype">int</span> sinfo_remove_qc_frames(cpl_frameset* sof,cpl_frameset** raw)
+<a name="l01931"></a>01931 {
+<a name="l01932"></a>01932    <span class="keywordtype">char</span>* tag=NULL;
+<a name="l01933"></a>01933    <span class="keywordtype">char</span>* name=NULL;
+<a name="l01934"></a>01934    cpl_frame* frame   = NULL;
+<a name="l01935"></a>01935    <span class="keywordtype">int</span> nsof=0;
+<a name="l01936"></a>01936    <span class="keywordtype">int</span> i=0;
+<a name="l01937"></a>01937 
+<a name="l01938"></a>01938    nsof = cpl_frameset_get_size(sof);
+<a name="l01939"></a>01939    <span class="keywordflow">for</span> (i=0 ; i<nsof ; i++) {
+<a name="l01940"></a>01940       frame = cpl_frameset_get_frame(sof,i);
+<a name="l01941"></a>01941       name= (<span class="keywordtype">char</span>*) cpl_frame_get_filename(frame);
+<a name="l01942"></a>01942       <span class="comment">/* sinfo_msg("name=%s",name); */</span>
+<a name="l01943"></a>01943       <span class="keywordflow">if</span>(sinfo_is_fits_file(name) == 1) {
+<a name="l01944"></a>01944          <span class="comment">/* sinfo_msg("\t exist "); */</span>
+<a name="l01945"></a>01945          <span class="comment">/* to go on the file must exist */</span>
+<a name="l01946"></a>01946          <span class="keywordflow">if</span>(cpl_frame_get_tag(frame) != NULL) {
+<a name="l01947"></a>01947             <span class="comment">/* If the frame has a tag we process it. Else it is an object */</span>
+<a name="l01948"></a>01948             tag= (<span class="keywordtype">char</span>*) cpl_frame_get_tag(frame);
+<a name="l01949"></a>01949             <span class="comment">/* sinfo_msg("\t tag %s\n ",tag); */</span>
+<a name="l01950"></a>01950             <span class="keywordflow">if</span>(strstr(tag,<span class="stringliteral">"QC"</span>) != NULL) {
+<a name="l01951"></a>01951                <span class="comment">/* sinfo_msg("remove frame %s\n",name); */</span>
+<a name="l01952"></a>01952                cpl_frameset_erase(*raw,tag);
+<a name="l01953"></a>01953             }
+<a name="l01954"></a>01954          }
+<a name="l01955"></a>01955       } <span class="keywordflow">else</span> {
+<a name="l01956"></a>01956          <span class="comment">/* sinfo_msg("remove frame\n"); */</span>
+<a name="l01957"></a>01957          cpl_frameset_erase_frame(*raw,frame);
+<a name="l01958"></a>01958       }
+<a name="l01959"></a>01959    }
+<a name="l01960"></a>01960    <span class="keywordflow">return</span> 0;
+<a name="l01961"></a>01961 
+<a name="l01962"></a>01962 }
+<a name="l01963"></a>01963 
+<a name="l01964"></a>01964 
+<a name="l01965"></a>01965 <span class="keywordtype">int</span> sinfo_contains_frames_kind(cpl_frameset * sof,
+<a name="l01966"></a>01966                                cpl_frameset* raw,
+<a name="l01967"></a>01967                                <span class="keyword">const</span> <span class="keywordtype">char</span>*         type)
+<a name="l01968"></a>01968 {
+<a name="l01969"></a>01969    <span class="keywordtype">char</span>* tag=NULL;
+<a name="l01970"></a>01970    <span class="keywordtype">char</span>* name=NULL;
+<a name="l01971"></a>01971    cpl_frame* frame   = NULL;
+<a name="l01972"></a>01972    cpl_frame* frame_dup   = NULL;
+<a name="l01973"></a>01973 
+<a name="l01974"></a>01974    <span class="keywordtype">int</span> nsof=0;
+<a name="l01975"></a>01975    <span class="keywordtype">int</span> i=0;
+<a name="l01976"></a>01976    nsof = cpl_frameset_get_size(sof);
+<a name="l01977"></a>01977    <span class="keywordflow">for</span> (i=0 ; i<nsof ; i++) {
+<a name="l01978"></a>01978      frame = cpl_frameset_get_frame(sof,i);
+<a name="l01979"></a>01979       name= (<span class="keywordtype">char</span>*) cpl_frame_get_filename(frame);
+<a name="l01980"></a>01980       <span class="keywordflow">if</span>(sinfo_is_fits_file(name) == 1) {
+<a name="l01981"></a>01981          <span class="comment">/* to go on the file must exist */</span>
+<a name="l01982"></a>01982          <span class="keywordflow">if</span>(cpl_frame_get_tag(frame) != NULL) {
+<a name="l01983"></a>01983             <span class="comment">/* If the frame has a tag we process it. Else it is an object */</span>
+<a name="l01984"></a>01984             tag= (<span class="keywordtype">char</span>*) cpl_frame_get_tag(frame);
+<a name="l01985"></a>01985             <span class="comment">/* sinfo_msg("name=%s tag=%s type=%s\n",name,tag,type); */</span>
+<a name="l01986"></a>01986             <span class="keywordflow">if</span>(strstr(tag,type) != NULL) {
+<a name="l01987"></a>01987                <span class="comment">/* sinfo_msg("Match name=%s tag=%s type=%s\n",name,tag,type); */</span>
+<a name="l01988"></a>01988                frame_dup = cpl_frame_duplicate(frame);
+<a name="l01989"></a>01989                cpl_frameset_insert(raw,frame_dup);
+<a name="l01990"></a>01990                <span class="comment">/* sinfo_msg("inserted\n"); */</span>
+<a name="l01991"></a>01991             }
+<a name="l01992"></a>01992          }
+<a name="l01993"></a>01993       }
+<a name="l01994"></a>01994    }
+<a name="l01995"></a>01995    <span class="keywordflow">return</span> 0;
+<a name="l01996"></a>01996 }
+<a name="l01997"></a>01997 
+<a name="l01998"></a>01998 
+<a name="l01999"></a>01999 
+<a name="l02000"></a>02000 
+<a name="l02001"></a>02001 <span class="keywordtype">int</span> sinfo_is_fibres_on_off(cpl_frameset * sof,
+<a name="l02002"></a>02002                            cpl_frameset* raw)
+<a name="l02003"></a>02003 {
+<a name="l02004"></a>02004    <span class="keywordtype">char</span>* tag=NULL;
+<a name="l02005"></a>02005    <span class="keywordtype">char</span>* name=NULL;
+<a name="l02006"></a>02006    cpl_frame* frame   = NULL;
+<a name="l02007"></a>02007    cpl_frame* frame_dup   = NULL;
+<a name="l02008"></a>02008 
+<a name="l02009"></a>02009    <span class="keywordtype">int</span> nsof=0;
+<a name="l02010"></a>02010    <span class="keywordtype">int</span> i=0;
+<a name="l02011"></a>02011    nsof = cpl_frameset_get_size(sof);
+<a name="l02012"></a>02012    <span class="keywordflow">for</span> (i=0 ; i<nsof ; i++) {
+<a name="l02013"></a>02013       frame = cpl_frameset_get_frame(sof,i);
+<a name="l02014"></a>02014       name= (<span class="keywordtype">char</span>*) cpl_frame_get_filename(frame);
+<a name="l02015"></a>02015       <span class="keywordflow">if</span>(sinfo_is_fits_file(name) == 1) {
+<a name="l02016"></a>02016          <span class="comment">/* to go on the file must exist */</span>
+<a name="l02017"></a>02017          <span class="keywordflow">if</span>(cpl_frame_get_tag(frame) != NULL) {
+<a name="l02018"></a>02018             <span class="comment">/* If the frame has a tag we process it. Else it is an object */</span>
+<a name="l02019"></a>02019             tag= (<span class="keywordtype">char</span>*) cpl_frame_get_tag(frame);
+<a name="l02020"></a>02020             <span class="comment">/* sinfo_msg("name=%s tag=%s type=%s\n",name,tag,type); */</span>
+<a name="l02021"></a>02021             <span class="keywordflow">if</span>( strcmp(tag,PRO_FIBRE_NS_STACKED ) == 0) {
+<a name="l02022"></a>02022                <span class="comment">/* sinfo_msg("Match name=%s tag=%s type=%s\n",name,tag); */</span>
+<a name="l02023"></a>02023                frame_dup = cpl_frame_duplicate(frame);
+<a name="l02024"></a>02024                cpl_frameset_insert(raw,frame_dup);
+<a name="l02025"></a>02025                <span class="comment">/* sinfo_msg("inserted\n"); */</span>
+<a name="l02026"></a>02026             }
+<a name="l02027"></a>02027          }
+<a name="l02028"></a>02028       }
+<a name="l02029"></a>02029    }
+<a name="l02030"></a>02030    <span class="keywordflow">return</span> 0;
+<a name="l02031"></a>02031 }
+<a name="l02032"></a>02032 
+<a name="l02033"></a>02033 
+<a name="l02034"></a>02034 <span class="keywordtype">int</span> sinfo_contains_frames_type(cpl_frameset * sof,
+<a name="l02035"></a>02035                                cpl_frameset** raw,
+<a name="l02036"></a>02036                                <span class="keyword">const</span> <span class="keywordtype">char</span>*          type)
+<a name="l02037"></a>02037 {
+<a name="l02038"></a>02038    <span class="keywordtype">char</span>* tag=NULL;
+<a name="l02039"></a>02039    <span class="keywordtype">char</span>* name=NULL;
+<a name="l02040"></a>02040    cpl_frame* frame   = NULL;
+<a name="l02041"></a>02041    cpl_frame* frame_dup   = NULL;
+<a name="l02042"></a>02042    <span class="keywordtype">int</span> nsof=0;
+<a name="l02043"></a>02043    <span class="keywordtype">int</span> i=0;
+<a name="l02044"></a>02044    nsof = cpl_frameset_get_size(sof);
+<a name="l02045"></a>02045    <span class="keywordflow">for</span> (i=0 ; i<nsof ; i++) {
+<a name="l02046"></a>02046       frame = cpl_frameset_get_frame(sof,i);
+<a name="l02047"></a>02047       name= (<span class="keywordtype">char</span>*) cpl_frame_get_filename(frame);
+<a name="l02048"></a>02048       <span class="keywordflow">if</span>(sinfo_is_fits_file(name) == 1) {
+<a name="l02049"></a>02049          <span class="comment">/* to go on the file must exist */</span>
+<a name="l02050"></a>02050          <span class="keywordflow">if</span>(cpl_frame_get_tag(frame) != NULL) {
+<a name="l02051"></a>02051             <span class="comment">/* If the frame has a tag we process it. Else it is an object */</span>
+<a name="l02052"></a>02052             tag= (<span class="keywordtype">char</span>*) cpl_frame_get_tag(frame);
+<a name="l02053"></a>02053             <span class="keywordflow">if</span>(strstr(tag,type) != NULL) {
+<a name="l02054"></a>02054                <span class="comment">/* sinfo_msg("name=%s tag=%s type=%s\n",name,tag,type); */</span>
+<a name="l02055"></a>02055                frame_dup=cpl_frame_duplicate(frame);
+<a name="l02056"></a>02056                cpl_frameset_insert(*raw,frame_dup);
+<a name="l02057"></a>02057             }
+<a name="l02058"></a>02058          }
+<a name="l02059"></a>02059       }
+<a name="l02060"></a>02060    }
+<a name="l02061"></a>02061    <span class="keywordflow">return</span> 0;
+<a name="l02062"></a>02062 }
+<a name="l02063"></a>02063 
+<a name="l02064"></a>02064 <span class="keywordtype">int</span> sinfo_extract_raw_frames_type2(cpl_frameset * sof,
+<a name="l02065"></a>02065                                    cpl_frameset** raw,
+<a name="l02066"></a>02066                                    <span class="keyword">const</span> <span class="keywordtype">char</span>*          type)
+<a name="l02067"></a>02067 {
+<a name="l02068"></a>02068 
+<a name="l02069"></a>02069    cpl_frame* frame=NULL;
+<a name="l02070"></a>02070    cpl_frame* frame_dup   = NULL;
+<a name="l02071"></a>02071    frame = cpl_frameset_find(sof,type);
+<a name="l02072"></a>02072    <span class="keywordflow">while</span>(frame) {
+<a name="l02073"></a>02073       frame_dup=cpl_frame_duplicate(frame);
+<a name="l02074"></a>02074       cpl_frameset_insert(*raw,frame_dup);
+<a name="l02075"></a>02075       frame = cpl_frameset_find(sof,NULL);
+<a name="l02076"></a>02076    }
+<a name="l02077"></a>02077    <span class="keywordflow">return</span> 0;
+<a name="l02078"></a>02078 
+<a name="l02079"></a>02079 }
+<a name="l02080"></a>02080 
+<a name="l02081"></a>02081 
+<a name="l02082"></a>02082 <span class="keywordtype">int</span> sinfo_extract_raw_frames_type1(cpl_frameset * sof,
+<a name="l02083"></a>02083                                    cpl_frameset* raw,
+<a name="l02084"></a>02084                                    <span class="keyword">const</span> <span class="keywordtype">char</span>*          type)
+<a name="l02085"></a>02085 {
+<a name="l02086"></a>02086 
+<a name="l02087"></a>02087    cpl_frame* frame=NULL;
+<a name="l02088"></a>02088    cpl_frame* frame_dup   = NULL;
+<a name="l02089"></a>02089    frame = cpl_frameset_find(sof,type);
+<a name="l02090"></a>02090    <span class="keywordflow">while</span>(frame) {
+<a name="l02091"></a>02091       frame_dup=cpl_frame_duplicate(frame);
+<a name="l02092"></a>02092       cpl_frameset_insert(raw,frame_dup);
+<a name="l02093"></a>02093       frame = cpl_frameset_find(sof,NULL);
+<a name="l02094"></a>02094    }
+<a name="l02095"></a>02095    <span class="keywordflow">return</span> 0;
+<a name="l02096"></a>02096 
+<a name="l02097"></a>02097 }
+<a name="l02098"></a>02098 
+<a name="l02099"></a>02099 <span class="keywordtype">int</span> sinfo_extract_raw_frames_type(cpl_frameset * sof,
+<a name="l02100"></a>02100                                   cpl_frameset** raw,
+<a name="l02101"></a>02101                                   <span class="keyword">const</span> <span class="keywordtype">char</span>*          type)
+<a name="l02102"></a>02102 {
+<a name="l02103"></a>02103    <span class="keywordtype">char</span> tag[FILE_NAME_SZ];
+<a name="l02104"></a>02104    <span class="keywordtype">char</span> name[FILE_NAME_SZ];
+<a name="l02105"></a>02105    cpl_frame* frame   = NULL;
+<a name="l02106"></a>02106    cpl_frame* frame_dup   = NULL;
+<a name="l02107"></a>02107    <span class="keywordtype">int</span> nsof=0;
+<a name="l02108"></a>02108    <span class="keywordtype">int</span> i=0;
+<a name="l02109"></a>02109    nsof = cpl_frameset_get_size(sof);
+<a name="l02110"></a>02110    <span class="keywordflow">for</span> (i=0 ; i<nsof ; i++) {
+<a name="l02111"></a>02111       frame = cpl_frameset_get_frame(sof,i);
+<a name="l02112"></a>02112       strcpy(name, cpl_frame_get_filename(frame));
+<a name="l02113"></a>02113       <span class="keywordflow">if</span>(sinfo_is_fits_file(name) == 1) {
+<a name="l02114"></a>02114          <span class="comment">/* to go on the file must exist */</span>
+<a name="l02115"></a>02115          <span class="keywordflow">if</span>(cpl_frame_get_tag(frame) != NULL) {
+<a name="l02116"></a>02116             <span class="comment">/* If the frame has a tag we process it. Else it is an object */</span>
+<a name="l02117"></a>02117             strcpy(tag,cpl_frame_get_tag(frame));
+<a name="l02118"></a>02118             <span class="keywordflow">if</span>(strcmp(tag,type) == 0) {
+<a name="l02119"></a>02119                <span class="comment">/* sinfo_msg("name=%s tag=%s type=%s\n",name,tag,type); */</span>
+<a name="l02120"></a>02120                frame_dup=cpl_frame_duplicate(frame);
+<a name="l02121"></a>02121 
+<a name="l02122"></a>02122                cpl_frameset_insert(*raw,frame_dup);
+<a name="l02123"></a>02123             }
+<a name="l02124"></a>02124          }
+<a name="l02125"></a>02125       }
+<a name="l02126"></a>02126    }
+<a name="l02127"></a>02127    <span class="keywordflow">return</span> 0;
+<a name="l02128"></a>02128 }
+<a name="l02129"></a>02129 
+<a name="l02130"></a>02130 <span class="keywordtype">int</span> sinfo_extract_frames_type(cpl_frameset * sof,
+<a name="l02131"></a>02131                               cpl_frameset * raw,
+<a name="l02132"></a>02132                               <span class="keyword">const</span> <span class="keywordtype">char</span>*          type)
+<a name="l02133"></a>02133 {
+<a name="l02134"></a>02134    <span class="keywordtype">char</span>* tag=NULL;
+<a name="l02135"></a>02135    <span class="keywordtype">char</span>* name=NULL;
+<a name="l02136"></a>02136    cpl_frame* frame   = NULL;
+<a name="l02137"></a>02137    cpl_frame* frame_dup   = NULL;
+<a name="l02138"></a>02138    <span class="keywordtype">int</span> nsof=0;
+<a name="l02139"></a>02139    <span class="keywordtype">int</span> i=0;
+<a name="l02140"></a>02140    nsof = cpl_frameset_get_size(sof);
+<a name="l02141"></a>02141    <span class="keywordflow">for</span> (i=0 ; i<nsof ; i++) {
+<a name="l02142"></a>02142       frame = cpl_frameset_get_frame(sof,i);
+<a name="l02143"></a>02143       name= (<span class="keywordtype">char</span>*) cpl_frame_get_filename(frame);
+<a name="l02144"></a>02144       <span class="keywordflow">if</span>(sinfo_is_fits_file(name) == 1) {
+<a name="l02145"></a>02145          <span class="comment">/* to go on the file must exist */</span>
+<a name="l02146"></a>02146          <span class="keywordflow">if</span>(cpl_frame_get_tag(frame) != NULL) {
+<a name="l02147"></a>02147             <span class="comment">/* If the frame has a tag we process it. Else it is an object */</span>
+<a name="l02148"></a>02148             tag= (<span class="keywordtype">char</span>*) cpl_frame_get_tag(frame);
+<a name="l02149"></a>02149             <span class="keywordflow">if</span>(strcmp(tag,type) == 0) {
+<a name="l02150"></a>02150                <span class="comment">/* sinfo_msg("name=%s tag=%s type=%s\n",name,tag,type); */</span>
+<a name="l02151"></a>02151                frame_dup=cpl_frame_duplicate(frame);
+<a name="l02152"></a>02152                cpl_frameset_insert(raw,frame_dup);
+<a name="l02153"></a>02153             }
+<a name="l02154"></a>02154          }
+<a name="l02155"></a>02155       }
+<a name="l02156"></a>02156    }
+<a name="l02157"></a>02157    <span class="keywordflow">return</span> 0;
+<a name="l02158"></a>02158 }
+<a name="l02159"></a>02159 
+<a name="l02160"></a>02160 
+<a name="l02161"></a>02161 <span class="keywordtype">int</span> sinfo_extract_obj_frames(cpl_frameset * sof, cpl_frameset* obj)
+<a name="l02162"></a>02162 {
+<a name="l02163"></a>02163    <span class="keywordtype">char</span>* tag=NULL;
+<a name="l02164"></a>02164    <span class="keywordtype">char</span>* name=NULL;
+<a name="l02165"></a>02165    cpl_frame* frame   = NULL;
+<a name="l02166"></a>02166    cpl_frame* frame_dup   = NULL;
+<a name="l02167"></a>02167 
+<a name="l02168"></a>02168    <span class="keywordtype">int</span> nsof=0;
+<a name="l02169"></a>02169    <span class="keywordtype">int</span> i=0;
+<a name="l02170"></a>02170    nsof = cpl_frameset_get_size(sof);
+<a name="l02171"></a>02171    <span class="keywordflow">for</span> (i=0 ; i<nsof ; i++) {
+<a name="l02172"></a>02172       frame = cpl_frameset_get_frame(sof,i);
+<a name="l02173"></a>02173       name= (<span class="keywordtype">char</span>*) cpl_frame_get_filename(frame);
+<a name="l02174"></a>02174       <span class="keywordflow">if</span>(sinfo_is_fits_file(name) ==1) {
+<a name="l02175"></a>02175          <span class="comment">/* to go on the file must exist */</span>
+<a name="l02176"></a>02176          <span class="keywordflow">if</span>(cpl_frame_get_tag(frame) != NULL) {
+<a name="l02177"></a>02177             <span class="comment">/* If the frame has a tag we process it. Else it is an object */</span>
+<a name="l02178"></a>02178             tag= (<span class="keywordtype">char</span>*) cpl_frame_get_tag(frame);
+<a name="l02179"></a>02179             <span class="keywordflow">if</span>(sinfo_tag_is_obj(tag) == 1) {
+<a name="l02180"></a>02180                frame_dup=cpl_frame_duplicate(frame);
+<a name="l02181"></a>02181                cpl_frameset_insert(obj,frame_dup);
+<a name="l02182"></a>02182             }
+<a name="l02183"></a>02183          }
+<a name="l02184"></a>02184       }
+<a name="l02185"></a>02185    }
+<a name="l02186"></a>02186 
+<a name="l02187"></a>02187    <span class="keywordflow">return</span> 0;
+<a name="l02188"></a>02188 }
+<a name="l02189"></a>02189 
+<a name="l02190"></a>02190 
+<a name="l02191"></a>02191 <span class="keywordtype">int</span> sinfo_extract_obj_products(cpl_frameset * sof, cpl_frameset* obj)
+<a name="l02192"></a>02192 {
+<a name="l02193"></a>02193    <span class="keywordtype">char</span>* tag=NULL;
+<a name="l02194"></a>02194    <span class="keywordtype">char</span>* name=NULL;
+<a name="l02195"></a>02195    cpl_frame* frame   = NULL;
+<a name="l02196"></a>02196    cpl_frame* frame_dup   = NULL;
+<a name="l02197"></a>02197 
+<a name="l02198"></a>02198    <span class="keywordtype">int</span> nsof=0;
+<a name="l02199"></a>02199    <span class="keywordtype">int</span> i=0;
+<a name="l02200"></a>02200    nsof = cpl_frameset_get_size(sof);
+<a name="l02201"></a>02201    <span class="keywordflow">for</span> (i=0 ; i<nsof ; i++) {
+<a name="l02202"></a>02202       frame = cpl_frameset_get_frame(sof,i);
+<a name="l02203"></a>02203       name= (<span class="keywordtype">char</span>*) cpl_frame_get_filename(frame);
+<a name="l02204"></a>02204       <span class="keywordflow">if</span>(sinfo_is_fits_file(name) ==1) {
+<a name="l02205"></a>02205          <span class="comment">/* to go on the file must exist */</span>
+<a name="l02206"></a>02206          <span class="keywordflow">if</span>(cpl_frame_get_tag(frame) != NULL) {
+<a name="l02207"></a>02207             <span class="comment">/* If the frame has a tag we process it. Else it is an object */</span>
+<a name="l02208"></a>02208             tag= (<span class="keywordtype">char</span>*) cpl_frame_get_tag(frame);
+<a name="l02209"></a>02209             <span class="keywordflow">if</span>(sinfo_tag_is_objpro(tag) == 1) {
+<a name="l02210"></a>02210                frame_dup=cpl_frame_duplicate(frame);
+<a name="l02211"></a>02211                cpl_frameset_insert(obj,frame_dup);
+<a name="l02212"></a>02212             }
+<a name="l02213"></a>02213          }
+<a name="l02214"></a>02214       }
+<a name="l02215"></a>02215    }
+<a name="l02216"></a>02216 
+<a name="l02217"></a>02217    <span class="keywordflow">return</span> 0;
+<a name="l02218"></a>02218 }
+<a name="l02219"></a>02219 
+<a name="l02220"></a>02220 <span class="keywordtype">int</span> sinfo_extract_on_frames(cpl_frameset * sof, cpl_frameset* on)
+<a name="l02221"></a>02221 {
+<a name="l02222"></a>02222    cpl_frame* frame   = NULL;
+<a name="l02223"></a>02223    cpl_frame* frame_dup   = NULL;
+<a name="l02224"></a>02224 
+<a name="l02225"></a>02225    <span class="keywordtype">int</span> nsof=0;
+<a name="l02226"></a>02226    <span class="keywordtype">int</span> i=0;
+<a name="l02227"></a>02227    nsof = cpl_frameset_get_size(sof);
+<a name="l02228"></a>02228    <span class="keywordflow">for</span> (i=0 ; i<nsof ; i++) {
+<a name="l02229"></a>02229       frame = cpl_frameset_get_frame(sof,i);
+<a name="l02230"></a>02230       <span class="keywordflow">if</span>(sinfo_frame_is_on(frame) ==1) {
+<a name="l02231"></a>02231          frame_dup=cpl_frame_duplicate(frame);
+<a name="l02232"></a>02232          cpl_frameset_insert(on,frame_dup);
+<a name="l02233"></a>02233       }
+<a name="l02234"></a>02234    }
+<a name="l02235"></a>02235 
+<a name="l02236"></a>02236    <span class="keywordflow">return</span> 0;
+<a name="l02237"></a>02237 }
+<a name="l02238"></a>02238 
+<a name="l02239"></a>02239 <span class="keywordtype">int</span> sinfo_extract_sky_frames(cpl_frameset * sof, cpl_frameset* sky)
+<a name="l02240"></a>02240 {
+<a name="l02241"></a>02241    <span class="keywordtype">char</span>* tag=NULL;
+<a name="l02242"></a>02242    <span class="keywordtype">char</span>* name=NULL;
+<a name="l02243"></a>02243    cpl_frame* frame   = NULL;
+<a name="l02244"></a>02244    cpl_frame* frame_dup   = NULL;
+<a name="l02245"></a>02245    <span class="keywordtype">int</span> nsof=0;
+<a name="l02246"></a>02246    <span class="keywordtype">int</span> i=0;
+<a name="l02247"></a>02247    nsof = cpl_frameset_get_size(sof);
+<a name="l02248"></a>02248    <span class="keywordflow">for</span> (i=0 ; i<nsof ; i++) {
+<a name="l02249"></a>02249       frame = cpl_frameset_get_frame(sof,i);
+<a name="l02250"></a>02250       name= (<span class="keywordtype">char</span>*) cpl_frame_get_filename(frame);
+<a name="l02251"></a>02251       <span class="keywordflow">if</span>(sinfo_is_fits_file(name) ==1) {
+<a name="l02252"></a>02252          <span class="comment">/* to go on the file must exist */</span>
+<a name="l02253"></a>02253          <span class="keywordflow">if</span>(cpl_frame_get_tag(frame) != NULL) {
+<a name="l02254"></a>02254             <span class="comment">/* If the frame has a tag we process it. Else it is an object */</span>
+<a name="l02255"></a>02255             tag= (<span class="keywordtype">char</span>*) cpl_frame_get_tag(frame);
+<a name="l02256"></a>02256             <span class="keywordflow">if</span>(sinfo_tag_is_sky(tag) == 1) {
+<a name="l02257"></a>02257                frame_dup=cpl_frame_duplicate(frame);
+<a name="l02258"></a>02258                cpl_frameset_insert(sky,frame_dup);
+<a name="l02259"></a>02259             }
+<a name="l02260"></a>02260          }
+<a name="l02261"></a>02261       }
+<a name="l02262"></a>02262    }
+<a name="l02263"></a>02263 
+<a name="l02264"></a>02264    <span class="keywordflow">return</span> 0;
+<a name="l02265"></a>02265 }
+<a name="l02266"></a>02266 
+<a name="l02267"></a>02267 
+<a name="l02268"></a>02268 
+<a name="l02269"></a>02269 <span class="keywordtype">int</span> sinfo_extract_off_frames(cpl_frameset * sof, cpl_frameset* off)
+<a name="l02270"></a>02270 {
+<a name="l02271"></a>02271    cpl_frame* frame   = NULL;
+<a name="l02272"></a>02272    cpl_frame* frame_dup   = NULL;
+<a name="l02273"></a>02273    <span class="keywordtype">int</span> nsof=0;
+<a name="l02274"></a>02274    <span class="keywordtype">int</span> i=0;
+<a name="l02275"></a>02275    nsof = cpl_frameset_get_size(sof);
+<a name="l02276"></a>02276    <span class="keywordflow">for</span> (i=0 ; i<nsof ; i++) {
+<a name="l02277"></a>02277       frame = cpl_frameset_get_frame(sof,i);
+<a name="l02278"></a>02278       <span class="keywordflow">if</span>(sinfo_frame_is_on(frame)) {
+<a name="l02279"></a>02279          frame_dup=cpl_frame_duplicate(frame);
+<a name="l02280"></a>02280          cpl_frameset_insert(off,frame_dup);
+<a name="l02281"></a>02281       }
+<a name="l02282"></a>02282    }
+<a name="l02283"></a>02283 
+<a name="l02284"></a>02284    <span class="keywordflow">return</span> 0;
+<a name="l02285"></a>02285 }
+<a name="l02286"></a>02286 
+<a name="l02287"></a>02287 <span class="keywordtype">int</span> sinfo_extract_mst_frames(cpl_frameset * sof, cpl_frameset* cdb)
+<a name="l02288"></a>02288 {
+<a name="l02289"></a>02289    <span class="keywordtype">char</span>* tag=NULL;
+<a name="l02290"></a>02290    <span class="keywordtype">char</span>* name=NULL;
+<a name="l02291"></a>02291    cpl_frame* frame   = NULL;
+<a name="l02292"></a>02292    cpl_frame* frame_dup   = NULL;
+<a name="l02293"></a>02293    <span class="keywordtype">int</span> nsof=0;
+<a name="l02294"></a>02294    <span class="keywordtype">int</span> i=0;
+<a name="l02295"></a>02295 
+<a name="l02296"></a>02296    nsof = cpl_frameset_get_size(sof);
+<a name="l02297"></a>02297    <span class="keywordflow">for</span> (i=0 ; i<nsof ; i++) {
+<a name="l02298"></a>02298       frame = cpl_frameset_get_frame(sof,i);
+<a name="l02299"></a>02299       name= (<span class="keywordtype">char</span>*) cpl_frame_get_filename(frame);
+<a name="l02300"></a>02300       <span class="keywordflow">if</span>(sinfo_is_fits_file(name) ==1) {
+<a name="l02301"></a>02301          <span class="comment">/* to go on the file must exist */</span>
+<a name="l02302"></a>02302          <span class="keywordflow">if</span>(cpl_frame_get_tag(frame) != NULL) {
+<a name="l02303"></a>02303             <span class="comment">/* If the frame has a tag we process it. Else it is an object */</span>
+<a name="l02304"></a>02304             tag= (<span class="keywordtype">char</span>*) cpl_frame_get_tag(frame);
+<a name="l02305"></a>02305             <span class="keywordflow">if</span>(sinfo_frame_is_cdb(tag) == 1) {
+<a name="l02306"></a>02306                frame_dup=cpl_frame_duplicate(frame);
+<a name="l02307"></a>02307                cpl_frameset_insert(cdb,frame_dup);
+<a name="l02308"></a>02308             }
+<a name="l02309"></a>02309          }
+<a name="l02310"></a>02310       }
+<a name="l02311"></a>02311    }
+<a name="l02312"></a>02312 
+<a name="l02313"></a>02313    <span class="keywordflow">return</span> 0;
+<a name="l02314"></a>02314 }
+<a name="l02315"></a>02315 
+<a name="l02316"></a>02316 cpl_frameset* sinfo_frameset_join(cpl_frameset* fs1,cpl_frameset* fs2) {
+<a name="l02317"></a>02317 
+<a name="l02318"></a>02318    cpl_frameset* join=NULL;
+<a name="l02319"></a>02319    cpl_frame* frm=NULL;
+<a name="l02320"></a>02320    cpl_frame* frm_dup=NULL;
+<a name="l02321"></a>02321    <span class="keywordtype">int</span> i=0;
+<a name="l02322"></a>02322    <span class="keywordtype">int</span> n=0;
+<a name="l02323"></a>02323 
+<a name="l02324"></a>02324    join=cpl_frameset_new();
+<a name="l02325"></a>02325 
+<a name="l02326"></a>02326    n=cpl_frameset_get_size(fs1);
+<a name="l02327"></a>02327    <span class="keywordflow">for</span>(i=0;i<n; i++) {
+<a name="l02328"></a>02328       frm=cpl_frameset_get_frame(fs1,i);
+<a name="l02329"></a>02329       frm_dup= cpl_frame_duplicate(frm);
+<a name="l02330"></a>02330       cpl_frameset_insert(join,frm_dup);
+<a name="l02331"></a>02331    }
+<a name="l02332"></a>02332 
+<a name="l02333"></a>02333    n=cpl_frameset_get_size(fs2);
+<a name="l02334"></a>02334    <span class="keywordflow">for</span>(i=0;i<n; i++) {
+<a name="l02335"></a>02335       frm=cpl_frameset_get_frame(fs2,i);
+<a name="l02336"></a>02336       frm_dup= cpl_frame_duplicate(frm);
+<a name="l02337"></a>02337       cpl_frameset_insert(join,frm_dup);
+<a name="l02338"></a>02338    }
+<a name="l02339"></a>02339 
+<a name="l02340"></a>02340 
+<a name="l02341"></a>02341    <span class="keywordflow">return</span> join;
+<a name="l02342"></a>02342 
+<a name="l02343"></a>02343 }
+<a name="l02344"></a>02344 
+<a name="l02345"></a>02345 
+<a name="l02346"></a>02346 <span class="keywordtype">int</span> sinfo_extract_stk_frames(cpl_frameset * sof,
+<a name="l02347"></a>02347                              cpl_frameset* res)
+<a name="l02348"></a>02348 {
+<a name="l02349"></a>02349    <span class="keywordtype">char</span>* tag=NULL;
+<a name="l02350"></a>02350    <span class="keywordtype">char</span>* name=NULL;
+<a name="l02351"></a>02351    cpl_frame* frame   = NULL;
+<a name="l02352"></a>02352    cpl_frame* frame_dup   = NULL;
+<a name="l02353"></a>02353    <span class="keywordtype">int</span> nsof=0;
+<a name="l02354"></a>02354    <span class="keywordtype">int</span> i=0;
+<a name="l02355"></a>02355 
+<a name="l02356"></a>02356    nsof = cpl_frameset_get_size(sof);
+<a name="l02357"></a>02357    <span class="keywordflow">for</span> (i=0 ; i<nsof ; i++) {
+<a name="l02358"></a>02358       frame = cpl_frameset_get_frame(sof,i);
+<a name="l02359"></a>02359       name= (<span class="keywordtype">char</span>*) cpl_frame_get_filename(frame);
+<a name="l02360"></a>02360       <span class="keywordflow">if</span>(sinfo_is_fits_file(name) ==1) {
+<a name="l02361"></a>02361          <span class="comment">/* to go on the file must exist */</span>
+<a name="l02362"></a>02362          <span class="keywordflow">if</span>(cpl_frame_get_tag(frame) != NULL) {
+<a name="l02363"></a>02363             <span class="comment">/* If the frame has a tag we process it. Else it is an object */</span>
+<a name="l02364"></a>02364             tag= (<span class="keywordtype">char</span>*) cpl_frame_get_tag(frame);
+<a name="l02365"></a>02365             <span class="keywordflow">if</span>(sinfo_frame_is_stk(tag) == 1) {
+<a name="l02366"></a>02366                frame_dup=cpl_frame_duplicate(frame);
+<a name="l02367"></a>02367                cpl_frameset_insert(res,frame_dup);
+<a name="l02368"></a>02368             }
+<a name="l02369"></a>02369          }
+<a name="l02370"></a>02370       }
+<a name="l02371"></a>02371    }
+<a name="l02372"></a>02372 
+<a name="l02373"></a>02373    <span class="keywordflow">return</span> 0;
+<a name="l02374"></a>02374 }
+<a name="l02375"></a>02375 
+<a name="l02376"></a>02376 
+<a name="l02377"></a>02377 <span class="keywordtype">int</span>
+<a name="l02378"></a>02378 sinfo_extract_preoptic_frames(cpl_frameset * sof,
+<a name="l02379"></a>02379                               cpl_frameset** res,
+<a name="l02380"></a>02380                               <span class="keyword">const</span> <span class="keywordtype">char</span>* val)
+<a name="l02381"></a>02381 {
+<a name="l02382"></a>02382    <span class="keywordtype">char</span>* name=NULL;
+<a name="l02383"></a>02383    cpl_frame* frame   = NULL;
+<a name="l02384"></a>02384    cpl_frame* frame_dup   = NULL;
+<a name="l02385"></a>02385    <span class="keywordtype">int</span> nsof=0;
+<a name="l02386"></a>02386    <span class="keywordtype">int</span> i=0;
+<a name="l02387"></a>02387 
+<a name="l02388"></a>02388    nsof = cpl_frameset_get_size(sof);
+<a name="l02389"></a>02389    <span class="keywordflow">for</span> (i=0 ; i<nsof ; i++) {
+<a name="l02390"></a>02390       frame = cpl_frameset_get_frame(sof,i);
+<a name="l02391"></a>02391       name= (<span class="keywordtype">char</span>*) cpl_frame_get_filename(frame);
+<a name="l02392"></a>02392       <span class="keywordflow">if</span>(sinfo_is_fits_file(name) ==1) {
+<a name="l02393"></a>02393          <span class="keywordflow">if</span>(sinfo_frame_is_preoptic(frame,val) == 1) {
+<a name="l02394"></a>02394             frame_dup=cpl_frame_duplicate(frame);
+<a name="l02395"></a>02395             cpl_frameset_insert(*res,frame_dup);
+<a name="l02396"></a>02396          }
+<a name="l02397"></a>02397       }
+<a name="l02398"></a>02398    }
+<a name="l02399"></a>02399 
+<a name="l02400"></a>02400    <span class="keywordflow">return</span> 0;
+<a name="l02401"></a>02401 }
+<a name="l02402"></a>02402 
+<a name="l02403"></a>02403 <span class="keywordtype">int</span> sinfo_extract_raw_stack_frames(cpl_frameset * sof, cpl_frameset** pro)
+<a name="l02404"></a>02404 {
+<a name="l02405"></a>02405    <span class="keywordtype">char</span>* tag=NULL;
+<a name="l02406"></a>02406    <span class="keywordtype">char</span>* name=NULL;
+<a name="l02407"></a>02407    cpl_frame* frame   = NULL;
+<a name="l02408"></a>02408    cpl_frame* frame_dup   = NULL;
+<a name="l02409"></a>02409 
+<a name="l02410"></a>02410    <span class="keywordtype">int</span> nsof=0;
+<a name="l02411"></a>02411    <span class="keywordtype">int</span> i=0;
+<a name="l02412"></a>02412    nsof = cpl_frameset_get_size(sof);
+<a name="l02413"></a>02413 
+<a name="l02414"></a>02414    <span class="keywordflow">for</span> (i=0 ; i<nsof ; i++) {
+<a name="l02415"></a>02415       frame = cpl_frameset_get_frame(sof,i);
+<a name="l02416"></a>02416       name= (<span class="keywordtype">char</span>*) cpl_frame_get_filename(frame);
+<a name="l02417"></a>02417       <span class="keywordflow">if</span>(sinfo_is_fits_file(name) ==1) {
+<a name="l02418"></a>02418          <span class="comment">/* to go on the file must exist */</span>
+<a name="l02419"></a>02419          <span class="keywordflow">if</span>(cpl_frame_get_tag(frame) != NULL) {
+<a name="l02420"></a>02420             <span class="comment">/* If the frame has a tag we process it. Else it is an object */</span>
+<a name="l02421"></a>02421             tag= (<span class="keywordtype">char</span>*) cpl_frame_get_tag(frame);
+<a name="l02422"></a>02422             <span class="comment">/* sinfo_msg("tag=%s\n",tag); */</span>
+<a name="l02423"></a>02423             <span class="keywordflow">if</span>(sinfo_frame_is_raw_stack(tag) == 1) {
+<a name="l02424"></a>02424                frame_dup   = cpl_frame_duplicate(frame);
+<a name="l02425"></a>02425                cpl_frameset_insert(*pro,frame_dup);
+<a name="l02426"></a>02426             }
+<a name="l02427"></a>02427          }
+<a name="l02428"></a>02428       }
+<a name="l02429"></a>02429    }
+<a name="l02430"></a>02430 
+<a name="l02431"></a>02431    <span class="keywordflow">return</span> 0;
+<a name="l02432"></a>02432 }
+<a name="l02433"></a>02433 
+<a name="l02434"></a>02434 
+<a name="l02435"></a>02435 <span class="keywordtype">int</span> sinfo_extract_raw_slit_frames(cpl_frameset * sof, cpl_frameset** pro)
+<a name="l02436"></a>02436 {
+<a name="l02437"></a>02437    <span class="keywordtype">char</span>* tag=NULL;
+<a name="l02438"></a>02438    <span class="keywordtype">char</span>* name=NULL;
+<a name="l02439"></a>02439    cpl_frame* frame   = NULL;
+<a name="l02440"></a>02440    <span class="keywordtype">int</span> nsof=0;
+<a name="l02441"></a>02441    <span class="keywordtype">int</span> i=0;
+<a name="l02442"></a>02442    nsof = cpl_frameset_get_size(sof);
+<a name="l02443"></a>02443    <span class="keywordflow">for</span> (i=0 ; i<nsof ; i++) {
+<a name="l02444"></a>02444       frame = cpl_frameset_get_frame(sof,i);
+<a name="l02445"></a>02445       name= (<span class="keywordtype">char</span>*) cpl_frame_get_filename(frame);
+<a name="l02446"></a>02446       <span class="keywordflow">if</span>(sinfo_is_fits_file(name) ==1) {
+<a name="l02447"></a>02447          <span class="comment">/* to go on the file must exist */</span>
+<a name="l02448"></a>02448          <span class="keywordflow">if</span>(cpl_frame_get_tag(frame) != NULL) {
+<a name="l02449"></a>02449             <span class="comment">/* If the frame has a tag we process it. Else it is an object */</span>
+<a name="l02450"></a>02450             tag= (<span class="keywordtype">char</span>*) cpl_frame_get_tag(frame);
+<a name="l02451"></a>02451             <span class="keywordflow">if</span>(sinfo_frame_is_slit_lamp(tag) == 1) {
+<a name="l02452"></a>02452                cpl_frameset_insert(*pro,frame);
+<a name="l02453"></a>02453             }
+<a name="l02454"></a>02454          }
+<a name="l02455"></a>02455       }
+<a name="l02456"></a>02456    }
+<a name="l02457"></a>02457 
+<a name="l02458"></a>02458    <span class="keywordflow">return</span> 0;
+<a name="l02459"></a>02459 }
+<a name="l02460"></a>02460 
+<a name="l02461"></a>02461 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l02467"></a>02467 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l02468"></a>02468 <span class="keywordtype">int</span> sinfo_frame_is_raw(<span class="keywordtype">char</span> * tag)
+<a name="l02469"></a>02469 {
+<a name="l02470"></a>02470    <span class="comment">/* Test entries */</span>
+<a name="l02471"></a>02471    <span class="keywordflow">if</span> (tag == NULL) <span class="keywordflow">return</span> -1 ;
+<a name="l02472"></a>02472 
+<a name="l02473"></a>02473    <span class="keywordflow">if</span> (!strcmp(tag, RAW_LINEARITY_LAMP)) <span class="keywordflow">return</span> 1 ;
+<a name="l02474"></a>02474    <span class="keywordflow">if</span> (!strcmp(tag, RAW_DARK)) <span class="keywordflow">return</span> 1 ;
+<a name="l02475"></a>02475    <span class="keywordflow">if</span> (!strcmp(tag, RAW_PINHOLE_LAMP)) <span class="keywordflow">return</span> 1 ;
+<a name="l02476"></a>02476    <span class="keywordflow">if</span> (!strcmp(tag, RAW_SLIT_LAMP)) <span class="keywordflow">return</span> 1 ;
+<a name="l02477"></a>02477    <span class="keywordflow">if</span> (!strcmp(tag, RAW_WAVE_LAMP)) <span class="keywordflow">return</span> 1 ;
+<a name="l02478"></a>02478    <span class="keywordflow">if</span> (!strcmp(tag, RAW_FLAT_LAMP)) <span class="keywordflow">return</span> 1 ;
+<a name="l02479"></a>02479    <span class="keywordflow">if</span> (!strcmp(tag, RAW_WAVE_NS)) <span class="keywordflow">return</span> 1 ;
+<a name="l02480"></a>02480    <span class="keywordflow">if</span> (!strcmp(tag, RAW_FLAT_NS)) <span class="keywordflow">return</span> 1 ;
+<a name="l02481"></a>02481    <span class="keywordflow">if</span> (!strcmp(tag, RAW_FIBRE_LAMP)) <span class="keywordflow">return</span> 1 ;
+<a name="l02482"></a>02482    <span class="keywordflow">if</span> (!strcmp(tag, RAW_FIBRE_EW)) <span class="keywordflow">return</span> 1 ;
+<a name="l02483"></a>02483    <span class="keywordflow">if</span> (!strcmp(tag, RAW_FIBRE_NS)) <span class="keywordflow">return</span> 1 ;
+<a name="l02484"></a>02484    <span class="keywordflow">if</span> (!strcmp(tag, RAW_FLAT_SKY)) <span class="keywordflow">return</span> 1 ;
+<a name="l02485"></a>02485    <span class="keywordflow">if</span> (!strcmp(tag, RAW_FLUX_LAMP)) <span class="keywordflow">return</span> 1 ;
+<a name="l02486"></a>02486    <span class="keywordflow">if</span> (!strcmp(tag, RAW_PSF_CALIBRATOR)) <span class="keywordflow">return</span> 1 ;
+<a name="l02487"></a>02487    <span class="keywordflow">if</span> (!strcmp(tag, RAW_FOCUS)) <span class="keywordflow">return</span> 1 ;
+<a name="l02488"></a>02488 
+<a name="l02489"></a>02489    <span class="keywordflow">if</span> (!strcmp(tag, RAW_STD)) <span class="keywordflow">return</span> 1 ;
+<a name="l02490"></a>02490    <span class="keywordflow">if</span> (!strcmp(tag, RAW_STD_STAR)) <span class="keywordflow">return</span> 1 ;
+<a name="l02491"></a>02491    <span class="keywordflow">if</span> (!strcmp(tag, RAW_STD_STAR_DITHER)) <span class="keywordflow">return</span> 1 ;
+<a name="l02492"></a>02492    <span class="keywordflow">if</span> (!strcmp(tag, RAW_SKY_STD)) <span class="keywordflow">return</span> 1 ;
+<a name="l02493"></a>02493    <span class="keywordflow">if</span> (!strcmp(tag, RAW_SKY_OH)) <span class="keywordflow">return</span> 1 ;
+<a name="l02494"></a>02494    <span class="keywordflow">if</span> (!strcmp(tag, RAW_SKY_PSF_CALIBRATOR)) <span class="keywordflow">return</span> 1 ;
+<a name="l02495"></a>02495 
+<a name="l02496"></a>02496    <span class="keywordflow">if</span> (!strcmp(tag, RAW_PUPIL_LAMP)) <span class="keywordflow">return</span> 1 ;
+<a name="l02497"></a>02497    <span class="keywordflow">if</span> (!strcmp(tag, RAW_OBJECT_JITTER)) <span class="keywordflow">return</span> 1 ;
+<a name="l02498"></a>02498    <span class="keywordflow">if</span> (!strcmp(tag, RAW_SKY_JITTER)) <span class="keywordflow">return</span> 1 ;
+<a name="l02499"></a>02499    <span class="keywordflow">if</span> (!strcmp(tag, RAW_OBJECT_NODDING)) <span class="keywordflow">return</span> 1 ;
+<a name="l02500"></a>02500    <span class="keywordflow">if</span> (!strcmp(tag, RAW_OBJECT_SKYSPIDER)) <span class="keywordflow">return</span> 1 ;
+<a name="l02501"></a>02501    <span class="keywordflow">if</span> (!strcmp(tag, RAW_SKY_NODDING)) <span class="keywordflow">return</span> 1 ;
+<a name="l02502"></a>02502 
+<a name="l02503"></a>02503    <span class="keywordflow">if</span> (!strcmp(tag, RAW_FLAT_LAMP_DITHER)) <span class="keywordflow">return</span> 1 ;
+<a name="l02504"></a>02504    <span class="keywordflow">if</span> (!strcmp(tag, RAW_WAVE_LAMP_DITHER)) <span class="keywordflow">return</span> 1 ;
+<a name="l02505"></a>02505    <span class="keywordflow">if</span> (!strcmp(tag, RAW_STD_STAR_DITHER)) <span class="keywordflow">return</span> 1 ;
+<a name="l02506"></a>02506    <span class="keywordflow">if</span> (!strcmp(tag, RAW_OBJECT_NODDING_DITHER)) <span class="keywordflow">return</span> 1 ;
+<a name="l02507"></a>02507    <span class="keywordflow">if</span> (!strcmp(tag, RAW_OBJECT_SKYSPIDER_DITHER)) <span class="keywordflow">return</span> 1 ;
+<a name="l02508"></a>02508    <span class="keywordflow">if</span> (!strcmp(tag, RAW_SKY_NODDING_DITHER)) <span class="keywordflow">return</span> 1 ;
+<a name="l02509"></a>02509 
+<a name="l02510"></a>02510 
+<a name="l02511"></a>02511    <span class="keywordflow">return</span> 0 ;
+<a name="l02512"></a>02512 }
+<a name="l02513"></a>02513 
+<a name="l02514"></a>02514 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l02520"></a>02520 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l02521"></a>02521 <span class="keywordtype">int</span> sinfo_frame_is_raw_stack(<span class="keywordtype">char</span> * tag)
+<a name="l02522"></a>02522 {
+<a name="l02523"></a>02523    <span class="comment">/* Test entries */</span>
+<a name="l02524"></a>02524    <span class="keywordflow">if</span> (tag == NULL) <span class="keywordflow">return</span> -1 ;
+<a name="l02525"></a>02525 
+<a name="l02526"></a>02526 
+<a name="l02527"></a>02527    <span class="keywordflow">if</span> (!strcmp(tag, PRO_SKY_DUMMY)) <span class="keywordflow">return</span> 1 ;
+<a name="l02528"></a>02528    <span class="keywordflow">if</span> (!strcmp(tag, RAW_WAVE_LAMP)) <span class="keywordflow">return</span> 1 ;
+<a name="l02529"></a>02529    <span class="keywordflow">if</span> (!strcmp(tag, RAW_WAVE_LAMP_DITHER)) <span class="keywordflow">return</span> 1 ;
+<a name="l02530"></a>02530    <span class="keywordflow">if</span> (!strcmp(tag, RAW_WAVE_NS)) <span class="keywordflow">return</span> 1 ;
+<a name="l02531"></a>02531    <span class="keywordflow">if</span> (!strcmp(tag, RAW_WAVE_NS_DITHER)) <span class="keywordflow">return</span> 1 ;
+<a name="l02532"></a>02532 
+<a name="l02533"></a>02533    <span class="keywordflow">if</span> (!strcmp(tag, RAW_FLUX_LAMP)) <span class="keywordflow">return</span> 1 ;
+<a name="l02534"></a>02534    <span class="keywordflow">if</span> (!strcmp(tag, RAW_FIBRE_NS)) <span class="keywordflow">return</span> 1 ;
+<a name="l02535"></a>02535    <span class="keywordflow">if</span> (!strcmp(tag, RAW_FIBRE_EW)) <span class="keywordflow">return</span> 1 ;
+<a name="l02536"></a>02536 
+<a name="l02537"></a>02537    <span class="keywordflow">if</span> (!strcmp(tag, RAW_PSF_CALIBRATOR)) <span class="keywordflow">return</span> 1 ;
+<a name="l02538"></a>02538    <span class="keywordflow">if</span> (!strcmp(tag, RAW_FIBRE_PSF)) <span class="keywordflow">return</span> 1 ;
+<a name="l02539"></a>02539    <span class="keywordflow">if</span> (!strcmp(tag, RAW_FIBRE_DARK)) <span class="keywordflow">return</span> 1 ;
+<a name="l02540"></a>02540 
+<a name="l02541"></a>02541    <span class="keywordflow">if</span> (!strcmp(tag, RAW_FOCUS)) <span class="keywordflow">return</span> 1 ;
+<a name="l02542"></a>02542 
+<a name="l02543"></a>02543    <span class="keywordflow">if</span> (!strcmp(tag, RAW_PUPIL_LAMP)) <span class="keywordflow">return</span> 1 ;
+<a name="l02544"></a>02544    <span class="keywordflow">if</span> (!strcmp(tag, RAW_OBJECT_JITTER)) <span class="keywordflow">return</span> 1 ;
+<a name="l02545"></a>02545    <span class="keywordflow">if</span> (!strcmp(tag, RAW_SKY_JITTER)) <span class="keywordflow">return</span> 1 ;
+<a name="l02546"></a>02546    <span class="keywordflow">if</span> (!strcmp(tag, RAW_OBJECT_NODDING)) <span class="keywordflow">return</span> 1 ;
+<a name="l02547"></a>02547    <span class="keywordflow">if</span> (!strcmp(tag, RAW_OBJECT_SKYSPIDER)) <span class="keywordflow">return</span> 1 ;
+<a name="l02548"></a>02548    <span class="keywordflow">if</span> (!strcmp(tag, RAW_SKY_NODDING)) <span class="keywordflow">return</span> 1 ;
+<a name="l02549"></a>02549 
+<a name="l02550"></a>02550    <span class="keywordflow">if</span> (!strcmp(tag, RAW_OBJECT_NODDING_DITHER)) <span class="keywordflow">return</span> 1 ;
+<a name="l02551"></a>02551    <span class="keywordflow">if</span> (!strcmp(tag, RAW_OBJECT_SKYSPIDER_DITHER)) <span class="keywordflow">return</span> 1 ;
+<a name="l02552"></a>02552    <span class="keywordflow">if</span> (!strcmp(tag, RAW_SKY_NODDING_DITHER)) <span class="keywordflow">return</span> 1 ;
+<a name="l02553"></a>02553 
+<a name="l02554"></a>02554 
+<a name="l02555"></a>02555    <span class="keywordflow">if</span> (!strcmp(tag, RAW_IMAGE_PRE_OBJECT)) <span class="keywordflow">return</span> 1 ;
+<a name="l02556"></a>02556    <span class="keywordflow">if</span> (!strcmp(tag, RAW_IMAGE_PRE_SKY)) <span class="keywordflow">return</span> 1 ;
+<a name="l02557"></a>02557    <span class="keywordflow">if</span> (!strcmp(tag, RAW_STD)) <span class="keywordflow">return</span> 1 ;
+<a name="l02558"></a>02558    <span class="keywordflow">if</span> (!strcmp(tag, RAW_SKY_STD)) <span class="keywordflow">return</span> 1 ;
+<a name="l02559"></a>02559    <span class="keywordflow">if</span> (!strcmp(tag, RAW_SKY_OH)) <span class="keywordflow">return</span> 1 ;
+<a name="l02560"></a>02560    <span class="keywordflow">if</span> (!strcmp(tag, RAW_SKY_PSF_CALIBRATOR)) <span class="keywordflow">return</span> 1 ;
+<a name="l02561"></a>02561    <span class="keywordflow">if</span> (!strcmp(tag, RAW_STD_STAR)) <span class="keywordflow">return</span> 1 ;
+<a name="l02562"></a>02562    <span class="keywordflow">if</span> (!strcmp(tag, RAW_SKY)) <span class="keywordflow">return</span> 1 ;
+<a name="l02563"></a>02563 
+<a name="l02564"></a>02564    <span class="keywordflow">return</span> 0 ;
+<a name="l02565"></a>02565 }
+<a name="l02566"></a>02566 
+<a name="l02567"></a>02567 
+<a name="l02568"></a>02568 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l02574"></a>02574 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l02575"></a>02575 <span class="keywordtype">int</span> sinfo_frame_is_raw_dark(<span class="keywordtype">char</span> * tag)
+<a name="l02576"></a>02576 {
+<a name="l02577"></a>02577    <span class="comment">/* Test entries */</span>
+<a name="l02578"></a>02578    <span class="keywordflow">if</span> (tag == NULL) <span class="keywordflow">return</span> -1 ;
+<a name="l02579"></a>02579 
+<a name="l02580"></a>02580    <span class="keywordflow">if</span> (!strcmp(tag, RAW_DARK)) <span class="keywordflow">return</span> 1 ;
+<a name="l02581"></a>02581 
+<a name="l02582"></a>02582    <span class="keywordflow">return</span> 0 ;
+<a name="l02583"></a>02583 }
+<a name="l02584"></a>02584 
+<a name="l02585"></a>02585 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l02591"></a>02591 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l02592"></a>02592 <span class="keywordtype">int</span> sinfo_frame_is_slit_lamp(<span class="keywordtype">char</span> * tag)
+<a name="l02593"></a>02593 {
+<a name="l02594"></a>02594    <span class="comment">/* Test entries */</span>
+<a name="l02595"></a>02595    <span class="keywordflow">if</span> (tag == NULL) <span class="keywordflow">return</span> -1 ;
+<a name="l02596"></a>02596 
+<a name="l02597"></a>02597    <span class="keywordflow">if</span> (!strcmp(tag, RAW_SLIT_LAMP)) <span class="keywordflow">return</span> 1 ;
+<a name="l02598"></a>02598 
+<a name="l02599"></a>02599    <span class="keywordflow">return</span> 0 ;
+<a name="l02600"></a>02600 }
+<a name="l02601"></a>02601 
+<a name="l02602"></a>02602 
+<a name="l02603"></a>02603 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l02609"></a>02609 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l02610"></a>02610 <span class="keywordtype">int</span> sinfo_frame_is_pinhole_lamp(<span class="keywordtype">char</span> * tag)
+<a name="l02611"></a>02611 {
+<a name="l02612"></a>02612    <span class="comment">/* Test entries */</span>
+<a name="l02613"></a>02613    <span class="keywordflow">if</span> (tag == NULL) <span class="keywordflow">return</span> -1 ;
+<a name="l02614"></a>02614 
+<a name="l02615"></a>02615    <span class="keywordflow">if</span> (!strcmp(tag, RAW_PINHOLE_LAMP)) <span class="keywordflow">return</span> 1 ;
+<a name="l02616"></a>02616 
+<a name="l02617"></a>02617    <span class="keywordflow">return</span> 0 ;
+<a name="l02618"></a>02618 }
+<a name="l02619"></a>02619 
+<a name="l02620"></a>02620 
+<a name="l02621"></a>02621 <span class="keywordtype">int</span> sinfo_frame_is_cdb(<span class="keywordtype">char</span> * tag)
+<a name="l02622"></a>02622 {
+<a name="l02623"></a>02623    <span class="comment">/* Test entries */</span>
+<a name="l02624"></a>02624    <span class="keywordflow">if</span> (tag == NULL) <span class="keywordflow">return</span> -1 ;
+<a name="l02625"></a>02625    <span class="comment">/* For the moment not checked the following:</span>
+<a name="l02626"></a>02626 <span class="comment"></span>
+<a name="l02627"></a>02627 <span class="comment">   PRO_STACKED</span>
+<a name="l02628"></a>02628 <span class="comment">   PRO_SLIT_ON</span>
+<a name="l02629"></a>02629 <span class="comment">   PRO_FLUX_LAMP_STACKED</span>
+<a name="l02630"></a>02630 <span class="comment">   PRO_WAVE_LAMP_STACKED</span>
+<a name="l02631"></a>02631 <span class="comment">   PRO_PSF_CALIBRATOR_STACKED</span>
+<a name="l02632"></a>02632 <span class="comment">   PRO_FOCUS_STACKED</span>
+<a name="l02633"></a>02633 <span class="comment">   PRO_OBJECT_NODDING_STACKED</span>
+<a name="l02634"></a>02634 <span class="comment">   PRO_OBJECT_SKYSPIDER_STACKED</span>
+<a name="l02635"></a>02635 <span class="comment">   PRO_SKY_NODDING_STACKED</span>
+<a name="l02636"></a>02636 <span class="comment">   PRO_STD_NODDING_STACKED</span>
+<a name="l02637"></a>02637 <span class="comment">   PRO_MASK_CUBE</span>
+<a name="l02638"></a>02638 <span class="comment">   PRO_PSF</span>
+<a name="l02639"></a>02639 <span class="comment">   TMP_FOCUS</span>
+<a name="l02640"></a>02640 <span class="comment">   TMP_FOCUS_ON</span>
+<a name="l02641"></a>02641 <span class="comment">   TMP_FOCUS_OFF</span>
+<a name="l02642"></a>02642 <span class="comment">   PRO_FOCUS</span>
+<a name="l02643"></a>02643 <span class="comment">   PRO_FOCUS_GAUSS</span>
+<a name="l02644"></a>02644 <span class="comment">   PRO_SPECTRA</span>
+<a name="l02645"></a>02645 <span class="comment">   PRO_CUBE</span>
+<a name="l02646"></a>02646 <span class="comment">   PRO_CUBE_COLL</span>
+<a name="l02647"></a>02647 <span class="comment">   PRO_SLOPEX</span>
+<a name="l02648"></a>02648 <span class="comment">   PRO_SLOPEY</span>
+<a name="l02649"></a>02649 <span class="comment">   PRO_MASK_CUBE</span>
+<a name="l02650"></a>02650 <span class="comment">   PRO_OBJ_CUBE</span>
+<a name="l02651"></a>02651 <span class="comment">   PRO_BP_COEFF</span>
+<a name="l02652"></a>02652 <span class="comment">   */</span>
+<a name="l02653"></a>02653 
+<a name="l02654"></a>02654    <span class="keywordflow">if</span> (!strcmp(tag, REF_LINE_ARC)) <span class="keywordflow">return</span> 1 ;
+<a name="l02655"></a>02655    <span class="keywordflow">if</span> (!strcmp(tag, PRO_BP_MAP)) <span class="keywordflow">return</span> 1 ;
+<a name="l02656"></a>02656    <span class="keywordflow">if</span> (!strcmp(tag, PRO_BP_MAP_HP)) <span class="keywordflow">return</span> 1 ;
+<a name="l02657"></a>02657    <span class="keywordflow">if</span> (!strcmp(tag, PRO_BP_MAP_DI)) <span class="keywordflow">return</span> 1 ;
+<a name="l02658"></a>02658    <span class="keywordflow">if</span> (!strcmp(tag, PRO_BP_MAP_NO)) <span class="keywordflow">return</span> 1 ;
+<a name="l02659"></a>02659    <span class="keywordflow">if</span> (!strcmp(tag, PRO_BP_MAP_NL)) <span class="keywordflow">return</span> 1 ;
+<a name="l02660"></a>02660    <span class="keywordflow">if</span> (!strcmp(tag, PRO_MASTER_BP_MAP)) <span class="keywordflow">return</span> 1 ;
+<a name="l02661"></a>02661    <span class="keywordflow">if</span> (!strcmp(tag, PRO_MASTER_DARK)) <span class="keywordflow">return</span> 1 ;
+<a name="l02662"></a>02662    <span class="keywordflow">if</span> (!strcmp(tag, PRO_SLOPE)) <span class="keywordflow">return</span> 1 ;
+<a name="l02663"></a>02663    <span class="keywordflow">if</span> (!strcmp(tag, PRO_DISTORTION)) <span class="keywordflow">return</span> 1 ;
+<a name="l02664"></a>02664    <span class="keywordflow">if</span> (!strcmp(tag, PRO_SLITLETS_DISTANCE)) <span class="keywordflow">return</span> 1 ;
+<a name="l02665"></a>02665    <span class="keywordflow">if</span> (!strcmp(tag, PRO_MASTER_FLAT_LAMP)) <span class="keywordflow">return</span> 1 ;
+<a name="l02666"></a>02666    <span class="keywordflow">if</span> (!strcmp(tag, PRO_MASTER_FLAT_LAMP1)) <span class="keywordflow">return</span> 1 ;
+<a name="l02667"></a>02667    <span class="keywordflow">if</span> (!strcmp(tag, PRO_MASTER_FLAT_LAMP2)) <span class="keywordflow">return</span> 1 ;
+<a name="l02668"></a>02668    <span class="keywordflow">if</span> (!strcmp(tag, PRO_SLIT_POS)) <span class="keywordflow">return</span> 1 ;
+<a name="l02669"></a>02669    <span class="keywordflow">if</span> (!strcmp(tag, PRO_SLIT_POS_GUESS)) <span class="keywordflow">return</span> 1 ;
+<a name="l02670"></a>02670    <span class="keywordflow">if</span> (!strcmp(tag, PRO_WAVE_PAR_LIST)) <span class="keywordflow">return</span> 1 ;
+<a name="l02671"></a>02671    <span class="keywordflow">if</span> (!strcmp(tag, PRO_WAVE_COEF_SLIT)) <span class="keywordflow">return</span> 1 ;
+<a name="l02672"></a>02672    <span class="keywordflow">if</span> (!strcmp(tag, PRO_MASTER_LAMP_SPEC)) <span class="keywordflow">return</span> 1 ;
+<a name="l02673"></a>02673    <span class="keywordflow">if</span> (!strcmp(tag, PRO_MASTER_TWIFLAT)) <span class="keywordflow">return</span> 1 ;
+<a name="l02674"></a>02674    <span class="keywordflow">if</span> (!strcmp(tag, PRO_COEFF_LIST)) <span class="keywordflow">return</span> 1 ;
+<a name="l02675"></a>02675    <span class="keywordflow">if</span> (!strcmp(tag, PRO_INDEX_LIST)) <span class="keywordflow">return</span> 1 ;
+<a name="l02676"></a>02676    <span class="keywordflow">if</span> (!strcmp(tag, PRO_HALO_SPECT)) <span class="keywordflow">return</span> 1 ;
+<a name="l02677"></a>02677    <span class="keywordflow">if</span> (!strcmp(tag, PRO_FIRST_COL)) <span class="keywordflow">return</span> 1 ;
+<a name="l02678"></a>02678    <span class="keywordflow">if</span> (!strcmp(tag, PRO_FOCUS)) <span class="keywordflow">return</span> 1 ;
+<a name="l02679"></a>02679    <span class="keywordflow">if</span> (!strcmp(tag, PRO_WAVE_MAP)) <span class="keywordflow">return</span> 1 ;
+<a name="l02680"></a>02680    <span class="keywordflow">if</span> (!strcmp(tag, PRO_REF_ATM_REF_CORR)) <span class="keywordflow">return</span> 1 ;
+<a name="l02681"></a>02681 
+<a name="l02682"></a>02682    <span class="keywordflow">return</span> 0;
+<a name="l02683"></a>02683 
+<a name="l02684"></a>02684 }
+<a name="l02685"></a>02685 
+<a name="l02686"></a>02686 
+<a name="l02687"></a>02687 
+<a name="l02688"></a>02688 
+<a name="l02689"></a>02689 <span class="keywordtype">int</span> sinfo_frame_is_stk(<span class="keywordtype">char</span> * tag)
+<a name="l02690"></a>02690 {
+<a name="l02691"></a>02691    <span class="comment">/* Test entries */</span>
+<a name="l02692"></a>02692    <span class="keywordflow">if</span> (tag == NULL) <span class="keywordflow">return</span> -1 ;
+<a name="l02693"></a>02693    <span class="comment">/* For the moment not checked the following: */</span>
+<a name="l02694"></a>02694 
+<a name="l02695"></a>02695 
+<a name="l02696"></a>02696    <span class="keywordflow">if</span> (!strcmp(tag, PRO_SKY_STACKED_DUMMY)) <span class="keywordflow">return</span> 1 ;
+<a name="l02697"></a>02697    <span class="keywordflow">if</span> (!strcmp(tag, PRO_STACK_SKY_DIST)) <span class="keywordflow">return</span> 1 ;
+<a name="l02698"></a>02698    <span class="keywordflow">if</span> (!strcmp(tag, PRO_STACK_MFLAT_DIST)) <span class="keywordflow">return</span> 1 ;
+<a name="l02699"></a>02699    <span class="keywordflow">if</span> (!strcmp(tag, PRO_PSF_CALIBRATOR_STACKED)) <span class="keywordflow">return</span> 1 ;
+<a name="l02700"></a>02700 
+<a name="l02701"></a>02701 
+<a name="l02702"></a>02702    <span class="keywordflow">return</span> 0;
+<a name="l02703"></a>02703 
+<a name="l02704"></a>02704 }
+<a name="l02705"></a>02705 
+<a name="l02706"></a>02706 <span class="keywordtype">int</span>
+<a name="l02707"></a>02707 sinfo_propertylist_has(cpl_propertylist* plist,
+<a name="l02708"></a>02708                        <span class="keyword">const</span> <span class="keywordtype">char</span>* key) {
+<a name="l02709"></a>02709 
+<a name="l02710"></a>02710    <span class="keywordflow">return</span> cpl_propertylist_has(plist,key);
+<a name="l02711"></a>02711 
+<a name="l02712"></a>02712 }
+<a name="l02713"></a>02713 
+<a name="l02714"></a>02714 <span class="keywordtype">int</span> sinfo_frame_is_preoptic(cpl_frame* frame,<span class="keyword">const</span> <span class="keywordtype">char</span>* val)
+<a name="l02715"></a>02715 {
+<a name="l02716"></a>02716 
+<a name="l02717"></a>02717    <span class="keywordtype">char</span>* file=NULL;
+<a name="l02718"></a>02718    <span class="keywordtype">char</span> popt[FILE_NAME_SZ];
+<a name="l02719"></a>02719    cpl_propertylist* plist=NULL;
+<a name="l02720"></a>02720 
+<a name="l02721"></a>02721 
+<a name="l02722"></a>02722    file = cpl_strdup(cpl_frame_get_filename(frame)) ;
+<a name="l02723"></a>02723    <span class="keywordflow">if</span> ((cpl_error_code)((plist = cpl_propertylist_load(file, 0)) == NULL)) {
+<a name="l02724"></a>02724       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>( <span class="stringliteral">"getting header from reference frame %s"</span>,file);
+<a name="l02725"></a>02725       cpl_propertylist_delete(plist) ;
+<a name="l02726"></a>02726       cpl_free(file);
+<a name="l02727"></a>02727       <span class="keywordflow">return</span> -1 ;
+<a name="l02728"></a>02728    }
+<a name="l02729"></a>02729 
+<a name="l02730"></a>02730    <span class="keywordflow">if</span> (sinfo_propertylist_has(plist, KEY_NAME_PREOPTICS)) {
+<a name="l02731"></a>02731       strcpy(popt,cpl_propertylist_get_string(plist, KEY_NAME_PREOPTICS));
+<a name="l02732"></a>02732    } <span class="keywordflow">else</span> {
+<a name="l02733"></a>02733       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"keyword %s does not exist"</span>,KEY_NAME_PREOPTICS);
+<a name="l02734"></a>02734       cpl_free(file);
+<a name="l02735"></a>02735       <span class="keywordflow">return</span> -1;
+<a name="l02736"></a>02736    }
+<a name="l02737"></a>02737    cpl_propertylist_delete(plist) ;
+<a name="l02738"></a>02738    cpl_free(file);
+<a name="l02739"></a>02739 
+<a name="l02740"></a>02740    <span class="keywordflow">if</span> (strstr(val,popt) != NULL) <span class="keywordflow">return</span> 1 ;
+<a name="l02741"></a>02741 
+<a name="l02742"></a>02742 
+<a name="l02743"></a>02743    <span class="keywordflow">return</span> 0;
+<a name="l02744"></a>02744 
+<a name="l02745"></a>02745 }
+<a name="l02746"></a>02746 
+<a name="l02747"></a>02747 
+<a name="l02748"></a>02748 <span class="keywordtype">int</span> sinfo_get_preoptic(<span class="keyword">const</span> <span class="keywordtype">char</span>* file, <span class="keyword">const</span> <span class="keywordtype">char</span>* val)
+<a name="l02749"></a>02749 {
+<a name="l02750"></a>02750 
+<a name="l02751"></a>02751    cpl_propertylist* plist=NULL;
+<a name="l02752"></a>02752 
+<a name="l02753"></a>02753 
+<a name="l02754"></a>02754    <span class="keywordflow">if</span> ((cpl_error_code)((plist = cpl_propertylist_load(file, 0)) == NULL)) {
+<a name="l02755"></a>02755       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>( <span class="stringliteral">"getting header from reference frame %s"</span>,file);
+<a name="l02756"></a>02756       cpl_propertylist_delete(plist) ;
+<a name="l02757"></a>02757       <span class="keywordflow">return</span> -1 ;
+<a name="l02758"></a>02758    }
+<a name="l02759"></a>02759 
+<a name="l02760"></a>02760    <span class="keywordflow">if</span> (sinfo_propertylist_has(plist, KEY_NAME_PREOPTICS)) {
+<a name="l02761"></a>02761       strcpy((<span class="keywordtype">char</span>*)val,cpl_propertylist_get_string(plist, KEY_NAME_PREOPTICS));
+<a name="l02762"></a>02762    } <span class="keywordflow">else</span> {
+<a name="l02763"></a>02763       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"keyword %s does not exist"</span>,KEY_NAME_PREOPTICS);
+<a name="l02764"></a>02764       <span class="keywordflow">return</span> -1;
+<a name="l02765"></a>02765    }
+<a name="l02766"></a>02766    cpl_propertylist_delete(plist) ;
+<a name="l02767"></a>02767 
+<a name="l02768"></a>02768    <span class="keywordflow">return</span> 0;
+<a name="l02769"></a>02769 
+<a name="l02770"></a>02770 }
+<a name="l02771"></a>02771 
+<a name="l02772"></a>02772 <span class="comment">/*</span>
+<a name="l02773"></a>02773 <span class="comment">  static int</span>
+<a name="l02774"></a>02774 <span class="comment">  sinfo_stat_rectangle(cpl_image* img,</span>
+<a name="l02775"></a>02775 <span class="comment">  const int kappa,</span>
+<a name="l02776"></a>02776 <span class="comment">  const int nclip,</span>
+<a name="l02777"></a>02777 <span class="comment">  double *mean,</span>
+<a name="l02778"></a>02778 <span class="comment">  double *stdev)</span>
+<a name="l02779"></a>02779 <span class="comment">  {</span>
+<a name="l02780"></a>02780 <span class="comment"></span>
+<a name="l02781"></a>02781 <span class="comment">  double sum=0;</span>
+<a name="l02782"></a>02782 <span class="comment">  double sum2=0;</span>
+<a name="l02783"></a>02783 <span class="comment">  double noise=0;</span>
+<a name="l02784"></a>02784 <span class="comment"></span>
+<a name="l02785"></a>02785 <span class="comment">  double* pim=NULL;</span>
+<a name="l02786"></a>02786 <span class="comment">  int i=0;</span>
+<a name="l02787"></a>02787 <span class="comment">  int j=0;</span>
+<a name="l02788"></a>02788 <span class="comment">  int kk=0;</span>
+<a name="l02789"></a>02789 <span class="comment">  int sx=0;</span>
+<a name="l02790"></a>02790 <span class="comment">  int sy=0;</span>
+<a name="l02791"></a>02791 <span class="comment"></span>
+<a name="l02792"></a>02792 <span class="comment">  *mean=0;</span>
+<a name="l02793"></a>02793 <span class="comment">  pim=cpl_image_get_data(img);</span>
+<a name="l02794"></a>02794 <span class="comment">  kk=0;</span>
+<a name="l02795"></a>02795 <span class="comment">  for(i=0;i<sx*sy;i++) {</span>
+<a name="l02796"></a>02796 <span class="comment">  *mean+=pim[i];</span>
+<a name="l02797"></a>02797 <span class="comment">  }</span>
+<a name="l02798"></a>02798 <span class="comment">  *mean/=(sx*sy);</span>
+<a name="l02799"></a>02799 <span class="comment"></span>
+<a name="l02800"></a>02800 <span class="comment">  for(i=0;i<sx*sy;i++) {</span>
+<a name="l02801"></a>02801 <span class="comment">  sum+=(pim[i]-*mean)*(pim[i]-*mean);</span>
+<a name="l02802"></a>02802 <span class="comment">  }</span>
+<a name="l02803"></a>02803 <span class="comment">  noise=sqrt(sum/(sx*sy));</span>
+<a name="l02804"></a>02804 <span class="comment"></span>
+<a name="l02805"></a>02805 <span class="comment"></span>
+<a name="l02806"></a>02806 <span class="comment">  //clean a bit the bad pixels</span>
+<a name="l02807"></a>02807 <span class="comment">  for(j=0;j<nclip;j++) {</span>
+<a name="l02808"></a>02808 <span class="comment">  sum=0;</span>
+<a name="l02809"></a>02809 <span class="comment">  sum2=0;</span>
+<a name="l02810"></a>02810 <span class="comment">  kk=0;</span>
+<a name="l02811"></a>02811 <span class="comment">  for(i=0;i<sx*sy;i++) {</span>
+<a name="l02812"></a>02812 <span class="comment">  if(fabs(pim[i]-*mean)<kappa*noise) {</span>
+<a name="l02813"></a>02813 <span class="comment"></span>
+<a name="l02814"></a>02814 <span class="comment">  sum  +=(pim[i]-*mean)*(pim[i]-*mean);</span>
+<a name="l02815"></a>02815 <span class="comment">  sum2 += pim[i];</span>
+<a name="l02816"></a>02816 <span class="comment">  kk+=1;</span>
+<a name="l02817"></a>02817 <span class="comment">  }</span>
+<a name="l02818"></a>02818 <span class="comment">  noise=sqrt(sum/kk);</span>
+<a name="l02819"></a>02819 <span class="comment">  *mean=sum2/kk;</span>
+<a name="l02820"></a>02820 <span class="comment"></span>
+<a name="l02821"></a>02821 <span class="comment">  }</span>
+<a name="l02822"></a>02822 <span class="comment"></span>
+<a name="l02823"></a>02823 <span class="comment">  }</span>
+<a name="l02824"></a>02824 <span class="comment">  *stdev=noise;</span>
+<a name="l02825"></a>02825 <span class="comment"></span>
+<a name="l02826"></a>02826 <span class="comment">  return 0;</span>
+<a name="l02827"></a>02827 <span class="comment"></span>
+<a name="l02828"></a>02828 <span class="comment">  }</span>
+<a name="l02829"></a>02829 <span class="comment">*/</span>
+<a name="l02830"></a>02830 
+<a name="l02831"></a>02831 cpl_table* sinfo_compute_gain(cpl_frameset* son, cpl_frameset* sof)
+<a name="l02832"></a>02832 {
+<a name="l02833"></a>02833 
+<a name="l02834"></a>02834 
+<a name="l02835"></a>02835    cpl_frame*    frm=NULL;
+<a name="l02836"></a>02836 
+<a name="l02837"></a>02837    cpl_image* img_on1=NULL;
+<a name="l02838"></a>02838    cpl_image* img_on2=NULL;
+<a name="l02839"></a>02839    cpl_image* img_on_dif=NULL;
+<a name="l02840"></a>02840    cpl_image* img_on_sub=NULL;
+<a name="l02841"></a>02841 
+<a name="l02842"></a>02842 
+<a name="l02843"></a>02843    cpl_image* img_of1=NULL;
+<a name="l02844"></a>02844    cpl_image* img_of2=NULL;
+<a name="l02845"></a>02845    cpl_image* img_of_dif=NULL;
+<a name="l02846"></a>02846    cpl_image* img_of_sub=NULL;
+<a name="l02847"></a>02847 
+<a name="l02848"></a>02848    cpl_table* res_tbl=NULL;
+<a name="l02849"></a>02849    cpl_vector* dit_on=NULL;
+<a name="l02850"></a>02850    cpl_vector* dit_of=NULL;
+<a name="l02851"></a>02851    cpl_vector* exptime_on=NULL;
+<a name="l02852"></a>02852    cpl_vector* exptime_of=NULL;
+<a name="l02853"></a>02853    cpl_propertylist* plist=NULL;
+<a name="l02854"></a>02854 
+<a name="l02855"></a>02855    <span class="keywordtype">int</span> non=0;
+<a name="l02856"></a>02856    <span class="keywordtype">int</span> nof=0;
+<a name="l02857"></a>02857    <span class="keywordtype">int</span> nfr=0;
+<a name="l02858"></a>02858    <span class="keywordtype">double</span> avg_on1=0;
+<a name="l02859"></a>02859    <span class="keywordtype">double</span> avg_on2=0;
+<a name="l02860"></a>02860    <span class="keywordtype">double</span> avg_of1=0;
+<a name="l02861"></a>02861    <span class="keywordtype">double</span> avg_of2=0;
+<a name="l02862"></a>02862    <span class="keywordtype">double</span> std=0;
+<a name="l02863"></a>02863 
+<a name="l02864"></a>02864    <span class="keywordtype">double</span> sig_on_dif=0;
+<a name="l02865"></a>02865    <span class="keywordtype">double</span> sig_of_dif=0;
+<a name="l02866"></a>02866    <span class="keywordtype">char</span>* name=NULL;
+<a name="l02867"></a>02867    <span class="keywordtype">int</span> i=0;
+<a name="l02868"></a>02868    <span class="keywordtype">int</span> m=0;
+<a name="l02869"></a>02869 
+<a name="l02870"></a>02870    <span class="keywordtype">int</span> llx=270;
+<a name="l02871"></a>02871    <span class="keywordtype">int</span> lly=1000;
+<a name="l02872"></a>02872    <span class="keywordtype">int</span> urx=320;
+<a name="l02873"></a>02873    <span class="keywordtype">int</span> ury=1050;
+<a name="l02874"></a>02874    <span class="keywordtype">int</span> zone[4];
+<a name="l02875"></a>02875    <span class="keywordtype">double</span> gain=0;
+<a name="l02876"></a>02876    <span class="keywordtype">double</span> dit_ref=0;
+<a name="l02877"></a>02877    <span class="keywordtype">double</span> dit_tmp=0;
+<a name="l02878"></a>02878    <span class="keywordtype">double</span> exptime_ref=0;
+<a name="l02879"></a>02879    <span class="keywordtype">double</span> exptime_tmp=0;
+<a name="l02880"></a>02880    <span class="keywordtype">int</span> kappa=5;
+<a name="l02881"></a>02881    <span class="keywordtype">int</span> nclip=25;
+<a name="l02882"></a>02882    <span class="keywordtype">double</span> centre=0;
+<a name="l02883"></a>02883 
+<a name="l02884"></a>02884    non = cpl_frameset_get_size(son);
+<a name="l02885"></a>02885    nof = cpl_frameset_get_size(sof);
+<a name="l02886"></a>02886    nfr = (non <= nof) ? non : nof;
+<a name="l02887"></a>02887 
+<a name="l02888"></a>02888    dit_on=cpl_vector_new(nfr);
+<a name="l02889"></a>02889    dit_of=cpl_vector_new(nfr);
+<a name="l02890"></a>02890    exptime_on=cpl_vector_new(nfr);
+<a name="l02891"></a>02891    exptime_of=cpl_vector_new(nfr);
+<a name="l02892"></a>02892 
+<a name="l02893"></a>02893    <span class="keywordflow">for</span>(i=0;i<nfr;i++) {
+<a name="l02894"></a>02894 
+<a name="l02895"></a>02895       frm=cpl_frameset_get_frame(son,i);
+<a name="l02896"></a>02896       name=(<span class="keywordtype">char</span>*)cpl_frame_get_filename(frm);
+<a name="l02897"></a>02897       plist=cpl_propertylist_load(name,0);
+<a name="l02898"></a>02898       dit_ref=sinfo_pfits_get_dit(plist);
+<a name="l02899"></a>02899       exptime_ref=(double)sinfo_pfits_get_exp_time(plist);
+<a name="l02900"></a>02900       cpl_propertylist_delete(plist);
+<a name="l02901"></a>02901       cpl_vector_set(dit_on,i,dit_ref);
+<a name="l02902"></a>02902       cpl_vector_set(exptime_on,i,exptime_ref);
+<a name="l02903"></a>02903 
+<a name="l02904"></a>02904       frm=cpl_frameset_get_frame(sof,i);
+<a name="l02905"></a>02905       name=(<span class="keywordtype">char</span>*)cpl_frame_get_filename(frm);
+<a name="l02906"></a>02906       plist=cpl_propertylist_load(name,0);
+<a name="l02907"></a>02907       dit_ref=sinfo_pfits_get_dit(plist);
+<a name="l02908"></a>02908       exptime_ref=(double)sinfo_pfits_get_exp_time(plist);
+<a name="l02909"></a>02909       cpl_propertylist_delete(plist);
+<a name="l02910"></a>02910       cpl_vector_set(dit_of,i,dit_ref);
+<a name="l02911"></a>02911       cpl_vector_set(exptime_of,i,exptime_ref);
+<a name="l02912"></a>02912 
+<a name="l02913"></a>02913    }
+<a name="l02914"></a>02914 
+<a name="l02915"></a>02915 
+<a name="l02916"></a>02916 
+<a name="l02917"></a>02917    zone[0]=270;
+<a name="l02918"></a>02918    zone[1]=1030;
+<a name="l02919"></a>02919    zone[2]=310;
+<a name="l02920"></a>02920    zone[3]=1060;
+<a name="l02921"></a>02921 
+<a name="l02922"></a>02922 
+<a name="l02923"></a>02923 
+<a name="l02924"></a>02924    zone[0]=20;
+<a name="l02925"></a>02925    zone[1]=2028;
+<a name="l02926"></a>02926    zone[2]=20;
+<a name="l02927"></a>02927    zone[3]=2028;
+<a name="l02928"></a>02928 
+<a name="l02929"></a>02929 
+<a name="l02930"></a>02930 
+<a name="l02931"></a>02931    check_nomsg(res_tbl=cpl_table_new(nfr));
+<a name="l02932"></a>02932    cpl_table_new_column(res_tbl,<span class="stringliteral">"adu"</span>, CPL_TYPE_DOUBLE);
+<a name="l02933"></a>02933    cpl_table_new_column(res_tbl,<span class="stringliteral">"gain"</span>, CPL_TYPE_DOUBLE);
+<a name="l02934"></a>02934 
+<a name="l02935"></a>02935    <span class="keywordflow">for</span>(i=0;i<nfr;i++) {
+<a name="l02936"></a>02936       frm=cpl_frameset_get_frame(son,i);
+<a name="l02937"></a>02937       name=(<span class="keywordtype">char</span>*)cpl_frame_get_filename(frm);
+<a name="l02938"></a>02938       img_on1=cpl_image_load(name,CPL_TYPE_DOUBLE,0,0);
+<a name="l02939"></a>02939 
+<a name="l02940"></a>02940       frm=cpl_frameset_get_frame(sof,i);
+<a name="l02941"></a>02941       name=(<span class="keywordtype">char</span>*)cpl_frame_get_filename(frm);
+<a name="l02942"></a>02942       img_of1=cpl_image_load(name,CPL_TYPE_DOUBLE,0,0);
+<a name="l02943"></a>02943 
+<a name="l02944"></a>02944 
+<a name="l02945"></a>02945       dit_ref=cpl_vector_get(dit_on,i);
+<a name="l02946"></a>02946       exptime_ref=cpl_vector_get(exptime_on,i);
+<a name="l02947"></a>02947 
+<a name="l02948"></a>02948 
+<a name="l02949"></a>02949       <span class="keywordflow">for</span>(m=0;m<nfr; m++) {
+<a name="l02950"></a>02950          <span class="keywordflow">if</span>(m != i) {
+<a name="l02951"></a>02951             frm=cpl_frameset_get_frame(son,m);
+<a name="l02952"></a>02952             name=(<span class="keywordtype">char</span>*)cpl_frame_get_filename(frm);
+<a name="l02953"></a>02953             dit_tmp=cpl_vector_get(dit_on,m);
+<a name="l02954"></a>02954             exptime_tmp=cpl_vector_get(exptime_on,m);
+<a name="l02955"></a>02955             <span class="keywordflow">if</span>(dit_tmp == dit_ref && exptime_tmp == exptime_ref) {
+<a name="l02956"></a>02956                <span class="comment">/* sinfo_msg("m=%d i=%d\n",m,i); */</span>
+<a name="l02957"></a>02957                img_on2=cpl_image_load(name,CPL_TYPE_DOUBLE,0,0);
+<a name="l02958"></a>02958                frm=cpl_frameset_get_frame(sof,m);
+<a name="l02959"></a>02959                name=(<span class="keywordtype">char</span>*)cpl_frame_get_filename(frm);
+<a name="l02960"></a>02960                img_of2=cpl_image_load(name,CPL_TYPE_DOUBLE,0,0);
+<a name="l02961"></a>02961 
+<a name="l02962"></a>02962                img_on_dif=cpl_image_subtract_create(img_on1,img_on2);
+<a name="l02963"></a>02963                img_of_dif=cpl_image_subtract_create(img_of1,img_of2);
+<a name="l02964"></a>02964 
+<a name="l02965"></a>02965                img_on_sub=cpl_image_extract(img_on_dif,llx,lly,urx,ury);
+<a name="l02966"></a>02966                img_of_sub=cpl_image_extract(img_of_dif,llx,lly,urx,ury);
+<a name="l02967"></a>02967 
+<a name="l02968"></a>02968                sinfo_get_clean_mean_window(img_on1,llx,lly,urx,ury,kappa,
+<a name="l02969"></a>02969                                            nclip,&avg_on1,&std);
+<a name="l02970"></a>02970                sinfo_get_clean_mean_window(img_on2,llx,lly,urx,ury,kappa,
+<a name="l02971"></a>02971                                            nclip,&avg_on2,&std);
+<a name="l02972"></a>02972                sinfo_get_clean_mean_window(img_of1,llx,lly,urx,ury,kappa,
+<a name="l02973"></a>02973                                            nclip,&avg_of1,&std);
+<a name="l02974"></a>02974                sinfo_get_clean_mean_window(img_of2,llx,lly,urx,ury,kappa,
+<a name="l02975"></a>02975                                            nclip,&avg_of2,&std);
+<a name="l02976"></a>02976                <span class="comment">/*</span>
+<a name="l02977"></a>02977 <span class="comment">                 cpl_image_save(img_on_sub,"ima_on_sub.fits",</span>
+<a name="l02978"></a>02978 <span class="comment">                                CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT);</span>
+<a name="l02979"></a>02979 <span class="comment">                 cpl_image_save(img_of_sub,"ima_of_sub.fits",</span>
+<a name="l02980"></a>02980 <span class="comment">                                CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT);</span>
+<a name="l02981"></a>02981 <span class="comment">               */</span>
+<a name="l02982"></a>02982                <span class="comment">/*</span>
+<a name="l02983"></a>02983 <span class="comment">               //worse accuracy</span>
+<a name="l02984"></a>02984 <span class="comment">               sinfo_stat_rectangle(img_on_dif,kappa,nclip,</span>
+<a name="l02985"></a>02985 <span class="comment">                                    &centre,&sig_on_dif);</span>
+<a name="l02986"></a>02986 <span class="comment">               sinfo_stat_rectangle(img_of_dif,kappa,nclip,</span>
+<a name="l02987"></a>02987 <span class="comment">                                    &centre,&sig_of_dif);</span>
+<a name="l02988"></a>02988 <span class="comment">               */</span>
+<a name="l02989"></a>02989 
+<a name="l02990"></a>02990 
+<a name="l02991"></a>02991                <span class="comment">//better accuracy</span>
+<a name="l02992"></a>02992                sinfo_get_clean_mean_window(img_on_dif,llx,lly,urx,ury,kappa,
+<a name="l02993"></a>02993                                            nclip,&centre,&sig_on_dif);
+<a name="l02994"></a>02994                sinfo_get_clean_mean_window(img_of_dif,llx,lly,urx,ury,kappa,
+<a name="l02995"></a>02995                                            nclip,&centre,&sig_of_dif);
+<a name="l03012"></a>03012                cpl_image_delete(img_on2);
+<a name="l03013"></a>03013                cpl_image_delete(img_of2);
+<a name="l03014"></a>03014                cpl_image_delete(img_on_dif);
+<a name="l03015"></a>03015                cpl_image_delete(img_of_dif);
+<a name="l03016"></a>03016                cpl_image_delete(img_on_sub);
+<a name="l03017"></a>03017                cpl_image_delete(img_of_sub);
+<a name="l03018"></a>03018 
+<a name="l03019"></a>03019                gain=((avg_on1+avg_on2)-(avg_of1+avg_of2))/
+<a name="l03020"></a>03020                   ((sig_on_dif*sig_on_dif)-(sig_of_dif*sig_of_dif));
+<a name="l03021"></a>03021 
+<a name="l03022"></a>03022                cpl_table_set_double(res_tbl,<span class="stringliteral">"gain"</span>,m,gain);
+<a name="l03023"></a>03023                cpl_table_set_double(res_tbl,<span class="stringliteral">"adu"</span>,m,
+<a name="l03024"></a>03024                                     ((avg_on1+avg_on2)/2-(avg_of1+avg_of2)/2));
+<a name="l03025"></a>03025                <span class="comment">/* sinfo_msg("gain=%f ADU=%f\n",gain,</span>
+<a name="l03026"></a>03026 <span class="comment">                  (avg_on1+avg_on2)/2-(avg_of1+avg_of2)/2);</span>
+<a name="l03027"></a>03027 <span class="comment">                  sinfo_msg("g=%f avg_on1=%f avg_on2=%f",gain,avg_on1,avg_on2);</span>
+<a name="l03028"></a>03028 <span class="comment">                 sinfo_msg("avg_of1=%f avg_of2=%f sig_on_dif=%f sig_of_dif=%f",</span>
+<a name="l03029"></a>03029 <span class="comment">                  avg_of1,avg_of2,sig_on_dif,sig_of_dif);</span>
+<a name="l03030"></a>03030 <span class="comment">               */</span>
+<a name="l03031"></a>03031 
+<a name="l03032"></a>03032             }
+<a name="l03033"></a>03033          }
+<a name="l03034"></a>03034       }
+<a name="l03035"></a>03035       cpl_image_delete(img_on1);
+<a name="l03036"></a>03036       cpl_image_delete(img_of1);
+<a name="l03037"></a>03037    }
+<a name="l03038"></a>03038 
+<a name="l03039"></a>03039 
+<a name="l03040"></a>03040    <span class="comment">/*</span>
+<a name="l03041"></a>03041 <span class="comment">     sinfo_get_clean_mean_window(img_on_dif,llx,lly,urx,ury,kappa,</span>
+<a name="l03042"></a>03042 <span class="comment">     nclip,&avg,&sig_on_dif);</span>
+<a name="l03043"></a>03043 <span class="comment">     sinfo_get_clean_mean_window(img_of_dif,llx,lly,urx,ury,kappa,</span>
+<a name="l03044"></a>03044 <span class="comment">     nclip,&avg,&sig_of_dif);</span>
+<a name="l03045"></a>03045 <span class="comment">   */</span>
+<a name="l03046"></a>03046 
+<a name="l03047"></a>03047    cpl_vector_delete(dit_on);
+<a name="l03048"></a>03048    cpl_vector_delete(dit_of);
+<a name="l03049"></a>03049    cpl_vector_delete(exptime_on);
+<a name="l03050"></a>03050    cpl_vector_delete(exptime_of);
+<a name="l03051"></a>03051 
+<a name="l03052"></a>03052    <span class="keywordflow">return</span> res_tbl;
+<a name="l03053"></a>03053 
+<a name="l03054"></a>03054   cleanup:
+<a name="l03055"></a>03055    <span class="keywordflow">return</span> NULL;
+<a name="l03056"></a>03056 
+<a name="l03057"></a>03057 }
+<a name="l03058"></a>03058 
+<a name="l03059"></a>03059 
+<a name="l03060"></a>03060 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l03072"></a>03072 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l03073"></a>03073 
+<a name="l03074"></a>03074 <span class="keywordtype">int</span>
+<a name="l03075"></a>03075 sinfo_image_estimate_noise(cpl_image* img,
+<a name="l03076"></a>03076                            <span class="keyword">const</span> <span class="keywordtype">int</span> noise_fit,
+<a name="l03077"></a>03077                            <span class="keywordtype">double</span>* centre,
+<a name="l03078"></a>03078                            <span class="keywordtype">double</span>* noise)
+<a name="l03079"></a>03079 {
+<a name="l03080"></a>03080 
+<a name="l03081"></a>03081    <span class="keywordtype">int</span> nbins=0;
+<a name="l03082"></a>03082 
+<a name="l03083"></a>03083    <span class="keywordtype">int</span> xsz=0;
+<a name="l03084"></a>03084    <span class="keywordtype">int</span> ysz=0;
+<a name="l03085"></a>03085    <span class="keywordtype">int</span> n=0;
+<a name="l03086"></a>03086    <span class="keywordtype">int</span> i=0;
+<a name="l03087"></a>03087    <span class="keywordtype">int</span> r=0;
+<a name="l03088"></a>03088 
+<a name="l03089"></a>03089    <span class="keywordtype">int</span> ndist=0;
+<a name="l03090"></a>03090    <span class="keywordtype">double</span> min_fct=HISTO_DIST_TEMPC_MIN_FCT;
+<a name="l03091"></a>03091    <span class="keywordtype">double</span> max_fct=HISTO_DIST_TEMPC_MAX_FCT;
+<a name="l03092"></a>03092    <span class="keywordtype">double</span> avg_d=0;
+<a name="l03093"></a>03093    <span class="keywordtype">double</span> std_d=0;
+<a name="l03094"></a>03094    <span class="keywordtype">double</span> hmin=0;
+<a name="l03095"></a>03095    <span class="keywordtype">double</span> hmax=0;
+<a name="l03096"></a>03096    <span class="keywordtype">double</span> kappa=3;
+<a name="l03097"></a>03097 
+<a name="l03098"></a>03098    <span class="keywordtype">double</span>* pdata=NULL;
+<a name="l03099"></a>03099    <span class="keywordtype">double</span>* disth=NULL;
+<a name="l03100"></a>03100    <span class="keywordtype">double</span>* distx=NULL;
+<a name="l03101"></a>03101 
+<a name="l03102"></a>03102    <span class="keywordtype">double</span> peak=0;
+<a name="l03103"></a>03103    <span class="keywordtype">double</span> tempc=0;
+<a name="l03104"></a>03104    <span class="keywordtype">double</span> value=0;
+<a name="l03105"></a>03105    <span class="keywordtype">double</span> x0=0;
+<a name="l03106"></a>03106    <span class="keywordtype">double</span> sigma=0;
+<a name="l03107"></a>03107    <span class="keywordtype">double</span> area=0;
+<a name="l03108"></a>03108    <span class="keywordtype">double</span> offset=0;
+<a name="l03109"></a>03109    <span class="comment">//double mse=0;</span>
+<a name="l03110"></a>03110    <span class="comment">//double chired=0;</span>
+<a name="l03111"></a>03111 
+<a name="l03112"></a>03112    cpl_table* data_tbl=NULL;
+<a name="l03113"></a>03113    cpl_table* histo=NULL;
+<a name="l03114"></a>03114    cpl_table* dist=NULL;
+<a name="l03115"></a>03115    cpl_table* min_xi=NULL;
+<a name="l03116"></a>03116    cpl_table* tmp_tbl1=NULL;
+<a name="l03117"></a>03117    cpl_table* tmp_tbl2=NULL;
+<a name="l03118"></a>03118    cpl_vector* vx=NULL;
+<a name="l03119"></a>03119    cpl_vector* vy=NULL;
+<a name="l03120"></a>03120    cpl_vector* sx=NULL;
+<a name="l03121"></a>03121    cpl_vector* sy=NULL;
+<a name="l03122"></a>03122 
+<a name="l03123"></a>03123    <span class="comment">// Get Object relevant information</span>
+<a name="l03124"></a>03124    check_nomsg(xsz=cpl_image_get_size_x(img));
+<a name="l03125"></a>03125    check_nomsg(ysz=cpl_image_get_size_y(img));
+<a name="l03126"></a>03126    n=xsz*ysz;
+<a name="l03127"></a>03127    nbins=sqrt(n);
+<a name="l03128"></a>03128    check_nomsg(data_tbl=cpl_table_new(n));
+<a name="l03129"></a>03129    check_nomsg(cpl_table_new_column(data_tbl,<span class="stringliteral">"DATA"</span>,CPL_TYPE_DOUBLE));
+<a name="l03130"></a>03130 
+<a name="l03131"></a>03131    check_nomsg(pdata=cpl_image_get_data(img));
+<a name="l03132"></a>03132    <span class="keywordflow">for</span>(i=0;i<n;i++) {
+<a name="l03133"></a>03133       <span class="keywordflow">if</span>(!isnan(pdata[i])) {
+<a name="l03134"></a>03134          cpl_table_set_double(data_tbl,<span class="stringliteral">"DATA"</span>,r,pdata[i]);
+<a name="l03135"></a>03135          r++;
+<a name="l03136"></a>03136       }
+<a name="l03137"></a>03137    }
+<a name="l03138"></a>03138 
+<a name="l03139"></a>03139    check_nomsg(cpl_table_erase_invalid(data_tbl));
+<a name="l03140"></a>03140    check_nomsg(avg_d=cpl_table_get_column_mean(data_tbl,<span class="stringliteral">"DATA"</span>));
+<a name="l03141"></a>03141    check_nomsg(std_d=cpl_table_get_column_stdev(data_tbl,<span class="stringliteral">"DATA"</span>));
+<a name="l03142"></a>03142 
+<a name="l03143"></a>03143    cpl_table_save(data_tbl, NULL, NULL, <span class="stringliteral">"out_data.fits"</span>, CPL_IO_DEFAULT);
+<a name="l03144"></a>03144 
+<a name="l03145"></a>03145    hmin=avg_d-kappa*std_d;
+<a name="l03146"></a>03146    hmax=avg_d+kappa*std_d;
+<a name="l03147"></a>03147    <span class="comment">//sinfo_msg("mean=%g stdv=%g",avg_d,std_d);</span>
+<a name="l03148"></a>03148    <span class="comment">//sinfo_msg("hmin=%g hmax=%g",hmin,hmax);</span>
+<a name="l03149"></a>03149    <span class="comment">//sinfo_msg("Computes histogram");</span>
+<a name="l03150"></a>03150    ck0(sinfo_histogram(data_tbl,nbins,hmin,hmax,&histo),<span class="stringliteral">"building histogram"</span>);
+<a name="l03151"></a>03151 
+<a name="l03152"></a>03152    value=(double)(hmax-hmin)/nbins/2.;
+<a name="l03153"></a>03153    <span class="comment">//sinfo_msg("value=%10.8f",value);</span>
+<a name="l03154"></a>03154    <span class="comment">//cpl_table_save(histo, NULL, NULL, "out_pippo.fits", CPL_IO_DEFAULT0);</span>
+<a name="l03155"></a>03155 
+<a name="l03156"></a>03156    check_nomsg(peak=cpl_table_get_column_max(histo,<span class="stringliteral">"HY"</span>));
+<a name="l03157"></a>03157    <span class="comment">//sinfo_msg("peak=%f",peak);</span>
+<a name="l03158"></a>03158    sinfo_free_table(&tmp_tbl1);
+<a name="l03159"></a>03159 
+<a name="l03160"></a>03160    check_nomsg(tmp_tbl1=sinfo_extract_table_rows(histo,<span class="stringliteral">"HY"</span>,CPL_EQUAL_TO,peak));
+<a name="l03161"></a>03161 
+<a name="l03162"></a>03162    <span class="comment">//cpl_table_save(tmp_tbl1, NULL, NULL, "out_tmp_tbl1.fits", CPL_IO_DEFAULT);</span>
+<a name="l03163"></a>03163 
+<a name="l03164"></a>03164 
+<a name="l03165"></a>03165    check_nomsg(*centre=cpl_table_get_column_mean(tmp_tbl1,<span class="stringliteral">"HL"</span>));
+<a name="l03166"></a>03166    <span class="comment">//sinfo_msg("Background level=%f",*centre);</span>
+<a name="l03167"></a>03167 
+<a name="l03168"></a>03168    sinfo_free_table(&tmp_tbl1);
+<a name="l03169"></a>03169    check_nomsg(tmp_tbl1=sinfo_extract_table_rows(histo,<span class="stringliteral">"HY"</span>,
+<a name="l03170"></a>03170                                                  CPL_GREATER_THAN,
+<a name="l03171"></a>03171                                                  peak/HISTO_Y_CUT));
+<a name="l03172"></a>03172    sinfo_free_table(&tmp_tbl2);
+<a name="l03173"></a>03173    check_nomsg(tmp_tbl2=sinfo_extract_table_rows(tmp_tbl1,<span class="stringliteral">"HY"</span>,
+<a name="l03174"></a>03174                                                  CPL_LESS_THAN,peak));
+<a name="l03175"></a>03175    sinfo_free_table(&tmp_tbl1);
+<a name="l03176"></a>03176 
+<a name="l03177"></a>03177    check_nomsg(tempc=*centre-cpl_table_get_column_min(tmp_tbl2,<span class="stringliteral">"HL"</span>));
+<a name="l03178"></a>03178    <span class="comment">//sinfo_msg("min HX %f",cpl_table_get_column_min(tmp_tbl2,"HL"));</span>
+<a name="l03179"></a>03179    sinfo_free_table(&tmp_tbl2);
+<a name="l03180"></a>03180    <span class="comment">//sinfo_msg("Tempc=%f",tempc);</span>
+<a name="l03181"></a>03181    check_nomsg(dist=sinfo_where_tab_min_max(histo,<span class="stringliteral">"HL"</span>,
+<a name="l03182"></a>03182                                             CPL_GREATER_THAN,
+<a name="l03183"></a>03183                                             *centre-min_fct*tempc,
+<a name="l03184"></a>03184                                             CPL_NOT_GREATER_THAN,
+<a name="l03185"></a>03185                                             *centre+max_fct*tempc));
+<a name="l03186"></a>03186 
+<a name="l03187"></a>03187    offset=cpl_table_get_column_min(histo,<span class="stringliteral">"HY"</span>);
+<a name="l03188"></a>03188    sinfo_free_table(&histo);
+<a name="l03189"></a>03189 
+<a name="l03190"></a>03190 
+<a name="l03191"></a>03191    check_nomsg(ndist=cpl_table_get_nrow(dist));
+<a name="l03192"></a>03192    check_nomsg(cpl_table_cast_column(dist,<span class="stringliteral">"HY"</span>,<span class="stringliteral">"HYdouble"</span>,CPL_TYPE_DOUBLE));
+<a name="l03193"></a>03193    check_nomsg(disth=cpl_table_get_data_double(dist,<span class="stringliteral">"HYdouble"</span>));
+<a name="l03194"></a>03194    check_nomsg(distx=cpl_table_get_data_double(dist,<span class="stringliteral">"HL"</span>));
+<a name="l03195"></a>03195    cpl_table_save(dist, NULL, NULL, <span class="stringliteral">"out_dist.fits"</span>, CPL_IO_DEFAULT);
+<a name="l03196"></a>03196 
+<a name="l03197"></a>03197    <span class="comment">//TODO</span>
+<a name="l03198"></a>03198    <span class="comment">//gaussfit(distx,disty,dista,nterms=3);</span>
+<a name="l03199"></a>03199    <span class="comment">//*noise=dista[2];</span>
+<a name="l03200"></a>03200    *noise=tempc/2;
+<a name="l03201"></a>03201    <span class="comment">/* THIS DOES NOT WORK */</span>
+<a name="l03202"></a>03202    <span class="comment">//sinfo_msg("FWHM/2=%f",*noise);</span>
+<a name="l03203"></a>03203 
+<a name="l03204"></a>03204    <span class="keywordflow">if</span>(noise_fit == 1) {
+<a name="l03205"></a>03205       check_nomsg(vy=cpl_vector_wrap(ndist,disth));
+<a name="l03206"></a>03206       check_nomsg(vx=cpl_vector_wrap(ndist,distx));
+<a name="l03207"></a>03207       check_nomsg(sx=cpl_vector_new(ndist));
+<a name="l03208"></a>03208       check_nomsg(cpl_vector_fill(sx,1.));
+<a name="l03209"></a>03209       check_nomsg(sy=cpl_vector_duplicate(sx));
+<a name="l03210"></a>03210       x0=*centre;
+<a name="l03211"></a>03211       sigma=tempc/2;
+<a name="l03212"></a>03212 
+<a name="l03213"></a>03213       <span class="keywordflow">if</span>(CPL_ERROR_NONE != cpl_vector_fit_gaussian(vx,NULL,
+<a name="l03214"></a>03214                                                    vy,NULL,
+<a name="l03215"></a>03215                                                    CPL_FIT_ALL,
+<a name="l03216"></a>03216                                                    &x0,&sigma,&area,&offset,
+<a name="l03217"></a>03217                                                    NULL,NULL,NULL)) {
+<a name="l03218"></a>03218          cpl_error_reset();
+<a name="l03219"></a>03219       }
+<a name="l03220"></a>03220       <span class="comment">//sinfo_msg("Gauss fit parameters:"</span>
+<a name="l03221"></a>03221       <span class="comment">//          "x0=%f sigma=%f area=%f offset=%f mse=%f chired=%f",</span>
+<a name="l03222"></a>03222       <span class="comment">//           x0,sigma,area,offset,mse,chired);</span>
+<a name="l03223"></a>03223       <span class="comment">//sinfo_msg("Background level=%f",*centre);</span>
+<a name="l03224"></a>03224       <span class="comment">//sinfo_msg("Noise=%f",sigma);</span>
+<a name="l03225"></a>03225       *noise=sigma;
+<a name="l03226"></a>03226       sinfo_unwrap_vector(&vx);
+<a name="l03227"></a>03227       sinfo_unwrap_vector(&vy);
+<a name="l03228"></a>03228       sinfo_free_my_vector(&sx);
+<a name="l03229"></a>03229       sinfo_free_my_vector(&sy);
+<a name="l03230"></a>03230    }
+<a name="l03231"></a>03231    sinfo_free_table(&dist);
+<a name="l03232"></a>03232 
+<a name="l03233"></a>03233    <span class="keywordflow">return</span> 0;
+<a name="l03234"></a>03234 
+<a name="l03235"></a>03235   cleanup:
+<a name="l03236"></a>03236    sinfo_free_table(&min_xi);
+<a name="l03237"></a>03237    sinfo_free_table(&tmp_tbl1);
+<a name="l03238"></a>03238    sinfo_free_table(&tmp_tbl2);
+<a name="l03239"></a>03239    sinfo_free_table(&histo);
+<a name="l03240"></a>03240    sinfo_free_table(&dist);
+<a name="l03241"></a>03241    sinfo_free_table(&data_tbl);
+<a name="l03242"></a>03242    sinfo_free_my_vector(&sx);
+<a name="l03243"></a>03243    sinfo_free_my_vector(&sy);
+<a name="l03244"></a>03244    sinfo_unwrap_vector(&vx);
+<a name="l03245"></a>03245    sinfo_unwrap_vector(&vy);
+<a name="l03246"></a>03246 
+<a name="l03247"></a>03247    <span class="keywordflow">return</span> -1;
+<a name="l03248"></a>03248 
+<a name="l03249"></a>03249 }
+<a name="l03250"></a>03250 
+<a name="l03251"></a>03251 
+<a name="l03252"></a>03252 
+<a name="l03253"></a>03253 
+<a name="l03254"></a>03254 
+<a name="l03255"></a>03255 cpl_table* sinfo_compute_linearity(cpl_frameset* son, cpl_frameset* sof)
+<a name="l03256"></a>03256 {
+<a name="l03257"></a>03257 
+<a name="l03258"></a>03258    cpl_frame*    frm=NULL;
+<a name="l03259"></a>03259 
+<a name="l03260"></a>03260    <span class="keywordtype">int</span>* status=0;
+<a name="l03261"></a>03261    <span class="keywordtype">int</span> non=0;
+<a name="l03262"></a>03262    <span class="keywordtype">int</span> nof=0;
+<a name="l03263"></a>03263    <span class="keywordtype">int</span> nfr=0;
+<a name="l03264"></a>03264    <span class="keywordtype">int</span> i=0;
+<a name="l03265"></a>03265    <span class="keywordtype">double</span> med_on=0;
+<a name="l03266"></a>03266    <span class="keywordtype">double</span> avg_on=0;
+<a name="l03267"></a>03267    <span class="keywordtype">double</span> med_of=0;
+<a name="l03268"></a>03268    <span class="keywordtype">double</span> avg_of=0;
+<a name="l03269"></a>03269    <span class="keywordtype">double</span> med_dit=0;
+<a name="l03270"></a>03270    <span class="keywordtype">double</span> avg_dit=0;
+<a name="l03271"></a>03271 
+<a name="l03272"></a>03272    <span class="keywordtype">double</span> med=0;
+<a name="l03273"></a>03273    <span class="keywordtype">double</span> avg=0;
+<a name="l03274"></a>03274 
+<a name="l03275"></a>03275    <span class="keywordtype">char</span>* name=NULL;
+<a name="l03276"></a>03276    cpl_image* img=NULL;
+<a name="l03277"></a>03277    cpl_vector* vec_adl=NULL;
+<a name="l03278"></a>03278    cpl_vector* vec_dit=NULL;
+<a name="l03279"></a>03279    cpl_vector* vec_avg=NULL;
+<a name="l03280"></a>03280    cpl_vector* vec_med=NULL;
+<a name="l03281"></a>03281    cpl_vector* vec_avg_dit=NULL;
+<a name="l03282"></a>03282    cpl_vector* vec_med_dit=NULL;
+<a name="l03283"></a>03283    cpl_propertylist* plist=NULL;
+<a name="l03284"></a>03284 
+<a name="l03285"></a>03285    <span class="keywordtype">double</span> dit=0;
+<a name="l03286"></a>03286    cpl_table* lin_tbl=NULL;
+<a name="l03287"></a>03287 
+<a name="l03288"></a>03288 
+<a name="l03289"></a>03289    non = cpl_frameset_get_size(son);
+<a name="l03290"></a>03290    nof = cpl_frameset_get_size(sof);
+<a name="l03291"></a>03291    nfr = (non <= nof) ? non : nof;
+<a name="l03292"></a>03292 
+<a name="l03293"></a>03293    lin_tbl=cpl_table_new(nfr);
+<a name="l03294"></a>03294    cpl_table_new_column(lin_tbl,<span class="stringliteral">"med"</span>, CPL_TYPE_DOUBLE);
+<a name="l03295"></a>03295    cpl_table_new_column(lin_tbl,<span class="stringliteral">"avg"</span>, CPL_TYPE_DOUBLE);
+<a name="l03296"></a>03296    cpl_table_new_column(lin_tbl,<span class="stringliteral">"med_dit"</span>, CPL_TYPE_DOUBLE);
+<a name="l03297"></a>03297    cpl_table_new_column(lin_tbl,<span class="stringliteral">"avg_dit"</span>, CPL_TYPE_DOUBLE);
+<a name="l03298"></a>03298    cpl_table_new_column(lin_tbl,<span class="stringliteral">"dit"</span>, CPL_TYPE_DOUBLE);
+<a name="l03299"></a>03299    vec_med=cpl_vector_new(nfr);
+<a name="l03300"></a>03300    vec_avg=cpl_vector_new(nfr);
+<a name="l03301"></a>03301    vec_med_dit=cpl_vector_new(nfr);
+<a name="l03302"></a>03302    vec_avg_dit=cpl_vector_new(nfr);
+<a name="l03303"></a>03303    vec_dit=cpl_vector_new(nfr);
+<a name="l03304"></a>03304    vec_adl=cpl_vector_new(nfr);
+<a name="l03305"></a>03305 
+<a name="l03306"></a>03306    <span class="keywordflow">for</span>(i=0;i<nfr;i++) {
+<a name="l03307"></a>03307       frm=cpl_frameset_get_frame(son,i);
+<a name="l03308"></a>03308       name=(<span class="keywordtype">char</span>*)cpl_frame_get_filename(frm);
+<a name="l03309"></a>03309       img=cpl_image_load(name,CPL_TYPE_FLOAT,0,0);
+<a name="l03310"></a>03310       med_on=cpl_image_get_median(img);
+<a name="l03311"></a>03311       avg_on=cpl_image_get_mean(img);
+<a name="l03312"></a>03312       cpl_image_delete(img);
+<a name="l03313"></a>03313 
+<a name="l03314"></a>03314       frm=cpl_frameset_get_frame(sof,i);
+<a name="l03315"></a>03315       name=(<span class="keywordtype">char</span>*)cpl_frame_get_filename(frm);
+<a name="l03316"></a>03316       img=cpl_image_load(name,CPL_TYPE_FLOAT,0,0);
+<a name="l03317"></a>03317       med_of=cpl_image_get_median(img);
+<a name="l03318"></a>03318       avg_of=cpl_image_get_mean(img);
+<a name="l03319"></a>03319       cpl_image_delete(img);
+<a name="l03320"></a>03320 
+<a name="l03321"></a>03321       med=med_on-med_of;
+<a name="l03322"></a>03322       avg=avg_on-avg_of;
+<a name="l03323"></a>03323       plist=cpl_propertylist_load(name,0);
+<a name="l03324"></a>03324       dit=(double)sinfo_pfits_get_dit(plist);
+<a name="l03325"></a>03325       cpl_propertylist_delete(plist);
+<a name="l03326"></a>03326       avg_dit=avg/dit;
+<a name="l03327"></a>03327       med_dit=med/dit;
+<a name="l03328"></a>03328 
+<a name="l03329"></a>03329       cpl_vector_set(vec_dit,i,dit);
+<a name="l03330"></a>03330       cpl_vector_set(vec_avg,i,avg);
+<a name="l03331"></a>03331       cpl_vector_set(vec_med,i,med);
+<a name="l03332"></a>03332       cpl_vector_set(vec_avg_dit,i,avg_dit);
+<a name="l03333"></a>03333       cpl_vector_set(vec_med_dit,i,med_dit);
+<a name="l03334"></a>03334 
+<a name="l03335"></a>03335       cpl_table_set_double(lin_tbl,<span class="stringliteral">"dit"</span>,i,dit);
+<a name="l03336"></a>03336       cpl_table_set_double(lin_tbl,<span class="stringliteral">"med"</span>,i,med);
+<a name="l03337"></a>03337       cpl_table_set_double(lin_tbl,<span class="stringliteral">"avg"</span>,i,avg);
+<a name="l03338"></a>03338       cpl_table_set_double(lin_tbl,<span class="stringliteral">"med_dit"</span>,i,med_dit);
+<a name="l03339"></a>03339       cpl_table_set_double(lin_tbl,<span class="stringliteral">"avg_dit"</span>,i,avg_dit);
+<a name="l03340"></a>03340 
+<a name="l03341"></a>03341    }
+<a name="l03342"></a>03342    cpl_table_new_column(lin_tbl,<span class="stringliteral">"adl"</span>, CPL_TYPE_DOUBLE);
+<a name="l03343"></a>03343    med_dit=cpl_vector_get_mean(vec_med_dit);
+<a name="l03344"></a>03344    avg_dit=cpl_vector_get_mean(vec_avg_dit);
+<a name="l03345"></a>03345 
+<a name="l03346"></a>03346    <span class="keywordflow">for</span>(i=0;i<nfr;i++) {
+<a name="l03347"></a>03347       dit = cpl_table_get_double(lin_tbl,<span class="stringliteral">"dit"</span>,i,status);
+<a name="l03348"></a>03348       cpl_vector_set(vec_adl,i,dit*med_dit);
+<a name="l03349"></a>03349       cpl_table_set_double(lin_tbl,<span class="stringliteral">"adl"</span>,i,dit*med_dit);
+<a name="l03350"></a>03350    }
+<a name="l03351"></a>03351 
+<a name="l03352"></a>03352    cpl_vector_delete(vec_dit);
+<a name="l03353"></a>03353    cpl_vector_delete(vec_adl);
+<a name="l03354"></a>03354    cpl_vector_delete(vec_avg);
+<a name="l03355"></a>03355    cpl_vector_delete(vec_med);
+<a name="l03356"></a>03356    cpl_vector_delete(vec_avg_dit);
+<a name="l03357"></a>03357    cpl_vector_delete(vec_med_dit);
+<a name="l03358"></a>03358 
+<a name="l03359"></a>03359 
+<a name="l03360"></a>03360    <span class="keywordflow">return</span> lin_tbl;
+<a name="l03361"></a>03361 
+<a name="l03362"></a>03362 }
+<a name="l03363"></a>03363 
+<a name="l03364"></a>03364 <span class="comment">/*--------------------------------------------------------------------*/</span>
+<a name="l03371"></a>03371 <span class="comment">/*--------------------------------------------------------------------*/</span>
+<a name="l03372"></a>03372 <span class="keywordtype">int</span>
+<a name="l03373"></a>03373 sinfo_get_ron(cpl_frameset    *   framelist,
+<a name="l03374"></a>03374               <span class="keyword">const</span> <span class="keywordtype">int</span> ron_xmin,
+<a name="l03375"></a>03375               <span class="keyword">const</span> <span class="keywordtype">int</span> ron_xmax,
+<a name="l03376"></a>03376               <span class="keyword">const</span> <span class="keywordtype">int</span> ron_ymin,
+<a name="l03377"></a>03377               <span class="keyword">const</span> <span class="keywordtype">int</span> ron_ymax,
+<a name="l03378"></a>03378               <span class="keyword">const</span> <span class="keywordtype">int</span> ron_hsize,
+<a name="l03379"></a>03379               <span class="keyword">const</span> <span class="keywordtype">int</span> ron_nsamp,
+<a name="l03380"></a>03380               <span class="keywordtype">double</span>** ron)
+<a name="l03381"></a>03381 {
+<a name="l03382"></a>03382    cpl_imagelist   *   iset =NULL;
+<a name="l03383"></a>03383    cpl_image       *   tmp_im =NULL;
+<a name="l03384"></a>03384    cpl_size                 zone[4] ;
+<a name="l03385"></a>03385    <span class="keywordtype">double</span>              rms  =0;
+<a name="l03386"></a>03386    <span class="keywordtype">double</span>              ndit =0;
+<a name="l03387"></a>03387    cpl_frame       *   frame =NULL;
+<a name="l03388"></a>03388    <span class="keywordtype">int</span>                 i;
+<a name="l03389"></a>03389    cpl_propertylist* plist=NULL;
+<a name="l03390"></a>03390 
+<a name="l03391"></a>03391    <span class="comment">/* Test entries */</span>
+<a name="l03392"></a>03392 
+<a name="l03393"></a>03393    <span class="keywordflow">if</span> (framelist == NULL) <span class="keywordflow">return</span> -1 ;
+<a name="l03394"></a>03394 
+<a name="l03395"></a>03395    <span class="comment">/* Load the current set */</span>
+<a name="l03396"></a>03396    <span class="keywordflow">if</span> ((iset = sinfo_new_frameset_to_iset(framelist)) == NULL) {
+<a name="l03397"></a>03397       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>( <span class="stringliteral">"Cannot load the data"</span>) ;
+<a name="l03398"></a>03398       <span class="keywordflow">return</span> -1 ;
+<a name="l03399"></a>03399    }
+<a name="l03400"></a>03400 
+<a name="l03401"></a>03401    <span class="comment">/* Initialise */</span>
+<a name="l03402"></a>03402    zone[0]=ron_xmin;
+<a name="l03403"></a>03403    zone[1]=ron_xmax;
+<a name="l03404"></a>03404    zone[2]=ron_ymin;
+<a name="l03405"></a>03405    zone[3]=ron_ymax;
+<a name="l03406"></a>03406 
+<a name="l03407"></a>03407    <span class="comment">/* Loop on all pairs */</span>
+<a name="l03408"></a>03408    <span class="keywordflow">for</span> (i=0 ; i<cpl_imagelist_get_size(iset)-1 ; i++) {
+<a name="l03409"></a>03409 
+<a name="l03410"></a>03410       <span class="comment">/* Compute the current subtracted image */</span>
+<a name="l03411"></a>03411       <span class="keywordflow">if</span> ((tmp_im=cpl_image_subtract_create(cpl_imagelist_get(iset,i),
+<a name="l03412"></a>03412                                             cpl_imagelist_get(iset, i+1)))
+<a name="l03413"></a>03413           == NULL) {
+<a name="l03414"></a>03414          <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>( <span class="stringliteral">"Cannot subtract the images"</span>) ;
+<a name="l03415"></a>03415          sinfo_free_imagelist(&iset) ;
+<a name="l03416"></a>03416          <span class="keywordflow">return</span> -1 ;
+<a name="l03417"></a>03417       }
+<a name="l03418"></a>03418 
+<a name="l03419"></a>03419       <span class="comment">/* Compute the read-out noise */</span>
+<a name="l03420"></a>03420       <span class="keywordflow">if</span> (cpl_flux_get_noise_window(tmp_im, zone, ron_hsize,
+<a name="l03421"></a>03421                                     ron_nsamp, &rms, NULL) != CPL_ERROR_NONE) {
+<a name="l03422"></a>03422          <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>( <span class="stringliteral">"Cannot compute the RON"</span>) ;
+<a name="l03423"></a>03423          sinfo_free_image(&tmp_im) ;
+<a name="l03424"></a>03424          sinfo_free_imagelist(&iset) ;
+<a name="l03425"></a>03425          <span class="keywordflow">return</span> -1 ;
+<a name="l03426"></a>03426       }
+<a name="l03427"></a>03427       sinfo_free_image(&tmp_im) ;
+<a name="l03428"></a>03428       <span class="comment">/* Normalise the RON with NDIT */</span>
+<a name="l03429"></a>03429       frame = cpl_frameset_get_frame(framelist, i) ;
+<a name="l03430"></a>03430       cknull_nomsg(plist=cpl_propertylist_load(cpl_frame_get_filename(frame),
+<a name="l03431"></a>03431                                                0));
+<a name="l03432"></a>03432       ndit=sinfo_pfits_get_ndit(plist);
+<a name="l03433"></a>03433       sinfo_free_propertylist(&plist);
+<a name="l03434"></a>03434 
+<a name="l03435"></a>03435       (*ron)[i] = rms * sqrt(ndit/2.0) ;
+<a name="l03436"></a>03436 
+<a name="l03437"></a>03437    }
+<a name="l03438"></a>03438 
+<a name="l03439"></a>03439    <span class="comment">/* Free and return */</span>
+<a name="l03440"></a>03440    sinfo_free_imagelist(&iset) ;
+<a name="l03441"></a>03441    <span class="keywordflow">return</span> 0 ;
+<a name="l03442"></a>03442 
+<a name="l03443"></a>03443   cleanup:
+<a name="l03444"></a>03444    sinfo_free_image(&tmp_im);
+<a name="l03445"></a>03445    sinfo_free_imagelist(&iset);
+<a name="l03446"></a>03446    sinfo_free_propertylist(&plist);
+<a name="l03447"></a>03447    <span class="keywordflow">return</span> -1;
+<a name="l03448"></a>03448 
+<a name="l03449"></a>03449 }
+<a name="l03450"></a>03450 
+<a name="l03451"></a>03451 
+<a name="l03452"></a>03452 
+<a name="l03453"></a>03453 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l03459"></a>03459 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l03460"></a>03460 <span class="keywordtype">int</span> sinfo_stack_get_pro_tag(<span class="keywordtype">char</span> * tag_in, <span class="keywordtype">char</span>* tag_out)
+<a name="l03461"></a>03461 {
+<a name="l03462"></a>03462    <span class="comment">/* Test entries */</span>
+<a name="l03463"></a>03463    <span class="keywordflow">if</span> (tag_in == NULL) <span class="keywordflow">return</span> -1 ;
+<a name="l03464"></a>03464    <span class="comment">/* here for the moment we set the same PRO ID as a non stacked frame */</span>
+<a name="l03465"></a>03465    <span class="keywordflow">if</span> (strcmp(tag_in,RAW_WAVE_LAMP_DITHER) == 0 ) {
+<a name="l03466"></a>03466       strcpy(tag_out,PRO_WAVE_LAMP_STACKED);
+<a name="l03467"></a>03467       <span class="keywordflow">return</span> 0 ;
+<a name="l03468"></a>03468    }
+<a name="l03469"></a>03469 
+<a name="l03470"></a>03470 
+<a name="l03471"></a>03471    <span class="keywordflow">if</span> (strcmp(tag_in,RAW_WAVE_LAMP) == 0 ) {
+<a name="l03472"></a>03472       strcpy(tag_out,PRO_WAVE_LAMP_STACKED);
+<a name="l03473"></a>03473       <span class="keywordflow">return</span> 0 ;
+<a name="l03474"></a>03474    }
+<a name="l03475"></a>03475 
+<a name="l03476"></a>03476    <span class="keywordflow">if</span> (strcmp(tag_in,RAW_WAVE_NS_DITHER) == 0 ) {
+<a name="l03477"></a>03477       strcpy(tag_out,PRO_WAVE_NS_STACKED);
+<a name="l03478"></a>03478       <span class="keywordflow">return</span> 0 ;
+<a name="l03479"></a>03479    }
+<a name="l03480"></a>03480 
+<a name="l03481"></a>03481 
+<a name="l03482"></a>03482    <span class="keywordflow">if</span> (strcmp(tag_in,RAW_WAVE_NS) == 0 ) {
+<a name="l03483"></a>03483       strcpy(tag_out,PRO_WAVE_NS_STACKED);
+<a name="l03484"></a>03484       <span class="keywordflow">return</span> 0 ;
+<a name="l03485"></a>03485    }
+<a name="l03486"></a>03486 
+<a name="l03487"></a>03487 
+<a name="l03488"></a>03488    <span class="keywordflow">if</span> (strcmp(tag_in,RAW_FIBRE_LAMP) == 0 ) {
+<a name="l03489"></a>03489       strcpy(tag_out,PRO_FIBRE_LAMP_STACKED);
+<a name="l03490"></a>03490       <span class="keywordflow">return</span> 0 ;
+<a name="l03491"></a>03491    }
+<a name="l03492"></a>03492 
+<a name="l03493"></a>03493    <span class="keywordflow">if</span> (strcmp(tag_in,RAW_FIBRE_EW) == 0 ) {
+<a name="l03494"></a>03494       strcpy(tag_out,PRO_FIBRE_EW_STACKED);
+<a name="l03495"></a>03495       <span class="keywordflow">return</span> 0 ;
+<a name="l03496"></a>03496    }
+<a name="l03497"></a>03497 
+<a name="l03498"></a>03498    <span class="keywordflow">if</span> (strcmp(tag_in,RAW_FIBRE_NS) == 0 ) {
+<a name="l03499"></a>03499       strcpy(tag_out,PRO_FIBRE_NS_STACKED);
+<a name="l03500"></a>03500       <span class="keywordflow">return</span> 0 ;
+<a name="l03501"></a>03501    }
+<a name="l03502"></a>03502 
+<a name="l03503"></a>03503 
+<a name="l03504"></a>03504    <span class="keywordflow">if</span> (strcmp(tag_in,PRO_FIBRE_NS_STACKED_ON) == 0 ) {
+<a name="l03505"></a>03505       strcpy(tag_out,PRO_FIBRE_NS_STACKED);
+<a name="l03506"></a>03506       <span class="keywordflow">return</span> 0 ;
+<a name="l03507"></a>03507    }
+<a name="l03508"></a>03508 
+<a name="l03509"></a>03509    <span class="keywordflow">if</span> (strcmp(tag_in,PRO_FIBRE_NS_STACKED) == 0 ) {
+<a name="l03510"></a>03510       strcpy(tag_out,PRO_FIBRE_NS_STACKED_DIST);
+<a name="l03511"></a>03511       <span class="keywordflow">return</span> 0 ;
+<a name="l03512"></a>03512    }
+<a name="l03513"></a>03513 
+<a name="l03514"></a>03514 
+<a name="l03515"></a>03515    <span class="keywordflow">if</span> (strcmp(tag_in,RAW_SLIT_LAMP) == 0 ) {
+<a name="l03516"></a>03516       strcpy(tag_out,PRO_SLIT_LAMP_STACKED);
+<a name="l03517"></a>03517       <span class="keywordflow">return</span> 0 ;
+<a name="l03518"></a>03518    }
+<a name="l03519"></a>03519 
+<a name="l03520"></a>03520 
+<a name="l03521"></a>03521    <span class="keywordflow">if</span> (strstr(tag_in, <span class="stringliteral">"FLUX"</span>) != NULL ) {
+<a name="l03522"></a>03522       strcpy(tag_out,PRO_FLUX_LAMP_STACKED);
+<a name="l03523"></a>03523       <span class="keywordflow">return</span> 0 ;
+<a name="l03524"></a>03524    }
+<a name="l03525"></a>03525 
+<a name="l03526"></a>03526    <span class="keywordflow">if</span> (strstr(tag_in, <span class="stringliteral">"PSF"</span>) != NULL ) {
+<a name="l03527"></a>03527       strcpy(tag_out,PRO_PSF_CALIBRATOR_STACKED);
+<a name="l03528"></a>03528       <span class="keywordflow">return</span> 0 ;
+<a name="l03529"></a>03529    }
+<a name="l03530"></a>03530 
+<a name="l03531"></a>03531 
+<a name="l03532"></a>03532    <span class="keywordflow">if</span> (strstr(tag_in, <span class="stringliteral">"FOCUS"</span>) != NULL ) {
+<a name="l03533"></a>03533       strcpy(tag_out,PRO_FOCUS_STACKED);
+<a name="l03534"></a>03534       <span class="keywordflow">return</span> 0 ;
+<a name="l03535"></a>03535    }
+<a name="l03536"></a>03536 
+<a name="l03537"></a>03537    <span class="keywordflow">if</span> (strstr(tag_in, <span class="stringliteral">"OBJECT_NODDING"</span>) != NULL ) {
+<a name="l03538"></a>03538       strcpy(tag_out,PRO_OBJECT_NODDING_STACKED);
+<a name="l03539"></a>03539       <span class="keywordflow">return</span> 0 ;
+<a name="l03540"></a>03540    }
+<a name="l03541"></a>03541 
+<a name="l03542"></a>03542    <span class="keywordflow">if</span> (strstr(tag_in, <span class="stringliteral">"SKY_NODDING"</span>) != NULL ) {
+<a name="l03543"></a>03543       strcpy(tag_out,PRO_SKY_NODDING_STACKED);
+<a name="l03544"></a>03544       <span class="keywordflow">return</span> 0 ;
+<a name="l03545"></a>03545    }
+<a name="l03546"></a>03546 
+<a name="l03547"></a>03547    <span class="keywordflow">if</span> (strstr(tag_in, <span class="stringliteral">"STD_NODDING"</span>) != NULL ) {
+<a name="l03548"></a>03548       strcpy(tag_out,PRO_STD_NODDING_STACKED);
+<a name="l03549"></a>03549       <span class="keywordflow">return</span> 0 ;
+<a name="l03550"></a>03550    }
+<a name="l03551"></a>03551 
+<a name="l03552"></a>03552    <span class="keywordflow">if</span> (strstr(tag_in, <span class="stringliteral">"OBJECT_SKYSPIDER"</span>) != NULL ) {
+<a name="l03553"></a>03553       strcpy(tag_out,PRO_OBJECT_SKYSPIDER_STACKED);
+<a name="l03554"></a>03554       <span class="keywordflow">return</span> 0 ;
+<a name="l03555"></a>03555    }
+<a name="l03556"></a>03556 
+<a name="l03557"></a>03557 
+<a name="l03558"></a>03558    <span class="keywordflow">if</span> (strstr(tag_in, RAW_STD) != NULL ) {
+<a name="l03559"></a>03559       strcpy(tag_out,PRO_STD_STACKED);
+<a name="l03560"></a>03560       <span class="keywordflow">return</span> 0 ;
+<a name="l03561"></a>03561    }
+<a name="l03562"></a>03562 
+<a name="l03563"></a>03563 
+<a name="l03564"></a>03564    <span class="keywordflow">if</span> (strstr(tag_in, RAW_SKY_STD) != NULL ) {
+<a name="l03565"></a>03565       strcpy(tag_out,PRO_SKY_STD_STACKED);
+<a name="l03566"></a>03566       <span class="keywordflow">return</span> 0 ;
+<a name="l03567"></a>03567    }
+<a name="l03568"></a>03568 
+<a name="l03569"></a>03569    <span class="keywordflow">if</span> (strstr(tag_in, RAW_SKY_OH) != NULL ) {
+<a name="l03570"></a>03570       strcpy(tag_out,PRO_SKY_OH_STACKED);
+<a name="l03571"></a>03571       <span class="keywordflow">return</span> 0 ;
+<a name="l03572"></a>03572    }
+<a name="l03573"></a>03573 
+<a name="l03574"></a>03574    <span class="keywordflow">if</span> (strstr(tag_in, RAW_SKY_PSF_CALIBRATOR) != NULL ) {
+<a name="l03575"></a>03575       strcpy(tag_out,PRO_SKY_PSF_CALIBRATOR_STACKED);
+<a name="l03576"></a>03576       <span class="keywordflow">return</span> 0 ;
+<a name="l03577"></a>03577    }
+<a name="l03578"></a>03578 
+<a name="l03579"></a>03579    <span class="keywordflow">if</span> (strstr(tag_in, RAW_STD_STAR) != NULL ) {
+<a name="l03580"></a>03580       strcpy(tag_out,PRO_STD_STAR_STACKED);
+<a name="l03581"></a>03581       <span class="keywordflow">return</span> 0 ;
+<a name="l03582"></a>03582    }
+<a name="l03583"></a>03583 
+<a name="l03584"></a>03584    <span class="keywordflow">if</span> (strstr(tag_in, RAW_STD_STAR) != NULL ) {
+<a name="l03585"></a>03585       strcpy(tag_out,PRO_STD_STAR_DITHER_STACKED);
+<a name="l03586"></a>03586       <span class="keywordflow">return</span> 0 ;
+<a name="l03587"></a>03587    }
+<a name="l03588"></a>03588 
+<a name="l03589"></a>03589    <span class="keywordflow">if</span> (strstr(tag_in, RAW_SKY) != NULL ) {
+<a name="l03590"></a>03590       strcpy(tag_out,PRO_SKY_STACKED);
+<a name="l03591"></a>03591       <span class="keywordflow">return</span> 0 ;
+<a name="l03592"></a>03592    }
+<a name="l03593"></a>03593 
+<a name="l03594"></a>03594 
+<a name="l03595"></a>03595    <span class="keywordflow">return</span> 1 ;
+<a name="l03596"></a>03596 }
+<a name="l03597"></a>03597 
+<a name="l03598"></a>03598 
+<a name="l03599"></a>03599 <span class="keywordtype">int</span> sinfo_is_dark(<span class="keywordtype">char</span> * tag)
+<a name="l03600"></a>03600 {
+<a name="l03601"></a>03601    <span class="comment">/* Test entries */</span>
+<a name="l03602"></a>03602    <span class="keywordflow">if</span> (tag == NULL) <span class="keywordflow">return</span> -1 ;
+<a name="l03603"></a>03603 
+<a name="l03604"></a>03604    <span class="keywordflow">if</span> (!strcmp(tag, RAW_DARK)) <span class="keywordflow">return</span> 1 ;
+<a name="l03605"></a>03605    <span class="keywordflow">if</span> (!strcmp(tag, PRO_MASTER_DARK)) <span class="keywordflow">return</span> 1 ;
+<a name="l03606"></a>03606    <span class="keywordflow">return</span> 0 ;
+<a name="l03607"></a>03607 }
+<a name="l03608"></a>03608 
+<a name="l03609"></a>03609 <span class="keywordtype">int</span> sinfo_is_flat_bp(<span class="keywordtype">char</span> * tag)
+<a name="l03610"></a>03610 {
+<a name="l03611"></a>03611    <span class="comment">/* Test entries */</span>
+<a name="l03612"></a>03612    <span class="keywordflow">if</span> (tag == NULL) <span class="keywordflow">return</span> -1 ;
+<a name="l03613"></a>03613 
+<a name="l03614"></a>03614    <span class="keywordflow">if</span> (!strcmp(tag, RAW_LINEARITY_LAMP)) <span class="keywordflow">return</span> 1 ;
+<a name="l03615"></a>03615    <span class="keywordflow">return</span> 0 ;
+<a name="l03616"></a>03616 }
+<a name="l03617"></a>03617 
+<a name="l03618"></a>03618 <span class="keywordtype">int</span> sinfo_is_flat_lindet(<span class="keywordtype">char</span> * tag)
+<a name="l03619"></a>03619 {
+<a name="l03620"></a>03620    <span class="comment">/* Test entries */</span>
+<a name="l03621"></a>03621    <span class="keywordflow">if</span> (tag == NULL) <span class="keywordflow">return</span> -1 ;
+<a name="l03622"></a>03622 
+<a name="l03623"></a>03623    <span class="keywordflow">if</span> (!strcmp(tag, RAW_LINEARITY_LAMP)) <span class="keywordflow">return</span> 1 ;
+<a name="l03624"></a>03624    <span class="keywordflow">return</span> 0 ;
+<a name="l03625"></a>03625 }
+<a name="l03626"></a>03626 
+<a name="l03627"></a>03627 
+<a name="l03628"></a>03628 <span class="keywordtype">int</span> sinfo_blank2dot(<span class="keyword">const</span> <span class="keywordtype">char</span> * in, <span class="keywordtype">char</span>* ou)
+<a name="l03629"></a>03629 {
+<a name="l03630"></a>03630    <span class="keywordtype">int</span> len=0;
+<a name="l03631"></a>03631    <span class="keywordtype">int</span> i=0;
+<a name="l03632"></a>03632 
+<a name="l03633"></a>03633    strcpy(ou,in);
+<a name="l03634"></a>03634    len = strlen(in);
+<a name="l03635"></a>03635    <span class="keywordflow">for</span> (i=0;i<len;i++)
+<a name="l03636"></a>03636    {
+<a name="l03637"></a>03637       <span class="keywordflow">if</span> (in[i] == <span class="charliteral">' '</span>) {
+<a name="l03638"></a>03638          ou[i] =  <span class="charliteral">'.'</span>;
+<a name="l03639"></a>03639       }
+<a name="l03640"></a>03640    }
+<a name="l03641"></a>03641    <span class="keywordflow">return</span> 0;
+<a name="l03642"></a>03642 }
+<a name="l03643"></a>03643 
+<a name="l03644"></a>03644 
+<a name="l03645"></a>03645 <span class="keywordtype">int</span> sinfo_is_sky_flat(<span class="keywordtype">char</span> * tag)
+<a name="l03646"></a>03646 {
+<a name="l03647"></a>03647    <span class="comment">/* Test entries */</span>
+<a name="l03648"></a>03648    <span class="keywordflow">if</span> (tag == NULL) <span class="keywordflow">return</span> -1 ;
+<a name="l03649"></a>03649    <span class="keywordflow">if</span> (!strcmp(tag, RAW_FLAT_SKY)) <span class="keywordflow">return</span> 1 ;
+<a name="l03650"></a>03650    <span class="keywordflow">return</span> 0 ;
+<a name="l03651"></a>03651 }
+<a name="l03652"></a>03652 
+<a name="l03653"></a>03653 
+<a name="l03654"></a>03654 
+<a name="l03655"></a>03655 <span class="keywordtype">int</span> sinfo_is_master_flat(<span class="keywordtype">char</span> * tag)
+<a name="l03656"></a>03656 {
+<a name="l03657"></a>03657    <span class="comment">/* Test entries */</span>
+<a name="l03658"></a>03658    <span class="keywordflow">if</span> (tag == NULL) <span class="keywordflow">return</span> -1 ;
+<a name="l03659"></a>03659 
+<a name="l03660"></a>03660    <span class="keywordflow">if</span> (!strcmp(tag, PRO_MASTER_FLAT_LAMP)) <span class="keywordflow">return</span> 1 ;
+<a name="l03661"></a>03661    <span class="keywordflow">if</span> (!strcmp(tag, PRO_MASTER_FLAT_LAMP1)) <span class="keywordflow">return</span> 1 ;
+<a name="l03662"></a>03662    <span class="keywordflow">return</span> 0 ;
+<a name="l03663"></a>03663 }
+<a name="l03664"></a>03664 
+<a name="l03665"></a>03665 <span class="keywordtype">int</span> sinfo_is_master_flat_dither(<span class="keywordtype">char</span> * tag)
+<a name="l03666"></a>03666 {
+<a name="l03667"></a>03667    <span class="comment">/* Test entries */</span>
+<a name="l03668"></a>03668    <span class="keywordflow">if</span> (tag == NULL) <span class="keywordflow">return</span> -1 ;
+<a name="l03669"></a>03669 
+<a name="l03670"></a>03670    <span class="keywordflow">if</span> (!strcmp(tag, PRO_MASTER_FLAT_LAMP2)) <span class="keywordflow">return</span> 1 ;
+<a name="l03671"></a>03671    <span class="keywordflow">return</span> 0 ;
+<a name="l03672"></a>03672 }
+<a name="l03673"></a>03673 
+<a name="l03674"></a>03674 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l03680"></a>03680 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l03681"></a>03681 <span class="keywordtype">int</span> sinfo_is_stack(<span class="keywordtype">char</span> * tag)
+<a name="l03682"></a>03682 {
+<a name="l03683"></a>03683    <span class="comment">/* Test entries */</span>
+<a name="l03684"></a>03684    <span class="keywordflow">if</span> (tag == NULL) <span class="keywordflow">return</span> -1 ;
+<a name="l03685"></a>03685 
+<a name="l03686"></a>03686    <span class="keywordflow">if</span> (strstr(tag, PRO_STACKED) != NULL) <span class="keywordflow">return</span> 1 ;
+<a name="l03687"></a>03687    <span class="keywordflow">return</span> 0 ;
+<a name="l03688"></a>03688 }
+<a name="l03689"></a>03689 
+<a name="l03690"></a>03690 <span class="keywordtype">int</span> sinfo_is_mflat(<span class="keywordtype">char</span> * tag)
+<a name="l03691"></a>03691 {
+<a name="l03692"></a>03692    <span class="comment">/* Test entries */</span>
+<a name="l03693"></a>03693    <span class="keywordflow">if</span> (tag == NULL) <span class="keywordflow">return</span> -1 ;
+<a name="l03694"></a>03694 
+<a name="l03695"></a>03695    <span class="keywordflow">if</span> (!strcmp(tag, PRO_MASTER_FLAT_LAMP)) <span class="keywordflow">return</span> 1 ;
+<a name="l03696"></a>03696    <span class="keywordflow">if</span> (!strcmp(tag, PRO_MASTER_FLAT_LAMP1)) <span class="keywordflow">return</span> 1 ;
+<a name="l03697"></a>03697    <span class="keywordflow">if</span> (!strcmp(tag, PRO_MASTER_FLAT_LAMP2)) <span class="keywordflow">return</span> 1 ;
+<a name="l03698"></a>03698    <span class="keywordflow">return</span> 0 ;
+<a name="l03699"></a>03699 }
+<a name="l03700"></a>03700 
+<a name="l03701"></a>03701 
+<a name="l03702"></a>03702 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l03708"></a>03708 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l03709"></a>03709 <span class="keywordtype">int</span> sinfo_is_psf_calibrator_stacked(<span class="keywordtype">char</span> * tag)
+<a name="l03710"></a>03710 {
+<a name="l03711"></a>03711    <span class="comment">/* Test entries */</span>
+<a name="l03712"></a>03712    <span class="keywordflow">if</span> (tag == NULL) <span class="keywordflow">return</span> -1 ;
+<a name="l03713"></a>03713 
+<a name="l03714"></a>03714    <span class="keywordflow">if</span> (!strcmp(tag, PRO_PSF_CALIBRATOR_STACKED)) <span class="keywordflow">return</span> 1 ;
+<a name="l03715"></a>03715    <span class="keywordflow">return</span> 0 ;
+<a name="l03716"></a>03716 }
+<a name="l03717"></a>03717 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l03723"></a>03723 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l03724"></a>03724 <span class="keywordtype">int</span> sinfo_is_focus_stacked(<span class="keywordtype">char</span> * tag)
+<a name="l03725"></a>03725 {
+<a name="l03726"></a>03726    <span class="comment">/* Test entries */</span>
+<a name="l03727"></a>03727    <span class="keywordflow">if</span> (tag == NULL) <span class="keywordflow">return</span> -1 ;
+<a name="l03728"></a>03728 
+<a name="l03729"></a>03729    <span class="keywordflow">if</span> (!strcmp(tag, PRO_FOCUS_STACKED)) <span class="keywordflow">return</span> 1 ;
+<a name="l03730"></a>03730    <span class="keywordflow">return</span> 0 ;
+<a name="l03731"></a>03731 }
+<a name="l03732"></a>03732 
+<a name="l03733"></a>03733 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l03739"></a>03739 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l03740"></a>03740 <span class="keywordtype">int</span> sinfo_is_lamp_wave_stacked(<span class="keywordtype">char</span> * tag)
+<a name="l03741"></a>03741 {
+<a name="l03742"></a>03742    <span class="comment">/* Test entries */</span>
+<a name="l03743"></a>03743    <span class="keywordflow">if</span> (tag == NULL) <span class="keywordflow">return</span> -1 ;
+<a name="l03744"></a>03744 
+<a name="l03745"></a>03745    <span class="keywordflow">if</span> (!strcmp(tag, PRO_WAVE_LAMP_STACKED)) <span class="keywordflow">return</span> 1 ;
+<a name="l03746"></a>03746    <span class="keywordflow">return</span> 0 ;
+<a name="l03747"></a>03747 }
+<a name="l03748"></a>03748 
+<a name="l03749"></a>03749 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l03755"></a>03755 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l03756"></a>03756 <span class="keywordtype">int</span> sinfo_is_lamp_flux_stacked(<span class="keywordtype">char</span> * tag)
+<a name="l03757"></a>03757 {
+<a name="l03758"></a>03758    <span class="comment">/* Test entries */</span>
+<a name="l03759"></a>03759    <span class="keywordflow">if</span> (tag == NULL) <span class="keywordflow">return</span> -1 ;
+<a name="l03760"></a>03760 
+<a name="l03761"></a>03761    <span class="keywordflow">if</span> (!strcmp(tag, PRO_FLUX_LAMP_STACKED)) <span class="keywordflow">return</span> 1 ;
+<a name="l03762"></a>03762    <span class="keywordflow">return</span> 0 ;
+<a name="l03763"></a>03763 }
+<a name="l03764"></a>03764 
+<a name="l03765"></a>03765 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l03771"></a>03771 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l03772"></a>03772 <span class="keywordtype">int</span> sinfo_is_object_nodding_stacked(<span class="keywordtype">char</span> * tag)
+<a name="l03773"></a>03773 {
+<a name="l03774"></a>03774    <span class="comment">/* Test entries */</span>
+<a name="l03775"></a>03775    <span class="keywordflow">if</span> (tag == NULL) <span class="keywordflow">return</span> -1 ;
+<a name="l03776"></a>03776 
+<a name="l03777"></a>03777    <span class="keywordflow">if</span> (!strcmp(tag, PRO_OBJECT_NODDING_STACKED)) <span class="keywordflow">return</span> 1 ;
+<a name="l03778"></a>03778    <span class="keywordflow">return</span> 0 ;
+<a name="l03779"></a>03779 }
+<a name="l03780"></a>03780 
+<a name="l03781"></a>03781 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l03787"></a>03787 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l03788"></a>03788 <span class="keywordtype">int</span> sinfo_is_object_skyspider_stacked(<span class="keywordtype">char</span> * tag)
+<a name="l03789"></a>03789 {
+<a name="l03790"></a>03790    <span class="comment">/* Test entries */</span>
+<a name="l03791"></a>03791    <span class="keywordflow">if</span> (tag == NULL) <span class="keywordflow">return</span> -1 ;
+<a name="l03792"></a>03792 
+<a name="l03793"></a>03793    <span class="keywordflow">if</span> (!strcmp(tag, PRO_OBJECT_SKYSPIDER_STACKED)) <span class="keywordflow">return</span> 1 ;
+<a name="l03794"></a>03794    <span class="keywordflow">return</span> 0 ;
+<a name="l03795"></a>03795 }
+<a name="l03796"></a>03796 
+<a name="l03797"></a>03797 
+<a name="l03798"></a>03798 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l03804"></a>03804 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l03805"></a>03805 <span class="keywordtype">int</span> sinfo_is_sky_nodding_stacked(<span class="keywordtype">char</span> * tag)
+<a name="l03806"></a>03806 {
+<a name="l03807"></a>03807    <span class="comment">/* Test entries */</span>
+<a name="l03808"></a>03808    <span class="keywordflow">if</span> (tag == NULL) <span class="keywordflow">return</span> -1 ;
+<a name="l03809"></a>03809 
+<a name="l03810"></a>03810    <span class="keywordflow">if</span> (!strcmp(tag, PRO_SKY_NODDING_STACKED)) <span class="keywordflow">return</span> 1 ;
+<a name="l03811"></a>03811    <span class="keywordflow">return</span> 0 ;
+<a name="l03812"></a>03812 }
+<a name="l03813"></a>03813 
+<a name="l03814"></a>03814 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l03820"></a>03820 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l03821"></a>03821 <span class="keywordtype">int</span> sinfo_is_wavemap(<span class="keywordtype">char</span> * tag)
+<a name="l03822"></a>03822 {
+<a name="l03823"></a>03823    <span class="comment">/* Test entries */</span>
+<a name="l03824"></a>03824    <span class="keywordflow">if</span> (tag == NULL) <span class="keywordflow">return</span> -1 ;
+<a name="l03825"></a>03825 
+<a name="l03826"></a>03826    <span class="keywordflow">if</span> (!strcmp(tag, PRO_WAVE_MAP)) <span class="keywordflow">return</span> 1 ;
+<a name="l03827"></a>03827    <span class="keywordflow">return</span> 0 ;
+<a name="l03828"></a>03828 }
+<a name="l03829"></a>03829 
+<a name="l03830"></a>03830 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l03836"></a>03836 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l03837"></a>03837 <span class="keywordtype">int</span> sinfo_is_halosp(<span class="keywordtype">char</span> * tag)
+<a name="l03838"></a>03838 {
+<a name="l03839"></a>03839    <span class="comment">/* Test entries */</span>
+<a name="l03840"></a>03840    <span class="keywordflow">if</span> (tag == NULL) <span class="keywordflow">return</span> -1 ;
+<a name="l03841"></a>03841 
+<a name="l03842"></a>03842    <span class="keywordflow">if</span> (!strcmp(tag, PRO_HALO_SPECT)) <span class="keywordflow">return</span> 1 ;
+<a name="l03843"></a>03843    <span class="keywordflow">return</span> 0 ;
+<a name="l03844"></a>03844 }
+<a name="l03845"></a>03845 
+<a name="l03846"></a>03846 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l03852"></a>03852 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l03853"></a>03853 <span class="keywordtype">int</span> sinfo_is_distlist(<span class="keywordtype">char</span> * tag)
+<a name="l03854"></a>03854 {
+<a name="l03855"></a>03855    <span class="comment">/* Test entries */</span>
+<a name="l03856"></a>03856    <span class="keywordflow">if</span> (tag == NULL) <span class="keywordflow">return</span> -1 ;
+<a name="l03857"></a>03857 
+<a name="l03858"></a>03858    <span class="keywordflow">if</span> (!strcmp(tag, PRO_SLITLETS_DISTANCE)) <span class="keywordflow">return</span> 1 ;
+<a name="l03859"></a>03859    <span class="keywordflow">return</span> 0 ;
+<a name="l03860"></a>03860 }
+<a name="l03861"></a>03861 
+<a name="l03862"></a>03862 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l03868"></a>03868 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l03869"></a>03869 <span class="keywordtype">int</span> sinfo_is_slitpos(<span class="keywordtype">char</span> * tag)
+<a name="l03870"></a>03870 {
+<a name="l03871"></a>03871    <span class="comment">/* Test entries */</span>
+<a name="l03872"></a>03872    <span class="keywordflow">if</span> (tag == NULL) <span class="keywordflow">return</span> -1 ;
+<a name="l03873"></a>03873 
+<a name="l03874"></a>03874    <span class="keywordflow">if</span> (!strcmp(tag, PRO_SLIT_POS)) <span class="keywordflow">return</span> 1 ;
+<a name="l03875"></a>03875    <span class="keywordflow">return</span> 0 ;
+<a name="l03876"></a>03876 }
+<a name="l03877"></a>03877 
+<a name="l03878"></a>03878 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l03884"></a>03884 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l03885"></a>03885 <span class="keywordtype">int</span> sinfo_is_firstcol(<span class="keywordtype">char</span> * tag)
+<a name="l03886"></a>03886 {
+<a name="l03887"></a>03887    <span class="comment">/* Test entries */</span>
+<a name="l03888"></a>03888    <span class="keywordflow">if</span> (tag == NULL) <span class="keywordflow">return</span> -1 ;
+<a name="l03889"></a>03889 
+<a name="l03890"></a>03890    <span class="keywordflow">if</span> (!strcmp(tag, PRO_FIRST_COL)) <span class="keywordflow">return</span> 1 ;
+<a name="l03891"></a>03891    <span class="keywordflow">return</span> 0 ;
+<a name="l03892"></a>03892 }
+<a name="l03893"></a>03893 
+<a name="l03894"></a>03894 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l03900"></a>03900 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l03901"></a>03901 <span class="keywordtype">int</span> sinfo_is_bpmap(<span class="keywordtype">char</span> * tag)
+<a name="l03902"></a>03902 {
+<a name="l03903"></a>03903    <span class="comment">/* Test entries */</span>
+<a name="l03904"></a>03904    <span class="keywordflow">if</span> (tag == NULL) <span class="keywordflow">return</span> -1 ;
+<a name="l03905"></a>03905 
+<a name="l03906"></a>03906    <span class="keywordflow">if</span> (!strcmp(tag, PRO_BP_MAP)) <span class="keywordflow">return</span> 1 ;
+<a name="l03907"></a>03907    <span class="keywordflow">return</span> 0 ;
+<a name="l03908"></a>03908 }
+<a name="l03909"></a>03909 
+<a name="l03910"></a>03910 
+<a name="l03911"></a>03911 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l03920"></a>03920 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l03921"></a>03921 
+<a name="l03922"></a>03922 <span class="keywordtype">int</span> sinfo_get_band(cpl_frame * ref_frame,<span class="keywordtype">char</span> * band)
+<a name="l03923"></a>03923 {
+<a name="l03924"></a>03924 
+<a name="l03925"></a>03925    <span class="keywordtype">char</span>* ref_file=NULL;
+<a name="l03926"></a>03926    cpl_propertylist* plist=NULL;
+<a name="l03927"></a>03927 
+<a name="l03928"></a>03928    ref_file = cpl_strdup(cpl_frame_get_filename(ref_frame)) ;
+<a name="l03929"></a>03929    <span class="keywordflow">if</span> ((cpl_error_code)((plist = cpl_propertylist_load(ref_file, 0)) == NULL)) {
+<a name="l03930"></a>03930       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>( <span class="stringliteral">"getting header from reference frame %s"</span>,ref_file);
+<a name="l03931"></a>03931       cpl_propertylist_delete(plist) ;
+<a name="l03932"></a>03932       <span class="keywordflow">return</span> -1 ;
+<a name="l03933"></a>03933    }
+<a name="l03934"></a>03934 
+<a name="l03935"></a>03935    <span class="keywordflow">if</span> (sinfo_propertylist_has(plist, KEY_NAME_FILT_NAME)) {
+<a name="l03936"></a>03936       strcpy(band, cpl_propertylist_get_string(plist, KEY_NAME_FILT_NAME));
+<a name="l03937"></a>03937       <span class="comment">/* sinfo_msg("%s value is %s", KEY_NAME_FILT_NAME, band); */</span>
+<a name="l03938"></a>03938 
+<a name="l03939"></a>03939    } <span class="keywordflow">else</span> {
+<a name="l03940"></a>03940       <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"keyword %s does not exist"</span>,KEY_NAME_FILT_NAME);
+<a name="l03941"></a>03941       <span class="keywordflow">return</span> -1;
+<a name="l03942"></a>03942    }
+<a name="l03943"></a>03943 
+<a name="l03944"></a>03944    cpl_free(ref_file);
+<a name="l03945"></a>03945    cpl_propertylist_delete(plist);
+<a name="l03946"></a>03946    <span class="keywordflow">return</span> 0;
+<a name="l03947"></a>03947 }
+<a name="l03948"></a>03948 
+<a name="l03949"></a>03949 
+<a name="l03950"></a>03950 
+<a name="l03951"></a>03951 
+<a name="l03952"></a>03952 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l03960"></a>03960 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l03961"></a>03961 
+<a name="l03962"></a>03962 <span class="keywordtype">int</span> sinfo_get_obsname(cpl_frame * ref_frame, <span class="keyword">const</span> <span class="keywordtype">char</span>* obs_name)
+<a name="l03963"></a>03963 {
+<a name="l03964"></a>03964 
+<a name="l03965"></a>03965    <span class="keywordtype">char</span>* ref_file=NULL;
+<a name="l03966"></a>03966    cpl_propertylist* plist=NULL;
+<a name="l03967"></a>03967 
+<a name="l03968"></a>03968    ref_file = cpl_strdup(cpl_frame_get_filename(ref_frame)) ;
+<a name="l03969"></a>03969    <span class="keywordflow">if</span> ((cpl_error_code)((plist = cpl_propertylist_load(ref_file, 0)) == NULL)) {
+<a name="l03970"></a>03970       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>( <span class="stringliteral">"getting header from reference frame %s"</span>,ref_file);
+<a name="l03971"></a>03971       cpl_propertylist_delete(plist) ;
+<a name="l03972"></a>03972       <span class="keywordflow">return</span> -1 ;
+<a name="l03973"></a>03973    }
+<a name="l03974"></a>03974 
+<a name="l03975"></a>03975    <span class="keywordflow">if</span> (sinfo_propertylist_has(plist, KEY_NAME_OBS_NAME)) {
+<a name="l03976"></a>03976       strcpy((<span class="keywordtype">char</span>*)obs_name, cpl_propertylist_get_string(plist,
+<a name="l03977"></a>03977                                                           KEY_NAME_OBS_NAME));
+<a name="l03978"></a>03978       <span class="comment">/* sinfo_msg("%s value is %s", KEY_NAME_OBS_NAME, obs_name); */</span>
+<a name="l03979"></a>03979 
+<a name="l03980"></a>03980    } <span class="keywordflow">else</span> {
+<a name="l03981"></a>03981       <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"keyword %s does not exist"</span>,KEY_NAME_OBS_NAME);
+<a name="l03982"></a>03982       <span class="keywordflow">return</span> -1;
+<a name="l03983"></a>03983    }
+<a name="l03984"></a>03984 
+<a name="l03985"></a>03985    cpl_free(ref_file);
+<a name="l03986"></a>03986    cpl_propertylist_delete(plist);
+<a name="l03987"></a>03987    <span class="keywordflow">return</span> 0;
+<a name="l03988"></a>03988 }
+<a name="l03989"></a>03989 
+<a name="l03990"></a>03990 
+<a name="l03991"></a>03991 
+<a name="l03992"></a>03992 
+<a name="l03993"></a>03993 
+<a name="l03994"></a>03994 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l04002"></a>04002 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l04003"></a>04003 
+<a name="l04004"></a>04004 <span class="keywordtype">int</span> sinfo_get_keyvalue_int(cpl_frame * ref_frame, <span class="keyword">const</span> <span class="keywordtype">char</span>* key_name)
+<a name="l04005"></a>04005 {
+<a name="l04006"></a>04006 
+<a name="l04007"></a>04007    <span class="keywordtype">char</span>* ref_file=NULL;
+<a name="l04008"></a>04008    cpl_propertylist* plist=NULL;
+<a name="l04009"></a>04009    <span class="keywordtype">int</span> result=0;
+<a name="l04010"></a>04010 
+<a name="l04011"></a>04011    ref_file = cpl_strdup(cpl_frame_get_filename(ref_frame)) ;
+<a name="l04012"></a>04012 
+<a name="l04013"></a>04013    <span class="keywordflow">if</span> ((cpl_error_code)((plist = cpl_propertylist_load(ref_file, 0)) == NULL)) {
+<a name="l04014"></a>04014       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>( <span class="stringliteral">"getting header from reference frame %s"</span>,ref_file);
+<a name="l04015"></a>04015       cpl_propertylist_delete(plist) ;
+<a name="l04016"></a>04016       <span class="keywordflow">return</span> -1;
+<a name="l04017"></a>04017    }
+<a name="l04018"></a>04018 
+<a name="l04019"></a>04019 
+<a name="l04020"></a>04020    <span class="keywordflow">if</span> (sinfo_propertylist_has(plist, key_name)) {
+<a name="l04021"></a>04021       result=cpl_propertylist_get_int(plist,key_name);
+<a name="l04022"></a>04022    } <span class="keywordflow">else</span> {
+<a name="l04023"></a>04023       <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"keyword %s does not exist"</span>,key_name);
+<a name="l04024"></a>04024       <span class="keywordflow">return</span> -1;
+<a name="l04025"></a>04025    }
+<a name="l04026"></a>04026 
+<a name="l04027"></a>04027    cpl_free(ref_file);
+<a name="l04028"></a>04028    cpl_propertylist_delete(plist);
+<a name="l04029"></a>04029 
+<a name="l04030"></a>04030    <span class="keywordflow">return</span> result;
+<a name="l04031"></a>04031 }
+<a name="l04032"></a>04032 
+<a name="l04033"></a>04033 
+<a name="l04034"></a>04034 
+<a name="l04035"></a>04035 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l04043"></a>04043 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l04044"></a>04044 
+<a name="l04045"></a>04045 <span class="keywordtype">float</span> sinfo_get_keyvalue_float(cpl_frame * ref_frame, <span class="keyword">const</span> <span class="keywordtype">char</span>* key_name)
+<a name="l04046"></a>04046 {
+<a name="l04047"></a>04047 
+<a name="l04048"></a>04048    <span class="keywordtype">char</span>* ref_file=NULL;
+<a name="l04049"></a>04049    cpl_propertylist* plist=NULL;
+<a name="l04050"></a>04050    <span class="keywordtype">float</span> result=0;
+<a name="l04051"></a>04051 
+<a name="l04052"></a>04052    ref_file = cpl_strdup(cpl_frame_get_filename(ref_frame)) ;
+<a name="l04053"></a>04053 
+<a name="l04054"></a>04054    <span class="keywordflow">if</span> ((cpl_error_code)((plist = cpl_propertylist_load(ref_file, 0)) == NULL)) {
+<a name="l04055"></a>04055       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>( <span class="stringliteral">"getting header from reference frame %s"</span>,ref_file);
+<a name="l04056"></a>04056       cpl_propertylist_delete(plist) ;
+<a name="l04057"></a>04057       <span class="keywordflow">return</span> -1;
+<a name="l04058"></a>04058    }
+<a name="l04059"></a>04059 
+<a name="l04060"></a>04060 
+<a name="l04061"></a>04061    <span class="keywordflow">if</span> (sinfo_propertylist_has(plist, key_name)) {
+<a name="l04062"></a>04062       result=cpl_propertylist_get_float(plist,key_name);
+<a name="l04063"></a>04063    } <span class="keywordflow">else</span> {
+<a name="l04064"></a>04064       <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"keyword %s does not exist"</span>,key_name);
+<a name="l04065"></a>04065       <span class="keywordflow">return</span> -1;
+<a name="l04066"></a>04066    }
+<a name="l04067"></a>04067 
+<a name="l04068"></a>04068    cpl_free(ref_file);
+<a name="l04069"></a>04069    cpl_propertylist_delete(plist);
+<a name="l04070"></a>04070 
+<a name="l04071"></a>04071    <span class="keywordflow">return</span> result;
+<a name="l04072"></a>04072 }
+<a name="l04073"></a>04073 
+<a name="l04074"></a>04074 
+<a name="l04075"></a>04075 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l04083"></a>04083 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l04084"></a>04084 
+<a name="l04085"></a>04085 <span class="keywordtype">char</span> sinfo_get_keyvalue_bool(cpl_frame * ref_frame, <span class="keyword">const</span> <span class="keywordtype">char</span>* key_name)
+<a name="l04086"></a>04086 {
+<a name="l04087"></a>04087 
+<a name="l04088"></a>04088    <span class="keywordtype">char</span>* ref_file=NULL;
+<a name="l04089"></a>04089    cpl_propertylist* plist=NULL;
+<a name="l04090"></a>04090    <span class="keywordtype">int</span> res_val=0;
+<a name="l04091"></a>04091 
+<a name="l04092"></a>04092    ref_file = cpl_strdup(cpl_frame_get_filename(ref_frame)) ;
+<a name="l04093"></a>04093 
+<a name="l04094"></a>04094    <span class="keywordflow">if</span> ((cpl_error_code)((plist = cpl_propertylist_load(ref_file, 0)) == NULL)) {
+<a name="l04095"></a>04095       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>( <span class="stringliteral">"getting header from reference frame %s"</span>,ref_file);
+<a name="l04096"></a>04096       cpl_propertylist_delete(plist) ;
+<a name="l04097"></a>04097       <span class="keywordflow">return</span> <span class="charliteral">'0'</span>;
+<a name="l04098"></a>04098    }
+<a name="l04099"></a>04099 
+<a name="l04100"></a>04100 
+<a name="l04101"></a>04101    <span class="keywordflow">if</span> (sinfo_propertylist_has(plist, key_name)) {
+<a name="l04102"></a>04102       res_val=cpl_propertylist_get_bool(plist,key_name);
+<a name="l04103"></a>04103    } <span class="keywordflow">else</span> {
+<a name="l04104"></a>04104       <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"keyword %s does not exist"</span>,key_name);
+<a name="l04105"></a>04105       <span class="keywordflow">return</span> <span class="charliteral">'0'</span>;
+<a name="l04106"></a>04106    }
+<a name="l04107"></a>04107 
+<a name="l04108"></a>04108    cpl_free(ref_file);
+<a name="l04109"></a>04109    cpl_propertylist_delete(plist);
+<a name="l04110"></a>04110    <span class="keywordflow">if</span>(res_val == 1) {
+<a name="l04111"></a>04111       <span class="keywordflow">return</span> <span class="charliteral">'T'</span>;
+<a name="l04112"></a>04112    } <span class="keywordflow">else</span> {
+<a name="l04113"></a>04113       <span class="keywordflow">return</span> <span class="charliteral">'F'</span>;
+<a name="l04114"></a>04114    }
+<a name="l04115"></a>04115 }
+<a name="l04116"></a>04116 
+<a name="l04117"></a>04117 
+<a name="l04118"></a>04118 
+<a name="l04119"></a>04119 
+<a name="l04120"></a>04120 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l04128"></a>04128 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l04129"></a>04129 
+<a name="l04130"></a>04130 <span class="keyword">const</span> <span class="keywordtype">char</span>*
+<a name="l04131"></a>04131 sinfo_get_keyvalue_string(cpl_frame * ref_frame, <span class="keyword">const</span> <span class="keywordtype">char</span>* key_name)
+<a name="l04132"></a>04132 {
+<a name="l04133"></a>04133 
+<a name="l04134"></a>04134    <span class="keywordtype">char</span>* ref_file=NULL;
+<a name="l04135"></a>04135    cpl_propertylist* plist=NULL;
+<a name="l04136"></a>04136    <span class="keyword">const</span> <span class="keywordtype">char</span>* result=NULL;
+<a name="l04137"></a>04137 
+<a name="l04138"></a>04138    ref_file = cpl_strdup(cpl_frame_get_filename(ref_frame)) ;
+<a name="l04139"></a>04139 
+<a name="l04140"></a>04140    <span class="keywordflow">if</span> ((cpl_error_code)((plist = cpl_propertylist_load(ref_file, 0)) == NULL)) {
+<a name="l04141"></a>04141       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>( <span class="stringliteral">"getting header from reference frame %s"</span>,ref_file);
+<a name="l04142"></a>04142       cpl_propertylist_delete(plist) ;
+<a name="l04143"></a>04143       <span class="keywordflow">return</span> FALSE;
+<a name="l04144"></a>04144    }
+<a name="l04145"></a>04145 
+<a name="l04146"></a>04146 
+<a name="l04147"></a>04147    <span class="keywordflow">if</span> (sinfo_propertylist_has(plist, key_name)) {
+<a name="l04148"></a>04148       result=cpl_propertylist_get_string(plist,key_name);
+<a name="l04149"></a>04149    } <span class="keywordflow">else</span> {
+<a name="l04150"></a>04150       <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"keyword %s does not exist"</span>,key_name);
+<a name="l04151"></a>04151       <span class="keywordflow">return</span> NULL;
+<a name="l04152"></a>04152    }
+<a name="l04153"></a>04153 
+<a name="l04154"></a>04154    cpl_free(ref_file);
+<a name="l04155"></a>04155    cpl_propertylist_delete(plist);
+<a name="l04156"></a>04156 
+<a name="l04157"></a>04157    <span class="keywordflow">return</span> result;
+<a name="l04158"></a>04158 }
+<a name="l04159"></a>04159 
+<a name="l04160"></a>04160 
+<a name="l04161"></a>04161 
+<a name="l04162"></a>04162 <span class="keywordtype">double</span> sinfo_get_mjd_obs(cpl_frame * frame)
+<a name="l04163"></a>04163 {
+<a name="l04164"></a>04164    cpl_propertylist* plist=NULL;
+<a name="l04165"></a>04165    <span class="keyword">const</span> <span class="keywordtype">char</span>* file=NULL;
+<a name="l04166"></a>04166 
+<a name="l04167"></a>04167    <span class="keywordtype">double</span> mjd_obs=0.;
+<a name="l04168"></a>04168    file = cpl_frame_get_filename(frame) ;
+<a name="l04169"></a>04169 
+<a name="l04170"></a>04170    <span class="keywordflow">if</span> ((cpl_error_code)((plist = cpl_propertylist_load(file, 0)) == NULL)) {
+<a name="l04171"></a>04171       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>( <span class="stringliteral">"getting header from reference frame %s"</span>,file);
+<a name="l04172"></a>04172       sinfo_free_propertylist(&plist) ;
+<a name="l04173"></a>04173       <span class="keywordflow">return</span> -1 ;
+<a name="l04174"></a>04174    }
+<a name="l04175"></a>04175 
+<a name="l04176"></a>04176    <span class="keywordflow">if</span> (sinfo_propertylist_has(plist, KEY_NAME_MJD_OBS)) {
+<a name="l04177"></a>04177       mjd_obs=cpl_propertylist_get_double(plist, KEY_NAME_MJD_OBS);
+<a name="l04178"></a>04178    } <span class="keywordflow">else</span> {
+<a name="l04179"></a>04179       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"keyword %s does not exist"</span>,KEY_NAME_MJD_OBS);
+<a name="l04180"></a>04180       sinfo_free_propertylist(&plist) ;
+<a name="l04181"></a>04181       <span class="keywordflow">return</span> -1;
+<a name="l04182"></a>04182    }
+<a name="l04183"></a>04183    sinfo_free_propertylist(&plist) ;
+<a name="l04184"></a>04184 
+<a name="l04185"></a>04185    <span class="keywordflow">return</span> mjd_obs;
+<a name="l04186"></a>04186 
+<a name="l04187"></a>04187 }
+<a name="l04188"></a>04188 
+<a name="l04189"></a>04189 
+<a name="l04190"></a>04190 
+<a name="l04191"></a>04191 
+<a name="l04192"></a>04192 <span class="keywordtype">double</span> sinfo_get_cumoffsetx(cpl_frame * frame)
+<a name="l04193"></a>04193 {
+<a name="l04194"></a>04194    cpl_propertylist* plist=NULL;
+<a name="l04195"></a>04195    <span class="keywordtype">char</span>* file=NULL;
+<a name="l04196"></a>04196 
+<a name="l04197"></a>04197    <span class="keywordtype">double</span> result=0.;
+<a name="l04198"></a>04198    file = cpl_strdup( cpl_frame_get_filename(frame)) ;
+<a name="l04199"></a>04199 
+<a name="l04200"></a>04200    <span class="keywordflow">if</span> ((cpl_error_code)((plist = cpl_propertylist_load(file, 0)) == NULL)) {
+<a name="l04201"></a>04201       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>( <span class="stringliteral">"getting header from reference frame %s"</span>,file);
+<a name="l04202"></a>04202       cpl_propertylist_delete(plist) ;
+<a name="l04203"></a>04203       cpl_free(file);
+<a name="l04204"></a>04204       <span class="keywordflow">return</span> -1 ;
+<a name="l04205"></a>04205    }
+<a name="l04206"></a>04206 
+<a name="l04207"></a>04207    <span class="keywordflow">if</span> (sinfo_propertylist_has(plist, KEY_NAME_CUMOFFX)) {
+<a name="l04208"></a>04208       result=cpl_propertylist_get_double(plist, KEY_NAME_CUMOFFX);
+<a name="l04209"></a>04209    } <span class="keywordflow">else</span> {
+<a name="l04210"></a>04210       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"keyword %s does not exist"</span>,KEY_NAME_CUMOFFX);
+<a name="l04211"></a>04211       cpl_propertylist_delete(plist) ;
+<a name="l04212"></a>04212       <span class="keywordflow">return</span> -1;
+<a name="l04213"></a>04213    }
+<a name="l04214"></a>04214    cpl_propertylist_delete(plist) ;
+<a name="l04215"></a>04215    cpl_free(file);
+<a name="l04216"></a>04216 
+<a name="l04217"></a>04217    <span class="keywordflow">return</span> result;
+<a name="l04218"></a>04218 
+<a name="l04219"></a>04219 }
+<a name="l04220"></a>04220 
+<a name="l04221"></a>04221 
+<a name="l04222"></a>04222 
+<a name="l04223"></a>04223 
+<a name="l04224"></a>04224 <span class="keywordtype">double</span> sinfo_get_cumoffsety(cpl_frame * frame)
+<a name="l04225"></a>04225 {
+<a name="l04226"></a>04226    cpl_propertylist* plist=NULL;
+<a name="l04227"></a>04227    <span class="keywordtype">char</span>* file=NULL;
+<a name="l04228"></a>04228 
+<a name="l04229"></a>04229    <span class="keywordtype">double</span> result=0.;
+<a name="l04230"></a>04230    file = cpl_strdup( cpl_frame_get_filename(frame)) ;
+<a name="l04231"></a>04231 
+<a name="l04232"></a>04232    <span class="keywordflow">if</span> ((cpl_error_code)((plist = cpl_propertylist_load(file, 0)) == NULL)) {
+<a name="l04233"></a>04233       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>( <span class="stringliteral">"getting header from reference frame %s"</span>,file);
+<a name="l04234"></a>04234       cpl_propertylist_delete(plist) ;
+<a name="l04235"></a>04235       cpl_free(file);
+<a name="l04236"></a>04236       <span class="keywordflow">return</span> -1 ;
+<a name="l04237"></a>04237    }
+<a name="l04238"></a>04238 
+<a name="l04239"></a>04239    <span class="keywordflow">if</span> (sinfo_propertylist_has(plist, KEY_NAME_CUMOFFY)) {
+<a name="l04240"></a>04240       result=cpl_propertylist_get_double(plist, KEY_NAME_CUMOFFY);
+<a name="l04241"></a>04241    } <span class="keywordflow">else</span> {
+<a name="l04242"></a>04242       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"keyword %s does not exist"</span>,KEY_NAME_CUMOFFY);
+<a name="l04243"></a>04243       cpl_propertylist_delete(plist) ;
+<a name="l04244"></a>04244       <span class="keywordflow">return</span> -1;
+<a name="l04245"></a>04245    }
+<a name="l04246"></a>04246    cpl_propertylist_delete(plist) ;
+<a name="l04247"></a>04247    cpl_free(file);
+<a name="l04248"></a>04248 
+<a name="l04249"></a>04249    <span class="keywordflow">return</span> result;
+<a name="l04250"></a>04250 
+<a name="l04251"></a>04251 }
+<a name="l04252"></a>04252 
+<a name="l04253"></a>04253 <span class="keywordtype">int</span> sinfo_frame_is_dither(cpl_frame * frame)
+<a name="l04254"></a>04254 {
+<a name="l04255"></a>04255 
+<a name="l04256"></a>04256    <span class="keywordtype">char</span> file[256];
+<a name="l04257"></a>04257    <span class="keywordtype">char</span> band[FILE_NAME_SZ];
+<a name="l04258"></a>04258 
+<a name="l04259"></a>04259 
+<a name="l04260"></a>04260    cpl_propertylist* plist=NULL;
+<a name="l04261"></a>04261    <span class="keywordtype">int</span> grat_encoder=0;
+<a name="l04262"></a>04262    <span class="keywordtype">int</span> dith_status=1;
+<a name="l04263"></a>04263    <span class="keywordtype">int</span> len=0;
+<a name="l04264"></a>04264 
+<a name="l04265"></a>04265 
+<a name="l04266"></a>04266    cknull(frame,<span class="stringliteral">"Null input frame. Exit!"</span>);
+<a name="l04267"></a>04267 
+<a name="l04268"></a>04268    cknull_nomsg(strcpy(file,cpl_frame_get_filename(frame)));
+<a name="l04269"></a>04269    len= strlen(file);
+<a name="l04270"></a>04270 
+<a name="l04271"></a>04271    <span class="keywordflow">if</span>(len<1) <span class="keywordflow">goto</span> cleanup;
+<a name="l04272"></a>04272    <span class="keywordflow">if</span>(sinfo_file_exists(file)==0) <span class="keywordflow">goto</span> cleanup;
+<a name="l04273"></a>04273    <span class="comment">//file = cpl_strdup(cpl_frame_get_filename(frame)) ;</span>
+<a name="l04274"></a>04274    cknull(plist = cpl_propertylist_load(file, 0),
+<a name="l04275"></a>04275       <span class="stringliteral">"getting header from reference frame %s"</span>,file);
+<a name="l04276"></a>04276 
+<a name="l04277"></a>04277    <span class="keywordflow">if</span> (sinfo_propertylist_has(plist, KEY_NAME_FILT_NAME)) {
+<a name="l04278"></a>04278       strcpy(band,cpl_propertylist_get_string(plist, KEY_NAME_FILT_NAME));
+<a name="l04279"></a>04279    } <span class="keywordflow">else</span> {
+<a name="l04280"></a>04280       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"keyword %s does not exist"</span>,KEY_NAME_FILT_NAME);
+<a name="l04281"></a>04281       sinfo_free_propertylist(&plist) ;
+<a name="l04282"></a>04282       <span class="keywordflow">return</span> -1;
+<a name="l04283"></a>04283    }
+<a name="l04284"></a>04284 
+<a name="l04285"></a>04285    <span class="keywordflow">if</span> (sinfo_propertylist_has(plist, KEY_NAME_GRAT_ENC)) {
+<a name="l04286"></a>04286       grat_encoder = cpl_propertylist_get_int(plist, KEY_NAME_GRAT_ENC);
+<a name="l04287"></a>04287    } <span class="keywordflow">else</span> {
+<a name="l04288"></a>04288       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"keyword %s does not exist"</span>,KEY_NAME_GRAT_ENC);
+<a name="l04289"></a>04289       sinfo_free_propertylist(&plist) ;
+<a name="l04290"></a>04290       <span class="keywordflow">return</span> -1;
+<a name="l04291"></a>04291    }
+<a name="l04292"></a>04292 
+<a name="l04293"></a>04293    sinfo_free_propertylist(&plist) ;
+<a name="l04294"></a>04294 
+<a name="l04295"></a>04295    <span class="keywordflow">if</span> (strcmp(band,<span class="stringliteral">"H"</span>) == 0) {
+<a name="l04296"></a>04296       <span class="keywordflow">if</span>( abs(grat_encoder - GRAT_VAL2_H) <= GRAT_VAL_TOL ) {
+<a name="l04297"></a>04297          dith_status = 0;
+<a name="l04298"></a>04298       } <span class="keywordflow">else</span> {
+<a name="l04299"></a>04299          dith_status = 0;
+<a name="l04300"></a>04300       }
+<a name="l04301"></a>04301    }
+<a name="l04302"></a>04302    <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(band,<span class="stringliteral">"H+K"</span>) == 0) {
+<a name="l04303"></a>04303       <span class="keywordflow">if</span>( abs(grat_encoder - GRAT_VAL2_HK) <= GRAT_VAL_TOL ) {
+<a name="l04304"></a>04304          dith_status = 0;
+<a name="l04305"></a>04305       } <span class="keywordflow">else</span> {
+<a name="l04306"></a>04306          dith_status = 0;
+<a name="l04307"></a>04307       }
+<a name="l04308"></a>04308    }
+<a name="l04309"></a>04309    <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(band,<span class="stringliteral">"K"</span>) == 0) {
+<a name="l04310"></a>04310       <span class="keywordflow">if</span>( abs(grat_encoder - GRAT_VAL2_K) <= GRAT_VAL_TOL ) {
+<a name="l04311"></a>04311          dith_status = 0;
+<a name="l04312"></a>04312       } <span class="keywordflow">else</span> {
+<a name="l04313"></a>04313          dith_status = 0;
+<a name="l04314"></a>04314       }
+<a name="l04315"></a>04315    }
+<a name="l04316"></a>04316    <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(band,<span class="stringliteral">"J"</span>) == 0) {
+<a name="l04317"></a>04317       <span class="keywordflow">if</span>( abs(grat_encoder - GRAT_VAL2_J) <= GRAT_VAL_TOL ) {
+<a name="l04318"></a>04318          dith_status = 0;
+<a name="l04319"></a>04319       } <span class="keywordflow">else</span> {
+<a name="l04320"></a>04320          dith_status = 0;
+<a name="l04321"></a>04321       }
+<a name="l04322"></a>04322    }
+<a name="l04323"></a>04323  cleanup:
+<a name="l04324"></a>04324 
+<a name="l04325"></a>04325    sinfo_free_propertylist(&plist) ;
+<a name="l04326"></a>04326    <span class="keywordflow">if</span>(cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l04327"></a>04327      <span class="keywordflow">return</span> -1;
+<a name="l04328"></a>04328    } <span class="keywordflow">else</span> {
+<a name="l04329"></a>04329      <span class="keywordflow">return</span> dith_status;
+<a name="l04330"></a>04330    }
+<a name="l04331"></a>04331 }
+<a name="l04332"></a>04332 
+<a name="l04333"></a>04333 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l04342"></a>04342 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l04343"></a>04343 
+<a name="l04344"></a>04344 <span class="keywordtype">int</span> sinfo_get_spatial_res(cpl_frame * ref_frame, <span class="keywordtype">char</span> * spat_res)
+<a name="l04345"></a>04345 {
+<a name="l04346"></a>04346 
+<a name="l04347"></a>04347    <span class="keyword">const</span> <span class="keywordtype">char</span>* ref_file;
+<a name="l04348"></a>04348    cpl_propertylist* plist=NULL;
+<a name="l04349"></a>04349 
+<a name="l04350"></a>04350    ref_file=cpl_frame_get_filename(ref_frame) ;
+<a name="l04351"></a>04351    <span class="keywordflow">if</span> ((cpl_error_code)((plist = cpl_propertylist_load(ref_file, 0)) == NULL)) {
+<a name="l04352"></a>04352       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>( <span class="stringliteral">"getting header from reference frame %s"</span>,ref_file);
+<a name="l04353"></a>04353       sinfo_free_propertylist(&plist) ;
+<a name="l04354"></a>04354       <span class="keywordflow">return</span> -1 ;
+<a name="l04355"></a>04355 
+<a name="l04356"></a>04356    }
+<a name="l04357"></a>04357 
+<a name="l04358"></a>04358    <span class="keywordflow">if</span> (sinfo_propertylist_has(plist, KEY_NAME_PREOPTICS)) {
+<a name="l04359"></a>04359       strcpy(spat_res,cpl_propertylist_get_string(plist, KEY_NAME_PREOPTICS));
+<a name="l04360"></a>04360       <span class="comment">/* sinfo_msg("%s value is %s", KEY_NAME_PREOPTICS, spat_res); */</span>
+<a name="l04361"></a>04361    } <span class="keywordflow">else</span> {
+<a name="l04362"></a>04362       <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"keyword %s does not exist"</span>,KEY_NAME_PREOPTICS);
+<a name="l04363"></a>04363       sinfo_free_propertylist(&plist);
+<a name="l04364"></a>04364       <span class="keywordflow">return</span> -1;
+<a name="l04365"></a>04365    }
+<a name="l04366"></a>04366    sinfo_free_propertylist(&plist);
+<a name="l04367"></a>04367    <span class="keywordflow">return</span> 0;
+<a name="l04368"></a>04368 
+<a name="l04369"></a>04369 }
+<a name="l04370"></a>04370 
+<a name="l04371"></a>04371 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l04379"></a>04379 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l04380"></a>04380 
+<a name="l04381"></a>04381 <span class="keywordtype">int</span> sinfo_frame_is_sky(cpl_frame * ref_frame)
+<a name="l04382"></a>04382 {
+<a name="l04383"></a>04383 
+<a name="l04384"></a>04384    <span class="keywordtype">char</span>  dpr_type[FILE_NAME_SZ];
+<a name="l04385"></a>04385    <span class="keywordtype">char</span>* ref_file=NULL;
+<a name="l04386"></a>04386    <span class="keyword">const</span> <span class="keywordtype">char</span>* sval=NULL;
+<a name="l04387"></a>04387 
+<a name="l04388"></a>04388    <span class="keywordtype">int</span> result=0;
+<a name="l04389"></a>04389    cpl_propertylist* plist=NULL;
+<a name="l04390"></a>04390 
+<a name="l04391"></a>04391    sval = cpl_frame_get_filename(ref_frame) ;
+<a name="l04392"></a>04392    ref_file = cpl_strdup(sval) ;
+<a name="l04393"></a>04393 
+<a name="l04394"></a>04394    <span class="keywordflow">if</span> ((cpl_error_code)((plist = cpl_propertylist_load(ref_file, 0)) == NULL)) {
+<a name="l04395"></a>04395       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>( <span class="stringliteral">"getting header from reference frame %s"</span>,ref_file);
+<a name="l04396"></a>04396       cpl_propertylist_delete(plist) ;
+<a name="l04397"></a>04397       cpl_free(ref_file);
+<a name="l04398"></a>04398       <span class="keywordflow">return</span> -1 ;
+<a name="l04399"></a>04399    }
+<a name="l04400"></a>04400 
+<a name="l04401"></a>04401    <span class="keywordflow">if</span> (sinfo_propertylist_has(plist, KEY_NAME_DPR_TYPE)) {
+<a name="l04402"></a>04402       strcpy(dpr_type,cpl_propertylist_get_string(plist, KEY_NAME_DPR_TYPE));
+<a name="l04403"></a>04403       <span class="comment">/* sinfo_msg("%s value is %d", KEY_NAME_DPR_TYPE, dpr_type); */</span>
+<a name="l04404"></a>04404    } <span class="keywordflow">else</span> {
+<a name="l04405"></a>04405       <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"keyword %s does not exist"</span>,KEY_NAME_DPR_TYPE);
+<a name="l04406"></a>04406       cpl_propertylist_delete(plist) ;
+<a name="l04407"></a>04407       cpl_free(ref_file);
+<a name="l04408"></a>04408       <span class="keywordflow">return</span> -1;
+<a name="l04409"></a>04409    }
+<a name="l04410"></a>04410    cpl_propertylist_delete(plist);
+<a name="l04411"></a>04411    <span class="keywordflow">if</span>(strstr(dpr_type,RAW_SKY) != NULL) {
+<a name="l04412"></a>04412       result=1;
+<a name="l04413"></a>04413    }
+<a name="l04414"></a>04414    cpl_free(ref_file);
+<a name="l04415"></a>04415 
+<a name="l04416"></a>04416    <span class="keywordflow">return</span> result;
+<a name="l04417"></a>04417 
+<a name="l04418"></a>04418 }
+<a name="l04419"></a>04419 
+<a name="l04420"></a>04420 
+<a name="l04421"></a>04421 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l04429"></a>04429 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l04430"></a>04430 
+<a name="l04431"></a>04431 <span class="keywordtype">int</span> sinfo_tag_is_sky(<span class="keywordtype">char</span> * tag)
+<a name="l04432"></a>04432 {
+<a name="l04433"></a>04433 
+<a name="l04434"></a>04434    <span class="keywordtype">int</span> result=0;
+<a name="l04435"></a>04435 
+<a name="l04436"></a>04436    <span class="keywordflow">if</span>(
+<a name="l04437"></a>04437       (strcmp(tag,RAW_SKY) == 0)         ||
+<a name="l04438"></a>04438       (strcmp(tag,RAW_IMAGE_PRE_SKY) == 0)         ||
+<a name="l04439"></a>04439       (strcmp(tag,RAW_SKY_NODDING) == 0) ||
+<a name="l04440"></a>04440       (strcmp(tag,RAW_SKY_JITTER) == 0) ||
+<a name="l04441"></a>04441       (strcmp(tag,RAW_SKY_STD) == 0)     ||
+<a name="l04442"></a>04442       (strcmp(tag,RAW_FIBRE_DARK) == 0) ||
+<a name="l04443"></a>04443       (strcmp(tag,RAW_SKY_OH) == 0)      ||
+<a name="l04444"></a>04444       (strcmp(tag,RAW_SKY_PSF_CALIBRATOR) == 0)
+<a name="l04445"></a>04445       ) {
+<a name="l04446"></a>04446       result=1;
+<a name="l04447"></a>04447    }
+<a name="l04448"></a>04448 
+<a name="l04449"></a>04449    <span class="keywordflow">return</span> result;
+<a name="l04450"></a>04450 
+<a name="l04451"></a>04451 }
+<a name="l04452"></a>04452 
+<a name="l04453"></a>04453 
+<a name="l04454"></a>04454 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l04462"></a>04462 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l04463"></a>04463 
+<a name="l04464"></a>04464 <span class="keywordtype">int</span> sinfo_tag_is_obj(<span class="keywordtype">char</span> * tag)
+<a name="l04465"></a>04465 {
+<a name="l04466"></a>04466 
+<a name="l04467"></a>04467    <span class="keywordtype">int</span> result=0;
+<a name="l04468"></a>04468 
+<a name="l04469"></a>04469    <span class="keywordflow">if</span>(
+<a name="l04470"></a>04470       (strcmp(tag,RAW_PUPIL_LAMP) == 0) ||
+<a name="l04471"></a>04471       (strcmp(tag,RAW_OBJECT) == 0)         ||
+<a name="l04472"></a>04472       (strcmp(tag,RAW_IMAGE_PRE_OBJECT) == 0)         ||
+<a name="l04473"></a>04473       (strcmp(tag,RAW_OBJECT_NODDING) == 0) ||
+<a name="l04474"></a>04474       (strcmp(tag,RAW_OBJECT_JITTER) == 0) ||
+<a name="l04475"></a>04475       (strcmp(tag,RAW_PSF_CALIBRATOR) == 0) ||
+<a name="l04476"></a>04476       (strcmp(tag,RAW_FIBRE_PSF) == 0) ||
+<a name="l04477"></a>04477       (strcmp(tag,RAW_STD) == 0)            ||
+<a name="l04478"></a>04478       (strcmp(tag,RAW_STD_STAR) == 0)
+<a name="l04479"></a>04479 
+<a name="l04480"></a>04480       ) {
+<a name="l04481"></a>04481       result=1;
+<a name="l04482"></a>04482    }
+<a name="l04483"></a>04483 
+<a name="l04484"></a>04484    <span class="keywordflow">return</span> result;
+<a name="l04485"></a>04485 
+<a name="l04486"></a>04486 }
+<a name="l04487"></a>04487 
+<a name="l04488"></a>04488 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l04496"></a>04496 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l04497"></a>04497 
+<a name="l04498"></a>04498 <span class="keywordtype">int</span> sinfo_tag_is_objpro(<span class="keywordtype">char</span> * tag)
+<a name="l04499"></a>04499 {
+<a name="l04500"></a>04500 
+<a name="l04501"></a>04501    <span class="keywordtype">int</span> result=0;
+<a name="l04502"></a>04502 
+<a name="l04503"></a>04503    <span class="keywordflow">if</span>(
+<a name="l04504"></a>04504       (strcmp(tag,PRO_COADD_OBJ) == 0) ||
+<a name="l04505"></a>04505       (strcmp(tag,PRO_COADD_PSF) == 0) ||
+<a name="l04506"></a>04506       (strcmp(tag,PRO_COADD_STD) == 0) ||
+<a name="l04507"></a>04507       (strcmp(tag,PRO_OBS_OBJ) == 0) ||
+<a name="l04508"></a>04508       (strcmp(tag,PRO_OBS_PSF) == 0) ||
+<a name="l04509"></a>04509       (strcmp(tag,PRO_OBS_STD) == 0) ||
+<a name="l04510"></a>04510       (strcmp(tag,PRO_PSF_CALIBRATOR_STACKED) == 0) ||
+<a name="l04511"></a>04511       (strcmp(tag,PRO_SKY_PSF_CALIBRATOR_STACKED) == 0) ||
+<a name="l04512"></a>04512       (strcmp(tag,PRO_STD_STACKED) == 0) ||
+<a name="l04513"></a>04513       (strcmp(tag,PRO_SKY_STD_STACKED) == 0) ||
+<a name="l04514"></a>04514       (strcmp(tag,PRO_OBJECT_NODDING_STACKED) == 0) ||
+<a name="l04515"></a>04515       (strcmp(tag,PRO_SKY_NODDING_STACKED) == 0)
+<a name="l04516"></a>04516       ) {
+<a name="l04517"></a>04517       result=1;
+<a name="l04518"></a>04518    }
+<a name="l04519"></a>04519 
+<a name="l04520"></a>04520    <span class="keywordflow">return</span> result;
+<a name="l04521"></a>04521 
+<a name="l04522"></a>04522 }
+<a name="l04523"></a>04523 
+<a name="l04524"></a>04524 
+<a name="l04525"></a>04525 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l04533"></a>04533 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l04534"></a>04534 
+<a name="l04535"></a>04535 <span class="keywordtype">int</span> sinfo_frame_is_on(cpl_frame * ref_frame)
+<a name="l04536"></a>04536 {
+<a name="l04537"></a>04537 
+<a name="l04538"></a>04538    <span class="keywordtype">char</span> ref_file[FILE_NAME_SZ];
+<a name="l04539"></a>04539    <span class="keywordtype">char</span> dpr_type[FILE_NAME_SZ];
+<a name="l04540"></a>04540    <span class="keywordtype">int</span> lamp_Xe=0;
+<a name="l04541"></a>04541    <span class="keywordtype">int</span> lamp_Kr=0;
+<a name="l04542"></a>04542    <span class="keywordtype">int</span> lamp_Ne=0;
+<a name="l04543"></a>04543    <span class="keywordtype">int</span> lamp_Ar=0;
+<a name="l04544"></a>04544    <span class="keywordtype">int</span> lamp_Halo=0;
+<a name="l04545"></a>04545    <span class="keywordtype">int</span> len=0;
+<a name="l04546"></a>04546    <span class="keywordtype">int</span> result=0;
+<a name="l04547"></a>04547    cpl_propertylist* plist=NULL;
+<a name="l04548"></a>04548    <span class="keyword">const</span> <span class="keywordtype">char</span>* filename=NULL;
+<a name="l04549"></a>04549    cknull(ref_frame,<span class="stringliteral">"Null input frame. Exit!"</span>);
+<a name="l04550"></a>04550 
+<a name="l04551"></a>04551    cknull_nomsg(filename=cpl_frame_get_filename(ref_frame));
+<a name="l04552"></a>04552    len= strlen(filename);
+<a name="l04553"></a>04553    <span class="keywordflow">if</span>(len<1) <span class="keywordflow">goto</span> cleanup;
+<a name="l04554"></a>04554 
+<a name="l04555"></a>04555    check_nomsg(strcpy(ref_file, filename)) ;
+<a name="l04556"></a>04556    <span class="keywordflow">if</span> ((cpl_error_code)((plist = cpl_propertylist_load(ref_file,0)) == NULL)) {
+<a name="l04557"></a>04557       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>( <span class="stringliteral">"getting header from reference frame %s"</span>,ref_file);
+<a name="l04558"></a>04558       sinfo_free_propertylist(&plist) ;
+<a name="l04559"></a>04559       <span class="keywordflow">return</span> -1 ;
+<a name="l04560"></a>04560    }
+<a name="l04561"></a>04561 
+<a name="l04562"></a>04562 <span class="comment">/*-----------------------------------------------------------------------</span>
+<a name="l04563"></a>04563 <span class="comment">  in J  Argon (4)</span>
+<a name="l04564"></a>04564 <span class="comment">  in H Xenon and Argon (1+4)</span>
+<a name="l04565"></a>04565 <span class="comment">  in K Neon (3)</span>
+<a name="l04566"></a>04566 <span class="comment">  in H+K Xenon (1)</span>
+<a name="l04567"></a>04567 <span class="comment">  -------------------------------------------------------------------------*/</span>
+<a name="l04568"></a>04568    <span class="keywordflow">if</span> (sinfo_propertylist_has(plist, KEY_NAME_DPR_TYPE)) {
+<a name="l04569"></a>04569       strcpy(dpr_type,cpl_propertylist_get_string(plist, KEY_NAME_DPR_TYPE));
+<a name="l04570"></a>04570       <span class="comment">/* sinfo_msg("%s value is %s", KEY_NAME_DPR_TYPE, dpr_type); */</span>
+<a name="l04571"></a>04571    } <span class="keywordflow">else</span> {
+<a name="l04572"></a>04572       <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"keyword %s does not exist"</span>,KEY_NAME_DPR_TYPE);
+<a name="l04573"></a>04573       sinfo_free_propertylist(&plist);
+<a name="l04574"></a>04574       <span class="keywordflow">return</span> -1;
+<a name="l04575"></a>04575    }
+<a name="l04576"></a>04576 
+<a name="l04577"></a>04577    <span class="comment">/*</span>
+<a name="l04578"></a>04578 <span class="comment">     In order to use the frame tag to identify frames we have to add this line</span>
+<a name="l04579"></a>04579 <span class="comment">     strcpy(dpr_type,cpl_frame_get_tag(ref_frame));</span>
+<a name="l04580"></a>04580 <span class="comment"></span>
+<a name="l04581"></a>04581 <span class="comment">   */</span>
+<a name="l04582"></a>04582 
+<a name="l04583"></a>04583    <span class="keywordflow">if</span>(strstr(dpr_type,<span class="stringliteral">"STD"</span>) != NULL) {
+<a name="l04584"></a>04584       result = 1;
+<a name="l04585"></a>04585       sinfo_free_propertylist(&plist);
+<a name="l04586"></a>04586       <span class="keywordflow">return</span> result;
+<a name="l04587"></a>04587    }
+<a name="l04588"></a>04588 
+<a name="l04589"></a>04589    <span class="keywordflow">if</span>(strstr(dpr_type,<span class="stringliteral">"PSF"</span>) != NULL) {
+<a name="l04590"></a>04590       result = 1;
+<a name="l04591"></a>04591       sinfo_free_propertylist(&plist);
+<a name="l04592"></a>04592       <span class="keywordflow">return</span> result;
+<a name="l04593"></a>04593    }
+<a name="l04594"></a>04594 
+<a name="l04595"></a>04595    <span class="keywordflow">if</span>(strstr(dpr_type,<span class="stringliteral">"SKY"</span>) != NULL) {
+<a name="l04596"></a>04596       result = 0;
+<a name="l04597"></a>04597       sinfo_free_propertylist(&plist);
+<a name="l04598"></a>04598       <span class="keywordflow">return</span> result;
+<a name="l04599"></a>04599    }
+<a name="l04600"></a>04600 
+<a name="l04601"></a>04601 
+<a name="l04602"></a>04602    <span class="keywordflow">if</span>(strstr(dpr_type,<span class="stringliteral">"OBJECT"</span>) != NULL) {
+<a name="l04603"></a>04603       result = 1;
+<a name="l04604"></a>04604       sinfo_free_propertylist(&plist);
+<a name="l04605"></a>04605       <span class="keywordflow">return</span> result;
+<a name="l04606"></a>04606    }
+<a name="l04607"></a>04607    <span class="comment">/*</span>
+<a name="l04608"></a>04608 <span class="comment">     if(strstr(dpr_type,"PUPIL") != NULL) {</span>
+<a name="l04609"></a>04609 <span class="comment">     result = 1;</span>
+<a name="l04610"></a>04610 <span class="comment">     cpl_propertylist_delete(plist);</span>
+<a name="l04611"></a>04611 <span class="comment">     return result;</span>
+<a name="l04612"></a>04612 <span class="comment">     }</span>
+<a name="l04613"></a>04613 <span class="comment">   */</span>
+<a name="l04614"></a>04614 
+<a name="l04615"></a>04615    <span class="keywordflow">if</span> (sinfo_propertylist_has(plist, KEY_NAME_LAMP_XE)) {
+<a name="l04616"></a>04616       lamp_Xe=cpl_propertylist_get_bool(plist, KEY_NAME_LAMP_XE);
+<a name="l04617"></a>04617       <span class="comment">/* sinfo_msg("%s value is %d", KEY_NAME_LAMP_XE, lamp_Xe); */</span>
+<a name="l04618"></a>04618    } <span class="keywordflow">else</span> {
+<a name="l04619"></a>04619       <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"keyword %s does not exist"</span>,KEY_NAME_LAMP_XE);
+<a name="l04620"></a>04620       sinfo_free_propertylist(&plist);
+<a name="l04621"></a>04621       <span class="keywordflow">return</span> -1;
+<a name="l04622"></a>04622    }
+<a name="l04623"></a>04623 
+<a name="l04624"></a>04624    <span class="keywordflow">if</span> (sinfo_propertylist_has(plist, KEY_NAME_LAMP_KR)) {
+<a name="l04625"></a>04625       lamp_Kr=cpl_propertylist_get_bool(plist, KEY_NAME_LAMP_KR);
+<a name="l04626"></a>04626       <span class="comment">/* sinfo_msg("%s value is %d", KEY_NAME_LAMP_KR, lamp_Kr); */</span>
+<a name="l04627"></a>04627    } <span class="keywordflow">else</span> {
+<a name="l04628"></a>04628       <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"keyword %s does not exist"</span>,KEY_NAME_LAMP_KR);
+<a name="l04629"></a>04629       sinfo_free_propertylist(&plist);
+<a name="l04630"></a>04630       <span class="keywordflow">return</span> -1;
+<a name="l04631"></a>04631    }
+<a name="l04632"></a>04632 
+<a name="l04633"></a>04633    <span class="keywordflow">if</span> (sinfo_propertylist_has(plist, KEY_NAME_LAMP_NE)) {
+<a name="l04634"></a>04634       lamp_Ne=cpl_propertylist_get_bool(plist, KEY_NAME_LAMP_NE);
+<a name="l04635"></a>04635       <span class="comment">/* sinfo_msg("%s value is %d", KEY_NAME_LAMP_NE, lamp_Ne); */</span>
+<a name="l04636"></a>04636    } <span class="keywordflow">else</span> {
+<a name="l04637"></a>04637       <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"keyword %s does not exist"</span>,KEY_NAME_LAMP_NE);
+<a name="l04638"></a>04638       sinfo_free_propertylist(&plist);
+<a name="l04639"></a>04639       <span class="keywordflow">return</span> -1;
+<a name="l04640"></a>04640    }
+<a name="l04641"></a>04641 
+<a name="l04642"></a>04642    <span class="keywordflow">if</span> (sinfo_propertylist_has(plist, KEY_NAME_LAMP_AR)) {
+<a name="l04643"></a>04643       lamp_Ar=cpl_propertylist_get_bool(plist, KEY_NAME_LAMP_AR);
+<a name="l04644"></a>04644       <span class="comment">/* sinfo_msg("%s value is %d", KEY_NAME_LAMP_AR, lamp_Ar); */</span>
+<a name="l04645"></a>04645    } <span class="keywordflow">else</span> {
+<a name="l04646"></a>04646       <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"keyword %s does not exist"</span>,KEY_NAME_LAMP_AR);
+<a name="l04647"></a>04647       sinfo_free_propertylist(&plist);
+<a name="l04648"></a>04648       <span class="keywordflow">return</span> -1;
+<a name="l04649"></a>04649    }
+<a name="l04650"></a>04650 
+<a name="l04651"></a>04651    <span class="keywordflow">if</span> (sinfo_propertylist_has(plist, KEY_NAME_LAMP_HALO)) {
+<a name="l04652"></a>04652       lamp_Halo=cpl_propertylist_get_bool(plist, KEY_NAME_LAMP_HALO);
+<a name="l04653"></a>04653       <span class="comment">/* sinfo_msg("%s value is %d", KEY_NAME_LAMP_HALO, lamp_Halo); */</span>
+<a name="l04654"></a>04654    } <span class="keywordflow">else</span> {
+<a name="l04655"></a>04655       <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"keyword %s does not exist"</span>,KEY_NAME_LAMP_HALO);
+<a name="l04656"></a>04656       sinfo_free_propertylist(&plist);
+<a name="l04657"></a>04657       <span class="keywordflow">return</span> -1;
+<a name="l04658"></a>04658    }
+<a name="l04659"></a>04659 
+<a name="l04660"></a>04660 
+<a name="l04661"></a>04661 
+<a name="l04662"></a>04662 
+<a name="l04663"></a>04663    <span class="keywordflow">if</span>(lamp_Xe) {
+<a name="l04664"></a>04664       result=1;
+<a name="l04665"></a>04665    }
+<a name="l04666"></a>04666 
+<a name="l04667"></a>04667    <span class="keywordflow">if</span>(lamp_Kr) {
+<a name="l04668"></a>04668       result=1;
+<a name="l04669"></a>04669    }
+<a name="l04670"></a>04670 
+<a name="l04671"></a>04671    <span class="keywordflow">if</span>(lamp_Ne) {
+<a name="l04672"></a>04672       result=1;
+<a name="l04673"></a>04673    }
+<a name="l04674"></a>04674 
+<a name="l04675"></a>04675    <span class="keywordflow">if</span>(lamp_Ar) {
+<a name="l04676"></a>04676       result=1;
+<a name="l04677"></a>04677    }
+<a name="l04678"></a>04678 
+<a name="l04679"></a>04679 
+<a name="l04680"></a>04680    <span class="keywordflow">if</span>(lamp_Halo) {
+<a name="l04681"></a>04681       result=1;
+<a name="l04682"></a>04682    }
+<a name="l04683"></a>04683 
+<a name="l04684"></a>04684   cleanup:
+<a name="l04685"></a>04685    sinfo_free_propertylist(&plist);
+<a name="l04686"></a>04686    <span class="keywordflow">return</span> result;
+<a name="l04687"></a>04687 
+<a name="l04688"></a>04688 
+<a name="l04689"></a>04689 }
+<a name="l04690"></a>04690 
+<a name="l04691"></a>04691 
+<a name="l04692"></a>04692 
+<a name="l04693"></a>04693 <span class="keywordtype">int</span>
+<a name="l04694"></a>04694 sinfo_pfits_add_qc(cpl_propertylist       *   plist,
+<a name="l04695"></a>04695                    qc_log          *   qclog)
+<a name="l04696"></a>04696 {
+<a name="l04697"></a>04697    <span class="keywordtype">char</span>            key_name[80] ;
+<a name="l04698"></a>04698    <span class="keywordtype">char</span>            key_value[80] ;
+<a name="l04699"></a>04699 
+<a name="l04700"></a>04700    <span class="keywordtype">int</span>             i =0;
+<a name="l04701"></a>04701 
+<a name="l04702"></a>04702    <span class="comment">/* Test entries */</span>
+<a name="l04703"></a>04703    <span class="keywordflow">if</span> (plist == NULL) <span class="keywordflow">return</span> -1 ;
+<a name="l04704"></a>04704 
+<a name="l04705"></a>04705    <span class="comment">/* Parameter Name:    PIPEFILE */</span>
+<a name="l04706"></a>04706    <span class="comment">/* we add ESO prefix to FITS keywords" */</span>
+<a name="l04707"></a>04707    <span class="keywordflow">for</span>(i=0;i<qclog[0].n;i++) {
+<a name="l04708"></a>04708       strcpy(key_name,<span class="stringliteral">"ESO "</span>);
+<a name="l04709"></a>04709       strcat(key_name,qclog[i].name);
+<a name="l04710"></a>04710       <span class="keywordflow">if</span>(strcmp(qclog[i].type,<span class="stringliteral">"string"</span>) == 0) {
+<a name="l04711"></a>04711          snprintf(key_value,<span class="keyword">sizeof</span>(key_value)-1,<span class="stringliteral">"%s"</span>,qclog[i].s_val);
+<a name="l04712"></a>04712          cpl_propertylist_append_string(plist, key_name,key_value) ;
+<a name="l04713"></a>04713          cpl_propertylist_set_comment(plist, key_name,qclog[i].comm) ;
+<a name="l04714"></a>04714 
+<a name="l04715"></a>04715       } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(strcmp(qclog[i].type,<span class="stringliteral">"bool"</span>) == 0) {
+<a name="l04716"></a>04716          snprintf(key_value,<span class="keyword">sizeof</span>(key_value),<span class="stringliteral">"%i"</span>,(<span class="keywordtype">int</span>)qclog[i].n_val);
+<a name="l04717"></a>04717          cpl_propertylist_append_bool(plist, key_name,(<span class="keywordtype">int</span>)qclog[i].n_val) ;
+<a name="l04718"></a>04718          cpl_propertylist_set_comment(plist, key_name,qclog[i].comm) ;
+<a name="l04719"></a>04719       } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(strcmp(qclog[i].type,<span class="stringliteral">"int"</span>) == 0) {
+<a name="l04720"></a>04720          snprintf(key_value,<span class="keyword">sizeof</span>(key_value),<span class="stringliteral">"%i"</span>,(<span class="keywordtype">int</span>)qclog[i].n_val);
+<a name="l04721"></a>04721          cpl_propertylist_append_int(plist, key_name,(<span class="keywordtype">int</span>)qclog[i].n_val) ;
+<a name="l04722"></a>04722          cpl_propertylist_set_comment(plist, key_name,qclog[i].comm) ;
+<a name="l04723"></a>04723       } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(strcmp(qclog[i].type,<span class="stringliteral">"float"</span>) == 0) {
+<a name="l04724"></a>04724          snprintf(key_value,<span class="keyword">sizeof</span>(key_value),<span class="stringliteral">"%f"</span>,(<span class="keywordtype">float</span>)qclog[i].n_val);
+<a name="l04725"></a>04725          cpl_propertylist_append_float(plist, key_name,(<span class="keywordtype">float</span>)qclog[i].n_val) ;
+<a name="l04726"></a>04726          cpl_propertylist_set_comment(plist, key_name,qclog[i].comm) ;
+<a name="l04727"></a>04727       } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(strcmp(qclog[i].type,<span class="stringliteral">"double"</span>) == 0) {
+<a name="l04728"></a>04728          snprintf(key_value,<span class="keyword">sizeof</span>(key_value),<span class="stringliteral">"%f"</span>,qclog[i].n_val);
+<a name="l04729"></a>04729          cpl_propertylist_append_double(plist, key_name,qclog[i].n_val) ;
+<a name="l04730"></a>04730          cpl_propertylist_set_comment(plist, key_name,qclog[i].comm) ;
+<a name="l04731"></a>04731       }
+<a name="l04732"></a>04732 
+<a name="l04733"></a>04733    }
+<a name="l04734"></a>04734 
+<a name="l04735"></a>04735    <span class="keywordflow">return</span> 0 ;
+<a name="l04736"></a>04736 }
+<a name="l04737"></a>04737 
+<a name="l04738"></a>04738 
+<a name="l04739"></a>04739 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__dfs_8h_source.html b/html/sinfo__dfs_8h_source.html
new file mode 100644
index 0000000..9f2634b
--- /dev/null
+++ b/html/sinfo__dfs_8h_source.html
@@ -0,0 +1,68 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_dfs.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_dfs.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_dfs.h,v 1.3 2010/02/17 09:23:43 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the SINFONI Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This proram is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2010/02/17 09:23:43 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.3 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifndef SINFO_DFS_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_DFS_H</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span>
+<a name="l00031"></a>00031 <span class="comment">/*--------------------------------------------------------------------------</span>
+<a name="l00032"></a>00032 <span class="comment">                                 general Includes</span>
+<a name="l00033"></a>00033 <span class="comment"> --------------------------------------------------------------------------*/</span>
+<a name="l00034"></a>00034 <span class="preprocessor">#include <config.h></span>
+<a name="l00035"></a>00035 <span class="preprocessor">#include <string.h></span>
+<a name="l00036"></a>00036 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include "sinfo_pfits.h"</span>
+<a name="l00038"></a>00038 <span class="comment">/* #include "utilities.h" */</span>   <span class="comment">/* critical for other modules */</span>
+<a name="l00039"></a>00039 <span class="comment">/*------------------------------------------------------------------------</span>
+<a name="l00040"></a>00040 <span class="comment">                                   Defines</span>
+<a name="l00041"></a>00041 <span class="comment"> --------------------------------------------------------------------------*/</span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include "sinfo_globals.h"</span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include "sinfo_raw_types.h"</span>
+<a name="l00044"></a>00044 <span class="preprocessor">#include "sinfo_ref_types.h"</span>
+<a name="l00045"></a>00045 <span class="preprocessor">#include "sinfo_pro_types.h"</span>
+<a name="l00046"></a>00046 <span class="preprocessor">#include "sinfo_key_names.h"</span>
+<a name="l00047"></a>00047 <span class="comment">/* ---------------------------------------------------------------------- </span>
+<a name="l00048"></a>00048 <span class="comment">   functions</span>
+<a name="l00049"></a>00049 <span class="comment">---------------------------------------------------------------------- */</span>
+<a name="l00050"></a>00050 <span class="preprocessor">#include "sinfo_functions.h"</span>
+<a name="l00051"></a>00051 CPL_END_DECLS
+<a name="l00052"></a>00052 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__distortion_8c_source.html b/html/sinfo__distortion_8c_source.html
new file mode 100644
index 0000000..a636ba6
--- /dev/null
+++ b/html/sinfo__distortion_8c_source.html
@@ -0,0 +1,1513 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_distortion.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_distortion.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_distortion.c,v 1.37 2012/03/05 16:34:06 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the irplib package</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2012/03/05 16:34:06 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.37 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span><span class="preprocessor">#include <sinfo_cpl_size.h></span>
+<a name="l00032"></a>00032 
+<a name="l00033"></a>00033 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00034"></a>00034 <span class="comment">                                   Includes</span>
+<a name="l00035"></a>00035 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00038"></a>00038 <span class="preprocessor">#include <sinfo_cpl_size.h></span>
+<a name="l00039"></a>00039 <span class="preprocessor">#include <math.h></span>
+<a name="l00040"></a>00040 
+<a name="l00041"></a>00041 
+<a name="l00042"></a>00042 <span class="preprocessor">#include "sinfo_distortion.h"</span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include "sinfo_functions.h"</span>
+<a name="l00044"></a>00044 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00045"></a>00045 <span class="preprocessor">#include "sinfo_error.h"</span>
+<a name="l00046"></a>00046 <span class="preprocessor">#include "irplib_flat.h"</span>
+<a name="l00047"></a>00047 <span class="preprocessor">#include "sinfo_utils_wrappers.h"</span>
+<a name="l00048"></a>00048 <span class="comment">//#include "sinfo_irplib_cpl_wrp.h"</span>
+<a name="l00049"></a>00049 <span class="preprocessor">#include "sinfo_utilities.h"</span>
+<a name="l00050"></a>00050 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00051"></a>00051 <span class="comment">                                   Define</span>
+<a name="l00052"></a>00052 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00053"></a>00053 
+<a name="l00054"></a>00054 <span class="preprocessor">#define ARC_NBSAMPLES       20</span>
+<a name="l00055"></a>00055 <span class="preprocessor"></span><span class="preprocessor">#define ARC_THRESHFACT      (1.0/3.0)</span>
+<a name="l00056"></a>00056 <span class="preprocessor"></span><span class="preprocessor">#define ARC_MINGOODPIX      100</span>
+<a name="l00057"></a>00057 <span class="preprocessor"></span><span class="preprocessor">#define ARC_MINARCLENFACT   1.19   </span><span class="comment">/* 1.1-2 */</span>
+<a name="l00058"></a>00058 <span class="preprocessor">#define ARC_MINNBARCS       32     </span><span class="comment">/* 4-32 */</span>
+<a name="l00059"></a>00059 <span class="preprocessor">#define ARC_RANGE_FACT      3.0</span>
+<a name="l00060"></a>00060 <span class="preprocessor"></span><span class="preprocessor">#define ARC_WINDOWSIZE      10  </span><span class="comment">/* 32 */</span>
+<a name="l00061"></a>00061 
+<a name="l00062"></a>00062 <span class="preprocessor">#define TRESH_MEDIAN_MIN    0.0</span>
+<a name="l00063"></a>00063 <span class="preprocessor"></span><span class="preprocessor">#define TRESH_SIGMA_MAX     200.0</span>
+<a name="l00064"></a>00064 <span class="preprocessor"></span>
+<a name="l00066"></a>00066 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00070"></a>00070 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00071"></a>00071 
+<a name="l00072"></a>00072 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00073"></a>00073 <span class="comment">                                Functions prototypes</span>
+<a name="l00074"></a>00074 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00075"></a>00075 <span class="keyword">static</span> cpl_apertures *
+<a name="l00076"></a>00076 sinfo_distortion_detect_arcs_new(cpl_image* ,cpl_image   **,
+<a name="l00077"></a>00077                                  <span class="keywordtype">int</span>,<span class="keywordtype">int</span>,<span class="keywordtype">double</span>,<span class="keywordtype">int</span>,<span class="keywordtype">int</span>,<span class="keywordtype">int</span>,<span class="keywordtype">int</span>,<span class="keywordtype">double</span>,<span class="keywordtype">int</span>);
+<a name="l00078"></a>00078 
+<a name="l00079"></a>00079 <span class="keyword">static</span>
+<a name="l00080"></a>00080 cpl_apertures * sinfo_distortion_detect_arcs(cpl_image *,
+<a name="l00081"></a>00081         cpl_image **, <span class="keywordtype">int</span>, <span class="keywordtype">int</span>, <span class="keywordtype">int</span>, <span class="keywordtype">int</span>, <span class="keywordtype">int</span>, <span class="keywordtype">int</span>) ;
+<a name="l00082"></a>00082 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00083"></a>00083 sinfo_distortion_fill_badzones(cpl_image *, <span class="keywordtype">int</span>, <span class="keywordtype">int</span>, <span class="keywordtype">int</span>, <span class="keywordtype">int</span>, <span class="keywordtype">double</span>) ;
+<a name="l00084"></a>00084 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00085"></a>00085 sinfo_distortion_threshold1d(cpl_image *, <span class="keywordtype">double</span>, cpl_image *, <span class="keywordtype">double</span>) ;
+<a name="l00086"></a>00086 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00087"></a>00087 sinfo_distortion_purge_arcs(cpl_image *, cpl_apertures **,
+<a name="l00088"></a>00088                             cpl_image **, <span class="keywordtype">int</span>, <span class="keywordtype">int</span>, <span class="keywordtype">double</span>) ;
+<a name="l00089"></a>00089 <span class="keyword">static</span> cpl_bivector **
+<a name="l00090"></a>00090 sinfo_distortion_get_arc_positions(cpl_image *,
+<a name="l00091"></a>00091                                    cpl_image *,
+<a name="l00092"></a>00092                                    cpl_apertures *, <span class="keywordtype">int</span>, <span class="keywordtype">double</span> **) ;
+<a name="l00093"></a>00093 <span class="keyword">static</span> <span class="keywordtype">double</span> sinfo_distortion_fine_pos(cpl_image *, cpl_image *, <span class="keywordtype">int</span>, <span class="keywordtype">int</span>) ;
+<a name="l00094"></a>00094 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_distortion_sub_hor_lowpass(cpl_image *, <span class="keywordtype">int</span>) ;
+<a name="l00095"></a>00095 <span class="keyword">static</span> cpl_image * sinfo_distortion_remove_ramp(<span class="keyword">const</span> cpl_image *) ;
+<a name="l00096"></a>00096 <span class="keyword">static</span> cpl_image *
+<a name="l00097"></a>00097 sinfo_distortion_smooth(cpl_image* inp,<span class="keyword">const</span> <span class="keywordtype">int</span> r,<span class="keyword">const</span> <span class="keywordtype">int</span> d);
+<a name="l00098"></a>00098 
+<a name="l00099"></a>00099 
+<a name="l00100"></a>00100 
+<a name="l00101"></a>00101 
+<a name="l00102"></a>00102 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00103"></a>00103 <span class="comment">                                Functions code</span>
+<a name="l00104"></a>00104 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00105"></a>00105 
+<a name="l00106"></a>00106 
+<a name="l00107"></a>00107 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00117"></a>00117 <span class="keyword">static</span> cpl_image *
+<a name="l00118"></a>00118 sinfo_distortion_smooth(cpl_image* inp,<span class="keyword">const</span> <span class="keywordtype">int</span> r,<span class="keyword">const</span> <span class="keywordtype">int</span> d)
+<a name="l00119"></a>00119 {
+<a name="l00120"></a>00120 
+<a name="l00121"></a>00121   <span class="keywordtype">int</span> sx=0;
+<a name="l00122"></a>00122   <span class="keywordtype">int</span> sy=0;
+<a name="l00123"></a>00123   <span class="keywordtype">int</span> i=0;
+<a name="l00124"></a>00124   <span class="keywordtype">int</span> j=0;
+<a name="l00125"></a>00125   <span class="keywordtype">int</span> z=0;
+<a name="l00126"></a>00126 
+<a name="l00127"></a>00127   <span class="keywordtype">float</span> sum;
+<a name="l00128"></a>00128   cpl_image* out=NULL;
+<a name="l00129"></a>00129   <span class="keywordtype">float</span>* pi=NULL;
+<a name="l00130"></a>00130   <span class="keywordtype">float</span>* po=NULL;
+<a name="l00131"></a>00131   <span class="keywordtype">int</span> min=0;
+<a name="l00132"></a>00132 
+<a name="l00133"></a>00133   cknull(inp,<span class="stringliteral">"Null input image!"</span>);
+<a name="l00134"></a>00134   check_nomsg(sx=cpl_image_get_size_x(inp));
+<a name="l00135"></a>00135   check_nomsg(sy=cpl_image_get_size_y(inp));
+<a name="l00136"></a>00136   check_nomsg(out=cpl_image_duplicate(inp));
+<a name="l00137"></a>00137   check_nomsg(pi=cpl_image_get_data_float(inp));
+<a name="l00138"></a>00138   check_nomsg(po=cpl_image_get_data_float(out));
+<a name="l00139"></a>00139   min = r/2;
+<a name="l00140"></a>00140   <span class="keywordflow">switch</span> (d) {
+<a name="l00141"></a>00141   <span class="keywordflow">case</span> 0:
+<a name="l00142"></a>00142     <span class="keywordflow">for</span>(j=0;j<sy;j++) {
+<a name="l00143"></a>00143       <span class="keywordflow">for</span>(i=min;i<sx-min;i++) {
+<a name="l00144"></a>00144     sum=0;
+<a name="l00145"></a>00145     <span class="keywordflow">for</span>(z=i-min;z<i+min+1;z++) {
+<a name="l00146"></a>00146       sum+=pi[z+j*sx];
+<a name="l00147"></a>00147     }
+<a name="l00148"></a>00148         po[i+j*sx]=sum/r;
+<a name="l00149"></a>00149       }
+<a name="l00150"></a>00150     }
+<a name="l00151"></a>00151     <span class="keywordflow">break</span>;
+<a name="l00152"></a>00152 
+<a name="l00153"></a>00153   <span class="keywordflow">case</span> 1:
+<a name="l00154"></a>00154     <span class="keywordflow">for</span>(i=0;i<sx;i++) {
+<a name="l00155"></a>00155       <span class="keywordflow">for</span>(j=min;j<sy-min;j++) {
+<a name="l00156"></a>00156     sum=0;
+<a name="l00157"></a>00157     <span class="keywordflow">for</span>(z=j-min;z<j+min+1;z++) {
+<a name="l00158"></a>00158       sum+=pi[i+z*sx];
+<a name="l00159"></a>00159     }
+<a name="l00160"></a>00160         po[i+j*sx]=sum;
+<a name="l00161"></a>00161       }
+<a name="l00162"></a>00162     }
+<a name="l00163"></a>00163     <span class="keywordflow">break</span>;
+<a name="l00164"></a>00164 
+<a name="l00165"></a>00165   <span class="keywordflow">default</span>:
+<a name="l00166"></a>00166     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"case not supported"</span>);
+<a name="l00167"></a>00167     <span class="keywordflow">goto</span> cleanup;
+<a name="l00168"></a>00168 
+<a name="l00169"></a>00169   }
+<a name="l00170"></a>00170   check_nomsg(cpl_image_delete(inp));
+<a name="l00171"></a>00171   <span class="keywordflow">return</span> out;
+<a name="l00172"></a>00172  cleanup:
+<a name="l00173"></a>00173   <span class="keywordflow">return</span> NULL;
+<a name="l00174"></a>00174 }
+<a name="l00175"></a>00175 
+<a name="l00176"></a>00176 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00189"></a>00189 cpl_image *
+<a name="l00190"></a>00190 sinfo_distortion_image_restore(<span class="keyword">const</span> cpl_image* inp,
+<a name="l00191"></a>00191                                <span class="keyword">const</span> <span class="keywordtype">int</span> r,
+<a name="l00192"></a>00192                                <span class="keyword">const</span> <span class="keywordtype">int</span> d,
+<a name="l00193"></a>00193                                <span class="keyword">const</span> <span class="keywordtype">double</span> kappa,
+<a name="l00194"></a>00194                                <span class="keyword">const</span> <span class="keywordtype">int</span> ks_method,
+<a name="l00195"></a>00195                                <span class="keyword">const</span> <span class="keywordtype">int</span> n)
+<a name="l00196"></a>00196 {
+<a name="l00197"></a>00197 
+<a name="l00198"></a>00198   <span class="keywordtype">int</span> sx=0;
+<a name="l00199"></a>00199   <span class="keywordtype">int</span> sy=0;
+<a name="l00200"></a>00200   <span class="keywordtype">int</span> i=0;
+<a name="l00201"></a>00201   <span class="keywordtype">int</span> j=0;
+<a name="l00202"></a>00202   <span class="keywordtype">int</span> z=0;
+<a name="l00203"></a>00203   <span class="keywordtype">int</span> k=0;
+<a name="l00204"></a>00204 
+<a name="l00205"></a>00205 
+<a name="l00206"></a>00206   cpl_image* out=NULL;
+<a name="l00207"></a>00207   <span class="keyword">const</span> <span class="keywordtype">float</span>* pi=NULL;
+<a name="l00208"></a>00208   <span class="keywordtype">float</span>* po=NULL;
+<a name="l00209"></a>00209   <span class="keywordtype">int</span> min=0;
+<a name="l00210"></a>00210   cpl_vector* vec=NULL;
+<a name="l00211"></a>00211   <span class="keywordtype">double</span>* pv=NULL;
+<a name="l00212"></a>00212   <span class="keywordtype">double</span> mean=0;
+<a name="l00213"></a>00213   <span class="keywordtype">double</span> median=0;
+<a name="l00214"></a>00214 
+<a name="l00215"></a>00215   cknull(inp,<span class="stringliteral">"Null input image!"</span>);
+<a name="l00216"></a>00216   check_nomsg(sx=cpl_image_get_size_x(inp));
+<a name="l00217"></a>00217   check_nomsg(sy=cpl_image_get_size_y(inp));
+<a name="l00218"></a>00218   check_nomsg(out=cpl_image_duplicate(inp));
+<a name="l00219"></a>00219   check_nomsg(pi=cpl_image_get_data_float_const(inp));
+<a name="l00220"></a>00220   check_nomsg(po=cpl_image_get_data_float(out));
+<a name="l00221"></a>00221   min = r/2;
+<a name="l00222"></a>00222   check_nomsg(vec=cpl_vector_new(r));
+<a name="l00223"></a>00223   check_nomsg(pv=cpl_vector_get_data(vec));
+<a name="l00224"></a>00224   <span class="keywordflow">switch</span> (d) {
+<a name="l00225"></a>00225   <span class="keywordflow">case</span> 0:
+<a name="l00226"></a>00226     <span class="keywordflow">for</span>(j=0;j<sy;j++) {
+<a name="l00227"></a>00227       <span class="keywordflow">for</span>(i=min;i<sx-min;i++) {
+<a name="l00228"></a>00228     k=0;
+<a name="l00229"></a>00229     <span class="keywordflow">for</span>(z=i-min;z<i+min+1;z++) {
+<a name="l00230"></a>00230       pv[k]=(double)pi[z+j*sx];
+<a name="l00231"></a>00231           k++;
+<a name="l00232"></a>00232     }
+<a name="l00233"></a>00233         cknull_nomsg(vec=sinfo_vector_clip(vec,kappa,n,ks_method));
+<a name="l00234"></a>00234         check_nomsg(mean=cpl_vector_get_mean(vec));
+<a name="l00235"></a>00235         check_nomsg(median=cpl_vector_get_mean(vec));
+<a name="l00236"></a>00236         po[i+j*sx]+=(mean-median);
+<a name="l00237"></a>00237       }
+<a name="l00238"></a>00238     }
+<a name="l00239"></a>00239     <span class="keywordflow">break</span>;
+<a name="l00240"></a>00240 
+<a name="l00241"></a>00241   <span class="keywordflow">case</span> 1:
+<a name="l00242"></a>00242     <span class="keywordflow">for</span>(i=0;i<sx;i++) {
+<a name="l00243"></a>00243       <span class="keywordflow">for</span>(j=min;j<sy-min;j++) {
+<a name="l00244"></a>00244         k=0;
+<a name="l00245"></a>00245     <span class="keywordflow">for</span>(z=j-min;z<j+min+1;z++) {
+<a name="l00246"></a>00246       pv[k]=(double)pi[i+z*sx];
+<a name="l00247"></a>00247           k++;
+<a name="l00248"></a>00248     }
+<a name="l00249"></a>00249         cknull_nomsg(vec=sinfo_vector_clip(vec,kappa,n,ks_method));
+<a name="l00250"></a>00250         check_nomsg(mean=cpl_vector_get_mean(vec));
+<a name="l00251"></a>00251         check_nomsg(median=cpl_vector_get_mean(vec));
+<a name="l00252"></a>00252         po[i+j*sx]+=(mean-median);
+<a name="l00253"></a>00253       }
+<a name="l00254"></a>00254     }
+<a name="l00255"></a>00255     <span class="keywordflow">break</span>;
+<a name="l00256"></a>00256 
+<a name="l00257"></a>00257   <span class="keywordflow">default</span>:
+<a name="l00258"></a>00258     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"case not supported"</span>);
+<a name="l00259"></a>00259     <span class="keywordflow">goto</span> cleanup;
+<a name="l00260"></a>00260 
+<a name="l00261"></a>00261   }
+<a name="l00262"></a>00262   check_nomsg(cpl_image_delete((cpl_image*)inp));
+<a name="l00263"></a>00263   <span class="keywordflow">return</span> out;
+<a name="l00264"></a>00264  cleanup:
+<a name="l00265"></a>00265   <span class="keywordflow">return</span> NULL;
+<a name="l00266"></a>00266 }
+<a name="l00267"></a>00267 
+<a name="l00268"></a>00268 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00292"></a>00292 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00293"></a>00293 cpl_polynomial * sinfo_distortion_estimate_new(
+<a name="l00294"></a>00294         <span class="keyword">const</span> cpl_image *   org,
+<a name="l00295"></a>00295         <span class="keywordtype">int</span>                 xmin,
+<a name="l00296"></a>00296         <span class="keywordtype">int</span>                 ymin,
+<a name="l00297"></a>00297         <span class="keywordtype">int</span>                 xmax,
+<a name="l00298"></a>00298         <span class="keywordtype">int</span>                 ymax,
+<a name="l00299"></a>00299         <span class="keywordtype">int</span>                 auto_ramp_sub,
+<a name="l00300"></a>00300         <span class="keywordtype">int</span>                 arc_sat,
+<a name="l00301"></a>00301         <span class="keywordtype">int</span>                 max_arc_width,
+<a name="l00302"></a>00302         <span class="keywordtype">double</span>              kappa,
+<a name="l00303"></a>00303         <span class="keywordtype">double</span>              arcs_min_arclen_factor,
+<a name="l00304"></a>00304         <span class="keywordtype">int</span>                 arcs_window_size,
+<a name="l00305"></a>00305         <span class="keywordtype">int</span>                 smooth_rad,
+<a name="l00306"></a>00306         <span class="keywordtype">int</span>                 degree,
+<a name="l00307"></a>00307         <span class="keywordtype">double</span>              offset,
+<a name="l00308"></a>00308         cpl_apertures   **  arcs)
+<a name="l00309"></a>00309 {
+<a name="l00310"></a>00310     cpl_image       *   local_im ;
+<a name="l00311"></a>00311     cpl_image       *   label_image ;
+<a name="l00312"></a>00312     <span class="keywordtype">double</span>              rightmost, leftmost ;
+<a name="l00313"></a>00313     cpl_bivector    **  arcs_pos ;
+<a name="l00314"></a>00314     <span class="keywordtype">double</span>          *   parc_posx ;
+<a name="l00315"></a>00315     <span class="keywordtype">double</span>          *   parc_posy ;
+<a name="l00316"></a>00316     <span class="keywordtype">double</span>          *   lines_pos ;
+<a name="l00317"></a>00317     cpl_bivector    *   grid ;
+<a name="l00318"></a>00318     <span class="keywordtype">double</span>          *   pgridx ;
+<a name="l00319"></a>00319     <span class="keywordtype">double</span>          *   pgridy ;
+<a name="l00320"></a>00320     cpl_vector      *   values_to_fit ;
+<a name="l00321"></a>00321     <span class="keywordtype">double</span>          *   pvalues_to_fit ;
+<a name="l00322"></a>00322     <span class="keywordtype">int</span>                 min_arc_range ;
+<a name="l00323"></a>00323     <span class="keywordtype">int</span>                 n_calib ;
+<a name="l00324"></a>00324     <span class="keywordtype">int</span>                 n_arcs ;
+<a name="l00325"></a>00325     cpl_polynomial  *   poly2d ;
+<a name="l00326"></a>00326     <span class="keywordtype">int</span>                 nx ;
+<a name="l00327"></a>00327     <span class="keywordtype">int</span>                 i, j ;
+<a name="l00328"></a>00328 
+<a name="l00329"></a>00329     <span class="comment">/* AMO added to use offset */</span>
+<a name="l00330"></a>00330     cpl_vector    *     lines_pos_tmp ;
+<a name="l00331"></a>00331     cpl_bivector    *   grid_tmp ;
+<a name="l00332"></a>00332     cpl_vector* grid_tot=0;
+<a name="l00333"></a>00333     <span class="keywordtype">double</span>* pgrid_tmp_x=NULL;
+<a name="l00334"></a>00334     <span class="keywordtype">double</span>* pgrid_tmp_y=NULL;
+<a name="l00335"></a>00335     <span class="keywordtype">double</span>* pgrid_tot=NULL;
+<a name="l00336"></a>00336     <span class="keywordtype">double</span>* plines_pos_tmp=NULL;
+<a name="l00337"></a>00337     <span class="keywordtype">int</span> n_lines=0;
+<a name="l00338"></a>00338     <span class="keywordtype">int</span> k=0;
+<a name="l00339"></a>00339 
+<a name="l00340"></a>00340 
+<a name="l00341"></a>00341     <span class="comment">/* Check entries */</span>
+<a name="l00342"></a>00342     <span class="keywordflow">if</span> (org == NULL) <span class="keywordflow">return</span> NULL ;
+<a name="l00343"></a>00343     <span class="keywordflow">if</span> (kappa < 0.0) <span class="keywordflow">return</span> NULL ;
+<a name="l00344"></a>00344 
+<a name="l00345"></a>00345     <span class="comment">/* Initialise */</span>
+<a name="l00346"></a>00346     n_calib = ARC_NBSAMPLES ;
+<a name="l00347"></a>00347     nx = cpl_image_get_size_x(org) ;
+<a name="l00348"></a>00348 
+<a name="l00349"></a>00349     <span class="keywordflow">if</span> (auto_ramp_sub) {
+<a name="l00350"></a>00350         local_im = sinfo_distortion_remove_ramp(org) ;
+<a name="l00351"></a>00351     } <span class="keywordflow">else</span> {
+<a name="l00352"></a>00352         <span class="comment">/* Local copy of input image */</span>
+<a name="l00353"></a>00353         local_im = cpl_image_duplicate(org) ;
+<a name="l00354"></a>00354     }
+<a name="l00355"></a>00355     <span class="keywordflow">if</span> (local_im == NULL) {
+<a name="l00356"></a>00356         cpl_msg_error(cpl_func, <span class="stringliteral">"Cannot clean the image"</span>) ;
+<a name="l00357"></a>00357         <span class="keywordflow">return</span> NULL ;
+<a name="l00358"></a>00358     }
+<a name="l00359"></a>00359     <span class="keywordflow">if</span>(smooth_rad > 1) {
+<a name="l00360"></a>00360       local_im=sinfo_distortion_smooth(local_im,smooth_rad,1);
+<a name="l00361"></a>00361       <span class="comment">//cpl_image_save(local_im,"out_local_im.fits",CPL_BPP_IEEE_FLOAT,</span>
+<a name="l00362"></a>00362       <span class="comment">//               NULL,CPL_IO_DEFAULT);</span>
+<a name="l00363"></a>00363       <span class="comment">//local_im=sinfo_distortion_image_restore(local_im,smooth_rad,1,2,0,2);</span>
+<a name="l00364"></a>00364       <span class="comment">//cpl_image_save(local_im,"out_local_im_post.fits",</span>
+<a name="l00365"></a>00365       <span class="comment">//               CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT);</span>
+<a name="l00366"></a>00366 
+<a name="l00367"></a>00367     }
+<a name="l00368"></a>00368     <span class="comment">/* Detect the arcs in the input image */</span>
+<a name="l00369"></a>00369     cpl_msg_info(cpl_func, <span class="stringliteral">"Detect arcs"</span>) ;
+<a name="l00370"></a>00370     <span class="keywordflow">if</span> ((*arcs = sinfo_distortion_detect_arcs_new(local_im,
+<a name="l00371"></a>00371                     &label_image,
+<a name="l00372"></a>00372                     arc_sat, max_arc_width, kappa,
+<a name="l00373"></a>00373                     xmin, ymin, xmax, ymax,
+<a name="l00374"></a>00374                     arcs_min_arclen_factor,arcs_window_size)) == NULL) {
+<a name="l00375"></a>00375         cpl_image_delete(local_im) ;
+<a name="l00376"></a>00376         cpl_msg_error(cpl_func, <span class="stringliteral">"Cannot detect the arcs"</span>) ;
+<a name="l00377"></a>00377         <span class="keywordflow">return</span> NULL ;
+<a name="l00378"></a>00378     }
+<a name="l00379"></a>00379     n_arcs = cpl_apertures_get_size(*arcs) ;
+<a name="l00380"></a>00380     cpl_msg_info(cpl_func, <span class="stringliteral">"%d detected arcs"</span>, n_arcs) ;
+<a name="l00381"></a>00381 
+<a name="l00382"></a>00382     <span class="comment">/* Check that the arcs are not concentrated in the same zone */</span>
+<a name="l00383"></a>00383     rightmost = leftmost = cpl_apertures_get_pos_x(*arcs, 1) ;
+<a name="l00384"></a>00384     <span class="keywordflow">for</span> (i=1 ; i<n_arcs ; i++) {
+<a name="l00385"></a>00385         <span class="keywordflow">if</span> (cpl_apertures_get_pos_x(*arcs, i+1) < leftmost)
+<a name="l00386"></a>00386             leftmost = cpl_apertures_get_pos_x(*arcs, i+1) ;
+<a name="l00387"></a>00387         <span class="keywordflow">if</span> (cpl_apertures_get_pos_x(*arcs, i+1) > rightmost)
+<a name="l00388"></a>00388             rightmost = cpl_apertures_get_pos_x(*arcs, i+1) ;
+<a name="l00389"></a>00389     }
+<a name="l00390"></a>00390     min_arc_range = (int)(nx / ARC_RANGE_FACT) ;
+<a name="l00391"></a>00391     <span class="keywordflow">if</span> ((<span class="keywordtype">int</span>)(rightmost-leftmost) < min_arc_range) {
+<a name="l00392"></a>00392         cpl_msg_error(cpl_func, <span class="stringliteral">"too narrow range (%g-%g)<%d"</span>,
+<a name="l00393"></a>00393                 rightmost, leftmost, min_arc_range) ;
+<a name="l00394"></a>00394         cpl_apertures_delete(*arcs) ;
+<a name="l00395"></a>00395         cpl_image_delete(local_im) ;
+<a name="l00396"></a>00396         cpl_image_delete(label_image) ;
+<a name="l00397"></a>00397         <span class="keywordflow">return</span> NULL ;
+<a name="l00398"></a>00398     }
+<a name="l00399"></a>00399 
+<a name="l00400"></a>00400     <span class="comment">/* Create a 2-D deformation grid with detected arcs */</span>
+<a name="l00401"></a>00401     cpl_msg_info(cpl_func, <span class="stringliteral">"Create deformation grid"</span>) ;
+<a name="l00402"></a>00402     lines_pos = cpl_malloc(n_arcs * <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>)) ;
+<a name="l00403"></a>00403     <span class="keywordflow">if</span> ((arcs_pos = sinfo_distortion_get_arc_positions(local_im,
+<a name="l00404"></a>00404                     label_image, *arcs, n_calib, &lines_pos))==NULL){
+<a name="l00405"></a>00405         cpl_msg_error(cpl_func, <span class="stringliteral">"cannot get arcs positions"</span>) ;
+<a name="l00406"></a>00406         cpl_apertures_delete(*arcs) ;
+<a name="l00407"></a>00407         cpl_image_delete(local_im) ;
+<a name="l00408"></a>00408         cpl_free(lines_pos) ;
+<a name="l00409"></a>00409         cpl_image_delete(label_image) ;
+<a name="l00410"></a>00410         <span class="keywordflow">return</span> NULL ;
+<a name="l00411"></a>00411     }
+<a name="l00412"></a>00412     cpl_image_delete(label_image) ;
+<a name="l00413"></a>00413     cpl_image_delete(local_im) ;
+<a name="l00414"></a>00414 
+<a name="l00415"></a>00415     <span class="comment">/* Prepare the fitting */</span>
+<a name="l00416"></a>00416     lines_pos_tmp=cpl_vector_new(n_arcs);
+<a name="l00417"></a>00417     plines_pos_tmp=cpl_vector_get_data(lines_pos_tmp);
+<a name="l00418"></a>00418 
+<a name="l00419"></a>00419 
+<a name="l00420"></a>00420     sinfo_msg(<span class="stringliteral">"Fit the 2d polynomial"</span>) ;
+<a name="l00421"></a>00421     grid = cpl_bivector_new(n_arcs * n_calib) ;
+<a name="l00422"></a>00422     pgridx = cpl_bivector_get_x_data(grid) ;
+<a name="l00423"></a>00423     pgridy = cpl_bivector_get_y_data(grid) ;
+<a name="l00424"></a>00424     values_to_fit = cpl_vector_new(n_arcs * n_calib) ;
+<a name="l00425"></a>00425     pvalues_to_fit = cpl_vector_get_data(values_to_fit) ;
+<a name="l00426"></a>00426 
+<a name="l00427"></a>00427     <span class="keywordflow">for</span> (i=0 ; i<n_arcs ; i++) {
+<a name="l00428"></a>00428         parc_posx = cpl_bivector_get_x_data(arcs_pos[i]) ;
+<a name="l00429"></a>00429         parc_posy = cpl_bivector_get_y_data(arcs_pos[i]) ;
+<a name="l00430"></a>00430         <span class="keywordflow">for</span> (j=0 ; j<n_calib ; j++) {
+<a name="l00431"></a>00431             plines_pos_tmp[i]=lines_pos[i] ;
+<a name="l00432"></a>00432             pgridx[j+i*n_calib] = lines_pos[i] ;
+<a name="l00433"></a>00433             pgridy[j+i*n_calib] = parc_posy[j] ;
+<a name="l00434"></a>00434             pvalues_to_fit[j+i*n_calib] = parc_posx[j] ;
+<a name="l00435"></a>00435         }
+<a name="l00436"></a>00436     }
+<a name="l00437"></a>00437     <span class="comment">/* AMO new to use offset */</span>
+<a name="l00438"></a>00438     n_lines= n_arcs/32.0;
+<a name="l00439"></a>00439     <span class="keywordflow">if</span>(n_lines < 1) {
+<a name="l00440"></a>00440       n_lines=1;
+<a name="l00441"></a>00441     }
+<a name="l00442"></a>00442     cpl_vector_sort(lines_pos_tmp,1);
+<a name="l00443"></a>00443     plines_pos_tmp=cpl_vector_get_data(lines_pos_tmp);
+<a name="l00444"></a>00444     grid_tmp=cpl_bivector_duplicate(grid);
+<a name="l00445"></a>00445     grid_tot=cpl_vector_new(n_calib);
+<a name="l00446"></a>00446     pgrid_tmp_x = cpl_bivector_get_x_data(grid_tmp) ;
+<a name="l00447"></a>00447     pgrid_tmp_y = cpl_bivector_get_y_data(grid_tmp) ;
+<a name="l00448"></a>00448     pgrid_tot = cpl_vector_get_data(grid_tot);
+<a name="l00449"></a>00449     <span class="keywordflow">for</span>(j=0;j<n_calib;j++) {
+<a name="l00450"></a>00450       pgrid_tot[j]=0;
+<a name="l00451"></a>00451       <span class="keywordflow">for</span>(i=n_lines ;i<n_arcs;i=i+n_lines)
+<a name="l00452"></a>00452     {
+<a name="l00453"></a>00453       <span class="keywordflow">for</span>(k=0;k<n_lines;k++) {
+<a name="l00454"></a>00454         pgrid_tot[j] += (plines_pos_tmp[i+k]-
+<a name="l00455"></a>00455                              plines_pos_tmp[k]);
+<a name="l00456"></a>00456         <span class="comment">/*</span>
+<a name="l00457"></a>00457 <span class="comment">            sinfo_msg("diff=%g",(plines_pos_tmp[i+k]-</span>
+<a name="l00458"></a>00458 <span class="comment">                 plines_pos_tmp[k]));</span>
+<a name="l00459"></a>00459 <span class="comment">        */</span>
+<a name="l00460"></a>00460       }
+<a name="l00461"></a>00461     }
+<a name="l00462"></a>00462       <span class="comment">/*</span>
+<a name="l00463"></a>00463 <span class="comment">      sinfo_msg("j=%d pgrid_tot=%g",j,pgrid_tot[j]);</span>
+<a name="l00464"></a>00464 <span class="comment">      */</span>
+<a name="l00465"></a>00465     }
+<a name="l00466"></a>00466 
+<a name="l00467"></a>00467     <span class="keywordflow">for</span>(j=0;j<n_calib;j++) {
+<a name="l00468"></a>00468       <span class="keywordflow">for</span> (i=0 ; i<n_arcs ; i++) {
+<a name="l00469"></a>00469      pgridx[j+i*n_calib]=pgridx[j+i*n_calib]*
+<a name="l00470"></a>00470                              ((nx/32.0)*n_lines*(31*32/2))/pgrid_tot[j]-offset;
+<a name="l00471"></a>00471      <span class="comment">/*</span>
+<a name="l00472"></a>00472 <span class="comment">         sinfo_msg_error("AMo after corr grid[%d,%d]=%g",</span>
+<a name="l00473"></a>00473 <span class="comment">                          i,k,pgridx[k+i*n_calib]);</span>
+<a name="l00474"></a>00474 <span class="comment">     */</span>
+<a name="l00475"></a>00475      pgrid_tmp_x[j+i*n_calib]=pgrid_tmp_x[j+i*n_calib]*
+<a name="l00476"></a>00476                                   ((nx/32.0)*n_lines*(31*32/2))/pgrid_tot[j]-
+<a name="l00477"></a>00477                                   offset;
+<a name="l00478"></a>00478 
+<a name="l00479"></a>00479       }
+<a name="l00480"></a>00480     }
+<a name="l00481"></a>00481     cpl_vector_delete(lines_pos_tmp);
+<a name="l00482"></a>00482     cpl_bivector_delete(grid_tmp);
+<a name="l00483"></a>00483     cpl_vector_delete(grid_tot);
+<a name="l00484"></a>00484     <span class="comment">/* end AMO: to use the offset */</span>
+<a name="l00485"></a>00485 
+<a name="l00486"></a>00486 
+<a name="l00487"></a>00487     <span class="keywordflow">for</span> (i=0 ; i<n_arcs ; i++) cpl_bivector_delete(arcs_pos[i]) ;
+<a name="l00488"></a>00488     cpl_free(arcs_pos) ;
+<a name="l00489"></a>00489     cpl_free(lines_pos) ;
+<a name="l00490"></a>00490 
+<a name="l00491"></a>00491     <span class="comment">/* Apply the fitting */</span>
+<a name="l00492"></a>00492     <span class="keywordflow">if</span> ((poly2d = sinfo_polynomial_fit_2d_create(grid, values_to_fit,
+<a name="l00493"></a>00493                     degree, NULL))==NULL) {
+<a name="l00494"></a>00494         cpl_msg_error(cpl_func, <span class="stringliteral">"cannot apply the 2d fit"</span>) ;
+<a name="l00495"></a>00495         cpl_bivector_delete(grid) ;
+<a name="l00496"></a>00496         cpl_vector_delete(values_to_fit) ;
+<a name="l00497"></a>00497         cpl_apertures_delete(*arcs) ;
+<a name="l00498"></a>00498         <span class="keywordflow">return</span> NULL ;
+<a name="l00499"></a>00499     }
+<a name="l00500"></a>00500 
+<a name="l00501"></a>00501     <span class="comment">/* Free and return */</span>
+<a name="l00502"></a>00502     cpl_bivector_delete(grid) ;
+<a name="l00503"></a>00503     cpl_vector_delete(values_to_fit) ;
+<a name="l00504"></a>00504     <span class="keywordflow">return</span> poly2d ;
+<a name="l00505"></a>00505 }
+<a name="l00506"></a>00506 
+<a name="l00507"></a>00507 
+<a name="l00508"></a>00508 
+<a name="l00509"></a>00509 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00525"></a>00525 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00526"></a>00526 <span class="keyword">static</span> cpl_apertures * sinfo_distortion_detect_arcs_new(
+<a name="l00527"></a>00527         cpl_image   *   im,
+<a name="l00528"></a>00528         cpl_image   **  label_im,
+<a name="l00529"></a>00529         <span class="keywordtype">int</span>             arc_sat,
+<a name="l00530"></a>00530         <span class="keywordtype">int</span>             max_arc_width,
+<a name="l00531"></a>00531         <span class="keywordtype">double</span>          kappa,
+<a name="l00532"></a>00532         <span class="keywordtype">int</span>             xmin,
+<a name="l00533"></a>00533         <span class="keywordtype">int</span>             ymin,
+<a name="l00534"></a>00534         <span class="keywordtype">int</span>             xmax,
+<a name="l00535"></a>00535         <span class="keywordtype">int</span>             ymax,
+<a name="l00536"></a>00536         <span class="keywordtype">double</span> arcs_min_arclen_factor,
+<a name="l00537"></a>00537         <span class="keywordtype">int</span> arcs_window_size)
+<a name="l00538"></a>00538 {
+<a name="l00539"></a>00539     cpl_image       *   filt_im ;
+<a name="l00540"></a>00540     cpl_matrix      *   filter ;
+<a name="l00541"></a>00541     cpl_image       *   collapsed ;
+<a name="l00542"></a>00542     cpl_mask        *   bin_im ;
+<a name="l00543"></a>00543     <span class="keywordtype">double</span>              threshold, fillval, median_val, sigma ;
+<a name="l00544"></a>00544     <span class="keywordtype">int</span>                 min_arclen = 0 ;
+<a name="l00545"></a>00545     cpl_apertures   *   det ;
+<a name="l00546"></a>00546     cpl_size                 nobj ;
+<a name="l00547"></a>00547     <span class="keywordtype">int</span>                 ngoodpix ;
+<a name="l00548"></a>00548     <span class="keywordtype">int</span>                 ny ;
+<a name="l00549"></a>00549 
+<a name="l00550"></a>00550     ny = cpl_image_get_size_y(im) ;
+<a name="l00551"></a>00551     <span class="comment">/* Default values for output parameters */</span>
+<a name="l00552"></a>00552     *label_im = NULL ;
+<a name="l00553"></a>00553 
+<a name="l00554"></a>00554     <span class="comment">/* Clear zones to be ignored (to avoid false detections) */</span>
+<a name="l00555"></a>00555     median_val = cpl_image_get_median_dev(im, &sigma) ;
+<a name="l00556"></a>00556     fillval = median_val-sigma/2.0 ;
+<a name="l00557"></a>00557     <span class="keywordflow">if</span> (sinfo_distortion_fill_badzones(im, xmin, ymin, xmax, ymax,
+<a name="l00558"></a>00558                 fillval) == -1) {
+<a name="l00559"></a>00559         cpl_msg_error(cpl_func, <span class="stringliteral">"cannot fill bad zones"</span>) ;
+<a name="l00560"></a>00560         <span class="keywordflow">return</span> NULL ;
+<a name="l00561"></a>00561     }
+<a name="l00562"></a>00562     <span class="comment">/* Median vertical filter */</span>
+<a name="l00563"></a>00563     filter = cpl_matrix_new(3, 1) ;
+<a name="l00564"></a>00564     cpl_matrix_fill(filter, 1.0) ;
+<a name="l00565"></a>00565     <span class="comment">/* filt_im = cpl_image_filter_median(im, filter) ; */</span>
+<a name="l00566"></a>00566     filt_im = cpl_image_duplicate(im) ;
+<a name="l00567"></a>00567     cpl_matrix_delete(filter) ;
+<a name="l00568"></a>00568 
+<a name="l00569"></a>00569     <span class="comment">/* Subtract a low-pass */</span>
+<a name="l00570"></a>00570     <span class="comment">/* AMO: suppressed as may remove arcs */</span>
+<a name="l00571"></a>00571     <span class="keywordflow">if</span> (sinfo_distortion_sub_hor_lowpass(filt_im, arcs_window_size) == -1) {
+<a name="l00572"></a>00572         cpl_image_delete(filt_im) ;
+<a name="l00573"></a>00573         <span class="keywordflow">return</span> NULL ;
+<a name="l00574"></a>00574     }
+<a name="l00575"></a>00575     <span class="comment">//cpl_image_save(filt_im,"out_filt_im_lp.fits",CPL_BPP_IEEE_FLOAT,</span>
+<a name="l00576"></a>00576     <span class="comment">//               NULL,CPL_IO_DEFAULT);</span>
+<a name="l00577"></a>00577 
+<a name="l00578"></a>00578     <span class="comment">/* Get relevant stats for thresholding */</span>
+<a name="l00579"></a>00579     median_val = cpl_image_get_median_dev(filt_im, &sigma) ;
+<a name="l00580"></a>00580 
+<a name="l00581"></a>00581     <span class="comment">/* Correct median_val and sigma if necessary */</span>
+<a name="l00582"></a>00582     <span class="keywordflow">if</span> (median_val < TRESH_MEDIAN_MIN) median_val = TRESH_MEDIAN_MIN ;
+<a name="l00583"></a>00583     <span class="keywordflow">if</span> (sigma > TRESH_SIGMA_MAX) sigma = TRESH_SIGMA_MAX ;
+<a name="l00584"></a>00584 
+<a name="l00585"></a>00585     <span class="comment">/* Set the threshold */</span>
+<a name="l00586"></a>00586     threshold = median_val + sigma * kappa ;
+<a name="l00587"></a>00587 
+<a name="l00588"></a>00588     <span class="comment">/* Collapse the image */</span>
+<a name="l00589"></a>00589     collapsed = cpl_image_collapse_median_create(filt_im, 0, 0, 0) ;
+<a name="l00590"></a>00590 
+<a name="l00591"></a>00591     <span class="comment">/* Threshold to keep only the arcs - use of the collapsed image */</span>
+<a name="l00592"></a>00592     <span class="keywordflow">if</span> (sinfo_distortion_threshold1d(filt_im, median_val,
+<a name="l00593"></a>00593                                      collapsed, 0.0)==-1) {
+<a name="l00594"></a>00594         cpl_msg_error(cpl_func, <span class="stringliteral">"cannot threshold the filtered image"</span>) ;
+<a name="l00595"></a>00595         cpl_image_delete(filt_im) ;
+<a name="l00596"></a>00596         cpl_image_delete(collapsed) ;
+<a name="l00597"></a>00597         <span class="keywordflow">return</span> NULL ;
+<a name="l00598"></a>00598     }
+<a name="l00599"></a>00599     cpl_image_delete(collapsed) ;
+<a name="l00600"></a>00600 
+<a name="l00601"></a>00601     <span class="comment">/* Binarize the image */</span>
+<a name="l00602"></a>00602     bin_im = cpl_mask_threshold_image_create(filt_im, threshold,
+<a name="l00603"></a>00603             SINFO_DBL_MAX);
+<a name="l00604"></a>00604     cpl_image_delete(filt_im) ;
+<a name="l00605"></a>00605     <span class="keywordflow">if</span> (bin_im == NULL) {
+<a name="l00606"></a>00606         cpl_msg_error(cpl_func, <span class="stringliteral">"cannot binarise the image"</span>) ;
+<a name="l00607"></a>00607         <span class="keywordflow">return</span> NULL ;
+<a name="l00608"></a>00608     }
+<a name="l00609"></a>00609 
+<a name="l00610"></a>00610     <span class="comment">/* Test if there are enough good pixels */</span>
+<a name="l00611"></a>00611     ngoodpix = cpl_mask_count(bin_im) ;
+<a name="l00612"></a>00612     <span class="keywordflow">if</span> (ngoodpix < ARC_MINGOODPIX) {
+<a name="l00613"></a>00613         cpl_msg_error(cpl_func, <span class="stringliteral">"Too few (%d) white pixels"</span>, ngoodpix) ;
+<a name="l00614"></a>00614         cpl_mask_delete(bin_im) ;
+<a name="l00615"></a>00615         <span class="keywordflow">return</span> NULL ;
+<a name="l00616"></a>00616     }
+<a name="l00617"></a>00617 
+<a name="l00618"></a>00618     <span class="comment">/* Apply a morphological closing to clean the isolated pixels */</span>
+<a name="l00619"></a>00619     filter = cpl_matrix_new(3, 3) ;
+<a name="l00620"></a>00620     cpl_matrix_fill(filter, 1.0) ;
+<a name="l00621"></a>00621     cpl_mask_closing(bin_im, filter) ;
+<a name="l00622"></a>00622     cpl_matrix_delete(filter) ;
+<a name="l00623"></a>00623 
+<a name="l00624"></a>00624     <span class="comment">/* Labelize pixel map to a label image */</span>
+<a name="l00625"></a>00625     *label_im = cpl_image_labelise_mask_create(bin_im, &nobj) ;
+<a name="l00626"></a>00626     cpl_mask_delete(bin_im) ;
+<a name="l00627"></a>00627     <span class="comment">//cpl_image_save(*label_im,"out_label_im.fits",CPL_BPP_IEEE_FLOAT,</span>
+<a name="l00628"></a>00628     <span class="comment">//               NULL,CPL_IO_DEFAULT);</span>
+<a name="l00629"></a>00629 
+<a name="l00630"></a>00630     <span class="comment">/* Compute statistics on objects */</span>
+<a name="l00631"></a>00631     <span class="keywordflow">if</span> ((det = cpl_apertures_new_from_image(im, *label_im)) == NULL) {
+<a name="l00632"></a>00632         cpl_msg_error(cpl_func, <span class="stringliteral">"Cannot compute arcs stats"</span>) ;
+<a name="l00633"></a>00633         cpl_image_delete(*label_im) ;
+<a name="l00634"></a>00634         *label_im = NULL ;
+<a name="l00635"></a>00635         <span class="keywordflow">return</span> NULL ;
+<a name="l00636"></a>00636     }
+<a name="l00637"></a>00637     <span class="comment">/* Set min_arclen */</span>
+<a name="l00638"></a>00638     min_arclen = (int)(ny /arcs_min_arclen_factor) ;
+<a name="l00639"></a>00639     <span class="comment">//cpl_image_save(im,"out_im.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT);</span>
+<a name="l00640"></a>00640 
+<a name="l00641"></a>00641     <span class="comment">/* Purge non-relevant arcs */</span>
+<a name="l00642"></a>00642     <span class="comment">/* cpl_apertures_dump(det,stdout); */</span>
+<a name="l00643"></a>00643     <span class="keywordflow">if</span> (sinfo_distortion_purge_arcs(im, &det, label_im, min_arclen,
+<a name="l00644"></a>00644                 max_arc_width, arc_sat) == -1) {
+<a name="l00645"></a>00645         cpl_msg_error(cpl_func, <span class="stringliteral">"Cannot purge the arcs"</span>) ;
+<a name="l00646"></a>00646         cpl_image_delete(*label_im) ;
+<a name="l00647"></a>00647         *label_im = NULL ;
+<a name="l00648"></a>00648         cpl_apertures_delete(det) ;
+<a name="l00649"></a>00649         <span class="keywordflow">return</span> NULL ;
+<a name="l00650"></a>00650     }
+<a name="l00651"></a>00651     <span class="comment">/* cpl_apertures_dump(det,stdout); */</span>
+<a name="l00652"></a>00652     <span class="keywordflow">if</span> (cpl_apertures_get_size(det) < ARC_MINNBARCS) {
+<a name="l00653"></a>00653         cpl_msg_error(cpl_func, <span class="stringliteral">"Not enough valid arcs (%"</span> 
+<a name="l00654"></a>00654                       CPL_SIZE_FORMAT <span class="stringliteral">" < %d)"</span>,
+<a name="l00655"></a>00655                 cpl_apertures_get_size(det), ARC_MINNBARCS) ;
+<a name="l00656"></a>00656         cpl_image_delete(*label_im) ;
+<a name="l00657"></a>00657         *label_im = NULL ;
+<a name="l00658"></a>00658         cpl_apertures_delete(det) ;
+<a name="l00659"></a>00659         <span class="keywordflow">return</span> NULL ;
+<a name="l00660"></a>00660     }
+<a name="l00661"></a>00661 
+<a name="l00662"></a>00662     <span class="comment">/* Return  */</span>
+<a name="l00663"></a>00663     <span class="keywordflow">return</span> det ;
+<a name="l00664"></a>00664 }
+<a name="l00665"></a>00665 
+<a name="l00666"></a>00666 
+<a name="l00667"></a>00667 
+<a name="l00668"></a>00668 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00692"></a>00692 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00693"></a>00693 cpl_polynomial * sinfo_distortion_estimate(
+<a name="l00694"></a>00694         <span class="keyword">const</span> cpl_image *   org,
+<a name="l00695"></a>00695         <span class="keywordtype">int</span>                 xmin,
+<a name="l00696"></a>00696         <span class="keywordtype">int</span>                 ymin,
+<a name="l00697"></a>00697         <span class="keywordtype">int</span>                 xmax,
+<a name="l00698"></a>00698         <span class="keywordtype">int</span>                 ymax,
+<a name="l00699"></a>00699         <span class="keywordtype">int</span>                 auto_ramp_sub,
+<a name="l00700"></a>00700         <span class="keywordtype">int</span>                 arc_sat,
+<a name="l00701"></a>00701         <span class="keywordtype">int</span>                 max_arc_width,
+<a name="l00702"></a>00702         <span class="keywordtype">int</span>                 degree,
+<a name="l00703"></a>00703         <span class="keywordtype">double</span>              offset,
+<a name="l00704"></a>00704         cpl_apertures   **  arcs)
+<a name="l00705"></a>00705 {
+<a name="l00706"></a>00706     <span class="keyword">const</span> <span class="keywordtype">char</span>      *   fctid = <span class="stringliteral">"sinfo_distortion_estimate"</span> ;
+<a name="l00707"></a>00707     cpl_image       *   local_im ;
+<a name="l00708"></a>00708     cpl_image       *   label_image ;
+<a name="l00709"></a>00709     <span class="keywordtype">double</span>              rightmost, leftmost ;
+<a name="l00710"></a>00710     cpl_bivector    **  arcs_pos ;
+<a name="l00711"></a>00711     <span class="keywordtype">double</span>          *   parc_posx ;
+<a name="l00712"></a>00712     <span class="keywordtype">double</span>          *   parc_posy ;
+<a name="l00713"></a>00713     <span class="keywordtype">double</span>          *   lines_pos ;
+<a name="l00714"></a>00714     cpl_bivector    *   grid ;
+<a name="l00715"></a>00715     <span class="keywordtype">double</span>          *   pgridx ;
+<a name="l00716"></a>00716     <span class="keywordtype">double</span>          *   pgridy ;
+<a name="l00717"></a>00717     cpl_vector      *   values_to_fit ;
+<a name="l00718"></a>00718     <span class="keywordtype">double</span>          *   pvalues_to_fit ;
+<a name="l00719"></a>00719     <span class="keywordtype">int</span>                 min_arc_range ;
+<a name="l00720"></a>00720     <span class="keywordtype">int</span>                 n_calib ;
+<a name="l00721"></a>00721     <span class="keywordtype">int</span>                 n_arcs ;
+<a name="l00722"></a>00722     cpl_polynomial  *   poly2d ;
+<a name="l00723"></a>00723     <span class="keywordtype">int</span>                 nx ;
+<a name="l00724"></a>00724     <span class="keywordtype">int</span>                 i, j ;
+<a name="l00725"></a>00725 
+<a name="l00726"></a>00726     <span class="comment">/* AMO added to use offset */</span>
+<a name="l00727"></a>00727     cpl_vector    *     lines_pos_tmp ;
+<a name="l00728"></a>00728     cpl_bivector    *   grid_tmp ;
+<a name="l00729"></a>00729     <span class="keywordtype">int</span> n_lines=0;
+<a name="l00730"></a>00730     <span class="keywordtype">int</span> k=0;
+<a name="l00731"></a>00731     cpl_vector* grid_tot=0;
+<a name="l00732"></a>00732     <span class="keywordtype">double</span>* pgrid_tmp_x=NULL;
+<a name="l00733"></a>00733     <span class="keywordtype">double</span>* pgrid_tmp_y=NULL;
+<a name="l00734"></a>00734     <span class="keywordtype">double</span>* pgrid_tot=NULL;
+<a name="l00735"></a>00735     <span class="keywordtype">double</span>* plines_pos_tmp=NULL;
+<a name="l00736"></a>00736 
+<a name="l00737"></a>00737     <span class="comment">/* Check entries */</span>
+<a name="l00738"></a>00738     <span class="keywordflow">if</span> (org == NULL) <span class="keywordflow">return</span> NULL ;
+<a name="l00739"></a>00739 
+<a name="l00740"></a>00740     <span class="comment">/* Initialise */</span>
+<a name="l00741"></a>00741     n_calib = ARC_NBSAMPLES ;
+<a name="l00742"></a>00742     nx = cpl_image_get_size_x(org) ;
+<a name="l00743"></a>00743 
+<a name="l00744"></a>00744     <span class="keywordflow">if</span> (auto_ramp_sub) {
+<a name="l00745"></a>00745         local_im = sinfo_distortion_remove_ramp(org) ;
+<a name="l00746"></a>00746     } <span class="keywordflow">else</span> {
+<a name="l00747"></a>00747         <span class="comment">/* Local copy of input image */</span>
+<a name="l00748"></a>00748         local_im = cpl_image_duplicate(org) ;
+<a name="l00749"></a>00749     }
+<a name="l00750"></a>00750     <span class="keywordflow">if</span> (local_im == NULL) {
+<a name="l00751"></a>00751         cpl_msg_error(fctid, <span class="stringliteral">"Cannot clean the image"</span>) ;
+<a name="l00752"></a>00752         <span class="keywordflow">return</span> NULL ;
+<a name="l00753"></a>00753     }
+<a name="l00754"></a>00754 
+<a name="l00755"></a>00755     <span class="comment">/* Detect the arcs in the input image */</span>
+<a name="l00756"></a>00756     cpl_msg_info(fctid, <span class="stringliteral">"Detect arcs"</span>) ;
+<a name="l00757"></a>00757     <span class="keywordflow">if</span> ((*arcs = sinfo_distortion_detect_arcs(local_im,
+<a name="l00758"></a>00758                     &label_image,
+<a name="l00759"></a>00759                     arc_sat, max_arc_width,
+<a name="l00760"></a>00760                     xmin, ymin, xmax, ymax)) == NULL) {
+<a name="l00761"></a>00761         cpl_image_delete(local_im) ;
+<a name="l00762"></a>00762         cpl_msg_error(fctid, <span class="stringliteral">"Cannot detect the arcs"</span>) ;
+<a name="l00763"></a>00763         <span class="keywordflow">return</span> NULL ;
+<a name="l00764"></a>00764     }
+<a name="l00765"></a>00765     n_arcs = cpl_apertures_get_size(*arcs) ;
+<a name="l00766"></a>00766     cpl_msg_info(fctid, <span class="stringliteral">"%d detected arcs"</span>, n_arcs) ;
+<a name="l00767"></a>00767 
+<a name="l00768"></a>00768     <span class="comment">/* Check that the arcs are not concentrated in the same zone */</span>
+<a name="l00769"></a>00769     rightmost = leftmost = cpl_apertures_get_pos_x(*arcs, 1) ;
+<a name="l00770"></a>00770     <span class="keywordflow">for</span> (i=1 ; i<n_arcs ; i++) {
+<a name="l00771"></a>00771         <span class="keywordflow">if</span> (cpl_apertures_get_pos_x(*arcs, i+1) < leftmost)
+<a name="l00772"></a>00772             leftmost = cpl_apertures_get_pos_x(*arcs, i+1) ;
+<a name="l00773"></a>00773         <span class="keywordflow">if</span> (cpl_apertures_get_pos_x(*arcs, i+1) > rightmost)
+<a name="l00774"></a>00774             rightmost = cpl_apertures_get_pos_x(*arcs, i+1) ;
+<a name="l00775"></a>00775     }
+<a name="l00776"></a>00776     min_arc_range = (int)(nx / ARC_RANGE_FACT) ;
+<a name="l00777"></a>00777     <span class="keywordflow">if</span> ((<span class="keywordtype">int</span>)(rightmost-leftmost) < min_arc_range) {
+<a name="l00778"></a>00778         cpl_msg_error(fctid, <span class="stringliteral">"too narrow range (%g-%g)<%d"</span>,
+<a name="l00779"></a>00779                 rightmost, leftmost, min_arc_range) ;
+<a name="l00780"></a>00780         cpl_apertures_delete(*arcs) ;
+<a name="l00781"></a>00781         cpl_image_delete(local_im) ;
+<a name="l00782"></a>00782         cpl_image_delete(label_image) ;
+<a name="l00783"></a>00783         <span class="keywordflow">return</span> NULL ;
+<a name="l00784"></a>00784     }
+<a name="l00785"></a>00785 
+<a name="l00786"></a>00786     <span class="comment">/* Create a 2-D deformation grid with detected arcs */</span>
+<a name="l00787"></a>00787     cpl_msg_info(fctid, <span class="stringliteral">"Create deformation grid"</span>) ;
+<a name="l00788"></a>00788     lines_pos = cpl_malloc(n_arcs * <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>)) ;
+<a name="l00789"></a>00789     <span class="keywordflow">if</span> ((arcs_pos = sinfo_distortion_get_arc_positions(local_im,
+<a name="l00790"></a>00790                     label_image, *arcs, n_calib, &lines_pos))==NULL){
+<a name="l00791"></a>00791         cpl_msg_error(fctid, <span class="stringliteral">"cannot get arcs positions"</span>) ;
+<a name="l00792"></a>00792         cpl_apertures_delete(*arcs) ;
+<a name="l00793"></a>00793         cpl_image_delete(local_im) ;
+<a name="l00794"></a>00794         cpl_free(lines_pos) ;
+<a name="l00795"></a>00795         cpl_image_delete(label_image) ;
+<a name="l00796"></a>00796         <span class="keywordflow">return</span> NULL ;
+<a name="l00797"></a>00797     }
+<a name="l00798"></a>00798     cpl_image_delete(label_image) ;
+<a name="l00799"></a>00799     cpl_image_delete(local_im) ;
+<a name="l00800"></a>00800 
+<a name="l00801"></a>00801     <span class="comment">/* Prepare the fitting */</span>
+<a name="l00802"></a>00802     lines_pos_tmp=cpl_vector_new(n_arcs);
+<a name="l00803"></a>00803     plines_pos_tmp=cpl_vector_get_data(lines_pos_tmp);
+<a name="l00804"></a>00804 
+<a name="l00805"></a>00805     cpl_msg_info(fctid, <span class="stringliteral">"Fit the 2d polynomial"</span>) ;
+<a name="l00806"></a>00806     grid = cpl_bivector_new(n_arcs * n_calib) ;
+<a name="l00807"></a>00807     pgridx = cpl_bivector_get_x_data(grid) ;
+<a name="l00808"></a>00808     pgridy = cpl_bivector_get_y_data(grid) ;
+<a name="l00809"></a>00809     values_to_fit = cpl_vector_new(n_arcs * n_calib) ;
+<a name="l00810"></a>00810     pvalues_to_fit = cpl_vector_get_data(values_to_fit) ;
+<a name="l00811"></a>00811     <span class="keywordflow">for</span> (i=0 ; i<n_arcs ; i++) {
+<a name="l00812"></a>00812         parc_posx = cpl_bivector_get_x_data(arcs_pos[i]) ;
+<a name="l00813"></a>00813         parc_posy = cpl_bivector_get_y_data(arcs_pos[i]) ;
+<a name="l00814"></a>00814         <span class="keywordflow">for</span> (j=0 ; j<n_calib ; j++) {
+<a name="l00815"></a>00815             plines_pos_tmp[i]=lines_pos[i] ;
+<a name="l00816"></a>00816             pgridx[j+i*n_calib] = lines_pos[i] ;
+<a name="l00817"></a>00817             pgridy[j+i*n_calib] = parc_posy[j] ;
+<a name="l00818"></a>00818             pvalues_to_fit[j+i*n_calib] = parc_posx[j];
+<a name="l00819"></a>00819 
+<a name="l00820"></a>00820 <span class="comment">/*</span>
+<a name="l00821"></a>00821 <span class="comment">      sinfo_msg("pgridx=%g pgridy=%g pvalues=%g",</span>
+<a name="l00822"></a>00822 <span class="comment">          pgridx[j+i*n_calib],pgridy[j+i*n_calib],pvalues_to_fit[j+i*n_calib]);</span>
+<a name="l00823"></a>00823 <span class="comment">*/</span>
+<a name="l00824"></a>00824         }
+<a name="l00825"></a>00825     }
+<a name="l00826"></a>00826 
+<a name="l00827"></a>00827 
+<a name="l00828"></a>00828     <span class="comment">/* AMO new to use offset */</span>
+<a name="l00829"></a>00829     n_lines= n_arcs/32.0;
+<a name="l00830"></a>00830     <span class="keywordflow">if</span>(n_lines < 1) {
+<a name="l00831"></a>00831       n_lines=1;
+<a name="l00832"></a>00832     }
+<a name="l00833"></a>00833     cpl_vector_sort(lines_pos_tmp,1);
+<a name="l00834"></a>00834     plines_pos_tmp=cpl_vector_get_data(lines_pos_tmp);
+<a name="l00835"></a>00835 
+<a name="l00836"></a>00836     grid_tmp=cpl_bivector_duplicate(grid);
+<a name="l00837"></a>00837     grid_tot=cpl_vector_new(n_calib);
+<a name="l00838"></a>00838     pgrid_tmp_x = cpl_bivector_get_x_data(grid_tmp) ;
+<a name="l00839"></a>00839     pgrid_tmp_y = cpl_bivector_get_y_data(grid_tmp) ;
+<a name="l00840"></a>00840     pgrid_tot = cpl_vector_get_data(grid_tot);
+<a name="l00841"></a>00841     <span class="keywordflow">for</span>(j=0;j<n_calib;j++) {
+<a name="l00842"></a>00842       pgrid_tot[j]=0;
+<a name="l00843"></a>00843       <span class="keywordflow">for</span>(i=n_lines ;i<n_arcs;i=i+n_lines)
+<a name="l00844"></a>00844     {
+<a name="l00845"></a>00845       <span class="keywordflow">for</span>(k=0;k<n_lines;k++) {
+<a name="l00846"></a>00846         pgrid_tot[j] += (plines_pos_tmp[i+k]-
+<a name="l00847"></a>00847                              plines_pos_tmp[k]);
+<a name="l00848"></a>00848         <span class="comment">/*</span>
+<a name="l00849"></a>00849 <span class="comment">            sinfo_msg("diff=%g",(plines_pos_tmp[i+k]-</span>
+<a name="l00850"></a>00850 <span class="comment">                 plines_pos_tmp[k]));</span>
+<a name="l00851"></a>00851 <span class="comment">        */</span>
+<a name="l00852"></a>00852       }
+<a name="l00853"></a>00853     }
+<a name="l00854"></a>00854       <span class="comment">/*</span>
+<a name="l00855"></a>00855 <span class="comment">      sinfo_msg("j=%d pgrid_tot=%g",j,pgrid_tot[j]);</span>
+<a name="l00856"></a>00856 <span class="comment">      */</span>
+<a name="l00857"></a>00857     }
+<a name="l00858"></a>00858 
+<a name="l00859"></a>00859     <span class="keywordflow">for</span>(j=0;j<n_calib;j++) {
+<a name="l00860"></a>00860       <span class="keywordflow">for</span> (i=0 ; i<n_arcs ; i++) {
+<a name="l00861"></a>00861      pgridx[j+i*n_calib]=pgridx[j+i*n_calib]*
+<a name="l00862"></a>00862                              ((nx/32.0)*n_lines*(31*32/2))/pgrid_tot[j]-offset;
+<a name="l00863"></a>00863      <span class="comment">/*</span>
+<a name="l00864"></a>00864 <span class="comment">         sinfo_msg_error("AMo after corr grid[%d,%d]=%g",</span>
+<a name="l00865"></a>00865 <span class="comment">                          i,k,pgridx[k+i*n_calib]);</span>
+<a name="l00866"></a>00866 <span class="comment">     */</span>
+<a name="l00867"></a>00867      pgrid_tmp_x[j+i*n_calib]=pgrid_tmp_x[j+i*n_calib]*
+<a name="l00868"></a>00868                                   ((nx/32.0)*n_lines*(31*32/2))/pgrid_tot[j]-
+<a name="l00869"></a>00869                                    offset;
+<a name="l00870"></a>00870 
+<a name="l00871"></a>00871       }
+<a name="l00872"></a>00872     }
+<a name="l00873"></a>00873     <span class="comment">/* end AMO: to use the offset */</span>
+<a name="l00874"></a>00874 
+<a name="l00875"></a>00875 
+<a name="l00876"></a>00876     <span class="keywordflow">for</span> (i=0 ; i<n_arcs ; i++) cpl_bivector_delete(arcs_pos[i]) ;
+<a name="l00877"></a>00877     cpl_free(arcs_pos) ;
+<a name="l00878"></a>00878     cpl_free(lines_pos) ;
+<a name="l00879"></a>00879 
+<a name="l00880"></a>00880     <span class="comment">/* Apply the fitting */</span>
+<a name="l00881"></a>00881     <span class="keywordflow">if</span> ((poly2d = sinfo_polynomial_fit_2d_create(grid, values_to_fit,
+<a name="l00882"></a>00882                     degree, NULL))==NULL) {
+<a name="l00883"></a>00883         cpl_msg_error(fctid, <span class="stringliteral">"cannot apply the 2d fit"</span>) ;
+<a name="l00884"></a>00884         cpl_bivector_delete(grid) ;
+<a name="l00885"></a>00885         cpl_vector_delete(values_to_fit) ;
+<a name="l00886"></a>00886         cpl_apertures_delete(*arcs) ;
+<a name="l00887"></a>00887         <span class="keywordflow">return</span> NULL ;
+<a name="l00888"></a>00888     }
+<a name="l00889"></a>00889 
+<a name="l00890"></a>00890     <span class="comment">/* Free and return */</span>
+<a name="l00891"></a>00891     cpl_bivector_delete(grid) ;
+<a name="l00892"></a>00892     cpl_vector_delete(values_to_fit) ;
+<a name="l00893"></a>00893     <span class="keywordflow">return</span> poly2d ;
+<a name="l00894"></a>00894 }
+<a name="l00895"></a>00895 
+<a name="l00898"></a>00898 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00913"></a>00913 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00914"></a>00914 <span class="keyword">static</span> cpl_apertures * sinfo_distortion_detect_arcs(
+<a name="l00915"></a>00915         cpl_image   *   im,
+<a name="l00916"></a>00916         cpl_image   **  label_im,
+<a name="l00917"></a>00917         <span class="keywordtype">int</span>             arc_sat,
+<a name="l00918"></a>00918         <span class="keywordtype">int</span>             max_arc_width,
+<a name="l00919"></a>00919         <span class="keywordtype">int</span>             xmin,
+<a name="l00920"></a>00920         <span class="keywordtype">int</span>             ymin,
+<a name="l00921"></a>00921         <span class="keywordtype">int</span>             xmax,
+<a name="l00922"></a>00922         <span class="keywordtype">int</span>             ymax)
+<a name="l00923"></a>00923 {
+<a name="l00924"></a>00924     <span class="keyword">const</span> <span class="keywordtype">char</span>      *   fctid = <span class="stringliteral">"sinfo_distortion_detect_arcs"</span> ;
+<a name="l00925"></a>00925     cpl_image       *   filt_im ;
+<a name="l00926"></a>00926     cpl_matrix      *   filter ;
+<a name="l00927"></a>00927     cpl_image       *   collapsed ;
+<a name="l00928"></a>00928     cpl_mask        *   bin_im ;
+<a name="l00929"></a>00929     <span class="keywordtype">double</span>              threshold, fillval, median_val, sigma ;
+<a name="l00930"></a>00930     <span class="keywordtype">int</span>                 min_arclen = 0 ;
+<a name="l00931"></a>00931     cpl_apertures   *   det ;
+<a name="l00932"></a>00932     cpl_size                 nobj ;
+<a name="l00933"></a>00933     <span class="keywordtype">int</span>                 ngoodpix ;
+<a name="l00934"></a>00934     <span class="keywordtype">int</span>                 ny ;
+<a name="l00935"></a>00935 
+<a name="l00936"></a>00936     ny = cpl_image_get_size_y(im) ;
+<a name="l00937"></a>00937 
+<a name="l00938"></a>00938     <span class="comment">/* Default values for output parameters */</span>
+<a name="l00939"></a>00939     *label_im = NULL ;
+<a name="l00940"></a>00940 
+<a name="l00941"></a>00941     <span class="comment">/* Clear zones to be ignored (to avoid false detections) */</span>
+<a name="l00942"></a>00942     median_val = cpl_image_get_median_dev(im, &sigma) ;
+<a name="l00943"></a>00943     fillval = median_val-sigma/2.0 ;
+<a name="l00944"></a>00944     <span class="keywordflow">if</span> (sinfo_distortion_fill_badzones(im, xmin, ymin, xmax, ymax,
+<a name="l00945"></a>00945                 fillval) == -1) {
+<a name="l00946"></a>00946         cpl_msg_error(fctid, <span class="stringliteral">"cannot fill bad zones"</span>) ;
+<a name="l00947"></a>00947         <span class="keywordflow">return</span> NULL ;
+<a name="l00948"></a>00948     }
+<a name="l00949"></a>00949 
+<a name="l00950"></a>00950     <span class="comment">/* Median vertical filter */</span>
+<a name="l00951"></a>00951     filter = cpl_matrix_new(3, 1) ;
+<a name="l00952"></a>00952     cpl_matrix_fill(filter, 1.0) ;
+<a name="l00953"></a>00953     <span class="comment">/* filt_im = cpl_image_filter_median(im, filter) ; */</span>
+<a name="l00954"></a>00954     filt_im = cpl_image_duplicate(im) ;
+<a name="l00955"></a>00955     cpl_matrix_delete(filter) ;
+<a name="l00956"></a>00956 
+<a name="l00957"></a>00957     <span class="comment">/* Subtract a low-pass */</span>
+<a name="l00958"></a>00958     <span class="keywordflow">if</span> (sinfo_distortion_sub_hor_lowpass(filt_im, ARC_WINDOWSIZE) == -1) {
+<a name="l00959"></a>00959         cpl_image_delete(filt_im) ;
+<a name="l00960"></a>00960         <span class="keywordflow">return</span> NULL ;
+<a name="l00961"></a>00961     }
+<a name="l00962"></a>00962 
+<a name="l00963"></a>00963     <span class="comment">/* Get relevant stats for thresholding */</span>
+<a name="l00964"></a>00964     median_val = cpl_image_get_median_dev(filt_im, &sigma) ;
+<a name="l00965"></a>00965 
+<a name="l00966"></a>00966     <span class="comment">/* Correct median_val and sigma if necessary */</span>
+<a name="l00967"></a>00967     <span class="keywordflow">if</span> (median_val < TRESH_MEDIAN_MIN) median_val = TRESH_MEDIAN_MIN ;
+<a name="l00968"></a>00968     <span class="keywordflow">if</span> (sigma > TRESH_SIGMA_MAX) sigma = TRESH_SIGMA_MAX ;
+<a name="l00969"></a>00969 
+<a name="l00970"></a>00970     <span class="comment">/* Set the threshold */</span>
+<a name="l00971"></a>00971     threshold = median_val + sigma * ARC_THRESHFACT ;
+<a name="l00972"></a>00972 
+<a name="l00973"></a>00973     <span class="comment">/* Collapse the image */</span>
+<a name="l00974"></a>00974     collapsed = cpl_image_collapse_median_create(filt_im, 0, 0, 0) ;
+<a name="l00975"></a>00975 
+<a name="l00976"></a>00976     <span class="comment">/* Threshold to keep only the arcs - use of the collapsed image */</span>
+<a name="l00977"></a>00977     <span class="keywordflow">if</span> (sinfo_distortion_threshold1d(filt_im, median_val,
+<a name="l00978"></a>00978                                      collapsed, 0.0)==-1) {
+<a name="l00979"></a>00979         cpl_msg_error(fctid, <span class="stringliteral">"cannot threshold the filtered image"</span>) ;
+<a name="l00980"></a>00980         cpl_image_delete(filt_im) ;
+<a name="l00981"></a>00981         cpl_image_delete(collapsed) ;
+<a name="l00982"></a>00982         <span class="keywordflow">return</span> NULL ;
+<a name="l00983"></a>00983     }
+<a name="l00984"></a>00984     cpl_image_delete(collapsed) ;
+<a name="l00985"></a>00985 
+<a name="l00986"></a>00986     <span class="comment">/* Binarize the image */</span>
+<a name="l00987"></a>00987     bin_im = cpl_mask_threshold_image_create(filt_im, threshold,
+<a name="l00988"></a>00988             SINFO_DBL_MAX);
+<a name="l00989"></a>00989     cpl_image_delete(filt_im) ;
+<a name="l00990"></a>00990     <span class="keywordflow">if</span> (bin_im == NULL) {
+<a name="l00991"></a>00991         cpl_msg_error(fctid, <span class="stringliteral">"cannot binarise the image"</span>) ;
+<a name="l00992"></a>00992         <span class="keywordflow">return</span> NULL ;
+<a name="l00993"></a>00993     }
+<a name="l00994"></a>00994 
+<a name="l00995"></a>00995     <span class="comment">/* Test if there are enough good pixels */</span>
+<a name="l00996"></a>00996     ngoodpix = cpl_mask_count(bin_im) ;
+<a name="l00997"></a>00997     <span class="keywordflow">if</span> (ngoodpix < ARC_MINGOODPIX) {
+<a name="l00998"></a>00998         cpl_msg_error(fctid, <span class="stringliteral">"Too few (%d) white pixels"</span>, ngoodpix) ;
+<a name="l00999"></a>00999         cpl_mask_delete(bin_im) ;
+<a name="l01000"></a>01000         <span class="keywordflow">return</span> NULL ;
+<a name="l01001"></a>01001     }
+<a name="l01002"></a>01002 
+<a name="l01003"></a>01003     <span class="comment">/* Apply a morphological closing to clean the isolated pixels */</span>
+<a name="l01004"></a>01004     filter = cpl_matrix_new(3, 3) ;
+<a name="l01005"></a>01005     cpl_matrix_fill(filter, 1.0) ;
+<a name="l01006"></a>01006     cpl_mask_closing(bin_im, filter) ;
+<a name="l01007"></a>01007     cpl_matrix_delete(filter) ;
+<a name="l01008"></a>01008 
+<a name="l01009"></a>01009     <span class="comment">/* Labelize pixel map to a label image */</span>
+<a name="l01010"></a>01010     *label_im = cpl_image_labelise_mask_create(bin_im, &nobj) ;
+<a name="l01011"></a>01011     cpl_mask_delete(bin_im) ;
+<a name="l01012"></a>01012 
+<a name="l01013"></a>01013     <span class="comment">/* Compute statistics on objects */</span>
+<a name="l01014"></a>01014     <span class="keywordflow">if</span> ((det = cpl_apertures_new_from_image(im, *label_im)) == NULL) {
+<a name="l01015"></a>01015         cpl_msg_error(fctid, <span class="stringliteral">"Cannot compute arcs stats"</span>) ;
+<a name="l01016"></a>01016         cpl_image_delete(*label_im) ;
+<a name="l01017"></a>01017         *label_im = NULL ;
+<a name="l01018"></a>01018         <span class="keywordflow">return</span> NULL ;
+<a name="l01019"></a>01019     }
+<a name="l01020"></a>01020 
+<a name="l01021"></a>01021     <span class="comment">/* Set min_arclen */</span>
+<a name="l01022"></a>01022     min_arclen = (int)(ny / ARC_MINARCLENFACT) ;
+<a name="l01023"></a>01023 
+<a name="l01024"></a>01024     <span class="comment">/* Purge non-relevant arcs */</span>
+<a name="l01025"></a>01025     <span class="keywordflow">if</span> (sinfo_distortion_purge_arcs(im, &det, label_im, min_arclen,
+<a name="l01026"></a>01026                 max_arc_width, arc_sat) == -1) {
+<a name="l01027"></a>01027         cpl_msg_error(fctid, <span class="stringliteral">"Cannot purge the arcs"</span>) ;
+<a name="l01028"></a>01028         cpl_image_delete(*label_im) ;
+<a name="l01029"></a>01029         *label_im = NULL ;
+<a name="l01030"></a>01030         cpl_apertures_delete(det) ;
+<a name="l01031"></a>01031         <span class="keywordflow">return</span> NULL ;
+<a name="l01032"></a>01032     }
+<a name="l01033"></a>01033     <span class="keywordflow">if</span> (cpl_apertures_get_size(det) < ARC_MINNBARCS) {
+<a name="l01034"></a>01034         cpl_msg_error(fctid, <span class="stringliteral">"Not enough valid arcs (%"</span> 
+<a name="l01035"></a>01035                       CPL_SIZE_FORMAT <span class="stringliteral">" < %d)"</span>,
+<a name="l01036"></a>01036                 cpl_apertures_get_size(det), ARC_MINNBARCS) ;
+<a name="l01037"></a>01037         cpl_image_delete(*label_im) ;
+<a name="l01038"></a>01038         *label_im = NULL ;
+<a name="l01039"></a>01039         cpl_apertures_delete(det) ;
+<a name="l01040"></a>01040         <span class="keywordflow">return</span> NULL ;
+<a name="l01041"></a>01041     }
+<a name="l01042"></a>01042 
+<a name="l01043"></a>01043     <span class="comment">/* Return  */</span>
+<a name="l01044"></a>01044     <span class="keywordflow">return</span> det ;
+<a name="l01045"></a>01045 }
+<a name="l01046"></a>01046 
+<a name="l01047"></a>01047 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_distortion_fill_badzones(
+<a name="l01048"></a>01048         cpl_image   *   im,
+<a name="l01049"></a>01049         <span class="keywordtype">int</span>             xmin,
+<a name="l01050"></a>01050         <span class="keywordtype">int</span>             ymin,
+<a name="l01051"></a>01051         <span class="keywordtype">int</span>             xmax,
+<a name="l01052"></a>01052         <span class="keywordtype">int</span>             ymax,
+<a name="l01053"></a>01053         <span class="keywordtype">double</span>          fillval)
+<a name="l01054"></a>01054 {
+<a name="l01055"></a>01055     <span class="keywordtype">float</span>       *   pfi ;
+<a name="l01056"></a>01056     <span class="keywordtype">int</span>             nx, ny ;
+<a name="l01057"></a>01057     <span class="keywordtype">int</span>             i, j ;
+<a name="l01058"></a>01058 
+<a name="l01059"></a>01059     <span class="comment">/* Check entries */</span>
+<a name="l01060"></a>01060     <span class="keywordflow">if</span> (im == NULL) <span class="keywordflow">return</span> -1 ;
+<a name="l01061"></a>01061     <span class="keywordflow">if</span> (cpl_image_get_type(im) != CPL_TYPE_FLOAT) <span class="keywordflow">return</span> -1 ;
+<a name="l01062"></a>01062 
+<a name="l01063"></a>01063     <span class="comment">/* Get the data */</span>
+<a name="l01064"></a>01064     pfi = cpl_image_get_data_float(im) ;
+<a name="l01065"></a>01065     nx = cpl_image_get_size_x(im) ;
+<a name="l01066"></a>01066     ny = cpl_image_get_size_y(im) ;
+<a name="l01067"></a>01067 
+<a name="l01068"></a>01068     <span class="comment">/* Fill the zone */</span>
+<a name="l01069"></a>01069     <span class="keywordflow">for</span> (i=0 ; i<nx ; i++) {
+<a name="l01070"></a>01070         <span class="keywordflow">for</span> (j=0 ; j<ny ; j++) {
+<a name="l01071"></a>01071             <span class="keywordflow">if</span> ((i<xmin-1) || (i>xmax-1) || (j<ymin-1) || (j>ymax-1)) {
+<a name="l01072"></a>01072                 pfi[i+j*nx] = (float)fillval ;
+<a name="l01073"></a>01073             }
+<a name="l01074"></a>01074         }
+<a name="l01075"></a>01075     }
+<a name="l01076"></a>01076     <span class="keywordflow">return</span> 0 ;
+<a name="l01077"></a>01077 }
+<a name="l01078"></a>01078 
+<a name="l01079"></a>01079 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_distortion_threshold1d(
+<a name="l01080"></a>01080         cpl_image   *   im,
+<a name="l01081"></a>01081         <span class="keywordtype">double</span>          threshold,
+<a name="l01082"></a>01082         cpl_image   *   im1d,
+<a name="l01083"></a>01083         <span class="keywordtype">double</span>          newval)
+<a name="l01084"></a>01084 {
+<a name="l01085"></a>01085     <span class="keywordtype">float</span>       *   pim ;
+<a name="l01086"></a>01086     <span class="keywordtype">float</span>       *   pim1d ;
+<a name="l01087"></a>01087     <span class="keywordtype">int</span>             nx, ny ;
+<a name="l01088"></a>01088     <span class="keywordtype">int</span>             i, j ;
+<a name="l01089"></a>01089 
+<a name="l01090"></a>01090     <span class="comment">/* Check entries */</span>
+<a name="l01091"></a>01091     <span class="keywordflow">if</span> (im == NULL) <span class="keywordflow">return</span> -1 ;
+<a name="l01092"></a>01092     <span class="keywordflow">if</span> (im1d == NULL) <span class="keywordflow">return</span> -1 ;
+<a name="l01093"></a>01093     <span class="keywordflow">if</span> (cpl_image_get_type(im) != CPL_TYPE_FLOAT) <span class="keywordflow">return</span> -1 ;
+<a name="l01094"></a>01094     <span class="keywordflow">if</span> (cpl_image_get_type(im1d) != CPL_TYPE_FLOAT) <span class="keywordflow">return</span> -1 ;
+<a name="l01095"></a>01095 
+<a name="l01096"></a>01096     <span class="comment">/* Get access to the im / im1d data */</span>
+<a name="l01097"></a>01097     pim = cpl_image_get_data_float(im) ;
+<a name="l01098"></a>01098     pim1d = cpl_image_get_data_float(im1d) ;
+<a name="l01099"></a>01099     nx = cpl_image_get_size_x(im) ;
+<a name="l01100"></a>01100     ny = cpl_image_get_size_y(im) ;
+<a name="l01101"></a>01101 
+<a name="l01102"></a>01102     <span class="comment">/* Apply the thresholding */</span>
+<a name="l01103"></a>01103     <span class="keywordflow">for</span> (i=0 ; i<nx ; i++)
+<a name="l01104"></a>01104         <span class="keywordflow">if</span> (pim1d[i] < threshold) {
+<a name="l01105"></a>01105             <span class="keywordflow">for</span> (j=0 ; j<ny ; j++) pim[i+j*nx] = (<span class="keywordtype">float</span>)newval ;
+<a name="l01106"></a>01106         }
+<a name="l01107"></a>01107 
+<a name="l01108"></a>01108     <span class="comment">/* Return */</span>
+<a name="l01109"></a>01109     <span class="keywordflow">return</span> 0 ;
+<a name="l01110"></a>01110 }
+<a name="l01111"></a>01111 
+<a name="l01112"></a>01112 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_distortion_sub_hor_lowpass(
+<a name="l01113"></a>01113         cpl_image   *   im,
+<a name="l01114"></a>01114         <span class="keywordtype">int</span>             filt_size)
+<a name="l01115"></a>01115 {
+<a name="l01116"></a>01116     cpl_vector  *   linehi ;
+<a name="l01117"></a>01117     cpl_vector  *   linelo ;
+<a name="l01118"></a>01118     cpl_vector  *   avglinehi ;
+<a name="l01119"></a>01119     cpl_vector  *   avglinelo ;
+<a name="l01120"></a>01120     <span class="keywordtype">double</span>      *   pavglinehi ;
+<a name="l01121"></a>01121     <span class="keywordtype">float</span>       *   pim ;
+<a name="l01122"></a>01122     <span class="keywordtype">int</span>             lopos, hipos, nx, ny ;
+<a name="l01123"></a>01123     <span class="keywordtype">int</span>             i, j ;
+<a name="l01124"></a>01124 
+<a name="l01125"></a>01125     <span class="comment">/* Test entries */</span>
+<a name="l01126"></a>01126     <span class="keywordflow">if</span> (im == NULL) <span class="keywordflow">return</span> -1 ;
+<a name="l01127"></a>01127     <span class="keywordflow">if</span> (filt_size <= 0) <span class="keywordflow">return</span> -1 ;
+<a name="l01128"></a>01128 
+<a name="l01129"></a>01129     <span class="comment">/* Initialise */</span>
+<a name="l01130"></a>01130     nx = cpl_image_get_size_x(im) ;
+<a name="l01131"></a>01131     ny = cpl_image_get_size_y(im) ;
+<a name="l01132"></a>01132     lopos = (int)(ny/4) ;
+<a name="l01133"></a>01133     hipos = (int)(3*ny/4) ;
+<a name="l01134"></a>01134 
+<a name="l01135"></a>01135     <span class="comment">/* Get the vectors out of the image */</span>
+<a name="l01136"></a>01136     <span class="keywordflow">if</span> ((linehi = cpl_vector_new_from_image_row(im, hipos)) == NULL) {
+<a name="l01137"></a>01137         <span class="keywordflow">return</span> -1 ;
+<a name="l01138"></a>01138     }
+<a name="l01139"></a>01139     <span class="keywordflow">if</span> ((linelo = cpl_vector_new_from_image_row(im, lopos)) == NULL) {
+<a name="l01140"></a>01140         cpl_vector_delete(linehi) ;
+<a name="l01141"></a>01141         <span class="keywordflow">return</span> -1 ;
+<a name="l01142"></a>01142     }
+<a name="l01143"></a>01143 
+<a name="l01144"></a>01144     <span class="comment">/* Filter the vectors */</span>
+<a name="l01145"></a>01145     <span class="keywordflow">if</span> ((avglinehi = cpl_vector_filter_median_create(linehi,
+<a name="l01146"></a>01146                     filt_size)) == NULL) {
+<a name="l01147"></a>01147         cpl_vector_delete(linehi) ;
+<a name="l01148"></a>01148         cpl_vector_delete(linelo) ;
+<a name="l01149"></a>01149         <span class="keywordflow">return</span> -1 ;
+<a name="l01150"></a>01150     }
+<a name="l01151"></a>01151     cpl_vector_delete(linehi) ;
+<a name="l01152"></a>01152 
+<a name="l01153"></a>01153     <span class="keywordflow">if</span> ((avglinelo = cpl_vector_filter_median_create(linelo,
+<a name="l01154"></a>01154                     filt_size)) == NULL) {
+<a name="l01155"></a>01155         cpl_vector_delete(linelo) ;
+<a name="l01156"></a>01156         cpl_vector_delete(avglinehi) ;
+<a name="l01157"></a>01157         <span class="keywordflow">return</span> -1 ;
+<a name="l01158"></a>01158     }
+<a name="l01159"></a>01159     cpl_vector_delete(linelo) ;
+<a name="l01160"></a>01160 
+<a name="l01161"></a>01161     <span class="comment">/* Average the filtered vectors to get the low freq signal */</span>
+<a name="l01162"></a>01162     cpl_vector_add(avglinehi, avglinelo) ;
+<a name="l01163"></a>01163     cpl_vector_delete(avglinelo) ;
+<a name="l01164"></a>01164     cpl_vector_divide_scalar(avglinehi, 2.0) ;
+<a name="l01165"></a>01165 
+<a name="l01166"></a>01166     <span class="comment">/* Subtract the low frequency signal */</span>
+<a name="l01167"></a>01167     pavglinehi = cpl_vector_get_data(avglinehi) ;
+<a name="l01168"></a>01168     pim = cpl_image_get_data_float(im) ;
+<a name="l01169"></a>01169     <span class="keywordflow">for</span> (i=0 ; i<nx ; i++) {
+<a name="l01170"></a>01170         <span class="keywordflow">for</span> (j=0 ; j<ny ; j++) {
+<a name="l01171"></a>01171             pim[i+j*nx] -= pavglinehi[i] ;
+<a name="l01172"></a>01172         }
+<a name="l01173"></a>01173     }
+<a name="l01174"></a>01174     cpl_vector_delete(avglinehi) ;
+<a name="l01175"></a>01175 
+<a name="l01176"></a>01176     <span class="keywordflow">return</span> 0 ;
+<a name="l01177"></a>01177 }
+<a name="l01178"></a>01178 
+<a name="l01179"></a>01179 
+<a name="l01180"></a>01180 
+<a name="l01181"></a>01181 
+<a name="l01182"></a>01182 
+<a name="l01183"></a>01183 
+<a name="l01184"></a>01184 
+<a name="l01185"></a>01185 
+<a name="l01186"></a>01186 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_distortion_purge_arcs(
+<a name="l01187"></a>01187         cpl_image       *   im,
+<a name="l01188"></a>01188         cpl_apertures   **  arcs,
+<a name="l01189"></a>01189         cpl_image       **  lab_im,
+<a name="l01190"></a>01190         <span class="keywordtype">int</span>                 min_arclen,
+<a name="l01191"></a>01191         <span class="keywordtype">int</span>                 max_arcwidth,
+<a name="l01192"></a>01192         <span class="keywordtype">double</span>              arc_sat)
+<a name="l01193"></a>01193 {
+<a name="l01194"></a>01194     <span class="keyword">const</span> <span class="keywordtype">char</span>  *   fctid = <span class="stringliteral">"sinfo_distortion_purge_arcs"</span> ;
+<a name="l01195"></a>01195     <span class="keywordtype">int</span>             nb_arcs ;
+<a name="l01196"></a>01196     <span class="keywordtype">int</span>         *   selection ;
+<a name="l01197"></a>01197     <span class="keywordtype">int</span>             arclen, arcwidth, edge ;
+<a name="l01198"></a>01198     <span class="keywordtype">double</span>          mean ;
+<a name="l01199"></a>01199     <span class="keywordtype">int</span>         *   plabim ;
+<a name="l01200"></a>01200     cpl_mask    *   bin_im ;
+<a name="l01201"></a>01201     <span class="keywordtype">int</span>             nx, ny ;
+<a name="l01202"></a>01202     <span class="keywordtype">int</span>             i, j ;
+<a name="l01203"></a>01203 
+<a name="l01204"></a>01204     <span class="comment">/* Check entries */</span>
+<a name="l01205"></a>01205     <span class="keywordflow">if</span> (arcs == NULL) <span class="keywordflow">return</span> -1 ;
+<a name="l01206"></a>01206     <span class="keywordflow">if</span> (*arcs == NULL) <span class="keywordflow">return</span> -1 ;
+<a name="l01207"></a>01207     <span class="keywordflow">if</span> (*lab_im == NULL) <span class="keywordflow">return</span> -1 ;
+<a name="l01208"></a>01208 
+<a name="l01209"></a>01209     <span class="comment">/* Get number of arcs */</span>
+<a name="l01210"></a>01210     nb_arcs = cpl_apertures_get_size(*arcs) ;
+<a name="l01211"></a>01211     nx = cpl_image_get_size_x(*lab_im) ;
+<a name="l01212"></a>01212     ny = cpl_image_get_size_y(*lab_im) ;
+<a name="l01213"></a>01213 
+<a name="l01214"></a>01214     <span class="comment">/* Allocate selection array */</span>
+<a name="l01215"></a>01215     selection = cpl_malloc(nb_arcs * <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>)) ;
+<a name="l01216"></a>01216     <span class="comment">/* Loop on the different arcs candidates */</span>
+<a name="l01217"></a>01217     <span class="comment">/* sinfo_msg("min_arclen=%d max_arcwidth=%d",min_arclen,max_arcwidth); */</span>
+<a name="l01218"></a>01218     <span class="keywordflow">for</span> (i=0 ; i<nb_arcs ; i++) {
+<a name="l01219"></a>01219         arclen = cpl_apertures_get_top(*arcs, i+1) -
+<a name="l01220"></a>01220             cpl_apertures_get_bottom(*arcs, i+1) + 1 ;
+<a name="l01221"></a>01221         arcwidth = cpl_apertures_get_right(*arcs, i+1) -
+<a name="l01222"></a>01222             cpl_apertures_get_left(*arcs, i+1) + 1 ;
+<a name="l01223"></a>01223         edge = cpl_apertures_get_left_y(*arcs, i+1) ;
+<a name="l01224"></a>01224         mean = cpl_apertures_get_mean(*arcs, i+1) ;
+<a name="l01225"></a>01225 
+<a name="l01226"></a>01226         <span class="comment">/* Test if the current object is a valid arc */</span>
+<a name="l01227"></a>01227 
+<a name="l01228"></a>01228         <span class="keywordflow">if</span> (
+<a name="l01229"></a>01229             (arclen>min_arclen) &&
+<a name="l01230"></a>01230         (arcwidth<max_arcwidth) &&
+<a name="l01231"></a>01231             (edge>0) &&
+<a name="l01232"></a>01232             (mean < arc_sat)) {
+<a name="l01233"></a>01233       <span class="comment">/*</span>
+<a name="l01234"></a>01234 <span class="comment">        sinfo_msg_warning("Take Pos=%5.4d len=%d width=%d edge=%d mean=%f ",</span>
+<a name="l01235"></a>01235 <span class="comment">    (cpl_apertures_get_right(*arcs, i+1)+cpl_apertures_get_left(*arcs, i+1))/2,</span>
+<a name="l01236"></a>01236 <span class="comment">     arclen,arcwidth,edge,mean);</span>
+<a name="l01237"></a>01237 <span class="comment">      */</span>
+<a name="l01238"></a>01238             selection[i] = 1 ;
+<a name="l01239"></a>01239         } <span class="keywordflow">else</span> {
+<a name="l01240"></a>01240       <span class="comment">/*</span>
+<a name="l01241"></a>01241 <span class="comment">    sinfo_msg_warning("Rej Pos=%5.4d len=%d width=%d edge=%d mean=%f i=%d",</span>
+<a name="l01242"></a>01242 <span class="comment">         (cpl_apertures_get_right(*arcs, i+1)+</span>
+<a name="l01243"></a>01243 <span class="comment">          cpl_apertures_get_left(*arcs, i+1))/2,arclen,arcwidth,edge,mean,i);</span>
+<a name="l01244"></a>01244 <span class="comment">      */</span>
+<a name="l01245"></a>01245             selection[i] = 0 ;
+<a name="l01246"></a>01246         }
+<a name="l01247"></a>01247     }
+<a name="l01248"></a>01248 
+<a name="l01249"></a>01249     <span class="comment">/* Update the labelised image by erasing non valid arcs */</span>
+<a name="l01250"></a>01250     <span class="keywordflow">for</span> (i=0 ; i<nb_arcs ; i++) {
+<a name="l01251"></a>01251         <span class="keywordflow">if</span> (selection[i] == 0) {
+<a name="l01252"></a>01252             plabim = cpl_image_get_data_int(*lab_im) ;
+<a name="l01253"></a>01253             <span class="keywordflow">for</span> (j=0 ; j<nx*ny ; j++) {
+<a name="l01254"></a>01254                 <span class="keywordflow">if</span> (plabim[j] == i+1) plabim[j] = 0 ;
+<a name="l01255"></a>01255             }
+<a name="l01256"></a>01256         }
+<a name="l01257"></a>01257     }
+<a name="l01258"></a>01258     cpl_free(selection) ;
+<a name="l01259"></a>01259 
+<a name="l01260"></a>01260     <span class="comment">/* Reset the labels to have consecutive ones */</span>
+<a name="l01261"></a>01261     bin_im = cpl_mask_threshold_image_create(*lab_im, 0.5, SINFO_DBL_MAX) ;
+<a name="l01262"></a>01262     cpl_image_delete(*lab_im) ;
+<a name="l01263"></a>01263     *lab_im = cpl_image_labelise_mask_create(bin_im, NULL) ;
+<a name="l01264"></a>01264     cpl_mask_delete(bin_im) ;
+<a name="l01265"></a>01265 
+<a name="l01266"></a>01266     <span class="comment">/* Purge the bad arcs */</span>
+<a name="l01267"></a>01267     cpl_apertures_delete(*arcs) ;
+<a name="l01268"></a>01268     *arcs = cpl_apertures_new_from_image(im, *lab_im) ;
+<a name="l01269"></a>01269 
+<a name="l01270"></a>01270     <span class="comment">/* Check if there are some valid arcs */</span>
+<a name="l01271"></a>01271     <span class="keywordflow">if</span> (cpl_apertures_get_size(*arcs) <= 0) {
+<a name="l01272"></a>01272         cpl_msg_error(fctid, <span class="stringliteral">"No valid arc found"</span>) ;
+<a name="l01273"></a>01273         <span class="keywordflow">return</span> -1 ;
+<a name="l01274"></a>01274     }
+<a name="l01275"></a>01275     <span class="comment">/* Return  */</span>
+<a name="l01276"></a>01276     <span class="keywordflow">return</span> 0 ;
+<a name="l01277"></a>01277 }
+<a name="l01278"></a>01278 
+<a name="l01279"></a>01279 <span class="keyword">static</span> cpl_bivector **
+<a name="l01280"></a>01280 sinfo_distortion_get_arc_positions(
+<a name="l01281"></a>01281         cpl_image       *   in,
+<a name="l01282"></a>01282         cpl_image       *   label_im,
+<a name="l01283"></a>01283         cpl_apertures   *   det,
+<a name="l01284"></a>01284         <span class="keywordtype">int</span>                 nb_samples,
+<a name="l01285"></a>01285         <span class="keywordtype">double</span>          **  lines_pos)
+<a name="l01286"></a>01286 {
+<a name="l01287"></a>01287     <span class="keyword">const</span> <span class="keywordtype">char</span>      *   fctid = <span class="stringliteral">"sinfo_distortion_get_arc_positions"</span> ;
+<a name="l01288"></a>01288     <span class="keywordtype">int</span>                 n_arcs ;
+<a name="l01289"></a>01289     cpl_image       *   filt_img ;
+<a name="l01290"></a>01290     cpl_matrix      *   kernel ;
+<a name="l01291"></a>01291     cpl_bivector    **  pos ;
+<a name="l01292"></a>01292     <span class="keywordtype">double</span>          *   biv_x ;
+<a name="l01293"></a>01293     <span class="keywordtype">double</span>          *   biv_y ;
+<a name="l01294"></a>01294     <span class="keywordtype">double</span>              x_finepos ;
+<a name="l01295"></a>01295     <span class="keywordtype">int</span>             *   plabel_im ;
+<a name="l01296"></a>01296     <span class="keywordtype">int</span>             *   arcs_samples_y ;
+<a name="l01297"></a>01297     <span class="keywordtype">int</span>             *   computed ;
+<a name="l01298"></a>01298     <span class="keywordtype">double</span>              arclen ;
+<a name="l01299"></a>01299     <span class="keywordtype">int</span>                 use_this_arc ;
+<a name="l01300"></a>01300     <span class="keywordtype">int</span>                 obj ;
+<a name="l01301"></a>01301     <span class="keywordtype">int</span>                 nx, ny ;
+<a name="l01302"></a>01302     <span class="keywordtype">int</span>                 i, j, k ;
+<a name="l01303"></a>01303 <span class="preprocessor">#if defined CPL_VERSION_CODE && CPL_VERSION_CODE >= CPL_VERSION(4, 8, 0)</span>
+<a name="l01304"></a>01304 <span class="preprocessor"></span>    cpl_mask*          mask=NULL;
+<a name="l01305"></a>01305 <span class="preprocessor">#endif</span>
+<a name="l01306"></a>01306 <span class="preprocessor"></span>
+<a name="l01307"></a>01307     <span class="comment">/* Check entries */</span>
+<a name="l01308"></a>01308 
+<a name="l01309"></a>01309     <span class="comment">/* Initialise */</span>
+<a name="l01310"></a>01310     n_arcs = cpl_apertures_get_size(det) ;
+<a name="l01311"></a>01311     nx = cpl_image_get_size_x(label_im) ;
+<a name="l01312"></a>01312     ny = cpl_image_get_size_y(label_im) ;
+<a name="l01313"></a>01313 
+<a name="l01314"></a>01314     <span class="comment">/* Allocate positions (pos. of n_arcs*nb_samples pts on the arcs) */</span>
+<a name="l01315"></a>01315     pos = cpl_calloc(n_arcs, <span class="keyword">sizeof</span>(cpl_bivector*)) ;
+<a name="l01316"></a>01316     <span class="keywordflow">for</span> (i=0 ; i<n_arcs ; i++) pos[i] = cpl_bivector_new(nb_samples) ;
+<a name="l01317"></a>01317 
+<a name="l01318"></a>01318     <span class="comment">/* Median filter on input image */</span>
+<a name="l01319"></a>01319     kernel = cpl_matrix_new(3, 3) ;
+<a name="l01320"></a>01320     cpl_matrix_fill(kernel, 1.0) ;
+<a name="l01321"></a>01321 <span class="preprocessor">#if defined CPL_VERSION_CODE && CPL_VERSION_CODE >= CPL_VERSION(4, 8, 0)</span>
+<a name="l01322"></a>01322 <span class="preprocessor"></span>    filt_img=cpl_image_duplicate(in);
+<a name="l01323"></a>01323     mask=cpl_mask_new(3,3);
+<a name="l01324"></a>01324     cpl_mask_not(mask);
+<a name="l01325"></a>01325     cpl_image_filter_mask(filt_img,in,mask,CPL_FILTER_MEDIAN,CPL_BORDER_FILTER);
+<a name="l01326"></a>01326     cpl_mask_delete(mask);
+<a name="l01327"></a>01327 <span class="preprocessor">#else</span>
+<a name="l01328"></a>01328 <span class="preprocessor"></span>    filt_img = cpl_image_filter_median(in, kernel) ;
+<a name="l01329"></a>01329 <span class="preprocessor">#endif</span>
+<a name="l01330"></a>01330 <span class="preprocessor"></span>    cpl_matrix_delete(kernel) ;
+<a name="l01331"></a>01331 
+<a name="l01332"></a>01332     <span class="comment">/* Measured Arcs coordinates along curvature */</span>
+<a name="l01333"></a>01333     arcs_samples_y = cpl_malloc(n_arcs * nb_samples * <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>)) ;
+<a name="l01334"></a>01334     computed = cpl_calloc(n_arcs*nb_samples, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>)) ;
+<a name="l01335"></a>01335 
+<a name="l01336"></a>01336     <span class="comment">/* Find out the Y coordinates along the arcs  */</span>
+<a name="l01337"></a>01337     <span class="keywordflow">for</span> (j=0 ; j<n_arcs ; j++) {
+<a name="l01338"></a>01338         arclen = cpl_apertures_get_top(det,j+1) -
+<a name="l01339"></a>01339             cpl_apertures_get_bottom(det,j+1) + 1 ;
+<a name="l01340"></a>01340         <span class="keywordflow">for</span> (i=0 ; i<nb_samples ; i++) {
+<a name="l01341"></a>01341             arcs_samples_y[i+j*nb_samples] =
+<a name="l01342"></a>01342                 (int)(cpl_apertures_get_bottom(det, j+1) +
+<a name="l01343"></a>01343                       (arclen * (i + 0.5)) / (<span class="keywordtype">double</span>)nb_samples) ;
+<a name="l01344"></a>01344         }
+<a name="l01345"></a>01345     }
+<a name="l01346"></a>01346 
+<a name="l01347"></a>01347     <span class="comment">/* Find out the X coord. at nb_samples Y positions on all arcs */</span>
+<a name="l01348"></a>01348     plabel_im = cpl_image_get_data_int(label_im) ;
+<a name="l01349"></a>01349     <span class="keywordflow">for</span> (i=0 ; i<nx ; i++) {
+<a name="l01350"></a>01350         <span class="keywordflow">for</span> (j=0 ; j<ny ; j++) {
+<a name="l01351"></a>01351             <span class="comment">/* use_this_arc is set to 1 if we are on the arc at a y */</span>
+<a name="l01352"></a>01352             <span class="comment">/* coordinate where the x coord should be found */</span>
+<a name="l01353"></a>01353             obj = plabel_im[i + j * nx] ;
+<a name="l01354"></a>01354             <span class="comment">/* Handle background */</span>
+<a name="l01355"></a>01355             <span class="keywordflow">if</span> (obj==0) continue ;
+<a name="l01356"></a>01356             <span class="comment">/* Decrease by one to index the array from 0 */</span>
+<a name="l01357"></a>01357             <span class="keywordflow">else</span> obj-- ;
+<a name="l01358"></a>01358 
+<a name="l01359"></a>01359             use_this_arc = 0 ;
+<a name="l01360"></a>01360             <span class="keywordflow">for</span> (k=0 ; k<nb_samples ; k++) {
+<a name="l01361"></a>01361                 <span class="keywordflow">if</span> (arcs_samples_y[k+obj*nb_samples] == j) {
+<a name="l01362"></a>01362                     use_this_arc = 1 ;
+<a name="l01363"></a>01363                     break ;
+<a name="l01364"></a>01364                 }
+<a name="l01365"></a>01365             }
+<a name="l01366"></a>01366             <span class="keywordflow">if</span> ((use_this_arc)  && (computed[k+obj*nb_samples] == 0)) {
+<a name="l01367"></a>01367                 <span class="comment">/* Find x coordinate of obj at the Y coord. */</span>
+<a name="l01368"></a>01368                 <span class="keywordflow">if</span> ((x_finepos = sinfo_distortion_fine_pos(filt_img,
+<a name="l01369"></a>01369                                 label_im, i, j)) < 0.0) {
+<a name="l01370"></a>01370                     cpl_msg_error(fctid, <span class="stringliteral">"cannot find fine arc position"</span>) ;
+<a name="l01371"></a>01371                     cpl_image_delete(filt_img) ;
+<a name="l01372"></a>01372                     cpl_free(arcs_samples_y);
+<a name="l01373"></a>01373                     cpl_free(computed) ;
+<a name="l01374"></a>01374                     <span class="keywordflow">for</span> (i=0 ; i<n_arcs ; i++) cpl_bivector_delete(pos[i]);
+<a name="l01375"></a>01375                     cpl_free(pos) ;
+<a name="l01376"></a>01376                     <span class="keywordflow">return</span> NULL ;
+<a name="l01377"></a>01377                 } <span class="keywordflow">else</span> {
+<a name="l01378"></a>01378                     biv_x = cpl_bivector_get_x_data(pos[obj]) ;
+<a name="l01379"></a>01379                     biv_y = cpl_bivector_get_y_data(pos[obj]) ;
+<a name="l01380"></a>01380                     biv_x[k] = x_finepos ;
+<a name="l01381"></a>01381                     biv_y[k] = j ;
+<a name="l01382"></a>01382                     (*lines_pos)[obj] = cpl_apertures_get_centroid_x(det,obj+1);
+<a name="l01383"></a>01383                     computed[k+obj*nb_samples] = 1 ;
+<a name="l01384"></a>01384                 }
+<a name="l01385"></a>01385             }
+<a name="l01386"></a>01386         }
+<a name="l01387"></a>01387     }
+<a name="l01388"></a>01388 
+<a name="l01389"></a>01389     <span class="comment">/* Free and return */</span>
+<a name="l01390"></a>01390     cpl_image_delete(filt_img) ;
+<a name="l01391"></a>01391     cpl_free(arcs_samples_y) ;
+<a name="l01392"></a>01392     cpl_free(computed) ;
+<a name="l01393"></a>01393     <span class="keywordflow">return</span> pos ;
+<a name="l01394"></a>01394 }
+<a name="l01395"></a>01395 
+<a name="l01396"></a>01396 <span class="keyword">static</span> <span class="keywordtype">double</span>
+<a name="l01397"></a>01397 sinfo_distortion_fine_pos(
+<a name="l01398"></a>01398         cpl_image   *   im,
+<a name="l01399"></a>01399         cpl_image   *   label_im,
+<a name="l01400"></a>01400         <span class="keywordtype">int</span>             x,
+<a name="l01401"></a>01401         <span class="keywordtype">int</span>             y)
+<a name="l01402"></a>01402 {
+<a name="l01403"></a>01403     <span class="keywordtype">float</span>   *   pim ;
+<a name="l01404"></a>01404     <span class="keywordtype">int</span>     *   plabel_im ;
+<a name="l01405"></a>01405     <span class="keywordtype">int</span>         objnum ;
+<a name="l01406"></a>01406     <span class="keywordtype">int</span>         curr_obj ;
+<a name="l01407"></a>01407     <span class="keywordtype">int</span>         start_pos ;
+<a name="l01408"></a>01408     <span class="keywordtype">double</span>      grav_c ;
+<a name="l01409"></a>01409     <span class="keywordtype">double</span>      sum ;
+<a name="l01410"></a>01410     <span class="keywordtype">double</span>      max ;
+<a name="l01411"></a>01411     <span class="keywordtype">double</span>      val ;
+<a name="l01412"></a>01412     <span class="keywordtype">int</span>         maxpos ;
+<a name="l01413"></a>01413     <span class="keywordtype">int</span>         im_extrem ;
+<a name="l01414"></a>01414     <span class="keywordtype">double</span>      arc_pos ;
+<a name="l01415"></a>01415     <span class="keywordtype">int</span>         nx ;
+<a name="l01416"></a>01416 
+<a name="l01417"></a>01417     <span class="comment">/* Initialize */</span>
+<a name="l01418"></a>01418     nx = cpl_image_get_size_x(im) ;
+<a name="l01419"></a>01419     grav_c = 0.0 ;
+<a name="l01420"></a>01420     sum    = 0.0 ;
+<a name="l01421"></a>01421     start_pos = x ;
+<a name="l01422"></a>01422     maxpos = start_pos ;
+<a name="l01423"></a>01423     pim = cpl_image_get_data_float(im) ;
+<a name="l01424"></a>01424     max    = (double)pim[start_pos + y * nx] ;
+<a name="l01425"></a>01425     plabel_im = cpl_image_get_data_int(label_im) ;
+<a name="l01426"></a>01426     objnum = plabel_im[start_pos + y * nx] ;
+<a name="l01427"></a>01427     im_extrem = nx ;
+<a name="l01428"></a>01428 
+<a name="l01429"></a>01429     <span class="comment">/* While we stay in the same object... */</span>
+<a name="l01430"></a>01430     <span class="keywordflow">do</span> {
+<a name="l01431"></a>01431         val = (double)pim[start_pos + y * nx] ;
+<a name="l01432"></a>01432         <span class="keywordflow">if</span> (start_pos == 0) grav_c = 0.0 ;
+<a name="l01433"></a>01433         <span class="keywordflow">else</span> grav_c += start_pos * val ;
+<a name="l01434"></a>01434         sum += val ;
+<a name="l01435"></a>01435         <span class="keywordflow">if</span> (val > max) {
+<a name="l01436"></a>01436             max = val ;
+<a name="l01437"></a>01437             maxpos = start_pos ;
+<a name="l01438"></a>01438         }
+<a name="l01439"></a>01439 
+<a name="l01440"></a>01440         <span class="comment">/* Next point */</span>
+<a name="l01441"></a>01441         start_pos++ ;
+<a name="l01442"></a>01442 
+<a name="l01443"></a>01443         curr_obj = plabel_im[start_pos + y * nx] ;
+<a name="l01444"></a>01444     } <span class="keywordflow">while</span> (curr_obj == objnum) ;
+<a name="l01445"></a>01445 
+<a name="l01446"></a>01446     <span class="comment">/* Returned position is the gravity center or the max in bad cases */</span>
+<a name="l01447"></a>01447     <span class="keywordflow">if</span> ((fabs(grav_c) < 1.0e-40) || (fabs(sum) < 1.0e-40)) {
+<a name="l01448"></a>01448         arc_pos = maxpos ;
+<a name="l01449"></a>01449     } <span class="keywordflow">else</span> {
+<a name="l01450"></a>01450         arc_pos = grav_c / sum ;
+<a name="l01451"></a>01451         <span class="keywordflow">if</span> (fabs(arc_pos) >= start_pos) arc_pos = maxpos ;
+<a name="l01452"></a>01452     }
+<a name="l01453"></a>01453 
+<a name="l01454"></a>01454     <span class="comment">/* Return */</span>
+<a name="l01455"></a>01455     <span class="keywordflow">return</span> arc_pos ;
+<a name="l01456"></a>01456 }
+<a name="l01457"></a>01457 
+<a name="l01458"></a>01458 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l01464"></a>01464 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l01465"></a>01465 <span class="preprocessor">#define IS_NB_TESTPOINTS    8</span>
+<a name="l01466"></a>01466 <span class="preprocessor"></span><span class="preprocessor">#define IS_MIN_SLOPE        0.01</span>
+<a name="l01467"></a>01467 <span class="preprocessor"></span><span class="preprocessor">#define IS_MAX_SLOPE_DIF    0.075</span>
+<a name="l01468"></a>01468 <span class="preprocessor"></span><span class="preprocessor">#define IS_MAX_FIT_EDGE_DIF 0.05</span>
+<a name="l01469"></a>01469 <span class="preprocessor"></span><span class="preprocessor">#define IS_MIN_RAMP         10.0</span>
+<a name="l01470"></a>01470 <span class="preprocessor"></span><span class="preprocessor">#define IS_MAX_MNERR        13.0</span>
+<a name="l01471"></a>01471 <span class="preprocessor"></span><span class="preprocessor">#define IS_MAX_MNERR_DIF    8.0</span>
+<a name="l01472"></a>01472 <span class="preprocessor"></span><span class="preprocessor">#define IS_MAX_INTER_DIF    20.0</span>
+<a name="l01473"></a>01473 <span class="preprocessor"></span><span class="preprocessor">#define IS_SKIPZONE         2.5</span>
+<a name="l01474"></a>01474 <span class="preprocessor"></span><span class="preprocessor">#define SQR(x) ((x)*(x))</span>
+<a name="l01475"></a>01475 <span class="preprocessor"></span><span class="keyword">static</span> cpl_image * sinfo_distortion_remove_ramp(<span class="keyword">const</span> cpl_image * in)
+<a name="l01476"></a>01476 {
+<a name="l01477"></a>01477     <span class="keyword">const</span> <span class="keywordtype">char</span>      *   fctid = <span class="stringliteral">"sinfo_distortion_remove_ramp"</span> ;
+<a name="l01478"></a>01478     <span class="keywordtype">int</span>                 ramp_present ;
+<a name="l01479"></a>01479     <span class="keywordtype">int</span>                 nx, ny ;
+<a name="l01480"></a>01480     <span class="keywordtype">int</span>                 y, yhi, ylo;
+<a name="l01481"></a>01481     cpl_vector      *   tmp_vector ;
+<a name="l01482"></a>01482     cpl_bivector    *   testpointlo ;
+<a name="l01483"></a>01483     <span class="keywordtype">double</span>          *   testpointlo_x ;
+<a name="l01484"></a>01484     <span class="keywordtype">double</span>          *   testpointlo_y ;
+<a name="l01485"></a>01485     cpl_bivector    *   testpointhi ;
+<a name="l01486"></a>01486     <span class="keywordtype">double</span>          *   testpointhi_x ;
+<a name="l01487"></a>01487     <span class="keywordtype">double</span>          *   testpointhi_y ;
+<a name="l01488"></a>01488     <span class="keywordtype">int</span>                 spacing;
+<a name="l01489"></a>01489     <span class="keywordtype">double</span>              rampdif, fitslope;
+<a name="l01490"></a>01490     <span class="keywordtype">double</span>          *   pol_coefhi,
+<a name="l01491"></a>01491                     *   pol_coeflo ;
+<a name="l01492"></a>01492     cpl_vector      *   median ;
+<a name="l01493"></a>01493     <span class="keywordtype">double</span>          *   median_data ;
+<a name="l01494"></a>01494     <span class="keywordtype">double</span>              medianerrlo, medianerrhi;
+<a name="l01495"></a>01495     <span class="keywordtype">double</span>              slope ;
+<a name="l01496"></a>01496     cpl_image       *   out ;
+<a name="l01497"></a>01497     <span class="keywordtype">float</span>           *   pout ;
+<a name="l01498"></a>01498     <span class="keywordtype">float</span>               val ;
+<a name="l01499"></a>01499     <span class="keywordtype">int</span>                 i, j ;
+<a name="l01500"></a>01500 
+<a name="l01501"></a>01501     <span class="comment">/* Initialise */</span>
+<a name="l01502"></a>01502     nx = cpl_image_get_size_x(in) ;
+<a name="l01503"></a>01503     ny = cpl_image_get_size_y(in) ;
+<a name="l01504"></a>01504 
+<a name="l01505"></a>01505     <span class="comment">/* Check entries */</span>
+<a name="l01506"></a>01506     <span class="keywordflow">if</span> (in==NULL) <span class="keywordflow">return</span> NULL ;
+<a name="l01507"></a>01507 
+<a name="l01508"></a>01508     <span class="keywordflow">if</span> (ny<IS_SKIPZONE*IS_NB_TESTPOINTS){
+<a name="l01509"></a>01509         cpl_msg_error(fctid, <span class="stringliteral">"image has %d lines, min=%d "</span>,
+<a name="l01510"></a>01510                 ny, (<span class="keywordtype">int</span>)(IS_SKIPZONE*IS_NB_TESTPOINTS*2));
+<a name="l01511"></a>01511         <span class="keywordflow">return</span> NULL ;
+<a name="l01512"></a>01512     }
+<a name="l01513"></a>01513 
+<a name="l01514"></a>01514     slope=0.0 ;
+<a name="l01515"></a>01515     spacing= ny / (IS_SKIPZONE*IS_NB_TESTPOINTS) ;
+<a name="l01516"></a>01516     yhi = (int)(ny/2) ;
+<a name="l01517"></a>01517     ylo = yhi - 1 ;
+<a name="l01518"></a>01518     <span class="comment">/* Fill the vectors */</span>
+<a name="l01519"></a>01519     testpointhi = cpl_bivector_new(IS_NB_TESTPOINTS) ;
+<a name="l01520"></a>01520     testpointhi_x = cpl_bivector_get_x_data(testpointhi) ;
+<a name="l01521"></a>01521     testpointhi_y = cpl_bivector_get_y_data(testpointhi) ;
+<a name="l01522"></a>01522     testpointlo = cpl_bivector_new(IS_NB_TESTPOINTS) ;
+<a name="l01523"></a>01523     testpointlo_x = cpl_bivector_get_x_data(testpointlo) ;
+<a name="l01524"></a>01524     testpointlo_y = cpl_bivector_get_y_data(testpointlo) ;
+<a name="l01525"></a>01525     <span class="keywordflow">for</span> (i=0 ; i<IS_NB_TESTPOINTS ; i++) {
+<a name="l01526"></a>01526         y = yhi + i * spacing;
+<a name="l01527"></a>01527         tmp_vector = cpl_vector_new_from_image_row(in, y+1) ;
+<a name="l01528"></a>01528         testpointhi_x[i] = y - ny / 2;
+<a name="l01529"></a>01529         testpointhi_y[i] = cpl_vector_get_median_const(tmp_vector) ;
+<a name="l01530"></a>01530         cpl_vector_delete(tmp_vector) ;
+<a name="l01531"></a>01531         y = ylo - i * spacing;
+<a name="l01532"></a>01532         tmp_vector = cpl_vector_new_from_image_row(in, y+1) ;
+<a name="l01533"></a>01533         testpointlo_x[IS_NB_TESTPOINTS-i-1] = y ;
+<a name="l01534"></a>01534         testpointlo_y[IS_NB_TESTPOINTS-i-1]=
+<a name="l01535"></a>01535       cpl_vector_get_median_const(tmp_vector);
+<a name="l01536"></a>01536         cpl_vector_delete(tmp_vector) ;
+<a name="l01537"></a>01537     }
+<a name="l01538"></a>01538 
+<a name="l01539"></a>01539     <span class="comment">/* Apply the fit */</span>
+<a name="l01540"></a>01540     pol_coefhi = <a class="code" href="group__irplib__flat.html#ga3e3e3bd45aef34e38758e1f2528d7c91" title="Fit a slope to a list of points (robust fit).">irplib_flat_fit_slope_robust</a>(testpointhi_x,
+<a name="l01541"></a>01541             testpointhi_y, IS_NB_TESTPOINTS) ;
+<a name="l01542"></a>01542     pol_coeflo = <a class="code" href="group__irplib__flat.html#ga3e3e3bd45aef34e38758e1f2528d7c91" title="Fit a slope to a list of points (robust fit).">irplib_flat_fit_slope_robust</a>(testpointlo_x,
+<a name="l01543"></a>01543             testpointlo_y, IS_NB_TESTPOINTS) ;
+<a name="l01544"></a>01544 
+<a name="l01545"></a>01545     <span class="comment">/* Compute the errors */</span>
+<a name="l01546"></a>01546     median = cpl_vector_new(IS_NB_TESTPOINTS) ;
+<a name="l01547"></a>01547     median_data = cpl_vector_get_data(median) ;
+<a name="l01548"></a>01548     <span class="keywordflow">for</span> (i=0 ; i<IS_NB_TESTPOINTS ; i++) {
+<a name="l01549"></a>01549         median_data[i]=SQR(testpointhi_y[i]
+<a name="l01550"></a>01550                 - pol_coefhi[0] - pol_coefhi[1] * testpointhi_x[i]);
+<a name="l01551"></a>01551     }
+<a name="l01552"></a>01552     medianerrhi = cpl_vector_get_median_const(median) ;
+<a name="l01553"></a>01553     <span class="keywordflow">for</span> (i=0; i<IS_NB_TESTPOINTS; i++) {
+<a name="l01554"></a>01554         median_data[i]=SQR(testpointlo_y[i]
+<a name="l01555"></a>01555                 - pol_coeflo[0] - pol_coeflo[1] * testpointlo_x[i]);
+<a name="l01556"></a>01556     }
+<a name="l01557"></a>01557     medianerrlo = cpl_vector_get_median_const(median) ;
+<a name="l01558"></a>01558     cpl_vector_delete(median) ;
+<a name="l01559"></a>01559     rampdif = testpointlo_y[IS_NB_TESTPOINTS-1] - testpointhi_y[0];
+<a name="l01560"></a>01560     slope = rampdif / (ny/2.0) ;
+<a name="l01561"></a>01561     fitslope = (pol_coefhi[1] + pol_coeflo[1]) / 2.0 ;
+<a name="l01562"></a>01562 
+<a name="l01563"></a>01563     cpl_bivector_delete(testpointlo);
+<a name="l01564"></a>01564     cpl_bivector_delete(testpointhi);
+<a name="l01565"></a>01565 
+<a name="l01566"></a>01566     <span class="comment">/* Decide if there is a ramp or not  */</span>
+<a name="l01567"></a>01567     <span class="keywordflow">if</span> (fabs(rampdif)<IS_MIN_RAMP ||
+<a name="l01568"></a>01568             fabs(pol_coefhi[1]) < IS_MIN_SLOPE ||
+<a name="l01569"></a>01569             fabs(pol_coeflo[1]) < IS_MIN_SLOPE ||
+<a name="l01570"></a>01570             pol_coefhi[1]/pol_coeflo[1]<0.5 ||
+<a name="l01571"></a>01571             pol_coefhi[1]/pol_coeflo[1]>2.0 ||
+<a name="l01572"></a>01572             fabs(pol_coefhi[1]-pol_coeflo[1])>IS_MAX_SLOPE_DIF ||
+<a name="l01573"></a>01573             fabs(pol_coefhi[0]-pol_coeflo[0]) > IS_MAX_INTER_DIF ||
+<a name="l01574"></a>01574             medianerrlo> IS_MAX_MNERR ||
+<a name="l01575"></a>01575             medianerrhi> IS_MAX_MNERR ||
+<a name="l01576"></a>01576             fabs(medianerrlo-medianerrhi) >IS_MAX_MNERR_DIF ||
+<a name="l01577"></a>01577             fabs(slope-fitslope) > IS_MAX_FIT_EDGE_DIF ||
+<a name="l01578"></a>01578             slope/fitslope<0.5 ||
+<a name="l01579"></a>01579             slope/fitslope>2.0) ramp_present = 0 ;
+<a name="l01580"></a>01580     <span class="keywordflow">else</span> ramp_present = 1 ;
+<a name="l01581"></a>01581 
+<a name="l01582"></a>01582     cpl_free(pol_coeflo) ;
+<a name="l01583"></a>01583     cpl_free(pol_coefhi) ;
+<a name="l01584"></a>01584 
+<a name="l01585"></a>01585     <span class="comment">/* Correct the ramp if it is there */</span>
+<a name="l01586"></a>01586     out = cpl_image_duplicate(in) ;
+<a name="l01587"></a>01587     pout = cpl_image_get_data_float(out) ;
+<a name="l01588"></a>01588     <span class="keywordflow">if</span> (ramp_present == 1) {
+<a name="l01589"></a>01589         <span class="keywordflow">for</span> (j=0 ; j<ny/2 ; j++) {
+<a name="l01590"></a>01590             val = slope * (j-ny/2) ;
+<a name="l01591"></a>01591             <span class="keywordflow">for</span> (i=0 ; i<nx ; i++)
+<a name="l01592"></a>01592                 pout[i+j*nx] -= val ;
+<a name="l01593"></a>01593         }
+<a name="l01594"></a>01594         <span class="keywordflow">for</span> (j=ny/2 ; j<ny ; j++) {
+<a name="l01595"></a>01595             val = slope * (j-ny) ;
+<a name="l01596"></a>01596             <span class="keywordflow">for</span> (i=0 ; i<nx ; i++)
+<a name="l01597"></a>01597                 pout[i+j*nx] -= val ;
+<a name="l01598"></a>01598         }
+<a name="l01599"></a>01599 
+<a name="l01600"></a>01600     }
+<a name="l01601"></a>01601 
+<a name="l01602"></a>01602     <span class="keywordflow">return</span> out ;
+<a name="l01603"></a>01603 }
+<a name="l01604"></a>01604 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__distortion_8h_source.html b/html/sinfo__distortion_8h_source.html
new file mode 100644
index 0000000..f2ae2ab
--- /dev/null
+++ b/html/sinfo__distortion_8h_source.html
@@ -0,0 +1,91 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_distortion.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_distortion.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_distortion.h,v 1.7 2007/06/06 07:10:45 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the irplib package</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2007/06/06 07:10:45 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.7 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifndef SINFO_DISTORTION_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_DISTORTION_H</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span>
+<a name="l00031"></a>00031 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00032"></a>00032 <span class="comment">                                   Includes</span>
+<a name="l00033"></a>00033 <span class="comment">-----------------------------------------------------------------------------*/</span>
+<a name="l00034"></a>00034 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00035"></a>00035 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00036"></a>00036 <span class="comment">                                       Prototypes</span>
+<a name="l00037"></a>00037 <span class="comment">-----------------------------------------------------------------------------*/</span>
+<a name="l00038"></a>00038 cpl_polynomial * 
+<a name="l00039"></a>00039 sinfo_distortion_estimate(<span class="keyword">const</span> cpl_image *, 
+<a name="l00040"></a>00040                           <span class="keywordtype">int</span>, 
+<a name="l00041"></a>00041                           <span class="keywordtype">int</span>, 
+<a name="l00042"></a>00042                           <span class="keywordtype">int</span>, 
+<a name="l00043"></a>00043                           <span class="keywordtype">int</span>, 
+<a name="l00044"></a>00044                           <span class="keywordtype">int</span>, 
+<a name="l00045"></a>00045                           <span class="keywordtype">int</span>, 
+<a name="l00046"></a>00046                           <span class="keywordtype">int</span>, 
+<a name="l00047"></a>00047                           <span class="keywordtype">int</span>, 
+<a name="l00048"></a>00048                           <span class="keywordtype">double</span>, 
+<a name="l00049"></a>00049                           cpl_apertures **) ;
+<a name="l00050"></a>00050 
+<a name="l00051"></a>00051 cpl_polynomial * sinfo_distortion_estimate_new(
+<a name="l00052"></a>00052         <span class="keyword">const</span> cpl_image *   org,
+<a name="l00053"></a>00053         <span class="keywordtype">int</span>                 xmin,
+<a name="l00054"></a>00054         <span class="keywordtype">int</span>                 ymin,
+<a name="l00055"></a>00055         <span class="keywordtype">int</span>                 xmax,
+<a name="l00056"></a>00056         <span class="keywordtype">int</span>                 ymax,
+<a name="l00057"></a>00057         <span class="keywordtype">int</span>                 auto_ramp_sub,
+<a name="l00058"></a>00058         <span class="keywordtype">int</span>                 arc_sat,
+<a name="l00059"></a>00059         <span class="keywordtype">int</span>                 max_arc_width,
+<a name="l00060"></a>00060         <span class="keywordtype">double</span>              kappa,
+<a name="l00061"></a>00061         <span class="keywordtype">double</span>              arcs_min_arclen_factor,
+<a name="l00062"></a>00062         <span class="keywordtype">int</span>                 arcs_window_size,
+<a name="l00063"></a>00063         <span class="keywordtype">int</span>                 smooth_rad,
+<a name="l00064"></a>00064         <span class="keywordtype">int</span>                 degree,
+<a name="l00065"></a>00065         <span class="keywordtype">double</span>              offset,
+<a name="l00066"></a>00066         cpl_apertures   **  arcs);
+<a name="l00067"></a>00067 
+<a name="l00068"></a>00068 cpl_image *
+<a name="l00069"></a>00069 sinfo_distortion_image_restore(<span class="keyword">const</span> cpl_image* inp,
+<a name="l00070"></a>00070                                <span class="keyword">const</span> <span class="keywordtype">int</span> r,
+<a name="l00071"></a>00071                                <span class="keyword">const</span> <span class="keywordtype">int</span> d,
+<a name="l00072"></a>00072                                <span class="keyword">const</span> <span class="keywordtype">double</span> kappa,
+<a name="l00073"></a>00073                                <span class="keyword">const</span> <span class="keywordtype">int</span> ks_method,
+<a name="l00074"></a>00074                                <span class="keyword">const</span> <span class="keywordtype">int</span> n);
+<a name="l00075"></a>00075 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__distortion__config_8c_source.html b/html/sinfo__distortion__config_8c_source.html
new file mode 100644
index 0000000..ae67dd1
--- /dev/null
+++ b/html/sinfo__distortion__config_8c_source.html
@@ -0,0 +1,553 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_distortion_config.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_distortion_config.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_distortion_config.c,v 1.6 2012/03/02 08:42:20 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the CPL (Common Pipeline Library)</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
+<a name="l00007"></a>00007 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span>
+<a name="l00008"></a>00008 <span class="comment"> * License as published by the Free Software Foundation; either</span>
+<a name="l00009"></a>00009 <span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
+<a name="l00014"></a>00014 <span class="comment"> * Lesser General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
+<a name="l00017"></a>00017 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2012/03/02 08:42:20 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.6 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> */</span>
+<a name="l00026"></a>00026 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00027"></a>00027 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00028"></a>00028 <span class="preprocessor">#endif</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span>
+<a name="l00030"></a>00030  <span class="comment">/****************************************************************</span>
+<a name="l00031"></a>00031 <span class="comment">  *   Wavecal Frames Data Reduction Parameter Initialization        *</span>
+<a name="l00032"></a>00032 <span class="comment">  ****************************************************************/</span>
+<a name="l00033"></a>00033 
+<a name="l00034"></a>00034 <span class="preprocessor">#include "sinfo_distortion_config.h"</span>
+<a name="l00035"></a>00035 <span class="preprocessor">#include "sinfo_globals.h"</span>
+<a name="l00037"></a>00037 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00041"></a>00041 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00042"></a>00042 
+<a name="l00043"></a>00043  <span class="keywordtype">void</span>
+<a name="l00044"></a>00044  sinfo_distortion_config_add(cpl_parameterlist *list)
+<a name="l00045"></a>00045 {
+<a name="l00046"></a>00046 
+<a name="l00047"></a>00047   cpl_parameter *p;
+<a name="l00048"></a>00048 
+<a name="l00049"></a>00049   <span class="keywordflow">if</span> (!list) {
+<a name="l00050"></a>00050     <span class="keywordflow">return</span>;
+<a name="l00051"></a>00051   }
+<a name="l00052"></a>00052 
+<a name="l00053"></a>00053   <span class="comment">/* Output file name */</span>
+<a name="l00054"></a>00054 <span class="comment">/* output name of resulting fits wavelength map */</span>
+<a name="l00055"></a>00055 
+<a name="l00056"></a>00056 
+<a name="l00057"></a>00057 <span class="comment">/* Find Lines */</span>
+<a name="l00058"></a>00058 <span class="comment">/* indicates if the dispersion relation is already determined or not */</span>
+<a name="l00059"></a>00059   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.distortion.calib_indicator"</span>,
+<a name="l00060"></a>00060                   CPL_TYPE_BOOL,
+<a name="l00061"></a>00061                               <span class="stringliteral">"Calib Indicator: "</span>
+<a name="l00062"></a>00062                               <span class="stringliteral">"FALSE: if the dispersion relation is already "</span>
+<a name="l00063"></a>00063                               <span class="stringliteral">"known, the routine can jump to the waveMap "</span>
+<a name="l00064"></a>00064                               <span class="stringliteral">"section "</span>
+<a name="l00065"></a>00065                               <span class="stringliteral">"TRUE: if the dispersion relation "</span>
+<a name="l00066"></a>00066                               <span class="stringliteral">"must first be determined"</span>,
+<a name="l00067"></a>00067                               <span class="stringliteral">"sinfoni.distortion"</span>,
+<a name="l00068"></a>00068                               TRUE);
+<a name="l00069"></a>00069 
+<a name="l00070"></a>00070   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"dist-calib_indicator"</span>);
+<a name="l00071"></a>00071   cpl_parameterlist_append(list, p);
+<a name="l00072"></a>00072 
+<a name="l00073"></a>00073 
+<a name="l00074"></a>00074 <span class="comment">/* minimal difference of mean and sinfo_median column intensity */</span>
+<a name="l00075"></a>00075   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.distortion.min_diff_mean_med_col_int"</span>,
+<a name="l00076"></a>00076                   CPL_TYPE_DOUBLE,
+<a name="l00077"></a>00077                               <span class="stringliteral">"Minimum Of Difference: "</span>
+<a name="l00078"></a>00078                               <span class="stringliteral">"minimum difference of mean and median column "</span>
+<a name="l00079"></a>00079                               <span class="stringliteral">"intensity to carry out the cross correlation"</span>,
+<a name="l00080"></a>00080                               <span class="stringliteral">"sinfoni.distortion"</span>,
+<a name="l00081"></a>00081                               10.);
+<a name="l00082"></a>00082 
+<a name="l00083"></a>00083   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
+<a name="l00084"></a>00084                           <span class="stringliteral">"dist-min_diff_mean_med_col_int"</span>);
+<a name="l00085"></a>00085   cpl_parameterlist_append(list, p);
+<a name="l00086"></a>00086 
+<a name="l00087"></a>00087 <span class="comment">/* half width of a box within which the line must sit */</span>
+<a name="l00088"></a>00088   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.distortion.half_width"</span>,
+<a name="l00089"></a>00089                   CPL_TYPE_INT,
+<a name="l00090"></a>00090                               <span class="stringliteral">"Half Width: "</span>
+<a name="l00091"></a>00091                               <span class="stringliteral">"half width of a box within which the line "</span>
+<a name="l00092"></a>00092                               <span class="stringliteral">"must be placed"</span>,
+<a name="l00093"></a>00093                               <span class="stringliteral">"sinfoni.distortion"</span>,
+<a name="l00094"></a>00094                               7);
+<a name="l00095"></a>00095 
+<a name="l00096"></a>00096   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"dist-hw"</span>);
+<a name="l00097"></a>00097   cpl_parameterlist_append(list, p);
+<a name="l00098"></a>00098 
+<a name="l00099"></a>00099 <span class="comment">/* sigma of Gaussian of artificial model spectra */</span>
+<a name="l00100"></a>00100   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.distortion.sigma"</span>,
+<a name="l00101"></a>00101                   CPL_TYPE_DOUBLE,
+<a name="l00102"></a>00102                               <span class="stringliteral">"Sigma: sigma of Gaussian which is convolved "</span>
+<a name="l00103"></a>00103                               <span class="stringliteral">"with the artificial spectrum generated using "</span>
+<a name="l00104"></a>00104                               <span class="stringliteral">"the line list"</span>,
+<a name="l00105"></a>00105                               <span class="stringliteral">"sinfoni.distortion"</span>,
+<a name="l00106"></a>00106                                2.);
+<a name="l00107"></a>00107 
+<a name="l00108"></a>00108   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"dist-sigma"</span>);
+<a name="l00109"></a>00109   cpl_parameterlist_append(list, p);
+<a name="l00110"></a>00110 
+<a name="l00111"></a>00111   <span class="comment">/* Wavelength Calibration */</span>
+<a name="l00112"></a>00112 <span class="comment">/* guess value for fwhm of emission lines */</span>
+<a name="l00113"></a>00113   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.distortion.fwhm"</span>,
+<a name="l00114"></a>00114                   CPL_TYPE_DOUBLE,
+<a name="l00115"></a>00115                               <span class="stringliteral">"FWHM: initial guess value for the fwhm of "</span>
+<a name="l00116"></a>00116                               <span class="stringliteral">"the Gaussian used for the line fit"</span>,
+<a name="l00117"></a>00117                               <span class="stringliteral">"sinfoni.distortion"</span>,
+<a name="l00118"></a>00118                                2.83);
+<a name="l00119"></a>00119 
+<a name="l00120"></a>00120   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"dist-fwhm"</span>);
+<a name="l00121"></a>00121   cpl_parameterlist_append(list, p);
+<a name="l00122"></a>00122 
+<a name="l00123"></a>00123 <span class="comment">/* minimum amplitude of a line to be fitted */</span>
+<a name="l00124"></a>00124   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.distortion.min_amplitude"</span>,
+<a name="l00125"></a>00125                   CPL_TYPE_DOUBLE,
+<a name="l00126"></a>00126                               <span class="stringliteral">"Minimum Of Amplitude: "</span>
+<a name="l00127"></a>00127                               <span class="stringliteral">"of the Gaussian to do the fit"</span>,
+<a name="l00128"></a>00128                               <span class="stringliteral">"sinfoni.distortion"</span>,
+<a name="l00129"></a>00129                               5.);
+<a name="l00130"></a>00130 
+<a name="l00131"></a>00131   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"dist-min_amplitude"</span>);
+<a name="l00132"></a>00132   cpl_parameterlist_append(list, p);
+<a name="l00133"></a>00133 
+<a name="l00134"></a>00134 <span class="comment">/* maximal residual value for a valid fit */</span>
+<a name="l00135"></a>00135   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.distortion.max_residual"</span>,
+<a name="l00136"></a>00136                   CPL_TYPE_DOUBLE,
+<a name="l00137"></a>00137                               <span class="stringliteral">"Maximum Residuals value: "</span>
+<a name="l00138"></a>00138                               <span class="stringliteral">"beyond this value the fit is rejected"</span>,
+<a name="l00139"></a>00139                               <span class="stringliteral">"sinfoni.distortion"</span>,
+<a name="l00140"></a>00140                               0.5);
+<a name="l00141"></a>00141 
+<a name="l00142"></a>00142   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"dist-max_residual"</span>);
+<a name="l00143"></a>00143   cpl_parameterlist_append(list, p);
+<a name="l00144"></a>00144 
+<a name="l00145"></a>00145 <span class="comment">/* # of polynomial coefficients used for the dispersion relation */</span>
+<a name="l00146"></a>00146   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.distortion.n_a_coefficients"</span>,
+<a name="l00147"></a>00147                   CPL_TYPE_INT,
+<a name="l00148"></a>00148                               <span class="stringliteral">"Number of A coefficients: number of "</span>
+<a name="l00149"></a>00149                               <span class="stringliteral">"polynomial coefficients for the "</span>
+<a name="l00150"></a>00150                               <span class="stringliteral">"dispersion relation"</span>,
+<a name="l00151"></a>00151                               <span class="stringliteral">"sinfoni.distortion"</span>,
+<a name="l00152"></a>00152                               4);
+<a name="l00153"></a>00153 
+<a name="l00154"></a>00154   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"dist-n_a_coeffs"</span>);
+<a name="l00155"></a>00155   cpl_parameterlist_append(list, p);
+<a name="l00156"></a>00156 
+<a name="l00157"></a>00157  <span class="comment">/* # of polynomial coefficients used for the fit of the dispersion </span>
+<a name="l00158"></a>00158 <span class="comment">    coefficients */</span>
+<a name="l00159"></a>00159   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.distortion.n_b_coefficients"</span>,
+<a name="l00160"></a>00160                   CPL_TYPE_INT,
+<a name="l00161"></a>00161                               <span class="stringliteral">"Number of B coefficients: "</span>
+<a name="l00162"></a>00162                               <span class="stringliteral">"number of polynomial coefficients for the "</span>
+<a name="l00163"></a>00163                               <span class="stringliteral">"polynomial fit of the dispersion coefficients"</span>,
+<a name="l00164"></a>00164                               <span class="stringliteral">"sinfoni.distortion"</span>,
+<a name="l00165"></a>00165                               2);
+<a name="l00166"></a>00166 
+<a name="l00167"></a>00167   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"dist-n_b_coeffs"</span>);
+<a name="l00168"></a>00168   cpl_parameterlist_append(list, p);
+<a name="l00169"></a>00169 
+<a name="l00170"></a>00170  <span class="comment">/* minimal factor of the standard deviation of the fit coefficients */</span>
+<a name="l00171"></a>00171   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.distortion.sigma_factor"</span>,
+<a name="l00172"></a>00172                   CPL_TYPE_DOUBLE,
+<a name="l00173"></a>00173                               <span class="stringliteral">"Sigma Factor: "</span>
+<a name="l00174"></a>00174                               <span class="stringliteral">"Factor of the standard deviation of the "</span>
+<a name="l00175"></a>00175                               <span class="stringliteral">"polynomial coefficients of the dispersion "</span>
+<a name="l00176"></a>00176                               <span class="stringliteral">"relation beyond which the coefficients are "</span>
+<a name="l00177"></a>00177                               <span class="stringliteral">"not used for the fit"</span>,
+<a name="l00178"></a>00178                               <span class="stringliteral">"sinfoni.distortion"</span>,
+<a name="l00179"></a>00179                               1.5);
+<a name="l00180"></a>00180 
+<a name="l00181"></a>00181   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"dist-sigma_factor"</span>);
+<a name="l00182"></a>00182   cpl_parameterlist_append(list, p);
+<a name="l00183"></a>00183 
+<a name="l00184"></a>00184   <span class="comment">/* indicates if the parameterized dispersion relation coefficients </span>
+<a name="l00185"></a>00185 <span class="comment">       should be written into an ASCII file */</span>
+<a name="l00186"></a>00186   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.distortion.write_coeffs_ind"</span>,
+<a name="l00187"></a>00187                   CPL_TYPE_BOOL,
+<a name="l00188"></a>00188                               <span class="stringliteral">"Write Coefficients Index: "</span>
+<a name="l00189"></a>00189                               <span class="stringliteral">"indicates if the coefficients should "</span>
+<a name="l00190"></a>00190                               <span class="stringliteral">"be written into a file or not"</span>,
+<a name="l00191"></a>00191                               <span class="stringliteral">"sinfoni.distortion"</span>,
+<a name="l00192"></a>00192                               TRUE);
+<a name="l00193"></a>00193 
+<a name="l00194"></a>00194   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"dist-wcoeff_ind"</span>);
+<a name="l00195"></a>00195   cpl_parameterlist_append(list, p);
+<a name="l00196"></a>00196 
+<a name="l00197"></a>00197   <span class="comment">/* indicates if the fit parameters should be written into an ASCII file */</span>
+<a name="l00198"></a>00198   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.distortion.write_par_ind"</span>,
+<a name="l00199"></a>00199                   CPL_TYPE_BOOL,
+<a name="l00200"></a>00200                               <span class="stringliteral">"Write Parameter Index: "</span>
+<a name="l00201"></a>00201                               <span class="stringliteral">"indicates if the fit parameters should "</span>
+<a name="l00202"></a>00202                               <span class="stringliteral">"be written into a file or not "</span>,
+<a name="l00203"></a>00203                               <span class="stringliteral">"sinfoni.distortion"</span>,
+<a name="l00204"></a>00204                               TRUE);
+<a name="l00205"></a>00205 
+<a name="l00206"></a>00206   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"dist-par_ind"</span>);
+<a name="l00207"></a>00207   cpl_parameterlist_append(list, p);
+<a name="l00208"></a>00208 
+<a name="l00209"></a>00209 
+<a name="l00210"></a>00210   <span class="comment">/* minimal distance of the slitlets in spectral direction */</span>
+<a name="l00211"></a>00211   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.distortion.pixel_dist"</span>,
+<a name="l00212"></a>00212                   CPL_TYPE_INT,
+<a name="l00213"></a>00213                          <span class="stringliteral">"Minimal Slitlets's Distance in spectral direction"</span>,
+<a name="l00214"></a>00214                               <span class="stringliteral">"sinfoni.distortion"</span>,
+<a name="l00215"></a>00215                               15);
+<a name="l00216"></a>00216 
+<a name="l00217"></a>00217   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"dist-pixel_dist"</span>);
+<a name="l00218"></a>00218   cpl_parameterlist_append(list, p);
+<a name="l00219"></a>00219 
+<a name="l00220"></a>00220 
+<a name="l00221"></a>00221 
+<a name="l00222"></a>00222   <span class="comment">/* allowed pixel position tolerance between estimated and fitted line </span>
+<a name="l00223"></a>00223 <span class="comment">     position</span>
+<a name="l00224"></a>00224 <span class="comment">  */</span>
+<a name="l00225"></a>00225   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.distortion.pixel_tol"</span>,
+<a name="l00226"></a>00226                   CPL_TYPE_DOUBLE,
+<a name="l00227"></a>00227                               <span class="stringliteral">"Pixel Tolerance: allowed pixel position "</span>
+<a name="l00228"></a>00228                               <span class="stringliteral">"tolerance between estimated and fitted "</span>
+<a name="l00229"></a>00229                   <span class="stringliteral">"line position"</span>,
+<a name="l00230"></a>00230                               <span class="stringliteral">"sinfoni.distortion"</span>,
+<a name="l00231"></a>00231                               5.0);
+<a name="l00232"></a>00232 
+<a name="l00233"></a>00233   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"dist-pixel_tol"</span>);
+<a name="l00234"></a>00234   cpl_parameterlist_append(list, p);
+<a name="l00235"></a>00235 
+<a name="l00236"></a>00236   <span class="comment">/* Wavelength Map */</span>
+<a name="l00237"></a>00237 <span class="comment">/* indicator if wavelength map should be generated or not */</span>
+<a name="l00238"></a>00238   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.distortion.wave_map_ind"</span>,
+<a name="l00239"></a>00239                   CPL_TYPE_BOOL,
+<a name="l00240"></a>00240                               <span class="stringliteral">"Wavelength Map Indicator: "</span>
+<a name="l00241"></a>00241                               <span class="stringliteral">"indicates if the wavelength calibration map "</span>
+<a name="l00242"></a>00242                               <span class="stringliteral">"should be generated (TRUE) or not (FALSE)"</span>,
+<a name="l00243"></a>00243                               <span class="stringliteral">"sinfoni.distortion"</span>,
+<a name="l00244"></a>00244                               FALSE);
+<a name="l00245"></a>00245 
+<a name="l00246"></a>00246   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"dist-wave_map_ind"</span>);
+<a name="l00247"></a>00247   cpl_parameterlist_append(list, p);
+<a name="l00248"></a>00248 
+<a name="l00249"></a>00249   <span class="comment">/* magnifying factor for FFT */</span>
+<a name="l00250"></a>00250   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.distortion.mag_factor"</span>,
+<a name="l00251"></a>00251                   CPL_TYPE_INT,
+<a name="l00252"></a>00252                               <span class="stringliteral">"Magnificator Factor: "</span>
+<a name="l00253"></a>00253                               <span class="stringliteral">"magnifying factor for the number of pixels "</span>
+<a name="l00254"></a>00254                               <span class="stringliteral">"in the columns needed for FFT"</span>,
+<a name="l00255"></a>00255                               <span class="stringliteral">"sinfoni.distortion"</span>,
+<a name="l00256"></a>00256                               8);
+<a name="l00257"></a>00257 
+<a name="l00258"></a>00258   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"dist-mag_factor"</span>);
+<a name="l00259"></a>00259   cpl_parameterlist_append(list, p);
+<a name="l00260"></a>00260 
+<a name="l00261"></a>00261 <span class="comment">/* Fits Slits */</span>
+<a name="l00262"></a>00262 <span class="comment">/* indicator if the fit of the slit edge positions is carried through or not */</span>
+<a name="l00263"></a>00263   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.distortion.slit_pos_indicator"</span>,
+<a name="l00264"></a>00264                   CPL_TYPE_BOOL,
+<a name="l00265"></a>00265                               <span class="stringliteral">"Slit Position Indicator: "</span>
+<a name="l00266"></a>00266                               <span class="stringliteral">"indicates if the fits of the slitlet "</span>
+<a name="l00267"></a>00267                               <span class="stringliteral">"edge positions should be carried "</span>
+<a name="l00268"></a>00268                               <span class="stringliteral">"through or not"</span>,
+<a name="l00269"></a>00269                               <span class="stringliteral">"sinfoni.distortion"</span>,
+<a name="l00270"></a>00270                               TRUE);
+<a name="l00271"></a>00271 
+<a name="l00272"></a>00272   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"dist-slit_pos_ind"</span>);
+<a name="l00273"></a>00273   cpl_parameterlist_append(list, p);
+<a name="l00274"></a>00274 
+<a name="l00275"></a>00275 <span class="comment">/* indicator if the fit model function is a Boltzmann function or not */</span>
+<a name="l00276"></a>00276   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.distortion.fit_boltz_indicator"</span>,
+<a name="l00277"></a>00277                   CPL_TYPE_BOOL ,
+<a name="l00278"></a>00278                               <span class="stringliteral">"Fit Boltzmann Indicator: "</span>
+<a name="l00279"></a>00279                               <span class="stringliteral">"indicates if the fits of the slitlet edge "</span>
+<a name="l00280"></a>00280                               <span class="stringliteral">"positions is carried trough by using a "</span>
+<a name="l00281"></a>00281                               <span class="stringliteral">"Boltzmann function as model function"</span>,
+<a name="l00282"></a>00282                               <span class="stringliteral">"sinfoni.distortion"</span>,
+<a name="l00283"></a>00283                               TRUE);
+<a name="l00284"></a>00284 
+<a name="l00285"></a>00285   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"dist-fit_boltz_ind"</span>);
+<a name="l00286"></a>00286   cpl_parameterlist_append(list, p);
+<a name="l00287"></a>00287 
+<a name="l00288"></a>00288 <span class="comment">/* indicator if the fit model function is a simple edge function or not */</span>
+<a name="l00289"></a>00289   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.distortion.fit_edge_indicator"</span>,
+<a name="l00290"></a>00290                   CPL_TYPE_BOOL,
+<a name="l00291"></a>00291                               <span class="stringliteral">"Fit Edge Indicator: "</span>
+<a name="l00292"></a>00292                               <span class="stringliteral">"indicates if the fits of the slitlet edge "</span>
+<a name="l00293"></a>00293                               <span class="stringliteral">"positions is carried through by using a "</span>
+<a name="l00294"></a>00294                               <span class="stringliteral">"simple edge function as model function"</span>,
+<a name="l00295"></a>00295                               <span class="stringliteral">"sinfoni.distortion"</span>,
+<a name="l00296"></a>00296                               FALSE);
+<a name="l00297"></a>00297 
+<a name="l00298"></a>00298   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"dist-fit_edge_ind"</span>);
+<a name="l00299"></a>00299   cpl_parameterlist_append(list, p);
+<a name="l00300"></a>00300 
+<a name="l00301"></a>00301  <span class="comment">/* indicator if the fit guess position are user </span>
+<a name="l00302"></a>00302 <span class="comment">    given or calculated automatically */</span>
+<a name="l00303"></a>00303 
+<a name="l00304"></a>00304   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.distortion.estimate_indicator"</span>,
+<a name="l00305"></a>00305                   CPL_TYPE_BOOL,
+<a name="l00306"></a>00306                               <span class="stringliteral">"Estimate Indicator: "</span>
+<a name="l00307"></a>00307                               <span class="stringliteral">"indicates if the fits of the slitlet edge "</span>
+<a name="l00308"></a>00308                               <span class="stringliteral">"positions is carried through by using a list "</span>
+<a name="l00309"></a>00309                               <span class="stringliteral">"of estimated guess positions in a file (TRUE)"</span>
+<a name="l00310"></a>00310                               <span class="stringliteral">"or if the initial positions are calculated "</span>
+<a name="l00311"></a>00311                               <span class="stringliteral">"automatically (FALSE). The estimation case "</span>
+<a name="l00312"></a>00312                               <span class="stringliteral">"is more stable"</span>,
+<a name="l00313"></a>00313                               <span class="stringliteral">"sinfoni.distortion"</span>,
+<a name="l00314"></a>00314                               FALSE);
+<a name="l00315"></a>00315 
+<a name="l00316"></a>00316   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"dist-estimate_ind"</span>);
+<a name="l00317"></a>00317   cpl_parameterlist_append(list, p);
+<a name="l00318"></a>00318 
+<a name="l00319"></a>00319 <span class="comment">/* pixel length of the row box within which </span>
+<a name="l00320"></a>00320 <span class="comment">   the fit of the slitlet positions is carried out*/</span>
+<a name="l00321"></a>00321 
+<a name="l00322"></a>00322   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.distortion.box_length"</span>,
+<a name="l00323"></a>00323                   CPL_TYPE_INT,
+<a name="l00324"></a>00324                               <span class="stringliteral">"Box Length: "</span>
+<a name="l00325"></a>00325                               <span class="stringliteral">"pixel length of the row box within "</span>
+<a name="l00326"></a>00326                               <span class="stringliteral">"which the fit is carried out"</span>,
+<a name="l00327"></a>00327                               <span class="stringliteral">"sinfoni.distortion"</span>,
+<a name="l00328"></a>00328                               32);
+<a name="l00329"></a>00329 
+<a name="l00330"></a>00330   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"dist-box_len"</span>);
+<a name="l00331"></a>00331   cpl_parameterlist_append(list, p);
+<a name="l00332"></a>00332 
+<a name="l00333"></a>00333 <span class="comment">/* float box half width in spectral direction */</span>
+<a name="l00334"></a>00334   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.distortion.y_box"</span>,
+<a name="l00335"></a>00335                   CPL_TYPE_DOUBLE,
+<a name="l00336"></a>00336                               <span class="stringliteral">"Y Box: half width of a small box in "</span>
+<a name="l00337"></a>00337                               <span class="stringliteral">"spectral direction within which the "</span>
+<a name="l00338"></a>00338                               <span class="stringliteral">"maximal intensity pixel is searched"</span>,
+<a name="l00339"></a>00339                               <span class="stringliteral">"sinfoni.distortion"</span>,
+<a name="l00340"></a>00340                               5.);
+<a name="l00341"></a>00341 
+<a name="l00342"></a>00342  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"dist-y_box"</span>);
+<a name="l00343"></a>00343   cpl_parameterlist_append(list, p);
+<a name="l00344"></a>00344 
+<a name="l00345"></a>00345 <span class="comment">/* maximal tolerable difference to the expected slitlet positions */</span>
+<a name="l00346"></a>00346   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.distortion.diff_tol"</span>,
+<a name="l00347"></a>00347                   CPL_TYPE_DOUBLE,
+<a name="l00348"></a>00348                               <span class="stringliteral">"Difference Tolearance: "</span>
+<a name="l00349"></a>00349                               <span class="stringliteral">"maximal tolerable difference of the "</span>
+<a name="l00350"></a>00350                               <span class="stringliteral">"resulting fit positions of the slitlet "</span>
+<a name="l00351"></a>00351                               <span class="stringliteral">"edges with respect to the expected positions"</span>,
+<a name="l00352"></a>00352                               <span class="stringliteral">"sinfoni.distortion"</span>,
+<a name="l00353"></a>00353                               2.);
+<a name="l00354"></a>00354 
+<a name="l00355"></a>00355   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"dist-diff_toll"</span>);
+<a name="l00356"></a>00356   cpl_parameterlist_append(list, p);
+<a name="l00357"></a>00357 
+<a name="l00358"></a>00358 
+<a name="l00359"></a>00359  p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.distortion.qc_thresh_min"</span>,
+<a name="l00360"></a>00360                   CPL_TYPE_INT,
+<a name="l00361"></a>00361                               <span class="stringliteral">"qc_thresh_min"</span>,
+<a name="l00362"></a>00362                               <span class="stringliteral">"sinfoni.distortion"</span>,
+<a name="l00363"></a>00363                               0);
+<a name="l00364"></a>00364 
+<a name="l00365"></a>00365   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"dist-qc_thresh_min"</span>);
+<a name="l00366"></a>00366   cpl_parameterlist_append(list, p);
+<a name="l00367"></a>00367 
+<a name="l00368"></a>00368 
+<a name="l00369"></a>00369   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.distortion.qc_thresh_max"</span>,
+<a name="l00370"></a>00370                   CPL_TYPE_INT,
+<a name="l00371"></a>00371                               <span class="stringliteral">"qc_thresh_max"</span>,
+<a name="l00372"></a>00372                               <span class="stringliteral">"sinfoni.distortion"</span>,
+<a name="l00373"></a>00373                               49000);
+<a name="l00374"></a>00374 
+<a name="l00375"></a>00375   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"dist-qc_thresh_max"</span>);
+<a name="l00376"></a>00376   cpl_parameterlist_append(list, p);
+<a name="l00377"></a>00377 
+<a name="l00378"></a>00378 
+<a name="l00379"></a>00379 
+<a name="l00380"></a>00380 
+<a name="l00381"></a>00381 
+<a name="l00382"></a>00382 
+<a name="l00383"></a>00383   <span class="comment">/* NORD SOUTH TEST */</span>
+<a name="l00384"></a>00384 
+<a name="l00385"></a>00385 
+<a name="l00386"></a>00386 
+<a name="l00387"></a>00387   <span class="comment">/* Clean Mean */</span>
+<a name="l00388"></a>00388   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.distortion.lower_rejection"</span>,
+<a name="l00389"></a>00389                   CPL_TYPE_DOUBLE,
+<a name="l00390"></a>00390                               <span class="stringliteral">"lower rejection: "</span>
+<a name="l00391"></a>00391                               <span class="stringliteral">"percentage of rejected low intensity pixels "</span>
+<a name="l00392"></a>00392                               <span class="stringliteral">"before averaging"</span>,
+<a name="l00393"></a>00393                               <span class="stringliteral">"sinfoni.distortion"</span>,
+<a name="l00394"></a>00394                                0.1,0.0,1.0);
+<a name="l00395"></a>00395 
+<a name="l00396"></a>00396   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"ns-lo_rejection"</span>);
+<a name="l00397"></a>00397   cpl_parameterlist_append(list, p);
+<a name="l00398"></a>00398 
+<a name="l00399"></a>00399   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.distortion.higher_rejection"</span>,
+<a name="l00400"></a>00400                   CPL_TYPE_DOUBLE,
+<a name="l00401"></a>00401                               <span class="stringliteral">"higher rejection: "</span>
+<a name="l00402"></a>00402                               <span class="stringliteral">"percentage of rejected high intensity pixels "</span>
+<a name="l00403"></a>00403                               <span class="stringliteral">"before averaging"</span>,
+<a name="l00404"></a>00404                               <span class="stringliteral">"sinfoni.distortion"</span>,
+<a name="l00405"></a>00405                               0.1,0.0,1.0);
+<a name="l00406"></a>00406 
+<a name="l00407"></a>00407   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"ns-hi_rejection"</span>);
+<a name="l00408"></a>00408   cpl_parameterlist_append(list, p);
+<a name="l00409"></a>00409 
+<a name="l00410"></a>00410 
+<a name="l00411"></a>00411   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.distortion.mask_ind"</span>,
+<a name="l00412"></a>00412                   CPL_TYPE_BOOL,
+<a name="l00413"></a>00413                               <span class="stringliteral">"Mask Index: "</span>
+<a name="l00414"></a>00414                              <span class="stringliteral">"indicator if a bad pixel mask is applied or not"</span>,
+<a name="l00415"></a>00415                               <span class="stringliteral">"sinfoni.distortion"</span>,
+<a name="l00416"></a>00416                               FALSE);
+<a name="l00417"></a>00417 
+<a name="l00418"></a>00418   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"ns-mask_ind"</span>);
+<a name="l00419"></a>00419   cpl_parameterlist_append(list, p);
+<a name="l00420"></a>00420 
+<a name="l00421"></a>00421 
+<a name="l00422"></a>00422   <span class="comment">/* Gauss Convolution */</span>
+<a name="l00423"></a>00423   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.distortion.gauss_ind"</span>,
+<a name="l00424"></a>00424                   CPL_TYPE_BOOL,
+<a name="l00425"></a>00425                               <span class="stringliteral">"Gauss Index: "</span>,
+<a name="l00426"></a>00426                               <span class="stringliteral">"sinfoni.distortion"</span>,
+<a name="l00427"></a>00427                               FALSE);
+<a name="l00428"></a>00428 
+<a name="l00429"></a>00429   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"ns-gauss_ind"</span>);
+<a name="l00430"></a>00430   cpl_parameterlist_append(list, p);
+<a name="l00431"></a>00431 
+<a name="l00432"></a>00432   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.distortion.kernel_half_width"</span>,
+<a name="l00433"></a>00433                   CPL_TYPE_INT,
+<a name="l00434"></a>00434                               <span class="stringliteral">"Kernel Half Width "</span>
+<a name="l00435"></a>00435                               <span class="stringliteral">"kernel half width of the Gaussian "</span>
+<a name="l00436"></a>00436                               <span class="stringliteral">"response function"</span>,
+<a name="l00437"></a>00437                               <span class="stringliteral">"sinfoni.distortion"</span>,
+<a name="l00438"></a>00438                                2);
+<a name="l00439"></a>00439 
+<a name="l00440"></a>00440   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"ns-khw"</span>);
+<a name="l00441"></a>00441   cpl_parameterlist_append(list, p);
+<a name="l00442"></a>00442 
+<a name="l00443"></a>00443 
+<a name="l00444"></a>00444 
+<a name="l00445"></a>00445   <span class="comment">/* North South Test */</span>
+<a name="l00446"></a>00446 
+<a name="l00447"></a>00447 
+<a name="l00448"></a>00448 
+<a name="l00449"></a>00449   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.distortion.ns_half_width"</span>,
+<a name="l00450"></a>00450                   CPL_TYPE_INT,
+<a name="l00451"></a>00451                               <span class="stringliteral">"Half Width"</span>,
+<a name="l00452"></a>00452                               <span class="stringliteral">"sinfoni.distortion"</span>,
+<a name="l00453"></a>00453                                4);
+<a name="l00454"></a>00454 
+<a name="l00455"></a>00455   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"ns-hw"</span>);
+<a name="l00456"></a>00456   cpl_parameterlist_append(list, p);
+<a name="l00457"></a>00457 
+<a name="l00458"></a>00458   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.distortion.ns_fwhm"</span>,
+<a name="l00459"></a>00459                   CPL_TYPE_DOUBLE,
+<a name="l00460"></a>00460                               <span class="stringliteral">"FWHM"</span>,
+<a name="l00461"></a>00461                               <span class="stringliteral">"sinfoni.distortion"</span>,
+<a name="l00462"></a>00462                                2.);
+<a name="l00463"></a>00463 
+<a name="l00464"></a>00464   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"ns-fwhm"</span>);
+<a name="l00465"></a>00465   cpl_parameterlist_append(list, p);
+<a name="l00466"></a>00466 
+<a name="l00467"></a>00467 
+<a name="l00468"></a>00468   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.distortion.min_diff"</span>,
+<a name="l00469"></a>00469                   CPL_TYPE_DOUBLE,
+<a name="l00470"></a>00470                               <span class="stringliteral">"Minimum of Difference"</span>,
+<a name="l00471"></a>00471                               <span class="stringliteral">"sinfoni.distortion"</span>,
+<a name="l00472"></a>00472                               1.);
+<a name="l00473"></a>00473 
+<a name="l00474"></a>00474   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"ns-min_diff"</span>);
+<a name="l00475"></a>00475   cpl_parameterlist_append(list, p);
+<a name="l00476"></a>00476 
+<a name="l00477"></a>00477 
+<a name="l00478"></a>00478   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.distortion.dev_tol"</span>,
+<a name="l00479"></a>00479                   CPL_TYPE_DOUBLE,
+<a name="l00480"></a>00480                               <span class="stringliteral">"Dev Tol"</span>,
+<a name="l00481"></a>00481                               <span class="stringliteral">"sinfoni.distortion"</span>,
+<a name="l00482"></a>00482                               20.);
+<a name="l00483"></a>00483 
+<a name="l00484"></a>00484 
+<a name="l00485"></a>00485   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"ns-dev_tol"</span>);
+<a name="l00486"></a>00486   cpl_parameterlist_append(list, p);
+<a name="l00487"></a>00487 
+<a name="l00488"></a>00488 
+<a name="l00489"></a>00489   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.distortion.arcs_thresh_factor"</span>,
+<a name="l00490"></a>00490                   CPL_TYPE_DOUBLE,
+<a name="l00491"></a>00491                               <span class="stringliteral">"arcs threshold factor. "</span>
+<a name="l00492"></a>00492                               <span class="stringliteral">"median_value(image)+ kappa*sigma is the "</span>
+<a name="l00493"></a>00493                               <span class="stringliteral">"minimum intensity threshold of accepted image"</span>
+<a name="l00494"></a>00494                               <span class="stringliteral">"pixels"</span>,
+<a name="l00495"></a>00495                               <span class="stringliteral">"sinfoni.distortion"</span>,
+<a name="l00496"></a>00496                               0.33333);
+<a name="l00497"></a>00497 
+<a name="l00498"></a>00498 
+<a name="l00499"></a>00499   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"arcs_thresh_factor"</span>);
+<a name="l00500"></a>00500   cpl_parameterlist_append(list, p);
+<a name="l00501"></a>00501 
+<a name="l00502"></a>00502 
+<a name="l00503"></a>00503 
+<a name="l00504"></a>00504   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.distortion.arcs_min_arclen_factor"</span>,
+<a name="l00505"></a>00505                   CPL_TYPE_DOUBLE,
+<a name="l00506"></a>00506                               <span class="stringliteral">"factor which sets minimum arc length (1.0-2)"</span>,
+<a name="l00507"></a>00507                               <span class="stringliteral">"sinfoni.distortion"</span>,
+<a name="l00508"></a>00508                               1.19);
+<a name="l00509"></a>00509 
+<a name="l00510"></a>00510 
+<a name="l00511"></a>00511   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"arcs_min_arclen_factor"</span>);
+<a name="l00512"></a>00512   cpl_parameterlist_append(list, p);
+<a name="l00513"></a>00513 
+<a name="l00514"></a>00514 
+<a name="l00515"></a>00515   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.distortion.arcs_window_size"</span>,
+<a name="l00516"></a>00516                   CPL_TYPE_INT,
+<a name="l00517"></a>00517                               <span class="stringliteral">"Size of window for low pass fileter used in"</span>
+<a name="l00518"></a>00518                               <span class="stringliteral">"an horizzontal low pass filter to remove "</span>
+<a name="l00519"></a>00519                               <span class="stringliteral">"unwanted arcs (5-64)"</span>,
+<a name="l00520"></a>00520                               <span class="stringliteral">"sinfoni.distortion"</span>,
+<a name="l00521"></a>00521                               14);
+<a name="l00522"></a>00522 
+<a name="l00523"></a>00523 
+<a name="l00524"></a>00524   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"arcs_window_size"</span>);
+<a name="l00525"></a>00525   cpl_parameterlist_append(list, p);
+<a name="l00526"></a>00526 
+<a name="l00527"></a>00527 
+<a name="l00528"></a>00528   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.distortion.smooth_rad"</span>,
+<a name="l00529"></a>00529                   CPL_TYPE_INT,
+<a name="l00530"></a>00530                               <span class="stringliteral">"Size of smoothing factor (1-11) used to "</span>
+<a name="l00531"></a>00531                               <span class="stringliteral">"prevent for possible intensity drops from "</span>
+<a name="l00532"></a>00532                               <span class="stringliteral">"detector electronics on fibre illuminated "</span>
+<a name="l00533"></a>00533                               <span class="stringliteral">"slitlets (1-11)"</span>,
+<a name="l00534"></a>00534                               <span class="stringliteral">"sinfoni.distortion"</span>,
+<a name="l00535"></a>00535                               3);
+<a name="l00536"></a>00536 
+<a name="l00537"></a>00537 
+<a name="l00538"></a>00538   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"smooth_rad"</span>);
+<a name="l00539"></a>00539   cpl_parameterlist_append(list, p);
+<a name="l00540"></a>00540 
+<a name="l00541"></a>00541 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__distortion__config_8h_source.html b/html/sinfo__distortion__config_8h_source.html
new file mode 100644
index 0000000..17b0838
--- /dev/null
+++ b/html/sinfo__distortion__config_8h_source.html
@@ -0,0 +1,48 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_distortion_config.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_distortion_config.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_distortion_config.h,v 1.1 2006/10/20 08:06:32 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the CPL (Common Pipeline Library)</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
+<a name="l00007"></a>00007 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span>
+<a name="l00008"></a>00008 <span class="comment"> * License as published by the Free Software Foundation; either</span>
+<a name="l00009"></a>00009 <span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
+<a name="l00014"></a>00014 <span class="comment"> * Lesser General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
+<a name="l00017"></a>00017 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2006/10/20 08:06:32 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.1 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> */</span>
+<a name="l00026"></a>00026 
+<a name="l00027"></a>00027  <span class="comment">/****************************************************************</span>
+<a name="l00028"></a>00028 <span class="comment">  *   Wavecal Frames Data Reduction Parameter Initialization        *</span>
+<a name="l00029"></a>00029 <span class="comment">  ****************************************************************/</span>
+<a name="l00030"></a>00030 <span class="preprocessor">#include <cpl.h></span>    <span class="comment">/* defines parlist structure */</span>
+<a name="l00031"></a>00031 <span class="keywordtype">void</span> sinfo_distortion_config_add(cpl_parameterlist *list);
+<a name="l00032"></a>00032 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__dump_8c_source.html b/html/sinfo__dump_8c_source.html
new file mode 100644
index 0000000..ff72dae
--- /dev/null
+++ b/html/sinfo__dump_8c_source.html
@@ -0,0 +1,377 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_dump.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_dump.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*                                                                           *</span>
+<a name="l00002"></a>00002 <span class="comment"> *   This file is part of the SINFONI   Pipeline                             *</span>
+<a name="l00003"></a>00003 <span class="comment"> *   Copyright (C) 2002,2003 European Southern Observatory                   *</span>
+<a name="l00004"></a>00004 <span class="comment"> *                                                                           *</span>
+<a name="l00005"></a>00005 <span class="comment"> *   This library is free software; you can redistribute it and/or modify    *</span>
+<a name="l00006"></a>00006 <span class="comment"> *   it under the terms of the GNU General Public License as published by    *</span>
+<a name="l00007"></a>00007 <span class="comment"> *   the Free Software Foundation; either version 2 of the License, or       *</span>
+<a name="l00008"></a>00008 <span class="comment"> *   (at your option) any later version.                                     *</span>
+<a name="l00009"></a>00009 <span class="comment"> *                                                                           *</span>
+<a name="l00010"></a>00010 <span class="comment"> *   This program is distributed in the hope that it will be useful,         *</span>
+<a name="l00011"></a>00011 <span class="comment"> *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *</span>
+<a name="l00012"></a>00012 <span class="comment"> *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *</span>
+<a name="l00013"></a>00013 <span class="comment"> *   GNU General Public License for more details.                            *</span>
+<a name="l00014"></a>00014 <span class="comment"> *                                                                           *</span>
+<a name="l00015"></a>00015 <span class="comment"> *   You should have received a copy of the GNU General Public License       *</span>
+<a name="l00016"></a>00016 <span class="comment"> *   along with this program; if not, write to the Free Software             *</span>
+<a name="l00017"></a>00017 <span class="comment"> *   Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA    *</span>
+<a name="l00018"></a>00018 <span class="comment"> *                                                                           */</span>
+<a name="l00019"></a>00019 
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2012/03/02 08:42:20 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.8 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Log: sinfo_dump.c,v $</span>
+<a name="l00026"></a>00026 <span class="comment"> * Revision 1.8  2012/03/02 08:42:20  amodigli</span>
+<a name="l00027"></a>00027 <span class="comment"> * fixed some typos on doxygen</span>
+<a name="l00028"></a>00028 <span class="comment"> *</span>
+<a name="l00029"></a>00029 <span class="comment"> * Revision 1.7  2011/11/23 17:29:19  amodigli</span>
+<a name="l00030"></a>00030 <span class="comment"> * fix warning with cpl6</span>
+<a name="l00031"></a>00031 <span class="comment"> *</span>
+<a name="l00032"></a>00032 <span class="comment"> * Revision 1.6  2008/01/17 07:54:04  amodigli</span>
+<a name="l00033"></a>00033 <span class="comment"> * shorten long lines</span>
+<a name="l00034"></a>00034 <span class="comment"> *</span>
+<a name="l00035"></a>00035 <span class="comment"> * Revision 1.5  2007/08/11 10:45:47  amodigli</span>
+<a name="l00036"></a>00036 <span class="comment"> * upgrade to CPL4, fixed compil warnings</span>
+<a name="l00037"></a>00037 <span class="comment"> *</span>
+<a name="l00038"></a>00038 <span class="comment"> * Revision 1.4  2007/06/06 07:10:45  amodigli</span>
+<a name="l00039"></a>00039 <span class="comment"> * replaced tab with 4 spaces</span>
+<a name="l00040"></a>00040 <span class="comment"> *</span>
+<a name="l00041"></a>00041 <span class="comment"> * Revision 1.3  2006/10/20 08:07:05  amodigli</span>
+<a name="l00042"></a>00042 <span class="comment"> * using prefix sinfo_ in place of sinfoni_ for includes</span>
+<a name="l00043"></a>00043 <span class="comment"> *</span>
+<a name="l00044"></a>00044 <span class="comment"> * Revision 1.2  2006/10/16 07:26:23  amodigli</span>
+<a name="l00045"></a>00045 <span class="comment"> * shortened line length</span>
+<a name="l00046"></a>00046 <span class="comment"> *</span>
+<a name="l00047"></a>00047 <span class="comment"> * Revision 1.1  2006/08/09 12:20:11  amodigli</span>
+<a name="l00048"></a>00048 <span class="comment"> * added sinfo_dump.h sinfo_dump.c</span>
+<a name="l00049"></a>00049 <span class="comment"> *</span>
+<a name="l00050"></a>00050 <span class="comment"> * Revision 1.7  2006/05/12 15:02:05  jmlarsen</span>
+<a name="l00051"></a>00051 <span class="comment"> * Support NULL tags</span>
+<a name="l00052"></a>00052 <span class="comment"> *</span>
+<a name="l00053"></a>00053 <span class="comment"> * Revision 1.6  2006/02/28 09:15:22  jmlarsen</span>
+<a name="l00054"></a>00054 <span class="comment"> * Minor update</span>
+<a name="l00055"></a>00055 <span class="comment"> *</span>
+<a name="l00056"></a>00056 <span class="comment"> * Revision 1.5  2006/02/15 13:19:15  jmlarsen</span>
+<a name="l00057"></a>00057 <span class="comment"> * Reduced source code max. line length</span>
+<a name="l00058"></a>00058 <span class="comment"> *</span>
+<a name="l00059"></a>00059 <span class="comment"> * Revision 1.4  2005/12/19 16:17:56  jmlarsen</span>
+<a name="l00060"></a>00060 <span class="comment"> * Replaced bool -> int</span>
+<a name="l00061"></a>00061 <span class="comment"> *</span>
+<a name="l00062"></a>00062 <span class="comment"> */</span>
+<a name="l00063"></a>00063 
+<a name="l00064"></a>00064 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00065"></a>00065 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00066"></a>00066 <span class="preprocessor">#endif</span>
+<a name="l00067"></a>00067 <span class="preprocessor"></span>
+<a name="l00070"></a>00070 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00077"></a>00077 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00078"></a>00078 
+<a name="l00079"></a>00079 
+<a name="l00080"></a>00080 <span class="preprocessor">#include <sinfo_dump.h></span>
+<a name="l00081"></a>00081 <span class="preprocessor">#include <sinfo_utils.h></span>
+<a name="l00082"></a>00082 <span class="preprocessor">#include <sinfo_error.h></span>
+<a name="l00083"></a>00083 <span class="preprocessor">#include <sinfo_msg.h></span>
+<a name="l00084"></a>00084 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00085"></a>00085 
+<a name="l00086"></a>00086 <span class="comment">/*----------------------------------------------------------------*/</span>
+<a name="l00098"></a>00098 <span class="comment">/*----------------------------------------------------------------*/</span>
+<a name="l00099"></a>00099 cpl_error_code
+<a name="l00100"></a>00100 sinfo_print_cpl_propertylist(<span class="keyword">const</span> cpl_propertylist *pl, <span class="keywordtype">long</span> low, <span class="keywordtype">long</span> high)
+<a name="l00101"></a>00101 {
+<a name="l00102"></a>00102     cpl_property *prop;
+<a name="l00103"></a>00103     <span class="keywordtype">long</span> i = 0;
+<a name="l00104"></a>00104     
+<a name="l00105"></a>00105     assure (0 <= low && high <= cpl_propertylist_get_size(pl) && low <= high,
+<a name="l00106"></a>00106         CPL_ERROR_ILLEGAL_INPUT, <span class="stringliteral">"Illegal range"</span>);
+<a name="l00107"></a>00107     <span class="comment">/* Printing an empty range is allowed but only when low == high */</span>
+<a name="l00108"></a>00108 
+<a name="l00109"></a>00109     <span class="keywordflow">if</span> (pl == NULL){
+<a name="l00110"></a>00110     sinfo_msg(<span class="stringliteral">"NULL"</span>);
+<a name="l00111"></a>00111     }
+<a name="l00112"></a>00112     <span class="keywordflow">else</span> <span class="keywordflow">if</span> (cpl_propertylist_is_empty(pl))  {
+<a name="l00113"></a>00113     sinfo_msg(<span class="stringliteral">"[Empty property list]"</span>);
+<a name="l00114"></a>00114     }
+<a name="l00115"></a>00115     <span class="keywordflow">else</span>    
+<a name="l00116"></a>00116     <span class="keywordflow">for</span> (i = low; i < high; i++)
+<a name="l00117"></a>00117         {
+<a name="l00118"></a>00118         <span class="comment">/* bug workaround: remove const cast when declaration </span>
+<a name="l00119"></a>00119 <span class="comment">           of cpl_propertylist_get() is changed */</span>
+<a name="l00120"></a>00120         prop = cpl_propertylist_get((cpl_propertylist *)pl, i);
+<a name="l00121"></a>00121         check (sinfo_print_cpl_property(prop), 
+<a name="l00122"></a>00122                 <span class="stringliteral">"Error printing property"</span>);
+<a name="l00123"></a>00123         }
+<a name="l00124"></a>00124     
+<a name="l00125"></a>00125   cleanup:
+<a name="l00126"></a>00126     <span class="keywordflow">return</span> cpl_error_get_code();
+<a name="l00127"></a>00127 }
+<a name="l00128"></a>00128 <span class="comment">/*----------------------------------------------------------------*/</span>
+<a name="l00136"></a>00136 <span class="comment">/*----------------------------------------------------------------*/</span>
+<a name="l00137"></a>00137 
+<a name="l00138"></a>00138 cpl_error_code
+<a name="l00139"></a>00139 sinfo_print_cpl_property(<span class="keyword">const</span> cpl_property *prop)
+<a name="l00140"></a>00140 {
+<a name="l00141"></a>00141     cpl_type t;
+<a name="l00142"></a>00142 
+<a name="l00143"></a>00143     <span class="keywordflow">if</span> (prop == NULL)
+<a name="l00144"></a>00144     {
+<a name="l00145"></a>00145         sinfo_msg(<span class="stringliteral">"NULL"</span>);
+<a name="l00146"></a>00146     }
+<a name="l00147"></a>00147     <span class="keywordflow">else</span>
+<a name="l00148"></a>00148     {   
+<a name="l00149"></a>00149         <span class="comment">/* print property with this formatting</span>
+<a name="l00150"></a>00150 <span class="comment">           NAME =</span>
+<a name="l00151"></a>00151 <span class="comment">             VALUE</span>
+<a name="l00152"></a>00152 <span class="comment">           COMMENT</span>
+<a name="l00153"></a>00153 <span class="comment">        */</span>
+<a name="l00154"></a>00154 
+<a name="l00155"></a>00155         <span class="comment">/* print name */</span>
+<a name="l00156"></a>00156         
+<a name="l00157"></a>00157         sinfo_msg(<span class="stringliteral">"%s ="</span>, cpl_property_get_name(prop));
+<a name="l00158"></a>00158 
+<a name="l00159"></a>00159         <span class="comment">/* print value */</span>
+<a name="l00160"></a>00160         
+<a name="l00161"></a>00161         check( t = cpl_property_get_type(prop), 
+<a name="l00162"></a>00162                   <span class="stringliteral">"Could not read property type"</span>);
+<a name="l00163"></a>00163         
+<a name="l00164"></a>00164         <span class="keywordflow">switch</span>(t & (~CPL_TYPE_FLAG_ARRAY))
+<a name="l00165"></a>00165         {
+<a name="l00166"></a>00166         <span class="keywordflow">case</span> CPL_TYPE_CHAR:
+<a name="l00167"></a>00167             <span class="keywordflow">if</span> (t & CPL_TYPE_FLAG_ARRAY)  <span class="comment">/* if type is string */</span>
+<a name="l00168"></a>00168             {
+<a name="l00169"></a>00169                 sinfo_msg(<span class="stringliteral">"  '%s'"</span>, cpl_property_get_string(prop));
+<a name="l00170"></a>00170             }
+<a name="l00171"></a>00171             <span class="keywordflow">else</span>                          <span class="comment">/* an ordinary char */</span>
+<a name="l00172"></a>00172             {
+<a name="l00173"></a>00173                 sinfo_msg(<span class="stringliteral">"  %c"</span>, cpl_property_get_char(prop));
+<a name="l00174"></a>00174             }
+<a name="l00175"></a>00175             <span class="keywordflow">break</span>;
+<a name="l00176"></a>00176         <span class="keywordflow">case</span> CPL_TYPE_BOOL:    <span class="keywordflow">if</span> (cpl_property_get_bool(prop))
+<a name="l00177"></a>00177             {sinfo_msg(<span class="stringliteral">"  true"</span>);}
+<a name="l00178"></a>00178         <span class="keywordflow">else</span>
+<a name="l00179"></a>00179             {sinfo_msg(<span class="stringliteral">"  false"</span>);}
+<a name="l00180"></a>00180             <span class="keywordflow">break</span>;
+<a name="l00181"></a>00181         <span class="keywordflow">case</span> CPL_TYPE_UCHAR: 
+<a name="l00182"></a>00182       sinfo_msg(<span class="stringliteral">"%c"</span>,cpl_property_get_char(prop)); 
+<a name="l00183"></a>00183           <span class="keywordflow">break</span>;
+<a name="l00184"></a>00184         <span class="keywordflow">case</span> CPL_TYPE_INT:   
+<a name="l00185"></a>00185       sinfo_msg(<span class="stringliteral">"%d"</span>,cpl_property_get_int(prop)); 
+<a name="l00186"></a>00186           <span class="keywordflow">break</span>;
+<a name="l00187"></a>00187         <span class="keywordflow">case</span> CPL_TYPE_UINT:  
+<a name="l00188"></a>00188           sinfo_msg(<span class="stringliteral">"%d"</span>,cpl_property_get_int(prop)); 
+<a name="l00189"></a>00189           <span class="keywordflow">break</span>;
+<a name="l00190"></a>00190         <span class="keywordflow">case</span> CPL_TYPE_LONG: 
+<a name="l00191"></a>00191           sinfo_msg(<span class="stringliteral">"%ld"</span>,cpl_property_get_long(prop)); 
+<a name="l00192"></a>00192           <span class="keywordflow">break</span>;
+<a name="l00193"></a>00193         <span class="keywordflow">case</span> CPL_TYPE_ULONG: 
+<a name="l00194"></a>00194           sinfo_msg(<span class="stringliteral">"%ld"</span>,cpl_property_get_long(prop)); 
+<a name="l00195"></a>00195           <span class="keywordflow">break</span>;
+<a name="l00196"></a>00196         <span class="keywordflow">case</span> CPL_TYPE_FLOAT: 
+<a name="l00197"></a>00197           sinfo_msg(<span class="stringliteral">"%f"</span>,cpl_property_get_float(prop)); 
+<a name="l00198"></a>00198           <span class="keywordflow">break</span>;
+<a name="l00199"></a>00199         <span class="keywordflow">case</span> CPL_TYPE_DOUBLE: 
+<a name="l00200"></a>00200           sinfo_msg(<span class="stringliteral">"%f"</span>,cpl_property_get_double(prop)); 
+<a name="l00201"></a>00201           <span class="keywordflow">break</span>;
+<a name="l00202"></a>00202         <span class="keywordflow">case</span> CPL_TYPE_POINTER: 
+<a name="l00203"></a>00203           sinfo_msg(<span class="stringliteral">"POINTER"</span>);    
+<a name="l00204"></a>00204           <span class="keywordflow">break</span>;
+<a name="l00205"></a>00205         <span class="keywordflow">case</span> CPL_TYPE_INVALID: 
+<a name="l00206"></a>00206           sinfo_msg(<span class="stringliteral">"INVALID"</span>);    
+<a name="l00207"></a>00207           <span class="keywordflow">break</span>;
+<a name="l00208"></a>00208         <span class="keywordflow">default</span>: 
+<a name="l00209"></a>00209           sinfo_msg(<span class="stringliteral">"  unrecognized property"</span>);  
+<a name="l00210"></a>00210           <span class="keywordflow">break</span>;
+<a name="l00211"></a>00211         }
+<a name="l00212"></a>00212         
+<a name="l00213"></a>00213         <span class="comment">/* Is this property an array? */</span>
+<a name="l00214"></a>00214         <span class="keywordflow">if</span> (t & CPL_TYPE_FLAG_ARRAY){
+<a name="l00215"></a>00215            cpl_msg_info(cpl_func,<span class="stringliteral">"  (array size = %"</span> CPL_SIZE_FORMAT <span class="stringliteral">" )"</span>, 
+<a name="l00216"></a>00216               cpl_property_get_size(prop));
+<a name="l00217"></a>00217         }
+<a name="l00218"></a>00218 
+<a name="l00219"></a>00219         <span class="comment">/* Print comment */</span>
+<a name="l00220"></a>00220         <span class="keywordflow">if</span> (cpl_property_get_comment(prop) != NULL){
+<a name="l00221"></a>00221         sinfo_msg(<span class="stringliteral">"    %s"</span>, cpl_property_get_comment(prop));
+<a name="l00222"></a>00222         }
+<a name="l00223"></a>00223     }
+<a name="l00224"></a>00224 
+<a name="l00225"></a>00225   cleanup:
+<a name="l00226"></a>00226     <span class="keywordflow">return</span> cpl_error_get_code();
+<a name="l00227"></a>00227 }
+<a name="l00228"></a>00228 
+<a name="l00229"></a>00229 <span class="comment">/*----------------------------------------------------------------*/</span>
+<a name="l00237"></a>00237 <span class="comment">/*----------------------------------------------------------------*/</span>
+<a name="l00238"></a>00238 cpl_error_code
+<a name="l00239"></a>00239 sinfo_print_cpl_frameset(<span class="keyword">const</span> cpl_frameset *frames)
+<a name="l00240"></a>00240 {
+<a name="l00241"></a>00241     <span class="comment">/* Two special cases: a NULL frame set and an empty frame set */</span>
+<a name="l00242"></a>00242 
+<a name="l00243"></a>00243     <span class="keywordflow">if</span> (frames == NULL)
+<a name="l00244"></a>00244     {
+<a name="l00245"></a>00245         sinfo_msg(<span class="stringliteral">"NULL"</span>);
+<a name="l00246"></a>00246     }
+<a name="l00247"></a>00247     <span class="keywordflow">else</span>
+<a name="l00248"></a>00248     {
+<a name="l00249"></a>00249         <span class="keyword">const</span> cpl_frame *f = NULL;
+<a name="l00250"></a>00250         check( f = cpl_frameset_get_first_const(frames), 
+<a name="l00251"></a>00251                    <span class="stringliteral">"Error reading frameset"</span>);
+<a name="l00252"></a>00252         
+<a name="l00253"></a>00253         <span class="keywordflow">if</span> (f == NULL)
+<a name="l00254"></a>00254         {
+<a name="l00255"></a>00255             sinfo_msg(<span class="stringliteral">"[Empty frame set]"</span>);
+<a name="l00256"></a>00256         }
+<a name="l00257"></a>00257         <span class="keywordflow">else</span>
+<a name="l00258"></a>00258         {
+<a name="l00259"></a>00259             <span class="keywordflow">while</span>(f != NULL)
+<a name="l00260"></a>00260             {
+<a name="l00261"></a>00261                 check( sinfo_print_cpl_frame(f), 
+<a name="l00262"></a>00262                                   <span class="stringliteral">"Could not print frame"</span>);
+<a name="l00263"></a>00263                 check( f = cpl_frameset_get_next_const(frames), 
+<a name="l00264"></a>00264                                   <span class="stringliteral">"Error reading frameset"</span>);
+<a name="l00265"></a>00265             }
+<a name="l00266"></a>00266         }
+<a name="l00267"></a>00267     }
+<a name="l00268"></a>00268     
+<a name="l00269"></a>00269   cleanup:
+<a name="l00270"></a>00270     <span class="keywordflow">return</span> cpl_error_get_code();
+<a name="l00271"></a>00271 }
+<a name="l00272"></a>00272 
+<a name="l00273"></a>00273 <span class="comment">/*----------------------------------------------------------------*/</span>
+<a name="l00281"></a>00281 <span class="comment">/*----------------------------------------------------------------*/</span>
+<a name="l00282"></a>00282 cpl_error_code
+<a name="l00283"></a>00283 sinfo_print_cpl_frame(<span class="keyword">const</span> cpl_frame *f)
+<a name="l00284"></a>00284 {
+<a name="l00285"></a>00285     <span class="keywordflow">if</span> (f == NULL)
+<a name="l00286"></a>00286     {
+<a name="l00287"></a>00287         sinfo_msg(<span class="stringliteral">"NULL"</span>);
+<a name="l00288"></a>00288     }
+<a name="l00289"></a>00289     <span class="keywordflow">else</span>
+<a name="l00290"></a>00290     {
+<a name="l00291"></a>00291         sinfo_msg(<span class="stringliteral">"%-7s %-20s '%s'"</span>, 
+<a name="l00292"></a>00292              sinfo_tostring_cpl_frame_group(cpl_frame_get_group(f)),
+<a name="l00293"></a>00293              cpl_frame_get_tag(f) != NULL ? 
+<a name="l00294"></a>00294                      cpl_frame_get_tag(f) : <span class="stringliteral">"Null"</span>,
+<a name="l00295"></a>00295              cpl_frame_get_filename(f));
+<a name="l00296"></a>00296         
+<a name="l00297"></a>00297         <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"type \t= %s"</span>,   
+<a name="l00298"></a>00298             sinfo_tostring_cpl_frame_type (cpl_frame_get_type (f)));
+<a name="l00299"></a>00299         <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"group \t= %s"</span>,  
+<a name="l00300"></a>00300             sinfo_tostring_cpl_frame_group(cpl_frame_get_group(f)));
+<a name="l00301"></a>00301         <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"level \t= %s"</span>,  
+<a name="l00302"></a>00302             sinfo_tostring_cpl_frame_level(cpl_frame_get_level(f)));
+<a name="l00303"></a>00303     }
+<a name="l00304"></a>00304 
+<a name="l00305"></a>00305     <span class="keywordflow">return</span> cpl_error_get_code();
+<a name="l00306"></a>00306 }
+<a name="l00307"></a>00307 
+<a name="l00308"></a>00308 <span class="comment">/*----------------------------------------------------------------*/</span>
+<a name="l00314"></a>00314 <span class="comment">/*----------------------------------------------------------------*/</span>
+<a name="l00315"></a>00315 <span class="keyword">const</span> <span class="keywordtype">char</span> *
+<a name="l00316"></a>00316 sinfo_tostring_cpl_frame_type(cpl_frame_type ft)
+<a name="l00317"></a>00317 {    
+<a name="l00318"></a>00318     <span class="keywordflow">switch</span>(ft)
+<a name="l00319"></a>00319     {
+<a name="l00320"></a>00320     <span class="keywordflow">case</span> CPL_FRAME_TYPE_NONE:   <span class="keywordflow">return</span> <span class="stringliteral">"NONE"</span>;      <span class="keywordflow">break</span>;
+<a name="l00321"></a>00321     <span class="keywordflow">case</span> CPL_FRAME_TYPE_IMAGE:  <span class="keywordflow">return</span> <span class="stringliteral">"IMAGE"</span>;     <span class="keywordflow">break</span>;
+<a name="l00322"></a>00322     <span class="keywordflow">case</span> CPL_FRAME_TYPE_MATRIX: <span class="keywordflow">return</span> <span class="stringliteral">"MATRIX"</span>;    <span class="keywordflow">break</span>;
+<a name="l00323"></a>00323     <span class="keywordflow">case</span> CPL_FRAME_TYPE_TABLE:  <span class="keywordflow">return</span> <span class="stringliteral">"TABLE"</span>;     <span class="keywordflow">break</span>;
+<a name="l00324"></a>00324     <span class="keywordflow">default</span>: <span class="keywordflow">return</span> <span class="stringliteral">"unrecognized frame type"</span>;
+<a name="l00325"></a>00325     }
+<a name="l00326"></a>00326 }
+<a name="l00327"></a>00327 
+<a name="l00328"></a>00328 <span class="comment">/*----------------------------------------------------------------*/</span>
+<a name="l00334"></a>00334 <span class="comment">/*----------------------------------------------------------------*/</span>
+<a name="l00335"></a>00335 <span class="keyword">const</span> <span class="keywordtype">char</span> *
+<a name="l00336"></a>00336 sinfo_tostring_cpl_frame_group(cpl_frame_group fg)
+<a name="l00337"></a>00337 {
+<a name="l00338"></a>00338     <span class="keywordflow">switch</span>(fg)
+<a name="l00339"></a>00339     {
+<a name="l00340"></a>00340     <span class="keywordflow">case</span> CPL_FRAME_GROUP_NONE:    <span class="keywordflow">return</span> <span class="stringliteral">"NONE"</span>;                    <span class="keywordflow">break</span>;
+<a name="l00341"></a>00341     <span class="keywordflow">case</span> CPL_FRAME_GROUP_RAW:     <span class="keywordflow">return</span> CPL_FRAME_GROUP_RAW_ID;    <span class="keywordflow">break</span>;
+<a name="l00342"></a>00342     <span class="keywordflow">case</span> CPL_FRAME_GROUP_CALIB:   <span class="keywordflow">return</span> CPL_FRAME_GROUP_CALIB_ID;  <span class="keywordflow">break</span>;
+<a name="l00343"></a>00343     <span class="keywordflow">case</span> CPL_FRAME_GROUP_PRODUCT: <span class="keywordflow">return</span> CPL_FRAME_GROUP_PRODUCT_ID;<span class="keywordflow">break</span>;
+<a name="l00344"></a>00344     <span class="keywordflow">default</span>:
+<a name="l00345"></a>00345         <span class="keywordflow">return</span> <span class="stringliteral">"unrecognized frame group"</span>;
+<a name="l00346"></a>00346     }
+<a name="l00347"></a>00347 }
+<a name="l00348"></a>00348 
+<a name="l00349"></a>00349 <span class="comment">/*----------------------------------------------------------------*/</span>
+<a name="l00355"></a>00355 <span class="comment">/*----------------------------------------------------------------*/</span>
+<a name="l00356"></a>00356 <span class="keyword">const</span> <span class="keywordtype">char</span> *
+<a name="l00357"></a>00357 sinfo_tostring_cpl_frame_level(cpl_frame_level fl)
+<a name="l00358"></a>00358 {
+<a name="l00359"></a>00359     
+<a name="l00360"></a>00360     <span class="keywordflow">switch</span>(fl)
+<a name="l00361"></a>00361     {
+<a name="l00362"></a>00362     <span class="keywordflow">case</span> CPL_FRAME_LEVEL_NONE:        <span class="keywordflow">return</span> <span class="stringliteral">"NONE"</span>;        <span class="keywordflow">break</span>;
+<a name="l00363"></a>00363     <span class="keywordflow">case</span> CPL_FRAME_LEVEL_TEMPORARY:   <span class="keywordflow">return</span> <span class="stringliteral">"TEMPORARY"</span>;   <span class="keywordflow">break</span>;
+<a name="l00364"></a>00364     <span class="keywordflow">case</span> CPL_FRAME_LEVEL_INTERMEDIATE:<span class="keywordflow">return</span> <span class="stringliteral">"INTERMEDIATE"</span>;<span class="keywordflow">break</span>;
+<a name="l00365"></a>00365     <span class="keywordflow">case</span> CPL_FRAME_LEVEL_FINAL:       <span class="keywordflow">return</span> <span class="stringliteral">"FINAL"</span>;       <span class="keywordflow">break</span>;
+<a name="l00366"></a>00366     <span class="keywordflow">default</span>: <span class="keywordflow">return</span> <span class="stringliteral">"unrecognized frame level"</span>;
+<a name="l00367"></a>00367     }
+<a name="l00368"></a>00368 }
+<a name="l00369"></a>00369 
+<a name="l00370"></a>00370 
+<a name="l00371"></a>00371 <span class="comment">/*----------------------------------------------------------------*/</span>
+<a name="l00377"></a>00377 <span class="comment">/*----------------------------------------------------------------*/</span>
+<a name="l00378"></a>00378 <span class="keyword">const</span> <span class="keywordtype">char</span> *
+<a name="l00379"></a>00379 sinfo_tostring_cpl_type(cpl_type t)
+<a name="l00380"></a>00380 {
+<a name="l00381"></a>00381 
+<a name="l00382"></a>00382     <span class="comment">/* Note that CPL_TYPE_STRING is shorthand</span>
+<a name="l00383"></a>00383 <span class="comment">       for CPL_TYPE_CHAR | CPL_TYPE_FLAG_ARRAY . */</span>
+<a name="l00384"></a>00384 
+<a name="l00385"></a>00385     <span class="keywordflow">if</span> (!(t & CPL_TYPE_FLAG_ARRAY))
+<a name="l00386"></a>00386     <span class="keywordflow">switch</span>(t & (~CPL_TYPE_FLAG_ARRAY))
+<a name="l00387"></a>00387         {
+<a name="l00388"></a>00388         <span class="keywordflow">case</span> CPL_TYPE_CHAR:       <span class="keywordflow">return</span> <span class="stringliteral">"char"</span>;    <span class="keywordflow">break</span>;
+<a name="l00389"></a>00389         <span class="keywordflow">case</span> CPL_TYPE_UCHAR:      <span class="keywordflow">return</span> <span class="stringliteral">"uchar"</span>;   <span class="keywordflow">break</span>;
+<a name="l00390"></a>00390         <span class="keywordflow">case</span> CPL_TYPE_BOOL:       <span class="keywordflow">return</span> <span class="stringliteral">"boolean"</span>; <span class="keywordflow">break</span>;
+<a name="l00391"></a>00391         <span class="keywordflow">case</span> CPL_TYPE_INT:        <span class="keywordflow">return</span> <span class="stringliteral">"int"</span>;     <span class="keywordflow">break</span>;
+<a name="l00392"></a>00392         <span class="keywordflow">case</span> CPL_TYPE_UINT:       <span class="keywordflow">return</span> <span class="stringliteral">"uint"</span>;    <span class="keywordflow">break</span>;
+<a name="l00393"></a>00393         <span class="keywordflow">case</span> CPL_TYPE_LONG:       <span class="keywordflow">return</span> <span class="stringliteral">"long"</span>;    <span class="keywordflow">break</span>;
+<a name="l00394"></a>00394         <span class="keywordflow">case</span> CPL_TYPE_ULONG:      <span class="keywordflow">return</span> <span class="stringliteral">"ulong"</span>;   <span class="keywordflow">break</span>;
+<a name="l00395"></a>00395         <span class="keywordflow">case</span> CPL_TYPE_FLOAT:      <span class="keywordflow">return</span> <span class="stringliteral">"float"</span>;   <span class="keywordflow">break</span>;
+<a name="l00396"></a>00396         <span class="keywordflow">case</span> CPL_TYPE_DOUBLE:     <span class="keywordflow">return</span> <span class="stringliteral">"double"</span>;  <span class="keywordflow">break</span>;
+<a name="l00397"></a>00397         <span class="keywordflow">case</span> CPL_TYPE_POINTER:    <span class="keywordflow">return</span> <span class="stringliteral">"pointer"</span>; <span class="keywordflow">break</span>;
+<a name="l00398"></a>00398 <span class="comment">/* not in CPL3.0: case CPL_TYPE_COMPLEX:    return "complex"; break; */</span>
+<a name="l00399"></a>00399         <span class="keywordflow">case</span> CPL_TYPE_INVALID:    <span class="keywordflow">return</span> <span class="stringliteral">"invalid"</span>; <span class="keywordflow">break</span>;
+<a name="l00400"></a>00400         <span class="keywordflow">default</span>:
+<a name="l00401"></a>00401         <span class="keywordflow">return</span> <span class="stringliteral">"unrecognized type"</span>;
+<a name="l00402"></a>00402         }
+<a name="l00403"></a>00403     <span class="keywordflow">else</span>
+<a name="l00404"></a>00404     <span class="keywordflow">switch</span>(t & (~CPL_TYPE_FLAG_ARRAY))
+<a name="l00405"></a>00405         {
+<a name="l00406"></a>00406         <span class="keywordflow">case</span> CPL_TYPE_CHAR:       <span class="keywordflow">return</span> <span class="stringliteral">"string (char array)"</span>; <span class="keywordflow">break</span>;
+<a name="l00407"></a>00407         <span class="keywordflow">case</span> CPL_TYPE_UCHAR:      <span class="keywordflow">return</span> <span class="stringliteral">"uchar array"</span>;         <span class="keywordflow">break</span>;
+<a name="l00408"></a>00408         <span class="keywordflow">case</span> CPL_TYPE_BOOL:       <span class="keywordflow">return</span> <span class="stringliteral">"boolean array"</span>;       <span class="keywordflow">break</span>;
+<a name="l00409"></a>00409         <span class="keywordflow">case</span> CPL_TYPE_INT:        <span class="keywordflow">return</span> <span class="stringliteral">"int array"</span>;           <span class="keywordflow">break</span>;
+<a name="l00410"></a>00410         <span class="keywordflow">case</span> CPL_TYPE_UINT:       <span class="keywordflow">return</span> <span class="stringliteral">"uint array"</span>;          <span class="keywordflow">break</span>;
+<a name="l00411"></a>00411         <span class="keywordflow">case</span> CPL_TYPE_LONG:       <span class="keywordflow">return</span> <span class="stringliteral">"long array"</span>;          <span class="keywordflow">break</span>;
+<a name="l00412"></a>00412         <span class="keywordflow">case</span> CPL_TYPE_ULONG:      <span class="keywordflow">return</span> <span class="stringliteral">"ulong array"</span>;         <span class="keywordflow">break</span>;
+<a name="l00413"></a>00413         <span class="keywordflow">case</span> CPL_TYPE_FLOAT:      <span class="keywordflow">return</span> <span class="stringliteral">"float array"</span>;         <span class="keywordflow">break</span>;
+<a name="l00414"></a>00414         <span class="keywordflow">case</span> CPL_TYPE_DOUBLE:     <span class="keywordflow">return</span> <span class="stringliteral">"double array"</span>;        <span class="keywordflow">break</span>;
+<a name="l00415"></a>00415         <span class="keywordflow">case</span> CPL_TYPE_POINTER:    <span class="keywordflow">return</span> <span class="stringliteral">"pointer array"</span>;       <span class="keywordflow">break</span>;
+<a name="l00416"></a>00416 <span class="comment">/* not in CPL3.0: case CPL_TYPE_COMPLEX:    return "complex array"; break; */</span>
+<a name="l00417"></a>00417         <span class="keywordflow">case</span> CPL_TYPE_INVALID:    <span class="keywordflow">return</span> <span class="stringliteral">"invalid (array)"</span>;     <span class="keywordflow">break</span>;
+<a name="l00418"></a>00418         <span class="keywordflow">default</span>:
+<a name="l00419"></a>00419         <span class="keywordflow">return</span> <span class="stringliteral">"unrecognized type"</span>;
+<a name="l00420"></a>00420         }
+<a name="l00421"></a>00421 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__dump_8h_source.html b/html/sinfo__dump_8h_source.html
new file mode 100644
index 0000000..0f37309
--- /dev/null
+++ b/html/sinfo__dump_8h_source.html
@@ -0,0 +1,100 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_dump.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_dump.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*                                                                           *</span>
+<a name="l00002"></a>00002 <span class="comment"> *   This file is part of the ESO UVES  Pipeline                             *</span>
+<a name="l00003"></a>00003 <span class="comment"> *   Copyright (C) 2004,2005 European Southern Observatory                   *</span>
+<a name="l00004"></a>00004 <span class="comment"> *                                                                           *</span>
+<a name="l00005"></a>00005 <span class="comment"> *   This library is free software; you can redistribute it and/or modify    *</span>
+<a name="l00006"></a>00006 <span class="comment"> *   it under the terms of the GNU General Public License as published by    *</span>
+<a name="l00007"></a>00007 <span class="comment"> *   the Free Software Foundation; either version 2 of the License, or       *</span>
+<a name="l00008"></a>00008 <span class="comment"> *   (at your option) any later version.                                     *</span>
+<a name="l00009"></a>00009 <span class="comment"> *                                                                           *</span>
+<a name="l00010"></a>00010 <span class="comment"> *   This program is distributed in the hope that it will be useful,         *</span>
+<a name="l00011"></a>00011 <span class="comment"> *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *</span>
+<a name="l00012"></a>00012 <span class="comment"> *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *</span>
+<a name="l00013"></a>00013 <span class="comment"> *   GNU General Public License for more details.                            *</span>
+<a name="l00014"></a>00014 <span class="comment"> *                                                                           *</span>
+<a name="l00015"></a>00015 <span class="comment"> *   You should have received a copy of the GNU General Public License       *</span>
+<a name="l00016"></a>00016 <span class="comment"> *   along with this program; if not, write to the Free Software             *</span>
+<a name="l00017"></a>00017 <span class="comment"> *   Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA    *</span>
+<a name="l00018"></a>00018 <span class="comment"> *                                                                           */</span>
+<a name="l00019"></a>00019 
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2011/11/23 17:29:09 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.6 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Log: sinfo_dump.h,v $</span>
+<a name="l00026"></a>00026 <span class="comment"> * Revision 1.6  2011/11/23 17:29:09  amodigli</span>
+<a name="l00027"></a>00027 <span class="comment"> * fix warning with cpl6</span>
+<a name="l00028"></a>00028 <span class="comment"> *</span>
+<a name="l00029"></a>00029 <span class="comment"> * Revision 1.5  2006/10/25 06:46:09  amodigli</span>
+<a name="l00030"></a>00030 <span class="comment"> * fixed warnings from static checks</span>
+<a name="l00031"></a>00031 <span class="comment"> *</span>
+<a name="l00032"></a>00032 <span class="comment"> * Revision 1.4  2006/10/17 11:13:30  amodigli</span>
+<a name="l00033"></a>00033 <span class="comment"> * added config.h</span>
+<a name="l00034"></a>00034 <span class="comment"> *</span>
+<a name="l00035"></a>00035 <span class="comment"> * Revision 1.3  2006/10/16 07:26:23  amodigli</span>
+<a name="l00036"></a>00036 <span class="comment"> * shortened line length</span>
+<a name="l00037"></a>00037 <span class="comment"> *</span>
+<a name="l00038"></a>00038 <span class="comment"> * Revision 1.2  2006/10/04 06:17:45  amodigli</span>
+<a name="l00039"></a>00039 <span class="comment"> * added doxygen doc</span>
+<a name="l00040"></a>00040 <span class="comment"> *</span>
+<a name="l00041"></a>00041 <span class="comment"> * Revision 1.1  2006/08/09 12:20:11  amodigli</span>
+<a name="l00042"></a>00042 <span class="comment"> * added sinfo_dump.h sinfo_dump.c</span>
+<a name="l00043"></a>00043 <span class="comment"> *</span>
+<a name="l00044"></a>00044 <span class="comment"> * Revision 1.2  2005/12/19 16:17:56  jmlarsen</span>
+<a name="l00045"></a>00045 <span class="comment"> * Replaced bool -> int</span>
+<a name="l00046"></a>00046 <span class="comment"> *</span>
+<a name="l00047"></a>00047 <span class="comment"> */</span>
+<a name="l00048"></a>00048 <span class="preprocessor">#ifndef SINFO_DUMP_H</span>
+<a name="l00049"></a>00049 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_DUMP_H</span>
+<a name="l00050"></a>00050 <span class="preprocessor"></span>
+<a name="l00051"></a>00051 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00052"></a>00052 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00053"></a>00053 <span class="preprocessor">#endif</span>
+<a name="l00054"></a>00054 <span class="preprocessor"></span>
+<a name="l00055"></a>00055 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00056"></a>00056 <span class="preprocessor">#include <sinfo_cpl_size.h></span>
+<a name="l00057"></a>00057 
+<a name="l00058"></a>00058 cpl_error_code 
+<a name="l00059"></a>00059 sinfo_print_cpl_propertylist(<span class="keyword">const</span> cpl_propertylist *pl, 
+<a name="l00060"></a>00060                              <span class="keywordtype">long</span> low, 
+<a name="l00061"></a>00061                              <span class="keywordtype">long</span> high);
+<a name="l00062"></a>00062 
+<a name="l00063"></a>00063 cpl_error_code 
+<a name="l00064"></a>00064 sinfo_print_cpl_property(<span class="keyword">const</span> cpl_property *);
+<a name="l00065"></a>00065 
+<a name="l00066"></a>00066 cpl_error_code 
+<a name="l00067"></a>00067 sinfo_print_cpl_frameset(<span class="keyword">const</span> cpl_frameset *);
+<a name="l00068"></a>00068 
+<a name="l00069"></a>00069 cpl_error_code 
+<a name="l00070"></a>00070 sinfo_print_cpl_frame(<span class="keyword">const</span> cpl_frame *);
+<a name="l00071"></a>00071 
+<a name="l00072"></a>00072 <span class="keyword">const</span> <span class="keywordtype">char</span> *
+<a name="l00073"></a>00073 sinfo_tostring_cpl_type(cpl_type t);
+<a name="l00074"></a>00074 
+<a name="l00075"></a>00075 <span class="keyword">const</span> <span class="keywordtype">char</span> *
+<a name="l00076"></a>00076 sinfo_tostring_cpl_frame_type(cpl_frame_type);
+<a name="l00077"></a>00077 
+<a name="l00078"></a>00078 <span class="keyword">const</span> <span class="keywordtype">char</span> *
+<a name="l00079"></a>00079 sinfo_tostring_cpl_frame_group(cpl_frame_group);
+<a name="l00080"></a>00080 
+<a name="l00081"></a>00081 <span class="keyword">const</span> <span class="keywordtype">char</span> *
+<a name="l00082"></a>00082 sinfo_tostring_cpl_frame_level(cpl_frame_level);
+<a name="l00083"></a>00083 
+<a name="l00084"></a>00084 <span class="preprocessor">#endif </span><span class="comment">/* SINFO_DUMP_H */</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__error_8h_source.html b/html/sinfo__error_8h_source.html
new file mode 100644
index 0000000..70fec27
--- /dev/null
+++ b/html/sinfo__error_8h_source.html
@@ -0,0 +1,139 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_error.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_error.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2007/10/26 09:42:36 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.13 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Log: sinfo_error.h,v $</span>
+<a name="l00026"></a>00026 <span class="comment"> * Revision 1.13  2007/10/26 09:42:36  amodigli</span>
+<a name="l00027"></a>00027 <span class="comment"> * removed check on CPL_VERSION_CODE (now works only for CPL4)</span>
+<a name="l00028"></a>00028 <span class="comment"> *</span>
+<a name="l00029"></a>00029 <span class="comment"> * Revision 1.12  2007/08/14 10:01:41  amodigli</span>
+<a name="l00030"></a>00030 <span class="comment"> * added sinfo_stop_if_error</span>
+<a name="l00031"></a>00031 <span class="comment"> *</span>
+<a name="l00032"></a>00032 <span class="comment"> * Revision 1.11  2007/08/11 10:46:18  amodigli</span>
+<a name="l00033"></a>00033 <span class="comment"> * clean</span>
+<a name="l00034"></a>00034 <span class="comment"> *</span>
+<a name="l00035"></a>00035 <span class="comment"> * Revision 1.9  2007/08/08 11:17:26  amodigli</span>
+<a name="l00036"></a>00036 <span class="comment"> * change to support CPL31 & CPL40</span>
+<a name="l00037"></a>00037 <span class="comment"> *</span>
+<a name="l00038"></a>00038 <span class="comment"> * Revision 1.8  2007/06/06 07:10:45  amodigli</span>
+<a name="l00039"></a>00039 <span class="comment"> * replaced tab with 4 spaces</span>
+<a name="l00040"></a>00040 <span class="comment"> *</span>
+<a name="l00041"></a>00041 <span class="comment"> * Revision 1.7  2006/11/21 11:56:10  amodigli</span>
+<a name="l00042"></a>00042 <span class="comment"> * replaced __func__ by cpl_func</span>
+<a name="l00043"></a>00043 <span class="comment"> *</span>
+<a name="l00044"></a>00044 <span class="comment"> * Revision 1.6  2006/10/16 07:26:23  amodigli</span>
+<a name="l00045"></a>00045 <span class="comment"> * shortened line length</span>
+<a name="l00046"></a>00046 <span class="comment"> *</span>
+<a name="l00047"></a>00047 <span class="comment"> * Revision 1.5  2006/10/13 08:09:42  amodigli</span>
+<a name="l00048"></a>00048 <span class="comment"> * shorten line length</span>
+<a name="l00049"></a>00049 <span class="comment"> *</span>
+<a name="l00050"></a>00050 <span class="comment"> * Revision 1.4  2006/10/13 06:34:40  amodigli</span>
+<a name="l00051"></a>00051 <span class="comment"> * shorten line length</span>
+<a name="l00052"></a>00052 <span class="comment"> *</span>
+<a name="l00053"></a>00053 <span class="comment"> * Revision 1.3  2006/10/04 06:17:45  amodigli</span>
+<a name="l00054"></a>00054 <span class="comment"> * added doxygen doc</span>
+<a name="l00055"></a>00055 <span class="comment"> *</span>
+<a name="l00056"></a>00056 <span class="comment"> * Revision 1.2  2006/07/31 06:33:34  amodigli</span>
+<a name="l00057"></a>00057 <span class="comment"> * fixed  bug in ck0 macro</span>
+<a name="l00058"></a>00058 <span class="comment"> *</span>
+<a name="l00059"></a>00059 <span class="comment"> * Revision 1.1  2006/05/30 09:09:37  amodigli</span>
+<a name="l00060"></a>00060 <span class="comment"> * added to repository</span>
+<a name="l00061"></a>00061 <span class="comment"> *</span>
+<a name="l00062"></a>00062 <span class="comment"> *</span>
+<a name="l00063"></a>00063 <span class="comment"> */</span>
+<a name="l00064"></a>00064 
+<a name="l00065"></a>00065 <span class="preprocessor">#ifndef SINFO_ERROR_H</span>
+<a name="l00066"></a>00066 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_ERROR_H</span>
+<a name="l00067"></a>00067 <span class="preprocessor"></span>
+<a name="l00072"></a>00072 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00073"></a>00073 <span class="comment">                    Includes</span>
+<a name="l00074"></a>00074 <span class="comment">-----------------------------------------------------------------------------*/</span>
+<a name="l00075"></a>00075 <span class="preprocessor">#include <cpl_error.h></span>
+<a name="l00076"></a>00076 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00077"></a>00077 
+<a name="l00078"></a>00078 <span class="preprocessor">#include <irplib_utils.h></span>
+<a name="l00079"></a>00079 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00080"></a>00080 <span class="comment">                             Defines</span>
+<a name="l00081"></a>00081 <span class="comment">-----------------------------------------------------------------------------*/</span>
+<a name="l00082"></a>00082 <span class="comment">/* To save some key-strokes, use the irplib error handling macros</span>
+<a name="l00083"></a>00083 <span class="comment">   under different (shorter) names.</span>
+<a name="l00084"></a>00084 <span class="comment">   Additionally, irplib macros require the VA_ARGS to be enclosed in (),</span>
+<a name="l00085"></a>00085 <span class="comment">*/</span>
+<a name="l00086"></a>00086 
+<a name="l00087"></a>00087 <span class="preprocessor">#define assure(BOOL, CODE, ...) \</span>
+<a name="l00088"></a>00088 <span class="preprocessor">  cpl_error_ensure(BOOL, CODE, goto cleanup,__VA_ARGS__)</span>
+<a name="l00089"></a>00089 <span class="preprocessor"></span>
+<a name="l00090"></a>00090 <span class="preprocessor">#define assure_nomsg(BOOL, CODE, ...)               \</span>
+<a name="l00091"></a>00091 <span class="preprocessor">  cpl_error_ensure(BOOL, CODE, goto cleanup,__VA_ARGS__)</span>
+<a name="l00092"></a>00092 <span class="preprocessor"></span>
+<a name="l00093"></a>00093 <span class="preprocessor">#define sinfo_stop_if_error() \</span>
+<a name="l00094"></a>00094 <span class="preprocessor">     do if(cpl_error_get_code()) { \</span>
+<a name="l00095"></a>00095 <span class="preprocessor">     cpl_msg_error(__func__,"Traced error"); \</span>
+<a name="l00096"></a>00096 <span class="preprocessor">     irplib_trace(); \</span>
+<a name="l00097"></a>00097 <span class="preprocessor">     goto cleanup; \</span>
+<a name="l00098"></a>00098 <span class="preprocessor">     } while (0) </span>
+<a name="l00099"></a>00099 <span class="preprocessor"></span>
+<a name="l00100"></a>00100 <span class="preprocessor">#define ck0(IEXP, ...) \</span>
+<a name="l00101"></a>00101 <span class="preprocessor">  cpl_error_ensure(IEXP == 0, CPL_ERROR_UNSPECIFIED, \</span>
+<a name="l00102"></a>00102 <span class="preprocessor">   goto cleanup,__VA_ARGS__)</span>
+<a name="l00103"></a>00103 <span class="preprocessor"></span>
+<a name="l00104"></a>00104 <span class="preprocessor">#define ck0_nomsg(IEXP) ck0(IEXP," ")</span>
+<a name="l00105"></a>00105 <span class="preprocessor"></span>
+<a name="l00106"></a>00106 <span class="preprocessor">#define cknull(NULLEXP, ...) \</span>
+<a name="l00107"></a>00107 <span class="preprocessor">  cpl_error_ensure((NULLEXP) != NULL, \</span>
+<a name="l00108"></a>00108 <span class="preprocessor">  CPL_ERROR_UNSPECIFIED, goto cleanup,__VA_ARGS__)</span>
+<a name="l00109"></a>00109 <span class="preprocessor"></span>
+<a name="l00110"></a>00110 <span class="preprocessor">#define cknull_nomsg(NULLEXP) cknull(NULLEXP," ")</span>
+<a name="l00111"></a>00111 <span class="preprocessor"></span>
+<a name="l00112"></a>00112 <span class="preprocessor">#define  check(CMD, ...)                                                 \</span>
+<a name="l00113"></a>00113 <span class="preprocessor">  cpl_error_ensure((sinfo_msg_softer(), (CMD), sinfo_msg_louder(),      \</span>
+<a name="l00114"></a>00114 <span class="preprocessor">              cpl_error_get_code() == CPL_ERROR_NONE),       \</span>
+<a name="l00115"></a>00115 <span class="preprocessor">                       cpl_error_get_code(), goto cleanup,__VA_ARGS__)</span>
+<a name="l00116"></a>00116 <span class="preprocessor"></span>
+<a name="l00117"></a>00117 <span class="preprocessor">#define  check_nomsg(CMD) check(CMD, " ")</span>
+<a name="l00118"></a>00118 <span class="preprocessor"></span>
+<a name="l00119"></a>00119 <span class="preprocessor">#define passure(BOOL, ...)                                               \</span>
+<a name="l00120"></a>00120 <span class="preprocessor">  cpl_error_ensure(BOOL, CPL_ERROR_UNSPECIFIED, goto cleanup,\</span>
+<a name="l00121"></a>00121 <span class="preprocessor">                      ("Internal error. Please report to "                \</span>
+<a name="l00122"></a>00122 <span class="preprocessor">                      PACKAGE_BUGREPORT " " __VA_ARGS__))</span>
+<a name="l00123"></a>00123 <span class="preprocessor"></span>                       <span class="comment">//  Assumes that PACKAGE_BUGREPORT</span>
+<a name="l00124"></a>00124                <span class="comment">//contains no formatting special characters  </span>
+<a name="l00125"></a>00125    
+<a name="l00126"></a>00126 
+<a name="l00410"></a>00410 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__fft__base_8c_source.html b/html/sinfo__fft__base_8c_source.html
new file mode 100644
index 0000000..64789f4
--- /dev/null
+++ b/html/sinfo__fft__base_8c_source.html
@@ -0,0 +1,191 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_fft_base.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_fft_base.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name     :    sinfo_fft_base.c</span>
+<a name="l00022"></a>00022 <span class="comment">   Author         :    N. Devillard</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on    :    October 1999</span>
+<a name="l00024"></a>00024 <span class="comment">   Description    :    base FFT routines</span>
+<a name="l00025"></a>00025 <span class="comment"></span>
+<a name="l00026"></a>00026 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00027"></a>00027 <span class="comment">/*</span>
+<a name="l00028"></a>00028 <span class="comment">    $Id: sinfo_fft_base.c,v 1.7 2012/03/02 08:42:20 amodigli Exp $</span>
+<a name="l00029"></a>00029 <span class="comment">    $Author: amodigli $</span>
+<a name="l00030"></a>00030 <span class="comment">    $Date: 2012/03/02 08:42:20 $</span>
+<a name="l00031"></a>00031 <span class="comment">    $Revision: 1.7 $</span>
+<a name="l00032"></a>00032 <span class="comment">*/</span>
+<a name="l00033"></a>00033 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00034"></a>00034 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00035"></a>00035 <span class="preprocessor">#endif</span>
+<a name="l00036"></a>00036 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00037"></a>00037 <span class="comment">                                   Includes</span>
+<a name="l00038"></a>00038 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00039"></a>00039 <span class="preprocessor">#include "sinfo_fft_base.h"</span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include "sinfo_globals.h"</span>
+<a name="l00047"></a>00047 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00048"></a>00048 <span class="comment">                              Function codes</span>
+<a name="l00049"></a>00049 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00093"></a>00093 <span class="keywordtype">void</span>
+<a name="l00094"></a>00094 sinfo_fftn(
+<a name="l00095"></a>00095     dcomplex data[],
+<a name="l00096"></a>00096     <span class="keywordtype">unsigned</span> nn[],
+<a name="l00097"></a>00097     <span class="keywordtype">int</span> ndim, 
+<a name="l00098"></a>00098     <span class="keywordtype">int</span> isign)
+<a name="l00099"></a>00099 {
+<a name="l00100"></a>00100   <span class="keywordtype">int</span>        idim=0;
+<a name="l00101"></a>00101   <span class="keywordtype">unsigned</span>   i1=0;
+<a name="l00102"></a>00102   <span class="keywordtype">unsigned</span>   i2rev=0;
+<a name="l00103"></a>00103   <span class="keywordtype">unsigned</span>   i3rev=0;
+<a name="l00104"></a>00104   <span class="keywordtype">unsigned</span>   ibit=0;
+<a name="l00105"></a>00105   <span class="keywordtype">unsigned</span>   ip2=0;
+<a name="l00106"></a>00106   <span class="keywordtype">unsigned</span>   ifp1=0;
+<a name="l00107"></a>00107   <span class="keywordtype">unsigned</span>   ifp2=0;
+<a name="l00108"></a>00108   <span class="keywordtype">unsigned</span>   k2=0;
+<a name="l00109"></a>00109   <span class="keywordtype">unsigned</span>   n=0;
+<a name="l00110"></a>00110   <span class="keywordtype">unsigned</span>   nprev = 1;
+<a name="l00111"></a>00111   <span class="keywordtype">unsigned</span>   ntot = 1;
+<a name="l00112"></a>00112   <span class="keyword">register</span>   <span class="keywordtype">unsigned</span> i2=0;
+<a name="l00113"></a>00113   <span class="keyword">register</span>   <span class="keywordtype">unsigned</span> i3=0;
+<a name="l00114"></a>00114   <span class="keywordtype">double</span>        theta=0;
+<a name="l00115"></a>00115   dcomplex   w, wp;
+<a name="l00116"></a>00116   <span class="keywordtype">double</span>        wtemp=0;
+<a name="l00117"></a>00117   dcomplex   temp, wt;
+<a name="l00118"></a>00118   <span class="keywordtype">double</span>       t1=0;
+<a name="l00119"></a>00119   <span class="keywordtype">double</span>     t2=0;
+<a name="l00120"></a>00120 
+<a name="l00121"></a>00121   <span class="comment">/*      Compute total number of complex values  */</span>
+<a name="l00122"></a>00122   <span class="keywordflow">for</span> (idim = 0; idim < ndim; ++idim) {
+<a name="l00123"></a>00123     ntot *= nn[idim];
+<a name="l00124"></a>00124   }
+<a name="l00125"></a>00125 
+<a name="l00126"></a>00126   <span class="keywordflow">for</span> (idim = ndim - 1; idim >= 0; --idim) {
+<a name="l00127"></a>00127     n = nn[idim];
+<a name="l00128"></a>00128 
+<a name="l00129"></a>00129     ip2 = nprev * n;        <span class="comment">/*  Unit step for next dimension */</span>
+<a name="l00130"></a>00130     i2rev = 0;              <span class="comment">/*  Bit reversed i2 */</span>
+<a name="l00131"></a>00131 
+<a name="l00132"></a>00132     <span class="comment">/*      This is the bit reversal section of the routine */</span>
+<a name="l00133"></a>00133     <span class="comment">/*      Loop over current dimension     */</span>
+<a name="l00134"></a>00134     <span class="keywordflow">for</span> (i2 = 0; i2 < ip2; i2 += nprev) {
+<a name="l00135"></a>00135       <span class="keywordflow">if</span> (i2 < i2rev) {
+<a name="l00136"></a>00136     <span class="comment">/*      Loop over lower dimensions      */</span>
+<a name="l00137"></a>00137     <span class="keywordflow">for</span> (i1 = i2; i1 < i2 + nprev; ++i1) {
+<a name="l00138"></a>00138       <span class="comment">/*      Loop over higher dimensions  */</span>
+<a name="l00139"></a>00139       <span class="keywordflow">for</span> (i3 = i1; i3 < ntot; i3 += ip2) {
+<a name="l00140"></a>00140         i3rev = i3 + i2rev - i2;
+<a name="l00141"></a>00141         temp = data[i3];
+<a name="l00142"></a>00142         data[i3] = data[i3rev];
+<a name="l00143"></a>00143         data[i3rev] = temp;
+<a name="l00144"></a>00144       }
+<a name="l00145"></a>00145     }
+<a name="l00146"></a>00146       }
+<a name="l00147"></a>00147       ibit = ip2;
+<a name="l00148"></a>00148       <span class="comment">/*      Increment from high end of i2rev to low */</span>
+<a name="l00149"></a>00149       <span class="keywordflow">do</span> {
+<a name="l00150"></a>00150     ibit >>= 1;
+<a name="l00151"></a>00151     i2rev ^= ibit;
+<a name="l00152"></a>00152       } <span class="keywordflow">while</span> (ibit >= nprev && !(ibit & i2rev));
+<a name="l00153"></a>00153     }
+<a name="l00154"></a>00154 
+<a name="l00155"></a>00155     <span class="comment">/*      Here begins the Danielson-Lanczos section of the routine */</span>
+<a name="l00156"></a>00156     <span class="comment">/*      Loop over step sizes    */</span>
+<a name="l00157"></a>00157     <span class="keywordflow">for</span> (ifp1 = nprev; ifp1 < ip2; ifp1 <<= 1) {
+<a name="l00158"></a>00158       ifp2 = ifp1 << 1;
+<a name="l00159"></a>00159       <span class="comment">/*  Initialize for the trig. recurrence */</span>
+<a name="l00160"></a>00160       theta = isign * 2.0 * PI_NUMB / (ifp2 / nprev);
+<a name="l00161"></a>00161       wp.x = sin(0.5 * theta);
+<a name="l00162"></a>00162       wp.x *= -2.0 * wp.x;
+<a name="l00163"></a>00163       wp.y = sin(theta);
+<a name="l00164"></a>00164       w.x = 1.0;
+<a name="l00165"></a>00165       w.y = 0.0;
+<a name="l00166"></a>00166 
+<a name="l00167"></a>00167       <span class="comment">/*  Loop by unit step in current dimension  */</span>
+<a name="l00168"></a>00168       <span class="keywordflow">for</span> (i3 = 0; i3 < ifp1; i3 += nprev) {
+<a name="l00169"></a>00169     <span class="comment">/*      Loop over lower dimensions      */</span>
+<a name="l00170"></a>00170     <span class="keywordflow">for</span> (i1 = i3; i1 < i3 + nprev; ++i1) {
+<a name="l00171"></a>00171       <span class="comment">/*  Loop over higher dimensions */</span>
+<a name="l00172"></a>00172       <span class="keywordflow">for</span> (i2 = i1; i2 < ntot; i2 += ifp2) {
+<a name="l00173"></a>00173         <span class="comment">/*      Danielson-Lanczos formula */</span>
+<a name="l00174"></a>00174         k2 = i2 + ifp1;
+<a name="l00175"></a>00175         wt = data[k2];
+<a name="l00176"></a>00176 
+<a name="l00177"></a>00177             <span class="comment">/* Complex multiply using 3 real multiplies.  </span>
+<a name="l00178"></a>00178 <span class="comment">               Should usually be faster.    */</span>
+<a name="l00179"></a>00179         data[k2].x = data[i2].x - (temp.x =
+<a name="l00180"></a>00180                        (t1 = w.x * wt.x) - (t2 = w.y * wt.y));
+<a name="l00181"></a>00181         data[k2].y = data[i2].y - (temp.y =
+<a name="l00182"></a>00182                        (w.x + w.y) * (wt.x + wt.y) - t1 - t2);
+<a name="l00183"></a>00183         data[i2].x += temp.x;
+<a name="l00184"></a>00184         data[i2].y += temp.y;
+<a name="l00185"></a>00185       }
+<a name="l00186"></a>00186     }
+<a name="l00187"></a>00187     <span class="comment">/*      Trigonometric recurrence        */</span>
+<a name="l00188"></a>00188     wtemp = w.x;
+<a name="l00189"></a>00189         <span class="comment">/*    Complex multiply using 3 real multiplies.    */</span>
+<a name="l00190"></a>00190     w.x += (t1 = w.x * wp.x) - (t2 = w.y * wp.y);
+<a name="l00191"></a>00191     w.y += (wtemp + w.y) * (wp.x + wp.y) - t1 - t2;
+<a name="l00192"></a>00192       }
+<a name="l00193"></a>00193     }
+<a name="l00194"></a>00194     nprev *= n;
+<a name="l00195"></a>00195   }
+<a name="l00196"></a>00196     
+<a name="l00197"></a>00197   return ;
+<a name="l00198"></a>00198 }
+<a name="l00199"></a>00199 
+<a name="l00200"></a>00200 
+<a name="l00201"></a>00201 
+<a name="l00202"></a>00202 
+<a name="l00220"></a>00220 <span class="keywordtype">int</span>
+<a name="l00221"></a>00221 sinfo_is_power_of_2(<span class="keywordtype">int</span> p)
+<a name="l00222"></a>00222 {
+<a name="l00223"></a>00223     <span class="keywordtype">float</span>    c ;
+<a name="l00224"></a>00224     <span class="keywordtype">int</span>        power2 ;
+<a name="l00225"></a>00225 
+<a name="l00226"></a>00226     <span class="keywordflow">if</span> (p == 0) { <span class="comment">/* Yes, 0 is a power of 2    */</span>
+<a name="l00227"></a>00227         power2 =  1 ;
+<a name="l00228"></a>00228     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (p<0) { <span class="comment">/* No, negatives are no power of 2 (in R at least) */</span>
+<a name="l00229"></a>00229         power2 = -1 ;
+<a name="l00230"></a>00230     } <span class="keywordflow">else</span> { <span class="comment">/* Compute log in base 2    */</span>
+<a name="l00231"></a>00231         c = (float)(log((<span class="keywordtype">double</span>)p) / log(2.0)) ;
+<a name="l00232"></a>00232         <span class="keywordflow">if</span> (c == (<span class="keywordtype">float</span>)((int)c)) {
+<a name="l00233"></a>00233             power2 = (int)c ;
+<a name="l00234"></a>00234         } <span class="keywordflow">else</span> {
+<a name="l00235"></a>00235             power2 = -1 ;
+<a name="l00236"></a>00236         }
+<a name="l00237"></a>00237     }
+<a name="l00238"></a>00238     
+<a name="l00239"></a>00239     <span class="keywordflow">return</span> power2 ;
+<a name="l00240"></a>00240 }
+<a name="l00241"></a>00241 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__fft__base_8h_source.html b/html/sinfo__fft__base_8h_source.html
new file mode 100644
index 0000000..24c50e3
--- /dev/null
+++ b/html/sinfo__fft__base_8h_source.html
@@ -0,0 +1,78 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_fft_base.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_fft_base.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   File name     :    sinfo_sinfo_fft_base.h</span>
+<a name="l00021"></a>00021 <span class="comment">   Author         :    N. Devillard</span>
+<a name="l00022"></a>00022 <span class="comment">   Created on    :    October 1999</span>
+<a name="l00023"></a>00023 <span class="comment">   Description    :    base FFT routines</span>
+<a name="l00024"></a>00024 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00025"></a>00025 <span class="comment">/*</span>
+<a name="l00026"></a>00026 <span class="comment">    $Id: sinfo_fft_base.h,v 1.6 2007/06/06 07:10:45 amodigli Exp $</span>
+<a name="l00027"></a>00027 <span class="comment">    $Author: amodigli $</span>
+<a name="l00028"></a>00028 <span class="comment">    $Date: 2007/06/06 07:10:45 $</span>
+<a name="l00029"></a>00029 <span class="comment">    $Revision: 1.6 $</span>
+<a name="l00030"></a>00030 <span class="comment">*/</span>
+<a name="l00031"></a>00031 <span class="preprocessor">#ifndef SINFO_FFT_BASE_H</span>
+<a name="l00032"></a>00032 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_FFT_BASE_H</span>
+<a name="l00033"></a>00033 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00034"></a>00034 <span class="comment">                                   Includes</span>
+<a name="l00035"></a>00035 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00036"></a>00036 <span class="preprocessor">#include <math.h></span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include "cpl.h"</span>
+<a name="l00038"></a>00038 <span class="preprocessor">#include "sinfo_local_types.h"</span>
+<a name="l00039"></a>00039 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00040"></a>00040 <span class="comment">                                   New types</span>
+<a name="l00041"></a>00041 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00042"></a>00042 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00043"></a>00043 <span class="comment">                                   Defines</span>
+<a name="l00044"></a>00044 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00045"></a>00045 <span class="preprocessor">#define FFT_FORWARD         1</span>
+<a name="l00046"></a>00046 <span class="preprocessor"></span><span class="preprocessor">#define FFT_INVERSE        -1</span>
+<a name="l00047"></a>00047 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00048"></a>00048 <span class="comment">                              Function codes</span>
+<a name="l00049"></a>00049 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00091"></a>00091 <span class="keywordtype">void</span>
+<a name="l00092"></a>00092 sinfo_fftn(
+<a name="l00093"></a>00093     dcomplex data[],
+<a name="l00094"></a>00094     <span class="keywordtype">unsigned</span> nn[],
+<a name="l00095"></a>00095     <span class="keywordtype">int</span> ndim, 
+<a name="l00096"></a>00096     <span class="keywordtype">int</span> isign);
+<a name="l00097"></a>00097 
+<a name="l00113"></a>00113 <span class="keywordtype">int</span> sinfo_is_power_of_2(<span class="keywordtype">int</span> p);
+<a name="l00114"></a>00114 
+<a name="l00115"></a>00115 
+<a name="l00116"></a>00116 <span class="preprocessor">#endif</span>
+<a name="l00117"></a>00117 <span class="preprocessor"></span><span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00118"></a>00118 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__file__handling_8c_source.html b/html/sinfo__file__handling_8c_source.html
new file mode 100644
index 0000000..a6c0720
--- /dev/null
+++ b/html/sinfo__file__handling_8c_source.html
@@ -0,0 +1,66 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_file_handling.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_file_handling.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00020"></a>00020 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00021"></a>00021 <span class="preprocessor">#endif</span>
+<a name="l00022"></a>00022 <span class="preprocessor"></span><span class="preprocessor">#include <stdio.h></span>
+<a name="l00023"></a>00023 <span class="preprocessor">#include <string.h></span>
+<a name="l00024"></a>00024 <span class="preprocessor">#include "sinfo_file_handling.h"</span>
+<a name="l00025"></a>00025 
+<a name="l00033"></a>00033 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00034"></a>00034 <span class="comment">                                                        Function codes</span>
+<a name="l00035"></a>00035 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 
+<a name="l00038"></a>00038 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l00049"></a>00049 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00050"></a>00050 
+<a name="l00051"></a>00051 
+<a name="l00052"></a>00052 <span class="keywordtype">int</span> sinfo_file_exists(<span class="keyword">const</span> <span class="keywordtype">char</span> * filename)
+<a name="l00053"></a>00053 {
+<a name="l00054"></a>00054   <span class="keywordtype">int</span> exists=0;
+<a name="l00055"></a>00055   FILE* fo=NULL;
+<a name="l00056"></a>00056   <span class="keywordflow">if</span> ((fo=fopen(filename,<span class="stringliteral">"r"</span>))==NULL) {
+<a name="l00057"></a>00057      exists=0;
+<a name="l00058"></a>00058    } <span class="keywordflow">else</span> {
+<a name="l00059"></a>00059      exists=1;
+<a name="l00060"></a>00060    }
+<a name="l00061"></a>00061 
+<a name="l00062"></a>00062   <span class="keywordflow">if</span>(fo!=NULL) {
+<a name="l00063"></a>00063      fclose(fo);
+<a name="l00064"></a>00064   }
+<a name="l00065"></a>00065 
+<a name="l00066"></a>00066    <span class="keywordflow">return</span> exists;
+<a name="l00067"></a>00067 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__file__handling_8h_source.html b/html/sinfo__file__handling_8h_source.html
new file mode 100644
index 0000000..faa78f8
--- /dev/null
+++ b/html/sinfo__file__handling_8h_source.html
@@ -0,0 +1,44 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_file_handling.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_file_handling.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#ifndef SINFO_FILE_HANDLING_H</span>
+<a name="l00002"></a>00002 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_FILE_HANDLING_H</span>
+<a name="l00003"></a>00003 <span class="preprocessor"></span><span class="comment">/*</span>
+<a name="l00004"></a>00004 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00005"></a>00005 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00006"></a>00006 <span class="comment"> *</span>
+<a name="l00007"></a>00007 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00008"></a>00008 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00009"></a>00009 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00010"></a>00010 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00011"></a>00011 <span class="comment"> *</span>
+<a name="l00012"></a>00012 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00013"></a>00013 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00014"></a>00014 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00015"></a>00015 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00016"></a>00016 <span class="comment"> *</span>
+<a name="l00017"></a>00017 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00018"></a>00018 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00019"></a>00019 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00020"></a>00020 <span class="comment"> */</span>
+<a name="l00021"></a>00021 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00022"></a>00022 <span class="comment">                                                Function ANSI C prototypes</span>
+<a name="l00023"></a>00023 <span class="comment"> --------------------------------------------------------------------------*/</span>
+<a name="l00024"></a>00024 
+<a name="l00035"></a>00035 <span class="keywordtype">int</span> 
+<a name="l00036"></a>00036 sinfo_file_exists(<span class="keyword">const</span> <span class="keywordtype">char</span> * filename);
+<a name="l00037"></a>00037 
+<a name="l00038"></a>00038 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__finddist__cfg_8c_source.html b/html/sinfo__finddist__cfg_8c_source.html
new file mode 100644
index 0000000..729d79b
--- /dev/null
+++ b/html/sinfo__finddist__cfg_8c_source.html
@@ -0,0 +1,68 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_finddist_cfg.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_finddist_cfg.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name     :    sinfo_wavecal_cfg.c</span>
+<a name="l00022"></a>00022 <span class="comment">   Author         : Juergen Schreiber</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on    :    September 2001</span>
+<a name="l00024"></a>00024 <span class="comment">   Description    :    wavelength calibration configuration handling tools</span>
+<a name="l00025"></a>00025 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00026"></a>00026 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00027"></a>00027 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00028"></a>00028 <span class="preprocessor">#endif</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span>
+<a name="l00030"></a>00030 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00031"></a>00031 <span class="comment">                                   Includes</span>
+<a name="l00032"></a>00032 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include "sinfo_finddist_cfg.h"</span>
+<a name="l00041"></a>00041 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00042"></a>00042 <span class="comment">                              Function codes</span>
+<a name="l00043"></a>00043 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00050"></a>00050 finddist_config * 
+<a name="l00051"></a>00051 sinfo_finddist_cfg_create(<span class="keywordtype">void</span>)
+<a name="l00052"></a>00052 {
+<a name="l00053"></a>00053     <span class="keywordflow">return</span> cpl_calloc(1, <span class="keyword">sizeof</span>(finddist_config));
+<a name="l00054"></a>00054 }
+<a name="l00055"></a>00055 
+<a name="l00063"></a>00063 <span class="keywordtype">void</span> 
+<a name="l00064"></a>00064 sinfo_finddist_cfg_destroy(finddist_config * wc)
+<a name="l00065"></a>00065 {
+<a name="l00066"></a>00066     <span class="keywordflow">if</span> (wc==NULL) return ;
+<a name="l00067"></a>00067 
+<a name="l00068"></a>00068     <span class="comment">/* Free main struct */</span>
+<a name="l00069"></a>00069     cpl_free(wc);
+<a name="l00070"></a>00070 
+<a name="l00071"></a>00071     return ;
+<a name="l00072"></a>00072 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__finddist__cfg_8h_source.html b/html/sinfo__finddist__cfg_8h_source.html
new file mode 100644
index 0000000..9207e08
--- /dev/null
+++ b/html/sinfo__finddist__cfg_8h_source.html
@@ -0,0 +1,158 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_finddist_cfg.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_finddist_cfg.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name     :    sinfo_wavecal_cfg.h</span>
+<a name="l00022"></a>00022 <span class="comment">   Author         :    Juergen Schreiber</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on    :    September 2001</span>
+<a name="l00024"></a>00024 <span class="comment">   Description    :    wavecal_ini definitions + handling prototypes</span>
+<a name="l00025"></a>00025 <span class="comment"></span>
+<a name="l00026"></a>00026 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00027"></a>00027 <span class="preprocessor">#ifndef SINFO_FINDDIST_CFG_H</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_FINDDIST_CFG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00030"></a>00030 <span class="comment">                                   Includes</span>
+<a name="l00031"></a>00031 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00032"></a>00032 <span class="preprocessor">#include "sinfo_globals.h"</span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00034"></a>00034 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00035"></a>00035 <span class="comment">                                   Defines</span>
+<a name="l00036"></a>00036 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00037"></a>00037 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00038"></a>00038 <span class="comment">                                   New types</span>
+<a name="l00039"></a>00039 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00040"></a>00040 <span class="comment">/*</span>
+<a name="l00041"></a>00041 <span class="comment">  Wavelength calibration blackboard container</span>
+<a name="l00042"></a>00042 <span class="comment"></span>
+<a name="l00043"></a>00043 <span class="comment">  This structure holds all information related to the wavelength calibration</span>
+<a name="l00044"></a>00044 <span class="comment">  routine. It is used as a container for the flux of ancillary data,</span>
+<a name="l00045"></a>00045 <span class="comment">  computed values, and algorithm status. Pixel flux is separated from</span>
+<a name="l00046"></a>00046 <span class="comment">  the blackboard.</span>
+<a name="l00047"></a>00047 <span class="comment">  */</span>
+<a name="l00048"></a>00048 
+<a name="l00049"></a>00049 <span class="keyword">typedef</span> <span class="keyword">struct </span>finddist_config {
+<a name="l00050"></a>00050 <span class="comment">/*-------General---------*/</span>
+<a name="l00051"></a>00051         <span class="keywordtype">char</span> inFrame[FILE_NAME_SZ] ; <span class="comment">/* input emission line frame */</span>
+<a name="l00052"></a>00052         <span class="keywordtype">char</span> lineList[FILE_NAME_SZ] ; <span class="comment">/* input wavelength and intensity </span>
+<a name="l00053"></a>00053 <span class="comment">                                         line list */</span>
+<a name="l00054"></a>00054         <span class="keywordtype">char</span> outName[FILE_NAME_SZ] ; <span class="comment">/* output name of resulting fits </span>
+<a name="l00055"></a>00055 <span class="comment">                                        wavelength map */</span>
+<a name="l00056"></a>00056         <span class="keywordtype">char</span> nsFrame[FILE_NAME_SZ] ; <span class="comment">/* input north-south frame */</span>
+<a name="l00057"></a>00057         <span class="keywordtype">char</span> mask[FILE_NAME_SZ] ;    <span class="comment">/* input north-south frame */</span>
+<a name="l00058"></a>00058         <span class="keywordtype">char</span> fitsname[FILE_NAME_SZ] ;  
+<a name="l00059"></a>00059         <span class="keywordtype">char</span> drs_setup[FILE_NAME_SZ] ;  
+<a name="l00060"></a>00060 <span class="comment">/*------ FindLines ------*/</span>
+<a name="l00061"></a>00061         <span class="comment">/* estimated central wavelength of the image */</span>
+<a name="l00062"></a>00062         <span class="keywordtype">float</span> guessBeginWavelength ;
+<a name="l00063"></a>00063         <span class="comment">/* estimated linear dispersion of emission line frame */</span>
+<a name="l00064"></a>00064         <span class="keywordtype">float</span> guessDispersion1 ;
+<a name="l00065"></a>00065         <span class="comment">/* estimated square dispersion of emission line frame */</span>
+<a name="l00066"></a>00066         <span class="keywordtype">float</span> guessDispersion2 ;
+<a name="l00067"></a>00067         <span class="comment">/* minimal difference of mean and sinfo_median column intensity */</span>
+<a name="l00068"></a>00068         <span class="keywordtype">float</span> mindiff ;
+<a name="l00069"></a>00069         <span class="comment">/* half width of a box within which the line must sit */</span>
+<a name="l00070"></a>00070         <span class="keywordtype">int</span> halfWidth ;
+<a name="l00071"></a>00071         <span class="comment">/* sigma of Gaussian of artificial model spectra */</span>
+<a name="l00072"></a>00072         <span class="keywordtype">float</span> sigma ; 
+<a name="l00073"></a>00073 
+<a name="l00074"></a>00074 <span class="comment">/*------ WaveCalib ------*/</span>
+<a name="l00075"></a>00075         <span class="comment">/* guess value for fwhm of emission lines */</span> 
+<a name="l00076"></a>00076         <span class="keywordtype">float</span> fwhm ;
+<a name="l00077"></a>00077         <span class="comment">/* minimum amplitude of a line to be fitted */</span>
+<a name="l00078"></a>00078         <span class="keywordtype">float</span> minAmplitude ;
+<a name="l00079"></a>00079         <span class="comment">/* maximal residual value for a valid fit */</span>
+<a name="l00080"></a>00080         <span class="keywordtype">float</span> maxResidual ;
+<a name="l00081"></a>00081         <span class="comment">/* # of polynomial coefficients used for the dispersion relation */</span>
+<a name="l00082"></a>00082         <span class="keywordtype">int</span> nrDispCoefficients ;
+<a name="l00083"></a>00083         <span class="comment">/* # of polynomial coefficients used for the fit of the dispersion </span>
+<a name="l00084"></a>00084 <span class="comment">             coefficients */</span>
+<a name="l00085"></a>00085         <span class="keywordtype">int</span> nrCoefCoefficients ;
+<a name="l00086"></a>00086         <span class="comment">/* minimal factor of the standard deviation of the fit coefficients */</span>
+<a name="l00087"></a>00087         <span class="keywordtype">float</span> sigmaFactor ;
+<a name="l00088"></a>00088         <span class="comment">/* number of slitlets */</span>
+<a name="l00089"></a>00089         <span class="keywordtype">int</span>    nslitlets ;
+<a name="l00090"></a>00090         <span class="comment">/* minimal pixel distance of slitlets in spectral direction */</span>
+<a name="l00091"></a>00091         <span class="keywordtype">int</span>    pixeldist ;
+<a name="l00092"></a>00092         <span class="comment">/* allowed pixel position tolerance between estimated and </span>
+<a name="l00093"></a>00093 <span class="comment">           fitted line position */</span>
+<a name="l00094"></a>00094         <span class="keywordtype">float</span>  pixel_tolerance  ;
+<a name="l00095"></a>00095 
+<a name="l00096"></a>00096 <span class="comment">/*------ WaveMap ------*/</span>
+<a name="l00097"></a>00097     <span class="comment">/* magnifying factor for FFT */</span>
+<a name="l00098"></a>00098     <span class="keywordtype">int</span> magFactor ;
+<a name="l00099"></a>00099 
+<a name="l00100"></a>00100 <span class="comment">/*------ FitSlits ------*/</span>
+<a name="l00101"></a>00101     <span class="comment">/* pixel length of the row box within which the fit of the </span>
+<a name="l00102"></a>00102 <span class="comment">           slitlet positions is carried out*/</span>
+<a name="l00103"></a>00103     <span class="keywordtype">int</span> boxLength ;
+<a name="l00104"></a>00104         <span class="comment">/* lower row position for the estimate fit */</span>
+<a name="l00105"></a>00105     <span class="keywordtype">int</span> loPos ;
+<a name="l00106"></a>00106         <span class="comment">/* upper row position for the estimate fit */</span>
+<a name="l00107"></a>00107     <span class="keywordtype">int</span> hiPos ;
+<a name="l00108"></a>00108     <span class="comment">/* float box half width in spectral direction */</span>
+<a name="l00109"></a>00109         <span class="keywordtype">float</span> yBox ;
+<a name="l00110"></a>00110         <span class="comment">/* maximal tolerable difference to the expected slitlet positions */</span>
+<a name="l00111"></a>00111         <span class="keywordtype">float</span> diffTol ;
+<a name="l00112"></a>00112 <span class="comment">/*------ NorthSouthTest ------*/</span>
+<a name="l00113"></a>00113         <span class="comment">/* number of slitlets */</span>
+<a name="l00114"></a>00114         <span class="keywordtype">int</span> nslits ;      
+<a name="l00115"></a>00115         <span class="comment">/* pixel half width of a box within which the spatial </span>
+<a name="l00116"></a>00116 <span class="comment">           profile is fitted by a Gaussian */</span>
+<a name="l00117"></a>00117         <span class="keywordtype">int</span> nshalfWidth ;
+<a name="l00118"></a>00118         <span class="comment">/* first guess of the fwhm of the Gaussian fit function */</span>
+<a name="l00119"></a>00119         <span class="keywordtype">float</span> nsfwhm ;
+<a name="l00120"></a>00120         <span class="comment">/* minimum amplitude above which the fit is carried out */</span>
+<a name="l00121"></a>00121         <span class="keywordtype">float</span> minDiff ;
+<a name="l00122"></a>00122         <span class="comment">/* estimated average distance of spectra */</span>
+<a name="l00123"></a>00123         <span class="keywordtype">float</span> estimated_dist ;
+<a name="l00124"></a>00124         <span class="comment">/* maximal pixel tolerance of the slitlet distances */</span>
+<a name="l00125"></a>00125         <span class="keywordtype">float</span> devtol ;
+<a name="l00126"></a>00126 
+<a name="l00127"></a>00127   <span class="comment">/*----qg log --------*/</span>
+<a name="l00128"></a>00128   <span class="keywordtype">int</span> qc_thresh_min;
+<a name="l00129"></a>00129   <span class="keywordtype">int</span> qc_thresh_max;
+<a name="l00130"></a>00130 
+<a name="l00131"></a>00131 
+<a name="l00132"></a>00132 } finddist_config ;
+<a name="l00133"></a>00133 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00134"></a>00134 <span class="comment">                               Function prototypes</span>
+<a name="l00135"></a>00135 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00143"></a>00143 finddist_config * 
+<a name="l00144"></a>00144 sinfo_finddist_cfg_create(<span class="keywordtype">void</span>);
+<a name="l00145"></a>00145 
+<a name="l00152"></a>00152 <span class="keywordtype">void</span> 
+<a name="l00153"></a>00153 sinfo_finddist_cfg_destroy(finddist_config * jc);
+<a name="l00154"></a>00154 
+<a name="l00155"></a>00155 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__finddist__ini_8h_source.html b/html/sinfo__finddist__ini_8h_source.html
new file mode 100644
index 0000000..d6daeca
--- /dev/null
+++ b/html/sinfo__finddist__ini_8h_source.html
@@ -0,0 +1,63 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_finddist_ini.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_finddist_ini.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name    :   sinfo_wavecal_ini.h</span>
+<a name="l00022"></a>00022 <span class="comment">   Author       :    Juergen Schreiber</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on   :    Sept 14, 2001</span>
+<a name="l00024"></a>00024 <span class="comment">   Description  :    wavelength calibration ini file handling for SPIFFI</span>
+<a name="l00025"></a>00025 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00026"></a>00026 <span class="preprocessor">#ifndef SINFO_FINDDIST_INI_H</span>
+<a name="l00027"></a>00027 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_FINDDIST_INI_H</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00029"></a>00029 <span class="comment">                                Includes</span>
+<a name="l00030"></a>00030 <span class="comment">---------------------------------------------------------------------------*/</span>
+<a name="l00031"></a>00031 <span class="preprocessor">#include "sinfo_finddist_cfg.h"</span>
+<a name="l00032"></a>00032 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                             Function prototypes </span>
+<a name="l00034"></a>00034 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00050"></a>00050 <span class="keywordtype">int</span> 
+<a name="l00051"></a>00051 generatefinddist_ini_file(
+<a name="l00052"></a>00052         <span class="keywordtype">char</span> * ini_name,
+<a name="l00053"></a>00053         <span class="keywordtype">char</span> * name_i,
+<a name="l00054"></a>00054         <span class="keywordtype">char</span> * name_o,
+<a name="l00055"></a>00055         <span class="keywordtype">char</span> * name_n,
+<a name="l00056"></a>00056         <span class="keywordtype">char</span> * name_c
+<a name="l00057"></a>00057 );
+<a name="l00058"></a>00058 
+<a name="l00068"></a>00068 finddist_config * 
+<a name="l00069"></a>00069 parse_finddist_ini_file(<span class="keywordtype">char</span> * ini_name) ;
+<a name="l00070"></a>00070 
+<a name="l00071"></a>00071 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__finddist__ini__by__cpl_8c_source.html b/html/sinfo__finddist__ini__by__cpl_8c_source.html
new file mode 100644
index 0000000..5ca1c54
--- /dev/null
+++ b/html/sinfo__finddist__ini__by__cpl_8c_source.html
@@ -0,0 +1,459 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_finddist_ini_by_cpl.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_finddist_ini_by_cpl.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name    :   sinfo_finddist_ini_by_cpl.c</span>
+<a name="l00022"></a>00022 <span class="comment">   Author       :   Andrea Modigliani</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on   :   Aug 12, 2004</span>
+<a name="l00024"></a>00024 <span class="comment">   Description  :   distortion, slitlet distances, first column CPL input </span>
+<a name="l00025"></a>00025 <span class="comment">                    handling for SINFONI</span>
+<a name="l00026"></a>00026 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00027"></a>00027 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00029"></a>00029 <span class="preprocessor">#endif</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00031"></a>00031 <span class="comment">                                Includes</span>
+<a name="l00032"></a>00032 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include <string.h></span>
+<a name="l00034"></a>00034 <span class="preprocessor">#include "sinfo_finddist_ini_by_cpl.h"</span>
+<a name="l00035"></a>00035 <span class="preprocessor">#include "sinfo_pro_types.h"</span>
+<a name="l00036"></a>00036 <span class="preprocessor">#include "sinfo_hidden.h"</span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include "sinfo_raw_types.h"</span>
+<a name="l00038"></a>00038 <span class="preprocessor">#include "sinfo_ref_types.h"</span>
+<a name="l00039"></a>00039 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00040"></a>00040 <span class="comment">                    Functions private to this module</span>
+<a name="l00041"></a>00041 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00042"></a>00042 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00043"></a>00043 parse_section_frames(finddist_config *, cpl_parameterlist* cpl_cfg, 
+<a name="l00044"></a>00044                      cpl_frameset* sof, cpl_frameset** raw, <span class="keywordtype">int</span>* status);
+<a name="l00045"></a>00045 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00046"></a>00046 parse_section_findlines(finddist_config *, cpl_parameterlist* cpl_cfg);
+<a name="l00047"></a>00047 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00048"></a>00048 parse_section_wavecalib(finddist_config *, cpl_parameterlist* cpl_cfg);
+<a name="l00049"></a>00049 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00050"></a>00050 parse_section_wavemap(finddist_config *, cpl_parameterlist* cpl_cfg);
+<a name="l00051"></a>00051 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00052"></a>00052 parse_section_fitslits(finddist_config *, cpl_parameterlist* cpl_cfg);
+<a name="l00053"></a>00053 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00054"></a>00054 parse_section_northsouthtest(finddist_config *, cpl_parameterlist* cpl_cfg);
+<a name="l00055"></a>00055 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00056"></a>00056 parse_section_qclog      (finddist_config * cfg, cpl_parameterlist* cpl_cfg);
+<a name="l00057"></a>00057 
+<a name="l00077"></a>00077 finddist_config * 
+<a name="l00078"></a>00078 sinfo_parse_cpl_input_finddist(cpl_parameterlist * cpl_cfg, 
+<a name="l00079"></a>00079                                cpl_frameset* sof, 
+<a name="l00080"></a>00080                                cpl_frameset** raw)
+<a name="l00081"></a>00081 {
+<a name="l00082"></a>00082         finddist_config   *       cfg ;
+<a name="l00083"></a>00083         <span class="keywordtype">int</span>                   status =0;
+<a name="l00084"></a>00084 
+<a name="l00085"></a>00085         cfg = sinfo_finddist_cfg_create();
+<a name="l00086"></a>00086 
+<a name="l00087"></a>00087         parse_section_findlines (cfg, cpl_cfg);
+<a name="l00088"></a>00088         parse_section_wavecalib (cfg, cpl_cfg);
+<a name="l00089"></a>00089         parse_section_wavemap   (cfg, cpl_cfg); 
+<a name="l00090"></a>00090         parse_section_fitslits  (cfg, cpl_cfg); 
+<a name="l00091"></a>00091         parse_section_northsouthtest (cfg, cpl_cfg);
+<a name="l00092"></a>00092         parse_section_qclog(cfg,cpl_cfg);
+<a name="l00093"></a>00093         parse_section_frames   (cfg, cpl_cfg, sof, raw, &status);
+<a name="l00094"></a>00094 
+<a name="l00095"></a>00095         <span class="keywordflow">if</span> (status > 0) {
+<a name="l00096"></a>00096                 <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"parsing cpl input"</span>);
+<a name="l00097"></a>00097                 sinfo_finddist_cfg_destroy(cfg);
+<a name="l00098"></a>00098                 cfg = NULL ;
+<a name="l00099"></a>00099                 <span class="keywordflow">return</span> NULL ;
+<a name="l00100"></a>00100         }
+<a name="l00101"></a>00101         <span class="keywordflow">return</span> cfg ;
+<a name="l00102"></a>00102 }
+<a name="l00103"></a>00103 
+<a name="l00104"></a>00104 
+<a name="l00116"></a>00116 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00117"></a>00117 parse_section_frames(finddist_config * cfg,
+<a name="l00118"></a>00118              cpl_parameterlist * cpl_cfg,
+<a name="l00119"></a>00119              cpl_frameset * sof,
+<a name="l00120"></a>00120                      cpl_frameset** raw,
+<a name="l00121"></a>00121                      <span class="keywordtype">int</span>* status)
+<a name="l00122"></a>00122 {
+<a name="l00123"></a>00123 
+<a name="l00124"></a>00124 
+<a name="l00125"></a>00125 
+<a name="l00126"></a>00126    <span class="keywordtype">int</span> nframes=0;
+<a name="l00127"></a>00127    <span class="keywordtype">int</span> nraw=0;
+<a name="l00128"></a>00128    cpl_frame* frame   = NULL;
+<a name="l00129"></a>00129    cpl_parameter *p; 
+<a name="l00130"></a>00130 
+<a name="l00131"></a>00131 
+<a name="l00132"></a>00132    <span class="keywordtype">char</span> spat_res[FILE_NAME_SZ];
+<a name="l00133"></a>00133    <span class="keywordtype">char</span> lamp_status[FILE_NAME_SZ];
+<a name="l00134"></a>00134    <span class="keywordtype">char</span> band[FILE_NAME_SZ];
+<a name="l00135"></a>00135    <span class="keywordtype">int</span> ins_set=0;
+<a name="l00136"></a>00136    cpl_table* drs_tab=NULL;
+<a name="l00137"></a>00137    wcal* w=NULL;
+<a name="l00138"></a>00138    <span class="keywordtype">int</span> check=0;
+<a name="l00139"></a>00139    nstpar* nstp=NULL;
+<a name="l00140"></a>00140    distpar* d=NULL;
+<a name="l00141"></a>00141 
+<a name="l00142"></a>00142    d=sinfo_distpar_new();
+<a name="l00143"></a>00143    w=sinfo_wcal_new();
+<a name="l00144"></a>00144 
+<a name="l00145"></a>00145    nframes = cpl_frameset_get_size(sof);
+<a name="l00146"></a>00146 
+<a name="l00147"></a>00147     <span class="comment">/* Get the raw and the calibration files */</span>
+<a name="l00148"></a>00148 
+<a name="l00149"></a>00149 
+<a name="l00150"></a>00150    sinfo_extract_raw_frames_type(sof,raw,PRO_FIBRE_NS_STACKED);
+<a name="l00151"></a>00151    
+<a name="l00152"></a>00152 
+<a name="l00153"></a>00153    nraw=cpl_frameset_get_size(*raw);
+<a name="l00154"></a>00154    <span class="keywordflow">if</span> (nraw < 1) {
+<a name="l00155"></a>00155       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Too few (%d) raw frames (%s) present "</span>
+<a name="l00156"></a>00156                       <span class="stringliteral">"in frameset!Aborting..."</span>,nraw,PRO_FIBRE_NS_STACKED);
+<a name="l00157"></a>00157         sinfo_distpar_delete(d);
+<a name="l00158"></a>00158     sinfo_wcal_delete(w);
+<a name="l00159"></a>00159           (*status)++;
+<a name="l00160"></a>00160           <span class="keywordflow">return</span>;
+<a name="l00161"></a>00161    }
+<a name="l00162"></a>00162 
+<a name="l00163"></a>00163 
+<a name="l00164"></a>00164    <span class="keywordflow">if</span>(NULL != cpl_frameset_find(sof,PRO_WAVE_LAMP_STACKED)) {
+<a name="l00165"></a>00165       frame = cpl_frameset_find(sof,PRO_WAVE_LAMP_STACKED);
+<a name="l00166"></a>00166       strcpy(cfg -> inFrame,cpl_frame_get_filename(frame));
+<a name="l00167"></a>00167    } <span class="keywordflow">else</span> {
+<a name="l00168"></a>00168       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Frame %s not found! Exit!"</span>, PRO_WAVE_LAMP_STACKED);
+<a name="l00169"></a>00169         sinfo_distpar_delete(d);
+<a name="l00170"></a>00170     sinfo_wcal_delete(w);
+<a name="l00171"></a>00171         (*status)++;
+<a name="l00172"></a>00172       <span class="keywordflow">return</span>;
+<a name="l00173"></a>00173    }
+<a name="l00174"></a>00174 
+<a name="l00175"></a>00175    strcpy(cfg -> outName, DISTORTION_OUT_FILENAME);
+<a name="l00176"></a>00176 
+<a name="l00177"></a>00177 
+<a name="l00178"></a>00178    <span class="keywordflow">if</span>(NULL != cpl_frameset_find(sof,REF_LINE_ARC)) {
+<a name="l00179"></a>00179       frame = cpl_frameset_find(sof,REF_LINE_ARC);
+<a name="l00180"></a>00180       strcpy(cfg -> lineList,cpl_frame_get_filename(frame));
+<a name="l00181"></a>00181    } <span class="keywordflow">else</span> {
+<a name="l00182"></a>00182       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Frame %s not found! Exit!"</span>, REF_LINE_ARC);
+<a name="l00183"></a>00183         sinfo_distpar_delete(d);
+<a name="l00184"></a>00184     sinfo_wcal_delete(w);
+<a name="l00185"></a>00185         (*status)++;
+<a name="l00186"></a>00186       <span class="keywordflow">return</span>;
+<a name="l00187"></a>00187    }
+<a name="l00188"></a>00188 
+<a name="l00189"></a>00189    <span class="keywordflow">if</span>(NULL != cpl_frameset_find(sof,PRO_FIBRE_NS_STACKED)) {
+<a name="l00190"></a>00190       frame = cpl_frameset_find(sof,PRO_FIBRE_NS_STACKED);
+<a name="l00191"></a>00191       strcpy(cfg -> nsFrame,cpl_frame_get_filename(frame));
+<a name="l00192"></a>00192    } <span class="keywordflow">else</span> {
+<a name="l00193"></a>00193       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Frame %s not found! Exit!"</span>, PRO_FIBRE_NS_STACKED);
+<a name="l00194"></a>00194         sinfo_distpar_delete(d);
+<a name="l00195"></a>00195     sinfo_wcal_delete(w);
+<a name="l00196"></a>00196         (*status)++;
+<a name="l00197"></a>00197       <span class="keywordflow">return</span>;
+<a name="l00198"></a>00198    }
+<a name="l00199"></a>00199 
+<a name="l00200"></a>00200 
+<a name="l00201"></a>00201    <span class="keywordflow">if</span>(NULL != cpl_frameset_find(sof,PRO_BP_MAP_DI)) {
+<a name="l00202"></a>00202       frame = cpl_frameset_find(sof,PRO_BP_MAP_DI);
+<a name="l00203"></a>00203       strcpy(cfg -> mask,cpl_frame_get_filename(frame));
+<a name="l00204"></a>00204    } <span class="keywordflow">else</span> {
+<a name="l00205"></a>00205       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Frame %s not found! Exit!"</span>, PRO_BP_MAP_DI);
+<a name="l00206"></a>00206         sinfo_distpar_delete(d);
+<a name="l00207"></a>00207     sinfo_wcal_delete(w);
+<a name="l00208"></a>00208         (*status)++;
+<a name="l00209"></a>00209       <span class="keywordflow">return</span>;
+<a name="l00210"></a>00210    }
+<a name="l00211"></a>00211 
+<a name="l00212"></a>00212 
+<a name="l00213"></a>00213   
+<a name="l00214"></a>00214    frame = cpl_frameset_get_frame(*raw,0);
+<a name="l00215"></a>00215    sinfo_get_spatial_res(frame,spat_res);
+<a name="l00216"></a>00216  
+<a name="l00217"></a>00217    <span class="keywordflow">switch</span>(sinfo_frame_is_on(frame)) 
+<a name="l00218"></a>00218      {
+<a name="l00219"></a>00219    <span class="keywordflow">case</span> 0: 
+<a name="l00220"></a>00220       strcpy(lamp_status,<span class="stringliteral">"on"</span>);
+<a name="l00221"></a>00221       <span class="keywordflow">break</span>;
+<a name="l00222"></a>00222     <span class="keywordflow">case</span> 1: 
+<a name="l00223"></a>00223       strcpy(lamp_status,<span class="stringliteral">"off"</span>);
+<a name="l00224"></a>00224       <span class="keywordflow">break</span>;
+<a name="l00225"></a>00225     <span class="keywordflow">case</span> -1:
+<a name="l00226"></a>00226       strcpy(lamp_status,<span class="stringliteral">"undefined"</span>);
+<a name="l00227"></a>00227       <span class="keywordflow">break</span>;
+<a name="l00228"></a>00228     <span class="keywordflow">default</span>: 
+<a name="l00229"></a>00229       strcpy(lamp_status,<span class="stringliteral">"undefined"</span>);
+<a name="l00230"></a>00230       <span class="keywordflow">break</span>;
+<a name="l00231"></a>00231      }
+<a name="l00232"></a>00232 
+<a name="l00233"></a>00233    sinfo_get_band(frame,band);
+<a name="l00234"></a>00234    sinfo_msg(<span class="stringliteral">"Spatial resolution: %s lamp_status: %s band: %s \n"</span>,
+<a name="l00235"></a>00235                      spat_res,    lamp_status,    band);
+<a name="l00236"></a>00236 
+<a name="l00237"></a>00237 
+<a name="l00238"></a>00238    sinfo_get_ins_set(band,&ins_set);
+<a name="l00239"></a>00239     <span class="keywordflow">if</span>(NULL != cpl_frameset_find(sof,DRS_SETUP_WAVE)) {
+<a name="l00240"></a>00240      frame = cpl_frameset_find(sof,DRS_SETUP_WAVE);
+<a name="l00241"></a>00241         strcpy(cfg -> drs_setup,cpl_frame_get_filename(frame));
+<a name="l00242"></a>00242         drs_tab = cpl_table_load(cfg->drs_setup,1,0);
+<a name="l00243"></a>00243         w->wstart=cpl_table_get_double(drs_tab,<span class="stringliteral">"W_START"</span>,ins_set,&check);
+<a name="l00244"></a>00244         w->wgdisp1=cpl_table_get_double(drs_tab,<span class="stringliteral">"W_DISP1"</span>,ins_set,&check);
+<a name="l00245"></a>00245         w->wgdisp2=cpl_table_get_double(drs_tab,<span class="stringliteral">"W_DISP2"</span>,ins_set,&check);
+<a name="l00246"></a>00246         w->hw=cpl_table_get_int(drs_tab,<span class="stringliteral">"W_HW"</span>,ins_set,&check);
+<a name="l00247"></a>00247         w->fwhm=cpl_table_get_double(drs_tab,<span class="stringliteral">"W_FWHM"</span>,ins_set,&check);
+<a name="l00248"></a>00248         w->min_amp=cpl_table_get_double(drs_tab,<span class="stringliteral">"W_MIN_AMP"</span>,ins_set,&check);
+<a name="l00249"></a>00249     <span class="comment">/*</span>
+<a name="l00250"></a>00250 <span class="comment">        w->min_dif=cpl_table_get_double(drs_tab,"W_MIN_DIF",ins_set,&check);</span>
+<a name="l00251"></a>00251 <span class="comment">        w->na_coef=cpl_table_get_int(drs_tab,"W_NA_COEFF",ins_set,&check);</span>
+<a name="l00252"></a>00252 <span class="comment">        w->nb_coef=cpl_table_get_int(drs_tab,"W_NB_COEFF",ins_set,&check);</span>
+<a name="l00253"></a>00253 <span class="comment">        w->pixel_tol=cpl_table_get_double(drs_tab,"W_PIX_TOL",ins_set,&check);</span>
+<a name="l00254"></a>00254 <span class="comment">        w->y_box=cpl_table_get_double(drs_tab,"W_Y_BOX",ins_set,&check);</span>
+<a name="l00255"></a>00255 <span class="comment">    */</span>
+<a name="l00256"></a>00256         w->low_pos=cpl_table_get_int(drs_tab,<span class="stringliteral">"W_LOW_POS"</span>,ins_set,&check);
+<a name="l00257"></a>00257         w->hig_pos=cpl_table_get_int(drs_tab,<span class="stringliteral">"W_HI_POS"</span>,ins_set,&check);
+<a name="l00258"></a>00258 
+<a name="l00259"></a>00259     cfg -> guessBeginWavelength = w->wstart;
+<a name="l00260"></a>00260     cfg -> guessDispersion1 =  w->wgdisp1;
+<a name="l00261"></a>00261     cfg -> guessDispersion2 =  w->wgdisp2;
+<a name="l00262"></a>00262     cfg -> halfWidth =         w->hw;
+<a name="l00263"></a>00263     cfg -> fwhm =              w->fwhm;
+<a name="l00264"></a>00264     cfg -> minAmplitude =      w->min_amp;
+<a name="l00265"></a>00265     <span class="comment">/*</span>
+<a name="l00266"></a>00266 <span class="comment">    cfg -> mindiff =           w->min_dif;</span>
+<a name="l00267"></a>00267 <span class="comment">    cfg -> nrDispCoefficients = w->na_coef;</span>
+<a name="l00268"></a>00268 <span class="comment">    cfg -> nrCoefCoefficients = w->nb_coef;</span>
+<a name="l00269"></a>00269 <span class="comment">    cfg -> pixel_tolerance =    w->pixel_tol;</span>
+<a name="l00270"></a>00270 <span class="comment">    cfg -> yBox =               w->y_box;</span>
+<a name="l00271"></a>00271 <span class="comment">    */</span>
+<a name="l00272"></a>00272     cfg -> loPos =              DISTORTION_LOPOS;
+<a name="l00273"></a>00273     cfg -> hiPos =              DISTORTION_HIPOS;
+<a name="l00274"></a>00274     cfg -> pixel_tolerance =    w->pixel_tol;
+<a name="l00275"></a>00275         cfg-> diffTol = d->diff_tol[ins_set];
+<a name="l00276"></a>00276     <span class="comment">/*</span>
+<a name="l00277"></a>00277 <span class="comment">        sinfo_msg("cfg->guessBeginWavelength %g",cfg -> guessBeginWavelength);</span>
+<a name="l00278"></a>00278 <span class="comment">        sinfo_msg("cfg->guessDispersion1 %g",cfg -> guessDispersion1);</span>
+<a name="l00279"></a>00279 <span class="comment">        sinfo_msg("cfg->guessDispersion2 %g",cfg -> guessDispersion2);</span>
+<a name="l00280"></a>00280 <span class="comment">        sinfo_msg("cfg->mindiff %g",cfg -> mindiff);</span>
+<a name="l00281"></a>00281 <span class="comment">        sinfo_msg("cfg->halfWidth %d",cfg ->  halfWidth);</span>
+<a name="l00282"></a>00282 <span class="comment">        sinfo_msg("cfg->fwhm %g",cfg -> fwhm);</span>
+<a name="l00283"></a>00283 <span class="comment">        sinfo_msg("cfg->minAmplitude %g",cfg -> minAmplitude);</span>
+<a name="l00284"></a>00284 <span class="comment">        sinfo_msg("cfg->nrDispCoefficients %d",cfg -> nrDispCoefficients);</span>
+<a name="l00285"></a>00285 <span class="comment">        sinfo_msg("cfg->nrCoefCoefficients %d",cfg -> nrCoefCoefficients);</span>
+<a name="l00286"></a>00286 <span class="comment">        sinfo_msg("cfg->pixel_tolerance  %g",cfg -> pixel_tolerance);</span>
+<a name="l00287"></a>00287 <span class="comment">        sinfo_msg("cfg->loPos %d",cfg -> loPos);</span>
+<a name="l00288"></a>00288 <span class="comment">        sinfo_msg("cfg->hiPos %d",cfg -> hiPos);</span>
+<a name="l00289"></a>00289 <span class="comment">        sinfo_msg("cfg->yBox  %f",cfg -> yBox);</span>
+<a name="l00290"></a>00290 <span class="comment">    */</span>
+<a name="l00291"></a>00291         sinfo_distpar_delete(d);
+<a name="l00292"></a>00292     sinfo_wcal_delete(w);
+<a name="l00293"></a>00293         cpl_table_delete(drs_tab);
+<a name="l00294"></a>00294         <span class="keywordflow">if</span>(-1 == sinfo_check_rec_status(0)) {
+<a name="l00295"></a>00295       (*status)++;
+<a name="l00296"></a>00296       <span class="keywordflow">return</span>;
+<a name="l00297"></a>00297     }
+<a name="l00298"></a>00298 
+<a name="l00299"></a>00299    } <span class="keywordflow">else</span> {
+<a name="l00300"></a>00300     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Frame %s not found! Exit!"</span>, DRS_SETUP_WAVE);
+<a name="l00301"></a>00301         sinfo_distpar_delete(d);
+<a name="l00302"></a>00302     sinfo_wcal_delete(w);
+<a name="l00303"></a>00303         (*status)++;
+<a name="l00304"></a>00304         <span class="keywordflow">return</span>;
+<a name="l00305"></a>00305    }
+<a name="l00306"></a>00306 
+<a name="l00307"></a>00307 
+<a name="l00308"></a>00308    nstp=sinfo_nstpar_new();  
+<a name="l00309"></a>00309    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.distortion.ns_fwhm"</span>);
+<a name="l00310"></a>00310    <span class="keywordflow">if</span>(cpl_parameter_get_default_flag(p) == 0) {
+<a name="l00311"></a>00311       cfg->nsfwhm=nstp->fwhm[ins_set];
+<a name="l00312"></a>00312    } <span class="keywordflow">else</span> {
+<a name="l00313"></a>00313       cfg->nsfwhm=cpl_parameter_get_double(p);
+<a name="l00314"></a>00314    }
+<a name="l00315"></a>00315 
+<a name="l00316"></a>00316    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.distortion.min_diff"</span>);
+<a name="l00317"></a>00317    <span class="keywordflow">if</span>(cpl_parameter_get_default_flag(p) == 0) {
+<a name="l00318"></a>00318      cfg->minDiff=nstp->min_dif[ins_set];
+<a name="l00319"></a>00319    } <span class="keywordflow">else</span> {
+<a name="l00320"></a>00320      cfg->minDiff=cpl_parameter_get_double(p);
+<a name="l00321"></a>00321    }
+<a name="l00322"></a>00322    sinfo_nstpar_delete(nstp);
+<a name="l00323"></a>00323    <span class="comment">//sinfo_msg("cfg -> nsfwhm  %f",cfg -> nsfwhm);</span>
+<a name="l00324"></a>00324    <span class="comment">//sinfo_msg("cfg -> minDiff  %f",cfg -> minDiff);</span>
+<a name="l00325"></a>00325 
+<a name="l00326"></a>00326 
+<a name="l00327"></a>00327    <span class="keywordflow">return</span>;
+<a name="l00328"></a>00328 
+<a name="l00329"></a>00329 }
+<a name="l00330"></a>00330 
+<a name="l00331"></a>00331 
+<a name="l00340"></a>00340 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00341"></a>00341 parse_section_findlines(finddist_config * cfg,cpl_parameterlist * cpl_cfg)
+<a name="l00342"></a>00342 {
+<a name="l00343"></a>00343 
+<a name="l00344"></a>00344    cpl_parameter* p;
+<a name="l00345"></a>00345 
+<a name="l00346"></a>00346    p = cpl_parameterlist_find(cpl_cfg, 
+<a name="l00347"></a>00347                               <span class="stringliteral">"sinfoni.distortion.min_diff_mean_med_col_int"</span>);
+<a name="l00348"></a>00348    cfg -> mindiff =  cpl_parameter_get_double(p);
+<a name="l00349"></a>00349 
+<a name="l00350"></a>00350    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.distortion.half_width"</span>);
+<a name="l00351"></a>00351    cfg -> halfWidth = cpl_parameter_get_int(p);
+<a name="l00352"></a>00352 
+<a name="l00353"></a>00353    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.distortion.sigma"</span>);
+<a name="l00354"></a>00354    cfg -> sigma =  cpl_parameter_get_double(p);
+<a name="l00355"></a>00355 
+<a name="l00356"></a>00356    return ;
+<a name="l00357"></a>00357 
+<a name="l00358"></a>00358 }
+<a name="l00359"></a>00359 
+<a name="l00367"></a>00367 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00368"></a>00368 parse_section_wavecalib(finddist_config * cfg,cpl_parameterlist * cpl_cfg)
+<a name="l00369"></a>00369 {
+<a name="l00370"></a>00370 
+<a name="l00371"></a>00371 
+<a name="l00372"></a>00372    cpl_parameter* p;
+<a name="l00373"></a>00373 
+<a name="l00374"></a>00374    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.distortion.fwhm"</span>);
+<a name="l00375"></a>00375    cfg -> fwhm =  cpl_parameter_get_double(p);
+<a name="l00376"></a>00376 
+<a name="l00377"></a>00377    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.distortion.min_amplitude"</span>);
+<a name="l00378"></a>00378    cfg -> minAmplitude =  cpl_parameter_get_double(p);
+<a name="l00379"></a>00379 
+<a name="l00380"></a>00380    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.distortion.max_residual"</span>);
+<a name="l00381"></a>00381    cfg -> maxResidual =  cpl_parameter_get_double(p);
+<a name="l00382"></a>00382 
+<a name="l00383"></a>00383    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.distortion.n_a_coefficients"</span>);
+<a name="l00384"></a>00384    cfg -> nrDispCoefficients = cpl_parameter_get_int(p);
+<a name="l00385"></a>00385 
+<a name="l00386"></a>00386    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.distortion.n_b_coefficients"</span>);
+<a name="l00387"></a>00387    cfg -> nrCoefCoefficients = cpl_parameter_get_int(p);
+<a name="l00388"></a>00388 
+<a name="l00389"></a>00389    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.distortion.sigma_factor"</span>);
+<a name="l00390"></a>00390    cfg -> sigmaFactor =  cpl_parameter_get_double(p);
+<a name="l00391"></a>00391 
+<a name="l00392"></a>00392 
+<a name="l00393"></a>00393    cfg -> nslitlets = NSLITLETS;
+<a name="l00394"></a>00394 
+<a name="l00395"></a>00395    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.distortion.pixel_dist"</span>);
+<a name="l00396"></a>00396    cfg -> pixeldist = cpl_parameter_get_int(p);
+<a name="l00397"></a>00397 
+<a name="l00398"></a>00398    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.distortion.pixel_tol"</span>);
+<a name="l00399"></a>00399    cfg -> pixel_tolerance = cpl_parameter_get_double(p);
+<a name="l00400"></a>00400 
+<a name="l00401"></a>00401 
+<a name="l00402"></a>00402 
+<a name="l00403"></a>00403 }
+<a name="l00404"></a>00404 
+<a name="l00412"></a>00412 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00413"></a>00413 parse_section_wavemap(finddist_config * cfg,cpl_parameterlist * cpl_cfg)
+<a name="l00414"></a>00414 {
+<a name="l00415"></a>00415    cpl_parameter* p;
+<a name="l00416"></a>00416 
+<a name="l00417"></a>00417    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.distortion.mag_factor"</span>);
+<a name="l00418"></a>00418    cfg -> magFactor = cpl_parameter_get_int(p);
+<a name="l00419"></a>00419 
+<a name="l00420"></a>00420 }
+<a name="l00421"></a>00421 
+<a name="l00429"></a>00429 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00430"></a>00430 parse_section_fitslits(finddist_config * cfg,cpl_parameterlist * cpl_cfg)
+<a name="l00431"></a>00431 {
+<a name="l00432"></a>00432 
+<a name="l00433"></a>00433    cpl_parameter* p;
+<a name="l00434"></a>00434 
+<a name="l00435"></a>00435    cfg -> loPos =  DISTORTION_LOPOS;
+<a name="l00436"></a>00436    cfg -> hiPos =  DISTORTION_HIPOS;
+<a name="l00437"></a>00437 
+<a name="l00438"></a>00438    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.distortion.box_length"</span>);
+<a name="l00439"></a>00439    cfg -> boxLength = cpl_parameter_get_int(p);
+<a name="l00440"></a>00440 
+<a name="l00441"></a>00441    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.distortion.y_box"</span>);
+<a name="l00442"></a>00442    cfg -> yBox = cpl_parameter_get_double(p);
+<a name="l00443"></a>00443 
+<a name="l00444"></a>00444    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.distortion.diff_tol"</span>);
+<a name="l00445"></a>00445    cfg -> diffTol =  cpl_parameter_get_double(p);
+<a name="l00446"></a>00446 
+<a name="l00447"></a>00447 }
+<a name="l00448"></a>00448 
+<a name="l00456"></a>00456 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00457"></a>00457 parse_section_qclog      (finddist_config * cfg, cpl_parameterlist* cpl_cfg)
+<a name="l00458"></a>00458 {
+<a name="l00459"></a>00459    cpl_parameter* p;
+<a name="l00460"></a>00460 
+<a name="l00461"></a>00461    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.distortion.qc_thresh_min"</span>);
+<a name="l00462"></a>00462    cfg ->  qc_thresh_min = cpl_parameter_get_int(p);
+<a name="l00463"></a>00463 
+<a name="l00464"></a>00464 
+<a name="l00465"></a>00465    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.distortion.qc_thresh_max"</span>);
+<a name="l00466"></a>00466    cfg ->  qc_thresh_max = cpl_parameter_get_int(p);
+<a name="l00467"></a>00467 
+<a name="l00468"></a>00468 
+<a name="l00469"></a>00469 }
+<a name="l00470"></a>00470 
+<a name="l00471"></a>00471 
+<a name="l00479"></a>00479 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00480"></a>00480 parse_section_northsouthtest(finddist_config * cfg,cpl_parameterlist * cpl_cfg)
+<a name="l00481"></a>00481 {
+<a name="l00482"></a>00482 
+<a name="l00483"></a>00483    cpl_parameter *p;   
+<a name="l00484"></a>00484    strcat(cfg -> fitsname, DISTORTION_NS_OUT_FILENAME);
+<a name="l00485"></a>00485 
+<a name="l00486"></a>00486    cfg -> nslits = NSLITLETS;
+<a name="l00487"></a>00487 
+<a name="l00488"></a>00488    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.distortion.ns_half_width"</span>);
+<a name="l00489"></a>00489    cfg -> nshalfWidth = cpl_parameter_get_int(p);
+<a name="l00490"></a>00490 
+<a name="l00491"></a>00491    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.distortion.ns_fwhm"</span>);
+<a name="l00492"></a>00492    cfg -> nsfwhm = cpl_parameter_get_double(p);
+<a name="l00493"></a>00493 
+<a name="l00494"></a>00494    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.distortion.min_diff"</span>);
+<a name="l00495"></a>00495    cfg -> minDiff = cpl_parameter_get_double(p);
+<a name="l00496"></a>00496 
+<a name="l00497"></a>00497    cfg -> estimated_dist = ESTIMATED_SLITLETS_DISTANCE;
+<a name="l00498"></a>00498 
+<a name="l00499"></a>00499    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.distortion.dev_tol"</span>);
+<a name="l00500"></a>00500    cfg -> devtol = cpl_parameter_get_double(p);
+<a name="l00501"></a>00501 
+<a name="l00502"></a>00502    return ;
+<a name="l00503"></a>00503 
+<a name="l00504"></a>00504 }
+<a name="l00505"></a>00505 
+<a name="l00513"></a>00513 <span class="keywordtype">void</span>
+<a name="l00514"></a>00514 sinfo_finddist_free(finddist_config ** cfg)
+<a name="l00515"></a>00515 {  
+<a name="l00516"></a>00516 
+<a name="l00517"></a>00517   <span class="keywordflow">if</span>(*cfg!=NULL) {
+<a name="l00518"></a>00518     sinfo_finddist_cfg_destroy(*cfg);
+<a name="l00519"></a>00519     *cfg=NULL;
+<a name="l00520"></a>00520   }
+<a name="l00521"></a>00521   <span class="keywordflow">return</span>;
+<a name="l00522"></a>00522 
+<a name="l00523"></a>00523 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__finddist__ini__by__cpl_8h_source.html b/html/sinfo__finddist__ini__by__cpl_8h_source.html
new file mode 100644
index 0000000..da5e03b
--- /dev/null
+++ b/html/sinfo__finddist__ini__by__cpl_8h_source.html
@@ -0,0 +1,63 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_finddist_ini_by_cpl.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_finddist_ini_by_cpl.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name    :   sinfo_finddist_ini_by_cpl.h</span>
+<a name="l00022"></a>00022 <span class="comment">   Author       :   Andrea Modigliani</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on   :   Aug 12, 2004</span>
+<a name="l00024"></a>00024 <span class="comment">   Description  :   Distortions, slitlets distances, </span>
+<a name="l00025"></a>00025 <span class="comment">                    first column determination cpl input </span>
+<a name="l00026"></a>00026 <span class="comment">                    parameters parsing for SINFONI</span>
+<a name="l00027"></a>00027 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00028"></a>00028 <span class="preprocessor">#ifndef SINFO_FINDDIST_INI_BY_CPL_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_FINDDIST_INI_BY_CPL_H</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00031"></a>00031 <span class="comment">                                Includes</span>
+<a name="l00032"></a>00032 <span class="comment">---------------------------------------------------------------------------*/</span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00034"></a>00034 <span class="preprocessor">#include "sinfo_functions.h"</span>
+<a name="l00035"></a>00035 <span class="preprocessor">#include "sinfo_finddist_cfg.h"</span>
+<a name="l00036"></a>00036 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00037"></a>00037 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00038"></a>00038 <span class="comment">                             Function prototypes </span>
+<a name="l00039"></a>00039 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00051"></a>00051 finddist_config * 
+<a name="l00052"></a>00052 sinfo_parse_cpl_input_finddist(cpl_parameterlist * cpl_cfg, 
+<a name="l00053"></a>00053                                cpl_frameset* sof, 
+<a name="l00054"></a>00054                    cpl_frameset** raw);
+<a name="l00061"></a>00061 <span class="keywordtype">void</span> 
+<a name="l00062"></a>00062 sinfo_finddist_free(finddist_config ** cfg);
+<a name="l00063"></a>00063 
+<a name="l00064"></a>00064 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__fit_8c_source.html b/html/sinfo__fit_8c_source.html
new file mode 100644
index 0000000..771e3c6
--- /dev/null
+++ b/html/sinfo__fit_8c_source.html
@@ -0,0 +1,388 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_fit.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_fit.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00020"></a>00020 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00021"></a>00021 <span class="preprocessor">#endif</span>
+<a name="l00022"></a>00022 <span class="preprocessor"></span><span class="preprocessor">#include <sinfo_fit.h></span>
+<a name="l00023"></a>00023 <span class="preprocessor">#include <sinfo_msg.h></span>
+<a name="l00024"></a>00024 <span class="preprocessor">#include <stdio.h></span>
+<a name="l00025"></a>00025 <span class="preprocessor">#include <math.h></span>
+<a name="l00034"></a>00034 <span class="keyword">static</span> <span class="keywordtype">double</span> 
+<a name="l00035"></a>00035 sinfo_spline(<span class="keywordtype">double</span> x,
+<a name="l00036"></a>00036              <span class="keywordtype">double</span> cons[],
+<a name="l00037"></a>00037              <span class="keywordtype">double</span> ak[],
+<a name="l00038"></a>00038              <span class="keywordtype">double</span> *sp,
+<a name="l00039"></a>00039              <span class="keywordtype">double</span> *spp,
+<a name="l00040"></a>00040              <span class="keywordtype">double</span> *sppp,
+<a name="l00041"></a>00041              <span class="keywordtype">int</span> n);
+<a name="l00042"></a>00042 
+<a name="l00043"></a>00043 
+<a name="l00044"></a>00044 
+<a name="l00045"></a>00045 
+<a name="l00046"></a>00046 
+<a name="l00047"></a>00047 
+<a name="l00062"></a>00062 <span class="keywordtype">double</span> 
+<a name="l00063"></a>00063 sinfo_amsub(<span class="keywordtype">double</span> d0[],
+<a name="l00064"></a>00064             <span class="keywordtype">double</span> d1[],
+<a name="l00065"></a>00065             <span class="keywordtype">double</span> d2[],
+<a name="l00066"></a>00066             <span class="keywordtype">double</span> value[],
+<a name="l00067"></a>00067             <span class="keywordtype">double</span> range[],
+<a name="l00068"></a>00068             <span class="keywordtype">double</span> tol,
+<a name="l00069"></a>00069             <span class="keywordtype">int</span> ivorf[], 
+<a name="l00070"></a>00070             <span class="keywordtype">int</span> ncon,
+<a name="l00071"></a>00071             <span class="keywordtype">int</span> nref,
+<a name="l00072"></a>00072             <span class="keywordtype">double</span>(*ftbm)(<span class="keywordtype">double</span>[],<span class="keywordtype">int</span> ncon)) 
+<a name="l00073"></a>00073 
+<a name="l00074"></a>00074 {
+<a name="l00075"></a>00075   <span class="keywordtype">double</span> alpha=1.0,loc_gamma=1.5;
+<a name="l00076"></a>00076   <span class="keywordtype">double</span> sf,bsave,temp,sum,cval,ccval,beta;
+<a name="l00077"></a>00077   <span class="keywordtype">int</span> idone,nvar,nvec,nrefl,i,j,k,kd1,kval,isign,jvar,imin,imax,i2max,
+<a name="l00078"></a>00078     it1,it2,itemp;
+<a name="l00079"></a>00079   idone=0;
+<a name="l00080"></a>00080   isign=1;
+<a name="l00081"></a>00081   <span class="comment">// we require that nvec=nvar+1, define nvar</span>
+<a name="l00082"></a>00082   nvar=0;
+<a name="l00083"></a>00083  <span class="keywordflow">for</span>(i=0;i<ncon;++i) {
+<a name="l00084"></a>00084    <span class="keywordflow">if</span>(ivorf[i] == 1) {
+<a name="l00085"></a>00085       nvar=nvar+1;
+<a name="l00086"></a>00086    }
+<a name="l00087"></a>00087  }
+<a name="l00088"></a>00088  nvec=nvar+1;
+<a name="l00089"></a>00089  <span class="comment">// sf is the 'shrink' factor</span>
+<a name="l00090"></a>00090  sf=1e5*nvec;
+<a name="l00091"></a>00091  nrefl=0;
+<a name="l00092"></a>00092  value[0]=(*ftbm)(d2,ncon);
+<a name="l00093"></a>00093  <span class="comment">// sinfo_msg("value[0] = %lg",value[0]);</span>
+<a name="l00094"></a>00094  <span class="comment">// initial and shrink calculation of the d1 array, uses range</span>
+<a name="l00095"></a>00095  <span class="comment">// set d2 in the first position -- using Fortran convention of 1st</span>
+<a name="l00096"></a>00096  <span class="comment">// array element moving first</span>
+<a name="l00097"></a>00097  cont20:
+<a name="l00098"></a>00098  kd1=-1;
+<a name="l00099"></a>00099  <span class="keywordflow">for</span>(i=0;i<ncon;++i) {
+<a name="l00100"></a>00100    <span class="keywordflow">if</span>(ivorf[i]==1) {
+<a name="l00101"></a>00101      kd1=kd1+1;
+<a name="l00102"></a>00102      d1[kd1]=d2[i];
+<a name="l00103"></a>00103    }
+<a name="l00104"></a>00104  }
+<a name="l00105"></a>00105  <span class="comment">// now for the next nvar values</span>
+<a name="l00106"></a>00106  kval=0;
+<a name="l00107"></a>00107  <span class="keywordflow">for</span>(jvar=0;jvar<ncon;++jvar) {
+<a name="l00108"></a>00108    <span class="keywordflow">if</span>(ivorf[jvar] == 1) {
+<a name="l00109"></a>00109      kval=kval+1;
+<a name="l00110"></a>00110      bsave=d2[jvar];
+<a name="l00111"></a>00111      isign=-isign;
+<a name="l00112"></a>00112      d2[jvar]=d2[jvar]+isign*range[jvar];
+<a name="l00113"></a>00113      value[kval]=(*ftbm)(d2,ncon);
+<a name="l00114"></a>00114      <span class="keywordflow">for</span>(i=0;i<ncon;++i) {
+<a name="l00115"></a>00115        <span class="keywordflow">if</span>(ivorf[i]==1) {
+<a name="l00116"></a>00116      kd1=kd1+1;
+<a name="l00117"></a>00117          d1[kd1]=d2[i];
+<a name="l00118"></a>00118        }
+<a name="l00119"></a>00119      }
+<a name="l00120"></a>00120      d2[jvar]=bsave;
+<a name="l00121"></a>00121    }
+<a name="l00122"></a>00122  }
+<a name="l00123"></a>00123  <span class="comment">// sinfo_msg(" d1 ");</span>
+<a name="l00124"></a>00124  <span class="comment">// for (j=0;j<nvec;++j) {</span>
+<a name="l00125"></a>00125  <span class="comment">//   for(i=0;i<nvar;++i) {</span>
+<a name="l00126"></a>00126  <span class="comment">//     sinfo_msg("%12.4lg ",d1[i+j*nvar]);</span>
+<a name="l00127"></a>00127  <span class="comment">//   }</span>
+<a name="l00128"></a>00128  <span class="comment">// }</span>
+<a name="l00129"></a>00129  <span class="comment">/* find highest, second highest, and minimum values</span>
+<a name="l00130"></a>00130 <span class="comment">    imax points to the vector with the largest value</span>
+<a name="l00131"></a>00131 <span class="comment">    i2max points to the vector with the second largest value</span>
+<a name="l00132"></a>00132 <span class="comment">    imin points to the vector with the smallest value  */</span>
+<a name="l00133"></a>00133  cont40:
+<a name="l00134"></a>00134  imin=1;
+<a name="l00135"></a>00135  <span class="keywordflow">if</span>(value[0]>value[1]) {
+<a name="l00136"></a>00136    imax=0;
+<a name="l00137"></a>00137    i2max=1;
+<a name="l00138"></a>00138  } <span class="keywordflow">else</span> {
+<a name="l00139"></a>00139    imax=1;
+<a name="l00140"></a>00140    i2max=0;
+<a name="l00141"></a>00141  }
+<a name="l00142"></a>00142  <span class="keywordflow">for</span>(i=0;i<nvec;++i) {
+<a name="l00143"></a>00143    <span class="keywordflow">if</span>(value[i]<value[imin]) imin=i;
+<a name="l00144"></a>00144    <span class="keywordflow">if</span>(value[i]>value[imax]) {
+<a name="l00145"></a>00145      i2max=imax;
+<a name="l00146"></a>00146      imax=i;
+<a name="l00147"></a>00147    } <span class="keywordflow">else</span> <span class="keywordflow">if</span>( (value[i]>value[i2max]) && (i != imax) ) {
+<a name="l00148"></a>00148        i2max=i;
+<a name="l00149"></a>00149    }
+<a name="l00150"></a>00150  }
+<a name="l00151"></a>00151  <span class="comment">// sinfo_msg(" values after sorting ");</span>
+<a name="l00152"></a>00152  <span class="comment">// for(i=0;i<nvec;++i)sinfo_msg("%12.4lg ",value[i]);</span>
+<a name="l00153"></a>00153  <span class="comment">// sinfo_msg("imin %d,i2max %d,imax %d",imin,i2max,imax); </span>
+<a name="l00154"></a>00154  <span class="comment">// scanf("%d",&itest);</span>
+<a name="l00155"></a>00155 
+<a name="l00156"></a>00156  <span class="comment">// check if done</span>
+<a name="l00157"></a>00157 
+<a name="l00158"></a>00158  <span class="keywordflow">if</span>(nrefl>=nref) {
+<a name="l00159"></a>00159    sinfo_msg(<span class="stringliteral">" maximum number of reflection reached"</span>);
+<a name="l00160"></a>00160    idone=1;
+<a name="l00161"></a>00161    <span class="keywordflow">goto</span> cont400;
+<a name="l00162"></a>00162  }
+<a name="l00163"></a>00163  <span class="keywordflow">if</span>(value[imin]!=0.0) {
+<a name="l00164"></a>00164    temp=(value[imax]-value[imin])/value[imin];
+<a name="l00165"></a>00165    <span class="keywordflow">if</span>(fabs(temp)<=tol) {
+<a name="l00166"></a>00166      sinfo_msg(<span class="stringliteral">" reached tolerance %lg temp %lg tol"</span>,temp,tol);
+<a name="l00167"></a>00167      idone=1;
+<a name="l00168"></a>00168      <span class="keywordflow">goto</span> cont400;
+<a name="l00169"></a>00169    }
+<a name="l00170"></a>00170  }
+<a name="l00171"></a>00171  <span class="keywordflow">if</span>(value[imax]-value[imin]<=tol) {
+<a name="l00172"></a>00172     sinfo_msg(<span class="stringliteral">"value[max]-value[min]<=tol"</span>);
+<a name="l00173"></a>00173     idone=1;
+<a name="l00174"></a>00174     <span class="keywordflow">goto</span> cont400;
+<a name="l00175"></a>00175  }
+<a name="l00176"></a>00176     
+<a name="l00177"></a>00177  <span class="comment">// *** form d0 the average of all but imax</span>
+<a name="l00178"></a>00178  <span class="keywordflow">for</span>(j=0;j<nvar;++j) {
+<a name="l00179"></a>00179    sum=0.0;
+<a name="l00180"></a>00180    <span class="keywordflow">for</span>(i=0;i<nvec;++i) {
+<a name="l00181"></a>00181       <span class="keywordflow">if</span>(i!=imax)sum=sum+d1[i*nvar+j];
+<a name="l00182"></a>00182    }
+<a name="l00183"></a>00183    d0[j]=sum/(nvec-1);
+<a name="l00184"></a>00184  }
+<a name="l00185"></a>00185  <span class="comment">// sinfo_msg(" D0 values ");</span>
+<a name="l00186"></a>00186  <span class="comment">// for(i=0;i<nvar;++i)sinfo_msg("%12.4lg ",d0[i]);</span>
+<a name="l00187"></a>00187  <span class="comment">// scanf("%d",&itest);</span>
+<a name="l00188"></a>00188  <span class="comment">// reflection</span>
+<a name="l00189"></a>00189 
+<a name="l00190"></a>00190  nrefl=nrefl+1;
+<a name="l00191"></a>00191  k=-1;
+<a name="l00192"></a>00192  <span class="keywordflow">for</span>(j=0;j<ncon;++j) {
+<a name="l00193"></a>00193    <span class="keywordflow">if</span>(ivorf[j]==1) {
+<a name="l00194"></a>00194      k=k+1;
+<a name="l00195"></a>00195      it1=imax*nvar+k;
+<a name="l00196"></a>00196      d2[j]=(1+alpha)*d0[k]-alpha*d1[it1];
+<a name="l00197"></a>00197    }
+<a name="l00198"></a>00198  }
+<a name="l00199"></a>00199 
+<a name="l00200"></a>00200  <span class="comment">// sinfo_msg(" refl d2 ");</span>
+<a name="l00201"></a>00201  <span class="comment">// for(i=0;i<nvar;++i) sinfo_msg("%12.4lg ",d2[i]);</span>
+<a name="l00202"></a>00202 
+<a name="l00203"></a>00203  cval=(*ftbm)(d2,ncon);
+<a name="l00204"></a>00204  <span class="comment">// sinfo_msg("refl ftbm %lg",cval);  </span>
+<a name="l00205"></a>00205 
+<a name="l00206"></a>00206  <span class="comment">// value is higher than i2max so do contraction</span>
+<a name="l00207"></a>00207  <span class="keywordflow">if</span>(cval>=value[i2max]) <span class="keywordflow">goto</span> cont200;
+<a name="l00208"></a>00208 
+<a name="l00209"></a>00209  <span class="comment">// value is less than i2max - normal - update d1 and value</span>
+<a name="l00210"></a>00210 
+<a name="l00211"></a>00211  value[imax]=cval;
+<a name="l00212"></a>00212  k=-1;
+<a name="l00213"></a>00213  <span class="keywordflow">for</span>(j=0;j<ncon;++j) {
+<a name="l00214"></a>00214    <span class="keywordflow">if</span>(ivorf[j]==1) {
+<a name="l00215"></a>00215      k=k+1;
+<a name="l00216"></a>00216      it1=imax*nvar+k;
+<a name="l00217"></a>00217      d1[it1]=d2[j];
+<a name="l00218"></a>00218    }
+<a name="l00219"></a>00219  }
+<a name="l00220"></a>00220 
+<a name="l00221"></a>00221  <span class="comment">// value is less than imin, try expansion</span>
+<a name="l00222"></a>00222  <span class="keywordflow">if</span>(cval<value[imin]) <span class="keywordflow">goto</span> cont300;
+<a name="l00223"></a>00223  <span class="keywordflow">goto</span> cont40;
+<a name="l00224"></a>00224 
+<a name="l00225"></a>00225  <span class="comment">// contraction</span>
+<a name="l00226"></a>00226  cont200:
+<a name="l00227"></a>00227  <span class="comment">// sinfo_msg(" contraction ");</span>
+<a name="l00228"></a>00228  beta=0.75;
+<a name="l00229"></a>00229  <span class="keywordflow">for</span>(itemp=0;itemp<3;++itemp) {
+<a name="l00230"></a>00230    <span class="keywordflow">if</span>(cval<=value[imax]) {
+<a name="l00231"></a>00231      value[imax]=cval;
+<a name="l00232"></a>00232      k=-1;
+<a name="l00233"></a>00233      <span class="keywordflow">for</span>(j=0;j<ncon;++j) {
+<a name="l00234"></a>00234        <span class="keywordflow">if</span>(ivorf[j]==1) {
+<a name="l00235"></a>00235          k=k+1;
+<a name="l00236"></a>00236          it1=imax*nvar+k;
+<a name="l00237"></a>00237          d1[it1]=d2[j];
+<a name="l00238"></a>00238        }
+<a name="l00239"></a>00239      }
+<a name="l00240"></a>00240    }
+<a name="l00241"></a>00241    k=-1;
+<a name="l00242"></a>00242    <span class="keywordflow">for</span>(j=0;j<ncon;++j) {
+<a name="l00243"></a>00243      <span class="keywordflow">if</span>(ivorf[j]==1) {
+<a name="l00244"></a>00244        k=k+1;
+<a name="l00245"></a>00245        it1=imax*nvar+k;
+<a name="l00246"></a>00246        d2[j]=beta*d1[it1]+(1.-beta)*d0[k];
+<a name="l00247"></a>00247      }
+<a name="l00248"></a>00248    }
+<a name="l00249"></a>00249    cval=ftbm(d2,ncon);
+<a name="l00250"></a>00250 
+<a name="l00251"></a>00251    <span class="comment">// sinfo_msg(" contraction beta %lg cval %lg ",beta,cval);</span>
+<a name="l00252"></a>00252    <span class="comment">// value is better</span>
+<a name="l00253"></a>00253    <span class="keywordflow">if</span>(cval<value[i2max]) {
+<a name="l00254"></a>00254      value[imax]=cval;
+<a name="l00255"></a>00255      k=-1;
+<a name="l00256"></a>00256      <span class="keywordflow">for</span>(j=0;j<ncon;++j) {
+<a name="l00257"></a>00257        <span class="keywordflow">if</span>(ivorf[j]==1) {
+<a name="l00258"></a>00258          k=k+1;
+<a name="l00259"></a>00259          it1=imax*nvar+k;
+<a name="l00260"></a>00260          d1[it1]=d2[j];
+<a name="l00261"></a>00261        }
+<a name="l00262"></a>00262      }
+<a name="l00263"></a>00263      <span class="keywordflow">if</span>(cval<value[imin]) sinfo_msg(<span class="stringliteral">" contraction minimum %lg"</span>,cval);
+<a name="l00264"></a>00264      <span class="keywordflow">goto</span> cont40;
+<a name="l00265"></a>00265    }
+<a name="l00266"></a>00266    beta=beta-0.25;
+<a name="l00267"></a>00267  }
+<a name="l00268"></a>00268  sinfo_msg(<span class="stringliteral">" contraction failed  ==>shrink"</span>);
+<a name="l00269"></a>00269  <span class="comment">// scanf("%d",&itest);</span>
+<a name="l00270"></a>00270  <span class="comment">// value is worse so shrink it</span>
+<a name="l00271"></a>00271 
+<a name="l00272"></a>00272  <span class="keywordflow">goto</span> cont400;
+<a name="l00273"></a>00273 
+<a name="l00274"></a>00274  <span class="comment">// expansion</span>
+<a name="l00275"></a>00275 
+<a name="l00276"></a>00276  cont300:
+<a name="l00277"></a>00277  sinfo_msg(<span class="stringliteral">" reflection min %lg \n"</span>, cval);
+<a name="l00278"></a>00278  k=-1;
+<a name="l00279"></a>00279  <span class="keywordflow">for</span>(j=0;j<ncon;++j) {
+<a name="l00280"></a>00280    <span class="keywordflow">if</span>(ivorf[j]==1) {
+<a name="l00281"></a>00281      k=k+1;
+<a name="l00282"></a>00282      d2[j]=loc_gamma*d2[j]+(1.-loc_gamma)*d0[k];
+<a name="l00283"></a>00283    }
+<a name="l00284"></a>00284  }
+<a name="l00285"></a>00285  ccval=(*ftbm)(d2,ncon);
+<a name="l00286"></a>00286  <span class="comment">// value is higher than reflected value ==> discard</span>
+<a name="l00287"></a>00287  <span class="keywordflow">if</span>(ccval>cval) <span class="keywordflow">goto</span> cont40;
+<a name="l00288"></a>00288  <span class="comment">// value is better so use it rather than the reflected point</span>
+<a name="l00289"></a>00289  sinfo_msg(<span class="stringliteral">" expansion minimum %lg \n"</span>,ccval);
+<a name="l00290"></a>00290  value[imax]=ccval;
+<a name="l00291"></a>00291  k=-1;
+<a name="l00292"></a>00292  <span class="keywordflow">for</span>(j=0;j<ncon;++j) {
+<a name="l00293"></a>00293    <span class="keywordflow">if</span>(ivorf[j]==1) {
+<a name="l00294"></a>00294      k=k+1;
+<a name="l00295"></a>00295      it1=imax*nvar+k;
+<a name="l00296"></a>00296      d1[it1]=d2[j];
+<a name="l00297"></a>00297    }
+<a name="l00298"></a>00298  }
+<a name="l00299"></a>00299  <span class="keywordflow">goto</span> cont40;
+<a name="l00300"></a>00300 
+<a name="l00301"></a>00301  cont400:
+<a name="l00302"></a>00302  <span class="comment">// sinfo_msg(" following cont400 ");</span>
+<a name="l00303"></a>00303  <span class="comment">// scanf("%d",&itest);</span>
+<a name="l00304"></a>00304  <span class="comment">// recalculate d2 and range</span>
+<a name="l00305"></a>00305  <span class="comment">// the range is the average of dist**2 from d1 with min value</span>
+<a name="l00306"></a>00306  k=-1;
+<a name="l00307"></a>00307  <span class="keywordflow">for</span>(j=0;j<ncon;++j) {
+<a name="l00308"></a>00308    <span class="keywordflow">if</span>(ivorf[j]==1) {
+<a name="l00309"></a>00309      k=k+1;
+<a name="l00310"></a>00310      it1=imin*nvar+k;
+<a name="l00311"></a>00311      d2[j]=d1[it1];
+<a name="l00312"></a>00312      sum=0.0;
+<a name="l00313"></a>00313      <span class="keywordflow">for</span>(i=0;i<nvec;++i) {
+<a name="l00314"></a>00314        it1=i*nvar+k;
+<a name="l00315"></a>00315        it2=imin*nvar+k;
+<a name="l00316"></a>00316        sum=sum+(d1[it1]-d1[it2])*(d1[it1]-d1[it2]);
+<a name="l00317"></a>00317      }
+<a name="l00318"></a>00318      range[j]=sf*sqrt(sum/(nvec-1));
+<a name="l00319"></a>00319    }
+<a name="l00320"></a>00320  }
+<a name="l00321"></a>00321  value[1]=value[imin];
+<a name="l00322"></a>00322  sf=.75*sf;
+<a name="l00323"></a>00323  <span class="keywordflow">if</span>(sf<0.1)idone=1;
+<a name="l00324"></a>00324  sinfo_msg(<span class="stringliteral">" shrink factor %lg "</span>,sf);
+<a name="l00325"></a>00325  <span class="keywordflow">if</span>(idone!=1)<span class="keywordflow">goto</span> cont20;
+<a name="l00326"></a>00326  <span class="keywordflow">return</span> value[1];
+<a name="l00327"></a>00327 
+<a name="l00328"></a>00328 }
+<a name="l00329"></a>00329 
+<a name="l00330"></a>00330 <span class="keyword">static</span> <span class="keywordtype">double</span> 
+<a name="l00331"></a>00331 sinfo_spline(<span class="keywordtype">double</span> x,
+<a name="l00332"></a>00332              <span class="keywordtype">double</span> cons[],
+<a name="l00333"></a>00333              <span class="keywordtype">double</span> ak[],
+<a name="l00334"></a>00334              <span class="keywordtype">double</span> *sp,
+<a name="l00335"></a>00335              <span class="keywordtype">double</span> *spp,
+<a name="l00336"></a>00336              <span class="keywordtype">double</span> *sppp,
+<a name="l00337"></a>00337              <span class="keywordtype">int</span> n)
+<a name="l00338"></a>00338 {
+<a name="l00339"></a>00339 <span class="keywordtype">double</span> retval=0;
+<a name="l00340"></a>00340 <span class="keywordtype">double</span> xm=0;
+<a name="l00341"></a>00341 <span class="keywordtype">double</span> xm2=0;
+<a name="l00342"></a>00342 <span class="keywordtype">double</span> xm3=0;
+<a name="l00343"></a>00343 
+<a name="l00344"></a>00344 <span class="keywordtype">int</span> i=0;
+<a name="l00345"></a>00345 
+<a name="l00346"></a>00346 
+<a name="l00347"></a>00347  *sp=0;
+<a name="l00348"></a>00348  *spp=0;
+<a name="l00349"></a>00349  *sppp=0;
+<a name="l00350"></a>00350 
+<a name="l00351"></a>00351  <span class="keywordflow">for</span>(i=0;i<n;++i) {
+<a name="l00352"></a>00352    <span class="keywordflow">if</span>(ak[i] >= x) {
+<a name="l00353"></a>00353      xm=ak[i]-x;
+<a name="l00354"></a>00354      xm2=xm*xm;
+<a name="l00355"></a>00355      xm3=xm*xm2;
+<a name="l00356"></a>00356      sinfo_msg(<span class="stringliteral">"cons=%g"</span>,cons[i]);
+<a name="l00357"></a>00357      retval+=cons[i]*xm3;
+<a name="l00358"></a>00358      *sp-=3*cons[i]*xm2;
+<a name="l00359"></a>00359      *spp+=6*cons[i]*xm;
+<a name="l00360"></a>00360      *sppp-=6*cons[i];
+<a name="l00361"></a>00361    }
+<a name="l00362"></a>00362  }
+<a name="l00363"></a>00363  sinfo_msg(<span class="stringliteral">"1x=%g retval=%g"</span>,x,retval);
+<a name="l00364"></a>00364  <span class="keywordflow">return</span> retval;
+<a name="l00365"></a>00365 
+<a name="l00366"></a>00366 }
+<a name="l00367"></a>00367 
+<a name="l00368"></a>00368 
+<a name="l00369"></a>00369 
+<a name="l00370"></a>00370 
+<a name="l00371"></a>00371 <span class="keywordtype">double</span> 
+<a name="l00372"></a>00372 sinfo_ftbm(<span class="keyword">const</span> <span class="keywordtype">double</span> x, <span class="keywordtype">double</span> cons[])
+<a name="l00373"></a>00373 {
+<a name="l00374"></a>00374   <span class="keywordtype">double</span> retval=0;
+<a name="l00375"></a>00375   <span class="keywordtype">double</span> ak[4]={-1,-.666666666666666,-.333333333333,0};
+<a name="l00376"></a>00376   <span class="keywordtype">double</span> sm1=0;
+<a name="l00377"></a>00377   <span class="keywordtype">double</span> spm1=0;
+<a name="l00378"></a>00378   <span class="keywordtype">double</span> sppm1=0;
+<a name="l00379"></a>00379   <span class="keywordtype">double</span> spppm1=0;
+<a name="l00380"></a>00380 
+<a name="l00381"></a>00381   <span class="keywordtype">int</span> n=4;
+<a name="l00382"></a>00382 
+<a name="l00383"></a>00383   sm1=sinfo_spline(x,cons,ak,&spm1,&sppm1,&spppm1,n)-1;
+<a name="l00384"></a>00384   sinfo_msg(<span class="stringliteral">"x=%g val=%g"</span>,x,sm1+1);
+<a name="l00385"></a>00385 
+<a name="l00386"></a>00386   retval=sm1*sm1+spm1*spm1+sppm1*sppm1+spppm1*spppm1;
+<a name="l00387"></a>00387   sinfo_msg(<span class="stringliteral">"fitbm: x=%g retval=%g"</span>,x,retval);
+<a name="l00388"></a>00388   
+<a name="l00389"></a>00389   <span class="keywordflow">return</span> retval;
+<a name="l00390"></a>00390 
+<a name="l00391"></a>00391 }
+<a name="l00392"></a>00392 
+<a name="l00393"></a>00393 
+<a name="l00394"></a>00394 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__fit_8h_source.html b/html/sinfo__fit_8h_source.html
new file mode 100644
index 0000000..6912e57
--- /dev/null
+++ b/html/sinfo__fit_8h_source.html
@@ -0,0 +1,54 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_fit.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_fit.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="preprocessor">#ifndef SINFO_FIT_H</span>
+<a name="l00020"></a>00020 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_FIT_H</span>
+<a name="l00021"></a>00021 <span class="preprocessor"></span><span class="keywordtype">double</span> 
+<a name="l00022"></a>00022 sinfo_amsub(<span class="keywordtype">double</span> d0[],
+<a name="l00023"></a>00023             <span class="keywordtype">double</span> d1[],
+<a name="l00024"></a>00024             <span class="keywordtype">double</span> d2[],
+<a name="l00025"></a>00025             <span class="keywordtype">double</span> value[],
+<a name="l00026"></a>00026             <span class="keywordtype">double</span> range[],
+<a name="l00027"></a>00027             <span class="keywordtype">double</span> tol,
+<a name="l00028"></a>00028             <span class="keywordtype">int</span> ivorf[], 
+<a name="l00029"></a>00029             <span class="keywordtype">int</span> ncon,
+<a name="l00030"></a>00030             <span class="keywordtype">int</span> nref,
+<a name="l00031"></a>00031         <span class="keywordtype">double</span>(*ftbm)(<span class="keywordtype">double</span>[],<span class="keywordtype">int</span> ncon));
+<a name="l00032"></a>00032 
+<a name="l00033"></a>00033 
+<a name="l00034"></a>00034 
+<a name="l00035"></a>00035 <span class="keywordtype">double</span> 
+<a name="l00036"></a>00036 sinfo_ftbm(<span class="keyword">const</span> <span class="keywordtype">double</span> x, <span class="keywordtype">double</span> cons[]);
+<a name="l00037"></a>00037 
+<a name="l00038"></a>00038 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__fit__curve_8c_source.html b/html/sinfo__fit__curve_8c_source.html
new file mode 100644
index 0000000..f388e59
--- /dev/null
+++ b/html/sinfo__fit__curve_8c_source.html
@@ -0,0 +1,146 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_fit_curve.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_fit_curve.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name     :    fit_curve.c</span>
+<a name="l00022"></a>00022 <span class="comment">   Author         :    N. Devillard</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on    :    July 1998</span>
+<a name="l00024"></a>00024 <span class="comment">   Description    :    1d and 2d fit related routines</span>
+<a name="l00025"></a>00025 <span class="comment"></span>
+<a name="l00026"></a>00026 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00027"></a>00027 <span class="comment">/*</span>
+<a name="l00028"></a>00028 <span class="comment">    $Id: sinfo_fit_curve.c,v 1.4 2012/03/02 08:42:20 amodigli Exp $</span>
+<a name="l00029"></a>00029 <span class="comment">    $Author: amodigli $</span>
+<a name="l00030"></a>00030 <span class="comment">    $Date: 2012/03/02 08:42:20 $</span>
+<a name="l00031"></a>00031 <span class="comment">    $Revision: 1.4 $</span>
+<a name="l00032"></a>00032 <span class="comment">*/</span>
+<a name="l00033"></a>00033 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00034"></a>00034 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00035"></a>00035 <span class="preprocessor">#endif</span>
+<a name="l00036"></a>00036 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00037"></a>00037 <span class="comment">                                   Includes</span>
+<a name="l00038"></a>00038 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00039"></a>00039 <span class="preprocessor">#include <math.h></span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include "sinfo_fit_curve.h"</span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include "sinfo_ipow.h"</span>
+<a name="l00050"></a>00050 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00051"></a>00051 <span class="comment">                            Private functions</span>
+<a name="l00052"></a>00052 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00053"></a>00053 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00054"></a>00054 <span class="comment">                              Function codes</span>
+<a name="l00055"></a>00055 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00078"></a>00078 <span class="keywordtype">double</span> *
+<a name="l00079"></a>00079 sinfo_fit_1d_poly(
+<a name="l00080"></a>00080     <span class="keywordtype">int</span>            poly_deg,
+<a name="l00081"></a>00081     dpoint    *    list,
+<a name="l00082"></a>00082     <span class="keywordtype">int</span>            np,
+<a name="l00083"></a>00083     <span class="keywordtype">double</span>    *    mse
+<a name="l00084"></a>00084 )
+<a name="l00085"></a>00085 {
+<a name="l00086"></a>00086     <span class="keywordtype">int</span>            i, k ;
+<a name="l00087"></a>00087     Matrix        mA, mB, mX ;
+<a name="l00088"></a>00088     <span class="keywordtype">double</span>    *    c ;
+<a name="l00089"></a>00089     <span class="keywordtype">double</span>        err ;
+<a name="l00090"></a>00090     <span class="keywordtype">double</span>        xp, y ;
+<a name="l00091"></a>00091 
+<a name="l00092"></a>00092     <span class="keywordflow">if</span> (np<poly_deg+1) {
+<a name="l00093"></a>00093         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"not enough points"</span>) ;
+<a name="l00094"></a>00094         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"cannot fit %dth degree polynomial with %d points"</span>,
+<a name="l00095"></a>00095                 poly_deg, np);
+<a name="l00096"></a>00096         <span class="keywordflow">return</span> NULL;
+<a name="l00097"></a>00097     }
+<a name="l00098"></a>00098 
+<a name="l00099"></a>00099     mA = sinfo_create_mx(poly_deg+1, np) ;
+<a name="l00100"></a>00100     mB = sinfo_create_mx(1, np) ;
+<a name="l00101"></a>00101 
+<a name="l00102"></a>00102     <span class="keywordflow">for</span> (i=0 ; i<np ; i++) {
+<a name="l00103"></a>00103         mA->m[i] = 1.0 ;
+<a name="l00104"></a>00104         <span class="keywordflow">for</span> (k=1 ; k<=poly_deg ; k++) {
+<a name="l00105"></a>00105             mA->m[i+k*np] = sinfo_ipow(list[i].x, k) ;
+<a name="l00106"></a>00106         }
+<a name="l00107"></a>00107         mB->m[i] = list[i].y ;
+<a name="l00108"></a>00108     }
+<a name="l00109"></a>00109 
+<a name="l00110"></a>00110     <span class="comment">/*</span>
+<a name="l00111"></a>00111 <span class="comment">     * Solve XA=B by a least-square solution (aka pseudo-inverse).</span>
+<a name="l00112"></a>00112 <span class="comment">     */</span>
+<a name="l00113"></a>00113     mX = sinfo_least_sq_mx(mA,mB) ;
+<a name="l00114"></a>00114     <span class="comment">/*</span>
+<a name="l00115"></a>00115 <span class="comment">     * Delete input matrices</span>
+<a name="l00116"></a>00116 <span class="comment">     */</span>
+<a name="l00117"></a>00117     sinfo_close_mx(mA) ;
+<a name="l00118"></a>00118     sinfo_close_mx(mB) ;
+<a name="l00119"></a>00119     <span class="comment">/*</span>
+<a name="l00120"></a>00120 <span class="comment">     * Examine result</span>
+<a name="l00121"></a>00121 <span class="comment">     */</span>
+<a name="l00122"></a>00122     <span class="keywordflow">if</span> (mX==NULL) {
+<a name="l00123"></a>00123         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"cannot fit: non-invertible sinfo_matrix"</span>) ;
+<a name="l00124"></a>00124         <span class="keywordflow">return</span> NULL ;
+<a name="l00125"></a>00125     }
+<a name="l00126"></a>00126 
+<a name="l00127"></a>00127     c = cpl_malloc((poly_deg+1)*<span class="keyword">sizeof</span>(<span class="keywordtype">double</span>)) ;
+<a name="l00128"></a>00128     <span class="keywordflow">for</span> (i=0 ; i<(poly_deg+1) ; i++) {
+<a name="l00129"></a>00129         c[i] = mX->m[i] ;
+<a name="l00130"></a>00130     }
+<a name="l00131"></a>00131     sinfo_close_mx(mX) ;
+<a name="l00132"></a>00132 
+<a name="l00133"></a>00133     <span class="comment">/*</span>
+<a name="l00134"></a>00134 <span class="comment">     * If requested, compute mean squared error</span>
+<a name="l00135"></a>00135 <span class="comment">     */</span>
+<a name="l00136"></a>00136     <span class="keywordflow">if</span> (mse != NULL) {
+<a name="l00137"></a>00137         err = 0.00 ;
+<a name="l00138"></a>00138         <span class="keywordflow">for</span> (i=0 ; i<np ; i++) {
+<a name="l00139"></a>00139             y = c[0] ;
+<a name="l00140"></a>00140             <span class="comment">/*</span>
+<a name="l00141"></a>00141 <span class="comment">             * Compute the value obtained through the fit</span>
+<a name="l00142"></a>00142 <span class="comment">             */</span>
+<a name="l00143"></a>00143             <span class="keywordflow">for</span> (k=1 ; k<=poly_deg ; k++) {
+<a name="l00144"></a>00144                 xp = sinfo_ipow(list[i].x, k) ;
+<a name="l00145"></a>00145                 y += c[k] * xp ; 
+<a name="l00146"></a>00146             }
+<a name="l00147"></a>00147             <span class="comment">/*</span>
+<a name="l00148"></a>00148 <span class="comment">             * Subtract from the true value, square, accumulate</span>
+<a name="l00149"></a>00149 <span class="comment">             */</span>
+<a name="l00150"></a>00150             xp   = sinfo_ipow(list[i].y - y, 2) ;
+<a name="l00151"></a>00151             err += xp ; 
+<a name="l00152"></a>00152         }
+<a name="l00153"></a>00153         <span class="comment">/* Average the error term */</span>
+<a name="l00154"></a>00154         err /= (double)np ;
+<a name="l00155"></a>00155         *mse = err ;
+<a name="l00156"></a>00156     }
+<a name="l00157"></a>00157     <span class="keywordflow">return</span> c ;
+<a name="l00158"></a>00158 }
+<a name="l00159"></a>00159 
+<a name="l00160"></a>00160 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__fit__curve_8h_source.html b/html/sinfo__fit__curve_8h_source.html
new file mode 100644
index 0000000..c00a4ab
--- /dev/null
+++ b/html/sinfo__fit__curve_8h_source.html
@@ -0,0 +1,73 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_fit_curve.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_fit_curve.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name     :    sinfo_fit_curve.h</span>
+<a name="l00022"></a>00022 <span class="comment">   Author         :    N. Devillard</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on    :    July 1998</span>
+<a name="l00024"></a>00024 <span class="comment">   Description    :    1d and 2d fit related routines</span>
+<a name="l00025"></a>00025 <span class="comment"></span>
+<a name="l00026"></a>00026 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="comment">/*</span>
+<a name="l00029"></a>00029 <span class="comment">    $Id: sinfo_fit_curve.h,v 1.4 2007/06/06 07:10:45 amodigli Exp $</span>
+<a name="l00030"></a>00030 <span class="comment">    $Author: amodigli $</span>
+<a name="l00031"></a>00031 <span class="comment">    $Date: 2007/06/06 07:10:45 $</span>
+<a name="l00032"></a>00032 <span class="comment">    $Revision: 1.4 $</span>
+<a name="l00033"></a>00033 <span class="comment">*/</span>
+<a name="l00034"></a>00034 
+<a name="l00035"></a>00035 <span class="preprocessor">#ifndef SINFO_FIT_CURVE_H</span>
+<a name="l00036"></a>00036 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_FIT_CURVE_H</span>
+<a name="l00037"></a>00037 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00038"></a>00038 <span class="comment">                                   Includes</span>
+<a name="l00039"></a>00039 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include "sinfo_matrix.h"</span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include "sinfo_local_types.h"</span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00043"></a>00043 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00044"></a>00044 <span class="comment">                              Function codes</span>
+<a name="l00045"></a>00045 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00046"></a>00046 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l00068"></a>00068 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00069"></a>00069 
+<a name="l00070"></a>00070 <span class="keywordtype">double</span> *
+<a name="l00071"></a>00071 sinfo_fit_1d_poly(
+<a name="l00072"></a>00072     <span class="keywordtype">int</span>         poly_deg,
+<a name="l00073"></a>00073     dpoint  *   list,
+<a name="l00074"></a>00074     <span class="keywordtype">int</span>         np,
+<a name="l00075"></a>00075     <span class="keywordtype">double</span>  *   mean_squared_error
+<a name="l00076"></a>00076 ) ;
+<a name="l00077"></a>00077 
+<a name="l00078"></a>00078 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__flat__cfg_8c_source.html b/html/sinfo__flat__cfg_8c_source.html
new file mode 100644
index 0000000..ad7be19
--- /dev/null
+++ b/html/sinfo__flat__cfg_8c_source.html
@@ -0,0 +1,70 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_flat_cfg.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_flat_cfg.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name     :    sinfo_flat_cfg.c</span>
+<a name="l00022"></a>00022 <span class="comment">   Author         : Juergen Schreiber</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on    :    March 2002</span>
+<a name="l00024"></a>00024 <span class="comment">   Description    :    prepare flatfield frames configuration handling tools</span>
+<a name="l00025"></a>00025 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00026"></a>00026 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00027"></a>00027 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00028"></a>00028 <span class="preprocessor">#endif</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00030"></a>00030 <span class="comment">                                   Includes</span>
+<a name="l00031"></a>00031 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00032"></a>00032 <span class="preprocessor">#include "sinfo_flat_cfg.h"</span>
+<a name="l00033"></a>00033 
+<a name="l00041"></a>00041 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00042"></a>00042 <span class="comment">                              Function codes</span>
+<a name="l00043"></a>00043 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00052"></a>00052 flat_config * sinfo_flat_cfg_create(<span class="keywordtype">void</span>)
+<a name="l00053"></a>00053 {
+<a name="l00054"></a>00054     <span class="keywordflow">return</span> cpl_calloc(1, <span class="keyword">sizeof</span>(flat_config));
+<a name="l00055"></a>00055 }
+<a name="l00063"></a>00063 <span class="keywordtype">void</span> sinfo_flat_cfg_destroy(flat_config * sc)
+<a name="l00064"></a>00064 {
+<a name="l00065"></a>00065     <span class="keywordflow">if</span> (sc==NULL) return ;
+<a name="l00066"></a>00066 
+<a name="l00067"></a>00067     <span class="comment">/* Free list of frame types */</span>
+<a name="l00068"></a>00068     <span class="comment">/*cpl_free(sc->frametype);*/</span>
+<a name="l00069"></a>00069     <span class="comment">/* Free positions */</span>
+<a name="l00070"></a>00070     <span class="comment">/*cpl_free(sc->frameposition);*/</span>
+<a name="l00071"></a>00071 
+<a name="l00072"></a>00072     <span class="comment">/* Free main struct */</span>
+<a name="l00073"></a>00073     cpl_free(sc);
+<a name="l00074"></a>00074 
+<a name="l00075"></a>00075     return ;
+<a name="l00076"></a>00076 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__flat__cfg_8h_source.html b/html/sinfo__flat__cfg_8h_source.html
new file mode 100644
index 0000000..9f742b9
--- /dev/null
+++ b/html/sinfo__flat__cfg_8h_source.html
@@ -0,0 +1,160 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_flat_cfg.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_flat_cfg.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name     :    sinfo_flat_cfg.h</span>
+<a name="l00022"></a>00022 <span class="comment">   Author         :    Juergen Schreiber</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on    :    march 2002</span>
+<a name="l00024"></a>00024 <span class="comment">   Description    :    flat_ini definitions + handling prototypes</span>
+<a name="l00025"></a>00025 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00026"></a>00026 <span class="preprocessor">#ifndef SINFO_FLAT_CFG_H</span>
+<a name="l00027"></a>00027 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_FLAT_CFG_H</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00029"></a>00029 <span class="comment">                                   Includes</span>
+<a name="l00030"></a>00030 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00031"></a>00031 <span class="preprocessor">#include <stdlib.h></span>
+<a name="l00032"></a>00032 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include "sinfo_globals.h"</span>
+<a name="l00034"></a>00034 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00035"></a>00035 <span class="comment">                                   Defines</span>
+<a name="l00036"></a>00036 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00037"></a>00037 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00038"></a>00038 <span class="comment">                                   New types</span>
+<a name="l00039"></a>00039 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00040"></a>00040 <span class="comment">/*</span>
+<a name="l00041"></a>00041 <span class="comment">  prepare lamp flat fields blackboard container</span>
+<a name="l00042"></a>00042 <span class="comment"></span>
+<a name="l00043"></a>00043 <span class="comment">  This structure holds all information related to the flatfield handling</span>
+<a name="l00044"></a>00044 <span class="comment">  routine. It is used as a container for the flux of ancillary data,</span>
+<a name="l00045"></a>00045 <span class="comment">  computed values, and algorithm status. Pixel flux is separated from</span>
+<a name="l00046"></a>00046 <span class="comment">  the blackboard.</span>
+<a name="l00047"></a>00047 <span class="comment">  */</span>
+<a name="l00048"></a>00048 
+<a name="l00049"></a>00049 <span class="keyword">typedef</span> <span class="keyword">struct </span>flat_config {
+<a name="l00050"></a>00050 <span class="comment">/*-------General---------*/</span>
+<a name="l00051"></a>00051         <span class="keywordtype">char</span> inFile[FILE_NAME_SZ] ; <span class="comment">/* file name of the file containing the </span>
+<a name="l00052"></a>00052 <span class="comment">                                       list of all input frames */</span>
+<a name="l00053"></a>00053         <span class="keywordtype">char</span> outName[FILE_NAME_SZ] ; <span class="comment">/* output name of resulting fits </span>
+<a name="l00054"></a>00054 <span class="comment">                                        wavelength map */</span>
+<a name="l00055"></a>00055         <span class="keywordtype">char</span> ** framelist ; <span class="comment">/* list of frames */</span>
+<a name="l00056"></a>00056         <span class="keywordtype">int</span>  * frametype ; <span class="comment">/* list of frame types on or off */</span>
+<a name="l00057"></a>00057         <span class="keywordtype">int</span>  * frameposition ; <span class="comment">/* list of grating positions */</span>  
+<a name="l00058"></a>00058         <span class="keywordtype">int</span>    contains_sky ; <span class="comment">/* indicates if off or sky frames were exposed */</span>
+<a name="l00059"></a>00059      <span class="keywordtype">int</span>    contains_dither ; <span class="comment">/* indicates if spectral dithering was applied */</span>
+<a name="l00060"></a>00060         <span class="keywordtype">int</span>    nframes ; <span class="comment">/* number of frames in frame list */</span>
+<a name="l00061"></a>00061         <span class="keywordtype">int</span>    nobj ;  <span class="comment">/* number of object frames in frame list */</span>
+<a name="l00062"></a>00062         <span class="keywordtype">int</span>    noff ;  <span class="comment">/* number of off frames in frame list */</span>
+<a name="l00063"></a>00063      <span class="keywordtype">int</span>    nditherobj ; <span class="comment">/* number of dithered object frames in frame list */</span>
+<a name="l00064"></a>00064         <span class="keywordtype">int</span>    nditheroff ; <span class="comment">/* number of dithered off frames in frame list */</span>
+<a name="l00065"></a>00065 <span class="comment">/*------ CleanMean ------*/</span>
+<a name="l00066"></a>00066         <span class="comment">/* percentage of rejected low intensity pixels */</span>
+<a name="l00067"></a>00067         <span class="keywordtype">float</span> loReject ;      
+<a name="l00068"></a>00068         <span class="comment">/* percentage of rejected high intensity pixels */</span>
+<a name="l00069"></a>00069         <span class="keywordtype">float</span> hiReject ;
+<a name="l00070"></a>00070 <span class="comment">/*------ BadPixel ------*/</span>
+<a name="l00071"></a>00071         <span class="comment">/* indicator if the bad pixels of the flat field are known and </span>
+<a name="l00072"></a>00072 <span class="comment">           if they should be interpolated or not */</span>
+<a name="l00073"></a>00073         <span class="keywordtype">int</span> interpolInd ;
+<a name="l00074"></a>00074         <span class="comment">/* file name of the bad pixel mask fits file */</span>
+<a name="l00075"></a>00075         <span class="keywordtype">char</span> mask[FILE_NAME_SZ] ;
+<a name="l00076"></a>00076         <span class="comment">/* maximal pixel distance from the bad pixel to which valid </span>
+<a name="l00077"></a>00077 <span class="comment">           pixels are searched for*/</span> 
+<a name="l00078"></a>00078         <span class="keywordtype">int</span> maxRad ;
+<a name="l00079"></a>00079         <span class="comment">/* file name of the slitlet sinfo_edge position list */</span>
+<a name="l00080"></a>00080         <span class="keywordtype">char</span> slitposList[FILE_NAME_SZ] ;
+<a name="l00081"></a>00081 <span class="comment">/*------ BadPix ------*/</span>
+<a name="l00082"></a>00082         <span class="comment">/* indicator if a bad pixel mask should be generated or not */</span>
+<a name="l00083"></a>00083         <span class="keywordtype">int</span> badInd ;
+<a name="l00084"></a>00084         <span class="comment">/* name of the static bad pixel mask to be generated */</span>
+<a name="l00085"></a>00085         <span class="keywordtype">char</span> maskname[FILE_NAME_SZ] ;
+<a name="l00086"></a>00086         <span class="comment">/* factor of noise within which the pixels are used to fit a </span>
+<a name="l00087"></a>00087 <span class="comment">           straight line to the column intensity */</span>
+<a name="l00088"></a>00088         <span class="keywordtype">float</span> sigmaFactor ;
+<a name="l00089"></a>00089         <span class="comment">/* factor of calculated standard deviation beyond which the </span>
+<a name="l00090"></a>00090 <span class="comment">           deviation of a pixel value from the</span>
+<a name="l00091"></a>00091 <span class="comment">           median of the 8 nearest neighbors declares a pixel as bad */</span>
+<a name="l00092"></a>00092         <span class="keywordtype">float</span> factor ;
+<a name="l00093"></a>00093         <span class="comment">/* number of iterations of sinfo_median filter */</span>
+<a name="l00094"></a>00094         <span class="keywordtype">int</span> iterations ;
+<a name="l00095"></a>00095         <span class="comment">/* percentage of extreme pixel value to reject when calculating </span>
+<a name="l00096"></a>00096 <span class="comment">           the mean and stdev */</span>
+<a name="l00097"></a>00097         <span class="keywordtype">float</span> badLoReject ;
+<a name="l00098"></a>00098         <span class="keywordtype">float</span> badHiReject ;
+<a name="l00099"></a>00099         <span class="comment">/* pixel coordinate of lower left edge of a rectangle zone </span>
+<a name="l00100"></a>00100 <span class="comment">           from which image statistics are computed */</span>
+<a name="l00101"></a>00101         <span class="keywordtype">int</span> llx ;
+<a name="l00102"></a>00102         <span class="keywordtype">int</span> lly ;
+<a name="l00103"></a>00103         <span class="comment">/* pixel coordinate of upper right edge of a rectangle zone from </span>
+<a name="l00104"></a>00104 <span class="comment">           which image statistics are computed */</span>
+<a name="l00105"></a>00105         <span class="keywordtype">int</span> urx ;
+<a name="l00106"></a>00106         <span class="keywordtype">int</span> ury ;
+<a name="l00107"></a>00107 <span class="comment">/*------ Thresh ------*/</span>
+<a name="l00108"></a>00108         <span class="comment">/* indicates if the values beyond threshold values should be </span>
+<a name="l00109"></a>00109 <span class="comment">           marked as bad before proceeding</span>
+<a name="l00110"></a>00110 <span class="comment">           to sinfo_median filtering */</span>
+<a name="l00111"></a>00111         <span class="keywordtype">int</span> threshInd ;
+<a name="l00112"></a>00112         <span class="comment">/* factor to the clean standard deviation to define the </span>
+<a name="l00113"></a>00113 <span class="comment">           threshold deviation from the clean mean */</span>
+<a name="l00114"></a>00114         <span class="keywordtype">float</span> meanfactor ;
+<a name="l00115"></a>00115 
+<a name="l00116"></a>00116 
+<a name="l00117"></a>00117   <span class="comment">/* QC LOG */</span>
+<a name="l00118"></a>00118 
+<a name="l00119"></a>00119   <span class="comment">/* FPN */</span>
+<a name="l00120"></a>00120   <span class="keywordtype">int</span> qc_fpn_xmin1;
+<a name="l00121"></a>00121   <span class="keywordtype">int</span> qc_fpn_xmax1;
+<a name="l00122"></a>00122   <span class="keywordtype">int</span> qc_fpn_ymin1;
+<a name="l00123"></a>00123   <span class="keywordtype">int</span> qc_fpn_ymax1;
+<a name="l00124"></a>00124 
+<a name="l00125"></a>00125   <span class="keywordtype">int</span> qc_fpn_xmin2;
+<a name="l00126"></a>00126   <span class="keywordtype">int</span> qc_fpn_xmax2;
+<a name="l00127"></a>00127   <span class="keywordtype">int</span> qc_fpn_ymin2;
+<a name="l00128"></a>00128   <span class="keywordtype">int</span> qc_fpn_ymax2;
+<a name="l00129"></a>00129 
+<a name="l00130"></a>00130   <span class="keywordtype">int</span> qc_thresh_min;
+<a name="l00131"></a>00131   <span class="keywordtype">int</span> qc_thresh_max;
+<a name="l00132"></a>00132 
+<a name="l00133"></a>00133 
+<a name="l00134"></a>00134 } flat_config ;
+<a name="l00135"></a>00135  
+<a name="l00136"></a>00136 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00137"></a>00137 <span class="comment">                               Function prototypes</span>
+<a name="l00138"></a>00138 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00146"></a>00146 flat_config * 
+<a name="l00147"></a>00147 sinfo_flat_cfg_create(<span class="keywordtype">void</span>);
+<a name="l00155"></a>00155 <span class="keywordtype">void</span> 
+<a name="l00156"></a>00156 sinfo_flat_cfg_destroy(flat_config * sc);
+<a name="l00157"></a>00157 
+<a name="l00158"></a>00158 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__flat__ini_8c_source.html b/html/sinfo__flat__ini_8c_source.html
new file mode 100644
index 0000000..2dd3e7b
--- /dev/null
+++ b/html/sinfo__flat__ini_8c_source.html
@@ -0,0 +1,562 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_flat_ini.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_flat_ini.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name    :   flat_ini.c</span>
+<a name="l00022"></a>00022 <span class="comment">   Author       :   Juergen Schreiber</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on   :    Mar 04, 2002</span>
+<a name="l00024"></a>00024 <span class="comment">   Description  :    prepare flatfield frames ini file handling for SPIFFI</span>
+<a name="l00025"></a>00025 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00026"></a>00026 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00027"></a>00027 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00028"></a>00028 <span class="preprocessor">#endif</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00030"></a>00030 <span class="comment">                                Includes</span>
+<a name="l00031"></a>00031 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00032"></a>00032 <span class="preprocessor">#include "sinfo_flat_ini.h"</span>
+<a name="l00033"></a>00033 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00034"></a>00034 <span class="comment">                    Functions private to this module</span>
+<a name="l00035"></a>00035 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00036"></a>00036 <span class="keyword">static</span> <span class="keywordtype">void</span>     parse_section_general(dictionary *, flat_config *, <span class="keywordtype">int</span> *);
+<a name="l00037"></a>00037 <span class="keyword">static</span> <span class="keywordtype">void</span>     parse_section_frames(dictionary *, flat_config *, <span class="keywordtype">int</span> *);
+<a name="l00038"></a>00038 <span class="keyword">static</span> <span class="keywordtype">void</span>     parse_section_cleanmean(dictionary *, flat_config *, <span class="keywordtype">int</span> *);
+<a name="l00039"></a>00039 <span class="keyword">static</span> <span class="keywordtype">void</span>     parse_section_badpixel(dictionary *, flat_config *, <span class="keywordtype">int</span> *);
+<a name="l00040"></a>00040 <span class="keyword">static</span> <span class="keywordtype">void</span>     parse_section_badpix(dictionary *, flat_config *, <span class="keywordtype">int</span> *);
+<a name="l00041"></a>00041 <span class="keyword">static</span> <span class="keywordtype">void</span>     parse_section_thresh(dictionary *, flat_config *, <span class="keywordtype">int</span> *);
+<a name="l00060"></a>00060 flat_config * 
+<a name="l00061"></a>00061 parse_flat_ini_file(<span class="keywordtype">char</span> * ini_name)
+<a name="l00062"></a>00062 {
+<a name="l00063"></a>00063         dictionary    *       sym ;
+<a name="l00064"></a>00064         flat_config   *       cfg ;
+<a name="l00065"></a>00065         <span class="keywordtype">int</span>                   status ;
+<a name="l00066"></a>00066 
+<a name="l00067"></a>00067         <span class="keywordflow">if</span> (!sinfo_file_exists(ini_name)) {
+<a name="l00068"></a>00068            <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"cannot find ini file [%s]: aborting"</span>, ini_name) ;
+<a name="l00069"></a>00069                 <span class="keywordflow">return</span> NULL ;
+<a name="l00070"></a>00070         }
+<a name="l00071"></a>00071         sym = iniparser_load(ini_name) ;
+<a name="l00072"></a>00072         <span class="keywordflow">if</span> (sym == NULL) {
+<a name="l00073"></a>00073            <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"in parsing ini file [%s]: aborting"</span>, ini_name) ;
+<a name="l00074"></a>00074            <span class="keywordflow">return</span> NULL ;
+<a name="l00075"></a>00075         }
+<a name="l00076"></a>00076 
+<a name="l00077"></a>00077         cfg = sinfo_flat_cfg_create();
+<a name="l00078"></a>00078         <span class="keywordflow">if</span> (cfg==NULL) {
+<a name="l00079"></a>00079            <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"allocating flat_config struct"</span>);
+<a name="l00080"></a>00080                 iniparser_freedict(sym) ;
+<a name="l00081"></a>00081                 <span class="keywordflow">return</span> NULL ;
+<a name="l00082"></a>00082         }
+<a name="l00083"></a>00083 
+<a name="l00084"></a>00084         <span class="comment">/*</span>
+<a name="l00085"></a>00085 <span class="comment">         * Perform sanity checks, fill up the structure with what was</span>
+<a name="l00086"></a>00086 <span class="comment">         * found in the ini file</span>
+<a name="l00087"></a>00087 <span class="comment">         */</span>
+<a name="l00088"></a>00088 
+<a name="l00089"></a>00089         status = 0 ;
+<a name="l00090"></a>00090         parse_section_general   (sym, cfg, &status);
+<a name="l00091"></a>00091         parse_section_frames    (sym, cfg, &status);
+<a name="l00092"></a>00092         parse_section_cleanmean (sym, cfg, &status);
+<a name="l00093"></a>00093         parse_section_badpixel  (sym, cfg, &status); 
+<a name="l00094"></a>00094         parse_section_badpix    (sym, cfg, &status); 
+<a name="l00095"></a>00095         parse_section_thresh    (sym, cfg, &status); 
+<a name="l00096"></a>00096 
+<a name="l00097"></a>00097         iniparser_freedict(sym);
+<a name="l00098"></a>00098 
+<a name="l00099"></a>00099         <span class="keywordflow">if</span> (status>0) {
+<a name="l00100"></a>00100           <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"%d errors in ini file [%s]"</span>, status, ini_name);
+<a name="l00101"></a>00101                 sinfo_flat_cfg_destroy(cfg);
+<a name="l00102"></a>00102                 cfg = NULL ;
+<a name="l00103"></a>00103                 <span class="keywordflow">return</span> NULL ;
+<a name="l00104"></a>00104         }
+<a name="l00105"></a>00105         <span class="keywordflow">return</span> cfg ;
+<a name="l00106"></a>00106 }
+<a name="l00107"></a>00107 
+<a name="l00108"></a>00108 
+<a name="l00109"></a>00109 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00110"></a>00110 <span class="comment">   Functions:   parse_section_xxx()</span>
+<a name="l00111"></a>00111 <span class="comment">   In           :       symbolic table read from ini file</span>
+<a name="l00112"></a>00112 <span class="comment">   Out          :       void</span>
+<a name="l00113"></a>00113 <span class="comment">   Job          :       update a flat_config structure from what can be</span>
+<a name="l00114"></a>00114 <span class="comment">                            found in the ini file.</span>
+<a name="l00115"></a>00115 <span class="comment">   Notice       :       all of these functions update a status integer to</span>
+<a name="l00116"></a>00116 <span class="comment">                        indicate if an error occurred, or leave it as it is if</span>
+<a name="l00117"></a>00117 <span class="comment">                        everything went Ok.</span>
+<a name="l00118"></a>00118 <span class="comment"></span>
+<a name="l00119"></a>00119 <span class="comment">        parse_section_general()</span>
+<a name="l00120"></a>00120 <span class="comment">        parse_section_frames ()</span>
+<a name="l00121"></a>00121 <span class="comment">        parse_section_cleanmean ()</span>
+<a name="l00122"></a>00122 <span class="comment">        parse_section_badpixel  () </span>
+<a name="l00123"></a>00123 <span class="comment">        parse_section_badpix ()</span>
+<a name="l00124"></a>00124 <span class="comment">        parse_section_thresh ()</span>
+<a name="l00125"></a>00125 <span class="comment"></span>
+<a name="l00126"></a>00126 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00127"></a>00127 
+<a name="l00128"></a>00128 
+<a name="l00129"></a>00129 <span class="keyword">static</span> <span class="keywordtype">void</span>     parse_section_general(
+<a name="l00130"></a>00130         dictionary * sym,
+<a name="l00131"></a>00131         flat_config * cfg,
+<a name="l00132"></a>00132         <span class="keywordtype">int</span> *status
+<a name="l00133"></a>00133 )
+<a name="l00134"></a>00134 {
+<a name="l00135"></a>00135         <span class="keywordtype">char</span>    *       cval ;
+<a name="l00136"></a>00136         <span class="keywordtype">int</span>             ival ;
+<a name="l00137"></a>00137 
+<a name="l00138"></a>00138         <span class="comment">/*</span>
+<a name="l00139"></a>00139 <span class="comment">         * General section</span>
+<a name="l00140"></a>00140 <span class="comment">         */</span>
+<a name="l00141"></a>00141         cval = iniparser_getstr(sym, <span class="stringliteral">"eclipse:versionnumber"</span>) ;
+<a name="l00142"></a>00142         <span class="keywordflow">if</span> (cval!=NULL) {
+<a name="l00143"></a>00143            <span class="keywordflow">if</span> (strcmp(cval, get_eclipse_version())) {
+<a name="l00144"></a>00144               <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"this ini file produced by version %s"</span>, cval);
+<a name="l00145"></a>00145               <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"you are running version %s"</span>, 
+<a name="l00146"></a>00146                                 get_eclipse_version());
+<a name="l00147"></a>00147                 }
+<a name="l00148"></a>00148         } <span class="keywordflow">else</span> {
+<a name="l00149"></a>00149               <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"no eclipse version number found in file"</span>);
+<a name="l00150"></a>00150         }
+<a name="l00151"></a>00151 
+<a name="l00152"></a>00152         ival = iniparser_getint(sym, <span class="stringliteral">"general:maximummemory"</span>, -1);
+<a name="l00153"></a>00153         <span class="keywordflow">if</span> (ival>0) sinfo_set_memory_parameter(<span class="stringliteral">"max_ram"</span>, ival);
+<a name="l00154"></a>00154         ival = iniparser_getint(sym, <span class="stringliteral">"general:maximumswap"</span>, -1);
+<a name="l00155"></a>00155         <span class="keywordflow">if</span> (ival>0) sinfo_set_memory_parameter(<span class="stringliteral">"max_swap"</span>, ival);
+<a name="l00156"></a>00156         sinfo_set_verbose(iniparser_getboolean(sym, <span class="stringliteral">"general:verbose"</span>, 0));
+<a name="l00157"></a>00157         sinfo_set_debug(iniparser_getboolean(sym, <span class="stringliteral">"general:debug"</span>, 0));
+<a name="l00158"></a>00158 
+<a name="l00159"></a>00159         cval = iniparser_getstr(sym, <span class="stringliteral">"general:tmpdirname"</span>);
+<a name="l00160"></a>00160         <span class="keywordflow">if</span> (cval!=NULL) {
+<a name="l00161"></a>00161                 sinfo_set_tmpdirname(cval);
+<a name="l00162"></a>00162         } <span class="keywordflow">else</span> {
+<a name="l00163"></a>00163                 sinfo_set_tmpdirname(<span class="stringliteral">"."</span>);
+<a name="l00164"></a>00164         }
+<a name="l00165"></a>00165 
+<a name="l00166"></a>00166         ival = iniparser_getboolean(sym, <span class="stringliteral">"general:logfile"</span>, 0);
+<a name="l00167"></a>00167         <span class="keywordflow">if</span> (ival) {
+<a name="l00168"></a>00168                 cval = iniparser_getstr(sym, <span class="stringliteral">"general:logfilename"</span>);
+<a name="l00169"></a>00169                 <span class="keywordflow">if</span> (cval!=NULL) {
+<a name="l00170"></a>00170                         sinfo_set_logfile(1);
+<a name="l00171"></a>00171                         sinfo_set_logfilename(cval);
+<a name="l00172"></a>00172                 } <span class="keywordflow">else</span> {
+<a name="l00173"></a>00173                         sinfo_set_logfile(0) ;
+<a name="l00174"></a>00174                 }
+<a name="l00175"></a>00175         }
+<a name="l00176"></a>00176         cval = iniparser_getstr(sym, <span class="stringliteral">"general:outname"</span>);
+<a name="l00177"></a>00177         <span class="keywordflow">if</span> (cval!=NULL) {
+<a name="l00178"></a>00178                 strcpy (cfg -> outName , cval ) ;
+<a name="l00179"></a>00179         } <span class="keywordflow">else</span> {
+<a name="l00180"></a>00180             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" OutName in the .ini file was not found!\n"</span>) ;
+<a name="l00181"></a>00181             (*status)++ ;
+<a name="l00182"></a>00182         }
+<a name="l00183"></a>00183 
+<a name="l00184"></a>00184         <span class="keywordflow">if</span> (sinfo_verbose_active())
+<a name="l00185"></a>00185                 sinfo_print_memory_parameters();
+<a name="l00186"></a>00186         return ;
+<a name="l00187"></a>00187 }
+<a name="l00188"></a>00188 
+<a name="l00189"></a>00189 <span class="keyword">static</span> <span class="keywordtype">void</span>     parse_section_frames(
+<a name="l00190"></a>00190         dictionary * sym,
+<a name="l00191"></a>00191         flat_config * cfg,
+<a name="l00192"></a>00192         <span class="keywordtype">int</span> *status
+<a name="l00193"></a>00193 )
+<a name="l00194"></a>00194 {
+<a name="l00195"></a>00195         <span class="keywordtype">char</span>            *       listname ;
+<a name="l00196"></a>00196         charmatrix      *       charm ;
+<a name="l00197"></a>00197         <span class="keywordtype">int</span>                     i, j ;
+<a name="l00198"></a>00198         <span class="keywordtype">char</span>            *       name,
+<a name="l00199"></a>00199                         *       type ;
+<a name="l00200"></a>00200         <span class="keywordtype">int</span>                     nval, nobj, noff ;
+<a name="l00201"></a>00201         <span class="keywordtype">int</span>                     nditherobj, nditheroff ;
+<a name="l00202"></a>00202         <span class="keywordtype">int</span>                     found_sky ;
+<a name="l00203"></a>00203         <span class="keywordtype">int</span>                     found_dither ;
+<a name="l00204"></a>00204         <span class="keywordtype">char</span>            **      framelist ;
+<a name="l00205"></a>00205         <span class="keywordtype">int</span>             *       frametypes ;
+<a name="l00206"></a>00206         <span class="keywordtype">int</span>             *       frameposition ;
+<a name="l00207"></a>00207 
+<a name="l00208"></a>00208         listname = iniparser_getstr(sym, <span class="stringliteral">"general:infile"</span>);
+<a name="l00209"></a>00209         <span class="keywordflow">if</span> (sinfo_is_ascii_list(listname)!=1) {
+<a name="l00210"></a>00210            <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"file [%s] is not an ASCII list: aborting"</span>,listname);
+<a name="l00211"></a>00211            (*status)++ ;
+<a name="l00212"></a>00212            return ;
+<a name="l00213"></a>00213         }
+<a name="l00214"></a>00214 
+<a name="l00215"></a>00215         <span class="comment">/* Read input char sinfo_matrix */</span>
+<a name="l00216"></a>00216         charm = sinfo_charmatrix_read(listname);
+<a name="l00217"></a>00217         <span class="keywordflow">if</span> (charm==NULL) {
+<a name="l00218"></a>00218            <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"parsing input list [%s]"</span>, listname);
+<a name="l00219"></a>00219            (*status)++;
+<a name="l00220"></a>00220            return ;
+<a name="l00221"></a>00221         }
+<a name="l00222"></a>00222 
+<a name="l00223"></a>00223         <span class="comment">/* Check input sinfo_matrix */</span>
+<a name="l00224"></a>00224         nval = charm->ly ;
+<a name="l00225"></a>00225         <span class="keywordflow">for</span> (j=0 ; j<charm->ly ; j++) {
+<a name="l00226"></a>00226            <span class="comment">/* Check file existence */</span>
+<a name="l00227"></a>00227            name = charmatrix_elem(charm, 0, j);
+<a name="l00228"></a>00228            <span class="keywordflow">if</span> (sinfo_file_exists(name)!=1) {
+<a name="l00229"></a>00229               <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"file [%s] declared in list does not exist"</span>, 
+<a name="l00230"></a>00230                                 name);
+<a name="l00231"></a>00231               nval -- ;
+<a name="l00232"></a>00232            }
+<a name="l00233"></a>00233         }
+<a name="l00234"></a>00234         <span class="keywordflow">if</span> (nval<1) {
+<a name="l00235"></a>00235            <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no valid plane found in list [%s]"</span>, listname);
+<a name="l00236"></a>00236            sinfo_charmatrix_del(charm);
+<a name="l00237"></a>00237            (*status)++ ;
+<a name="l00238"></a>00238            return ;
+<a name="l00239"></a>00239         }
+<a name="l00240"></a>00240 
+<a name="l00241"></a>00241         <span class="comment">/* Allocate structures to go into the blackboard */</span>
+<a name="l00242"></a>00242         framelist     = cpl_malloc(nval * <span class="keyword">sizeof</span>(<span class="keywordtype">char</span>*));
+<a name="l00243"></a>00243         frametypes    = cpl_malloc(nval * <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>));
+<a name="l00244"></a>00244         frameposition = cpl_malloc(nval * <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>));
+<a name="l00245"></a>00245 
+<a name="l00246"></a>00246         found_sky     = 0 ;
+<a name="l00247"></a>00247         found_dither  = 0 ;
+<a name="l00248"></a>00248         nobj          = 0 ;
+<a name="l00249"></a>00249         noff          = 0 ;
+<a name="l00250"></a>00250         nditheroff    = 0 ;
+<a name="l00251"></a>00251         nditherobj    = 0 ;
+<a name="l00252"></a>00252 
+<a name="l00253"></a>00253         <span class="comment">/* Browse through the charmatrix to get names and file types */</span>
+<a name="l00254"></a>00254         i = 0 ;
+<a name="l00255"></a>00255         <span class="keywordflow">for</span> (j=0 ; j<charm->ly ; j++) 
+<a name="l00256"></a>00256         {
+<a name="l00257"></a>00257            name = charmatrix_elem(charm, 0, j);
+<a name="l00258"></a>00258            <span class="keywordflow">if</span> (sinfo_file_exists(name)==1) 
+<a name="l00259"></a>00259            {
+<a name="l00260"></a>00260               <span class="comment">/* Store file name into framelist */</span>
+<a name="l00261"></a>00261               framelist[i] = cpl_strdup(name);
+<a name="l00262"></a>00262               <span class="comment">/* Check if a file type is present */</span>
+<a name="l00263"></a>00263               <span class="keywordflow">if</span> (charm->lx>1) 
+<a name="l00264"></a>00264               {
+<a name="l00265"></a>00265                  <span class="comment">/* Get file type */</span>
+<a name="l00266"></a>00266                  type = charmatrix_elem(charm, 1, j);
+<a name="l00267"></a>00267                  strlwc(type);
+<a name="l00268"></a>00268                  <span class="comment">/* Checking if the type contains 'off' or 'sky' */</span>
+<a name="l00269"></a>00269                  <span class="keywordflow">if</span> (strstr(type, <span class="stringliteral">"sky"</span>)!=NULL || strstr(type, <span class="stringliteral">"off"</span>) != NULL) 
+<a name="l00270"></a>00270                  {
+<a name="l00271"></a>00271                      frametypes[i] = FRAME_OFF ;
+<a name="l00272"></a>00272                      found_sky = 1 ;
+<a name="l00273"></a>00273                      <span class="comment">/* Checking if the type contains 'pos1' or 'pos2' */</span>
+<a name="l00274"></a>00274                      <span class="keywordflow">if</span> (strstr(type, <span class="stringliteral">"2"</span>)!=NULL) 
+<a name="l00275"></a>00275                      {
+<a name="l00276"></a>00276                         frameposition[i] = FRAME_POS2 ;
+<a name="l00277"></a>00277                         found_dither = 1 ;
+<a name="l00278"></a>00278                         nditheroff++ ;
+<a name="l00279"></a>00279                      }
+<a name="l00280"></a>00280                      <span class="keywordflow">else</span> 
+<a name="l00281"></a>00281                      {
+<a name="l00282"></a>00282                         frameposition[i] = FRAME_POS1 ;
+<a name="l00283"></a>00283                         noff++ ;
+<a name="l00284"></a>00284                      }
+<a name="l00285"></a>00285 
+<a name="l00286"></a>00286                   }
+<a name="l00287"></a>00287                   <span class="keywordflow">else</span>  
+<a name="l00288"></a>00288                   {
+<a name="l00289"></a>00289                      frametypes[i] = FRAME_ON ;
+<a name="l00290"></a>00290                      <span class="comment">/* Checking if the type contains 'pos1' or 'pos2' */</span>
+<a name="l00291"></a>00291                      <span class="keywordflow">if</span> (strstr(type, <span class="stringliteral">"2"</span>)!=NULL) 
+<a name="l00292"></a>00292                      {
+<a name="l00293"></a>00293                         frameposition[i] = FRAME_POS2 ;
+<a name="l00294"></a>00294                         found_dither = 1 ;
+<a name="l00295"></a>00295                         nditherobj++ ;
+<a name="l00296"></a>00296                      } 
+<a name="l00297"></a>00297                      <span class="keywordflow">else</span> 
+<a name="l00298"></a>00298                      {
+<a name="l00299"></a>00299                         frameposition[i] = FRAME_POS1 ;
+<a name="l00300"></a>00300                         nobj++ ;
+<a name="l00301"></a>00301                      }
+<a name="l00302"></a>00302                    }
+<a name="l00303"></a>00303                 } 
+<a name="l00304"></a>00304                 <span class="keywordflow">else</span> 
+<a name="l00305"></a>00305                 {
+<a name="l00306"></a>00306                    <span class="comment">/* No type means an object */</span>
+<a name="l00307"></a>00307                    frametypes[i] = FRAME_ON ;
+<a name="l00308"></a>00308                    <span class="comment">/* No type means position 1 */</span>
+<a name="l00309"></a>00309                    frameposition[i] = FRAME_POS1 ;
+<a name="l00310"></a>00310                    nobj ++ ;
+<a name="l00311"></a>00311                 }
+<a name="l00312"></a>00312                 i++ ;
+<a name="l00313"></a>00313             }
+<a name="l00314"></a>00314         }
+<a name="l00315"></a>00315         sinfo_charmatrix_del(charm);
+<a name="l00316"></a>00316 
+<a name="l00317"></a>00317         <span class="comment">/* Copy relevant information into the blackboard */</span>
+<a name="l00318"></a>00318         cfg->framelist       = framelist ;
+<a name="l00319"></a>00319         cfg->frametype       = frametypes ;
+<a name="l00320"></a>00320         cfg->frameposition   = frameposition ;
+<a name="l00321"></a>00321         cfg->nframes         = nval ;
+<a name="l00322"></a>00322         cfg->nobj            = nobj ;
+<a name="l00323"></a>00323         cfg->noff            = noff ;
+<a name="l00324"></a>00324         cfg->nditherobj      = nditherobj ;
+<a name="l00325"></a>00325         cfg->nditheroff      = nditheroff ;
+<a name="l00326"></a>00326         cfg->contains_sky    = found_sky ;
+<a name="l00327"></a>00327         cfg->contains_dither = found_dither ;
+<a name="l00328"></a>00328 
+<a name="l00329"></a>00329         return ;
+<a name="l00330"></a>00330 }
+<a name="l00331"></a>00331 
+<a name="l00332"></a>00332 <span class="keyword">static</span> <span class="keywordtype">void</span>     parse_section_cleanmean(
+<a name="l00333"></a>00333         dictionary * sym,
+<a name="l00334"></a>00334         flat_config * cfg,
+<a name="l00335"></a>00335         <span class="keywordtype">int</span> *status )
+<a name="l00336"></a>00336 {
+<a name="l00337"></a>00337         <span class="keywordtype">float</span>           dval ;
+<a name="l00338"></a>00338 
+<a name="l00339"></a>00339         dval = iniparser_getdouble(sym, <span class="stringliteral">"cleanmean:loreject"</span>, -1.) ;
+<a name="l00340"></a>00340         <span class="keywordflow">if</span> (dval!=-1.) 
+<a name="l00341"></a>00341         {
+<a name="l00342"></a>00342             cfg -> loReject = dval ; 
+<a name="l00343"></a>00343         }
+<a name="l00344"></a>00344         <span class="keywordflow">else</span> 
+<a name="l00345"></a>00345         {
+<a name="l00346"></a>00346             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" LoReject in the .ini file was not found!\n"</span>) ;
+<a name="l00347"></a>00347             (*status)++ ;
+<a name="l00348"></a>00348         }
+<a name="l00349"></a>00349         dval = iniparser_getdouble(sym, <span class="stringliteral">"cleanmean:hireject"</span>, -1.) ;
+<a name="l00350"></a>00350         <span class="keywordflow">if</span> (dval!=-1.) 
+<a name="l00351"></a>00351         {
+<a name="l00352"></a>00352             cfg -> hiReject = dval ; 
+<a name="l00353"></a>00353         }
+<a name="l00354"></a>00354         <span class="keywordflow">else</span> 
+<a name="l00355"></a>00355         {
+<a name="l00356"></a>00356             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" hiReject in the .ini file was not found!\n"</span>) ;
+<a name="l00357"></a>00357             (*status)++ ;
+<a name="l00358"></a>00358         }
+<a name="l00359"></a>00359         return ;
+<a name="l00360"></a>00360 }
+<a name="l00361"></a>00361 
+<a name="l00362"></a>00362 <span class="keyword">static</span> <span class="keywordtype">void</span>     parse_section_badpixel(
+<a name="l00363"></a>00363         dictionary * sym,
+<a name="l00364"></a>00364         flat_config * cfg,
+<a name="l00365"></a>00365         <span class="keywordtype">int</span> *status )
+<a name="l00366"></a>00366 {
+<a name="l00367"></a>00367         <span class="keywordtype">int</span>             ival ;
+<a name="l00368"></a>00368         <span class="keywordtype">char</span>        *   cval ;
+<a name="l00369"></a>00369 
+<a name="l00370"></a>00370         ival = iniparser_getboolean(sym, <span class="stringliteral">"badpixel:interpolind"</span>, -1) ;
+<a name="l00371"></a>00371         <span class="keywordflow">if</span> (ival != -1)
+<a name="l00372"></a>00372         {
+<a name="l00373"></a>00373             cfg -> interpolInd = ival ;
+<a name="l00374"></a>00374         }
+<a name="l00375"></a>00375         <span class="keywordflow">else</span>
+<a name="l00376"></a>00376         {
+<a name="l00377"></a>00377             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" interpolInd in the .ini file was not found!\n"</span>) ;
+<a name="l00378"></a>00378             (*status)++ ;
+<a name="l00379"></a>00379         }
+<a name="l00380"></a>00380         cval = iniparser_getstr(sym, <span class="stringliteral">"badpixel:mask"</span>) ;
+<a name="l00381"></a>00381         <span class="keywordflow">if</span> (cval != NULL) 
+<a name="l00382"></a>00382         {
+<a name="l00383"></a>00383             strcpy (cfg -> mask , cval)  ;
+<a name="l00384"></a>00384         }
+<a name="l00385"></a>00385         <span class="keywordflow">else</span>
+<a name="l00386"></a>00386         {
+<a name="l00387"></a>00387             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" mask in the .ini file was not found!\n"</span>) ;
+<a name="l00388"></a>00388             (*status)++ ;
+<a name="l00389"></a>00389         }
+<a name="l00390"></a>00390         ival = iniparser_getint(sym, <span class="stringliteral">"badpixel:maxrad"</span>, -1) ;
+<a name="l00391"></a>00391         <span class="keywordflow">if</span> (ival!=-1) 
+<a name="l00392"></a>00392         {
+<a name="l00393"></a>00393             cfg -> maxRad = ival ; 
+<a name="l00394"></a>00394         }
+<a name="l00395"></a>00395         <span class="keywordflow">else</span> 
+<a name="l00396"></a>00396         {
+<a name="l00397"></a>00397             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" MaxRad in the .ini file was not found!\n"</span>) ;
+<a name="l00398"></a>00398             (*status)++ ;
+<a name="l00399"></a>00399         }
+<a name="l00400"></a>00400         cval = iniparser_getstr(sym, <span class="stringliteral">"badpixel:slitposlist"</span>) ;
+<a name="l00401"></a>00401         <span class="keywordflow">if</span> (cval != NULL) 
+<a name="l00402"></a>00402         {
+<a name="l00403"></a>00403             strcpy (cfg -> slitposList , cval) ;
+<a name="l00404"></a>00404         }
+<a name="l00405"></a>00405         <span class="keywordflow">else</span>
+<a name="l00406"></a>00406         {
+<a name="l00407"></a>00407             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" SlitposList in the .ini file was not found!\n"</span>) ;
+<a name="l00408"></a>00408             (*status)++ ;
+<a name="l00409"></a>00409         }
+<a name="l00410"></a>00410 }
+<a name="l00411"></a>00411 
+<a name="l00412"></a>00412 <span class="keyword">static</span> <span class="keywordtype">void</span>     parse_section_badpix(
+<a name="l00413"></a>00413         dictionary * sym,
+<a name="l00414"></a>00414         flat_config * cfg,
+<a name="l00415"></a>00415         <span class="keywordtype">int</span> *status )
+<a name="l00416"></a>00416 {
+<a name="l00417"></a>00417         <span class="keywordtype">int</span>             ival ;
+<a name="l00418"></a>00418         <span class="keywordtype">float</span>           dval ;
+<a name="l00419"></a>00419         <span class="keywordtype">char</span>       *    cval ;
+<a name="l00420"></a>00420 
+<a name="l00421"></a>00421         ival = iniparser_getboolean(sym, <span class="stringliteral">"badpix:badind"</span>, -1) ;
+<a name="l00422"></a>00422         <span class="keywordflow">if</span> (ival != -1)
+<a name="l00423"></a>00423         {
+<a name="l00424"></a>00424             cfg -> badInd = ival ;
+<a name="l00425"></a>00425         }
+<a name="l00426"></a>00426         <span class="keywordflow">else</span>
+<a name="l00427"></a>00427         {
+<a name="l00428"></a>00428             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" badInd in the .ini file was not found!\n"</span>) ;
+<a name="l00429"></a>00429             (*status)++ ;
+<a name="l00430"></a>00430         }
+<a name="l00431"></a>00431         cval = iniparser_getstr(sym, <span class="stringliteral">"badpix:maskname"</span>) ;
+<a name="l00432"></a>00432         <span class="keywordflow">if</span> (cval != NULL) 
+<a name="l00433"></a>00433         {
+<a name="l00434"></a>00434             strcpy (cfg -> maskname , cval) ;
+<a name="l00435"></a>00435         }
+<a name="l00436"></a>00436         <span class="keywordflow">else</span>
+<a name="l00437"></a>00437         {
+<a name="l00438"></a>00438             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" mask in the .ini file was not found!\n"</span>) ;
+<a name="l00439"></a>00439             (*status)++ ;
+<a name="l00440"></a>00440         }
+<a name="l00441"></a>00441         dval = iniparser_getdouble(sym, <span class="stringliteral">"badpix:sigmafactor"</span>, -1.) ;
+<a name="l00442"></a>00442         <span class="keywordflow">if</span> (dval!=-1.)
+<a name="l00443"></a>00443         {
+<a name="l00444"></a>00444             cfg -> sigmaFactor = dval ;
+<a name="l00445"></a>00445         }
+<a name="l00446"></a>00446         <span class="keywordflow">else</span>
+<a name="l00447"></a>00447         {
+<a name="l00448"></a>00448             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" sigmaFactor in the .ini file was not found!\n"</span>) ;
+<a name="l00449"></a>00449             (*status)++ ;
+<a name="l00450"></a>00450         }
+<a name="l00451"></a>00451         dval = iniparser_getdouble(sym, <span class="stringliteral">"badpix:factor"</span>, -1.) ;
+<a name="l00452"></a>00452         <span class="keywordflow">if</span> (dval!=-1.)
+<a name="l00453"></a>00453         {
+<a name="l00454"></a>00454             cfg -> factor = dval ;
+<a name="l00455"></a>00455         }
+<a name="l00456"></a>00456         <span class="keywordflow">else</span>
+<a name="l00457"></a>00457         {
+<a name="l00458"></a>00458             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" factor in the .ini file was not found!\n"</span>) ;
+<a name="l00459"></a>00459             (*status)++ ;
+<a name="l00460"></a>00460         }
+<a name="l00461"></a>00461         ival = iniparser_getint(sym, <span class="stringliteral">"badpix:iterations"</span>, -1) ;
+<a name="l00462"></a>00462         <span class="keywordflow">if</span> (ival!=-1)
+<a name="l00463"></a>00463         {
+<a name="l00464"></a>00464             cfg -> iterations = ival ;
+<a name="l00465"></a>00465         }
+<a name="l00466"></a>00466         <span class="keywordflow">else</span>
+<a name="l00467"></a>00467         {
+<a name="l00468"></a>00468             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" iterations in the .ini file was not found!\n"</span>) ;
+<a name="l00469"></a>00469             (*status)++ ;
+<a name="l00470"></a>00470         }
+<a name="l00471"></a>00471         dval = iniparser_getdouble(sym, <span class="stringliteral">"badpix:badloreject"</span>, -1.) ;
+<a name="l00472"></a>00472         <span class="keywordflow">if</span> (dval!=-1.)
+<a name="l00473"></a>00473         {
+<a name="l00474"></a>00474             cfg -> badLoReject = dval ;
+<a name="l00475"></a>00475         }
+<a name="l00476"></a>00476         <span class="keywordflow">else</span>
+<a name="l00477"></a>00477         {
+<a name="l00478"></a>00478             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" badLoReject in the .ini file was not found!\n"</span>) ;
+<a name="l00479"></a>00479             (*status)++ ;
+<a name="l00480"></a>00480         }
+<a name="l00481"></a>00481         dval = iniparser_getdouble(sym, <span class="stringliteral">"badpix:badhireject"</span>, -1.) ;
+<a name="l00482"></a>00482         <span class="keywordflow">if</span> (dval!=-1.)
+<a name="l00483"></a>00483         {
+<a name="l00484"></a>00484             cfg -> badHiReject = dval ;
+<a name="l00485"></a>00485         }
+<a name="l00486"></a>00486         <span class="keywordflow">else</span>
+<a name="l00487"></a>00487         {
+<a name="l00488"></a>00488             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" badHiReject in the .ini file was not found!\n"</span>) ;
+<a name="l00489"></a>00489             (*status)++ ;
+<a name="l00490"></a>00490         }
+<a name="l00491"></a>00491         ival = iniparser_getint(sym, <span class="stringliteral">"badpix:llx"</span>, -1) ;
+<a name="l00492"></a>00492         <span class="keywordflow">if</span> (ival!=-1)
+<a name="l00493"></a>00493         {
+<a name="l00494"></a>00494             cfg -> llx = ival ;
+<a name="l00495"></a>00495         }
+<a name="l00496"></a>00496         <span class="keywordflow">else</span>
+<a name="l00497"></a>00497         {
+<a name="l00498"></a>00498             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" factor in the .ini file was not found!\n"</span>) ;
+<a name="l00499"></a>00499             (*status)++ ;
+<a name="l00500"></a>00500         }
+<a name="l00501"></a>00501         ival = iniparser_getint(sym, <span class="stringliteral">"badpix:lly"</span>, -1) ;
+<a name="l00502"></a>00502         <span class="keywordflow">if</span> (ival!=-1)
+<a name="l00503"></a>00503         {
+<a name="l00504"></a>00504             cfg -> lly = ival ;
+<a name="l00505"></a>00505         }
+<a name="l00506"></a>00506         <span class="keywordflow">else</span>
+<a name="l00507"></a>00507         {
+<a name="l00508"></a>00508             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" factor in the .ini file was not found!\n"</span>) ;
+<a name="l00509"></a>00509             (*status)++ ;
+<a name="l00510"></a>00510         }
+<a name="l00511"></a>00511         ival = iniparser_getint(sym, <span class="stringliteral">"badpix:urx"</span>, -1) ;
+<a name="l00512"></a>00512         <span class="keywordflow">if</span> (ival!=-1)
+<a name="l00513"></a>00513         {
+<a name="l00514"></a>00514             cfg -> urx = ival ;
+<a name="l00515"></a>00515         }
+<a name="l00516"></a>00516         <span class="keywordflow">else</span>
+<a name="l00517"></a>00517         {
+<a name="l00518"></a>00518             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" factor in the .ini file was not found!\n"</span>) ;
+<a name="l00519"></a>00519             (*status)++ ;
+<a name="l00520"></a>00520         }
+<a name="l00521"></a>00521         ival = iniparser_getint(sym, <span class="stringliteral">"badpix:ury"</span>, -1) ;
+<a name="l00522"></a>00522         <span class="keywordflow">if</span> (ival!=-1)
+<a name="l00523"></a>00523         {
+<a name="l00524"></a>00524             cfg -> ury = ival ;
+<a name="l00525"></a>00525         }
+<a name="l00526"></a>00526         <span class="keywordflow">else</span>
+<a name="l00527"></a>00527         {
+<a name="l00528"></a>00528             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" factor in the .ini file was not found!\n"</span>) ;
+<a name="l00529"></a>00529             (*status)++ ;
+<a name="l00530"></a>00530         }
+<a name="l00531"></a>00531         return ;
+<a name="l00532"></a>00532 }
+<a name="l00533"></a>00533 
+<a name="l00534"></a>00534 <span class="keyword">static</span> <span class="keywordtype">void</span>     parse_section_thresh(
+<a name="l00535"></a>00535         dictionary * sym,
+<a name="l00536"></a>00536         flat_config * cfg,
+<a name="l00537"></a>00537         <span class="keywordtype">int</span> *status )
+<a name="l00538"></a>00538 {
+<a name="l00539"></a>00539         <span class="keywordtype">int</span>             ival ;
+<a name="l00540"></a>00540         <span class="keywordtype">float</span>           dval ;
+<a name="l00541"></a>00541 
+<a name="l00542"></a>00542         ival = iniparser_getboolean(sym, <span class="stringliteral">"thresh:threshind"</span>, -1) ;
+<a name="l00543"></a>00543         <span class="keywordflow">if</span> (ival != -1)
+<a name="l00544"></a>00544         {
+<a name="l00545"></a>00545             cfg -> threshInd = ival ;
+<a name="l00546"></a>00546         }
+<a name="l00547"></a>00547         <span class="keywordflow">else</span>
+<a name="l00548"></a>00548         {
+<a name="l00549"></a>00549             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" ThreshInd in the .ini file was not found!\n"</span>) ;
+<a name="l00550"></a>00550             (*status)++ ;
+<a name="l00551"></a>00551         }
+<a name="l00552"></a>00552         dval = iniparser_getdouble(sym, <span class="stringliteral">"thresh:meanfactor"</span>, -1.) ;
+<a name="l00553"></a>00553         <span class="keywordflow">if</span> (dval!=-1.)
+<a name="l00554"></a>00554         {
+<a name="l00555"></a>00555             cfg -> meanfactor = dval ;
+<a name="l00556"></a>00556         }
+<a name="l00557"></a>00557         <span class="keywordflow">else</span>
+<a name="l00558"></a>00558         {
+<a name="l00559"></a>00559             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" meanfactor in the .ini file was not found!\n"</span>) ;
+<a name="l00560"></a>00560             (*status)++ ;
+<a name="l00561"></a>00561         }
+<a name="l00562"></a>00562 }
+<a name="l00563"></a>00563 
+<a name="l00564"></a>00564 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__flat__ini_8h_source.html b/html/sinfo__flat__ini_8h_source.html
new file mode 100644
index 0000000..ee253c4
--- /dev/null
+++ b/html/sinfo__flat__ini_8h_source.html
@@ -0,0 +1,64 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_flat_ini.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_flat_ini.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name    :   sinfo_flat_ini.h</span>
+<a name="l00022"></a>00022 <span class="comment">   Author       :    Juergen Schreiber</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on   :    Mar 04, 2002</span>
+<a name="l00024"></a>00024 <span class="comment">   Description  :    preparing flatfield ini file handling for SPIFFI</span>
+<a name="l00025"></a>00025 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00026"></a>00026 <span class="preprocessor">#ifndef SINFO_FLAT_INI_H</span>
+<a name="l00027"></a>00027 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_FLAT_INI_H</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00029"></a>00029 <span class="comment">                                Includes</span>
+<a name="l00030"></a>00030 <span class="comment">---------------------------------------------------------------------------*/</span>
+<a name="l00031"></a>00031 <span class="preprocessor">#include "sinfo_flat_cfg.h"</span>
+<a name="l00032"></a>00032 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00033"></a>00033 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00034"></a>00034 <span class="comment">                                Defines</span>
+<a name="l00035"></a>00035 <span class="comment">---------------------------------------------------------------------------*/</span>
+<a name="l00036"></a>00036 <span class="preprocessor">#define FRAME_ON     1 </span><span class="comment">/* object frames */</span>
+<a name="l00037"></a>00037 <span class="preprocessor">#define FRAME_OFF    0 </span><span class="comment">/* off frames, that means sky frames or </span>
+<a name="l00038"></a>00038 <span class="comment">                          calibration frames with lamp switched off */</span>
+<a name="l00039"></a>00039 <span class="preprocessor">#define FRAME_POS1   2 </span><span class="comment">/* frames exposed with grating position 1 */</span>
+<a name="l00040"></a>00040 <span class="preprocessor">#define FRAME_POS2   3 </span><span class="comment">/* frames exposed with dithered grating position 2 */</span>
+<a name="l00041"></a>00041 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00042"></a>00042 <span class="comment">                             Function prototypes </span>
+<a name="l00043"></a>00043 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00044"></a>00044 
+<a name="l00054"></a>00054 flat_config * 
+<a name="l00055"></a>00055 parse_flat_ini_file(<span class="keywordtype">char</span> * ini_name) ;
+<a name="l00056"></a>00056 
+<a name="l00057"></a>00057 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__flat__ini__by__cpl_8c_source.html b/html/sinfo__flat__ini__by__cpl_8c_source.html
new file mode 100644
index 0000000..a82c316
--- /dev/null
+++ b/html/sinfo__flat__ini__by__cpl_8c_source.html
@@ -0,0 +1,468 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_flat_ini_by_cpl.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_flat_ini_by_cpl.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name    :   sinfo_flat_ini_by_cpl.c</span>
+<a name="l00022"></a>00022 <span class="comment">   Author       :   Andrea Modigliani</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on   :   May 19, 2004</span>
+<a name="l00024"></a>00024 <span class="comment">   Description  :   read cpl input for SPIFFI</span>
+<a name="l00025"></a>00025 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00026"></a>00026 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00027"></a>00027 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00028"></a>00028 <span class="preprocessor">#endif</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00030"></a>00030 <span class="comment">                                Includes</span>
+<a name="l00031"></a>00031 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00032"></a>00032 <span class="preprocessor">#include <string.h></span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include "sinfo_flat_ini_by_cpl.h"</span>
+<a name="l00034"></a>00034 <span class="preprocessor">#include "sinfo_error.h"</span>
+<a name="l00035"></a>00035 <span class="preprocessor">#include "sinfo_hidden.h"</span>
+<a name="l00036"></a>00036 <span class="preprocessor">#include "sinfo_pro_types.h"</span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include "sinfo_raw_types.h"</span>
+<a name="l00038"></a>00038 <span class="preprocessor">#include "sinfo_functions.h"</span>
+<a name="l00039"></a>00039 <span class="preprocessor">#include "sinfo_file_handling.h"</span>
+<a name="l00040"></a>00040 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00041"></a>00041 <span class="comment">                    Functions private to this module</span>
+<a name="l00042"></a>00042 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00043"></a>00043 <span class="keywordtype">void</span> sinfo_flat_free_alloc(flat_config * cfg);
+<a name="l00044"></a>00044 <span class="keyword">static</span> <span class="keywordtype">void</span> 
+<a name="l00045"></a>00045 parse_section_frames(flat_config *, cpl_frameset* sof, 
+<a name="l00046"></a>00046                      cpl_frameset** raw, <span class="keywordtype">int</span>* status);
+<a name="l00047"></a>00047 <span class="keyword">static</span> <span class="keywordtype">void</span> parse_section_cleanmean(flat_config *, cpl_parameterlist* cpl_cfg);
+<a name="l00048"></a>00048 <span class="keyword">static</span> <span class="keywordtype">void</span> parse_section_badpixel(flat_config *, cpl_parameterlist* cpl_cfg);
+<a name="l00049"></a>00049 <span class="keyword">static</span> <span class="keywordtype">void</span> parse_section_badpix(flat_config *, cpl_parameterlist* cpl_cfg);
+<a name="l00050"></a>00050 <span class="keyword">static</span> <span class="keywordtype">void</span> parse_section_thresh(flat_config *, cpl_parameterlist* cpl_cfg);
+<a name="l00051"></a>00051 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00052"></a>00052 parse_section_qclog(flat_config * cfg, cpl_parameterlist *   cpl_cfg);
+<a name="l00074"></a>00074 flat_config * 
+<a name="l00075"></a>00075 sinfo_parse_cpl_input_flat(cpl_parameterlist* cpl_cfg, 
+<a name="l00076"></a>00076                                    cpl_frameset* sof, 
+<a name="l00077"></a>00077                                    cpl_frameset** raw)
+<a name="l00078"></a>00078 {
+<a name="l00079"></a>00079         flat_config   *       cfg = sinfo_flat_cfg_create();
+<a name="l00080"></a>00080         <span class="keywordtype">int</span> status=0;
+<a name="l00081"></a>00081         <span class="comment">/*</span>
+<a name="l00082"></a>00082 <span class="comment">         * Perform sanity checks, fill up the structure with what was</span>
+<a name="l00083"></a>00083 <span class="comment">         * found in the ini file</span>
+<a name="l00084"></a>00084 <span class="comment">         */</span>
+<a name="l00085"></a>00085         parse_section_badpixel  (cfg, cpl_cfg);
+<a name="l00086"></a>00086         parse_section_cleanmean (cfg, cpl_cfg);
+<a name="l00087"></a>00087         parse_section_badpix    (cfg, cpl_cfg);
+<a name="l00088"></a>00088         parse_section_thresh    (cfg, cpl_cfg); 
+<a name="l00089"></a>00089         parse_section_qclog     (cfg,cpl_cfg);
+<a name="l00090"></a>00090       
+<a name="l00091"></a>00091         parse_section_frames    (cfg, sof, raw,  &status);
+<a name="l00092"></a>00092         <span class="keywordflow">if</span> (status > 0) {
+<a name="l00093"></a>00093                 <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"parsing cpl input"</span>);
+<a name="l00094"></a>00094                 sinfo_flat_cfg_destroy(cfg);
+<a name="l00095"></a>00095                 cfg = NULL ;
+<a name="l00096"></a>00096                 <span class="keywordflow">return</span> NULL ;
+<a name="l00097"></a>00097         }
+<a name="l00098"></a>00098         <span class="keywordflow">return</span> cfg ;
+<a name="l00099"></a>00099 }
+<a name="l00100"></a>00100 
+<a name="l00110"></a>00110 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00111"></a>00111 parse_section_frames(flat_config * cfg,
+<a name="l00112"></a>00112              cpl_frameset * sof,
+<a name="l00113"></a>00113              cpl_frameset ** raw,
+<a name="l00114"></a>00114                      <span class="keywordtype">int</span>* status)
+<a name="l00115"></a>00115 {
+<a name="l00116"></a>00116    <span class="keywordtype">int</span>                     i;
+<a name="l00117"></a>00117 
+<a name="l00118"></a>00118    <span class="keywordtype">char</span>           *       name ;
+<a name="l00119"></a>00119 
+<a name="l00120"></a>00120    <span class="keywordtype">int</span>                     nobj, noff ;
+<a name="l00121"></a>00121    <span class="keywordtype">int</span>                     nditherobj, nditheroff ;
+<a name="l00122"></a>00122    <span class="keywordtype">int</span>                     found_sky ;
+<a name="l00123"></a>00123    <span class="keywordtype">int</span>                     found_dither ;
+<a name="l00124"></a>00124    <span class="keywordtype">int</span> nframes=0;
+<a name="l00125"></a>00125    <span class="keywordtype">int</span> nraw=0;
+<a name="l00126"></a>00126    <span class="keywordtype">char</span>* tag;
+<a name="l00127"></a>00127    <span class="keywordtype">char</span> spat_res[FILE_NAME_SZ];
+<a name="l00128"></a>00128    <span class="keywordtype">char</span> lamp_status[FILE_NAME_SZ];
+<a name="l00129"></a>00129    <span class="keywordtype">char</span> band[FILE_NAME_SZ];
+<a name="l00130"></a>00130    <span class="keywordtype">int</span> ins_set=0;
+<a name="l00131"></a>00131 
+<a name="l00132"></a>00132    cpl_frame* frame   = NULL;
+<a name="l00133"></a>00133 
+<a name="l00134"></a>00134 
+<a name="l00135"></a>00135    nframes = cpl_frameset_get_size(sof);
+<a name="l00136"></a>00136 
+<a name="l00137"></a>00137    sinfo_extract_raw_frames_type(sof,raw,RAW_FLAT_LAMP);
+<a name="l00138"></a>00138    nraw=cpl_frameset_get_size(*raw);
+<a name="l00139"></a>00139 
+<a name="l00140"></a>00140    <span class="keywordflow">if</span> (nraw==0) {
+<a name="l00141"></a>00141       sinfo_extract_raw_frames_type(sof,raw,RAW_FLAT_NS);
+<a name="l00142"></a>00142    }   
+<a name="l00143"></a>00143 
+<a name="l00144"></a>00144 
+<a name="l00145"></a>00145    nraw=cpl_frameset_get_size(*raw);
+<a name="l00146"></a>00146    <span class="keywordflow">if</span> (nraw==0) {
+<a name="l00147"></a>00147        sinfo_msg(<span class="stringliteral">"Frame %s or %s not found!"</span>, RAW_FLAT_LAMP,RAW_FLAT_NS);
+<a name="l00148"></a>00148        (*status)++;
+<a name="l00149"></a>00149        return   ;
+<a name="l00150"></a>00150    }
+<a name="l00151"></a>00151 
+<a name="l00152"></a>00152    nraw  = cpl_frameset_get_size(*raw);
+<a name="l00153"></a>00153 
+<a name="l00154"></a>00154    sinfo_msg(<span class="stringliteral">"nraw=%d"</span>,nraw);
+<a name="l00155"></a>00155    <span class="keywordflow">if</span>(nraw<1) {
+<a name="l00156"></a>00156      <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no good raw frame in input, something wrong!"</span>);
+<a name="l00157"></a>00157      (*status)++;
+<a name="l00158"></a>00158      <span class="keywordflow">return</span>;
+<a name="l00159"></a>00159    }
+<a name="l00160"></a>00160 
+<a name="l00161"></a>00161    cknull_nomsg(frame = cpl_frameset_get_frame(*raw,0));
+<a name="l00162"></a>00162 
+<a name="l00163"></a>00163    ck0_nomsg(sinfo_get_spatial_res(frame,spat_res));
+<a name="l00164"></a>00164    <span class="keywordflow">switch</span>(sinfo_frame_is_on(frame))
+<a name="l00165"></a>00165      {
+<a name="l00166"></a>00166 
+<a name="l00167"></a>00167     <span class="keywordflow">case</span> 0: 
+<a name="l00168"></a>00168       strcpy(lamp_status,<span class="stringliteral">"on"</span>);
+<a name="l00169"></a>00169       <span class="keywordflow">break</span>;
+<a name="l00170"></a>00170     <span class="keywordflow">case</span> 1: 
+<a name="l00171"></a>00171       strcpy(lamp_status,<span class="stringliteral">"off"</span>);
+<a name="l00172"></a>00172       <span class="keywordflow">break</span>;
+<a name="l00173"></a>00173     <span class="keywordflow">case</span> -1:
+<a name="l00174"></a>00174       strcpy(lamp_status,<span class="stringliteral">"undefined"</span>);
+<a name="l00175"></a>00175       <span class="keywordflow">break</span>;
+<a name="l00176"></a>00176     <span class="keywordflow">default</span>: 
+<a name="l00177"></a>00177       strcpy(lamp_status,<span class="stringliteral">"undefined"</span>);
+<a name="l00178"></a>00178       <span class="keywordflow">break</span>;
+<a name="l00179"></a>00179 
+<a name="l00180"></a>00180      }
+<a name="l00181"></a>00181 
+<a name="l00182"></a>00182    sinfo_get_band(frame,band);
+<a name="l00183"></a>00183    sinfo_msg(<span class="stringliteral">"Spatial resolution: %s lamp status: %s band: %s \n"</span>,
+<a name="l00184"></a>00184                      spat_res,              lamp_status,    band);
+<a name="l00185"></a>00185 
+<a name="l00186"></a>00186    
+<a name="l00187"></a>00187    sinfo_get_ins_set(band,&ins_set);
+<a name="l00188"></a>00188 
+<a name="l00189"></a>00189 
+<a name="l00190"></a>00190    <span class="comment">/* Allocate structures to go into the blackboard */</span>
+<a name="l00191"></a>00191    cfg->framelist     = cpl_malloc(nraw * <span class="keyword">sizeof</span>(<span class="keywordtype">char</span>*));
+<a name="l00192"></a>00192    cfg->frametype     = cpl_malloc(nraw * <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>));
+<a name="l00193"></a>00193    cfg->frameposition = cpl_malloc(nraw * <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>));
+<a name="l00194"></a>00194 
+<a name="l00195"></a>00195    found_sky     = 0 ;
+<a name="l00196"></a>00196    found_dither  = 0 ;
+<a name="l00197"></a>00197    nobj          = 0 ;
+<a name="l00198"></a>00198    noff          = 0 ;
+<a name="l00199"></a>00199    nditheroff    = 0 ;
+<a name="l00200"></a>00200    nditherobj    = 0 ;
+<a name="l00201"></a>00201    <span class="keywordflow">for</span> (i=0;i<nraw;i++) {
+<a name="l00202"></a>00202      cfg->framelist[i]=NULL;
+<a name="l00203"></a>00203      cfg->frametype[i]=-1;
+<a name="l00204"></a>00204      cfg->frameposition[i]=-1;
+<a name="l00205"></a>00205    }
+<a name="l00206"></a>00206 
+<a name="l00207"></a>00207 
+<a name="l00208"></a>00208    cfg->nframes         = nraw ;
+<a name="l00209"></a>00209     <span class="comment">/* Browse through the charmatrix to get names and file types */</span>
+<a name="l00210"></a>00210    <span class="keywordflow">for</span> (i=0 ; i<nraw ; i++) {
+<a name="l00211"></a>00211       frame = cpl_frameset_get_frame(*raw,i);
+<a name="l00212"></a>00212       name= (<span class="keywordtype">char</span>*) cpl_frame_get_filename(frame);
+<a name="l00213"></a>00213       <span class="keywordflow">if</span>(sinfo_file_exists(name)==1) {
+<a name="l00214"></a>00214     <span class="comment">/* to go on the file must exist */</span>
+<a name="l00215"></a>00215     <span class="keywordflow">if</span>(cpl_frame_get_tag(frame) != NULL) {
+<a name="l00216"></a>00216       <span class="comment">/* If the frame has a tag we process it. Else it is an object */</span> 
+<a name="l00217"></a>00217       tag= (<span class="keywordtype">char</span>*) cpl_frame_get_tag(frame);
+<a name="l00218"></a>00218           <span class="comment">/* sinfo_msg("frame %s tag =%s \n",name,tag); */</span>
+<a name="l00219"></a>00219           <span class="keywordflow">if</span>((sinfo_frame_is_on(frame)  == 0) ||
+<a name="l00220"></a>00220              (sinfo_frame_is_sky(frame)  == 1) ) 
+<a name="l00221"></a>00221         {
+<a name="l00222"></a>00222 
+<a name="l00223"></a>00223              cfg->framelist[i]=(<span class="keywordtype">char</span>*) cpl_frame_get_filename(frame);
+<a name="l00224"></a>00224              cfg->frametype[i] = FRAME_OFF ;
+<a name="l00225"></a>00225              found_sky = 1;
+<a name="l00226"></a>00226              <span class="keywordflow">if</span> (sinfo_frame_is_dither(frame)) 
+<a name="l00227"></a>00227            {
+<a name="l00228"></a>00228                 cfg->frameposition[i] = FRAME_POS2 ;
+<a name="l00229"></a>00229                 found_dither = 1 ;
+<a name="l00230"></a>00230                 nditheroff++ ;
+<a name="l00231"></a>00231            }
+<a name="l00232"></a>00232              <span class="keywordflow">else</span> 
+<a name="l00233"></a>00233            {
+<a name="l00234"></a>00234                  cfg->frameposition[i] = FRAME_POS1 ;
+<a name="l00235"></a>00235                  noff++ ;
+<a name="l00236"></a>00236            }
+<a name="l00237"></a>00237         }
+<a name="l00238"></a>00238           <span class="keywordflow">else</span> <span class="keywordflow">if</span>(sinfo_frame_is_on(frame)  == 1) 
+<a name="l00239"></a>00239         {
+<a name="l00240"></a>00240            cfg->framelist[i]=(<span class="keywordtype">char</span>*) cpl_frame_get_filename(frame);
+<a name="l00241"></a>00241            cfg->frametype[i] = FRAME_ON ;
+<a name="l00242"></a>00242           <span class="keywordflow">if</span> (sinfo_frame_is_dither(frame))
+<a name="l00243"></a>00243         {
+<a name="l00244"></a>00244           cfg->frameposition[i] = FRAME_POS2 ;
+<a name="l00245"></a>00245           found_dither = 1 ;
+<a name="l00246"></a>00246           nditherobj++ ;
+<a name="l00247"></a>00247         }
+<a name="l00248"></a>00248               <span class="keywordflow">else</span> 
+<a name="l00249"></a>00249         {
+<a name="l00250"></a>00250           cfg->frameposition[i] = FRAME_POS1 ;
+<a name="l00251"></a>00251           nobj++ ;
+<a name="l00252"></a>00252         }
+<a name="l00253"></a>00253         }
+<a name="l00254"></a>00254  
+<a name="l00255"></a>00255     }
+<a name="l00256"></a>00256        
+<a name="l00257"></a>00257         <span class="keywordflow">else</span> 
+<a name="l00258"></a>00258       {
+<a name="l00259"></a>00259             <span class="comment">/* No type means an object */</span>
+<a name="l00260"></a>00260             <span class="comment">/* No type means position 1 */</span>
+<a name="l00261"></a>00261     <span class="comment">/*</span>
+<a name="l00262"></a>00262 <span class="comment">        cfg->frametype[i] = FRAME_ON ;</span>
+<a name="l00263"></a>00263 <span class="comment">        cfg->frameposition[i] = FRAME_POS1 ;</span>
+<a name="l00264"></a>00264 <span class="comment">        nobj ++ ;</span>
+<a name="l00265"></a>00265 <span class="comment">    */</span>
+<a name="l00266"></a>00266       }
+<a name="l00267"></a>00267       }
+<a name="l00268"></a>00268       <span class="comment">/* Store file name into framelist */</span>
+<a name="l00269"></a>00269       <span class="comment">/* sinfo_msg("frame=%s\n",cfg->framelist[i]); */</span>
+<a name="l00270"></a>00270     }
+<a name="l00271"></a>00271    
+<a name="l00272"></a>00272    <span class="comment">/*</span>
+<a name="l00273"></a>00273 <span class="comment">   sinfo_msg("Noff= %d Nobj= %d Nditheroff= %d Nditherobj= %d",</span>
+<a name="l00274"></a>00274 <span class="comment">                     noff,nobj,nditheroff,nditherobj);</span>
+<a name="l00275"></a>00275 <span class="comment">   */</span>
+<a name="l00276"></a>00276 
+<a name="l00277"></a>00277 
+<a name="l00278"></a>00278    <span class="keywordflow">if</span>((nobj<1) && (nditherobj< 1)) {
+<a name="l00279"></a>00279      <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no ON raw frame in input, something wrong!"</span>);
+<a name="l00280"></a>00280      sinfo_flat_free_alloc(cfg);
+<a name="l00281"></a>00281      (*status)++;
+<a name="l00282"></a>00282      <span class="keywordflow">return</span>;
+<a name="l00283"></a>00283    }
+<a name="l00284"></a>00284  
+<a name="l00285"></a>00285    <span class="comment">/* Copy relevant information into the blackboard */</span>
+<a name="l00286"></a>00286    cfg->nobj            = nobj ;
+<a name="l00287"></a>00287    cfg->noff            = noff ;
+<a name="l00288"></a>00288    cfg->nditherobj      = nditherobj ;
+<a name="l00289"></a>00289    cfg->nditheroff      = nditheroff ;
+<a name="l00290"></a>00290    cfg->contains_sky    = found_sky ;
+<a name="l00291"></a>00291    cfg->contains_dither = found_dither ;
+<a name="l00292"></a>00292 
+<a name="l00293"></a>00293    strcpy(cfg -> outName, LAMP_FLATS_OUT_FILENAME);
+<a name="l00294"></a>00294 
+<a name="l00295"></a>00295    <span class="keywordflow">if</span>(cfg->interpolInd != 0) {
+<a name="l00296"></a>00296 
+<a name="l00297"></a>00297       <span class="keywordflow">if</span>(NULL != cpl_frameset_find(sof,PRO_BP_MAP)) {
+<a name="l00298"></a>00298          frame = cpl_frameset_find(sof,PRO_BP_MAP);
+<a name="l00299"></a>00299          strcpy(cfg -> mask,cpl_frame_get_filename(frame));
+<a name="l00300"></a>00300          <span class="keywordflow">if</span>(sinfo_file_exists(cfg->mask)==1) {
+<a name="l00301"></a>00301          } <span class="keywordflow">else</span> {
+<a name="l00302"></a>00302             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Filename %s for Frame %s not found!"</span>, 
+<a name="l00303"></a>00303                        cfg->mask, PRO_BP_MAP);
+<a name="l00304"></a>00304             sinfo_flat_free_alloc(cfg);
+<a name="l00305"></a>00305             (*status)++;
+<a name="l00306"></a>00306            <span class="keywordflow">return</span>;
+<a name="l00307"></a>00307  
+<a name="l00308"></a>00308          }
+<a name="l00309"></a>00309 
+<a name="l00310"></a>00310       } <span class="keywordflow">else</span> {
+<a name="l00311"></a>00311         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Frame %s not found!"</span>, PRO_BP_MAP);
+<a name="l00312"></a>00312         sinfo_flat_free_alloc(cfg);
+<a name="l00313"></a>00313         (*status)++;
+<a name="l00314"></a>00314        <span class="keywordflow">return</span>;
+<a name="l00315"></a>00315       } 
+<a name="l00316"></a>00316       <span class="keywordflow">if</span>(NULL != cpl_frameset_find(sof,PRO_SLIT_POS)) {
+<a name="l00317"></a>00317          frame = cpl_frameset_find(sof,PRO_SLIT_POS);
+<a name="l00318"></a>00318          strcpy(cfg -> slitposList,cpl_frame_get_filename(frame));
+<a name="l00319"></a>00319          <span class="keywordflow">if</span>(sinfo_file_exists(cfg->mask) == 1) {
+<a name="l00320"></a>00320          } <span class="keywordflow">else</span> {
+<a name="l00321"></a>00321             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Filename %s for Frame %s not found!"</span>, 
+<a name="l00322"></a>00322                        cfg->slitposList, PRO_SLIT_POS);
+<a name="l00323"></a>00323             sinfo_flat_free_alloc(cfg);
+<a name="l00324"></a>00324             (*status)++;
+<a name="l00325"></a>00325             <span class="keywordflow">return</span>;
+<a name="l00326"></a>00326      }
+<a name="l00327"></a>00327       } <span class="keywordflow">else</span> {
+<a name="l00328"></a>00328         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Frame %s not found!"</span>, PRO_SLIT_POS);
+<a name="l00329"></a>00329         sinfo_flat_free_alloc(cfg);
+<a name="l00330"></a>00330         (*status)++;
+<a name="l00331"></a>00331         <span class="keywordflow">return</span>;
+<a name="l00332"></a>00332       }
+<a name="l00333"></a>00333 
+<a name="l00334"></a>00334    }
+<a name="l00335"></a>00335 
+<a name="l00336"></a>00336   cleanup:
+<a name="l00337"></a>00337 
+<a name="l00338"></a>00338    <span class="keywordflow">return</span>;
+<a name="l00339"></a>00339 }
+<a name="l00340"></a>00340 
+<a name="l00348"></a>00348 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00349"></a>00349 parse_section_cleanmean(flat_config * cfg, cpl_parameterlist * cpl_cfg)
+<a name="l00350"></a>00350 {
+<a name="l00351"></a>00351    cpl_parameter *p; 
+<a name="l00352"></a>00352   
+<a name="l00353"></a>00353    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.lamp_flats.low_rejection"</span>);
+<a name="l00354"></a>00354    cfg -> loReject = cpl_parameter_get_double(p);
+<a name="l00355"></a>00355 
+<a name="l00356"></a>00356    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.lamp_flats.high_rejection"</span>);
+<a name="l00357"></a>00357    cfg -> hiReject = cpl_parameter_get_double(p);
+<a name="l00358"></a>00358 
+<a name="l00359"></a>00359 }
+<a name="l00360"></a>00360 
+<a name="l00368"></a>00368 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00369"></a>00369 parse_section_badpixel(flat_config * cfg, cpl_parameterlist * cpl_cfg)
+<a name="l00370"></a>00370 {
+<a name="l00371"></a>00371    cpl_parameter *p; 
+<a name="l00372"></a>00372 
+<a name="l00373"></a>00373    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.lamp_flats.interpol_index"</span>);
+<a name="l00374"></a>00374    cfg -> interpolInd = cpl_parameter_get_bool(p);
+<a name="l00375"></a>00375 
+<a name="l00376"></a>00376    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.lamp_flats.max_rad"</span>);
+<a name="l00377"></a>00377    cfg -> maxRad =  cpl_parameter_get_int(p);
+<a name="l00378"></a>00378 
+<a name="l00379"></a>00379 }
+<a name="l00380"></a>00380 
+<a name="l00388"></a>00388 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00389"></a>00389 parse_section_badpix(flat_config * cfg, cpl_parameterlist * cpl_cfg)
+<a name="l00390"></a>00390 {
+<a name="l00391"></a>00391 
+<a name="l00392"></a>00392    cpl_parameter* p;
+<a name="l00393"></a>00393 
+<a name="l00394"></a>00394    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.lamp_flats.bad_ind"</span>);
+<a name="l00395"></a>00395    cfg ->  badInd = cpl_parameter_get_bool(p);
+<a name="l00396"></a>00396 
+<a name="l00397"></a>00397    strcpy(cfg -> maskname, LAMP_FLATS_OUT_BPMAP);
+<a name="l00398"></a>00398 
+<a name="l00399"></a>00399    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.lamp_flats.sigma_factor"</span>);
+<a name="l00400"></a>00400    cfg -> sigmaFactor = cpl_parameter_get_double(p);
+<a name="l00401"></a>00401 
+<a name="l00402"></a>00402    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.lamp_flats.factor"</span>);
+<a name="l00403"></a>00403    cfg -> factor = cpl_parameter_get_double(p);
+<a name="l00404"></a>00404 
+<a name="l00405"></a>00405    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.lamp_flats.iterations"</span>);
+<a name="l00406"></a>00406    cfg -> iterations = cpl_parameter_get_int(p);
+<a name="l00407"></a>00407 
+<a name="l00408"></a>00408    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.lamp_flats.bad_low_rejection"</span>);
+<a name="l00409"></a>00409    cfg -> badLoReject = cpl_parameter_get_double(p);
+<a name="l00410"></a>00410 
+<a name="l00411"></a>00411    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.lamp_flats.bad_high_rejection"</span>);
+<a name="l00412"></a>00412    cfg -> badHiReject = cpl_parameter_get_double(p);
+<a name="l00413"></a>00413 
+<a name="l00414"></a>00414    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.lamp_flats.llx"</span>);
+<a name="l00415"></a>00415    cfg -> llx = cpl_parameter_get_int(p);
+<a name="l00416"></a>00416 
+<a name="l00417"></a>00417    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.lamp_flats.lly"</span>);
+<a name="l00418"></a>00418    cfg -> lly = cpl_parameter_get_int(p);
+<a name="l00419"></a>00419  
+<a name="l00420"></a>00420    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.lamp_flats.urx"</span>);
+<a name="l00421"></a>00421    cfg -> urx = cpl_parameter_get_int(p);
+<a name="l00422"></a>00422 
+<a name="l00423"></a>00423    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.lamp_flats.ury"</span>);
+<a name="l00424"></a>00424    cfg -> ury = cpl_parameter_get_int(p);
+<a name="l00425"></a>00425 
+<a name="l00426"></a>00426 }
+<a name="l00427"></a>00427 
+<a name="l00435"></a>00435 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00436"></a>00436 parse_section_thresh(flat_config * cfg,cpl_parameterlist* cpl_cfg)
+<a name="l00437"></a>00437 {
+<a name="l00438"></a>00438 
+<a name="l00439"></a>00439    cpl_parameter* p;
+<a name="l00440"></a>00440    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.lamp_flats.thresh_ind"</span>);
+<a name="l00441"></a>00441    cfg -> threshInd =cpl_parameter_get_bool(p);
+<a name="l00442"></a>00442 
+<a name="l00443"></a>00443    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.lamp_flats.mean_factor"</span>);
+<a name="l00444"></a>00444    cfg -> meanfactor = cpl_parameter_get_double(p);
+<a name="l00445"></a>00445 
+<a name="l00446"></a>00446 
+<a name="l00447"></a>00447 }
+<a name="l00448"></a>00448 
+<a name="l00449"></a>00449 
+<a name="l00457"></a>00457 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00458"></a>00458 parse_section_qclog(flat_config * cfg, cpl_parameterlist *   cpl_cfg)
+<a name="l00459"></a>00459 {
+<a name="l00460"></a>00460    cpl_parameter *p;  
+<a name="l00461"></a>00461 
+<a name="l00462"></a>00462    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.lamp_flats.qc_fpn_xmin1"</span>);
+<a name="l00463"></a>00463    cfg -> qc_fpn_xmin1 = cpl_parameter_get_int(p);
+<a name="l00464"></a>00464 
+<a name="l00465"></a>00465    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.lamp_flats.qc_fpn_xmax1"</span>);
+<a name="l00466"></a>00466    cfg -> qc_fpn_xmax1 = cpl_parameter_get_int(p);
+<a name="l00467"></a>00467 
+<a name="l00468"></a>00468    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.lamp_flats.qc_fpn_ymin1"</span>);
+<a name="l00469"></a>00469    cfg -> qc_fpn_ymin1 = cpl_parameter_get_int(p);
+<a name="l00470"></a>00470 
+<a name="l00471"></a>00471    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.lamp_flats.qc_fpn_ymax1"</span>);
+<a name="l00472"></a>00472    cfg -> qc_fpn_ymax1 = cpl_parameter_get_int(p);
+<a name="l00473"></a>00473 
+<a name="l00474"></a>00474    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.lamp_flats.qc_fpn_xmin2"</span>);
+<a name="l00475"></a>00475    cfg -> qc_fpn_xmin2 = cpl_parameter_get_int(p);
+<a name="l00476"></a>00476    
+<a name="l00477"></a>00477    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.lamp_flats.qc_fpn_xmax2"</span>);
+<a name="l00478"></a>00478    cfg -> qc_fpn_xmax2 = cpl_parameter_get_int(p);
+<a name="l00479"></a>00479 
+<a name="l00480"></a>00480    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.lamp_flats.qc_fpn_ymin2"</span>);
+<a name="l00481"></a>00481    cfg -> qc_fpn_ymin2 = cpl_parameter_get_int(p);
+<a name="l00482"></a>00482 
+<a name="l00483"></a>00483    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.lamp_flats.qc_fpn_ymax2"</span>);
+<a name="l00484"></a>00484    cfg -> qc_fpn_ymax2 = cpl_parameter_get_int(p);
+<a name="l00485"></a>00485 
+<a name="l00486"></a>00486    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.lamp_flats.qc_thresh_min"</span>);
+<a name="l00487"></a>00487    cfg -> qc_thresh_min = cpl_parameter_get_int(p);
+<a name="l00488"></a>00488 
+<a name="l00489"></a>00489    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.lamp_flats.qc_thresh_max"</span>);
+<a name="l00490"></a>00490    cfg -> qc_thresh_max = cpl_parameter_get_int(p);
+<a name="l00491"></a>00491 
+<a name="l00492"></a>00492 }
+<a name="l00500"></a>00500 <span class="keywordtype">void</span>
+<a name="l00501"></a>00501 sinfo_flat_free(flat_config ** cfg)
+<a name="l00502"></a>00502 {  
+<a name="l00503"></a>00503   <span class="keywordflow">if</span> ((*cfg) != NULL) {
+<a name="l00504"></a>00504     sinfo_flat_free_alloc(*cfg);
+<a name="l00505"></a>00505     sinfo_flat_cfg_destroy(*cfg);
+<a name="l00506"></a>00506     *cfg=NULL;
+<a name="l00507"></a>00507   }
+<a name="l00508"></a>00508   <span class="keywordflow">return</span>;
+<a name="l00509"></a>00509 
+<a name="l00510"></a>00510 }
+<a name="l00518"></a>00518 <span class="keywordtype">void</span> 
+<a name="l00519"></a>00519 sinfo_flat_free_alloc(flat_config * cfg)
+<a name="l00520"></a>00520 {
+<a name="l00521"></a>00521   <span class="keywordflow">if</span>(cfg->frametype != NULL){
+<a name="l00522"></a>00522        cpl_free(cfg->frametype); 
+<a name="l00523"></a>00523   }
+<a name="l00524"></a>00524   <span class="keywordflow">if</span>(cfg->framelist != NULL) {
+<a name="l00525"></a>00525      cpl_free(cfg->framelist);
+<a name="l00526"></a>00526   }
+<a name="l00527"></a>00527   <span class="keywordflow">if</span>(cfg->frameposition != NULL) {
+<a name="l00528"></a>00528      cpl_free(cfg->frameposition);
+<a name="l00529"></a>00529   }
+<a name="l00530"></a>00530 return ;
+<a name="l00531"></a>00531 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__flat__ini__by__cpl_8h_source.html b/html/sinfo__flat__ini__by__cpl_8h_source.html
new file mode 100644
index 0000000..b23c2fb
--- /dev/null
+++ b/html/sinfo__flat__ini__by__cpl_8h_source.html
@@ -0,0 +1,69 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_flat_ini_by_cpl.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_flat_ini_by_cpl.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name    :   sinfo_flat_ini.h</span>
+<a name="l00022"></a>00022 <span class="comment">   Author       :   Andrea Modigliani</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on   :   Mar 04, 2004</span>
+<a name="l00024"></a>00024 <span class="comment">   Description  :   flatfield cpl_input handling for SPIFFI</span>
+<a name="l00025"></a>00025 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00026"></a>00026 <span class="preprocessor">#ifndef SINFO_FLAT_INI_BY_CPL_H</span>
+<a name="l00027"></a>00027 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_FLAT_INI_BY_CPL_H</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00029"></a>00029 <span class="comment">                                Includes</span>
+<a name="l00030"></a>00030 <span class="comment">---------------------------------------------------------------------------*/</span>
+<a name="l00031"></a>00031 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00032"></a>00032 <span class="preprocessor">#include "sinfo_flat_cfg.h"</span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00034"></a>00034 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00035"></a>00035 <span class="comment">                                Defines</span>
+<a name="l00036"></a>00036 <span class="comment">---------------------------------------------------------------------------*/</span>
+<a name="l00037"></a>00037 <span class="preprocessor">#define FRAME_ON     1 </span><span class="comment">/* object frames */</span>
+<a name="l00038"></a>00038 <span class="preprocessor">#define FRAME_OFF    0 </span><span class="comment">/* off frames, that means sky frames or </span>
+<a name="l00039"></a>00039 <span class="comment">                          calibration frames with lamp switched off */</span>
+<a name="l00040"></a>00040 <span class="preprocessor">#define FRAME_POS1   2 </span><span class="comment">/* frames exposed with grating position 1 */</span>
+<a name="l00041"></a>00041 <span class="preprocessor">#define FRAME_POS2   3 </span><span class="comment">/* frames exposed with dithered grating position 2 */</span>
+<a name="l00042"></a>00042 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00043"></a>00043 <span class="comment">                             Function prototypes </span>
+<a name="l00044"></a>00044 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00045"></a>00045 
+<a name="l00058"></a>00058 flat_config * 
+<a name="l00059"></a>00059 sinfo_parse_cpl_input_flat(cpl_parameterlist * cpl_cfg, 
+<a name="l00060"></a>00060                cpl_frameset* sof, 
+<a name="l00061"></a>00061                            cpl_frameset** raw) ;
+<a name="l00062"></a>00062 
+<a name="l00069"></a>00069 <span class="keywordtype">void</span> sinfo_flat_free(flat_config ** cfg);
+<a name="l00070"></a>00070 
+<a name="l00071"></a>00071 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__focus_8c_source.html b/html/sinfo__focus_8c_source.html
new file mode 100644
index 0000000..956197f
--- /dev/null
+++ b/html/sinfo__focus_8c_source.html
@@ -0,0 +1,1373 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_focus.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_focus.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*******************************************************************************</span>
+<a name="l00020"></a>00020 <span class="comment">* E.S.O. - VLT project</span>
+<a name="l00021"></a>00021 <span class="comment">*</span>
+<a name="l00022"></a>00022 <span class="comment">*</span>
+<a name="l00023"></a>00023 <span class="comment">*</span>
+<a name="l00024"></a>00024 <span class="comment">* who       when      what</span>
+<a name="l00025"></a>00025 <span class="comment">* --------  --------  ----------------------------------------------</span>
+<a name="l00026"></a>00026 <span class="comment">* schreib  16/01/02  created</span>
+<a name="l00027"></a>00027 <span class="comment">*/</span>
+<a name="l00028"></a>00028 
+<a name="l00029"></a>00029 <span class="comment">/************************************************************************</span>
+<a name="l00030"></a>00030 <span class="comment">*   NAME</span>
+<a name="l00031"></a>00031 <span class="comment">*        sinfo_focus.c -</span>
+<a name="l00032"></a>00032 <span class="comment">*        routines to determine the focus position of the detector</span>
+<a name="l00033"></a>00033 <span class="comment">*</span>
+<a name="l00034"></a>00034 <span class="comment">*   SYNOPSIS</span>
+<a name="l00035"></a>00035 <span class="comment">*   #include "sinfo_focus.h"</span>
+<a name="l00036"></a>00036 <span class="comment">*</span>
+<a name="l00037"></a>00037 <span class="comment">*   1) double sinfo_new_gaussian_ellipse ( double * xdat, double * parlist )</span>
+<a name="l00038"></a>00038 <span class="comment">*   2) void sinfo_new_gaussian_ellipse_deriv( double * xdat, </span>
+<a name="l00039"></a>00039 <span class="comment">                                              double * parlist, </span>
+<a name="l00040"></a>00040 <span class="comment">                                              double * dervs )</span>
+<a name="l00041"></a>00041 <span class="comment">*   3) static int new_inv_mat (void)</span>
+<a name="l00042"></a>00042 <span class="comment">*   4) static void new_get_mat ( double * xdat,</span>
+<a name="l00043"></a>00043 <span class="comment">*                            int    * xdim,</span>
+<a name="l00044"></a>00044 <span class="comment">*                            double * ydat,</span>
+<a name="l00045"></a>00045 <span class="comment">*                            double * wdat,</span>
+<a name="l00046"></a>00046 <span class="comment">*                            int    * ndat,</span>
+<a name="l00047"></a>00047 <span class="comment">*                            double * fpar,</span>
+<a name="l00048"></a>00048 <span class="comment">*                            double * epar,</span>
+<a name="l00049"></a>00049 <span class="comment">*                            int    * npar )</span>
+<a name="l00050"></a>00050 <span class="comment">*   5) static int new_get_vec ( double * xdat,</span>
+<a name="l00051"></a>00051 <span class="comment">*                           int    * xdim,</span>
+<a name="l00052"></a>00052 <span class="comment">*                           double * ydat,</span>
+<a name="l00053"></a>00053 <span class="comment">*                           double * wdat,</span>
+<a name="l00054"></a>00054 <span class="comment">*                           int    * ndat,</span>
+<a name="l00055"></a>00055 <span class="comment">*                           double * fpar,</span>
+<a name="l00056"></a>00056 <span class="comment">*                           double * epar,</span>
+<a name="l00057"></a>00057 <span class="comment">*                           int    * npar )</span>
+<a name="l00058"></a>00058 <span class="comment">*   6) int new_lsqfit ( double * xdat,</span>
+<a name="l00059"></a>00059 <span class="comment">*                   int    * xdim,</span>
+<a name="l00060"></a>00060 <span class="comment">*                   double * ydat,</span>
+<a name="l00061"></a>00061 <span class="comment">*                   double * wdat,</span>
+<a name="l00062"></a>00062 <span class="comment">*                   int    * ndat,</span>
+<a name="l00063"></a>00063 <span class="comment">*                   double * fpar,</span>
+<a name="l00064"></a>00064 <span class="comment">*                   double * epar,</span>
+<a name="l00065"></a>00065 <span class="comment">*                   int    * mpar,</span>
+<a name="l00066"></a>00066 <span class="comment">*                   int    * npar,</span>
+<a name="l00067"></a>00067 <span class="comment">*                   double * tol ,</span>
+<a name="l00068"></a>00068 <span class="comment">*                   int    * its ,</span>
+<a name="l00069"></a>00069 <span class="comment">*                   double * lab  )</span>
+<a name="l00070"></a>00070 <span class="comment">*   7) int sinfo_new_fit_2d_gaussian( cpl_image   * lineImage, </span>
+<a name="l00071"></a>00071 <span class="comment">*                         double     * fit_par, </span>
+<a name="l00072"></a>00072 <span class="comment">*                         double     * derv_par   </span>
+<a name="l00073"></a>00073 <span class="comment">*                         int        * mpar,</span>
+<a name="l00074"></a>00074 <span class="comment">*                         int          lleftx,</span>
+<a name="l00075"></a>00075 <span class="comment">*                         int          llefty,</span>
+<a name="l00076"></a>00076 <span class="comment">*                         int          halfbox_x,</span>
+<a name="l00077"></a>00077 <span class="comment">*                         int          halfbox_y, int* check )</span>
+<a name="l00078"></a>00078 <span class="comment">*   8) cpl_image * sinfo_new_plot_gaussian ( cpl_image   * image, </span>
+<a name="l00079"></a>00079 <span class="comment">*                                double     * parlist )</span>
+<a name="l00080"></a>00080 <span class="comment">*   9) static int new_gauss2ellipse ( double     * parlist ,</span>
+<a name="l00081"></a>00081 <span class="comment">*  10) float sinfo_new_determine_conversion_factor ( cpl_imagelist * cube, </span>
+<a name="l00082"></a>00082 <span class="comment">*                                        float     mag,</span>
+<a name="l00083"></a>00083 <span class="comment">*                                        float     exptime,</span>
+<a name="l00084"></a>00084 <span class="comment">*                                        int       lleftx,</span>
+<a name="l00085"></a>00085 <span class="comment">*                                        int       llefty,</span>
+<a name="l00086"></a>00086 <span class="comment">*                                        int       halfbox_x,</span>
+<a name="l00087"></a>00087 <span class="comment">*                                        int       halfbox_y, </span>
+<a name="l00088"></a>00088 <span class="comment">*                                        int* check )</span>
+<a name="l00089"></a>00089 <span class="comment">*</span>
+<a name="l00090"></a>00090 <span class="comment">*   DESCRIPTION</span>
+<a name="l00091"></a>00091 <span class="comment">*   1) Compute the value of a 2d Gaussian function at a given point.</span>
+<a name="l00092"></a>00092 <span class="comment">*      The ellptical 2D Gaussian is:</span>
+<a name="l00093"></a>00093 <span class="comment">*      F(x,y) = par(2) * EXP( -4.0*log(2.0)*[(xr/par(4))^2+(yr/par(5))^2]) + </span>
+<a name="l00094"></a>00094 <span class="comment">                par(3),</span>
+<a name="l00095"></a>00095 <span class="comment">*      where: xr = xo * cos(par(6)) + yo * sin(par(6))</span>
+<a name="l00096"></a>00096 <span class="comment">*      yr = -xo * sin(par(6)) + yo * cos(par(6))</span>
+<a name="l00097"></a>00097 <span class="comment">*      and:   x0 = x - par(0)</span>
+<a name="l00098"></a>00098 <span class="comment">*             y0 = y - par(1)</span>
+<a name="l00099"></a>00099 <span class="comment">*   2) calculates the partial derivatives for a 2d Gaussian function with</span>
+<a name="l00100"></a>00100 <span class="comment">*      parameters parlist at position xdat </span>
+<a name="l00101"></a>00101 <span class="comment">*   3) calculates the inverse of matrix2. The algorithm used </span>
+<a name="l00102"></a>00102 <span class="comment">*      is the Gauss-Jordan algorithm described in Stoer,</span>
+<a name="l00103"></a>00103 <span class="comment">*      Numerische Mathematik, 1. Teil.</span>
+<a name="l00104"></a>00104 <span class="comment">*   4) builds the sinfo_matrix </span>
+<a name="l00105"></a>00105 <span class="comment">*   5) calculates the correction sinfo_vector. The sinfo_matrix has been</span>
+<a name="l00106"></a>00106 <span class="comment">*      built by get_mat(), we only have to rescale it for the </span>
+<a name="l00107"></a>00107 <span class="comment">*      current value of labda. The sinfo_matrix is rescaled so that</span>
+<a name="l00108"></a>00108 <span class="comment">*      the diagonal gets the value 1 + labda.</span>
+<a name="l00109"></a>00109 <span class="comment">*      Next we calculate the inverse of the sinfo_matrix and then</span>
+<a name="l00110"></a>00110 <span class="comment">*      the correction sinfo_vector.</span>
+<a name="l00111"></a>00111 <span class="comment">*   6) this is a routine for making a least-squares fit of a</span>
+<a name="l00112"></a>00112 <span class="comment">*      function to a set of data points. The method used is</span>
+<a name="l00113"></a>00113 <span class="comment">*      described in: Marquardt, J.Soc.Ind.Appl.Math. 11. 431 (1963).</span>
+<a name="l00114"></a>00114 <span class="comment">*      This method is a mixture of the steepest descent method </span>
+<a name="l00115"></a>00115 <span class="comment">*      and the Taylor method.</span>
+<a name="l00116"></a>00116 <span class="comment">*   7) fits the image of a point source by using a 2-D Gaussian</span>
+<a name="l00117"></a>00117 <span class="comment">*      fit.</span>
+<a name="l00118"></a>00118 <span class="comment">*   8) plots an image of a given 2D-Gaussian </span>
+<a name="l00119"></a>00119 <span class="comment">*   9) converts gauss parameters to ellipse parameters. </span>
+<a name="l00120"></a>00120 <span class="comment">*  10) determines an intensity conversion factor for the instrument</span>
+<a name="l00121"></a>00121 <span class="comment">*      by fitting a 2D-Gaussian to an collapsed image of a standard star</span>
+<a name="l00122"></a>00122 <span class="comment">*      with known brightness (only for non-AO observations).</span>
+<a name="l00123"></a>00123 <span class="comment">*      Then the resulting Gaussian is integrated and the counts</span>
+<a name="l00124"></a>00124 <span class="comment">*      are divided by the exposure time (Fits header information) </span>
+<a name="l00125"></a>00125 <span class="comment">*</span>
+<a name="l00126"></a>00126 <span class="comment">*   FILES</span>
+<a name="l00127"></a>00127 <span class="comment">*</span>
+<a name="l00128"></a>00128 <span class="comment">*   ENVIRONMENT</span>
+<a name="l00129"></a>00129 <span class="comment">*</span>
+<a name="l00130"></a>00130 <span class="comment">*   RETURN VALUES</span>
+<a name="l00131"></a>00131 <span class="comment">*</span>
+<a name="l00132"></a>00132 <span class="comment">*   CAUTIONS</span>
+<a name="l00133"></a>00133 <span class="comment">*</span>
+<a name="l00134"></a>00134 <span class="comment">*   EXAMPLES</span>
+<a name="l00135"></a>00135 <span class="comment">*</span>
+<a name="l00136"></a>00136 <span class="comment">*   SEE ALSO</span>
+<a name="l00137"></a>00137 <span class="comment">*</span>
+<a name="l00138"></a>00138 <span class="comment">*   BUGS</span>
+<a name="l00139"></a>00139 <span class="comment">*</span>
+<a name="l00140"></a>00140 <span class="comment">*------------------------------------------------------------------------</span>
+<a name="l00141"></a>00141 <span class="comment">*/</span>
+<a name="l00142"></a>00142 
+<a name="l00143"></a>00143 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00144"></a>00144 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00145"></a>00145 <span class="preprocessor">#endif</span>
+<a name="l00146"></a>00146 <span class="preprocessor"></span><span class="preprocessor">#include "sinfo_vltPort.h"</span>
+<a name="l00147"></a>00147 
+<a name="l00148"></a>00148 <span class="comment">/*</span>
+<a name="l00149"></a>00149 <span class="comment"> * System Headers</span>
+<a name="l00150"></a>00150 <span class="comment"> */</span>
+<a name="l00151"></a>00151 
+<a name="l00152"></a>00152 <span class="comment">/*</span>
+<a name="l00153"></a>00153 <span class="comment"> * Local Headers</span>
+<a name="l00154"></a>00154 <span class="comment"> */</span>
+<a name="l00155"></a>00155 
+<a name="l00156"></a>00156 <span class="preprocessor">#include "sinfo_focus.h"</span>
+<a name="l00157"></a>00157 <span class="preprocessor">#include "sinfo_recipes.h"</span>
+<a name="l00158"></a>00158 <span class="preprocessor">#include <float.h></span>
+<a name="l00159"></a>00159 
+<a name="l00160"></a>00160 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00161"></a>00161 <span class="comment"> *                                 Defines</span>
+<a name="l00162"></a>00162 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00163"></a>00163 
+<a name="l00164"></a>00164 <span class="preprocessor">#define XDIMG          2         </span><span class="comment">/* dimension of the x values */</span>
+<a name="l00165"></a>00165 <span class="preprocessor">#define TOLG           0.001     </span><span class="comment">/* fitting tolerance */</span>
+<a name="l00166"></a>00166 <span class="preprocessor">#define LABG           0.1       </span><span class="comment">/* labda parameter */</span>
+<a name="l00167"></a>00167 <span class="preprocessor">#define ITSG           200       </span><span class="comment">/* maximum number of iterations */</span>
+<a name="l00168"></a>00168 <span class="preprocessor">#define LABFACG        10.0      </span><span class="comment">/* labda step factor */</span>
+<a name="l00169"></a>00169 <span class="preprocessor">#define LABMAXG        1.0e+10   </span><span class="comment">/* maximum value for labda */</span>
+<a name="l00170"></a>00170 <span class="preprocessor">#define LABMING        1.0e-10   </span><span class="comment">/* minimum value for labda */</span>
+<a name="l00171"></a>00171 <span class="preprocessor">#define NPAR           7         </span><span class="comment">/* number of fit parameters */</span>
+<a name="l00172"></a>00172 <span class="preprocessor">#define PI_NUMB        (3.1415926535897932384626433832795) </span><span class="comment">/* pi */</span>
+<a name="l00173"></a>00173 
+<a name="l00174"></a>00174 
+<a name="l00175"></a>00175 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00176"></a>00176 <span class="comment"> *                                    Local variables</span>
+<a name="l00177"></a>00177 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00178"></a>00178 
+<a name="l00179"></a>00179 <span class="keyword">static</span> <span class="keywordtype">double</span> chi1 ;                    <span class="comment">/* old reduced chi-squared */</span>
+<a name="l00180"></a>00180 <span class="keyword">static</span> <span class="keywordtype">double</span> chi2 ;                    <span class="comment">/* new reduced chi-squared */</span>
+<a name="l00181"></a>00181 <span class="keyword">static</span> <span class="keywordtype">double</span> labda ;                   <span class="comment">/* mixing parameter */</span>
+<a name="l00182"></a>00182 <span class="keyword">static</span> <span class="keywordtype">double</span> vec[NPAR] ;               <span class="comment">/* correction sinfo_vector */</span>
+<a name="l00183"></a>00183 <span class="keyword">static</span> <span class="keywordtype">double</span> matrix1[NPAR][NPAR] ;     <span class="comment">/* original sinfo_matrix */</span>
+<a name="l00184"></a>00184 <span class="keyword">static</span> <span class="keywordtype">double</span> matrix2[NPAR][NPAR] ;     <span class="comment">/* inverse of matrix1 */</span>
+<a name="l00185"></a>00185 <span class="keyword">static</span> <span class="keywordtype">int</span>    nfree ;                   <span class="comment">/* number of free parameters */</span>
+<a name="l00186"></a>00186 <span class="keyword">static</span> <span class="keywordtype">int</span>    parptr[NPAR] ;            <span class="comment">/* parameter pointer */</span>
+<a name="l00187"></a>00187 
+<a name="l00188"></a>00188 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00189"></a>00189 <span class="comment"> *                    Functions private to this module</span>
+<a name="l00190"></a>00190 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00191"></a>00191 
+<a name="l00192"></a>00192 <span class="keyword">static</span> <span class="keywordtype">int</span> new_inv_mat (<span class="keywordtype">void</span>) ;
+<a name="l00193"></a>00193 
+<a name="l00194"></a>00194 <span class="keyword">static</span> <span class="keywordtype">void</span> new_get_mat ( <span class="keywordtype">double</span> * xdat,
+<a name="l00195"></a>00195                       <span class="keywordtype">int</span>    * xdim,
+<a name="l00196"></a>00196                       <span class="keywordtype">double</span> * ydat,
+<a name="l00197"></a>00197                       <span class="keywordtype">double</span> * wdat,
+<a name="l00198"></a>00198                       <span class="keywordtype">int</span>    * ndat,
+<a name="l00199"></a>00199                       <span class="keywordtype">double</span> * fpar,
+<a name="l00200"></a>00200                       <span class="keywordtype">double</span> * epar<span class="comment">/*,</span>
+<a name="l00201"></a>00201 <span class="comment">                      int    * npar */</span>) ;
+<a name="l00202"></a>00202 
+<a name="l00203"></a>00203 <span class="keyword">static</span> <span class="keywordtype">int</span> new_get_vec ( <span class="keywordtype">double</span> * xdat,
+<a name="l00204"></a>00204                      <span class="keywordtype">int</span>    * xdim,
+<a name="l00205"></a>00205                      <span class="keywordtype">double</span> * ydat,
+<a name="l00206"></a>00206                      <span class="keywordtype">double</span> * wdat,
+<a name="l00207"></a>00207                      <span class="keywordtype">int</span>    * ndat,
+<a name="l00208"></a>00208                      <span class="keywordtype">double</span> * fpar,
+<a name="l00209"></a>00209                      <span class="keywordtype">double</span> * epar,
+<a name="l00210"></a>00210                      <span class="keywordtype">int</span>    * npar ) ;
+<a name="l00211"></a>00211 
+<a name="l00212"></a>00212 <span class="keyword">static</span> <span class="keywordtype">int</span> new_gauss2Ellipse ( <span class="keywordtype">double</span>  * parlist ) ;
+<a name="l00221"></a>00221 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00222"></a>00222 <span class="comment"> *                            Function codes</span>
+<a name="l00223"></a>00223 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00224"></a>00224 
+<a name="l00225"></a>00225 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l00249"></a>00249 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00250"></a>00250 
+<a name="l00251"></a>00251 <span class="keywordtype">double</span> sinfo_new_gaussian_ellipse(<span class="keywordtype">double</span> * xdat, <span class="keywordtype">double</span> * parlist)
+<a name="l00252"></a>00252 {
+<a name="l00253"></a>00253     <span class="keywordtype">double</span>  result ;
+<a name="l00254"></a>00254     <span class="keywordtype">double</span> x ;
+<a name="l00255"></a>00255     <span class="keywordtype">double</span> y ;
+<a name="l00256"></a>00256     <span class="keywordtype">double</span> fwhmx ;
+<a name="l00257"></a>00257     <span class="keywordtype">double</span> fwhmy ;
+<a name="l00258"></a>00258     <span class="keywordtype">double</span> costheta ;
+<a name="l00259"></a>00259     <span class="keywordtype">double</span> sintheta ;
+<a name="l00260"></a>00260     <span class="keywordtype">double</span> argX ;           <span class="comment">/* arguments in the exponent */</span>
+<a name="l00261"></a>00261     <span class="keywordtype">double</span> argY ;
+<a name="l00262"></a>00262 
+<a name="l00263"></a>00263     <span class="comment">/* some abbreviations */</span>
+<a name="l00264"></a>00264     x =  xdat[0] -  parlist[0] ;
+<a name="l00265"></a>00265     y =  xdat[1] -  parlist[1] ;
+<a name="l00266"></a>00266 
+<a name="l00267"></a>00267     fwhmx = fabs(parlist[4]) ;
+<a name="l00268"></a>00268     fwhmy = fabs(parlist[5]) ;
+<a name="l00269"></a>00269     
+<a name="l00270"></a>00270     costheta = cos ( parlist[6] ) ;
+<a name="l00271"></a>00271     sintheta = sin ( parlist[6] ) ;
+<a name="l00272"></a>00272 
+<a name="l00273"></a>00273     argX = x * costheta + y * sintheta ;
+<a name="l00274"></a>00274     argY = -x * sintheta + y * costheta ;
+<a name="l00275"></a>00275     
+<a name="l00276"></a>00276     <span class="comment">/* function */</span>
+<a name="l00277"></a>00277     result =  parlist[2] * exp(-4.*log(2.0)*((argX/fwhmx)*(argX/fwhmx)+
+<a name="l00278"></a>00278                                              (argY/fwhmy)*(argY/fwhmy))) +
+<a name="l00279"></a>00279               parlist[3] ; 
+<a name="l00280"></a>00280 
+<a name="l00281"></a>00281     <span class="keywordflow">return</span> result ;
+<a name="l00282"></a>00282 }
+<a name="l00283"></a>00283 
+<a name="l00308"></a>00308 <span class="keywordtype">void</span> 
+<a name="l00309"></a>00309 sinfo_new_gaussian_ellipse_deriv(<span class="keywordtype">double</span> * xdat, 
+<a name="l00310"></a>00310                                  <span class="keywordtype">double</span> * parlist, 
+<a name="l00311"></a>00311                                  <span class="keywordtype">double</span> * dervs )
+<a name="l00312"></a>00312 {
+<a name="l00313"></a>00313     <span class="keywordtype">double</span> x ;
+<a name="l00314"></a>00314     <span class="keywordtype">double</span> y ;
+<a name="l00315"></a>00315     <span class="keywordtype">double</span> fwhmx ;
+<a name="l00316"></a>00316     <span class="keywordtype">double</span> fwhmy ;
+<a name="l00317"></a>00317     <span class="keywordtype">double</span> argX ;
+<a name="l00318"></a>00318     <span class="keywordtype">double</span> argY ;
+<a name="l00319"></a>00319     <span class="keywordtype">double</span> expon ;
+<a name="l00320"></a>00320     <span class="keywordtype">double</span> e8log2 ;
+<a name="l00321"></a>00321     <span class="keywordtype">double</span> fwx2 ;
+<a name="l00322"></a>00322     <span class="keywordtype">double</span> fwy2 ;
+<a name="l00323"></a>00323     <span class="keywordtype">double</span> costheta ;
+<a name="l00324"></a>00324     <span class="keywordtype">double</span> sintheta ;
+<a name="l00325"></a>00325 
+<a name="l00326"></a>00326     <span class="comment">/* some abbreviations */</span>
+<a name="l00327"></a>00327     x = xdat[0] - parlist[0] ;
+<a name="l00328"></a>00328     y = xdat[1] - parlist[1] ;
+<a name="l00329"></a>00329 
+<a name="l00330"></a>00330     fwhmx = fabs(parlist[4]) ;
+<a name="l00331"></a>00331     fwhmy = fabs(parlist[5]) ;
+<a name="l00332"></a>00332     fwx2 = fwhmx * fwhmx ;
+<a name="l00333"></a>00333     fwy2 = fwhmy * fwhmy ;
+<a name="l00334"></a>00334 
+<a name="l00335"></a>00335     costheta = cos ( parlist[6] ) ;
+<a name="l00336"></a>00336     sintheta = sin ( parlist[6] ) ;
+<a name="l00337"></a>00337 
+<a name="l00338"></a>00338     argX = x * costheta + y * sintheta ;
+<a name="l00339"></a>00339     argY = -x * sintheta + y * costheta ;
+<a name="l00340"></a>00340 
+<a name="l00341"></a>00341     expon = exp ( -4.0 * log(2.0) * ((argX/fwhmx)*(argX/fwhmx) + 
+<a name="l00342"></a>00342                                      (argY/fwhmy)*(argY/fwhmy)) ) ;
+<a name="l00343"></a>00343     e8log2 = expon * 8.0 * log(2.0) ;
+<a name="l00344"></a>00344 
+<a name="l00345"></a>00345     <span class="comment">/* determine the derivatives */</span>
+<a name="l00346"></a>00346     <span class="comment">/* partial derivative x-position */</span>
+<a name="l00347"></a>00347     dervs[0] = -parlist[2]*e8log2 * (-argX*costheta/fwx2 + argY*sintheta/fwy2);
+<a name="l00348"></a>00348     <span class="comment">/* partial derivative y-position */</span>
+<a name="l00349"></a>00349     dervs[1] = -parlist[2]*e8log2 * (-argX*sintheta/fwx2 - argY*costheta/fwy2);
+<a name="l00350"></a>00350     <span class="comment">/* partial derivative amplitude */</span>
+<a name="l00351"></a>00351     dervs[2] = expon ;
+<a name="l00352"></a>00352     <span class="comment">/* partial derivative background */</span>
+<a name="l00353"></a>00353     dervs[3] = 1. ;
+<a name="l00354"></a>00354     <span class="comment">/* partial derivative fwhmx */</span>
+<a name="l00355"></a>00355     dervs[4] = parlist[2]*e8log2 * argX*argX/(fwx2*fwhmx) ;
+<a name="l00356"></a>00356     <span class="comment">/* partial derivative fwhmy */</span>
+<a name="l00357"></a>00357     dervs[5] = parlist[2]*e8log2 * argY*argY/(fwy2*fwhmy) ;
+<a name="l00358"></a>00358     <span class="comment">/* partial derivative theta */</span>
+<a name="l00359"></a>00359     dervs[6] = -parlist[2]*e8log2 * argY * argX * (1.0/fwx2 - 1.0/fwy2) ;
+<a name="l00360"></a>00360     
+<a name="l00361"></a>00361 }
+<a name="l00362"></a>00362 
+<a name="l00373"></a>00373 <span class="keyword">static</span> <span class="keywordtype">int</span> new_inv_mat (<span class="keywordtype">void</span>)
+<a name="l00374"></a>00374 {
+<a name="l00375"></a>00375     <span class="keywordtype">double</span> even ;
+<a name="l00376"></a>00376     <span class="keywordtype">double</span> hv[NPAR] ;
+<a name="l00377"></a>00377     <span class="keywordtype">double</span> mjk ;
+<a name="l00378"></a>00378     <span class="keywordtype">double</span> rowmax ;
+<a name="l00379"></a>00379     <span class="keywordtype">int</span> evin ;
+<a name="l00380"></a>00380     <span class="keywordtype">int</span> i, j, k, row ;
+<a name="l00381"></a>00381     <span class="keywordtype">int</span> per[NPAR] ;
+<a name="l00382"></a>00382    
+<a name="l00383"></a>00383     <span class="comment">/* set permutation array */</span>
+<a name="l00384"></a>00384     <span class="keywordflow">for</span> ( i = 0 ; i < nfree ; i++ )
+<a name="l00385"></a>00385     {
+<a name="l00386"></a>00386         per[i] = i ;
+<a name="l00387"></a>00387     }
+<a name="l00388"></a>00388     
+<a name="l00389"></a>00389     <span class="keywordflow">for</span> ( j = 0 ; j < nfree ; j++ ) <span class="comment">/* in j-th column */</span>
+<a name="l00390"></a>00390     {
+<a name="l00391"></a>00391         <span class="comment">/* determine largest element of a row */</span>                                
+<a name="l00392"></a>00392         rowmax = fabs ( matrix2[j][j] ) ;
+<a name="l00393"></a>00393         row = j ;                         
+<a name="l00394"></a>00394 
+<a name="l00395"></a>00395         <span class="keywordflow">for</span> ( i = j + 1 ; i < nfree ; i++ )
+<a name="l00396"></a>00396         {
+<a name="l00397"></a>00397             <span class="keywordflow">if</span> ( fabs ( matrix2[i][j] ) > rowmax )
+<a name="l00398"></a>00398             {
+<a name="l00399"></a>00399                 rowmax = fabs( matrix2[i][j] ) ;
+<a name="l00400"></a>00400                 row = i ;
+<a name="l00401"></a>00401             }
+<a name="l00402"></a>00402         }
+<a name="l00403"></a>00403 
+<a name="l00404"></a>00404         <span class="comment">/* determinant is zero! */</span>
+<a name="l00405"></a>00405         <span class="keywordflow">if</span> ( matrix2[row][j] == 0.0 )
+<a name="l00406"></a>00406         {
+<a name="l00407"></a>00407             <span class="keywordflow">return</span> -6 ;
+<a name="l00408"></a>00408         }
+<a name="l00409"></a>00409         
+<a name="l00410"></a>00410         <span class="comment">/* if the largest element is not on the diagonal, </span>
+<a name="l00411"></a>00411 <span class="comment">           then permutate rows */</span>
+<a name="l00412"></a>00412         <span class="keywordflow">if</span> ( row > j )
+<a name="l00413"></a>00413         {
+<a name="l00414"></a>00414             <span class="keywordflow">for</span> ( k = 0 ; k < nfree ; k++ )
+<a name="l00415"></a>00415             {
+<a name="l00416"></a>00416                 even = matrix2[j][k] ;
+<a name="l00417"></a>00417                 matrix2[j][k] = matrix2[row][k] ;
+<a name="l00418"></a>00418                 matrix2[row][k] = even ;
+<a name="l00419"></a>00419             }
+<a name="l00420"></a>00420             <span class="comment">/* keep track of permutation */</span>
+<a name="l00421"></a>00421             evin = per[j] ;
+<a name="l00422"></a>00422             per[j] = per[row] ;
+<a name="l00423"></a>00423             per[row] = evin ;
+<a name="l00424"></a>00424         }
+<a name="l00425"></a>00425         
+<a name="l00426"></a>00426         <span class="comment">/* modify column */</span>
+<a name="l00427"></a>00427         even = 1.0 / matrix2[j][j] ;
+<a name="l00428"></a>00428         <span class="keywordflow">for</span> ( i = 0 ; i < nfree ; i++ )
+<a name="l00429"></a>00429         {
+<a name="l00430"></a>00430             matrix2[i][j] *= even ;
+<a name="l00431"></a>00431         }
+<a name="l00432"></a>00432         matrix2[j][j] = even ;
+<a name="l00433"></a>00433         
+<a name="l00434"></a>00434         <span class="keywordflow">for</span> ( k = 0 ; k < j ; k++ )
+<a name="l00435"></a>00435         {
+<a name="l00436"></a>00436             mjk = matrix2[j][k] ;
+<a name="l00437"></a>00437             <span class="keywordflow">for</span> ( i = 0 ; i < j ; i++ )
+<a name="l00438"></a>00438             {
+<a name="l00439"></a>00439                 matrix2[i][k] -= matrix2[i][j] * mjk ;
+<a name="l00440"></a>00440             }
+<a name="l00441"></a>00441             <span class="keywordflow">for</span> ( i = j + 1 ; i < nfree ; i++ )
+<a name="l00442"></a>00442             {
+<a name="l00443"></a>00443                 matrix2[i][k] -= matrix2[i][j] * mjk ;
+<a name="l00444"></a>00444             }
+<a name="l00445"></a>00445             matrix2[j][k] = -even * mjk ;
+<a name="l00446"></a>00446         }
+<a name="l00447"></a>00447     
+<a name="l00448"></a>00448         <span class="keywordflow">for</span> ( k = j + 1 ; k < nfree ; k++ )
+<a name="l00449"></a>00449         {
+<a name="l00450"></a>00450             mjk = matrix2[j][k] ;
+<a name="l00451"></a>00451             <span class="keywordflow">for</span> ( i = 0 ; i < j ; i++ )
+<a name="l00452"></a>00452             {
+<a name="l00453"></a>00453                 matrix2[i][k]  -= matrix2[i][j] * mjk ;
+<a name="l00454"></a>00454             }
+<a name="l00455"></a>00455             <span class="keywordflow">for</span> ( i = j + 1 ; i < nfree ; i++ )
+<a name="l00456"></a>00456             {
+<a name="l00457"></a>00457                 matrix2[i][k]  -= matrix2[i][j] * mjk ;
+<a name="l00458"></a>00458             }
+<a name="l00459"></a>00459             matrix2[j][k] = -even * mjk ;
+<a name="l00460"></a>00460         }
+<a name="l00461"></a>00461     }
+<a name="l00462"></a>00462     
+<a name="l00463"></a>00463     <span class="comment">/* finally, repermute the columns */</span>
+<a name="l00464"></a>00464     <span class="keywordflow">for</span> ( i = 0 ; i < nfree ; i++ )
+<a name="l00465"></a>00465     {
+<a name="l00466"></a>00466         <span class="keywordflow">for</span> ( k = 0 ; k < nfree ; k++ )
+<a name="l00467"></a>00467         {
+<a name="l00468"></a>00468             hv[per[k]] = matrix2[i][k] ;
+<a name="l00469"></a>00469         }
+<a name="l00470"></a>00470         <span class="keywordflow">for</span> ( k = 0 ; k < nfree ; k++ )
+<a name="l00471"></a>00471         {
+<a name="l00472"></a>00472             matrix2[i][k] = hv[k] ;
+<a name="l00473"></a>00473         }
+<a name="l00474"></a>00474     }
+<a name="l00475"></a>00475         
+<a name="l00476"></a>00476     <span class="comment">/* all is well */</span>
+<a name="l00477"></a>00477     <span class="keywordflow">return</span> 0 ;
+<a name="l00478"></a>00478 }
+<a name="l00479"></a>00479     
+<a name="l00495"></a>00495 <span class="keyword">static</span> <span class="keywordtype">void</span> new_get_mat ( <span class="keywordtype">double</span> * xdat,
+<a name="l00496"></a>00496                       <span class="keywordtype">int</span>    * xdim,
+<a name="l00497"></a>00497                       <span class="keywordtype">double</span> * ydat,
+<a name="l00498"></a>00498                       <span class="keywordtype">double</span> * wdat,
+<a name="l00499"></a>00499                       <span class="keywordtype">int</span>    * ndat,
+<a name="l00500"></a>00500                       <span class="keywordtype">double</span> * fpar,
+<a name="l00501"></a>00501                       <span class="keywordtype">double</span> * epar<span class="comment">/*,</span>
+<a name="l00502"></a>00502 <span class="comment">                      int    * npar */</span>)
+<a name="l00503"></a>00503 {
+<a name="l00504"></a>00504     <span class="keywordtype">double</span> wd ;
+<a name="l00505"></a>00505     <span class="keywordtype">double</span> wn ;
+<a name="l00506"></a>00506     <span class="keywordtype">double</span> yd ;
+<a name="l00507"></a>00507     <span class="keywordtype">int</span> i, j, n ;
+<a name="l00508"></a>00508 
+<a name="l00509"></a>00509     <span class="keywordflow">for</span> ( j = 0 ; j < nfree ; j++ )
+<a name="l00510"></a>00510     {
+<a name="l00511"></a>00511         vec[j] = 0.0 ; <span class="comment">/* zero sinfo_vector */</span>
+<a name="l00512"></a>00512         <span class="keywordflow">for</span> ( i = 0 ; i<= j ; i++ )   <span class="comment">/* zero sinfo_matrix only on </span>
+<a name="l00513"></a>00513 <span class="comment">                                         and below diagonal */</span>
+<a name="l00514"></a>00514         {
+<a name="l00515"></a>00515             matrix1[j][i] = 0.0 ;
+<a name="l00516"></a>00516         }
+<a name="l00517"></a>00517     }
+<a name="l00518"></a>00518     chi2 = 0.0 ;  <span class="comment">/* reset reduced chi-squared */</span>
+<a name="l00519"></a>00519     
+<a name="l00520"></a>00520     <span class="comment">/* loop through data points */</span>
+<a name="l00521"></a>00521     <span class="keywordflow">for</span> ( n = 0 ; n < (*ndat) ; n++ )
+<a name="l00522"></a>00522     {
+<a name="l00523"></a>00523         wn = wdat[n] ;
+<a name="l00524"></a>00524         <span class="keywordflow">if</span> ( wn > 0.0 )  <span class="comment">/* legal weight ? */</span>
+<a name="l00525"></a>00525         {
+<a name="l00526"></a>00526             yd=ydat[n] - sinfo_new_gaussian_ellipse(&xdat[(*xdim) * n],fpar) ;
+<a name="l00527"></a>00527             sinfo_new_gaussian_ellipse_deriv( &xdat[(*xdim) * n], fpar, epar ) ;
+<a name="l00528"></a>00528             chi2 += yd * yd * wn ; <span class="comment">/* add to chi-squared */</span>
+<a name="l00529"></a>00529             <span class="keywordflow">for</span> ( j = 0 ; j < nfree ; j++ )
+<a name="l00530"></a>00530             {
+<a name="l00531"></a>00531                 wd = epar[parptr[j]] * wn ;  <span class="comment">/* weighted derivative */</span>
+<a name="l00532"></a>00532                 vec[j] += yd * wd ;       <span class="comment">/* fill sinfo_vector */</span>
+<a name="l00533"></a>00533                 <span class="keywordflow">for</span> ( i = 0 ; i <= j ; i++ ) <span class="comment">/* fill sinfo_matrix */</span>
+<a name="l00534"></a>00534                 {
+<a name="l00535"></a>00535                     matrix1[j][i] += epar[parptr[i]] * wd ;
+<a name="l00536"></a>00536                 }
+<a name="l00537"></a>00537             }
+<a name="l00538"></a>00538         }
+<a name="l00539"></a>00539     }                   
+<a name="l00540"></a>00540 }  
+<a name="l00541"></a>00541                 
+<a name="l00542"></a>00542             
+<a name="l00568"></a>00568 <span class="keyword">static</span> <span class="keywordtype">int</span> new_get_vec ( <span class="keywordtype">double</span> * xdat,
+<a name="l00569"></a>00569                      <span class="keywordtype">int</span>    * xdim,
+<a name="l00570"></a>00570                      <span class="keywordtype">double</span> * ydat,
+<a name="l00571"></a>00571                      <span class="keywordtype">double</span> * wdat,
+<a name="l00572"></a>00572                      <span class="keywordtype">int</span>    * ndat,
+<a name="l00573"></a>00573                      <span class="keywordtype">double</span> * fpar,
+<a name="l00574"></a>00574                      <span class="keywordtype">double</span> * epar,
+<a name="l00575"></a>00575                      <span class="keywordtype">int</span>    * npar )
+<a name="l00576"></a>00576 {
+<a name="l00577"></a>00577     <span class="keywordtype">double</span> dj ;
+<a name="l00578"></a>00578     <span class="keywordtype">double</span> dy ;
+<a name="l00579"></a>00579     <span class="keywordtype">double</span> mii ;
+<a name="l00580"></a>00580     <span class="keywordtype">double</span> mji ;
+<a name="l00581"></a>00581     <span class="keywordtype">double</span> mjj ;
+<a name="l00582"></a>00582     <span class="keywordtype">double</span> wn ;
+<a name="l00583"></a>00583     <span class="keywordtype">int</span> i, j, n, r ;
+<a name="l00584"></a>00584 
+<a name="l00585"></a>00585     <span class="comment">/* loop to modify and scale the sinfo_matrix */</span>
+<a name="l00586"></a>00586     <span class="keywordflow">for</span> ( j = 0 ; j < nfree ; j++ )
+<a name="l00587"></a>00587     {
+<a name="l00588"></a>00588         mjj = matrix1[j][j] ;
+<a name="l00589"></a>00589         <span class="keywordflow">if</span> ( mjj <= 0.0 )             <span class="comment">/* diagonal element wrong */</span>
+<a name="l00590"></a>00590         {
+<a name="l00591"></a>00591             <span class="keywordflow">return</span> -5 ;
+<a name="l00592"></a>00592         }
+<a name="l00593"></a>00593         mjj = sqrt( mjj ) ;
+<a name="l00594"></a>00594         <span class="keywordflow">for</span> ( i = 0 ; i < j ; i++ )
+<a name="l00595"></a>00595         {
+<a name="l00596"></a>00596             mji = matrix1[j][i] / mjj / sqrt( matrix1[i][i] ) ;
+<a name="l00597"></a>00597             matrix2[i][j] = matrix2[j][i] = mji ;
+<a name="l00598"></a>00598         }
+<a name="l00599"></a>00599         matrix2[j][j] = 1.0 + labda ;  <span class="comment">/* scaled value on diagonal */</span>
+<a name="l00600"></a>00600     }    
+<a name="l00601"></a>00601     
+<a name="l00602"></a>00602     <span class="keywordflow">if</span> ( (r = new_inv_mat()) ) <span class="comment">/* sinfo_invert sinfo_matrix inlace */</span>
+<a name="l00603"></a>00603     {
+<a name="l00604"></a>00604         <span class="keywordflow">return</span> r ;
+<a name="l00605"></a>00605     }
+<a name="l00606"></a>00606     
+<a name="l00607"></a>00607     <span class="keywordflow">for</span> ( i = 0 ; i < (*npar) ; i ++ )
+<a name="l00608"></a>00608     {
+<a name="l00609"></a>00609         epar[i] = fpar[i] ;
+<a name="l00610"></a>00610     }
+<a name="l00611"></a>00611     
+<a name="l00612"></a>00612     <span class="comment">/* loop to calculate correction sinfo_vector */</span>
+<a name="l00613"></a>00613     <span class="keywordflow">for</span> ( j = 0 ; j < nfree ; j++ )
+<a name="l00614"></a>00614     {
+<a name="l00615"></a>00615         dj = 0.0 ;
+<a name="l00616"></a>00616         mjj = matrix1[j][j] ;
+<a name="l00617"></a>00617         <span class="keywordflow">if</span> ( mjj <= 0.0)               <span class="comment">/* not allowed */</span>
+<a name="l00618"></a>00618         {
+<a name="l00619"></a>00619             <span class="keywordflow">return</span> -7 ;
+<a name="l00620"></a>00620         }
+<a name="l00621"></a>00621         mjj = sqrt ( mjj ) ;
+<a name="l00622"></a>00622         <span class="keywordflow">for</span> ( i = 0 ; i < nfree ; i++ )
+<a name="l00623"></a>00623         {
+<a name="l00624"></a>00624             mii = matrix1[i][i] ;
+<a name="l00625"></a>00625             <span class="keywordflow">if</span> ( mii <= 0.0 )
+<a name="l00626"></a>00626             {
+<a name="l00627"></a>00627                 <span class="keywordflow">return</span> -7 ;
+<a name="l00628"></a>00628             }
+<a name="l00629"></a>00629             mii = sqrt( mii ) ;
+<a name="l00630"></a>00630             dj += vec[i] * matrix2[j][i] / mjj / mii ;
+<a name="l00631"></a>00631         }
+<a name="l00632"></a>00632         epar[parptr[j]] += dj ;       <span class="comment">/* new parameters */</span>
+<a name="l00633"></a>00633     }    
+<a name="l00634"></a>00634     chi1 = 0.0 ;                      <span class="comment">/* reset reduced chi-squared */</span>
+<a name="l00635"></a>00635  
+<a name="l00636"></a>00636     <span class="comment">/* loop through the data points */</span>
+<a name="l00637"></a>00637     <span class="keywordflow">for</span> ( n = 0 ; n < (*ndat) ; n++ )
+<a name="l00638"></a>00638     {
+<a name="l00639"></a>00639         wn = wdat[n] ;               <span class="comment">/* get weight */</span>
+<a name="l00640"></a>00640         <span class="keywordflow">if</span> ( wn > 0.0 )              <span class="comment">/* legal weight */</span>
+<a name="l00641"></a>00641         {
+<a name="l00642"></a>00642             dy=ydat[n] - sinfo_new_gaussian_ellipse(&xdat[(*xdim) * n],epar);
+<a name="l00643"></a>00643             chi1 += wdat[n] * dy * dy ;
+<a name="l00644"></a>00644         }
+<a name="l00645"></a>00645     }
+<a name="l00646"></a>00646     <span class="keywordflow">return</span> 0 ;
+<a name="l00647"></a>00647 }   
+<a name="l00648"></a>00648     
+<a name="l00649"></a>00649         
+<a name="l00650"></a>00650 
+<a name="l00698"></a>00698 <span class="keywordtype">int</span> sinfo_new_lsqfitd ( <span class="keywordtype">double</span> * xdat,
+<a name="l00699"></a>00699               <span class="keywordtype">int</span>    * xdim,
+<a name="l00700"></a>00700               <span class="keywordtype">double</span> * ydat,
+<a name="l00701"></a>00701               <span class="keywordtype">double</span> * wdat,
+<a name="l00702"></a>00702               <span class="keywordtype">int</span>    * ndat,
+<a name="l00703"></a>00703               <span class="keywordtype">double</span> * fpar,
+<a name="l00704"></a>00704               <span class="keywordtype">double</span> * epar,
+<a name="l00705"></a>00705               <span class="keywordtype">int</span>    * mpar,
+<a name="l00706"></a>00706               <span class="keywordtype">int</span>    * npar,
+<a name="l00707"></a>00707               <span class="keywordtype">double</span> * tol ,
+<a name="l00708"></a>00708               <span class="keywordtype">int</span>    * its ,
+<a name="l00709"></a>00709               <span class="keywordtype">double</span> * lab  )
+<a name="l00710"></a>00710 {
+<a name="l00711"></a>00711     <span class="keywordtype">int</span> i, n, r ;
+<a name="l00712"></a>00712     <span class="keywordtype">int</span> itc ;                      <span class="comment">/* fate of fit */</span>
+<a name="l00713"></a>00713     <span class="keywordtype">int</span> found ;                    <span class="comment">/* fit converged: 1, not yet converged: 0 */</span>
+<a name="l00714"></a>00714     <span class="keywordtype">int</span>  nuse ;                    <span class="comment">/* number of useable data points */</span>
+<a name="l00715"></a>00715     <span class="keywordtype">double</span> tolerance ;             <span class="comment">/* accuracy */</span>
+<a name="l00716"></a>00716 
+<a name="l00717"></a>00717     itc   = 0 ;                    <span class="comment">/* fate of fit */</span>
+<a name="l00718"></a>00718     found = 0 ;                    <span class="comment">/* reset */</span>
+<a name="l00719"></a>00719     nfree = 0 ;                    <span class="comment">/* number of free parameters */</span>
+<a name="l00720"></a>00720     nuse  = 0 ;                    <span class="comment">/* number of legal data points */</span>
+<a name="l00721"></a>00721 
+<a name="l00722"></a>00722     <span class="keywordflow">if</span> ( *tol < (DBL_EPSILON * 10.0 ) )
+<a name="l00723"></a>00723     {
+<a name="l00724"></a>00724         tolerance = DBL_EPSILON * 10.0 ;  <span class="comment">/* default tolerance */</span>
+<a name="l00725"></a>00725     }
+<a name="l00726"></a>00726     <span class="keywordflow">else</span>
+<a name="l00727"></a>00727     {
+<a name="l00728"></a>00728         tolerance = *tol ;                <span class="comment">/* tolerance */</span>
+<a name="l00729"></a>00729     }
+<a name="l00730"></a>00730     
+<a name="l00731"></a>00731     labda = fabs( *lab ) * LABFACG ; <span class="comment">/* start value for mixing parameter */</span>
+<a name="l00732"></a>00732     <span class="keywordflow">for</span> ( i = 0 ; i < (*npar) ; i++ )
+<a name="l00733"></a>00733     {
+<a name="l00734"></a>00734         <span class="keywordflow">if</span> ( mpar[i] )
+<a name="l00735"></a>00735         {
+<a name="l00736"></a>00736             <span class="keywordflow">if</span> ( nfree > NPAR )         <span class="comment">/* too many free parameters */</span>
+<a name="l00737"></a>00737             {
+<a name="l00738"></a>00738                 <span class="keywordflow">return</span> -1 ;
+<a name="l00739"></a>00739             }
+<a name="l00740"></a>00740             parptr[nfree++] = i ;         <span class="comment">/* a free parameter */</span>
+<a name="l00741"></a>00741         }
+<a name="l00742"></a>00742     }
+<a name="l00743"></a>00743     
+<a name="l00744"></a>00744     <span class="keywordflow">if</span> (nfree == 0)                       <span class="comment">/* no free parameters */</span>     
+<a name="l00745"></a>00745     {
+<a name="l00746"></a>00746         <span class="keywordflow">return</span> -2 ;
+<a name="l00747"></a>00747     }
+<a name="l00748"></a>00748     
+<a name="l00749"></a>00749     <span class="keywordflow">for</span> ( n = 0 ; n < (*ndat) ; n++ )
+<a name="l00750"></a>00750     {
+<a name="l00751"></a>00751         <span class="keywordflow">if</span> ( wdat[n] > 0.0 )              <span class="comment">/* legal weight */</span>
+<a name="l00752"></a>00752         {
+<a name="l00753"></a>00753             nuse ++ ;
+<a name="l00754"></a>00754         }
+<a name="l00755"></a>00755     }
+<a name="l00756"></a>00756     
+<a name="l00757"></a>00757     <span class="keywordflow">if</span> ( nfree >= nuse )
+<a name="l00758"></a>00758     {
+<a name="l00759"></a>00759         <span class="keywordflow">return</span> -3 ;                       <span class="comment">/* no degrees of freedom */</span>
+<a name="l00760"></a>00760     }
+<a name="l00761"></a>00761     <span class="keywordflow">if</span> ( labda == 0.0 )                   <span class="comment">/* linear fit */</span>
+<a name="l00762"></a>00762     {
+<a name="l00763"></a>00763         <span class="comment">/* initialize fpar array */</span>
+<a name="l00764"></a>00764         <span class="keywordflow">for</span> ( i = 0 ; i < nfree ; fpar[parptr[i++]] = 0.0 ) ;  
+<a name="l00765"></a>00765         new_get_mat ( xdat, xdim, ydat, wdat, ndat, fpar, epar<span class="comment">/*, npar */</span>) ;
+<a name="l00766"></a>00766         r =  new_get_vec ( xdat, xdim, ydat, wdat, ndat, fpar, epar, npar ) ;
+<a name="l00767"></a>00767         <span class="keywordflow">if</span> ( r )                         <span class="comment">/* error */</span>
+<a name="l00768"></a>00768         {
+<a name="l00769"></a>00769             <span class="keywordflow">return</span> r ;
+<a name="l00770"></a>00770         }
+<a name="l00771"></a>00771         <span class="keywordflow">for</span> ( i = 0 ; i < (*npar) ; i++ )
+<a name="l00772"></a>00772         {
+<a name="l00773"></a>00773             fpar[i] = epar[i] ;           <span class="comment">/* save new parameters */</span>
+<a name="l00774"></a>00774             epar[i] = 0.0 ;               <span class="comment">/* and set errors to zero */</span>
+<a name="l00775"></a>00775         }
+<a name="l00776"></a>00776         chi1 = sqrt( chi1 / (<span class="keywordtype">double</span>) (nuse - nfree) ) ;
+<a name="l00777"></a>00777         <span class="keywordflow">for</span> ( i = 0 ; i < nfree ; i++ )
+<a name="l00778"></a>00778         {
+<a name="l00779"></a>00779             <span class="keywordflow">if</span> ( (matrix1[i][i] <= 0.0 ) || (matrix2[i][i] <= 0.0) )
+<a name="l00780"></a>00780             {
+<a name="l00781"></a>00781                 <span class="keywordflow">return</span> -7 ;
+<a name="l00782"></a>00782             }
+<a name="l00783"></a>00783             epar[parptr[i]] = chi1 * sqrt( matrix2[i][i] ) / 
+<a name="l00784"></a>00784                                      sqrt( matrix1[i][i] ) ;
+<a name="l00785"></a>00785         }
+<a name="l00786"></a>00786     }
+<a name="l00787"></a>00787     <span class="keywordflow">else</span>                                  <span class="comment">/* non-linear fit */</span>
+<a name="l00788"></a>00788     {
+<a name="l00789"></a>00789         <span class="comment">/*----------------------------------------------------------------</span>
+<a name="l00790"></a>00790 <span class="comment">         * the non-linear fit uses the steepest descent method in combination</span>
+<a name="l00791"></a>00791 <span class="comment">         * with the Taylor method. The mixing of these methods is controlled</span>
+<a name="l00792"></a>00792 <span class="comment">         * by labda. In the outer loop ( called the iteration loop ) we build</span>
+<a name="l00793"></a>00793 <span class="comment">         * the matrix and calculate the correction sinfo_vector. In the </span>
+<a name="l00794"></a>00794 <span class="comment">           inner loop</span>
+<a name="l00795"></a>00795 <span class="comment">         * (called the interpolation loop) we check whether we have obtained a</span>
+<a name="l00796"></a>00796 <span class="comment">         * better solution than the previous one. If so, we leave the inner loop</span>
+<a name="l00797"></a>00797 <span class="comment">         * else we increase lambda ( give more weight to the steepest descent </span>
+<a name="l00798"></a>00798 <span class="comment">         * method) calculate the correction vector and check again. After the </span>
+<a name="l00799"></a>00799 <span class="comment">         * inner loop</span>
+<a name="l00800"></a>00800 <span class="comment">         * we do a final check on the goodness of the fit and if this satisfies</span>
+<a name="l00801"></a>00801 <span class="comment">         * the tolerance we calculate the errors of the fitted parameters.</span>
+<a name="l00802"></a>00802 <span class="comment">         */</span>
+<a name="l00803"></a>00803         <span class="keywordflow">while</span> ( !found )                  <span class="comment">/* iteration loop */</span>
+<a name="l00804"></a>00804         {      
+<a name="l00805"></a>00805             <span class="keywordflow">if</span> ( itc++ == (*its) )        <span class="comment">/* increase iteration counter */</span>
+<a name="l00806"></a>00806             {
+<a name="l00807"></a>00807                 <span class="keywordflow">return</span> -4 ;               
+<a name="l00808"></a>00808             }
+<a name="l00809"></a>00809             new_get_mat( xdat, xdim, ydat, wdat, ndat, fpar, epar<span class="comment">/*, npar*/</span> ) ;
+<a name="l00810"></a>00810             
+<a name="l00811"></a>00811             <span class="comment">/*-------------------------------------------------------------</span>
+<a name="l00812"></a>00812 <span class="comment">             * here we decrease labda since we may assume that each iteration</span>
+<a name="l00813"></a>00813 <span class="comment">             * brings us closer to the answer.</span>
+<a name="l00814"></a>00814 <span class="comment">             */</span>
+<a name="l00815"></a>00815             <span class="keywordflow">if</span> ( labda > LABMING )
+<a name="l00816"></a>00816             {
+<a name="l00817"></a>00817                 labda = labda / LABFACG ;         <span class="comment">/* decrease labda */</span>
+<a name="l00818"></a>00818             }
+<a name="l00819"></a>00819             r = new_get_vec ( xdat, xdim, ydat, wdat, ndat, fpar, epar, npar ) ;
+<a name="l00820"></a>00820 
+<a name="l00821"></a>00821             <span class="keywordflow">if</span> ( r )                      <span class="comment">/* error */</span>
+<a name="l00822"></a>00822             {
+<a name="l00823"></a>00823                 <span class="keywordflow">return</span> r ;
+<a name="l00824"></a>00824             }
+<a name="l00825"></a>00825 
+<a name="l00826"></a>00826             <span class="keywordflow">while</span> ( chi1 >= chi2 )        <span class="comment">/* interpolation loop */</span>
+<a name="l00827"></a>00827             {
+<a name="l00828"></a>00828                 <span class="comment">/*-----------------------------------------------------------</span>
+<a name="l00829"></a>00829 <span class="comment">                 * The next statement is based on experience, not on the </span>
+<a name="l00830"></a>00830 <span class="comment">                 * mathematics of the problem. It is assumed that we have </span>
+<a name="l00831"></a>00831 <span class="comment">                 * reached convergence when the pure steepest descent method </span>
+<a name="l00832"></a>00832 <span class="comment">                 * does not produce a better solution.</span>
+<a name="l00833"></a>00833 <span class="comment">                 */</span>
+<a name="l00834"></a>00834                 <span class="keywordflow">if</span> ( labda > LABMAXG )    <span class="comment">/* assume solution found */</span>
+<a name="l00835"></a>00835                 {
+<a name="l00836"></a>00836                     break ;
+<a name="l00837"></a>00837                 }
+<a name="l00838"></a>00838                 labda = labda * LABFACG ; <span class="comment">/* increase mixing parameter */</span>
+<a name="l00839"></a>00839                 r = new_get_vec(xdat,xdim,ydat,wdat,ndat,fpar,epar,npar) ;
+<a name="l00840"></a>00840 
+<a name="l00841"></a>00841                 <span class="keywordflow">if</span> ( r )                  <span class="comment">/* error */</span>
+<a name="l00842"></a>00842                 {
+<a name="l00843"></a>00843                     <span class="keywordflow">return</span> r ;
+<a name="l00844"></a>00844                 }
+<a name="l00845"></a>00845             }
+<a name="l00846"></a>00846 
+<a name="l00847"></a>00847             <span class="keywordflow">if</span> ( labda <= LABMAXG )        <span class="comment">/* save old parameters */</span>
+<a name="l00848"></a>00848             {
+<a name="l00849"></a>00849                 <span class="keywordflow">for</span> ( i = 0 ; i < *npar ; i++ )
+<a name="l00850"></a>00850                 {
+<a name="l00851"></a>00851                     fpar[i] = epar[i] ;
+<a name="l00852"></a>00852                 }
+<a name="l00853"></a>00853             }
+<a name="l00854"></a>00854             <span class="keywordflow">if</span> ( (fabs( chi2 - chi1 ) <= (tolerance * chi1)) || 
+<a name="l00855"></a>00855                       (labda > LABMAXG) )
+<a name="l00856"></a>00856             {
+<a name="l00857"></a>00857                 <span class="comment">/*-----------------------------------------------------------</span>
+<a name="l00858"></a>00858 <span class="comment">                 * we have a satisfying solution, so now we need to calculate </span>
+<a name="l00859"></a>00859 <span class="comment">                 * the correct errors of the fitted parameters. This we do by </span>
+<a name="l00860"></a>00860 <span class="comment">                 * using the pure Taylor</span>
+<a name="l00861"></a>00861 <span class="comment">                 * method because we are very close to the real solution.</span>
+<a name="l00862"></a>00862 <span class="comment">                 */</span>
+<a name="l00863"></a>00863                 labda = LABMING ;              <span class="comment">/* for Taylor solution */</span>
+<a name="l00864"></a>00864                 new_get_mat(xdat,xdim,ydat,wdat,ndat,fpar,epar<span class="comment">/*, npar */</span>) ;
+<a name="l00865"></a>00865                 r=new_get_vec(xdat,xdim,ydat,wdat,ndat,fpar,epar,npar ) ;
+<a name="l00866"></a>00866 
+<a name="l00867"></a>00867                 <span class="keywordflow">if</span> ( r )                    <span class="comment">/* error */</span>
+<a name="l00868"></a>00868                 {
+<a name="l00869"></a>00869                     <span class="keywordflow">return</span> r ;
+<a name="l00870"></a>00870                 }
+<a name="l00871"></a>00871                 <span class="keywordflow">for</span> ( i = 0 ; i < (*npar) ; i++ )
+<a name="l00872"></a>00872                 {
+<a name="l00873"></a>00873                     epar[i] = 0.0 ;          <span class="comment">/* set error to zero */</span>
+<a name="l00874"></a>00874                 }
+<a name="l00875"></a>00875                 chi2 = sqrt ( chi2 / (<span class="keywordtype">double</span>) (nuse - nfree) ) ;
+<a name="l00876"></a>00876 
+<a name="l00877"></a>00877                 <span class="keywordflow">for</span> ( i = 0 ; i < nfree ; i++ )
+<a name="l00878"></a>00878                 {
+<a name="l00879"></a>00879                     <span class="keywordflow">if</span> ( (matrix1[i][i] <= 0.0) || (matrix2[i][i] <= 0.0) )
+<a name="l00880"></a>00880                     {
+<a name="l00881"></a>00881                         <span class="keywordflow">return</span> -7 ;
+<a name="l00882"></a>00882                     }
+<a name="l00883"></a>00883                     epar[parptr[i]] = chi2 * sqrt( matrix2[i][i] ) / 
+<a name="l00884"></a>00884                                              sqrt( matrix1[i][i] ) ;
+<a name="l00885"></a>00885                 }
+<a name="l00886"></a>00886                 found = 1 ;                  <span class="comment">/* we found a solution */</span>
+<a name="l00887"></a>00887             }
+<a name="l00888"></a>00888         }
+<a name="l00889"></a>00889     }
+<a name="l00890"></a>00890     <span class="keywordflow">return</span> itc ;                             <span class="comment">/* return number of iterations */</span>
+<a name="l00891"></a>00891 }
+<a name="l00892"></a>00892 
+<a name="l00922"></a>00922 <span class="keywordtype">int</span> 
+<a name="l00923"></a>00923 sinfo_new_fit_2d_gaussian ( cpl_image   * image, 
+<a name="l00924"></a>00924                     <span class="keywordtype">double</span>     * fit_par, 
+<a name="l00925"></a>00925                     <span class="keywordtype">double</span>     * derv_par,   
+<a name="l00926"></a>00926                     <span class="keywordtype">int</span>        * mpar,
+<a name="l00927"></a>00927                     <span class="keywordtype">int</span>          lleftx,
+<a name="l00928"></a>00928                     <span class="keywordtype">int</span>          llefty,
+<a name="l00929"></a>00929                     <span class="keywordtype">int</span>          halfbox_x,
+<a name="l00930"></a>00930                     <span class="keywordtype">int</span>          halfbox_y, 
+<a name="l00931"></a>00931                     <span class="keywordtype">int</span>* check )
+<a name="l00932"></a>00932 {
+<a name="l00933"></a>00933     <span class="keywordtype">int</span> i, j, n ;
+<a name="l00934"></a>00934     <span class="keywordtype">int</span> col, row ;
+<a name="l00935"></a>00935     <span class="keywordtype">int</span> boxi, boxj ;
+<a name="l00936"></a>00936     <span class="keywordtype">int</span> iters ;
+<a name="l00937"></a>00937     <span class="keywordtype">int</span> ndata ;
+<a name="l00938"></a>00938     <span class="keywordtype">int</span> xdim ;
+<a name="l00939"></a>00939     <span class="keywordtype">int</span> npar ;
+<a name="l00940"></a>00940     <span class="keywordtype">int</span> its ;
+<a name="l00941"></a>00941     <span class="keywordtype">double</span> lab ;
+<a name="l00942"></a>00942     <span class="keywordtype">double</span> tol ;
+<a name="l00943"></a>00943     <span class="keywordtype">double</span> maxval ;
+<a name="l00944"></a>00944     <span class="keywordtype">double</span> background ;
+<a name="l00945"></a>00945     <span class="keywordtype">double</span> amplitude ;
+<a name="l00946"></a>00946     <span class="keywordtype">float</span> * backarray=NULL ;
+<a name="l00947"></a>00947     <span class="keywordtype">double</span> M, Mx, My ;
+<a name="l00948"></a>00948     <span class="keywordtype">double</span> Mxx, Mxy, Myy ; 
+<a name="l00949"></a>00949     <span class="keywordtype">double</span> X0, Y0 ;
+<a name="l00950"></a>00950     <span class="keywordtype">double</span> xydat[4 *halfbox_x*halfbox_y][XDIMG] ;
+<a name="l00951"></a>00951     <span class="keywordtype">double</span> zdat[4*halfbox_x*halfbox_y] ;
+<a name="l00952"></a>00952     <span class="keywordtype">double</span> wdat[4*halfbox_x*halfbox_y] ;
+<a name="l00953"></a>00953     <span class="keywordtype">double</span> xco, yco ;
+<a name="l00954"></a>00954     <span class="keywordtype">double</span> value ;
+<a name="l00955"></a>00955     <span class="keywordtype">double</span> denom ;
+<a name="l00956"></a>00956     <span class="keywordtype">double</span> temp ;
+<a name="l00957"></a>00957     <span class="keywordtype">int</span> llx, lly ;
+<a name="l00958"></a>00958     <span class="keywordtype">int</span> foundrow ;
+<a name="l00959"></a>00959     <span class="keywordtype">int</span> foundcol ;
+<a name="l00960"></a>00960     <span class="keywordtype">int</span> k ;
+<a name="l00961"></a>00961     <span class="keywordtype">int</span> ilx=0;
+<a name="l00962"></a>00962     <span class="keywordtype">int</span> ily=0;
+<a name="l00963"></a>00963     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l00964"></a>00964 
+<a name="l00965"></a>00965 
+<a name="l00966"></a>00966     <span class="keywordflow">if</span> ( NULL == image )
+<a name="l00967"></a>00967     {
+<a name="l00968"></a>00968         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no image given"</span>) ;
+<a name="l00969"></a>00969         <span class="keywordflow">return</span> -1 ;
+<a name="l00970"></a>00970     }
+<a name="l00971"></a>00971     ilx=cpl_image_get_size_x(image);
+<a name="l00972"></a>00972     ily=cpl_image_get_size_y(image);
+<a name="l00973"></a>00973 
+<a name="l00974"></a>00974     <span class="keywordflow">if</span> ( NULL == fit_par )
+<a name="l00975"></a>00975     {
+<a name="l00976"></a>00976         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no fit parameters given"</span>) ;
+<a name="l00977"></a>00977         <span class="keywordflow">return</span> -1 ;
+<a name="l00978"></a>00978     }
+<a name="l00979"></a>00979     <span class="keywordflow">if</span> ( NULL == derv_par )
+<a name="l00980"></a>00980     {
+<a name="l00981"></a>00981         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no derivatives of fit parameters given"</span>) ;
+<a name="l00982"></a>00982         <span class="keywordflow">return</span> -1 ;
+<a name="l00983"></a>00983     }
+<a name="l00984"></a>00984     <span class="keywordflow">if</span> ( lleftx < 0 || lleftx + 2*halfbox_x >= ilx ||
+<a name="l00985"></a>00985          llefty < 0 || llefty + 2*halfbox_y >= ily )
+<a name="l00986"></a>00986     {
+<a name="l00987"></a>00987         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"wrong lower left point of fitting box given!"</span>) ;
+<a name="l00988"></a>00988         <span class="keywordflow">return</span> -1 ;
+<a name="l00989"></a>00989     }
+<a name="l00990"></a>00990     <span class="keywordflow">if</span> ( halfbox_x <= 1 || halfbox_y <= 1 )
+<a name="l00991"></a>00991     {
+<a name="l00992"></a>00992         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"wrong box dimensions given"</span>) ;
+<a name="l00993"></a>00993         <span class="keywordflow">return</span> -1 ;
+<a name="l00994"></a>00994     }
+<a name="l00995"></a>00995     <span class="comment">/* allocate memory */</span>
+<a name="l00996"></a>00996     <span class="keywordflow">if</span> ( NULL == (backarray = (<span class="keywordtype">float</span>*) cpl_calloc(4*halfbox_x+4*halfbox_y, 
+<a name="l00997"></a>00997                   <span class="keyword">sizeof</span>(<span class="keywordtype">float</span>) ) ) ) 
+<a name="l00998"></a>00998     {
+<a name="l00999"></a>00999         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"could not allocate memory"</span>) ;
+<a name="l01000"></a>01000         <span class="keywordflow">return</span> -1 ;
+<a name="l01001"></a>01001     }
+<a name="l01002"></a>01002 
+<a name="l01003"></a>01003     <span class="comment">/* -------------------------------------------------------------------</span>
+<a name="l01004"></a>01004 <span class="comment">     * find the initial estimates for the free parameters</span>
+<a name="l01005"></a>01005 <span class="comment">     */</span>
+<a name="l01006"></a>01006 
+<a name="l01007"></a>01007     <span class="comment">/* first search for the position of the maximum intensity */</span>
+<a name="l01008"></a>01008     foundrow = 0 ;
+<a name="l01009"></a>01009     foundcol = 0 ;
+<a name="l01010"></a>01010     maxval   = -SINFO_DBL_MAX ;
+<a name="l01011"></a>01011     pidata=cpl_image_get_data_float(image);
+<a name="l01012"></a>01012     <span class="keywordflow">for</span> ( col = lleftx ; col < lleftx + 2*halfbox_x ; col++ )
+<a name="l01013"></a>01013     {
+<a name="l01014"></a>01014         <span class="keywordflow">for</span> ( row = llefty ; row < llefty + 2*halfbox_y ; row++ )
+<a name="l01015"></a>01015         {
+<a name="l01016"></a>01016             <span class="keywordflow">if</span> ( isnan(pidata[col+row*ilx]) )
+<a name="l01017"></a>01017             {
+<a name="l01018"></a>01018                 continue ;
+<a name="l01019"></a>01019             }
+<a name="l01020"></a>01020             <span class="keywordflow">if</span> ( maxval < pidata[col+row*ilx] ) 
+<a name="l01021"></a>01021             {
+<a name="l01022"></a>01022                 maxval = pidata[col+row*ilx] ;
+<a name="l01023"></a>01023                 foundrow = row ;
+<a name="l01024"></a>01024                 foundcol = col ;
+<a name="l01025"></a>01025             }
+<a name="l01026"></a>01026         }
+<a name="l01027"></a>01027     }
+<a name="l01028"></a>01028 
+<a name="l01029"></a>01029     <span class="keywordflow">if</span> ( foundrow == 0 || foundcol == 0 || maxval <= 0. ||
+<a name="l01030"></a>01030          foundrow == ilx-1 || foundcol == ily-1 )
+<a name="l01031"></a>01031     {
+<a name="l01032"></a>01032         <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"no maximum found"</span>) ;
+<a name="l01033"></a>01033         cpl_free(backarray) ;
+<a name="l01034"></a>01034         <span class="keywordflow">return</span> -1 ;
+<a name="l01035"></a>01035     }
+<a name="l01036"></a>01036 
+<a name="l01037"></a>01037     <span class="comment">/* determine the lower left sinfo_edge of the fitting box, center it </span>
+<a name="l01038"></a>01038 <span class="comment">       on the maximum value */</span>
+<a name="l01039"></a>01039     llx = foundcol - halfbox_x ;
+<a name="l01040"></a>01040     lly = foundrow - halfbox_y ;
+<a name="l01041"></a>01041     <span class="keywordflow">if</span> ((foundcol - halfbox_x) > 0) {
+<a name="l01042"></a>01042       llx = (foundcol - halfbox_x);
+<a name="l01043"></a>01043     } <span class="keywordflow">else</span> {
+<a name="l01044"></a>01044       llx=1;
+<a name="l01045"></a>01045       check++;
+<a name="l01046"></a>01046     }
+<a name="l01047"></a>01047 
+<a name="l01048"></a>01048     <span class="keywordflow">if</span> ((foundrow - halfbox_y) > 0) {
+<a name="l01049"></a>01049       lly = (foundrow - halfbox_y);
+<a name="l01050"></a>01050     } <span class="keywordflow">else</span> {
+<a name="l01051"></a>01051       lly=1;
+<a name="l01052"></a>01052       check++;
+<a name="l01053"></a>01053     } 
+<a name="l01054"></a>01054 
+<a name="l01055"></a>01055     <span class="keywordflow">if</span> ( ( llx + 2*halfbox_x) <  ilx-1 ) {
+<a name="l01056"></a>01056       halfbox_x=halfbox_x;
+<a name="l01057"></a>01057     } <span class="keywordflow">else</span> {
+<a name="l01058"></a>01058        halfbox_x=(int) (ilx-2-llx)/2;
+<a name="l01059"></a>01059       check++;
+<a name="l01060"></a>01060     }
+<a name="l01061"></a>01061 
+<a name="l01062"></a>01062     <span class="keywordflow">if</span> ( ( lly + 2*halfbox_y) <  ily-1 ) {
+<a name="l01063"></a>01063       halfbox_y= halfbox_y;
+<a name="l01064"></a>01064     } <span class="keywordflow">else</span> {
+<a name="l01065"></a>01065       halfbox_y=(int) (ily-2-lly)/2;
+<a name="l01066"></a>01066       check++;
+<a name="l01067"></a>01067     }
+<a name="l01068"></a>01068 
+<a name="l01069"></a>01069     <span class="keywordflow">if</span> ( llx <= 0 || lly < 0 || llx + 2*halfbox_x >= ilx-1 ||
+<a name="l01070"></a>01070          lly + 2*halfbox_y >= ily )
+<a name="l01071"></a>01071     {
+<a name="l01072"></a>01072         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"box does not fit into image"</span>) ;
+<a name="l01073"></a>01073         cpl_free(backarray) ;
+<a name="l01074"></a>01074         <span class="keywordflow">return</span> -1 ;
+<a name="l01075"></a>01075     }
+<a name="l01076"></a>01076     
+<a name="l01077"></a>01077     <span class="comment">/* determine the zeroth and first order moments of the image  </span>
+<a name="l01078"></a>01078 <span class="comment">       within the fitting box */</span> 
+<a name="l01079"></a>01079     M = Mx = My = 0. ;
+<a name="l01080"></a>01080     n = 0 ;
+<a name="l01081"></a>01081     boxi = boxj = 0 ;
+<a name="l01082"></a>01082     <span class="keywordflow">for</span> ( j = lly ; j < lly + 2*halfbox_y ; j++ )
+<a name="l01083"></a>01083     {
+<a name="l01084"></a>01084         boxj = j - lly ;
+<a name="l01085"></a>01085         <span class="keywordflow">for</span> ( i = llx ; i < llx + 2*halfbox_x ; i++ )
+<a name="l01086"></a>01086         {
+<a name="l01087"></a>01087             boxi = i - llx ;
+<a name="l01088"></a>01088             <span class="keywordflow">if</span> ( !isnan(pidata[i+j*ilx]) )
+<a name="l01089"></a>01089             {
+<a name="l01090"></a>01090                 M  += pidata[i+j*ilx] ;  
+<a name="l01091"></a>01091                 Mx += (double)boxi * pidata[i+j*ilx] ;
+<a name="l01092"></a>01092                 My += (double)boxj * pidata[i+j*ilx] ;
+<a name="l01093"></a>01093                 <span class="comment">/*-----------------------------------------------------------</span>
+<a name="l01094"></a>01094 <span class="comment">                 * estimate the amplitude and the background </span>
+<a name="l01095"></a>01095 <span class="comment">                 * go through the margins of the fitting box </span>
+<a name="l01096"></a>01096 <span class="comment">                 * and calculate the clean mean to</span>
+<a name="l01097"></a>01097 <span class="comment">                 * determine the background </span>
+<a name="l01098"></a>01098 <span class="comment">                 */</span>
+<a name="l01099"></a>01099                 <span class="keywordflow">if</span> ( i == llx || i == llx + 2*halfbox_x -1 ||
+<a name="l01100"></a>01100                      j == lly || j == lly + 2*halfbox_y -1 )
+<a name="l01101"></a>01101                 {
+<a name="l01102"></a>01102                     backarray[n] = pidata[i+j*ilx] ;
+<a name="l01103"></a>01103                     n++ ;
+<a name="l01104"></a>01104                 }
+<a name="l01105"></a>01105             }
+<a name="l01106"></a>01106         }
+<a name="l01107"></a>01107     }
+<a name="l01108"></a>01108     <span class="keywordflow">if</span> ( M <= 0. )
+<a name="l01109"></a>01109     {
+<a name="l01110"></a>01110         <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"only negative or zero values"</span>) ;
+<a name="l01111"></a>01111         cpl_free(backarray) ;
+<a name="l01112"></a>01112         <span class="keywordflow">return</span> -1 ;
+<a name="l01113"></a>01113     }
+<a name="l01114"></a>01114     <span class="keywordflow">if</span> ( n < 3 )
+<a name="l01115"></a>01115     {
+<a name="l01116"></a>01116         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"not enough data points to calculate background"</span>) ;
+<a name="l01117"></a>01117         cpl_free(backarray) ;
+<a name="l01118"></a>01118         <span class="keywordflow">return</span> -1 ;
+<a name="l01119"></a>01119     }
+<a name="l01120"></a>01120     <span class="comment">/* determine the background as sinfo_median of the surrounding pixels */</span>
+<a name="l01121"></a>01121     <span class="keywordflow">if</span> (FLT_MAX==(background=sinfo_new_clean_mean(backarray,n,10.,10.))) 
+<a name="l01122"></a>01122     {
+<a name="l01123"></a>01123         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"it was not possible to compute the "</span>
+<a name="l01124"></a>01124                         <span class="stringliteral">"clean mean of the background values"</span>) ;
+<a name="l01125"></a>01125         cpl_free(backarray) ;
+<a name="l01126"></a>01126         <span class="keywordflow">return</span> -1 ;
+<a name="l01127"></a>01127     }
+<a name="l01128"></a>01128     cpl_free (backarray) ;
+<a name="l01129"></a>01129     <span class="comment">/* now calculate the amplitude estimation */</span>
+<a name="l01130"></a>01130     amplitude = maxval - background ;
+<a name="l01131"></a>01131     <span class="keywordflow">if</span> ( amplitude < 1e-12 )
+<a name="l01132"></a>01132     {
+<a name="l01133"></a>01133         <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"amplitude is too small"</span>) ;
+<a name="l01134"></a>01134         <span class="keywordflow">return</span> -1 ;
+<a name="l01135"></a>01135     }
+<a name="l01136"></a>01136 
+<a name="l01137"></a>01137     <span class="comment">/* determine the center of gravity = centroid */</span>
+<a name="l01138"></a>01138     X0 = Mx / M ;
+<a name="l01139"></a>01139     Y0 = My / M ;
+<a name="l01140"></a>01140     <span class="comment">/* if one of the values is outside the fitting box return with error */</span>
+<a name="l01141"></a>01141     <span class="keywordflow">if</span> ( X0 <= 0. || Y0 <= 0. || X0 >= 2.*(<span class="keywordtype">double</span>)halfbox_x || 
+<a name="l01142"></a>01142          Y0 >= 2.*(<span class="keywordtype">double</span>)halfbox_y )
+<a name="l01143"></a>01143     {
+<a name="l01144"></a>01144         <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"center of gravity is outside the fitting box!"</span>) ;
+<a name="l01145"></a>01145         <span class="keywordflow">return</span> -1 ;
+<a name="l01146"></a>01146     }
+<a name="l01147"></a>01147     
+<a name="l01148"></a>01148     <span class="comment">/*------------------------------------------------------------------------ </span>
+<a name="l01149"></a>01149 <span class="comment">     * put the data in the 2-d array xydat[][] (pixel position) and zdat[] </span>
+<a name="l01150"></a>01150 <span class="comment">     * (data values) additionally, determine the second order momentum</span>
+<a name="l01151"></a>01151 <span class="comment">     */</span>
+<a name="l01152"></a>01152     n = 0 ;
+<a name="l01153"></a>01153     M = Mx = Mxx = My = Myy = Mxy = 0. ;
+<a name="l01154"></a>01154     boxi = boxj = 0 ;
+<a name="l01155"></a>01155     <span class="keywordflow">for</span> ( j = lly ; j < lly + 2*halfbox_y ; j++ )
+<a name="l01156"></a>01156     {
+<a name="l01157"></a>01157         boxj = j - lly ;
+<a name="l01158"></a>01158         <span class="keywordflow">for</span> ( i = llx ; i < llx + 2*halfbox_x ; i++ )
+<a name="l01159"></a>01159         {
+<a name="l01160"></a>01160             boxi = i - llx ;
+<a name="l01161"></a>01161             value = pidata[i+j*ilx] ;
+<a name="l01162"></a>01162             <span class="keywordflow">if</span> ( !isnan(value) )
+<a name="l01163"></a>01163             {
+<a name="l01164"></a>01164                 xydat[n][0] = (double) boxi ;
+<a name="l01165"></a>01165                 xydat[n][1] = (double) boxj ;
+<a name="l01166"></a>01166                 zdat[n]     = value ;
+<a name="l01167"></a>01167                 wdat[n]     = 1. ;
+<a name="l01168"></a>01168                 n++ ; 
+<a name="l01169"></a>01169                
+<a name="l01170"></a>01170                 <span class="comment">/* now calculate the moments without background in the </span>
+<a name="l01171"></a>01171 <span class="comment">                   centroid coordinate system */</span>
+<a name="l01172"></a>01172                 value -= background ;
+<a name="l01173"></a>01173                 xco = (double) boxi - X0 ;
+<a name="l01174"></a>01174                 yco = (double) boxj - Y0 ;
+<a name="l01175"></a>01175                 M   += value ;
+<a name="l01176"></a>01176                 Mx  += xco * value ;
+<a name="l01177"></a>01177                 My  += yco * value ;
+<a name="l01178"></a>01178                 Mxx += xco * xco * value ;
+<a name="l01179"></a>01179                 Myy += yco * yco * value ;
+<a name="l01180"></a>01180                 Mxy += xco * yco * value ;
+<a name="l01181"></a>01181             }
+<a name="l01182"></a>01182         }
+<a name="l01183"></a>01183     }
+<a name="l01184"></a>01184     <span class="keywordflow">if</span> ( M <= 0. )
+<a name="l01185"></a>01185     {
+<a name="l01186"></a>01186         <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"only negative or zero values"</span>) ;
+<a name="l01187"></a>01187         <span class="keywordflow">return</span> -1 ;
+<a name="l01188"></a>01188     }
+<a name="l01189"></a>01189   
+<a name="l01190"></a>01190     <span class="comment">/* ----------------------------------------------------------------</span>
+<a name="l01191"></a>01191 <span class="comment">     * estimate the fwhm_x and fwhm_y and theta </span>
+<a name="l01192"></a>01192 <span class="comment">     */</span> 
+<a name="l01193"></a>01193   
+<a name="l01194"></a>01194     <span class="comment">/* first scale the moments */</span>
+<a name="l01195"></a>01195     <span class="comment">/* TODO: why use Mx is later this is never used? */</span>
+<a name="l01196"></a>01196     Mx  /= M ;
+<a name="l01197"></a>01197     My  /= M ;
+<a name="l01198"></a>01198     Mxx /= M ;
+<a name="l01199"></a>01199     Myy /= M ;
+<a name="l01200"></a>01200     Mxy /= M ;
+<a name="l01201"></a>01201    
+<a name="l01202"></a>01202     denom = 2. * (Mxx*Myy - Mxy*Mxy) ;
+<a name="l01203"></a>01203     <span class="keywordflow">if</span> ( denom == 0. )
+<a name="l01204"></a>01204     {
+<a name="l01205"></a>01205         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"denominator is zero!"</span>) ;
+<a name="l01206"></a>01206         <span class="keywordflow">return</span> -1 ;
+<a name="l01207"></a>01207     }
+<a name="l01208"></a>01208     
+<a name="l01209"></a>01209     <span class="comment">/* now associate the parameter list with the found estimates */</span>
+<a name="l01210"></a>01210     fit_par[0] = X0 ;
+<a name="l01211"></a>01211     fit_par[1] = Y0 ;
+<a name="l01212"></a>01212     fit_par[2] = amplitude ;
+<a name="l01213"></a>01213     fit_par[3] = background ;
+<a name="l01214"></a>01214     fit_par[4] = Myy/denom ;
+<a name="l01215"></a>01215     fit_par[5] = Mxx/denom ;
+<a name="l01216"></a>01216     fit_par[6] = -Mxy/denom ;
+<a name="l01217"></a>01217 
+<a name="l01218"></a>01218     <span class="comment">/* convert the moments to ellipse paramters */</span>
+<a name="l01219"></a>01219     <span class="keywordflow">if</span> ( 0 > new_gauss2Ellipse (fit_par) )
+<a name="l01220"></a>01220     {
+<a name="l01221"></a>01221         <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"gauss2Ellipse does not run!"</span>) ;
+<a name="l01222"></a>01222         <span class="keywordflow">return</span> -1 ;
+<a name="l01223"></a>01223     }
+<a name="l01224"></a>01224 
+<a name="l01225"></a>01225     <span class="comment">/* total number of data points */</span>
+<a name="l01226"></a>01226     ndata = 4 * halfbox_x * halfbox_y ;
+<a name="l01227"></a>01227     xdim = XDIMG ; <span class="comment">/* dimension of xydat array */</span>
+<a name="l01228"></a>01228     npar = NPAR ; <span class="comment">/* number of parameters in the fit */</span>
+<a name="l01229"></a>01229     its = ITSG ;
+<a name="l01230"></a>01230     lab = LABG ;
+<a name="l01231"></a>01231     tol = TOLG ;
+<a name="l01232"></a>01232     <span class="keywordflow">for</span> ( i = 0 ; i < NPAR ; i++ )
+<a name="l01233"></a>01233     {
+<a name="l01234"></a>01234         derv_par[i] = 0. ;
+<a name="l01235"></a>01235     }
+<a name="l01236"></a>01236     
+<a name="l01237"></a>01237     <span class="keywordflow">if</span> ( 0 > ( iters = sinfo_new_lsqfitd ( &xydat[0][0],
+<a name="l01238"></a>01238                                  &xdim,
+<a name="l01239"></a>01239                                  zdat,
+<a name="l01240"></a>01240                                  wdat, 
+<a name="l01241"></a>01241                                  &ndata,
+<a name="l01242"></a>01242                                  fit_par,
+<a name="l01243"></a>01243                                  derv_par,
+<a name="l01244"></a>01244                                  mpar,
+<a name="l01245"></a>01245                                  &npar,
+<a name="l01246"></a>01246                                  &tol,
+<a name="l01247"></a>01247                                  &its,
+<a name="l01248"></a>01248                                  &lab )) ) 
+<a name="l01249"></a>01249     {
+<a name="l01250"></a>01250         <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">" least squares fit failed, error no: %d!"</span>, iters) ;
+<a name="l01251"></a>01251         <span class="keywordflow">return</span> -1 ;
+<a name="l01252"></a>01252     }
+<a name="l01253"></a>01253 
+<a name="l01254"></a>01254     <span class="comment">/* exclude impossible fit results */</span>
+<a name="l01255"></a>01255     <span class="keywordflow">if</span> ( fit_par[2] <= 0. || fit_par[4] < 0. || fit_par[5] < 0. )
+<a name="l01256"></a>01256     {
+<a name="l01257"></a>01257         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"sorry, some impossible negative fit results!"</span>) ;
+<a name="l01258"></a>01258         <span class="keywordflow">return</span> -1 ;
+<a name="l01259"></a>01259     }
+<a name="l01260"></a>01260     fit_par[0] += llx ;
+<a name="l01261"></a>01261     fit_par[1] += lly ;
+<a name="l01262"></a>01262     <span class="keywordflow">if</span> ( fit_par[0] < llx || fit_par[0] >= llx + 2*halfbox_x ||
+<a name="l01263"></a>01263          fit_par[1] < lly || fit_par[1] >= lly + 2*halfbox_y )
+<a name="l01264"></a>01264     {
+<a name="l01265"></a>01265         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"sorry, centroid after the fit "</span>
+<a name="l01266"></a>01266                         <span class="stringliteral">"outside the fitting box"</span>) ;
+<a name="l01267"></a>01267         <span class="keywordflow">return</span> -1 ;
+<a name="l01268"></a>01268     }
+<a name="l01269"></a>01269 
+<a name="l01270"></a>01270     <span class="comment">/* exchange fwhmx and fwhmy if |theta| is bigger than </span>
+<a name="l01271"></a>01271 <span class="comment">       pi/4 and subtract pi/2 from theta */</span>
+<a name="l01272"></a>01272     <span class="keywordflow">if</span> ( fabs ( fit_par[6] ) > PI_NUMB / 4. )
+<a name="l01273"></a>01273     {
+<a name="l01274"></a>01274         <span class="comment">/* first convert angle to smaller than 2 pi */</span>
+<a name="l01275"></a>01275         <span class="keywordflow">if</span> ( fabs (fit_par[6]) >= 2. * PI_NUMB )
+<a name="l01276"></a>01276         { 
+<a name="l01277"></a>01277             k = (int) (fit_par[6] / (2.*PI_NUMB)) ;
+<a name="l01278"></a>01278             <span class="keywordflow">if</span> ( k > 0 ) 
+<a name="l01279"></a>01279             {
+<a name="l01280"></a>01280                 fit_par[6] -= k*2.*PI_NUMB ;
+<a name="l01281"></a>01281             }
+<a name="l01282"></a>01282             <span class="keywordflow">else</span>
+<a name="l01283"></a>01283             {
+<a name="l01284"></a>01284                 fit_par[6] += k*2.*PI_NUMB ;
+<a name="l01285"></a>01285             }
+<a name="l01286"></a>01286         }
+<a name="l01287"></a>01287         <span class="comment">/* first convert angle to smaller than pi/2 */</span>
+<a name="l01288"></a>01288         <span class="keywordflow">if</span> ( fabs (fit_par[6]) > PI_NUMB / 2. )
+<a name="l01289"></a>01289         {
+<a name="l01290"></a>01290             <span class="keywordflow">if</span> ( fit_par[6] > 0. )
+<a name="l01291"></a>01291             {
+<a name="l01292"></a>01292                 fit_par[6] -= PI_NUMB ;
+<a name="l01293"></a>01293             }
+<a name="l01294"></a>01294             <span class="keywordflow">else</span>
+<a name="l01295"></a>01295             {
+<a name="l01296"></a>01296                 fit_par[6] += PI_NUMB ;
+<a name="l01297"></a>01297             }
+<a name="l01298"></a>01298         }
+<a name="l01299"></a>01299 
+<a name="l01300"></a>01300         <span class="keywordflow">if</span> ( fabs (fit_par[6]) > PI_NUMB / 4. )
+<a name="l01301"></a>01301         {
+<a name="l01302"></a>01302             temp       = fit_par[4] ;
+<a name="l01303"></a>01303             fit_par[4] = fit_par[5] ;
+<a name="l01304"></a>01304             fit_par[5] = temp ;
+<a name="l01305"></a>01305             <span class="keywordflow">if</span> ( fit_par[6] < 0. )
+<a name="l01306"></a>01306             { 
+<a name="l01307"></a>01307                 fit_par[6] += PI_NUMB / 2. ;
+<a name="l01308"></a>01308             }
+<a name="l01309"></a>01309             <span class="keywordflow">else</span>
+<a name="l01310"></a>01310             {
+<a name="l01311"></a>01311                 fit_par[6] -= PI_NUMB / 2. ;
+<a name="l01312"></a>01312             }  
+<a name="l01313"></a>01313         }
+<a name="l01314"></a>01314     }
+<a name="l01315"></a>01315     
+<a name="l01316"></a>01316     <span class="keywordflow">return</span> iters ;
+<a name="l01317"></a>01317 }
+<a name="l01318"></a>01318 
+<a name="l01328"></a>01328 cpl_image * 
+<a name="l01329"></a>01329 sinfo_new_plot_gaussian (cpl_image   * image, 
+<a name="l01330"></a>01330                          <span class="keywordtype">double</span>     * parlist )
+<a name="l01331"></a>01331 {
+<a name="l01332"></a>01332     <span class="keywordtype">int</span> col, row ;
+<a name="l01333"></a>01333     cpl_image * retImage ;
+<a name="l01334"></a>01334     <span class="keywordtype">double</span> xdat[2] ;
+<a name="l01335"></a>01335     <span class="keywordtype">int</span> ilx=0;
+<a name="l01336"></a>01336     <span class="keywordtype">int</span> ily=0;
+<a name="l01337"></a>01337     <span class="keywordtype">float</span>* podata=NULL;
+<a name="l01338"></a>01338 
+<a name="l01339"></a>01339     <span class="keywordflow">if</span> ( image == NULL )
+<a name="l01340"></a>01340     {
+<a name="l01341"></a>01341         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no input image given!"</span>) ;
+<a name="l01342"></a>01342         <span class="keywordflow">return</span> NULL ;
+<a name="l01343"></a>01343     }
+<a name="l01344"></a>01344     ilx=cpl_image_get_size_x(image);
+<a name="l01345"></a>01345     ily=cpl_image_get_size_y(image);
+<a name="l01346"></a>01346 
+<a name="l01347"></a>01347     <span class="keywordflow">if</span> ( parlist == NULL ) 
+<a name="l01348"></a>01348     {
+<a name="l01349"></a>01349         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no Gaussian parameters given!"</span>) ;
+<a name="l01350"></a>01350         <span class="keywordflow">return</span> NULL ;
+<a name="l01351"></a>01351     }
+<a name="l01352"></a>01352  
+<a name="l01353"></a>01353     retImage = cpl_image_new (ilx, ily, CPL_TYPE_FLOAT) ;
+<a name="l01354"></a>01354     podata=cpl_image_get_data_float(retImage);
+<a name="l01355"></a>01355     <span class="keywordflow">for</span> ( row = 0 ; row < ily ; row++ )
+<a name="l01356"></a>01356     {
+<a name="l01357"></a>01357         <span class="keywordflow">for</span> ( col = 0 ; col < ilx ; col++ )
+<a name="l01358"></a>01358         {
+<a name="l01359"></a>01359             xdat[0] = (double) col ;
+<a name="l01360"></a>01360             xdat[1] = (double) row ;
+<a name="l01361"></a>01361             podata[col+row*ilx] = sinfo_new_gaussian_ellipse( xdat , parlist) ; 
+<a name="l01362"></a>01362         }
+<a name="l01363"></a>01363     }
+<a name="l01364"></a>01364 
+<a name="l01365"></a>01365     <span class="keywordflow">return</span> retImage ;
+<a name="l01366"></a>01366 }
+<a name="l01367"></a>01367 
+<a name="l01375"></a>01375 <span class="keyword">static</span> <span class="keywordtype">int</span> new_gauss2Ellipse ( <span class="keywordtype">double</span>     * parlist )
+<a name="l01376"></a>01376 {
+<a name="l01377"></a>01377     <span class="keywordtype">double</span> a, b, c ;
+<a name="l01378"></a>01378     <span class="keywordtype">double</span> ellipseconst ;
+<a name="l01379"></a>01379     <span class="keywordtype">double</span> axisX, axisY, phi ;
+<a name="l01380"></a>01380     <span class="keywordtype">double</span> p ;
+<a name="l01381"></a>01381     
+<a name="l01382"></a>01382     <span class="keywordflow">if</span> ( parlist == NULL )
+<a name="l01383"></a>01383     {
+<a name="l01384"></a>01384         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" no parameters given!\n"</span>) ;
+<a name="l01385"></a>01385         <span class="keywordflow">return</span> -1 ;
+<a name="l01386"></a>01386     }
+<a name="l01387"></a>01387 
+<a name="l01388"></a>01388     a = parlist[4] ; <span class="comment">/* fwhmx */</span>
+<a name="l01389"></a>01389     b = parlist[5] ; <span class="comment">/* fwhmy */</span>
+<a name="l01390"></a>01390     c = parlist[6] ; <span class="comment">/* theta */</span>
+<a name="l01391"></a>01391 
+<a name="l01392"></a>01392     ellipseconst = 2. * log(2.) ;
+<a name="l01393"></a>01393 
+<a name="l01394"></a>01394     <span class="keywordflow">if</span> ( a*b - c*c <= 0. )
+<a name="l01395"></a>01395     {
+<a name="l01396"></a>01396         <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"estimates of moments are unusable, "</span>
+<a name="l01397"></a>01397                           <span class="stringliteral">"they do not make an ellipse!"</span>) ;
+<a name="l01398"></a>01398         <span class="keywordflow">return</span> -1 ;
+<a name="l01399"></a>01399     }
+<a name="l01400"></a>01400     
+<a name="l01401"></a>01401     <span class="keywordflow">if</span> ( a == b )
+<a name="l01402"></a>01402     { 
+<a name="l01403"></a>01403         phi = 0. ;
+<a name="l01404"></a>01404     }
+<a name="l01405"></a>01405     <span class="keywordflow">else</span>
+<a name="l01406"></a>01406     {
+<a name="l01407"></a>01407         phi = 0.5 * atan( 2. * c / (a-b) ) ;
+<a name="l01408"></a>01408     }
+<a name="l01409"></a>01409 
+<a name="l01410"></a>01410     p = sqrt ( (a-b) * (a-b) + 4. * c*c ) ;
+<a name="l01411"></a>01411 
+<a name="l01412"></a>01412     <span class="keywordflow">if</span> ( a > b )
+<a name="l01413"></a>01413     {
+<a name="l01414"></a>01414         axisX = 2. * sqrt ( ellipseconst / (a+b+p) ) ;
+<a name="l01415"></a>01415         axisY = 2. * sqrt ( ellipseconst / (a+b-p) ) ;
+<a name="l01416"></a>01416     }
+<a name="l01417"></a>01417     <span class="keywordflow">else</span>
+<a name="l01418"></a>01418     {
+<a name="l01419"></a>01419         axisX = 2. * sqrt ( ellipseconst / (a+b-p) ) ;
+<a name="l01420"></a>01420         axisY = 2. * sqrt ( ellipseconst / (a+b+p) ) ;
+<a name="l01421"></a>01421     }
+<a name="l01422"></a>01422 
+<a name="l01423"></a>01423     parlist[4] = axisX ;
+<a name="l01424"></a>01424     parlist[5] = axisY ;
+<a name="l01425"></a>01425     parlist[6] = phi ;
+<a name="l01426"></a>01426 
+<a name="l01427"></a>01427     <span class="keywordflow">return</span> 0 ;
+<a name="l01428"></a>01428 }
+<a name="l01429"></a>01429 
+<a name="l01453"></a>01453 <span class="keywordtype">float</span> sinfo_new_determine_conversion_factor ( cpl_imagelist * cube, 
+<a name="l01454"></a>01454                                   <span class="keywordtype">float</span>     mag,
+<a name="l01455"></a>01455                                   <span class="keywordtype">float</span>     exptime,
+<a name="l01456"></a>01456                                   <span class="keywordtype">int</span>       llx,
+<a name="l01457"></a>01457                                   <span class="keywordtype">int</span>       lly,
+<a name="l01458"></a>01458                                   <span class="keywordtype">int</span>       halfbox_x,
+<a name="l01459"></a>01459                                   <span class="keywordtype">int</span>       halfbox_y, 
+<a name="l01460"></a>01460                                   <span class="keywordtype">int</span>* check )
+<a name="l01461"></a>01461 {
+<a name="l01462"></a>01462     <span class="keywordtype">int</span> row, col, i ;
+<a name="l01463"></a>01463     <span class="keywordtype">int</span> first_row, first_col ;
+<a name="l01464"></a>01464     <span class="keywordtype">int</span> last_row, last_col ;
+<a name="l01465"></a>01465     <span class="keywordtype">float</span> factor ;
+<a name="l01466"></a>01466     <span class="keywordtype">int</span> mpar[7] ;
+<a name="l01467"></a>01467     <span class="keywordtype">double</span> fit_par[7] ;
+<a name="l01468"></a>01468     <span class="keywordtype">double</span> derv_par[7] ;
+<a name="l01469"></a>01469     <span class="keywordtype">int</span> fitInd ;
+<a name="l01470"></a>01470     <span class="keywordtype">double</span> sum ;
+<a name="l01471"></a>01471     <span class="keywordtype">double</span> xdat[2] ;
+<a name="l01472"></a>01472     cpl_image * summedIm ;
+<a name="l01473"></a>01473 
+<a name="l01474"></a>01474     <span class="keywordtype">int</span> ilx=0;
+<a name="l01475"></a>01475     <span class="keywordtype">int</span> ily=0;
+<a name="l01476"></a>01476     <span class="keywordtype">int</span> inp=0;
+<a name="l01477"></a>01477 
+<a name="l01478"></a>01478     <span class="keywordflow">if</span> ( NULL == cube )
+<a name="l01479"></a>01479     {
+<a name="l01480"></a>01480         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" no cube given!\n"</span>) ;
+<a name="l01481"></a>01481         <span class="keywordflow">return</span> -FLT_MAX ;
+<a name="l01482"></a>01482     }
+<a name="l01483"></a>01483 
+<a name="l01484"></a>01484     ilx=cpl_image_get_size_x(cpl_imagelist_get(cube,0));
+<a name="l01485"></a>01485     ily=cpl_image_get_size_y(cpl_imagelist_get(cube,0));
+<a name="l01486"></a>01486     inp=cpl_imagelist_get_size(cube);
+<a name="l01487"></a>01487 
+<a name="l01488"></a>01488     <span class="keywordflow">if</span> ( halfbox_x <= 0 || halfbox_y <= 0 || 
+<a name="l01489"></a>01489        2*halfbox_x > ilx || 2*halfbox_y > ily)
+<a name="l01490"></a>01490     {
+<a name="l01491"></a>01491         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" wrong width of halfbox given!"</span>) ;
+<a name="l01492"></a>01492         <span class="keywordflow">return</span> -FLT_MAX ;
+<a name="l01493"></a>01493     }
+<a name="l01494"></a>01494     <span class="keywordflow">if</span> ( exptime <= 0. )
+<a name="l01495"></a>01495     {
+<a name="l01496"></a>01496         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" impossible exposure time given !"</span>) ;
+<a name="l01497"></a>01497         <span class="keywordflow">return</span> -FLT_MAX ;
+<a name="l01498"></a>01498     }
+<a name="l01499"></a>01499 
+<a name="l01500"></a>01500     <span class="comment">/* collapse the cube to be able to do 2D-Gaussian fitting */</span>
+<a name="l01501"></a>01501     <span class="keywordflow">if</span> ( NULL == (summedIm = sinfo_new_sum_cube_to_image(cube)) )
+<a name="l01502"></a>01502     {
+<a name="l01503"></a>01503         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" sinfo_averageCubeToImage failed!"</span>) ;
+<a name="l01504"></a>01504         <span class="keywordflow">return</span> -FLT_MAX ;
+<a name="l01505"></a>01505     }
+<a name="l01506"></a>01506 
+<a name="l01507"></a>01507     <span class="comment">/* call the 2D-Gaussian fit routine */</span>
+<a name="l01508"></a>01508     <span class="keywordflow">for</span> ( i = 0 ; i < 7 ; i++ )
+<a name="l01509"></a>01509     {
+<a name="l01510"></a>01510         mpar[i] = 1 ;
+<a name="l01511"></a>01511     }
+<a name="l01512"></a>01512     <span class="keywordflow">if</span> ( -1 == (fitInd = sinfo_new_fit_2d_gaussian(summedIm, fit_par, derv_par,
+<a name="l01513"></a>01513                                                    mpar, llx, lly, halfbox_x, 
+<a name="l01514"></a>01514                                                    halfbox_y, check)) )
+<a name="l01515"></a>01515     {
+<a name="l01516"></a>01516         <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"sinfo_fit2dGaussian failed!"</span>) ;
+<a name="l01517"></a>01517         cpl_image_delete( summedIm) ;
+<a name="l01518"></a>01518         <span class="keywordflow">return</span> -FLT_MAX ;
+<a name="l01519"></a>01519     }
+<a name="l01520"></a>01520     cpl_image_delete(summedIm) ;
+<a name="l01521"></a>01521 
+<a name="l01522"></a>01522     <span class="comment">/* now integrate the found 2D Gaussian by first </span>
+<a name="l01523"></a>01523 <span class="comment">       subtracting the background */</span>
+<a name="l01524"></a>01524     <span class="keywordflow">if</span>  ((fit_par[0] - halfbox_x) < 0) {
+<a name="l01525"></a>01525       first_col=0;
+<a name="l01526"></a>01526       check++;
+<a name="l01527"></a>01527     } <span class="keywordflow">else</span> {
+<a name="l01528"></a>01528       first_col=(fit_par[0] - halfbox_x);
+<a name="l01529"></a>01529     }
+<a name="l01530"></a>01530 
+<a name="l01531"></a>01531     <span class="keywordflow">if</span> ((fit_par[0] + halfbox_x) < ilx) {
+<a name="l01532"></a>01532       last_col  = (fit_par[0] + halfbox_x);
+<a name="l01533"></a>01533     } <span class="keywordflow">else</span> {
+<a name="l01534"></a>01534       last_col = (ilx-1) ;
+<a name="l01535"></a>01535       check++;
+<a name="l01536"></a>01536     }
+<a name="l01537"></a>01537 
+<a name="l01538"></a>01538     <span class="keywordflow">if</span> ((fit_par[1] - halfbox_y) < 0) {
+<a name="l01539"></a>01539       first_row=0;
+<a name="l01540"></a>01540       check++;
+<a name="l01541"></a>01541     } <span class="keywordflow">else</span> {
+<a name="l01542"></a>01542       first_row=(fit_par[1] - halfbox_y) ;
+<a name="l01543"></a>01543     }
+<a name="l01544"></a>01544 
+<a name="l01545"></a>01545     <span class="keywordflow">if</span> ((fit_par[1] + halfbox_y) < ily) {
+<a name="l01546"></a>01546       last_row=(fit_par[1] + halfbox_y);
+<a name="l01547"></a>01547     } <span class="keywordflow">else</span> {
+<a name="l01548"></a>01548       last_row= (ily-1);
+<a name="l01549"></a>01549       check++;
+<a name="l01550"></a>01550     }
+<a name="l01551"></a>01551 
+<a name="l01552"></a>01552 
+<a name="l01553"></a>01553     <span class="keywordflow">if</span> ( first_col < 0 || first_row < 0 || last_col >= ilx || last_row >= ily )
+<a name="l01554"></a>01554     {
+<a name="l01555"></a>01555         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"star badly centered in FOV or fitting box too big!"</span>) ;
+<a name="l01556"></a>01556         <span class="keywordflow">return</span> -FLT_MAX ;
+<a name="l01557"></a>01557     }
+<a name="l01558"></a>01558     sum = 0. ;
+<a name="l01559"></a>01559     <span class="keywordflow">for</span> ( row = first_row ; row < last_row ; row++ )  
+<a name="l01560"></a>01560     {
+<a name="l01561"></a>01561         <span class="keywordflow">for</span>( col = first_col ; col < last_col ; col++ )
+<a name="l01562"></a>01562         {
+<a name="l01563"></a>01563             xdat[0] = (double) col ;
+<a name="l01564"></a>01564             xdat[1] = (double) row ;
+<a name="l01565"></a>01565             sum += (sinfo_new_gaussian_ellipse( xdat, fit_par ) - fit_par[3]) ;
+<a name="l01566"></a>01566         }
+<a name="l01567"></a>01567     }
+<a name="l01568"></a>01568     <span class="keywordflow">if</span> ( sum <= 0. )
+<a name="l01569"></a>01569     {
+<a name="l01570"></a>01570         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"zero or negative sum of counts!"</span>) ;
+<a name="l01571"></a>01571         <span class="keywordflow">return</span> -FLT_MAX ;
+<a name="l01572"></a>01572     }
+<a name="l01573"></a>01573     factor = mag / (float)sum * exptime ;
+<a name="l01574"></a>01574     <span class="keywordflow">return</span> factor ;
+<a name="l01575"></a>01575 }
+<a name="l01576"></a>01576                               
+<a name="l01577"></a>01577 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__focus_8h_source.html b/html/sinfo__focus_8h_source.html
new file mode 100644
index 0000000..ffe4c3d
--- /dev/null
+++ b/html/sinfo__focus_8h_source.html
@@ -0,0 +1,108 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_focus.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_focus.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#ifndef SINFO_FOCUS_H</span>
+<a name="l00002"></a>00002 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_FOCUS_H</span>
+<a name="l00003"></a>00003 <span class="preprocessor"></span><span class="comment">/*</span>
+<a name="l00004"></a>00004 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00005"></a>00005 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00006"></a>00006 <span class="comment"> *</span>
+<a name="l00007"></a>00007 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00008"></a>00008 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00009"></a>00009 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00010"></a>00010 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00011"></a>00011 <span class="comment"> *</span>
+<a name="l00012"></a>00012 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00013"></a>00013 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00014"></a>00014 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00015"></a>00015 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00016"></a>00016 <span class="comment"> *</span>
+<a name="l00017"></a>00017 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00018"></a>00018 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00019"></a>00019 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00020"></a>00020 <span class="comment"> */</span>
+<a name="l00021"></a>00021 <span class="comment">/*******************************************************************************</span>
+<a name="l00022"></a>00022 <span class="comment">* E.S.O. - VLT project</span>
+<a name="l00023"></a>00023 <span class="comment">*</span>
+<a name="l00024"></a>00024 <span class="comment">* "@(#) $Id: sinfo_focus.h,v 1.3 2007/06/06 07:10:45 amodigli Exp $"</span>
+<a name="l00025"></a>00025 <span class="comment">*</span>
+<a name="l00026"></a>00026 <span class="comment">* who       when      what</span>
+<a name="l00027"></a>00027 <span class="comment">* --------  --------  ----------------------------------------------</span>
+<a name="l00028"></a>00028 <span class="comment">* schreib  04/02/02  created</span>
+<a name="l00029"></a>00029 <span class="comment">*/</span>
+<a name="l00030"></a>00030 
+<a name="l00031"></a>00031 <span class="comment">/************************************************************************</span>
+<a name="l00032"></a>00032 <span class="comment"> * sinfo_focus.h</span>
+<a name="l00033"></a>00033 <span class="comment"> * some functions to fit a 2-D Gaussian for focus finding</span>
+<a name="l00034"></a>00034 <span class="comment"> *----------------------------------------------------------------------</span>
+<a name="l00035"></a>00035 <span class="comment"> */</span>
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="comment">/*</span>
+<a name="l00038"></a>00038 <span class="comment"> * header files</span>
+<a name="l00039"></a>00039 <span class="comment"> */</span>
+<a name="l00040"></a>00040 
+<a name="l00041"></a>00041 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include "sinfo_utilities.h"</span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include "sinfo_new_cube_ops.h"</span>
+<a name="l00044"></a>00044 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00045"></a>00045 <span class="comment"> *                        Function ANSI C prototypes</span>
+<a name="l00046"></a>00046 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00072"></a>00072 <span class="keywordtype">double</span> 
+<a name="l00073"></a>00073 sinfo_new_gaussian_ellipse(<span class="keywordtype">double</span> * xdat, <span class="keywordtype">double</span> * parlist) ;
+<a name="l00074"></a>00074 
+<a name="l00100"></a>00100 <span class="keywordtype">void</span> 
+<a name="l00101"></a>00101 sinfo_new_gaussian_ellipse_deriv( <span class="keywordtype">double</span> * xdat, 
+<a name="l00102"></a>00102                                   <span class="keywordtype">double</span> * parlist, 
+<a name="l00103"></a>00103                                   <span class="keywordtype">double</span> * dervs ) ;
+<a name="l00104"></a>00104 
+<a name="l00150"></a>00150 <span class="keywordtype">int</span> 
+<a name="l00151"></a>00151 sinfo_new_lsqfitd ( <span class="keywordtype">double</span> * xdat,
+<a name="l00152"></a>00152               <span class="keywordtype">int</span>    * xdim,
+<a name="l00153"></a>00153               <span class="keywordtype">double</span> * ydat,
+<a name="l00154"></a>00154               <span class="keywordtype">double</span> * wdat,
+<a name="l00155"></a>00155               <span class="keywordtype">int</span>    * ndat,
+<a name="l00156"></a>00156               <span class="keywordtype">double</span> * fpar,
+<a name="l00157"></a>00157               <span class="keywordtype">double</span> * epar,
+<a name="l00158"></a>00158               <span class="keywordtype">int</span>    * mpar,
+<a name="l00159"></a>00159               <span class="keywordtype">int</span>    * npar,
+<a name="l00160"></a>00160               <span class="keywordtype">double</span> * tol ,
+<a name="l00161"></a>00161               <span class="keywordtype">int</span>    * its ,
+<a name="l00162"></a>00162               <span class="keywordtype">double</span> * lab  ) ;
+<a name="l00163"></a>00163 
+<a name="l00188"></a>00188 <span class="keywordtype">int</span> 
+<a name="l00189"></a>00189 sinfo_new_fit_2d_gaussian ( cpl_image   * image,
+<a name="l00190"></a>00190                     <span class="keywordtype">double</span>     * fit_par,
+<a name="l00191"></a>00191                     <span class="keywordtype">double</span>     * derv_par,
+<a name="l00192"></a>00192                     <span class="keywordtype">int</span>        * mpar,
+<a name="l00193"></a>00193                     <span class="keywordtype">int</span>          lleftx,
+<a name="l00194"></a>00194                     <span class="keywordtype">int</span>          llefty,
+<a name="l00195"></a>00195                     <span class="keywordtype">int</span>          halfbox_x,
+<a name="l00196"></a>00196                     <span class="keywordtype">int</span>          halfbox_y, <span class="keywordtype">int</span>* check ) ;
+<a name="l00197"></a>00197 
+<a name="l00206"></a>00206 cpl_image * 
+<a name="l00207"></a>00207 sinfo_new_plot_gaussian ( cpl_image   * image,
+<a name="l00208"></a>00208                           <span class="keywordtype">double</span>     * parlist ) ;
+<a name="l00209"></a>00209 
+<a name="l00228"></a>00228 <span class="keywordtype">float</span> 
+<a name="l00229"></a>00229 sinfo_new_determine_conversion_factor ( cpl_imagelist * cube,
+<a name="l00230"></a>00230                                   <span class="keywordtype">float</span>     mag,
+<a name="l00231"></a>00231                                   <span class="keywordtype">float</span>     exptime,
+<a name="l00232"></a>00232                                   <span class="keywordtype">int</span>       llx,
+<a name="l00233"></a>00233                                   <span class="keywordtype">int</span>       lly,
+<a name="l00234"></a>00234                                   <span class="keywordtype">int</span>       halfbox_x,
+<a name="l00235"></a>00235                                   <span class="keywordtype">int</span>       halfbox_y, <span class="keywordtype">int</span>* check ) ;
+<a name="l00236"></a>00236 
+<a name="l00237"></a>00237 <span class="preprocessor">#endif </span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__focus__cfg_8c_source.html b/html/sinfo__focus__cfg_8c_source.html
new file mode 100644
index 0000000..6ec3e72
--- /dev/null
+++ b/html/sinfo__focus__cfg_8c_source.html
@@ -0,0 +1,69 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_focus_cfg.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_focus_cfg.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name     :    sinfo_focus_cfg.c</span>
+<a name="l00022"></a>00022 <span class="comment">   Author     :       Juergen Schreiber</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on    :    February 2002</span>
+<a name="l00024"></a>00024 <span class="comment">   Description    :    configuration handling tools for the 2d-Gaussian fit </span>
+<a name="l00025"></a>00025 <span class="comment">                        of a point source</span>
+<a name="l00026"></a>00026 <span class="comment"></span>
+<a name="l00027"></a>00027 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span>
+<a name="l00032"></a>00032 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                                   Includes</span>
+<a name="l00034"></a>00034 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 <span class="preprocessor">#include "sinfo_focus_cfg.h"</span>
+<a name="l00044"></a>00044 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00045"></a>00045 <span class="comment">                              Function codes</span>
+<a name="l00046"></a>00046 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00053"></a>00053 focus_config * 
+<a name="l00054"></a>00054 sinfo_focus_cfg_create(<span class="keywordtype">void</span>)
+<a name="l00055"></a>00055 {
+<a name="l00056"></a>00056     <span class="keywordflow">return</span> cpl_calloc(1, <span class="keyword">sizeof</span>(focus_config));
+<a name="l00057"></a>00057 }
+<a name="l00064"></a>00064 <span class="keywordtype">void</span> 
+<a name="l00065"></a>00065 sinfo_focus_cfg_destroy(focus_config * cc)
+<a name="l00066"></a>00066 {
+<a name="l00067"></a>00067     <span class="keywordflow">if</span> (cc==NULL) return ;
+<a name="l00068"></a>00068 
+<a name="l00069"></a>00069     <span class="comment">/* Free main struct */</span>
+<a name="l00070"></a>00070     cpl_free(cc);
+<a name="l00071"></a>00071 
+<a name="l00072"></a>00072     return ;
+<a name="l00073"></a>00073 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__focus__cfg_8h_source.html b/html/sinfo__focus__cfg_8h_source.html
new file mode 100644
index 0000000..443bbf3
--- /dev/null
+++ b/html/sinfo__focus__cfg_8h_source.html
@@ -0,0 +1,137 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_focus_cfg.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_focus_cfg.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name     :    sinfo_focus_cfg.h</span>
+<a name="l00022"></a>00022 <span class="comment">   Author    :    Juergen Schreiber</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on    :    February 2002</span>
+<a name="l00024"></a>00024 <span class="comment">   Description    :    focus_cfg.c definitions + handling prototypes</span>
+<a name="l00025"></a>00025 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00026"></a>00026 <span class="preprocessor">#ifndef SINFO_FOCUS_CFG_H</span>
+<a name="l00027"></a>00027 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_FOCUS_CFG_H</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00029"></a>00029 <span class="comment">                                   Includes</span>
+<a name="l00030"></a>00030 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00031"></a>00031 <span class="preprocessor">#include <stdlib.h></span>
+<a name="l00032"></a>00032 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include "sinfo_globals.h"</span>
+<a name="l00034"></a>00034 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00035"></a>00035 <span class="comment">                                   Defines</span>
+<a name="l00036"></a>00036 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00037"></a>00037 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00038"></a>00038 <span class="comment">                                   New types</span>
+<a name="l00039"></a>00039 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00040"></a>00040 <span class="comment">/*</span>
+<a name="l00041"></a>00041 <span class="comment">  point source 2D-Gaussian fit blackboard container</span>
+<a name="l00042"></a>00042 <span class="comment"></span>
+<a name="l00043"></a>00043 <span class="comment">  This structure holds all information related to the 2D-Gaussian fit</span>
+<a name="l00044"></a>00044 <span class="comment">  routine. It is used as a container for the flux of ancillary data,</span>
+<a name="l00045"></a>00045 <span class="comment">  computed values, and algorithm status. Pixel flux is separated from</span>
+<a name="l00046"></a>00046 <span class="comment">  the blackboard.</span>
+<a name="l00047"></a>00047 <span class="comment">  */</span>
+<a name="l00048"></a>00048 
+<a name="l00049"></a>00049 <span class="keyword">typedef</span> <span class="keyword">struct </span>focus_config {
+<a name="l00050"></a>00050 <span class="comment">/*-------General---------*/</span>
+<a name="l00051"></a>00051         <span class="keywordtype">char</span> inFile[FILE_NAME_SZ] ;       <span class="comment">/* file name of frame list */</span>
+<a name="l00052"></a>00052         <span class="keywordtype">char</span> ** inFrameList ; <span class="comment">/* input averaged, bad pixel corrected, </span>
+<a name="l00053"></a>00053 <span class="comment">                                 off subtracted, flatfielded, spectral tilt </span>
+<a name="l00054"></a>00054 <span class="comment">                                 corrected list of frames */</span>
+<a name="l00055"></a>00055         <span class="keywordtype">int</span> nframes ;        <span class="comment">/* number of frames in the list */</span>
+<a name="l00056"></a>00056         <span class="keywordtype">char</span> outName[FILE_NAME_SZ] ; <span class="comment">/* output name of resulting </span>
+<a name="l00057"></a>00057 <span class="comment">                                        fits data cube */</span>
+<a name="l00058"></a>00058 
+<a name="l00059"></a>00059 <span class="comment">/*------ Reconstruction ------*/</span>
+<a name="l00060"></a>00060         <span class="comment">/* the fraction [0...1] of rejected low intensity pixels </span>
+<a name="l00061"></a>00061 <span class="comment">           when taking the average of columns */</span>
+<a name="l00062"></a>00062         <span class="keywordtype">float</span> lo_reject ;
+<a name="l00063"></a>00063         <span class="comment">/* the fraction [0...1] of rejected high intensity pixels </span>
+<a name="l00064"></a>00064 <span class="comment">           when taking the average of columns */</span>
+<a name="l00065"></a>00065         <span class="keywordtype">float</span> hi_reject ;
+<a name="l00066"></a>00066         <span class="comment">/* indicates if the slitlet distances are determined by a </span>
+<a name="l00067"></a>00067 <span class="comment">           north-south test (1) </span>
+<a name="l00068"></a>00068 <span class="comment">           or slitlet edge fits (0) */</span> 
+<a name="l00069"></a>00069         <span class="keywordtype">int</span> northsouthInd  ;
+<a name="l00070"></a>00070         <span class="comment">/* name of the ASCII list of the fitted slitlet edge </span>
+<a name="l00071"></a>00071 <span class="comment">          positions or the distances of the slitlets */</span>
+<a name="l00072"></a>00072         <span class="keywordtype">char</span> poslist[FILE_NAME_SZ] ;
+<a name="l00073"></a>00073         <span class="comment">/* number of slitlets (32) */</span>
+<a name="l00074"></a>00074         <span class="keywordtype">int</span> nslits ;
+<a name="l00075"></a>00075         <span class="comment">/* sub pixel position of the column position of the left sinfo_edge of </span>
+<a name="l00076"></a>00076 <span class="comment">           the first slitlet needed if the slitlet distances were determined </span>
+<a name="l00077"></a>00077 <span class="comment">           by a north south test */</span>
+<a name="l00078"></a>00078         <span class="keywordtype">char</span> firstCol[FILE_NAME_SZ] ;
+<a name="l00079"></a>00079     <span class="comment">/* indicator for the shifting method to use */</span>
+<a name="l00080"></a>00080     <span class="keywordtype">char</span>  method[1] ;
+<a name="l00081"></a>00081         <span class="comment">/* order of polynomial if the polynomial interpolation shifting </span>
+<a name="l00082"></a>00082 <span class="comment">           method is used */</span>
+<a name="l00083"></a>00083         <span class="keywordtype">int</span> order ;
+<a name="l00084"></a>00084 <span class="comment">/*------ Gauss2Dfit ------*/</span>
+<a name="l00085"></a>00085         <span class="comment">/* lower left sinfo_edge coordinates of fitting box for 2D </span>
+<a name="l00086"></a>00086 <span class="comment">           Gaussian fit */</span>
+<a name="l00087"></a>00087         <span class="keywordtype">int</span> llx ;
+<a name="l00088"></a>00088         <span class="keywordtype">int</span> lly ;
+<a name="l00089"></a>00089         <span class="comment">/* half length in pixels of the box within the point source </span>
+<a name="l00090"></a>00090 <span class="comment">           is fitted in x and y-direction */</span>
+<a name="l00091"></a>00091         <span class="keywordtype">int</span> halfbox_x ;
+<a name="l00092"></a>00092         <span class="keywordtype">int</span> halfbox_y ;
+<a name="l00093"></a>00093         <span class="comment">/* mask parameters ( 1 or 0 ) for the fit parameters. If 1 </span>
+<a name="l00094"></a>00094 <span class="comment">           the corresponding parameter</span>
+<a name="l00095"></a>00095 <span class="comment">           is set free, if 0 the parameter is kept fixed. */</span>
+<a name="l00096"></a>00096         <span class="keywordtype">int</span> mpar0 ; <span class="comment">/* mask for the x-position */</span>
+<a name="l00097"></a>00097         <span class="keywordtype">int</span> mpar1 ; <span class="comment">/* mask for the y-position */</span>
+<a name="l00098"></a>00098         <span class="keywordtype">int</span> mpar2 ; <span class="comment">/* mask for the amplitude */</span>
+<a name="l00099"></a>00099         <span class="keywordtype">int</span> mpar3 ; <span class="comment">/* mask for the background */</span>
+<a name="l00100"></a>00100         <span class="keywordtype">int</span> mpar4 ; <span class="comment">/* mask for the fwhmx */</span>
+<a name="l00101"></a>00101         <span class="keywordtype">int</span> mpar5 ; <span class="comment">/* mask for the fwhmy */</span>
+<a name="l00102"></a>00102         <span class="keywordtype">int</span> mpar6 ; <span class="comment">/* mask for the position angle of fwhmx line */</span>
+<a name="l00103"></a>00103         <span class="comment">/* name of the resulting ASCII file containing the fit parameters */</span>
+<a name="l00104"></a>00104         <span class="keywordtype">char</span> fitlist[FILE_NAME_SZ] ;
+<a name="l00105"></a>00105         <span class="comment">/* indicator if the resulting 2D-Gaussian is stored in a fits </span>
+<a name="l00106"></a>00106 <span class="comment">           file or not */</span>
+<a name="l00107"></a>00107         <span class="keywordtype">int</span> plotGaussInd ;
+<a name="l00108"></a>00108         <span class="comment">/* name of the fits file containing the resulting 2D-Gaussian */</span>
+<a name="l00109"></a>00109         <span class="keywordtype">char</span> gaussplotName[FILE_NAME_SZ] ;
+<a name="l00110"></a>00110 } focus_config ;
+<a name="l00111"></a>00111 
+<a name="l00112"></a>00112 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00113"></a>00113 <span class="comment">                               Function prototypes</span>
+<a name="l00114"></a>00114 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00122"></a>00122 focus_config * 
+<a name="l00123"></a>00123 sinfo_focus_cfg_create(<span class="keywordtype">void</span>);
+<a name="l00124"></a>00124 
+<a name="l00131"></a>00131 <span class="keywordtype">void</span> 
+<a name="l00132"></a>00132 sinfo_focus_cfg_destroy(focus_config * cc);
+<a name="l00133"></a>00133 
+<a name="l00134"></a>00134 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__focus__determination__config_8c_source.html b/html/sinfo__focus__determination__config_8c_source.html
new file mode 100644
index 0000000..92f2832
--- /dev/null
+++ b/html/sinfo__focus__determination__config_8c_source.html
@@ -0,0 +1,306 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_focus_determination_config.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_focus_determination_config.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_focus_determination_config.c,v 1.6 2012/03/02 08:42:20 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the CPL (Common Pipeline Library)</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
+<a name="l00007"></a>00007 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span>
+<a name="l00008"></a>00008 <span class="comment"> * License as published by the Free Software Foundation; either</span>
+<a name="l00009"></a>00009 <span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
+<a name="l00014"></a>00014 <span class="comment"> * Lesser General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
+<a name="l00017"></a>00017 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2012/03/02 08:42:20 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.6 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00029"></a>00029 <span class="preprocessor">#endif</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span>
+<a name="l00031"></a>00031  <span class="comment">/****************************************************************</span>
+<a name="l00032"></a>00032 <span class="comment">  *   Focus Determination                                        *</span>
+<a name="l00033"></a>00033 <span class="comment">  ****************************************************************/</span>
+<a name="l00034"></a>00034 <span class="preprocessor">#include "cpl_parameterlist.h"</span>    <span class="comment">/* defines parlist structure */</span>
+<a name="l00035"></a>00035 <span class="preprocessor">#include "sinfo_dfs.h"</span>
+<a name="l00036"></a>00036 <span class="preprocessor">#include "sinfo_focus_determination_config.h"</span>
+<a name="l00037"></a>00037 
+<a name="l00046"></a>00046   <span class="comment">/* Focus Determination Parameters Definition */</span>
+<a name="l00047"></a>00047    
+<a name="l00048"></a>00048 
+<a name="l00049"></a>00049 <span class="keywordtype">void</span>
+<a name="l00050"></a>00050  sinfo_focus_determination_config_add(cpl_parameterlist *list)
+<a name="l00051"></a>00051 {
+<a name="l00052"></a>00052 
+<a name="l00053"></a>00053   cpl_parameter *p;
+<a name="l00054"></a>00054 
+<a name="l00055"></a>00055   <span class="keywordflow">if</span> (!list) {
+<a name="l00056"></a>00056     <span class="keywordflow">return</span>;
+<a name="l00057"></a>00057   }
+<a name="l00058"></a>00058 
+<a name="l00059"></a>00059   <span class="comment">/* Output file name */</span>
+<a name="l00060"></a>00060   <span class="comment">/* output name of resulting fits wavelength map */</span>
+<a name="l00061"></a>00061   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.focus.output_filename"</span>,
+<a name="l00062"></a>00062                   CPL_TYPE_STRING,
+<a name="l00063"></a>00063                               <span class="stringliteral">"Output File Name: "</span>,
+<a name="l00064"></a>00064                               <span class="stringliteral">"sinfoni.focus"</span>,
+<a name="l00065"></a>00065                               FOCUS_OUT_FILENAME);
+<a name="l00066"></a>00066 
+<a name="l00067"></a>00067 
+<a name="l00068"></a>00068   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"out-focus_filename"</span>);
+<a name="l00069"></a>00069   cpl_parameterlist_append(list, p);
+<a name="l00070"></a>00070 
+<a name="l00071"></a>00071 
+<a name="l00072"></a>00072 
+<a name="l00073"></a>00073  p = cpl_parameter_new_enum(<span class="stringliteral">"sinfoni.focus.method"</span>,
+<a name="l00074"></a>00074                   CPL_TYPE_STRING,
+<a name="l00075"></a>00075                               <span class="stringliteral">"Shifting method to use: "</span>,
+<a name="l00076"></a>00076                               <span class="stringliteral">"sinfoni.focus"</span>,
+<a name="l00077"></a>00077                               <span class="stringliteral">"P"</span>,
+<a name="l00078"></a>00078                                3,
+<a name="l00079"></a>00079                               <span class="stringliteral">"P"</span>,<span class="stringliteral">"F"</span>,<span class="stringliteral">"S"</span>);
+<a name="l00080"></a>00080 
+<a name="l00081"></a>00081   cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"focus-method"</span>);
+<a name="l00082"></a>00082   cpl_parameterlist_append(list, p);
+<a name="l00083"></a>00083 
+<a name="l00084"></a>00084 
+<a name="l00085"></a>00085   <span class="comment">/* Reconstruction */</span>
+<a name="l00086"></a>00086 
+<a name="l00087"></a>00087  <span class="comment">/* float </span>
+<a name="l00088"></a>00088 <span class="comment">     threshold used in the clean mean percentage of rejection used to reject </span>
+<a name="l00089"></a>00089 <span class="comment">     low and high frame */</span>
+<a name="l00090"></a>00090  <span class="comment">/* percentage of extreme pixel value to reject when calculating the mean </span>
+<a name="l00091"></a>00091 <span class="comment">    and stdev */</span>
+<a name="l00092"></a>00092   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.focus.lower_rejection"</span>,
+<a name="l00093"></a>00093                   CPL_TYPE_DOUBLE,
+<a name="l00094"></a>00094                               <span class="stringliteral">"lower rejection"</span>,
+<a name="l00095"></a>00095                               <span class="stringliteral">"sinfoni.focus"</span>,
+<a name="l00096"></a>00096                                0.1,0.0,1.0);
+<a name="l00097"></a>00097 
+<a name="l00098"></a>00098 
+<a name="l00099"></a>00099   cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"focus-det-low_rejection"</span>);
+<a name="l00100"></a>00100   cpl_parameterlist_append(list, p);
+<a name="l00101"></a>00101 
+<a name="l00102"></a>00102   <span class="comment">/* float </span>
+<a name="l00103"></a>00103 <span class="comment">     threshold used in the clean mean percentage of rejection used to reject </span>
+<a name="l00104"></a>00104 <span class="comment">     low and high frame */</span>
+<a name="l00105"></a>00105  <span class="comment">/* percentage of extreme pixel value to reject when calculating the mean </span>
+<a name="l00106"></a>00106 <span class="comment">    and stdev */</span>
+<a name="l00107"></a>00107   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.focus.higher_rejection"</span>,
+<a name="l00108"></a>00108                   CPL_TYPE_DOUBLE,
+<a name="l00109"></a>00109                               <span class="stringliteral">"high rejection"</span>,
+<a name="l00110"></a>00110                               <span class="stringliteral">"sinfoni.focus"</span>,
+<a name="l00111"></a>00111                                0.1,0.0,1.0);
+<a name="l00112"></a>00112 
+<a name="l00113"></a>00113 
+<a name="l00114"></a>00114   cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"focus-det-high_rejection"</span>);
+<a name="l00115"></a>00115   cpl_parameterlist_append(list, p);
+<a name="l00116"></a>00116 
+<a name="l00117"></a>00117 <span class="comment">/* indicates if the slitlet distances are determined by </span>
+<a name="l00118"></a>00118 <span class="comment">   a north-south test (1) </span>
+<a name="l00119"></a>00119 <span class="comment">           or </span>
+<a name="l00120"></a>00120 <span class="comment">   slitlet sinfo_edge fits (0) */</span> 
+<a name="l00121"></a>00121   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.focus.north_south_index"</span>,
+<a name="l00122"></a>00122                   CPL_TYPE_BOOL,
+<a name="l00123"></a>00123                               <span class="stringliteral">"North South Index"</span>,
+<a name="l00124"></a>00124                               <span class="stringliteral">"sinfoni.focus"</span>,
+<a name="l00125"></a>00125                               TRUE);
+<a name="l00126"></a>00126 
+<a name="l00127"></a>00127   cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"focus-det-ns_index"</span>);
+<a name="l00128"></a>00128   cpl_parameterlist_append(list, p);
+<a name="l00129"></a>00129 
+<a name="l00130"></a>00130   <span class="comment">/* number of slitlets (32) */</span>
+<a name="l00131"></a>00131   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.focus.nslits"</span>,
+<a name="l00132"></a>00132                   CPL_TYPE_INT,
+<a name="l00133"></a>00133                               <span class="stringliteral">"Number Of Slits"</span>,
+<a name="l00134"></a>00134                               <span class="stringliteral">"sinfoni.focus"</span>,
+<a name="l00135"></a>00135                               32);
+<a name="l00136"></a>00136 
+<a name="l00137"></a>00137 
+<a name="l00138"></a>00138   cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"focus-det-nslits"</span>);
+<a name="l00139"></a>00139   cpl_parameterlist_append(list, p);
+<a name="l00140"></a>00140 
+<a name="l00141"></a>00141   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.focus.order"</span>,
+<a name="l00142"></a>00142                   CPL_TYPE_INT,
+<a name="l00143"></a>00143                               <span class="stringliteral">"Order"</span>,
+<a name="l00144"></a>00144                               <span class="stringliteral">"sinfoni.focus"</span>,
+<a name="l00145"></a>00145                               2);
+<a name="l00146"></a>00146 
+<a name="l00147"></a>00147   cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"focus-det-order"</span>);
+<a name="l00148"></a>00148   cpl_parameterlist_append(list, p);
+<a name="l00149"></a>00149 
+<a name="l00150"></a>00150 
+<a name="l00151"></a>00151   <span class="comment">/* Gauss 2D Fit */</span>
+<a name="l00152"></a>00152   <span class="comment">/* lower left sinfo_edge coordinates of fitting box for 2D Gaussian fit */</span>
+<a name="l00153"></a>00153   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.focus.llx"</span>,
+<a name="l00154"></a>00154                   CPL_TYPE_INT,
+<a name="l00155"></a>00155                               <span class="stringliteral">"llx"</span>,
+<a name="l00156"></a>00156                               <span class="stringliteral">"sinfoni.focus"</span>,
+<a name="l00157"></a>00157                               9,DET_PIX_MIN,DET_PIX_MAX);
+<a name="l00158"></a>00158 
+<a name="l00159"></a>00159   cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"focus-det-llx"</span>);
+<a name="l00160"></a>00160   cpl_parameterlist_append(list, p);
+<a name="l00161"></a>00161 
+<a name="l00162"></a>00162   <span class="comment">/* lower left sinfo_edge coordinates of fitting box for 2D Gaussian fit */</span>
+<a name="l00163"></a>00163   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.focus.lly"</span>,
+<a name="l00164"></a>00164                   CPL_TYPE_INT,
+<a name="l00165"></a>00165                               <span class="stringliteral">"lly"</span>,
+<a name="l00166"></a>00166                               <span class="stringliteral">"sinfoni.focus"</span>,
+<a name="l00167"></a>00167                               9,DET_PIX_MIN,DET_PIX_MAX);
+<a name="l00168"></a>00168 
+<a name="l00169"></a>00169 
+<a name="l00170"></a>00170   cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"focus-det-lly"</span>);
+<a name="l00171"></a>00171   cpl_parameterlist_append(list, p);
+<a name="l00172"></a>00172 
+<a name="l00173"></a>00173 <span class="comment">/* half length in pixels of the box within the point source is fitted in x </span>
+<a name="l00174"></a>00174 <span class="comment">   and y-direction */</span>
+<a name="l00175"></a>00175   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.focus.halfbox_x"</span>,
+<a name="l00176"></a>00176                   CPL_TYPE_INT,
+<a name="l00177"></a>00177                               <span class="stringliteral">"half box x"</span>,
+<a name="l00178"></a>00178                               <span class="stringliteral">"sinfoni.focus"</span>,
+<a name="l00179"></a>00179                               7,DET_PIX_MIN,DET_PIX_MAX);
+<a name="l00180"></a>00180 
+<a name="l00181"></a>00181   cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"focus-det-hbx"</span>);
+<a name="l00182"></a>00182   cpl_parameterlist_append(list, p);
+<a name="l00183"></a>00183 
+<a name="l00184"></a>00184 <span class="comment">/* half length in pixels of the box within the point source is fitted in x </span>
+<a name="l00185"></a>00185 <span class="comment">   and y-direction */</span>
+<a name="l00186"></a>00186   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.focus.halfbox_y"</span>,
+<a name="l00187"></a>00187                   CPL_TYPE_INT,
+<a name="l00188"></a>00188                               <span class="stringliteral">"half box y"</span>,
+<a name="l00189"></a>00189                               <span class="stringliteral">"sinfoni.focus"</span>,
+<a name="l00190"></a>00190                               7,DET_PIX_MIN,DET_PIX_MAX);
+<a name="l00191"></a>00191 
+<a name="l00192"></a>00192 
+<a name="l00193"></a>00193   cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"focus-det-hby"</span>);
+<a name="l00194"></a>00194   cpl_parameterlist_append(list, p);
+<a name="l00195"></a>00195 
+<a name="l00196"></a>00196   <span class="comment">/* mask for the x-position */</span>
+<a name="l00197"></a>00197   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.focus.mpar0"</span>,
+<a name="l00198"></a>00198                   CPL_TYPE_INT,
+<a name="l00199"></a>00199                               <span class="stringliteral">"mask par 0"</span>,
+<a name="l00200"></a>00200                               <span class="stringliteral">"sinfoni.focus"</span>,
+<a name="l00201"></a>00201                               1);
+<a name="l00202"></a>00202 
+<a name="l00203"></a>00203   cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"focus-det-mpar0"</span>);
+<a name="l00204"></a>00204   cpl_parameterlist_append(list, p);
+<a name="l00205"></a>00205 
+<a name="l00206"></a>00206   <span class="comment">/* mask for the y-position */</span>
+<a name="l00207"></a>00207   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.focus.mpar1"</span>,
+<a name="l00208"></a>00208                   CPL_TYPE_INT,
+<a name="l00209"></a>00209                               <span class="stringliteral">"mask par 1"</span>,
+<a name="l00210"></a>00210                               <span class="stringliteral">"sinfoni.focus"</span>,
+<a name="l00211"></a>00211                               1);
+<a name="l00212"></a>00212 
+<a name="l00213"></a>00213   cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"focus-det-mpar1"</span>);
+<a name="l00214"></a>00214   cpl_parameterlist_append(list, p);
+<a name="l00215"></a>00215 
+<a name="l00216"></a>00216   <span class="comment">/* mask for the amplitude */</span>
+<a name="l00217"></a>00217   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.focus.mpar2"</span>,
+<a name="l00218"></a>00218                   CPL_TYPE_INT,
+<a name="l00219"></a>00219                               <span class="stringliteral">"mask par 2"</span>,
+<a name="l00220"></a>00220                               <span class="stringliteral">"sinfoni.focus"</span>,
+<a name="l00221"></a>00221                               1);
+<a name="l00222"></a>00222 
+<a name="l00223"></a>00223   cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"focus-det-mpar2"</span>);
+<a name="l00224"></a>00224   cpl_parameterlist_append(list, p);
+<a name="l00225"></a>00225 
+<a name="l00226"></a>00226   <span class="comment">/* mask for the background */</span>
+<a name="l00227"></a>00227   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.focus.mpar3"</span>,
+<a name="l00228"></a>00228                   CPL_TYPE_INT,
+<a name="l00229"></a>00229                               <span class="stringliteral">"mask par 3"</span>,
+<a name="l00230"></a>00230                               <span class="stringliteral">"sinfoni.focus"</span>,
+<a name="l00231"></a>00231                               1);
+<a name="l00232"></a>00232 
+<a name="l00233"></a>00233   cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"focus-det-mpar3"</span>);
+<a name="l00234"></a>00234   cpl_parameterlist_append(list, p);
+<a name="l00235"></a>00235 
+<a name="l00236"></a>00236   <span class="comment">/* mask for the fwhmx */</span>
+<a name="l00237"></a>00237   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.focus.mpar4"</span>,
+<a name="l00238"></a>00238                   CPL_TYPE_INT,
+<a name="l00239"></a>00239                               <span class="stringliteral">"mask par 4"</span>,
+<a name="l00240"></a>00240                               <span class="stringliteral">"sinfoni.focus"</span>,
+<a name="l00241"></a>00241                               1);
+<a name="l00242"></a>00242 
+<a name="l00243"></a>00243   cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"focus-det-mpar4"</span>);
+<a name="l00244"></a>00244   cpl_parameterlist_append(list, p);
+<a name="l00245"></a>00245 
+<a name="l00246"></a>00246   <span class="comment">/* mask for the fwhmy */</span>
+<a name="l00247"></a>00247   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.focus.mpar5"</span>,
+<a name="l00248"></a>00248                   CPL_TYPE_INT,
+<a name="l00249"></a>00249                               <span class="stringliteral">"mask par 5"</span>,
+<a name="l00250"></a>00250                               <span class="stringliteral">"sinfoni.focus"</span>,
+<a name="l00251"></a>00251                               1);
+<a name="l00252"></a>00252 
+<a name="l00253"></a>00253   cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"focus-det-mpar5"</span>);
+<a name="l00254"></a>00254   cpl_parameterlist_append(list, p);
+<a name="l00255"></a>00255 
+<a name="l00256"></a>00256   <span class="comment">/* mask for the position angle of fwhmx line */</span>
+<a name="l00257"></a>00257   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.focus.mpar6"</span>,
+<a name="l00258"></a>00258                   CPL_TYPE_INT,
+<a name="l00259"></a>00259                               <span class="stringliteral">"mask par 6"</span>,
+<a name="l00260"></a>00260                               <span class="stringliteral">"sinfoni.focus"</span>,
+<a name="l00261"></a>00261                               1);
+<a name="l00262"></a>00262 
+<a name="l00263"></a>00263   cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"focus-det-mpar6"</span>);
+<a name="l00264"></a>00264   cpl_parameterlist_append(list, p);
+<a name="l00265"></a>00265 
+<a name="l00266"></a>00266   <span class="comment">/* name of the resulting ASCII file containing the fit parameters */</span>
+<a name="l00267"></a>00267   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.focus.fit_list"</span>,
+<a name="l00268"></a>00268                   CPL_TYPE_STRING,
+<a name="l00269"></a>00269                               <span class="stringliteral">"Fit List: "</span>,
+<a name="l00270"></a>00270                               <span class="stringliteral">"sinfoni.fit_list"</span>,
+<a name="l00271"></a>00271                               FOCUS_FITPAR_OUT_FILENAME);
+<a name="l00272"></a>00272 
+<a name="l00273"></a>00273   cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"focus-det-fit_list"</span>);
+<a name="l00274"></a>00274   cpl_parameterlist_append(list, p);
+<a name="l00275"></a>00275 
+<a name="l00276"></a>00276  <span class="comment">/* indicator if the resulting 2D-Gaussian is stored in a fits file or not */</span>
+<a name="l00277"></a>00277   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.focus.plot_gauss_ind"</span>,
+<a name="l00278"></a>00278                   CPL_TYPE_BOOL,
+<a name="l00279"></a>00279                               <span class="stringliteral">"Plot Gauss Ind"</span>,
+<a name="l00280"></a>00280                               <span class="stringliteral">"sinfoni.focus"</span>,
+<a name="l00281"></a>00281                               TRUE);
+<a name="l00282"></a>00282 
+<a name="l00283"></a>00283   cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"focus-det-gauss_ind"</span>);
+<a name="l00284"></a>00284   cpl_parameterlist_append(list, p);
+<a name="l00285"></a>00285 
+<a name="l00286"></a>00286 
+<a name="l00287"></a>00287   <span class="comment">/* name of the fits file containing the resulting 2D-Gaussian */</span>
+<a name="l00288"></a>00288   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.focus.gauss_plot_name"</span>,
+<a name="l00289"></a>00289                   CPL_TYPE_STRING,
+<a name="l00290"></a>00290                               <span class="stringliteral">"Gauss Plot Name: "</span>,
+<a name="l00291"></a>00291                               <span class="stringliteral">"sinfoni.focus"</span>,
+<a name="l00292"></a>00292                               FOCUS_GAUSSPLOT_OUT_FILENAME);
+<a name="l00293"></a>00293 
+<a name="l00294"></a>00294   cpl_parameter_set_alias(p,  
+<a name="l00295"></a>00295        CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"focus-det-gauss_plot_name"</span>);
+<a name="l00296"></a>00296   cpl_parameterlist_append(list, p);
+<a name="l00297"></a>00297 
+<a name="l00298"></a>00298 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__focus__determination__config_8h_source.html b/html/sinfo__focus__determination__config_8h_source.html
new file mode 100644
index 0000000..bf76755
--- /dev/null
+++ b/html/sinfo__focus__determination__config_8h_source.html
@@ -0,0 +1,52 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_focus_determination_config.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_focus_determination_config.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_focus_determination_config.h,v 1.1 2006/10/20 08:06:32 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the CPL (Common Pipeline Library)</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
+<a name="l00007"></a>00007 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span>
+<a name="l00008"></a>00008 <span class="comment"> * License as published by the Free Software Foundation; either</span>
+<a name="l00009"></a>00009 <span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
+<a name="l00014"></a>00014 <span class="comment"> * Lesser General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
+<a name="l00017"></a>00017 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2006/10/20 08:06:32 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.1 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028  <span class="comment">/****************************************************************</span>
+<a name="l00029"></a>00029 <span class="comment">  *   Focus Determination                                        *</span>
+<a name="l00030"></a>00030 <span class="comment">  ****************************************************************/</span>
+<a name="l00031"></a>00031 <span class="preprocessor">#include "cpl.h"</span>    <span class="comment">/* defines parlist structure */</span>
+<a name="l00032"></a>00032 <span class="comment">/*</span>
+<a name="l00033"></a>00033 <span class="comment">#include "sinfo_dfs.h"</span>
+<a name="l00034"></a>00034 <span class="comment">*/</span>
+<a name="l00035"></a>00035 <span class="preprocessor">#include "sinfo_hidden.h"</span>
+<a name="l00036"></a>00036 <span class="keywordtype">void</span> sinfo_focus_determination_config_add(cpl_parameterlist *list);
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__focus__ini_8h_source.html b/html/sinfo__focus__ini_8h_source.html
new file mode 100644
index 0000000..f9d6d20
--- /dev/null
+++ b/html/sinfo__focus__ini_8h_source.html
@@ -0,0 +1,65 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_focus_ini.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_focus_ini.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name    :   sinfo_focus_ini.h</span>
+<a name="l00022"></a>00022 <span class="comment">   Author       :    Juergen Schreiber</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on   :    Feb 13, 2002</span>
+<a name="l00024"></a>00024 <span class="comment">   Description  :    ini file handling for SPIFFIs focus finding</span>
+<a name="l00025"></a>00025 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00026"></a>00026 <span class="preprocessor">#ifndef SINFO_FOCUS_INI_H</span>
+<a name="l00027"></a>00027 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_FOCUS_INI_H</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00029"></a>00029 <span class="comment">                                Includes</span>
+<a name="l00030"></a>00030 <span class="comment">---------------------------------------------------------------------------*/</span>
+<a name="l00031"></a>00031 <span class="preprocessor">#include "sinfo_focus_cfg.h"</span>
+<a name="l00032"></a>00032 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00033"></a>00033 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00034"></a>00034 <span class="comment">                             Function prototypes </span>
+<a name="l00035"></a>00035 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00036"></a>00036 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l00050"></a>00050 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00051"></a>00051 <span class="keywordtype">int</span> 
+<a name="l00052"></a>00052 generateFocus_ini_file(
+<a name="l00053"></a>00053         <span class="keywordtype">char</span> * ini_name,
+<a name="l00054"></a>00054         <span class="keywordtype">char</span> * name_i,
+<a name="l00055"></a>00055         <span class="keywordtype">char</span> * name_o
+<a name="l00056"></a>00056 );
+<a name="l00057"></a>00057  
+<a name="l00068"></a>00068 focus_config * 
+<a name="l00069"></a>00069 parse_focus_ini_file(<span class="keywordtype">char</span> * ini_name) ;
+<a name="l00070"></a>00070  
+<a name="l00071"></a>00071 
+<a name="l00072"></a>00072 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__focus__ini__by__cpl_8c_source.html b/html/sinfo__focus__ini__by__cpl_8c_source.html
new file mode 100644
index 0000000..15526a9
--- /dev/null
+++ b/html/sinfo__focus__ini__by__cpl_8c_source.html
@@ -0,0 +1,289 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_focus_ini_by_cpl.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_focus_ini_by_cpl.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name    :   sinfo_focus_ini_by_cpl.c</span>
+<a name="l00022"></a>00022 <span class="comment">   Author       :   Andrea Modigliani</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on   :   May 20, 2004</span>
+<a name="l00024"></a>00024 <span class="comment">   Description  :   cpl input handling for SPIFFI</span>
+<a name="l00025"></a>00025 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00026"></a>00026 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00027"></a>00027 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00028"></a>00028 <span class="preprocessor">#endif</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00030"></a>00030 <span class="comment">                                Includes</span>
+<a name="l00031"></a>00031 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00032"></a>00032 <span class="preprocessor">#include <string.h></span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include "sinfo_focus_ini_by_cpl.h"</span>
+<a name="l00034"></a>00034 <span class="preprocessor">#include "sinfo_pro_types.h"</span>
+<a name="l00035"></a>00035 <span class="preprocessor">#include "sinfo_functions.h"</span>
+<a name="l00036"></a>00036 <span class="preprocessor">#include "sinfo_file_handling.h"</span>
+<a name="l00037"></a>00037 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00038"></a>00038 <span class="comment">                    Functions private to this module</span>
+<a name="l00039"></a>00039 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00040"></a>00040 <span class="keyword">static</span> <span class="keywordtype">void</span> 
+<a name="l00041"></a>00041 parse_section_frames(focus_config *, cpl_parameterlist* cpl_cfg, 
+<a name="l00042"></a>00042                    cpl_frameset* sof,cpl_frameset** stk, <span class="keywordtype">int</span>* status);
+<a name="l00043"></a>00043 <span class="keyword">static</span> <span class="keywordtype">void</span> 
+<a name="l00044"></a>00044 parse_section_reconstruction(focus_config *, cpl_parameterlist* cpl_cfg);
+<a name="l00045"></a>00045 <span class="keyword">static</span> <span class="keywordtype">void</span> 
+<a name="l00046"></a>00046 parse_section_gauss2dfit(focus_config *, cpl_parameterlist* cpl_cfg);
+<a name="l00047"></a>00047 
+<a name="l00070"></a>00070 focus_config * 
+<a name="l00071"></a>00071 sinfo_parse_cpl_input_focus(cpl_parameterlist * cpl_cfg, cpl_frameset* sof,
+<a name="l00072"></a>00072                      cpl_frameset** stk)
+<a name="l00073"></a>00073 {
+<a name="l00074"></a>00074         focus_config  *       cfg = sinfo_focus_cfg_create();
+<a name="l00075"></a>00075   <span class="keywordtype">int</span> status=0;
+<a name="l00076"></a>00076         <span class="comment">/*</span>
+<a name="l00077"></a>00077 <span class="comment">         * Perform sanity checks, fill up the structure with what was</span>
+<a name="l00078"></a>00078 <span class="comment">         * found in the ini file</span>
+<a name="l00079"></a>00079 <span class="comment">         */</span>
+<a name="l00080"></a>00080 
+<a name="l00081"></a>00081         parse_section_reconstruction   (cfg, cpl_cfg);
+<a name="l00082"></a>00082         parse_section_gauss2dfit       (cfg, cpl_cfg);
+<a name="l00083"></a>00083         parse_section_frames           (cfg, cpl_cfg,sof,stk,&status);
+<a name="l00084"></a>00084         <span class="keywordflow">if</span> (status > 0) {
+<a name="l00085"></a>00085                 <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"parsing cpl input"</span>);
+<a name="l00086"></a>00086                 sinfo_focus_cfg_destroy(cfg);
+<a name="l00087"></a>00087                 cfg = NULL ;
+<a name="l00088"></a>00088                 <span class="keywordflow">return</span> NULL ;
+<a name="l00089"></a>00089         }
+<a name="l00090"></a>00090         <span class="keywordflow">return</span> cfg ;
+<a name="l00091"></a>00091 }
+<a name="l00092"></a>00092 
+<a name="l00103"></a>00103 <span class="keyword">static</span> <span class="keywordtype">void</span>   
+<a name="l00104"></a>00104 parse_section_frames(focus_config * cfg,
+<a name="l00105"></a>00105                      cpl_parameterlist* cpl_cfg,
+<a name="l00106"></a>00106                      cpl_frameset* sof,
+<a name="l00107"></a>00107                      cpl_frameset** raw, 
+<a name="l00108"></a>00108                      <span class="keywordtype">int</span>* status)
+<a name="l00109"></a>00109 {
+<a name="l00110"></a>00110 
+<a name="l00111"></a>00111 
+<a name="l00112"></a>00112    <span class="keywordtype">char</span>            *       name ;
+<a name="l00113"></a>00113     <span class="keywordtype">int</span> nframes=0;
+<a name="l00114"></a>00114    <span class="keywordtype">int</span> nraw=0;
+<a name="l00115"></a>00115    cpl_frame* frame   = NULL;
+<a name="l00116"></a>00116    cpl_parameter *p; 
+<a name="l00117"></a>00117 
+<a name="l00118"></a>00118 
+<a name="l00119"></a>00119    <span class="keywordtype">char</span> spat_res[FILE_NAME_SZ];
+<a name="l00120"></a>00120    <span class="keywordtype">char</span> lamp_status[FILE_NAME_SZ];
+<a name="l00121"></a>00121    <span class="keywordtype">char</span> band[FILE_NAME_SZ];
+<a name="l00122"></a>00122    <span class="keywordtype">int</span> ins_set=0;
+<a name="l00123"></a>00123 
+<a name="l00124"></a>00124 
+<a name="l00125"></a>00125    <span class="keywordtype">char</span> * tag;
+<a name="l00126"></a>00126    <span class="keywordtype">int</span> i=0;
+<a name="l00127"></a>00127    nframes = cpl_frameset_get_size(sof);
+<a name="l00128"></a>00128     <span class="comment">/* Get the raw and the calibration files */</span>
+<a name="l00129"></a>00129     <span class="comment">/* Labelise the input frames according to their tags */</span>
+<a name="l00130"></a>00130 
+<a name="l00131"></a>00131   *raw=cpl_frameset_new();
+<a name="l00132"></a>00132    sinfo_extract_raw_frames_type(sof,raw,PRO_FOCUS_STACKED);
+<a name="l00133"></a>00133 
+<a name="l00134"></a>00134 
+<a name="l00135"></a>00135    nraw=cpl_frameset_get_size(*raw);
+<a name="l00136"></a>00136    <span class="keywordflow">if</span> (nraw < 1) {
+<a name="l00137"></a>00137       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Too few (%d) raw frames (%s) present in"</span>
+<a name="l00138"></a>00138             <span class="stringliteral">"frameset!Aborting..."</span>,nraw,PRO_FOCUS_STACKED);
+<a name="l00139"></a>00139           (*status)++;
+<a name="l00140"></a>00140           <span class="keywordflow">return</span>;
+<a name="l00141"></a>00141    }
+<a name="l00142"></a>00142    <span class="comment">/* Allocate structures to go into the blackboard */</span>
+<a name="l00143"></a>00143    cfg->inFrameList     = cpl_malloc(nraw * <span class="keyword">sizeof</span>(<span class="keywordtype">char</span>*));
+<a name="l00144"></a>00144  
+<a name="l00145"></a>00145    <span class="comment">/* Browse through the charmatrix to get names and file types */</span>
+<a name="l00146"></a>00146    <span class="keywordflow">for</span> (i=0 ; i<nraw ; i++) {
+<a name="l00147"></a>00147       frame = cpl_frameset_get_frame(*raw,i);
+<a name="l00148"></a>00148       name= (<span class="keywordtype">char</span>*) cpl_frame_get_filename(frame);
+<a name="l00149"></a>00149       <span class="keywordflow">if</span>(sinfo_file_exists(name)==1) {
+<a name="l00150"></a>00150     <span class="comment">/* to go on the file must exist */</span>
+<a name="l00151"></a>00151     <span class="keywordflow">if</span>(cpl_frame_get_tag(frame) != NULL) {
+<a name="l00152"></a>00152       <span class="comment">/* If the frame has a tag we process it. Else it is an object */</span> 
+<a name="l00153"></a>00153       tag= (<span class="keywordtype">char</span>*) cpl_frame_get_tag(frame);
+<a name="l00154"></a>00154           <span class="keywordflow">if</span>(sinfo_is_stack(tag)) 
+<a name="l00155"></a>00155         {
+<a name="l00156"></a>00156              cfg->inFrameList[i]=cpl_strdup(cpl_frame_get_filename(frame));
+<a name="l00157"></a>00157         }
+<a name="l00158"></a>00158           <span class="keywordflow">else</span> {
+<a name="l00159"></a>00159             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"No good frame tag %s in input frame set"</span>,tag);
+<a name="l00160"></a>00160         (*status)++;
+<a name="l00161"></a>00161             <span class="keywordflow">return</span>;
+<a name="l00162"></a>00162       }
+<a name="l00163"></a>00163     }
+<a name="l00164"></a>00164       }
+<a name="l00165"></a>00165       <span class="comment">/* Store file name into inFrameList */</span>
+<a name="l00166"></a>00166    }
+<a name="l00167"></a>00167 
+<a name="l00168"></a>00168    <span class="comment">/* Copy relevant information into the blackboard */</span>
+<a name="l00169"></a>00169    cfg->nframes = nraw ;
+<a name="l00170"></a>00170 
+<a name="l00171"></a>00171 
+<a name="l00172"></a>00172    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.focus.output_filename"</span>);
+<a name="l00173"></a>00173    strcpy(cfg -> outName, cpl_parameter_get_string(p));
+<a name="l00174"></a>00174 
+<a name="l00175"></a>00175    <span class="keywordflow">if</span>(NULL != cpl_frameset_find(sof,PRO_FIRST_COL)) {
+<a name="l00176"></a>00176       frame = cpl_frameset_find(sof,PRO_FIRST_COL);
+<a name="l00177"></a>00177       strcpy(cfg -> firstCol,cpl_strdup(cpl_frame_get_filename(frame)));
+<a name="l00178"></a>00178    } <span class="keywordflow">else</span> {
+<a name="l00179"></a>00179       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Frame %s not found! Exit!"</span>, PRO_FIRST_COL);
+<a name="l00180"></a>00180         (*status)++;
+<a name="l00181"></a>00181       <span class="keywordflow">return</span>;
+<a name="l00182"></a>00182    }
+<a name="l00183"></a>00183 
+<a name="l00184"></a>00184    <span class="keywordflow">if</span>(NULL != cpl_frameset_find(sof,PRO_SLITLETS_DISTANCE)) {
+<a name="l00185"></a>00185       frame = cpl_frameset_find(sof,PRO_SLITLETS_DISTANCE);
+<a name="l00186"></a>00186       strcpy(cfg -> poslist,cpl_strdup(cpl_frame_get_filename(frame)));
+<a name="l00187"></a>00187    } <span class="keywordflow">else</span> {
+<a name="l00188"></a>00188       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Frame %s not found! Exit!"</span>, PRO_SLITLETS_DISTANCE);
+<a name="l00189"></a>00189         (*status)++;
+<a name="l00190"></a>00190       <span class="keywordflow">return</span>;
+<a name="l00191"></a>00191    }
+<a name="l00192"></a>00192 
+<a name="l00193"></a>00193 
+<a name="l00194"></a>00194 
+<a name="l00195"></a>00195    frame = cpl_frameset_get_frame(*raw,0);
+<a name="l00196"></a>00196    sinfo_get_spatial_res(frame,spat_res);
+<a name="l00197"></a>00197  
+<a name="l00198"></a>00198    <span class="keywordflow">switch</span>(sinfo_frame_is_on(frame)) 
+<a name="l00199"></a>00199      {
+<a name="l00200"></a>00200    <span class="keywordflow">case</span> 0: 
+<a name="l00201"></a>00201       strcpy(lamp_status,<span class="stringliteral">"on"</span>);
+<a name="l00202"></a>00202       <span class="keywordflow">break</span>;
+<a name="l00203"></a>00203     <span class="keywordflow">case</span> 1: 
+<a name="l00204"></a>00204       strcpy(lamp_status,<span class="stringliteral">"off"</span>);
+<a name="l00205"></a>00205       <span class="keywordflow">break</span>;
+<a name="l00206"></a>00206     <span class="keywordflow">case</span> -1:
+<a name="l00207"></a>00207       strcpy(lamp_status,<span class="stringliteral">"undefined"</span>);
+<a name="l00208"></a>00208       <span class="keywordflow">break</span>;
+<a name="l00209"></a>00209     <span class="keywordflow">default</span>: 
+<a name="l00210"></a>00210       strcpy(lamp_status,<span class="stringliteral">"undefined"</span>);
+<a name="l00211"></a>00211       <span class="keywordflow">break</span>;
+<a name="l00212"></a>00212      }
+<a name="l00213"></a>00213 
+<a name="l00214"></a>00214    sinfo_get_band(frame,band);
+<a name="l00215"></a>00215    sinfo_msg(<span class="stringliteral">"Spatial resolution: %s lamp_status: %s band: %s \n"</span>,
+<a name="l00216"></a>00216                      spat_res,    lamp_status,    band);
+<a name="l00217"></a>00217 
+<a name="l00218"></a>00218 
+<a name="l00219"></a>00219    sinfo_get_ins_set(band,&ins_set);
+<a name="l00220"></a>00220    <span class="keywordflow">return</span>;
+<a name="l00221"></a>00221 }
+<a name="l00222"></a>00222 
+<a name="l00230"></a>00230 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00231"></a>00231 parse_section_reconstruction(focus_config * cfg,cpl_parameterlist * cpl_cfg)
+<a name="l00232"></a>00232 {
+<a name="l00233"></a>00233 
+<a name="l00234"></a>00234 
+<a name="l00235"></a>00235   cpl_parameter* p;
+<a name="l00236"></a>00236 
+<a name="l00237"></a>00237    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.focus.lower_rejection"</span>);
+<a name="l00238"></a>00238    cfg -> lo_reject = cpl_parameter_get_double(p);
+<a name="l00239"></a>00239 
+<a name="l00240"></a>00240    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.focus.higher_rejection"</span>);
+<a name="l00241"></a>00241    cfg -> hi_reject =  cpl_parameter_get_double(p);
+<a name="l00242"></a>00242 
+<a name="l00243"></a>00243    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.focus.north_south_index"</span>);
+<a name="l00244"></a>00244    cfg -> northsouthInd = cpl_parameter_get_bool(p);
+<a name="l00245"></a>00245 
+<a name="l00246"></a>00246    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.focus.nslits"</span>);
+<a name="l00247"></a>00247    cfg -> nslits = cpl_parameter_get_int(p);
+<a name="l00248"></a>00248  
+<a name="l00249"></a>00249    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.focus.method"</span>);
+<a name="l00250"></a>00250    strcpy(cfg->method, cpl_parameter_get_string(p));
+<a name="l00251"></a>00251 
+<a name="l00252"></a>00252    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.focus.order"</span>);
+<a name="l00253"></a>00253    cfg -> order= cpl_parameter_get_int(p);
+<a name="l00254"></a>00254 
+<a name="l00255"></a>00255 }
+<a name="l00256"></a>00256 
+<a name="l00264"></a>00264 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00265"></a>00265 parse_section_gauss2dfit(focus_config * cfg,cpl_parameterlist * cpl_cfg)
+<a name="l00266"></a>00266 {
+<a name="l00267"></a>00267  cpl_parameter* p;
+<a name="l00268"></a>00268    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.focus.llx"</span>);
+<a name="l00269"></a>00269    cfg -> llx = cpl_parameter_get_int(p);
+<a name="l00270"></a>00270 
+<a name="l00271"></a>00271    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.focus.lly"</span>);
+<a name="l00272"></a>00272    cfg -> lly = cpl_parameter_get_int(p);
+<a name="l00273"></a>00273 
+<a name="l00274"></a>00274    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.focus.halfbox_x"</span>);
+<a name="l00275"></a>00275    cfg -> halfbox_x =  cpl_parameter_get_int(p);
+<a name="l00276"></a>00276 
+<a name="l00277"></a>00277    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.focus.halfbox_y"</span>);
+<a name="l00278"></a>00278    cfg -> halfbox_y = cpl_parameter_get_int(p);
+<a name="l00279"></a>00279 
+<a name="l00280"></a>00280    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.focus.mpar0"</span>);
+<a name="l00281"></a>00281    cfg -> mpar0 = cpl_parameter_get_int(p);
+<a name="l00282"></a>00282 
+<a name="l00283"></a>00283    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.focus.mpar1"</span>);
+<a name="l00284"></a>00284    cfg -> mpar1 = cpl_parameter_get_int(p);
+<a name="l00285"></a>00285 
+<a name="l00286"></a>00286    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.focus.mpar2"</span>);
+<a name="l00287"></a>00287    cfg -> mpar2 = cpl_parameter_get_int(p);
+<a name="l00288"></a>00288 
+<a name="l00289"></a>00289    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.focus.mpar3"</span>);
+<a name="l00290"></a>00290    cfg -> mpar3 = cpl_parameter_get_int(p);
+<a name="l00291"></a>00291 
+<a name="l00292"></a>00292    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.focus.mpar4"</span>);
+<a name="l00293"></a>00293    cfg -> mpar4 = cpl_parameter_get_int(p);
+<a name="l00294"></a>00294 
+<a name="l00295"></a>00295    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.focus.mpar5"</span>);
+<a name="l00296"></a>00296    cfg -> mpar5 = cpl_parameter_get_int(p);
+<a name="l00297"></a>00297 
+<a name="l00298"></a>00298    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.focus.mpar6"</span>);
+<a name="l00299"></a>00299    cfg -> mpar6 = cpl_parameter_get_int(p);
+<a name="l00300"></a>00300 
+<a name="l00301"></a>00301    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.focus.fit_list"</span>);
+<a name="l00302"></a>00302    strcpy(cfg -> fitlist, cpl_parameter_get_string(p));
+<a name="l00303"></a>00303 
+<a name="l00304"></a>00304    <span class="comment">/* int or string ?*/</span>
+<a name="l00305"></a>00305    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.focus.plot_gauss_ind"</span>);
+<a name="l00306"></a>00306    cfg -> plotGaussInd = cpl_parameter_get_bool(p);
+<a name="l00307"></a>00307 
+<a name="l00308"></a>00308    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.focus.gauss_plot_name"</span>);
+<a name="l00309"></a>00309    strcpy( cfg -> gaussplotName, cpl_parameter_get_string(p));
+<a name="l00310"></a>00310 
+<a name="l00311"></a>00311    return ;
+<a name="l00312"></a>00312 }
+<a name="l00319"></a>00319 <span class="keywordtype">void</span>
+<a name="l00320"></a>00320 sinfo_free_focus(focus_config * cfg) {
+<a name="l00321"></a>00321    cpl_free(cfg->inFrameList);
+<a name="l00322"></a>00322    sinfo_focus_cfg_destroy (cfg);
+<a name="l00323"></a>00323   
+<a name="l00324"></a>00324    <span class="keywordflow">return</span>;
+<a name="l00325"></a>00325 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__focus__ini__by__cpl_8h_source.html b/html/sinfo__focus__ini__by__cpl_8h_source.html
new file mode 100644
index 0000000..51a0473
--- /dev/null
+++ b/html/sinfo__focus__ini__by__cpl_8h_source.html
@@ -0,0 +1,63 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_focus_ini_by_cpl.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_focus_ini_by_cpl.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name    :   sinfo_focus_ini_by_cpl.h</span>
+<a name="l00022"></a>00022 <span class="comment">   Author       :   Andrea Modigliani</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on   :   May 20, 2004</span>
+<a name="l00024"></a>00024 <span class="comment">   Description  :   cpl input handling for SPIFFIs focus finding</span>
+<a name="l00025"></a>00025 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00026"></a>00026 <span class="preprocessor">#ifndef SINFO_FOCUS_INI_BY_CPL_H</span>
+<a name="l00027"></a>00027 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_FOCUS_INI_BY_CPL_H</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00029"></a>00029 <span class="comment">                                Includes</span>
+<a name="l00030"></a>00030 <span class="comment">---------------------------------------------------------------------------*/</span>
+<a name="l00031"></a>00031 <span class="preprocessor">#include <stdio.h></span>
+<a name="l00032"></a>00032 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00034"></a>00034 <span class="preprocessor">#include "sinfo_focus_cfg.h"</span>
+<a name="l00035"></a>00035 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00036"></a>00036 <span class="comment">                             Function prototypes </span>
+<a name="l00037"></a>00037 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00038"></a>00038 
+<a name="l00045"></a>00045 <span class="keywordtype">void</span> 
+<a name="l00046"></a>00046 sinfo_free_focus(focus_config * cfg);
+<a name="l00047"></a>00047 
+<a name="l00060"></a>00060 focus_config * 
+<a name="l00061"></a>00061 sinfo_parse_cpl_input_focus(cpl_parameterlist * cpl_cfg, 
+<a name="l00062"></a>00062                             cpl_frameset* sof, 
+<a name="l00063"></a>00063                             cpl_frameset** stk) ;
+<a name="l00064"></a>00064 
+<a name="l00065"></a>00065 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__function__1d_8c_source.html b/html/sinfo__function__1d_8c_source.html
new file mode 100644
index 0000000..f6a1ebd
--- /dev/null
+++ b/html/sinfo__function__1d_8c_source.html
@@ -0,0 +1,724 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_function_1d.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_function_1d.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name     :    function_1d.c</span>
+<a name="l00022"></a>00022 <span class="comment">   Author         :    Nicolas Devillard</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on    :    Tue, Sept 23 1997    </span>
+<a name="l00024"></a>00024 <span class="comment">   Description    :    1d signal processing related routines    </span>
+<a name="l00025"></a>00025 <span class="comment"></span>
+<a name="l00026"></a>00026 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00027"></a>00027 <span class="comment">/*</span>
+<a name="l00028"></a>00028 <span class="comment"> $Id: sinfo_function_1d.c,v 1.7 2012/03/02 08:42:20 amodigli Exp $</span>
+<a name="l00029"></a>00029 <span class="comment"> $Author: amodigli $</span>
+<a name="l00030"></a>00030 <span class="comment"> $Date: 2012/03/02 08:42:20 $</span>
+<a name="l00031"></a>00031 <span class="comment"> $Revision: 1.7 $</span>
+<a name="l00032"></a>00032 <span class="comment"> */</span>
+<a name="l00033"></a>00033 
+<a name="l00034"></a>00034 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00035"></a>00035 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00036"></a>00036 <span class="preprocessor">#endif</span>
+<a name="l00037"></a>00037 <span class="preprocessor"></span><span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00038"></a>00038 <span class="comment">                                   Includes</span>
+<a name="l00039"></a>00039 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include <math.h></span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include <string.h></span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include "sinfo_function_1d.h"</span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include "sinfo_fit_curve.h"</span>
+<a name="l00044"></a>00044 <span class="preprocessor">#include "sinfo_median.h"</span>
+<a name="l00045"></a>00045 
+<a name="l00054"></a>00054 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00055"></a>00055 <span class="comment">                                   Defines</span>
+<a name="l00056"></a>00056 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00057"></a>00057 <span class="comment">/*</span>
+<a name="l00058"></a>00058 <span class="comment"> * This parameter sets up the half size of the domain around which a</span>
+<a name="l00059"></a>00059 <span class="comment"> * centroid position will be computed.</span>
+<a name="l00060"></a>00060 <span class="comment"> */</span>
+<a name="l00061"></a>00061 <span class="preprocessor">#define HALF_CENTROID_DOMAIN    5</span>
+<a name="l00062"></a>00062 <span class="preprocessor"></span><span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00063"></a>00063 <span class="comment">                        Private function prototypes</span>
+<a name="l00064"></a>00064 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00065"></a>00065 <span class="keyword">static</span> <span class="keywordtype">double</span> * function1d_generate_smooth_kernel(<span class="keywordtype">int</span> filt_type, <span class="keywordtype">int</span> hw);
+<a name="l00066"></a>00066 
+<a name="l00067"></a>00067 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00068"></a>00068 function1d_search_value(
+<a name="l00069"></a>00069     pixelvalue  *   x,
+<a name="l00070"></a>00070     <span class="keywordtype">int</span>             len,
+<a name="l00071"></a>00071     pixelvalue      key,
+<a name="l00072"></a>00072     <span class="keywordtype">int</span>         *   foundPtr
+<a name="l00073"></a>00073 ) ;
+<a name="l00074"></a>00074 
+<a name="l00075"></a>00075 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00076"></a>00076 <span class="comment">                              Function codes</span>
+<a name="l00077"></a>00077 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00094"></a>00094 pixelvalue *
+<a name="l00095"></a>00095 sinfo_function1d_new(<span class="keywordtype">int</span> nsamples)
+<a name="l00096"></a>00096 {
+<a name="l00097"></a>00097     <span class="keywordflow">if</span> (nsamples<1) <span class="keywordflow">return</span> NULL ;
+<a name="l00098"></a>00098     <span class="keywordflow">return</span> cpl_calloc(nsamples, <span class="keyword">sizeof</span>(pixelvalue)) ;
+<a name="l00099"></a>00099 }
+<a name="l00100"></a>00100 
+<a name="l00101"></a>00101 
+<a name="l00111"></a>00111 <span class="keywordtype">void</span> 
+<a name="l00112"></a>00112 sinfo_function1d_del(pixelvalue * s)
+<a name="l00113"></a>00113 {
+<a name="l00114"></a>00114     <span class="keywordflow">if</span> (s)
+<a name="l00115"></a>00115         cpl_free(s);
+<a name="l00116"></a>00116     return ;
+<a name="l00117"></a>00117 }
+<a name="l00118"></a>00118 
+<a name="l00135"></a>00135 pixelvalue * 
+<a name="l00136"></a>00136 sinfo_function1d_dup(pixelvalue * arr, <span class="keywordtype">int</span> ns)
+<a name="l00137"></a>00137 {
+<a name="l00138"></a>00138     pixelvalue    *    n_arr ;
+<a name="l00139"></a>00139 
+<a name="l00140"></a>00140     n_arr = sinfo_function1d_new(ns);
+<a name="l00141"></a>00141     memcpy(n_arr, arr, ns * <span class="keyword">sizeof</span>(pixelvalue));
+<a name="l00142"></a>00142     <span class="keywordflow">return</span> n_arr ;
+<a name="l00143"></a>00143 }
+<a name="l00144"></a>00144 
+<a name="l00160"></a>00160 <span class="keywordtype">double</span>
+<a name="l00161"></a>00161 sinfo_function1d_find_centroid(
+<a name="l00162"></a>00162     pixelvalue    *    line,    <span class="comment">/*    the input line    */</span>
+<a name="l00163"></a>00163     <span class="keywordtype">int</span>    npix    <span class="comment">/*     number of pixels in this line    */</span>
+<a name="l00164"></a>00164 )
+<a name="l00165"></a>00165 {
+<a name="l00166"></a>00166     pixelvalue    max ;
+<a name="l00167"></a>00167     <span class="keywordtype">double</span>        centroid ;
+<a name="l00168"></a>00168     <span class="keywordtype">double</span>        weights ;
+<a name="l00169"></a>00169     <span class="keywordtype">int</span>            i, maxpos ;
+<a name="l00170"></a>00170 
+<a name="l00171"></a>00171     <span class="comment">/*</span>
+<a name="l00172"></a>00172 <span class="comment">     * Search for the maximum pixel value on the line</span>
+<a name="l00173"></a>00173 <span class="comment">     */</span>
+<a name="l00174"></a>00174 
+<a name="l00175"></a>00175     max = line[0] ;
+<a name="l00176"></a>00176     maxpos = 0 ;
+<a name="l00177"></a>00177     <span class="keywordflow">for</span> (i=1 ; i<npix ; i++) {
+<a name="l00178"></a>00178         <span class="keywordflow">if</span> (line[i]>max) {
+<a name="l00179"></a>00179             max = line[i] ;
+<a name="l00180"></a>00180             maxpos = i ;
+<a name="l00181"></a>00181         }
+<a name="l00182"></a>00182     }
+<a name="l00183"></a>00183 
+<a name="l00184"></a>00184     <span class="comment">/*</span>
+<a name="l00185"></a>00185 <span class="comment">     * The centroid position is the weighted average over the maximum </span>
+<a name="l00186"></a>00186 <span class="comment">     * pixel neighborhood.</span>
+<a name="l00187"></a>00187 <span class="comment">     */</span>
+<a name="l00188"></a>00188 
+<a name="l00189"></a>00189     centroid = 0.0 ;
+<a name="l00190"></a>00190     weights  = 0.0 ;
+<a name="l00191"></a>00191     <span class="keywordflow">for</span> (i=maxpos-HALF_CENTROID_DOMAIN; 
+<a name="l00192"></a>00192             i<=maxpos+HALF_CENTROID_DOMAIN; i++) {
+<a name="l00193"></a>00193         centroid += (double)line[i] * (<span class="keywordtype">double</span>)i ;
+<a name="l00194"></a>00194         weights  += (double)line[i] ;
+<a name="l00195"></a>00195     }
+<a name="l00196"></a>00196 
+<a name="l00197"></a>00197     centroid /= weights ;
+<a name="l00198"></a>00198     <span class="keywordflow">return</span> centroid ;    
+<a name="l00199"></a>00199 }
+<a name="l00200"></a>00200 
+<a name="l00223"></a>00223 <span class="keywordtype">double</span>
+<a name="l00224"></a>00224 sinfo_function1d_find_locmax(
+<a name="l00225"></a>00225     pixelvalue    *    line,
+<a name="l00226"></a>00226     <span class="keywordtype">int</span>                npix,
+<a name="l00227"></a>00227     <span class="keywordtype">int</span>                where,
+<a name="l00228"></a>00228     <span class="keywordtype">int</span>                hs
+<a name="l00229"></a>00229 )
+<a name="l00230"></a>00230 {
+<a name="l00231"></a>00231     pixelvalue    max ;
+<a name="l00232"></a>00232     <span class="keywordtype">double</span>        centroid ;
+<a name="l00233"></a>00233     <span class="keywordtype">double</span>        weights ;
+<a name="l00234"></a>00234     <span class="keywordtype">int</span>            i, maxpos ;
+<a name="l00235"></a>00235 
+<a name="l00236"></a>00236 
+<a name="l00237"></a>00237     <span class="keywordflow">if</span> ((where<hs) || (where>(npix-hs-1))) {
+<a name="l00238"></a>00238         <span class="keywordflow">return</span> (<span class="keywordtype">double</span>)-1.0 ;
+<a name="l00239"></a>00239     }
+<a name="l00240"></a>00240     
+<a name="l00241"></a>00241     <span class="comment">/*</span>
+<a name="l00242"></a>00242 <span class="comment">     * Search for the closest local maximal around the requested range.</span>
+<a name="l00243"></a>00243 <span class="comment">     */</span>
+<a name="l00244"></a>00244     max = line[where] ;
+<a name="l00245"></a>00245     maxpos = where ;
+<a name="l00246"></a>00246     <span class="keywordflow">for</span> (i=-hs ; i<=hs ; i++) {
+<a name="l00247"></a>00247         <span class="keywordflow">if</span> (line[where+i]>max) {
+<a name="l00248"></a>00248             max = line[where+i] ;
+<a name="l00249"></a>00249             maxpos = where+i ;
+<a name="l00250"></a>00250         }
+<a name="l00251"></a>00251     }
+<a name="l00252"></a>00252 
+<a name="l00253"></a>00253     <span class="comment">/*</span>
+<a name="l00254"></a>00254 <span class="comment">     * The centroid position is the weighted average over the maximum </span>
+<a name="l00255"></a>00255 <span class="comment">     * pixel neighborhood.</span>
+<a name="l00256"></a>00256 <span class="comment">     */</span>
+<a name="l00257"></a>00257 
+<a name="l00258"></a>00258     centroid = 0.0 ;
+<a name="l00259"></a>00259     weights  = 0.0 ;
+<a name="l00260"></a>00260     <span class="keywordflow">for</span> (i=maxpos-hs; i<=maxpos+hs; i++) {
+<a name="l00261"></a>00261         centroid += (double)line[i] * (<span class="keywordtype">double</span>)i ;
+<a name="l00262"></a>00262         weights  += (double)line[i] ;
+<a name="l00263"></a>00263     }
+<a name="l00264"></a>00264     <span class="keywordflow">if</span> (fabs(weights)>1e-6) {
+<a name="l00265"></a>00265         centroid /= weights ;
+<a name="l00266"></a>00266     } <span class="keywordflow">else</span> {
+<a name="l00267"></a>00267         centroid = -1.0 ;
+<a name="l00268"></a>00268     }
+<a name="l00269"></a>00269     <span class="keywordflow">return</span> centroid ;    
+<a name="l00270"></a>00270 }
+<a name="l00271"></a>00271 
+<a name="l00296"></a>00296 pixelvalue *
+<a name="l00297"></a>00297 sinfo_function1d_filter_lowpass(
+<a name="l00298"></a>00298     pixelvalue    *    input_sig,
+<a name="l00299"></a>00299     <span class="keywordtype">int</span>                samples,
+<a name="l00300"></a>00300     <span class="keywordtype">int</span>                filter_type,
+<a name="l00301"></a>00301     <span class="keywordtype">int</span>                hw
+<a name="l00302"></a>00302 )
+<a name="l00303"></a>00303 {
+<a name="l00304"></a>00304     pixelvalue    *    out_sig ;
+<a name="l00305"></a>00305     <span class="keywordtype">int</span>                i, j ;
+<a name="l00306"></a>00306     <span class="keywordtype">double</span>            replace ;
+<a name="l00307"></a>00307     <span class="keywordtype">double</span>        *    kernel ;
+<a name="l00308"></a>00308 
+<a name="l00309"></a>00309     <span class="comment">/* allocate output signal */</span>
+<a name="l00310"></a>00310     out_sig = sinfo_function1d_new(samples);
+<a name="l00311"></a>00311 
+<a name="l00312"></a>00312     <span class="comment">/* generate low-pass filter kernel */</span>
+<a name="l00313"></a>00313     kernel = function1d_generate_smooth_kernel(filter_type, hw) ;
+<a name="l00314"></a>00314 
+<a name="l00315"></a>00315     <span class="comment">/* compute sinfo_edge effects for the first hw elements */</span>
+<a name="l00316"></a>00316     <span class="keywordflow">for</span> (i=0 ; i<hw ; i++) {
+<a name="l00317"></a>00317         replace = 0.0 ;
+<a name="l00318"></a>00318         <span class="keywordflow">for</span> (j=-hw ; j<=hw ; j++) {
+<a name="l00319"></a>00319             <span class="keywordflow">if</span> (i+j<0) {
+<a name="l00320"></a>00320                 replace += kernel[hw+j] * (double)input_sig[0] ;
+<a name="l00321"></a>00321             } <span class="keywordflow">else</span> {
+<a name="l00322"></a>00322                 replace += kernel[hw+j] * (double)input_sig[i+j] ;
+<a name="l00323"></a>00323             }
+<a name="l00324"></a>00324         }
+<a name="l00325"></a>00325         out_sig[i] = (pixelvalue)replace ;
+<a name="l00326"></a>00326     }
+<a name="l00327"></a>00327 
+<a name="l00328"></a>00328     <span class="comment">/* compute sinfo_edge effects for the last hw elements */</span>
+<a name="l00329"></a>00329     <span class="keywordflow">for</span> (i=samples-hw ; i<samples ; i++) {
+<a name="l00330"></a>00330         replace = 0.0 ;
+<a name="l00331"></a>00331         <span class="keywordflow">for</span> (j=-hw ; j<=hw ; j++) {
+<a name="l00332"></a>00332             <span class="keywordflow">if</span> (i+j>samples-1) {
+<a name="l00333"></a>00333                 replace += kernel[hw+j] * (double)input_sig[samples-1] ;
+<a name="l00334"></a>00334             } <span class="keywordflow">else</span> {
+<a name="l00335"></a>00335                 replace += kernel[hw+j] * (double)input_sig[i+j] ;
+<a name="l00336"></a>00336             }
+<a name="l00337"></a>00337         }
+<a name="l00338"></a>00338         out_sig[i] = (pixelvalue)replace ;
+<a name="l00339"></a>00339     }
+<a name="l00340"></a>00340 
+<a name="l00341"></a>00341     <span class="comment">/* compute all other elements */</span>
+<a name="l00342"></a>00342     <span class="keywordflow">for</span> (i=hw ; i<samples-hw ; i++) {
+<a name="l00343"></a>00343         replace = 0.0 ;
+<a name="l00344"></a>00344         <span class="keywordflow">for</span> (j=-hw ; j<=hw ; j++) {
+<a name="l00345"></a>00345             replace += kernel[hw+j] * (double)input_sig[i+j] ;
+<a name="l00346"></a>00346         }
+<a name="l00347"></a>00347         out_sig[i] = (pixelvalue)replace ;
+<a name="l00348"></a>00348     }
+<a name="l00349"></a>00349 
+<a name="l00350"></a>00350     cpl_free(kernel) ;
+<a name="l00351"></a>00351     <span class="keywordflow">return</span> out_sig ;
+<a name="l00352"></a>00352 
+<a name="l00353"></a>00353 }
+<a name="l00354"></a>00354 
+<a name="l00371"></a>00371 <span class="keyword">static</span> <span class="keywordtype">double</span> * 
+<a name="l00372"></a>00372 function1d_generate_smooth_kernel(<span class="keywordtype">int</span> filt_type, <span class="keywordtype">int</span> hw)
+<a name="l00373"></a>00373 {
+<a name="l00374"></a>00374     <span class="keywordtype">double</span>  *   kernel ;
+<a name="l00375"></a>00375     <span class="keywordtype">double</span>      norm ;
+<a name="l00376"></a>00376     <span class="keywordtype">int</span>         i ;
+<a name="l00377"></a>00377 
+<a name="l00378"></a>00378     kernel = (<span class="keywordtype">double</span>*)cpl_calloc(2*hw+1, <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>)) ;
+<a name="l00379"></a>00379 
+<a name="l00380"></a>00380     <span class="keywordflow">switch</span>(filt_type) {
+<a name="l00381"></a>00381 
+<a name="l00382"></a>00382         <span class="keywordflow">case</span> LOW_PASS_LINEAR:
+<a name="l00383"></a>00383         <span class="keywordflow">for</span> (i=-hw ; i<=hw ; i++) {
+<a name="l00384"></a>00384             <span class="comment">/* flat kernel */</span>
+<a name="l00385"></a>00385             kernel[hw+i] = 1.0 / (double)(2*hw+1) ;
+<a name="l00386"></a>00386         }
+<a name="l00387"></a>00387         break ;
+<a name="l00388"></a>00388 
+<a name="l00389"></a>00389         <span class="keywordflow">case</span> LOW_PASS_GAUSSIAN:
+<a name="l00390"></a>00390         norm = 0.00 ;
+<a name="l00391"></a>00391         <span class="keywordflow">for</span> (i=-hw ; i<=hw ; i++) {
+<a name="l00392"></a>00392             <span class="comment">/* sinfo_gaussian kernel */</span>
+<a name="l00393"></a>00393             kernel[hw+i] = exp(-(<span class="keywordtype">double</span>)(i*i)) ;
+<a name="l00394"></a>00394             norm += kernel[hw+i] ;
+<a name="l00395"></a>00395         }
+<a name="l00396"></a>00396         <span class="keywordflow">for</span> (i=0 ; i<2*hw+1 ; i++) {
+<a name="l00397"></a>00397             kernel[i] /= norm ;
+<a name="l00398"></a>00398         }
+<a name="l00399"></a>00399         break ;
+<a name="l00400"></a>00400 
+<a name="l00401"></a>00401         <span class="keywordflow">default</span>:
+<a name="l00402"></a>00402         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"unrecognized low pass filter: "</span>
+<a name="l00403"></a>00403                                 <span class="stringliteral">"cannot generate kernel"</span>) ;
+<a name="l00404"></a>00404         <span class="keywordflow">return</span> (<span class="keywordtype">double</span>*)NULL ;
+<a name="l00405"></a>00405         break ;
+<a name="l00406"></a>00406     }
+<a name="l00407"></a>00407 
+<a name="l00408"></a>00408     <span class="keywordflow">return</span> kernel ;
+<a name="l00409"></a>00409 }
+<a name="l00410"></a>00410 
+<a name="l00429"></a>00429 pixelvalue * 
+<a name="l00430"></a>00430 sinfo_function1d_median_smooth(
+<a name="l00431"></a>00431     pixelvalue * list,
+<a name="l00432"></a>00432     <span class="keywordtype">int</span>          np,
+<a name="l00433"></a>00433     <span class="keywordtype">int</span>             hw)
+<a name="l00434"></a>00434 {
+<a name="l00435"></a>00435     <span class="keywordtype">int</span>             i,j ;
+<a name="l00436"></a>00436     pixelvalue    *    row ;
+<a name="l00437"></a>00437     pixelvalue    *     smoothed ;
+<a name="l00438"></a>00438 
+<a name="l00439"></a>00439     <span class="comment">/* simply copy first 3 and last 3 items */</span>
+<a name="l00440"></a>00440     smoothed = sinfo_function1d_new(np);
+<a name="l00441"></a>00441     <span class="keywordflow">for</span> (i=0 ; i<hw ; i++) {
+<a name="l00442"></a>00442         smoothed[i] = list[i] ;
+<a name="l00443"></a>00443     }
+<a name="l00444"></a>00444     <span class="keywordflow">for</span> (i=np-hw ; i<np ; i++) {
+<a name="l00445"></a>00445         smoothed[i] = list[i] ;
+<a name="l00446"></a>00446     }
+<a name="l00447"></a>00447 
+<a name="l00448"></a>00448     <span class="comment">/* sinfo_median filter on all central items */</span>
+<a name="l00449"></a>00449     row = sinfo_function1d_new(2*hw+1);
+<a name="l00450"></a>00450     <span class="keywordflow">for</span> (i=hw ; i<np-hw ; i++) {
+<a name="l00451"></a>00451         <span class="keywordflow">for</span> (j=-hw ; j<=hw ; j++) {
+<a name="l00452"></a>00452             row[j+hw] = list[i+j] ;
+<a name="l00453"></a>00453         }
+<a name="l00454"></a>00454         smoothed[i] = sinfo_median_pixelvalue(row, 2*hw+1) ; 
+<a name="l00455"></a>00455     }
+<a name="l00456"></a>00456     sinfo_function1d_del(row) ;
+<a name="l00457"></a>00457     <span class="keywordflow">return</span> smoothed ;
+<a name="l00458"></a>00458 }
+<a name="l00459"></a>00459 
+<a name="l00476"></a>00476 <span class="preprocessor">#define LOWFREQ_PASSES        5</span>
+<a name="l00477"></a>00477 <span class="preprocessor"></span>
+<a name="l00478"></a>00478 pixelvalue * 
+<a name="l00479"></a>00479 sinfo_function1d_remove_lowfreq(
+<a name="l00480"></a>00480     pixelvalue * pixel_signal,
+<a name="l00481"></a>00481     <span class="keywordtype">int</span>             ns)
+<a name="l00482"></a>00482 {
+<a name="l00483"></a>00483     pixelvalue    *    sig_in ;
+<a name="l00484"></a>00484     pixelvalue    *    smooth ;
+<a name="l00485"></a>00485     <span class="keywordtype">int</span>                i ;
+<a name="l00486"></a>00486     
+<a name="l00487"></a>00487     
+<a name="l00488"></a>00488     <span class="comment">/* Apply severe low-pass filter several times */</span>
+<a name="l00489"></a>00489     sig_in = sinfo_function1d_dup(pixel_signal, ns);
+<a name="l00490"></a>00490     <span class="keywordflow">for</span> (i=0 ; i<LOWFREQ_PASSES ; i++) {
+<a name="l00491"></a>00491         smooth = sinfo_function1d_filter_lowpass( sig_in, ns, 
+<a name="l00492"></a>00492                          LOW_PASS_LINEAR, 5);
+<a name="l00493"></a>00493         cpl_free(sig_in);
+<a name="l00494"></a>00494         sig_in = smooth ;
+<a name="l00495"></a>00495     }
+<a name="l00496"></a>00496 
+<a name="l00497"></a>00497     <span class="comment">/* Subtract smoothed signal from input signal */</span>
+<a name="l00498"></a>00498     <span class="keywordflow">for</span> (i=0 ; i<ns ; i++) {
+<a name="l00499"></a>00499         smooth[i] = pixel_signal[i] - smooth[i];
+<a name="l00500"></a>00500     }
+<a name="l00501"></a>00501     <span class="keywordflow">return</span> smooth ;
+<a name="l00502"></a>00502 }
+<a name="l00503"></a>00503 
+<a name="l00504"></a>00504 <span class="preprocessor">#undef LOWFREQ_PASSES</span>
+<a name="l00505"></a>00505 <span class="preprocessor"></span>
+<a name="l00527"></a>00527 <span class="preprocessor">#define SAMPLE_BORDER    10</span>
+<a name="l00528"></a>00528 <span class="preprocessor"></span>
+<a name="l00529"></a>00529 pixelvalue * 
+<a name="l00530"></a>00530 sinfo_function1d_remove_thermalbg(
+<a name="l00531"></a>00531     pixelvalue * pixel_signal,
+<a name="l00532"></a>00532     <span class="keywordtype">int</span>             ns)
+<a name="l00533"></a>00533 {
+<a name="l00534"></a>00534     pixelvalue    *    smooth ;
+<a name="l00535"></a>00535     <span class="keywordtype">int</span>                i ;
+<a name="l00536"></a>00536     
+<a name="l00537"></a>00537     <span class="keywordtype">int</span>                nmin ;
+<a name="l00538"></a>00538     pixelvalue        lef[2], rig[2];
+<a name="l00539"></a>00539 
+<a name="l00540"></a>00540     pixelvalue    *    x,
+<a name="l00541"></a>00541                 *    y,
+<a name="l00542"></a>00542                 *    spl_x,
+<a name="l00543"></a>00543                 *    spl_y ;
+<a name="l00544"></a>00544     <span class="keywordtype">double</span>            med_y ;
+<a name="l00545"></a>00545     <span class="keywordtype">double</span>            avg2med ;
+<a name="l00546"></a>00546     <span class="keywordtype">double</span>            dist ;
+<a name="l00547"></a>00547 
+<a name="l00548"></a>00548     
+<a name="l00549"></a>00549     <span class="comment">/* Detect all local minima */</span>
+<a name="l00550"></a>00550     nmin = 0 ;
+<a name="l00551"></a>00551     x = sinfo_function1d_new(ns);
+<a name="l00552"></a>00552     y = sinfo_function1d_new(ns);
+<a name="l00553"></a>00553 
+<a name="l00554"></a>00554     <span class="keywordflow">for</span> (i=SAMPLE_BORDER ; i<(ns-SAMPLE_BORDER) ; i++) {
+<a name="l00555"></a>00555         lef[0] = pixel_signal[i-2];
+<a name="l00556"></a>00556         lef[1] = pixel_signal[i-1];
+<a name="l00557"></a>00557         rig[0] = pixel_signal[i+1];
+<a name="l00558"></a>00558         rig[1] = pixel_signal[i+2];
+<a name="l00559"></a>00559 
+<a name="l00560"></a>00560         <span class="keywordflow">if</span> ( (pixel_signal[i] < lef[0]) &&
+<a name="l00561"></a>00561              (pixel_signal[i] < lef[1]) &&
+<a name="l00562"></a>00562              (pixel_signal[i] < rig[0]) &&
+<a name="l00563"></a>00563              (pixel_signal[i] < rig[1])) {
+<a name="l00564"></a>00564             x[nmin] = (pixelvalue)i ;
+<a name="l00565"></a>00565             y[nmin] = pixel_signal[i];
+<a name="l00566"></a>00566             nmin ++ ;
+<a name="l00567"></a>00567         }
+<a name="l00568"></a>00568     }
+<a name="l00569"></a>00569 
+<a name="l00570"></a>00570 
+<a name="l00571"></a>00571     <span class="comment">/* Interpolate linearly missing values */</span>
+<a name="l00572"></a>00572     spl_x = sinfo_function1d_new(ns);
+<a name="l00573"></a>00573     spl_y = sinfo_function1d_new(ns);
+<a name="l00574"></a>00574     <span class="keywordflow">for</span> (i=0 ; i<ns ; i++) {
+<a name="l00575"></a>00575         spl_x[i] = (pixelvalue)i ;
+<a name="l00576"></a>00576     }
+<a name="l00577"></a>00577     sinfo_function1d_interpolate_linear(x, y, nmin, spl_x, spl_y, ns);
+<a name="l00578"></a>00578 
+<a name="l00579"></a>00579     sinfo_function1d_del(x) ;
+<a name="l00580"></a>00580     sinfo_function1d_del(y) ;
+<a name="l00581"></a>00581     sinfo_function1d_del(spl_x);
+<a name="l00582"></a>00582 
+<a name="l00583"></a>00583     <span class="comment">/* Compute sinfo_median and average distance to the sinfo_median */</span>
+<a name="l00584"></a>00584     med_y = (double)sinfo_median_pixelvalue(pixel_signal, ns);
+<a name="l00585"></a>00585     avg2med = 0.0 ;
+<a name="l00586"></a>00586     <span class="keywordflow">for</span> (i=0 ; i<ns ; i++) {
+<a name="l00587"></a>00587         avg2med += fabs((<span class="keywordtype">double</span>)pixel_signal[i] - med_y) ;
+<a name="l00588"></a>00588     }
+<a name="l00589"></a>00589     avg2med /= (double)ns ;
+<a name="l00590"></a>00590 
+<a name="l00591"></a>00591     <span class="comment">/* Reset all pixels out of sinfo_median + 2 * avg2med to zero. */</span>
+<a name="l00592"></a>00592     <span class="keywordflow">for</span> (i=0 ; i<ns ; i++) {
+<a name="l00593"></a>00593         dist = fabs((<span class="keywordtype">double</span>)pixel_signal[i] - med_y);
+<a name="l00594"></a>00594         <span class="keywordflow">if</span> (dist > (2.0*avg2med)) {
+<a name="l00595"></a>00595             spl_y[i] = (pixelvalue)0 ;
+<a name="l00596"></a>00596         }
+<a name="l00597"></a>00597     }
+<a name="l00598"></a>00598 
+<a name="l00599"></a>00599 
+<a name="l00600"></a>00600     smooth = sinfo_function1d_new(ns);
+<a name="l00601"></a>00601     <span class="keywordflow">for</span> (i=0 ; i<ns ; i++) {
+<a name="l00602"></a>00602         <span class="keywordflow">if</span> (spl_y[i]>1e-4) {
+<a name="l00603"></a>00603             smooth[i] = pixel_signal[i] - spl_y[i];
+<a name="l00604"></a>00604         } <span class="keywordflow">else</span> {
+<a name="l00605"></a>00605             smooth[i] = 0.0 ;
+<a name="l00606"></a>00606         }
+<a name="l00607"></a>00607     }
+<a name="l00608"></a>00608     sinfo_function1d_del(spl_y);
+<a name="l00609"></a>00609     <span class="keywordflow">return</span> smooth ;
+<a name="l00610"></a>00610 }
+<a name="l00611"></a>00611 
+<a name="l00612"></a>00612 <span class="preprocessor">#undef LOWFREQ_PASSES</span>
+<a name="l00613"></a>00613 <span class="preprocessor"></span>
+<a name="l00635"></a>00635 <span class="keywordtype">void</span> 
+<a name="l00636"></a>00636 sinfo_function1d_interpolate_linear(
+<a name="l00637"></a>00637     pixelvalue    *    x,
+<a name="l00638"></a>00638     pixelvalue    *    y,
+<a name="l00639"></a>00639     <span class="keywordtype">int</span>                len,
+<a name="l00640"></a>00640     pixelvalue    *    spl_x,
+<a name="l00641"></a>00641     pixelvalue    *    spl_y,
+<a name="l00642"></a>00642     <span class="keywordtype">int</span>                spl_len
+<a name="l00643"></a>00643 )
+<a name="l00644"></a>00644 {
+<a name="l00645"></a>00645     <span class="keywordtype">double</span>        a, b ;
+<a name="l00646"></a>00646     <span class="keywordtype">int</span>            i, j ;
+<a name="l00647"></a>00647     <span class="keywordtype">int</span>            found ;
+<a name="l00648"></a>00648 
+<a name="l00649"></a>00649     <span class="keywordflow">for</span> (i=0 ; i<spl_len ; i++) {
+<a name="l00650"></a>00650         <span class="comment">/* Find (x1,y1) on the left of the current point */</span>
+<a name="l00651"></a>00651         found = 0 ;
+<a name="l00652"></a>00652         <span class="keywordflow">for</span> (j=0 ; j<(len-1) ; j++) {
+<a name="l00653"></a>00653             <span class="keywordflow">if</span> ((spl_x[i]>=x[j]) && (spl_x[i]<=x[j+1])) {
+<a name="l00654"></a>00654                 found++ ;
+<a name="l00655"></a>00655                 break ;
+<a name="l00656"></a>00656             }
+<a name="l00657"></a>00657         }
+<a name="l00658"></a>00658         <span class="keywordflow">if</span> (!found) {
+<a name="l00659"></a>00659             spl_y[i] = 0.0;
+<a name="l00660"></a>00660         } <span class="keywordflow">else</span> {
+<a name="l00661"></a>00661             a = ((double)y[j+1]-(<span class="keywordtype">double</span>)y[j]) /
+<a name="l00662"></a>00662                 ((<span class="keywordtype">double</span>)x[j+1]-(double)x[j]);
+<a name="l00663"></a>00663             b = (double)y[j] - a * (<span class="keywordtype">double</span>)x[j] ;
+<a name="l00664"></a>00664             spl_y[i] = (pixelvalue)(a * (<span class="keywordtype">double</span>)spl_x[i] + b) ;
+<a name="l00665"></a>00665         }
+<a name="l00666"></a>00666     }
+<a name="l00667"></a>00667     return ;
+<a name="l00668"></a>00668 }
+<a name="l00669"></a>00669 
+<a name="l00686"></a>00686 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00687"></a>00687 function1d_search_value(
+<a name="l00688"></a>00688     pixelvalue    *    x,
+<a name="l00689"></a>00689     <span class="keywordtype">int</span>             len,
+<a name="l00690"></a>00690     pixelvalue         key,
+<a name="l00691"></a>00691     <span class="keywordtype">int</span>         *    foundPtr
+<a name="l00692"></a>00692 )
+<a name="l00693"></a>00693 {
+<a name="l00694"></a>00694     <span class="keywordtype">int</span>    high,
+<a name="l00695"></a>00695         low,
+<a name="l00696"></a>00696         middle;
+<a name="l00697"></a>00697 
+<a name="l00698"></a>00698     low  = 0;
+<a name="l00699"></a>00699     high = len - 1;
+<a name="l00700"></a>00700 
+<a name="l00701"></a>00701     <span class="keywordflow">while</span> (high >= low) {
+<a name="l00702"></a>00702         middle = (high + low) / 2;
+<a name="l00703"></a>00703         <span class="keywordflow">if</span> (key > x[middle]) {
+<a name="l00704"></a>00704             low = middle + 1;
+<a name="l00705"></a>00705         } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (key < x[middle]) {
+<a name="l00706"></a>00706             high = middle - 1;
+<a name="l00707"></a>00707         } <span class="keywordflow">else</span> {
+<a name="l00708"></a>00708             *foundPtr = 1;
+<a name="l00709"></a>00709             <span class="keywordflow">return</span> (middle);
+<a name="l00710"></a>00710         }
+<a name="l00711"></a>00711     }
+<a name="l00712"></a>00712     *foundPtr = 0;
+<a name="l00713"></a>00713     <span class="keywordflow">return</span> (low);
+<a name="l00714"></a>00714 }
+<a name="l00715"></a>00715 
+<a name="l00741"></a>00741 <span class="keywordtype">int</span>
+<a name="l00742"></a>00742 sinfo_function1d_natural_spline(
+<a name="l00743"></a>00743     pixelvalue    *     x,
+<a name="l00744"></a>00744     pixelvalue    *     y,
+<a name="l00745"></a>00745     <span class="keywordtype">int</span>             len,
+<a name="l00746"></a>00746     pixelvalue    *     splX,
+<a name="l00747"></a>00747     pixelvalue    *     splY,
+<a name="l00748"></a>00748     <span class="keywordtype">int</span>             splLen
+<a name="l00749"></a>00749 )
+<a name="l00750"></a>00750 {
+<a name="l00751"></a>00751     <span class="keywordtype">int</span>             end;
+<a name="l00752"></a>00752     <span class="keywordtype">int</span>             loc,
+<a name="l00753"></a>00753                     found;
+<a name="l00754"></a>00754     <span class="keyword">register</span> <span class="keywordtype">int</span>     i,
+<a name="l00755"></a>00755                     j,
+<a name="l00756"></a>00756                     n;
+<a name="l00757"></a>00757     <span class="keywordtype">double</span>         *    h; <span class="comment">/* sinfo_vector of deltas in x */</span>
+<a name="l00758"></a>00758     <span class="keywordtype">double</span>         *    alpha;
+<a name="l00759"></a>00759     <span class="keywordtype">double</span>         *    l,
+<a name="l00760"></a>00760                 *    mu,
+<a name="l00761"></a>00761                 *    z,
+<a name="l00762"></a>00762                 *    a,
+<a name="l00763"></a>00763                 *    b,
+<a name="l00764"></a>00764                 *    c,
+<a name="l00765"></a>00765                 *    d,
+<a name="l00766"></a>00766                     v;
+<a name="l00767"></a>00767 
+<a name="l00768"></a>00768     end = len - 1;
+<a name="l00769"></a>00769 
+<a name="l00770"></a>00770     a = cpl_malloc(<span class="keyword">sizeof</span>(<span class="keywordtype">double</span>) * splLen * 9) ;
+<a name="l00771"></a>00771     b = a + len;
+<a name="l00772"></a>00772     c = b + len;
+<a name="l00773"></a>00773     d = c + len;
+<a name="l00774"></a>00774     h = d + len;
+<a name="l00775"></a>00775     l = h + len;
+<a name="l00776"></a>00776     z = l + len;
+<a name="l00777"></a>00777     mu = z + len;
+<a name="l00778"></a>00778     alpha = mu + len;
+<a name="l00779"></a>00779 
+<a name="l00780"></a>00780     <span class="keywordflow">for</span> (i = 0; i < len; i++) {
+<a name="l00781"></a>00781         a[i] = (double)y[i];
+<a name="l00782"></a>00782     }
+<a name="l00783"></a>00783 
+<a name="l00784"></a>00784     <span class="comment">/* Calculate sinfo_vector of differences */</span>
+<a name="l00785"></a>00785     <span class="keywordflow">for</span> (i = 0; i < end; i++) {
+<a name="l00786"></a>00786         h[i] = (double)x[i + 1] - (<span class="keywordtype">double</span>)x[i];
+<a name="l00787"></a>00787         <span class="keywordflow">if</span> (h[i] < 0.0) {
+<a name="l00788"></a>00788             cpl_free(a) ;
+<a name="l00789"></a>00789             <span class="keywordflow">return</span> -1;
+<a name="l00790"></a>00790         }
+<a name="l00791"></a>00791     }
+<a name="l00792"></a>00792 
+<a name="l00793"></a>00793     <span class="comment">/* Calculate alpha sinfo_vector */</span>
+<a name="l00794"></a>00794     <span class="keywordflow">for</span> (n = 0, i = 1; i < end; i++, n++) {
+<a name="l00795"></a>00795         <span class="comment">/* n = i - 1 */</span>
+<a name="l00796"></a>00796         alpha[i] = 3.0 * ((a[i+1] / h[i]) - (a[i] / h[n]) - (a[i] / h[i]) +
+<a name="l00797"></a>00797                   (a[n] / h[n]));
+<a name="l00798"></a>00798     }
+<a name="l00799"></a>00799 
+<a name="l00800"></a>00800     <span class="comment">/* Vectors to solve the tridiagonal sinfo_matrix */</span>
+<a name="l00801"></a>00801     l[0] = l[end] = 1.0;
+<a name="l00802"></a>00802     mu[0] = mu[end] = 0.0;
+<a name="l00803"></a>00803     z[0] = z[end] = 0.0;
+<a name="l00804"></a>00804     c[0] = c[end] = 0.0;
+<a name="l00805"></a>00805 
+<a name="l00806"></a>00806     <span class="comment">/* Calculate the intermediate results */</span>
+<a name="l00807"></a>00807     <span class="keywordflow">for</span> (n = 0, i = 1; i < end; i++, n++) {
+<a name="l00808"></a>00808         <span class="comment">/* n = i-1 */</span>
+<a name="l00809"></a>00809         l[i] = 2 * (h[i] + h[n]) - h[n] * mu[n];
+<a name="l00810"></a>00810         mu[i] = h[i] / l[i];
+<a name="l00811"></a>00811         z[i] = (alpha[i] - h[n] * z[n]) / l[i];
+<a name="l00812"></a>00812     }
+<a name="l00813"></a>00813     <span class="keywordflow">for</span> (n = end, j = end - 1; j >= 0; j--, n--) {
+<a name="l00814"></a>00814         <span class="comment">/* n = j + 1 */</span>
+<a name="l00815"></a>00815         c[j] = z[j] - mu[j] * c[n];
+<a name="l00816"></a>00816         b[j] = (a[n] - a[j]) / h[j] - h[j] * (c[n] + 2.0 * c[j]) / 3.0;
+<a name="l00817"></a>00817         d[j] = (c[n] - c[j]) / (3.0 * h[j]);
+<a name="l00818"></a>00818     }
+<a name="l00819"></a>00819 
+<a name="l00820"></a>00820     <span class="comment">/* Now calculate the new values */</span>
+<a name="l00821"></a>00821     <span class="keywordflow">for</span> (j = 0; j < splLen; j++) {
+<a name="l00822"></a>00822          v = (double)splX[j];
+<a name="l00823"></a>00823      splY[j] = (pixelvalue)0;
+<a name="l00824"></a>00824 
+<a name="l00825"></a>00825      <span class="comment">/* Is it outside the interval? */</span>
+<a name="l00826"></a>00826      <span class="keywordflow">if</span> ((v < (<span class="keywordtype">double</span>)x[0]) || (v > (<span class="keywordtype">double</span>)x[end])) {
+<a name="l00827"></a>00827         <span class="keywordflow">continue</span>;
+<a name="l00828"></a>00828      }
+<a name="l00829"></a>00829      <span class="comment">/* Search for the interval containing v in the x sinfo_vector */</span>
+<a name="l00830"></a>00830      loc = function1d_search_value(x, len, (pixelvalue)v, &found);
+<a name="l00831"></a>00831      <span class="keywordflow">if</span> (found) {
+<a name="l00832"></a>00832         splY[j] = y[loc];
+<a name="l00833"></a>00833      } <span class="keywordflow">else</span> {
+<a name="l00834"></a>00834         loc--;
+<a name="l00835"></a>00835         v -= (double)x[loc];
+<a name="l00836"></a>00836         splY[j] = (pixelvalue)(    a[loc] +
+<a name="l00837"></a>00837                         v * (b[loc] +
+<a name="l00838"></a>00838                    v * (c[loc] +
+<a name="l00839"></a>00839                     v * d[loc])));
+<a name="l00840"></a>00840         }
+<a name="l00841"></a>00841     }
+<a name="l00842"></a>00842     cpl_free(a) ;
+<a name="l00843"></a>00843     <span class="keywordflow">return</span> 0;
+<a name="l00844"></a>00844 }
+<a name="l00845"></a>00845 
+<a name="l00864"></a>00864 pixelvalue
+<a name="l00865"></a>00865 sinfo_function1d_average_reject(
+<a name="l00866"></a>00866     pixelvalue    *    line,
+<a name="l00867"></a>00867     <span class="keywordtype">int</span>                npix,
+<a name="l00868"></a>00868     <span class="keywordtype">int</span>                pix_low,
+<a name="l00869"></a>00869     <span class="keywordtype">int</span>                pix_high)
+<a name="l00870"></a>00870 {
+<a name="l00871"></a>00871     pixelvalue    *    sorted ;
+<a name="l00872"></a>00872     <span class="keywordtype">int</span>                i ;
+<a name="l00873"></a>00873     <span class="keywordtype">double</span>            avg ;
+<a name="l00874"></a>00874 
+<a name="l00875"></a>00875     <span class="comment">/* Sanity tests */</span>
+<a name="l00876"></a>00876     <span class="keywordflow">if</span> ((line==NULL) || (npix<1)) <span class="keywordflow">return</span> (pixelvalue)0 ;
+<a name="l00877"></a>00877     <span class="keywordflow">if</span> ((pix_low+pix_high)>=npix) <span class="keywordflow">return</span> (pixelvalue)0 ;
+<a name="l00878"></a>00878 
+<a name="l00879"></a>00879     <span class="comment">/* Copy input line and sort it */</span>
+<a name="l00880"></a>00880     sorted = cpl_malloc(npix * <span class="keyword">sizeof</span>(pixelvalue)) ;
+<a name="l00881"></a>00881     memcpy(sorted, line, npix * <span class="keyword">sizeof</span>(pixelvalue)) ;
+<a name="l00882"></a>00882     sinfo_pixel_qsort(sorted, npix);
+<a name="l00883"></a>00883 
+<a name="l00884"></a>00884     <span class="comment">/* Find out average of remaining values */</span>
+<a name="l00885"></a>00885     avg = 0.00 ;
+<a name="l00886"></a>00886     <span class="keywordflow">for</span> (i=pix_low+1 ; i<(npix-pix_high) ; i++) {
+<a name="l00887"></a>00887         avg += (double)sorted[i] ;
+<a name="l00888"></a>00888     }
+<a name="l00889"></a>00889     cpl_free(sorted);
+<a name="l00890"></a>00890     avg /= (double)(npix - pix_high - pix_low) ;
+<a name="l00891"></a>00891 
+<a name="l00892"></a>00892     <span class="keywordflow">return</span> (pixelvalue)avg ;
+<a name="l00893"></a>00893 }
+<a name="l00894"></a>00894 
+<a name="l00920"></a>00920 <span class="preprocessor">#define STEP_MIN    (-half_search)</span>
+<a name="l00921"></a>00921 <span class="preprocessor"></span><span class="preprocessor">#define STEP_MAX    (half_search)</span>
+<a name="l00922"></a>00922 <span class="preprocessor"></span>
+<a name="l00923"></a>00923 <span class="keywordtype">double</span> 
+<a name="l00924"></a>00924 sinfo_function1d_xcorrelate(
+<a name="l00925"></a>00925     pixelvalue *    line_i,
+<a name="l00926"></a>00926     <span class="keywordtype">int</span>             width_i,
+<a name="l00927"></a>00927     pixelvalue *    line_t,
+<a name="l00928"></a>00928     <span class="keywordtype">int</span>             width_t,
+<a name="l00929"></a>00929     <span class="keywordtype">int</span>                half_search,
+<a name="l00930"></a>00930     <span class="keywordtype">double</span>     *    delta
+<a name="l00931"></a>00931 )
+<a name="l00932"></a>00932 {
+<a name="l00933"></a>00933     <span class="keywordtype">double</span> * xcorr ;
+<a name="l00934"></a>00934     <span class="keywordtype">double</span>   xcorr_max ;
+<a name="l00935"></a>00935     <span class="keywordtype">double</span>   mean_i, mean_t ;
+<a name="l00936"></a>00936     <span class="keywordtype">double</span>   rms_i, rms_t ;
+<a name="l00937"></a>00937     <span class="keywordtype">double</span>   sum, sqsum ;
+<a name="l00938"></a>00938     <span class="keywordtype">double</span>   norm ;
+<a name="l00939"></a>00939     <span class="keywordtype">int</span>      maxpos ;
+<a name="l00940"></a>00940     <span class="keywordtype">int</span>      nsteps ;
+<a name="l00941"></a>00941     <span class="keywordtype">int</span>      i ;
+<a name="l00942"></a>00942     <span class="keywordtype">int</span>      step ;
+<a name="l00943"></a>00943     <span class="keywordtype">int</span>      nval ;
+<a name="l00944"></a>00944 
+<a name="l00945"></a>00945 
+<a name="l00946"></a>00946     <span class="comment">/* Compute normalization factors */</span>
+<a name="l00947"></a>00947     sum = sqsum = 0.00 ;
+<a name="l00948"></a>00948     <span class="keywordflow">for</span> (i=0 ; i<width_i ; i++) {
+<a name="l00949"></a>00949         sum += (double)line_i[i] ;
+<a name="l00950"></a>00950         sqsum += (double)line_i[i] * (<span class="keywordtype">double</span>)line_i[i];
+<a name="l00951"></a>00951     }
+<a name="l00952"></a>00952     mean_i = sum / (double)width_i ;
+<a name="l00953"></a>00953     sqsum /= (double)width_i ;
+<a name="l00954"></a>00954     rms_i = sqsum - mean_i*mean_i ;
+<a name="l00955"></a>00955 
+<a name="l00956"></a>00956     sum = sqsum = 0.00 ;
+<a name="l00957"></a>00957     <span class="keywordflow">for</span> (i=0 ; i<width_t ; i++) {
+<a name="l00958"></a>00958         sum += (double)line_t[i] ;
+<a name="l00959"></a>00959         sqsum += (double)line_t[i] * (<span class="keywordtype">double</span>)line_t[i];
+<a name="l00960"></a>00960     }
+<a name="l00961"></a>00961     mean_t = sum / (double)width_t ;
+<a name="l00962"></a>00962     sqsum /= (double)width_t ;
+<a name="l00963"></a>00963     rms_t = sqsum - mean_t*mean_t ;
+<a name="l00964"></a>00964 
+<a name="l00965"></a>00965     norm = 1.00 / sqrt(rms_i * rms_t);
+<a name="l00966"></a>00966 
+<a name="l00967"></a>00967     nsteps = (STEP_MAX - STEP_MIN) +1 ;
+<a name="l00968"></a>00968     xcorr = cpl_malloc(nsteps * <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>));
+<a name="l00969"></a>00969     <span class="keywordflow">for</span> (step=STEP_MIN ; step<=STEP_MAX ; step++) {
+<a name="l00970"></a>00970         xcorr[step-STEP_MIN] = 0.00 ;
+<a name="l00971"></a>00971         nval = 0 ;
+<a name="l00972"></a>00972         <span class="keywordflow">for</span> (i=0 ; i<width_t ; i++) {
+<a name="l00973"></a>00973             <span class="keywordflow">if</span> ((i+step > 0) &&
+<a name="l00974"></a>00974                 (i+step < width_i)) {
+<a name="l00975"></a>00975             xcorr[step-STEP_MIN] += ((double)line_t[i] - mean_t) *
+<a name="l00976"></a>00976                                     ((double)line_i[i+step] - mean_i) *
+<a name="l00977"></a>00977                                     norm ;
+<a name="l00978"></a>00978                 nval++ ;
+<a name="l00979"></a>00979             }
+<a name="l00980"></a>00980         }
+<a name="l00981"></a>00981         xcorr[step-STEP_MIN] /= (double)nval ;
+<a name="l00982"></a>00982     }
+<a name="l00983"></a>00983     xcorr_max = xcorr[0] ;
+<a name="l00984"></a>00984     maxpos    = 0 ;
+<a name="l00985"></a>00985     <span class="keywordflow">for</span> (i=0 ; i<nsteps ; i++) {
+<a name="l00986"></a>00986         <span class="keywordflow">if</span> (xcorr[i]>xcorr_max) {
+<a name="l00987"></a>00987             maxpos = i ;
+<a name="l00988"></a>00988             xcorr_max = xcorr[i];
+<a name="l00989"></a>00989         }
+<a name="l00990"></a>00990     }
+<a name="l00991"></a>00991     cpl_free(xcorr);
+<a name="l00992"></a>00992     (*delta) = + ((double)STEP_MIN + (<span class="keywordtype">double</span>)maxpos);
+<a name="l00993"></a>00993     <span class="keywordflow">return</span> xcorr_max ;
+<a name="l00994"></a>00994 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__function__1d_8h_source.html b/html/sinfo__function__1d_8h_source.html
new file mode 100644
index 0000000..8d77537
--- /dev/null
+++ b/html/sinfo__function__1d_8h_source.html
@@ -0,0 +1,154 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_function_1d.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_function_1d.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name     :    sinfo_function_1d.h</span>
+<a name="l00022"></a>00022 <span class="comment">   Author         :    Nicolas Devillard</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on    :    Tue, Sept 23 1997    </span>
+<a name="l00024"></a>00024 <span class="comment">   Description    :    1d signal processing related routines    </span>
+<a name="l00025"></a>00025 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00026"></a>00026 <span class="comment">/*</span>
+<a name="l00027"></a>00027 <span class="comment"> $Id: sinfo_function_1d.h,v 1.6 2008/03/25 08:20:43 amodigli Exp $</span>
+<a name="l00028"></a>00028 <span class="comment"> $Author: amodigli $</span>
+<a name="l00029"></a>00029 <span class="comment"> $Date: 2008/03/25 08:20:43 $</span>
+<a name="l00030"></a>00030 <span class="comment"> $Revision: 1.6 $</span>
+<a name="l00031"></a>00031 <span class="comment"> */</span>
+<a name="l00032"></a>00032 <span class="preprocessor">#ifndef SINFO_FUNCTION_1D_H</span>
+<a name="l00033"></a>00033 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_FUNCTION_1D_H</span>
+<a name="l00034"></a>00034 <span class="preprocessor"></span><span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00035"></a>00035 <span class="comment">                                   Includes</span>
+<a name="l00036"></a>00036 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include <math.h></span>
+<a name="l00038"></a>00038 <span class="preprocessor">#include "sinfo_local_types.h"</span>
+<a name="l00039"></a>00039 <span class="preprocessor">#include "sinfo_pixel_handling.h"</span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00042"></a>00042 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00043"></a>00043 <span class="comment">                                   Defines</span>
+<a name="l00044"></a>00044 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00045"></a>00045 <span class="comment">/* Low pass filter types: */</span>
+<a name="l00046"></a>00046 
+<a name="l00047"></a>00047 <span class="preprocessor">#define LOW_PASS_LINEAR            100</span>
+<a name="l00048"></a>00048 <span class="preprocessor"></span><span class="preprocessor">#define LOW_PASS_GAUSSIAN        101</span>
+<a name="l00049"></a>00049 <span class="preprocessor"></span><span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00050"></a>00050 <span class="comment">                          Function ANSI C prototypes</span>
+<a name="l00051"></a>00051 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00067"></a>00067 pixelvalue * 
+<a name="l00068"></a>00068 sinfo_function1d_new(<span class="keywordtype">int</span> nsamples);
+<a name="l00069"></a>00069 
+<a name="l00079"></a>00079 <span class="keywordtype">void</span> 
+<a name="l00080"></a>00080 sinfo_function1d_del(pixelvalue * s);
+<a name="l00097"></a>00097 pixelvalue * 
+<a name="l00098"></a>00098 sinfo_function1d_dup(pixelvalue * arr, <span class="keywordtype">int</span> ns);
+<a name="l00099"></a>00099 
+<a name="l00116"></a>00116 <span class="keywordtype">double</span>
+<a name="l00117"></a>00117 sinfo_function1d_find_centroid(
+<a name="l00118"></a>00118     pixelvalue  *   line,   <span class="comment">/*  the input line                  */</span>
+<a name="l00119"></a>00119     <span class="keywordtype">int</span>             npix    <span class="comment">/*  number of pixels in this line   */</span>
+<a name="l00120"></a>00120 );
+<a name="l00121"></a>00121 
+<a name="l00144"></a>00144 <span class="keywordtype">double</span>
+<a name="l00145"></a>00145 sinfo_function1d_find_locmax(
+<a name="l00146"></a>00146     pixelvalue  *   line,
+<a name="l00147"></a>00147     <span class="keywordtype">int</span>             npix,
+<a name="l00148"></a>00148     <span class="keywordtype">int</span>             where,
+<a name="l00149"></a>00149     <span class="keywordtype">int</span>             hs
+<a name="l00150"></a>00150 ) ;
+<a name="l00151"></a>00151 
+<a name="l00152"></a>00152 
+<a name="l00177"></a>00177 pixelvalue *
+<a name="l00178"></a>00178 sinfo_function1d_filter_lowpass(
+<a name="l00179"></a>00179     pixelvalue  *   input_sig,
+<a name="l00180"></a>00180     <span class="keywordtype">int</span>             samples,
+<a name="l00181"></a>00181     <span class="keywordtype">int</span>             filter_type,
+<a name="l00182"></a>00182     <span class="keywordtype">int</span>             hw
+<a name="l00183"></a>00183 ) ;
+<a name="l00184"></a>00184 
+<a name="l00203"></a>00203 pixelvalue * 
+<a name="l00204"></a>00204 sinfo_function1d_median_smooth(
+<a name="l00205"></a>00205     pixelvalue * list,
+<a name="l00206"></a>00206     <span class="keywordtype">int</span>          np,
+<a name="l00207"></a>00207     <span class="keywordtype">int</span>          hw);
+<a name="l00208"></a>00208 
+<a name="l00225"></a>00225 pixelvalue * 
+<a name="l00226"></a>00226 sinfo_function1d_remove_lowfreq(
+<a name="l00227"></a>00227     pixelvalue * loc_signal,
+<a name="l00228"></a>00228     <span class="keywordtype">int</span>          ns);
+<a name="l00229"></a>00229 
+<a name="l00251"></a>00251 pixelvalue * 
+<a name="l00252"></a>00252 sinfo_function1d_remove_thermalbg(
+<a name="l00253"></a>00253     pixelvalue * pixel_signal,
+<a name="l00254"></a>00254     <span class="keywordtype">int</span>          ns);
+<a name="l00255"></a>00255 
+<a name="l00256"></a>00256 
+<a name="l00278"></a>00278 <span class="keywordtype">void</span> 
+<a name="l00279"></a>00279 sinfo_function1d_interpolate_linear(
+<a name="l00280"></a>00280     pixelvalue  *   x,
+<a name="l00281"></a>00281     pixelvalue  *   y,
+<a name="l00282"></a>00282     <span class="keywordtype">int</span>             len,
+<a name="l00283"></a>00283     pixelvalue  *   spl_x,
+<a name="l00284"></a>00284     pixelvalue  *   spl_y,
+<a name="l00285"></a>00285     <span class="keywordtype">int</span>             spl_len
+<a name="l00286"></a>00286 );
+<a name="l00287"></a>00287 
+<a name="l00288"></a>00288 
+<a name="l00314"></a>00314 <span class="keywordtype">int</span>
+<a name="l00315"></a>00315 sinfo_function1d_natural_spline(
+<a name="l00316"></a>00316     pixelvalue  *   x,
+<a name="l00317"></a>00317     pixelvalue  *   y,
+<a name="l00318"></a>00318     <span class="keywordtype">int</span>             len,
+<a name="l00319"></a>00319     pixelvalue  *   splX,
+<a name="l00320"></a>00320     pixelvalue  *   splY,
+<a name="l00321"></a>00321     <span class="keywordtype">int</span>             splLen
+<a name="l00322"></a>00322 ) ;
+<a name="l00323"></a>00323 
+<a name="l00324"></a>00324 
+<a name="l00343"></a>00343 pixelvalue
+<a name="l00344"></a>00344 sinfo_function1d_average_reject(
+<a name="l00345"></a>00345     pixelvalue  *   line,
+<a name="l00346"></a>00346     <span class="keywordtype">int</span>             npix,
+<a name="l00347"></a>00347     <span class="keywordtype">int</span>             pix_low,
+<a name="l00348"></a>00348     <span class="keywordtype">int</span>             pix_high);
+<a name="l00349"></a>00349 
+<a name="l00374"></a>00374 <span class="keywordtype">double</span> 
+<a name="l00375"></a>00375 sinfo_function1d_xcorrelate(
+<a name="l00376"></a>00376     pixelvalue *    line_i,
+<a name="l00377"></a>00377     <span class="keywordtype">int</span>             width_i,
+<a name="l00378"></a>00378     pixelvalue *    line_t,
+<a name="l00379"></a>00379     <span class="keywordtype">int</span>             width_t,
+<a name="l00380"></a>00380     <span class="keywordtype">int</span>             half_search,
+<a name="l00381"></a>00381     <span class="keywordtype">double</span>     *    delta);
+<a name="l00382"></a>00382 
+<a name="l00383"></a>00383 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__functions_8h_source.html b/html/sinfo__functions_8h_source.html
new file mode 100644
index 0000000..0114d00
--- /dev/null
+++ b/html/sinfo__functions_8h_source.html
@@ -0,0 +1,289 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_functions.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_functions.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_functions.h,v 1.13 2009/03/04 10:17:38 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the SINFONI Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This proram is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2009/03/04 10:17:38 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.13 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 <span class="preprocessor">#ifndef SINFO_FUNCTIONS_H</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_FUNCTIONS_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00031"></a>00031 <span class="preprocessor">#include <sinfo_time.h></span>
+<a name="l00032"></a>00032 <span class="preprocessor">#include <sinfo_globals.h></span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include <sinfo_skycor.h></span>
+<a name="l00034"></a>00034 
+<a name="l00035"></a>00035 <span class="keywordtype">int</span> sinfo_print_rec_status(<span class="keyword">const</span> <span class="keywordtype">int</span> val);
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 cpl_frameset *
+<a name="l00038"></a>00038 sinfo_frameset_extract(<span class="keyword">const</span> cpl_frameset *frames,<span class="keyword">const</span> <span class="keywordtype">char</span> *tag);
+<a name="l00039"></a>00039 
+<a name="l00040"></a>00040 <span class="keywordtype">int</span> 
+<a name="l00041"></a>00041 sinfo_propertylist_has(cpl_propertylist* plist,<span class="keyword">const</span> <span class="keywordtype">char</span>* key);
+<a name="l00042"></a>00042 
+<a name="l00043"></a>00043 cpl_vector* 
+<a name="l00044"></a>00044 sinfo_vector_clip(<span class="keyword">const</span> cpl_vector* vinp, 
+<a name="l00045"></a>00045                   <span class="keyword">const</span> <span class="keywordtype">double</span> kappa, 
+<a name="l00046"></a>00046                   <span class="keyword">const</span> <span class="keywordtype">int</span> n, 
+<a name="l00047"></a>00047                   <span class="keyword">const</span> <span class="keywordtype">int</span> method);
+<a name="l00048"></a>00048 
+<a name="l00049"></a>00049 
+<a name="l00050"></a>00050 <span class="keywordtype">int</span>
+<a name="l00051"></a>00051 sinfo_image_estimate_noise(cpl_image* img,
+<a name="l00052"></a>00052                             <span class="keyword">const</span> <span class="keywordtype">int</span> noise_fit, 
+<a name="l00053"></a>00053                             <span class="keywordtype">double</span>* centre, 
+<a name="l00054"></a>00054                <span class="keywordtype">double</span>* noise);
+<a name="l00055"></a>00055 
+<a name="l00056"></a>00056 
+<a name="l00057"></a>00057 cpl_table* sinfo_compute_gain(cpl_frameset* son, cpl_frameset* sof);
+<a name="l00058"></a>00058 cpl_table* sinfo_compute_linearity(cpl_frameset* son, cpl_frameset* sof);
+<a name="l00059"></a>00059 cpl_error_code sinfo_fit_lm(<span class="keyword">const</span> cpl_matrix *x, 
+<a name="l00060"></a>00060                             <span class="keyword">const</span> cpl_matrix *sigma_x,
+<a name="l00061"></a>00061                 <span class="keyword">const</span> cpl_vector *y, 
+<a name="l00062"></a>00062                             <span class="keyword">const</span> cpl_vector *sigma_y,
+<a name="l00063"></a>00063                       cpl_vector *a, 
+<a name="l00064"></a>00064                             <span class="keyword">const</span> <span class="keywordtype">int</span> ia[],
+<a name="l00065"></a>00065                 <span class="keywordtype">int</span>    (*f)(<span class="keyword">const</span> <span class="keywordtype">double</span> x[], 
+<a name="l00066"></a>00066                                         <span class="keyword">const</span> <span class="keywordtype">double</span> a[], 
+<a name="l00067"></a>00067                           <span class="keywordtype">double</span> *result),
+<a name="l00068"></a>00068                  <span class="keywordtype">int</span> (*dfda)(<span class="keyword">const</span> <span class="keywordtype">double</span> x[], 
+<a name="l00069"></a>00069                                              <span class="keyword">const</span> <span class="keywordtype">double</span> a[], 
+<a name="l00070"></a>00070                          <span class="keywordtype">double</span> result[]),
+<a name="l00071"></a>00071                  <span class="keywordtype">double</span> *mse,
+<a name="l00072"></a>00072                  <span class="keywordtype">double</span> *red_chisq,
+<a name="l00073"></a>00073                  cpl_matrix **covariance);
+<a name="l00074"></a>00074 
+<a name="l00075"></a>00075 <span class="keywordtype">void</span>
+<a name="l00076"></a>00076 sinfo_fit_amoeba(<span class="keywordtype">double</span>**p, 
+<a name="l00077"></a>00077        <span class="keywordtype">double</span> y[], 
+<a name="l00078"></a>00078        <span class="keywordtype">int</span> ndim, 
+<a name="l00079"></a>00079        <span class="keywordtype">double</span> ftol, 
+<a name="l00080"></a>00080        <span class="keywordtype">double</span> (*funk)(<span class="keywordtype">double</span>[]),
+<a name="l00081"></a>00081        <span class="keywordtype">int</span>* nfunk);
+<a name="l00082"></a>00082 
+<a name="l00083"></a>00083 <span class="keywordtype">int</span> sinfo_vector_dindgen(cpl_vector** v);
+<a name="l00084"></a>00084 <span class="keywordtype">int</span> sinfo_is_fits_file(<span class="keyword">const</span> <span class="keywordtype">char</span> *filename);
+<a name="l00085"></a>00085 cpl_error_code
+<a name="l00086"></a>00086 sinfo_extract_frames_group_type(<span class="keyword">const</span> cpl_frameset * <span class="keyword">set</span>, 
+<a name="l00087"></a>00087                                 cpl_frameset** ext, cpl_frame_group type);
+<a name="l00088"></a>00088 cpl_error_code sinfo_frameset_merge(cpl_frameset * set1, 
+<a name="l00089"></a>00089                                     cpl_frameset* set2);
+<a name="l00090"></a>00090 cpl_error_code
+<a name="l00091"></a>00091 sinfo_table_correl(cpl_table * t1, 
+<a name="l00092"></a>00092                    cpl_table* t2, 
+<a name="l00093"></a>00093                    cpl_table* range,
+<a name="l00094"></a>00094                    <span class="keywordtype">double</span>* xcor);
+<a name="l00095"></a>00095 <span class="keywordtype">int</span> 
+<a name="l00096"></a>00096 sinfo_get_pupil_shift(cpl_imagelist* iml,<span class="keyword">const</span> <span class="keywordtype">int</span> n,cpl_table** qclog_tbl);
+<a name="l00097"></a>00097 <span class="keywordtype">int</span> sinfo_get_preoptic(<span class="keyword">const</span> <span class="keywordtype">char</span>* file,<span class="keyword">const</span> <span class="keywordtype">char</span>* val);
+<a name="l00098"></a>00098 <span class="keywordtype">int</span> sinfo_get_keyvalue_int(cpl_frame * ref_frame, <span class="keyword">const</span> <span class="keywordtype">char</span>* key_name);
+<a name="l00099"></a>00099 <span class="keywordtype">float</span> sinfo_get_keyvalue_float(cpl_frame * ref_frame, <span class="keyword">const</span> <span class="keywordtype">char</span>* key_name);
+<a name="l00100"></a>00100 <span class="keywordtype">double</span> sinfo_get_keyvalue_double(cpl_frame * ref_frame, <span class="keyword">const</span> <span class="keywordtype">char</span>* key_name);
+<a name="l00101"></a>00101 <span class="keywordtype">char</span> sinfo_get_keyvalue_bool(cpl_frame * ref_frame, <span class="keyword">const</span> <span class="keywordtype">char</span>* key_name);
+<a name="l00102"></a>00102 <span class="keyword">const</span> <span class="keywordtype">char</span>* 
+<a name="l00103"></a>00103 sinfo_get_keyvalue_string(cpl_frame * ref_frame, <span class="keyword">const</span> <span class="keywordtype">char</span>* key_name);
+<a name="l00104"></a>00104 <span class="keywordtype">int</span> sinfo_get_strehl_type(cpl_frameset* sof);
+<a name="l00105"></a>00105 <span class="keywordtype">double</span> sinfo_get_wave_cent(<span class="keyword">const</span> <span class="keywordtype">char</span>* band);
+<a name="l00106"></a>00106 <span class="keywordtype">void</span> sinfo_memory_status(<span class="keywordtype">void</span>);
+<a name="l00107"></a>00107 <span class="keywordtype">int</span> sinfo_check_rec_status(<span class="keyword">const</span> <span class="keywordtype">int</span> val);
+<a name="l00108"></a>00108 <span class="keywordtype">void</span> 
+<a name="l00109"></a>00109 sinfo_add_pro_fits_key(cpl_propertylist * plist,  
+<a name="l00110"></a>00110                        <span class="keywordtype">char</span>* pro_catg, 
+<a name="l00111"></a>00111                        <span class="keywordtype">char</span>* file_name, 
+<a name="l00112"></a>00112                        <span class="keywordtype">char</span>* out_name);
+<a name="l00113"></a>00113 <span class="comment">/* ---------------------------------------------------------------------- </span>
+<a name="l00114"></a>00114 <span class="comment">   group of frames</span>
+<a name="l00115"></a>00115 <span class="comment">---------------------------------------------------------------------- */</span>
+<a name="l00116"></a>00116 
+<a name="l00117"></a>00117 
+<a name="l00118"></a>00118 
+<a name="l00119"></a>00119 <span class="keywordtype">int</span> 
+<a name="l00120"></a>00120 sinfoni_extract_raw_linearity_frames(cpl_frameset * sof, cpl_frameset** raw);
+<a name="l00121"></a>00121 <span class="keywordtype">int</span> sinfoni_extract_raw_dark_frames(cpl_frameset * sof, cpl_frameset** raw);
+<a name="l00122"></a>00122 <span class="keywordtype">int</span> sinfo_extract_raw_pinhole_frames(cpl_frameset * sof, cpl_frameset** raw);
+<a name="l00123"></a>00123 <span class="keywordtype">int</span> sinfo_extract_raw_slit_frames(cpl_frameset * sof, cpl_frameset** raw);
+<a name="l00124"></a>00124 <span class="keywordtype">int</span> sinfo_extract_raw_stack_frames(cpl_frameset * sof, cpl_frameset** pro);
+<a name="l00125"></a>00125 <span class="keywordtype">int</span> sinfo_extract_on_frames(cpl_frameset * sof, cpl_frameset* on);
+<a name="l00126"></a>00126 <span class="keywordtype">int</span> sinfo_extract_off_frames(cpl_frameset * sof, cpl_frameset* off);
+<a name="l00127"></a>00127 
+<a name="l00128"></a>00128 <span class="keywordtype">int</span> sinfo_extract_raw_frames(cpl_frameset * sof, cpl_frameset** raw); 
+<a name="l00129"></a>00129 <span class="keywordtype">int</span> sinfoni_extract_pro_frames(cpl_frameset * sof, cpl_frameset** pro); 
+<a name="l00130"></a>00130 <span class="keywordtype">int</span> sinfo_extract_cdb_frames(cpl_frameset * sof, cpl_frameset** cdb);
+<a name="l00131"></a>00131  
+<a name="l00132"></a>00132 <span class="keywordtype">int</span> sinfo_extract_obj_frames(cpl_frameset * sof, cpl_frameset* obj);
+<a name="l00133"></a>00133 <span class="keywordtype">int</span> sinfo_extract_sky_frames(cpl_frameset * sof, cpl_frameset* sky);
+<a name="l00134"></a>00134 <span class="keywordtype">int</span> sinfo_extract_mst_frames(cpl_frameset * sof, cpl_frameset* cdb); 
+<a name="l00135"></a>00135 <span class="keywordtype">int</span> sinfo_extract_stk_frames(cpl_frameset * sof, cpl_frameset* res);
+<a name="l00136"></a>00136 <span class="keywordtype">int</span> 
+<a name="l00137"></a>00137 sinfo_extract_preoptic_frames(cpl_frameset * sof, 
+<a name="l00138"></a>00138                               cpl_frameset** res, 
+<a name="l00139"></a>00139                               <span class="keyword">const</span> <span class="keywordtype">char</span>* pre_opt);
+<a name="l00140"></a>00140 
+<a name="l00141"></a>00141 <span class="keywordtype">double</span> sinfo_get_cumoffsetx(cpl_frame * frame);
+<a name="l00142"></a>00142 <span class="keywordtype">double</span> sinfo_get_cumoffsety(cpl_frame * frame);
+<a name="l00143"></a>00143 <span class="keywordtype">int</span> sinfo_tag_is_objpro(<span class="keywordtype">char</span> * tag);
+<a name="l00144"></a>00144 <span class="keywordtype">int</span> sinfo_extract_obj_products(cpl_frameset * sof, cpl_frameset* obj);
+<a name="l00145"></a>00145 
+<a name="l00146"></a>00146 cpl_frameset* sinfo_frameset_join(cpl_frameset* fs1,cpl_frameset* fs2);
+<a name="l00147"></a>00147 
+<a name="l00148"></a>00148 <span class="keyword">const</span> <span class="keywordtype">char</span>* sinfo_get_pix_scale(<span class="keywordtype">float</span> ps);
+<a name="l00149"></a>00149 <span class="keywordtype">int</span> sinfo_pix_scale_isnot_const(<span class="keywordtype">float</span>* pix_scale, <span class="keywordtype">int</span> size);
+<a name="l00150"></a>00150 
+<a name="l00151"></a>00151 <span class="keywordtype">int</span> sinfo_contains_frames_kind(cpl_frameset * sof, 
+<a name="l00152"></a>00152                                  cpl_frameset* raw,
+<a name="l00153"></a>00153                                  <span class="keyword">const</span> <span class="keywordtype">char</span>*         type);
+<a name="l00154"></a>00154 
+<a name="l00155"></a>00155 <span class="keywordtype">int</span> sinfo_contains_frames_type(cpl_frameset * sof, 
+<a name="l00156"></a>00156                                     cpl_frameset** raw,
+<a name="l00157"></a>00157                                     <span class="keyword">const</span> <span class="keywordtype">char</span>*          type);
+<a name="l00158"></a>00158 
+<a name="l00159"></a>00159 
+<a name="l00160"></a>00160 <span class="keywordtype">int</span> sinfo_extract_raw_frames_type(cpl_frameset * sof, 
+<a name="l00161"></a>00161                                     cpl_frameset** raw,
+<a name="l00162"></a>00162                                     <span class="keyword">const</span> <span class="keywordtype">char</span>*          type);
+<a name="l00163"></a>00163 
+<a name="l00164"></a>00164 <span class="keywordtype">int</span> sinfo_extract_raw_frames_type2(cpl_frameset * sof, 
+<a name="l00165"></a>00165                                     cpl_frameset** raw,
+<a name="l00166"></a>00166                                     <span class="keyword">const</span> <span class="keywordtype">char</span>*          type);
+<a name="l00167"></a>00167 
+<a name="l00168"></a>00168 <span class="keywordtype">int</span> sinfo_extract_raw_frames_type1(cpl_frameset * sof, 
+<a name="l00169"></a>00169                                     cpl_frameset* raw,
+<a name="l00170"></a>00170                                     <span class="keyword">const</span> <span class="keywordtype">char</span>*          type);
+<a name="l00171"></a>00171 
+<a name="l00172"></a>00172 <span class="keywordtype">int</span> sinfo_extract_frames_type(cpl_frameset * sof, 
+<a name="l00173"></a>00173                                 cpl_frameset * raw,
+<a name="l00174"></a>00174                 <span class="keyword">const</span> <span class="keywordtype">char</span>*          type);
+<a name="l00175"></a>00175 
+<a name="l00176"></a>00176 <span class="keywordtype">int</span> sinfo_remove_qc_frames(cpl_frameset* sof,cpl_frameset** raw);
+<a name="l00177"></a>00177 <span class="comment">/* ---------------------------------------------------------------------- </span>
+<a name="l00178"></a>00178 <span class="comment">   single frames</span>
+<a name="l00179"></a>00179 <span class="comment">---------------------------------------------------------------------- */</span>
+<a name="l00180"></a>00180 <span class="keywordtype">double</span> sinfo_get_mjd_obs(cpl_frame * frame);
+<a name="l00181"></a>00181 <span class="keywordtype">int</span> sinfo_frame_is_raw(<span class="keywordtype">char</span> * tag); 
+<a name="l00182"></a>00182 <span class="keywordtype">int</span> sinfoni_frame_is_pro(<span class="keywordtype">char</span> * tag); 
+<a name="l00183"></a>00183 <span class="keywordtype">int</span> sinfo_frame_is_cdb(<span class="keywordtype">char</span> * tag); 
+<a name="l00184"></a>00184 <span class="keywordtype">int</span> sinfo_frame_is_stk(<span class="keywordtype">char</span> * tag); 
+<a name="l00185"></a>00185 <span class="keywordtype">int</span> sinfo_frame_is_preoptic(cpl_frame*, <span class="keyword">const</span> <span class="keywordtype">char</span>* val); 
+<a name="l00186"></a>00186 
+<a name="l00187"></a>00187 <span class="keywordtype">int</span> sinfo_frame_is_pinhole_lamp(<span class="keywordtype">char</span> * tag); 
+<a name="l00188"></a>00188 <span class="keywordtype">int</span> sinfo_frame_is_raw_stack(<span class="keywordtype">char</span> * tag); 
+<a name="l00189"></a>00189 <span class="keywordtype">int</span> sinfo_frame_is_slit_lamp(<span class="keywordtype">char</span> * tag); 
+<a name="l00190"></a>00190 
+<a name="l00191"></a>00191 
+<a name="l00192"></a>00192 <span class="keywordtype">int</span> sinfo_is_flat_bp(<span class="keywordtype">char</span> * tag);
+<a name="l00193"></a>00193 <span class="keywordtype">int</span> sinfo_is_flat_lindet(<span class="keywordtype">char</span> * tag);
+<a name="l00194"></a>00194 <span class="keywordtype">int</span> sinfo_is_dark(<span class="keywordtype">char</span> * tag);
+<a name="l00195"></a>00195 <span class="keywordtype">int</span> sinfoni_is_pinhole_lamp(<span class="keywordtype">char</span> * tag) ;
+<a name="l00196"></a>00196 <span class="keywordtype">int</span> sinfoni_is_raw_stack(<span class="keywordtype">char</span> * tag) ;
+<a name="l00197"></a>00197 
+<a name="l00198"></a>00198 <span class="keywordtype">int</span> sinfoni_is_lamp_slit(<span class="keywordtype">char</span> * tag) ;
+<a name="l00199"></a>00199 <span class="keywordtype">int</span> sinfo_is_sky_flat(<span class="keywordtype">char</span> * tag) ;
+<a name="l00200"></a>00200 
+<a name="l00201"></a>00201 <span class="keywordtype">int</span> sinfo_is_mflat(<span class="keywordtype">char</span> * tag) ;
+<a name="l00202"></a>00202 <span class="keywordtype">int</span> sinfo_is_master_flat(<span class="keywordtype">char</span> * tag) ;
+<a name="l00203"></a>00203 <span class="keywordtype">int</span> sinfo_is_master_flat_dither(<span class="keywordtype">char</span> * tag) ;
+<a name="l00204"></a>00204 
+<a name="l00205"></a>00205 <span class="keywordtype">int</span> sinfo_is_stack(<span class="keywordtype">char</span> * tag) ;
+<a name="l00206"></a>00206 <span class="keywordtype">int</span> sinfo_is_lamp_wave_stacked(<span class="keywordtype">char</span> * tag) ;
+<a name="l00207"></a>00207 <span class="keywordtype">int</span> sinfo_is_lamp_flux_stacked(<span class="keywordtype">char</span> * tag) ;
+<a name="l00208"></a>00208 <span class="keywordtype">int</span> sinfo_is_psf_calibrator_stacked(<span class="keywordtype">char</span> * tag) ;
+<a name="l00209"></a>00209 <span class="keywordtype">int</span> sinfo_is_focus_stacked(<span class="keywordtype">char</span> * tag) ;
+<a name="l00210"></a>00210 <span class="keywordtype">int</span> sinfo_is_object_nodding_stacked(<span class="keywordtype">char</span> * tag) ;
+<a name="l00211"></a>00211 <span class="keywordtype">int</span> sinfo_is_sky_nodding_stacked(<span class="keywordtype">char</span> * tag) ;
+<a name="l00212"></a>00212 <span class="keywordtype">int</span> sinfo_is_object_skyspider_stacked(<span class="keywordtype">char</span> * tag) ;
+<a name="l00213"></a>00213 
+<a name="l00214"></a>00214 
+<a name="l00215"></a>00215 <span class="keywordtype">int</span> sinfo_blank2dot(<span class="keyword">const</span> <span class="keywordtype">char</span> * in, <span class="keywordtype">char</span>* ou) ;
+<a name="l00216"></a>00216 <span class="keywordtype">int</span> sinfo_is_bpmap(<span class="keywordtype">char</span> *) ;
+<a name="l00217"></a>00217 <span class="keywordtype">int</span> sinfo_is_slitpos(<span class="keywordtype">char</span> * tag) ;
+<a name="l00218"></a>00218 <span class="keywordtype">int</span> sinfo_is_wavemap(<span class="keywordtype">char</span> * tag) ;
+<a name="l00219"></a>00219 <span class="keywordtype">int</span> sinfo_is_halosp(<span class="keywordtype">char</span> * tag) ;
+<a name="l00220"></a>00220 <span class="keywordtype">int</span> sinfo_is_distlist(<span class="keywordtype">char</span> * tag) ;
+<a name="l00221"></a>00221 <span class="keywordtype">int</span> sinfo_is_firstcol(<span class="keywordtype">char</span> * tag) ;
+<a name="l00222"></a>00222 <span class="keywordtype">int</span> sinfo_is_fibres_on_off(cpl_frameset * sof, 
+<a name="l00223"></a>00223                  cpl_frameset* raw);
+<a name="l00224"></a>00224 <span class="comment">/* ---------------------------------------------------------------------- </span>
+<a name="l00225"></a>00225 <span class="comment">   Extra functionalities</span>
+<a name="l00226"></a>00226 <span class="comment">---------------------------------------------------------------------- */</span>
+<a name="l00227"></a>00227 <span class="keywordtype">int</span>
+<a name="l00228"></a>00228 sinfo_clean_nan(cpl_image** im);
+<a name="l00229"></a>00229 
+<a name="l00230"></a>00230 <span class="keywordtype">int</span>  sinfo_get_clean_mean_window(cpl_image* img, 
+<a name="l00231"></a>00231                                  <span class="keywordtype">int</span> llx, 
+<a name="l00232"></a>00232                                  <span class="keywordtype">int</span> lly, 
+<a name="l00233"></a>00233                                  <span class="keywordtype">int</span> urx, 
+<a name="l00234"></a>00234                                  <span class="keywordtype">int</span> ury, 
+<a name="l00235"></a>00235                                  <span class="keyword">const</span> <span class="keywordtype">int</span> kappa, 
+<a name="l00236"></a>00236                                  <span class="keyword">const</span> <span class="keywordtype">int</span> nclip, 
+<a name="l00237"></a>00237                                  <span class="keywordtype">double</span>* sinfo_clean_mean, 
+<a name="l00238"></a>00238                                  <span class="keywordtype">double</span>* clean_stdev);
+<a name="l00239"></a>00239 
+<a name="l00240"></a>00240 <span class="keywordtype">int</span> sinfo_get_obsname(cpl_frame * ref_frame, <span class="keyword">const</span> <span class="keywordtype">char</span>* ob_name);
+<a name="l00241"></a>00241 
+<a name="l00242"></a>00242 
+<a name="l00243"></a>00243  <span class="keywordtype">int</span> sinfo_get_ron(cpl_frameset    *   framelist,
+<a name="l00244"></a>00244                 <span class="keyword">const</span> <span class="keywordtype">int</span> ron_xmin,
+<a name="l00245"></a>00245                 <span class="keyword">const</span> <span class="keywordtype">int</span> ron_xmax,
+<a name="l00246"></a>00246                 <span class="keyword">const</span> <span class="keywordtype">int</span> ron_ymin,
+<a name="l00247"></a>00247                 <span class="keyword">const</span> <span class="keywordtype">int</span> ron_ymax,
+<a name="l00248"></a>00248                 <span class="keyword">const</span> <span class="keywordtype">int</span> ron_hsize,
+<a name="l00249"></a>00249                 <span class="keyword">const</span> <span class="keywordtype">int</span> ron_nsamp,
+<a name="l00250"></a>00250              <span class="keywordtype">double</span>** ron);
+<a name="l00251"></a>00251 <span class="keywordtype">int</span> sinfo_stack_get_pro_tag(<span class="keywordtype">char</span> * tag_in, <span class="keywordtype">char</span>* tag_out) ; 
+<a name="l00252"></a>00252 <span class="keywordtype">int</span> sinfo_compare_tags(<span class="keyword">const</span> cpl_frame *, <span class="keyword">const</span> cpl_frame *) ;
+<a name="l00253"></a>00253 
+<a name="l00254"></a>00254 <span class="keywordtype">int</span> sinfo_get_spatial_res(cpl_frame * ref_frame,<span class="keywordtype">char</span> * spat_res);
+<a name="l00255"></a>00255 <span class="keywordtype">int</span> sinfo_frame_is_dither(cpl_frame * ref_frame);
+<a name="l00256"></a>00256 <span class="keywordtype">int</span> sinfo_frame_is_sky(cpl_frame * ref_frame);
+<a name="l00257"></a>00257 <span class="keywordtype">int</span> sinfo_tag_is_obj(<span class="keywordtype">char</span> * ref_frame);
+<a name="l00258"></a>00258 <span class="keywordtype">int</span> sinfo_tag_is_sky(<span class="keywordtype">char</span> * ref_frame);
+<a name="l00259"></a>00259 
+<a name="l00260"></a>00260 <span class="keywordtype">int</span> sinfo_frame_is_on(cpl_frame * ref_frame);
+<a name="l00261"></a>00261 <span class="keywordtype">int</span> sinfo_get_band(cpl_frame * ref_frame,<span class="keywordtype">char</span> * band);
+<a name="l00262"></a>00262 <span class="keywordtype">int</span> sinfo_get_ins_set(<span class="keywordtype">char</span>* band,<span class="keywordtype">int</span>* ins_set);
+<a name="l00263"></a>00263 <span class="keywordtype">int</span> sinfoni_get_ins_setting(cpl_frame * ref_file,<span class="keywordtype">char</span> * set_id);
+<a name="l00264"></a>00264 <span class="keywordtype">int</span> sinfo_pfits_add_qc(cpl_propertylist * plist,qc_log * qclog);
+<a name="l00265"></a>00265 
+<a name="l00266"></a>00266 
+<a name="l00267"></a>00267 
+<a name="l00268"></a>00268 
+<a name="l00269"></a>00269 
+<a name="l00270"></a>00270 
+<a name="l00271"></a>00271 CPL_END_DECLS
+<a name="l00272"></a>00272 
+<a name="l00273"></a>00273 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__general__config_8c_source.html b/html/sinfo__general__config_8c_source.html
new file mode 100644
index 0000000..513b095
--- /dev/null
+++ b/html/sinfo__general__config_8c_source.html
@@ -0,0 +1,107 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_general_config.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_general_config.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_general_config.c,v 1.6 2012/03/02 08:42:20 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the CPL (Common Pipeline Library)</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
+<a name="l00007"></a>00007 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span>
+<a name="l00008"></a>00008 <span class="comment"> * License as published by the Free Software Foundation; either</span>
+<a name="l00009"></a>00009 <span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
+<a name="l00014"></a>00014 <span class="comment"> * Lesser General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
+<a name="l00017"></a>00017 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2012/03/02 08:42:20 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.6 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> */</span>
+<a name="l00026"></a>00026 
+<a name="l00027"></a>00027  <span class="comment">/****************************************************************</span>
+<a name="l00028"></a>00028 <span class="comment">  *           Bad pixel search  (normal method)                  *</span>
+<a name="l00029"></a>00029 <span class="comment">  ****************************************************************/</span>
+<a name="l00030"></a>00030 
+<a name="l00031"></a>00031 
+<a name="l00032"></a>00032 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00033"></a>00033 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00034"></a>00034 <span class="preprocessor">#endif</span>
+<a name="l00035"></a>00035 <span class="preprocessor"></span>
+<a name="l00036"></a>00036 <span class="preprocessor">#include "sinfo_general_config.h"</span>
+<a name="l00037"></a>00037 
+<a name="l00056"></a>00056   <span class="comment">/* General data reduction parameters */</span>
+<a name="l00057"></a>00057 
+<a name="l00058"></a>00058 <span class="keywordtype">void</span>
+<a name="l00059"></a>00059  sinfo_general_config_add(cpl_parameterlist *list)
+<a name="l00060"></a>00060 {
+<a name="l00061"></a>00061 
+<a name="l00062"></a>00062   cpl_parameter *p;
+<a name="l00063"></a>00063 
+<a name="l00064"></a>00064   <span class="keywordflow">if</span> (!list) {
+<a name="l00065"></a>00065     <span class="keywordflow">return</span>;
+<a name="l00066"></a>00066   }
+<a name="l00067"></a>00067 
+<a name="l00068"></a>00068   <span class="comment">/* indicates if parameters will be overwritten */</span>
+<a name="l00069"></a>00069   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.general.overwrite_parameters"</span>,
+<a name="l00070"></a>00070                   CPL_TYPE_BOOL,
+<a name="l00071"></a>00071                               <span class="stringliteral">"Overwrite DRS ini parameters: "</span>,
+<a name="l00072"></a>00072                               <span class="stringliteral">"sinfoni.general"</span>,
+<a name="l00073"></a>00073                               TRUE);
+<a name="l00074"></a>00074 
+<a name="l00075"></a>00075   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"gen-overpar"</span>);
+<a name="l00076"></a>00076   cpl_parameterlist_append(list, p);
+<a name="l00077"></a>00077 
+<a name="l00078"></a>00078   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.general.lc_sw"</span>,
+<a name="l00079"></a>00079                               CPL_TYPE_BOOL,
+<a name="l00080"></a>00080                               <span class="stringliteral">"Correct for bad lines introduced by "</span>
+<a name="l00081"></a>00081                               <span class="stringliteral">"instrument software: "</span>,
+<a name="l00082"></a>00082                               <span class="stringliteral">"sinfoni.general"</span>,
+<a name="l00083"></a>00083                               FALSE);
+<a name="l00084"></a>00084 
+<a name="l00085"></a>00085   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"lc_sw"</span>);
+<a name="l00086"></a>00086   cpl_parameterlist_append(list, p);
+<a name="l00087"></a>00087 
+<a name="l00088"></a>00088 
+<a name="l00089"></a>00089   <span class="comment">/* Fill the parameters list */</span>
+<a name="l00090"></a>00090   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.general.lc_kappa"</span>, 
+<a name="l00091"></a>00091                               CPL_TYPE_INT,
+<a name="l00092"></a>00092                               <span class="stringliteral">"Kappa sigma value"</span>, 
+<a name="l00093"></a>00093                               <span class="stringliteral">"sinfoni.general"</span>,18);
+<a name="l00094"></a>00094   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"lc_kappa"</span>) ;
+<a name="l00095"></a>00095   cpl_parameterlist_append(list, p) ;
+<a name="l00096"></a>00096 
+<a name="l00097"></a>00097   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.general.lc_filt_rad"</span>, 
+<a name="l00098"></a>00098                               CPL_TYPE_INT,
+<a name="l00099"></a>00099                   <span class="stringliteral">"Filtering radii applied during median filter."</span>
+<a name="l00100"></a>00100                               <span class="stringliteral">" Should be small"</span>, 
+<a name="l00101"></a>00101                   <span class="stringliteral">"sinfoni.general"</span>,3) ;
+<a name="l00102"></a>00102 
+<a name="l00103"></a>00103   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"lc_filt_rad"</span>) ;
+<a name="l00104"></a>00104   cpl_parameterlist_append(list, p) ;
+<a name="l00105"></a>00105 
+<a name="l00106"></a>00106 
+<a name="l00107"></a>00107   <span class="keywordflow">return</span>;
+<a name="l00108"></a>00108 
+<a name="l00109"></a>00109 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__general__config_8h_source.html b/html/sinfo__general__config_8h_source.html
new file mode 100644
index 0000000..d9a6d81
--- /dev/null
+++ b/html/sinfo__general__config_8h_source.html
@@ -0,0 +1,53 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_general_config.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_general_config.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_general_config.h,v 1.1 2006/10/20 08:06:32 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the CPL (Common Pipeline Library)</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
+<a name="l00007"></a>00007 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span>
+<a name="l00008"></a>00008 <span class="comment"> * License as published by the Free Software Foundation; either</span>
+<a name="l00009"></a>00009 <span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
+<a name="l00014"></a>00014 <span class="comment"> * Lesser General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
+<a name="l00017"></a>00017 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2006/10/20 08:06:32 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.1 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> */</span>
+<a name="l00026"></a>00026 
+<a name="l00027"></a>00027  <span class="comment">/****************************************************************</span>
+<a name="l00028"></a>00028 <span class="comment">  *           Bad pixel search  (noise method)                  *</span>
+<a name="l00029"></a>00029 <span class="comment">  ****************************************************************/</span>
+<a name="l00030"></a>00030 <span class="preprocessor">#ifndef SINFO_GENERAL_CONFIG_H</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_GENERAL_CONFIG_H</span>
+<a name="l00032"></a>00032 <span class="preprocessor"></span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include <cpl.h></span>   
+<a name="l00034"></a>00034 
+<a name="l00035"></a>00035 <span class="keywordtype">void</span> sinfo_general_config_add(cpl_parameterlist *list);
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__globals_8c_source.html b/html/sinfo__globals_8c_source.html
new file mode 100644
index 0000000..b948e70
--- /dev/null
+++ b/html/sinfo__globals_8c_source.html
@@ -0,0 +1,185 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_globals.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_globals.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00020"></a>00020 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00021"></a>00021 <span class="preprocessor">#endif</span>
+<a name="l00022"></a>00022 <span class="preprocessor"></span><span class="preprocessor">#include <string.h></span>
+<a name="l00023"></a>00023 <span class="preprocessor">#include "sinfo_globals.h"</span>
+<a name="l00024"></a>00024 <span class="preprocessor">#include "sinfo_utils_wrappers.h"</span>
+<a name="l00025"></a>00025 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00026"></a>00026 
+<a name="l00041"></a>00041 amoeba_dat*
+<a name="l00042"></a>00042 sinfo_amoeba_new(cpl_vector* vx, 
+<a name="l00043"></a>00043                  cpl_vector* vy, 
+<a name="l00044"></a>00044                  cpl_vector* sx, 
+<a name="l00045"></a>00045                  cpl_vector* sy)
+<a name="l00046"></a>00046  {
+<a name="l00047"></a>00047    amoeba_dat * a;
+<a name="l00048"></a>00048    a= cpl_malloc(<span class="keyword">sizeof</span>(amoeba_dat));
+<a name="l00049"></a>00049 
+<a name="l00050"></a>00050    a->vx=cpl_vector_duplicate(vx);
+<a name="l00051"></a>00051    a->vy=cpl_vector_duplicate(vy);
+<a name="l00052"></a>00052    a->sx=cpl_vector_duplicate(sx);
+<a name="l00053"></a>00053    a->sy=cpl_vector_duplicate(sy);
+<a name="l00054"></a>00054 
+<a name="l00055"></a>00055 
+<a name="l00056"></a>00056   <span class="keywordflow">return</span> a;
+<a name="l00057"></a>00057 
+<a name="l00058"></a>00058 }
+<a name="l00065"></a>00065 <span class="keywordtype">void</span>
+<a name="l00066"></a>00066 sinfo_amoeba_delete(amoeba_dat** a)
+<a name="l00067"></a>00067 {
+<a name="l00068"></a>00068   sinfo_free_my_vector(&((*a)->vx));
+<a name="l00069"></a>00069   sinfo_free_my_vector(&((*a)->vy));
+<a name="l00070"></a>00070   sinfo_free_my_vector(&((*a)->sx));
+<a name="l00071"></a>00071   sinfo_free_my_vector(&((*a)->sy));
+<a name="l00072"></a>00072 
+<a name="l00073"></a>00073   cpl_free(*a);
+<a name="l00074"></a>00074   *a=NULL;
+<a name="l00075"></a>00075 }
+<a name="l00076"></a>00076 
+<a name="l00077"></a>00077 
+<a name="l00084"></a>00084 fake*
+<a name="l00085"></a>00085 sinfo_fake_new(<span class="keywordtype">void</span>)
+<a name="l00086"></a>00086  {
+<a name="l00087"></a>00087    fake * f;
+<a name="l00088"></a>00088    f= cpl_malloc(<span class="keyword">sizeof</span>(fake));
+<a name="l00089"></a>00089 
+<a name="l00090"></a>00090   strcpy(f->pro_class,<span class="stringliteral">"DEFAULT"</span>);
+<a name="l00091"></a>00091   f->frm_switch=0;
+<a name="l00092"></a>00092   f->is_fake_sky=0;
+<a name="l00093"></a>00093   f->mask_index=1;
+<a name="l00094"></a>00094   f->ind_index=0;
+<a name="l00095"></a>00095   f->flat_index=1;
+<a name="l00096"></a>00096   f->wfix_index=1;
+<a name="l00097"></a>00097   f->low_rej=0.1;
+<a name="l00098"></a>00098   f->hig_rej=0.1;
+<a name="l00099"></a>00099   <span class="keywordflow">return</span> f;
+<a name="l00100"></a>00100 }
+<a name="l00107"></a>00107 <span class="keywordtype">void</span>
+<a name="l00108"></a>00108 sinfo_fake_delete(fake** f)
+<a name="l00109"></a>00109 {
+<a name="l00110"></a>00110   cpl_free(*f);
+<a name="l00111"></a>00111   *f=NULL;
+<a name="l00112"></a>00112 }
+<a name="l00113"></a>00113 
+<a name="l00120"></a>00120 wcal*
+<a name="l00121"></a>00121 sinfo_wcal_new(<span class="keywordtype">void</span>)
+<a name="l00122"></a>00122  {
+<a name="l00123"></a>00123    wcal * w;
+<a name="l00124"></a>00124    w= cpl_malloc(<span class="keyword">sizeof</span>(wcal));
+<a name="l00125"></a>00125 
+<a name="l00126"></a>00126    w->wstart=1.65;
+<a name="l00127"></a>00127    w->wgdisp1=-0.000200018796022;
+<a name="l00128"></a>00128    w->wgdisp2=9.30345245278e-10;
+<a name="l00129"></a>00129    w->min_dif=10.0;
+<a name="l00130"></a>00130    w->hw=7;
+<a name="l00131"></a>00131    w->fwhm=2.83;
+<a name="l00132"></a>00132    w->min_amp=5.0;
+<a name="l00133"></a>00133    w->na_coef=3;
+<a name="l00134"></a>00134    w->nb_coef=2;
+<a name="l00135"></a>00135    w->pixel_tol=7.0;
+<a name="l00136"></a>00136    w->y_box=2.0;
+<a name="l00137"></a>00137    w->low_pos=750;
+<a name="l00138"></a>00138    w->hig_pos=1000;
+<a name="l00139"></a>00139  
+<a name="l00140"></a>00140   <span class="keywordflow">return</span> w;
+<a name="l00141"></a>00141 }
+<a name="l00148"></a>00148 <span class="keywordtype">void</span>
+<a name="l00149"></a>00149 sinfo_wcal_delete(wcal* w)
+<a name="l00150"></a>00150 {
+<a name="l00151"></a>00151   cpl_free(w);
+<a name="l00152"></a>00152 }
+<a name="l00153"></a>00153 
+<a name="l00154"></a>00154 
+<a name="l00162"></a>00162 stack*
+<a name="l00163"></a>00163 sinfo_stack_new(<span class="keywordtype">void</span>)
+<a name="l00164"></a>00164  {
+<a name="l00165"></a>00165    stack * s;
+<a name="l00166"></a>00166    s= cpl_malloc(<span class="keyword">sizeof</span>(stack));
+<a name="l00167"></a>00167 
+<a name="l00168"></a>00168    strcpy(s->do_class,<span class="stringliteral">"DEFAULT"</span>);
+<a name="l00169"></a>00169    strcpy(s->index_list,<span class="stringliteral">"indexlist"</span>);
+<a name="l00170"></a>00170    s->warp_fix_ind=1;
+<a name="l00171"></a>00171   
+<a name="l00172"></a>00172   <span class="keywordflow">return</span> s;
+<a name="l00173"></a>00173 }
+<a name="l00180"></a>00180 <span class="keywordtype">void</span>
+<a name="l00181"></a>00181 sinfo_stack_delete(stack* s)
+<a name="l00182"></a>00182 {
+<a name="l00183"></a>00183   cpl_free(s);
+<a name="l00184"></a>00184 }
+<a name="l00191"></a>00191 nstpar*
+<a name="l00192"></a>00192 sinfo_nstpar_new(<span class="keywordtype">void</span>)
+<a name="l00193"></a>00193  {
+<a name="l00194"></a>00194    nstpar * n;
+<a name="l00195"></a>00195    n= cpl_malloc(<span class="keyword">sizeof</span>(nstpar));
+<a name="l00196"></a>00196 
+<a name="l00197"></a>00197    n->fwhm[0]=2.0;
+<a name="l00198"></a>00198    n->fwhm[1]=5.0;
+<a name="l00199"></a>00199    n->fwhm[2]=2.0;
+<a name="l00200"></a>00200    n->fwhm[3]=2.0;
+<a name="l00201"></a>00201 
+<a name="l00202"></a>00202    n->min_dif[0]=1.0;
+<a name="l00203"></a>00203    n->min_dif[1]=5.0;
+<a name="l00204"></a>00204    n->min_dif[2]=5.0;
+<a name="l00205"></a>00205    n->min_dif[3]=5.0;
+<a name="l00206"></a>00206  
+<a name="l00207"></a>00207   <span class="keywordflow">return</span> n;
+<a name="l00208"></a>00208 }
+<a name="l00215"></a>00215 <span class="keywordtype">void</span>
+<a name="l00216"></a>00216 sinfo_nstpar_delete(nstpar* n)
+<a name="l00217"></a>00217 {
+<a name="l00218"></a>00218   cpl_free(n);
+<a name="l00219"></a>00219 }
+<a name="l00227"></a>00227 distpar*
+<a name="l00228"></a>00228 sinfo_distpar_new(<span class="keywordtype">void</span>)
+<a name="l00229"></a>00229  {
+<a name="l00230"></a>00230    distpar * d;
+<a name="l00231"></a>00231    d= cpl_malloc(<span class="keyword">sizeof</span>(distpar));
+<a name="l00232"></a>00232 
+<a name="l00233"></a>00233    d->diff_tol[0]=2.0;
+<a name="l00234"></a>00234    d->diff_tol[1]=4.0;
+<a name="l00235"></a>00235    d->diff_tol[2]=2.0;
+<a name="l00236"></a>00236    d->diff_tol[3]=4.0;
+<a name="l00237"></a>00237  
+<a name="l00238"></a>00238   <span class="keywordflow">return</span> d;
+<a name="l00239"></a>00239 }
+<a name="l00246"></a>00246 <span class="keywordtype">void</span>
+<a name="l00247"></a>00247 sinfo_distpar_delete(distpar* d)
+<a name="l00248"></a>00248 {
+<a name="l00249"></a>00249   cpl_free(d);
+<a name="l00250"></a>00250 }
+<a name="l00251"></a>00251 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__globals_8h_source.html b/html/sinfo__globals_8h_source.html
new file mode 100644
index 0000000..eca3a82
--- /dev/null
+++ b/html/sinfo__globals_8h_source.html
@@ -0,0 +1,196 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_globals.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_globals.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_globals.h,v 1.6 2007/10/09 15:58:00 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the SINFONI Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This proram is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2007/10/09 15:58:00 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.6 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifndef SINFO_GLOBALS_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_GLOBALS_H</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span><span class="preprocessor">#include <cpl.h></span>
+<a name="l00031"></a>00031 <span class="comment">/*------------------------------------------------------------------------</span>
+<a name="l00032"></a>00032 <span class="comment">                                   Defines</span>
+<a name="l00033"></a>00033 <span class="comment"> --------------------------------------------------------------------------*/</span>
+<a name="l00034"></a>00034 <span class="preprocessor">#define SINFO_RESAMP_NROWS 2560</span>
+<a name="l00035"></a>00035 <span class="preprocessor"></span><span class="preprocessor">#define PI_NUMB     (3.1415926535897932384626433832795)</span>
+<a name="l00036"></a>00036 <span class="preprocessor"></span><span class="preprocessor">#define ZERO    0./0.</span>
+<a name="l00037"></a>00037 <span class="preprocessor"></span><span class="preprocessor">#define FLAG    -1.e+9</span>
+<a name="l00038"></a>00038 <span class="preprocessor"></span><span class="preprocessor">#define QC_DID_ID                          "SINFONI-1.0.0"</span>
+<a name="l00039"></a>00039 <span class="preprocessor"></span><span class="preprocessor">#define FILE_NAME_SZ                       512</span>
+<a name="l00040"></a>00040 <span class="preprocessor"></span><span class="preprocessor">#define MAX_NAME_SIZE                      512</span>
+<a name="l00041"></a>00041 <span class="preprocessor"></span><span class="preprocessor">#define TELESCOPE_SURFACE                  52.8101279</span>
+<a name="l00042"></a>00042 <span class="preprocessor"></span>
+<a name="l00043"></a>00043 <span class="preprocessor">#define NOISE_HSIZE                        4</span>
+<a name="l00044"></a>00044 <span class="preprocessor"></span><span class="preprocessor">#define NOISE_NSAMPLES                     100</span>
+<a name="l00045"></a>00045 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_DBL_MIN 1e-37</span>
+<a name="l00046"></a>00046 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_DBL_MAX 1e+37</span>
+<a name="l00047"></a>00047 <span class="preprocessor"></span>
+<a name="l00048"></a>00048 <span class="preprocessor">#define IMA_PIX_START                      0</span>
+<a name="l00049"></a>00049 <span class="preprocessor"></span><span class="preprocessor">#define IMA_PIX_END                        2047</span>
+<a name="l00050"></a>00050 <span class="preprocessor"></span><span class="preprocessor">#define SIZEX                              2048</span>
+<a name="l00051"></a>00051 <span class="preprocessor"></span><span class="preprocessor">#define SIZEY                              2048</span>
+<a name="l00052"></a>00052 <span class="preprocessor"></span><span class="preprocessor">#define DET_PIX_MIN                        1</span>
+<a name="l00053"></a>00053 <span class="preprocessor"></span><span class="preprocessor">#define DET_PIX_MAX                        2048</span>
+<a name="l00054"></a>00054 <span class="preprocessor"></span>
+<a name="l00055"></a>00055 
+<a name="l00056"></a>00056 <span class="preprocessor">#define LLX                                1350</span>
+<a name="l00057"></a>00057 <span class="preprocessor"></span><span class="preprocessor">#define LLY                                1000</span>
+<a name="l00058"></a>00058 <span class="preprocessor"></span><span class="preprocessor">#define URX                                1390</span>
+<a name="l00059"></a>00059 <span class="preprocessor"></span><span class="preprocessor">#define URY                                1200</span>
+<a name="l00060"></a>00060 <span class="preprocessor"></span>
+<a name="l00061"></a>00061 <span class="preprocessor">#define DISTORTION_LOPOS                    974</span>
+<a name="l00062"></a>00062 <span class="preprocessor"></span><span class="preprocessor">#define DISTORTION_HIPOS                   1074</span>
+<a name="l00063"></a>00063 <span class="preprocessor"></span>
+<a name="l00064"></a>00064 <span class="preprocessor">#define GRAT_VAL1_HK                       3997330</span>
+<a name="l00065"></a>00065 <span class="preprocessor"></span><span class="preprocessor">#define GRAT_VAL2_HK                       3997339</span>
+<a name="l00066"></a>00066 <span class="preprocessor"></span><span class="preprocessor">#define GRAT_VAL1_H                        2948723</span>
+<a name="l00067"></a>00067 <span class="preprocessor"></span><span class="preprocessor">#define GRAT_VAL2_H                        2948733</span>
+<a name="l00068"></a>00068 <span class="preprocessor"></span><span class="preprocessor">#define GRAT_VAL1_K                        1893844</span>
+<a name="l00069"></a>00069 <span class="preprocessor"></span><span class="preprocessor">#define GRAT_VAL2_K                        1893854</span>
+<a name="l00070"></a>00070 <span class="preprocessor"></span><span class="preprocessor">#define GRAT_VAL1_J                         849618</span>
+<a name="l00071"></a>00071 <span class="preprocessor"></span><span class="preprocessor">#define GRAT_VAL2_J                         849628</span>
+<a name="l00072"></a>00072 <span class="preprocessor"></span><span class="preprocessor">#define GRAT_VAL_TOL                             4</span>
+<a name="l00073"></a>00073 <span class="preprocessor"></span>
+<a name="l00074"></a>00074 <span class="preprocessor">#define SKY_FLUX                                 0</span>
+<a name="l00075"></a>00075 <span class="preprocessor"></span><span class="preprocessor">#define BKG_VARIANCE                            9.6</span>
+<a name="l00076"></a>00076 <span class="preprocessor"></span><span class="preprocessor">#define GAIN                                    2.42</span>
+<a name="l00077"></a>00077 <span class="preprocessor"></span><span class="preprocessor">#define MAGNITUDE                              11</span>
+<a name="l00078"></a>00078 <span class="preprocessor"></span>
+<a name="l00079"></a>00079 <span class="preprocessor">#define MSG_OVER_WRITE_PAR        "Using default data reduction parameters"</span>
+<a name="l00080"></a>00080 <span class="preprocessor"></span><span class="preprocessor">#define LAMP_ON     TRUE</span>
+<a name="l00081"></a>00081 <span class="preprocessor"></span><span class="preprocessor">#define LAMP_OFF    FALSE</span>
+<a name="l00082"></a>00082 <span class="preprocessor"></span>
+<a name="l00083"></a>00083 <span class="keyword">struct </span>amoeba_ {
+<a name="l00084"></a>00084   cpl_vector*   vx;
+<a name="l00085"></a>00085   cpl_vector*   vy;
+<a name="l00086"></a>00086   cpl_vector*   sx;
+<a name="l00087"></a>00087   cpl_vector*   sy;
+<a name="l00088"></a>00088 };
+<a name="l00089"></a>00089 <span class="keyword">typedef</span> <span class="keyword">struct </span>amoeba_ amoeba_dat; 
+<a name="l00090"></a>00090 
+<a name="l00091"></a>00091 amoeba_dat* sinfo_amoeba_new(cpl_vector* vx, 
+<a name="l00092"></a>00092                              cpl_vector* vy, 
+<a name="l00093"></a>00093                              cpl_vector* sx, 
+<a name="l00094"></a>00094                              cpl_vector* sy);
+<a name="l00095"></a>00095 <span class="keywordtype">void</span> sinfo_amoeba_delete(amoeba_dat** a);
+<a name="l00096"></a>00096 
+<a name="l00097"></a>00097 <span class="keyword">struct </span>qc_log_ {
+<a name="l00098"></a>00098   <span class="keywordtype">char</span>   name[30];
+<a name="l00099"></a>00099   <span class="keywordtype">char</span>   type[30];
+<a name="l00100"></a>00100   <span class="keywordtype">char</span>   s_val[30];
+<a name="l00101"></a>00101   <span class="keywordtype">char</span>   comm[30];
+<a name="l00102"></a>00102   <span class="keywordtype">double</span> n_val;
+<a name="l00103"></a>00103   <span class="keywordtype">int</span>    n;
+<a name="l00104"></a>00104 };
+<a name="l00105"></a>00105 <span class="keyword">typedef</span> <span class="keyword">struct </span>qc_log_ qc_log; 
+<a name="l00106"></a>00106 
+<a name="l00107"></a>00107 <span class="keyword">struct </span>fake_ {
+<a name="l00108"></a>00108   <span class="keywordtype">char</span>  pro_class[FILE_NAME_SZ];
+<a name="l00109"></a>00109   <span class="keywordtype">int</span>   frm_switch;
+<a name="l00110"></a>00110   <span class="keywordtype">int</span>   is_fake_sky;
+<a name="l00111"></a>00111   <span class="keywordtype">int</span>   mask_index;
+<a name="l00112"></a>00112   <span class="keywordtype">int</span>   ind_index;
+<a name="l00113"></a>00113   <span class="keywordtype">int</span>   flat_index;
+<a name="l00114"></a>00114   <span class="keywordtype">int</span>   wfix_index;
+<a name="l00115"></a>00115   <span class="keywordtype">double</span>   low_rej;
+<a name="l00116"></a>00116   <span class="keywordtype">double</span>   hig_rej;
+<a name="l00117"></a>00117 };
+<a name="l00118"></a>00118 
+<a name="l00119"></a>00119 <span class="keyword">typedef</span> <span class="keyword">struct </span>fake_ fake;
+<a name="l00120"></a>00120 fake* sinfo_fake_new(<span class="keywordtype">void</span>);
+<a name="l00121"></a>00121 <span class="keywordtype">void</span> sinfo_fake_delete(fake** f);
+<a name="l00122"></a>00122 
+<a name="l00123"></a>00123 
+<a name="l00124"></a>00124 <span class="keyword">struct </span>wcal_ {
+<a name="l00125"></a>00125   <span class="keywordtype">double</span> wstart;
+<a name="l00126"></a>00126   <span class="keywordtype">double</span> wgdisp1;
+<a name="l00127"></a>00127   <span class="keywordtype">double</span> wgdisp2;
+<a name="l00128"></a>00128   <span class="keywordtype">double</span> min_dif;
+<a name="l00129"></a>00129   <span class="keywordtype">double</span> fwhm;
+<a name="l00130"></a>00130   <span class="keywordtype">double</span> min_amp;
+<a name="l00131"></a>00131   <span class="keywordtype">double</span> pixel_tol;
+<a name="l00132"></a>00132   <span class="keywordtype">double</span> y_box;
+<a name="l00133"></a>00133   <span class="keywordtype">int</span> low_pos;
+<a name="l00134"></a>00134   <span class="keywordtype">int</span> hig_pos;
+<a name="l00135"></a>00135   <span class="keywordtype">int</span>    hw;
+<a name="l00136"></a>00136   <span class="keywordtype">int</span>    na_coef;
+<a name="l00137"></a>00137   <span class="keywordtype">int</span>    nb_coef;
+<a name="l00138"></a>00138 
+<a name="l00139"></a>00139 };
+<a name="l00140"></a>00140 
+<a name="l00141"></a>00141 <span class="keyword">typedef</span> <span class="keyword">struct </span>wcal_ wcal;
+<a name="l00142"></a>00142 
+<a name="l00143"></a>00143 wcal* sinfo_wcal_new(<span class="keywordtype">void</span>);
+<a name="l00144"></a>00144 <span class="keywordtype">void</span> sinfo_wcal_delete(wcal* f);
+<a name="l00145"></a>00145 
+<a name="l00146"></a>00146 
+<a name="l00147"></a>00147 <span class="keyword">struct </span>stack_ {
+<a name="l00148"></a>00148   <span class="keywordtype">char</span> do_class[FILE_NAME_SZ];
+<a name="l00149"></a>00149   <span class="keywordtype">char</span> index_list[FILE_NAME_SZ];
+<a name="l00150"></a>00150   <span class="keywordtype">int</span>  warp_fix_ind;
+<a name="l00151"></a>00151 };
+<a name="l00152"></a>00152 
+<a name="l00153"></a>00153 <span class="keyword">typedef</span> <span class="keyword">struct </span>stack_ stack;
+<a name="l00154"></a>00154 
+<a name="l00155"></a>00155 stack* sinfo_stack_new(<span class="keywordtype">void</span>);
+<a name="l00156"></a>00156 <span class="keywordtype">void</span> sinfo_stack_delete(stack* s);
+<a name="l00157"></a>00157 
+<a name="l00158"></a>00158 
+<a name="l00159"></a>00159 
+<a name="l00160"></a>00160 <span class="keyword">struct </span>nst_ {
+<a name="l00161"></a>00161   <span class="keywordtype">double</span> min_dif[4];
+<a name="l00162"></a>00162   <span class="keywordtype">double</span> fwhm[4];
+<a name="l00163"></a>00163 };
+<a name="l00164"></a>00164 
+<a name="l00165"></a>00165 <span class="keyword">typedef</span> <span class="keyword">struct </span>nst_ nstpar;
+<a name="l00166"></a>00166 
+<a name="l00167"></a>00167 nstpar* sinfo_nstpar_new(<span class="keywordtype">void</span>);
+<a name="l00168"></a>00168 <span class="keywordtype">void</span> sinfo_nstpar_delete(nstpar* n);
+<a name="l00169"></a>00169 
+<a name="l00170"></a>00170 <span class="keyword">struct </span>dist_ {
+<a name="l00171"></a>00171   <span class="keywordtype">double</span> diff_tol[4];
+<a name="l00172"></a>00172 };
+<a name="l00173"></a>00173 
+<a name="l00174"></a>00174 <span class="keyword">typedef</span> <span class="keyword">struct </span>dist_ distpar;
+<a name="l00175"></a>00175 
+<a name="l00176"></a>00176 distpar* sinfo_distpar_new(<span class="keywordtype">void</span>);
+<a name="l00177"></a>00177 <span class="keywordtype">void</span> sinfo_distpar_delete(distpar* d);
+<a name="l00178"></a>00178 
+<a name="l00179"></a>00179 
+<a name="l00180"></a>00180 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__hidden_8h_source.html b/html/sinfo__hidden_8h_source.html
new file mode 100644
index 0000000..2727ee6
--- /dev/null
+++ b/html/sinfo__hidden_8h_source.html
@@ -0,0 +1,128 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_hidden.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_hidden.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_hidden.h,v 1.7 2010/02/12 17:56:35 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the CPL (Common Pipeline Library)</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
+<a name="l00007"></a>00007 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span>
+<a name="l00008"></a>00008 <span class="comment"> * License as published by the Free Software Foundation; either</span>
+<a name="l00009"></a>00009 <span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
+<a name="l00014"></a>00014 <span class="comment"> * Lesser General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
+<a name="l00017"></a>00017 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2010/02/12 17:56:35 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.7 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> */</span>
+<a name="l00026"></a>00026 
+<a name="l00027"></a>00027  <span class="comment">/****************************************************************</span>
+<a name="l00028"></a>00028 <span class="comment">  *           Bad pixel search  (noise method)                  *</span>
+<a name="l00029"></a>00029 <span class="comment">  ****************************************************************/</span>
+<a name="l00030"></a>00030 <span class="preprocessor">#ifndef SINFO_HIDDEN_H</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_HIDDEN_H</span>
+<a name="l00032"></a>00032 <span class="preprocessor"></span>
+<a name="l00033"></a>00033 <span class="preprocessor">#define BP_LIN_OUT_FILENAME               "out_bp_lin.fits"</span>
+<a name="l00034"></a>00034 <span class="preprocessor"></span><span class="preprocessor">#define BP_LIN_GAIN_OUT_FILENAME          "out_gain_info.fits"</span>
+<a name="l00035"></a>00035 <span class="preprocessor"></span><span class="preprocessor">#define BP_LIN_LIN_DET_INFO_OUT_FILENAME  "out_lin_det_info.fits"</span>
+<a name="l00036"></a>00036 <span class="preprocessor"></span><span class="preprocessor">#define BP_LIN_COEFFS_CUBE_OUT_FILENAME   "out_bplin_coeffsCube.fits"</span>
+<a name="l00037"></a>00037 <span class="preprocessor"></span><span class="preprocessor">#define BP_NOISE_OUT_FILENAME             "out_bp_noise.fits"</span>
+<a name="l00038"></a>00038 <span class="preprocessor"></span>
+<a name="l00039"></a>00039 <span class="preprocessor">#define BP_NORM_INT_COL_TILT_CORR_OUT_FILENAME  "out_int_col_tilt_corr.fits"</span>
+<a name="l00040"></a>00040 <span class="preprocessor"></span>
+<a name="l00041"></a>00041 <span class="preprocessor">#define DARK_OUT_FILENAME        "out_dark.fits"</span>
+<a name="l00042"></a>00042 <span class="preprocessor"></span>
+<a name="l00043"></a>00043 <span class="preprocessor">#define LAMP_FLATS_OUT_FILENAME   "out_flat.fits"</span>
+<a name="l00044"></a>00044 <span class="preprocessor"></span><span class="preprocessor">#define LAMP_FLATS_OUT_BPMAP      "out_bpmask.fits"</span>
+<a name="l00045"></a>00045 <span class="preprocessor"></span><span class="preprocessor">#define BP_NORM_OUT_FILENAME      "out_bp_norm.fits"</span>
+<a name="l00046"></a>00046 <span class="preprocessor"></span><span class="preprocessor">#define MASTER_BPMAP_OUT_FILENAME "out_bpmap_sum.fits"</span>
+<a name="l00047"></a>00047 <span class="preprocessor"></span>
+<a name="l00048"></a>00048 <span class="preprocessor">#define DISTORTION_NS_OUT_FILENAME "out_ns_distortion.fits"</span>
+<a name="l00049"></a>00049 <span class="preprocessor"></span><span class="preprocessor">#define DISTORTION_OUT_FILENAME    "out_distortion.fits"</span>
+<a name="l00050"></a>00050 <span class="preprocessor"></span><span class="preprocessor">#define DISTORTION_STACK_OFF_OUT_FILENAME   "out_ns_stack_off.fits"</span>
+<a name="l00051"></a>00051 <span class="preprocessor"></span><span class="preprocessor">#define DISTORTION_STACK_ON_OUT_FILENAME    "out_ns_stack_on.fits"</span>
+<a name="l00052"></a>00052 <span class="preprocessor"></span>
+<a name="l00053"></a>00053 
+<a name="l00054"></a>00054 <span class="preprocessor">#define SLITPOS_OUT_FILENAME       "out_slit_pos.fits"</span>
+<a name="l00055"></a>00055 <span class="preprocessor"></span><span class="preprocessor">#define BP_DIST_OUT_FILENAME       "out_bp_dist.fits"</span>
+<a name="l00056"></a>00056 <span class="preprocessor"></span><span class="preprocessor">#define COEFF_OUT_FILENAME         "out_coef_params.fits"</span>
+<a name="l00057"></a>00057 <span class="preprocessor"></span><span class="preprocessor">#define NS_TEST_DISTANCES_OUT_FILENAME "out_distances.fits"</span>
+<a name="l00058"></a>00058 <span class="preprocessor"></span><span class="preprocessor">#define NS_TEST_OUT_FILENAME           "out_ns.fits"</span>
+<a name="l00059"></a>00059 <span class="preprocessor"></span>
+<a name="l00060"></a>00060 
+<a name="l00061"></a>00061 <span class="preprocessor">#define WAVECAL_OUT_FILENAME              "out_wavemap_ima.fits"</span>
+<a name="l00062"></a>00062 <span class="preprocessor"></span><span class="preprocessor">#define WAVECAL_FIT_PARAMS_OUT_FILENAME   "out_fit_params.fits"</span>
+<a name="l00063"></a>00063 <span class="preprocessor"></span><span class="preprocessor">#define WAVECAL_FIT_PARAMS_OUT_FILEASCII   "out_fit_params.ascii"</span>
+<a name="l00064"></a>00064 <span class="preprocessor"></span><span class="preprocessor">#define WAVECAL_COEFF_SLIT_OUT_FILENAME   "outCoeffsSlit.fits"</span>
+<a name="l00065"></a>00065 <span class="preprocessor"></span><span class="preprocessor">#define WAVECAL_SLIT_POS_OUT_FILENAME     "out_slitpos.fits"</span>
+<a name="l00066"></a>00066 <span class="preprocessor"></span><span class="preprocessor">#define WAVECAL_RESAMPLED_OUT_FILENAME   "out_resampled_arclamp.fits"</span>
+<a name="l00067"></a>00067 <span class="preprocessor"></span>
+<a name="l00068"></a>00068 
+<a name="l00069"></a>00069 <span class="preprocessor">#define STACKED_OUT_FILENAME                 "out_stack.fits"</span>
+<a name="l00070"></a>00070 <span class="preprocessor"></span><span class="preprocessor">#define STACK_MFLAT_DIST_OUT_FILENAME        "out_stack_mflat_dist.fits"</span>
+<a name="l00071"></a>00071 <span class="preprocessor"></span><span class="preprocessor">#define STACK_MFLAT_DITHER_DIST_OUT_FILENAME "out_stack_mflat_dither_dist.fits"</span>
+<a name="l00072"></a>00072 <span class="preprocessor"></span>
+<a name="l00073"></a>00073 <span class="preprocessor">#define STACK_SKY_DIST_OUT_FILENAME             "out_sky_stack_dist"</span>
+<a name="l00074"></a>00074 <span class="preprocessor"></span>
+<a name="l00075"></a>00075 <span class="preprocessor">#define ESTIMATED_SLITLETS_DISTANCE 64.</span>
+<a name="l00076"></a>00076 <span class="preprocessor"></span>
+<a name="l00077"></a>00077 
+<a name="l00078"></a>00078 <span class="preprocessor">#define PSF_OUT_FILENAME                   "out_psf.fits"</span>
+<a name="l00079"></a>00079 <span class="preprocessor"></span><span class="preprocessor">#define PSF_MED_CUB_025_FILENAME           "out_med_cube_025_mas.fits"</span>
+<a name="l00080"></a>00080 <span class="preprocessor"></span><span class="preprocessor">#define PSF_MED_CUB_100_FILENAME           "out_med_cube_100_mas.fits"</span>
+<a name="l00081"></a>00081 <span class="preprocessor"></span><span class="preprocessor">#define PSF_AO_PERFORMANCE_OUT_FILENAME    "out_ao_performance.fits"</span>
+<a name="l00082"></a>00082 <span class="preprocessor"></span><span class="preprocessor">#define PSF_ENC_ENERGY_OUT_FILENAME        "out_encircled_energy.fits"</span>
+<a name="l00083"></a>00083 <span class="preprocessor"></span><span class="preprocessor">#define STDSTAR_OUT_FILENAME               "out_starspectrum.fits"</span>
+<a name="l00084"></a>00084 <span class="preprocessor"></span><span class="preprocessor">#define STDSTAR_OUT_TABLE                  "out_std_star_spectrum.fits"</span>
+<a name="l00085"></a>00085 <span class="preprocessor"></span><span class="preprocessor">#define STDSTAR_CONV_OUT_FILENAME          "out_convfactor.fits"</span>
+<a name="l00086"></a>00086 <span class="preprocessor"></span><span class="preprocessor">#define SKYPMAP_OUT_FILENAME               "out_skymap.fits"</span>
+<a name="l00087"></a>00087 <span class="preprocessor"></span><span class="preprocessor">#define NSLITLETS               32</span>
+<a name="l00088"></a>00088 <span class="preprocessor"></span>
+<a name="l00089"></a>00089 <span class="preprocessor">#define OBJNOD_OUT_BPMAP        "out_objnod_bpmap.fits"</span>
+<a name="l00090"></a>00090 <span class="preprocessor"></span><span class="preprocessor">#define OBJNOD_OUT_MED_CUBE     "out_objnod_med_cube.fits"</span>
+<a name="l00091"></a>00091 <span class="preprocessor"></span><span class="preprocessor">#define OBJNOD_OUT_FILENAME     "out_objnod.fits"</span>
+<a name="l00092"></a>00092 <span class="preprocessor"></span>
+<a name="l00093"></a>00093 <span class="preprocessor">#define OBJNOD_OUT_MFLAT_CUBE_FILENAME     "out_mflat_cube.fits"</span>
+<a name="l00094"></a>00094 <span class="preprocessor"></span><span class="preprocessor">#define OBJNOD_OUT_MFLAT_AVG_FILENAME      "out_mflat_avg.fits"</span>
+<a name="l00095"></a>00095 <span class="preprocessor"></span><span class="preprocessor">#define OBJNOD_OUT_MFLAT_MED_FILENAME      "out_mflat_med.fits"</span>
+<a name="l00096"></a>00096 <span class="preprocessor"></span><span class="preprocessor">#define RESAMPLED_OUT_OBJ_FILENAME         "out_resampled_obj"</span>
+<a name="l00097"></a>00097 <span class="preprocessor"></span><span class="preprocessor">#define RESAMPLED_OUT_SKY_FILENAME         "out_resampled_sky"</span>
+<a name="l00098"></a>00098 <span class="preprocessor"></span><span class="preprocessor">#define RESAMPLED_OUT_FLAT_FILENAME        "out_resampled_flat"</span>
+<a name="l00099"></a>00099 <span class="preprocessor"></span>
+<a name="l00100"></a>00100 
+<a name="l00101"></a>00101 <span class="preprocessor">#define STDSTAR_OUT_MED_CUBE    "out_stdstar_med_cube.fits"</span>
+<a name="l00102"></a>00102 <span class="preprocessor"></span>
+<a name="l00103"></a>00103 <span class="preprocessor">#define FOCUS_OUT_FILENAME             "out_focus.fits"</span>
+<a name="l00104"></a>00104 <span class="preprocessor"></span><span class="preprocessor">#define FOCUS_FITPAR_OUT_FILENAME      "out_focus_fitpar.fits"</span>
+<a name="l00105"></a>00105 <span class="preprocessor"></span><span class="preprocessor">#define FOCUS_GAUSSPLOT_OUT_FILENAME   "out_focus_gaussplot.fits"</span>
+<a name="l00106"></a>00106 <span class="preprocessor"></span>
+<a name="l00107"></a>00107 <span class="preprocessor">#define LAMPSPEC_OUT_FILENAME "out_lampspec.fits"</span>
+<a name="l00108"></a>00108 <span class="preprocessor"></span><span class="preprocessor">#define TWIFLAT_OUT_FILENAME  "out_twiflat.fits"</span>
+<a name="l00109"></a>00109 <span class="preprocessor"></span><span class="preprocessor">#define SKYSPIDER_OUT_FILENAME "out_objnod.fits"</span>
+<a name="l00110"></a>00110 <span class="preprocessor"></span><span class="preprocessor">#define SKYSPIDER_MASK_OUT_FILENAME "out_mask_cube_spider.fits"</span>
+<a name="l00111"></a>00111 <span class="preprocessor"></span><span class="preprocessor">#define EFFICIENCY_FILENAME "out_efficiency.fits"</span>
+<a name="l00112"></a>00112 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__image__ops_8c_source.html b/html/sinfo__image__ops_8c_source.html
new file mode 100644
index 0000000..c0dd3c7
--- /dev/null
+++ b/html/sinfo__image__ops_8c_source.html
@@ -0,0 +1,3117 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_image_ops.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_image_ops.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*************************************************************************</span>
+<a name="l00020"></a>00020 <span class="comment">* M.P.E. - SPIFFI project</span>
+<a name="l00021"></a>00021 <span class="comment">*</span>
+<a name="l00022"></a>00022 <span class="comment">*</span>
+<a name="l00023"></a>00023 <span class="comment">*</span>
+<a name="l00024"></a>00024 <span class="comment">* who       when      what</span>
+<a name="l00025"></a>00025 <span class="comment">* --------  --------  ----------------------------------------------</span>
+<a name="l00026"></a>00026 <span class="comment">* rabuter 2004-12-03 support one dimensional image in sinfo_shiftImage</span>
+<a name="l00027"></a>00027 <span class="comment">* schreib  23/05/00  created</span>
+<a name="l00028"></a>00028 <span class="comment">*/</span>
+<a name="l00029"></a>00029 
+<a name="l00030"></a>00030 <span class="comment">/************************************************************************</span>
+<a name="l00031"></a>00031 <span class="comment">*   NAME</span>
+<a name="l00032"></a>00032 <span class="comment">*        sinfo_image_ops.c -</span>
+<a name="l00033"></a>00033 <span class="comment">*        image arithmetic routines</span>
+<a name="l00034"></a>00034 <span class="comment">*</span>
+<a name="l00035"></a>00035 <span class="comment">*   SYNOPSIS</span>
+<a name="l00036"></a>00036 <span class="comment">*   #include "sinfo_image_ops.h"</span>
+<a name="l00037"></a>00037 <span class="comment">*</span>
+<a name="l00038"></a>00038 <span class="comment">*   1) Vector * sinfo_new_mean_of_columns( cpl_image *im )</span>
+<a name="l00039"></a>00039 <span class="comment">*   2) Vector * sinfo_new_clean_mean_of_columns( cpl_image *im,</span>
+<a name="l00040"></a>00040 <span class="comment">*                                   double lo_reject,</span>
+<a name="l00041"></a>00041 <span class="comment">*                                   double hi_reject)</span>
+<a name="l00042"></a>00042 <span class="comment">*   3) cpl_image * sinfo_new_div_image_by_row( cpl_image *im, Vector *row )</span>
+<a name="l00043"></a>00043 <span class="comment">*   4) cpl_image * sinfo_new_mult_row_to_image( cpl_image *im, Vector *row )</span>
+<a name="l00044"></a>00044 <span class="comment">*   5) cpl_image * sinfo_new_col_tilt ( cpl_image * image, float sigmaFactor )</span>
+<a name="l00045"></a>00045 <span class="comment">*   6) cpl_image * sinfo_new_median_image( cpl_image * im, float fmedian )</span>
+<a name="l00046"></a>00046 <span class="comment">*   7) cpl_image * sinfo_new_compare_images( cpl_image * im1,</span>
+<a name="l00047"></a>00047 <span class="comment">                                             cpl_image * im2,</span>
+<a name="l00048"></a>00048 <span class="comment">                                             cpl_image * origim )</span>
+<a name="l00049"></a>00049 <span class="comment">*   8) cpl_image * sinfo_new_thresh_image ( cpl_image * im,</span>
+<a name="l00050"></a>00050 <span class="comment">                                            float lo_cut, float hi_cut )</span>
+<a name="l00051"></a>00051 <span class="comment">*   9) pixel_map * sinfo_new_promote_image_to_pixelmap ( cpl_image * im )</span>
+<a name="l00052"></a>00052 <span class="comment">*  10) cpl_image * sinfo_new_promote_image_to_mask ( cpl_image * im,</span>
+<a name="l00053"></a>00053 <span class="comment">                                                     int * n_badpixels )</span>
+<a name="l00054"></a>00054 <span class="comment">*  11) cpl_image * sinfo_new_mult_image_by_mask ( cpl_image * im,</span>
+<a name="l00055"></a>00055 <span class="comment">                                                  cpl_image * mask )</span>
+<a name="l00056"></a>00056 <span class="comment">*  12) cpl_image * sinfo_new_interpol_image ( cpl_image * im,</span>
+<a name="l00057"></a>00057 <span class="comment">*                                 cpl_image * mask,</span>
+<a name="l00058"></a>00058 <span class="comment">*                                 int        max_radius,</span>
+<a name="l00059"></a>00059 <span class="comment">*                                 int        n_pixels )</span>
+<a name="l00060"></a>00060 <span class="comment">*  13) cpl_image * sinfo_interpol_source_image ( cpl_image * im,</span>
+<a name="l00061"></a>00061 <span class="comment">*                                       cpl_image * mask,</span>
+<a name="l00062"></a>00062 <span class="comment">*                                       int        max_rad,</span>
+<a name="l00063"></a>00063 <span class="comment">*                                       float   ** slit_edges )</span>
+<a name="l00064"></a>00064 <span class="comment">*  14) cpl_image * sinfo_new_stack_row_to_image ( Vector * row, int ly )</span>
+<a name="l00065"></a>00065 <span class="comment">*  15) Stats * sinfo_new_image_stats_on_rectangle ( cpl_image * im,</span>
+<a name="l00066"></a>00066 <span class="comment">*                                      float      loReject,</span>
+<a name="l00067"></a>00067 <span class="comment">*                                      float      hiReject,</span>
+<a name="l00068"></a>00068 <span class="comment">*                                      int        llx,</span>
+<a name="l00069"></a>00069 <span class="comment">*                                      int        lly,</span>
+<a name="l00070"></a>00070 <span class="comment">*                                      int        urx,</span>
+<a name="l00071"></a>00071 <span class="comment">*                                      int        ury )</span>
+<a name="l00072"></a>00072 <span class="comment">*  16) cpl_image * sinfo_new_normalize_to_central_pixel ( cpl_image * image )</span>
+<a name="l00073"></a>00073 <span class="comment">*  17) cpl_image *</span>
+<a name="l00074"></a>00074 <span class="comment">*      sinfo_new_shift_image(</span>
+<a name="l00075"></a>00075 <span class="comment">*            cpl_image    *    image_in,</span>
+<a name="l00076"></a>00076 <span class="comment">*            double           shift_x,</span>
+<a name="l00077"></a>00077 <span class="comment">*            double           shift_y,</span>
+<a name="l00078"></a>00078 <span class="comment">*            double       *   interp_kernel)</span>
+<a name="l00079"></a>00079 <span class="comment">*  18) cpl_image * sinfo_new_combine_masks ( cpl_image * firstMask,</span>
+<a name="l00080"></a>00080 <span class="comment">                                             cpl_image * secondMask )</span>
+<a name="l00081"></a>00081 <span class="comment">*  19) cpl_image * sinfo_new_slice_cube (cpl_imagelist * cube, int x, int y )</span>
+<a name="l00082"></a>00082 <span class="comment">*  20) cpl_image * sinfo_new_div_images_robust ( cpl_image * im1,</span>
+<a name="l00083"></a>00083 <span class="comment">                                                 cpl_image * im2 )</span>
+<a name="l00084"></a>00084 <span class="comment">*</span>
+<a name="l00085"></a>00085 <span class="comment">*</span>
+<a name="l00086"></a>00086 <span class="comment">*   DESCRIPTION</span>
+<a name="l00087"></a>00087 <span class="comment">*   1) takes the average of each image column</span>
+<a name="l00088"></a>00088 <span class="comment">*   2) takes the average of each image column by sorting the</span>
+<a name="l00089"></a>00089 <span class="comment">*      column values and rejecting the given percentage of</span>
+<a name="l00090"></a>00090 <span class="comment">*      the highest and lowest values  [0...1]</span>
+<a name="l00091"></a>00091 <span class="comment">*   3) divides each image column by a row value</span>
+<a name="l00092"></a>00092 <span class="comment">*   4) multiplies each image column with a row value</span>
+<a name="l00093"></a>00093 <span class="comment">*   5) first calculates statistics for each column of an image.</span>
+<a name="l00094"></a>00094 <span class="comment">*      sinfo_median value and standard deviation of columns are de-</span>
+<a name="l00095"></a>00095 <span class="comment">*      termined, blank values are excluded. Fits a straight</span>
+<a name="l00096"></a>00096 <span class="comment">*      line through the pixel values of each column and subtracts</span>
+<a name="l00097"></a>00097 <span class="comment">*      the fit in order to remove the tilt of each column.</span>
+<a name="l00098"></a>00098 <span class="comment">*      Only those pixels are used for the fit that are within</span>
+<a name="l00099"></a>00099 <span class="comment">*      a defined factor of sigma noise limit. The noise is</span>
+<a name="l00100"></a>00100 <span class="comment">*      calculated from pixels between the 10percentil and</span>
+<a name="l00101"></a>00101 <span class="comment">*      90percentil points.</span>
+<a name="l00102"></a>00102 <span class="comment">*      if the straight line could not be determined, the sinfo_median</span>
+<a name="l00103"></a>00103 <span class="comment">*      of the column is subtracted from the column</span>
+<a name="l00104"></a>00104 <span class="comment">*   6) sinfo_median filter, calculates the sinfo_median for an image</span>
+<a name="l00105"></a>00105 <span class="comment">*      by using the 8 closest pixels to each pixel.</span>
+<a name="l00106"></a>00106 <span class="comment">*      The values in the output image are determined according</span>
+<a name="l00107"></a>00107 <span class="comment">*      to the values of the input parameter.</span>
+<a name="l00108"></a>00108 <span class="comment">*      If fmedian = 0: always replace by sinfo_median</span>
+<a name="l00109"></a>00109 <span class="comment">*      if fmedian < 0: replace by sinfo_median if |pixel - sinfo_median| ></span>
+<a name="l00110"></a>00110 <span class="comment">*                      -fmedian</span>
+<a name="l00111"></a>00111 <span class="comment">*      if fmedian > 0: replace by sinfo_median (fmedian as a factor of</span>
+<a name="l00112"></a>00112 <span class="comment">*                      the square root of the sinfo_median itself)</span>
+<a name="l00113"></a>00113 <span class="comment">*                      if |pixel - median| >= fmedian * sqrt ( median )</span>
+<a name="l00114"></a>00114 <span class="comment">*                      This can be used to consider photon noise.</span>
+<a name="l00115"></a>00115 <span class="comment">*                      This considers a dependence of the differences on the</span>
+<a name="l00116"></a>00116 <span class="comment">*                      pixel values themselves.</span>
+<a name="l00117"></a>00117 <span class="comment">*   7) if a pixel value of one image (im1) equals</span>
+<a name="l00118"></a>00118 <span class="comment">*      the pixel value of the other image keep the</span>
+<a name="l00119"></a>00119 <span class="comment">*      pixel value of the original image otherwise replace</span>
+<a name="l00120"></a>00120 <span class="comment">*      it with ZEROs</span>
+<a name="l00121"></a>00121 <span class="comment">*   8) simple search for static bad pixels for a flat field</span>
+<a name="l00122"></a>00122 <span class="comment">*      or sinfo_dark frame, values below and above the threshold</span>
+<a name="l00123"></a>00123 <span class="comment">*      values are set to ZERO.</span>
+<a name="l00124"></a>00124 <span class="comment">*   9) changes an image with ZERO indicated bad pixels to</span>
+<a name="l00125"></a>00125 <span class="comment">*      a bad pixel map.</span>
+<a name="l00126"></a>00126 <span class="comment">*  10) changes an image with ZERO indicated bad pixels to</span>
+<a name="l00127"></a>00127 <span class="comment">*      a bad pixel mask image, that means the returned</span>
+<a name="l00128"></a>00128 <span class="comment">*      image has values 1 at positions of good pixels and</span>
+<a name="l00129"></a>00129 <span class="comment">*      ZEROs at positions of bad pixels.</span>
+<a name="l00130"></a>00130 <span class="comment">*  11) changes an image to an image that has ZERO indicated</span>
+<a name="l00131"></a>00131 <span class="comment">*      static bad pixels</span>
+<a name="l00132"></a>00132 <span class="comment">*  12) interpolates all bad pixels indicated by the bad pixel mask.</span>
+<a name="l00133"></a>00133 <span class="comment">*      Therefore, the mean of at least 2 valid values of</span>
+<a name="l00134"></a>00134 <span class="comment">*      the nearest 8 neighbors is taken. If too much</span>
+<a name="l00135"></a>00135 <span class="comment">*      neighbors are also bad pixels</span>
+<a name="l00136"></a>00136 <span class="comment">*      the neighbor radius is increased to a maximum of</span>
+<a name="l00137"></a>00137 <span class="comment">*      max_radius until n_pixels valid pixels are found.</span>
+<a name="l00138"></a>00138 <span class="comment">*      The valid neighbors are searched by going through</span>
+<a name="l00139"></a>00139 <span class="comment">*      the columns and rows around the central square that</span>
+<a name="l00140"></a>00140 <span class="comment">*      was already searched.</span>
+<a name="l00141"></a>00141 <span class="comment">*      The bad pixel is interpolated by the mean of these</span>
+<a name="l00142"></a>00142 <span class="comment">*      valid pixels (less than 9) or by the sinfo_median of them</span>
+<a name="l00143"></a>00143 <span class="comment">*      (more than 8).</span>
+<a name="l00144"></a>00144 <span class="comment">*  13) interpolates all bad pixels indicated by the bad pixel mask.</span>
+<a name="l00145"></a>00145 <span class="comment">*      Therefore, the mean of the nearest 4 neighbors is taken,</span>
+<a name="l00146"></a>00146 <span class="comment">*      two in spectral direction and 2 in spatial direction.</span>
+<a name="l00147"></a>00147 <span class="comment">*      The routine cares about the image and slitlet edges.</span>
+<a name="l00148"></a>00148 <span class="comment">*      If there are no good pixel found within the nearest neighbors,</span>
+<a name="l00149"></a>00149 <span class="comment">*      the next 4 nearest neighbors in spatial and spectral direction</span>
+<a name="l00150"></a>00150 <span class="comment">*      are searched for valid pixels until a limit of max_rad.</span>
+<a name="l00151"></a>00151 <span class="comment">*      A maximum of 4 valid pixels are used for interpolation by their mean.</span>
+<a name="l00152"></a>00152 <span class="comment">*  14) stack a given image row to build a whole image</span>
+<a name="l00153"></a>00153 <span class="comment">*  15) computes the mean and standard deviation of</span>
+<a name="l00154"></a>00154 <span class="comment">*      a given rectangle on an image by leaving the extreme</span>
+<a name="l00155"></a>00155 <span class="comment">*      intensity values.</span>
+<a name="l00156"></a>00156 <span class="comment">*  16) normalizes a raw flatfield image by dividing by the median of the</span>
+<a name="l00157"></a>00157 <span class="comment">       central spectral pixels to produce a master flatfield</span>
+<a name="l00158"></a>00158 <span class="comment">*  17) This function is a conversion to CPL of the ECLIPSE function</span>
+<a name="l00159"></a>00159 <span class="comment">       shift_image()</span>
+<a name="l00160"></a>00160 <span class="comment">*      but slightly changed. If a blank (ZERO) pixel appears the blank pixel</span>
+<a name="l00161"></a>00161 <span class="comment">*      is shifted but preserved as blank.</span>
+<a name="l00162"></a>00162 <span class="comment">*      If a blank (ZERO) pixel appears within the</span>
+<a name="l00163"></a>00163 <span class="comment">*      interpolation kernel the blank pixel is set to 0.</span>
+<a name="l00164"></a>00164 <span class="comment">*</span>
+<a name="l00165"></a>00165 <span class="comment">*      This function shifts an image by a non-integer offset, using</span>
+<a name="l00166"></a>00166 <span class="comment">*      interpolation. You can either generate an interpolation kernel once and</span>
+<a name="l00167"></a>00167 <span class="comment">*      pass it to this function, or let it generate a default kernel. In the</span>
+<a name="l00168"></a>00168 <span class="comment">*      former case, use sinfo_generate_interpolation_kernel() to generate an</span>
+<a name="l00169"></a>00169 <span class="comment">*      appropriate kernel. In the latter case, pass NULL as last argument. A</span>
+<a name="l00170"></a>00170 <span class="comment">*      default interpolation kernel is then generated then discarded</span>
+<a name="l00171"></a>00171 <span class="comment">       before this function returns.</span>
+<a name="l00172"></a>00172 <span class="comment">*</span>
+<a name="l00173"></a>00173 <span class="comment">*      The returned image is a newly allocated object, it must be deallocated</span>
+<a name="l00174"></a>00174 <span class="comment">*      using cpl_image_delete().</span>
+<a name="l00175"></a>00175 <span class="comment">*  18) combines two bad pixel mask to one using an or relation</span>
+<a name="l00176"></a>00176 <span class="comment">*  19) slices a data cube in x or y direction</span>
+<a name="l00177"></a>00177 <span class="comment">*  20) divides two images by considering blanks and</span>
+<a name="l00178"></a>00178 <span class="comment">*      calculating first 1/im2 by</span>
+<a name="l00179"></a>00179 <span class="comment">*      cutting the very high values and setting to 1,</span>
+<a name="l00180"></a>00180 <span class="comment">*      then multiplying im1 * 1/im2.</span>
+<a name="l00181"></a>00181 <span class="comment">*</span>
+<a name="l00182"></a>00182 <span class="comment">*   FILES</span>
+<a name="l00183"></a>00183 <span class="comment">*</span>
+<a name="l00184"></a>00184 <span class="comment">*   ENVIRONMENT</span>
+<a name="l00185"></a>00185 <span class="comment">*</span>
+<a name="l00186"></a>00186 <span class="comment">*   RETURN VALUES</span>
+<a name="l00187"></a>00187 <span class="comment">*</span>
+<a name="l00188"></a>00188 <span class="comment">*   CAUTIONS</span>
+<a name="l00189"></a>00189 <span class="comment">*</span>
+<a name="l00190"></a>00190 <span class="comment">*   EXAMPLES</span>
+<a name="l00191"></a>00191 <span class="comment">*</span>
+<a name="l00192"></a>00192 <span class="comment">*   SEE ALSO</span>
+<a name="l00193"></a>00193 <span class="comment">*</span>
+<a name="l00194"></a>00194 <span class="comment">*   BUGS</span>
+<a name="l00195"></a>00195 <span class="comment">*</span>
+<a name="l00196"></a>00196 <span class="comment">*------------------------------------------------------------------------</span>
+<a name="l00197"></a>00197 <span class="comment">*/</span>
+<a name="l00198"></a>00198 
+<a name="l00199"></a>00199 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00200"></a>00200 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00201"></a>00201 <span class="preprocessor">#endif</span>
+<a name="l00202"></a>00202 <span class="preprocessor"></span><span class="preprocessor">#include "sinfo_vltPort.h"</span>
+<a name="l00203"></a>00203 
+<a name="l00204"></a>00204 <span class="comment">/*</span>
+<a name="l00205"></a>00205 <span class="comment"> * System Headers</span>
+<a name="l00206"></a>00206 <span class="comment"> */</span>
+<a name="l00207"></a>00207 <span class="preprocessor">#include <errno.h></span>
+<a name="l00208"></a>00208 <span class="comment">/*</span>
+<a name="l00209"></a>00209 <span class="comment"> * Local Headers</span>
+<a name="l00210"></a>00210 <span class="comment"> */</span>
+<a name="l00211"></a>00211 
+<a name="l00212"></a>00212 <span class="preprocessor">#include "sinfo_image_ops.h"</span>
+<a name="l00213"></a>00213 <span class="preprocessor">#include "sinfo_error.h"</span>
+<a name="l00214"></a>00214 <span class="preprocessor">#include "sinfo_resampling.h"</span>
+<a name="l00215"></a>00215 <span class="preprocessor">#include "sinfo_local_types.h"</span>
+<a name="l00216"></a>00216 <span class="preprocessor">#include "sinfo_utils_wrappers.h"</span>
+<a name="l00225"></a>00225 <span class="keyword">static</span> cpl_image *
+<a name="l00226"></a>00226 sinfo_gen_lowpass(<span class="keyword">const</span> <span class="keywordtype">int</span> xs,
+<a name="l00227"></a>00227                   <span class="keyword">const</span> <span class="keywordtype">int</span> ys,
+<a name="l00228"></a>00228                   <span class="keyword">const</span> <span class="keywordtype">double</span> sigma_x,
+<a name="l00229"></a>00229                   <span class="keyword">const</span> <span class="keywordtype">double</span> sigma_y);
+<a name="l00230"></a>00230 
+<a name="l00231"></a>00231 
+<a name="l00232"></a>00232 <span class="keyword">static</span> <span class="keywordtype">void</span> quicksort_int(<span class="keywordtype">int</span>* data, <span class="keywordtype">int</span> left, <span class="keywordtype">int</span> right);
+<a name="l00235"></a>00235 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00236"></a>00236 <span class="comment"> *                            Function codes</span>
+<a name="l00237"></a>00237 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00238"></a>00238 
+<a name="l00239"></a>00239 
+<a name="l00240"></a>00240 
+<a name="l00252"></a>00252 cpl_error_code
+<a name="l00253"></a>00253 sinfo_image_line_corr(<span class="keyword">const</span> <span class="keywordtype">int</span> width,
+<a name="l00254"></a>00254                 <span class="keyword">const</span> <span class="keywordtype">int</span> filt_rad,
+<a name="l00255"></a>00255                 <span class="keyword">const</span> <span class="keywordtype">int</span> kappa,
+<a name="l00256"></a>00256                 cpl_image* ima_in,
+<a name="l00257"></a>00257                 cpl_image** ima_out)
+<a name="l00258"></a>00258 {
+<a name="l00259"></a>00259 
+<a name="l00260"></a>00260   cpl_image* mask=NULL;
+<a name="l00261"></a>00261 
+<a name="l00262"></a>00262   cpl_image* ima_backpix=NULL;
+<a name="l00263"></a>00263   cpl_image* ima_backpos=NULL;
+<a name="l00264"></a>00264   cpl_image* ima_ybackpix=NULL;
+<a name="l00265"></a>00265   cpl_image* ima_diffbackpix=NULL;
+<a name="l00266"></a>00266   cpl_image* ima_filt=NULL;
+<a name="l00267"></a>00267   cpl_image* ima = NULL;
+<a name="l00268"></a>00268 
+<a name="l00269"></a>00269   cpl_matrix* filter=NULL;
+<a name="l00270"></a>00270   <span class="comment">//cpl_mask* bpm_good=NULL; //Is this really useful?</span>
+<a name="l00271"></a>00271   cpl_mask* bpm_bad=NULL;
+<a name="l00272"></a>00272 
+<a name="l00273"></a>00273   <span class="keywordtype">int</span> sx=0;
+<a name="l00274"></a>00274   <span class="keywordtype">int</span> sy=0;
+<a name="l00275"></a>00275   <span class="keywordtype">int</span> i=0;
+<a name="l00276"></a>00276   <span class="keywordtype">int</span> j=0;
+<a name="l00277"></a>00277   <span class="keywordtype">int</span> k=0;
+<a name="l00278"></a>00278   <span class="keywordtype">double</span> med_back=0;
+<a name="l00279"></a>00279   <span class="keywordtype">double</span> sigma_back=0;
+<a name="l00280"></a>00280   <span class="keywordtype">double</span> medvalue=0;
+<a name="l00281"></a>00281 
+<a name="l00282"></a>00282   <span class="keywordtype">float</span>* pima=NULL;
+<a name="l00283"></a>00283   <span class="keywordtype">float</span>* ppix=NULL;
+<a name="l00284"></a>00284   <span class="keywordtype">float</span>* pmsk=NULL;
+<a name="l00285"></a>00285   <span class="keywordtype">int</span>* ppos=NULL;
+<a name="l00286"></a>00286   <span class="keywordtype">int</span>* pbackpix=NULL;
+<a name="l00287"></a>00287   cpl_binary* pbin=NULL;
+<a name="l00288"></a>00288   <span class="keywordtype">double</span> tot=0;
+<a name="l00289"></a>00289   <span class="keywordtype">double</span> mean=0;
+<a name="l00290"></a>00290   <span class="keywordtype">int</span>* ybad=NULL;
+<a name="l00291"></a>00291 
+<a name="l00292"></a>00292   <span class="keywordtype">int</span> nrow=0;
+<a name="l00293"></a>00293   <span class="keywordtype">int</span> nbad=0;
+<a name="l00294"></a>00294   <span class="keywordtype">int</span> yval=0;
+<a name="l00295"></a>00295   <span class="keywordtype">int</span> yprev=0;
+<a name="l00296"></a>00296 
+<a name="l00297"></a>00297 
+<a name="l00298"></a>00298   check_nomsg(sx=cpl_image_get_size_x(ima_in));
+<a name="l00299"></a>00299   check_nomsg(sy=cpl_image_get_size_y(ima_in));
+<a name="l00300"></a>00300   check_nomsg(*ima_out=cpl_image_duplicate(ima_in));
+<a name="l00301"></a>00301 
+<a name="l00302"></a>00302   check_nomsg(mask=cpl_image_new(sx,sy,CPL_TYPE_FLOAT));
+<a name="l00303"></a>00303   check_nomsg(pmsk=cpl_image_get_data_float(mask));
+<a name="l00304"></a>00304 
+<a name="l00305"></a>00305   <span class="keywordflow">for</span>(i=0;i<width;i++) {
+<a name="l00306"></a>00306     <span class="keywordflow">for</span>(j=width;j<sy-width;j++) {
+<a name="l00307"></a>00307       pmsk[j*sx+i]=1;
+<a name="l00308"></a>00308     }
+<a name="l00309"></a>00309   }
+<a name="l00310"></a>00310 
+<a name="l00311"></a>00311   <span class="keywordflow">for</span>(i=sx-width;i<sx;i++) {
+<a name="l00312"></a>00312     <span class="keywordflow">for</span>(j=width;j<sy-width;j++) {
+<a name="l00313"></a>00313       pmsk[j*sx+i]=1;
+<a name="l00314"></a>00314     }
+<a name="l00315"></a>00315   }
+<a name="l00316"></a>00316   sinfo_free_image(&mask); <span class="comment">//is mask needed?</span>
+<a name="l00317"></a>00317 
+<a name="l00318"></a>00318 
+<a name="l00319"></a>00319   nrow=2*width*(sy-2*width);
+<a name="l00320"></a>00320   check_nomsg(ima_backpix=cpl_image_new(nrow,1,CPL_TYPE_FLOAT));
+<a name="l00321"></a>00321   check_nomsg(ima_backpos=cpl_image_new(nrow,1,CPL_TYPE_INT));
+<a name="l00322"></a>00322 
+<a name="l00323"></a>00323   check_nomsg(pima=cpl_image_get_data_float(ima_in));
+<a name="l00324"></a>00324   check_nomsg(ppix=cpl_image_get_data_float(ima_backpix));
+<a name="l00325"></a>00325   check_nomsg(ppos=cpl_image_get_data_int(ima_backpos));
+<a name="l00326"></a>00326 
+<a name="l00327"></a>00327   k=0;
+<a name="l00328"></a>00328   <span class="keywordflow">for</span>(i=0;i<width;i++) {
+<a name="l00329"></a>00329     <span class="keywordflow">for</span>(j=width;j<sy-width;j++) {
+<a name="l00330"></a>00330       ppix[k]=pima[j*sx+i];
+<a name="l00331"></a>00331       ppos[k]=j*sx+i;
+<a name="l00332"></a>00332       k++;
+<a name="l00333"></a>00333     }
+<a name="l00334"></a>00334   }
+<a name="l00335"></a>00335 
+<a name="l00336"></a>00336   <span class="keywordflow">for</span>(i=sx-width;i<sx;i++) {
+<a name="l00337"></a>00337     <span class="keywordflow">for</span>(j=width;j<sy-width;j++) {
+<a name="l00338"></a>00338       ppix[k]=pima[j*sx+i];
+<a name="l00339"></a>00339       ppos[k]=j*sx+i;
+<a name="l00340"></a>00340       k++;
+<a name="l00341"></a>00341     }
+<a name="l00342"></a>00342   }
+<a name="l00343"></a>00343 
+<a name="l00344"></a>00344   check_nomsg(ima_ybackpix=cpl_image_duplicate(ima_backpos));
+<a name="l00345"></a>00345   sinfo_free_image(&ima_backpos);
+<a name="l00346"></a>00346 
+<a name="l00347"></a>00347   check_nomsg(pbackpix=cpl_image_get_data_int(ima_ybackpix));
+<a name="l00348"></a>00348 
+<a name="l00349"></a>00349   check_nomsg(cpl_image_divide_scalar(ima_ybackpix,sx));
+<a name="l00350"></a>00350   check_nomsg(pbackpix=cpl_image_get_data_int(ima_ybackpix));
+<a name="l00351"></a>00351 
+<a name="l00352"></a>00352 
+<a name="l00353"></a>00353   check_nomsg(med_back=cpl_image_get_median(ima_backpix));
+<a name="l00354"></a>00354   check_nomsg(ima_diffbackpix=cpl_image_duplicate(ima_backpix));
+<a name="l00355"></a>00355   <span class="comment">//sinfo_msg("med_back=%g",med_back);</span>
+<a name="l00356"></a>00356   check_nomsg(cpl_image_subtract_scalar(ima_diffbackpix,med_back));
+<a name="l00357"></a>00357   <span class="comment">//check_nomsg(cpl_image_save(ima_diffbackpix,"ima_diff.fits",</span>
+<a name="l00358"></a>00358   <span class="comment">//                           CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT));</span>
+<a name="l00359"></a>00359 
+<a name="l00360"></a>00360   check_nomsg(filter=cpl_matrix_new(1,filt_rad));
+<a name="l00361"></a>00361   check_nomsg(cpl_matrix_fill(filter,1.));
+<a name="l00362"></a>00362   check_nomsg(ima_filt=sinfo_image_filter_median(ima_diffbackpix,filter));
+<a name="l00363"></a>00363   sinfoni_free_matrix(&filter);
+<a name="l00364"></a>00364   <span class="comment">//check_nomsg(cpl_image_save(ima_filt,"ima_filt.fits",CPL_BPP_IEEE_FLOAT,</span>
+<a name="l00365"></a>00365   <span class="comment">//             NULL,CPL_IO_DEFAULT));</span>
+<a name="l00366"></a>00366 
+<a name="l00367"></a>00367   
+<a name="l00368"></a>00368   check_nomsg(sigma_back=cpl_image_get_stdev(ima_filt));
+<a name="l00369"></a>00369   sinfo_free_image(&ima_filt);
+<a name="l00370"></a>00370 
+<a name="l00371"></a>00371   check_nomsg(ima=cpl_image_duplicate(ima_diffbackpix));
+<a name="l00372"></a>00372   sinfo_free_image(&ima_diffbackpix);
+<a name="l00373"></a>00373 
+<a name="l00374"></a>00374   check_nomsg(cpl_image_abs(ima));
+<a name="l00375"></a>00375   <span class="comment">//sinfo_msg("sigma_back=%g",sigma_back);</span>
+<a name="l00376"></a>00376 
+<a name="l00377"></a>00377   <span class="comment">//find good pixels</span>
+<a name="l00378"></a>00378   check_nomsg(bpm_bad=cpl_mask_threshold_image_create(ima,kappa*sigma_back,
+<a name="l00379"></a>00379                               SINFO_DBL_MAX));
+<a name="l00380"></a>00380   <span class="comment">/*check_nomsg(bpm_good=cpl_mask_threshold_image_create(ima,SINFO_DBL_MIN,</span>
+<a name="l00381"></a>00381 <span class="comment">                               kappa*sigma_back));</span>
+<a name="l00382"></a>00382 <span class="comment">  sinfo_free_mask(&bpm_good);</span>
+<a name="l00383"></a>00383 <span class="comment">*/</span>
+<a name="l00384"></a>00384   check_nomsg(cpl_image_reject_from_mask(ima_backpix,bpm_bad));
+<a name="l00385"></a>00385   check_nomsg(medvalue=cpl_image_get_median(ima_backpix));
+<a name="l00386"></a>00386   <span class="comment">//sinfo_msg("medvalue=%g",sigma_back);</span>
+<a name="l00387"></a>00387   check_nomsg(nbad=cpl_mask_count(bpm_bad));
+<a name="l00388"></a>00388   <span class="comment">//sinfo_msg("nbad=%d",nbad);</span>
+<a name="l00389"></a>00389   check_nomsg(cpl_image_reject_from_mask(ima_backpix,bpm_bad));
+<a name="l00390"></a>00390   sinfo_free_image(&ima_backpix);
+<a name="l00391"></a>00391 
+<a name="l00392"></a>00392   yprev=-1;
+<a name="l00393"></a>00393 
+<a name="l00394"></a>00394   check_nomsg(pbin=cpl_mask_get_data(bpm_bad));
+<a name="l00395"></a>00395   check_nomsg(pbackpix=cpl_image_get_data_int(ima_ybackpix));
+<a name="l00396"></a>00396   cpl_msg_debug(cpl_func, <span class="stringliteral">"%d lines detected"</span>, nbad);
+<a name="l00397"></a>00397   <span class="keywordflow">if</span>(nbad)
+<a name="l00398"></a>00398   {
+<a name="l00399"></a>00399 
+<a name="l00400"></a>00400       ybad = cpl_calloc(nbad,<span class="keyword">sizeof</span>(<span class="keywordtype">int</span>));
+<a name="l00401"></a>00401       k=0;
+<a name="l00402"></a>00402 
+<a name="l00403"></a>00403       <span class="keywordflow">for</span>(i=0;i<nrow;i++) {
+<a name="l00404"></a>00404         <span class="keywordflow">if</span>(pbin[i] == CPL_BINARY_1) {
+<a name="l00405"></a>00405            ybad[k]=pbackpix[i] + 1;
+<a name="l00406"></a>00406            k++;
+<a name="l00407"></a>00407         }
+<a name="l00408"></a>00408       }
+<a name="l00409"></a>00409       sinfo_free_mask(&bpm_bad);
+<a name="l00410"></a>00410       sinfo_free_image(&ima_ybackpix);
+<a name="l00411"></a>00411 
+<a name="l00412"></a>00412       quicksort_int(&(ybad[0]), 0, nbad-1);
+<a name="l00413"></a>00413       yprev=-1;
+<a name="l00414"></a>00414       <span class="keywordflow">for</span>(k=0;k<nbad;k++) {
+<a name="l00415"></a>00415         yval=ybad[k];
+<a name="l00416"></a>00416         <span class="keywordflow">if</span>(yval == yprev) {
+<a name="l00417"></a>00417           <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"skyp %d"</span>,yval);
+<a name="l00418"></a>00418         }
+<a name="l00419"></a>00419         <span class="keywordflow">else</span> {
+<a name="l00420"></a>00420           yprev=yval;
+<a name="l00421"></a>00421           <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"correct raw %d"</span>,yval);
+<a name="l00422"></a>00422           check_nomsg(tot=cpl_image_get_flux_window(ima_in,1,yval,width,yval));
+<a name="l00423"></a>00423           check_nomsg(tot+=cpl_image_get_flux_window(ima_in,sx-width+1,
+<a name="l00424"></a>00424                             yval,sx,yval));
+<a name="l00425"></a>00425           mean=tot/(2. * width);
+<a name="l00426"></a>00426           check_nomsg(pima=cpl_image_get_data_float(*ima_out));
+<a name="l00427"></a>00427           <span class="keywordflow">for</span>(i=width;i<sx-width;i++) {
+<a name="l00428"></a>00428         pima[i+(yval-1)*sx]+=(<span class="keywordtype">float</span>)(mean-medvalue);
+<a name="l00429"></a>00429           }
+<a name="l00430"></a>00430 
+<a name="l00431"></a>00431         }
+<a name="l00432"></a>00432       }
+<a name="l00433"></a>00433   }
+<a name="l00434"></a>00434 
+<a name="l00435"></a>00435 
+<a name="l00436"></a>00436  cleanup:
+<a name="l00437"></a>00437 
+<a name="l00438"></a>00438   sinfo_free_image(&mask); <span class="comment">//is mask needed?</span>
+<a name="l00439"></a>00439   sinfo_free_image(&ima_backpos);
+<a name="l00440"></a>00440   sinfoni_free_matrix(&filter);
+<a name="l00441"></a>00441   sinfo_free_image(&ima_filt);
+<a name="l00442"></a>00442   sinfo_free_image(&ima_diffbackpix);
+<a name="l00443"></a>00443 <span class="comment">//  sinfo_free_mask(&bpm_good);</span>
+<a name="l00444"></a>00444   sinfo_free_image(&ima_backpix);
+<a name="l00445"></a>00445   sinfo_free_mask(&bpm_bad);
+<a name="l00446"></a>00446   sinfo_free_image(&ima_ybackpix);
+<a name="l00447"></a>00447   cpl_image_delete(ima);
+<a name="l00448"></a>00448   cpl_free(ybad);
+<a name="l00449"></a>00449   <span class="keywordflow">return</span> cpl_error_get_code();
+<a name="l00450"></a>00450 
+<a name="l00451"></a>00451 }
+<a name="l00452"></a>00452 
+<a name="l00453"></a>00453 
+<a name="l00462"></a>00462 <span class="keywordtype">double</span> sinfo_new_my_median_image(cpl_image* im)
+<a name="l00463"></a>00463 {
+<a name="l00464"></a>00464   <span class="keywordtype">double</span> m=0;
+<a name="l00465"></a>00465   <span class="keyword">register</span> <span class="keywordtype">int</span> i=0;
+<a name="l00466"></a>00466   <span class="keywordtype">int</span> n=0;
+<a name="l00467"></a>00467   pixelvalue* pv=0;
+<a name="l00468"></a>00468   <span class="keywordtype">int</span> ilx=0;
+<a name="l00469"></a>00469   <span class="keywordtype">int</span> ily=0;
+<a name="l00470"></a>00470   <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l00471"></a>00471 
+<a name="l00472"></a>00472 
+<a name="l00473"></a>00473   <span class="keywordflow">if</span>(im==NULL) <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Null Image"</span>);
+<a name="l00474"></a>00474   ilx=cpl_image_get_size_x(im);
+<a name="l00475"></a>00475   ily=cpl_image_get_size_y(im);
+<a name="l00476"></a>00476   pidata=cpl_image_get_data_float(im);
+<a name="l00477"></a>00477 
+<a name="l00478"></a>00478    <span class="keywordflow">for</span> ( i = 0 ; i < (int) ilx*ily ; i++ )
+<a name="l00479"></a>00479     {
+<a name="l00480"></a>00480       <span class="keywordflow">if</span> ( isnan(pidata[i]) )
+<a name="l00481"></a>00481         {
+<a name="l00482"></a>00482 
+<a name="l00483"></a>00483     } <span class="keywordflow">else</span> {
+<a name="l00484"></a>00484       n++;
+<a name="l00485"></a>00485     }
+<a name="l00486"></a>00486     }
+<a name="l00487"></a>00487    pv = cpl_calloc(n,<span class="keyword">sizeof</span>(pixelvalue));
+<a name="l00488"></a>00488    n=0;
+<a name="l00489"></a>00489    <span class="keywordflow">for</span> ( i = 0 ; i < (int) ilx*ily ; i++ )
+<a name="l00490"></a>00490     {
+<a name="l00491"></a>00491       <span class="keywordflow">if</span> ( isnan(pidata[i]) )
+<a name="l00492"></a>00492         {
+<a name="l00493"></a>00493 
+<a name="l00494"></a>00494     } <span class="keywordflow">else</span> {
+<a name="l00495"></a>00495       pv[n]=pidata[i];
+<a name="l00496"></a>00496           n++;
+<a name="l00497"></a>00497     }
+<a name="l00498"></a>00498     }
+<a name="l00499"></a>00499    <span class="keywordflow">if</span>(pv == NULL || n == 0) {
+<a name="l00500"></a>00500      m=0;
+<a name="l00501"></a>00501    } <span class="keywordflow">else</span> {
+<a name="l00502"></a>00502      m=sinfo_new_median(pv,n);
+<a name="l00503"></a>00503    }
+<a name="l00504"></a>00504    cpl_free(pv);
+<a name="l00505"></a>00505    <span class="keywordflow">if</span>(isnan(m)){
+<a name="l00506"></a>00506      m=0;
+<a name="l00507"></a>00507    }
+<a name="l00508"></a>00508   <span class="keywordflow">return</span> m;
+<a name="l00509"></a>00509 }
+<a name="l00510"></a>00510 
+<a name="l00519"></a>00519 Vector * sinfo_new_mean_of_columns( cpl_image *im )
+<a name="l00520"></a>00520 {
+<a name="l00521"></a>00521     Vector * row=NULL ;
+<a name="l00522"></a>00522     <span class="keywordtype">int</span> i=0;
+<a name="l00523"></a>00523     <span class="keywordtype">int</span> j=0;
+<a name="l00524"></a>00524     <span class="keywordtype">int</span> ilx=0;
+<a name="l00525"></a>00525     <span class="keywordtype">int</span> ily=0;
+<a name="l00526"></a>00526     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l00527"></a>00527 
+<a name="l00528"></a>00528     <span class="keywordflow">if</span> ( im == NULL )
+<a name="l00529"></a>00529     {
+<a name="l00530"></a>00530         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"null image"</span>) ;
+<a name="l00531"></a>00531         <span class="keywordflow">return</span> NullVector ;
+<a name="l00532"></a>00532     }
+<a name="l00533"></a>00533     ilx=cpl_image_get_size_x(im);
+<a name="l00534"></a>00534     ily=cpl_image_get_size_y(im);
+<a name="l00535"></a>00535     pidata=cpl_image_get_data_float(im);
+<a name="l00536"></a>00536 
+<a name="l00537"></a>00537     <span class="comment">/* allocate memory for a row with the length of the image x-axis */</span>
+<a name="l00538"></a>00538     <span class="keywordflow">if</span> ( NULL == (row = sinfo_new_vector (ilx)) )
+<a name="l00539"></a>00539     {
+<a name="l00540"></a>00540         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"not able to allocate a sinfo_vector"</span> ) ;
+<a name="l00541"></a>00541         <span class="keywordflow">return</span> NullVector ;
+<a name="l00542"></a>00542     }
+<a name="l00543"></a>00543 
+<a name="l00544"></a>00544     <span class="keywordflow">for</span> ( i = 0 ; i < ilx ; i++ )
+<a name="l00545"></a>00545     {
+<a name="l00546"></a>00546         <span class="keywordflow">for</span> ( j = 0 ; j < ily ; j++ )
+<a name="l00547"></a>00547         {
+<a name="l00548"></a>00548             <span class="keywordflow">if</span> (!isnan(pidata[i+j*ilx]))
+<a name="l00549"></a>00549             {
+<a name="l00550"></a>00550                 row->data[i] += pidata[i + j*(ilx)] ;
+<a name="l00551"></a>00551             }
+<a name="l00552"></a>00552         }
+<a name="l00553"></a>00553 
+<a name="l00554"></a>00554         row->data[i] /= ily ;
+<a name="l00555"></a>00555     }
+<a name="l00556"></a>00556     <span class="keywordflow">return</span> row ;
+<a name="l00557"></a>00557 }
+<a name="l00569"></a>00569 cpl_image * sinfo_new_clean_mean_of_columns( cpl_image *im,
+<a name="l00570"></a>00570                              <span class="keywordtype">float</span> lo_reject,
+<a name="l00571"></a>00571                              <span class="keywordtype">float</span> hi_reject)
+<a name="l00572"></a>00572 {
+<a name="l00573"></a>00573     cpl_image     * row=NULL ;
+<a name="l00574"></a>00574     pixelvalue*   buffer=NULL ;
+<a name="l00575"></a>00575     <span class="keywordtype">int</span>          i=0;
+<a name="l00576"></a>00576     <span class="keywordtype">int</span>          j=0;
+<a name="l00577"></a>00577     <span class="keywordtype">int</span>          k=0;
+<a name="l00578"></a>00578     <span class="keywordtype">int</span>          nv=0;
+<a name="l00579"></a>00579     <span class="keywordtype">int</span>          lo_n=0;
+<a name="l00580"></a>00580     <span class="keywordtype">int</span>          hi_n=0;
+<a name="l00581"></a>00581     <span class="keywordtype">int</span> ilx=0;
+<a name="l00582"></a>00582     <span class="keywordtype">int</span> ily=0;
+<a name="l00583"></a>00583     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l00584"></a>00584     <span class="keywordtype">float</span>* podata=NULL;
+<a name="l00585"></a>00585 
+<a name="l00586"></a>00586     <span class="keywordflow">if</span> ( im == NULL )
+<a name="l00587"></a>00587     {
+<a name="l00588"></a>00588         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"null image"</span>) ;
+<a name="l00589"></a>00589         <span class="keywordflow">return</span> NULL ;
+<a name="l00590"></a>00590     }
+<a name="l00591"></a>00591     ilx=cpl_image_get_size_x(im);
+<a name="l00592"></a>00592     ily=cpl_image_get_size_y(im);
+<a name="l00593"></a>00593     pidata=cpl_image_get_data_float(im);
+<a name="l00594"></a>00594 
+<a name="l00595"></a>00595     <span class="keywordflow">if</span> ((lo_reject + hi_reject) > 0.9)
+<a name="l00596"></a>00596     {
+<a name="l00597"></a>00597         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"illegal rejection thresholds: [%f] and [%f]"</span>,
+<a name="l00598"></a>00598                         lo_reject, hi_reject) ;
+<a name="l00599"></a>00599         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"threshold sum should not be over "</span>
+<a name="l00600"></a>00600                         <span class="stringliteral">"0.90 aborting average"</span>) ;
+<a name="l00601"></a>00601         <span class="keywordflow">return</span> NULL ;
+<a name="l00602"></a>00602     }
+<a name="l00603"></a>00603 
+<a name="l00604"></a>00604     lo_n = (int) (ily * lo_reject + 0.5) ;
+<a name="l00605"></a>00605     hi_n = (int) (ily * hi_reject + 0.5) ;
+<a name="l00606"></a>00606     <span class="keywordflow">if</span> (lo_n + hi_n >= ily)
+<a name="l00607"></a>00607     {
+<a name="l00608"></a>00608         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"everything would be rejected"</span>) ;
+<a name="l00609"></a>00609         <span class="keywordflow">return</span> NULL ;
+<a name="l00610"></a>00610     }
+<a name="l00611"></a>00611 
+<a name="l00612"></a>00612     <span class="comment">/* allocate memory for a row with the length of the image x-axis */</span>
+<a name="l00613"></a>00613     <span class="keywordflow">if</span> ( NULL == (row = cpl_image_new (ilx, 1,CPL_TYPE_FLOAT)) )
+<a name="l00614"></a>00614     {
+<a name="l00615"></a>00615         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"cannot allocate new image"</span>) ;
+<a name="l00616"></a>00616         <span class="keywordflow">return</span> NULL ;
+<a name="l00617"></a>00617     }
+<a name="l00618"></a>00618     podata=cpl_image_get_data_float(row);
+<a name="l00619"></a>00619 
+<a name="l00620"></a>00620     buffer=(pixelvalue*) cpl_calloc(ily,<span class="keyword">sizeof</span>(pixelvalue)) ;
+<a name="l00621"></a>00621 
+<a name="l00622"></a>00622     <span class="keywordflow">for</span> ( i = 0 ; i < ilx ; i++ )
+<a name="l00623"></a>00623     {
+<a name="l00624"></a>00624         <span class="keywordflow">for</span> ( j = 0 ; j < ily ; j++ )
+<a name="l00625"></a>00625         {
+<a name="l00626"></a>00626             buffer[j] = pidata[i + j*(ilx)] ;
+<a name="l00627"></a>00627         }
+<a name="l00628"></a>00628         sinfo_pixel_qsort (buffer, ily) ;
+<a name="l00629"></a>00629 
+<a name="l00630"></a>00630         nv = 0 ;
+<a name="l00631"></a>00631         <span class="keywordflow">for</span> (k = lo_n ; k < ily - hi_n ; k ++)
+<a name="l00632"></a>00632         {
+<a name="l00633"></a>00633             <span class="keywordflow">if</span> ( !isnan(buffer[k]) )
+<a name="l00634"></a>00634             {
+<a name="l00635"></a>00635                 podata[i] += buffer[k] ;
+<a name="l00636"></a>00636                 nv ++ ;
+<a name="l00637"></a>00637             }
+<a name="l00638"></a>00638         }
+<a name="l00639"></a>00639         podata[i] /= nv ;
+<a name="l00640"></a>00640 
+<a name="l00641"></a>00641     }
+<a name="l00642"></a>00642     cpl_free(buffer);
+<a name="l00643"></a>00643     <span class="keywordflow">return</span> row ;
+<a name="l00644"></a>00644 }
+<a name="l00645"></a>00645 
+<a name="l00646"></a>00646 
+<a name="l00656"></a>00656 cpl_image * sinfo_new_div_image_by_row( cpl_image *im, Vector *row )
+<a name="l00657"></a>00657 {
+<a name="l00658"></a>00658     cpl_image *image=NULL ;
+<a name="l00659"></a>00659     <span class="keywordtype">int</span>         i=0;
+<a name="l00660"></a>00660     <span class="keywordtype">int</span>         j=0;
+<a name="l00661"></a>00661     <span class="keywordtype">int</span> ilx=0;
+<a name="l00662"></a>00662     <span class="keywordtype">int</span> ily=0;
+<a name="l00663"></a>00663     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l00664"></a>00664     <span class="keywordtype">float</span>* podata=NULL;
+<a name="l00665"></a>00665 
+<a name="l00666"></a>00666     <span class="keywordflow">if</span> ( im == NULL || row == NULL )
+<a name="l00667"></a>00667     {
+<a name="l00668"></a>00668         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"null image or null row"</span>) ;
+<a name="l00669"></a>00669         <span class="keywordflow">return</span> NULL ;
+<a name="l00670"></a>00670     }
+<a name="l00671"></a>00671     ilx=cpl_image_get_size_x(im);
+<a name="l00672"></a>00672     ily=cpl_image_get_size_y(im);
+<a name="l00673"></a>00673     pidata=cpl_image_get_data_float(im);
+<a name="l00674"></a>00674 
+<a name="l00675"></a>00675     <span class="keywordflow">if</span> ( ilx != row -> n_elements )
+<a name="l00676"></a>00676     {
+<a name="l00677"></a>00677         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"image and row size not compatible"</span>) ;
+<a name="l00678"></a>00678         <span class="keywordflow">return</span> NULL ;
+<a name="l00679"></a>00679     }
+<a name="l00680"></a>00680 
+<a name="l00681"></a>00681     <span class="keywordflow">if</span> ( NULL == (image = cpl_image_duplicate (im)) )
+<a name="l00682"></a>00682     {
+<a name="l00683"></a>00683         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"cannot copy image"</span>) ;
+<a name="l00684"></a>00684         <span class="keywordflow">return</span> NULL ;
+<a name="l00685"></a>00685     }
+<a name="l00686"></a>00686     podata=cpl_image_get_data_float(image);
+<a name="l00687"></a>00687 
+<a name="l00688"></a>00688     <span class="keywordflow">for</span> (i = 0 ; i < ilx ; i++ )
+<a name="l00689"></a>00689     {
+<a name="l00690"></a>00690         <span class="keywordflow">for</span> (j = 0 ; j < ily ; j++)
+<a name="l00691"></a>00691         {
+<a name="l00692"></a>00692             <span class="keywordflow">if</span> ( !isnan(pidata[i + j*(ilx)]) )
+<a name="l00693"></a>00693             {
+<a name="l00694"></a>00694                 podata[i + j*(ilx)] = pidata[i + j*(ilx)] / row -> data[i] ;
+<a name="l00695"></a>00695             }
+<a name="l00696"></a>00696         }
+<a name="l00697"></a>00697     }
+<a name="l00698"></a>00698     <span class="keywordflow">return</span> image ;
+<a name="l00699"></a>00699 }
+<a name="l00700"></a>00700 
+<a name="l00701"></a>00701 
+<a name="l00711"></a>00711 cpl_image * sinfo_new_mult_row_to_image( cpl_image *im, Vector *row )
+<a name="l00712"></a>00712 {
+<a name="l00713"></a>00713     cpl_image *image=NULL;
+<a name="l00714"></a>00714     <span class="keywordtype">int</span>         i=0;
+<a name="l00715"></a>00715     <span class="keywordtype">int</span>         j=0;
+<a name="l00716"></a>00716     <span class="keywordtype">int</span> ilx=0;
+<a name="l00717"></a>00717     <span class="keywordtype">int</span> ily=0;
+<a name="l00718"></a>00718     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l00719"></a>00719     <span class="keywordtype">float</span>* podata=NULL;
+<a name="l00720"></a>00720 
+<a name="l00721"></a>00721 
+<a name="l00722"></a>00722 
+<a name="l00723"></a>00723 
+<a name="l00724"></a>00724     <span class="keywordflow">if</span> ( im == NULL || row == NULL )
+<a name="l00725"></a>00725     {
+<a name="l00726"></a>00726         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"null image or null row"</span>) ;
+<a name="l00727"></a>00727         <span class="keywordflow">return</span> NULL ;
+<a name="l00728"></a>00728     }
+<a name="l00729"></a>00729     ilx=cpl_image_get_size_x(im);
+<a name="l00730"></a>00730     ily=cpl_image_get_size_y(im);
+<a name="l00731"></a>00731     pidata=cpl_image_get_data_float(im);
+<a name="l00732"></a>00732 
+<a name="l00733"></a>00733     <span class="keywordflow">if</span> ( ilx != row -> n_elements )
+<a name="l00734"></a>00734     {
+<a name="l00735"></a>00735         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"image and row size not compatible"</span>) ;
+<a name="l00736"></a>00736         <span class="keywordflow">return</span> NULL ;
+<a name="l00737"></a>00737     }
+<a name="l00738"></a>00738 
+<a name="l00739"></a>00739     <span class="keywordflow">if</span> ( NULL == (image = cpl_image_duplicate (im)) )
+<a name="l00740"></a>00740     {
+<a name="l00741"></a>00741         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"cannot copy image"</span>) ;
+<a name="l00742"></a>00742         <span class="keywordflow">return</span> NULL ;
+<a name="l00743"></a>00743     }
+<a name="l00744"></a>00744     podata=cpl_image_get_data_float(image);
+<a name="l00745"></a>00745 
+<a name="l00746"></a>00746     <span class="keywordflow">for</span> (i = 0 ; i < ilx ; i++ )
+<a name="l00747"></a>00747     {
+<a name="l00748"></a>00748         <span class="keywordflow">for</span> (j = 0 ; j < ily ; j++)
+<a name="l00749"></a>00749         {
+<a name="l00750"></a>00750             <span class="keywordflow">if</span> ( !isnan(pidata[i + j*(ilx)]) )
+<a name="l00751"></a>00751             {
+<a name="l00752"></a>00752                 podata[i + j*(ilx)] = pidata[i + j*(ilx)] * row -> data[i] ;
+<a name="l00753"></a>00753             }
+<a name="l00754"></a>00754         }
+<a name="l00755"></a>00755     }
+<a name="l00756"></a>00756     <span class="keywordflow">return</span> image ;
+<a name="l00757"></a>00757 }
+<a name="l00758"></a>00758 
+<a name="l00759"></a>00759 
+<a name="l00760"></a>00760 
+<a name="l00761"></a>00761 
+<a name="l00762"></a>00762 
+<a name="l00763"></a>00763 
+<a name="l00787"></a>00787 cpl_image * sinfo_new_col_tilt ( cpl_image * image, <span class="keywordtype">float</span> sigmaFactor )
+<a name="l00788"></a>00788 {
+<a name="l00789"></a>00789     cpl_image   * im=NULL;
+<a name="l00790"></a>00790     <span class="keywordtype">float</span>      * column=NULL ;
+<a name="l00791"></a>00791     <span class="keywordtype">double</span>       sum=0;
+<a name="l00792"></a>00792     <span class="keywordtype">double</span>  sum2=0;
+<a name="l00793"></a>00793     <span class="keywordtype">double</span>  mean=0;
+<a name="l00794"></a>00794     <span class="keywordtype">float</span>   sinfo_median=0;
+<a name="l00795"></a>00795     <span class="keywordtype">float</span>   noise=0 ;
+<a name="l00796"></a>00796     <span class="keywordtype">float</span>      * sig=NULL;
+<a name="l00797"></a>00797     <span class="keywordtype">float</span>    * dat=NULL;
+<a name="l00798"></a>00798     <span class="keywordtype">float</span>        a=0;
+<a name="l00799"></a>00799     <span class="keywordtype">float</span>        b=0;
+<a name="l00800"></a>00800     <span class="keywordtype">float</span>        siga=0;
+<a name="l00801"></a>00801     <span class="keywordtype">float</span>        sigb=0;
+<a name="l00802"></a>00802     <span class="keywordtype">float</span>        chi2=0;
+<a name="l00803"></a>00803     <span class="keywordtype">float</span>        q=0;
+<a name="l00804"></a>00804     <span class="keywordtype">int</span>          i=0;
+<a name="l00805"></a>00805     <span class="keywordtype">int</span>          j=0;
+<a name="l00806"></a>00806     <span class="keywordtype">int</span>          colnum=0;
+<a name="l00807"></a>00807     <span class="keywordtype">int</span>         npix=0;
+<a name="l00808"></a>00808     <span class="keywordtype">int</span>         mwt=0 ;
+<a name="l00809"></a>00809     <span class="keywordtype">int</span> lx=0;
+<a name="l00810"></a>00810     <span class="keywordtype">int</span> ly=0;
+<a name="l00811"></a>00811     <span class="keywordtype">float</span>* p_in_data=NULL;
+<a name="l00812"></a>00812     <span class="keywordtype">float</span>* p_ou_data=NULL;
+<a name="l00813"></a>00813 
+<a name="l00814"></a>00814 
+<a name="l00815"></a>00815     <span class="keywordflow">if</span> ( image == NULL )
+<a name="l00816"></a>00816     {
+<a name="l00817"></a>00817         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"no image given"</span> ) ;
+<a name="l00818"></a>00818         <span class="keywordflow">return</span> NULL ;
+<a name="l00819"></a>00819     }
+<a name="l00820"></a>00820 
+<a name="l00821"></a>00821     <span class="keywordflow">if</span> ( sigmaFactor <= 0. )
+<a name="l00822"></a>00822     {
+<a name="l00823"></a>00823         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"no or negative sigma factor"</span>) ;
+<a name="l00824"></a>00824         <span class="keywordflow">return</span> NULL ;
+<a name="l00825"></a>00825     }
+<a name="l00826"></a>00826     lx = cpl_image_get_size_x(image);
+<a name="l00827"></a>00827     ly = cpl_image_get_size_y(image);
+<a name="l00828"></a>00828 
+<a name="l00829"></a>00829 
+<a name="l00830"></a>00830     <span class="comment">/* allocate memory */</span>
+<a name="l00831"></a>00831     <span class="keywordflow">if</span> ( NULL == (im = cpl_image_new (lx,ly,CPL_TYPE_FLOAT )) )
+<a name="l00832"></a>00832     {
+<a name="l00833"></a>00833         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"cannot allocate new image"</span> ) ;
+<a name="l00834"></a>00834         <span class="keywordflow">return</span> NULL ;
+<a name="l00835"></a>00835     }
+<a name="l00836"></a>00836 
+<a name="l00837"></a>00837     <span class="comment">/* go through the columns */</span>
+<a name="l00838"></a>00838     p_in_data = cpl_image_get_data_float(image);
+<a name="l00839"></a>00839     p_ou_data = cpl_image_get_data_float(im);
+<a name="l00840"></a>00840     <span class="keywordflow">for</span> ( i = 0 ; i < lx ; i ++ )
+<a name="l00841"></a>00841     {
+<a name="l00842"></a>00842         <span class="comment">/* initialize the buffer variables for each column */</span>
+<a name="l00843"></a>00843         colnum = 0 ;
+<a name="l00844"></a>00844         column = (<span class="keywordtype">float</span> *) cpl_calloc ( ly , <span class="keyword">sizeof</span> (<span class="keywordtype">float</span> *) ) ;
+<a name="l00845"></a>00845         sig    = (<span class="keywordtype">float</span> *) cpl_calloc ( ly , <span class="keyword">sizeof</span> (<span class="keywordtype">float</span> *) ) ;
+<a name="l00846"></a>00846         dat    = (<span class="keywordtype">float</span> *) cpl_calloc ( ly , <span class="keyword">sizeof</span> (<span class="keywordtype">float</span> *) ) ;
+<a name="l00847"></a>00847 
+<a name="l00848"></a>00848         <span class="comment">/*select only non-ZERO values of one column*/</span>
+<a name="l00849"></a>00849         <span class="keywordflow">for</span> ( j = 0 ; j < ly ; j++ )
+<a name="l00850"></a>00850         {
+<a name="l00851"></a>00851             <span class="keywordflow">if</span> ( !isnan(p_in_data[i + j*lx]) )
+<a name="l00852"></a>00852             {
+<a name="l00853"></a>00853                 column[j] = p_in_data[i + j*lx] ;
+<a name="l00854"></a>00854                 colnum ++ ;
+<a name="l00855"></a>00855             }
+<a name="l00856"></a>00856         }
+<a name="l00857"></a>00857         <span class="keywordflow">if</span> ( colnum < 10 )
+<a name="l00858"></a>00858         {
+<a name="l00859"></a>00859             <span class="comment">/*sinfo_msg_warning ("sinfo_new_col_tilt:",</span>
+<a name="l00860"></a>00860 <span class="comment">          "column %d has almost only blank pixels and is set to blank", i+1) ;*/</span>
+<a name="l00861"></a>00861             <span class="keywordflow">for</span> ( j = 0 ; j < ly ; j++ )
+<a name="l00862"></a>00862             {
+<a name="l00863"></a>00863                 p_ou_data[i + j*lx] = ZERO;
+<a name="l00864"></a>00864             }
+<a name="l00865"></a>00865             <span class="comment">/*</span>
+<a name="l00866"></a>00866 <span class="comment">            cpl_free (column) ;</span>
+<a name="l00867"></a>00867 <span class="comment">            cpl_free (sig);</span>
+<a name="l00868"></a>00868 <span class="comment">            cpl_free (dat) ;</span>
+<a name="l00869"></a>00869 <span class="comment">            continue ;</span>
+<a name="l00870"></a>00870 <span class="comment">            */</span>
+<a name="l00871"></a>00871         }
+<a name="l00872"></a>00872 
+<a name="l00873"></a>00873         <span class="comment">/*-------------------------------------------------------------------</span>
+<a name="l00874"></a>00874 <span class="comment">         * sort the data, clip off the extremes, determine the noise</span>
+<a name="l00875"></a>00875 <span class="comment">         * and get the range for the valid data. It is assumed here</span>
+<a name="l00876"></a>00876 <span class="comment">         * that most pixels are o.k.</span>
+<a name="l00877"></a>00877 <span class="comment">         */</span>
+<a name="l00878"></a>00878 
+<a name="l00879"></a>00879         sinfo_pixel_qsort (column, colnum) ;
+<a name="l00880"></a>00880 
+<a name="l00881"></a>00881         sum   = 0. ;
+<a name="l00882"></a>00882         sum2  = 0. ;
+<a name="l00883"></a>00883         npix  = 0  ;
+<a name="l00884"></a>00884 
+<a name="l00885"></a>00885         <span class="keywordflow">for</span> ( j = 0.1*colnum + 1 ; j <= 0.9*colnum ; j++ )
+<a name="l00886"></a>00886         {
+<a name="l00887"></a>00887             sum  += column[j] ;
+<a name="l00888"></a>00888             sum2 += column[j] * column[j] ;
+<a name="l00889"></a>00889             npix ++ ;
+<a name="l00890"></a>00890         }
+<a name="l00891"></a>00891 
+<a name="l00892"></a>00892         <span class="keywordflow">if</span> (npix <= 1)
+<a name="l00893"></a>00893         {
+<a name="l00894"></a>00894             noise = sigmaFactor * 1000.;
+<a name="l00895"></a>00895         }
+<a name="l00896"></a>00896         <span class="keywordflow">else</span>
+<a name="l00897"></a>00897         {
+<a name="l00898"></a>00898             mean   = sum/(float)npix ;
+<a name="l00899"></a>00899             noise  = sqrt( (sum2 - sum*mean)/(<span class="keywordtype">double</span>)(npix -1) ) ;
+<a name="l00900"></a>00900             noise *= sigmaFactor ;
+<a name="l00901"></a>00901         }
+<a name="l00902"></a>00902 
+<a name="l00903"></a>00903         <span class="comment">/* -------------------------------------------------------------</span>
+<a name="l00904"></a>00904 <span class="comment">         * determine sinfo_median if colnum is odd, sinfo_median will be the</span>
+<a name="l00905"></a>00905 <span class="comment">           colnum/2 th value, otherwise</span>
+<a name="l00906"></a>00906 <span class="comment">         * sinfo_median is the mean of colnum/2-1 th and colnum/2 th value.</span>
+<a name="l00907"></a>00907 <span class="comment">         */</span>
+<a name="l00908"></a>00908 
+<a name="l00909"></a>00909         <span class="keywordflow">if</span> ( colnum % 2 == 1 )
+<a name="l00910"></a>00910         {
+<a name="l00911"></a>00911             sinfo_median = column[colnum/2] ;
+<a name="l00912"></a>00912         }
+<a name="l00913"></a>00913         <span class="keywordflow">else</span>
+<a name="l00914"></a>00914         {
+<a name="l00915"></a>00915             sinfo_median = (column[colnum/2 - 1] + column[colnum/2])/2. ;
+<a name="l00916"></a>00916         }
+<a name="l00917"></a>00917 
+<a name="l00918"></a>00918         <span class="comment">/* now select the pixels for the tilt calculation */</span>
+<a name="l00919"></a>00919 
+<a name="l00920"></a>00920         colnum = 0 ;
+<a name="l00921"></a>00921         <span class="keywordflow">for</span> ( j = 0; j < ly ; j ++ )
+<a name="l00922"></a>00922         {
+<a name="l00923"></a>00923             <span class="keywordflow">if</span> ( !isnan(p_in_data[i+j*lx]) &&
+<a name="l00924"></a>00924                  fabs ( (p_in_data[i+j*lx]) - sinfo_median) <= noise )
+<a name="l00925"></a>00925             {
+<a name="l00926"></a>00926                 column[colnum] = p_in_data[i+j*lx] ;
+<a name="l00927"></a>00927                 dat[colnum] = (float) j ;
+<a name="l00928"></a>00928                 sig[colnum] = 1. ;
+<a name="l00929"></a>00929                 colnum ++ ;
+<a name="l00930"></a>00930             }
+<a name="l00931"></a>00931         }
+<a name="l00932"></a>00932 
+<a name="l00933"></a>00933         <span class="keywordflow">if</span> ( colnum == 0 )
+<a name="l00934"></a>00934         {
+<a name="l00935"></a>00935             <span class="comment">/*for ( j = 0; j < ly; j++ )</span>
+<a name="l00936"></a>00936 <span class="comment">            {</span>
+<a name="l00937"></a>00937 <span class="comment">                p_ou_data[i+j*lx] -= sinfo_median ;</span>
+<a name="l00938"></a>00938 <span class="comment">            }</span>
+<a name="l00939"></a>00939 <span class="comment">            cpl_free (column) ;</span>
+<a name="l00940"></a>00940 <span class="comment">            cpl_free (sig)    ;</span>
+<a name="l00941"></a>00941 <span class="comment">            cpl_free (dat)    ;</span>
+<a name="l00942"></a>00942 <span class="comment">            continue ;*/</span>
+<a name="l00943"></a>00943         a=0./0.;
+<a name="l00944"></a>00944         b=0./0.;
+<a name="l00945"></a>00945         }
+<a name="l00946"></a>00946     <span class="keywordflow">else</span>
+<a name="l00947"></a>00947     {
+<a name="l00948"></a>00948         mwt = 0 ;
+<a name="l00949"></a>00949         sinfo_my_fit ( dat, column, colnum, sig, mwt, &a,
+<a name="l00950"></a>00950                        &b, &siga, &sigb, &chi2, &q ) ;
+<a name="l00951"></a>00951     }
+<a name="l00952"></a>00952         <span class="keywordflow">if</span> ( fabs(b) >= SLOPE || fabs(a) >= SATURATION  ||
+<a name="l00953"></a>00953              isnan(b) || isnan(a))
+<a name="l00954"></a>00954         {
+<a name="l00955"></a>00955             <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a> (<span class="stringliteral">"linear fit: slope is greater than limit: %f"</span>
+<a name="l00956"></a>00956                                <span class="stringliteral">" saturation level is reached: %f in column"</span>
+<a name="l00957"></a>00957                                <span class="stringliteral">" number %d "</span>, b, a , i+1) ;
+<a name="l00958"></a>00958         }
+<a name="l00959"></a>00959 
+<a name="l00960"></a>00960         <span class="comment">/* subtract fit or sinfo_median from data */</span>
+<a name="l00961"></a>00961         <span class="keywordflow">for</span> ( j = 0; j < ly; j++ )
+<a name="l00962"></a>00962         {
+<a name="l00963"></a>00963             <span class="keywordflow">if</span> ( !isnan(p_in_data[i+j*lx]) &&
+<a name="l00964"></a>00964                  fabs(b) < SLOPE && fabs(a) < SATURATION )
+<a name="l00965"></a>00965             {
+<a name="l00966"></a>00966                 p_ou_data[i+j*lx] = p_in_data[i+j*lx] - (a + b * (float)j) ;
+<a name="l00967"></a>00967             }
+<a name="l00968"></a>00968             <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( isnan(p_in_data[i+j*lx]) )
+<a name="l00969"></a>00969             {
+<a name="l00970"></a>00970                 p_ou_data[i+j*lx] = ZERO ;
+<a name="l00971"></a>00971             }
+<a name="l00972"></a>00972             <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( (fabs(b) >= SLOPE ||
+<a name="l00973"></a>00973                        fabs(a) >= SATURATION || isnan(a) || isnan(b)) &&
+<a name="l00974"></a>00974                       !isnan(p_in_data[i+j*lx]) )
+<a name="l00975"></a>00975             {
+<a name="l00976"></a>00976                 p_ou_data[i+j*lx] -= sinfo_median ;
+<a name="l00977"></a>00977             }
+<a name="l00978"></a>00978             <span class="keywordflow">else</span>
+<a name="l00979"></a>00979             {
+<a name="l00980"></a>00980                 <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" case is not possible! %f %f"</span>, b,a) ;
+<a name="l00981"></a>00981                 <span class="comment">/*cpl_free (column) ;</span>
+<a name="l00982"></a>00982 <span class="comment">                cpl_free (sig)    ;</span>
+<a name="l00983"></a>00983 <span class="comment">                cpl_free (dat)    ;</span>
+<a name="l00984"></a>00984 <span class="comment">                cpl_image_delete(im) ;</span>
+<a name="l00985"></a>00985 <span class="comment">                return NULL ;*/</span>
+<a name="l00986"></a>00986             }
+<a name="l00987"></a>00987         }
+<a name="l00988"></a>00988         cpl_free (column) ;
+<a name="l00989"></a>00989         cpl_free (sig)    ;
+<a name="l00990"></a>00990         cpl_free (dat)    ;
+<a name="l00991"></a>00991     }
+<a name="l00992"></a>00992 
+<a name="l00993"></a>00993     <span class="keywordflow">return</span> im     ;
+<a name="l00994"></a>00994 }
+<a name="l00995"></a>00995 
+<a name="l00996"></a>00996 
+<a name="l00997"></a>00997 
+<a name="l00998"></a>00998 
+<a name="l00999"></a>00999 
+<a name="l01023"></a>01023 cpl_image * sinfo_new_median_image( cpl_image * im, <span class="keywordtype">float</span> fmedian )
+<a name="l01024"></a>01024 {
+<a name="l01025"></a>01025     cpl_image *   image=NULL       ;
+<a name="l01026"></a>01026     pixelvalue * value=NULL       ;
+<a name="l01027"></a>01027     pixelvalue   sinfo_median=0      ;
+<a name="l01028"></a>01028     <span class="keywordtype">int</span>        * position=NULL    ;
+<a name="l01029"></a>01029     <span class="keywordtype">int</span>          nposition=0   ;
+<a name="l01030"></a>01030     <span class="keywordtype">int</span>          n=0;
+<a name="l01031"></a>01031     <span class="keywordtype">int</span>          i=0;
+<a name="l01032"></a>01032     <span class="keywordtype">int</span>          j=0;
+<a name="l01033"></a>01033     <span class="keywordtype">int</span> lx=0;
+<a name="l01034"></a>01034     <span class="keywordtype">int</span> ly=0;
+<a name="l01035"></a>01035     <span class="keywordtype">float</span>* p_in_data=NULL;
+<a name="l01036"></a>01036     <span class="keywordtype">float</span>* p_ou_data=NULL;
+<a name="l01037"></a>01037     <span class="keywordtype">int</span> im_size=0;
+<a name="l01038"></a>01038     <span class="keywordflow">if</span> ( im == NULL )
+<a name="l01039"></a>01039     {
+<a name="l01040"></a>01040         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"no image input"</span>) ;
+<a name="l01041"></a>01041         <span class="keywordflow">return</span> NULL ;
+<a name="l01042"></a>01042     }
+<a name="l01043"></a>01043 
+<a name="l01044"></a>01044     image = cpl_image_duplicate ( im ) ;
+<a name="l01045"></a>01045     lx=cpl_image_get_size_x(im);
+<a name="l01046"></a>01046     ly=cpl_image_get_size_y(im);
+<a name="l01047"></a>01047     im_size=lx*ly;
+<a name="l01048"></a>01048     p_in_data=cpl_image_get_data_float(im);
+<a name="l01049"></a>01049     p_ou_data=cpl_image_get_data_float(image);
+<a name="l01050"></a>01050 
+<a name="l01051"></a>01051     <span class="comment">/*----------------------------------------------------------------------</span>
+<a name="l01052"></a>01052 <span class="comment">     * go through all pixels</span>
+<a name="l01053"></a>01053 <span class="comment">     */</span>
+<a name="l01054"></a>01054 
+<a name="l01055"></a>01055     <span class="keywordflow">for</span> ( i = 0 ; i < im_size ; i++ )
+<a name="l01056"></a>01056     {
+<a name="l01057"></a>01057         <span class="comment">/* blank pixels are not replaced */</span>
+<a name="l01058"></a>01058         <span class="keywordflow">if</span> ( isnan(p_in_data[i]) )
+<a name="l01059"></a>01059         {
+<a name="l01060"></a>01060             continue ;
+<a name="l01061"></a>01061         }
+<a name="l01062"></a>01062 
+<a name="l01063"></a>01063         <span class="comment">/* initialize the buffer variables for the 8 nearest neighbors */</span>
+<a name="l01064"></a>01064         value = (pixelvalue * )cpl_calloc ( 8, <span class="keyword">sizeof</span> ( pixelvalue * ) ) ;
+<a name="l01065"></a>01065         position = ( <span class="keywordtype">int</span> * ) cpl_calloc ( 8, <span class="keyword">sizeof</span> ( <span class="keywordtype">int</span> * ) ) ;
+<a name="l01066"></a>01066 
+<a name="l01067"></a>01067         <span class="comment">/*--------------------------------------------------------------------</span>
+<a name="l01068"></a>01068 <span class="comment">         * determine the pixel position of the 8 nearest neighbors</span>
+<a name="l01069"></a>01069 <span class="comment">         */</span>
+<a name="l01070"></a>01070 
+<a name="l01071"></a>01071         position[0] = i + lx - 1 ; <span class="comment">/* upper left  */</span>
+<a name="l01072"></a>01072         position[1] = i + lx     ; <span class="comment">/* upper       */</span>
+<a name="l01073"></a>01073         position[2] = i + lx + 1 ; <span class="comment">/* upper right */</span>
+<a name="l01074"></a>01074         position[3] = i + 1      ; <span class="comment">/* right       */</span>
+<a name="l01075"></a>01075         position[4] = i - lx + 1 ; <span class="comment">/* lower right */</span>
+<a name="l01076"></a>01076         position[5] = i - lx     ; <span class="comment">/* lower       */</span>
+<a name="l01077"></a>01077         position[6] = i - lx - 1 ; <span class="comment">/* lower left  */</span>
+<a name="l01078"></a>01078         position[7] = i - 1      ; <span class="comment">/* left        */</span>
+<a name="l01079"></a>01079 
+<a name="l01080"></a>01080         <span class="comment">/*-------------------------------------------------------------------</span>
+<a name="l01081"></a>01081 <span class="comment">         * determine the positions of the image margins, top positions are</span>
+<a name="l01082"></a>01082 <span class="comment">           changed to low positions and vice versa. Right positions are</span>
+<a name="l01083"></a>01083 <span class="comment">           changed to left positions and vice versa.</span>
+<a name="l01084"></a>01084 <span class="comment">         */</span>
+<a name="l01085"></a>01085 
+<a name="l01086"></a>01086         <span class="keywordflow">if</span> ( i >= 0 && i < lx )    <span class="comment">/* bottom line */</span>
+<a name="l01087"></a>01087         {
+<a name="l01088"></a>01088             position[4] += 2 * lx ;
+<a name="l01089"></a>01089             position[5] += 2 * lx ;
+<a name="l01090"></a>01090             position[6] += 2 * lx ;
+<a name="l01091"></a>01091         }
+<a name="l01092"></a>01092         <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( i >= ((<span class="keywordtype">int</span>) lx*ly - lx ) && i < (<span class="keywordtype">int</span>) lx*ly ) <span class="comment">/* top line */</span>
+<a name="l01093"></a>01093         {
+<a name="l01094"></a>01094             position[0] -= 2 * lx ;
+<a name="l01095"></a>01095             position[1] -= 2 * lx ;
+<a name="l01096"></a>01096             position[2] -= 2 * lx ;
+<a name="l01097"></a>01097         }
+<a name="l01098"></a>01098         <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( i % lx == 0 )    <span class="comment">/* left side */</span>
+<a name="l01099"></a>01099         {
+<a name="l01100"></a>01100             position[0] += 2 ;
+<a name="l01101"></a>01101             position[6] += 2 ;
+<a name="l01102"></a>01102             position[7] += 2 ;
+<a name="l01103"></a>01103         }
+<a name="l01104"></a>01104         <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( i % lx == lx - 1 )    <span class="comment">/* right side */</span>
+<a name="l01105"></a>01105         {
+<a name="l01106"></a>01106             position[2] -= 2 ;
+<a name="l01107"></a>01107             position[3] -= 2 ;
+<a name="l01108"></a>01108             position[4] -= 2 ;
+<a name="l01109"></a>01109         }
+<a name="l01110"></a>01110 
+<a name="l01111"></a>01111         <span class="comment">/* --------------------------------------------------------------------</span>
+<a name="l01112"></a>01112 <span class="comment">         * read the pixel values of the neighboring pixels,</span>
+<a name="l01113"></a>01113 <span class="comment">         * blanks are not considered</span>
+<a name="l01114"></a>01114 <span class="comment">         */</span>
+<a name="l01115"></a>01115 
+<a name="l01116"></a>01116         nposition = 8 ;
+<a name="l01117"></a>01117         n = 0 ;
+<a name="l01118"></a>01118         <span class="keywordflow">for</span> ( j = 0 ; j < nposition ; j ++ )
+<a name="l01119"></a>01119         {
+<a name="l01120"></a>01120            <span class="keywordflow">if</span>((position[j] >-1 ) && (position[j]<im_size)) {
+<a name="l01121"></a>01121               <span class="keywordflow">if</span> ( !isnan(p_in_data[position[j]]) )
+<a name="l01122"></a>01122               {
+<a name="l01123"></a>01123                 value[n] = p_in_data[position[j]] ;
+<a name="l01124"></a>01124                 n ++ ;
+<a name="l01125"></a>01125               }
+<a name="l01126"></a>01126            }
+<a name="l01127"></a>01127         }
+<a name="l01128"></a>01128         nposition = n ;
+<a name="l01129"></a>01129 
+<a name="l01130"></a>01130         <span class="keywordflow">if</span> ( nposition <= 1 )  <span class="comment">/* almost all neighbors are blank */</span>
+<a name="l01131"></a>01131         {
+<a name="l01132"></a>01132             p_ou_data[i] = ZERO ;
+<a name="l01133"></a>01133             cpl_free(value) ;
+<a name="l01134"></a>01134             cpl_free(position) ;
+<a name="l01135"></a>01135             continue ;
+<a name="l01136"></a>01136         }
+<a name="l01137"></a>01137 
+<a name="l01138"></a>01138         <span class="comment">/* sort the values and determine the sinfo_median */</span>
+<a name="l01139"></a>01139 
+<a name="l01140"></a>01140         sinfo_pixel_qsort ( value, nposition ) ;
+<a name="l01141"></a>01141         <span class="keywordflow">if</span> ( nposition % 2 == 1 )
+<a name="l01142"></a>01142         {
+<a name="l01143"></a>01143             sinfo_median = value [ nposition/2 ] ;
+<a name="l01144"></a>01144         }
+<a name="l01145"></a>01145         <span class="keywordflow">else</span>
+<a name="l01146"></a>01146         {
+<a name="l01147"></a>01147             sinfo_median = ( value [nposition/2 - 1] +
+<a name="l01148"></a>01148                              value [nposition/2] ) / 2. ;
+<a name="l01149"></a>01149         }
+<a name="l01150"></a>01150 
+<a name="l01151"></a>01151         <span class="comment">/* -----------------------------------------------------------------</span>
+<a name="l01152"></a>01152 <span class="comment">         * replace the pixel value by the sinfo_median on conditions:</span>
+<a name="l01153"></a>01153 <span class="comment">         * fmedian = 0: always replace with sinfo_median.</span>
+<a name="l01154"></a>01154 <span class="comment">         * fmedian < 0: interpret as absolute condition:</span>
+<a name="l01155"></a>01155 <span class="comment">         *              if |pixel - sinfo_median| > -fmedian</span>
+<a name="l01156"></a>01156 <span class="comment">         *              replace with sinfo_median.</span>
+<a name="l01157"></a>01157 <span class="comment">         * fmedian > 0: replace by sinfo_median (fmedian as a factor of</span>
+<a name="l01158"></a>01158 <span class="comment">         *              the square root of the sinfo_median itself)</span>
+<a name="l01159"></a>01159 <span class="comment">         *              if |pixel - sinfo_median| >= fmedian *</span>
+<a name="l01160"></a>01160 <span class="comment">                                                     sqrt ( sinfo_median )</span>
+<a name="l01161"></a>01161 <span class="comment">         *              considers a dependence on the pixel value.</span>
+<a name="l01162"></a>01162 <span class="comment">         *              This can be used to consider photon noise.</span>
+<a name="l01163"></a>01163 <span class="comment">         */</span>
+<a name="l01164"></a>01164 
+<a name="l01165"></a>01165         <span class="keywordflow">if</span> ( fmedian == 0 )
+<a name="l01166"></a>01166         {
+<a name="l01167"></a>01167             p_ou_data[i] = sinfo_median ;
+<a name="l01168"></a>01168         }
+<a name="l01169"></a>01169         <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( fmedian < 0 &&
+<a name="l01170"></a>01170                   fabs ( sinfo_median - p_in_data[i] ) >= -fmedian )
+<a name="l01171"></a>01171         {
+<a name="l01172"></a>01172             p_ou_data[i] = sinfo_median ;
+<a name="l01173"></a>01173         }
+<a name="l01174"></a>01174         <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( fmedian > 0 &&
+<a name="l01175"></a>01175                   fabs ( sinfo_median - p_in_data[i] ) >= fmedian *
+<a name="l01176"></a>01176                                                       sqrt(fabs(sinfo_median)) )
+<a name="l01177"></a>01177         {
+<a name="l01178"></a>01178             p_ou_data[i] = sinfo_median ;
+<a name="l01179"></a>01179         }
+<a name="l01180"></a>01180         <span class="keywordflow">else</span>
+<a name="l01181"></a>01181         {
+<a name="l01182"></a>01182             cpl_free (value) ;
+<a name="l01183"></a>01183             cpl_free (position) ;
+<a name="l01184"></a>01184             continue ;
+<a name="l01185"></a>01185         }
+<a name="l01186"></a>01186 
+<a name="l01187"></a>01187         cpl_free (value) ;
+<a name="l01188"></a>01188         cpl_free (position) ;
+<a name="l01189"></a>01189     }
+<a name="l01190"></a>01190     <span class="keywordflow">return</span> image ;
+<a name="l01191"></a>01191 }
+<a name="l01192"></a>01192 
+<a name="l01193"></a>01193 
+<a name="l01194"></a>01194 
+<a name="l01195"></a>01195 
+<a name="l01206"></a>01206 cpl_image *
+<a name="l01207"></a>01207 sinfo_new_compare_images(cpl_image * im1,cpl_image * im2,cpl_image * origim )
+<a name="l01208"></a>01208 {
+<a name="l01209"></a>01209     cpl_image * image=NULL ;
+<a name="l01210"></a>01210     <span class="keywordtype">int</span>            i=0 ;
+<a name="l01211"></a>01211     <span class="keywordtype">int</span> lx1=0;
+<a name="l01212"></a>01212     <span class="keywordtype">int</span> ly1=0;
+<a name="l01213"></a>01213     <span class="keywordtype">int</span> lx2=0;
+<a name="l01214"></a>01214     <span class="keywordtype">int</span> ly2=0;
+<a name="l01215"></a>01215     <span class="keywordtype">float</span>* p_in1_data=NULL;
+<a name="l01216"></a>01216     <span class="keywordtype">float</span>* p_in2_data=NULL;
+<a name="l01217"></a>01217     <span class="keywordtype">float</span>* p_ou_data=NULL;
+<a name="l01218"></a>01218     <span class="keywordtype">float</span>* p_org_data=NULL;
+<a name="l01219"></a>01219 
+<a name="l01220"></a>01220 
+<a name="l01221"></a>01221     <span class="keywordflow">if</span> ( im1 == NULL || im2 == NULL || origim == NULL )
+<a name="l01222"></a>01222     {
+<a name="l01223"></a>01223         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"Null images as input"</span> ) ;
+<a name="l01224"></a>01224         <span class="keywordflow">return</span> NULL ;
+<a name="l01225"></a>01225     }
+<a name="l01226"></a>01226     lx1=cpl_image_get_size_x(im1);
+<a name="l01227"></a>01227     ly1=cpl_image_get_size_y(im1);
+<a name="l01228"></a>01228 
+<a name="l01229"></a>01229     lx2=cpl_image_get_size_x(im2);
+<a name="l01230"></a>01230     ly2=cpl_image_get_size_y(im2);
+<a name="l01231"></a>01231 
+<a name="l01232"></a>01232     p_in1_data=cpl_image_get_data_float(im1);
+<a name="l01233"></a>01233     p_in2_data=cpl_image_get_data_float(im2);
+<a name="l01234"></a>01234     p_org_data=cpl_image_get_data_float(origim);
+<a name="l01235"></a>01235     <span class="keywordflow">if</span> ( lx1 != lx2 || ly1 != ly2 )
+<a name="l01236"></a>01236     {
+<a name="l01237"></a>01237         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"incompatible image sizes"</span> ) ;
+<a name="l01238"></a>01238         <span class="keywordflow">return</span> NULL ;
+<a name="l01239"></a>01239     }
+<a name="l01240"></a>01240 
+<a name="l01241"></a>01241     <span class="comment">/* allocate memory */</span>
+<a name="l01242"></a>01242     <span class="keywordflow">if</span> ( NULL == (image = cpl_image_new ( lx1, ly1, CPL_TYPE_FLOAT )) )
+<a name="l01243"></a>01243     {
+<a name="l01244"></a>01244         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"cannot allocate new image"</span> ) ;
+<a name="l01245"></a>01245         <span class="keywordflow">return</span> NULL ;
+<a name="l01246"></a>01246     }
+<a name="l01247"></a>01247     p_ou_data=cpl_image_get_data_float(image);
+<a name="l01248"></a>01248     <span class="keywordflow">for</span> ( i = 0 ; i < (int) lx1*ly1 ; i ++ )
+<a name="l01249"></a>01249     {
+<a name="l01250"></a>01250         <span class="keywordflow">if</span> ( isnan(p_in1_data[i]) && isnan(p_in2_data[i]) )
+<a name="l01251"></a>01251         {
+<a name="l01252"></a>01252             p_ou_data[i] = ZERO ;
+<a name="l01253"></a>01253         }
+<a name="l01254"></a>01254         <span class="keywordflow">else</span>
+<a name="l01255"></a>01255         {
+<a name="l01256"></a>01256             <span class="keywordflow">if</span> ( p_in1_data[i] == p_in2_data[i] )
+<a name="l01257"></a>01257             {
+<a name="l01258"></a>01258                 p_ou_data[i] = p_org_data[i] ;
+<a name="l01259"></a>01259             }
+<a name="l01260"></a>01260             <span class="keywordflow">else</span>
+<a name="l01261"></a>01261             {
+<a name="l01262"></a>01262                 p_ou_data[i] = ZERO ;
+<a name="l01263"></a>01263             }
+<a name="l01264"></a>01264         }
+<a name="l01265"></a>01265     }
+<a name="l01266"></a>01266     <span class="keywordflow">return</span> image ;
+<a name="l01267"></a>01267 }
+<a name="l01268"></a>01268 
+<a name="l01269"></a>01269 
+<a name="l01270"></a>01270 
+<a name="l01282"></a>01282 cpl_image *
+<a name="l01283"></a>01283 sinfo_new_promote_image_to_mask (cpl_image * im, <span class="keywordtype">int</span> * n_badpixels )
+<a name="l01284"></a>01284 {
+<a name="l01285"></a>01285     cpl_image * reImage=NULL ;
+<a name="l01286"></a>01286     <span class="keywordtype">int</span>        i=0 ;
+<a name="l01287"></a>01287     <span class="keywordtype">int</span> lx=0;
+<a name="l01288"></a>01288     <span class="keywordtype">int</span> ly=0;
+<a name="l01289"></a>01289     <span class="keywordtype">float</span>* p_in_data=NULL;
+<a name="l01290"></a>01290     <span class="keywordtype">float</span>* p_ou_data=NULL;
+<a name="l01291"></a>01291 
+<a name="l01292"></a>01292     <span class="keywordflow">if</span> ( NULL == im )
+<a name="l01293"></a>01293     {
+<a name="l01294"></a>01294         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no input image given!"</span>) ;
+<a name="l01295"></a>01295         <span class="keywordflow">return</span> NULL ;
+<a name="l01296"></a>01296     }
+<a name="l01297"></a>01297     lx=cpl_image_get_size_x(im);
+<a name="l01298"></a>01298     ly=cpl_image_get_size_y(im);
+<a name="l01299"></a>01299     p_in_data=cpl_image_get_data_float(im);
+<a name="l01300"></a>01300 
+<a name="l01301"></a>01301     <span class="comment">/* allocate memory for the returned image */</span>
+<a name="l01302"></a>01302     <span class="keywordflow">if</span> ( NULL == (reImage = cpl_image_new (lx,ly,CPL_TYPE_FLOAT )) )
+<a name="l01303"></a>01303     {
+<a name="l01304"></a>01304         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"cannot allocate new image!"</span>) ;
+<a name="l01305"></a>01305         <span class="keywordflow">return</span> NULL ;
+<a name="l01306"></a>01306     }
+<a name="l01307"></a>01307     p_ou_data=cpl_image_get_data_float(reImage);
+<a name="l01308"></a>01308 
+<a name="l01309"></a>01309     *n_badpixels = 0 ;
+<a name="l01310"></a>01310     <span class="keywordflow">for</span> ( i = 0 ; i < (int) lx*ly ; i ++ )
+<a name="l01311"></a>01311     {
+<a name="l01312"></a>01312         <span class="keywordflow">if</span> ( isnan(p_in_data[i]) )
+<a name="l01313"></a>01313         {
+<a name="l01314"></a>01314             p_ou_data[i] = 0. ;
+<a name="l01315"></a>01315             (*n_badpixels)++ ;
+<a name="l01316"></a>01316         }
+<a name="l01317"></a>01317         <span class="keywordflow">else</span>
+<a name="l01318"></a>01318         {
+<a name="l01319"></a>01319             p_ou_data[i] = 1. ;
+<a name="l01320"></a>01320         }
+<a name="l01321"></a>01321     }
+<a name="l01322"></a>01322     <span class="keywordflow">return</span> reImage ;
+<a name="l01323"></a>01323 }
+<a name="l01324"></a>01324 
+<a name="l01325"></a>01325 
+<a name="l01336"></a>01336 cpl_image * sinfo_new_mult_image_by_mask (cpl_image * im,cpl_image * mask )
+<a name="l01337"></a>01337 {
+<a name="l01338"></a>01338     cpl_image * reImage=NULL ;
+<a name="l01339"></a>01339     <span class="keywordtype">int</span>        i=0 ;
+<a name="l01340"></a>01340     <span class="keywordtype">int</span> ix=0;
+<a name="l01341"></a>01341     <span class="keywordtype">int</span> iy=0;
+<a name="l01342"></a>01342     <span class="keywordtype">int</span> mx=0;
+<a name="l01343"></a>01343     <span class="keywordtype">int</span> my=0;
+<a name="l01344"></a>01344 
+<a name="l01345"></a>01345 
+<a name="l01346"></a>01346     <span class="keywordtype">float</span>* pmdata=NULL;
+<a name="l01347"></a>01347     <span class="keywordtype">float</span>* podata=NULL;
+<a name="l01348"></a>01348 
+<a name="l01349"></a>01349     <span class="keywordflow">if</span> ( NULL == im )
+<a name="l01350"></a>01350     {
+<a name="l01351"></a>01351         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no input image given!"</span>) ;
+<a name="l01352"></a>01352         <span class="keywordflow">return</span> NULL ;
+<a name="l01353"></a>01353     }
+<a name="l01354"></a>01354     <span class="keywordflow">if</span> ( NULL == mask )
+<a name="l01355"></a>01355     {
+<a name="l01356"></a>01356         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no mask image given!"</span>) ;
+<a name="l01357"></a>01357         <span class="keywordflow">return</span> NULL ;
+<a name="l01358"></a>01358     }
+<a name="l01359"></a>01359     ix=cpl_image_get_size_x(im);
+<a name="l01360"></a>01360     iy=cpl_image_get_size_y(im);
+<a name="l01361"></a>01361     mx=cpl_image_get_size_x(mask);
+<a name="l01362"></a>01362     my=cpl_image_get_size_y(mask);
+<a name="l01363"></a>01363 
+<a name="l01364"></a>01364     <span class="keywordflow">if</span> ( ix != mx || iy != my)
+<a name="l01365"></a>01365     {
+<a name="l01366"></a>01366         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"image sizes are not correspondent!"</span>) ;
+<a name="l01367"></a>01367         <span class="keywordflow">return</span> NULL ;
+<a name="l01368"></a>01368     }
+<a name="l01369"></a>01369 
+<a name="l01370"></a>01370     reImage = cpl_image_duplicate( im ) ;
+<a name="l01371"></a>01371     podata=cpl_image_get_data_float(reImage);
+<a name="l01372"></a>01372     pmdata=cpl_image_get_data_float(mask);
+<a name="l01373"></a>01373 
+<a name="l01374"></a>01374     <span class="keywordflow">for</span> ( i = 0 ; i < (int) ix*iy ; i ++ )
+<a name="l01375"></a>01375     {
+<a name="l01376"></a>01376         <span class="keywordflow">if</span> ( pmdata[i] == 0. )
+<a name="l01377"></a>01377         {
+<a name="l01378"></a>01378             podata[i] = ZERO ;
+<a name="l01379"></a>01379         }
+<a name="l01380"></a>01380     }
+<a name="l01381"></a>01381 
+<a name="l01382"></a>01382     <span class="keywordflow">return</span> reImage ;
+<a name="l01383"></a>01383 }
+<a name="l01384"></a>01384 
+<a name="l01385"></a>01385 
+<a name="l01386"></a>01386 
+<a name="l01396"></a>01396 cpl_image *
+<a name="l01397"></a>01397 sinfo_new_thresh_image (cpl_image * im, <span class="keywordtype">float</span> lo_cut, <span class="keywordtype">float</span> hi_cut )
+<a name="l01398"></a>01398 {
+<a name="l01399"></a>01399     cpl_image * image=NULL ;
+<a name="l01400"></a>01400     <span class="keywordtype">float</span>* p_inp_data=NULL;
+<a name="l01401"></a>01401     <span class="keywordtype">float</span>* p_out_data=NULL;
+<a name="l01402"></a>01402     <span class="keywordtype">int</span> lx=0;
+<a name="l01403"></a>01403     <span class="keywordtype">int</span> ly=0;
+<a name="l01404"></a>01404 
+<a name="l01405"></a>01405     <span class="keywordtype">int</span>            i=0 ;
+<a name="l01406"></a>01406 
+<a name="l01407"></a>01407     <span class="keywordflow">if</span> (im == NULL)
+<a name="l01408"></a>01408     {
+<a name="l01409"></a>01409         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"null image given"</span>) ;
+<a name="l01410"></a>01410         <span class="keywordflow">return</span> NULL ;
+<a name="l01411"></a>01411     }
+<a name="l01412"></a>01412     lx=cpl_image_get_size_x(im);
+<a name="l01413"></a>01413     ly=cpl_image_get_size_y(im);
+<a name="l01414"></a>01414 
+<a name="l01415"></a>01415     image = cpl_image_duplicate(im) ;
+<a name="l01416"></a>01416     p_inp_data=cpl_image_get_data(im);
+<a name="l01417"></a>01417     p_out_data=cpl_image_get_data(image);
+<a name="l01418"></a>01418     <span class="keywordflow">for</span> ( i = 0 ; i < (int) lx*ly ; i ++ )
+<a name="l01419"></a>01419     {
+<a name="l01420"></a>01420         <span class="keywordflow">if</span> ( p_inp_data[i] > (pixelvalue) hi_cut ||
+<a name="l01421"></a>01421              p_inp_data[i] < (pixelvalue) lo_cut )
+<a name="l01422"></a>01422         {
+<a name="l01423"></a>01423              p_out_data[i] = ZERO ;
+<a name="l01424"></a>01424         }
+<a name="l01425"></a>01425     }
+<a name="l01426"></a>01426     <span class="keywordflow">return</span> image ;
+<a name="l01427"></a>01427 }
+<a name="l01428"></a>01428 
+<a name="l01429"></a>01429 
+<a name="l01430"></a>01430 
+<a name="l01431"></a>01431 
+<a name="l01456"></a>01456 cpl_image * sinfo_new_interpol_image ( cpl_image * im,
+<a name="l01457"></a>01457                            cpl_image * mask,
+<a name="l01458"></a>01458                            <span class="keywordtype">int</span>        max_radius,
+<a name="l01459"></a>01459                            <span class="keywordtype">int</span>        n_pixels )
+<a name="l01460"></a>01460 {
+<a name="l01461"></a>01461     cpl_image * returnImage=NULL ;
+<a name="l01462"></a>01462     <span class="keywordtype">float</span>* neighbors=NULL ;
+<a name="l01463"></a>01463     <span class="keywordtype">float</span> sum=0;
+<a name="l01464"></a>01464     <span class="keywordtype">float</span> mean=0;
+<a name="l01465"></a>01465     <span class="keywordtype">int</span> i=0;
+<a name="l01466"></a>01466     <span class="keywordtype">int</span> j=0;
+<a name="l01467"></a>01467     <span class="keywordtype">int</span> k=0;
+<a name="l01468"></a>01468     <span class="keywordtype">int</span> row=0;
+<a name="l01469"></a>01469     <span class="keywordtype">int</span> col=0;
+<a name="l01470"></a>01470     <span class="keywordtype">int</span> n_valid=0;
+<a name="l01471"></a>01471     <span class="keywordtype">int</span> agreed=0;
+<a name="l01472"></a>01472 
+<a name="l01473"></a>01473     <span class="keywordtype">int</span> ilx=0;
+<a name="l01474"></a>01474     <span class="keywordtype">int</span> ily=0;
+<a name="l01475"></a>01475     <span class="keywordtype">int</span> mlx=0;
+<a name="l01476"></a>01476     <span class="keywordtype">int</span> mly=0;
+<a name="l01477"></a>01477     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l01478"></a>01478     <span class="keywordtype">float</span>* podata=NULL;
+<a name="l01479"></a>01479     <span class="keywordtype">float</span>* pmdata=NULL;
+<a name="l01480"></a>01480 
+<a name="l01481"></a>01481     <span class="keywordflow">if</span> ( NULL == im )
+<a name="l01482"></a>01482     {
+<a name="l01483"></a>01483         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"sorry, no input image given!"</span>) ;
+<a name="l01484"></a>01484         <span class="keywordflow">return</span> NULL ;
+<a name="l01485"></a>01485     }
+<a name="l01486"></a>01486     ilx=cpl_image_get_size_x(im);
+<a name="l01487"></a>01487     ily=cpl_image_get_size_y(im);
+<a name="l01488"></a>01488     pidata=cpl_image_get_data_float(im);
+<a name="l01489"></a>01489 
+<a name="l01490"></a>01490     <span class="keywordflow">if</span> ( NULL == mask )
+<a name="l01491"></a>01491     {
+<a name="l01492"></a>01492         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"sorry, no mask image given!"</span>) ;
+<a name="l01493"></a>01493         <span class="keywordflow">return</span> NULL ;
+<a name="l01494"></a>01494     }
+<a name="l01495"></a>01495 
+<a name="l01496"></a>01496     mlx=cpl_image_get_size_x(mask);
+<a name="l01497"></a>01497     mly=cpl_image_get_size_y(mask);
+<a name="l01498"></a>01498     pmdata=cpl_image_get_data_float(mask);
+<a name="l01499"></a>01499 
+<a name="l01500"></a>01500     <span class="keywordflow">if</span> ( mlx != ilx || mly != mly )
+<a name="l01501"></a>01501     {
+<a name="l01502"></a>01502         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"images not compatible !"</span>) ;
+<a name="l01503"></a>01503         <span class="keywordflow">return</span> NULL ;
+<a name="l01504"></a>01504     }
+<a name="l01505"></a>01505 
+<a name="l01506"></a>01506     <span class="keywordflow">if</span> ( max_radius <= 0 )
+<a name="l01507"></a>01507     {
+<a name="l01508"></a>01508         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"wrong number of pixels for maximal "</span>
+<a name="l01509"></a>01509                         <span class="stringliteral">"search radius given!"</span>) ;
+<a name="l01510"></a>01510         <span class="keywordflow">return</span> NULL ;
+<a name="l01511"></a>01511     }
+<a name="l01512"></a>01512 
+<a name="l01513"></a>01513     <span class="keywordflow">if</span> ( n_pixels <= 2 )
+<a name="l01514"></a>01514     {
+<a name="l01515"></a>01515         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"wrong number of pixels used "</span>
+<a name="l01516"></a>01516                         <span class="stringliteral">"for interpolation given!"</span>) ;
+<a name="l01517"></a>01517         <span class="keywordflow">return</span> NULL ;
+<a name="l01518"></a>01518     }
+<a name="l01519"></a>01519 
+<a name="l01520"></a>01520     returnImage = cpl_image_duplicate ( im ) ;
+<a name="l01521"></a>01521     podata=cpl_image_get_data_float(returnImage);
+<a name="l01522"></a>01522 
+<a name="l01523"></a>01523     <span class="comment">/* go through the columns and rows of the input and mask image */</span>
+<a name="l01524"></a>01524     neighbors=cpl_calloc(4*max_radius*max_radius,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l01525"></a>01525 
+<a name="l01526"></a>01526     <span class="keywordflow">for</span> ( col = 0 ; col < ilx ; col++ )
+<a name="l01527"></a>01527     {
+<a name="l01528"></a>01528         <span class="keywordflow">for</span> ( row = 0 ; row < ily ; row++ )
+<a name="l01529"></a>01529         {
+<a name="l01530"></a>01530             <span class="comment">/* look for the ZEROS that means the detected bad pixels */</span>
+<a name="l01531"></a>01531             <span class="keywordflow">if</span> ( isnan(pmdata[col+row*ilx]) || pmdata[col+row*ilx] == 0. )
+<a name="l01532"></a>01532             {
+<a name="l01533"></a>01533                 <span class="comment">/* now the neighbors must be considered */</span>
+<a name="l01534"></a>01534                 n_valid = 0 ;
+<a name="l01535"></a>01535                 agreed  = 0 ;
+<a name="l01536"></a>01536                 <span class="keywordflow">for</span> ( j = 1 ; j <= max_radius ; j++ )
+<a name="l01537"></a>01537                 {
+<a name="l01538"></a>01538 
+<a name="l01539"></a>01539                     <span class="comment">/* go through the left column */</span>
+<a name="l01540"></a>01540                     <span class="keywordflow">for</span> ( k = -j ; k < j ; k++ )
+<a name="l01541"></a>01541                     {
+<a name="l01542"></a>01542                         <span class="keywordflow">if</span> ( col-j >= 0 && row+k < ily && row+k >= 0 )
+<a name="l01543"></a>01543                         {
+<a name="l01544"></a>01544                             <span class="keywordflow">if</span> ( !isnan(pmdata[col-j+(row+k)*mlx]) ||
+<a name="l01545"></a>01545                                  pmdata[col-j+(row+k)*mlx] != 0 )
+<a name="l01546"></a>01546                             {
+<a name="l01547"></a>01547                                 neighbors[n_valid]=pidata[col-j+(row+k)*ilx] ;
+<a name="l01548"></a>01548                                 n_valid++ ;
+<a name="l01549"></a>01549                             }
+<a name="l01550"></a>01550                         }
+<a name="l01551"></a>01551                     }
+<a name="l01552"></a>01552 
+<a name="l01553"></a>01553                     <span class="comment">/* go through the upper row */</span>
+<a name="l01554"></a>01554                     <span class="keywordflow">for</span> ( k = -j ; k < j ; k++ )
+<a name="l01555"></a>01555                     {
+<a name="l01556"></a>01556                         <span class="keywordflow">if</span> ( col+k < ilx && col+k >= 0 && row+j < ily )
+<a name="l01557"></a>01557                         {
+<a name="l01558"></a>01558                             <span class="keywordflow">if</span> ( !isnan(pmdata[col+k+(row+j)*mlx]) ||
+<a name="l01559"></a>01559                                  pmdata[col+k+(row+j)*mlx] != 0. )
+<a name="l01560"></a>01560                             {
+<a name="l01561"></a>01561                                 neighbors[n_valid]=pidata[col+k+(row+j)*ilx] ;
+<a name="l01562"></a>01562                                 n_valid++ ;
+<a name="l01563"></a>01563                             }
+<a name="l01564"></a>01564                         }
+<a name="l01565"></a>01565                     }
+<a name="l01566"></a>01566 
+<a name="l01567"></a>01567                     <span class="comment">/* go through the right column */</span>
+<a name="l01568"></a>01568                     <span class="keywordflow">for</span> ( k = -j ; k < j ; k++ )
+<a name="l01569"></a>01569                     {
+<a name="l01570"></a>01570                         <span class="keywordflow">if</span> ( col+j < ilx  && row-k >= 0 && row-k < ily )
+<a name="l01571"></a>01571                         {
+<a name="l01572"></a>01572                             <span class="keywordflow">if</span> ( !isnan(pmdata[col+j+(row-k)*mlx]) ||
+<a name="l01573"></a>01573                                  pmdata[col+j+(row-k)*mlx] != 0. )
+<a name="l01574"></a>01574                             {
+<a name="l01575"></a>01575                                 neighbors[n_valid]=pidata[col+j+(row-k)*ilx] ;
+<a name="l01576"></a>01576                                 n_valid++ ;
+<a name="l01577"></a>01577                             }
+<a name="l01578"></a>01578                         }
+<a name="l01579"></a>01579                     }
+<a name="l01580"></a>01580 
+<a name="l01581"></a>01581                     <span class="comment">/* go through the lower row */</span>
+<a name="l01582"></a>01582                     <span class="keywordflow">for</span> ( k = -j ; k < j ; k++ )
+<a name="l01583"></a>01583                     {
+<a name="l01584"></a>01584                         <span class="keywordflow">if</span> ( col-k >= 0 && col-k < ilx && row-j < ily )
+<a name="l01585"></a>01585                         {
+<a name="l01586"></a>01586                             <span class="keywordflow">if</span> ( !isnan(pmdata[col-k+(row-j)*mlx]) ||
+<a name="l01587"></a>01587                                  pmdata[col-k+(row-j)*mlx] != 0. )
+<a name="l01588"></a>01588                             {
+<a name="l01589"></a>01589                                 neighbors[n_valid]=pidata[col-k+(row-j)*ilx] ;
+<a name="l01590"></a>01590                                 n_valid++ ;
+<a name="l01591"></a>01591                             }
+<a name="l01592"></a>01592                         }
+<a name="l01593"></a>01593                     }
+<a name="l01594"></a>01594 
+<a name="l01595"></a>01595                     <span class="comment">/* control if the breaking criteria is fullfilled */</span>
+<a name="l01596"></a>01596                     <span class="keywordflow">if</span> ( n_valid >= n_pixels )
+<a name="l01597"></a>01597                     {
+<a name="l01598"></a>01598                         agreed = 1 ;
+<a name="l01599"></a>01599                         break ;
+<a name="l01600"></a>01600                     }
+<a name="l01601"></a>01601                     <span class="comment">/* do a break if more than 2 nearest neighbors are found */</span>
+<a name="l01602"></a>01602                     <span class="keywordflow">if</span> ( j == 1 && n_valid >= 2 )
+<a name="l01603"></a>01603                     {
+<a name="l01604"></a>01604                         agreed = 1 ;
+<a name="l01605"></a>01605                         break ;
+<a name="l01606"></a>01606                     }
+<a name="l01607"></a>01607                 }
+<a name="l01608"></a>01608                 <span class="keywordflow">if</span> ( n_valid < n_pixels && agreed == 0 )
+<a name="l01609"></a>01609                 {
+<a name="l01610"></a>01610                     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"not enough valid neighbors found to "</span>
+<a name="l01611"></a>01611                                     <span class="stringliteral">"interpolate bad pixel in col: "</span>
+<a name="l01612"></a>01612                                     <span class="stringliteral">"%d, row: %d"</span>, col, row ) ;
+<a name="l01613"></a>01613                     <span class="keywordflow">return</span> NULL ;
+<a name="l01614"></a>01614                 }
+<a name="l01615"></a>01615                 <span class="keywordflow">else</span>
+<a name="l01616"></a>01616                 {
+<a name="l01617"></a>01617                     <span class="comment">/* ------------------------------------------------------</span>
+<a name="l01618"></a>01618 <span class="comment">                     * take the mean of the valid neighboring pixels if less</span>
+<a name="l01619"></a>01619 <span class="comment">                     * than 9 valid pixels are available else take the</span>
+<a name="l01620"></a>01620 <span class="comment">                       sinfo_median.</span>
+<a name="l01621"></a>01621 <span class="comment">                     */</span>
+<a name="l01622"></a>01622                     <span class="keywordflow">if</span> ( n_valid <= 8 )
+<a name="l01623"></a>01623                     {
+<a name="l01624"></a>01624                         sum = 0. ;
+<a name="l01625"></a>01625 
+<a name="l01626"></a>01626                         <span class="keywordflow">for</span> ( i = 0 ; i < n_valid ; i++ )
+<a name="l01627"></a>01627                         {
+<a name="l01628"></a>01628                             sum += neighbors[i] ;
+<a name="l01629"></a>01629                         }
+<a name="l01630"></a>01630                         mean = sum / n_valid ;
+<a name="l01631"></a>01631 
+<a name="l01632"></a>01632                         podata[col+row*ilx] = mean ;
+<a name="l01633"></a>01633                     }
+<a name="l01634"></a>01634                     <span class="keywordflow">else</span>
+<a name="l01635"></a>01635                     {
+<a name="l01636"></a>01636                        podata[col+row*ilx]=sinfo_new_median(neighbors,n_valid);
+<a name="l01637"></a>01637                     }
+<a name="l01638"></a>01638                 }
+<a name="l01639"></a>01639             }
+<a name="l01640"></a>01640         }
+<a name="l01641"></a>01641     }
+<a name="l01642"></a>01642     cpl_free(neighbors);
+<a name="l01643"></a>01643     <span class="keywordflow">return</span> returnImage ;
+<a name="l01644"></a>01644 }
+<a name="l01645"></a>01645 
+<a name="l01646"></a>01646 
+<a name="l01669"></a>01669 cpl_image * sinfo_interpol_source_image ( cpl_image * im,
+<a name="l01670"></a>01670                                  cpl_image * mask,
+<a name="l01671"></a>01671                                  <span class="keywordtype">int</span>        max_rad,
+<a name="l01672"></a>01672                                  <span class="keywordtype">float</span>   ** slit_edges )
+<a name="l01673"></a>01673 {
+<a name="l01674"></a>01674     cpl_image * returnImage=NULL ;
+<a name="l01675"></a>01675     <span class="keywordtype">float</span> validpixel[6] ;
+<a name="l01676"></a>01676     <span class="keywordtype">float</span> sum=0 ;
+<a name="l01677"></a>01677     <span class="keywordtype">int</span> n=0;
+<a name="l01678"></a>01678     <span class="keywordtype">int</span> row=0;
+<a name="l01679"></a>01679     <span class="keywordtype">int</span> col=0;
+<a name="l01680"></a>01680     <span class="keywordtype">int</span> i=0;
+<a name="l01681"></a>01681     <span class="keywordtype">int</span> k=0;
+<a name="l01682"></a>01682     <span class="keywordtype">int</span> slitlet=0;
+<a name="l01683"></a>01683     <span class="keywordtype">int</span> n_slitlets=0;
+<a name="l01684"></a>01684     <span class="keywordtype">int</span> ilx=0;
+<a name="l01685"></a>01685     <span class="keywordtype">int</span> ily=0;
+<a name="l01686"></a>01686     <span class="keywordtype">int</span> mlx=0;
+<a name="l01687"></a>01687     <span class="keywordtype">int</span> mly=0;
+<a name="l01688"></a>01688 
+<a name="l01689"></a>01689     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l01690"></a>01690     <span class="keywordtype">float</span>* podata=NULL;
+<a name="l01691"></a>01691     <span class="keywordtype">float</span>* pmdata=NULL;
+<a name="l01692"></a>01692 
+<a name="l01693"></a>01693 
+<a name="l01694"></a>01694     <span class="keywordflow">if</span> ( NULL == im )
+<a name="l01695"></a>01695     {
+<a name="l01696"></a>01696         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"sorry, no input image given!"</span>) ;
+<a name="l01697"></a>01697         <span class="keywordflow">return</span> NULL ;
+<a name="l01698"></a>01698     }
+<a name="l01699"></a>01699     ilx=cpl_image_get_size_x(im);
+<a name="l01700"></a>01700     ily=cpl_image_get_size_y(im);
+<a name="l01701"></a>01701     pidata=cpl_image_get_data_float(im);
+<a name="l01702"></a>01702 
+<a name="l01703"></a>01703     <span class="keywordflow">if</span> ( NULL == mask )
+<a name="l01704"></a>01704     {
+<a name="l01705"></a>01705         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"sorry, no bad pixel mask image given!"</span>) ;
+<a name="l01706"></a>01706         <span class="keywordflow">return</span> NULL ;
+<a name="l01707"></a>01707     }
+<a name="l01708"></a>01708     mlx=cpl_image_get_size_x(mask);
+<a name="l01709"></a>01709     mly=cpl_image_get_size_y(mask);
+<a name="l01710"></a>01710     pmdata=cpl_image_get_data_float(mask);
+<a name="l01711"></a>01711 
+<a name="l01712"></a>01712     <span class="keywordflow">if</span> ( mlx != ilx || mly != ily )
+<a name="l01713"></a>01713     {
+<a name="l01714"></a>01714         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"images not compatible in size!"</span>) ;
+<a name="l01715"></a>01715         <span class="keywordflow">return</span> NULL ;
+<a name="l01716"></a>01716     }
+<a name="l01717"></a>01717 
+<a name="l01718"></a>01718     <span class="keywordflow">if</span> ( max_rad < 1 )
+<a name="l01719"></a>01719     {
+<a name="l01720"></a>01720         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"sorry, wrong maximum distance given!"</span>) ;
+<a name="l01721"></a>01721         <span class="keywordflow">return</span> NULL ;
+<a name="l01722"></a>01722     }
+<a name="l01723"></a>01723 
+<a name="l01724"></a>01724     <span class="keywordflow">if</span> ( slit_edges == NULL )
+<a name="l01725"></a>01725     {
+<a name="l01726"></a>01726         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"sorry, array slit_edges is empty!"</span>) ;
+<a name="l01727"></a>01727         <span class="keywordflow">return</span> NULL ;
+<a name="l01728"></a>01728     }
+<a name="l01729"></a>01729 
+<a name="l01730"></a>01730     <span class="comment">/* determine the number of slitlets */</span>
+<a name="l01731"></a>01731     n_slitlets = N_SLITLETS ;
+<a name="l01732"></a>01732 
+<a name="l01733"></a>01733     <span class="comment">/* copy the original image in the image that will be returned */</span>
+<a name="l01734"></a>01734     returnImage = cpl_image_duplicate( im ) ;
+<a name="l01735"></a>01735     podata=cpl_image_get_data_float(returnImage);
+<a name="l01736"></a>01736 
+<a name="l01737"></a>01737     <span class="comment">/* go through the rows and columns of the image and search for</span>
+<a name="l01738"></a>01738 <span class="comment">      the bad pixels */</span>
+<a name="l01739"></a>01739     <span class="keywordflow">for</span> ( row = 0 ; row < ily ; row++ )
+<a name="l01740"></a>01740     {
+<a name="l01741"></a>01741         <span class="keywordflow">for</span> ( col = 0 ; col < ilx ; col++ )
+<a name="l01742"></a>01742         {
+<a name="l01743"></a>01743             n = 0 ;
+<a name="l01744"></a>01744             <span class="keywordflow">if</span> ( isnan(pmdata[col + row*mlx]) ||
+<a name="l01745"></a>01745                  pmdata[col + row*mlx] == 0. ||
+<a name="l01746"></a>01746                  isnan(pidata[col + row*mlx]) )
+<a name="l01747"></a>01747             {
+<a name="l01748"></a>01748                 <span class="comment">/* look for the slitlet where the bad pixel is found */</span>
+<a name="l01749"></a>01749                 slitlet = -1000 ;
+<a name="l01750"></a>01750                 <span class="keywordflow">for</span> ( k = 0 ; k < n_slitlets ; k++ )
+<a name="l01751"></a>01751                 {
+<a name="l01752"></a>01752                     <span class="keywordflow">if</span> ( sinfo_new_nint(slit_edges[k][0]) <= col &&
+<a name="l01753"></a>01753                          sinfo_new_nint(slit_edges[k][1]) >= col )
+<a name="l01754"></a>01754                     {
+<a name="l01755"></a>01755                         slitlet = k ;
+<a name="l01756"></a>01756                     }
+<a name="l01757"></a>01757 <span class="comment">/* The following else statement is wrong, because in the</span>
+<a name="l01758"></a>01758 <span class="comment">     end slitlet will always be -1000</span>
+<a name="l01759"></a>01759 <span class="comment">            else</span>
+<a name="l01760"></a>01760 <span class="comment">                    {</span>
+<a name="l01761"></a>01761 <span class="comment">                        slitlet = -1000 ;</span>
+<a name="l01762"></a>01762 <span class="comment">                    }</span>
+<a name="l01763"></a>01763 <span class="comment">*/</span>
+<a name="l01764"></a>01764                 }
+<a name="l01765"></a>01765                 <span class="keywordflow">for</span> ( i = 0 ; i < 6 ; i++ )
+<a name="l01766"></a>01766                 {
+<a name="l01767"></a>01767                     validpixel[i] = 0. ;
+<a name="l01768"></a>01768                 }
+<a name="l01769"></a>01769                 <span class="comment">/* look for the valid nearest neighbors</span>
+<a name="l01770"></a>01770 <span class="comment">                   and collect them but only a maximum of 4 */</span>
+<a name="l01771"></a>01771                 <span class="keywordflow">for</span> ( i = 1 ; i <= max_rad ; i++ )
+<a name="l01772"></a>01772                 {
+<a name="l01773"></a>01773                     <span class="keywordflow">if</span> ( row + i < ily)
+<a name="l01774"></a>01774                     {
+<a name="l01775"></a>01775                         <span class="keywordflow">if</span> ( !isnan(pmdata[col + (row+i) * mlx])
+<a name="l01776"></a>01776                              && pmdata[col + (row+i) * mlx] != 0. &&
+<a name="l01777"></a>01777                                 !isnan(pidata[col + (row+i) * ilx]) )
+<a name="l01778"></a>01778                         {
+<a name="l01779"></a>01779                             validpixel[n] = pidata[col + (row+i) * ilx] ;
+<a name="l01780"></a>01780                             n++ ;
+<a name="l01781"></a>01781                         }
+<a name="l01782"></a>01782                     }
+<a name="l01783"></a>01783                     <span class="keywordflow">if</span> ( row - i >= 0 )
+<a name="l01784"></a>01784                     {
+<a name="l01785"></a>01785                         <span class="keywordflow">if</span> ( !isnan(pmdata[col + (row-i) * mlx])
+<a name="l01786"></a>01786                              && pmdata[col + (row-i) * mlx] != 0. &&
+<a name="l01787"></a>01787                                 !isnan(pidata[col + (row-i) * ilx]) )
+<a name="l01788"></a>01788                         {
+<a name="l01789"></a>01789                             validpixel[n] = pidata[col + (row-i) * ilx] ;
+<a name="l01790"></a>01790                             n++ ;
+<a name="l01791"></a>01791                         }
+<a name="l01792"></a>01792                     }
+<a name="l01793"></a>01793 
+<a name="l01794"></a>01794                     <span class="comment">/* be aware of the slitlet edges in the</span>
+<a name="l01795"></a>01795 <span class="comment">                       spatial direction */</span>
+<a name="l01796"></a>01796                     <span class="keywordflow">if</span> ( col + i < ilx )
+<a name="l01797"></a>01797                     {
+<a name="l01798"></a>01798                       <span class="keywordflow">if</span> (  slitlet != -1000 )
+<a name="l01799"></a>01799                       {
+<a name="l01800"></a>01800                          <span class="keywordflow">if</span> (col+i <= sinfo_new_nint(slit_edges[slitlet][1]) &&
+<a name="l01801"></a>01801                              !isnan(pmdata[col + i + row * mlx]) &&
+<a name="l01802"></a>01802                              pmdata[col + i + row * mlx] != 0. &&
+<a name="l01803"></a>01803                              !isnan(pidata[col + i + row * ilx]) )
+<a name="l01804"></a>01804                          {
+<a name="l01805"></a>01805                              validpixel[n] = pidata[col + i + row * ilx] ;
+<a name="l01806"></a>01806                              n++ ;
+<a name="l01807"></a>01807                          }
+<a name="l01808"></a>01808                       }
+<a name="l01809"></a>01809                     }
+<a name="l01810"></a>01810                     <span class="keywordflow">if</span> ( col - i >= 0 )
+<a name="l01811"></a>01811                     {
+<a name="l01812"></a>01812                       <span class="keywordflow">if</span> ( slitlet != -1000 )
+<a name="l01813"></a>01813                       {
+<a name="l01814"></a>01814                          <span class="keywordflow">if</span> (col-i >= sinfo_new_nint(slit_edges[slitlet][0]) &&
+<a name="l01815"></a>01815                              !isnan(pmdata[col - i + row * mlx]) &&
+<a name="l01816"></a>01816                              pmdata[col - i + row * mlx] != 0. &&
+<a name="l01817"></a>01817                              !isnan(pidata[col - i + row * ilx]) )
+<a name="l01818"></a>01818                          {
+<a name="l01819"></a>01819                              validpixel[n] = pidata[col - i + row * ilx] ;
+<a name="l01820"></a>01820                              n++ ;
+<a name="l01821"></a>01821                          }
+<a name="l01822"></a>01822                       }
+<a name="l01823"></a>01823                     }
+<a name="l01824"></a>01824 
+<a name="l01825"></a>01825                     <span class="keywordflow">if</span> ( i == 1 && n > 1 )
+<a name="l01826"></a>01826                     {
+<a name="l01827"></a>01827                         break ;
+<a name="l01828"></a>01828                     }
+<a name="l01829"></a>01829                     <span class="keywordflow">if</span> ( n > 2 )
+<a name="l01830"></a>01830                     {
+<a name="l01831"></a>01831                         break ;
+<a name="l01832"></a>01832                     }
+<a name="l01833"></a>01833                 }
+<a name="l01834"></a>01834 
+<a name="l01835"></a>01835                 <span class="keywordflow">if</span> ( n == 0 )
+<a name="l01836"></a>01836                 {
+<a name="l01837"></a>01837                     podata[col + row*ilx] = ZERO ;
+<a name="l01838"></a>01838             <span class="comment">/*sinfo_msg_warning("sinfo_interpolSourceImage:",</span>
+<a name="l01839"></a>01839 <span class="comment">                                        "bad pixel in column: %d and row: %d"</span>
+<a name="l01840"></a>01840 <span class="comment">                                        " could not be interpolated!",col,row);</span>
+<a name="l01841"></a>01841 <span class="comment">                             */</span>
+<a name="l01842"></a>01842                 }
+<a name="l01843"></a>01843                 <span class="keywordflow">else</span>
+<a name="l01844"></a>01844                 {
+<a name="l01845"></a>01845                     <span class="comment">/* now compute the mean and replace</span>
+<a name="l01846"></a>01846 <span class="comment">                       the bad pixel value by the mean */</span>
+<a name="l01847"></a>01847                     sum = 0. ;
+<a name="l01848"></a>01848                     <span class="keywordflow">for</span> ( i = 0 ; i < n ; i++ )
+<a name="l01849"></a>01849                     {
+<a name="l01850"></a>01850                         sum += validpixel[i] ;
+<a name="l01851"></a>01851                     }
+<a name="l01852"></a>01852                     podata[col + row*ilx] = sum/n ;
+<a name="l01853"></a>01853                 }
+<a name="l01854"></a>01854             }
+<a name="l01855"></a>01855         }
+<a name="l01856"></a>01856     }
+<a name="l01857"></a>01857 
+<a name="l01858"></a>01858     <span class="keywordflow">return</span> returnImage ;
+<a name="l01859"></a>01859 }
+<a name="l01860"></a>01860 
+<a name="l01870"></a>01870 cpl_image * sinfo_new_stack_row_to_image ( Vector * row, <span class="keywordtype">int</span> ly )
+<a name="l01871"></a>01871 {
+<a name="l01872"></a>01872     cpl_image * image=NULL;
+<a name="l01873"></a>01873     <span class="keywordtype">int</span>        col=0;
+<a name="l01874"></a>01874     <span class="keywordtype">int</span>        ro=0;
+<a name="l01875"></a>01875     <span class="keywordtype">float</span>* podata=NULL;
+<a name="l01876"></a>01876 
+<a name="l01877"></a>01877     <span class="keywordflow">if</span> ( row == NullVector )
+<a name="l01878"></a>01878     {
+<a name="l01879"></a>01879         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"Null sinfo_vector as input"</span> ) ;
+<a name="l01880"></a>01880         <span class="keywordflow">return</span> NULL ;
+<a name="l01881"></a>01881     }
+<a name="l01882"></a>01882     <span class="keywordflow">if</span> ( ly <= 1 )
+<a name="l01883"></a>01883     {
+<a name="l01884"></a>01884         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"wrong image length given"</span> ) ;
+<a name="l01885"></a>01885         <span class="keywordflow">return</span> NULL ;
+<a name="l01886"></a>01886     }
+<a name="l01887"></a>01887 
+<a name="l01888"></a>01888     <span class="comment">/* allocate memory */</span>
+<a name="l01889"></a>01889     <span class="keywordflow">if</span> (NULL == (image = cpl_image_new(row->n_elements ,ly,CPL_TYPE_FLOAT )) )
+<a name="l01890"></a>01890     {
+<a name="l01891"></a>01891         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"cannot allocate new image"</span> ) ;
+<a name="l01892"></a>01892         <span class="keywordflow">return</span> NULL ;
+<a name="l01893"></a>01893     }
+<a name="l01894"></a>01894     podata=cpl_image_get_data_float(image);
+<a name="l01895"></a>01895 
+<a name="l01896"></a>01896     <span class="keywordflow">for</span> ( col = 0 ; col < row -> n_elements ; col++ )
+<a name="l01897"></a>01897     {
+<a name="l01898"></a>01898         <span class="keywordflow">for</span> ( ro = 0 ; ro < ly ; ro++ )
+<a name="l01899"></a>01899         {
+<a name="l01900"></a>01900             podata[col + ro*ly] = row -> data[col] ;
+<a name="l01901"></a>01901         }
+<a name="l01902"></a>01902     }
+<a name="l01903"></a>01903     <span class="keywordflow">return</span> image ;
+<a name="l01904"></a>01904 }
+<a name="l01905"></a>01905 
+<a name="l01921"></a>01921 Stats * sinfo_new_image_stats_on_rectangle ( cpl_image * im,
+<a name="l01922"></a>01922                                 <span class="keywordtype">float</span>      loReject,
+<a name="l01923"></a>01923                                 <span class="keywordtype">float</span>      hiReject,
+<a name="l01924"></a>01924                                 <span class="keywordtype">int</span>        llx,
+<a name="l01925"></a>01925                                 <span class="keywordtype">int</span>        lly,
+<a name="l01926"></a>01926                                 <span class="keywordtype">int</span>        urx,
+<a name="l01927"></a>01927                                 <span class="keywordtype">int</span>        ury )
+<a name="l01928"></a>01928 {
+<a name="l01929"></a>01929     Stats * retstats=NULL;
+<a name="l01930"></a>01930     <span class="keywordtype">int</span> i=0 ;
+<a name="l01931"></a>01931     <span class="keywordtype">int</span> row=0;
+<a name="l01932"></a>01932     <span class="keywordtype">int</span> col=0;
+<a name="l01933"></a>01933     <span class="keywordtype">int</span> n=0;
+<a name="l01934"></a>01934     <span class="keywordtype">int</span> npix=0;
+<a name="l01935"></a>01935     <span class="keywordtype">int</span> lo_n=0;
+<a name="l01936"></a>01936     <span class="keywordtype">int</span> hi_n=0;
+<a name="l01937"></a>01937     <span class="keywordtype">double</span> pix_sum=0;
+<a name="l01938"></a>01938     <span class="keywordtype">double</span> sqr_sum=0;
+<a name="l01939"></a>01939     <span class="keywordtype">float</span> * pix_array=NULL;
+<a name="l01940"></a>01940     <span class="keywordtype">int</span> im_lx=0;
+<a name="l01941"></a>01941     <span class="keywordtype">int</span> im_ly=0;
+<a name="l01942"></a>01942     <span class="keywordtype">float</span>* pim=NULL;
+<a name="l01943"></a>01943 
+<a name="l01944"></a>01944     <span class="keywordflow">if</span> ( NULL == im )
+<a name="l01945"></a>01945     {
+<a name="l01946"></a>01946         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"sorry, no input image given!"</span>) ;
+<a name="l01947"></a>01947         <span class="keywordflow">return</span> NULL ;
+<a name="l01948"></a>01948     }
+<a name="l01949"></a>01949     <span class="keywordflow">if</span> ( loReject+hiReject >= 100. )
+<a name="l01950"></a>01950     {
+<a name="l01951"></a>01951         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"sorry, too much pixels rejected!"</span>) ;
+<a name="l01952"></a>01952         <span class="keywordflow">return</span> NULL ;
+<a name="l01953"></a>01953     }
+<a name="l01954"></a>01954     <span class="keywordflow">if</span> ( loReject < 0. || loReject >= 100. ||
+<a name="l01955"></a>01955          hiReject < 0. || hiReject >= 100. )
+<a name="l01956"></a>01956     {
+<a name="l01957"></a>01957         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"sorry, negative reject values!"</span>) ;
+<a name="l01958"></a>01958         <span class="keywordflow">return</span> NULL ;
+<a name="l01959"></a>01959     }
+<a name="l01960"></a>01960 
+<a name="l01961"></a>01961     im_lx=cpl_image_get_size_x(im);
+<a name="l01962"></a>01962     im_ly=cpl_image_get_size_y(im);
+<a name="l01963"></a>01963 
+<a name="l01964"></a>01964     <span class="keywordflow">if</span> ( llx < 0 || lly < 0 || urx < 0 || ury < 0 ||
+<a name="l01965"></a>01965          llx >= im_lx || lly >= im_ly || urx >= im_lx ||
+<a name="l01966"></a>01966          ury >= im_ly || ury <= lly || urx <= llx )
+<a name="l01967"></a>01967     {
+<a name="l01968"></a>01968         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"sorry, wrong pixel coordinates of rectangle!"</span>) ;
+<a name="l01969"></a>01969         <span class="keywordflow">return</span> NULL ;
+<a name="l01970"></a>01970     }
+<a name="l01971"></a>01971 
+<a name="l01972"></a>01972      <span class="comment">/* allocate memory */</span>
+<a name="l01973"></a>01973     retstats = (Stats*) cpl_calloc(1, <span class="keyword">sizeof</span>(Stats)) ;
+<a name="l01974"></a>01974     npix = (urx - llx + 1) * (ury - lly + 1) ;
+<a name="l01975"></a>01975     pix_array = (<span class="keywordtype">float</span>*) cpl_calloc ( npix, <span class="keyword">sizeof</span>(<span class="keywordtype">float</span>) ) ;
+<a name="l01976"></a>01976 
+<a name="l01977"></a>01977     <span class="comment">/*-------------------------------------------------------------------------</span>
+<a name="l01978"></a>01978 <span class="comment">     * go through the rectangle and copy the pixel values into an array.</span>
+<a name="l01979"></a>01979 <span class="comment">     */</span>
+<a name="l01980"></a>01980     n = 0 ;
+<a name="l01981"></a>01981     pim = cpl_image_get_data_float(im);
+<a name="l01982"></a>01982     <span class="keywordflow">for</span> ( row = lly ; row <= ury ; row++ )
+<a name="l01983"></a>01983     {
+<a name="l01984"></a>01984         <span class="keywordflow">for</span> ( col = llx ; col <= urx ; col++ )
+<a name="l01985"></a>01985         {
+<a name="l01986"></a>01986             <span class="keywordflow">if</span> ( !isnan(pim[col + row*im_lx]) )
+<a name="l01987"></a>01987             {
+<a name="l01988"></a>01988                 pix_array[n] = pim[col + row*im_lx] ;
+<a name="l01989"></a>01989                 n++ ;
+<a name="l01990"></a>01990             }
+<a name="l01991"></a>01991     }
+<a name="l01992"></a>01992     }
+<a name="l01993"></a>01993 
+<a name="l01994"></a>01994     npix = n;
+<a name="l01995"></a>01995     <span class="comment">/*if (n != npix)</span>
+<a name="l01996"></a>01996 <span class="comment">    {</span>
+<a name="l01997"></a>01997 <span class="comment">        sinfo_msg_error("the computed number of pixel equals "</span>
+<a name="l01998"></a>01998 <span class="comment">                        "not the counted number, impossible!") ;</span>
+<a name="l01999"></a>01999 <span class="comment">        cpl_free(retstats) ;</span>
+<a name="l02000"></a>02000 <span class="comment">        cpl_free(pix_array) ;</span>
+<a name="l02001"></a>02001 <span class="comment">        return NULL ;</span>
+<a name="l02002"></a>02002 <span class="comment">    }*/</span>
+<a name="l02003"></a>02003 
+<a name="l02004"></a>02004     <span class="comment">/* determining the clean mean is already done in the recipes */</span>
+<a name="l02005"></a>02005     <span class="keywordflow">if</span> ( FLT_MAX == (retstats->cleanmean = sinfo_new_clean_mean(pix_array,
+<a name="l02006"></a>02006                                            npix, loReject, hiReject)) )
+<a name="l02007"></a>02007     {
+<a name="l02008"></a>02008         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"sinfo_new_clean_mean() did not work!"</span>) ;
+<a name="l02009"></a>02009         cpl_free(retstats) ;
+<a name="l02010"></a>02010         cpl_free(pix_array) ;
+<a name="l02011"></a>02011         <span class="keywordflow">return</span> NULL ;
+<a name="l02012"></a>02012     }
+<a name="l02013"></a>02013 
+<a name="l02014"></a>02014     <span class="comment">/* now the clean standard deviation must be calculated */</span>
+<a name="l02015"></a>02015     <span class="comment">/* initialize sums */</span>
+<a name="l02016"></a>02016     lo_n = (int) (loReject / 100. * (<span class="keywordtype">float</span>)npix) ;
+<a name="l02017"></a>02017     hi_n = (int) (hiReject / 100. * (<span class="keywordtype">float</span>)npix) ;
+<a name="l02018"></a>02018     pix_sum = 0. ;
+<a name="l02019"></a>02019     sqr_sum = 0. ;
+<a name="l02020"></a>02020     n = 0 ;
+<a name="l02021"></a>02021     <span class="keywordflow">for</span> ( i = lo_n ; i <= npix - hi_n ; i++ )
+<a name="l02022"></a>02022     {
+<a name="l02023"></a>02023         pix_sum += (double)pix_array[i] ;
+<a name="l02024"></a>02024         sqr_sum += ((double)pix_array[i] * (<span class="keywordtype">double</span>)pix_array[i]) ;
+<a name="l02025"></a>02025         n++ ;
+<a name="l02026"></a>02026     }
+<a name="l02027"></a>02027 
+<a name="l02028"></a>02028     <span class="keywordflow">if</span> ( n == 0 )
+<a name="l02029"></a>02029     {
+<a name="l02030"></a>02030         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"number of clean pixels is zero!"</span>) ;
+<a name="l02031"></a>02031         cpl_free(retstats) ;
+<a name="l02032"></a>02032         cpl_free(pix_array) ;
+<a name="l02033"></a>02033         <span class="keywordflow">return</span> NULL ;
+<a name="l02034"></a>02034     }
+<a name="l02035"></a>02035     retstats -> npix = n ;
+<a name="l02036"></a>02036     pix_sum /= (double) n ;
+<a name="l02037"></a>02037     sqr_sum /= (double) n ;
+<a name="l02038"></a>02038     retstats -> cleanstdev = (float)sqrt(sqr_sum - pix_sum * pix_sum) ;
+<a name="l02039"></a>02039     cpl_free (pix_array) ;
+<a name="l02040"></a>02040     <span class="keywordflow">return</span> retstats ;
+<a name="l02041"></a>02041 }
+<a name="l02042"></a>02042 
+<a name="l02043"></a>02043 
+<a name="l02044"></a>02044 
+<a name="l02053"></a>02053 cpl_image * sinfo_new_normalize_to_central_pixel ( cpl_image * image )
+<a name="l02054"></a>02054 {
+<a name="l02055"></a>02055     <span class="keywordtype">int</span> col=0;
+<a name="l02056"></a>02056     <span class="keywordtype">int</span> row=0;
+<a name="l02057"></a>02057     <span class="keywordtype">int</span> i=0;
+<a name="l02058"></a>02058     <span class="keywordtype">int</span> n=0;
+<a name="l02059"></a>02059     <span class="keywordtype">float</span>* array=NULL ;
+<a name="l02060"></a>02060     <span class="keywordtype">float</span> divisor=0;
+<a name="l02061"></a>02061     cpl_image * retImage=NULL;
+<a name="l02062"></a>02062     <span class="keywordtype">int</span> ilx=0;
+<a name="l02063"></a>02063     <span class="keywordtype">int</span> ily=0;
+<a name="l02064"></a>02064     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l02065"></a>02065     <span class="keywordtype">float</span>* podata=NULL;
+<a name="l02066"></a>02066 
+<a name="l02067"></a>02067     <span class="keywordflow">if</span> ( image == NULL )
+<a name="l02068"></a>02068     {
+<a name="l02069"></a>02069         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no image given!"</span>) ;
+<a name="l02070"></a>02070         <span class="keywordflow">return</span> NULL ;
+<a name="l02071"></a>02071     }
+<a name="l02072"></a>02072     ilx=cpl_image_get_size_x(image);
+<a name="l02073"></a>02073     ily=cpl_image_get_size_y(image);
+<a name="l02074"></a>02074     pidata=cpl_image_get_data_float(image);
+<a name="l02075"></a>02075 
+<a name="l02076"></a>02076     retImage = cpl_image_duplicate(image) ;
+<a name="l02077"></a>02077     podata=cpl_image_get_data_float(retImage);
+<a name="l02078"></a>02078 
+<a name="l02079"></a>02079     n = 0 ;
+<a name="l02080"></a>02080     <span class="comment">/* go through the central two image rows and store</span>
+<a name="l02081"></a>02081 <span class="comment">       the values in an array */</span>
+<a name="l02082"></a>02082     array=cpl_calloc(2*ilx,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l02083"></a>02083 
+<a name="l02084"></a>02084     <span class="keywordflow">for</span> ( row = ily/2 ; row < ily/2+1 ; row++ )
+<a name="l02085"></a>02085     {
+<a name="l02086"></a>02086         <span class="keywordflow">for</span> ( col = 0 ; col < ilx ; col++ )
+<a name="l02087"></a>02087         {
+<a name="l02088"></a>02088             <span class="keywordflow">if</span> ( !isnan(pidata[col+ilx*row]) )
+<a name="l02089"></a>02089             {
+<a name="l02090"></a>02090                 array[n] = pidata[col+ilx*row] ;
+<a name="l02091"></a>02091                 n++ ;
+<a name="l02092"></a>02092             }
+<a name="l02093"></a>02093         }
+<a name="l02094"></a>02094     }
+<a name="l02095"></a>02095     <span class="comment">/* compute the sinfo_median of the central 2 spectral</span>
+<a name="l02096"></a>02096 <span class="comment">       values of all spatial pixels*/</span>
+<a name="l02097"></a>02097     <span class="keywordflow">if</span> ( isnan(divisor = sinfo_new_median(array, n) ) )
+<a name="l02098"></a>02098     {
+<a name="l02099"></a>02099         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no sinfo_median possible!"</span>) ;
+<a name="l02100"></a>02100         <span class="keywordflow">return</span> NULL ;
+<a name="l02101"></a>02101     }
+<a name="l02102"></a>02102     <span class="keywordflow">if</span> ( 0 == divisor )
+<a name="l02103"></a>02103     {
+<a name="l02104"></a>02104         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"cannot divide by 0"</span>) ;
+<a name="l02105"></a>02105         <span class="keywordflow">return</span> NULL ;
+<a name="l02106"></a>02106     }
+<a name="l02107"></a>02107 
+<a name="l02108"></a>02108     <span class="keywordflow">for</span> ( i = 0 ; i < (int) ilx*ily ; i++ )
+<a name="l02109"></a>02109     {
+<a name="l02110"></a>02110         <span class="keywordflow">if</span> ( isnan(pidata[i]) )
+<a name="l02111"></a>02111         {
+<a name="l02112"></a>02112             podata[i] = ZERO ;
+<a name="l02113"></a>02113         }
+<a name="l02114"></a>02114         <span class="keywordflow">else</span>
+<a name="l02115"></a>02115         {
+<a name="l02116"></a>02116             podata[i] = pidata[i]/divisor ;
+<a name="l02117"></a>02117         }
+<a name="l02118"></a>02118     }
+<a name="l02119"></a>02119     cpl_free(array);
+<a name="l02120"></a>02120     <span class="keywordflow">return</span> retImage ;
+<a name="l02121"></a>02121 }
+<a name="l02122"></a>02122 
+<a name="l02123"></a>02123 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l02152"></a>02152 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l02153"></a>02153 
+<a name="l02154"></a>02154 cpl_image *
+<a name="l02155"></a>02155 sinfo_new_mpe_shift_image(
+<a name="l02156"></a>02156     cpl_image    *    image_in,
+<a name="l02157"></a>02157     <span class="keywordtype">double</span>           shift_x,
+<a name="l02158"></a>02158     <span class="keywordtype">double</span>           shift_y,
+<a name="l02159"></a>02159     <span class="keywordtype">double</span>       *   interp_kernel)
+<a name="l02160"></a>02160 {
+<a name="l02161"></a>02161     cpl_image    *       shifted=NULL ;
+<a name="l02162"></a>02162     pixelvalue  *       first_pass=NULL ;
+<a name="l02163"></a>02163     pixelvalue  *       second_pass=NULL ;
+<a name="l02164"></a>02164     <span class="keywordtype">int</span>             samples = KERNEL_SAMPLES ;
+<a name="l02165"></a>02165     <span class="keywordtype">int</span>          i=0, j=0 ;
+<a name="l02166"></a>02166     <span class="keywordtype">double</span>           fx=0, fy=0 ;
+<a name="l02167"></a>02167     <span class="keywordtype">double</span>           rx=0, ry=0 ;
+<a name="l02168"></a>02168     <span class="keywordtype">int</span>             px=0, py=0 ;
+<a name="l02169"></a>02169     <span class="keywordtype">int</span>             tabx=0, taby=0 ;
+<a name="l02170"></a>02170     <span class="keywordtype">double</span>           value=0 ;
+<a name="l02171"></a>02171     <span class="keywordtype">size_t</span>          pos ;
+<a name="l02172"></a>02172     <span class="keyword">register</span> pixelvalue     *   pix ;
+<a name="l02173"></a>02173     <span class="keyword">register</span> pixelvalue     *   pixint ;
+<a name="l02174"></a>02174     <span class="keywordtype">int</span>             mid=0;
+<a name="l02175"></a>02175     <span class="keywordtype">double</span>          norm=0 ;
+<a name="l02176"></a>02176     <span class="keywordtype">double</span>       *      ker=NULL ;
+<a name="l02177"></a>02177     <span class="keywordtype">int</span>                         freeKernel = 1 ;
+<a name="l02178"></a>02178 
+<a name="l02179"></a>02179     <span class="keywordtype">int</span> ilx=0;
+<a name="l02180"></a>02180     <span class="keywordtype">int</span> ily=0;
+<a name="l02181"></a>02181     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l02182"></a>02182     <span class="keywordtype">float</span>* psdata=NULL;
+<a name="l02183"></a>02183 
+<a name="l02184"></a>02184 
+<a name="l02185"></a>02185     <span class="comment">/* error handling: test entries */</span>
+<a name="l02186"></a>02186     <span class="keywordflow">if</span> (image_in==NULL) <span class="keywordflow">return</span> NULL ;
+<a name="l02187"></a>02187 
+<a name="l02188"></a>02188     <span class="comment">/* Shifting by a zero offset returns a copy of the input image */</span>
+<a name="l02189"></a>02189     <span class="keywordflow">if</span> ((fabs(shift_x)<1e-2) && (fabs(shift_y)<1e-2))
+<a name="l02190"></a>02190       <span class="keywordflow">return</span> cpl_image_duplicate(image_in) ;
+<a name="l02191"></a>02191     ilx=cpl_image_get_size_x(image_in);
+<a name="l02192"></a>02192     ily=cpl_image_get_size_y(image_in);
+<a name="l02193"></a>02193     pidata=cpl_image_get_data_float(image_in);
+<a name="l02194"></a>02194 
+<a name="l02195"></a>02195 
+<a name="l02196"></a>02196         <span class="comment">/* See if a kernel needs to be generated */</span>
+<a name="l02197"></a>02197     <span class="keywordflow">if</span> (interp_kernel == NULL) {
+<a name="l02198"></a>02198         ker = sinfo_generate_interpolation_kernel(<span class="stringliteral">"default"</span>) ;
+<a name="l02199"></a>02199         <span class="keywordflow">if</span> (ker == NULL) {
+<a name="l02200"></a>02200             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"kernel generation failure:aborting resampling"</span>) ;
+<a name="l02201"></a>02201             <span class="keywordflow">return</span> NULL ;
+<a name="l02202"></a>02202         }
+<a name="l02203"></a>02203     } <span class="keywordflow">else</span> {
+<a name="l02204"></a>02204         ker = interp_kernel ;
+<a name="l02205"></a>02205         freeKernel = 0 ;
+<a name="l02206"></a>02206     }
+<a name="l02207"></a>02207 
+<a name="l02208"></a>02208     mid = (int)samples/(<span class="keywordtype">int</span>)2 ;
+<a name="l02209"></a>02209     first_pass = cpl_calloc(ilx, ily*<span class="keyword">sizeof</span>(pixelvalue)) ;
+<a name="l02210"></a>02210     shifted = cpl_image_new(ilx, ily,CPL_TYPE_FLOAT) ;
+<a name="l02211"></a>02211     psdata=cpl_image_get_data_float(shifted);
+<a name="l02212"></a>02212 
+<a name="l02213"></a>02213     second_pass = psdata ;
+<a name="l02214"></a>02214 
+<a name="l02215"></a>02215     pix = pidata ;
+<a name="l02216"></a>02216     <span class="keywordflow">if</span> ( ilx != 1 )
+<a name="l02217"></a>02217     {
+<a name="l02218"></a>02218     <span class="keywordflow">for</span> (j=0 ; j<ily ; j++)
+<a name="l02219"></a>02219         {
+<a name="l02220"></a>02220          <span class="keywordflow">for</span> (i=0 ; i<ilx ; i++) {
+<a name="l02221"></a>02221            fx = (double)i-shift_x ;
+<a name="l02222"></a>02222            px = (int)fx ;
+<a name="l02223"></a>02223            rx = fx - (double)px ;
+<a name="l02224"></a>02224            pos = px + j * ilx ;
+<a name="l02225"></a>02225 
+<a name="l02226"></a>02226            <span class="keywordflow">if</span> ((px>1) && (px<(ilx-2)))
+<a name="l02227"></a>02227            {
+<a name="l02228"></a>02228            tabx = (int)(fabs((<span class="keywordtype">double</span>)mid * rx)) ;
+<a name="l02229"></a>02229            <span class="comment">/* exclude blank (ZERO) pixels from interpolation */</span>
+<a name="l02230"></a>02230            <span class="keywordflow">if</span> (isnan(pix[pos]))
+<a name="l02231"></a>02231                {
+<a name="l02232"></a>02232                value = ZERO ;
+<a name="l02233"></a>02233                }
+<a name="l02234"></a>02234            <span class="keywordflow">else</span>
+<a name="l02235"></a>02235                {
+<a name="l02236"></a>02236                <span class="keywordflow">if</span> (isnan(pix[pos-1]))
+<a name="l02237"></a>02237                {
+<a name="l02238"></a>02238                pix[pos-1] = 0. ;
+<a name="l02239"></a>02239                }
+<a name="l02240"></a>02240                <span class="keywordflow">if</span> (isnan(pix[pos+1]))
+<a name="l02241"></a>02241                {
+<a name="l02242"></a>02242                pix[pos+1] = 0. ;
+<a name="l02243"></a>02243                }
+<a name="l02244"></a>02244                <span class="keywordflow">if</span> (isnan(pix[pos+2]))
+<a name="l02245"></a>02245                {
+<a name="l02246"></a>02246                pix[pos+2] = 0. ;
+<a name="l02247"></a>02247                }
+<a name="l02248"></a>02248 
+<a name="l02249"></a>02249                <span class="comment">/*</span>
+<a name="l02250"></a>02250 <span class="comment">            * Sum up over 4 closest pixel values,</span>
+<a name="l02251"></a>02251 <span class="comment">            * weighted by interpolation kernel values</span>
+<a name="l02252"></a>02252 <span class="comment">            */</span>
+<a name="l02253"></a>02253                value =     (double)pix[pos-1] * ker[mid+tabx] +
+<a name="l02254"></a>02254                (<span class="keywordtype">double</span>)pix[pos] * ker[tabx] +
+<a name="l02255"></a>02255                (double)pix[pos+1] * ker[mid-tabx] +
+<a name="l02256"></a>02256                (<span class="keywordtype">double</span>)pix[pos+2] * ker[samples-tabx-1] ;
+<a name="l02257"></a>02257                <span class="comment">/*</span>
+<a name="l02258"></a>02258 <span class="comment">            * Also sum up interpolation kernel coefficients</span>
+<a name="l02259"></a>02259 <span class="comment">            * for further normalization</span>
+<a name="l02260"></a>02260 <span class="comment">            */</span>
+<a name="l02261"></a>02261                norm =      (<span class="keywordtype">double</span>)ker[mid+tabx] +
+<a name="l02262"></a>02262                (<span class="keywordtype">double</span>)ker[tabx] +
+<a name="l02263"></a>02263                (<span class="keywordtype">double</span>)ker[mid-tabx] +
+<a name="l02264"></a>02264                (<span class="keywordtype">double</span>)ker[samples-tabx-1] ;
+<a name="l02265"></a>02265                if (fabs(norm) > 1e-4) {
+<a name="l02266"></a>02266                value /= norm ;
+<a name="l02267"></a>02267                }
+<a name="l02268"></a>02268                }
+<a name="l02269"></a>02269            } <span class="keywordflow">else</span> {
+<a name="l02270"></a>02270            value = ZERO ;
+<a name="l02271"></a>02271            }
+<a name="l02272"></a>02272            <span class="comment">/*</span>
+<a name="l02273"></a>02273 <span class="comment">        * There may be a problem of rounding here if pixelvalue</span>
+<a name="l02274"></a>02274 <span class="comment">        * has not enough bits to sustain the accuracy.</span>
+<a name="l02275"></a>02275 <span class="comment">        */</span>
+<a name="l02276"></a>02276            <span class="keywordflow">if</span> ( isnan(value) )
+<a name="l02277"></a>02277            {
+<a name="l02278"></a>02278            first_pass[i+j*ilx] = ZERO ;
+<a name="l02279"></a>02279            }
+<a name="l02280"></a>02280            <span class="keywordflow">else</span>
+<a name="l02281"></a>02281            {
+<a name="l02282"></a>02282            first_pass[i+j*ilx] = (pixelvalue)value ;
+<a name="l02283"></a>02283            }
+<a name="l02284"></a>02284          }
+<a name="l02285"></a>02285         }
+<a name="l02286"></a>02286     }
+<a name="l02287"></a>02287     <span class="keywordflow">else</span>
+<a name="l02288"></a>02288     {
+<a name="l02289"></a>02289     memcpy(first_pass,pix,ily*<span class="keyword">sizeof</span>(pixelvalue));
+<a name="l02290"></a>02290     }
+<a name="l02291"></a>02291 
+<a name="l02292"></a>02292     pixint = first_pass ;
+<a name="l02293"></a>02293     <span class="keywordflow">for</span> (i=0 ; i<ilx ; i++) {
+<a name="l02294"></a>02294         <span class="keywordflow">for</span> (j=0 ; j<ily ; j++) {
+<a name="l02295"></a>02295             fy = (double)j - shift_y ;
+<a name="l02296"></a>02296             py = (int)fy ;
+<a name="l02297"></a>02297             ry = fy - (double)py ;
+<a name="l02298"></a>02298             pos = i + py * ilx ;
+<a name="l02299"></a>02299 
+<a name="l02300"></a>02300             taby = (int)(fabs((<span class="keywordtype">double</span>)mid * ry)) ;
+<a name="l02301"></a>02301 
+<a name="l02302"></a>02302             <span class="keywordflow">if</span> ((py>(<span class="keywordtype">int</span>)1) && (py<(ily-2))) {
+<a name="l02303"></a>02303                 <span class="comment">/* exclude blank (ZERO) pixels from interpolation */</span>
+<a name="l02304"></a>02304                 <span class="keywordflow">if</span> (isnan(pixint[pos]) && ilx != 1 )
+<a name="l02305"></a>02305                 {
+<a name="l02306"></a>02306                     value = ZERO ;
+<a name="l02307"></a>02307                 }
+<a name="l02308"></a>02308                 <span class="keywordflow">else</span>
+<a name="l02309"></a>02309                 {
+<a name="l02310"></a>02310                     <span class="keywordflow">if</span> (isnan(pixint[pos-ilx]))
+<a name="l02311"></a>02311                     {
+<a name="l02312"></a>02312                         pixint[pos-ilx] = 0. ;
+<a name="l02313"></a>02313                     }
+<a name="l02314"></a>02314                     <span class="keywordflow">if</span> (isnan(pixint[pos+ilx]))
+<a name="l02315"></a>02315                     {
+<a name="l02316"></a>02316                         pixint[pos+ilx] = 0. ;
+<a name="l02317"></a>02317                     }
+<a name="l02318"></a>02318                     <span class="keywordflow">if</span> (isnan(pixint[pos+2*ilx]))
+<a name="l02319"></a>02319                     {
+<a name="l02320"></a>02320                         pixint[pos+2*ilx] = 0. ;
+<a name="l02321"></a>02321                     }
+<a name="l02322"></a>02322                     <span class="comment">/*</span>
+<a name="l02323"></a>02323 <span class="comment">                     * Sum up over 4 closest pixel values,</span>
+<a name="l02324"></a>02324 <span class="comment">                     * weighted by interpolation kernel values</span>
+<a name="l02325"></a>02325 <span class="comment">                     */</span>
+<a name="l02326"></a>02326                     value = (double)pixint[pos-ilx] * ker[mid+taby] +
+<a name="l02327"></a>02327                             (<span class="keywordtype">double</span>)pixint[pos] * ker[taby] +
+<a name="l02328"></a>02328                             (double)pixint[pos+ilx] * ker[mid-taby] +
+<a name="l02329"></a>02329                             (<span class="keywordtype">double</span>)pixint[pos+2*ilx]*ker[samples-taby-1];
+<a name="l02330"></a>02330                     <span class="comment">/*</span>
+<a name="l02331"></a>02331 <span class="comment">                     * Also sum up interpolation kernel coefficients</span>
+<a name="l02332"></a>02332 <span class="comment">                     * for further normalization</span>
+<a name="l02333"></a>02333 <span class="comment">                     */</span>
+<a name="l02334"></a>02334                     norm =      (<span class="keywordtype">double</span>)ker[mid+taby] +
+<a name="l02335"></a>02335                                 (<span class="keywordtype">double</span>)ker[taby] +
+<a name="l02336"></a>02336                                 (<span class="keywordtype">double</span>)ker[mid-taby] +
+<a name="l02337"></a>02337                                 (<span class="keywordtype">double</span>)ker[samples-taby-1] ;
+<a name="l02338"></a>02338 
+<a name="l02339"></a>02339                     if (fabs(norm) > 1e-4) {
+<a name="l02340"></a>02340                         value /= norm ;
+<a name="l02341"></a>02341                     }
+<a name="l02342"></a>02342                 }
+<a name="l02343"></a>02343             } <span class="keywordflow">else</span> {
+<a name="l02344"></a>02344                 value = ZERO ;
+<a name="l02345"></a>02345             }
+<a name="l02346"></a>02346             <span class="keywordflow">if</span> (isnan(value))
+<a name="l02347"></a>02347             {
+<a name="l02348"></a>02348                 second_pass[i+j*ilx] = ZERO ;
+<a name="l02349"></a>02349             }
+<a name="l02350"></a>02350             <span class="keywordflow">else</span>
+<a name="l02351"></a>02351             {
+<a name="l02352"></a>02352                 second_pass[i+j*ilx] = (pixelvalue)value ;
+<a name="l02353"></a>02353             }
+<a name="l02354"></a>02354         }
+<a name="l02355"></a>02355     }
+<a name="l02356"></a>02356 
+<a name="l02357"></a>02357     cpl_free(first_pass) ;
+<a name="l02358"></a>02358     <span class="keywordflow">if</span> (freeKernel)
+<a name="l02359"></a>02359         cpl_free(ker) ;
+<a name="l02360"></a>02360     <span class="keywordflow">return</span> shifted ;
+<a name="l02361"></a>02361 }
+<a name="l02362"></a>02362 
+<a name="l02363"></a>02363 
+<a name="l02364"></a>02364 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l02395"></a>02395 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l02396"></a>02396 
+<a name="l02397"></a>02397 <span class="keywordtype">void</span>
+<a name="l02398"></a>02398 sinfo_new_shift_image_in_cube(
+<a name="l02399"></a>02399     cpl_image     *   image_in,
+<a name="l02400"></a>02400     <span class="keywordtype">double</span>           shift_x,
+<a name="l02401"></a>02401     <span class="keywordtype">double</span>           shift_y,
+<a name="l02402"></a>02402     <span class="keywordtype">double</span>       *   interp_kernel,
+<a name="l02403"></a>02403     cpl_image     *   shifted,
+<a name="l02404"></a>02404     pixelvalue   *   first_pass)
+<a name="l02405"></a>02405 {
+<a name="l02406"></a>02406     pixelvalue  *       second_pass=NULL ;
+<a name="l02407"></a>02407     <span class="keywordtype">int</span>             samples = KERNEL_SAMPLES ;
+<a name="l02408"></a>02408     <span class="keywordtype">int</span>          i=0, j=0 ;
+<a name="l02409"></a>02409     <span class="keywordtype">double</span>           fx=0, fy=0 ;
+<a name="l02410"></a>02410     <span class="keywordtype">double</span>           rx=0, ry=0 ;
+<a name="l02411"></a>02411     <span class="keywordtype">int</span>             px=0, py=0 ;
+<a name="l02412"></a>02412     <span class="keywordtype">int</span>             tabx=0, taby=0 ;
+<a name="l02413"></a>02413     <span class="keywordtype">double</span>           value=0 ;
+<a name="l02414"></a>02414     <span class="keywordtype">size_t</span>          pos ;
+<a name="l02415"></a>02415     <span class="keyword">register</span> pixelvalue     *   pix ;
+<a name="l02416"></a>02416     <span class="keyword">register</span> pixelvalue     *   pixint ;
+<a name="l02417"></a>02417     <span class="keywordtype">int</span>             mid=0;
+<a name="l02418"></a>02418     <span class="keywordtype">double</span>          norm=0 ;
+<a name="l02419"></a>02419     <span class="keywordtype">double</span>       *      ker=NULL ;
+<a name="l02420"></a>02420     <span class="keywordtype">int</span>                         freeKernel = 1 ;
+<a name="l02421"></a>02421 
+<a name="l02422"></a>02422     <span class="keywordtype">int</span> ilx=0;
+<a name="l02423"></a>02423     <span class="keywordtype">int</span> ily=0;
+<a name="l02424"></a>02424     <span class="keywordtype">int</span> slx=0;
+<a name="l02425"></a>02425     <span class="keywordtype">int</span> sly=0;
+<a name="l02426"></a>02426     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l02427"></a>02427     <span class="keywordtype">float</span>* psdata=NULL;
+<a name="l02428"></a>02428 
+<a name="l02429"></a>02429     <span class="comment">/* error handling: test entries */</span>
+<a name="l02430"></a>02430         <span class="keywordflow">if</span> (image_in==NULL) shifted = NULL ;
+<a name="l02431"></a>02431         pidata=cpl_image_get_data_float(image_in);
+<a name="l02432"></a>02432         ilx=cpl_image_get_size_x(image_in);
+<a name="l02433"></a>02433         ily=cpl_image_get_size_y(image_in);
+<a name="l02434"></a>02434 
+<a name="l02435"></a>02435         shifted=cpl_image_new(ilx,ily,CPL_TYPE_FLOAT);
+<a name="l02436"></a>02436         slx=ilx;
+<a name="l02437"></a>02437         sly=ily;
+<a name="l02438"></a>02438 
+<a name="l02439"></a>02439         psdata=cpl_image_get_data_float(shifted);
+<a name="l02440"></a>02440 
+<a name="l02441"></a>02441         <span class="comment">/* Shifting by a zero offset returns a copy of the input image */</span>
+<a name="l02442"></a>02442         <span class="keywordflow">if</span> ((fabs(shift_x)<1e-2) && (fabs(shift_y)<1e-2))
+<a name="l02443"></a>02443                 memcpy(psdata,pidata, (<span class="keywordtype">size_t</span>) slx*sly * <span class="keyword">sizeof</span>(pixelvalue)) ;
+<a name="l02444"></a>02444 
+<a name="l02445"></a>02445         <span class="comment">/* See if a kernel needs to be generated */</span>
+<a name="l02446"></a>02446     <span class="keywordflow">if</span> (interp_kernel == NULL) {
+<a name="l02447"></a>02447         ker = sinfo_generate_interpolation_kernel(<span class="stringliteral">"default"</span>) ;
+<a name="l02448"></a>02448         <span class="keywordflow">if</span> (ker == NULL) {
+<a name="l02449"></a>02449             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"kernel generation failure:aborting resampling"</span>) ;
+<a name="l02450"></a>02450             shifted = NULL ;
+<a name="l02451"></a>02451         }
+<a name="l02452"></a>02452     } <span class="keywordflow">else</span> {
+<a name="l02453"></a>02453         ker = interp_kernel ;
+<a name="l02454"></a>02454         freeKernel = 0 ;
+<a name="l02455"></a>02455     }
+<a name="l02456"></a>02456 
+<a name="l02457"></a>02457     mid = (int)samples/(<span class="keywordtype">int</span>)2 ;
+<a name="l02458"></a>02458     second_pass = psdata ;
+<a name="l02459"></a>02459 
+<a name="l02460"></a>02460     pix = pidata ;
+<a name="l02461"></a>02461     <span class="keywordflow">for</span> (j=0 ; j<ily ; j++) {
+<a name="l02462"></a>02462         <span class="keywordflow">for</span> (i=1 ; i<ilx-2 ; i++) {
+<a name="l02463"></a>02463             fx = (double)i-shift_x ;
+<a name="l02464"></a>02464             px = (int)fx ;
+<a name="l02465"></a>02465             rx = fx - (double)px ;
+<a name="l02466"></a>02466 
+<a name="l02467"></a>02467             pos = px + j * ilx ;
+<a name="l02468"></a>02468 
+<a name="l02469"></a>02469             <span class="keywordflow">if</span> ((px>1) && (px<(ilx-2))) {
+<a name="l02470"></a>02470                 tabx = (int)(fabs((<span class="keywordtype">double</span>)mid * rx)) ;
+<a name="l02471"></a>02471                 <span class="comment">/* exclude blank (ZERO) pixels from interpolation */</span>
+<a name="l02472"></a>02472                 <span class="keywordflow">if</span> (isnan(pix[pos]))
+<a name="l02473"></a>02473                 {
+<a name="l02474"></a>02474                     value = ZERO ;
+<a name="l02475"></a>02475                 }
+<a name="l02476"></a>02476                 <span class="keywordflow">else</span>
+<a name="l02477"></a>02477                 {
+<a name="l02478"></a>02478                     <span class="keywordflow">if</span> (isnan(pix[pos-1]))
+<a name="l02479"></a>02479                     {
+<a name="l02480"></a>02480                         pix[pos-1] = 0. ;
+<a name="l02481"></a>02481                     }
+<a name="l02482"></a>02482                     <span class="keywordflow">if</span> (isnan(pix[pos+1]))
+<a name="l02483"></a>02483                     {
+<a name="l02484"></a>02484                         pix[pos+1] = 0. ;
+<a name="l02485"></a>02485                     }
+<a name="l02486"></a>02486                     <span class="keywordflow">if</span> (isnan(pix[pos+2]))
+<a name="l02487"></a>02487                     {
+<a name="l02488"></a>02488                         pix[pos+2] = 0. ;
+<a name="l02489"></a>02489                     }
+<a name="l02490"></a>02490 
+<a name="l02491"></a>02491                     <span class="comment">/*</span>
+<a name="l02492"></a>02492 <span class="comment">                     * Sum up over 4 closest pixel values,</span>
+<a name="l02493"></a>02493 <span class="comment">                     * weighted by interpolation kernel values</span>
+<a name="l02494"></a>02494 <span class="comment">                     */</span>
+<a name="l02495"></a>02495                     value =     (double)pix[pos-1] * ker[mid+tabx] +
+<a name="l02496"></a>02496                                 (<span class="keywordtype">double</span>)pix[pos] * ker[tabx] +
+<a name="l02497"></a>02497                                 (double)pix[pos+1] * ker[mid-tabx] +
+<a name="l02498"></a>02498                                 (<span class="keywordtype">double</span>)pix[pos+2] * ker[samples-tabx-1] ;
+<a name="l02499"></a>02499                     <span class="comment">/*</span>
+<a name="l02500"></a>02500 <span class="comment">                     * Also sum up interpolation kernel coefficients</span>
+<a name="l02501"></a>02501 <span class="comment">                     * for further normalization</span>
+<a name="l02502"></a>02502 <span class="comment">                     */</span>
+<a name="l02503"></a>02503                     norm =      (<span class="keywordtype">double</span>)ker[mid+tabx] +
+<a name="l02504"></a>02504                                 (<span class="keywordtype">double</span>)ker[tabx] +
+<a name="l02505"></a>02505                                 (<span class="keywordtype">double</span>)ker[mid-tabx] +
+<a name="l02506"></a>02506                                 (<span class="keywordtype">double</span>)ker[samples-tabx-1] ;
+<a name="l02507"></a>02507                     if (fabs(norm) > 1e-4) {
+<a name="l02508"></a>02508                         value /= norm ;
+<a name="l02509"></a>02509                     }
+<a name="l02510"></a>02510                 }
+<a name="l02511"></a>02511             } <span class="keywordflow">else</span> {
+<a name="l02512"></a>02512                 value = 0.0 ;
+<a name="l02513"></a>02513             }
+<a name="l02514"></a>02514             <span class="comment">/*</span>
+<a name="l02515"></a>02515 <span class="comment">             * There may be a problem of rounding here if pixelvalue</span>
+<a name="l02516"></a>02516 <span class="comment">             * has not enough bits to sustain the accuracy.</span>
+<a name="l02517"></a>02517 <span class="comment">             */</span>
+<a name="l02518"></a>02518             <span class="keywordflow">if</span> ( isnan(value) )
+<a name="l02519"></a>02519             {
+<a name="l02520"></a>02520                 first_pass[i+j*ilx] = ZERO ;
+<a name="l02521"></a>02521             }
+<a name="l02522"></a>02522             <span class="keywordflow">else</span>
+<a name="l02523"></a>02523             {
+<a name="l02524"></a>02524                 first_pass[i+j*ilx] = (pixelvalue)value ;
+<a name="l02525"></a>02525             }
+<a name="l02526"></a>02526         }
+<a name="l02527"></a>02527     }
+<a name="l02528"></a>02528     pixint = first_pass ;
+<a name="l02529"></a>02529     <span class="keywordflow">for</span> (i=0 ; i< ilx ; i++) {
+<a name="l02530"></a>02530         <span class="keywordflow">for</span> (j=1 ; j< ily-2 ; j++) {
+<a name="l02531"></a>02531             fy = (double)j - shift_y ;
+<a name="l02532"></a>02532             py = (int)fy ;
+<a name="l02533"></a>02533             ry = fy - (double)py ;
+<a name="l02534"></a>02534             pos = i + py * ilx ;
+<a name="l02535"></a>02535 
+<a name="l02536"></a>02536             taby = (int)(fabs((<span class="keywordtype">double</span>)mid * ry)) ;
+<a name="l02537"></a>02537 
+<a name="l02538"></a>02538             <span class="keywordflow">if</span> ((py>(<span class="keywordtype">int</span>)1) && (py<(ily-2))) {
+<a name="l02539"></a>02539                 <span class="comment">/* exclude blank (ZERO) pixels from interpolation */</span>
+<a name="l02540"></a>02540                 <span class="keywordflow">if</span> (isnan(pixint[pos]))
+<a name="l02541"></a>02541                 {
+<a name="l02542"></a>02542                     value = ZERO ;
+<a name="l02543"></a>02543                 }
+<a name="l02544"></a>02544                 <span class="keywordflow">else</span>
+<a name="l02545"></a>02545                 {
+<a name="l02546"></a>02546                     <span class="keywordflow">if</span> (isnan(pixint[pos-ilx]))
+<a name="l02547"></a>02547                     {
+<a name="l02548"></a>02548                         pixint[pos-ilx] = 0. ;
+<a name="l02549"></a>02549                     }
+<a name="l02550"></a>02550                     <span class="keywordflow">if</span> (isnan(pixint[pos+ilx]))
+<a name="l02551"></a>02551                     {
+<a name="l02552"></a>02552                         pixint[pos+ilx] = 0. ;
+<a name="l02553"></a>02553                     }
+<a name="l02554"></a>02554                     <span class="keywordflow">if</span> (isnan(pixint[pos+2*ilx]))
+<a name="l02555"></a>02555                     {
+<a name="l02556"></a>02556                         pixint[pos+2*ilx] = 0. ;
+<a name="l02557"></a>02557                     }
+<a name="l02558"></a>02558                     <span class="comment">/*</span>
+<a name="l02559"></a>02559 <span class="comment">                     * Sum up over 4 closest pixel values,</span>
+<a name="l02560"></a>02560 <span class="comment">                     * weighted by interpolation kernel values</span>
+<a name="l02561"></a>02561 <span class="comment">                     */</span>
+<a name="l02562"></a>02562                     value = (double)pixint[pos-ilx] * ker[mid+taby] +
+<a name="l02563"></a>02563                             (<span class="keywordtype">double</span>)pixint[pos] * ker[taby] +
+<a name="l02564"></a>02564                             (double)pixint[pos+ilx] * ker[mid-taby] +
+<a name="l02565"></a>02565                             (<span class="keywordtype">double</span>)pixint[pos+2*ilx]*ker[samples-taby-1];
+<a name="l02566"></a>02566                     <span class="comment">/*</span>
+<a name="l02567"></a>02567 <span class="comment">                     * Also sum up interpolation kernel coefficients</span>
+<a name="l02568"></a>02568 <span class="comment">                     * for further normalization</span>
+<a name="l02569"></a>02569 <span class="comment">                     */</span>
+<a name="l02570"></a>02570                     norm =      (<span class="keywordtype">double</span>)ker[mid+taby] +
+<a name="l02571"></a>02571                                 (<span class="keywordtype">double</span>)ker[taby] +
+<a name="l02572"></a>02572                                 (<span class="keywordtype">double</span>)ker[mid-taby] +
+<a name="l02573"></a>02573                                 (<span class="keywordtype">double</span>)ker[samples-taby-1] ;
+<a name="l02574"></a>02574 
+<a name="l02575"></a>02575                     if (fabs(norm) > 1e-4) {
+<a name="l02576"></a>02576                         value /= norm ;
+<a name="l02577"></a>02577                     }
+<a name="l02578"></a>02578                 }
+<a name="l02579"></a>02579             } <span class="keywordflow">else</span> {
+<a name="l02580"></a>02580           <span class="comment">/* value = 0.0 ; AMo: This affect slitlet #1 */</span>
+<a name="l02581"></a>02581             }
+<a name="l02582"></a>02582             <span class="keywordflow">if</span> (isnan(value))
+<a name="l02583"></a>02583             {
+<a name="l02584"></a>02584                 second_pass[i+j*ilx] = ZERO ;
+<a name="l02585"></a>02585             }
+<a name="l02586"></a>02586             <span class="keywordflow">else</span>
+<a name="l02587"></a>02587             {
+<a name="l02588"></a>02588                 second_pass[i+j*ilx] = (pixelvalue)value ;
+<a name="l02589"></a>02589             }
+<a name="l02590"></a>02590         }
+<a name="l02591"></a>02591     }
+<a name="l02592"></a>02592 
+<a name="l02593"></a>02593     <span class="keywordflow">if</span> (freeKernel)
+<a name="l02594"></a>02594         cpl_free(ker) ;
+<a name="l02595"></a>02595 }
+<a name="l02596"></a>02596 
+<a name="l02597"></a>02597 <span class="comment">/* function to delete the image statistics within python */</span>
+<a name="l02598"></a>02598 <span class="keywordtype">void</span> sinfo_new_del_Stats( Stats * st)
+<a name="l02599"></a>02599 {
+<a name="l02600"></a>02600     cpl_free (st) ;
+<a name="l02601"></a>02601 }
+<a name="l02602"></a>02602 
+<a name="l02609"></a>02609 cpl_image *
+<a name="l02610"></a>02610 sinfo_new_combine_masks ( cpl_image * firstMask, cpl_image * secondMask )
+<a name="l02611"></a>02611 {
+<a name="l02612"></a>02612     cpl_image * retMask=NULL ;
+<a name="l02613"></a>02613     <span class="keywordtype">int</span> n=0 ;
+<a name="l02614"></a>02614     <span class="keywordtype">int</span> olx=0;
+<a name="l02615"></a>02615     <span class="keywordtype">int</span> oly=0;
+<a name="l02616"></a>02616     <span class="keywordtype">float</span>* podata=NULL;
+<a name="l02617"></a>02617     <span class="keywordtype">float</span>* pm1data=NULL;
+<a name="l02618"></a>02618     <span class="keywordtype">float</span>* pm2data=NULL;
+<a name="l02619"></a>02619 
+<a name="l02620"></a>02620     <span class="keywordflow">if</span> ( firstMask == NULL || secondMask == NULL )
+<a name="l02621"></a>02621     {
+<a name="l02622"></a>02622         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"no input mask image given!"</span>) ;
+<a name="l02623"></a>02623         <span class="keywordflow">return</span> NULL ;
+<a name="l02624"></a>02624     }
+<a name="l02625"></a>02625     retMask = cpl_image_duplicate (firstMask) ;
+<a name="l02626"></a>02626     podata = cpl_image_get_data_float(retMask);
+<a name="l02627"></a>02627     pm1data = cpl_image_get_data_float(firstMask);
+<a name="l02628"></a>02628     pm2data = cpl_image_get_data_float(secondMask);
+<a name="l02629"></a>02629     olx=cpl_image_get_size_x(retMask);
+<a name="l02630"></a>02630     oly=cpl_image_get_size_y(retMask);
+<a name="l02631"></a>02631 
+<a name="l02632"></a>02632     <span class="keywordflow">for</span> ( n = 0 ; n < (int) olx*oly ; n++ )
+<a name="l02633"></a>02633     {
+<a name="l02634"></a>02634        <span class="keywordflow">if</span> ( podata[n] == 0. || pm2data[n] == 0. )
+<a name="l02635"></a>02635        {
+<a name="l02636"></a>02636            podata[n] = 0. ;
+<a name="l02637"></a>02637        }
+<a name="l02638"></a>02638        <span class="keywordflow">else</span>
+<a name="l02639"></a>02639        {
+<a name="l02640"></a>02640            podata[n] = 1. ;
+<a name="l02641"></a>02641        }
+<a name="l02642"></a>02642     }
+<a name="l02643"></a>02643     <span class="keywordflow">return</span> retMask ;
+<a name="l02644"></a>02644 }
+<a name="l02645"></a>02645 
+<a name="l02654"></a>02654 cpl_image * sinfo_new_slice_cube (cpl_imagelist * cube, <span class="keywordtype">int</span> x, <span class="keywordtype">int</span> y )
+<a name="l02655"></a>02655 {
+<a name="l02656"></a>02656     cpl_image * retImage=NULL ;
+<a name="l02657"></a>02657     <span class="keywordtype">int</span> col=0, row=0, z=0 ;
+<a name="l02658"></a>02658     <span class="keywordtype">int</span> inp=0;
+<a name="l02659"></a>02659     <span class="keywordtype">int</span> ilx=0;
+<a name="l02660"></a>02660     <span class="keywordtype">int</span> ily=0;
+<a name="l02661"></a>02661     cpl_image* img=NULL;
+<a name="l02662"></a>02662     <span class="keywordtype">float</span>* podata=NULL;
+<a name="l02663"></a>02663     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l02664"></a>02664 
+<a name="l02665"></a>02665     <span class="keywordflow">if</span> ( cube == NULL )
+<a name="l02666"></a>02666     {
+<a name="l02667"></a>02667         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no cube given!"</span>) ;
+<a name="l02668"></a>02668         <span class="keywordflow">return</span> NULL ;
+<a name="l02669"></a>02669     }
+<a name="l02670"></a>02670     <span class="keywordflow">if</span> ( x > 31 || y > 31 )
+<a name="l02671"></a>02671     {
+<a name="l02672"></a>02672         <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"wrong x or y values!"</span>) ;
+<a name="l02673"></a>02673     }
+<a name="l02674"></a>02674 
+<a name="l02675"></a>02675     img=cpl_imagelist_get(cube,0);
+<a name="l02676"></a>02676     ilx=cpl_image_get_size_x(img);
+<a name="l02677"></a>02677     ily=cpl_image_get_size_y(img);
+<a name="l02678"></a>02678     inp=cpl_imagelist_get_size(cube);
+<a name="l02679"></a>02679     <span class="keywordflow">if</span> ( x < 0 )
+<a name="l02680"></a>02680     {
+<a name="l02681"></a>02681         <span class="comment">/* allocate memory */</span>
+<a name="l02682"></a>02682         <span class="keywordflow">if</span> ( NULL == (retImage = cpl_image_new(ilx, inp, CPL_TYPE_FLOAT)) )
+<a name="l02683"></a>02683         {
+<a name="l02684"></a>02684             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"could not allocate memory!"</span>) ;
+<a name="l02685"></a>02685             <span class="keywordflow">return</span> NULL ;
+<a name="l02686"></a>02686         }
+<a name="l02687"></a>02687         podata=cpl_image_get_data_float(retImage);
+<a name="l02688"></a>02688         <span class="keywordflow">for</span> ( z = 0 ; z < inp ; z++ )
+<a name="l02689"></a>02689         {
+<a name="l02690"></a>02690 
+<a name="l02691"></a>02691             pidata=cpl_image_get_data_float(cpl_imagelist_get(cube,z));
+<a name="l02692"></a>02692             <span class="keywordflow">for</span> ( col = 0 ; col < ilx ; col++ )
+<a name="l02693"></a>02693             {
+<a name="l02694"></a>02694                 podata[col+z*ilx] = pidata[col+y*ilx] ;
+<a name="l02695"></a>02695             }
+<a name="l02696"></a>02696         }
+<a name="l02697"></a>02697     }
+<a name="l02698"></a>02698     <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( y < 0 )
+<a name="l02699"></a>02699     {
+<a name="l02700"></a>02700         <span class="comment">/* allocate memory */</span>
+<a name="l02701"></a>02701         <span class="keywordflow">if</span> ( NULL == (retImage = cpl_image_new(ily, inp,CPL_TYPE_FLOAT)) )
+<a name="l02702"></a>02702         {
+<a name="l02703"></a>02703             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"could not allocate memory!"</span>) ;
+<a name="l02704"></a>02704             <span class="keywordflow">return</span> NULL ;
+<a name="l02705"></a>02705         }
+<a name="l02706"></a>02706         podata=cpl_image_get_data_float(retImage);
+<a name="l02707"></a>02707 
+<a name="l02708"></a>02708         <span class="keywordflow">for</span> ( z = 0 ; z < inp ; z++ )
+<a name="l02709"></a>02709         {
+<a name="l02710"></a>02710             pidata=cpl_image_get_data_float(cpl_imagelist_get(cube,z));
+<a name="l02711"></a>02711             <span class="keywordflow">for</span> ( row = 0 ; row < ily ; row++ )
+<a name="l02712"></a>02712             {
+<a name="l02713"></a>02713                 podata[row+z*ily] = pidata[x+row*ily] ;
+<a name="l02714"></a>02714             }
+<a name="l02715"></a>02715         }
+<a name="l02716"></a>02716     }
+<a name="l02717"></a>02717     <span class="keywordflow">else</span>
+<a name="l02718"></a>02718     {
+<a name="l02719"></a>02719         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"wrong input!"</span>) ;
+<a name="l02720"></a>02720         <span class="keywordflow">return</span> NULL ;
+<a name="l02721"></a>02721     }
+<a name="l02722"></a>02722     <span class="keywordflow">return</span> retImage ;
+<a name="l02723"></a>02723 }
+<a name="l02724"></a>02724 
+<a name="l02736"></a>02736 cpl_image * sinfo_new_div_images_robust ( cpl_image * im1, cpl_image * im2 )
+<a name="l02737"></a>02737 {
+<a name="l02738"></a>02738     cpl_image * retIm=NULL ;
+<a name="l02739"></a>02739     <span class="keywordtype">float</span> help=0 ;
+<a name="l02740"></a>02740     <span class="keywordtype">int</span> i=0 ;
+<a name="l02741"></a>02741     <span class="keywordtype">int</span> lx1=0;
+<a name="l02742"></a>02742     <span class="keywordtype">int</span> ly1=0;
+<a name="l02743"></a>02743     <span class="keywordtype">int</span> lx2=0;
+<a name="l02744"></a>02744     <span class="keywordtype">int</span> ly2=0;
+<a name="l02745"></a>02745 
+<a name="l02746"></a>02746     <span class="keywordtype">float</span>* p1data=NULL;
+<a name="l02747"></a>02747     <span class="keywordtype">float</span>* p2data=NULL;
+<a name="l02748"></a>02748     <span class="keywordtype">float</span>* podata=NULL;
+<a name="l02749"></a>02749 
+<a name="l02750"></a>02750     <span class="keywordflow">if</span> ( im1 == NULL || im2 == NULL )
+<a name="l02751"></a>02751     {
+<a name="l02752"></a>02752         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no input images given!"</span>) ;
+<a name="l02753"></a>02753         <span class="keywordflow">return</span> NULL ;
+<a name="l02754"></a>02754     }
+<a name="l02755"></a>02755     lx1=cpl_image_get_size_x(im1);
+<a name="l02756"></a>02756     ly1=cpl_image_get_size_y(im1);
+<a name="l02757"></a>02757     lx2=cpl_image_get_size_x(im2);
+<a name="l02758"></a>02758     ly2=cpl_image_get_size_y(im2);
+<a name="l02759"></a>02759     p1data=cpl_image_get_data_float(im1);
+<a name="l02760"></a>02760     p2data=cpl_image_get_data_float(im2);
+<a name="l02761"></a>02761 
+<a name="l02762"></a>02762     <span class="keywordflow">if</span> ( lx1 != lx2 || ly1 != ly2 )
+<a name="l02763"></a>02763     {
+<a name="l02764"></a>02764         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"images not compatible!"</span>) ;
+<a name="l02765"></a>02765         <span class="keywordflow">return</span> NULL ;
+<a name="l02766"></a>02766     }
+<a name="l02767"></a>02767     <span class="keywordflow">if</span> ( NULL == (retIm = cpl_image_new(lx1, ly1, CPL_TYPE_FLOAT)) )
+<a name="l02768"></a>02768     {
+<a name="l02769"></a>02769         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"could not allocate memory!"</span>) ;
+<a name="l02770"></a>02770         <span class="keywordflow">return</span> NULL ;
+<a name="l02771"></a>02771     }
+<a name="l02772"></a>02772     podata=cpl_image_get_data_float(retIm);
+<a name="l02773"></a>02773 
+<a name="l02774"></a>02774     <span class="keywordflow">for</span> ( i = 0 ; i < (int) lx2*ly2 ; i++ )
+<a name="l02775"></a>02775     {
+<a name="l02776"></a>02776         <span class="keywordflow">if</span> ( !isnan(p2data[i]) )
+<a name="l02777"></a>02777         {
+<a name="l02778"></a>02778             help = 1./p2data[i] ;
+<a name="l02779"></a>02779             <span class="keywordflow">if</span> (fabs( help )> THRESH )
+<a name="l02780"></a>02780             {
+<a name="l02781"></a>02781                help = 1. ;
+<a name="l02782"></a>02782             }
+<a name="l02783"></a>02783         }
+<a name="l02784"></a>02784         <span class="keywordflow">else</span>
+<a name="l02785"></a>02785         {
+<a name="l02786"></a>02786             help = ZERO ;
+<a name="l02787"></a>02787         }
+<a name="l02788"></a>02788         <span class="keywordflow">if</span> ( isnan(help) || isnan(p1data[i]) )
+<a name="l02789"></a>02789         {
+<a name="l02790"></a>02790             podata[i] = ZERO ;
+<a name="l02791"></a>02791         }
+<a name="l02792"></a>02792         <span class="keywordflow">else</span>
+<a name="l02793"></a>02793         {
+<a name="l02794"></a>02794             podata[i] = p1data[i] * help ;
+<a name="l02795"></a>02795         }
+<a name="l02796"></a>02796     }
+<a name="l02797"></a>02797     <span class="keywordflow">return</span> retIm ;
+<a name="l02798"></a>02798 }
+<a name="l02799"></a>02799 
+<a name="l02800"></a>02800 cpl_image * sinfo_new_null_edges ( cpl_image * image)
+<a name="l02801"></a>02801 {
+<a name="l02802"></a>02802     cpl_image * <span class="keyword">new</span>=NULL ;
+<a name="l02803"></a>02803     <span class="keywordtype">int</span> i=0,j=0 ;
+<a name="l02804"></a>02804     <span class="keywordtype">int</span> ilx=0;
+<a name="l02805"></a>02805     <span class="keywordtype">int</span> ily=0;
+<a name="l02806"></a>02806     <span class="keywordtype">int</span> olx=0;
+<a name="l02807"></a>02807     <span class="keywordtype">int</span> oly=0;
+<a name="l02808"></a>02808 
+<a name="l02809"></a>02809     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l02810"></a>02810     <span class="keywordtype">float</span>* podata=NULL;
+<a name="l02811"></a>02811 
+<a name="l02812"></a>02812     <span class="keywordflow">if</span> ( image == NULL )
+<a name="l02813"></a>02813     {
+<a name="l02814"></a>02814         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"no input image given!\n"</span>) ;
+<a name="l02815"></a>02815         <span class="keywordflow">return</span> NULL ;
+<a name="l02816"></a>02816     }
+<a name="l02817"></a>02817 
+<a name="l02818"></a>02818 
+<a name="l02819"></a>02819     <span class="keyword">new</span> = cpl_image_duplicate (image) ;
+<a name="l02820"></a>02820     ilx=cpl_image_get_size_x(image);
+<a name="l02821"></a>02821     ily=cpl_image_get_size_y(image);
+<a name="l02822"></a>02822     olx=cpl_image_get_size_x(<span class="keyword">new</span>);
+<a name="l02823"></a>02823     oly=cpl_image_get_size_y(<span class="keyword">new</span>);
+<a name="l02824"></a>02824     pidata=cpl_image_get_data_float(image);
+<a name="l02825"></a>02825     podata=cpl_image_get_data_float(<span class="keyword">new</span>);
+<a name="l02826"></a>02826 
+<a name="l02827"></a>02827     <span class="keywordflow">for</span> ( i = 0 ; i < olx ; i++ )
+<a name="l02828"></a>02828     {
+<a name="l02829"></a>02829         <span class="keywordflow">for</span> ( j = 0 ; j < 4 ; j++)
+<a name="l02830"></a>02830     {
+<a name="l02831"></a>02831         podata[i+j*olx]=0;
+<a name="l02832"></a>02832         podata[i+(oly-j-1)*olx]=0;
+<a name="l02833"></a>02833     }
+<a name="l02834"></a>02834     }
+<a name="l02835"></a>02835     <span class="keywordflow">for</span> ( i = 0 ; i < oly ; i++ )
+<a name="l02836"></a>02836     {
+<a name="l02837"></a>02837         <span class="keywordflow">for</span> ( j = 0 ; j < 4 ; j++)
+<a name="l02838"></a>02838     {
+<a name="l02839"></a>02839         podata[j+i*olx]=0;
+<a name="l02840"></a>02840         podata[(olx-j-1)+i*olx]=0;
+<a name="l02841"></a>02841     }
+<a name="l02842"></a>02842     }
+<a name="l02843"></a>02843     <span class="keywordflow">return</span> new ;
+<a name="l02844"></a>02844 }
+<a name="l02845"></a>02845 
+<a name="l02846"></a>02846 
+<a name="l02847"></a>02847 <span class="keywordtype">void</span> sinfo_new_used_cor_map( cpl_image *im, cpl_image *map)
+<a name="l02848"></a>02848 {
+<a name="l02849"></a>02849     <span class="keywordtype">int</span> i=0,j=0,loc_index=0;
+<a name="l02850"></a>02850     <span class="keywordtype">float</span> temp_array[2048];
+<a name="l02851"></a>02851     <span class="keywordtype">int</span> lx=cpl_image_get_size_x(im);
+<a name="l02852"></a>02852     <span class="keywordtype">int</span> ly=cpl_image_get_size_y(im);
+<a name="l02853"></a>02853     <span class="keywordtype">float</span>* pidata=cpl_image_get_data_float(im);
+<a name="l02854"></a>02854     <span class="keywordtype">float</span>* pmdata=cpl_image_get_data_float(map);
+<a name="l02855"></a>02855 
+<a name="l02856"></a>02856     <span class="keywordflow">for</span>( j=0; j<ly; j++)
+<a name="l02857"></a>02857     {
+<a name="l02858"></a>02858     <span class="keywordflow">for</span>( i=0;i<lx;i++)
+<a name="l02859"></a>02859         {
+<a name="l02860"></a>02860           loc_index = (int)pmdata[i+j*lx];
+<a name="l02861"></a>02861            temp_array[i] = pidata[loc_index+j*lx];
+<a name="l02862"></a>02862         }
+<a name="l02863"></a>02863     <span class="keywordflow">for</span>( i=0;i<lx;i++)
+<a name="l02864"></a>02864         {
+<a name="l02865"></a>02865           pidata[i+j*lx]= temp_array[i];
+<a name="l02866"></a>02866         }
+<a name="l02867"></a>02867     }
+<a name="l02868"></a>02868 }
+<a name="l02869"></a>02869 
+<a name="l02870"></a>02870 
+<a name="l02871"></a>02871 
+<a name="l02872"></a>02872 
+<a name="l02873"></a>02873 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l02896"></a>02896 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l02897"></a>02897 
+<a name="l02898"></a>02898 cpl_image *
+<a name="l02899"></a>02899 sinfo_new_shift_image(
+<a name="l02900"></a>02900     cpl_image    *    image_in,
+<a name="l02901"></a>02901     <span class="keywordtype">double</span>           shift_x,
+<a name="l02902"></a>02902     <span class="keywordtype">double</span>           shift_y,
+<a name="l02903"></a>02903     <span class="keywordtype">double</span>       *    interp_kernel)
+<a name="l02904"></a>02904 {
+<a name="l02905"></a>02905     cpl_image    *    shifted=NULL ;
+<a name="l02906"></a>02906     <span class="keywordtype">float</span>  *    first_pass=NULL ;
+<a name="l02907"></a>02907     <span class="keywordtype">float</span>  *    second_pass=NULL ;
+<a name="l02908"></a>02908     <span class="keywordtype">int</span>             samples = KERNEL_SAMPLES ;
+<a name="l02909"></a>02909     <span class="keywordtype">int</span>          i=0, j=0 ;
+<a name="l02910"></a>02910     <span class="keywordtype">double</span>           fx=0, fy=0 ;
+<a name="l02911"></a>02911     <span class="keywordtype">double</span>           rx=0, ry=0 ;
+<a name="l02912"></a>02912     <span class="keywordtype">int</span>             px=0, py=0 ;
+<a name="l02913"></a>02913     <span class="keywordtype">int</span>             tabx=0, taby=0 ;
+<a name="l02914"></a>02914     <span class="keywordtype">double</span>           value=0 ;
+<a name="l02915"></a>02915     <span class="keywordtype">size_t</span>          pos ;
+<a name="l02916"></a>02916     <span class="keyword">register</span> <span class="keywordtype">float</span>     *    pix=NULL ;
+<a name="l02917"></a>02917     <span class="keyword">register</span> <span class="keywordtype">float</span>     *    pixint=NULL ;
+<a name="l02918"></a>02918     <span class="keywordtype">int</span>             mid=0;
+<a name="l02919"></a>02919     <span class="keywordtype">double</span>          norm=0 ;
+<a name="l02920"></a>02920     <span class="keywordtype">double</span>       *    ker=NULL ;
+<a name="l02921"></a>02921     <span class="keywordtype">int</span>                freeKernel = 1 ;
+<a name="l02922"></a>02922     <span class="keywordtype">int</span> ilx=0;
+<a name="l02923"></a>02923     <span class="keywordtype">int</span> ily=0;
+<a name="l02924"></a>02924 
+<a name="l02925"></a>02925     <span class="comment">/* error handling: test entries */</span>
+<a name="l02926"></a>02926     <span class="keywordflow">if</span> (image_in==NULL) <span class="keywordflow">return</span> NULL ;
+<a name="l02927"></a>02927 
+<a name="l02928"></a>02928     <span class="comment">/* Shifting by a zero offset returns a copy of the input image */</span>
+<a name="l02929"></a>02929     <span class="keywordflow">if</span> ((fabs(shift_x)<1e-2) && (fabs(shift_y)<1e-2))
+<a name="l02930"></a>02930         <span class="keywordflow">return</span> cpl_image_duplicate(image_in) ;
+<a name="l02931"></a>02931 
+<a name="l02932"></a>02932     <span class="comment">/* See if a kernel needs to be generated */</span>
+<a name="l02933"></a>02933     <span class="keywordflow">if</span> (interp_kernel == NULL) {
+<a name="l02934"></a>02934         ker = sinfo_generate_interpolation_kernel(<span class="stringliteral">"default"</span>) ;
+<a name="l02935"></a>02935         <span class="keywordflow">if</span> (ker == NULL) {
+<a name="l02936"></a>02936             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"kernel generation failure: aborting resampling"</span>) ;
+<a name="l02937"></a>02937             <span class="keywordflow">return</span> NULL ;
+<a name="l02938"></a>02938         }
+<a name="l02939"></a>02939     } <span class="keywordflow">else</span> {
+<a name="l02940"></a>02940         ker = interp_kernel ;
+<a name="l02941"></a>02941         freeKernel = 0 ;
+<a name="l02942"></a>02942     }
+<a name="l02943"></a>02943 
+<a name="l02944"></a>02944     ilx=cpl_image_get_size_x(image_in);
+<a name="l02945"></a>02945     ily=cpl_image_get_size_y(image_in);
+<a name="l02946"></a>02946 
+<a name="l02947"></a>02947 
+<a name="l02948"></a>02948     pix = cpl_image_get_data_float(image_in);
+<a name="l02949"></a>02949     <span class="keywordflow">if</span> (pix)
+<a name="l02950"></a>02950     {
+<a name="l02951"></a>02951         mid = (int)samples/(<span class="keywordtype">int</span>)2 ;
+<a name="l02952"></a>02952         first_pass = cpl_calloc(ilx, ily*<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l02953"></a>02953         shifted = cpl_image_new(ilx, ily,CPL_TYPE_FLOAT) ;
+<a name="l02954"></a>02954         second_pass = cpl_image_get_data_float(shifted);
+<a name="l02955"></a>02955         <span class="keywordflow">for</span> (j=0 ; j<ily ; j++) {
+<a name="l02956"></a>02956             <span class="keywordflow">for</span> (i=1 ; i<ilx-2 ; i++) {
+<a name="l02957"></a>02957                 fx = (double)i-shift_x ;
+<a name="l02958"></a>02958                 px = (int)fx ;
+<a name="l02959"></a>02959                 rx = fx - (double)px ;
+<a name="l02960"></a>02960 
+<a name="l02961"></a>02961                 pos = px + j * ilx ;
+<a name="l02962"></a>02962 
+<a name="l02963"></a>02963                 <span class="keywordflow">if</span> ((px>1) && (px<(ilx-3))) {
+<a name="l02964"></a>02964                     tabx = (int)(fabs((<span class="keywordtype">double</span>)mid * rx)) ;
+<a name="l02965"></a>02965                     <span class="comment">/*</span>
+<a name="l02966"></a>02966 <span class="comment">                     * Sum up over 4 closest pixel values,</span>
+<a name="l02967"></a>02967 <span class="comment">                     * weighted by interpolation kernel values</span>
+<a name="l02968"></a>02968 <span class="comment">                     */</span>
+<a name="l02969"></a>02969                     value =     (double)pix[pos-1] * ker[mid+tabx] +
+<a name="l02970"></a>02970                                 (<span class="keywordtype">double</span>)pix[pos] * ker[tabx] +
+<a name="l02971"></a>02971                                 (double)pix[pos+1] * ker[mid-tabx] +
+<a name="l02972"></a>02972                                 (<span class="keywordtype">double</span>)pix[pos+2] * ker[samples-tabx-1] ;
+<a name="l02973"></a>02973                     <span class="comment">/*</span>
+<a name="l02974"></a>02974 <span class="comment">                     * Also sum up interpolation kernel coefficients</span>
+<a name="l02975"></a>02975 <span class="comment">                     * for further normalization</span>
+<a name="l02976"></a>02976 <span class="comment">                     */</span>
+<a name="l02977"></a>02977                     norm =      (<span class="keywordtype">double</span>)ker[mid+tabx] +
+<a name="l02978"></a>02978                                 (<span class="keywordtype">double</span>)ker[tabx] +
+<a name="l02979"></a>02979                                 (<span class="keywordtype">double</span>)ker[mid-tabx] +
+<a name="l02980"></a>02980                                 (<span class="keywordtype">double</span>)ker[samples-tabx-1] ;
+<a name="l02981"></a>02981                     if (fabs(norm) > 1e-4) {
+<a name="l02982"></a>02982                         value /= norm ;
+<a name="l02983"></a>02983                     }
+<a name="l02984"></a>02984                 } <span class="keywordflow">else</span> {
+<a name="l02985"></a>02985                     value = 0.0 ;
+<a name="l02986"></a>02986                 }
+<a name="l02987"></a>02987                 <span class="comment">/*</span>
+<a name="l02988"></a>02988 <span class="comment">                 * There may be a problem of rounding here if pixelvalue</span>
+<a name="l02989"></a>02989 <span class="comment">                 * has not enough bits to sustain the accuracy.</span>
+<a name="l02990"></a>02990 <span class="comment">                 */</span>
+<a name="l02991"></a>02991                 first_pass[i+j*ilx] = (float)value ;
+<a name="l02992"></a>02992             }
+<a name="l02993"></a>02993         }
+<a name="l02994"></a>02994         pixint = first_pass ;
+<a name="l02995"></a>02995         <span class="keywordflow">for</span> (i=0 ; i<ilx ; i++) {
+<a name="l02996"></a>02996             <span class="keywordflow">for</span> (j=1 ; j<ily-3 ; j++) {
+<a name="l02997"></a>02997                 fy = (double)j - shift_y ;
+<a name="l02998"></a>02998                 py = (int)fy ;
+<a name="l02999"></a>02999                 ry = fy - (double)py ;
+<a name="l03000"></a>03000                 pos = i + py * ilx ;
+<a name="l03001"></a>03001 
+<a name="l03002"></a>03002                 taby = (int)(fabs((<span class="keywordtype">double</span>)mid * ry)) ;
+<a name="l03003"></a>03003 
+<a name="l03004"></a>03004                 <span class="keywordflow">if</span> ((py>(<span class="keywordtype">int</span>)1) && (py<(ily-2))) {
+<a name="l03005"></a>03005                     <span class="comment">/*</span>
+<a name="l03006"></a>03006 <span class="comment">                     * Sum up over 4 closest pixel values,</span>
+<a name="l03007"></a>03007 <span class="comment">                     * weighted by interpolation kernel values</span>
+<a name="l03008"></a>03008 <span class="comment">                     */</span>
+<a name="l03009"></a>03009                     value = (double)pixint[pos-ilx] * ker[mid+taby] +
+<a name="l03010"></a>03010                             (<span class="keywordtype">double</span>)pixint[pos] * ker[taby] +
+<a name="l03011"></a>03011                             (double)pixint[pos+ilx] * ker[mid-taby] +
+<a name="l03012"></a>03012                             (<span class="keywordtype">double</span>)pixint[pos+2*ilx]*ker[samples-taby-1];
+<a name="l03013"></a>03013                     <span class="comment">/*</span>
+<a name="l03014"></a>03014 <span class="comment">                     * Also sum up interpolation kernel coefficients</span>
+<a name="l03015"></a>03015 <span class="comment">                     * for further normalization</span>
+<a name="l03016"></a>03016 <span class="comment">                     */</span>
+<a name="l03017"></a>03017                     norm =      (<span class="keywordtype">double</span>)ker[mid+taby] +
+<a name="l03018"></a>03018                                 (<span class="keywordtype">double</span>)ker[taby] +
+<a name="l03019"></a>03019                                 (<span class="keywordtype">double</span>)ker[mid-taby] +
+<a name="l03020"></a>03020                                 (<span class="keywordtype">double</span>)ker[samples-taby-1] ;
+<a name="l03021"></a>03021 
+<a name="l03022"></a>03022                     if (fabs(norm) > 1e-4) {
+<a name="l03023"></a>03023                         value /= norm ;
+<a name="l03024"></a>03024                     }
+<a name="l03025"></a>03025                 } <span class="keywordflow">else</span> {
+<a name="l03026"></a>03026                     value = 0.0 ;
+<a name="l03027"></a>03027                 }
+<a name="l03028"></a>03028                 second_pass[i+j*ilx] = (float)value ;
+<a name="l03029"></a>03029             }
+<a name="l03030"></a>03030         }
+<a name="l03031"></a>03031     }
+<a name="l03032"></a>03032     <span class="keywordflow">else</span>
+<a name="l03033"></a>03033     {
+<a name="l03034"></a>03034         cpl_msg_warning(cpl_func, <span class="stringliteral">"cannot get a data from an image"</span>);
+<a name="l03035"></a>03035     }
+<a name="l03036"></a>03036     cpl_free(first_pass) ;
+<a name="l03037"></a>03037     <span class="keywordflow">if</span> (freeKernel)
+<a name="l03038"></a>03038         cpl_free(ker) ;
+<a name="l03039"></a>03039     <span class="keywordflow">return</span> shifted ;
+<a name="l03040"></a>03040 }
+<a name="l03041"></a>03041 
+<a name="l03042"></a>03042 
+<a name="l03043"></a>03043 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l03057"></a>03057 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l03058"></a>03058 
+<a name="l03059"></a>03059 cpl_image *
+<a name="l03060"></a>03060 sinfo_image_hermite_interpol(cpl_image * inp)
+<a name="l03061"></a>03061 {
+<a name="l03062"></a>03062 
+<a name="l03063"></a>03063   <span class="comment">/*</span>
+<a name="l03064"></a>03064 <span class="comment">   @param xp     x-value to interpolate</span>
+<a name="l03065"></a>03065 <span class="comment">   @param x      x-values</span>
+<a name="l03066"></a>03066 <span class="comment">   @param y      y-values</span>
+<a name="l03067"></a>03067 <span class="comment">   @param n      array length</span>
+<a name="l03068"></a>03068 <span class="comment">   @param istart    (input/output) initial row (set to 0 to search all row)</span>
+<a name="l03069"></a>03069 <span class="comment"></span>
+<a name="l03070"></a>03070 <span class="comment">  sinfo_spline_hermite( double xp, const double *x,</span>
+<a name="l03071"></a>03071 <span class="comment">                        const double *y, int n, int *istart );</span>
+<a name="l03072"></a>03072 <span class="comment"></span>
+<a name="l03073"></a>03073 <span class="comment">  */</span>
+<a name="l03074"></a>03074   <span class="keywordtype">float</span>* pinp=NULL;
+<a name="l03075"></a>03075   <span class="keywordtype">float</span>* pout=NULL;
+<a name="l03076"></a>03076   <span class="keywordtype">int</span> sx=0;
+<a name="l03077"></a>03077   <span class="keywordtype">int</span> sy=0;
+<a name="l03078"></a>03078   <span class="keywordtype">int</span> i=0;
+<a name="l03079"></a>03079   <span class="keywordtype">int</span> j=0;
+<a name="l03080"></a>03080   <span class="keywordtype">int</span> r=5;
+<a name="l03081"></a>03081   <span class="keywordtype">int</span> k=0;
+<a name="l03082"></a>03082 
+<a name="l03083"></a>03083   cpl_image* out=NULL;
+<a name="l03084"></a>03084 
+<a name="l03085"></a>03085   cknull(inp,<span class="stringliteral">"Null in put image, exit"</span>);
+<a name="l03086"></a>03086   check_nomsg(out=cpl_image_duplicate(inp));
+<a name="l03087"></a>03087   check_nomsg(sx=cpl_image_get_size_x(inp));
+<a name="l03088"></a>03088   check_nomsg(sy=cpl_image_get_size_y(inp));
+<a name="l03089"></a>03089   check_nomsg(pinp=cpl_image_get_data_float(inp));
+<a name="l03090"></a>03090   check_nomsg(pout=cpl_image_get_data_float(out));
+<a name="l03091"></a>03091   <span class="keywordflow">for</span>(j=r;j<sy-r;j++) {
+<a name="l03092"></a>03092     <span class="keywordflow">for</span>(i=0;i<sx;i++) {
+<a name="l03093"></a>03093       <span class="keywordflow">for</span>(k=-r;k<r;k++) {
+<a name="l03094"></a>03094     pout[j*sx+i]+=pinp[(j+k)*sx+i];
+<a name="l03095"></a>03095       }
+<a name="l03096"></a>03096       pout[j*sx+i]/=2*r;
+<a name="l03097"></a>03097     }
+<a name="l03098"></a>03098   }
+<a name="l03099"></a>03099 
+<a name="l03100"></a>03100  cleanup:
+<a name="l03101"></a>03101 
+<a name="l03102"></a>03102   <span class="keywordflow">if</span>(cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l03103"></a>03103     <span class="keywordflow">return</span> NULL;
+<a name="l03104"></a>03104   } <span class="keywordflow">else</span> {
+<a name="l03105"></a>03105     <span class="keywordflow">return</span> out;
+<a name="l03106"></a>03106 
+<a name="l03107"></a>03107   }
+<a name="l03108"></a>03108 
+<a name="l03109"></a>03109 }
+<a name="l03110"></a>03110 
+<a name="l03111"></a>03111 
+<a name="l03112"></a>03112 
+<a name="l03113"></a>03113 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l03127"></a>03127 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l03128"></a>03128 
+<a name="l03129"></a>03129 cpl_image *
+<a name="l03130"></a>03130 sinfo_image_smooth_y(cpl_image * inp, <span class="keyword">const</span> <span class="keywordtype">int</span> r)
+<a name="l03131"></a>03131 {
+<a name="l03132"></a>03132 
+<a name="l03133"></a>03133   <span class="comment">/*</span>
+<a name="l03134"></a>03134 <span class="comment">   @param xp     x-value to interpolate</span>
+<a name="l03135"></a>03135 <span class="comment">   @param x      x-values</span>
+<a name="l03136"></a>03136 <span class="comment">   @param y      y-values</span>
+<a name="l03137"></a>03137 <span class="comment">   @param n      array length</span>
+<a name="l03138"></a>03138 <span class="comment">   @param istart    (input/output) initial row (set to 0 to search all row)</span>
+<a name="l03139"></a>03139 <span class="comment"></span>
+<a name="l03140"></a>03140 <span class="comment">  */</span>
+<a name="l03141"></a>03141   <span class="keywordtype">float</span>* pinp=NULL;
+<a name="l03142"></a>03142   <span class="keywordtype">float</span>* pout=NULL;
+<a name="l03143"></a>03143   <span class="keywordtype">int</span> sx=0;
+<a name="l03144"></a>03144   <span class="keywordtype">int</span> sy=0;
+<a name="l03145"></a>03145   <span class="keywordtype">int</span> i=0;
+<a name="l03146"></a>03146   <span class="keywordtype">int</span> j=0;
+<a name="l03147"></a>03147   <span class="keywordtype">int</span> k=0;
+<a name="l03148"></a>03148 
+<a name="l03149"></a>03149   cpl_image* out=NULL;
+<a name="l03150"></a>03150 
+<a name="l03151"></a>03151   cknull(inp,<span class="stringliteral">"Null in put image, exit"</span>);
+<a name="l03152"></a>03152   check_nomsg(out=cpl_image_duplicate(inp));
+<a name="l03153"></a>03153   check_nomsg(sx=cpl_image_get_size_x(inp));
+<a name="l03154"></a>03154   check_nomsg(sy=cpl_image_get_size_y(inp));
+<a name="l03155"></a>03155   check_nomsg(pinp=cpl_image_get_data_float(inp));
+<a name="l03156"></a>03156   check_nomsg(pout=cpl_image_get_data_float(out));
+<a name="l03157"></a>03157   <span class="keywordflow">for</span>(j=r;j<sy-r;j++) {
+<a name="l03158"></a>03158     <span class="keywordflow">for</span>(i=0;i<sx;i++) {
+<a name="l03159"></a>03159       <span class="keywordflow">for</span>(k=-r;k<r;k++) {
+<a name="l03160"></a>03160     pout[j*sx+i]+=pinp[(j+k)*sx+i];
+<a name="l03161"></a>03161       }
+<a name="l03162"></a>03162       pout[j*sx+i]/=2*r;
+<a name="l03163"></a>03163     }
+<a name="l03164"></a>03164   }
+<a name="l03165"></a>03165 
+<a name="l03166"></a>03166  cleanup:
+<a name="l03167"></a>03167 
+<a name="l03168"></a>03168   <span class="keywordflow">if</span>(cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l03169"></a>03169     <span class="keywordflow">return</span> NULL;
+<a name="l03170"></a>03170   } <span class="keywordflow">else</span> {
+<a name="l03171"></a>03171     <span class="keywordflow">return</span> out;
+<a name="l03172"></a>03172 
+<a name="l03173"></a>03173   }
+<a name="l03174"></a>03174 
+<a name="l03175"></a>03175 }
+<a name="l03176"></a>03176 
+<a name="l03177"></a>03177 
+<a name="l03178"></a>03178 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l03192"></a>03192 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l03193"></a>03193 
+<a name="l03194"></a>03194 cpl_image *
+<a name="l03195"></a>03195 sinfo_image_smooth_mean_y(cpl_image * inp, <span class="keyword">const</span> <span class="keywordtype">int</span> r)
+<a name="l03196"></a>03196 {
+<a name="l03197"></a>03197 
+<a name="l03198"></a>03198   <span class="comment">/*</span>
+<a name="l03199"></a>03199 <span class="comment">   @param xp     x-value to interpolate</span>
+<a name="l03200"></a>03200 <span class="comment">   @param x      x-values</span>
+<a name="l03201"></a>03201 <span class="comment">   @param y      y-values</span>
+<a name="l03202"></a>03202 <span class="comment">   @param n      array length</span>
+<a name="l03203"></a>03203 <span class="comment">   @param istart    (input/output) initial row (set to 0 to search all row)</span>
+<a name="l03204"></a>03204 <span class="comment"></span>
+<a name="l03205"></a>03205 <span class="comment">  */</span>
+<a name="l03206"></a>03206   <span class="keywordtype">float</span>* pinp=NULL;
+<a name="l03207"></a>03207   <span class="keywordtype">float</span>* pout=NULL;
+<a name="l03208"></a>03208   <span class="keywordtype">int</span> sx=0;
+<a name="l03209"></a>03209   <span class="keywordtype">int</span> sy=0;
+<a name="l03210"></a>03210   <span class="keywordtype">int</span> i=0;
+<a name="l03211"></a>03211   <span class="keywordtype">int</span> j=0;
+<a name="l03212"></a>03212   <span class="keywordtype">int</span> k=0;
+<a name="l03213"></a>03213 
+<a name="l03214"></a>03214   cpl_image* out=NULL;
+<a name="l03215"></a>03215 
+<a name="l03216"></a>03216   cknull(inp,<span class="stringliteral">"Null in put image, exit"</span>);
+<a name="l03217"></a>03217   check_nomsg(out=cpl_image_duplicate(inp));
+<a name="l03218"></a>03218   check_nomsg(sx=cpl_image_get_size_x(inp));
+<a name="l03219"></a>03219   check_nomsg(sy=cpl_image_get_size_y(inp));
+<a name="l03220"></a>03220   check_nomsg(pinp=cpl_image_get_data_float(inp));
+<a name="l03221"></a>03221   check_nomsg(pout=cpl_image_get_data_float(out));
+<a name="l03222"></a>03222   <span class="keywordflow">for</span>(j=r;j<sy-r;j++) {
+<a name="l03223"></a>03223     <span class="keywordflow">for</span>(i=0;i<sx;i++) {
+<a name="l03224"></a>03224       <span class="keywordflow">for</span>(k=-r;k<r;k++) {
+<a name="l03225"></a>03225     pout[j*sx+i]+=pinp[(j+k)*sx+i];
+<a name="l03226"></a>03226       }
+<a name="l03227"></a>03227       pout[j*sx+i]/=2*r;
+<a name="l03228"></a>03228     }
+<a name="l03229"></a>03229   }
+<a name="l03230"></a>03230 
+<a name="l03231"></a>03231  cleanup:
+<a name="l03232"></a>03232 
+<a name="l03233"></a>03233   <span class="keywordflow">if</span>(cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l03234"></a>03234     <span class="keywordflow">return</span> NULL;
+<a name="l03235"></a>03235   } <span class="keywordflow">else</span> {
+<a name="l03236"></a>03236     <span class="keywordflow">return</span> out;
+<a name="l03237"></a>03237 
+<a name="l03238"></a>03238   }
+<a name="l03239"></a>03239 
+<a name="l03240"></a>03240 }
+<a name="l03241"></a>03241 
+<a name="l03242"></a>03242 
+<a name="l03243"></a>03243 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l03257"></a>03257 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l03258"></a>03258 
+<a name="l03259"></a>03259 cpl_image *
+<a name="l03260"></a>03260 sinfo_image_smooth_median_y(cpl_image * inp, <span class="keyword">const</span> <span class="keywordtype">int</span> r)
+<a name="l03261"></a>03261 {
+<a name="l03262"></a>03262 
+<a name="l03263"></a>03263   <span class="comment">/*</span>
+<a name="l03264"></a>03264 <span class="comment">   @param xp     x-value to interpolate</span>
+<a name="l03265"></a>03265 <span class="comment">   @param x      x-values</span>
+<a name="l03266"></a>03266 <span class="comment">   @param y      y-values</span>
+<a name="l03267"></a>03267 <span class="comment">   @param n      array length</span>
+<a name="l03268"></a>03268 <span class="comment">   @param istart    (input/output) initial row (set to 0 to search all row)</span>
+<a name="l03269"></a>03269 <span class="comment"></span>
+<a name="l03270"></a>03270 <span class="comment">  */</span>
+<a name="l03271"></a>03271   <span class="keywordtype">float</span>* pout=NULL;
+<a name="l03272"></a>03272   <span class="keywordtype">int</span> sx=0;
+<a name="l03273"></a>03273   <span class="keywordtype">int</span> sy=0;
+<a name="l03274"></a>03274   <span class="keywordtype">int</span> i=0;
+<a name="l03275"></a>03275   <span class="keywordtype">int</span> j=0;
+<a name="l03276"></a>03276 
+<a name="l03277"></a>03277   cpl_image* out=NULL;
+<a name="l03278"></a>03278 
+<a name="l03279"></a>03279 
+<a name="l03280"></a>03280   cknull(inp,<span class="stringliteral">"Null in put image, exit"</span>);
+<a name="l03281"></a>03281   check_nomsg(out=cpl_image_duplicate(inp));
+<a name="l03282"></a>03282   check_nomsg(sx=cpl_image_get_size_x(inp));
+<a name="l03283"></a>03283   check_nomsg(sy=cpl_image_get_size_y(inp));
+<a name="l03284"></a>03284   check_nomsg(pout=cpl_image_get_data_float(out));
+<a name="l03285"></a>03285 
+<a name="l03286"></a>03286   <span class="keywordflow">for</span>(j=r+1;j<sy-r;j++) {
+<a name="l03287"></a>03287     <span class="keywordflow">for</span>(i=1;i<sx;i++) {
+<a name="l03288"></a>03288       pout[j*sx+i]=(float)cpl_image_get_median_window(inp,i,j,i,j+r);
+<a name="l03289"></a>03289     }
+<a name="l03290"></a>03290   }
+<a name="l03291"></a>03291 
+<a name="l03292"></a>03292  cleanup:
+<a name="l03293"></a>03293 
+<a name="l03294"></a>03294   <span class="keywordflow">if</span>(cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l03295"></a>03295     <span class="keywordflow">return</span> NULL;
+<a name="l03296"></a>03296   } <span class="keywordflow">else</span> {
+<a name="l03297"></a>03297     <span class="keywordflow">return</span> out;
+<a name="l03298"></a>03298 
+<a name="l03299"></a>03299   }
+<a name="l03300"></a>03300 
+<a name="l03301"></a>03301 }
+<a name="l03302"></a>03302 
+<a name="l03303"></a>03303 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l03316"></a>03316 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l03317"></a>03317 
+<a name="l03318"></a>03318 cpl_image *
+<a name="l03319"></a>03319 sinfo_image_smooth_fft(cpl_image * inp, <span class="keyword">const</span> <span class="keywordtype">int</span> fy)
+<a name="l03320"></a>03320 {
+<a name="l03321"></a>03321 
+<a name="l03322"></a>03322   <span class="keywordtype">int</span> sx=0;
+<a name="l03323"></a>03323   <span class="keywordtype">int</span> sy=0;
+<a name="l03324"></a>03324 
+<a name="l03325"></a>03325   cpl_image* out=NULL;
+<a name="l03326"></a>03326   cpl_image* im_re=NULL;
+<a name="l03327"></a>03327   cpl_image* im_im=NULL;
+<a name="l03328"></a>03328   cpl_image* ifft_re=NULL;
+<a name="l03329"></a>03329   cpl_image* ifft_im=NULL;
+<a name="l03330"></a>03330   cpl_image* filter=NULL;
+<a name="l03331"></a>03331 
+<a name="l03332"></a>03332   <span class="keywordtype">int</span> sigma_x=0;
+<a name="l03333"></a>03333   <span class="keywordtype">int</span> sigma_y=fy;
+<a name="l03334"></a>03334 
+<a name="l03335"></a>03335   cknull(inp,<span class="stringliteral">"Null in put image, exit"</span>);
+<a name="l03336"></a>03336   check_nomsg(im_re = cpl_image_cast(inp, CPL_TYPE_DOUBLE));
+<a name="l03337"></a>03337   check_nomsg(im_im = cpl_image_cast(inp, CPL_TYPE_DOUBLE));
+<a name="l03338"></a>03338 
+<a name="l03339"></a>03339   <span class="comment">// Compute FFT</span>
+<a name="l03340"></a>03340   check_nomsg(cpl_image_fft(im_re,im_im,CPL_FFT_DEFAULT));
+<a name="l03341"></a>03341 
+<a name="l03342"></a>03342   check_nomsg(sx=cpl_image_get_size_x(inp));
+<a name="l03343"></a>03343   check_nomsg(sy=cpl_image_get_size_y(inp));
+<a name="l03344"></a>03344   sigma_x=sx;
+<a name="l03345"></a>03345 
+<a name="l03346"></a>03346   <span class="comment">//Generates filter image</span>
+<a name="l03347"></a>03347   check_nomsg(filter = sinfo_gen_lowpass(sx,sy,sigma_x,sigma_y));
+<a name="l03348"></a>03348 
+<a name="l03349"></a>03349   <span class="comment">//Apply filter</span>
+<a name="l03350"></a>03350   cpl_image_multiply(im_re,filter);
+<a name="l03351"></a>03351   cpl_image_multiply(im_im,filter);
+<a name="l03352"></a>03352 
+<a name="l03353"></a>03353   sinfo_free_image(&filter);
+<a name="l03354"></a>03354 
+<a name="l03355"></a>03355   check_nomsg(ifft_re = cpl_image_duplicate(im_re));
+<a name="l03356"></a>03356   check_nomsg(ifft_im = cpl_image_duplicate(im_im));
+<a name="l03357"></a>03357 
+<a name="l03358"></a>03358   sinfo_free_image(&im_re);
+<a name="l03359"></a>03359   sinfo_free_image(&im_im);
+<a name="l03360"></a>03360 
+<a name="l03361"></a>03361   <span class="comment">//Computes FFT-INVERSE</span>
+<a name="l03362"></a>03362   check_nomsg(cpl_image_fft(ifft_re,ifft_im,CPL_FFT_INVERSE));
+<a name="l03363"></a>03363   check_nomsg(out = cpl_image_cast(ifft_re, CPL_TYPE_FLOAT));
+<a name="l03364"></a>03364 
+<a name="l03365"></a>03365  cleanup:
+<a name="l03366"></a>03366 
+<a name="l03367"></a>03367   sinfo_free_image(&ifft_re);
+<a name="l03368"></a>03368   sinfo_free_image(&ifft_im);
+<a name="l03369"></a>03369   sinfo_free_image(&filter);
+<a name="l03370"></a>03370   sinfo_free_image(&im_re);
+<a name="l03371"></a>03371   sinfo_free_image(&im_im);
+<a name="l03372"></a>03372 
+<a name="l03373"></a>03373   <span class="keywordflow">if</span>(cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l03374"></a>03374     <span class="keywordflow">return</span> NULL;
+<a name="l03375"></a>03375   } <span class="keywordflow">else</span> {
+<a name="l03376"></a>03376     <span class="keywordflow">return</span> out;
+<a name="l03377"></a>03377   }
+<a name="l03378"></a>03378 
+<a name="l03379"></a>03379 }
+<a name="l03380"></a>03380 
+<a name="l03381"></a>03381 
+<a name="l03382"></a>03382 
+<a name="l03383"></a>03383 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l03399"></a>03399 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l03400"></a>03400 <span class="keyword">static</span> cpl_image *
+<a name="l03401"></a>03401 sinfo_gen_lowpass(<span class="keyword">const</span> <span class="keywordtype">int</span> xs,
+<a name="l03402"></a>03402                   <span class="keyword">const</span> <span class="keywordtype">int</span> ys,
+<a name="l03403"></a>03403                   <span class="keyword">const</span> <span class="keywordtype">double</span> sigma_x,
+<a name="l03404"></a>03404                   <span class="keyword">const</span> <span class="keywordtype">double</span> sigma_y)
+<a name="l03405"></a>03405 {
+<a name="l03406"></a>03406 
+<a name="l03407"></a>03407     <span class="keywordtype">int</span> i= 0.0;
+<a name="l03408"></a>03408     <span class="keywordtype">int</span> j= 0.0;
+<a name="l03409"></a>03409     <span class="keywordtype">int</span> hlx= 0.0;
+<a name="l03410"></a>03410     <span class="keywordtype">int</span> hly = 0.0;
+<a name="l03411"></a>03411     <span class="keywordtype">double</span> x= 0.0;
+<a name="l03412"></a>03412     <span class="keywordtype">double</span> y= 0.0;
+<a name="l03413"></a>03413     <span class="keywordtype">double</span> gaussval= 0.0;
+<a name="l03414"></a>03414     <span class="keywordtype">double</span> inv_sigma_x=1./sigma_x;
+<a name="l03415"></a>03415     <span class="keywordtype">double</span> inv_sigma_y=1./sigma_y;
+<a name="l03416"></a>03416 
+<a name="l03417"></a>03417     <span class="keywordtype">float</span> *data;
+<a name="l03418"></a>03418 
+<a name="l03419"></a>03419     cpl_image   *lowpass_image=NULL;
+<a name="l03420"></a>03420 
+<a name="l03421"></a>03421 
+<a name="l03422"></a>03422     lowpass_image = cpl_image_new (xs, ys, CPL_TYPE_FLOAT);
+<a name="l03423"></a>03423     <span class="keywordflow">if</span> (lowpass_image == NULL) {
+<a name="l03424"></a>03424         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Cannot generate lowpass filter <%s>"</span>,
+<a name="l03425"></a>03425                         cpl_error_get_message());
+<a name="l03426"></a>03426         <span class="keywordflow">return</span> NULL;
+<a name="l03427"></a>03427     }
+<a name="l03428"></a>03428 
+<a name="l03429"></a>03429     hlx = xs/2;
+<a name="l03430"></a>03430     hly = ys/2;
+<a name="l03431"></a>03431 
+<a name="l03432"></a>03432     data = cpl_image_get_data_float(lowpass_image);
+<a name="l03433"></a>03433 
+<a name="l03434"></a>03434 <span class="comment">/* Given an image with pixels 0<=i<N, 0<=j<M then the convolution image</span>
+<a name="l03435"></a>03435 <span class="comment">   has the following properties:</span>
+<a name="l03436"></a>03436 <span class="comment"></span>
+<a name="l03437"></a>03437 <span class="comment">   ima[0][0] = 1</span>
+<a name="l03438"></a>03438 <span class="comment">   ima[i][0] = ima[N-i][0] = exp (-0.5 * (i/sig_i)^2)   1<=i<N/2</span>
+<a name="l03439"></a>03439 <span class="comment">   ima[0][j] = ima[0][M-j] = exp (-0.5 * (j/sig_j)^2)   1<=j<M/2</span>
+<a name="l03440"></a>03440 <span class="comment">   ima[i][j] = ima[N-i][j] = ima[i][M-j] = ima[N-i][M-j]</span>
+<a name="l03441"></a>03441 <span class="comment">             = exp (-0.5 * ((i/sig_i)^2 + (j/sig_j)^2))</span>
+<a name="l03442"></a>03442 <span class="comment">*/</span>
+<a name="l03443"></a>03443 
+<a name="l03444"></a>03444     data[0] = 1.0;
+<a name="l03445"></a>03445 
+<a name="l03446"></a>03446     <span class="comment">/* first row */</span>
+<a name="l03447"></a>03447     <span class="keywordflow">for</span> (i=1 ; i<=hlx ; i++) {
+<a name="l03448"></a>03448         x = i * inv_sigma_x;
+<a name="l03449"></a>03449         gaussval = exp(-0.5*x*x);
+<a name="l03450"></a>03450         data[i] = gaussval;
+<a name="l03451"></a>03451         data[xs-i] = gaussval;
+<a name="l03452"></a>03452     }
+<a name="l03453"></a>03453 
+<a name="l03454"></a>03454     <span class="keywordflow">for</span> (j=1; j<=hly ; j++) {
+<a name="l03455"></a>03455         y = j * inv_sigma_y;
+<a name="l03456"></a>03456       <span class="comment">/* first column */</span>
+<a name="l03457"></a>03457         data[j*xs] = exp(-0.5*y*y);
+<a name="l03458"></a>03458         data[(ys-j)*xs] = exp(-0.5*y*y);
+<a name="l03459"></a>03459 
+<a name="l03460"></a>03460         <span class="keywordflow">for</span> (i=1 ; i<=hlx ; i++) {
+<a name="l03461"></a>03461     <span class="comment">/* Use internal symetries */</span>
+<a name="l03462"></a>03462             x = i * inv_sigma_x;
+<a name="l03463"></a>03463             gaussval = exp (-0.5*(x*x+y*y));
+<a name="l03464"></a>03464             data[j*xs+i] = gaussval;
+<a name="l03465"></a>03465             data[(j+1)*xs-i] = gaussval;
+<a name="l03466"></a>03466             data[(ys-j)*xs+i] = gaussval;
+<a name="l03467"></a>03467             data[(ys+1-j)*xs-i] = gaussval;
+<a name="l03468"></a>03468 
+<a name="l03469"></a>03469         }
+<a name="l03470"></a>03470     }
+<a name="l03471"></a>03471 
+<a name="l03472"></a>03472     <span class="comment">/* FIXME: for the moment, reset errno which is coming from exp()</span>
+<a name="l03473"></a>03473 <span class="comment">            in first for-loop at i=348. This is causing cfitsio to</span>
+<a name="l03474"></a>03474 <span class="comment">            fail when loading an extension image (bug in cfitsio too).</span>
+<a name="l03475"></a>03475 <span class="comment">    */</span>
+<a name="l03476"></a>03476     <span class="keywordflow">if</span>(errno != 0)
+<a name="l03477"></a>03477         errno = 0;
+<a name="l03478"></a>03478 
+<a name="l03479"></a>03479     <span class="keywordflow">return</span> lowpass_image;
+<a name="l03480"></a>03480 }
+<a name="l03481"></a>03481 
+<a name="l03482"></a>03482 <span class="keyword">static</span> <span class="keywordtype">void</span> quicksort_int(<span class="keywordtype">int</span>* data, <span class="keywordtype">int</span> left, <span class="keywordtype">int</span> right)
+<a name="l03483"></a>03483 {
+<a name="l03484"></a>03484     <span class="keywordtype">int</span> i = left;
+<a name="l03485"></a>03485     <span class="keywordtype">int</span> j = right;
+<a name="l03486"></a>03486     <span class="keywordtype">int</span> pivot = (i + j) / 2;
+<a name="l03487"></a>03487     <span class="keywordtype">double</span> index_value = data[pivot];
+<a name="l03488"></a>03488     <span class="keywordflow">do</span>
+<a name="l03489"></a>03489     {
+<a name="l03490"></a>03490         <span class="keywordflow">while</span>(data[i] < index_value) i++;
+<a name="l03491"></a>03491         <span class="keywordflow">while</span>(data[j] > index_value) j--;
+<a name="l03492"></a>03492         <span class="keywordflow">if</span> (i <= j)
+<a name="l03493"></a>03493         {
+<a name="l03494"></a>03494             <span class="keywordflow">if</span>(i < j)
+<a name="l03495"></a>03495             {
+<a name="l03496"></a>03496                 <span class="keywordtype">int</span> tmp = data[i];
+<a name="l03497"></a>03497                 data[i]=data[j];
+<a name="l03498"></a>03498                 data[j]=tmp;
+<a name="l03499"></a>03499             }
+<a name="l03500"></a>03500             i++;
+<a name="l03501"></a>03501             j--;
+<a name="l03502"></a>03502         }
+<a name="l03503"></a>03503     } <span class="keywordflow">while</span> (i <= j);
+<a name="l03504"></a>03504 
+<a name="l03505"></a>03505     <span class="keywordflow">if</span> (i < right)
+<a name="l03506"></a>03506     {
+<a name="l03507"></a>03507         quicksort_int(data, i, right);
+<a name="l03508"></a>03508     }
+<a name="l03509"></a>03509     <span class="keywordflow">if</span> (left < j)
+<a name="l03510"></a>03510     {
+<a name="l03511"></a>03511         quicksort_int(data, left, j);
+<a name="l03512"></a>03512     }
+<a name="l03513"></a>03513 }
+<a name="l03514"></a>03514 
+<a name="l03515"></a>03515 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__image__ops_8h_source.html b/html/sinfo__image__ops_8h_source.html
new file mode 100644
index 0000000..a9b1229
--- /dev/null
+++ b/html/sinfo__image__ops_8h_source.html
@@ -0,0 +1,195 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_image_ops.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_image_ops.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#ifndef SINFO_IMAGE_OPS_H</span>
+<a name="l00002"></a>00002 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_IMAGE_OPS_H</span>
+<a name="l00003"></a>00003 <span class="preprocessor"></span><span class="comment">/*</span>
+<a name="l00004"></a>00004 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00005"></a>00005 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00006"></a>00006 <span class="comment"> *</span>
+<a name="l00007"></a>00007 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00008"></a>00008 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00009"></a>00009 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00010"></a>00010 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00011"></a>00011 <span class="comment"> *</span>
+<a name="l00012"></a>00012 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00013"></a>00013 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00014"></a>00014 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00015"></a>00015 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00016"></a>00016 <span class="comment"> *</span>
+<a name="l00017"></a>00017 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00018"></a>00018 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00019"></a>00019 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00020"></a>00020 <span class="comment"> */</span>
+<a name="l00021"></a>00021 <span class="comment">/*******************************************************************************</span>
+<a name="l00022"></a>00022 <span class="comment">* E.S.O. - VLT project</span>
+<a name="l00023"></a>00023 <span class="comment">*</span>
+<a name="l00024"></a>00024 <span class="comment">* "@(#) $Id: sinfo_image_ops.h,v 1.9 2008/03/25 08:20:43 amodigli Exp $"</span>
+<a name="l00025"></a>00025 <span class="comment">*</span>
+<a name="l00026"></a>00026 <span class="comment">* who       when      what</span>
+<a name="l00027"></a>00027 <span class="comment">* --------  --------  ----------------------------------------------</span>
+<a name="l00028"></a>00028 <span class="comment">* amodigli  04/01/06  created</span>
+<a name="l00029"></a>00029 <span class="comment">*/</span>
+<a name="l00030"></a>00030 
+<a name="l00031"></a>00031 <span class="comment">/************************************************************************</span>
+<a name="l00032"></a>00032 <span class="comment"> * sinfo_image_ops.h</span>
+<a name="l00033"></a>00033 <span class="comment"> * image arithmetic routines</span>
+<a name="l00034"></a>00034 <span class="comment"> *----------------------------------------------------------------------</span>
+<a name="l00035"></a>00035 <span class="comment"> */</span>
+<a name="l00036"></a>00036 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00037"></a>00037 
+<a name="l00038"></a>00038 <span class="preprocessor">#include "sinfo_spiffi_types.h"</span> 
+<a name="l00039"></a>00039 <span class="preprocessor">#include "sinfo_spectrum_ops.h"</span> 
+<a name="l00040"></a>00040 <span class="preprocessor">#include "sinfo_recipes.h"</span>
+<a name="l00041"></a>00041 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00042"></a>00042 <span class="comment"> *                        Function ANSI C prototypes</span>
+<a name="l00043"></a>00043 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00044"></a>00044 
+<a name="l00045"></a>00045 
+<a name="l00046"></a>00046 
+<a name="l00047"></a>00047 cpl_image *
+<a name="l00048"></a>00048 sinfo_image_smooth_y(cpl_image * inp, <span class="keyword">const</span> <span class="keywordtype">int</span> r);
+<a name="l00049"></a>00049 
+<a name="l00050"></a>00050 cpl_error_code
+<a name="l00051"></a>00051 sinfo_image_line_corr(<span class="keyword">const</span> <span class="keywordtype">int</span> width,
+<a name="l00052"></a>00052               <span class="keyword">const</span> <span class="keywordtype">int</span> filt_rad,
+<a name="l00053"></a>00053               <span class="keyword">const</span> <span class="keywordtype">int</span> kappa,
+<a name="l00054"></a>00054               cpl_image* ima,
+<a name="l00055"></a>00055               cpl_image** ima_out);
+<a name="l00056"></a>00056 
+<a name="l00057"></a>00057 
+<a name="l00079"></a>00079 cpl_image *
+<a name="l00080"></a>00080 sinfo_new_shift_image(
+<a name="l00081"></a>00081     cpl_image    *    image_in,
+<a name="l00082"></a>00082     <span class="keywordtype">double</span>           shift_x,
+<a name="l00083"></a>00083     <span class="keywordtype">double</span>           shift_y,
+<a name="l00084"></a>00084     <span class="keywordtype">double</span>       *    interp_kernel) ;
+<a name="l00091"></a>00091 Vector * 
+<a name="l00092"></a>00092 sinfo_new_mean_of_columns( cpl_image * im ) ;
+<a name="l00093"></a>00093 
+<a name="l00094"></a>00094 
+<a name="l00104"></a>00104 <span class="keywordtype">double</span> 
+<a name="l00105"></a>00105 sinfo_new_my_median_image(cpl_image* im);
+<a name="l00106"></a>00106 
+<a name="l00107"></a>00107 
+<a name="l00108"></a>00108 cpl_image * 
+<a name="l00109"></a>00109 sinfo_new_clean_mean_of_columns( cpl_image * im,
+<a name="l00110"></a>00110                                <span class="keywordtype">float</span> lo_reject,
+<a name="l00111"></a>00111                                <span class="keywordtype">float</span> hi_reject) ;
+<a name="l00112"></a>00112 
+<a name="l00113"></a>00113 
+<a name="l00122"></a>00122 cpl_image * 
+<a name="l00123"></a>00123 sinfo_new_div_image_by_row( cpl_image * im, Vector * row ) ;
+<a name="l00124"></a>00124 
+<a name="l00133"></a>00133 cpl_image * 
+<a name="l00134"></a>00134 sinfo_new_mult_row_to_image( cpl_image *im, Vector *row ) ;
+<a name="l00135"></a>00135 
+<a name="l00154"></a>00154 cpl_image * 
+<a name="l00155"></a>00155 sinfo_new_col_tilt ( cpl_image * image, <span class="keywordtype">float</span> sigmaFactor ) ;
+<a name="l00176"></a>00176 cpl_image * 
+<a name="l00177"></a>00177 sinfo_new_median_image( cpl_image * im, <span class="keywordtype">float</span> fmedian ) ;
+<a name="l00178"></a>00178 
+<a name="l00189"></a>00189 cpl_image * 
+<a name="l00190"></a>00190 sinfo_new_compare_images(cpl_image * im1, cpl_image * im2, cpl_image * origim);
+<a name="l00201"></a>00201 cpl_image * 
+<a name="l00202"></a>00202 sinfo_new_thresh_image ( cpl_image * im, <span class="keywordtype">float</span> lo_cut, <span class="keywordtype">float</span> hi_cut ) ;
+<a name="l00203"></a>00203 
+<a name="l00215"></a>00215 cpl_image * 
+<a name="l00216"></a>00216 sinfo_new_promote_image_to_mask(cpl_image * im, <span class="keywordtype">int</span> * n_badpixels ) ;
+<a name="l00227"></a>00227 cpl_image * sinfo_new_mult_image_by_mask ( cpl_image * im, cpl_image * mask ) ;
+<a name="l00228"></a>00228 
+<a name="l00251"></a>00251 cpl_image * 
+<a name="l00252"></a>00252 sinfo_new_interpol_image ( cpl_image * im,
+<a name="l00253"></a>00253                            cpl_image * mask,
+<a name="l00254"></a>00254                            <span class="keywordtype">int</span>        max_radius,
+<a name="l00255"></a>00255                            <span class="keywordtype">int</span>        n_pixels ) ;
+<a name="l00256"></a>00256 
+<a name="l00275"></a>00275 cpl_image * 
+<a name="l00276"></a>00276 sinfo_interpol_source_image ( cpl_image * im,
+<a name="l00277"></a>00277                                  cpl_image * mask,
+<a name="l00278"></a>00278                                  <span class="keywordtype">int</span>        max_rad,
+<a name="l00279"></a>00279                                  <span class="keywordtype">float</span>   ** slit_edges ) ;
+<a name="l00280"></a>00280 
+<a name="l00290"></a>00290 cpl_image * 
+<a name="l00291"></a>00291 sinfo_new_stack_row_to_image ( Vector * row, <span class="keywordtype">int</span> ly ) ;
+<a name="l00292"></a>00292 
+<a name="l00293"></a>00293 
+<a name="l00310"></a>00310 Stats * 
+<a name="l00311"></a>00311 sinfo_new_image_stats_on_rectangle ( cpl_image * im,
+<a name="l00312"></a>00312                                 <span class="keywordtype">float</span>      loReject,
+<a name="l00313"></a>00313                                 <span class="keywordtype">float</span>      hiReject,
+<a name="l00314"></a>00314                                 <span class="keywordtype">int</span>        llx,
+<a name="l00315"></a>00315                                 <span class="keywordtype">int</span>        lly,
+<a name="l00316"></a>00316                                 <span class="keywordtype">int</span>        urx,
+<a name="l00317"></a>00317                                 <span class="keywordtype">int</span>        ury ) ;
+<a name="l00318"></a>00318 
+<a name="l00328"></a>00328 cpl_image * 
+<a name="l00329"></a>00329 sinfo_new_normalize_to_central_pixel ( cpl_image * image ) ;
+<a name="l00330"></a>00330 
+<a name="l00361"></a>00361 cpl_image *
+<a name="l00362"></a>00362 sinfo_new_mpe_shift_image(
+<a name="l00363"></a>00363     cpl_image    *    image_in,
+<a name="l00364"></a>00364     <span class="keywordtype">double</span>           shift_x,
+<a name="l00365"></a>00365     <span class="keywordtype">double</span>           shift_y,
+<a name="l00366"></a>00366     <span class="keywordtype">double</span>       *   interp_kernel) ;
+<a name="l00367"></a>00367 
+<a name="l00377"></a>00377 <span class="keywordtype">void</span>
+<a name="l00378"></a>00378 sinfo_new_shift_image_in_cube(
+<a name="l00379"></a>00379     cpl_image     *   image_in,
+<a name="l00380"></a>00380     <span class="keywordtype">double</span>           shift_x,
+<a name="l00381"></a>00381     <span class="keywordtype">double</span>           shift_y,
+<a name="l00382"></a>00382     <span class="keywordtype">double</span>       *   interp_kernel,
+<a name="l00383"></a>00383     cpl_image     *   shifted,
+<a name="l00384"></a>00384     pixelvalue   *   first_pass) ;
+<a name="l00385"></a>00385 
+<a name="l00386"></a>00386 
+<a name="l00387"></a>00387 <span class="keywordtype">void</span> sinfo_new_del_Stats (Stats *) ;
+<a name="l00388"></a>00388 
+<a name="l00389"></a>00389 
+<a name="l00398"></a>00398 cpl_image * 
+<a name="l00399"></a>00399 sinfo_new_combine_masks ( cpl_image * firstMask, cpl_image * secondMask ) ;
+<a name="l00400"></a>00400 
+<a name="l00411"></a>00411 cpl_image * 
+<a name="l00412"></a>00412 sinfo_new_slice_cube (cpl_imagelist * cube, <span class="keywordtype">int</span> x, <span class="keywordtype">int</span> y ) ;
+<a name="l00413"></a>00413 
+<a name="l00414"></a>00414 
+<a name="l00425"></a>00425 cpl_image * 
+<a name="l00426"></a>00426 sinfo_new_div_images_robust ( cpl_image * im1, cpl_image * im2 ) ;
+<a name="l00427"></a>00427 
+<a name="l00428"></a>00428 
+<a name="l00429"></a>00429 
+<a name="l00430"></a>00430 cpl_image * 
+<a name="l00431"></a>00431 sinfo_new_null_edges ( cpl_image * image) ;
+<a name="l00432"></a>00432 
+<a name="l00433"></a>00433 
+<a name="l00434"></a>00434 
+<a name="l00435"></a>00435 <span class="keywordtype">void</span> 
+<a name="l00436"></a>00436 sinfo_new_used_cor_map( cpl_image *im, cpl_image *map);
+<a name="l00437"></a>00437 
+<a name="l00438"></a>00438 
+<a name="l00439"></a>00439 cpl_image *
+<a name="l00440"></a>00440 sinfo_image_smooth_mean_y(cpl_image * inp,<span class="keyword">const</span> <span class="keywordtype">int</span> r);
+<a name="l00441"></a>00441 
+<a name="l00442"></a>00442 cpl_image *
+<a name="l00443"></a>00443 sinfo_image_smooth_median_y(cpl_image * inp,<span class="keyword">const</span> <span class="keywordtype">int</span> r);
+<a name="l00444"></a>00444 
+<a name="l00445"></a>00445 cpl_image *
+<a name="l00446"></a>00446 sinfo_image_hermite_interpol(cpl_image * inp);
+<a name="l00447"></a>00447 
+<a name="l00448"></a>00448 cpl_image *
+<a name="l00449"></a>00449 sinfo_image_smooth_fft(cpl_image * inp, <span class="keyword">const</span> <span class="keywordtype">int</span> r);
+<a name="l00450"></a>00450 
+<a name="l00451"></a>00451 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__img__noise_8c_source.html b/html/sinfo__img__noise_8c_source.html
new file mode 100644
index 0000000..573a270
--- /dev/null
+++ b/html/sinfo__img__noise_8c_source.html
@@ -0,0 +1,140 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_img_noise.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_img_noise.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_img_noise.c,v 1.3 2009/09/11 10:00:24 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the SINFONI Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2009/09/11 10:00:24 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.3 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> * $Log: sinfo_img_noise.c,v $</span>
+<a name="l00027"></a>00027 <span class="comment"> * Revision 1.3  2009/09/11 10:00:24  amodigli</span>
+<a name="l00028"></a>00028 <span class="comment"> * put back include of irplib_detmon.h</span>
+<a name="l00029"></a>00029 <span class="comment"> *</span>
+<a name="l00030"></a>00030 <span class="comment"> * Revision 1.2  2009/09/11 09:25:29  kmirny</span>
+<a name="l00031"></a>00031 <span class="comment"> * changing img_noise from cpl to irplib</span>
+<a name="l00032"></a>00032 <span class="comment"> *</span>
+<a name="l00033"></a>00033 <span class="comment"> * Revision 1.1  2009/09/09 14:17:36  kmirny</span>
+<a name="l00034"></a>00034 <span class="comment"> * Adding img_noise recipe based on detmon</span>
+<a name="l00035"></a>00035 <span class="comment"> *</span>
+<a name="l00036"></a>00036 <span class="comment"> */</span>
+<a name="l00037"></a>00037 
+<a name="l00042"></a>00042 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00043"></a>00043 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>
+<a name="l00044"></a>00044 <span class="preprocessor">#endif</span>
+<a name="l00045"></a>00045 <span class="preprocessor"></span>
+<a name="l00046"></a>00046 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00047"></a>00047 <span class="comment">                                Includes</span>
+<a name="l00048"></a>00048 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00049"></a>00049 
+<a name="l00050"></a>00050 <span class="comment">/* std libraries */</span>
+<a name="l00051"></a>00051 <span class="comment">//#include <strings.h></span>
+<a name="l00052"></a>00052 <span class="comment">//#include <string.h></span>
+<a name="l00053"></a>00053 <span class="comment">//#include <stdio.h></span>
+<a name="l00054"></a>00054 <span class="comment">//#include <sinfo_general_config.h></span>
+<a name="l00055"></a>00055 <span class="comment">/* cpl */</span>
+<a name="l00056"></a>00056 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00057"></a>00057 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00058"></a>00058 <span class="preprocessor">#include "sinfo_utils_wrappers.h"</span>
+<a name="l00059"></a>00059 <span class="preprocessor">#include "sinfo_error.h"</span>
+<a name="l00060"></a>00060 <span class="comment">//#include "cpl_utils.h"</span>
+<a name="l00061"></a>00061 <span class="comment">//#include "cpl_hist.h"</span>
+<a name="l00062"></a>00062 <span class="preprocessor">#include <irplib_detmon.h></span>
+<a name="l00063"></a>00063 <span class="comment">/* Define here the DO.CATG keywords */</span>
+<a name="l00064"></a>00064 <span class="preprocessor">#define  SINFO_PERNOISE_RAW "DARK"</span>
+<a name="l00065"></a>00065 <span class="preprocessor"></span>
+<a name="l00066"></a>00066 <span class="preprocessor">#define RECIPE_NAME "sinfo_img_noise"</span>
+<a name="l00067"></a>00067 <span class="preprocessor"></span>
+<a name="l00068"></a>00068 
+<a name="l00069"></a>00069 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00070"></a>00070 <span class="comment">                Functions prototypes</span>
+<a name="l00071"></a>00071 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00072"></a>00072 <span class="comment">/*static int sinfo_img_noise(cpl_frameset            * frameset,</span>
+<a name="l00073"></a>00073 <span class="comment">               const cpl_parameterlist * parlist);</span>
+<a name="l00074"></a>00074 <span class="comment">*/</span>
+<a name="l00075"></a>00075 
+<a name="l00076"></a>00076 
+<a name="l00077"></a>00077 CPL_RECIPE_DEFINE(sinfo_img_noise, SINFONI_BINARY_VERSION,
+<a name="l00078"></a>00078              <span class="comment">/* Replace DETMON_BINARY_VERSION with</span>
+<a name="l00079"></a>00079 <span class="comment">            corresponding pipeline macro */</span>
+<a name="l00080"></a>00080         irplib_detmon_fill_pernoise_params_default(recipe->parameters,
+<a name="l00081"></a>00081                                                 RECIPE_NAME,
+<a name="l00082"></a>00082                                                 PACKAGE_TARNAME),
+<a name="l00083"></a>00083              <span class="comment">/* Replace "sinfoni" with PACKAGE_TARNAME</span>
+<a name="l00084"></a>00084 <span class="comment">            when moved into SINFONI */</span>
+<a name="l00085"></a>00085                      <span class="stringliteral">"Konstantin Mirny"</span>, <span class="stringliteral">"kmirny at eso.org"</span>, <span class="stringliteral">"2009"</span>,
+<a name="l00086"></a>00086                      <span class="stringliteral">"Periodic Noise Characterisation recipe"</span>,
+<a name="l00087"></a>00087                      irplib_detmon_pernoise_get_description(RECIPE_NAME, PACKAGE_TARNAME,
+<a name="l00088"></a>00088                              SINFO_PERNOISE_RAW));
+<a name="l00089"></a>00089 
+<a name="l00090"></a>00090 <span class="comment">/*</span>
+<a name="l00091"></a>00091 <span class="comment">CPL_RECIPE_DEFINE(sinfo_img_noise, SINFONI_BINARY_VERSION,</span>
+<a name="l00092"></a>00092 <span class="comment">                  cpl_detmon_fill_pernoise_params_default(</span>
+<a name="l00093"></a>00093 <span class="comment">                                                            recipe->parameters,</span>
+<a name="l00094"></a>00094 <span class="comment">                                                             RECIPE_NAME,</span>
+<a name="l00095"></a>00095 <span class="comment">                                                             PACKAGE_TARNAME),</span>
+<a name="l00096"></a>00096 <span class="comment">                  "Konstantin Mirny", "kmirny at eso.org", "2009",</span>
+<a name="l00097"></a>00097 <span class="comment">                  "Periodic Noise Characterisation recipe",</span>
+<a name="l00098"></a>00098 <span class="comment">                  cpl_detmon_pernoise_get_description(RECIPE_NAME,</span>
+<a name="l00099"></a>00099 <span class="comment">                                                         PACKAGE_TARNAME,</span>
+<a name="l00100"></a>00100 <span class="comment">                                                         SINFO_PERNOISE_RAW));</span>
+<a name="l00101"></a>00101 <span class="comment">*/</span>
+<a name="l00102"></a>00102 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00103"></a>00103 <span class="comment">/*</span>
+<a name="l00104"></a>00104 <span class="comment">  @brief    Interpret the command line options and execute the data processing</span>
+<a name="l00105"></a>00105 <span class="comment">  @param    frameset    the frames list</span>
+<a name="l00106"></a>00106 <span class="comment">  @param    parlist     the parameters list</span>
+<a name="l00107"></a>00107 <span class="comment">  @return   0 if everything is ok</span>
+<a name="l00108"></a>00108 <span class="comment"> */</span>
+<a name="l00109"></a>00109 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00110"></a>00110 
+<a name="l00111"></a>00111 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_img_noise(cpl_frameset            * frameset,
+<a name="l00112"></a>00112                <span class="keyword">const</span> cpl_parameterlist * parlist)
+<a name="l00113"></a>00113 {
+<a name="l00114"></a>00114     <span class="keyword">const</span> cpl_error_code error = irplib_detmon_pernoise(frameset,
+<a name="l00115"></a>00115                                                        parlist,
+<a name="l00116"></a>00116                                                        SINFO_PERNOISE_RAW,
+<a name="l00117"></a>00117                                                        RECIPE_NAME,
+<a name="l00118"></a>00118                                                        PACKAGE_TARNAME,
+<a name="l00119"></a>00119                                                        <span class="stringliteral">"FREQ_TABLE"</span>,
+<a name="l00120"></a>00120                                                        PACKAGE <span class="stringliteral">"/"</span> PACKAGE_VERSION,
+<a name="l00121"></a>00121                                                        NULL);
+<a name="l00122"></a>00122 
+<a name="l00123"></a>00123     <span class="comment">/* Propagate the error, if any */</span>
+<a name="l00124"></a>00124     cpl_ensure_code(!error, error);
+<a name="l00125"></a>00125 
+<a name="l00126"></a>00126     <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l00127"></a>00127 }
+<a name="l00128"></a>00128 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__ipow_8c_source.html b/html/sinfo__ipow_8c_source.html
new file mode 100644
index 0000000..569e5f0
--- /dev/null
+++ b/html/sinfo__ipow_8c_source.html
@@ -0,0 +1,83 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_ipow.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_ipow.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00020"></a>00020 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00021"></a>00021 <span class="preprocessor">#endif</span>
+<a name="l00022"></a>00022 <span class="preprocessor"></span><span class="comment">/*</span>
+<a name="l00023"></a>00023 <span class="comment"> * This function is so generic and used everywhere, it diserves its</span>
+<a name="l00024"></a>00024 <span class="comment"> * own source file...</span>
+<a name="l00025"></a>00025 <span class="comment"> */</span>
+<a name="l00026"></a>00026 <span class="comment">/*</span>
+<a name="l00027"></a>00027 <span class="comment"> $Id: sinfo_ipow.c,v 1.4 2012/03/02 08:42:20 amodigli Exp $</span>
+<a name="l00028"></a>00028 <span class="comment"> $Author: amodigli $</span>
+<a name="l00029"></a>00029 <span class="comment"> $Date: 2012/03/02 08:42:20 $</span>
+<a name="l00030"></a>00030 <span class="comment"> $Revision: 1.4 $</span>
+<a name="l00031"></a>00031 <span class="comment"> */</span>
+<a name="l00053"></a>00053 <span class="preprocessor">#include "sinfo_ipow.h"</span>
+<a name="l00054"></a>00054 <span class="keywordtype">double</span> sinfo_ipow(<span class="keywordtype">double</span> x, <span class="keywordtype">int</span> p)
+<a name="l00055"></a>00055 {
+<a name="l00056"></a>00056     <span class="keywordtype">double</span> r, recip ;
+<a name="l00057"></a>00057 
+<a name="l00058"></a>00058     <span class="comment">/* Get rid of trivial cases */</span>
+<a name="l00059"></a>00059     <span class="keywordflow">switch</span> (p) {
+<a name="l00060"></a>00060         <span class="keywordflow">case</span> 0:
+<a name="l00061"></a>00061         <span class="keywordflow">return</span> 1.00 ;
+<a name="l00062"></a>00062 
+<a name="l00063"></a>00063         <span class="keywordflow">case</span> 1:
+<a name="l00064"></a>00064         <span class="keywordflow">return</span> x ;
+<a name="l00065"></a>00065 
+<a name="l00066"></a>00066         <span class="keywordflow">case</span> 2:
+<a name="l00067"></a>00067         <span class="keywordflow">return</span> x*x ;
+<a name="l00068"></a>00068 
+<a name="l00069"></a>00069         <span class="keywordflow">case</span> 3:
+<a name="l00070"></a>00070         <span class="keywordflow">return</span> x*x*x ;
+<a name="l00071"></a>00071 
+<a name="l00072"></a>00072         <span class="keywordflow">case</span> -1:
+<a name="l00073"></a>00073         <span class="keywordflow">return</span> 1.00 / x ;
+<a name="l00074"></a>00074 
+<a name="l00075"></a>00075         <span class="keywordflow">case</span> -2:
+<a name="l00076"></a>00076         <span class="keywordflow">return</span> (1.00 / x) * (1.00 / x) ;
+<a name="l00077"></a>00077     }
+<a name="l00078"></a>00078     <span class="keywordflow">if</span> (p>0) {
+<a name="l00079"></a>00079         r = x ;
+<a name="l00080"></a>00080         <span class="keywordflow">while</span> (--p) r *= x ;
+<a name="l00081"></a>00081     } <span class="keywordflow">else</span> {
+<a name="l00082"></a>00082         r = recip = 1.00 / x ;
+<a name="l00083"></a>00083         <span class="keywordflow">while</span> (++p) r *= recip ;
+<a name="l00084"></a>00084     }
+<a name="l00085"></a>00085     <span class="keywordflow">return</span> r;
+<a name="l00086"></a>00086 }
+<a name="l00087"></a>00087 
+<a name="l00088"></a>00088 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__ipow_8h_source.html b/html/sinfo__ipow_8h_source.html
new file mode 100644
index 0000000..c4d47a6
--- /dev/null
+++ b/html/sinfo__ipow_8h_source.html
@@ -0,0 +1,58 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_ipow.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_ipow.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name     :    sinfo_ipow.h</span>
+<a name="l00022"></a>00022 <span class="comment">   Author         :    N. Devillard</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on    :    June 1999</span>
+<a name="l00024"></a>00024 <span class="comment">   Description    :    integer powers</span>
+<a name="l00025"></a>00025 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00026"></a>00026 
+<a name="l00027"></a>00027 <span class="comment">/*</span>
+<a name="l00028"></a>00028 <span class="comment"> $Id: sinfo_ipow.h,v 1.3 2007/06/06 07:10:45 amodigli Exp $</span>
+<a name="l00029"></a>00029 <span class="comment"> $Author: amodigli $</span>
+<a name="l00030"></a>00030 <span class="comment"> $Date: 2007/06/06 07:10:45 $</span>
+<a name="l00031"></a>00031 <span class="comment"> $Revision: 1.3 $</span>
+<a name="l00032"></a>00032 <span class="comment"> */</span>
+<a name="l00033"></a>00033 
+<a name="l00034"></a>00034 <span class="preprocessor">#ifndef SINFO_IPOW_H</span>
+<a name="l00035"></a>00035 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_IPOW_H</span>
+<a name="l00036"></a>00036 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00037"></a>00037 <span class="comment">                               Function prototypes</span>
+<a name="l00038"></a>00038 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00053"></a>00053 <span class="keywordtype">double</span> 
+<a name="l00054"></a>00054 sinfo_ipow(<span class="keywordtype">double</span> x, <span class="keywordtype">int</span> p);
+<a name="l00055"></a>00055 
+<a name="l00056"></a>00056 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__irplib__cpl__wrp_8h_source.html b/html/sinfo__irplib__cpl__wrp_8h_source.html
new file mode 100644
index 0000000..cce6882
--- /dev/null
+++ b/html/sinfo__irplib__cpl__wrp_8h_source.html
@@ -0,0 +1,70 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_irplib_cpl_wrp.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_irplib_cpl_wrp.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_irplib_cpl_wrp.h,v 1.3 2009/10/20 14:32:56 kmirny Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the SINFONI pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2009 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: kmirny $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2009/10/20 14:32:56 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.3 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 <span class="preprocessor">#ifndef SINFO_IRPLIB_CPL_WRP_H_</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_IRPLIB_CPL_WRP_H_</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#if 0 //defined CPL_VERSION_CODE && CPL_VERSION_CODE >= CPL_VERSION(5, 1, 0)</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span><span class="preprocessor">#define DETMON_FILL_PROLIST(par1, par2, par3, par4) cpl_detmon_fill_prolist(par1, par2, par3, par4);</span>
+<a name="l00032"></a>00032 <span class="preprocessor"></span><span class="preprocessor">#define DETMON_LG_FILL_PARLIST_NIR_DEFAULT(par1, par2, par3) cpl_detmon_lg_fill_parlist_nir_default(par1, par2, par3);</span>
+<a name="l00033"></a>00033 <span class="preprocessor"></span><span class="preprocessor">#define DETMON_LG(par1, par2, par3, par4, par5, par6, par7, par8, par9, par10,p11,p12,p13,p14,p15,p16,p17) \</span>
+<a name="l00034"></a>00034 <span class="preprocessor">    cpl_detmon_lg(par1, par2, par3, par4, par5, par6, par7, par8, par9, par10,p11,p12,p13,p14,p15,p16,p17);</span>
+<a name="l00035"></a>00035 <span class="preprocessor"></span><span class="preprocessor">#define DETMON_FLAT_FIT_SLOPE_ROBUST(p1, p2, p3) cpl_flat_fit_slope_robust(p1, p2, p3);</span>
+<a name="l00036"></a>00036 <span class="preprocessor"></span><span class="preprocessor">#define LG_DESCR(p1, p2, p3, p4) cpl_detmon_lg_get_description(p1, p2, p3, p4)</span>
+<a name="l00037"></a>00037 <span class="preprocessor"></span><span class="preprocessor">#else</span>
+<a name="l00038"></a>00038 <span class="preprocessor"></span><span class="preprocessor">#include "irplib_detmon_lg.h"</span>
+<a name="l00039"></a>00039 <span class="preprocessor">#include "irplib_detmon.h"</span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include "irplib_plugin.h"</span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include "irplib_calib.h"</span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include "irplib_flat.h"</span>
+<a name="l00043"></a>00043 <span class="preprocessor">#define DETMON_FILL_PROLIST(par1, par2, par3, par4) irplib_detmon_fill_prolist(par1, par2, par3, par4);</span>
+<a name="l00044"></a>00044 <span class="preprocessor"></span><span class="preprocessor">#define DETMON_LG_FILL_PARLIST_NIR_DEFAULT(par1, par2, par3) irplib_detmon_lg_fill_parlist_nir_default(par1, par2, par3);</span>
+<a name="l00045"></a>00045 <span class="preprocessor"></span><span class="preprocessor">#define DETMON_LG(par1, par2, par3, par4, par5, par6, par7, par8, par9, par10,p11,p12,p13,p14,p15,p16,p17) \</span>
+<a name="l00046"></a>00046 <span class="preprocessor">    irplib_detmon_lg(par1, par2, par3, par4, par5, par6, par7, par8, par9, par10,p11,p12,p13,p14,p15,p16,p17);</span>
+<a name="l00047"></a>00047 <span class="preprocessor"></span><span class="preprocessor">#define DETMON_FLAT_FIT_SLOPE_ROBUST(p1, p2, p3) irplib_flat_fit_slope_robust(p1, p2, p3);</span>
+<a name="l00048"></a>00048 <span class="preprocessor"></span><span class="preprocessor">#define LG_DESCR(p1, p2, p3, p4) irplib_detmon_lg_get_description(p1, p2, p3, p4)</span>
+<a name="l00049"></a>00049 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
+<a name="l00050"></a>00050 <span class="preprocessor"></span>
+<a name="l00051"></a>00051 
+<a name="l00052"></a>00052 
+<a name="l00053"></a>00053 
+<a name="l00054"></a>00054 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__key__names_8h_source.html b/html/sinfo__key__names_8h_source.html
new file mode 100644
index 0000000..3fde9ad
--- /dev/null
+++ b/html/sinfo__key__names_8h_source.html
@@ -0,0 +1,244 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_key_names.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_key_names.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_key_names.h,v 1.1 2006/10/20 08:06:32 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the SINFONI Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This proram is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2006/10/20 08:06:32 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.1 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifndef SINFO_KEY_NAMES_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_KEY_NAMES_H</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span>
+<a name="l00031"></a>00031 
+<a name="l00032"></a>00032 
+<a name="l00033"></a>00033 CPL_BEGIN_DECLS
+<a name="l00034"></a>00034 <span class="preprocessor">#define KEY_NAME_CDELT1                     "CDELT1"</span>
+<a name="l00035"></a>00035 <span class="preprocessor"></span><span class="preprocessor">#define KEY_NAME_CDELT2                     "CDELT2"</span>
+<a name="l00036"></a>00036 <span class="preprocessor"></span><span class="preprocessor">#define KEY_NAME_CDELT3                     "CDELT3"</span>
+<a name="l00037"></a>00037 <span class="preprocessor"></span>
+<a name="l00038"></a>00038 <span class="preprocessor">#define KEY_NAME_CRPIX1                     "CRPIX1"</span>
+<a name="l00039"></a>00039 <span class="preprocessor"></span><span class="preprocessor">#define KEY_NAME_CRPIX2                     "CRPIX2"</span>
+<a name="l00040"></a>00040 <span class="preprocessor"></span><span class="preprocessor">#define KEY_NAME_CRPIX3                     "CRPIX3"</span>
+<a name="l00041"></a>00041 <span class="preprocessor"></span>
+<a name="l00042"></a>00042 <span class="preprocessor">#define KEY_NAME_CRVAL1                     "CRVAL1"</span>
+<a name="l00043"></a>00043 <span class="preprocessor"></span><span class="preprocessor">#define KEY_NAME_CRVAL2                     "CRVAL2"</span>
+<a name="l00044"></a>00044 <span class="preprocessor"></span><span class="preprocessor">#define KEY_NAME_CRVAL3                     "CRVAL3"</span>
+<a name="l00045"></a>00045 <span class="preprocessor"></span>
+<a name="l00046"></a>00046 <span class="preprocessor">#define KEY_NAME_LOOP_STATE                "ESO AOS RTC LOOP STATE"</span>
+<a name="l00047"></a>00047 <span class="preprocessor"></span><span class="preprocessor">#define KEY_NAME_LOOP_LGS                  "ESO AOS RTC LOOP LGS"</span>
+<a name="l00048"></a>00048 <span class="preprocessor"></span><span class="preprocessor">#define KEY_NAME_INS1_MODE                 "ESO INS1 MODE"</span>
+<a name="l00049"></a>00049 <span class="preprocessor"></span>
+<a name="l00050"></a>00050 <span class="preprocessor">#define PAF_NAME_LOOP_STATE                "AOS RTC LOOP STATE"</span>
+<a name="l00051"></a>00051 <span class="preprocessor"></span><span class="preprocessor">#define PAF_NAME_LOOP_LGS                  "AOS RTC LOOP LGS"</span>
+<a name="l00052"></a>00052 <span class="preprocessor"></span><span class="preprocessor">#define PAF_NAME_INS1_MODE                 "INS1 MODE"</span>
+<a name="l00053"></a>00053 <span class="preprocessor"></span>
+<a name="l00054"></a>00054 <span class="preprocessor">#define KEY_HELP_LOOP_STATE                "Loop state, open or closed"</span>
+<a name="l00055"></a>00055 <span class="preprocessor"></span><span class="preprocessor">#define KEY_HELP_LOOP_LGS                  "LGS loop on or off"</span>
+<a name="l00056"></a>00056 <span class="preprocessor"></span><span class="preprocessor">#define KEY_HELP_INS1_MODE                 "Instrument mode used."</span>
+<a name="l00057"></a>00057 <span class="preprocessor"></span>
+<a name="l00058"></a>00058 <span class="preprocessor">#define KEY_NAME_CUMOFFX                   "ESO SEQ CUMOFFSETX"</span>
+<a name="l00059"></a>00059 <span class="preprocessor"></span><span class="preprocessor">#define KEY_NAME_CUMOFFY                   "ESO SEQ CUMOFFSETY"</span>
+<a name="l00060"></a>00060 <span class="preprocessor"></span>
+<a name="l00061"></a>00061 <span class="preprocessor">#define KEY_NAME_MJD_OBS                   "MJD-OBS"</span>
+<a name="l00062"></a>00062 <span class="preprocessor"></span><span class="preprocessor">#define KEY_NAME_OBS_NAME                   "ESO OBS NAME"</span>
+<a name="l00063"></a>00063 <span class="preprocessor"></span>
+<a name="l00064"></a>00064 <span class="preprocessor">#define KEY_NAME_PRO_CATG                  "ESO PRO CATG"</span>
+<a name="l00065"></a>00065 <span class="preprocessor"></span><span class="preprocessor">#define PAF_NAME_PRO_CATG                  "PRO CATG"</span>
+<a name="l00066"></a>00066 <span class="preprocessor"></span><span class="preprocessor">#define KEY_HELP_PRO_CATG                  "Category of pipeline product frame"</span>
+<a name="l00067"></a>00067 <span class="preprocessor"></span>
+<a name="l00068"></a>00068 
+<a name="l00069"></a>00069 <span class="preprocessor">#define KEY_NAME_DET_DIT                   "ESO DET DIT"</span>
+<a name="l00070"></a>00070 <span class="preprocessor"></span><span class="preprocessor">#define PAF_NAME_DET_DIT                   "DET DIT"</span>
+<a name="l00071"></a>00071 <span class="preprocessor"></span><span class="preprocessor">#define KEY_HELP_DET_DIT                   "Integration Time"</span>
+<a name="l00072"></a>00072 <span class="preprocessor"></span>
+<a name="l00073"></a>00073 <span class="preprocessor">#define KEY_NAME_DET_NDIT                  "ESO DET NDIT"</span>
+<a name="l00074"></a>00074 <span class="preprocessor"></span><span class="preprocessor">#define PAF_NAME_DET_NDIT                  "DET NDIT"</span>
+<a name="l00075"></a>00075 <span class="preprocessor"></span><span class="preprocessor">#define KEY_HELP_DET_NDIT                  "# of Sub-Integrations"</span>
+<a name="l00076"></a>00076 <span class="preprocessor"></span>
+<a name="l00077"></a>00077 <span class="preprocessor">#define KEY_NAME_NCORRS_NAME               "ESO DET NCORRS NAME"</span>
+<a name="l00078"></a>00078 <span class="preprocessor"></span><span class="preprocessor">#define PAF_NAME_NCORRS_NAME               "DET NCORRS NAME"</span>
+<a name="l00079"></a>00079 <span class="preprocessor"></span><span class="preprocessor">#define KEY_HELP_NCORRS_NAME               "Read-Out Mode Name"</span>
+<a name="l00080"></a>00080 <span class="preprocessor"></span>
+<a name="l00081"></a>00081 <span class="preprocessor">#define KEY_NAME_DET_NDSAMPLES             "ESO DET NDSAMPLES"</span>
+<a name="l00082"></a>00082 <span class="preprocessor"></span><span class="preprocessor">#define KEY_HELP_DET_NDSAMPLES             "# of Non-Dest. Samples"</span>
+<a name="l00083"></a>00083 <span class="preprocessor"></span><span class="preprocessor">#define PAF_NAME_DET_NDSAMPLES             "DET NDSAMPLES"</span>
+<a name="l00084"></a>00084 <span class="preprocessor"></span>
+<a name="l00085"></a>00085 
+<a name="l00086"></a>00086 <span class="preprocessor">#define KEY_NAME_FILT_NAME                 "ESO INS FILT1 NAME"</span>
+<a name="l00087"></a>00087 <span class="preprocessor"></span><span class="preprocessor">#define PAF_NAME_FILT_NAME                 "INS FILT1 NAME"</span>
+<a name="l00088"></a>00088 <span class="preprocessor"></span><span class="preprocessor">#define KEY_HELP_FILT_NAME                 "Filter name."</span>
+<a name="l00089"></a>00089 <span class="preprocessor"></span>
+<a name="l00090"></a>00090 <span class="preprocessor">#define KEY_NAME_FILT_ID                   "ESO INS FILT1 ID"</span>
+<a name="l00091"></a>00091 <span class="preprocessor"></span><span class="preprocessor">#define PAF_NAME_FILT_ID                   "INS FILT1 ID"</span>
+<a name="l00092"></a>00092 <span class="preprocessor"></span><span class="preprocessor">#define KEY_HELP_FILT_ID                   "Filter unique id."</span>
+<a name="l00093"></a>00093 <span class="preprocessor"></span>
+<a name="l00094"></a>00094 <span class="preprocessor">#define KEY_NAME_GRAT_NAME                 "ESO INS GRAT1 NAME"</span>
+<a name="l00095"></a>00095 <span class="preprocessor"></span><span class="preprocessor">#define PAF_NAME_GRAT_NAME                 "INS GRAT1 NAME"</span>
+<a name="l00096"></a>00096 <span class="preprocessor"></span><span class="preprocessor">#define KEY_HELP_GRAT_NAME                 "Grating common name."</span>
+<a name="l00097"></a>00097 <span class="preprocessor"></span>
+<a name="l00098"></a>00098 <span class="preprocessor">#define KEY_NAME_INS_SETUP                 "ESO INS SETUP ID"</span>
+<a name="l00099"></a>00099 <span class="preprocessor"></span><span class="preprocessor">#define PAF_NAME_INS_SETUP                 "INS SETUP ID"</span>
+<a name="l00100"></a>00100 <span class="preprocessor"></span><span class="preprocessor">#define KEY_HELP_INS_SETUP                 "Instrument setup identifier."</span>
+<a name="l00101"></a>00101 <span class="preprocessor"></span>
+<a name="l00102"></a>00102 <span class="preprocessor">#define KEY_NAME_GRAT_WLEN                 "ESO INS GRAT1 WLEN"</span>
+<a name="l00103"></a>00103 <span class="preprocessor"></span><span class="preprocessor">#define PAF_NAME_GRAT_WLEN                 "INS GRAT1 WLEN"</span>
+<a name="l00104"></a>00104 <span class="preprocessor"></span><span class="preprocessor">#define KEY_HELP_GRAT_WLEN                 "Grating central wavelength [nm]."</span>
+<a name="l00105"></a>00105 <span class="preprocessor"></span>
+<a name="l00106"></a>00106 
+<a name="l00107"></a>00107 <span class="preprocessor">#define KEY_NAME_PRO_REC1_RAW1_NAME        "ESO PRO REC1 RAW1 NAME"</span>
+<a name="l00108"></a>00108 <span class="preprocessor"></span>
+<a name="l00109"></a>00109 <span class="preprocessor">#define KEY_NAME_LAMP_XE                   "ESO INS1 LAMP1 ST"</span>
+<a name="l00110"></a>00110 <span class="preprocessor"></span><span class="preprocessor">#define KEY_NAME_LAMP_KR                   "ESO INS1 LAMP2 ST"</span>
+<a name="l00111"></a>00111 <span class="preprocessor"></span><span class="preprocessor">#define KEY_NAME_LAMP_NE                   "ESO INS1 LAMP3 ST"</span>
+<a name="l00112"></a>00112 <span class="preprocessor"></span><span class="preprocessor">#define KEY_NAME_LAMP_AR                   "ESO INS1 LAMP4 ST"</span>
+<a name="l00113"></a>00113 <span class="preprocessor"></span><span class="preprocessor">#define KEY_NAME_LAMP_HALO                 "ESO INS1 LAMP5 ST"</span>
+<a name="l00114"></a>00114 <span class="preprocessor"></span><span class="preprocessor">#define PAF_NAME_LAMP_HALO                 "INS1 LAMP5 ST"</span>
+<a name="l00115"></a>00115 <span class="preprocessor"></span><span class="preprocessor">#define KEY_HELP_LAMP_HALO                 "Lamp activated."</span>
+<a name="l00116"></a>00116 <span class="preprocessor"></span>
+<a name="l00117"></a>00117 <span class="preprocessor">#define KEY_NAME_SHUT2_ST                  "ESO INS1 SHUT2 ST"</span>
+<a name="l00118"></a>00118 <span class="preprocessor"></span><span class="preprocessor">#define PAF_NAME_SHUT2_ST                  "INS1 SHUT2 ST"</span>
+<a name="l00119"></a>00119 <span class="preprocessor"></span><span class="preprocessor">#define KEY_HELP_SHUT2_ST                  "Shutter open."</span>
+<a name="l00120"></a>00120 <span class="preprocessor"></span>
+<a name="l00121"></a>00121 <span class="preprocessor">#define KEY_NAME_PREOPTICS                 "ESO INS OPTI1 NAME"</span>
+<a name="l00122"></a>00122 <span class="preprocessor"></span><span class="preprocessor">#define PAF_NAME_PREOPTICS                 "INS OPTI1 NAME"</span>
+<a name="l00123"></a>00123 <span class="preprocessor"></span><span class="preprocessor">#define KEY_HELP_PREOPTICS                 "OPTIi name."</span>
+<a name="l00124"></a>00124 <span class="preprocessor"></span>
+<a name="l00125"></a>00125 <span class="preprocessor">#define KEY_NAME_DPR_TYPE                  "ESO DPR TYPE"</span>
+<a name="l00126"></a>00126 <span class="preprocessor"></span><span class="preprocessor">#define PAF_NAME_DPR_TYPE                  "DPR TYPE"</span>
+<a name="l00127"></a>00127 <span class="preprocessor"></span><span class="preprocessor">#define KEY_HELP_DPR_TYPE                  "Observation type"</span>
+<a name="l00128"></a>00128 <span class="preprocessor"></span>
+<a name="l00129"></a>00129 <span class="preprocessor">#define KEY_NAME_DPR_CATG                  "ESO DPR CATG"</span>
+<a name="l00130"></a>00130 <span class="preprocessor"></span><span class="preprocessor">#define PAF_NAME_DPR_CATG                  "DPR CATG"</span>
+<a name="l00131"></a>00131 <span class="preprocessor"></span><span class="preprocessor">#define KEY_HELP_DPR_CATG                  "Observation category"</span>
+<a name="l00132"></a>00132 <span class="preprocessor"></span>
+<a name="l00133"></a>00133 <span class="preprocessor">#define KEY_NAME_DPR_TECH                  "ESO DPR TECH"</span>
+<a name="l00134"></a>00134 <span class="preprocessor"></span><span class="preprocessor">#define PAF_NAME_DPR_TECH                  "DPR TECH"</span>
+<a name="l00135"></a>00135 <span class="preprocessor"></span><span class="preprocessor">#define KEY_HELP_DPR_TECH                  "Observation technique"</span>
+<a name="l00136"></a>00136 <span class="preprocessor"></span>
+<a name="l00137"></a>00137 <span class="preprocessor">#define KEY_NAME_PIPE_ID                   "ESO PRO REC1 PIPE ID"</span>
+<a name="l00138"></a>00138 <span class="preprocessor"></span><span class="preprocessor">#define PAF_NAME_PIPE_ID                   "PRO REC1 PIPE ID"</span>
+<a name="l00139"></a>00139 <span class="preprocessor"></span><span class="preprocessor">#define KEY_HELP_PIPE_ID                   "Pipeline (unique) identifier"</span>
+<a name="l00140"></a>00140 <span class="preprocessor"></span>
+<a name="l00141"></a>00141 <span class="preprocessor">#define KEY_NAME_PIPEFILE                  "PIPEFILE"</span>
+<a name="l00142"></a>00142 <span class="preprocessor"></span><span class="preprocessor">#define KEY_HELP_PIPEFILE                  "Filename of data product"</span>
+<a name="l00143"></a>00143 <span class="preprocessor"></span>
+<a name="l00144"></a>00144 <span class="preprocessor">#define KEY_NAME_PRO_TYPE                  "ESO PRO TYPE"</span>
+<a name="l00145"></a>00145 <span class="preprocessor"></span><span class="preprocessor">#define PAF_NAME_PRO_TYPE                  "PRO TYPE"</span>
+<a name="l00146"></a>00146 <span class="preprocessor"></span><span class="preprocessor">#define KEY_HELP_PRO_TYPE                  "Product Type"</span>
+<a name="l00147"></a>00147 <span class="preprocessor"></span>
+<a name="l00148"></a>00148 <span class="preprocessor">#define KEY_NAME_PRO_REDLEVEL              "ESO PRO REDLEVEL"</span>
+<a name="l00149"></a>00149 <span class="preprocessor"></span>
+<a name="l00150"></a>00150 <span class="preprocessor">#define KEY_NAME_PRO_CATG                  "ESO PRO CATG"</span>
+<a name="l00151"></a>00151 <span class="preprocessor"></span><span class="preprocessor">#define PAF_NAME_PRO_CATG                  "PRO CATG"</span>
+<a name="l00152"></a>00152 <span class="preprocessor"></span>
+<a name="l00153"></a>00153 <span class="preprocessor">#define KEY_NAME_PRO_STATUS                "ESO PRO STATUS"</span>
+<a name="l00154"></a>00154 <span class="preprocessor"></span>
+<a name="l00155"></a>00155 <span class="preprocessor">#define KEY_NAME_PRO_DATE                  "ESO PRO DATE"</span>
+<a name="l00156"></a>00156 <span class="preprocessor"></span>
+<a name="l00157"></a>00157 <span class="preprocessor">#define KEY_NAME_DATE_OBS                  "DATE-OBS"</span>
+<a name="l00158"></a>00158 <span class="preprocessor"></span><span class="preprocessor">#define KEY_HELP_DATE_OBS                  "Observing date"</span>
+<a name="l00159"></a>00159 <span class="preprocessor"></span>
+<a name="l00160"></a>00160 <span class="preprocessor">#define KEY_NAME_TEL_AIRM_START            "ESO TEL AIRM START"</span>
+<a name="l00161"></a>00161 <span class="preprocessor"></span><span class="preprocessor">#define PAF_NAME_TEL_AIRM_START            "TEL AIRM START"</span>
+<a name="l00162"></a>00162 <span class="preprocessor"></span><span class="preprocessor">#define KEY_HELP_TEL_AIRM_START            "Airmass at start"</span>
+<a name="l00163"></a>00163 <span class="preprocessor"></span>
+<a name="l00164"></a>00164 
+<a name="l00165"></a>00165 
+<a name="l00166"></a>00166 <span class="preprocessor">#define KEY_NAME_ARCFILE                   "ARCFILE"</span>
+<a name="l00167"></a>00167 <span class="preprocessor"></span><span class="preprocessor">#define KEY_HELP_ARCFILE                   "Archive file name"</span>
+<a name="l00168"></a>00168 <span class="preprocessor"></span>
+<a name="l00169"></a>00169 
+<a name="l00170"></a>00170 <span class="preprocessor">#define KEY_NAME_TPL_ID                    "ESO TPL ID"</span>
+<a name="l00171"></a>00171 <span class="preprocessor"></span><span class="preprocessor">#define PAF_NAME_TPL_ID                    "TPL ID"</span>
+<a name="l00172"></a>00172 <span class="preprocessor"></span><span class="preprocessor">#define KEY_HELP_TPL_ID                    "Template sig"</span>
+<a name="l00173"></a>00173 <span class="preprocessor"></span>
+<a name="l00174"></a>00174 <span class="preprocessor">#define KEY_NAME_DATANCOM                  "DATANCOM"</span>
+<a name="l00175"></a>00175 <span class="preprocessor"></span><span class="preprocessor">#define KEY_NAME_PRO_DATANCOM              "ESO PRO DATANCOM"</span>
+<a name="l00176"></a>00176 <span class="preprocessor"></span><span class="preprocessor">#define PAF_NAME_PRO_DATANCOM              "PRO DATANCOM"</span>
+<a name="l00177"></a>00177 <span class="preprocessor"></span><span class="preprocessor">#define KEY_HELP_PRO_DATANCOM              "Number of frames combined"</span>
+<a name="l00178"></a>00178 <span class="preprocessor"></span>
+<a name="l00179"></a>00179 <span class="preprocessor">#define KEY_NAME_PRO_RECID                "ESO PRO REC1 ID"</span>
+<a name="l00180"></a>00180 <span class="preprocessor"></span><span class="preprocessor">#define PAF_NAME_PRO_RECID                "PRO REC1 ID"</span>
+<a name="l00181"></a>00181 <span class="preprocessor"></span><span class="preprocessor">#define KEY_HELP_PRO_RECID                "Pipeline recipe (unique) identifier"</span>
+<a name="l00182"></a>00182 <span class="preprocessor"></span>
+<a name="l00183"></a>00183 <span class="preprocessor">#define KEY_NAME_PRO_DRSID                 "ESO PRO REC1 DRS ID"</span>
+<a name="l00184"></a>00184 <span class="preprocessor"></span><span class="preprocessor">#define PAF_NAME_PRO_DRSID                 "PRO REC1 DRS ID"</span>
+<a name="l00185"></a>00185 <span class="preprocessor"></span><span class="preprocessor">#define KEY_HELP_PRO_DRSID                 "Data Reduction System identifier"</span>
+<a name="l00186"></a>00186 <span class="preprocessor"></span>
+<a name="l00187"></a>00187 <span class="preprocessor">#define KEY_NAME_HPRO_TYPE                 "HIERARCH ESO PRO TYPE"</span>
+<a name="l00188"></a>00188 <span class="preprocessor"></span><span class="preprocessor">#define KEY_HELP_HPRO_TYPE                "product type"</span>
+<a name="l00189"></a>00189 <span class="preprocessor"></span>
+<a name="l00190"></a>00190 <span class="preprocessor">#define KEY_NAME_HPRO_CATG                 "HIERARCH ESO PRO CATG"</span>
+<a name="l00191"></a>00191 <span class="preprocessor"></span><span class="preprocessor">#define KEY_HELP_HPRO_CATG                 "product category"</span>
+<a name="l00192"></a>00192 <span class="preprocessor"></span>
+<a name="l00193"></a>00193 <span class="preprocessor">#define KEY_NAME_HPRO_STATUS               "HIERARCH ESO PRO STATUS"</span>
+<a name="l00194"></a>00194 <span class="preprocessor"></span><span class="preprocessor">#define KEY_HELP_HPRO_STATUS               "pipeline status"</span>
+<a name="l00195"></a>00195 <span class="preprocessor"></span>
+<a name="l00196"></a>00196 <span class="preprocessor">#define KEY_NAME_HPRO_DATE                 "HIERARCH ESO PRO DATE"</span>
+<a name="l00197"></a>00197 <span class="preprocessor"></span><span class="preprocessor">#define KEY_HELP_HPRO_DATE                 "pipeline execution date"</span>
+<a name="l00198"></a>00198 <span class="preprocessor"></span>
+<a name="l00199"></a>00199 
+<a name="l00200"></a>00200 <span class="preprocessor">#define KEY_NAME_HPRO_RECID                "HIERARCH ESO PRO REC ID"</span>
+<a name="l00201"></a>00201 <span class="preprocessor"></span><span class="preprocessor">#define KEY_HELP_HPRO_RECID                "recipe ID"</span>
+<a name="l00202"></a>00202 <span class="preprocessor"></span>
+<a name="l00203"></a>00203 <span class="preprocessor">#define KEY_NAME_HPRO_DRSID                "HIERARCH ESO PRO DRS ID"</span>
+<a name="l00204"></a>00204 <span class="preprocessor"></span><span class="preprocessor">#define KEY_HELP_HPRO_DRSID                "data reduction system ID"</span>
+<a name="l00205"></a>00205 <span class="preprocessor"></span>
+<a name="l00206"></a>00206 <span class="preprocessor">#define KEY_NAME_HPRO_DATANCOM             "HIERARCH ESO PRO DATANCOM"</span>
+<a name="l00207"></a>00207 <span class="preprocessor"></span><span class="preprocessor">#define KEY_NAME_HPRO_DID                  "HIERARCH ESO PRO DID"</span>
+<a name="l00208"></a>00208 <span class="preprocessor"></span><span class="preprocessor">#define KEY_VALUE_HPRO_DID                 "PRO-1.15"</span>
+<a name="l00209"></a>00209 <span class="preprocessor"></span><span class="preprocessor">#define KEY_HELP_HPRO_DID                  "Data dictionary for PRO"</span>
+<a name="l00210"></a>00210 <span class="preprocessor"></span>
+<a name="l00211"></a>00211 
+<a name="l00212"></a>00212 <span class="preprocessor">#define KEY_NAME_HPRO_DOID                  "HIERARCH ESO PRO DO ID"</span>
+<a name="l00213"></a>00213 <span class="preprocessor"></span><span class="preprocessor">#define KEY_VALUE_HPRO_DOID                 "DO-1_18"</span>
+<a name="l00214"></a>00214 <span class="preprocessor"></span><span class="preprocessor">#define KEY_HELP_HPRO_DOID                  "Data Organizer identification ID"</span>
+<a name="l00215"></a>00215 <span class="preprocessor"></span>
+<a name="l00216"></a>00216 
+<a name="l00217"></a>00217 <span class="preprocessor">#define KEY_NAME_HPRO_RBSID                  "HIERARCH ESO PRO RBS ID"</span>
+<a name="l00218"></a>00218 <span class="preprocessor"></span><span class="preprocessor">#define KEY_VALUE_HPRO_RBSID                 "RBS-1_11"</span>
+<a name="l00219"></a>00219 <span class="preprocessor"></span><span class="preprocessor">#define KEY_HELP_HPRO_RBSID      "Reduction Block Scheduler identification ID"</span>
+<a name="l00220"></a>00220 <span class="preprocessor"></span>
+<a name="l00221"></a>00221 <span class="preprocessor">#define KEY_NAME_REC1_RAW1_NAME            "ESO PRO REC1 RAW1 NAME"</span>
+<a name="l00222"></a>00222 <span class="preprocessor"></span>
+<a name="l00223"></a>00223 <span class="preprocessor">#define KEY_NAME_GRAT_ENC                  "ESO INS GRAT1 ENC"</span>
+<a name="l00224"></a>00224 <span class="preprocessor"></span>
+<a name="l00225"></a>00225 
+<a name="l00226"></a>00226 CPL_END_DECLS
+<a name="l00227"></a>00227 
+<a name="l00228"></a>00228 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__lamp__cfg_8c_source.html b/html/sinfo__lamp__cfg_8c_source.html
new file mode 100644
index 0000000..fa34b81
--- /dev/null
+++ b/html/sinfo__lamp__cfg_8c_source.html
@@ -0,0 +1,69 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_lamp_cfg.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_lamp_cfg.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name     :sinfo_lamp_cfg.c</span>
+<a name="l00022"></a>00022 <span class="comment">   Author     :Juergen Schreiber</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on    :March 2002</span>
+<a name="l00024"></a>00024 <span class="comment">   Description    :prepare halogen lamp spectrum frames configuration </span>
+<a name="l00025"></a>00025 <span class="comment">                 handling tools</span>
+<a name="l00026"></a>00026 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00032"></a>00032 <span class="comment">                                   Includes</span>
+<a name="l00033"></a>00033 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00034"></a>00034 <span class="preprocessor">#include "sinfo_lamp_cfg.h"</span>
+<a name="l00042"></a>00042 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00043"></a>00043 <span class="comment">                              Function codes</span>
+<a name="l00044"></a>00044 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00051"></a>00051 lamp_config * 
+<a name="l00052"></a>00052 sinfo_lamp_cfg_create(<span class="keywordtype">void</span>)
+<a name="l00053"></a>00053 {
+<a name="l00054"></a>00054     <span class="keywordflow">return</span> cpl_calloc(1, <span class="keyword">sizeof</span>(lamp_config));
+<a name="l00055"></a>00055 }
+<a name="l00056"></a>00056 
+<a name="l00063"></a>00063 <span class="keywordtype">void</span> 
+<a name="l00064"></a>00064 sinfo_lamp_cfg_destroy(lamp_config * sc)
+<a name="l00065"></a>00065 {
+<a name="l00066"></a>00066     <span class="keywordflow">if</span> (sc==NULL) return ;
+<a name="l00067"></a>00067 
+<a name="l00068"></a>00068     <span class="comment">/* Free main struct */</span>
+<a name="l00069"></a>00069     cpl_free(sc);
+<a name="l00070"></a>00070 
+<a name="l00071"></a>00071     return ;
+<a name="l00072"></a>00072 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__lamp__cfg_8h_source.html b/html/sinfo__lamp__cfg_8h_source.html
new file mode 100644
index 0000000..34cc304
--- /dev/null
+++ b/html/sinfo__lamp__cfg_8h_source.html
@@ -0,0 +1,96 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_lamp_cfg.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_lamp_cfg.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   File name     :    sinfo_lamp_cfg.h</span>
+<a name="l00021"></a>00021 <span class="comment">   Author         :    Juergen Schreiber</span>
+<a name="l00022"></a>00022 <span class="comment">   Created on    :    March 2002</span>
+<a name="l00023"></a>00023 <span class="comment">   Description    :    lamp_ini definitions + handling prototypes</span>
+<a name="l00024"></a>00024 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00025"></a>00025 <span class="preprocessor">#ifndef SINFO_LAMP_CFG_H</span>
+<a name="l00026"></a>00026 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_LAMP_CFG_H</span>
+<a name="l00027"></a>00027 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00028"></a>00028 <span class="comment">                                   Includes</span>
+<a name="l00029"></a>00029 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00030"></a>00030 <span class="preprocessor">#include <stdlib.h></span>
+<a name="l00031"></a>00031 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00032"></a>00032 <span class="preprocessor">#include "sinfo_globals.h"</span>
+<a name="l00033"></a>00033 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00034"></a>00034 <span class="comment">                                   Defines</span>
+<a name="l00035"></a>00035 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00036"></a>00036 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00037"></a>00037 <span class="comment">                                   New types</span>
+<a name="l00038"></a>00038 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00039"></a>00039 <span class="comment">/*</span>
+<a name="l00040"></a>00040 <span class="comment">  prepare lamp spectrum blackboard container</span>
+<a name="l00041"></a>00041 <span class="comment"></span>
+<a name="l00042"></a>00042 <span class="comment">  This structure holds all information related to the halogen lamp </span>
+<a name="l00043"></a>00043 <span class="comment">  spectrum handling</span>
+<a name="l00044"></a>00044 <span class="comment">  routine. It is used as a container for the flux of ancillary data,</span>
+<a name="l00045"></a>00045 <span class="comment">  computed values, and algorithm status. Pixel flux is separated from</span>
+<a name="l00046"></a>00046 <span class="comment">  the blackboard.</span>
+<a name="l00047"></a>00047 <span class="comment">  */</span>
+<a name="l00048"></a>00048 
+<a name="l00049"></a>00049 <span class="keyword">typedef</span> <span class="keyword">struct </span>lamp_config {
+<a name="l00050"></a>00050 <span class="comment">/*-------General---------*/</span>
+<a name="l00051"></a>00051         <span class="keywordtype">char</span> inFrame[FILE_NAME_SZ] ; <span class="comment">/* file name of the input halogen </span>
+<a name="l00052"></a>00052 <span class="comment">                                        lamp frame */</span>
+<a name="l00053"></a>00053         <span class="keywordtype">char</span> wavemapim[FILE_NAME_SZ] ; <span class="comment">/* file name of the wavelength map */</span>
+<a name="l00054"></a>00054         <span class="keywordtype">char</span> outName[FILE_NAME_SZ] ; <span class="comment">/* output name of resulting fits frame */</span>
+<a name="l00055"></a>00055 <span class="comment">/*------ Resampling ------*/</span>
+<a name="l00056"></a>00056         <span class="comment">/* number of coefficients for the polynomial interpolation </span>
+<a name="l00057"></a>00057 <span class="comment">          (order + 1) */</span>
+<a name="l00058"></a>00058         <span class="keywordtype">int</span> ncoeffs ;
+<a name="l00059"></a>00059         <span class="comment">/* number of rows in the resulting resampled image = </span>
+<a name="l00060"></a>00060 <span class="comment">           number of spectral bins */</span>
+<a name="l00061"></a>00061         <span class="keywordtype">int</span> nrows ;
+<a name="l00062"></a>00062 <span class="comment">/*------ Extractspectrum ------*/</span>
+<a name="l00063"></a>00063         <span class="comment">/* percentage of rejected low intensity pixels */</span>
+<a name="l00064"></a>00064         <span class="keywordtype">float</span> loReject ;      
+<a name="l00065"></a>00065         <span class="comment">/* percentage of rejected high intensity pixels */</span>
+<a name="l00066"></a>00066         <span class="keywordtype">float</span> hiReject ;
+<a name="l00067"></a>00067         <span class="comment">/* conversion factor of detector counts per intensity unit */</span>
+<a name="l00068"></a>00068         <span class="keywordtype">float</span> countsToIntensity ;
+<a name="l00069"></a>00069 } lamp_config ;
+<a name="l00070"></a>00070 
+<a name="l00071"></a>00071 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00072"></a>00072 <span class="comment">                               Function prototypes</span>
+<a name="l00073"></a>00073 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00081"></a>00081 lamp_config * 
+<a name="l00082"></a>00082 sinfo_lamp_cfg_create(<span class="keywordtype">void</span>);
+<a name="l00083"></a>00083 
+<a name="l00091"></a>00091 <span class="keywordtype">void</span> 
+<a name="l00092"></a>00092 sinfo_lamp_cfg_destroy(lamp_config * sc);
+<a name="l00093"></a>00093 
+<a name="l00094"></a>00094 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__lamp__flats__config_8c_source.html b/html/sinfo__lamp__flats__config_8c_source.html
new file mode 100644
index 0000000..12c80b3
--- /dev/null
+++ b/html/sinfo__lamp__flats__config_8c_source.html
@@ -0,0 +1,378 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_lamp_flats_config.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_lamp_flats_config.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_lamp_flats_config.c,v 1.4 2012/03/02 08:42:20 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the CPL (Common Pipeline Library)</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
+<a name="l00007"></a>00007 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span>
+<a name="l00008"></a>00008 <span class="comment"> * License as published by the Free Software Foundation; either</span>
+<a name="l00009"></a>00009 <span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
+<a name="l00014"></a>00014 <span class="comment"> * Lesser General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
+<a name="l00017"></a>00017 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2012/03/02 08:42:20 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.4 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> */</span>
+<a name="l00026"></a>00026 
+<a name="l00027"></a>00027 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00029"></a>00029 <span class="preprocessor">#endif</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span> <span class="comment">/****************************************************************</span>
+<a name="l00031"></a>00031 <span class="comment">  *   Lamp_Spec Frames Data Reduction Parameter Initialization        *</span>
+<a name="l00032"></a>00032 <span class="comment">  ****************************************************************/</span>
+<a name="l00033"></a>00033 
+<a name="l00034"></a>00034 <span class="preprocessor">#include "sinfo_lamp_flats_config.h"</span>
+<a name="l00042"></a>00042 <span class="keywordtype">void</span>
+<a name="l00043"></a>00043  sinfo_lamp_flats_config_add(cpl_parameterlist *list)
+<a name="l00044"></a>00044 {
+<a name="l00045"></a>00045 
+<a name="l00046"></a>00046   cpl_parameter *p;
+<a name="l00047"></a>00047 
+<a name="l00048"></a>00048   <span class="keywordflow">if</span> (!list) {
+<a name="l00049"></a>00049     <span class="keywordflow">return</span>;
+<a name="l00050"></a>00050   }
+<a name="l00051"></a>00051 
+<a name="l00052"></a>00052   <span class="comment">/*Reconstruction */</span>
+<a name="l00053"></a>00053  <span class="comment">/* the fraction [0...1] of rejected low intensity pixels when taking </span>
+<a name="l00054"></a>00054 <span class="comment">the average of columns */</span>
+<a name="l00055"></a>00055   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.lamp_flats.low_rejection"</span>,
+<a name="l00056"></a>00056                   CPL_TYPE_DOUBLE,
+<a name="l00057"></a>00057                               <span class="stringliteral">"lower rejection: "</span>
+<a name="l00058"></a>00058                               <span class="stringliteral">"percentage of rejected low intensity "</span>
+<a name="l00059"></a>00059                               <span class="stringliteral">"pixels before averaging"</span>,
+<a name="l00060"></a>00060                               <span class="stringliteral">"sinfoni.lamp_flats"</span>,
+<a name="l00061"></a>00061                               0.1,0.0,1.0);
+<a name="l00062"></a>00062 
+<a name="l00063"></a>00063   cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"lamp_flats-lo_rej"</span>);
+<a name="l00064"></a>00064   cpl_parameterlist_append(list, p);
+<a name="l00065"></a>00065 
+<a name="l00066"></a>00066  <span class="comment">/* the fraction [0...1] of rejected high intensity pixels when taking </span>
+<a name="l00067"></a>00067 <span class="comment">    the average of columns */</span>
+<a name="l00068"></a>00068   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.lamp_flats.high_rejection"</span>,
+<a name="l00069"></a>00069                   CPL_TYPE_DOUBLE,
+<a name="l00070"></a>00070                               <span class="stringliteral">"high rejection: "</span>
+<a name="l00071"></a>00071                               <span class="stringliteral">"percentage of rejected high intensity "</span>
+<a name="l00072"></a>00072                               <span class="stringliteral">"pixels before averaging"</span>,
+<a name="l00073"></a>00073                               <span class="stringliteral">"sinfoni.lamp_flats"</span>,
+<a name="l00074"></a>00074                               0.1,0.0,1.0);
+<a name="l00075"></a>00075 
+<a name="l00076"></a>00076   cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"lamp_flats-hi_rej"</span>);
+<a name="l00077"></a>00077   cpl_parameterlist_append(list, p);
+<a name="l00078"></a>00078 
+<a name="l00079"></a>00079 
+<a name="l00080"></a>00080   <span class="comment">/* indicator if the bad pixels of the flatfield should be interpolated */</span>
+<a name="l00081"></a>00081   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.lamp_flats.interpol_index"</span>,
+<a name="l00082"></a>00082                   CPL_TYPE_BOOL,
+<a name="l00083"></a>00083                               <span class="stringliteral">"Interpolation index switch: "</span>
+<a name="l00084"></a>00084                               <span class="stringliteral">"indicator if the bad pixels of the flatfield "</span>
+<a name="l00085"></a>00085                               <span class="stringliteral">"should be interpolated"</span>,
+<a name="l00086"></a>00086                               <span class="stringliteral">"sinfoni.lamp_flats"</span>,
+<a name="l00087"></a>00087                               FALSE);
+<a name="l00088"></a>00088 
+<a name="l00089"></a>00089 
+<a name="l00090"></a>00090   cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,
+<a name="l00091"></a>00091                           <span class="stringliteral">"lamp_flats-interpol_index"</span>);
+<a name="l00092"></a>00092   cpl_parameterlist_append(list, p);
+<a name="l00093"></a>00093 
+<a name="l00094"></a>00094  
+<a name="l00095"></a>00095   <span class="comment">/* maximal pixel distance from bad pixel to take valid pixels */</span>
+<a name="l00096"></a>00096   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.lamp_flats.max_rad"</span>,
+<a name="l00097"></a>00097                   CPL_TYPE_INT,
+<a name="l00098"></a>00098                               <span class="stringliteral">"Max Rad: "</span>
+<a name="l00099"></a>00099                               <span class="stringliteral">"maximal pixel distance from bad pixel "</span>
+<a name="l00100"></a>00100                               <span class="stringliteral">"to take valid pixels"</span>,
+<a name="l00101"></a>00101                               <span class="stringliteral">"sinfoni.lamp_flats"</span>,
+<a name="l00102"></a>00102                               4);
+<a name="l00103"></a>00103 
+<a name="l00104"></a>00104   cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"lamp_flats-max_rad"</span>);
+<a name="l00105"></a>00105   cpl_parameterlist_append(list, p);
+<a name="l00106"></a>00106 
+<a name="l00107"></a>00107 
+<a name="l00108"></a>00108   <span class="comment">/*  indicator if a bad pixel mask should be generated or not */</span> 
+<a name="l00109"></a>00109   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.lamp_flats.bad_ind"</span>,
+<a name="l00110"></a>00110                   CPL_TYPE_BOOL,
+<a name="l00111"></a>00111                               <span class="stringliteral">"indicator if a bad pixel mask should be "</span>
+<a name="l00112"></a>00112                               <span class="stringliteral">"generated or not"</span>,
+<a name="l00113"></a>00113                               <span class="stringliteral">"sinfoni.lamp_flats"</span>,
+<a name="l00114"></a>00114                               FALSE);
+<a name="l00115"></a>00115 
+<a name="l00116"></a>00116   cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"lamp_flats-bad_ind"</span>);
+<a name="l00117"></a>00117   cpl_parameterlist_append(list, p);
+<a name="l00118"></a>00118 
+<a name="l00119"></a>00119   <span class="comment">/*</span>
+<a name="l00120"></a>00120 <span class="comment">   factor of the sigma noise limit; to remove the column intensity tilt only </span>
+<a name="l00121"></a>00121 <span class="comment">   pixels which lie within a defined noise limit are used to fit a straight </span>
+<a name="l00122"></a>00122 <span class="comment">   line</span>
+<a name="l00123"></a>00123 <span class="comment">  */</span>
+<a name="l00124"></a>00124   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.lamp_flats.sigma_factor"</span>,
+<a name="l00125"></a>00125                   CPL_TYPE_DOUBLE,
+<a name="l00126"></a>00126                               <span class="stringliteral">"Sigma Factor: "</span>
+<a name="l00127"></a>00127                               <span class="stringliteral">"factor of the sigma noise limit; "</span>
+<a name="l00128"></a>00128                               <span class="stringliteral">"to remove the column intensity tilt only "</span>
+<a name="l00129"></a>00129                               <span class="stringliteral">"pixels which lie within a defined noise "</span>
+<a name="l00130"></a>00130                               <span class="stringliteral">"limit are used to fit a straight line"</span>,
+<a name="l00131"></a>00131                               <span class="stringliteral">"sinfoni.lamp_flats"</span>,
+<a name="l00132"></a>00132                               5.);
+<a name="l00133"></a>00133 
+<a name="l00134"></a>00134   cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"lamp_flats-sigma_factor"</span>);
+<a name="l00135"></a>00135   cpl_parameterlist_append(list, p);
+<a name="l00136"></a>00136 
+<a name="l00137"></a>00137   <span class="comment">/* </span>
+<a name="l00138"></a>00138 <span class="comment">   if |pixel - sinfo_median| > factor * standard deviation -> then the</span>
+<a name="l00139"></a>00139 <span class="comment">    pixel value is replaced by the median of the 8 nearest neighbors</span>
+<a name="l00140"></a>00140 <span class="comment">  */</span>
+<a name="l00141"></a>00141   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.lamp_flats.factor"</span>,
+<a name="l00142"></a>00142                   CPL_TYPE_DOUBLE,
+<a name="l00143"></a>00143                               <span class="stringliteral">"Factor: "</span>
+<a name="l00144"></a>00144                    <span class="stringliteral">"if |pixel - median| > factor * standard deviation -> "</span>
+<a name="l00145"></a>00145                    <span class="stringliteral">"then the pixel value is replaced by the median of the 8 "</span>
+<a name="l00146"></a>00146                    <span class="stringliteral">"nearest neighbors"</span>,
+<a name="l00147"></a>00147                               <span class="stringliteral">"sinfoni.lamp_flats"</span>,
+<a name="l00148"></a>00148                               3.);
+<a name="l00149"></a>00149 
+<a name="l00150"></a>00150   cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"lamp_flats-factor"</span>);
+<a name="l00151"></a>00151   cpl_parameterlist_append(list, p);
+<a name="l00152"></a>00152 
+<a name="l00153"></a>00153   <span class="comment">/* number of iterations to of sinfo_median filtering to find bad </span>
+<a name="l00154"></a>00154 <span class="comment">     pixel clusters */</span>
+<a name="l00155"></a>00155   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.lamp_flats.iterations"</span>,
+<a name="l00156"></a>00156                   CPL_TYPE_INT,
+<a name="l00157"></a>00157                               <span class="stringliteral">"Iterations: "</span>
+<a name="l00158"></a>00158                               <span class="stringliteral">"number of iterations to of median filtering "</span>
+<a name="l00159"></a>00159                               <span class="stringliteral">"to find bad pixel clusters"</span>,
+<a name="l00160"></a>00160                               <span class="stringliteral">"sinfoni.lamp_flats"</span>,
+<a name="l00161"></a>00161                               8);
+<a name="l00162"></a>00162 
+<a name="l00163"></a>00163   cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"lamp_flats-iterations"</span>);
+<a name="l00164"></a>00164   cpl_parameterlist_append(list, p);
+<a name="l00165"></a>00165 
+<a name="l00166"></a>00166   <span class="comment">/* percentage of rejected low intensity pixels before averaging */</span>
+<a name="l00167"></a>00167   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.lamp_flats.bad_low_rejection"</span>,
+<a name="l00168"></a>00168                   CPL_TYPE_DOUBLE,
+<a name="l00169"></a>00169                               <span class="stringliteral">"low rejection: "</span>
+<a name="l00170"></a>00170                               <span class="stringliteral">"Percentage for bad pixel low rejection"</span>,
+<a name="l00171"></a>00171                               <span class="stringliteral">"sinfoni.lamp_flats"</span>,
+<a name="l00172"></a>00172                               10.,0.,100.);
+<a name="l00173"></a>00173 
+<a name="l00174"></a>00174   cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"lamp_flats-bad_lo_rej"</span>);
+<a name="l00175"></a>00175   cpl_parameterlist_append(list, p);
+<a name="l00176"></a>00176 
+<a name="l00177"></a>00177   <span class="comment">/* percentage of rejected high intensity pixels before averaging */</span>
+<a name="l00178"></a>00178   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.lamp_flats.bad_high_rejection"</span>,
+<a name="l00179"></a>00179                   CPL_TYPE_DOUBLE,
+<a name="l00180"></a>00180                               <span class="stringliteral">"high rejection: "</span>
+<a name="l00181"></a>00181                               <span class="stringliteral">"Percentage for bad pixel high rejection"</span>,
+<a name="l00182"></a>00182                               <span class="stringliteral">"sinfoni.lamp_flats"</span>,
+<a name="l00183"></a>00183                               10.,0.,100.);
+<a name="l00184"></a>00184 
+<a name="l00185"></a>00185   cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"lamp_flats-bad_hi_rej"</span>);
+<a name="l00186"></a>00186   cpl_parameterlist_append(list, p);
+<a name="l00187"></a>00187 
+<a name="l00188"></a>00188 
+<a name="l00189"></a>00189   <span class="comment">/* to compute image statistics on a rectangular zone of the image</span>
+<a name="l00190"></a>00190 <span class="comment">     the coordinates of the rectangle are needed</span>
+<a name="l00191"></a>00191 <span class="comment">  */</span>
+<a name="l00192"></a>00192   <span class="comment">/* lower left x coordinate */</span>
+<a name="l00193"></a>00193   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.lamp_flats.llx"</span>,
+<a name="l00194"></a>00194                   CPL_TYPE_INT,
+<a name="l00195"></a>00195                               <span class="stringliteral">"Lower Lext X corner"</span>,
+<a name="l00196"></a>00196                               <span class="stringliteral">"sinfoni.lamp_flats"</span>,
+<a name="l00197"></a>00197                               1350,DET_PIX_MIN,DET_PIX_MAX);
+<a name="l00198"></a>00198 
+<a name="l00199"></a>00199   cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"lamp_flats-llx"</span>);
+<a name="l00200"></a>00200   cpl_parameterlist_append(list, p);
+<a name="l00201"></a>00201 
+<a name="l00202"></a>00202   <span class="comment">/* lower left y coordinate */</span>
+<a name="l00203"></a>00203   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.lamp_flats.lly"</span>,
+<a name="l00204"></a>00204                   CPL_TYPE_INT,
+<a name="l00205"></a>00205                               <span class="stringliteral">"Lower Lext Y corner"</span>,
+<a name="l00206"></a>00206                               <span class="stringliteral">"sinfoni.lamp_flats"</span>,
+<a name="l00207"></a>00207                               1000,DET_PIX_MIN,DET_PIX_MAX);
+<a name="l00208"></a>00208 
+<a name="l00209"></a>00209   cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"lamp_flats-lly"</span>);
+<a name="l00210"></a>00210   cpl_parameterlist_append(list, p);
+<a name="l00211"></a>00211 
+<a name="l00212"></a>00212   <span class="comment">/* upper right x coordinate */</span>
+<a name="l00213"></a>00213   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.lamp_flats.urx"</span>,
+<a name="l00214"></a>00214                   CPL_TYPE_INT,
+<a name="l00215"></a>00215                               <span class="stringliteral">"Upper right X corner"</span>,
+<a name="l00216"></a>00216                               <span class="stringliteral">"sinfoni.lamp_flats"</span>,
+<a name="l00217"></a>00217                               1390,DET_PIX_MIN,DET_PIX_MAX);
+<a name="l00218"></a>00218 
+<a name="l00219"></a>00219   cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"lamp_flats-rrx"</span>);
+<a name="l00220"></a>00220   cpl_parameterlist_append(list, p);
+<a name="l00221"></a>00221 
+<a name="l00222"></a>00222   <span class="comment">/* upper right y coordinate */</span>
+<a name="l00223"></a>00223   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.lamp_flats.ury"</span>,
+<a name="l00224"></a>00224                   CPL_TYPE_INT,
+<a name="l00225"></a>00225                               <span class="stringliteral">"Upper right Y corner"</span>,
+<a name="l00226"></a>00226                               <span class="stringliteral">"sinfoni.lamp_flats"</span>,
+<a name="l00227"></a>00227                               1200,DET_PIX_MIN,DET_PIX_MAX);
+<a name="l00228"></a>00228 
+<a name="l00229"></a>00229   cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"lamp_flats-ury"</span>);
+<a name="l00230"></a>00230   cpl_parameterlist_append(list, p);
+<a name="l00231"></a>00231 
+<a name="l00232"></a>00232   <span class="comment">/* indicator that indicates if the values beyond a threshold deviation */</span>
+<a name="l00233"></a>00233   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.lamp_flats.thresh_ind"</span>,
+<a name="l00234"></a>00234                   CPL_TYPE_BOOL,
+<a name="l00235"></a>00235                               <span class="stringliteral">"Treshold index: "</span>,
+<a name="l00236"></a>00236                               <span class="stringliteral">"sinfoni.lamp_flats"</span>,
+<a name="l00237"></a>00237                               FALSE);
+<a name="l00238"></a>00238 
+<a name="l00239"></a>00239 
+<a name="l00240"></a>00240   cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"lamp_flats-tresh_ind"</span>);
+<a name="l00241"></a>00241   cpl_parameterlist_append(list, p);
+<a name="l00242"></a>00242 
+<a name="l00243"></a>00243   <span class="comment">/* </span>
+<a name="l00244"></a>00244 <span class="comment">  factor to the clean standard deviation to define the threshold deviation</span>
+<a name="l00245"></a>00245 <span class="comment">  from the clean mean</span>
+<a name="l00246"></a>00246 <span class="comment">  */</span>
+<a name="l00247"></a>00247   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.lamp_flats.mean_factor"</span>,
+<a name="l00248"></a>00248                   CPL_TYPE_DOUBLE,
+<a name="l00249"></a>00249                               <span class="stringliteral">"Mean Factor: "</span>
+<a name="l00250"></a>00250                               <span class="stringliteral">"factor to the clean standard deviation to "</span>
+<a name="l00251"></a>00251                               <span class="stringliteral">"define the threshold deviation "</span>
+<a name="l00252"></a>00252                               <span class="stringliteral">"from the clean mean"</span>,
+<a name="l00253"></a>00253                               <span class="stringliteral">"sinfoni.lamp_flats"</span>,
+<a name="l00254"></a>00254                               10.);
+<a name="l00255"></a>00255 
+<a name="l00256"></a>00256   cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"lamp_flats-mean_factor"</span>);
+<a name="l00257"></a>00257   cpl_parameterlist_append(list, p);
+<a name="l00258"></a>00258 
+<a name="l00259"></a>00259 
+<a name="l00260"></a>00260   <span class="comment">/* QC LOG */</span>
+<a name="l00261"></a>00261  <span class="comment">/* FPN */</span>
+<a name="l00262"></a>00262 
+<a name="l00263"></a>00263 
+<a name="l00264"></a>00264  p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.lamp_flats.qc_fpn_xmin1"</span>,
+<a name="l00265"></a>00265                   CPL_TYPE_INT,
+<a name="l00266"></a>00266                               <span class="stringliteral">"qc_fpn_xmin1"</span>,
+<a name="l00267"></a>00267                               <span class="stringliteral">"sinfoni.lamp_flats"</span>,
+<a name="l00268"></a>00268                               512,DET_PIX_MIN,DET_PIX_MAX);
+<a name="l00269"></a>00269 
+<a name="l00270"></a>00270   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"lamp_flats-qc_fpn_xmin1"</span>);
+<a name="l00271"></a>00271   cpl_parameterlist_append(list, p);
+<a name="l00272"></a>00272   
+<a name="l00273"></a>00273  
+<a name="l00274"></a>00274   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.lamp_flats.qc_fpn_xmax1"</span>,
+<a name="l00275"></a>00275                   CPL_TYPE_INT,
+<a name="l00276"></a>00276                               <span class="stringliteral">"qc_fpn_xmax1"</span>,
+<a name="l00277"></a>00277                               <span class="stringliteral">"sinfoni.lamp_flats"</span>,
+<a name="l00278"></a>00278                               1536,DET_PIX_MIN,DET_PIX_MAX);
+<a name="l00279"></a>00279 
+<a name="l00280"></a>00280   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"lamp_flats-qc_fpn_xmax1"</span>);
+<a name="l00281"></a>00281   cpl_parameterlist_append(list, p);
+<a name="l00282"></a>00282 
+<a name="l00283"></a>00283   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.lamp_flats.qc_fpn_ymin1"</span>,
+<a name="l00284"></a>00284                   CPL_TYPE_INT,
+<a name="l00285"></a>00285                               <span class="stringliteral">"qc_fpn_ymin1"</span>,
+<a name="l00286"></a>00286                               <span class="stringliteral">"sinfoni.lamp_flats"</span>,
+<a name="l00287"></a>00287                               512,DET_PIX_MIN,DET_PIX_MAX);
+<a name="l00288"></a>00288 
+<a name="l00289"></a>00289   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"lamp_flats-qc_fpn_ymin1"</span>);
+<a name="l00290"></a>00290   cpl_parameterlist_append(list, p);
+<a name="l00291"></a>00291 
+<a name="l00292"></a>00292 
+<a name="l00293"></a>00293   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.lamp_flats.qc_fpn_ymax1"</span>,
+<a name="l00294"></a>00294                   CPL_TYPE_INT,
+<a name="l00295"></a>00295                               <span class="stringliteral">"qc_fpn_ymax1"</span>,
+<a name="l00296"></a>00296                               <span class="stringliteral">"sinfoni.lamp_flats"</span>,
+<a name="l00297"></a>00297                               1536,DET_PIX_MIN,DET_PIX_MAX);
+<a name="l00298"></a>00298 
+<a name="l00299"></a>00299   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"lamp_flats-qc_fpn_ymax1"</span>);
+<a name="l00300"></a>00300   cpl_parameterlist_append(list, p);
+<a name="l00301"></a>00301 
+<a name="l00302"></a>00302 
+<a name="l00303"></a>00303 
+<a name="l00304"></a>00304 
+<a name="l00305"></a>00305 
+<a name="l00306"></a>00306 
+<a name="l00307"></a>00307  p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.lamp_flats.qc_fpn_xmin2"</span>,
+<a name="l00308"></a>00308                   CPL_TYPE_INT,
+<a name="l00309"></a>00309                               <span class="stringliteral">"qc_fpn_xmin2"</span>,
+<a name="l00310"></a>00310                               <span class="stringliteral">"sinfoni.lamp_flats"</span>,
+<a name="l00311"></a>00311                               1350,DET_PIX_MIN,DET_PIX_MAX);
+<a name="l00312"></a>00312 
+<a name="l00313"></a>00313   cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"lamp_flats-qc_fpn_xmin2"</span>);
+<a name="l00314"></a>00314   cpl_parameterlist_append(list, p);
+<a name="l00315"></a>00315   
+<a name="l00316"></a>00316  
+<a name="l00317"></a>00317   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.lamp_flats.qc_fpn_xmax2"</span>,
+<a name="l00318"></a>00318                   CPL_TYPE_INT,
+<a name="l00319"></a>00319                               <span class="stringliteral">"qc_fpn_xmax2"</span>,
+<a name="l00320"></a>00320                               <span class="stringliteral">"sinfoni.lamp_flats"</span>,
+<a name="l00321"></a>00321                               1390,DET_PIX_MIN,DET_PIX_MAX);
+<a name="l00322"></a>00322 
+<a name="l00323"></a>00323   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"lamp_flats-qc_fpn_xmax2"</span>);
+<a name="l00324"></a>00324   cpl_parameterlist_append(list, p);
+<a name="l00325"></a>00325 
+<a name="l00326"></a>00326   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.lamp_flats.qc_fpn_ymin2"</span>,
+<a name="l00327"></a>00327                   CPL_TYPE_INT,
+<a name="l00328"></a>00328                               <span class="stringliteral">"qc_fpn_ymin2"</span>,
+<a name="l00329"></a>00329                               <span class="stringliteral">"sinfoni.lamp_flats"</span>,
+<a name="l00330"></a>00330                               1000,DET_PIX_MIN,DET_PIX_MAX);
+<a name="l00331"></a>00331 
+<a name="l00332"></a>00332   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"lamp_flats-qc_fpn_ymin2"</span>);
+<a name="l00333"></a>00333   cpl_parameterlist_append(list, p);
+<a name="l00334"></a>00334 
+<a name="l00335"></a>00335 
+<a name="l00336"></a>00336   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.lamp_flats.qc_fpn_ymax2"</span>,
+<a name="l00337"></a>00337                   CPL_TYPE_INT,
+<a name="l00338"></a>00338                               <span class="stringliteral">"qc_fpn_ymax2"</span>,
+<a name="l00339"></a>00339                               <span class="stringliteral">"sinfoni.lamp_flats"</span>,
+<a name="l00340"></a>00340                               1200,DET_PIX_MIN,DET_PIX_MAX);
+<a name="l00341"></a>00341 
+<a name="l00342"></a>00342   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"lamp_flats-qc_fpn_ymax2"</span>);
+<a name="l00343"></a>00343   cpl_parameterlist_append(list, p);
+<a name="l00344"></a>00344 
+<a name="l00345"></a>00345 
+<a name="l00346"></a>00346 
+<a name="l00347"></a>00347 
+<a name="l00348"></a>00348 
+<a name="l00349"></a>00349   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.lamp_flats.qc_thresh_min"</span>,
+<a name="l00350"></a>00350                   CPL_TYPE_INT,
+<a name="l00351"></a>00351                               <span class="stringliteral">"qc_thresh_min"</span>,
+<a name="l00352"></a>00352                               <span class="stringliteral">"sinfoni.lamp_flats"</span>,
+<a name="l00353"></a>00353                               0);
+<a name="l00354"></a>00354 
+<a name="l00355"></a>00355   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"lamp_flats-qc_thresh_min"</span>);
+<a name="l00356"></a>00356   cpl_parameterlist_append(list, p);
+<a name="l00357"></a>00357 
+<a name="l00358"></a>00358 
+<a name="l00359"></a>00359   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.lamp_flats.qc_thresh_max"</span>,
+<a name="l00360"></a>00360                   CPL_TYPE_INT,
+<a name="l00361"></a>00361                               <span class="stringliteral">"qc_thresh_max"</span>,
+<a name="l00362"></a>00362                               <span class="stringliteral">"sinfoni.lamp_flats"</span>,
+<a name="l00363"></a>00363                               49000);
+<a name="l00364"></a>00364 
+<a name="l00365"></a>00365   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"lamp_flats-qc_thresh_max"</span>);
+<a name="l00366"></a>00366   cpl_parameterlist_append(list, p);
+<a name="l00367"></a>00367 
+<a name="l00368"></a>00368 
+<a name="l00369"></a>00369 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__lamp__flats__config_8h_source.html b/html/sinfo__lamp__flats__config_8h_source.html
new file mode 100644
index 0000000..b7e7627
--- /dev/null
+++ b/html/sinfo__lamp__flats__config_8h_source.html
@@ -0,0 +1,55 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_lamp_flats_config.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_lamp_flats_config.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_lamp_flats_config.h,v 1.1 2006/10/20 08:06:32 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the CPL (Common Pipeline Library)</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
+<a name="l00007"></a>00007 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span>
+<a name="l00008"></a>00008 <span class="comment"> * License as published by the Free Software Foundation; either</span>
+<a name="l00009"></a>00009 <span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
+<a name="l00014"></a>00014 <span class="comment"> * Lesser General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
+<a name="l00017"></a>00017 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2006/10/20 08:06:32 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.1 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> */</span>
+<a name="l00026"></a>00026 
+<a name="l00027"></a>00027  <span class="comment">/****************************************************************</span>
+<a name="l00028"></a>00028 <span class="comment">  *   Lamp_Spec Frames Data Reduction Parameter Initialization        *</span>
+<a name="l00029"></a>00029 <span class="comment">  ****************************************************************/</span>
+<a name="l00030"></a>00030 <span class="preprocessor">#include <cpl.h></span>    <span class="comment">/* defines parlist structure */</span>
+<a name="l00031"></a>00031 
+<a name="l00032"></a>00032 <span class="comment">/*</span>
+<a name="l00033"></a>00033 <span class="comment">#include "sinfo_dfs.h"</span>
+<a name="l00034"></a>00034 <span class="comment">*/</span>
+<a name="l00035"></a>00035 <span class="preprocessor">#include "sinfo_globals.h"</span>
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="keywordtype">void</span>
+<a name="l00038"></a>00038 sinfo_lamp_flats_config_add(cpl_parameterlist *list);
+<a name="l00039"></a>00039 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__lamp__flats__hidden__config_8c_source.html b/html/sinfo__lamp__flats__hidden__config_8c_source.html
new file mode 100644
index 0000000..3ee558f
--- /dev/null
+++ b/html/sinfo__lamp__flats__hidden__config_8c_source.html
@@ -0,0 +1,92 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_lamp_flats_hidden_config.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_lamp_flats_hidden_config.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_lamp_flats_hidden_config.c,v 1.5 2012/03/02 08:42:20 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the CPL (Common Pipeline Library)</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
+<a name="l00007"></a>00007 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span>
+<a name="l00008"></a>00008 <span class="comment"> * License as published by the Free Software Foundation; either</span>
+<a name="l00009"></a>00009 <span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
+<a name="l00014"></a>00014 <span class="comment"> * Lesser General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
+<a name="l00017"></a>00017 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2012/03/02 08:42:20 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.5 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> */</span>
+<a name="l00026"></a>00026 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00027"></a>00027 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00028"></a>00028 <span class="preprocessor">#endif</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span>
+<a name="l00030"></a>00030  <span class="comment">/****************************************************************</span>
+<a name="l00031"></a>00031 <span class="comment">  *   Lamp_Spec Frames Data Reduction Parameter Initialization        *</span>
+<a name="l00032"></a>00032 <span class="comment">  ****************************************************************/</span>
+<a name="l00033"></a>00033 
+<a name="l00034"></a>00034 <span class="preprocessor">#include "sinfo_lamp_flats_hidden_config.h"</span>
+<a name="l00043"></a>00043 <span class="keywordtype">void</span>
+<a name="l00044"></a>00044  sinfoni_lamp_flats_hidden_config_add(cpl_parameterlist *list)
+<a name="l00045"></a>00045 {
+<a name="l00046"></a>00046 
+<a name="l00047"></a>00047   cpl_parameter *p;
+<a name="l00048"></a>00048 
+<a name="l00049"></a>00049   <span class="keywordflow">if</span> (!list) {
+<a name="l00050"></a>00050     <span class="keywordflow">return</span>;
+<a name="l00051"></a>00051   }
+<a name="l00052"></a>00052 
+<a name="l00053"></a>00053 
+<a name="l00054"></a>00054   <span class="comment">/* Output file name */</span>
+<a name="l00055"></a>00055 <span class="comment">/* output name of resulting fits wavelength map */</span>
+<a name="l00056"></a>00056   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.lamp_flats.output_filename"</span>,
+<a name="l00057"></a>00057                   CPL_TYPE_STRING,
+<a name="l00058"></a>00058                               <span class="stringliteral">"Output File Name: "</span>,
+<a name="l00059"></a>00059                               <span class="stringliteral">"sinfoni.lamp_flats"</span>,
+<a name="l00060"></a>00060                               <span class="stringliteral">"out_flat.fits"</span>);
+<a name="l00061"></a>00061 
+<a name="l00062"></a>00062 
+<a name="l00063"></a>00063   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"out-lampflat_filename"</span>);
+<a name="l00064"></a>00064   cpl_parameterlist_append(list, p);
+<a name="l00065"></a>00065 
+<a name="l00066"></a>00066 
+<a name="l00067"></a>00067   <span class="comment">/* name of the bad pixel mask fits file to be generated */</span>
+<a name="l00068"></a>00068   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.lamp_flats.bp_mask_out"</span>,
+<a name="l00069"></a>00069                   CPL_TYPE_STRING,
+<a name="l00070"></a>00070                               <span class="stringliteral">"Output Bad pixel mask: "</span>
+<a name="l00071"></a>00071                               <span class="stringliteral">"name of the bad pixel mask fits file to be "</span>
+<a name="l00072"></a>00072                               <span class="stringliteral">"generated"</span>,
+<a name="l00073"></a>00073                               <span class="stringliteral">"sinfoni.lamp_flats"</span>,
+<a name="l00074"></a>00074                               <span class="stringliteral">"out_bpmask.fits"</span>);
+<a name="l00075"></a>00075 
+<a name="l00076"></a>00076 
+<a name="l00077"></a>00077   cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"lamp_flats-bp_mask_out"</span>);
+<a name="l00078"></a>00078   cpl_parameterlist_append(list, p);
+<a name="l00079"></a>00079 
+<a name="l00080"></a>00080 
+<a name="l00081"></a>00081 
+<a name="l00082"></a>00082 
+<a name="l00083"></a>00083 
+<a name="l00084"></a>00084 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__lamp__flats__hidden__config_8h_source.html b/html/sinfo__lamp__flats__hidden__config_8h_source.html
new file mode 100644
index 0000000..a3f0385
--- /dev/null
+++ b/html/sinfo__lamp__flats__hidden__config_8h_source.html
@@ -0,0 +1,55 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_lamp_flats_hidden_config.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_lamp_flats_hidden_config.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_lamp_flats_hidden_config.h,v 1.1 2006/10/20 08:06:32 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the CPL (Common Pipeline Library)</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
+<a name="l00007"></a>00007 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span>
+<a name="l00008"></a>00008 <span class="comment"> * License as published by the Free Software Foundation; either</span>
+<a name="l00009"></a>00009 <span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
+<a name="l00014"></a>00014 <span class="comment"> * Lesser General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
+<a name="l00017"></a>00017 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2006/10/20 08:06:32 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.1 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> */</span>
+<a name="l00026"></a>00026 
+<a name="l00027"></a>00027  <span class="comment">/****************************************************************</span>
+<a name="l00028"></a>00028 <span class="comment">  *   Lamp_Spec Frames Data Reduction Parameter Initialization        *</span>
+<a name="l00029"></a>00029 <span class="comment">  ****************************************************************/</span>
+<a name="l00030"></a>00030 <span class="preprocessor">#include "cpl.h"</span>    <span class="comment">/* defines parlist structure */</span>
+<a name="l00031"></a>00031 
+<a name="l00032"></a>00032 <span class="comment">/*</span>
+<a name="l00033"></a>00033 <span class="comment">#include "sinfo_dfs.h"</span>
+<a name="l00034"></a>00034 <span class="comment">*/</span>
+<a name="l00035"></a>00035 <span class="preprocessor">#include "sinfo_globals.h"</span>
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="keywordtype">void</span>
+<a name="l00038"></a>00038 sinfoni_lamp_flats_hidden_config_add(cpl_parameterlist *list);
+<a name="l00039"></a>00039 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__lamp__ini_8c_source.html b/html/sinfo__lamp__ini_8c_source.html
new file mode 100644
index 0000000..ef383d7
--- /dev/null
+++ b/html/sinfo__lamp__ini_8c_source.html
@@ -0,0 +1,364 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_lamp_ini.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_lamp_ini.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name    :   lamp_ini.c</span>
+<a name="l00022"></a>00022 <span class="comment">   Author       :   Juergen Schreiber</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on   :Mar 08, 2002</span>
+<a name="l00024"></a>00024 <span class="comment">   Description  :prepare lamp spectrum frames ini file handling for SPIFFI</span>
+<a name="l00025"></a>00025 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00026"></a>00026 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00027"></a>00027 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00028"></a>00028 <span class="preprocessor">#endif</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00030"></a>00030 <span class="comment">                                Includes</span>
+<a name="l00031"></a>00031 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00032"></a>00032 <span class="preprocessor">#include "sinfo_lamp_ini.h"</span>
+<a name="l00033"></a>00033 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00034"></a>00034 <span class="comment">                    Functions private to this module</span>
+<a name="l00035"></a>00035 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00036"></a>00036 <span class="keyword">static</span> <span class="keywordtype">void</span>     parse_section_general(dictionary *, lamp_config *, <span class="keywordtype">int</span> *);
+<a name="l00037"></a>00037 <span class="keyword">static</span> <span class="keywordtype">void</span>     parse_section_resampling(dictionary *, lamp_config *, <span class="keywordtype">int</span> *);
+<a name="l00038"></a>00038 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00039"></a>00039 parse_section_extractspectrum(dictionary *, lamp_config *, <span class="keywordtype">int</span> *);
+<a name="l00040"></a>00040 
+<a name="l00049"></a>00049 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l00065"></a>00065 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00066"></a>00066 
+<a name="l00067"></a>00067 
+<a name="l00068"></a>00068 
+<a name="l00069"></a>00069 <span class="keywordtype">int</span> generateLamp_ini_file(
+<a name="l00070"></a>00070     <span class="keywordtype">char</span> * ini_name,
+<a name="l00071"></a>00071     <span class="keywordtype">char</span> * name_i,
+<a name="l00072"></a>00072     <span class="keywordtype">char</span> * name_o,
+<a name="l00073"></a>00073         <span class="keywordtype">char</span> * name_c
+<a name="l00074"></a>00074 )
+<a name="l00075"></a>00075 {
+<a name="l00076"></a>00076     FILE * ini_file ;
+<a name="l00077"></a>00077 
+<a name="l00078"></a>00078     <span class="keywordflow">if</span> (sinfo_file_exists(ini_name)) {
+<a name="l00079"></a>00079        <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"overwriting %s"</span>, ini_name) ;
+<a name="l00080"></a>00080     }
+<a name="l00081"></a>00081     <span class="keywordflow">if</span> ((ini_file = fopen(ini_name, <span class="stringliteral">"w"</span>)) == (FILE*)NULL) {
+<a name="l00082"></a>00082         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"cannot create .ini file %s"</span>, ini_name) ;
+<a name="l00083"></a>00083         <span class="keywordflow">return</span> -1 ;
+<a name="l00084"></a>00084     }
+<a name="l00085"></a>00085 
+<a name="l00086"></a>00086     fprintf(ini_file,
+<a name="l00087"></a>00087 <span class="stringliteral">"#\n"</span>
+<a name="l00088"></a>00088 <span class="stringliteral">"# Configuration file for the extraction of a halogen lamp spectrumn"</span>
+<a name="l00089"></a>00089 <span class="stringliteral">"#\n"</span>) ;
+<a name="l00090"></a>00090 
+<a name="l00091"></a>00091     fprintf(ini_file, <span class="stringliteral">"#\n\n[Eclipse]\n"</span>) ;
+<a name="l00092"></a>00092     fprintf(ini_file, <span class="stringliteral">"VersionNumber = %s\n\n"</span>, get_eclipse_version()) ;
+<a name="l00093"></a>00093     fprintf(ini_file,
+<a name="l00094"></a>00094 <span class="stringliteral">"\n"</span>
+<a name="l00095"></a>00095 <span class="stringliteral">"#\n"</span>
+<a name="l00096"></a>00096 <span class="stringliteral">"# ----- [General] configures various software stuff\n"</span>
+<a name="l00097"></a>00097 <span class="stringliteral">"#\n"</span>
+<a name="l00098"></a>00098 <span class="stringliteral">"# This section is not mandatory. All eclipse routines\n"</span>
+<a name="l00099"></a>00099 <span class="stringliteral">"# should be set once for all in a .eclipse-rc file.\n"</span>
+<a name="l00100"></a>00100 <span class="stringliteral">"# If you choose to use the variables here, they will\n"</span>
+<a name="l00101"></a>00101 <span class="stringliteral">"# override the settings you have in the environment.\n"</span>
+<a name="l00102"></a>00102 <span class="stringliteral">"# See the eclipse installation manual to see what\n"</span>
+<a name="l00103"></a>00103 <span class="stringliteral">"# these variables refer to.\n"</span>
+<a name="l00104"></a>00104 <span class="stringliteral">"#\n"</span>
+<a name="l00105"></a>00105 <span class="stringliteral">"\n"</span>
+<a name="l00106"></a>00106 <span class="stringliteral">"[General]\n"</span>
+<a name="l00107"></a>00107 <span class="stringliteral">"# MaximumMemory = 512 ;   integer, maximum megs to allocate in RAM\n"</span>
+<a name="l00108"></a>00108 <span class="stringliteral">"# MaximumSwap   = 2048 ;  integer, maximum megs to allocate in swap\n"</span>
+<a name="l00109"></a>00109 <span class="stringliteral">"# TmpDirName    = .   ;   path to temporary directory\n"</span>
+<a name="l00110"></a>00110 <span class="stringliteral">"\n"</span>
+<a name="l00111"></a>00111 <span class="stringliteral">"Verbose       = no ;   verbose mode activation\n"</span>
+<a name="l00112"></a>00112 <span class="stringliteral">"Debug         = no ;   debug mode activation\n"</span>
+<a name="l00113"></a>00113 <span class="stringliteral">"\n"</span>
+<a name="l00114"></a>00114 <span class="stringliteral">"# LogFile       = yes ;   activate message logging to a file\n"</span>
+<a name="l00115"></a>00115 <span class="stringliteral">"# LogFileName   = /tmp/spiffi-log ;  log file name\n"</span>
+<a name="l00116"></a>00116 <span class="stringliteral">"\n"</span>
+<a name="l00117"></a>00117 <span class="stringliteral">"\n"</span>) ;
+<a name="l00118"></a>00118     fprintf(ini_file,
+<a name="l00119"></a>00119 <span class="stringliteral">"#\n"</span>
+<a name="l00120"></a>00120 <span class="stringliteral">"# the following are the names given in the argument of the python script\n"</span>
+<a name="l00121"></a>00121 <span class="stringliteral">"#\n"</span>
+<a name="l00122"></a>00122 <span class="stringliteral">"\n"</span>) ;
+<a name="l00123"></a>00123         fprintf(ini_file,
+<a name="l00124"></a>00124 <span class="stringliteral">"InFrame   = %s ; input file name\n"</span> 
+<a name="l00125"></a>00125 <span class="stringliteral">"Wavemapim = %s ; file name of the wavelength map\n"</span> 
+<a name="l00126"></a>00126 <span class="stringliteral">"OutName   = %s ; name of output fits file\n"</span>
+<a name="l00127"></a>00127 , name_i, name_c, name_o ) ;
+<a name="l00128"></a>00128 
+<a name="l00129"></a>00129     fprintf(ini_file,
+<a name="l00130"></a>00130 <span class="stringliteral">"#\n"</span>
+<a name="l00131"></a>00131 <span class="stringliteral">"# [Resampling] resamples the spectra to a given pixel length\n"</span>
+<a name="l00132"></a>00132 <span class="stringliteral">"# ExtractSpectrum] takes the clean mean along the spatial pixels \n"</span>
+<a name="l00133"></a>00133 <span class="stringliteral">"# by avoiding the bad pixel positions and delivers the final \n"</span>
+<a name="l00134"></a>00134 <span class="stringliteral">"# halogen lamp\n"</span> <span class="stringliteral">"# spectrum\n"</span>
+<a name="l00135"></a>00135 <span class="stringliteral">"\n"</span>
+<a name="l00136"></a>00136 <span class="stringliteral">"[Resampling]\n"</span>
+<a name="l00137"></a>00137 <span class="stringliteral">"Ncoeffs               = 3 ;     number of coefficients for the polynomial\n"</span> 
+<a name="l00138"></a>00138 <span class="stringliteral">"                interpolation\n"</span>
+<a name="l00139"></a>00139 <span class="stringliteral">"Nrows                 = 2560 ;  number of image rows in the resampled frame\n"</span>
+<a name="l00140"></a>00140 <span class="stringliteral">"                (2560 for single frames, 5120 for dithered)\n"</span>
+<a name="l00141"></a>00141 <span class="stringliteral">"[ExtractSpectrum]\n"</span>
+<a name="l00142"></a>00142 <span class="stringliteral">"LoReject              = 0.1 ;   percentage of rejected low intensity pixels\n"</span>
+<a name="l00143"></a>00143 <span class="stringliteral">"                before averaging\n"</span> 
+<a name="l00144"></a>00144 <span class="stringliteral">"HiReject              = 0.1 ;   percentage of rejected high intensity pixels\n"</span>
+<a name="l00145"></a>00145 <span class="stringliteral">"                before averaging\n"</span> 
+<a name="l00146"></a>00146 <span class="stringliteral">"CountsToIntensity     = 1. ;    intensity conversion factor: counts per\n"</span>
+<a name="l00147"></a>00147 <span class="stringliteral">"                intensity unit\n"</span> 
+<a name="l00148"></a>00148 <span class="stringliteral">"\n"</span>
+<a name="l00149"></a>00149 <span class="stringliteral">"\n"</span>) ;
+<a name="l00150"></a>00150 
+<a name="l00151"></a>00151     fclose(ini_file) ;
+<a name="l00152"></a>00152     <span class="keywordflow">return</span> 0 ;
+<a name="l00153"></a>00153 }
+<a name="l00154"></a>00154 
+<a name="l00155"></a>00155 
+<a name="l00156"></a>00156 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l00167"></a>00167 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00168"></a>00168 
+<a name="l00169"></a>00169 lamp_config * parse_lamp_ini_file(<span class="keywordtype">char</span> * ini_name)
+<a name="l00170"></a>00170 {
+<a name="l00171"></a>00171         dictionary    *       sym ;
+<a name="l00172"></a>00172         lamp_config   *       cfg ;
+<a name="l00173"></a>00173         <span class="keywordtype">int</span>                   status ;
+<a name="l00174"></a>00174 
+<a name="l00175"></a>00175         <span class="keywordflow">if</span> (!sinfo_file_exists(ini_name)) {
+<a name="l00176"></a>00176             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"cannot find ini file [%s]: aborting"</span>, ini_name) ;
+<a name="l00177"></a>00177                 <span class="keywordflow">return</span> NULL ;
+<a name="l00178"></a>00178         }
+<a name="l00179"></a>00179         sym = iniparser_load(ini_name) ;
+<a name="l00180"></a>00180         <span class="keywordflow">if</span> (sym == NULL) {
+<a name="l00181"></a>00181             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"in parsing ini file [%s]: aborting"</span>, ini_name) ;
+<a name="l00182"></a>00182                 <span class="keywordflow">return</span> NULL ;
+<a name="l00183"></a>00183         }
+<a name="l00184"></a>00184 
+<a name="l00185"></a>00185         cfg = sinfo_lamp_cfg_create();
+<a name="l00186"></a>00186         <span class="keywordflow">if</span> (cfg==NULL) {
+<a name="l00187"></a>00187             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"allocating lamp_config struct"</span>);
+<a name="l00188"></a>00188                 iniparser_freedict(sym) ;
+<a name="l00189"></a>00189                 <span class="keywordflow">return</span> NULL ;
+<a name="l00190"></a>00190         }
+<a name="l00191"></a>00191 
+<a name="l00192"></a>00192         <span class="comment">/*</span>
+<a name="l00193"></a>00193 <span class="comment">         * Perform sanity checks, fill up the structure with what was</span>
+<a name="l00194"></a>00194 <span class="comment">         * found in the ini file</span>
+<a name="l00195"></a>00195 <span class="comment">         */</span>
+<a name="l00196"></a>00196 
+<a name="l00197"></a>00197         status = 0 ;
+<a name="l00198"></a>00198         parse_section_general   (sym, cfg, &status);
+<a name="l00199"></a>00199         parse_section_resampling    (sym, cfg, &status);
+<a name="l00200"></a>00200         parse_section_extractspectrum (sym, cfg, &status);
+<a name="l00201"></a>00201 
+<a name="l00202"></a>00202         iniparser_freedict(sym);
+<a name="l00203"></a>00203 
+<a name="l00204"></a>00204         <span class="keywordflow">if</span> (status>0) {
+<a name="l00205"></a>00205            <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"%d errors in ini file [%s]"</span>, status, ini_name);
+<a name="l00206"></a>00206                 sinfo_lamp_cfg_destroy(cfg);
+<a name="l00207"></a>00207                 cfg = NULL ;
+<a name="l00208"></a>00208                 <span class="keywordflow">return</span> NULL ;
+<a name="l00209"></a>00209         }
+<a name="l00210"></a>00210         <span class="keywordflow">return</span> cfg ;
+<a name="l00211"></a>00211 }
+<a name="l00212"></a>00212 
+<a name="l00213"></a>00213 
+<a name="l00214"></a>00214 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00215"></a>00215 <span class="comment">   Functions:   parse_section_xxx()</span>
+<a name="l00216"></a>00216 <span class="comment">   In           :       symbolic table read from ini file</span>
+<a name="l00217"></a>00217 <span class="comment">   Out          :       void</span>
+<a name="l00218"></a>00218 <span class="comment">   Job          :       update a lamp_config structure from what can be</span>
+<a name="l00219"></a>00219 <span class="comment">                            found in the ini file.</span>
+<a name="l00220"></a>00220 <span class="comment">   Notice       :       all of these functions update a status integer to</span>
+<a name="l00221"></a>00221 <span class="comment">                        indicate if an error occurred, or leave it as it is if</span>
+<a name="l00222"></a>00222 <span class="comment">                        everything went Ok.</span>
+<a name="l00223"></a>00223 <span class="comment"></span>
+<a name="l00224"></a>00224 <span class="comment">        parse_section_general()</span>
+<a name="l00225"></a>00225 <span class="comment">        parse_section_resampling ()</span>
+<a name="l00226"></a>00226 <span class="comment">        parse_section_extractspectrum ()</span>
+<a name="l00227"></a>00227 <span class="comment"></span>
+<a name="l00228"></a>00228 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00229"></a>00229 
+<a name="l00230"></a>00230 
+<a name="l00231"></a>00231 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00232"></a>00232 parse_section_general(
+<a name="l00233"></a>00233         dictionary * sym,
+<a name="l00234"></a>00234         lamp_config * cfg,
+<a name="l00235"></a>00235         <span class="keywordtype">int</span> *status
+<a name="l00236"></a>00236 )
+<a name="l00237"></a>00237 {
+<a name="l00238"></a>00238         <span class="keywordtype">char</span>    *       cval ;
+<a name="l00239"></a>00239         <span class="keywordtype">int</span>             ival ;
+<a name="l00240"></a>00240 
+<a name="l00241"></a>00241         <span class="comment">/*</span>
+<a name="l00242"></a>00242 <span class="comment">         * General section</span>
+<a name="l00243"></a>00243 <span class="comment">         */</span>
+<a name="l00244"></a>00244         cval = iniparser_getstr(sym, <span class="stringliteral">"eclipse:versionnumber"</span>) ;
+<a name="l00245"></a>00245         <span class="keywordflow">if</span> (cval!=NULL) {
+<a name="l00246"></a>00246            <span class="keywordflow">if</span> (strcmp(cval, get_eclipse_version())) {
+<a name="l00247"></a>00247                <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"this ini file produced by version %s"</span>, cval);
+<a name="l00248"></a>00248                <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"you are running version %s"</span>, 
+<a name="l00249"></a>00249                                  get_eclipse_version());
+<a name="l00250"></a>00250                 }
+<a name="l00251"></a>00251         } <span class="keywordflow">else</span> {
+<a name="l00252"></a>00252                 <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"no eclipse version number found in file"</span>);
+<a name="l00253"></a>00253         }
+<a name="l00254"></a>00254 
+<a name="l00255"></a>00255         ival = iniparser_getint(sym, <span class="stringliteral">"general:maximummemory"</span>, -1);
+<a name="l00256"></a>00256         <span class="keywordflow">if</span> (ival>0) sinfo_set_memory_parameter(<span class="stringliteral">"max_ram"</span>, ival);
+<a name="l00257"></a>00257         ival = iniparser_getint(sym, <span class="stringliteral">"general:maximumswap"</span>, -1);
+<a name="l00258"></a>00258         <span class="keywordflow">if</span> (ival>0) sinfo_set_memory_parameter(<span class="stringliteral">"max_swap"</span>, ival);
+<a name="l00259"></a>00259         sinfo_set_verbose(iniparser_getboolean(sym, <span class="stringliteral">"general:verbose"</span>, 0));
+<a name="l00260"></a>00260         sinfo_set_debug(iniparser_getboolean(sym, <span class="stringliteral">"general:debug"</span>, 0));
+<a name="l00261"></a>00261 
+<a name="l00262"></a>00262         cval = iniparser_getstr(sym, <span class="stringliteral">"general:tmpdirname"</span>);
+<a name="l00263"></a>00263         <span class="keywordflow">if</span> (cval!=NULL) {
+<a name="l00264"></a>00264                 sinfo_set_tmpdirname(cval);
+<a name="l00265"></a>00265         } <span class="keywordflow">else</span> {
+<a name="l00266"></a>00266                 sinfo_set_tmpdirname(<span class="stringliteral">"."</span>);
+<a name="l00267"></a>00267         }
+<a name="l00268"></a>00268 
+<a name="l00269"></a>00269         ival = iniparser_getboolean(sym, <span class="stringliteral">"general:logfile"</span>, 0);
+<a name="l00270"></a>00270         <span class="keywordflow">if</span> (ival) {
+<a name="l00271"></a>00271                 cval = iniparser_getstr(sym, <span class="stringliteral">"general:logfilename"</span>);
+<a name="l00272"></a>00272                 <span class="keywordflow">if</span> (cval!=NULL) {
+<a name="l00273"></a>00273                         sinfo_set_logfile(1);
+<a name="l00274"></a>00274                         sinfo_set_logfilename(cval);
+<a name="l00275"></a>00275                 } <span class="keywordflow">else</span> {
+<a name="l00276"></a>00276                         sinfo_set_logfile(0) ;
+<a name="l00277"></a>00277                 }
+<a name="l00278"></a>00278         }
+<a name="l00279"></a>00279         cval = iniparser_getstr(sym, <span class="stringliteral">"general:inframe"</span>);
+<a name="l00280"></a>00280         <span class="keywordflow">if</span> (cval!=NULL) {
+<a name="l00281"></a>00281                 strcpy (cfg -> inFrame , cval ) ;
+<a name="l00282"></a>00282         } <span class="keywordflow">else</span> {
+<a name="l00283"></a>00283             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" InFrame in the .ini file was not found!\n"</span>) ;
+<a name="l00284"></a>00284             (*status)++ ;
+<a name="l00285"></a>00285         }
+<a name="l00286"></a>00286         cval = iniparser_getstr(sym, <span class="stringliteral">"general:wavemapim"</span>);
+<a name="l00287"></a>00287         <span class="keywordflow">if</span> (cval!=NULL) {
+<a name="l00288"></a>00288                 strcpy (cfg -> wavemapim , cval ) ;
+<a name="l00289"></a>00289         } <span class="keywordflow">else</span> {
+<a name="l00290"></a>00290             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" Wavemapim in the .ini file was not found!\n"</span>) ;
+<a name="l00291"></a>00291             (*status)++ ;
+<a name="l00292"></a>00292         }
+<a name="l00293"></a>00293 
+<a name="l00294"></a>00294         cval = iniparser_getstr(sym, <span class="stringliteral">"general:outname"</span>);
+<a name="l00295"></a>00295         <span class="keywordflow">if</span> (cval!=NULL) {
+<a name="l00296"></a>00296                 strcpy (cfg -> outName , cval );
+<a name="l00297"></a>00297         } <span class="keywordflow">else</span> {
+<a name="l00298"></a>00298             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" OutName in the .ini file was not found!\n"</span>) ;
+<a name="l00299"></a>00299             (*status)++ ;
+<a name="l00300"></a>00300         }
+<a name="l00301"></a>00301 
+<a name="l00302"></a>00302         <span class="keywordflow">if</span> (sinfo_verbose_active())
+<a name="l00303"></a>00303                 sinfo_print_memory_parameters();
+<a name="l00304"></a>00304         return ;
+<a name="l00305"></a>00305 }
+<a name="l00306"></a>00306 
+<a name="l00307"></a>00307 <span class="keyword">static</span> <span class="keywordtype">void</span>     parse_section_resampling(
+<a name="l00308"></a>00308         dictionary * sym,
+<a name="l00309"></a>00309         lamp_config * cfg,
+<a name="l00310"></a>00310         <span class="keywordtype">int</span> *status
+<a name="l00311"></a>00311 )
+<a name="l00312"></a>00312 {
+<a name="l00313"></a>00313         <span class="keywordtype">int</span>             ival ;
+<a name="l00314"></a>00314 
+<a name="l00315"></a>00315         ival = iniparser_getint(sym, <span class="stringliteral">"resampling:ncoeffs"</span>, -1) ;
+<a name="l00316"></a>00316         <span class="keywordflow">if</span> (ival != -1)
+<a name="l00317"></a>00317         {
+<a name="l00318"></a>00318             cfg -> ncoeffs = ival ;
+<a name="l00319"></a>00319         }
+<a name="l00320"></a>00320         <span class="keywordflow">else</span>
+<a name="l00321"></a>00321         {
+<a name="l00322"></a>00322             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" ncoeffs in the .ini file was not found!\n"</span>) ;
+<a name="l00323"></a>00323             (*status)++ ;
+<a name="l00324"></a>00324         }
+<a name="l00325"></a>00325 
+<a name="l00326"></a>00326         ival = iniparser_getint(sym, <span class="stringliteral">"resampling:nrows"</span>, -1) ;
+<a name="l00327"></a>00327         <span class="keywordflow">if</span> (ival != -1)
+<a name="l00328"></a>00328         {
+<a name="l00329"></a>00329             cfg -> nrows = ival ;
+<a name="l00330"></a>00330         }
+<a name="l00331"></a>00331         <span class="keywordflow">else</span>
+<a name="l00332"></a>00332         {
+<a name="l00333"></a>00333             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" nrows in the .ini file was not found!\n"</span>) ;
+<a name="l00334"></a>00334             (*status)++ ;
+<a name="l00335"></a>00335         }
+<a name="l00336"></a>00336 
+<a name="l00337"></a>00337         return ;
+<a name="l00338"></a>00338 
+<a name="l00339"></a>00339 }
+<a name="l00340"></a>00340 
+<a name="l00341"></a>00341 <span class="keyword">static</span> <span class="keywordtype">void</span>     parse_section_extractspectrum(
+<a name="l00342"></a>00342         dictionary * sym,
+<a name="l00343"></a>00343         lamp_config * cfg,
+<a name="l00344"></a>00344         <span class="keywordtype">int</span> *status )
+<a name="l00345"></a>00345 {
+<a name="l00346"></a>00346         <span class="keywordtype">float</span>           dval ;
+<a name="l00347"></a>00347 
+<a name="l00348"></a>00348         dval = iniparser_getdouble(sym, <span class="stringliteral">"extractspectrum:loreject"</span>, -1.) ;
+<a name="l00349"></a>00349         <span class="keywordflow">if</span> (dval!=-1.)
+<a name="l00350"></a>00350         {
+<a name="l00351"></a>00351             cfg -> loReject = dval ;
+<a name="l00352"></a>00352         }
+<a name="l00353"></a>00353         <span class="keywordflow">else</span>
+<a name="l00354"></a>00354         {
+<a name="l00355"></a>00355             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" LoReject in the .ini file was not found!\n"</span>) ;
+<a name="l00356"></a>00356             (*status)++ ;
+<a name="l00357"></a>00357         }
+<a name="l00358"></a>00358         dval = iniparser_getdouble(sym, <span class="stringliteral">"extractspectrum:hireject"</span>, -1.) ;
+<a name="l00359"></a>00359         <span class="keywordflow">if</span> (dval!=-1.)
+<a name="l00360"></a>00360         {
+<a name="l00361"></a>00361             cfg -> hiReject = dval ;
+<a name="l00362"></a>00362         }
+<a name="l00363"></a>00363         <span class="keywordflow">else</span>
+<a name="l00364"></a>00364         {
+<a name="l00365"></a>00365             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" hiReject in the .ini file was not found!\n"</span>) ;
+<a name="l00366"></a>00366             (*status)++ ;
+<a name="l00367"></a>00367         }
+<a name="l00368"></a>00368         dval=iniparser_getdouble(sym,<span class="stringliteral">"extractspectrum:countstointensity"</span>,-1.);
+<a name="l00369"></a>00369         <span class="keywordflow">if</span> (dval!=-1.)
+<a name="l00370"></a>00370         {
+<a name="l00371"></a>00371             cfg -> countsToIntensity = dval ;
+<a name="l00372"></a>00372         }
+<a name="l00373"></a>00373         <span class="keywordflow">else</span>
+<a name="l00374"></a>00374         {
+<a name="l00375"></a>00375           <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"CountsToIntensity in the .ini file was not found!"</span>);
+<a name="l00376"></a>00376           (*status)++ ;
+<a name="l00377"></a>00377         }
+<a name="l00378"></a>00378 
+<a name="l00379"></a>00379         return ;
+<a name="l00380"></a>00380 }
+<a name="l00381"></a>00381 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__lamp__ini_8h_source.html b/html/sinfo__lamp__ini_8h_source.html
new file mode 100644
index 0000000..a58aeb2
--- /dev/null
+++ b/html/sinfo__lamp__ini_8h_source.html
@@ -0,0 +1,63 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_lamp_ini.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_lamp_ini.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   File name    :   sinfo_lamp_ini.h</span>
+<a name="l00021"></a>00021 <span class="comment">   Author       :    Juergen Schreiber</span>
+<a name="l00022"></a>00022 <span class="comment">   Created on   :    Mar 08, 2002</span>
+<a name="l00023"></a>00023 <span class="comment">   Description  :    preparing lamp ini file handling for SPIFFI</span>
+<a name="l00024"></a>00024 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00025"></a>00025 <span class="preprocessor">#ifndef SINFO_LAMP_INI_H</span>
+<a name="l00026"></a>00026 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_LAMP_INI_H</span>
+<a name="l00027"></a>00027 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00028"></a>00028 <span class="comment">                                Includes</span>
+<a name="l00029"></a>00029 <span class="comment">---------------------------------------------------------------------------*/</span>
+<a name="l00030"></a>00030 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00031"></a>00031 <span class="preprocessor">#include "sinfo_lamp_cfg.h"</span>
+<a name="l00032"></a>00032 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                             Function prototypes </span>
+<a name="l00034"></a>00034 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00047"></a>00047 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00048"></a>00048 <span class="keywordtype">int</span> 
+<a name="l00049"></a>00049 generateLamp_ini_file(
+<a name="l00050"></a>00050         <span class="keywordtype">char</span> * ini_name,
+<a name="l00051"></a>00051         <span class="keywordtype">char</span> * name_i,
+<a name="l00052"></a>00052         <span class="keywordtype">char</span> * name_o,
+<a name="l00053"></a>00053         <span class="keywordtype">char</span> * name_c
+<a name="l00054"></a>00054 );
+<a name="l00055"></a>00055 
+<a name="l00065"></a>00065 lamp_config * 
+<a name="l00066"></a>00066 parse_lamp_ini_file(<span class="keywordtype">char</span> * ini_name) ;
+<a name="l00067"></a>00067 
+<a name="l00068"></a>00068 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__lamp__ini__by__cpl_8c_source.html b/html/sinfo__lamp__ini__by__cpl_8c_source.html
new file mode 100644
index 0000000..cdc8851
--- /dev/null
+++ b/html/sinfo__lamp__ini__by__cpl_8c_source.html
@@ -0,0 +1,208 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_lamp_ini_by_cpl.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_lamp_ini_by_cpl.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name    :   sinfo_lamp_ini_by_cpl.c</span>
+<a name="l00022"></a>00022 <span class="comment">   Author       :   Andrea Modigliani</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on   :   May 26, 2004</span>
+<a name="l00024"></a>00024 <span class="comment">   Description  :   lamp spectrum cpl input handling for SPIFFI</span>
+<a name="l00025"></a>00025 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00026"></a>00026 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00027"></a>00027 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00028"></a>00028 <span class="preprocessor">#endif</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00030"></a>00030 <span class="comment">                                Includes</span>
+<a name="l00031"></a>00031 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00032"></a>00032 <span class="preprocessor">#include <string.h></span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include "sinfo_lamp_ini_by_cpl.h"</span>
+<a name="l00034"></a>00034 <span class="preprocessor">#include "sinfo_functions.h"</span>
+<a name="l00035"></a>00035 <span class="preprocessor">#include "sinfo_pro_types.h"</span>
+<a name="l00036"></a>00036 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00037"></a>00037 <span class="comment">                    Functions private to this module</span>
+<a name="l00038"></a>00038 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00039"></a>00039 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00040"></a>00040 parse_section_frames(lamp_config *, 
+<a name="l00041"></a>00041                      cpl_parameterlist* cpl_cfg, 
+<a name="l00042"></a>00042                      cpl_frameset* sof, 
+<a name="l00043"></a>00043                      cpl_frameset** raw, 
+<a name="l00044"></a>00044                      <span class="keywordtype">int</span>* status);
+<a name="l00045"></a>00045 
+<a name="l00046"></a>00046 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00047"></a>00047 parse_section_resampling(lamp_config *, cpl_parameterlist* cpl_cfg);
+<a name="l00048"></a>00048 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00049"></a>00049 parse_section_extractspectrum(lamp_config *, cpl_parameterlist* cpl_cfg);
+<a name="l00050"></a>00050 
+<a name="l00069"></a>00069 lamp_config * 
+<a name="l00070"></a>00070 sinfo_parse_cpl_input_lamp(cpl_parameterlist* cpl_cfg, 
+<a name="l00071"></a>00071                            cpl_frameset* sof, 
+<a name="l00072"></a>00072                cpl_frameset** raw)
+<a name="l00073"></a>00073 
+<a name="l00074"></a>00074 {
+<a name="l00075"></a>00075         lamp_config   *       cfg= sinfo_lamp_cfg_create();
+<a name="l00076"></a>00076         <span class="keywordtype">int</span> status=0;
+<a name="l00077"></a>00077         <span class="comment">/*</span>
+<a name="l00078"></a>00078 <span class="comment">         * Perform sanity checks, fill up the structure with what was</span>
+<a name="l00079"></a>00079 <span class="comment">         * found in the ini file</span>
+<a name="l00080"></a>00080 <span class="comment">         */</span>
+<a name="l00081"></a>00081 
+<a name="l00082"></a>00082 
+<a name="l00083"></a>00083         parse_section_resampling    (cfg, cpl_cfg);
+<a name="l00084"></a>00084         parse_section_extractspectrum (cfg, cpl_cfg);
+<a name="l00085"></a>00085         parse_section_frames    (cfg, cpl_cfg, sof, raw,&status);
+<a name="l00086"></a>00086  
+<a name="l00087"></a>00087         <span class="keywordflow">if</span> (status > 0) {
+<a name="l00088"></a>00088                 <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"parsing cpl input"</span>);
+<a name="l00089"></a>00089                 sinfo_lamp_cfg_destroy(cfg);
+<a name="l00090"></a>00090                 cfg = NULL ;
+<a name="l00091"></a>00091                 <span class="keywordflow">return</span> NULL ;
+<a name="l00092"></a>00092         }
+<a name="l00093"></a>00093         <span class="keywordflow">return</span> cfg ;
+<a name="l00094"></a>00094 }
+<a name="l00095"></a>00095 
+<a name="l00096"></a>00096 
+<a name="l00106"></a>00106 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00107"></a>00107 parse_section_frames(lamp_config * cfg,
+<a name="l00108"></a>00108              cpl_parameterlist * cpl_cfg,
+<a name="l00109"></a>00109              cpl_frameset * sof,
+<a name="l00110"></a>00110              cpl_frameset ** raw,
+<a name="l00111"></a>00111                      <span class="keywordtype">int</span>* status)
+<a name="l00112"></a>00112 {
+<a name="l00113"></a>00113 
+<a name="l00114"></a>00114    cpl_frame* frame   = NULL;
+<a name="l00115"></a>00115    cpl_parameter *p; 
+<a name="l00116"></a>00116    <span class="keywordtype">int</span> nraw=0;
+<a name="l00117"></a>00117     <span class="keywordtype">char</span> spat_res[FILE_NAME_SZ];
+<a name="l00118"></a>00118    <span class="keywordtype">char</span> lamp_status[FILE_NAME_SZ];
+<a name="l00119"></a>00119    <span class="keywordtype">char</span> band[FILE_NAME_SZ];
+<a name="l00120"></a>00120    <span class="keywordtype">int</span> ins_set=0;
+<a name="l00121"></a>00121 
+<a name="l00122"></a>00122    <span class="comment">/* Input */</span>
+<a name="l00123"></a>00123 
+<a name="l00124"></a>00124    *raw=cpl_frameset_new();
+<a name="l00125"></a>00125    sinfo_extract_raw_frames_type(sof,raw,PRO_FLUX_LAMP_STACKED);   
+<a name="l00126"></a>00126 
+<a name="l00127"></a>00127    nraw    = cpl_frameset_get_size(*raw);
+<a name="l00128"></a>00128 
+<a name="l00129"></a>00129    <span class="keywordflow">if</span>(nraw<1) {
+<a name="l00130"></a>00130      <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no good raw frame %s in input!"</span>,PRO_FLUX_LAMP_STACKED);
+<a name="l00131"></a>00131      (*status)++;
+<a name="l00132"></a>00132      <span class="keywordflow">return</span>;
+<a name="l00133"></a>00133    }
+<a name="l00134"></a>00134    frame = cpl_frameset_get_frame(*raw,0);
+<a name="l00135"></a>00135    strcpy(cfg -> inFrame,cpl_strdup(cpl_frame_get_filename(frame)));
+<a name="l00136"></a>00136 
+<a name="l00137"></a>00137    <span class="comment">/* Output */</span>
+<a name="l00138"></a>00138    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.lamp_spec.output_filename"</span>);
+<a name="l00139"></a>00139    strcpy(cfg -> outName, cpl_parameter_get_string(p));
+<a name="l00140"></a>00140 
+<a name="l00141"></a>00141    sinfo_get_spatial_res(frame,spat_res);
+<a name="l00142"></a>00142    <span class="keywordflow">switch</span>(sinfo_frame_is_on(frame))
+<a name="l00143"></a>00143      {
+<a name="l00144"></a>00144 
+<a name="l00145"></a>00145     <span class="keywordflow">case</span> 0: 
+<a name="l00146"></a>00146       strcpy(lamp_status,<span class="stringliteral">"on"</span>);
+<a name="l00147"></a>00147       <span class="keywordflow">break</span>;
+<a name="l00148"></a>00148     <span class="keywordflow">case</span> 1: 
+<a name="l00149"></a>00149       strcpy(lamp_status,<span class="stringliteral">"off"</span>);
+<a name="l00150"></a>00150       <span class="keywordflow">break</span>;
+<a name="l00151"></a>00151     <span class="keywordflow">case</span> -1:
+<a name="l00152"></a>00152       strcpy(lamp_status,<span class="stringliteral">"undefined"</span>);
+<a name="l00153"></a>00153       <span class="keywordflow">break</span>;
+<a name="l00154"></a>00154     <span class="keywordflow">default</span>: 
+<a name="l00155"></a>00155       strcpy(lamp_status,<span class="stringliteral">"undefined"</span>);
+<a name="l00156"></a>00156       <span class="keywordflow">break</span>;
+<a name="l00157"></a>00157 
+<a name="l00158"></a>00158      }
+<a name="l00159"></a>00159    sinfo_get_band(frame,band);
+<a name="l00160"></a>00160    sinfo_msg(<span class="stringliteral">"Spatial resolution: %s lamp_status: %s band: %s \n"</span>,
+<a name="l00161"></a>00161                      spat_res,    lamp_status,    band);
+<a name="l00162"></a>00162 
+<a name="l00163"></a>00163    
+<a name="l00164"></a>00164    sinfo_get_ins_set(band,&ins_set);
+<a name="l00165"></a>00165 
+<a name="l00166"></a>00166    <span class="keywordflow">if</span>(NULL != cpl_frameset_find(sof,PRO_WAVE_MAP)) {
+<a name="l00167"></a>00167       frame = cpl_frameset_find(sof,PRO_WAVE_MAP);
+<a name="l00168"></a>00168       strcpy(cfg -> wavemapim,cpl_strdup(cpl_frame_get_filename(frame)));
+<a name="l00169"></a>00169    } <span class="keywordflow">else</span> {
+<a name="l00170"></a>00170      <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Frame %s not found! Exit!"</span>, PRO_WAVE_MAP);
+<a name="l00171"></a>00171      (*status)++;
+<a name="l00172"></a>00172      <span class="keywordflow">return</span>;
+<a name="l00173"></a>00173    }
+<a name="l00174"></a>00174 
+<a name="l00175"></a>00175 
+<a name="l00176"></a>00176    return ;
+<a name="l00177"></a>00177 
+<a name="l00178"></a>00178 }
+<a name="l00179"></a>00179 
+<a name="l00180"></a>00180 
+<a name="l00181"></a>00181 
+<a name="l00189"></a>00189 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00190"></a>00190 parse_section_resampling(lamp_config * cfg, cpl_parameterlist * cpl_cfg)
+<a name="l00191"></a>00191 {
+<a name="l00192"></a>00192 
+<a name="l00193"></a>00193    cpl_parameter *p; 
+<a name="l00194"></a>00194    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.lamp_spec.ncoeffs"</span>);
+<a name="l00195"></a>00195    cfg -> ncoeffs =  cpl_parameter_get_int(p);
+<a name="l00196"></a>00196 
+<a name="l00197"></a>00197    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.lamp_spec.nrows"</span>);
+<a name="l00198"></a>00198    cfg -> nrows =  cpl_parameter_get_int(p);
+<a name="l00199"></a>00199 
+<a name="l00200"></a>00200    return ;
+<a name="l00201"></a>00201 
+<a name="l00202"></a>00202 }
+<a name="l00210"></a>00210 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00211"></a>00211 parse_section_extractspectrum(lamp_config * cfg, cpl_parameterlist * cpl_cfg)
+<a name="l00212"></a>00212 {
+<a name="l00213"></a>00213    cpl_parameter *p; 
+<a name="l00214"></a>00214   
+<a name="l00215"></a>00215    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.lamp_spec.lower_rejection"</span>);
+<a name="l00216"></a>00216    cfg -> loReject = cpl_parameter_get_double(p);
+<a name="l00217"></a>00217 
+<a name="l00218"></a>00218    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.lamp_spec.higher_rejection"</span>);
+<a name="l00219"></a>00219    cfg -> hiReject = cpl_parameter_get_double(p);
+<a name="l00220"></a>00220 
+<a name="l00221"></a>00221    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.lamp_spec.counts_to_intensity"</span>);
+<a name="l00222"></a>00222    cfg -> countsToIntensity = cpl_parameter_get_double(p);
+<a name="l00223"></a>00223 
+<a name="l00224"></a>00224    return ;
+<a name="l00225"></a>00225 
+<a name="l00226"></a>00226 }
+<a name="l00233"></a>00233 <span class="keywordtype">void</span>
+<a name="l00234"></a>00234 sinfo_lamp_free(lamp_config * cfg)
+<a name="l00235"></a>00235 {  
+<a name="l00236"></a>00236   sinfo_lamp_cfg_destroy(cfg);
+<a name="l00237"></a>00237   <span class="keywordflow">return</span>;
+<a name="l00238"></a>00238 
+<a name="l00239"></a>00239 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__lamp__ini__by__cpl_8h_source.html b/html/sinfo__lamp__ini__by__cpl_8h_source.html
new file mode 100644
index 0000000..e849a21
--- /dev/null
+++ b/html/sinfo__lamp__ini__by__cpl_8h_source.html
@@ -0,0 +1,61 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_lamp_ini_by_cpl.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_lamp_ini_by_cpl.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   File name    :   sinfo_lamp_ini_by_cpl.h</span>
+<a name="l00021"></a>00021 <span class="comment">   Author       :   Andrea Modigliani</span>
+<a name="l00022"></a>00022 <span class="comment">   Created on   :   May 26, 2004</span>
+<a name="l00023"></a>00023 <span class="comment">   Description  :   lamp cpl input handling for SPIFFI</span>
+<a name="l00024"></a>00024 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00025"></a>00025 <span class="preprocessor">#ifndef SINFO_LAMP_INI_BY_CPL_H</span>
+<a name="l00026"></a>00026 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_LAMP_INI_BY_CPL_H</span>
+<a name="l00027"></a>00027 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00028"></a>00028 <span class="comment">                                Includes</span>
+<a name="l00029"></a>00029 <span class="comment">---------------------------------------------------------------------------*/</span>
+<a name="l00030"></a>00030 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00031"></a>00031 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00032"></a>00032 <span class="preprocessor">#include "sinfo_lamp_cfg.h"</span>
+<a name="l00033"></a>00033 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00034"></a>00034 <span class="comment">                             Function prototypes </span>
+<a name="l00035"></a>00035 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00046"></a>00046 lamp_config * 
+<a name="l00047"></a>00047 sinfo_parse_cpl_input_lamp(cpl_parameterlist* cpl_cfg, 
+<a name="l00048"></a>00048                            cpl_frameset* sof, 
+<a name="l00049"></a>00049                            cpl_frameset** raw) ;
+<a name="l00050"></a>00050 
+<a name="l00057"></a>00057 <span class="keywordtype">void</span> 
+<a name="l00058"></a>00058 sinfo_lamp_free(lamp_config * cfg);
+<a name="l00059"></a>00059 
+<a name="l00060"></a>00060 
+<a name="l00061"></a>00061 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__lamp__spec__config_8c_source.html b/html/sinfo__lamp__spec__config_8c_source.html
new file mode 100644
index 0000000..7dc4c5d
--- /dev/null
+++ b/html/sinfo__lamp__spec__config_8c_source.html
@@ -0,0 +1,134 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_lamp_spec_config.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_lamp_spec_config.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_lamp_spec_config.c,v 1.5 2012/03/02 08:42:20 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the CPL (Common Pipeline Library)</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
+<a name="l00007"></a>00007 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span>
+<a name="l00008"></a>00008 <span class="comment"> * License as published by the Free Software Foundation; either</span>
+<a name="l00009"></a>00009 <span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
+<a name="l00014"></a>00014 <span class="comment"> * Lesser General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
+<a name="l00017"></a>00017 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2012/03/02 08:42:20 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.5 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> */</span>
+<a name="l00026"></a>00026 
+<a name="l00027"></a>00027  <span class="comment">/****************************************************************</span>
+<a name="l00028"></a>00028 <span class="comment">  *   Lamp_Spec Frames Data Reduction Parameter Initialization        *</span>
+<a name="l00029"></a>00029 <span class="comment">  ****************************************************************/</span>
+<a name="l00030"></a>00030 
+<a name="l00031"></a>00031 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00032"></a>00032 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00033"></a>00033 <span class="preprocessor">#endif</span>
+<a name="l00034"></a>00034 <span class="preprocessor"></span><span class="preprocessor">#include "sinfo_lamp_spec_config.h"</span>
+<a name="l00035"></a>00035 <span class="preprocessor">#include "sinfo_globals.h"</span>
+<a name="l00036"></a>00036   
+<a name="l00044"></a>00044 <span class="keywordtype">void</span>
+<a name="l00045"></a>00045  sinfo_lamp_spec_config_add(cpl_parameterlist *list)
+<a name="l00046"></a>00046 {
+<a name="l00047"></a>00047 
+<a name="l00048"></a>00048   cpl_parameter *p;
+<a name="l00049"></a>00049 
+<a name="l00050"></a>00050   <span class="keywordflow">if</span> (!list) {
+<a name="l00051"></a>00051     <span class="keywordflow">return</span>;
+<a name="l00052"></a>00052   }
+<a name="l00053"></a>00053 
+<a name="l00054"></a>00054   <span class="comment">/* Input file name */</span>
+<a name="l00055"></a>00055   <span class="comment">/* Output file name */</span>
+<a name="l00056"></a>00056 <span class="comment">/* output name of resulting fits wavelength map */</span>
+<a name="l00057"></a>00057   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.lamp_spec.output_filename"</span>,
+<a name="l00058"></a>00058                   CPL_TYPE_STRING,
+<a name="l00059"></a>00059                               <span class="stringliteral">"Output File Name: "</span>,
+<a name="l00060"></a>00060                               <span class="stringliteral">"sinfoni.lamp_spec"</span>,
+<a name="l00061"></a>00061                               <span class="stringliteral">"out_flatspec.fits"</span>);
+<a name="l00062"></a>00062 
+<a name="l00063"></a>00063 
+<a name="l00064"></a>00064   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"out-lampspec_filename"</span>);
+<a name="l00065"></a>00065   cpl_parameterlist_append(list, p);
+<a name="l00066"></a>00066 
+<a name="l00067"></a>00067 
+<a name="l00068"></a>00068   <span class="comment">/* number of coefficients for the polynomial interpolation */</span>
+<a name="l00069"></a>00069  p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.lamp_spec.ncoeffs"</span>,
+<a name="l00070"></a>00070                   CPL_TYPE_INT,
+<a name="l00071"></a>00071                               <span class="stringliteral">"No of polynomial coeffs"</span>,
+<a name="l00072"></a>00072                               <span class="stringliteral">"sinfoni.lamp_spec"</span>,
+<a name="l00073"></a>00073                               3);
+<a name="l00074"></a>00074 
+<a name="l00075"></a>00075   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"lamp_spec-ncoeffs"</span>);
+<a name="l00076"></a>00076   cpl_parameterlist_append(list, p);
+<a name="l00077"></a>00077 
+<a name="l00078"></a>00078   <span class="comment">/* number of image rows in the resampled frame </span>
+<a name="l00079"></a>00079 <span class="comment">    (1280 for single frames, 2560 for interleaved frames) */</span>
+<a name="l00080"></a>00080  p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.lamp_spec.nrows"</span>,
+<a name="l00081"></a>00081                   CPL_TYPE_INT,
+<a name="l00082"></a>00082                               <span class="stringliteral">"No of image rows in resampled frame"</span>,
+<a name="l00083"></a>00083                               <span class="stringliteral">"sinfoni.lamp_spec"</span>,
+<a name="l00084"></a>00084                               SINFO_RESAMP_NROWS);
+<a name="l00085"></a>00085 
+<a name="l00086"></a>00086   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"lamp_spec-nrows"</span>);
+<a name="l00087"></a>00087   cpl_parameterlist_append(list, p);
+<a name="l00088"></a>00088 
+<a name="l00089"></a>00089 
+<a name="l00090"></a>00090 
+<a name="l00091"></a>00091   <span class="comment">/*Reconstruction */</span>
+<a name="l00092"></a>00092  <span class="comment">/* the fraction [0...1] of rejected low intensity pixels when taking </span>
+<a name="l00093"></a>00093 <span class="comment">the average of columns */</span>
+<a name="l00094"></a>00094   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.lamp_spec.lower_rejection"</span>,
+<a name="l00095"></a>00095                   CPL_TYPE_DOUBLE,
+<a name="l00096"></a>00096                               <span class="stringliteral">"lower rejection"</span>,
+<a name="l00097"></a>00097                               <span class="stringliteral">"sinfoni.lamp_spec"</span>,
+<a name="l00098"></a>00098                               0.1,0.0,1.0);
+<a name="l00099"></a>00099 
+<a name="l00100"></a>00100   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"lamp_spec-low_rejection"</span>);
+<a name="l00101"></a>00101   cpl_parameterlist_append(list, p);
+<a name="l00102"></a>00102 
+<a name="l00103"></a>00103  <span class="comment">/* the fraction [0...1] of rejected high intensity pixels when taking </span>
+<a name="l00104"></a>00104 <span class="comment">the average of columns */</span>
+<a name="l00105"></a>00105   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.lamp_spec.higher_rejection"</span>,
+<a name="l00106"></a>00106                   CPL_TYPE_DOUBLE,
+<a name="l00107"></a>00107                               <span class="stringliteral">"high rejection"</span>,
+<a name="l00108"></a>00108                               <span class="stringliteral">"sinfoni.lamp_spec"</span>,
+<a name="l00109"></a>00109                               0.1,0.0,1.0);
+<a name="l00110"></a>00110 
+<a name="l00111"></a>00111   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"lamp_spec-high_rejection"</span>);
+<a name="l00112"></a>00112   cpl_parameterlist_append(list, p);
+<a name="l00113"></a>00113 
+<a name="l00114"></a>00114 
+<a name="l00115"></a>00115   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.lamp_spec.counts_to_intensity"</span>,
+<a name="l00116"></a>00116                   CPL_TYPE_DOUBLE,
+<a name="l00117"></a>00117                               <span class="stringliteral">"Counts To Intensity"</span>,
+<a name="l00118"></a>00118                               <span class="stringliteral">"sinfoni.lamp_spec"</span>,
+<a name="l00119"></a>00119                               1.);
+<a name="l00120"></a>00120 
+<a name="l00121"></a>00121   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"lamp_spec-cnt2int"</span>);
+<a name="l00122"></a>00122   cpl_parameterlist_append(list, p);
+<a name="l00123"></a>00123 
+<a name="l00124"></a>00124 
+<a name="l00125"></a>00125 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__lamp__spec__config_8h_source.html b/html/sinfo__lamp__spec__config_8h_source.html
new file mode 100644
index 0000000..0b3d370
--- /dev/null
+++ b/html/sinfo__lamp__spec__config_8h_source.html
@@ -0,0 +1,51 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_lamp_spec_config.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_lamp_spec_config.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_lamp_spec_config.h,v 1.1 2006/10/20 08:06:32 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the CPL (Common Pipeline Library)</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
+<a name="l00007"></a>00007 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span>
+<a name="l00008"></a>00008 <span class="comment"> * License as published by the Free Software Foundation; either</span>
+<a name="l00009"></a>00009 <span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
+<a name="l00014"></a>00014 <span class="comment"> * Lesser General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
+<a name="l00017"></a>00017 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2006/10/20 08:06:32 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.1 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> */</span>
+<a name="l00026"></a>00026 
+<a name="l00027"></a>00027  <span class="comment">/****************************************************************</span>
+<a name="l00028"></a>00028 <span class="comment">  *   Lamp_Spec Frames Data Reduction Parameter Initialization        *</span>
+<a name="l00029"></a>00029 <span class="comment">  ****************************************************************/</span>
+<a name="l00030"></a>00030 <span class="preprocessor">#include "cpl.h"</span>    <span class="comment">/* defines parlist structure */</span>
+<a name="l00031"></a>00031 
+<a name="l00032"></a>00032 
+<a name="l00033"></a>00033 
+<a name="l00034"></a>00034 <span class="keywordtype">void</span>
+<a name="l00035"></a>00035 sinfo_lamp_spec_config_add(cpl_parameterlist *list);
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__local__types_8h_source.html b/html/sinfo__local__types_8h_source.html
new file mode 100644
index 0000000..60d1dea
--- /dev/null
+++ b/html/sinfo__local__types_8h_source.html
@@ -0,0 +1,147 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_local_types.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_local_types.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name     :    sinfo_local_types.h</span>
+<a name="l00022"></a>00022 <span class="comment">   Author         :    Nicolas Devillard</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on    :    Nov 27, 1995</span>
+<a name="l00024"></a>00024 <span class="comment">   Description    :    all shared local types for eclipse</span>
+<a name="l00025"></a>00025 <span class="comment"></span>
+<a name="l00026"></a>00026 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00027"></a>00027 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00028"></a>00028 <span class="comment">    PUBLIC NOTICE AS REQUIRED BY LAW: Any use of this product, in any</span>
+<a name="l00029"></a>00029 <span class="comment">    manner whatsoever, will increase the amount of disorder in the</span>
+<a name="l00030"></a>00030 <span class="comment">    universe. Although no liability is implied herein, the consumer is</span>
+<a name="l00031"></a>00031 <span class="comment">    warned that this process will ultimately lead to the heat death of the</span>
+<a name="l00032"></a>00032 <span class="comment">    universe.</span>
+<a name="l00033"></a>00033 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00034"></a>00034 <span class="comment">/*</span>
+<a name="l00035"></a>00035 <span class="comment">    $Id: sinfo_local_types.h,v 1.4 2007/06/06 07:10:45 amodigli Exp $</span>
+<a name="l00036"></a>00036 <span class="comment">    $Author: amodigli $</span>
+<a name="l00037"></a>00037 <span class="comment">    $Date: 2007/06/06 07:10:45 $</span>
+<a name="l00038"></a>00038 <span class="comment">    $Revision: 1.4 $</span>
+<a name="l00039"></a>00039 <span class="comment"> */</span>
+<a name="l00040"></a>00040 
+<a name="l00041"></a>00041 <span class="preprocessor">#ifndef SINFO_LOCAL_TYPES_H</span>
+<a name="l00042"></a>00042 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_LOCAL_TYPES_H</span>
+<a name="l00043"></a>00043 <span class="preprocessor"></span><span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00044"></a>00044 <span class="comment">                                   Includes</span>
+<a name="l00045"></a>00045 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00046"></a>00046 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00047"></a>00047 <span class="comment">                                   Defines</span>
+<a name="l00048"></a>00048 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00049"></a>00049 
+<a name="l00050"></a>00050 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00051"></a>00051 <span class="comment">                                   New types</span>
+<a name="l00052"></a>00052 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00053"></a>00053 <span class="comment">/*</span>
+<a name="l00054"></a>00054 <span class="comment"> * These types are defined for portability issues</span>
+<a name="l00055"></a>00055 <span class="comment"> * On DEC-Alpha stations, long is 64 bits, but int is 32</span>
+<a name="l00056"></a>00056 <span class="comment"> * We have to redefine all int values accordingly to ensure</span>
+<a name="l00057"></a>00057 <span class="comment"> * portability!</span>
+<a name="l00058"></a>00058 <span class="comment"> */</span>
+<a name="l00059"></a>00059 
+<a name="l00060"></a>00060 <span class="preprocessor">#ifdef _DEC_ALPHA</span>
+<a name="l00061"></a>00061 <span class="preprocessor"></span><span class="keyword">typedef</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> ulong32 ;
+<a name="l00062"></a>00062 <span class="keyword">typedef</span> <span class="keywordtype">int</span> long32 ;
+<a name="l00063"></a>00063 <span class="preprocessor">#else</span>
+<a name="l00064"></a>00064 <span class="preprocessor"></span><span class="keyword">typedef</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> ulong32 ;
+<a name="l00065"></a>00065 <span class="keyword">typedef</span> <span class="keywordtype">long</span> long32 ;
+<a name="l00066"></a>00066 <span class="preprocessor">#endif</span>
+<a name="l00067"></a>00067 <span class="preprocessor"></span>
+<a name="l00068"></a>00068 <span class="keyword">typedef</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> ushort16 ;
+<a name="l00069"></a>00069 <span class="keyword">typedef</span> <span class="keywordtype">short</span> short16 ;
+<a name="l00070"></a>00070 
+<a name="l00071"></a>00071 <span class="keyword">typedef</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> uchar8 ;
+<a name="l00072"></a>00072 <span class="keyword">typedef</span> <span class="keywordtype">char</span> char8 ;
+<a name="l00073"></a>00073  
+<a name="l00074"></a>00074 <span class="keyword">typedef</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> BYTE ;
+<a name="l00075"></a>00075 
+<a name="l00076"></a>00076 <span class="comment">/* defined in limits.h, redefined here for portability  */</span>
+<a name="l00077"></a>00077 
+<a name="l00078"></a>00078 <span class="preprocessor">#define LONG32_MIN  (long32)(-2147483647-1) </span>
+<a name="l00079"></a>00079 <span class="preprocessor"></span><span class="preprocessor">#define LONG32_MAX  (long32)(2147483647)</span>
+<a name="l00080"></a>00080 <span class="preprocessor"></span><span class="preprocessor">#define ULONG32_MAX (ulong32)(4294967295)</span>
+<a name="l00081"></a>00081 <span class="preprocessor"></span>
+<a name="l00082"></a>00082 <span class="preprocessor">#define SHRT16_MIN  (short16)(-32768)</span>
+<a name="l00083"></a>00083 <span class="preprocessor"></span><span class="preprocessor">#define SHRT16_MAX  (short16)(32767)</span>
+<a name="l00084"></a>00084 <span class="preprocessor"></span><span class="preprocessor">#define USHRT16_MAX (ushort16)(65535)</span>
+<a name="l00085"></a>00085 <span class="preprocessor"></span>
+<a name="l00086"></a>00086 <span class="keyword">typedef</span> <span class="keyword">struct </span>_DOUBLE_COMPLEX_ {
+<a name="l00087"></a>00087     <span class="keywordtype">double</span> x, y ;
+<a name="l00088"></a>00088 } dcomplex ;
+<a name="l00089"></a>00089 
+<a name="l00090"></a>00090 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00091"></a>00091 <span class="comment">/* pixelvalue is the internal Pixel representation  */</span>
+<a name="l00092"></a>00092 
+<a name="l00093"></a>00093 <span class="preprocessor">#ifdef DOUBLEPIX</span>
+<a name="l00094"></a>00094 <span class="preprocessor"></span><span class="keyword">typedef</span> <span class="keywordtype">double</span>    pixelvalue ;
+<a name="l00095"></a>00095 <span class="preprocessor">#else</span>
+<a name="l00096"></a>00096 <span class="preprocessor"></span><span class="keyword">typedef</span> <span class="keywordtype">float</span>    pixelvalue ;
+<a name="l00097"></a>00097 <span class="preprocessor">#endif</span>
+<a name="l00098"></a>00098 <span class="preprocessor"></span>
+<a name="l00099"></a>00099 
+<a name="l00100"></a>00100 
+<a name="l00101"></a>00101 <span class="comment">/*</span>
+<a name="l00102"></a>00102 <span class="comment"> * dpoint: useful to store point coordinates in double precision</span>
+<a name="l00103"></a>00103 <span class="comment"> */</span>
+<a name="l00104"></a>00104 
+<a name="l00105"></a>00105 <span class="keyword">typedef</span> <span class="keyword">struct </span>_DPOINT_ {
+<a name="l00106"></a>00106     <span class="keywordtype">double</span> x ;
+<a name="l00107"></a>00107     <span class="keywordtype">double</span> y ;
+<a name="l00108"></a>00108 } dpoint ;
+<a name="l00109"></a>00109 
+<a name="l00110"></a>00110 
+<a name="l00111"></a>00111 
+<a name="l00112"></a>00112 
+<a name="l00113"></a>00113 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00114"></a>00114 <span class="comment">/* Pixel map */</span>
+<a name="l00115"></a>00115 
+<a name="l00116"></a>00116 
+<a name="l00117"></a>00117 <span class="keyword">typedef</span> uchar8 binpix ;
+<a name="l00118"></a>00118 
+<a name="l00119"></a>00119 <span class="keyword">typedef</span> <span class="keyword">struct </span>_PIXEL_MAP_
+<a name="l00120"></a>00120 {
+<a name="l00121"></a>00121     <span class="keywordtype">int</span>            lx, ly ;
+<a name="l00122"></a>00122     <span class="keywordtype">int</span>            nbpix ;
+<a name="l00123"></a>00123     <span class="keywordtype">int</span>            ngoodpix ;
+<a name="l00124"></a>00124     binpix    *    data ;
+<a name="l00125"></a>00125 } pixel_map ;
+<a name="l00126"></a>00126 
+<a name="l00127"></a>00127 
+<a name="l00128"></a>00128 <span class="preprocessor">#define NullMap (pixel_map*)NULL</span>
+<a name="l00129"></a>00129 <span class="preprocessor"></span>
+<a name="l00130"></a>00130 
+<a name="l00131"></a>00131 <span class="preprocessor">#endif </span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__matrix_8c_source.html b/html/sinfo__matrix_8c_source.html
new file mode 100644
index 0000000..d894394
--- /dev/null
+++ b/html/sinfo__matrix_8c_source.html
@@ -0,0 +1,329 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_matrix.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_matrix.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name     :    sinfo_matrix.c</span>
+<a name="l00022"></a>00022 <span class="comment">   Author         :    Nicolas Devillard</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on    :    1994</span>
+<a name="l00024"></a>00024 <span class="comment">   Description    :    basic 2d sinfo_eclipse_matrix handling routines</span>
+<a name="l00025"></a>00025 <span class="comment"></span>
+<a name="l00026"></a>00026 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00027"></a>00027 <span class="comment">/*</span>
+<a name="l00028"></a>00028 <span class="comment"> $Id: sinfo_matrix.c,v 1.4 2012/03/02 08:42:20 amodigli Exp $</span>
+<a name="l00029"></a>00029 <span class="comment"> $Author: amodigli $</span>
+<a name="l00030"></a>00030 <span class="comment"> $Date: 2012/03/02 08:42:20 $</span>
+<a name="l00031"></a>00031 <span class="comment"> $Revision: 1.4 $</span>
+<a name="l00032"></a>00032 <span class="comment"> */</span>
+<a name="l00033"></a>00033 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00034"></a>00034 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00035"></a>00035 <span class="preprocessor">#endif</span>
+<a name="l00036"></a>00036 <span class="preprocessor"></span><span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00037"></a>00037 <span class="comment">                                   Includes</span>
+<a name="l00038"></a>00038 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00039"></a>00039 <span class="preprocessor">#include "sinfo_matrix.h"</span>
+<a name="l00048"></a>00048 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00049"></a>00049 <span class="comment">                                   Macros</span>
+<a name="l00050"></a>00050 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00051"></a>00051 <span class="preprocessor">#define dtiny(a) ((a)<0?(a)> -1.e-30:(a)<1.e-30)</span>
+<a name="l00052"></a>00052 <span class="preprocessor"></span><span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00053"></a>00053 <span class="comment">                        Private function prototypes</span>
+<a name="l00054"></a>00054 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00055"></a>00055 <span class="keyword">static</span> <span class="keywordtype">int</span> gauss_pivot(<span class="keywordtype">double</span> *ptra, <span class="keywordtype">double</span> *ptrc, <span class="keywordtype">int</span> n);
+<a name="l00056"></a>00056 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00057"></a>00057 <span class="comment">                              Function codes</span>
+<a name="l00058"></a>00058 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00059"></a>00059 
+<a name="l00071"></a>00071 Matrix
+<a name="l00072"></a>00072 sinfo_create_mx(<span class="keywordtype">int</span> nr, <span class="keywordtype">int</span> nc)
+<a name="l00073"></a>00073 {
+<a name="l00074"></a>00074     Matrix b;
+<a name="l00075"></a>00075     b = (Matrix)cpl_calloc(1,<span class="keyword">sizeof</span>(sinfo_eclipse_matrix));
+<a name="l00076"></a>00076     b->m = (<span class="keywordtype">double</span>*)cpl_calloc(nr*nc,<span class="keyword">sizeof</span>(<span class="keywordtype">double</span>));
+<a name="l00077"></a>00077     b->nr= nr;
+<a name="l00078"></a>00078     b->nc= nc;
+<a name="l00079"></a>00079     <span class="keywordflow">return</span> b;
+<a name="l00080"></a>00080 }
+<a name="l00081"></a>00081 
+<a name="l00091"></a>00091 Matrix
+<a name="l00092"></a>00092 sinfo_copy_mx(Matrix a)
+<a name="l00093"></a>00093 {
+<a name="l00094"></a>00094     Matrix b = sinfo_create_mx(a->nr,a->nc);
+<a name="l00095"></a>00095     <span class="keywordflow">if</span> (b!=NULL) {
+<a name="l00096"></a>00096         <span class="keyword">register</span> <span class="keywordtype">int</span> s = a->nr*a->nc;
+<a name="l00097"></a>00097         <span class="keyword">register</span> <span class="keywordtype">double</span> *mm = b->m+s;
+<a name="l00098"></a>00098         <span class="keyword">register</span> <span class="keywordtype">double</span> *am = a->m+s;
+<a name="l00099"></a>00099         <span class="keywordflow">while</span> (s--) *--mm = *--am;
+<a name="l00100"></a>00100     }
+<a name="l00101"></a>00101     <span class="keywordflow">return</span> b;
+<a name="l00102"></a>00102 }
+<a name="l00103"></a>00103 
+<a name="l00113"></a>00113 <span class="keywordtype">void</span>
+<a name="l00114"></a>00114 sinfo_close_mx(Matrix a)
+<a name="l00115"></a>00115 {
+<a name="l00116"></a>00116     <span class="keywordflow">if</span> (a==NULL) return ;
+<a name="l00117"></a>00117     <span class="keywordflow">if</span> (a->m != NULL)
+<a name="l00118"></a>00118         cpl_free(a->m);
+<a name="l00119"></a>00119     cpl_free(a);
+<a name="l00120"></a>00120     <span class="keywordflow">return</span>;
+<a name="l00121"></a>00121 }
+<a name="l00122"></a>00122 
+<a name="l00133"></a>00133 Matrix
+<a name="l00134"></a>00134 sinfo_mul_mx(Matrix a, Matrix b)
+<a name="l00135"></a>00135 {
+<a name="l00136"></a>00136     Matrix c, d;
+<a name="l00137"></a>00137     <span class="keywordtype">int</span> n1=a->nr, n2=a->nc, n3=b->nc;
+<a name="l00138"></a>00138     <span class="keyword">register</span> <span class="keywordtype">double</span> *a0;
+<a name="l00139"></a>00139     <span class="keyword">register</span> <span class="keywordtype">double</span> *c0;
+<a name="l00140"></a>00140     <span class="keyword">register</span> <span class="keywordtype">double</span> *d0;
+<a name="l00141"></a>00141     <span class="keyword">register</span> <span class="keywordtype">int</span> i,j,k;
+<a name="l00142"></a>00142 
+<a name="l00143"></a>00143     <span class="keywordflow">if</span>(n2!=b->nr) <span class="keywordflow">return</span> NULL;
+<a name="l00144"></a>00144     c = sinfo_create_mx(n1,n3);
+<a name="l00145"></a>00145     d = sinfo_transp_mx(b);
+<a name="l00146"></a>00146 
+<a name="l00147"></a>00147     <span class="keywordflow">for</span> (i=0,c0=c->m;i<n1;i++)
+<a name="l00148"></a>00148         <span class="keywordflow">for</span> (j=0,d0=d->m;j<n3;j++,c0++)
+<a name="l00149"></a>00149             <span class="keywordflow">for</span> (k=0,*c0=0,a0=a->m+i*n2;k<n2;k++)
+<a name="l00150"></a>00150                 *c0 += *a0++ * *d0++;
+<a name="l00151"></a>00151     sinfo_close_mx(d);
+<a name="l00152"></a>00152     <span class="keywordflow">return</span> c;
+<a name="l00153"></a>00153 }
+<a name="l00154"></a>00154 
+<a name="l00166"></a>00166 Matrix
+<a name="l00167"></a>00167 sinfo_invert_mx(Matrix aa)
+<a name="l00168"></a>00168 {
+<a name="l00169"></a>00169     Matrix bb;
+<a name="l00170"></a>00170     <span class="keywordtype">int</span> test=1;
+<a name="l00171"></a>00171 
+<a name="l00172"></a>00172     <span class="keywordflow">if</span>(aa->nr!=aa->nc) <span class="keywordflow">return</span> NULL;
+<a name="l00173"></a>00173     bb = sinfo_create_mx(aa->nr,aa->nc);
+<a name="l00174"></a>00174 
+<a name="l00175"></a>00175     <span class="keywordflow">if</span>(aa->nr==1)
+<a name="l00176"></a>00176     {
+<a name="l00177"></a>00177         <span class="keywordtype">double</span> det;
+<a name="l00178"></a>00178         <span class="keyword">register</span> <span class="keywordtype">double</span> ted;
+<a name="l00179"></a>00179         det= *(aa->m);
+<a name="l00180"></a>00180         <span class="keywordflow">if</span>(dtiny(det)) test=0;
+<a name="l00181"></a>00181         ted=1./det;
+<a name="l00182"></a>00182         *(bb->m)=ted;
+<a name="l00183"></a>00183     }
+<a name="l00184"></a>00184     <span class="keywordflow">else</span> <span class="keywordflow">if</span>(aa->nr==2)
+<a name="l00185"></a>00185     {
+<a name="l00186"></a>00186         <span class="keywordtype">double</span> det;
+<a name="l00187"></a>00187         <span class="keyword">register</span> <span class="keywordtype">double</span> ted;
+<a name="l00188"></a>00188         <span class="keyword">register</span> <span class="keywordtype">double</span> *mm=aa->m;
+<a name="l00189"></a>00189         <span class="keywordtype">double</span> a= *(mm++),b= *(mm++);
+<a name="l00190"></a>00190         <span class="keywordtype">double</span> c= *(mm++),d= *(mm);
+<a name="l00191"></a>00191         det=a*d-b*c;
+<a name="l00192"></a>00192         <span class="keywordflow">if</span>(dtiny(det)) test=0;
+<a name="l00193"></a>00193         ted=1./det;
+<a name="l00194"></a>00194         mm=bb->m;
+<a name="l00195"></a>00195         *(mm++)= d*ted,*(mm++)= -b*ted;
+<a name="l00196"></a>00196         *(mm++)= -c*ted,*(mm)= a*ted;
+<a name="l00197"></a>00197     }
+<a name="l00198"></a>00198     <span class="keywordflow">else</span> <span class="keywordflow">if</span>(aa->nr==3)
+<a name="l00199"></a>00199     {
+<a name="l00200"></a>00200         <span class="keywordtype">double</span> det;
+<a name="l00201"></a>00201         <span class="keyword">register</span> <span class="keywordtype">double</span> ted;
+<a name="l00202"></a>00202         <span class="keyword">register</span> <span class="keywordtype">double</span> *mm=aa->m;
+<a name="l00203"></a>00203         <span class="keywordtype">double</span> a= *(mm++),b= *(mm++),c= *(mm++);
+<a name="l00204"></a>00204         <span class="keywordtype">double</span> d= *(mm++),e= *(mm++),f= *(mm++);
+<a name="l00205"></a>00205         <span class="keywordtype">double</span> g= *(mm++),h= *(mm++),i= *(mm);
+<a name="l00206"></a>00206         det=a*e*i-a*h*f-b*d*i+b*g*f+c*d*h-c*g*e;
+<a name="l00207"></a>00207         <span class="keywordflow">if</span>(dtiny(det)) test=0;
+<a name="l00208"></a>00208         ted=1./det;
+<a name="l00209"></a>00209         mm=bb->m;
+<a name="l00210"></a>00210         *(mm++)=(e*i-f*h)*ted,
+<a name="l00211"></a>00211                 *(mm++)=(c*h-b*i)*ted,
+<a name="l00212"></a>00212                 *(mm++)=(b*f-e*c)*ted;
+<a name="l00213"></a>00213 
+<a name="l00214"></a>00214         *(mm++)=(f*g-d*i)*ted,
+<a name="l00215"></a>00215                 *(mm++)=(a*i-g*c)*ted,
+<a name="l00216"></a>00216                 *(mm++)=(d*c-a*f)*ted;
+<a name="l00217"></a>00217 
+<a name="l00218"></a>00218         *(mm++)=(d*h-g*e)*ted,
+<a name="l00219"></a>00219                 *(mm++)=(g*b-a*h)*ted,
+<a name="l00220"></a>00220                 *(mm)=(a*e-d*b)*ted;
+<a name="l00221"></a>00221     }
+<a name="l00222"></a>00222     <span class="keywordflow">else</span>
+<a name="l00223"></a>00223     {
+<a name="l00224"></a>00224         Matrix temp=sinfo_copy_mx(aa);
+<a name="l00225"></a>00225         <span class="keywordflow">if</span>(gauss_pivot(temp->m,bb->m,aa->nr)==0) test=0;
+<a name="l00226"></a>00226         sinfo_close_mx(temp);
+<a name="l00227"></a>00227     }
+<a name="l00228"></a>00228     <span class="keywordflow">if</span>(test==0)
+<a name="l00229"></a>00229     {
+<a name="l00230"></a>00230         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"not invertible, aborting inversion"</span>);
+<a name="l00231"></a>00231         <span class="keywordflow">return</span> NULL;
+<a name="l00232"></a>00232     }
+<a name="l00233"></a>00233     <span class="keywordflow">return</span> bb;
+<a name="l00234"></a>00234 }
+<a name="l00235"></a>00235 
+<a name="l00245"></a>00245 Matrix
+<a name="l00246"></a>00246 sinfo_transp_mx(Matrix a)
+<a name="l00247"></a>00247 {
+<a name="l00248"></a>00248     <span class="keyword">register</span> <span class="keywordtype">int</span> nc=a->nc, nr=a->nr;
+<a name="l00249"></a>00249     <span class="keyword">register</span> <span class="keywordtype">double</span> *a0;
+<a name="l00250"></a>00250     <span class="keyword">register</span> <span class="keywordtype">double</span> *b0;
+<a name="l00251"></a>00251     <span class="keyword">register</span> <span class="keywordtype">int</span> i,j;
+<a name="l00252"></a>00252     Matrix b = sinfo_create_mx(nc,nr);
+<a name="l00253"></a>00253 
+<a name="l00254"></a>00254     <span class="keywordflow">if</span> (b == (Matrix)NULL) <span class="keywordflow">return</span> b ;
+<a name="l00255"></a>00255     <span class="keywordflow">for</span> (i=0,b0=b->m;i<nc;i++)
+<a name="l00256"></a>00256         <span class="keywordflow">for</span> (j=0,a0=a->m+i;j<nr;j++,a0+=nc,b0++)
+<a name="l00257"></a>00257             *b0 = *a0;
+<a name="l00258"></a>00258     <span class="keywordflow">return</span> b;
+<a name="l00259"></a>00259 }
+<a name="l00260"></a>00260 
+<a name="l00273"></a>00273 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00274"></a>00274 gauss_pivot(<span class="keywordtype">double</span> *ptra, <span class="keywordtype">double</span> *ptrc, <span class="keywordtype">int</span> n)
+<a name="l00275"></a>00275 <span class="comment">/* c(n,n) = a(n,n)^-1 */</span>
+<a name="l00276"></a>00276 {
+<a name="l00277"></a>00277 <span class="preprocessor">#define SINFO_ABS(a) (((a) > 0) ? (a) : -(a))</span>
+<a name="l00278"></a>00278 <span class="preprocessor"></span>
+<a name="l00279"></a>00279     <span class="keyword">register</span> <span class="keywordtype">int</span> i,j,k,l;
+<a name="l00280"></a>00280     <span class="keywordtype">int</span> maj;
+<a name="l00281"></a>00281     <span class="keywordtype">double</span> max,r,t;
+<a name="l00282"></a>00282     <span class="keywordtype">double</span> *ptrb;
+<a name="l00283"></a>00283 
+<a name="l00284"></a>00284     ptrb=(<span class="keywordtype">double</span> *)cpl_calloc(n*n,<span class="keyword">sizeof</span>(<span class="keywordtype">double</span>));
+<a name="l00285"></a>00285     <span class="keywordflow">for</span>(i=0;i<n;i++)
+<a name="l00286"></a>00286         ptrb[i*n+i]= 1.0;
+<a name="l00287"></a>00287 
+<a name="l00288"></a>00288     <span class="keywordflow">for</span> (i=1;i <= n;i++)
+<a name="l00289"></a>00289     {
+<a name="l00290"></a>00290         <span class="comment">/* Search max in current column  */</span>
+<a name="l00291"></a>00291         max = SINFO_ABS(*(ptra + n*i-n));
+<a name="l00292"></a>00292         maj = i;
+<a name="l00293"></a>00293         <span class="keywordflow">for</span> (j = i;j <= n;j++)
+<a name="l00294"></a>00294             <span class="keywordflow">if</span> (SINFO_ABS(*(ptra+n*j+i-n-1)) > max)
+<a name="l00295"></a>00295             {
+<a name="l00296"></a>00296                 maj = j;
+<a name="l00297"></a>00297                 max = SINFO_ABS(*(ptra+n*j+i-n-1));
+<a name="l00298"></a>00298             }
+<a name="l00299"></a>00299 
+<a name="l00300"></a>00300         <span class="comment">/* swap lines i and maj */</span>
+<a name="l00301"></a>00301         <span class="keywordflow">if</span> (maj != i)
+<a name="l00302"></a>00302         {
+<a name="l00303"></a>00303             <span class="keywordflow">for</span> (j = i;j <= n;j++)
+<a name="l00304"></a>00304             {
+<a name="l00305"></a>00305                 r = *(ptra+n*maj+j-n-1);
+<a name="l00306"></a>00306                 *(ptra+n*maj+j-n-1) = *(ptra+n*i+j-n-1);
+<a name="l00307"></a>00307                 *(ptra+n*i+j-n-1) = r;
+<a name="l00308"></a>00308             }
+<a name="l00309"></a>00309             <span class="keywordflow">for</span>(l=0;l<n;l++)
+<a name="l00310"></a>00310             {
+<a name="l00311"></a>00311                 r = *(ptrb+l*n+maj-1);
+<a name="l00312"></a>00312                 *(ptrb+l*n+maj-1) = *(ptrb+l*n+i-1);
+<a name="l00313"></a>00313                 *(ptrb+l*n+i-1) = r;
+<a name="l00314"></a>00314             }
+<a name="l00315"></a>00315         }
+<a name="l00316"></a>00316 
+<a name="l00317"></a>00317         <span class="comment">/* Subtract line by line */</span>
+<a name="l00318"></a>00318         <span class="keywordflow">for</span> (j = i + 1;j <= n;j++)
+<a name="l00319"></a>00319         {
+<a name="l00320"></a>00320             t = (*(ptra+(n+1)*i-n-1));
+<a name="l00321"></a>00321             <span class="keywordflow">if</span>(dtiny(t)) <span class="keywordflow">return</span>(0);
+<a name="l00322"></a>00322             r = (*(ptra+n*j+i-n-1)) / t;
+<a name="l00323"></a>00323             <span class="keywordflow">for</span>(l=0;l<n;l++)
+<a name="l00324"></a>00324                 *(ptrb+l*n+j-1) -= r * (*(ptrb+l*n+i-1));
+<a name="l00325"></a>00325             <span class="keywordflow">for</span> (k = i;k <= n;k++)
+<a name="l00326"></a>00326                 *(ptra+n*j+k-n-1) -= r * (*(ptra+n*i+k-n-1));
+<a name="l00327"></a>00327         }
+<a name="l00328"></a>00328     }
+<a name="l00329"></a>00329 
+<a name="l00330"></a>00330     <span class="comment">/* Triangular system resolution    */</span>
+<a name="l00331"></a>00331     <span class="keywordflow">for</span>(l=0;l<n;l++)
+<a name="l00332"></a>00332        <span class="keywordflow">for</span> (i = n;i >= 1;i--)
+<a name="l00333"></a>00333        {
+<a name="l00334"></a>00334         t = (*(ptra+(n+1)*i-n-1));
+<a name="l00335"></a>00335         <span class="keywordflow">if</span>(dtiny(t)) <span class="keywordflow">return</span>(0);
+<a name="l00336"></a>00336         *(ptrc+l+(i-1)*n) = (*(ptrb+l*n+i-1)) / t;
+<a name="l00337"></a>00337         <span class="keywordflow">if</span> (i > 1)
+<a name="l00338"></a>00338            <span class="keywordflow">for</span> (j = i - 1;j > 0;j--)
+<a name="l00339"></a>00339             *(ptrb+l*n+j-1) -= (*(ptra+n*j+i-n-1)) * 
+<a name="l00340"></a>00340                                            (*(ptrc+l+(i-1)*n));
+<a name="l00341"></a>00341         }
+<a name="l00342"></a>00342     cpl_free(ptrb);
+<a name="l00343"></a>00343     <span class="keywordflow">return</span>(1);
+<a name="l00344"></a>00344 }
+<a name="l00345"></a>00345 
+<a name="l00365"></a>00365 Matrix 
+<a name="l00366"></a>00366 sinfo_least_sq_mx(
+<a name="l00367"></a>00367     Matrix    A,
+<a name="l00368"></a>00368     Matrix    B
+<a name="l00369"></a>00369 )
+<a name="l00370"></a>00370 {
+<a name="l00371"></a>00371     Matrix    m1,
+<a name="l00372"></a>00372             m2,
+<a name="l00373"></a>00373             m3,
+<a name="l00374"></a>00374             m4,
+<a name="l00375"></a>00375             m5 ;
+<a name="l00376"></a>00376 
+<a name="l00377"></a>00377 
+<a name="l00378"></a>00378 
+<a name="l00379"></a>00379     m1 = sinfo_transp_mx(A) ;
+<a name="l00380"></a>00380     m2 = sinfo_mul_mx(A, m1) ;
+<a name="l00381"></a>00381     m3 = sinfo_invert_mx(m2) ;
+<a name="l00382"></a>00382     m4 = sinfo_mul_mx(B, m1) ;
+<a name="l00383"></a>00383     m5 = sinfo_mul_mx(m4, m3) ;
+<a name="l00384"></a>00384 
+<a name="l00385"></a>00385     sinfo_close_mx(m1) ;
+<a name="l00386"></a>00386     sinfo_close_mx(m2) ;
+<a name="l00387"></a>00387     sinfo_close_mx(m3) ;
+<a name="l00388"></a>00388     sinfo_close_mx(m4) ;
+<a name="l00389"></a>00389 
+<a name="l00390"></a>00390     <span class="keywordflow">return</span> m5 ;
+<a name="l00391"></a>00391 }
+<a name="l00392"></a>00392 
+<a name="l00405"></a>00405 <span class="keywordtype">void</span> 
+<a name="l00406"></a>00406 sinfo_print_mx(
+<a name="l00407"></a>00407     Matrix    M,
+<a name="l00408"></a>00408     <span class="keyword">const</span> <span class="keywordtype">char</span> *    name
+<a name="l00409"></a>00409 )
+<a name="l00410"></a>00410 {
+<a name="l00411"></a>00411     <span class="keywordtype">int</span>    i, j ;
+<a name="l00412"></a>00412 
+<a name="l00413"></a>00413     fprintf(stdout, <span class="stringliteral">"# sinfo_eclipse_matrix %s is [%d x %d]\n"</span>, 
+<a name="l00414"></a>00414         name, M->nr, M->nc) ;
+<a name="l00415"></a>00415     <span class="keywordflow">for</span> (j=0 ; j<M->nr ; j++) {
+<a name="l00416"></a>00416         <span class="keywordflow">for</span> (i=0 ; i<M->nc ; i++) {
+<a name="l00417"></a>00417             fprintf(stdout, <span class="stringliteral">"%g\t"</span>, M->m[i+j*M->nc]) ;
+<a name="l00418"></a>00418         }
+<a name="l00419"></a>00419         fprintf(stdout, <span class="stringliteral">"\n"</span>) ;
+<a name="l00420"></a>00420     }
+<a name="l00421"></a>00421     fprintf(stdout, <span class="stringliteral">"\n"</span>) ;
+<a name="l00422"></a>00422 }
+<a name="l00423"></a>00423 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__matrix_8h_source.html b/html/sinfo__matrix_8h_source.html
new file mode 100644
index 0000000..3285688
--- /dev/null
+++ b/html/sinfo__matrix_8h_source.html
@@ -0,0 +1,123 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_matrix.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_matrix.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name     :    sinfo_matrix.h</span>
+<a name="l00022"></a>00022 <span class="comment">   Author         :    Nicolas Devillard</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on    :    1994</span>
+<a name="l00024"></a>00024 <span class="comment">   Description    :    basic 2d sinfo_eclipse_matrix handling routines</span>
+<a name="l00025"></a>00025 <span class="comment"></span>
+<a name="l00026"></a>00026 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00027"></a>00027 <span class="comment">/*</span>
+<a name="l00028"></a>00028 <span class="comment"> $Id: sinfo_matrix.h,v 1.3 2007/06/06 07:10:45 amodigli Exp $</span>
+<a name="l00029"></a>00029 <span class="comment"> $Author: amodigli $</span>
+<a name="l00030"></a>00030 <span class="comment"> $Date: 2007/06/06 07:10:45 $</span>
+<a name="l00031"></a>00031 <span class="comment"> $Revision: 1.3 $</span>
+<a name="l00032"></a>00032 <span class="comment"> */</span>
+<a name="l00033"></a>00033 
+<a name="l00034"></a>00034 <span class="preprocessor">#ifndef SINFO_MATRIX_H</span>
+<a name="l00035"></a>00035 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_MATRIX_H</span>
+<a name="l00036"></a>00036 <span class="preprocessor"></span>
+<a name="l00037"></a>00037 
+<a name="l00038"></a>00038 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00039"></a>00039 <span class="comment">                                   Includes</span>
+<a name="l00040"></a>00040 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00041"></a>00041 
+<a name="l00042"></a>00042 <span class="preprocessor">#include <stdio.h></span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include <stdlib.h></span>
+<a name="l00044"></a>00044 <span class="preprocessor">#include <math.h></span>
+<a name="l00045"></a>00045 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00046"></a>00046 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00047"></a>00047 
+<a name="l00048"></a>00048 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00049"></a>00049 <span class="comment">                                   Defines</span>
+<a name="l00050"></a>00050 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00051"></a>00051 
+<a name="l00052"></a>00052 <span class="preprocessor">#define _(b,i,j) (*((b)->m+(i)*(b)->nc+(j))) </span><span class="comment">/* b(i,j)*/</span>
+<a name="l00053"></a>00053 
+<a name="l00054"></a>00054 <span class="preprocessor">#define mx_get(M,i,j)    ((M)->m[(i)+(j)*(M)->nc])</span>
+<a name="l00055"></a>00055 <span class="preprocessor"></span><span class="preprocessor">#define mx_set(M,i,j,v)    (mx_get(M,i,j)=v)</span>
+<a name="l00056"></a>00056 <span class="preprocessor"></span>
+<a name="l00057"></a>00057 
+<a name="l00058"></a>00058 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00059"></a>00059 <span class="comment">                                   New Types</span>
+<a name="l00060"></a>00060 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00061"></a>00061 
+<a name="l00062"></a>00062 
+<a name="l00063"></a>00063 <span class="keyword">typedef</span> <span class="keyword">struct </span>_MATRIX_ {
+<a name="l00064"></a>00064     <span class="keywordtype">double</span>    *    m;
+<a name="l00065"></a>00065     <span class="keywordtype">int</span>         nr;
+<a name="l00066"></a>00066     <span class="keywordtype">int</span>         nc;
+<a name="l00067"></a>00067 } sinfo_eclipse_matrix, *Matrix;
+<a name="l00068"></a>00068 
+<a name="l00069"></a>00069 
+<a name="l00070"></a>00070 
+<a name="l00071"></a>00071 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00072"></a>00072 <span class="comment">                          Function ANSI C prototypes</span>
+<a name="l00073"></a>00073 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00074"></a>00074 
+<a name="l00086"></a>00086 Matrix
+<a name="l00087"></a>00087 sinfo_create_mx(<span class="keywordtype">int</span> nr, <span class="keywordtype">int</span> nc) ;
+<a name="l00088"></a>00088 
+<a name="l00099"></a>00099 Matrix
+<a name="l00100"></a>00100 sinfo_copy_mx(Matrix a) ;
+<a name="l00101"></a>00101 
+<a name="l00112"></a>00112 <span class="keywordtype">void</span>
+<a name="l00113"></a>00113 sinfo_close_mx(Matrix a) ;
+<a name="l00114"></a>00114 
+<a name="l00115"></a>00115 
+<a name="l00127"></a>00127 Matrix
+<a name="l00128"></a>00128 sinfo_mul_mx(Matrix a, Matrix b) ;
+<a name="l00129"></a>00129 
+<a name="l00143"></a>00143 Matrix
+<a name="l00144"></a>00144 sinfo_invert_mx(Matrix aa) ;
+<a name="l00145"></a>00145 
+<a name="l00146"></a>00146 
+<a name="l00157"></a>00157 Matrix
+<a name="l00158"></a>00158 sinfo_transp_mx(Matrix a) ;
+<a name="l00159"></a>00159 
+<a name="l00179"></a>00179 Matrix sinfo_least_sq_mx(
+<a name="l00180"></a>00180     Matrix  A,
+<a name="l00181"></a>00181     Matrix  B
+<a name="l00182"></a>00182 ) ;
+<a name="l00183"></a>00183 
+<a name="l00184"></a>00184 
+<a name="l00197"></a>00197 <span class="keywordtype">void</span> sinfo_print_mx(
+<a name="l00198"></a>00198     Matrix  M,
+<a name="l00199"></a>00199     <span class="keyword">const</span> <span class="keywordtype">char</span> *  name
+<a name="l00200"></a>00200 ) ;
+<a name="l00201"></a>00201 
+<a name="l00202"></a>00202 
+<a name="l00203"></a>00203 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__median_8c_source.html b/html/sinfo__median_8c_source.html
new file mode 100644
index 0000000..9242415
--- /dev/null
+++ b/html/sinfo__median_8c_source.html
@@ -0,0 +1,247 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_median.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_median.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name     :    sinfo_median.c</span>
+<a name="l00022"></a>00022 <span class="comment">   Author         :    N. Devillard</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on    :    1998</span>
+<a name="l00024"></a>00024 <span class="comment">   Description    :    Fast sinfo_median finding routines.</span>
+<a name="l00025"></a>00025 <span class="comment"></span>
+<a name="l00026"></a>00026 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00027"></a>00027 <span class="comment">/*</span>
+<a name="l00028"></a>00028 <span class="comment">    $Id: sinfo_median.c,v 1.4 2012/03/02 08:42:20 amodigli Exp $</span>
+<a name="l00029"></a>00029 <span class="comment">    $Author: amodigli $</span>
+<a name="l00030"></a>00030 <span class="comment">    $Date: 2012/03/02 08:42:20 $</span>
+<a name="l00031"></a>00031 <span class="comment">    $Revision: 1.4 $</span>
+<a name="l00032"></a>00032 <span class="comment">*/</span>
+<a name="l00033"></a>00033 
+<a name="l00034"></a>00034 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00035"></a>00035 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00036"></a>00036 <span class="preprocessor">#endif</span>
+<a name="l00037"></a>00037 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00038"></a>00038 <span class="comment">                                   Includes</span>
+<a name="l00039"></a>00039 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include "sinfo_median.h"</span>
+<a name="l00048"></a>00048 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00049"></a>00049 <span class="comment">                                   Macros</span>
+<a name="l00050"></a>00050 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00051"></a>00051 <span class="preprocessor">#define median_WIRTH(a,n) sinfo_kth_smallest(a,n,(((n)&1)?((n)/2):(((n)/2)-1)))</span>
+<a name="l00052"></a>00052 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00053"></a>00053 <span class="comment">                              Function codes</span>
+<a name="l00054"></a>00054 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00083"></a>00083 <span class="preprocessor">#define PIX_SWAP(a,b) { register pixelvalue t=(a);(a)=(b);(b)=t; }</span>
+<a name="l00084"></a>00084 <span class="preprocessor"></span>
+<a name="l00085"></a>00085 pixelvalue 
+<a name="l00086"></a>00086 sinfo_kth_smallest(pixelvalue a[], <span class="keywordtype">int</span> n, <span class="keywordtype">int</span> k)
+<a name="l00087"></a>00087 {
+<a name="l00088"></a>00088     <span class="keyword">register</span> <span class="keywordtype">int</span> i,j,l,m ;
+<a name="l00089"></a>00089     <span class="keyword">register</span> pixelvalue x ;
+<a name="l00090"></a>00090 
+<a name="l00091"></a>00091     l=0 ; m=n-1 ;
+<a name="l00092"></a>00092     <span class="keywordflow">while</span> (l<m) {
+<a name="l00093"></a>00093         x=a[k] ;
+<a name="l00094"></a>00094         i=l ;
+<a name="l00095"></a>00095         j=m ;
+<a name="l00096"></a>00096         <span class="keywordflow">do</span> {
+<a name="l00097"></a>00097             <span class="keywordflow">while</span> (a[i]<x) i++ ;
+<a name="l00098"></a>00098             <span class="keywordflow">while</span> (x<a[j]) j-- ;
+<a name="l00099"></a>00099             <span class="keywordflow">if</span> (i<=j) {
+<a name="l00100"></a>00100                 PIX_SWAP(a[i],a[j]) ;
+<a name="l00101"></a>00101                 i++ ; j-- ;
+<a name="l00102"></a>00102             }
+<a name="l00103"></a>00103         } <span class="keywordflow">while</span> (i<=j) ;
+<a name="l00104"></a>00104         <span class="keywordflow">if</span> (j<k) l=i ;
+<a name="l00105"></a>00105         <span class="keywordflow">if</span> (k<i) m=j ;
+<a name="l00106"></a>00106     }
+<a name="l00107"></a>00107     <span class="keywordflow">return</span> a[k] ;
+<a name="l00108"></a>00108 }
+<a name="l00109"></a>00109 
+<a name="l00110"></a>00110 <span class="preprocessor">#undef PIX_SWAP</span>
+<a name="l00111"></a>00111 <span class="preprocessor"></span>
+<a name="l00126"></a>00126 <span class="preprocessor">#define DBL_SWAP(a,b) { register double t=(a);(a)=(b);(b)=t; }</span>
+<a name="l00127"></a>00127 <span class="preprocessor"></span>
+<a name="l00128"></a>00128 <span class="keywordtype">double</span> 
+<a name="l00129"></a>00129 sinfo_kth_smallest_double(<span class="keywordtype">double</span> a[], <span class="keywordtype">int</span> n, <span class="keywordtype">int</span> k)
+<a name="l00130"></a>00130 {
+<a name="l00131"></a>00131     <span class="keyword">register</span> <span class="keywordtype">int</span> i,j,l,m ;
+<a name="l00132"></a>00132     <span class="keyword">register</span> <span class="keywordtype">double</span> x ;
+<a name="l00133"></a>00133 
+<a name="l00134"></a>00134     l=0 ; m=n-1 ;
+<a name="l00135"></a>00135     <span class="keywordflow">while</span> (l<m) {
+<a name="l00136"></a>00136         x=a[k] ;
+<a name="l00137"></a>00137         i=l ;
+<a name="l00138"></a>00138         j=m ;
+<a name="l00139"></a>00139         <span class="keywordflow">do</span> {
+<a name="l00140"></a>00140             <span class="keywordflow">while</span> (a[i]<x) i++ ;
+<a name="l00141"></a>00141             <span class="keywordflow">while</span> (x<a[j]) j-- ;
+<a name="l00142"></a>00142             <span class="keywordflow">if</span> (i<=j) {
+<a name="l00143"></a>00143                 DBL_SWAP(a[i],a[j]) ;
+<a name="l00144"></a>00144                 i++ ; j-- ;
+<a name="l00145"></a>00145             }
+<a name="l00146"></a>00146         } <span class="keywordflow">while</span> (i<=j) ;
+<a name="l00147"></a>00147         <span class="keywordflow">if</span> (j<k) l=i ;
+<a name="l00148"></a>00148         <span class="keywordflow">if</span> (k<i) m=j ;
+<a name="l00149"></a>00149     }
+<a name="l00150"></a>00150     <span class="keywordflow">return</span> a[k] ;
+<a name="l00151"></a>00151 }
+<a name="l00152"></a>00152 
+<a name="l00153"></a>00153 <span class="preprocessor">#undef DBL_SWAP</span>
+<a name="l00154"></a>00154 <span class="preprocessor"></span>
+<a name="l00155"></a>00155 <span class="preprocessor">#define PIX_SORT(a,b) { if ((a)>(b)) PIX_SWAP((a),(b)); }</span>
+<a name="l00156"></a>00156 <span class="preprocessor"></span><span class="preprocessor">#define PIX_SWAP(a,b) { pixelvalue temp=(a);(a)=(b);(b)=temp; }</span>
+<a name="l00157"></a>00157 <span class="preprocessor"></span>
+<a name="l00172"></a>00172 pixelvalue
+<a name="l00173"></a>00173 sinfo_opt_med3(
+<a name="l00174"></a>00174     pixelvalue  *   p
+<a name="l00175"></a>00175 )
+<a name="l00176"></a>00176 {
+<a name="l00177"></a>00177     PIX_SORT(p[0],p[1]) ; PIX_SORT(p[1],p[2]) ; PIX_SORT(p[0],p[1]) ;
+<a name="l00178"></a>00178     <span class="keywordflow">return</span>(p[1]) ;
+<a name="l00179"></a>00179 }
+<a name="l00180"></a>00180 
+<a name="l00195"></a>00195 pixelvalue
+<a name="l00196"></a>00196 sinfo_opt_med5(
+<a name="l00197"></a>00197     pixelvalue  *   p
+<a name="l00198"></a>00198 )
+<a name="l00199"></a>00199 {
+<a name="l00200"></a>00200     PIX_SORT(p[0],p[1]) ; PIX_SORT(p[3],p[4]) ; PIX_SORT(p[0],p[3]) ;
+<a name="l00201"></a>00201     PIX_SORT(p[1],p[4]) ; PIX_SORT(p[1],p[2]) ; PIX_SORT(p[2],p[3]) ;
+<a name="l00202"></a>00202     PIX_SORT(p[1],p[2]) ; <span class="keywordflow">return</span>(p[2]) ;
+<a name="l00203"></a>00203 }
+<a name="l00204"></a>00204 
+<a name="l00219"></a>00219 pixelvalue
+<a name="l00220"></a>00220 sinfo_opt_med7(
+<a name="l00221"></a>00221     pixelvalue  *   p
+<a name="l00222"></a>00222 )
+<a name="l00223"></a>00223 {
+<a name="l00224"></a>00224     PIX_SORT(p[0], p[5]) ; PIX_SORT(p[0], p[3]) ; PIX_SORT(p[1], p[6]) ;
+<a name="l00225"></a>00225     PIX_SORT(p[2], p[4]) ; PIX_SORT(p[0], p[1]) ; PIX_SORT(p[3], p[5]) ;
+<a name="l00226"></a>00226     PIX_SORT(p[2], p[6]) ; PIX_SORT(p[2], p[3]) ; PIX_SORT(p[3], p[6]) ;
+<a name="l00227"></a>00227     PIX_SORT(p[4], p[5]) ; PIX_SORT(p[1], p[4]) ; PIX_SORT(p[1], p[3]) ;
+<a name="l00228"></a>00228     PIX_SORT(p[3], p[4]) ; <span class="keywordflow">return</span> (p[3]) ;
+<a name="l00229"></a>00229 }
+<a name="l00230"></a>00230 
+<a name="l00249"></a>00249 pixelvalue
+<a name="l00250"></a>00250 sinfo_opt_med9(
+<a name="l00251"></a>00251     pixelvalue  *   p
+<a name="l00252"></a>00252 )
+<a name="l00253"></a>00253 {
+<a name="l00254"></a>00254     PIX_SORT(p[1], p[2]) ; PIX_SORT(p[4], p[5]) ; PIX_SORT(p[7], p[8]) ;
+<a name="l00255"></a>00255     PIX_SORT(p[0], p[1]) ; PIX_SORT(p[3], p[4]) ; PIX_SORT(p[6], p[7]) ;
+<a name="l00256"></a>00256     PIX_SORT(p[1], p[2]) ; PIX_SORT(p[4], p[5]) ; PIX_SORT(p[7], p[8]) ;
+<a name="l00257"></a>00257     PIX_SORT(p[0], p[3]) ; PIX_SORT(p[5], p[8]) ; PIX_SORT(p[4], p[7]) ;
+<a name="l00258"></a>00258     PIX_SORT(p[3], p[6]) ; PIX_SORT(p[1], p[4]) ; PIX_SORT(p[2], p[5]) ;
+<a name="l00259"></a>00259     PIX_SORT(p[4], p[7]) ; PIX_SORT(p[4], p[2]) ; PIX_SORT(p[6], p[4]) ;
+<a name="l00260"></a>00260     PIX_SORT(p[4], p[2]) ; <span class="keywordflow">return</span>(p[4]) ;
+<a name="l00261"></a>00261 }
+<a name="l00262"></a>00262 
+<a name="l00281"></a>00281 pixelvalue
+<a name="l00282"></a>00282 sinfo_opt_med25(
+<a name="l00283"></a>00283     pixelvalue  *   p
+<a name="l00284"></a>00284 )
+<a name="l00285"></a>00285 { 
+<a name="l00286"></a>00286     PIX_SORT(p[0], p[1]) ;   PIX_SORT(p[3], p[4]) ;   PIX_SORT(p[2], p[4]) ;
+<a name="l00287"></a>00287     PIX_SORT(p[2], p[3]) ;   PIX_SORT(p[6], p[7]) ;   PIX_SORT(p[5], p[7]) ;
+<a name="l00288"></a>00288     PIX_SORT(p[5], p[6]) ;   PIX_SORT(p[9], p[10]) ;  PIX_SORT(p[8], p[10]) ;
+<a name="l00289"></a>00289     PIX_SORT(p[8], p[9]) ;   PIX_SORT(p[12], p[13]) ; PIX_SORT(p[11], p[13]) ;
+<a name="l00290"></a>00290     PIX_SORT(p[11], p[12]) ; PIX_SORT(p[15], p[16]) ; PIX_SORT(p[14], p[16]) ;
+<a name="l00291"></a>00291     PIX_SORT(p[14], p[15]) ; PIX_SORT(p[18], p[19]) ; PIX_SORT(p[17], p[19]) ;
+<a name="l00292"></a>00292     PIX_SORT(p[17], p[18]) ; PIX_SORT(p[21], p[22]) ; PIX_SORT(p[20], p[22]) ;
+<a name="l00293"></a>00293     PIX_SORT(p[20], p[21]) ; PIX_SORT(p[23], p[24]) ; PIX_SORT(p[2], p[5]) ;
+<a name="l00294"></a>00294     PIX_SORT(p[3], p[6]) ;   PIX_SORT(p[0], p[6]) ;   PIX_SORT(p[0], p[3]) ;
+<a name="l00295"></a>00295     PIX_SORT(p[4], p[7]) ;   PIX_SORT(p[1], p[7]) ;   PIX_SORT(p[1], p[4]) ;
+<a name="l00296"></a>00296     PIX_SORT(p[11], p[14]) ; PIX_SORT(p[8], p[14]) ;  PIX_SORT(p[8], p[11]) ;
+<a name="l00297"></a>00297     PIX_SORT(p[12], p[15]) ; PIX_SORT(p[9], p[15]) ;  PIX_SORT(p[9], p[12]) ;
+<a name="l00298"></a>00298     PIX_SORT(p[13], p[16]) ; PIX_SORT(p[10], p[16]) ; PIX_SORT(p[10], p[13]) ;
+<a name="l00299"></a>00299     PIX_SORT(p[20], p[23]) ; PIX_SORT(p[17], p[23]) ; PIX_SORT(p[17], p[20]) ;
+<a name="l00300"></a>00300     PIX_SORT(p[21], p[24]) ; PIX_SORT(p[18], p[24]) ; PIX_SORT(p[18], p[21]) ;
+<a name="l00301"></a>00301     PIX_SORT(p[19], p[22]) ; PIX_SORT(p[8], p[17]) ;  PIX_SORT(p[9], p[18]) ;
+<a name="l00302"></a>00302     PIX_SORT(p[0], p[18]) ;  PIX_SORT(p[0], p[9]) ;   PIX_SORT(p[10], p[19]) ;
+<a name="l00303"></a>00303     PIX_SORT(p[1], p[19]) ;  PIX_SORT(p[1], p[10]) ;  PIX_SORT(p[11], p[20]) ;
+<a name="l00304"></a>00304     PIX_SORT(p[2], p[20]) ;  PIX_SORT(p[2], p[11]) ;  PIX_SORT(p[12], p[21]) ;
+<a name="l00305"></a>00305     PIX_SORT(p[3], p[21]) ;  PIX_SORT(p[3], p[12]) ;  PIX_SORT(p[13], p[22]) ;
+<a name="l00306"></a>00306     PIX_SORT(p[4], p[22]) ;  PIX_SORT(p[4], p[13]) ;  PIX_SORT(p[14], p[23]) ;
+<a name="l00307"></a>00307     PIX_SORT(p[5], p[23]) ;  PIX_SORT(p[5], p[14]) ;  PIX_SORT(p[15], p[24]) ;
+<a name="l00308"></a>00308     PIX_SORT(p[6], p[24]) ;  PIX_SORT(p[6], p[15]) ;  PIX_SORT(p[7], p[16]) ;
+<a name="l00309"></a>00309     PIX_SORT(p[7], p[19]) ;  PIX_SORT(p[13], p[21]) ; PIX_SORT(p[15], p[23]) ;
+<a name="l00310"></a>00310     PIX_SORT(p[7], p[13]) ;  PIX_SORT(p[7], p[15]) ;  PIX_SORT(p[1], p[9]) ;
+<a name="l00311"></a>00311     PIX_SORT(p[3], p[11]) ;  PIX_SORT(p[5], p[17]) ;  PIX_SORT(p[11], p[17]) ;
+<a name="l00312"></a>00312     PIX_SORT(p[9], p[17]) ;  PIX_SORT(p[4], p[10]) ;  PIX_SORT(p[6], p[12]) ;
+<a name="l00313"></a>00313     PIX_SORT(p[7], p[14]) ;  PIX_SORT(p[4], p[6]) ;   PIX_SORT(p[4], p[7]) ;
+<a name="l00314"></a>00314     PIX_SORT(p[12], p[14]) ; PIX_SORT(p[10], p[14]) ; PIX_SORT(p[6], p[7]) ;
+<a name="l00315"></a>00315     PIX_SORT(p[10], p[12]) ; PIX_SORT(p[6], p[10]) ;  PIX_SORT(p[6], p[17]) ;
+<a name="l00316"></a>00316     PIX_SORT(p[12], p[17]) ; PIX_SORT(p[7], p[17]) ;  PIX_SORT(p[7], p[10]) ;
+<a name="l00317"></a>00317     PIX_SORT(p[12], p[18]) ; PIX_SORT(p[7], p[12]) ;  PIX_SORT(p[10], p[18]) ;
+<a name="l00318"></a>00318     PIX_SORT(p[12], p[20]) ; PIX_SORT(p[10], p[20]) ; PIX_SORT(p[10], p[12]) ;
+<a name="l00319"></a>00319  
+<a name="l00320"></a>00320     <span class="keywordflow">return</span> (p[12]);
+<a name="l00321"></a>00321 } 
+<a name="l00322"></a>00322 
+<a name="l00323"></a>00323 <span class="preprocessor">#undef PIX_SORT</span>
+<a name="l00324"></a>00324 <span class="preprocessor"></span><span class="preprocessor">#undef PIX_SWAP</span>
+<a name="l00325"></a>00325 <span class="preprocessor"></span>
+<a name="l00341"></a>00341 pixelvalue 
+<a name="l00342"></a>00342 sinfo_median_pixelvalue(pixelvalue * a, <span class="keywordtype">int</span> n)
+<a name="l00343"></a>00343 {
+<a name="l00344"></a>00344     pixelvalue    sinfo_median ;
+<a name="l00345"></a>00345 
+<a name="l00346"></a>00346     <span class="keywordflow">switch</span>(n) {
+<a name="l00347"></a>00347         <span class="keywordflow">case</span> 3:
+<a name="l00348"></a>00348         sinfo_median = sinfo_opt_med3(a);
+<a name="l00349"></a>00349         break ;
+<a name="l00350"></a>00350 
+<a name="l00351"></a>00351         <span class="keywordflow">case</span> 5:
+<a name="l00352"></a>00352         sinfo_median = sinfo_opt_med5(a);
+<a name="l00353"></a>00353         break ;
+<a name="l00354"></a>00354 
+<a name="l00355"></a>00355         <span class="keywordflow">case</span> 7:
+<a name="l00356"></a>00356         sinfo_median = sinfo_opt_med7(a);
+<a name="l00357"></a>00357         break ;
+<a name="l00358"></a>00358 
+<a name="l00359"></a>00359         <span class="keywordflow">case</span> 9:
+<a name="l00360"></a>00360         sinfo_median = sinfo_opt_med9(a);
+<a name="l00361"></a>00361         break ;
+<a name="l00362"></a>00362 
+<a name="l00363"></a>00363         <span class="keywordflow">case</span> 25:
+<a name="l00364"></a>00364         sinfo_median = sinfo_opt_med25(a);
+<a name="l00365"></a>00365         break ;
+<a name="l00366"></a>00366 
+<a name="l00367"></a>00367         <span class="keywordflow">default</span>:
+<a name="l00368"></a>00368         sinfo_median = median_WIRTH(a,n);
+<a name="l00369"></a>00369         break ;
+<a name="l00370"></a>00370     }
+<a name="l00371"></a>00371     <span class="keywordflow">return</span> sinfo_median;
+<a name="l00372"></a>00372 }
+<a name="l00373"></a>00373 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__median_8h_source.html b/html/sinfo__median_8h_source.html
new file mode 100644
index 0000000..af430e1
--- /dev/null
+++ b/html/sinfo__median_8h_source.html
@@ -0,0 +1,103 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_median.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_median.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name     :    sinfo_median.h</span>
+<a name="l00022"></a>00022 <span class="comment">   Author         :    N. Devillard</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on    :    1998</span>
+<a name="l00024"></a>00024 <span class="comment">   Description    :    Fast sinfo_median finding routines</span>
+<a name="l00025"></a>00025 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00026"></a>00026 <span class="comment">/*</span>
+<a name="l00027"></a>00027 <span class="comment">    $Id: sinfo_median.h,v 1.3 2007/06/06 07:10:45 amodigli Exp $</span>
+<a name="l00028"></a>00028 <span class="comment">    $Author: amodigli $</span>
+<a name="l00029"></a>00029 <span class="comment">    $Date: 2007/06/06 07:10:45 $</span>
+<a name="l00030"></a>00030 <span class="comment">    $Revision: 1.3 $</span>
+<a name="l00031"></a>00031 <span class="comment">*/</span>
+<a name="l00032"></a>00032 <span class="preprocessor">#ifndef SINFO_MEDIAN_H</span>
+<a name="l00033"></a>00033 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_MEDIAN_H</span>
+<a name="l00034"></a>00034 <span class="preprocessor"></span>
+<a name="l00035"></a>00035 
+<a name="l00036"></a>00036 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00037"></a>00037 <span class="comment">                                   Includes</span>
+<a name="l00038"></a>00038 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00039"></a>00039 
+<a name="l00040"></a>00040 <span class="comment">/* Get the definition of a pixelvalue */</span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include "sinfo_local_types.h"</span>
+<a name="l00042"></a>00042 
+<a name="l00043"></a>00043 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00044"></a>00044 <span class="comment">                               Function prototypes</span>
+<a name="l00045"></a>00045 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00073"></a>00073 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00074"></a>00074 
+<a name="l00075"></a>00075 pixelvalue 
+<a name="l00076"></a>00076 sinfo_kth_smallest(pixelvalue a[], <span class="keywordtype">int</span> n, <span class="keywordtype">int</span> k);
+<a name="l00077"></a>00077 
+<a name="l00092"></a>00092 <span class="keywordtype">double</span> 
+<a name="l00093"></a>00093 sinfo_kth_smallest_double(<span class="keywordtype">double</span> a[], <span class="keywordtype">int</span> n, <span class="keywordtype">int</span> k) ;
+<a name="l00094"></a>00094 
+<a name="l00095"></a>00095 <span class="preprocessor">#define median_double(a,n) \</span>
+<a name="l00096"></a>00096 <span class="preprocessor">sinfo_kth_smallest_double(a,n,(((n)&1)?((n)/2):(((n)/2)-1)))</span>
+<a name="l00097"></a>00097 <span class="preprocessor"></span>
+<a name="l00112"></a>00112 pixelvalue
+<a name="l00113"></a>00113 sinfo_opt_med3(
+<a name="l00114"></a>00114     pixelvalue  *   p
+<a name="l00115"></a>00115 ) ;
+<a name="l00116"></a>00116 
+<a name="l00131"></a>00131 pixelvalue
+<a name="l00132"></a>00132 sinfo_opt_med5(
+<a name="l00133"></a>00133     pixelvalue  *   p
+<a name="l00134"></a>00134 );
+<a name="l00135"></a>00135 
+<a name="l00136"></a>00136 
+<a name="l00151"></a>00151 pixelvalue
+<a name="l00152"></a>00152 sinfo_opt_med7(
+<a name="l00153"></a>00153     pixelvalue  *   p
+<a name="l00154"></a>00154 ) ;
+<a name="l00155"></a>00155 
+<a name="l00174"></a>00174 pixelvalue
+<a name="l00175"></a>00175 sinfo_opt_med9(
+<a name="l00176"></a>00176     pixelvalue  *   p
+<a name="l00177"></a>00177 ) ;
+<a name="l00178"></a>00178 
+<a name="l00197"></a>00197 pixelvalue
+<a name="l00198"></a>00198 sinfo_opt_med25(
+<a name="l00199"></a>00199     pixelvalue  *   p
+<a name="l00200"></a>00200 ) ;
+<a name="l00201"></a>00201 
+<a name="l00202"></a>00202 
+<a name="l00218"></a>00218 pixelvalue 
+<a name="l00219"></a>00219 sinfo_median_pixelvalue(pixelvalue * a, <span class="keywordtype">int</span> n);
+<a name="l00220"></a>00220 
+<a name="l00221"></a>00221 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__merge_8c_source.html b/html/sinfo__merge_8c_source.html
new file mode 100644
index 0000000..b307be6
--- /dev/null
+++ b/html/sinfo__merge_8c_source.html
@@ -0,0 +1,985 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_merge.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_merge.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/************************************************************************</span>
+<a name="l00020"></a>00020 <span class="comment">* E.S.O. - VLT project</span>
+<a name="l00021"></a>00021 <span class="comment">*</span>
+<a name="l00022"></a>00022 <span class="comment">* </span>
+<a name="l00023"></a>00023 <span class="comment">*</span>
+<a name="l00024"></a>00024 <span class="comment">* who       when      what</span>
+<a name="l00025"></a>00025 <span class="comment">* --------  --------  ----------------------------------------------</span>
+<a name="l00026"></a>00026 <span class="comment">* schreib  04/07/00  created</span>
+<a name="l00027"></a>00027 <span class="comment">*/</span>
+<a name="l00028"></a>00028 
+<a name="l00029"></a>00029 <span class="comment">/************************************************************************</span>
+<a name="l00030"></a>00030 <span class="comment">*   NAME              </span>
+<a name="l00031"></a>00031 <span class="comment">*        sinfo_merge.c - merges the rows of two image data frames into</span>
+<a name="l00032"></a>00032 <span class="comment">*                  one frame with doubled column length     </span>
+<a name="l00033"></a>00033 <span class="comment">*        </span>
+<a name="l00034"></a>00034 <span class="comment">*   SYNOPSIS</span>
+<a name="l00035"></a>00035 <span class="comment">*   #include "merge.h"</span>
+<a name="l00036"></a>00036 <span class="comment">*</span>
+<a name="l00037"></a>00037 <span class="comment">*   a) cpl_image * sinfo_sinfo_merge_images ( cpl_image * im1, </span>
+<a name="l00038"></a>00038 <span class="comment">*                               cpl_image * im2, </span>
+<a name="l00039"></a>00039 <span class="comment">*                               cpl_image * res_image )</span>
+<a name="l00040"></a>00040 <span class="comment">*</span>
+<a name="l00041"></a>00041 <span class="comment">*   1) cpl_image * sinfo_new_remove_general_offset( cpl_image * im1, </span>
+<a name="l00042"></a>00042 <span class="comment">*                                      cpl_image * im2, </span>
+<a name="l00043"></a>00043 <span class="comment">*                                      cpl_image * res_image, </span>
+<a name="l00044"></a>00044 <span class="comment">*                                      int n )</span>
+<a name="l00045"></a>00045 <span class="comment">*</span>
+<a name="l00046"></a>00046 <span class="comment">*   2) cpl_image * sinfo_new_remove_regional_tilt ( cpl_image * im1,</span>
+<a name="l00047"></a>00047 <span class="comment">*                                      cpl_image * im2, </span>
+<a name="l00048"></a>00048 <span class="comment">*                                      cpl_image * res_image )</span>
+<a name="l00049"></a>00049 <span class="comment">*</span>
+<a name="l00050"></a>00050 <span class="comment">*   3) cpl_image * sinfo_new_remove_column_offset ( cpl_image * im1, </span>
+<a name="l00051"></a>00051 <span class="comment">*                                      cpl_image * im2, </span>
+<a name="l00052"></a>00052 <span class="comment">*                                      cpl_image * res_image )</span>
+<a name="l00053"></a>00053 <span class="comment">*</span>
+<a name="l00054"></a>00054 <span class="comment">*   4) cpl_image * sinfo_new_remove_residual_tilt ( cpl_image * im2, </span>
+<a name="l00055"></a>00055 <span class="comment">                                                   cpl_image * res_image )</span>
+<a name="l00056"></a>00056 <span class="comment">*</span>
+<a name="l00057"></a>00057 <span class="comment">*   5) cpl_image * sinfo_new_remove_residual_offset( cpl_image * im2, </span>
+<a name="l00058"></a>00058 <span class="comment">                                                    cpl_image * res_image )</span>
+<a name="l00059"></a>00059 <span class="comment">*</span>
+<a name="l00060"></a>00060 <span class="comment">*   DESCRIPTION</span>
+<a name="l00061"></a>00061 <span class="comment">*   a) merges the rows of two image frames in a way that the resulting</span>
+<a name="l00062"></a>00062 <span class="comment">*      image has double length in y-direction</span>
+<a name="l00063"></a>00063 <span class="comment">*</span>
+<a name="l00064"></a>00064 <span class="comment">*        The procedures are used in the SPIFFI data reduction to merge two </span>
+<a name="l00065"></a>00065 <span class="comment">*        data frames. In order to fully match the two input frames there</span>
+<a name="l00066"></a>00066 <span class="comment">*        are five steps (procedures) foreseen:</span>
+<a name="l00067"></a>00067 <span class="comment">*        1) remove general offset between the frames, created by e.g. different</span>
+<a name="l00068"></a>00068 <span class="comment">*           air masses. </span>
+<a name="l00069"></a>00069 <span class="comment">*        2) remove regional tilt between frames, created by e.g. different </span>
+<a name="l00070"></a>00070 <span class="comment">*           emissivities.</span>
+<a name="l00071"></a>00071 <span class="comment">*        3) remove individual column offsets, created e.g. by imperfect </span>
+<a name="l00072"></a>00072 <span class="comment">*           guiding, offset is divided out.</span>
+<a name="l00073"></a>00073 <span class="comment">*        4) remove residual individual column tilts, created by previous </span>
+<a name="l00074"></a>00074 <span class="comment">*           operations.</span>
+<a name="l00075"></a>00075 <span class="comment">*        5) remove residual column offsets by subtracting the sinfo_median.</span>
+<a name="l00076"></a>00076 <span class="comment">*</span>
+<a name="l00077"></a>00077 <span class="comment">*   FILES</span>
+<a name="l00078"></a>00078 <span class="comment">*</span>
+<a name="l00079"></a>00079 <span class="comment">*   ENVIRONMENT</span>
+<a name="l00080"></a>00080 <span class="comment">*</span>
+<a name="l00081"></a>00081 <span class="comment">*   RETURN VALUES </span>
+<a name="l00082"></a>00082 <span class="comment">*   always the pointer to the image data structure cpl_image</span>
+<a name="l00083"></a>00083 <span class="comment">*</span>
+<a name="l00084"></a>00084 <span class="comment">*   CAUTIONS </span>
+<a name="l00085"></a>00085 <span class="comment">*</span>
+<a name="l00086"></a>00086 <span class="comment">*   EXAMPLES</span>
+<a name="l00087"></a>00087 <span class="comment">*</span>
+<a name="l00088"></a>00088 <span class="comment">*   SEE ALSO</span>
+<a name="l00089"></a>00089 <span class="comment">*   Python script merging.py</span>
+<a name="l00090"></a>00090 <span class="comment">*</span>
+<a name="l00091"></a>00091 <span class="comment">*   BUGS   </span>
+<a name="l00092"></a>00092 <span class="comment">*</span>
+<a name="l00093"></a>00093 <span class="comment">*------------------------------------------------------------------------</span>
+<a name="l00094"></a>00094 <span class="comment">*/</span>
+<a name="l00095"></a>00095 
+<a name="l00096"></a>00096 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00097"></a>00097 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00098"></a>00098 <span class="preprocessor">#endif</span>
+<a name="l00099"></a>00099 <span class="preprocessor"></span><span class="preprocessor">#include "sinfo_vltPort.h"</span>
+<a name="l00100"></a>00100 
+<a name="l00101"></a>00101 <span class="comment">/* </span>
+<a name="l00102"></a>00102 <span class="comment"> * System Headers</span>
+<a name="l00103"></a>00103 <span class="comment"> */</span>
+<a name="l00104"></a>00104 
+<a name="l00105"></a>00105 <span class="comment">/* </span>
+<a name="l00106"></a>00106 <span class="comment"> * Local Headers</span>
+<a name="l00107"></a>00107 <span class="comment"> */</span>
+<a name="l00108"></a>00108 
+<a name="l00109"></a>00109 <span class="preprocessor">#include "sinfo_merge.h"</span>
+<a name="l00110"></a>00110 <span class="preprocessor">#include "sinfo_globals.h"</span>
+<a name="l00130"></a>00130 cpl_image * sinfo_sinfo_merge_images ( cpl_image * im1, 
+<a name="l00131"></a>00131                          cpl_image * im2, 
+<a name="l00132"></a>00132                          cpl_image * res_image )
+<a name="l00133"></a>00133 {
+<a name="l00134"></a>00134     cpl_image * out_image ;
+<a name="l00135"></a>00135     cpl_image * residual ;
+<a name="l00136"></a>00136     <span class="keywordtype">int</span> i, j ;
+<a name="l00137"></a>00137 
+<a name="l00138"></a>00138     <span class="keywordtype">int</span> lx1=0;
+<a name="l00139"></a>00139     <span class="keywordtype">int</span> ly1=0;
+<a name="l00140"></a>00140     <span class="keywordtype">int</span> lx2=0;
+<a name="l00141"></a>00141     <span class="keywordtype">int</span> ly2=0;
+<a name="l00142"></a>00142 
+<a name="l00143"></a>00143 
+<a name="l00144"></a>00144     <span class="keywordtype">float</span>* pi1data=NULL;
+<a name="l00145"></a>00145     <span class="keywordtype">float</span>* pi2data=NULL;
+<a name="l00146"></a>00146     <span class="keywordtype">float</span>* pirdata=NULL;
+<a name="l00147"></a>00147     <span class="keywordtype">float</span>* poutdata=NULL;
+<a name="l00148"></a>00148     <span class="keywordtype">float</span>* ptmpdata=NULL;
+<a name="l00149"></a>00149 
+<a name="l00150"></a>00150 
+<a name="l00151"></a>00151 
+<a name="l00152"></a>00152     <span class="keywordflow">if</span> ( im1 == NULL || im2 == NULL || res_image == NULL)
+<a name="l00153"></a>00153     {
+<a name="l00154"></a>00154         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" null image as input"</span>) ;
+<a name="l00155"></a>00155         <span class="keywordflow">return</span> NULL ;
+<a name="l00156"></a>00156     }
+<a name="l00157"></a>00157     lx1=cpl_image_get_size_x(im1);
+<a name="l00158"></a>00158     ly1=cpl_image_get_size_y(im1);
+<a name="l00159"></a>00159 
+<a name="l00160"></a>00160     lx2=cpl_image_get_size_x(im2);
+<a name="l00161"></a>00161     ly2=cpl_image_get_size_y(im2);
+<a name="l00162"></a>00162 
+<a name="l00163"></a>00163 
+<a name="l00164"></a>00164 
+<a name="l00165"></a>00165     pi1data=cpl_image_get_data_float(im1);
+<a name="l00166"></a>00166     pi2data=cpl_image_get_data_float(im2);
+<a name="l00167"></a>00167     pirdata=cpl_image_get_data_float(res_image);
+<a name="l00168"></a>00168 
+<a name="l00169"></a>00169 
+<a name="l00170"></a>00170     <span class="keywordflow">if</span> ( lx1 != lx2 || ly1 != ly2 )
+<a name="l00171"></a>00171     {
+<a name="l00172"></a>00172         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"input images are not compatible in size"</span>) ;
+<a name="l00173"></a>00173         <span class="keywordflow">return</span> NULL ;
+<a name="l00174"></a>00174     }
+<a name="l00175"></a>00175 
+<a name="l00176"></a>00176     <span class="comment">/* allocate memory */</span>
+<a name="l00177"></a>00177     <span class="keywordflow">if</span> ( NULL == (out_image = cpl_image_new (lx1, 2 * ly1,CPL_TYPE_FLOAT)) )
+<a name="l00178"></a>00178     {
+<a name="l00179"></a>00179         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" cannot allocate new image"</span>) ;
+<a name="l00180"></a>00180         <span class="keywordflow">return</span> NULL ;
+<a name="l00181"></a>00181     }
+<a name="l00182"></a>00182     poutdata=cpl_image_get_data_float(out_image);
+<a name="l00183"></a>00183 
+<a name="l00184"></a>00184     <span class="keywordflow">if</span> ( NULL == (residual = cpl_image_new (lx1, ly1,CPL_TYPE_FLOAT)) )
+<a name="l00185"></a>00185     {
+<a name="l00186"></a>00186         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" cannot allocate new image "</span>) ;
+<a name="l00187"></a>00187         <span class="keywordflow">return</span> NULL ;
+<a name="l00188"></a>00188     }
+<a name="l00189"></a>00189     ptmpdata=cpl_image_get_data_float(residual);
+<a name="l00190"></a>00190 
+<a name="l00191"></a>00191     <span class="comment">/* now compute the final residual image */</span>
+<a name="l00192"></a>00192     <span class="keywordflow">for</span> ( i = 0 ; i < (int) lx1*ly1 ; i ++ )
+<a name="l00193"></a>00193     {
+<a name="l00194"></a>00194         <span class="keywordflow">if</span> ( isnan(pi1data[i]) || isnan(pi2data[i]) )
+<a name="l00195"></a>00195         {
+<a name="l00196"></a>00196             ptmpdata[i] = ZERO ;
+<a name="l00197"></a>00197         }   
+<a name="l00198"></a>00198         <span class="keywordflow">else</span>
+<a name="l00199"></a>00199         {
+<a name="l00200"></a>00200             ptmpdata[i] = pi1data[i] - pi2data[i] ;
+<a name="l00201"></a>00201         }
+<a name="l00202"></a>00202         pirdata[i] = ptmpdata[i] ;
+<a name="l00203"></a>00203     }
+<a name="l00204"></a>00204 
+<a name="l00205"></a>00205     <span class="comment">/* now merge the two images */</span>
+<a name="l00206"></a>00206     <span class="keywordflow">for</span> ( i = 0 ; i < ly1 ; i ++ )
+<a name="l00207"></a>00207     {
+<a name="l00208"></a>00208         <span class="keywordflow">for</span> ( j = 0 ; j < lx1 ; j ++ )
+<a name="l00209"></a>00209         {
+<a name="l00210"></a>00210             <span class="comment">/* transfer rows to output */</span>
+<a name="l00211"></a>00211             poutdata[2*i*lx1 + j] = pi1data[i*lx1 + j]  ;
+<a name="l00212"></a>00212             poutdata[(2*i+1) * lx1 + j] = pi2data[i*lx1 + j] ;
+<a name="l00213"></a>00213         }     
+<a name="l00214"></a>00214     }
+<a name="l00215"></a>00215 
+<a name="l00216"></a>00216     cpl_image_delete (residual) ;
+<a name="l00217"></a>00217 
+<a name="l00218"></a>00218     <span class="keywordflow">return</span> out_image ;
+<a name="l00219"></a>00219 }
+<a name="l00220"></a>00220     
+<a name="l00221"></a>00221 
+<a name="l00238"></a>00238 cpl_image * sinfo_new_remove_general_offset( cpl_image * im1, 
+<a name="l00239"></a>00239                                 cpl_image * im2, 
+<a name="l00240"></a>00240                                 cpl_image * res_image, 
+<a name="l00241"></a>00241                                 <span class="keywordtype">int</span> n )
+<a name="l00242"></a>00242 {
+<a name="l00243"></a>00243     cpl_image * out_image ;
+<a name="l00244"></a>00244     cpl_image * residual  ;
+<a name="l00245"></a>00245     pixelvalue sum, sqr_sum ;
+<a name="l00246"></a>00246     pixelvalue mean, stdev  ;
+<a name="l00247"></a>00247     <span class="keywordtype">int</span> i, npix ;
+<a name="l00248"></a>00248 
+<a name="l00249"></a>00249     <span class="keywordtype">int</span> lx1=0;
+<a name="l00250"></a>00250     <span class="keywordtype">int</span> ly1=0;
+<a name="l00251"></a>00251     <span class="keywordtype">int</span> lx2=0;
+<a name="l00252"></a>00252     <span class="keywordtype">int</span> ly2=0;
+<a name="l00253"></a>00253     <span class="keywordtype">int</span> lxr=0;
+<a name="l00254"></a>00254     <span class="keywordtype">int</span> lyr=0;
+<a name="l00255"></a>00255     <span class="keywordtype">int</span> lxt=0;
+<a name="l00256"></a>00256     <span class="keywordtype">int</span> lyt=0;
+<a name="l00257"></a>00257 
+<a name="l00258"></a>00258     <span class="keywordtype">float</span>* pi1data=NULL;
+<a name="l00259"></a>00259     <span class="keywordtype">float</span>* pi2data=NULL;
+<a name="l00260"></a>00260     <span class="keywordtype">float</span>* pirdata=NULL;
+<a name="l00261"></a>00261     <span class="keywordtype">float</span>* poutdata=NULL;
+<a name="l00262"></a>00262     <span class="keywordtype">float</span>* ptmpdata=NULL;
+<a name="l00263"></a>00263 
+<a name="l00264"></a>00264 
+<a name="l00265"></a>00265 
+<a name="l00266"></a>00266     <span class="keywordflow">if</span> ( im1 == NULL || im2 == NULL )
+<a name="l00267"></a>00267     {
+<a name="l00268"></a>00268         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" null image as input"</span>) ;
+<a name="l00269"></a>00269         <span class="keywordflow">return</span> NULL ;
+<a name="l00270"></a>00270     }
+<a name="l00271"></a>00271     lx1=cpl_image_get_size_x(im1);
+<a name="l00272"></a>00272     ly1=cpl_image_get_size_y(im1);
+<a name="l00273"></a>00273 
+<a name="l00274"></a>00274     lx2=cpl_image_get_size_x(im2);
+<a name="l00275"></a>00275     ly2=cpl_image_get_size_y(im2);
+<a name="l00276"></a>00276 
+<a name="l00277"></a>00277 
+<a name="l00278"></a>00278 
+<a name="l00279"></a>00279     pi1data=cpl_image_get_data_float(im1);
+<a name="l00280"></a>00280     pi2data=cpl_image_get_data_float(im2);
+<a name="l00281"></a>00281 
+<a name="l00282"></a>00282 
+<a name="l00283"></a>00283     <span class="keywordflow">if</span> ( lx1 != lx2 || ly1 != ly2 )
+<a name="l00284"></a>00284     {
+<a name="l00285"></a>00285         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" input images are not compatible in size"</span>) ;
+<a name="l00286"></a>00286         <span class="keywordflow">return</span> NULL ;
+<a name="l00287"></a>00287     }
+<a name="l00288"></a>00288     
+<a name="l00289"></a>00289     <span class="keywordflow">if</span> ( n <= 0 )
+<a name="l00290"></a>00290     {
+<a name="l00291"></a>00291         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"number of rows for offset determination "</span>
+<a name="l00292"></a>00292                         <span class="stringliteral">"is 0 or smaller "</span>) ;
+<a name="l00293"></a>00293         <span class="keywordflow">return</span> NULL ;
+<a name="l00294"></a>00294     }
+<a name="l00295"></a>00295         
+<a name="l00296"></a>00296     <span class="comment">/* allocate memory */</span>
+<a name="l00297"></a>00297     <span class="keywordflow">if</span> ( NULL == (residual = cpl_image_new (lx1, ly1, CPL_TYPE_FLOAT)) )
+<a name="l00298"></a>00298     {
+<a name="l00299"></a>00299         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" cannot allocate new image "</span>) ;
+<a name="l00300"></a>00300         <span class="keywordflow">return</span> NULL ;
+<a name="l00301"></a>00301     }
+<a name="l00302"></a>00302        
+<a name="l00303"></a>00303     out_image = cpl_image_duplicate( im2 ) ;
+<a name="l00304"></a>00304     poutdata=cpl_image_get_data_float(out_image);
+<a name="l00305"></a>00305     ptmpdata=cpl_image_get_data_float(residual);
+<a name="l00306"></a>00306     lxt=cpl_image_get_size_x(residual);
+<a name="l00307"></a>00307     lyt=cpl_image_get_size_y(residual);
+<a name="l00308"></a>00308 
+<a name="l00309"></a>00309     <span class="comment">/* ---------------------------------------------------------------------</span>
+<a name="l00310"></a>00310 <span class="comment">     * first we determine the "good" pixels and subtract the two images </span>
+<a name="l00311"></a>00311 <span class="comment">     * then we determine the mean and 3 sigma</span>
+<a name="l00312"></a>00312 <span class="comment">     */</span>
+<a name="l00313"></a>00313 
+<a name="l00314"></a>00314     sum = 0. ;
+<a name="l00315"></a>00315     sqr_sum = 0. ;
+<a name="l00316"></a>00316     npix = 0 ;
+<a name="l00317"></a>00317     <span class="keywordflow">for</span> ( i = 0 ; i < (int) lx1*ly1 ; i ++ )
+<a name="l00318"></a>00318     {
+<a name="l00319"></a>00319         <span class="keywordflow">if</span> ( isnan(pi1data[i]) || isnan(pi2data[i]) )
+<a name="l00320"></a>00320         {
+<a name="l00321"></a>00321             ptmpdata[i] = ZERO ;
+<a name="l00322"></a>00322             continue ;
+<a name="l00323"></a>00323         }   
+<a name="l00324"></a>00324         <span class="keywordflow">else</span>
+<a name="l00325"></a>00325         {
+<a name="l00326"></a>00326             ptmpdata[i] = pi1data[i] - pi2data[i] ;
+<a name="l00327"></a>00327         }
+<a name="l00328"></a>00328 
+<a name="l00329"></a>00329         sum += ptmpdata[i] ;
+<a name="l00330"></a>00330         sqr_sum += (ptmpdata[i]) * (ptmpdata[i]) ;
+<a name="l00331"></a>00331         npix ++ ;
+<a name="l00332"></a>00332     }
+<a name="l00333"></a>00333     <span class="keywordflow">if</span> ( npix <= 1 )
+<a name="l00334"></a>00334     {
+<a name="l00335"></a>00335         mean = 0. ;
+<a name="l00336"></a>00336         stdev = 0. ;
+<a name="l00337"></a>00337     }
+<a name="l00338"></a>00338     <span class="keywordflow">else</span>
+<a name="l00339"></a>00339     {
+<a name="l00340"></a>00340         mean = sum / (pixelvalue) npix ;   
+<a name="l00341"></a>00341         <span class="comment">/* stdev is 3 sigma */</span>
+<a name="l00342"></a>00342         stdev = 3 * sqrt(( sqr_sum - sum*mean ) / (pixelvalue)(npix - 1)) ;
+<a name="l00343"></a>00343     }
+<a name="l00344"></a>00344     
+<a name="l00345"></a>00345     <span class="comment">/* exclude everything > 3 sigma */</span>
+<a name="l00346"></a>00346     
+<a name="l00347"></a>00347     <span class="keywordflow">for</span> ( i = 0 ; i < (int) lxt*lyt ; i++ )
+<a name="l00348"></a>00348     {
+<a name="l00349"></a>00349         <span class="keywordflow">if</span> ( fabs( ptmpdata[i] - mean ) > stdev )
+<a name="l00350"></a>00350         {
+<a name="l00351"></a>00351             ptmpdata[i] = ZERO ;
+<a name="l00352"></a>00352         }
+<a name="l00353"></a>00353     }
+<a name="l00354"></a>00354     
+<a name="l00355"></a>00355     <span class="comment">/* now subtract the general offset which is determined </span>
+<a name="l00356"></a>00356 <span class="comment">       as mean of the first n rows */</span>
+<a name="l00357"></a>00357     
+<a name="l00358"></a>00358     sum = 0. ;
+<a name="l00359"></a>00359     npix = 0 ;
+<a name="l00360"></a>00360     <span class="keywordflow">for</span> ( i = 0 ; i < n * lxt ; i++ )
+<a name="l00361"></a>00361     {
+<a name="l00362"></a>00362         <span class="keywordflow">if</span> ( isnan(ptmpdata[i]) )
+<a name="l00363"></a>00363         {
+<a name="l00364"></a>00364             continue ;
+<a name="l00365"></a>00365         }
+<a name="l00366"></a>00366 
+<a name="l00367"></a>00367         sum += ptmpdata[i] ;
+<a name="l00368"></a>00368         npix ++ ;
+<a name="l00369"></a>00369     }
+<a name="l00370"></a>00370     <span class="keywordflow">if</span> ( npix == 0 )
+<a name="l00371"></a>00371     {
+<a name="l00372"></a>00372         mean = 0. ;
+<a name="l00373"></a>00373     }
+<a name="l00374"></a>00374     <span class="keywordflow">else</span>
+<a name="l00375"></a>00375     {
+<a name="l00376"></a>00376         mean = sum / (pixelvalue) npix ;      
+<a name="l00377"></a>00377     } 
+<a name="l00378"></a>00378     
+<a name="l00379"></a>00379     <span class="comment">/* now apply this to the second input image */</span>
+<a name="l00380"></a>00380     <span class="keywordflow">for</span> ( i = 0 ; i < (int) lx2*ly2 ; i++ )
+<a name="l00381"></a>00381     {
+<a name="l00382"></a>00382         <span class="keywordflow">if</span> ( isnan(pi2data[i]) )
+<a name="l00383"></a>00383         {
+<a name="l00384"></a>00384             poutdata[i] = ZERO ;
+<a name="l00385"></a>00385             continue ;
+<a name="l00386"></a>00386         }
+<a name="l00387"></a>00387         poutdata[i] = pi2data[i] + mean ;
+<a name="l00388"></a>00388     }    
+<a name="l00389"></a>00389  
+<a name="l00390"></a>00390     <span class="comment">/* now determine the residual image if available */</span>
+<a name="l00391"></a>00391     <span class="keywordflow">if</span> ( res_image != NULL )
+<a name="l00392"></a>00392     {
+<a name="l00393"></a>00393 
+<a name="l00394"></a>00394        lxr=cpl_image_get_size_x(res_image);
+<a name="l00395"></a>00395        lyr=cpl_image_get_size_y(res_image);
+<a name="l00396"></a>00396        pirdata=cpl_image_get_data_float(res_image);
+<a name="l00397"></a>00397 
+<a name="l00398"></a>00398 
+<a name="l00399"></a>00399         <span class="keywordflow">for</span> ( i = 0 ; i < (int) lxt*lyt ; i++ )
+<a name="l00400"></a>00400         {
+<a name="l00401"></a>00401             <span class="keywordflow">if</span> ( isnan(ptmpdata[i]) )
+<a name="l00402"></a>00402             {
+<a name="l00403"></a>00403                 pirdata[i] = ZERO ;
+<a name="l00404"></a>00404                 continue ;
+<a name="l00405"></a>00405             }
+<a name="l00406"></a>00406             pirdata[i] = ptmpdata[i] - mean ;
+<a name="l00407"></a>00407         }
+<a name="l00408"></a>00408     }    
+<a name="l00409"></a>00409 
+<a name="l00410"></a>00410     cpl_image_delete (residual) ;
+<a name="l00411"></a>00411 
+<a name="l00412"></a>00412     <span class="keywordflow">return</span> out_image ;
+<a name="l00413"></a>00413 }
+<a name="l00414"></a>00414 
+<a name="l00427"></a>00427 cpl_image * sinfo_new_remove_regional_tilt ( cpl_image * im1, 
+<a name="l00428"></a>00428                                 cpl_image * im2, 
+<a name="l00429"></a>00429                                 cpl_image * res_image )
+<a name="l00430"></a>00430 {
+<a name="l00431"></a>00431     cpl_image * out_image ;
+<a name="l00432"></a>00432     cpl_image * filtered  ;
+<a name="l00433"></a>00433     <span class="keywordtype">int</span> i, j, k, npix, nrunning ;
+<a name="l00434"></a>00434     pixelvalue a, b, sum, sumx, sumy, sumc, sum2 ;
+<a name="l00435"></a>00435     <span class="keywordtype">int</span> lx1=0;
+<a name="l00436"></a>00436     <span class="keywordtype">int</span> ly1=0;
+<a name="l00437"></a>00437     <span class="keywordtype">int</span> lx2=0;
+<a name="l00438"></a>00438     <span class="keywordtype">int</span> ly2=0;
+<a name="l00439"></a>00439     <span class="keywordtype">int</span> lxr=0;
+<a name="l00440"></a>00440     <span class="keywordtype">int</span> lyr=0;
+<a name="l00441"></a>00441     <span class="keywordtype">int</span> lxf=0;
+<a name="l00442"></a>00442     <span class="keywordtype">int</span> lyf=0;
+<a name="l00443"></a>00443 
+<a name="l00444"></a>00444     <span class="keywordtype">float</span>* pi1data=NULL;
+<a name="l00445"></a>00445     <span class="keywordtype">float</span>* pi2data=NULL;
+<a name="l00446"></a>00446     <span class="keywordtype">float</span>* pirdata=NULL;
+<a name="l00447"></a>00447     <span class="keywordtype">float</span>* poutdata=NULL;
+<a name="l00448"></a>00448     <span class="keywordtype">float</span>* pfildata=NULL;
+<a name="l00449"></a>00449 
+<a name="l00450"></a>00450 
+<a name="l00451"></a>00451     <span class="keywordflow">if</span> ( im1 == NULL || im2 == NULL || res_image == NULL )
+<a name="l00452"></a>00452     {
+<a name="l00453"></a>00453         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"null image as input"</span>) ;
+<a name="l00454"></a>00454         <span class="keywordflow">return</span> NULL ;
+<a name="l00455"></a>00455     }
+<a name="l00456"></a>00456     lx1=cpl_image_get_size_x(im1);
+<a name="l00457"></a>00457     ly1=cpl_image_get_size_y(im1);
+<a name="l00458"></a>00458 
+<a name="l00459"></a>00459     lx2=cpl_image_get_size_x(im2);
+<a name="l00460"></a>00460     ly2=cpl_image_get_size_y(im2);
+<a name="l00461"></a>00461 
+<a name="l00462"></a>00462     lxr=cpl_image_get_size_x(res_image);
+<a name="l00463"></a>00463     lyr=cpl_image_get_size_y(res_image);
+<a name="l00464"></a>00464 
+<a name="l00465"></a>00465 
+<a name="l00466"></a>00466     pi1data=cpl_image_get_data_float(im1);
+<a name="l00467"></a>00467     pi2data=cpl_image_get_data_float(im2);
+<a name="l00468"></a>00468     pirdata=cpl_image_get_data_float(res_image);
+<a name="l00469"></a>00469 
+<a name="l00470"></a>00470     <span class="keywordflow">if</span> ( lx1 != lx2 || ly1 != ly2 ||
+<a name="l00471"></a>00471          lx2 != lxr || ly2 != lyr )
+<a name="l00472"></a>00472     {
+<a name="l00473"></a>00473         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"input images are not compatible in size"</span>) ;
+<a name="l00474"></a>00474         <span class="keywordflow">return</span> NULL ;
+<a name="l00475"></a>00475     }
+<a name="l00476"></a>00476 
+<a name="l00477"></a>00477     <span class="comment">/* allocate memory */</span>
+<a name="l00478"></a>00478     <span class="keywordflow">if</span> ( NULL == ( filtered = cpl_image_new (lx2, ly2,CPL_TYPE_FLOAT)) )
+<a name="l00479"></a>00479     {
+<a name="l00480"></a>00480         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"cannot allocate new image "</span>) ;
+<a name="l00481"></a>00481         <span class="keywordflow">return</span> NULL ;
+<a name="l00482"></a>00482     }
+<a name="l00483"></a>00483 
+<a name="l00484"></a>00484     out_image = cpl_image_duplicate( im2 ) ;
+<a name="l00485"></a>00485     poutdata=cpl_image_get_data_float(out_image);
+<a name="l00486"></a>00486     pfildata=cpl_image_get_data_float(filtered);
+<a name="l00487"></a>00487     lxf=cpl_image_get_size_x(filtered);
+<a name="l00488"></a>00488     lyf=cpl_image_get_size_y(filtered);
+<a name="l00489"></a>00489     
+<a name="l00490"></a>00490     <span class="comment">/*-------------------------------------------------------------------------</span>
+<a name="l00491"></a>00491 <span class="comment">     * Now work in the given difference image res_image on each </span>
+<a name="l00492"></a>00492 <span class="comment">       column separately. This image is first smoothed columnwise </span>
+<a name="l00493"></a>00493 <span class="comment">       by a running box</span>
+<a name="l00494"></a>00494 <span class="comment">     */</span>
+<a name="l00495"></a>00495     
+<a name="l00496"></a>00496     nrunning = 31 ; <span class="comment">/* # of points in the running box, odd number required */</span>
+<a name="l00497"></a>00497 
+<a name="l00498"></a>00498     <span class="keywordflow">for</span> ( j = 0 ; j < lyr ; j ++ ) <span class="comment">/* select a row */</span>
+<a name="l00499"></a>00499     {
+<a name="l00500"></a>00500         <span class="keywordflow">for</span> ( i = 0 ; i < lxr ; i ++ ) <span class="comment">/* go through one row */</span>
+<a name="l00501"></a>00501         {
+<a name="l00502"></a>00502             npix = 0 ;
+<a name="l00503"></a>00503             sum = 0. ;
+<a name="l00504"></a>00504             <span class="keywordflow">for</span> (k = i - (nrunning-1)/2 ; k < i + (nrunning+1)/2; k ++ )
+<a name="l00505"></a>00505             {
+<a name="l00506"></a>00506                 <span class="comment">/* marginal pixels are not considered */</span>
+<a name="l00507"></a>00507                 <span class="keywordflow">if</span> ( k < 2 )
+<a name="l00508"></a>00508                 {
+<a name="l00509"></a>00509                     continue ;
+<a name="l00510"></a>00510                 }
+<a name="l00511"></a>00511                 <span class="keywordflow">if</span> ( k > (lxr) - 2 )
+<a name="l00512"></a>00512                 {
+<a name="l00513"></a>00513                     break ;
+<a name="l00514"></a>00514 
+<a name="l00515"></a>00515                 }
+<a name="l00516"></a>00516                 <span class="keywordflow">if</span> ( isnan(pirdata[j*lxr + k]) )
+<a name="l00517"></a>00517                 {
+<a name="l00518"></a>00518                     continue ;
+<a name="l00519"></a>00519                 }
+<a name="l00520"></a>00520                 npix ++ ;
+<a name="l00521"></a>00521                 sum += pirdata[j*lxr + k] ;
+<a name="l00522"></a>00522             }
+<a name="l00523"></a>00523             <span class="keywordflow">if</span> ( npix != 0 )
+<a name="l00524"></a>00524             {
+<a name="l00525"></a>00525                 pfildata[j*lxr + i] = sum/npix ;
+<a name="l00526"></a>00526             }
+<a name="l00527"></a>00527             <span class="keywordflow">else</span>
+<a name="l00528"></a>00528             {
+<a name="l00529"></a>00529                 pfildata[j*lxr + i] = ZERO ;
+<a name="l00530"></a>00530             }
+<a name="l00531"></a>00531         }
+<a name="l00532"></a>00532     }                  
+<a name="l00533"></a>00533    
+<a name="l00534"></a>00534     <span class="comment">/*------------------------------------------------------------------</span>
+<a name="l00535"></a>00535 <span class="comment">     * now determine the tilt in each column and remove it in such a way</span>
+<a name="l00536"></a>00536 <span class="comment">     * that the first rows are used as references that are not changed</span>
+<a name="l00537"></a>00537 <span class="comment">     * a free regression fit is (index i means the sum over i):</span>
+<a name="l00538"></a>00538 <span class="comment">     * ax + b: a = [<xiyi>-<xi><yi>]/[<xi^2>-<xi>^2]</span>
+<a name="l00539"></a>00539 <span class="comment">     * =>    : a = [xiyi - xi<yi>]/[xi^2 - xi<xi>]</span>
+<a name="l00540"></a>00540 <span class="comment">     *         b = <yi> - a<xi></span>
+<a name="l00541"></a>00541 <span class="comment">     */</span>
+<a name="l00542"></a>00542     
+<a name="l00543"></a>00543     <span class="keywordflow">for</span> ( i = 0 ; i < lxf ; i ++ ) <span class="comment">/* one column selected */</span>
+<a name="l00544"></a>00544     {
+<a name="l00545"></a>00545         sumy = 0. ;                   <span class="comment">/* yi   */</span>
+<a name="l00546"></a>00546         sumc = 0. ;                   <span class="comment">/* xiyi */</span>
+<a name="l00547"></a>00547         sumx = 0. ;                   <span class="comment">/* xi   */</span>
+<a name="l00548"></a>00548         sum2 = 0. ;                   <span class="comment">/* xi^2 */</span>
+<a name="l00549"></a>00549         npix = 0  ;  
+<a name="l00550"></a>00550           
+<a name="l00551"></a>00551         <span class="keywordflow">for</span> ( j = 0 ; j < lyf ; j ++ ) 
+<a name="l00552"></a>00552         {
+<a name="l00553"></a>00553             <span class="keywordflow">if</span> ( isnan(pfildata[i + j*lxf]) )
+<a name="l00554"></a>00554             {
+<a name="l00555"></a>00555                 continue ;
+<a name="l00556"></a>00556             }
+<a name="l00557"></a>00557             sumy +=  pfildata[i + j*lxf] ;
+<a name="l00558"></a>00558             sumc += (pfildata[i + j*lxf]) * j ;
+<a name="l00559"></a>00559             sum2 += j*j ;
+<a name="l00560"></a>00560             sumx += j   ;
+<a name="l00561"></a>00561             npix ++     ;
+<a name="l00562"></a>00562         }
+<a name="l00563"></a>00563         <span class="keywordflow">if</span> ( npix > 2 && fabs(sum2 - sumx*sumx/npix) >= 1e-6 ) 
+<a name="l00564"></a>00564         {
+<a name="l00565"></a>00565             a = ( sumc - sumx*sumy/npix ) / ( sum2 - sumx*sumx/npix ) ;
+<a name="l00566"></a>00566             b = ( sumy - a*sumx ) / npix ;
+<a name="l00567"></a>00567         } 
+<a name="l00568"></a>00568         <span class="keywordflow">else</span>
+<a name="l00569"></a>00569         {
+<a name="l00570"></a>00570             a = ZERO ;
+<a name="l00571"></a>00571             b = ZERO ;
+<a name="l00572"></a>00572         }
+<a name="l00573"></a>00573 
+<a name="l00574"></a>00574         <span class="comment">/*-----------------------------------------------------------</span>
+<a name="l00575"></a>00575 <span class="comment">         * now correct the second input image im2 and the res_image.</span>
+<a name="l00576"></a>00576 <span class="comment">         */</span> 
+<a name="l00577"></a>00577 
+<a name="l00578"></a>00578         <span class="keywordflow">if</span> ( !isnan(a) && !isnan(b) && fabs(a) < 1e8 && fabs(b) < 1e8 )
+<a name="l00579"></a>00579         {
+<a name="l00580"></a>00580             <span class="keywordflow">for</span> ( j = 0 ; j < lyf ; j ++ ) <span class="comment">/* the same column */</span>
+<a name="l00581"></a>00581             {
+<a name="l00582"></a>00582                 <span class="keywordflow">if</span> ( !isnan(poutdata[i + j*lxf]) )
+<a name="l00583"></a>00583                 {
+<a name="l00584"></a>00584                     poutdata[i + j*lxf] += a*j+b ;        
+<a name="l00585"></a>00585                 }
+<a name="l00586"></a>00586             }
+<a name="l00587"></a>00587         }
+<a name="l00588"></a>00588     }
+<a name="l00589"></a>00589    
+<a name="l00590"></a>00590     <span class="comment">/* now compute the final residual image */</span>
+<a name="l00591"></a>00591     <span class="keywordflow">for</span> ( i = 0 ; i < (int) lx1*ly1 ; i ++ )
+<a name="l00592"></a>00592     {
+<a name="l00593"></a>00593         <span class="keywordflow">if</span> ( isnan(pi1data[i]) || isnan(poutdata[i]) )
+<a name="l00594"></a>00594         {
+<a name="l00595"></a>00595             pirdata[i] = ZERO ;
+<a name="l00596"></a>00596         }   
+<a name="l00597"></a>00597         <span class="keywordflow">else</span>
+<a name="l00598"></a>00598         {
+<a name="l00599"></a>00599             pirdata[i] = pi1data[i] - poutdata[i] ;
+<a name="l00600"></a>00600         }
+<a name="l00601"></a>00601     }
+<a name="l00602"></a>00602 
+<a name="l00603"></a>00603     cpl_image_delete (filtered) ;
+<a name="l00604"></a>00604    
+<a name="l00605"></a>00605     <span class="keywordflow">return</span> out_image ;
+<a name="l00606"></a>00606 }
+<a name="l00607"></a>00607 
+<a name="l00608"></a>00608 
+<a name="l00621"></a>00621 cpl_image * sinfo_new_remove_column_offset ( cpl_image * im1, 
+<a name="l00622"></a>00622                                 cpl_image * im2, 
+<a name="l00623"></a>00623                                 cpl_image * res_image )
+<a name="l00624"></a>00624 {
+<a name="l00625"></a>00625     cpl_image * out_image ;
+<a name="l00626"></a>00626     <span class="keywordtype">int</span> i, j, npix, nrunning ;
+<a name="l00627"></a>00627     pixelvalue sum, sum2, mean, stdev, median1, median2, ratio ;
+<a name="l00628"></a>00628     pixelvalue * column1, * column2 ;
+<a name="l00629"></a>00629     <span class="keywordtype">int</span> lx1=0;
+<a name="l00630"></a>00630     <span class="keywordtype">int</span> ly1=0;
+<a name="l00631"></a>00631     <span class="keywordtype">int</span> lx2=0;
+<a name="l00632"></a>00632     <span class="keywordtype">int</span> ly2=0;
+<a name="l00633"></a>00633     <span class="keywordtype">int</span> lxr=0;
+<a name="l00634"></a>00634     <span class="keywordtype">int</span> lyr=0;
+<a name="l00635"></a>00635     <span class="keywordtype">float</span>* pi1data=NULL;
+<a name="l00636"></a>00636     <span class="keywordtype">float</span>* pi2data=NULL;
+<a name="l00637"></a>00637     <span class="keywordtype">float</span>* pirdata=NULL;
+<a name="l00638"></a>00638     <span class="keywordtype">float</span>* poutdata=NULL;
+<a name="l00639"></a>00639 
+<a name="l00640"></a>00640     <span class="keywordflow">if</span> ( im1 == NULL || im2 == NULL || res_image == NULL )
+<a name="l00641"></a>00641     {
+<a name="l00642"></a>00642         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"null image as input"</span>) ;
+<a name="l00643"></a>00643         <span class="keywordflow">return</span> NULL ;
+<a name="l00644"></a>00644     }
+<a name="l00645"></a>00645     lx1=cpl_image_get_size_x(im1);
+<a name="l00646"></a>00646     ly1=cpl_image_get_size_y(im1);
+<a name="l00647"></a>00647 
+<a name="l00648"></a>00648     lx2=cpl_image_get_size_x(im2);
+<a name="l00649"></a>00649     ly2=cpl_image_get_size_y(im2);
+<a name="l00650"></a>00650 
+<a name="l00651"></a>00651     lxr=cpl_image_get_size_x(res_image);
+<a name="l00652"></a>00652     lyr=cpl_image_get_size_y(res_image);
+<a name="l00653"></a>00653 
+<a name="l00654"></a>00654 
+<a name="l00655"></a>00655     pi1data=cpl_image_get_data_float(im1);
+<a name="l00656"></a>00656     pi2data=cpl_image_get_data_float(im2);
+<a name="l00657"></a>00657     pirdata=cpl_image_get_data_float(res_image);
+<a name="l00658"></a>00658 
+<a name="l00659"></a>00659     <span class="keywordflow">if</span> ( lx1 != lx2 || ly1 != ly2 ||
+<a name="l00660"></a>00660          lx2 != lxr || ly2 != lyr )
+<a name="l00661"></a>00661     {
+<a name="l00662"></a>00662         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"input images are not compatible in size"</span>) ;
+<a name="l00663"></a>00663         <span class="keywordflow">return</span> NULL ;
+<a name="l00664"></a>00664     }
+<a name="l00665"></a>00665 
+<a name="l00666"></a>00666     out_image = cpl_image_duplicate( im2 ) ;
+<a name="l00667"></a>00667     poutdata=cpl_image_get_data_float(out_image);
+<a name="l00668"></a>00668 
+<a name="l00669"></a>00669     <span class="comment">/*------------------------------------------------------------------------- </span>
+<a name="l00670"></a>00670 <span class="comment">     *  now we deal with a constant offset in every column. We assume that it </span>
+<a name="l00671"></a>00671 <span class="comment">        is due to redistribution of the flux. So we should divide the offset </span>
+<a name="l00672"></a>00672 <span class="comment">        out.  The ratio is derived from the medians of the contributions </span>
+<a name="l00673"></a>00673 <span class="comment">        rather than the means.</span>
+<a name="l00674"></a>00674 <span class="comment">     */</span>
+<a name="l00675"></a>00675 
+<a name="l00676"></a>00676     <span class="keywordflow">for</span> ( i = 0 ; i < lx2 ; i ++ ) <span class="comment">/* select a column */</span>
+<a name="l00677"></a>00677     {
+<a name="l00678"></a>00678         <span class="comment">/* statistics on columns */</span>
+<a name="l00679"></a>00679         sum  = 0.  ;
+<a name="l00680"></a>00680         sum2 = 0. ;
+<a name="l00681"></a>00681         npix = 0  ;
+<a name="l00682"></a>00682         <span class="keywordflow">for</span> ( j = 0 ; j < ly2 ; j ++ )
+<a name="l00683"></a>00683         {
+<a name="l00684"></a>00684             <span class="comment">/* first select only the good pixels */</span>
+<a name="l00685"></a>00685             <span class="keywordflow">if</span> ( isnan(pirdata[i + j*lxr]) )
+<a name="l00686"></a>00686             {
+<a name="l00687"></a>00687                 continue ;
+<a name="l00688"></a>00688             }
+<a name="l00689"></a>00689             sum  += pirdata[i + j*lxr] ;
+<a name="l00690"></a>00690             sum2 += pirdata[i + j*lxr] * 
+<a name="l00691"></a>00691                     pirdata[i + j*lxr] ; 
+<a name="l00692"></a>00692             npix ++ ;
+<a name="l00693"></a>00693         }
+<a name="l00694"></a>00694         <span class="keywordflow">if</span> ( npix <= 1 )
+<a name="l00695"></a>00695         {
+<a name="l00696"></a>00696             continue ;
+<a name="l00697"></a>00697         }
+<a name="l00698"></a>00698         <span class="keywordflow">else</span>
+<a name="l00699"></a>00699         {
+<a name="l00700"></a>00700             mean  = sum/(pixelvalue) npix ;
+<a name="l00701"></a>00701             <span class="keywordflow">if</span> ( (sum2 - sum * mean) < 0 )
+<a name="l00702"></a>00702             {
+<a name="l00703"></a>00703                 <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"variance is negative"</span>) ; 
+<a name="l00704"></a>00704                 continue ;
+<a name="l00705"></a>00705             }
+<a name="l00706"></a>00706             <span class="keywordflow">else</span>
+<a name="l00707"></a>00707             {
+<a name="l00708"></a>00708                 <span class="comment">/* 2 sigma */</span>
+<a name="l00709"></a>00709                 stdev = 2 * sqrt ( (sum2 - sum*mean)/(pixelvalue)(npix - 1) ) ;
+<a name="l00710"></a>00710             }
+<a name="l00711"></a>00711         }
+<a name="l00712"></a>00712 
+<a name="l00713"></a>00713         <span class="comment">/* do it only if the S/N is high enough */</span>
+<a name="l00714"></a>00714         <span class="keywordflow">if</span> ( fabs(mean)/stdev < 0.5 )
+<a name="l00715"></a>00715         {
+<a name="l00716"></a>00716             continue ;
+<a name="l00717"></a>00717         }
+<a name="l00718"></a>00718 
+<a name="l00719"></a>00719         <span class="comment">/* exclude everything > 2 sigma */</span>
+<a name="l00720"></a>00720         <span class="keywordflow">for</span> ( j = 0 ; j < lyr ; j ++ )
+<a name="l00721"></a>00721         {
+<a name="l00722"></a>00722             <span class="keywordflow">if</span> ( pirdata[i + j*lxr] < mean - stdev ||
+<a name="l00723"></a>00723                  pirdata[i + j*lxr] > mean + stdev )
+<a name="l00724"></a>00724             {
+<a name="l00725"></a>00725                 pirdata[i + j*lxr] = ZERO ;
+<a name="l00726"></a>00726             }
+<a name="l00727"></a>00727         } 
+<a name="l00728"></a>00728         
+<a name="l00729"></a>00729         <span class="comment">/* now deal with the offset */</span>
+<a name="l00730"></a>00730         median1 = 0. ;
+<a name="l00731"></a>00731         median2 = 0. ;
+<a name="l00732"></a>00732         nrunning = 0 ;
+<a name="l00733"></a>00733         <span class="comment">/* allocate memory for the column buffers */</span>
+<a name="l00734"></a>00734         column1 = (pixelvalue *) cpl_calloc ( ly1 , <span class="keyword">sizeof</span> (pixelvalue *) ) ;
+<a name="l00735"></a>00735         column2 = (pixelvalue *) cpl_calloc ( ly2 , <span class="keyword">sizeof</span> (pixelvalue *) ) ; 
+<a name="l00736"></a>00736 
+<a name="l00737"></a>00737         <span class="keywordflow">for</span> ( j = 0 ; j < lyr ; j++ ) <span class="comment">/* go through one column */</span>
+<a name="l00738"></a>00738         {
+<a name="l00739"></a>00739             <span class="keywordflow">if</span> ( isnan(pirdata[i + j*lxr]) )
+<a name="l00740"></a>00740             {
+<a name="l00741"></a>00741                 continue ;
+<a name="l00742"></a>00742             }
+<a name="l00743"></a>00743             <span class="keywordflow">if</span> ( isnan(pi1data[i+j*lx1]) || isnan(pi2data[i+j*lx2]) )
+<a name="l00744"></a>00744             {
+<a name="l00745"></a>00745                 continue ;
+<a name="l00746"></a>00746             }
+<a name="l00747"></a>00747         column1[nrunning] = pi1data[i + j*lx1] ;
+<a name="l00748"></a>00748             column2[nrunning] = pi2data[i + j*lx2] ;
+<a name="l00749"></a>00749             nrunning ++ ;
+<a name="l00750"></a>00750         }
+<a name="l00751"></a>00751 
+<a name="l00752"></a>00752         <span class="comment">/* change the second input image only if there are more then </span>
+<a name="l00753"></a>00753 <span class="comment">           10 % good pixels in a column */</span>
+<a name="l00754"></a>00754         <span class="keywordflow">if</span> ( nrunning > 0.1*lyr )
+<a name="l00755"></a>00755         {
+<a name="l00756"></a>00756             <span class="comment">/* --------------------------------------------------------------</span>
+<a name="l00757"></a>00757 <span class="comment">             * determine the medians of the columns of both images and compute </span>
+<a name="l00758"></a>00758 <span class="comment">               the ratio, the columns of the second input image are multiplied </span>
+<a name="l00759"></a>00759 <span class="comment">               by this ratio to adjust the column offsets. </span>
+<a name="l00760"></a>00760 <span class="comment">             */</span>
+<a name="l00761"></a>00761             median2 = sinfo_new_median( column2, nrunning ) ;
+<a name="l00762"></a>00762             <span class="keywordflow">if</span> ( median2 != 0. )
+<a name="l00763"></a>00763             {
+<a name="l00764"></a>00764                 median1 = sinfo_new_median( column1, nrunning ) ;
+<a name="l00765"></a>00765                 ratio = median1 / median2 ;
+<a name="l00766"></a>00766                 <span class="keywordflow">if</span> ( ratio > 0 )
+<a name="l00767"></a>00767                 {
+<a name="l00768"></a>00768                     <span class="keywordflow">for</span> ( j = 0 ; j < ly2 ; j++ ) <span class="comment">/* go through one column */</span>
+<a name="l00769"></a>00769                     {
+<a name="l00770"></a>00770                         <span class="keywordflow">if</span> ( !isnan(pi2data[i + j*lx2]) )
+<a name="l00771"></a>00771                         {
+<a name="l00772"></a>00772                             poutdata[i + j*lx2] = pi2data[i + j*lx2] * ratio ;
+<a name="l00773"></a>00773                         }
+<a name="l00774"></a>00774                         <span class="keywordflow">else</span>
+<a name="l00775"></a>00775                         {
+<a name="l00776"></a>00776                             poutdata[i + j*lx2] = ZERO ;
+<a name="l00777"></a>00777                         }
+<a name="l00778"></a>00778                     }
+<a name="l00779"></a>00779                 }
+<a name="l00780"></a>00780             }
+<a name="l00781"></a>00781         }   
+<a name="l00782"></a>00782         cpl_free ( column1 ) ;
+<a name="l00783"></a>00783         cpl_free ( column2 ) ;
+<a name="l00784"></a>00784     }
+<a name="l00785"></a>00785 
+<a name="l00786"></a>00786     <span class="comment">/* now compute the final residual image */</span>
+<a name="l00787"></a>00787     <span class="keywordflow">for</span> ( i = 0 ; i < (int) lx1*ly1 ; i ++ )
+<a name="l00788"></a>00788     {
+<a name="l00789"></a>00789         <span class="keywordflow">if</span> ( isnan(pi1data[i]) || isnan(poutdata[i]) )
+<a name="l00790"></a>00790         {
+<a name="l00791"></a>00791             pirdata[i] = ZERO ;
+<a name="l00792"></a>00792         }   
+<a name="l00793"></a>00793         <span class="keywordflow">else</span>
+<a name="l00794"></a>00794         {
+<a name="l00795"></a>00795             pirdata[i] = pi1data[i] - poutdata[i] ;
+<a name="l00796"></a>00796         }
+<a name="l00797"></a>00797     }
+<a name="l00798"></a>00798    
+<a name="l00799"></a>00799     <span class="keywordflow">return</span> out_image ;
+<a name="l00800"></a>00800 }
+<a name="l00801"></a>00801 
+<a name="l00802"></a>00802 
+<a name="l00812"></a>00812 cpl_image * 
+<a name="l00813"></a>00813 sinfo_new_remove_residual_tilt ( cpl_image * im2, cpl_image * res_image )
+<a name="l00814"></a>00814 {
+<a name="l00815"></a>00815     cpl_image * out_image ;
+<a name="l00816"></a>00816     cpl_image * residual  ;
+<a name="l00817"></a>00817     <span class="keywordtype">int</span> i, j, npix ;
+<a name="l00818"></a>00818     pixelvalue a, b, sum, sumx, sumy, sumc, sum2, mean, stdev ;
+<a name="l00819"></a>00819     <span class="keywordtype">int</span> lx2=0;
+<a name="l00820"></a>00820     <span class="keywordtype">int</span> ly2=0;
+<a name="l00821"></a>00821     <span class="keywordtype">int</span> rlx=0;
+<a name="l00822"></a>00822     <span class="keywordtype">int</span> rly=0;
+<a name="l00823"></a>00823     <span class="keywordtype">float</span>* pi2data=NULL;
+<a name="l00824"></a>00824     <span class="keywordtype">float</span>* pirdata=NULL;
+<a name="l00825"></a>00825     <span class="keywordtype">float</span>* poutdata=NULL;
+<a name="l00826"></a>00826     <span class="keywordtype">float</span>* ptmpdata=NULL;
+<a name="l00827"></a>00827 
+<a name="l00828"></a>00828 
+<a name="l00829"></a>00829 
+<a name="l00830"></a>00830 
+<a name="l00831"></a>00831     <span class="keywordflow">if</span> ( im2 == NULL || res_image == NULL )
+<a name="l00832"></a>00832     {
+<a name="l00833"></a>00833         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"null image as input"</span>) ;
+<a name="l00834"></a>00834         <span class="keywordflow">return</span> NULL ;
+<a name="l00835"></a>00835     }
+<a name="l00836"></a>00836     lx2=cpl_image_get_size_x(im2);
+<a name="l00837"></a>00837     ly2=cpl_image_get_size_y(im2);
+<a name="l00838"></a>00838     rlx=cpl_image_get_size_x(res_image);
+<a name="l00839"></a>00839     rly=cpl_image_get_size_y(res_image);
+<a name="l00840"></a>00840     pi2data=cpl_image_get_data_float(im2);
+<a name="l00841"></a>00841     pirdata=cpl_image_get_data_float(res_image);
+<a name="l00842"></a>00842 
+<a name="l00843"></a>00843     <span class="keywordflow">if</span> ( lx2 != rlx || ly2 != rly )
+<a name="l00844"></a>00844     {
+<a name="l00845"></a>00845         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"input images are not compatible in size"</span>) ;
+<a name="l00846"></a>00846         <span class="keywordflow">return</span> NULL ;
+<a name="l00847"></a>00847     }
+<a name="l00848"></a>00848 
+<a name="l00849"></a>00849     out_image = cpl_image_duplicate( im2 ) ;
+<a name="l00850"></a>00850     residual  = cpl_image_duplicate( res_image ) ;
+<a name="l00851"></a>00851     poutdata=cpl_image_get_data_float(out_image);
+<a name="l00852"></a>00852     ptmpdata=cpl_image_get_data_float(residual);
+<a name="l00853"></a>00853 
+<a name="l00854"></a>00854     <span class="keywordflow">for</span> ( i = 0 ; i < lx2; i++ ) <span class="comment">/* select one column */</span>
+<a name="l00855"></a>00855     {
+<a name="l00856"></a>00856         sum  = 0. ;
+<a name="l00857"></a>00857         sum2 = 0. ;
+<a name="l00858"></a>00858         npix = 0  ;
+<a name="l00859"></a>00859         <span class="keywordflow">for</span> ( j = 0 ; j < ly2 ; j++ ) 
+<a name="l00860"></a>00860         {
+<a name="l00861"></a>00861             <span class="comment">/* first select good pixels and derive the mean </span>
+<a name="l00862"></a>00862 <span class="comment">               and sigma of each column */</span>
+<a name="l00863"></a>00863             <span class="keywordflow">if</span> ( isnan(pirdata[i + j*rlx]) )
+<a name="l00864"></a>00864             {
+<a name="l00865"></a>00865                 continue ;
+<a name="l00866"></a>00866             }
+<a name="l00867"></a>00867             sum  += pirdata[i + j*rlx] ;
+<a name="l00868"></a>00868             sum2 += pirdata[i + j*rlx] *
+<a name="l00869"></a>00869                     pirdata[i + j*rlx] ;
+<a name="l00870"></a>00870             npix ++ ;
+<a name="l00871"></a>00871         }
+<a name="l00872"></a>00872         
+<a name="l00873"></a>00873         <span class="keywordflow">if</span> ( npix <= 1 )
+<a name="l00874"></a>00874         {
+<a name="l00875"></a>00875             continue ;
+<a name="l00876"></a>00876         }
+<a name="l00877"></a>00877         <span class="keywordflow">else</span>
+<a name="l00878"></a>00878         {
+<a name="l00879"></a>00879             mean  = sum / (pixelvalue) npix ;
+<a name="l00880"></a>00880             stdev = 1.5 * sqrt( (sum2 - sum*mean) / (pixelvalue)(npix - 1) ) ;
+<a name="l00881"></a>00881         }
+<a name="l00882"></a>00882  
+<a name="l00883"></a>00883         <span class="comment">/* exclude everything > 1.5 sigma */</span>
+<a name="l00884"></a>00884         <span class="keywordflow">for</span> ( j = 0 ; j < ly2 ; j++ )
+<a name="l00885"></a>00885         {
+<a name="l00886"></a>00886             <span class="keywordflow">if</span> ( pirdata[i + j*rlx] < mean - stdev ||
+<a name="l00887"></a>00887                  pirdata[i + j*rlx] > mean + stdev )
+<a name="l00888"></a>00888             {
+<a name="l00889"></a>00889                 pirdata[i + j*rlx] = ZERO ;
+<a name="l00890"></a>00890             }
+<a name="l00891"></a>00891         }
+<a name="l00892"></a>00892 
+<a name="l00893"></a>00893         <span class="comment">/* now determine the tilt, see function sinfo_removeRegionalTilt </span>
+<a name="l00894"></a>00894 <span class="comment">           for explanation */</span>
+<a name="l00895"></a>00895         sumy = 0. ;                   <span class="comment">/* yi   */</span>
+<a name="l00896"></a>00896         sumc = 0. ;                   <span class="comment">/* xiyi */</span>
+<a name="l00897"></a>00897         sumx = 0. ;                   <span class="comment">/* xi   */</span>
+<a name="l00898"></a>00898         sum2 = 0. ;                   <span class="comment">/* xi^2 */</span>
+<a name="l00899"></a>00899         npix = 0  ;  
+<a name="l00900"></a>00900           
+<a name="l00901"></a>00901         <span class="keywordflow">for</span> ( j = 0 ; j < rly ; j ++ ) 
+<a name="l00902"></a>00902         {
+<a name="l00903"></a>00903             <span class="keywordflow">if</span> ( isnan(pirdata[i + j*rlx]) )
+<a name="l00904"></a>00904             {
+<a name="l00905"></a>00905                 continue ;
+<a name="l00906"></a>00906             }
+<a name="l00907"></a>00907             sumy +=  pirdata[i + j*rlx] ;
+<a name="l00908"></a>00908             sumc += (pirdata[i + j*rlx]) * j ;
+<a name="l00909"></a>00909             sum2 += j*j ;
+<a name="l00910"></a>00910             sumx += j   ;
+<a name="l00911"></a>00911             npix ++     ;
+<a name="l00912"></a>00912         }
+<a name="l00913"></a>00913         <span class="keywordflow">if</span> ( npix > 2 && fabs(sum2 - sumx*sumx/npix) >= 1e-6 ) 
+<a name="l00914"></a>00914         {
+<a name="l00915"></a>00915             a = ( sumc - sumx*sumy/npix ) / ( sum2 - sumx*sumx/npix ) ;
+<a name="l00916"></a>00916             b = ( sumy - a*sumx ) / npix ;
+<a name="l00917"></a>00917         } 
+<a name="l00918"></a>00918         <span class="keywordflow">else</span>
+<a name="l00919"></a>00919         {
+<a name="l00920"></a>00920             a = ZERO ;
+<a name="l00921"></a>00921             b = ZERO ;
+<a name="l00922"></a>00922         }
+<a name="l00923"></a>00923 
+<a name="l00924"></a>00924         <span class="comment">/*-------------------------------------------------------------------</span>
+<a name="l00925"></a>00925 <span class="comment">         * now correct the second input image im2 and the res_image.</span>
+<a name="l00926"></a>00926 <span class="comment">         */</span> 
+<a name="l00927"></a>00927 
+<a name="l00928"></a>00928         <span class="keywordflow">if</span> ( !isnan(a) && !isnan(b) && fabs(a) < 1e8 && fabs(b) < 1e8 )
+<a name="l00929"></a>00929         {
+<a name="l00930"></a>00930             <span class="keywordflow">for</span> ( j = 0 ; j < ly2 ; j ++ ) <span class="comment">/* the same column */</span>
+<a name="l00931"></a>00931             {
+<a name="l00932"></a>00932                 <span class="keywordflow">if</span> ( !isnan(poutdata[i+j*lx2]) )
+<a name="l00933"></a>00933                 {
+<a name="l00934"></a>00934                     poutdata[i + j*lx2] += a*j+b ;        
+<a name="l00935"></a>00935                     pirdata[i + j*lx2] = ptmpdata[i + j*lx2] -(a*j+b) ;
+<a name="l00936"></a>00936                 }
+<a name="l00937"></a>00937             }
+<a name="l00938"></a>00938         }
+<a name="l00939"></a>00939     }
+<a name="l00940"></a>00940 
+<a name="l00941"></a>00941     cpl_image_delete (residual) ;
+<a name="l00942"></a>00942 
+<a name="l00943"></a>00943     <span class="keywordflow">return</span> out_image ;
+<a name="l00944"></a>00944 }
+<a name="l00945"></a>00945 
+<a name="l00946"></a>00946 
+<a name="l00957"></a>00957 cpl_image * 
+<a name="l00958"></a>00958 sinfo_new_remove_residual_offset( cpl_image * im2, cpl_image * res_image )
+<a name="l00959"></a>00959 {
+<a name="l00960"></a>00960     cpl_image * out_image ;
+<a name="l00961"></a>00961     <span class="keywordtype">int</span> i, j, npix ;
+<a name="l00962"></a>00962     pixelvalue res_median ;
+<a name="l00963"></a>00963     pixelvalue * column ;
+<a name="l00964"></a>00964     <span class="keywordtype">int</span> lx2=0;
+<a name="l00965"></a>00965     <span class="keywordtype">int</span> ly2=0;
+<a name="l00966"></a>00966     <span class="keywordtype">int</span> rlx=0;
+<a name="l00967"></a>00967     <span class="keywordtype">int</span> rly=0;
+<a name="l00968"></a>00968     <span class="keywordtype">int</span> olx=0;
+<a name="l00969"></a>00969     <span class="keywordtype">int</span> oly=0;
+<a name="l00970"></a>00970     <span class="keywordtype">float</span>* pi2data=NULL;
+<a name="l00971"></a>00971     <span class="keywordtype">float</span>* pirdata=NULL;
+<a name="l00972"></a>00972     <span class="keywordtype">float</span>* poudata=NULL;
+<a name="l00973"></a>00973 
+<a name="l00974"></a>00974 
+<a name="l00975"></a>00975     <span class="keywordflow">if</span> ( im2 == NULL || res_image == NULL )
+<a name="l00976"></a>00976     {
+<a name="l00977"></a>00977         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"null image as input"</span>) ;
+<a name="l00978"></a>00978         <span class="keywordflow">return</span> NULL ;
+<a name="l00979"></a>00979     }
+<a name="l00980"></a>00980     lx2=cpl_image_get_size_x(im2);
+<a name="l00981"></a>00981     ly2=cpl_image_get_size_y(im2);
+<a name="l00982"></a>00982     rlx=cpl_image_get_size_x(res_image);
+<a name="l00983"></a>00983     rly=cpl_image_get_size_y(res_image);
+<a name="l00984"></a>00984     pi2data=cpl_image_get_data_float(im2);
+<a name="l00985"></a>00985     pirdata=cpl_image_get_data_float(res_image);
+<a name="l00986"></a>00986 
+<a name="l00987"></a>00987 
+<a name="l00988"></a>00988     <span class="keywordflow">if</span> ( lx2 != rlx || ly2 != rly )
+<a name="l00989"></a>00989     {
+<a name="l00990"></a>00990         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"input images are not compatible in size"</span>) ;
+<a name="l00991"></a>00991         <span class="keywordflow">return</span> NULL ;
+<a name="l00992"></a>00992     }
+<a name="l00993"></a>00993 
+<a name="l00994"></a>00994     out_image = cpl_image_duplicate( im2 ) ;
+<a name="l00995"></a>00995     poudata=cpl_image_get_data_float(res_image);
+<a name="l00996"></a>00996     olx=cpl_image_get_size_x(res_image);
+<a name="l00997"></a>00997     oly=cpl_image_get_size_y(res_image);
+<a name="l00998"></a>00998 
+<a name="l00999"></a>00999     column = (pixelvalue *) cpl_calloc ( ly2 , <span class="keyword">sizeof</span> (pixelvalue *) ) ;
+<a name="l01000"></a>01000     
+<a name="l01001"></a>01001     <span class="keywordflow">for</span> ( i = 0 ; i < lx2 ; i++ ) <span class="comment">/* select one column */</span>
+<a name="l01002"></a>01002     {
+<a name="l01003"></a>01003         npix = 0  ;
+<a name="l01004"></a>01004     <span class="keywordflow">for</span> (j=0;j<ly2;j++)
+<a name="l01005"></a>01005         column[j]=0;
+<a name="l01006"></a>01006 
+<a name="l01007"></a>01007         <span class="keywordflow">for</span> ( j = 0 ; j < rly ; j++ ) <span class="comment">/* go through one column */</span>
+<a name="l01008"></a>01008         {
+<a name="l01009"></a>01009             <span class="keywordflow">if</span> ( isnan(pirdata[i + j*rlx]) )
+<a name="l01010"></a>01010             {
+<a name="l01011"></a>01011                 continue ;
+<a name="l01012"></a>01012             }
+<a name="l01013"></a>01013    
+<a name="l01014"></a>01014             column[npix] = pirdata[i + j*rlx] ;
+<a name="l01015"></a>01015             npix ++ ;
+<a name="l01016"></a>01016         }
+<a name="l01017"></a>01017             
+<a name="l01018"></a>01018         <span class="comment">/* determine the sinfo_median of a column of the residual image */</span>
+<a name="l01019"></a>01019         <span class="keywordflow">if</span> ( npix > 0.1 * rly )
+<a name="l01020"></a>01020         {
+<a name="l01021"></a>01021             res_median = sinfo_new_median( column, npix ) ;
+<a name="l01022"></a>01022         }
+<a name="l01023"></a>01023         <span class="keywordflow">else</span>
+<a name="l01024"></a>01024         {
+<a name="l01025"></a>01025             continue ;
+<a name="l01026"></a>01026         }
+<a name="l01027"></a>01027         
+<a name="l01028"></a>01028         <span class="keywordflow">for</span> ( j = 0 ; j < ly2 ; j++ ) <span class="comment">/* go through one column */</span>
+<a name="l01029"></a>01029         {
+<a name="l01030"></a>01030             <span class="keywordflow">if</span> ( !isnan(pi2data[i+j*lx2]))
+<a name="l01031"></a>01031             {
+<a name="l01032"></a>01032                 poudata[i + j*lx2] = pi2data[i + j*lx2] + res_median ;
+<a name="l01033"></a>01033             }
+<a name="l01034"></a>01034             <span class="keywordflow">else</span>
+<a name="l01035"></a>01035             {
+<a name="l01036"></a>01036                 poudata[i + j*lx2] = ZERO ;
+<a name="l01037"></a>01037             }
+<a name="l01038"></a>01038             <span class="keywordflow">if</span> ( !isnan(pirdata[i + j*rlx]) )
+<a name="l01039"></a>01039             {
+<a name="l01040"></a>01040                 pirdata[i + j*rlx] -= res_median ;
+<a name="l01041"></a>01041             }
+<a name="l01042"></a>01042         }
+<a name="l01043"></a>01043     }
+<a name="l01044"></a>01044     cpl_free ( column ) ;
+<a name="l01045"></a>01045     <span class="keywordflow">return</span> out_image ;
+<a name="l01046"></a>01046 }
+<a name="l01048"></a>01048 <span class="comment">/*___oOo___*/</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__merge_8h_source.html b/html/sinfo__merge_8h_source.html
new file mode 100644
index 0000000..d72a73f
--- /dev/null
+++ b/html/sinfo__merge_8h_source.html
@@ -0,0 +1,93 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_merge.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_merge.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#ifndef SINFO_MERGE_H</span>
+<a name="l00002"></a>00002 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_MERGE_H</span>
+<a name="l00003"></a>00003 <span class="preprocessor"></span><span class="comment">/*</span>
+<a name="l00004"></a>00004 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00005"></a>00005 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00006"></a>00006 <span class="comment"> *</span>
+<a name="l00007"></a>00007 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00008"></a>00008 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00009"></a>00009 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00010"></a>00010 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00011"></a>00011 <span class="comment"> *</span>
+<a name="l00012"></a>00012 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00013"></a>00013 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00014"></a>00014 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00015"></a>00015 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00016"></a>00016 <span class="comment"> *</span>
+<a name="l00017"></a>00017 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00018"></a>00018 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00019"></a>00019 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00020"></a>00020 <span class="comment"> */</span>
+<a name="l00021"></a>00021 <span class="comment">/*******************************************************************************</span>
+<a name="l00022"></a>00022 <span class="comment">* E.S.O. - VLT project</span>
+<a name="l00023"></a>00023 <span class="comment">*</span>
+<a name="l00024"></a>00024 <span class="comment">* "@(#) $Id: sinfo_merge.h,v 1.4 2007/06/06 07:10:45 amodigli Exp $"</span>
+<a name="l00025"></a>00025 <span class="comment">*</span>
+<a name="l00026"></a>00026 <span class="comment">* who       when      what</span>
+<a name="l00027"></a>00027 <span class="comment">* --------  --------  ----------------------------------------------</span>
+<a name="l00028"></a>00028 <span class="comment">* schreib  04/07/00  created</span>
+<a name="l00029"></a>00029 <span class="comment">*/</span>
+<a name="l00030"></a>00030 
+<a name="l00031"></a>00031 <span class="comment">/************************************************************************</span>
+<a name="l00032"></a>00032 <span class="comment"> * sinfo_merge.h</span>
+<a name="l00033"></a>00033 <span class="comment"> * merges the rows of two image data frames into one frame with doubled</span>
+<a name="l00034"></a>00034 <span class="comment"> * column length</span>
+<a name="l00035"></a>00035 <span class="comment"> *----------------------------------------------------------------------</span>
+<a name="l00036"></a>00036 <span class="comment"> */</span>
+<a name="l00037"></a>00037 
+<a name="l00038"></a>00038 <span class="comment">/*</span>
+<a name="l00039"></a>00039 <span class="comment"> * header files</span>
+<a name="l00040"></a>00040 <span class="comment"> */</span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include "sinfo_recipes.h"</span>
+<a name="l00044"></a>00044 
+<a name="l00045"></a>00045 <span class="comment">/*</span>
+<a name="l00046"></a>00046 <span class="comment"> * function prototypes</span>
+<a name="l00047"></a>00047 <span class="comment"> */</span>
+<a name="l00048"></a>00048 
+<a name="l00061"></a>00061 cpl_image * 
+<a name="l00062"></a>00062 sinfo_sinfo_merge_images (cpl_image * im1, 
+<a name="l00063"></a>00063                   cpl_image * im2,
+<a name="l00064"></a>00064                   cpl_image * res_image ) ;
+<a name="l00065"></a>00065 
+<a name="l00078"></a>00078 cpl_image * 
+<a name="l00079"></a>00079 sinfo_new_remove_general_offset(cpl_image * im1, 
+<a name="l00080"></a>00080                       cpl_image * im2, 
+<a name="l00081"></a>00081                       cpl_image * res_image,
+<a name="l00082"></a>00082                       <span class="keywordtype">int</span> n ) ;
+<a name="l00083"></a>00083 
+<a name="l00094"></a>00094 cpl_image * 
+<a name="l00095"></a>00095 sinfo_new_remove_regional_tilt (cpl_image * im1,
+<a name="l00096"></a>00096               cpl_image * im2, 
+<a name="l00097"></a>00097               cpl_image * res_image ) ;
+<a name="l00098"></a>00098 
+<a name="l00110"></a>00110 cpl_image * sinfo_new_remove_column_offset (cpl_image * im1,
+<a name="l00111"></a>00111                       cpl_image * im2,
+<a name="l00112"></a>00112                       cpl_image * res_image );
+<a name="l00113"></a>00113 
+<a name="l00123"></a>00123 cpl_image * 
+<a name="l00124"></a>00124 sinfo_new_remove_residual_tilt (cpl_image * im2,cpl_image * res_image ) ;
+<a name="l00125"></a>00125 
+<a name="l00126"></a>00126 
+<a name="l00137"></a>00137 cpl_image * 
+<a name="l00138"></a>00138 sinfo_new_remove_residual_offset(cpl_image * im2,cpl_image * res_image);
+<a name="l00139"></a>00139 
+<a name="l00140"></a>00140 
+<a name="l00141"></a>00141 <span class="preprocessor">#endif </span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__msg_8c_source.html b/html/sinfo__msg_8c_source.html
new file mode 100644
index 0000000..29aa342
--- /dev/null
+++ b/html/sinfo__msg_8c_source.html
@@ -0,0 +1,247 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_msg.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_msg.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*                                                                          *</span>
+<a name="l00002"></a>00002 <span class="comment"> *   This file is part of the ESO SINFO Pipeline                            *</span>
+<a name="l00003"></a>00003 <span class="comment"> *   Copyright (C) 2004,2005 European Southern Observatory                  *</span>
+<a name="l00004"></a>00004 <span class="comment"> *                                                                          *</span>
+<a name="l00005"></a>00005 <span class="comment"> *   This library is free software; you can redistribute it and/or modify   *</span>
+<a name="l00006"></a>00006 <span class="comment"> *   it under the terms of the GNU General Public License as published by   *</span>
+<a name="l00007"></a>00007 <span class="comment"> *   the Free Software Foundation; either version 2 of the License, or      *</span>
+<a name="l00008"></a>00008 <span class="comment"> *   (at your option) any later version.                                    *</span>
+<a name="l00009"></a>00009 <span class="comment"> *                                                                          *</span>
+<a name="l00010"></a>00010 <span class="comment"> *   This program is distributed in the hope that it will be useful,        *</span>
+<a name="l00011"></a>00011 <span class="comment"> *   but WITHOUT ANY WARRANTY; without even the implied warranty of         *</span>
+<a name="l00012"></a>00012 <span class="comment"> *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *</span>
+<a name="l00013"></a>00013 <span class="comment"> *   GNU General Public License for more details.                           *</span>
+<a name="l00014"></a>00014 <span class="comment"> *                                                                          *</span>
+<a name="l00015"></a>00015 <span class="comment"> *   You should have received a copy of the GNU General Public License      *</span>
+<a name="l00016"></a>00016 <span class="comment"> *   along with this program; if not, write to the Free Software            *</span>
+<a name="l00017"></a>00017 <span class="comment"> *   Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA   *</span>
+<a name="l00018"></a>00018 <span class="comment"> *                                                                          */</span>
+<a name="l00019"></a>00019 
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2008/02/12 14:57:39 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.7 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> */</span>
+<a name="l00026"></a>00026 
+<a name="l00027"></a>00027 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00029"></a>00029 <span class="preprocessor">#endif</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span>
+<a name="l00031"></a>00031 <span class="preprocessor">#include <sinfo_msg.h></span>
+<a name="l00032"></a>00032 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include <stdarg.h></span>
+<a name="l00034"></a>00034 <span class="preprocessor">#include <stdio.h></span>
+<a name="l00035"></a>00035 
+<a name="l00037"></a>00037 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00050"></a>00050 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00051"></a>00051 
+<a name="l00052"></a>00052 <span class="preprocessor">#define DEBUG_CALLER 0  </span><span class="comment">/* Define whether to check consistency of </span>
+<a name="l00053"></a>00053 <span class="comment">                           msg_louder/softer calls */</span>
+<a name="l00054"></a>00054 <span class="comment">/* #define DEBUG_CALLER */</span>
+<a name="l00055"></a>00055 
+<a name="l00056"></a>00056 <span class="preprocessor">#define MAXLEVEL 256</span>
+<a name="l00057"></a>00057 <span class="preprocessor"></span><span class="preprocessor">#define MAXSTRINGLENGTH 1000</span>
+<a name="l00058"></a>00058 <span class="preprocessor"></span>
+<a name="l00059"></a>00059 <span class="keyword">static</span> <span class="keywordtype">int</span> level = 0;  <span class="comment">/* Current message & indentation level </span>
+<a name="l00060"></a>00060 <span class="comment">                          from 0 to MAXLEVEL-1.</span>
+<a name="l00061"></a>00061 <span class="comment">            0 is the most verbose level. */</span>
+<a name="l00062"></a>00062 <span class="keyword">static</span> <span class="keywordtype">int</span> outlevel = -1; <span class="comment">/* Only print message if level is </span>
+<a name="l00063"></a>00063 <span class="comment">                             in {0, 1, ..., outlevel}.</span>
+<a name="l00064"></a>00064 <span class="comment">             Always print if outlevel = - 1 */</span>
+<a name="l00065"></a>00065 <span class="preprocessor">#ifdef DEBUG_CALLER</span>
+<a name="l00066"></a>00066 <span class="preprocessor"></span><span class="keyword">const</span> <span class="keywordtype">char</span> *sinfo_callers[MAXLEVEL]; <span class="comment">/* Check the consistency of </span>
+<a name="l00067"></a>00067 <span class="comment">                                         calls to softer/louder  */</span>
+<a name="l00068"></a>00068 <span class="preprocessor">#endif</span>
+<a name="l00069"></a>00069 <span class="preprocessor"></span>
+<a name="l00070"></a>00070 <span class="keyword">static</span> <span class="keywordtype">char</span> printbuffer[MAXSTRINGLENGTH]; <span class="comment">/* Used to pass variable argument </span>
+<a name="l00071"></a>00071 <span class="comment">                                             list to cpl_msg_info() */</span>
+<a name="l00072"></a>00072 
+<a name="l00073"></a>00073 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> *domain = <span class="stringliteral">"Undefined domain"</span>;
+<a name="l00074"></a>00074                                      <span class="comment">/* This is to support getting the </span>
+<a name="l00075"></a>00075 <span class="comment">                                        current domain </span>
+<a name="l00076"></a>00076 <span class="comment">                      * which is currently not available in CPL</span>
+<a name="l00077"></a>00077 <span class="comment">                      */</span>
+<a name="l00078"></a>00078 <span class="keyword">static</span> <span class="keywordtype">int</span> initialized = FALSE;
+<a name="l00079"></a>00079 
+<a name="l00080"></a>00080 <span class="keyword">static</span> <span class="keywordtype">int</span> number_of_warnings = 0;     <span class="comment">/* Coun't the number of warnings since </span>
+<a name="l00081"></a>00081 <span class="comment">                                          initialization */</span>
+<a name="l00082"></a>00082 
+<a name="l00083"></a>00083 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00100"></a>00100 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00101"></a><a class="code" href="group__sinfo__msg.html#ga639b5d352f0518db6cc346c0737484cc">00101</a> <span class="keywordtype">void</span> <a class="code" href="group__sinfo__msg.html#ga639b5d352f0518db6cc346c0737484cc" title="Initialize messaging.">sinfo_msg_init</a>(<span class="keywordtype">int</span> olevel, <span class="keyword">const</span> <span class="keywordtype">char</span> *dom)
+<a name="l00102"></a>00102 {
+<a name="l00103"></a>00103     <span class="comment">/* Initialize per recipe: */</span>
+<a name="l00104"></a>00104     number_of_warnings = 0;
+<a name="l00105"></a>00105         
+<a name="l00106"></a>00106     <span class="keywordflow">if</span> (!initialized)
+<a name="l00107"></a>00107     {
+<a name="l00108"></a>00108         <span class="comment">/* Initialize once: */</span>
+<a name="l00109"></a>00109         outlevel = olevel;
+<a name="l00110"></a>00110 
+<a name="l00111"></a>00111         cpl_msg_set_indentation(2);
+<a name="l00112"></a>00112         
+<a name="l00113"></a>00113         <span class="comment">/*  CPL message format is</span>
+<a name="l00114"></a>00114 <span class="comment">         *  [Time][Verbosity][domain][component] message</span>
+<a name="l00115"></a>00115 <span class="comment">         *</span>
+<a name="l00116"></a>00116 <span class="comment">         *  Don't show the (variable length and wildly</span>
+<a name="l00117"></a>00117 <span class="comment">         *  fluctuating) component. It interferes with</span>
+<a name="l00118"></a>00118 <span class="comment">         *  indentation. The component is available anyway</span>
+<a name="l00119"></a>00119 <span class="comment">         *  on CPL_MSG_DEBUG level.</span>
+<a name="l00120"></a>00120 <span class="comment">         */</span>
+<a name="l00121"></a>00121         cpl_msg_set_time_on();
+<a name="l00122"></a>00122         <a class="code" href="group__sinfo__msg.html#ga5671e5e7722c35d9d174772c80013ad5" title="Set message domain.">sinfo_msg_set_domain</a>(dom);
+<a name="l00123"></a>00123         cpl_msg_set_domain_on();
+<a name="l00124"></a>00124         cpl_msg_set_component_off();
+<a name="l00125"></a>00125 
+<a name="l00126"></a>00126         initialized = TRUE;
+<a name="l00127"></a>00127     }
+<a name="l00128"></a>00128 }
+<a name="l00129"></a>00129 
+<a name="l00130"></a>00130 
+<a name="l00131"></a>00131 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00138"></a>00138 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00139"></a><a class="code" href="group__sinfo__msg.html#gad9c8f46542015d0c93094c337a557d5e">00139</a> <span class="keywordtype">void</span> <a class="code" href="group__sinfo__msg.html#gad9c8f46542015d0c93094c337a557d5e" title="Set output level.">sinfo_msg_set_level</a>(<span class="keywordtype">int</span> olevel) 
+<a name="l00140"></a>00140 {
+<a name="l00141"></a>00141     outlevel = olevel; 
+<a name="l00142"></a>00142 } 
+<a name="l00143"></a>00143 
+<a name="l00144"></a>00144 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00152"></a>00152 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00153"></a><a class="code" href="group__sinfo__msg.html#gae0f3e727182610d92efdb755f1da6788">00153</a> <span class="keywordtype">void</span> <a class="code" href="group__sinfo__msg.html#gae0f3e727182610d92efdb755f1da6788" title="Decrease message level.">sinfo_msg_softer_macro</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *fctid)
+<a name="l00154"></a>00154 {
+<a name="l00155"></a>00155     <span class="keywordflow">if</span> (level + 1 < MAXLEVEL)
+<a name="l00156"></a>00156     {
+<a name="l00157"></a>00157         level++;
+<a name="l00158"></a>00158         cpl_msg_indent_more();
+<a name="l00159"></a>00159 <span class="preprocessor">#if DEBUG_CALLER</span>
+<a name="l00160"></a>00160 <span class="preprocessor"></span>        sinfo_callers[level] = fctid;
+<a name="l00161"></a>00161 <span class="preprocessor">#else</span>
+<a name="l00162"></a>00162 <span class="preprocessor"></span>        fctid = fctid; <span class="comment">/* Satisfy compiler */</span>
+<a name="l00163"></a>00163 <span class="preprocessor">#endif</span>
+<a name="l00164"></a>00164 <span class="preprocessor"></span>        }
+<a name="l00165"></a>00165 }
+<a name="l00166"></a>00166 
+<a name="l00167"></a>00167 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00175"></a>00175 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00176"></a><a class="code" href="group__sinfo__msg.html#ga38ac31ae7cb0ce5c792486fd3c9478e6">00176</a> <span class="keywordtype">void</span> <a class="code" href="group__sinfo__msg.html#ga38ac31ae7cb0ce5c792486fd3c9478e6" title="Increase message level.">sinfo_msg_louder_macro</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *fctid)
+<a name="l00177"></a>00177 {
+<a name="l00178"></a>00178     <span class="keywordflow">if</span> (level == 0)
+<a name="l00179"></a>00179     {
+<a name="l00180"></a>00180         <span class="comment">/* 0 is the loudest, ignore request */</span>
+<a name="l00181"></a>00181         <span class="keywordflow">return</span>;
+<a name="l00182"></a>00182     }
+<a name="l00183"></a>00183     
+<a name="l00184"></a>00184     <span class="comment">/* Only make louder, if called from the same function which called</span>
+<a name="l00185"></a>00185 <span class="comment">       sinfo_msg_softer. (disable check if level is more than MAXLEVEL)</span>
+<a name="l00186"></a>00186 <span class="comment">    */</span>
+<a name="l00187"></a>00187 <span class="preprocessor">#if DEBUG_CALLER</span>
+<a name="l00188"></a>00188 <span class="preprocessor"></span>    <span class="keywordflow">if</span> (level >= MAXLEVEL || strcmp(sinfo_callers[level], fctid) == 0)
+<a name="l00189"></a>00189 <span class="preprocessor">#else</span>
+<a name="l00190"></a>00190 <span class="preprocessor"></span>    fctid = fctid;              <span class="comment">/* Satisfy compiler */</span>
+<a name="l00191"></a>00191 <span class="preprocessor">#endif</span>
+<a name="l00192"></a>00192 <span class="preprocessor"></span>    {
+<a name="l00193"></a>00193         level--;
+<a name="l00194"></a>00194         cpl_msg_indent_less();
+<a name="l00195"></a>00195     }
+<a name="l00196"></a>00196 <span class="preprocessor">#if DEBUG_CALLER</span>
+<a name="l00197"></a>00197 <span class="preprocessor"></span>    <span class="keywordflow">else</span>
+<a name="l00198"></a>00198     {
+<a name="l00199"></a>00199      <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"Message level decreased by '%s' but increased by '%s'"</span>,
+<a name="l00200"></a>00200                sinfo_callers[level], fctid);
+<a name="l00201"></a>00201     }
+<a name="l00202"></a>00202 <span class="preprocessor">#endif</span>
+<a name="l00203"></a>00203 <span class="preprocessor"></span>}
+<a name="l00204"></a>00204 
+<a name="l00205"></a>00205 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00218"></a>00218 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00219"></a><a class="code" href="group__sinfo__msg.html#gacccff4e78e5f14f06b2c06686a0e19e1">00219</a> <span class="keywordtype">void</span> <a class="code" href="group__sinfo__msg.html#gacccff4e78e5f14f06b2c06686a0e19e1" title="Print a message on &#39;info&#39; or &#39;debug&#39; level.">sinfo_msg_macro</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *fct, <span class="keyword">const</span> <span class="keywordtype">char</span> *form [...]
+<a name="l00220"></a>00220 {
+<a name="l00221"></a>00221     va_list al;
+<a name="l00222"></a>00222     
+<a name="l00223"></a>00223     va_start(al, format);
+<a name="l00224"></a>00224     vsnprintf(printbuffer, MAXSTRINGLENGTH - 1, format, al);
+<a name="l00225"></a>00225     va_end(al);
+<a name="l00226"></a>00226 
+<a name="l00227"></a>00227     printbuffer[MAXSTRINGLENGTH - 1] = <span class="charliteral">'\0'</span>;
+<a name="l00228"></a>00228     
+<a name="l00229"></a>00229     <span class="keywordflow">if</span> (outlevel < 0 || level <= outlevel)
+<a name="l00230"></a>00230     {
+<a name="l00231"></a>00231 <span class="comment">/*</span>
+<a name="l00232"></a>00232 <span class="comment">#undef cpl_msg_info</span>
+<a name="l00233"></a>00233 <span class="comment">*/</span>
+<a name="l00234"></a>00234         cpl_msg_info(fct, <span class="stringliteral">"%s"</span>, printbuffer);
+<a name="l00235"></a>00235 <span class="comment">/*</span>
+<a name="l00236"></a>00236 <span class="comment">#define cpl_msg_info(...)  use__sinfo_msg__instead__of__cpl_msg_info</span>
+<a name="l00237"></a>00237 <span class="comment">*/</span>
+<a name="l00238"></a>00238     }
+<a name="l00239"></a>00239     <span class="keywordflow">else</span>
+<a name="l00240"></a>00240     {
+<a name="l00241"></a>00241         cpl_msg_debug(fct, <span class="stringliteral">"%s"</span>, printbuffer);
+<a name="l00242"></a>00242     }
+<a name="l00243"></a>00243 }
+<a name="l00244"></a>00244 
+<a name="l00245"></a>00245 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00250"></a>00250 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00251"></a><a class="code" href="group__sinfo__msg.html#ga819ca13f95340688515071106d88af30">00251</a> <span class="keywordtype">int</span> <a class="code" href="group__sinfo__msg.html#ga819ca13f95340688515071106d88af30" title="Get number of warnings printed so far.">sinfo_msg_get_warnings</a>(<span class="keywordtype">void</span>)
+<a name="l00252"></a>00252 {
+<a name="l00253"></a>00253     <span class="keywordflow">return</span> number_of_warnings;
+<a name="l00254"></a>00254 }
+<a name="l00255"></a>00255 
+<a name="l00256"></a>00256 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00265"></a>00265 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00266"></a><a class="code" href="group__sinfo__msg.html#gac95702d684d815593ec1516082c0071a">00266</a> <span class="keywordtype">void</span> <a class="code" href="group__sinfo__msg.html#gac95702d684d815593ec1516082c0071a" title="Accumulate warnings.">sinfo_msg_add_warnings</a>(<span class="keywordtype">int</span> n)
+<a name="l00267"></a>00267 {
+<a name="l00268"></a>00268     number_of_warnings += n;
+<a name="l00269"></a>00269 }
+<a name="l00270"></a>00270 
+<a name="l00271"></a>00271 
+<a name="l00272"></a>00272 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00286"></a>00286 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00287"></a><a class="code" href="group__sinfo__msg.html#ga905c39fd148a95c77ea1335aa9441b28">00287</a> <span class="keywordtype">void</span> <a class="code" href="group__sinfo__msg.html#ga905c39fd148a95c77ea1335aa9441b28" title="Print a warning message.">sinfo_msg_warning_macro</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *fct, <span class="keyword">const</span> <span class="keywordtype">char</span> *format, ...)
+<a name="l00288"></a>00288 {
+<a name="l00289"></a>00289     va_list al;
+<a name="l00290"></a>00290     
+<a name="l00291"></a>00291     va_start(al, format);
+<a name="l00292"></a>00292     vsnprintf(printbuffer, MAXSTRINGLENGTH - 1, format, al);
+<a name="l00293"></a>00293     va_end(al);
+<a name="l00294"></a>00294 
+<a name="l00295"></a>00295     printbuffer[MAXSTRINGLENGTH - 1] = <span class="charliteral">'\0'</span>;
+<a name="l00296"></a>00296     
+<a name="l00297"></a>00297     cpl_msg_warning(fct, <span class="stringliteral">"%s"</span>, printbuffer);
+<a name="l00298"></a>00298 
+<a name="l00299"></a>00299     number_of_warnings += 1;
+<a name="l00300"></a>00300 }
+<a name="l00301"></a>00301 
+<a name="l00302"></a>00302 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00308"></a>00308 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00309"></a><a class="code" href="group__sinfo__msg.html#ga15d005a10b6dac6031d611eecdce129a">00309</a> <span class="keyword">const</span> <span class="keywordtype">char</span> *<a class="code" href="group__sinfo__msg.html#ga15d005a10b6dac6031d611eecdce129a" title="Get current message domain.">sinfo_msg_get_domain</a>(<span class="keywordtype">void</span>)
+<a name="l00310"></a>00310 {
+<a name="l00311"></a>00311     <span class="keywordflow">return</span> domain;
+<a name="l00312"></a>00312 }
+<a name="l00313"></a>00313 
+<a name="l00314"></a>00314 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00319"></a>00319 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00320"></a><a class="code" href="group__sinfo__msg.html#ga5671e5e7722c35d9d174772c80013ad5">00320</a> <span class="keywordtype">void</span> <a class="code" href="group__sinfo__msg.html#ga5671e5e7722c35d9d174772c80013ad5" title="Set message domain.">sinfo_msg_set_domain</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *d)
+<a name="l00321"></a>00321 {
+<a name="l00322"></a>00322     <span class="comment">/* Set domain and remember */</span>
+<a name="l00323"></a>00323     cpl_msg_set_domain(d);
+<a name="l00324"></a>00324     domain = d;
+<a name="l00325"></a>00325 }
+<a name="l00326"></a>00326 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__msg_8h_source.html b/html/sinfo__msg_8h_source.html
new file mode 100644
index 0000000..cbcfad0
--- /dev/null
+++ b/html/sinfo__msg_8h_source.html
@@ -0,0 +1,119 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_msg.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_msg.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFO Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2006/11/21 11:56:10 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.2 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> */</span>
+<a name="l00026"></a>00026 <span class="preprocessor">#ifndef SINFO_MSG_H</span>
+<a name="l00027"></a>00027 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_MSG_H</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span>
+<a name="l00029"></a>00029 <span class="comment">/*</span>
+<a name="l00030"></a>00030 <span class="comment">#include <sinfo_utils.h></span>
+<a name="l00031"></a>00031 <span class="comment">*/</span>
+<a name="l00032"></a>00032 <span class="preprocessor">#include <cpl_msg.h></span>
+<a name="l00033"></a>00033 
+<a name="l00034"></a>00034 <span class="comment">/* Nothing bad happens if user also calls cpl_msg_info()</span>
+<a name="l00035"></a>00035 <span class="comment"> * but prevent it as a service to the user of this module</span>
+<a name="l00036"></a>00036 <span class="comment">#define cpl_msg_info(...)  use__sinfo_msg__instead__of__cpl_msg_info</span>
+<a name="l00037"></a>00037 <span class="comment">#define cpl_msg_indent()</span>
+<a name="l00038"></a>00038 <span class="comment"> */</span>
+<a name="l00039"></a>00039 
+<a name="l00040"></a>00040 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00045"></a>00045 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00049"></a>00049 <span class="keywordtype">void</span> <a class="code" href="group__sinfo__msg.html#ga639b5d352f0518db6cc346c0737484cc" title="Initialize messaging.">sinfo_msg_init</a>(<span class="keywordtype">int</span> outlevel, <span class="keyword">const</span> <span class="keywordtype">char</span> *dom);
+<a name="l00050"></a>00050 
+<a name="l00051"></a>00051 
+<a name="l00052"></a>00052 <span class="keywordtype">void</span> <a class="code" href="group__sinfo__msg.html#gad9c8f46542015d0c93094c337a557d5e" title="Set output level.">sinfo_msg_set_level</a>(<span class="keywordtype">int</span> olevel);
+<a name="l00053"></a>00053 
+<a name="l00054"></a>00054 <span class="keyword">const</span> <span class="keywordtype">char</span> *<a class="code" href="group__sinfo__msg.html#ga15d005a10b6dac6031d611eecdce129a" title="Get current message domain.">sinfo_msg_get_domain</a>(<span class="keywordtype">void</span>);
+<a name="l00055"></a>00055 <span class="keywordtype">void</span> <a class="code" href="group__sinfo__msg.html#ga5671e5e7722c35d9d174772c80013ad5" title="Set message domain.">sinfo_msg_set_domain</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *d);
+<a name="l00056"></a>00056 
+<a name="l00057"></a>00057 
+<a name="l00058"></a>00058 <span class="comment">/* Convenience macros to save the user from typing function id */</span>
+<a name="l00059"></a>00059 
+<a name="l00060"></a>00060 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00068"></a>00068 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00069"></a><a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789">00069</a> <span class="preprocessor">#define sinfo_msg_error(...) cpl_msg_error(cpl_func, __VA_ARGS__)</span>
+<a name="l00070"></a>00070 <span class="preprocessor"></span>
+<a name="l00071"></a>00071 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00081"></a>00081 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00082"></a><a class="code" href="group__sinfo__msg.html#ga75cab6805099905b3b101f660a907f37">00082</a> <span class="preprocessor">#define sinfo_msg_progress(i, iter, ...) \</span>
+<a name="l00083"></a>00083 <span class="preprocessor">  cpl_msg_progress(cpl_func, (i), (iter), __VA_ARGS__)</span>
+<a name="l00084"></a>00084 <span class="preprocessor"></span><span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00092"></a>00092 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00093"></a><a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6">00093</a> <span class="preprocessor">#define sinfo_msg_warning(...) sinfo_msg_warning_macro(cpl_func, __VA_ARGS__)</span>
+<a name="l00094"></a>00094 <span class="preprocessor"></span><span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00102"></a>00102 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00103"></a><a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8">00103</a> <span class="preprocessor">#define sinfo_msg_debug(...) cpl_msg_debug(cpl_func, __VA_ARGS__)</span>
+<a name="l00104"></a>00104 <span class="preprocessor"></span>
+<a name="l00105"></a>00105 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00110"></a>00110 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00111"></a><a class="code" href="group__sinfo__msg.html#gaa6da02902135556d8517de4c05b7a1a6">00111</a> <span class="preprocessor">#define sinfo_msg_low(...)  do {                     \</span>
+<a name="l00112"></a>00112 <span class="preprocessor">                           sinfo_msg_softer();       \</span>
+<a name="l00113"></a>00113 <span class="preprocessor">                           sinfo_msg(__VA_ARGS__);   \</span>
+<a name="l00114"></a>00114 <span class="preprocessor">                           sinfo_msg_louder();       \</span>
+<a name="l00115"></a>00115 <span class="preprocessor">                           } while (FALSE)</span>
+<a name="l00116"></a>00116 <span class="preprocessor"></span>
+<a name="l00117"></a>00117 
+<a name="l00118"></a>00118 
+<a name="l00119"></a>00119 
+<a name="l00120"></a>00120 <span class="preprocessor">#define sinfo_msg(...) sinfo_msg_macro(cpl_func, __VA_ARGS__)</span>
+<a name="l00121"></a>00121 <span class="preprocessor"></span><span class="preprocessor">#define sinfo_msg_softer() sinfo_msg_softer_macro(cpl_func)</span>
+<a name="l00122"></a>00122 <span class="preprocessor"></span><span class="preprocessor">#define sinfo_msg_louder() sinfo_msg_louder_macro(cpl_func)</span>
+<a name="l00123"></a>00123 <span class="preprocessor"></span>
+<a name="l00124"></a>00124 
+<a name="l00125"></a>00125 <span class="keywordtype">void</span> <a class="code" href="group__sinfo__msg.html#gacccff4e78e5f14f06b2c06686a0e19e1" title="Print a message on &#39;info&#39; or &#39;debug&#39; level.">sinfo_msg_macro</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *fct, <span class="keyword">const</span> <span class="keywordtype">char</span> *format, ...)
+<a name="l00126"></a>00126 <span class="preprocessor">#ifdef __GNUC__</span>
+<a name="l00127"></a>00127 <span class="preprocessor"></span>__attribute__((format (printf, 2, 3)))
+<a name="l00128"></a>00128 <span class="preprocessor">#endif</span>
+<a name="l00129"></a>00129 <span class="preprocessor"></span>;
+<a name="l00130"></a>00130 
+<a name="l00131"></a>00131 <span class="keywordtype">void</span> <a class="code" href="group__sinfo__msg.html#ga905c39fd148a95c77ea1335aa9441b28" title="Print a warning message.">sinfo_msg_warning_macro</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *fct, <span class="keyword">const</span> <span class="keywordtype">char</span> *format, ...)
+<a name="l00132"></a>00132 <span class="preprocessor">#ifdef __GNUC__</span>
+<a name="l00133"></a>00133 <span class="preprocessor"></span>__attribute__((format (printf, 2, 3)))
+<a name="l00134"></a>00134 <span class="preprocessor">#endif</span>
+<a name="l00135"></a>00135 <span class="preprocessor"></span>;
+<a name="l00136"></a>00136 
+<a name="l00137"></a>00137 <span class="keywordtype">int</span> <a class="code" href="group__sinfo__msg.html#ga819ca13f95340688515071106d88af30" title="Get number of warnings printed so far.">sinfo_msg_get_warnings</a>(<span class="keywordtype">void</span>);
+<a name="l00138"></a>00138 <span class="keywordtype">void</span> <a class="code" href="group__sinfo__msg.html#gac95702d684d815593ec1516082c0071a" title="Accumulate warnings.">sinfo_msg_add_warnings</a>(<span class="keywordtype">int</span> n);
+<a name="l00139"></a>00139 
+<a name="l00140"></a>00140 <span class="keywordtype">void</span> <a class="code" href="group__sinfo__msg.html#gae0f3e727182610d92efdb755f1da6788" title="Decrease message level.">sinfo_msg_softer_macro</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *fct);
+<a name="l00141"></a>00141 <span class="keywordtype">void</span> <a class="code" href="group__sinfo__msg.html#ga38ac31ae7cb0ce5c792486fd3c9478e6" title="Increase message level.">sinfo_msg_louder_macro</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *fct);
+<a name="l00142"></a>00142 
+<a name="l00143"></a>00143 <span class="preprocessor">#endif </span><span class="comment">/* SINFO_MSG_H */</span>
+<a name="l00144"></a>00144 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__new__add__bp__map_8c_source.html b/html/sinfo__new__add__bp__map_8c_source.html
new file mode 100644
index 0000000..d386b6d
--- /dev/null
+++ b/html/sinfo__new__add__bp__map_8c_source.html
@@ -0,0 +1,286 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_new_add_bp_map.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_new_add_bp_map.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name    :       sinfo_new_add_bp_map.c</span>
+<a name="l00022"></a>00022 <span class="comment">   Author       :    A. Modigliani</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on   :    Oct 13, 2004</span>
+<a name="l00024"></a>00024 <span class="comment">   Description  :    Coadd different BP MAP </span>
+<a name="l00025"></a>00025 <span class="comment"></span>
+<a name="l00026"></a>00026 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span><span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00032"></a>00032 <span class="comment">                                Includes</span>
+<a name="l00033"></a>00033 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00034"></a>00034 <span class="preprocessor">#include "sinfo_new_add_bp_map.h"</span>
+<a name="l00035"></a>00035 <span class="preprocessor">#include "sinfo_pro_save.h"</span>
+<a name="l00036"></a>00036 <span class="preprocessor">#include "sinfo_error.h"</span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include "sinfo_utils_wrappers.h"</span>
+<a name="l00038"></a>00038 <span class="comment">/* #include "image_ops.h" */</span>
+<a name="l00039"></a>00039 <span class="preprocessor">#include "sinfo_pro_types.h"</span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include "sinfo_functions.h"</span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include "sinfo_detlin.h"</span>
+<a name="l00042"></a>00042 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00043"></a>00043 <span class="comment">                                Prototypes</span>
+<a name="l00044"></a>00044 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00045"></a>00045 
+<a name="l00046"></a>00046 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00047"></a>00047 <span class="comment">                                Defines</span>
+<a name="l00048"></a>00048 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00049"></a>00049 
+<a name="l00050"></a>00050 
+<a name="l00051"></a>00051 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00052"></a>00052 <span class="comment">  Function Definitions</span>
+<a name="l00053"></a>00053 <span class="comment">  ---------------------------------------------------------------------------*/</span>
+<a name="l00071"></a>00071 <span class="keywordtype">int</span> 
+<a name="l00072"></a>00072 sinfo_new_add_bp_map (<span class="keyword">const</span> <span class="keywordtype">char</span>* plugin_id,
+<a name="l00073"></a>00073                       cpl_parameterlist* config, 
+<a name="l00074"></a>00074                       cpl_frameset* sof,cpl_frameset* ref_set)
+<a name="l00075"></a>00075 {
+<a name="l00076"></a>00076 
+<a name="l00077"></a>00077   <span class="keywordtype">int</span>  nmsk =0;
+<a name="l00078"></a>00078   <span class="keywordtype">int</span>  nmsk_ref_fits =0;
+<a name="l00079"></a>00079   <span class="keywordtype">int</span> i=0;
+<a name="l00080"></a>00080   <span class="keywordtype">int</span> k=0;
+<a name="l00081"></a>00081   <span class="keywordtype">int</span> n_bad=0;
+<a name="l00082"></a>00082   cpl_image**  img_sum=NULL;
+<a name="l00083"></a>00083   cpl_image*   img_set=NULL;
+<a name="l00084"></a>00084   cpl_image*   img_tot=NULL;
+<a name="l00085"></a>00085   cpl_frameset* msk_set=NULL;
+<a name="l00086"></a>00086   cpl_frameset* msk_ref_fits=NULL;
+<a name="l00087"></a>00087   cpl_frame* frame=NULL;
+<a name="l00088"></a>00088   <span class="keywordtype">double</span> max=0;
+<a name="l00089"></a>00089   <span class="keywordtype">char</span> frame_name[FILE_NAME_SZ];
+<a name="l00090"></a>00090   <span class="keywordtype">char</span> out_msk[FILE_NAME_SZ];
+<a name="l00091"></a>00091       
+<a name="l00092"></a>00092   cpl_table* qclog_tbl=NULL;
+<a name="l00093"></a>00093   <span class="keywordtype">char</span> * tag=NULL;
+<a name="l00094"></a>00094   <span class="keywordtype">char</span> * tmp_tag=NULL;
+<a name="l00095"></a>00095 
+<a name="l00096"></a>00096   strcpy(out_msk, MASTER_BPMAP_OUT_FILENAME);
+<a name="l00097"></a>00097 
+<a name="l00098"></a>00098 
+<a name="l00099"></a>00099   <span class="comment">/* cpl_parameterlist_dump(config); */</span>
+<a name="l00100"></a>00100   check_nomsg(msk_set=cpl_frameset_new());
+<a name="l00101"></a>00101   ck0_nomsg(sinfo_contains_frames_kind(sof,msk_set,<span class="stringliteral">"BP_MAP"</span>));
+<a name="l00102"></a>00102   check_nomsg(nmsk = cpl_frameset_get_size(msk_set));
+<a name="l00103"></a>00103   <span class="keywordflow">if</span>(nmsk == 0) {
+<a name="l00104"></a>00104     <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"No bad pixel masks to add"</span>);
+<a name="l00105"></a>00105     <span class="keywordflow">goto</span> cleanup;
+<a name="l00106"></a>00106   }
+<a name="l00107"></a>00107 
+<a name="l00108"></a>00108 
+<a name="l00109"></a>00109   check_nomsg(frame = cpl_frameset_get_frame(msk_set,0));
+<a name="l00110"></a>00110   strcpy(frame_name,cpl_frame_get_filename(frame));
+<a name="l00111"></a>00111   check_nomsg(tag = (<span class="keywordtype">char</span>*) cpl_frame_get_tag(frame));
+<a name="l00112"></a>00112   {
+<a name="l00113"></a>00113     check_nomsg(msk_ref_fits=cpl_frameset_new());
+<a name="l00114"></a>00114     <span class="keywordflow">if</span> (nmsk < 1) {
+<a name="l00115"></a>00115       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"No input frames. Nothing to do."</span>);
+<a name="l00116"></a>00116       <span class="keywordflow">goto</span> cleanup;
+<a name="l00117"></a>00117     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (nmsk==1) {
+<a name="l00118"></a>00118 
+<a name="l00119"></a>00119       <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"Only one input frames. Use it as master."</span>);
+<a name="l00120"></a>00120       check_nomsg(frame = cpl_frameset_get_frame(msk_set,0));
+<a name="l00121"></a>00121       strcpy(frame_name,cpl_frame_get_filename(frame));
+<a name="l00122"></a>00122       check_nomsg(tag = (<span class="keywordtype">char</span>*) cpl_frame_get_tag(frame));
+<a name="l00123"></a>00123 
+<a name="l00124"></a>00124     } <span class="keywordflow">else</span> {
+<a name="l00125"></a>00125        
+<a name="l00126"></a>00126       ck0_nomsg(sinfo_contains_frames_kind(msk_set,
+<a name="l00127"></a>00127                        msk_ref_fits,PRO_BP_MAP_NO));
+<a name="l00128"></a>00128       check_nomsg(nmsk_ref_fits = cpl_frameset_get_size(msk_ref_fits));
+<a name="l00129"></a>00129 
+<a name="l00130"></a>00130       <span class="keywordflow">if</span> (nmsk_ref_fits < 1) {
+<a name="l00131"></a>00131     <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"No %s input frames. Uses %s for FITS header"</span>,
+<a name="l00132"></a>00132               PRO_BP_MAP_NO,PRO_BP_MAP_DI);
+<a name="l00133"></a>00133 
+<a name="l00134"></a>00134     ck0_nomsg(sinfo_contains_frames_kind(msk_set,
+<a name="l00135"></a>00135                          msk_ref_fits,PRO_BP_MAP_DI));
+<a name="l00136"></a>00136     check_nomsg(nmsk_ref_fits = cpl_frameset_get_size(msk_ref_fits));
+<a name="l00137"></a>00137 
+<a name="l00138"></a>00138 
+<a name="l00139"></a>00139     <span class="keywordflow">if</span> (nmsk_ref_fits < 1) {
+<a name="l00140"></a>00140 
+<a name="l00141"></a>00141       <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"No %s input frames. Uses %s for FITS header"</span>,
+<a name="l00142"></a>00142                 PRO_BP_MAP_DI,PRO_BP_MAP_NL);
+<a name="l00143"></a>00143         
+<a name="l00144"></a>00144       ck0_nomsg(sinfo_contains_frames_kind(msk_set,
+<a name="l00145"></a>00145                            msk_ref_fits,PRO_BP_MAP_NL));
+<a name="l00146"></a>00146       check_nomsg(nmsk_ref_fits = cpl_frameset_get_size(msk_ref_fits));
+<a name="l00147"></a>00147 
+<a name="l00148"></a>00148       <span class="keywordflow">if</span> (nmsk_ref_fits < 1) {
+<a name="l00149"></a>00149 
+<a name="l00150"></a>00150         <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"No %s input frames. Uses 1st mask in the list"</span>,
+<a name="l00151"></a>00151                   PRO_BP_MAP_NL);
+<a name="l00152"></a>00152         sinfo_free_frameset(&msk_ref_fits);
+<a name="l00153"></a>00153         check_nomsg(msk_ref_fits=cpl_frameset_duplicate(msk_set));
+<a name="l00154"></a>00154         check_nomsg(frame = cpl_frameset_get_frame(msk_set,0));
+<a name="l00155"></a>00155         check_nomsg(cpl_frameset_erase_frame(msk_set,frame));
+<a name="l00156"></a>00156         check_nomsg(tag = (<span class="keywordtype">char</span>*) cpl_frame_get_tag(frame));
+<a name="l00157"></a>00157 
+<a name="l00158"></a>00158       } <span class="keywordflow">else</span> {
+<a name="l00159"></a>00159         sinfo_msg(<span class="stringliteral">"Uses as reference frame %s"</span>,PRO_BP_MAP_NL);
+<a name="l00160"></a>00160         check_nomsg(frame = cpl_frameset_get_frame(msk_ref_fits,0));
+<a name="l00161"></a>00161         strcpy(frame_name,cpl_frame_get_filename(frame));
+<a name="l00162"></a>00162         tag = (<span class="keywordtype">char</span>*) PRO_BP_MAP_NL;
+<a name="l00163"></a>00163       }
+<a name="l00164"></a>00164     } <span class="keywordflow">else</span> {
+<a name="l00165"></a>00165           sinfo_msg(<span class="stringliteral">"Uses as reference frame %s"</span>,PRO_BP_MAP_DI);
+<a name="l00166"></a>00166       check_nomsg(frame = cpl_frameset_get_frame(msk_ref_fits,0));
+<a name="l00167"></a>00167       strcpy(frame_name,cpl_frame_get_filename(frame));
+<a name="l00168"></a>00168       tag = (<span class="keywordtype">char</span>*) PRO_BP_MAP_DI;
+<a name="l00169"></a>00169     }
+<a name="l00170"></a>00170       } <span class="keywordflow">else</span> {
+<a name="l00171"></a>00171         sinfo_msg(<span class="stringliteral">"Uses as reference frame %s"</span>,PRO_BP_MAP_NO);
+<a name="l00172"></a>00172     check_nomsg(frame = cpl_frameset_get_frame(msk_ref_fits,0));
+<a name="l00173"></a>00173     strcpy(frame_name,cpl_frame_get_filename(frame));
+<a name="l00174"></a>00174     tag = (<span class="keywordtype">char</span>*) PRO_BP_MAP_NO;
+<a name="l00175"></a>00175       }
+<a name="l00176"></a>00176     }
+<a name="l00177"></a>00177 
+<a name="l00178"></a>00178     check_nomsg(nmsk = cpl_frameset_get_size(msk_set));  
+<a name="l00179"></a>00179     cknull_nomsg(img_sum = (cpl_image**) cpl_calloc ((nmsk+1), 
+<a name="l00180"></a>00180                              <span class="keyword">sizeof</span>(cpl_image*))) ;
+<a name="l00181"></a>00181     cknull_nomsg(img_sum[0]=cpl_image_load(frame_name,CPL_TYPE_FLOAT,0,0));
+<a name="l00182"></a>00182 
+<a name="l00183"></a>00183     <span class="comment">/* here mem leak */</span>
+<a name="l00184"></a>00184     <span class="keywordflow">for</span> (i=0;i<nmsk;i++) {
+<a name="l00185"></a>00185       check_nomsg(frame = cpl_frameset_get_frame(msk_set,i));
+<a name="l00186"></a>00186       check_nomsg(strcpy(frame_name,cpl_frame_get_filename(frame)));
+<a name="l00187"></a>00187       check_nomsg(tmp_tag=(<span class="keywordtype">char</span>*)cpl_frame_get_tag(frame));
+<a name="l00188"></a>00188 
+<a name="l00189"></a>00189       <span class="keywordflow">if</span>(strcmp(tmp_tag,tag) == 0 ) {
+<a name="l00190"></a>00190     cknull_nomsg(img_set=cpl_image_load(frame_name,CPL_TYPE_FLOAT,0,0));
+<a name="l00191"></a>00191         check_nomsg(max=cpl_image_get_max(img_set));
+<a name="l00192"></a>00192     <span class="keywordflow">if</span>((strcmp(tmp_tag,PRO_BP_MAP_NL) == 0) && max>1 ) {
+<a name="l00193"></a>00193       sinfo_msg(<span class="stringliteral">"corr1"</span>);
+<a name="l00194"></a>00194       check_nomsg(cpl_image_threshold(img_set,0.5,0.9,1,0));
+<a name="l00195"></a>00195           sinfo_free_image(&(img_sum[0]));
+<a name="l00196"></a>00196           check_nomsg(img_sum[0]=cpl_image_duplicate(img_set));
+<a name="l00197"></a>00197     }
+<a name="l00198"></a>00198 
+<a name="l00199"></a>00199       } <span class="keywordflow">else</span> {
+<a name="l00200"></a>00200 
+<a name="l00201"></a>00201     cknull_nomsg(img_set=cpl_image_load(frame_name,CPL_TYPE_FLOAT,0,0));
+<a name="l00202"></a>00202         check_nomsg(max=cpl_image_get_max(img_set));
+<a name="l00203"></a>00203     <span class="keywordflow">if</span>((strcmp(tmp_tag,PRO_BP_MAP_NL) == 0) &&  max>1 ) {
+<a name="l00204"></a>00204       sinfo_msg(<span class="stringliteral">"corr2 name=%s tag=%s"</span>,frame_name,tmp_tag);
+<a name="l00205"></a>00205       check_nomsg(cpl_image_threshold(img_set,0.5,0.9,1,0));
+<a name="l00206"></a>00206     }
+<a name="l00207"></a>00207    
+<a name="l00208"></a>00208     cknull_nomsg(img_sum[k+1]=sinfo_new_combine_masks (img_sum[k], img_set));
+<a name="l00209"></a>00209     k++;
+<a name="l00210"></a>00210     sinfo_free_image(&img_set);
+<a name="l00211"></a>00211     sinfo_free_image(&(img_sum[k-1]));
+<a name="l00212"></a>00212       }
+<a name="l00213"></a>00213     }
+<a name="l00214"></a>00214     img_tot=cpl_image_duplicate(img_sum[k]);
+<a name="l00215"></a>00215     sinfo_free_image(&(img_sum[k]));
+<a name="l00216"></a>00216     sinfo_free_array_image(&img_sum);
+<a name="l00217"></a>00217     <span class="comment">/*</span>
+<a name="l00218"></a>00218 <span class="comment"></span>
+<a name="l00219"></a>00219 <span class="comment">    frame = cpl_frameset_get_frame(msk_set,0);</span>
+<a name="l00220"></a>00220 <span class="comment">    strcpy(frame_name,cpl_frame_get_filename(frame));</span>
+<a name="l00221"></a>00221 <span class="comment">    img_sum=cpl_image_load(frame_name,CPL_TYPE_INT,0,0);</span>
+<a name="l00222"></a>00222 <span class="comment">        </span>
+<a name="l00223"></a>00223 <span class="comment">    for (i=1;i<nmsk;i++) {</span>
+<a name="l00224"></a>00224 <span class="comment">    frame = cpl_frameset_get_frame(msk_set,i);</span>
+<a name="l00225"></a>00225 <span class="comment">    strcpy(frame_name,cpl_frame_get_filename(frame));</span>
+<a name="l00226"></a>00226 <span class="comment">    img_set=cpl_image_load(frame_name,CPL_TYPE_INT,0,0);</span>
+<a name="l00227"></a>00227 <span class="comment">    cpl_mask_and(img_sum, img_set);</span>
+<a name="l00228"></a>00228 <span class="comment"></span>
+<a name="l00229"></a>00229 <span class="comment">    }</span>
+<a name="l00230"></a>00230 <span class="comment">    </span>
+<a name="l00231"></a>00231 <span class="comment">    */</span>
+<a name="l00232"></a>00232 
+<a name="l00233"></a>00233     n_bad = sinfo_new_count_bad_pixels(img_tot) ;
+<a name="l00234"></a>00234     sinfo_msg (<span class="stringliteral">"number of bad pixels: %d\n"</span>, n_bad) ;
+<a name="l00235"></a>00235     cknull_nomsg(qclog_tbl = sinfo_qclog_init());
+<a name="l00236"></a>00236     ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,<span class="stringliteral">"QC MBP_MAP NBADPIX"</span>,
+<a name="l00237"></a>00237                   n_bad,<span class="stringliteral">"No of bad pixels"</span>,<span class="stringliteral">"%d"</span>));
+<a name="l00238"></a>00238 
+<a name="l00239"></a>00239     <span class="keywordflow">if</span> (nmsk>1) {
+<a name="l00240"></a>00240       ck0(sinfo_pro_save_ima(img_tot,ref_set,sof,out_msk,
+<a name="l00241"></a>00241                  PRO_MASTER_BP_MAP,qclog_tbl,
+<a name="l00242"></a>00242                  plugin_id,config),
+<a name="l00243"></a>00243       <span class="stringliteral">"cannot save ima %s"</span>, out_msk);   
+<a name="l00244"></a>00244 
+<a name="l00245"></a>00245     } <span class="keywordflow">else</span> {
+<a name="l00246"></a>00246       ck0(sinfo_pro_save_ima(img_tot,ref_set,sof,out_msk,
+<a name="l00247"></a>00247                  PRO_MASTER_BP_MAP,qclog_tbl,
+<a name="l00248"></a>00248                  plugin_id,config),
+<a name="l00249"></a>00249       <span class="stringliteral">"cannot save ima %s"</span>, out_msk);   
+<a name="l00250"></a>00250     }
+<a name="l00251"></a>00251 
+<a name="l00252"></a>00252     sinfo_free_image(&img_tot);
+<a name="l00253"></a>00253     sinfo_free_table(&qclog_tbl);
+<a name="l00254"></a>00254     sinfo_free_frameset(&msk_ref_fits);
+<a name="l00255"></a>00255     sinfo_free_frameset(&msk_set);
+<a name="l00256"></a>00256   
+<a name="l00257"></a>00257   }
+<a name="l00258"></a>00258 
+<a name="l00259"></a>00259  cleanup:
+<a name="l00260"></a>00260 
+<a name="l00261"></a>00261   sinfo_free_image(&img_tot);
+<a name="l00262"></a>00262   <span class="keywordflow">if</span>(img_sum!=NULL) {
+<a name="l00263"></a>00263     <span class="keywordflow">for</span>(i=0;i<nmsk;i++) {
+<a name="l00264"></a>00264       <span class="keywordflow">if</span>(img_sum[i] != NULL) {
+<a name="l00265"></a>00265     sinfo_free_image(&(img_sum[i]));
+<a name="l00266"></a>00266     img_sum[i]=NULL;         
+<a name="l00267"></a>00267       }
+<a name="l00268"></a>00268     }
+<a name="l00269"></a>00269     sinfo_free_array_image(&img_sum);
+<a name="l00270"></a>00270     img_sum=NULL;
+<a name="l00271"></a>00271   }
+<a name="l00272"></a>00272   sinfo_free_image(&img_set);
+<a name="l00273"></a>00273   sinfo_free_table(&qclog_tbl);
+<a name="l00274"></a>00274   sinfo_free_frameset(&msk_set);
+<a name="l00275"></a>00275   sinfo_free_frameset(&msk_ref_fits);
+<a name="l00276"></a>00276 
+<a name="l00277"></a>00277   <span class="keywordflow">if</span> (cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l00278"></a>00278      <span class="keywordflow">return</span> -1; 
+<a name="l00279"></a>00279   } <span class="keywordflow">else</span> {
+<a name="l00280"></a>00280      <span class="keywordflow">return</span> 0;
+<a name="l00281"></a>00281   }
+<a name="l00282"></a>00282 
+<a name="l00283"></a>00283 
+<a name="l00284"></a>00284 }
+<a name="l00285"></a>00285 
+<a name="l00286"></a>00286 
+<a name="l00287"></a>00287 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__new__add__bp__map_8h_source.html b/html/sinfo__new__add__bp__map_8h_source.html
new file mode 100644
index 0000000..34f8be0
--- /dev/null
+++ b/html/sinfo__new__add__bp__map_8h_source.html
@@ -0,0 +1,71 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_new_add_bp_map.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_new_add_bp_map.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#ifndef SINFO_NEW_ADD_BP_MAP_H</span>
+<a name="l00002"></a>00002 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_NEW_ADD_BP_MAP_H</span>
+<a name="l00003"></a>00003 <span class="preprocessor"></span><span class="comment">/*</span>
+<a name="l00004"></a>00004 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00005"></a>00005 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00006"></a>00006 <span class="comment"> *</span>
+<a name="l00007"></a>00007 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00008"></a>00008 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00009"></a>00009 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00010"></a>00010 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00011"></a>00011 <span class="comment"> *</span>
+<a name="l00012"></a>00012 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00013"></a>00013 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00014"></a>00014 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00015"></a>00015 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00016"></a>00016 <span class="comment"> *</span>
+<a name="l00017"></a>00017 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00018"></a>00018 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00019"></a>00019 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00020"></a>00020 <span class="comment"> */</span>
+<a name="l00021"></a>00021 <span class="comment">/*******************************************************************************</span>
+<a name="l00022"></a>00022 <span class="comment">* E.S.O. - VLT project</span>
+<a name="l00023"></a>00023 <span class="comment">*</span>
+<a name="l00024"></a>00024 <span class="comment">* "@(#) $Id: sinfo_new_add_bp_map.h,v 1.7 2007/09/21 14:13:43 amodigli Exp $"</span>
+<a name="l00025"></a>00025 <span class="comment">*</span>
+<a name="l00026"></a>00026 <span class="comment">* who       when      what</span>
+<a name="l00027"></a>00027 <span class="comment">* --------  --------  ----------------------------------------------</span>
+<a name="l00028"></a>00028 <span class="comment">* amodigli  13/10/04  created</span>
+<a name="l00029"></a>00029 <span class="comment">*/</span>
+<a name="l00030"></a>00030 
+<a name="l00031"></a>00031 <span class="comment">/************************************************************************</span>
+<a name="l00032"></a>00032 <span class="comment"> * sinfo_add_bp_map.h</span>
+<a name="l00033"></a>00033 <span class="comment"> * routines to search for bad pixels</span>
+<a name="l00034"></a>00034 <span class="comment"> *----------------------------------------------------------------------</span>
+<a name="l00035"></a>00035 <span class="comment"> */</span>
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="comment">/*</span>
+<a name="l00038"></a>00038 <span class="comment"> * header files</span>
+<a name="l00039"></a>00039 <span class="comment"> */</span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include <sinfo_hidden.h></span>  
+<a name="l00042"></a>00042 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00043"></a>00043 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00044"></a>00044 <span class="comment"> *                        Function ANSI C prototypes</span>
+<a name="l00045"></a>00045 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00055"></a>00055 <span class="keywordtype">int</span> 
+<a name="l00056"></a>00056 sinfo_new_add_bp_map(<span class="keyword">const</span> <span class="keywordtype">char</span>* plugin_id, 
+<a name="l00057"></a>00057                      cpl_parameterlist* config, 
+<a name="l00058"></a>00058                      cpl_frameset* <span class="keyword">set</span>,
+<a name="l00059"></a>00059                      cpl_frameset* ref_set);
+<a name="l00060"></a>00060 
+<a name="l00061"></a>00061 
+<a name="l00062"></a>00062 <span class="preprocessor">#endif </span>
+<a name="l00063"></a>00063 <span class="preprocessor"></span>
+<a name="l00064"></a>00064 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__new__bezier_8c_source.html b/html/sinfo__new__bezier_8c_source.html
new file mode 100644
index 0000000..79df627
--- /dev/null
+++ b/html/sinfo__new__bezier_8c_source.html
@@ -0,0 +1,1540 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_new_bezier.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_new_bezier.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*****************************************************************************</span>
+<a name="l00020"></a>00020 <span class="comment">* M.P.E. - SPIFFI project</span>
+<a name="l00021"></a>00021 <span class="comment">*</span>
+<a name="l00022"></a>00022 <span class="comment">*</span>
+<a name="l00023"></a>00023 <span class="comment">*</span>
+<a name="l00024"></a>00024 <span class="comment">* who       when      what</span>
+<a name="l00025"></a>00025 <span class="comment"></span>
+<a name="l00026"></a>00026 <span class="comment">* --------  --------  ----------------------------------------------</span>
+<a name="l00027"></a>00027 <span class="comment">* rabuter 2004-11-04 Fixed error on Find Cosmic when no valid neighboors</span>
+<a name="l00028"></a>00028 <span class="comment">                     where found in the subcube</span>
+<a name="l00029"></a>00029 <span class="comment">* rabuter 10/07/03  created</span>
+<a name="l00030"></a>00030 <span class="comment">*/</span>
+<a name="l00031"></a>00031 
+<a name="l00032"></a>00032 <span class="comment">/************************************************************************</span>
+<a name="l00033"></a>00033 <span class="comment">*   NAME</span>
+<a name="l00034"></a>00034 <span class="comment">*        sinfo_new_bezier.c -</span>
+<a name="l00035"></a>00035 <span class="comment">*        procedures to correct for bad pixels using bezier splines</span>
+<a name="l00036"></a>00036 <span class="comment">*</span>
+<a name="l00037"></a>00037 <span class="comment">*   SYNOPSIS</span>
+<a name="l00038"></a>00038 <span class="comment">*</span>
+<a name="l00039"></a>00039 <span class="comment">*   DESCRIPTION</span>
+<a name="l00040"></a>00040 <span class="comment">*</span>
+<a name="l00041"></a>00041 <span class="comment">*   FILES</span>
+<a name="l00042"></a>00042 <span class="comment">*</span>
+<a name="l00043"></a>00043 <span class="comment">*   ENVIRONMENT</span>
+<a name="l00044"></a>00044 <span class="comment">*</span>
+<a name="l00045"></a>00045 <span class="comment">*   RETURN VALUES</span>
+<a name="l00046"></a>00046 <span class="comment">*</span>
+<a name="l00047"></a>00047 <span class="comment">*   CAUTIONS</span>
+<a name="l00048"></a>00048 <span class="comment">*</span>
+<a name="l00049"></a>00049 <span class="comment">*   EXAMPLES</span>
+<a name="l00050"></a>00050 <span class="comment">*</span>
+<a name="l00051"></a>00051 <span class="comment">*   SEE ALSO</span>
+<a name="l00052"></a>00052 <span class="comment">*</span>
+<a name="l00053"></a>00053 <span class="comment">*   BUGS</span>
+<a name="l00054"></a>00054 <span class="comment">*</span>
+<a name="l00055"></a>00055 <span class="comment">*------------------------------------------------------------------------</span>
+<a name="l00056"></a>00056 <span class="comment">*/</span>
+<a name="l00057"></a>00057 
+<a name="l00058"></a>00058 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00059"></a>00059 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00060"></a>00060 <span class="preprocessor">#endif</span>
+<a name="l00061"></a>00061 <span class="preprocessor"></span><span class="preprocessor">#define POSIX_SOURCE 1</span>
+<a name="l00062"></a>00062 <span class="preprocessor"></span><span class="preprocessor">#include "sinfo_vltPort.h"</span>
+<a name="l00063"></a>00063 
+<a name="l00064"></a>00064 <span class="comment">/*</span>
+<a name="l00065"></a>00065 <span class="comment"> * System Headers</span>
+<a name="l00066"></a>00066 <span class="comment"> */</span>
+<a name="l00067"></a>00067 
+<a name="l00068"></a>00068 <span class="comment">/*</span>
+<a name="l00069"></a>00069 <span class="comment"> * Local Headers</span>
+<a name="l00070"></a>00070 <span class="comment"> */</span>
+<a name="l00071"></a>00071 
+<a name="l00072"></a>00072 <span class="preprocessor">#include "sinfo_new_bezier.h"</span>
+<a name="l00073"></a>00073 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00081"></a>00081 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00082"></a>00082 <span class="comment"> *                            Function codes</span>
+<a name="l00083"></a>00083 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00084"></a>00084 
+<a name="l00093"></a>00093 <span class="keywordtype">int</span> sinfo_im_xy(cpl_image* im, <span class="keywordtype">int</span> X, <span class="keywordtype">int</span> Y)
+<a name="l00094"></a>00094 {
+<a name="l00095"></a>00095   <span class="keywordtype">int</span> res=0;
+<a name="l00096"></a>00096 
+<a name="l00097"></a>00097    res=X+Y*cpl_image_get_size_x(im);
+<a name="l00098"></a>00098   <span class="keywordflow">return</span> res;
+<a name="l00099"></a>00099 }
+<a name="l00108"></a>00108 <span class="keywordtype">int</span> sinfo_im_xyz(cpl_image* im, <span class="keywordtype">int</span> X, <span class="keywordtype">int</span> Y, <span class="keywordtype">int</span> Z)
+<a name="l00109"></a>00109 {
+<a name="l00110"></a>00110   <span class="keywordtype">int</span> res=0;
+<a name="l00111"></a>00111    res = X+
+<a name="l00112"></a>00112          Y*cpl_image_get_size_x(im)+
+<a name="l00113"></a>00113          Z*cpl_image_get_size_x(im)*
+<a name="l00114"></a>00114            cpl_image_get_size_y(im);
+<a name="l00115"></a>00115   <span class="keywordflow">return</span> res;
+<a name="l00116"></a>00116 }
+<a name="l00117"></a>00117 
+<a name="l00118"></a>00118 
+<a name="l00119"></a>00119 
+<a name="l00128"></a>00128 <span class="keywordtype">int</span> sinfo_cu_xy(cpl_imagelist* cu, <span class="keywordtype">int</span> X, <span class="keywordtype">int</span> Y)
+<a name="l00129"></a>00129 {
+<a name="l00130"></a>00130   <span class="keywordtype">int</span> res=0;
+<a name="l00131"></a>00131 
+<a name="l00132"></a>00132    res=X+Y*cpl_image_get_size_x(cpl_imagelist_get(cu,0));
+<a name="l00133"></a>00133   <span class="keywordflow">return</span> res;
+<a name="l00134"></a>00134 }
+<a name="l00145"></a>00145 <span class="keywordtype">int</span> sinfo_cu_xyz(cpl_imagelist* cu, <span class="keywordtype">int</span> X, <span class="keywordtype">int</span> Y, <span class="keywordtype">int</span> Z)
+<a name="l00146"></a>00146 {
+<a name="l00147"></a>00147   <span class="keywordtype">int</span> res=0;
+<a name="l00148"></a>00148    res = X+
+<a name="l00149"></a>00149          Y*cpl_image_get_size_x(cpl_imagelist_get(cu,0))+
+<a name="l00150"></a>00150          Z*cpl_image_get_size_x(cpl_imagelist_get(cu,0))*
+<a name="l00151"></a>00151            cpl_image_get_size_y(cpl_imagelist_get(cu,0));
+<a name="l00152"></a>00152   <span class="keywordflow">return</span> res;
+<a name="l00153"></a>00153 }
+<a name="l00154"></a>00154 
+<a name="l00169"></a>00169 cpl_image *
+<a name="l00170"></a>00170 sinfo_new_c_bezier_interpolate_image(cpl_image *im,
+<a name="l00171"></a>00171                                      cpl_image *mask,
+<a name="l00172"></a>00172                                      new_Lookup *look,
+<a name="l00173"></a>00173                                            <span class="keywordtype">short</span> rx,
+<a name="l00174"></a>00174                                            <span class="keywordtype">short</span> ry,
+<a name="l00175"></a>00175                                            <span class="keywordtype">short</span> rz,
+<a name="l00176"></a>00176                            <span class="keywordtype">int</span> max_rad ,
+<a name="l00177"></a>00177                                            <span class="keywordtype">float</span>   ** slit_edges )
+<a name="l00178"></a>00178 {
+<a name="l00179"></a>00179 
+<a name="l00180"></a>00180     <span class="keywordtype">int</span> i,j,count;
+<a name="l00181"></a>00181     cpl_imagelist * sc_im,* drs_sc_mask;
+<a name="l00182"></a>00182     cpl_image *auxImage;
+<a name="l00183"></a>00183     cpl_image *tempMask;
+<a name="l00184"></a>00184     <span class="keywordtype">short</span> szx,szy,szz;
+<a name="l00185"></a>00185     <span class="keywordtype">short</span> rx_loop, ry_loop, rz_loop;
+<a name="l00186"></a>00186     <span class="comment">/*float ant,new,dif;*/</span>
+<a name="l00187"></a>00187 
+<a name="l00188"></a>00188     <span class="keywordtype">int</span> ilx=0;
+<a name="l00189"></a>00189     <span class="keywordtype">int</span> ily=0;
+<a name="l00190"></a>00190     <span class="keywordtype">int</span> mlx=0;
+<a name="l00191"></a>00191     <span class="keywordtype">int</span> mly=0;
+<a name="l00192"></a>00192 
+<a name="l00193"></a>00193     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l00194"></a>00194     <span class="keywordtype">float</span>* pmdata=NULL;
+<a name="l00195"></a>00195     <span class="keywordtype">float</span>* ptdata=NULL;
+<a name="l00196"></a>00196     <span class="keywordtype">float</span>* padata=NULL;
+<a name="l00197"></a>00197 
+<a name="l00198"></a>00198     cpl_image* sc_img=NULL;
+<a name="l00199"></a>00199     cpl_image* drs_img=NULL;
+<a name="l00200"></a>00200 
+<a name="l00201"></a>00201     mlx=cpl_image_get_size_x(mask);
+<a name="l00202"></a>00202     mly=cpl_image_get_size_y(mask);
+<a name="l00203"></a>00203     ilx=cpl_image_get_size_x(im);
+<a name="l00204"></a>00204     ily=cpl_image_get_size_y(im);
+<a name="l00205"></a>00205 
+<a name="l00206"></a>00206     pmdata=cpl_image_get_data_float(mask);
+<a name="l00207"></a>00207     pidata=cpl_image_get_data_float(im);
+<a name="l00208"></a>00208 
+<a name="l00209"></a>00209     <span class="keywordflow">if</span> ( mlx != ilx || mly != ily )
+<a name="l00210"></a>00210     {
+<a name="l00211"></a>00211         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" data & mask images not compatible in size\n"</span>) ;
+<a name="l00212"></a>00212         <span class="keywordflow">return</span> NULL ;
+<a name="l00213"></a>00213     }
+<a name="l00214"></a>00214 
+<a name="l00215"></a>00215     <span class="comment">/* allocate memory for sub cubes*/</span>
+<a name="l00216"></a>00216     szx = (rx * 2 ) + 1;
+<a name="l00217"></a>00217     szy = (ry * 2 ) + 1;
+<a name="l00218"></a>00218     szz = (rz * 2 ) + 1;
+<a name="l00219"></a>00219 
+<a name="l00220"></a>00220     <span class="keywordflow">if</span> ( NULL == ( sc_im = cpl_imagelist_new() ) )
+<a name="l00221"></a>00221     {
+<a name="l00222"></a>00222         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" could not allocate memory for data subcube\n"</span>) ;
+<a name="l00223"></a>00223         <span class="keywordflow">return</span> NULL ;
+<a name="l00224"></a>00224     }
+<a name="l00225"></a>00225 
+<a name="l00226"></a>00226     <span class="keywordflow">for</span>(i=0;i<szz;i++) {
+<a name="l00227"></a>00227       sc_img=cpl_image_new(szx,szy,CPL_TYPE_FLOAT);
+<a name="l00228"></a>00228       cpl_imagelist_set(sc_im,sc_img,i);
+<a name="l00229"></a>00229     }
+<a name="l00230"></a>00230 
+<a name="l00231"></a>00231     <span class="keywordflow">if</span> ( NULL == ( drs_sc_mask = cpl_imagelist_new() ) )
+<a name="l00232"></a>00232     {
+<a name="l00233"></a>00233         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" could not allocate memory for mask subcube\n"</span>) ;
+<a name="l00234"></a>00234         <span class="keywordflow">return</span> NULL ;
+<a name="l00235"></a>00235     }
+<a name="l00236"></a>00236     <span class="keywordflow">for</span>(i=0;i<szz;i++) {
+<a name="l00237"></a>00237       drs_img=cpl_image_new(szx,szy,CPL_TYPE_FLOAT);
+<a name="l00238"></a>00238       cpl_imagelist_set(drs_sc_mask,drs_img,i);
+<a name="l00239"></a>00239     }
+<a name="l00240"></a>00240 
+<a name="l00241"></a>00241     <span class="keywordflow">if</span> ( NULL == ( tempMask = cpl_image_new(mlx, mly, CPL_TYPE_FLOAT) ) )
+<a name="l00242"></a>00242     {
+<a name="l00243"></a>00243         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"could not allocate memory for temporary "</span>
+<a name="l00244"></a>00244                         <span class="stringliteral">"dead pixel mask\n"</span>) ;
+<a name="l00245"></a>00245         <span class="keywordflow">return</span> NULL ;
+<a name="l00246"></a>00246     }
+<a name="l00247"></a>00247     ptdata=cpl_image_get_data_float(tempMask);
+<a name="l00248"></a>00248 
+<a name="l00249"></a>00249     count=0;
+<a name="l00250"></a>00250     <span class="keywordflow">for</span> ( i = 0 ; i < mlx; i++ )
+<a name="l00251"></a>00251     {
+<a name="l00252"></a>00252         <span class="keywordflow">for</span> ( j = 0 ; j < mly ; j++ )
+<a name="l00253"></a>00253         {
+<a name="l00254"></a>00254         <span class="keywordflow">if</span> ( pmdata[sinfo_im_xy(im,i,j)] ==  cubePT_BADPIXEL )
+<a name="l00255"></a>00255         {
+<a name="l00256"></a>00256           rx_loop = 1 ; ry_loop = 1 ; rz_loop = 1 ;
+<a name="l00257"></a>00257           pidata[sinfo_im_xy(im,i,j)] =
+<a name="l00258"></a>00258                    sinfo_new_c_bezier_correct_pixel( i, j, im, mask, sc_im,
+<a name="l00259"></a>00259                                drs_sc_mask, look, rx_loop, ry_loop, rz_loop );
+<a name="l00260"></a>00260           <span class="comment">/* if not enough neighbors found, increase size of sub</span>
+<a name="l00261"></a>00261 <span class="comment">                     cube until max radius is reached */</span>
+<a name="l00262"></a>00262           <span class="keywordflow">while</span> ( pidata[sinfo_im_xy(im,i,j)] == cubeNONEIGHBOR &&
+<a name="l00263"></a>00263                           rx_loop < rx && ry_loop < ry && rz_loop < rz )
+<a name="l00264"></a>00264             {
+<a name="l00265"></a>00265               rx_loop++ ; ry_loop++; rz_loop++;
+<a name="l00266"></a>00266               <span class="comment">/* sinfo_msg_warning("Increasing radius to %d, in %d %d",</span>
+<a name="l00267"></a>00267 <span class="comment">                                            rx_loop, i, j) ; */</span>
+<a name="l00268"></a>00268 
+<a name="l00269"></a>00269               pidata[sinfo_im_xy(im,i,j)] =
+<a name="l00270"></a>00270                         sinfo_new_c_bezier_correct_pixel( i, j, im, mask, sc_im,
+<a name="l00271"></a>00271                                 drs_sc_mask, look, rx_loop, ry_loop, rz_loop );
+<a name="l00272"></a>00272             }
+<a name="l00273"></a>00273           <span class="comment">/* If still not enough neighbors, make result NaN = ZERO</span>
+<a name="l00274"></a>00274 <span class="comment">                     in spred convention */</span>
+<a name="l00275"></a>00275           <span class="keywordflow">if</span> ( pidata[sinfo_im_xy(im,i,j)] == cubeNONEIGHBOR )
+<a name="l00276"></a>00276             {
+<a name="l00277"></a>00277               pidata[sinfo_im_xy(im,i,j)] = ZERO ;
+<a name="l00278"></a>00278             }
+<a name="l00279"></a>00279         count++;
+<a name="l00280"></a>00280         }
+<a name="l00281"></a>00281         <span class="keywordflow">if</span> ( pidata[sinfo_im_xy(im,i,j)] == ZERO )
+<a name="l00282"></a>00282           {
+<a name="l00283"></a>00283         ptdata[sinfo_im_xy(tempMask,i,j)] = 0 ;
+<a name="l00284"></a>00284           }
+<a name="l00285"></a>00285          <span class="keywordflow">else</span>
+<a name="l00286"></a>00286           {
+<a name="l00287"></a>00287         ptdata[sinfo_im_xy(tempMask,i,j)] = 1 ;
+<a name="l00288"></a>00288           }
+<a name="l00289"></a>00289         }
+<a name="l00290"></a>00290     }
+<a name="l00291"></a>00291 
+<a name="l00292"></a>00292 
+<a name="l00293"></a>00293     sinfo_msg(<span class="stringliteral">"Replacing NaN\n"</span>);
+<a name="l00294"></a>00294     auxImage=sinfo_interpol_source_image( im, tempMask, max_rad, slit_edges );
+<a name="l00295"></a>00295     padata=cpl_image_get_data_float(auxImage);
+<a name="l00296"></a>00296     <span class="keywordflow">for</span> ( i = 0 ; i < mlx; i++ )
+<a name="l00297"></a>00297     {
+<a name="l00298"></a>00298         <span class="keywordflow">for</span> ( j = 0 ; j < mly ; j++ )
+<a name="l00299"></a>00299         {
+<a name="l00300"></a>00300 
+<a name="l00301"></a>00301         <span class="keywordflow">if</span> ( isnan(pidata[sinfo_im_xy(im,i,j)])) <span class="comment">/*<= -2e10ZERO )*/</span>
+<a name="l00302"></a>00302         {
+<a name="l00303"></a>00303           <span class="comment">/* sinfo_msg_warning("Replacing NaN -> %d %d %f\n",</span>
+<a name="l00304"></a>00304 <span class="comment">                                       i,j, padata[sinfo_im_xy(im,i,j)] ); */</span>
+<a name="l00305"></a>00305         pidata[sinfo_im_xy(im,i,j)] = padata[sinfo_im_xy(im,i,j)];
+<a name="l00306"></a>00306         }
+<a name="l00307"></a>00307         }
+<a name="l00308"></a>00308     }
+<a name="l00309"></a>00309     cpl_image_delete(auxImage);
+<a name="l00310"></a>00310     cpl_imagelist_delete(sc_im);
+<a name="l00311"></a>00311     cpl_imagelist_delete(drs_sc_mask);
+<a name="l00312"></a>00312 
+<a name="l00313"></a>00313     sinfo_msg(<span class="stringliteral">"bad pixels count: %d\n"</span>,count);
+<a name="l00314"></a>00314 
+<a name="l00315"></a>00315 
+<a name="l00316"></a>00316     <span class="keywordflow">return</span> im;
+<a name="l00317"></a>00317 }
+<a name="l00318"></a>00318 
+<a name="l00319"></a>00319 cpl_image *
+<a name="l00320"></a>00320 sinfo_new_c_bezier_find_bad( cpl_image *im,
+<a name="l00321"></a>00321                                    cpl_image *mask,
+<a name="l00322"></a>00322                                    <span class="comment">/* Lookup *look,*/</span>
+<a name="l00323"></a>00323                                    <span class="keywordtype">short</span> rx,
+<a name="l00324"></a>00324                                    <span class="keywordtype">short</span> ry,
+<a name="l00325"></a>00325                                    <span class="keywordtype">short</span> rz,
+<a name="l00326"></a>00326                        <span class="keywordtype">short</span> lowerI,
+<a name="l00327"></a>00327                                    <span class="keywordtype">short</span> highI,
+<a name="l00328"></a>00328                                    <span class="keywordtype">short</span> lowerJ,
+<a name="l00329"></a>00329                                    <span class="keywordtype">short</span> highJ,
+<a name="l00330"></a>00330                                    <span class="keywordtype">float</span> factor )
+<a name="l00331"></a>00331 {
+<a name="l00332"></a>00332 
+<a name="l00333"></a>00333     <span class="keywordtype">int</span> i,j,count;
+<a name="l00334"></a>00334     cpl_imagelist * sc_im,* drs_sc_mask;
+<a name="l00335"></a>00335     <span class="keywordtype">short</span> szx,szy,szz;
+<a name="l00336"></a>00336     <span class="keywordtype">float</span> <span class="comment">/*ant,*/</span>newValue,old<span class="comment">/*,dif,porcentage,distance*/</span>;
+<a name="l00337"></a>00337     <span class="keywordtype">double</span> med, stdev;
+<a name="l00338"></a>00338     <span class="comment">/*cpl_image *out;*/</span>
+<a name="l00339"></a>00339     <span class="keywordtype">short</span> rx_loop, ry_loop, rz_loop;
+<a name="l00340"></a>00340 
+<a name="l00341"></a>00341     <span class="keywordtype">int</span> ilx=0;
+<a name="l00342"></a>00342     <span class="keywordtype">int</span> ily=0;
+<a name="l00343"></a>00343     <span class="keywordtype">int</span> mlx=0;
+<a name="l00344"></a>00344     <span class="keywordtype">int</span> mly=0;
+<a name="l00345"></a>00345 
+<a name="l00346"></a>00346     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l00347"></a>00347     <span class="keywordtype">float</span>* pmdata=NULL;
+<a name="l00348"></a>00348 
+<a name="l00349"></a>00349     cpl_image* sc_img=NULL;
+<a name="l00350"></a>00350     cpl_image* drs_img=NULL;
+<a name="l00351"></a>00351 
+<a name="l00352"></a>00352 
+<a name="l00353"></a>00353     mlx=cpl_image_get_size_x(mask);
+<a name="l00354"></a>00354     mly=cpl_image_get_size_y(mask);
+<a name="l00355"></a>00355     ilx=cpl_image_get_size_x(im);
+<a name="l00356"></a>00356     ily=cpl_image_get_size_y(im);
+<a name="l00357"></a>00357 
+<a name="l00358"></a>00358     pmdata=cpl_image_get_data_float(mask);
+<a name="l00359"></a>00359     pidata=cpl_image_get_data_float(im);
+<a name="l00360"></a>00360 
+<a name="l00361"></a>00361 
+<a name="l00362"></a>00362     <span class="keywordflow">if</span> ( mlx != ilx || mly != ily )
+<a name="l00363"></a>00363     {
+<a name="l00364"></a>00364         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" data & mask images not compatible in size\n"</span>) ;
+<a name="l00365"></a>00365         <span class="keywordflow">return</span> NULL ;
+<a name="l00366"></a>00366     }
+<a name="l00367"></a>00367 
+<a name="l00368"></a>00368     <span class="comment">/* allocate memory for sub cubes*/</span>
+<a name="l00369"></a>00369     szx = (rx * 2 ) + 1;
+<a name="l00370"></a>00370     szy = (ry * 2 ) + 1;
+<a name="l00371"></a>00371     szz = (rz * 2 ) + 1;
+<a name="l00372"></a>00372 
+<a name="l00373"></a>00373     <span class="keywordflow">if</span> ( NULL == ( sc_im = cpl_imagelist_new() ) )
+<a name="l00374"></a>00374     {
+<a name="l00375"></a>00375         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" could not allocate memory for data subcube\n"</span>) ;
+<a name="l00376"></a>00376         <span class="keywordflow">return</span> NULL ;
+<a name="l00377"></a>00377     }
+<a name="l00378"></a>00378     <span class="keywordflow">for</span>(i=0;i<szz;i++) {
+<a name="l00379"></a>00379       sc_img=cpl_image_new(szx,szy,CPL_TYPE_FLOAT);
+<a name="l00380"></a>00380       cpl_imagelist_set(sc_im,sc_img,i);
+<a name="l00381"></a>00381     }
+<a name="l00382"></a>00382 
+<a name="l00383"></a>00383     <span class="keywordflow">if</span> ( NULL == ( drs_sc_mask = cpl_imagelist_new() ) )
+<a name="l00384"></a>00384     {
+<a name="l00385"></a>00385         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" could not allocate memory for mask subcube\n"</span>) ;
+<a name="l00386"></a>00386         <span class="keywordflow">return</span> NULL ;
+<a name="l00387"></a>00387     }
+<a name="l00388"></a>00388     <span class="keywordflow">for</span>(i=0;i<szz;i++) {
+<a name="l00389"></a>00389       drs_img=cpl_image_new(szx,szy,CPL_TYPE_FLOAT);
+<a name="l00390"></a>00390       cpl_imagelist_set(drs_sc_mask,drs_img,i);
+<a name="l00391"></a>00391     }
+<a name="l00392"></a>00392 
+<a name="l00393"></a>00393     count=0;
+<a name="l00394"></a>00394     <span class="keywordflow">for</span> ( i = 0 ; i < mlx; i++ )
+<a name="l00395"></a>00395     {
+<a name="l00396"></a>00396         <span class="keywordflow">for</span> ( j = 0 ; j < mly ; j++ )
+<a name="l00397"></a>00397         {
+<a name="l00398"></a>00398         <span class="keywordflow">if</span> ( i >= lowerI && i < highI && j >= lowerJ && j < highJ )
+<a name="l00399"></a>00399         {
+<a name="l00400"></a>00400 
+<a name="l00401"></a>00401         rx_loop = 1 ; ry_loop = 1 ; rz_loop = 1 ;
+<a name="l00402"></a>00402         newValue = sinfo_new_c_bezier_correct_pixel_2D( i, j, im,
+<a name="l00403"></a>00403                                                                 mask,
+<a name="l00404"></a>00404                                                                 sc_im,
+<a name="l00405"></a>00405                                                                 drs_sc_mask,
+<a name="l00406"></a>00406                                                                 <span class="comment">/* look,*/</span>
+<a name="l00407"></a>00407                                                                 rx_loop,
+<a name="l00408"></a>00408                                                                 ry_loop,
+<a name="l00409"></a>00409                                                                 rz_loop,
+<a name="l00410"></a>00410                                                                 &med,
+<a name="l00411"></a>00411                                                                 &stdev,
+<a name="l00412"></a>00412                                                                 factor );
+<a name="l00413"></a>00413             <span class="comment">/* if NaN returned, increase size of sub cube</span>
+<a name="l00414"></a>00414 <span class="comment">                   until max radius is reached */</span>
+<a name="l00415"></a>00415         <span class="keywordflow">while</span> ( newValue == ZERO && rx_loop < rx &&
+<a name="l00416"></a>00416                         ry_loop < ry && rz_loop < rz )
+<a name="l00417"></a>00417             {
+<a name="l00418"></a>00418               rx_loop++ ; ry_loop++; rz_loop++;
+<a name="l00419"></a>00419               <span class="comment">/*sinfo_msg_warning("Increasing radius to %d,</span>
+<a name="l00420"></a>00420 <span class="comment">                        in %d %d", rx_loop, i, j) ;  */</span>
+<a name="l00421"></a>00421                    newValue = sinfo_new_c_bezier_correct_pixel_2D( i, j, im,
+<a name="l00422"></a>00422                                                                       mask,
+<a name="l00423"></a>00423                                                                       sc_im,
+<a name="l00424"></a>00424                                                                     drs_sc_mask,
+<a name="l00425"></a>00425                                                                     <span class="comment">/*, look*/</span>
+<a name="l00426"></a>00426                                                                     rx_loop,
+<a name="l00427"></a>00427                                                                     ry_loop,
+<a name="l00428"></a>00428                                                                     rz_loop,
+<a name="l00429"></a>00429                                                                     &med,
+<a name="l00430"></a>00430                                                                     &stdev,
+<a name="l00431"></a>00431                                                                     factor );
+<a name="l00432"></a>00432             }
+<a name="l00433"></a>00433         <span class="keywordflow">if</span> ( isnan(newValue)) <span class="comment">/*<= -3.e10 ZERO )*/</span>
+<a name="l00434"></a>00434             <span class="keywordflow">continue</span>;
+<a name="l00435"></a>00435 
+<a name="l00436"></a>00436         old = pidata[sinfo_im_xy(im,i,j)];
+<a name="l00437"></a>00437         <span class="keywordflow">if</span> ( newValue != old )
+<a name="l00438"></a>00438             {
+<a name="l00439"></a>00439             pidata[sinfo_im_xy(im,i,j)] = newValue;
+<a name="l00440"></a>00440             <span class="comment">/*sinfo_msg_warning("[%d,%d]=%f -> %f, med= %f,</span>
+<a name="l00441"></a>00441 <span class="comment">                      stdev=%f\n",i,j, old, newValue, med, stdev );*/</span>
+<a name="l00442"></a>00442             count++;
+<a name="l00443"></a>00443             }
+<a name="l00444"></a>00444         }
+<a name="l00445"></a>00445         }
+<a name="l00446"></a>00446     }
+<a name="l00447"></a>00447 
+<a name="l00448"></a>00448 
+<a name="l00449"></a>00449     sinfo_msg(<span class="stringliteral">"bad pixels count: %d\n"</span>,count);
+<a name="l00450"></a>00450 
+<a name="l00451"></a>00451 
+<a name="l00452"></a>00452     cpl_imagelist_delete(sc_im);
+<a name="l00453"></a>00453     cpl_imagelist_delete(drs_sc_mask);
+<a name="l00454"></a>00454     <span class="keywordflow">return</span> im;
+<a name="l00455"></a>00455 }
+<a name="l00456"></a>00456 
+<a name="l00457"></a>00457 <span class="keywordtype">float</span>
+<a name="l00458"></a>00458 sinfo_new_c_bezier_correct_pixel(<span class="keywordtype">int</span> ipos,
+<a name="l00459"></a>00459                                  <span class="keywordtype">int</span> jpos,
+<a name="l00460"></a>00460                                  cpl_image * im,
+<a name="l00461"></a>00461                                  cpl_image * mask,
+<a name="l00462"></a>00462                      cpl_imagelist * sc_im,
+<a name="l00463"></a>00463                                  cpl_imagelist * drs_sc_mask,
+<a name="l00464"></a>00464                                  new_Lookup * look,
+<a name="l00465"></a>00465                                  <span class="keywordtype">short</span> rx,
+<a name="l00466"></a>00466                                  <span class="keywordtype">short</span> ry,
+<a name="l00467"></a>00467                                  <span class="keywordtype">short</span> rz )
+<a name="l00468"></a>00468 {
+<a name="l00469"></a>00469     <span class="keywordtype">short</span> ic, jc, kc, ii, jj, kk<span class="comment">/*, sjj, skk*/</span>,is,js,ks;
+<a name="l00470"></a>00470     <span class="keywordtype">short</span> i, j, k, indexJ, indexI, lx, ly, lz, szx, szy, szz;
+<a name="l00471"></a>00471     <span class="comment">/*float indexIf,indexJf,sp;*/</span>
+<a name="l00472"></a>00472     cpl_image * X, * Y, * Z, * hX;
+<a name="l00473"></a>00473     cpl_imagelist  * id, * jd;
+<a name="l00474"></a>00474 
+<a name="l00475"></a>00475     <span class="keywordtype">int</span> idlx=0;
+<a name="l00476"></a>00476     <span class="keywordtype">int</span> idly=0;
+<a name="l00477"></a>00477     <span class="keywordtype">int</span> idnp=0;
+<a name="l00478"></a>00478 
+<a name="l00479"></a>00479     <span class="keywordtype">int</span> drslx=0;
+<a name="l00480"></a>00480     <span class="keywordtype">int</span> drsly=0;
+<a name="l00481"></a>00481     <span class="keywordtype">int</span> drsnp=0;
+<a name="l00482"></a>00482 
+<a name="l00483"></a>00483 
+<a name="l00484"></a>00484     <span class="keywordtype">float</span>* pXdata=NULL;
+<a name="l00485"></a>00485     <span class="keywordtype">float</span>* pYdata=NULL;
+<a name="l00486"></a>00486     <span class="keywordtype">float</span>* pZdata=NULL;
+<a name="l00487"></a>00487     <span class="keywordtype">float</span>* phXdata=NULL;
+<a name="l00488"></a>00488     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l00489"></a>00489     <span class="keywordtype">float</span>* pmdata=NULL;
+<a name="l00490"></a>00490     <span class="keywordtype">float</span>* piddata=NULL;
+<a name="l00491"></a>00491     <span class="keywordtype">float</span>* pjddata=NULL;
+<a name="l00492"></a>00492     <span class="keywordtype">float</span>* pscdata=NULL;
+<a name="l00493"></a>00493     <span class="keywordtype">float</span>* pdrsdata=NULL;
+<a name="l00494"></a>00494 
+<a name="l00495"></a>00495     cpl_image* id_img=NULL;
+<a name="l00496"></a>00496     cpl_image* jd_img=NULL;
+<a name="l00497"></a>00497     cpl_image* sc_img=NULL;
+<a name="l00498"></a>00498     cpl_image* drs_img=NULL;
+<a name="l00499"></a>00499 
+<a name="l00500"></a>00500     X  = look -> X;
+<a name="l00501"></a>00501     Y  = look -> Y;
+<a name="l00502"></a>00502     Z  = look -> Z;
+<a name="l00503"></a>00503     hX = look -> hX;
+<a name="l00504"></a>00504     <span class="keywordtype">id</span> = look -> id;
+<a name="l00505"></a>00505     jd = look -> jd;
+<a name="l00506"></a>00506 
+<a name="l00507"></a>00507     <span class="comment">/*</span>
+<a name="l00508"></a>00508 <span class="comment">      phXdata=cpl_image_get_data_float(hX);</span>
+<a name="l00509"></a>00509 <span class="comment">      if ( phXdata[sinfo_im_xy( hX, ipos, jpos)] > 1 )</span>
+<a name="l00510"></a>00510 <span class="comment">    {</span>
+<a name="l00511"></a>00511 <span class="comment">    sinfo_msg_error(" double hit in position [%d,%d]=%f, "</span>
+<a name="l00512"></a>00512 <span class="comment">                        "can not correct\n",</span>
+<a name="l00513"></a>00513 <span class="comment">        ipos,jpos,phXdata[sinfo_im_xy(hX,ipos,jpos)]) ;</span>
+<a name="l00514"></a>00514 <span class="comment">    return ( -2e10 );</span>
+<a name="l00515"></a>00515 <span class="comment">    }*/</span>
+<a name="l00516"></a>00516 
+<a name="l00517"></a>00517     pidata=cpl_image_get_data_float(im);
+<a name="l00518"></a>00518     pmdata=cpl_image_get_data_float(mask);
+<a name="l00519"></a>00519 
+<a name="l00520"></a>00520     phXdata=cpl_image_get_data_float(hX);
+<a name="l00521"></a>00521     <span class="keywordflow">if</span> ( phXdata[sinfo_im_xy( hX, ipos, jpos)] < 1 )
+<a name="l00522"></a>00522     {
+<a name="l00523"></a>00523     <span class="comment">/*sinfo_msg_error("no lookup in position [%d,%d]=%f, can not correct",</span>
+<a name="l00524"></a>00524 <span class="comment">      ipos,jpos,phXdata[sinfo_im_xy(hX,ipos,jpos)]) ;*/</span>
+<a name="l00525"></a>00525     <span class="keywordflow">return</span> ( ZERO );
+<a name="l00526"></a>00526     }
+<a name="l00527"></a>00527     pXdata=cpl_image_get_data_float(X);
+<a name="l00528"></a>00528     pYdata=cpl_image_get_data_float(Y);
+<a name="l00529"></a>00529     pZdata=cpl_image_get_data_float(Z);
+<a name="l00530"></a>00530 
+<a name="l00531"></a>00531 
+<a name="l00532"></a>00532     ic = pXdata[sinfo_im_xy( X, ipos, jpos)];
+<a name="l00533"></a>00533     jc = pYdata[sinfo_im_xy( Y, ipos, jpos)];
+<a name="l00534"></a>00534     kc = pZdata[sinfo_im_xy( Z, ipos, jpos)];
+<a name="l00535"></a>00535     <span class="comment">/*if ( !(ipos % 16 )  )*/</span>
+<a name="l00536"></a>00536 <span class="preprocessor">#ifdef DEBUG</span>
+<a name="l00537"></a>00537 <span class="preprocessor"></span>    <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"Correcting bad pixel : ipos=%d,jpos=%d, "</span>
+<a name="l00538"></a>00538                     <span class="stringliteral">"in Cube -> ic=%d, jc=%d, kc=%d\n"</span>,
+<a name="l00539"></a>00539                     ipos,jpos, ic, jc, kc );
+<a name="l00540"></a>00540 <span class="preprocessor">#endif</span>
+<a name="l00541"></a>00541 <span class="preprocessor"></span>    <span class="comment">/*limit to start not before the beginning of the cube*/</span>
+<a name="l00542"></a>00542     ii = ic - rx; <span class="keywordflow">if</span> ( ii < 0 ) ii = 0;
+<a name="l00543"></a>00543     jj = jc - ry; <span class="keywordflow">if</span> ( jj < 0 ) jj = 0;
+<a name="l00544"></a>00544     kk = kc - rz; <span class="keywordflow">if</span> ( kk < 0 ) kk = 0;
+<a name="l00545"></a>00545 
+<a name="l00546"></a>00546 <span class="preprocessor">#ifdef DEBUG</span>
+<a name="l00547"></a>00547 <span class="preprocessor"></span>    <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"Start Point in Cube -> ii=%d,jj=%d,kk=%d\n"</span>, ii, jj, kk );
+<a name="l00548"></a>00548 <span class="preprocessor">#endif</span>
+<a name="l00549"></a>00549 <span class="preprocessor"></span>
+<a name="l00550"></a>00550     <span class="comment">/*limit to end not outside of the cube */</span>
+<a name="l00551"></a>00551     szx = (rx * 2 ) + 1;
+<a name="l00552"></a>00552     szy = (ry * 2 ) + 1;
+<a name="l00553"></a>00553     szz = (rz * 2 ) + 1;
+<a name="l00554"></a>00554 
+<a name="l00555"></a>00555     idlx=cpl_image_get_size_x(cpl_imagelist_get(<span class="keywordtype">id</span>,0));
+<a name="l00556"></a>00556     idly=cpl_image_get_size_y(cpl_imagelist_get(<span class="keywordtype">id</span>,0));
+<a name="l00557"></a>00557     idnp=cpl_imagelist_get_size(<span class="keywordtype">id</span>);
+<a name="l00558"></a>00558 
+<a name="l00559"></a>00559     lx = idlx;
+<a name="l00560"></a>00560     ly = idly;
+<a name="l00561"></a>00561     lz = idnp;
+<a name="l00562"></a>00562 
+<a name="l00563"></a>00563     <span class="keywordflow">if</span> ( ( ic + rx ) >= idlx )
+<a name="l00564"></a>00564     szx = szx - ( (ic+rx)-(lx-1) );
+<a name="l00565"></a>00565 
+<a name="l00566"></a>00566     <span class="keywordflow">if</span> ( ( jc + ry ) >= idly )
+<a name="l00567"></a>00567     szy = szy - ( (jc+ry)-(ly-1) );
+<a name="l00568"></a>00568 
+<a name="l00569"></a>00569     <span class="keywordflow">if</span> ( ( kc + rz ) >= idnp )
+<a name="l00570"></a>00570     szz = szz - ( (kc+rz)-(lz-1) );
+<a name="l00571"></a>00571 
+<a name="l00572"></a>00572     drslx=cpl_image_get_size_x(cpl_imagelist_get(drs_sc_mask,0));
+<a name="l00573"></a>00573     drsly=cpl_image_get_size_y(cpl_imagelist_get(drs_sc_mask,0));
+<a name="l00574"></a>00574     drsnp=cpl_imagelist_get_size(drs_sc_mask);
+<a name="l00575"></a>00575 <span class="preprocessor">#ifdef DEBUG</span>
+<a name="l00576"></a>00576 <span class="preprocessor"></span>
+<a name="l00577"></a>00577 
+<a name="l00578"></a>00578     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Size of subcube: szx=%d,szy=%d,szz=%d\n"</span>, szx, szy, szz );
+<a name="l00579"></a>00579     <span class="comment">/*fill whole mask with not available*/</span>
+<a name="l00580"></a>00580     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Fill Mask subcube of size: %d,%d,%d, with NOINFO\n"</span>,
+<a name="l00581"></a>00581                      drslx, drsly,  drsnp);
+<a name="l00582"></a>00582 <span class="preprocessor">#endif</span>
+<a name="l00583"></a>00583 <span class="preprocessor"></span>    <span class="keywordflow">for</span>( i = 0; i < drslx; i++) {
+<a name="l00584"></a>00584       <span class="keywordflow">for</span>( j = 0; j < drsly; j++) {
+<a name="l00585"></a>00585     <span class="keywordflow">for</span>( k = 0; k < drsnp; k++) {
+<a name="l00586"></a>00586       drs_img=cpl_imagelist_get(drs_sc_mask,k);
+<a name="l00587"></a>00587           pdrsdata=cpl_image_get_data_float(drs_img);
+<a name="l00588"></a>00588       pdrsdata[sinfo_cu_xy(drs_sc_mask,i,j)] = cubePT_NOINFO;
+<a name="l00589"></a>00589     }
+<a name="l00590"></a>00590       }
+<a name="l00591"></a>00591     }
+<a name="l00592"></a>00592 
+<a name="l00593"></a>00593      <span class="keywordflow">for</span>( i = ii,is=0;  i < ii+szx; i++,is++)
+<a name="l00594"></a>00594      {
+<a name="l00595"></a>00595      <span class="keywordflow">for</span>( j = jj,js=0;  j < jj+szy; j++,js++)
+<a name="l00596"></a>00596          {
+<a name="l00597"></a>00597          <span class="keywordflow">for</span>( k = kk,ks=0;  k < kk+szz; k++,ks++)
+<a name="l00598"></a>00598          {
+<a name="l00599"></a>00599 <span class="preprocessor">#ifdef DEBUG</span>
+<a name="l00600"></a>00600 <span class="preprocessor"></span>         <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"i=%d j=%d k=%d is=%d ij=%d ik=%d"</span>,
+<a name="l00601"></a>00601                                   i,j,k,is,js,ks);
+<a name="l00602"></a>00602 <span class="preprocessor">#endif</span>
+<a name="l00603"></a>00603 <span class="preprocessor"></span>                 id_img=cpl_imagelist_get(<span class="keywordtype">id</span>,k);
+<a name="l00604"></a>00604                  jd_img=cpl_imagelist_get(jd,k);
+<a name="l00605"></a>00605                  piddata=cpl_image_get_data_float(id_img);
+<a name="l00606"></a>00606                  pjddata=cpl_image_get_data_float(jd_img);
+<a name="l00607"></a>00607 
+<a name="l00608"></a>00608                  drs_img=cpl_imagelist_get(drs_sc_mask,ks);
+<a name="l00609"></a>00609                  pdrsdata=cpl_image_get_data_float(drs_img);
+<a name="l00610"></a>00610                  sc_img=cpl_imagelist_get(sc_im,ks);
+<a name="l00611"></a>00611                  pscdata=cpl_image_get_data_float(sc_img);
+<a name="l00612"></a>00612 
+<a name="l00613"></a>00613          indexI = sinfo_new_nint( piddata[sinfo_cu_xy(<span class="keywordtype">id</span>,i,j)] );
+<a name="l00614"></a>00614          indexJ = sinfo_new_nint( pjddata[sinfo_cu_xy(jd,i,j)] );
+<a name="l00615"></a>00615          <span class="keywordflow">if</span> ( indexJ <= -1 || indexJ>=2048 || indexI == -1 )
+<a name="l00616"></a>00616            {
+<a name="l00617"></a>00617              pdrsdata[sinfo_cu_xy(drs_sc_mask,is,js)] = cubePT_NOINFO;
+<a name="l00618"></a>00618              <span class="keywordflow">continue</span>;
+<a name="l00619"></a>00619            }
+<a name="l00620"></a>00620          pscdata[sinfo_cu_xy(sc_im,is,js)]  =
+<a name="l00621"></a>00621                          pidata[sinfo_im_xy(im,indexI,indexJ)];
+<a name="l00622"></a>00622          pdrsdata[sinfo_cu_xy(drs_sc_mask,is,js)]  =
+<a name="l00623"></a>00623                          pmdata[sinfo_im_xy(mask,indexI,indexJ)];
+<a name="l00624"></a>00624 <span class="preprocessor">#ifdef DEBUG</span>
+<a name="l00625"></a>00625 <span class="preprocessor"></span>        <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"Cube i=%d, j=%d, k=%d  ;"</span>
+<a name="l00626"></a>00626                                 <span class="stringliteral">"  Sub is=%d, js=%d, ks=%d  ;"</span>
+<a name="l00627"></a>00627                                 <span class="stringliteral">"  Plane I=%d,J=%d ; mask %f ; im %f"</span>,
+<a name="l00628"></a>00628                         i, j, k, is, js, ks, indexI, indexJ,
+<a name="l00629"></a>00629                                 mask -> data[sinfo_im_xy(mask,indexI,indexJ)],
+<a name="l00630"></a>00630                                 im   -> data[sinfo_im_xy(im,indexI,indexJ)]);
+<a name="l00631"></a>00631 <span class="preprocessor">#endif</span>
+<a name="l00632"></a>00632 <span class="preprocessor"></span>
+<a name="l00633"></a>00633          }
+<a name="l00634"></a>00634          }
+<a name="l00635"></a>00635      }
+<a name="l00636"></a>00636 
+<a name="l00637"></a>00637 
+<a name="l00638"></a>00638     <span class="comment">/*signal to correct this pixel*/</span>
+<a name="l00639"></a>00639      drs_img=cpl_imagelist_get(drs_sc_mask,rz);
+<a name="l00640"></a>00640      pdrsdata=cpl_image_get_data_float(drs_img);
+<a name="l00641"></a>00641     pdrsdata[sinfo_cu_xy(drs_sc_mask,rx,ry)] = cubePT_FIND;
+<a name="l00642"></a>00642     <span class="keywordflow">return</span> ( sinfo_new_c_bezier_interpol( sc_im, drs_sc_mask ) );
+<a name="l00643"></a>00643 }
+<a name="l00644"></a>00644 
+<a name="l00645"></a>00645 <span class="keywordtype">float</span>
+<a name="l00646"></a>00646 sinfo_new_c_bezier_correct_pixel_2D(<span class="keywordtype">int</span> ipos,
+<a name="l00647"></a>00647                                     <span class="keywordtype">int</span> jpos,
+<a name="l00648"></a>00648                                     cpl_image * im,
+<a name="l00649"></a>00649                                     cpl_image * mask,
+<a name="l00650"></a>00650                         cpl_imagelist * sc_im,
+<a name="l00651"></a>00651                                     cpl_imagelist * drs_sc_mask,
+<a name="l00652"></a>00652                                     <span class="comment">/* Lookup * look,*/</span>
+<a name="l00653"></a>00653                                     <span class="keywordtype">short</span> rx, <span class="keywordtype">short</span> ry,
+<a name="l00654"></a>00654                                     <span class="keywordtype">short</span> rz ,
+<a name="l00655"></a>00655                                     <span class="keywordtype">double</span> *med ,
+<a name="l00656"></a>00656                         <span class="keywordtype">double</span> *stdev,
+<a name="l00657"></a>00657                                     <span class="keywordtype">float</span> factor )
+<a name="l00658"></a>00658 {
+<a name="l00659"></a>00659     <span class="keywordtype">short</span> ic, jc, kc, ii, jj, kk<span class="comment">/*, sjj, skk*/</span>,is,js,ks;
+<a name="l00660"></a>00660     <span class="keywordtype">short</span> i, j, k, indexJ, indexI, lx, ly, lz, szx, szy, szz;
+<a name="l00661"></a>00661     <span class="keywordtype">double</span> sum,aux;
+<a name="l00662"></a>00662     <span class="keywordtype">int</span> counter;
+<a name="l00663"></a>00663     <span class="keywordtype">float</span> sumarr[100];
+<a name="l00664"></a>00664 
+<a name="l00665"></a>00665 
+<a name="l00666"></a>00666     <span class="keywordtype">int</span> ilx=0;
+<a name="l00667"></a>00667     <span class="keywordtype">int</span> ily=0;
+<a name="l00668"></a>00668 
+<a name="l00669"></a>00669     <span class="keywordtype">int</span> drslx=0;
+<a name="l00670"></a>00670     <span class="keywordtype">int</span> drsly=0;
+<a name="l00671"></a>00671     <span class="keywordtype">int</span> drsnp=0;
+<a name="l00672"></a>00672 
+<a name="l00673"></a>00673 
+<a name="l00674"></a>00674     <span class="keywordtype">float</span>* pidata=0;
+<a name="l00675"></a>00675     <span class="keywordtype">float</span>* pmdata=0;
+<a name="l00676"></a>00676     <span class="keywordtype">float</span>* pscdata=0;
+<a name="l00677"></a>00677     <span class="keywordtype">float</span>* pdrsdata=0;
+<a name="l00678"></a>00678 
+<a name="l00679"></a>00679     cpl_image* drs_img=NULL;
+<a name="l00680"></a>00680     cpl_image* sc_img=NULL;
+<a name="l00681"></a>00681 
+<a name="l00682"></a>00682     jc = 0;
+<a name="l00683"></a>00683     ic = ipos;
+<a name="l00684"></a>00684     kc = jpos;
+<a name="l00685"></a>00685     <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"Correcting bad pixel : ipos=%d,jpos=%d, "</span>
+<a name="l00686"></a>00686                     <span class="stringliteral">"in Cube -> ic=%d, jc=%d, kc=%d"</span>, ipos,jpos, ic, jc, kc );
+<a name="l00687"></a>00687     <span class="comment">/*limit to start not before the beginning of the cube*/</span>
+<a name="l00688"></a>00688     ii = ic - rx; <span class="keywordflow">if</span> ( ii < 0 ) ii = 0;
+<a name="l00689"></a>00689     jj = jc - ry; <span class="keywordflow">if</span> ( jj < 0 ) jj = 0;
+<a name="l00690"></a>00690     kk = kc - rz; <span class="keywordflow">if</span> ( kk < 0 ) kk = 0;
+<a name="l00691"></a>00691 
+<a name="l00692"></a>00692     <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"Start Point in Cube -> ii=%d,jj=%d,kk=%d"</span>, ii, jj, kk );
+<a name="l00693"></a>00693 
+<a name="l00694"></a>00694     ilx=cpl_image_get_size_x(im);
+<a name="l00695"></a>00695     ily=cpl_image_get_size_y(im);
+<a name="l00696"></a>00696 
+<a name="l00697"></a>00697     <span class="comment">/*limit to end not outside of the cube */</span>
+<a name="l00698"></a>00698     szx = (rx * 2 ) + 1;
+<a name="l00699"></a>00699     szy = (ry * 2 ) + 1;
+<a name="l00700"></a>00700     szz = (rz * 2 ) + 1;
+<a name="l00701"></a>00701     lx = ilx;
+<a name="l00702"></a>00702     ly = ily;
+<a name="l00703"></a>00703     lz = ily;
+<a name="l00704"></a>00704     <span class="keywordflow">if</span> ( ( ic + rx ) >= ilx )
+<a name="l00705"></a>00705     szx = szx - ( (ic+rx)-(lx-1) );
+<a name="l00706"></a>00706 
+<a name="l00707"></a>00707     <span class="keywordflow">if</span> ( ( jc + ry ) >= ily )
+<a name="l00708"></a>00708     szy = szy - ( (jc+ry)-(ly-1) );
+<a name="l00709"></a>00709 
+<a name="l00710"></a>00710     <span class="keywordflow">if</span> ( ( kc + rz ) >= ily )
+<a name="l00711"></a>00711     szz = szz - ( (kc+rz)-(lz-1) );
+<a name="l00712"></a>00712 
+<a name="l00713"></a>00713 <span class="preprocessor">#ifdef DEBUG</span>
+<a name="l00714"></a>00714 <span class="preprocessor"></span>    drslx=cpl_image_get_size_x(cpl_imagelist_get(drs_sc_mask,0));
+<a name="l00715"></a>00715     drsly=cpl_image_get_size_y(cpl_imagelist_get(drs_sc_mask,0));
+<a name="l00716"></a>00716     drsnp=cpl_imagelist_get_size(drs_sc_mask);
+<a name="l00717"></a>00717     <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"Size of subcube : szx=%d,szy=%d,szz=%d"</span>, szx, szy, szz );
+<a name="l00718"></a>00718     <span class="comment">/*fill whole mask with not available*/</span>
+<a name="l00719"></a>00719     <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"Fill Mask subcube of size:%d,%d,%d, with NOINFO"</span>,
+<a name="l00720"></a>00720                     drslx, drsly,  drsnp);
+<a name="l00721"></a>00721 <span class="preprocessor">#endif</span>
+<a name="l00722"></a>00722 <span class="preprocessor"></span>    <span class="keywordflow">for</span>( i = 0; i < drslx; i++) {
+<a name="l00723"></a>00723       <span class="keywordflow">for</span>( j = 0; j < drsly; j++) {
+<a name="l00724"></a>00724     <span class="keywordflow">for</span>( k = 0; k < drsnp; k++) {
+<a name="l00725"></a>00725       drs_img=cpl_imagelist_get(drs_sc_mask,k);
+<a name="l00726"></a>00726       pdrsdata=cpl_image_get_data_float(drs_img);
+<a name="l00727"></a>00727       pdrsdata[sinfo_cu_xy(drs_sc_mask,i,j)] = cubePT_NOINFO;
+<a name="l00728"></a>00728     }
+<a name="l00729"></a>00729       }
+<a name="l00730"></a>00730     }
+<a name="l00731"></a>00731     counter = 0;
+<a name="l00732"></a>00732     sum=0;
+<a name="l00733"></a>00733     memset(sumarr,0x00,<span class="keyword">sizeof</span>(sumarr));
+<a name="l00734"></a>00734     pidata=cpl_image_get_data(im);
+<a name="l00735"></a>00735     pmdata=cpl_image_get_data(mask);
+<a name="l00736"></a>00736 
+<a name="l00737"></a>00737      <span class="keywordflow">for</span>( i = ii,is=0;  i < ii+szx; i++,is++)
+<a name="l00738"></a>00738      {
+<a name="l00739"></a>00739      <span class="keywordflow">for</span>( j = jj,js=0;  j < jj+szy; j++,js++)
+<a name="l00740"></a>00740          {
+<a name="l00741"></a>00741          <span class="keywordflow">for</span>( k = kk,ks=0;  k < kk+szz; k++,ks++)
+<a name="l00742"></a>00742          {
+<a name="l00743"></a>00743 <span class="preprocessor">#ifdef DEBUG</span>
+<a name="l00744"></a>00744 <span class="preprocessor"></span>         <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"i=%d j=%d k=%d is=%d ij=%d ik=%d"</span>,
+<a name="l00745"></a>00745                                   i,j,k,is,js,ks);
+<a name="l00746"></a>00746 <span class="preprocessor">#endif</span>
+<a name="l00747"></a>00747 <span class="preprocessor"></span>         indexI = i;
+<a name="l00748"></a>00748          indexJ = k;
+<a name="l00749"></a>00749          <span class="keywordflow">if</span> ( isnan(pidata[sinfo_im_xy(mask,indexI,indexJ)]) )
+<a name="l00750"></a>00750            pmdata[sinfo_im_xy(mask,indexI,indexJ)] = 0;
+<a name="l00751"></a>00751 
+<a name="l00752"></a>00752          <span class="keywordflow">if</span> ( pmdata[sinfo_im_xy(mask,indexI,indexJ)] == 1 &&
+<a name="l00753"></a>00753                             ( indexI != ipos || indexJ != jpos) )
+<a name="l00754"></a>00754            {
+<a name="l00755"></a>00755              <span class="comment">/*sumarr[counter] = pidata[sinfo_im_xy(im,indexI,indexJ)];*/</span>
+<a name="l00756"></a>00756              sum = sum + pidata[sinfo_im_xy(im,indexI,indexJ)];
+<a name="l00757"></a>00757              counter++;
+<a name="l00758"></a>00758            }
+<a name="l00759"></a>00759          sc_img=cpl_imagelist_get(sc_im,ks);
+<a name="l00760"></a>00760          pscdata[sinfo_cu_xy(sc_im,is,js)]=
+<a name="l00761"></a>00761                         pidata[sinfo_im_xy(im,indexI,indexJ)];
+<a name="l00762"></a>00762                  drs_img=cpl_imagelist_get(drs_sc_mask,ks);
+<a name="l00763"></a>00763                  pdrsdata=cpl_image_get_data_float(drs_img);
+<a name="l00764"></a>00764          pdrsdata[sinfo_cu_xy(drs_sc_mask,is,js)]=
+<a name="l00765"></a>00765                          pmdata[sinfo_im_xy(mask,indexI,indexJ)];
+<a name="l00766"></a>00766 <span class="preprocessor">#ifdef DEBUG</span>
+<a name="l00767"></a>00767 <span class="preprocessor"></span>         <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"Cube i=%d, j=%d, k=%d  ;  "</span>
+<a name="l00768"></a>00768                                  <span class="stringliteral">"Sub is=%d, js=%d, ks=%d  ; "</span>
+<a name="l00769"></a>00769                                 <span class="stringliteral">" Plane I=%d,J=%d ; mask %f ; im %f"</span>,
+<a name="l00770"></a>00770                         i, j, k, is, js, ks, indexI, indexJ,
+<a name="l00771"></a>00771                                 pmdata[sinfo_im_xy(mask,indexI,indexJ)],
+<a name="l00772"></a>00772                                 pidata[sinfo_im_xy(im,indexI,indexJ)]);
+<a name="l00773"></a>00773 <span class="preprocessor">#endif</span>
+<a name="l00774"></a>00774 <span class="preprocessor"></span>
+<a name="l00775"></a>00775          }
+<a name="l00776"></a>00776          }
+<a name="l00777"></a>00777      }
+<a name="l00778"></a>00778 
+<a name="l00779"></a>00779 
+<a name="l00780"></a>00780     <span class="comment">/*signal to correct this pixel*/</span>
+<a name="l00781"></a>00781     drs_img=cpl_imagelist_get(drs_sc_mask,rz);
+<a name="l00782"></a>00782     pdrsdata=cpl_image_get_data_float(drs_img);
+<a name="l00783"></a>00783     pdrsdata[sinfo_cu_xy(drs_sc_mask,rx,ry)] = cubePT_FIND;
+<a name="l00784"></a>00784     <span class="keywordflow">if</span> ( counter )
+<a name="l00786"></a>00786     *med = sum/counter;
+<a name="l00787"></a>00787     <span class="keywordflow">else</span>
+<a name="l00788"></a>00788     <span class="keywordflow">return</span>(pidata[sinfo_im_xy(im,ipos,jpos)]);
+<a name="l00789"></a>00789 
+<a name="l00790"></a>00790     <span class="comment">/*sinfo_msg_debug("%f %f %d\n",</span>
+<a name="l00791"></a>00791 <span class="comment">                      sum ,pidata[sinfo_im_xy(im,ipos,jpos)], counter);*/</span>
+<a name="l00792"></a>00792 
+<a name="l00793"></a>00793 
+<a name="l00794"></a>00794 
+<a name="l00795"></a>00795     sum =0;
+<a name="l00796"></a>00796     counter=0;
+<a name="l00797"></a>00797     <span class="keywordflow">for</span>( i = ii,is=0;  i < ii+szx; i++,is++)
+<a name="l00798"></a>00798       {
+<a name="l00799"></a>00799     <span class="keywordflow">for</span>( j = jj,js=0;  j < jj+szy; j++,js++)
+<a name="l00800"></a>00800       {
+<a name="l00801"></a>00801         <span class="keywordflow">for</span>( k = kk,ks=0;  k < kk+szz; k++,ks++)
+<a name="l00802"></a>00802           {
+<a name="l00803"></a>00803         drs_img=cpl_imagelist_get(drs_sc_mask,ks);
+<a name="l00804"></a>00804         pdrsdata=cpl_image_get_data_float(drs_img);
+<a name="l00805"></a>00805         indexI = i;
+<a name="l00806"></a>00806         indexJ = k;
+<a name="l00807"></a>00807         <span class="keywordflow">if</span> ( pdrsdata[sinfo_cu_xy(drs_sc_mask,is,js)] == 1 &&
+<a name="l00808"></a>00808                          ( indexI != ipos || indexJ != jpos) )
+<a name="l00809"></a>00809           {
+<a name="l00810"></a>00810               sc_img=cpl_imagelist_get(sc_im,ks);
+<a name="l00811"></a>00811               pscdata=cpl_image_get_data_float(sc_img);
+<a name="l00812"></a>00812 
+<a name="l00813"></a>00813             sum=sum+((pscdata[sinfo_cu_xy(drs_sc_mask,is,js)]- *med) *
+<a name="l00814"></a>00814              (pscdata[sinfo_cu_xy(drs_sc_mask,is,js)] - *med ) );
+<a name="l00815"></a>00815             counter++;
+<a name="l00816"></a>00816           }
+<a name="l00817"></a>00817           }
+<a name="l00818"></a>00818       }
+<a name="l00819"></a>00819       }
+<a name="l00820"></a>00820 
+<a name="l00821"></a>00821     aux = sum;
+<a name="l00822"></a>00822     sum   = sum / (counter - 1);
+<a name="l00823"></a>00823     *stdev = sqrt( sum );
+<a name="l00824"></a>00824 
+<a name="l00825"></a>00825     <span class="keywordflow">if</span> ( (fabs( pidata[sinfo_im_xy(im,ipos,jpos)] - *med ) >
+<a name="l00826"></a>00826          factor * *stdev) ||
+<a name="l00827"></a>00827      isnan(pidata[sinfo_im_xy(im,ipos,jpos)]) )
+<a name="l00828"></a>00828     {
+<a name="l00829"></a>00829     <span class="comment">/*sinfo_msg_debug("[%d,%d]: distance to mean = %f,"</span>
+<a name="l00830"></a>00830 <span class="comment">                          " thres =%f sum=%f, stdev=%f, counter=%d, aux= %f",</span>
+<a name="l00831"></a>00831 <span class="comment">                ipos,jpos, fabs( pidata[sinfo_im_xy(im,ipos,jpos)] - *med),</span>
+<a name="l00832"></a>00832 <span class="comment">                    factor * *stdev, sum,*stdev, counter,aux );</span>
+<a name="l00833"></a>00833 <span class="comment">    pmdata[sinfo_im_xy(mask,ipos,jpos)] = 0;*/</span>
+<a name="l00834"></a>00834     <span class="keywordflow">return</span> ( sinfo_new_c_bezier_interpol( sc_im, drs_sc_mask ) );
+<a name="l00835"></a>00835     }
+<a name="l00836"></a>00836     <span class="keywordflow">return</span>(pidata[sinfo_im_xy(im,ipos,jpos)]);
+<a name="l00837"></a>00837 }
+<a name="l00838"></a>00838 
+<a name="l00839"></a>00839 
+<a name="l00840"></a>00840 
+<a name="l00841"></a>00841 <span class="keywordtype">float</span>
+<a name="l00842"></a>00842 sinfo_new_c_bezier_interpol( cpl_imagelist * im, cpl_imagelist * action )
+<a name="l00843"></a>00843 {
+<a name="l00844"></a>00844     <span class="keywordtype">short</span> pos;
+<a name="l00845"></a>00845     <span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> i,j,k;
+<a name="l00846"></a>00846     new_XYZW  indata[1000];
+<a name="l00847"></a>00847     new_XYZW  res;
+<a name="l00848"></a>00848     new_XYZW  selected;
+<a name="l00849"></a>00849     <span class="keywordtype">float</span> step,cumstep,distance,selected_distance;
+<a name="l00850"></a>00850     new_Dim *point=NULL;
+<a name="l00851"></a>00851     <span class="keywordtype">double</span> munk;
+<a name="l00852"></a>00852     <span class="keywordtype">int</span> ilx=0;
+<a name="l00853"></a>00853     <span class="keywordtype">int</span> ily=0;
+<a name="l00854"></a>00854     <span class="keywordtype">int</span> inp=0;
+<a name="l00855"></a>00855 
+<a name="l00856"></a>00856     <span class="keywordtype">float</span>* padata=NULL;
+<a name="l00857"></a>00857     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l00858"></a>00858     cpl_image* i_img=NULL;
+<a name="l00859"></a>00859     cpl_image* a_img=NULL;
+<a name="l00860"></a>00860 
+<a name="l00861"></a>00861     selected.w = 0;
+<a name="l00862"></a>00862     memset(indata,0x00,1000*<span class="keyword">sizeof</span>(new_XYZW));
+<a name="l00863"></a>00863     ilx=cpl_image_get_size_x(cpl_imagelist_get(im,0));
+<a name="l00864"></a>00864     ily=cpl_image_get_size_y(cpl_imagelist_get(im,0));
+<a name="l00865"></a>00865     inp=cpl_imagelist_get_size(im);
+<a name="l00866"></a>00866 
+<a name="l00867"></a>00867     pos=0;
+<a name="l00868"></a>00868     <span class="keywordflow">for</span>( i=0; i < ilx; i++)
+<a name="l00869"></a>00869     {
+<a name="l00870"></a>00870     <span class="keywordflow">for</span>( j=0; j < ily; j++)
+<a name="l00871"></a>00871         {
+<a name="l00872"></a>00872         <span class="keywordflow">for</span>( k=0; k < inp; k++)
+<a name="l00873"></a>00873         {
+<a name="l00874"></a>00874           a_img=cpl_imagelist_get(action,k);
+<a name="l00875"></a>00875                   padata=cpl_image_get_data_float(a_img);
+<a name="l00876"></a>00876           i_img=cpl_imagelist_get(action,k);
+<a name="l00877"></a>00877                   pidata=cpl_image_get_data_float(i_img);
+<a name="l00878"></a>00878         <span class="keywordflow">if</span> ( padata[sinfo_cu_xy(action,i,j)] == cubePT_USE )
+<a name="l00879"></a>00879             {
+<a name="l00880"></a>00880 <span class="preprocessor">#ifdef DEBUG</span>
+<a name="l00881"></a>00881 <span class="preprocessor"></span>            <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"Used im[%d,%d,%d]=%lf\n"</span>,
+<a name="l00882"></a>00882                                       i,j,k,pidata[sinfo_im_xy(im,i,j)]);
+<a name="l00883"></a>00883 <span class="preprocessor">#endif</span>
+<a name="l00884"></a>00884 <span class="preprocessor"></span>            indata[pos].x = i;
+<a name="l00885"></a>00885             indata[pos].y = j;
+<a name="l00886"></a>00886             indata[pos].z = k;
+<a name="l00887"></a>00887             indata[pos].w = pidata[sinfo_cu_xy(im,i,j)];
+<a name="l00888"></a>00888             pos++;
+<a name="l00889"></a>00889             }
+<a name="l00890"></a>00890         <span class="keywordflow">else</span>
+<a name="l00891"></a>00891             {
+<a name="l00892"></a>00892             <span class="keywordflow">if</span> ( padata[sinfo_cu_xy(action,i,j)] == cubePT_FIND )
+<a name="l00893"></a>00893             {
+<a name="l00894"></a>00894                (*point).x = i;
+<a name="l00895"></a>00895                (*point).y = j;
+<a name="l00896"></a>00896                (*point).z = k;
+<a name="l00897"></a>00897 <span class="preprocessor">#ifdef DEBUG</span>
+<a name="l00898"></a>00898 <span class="preprocessor"></span>            <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"Find for im[%d,%d,%d]=%lf reason:%f"</span>,
+<a name="l00899"></a>00899                         i,j,k,pidata[sinfo_im_xy(im,i,j)],
+<a name="l00900"></a>00900                         padata[sinfo_cu_xy(action,i,j)]);
+<a name="l00901"></a>00901 <span class="preprocessor">#endif</span>
+<a name="l00902"></a>00902 <span class="preprocessor"></span>            }
+<a name="l00903"></a>00903             <span class="keywordflow">else</span>
+<a name="l00904"></a>00904             {
+<a name="l00905"></a>00905 <span class="preprocessor">#ifdef DEBUG</span>
+<a name="l00906"></a>00906 <span class="preprocessor"></span>            <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"Ignored im[%d,%d,%d]=%lf reason:%f"</span>,
+<a name="l00907"></a>00907                         i,j,k,pidata[sinfo_im_xy(im,i,j)],
+<a name="l00908"></a>00908                         padata[sinfo_im_xy(action,i,j)]);
+<a name="l00909"></a>00909 <span class="preprocessor">#endif</span>
+<a name="l00910"></a>00910 <span class="preprocessor"></span>            }
+<a name="l00911"></a>00911             }
+<a name="l00912"></a>00912         }
+<a name="l00913"></a>00913         }
+<a name="l00914"></a>00914     }
+<a name="l00915"></a>00915 
+<a name="l00916"></a>00916     
+<a name="l00917"></a>00917     <span class="keywordflow">if</span> ( pos < 2 )
+<a name="l00918"></a>00918     {
+<a name="l00919"></a>00919 <span class="preprocessor">#ifdef DEBUG</span>
+<a name="l00920"></a>00920 <span class="preprocessor"></span>       <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"subcube contains no valid pixels "</span>
+<a name="l00921"></a>00921                        <span class="stringliteral">"to use in iterpolation"</span>);
+<a name="l00922"></a>00922 <span class="preprocessor">#endif</span>
+<a name="l00923"></a>00923 <span class="preprocessor"></span>    <span class="comment">/*i_img=cpl_imagelist_get((*point).z);</span>
+<a name="l00924"></a>00924 <span class="comment">          pidata=cpl_image_get_data_float(i_img);</span>
+<a name="l00925"></a>00925 <span class="comment">          return( pidata[sinfo_im_xy(im,(*point).x,(*point).y)] );*/</span>
+<a name="l00926"></a>00926     <span class="keywordflow">return</span>( cubeNONEIGHBOR );
+<a name="l00927"></a>00927 
+<a name="l00928"></a>00928     }
+<a name="l00929"></a>00929 
+<a name="l00930"></a>00930 
+<a name="l00931"></a>00931     step    = 0.01;
+<a name="l00932"></a>00932     cumstep = 0.0;
+<a name="l00933"></a>00933     selected_distance=1000;
+<a name="l00934"></a>00934     munk = pow( 1.0-cumstep, (<span class="keywordtype">double</span>)pos - 1 );
+<a name="l00935"></a>00935     <span class="keywordflow">for</span> ( i = 0 ; ( i < 100 ) && ( munk != 0.0 ); i++ )
+<a name="l00936"></a>00936     {
+<a name="l00937"></a>00937     memset( &res, 0x00, <span class="keyword">sizeof</span>(new_XYZW) );
+<a name="l00938"></a>00938     sinfo_new_bezier( indata, pos-1, cumstep, munk, &res);
+<a name="l00939"></a>00939     distance = sqrt( pow( ((*point).x-res.x), 2)+
+<a name="l00940"></a>00940                      pow( ((*point).y-res.y), 2)+
+<a name="l00941"></a>00941                      pow( ((*point).z-res.z), 2) );
+<a name="l00942"></a>00942     <span class="comment">/*sinfo_msg_debug("%lf %lf %lf %lf %lf\n",</span>
+<a name="l00943"></a>00943 <span class="comment">                          res.x,res.y,res.z,res.w,distance);*/</span>
+<a name="l00944"></a>00944     <span class="keywordflow">if</span> ( distance < selected_distance )
+<a name="l00945"></a>00945         {
+<a name="l00946"></a>00946         selected_distance = distance;
+<a name="l00947"></a>00947         selected.x = res.x;
+<a name="l00948"></a>00948         selected.y = res.y;
+<a name="l00949"></a>00949         selected.z = res.z;
+<a name="l00950"></a>00950         selected.w = res.w;
+<a name="l00951"></a>00951         }
+<a name="l00952"></a>00952     cumstep = cumstep + step;
+<a name="l00953"></a>00953     munk = pow( 1.0 - cumstep, (<span class="keywordtype">double</span>)pos - 1 );
+<a name="l00954"></a>00954 
+<a name="l00955"></a>00955     }
+<a name="l00956"></a>00956 
+<a name="l00957"></a>00957 <span class="preprocessor">#ifdef DEBUG</span>
+<a name="l00958"></a>00958 <span class="preprocessor"></span>   <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"Selected %lf %lf %lf %lf, distance=%lf"</span>,
+<a name="l00959"></a>00959                     selected.x,selected.y,selected.z,
+<a name="l00960"></a>00960                     selected.w,selected_distance);
+<a name="l00961"></a>00961 <span class="preprocessor">#endif</span>
+<a name="l00962"></a>00962 <span class="preprocessor"></span>   i_img=cpl_imagelist_get(im,(*point).z);
+<a name="l00963"></a>00963     pidata=cpl_image_get_data_float(i_img);
+<a name="l00964"></a>00964     pidata[sinfo_cu_xy(im,(*point).x,(*point).y)] = selected.w;
+<a name="l00965"></a>00965 
+<a name="l00966"></a>00966     <span class="keywordflow">return</span> selected.w;
+<a name="l00967"></a>00967 }
+<a name="l00968"></a>00968 
+<a name="l00969"></a>00969 
+<a name="l00970"></a>00970 
+<a name="l00971"></a>00971 <span class="keywordtype">int</span>
+<a name="l00972"></a>00972 sinfo_new_bezier(new_XYZW *p,<span class="keywordtype">int</span> n,<span class="keywordtype">double</span> mu,<span class="keywordtype">double</span> munk,new_XYZW *res )
+<a name="l00973"></a>00973 {
+<a name="l00974"></a>00974    <span class="keywordtype">int</span> k, kn, nn, nkn;
+<a name="l00975"></a>00975    <span class="keywordtype">double</span> blend, muk;
+<a name="l00976"></a>00976 
+<a name="l00977"></a>00977    muk = 1;
+<a name="l00978"></a>00978    <span class="keywordflow">for</span> ( k = 0; k <= n; k++ ) {
+<a name="l00979"></a>00979       nn = n;
+<a name="l00980"></a>00980       kn = k;
+<a name="l00981"></a>00981       nkn = n - k;
+<a name="l00982"></a>00982       blend = muk * munk;
+<a name="l00983"></a>00983       muk *= mu;
+<a name="l00984"></a>00984       munk /= ( 1.0 - mu );
+<a name="l00985"></a>00985       <span class="keywordflow">while</span> ( nn >= 1 ) {
+<a name="l00986"></a>00986          blend *= (double)nn;
+<a name="l00987"></a>00987          nn--;
+<a name="l00988"></a>00988          <span class="keywordflow">if</span> ( kn > 1 ) {
+<a name="l00989"></a>00989             blend /= (double)kn;
+<a name="l00990"></a>00990             kn--;
+<a name="l00991"></a>00991          }
+<a name="l00992"></a>00992          <span class="keywordflow">if</span> ( nkn > 1 ) {
+<a name="l00993"></a>00993             blend /= (double)nkn;
+<a name="l00994"></a>00994             nkn--;
+<a name="l00995"></a>00995          }
+<a name="l00996"></a>00996       }
+<a name="l00997"></a>00997       res -> x += p[k].x * blend;
+<a name="l00998"></a>00998       res -> y += p[k].y * blend;
+<a name="l00999"></a>00999       res -> z += p[k].z * blend;
+<a name="l01000"></a>01000       res -> w += p[k].w * blend;
+<a name="l01001"></a>01001    }
+<a name="l01002"></a>01002    <span class="keywordflow">return</span>( 0 );
+<a name="l01003"></a>01003 }
+<a name="l01004"></a>01004 
+<a name="l01005"></a>01005 <span class="keywordtype">int</span>
+<a name="l01006"></a>01006 sinfo_new_c_create_XYZ( new_Lookup *l )
+<a name="l01007"></a>01007 {
+<a name="l01008"></a>01008     cpl_image *imX,*imY,*imZ,*imcX;
+<a name="l01009"></a>01009     <span class="keywordtype">short</span> i,j,k,indexI,indexJ,x,y,z;
+<a name="l01010"></a>01010     <span class="keywordtype">int</span> size;
+<a name="l01011"></a>01011     <span class="keywordtype">int</span> idlx=0;
+<a name="l01012"></a>01012     <span class="keywordtype">int</span> idly=0;
+<a name="l01013"></a>01013     <span class="keywordtype">int</span> idnp=0;
+<a name="l01014"></a>01014     <span class="keywordtype">float</span>* piddata=NULL;
+<a name="l01015"></a>01015     <span class="keywordtype">float</span>* pjddata=NULL;
+<a name="l01016"></a>01016     <span class="keywordtype">float</span>* pXdata=NULL;
+<a name="l01017"></a>01017     <span class="keywordtype">float</span>* pYdata=NULL;
+<a name="l01018"></a>01018     <span class="keywordtype">float</span>* pZdata=NULL;
+<a name="l01019"></a>01019     <span class="keywordtype">float</span>* phXdata=NULL;
+<a name="l01020"></a>01020 
+<a name="l01021"></a>01021     cpl_image* i_img=NULL;
+<a name="l01022"></a>01022     cpl_image* j_img=NULL;
+<a name="l01023"></a>01023 
+<a name="l01024"></a>01024     idlx=cpl_image_get_size_x(cpl_imagelist_get(l->id,0));
+<a name="l01025"></a>01025     idly=cpl_image_get_size_y(cpl_imagelist_get(l->id,0));
+<a name="l01026"></a>01026     idnp=cpl_imagelist_get_size(l->id);
+<a name="l01027"></a>01027 
+<a name="l01028"></a>01028     size = idlx*idly;
+<a name="l01029"></a>01029     <span class="comment">/* allocate memory */</span>
+<a name="l01030"></a>01030     <span class="keywordflow">if</span> ( NULL == (imX = cpl_image_new(size, size, CPL_TYPE_FLOAT)) )
+<a name="l01031"></a>01031         {
+<a name="l01032"></a>01032     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" could not allocate memory for X !\n"</span>) ;
+<a name="l01033"></a>01033     <span class="keywordflow">return</span> -1 ;
+<a name="l01034"></a>01034         }
+<a name="l01035"></a>01035     <span class="keywordflow">if</span> ( NULL == (imY = cpl_image_new(size, size, CPL_TYPE_FLOAT)) )
+<a name="l01036"></a>01036         {
+<a name="l01037"></a>01037     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" could not allocate memory for Y !\n"</span>) ;
+<a name="l01038"></a>01038     <span class="keywordflow">return</span> -1 ;
+<a name="l01039"></a>01039         }
+<a name="l01040"></a>01040     <span class="keywordflow">if</span> ( NULL == (imZ = cpl_image_new(size, size, CPL_TYPE_FLOAT)) )
+<a name="l01041"></a>01041         {
+<a name="l01042"></a>01042     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" could not allocate memory for Z !\n"</span>) ;
+<a name="l01043"></a>01043     <span class="keywordflow">return</span> -1 ;
+<a name="l01044"></a>01044         }
+<a name="l01045"></a>01045     <span class="keywordflow">if</span> ( NULL == (imcX = cpl_image_new(size, size, CPL_TYPE_FLOAT)) )
+<a name="l01046"></a>01046         {
+<a name="l01047"></a>01047     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" could not allocate memory for cX !\n"</span>) ;
+<a name="l01048"></a>01048     <span class="keywordflow">return</span> -1 ;
+<a name="l01049"></a>01049         }
+<a name="l01050"></a>01050 
+<a name="l01051"></a>01051     l -> X  = imX;
+<a name="l01052"></a>01052     l -> Y  = imY;
+<a name="l01053"></a>01053     l -> Z  = imZ;
+<a name="l01054"></a>01054     l -> hX = imcX;
+<a name="l01055"></a>01055 
+<a name="l01056"></a>01056     <span class="comment">/*Round id*/</span>
+<a name="l01057"></a>01057     <span class="keywordflow">for</span>( i = 0; i < idlx; i++)
+<a name="l01058"></a>01058     {
+<a name="l01059"></a>01059     <span class="keywordflow">for</span>( j = 0; j < idly; j++)
+<a name="l01060"></a>01060         {
+<a name="l01061"></a>01061         <span class="keywordflow">for</span>( k = 0; k < idnp; k++)
+<a name="l01062"></a>01062         {
+<a name="l01063"></a>01063           i_img=cpl_imagelist_get(l->id,k);
+<a name="l01064"></a>01064           piddata=cpl_image_get_data_float(i_img);
+<a name="l01065"></a>01065           piddata[sinfo_cu_xy(l->id,i,j)] =
+<a name="l01066"></a>01066                   (float)sinfo_new_nint(piddata[sinfo_cu_xy(l->id,i,j)]);
+<a name="l01067"></a>01067         }
+<a name="l01068"></a>01068         }
+<a name="l01069"></a>01069     }
+<a name="l01070"></a>01070 
+<a name="l01071"></a>01071     <span class="comment">/*Round jd*/</span>
+<a name="l01072"></a>01072     <span class="keywordflow">for</span>( i = 0; i < idlx; i++)
+<a name="l01073"></a>01073     {
+<a name="l01074"></a>01074     <span class="keywordflow">for</span>( j = 0; j < idly; j++)
+<a name="l01075"></a>01075         {
+<a name="l01076"></a>01076         <span class="keywordflow">for</span>( k = 0; k < idnp; k++)
+<a name="l01077"></a>01077         {
+<a name="l01078"></a>01078           j_img=cpl_imagelist_get(l->jd,k);
+<a name="l01079"></a>01079           pjddata=cpl_image_get_data_float(j_img);
+<a name="l01080"></a>01080           pjddata[sinfo_cu_xy(l->jd,i,j)] =
+<a name="l01081"></a>01081                  (float)sinfo_new_nint(pjddata[sinfo_cu_xy(l->jd,i,j)]);
+<a name="l01082"></a>01082         }
+<a name="l01083"></a>01083         }
+<a name="l01084"></a>01084     }
+<a name="l01085"></a>01085 
+<a name="l01086"></a>01086     <span class="comment">/*Fill with -1 X Y Z*/</span>
+<a name="l01087"></a>01087     <span class="keywordflow">for</span>( i = 0; i < cpl_image_get_size_x(l -> X); i++)
+<a name="l01088"></a>01088     {
+<a name="l01089"></a>01089     <span class="keywordflow">for</span>( j = 0; j < cpl_image_get_size_y(l -> X); j++)
+<a name="l01090"></a>01090         {
+<a name="l01091"></a>01091           pXdata=cpl_image_get_data_float(l->X);
+<a name="l01092"></a>01092           pYdata=cpl_image_get_data_float(l->Y);
+<a name="l01093"></a>01093           pZdata=cpl_image_get_data_float(l->Z);
+<a name="l01094"></a>01094 
+<a name="l01095"></a>01095           pXdata[sinfo_im_xy(l->X,i,j)] = ZERO;
+<a name="l01096"></a>01096           pYdata[sinfo_im_xy(l->Y,i,j)] = ZERO;
+<a name="l01097"></a>01097           pZdata[sinfo_im_xy(l->Z,i,j)] = ZERO;
+<a name="l01098"></a>01098         }
+<a name="l01099"></a>01099     }
+<a name="l01100"></a>01100 <span class="preprocessor">#define  FORW</span>
+<a name="l01101"></a>01101 <span class="preprocessor"></span><span class="preprocessor">#ifdef BACK</span>
+<a name="l01102"></a>01102 <span class="preprocessor"></span>    <span class="keywordflow">for</span>( x = idlx - 1;x>=0;x--)
+<a name="l01103"></a>01103     {
+<a name="l01104"></a>01104     <span class="keywordflow">for</span>( y = idly - 1;y>=0;y--)
+<a name="l01105"></a>01105         {
+<a name="l01106"></a>01106         <span class="keywordflow">for</span>( z = idnp - 1;z>=0;z--)
+<a name="l01107"></a>01107 #endif
+<a name="l01108"></a>01108 #ifdef FORW
+<a name="l01109"></a>01109     <span class="keywordflow">for</span>( x = 0; x <  idlx; x++)
+<a name="l01110"></a>01110     {
+<a name="l01111"></a>01111     <span class="keywordflow">for</span>( y = 0; y < idly; y++)
+<a name="l01112"></a>01112         {
+<a name="l01113"></a>01113         <span class="keywordflow">for</span>( z = 0; z < idnp; z++)
+<a name="l01114"></a>01114 #endif
+<a name="l01115"></a>01115           {
+<a name="l01116"></a>01116         i_img=cpl_imagelist_get(l->id,z);
+<a name="l01117"></a>01117         piddata=cpl_image_get_data_float(i_img);
+<a name="l01118"></a>01118         j_img=cpl_imagelist_get(l->jd,z);
+<a name="l01119"></a>01119         pjddata=cpl_image_get_data_float(j_img);
+<a name="l01120"></a>01120         indexI = piddata [sinfo_cu_xy(l->id,x,y)];
+<a name="l01121"></a>01121         indexJ = pjddata [sinfo_cu_xy(l->jd,x,y)];
+<a name="l01122"></a>01122         <span class="keywordflow">if</span> ( indexI > 0.0  && indexI < size  &&
+<a name="l01123"></a>01123              indexJ > 0.0  && indexJ < size )
+<a name="l01124"></a>01124             {
+<a name="l01125"></a>01125             <span class="comment">/*sinfo_msg_debug("%d %d %d = %f, %f\n",</span>
+<a name="l01126"></a>01126 <span class="comment">                      x,y,z,(float)ICube(x,y,z),(float)JCube(x,y,z));*/</span>
+<a name="l01127"></a>01127               pXdata=cpl_image_get_data_float(l->X);
+<a name="l01128"></a>01128               pYdata=cpl_image_get_data_float(l->Y);
+<a name="l01129"></a>01129               pZdata=cpl_image_get_data_float(l->Z);
+<a name="l01130"></a>01130               phXdata=cpl_image_get_data_float(l->hX);
+<a name="l01131"></a>01131 
+<a name="l01132"></a>01132               pXdata[sinfo_im_xy(l->X ,indexI,indexJ)] = x;
+<a name="l01133"></a>01133               phXdata[sinfo_im_xy(l->hX,indexI,indexJ)] =
+<a name="l01134"></a>01134                          phXdata[sinfo_im_xy(l->hX,indexI,indexJ)] + 1;
+<a name="l01135"></a>01135 
+<a name="l01136"></a>01136             pYdata[sinfo_im_xy(l->Y ,indexI,indexJ)] = y;
+<a name="l01137"></a>01137             <span class="comment">/*phXdata[sinfo_im_xy(l->hX,indexI,indexJ)] =</span>
+<a name="l01138"></a>01138 <span class="comment">                      phXdata[sinfo_im_xy(l->hX,indexI,indexJ)] + 1;*/</span>
+<a name="l01139"></a>01139 
+<a name="l01140"></a>01140             pZdata[sinfo_im_xy(l->Z ,indexI,indexJ)] = z;
+<a name="l01141"></a>01141             <span class="comment">/*phXdata[sinfo_im_xy(l->hX,indexI,indexJ)] =</span>
+<a name="l01142"></a>01142 <span class="comment">                      phXdata[sinfo_im_xy(l->hX,indexI,indexJ)] + 1;*/</span>
+<a name="l01143"></a>01143             }
+<a name="l01144"></a>01144         }
+<a name="l01145"></a>01145         }
+<a name="l01146"></a>01146     }
+<a name="l01147"></a>01147 
+<a name="l01148"></a>01148 
+<a name="l01149"></a>01149     sinfo_msg(<span class="stringliteral">"Filled X Y Z , cX cY cZ 2D frames\n"</span>);
+<a name="l01150"></a>01150     <span class="keywordflow">return</span>(0);
+<a name="l01151"></a>01151 }
+<a name="l01152"></a>01152 
+<a name="l01158"></a>01158 new_Lookup *
+<a name="l01159"></a>01159 sinfo_new_lookup( <span class="keywordtype">void</span> )
+<a name="l01160"></a>01160 {
+<a name="l01161"></a>01161     new_Lookup *l;
+<a name="l01162"></a>01162     l = (new_Lookup*)cpl_calloc(1, <span class="keyword">sizeof</span>(new_Lookup));
+<a name="l01163"></a>01163     <span class="keywordflow">return</span> (l);
+<a name="l01164"></a>01164 }
+<a name="l01171"></a>01171 <span class="keywordtype">void</span>
+<a name="l01172"></a>01172 sinfo_new_destroy_lookup( new_Lookup *l )
+<a name="l01173"></a>01173 {
+<a name="l01174"></a>01174     <span class="keywordflow">if</span> ( l )
+<a name="l01175"></a>01175     cpl_free(l);
+<a name="l01176"></a>01176 }
+<a name="l01184"></a>01184 <span class="keywordtype">int</span>
+<a name="l01185"></a>01185 sinfo_new_change_mask (cpl_image * mask, cpl_image * im)
+<a name="l01186"></a>01186 {
+<a name="l01187"></a>01187     <span class="keywordtype">int</span> i ;
+<a name="l01188"></a>01188     <span class="keywordtype">int</span> mlx=0;
+<a name="l01189"></a>01189     <span class="keywordtype">int</span> mly=0;
+<a name="l01190"></a>01190     <span class="keywordtype">int</span> ilx=0;
+<a name="l01191"></a>01191     <span class="keywordtype">int</span> ily=0;
+<a name="l01192"></a>01192     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l01193"></a>01193     <span class="keywordtype">float</span>* pmdata=NULL;
+<a name="l01194"></a>01194 
+<a name="l01195"></a>01195     <span class="keywordflow">if</span> (mask == NULL || im == NULL) <span class="keywordflow">return</span> -1 ;
+<a name="l01196"></a>01196     ilx=cpl_image_get_size_x(im);
+<a name="l01197"></a>01197     ily=cpl_image_get_size_y(im);
+<a name="l01198"></a>01198     pidata=cpl_image_get_data_float(im);
+<a name="l01199"></a>01199 
+<a name="l01200"></a>01200     mlx=cpl_image_get_size_x(mask);
+<a name="l01201"></a>01201     mly=cpl_image_get_size_y(mask);
+<a name="l01202"></a>01202     pmdata=cpl_image_get_data_float(mask);
+<a name="l01203"></a>01203 
+<a name="l01204"></a>01204     <span class="keywordflow">for</span> ( i = 0 ; i < (int) ilx*ily ; i++ )
+<a name="l01205"></a>01205     {
+<a name="l01206"></a>01206         <span class="keywordflow">if</span> (isnan(pidata[i]))
+<a name="l01207"></a>01207         {
+<a name="l01208"></a>01208             pmdata[i] = 0. ;
+<a name="l01209"></a>01209         }
+<a name="l01210"></a>01210     }
+<a name="l01211"></a>01211     <span class="keywordflow">return</span> 0 ;
+<a name="l01212"></a>01212 }
+<a name="l01213"></a>01213 
+<a name="l01214"></a>01214 
+<a name="l01231"></a>01231 cpl_image *
+<a name="l01232"></a>01232 sinfo_new_c_bezier_find_cosmic( cpl_image *im,
+<a name="l01233"></a>01233                                       cpl_image *mask,
+<a name="l01234"></a>01234                                       new_Lookup *look,
+<a name="l01235"></a>01235                                       <span class="keywordtype">short</span> rx,
+<a name="l01236"></a>01236                                       <span class="keywordtype">short</span> ry,
+<a name="l01237"></a>01237                                       <span class="keywordtype">short</span> rz,
+<a name="l01238"></a>01238                           <span class="keywordtype">short</span> lowerI,
+<a name="l01239"></a>01239                                       <span class="keywordtype">short</span> highI,
+<a name="l01240"></a>01240                                       <span class="keywordtype">short</span> lowerJ,
+<a name="l01241"></a>01241                                       <span class="keywordtype">short</span> highJ,
+<a name="l01242"></a>01242                                       <span class="keywordtype">float</span> factor )
+<a name="l01243"></a>01243 {
+<a name="l01244"></a>01244 
+<a name="l01245"></a>01245     <span class="keywordtype">int</span> i,j,count;
+<a name="l01246"></a>01246     cpl_imagelist * sc_im,* drs_sc_mask;
+<a name="l01247"></a>01247     <span class="keywordtype">short</span> szx,szy,szz;
+<a name="l01248"></a>01248     <span class="keywordtype">float</span> <span class="comment">/*ant,*/</span>newValue,old<span class="comment">/*,dif,porcentage,distance*/</span>;
+<a name="l01249"></a>01249     <span class="keywordtype">double</span> med, stdev;
+<a name="l01250"></a>01250     <span class="comment">/*cpl_image *out;*/</span>
+<a name="l01251"></a>01251     <span class="keywordtype">short</span> rx_loop, ry_loop, rz_loop;
+<a name="l01252"></a>01252 
+<a name="l01253"></a>01253 
+<a name="l01254"></a>01254     cpl_image* o_img=NULL;
+<a name="l01255"></a>01255     <span class="keywordtype">float</span>* pmdata=NULL;
+<a name="l01256"></a>01256     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l01257"></a>01257 
+<a name="l01258"></a>01258 
+<a name="l01259"></a>01259 
+<a name="l01260"></a>01260     <span class="keywordtype">int</span> ilx=0;
+<a name="l01261"></a>01261     <span class="keywordtype">int</span> ily=0;
+<a name="l01262"></a>01262 
+<a name="l01263"></a>01263     <span class="keywordtype">int</span> mlx=0;
+<a name="l01264"></a>01264     <span class="keywordtype">int</span> mly=0;
+<a name="l01265"></a>01265 
+<a name="l01266"></a>01266 
+<a name="l01267"></a>01267 
+<a name="l01268"></a>01268 
+<a name="l01269"></a>01269     mlx=cpl_image_get_size_x(mask);
+<a name="l01270"></a>01270     mly=cpl_image_get_size_y(mask);
+<a name="l01271"></a>01271     pmdata=cpl_image_get_data_float(mask);
+<a name="l01272"></a>01272 
+<a name="l01273"></a>01273     ilx=cpl_image_get_size_x(im);
+<a name="l01274"></a>01274     ily=cpl_image_get_size_y(im);
+<a name="l01275"></a>01275     pidata=cpl_image_get_data_float(im);
+<a name="l01276"></a>01276 
+<a name="l01277"></a>01277     <span class="keywordflow">if</span> ( mlx != ilx || mly != ily )
+<a name="l01278"></a>01278     {
+<a name="l01279"></a>01279         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" data & mask images not compatible in size\n"</span>) ;
+<a name="l01280"></a>01280         <span class="keywordflow">return</span> NULL ;
+<a name="l01281"></a>01281     }
+<a name="l01282"></a>01282 
+<a name="l01283"></a>01283     <span class="comment">/* allocate memory for sub cubes*/</span>
+<a name="l01284"></a>01284     szx = (rx * 2 ) + 1;
+<a name="l01285"></a>01285     szy = (ry * 2 ) + 1;
+<a name="l01286"></a>01286     szz = (rz * 2 ) + 1;
+<a name="l01287"></a>01287 
+<a name="l01288"></a>01288     <span class="keywordflow">if</span> ( NULL == ( sc_im = cpl_imagelist_new() ) )
+<a name="l01289"></a>01289     {
+<a name="l01290"></a>01290         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" could not allocate memory for data subcube\n"</span>) ;
+<a name="l01291"></a>01291         <span class="keywordflow">return</span> NULL ;
+<a name="l01292"></a>01292     }
+<a name="l01293"></a>01293     <span class="keywordflow">for</span>(i=0;i<szz;i++){
+<a name="l01294"></a>01294       o_img=cpl_image_new(szx,szy,CPL_TYPE_FLOAT);
+<a name="l01295"></a>01295       cpl_imagelist_set(sc_im,o_img,i);
+<a name="l01296"></a>01296     }
+<a name="l01297"></a>01297 
+<a name="l01298"></a>01298     <span class="keywordflow">if</span> ( NULL == ( drs_sc_mask = cpl_imagelist_new() ) )
+<a name="l01299"></a>01299     {
+<a name="l01300"></a>01300         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" could not allocate memory for mask subcube\n"</span>) ;
+<a name="l01301"></a>01301         <span class="keywordflow">return</span> NULL ;
+<a name="l01302"></a>01302     }
+<a name="l01303"></a>01303 
+<a name="l01304"></a>01304     <span class="keywordflow">for</span>(i=0;i<szz;i++){
+<a name="l01305"></a>01305       o_img=cpl_image_new(szx,szy,CPL_TYPE_FLOAT);
+<a name="l01306"></a>01306       cpl_imagelist_set(drs_sc_mask,o_img,i);
+<a name="l01307"></a>01307     }
+<a name="l01308"></a>01308 
+<a name="l01309"></a>01309 
+<a name="l01310"></a>01310 
+<a name="l01311"></a>01311 
+<a name="l01312"></a>01312     count=0;
+<a name="l01313"></a>01313     <span class="keywordflow">for</span> ( i = 0 ; i < mlx; i++ )
+<a name="l01314"></a>01314     {
+<a name="l01315"></a>01315         <span class="keywordflow">for</span> ( j = 0 ; j < mly ; j++ )
+<a name="l01316"></a>01316         {
+<a name="l01317"></a>01317         <span class="keywordflow">if</span> ( i >= lowerI && i < highI && j >= lowerJ && j < highJ )
+<a name="l01318"></a>01318         {
+<a name="l01319"></a>01319 
+<a name="l01320"></a>01320         rx_loop = 1 ; ry_loop = 1 ; rz_loop = 1 ;
+<a name="l01321"></a>01321         newValue = sinfo_new_c_bezier_correct_cosmic( i, j, im,
+<a name="l01322"></a>01322                                                               mask, sc_im,
+<a name="l01323"></a>01323                                                               drs_sc_mask,
+<a name="l01324"></a>01324                                                               look,
+<a name="l01325"></a>01325                                                               rx_loop,
+<a name="l01326"></a>01326                                                               ry_loop,
+<a name="l01327"></a>01327                                                               rz_loop,
+<a name="l01328"></a>01328                                                               &med,
+<a name="l01329"></a>01329                                                               &stdev,
+<a name="l01330"></a>01330                                                               factor );
+<a name="l01331"></a>01331             <span class="comment">/* if no valid neighboors are found, increase size of</span>
+<a name="l01332"></a>01332 <span class="comment">                   sub cube until max radius is reached */</span>
+<a name="l01333"></a>01333         <span class="keywordflow">while</span> ( newValue == cubeNONEIGHBOR && rx_loop < rx &&
+<a name="l01334"></a>01334                         ry_loop < ry && rz_loop < rz )
+<a name="l01335"></a>01335             {
+<a name="l01336"></a>01336               rx_loop++ ; ry_loop++; rz_loop++;
+<a name="l01337"></a>01337               <span class="comment">/*sinfo_msg_debug("Increasing radius to %d, in %d %d",</span>
+<a name="l01338"></a>01338 <span class="comment">                          rx_loop, i, j) ;  */</span>
+<a name="l01339"></a>01339                    newValue = sinfo_new_c_bezier_correct_cosmic( i, j, im,
+<a name="l01340"></a>01340                                                                     mask,
+<a name="l01341"></a>01341                                                                     sc_im,
+<a name="l01342"></a>01342                                                                     drs_sc_mask,
+<a name="l01343"></a>01343                                                                     look,
+<a name="l01344"></a>01344                                                                     rx_loop,
+<a name="l01345"></a>01345                                                                     ry_loop,
+<a name="l01346"></a>01346                                                                     rz_loop,
+<a name="l01347"></a>01347                                                                     &med,
+<a name="l01348"></a>01348                                                                     &stdev,
+<a name="l01349"></a>01349                                                                      factor );
+<a name="l01350"></a>01350             }
+<a name="l01351"></a>01351         <span class="comment">/*give up on increasing the size*/</span>
+<a name="l01352"></a>01352         <span class="keywordflow">if</span> ( isnan(newValue) || newValue == cubeNONEIGHBOR )
+<a name="l01353"></a>01353                 <span class="comment">/*<= -3.e10 ZERO )*/</span>
+<a name="l01354"></a>01354             <span class="keywordflow">continue</span>;
+<a name="l01355"></a>01355 
+<a name="l01356"></a>01356         old = pidata[sinfo_im_xy(im,i,j)];
+<a name="l01357"></a>01357         <span class="keywordflow">if</span> ( newValue != old )
+<a name="l01358"></a>01358             {
+<a name="l01359"></a>01359             pidata[sinfo_im_xy(im,i,j)] = newValue;
+<a name="l01360"></a>01360             <span class="comment">/*sinfo_msg_debug("[%d,%d]=%f -> %f, med= %f, stdev=%f",</span>
+<a name="l01361"></a>01361 <span class="comment">                      i,j, old, newValue, med, stdev ); */</span>
+<a name="l01362"></a>01362             count++;
+<a name="l01363"></a>01363             }
+<a name="l01364"></a>01364         }
+<a name="l01365"></a>01365         }
+<a name="l01366"></a>01366     }
+<a name="l01367"></a>01367 
+<a name="l01368"></a>01368 
+<a name="l01369"></a>01369     <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"bad pixels count: %d"</span>,count);
+<a name="l01370"></a>01370 
+<a name="l01371"></a>01371 
+<a name="l01372"></a>01372     cpl_imagelist_delete(sc_im);
+<a name="l01373"></a>01373     cpl_imagelist_delete(drs_sc_mask);
+<a name="l01374"></a>01374     <span class="keywordflow">return</span> im;
+<a name="l01375"></a>01375 }
+<a name="l01376"></a>01376 
+<a name="l01377"></a>01377 
+<a name="l01395"></a>01395 <span class="keywordtype">float</span>
+<a name="l01396"></a>01396 sinfo_new_c_bezier_correct_cosmic(<span class="keywordtype">int</span> ipos,
+<a name="l01397"></a>01397                                   <span class="keywordtype">int</span> jpos,
+<a name="l01398"></a>01398                                   cpl_image * im,
+<a name="l01399"></a>01399                                   cpl_image * mask,
+<a name="l01400"></a>01400                       cpl_imagelist * sc_im,
+<a name="l01401"></a>01401                                   cpl_imagelist * drs_sc_mask,
+<a name="l01402"></a>01402                                   new_Lookup * look,
+<a name="l01403"></a>01403                                   <span class="keywordtype">short</span> rx,
+<a name="l01404"></a>01404                                   <span class="keywordtype">short</span> ry,
+<a name="l01405"></a>01405                                   <span class="keywordtype">short</span> rz ,
+<a name="l01406"></a>01406                                   <span class="keywordtype">double</span> *med ,
+<a name="l01407"></a>01407                       <span class="keywordtype">double</span> *stdev,
+<a name="l01408"></a>01408                                   <span class="keywordtype">float</span> factor )
+<a name="l01409"></a>01409 {
+<a name="l01410"></a>01410     <span class="keywordtype">short</span> ic, jc, kc, ii, jj, kk<span class="comment">/*, sjj, skk*/</span>,is,js,ks;
+<a name="l01411"></a>01411     <span class="keywordtype">short</span> i, j, k, indexJ, indexI, lx, ly, lz, szx, szy, szz;
+<a name="l01412"></a>01412     <span class="comment">/*float indexIf,indexJf,sp;*/</span>
+<a name="l01413"></a>01413     cpl_image * X, * Y, * Z, * hX;
+<a name="l01414"></a>01414     cpl_imagelist  * id, * jd;
+<a name="l01415"></a>01415     <span class="keywordtype">short</span> counter;
+<a name="l01416"></a>01416     <span class="keywordtype">double</span> sum;
+<a name="l01417"></a>01417     <span class="keywordtype">float</span>* phXdata=NULL;
+<a name="l01418"></a>01418     <span class="keywordtype">float</span>* pXdata=NULL;
+<a name="l01419"></a>01419     <span class="keywordtype">float</span>* pYdata=NULL;
+<a name="l01420"></a>01420     <span class="keywordtype">float</span>* pZdata=NULL;
+<a name="l01421"></a>01421 
+<a name="l01422"></a>01422     <span class="keywordtype">float</span>* pimdata=NULL;
+<a name="l01423"></a>01423     <span class="keywordtype">float</span>* pscdata=NULL;
+<a name="l01424"></a>01424     <span class="keywordtype">float</span>* pdrsdata=NULL;
+<a name="l01425"></a>01425     <span class="keywordtype">float</span>* piddata=NULL;
+<a name="l01426"></a>01426     <span class="keywordtype">float</span>* pjddata=NULL;
+<a name="l01427"></a>01427     <span class="keywordtype">float</span>* pmaskdata=NULL;
+<a name="l01428"></a>01428 
+<a name="l01429"></a>01429 
+<a name="l01430"></a>01430     <span class="keywordtype">int</span> idlx=0;
+<a name="l01431"></a>01431     <span class="keywordtype">int</span> idly=0;
+<a name="l01432"></a>01432     <span class="keywordtype">int</span> idnp=0;
+<a name="l01433"></a>01433 
+<a name="l01434"></a>01434     <span class="keywordtype">int</span> drslx=0;
+<a name="l01435"></a>01435     <span class="keywordtype">int</span> drsly=0;
+<a name="l01436"></a>01436     <span class="keywordtype">int</span> drsnp=0;
+<a name="l01437"></a>01437 
+<a name="l01438"></a>01438 
+<a name="l01439"></a>01439     X  = look -> X;
+<a name="l01440"></a>01440     Y  = look -> Y;
+<a name="l01441"></a>01441     Z  = look -> Z;
+<a name="l01442"></a>01442     hX = look -> hX;
+<a name="l01443"></a>01443     <span class="keywordtype">id</span> = look -> id;
+<a name="l01444"></a>01444     jd = look -> jd;
+<a name="l01445"></a>01445 
+<a name="l01446"></a>01446     phXdata=cpl_image_get_data_float(hX);
+<a name="l01447"></a>01447     <span class="comment">/*if ( phXdata[sinfo_im_xy( hX, ipos, jpos)] > 1 )</span>
+<a name="l01448"></a>01448 <span class="comment">    {</span>
+<a name="l01449"></a>01449 <span class="comment">    sinfo_msg_error("double hit in position [%d,%d]=%f, can not correct",</span>
+<a name="l01450"></a>01450 <span class="comment">        ipos,jpos,phXdata[sinfo_im_xy(hX,ipos,jpos)]) ;</span>
+<a name="l01451"></a>01451 <span class="comment">    return ( -2e10 );</span>
+<a name="l01452"></a>01452 <span class="comment">    }*/</span>
+<a name="l01453"></a>01453     <span class="keywordflow">if</span> ( phXdata[sinfo_im_xy( hX, ipos, jpos)] < 1 )
+<a name="l01454"></a>01454     {
+<a name="l01455"></a>01455     <span class="comment">/*sinfo_msg_error("no lookup  in position [%d,%d]=%f, can not correct",</span>
+<a name="l01456"></a>01456 <span class="comment">      ipos,jpos,phXdata[sinfo_im_xy(hX,ipos,jpos)]) ;*/</span>
+<a name="l01457"></a>01457     <span class="keywordflow">return</span> ( ZERO );
+<a name="l01458"></a>01458     }
+<a name="l01459"></a>01459 
+<a name="l01460"></a>01460     pXdata=cpl_image_get_data_float(X);
+<a name="l01461"></a>01461     pYdata=cpl_image_get_data_float(Y);
+<a name="l01462"></a>01462     pZdata=cpl_image_get_data_float(Z);
+<a name="l01463"></a>01463 
+<a name="l01464"></a>01464     ic = pXdata[sinfo_im_xy( X, ipos, jpos)];
+<a name="l01465"></a>01465     jc = pYdata[sinfo_im_xy( Y, ipos, jpos)];
+<a name="l01466"></a>01466     kc = pZdata[sinfo_im_xy( Z, ipos, jpos)];
+<a name="l01467"></a>01467     <span class="comment">/*if ( !(ipos % 16 )  )*/</span>
+<a name="l01468"></a>01468 <span class="preprocessor">#ifdef DEBUG</span>
+<a name="l01469"></a>01469 <span class="preprocessor"></span>    <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"Correcting bad pixel : ipos=%d,jpos=%d, "</span>
+<a name="l01470"></a>01470                     <span class="stringliteral">"in Cube -> ic=%d, jc=%d, kc=%d"</span>, ipos,jpos, ic, jc, kc );
+<a name="l01471"></a>01471 <span class="preprocessor">#endif</span>
+<a name="l01472"></a>01472 <span class="preprocessor"></span>    <span class="comment">/*limit to start not before the beginning of the cube*/</span>
+<a name="l01473"></a>01473     ii = ic - rx; <span class="keywordflow">if</span> ( ii < 0 ) ii = 0;
+<a name="l01474"></a>01474     jj = jc - ry; <span class="keywordflow">if</span> ( jj < 0 ) jj = 0;
+<a name="l01475"></a>01475     kk = kc - rz; <span class="keywordflow">if</span> ( kk < 0 ) kk = 0;
+<a name="l01476"></a>01476 
+<a name="l01477"></a>01477 <span class="preprocessor">#ifdef DEBUG</span>
+<a name="l01478"></a>01478 <span class="preprocessor"></span>    <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"Start Point in Cube -> ii=%d,jj=%d,kk=%d"</span>, ii, jj, kk );
+<a name="l01479"></a>01479 <span class="preprocessor">#endif</span>
+<a name="l01480"></a>01480 <span class="preprocessor"></span>
+<a name="l01481"></a>01481     <span class="comment">/*limit to end not outside of the cube */</span>
+<a name="l01482"></a>01482     szx = (rx * 2 ) + 1;
+<a name="l01483"></a>01483     szy = (ry * 2 ) + 1;
+<a name="l01484"></a>01484     szz = (rz * 2 ) + 1;
+<a name="l01485"></a>01485 
+<a name="l01486"></a>01486     idlx = cpl_image_get_size_x(cpl_imagelist_get(<span class="keywordtype">id</span>,0));
+<a name="l01487"></a>01487     idly = cpl_image_get_size_y(cpl_imagelist_get(<span class="keywordtype">id</span>,0));
+<a name="l01488"></a>01488     idnp = cpl_imagelist_get_size(<span class="keywordtype">id</span>);
+<a name="l01489"></a>01489 
+<a name="l01490"></a>01490     lx = idlx;
+<a name="l01491"></a>01491     ly = idly;
+<a name="l01492"></a>01492     lz = idnp;
+<a name="l01493"></a>01493     <span class="keywordflow">if</span> ( ( ic + rx ) >= idlx )
+<a name="l01494"></a>01494     szx = szx - ( (ic+rx)-(lx-1) );
+<a name="l01495"></a>01495 
+<a name="l01496"></a>01496     <span class="keywordflow">if</span> ( ( jc + ry ) >= idly )
+<a name="l01497"></a>01497     szy = szy - ( (jc+ry)-(ly-1) );
+<a name="l01498"></a>01498 
+<a name="l01499"></a>01499     <span class="keywordflow">if</span> ( ( kc + rz ) >= idnp )
+<a name="l01500"></a>01500     szz = szz - ( (kc+rz)-(lz-1) );
+<a name="l01501"></a>01501 
+<a name="l01502"></a>01502 <span class="preprocessor">#ifdef DEBUG</span>
+<a name="l01503"></a>01503 <span class="preprocessor"></span>    <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Size of subcube : szx=%d,szy=%d,szz=%d\n"</span>, szx, szy, szz );
+<a name="l01504"></a>01504     <span class="comment">/*fill whole mask with not available*/</span>
+<a name="l01505"></a>01505     drsnp=cpl_imagelist_get_size(drs_sc_mask);
+<a name="l01506"></a>01506     drslx=cpl_image_get_size_x(cpl_imagelist_get(drs_sc_mask,0));
+<a name="l01507"></a>01507     drsly=cpl_image_get_size_y(cpl_imagelist_get(drs_sc_mask,0));
+<a name="l01508"></a>01508 
+<a name="l01509"></a>01509     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Fill Mask subcube of size: %d,%d,%d, with NOINFO"</span>,
+<a name="l01510"></a>01510                      drslx, drsly,  drsnp);
+<a name="l01511"></a>01511 <span class="preprocessor">#endif</span>
+<a name="l01512"></a>01512 <span class="preprocessor"></span>    <span class="keywordflow">for</span>( i = 0; i < drslx; i++) {
+<a name="l01513"></a>01513       <span class="keywordflow">for</span>( j = 0; j < drsly; j++) {
+<a name="l01514"></a>01514     <span class="keywordflow">for</span>( k = 0; k < drsnp; k++) {
+<a name="l01515"></a>01515       pdrsdata=cpl_image_get_data_float(cpl_imagelist_get(drs_sc_mask,k));
+<a name="l01516"></a>01516       pdrsdata[sinfo_cu_xy(drs_sc_mask,i,j)] = cubePT_NOINFO;
+<a name="l01517"></a>01517     }
+<a name="l01518"></a>01518       }
+<a name="l01519"></a>01519     }
+<a name="l01520"></a>01520     pimdata=cpl_image_get_data_float(im);
+<a name="l01521"></a>01521     pmaskdata=cpl_image_get_data_float(mask);
+<a name="l01522"></a>01522     <span class="keywordflow">for</span>( i = ii,is=0;  i < ii+szx; i++,is++)
+<a name="l01523"></a>01523       {
+<a name="l01524"></a>01524     <span class="keywordflow">for</span>( j = jj,js=0;  j < jj+szy; j++,js++)
+<a name="l01525"></a>01525       {
+<a name="l01526"></a>01526         <span class="keywordflow">for</span>( k = kk,ks=0;  k < kk+szz; k++,ks++)
+<a name="l01527"></a>01527           {
+<a name="l01528"></a>01528 <span class="preprocessor">#ifdef DEBUG</span>
+<a name="l01529"></a>01529 <span class="preprocessor"></span>        <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"i=%d j=%d k=%d is=%d ij=%d ik=%d"</span>,
+<a name="l01530"></a>01530                 i,j,k,is,js,ks);
+<a name="l01531"></a>01531 <span class="preprocessor">#endif</span>
+<a name="l01532"></a>01532 <span class="preprocessor"></span>        piddata=cpl_image_get_data_float(cpl_imagelist_get(<span class="keywordtype">id</span>,k));
+<a name="l01533"></a>01533         pjddata=cpl_image_get_data_float(cpl_imagelist_get(<span class="keywordtype">id</span>,k));
+<a name="l01534"></a>01534           pdrsdata=cpl_image_get_data_float(cpl_imagelist_get(drs_sc_mask,ks));
+<a name="l01535"></a>01535                 pscdata=cpl_image_get_data_float(cpl_imagelist_get(sc_im,ks));
+<a name="l01536"></a>01536 
+<a name="l01537"></a>01537 
+<a name="l01538"></a>01538         indexI = sinfo_new_nint( piddata[sinfo_cu_xy(<span class="keywordtype">id</span>,i,j)] );
+<a name="l01539"></a>01539         indexJ = sinfo_new_nint( pjddata[sinfo_cu_xy(jd,i,j)] );
+<a name="l01540"></a>01540         <span class="keywordflow">if</span> ( indexJ <= -1 || indexJ>=2048 || indexI == -1 )
+<a name="l01541"></a>01541           {
+<a name="l01542"></a>01542             pdrsdata[sinfo_cu_xy(drs_sc_mask,is,js)] = cubePT_NOINFO;
+<a name="l01543"></a>01543             <span class="keywordflow">continue</span>;
+<a name="l01544"></a>01544           }
+<a name="l01545"></a>01545         pscdata[sinfo_cu_xy(sc_im,is,js)]=
+<a name="l01546"></a>01546                          pimdata[sinfo_im_xy(im,indexI,indexJ)];
+<a name="l01547"></a>01547         pdrsdata[sinfo_cu_xy(drs_sc_mask,is,js)]=
+<a name="l01548"></a>01548                          pmaskdata[sinfo_im_xy(mask,indexI,indexJ)];
+<a name="l01549"></a>01549 <span class="preprocessor">#ifdef DEBUG</span>
+<a name="l01550"></a>01550 <span class="preprocessor"></span>        <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"Cube i=%d, j=%d, k=%d  ; "</span>
+<a name="l01551"></a>01551                                 <span class="stringliteral">" Sub is=%d, js=%d, ks=%d  ; "</span>
+<a name="l01552"></a>01552                                 <span class="stringliteral">" Plane I=%d,J=%d ; mask %f ; im %f\n"</span>,
+<a name="l01553"></a>01553                         i, j, k, is, js, ks, indexI, indexJ,
+<a name="l01554"></a>01554                                 pmaskdata[sinfo_im_xy(mask,indexI,indexJ)],
+<a name="l01555"></a>01555                                 pimdata[sinfo_im_xy(im,indexI,indexJ)]);
+<a name="l01556"></a>01556 <span class="preprocessor">#endif</span>
+<a name="l01557"></a>01557 <span class="preprocessor"></span>
+<a name="l01558"></a>01558           }
+<a name="l01559"></a>01559       }
+<a name="l01560"></a>01560       }
+<a name="l01561"></a>01561 
+<a name="l01562"></a>01562     <span class="comment">/* ignoring the elements in the slitlet of the tested pixel */</span>
+<a name="l01563"></a>01563 
+<a name="l01564"></a>01564     <span class="keywordflow">for</span>( i = 0; i < szx; i++) {
+<a name="l01565"></a>01565       <span class="keywordflow">for</span>( k = 0;  k < szz; k++) {
+<a name="l01566"></a>01566     pdrsdata=cpl_image_get_data_float(cpl_imagelist_get(drs_sc_mask,k));
+<a name="l01567"></a>01567     pdrsdata[sinfo_cu_xy(drs_sc_mask,i,ry)] = cubePT_NOINFO;
+<a name="l01568"></a>01568       }
+<a name="l01569"></a>01569     }
+<a name="l01570"></a>01570 <span class="comment">/* now calculate mean and stdev in subcube */</span>
+<a name="l01571"></a>01571 
+<a name="l01572"></a>01572     counter = 0;
+<a name="l01573"></a>01573     sum=0;
+<a name="l01574"></a>01574     <span class="keywordflow">for</span>( i = 0; i < szx; i++)
+<a name="l01575"></a>01575       {
+<a name="l01576"></a>01576     <span class="keywordflow">for</span>( j = 0;  j < szy; j++)
+<a name="l01577"></a>01577       {
+<a name="l01578"></a>01578         <span class="keywordflow">for</span>( k = 0;  k < szz; k++)
+<a name="l01579"></a>01579           {
+<a name="l01580"></a>01580         pdrsdata=cpl_image_get_data_float(cpl_imagelist_get(drs_sc_mask,k));
+<a name="l01581"></a>01581         pscdata=cpl_image_get_data_float(cpl_imagelist_get(sc_im,k));
+<a name="l01582"></a>01582         <span class="keywordflow">if</span> (pscdata[sinfo_cu_xy(sc_im ,i ,j)] != ZERO &&
+<a name="l01583"></a>01583                     pdrsdata[sinfo_cu_xy(drs_sc_mask,i ,j)] != cubePT_NOINFO)
+<a name="l01584"></a>01584           {
+<a name="l01585"></a>01585             sum = sum + pscdata[sinfo_cu_xy(sc_im ,i ,j)];
+<a name="l01586"></a>01586             counter++;
+<a name="l01587"></a>01587           }
+<a name="l01588"></a>01588           }
+<a name="l01589"></a>01589       }
+<a name="l01590"></a>01590       }
+<a name="l01591"></a>01591 
+<a name="l01592"></a>01592     *med = sum / counter ;
+<a name="l01593"></a>01593 
+<a name="l01594"></a>01594     counter = 0;
+<a name="l01595"></a>01595     sum=0;
+<a name="l01596"></a>01596     <span class="keywordflow">for</span>( i = 0; i < szx; i++)
+<a name="l01597"></a>01597       {
+<a name="l01598"></a>01598     <span class="keywordflow">for</span>( j = 0;  j < szy; j++)
+<a name="l01599"></a>01599       {
+<a name="l01600"></a>01600         <span class="keywordflow">for</span>( k = 0;  k < szz; k++)
+<a name="l01601"></a>01601           {
+<a name="l01602"></a>01602         pscdata=cpl_image_get_data_float(cpl_imagelist_get(sc_im,k));
+<a name="l01603"></a>01603         pdrsdata=cpl_image_get_data_float(cpl_imagelist_get(drs_sc_mask,k));
+<a name="l01604"></a>01604         <span class="keywordflow">if</span> (pscdata[sinfo_cu_xy(sc_im ,i ,j)] != ZERO &&
+<a name="l01605"></a>01605                     pdrsdata[sinfo_cu_xy(drs_sc_mask,i ,j)] != cubePT_NOINFO)
+<a name="l01606"></a>01606           {
+<a name="l01607"></a>01607                sum = sum + (pscdata[sinfo_cu_xy(sc_im ,i ,j)] - *med) *
+<a name="l01608"></a>01608                                    (pscdata[sinfo_cu_xy(sc_im ,i ,j)] - *med) ;
+<a name="l01609"></a>01609                counter++;
+<a name="l01610"></a>01610           }
+<a name="l01611"></a>01611           }
+<a name="l01612"></a>01612       }
+<a name="l01613"></a>01613       }
+<a name="l01614"></a>01614 
+<a name="l01615"></a>01615     *stdev = sqrt( sum / ( counter - 1 ) );
+<a name="l01616"></a>01616 
+<a name="l01617"></a>01617 
+<a name="l01618"></a>01618     <span class="keywordflow">if</span> ( (fabs( pimdata[sinfo_im_xy(im,ipos,jpos)] - *med ) >
+<a name="l01619"></a>01619           factor * *stdev) ||
+<a name="l01620"></a>01620           isnan(pimdata[sinfo_im_xy(im,ipos,jpos)]) )
+<a name="l01621"></a>01621     {
+<a name="l01622"></a>01622     pdrsdata=cpl_image_get_data_float(cpl_imagelist_get(drs_sc_mask,rz));
+<a name="l01623"></a>01623     pdrsdata[sinfo_cu_xy(drs_sc_mask,rx,ry)] = cubePT_FIND;
+<a name="l01624"></a>01624     <span class="keywordflow">return</span> ( sinfo_new_c_bezier_interpol( sc_im, drs_sc_mask ) );
+<a name="l01625"></a>01625     }
+<a name="l01626"></a>01626     <span class="keywordflow">else</span>
+<a name="l01627"></a>01627         <span class="keywordflow">return</span>(pimdata[sinfo_im_xy(im,ipos,jpos)]);
+<a name="l01628"></a>01628 
+<a name="l01629"></a>01629 
+<a name="l01630"></a>01630 }
+<a name="l01631"></a>01631 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__new__bezier_8h_source.html b/html/sinfo__new__bezier_8h_source.html
new file mode 100644
index 0000000..c75a2f8
--- /dev/null
+++ b/html/sinfo__new__bezier_8h_source.html
@@ -0,0 +1,199 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_new_bezier.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_new_bezier.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#ifndef SINFO_NEW_BEZIER_H</span>
+<a name="l00002"></a>00002 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_NEW_BEZIER_H</span>
+<a name="l00003"></a>00003 <span class="preprocessor"></span><span class="comment">/*</span>
+<a name="l00004"></a>00004 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00005"></a>00005 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00006"></a>00006 <span class="comment"> *</span>
+<a name="l00007"></a>00007 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00008"></a>00008 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00009"></a>00009 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00010"></a>00010 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00011"></a>00011 <span class="comment"> *</span>
+<a name="l00012"></a>00012 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00013"></a>00013 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00014"></a>00014 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00015"></a>00015 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00016"></a>00016 <span class="comment"> *</span>
+<a name="l00017"></a>00017 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00018"></a>00018 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00019"></a>00019 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00020"></a>00020 <span class="comment"> */</span>
+<a name="l00021"></a>00021 <span class="comment">/*************************************************************************</span>
+<a name="l00022"></a>00022 <span class="comment">* E.S.O. - VLT project</span>
+<a name="l00023"></a>00023 <span class="comment">*</span>
+<a name="l00024"></a>00024 <span class="comment">* "@(#) $Id: sinfo_new_bezier.h,v 1.12 2007/06/06 07:10:45 amodigli Exp $"</span>
+<a name="l00025"></a>00025 <span class="comment">*</span>
+<a name="l00026"></a>00026 <span class="comment">* who       when      what</span>
+<a name="l00027"></a>00027 <span class="comment">* --------  --------  ----------------------------------------------</span>
+<a name="l00028"></a>00028 <span class="comment">* schreib  10/10/03  created</span>
+<a name="l00029"></a>00029 <span class="comment">*/</span>
+<a name="l00030"></a>00030 
+<a name="l00031"></a>00031 <span class="comment">/************************************************************************</span>
+<a name="l00032"></a>00032 <span class="comment"> * bezier.h</span>
+<a name="l00033"></a>00033 <span class="comment"> * bad pixel interpolation routines using bezier splines</span>
+<a name="l00034"></a>00034 <span class="comment"> *----------------------------------------------------------------------</span>
+<a name="l00035"></a>00035 <span class="comment"> */</span>
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="comment">/*</span>
+<a name="l00038"></a>00038 <span class="comment"> * header files</span>
+<a name="l00039"></a>00039 <span class="comment"> */</span>
+<a name="l00040"></a>00040 
+<a name="l00041"></a>00041 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include "sinfo_spectrum_ops.h"</span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00044"></a>00044 <span class="preprocessor">#include "sinfo_image_ops.h"</span>
+<a name="l00045"></a>00045 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00046"></a>00046 <span class="comment"> *                        Function ANSI C prototypes</span>
+<a name="l00047"></a>00047 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00048"></a>00048 <span class="preprocessor">#define cubeNONEIGHBOR  -1000000 </span>
+<a name="l00049"></a>00049 <span class="preprocessor"></span><span class="comment">/* define new number that indicates that not enough neighors </span>
+<a name="l00050"></a>00050 <span class="comment">   are available for sinfo_Bezier correction */</span>
+<a name="l00051"></a>00051 <span class="preprocessor">#define cubePT_BADPIXEL   0 </span><span class="comment">/*Bad pixel*/</span>
+<a name="l00052"></a>00052 <span class="preprocessor">#define cubePT_USE        1 </span><span class="comment">/*Good pixel*/</span>
+<a name="l00053"></a>00053 <span class="preprocessor">#define cubePT_FIND       2 </span><span class="comment">/*Correct that pixel*/</span>
+<a name="l00054"></a>00054 <span class="preprocessor">#define cubePT_NOINFO     3 </span>
+<a name="l00055"></a>00055 <span class="preprocessor"></span>
+<a name="l00056"></a>00056 <span class="keyword">typedef</span> <span class="keyword">struct </span>new_dim_ {
+<a name="l00057"></a>00057   <span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> x;
+<a name="l00058"></a>00058   <span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> y;
+<a name="l00059"></a>00059   <span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> z;
+<a name="l00060"></a>00060 } new_Dim;
+<a name="l00061"></a>00061 
+<a name="l00062"></a>00062 <span class="keyword">typedef</span> <span class="keyword">struct </span>new_xyzw_ {
+<a name="l00063"></a>00063   <span class="keywordtype">double</span> x;
+<a name="l00064"></a>00064   <span class="keywordtype">double</span> y;
+<a name="l00065"></a>00065   <span class="keywordtype">double</span> z;
+<a name="l00066"></a>00066   <span class="keywordtype">double</span> w;
+<a name="l00067"></a>00067 } new_XYZW;
+<a name="l00068"></a>00068 
+<a name="l00069"></a>00069 <span class="keyword">typedef</span> <span class="keyword">struct </span>new_lookup_ {
+<a name="l00070"></a>00070     cpl_image *X;
+<a name="l00071"></a>00071     cpl_image *hX;
+<a name="l00072"></a>00072     cpl_image *Y;
+<a name="l00073"></a>00073     cpl_image *Z;
+<a name="l00074"></a>00074     cpl_imagelist  *id;
+<a name="l00075"></a>00075     cpl_imagelist  *jd;
+<a name="l00076"></a>00076 } new_Lookup;
+<a name="l00077"></a>00077 
+<a name="l00078"></a>00078 
+<a name="l00079"></a>00079 <span class="keywordtype">int</span> sinfo_im_xy(cpl_image* im, <span class="keywordtype">int</span> X, <span class="keywordtype">int</span> Y); 
+<a name="l00080"></a>00080 <span class="keywordtype">int</span> sinfo_im_xyz(cpl_image* im, <span class="keywordtype">int</span> X, <span class="keywordtype">int</span> Y, <span class="keywordtype">int</span> Z); 
+<a name="l00081"></a>00081 <span class="keywordtype">int</span> sinfo_cu_xy(cpl_imagelist* cu, <span class="keywordtype">int</span> X, <span class="keywordtype">int</span> Y); 
+<a name="l00082"></a>00082 <span class="keywordtype">int</span> sinfo_cu_xyz(cpl_imagelist* cu, <span class="keywordtype">int</span> X, <span class="keywordtype">int</span> Y, <span class="keywordtype">int</span> Z); 
+<a name="l00083"></a>00083 
+<a name="l00084"></a>00084 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00085"></a>00085 <span class="comment"> *                        Function ANSI C prototypes</span>
+<a name="l00086"></a>00086 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00087"></a>00087 
+<a name="l00088"></a>00088 cpl_image * 
+<a name="l00089"></a>00089 sinfo_new_c_bezier_interpolate_image(cpl_image *im, 
+<a name="l00090"></a>00090                                           cpl_image *mask, 
+<a name="l00091"></a>00091                                           new_Lookup *look, 
+<a name="l00092"></a>00092                                           <span class="keywordtype">short</span> rx, 
+<a name="l00093"></a>00093                                           <span class="keywordtype">short</span> ry, 
+<a name="l00094"></a>00094                                           <span class="keywordtype">short</span> rz,
+<a name="l00095"></a>00095                           <span class="keywordtype">int</span> max_rad , 
+<a name="l00096"></a>00096                                           <span class="keywordtype">float</span>   ** slit_edges );
+<a name="l00097"></a>00097 
+<a name="l00098"></a>00098 cpl_image * 
+<a name="l00099"></a>00099 sinfo_new_c_bezier_find_bad(cpl_image *im, 
+<a name="l00100"></a>00100                                  cpl_image *mask<span class="comment">/*, sinfo_new_lookup *look*/</span>, 
+<a name="l00101"></a>00101                                  <span class="keywordtype">short</span> rx, 
+<a name="l00102"></a>00102                                  <span class="keywordtype">short</span> ry, 
+<a name="l00103"></a>00103                                  <span class="keywordtype">short</span> rz,
+<a name="l00104"></a>00104                      <span class="keywordtype">short</span> lowerI, 
+<a name="l00105"></a>00105                                  <span class="keywordtype">short</span> highI, 
+<a name="l00106"></a>00106                                  <span class="keywordtype">short</span> lowerJ, 
+<a name="l00107"></a>00107                                  <span class="keywordtype">short</span> highJ, 
+<a name="l00108"></a>00108                                  <span class="keywordtype">float</span> factor );
+<a name="l00109"></a>00109 
+<a name="l00110"></a>00110 
+<a name="l00111"></a>00111 <span class="keywordtype">float</span>      
+<a name="l00112"></a>00112 sinfo_new_c_bezier_correct_pixel(<span class="keywordtype">int</span> ipos, 
+<a name="l00113"></a>00113                                      <span class="keywordtype">int</span> jpos, 
+<a name="l00114"></a>00114                      cpl_image *im, 
+<a name="l00115"></a>00115                      cpl_image *mask, 
+<a name="l00116"></a>00116                      cpl_imagelist  *sc_im, 
+<a name="l00117"></a>00117                      cpl_imagelist  *drs_sc_mask, 
+<a name="l00118"></a>00118                      new_Lookup *look, 
+<a name="l00119"></a>00119                                      <span class="keywordtype">short</span> rx, 
+<a name="l00120"></a>00120                                      <span class="keywordtype">short</span> ry, 
+<a name="l00121"></a>00121                                      <span class="keywordtype">short</span> rz  );
+<a name="l00122"></a>00122 
+<a name="l00123"></a>00123 
+<a name="l00124"></a>00124 <span class="keywordtype">float</span>      
+<a name="l00125"></a>00125 sinfo_new_c_bezier_correct_pixel_2D( <span class="keywordtype">int</span> ipos ,
+<a name="l00126"></a>00126                                         <span class="keywordtype">int</span> jpos, 
+<a name="l00127"></a>00127                         cpl_image *im, 
+<a name="l00128"></a>00128                         cpl_image *mask, 
+<a name="l00129"></a>00129                         cpl_imagelist  *sc_im, 
+<a name="l00130"></a>00130                         cpl_imagelist  *drs_sc_mask, 
+<a name="l00131"></a>00131                         <span class="comment">/*new_Lookup *look,*/</span> 
+<a name="l00132"></a>00132                                         <span class="keywordtype">short</span> rx, 
+<a name="l00133"></a>00133                                         <span class="keywordtype">short</span> ry, 
+<a name="l00134"></a>00134                                         <span class="keywordtype">short</span> rz , 
+<a name="l00135"></a>00135                                         <span class="keywordtype">double</span> *med, 
+<a name="l00136"></a>00136                                         <span class="keywordtype">double</span> *stdev, 
+<a name="l00137"></a>00137                                         <span class="keywordtype">float</span> factor );
+<a name="l00138"></a>00138 
+<a name="l00139"></a>00139 <span class="keywordtype">float</span> sinfo_new_c_bezier_interpol(cpl_imagelist * im, cpl_imagelist * action );
+<a name="l00140"></a>00140 
+<a name="l00141"></a>00141 <span class="keywordtype">int</span> sinfo_new_bezier(new_XYZW *p,<span class="keywordtype">int</span> n,<span class="keywordtype">double</span> mu,<span class="keywordtype">double</span> munk,new_XYZW *res );
+<a name="l00142"></a>00142 
+<a name="l00143"></a>00143 <span class="keywordtype">float</span>      
+<a name="l00144"></a>00144 sinfo_new_c_bezier_correct_cosmic( <span class="keywordtype">int</span> ipos ,
+<a name="l00145"></a>00145                                        <span class="keywordtype">int</span> jpos,
+<a name="l00146"></a>00146                                        cpl_image *im,
+<a name="l00147"></a>00147                                        cpl_image *mask,
+<a name="l00148"></a>00148                                        cpl_imagelist  *sc_im,
+<a name="l00149"></a>00149                                        cpl_imagelist  *drs_sc_mask,
+<a name="l00150"></a>00150                                        new_Lookup *look, 
+<a name="l00151"></a>00151                                        <span class="keywordtype">short</span> rx, 
+<a name="l00152"></a>00152                                        <span class="keywordtype">short</span> ry, 
+<a name="l00153"></a>00153                                        <span class="keywordtype">short</span> rz , 
+<a name="l00154"></a>00154                                        <span class="keywordtype">double</span> *med, 
+<a name="l00155"></a>00155                                        <span class="keywordtype">double</span> *stdev, 
+<a name="l00156"></a>00156                                        <span class="keywordtype">float</span> factor );
+<a name="l00157"></a>00157 
+<a name="l00158"></a>00158 
+<a name="l00159"></a>00159 cpl_image * 
+<a name="l00160"></a>00160 sinfo_new_c_bezier_find_cosmic(cpl_image *im, 
+<a name="l00161"></a>00161                                     cpl_image *mask, 
+<a name="l00162"></a>00162                                     new_Lookup *look, 
+<a name="l00163"></a>00163                                     <span class="keywordtype">short</span> rx, 
+<a name="l00164"></a>00164                                     <span class="keywordtype">short</span> ry, 
+<a name="l00165"></a>00165                                     <span class="keywordtype">short</span> rz,
+<a name="l00166"></a>00166                                     <span class="keywordtype">short</span> lowerI, 
+<a name="l00167"></a>00167                                     <span class="keywordtype">short</span> highI, 
+<a name="l00168"></a>00168                                     <span class="keywordtype">short</span> lowerJ, 
+<a name="l00169"></a>00169                                     <span class="keywordtype">short</span> highJ, 
+<a name="l00170"></a>00170                                     <span class="keywordtype">float</span> factor );
+<a name="l00171"></a>00171 
+<a name="l00172"></a>00172 
+<a name="l00173"></a>00173 <span class="keywordtype">int</span> sinfo_new_c_create_XYZ( new_Lookup *l );
+<a name="l00174"></a>00174 
+<a name="l00175"></a>00175 new_Lookup * sinfo_new_lookup( <span class="keywordtype">void</span> ) ;
+<a name="l00176"></a>00176 
+<a name="l00177"></a>00177 <span class="keywordtype">void</span> sinfo_new_destroy_lookup( new_Lookup *l ) ;
+<a name="l00178"></a>00178 
+<a name="l00179"></a>00179 <span class="keywordtype">int</span> sinfo_new_change_mask(cpl_image * mask,cpl_image * im ) ;
+<a name="l00180"></a>00180 
+<a name="l00181"></a>00181 
+<a name="l00182"></a>00182 <span class="preprocessor">#endif </span>
+<a name="l00184"></a>00184 <span class="preprocessor"></span><span class="comment">/*--------------------------------------------------------------------------*/</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__new__cube__ops_8c_source.html b/html/sinfo__new__cube__ops_8c_source.html
new file mode 100644
index 0000000..dc12108
--- /dev/null
+++ b/html/sinfo__new__cube__ops_8c_source.html
@@ -0,0 +1,5012 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_new_cube_ops.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_new_cube_ops.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*$Id: sinfo_new_cube_ops.c,v 1.44 2012/03/03 09:50:51 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*************************************************************************</span>
+<a name="l00020"></a>00020 <span class="comment">* E.S.O. - VLT project</span>
+<a name="l00021"></a>00021 <span class="comment">*</span>
+<a name="l00022"></a>00022 <span class="comment">*</span>
+<a name="l00023"></a>00023 <span class="comment">*</span>
+<a name="l00024"></a>00024 <span class="comment">* who       when      what</span>
+<a name="l00025"></a>00025 <span class="comment">* --------  --------  ----------------------------------------------</span>
+<a name="l00026"></a>00026 <span class="comment">* schreib  17/05/00  created</span>
+<a name="l00027"></a>00027 <span class="comment">*/</span>
+<a name="l00028"></a>00028 <span class="comment">/*</span>
+<a name="l00029"></a>00029 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00030"></a>00030 <span class="comment"> * $Date: 2012/03/03 09:50:51 $</span>
+<a name="l00031"></a>00031 <span class="comment"> * $Revision: 1.44 $</span>
+<a name="l00032"></a>00032 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00033"></a>00033 <span class="comment"> */</span>
+<a name="l00034"></a>00034 
+<a name="l00035"></a>00035 <span class="comment">/************************************************************************</span>
+<a name="l00036"></a>00036 <span class="comment">*   NAME</span>
+<a name="l00037"></a>00037 <span class="comment">*       sinfo_new_cube_ops.c -</span>
+<a name="l00038"></a>00038 <span class="comment">*       cube arithmetic routines</span>
+<a name="l00039"></a>00039 <span class="comment">*</span>
+<a name="l00040"></a>00040 <span class="comment">*   SYNOPSIS</span>
+<a name="l00041"></a>00041 <span class="comment">*    #include "sinfo_new_cube_ops.h"</span>
+<a name="l00042"></a>00042 <span class="comment">*</span>
+<a name="l00043"></a>00043 <span class="comment">*</span>
+<a name="l00044"></a>00044 <span class="comment">*</span>
+<a name="l00045"></a>00045 <span class="comment">*    2) cpl_imagelist *</span>
+<a name="l00046"></a>00046 <span class="comment">*       sinfo_new_cube_ops( cpl_imagelist    *    cube1,</span>
+<a name="l00047"></a>00047 <span class="comment">*                cpl_imagelist    *    cube2,</span>
+<a name="l00048"></a>00048 <span class="comment">*                int        operation)</span>
+<a name="l00049"></a>00049 <span class="comment">*</span>
+<a name="l00050"></a>00050 <span class="comment">*    3) cpl_imagelist *</span>
+<a name="l00051"></a>00051 <span class="comment">*       sinfo_new_cube_const_ops(</span>
+<a name="l00052"></a>00052 <span class="comment">*                     cpl_imagelist    * cube1,</span>
+<a name="l00053"></a>00053 <span class="comment">*                     double    constant,</span>
+<a name="l00054"></a>00054 <span class="comment">*                     int        operation)</span>
+<a name="l00055"></a>00055 <span class="comment">*</span>
+<a name="l00056"></a>00056 <span class="comment">*    4) cpl_imagelist *</span>
+<a name="l00057"></a>00057 <span class="comment">*       sinfo_new_cube_sub(</span>
+<a name="l00058"></a>00058 <span class="comment">*               cpl_imagelist    *    c1,</span>
+<a name="l00059"></a>00059 <span class="comment">*               cpl_imagelist    *    c2 )</span>
+<a name="l00060"></a>00060 <span class="comment">*</span>
+<a name="l00061"></a>00061 <span class="comment">*    5) cpl_imagelist *</span>
+<a name="l00062"></a>00062 <span class="comment">*       sinfo_new_cube_add(</span>
+<a name="l00063"></a>00063 <span class="comment">*               cpl_imagelist    *    c1,</span>
+<a name="l00064"></a>00064 <span class="comment">*               cpl_imagelist    *    c2  )</span>
+<a name="l00065"></a>00065 <span class="comment">*    6) cpl_imagelist *</span>
+<a name="l00066"></a>00066 <span class="comment">*       sinfo_new_cube_mul(</span>
+<a name="l00067"></a>00067 <span class="comment">*               cpl_imagelist    *    c1,</span>
+<a name="l00068"></a>00068 <span class="comment">*               cpl_imagelist    *    c2 )</span>
+<a name="l00069"></a>00069 <span class="comment">*</span>
+<a name="l00070"></a>00070 <span class="comment">*    7) cpl_imagelist *</span>
+<a name="l00071"></a>00071 <span class="comment">*       sinfo_new_cube_div(</span>
+<a name="l00072"></a>00072 <span class="comment">*               cpl_imagelist    *    c1,</span>
+<a name="l00073"></a>00073 <span class="comment">*               cpl_imagelist    *    c2 )</span>
+<a name="l00074"></a>00074 <span class="comment">*</span>
+<a name="l00075"></a>00075 <span class="comment">*    8) cpl_imagelist * sinfo_new_add_image_to_cube(cpl_imagelist * cu,</span>
+<a name="l00076"></a>00076 <span class="comment">                                                    cpl_image * im)</span>
+<a name="l00077"></a>00077 <span class="comment">*</span>
+<a name="l00078"></a>00078 <span class="comment">*    9) cpl_imagelist * sinfo_new_sub_image_from_cube (cpl_imagelist * cu,</span>
+<a name="l00079"></a>00079 <span class="comment">                                                    cpl_image * im)</span>
+<a name="l00080"></a>00080 <span class="comment">*</span>
+<a name="l00081"></a>00081 <span class="comment">*    10) cpl_imagelist * sinfo_new_mul_image_to_cube(cpl_imagelist * cu,</span>
+<a name="l00082"></a>00082 <span class="comment">                                                    cpl_image * im)</span>
+<a name="l00083"></a>00083 <span class="comment">*</span>
+<a name="l00084"></a>00084 <span class="comment">*    11) cpl_imagelist * sinfo_new_div_cube_by_image(cpl_imagelist * cu,</span>
+<a name="l00085"></a>00085 <span class="comment">                                                    cpl_image * im)</span>
+<a name="l00086"></a>00086 <span class="comment">*</span>
+<a name="l00087"></a>00087 <span class="comment">*    12) cpl_imagelist * sinfo_new_add_spectrum_to_cube(cpl_imagelist *cu,</span>
+<a name="l00088"></a>00088 <span class="comment">                                                    Vector *spec)</span>
+<a name="l00089"></a>00089 <span class="comment">*</span>
+<a name="l00090"></a>00090 <span class="comment">*    13) cpl_imagelist * sinfo_new_sub_spectrum_from_cube(cpl_imagelist *cu,</span>
+<a name="l00091"></a>00091 <span class="comment">                                                    Vector *spec)</span>
+<a name="l00092"></a>00092 <span class="comment">*</span>
+<a name="l00093"></a>00093 <span class="comment">*    14) cpl_imagelist * sinfo_new_mul_spectrum_to_cube(cpl_imagelist *cu,</span>
+<a name="l00094"></a>00094 <span class="comment">                                                    Vector *spec)</span>
+<a name="l00095"></a>00095 <span class="comment">*</span>
+<a name="l00096"></a>00096 <span class="comment">*    15) cpl_imagelist * sinfo_new_div_cube_by_spectrum(cpl_imagelist *cu,</span>
+<a name="l00097"></a>00097 <span class="comment">                                                    Vector *spec)</span>
+<a name="l00098"></a>00098 <span class="comment">*</span>
+<a name="l00099"></a>00099 <span class="comment">*    16) Vector * sinfo_new_clean_mean_of_spectra(cpl_imagelist * cube,</span>
+<a name="l00100"></a>00100 <span class="comment">*                                    int llx,</span>
+<a name="l00101"></a>00101 <span class="comment">*                                    int lly,</span>
+<a name="l00102"></a>00102 <span class="comment">*                                    int urx,</span>
+<a name="l00103"></a>00103 <span class="comment">*                                    int ury,</span>
+<a name="l00104"></a>00104 <span class="comment">*                                    double lo_reject,</span>
+<a name="l00105"></a>00105 <span class="comment">*                                    double hi_reject)</span>
+<a name="l00106"></a>00106 <span class="comment">*</span>
+<a name="l00107"></a>00107 <span class="comment">*    17) cpl_image * sinfo_new_median_cube(cpl_imagelist * cube)</span>
+<a name="l00108"></a>00108 <span class="comment">*</span>
+<a name="l00109"></a>00109 <span class="comment">*    18) cpl_image * sinfo_new_average_cube_to_image(cpl_imagelist * cube)</span>
+<a name="l00110"></a>00110 <span class="comment">*</span>
+<a name="l00111"></a>00111 <span class="comment">*    19) cpl_image * sinfo_new_sum_cube_to_image(cpl_imagelist * cube)</span>
+<a name="l00112"></a>00112 <span class="comment">*</span>
+<a name="l00113"></a>00113 <span class="comment">*    20) cpl_image *</span>
+<a name="l00114"></a>00114 <span class="comment">         sinfo_new_average_cube_to_image_between_waves (cpl_imagelist * cube,</span>
+<a name="l00115"></a>00115 <span class="comment">*                                                   float     dispersion,</span>
+<a name="l00116"></a>00116 <span class="comment">*                                                   float     centralWave,</span>
+<a name="l00117"></a>00117 <span class="comment">*                                                   float     initialLambda,</span>
+<a name="l00118"></a>00118 <span class="comment">*                                                   float     finalLambda)</span>
+<a name="l00119"></a>00119 <span class="comment">*</span>
+<a name="l00120"></a>00120 <span class="comment">*    21) cpl_image * sinfo_new_extract_image_from_cube(cpl_imagelist * cube,</span>
+<a name="l00121"></a>00121 <span class="comment">                                                    int plane_index)</span>
+<a name="l00122"></a>00122 <span class="comment">*</span>
+<a name="l00123"></a>00123 <span class="comment">*    22) Vector * sinfo_new_extract_spectrum_from_cube( cpl_imagelist * cube,</span>
+<a name="l00124"></a>00124 <span class="comment">                                                    int x_pos, int y_pos )</span>
+<a name="l00125"></a>00125 <span class="comment">*    23) cpl_imagelist *</span>
+<a name="l00126"></a>00126 <span class="comment">         sinfo_new_combine_jittered_cubes ( cpl_imagelist ** cubes,</span>
+<a name="l00127"></a>00127 <span class="comment">*                                         cpl_imagelist  * mergedCube,</span>
+<a name="l00128"></a>00128 <span class="comment">*                                         int        n_cubes,</span>
+<a name="l00129"></a>00129 <span class="comment">*                                         float    * cumoffsetx,</span>
+<a name="l00130"></a>00130 <span class="comment">*                                         float    * cumoffsety,</span>
+<a name="l00131"></a>00131 <span class="comment">*                                         float    * exptimes,</span>
+<a name="l00132"></a>00132 <span class="comment">*                                         char     * kernel_type )</span>
+<a name="l00133"></a>00133 <span class="comment">*    24) cpl_imagelist * sinfo_new_interpol_cube_simple( cpl_imagelist * cube,</span>
+<a name="l00134"></a>00134 <span class="comment">*                                      cpl_imagelist * badcube,</span>
+<a name="l00135"></a>00135 <span class="comment">*                                      int       maxdist )</span>
+<a name="l00136"></a>00136 <span class="comment">*</span>
+<a name="l00137"></a>00137 <span class="comment">*</span>
+<a name="l00138"></a>00138 <span class="comment">*    25) cpl_imagelist * sinfo_cube_zshift(const cpl_imagelist * cube,</span>
+<a name="l00139"></a>00139 <span class="comment">*                                          const double shift,</span>
+<a name="l00140"></a>00140 <span class="comment">*                                          double* rest)</span>
+<a name="l00141"></a>00141 <span class="comment">*</span>
+<a name="l00142"></a>00142 <span class="comment">*    26) cpl_imagelist * sinfo_cube_zshift_poly(const cpl_imagelist * cube,</span>
+<a name="l00143"></a>00143 <span class="comment">*                                               const double shift,</span>
+<a name="l00144"></a>00144 <span class="comment">*                                               const int    order)</span>
+<a name="l00145"></a>00145 <span class="comment">*</span>
+<a name="l00146"></a>00146 <span class="comment">*    27) cpl_imagelist * sinfo_cube_zshift_spline3(const cpl_imagelist * cube,</span>
+<a name="l00147"></a>00147 <span class="comment">*                                                  const double shift)</span>
+<a name="l00148"></a>00148 <span class="comment">*</span>
+<a name="l00149"></a>00149 <span class="comment">*</span>
+<a name="l00150"></a>00150 <span class="comment">*</span>
+<a name="l00151"></a>00151 <span class="comment">*</span>
+<a name="l00152"></a>00152 <span class="comment">*   DESCRIPTION</span>
+<a name="l00153"></a>00153 <span class="comment">*    2) 4 operations between 2 cubes</span>
+<a name="l00154"></a>00154 <span class="comment">*    3) 4 operations between a cube and a constant</span>
+<a name="l00155"></a>00155 <span class="comment">*    4)    subtract one cube from another</span>
+<a name="l00156"></a>00156 <span class="comment">*    5) add a cube to another</span>
+<a name="l00157"></a>00157 <span class="comment">*    6) multiply two cubes</span>
+<a name="l00158"></a>00158 <span class="comment">*    7) divide two cubes</span>
+<a name="l00159"></a>00159 <span class="comment">*    8) add an image to all planes in the cube</span>
+<a name="l00160"></a>00160 <span class="comment">*    9) subtract an image from all planes in the cube</span>
+<a name="l00161"></a>00161 <span class="comment">*    10) multiply an image to all planes in the cube</span>
+<a name="l00162"></a>00162 <span class="comment">*    11) divide all planes in the cube by an image</span>
+<a name="l00163"></a>00163 <span class="comment">*    12) adds a spectrum (in z-direction) to all data</span>
+<a name="l00164"></a>00164 <span class="comment">*                        points in a cube</span>
+<a name="l00165"></a>00165 <span class="comment">*    13) subtracts a spectrum (in z-direction) from all</span>
+<a name="l00166"></a>00166 <span class="comment">*                        data points in a cube</span>
+<a name="l00167"></a>00167 <span class="comment">*    14) multiplies a spectrum (in z-direction) to all data</span>
+<a name="l00168"></a>00168 <span class="comment">*                        points in a cube</span>
+<a name="l00169"></a>00169 <span class="comment">*    15) divides all data points of a cube by a spectrum</span>
+<a name="l00170"></a>00170 <span class="comment">*                        (in z-direction)</span>
+<a name="l00171"></a>00171 <span class="comment">*    16) averaging routine to get a better spectral S/N, sorts</span>
+<a name="l00172"></a>00172 <span class="comment">*        the values of the same z-position, cuts the lowest and</span>
+<a name="l00173"></a>00173 <span class="comment">*        highest values according to given thresholds and then</span>
+<a name="l00174"></a>00174 <span class="comment">*        takes the average within the x-y plane , cannot have</span>
+<a name="l00175"></a>00175 <span class="comment">*        a sum of low and high rejected values greater than 90%</span>
+<a name="l00176"></a>00176 <span class="comment">*        of all values</span>
+<a name="l00177"></a>00177 <span class="comment">*    17) determines the sinfo_new_median value in every pixel position</span>
+<a name="l00178"></a>00178 <span class="comment">*        by considering all pixels along the third axis.</span>
+<a name="l00179"></a>00179 <span class="comment">*        ZERO pixels in a plane are not considered. If all</span>
+<a name="l00180"></a>00180 <span class="comment">*        pixels at a position are not valid the result will</span>
+<a name="l00181"></a>00181 <span class="comment">*        be 'ZERO'.</span>
+<a name="l00182"></a>00182 <span class="comment">*    18) determines the average value in every pixel position</span>
+<a name="l00183"></a>00183 <span class="comment">*        by considering all pixels along the third axis.</span>
+<a name="l00184"></a>00184 <span class="comment">*        ZERO pixels in a plane are not considered. If all</span>
+<a name="l00185"></a>00185 <span class="comment">*        pixels at a position are not valid the result will</span>
+<a name="l00186"></a>00186 <span class="comment">*        be 'ZERO'.</span>
+<a name="l00187"></a>00187 <span class="comment">*    19) determines the sum value in every pixel position</span>
+<a name="l00188"></a>00188 <span class="comment">*        by considering all pixels along the third axis.</span>
+<a name="l00189"></a>00189 <span class="comment">*        ZERO pixels in a plane are not considered. If all</span>
+<a name="l00190"></a>00190 <span class="comment">*        pixels at a position are not valid the result will</span>
+<a name="l00191"></a>00191 <span class="comment">*        be 'ZERO'.</span>
+<a name="l00192"></a>00192 <span class="comment">*    20) determines the average value in every pixel position</span>
+<a name="l00193"></a>00193 <span class="comment">*        by considering only the pixels along the third axis</span>
+<a name="l00194"></a>00194 <span class="comment">*        which lie between the given wavelength values.</span>
+<a name="l00195"></a>00195 <span class="comment">*        These values are first recalculated to plane indices</span>
+<a name="l00196"></a>00196 <span class="comment">*        by using the given dispersion and minimum wavelength in</span>
+<a name="l00197"></a>00197 <span class="comment">*        the cube.</span>
+<a name="l00198"></a>00198 <span class="comment">*        ZERO pixels in a plane are not considered. If all</span>
+<a name="l00199"></a>00199 <span class="comment">*        pixels at a position are not valid the result will</span>
+<a name="l00200"></a>00200 <span class="comment">*        be 'ZERO'.</span>
+<a name="l00201"></a>00201 <span class="comment">*    21) returns the wanted image plane of the cube</span>
+<a name="l00202"></a>00202 <span class="comment">*    22) returns the wanted single spectrum of the cube</span>
+<a name="l00203"></a>00203 <span class="comment">*    23) merges jittered data cubes to one bigger cube</span>
+<a name="l00204"></a>00204 <span class="comment">*        by averaging the overlap regions weighted by</span>
+<a name="l00205"></a>00205 <span class="comment">*        the integration times. The x, y size of the final data</span>
+<a name="l00206"></a>00206 <span class="comment">*        cube is user given, and should be between 32 and 64</span>
+<a name="l00207"></a>00207 <span class="comment">*        pixels, while the relative pixel-offset (sub-pixel</span>
+<a name="l00208"></a>00208 <span class="comment">*        accuracy) of the single cubes with respect to the</span>
+<a name="l00209"></a>00209 <span class="comment">*        first cube in the list is read from the SEQ CUMOFFSETX,Y</span>
+<a name="l00210"></a>00210 <span class="comment">*        fits header keyword.</span>
+<a name="l00211"></a>00211 <span class="comment">*   24)  interpolates bad pixel of an object cube if a bad pixel</span>
+<a name="l00212"></a>00212 <span class="comment">*        mask cube is available by using the nearest neighbors</span>
+<a name="l00213"></a>00213 <span class="comment">*        in 3 dimensions.</span>
+<a name="l00214"></a>00214 <span class="comment">*</span>
+<a name="l00215"></a>00215 <span class="comment">*   25)  shifts an imagelist by a given amount to integer pixel accuracy</span>
+<a name="l00216"></a>00216 <span class="comment">*   26)  shifts an imagelist by a given amount to sub-pixel accuracy</span>
+<a name="l00217"></a>00217 <span class="comment">*   27)  shifts an imagelist by a given amount to sub-pixel accuracy</span>
+<a name="l00218"></a>00218 <span class="comment">*   FILES</span>
+<a name="l00219"></a>00219 <span class="comment">*</span>
+<a name="l00220"></a>00220 <span class="comment">*   ENVIRONMENT</span>
+<a name="l00221"></a>00221 <span class="comment">*</span>
+<a name="l00222"></a>00222 <span class="comment">*   RETURN VALUES</span>
+<a name="l00223"></a>00223 <span class="comment">*</span>
+<a name="l00224"></a>00224 <span class="comment">*   CAUTIONS</span>
+<a name="l00225"></a>00225 <span class="comment">*</span>
+<a name="l00226"></a>00226 <span class="comment">*   EXAMPLES</span>
+<a name="l00227"></a>00227 <span class="comment">*</span>
+<a name="l00228"></a>00228 <span class="comment">*   SEE ALSO</span>
+<a name="l00229"></a>00229 <span class="comment">*</span>
+<a name="l00230"></a>00230 <span class="comment">*   BUGS</span>
+<a name="l00231"></a>00231 <span class="comment">*</span>
+<a name="l00232"></a>00232 <span class="comment">*------------------------------------------------------------------------</span>
+<a name="l00233"></a>00233 <span class="comment">*/</span>
+<a name="l00234"></a>00234 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00235"></a>00235 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00236"></a>00236 <span class="preprocessor">#endif</span>
+<a name="l00237"></a>00237 <span class="preprocessor"></span>
+<a name="l00238"></a>00238 <span class="preprocessor">#include "sinfo_vltPort.h"</span>
+<a name="l00239"></a>00239 
+<a name="l00240"></a>00240 <span class="comment">/*</span>
+<a name="l00241"></a>00241 <span class="comment"> * System Headers</span>
+<a name="l00242"></a>00242 <span class="comment"> */</span>
+<a name="l00243"></a>00243 
+<a name="l00244"></a>00244 <span class="preprocessor">#include <sys/types.h></span>
+<a name="l00245"></a>00245 <span class="preprocessor">#include <sys/times.h></span>
+<a name="l00246"></a>00246 <span class="preprocessor">#include <math.h></span>
+<a name="l00247"></a>00247 <span class="comment">/*</span>
+<a name="l00248"></a>00248 <span class="comment"> * Local Headers</span>
+<a name="l00249"></a>00249 <span class="comment"> */</span>
+<a name="l00250"></a>00250 <span class="preprocessor">#include "sinfo_dfs.h"</span>
+<a name="l00251"></a>00251 <span class="preprocessor">#include "sinfo_new_cube_ops.h"</span>
+<a name="l00252"></a>00252 <span class="preprocessor">#include "sinfo_resampling.h"</span>
+<a name="l00253"></a>00253 <span class="preprocessor">#include "sinfo_function_1d.h"</span>
+<a name="l00254"></a>00254 <span class="preprocessor">#include "sinfo_error.h"</span>
+<a name="l00255"></a>00255 <span class="preprocessor">#include "sinfo_globals.h"</span>
+<a name="l00256"></a>00256 <span class="preprocessor">#include "sinfo_utils_wrappers.h"</span>
+<a name="l00257"></a>00257 
+<a name="l00258"></a>00258 <span class="preprocessor">#include <cpl_vector.h></span>
+<a name="l00259"></a>00259 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00260"></a>00260 <span class="comment"> *                            Function codes</span>
+<a name="l00261"></a>00261 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00262"></a>00262 
+<a name="l00263"></a>00263 
+<a name="l00264"></a>00264 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00265"></a>00265 sinfo_shift_cubes(cpl_imagelist** tmpcubes,
+<a name="l00266"></a>00266                   <span class="keywordtype">char</span>* kernel_type,
+<a name="l00267"></a>00267                   <span class="keyword">const</span> <span class="keywordtype">int</span> n_cubes,
+<a name="l00268"></a>00268                   cpl_imagelist** cubes,
+<a name="l00269"></a>00269                   <span class="keyword">const</span> <span class="keywordtype">int</span> z_min,
+<a name="l00270"></a>00270                   <span class="keyword">const</span> <span class="keywordtype">int</span> z_max,
+<a name="l00271"></a>00271                   <span class="keywordtype">float</span>* sub_offsetx,
+<a name="l00272"></a>00272                   <span class="keywordtype">float</span>* sub_offsety,
+<a name="l00273"></a>00273                   <span class="keyword">const</span> <span class="keywordtype">int</span> mlx,
+<a name="l00274"></a>00274                   <span class="keyword">const</span> <span class="keywordtype">int</span> mly,
+<a name="l00275"></a>00275                   cpl_imagelist* mask);
+<a name="l00276"></a>00276 
+<a name="l00277"></a>00277 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00278"></a>00278 sinfo_build_mask_cube(<span class="keyword">const</span> <span class="keywordtype">int</span> z_min,
+<a name="l00279"></a>00279                       <span class="keyword">const</span> <span class="keywordtype">int</span> z_max,
+<a name="l00280"></a>00280                       <span class="keyword">const</span> <span class="keywordtype">int</span> olx,
+<a name="l00281"></a>00281                       <span class="keyword">const</span> <span class="keywordtype">int</span> oly,
+<a name="l00282"></a>00282                       <span class="keyword">const</span> <span class="keywordtype">int</span> n_cubes,
+<a name="l00283"></a>00283                       <span class="keyword">const</span> <span class="keywordtype">int</span>* llx,
+<a name="l00284"></a>00284                       <span class="keyword">const</span> <span class="keywordtype">int</span>* lly,
+<a name="l00285"></a>00285               <span class="keywordtype">double</span>    * exptimes,
+<a name="l00286"></a>00286                       cpl_imagelist** cubes,
+<a name="l00287"></a>00287                       cpl_imagelist** tmpcubes,
+<a name="l00288"></a>00288                       cpl_imagelist* mask);
+<a name="l00289"></a>00289 
+<a name="l00290"></a>00290 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00291"></a>00291 sinfo_build_mask_cube_thomas(<span class="keyword">const</span> <span class="keywordtype">int</span> z_min,
+<a name="l00292"></a>00292                              <span class="keyword">const</span> <span class="keywordtype">int</span> z_max,
+<a name="l00293"></a>00293                              <span class="keyword">const</span> <span class="keywordtype">int</span> olx,
+<a name="l00294"></a>00294                              <span class="keyword">const</span> <span class="keywordtype">int</span> oly,
+<a name="l00295"></a>00295                              <span class="keyword">const</span> <span class="keywordtype">int</span> n_cubes,
+<a name="l00296"></a>00296                              <span class="keyword">const</span> <span class="keywordtype">int</span>* llx,
+<a name="l00297"></a>00297                              <span class="keyword">const</span> <span class="keywordtype">int</span>* lly,
+<a name="l00298"></a>00298                      <span class="keywordtype">double</span>    * exptimes,
+<a name="l00299"></a>00299                              cpl_imagelist** cubes,
+<a name="l00300"></a>00300                              cpl_imagelist** tmpcubes,
+<a name="l00301"></a>00301                  cpl_imagelist* mask);
+<a name="l00302"></a>00302 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00303"></a>00303 sinfo_compute_weight_average(<span class="keyword">const</span> <span class="keywordtype">int</span> z_min,
+<a name="l00304"></a>00304                              <span class="keyword">const</span> <span class="keywordtype">int</span> z_max,
+<a name="l00305"></a>00305                              <span class="keyword">const</span> <span class="keywordtype">int</span> ilx,
+<a name="l00306"></a>00306                              <span class="keyword">const</span> <span class="keywordtype">int</span> ily,
+<a name="l00307"></a>00307                  <span class="keyword">const</span> <span class="keywordtype">int</span> n_cubes,
+<a name="l00308"></a>00308                              cpl_imagelist* mergedCube,
+<a name="l00309"></a>00309                              cpl_imagelist* mask,
+<a name="l00310"></a>00310                              cpl_imagelist** tmpcubes,
+<a name="l00311"></a>00311                  <span class="keywordtype">double</span>* exptimes,
+<a name="l00312"></a>00312                              <span class="keywordtype">int</span>* llx,
+<a name="l00313"></a>00313                              <span class="keywordtype">int</span>* lly);
+<a name="l00314"></a>00314 
+<a name="l00315"></a>00315 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00316"></a>00316 sinfo_check_input(cpl_imagelist** cubes,
+<a name="l00317"></a>00317                           <span class="keyword">const</span> <span class="keywordtype">int</span> n_cubes,
+<a name="l00318"></a>00318                           <span class="keywordtype">float</span>* cumoffsetx,
+<a name="l00319"></a>00319                           <span class="keywordtype">float</span>* cumoffsety,
+<a name="l00320"></a>00320               <span class="keywordtype">double</span>* exptimes);
+<a name="l00321"></a>00321 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00322"></a>00322 sinfo_coadd_with_ks_clip2(<span class="keyword">const</span> <span class="keywordtype">int</span> z_min,
+<a name="l00323"></a>00323             <span class="keyword">const</span> <span class="keywordtype">int</span> z_max,
+<a name="l00324"></a>00324             <span class="keyword">const</span> <span class="keywordtype">int</span> ilx,
+<a name="l00325"></a>00325             <span class="keyword">const</span> <span class="keywordtype">int</span> ily,
+<a name="l00326"></a>00326             <span class="keyword">const</span> <span class="keywordtype">int</span> n_cubes,
+<a name="l00327"></a>00327             <span class="keyword">const</span> <span class="keywordtype">double</span> kappa,
+<a name="l00328"></a>00328             <span class="keywordtype">int</span>* llx,
+<a name="l00329"></a>00329             <span class="keywordtype">int</span>* lly,
+<a name="l00330"></a>00330                         <span class="keywordtype">double</span>* exptimes,
+<a name="l00331"></a>00331             cpl_imagelist* mask,
+<a name="l00332"></a>00332             cpl_imagelist* mergedCube,
+<a name="l00333"></a>00333                           cpl_imagelist** tmpcubes);
+<a name="l00334"></a>00334 
+<a name="l00335"></a>00335 
+<a name="l00336"></a>00336 <span class="comment">/* temporally commented out as not yet used</span>
+<a name="l00337"></a>00337 <span class="comment">static int</span>
+<a name="l00338"></a>00338 <span class="comment">sinfo_ks_clip(</span>
+<a name="l00339"></a>00339 <span class="comment">          const int n_cubes,</span>
+<a name="l00340"></a>00340 <span class="comment">              const int nc,</span>
+<a name="l00341"></a>00341 <span class="comment">          const int ilx,</span>
+<a name="l00342"></a>00342 <span class="comment">          const int ily,</span>
+<a name="l00343"></a>00343 <span class="comment">          const double kappa,</span>
+<a name="l00344"></a>00344 <span class="comment">          int* llx,</span>
+<a name="l00345"></a>00345 <span class="comment">          int* lly,</span>
+<a name="l00346"></a>00346 <span class="comment">          double* exptimes,</span>
+<a name="l00347"></a>00347 <span class="comment">          cpl_imagelist** tmpcubes,</span>
+<a name="l00348"></a>00348 <span class="comment">              float* podata,</span>
+<a name="l00349"></a>00349 <span class="comment">              float* pmdata,</span>
+<a name="l00350"></a>00350 <span class="comment">          const int x,</span>
+<a name="l00351"></a>00351 <span class="comment">          const int y,</span>
+<a name="l00352"></a>00352 <span class="comment">          const int m,</span>
+<a name="l00353"></a>00353 <span class="comment">          const int mlx,</span>
+<a name="l00354"></a>00354 <span class="comment">          const int olx</span>
+<a name="l00355"></a>00355 <span class="comment">          );</span>
+<a name="l00356"></a>00356 <span class="comment"></span>
+<a name="l00357"></a>00357 <span class="comment"></span>
+<a name="l00358"></a>00358 <span class="comment">*/</span>
+<a name="l00359"></a>00359 
+<a name="l00360"></a>00360 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00361"></a>00361 sinfo_coadd_with_ks_clip(<span class="keyword">const</span> <span class="keywordtype">int</span> z_min,
+<a name="l00362"></a>00362             <span class="keyword">const</span> <span class="keywordtype">int</span> z_max,
+<a name="l00363"></a>00363             <span class="keyword">const</span> <span class="keywordtype">int</span> ilx,
+<a name="l00364"></a>00364             <span class="keyword">const</span> <span class="keywordtype">int</span> ily,
+<a name="l00365"></a>00365             <span class="keyword">const</span> <span class="keywordtype">int</span> n_cubes,
+<a name="l00366"></a>00366             <span class="keyword">const</span> <span class="keywordtype">double</span> kappa,
+<a name="l00367"></a>00367             <span class="keywordtype">int</span>* llx,
+<a name="l00368"></a>00368             <span class="keywordtype">int</span>* lly,
+<a name="l00369"></a>00369                         <span class="keywordtype">double</span>* exptimes,
+<a name="l00370"></a>00370             cpl_imagelist* mask,
+<a name="l00371"></a>00371             cpl_imagelist* mergedCube,
+<a name="l00372"></a>00372                         cpl_imagelist** tmpcubes);
+<a name="l00373"></a>00373 
+<a name="l00374"></a>00374 
+<a name="l00399"></a>00399 cpl_imagelist *
+<a name="l00400"></a>00400 sinfo_new_cube_ops(
+<a name="l00401"></a>00401     cpl_imagelist    *    cube1,
+<a name="l00402"></a>00402     cpl_imagelist    *    cube2,
+<a name="l00403"></a>00403     <span class="keywordtype">int</span>        operation)
+<a name="l00404"></a>00404 {
+<a name="l00405"></a>00405 
+<a name="l00406"></a>00406     <span class="keywordflow">if</span> (cube1==NULL || cube2==NULL)
+<a name="l00407"></a>00407     {
+<a name="l00408"></a>00408         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"null cubes"</span>);
+<a name="l00409"></a>00409         <span class="keywordflow">return</span> NULL ;
+<a name="l00410"></a>00410     }
+<a name="l00411"></a>00411 
+<a name="l00412"></a>00412     <span class="keywordflow">switch</span>(operation)
+<a name="l00413"></a>00413     {
+<a name="l00414"></a>00414     <span class="keywordflow">case</span> <span class="charliteral">'+'</span>:
+<a name="l00415"></a>00415     <span class="keywordflow">return</span> sinfo_new_cube_add(cube1, cube2) ;
+<a name="l00416"></a>00416     break ;
+<a name="l00417"></a>00417     <span class="keywordflow">case</span> <span class="charliteral">'-'</span>:
+<a name="l00418"></a>00418     <span class="keywordflow">return</span> sinfo_new_cube_sub(cube1, cube2) ;
+<a name="l00419"></a>00419     break ;
+<a name="l00420"></a>00420 
+<a name="l00421"></a>00421     <span class="keywordflow">case</span> <span class="charliteral">'*'</span>:
+<a name="l00422"></a>00422     <span class="keywordflow">return</span> sinfo_new_cube_mul(cube1, cube2) ;
+<a name="l00423"></a>00423     break ;
+<a name="l00424"></a>00424 
+<a name="l00425"></a>00425     <span class="keywordflow">case</span> <span class="charliteral">'/'</span>:
+<a name="l00426"></a>00426     <span class="keywordflow">return</span> sinfo_new_cube_div(cube1, cube2) ;
+<a name="l00427"></a>00427     break ;
+<a name="l00428"></a>00428 
+<a name="l00429"></a>00429     <span class="keywordflow">default</span>:
+<a name="l00430"></a>00430     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"illegal requested operation: aborting cube arithmetic"</span>) ;
+<a name="l00431"></a>00431     <span class="keywordflow">return</span> NULL ;
+<a name="l00432"></a>00432     }
+<a name="l00433"></a>00433 }
+<a name="l00434"></a>00434 
+<a name="l00435"></a>00435 
+<a name="l00436"></a>00436 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00437"></a>00437 <span class="comment">   Function    :    sinfo_new_cube_const_ops()</span>
+<a name="l00438"></a>00438 <span class="comment">   In         :    1 cube, 1 constant, operation to perform</span>
+<a name="l00439"></a>00439 <span class="comment">   Out         :    result cube</span>
+<a name="l00440"></a>00440 <span class="comment">   Job        :    4 operations between a cube and a constant</span>
+<a name="l00441"></a>00441 <span class="comment">   Notice    :    possible operations are:</span>
+<a name="l00442"></a>00442 <span class="comment">                  Addition    '+'</span>
+<a name="l00443"></a>00443 <span class="comment">                  Subtraction     '-'</span>
+<a name="l00444"></a>00444 <span class="comment">                  Multiplication    '*'</span>
+<a name="l00445"></a>00445 <span class="comment">                  Division    '/'</span>
+<a name="l00446"></a>00446 <span class="comment">                  Logarithm    'l'</span>
+<a name="l00447"></a>00447 <span class="comment">                  Power        '^'</span>
+<a name="l00448"></a>00448 <span class="comment">                  Exponentiation    'e'</span>
+<a name="l00449"></a>00449 <span class="comment"></span>
+<a name="l00450"></a>00450 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00451"></a>00451 
+<a name="l00452"></a>00452 cpl_imagelist *
+<a name="l00453"></a>00453 sinfo_new_cube_const_ops(
+<a name="l00454"></a>00454     cpl_imagelist    *    c1,
+<a name="l00455"></a>00455     <span class="keywordtype">double</span>        constant,
+<a name="l00456"></a>00456     <span class="keywordtype">int</span>        operation)
+<a name="l00457"></a>00457 {
+<a name="l00458"></a>00458     <span class="keywordtype">int</span> ilx1=0;
+<a name="l00459"></a>00459     <span class="keywordtype">int</span> ily1=0;
+<a name="l00460"></a>00460     <span class="keywordtype">int</span> inp1=0;
+<a name="l00461"></a>00461     cpl_imagelist* c2=NULL;
+<a name="l00462"></a>00462     cpl_image* img1=NULL;
+<a name="l00463"></a>00463 
+<a name="l00464"></a>00464 
+<a name="l00465"></a>00465 
+<a name="l00466"></a>00466     <span class="keywordflow">if</span> (c1 == NULL)
+<a name="l00467"></a>00467     {
+<a name="l00468"></a>00468          <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"null cube"</span>) ;
+<a name="l00469"></a>00469          <span class="keywordflow">return</span> NULL ;
+<a name="l00470"></a>00470     }
+<a name="l00471"></a>00471     inp1=cpl_imagelist_get_size(c1);
+<a name="l00472"></a>00472     img1=cpl_imagelist_get(c1,0);
+<a name="l00473"></a>00473     ilx1=cpl_image_get_size_x(img1);
+<a name="l00474"></a>00474     ily1=cpl_image_get_size_y(img1);
+<a name="l00475"></a>00475 
+<a name="l00476"></a>00476 
+<a name="l00477"></a>00477 
+<a name="l00478"></a>00478 
+<a name="l00479"></a>00479 
+<a name="l00480"></a>00480     <span class="keywordflow">if</span> ((constant == 0.0) && (operation == <span class="charliteral">'/'</span>))
+<a name="l00481"></a>00481     {
+<a name="l00482"></a>00482         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"division by zero requested "</span>
+<a name="l00483"></a>00483                         <span class="stringliteral">"in cube/constant operation"</span>) ;
+<a name="l00484"></a>00484         <span class="keywordflow">return</span> NULL ;
+<a name="l00485"></a>00485     }
+<a name="l00486"></a>00486 
+<a name="l00487"></a>00487     <span class="keywordflow">if</span> ( NULL == (c2 = cpl_imagelist_new()) )
+<a name="l00488"></a>00488     {
+<a name="l00489"></a>00489         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"cannot allocate new cube"</span> ) ;
+<a name="l00490"></a>00490         <span class="keywordflow">return</span> NULL ;
+<a name="l00491"></a>00491     }
+<a name="l00492"></a>00492 
+<a name="l00493"></a>00493     c2=cpl_imagelist_duplicate(c1);
+<a name="l00494"></a>00494     <span class="keywordflow">if</span>(operation == <span class="charliteral">'+'</span>) {
+<a name="l00495"></a>00495       cpl_imagelist_add_scalar(c2,constant);
+<a name="l00496"></a>00496     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (operation == <span class="charliteral">'-'</span>) {
+<a name="l00497"></a>00497       cpl_imagelist_subtract_scalar(c2,constant);
+<a name="l00498"></a>00498     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (operation == <span class="charliteral">'*'</span>) {
+<a name="l00499"></a>00499       cpl_imagelist_multiply_scalar(c2,constant);
+<a name="l00500"></a>00500     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (operation == <span class="charliteral">'/'</span>) {
+<a name="l00501"></a>00501       cpl_imagelist_divide_scalar(c2,constant);
+<a name="l00502"></a>00502 
+<a name="l00503"></a>00503     } <span class="keywordflow">else</span> {
+<a name="l00504"></a>00504       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"operation not supported"</span>);
+<a name="l00505"></a>00505       <span class="keywordflow">return</span> NULL;
+<a name="l00506"></a>00506     }
+<a name="l00507"></a>00507     <span class="keywordflow">return</span> c2 ;
+<a name="l00508"></a>00508 }
+<a name="l00509"></a>00509 
+<a name="l00510"></a>00510 
+<a name="l00511"></a>00511 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00512"></a>00512 <span class="comment"> * Function    :    sinfo_new_cube_sub()</span>
+<a name="l00513"></a>00513 <span class="comment"> * In         :    two cubes</span>
+<a name="l00514"></a>00514 <span class="comment"> * Out         :    result cube</span>
+<a name="l00515"></a>00515 <span class="comment"> * Job        :    subtract one cube from another</span>
+<a name="l00516"></a>00516 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00517"></a>00517 
+<a name="l00518"></a>00518 cpl_imagelist *
+<a name="l00519"></a>00519 sinfo_new_cube_sub(
+<a name="l00520"></a>00520     cpl_imagelist    *    c1,
+<a name="l00521"></a>00521     cpl_imagelist    *    c2
+<a name="l00522"></a>00522 )
+<a name="l00523"></a>00523 {
+<a name="l00524"></a>00524     cpl_imagelist   *                 c3 ;
+<a name="l00525"></a>00525     ulong32            i ;
+<a name="l00526"></a>00526     <span class="keywordtype">int</span>                     np ;
+<a name="l00527"></a>00527     <span class="keywordtype">int</span> ilx1=0;
+<a name="l00528"></a>00528     <span class="keywordtype">int</span> ily1=0;
+<a name="l00529"></a>00529     <span class="keywordtype">int</span> inp1=0;
+<a name="l00530"></a>00530     <span class="keywordtype">int</span> ilx2=0;
+<a name="l00531"></a>00531     <span class="keywordtype">int</span> ily2=0;
+<a name="l00532"></a>00532     <span class="keywordtype">int</span> inp2=0;
+<a name="l00533"></a>00533 
+<a name="l00534"></a>00534 
+<a name="l00535"></a>00535     cpl_image* i_img=NULL;
+<a name="l00536"></a>00536     cpl_image* img1=NULL;
+<a name="l00537"></a>00537     cpl_image* img2=NULL;
+<a name="l00538"></a>00538     cpl_image* img3=NULL;
+<a name="l00539"></a>00539     <span class="keywordtype">float</span>* p1data=NULL;
+<a name="l00540"></a>00540     <span class="keywordtype">float</span>* p2data=NULL;
+<a name="l00541"></a>00541     <span class="keywordtype">float</span>* p3data=NULL;
+<a name="l00542"></a>00542 
+<a name="l00543"></a>00543 
+<a name="l00544"></a>00544 
+<a name="l00545"></a>00545     inp1=cpl_imagelist_get_size(c1);
+<a name="l00546"></a>00546     i_img=cpl_imagelist_get(c1,0);
+<a name="l00547"></a>00547     ilx1=cpl_image_get_size_x(i_img);
+<a name="l00548"></a>00548     ily1=cpl_image_get_size_y(i_img);
+<a name="l00549"></a>00549 
+<a name="l00550"></a>00550 
+<a name="l00551"></a>00551     inp2=cpl_imagelist_get_size(c2);
+<a name="l00552"></a>00552     i_img=cpl_imagelist_get(c2,0);
+<a name="l00553"></a>00553     ilx2=cpl_image_get_size_x(i_img);
+<a name="l00554"></a>00554     ily2=cpl_image_get_size_y(i_img);
+<a name="l00555"></a>00555 
+<a name="l00556"></a>00556     <span class="keywordflow">if</span> ((ilx1 != ilx2) ||
+<a name="l00557"></a>00557     (ily1 != ily2))
+<a name="l00558"></a>00558     {
+<a name="l00559"></a>00559     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"incompatible size: cannot subtract"</span>) ;
+<a name="l00560"></a>00560     <span class="keywordflow">return</span> NULL ;
+<a name="l00561"></a>00561     }
+<a name="l00562"></a>00562 
+<a name="l00563"></a>00563     <span class="keywordflow">if</span> ((inp2 != inp1) &&
+<a name="l00564"></a>00564     (inp2 != 1))
+<a name="l00565"></a>00565     {
+<a name="l00566"></a>00566     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"cannot compute with these number of planes"</span>) ;
+<a name="l00567"></a>00567     <span class="keywordflow">return</span> NULL ;
+<a name="l00568"></a>00568     }
+<a name="l00569"></a>00569 
+<a name="l00570"></a>00570     <span class="keywordflow">if</span> ( NULL == (c3 = cpl_imagelist_new()) )
+<a name="l00571"></a>00571     {
+<a name="l00572"></a>00572         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"cannot allocate new cube"</span> ) ;
+<a name="l00573"></a>00573         <span class="keywordflow">return</span> NULL ;
+<a name="l00574"></a>00574     }
+<a name="l00575"></a>00575 
+<a name="l00576"></a>00576     <span class="keywordflow">for</span> (np=0 ; np < inp1 ; np++)
+<a name="l00577"></a>00577     {
+<a name="l00578"></a>00578       img3=cpl_image_new(ilx1,ily1,CPL_TYPE_FLOAT);
+<a name="l00579"></a>00579       cpl_imagelist_set(c3,img3,np);
+<a name="l00580"></a>00580     }
+<a name="l00581"></a>00581 
+<a name="l00582"></a>00582 
+<a name="l00583"></a>00583     <span class="keywordflow">for</span> (np=0 ; np < inp1 ; np++)
+<a name="l00584"></a>00584     {
+<a name="l00585"></a>00585       img1=cpl_imagelist_get(c1,np);
+<a name="l00586"></a>00586       p1data=cpl_image_get_data_float(img1);
+<a name="l00587"></a>00587       img2=cpl_imagelist_get(c2,np);
+<a name="l00588"></a>00588       p2data=cpl_image_get_data_float(img2);
+<a name="l00589"></a>00589       img3=cpl_imagelist_get(c3,np);
+<a name="l00590"></a>00590       p3data=cpl_image_get_data_float(img3);
+<a name="l00591"></a>00591 
+<a name="l00592"></a>00592         <span class="keywordflow">for</span> (i=0 ; i< (ulong32)ilx1*ily1 ; i++)
+<a name="l00593"></a>00593         {
+<a name="l00594"></a>00594             p3data[i] = p1data[i] - p2data[i] ;
+<a name="l00595"></a>00595     }
+<a name="l00596"></a>00596     }
+<a name="l00597"></a>00597 
+<a name="l00598"></a>00598     <span class="keywordflow">return</span> c3 ;
+<a name="l00599"></a>00599 }
+<a name="l00600"></a>00600 
+<a name="l00601"></a>00601 
+<a name="l00602"></a>00602 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00603"></a>00603 <span class="comment"> * Function    :    sinfo_new_cube_add()</span>
+<a name="l00604"></a>00604 <span class="comment"> * In         :    two cubes</span>
+<a name="l00605"></a>00605 <span class="comment"> * Out         :    result cube</span>
+<a name="l00606"></a>00606 <span class="comment"> * Job        :    add a cube to another</span>
+<a name="l00607"></a>00607 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00608"></a>00608 
+<a name="l00609"></a>00609 cpl_imagelist *
+<a name="l00610"></a>00610 sinfo_new_cube_add(
+<a name="l00611"></a>00611     cpl_imagelist    *    c1,
+<a name="l00612"></a>00612     cpl_imagelist    *    c2
+<a name="l00613"></a>00613 )
+<a name="l00614"></a>00614 {
+<a name="l00615"></a>00615     cpl_imagelist  *          c3 ;
+<a name="l00616"></a>00616     ulong32        i ;
+<a name="l00617"></a>00617     <span class="keywordtype">int</span>         np ;
+<a name="l00618"></a>00618     <span class="keywordtype">int</span> ilx1=0;
+<a name="l00619"></a>00619     <span class="keywordtype">int</span> ily1=0;
+<a name="l00620"></a>00620     <span class="keywordtype">int</span> inp1=0;
+<a name="l00621"></a>00621     <span class="keywordtype">int</span> ilx2=0;
+<a name="l00622"></a>00622     <span class="keywordtype">int</span> ily2=0;
+<a name="l00623"></a>00623     <span class="keywordtype">int</span> inp2=0;
+<a name="l00624"></a>00624 
+<a name="l00625"></a>00625 
+<a name="l00626"></a>00626     cpl_image* i_img=NULL;
+<a name="l00627"></a>00627     cpl_image* img1=NULL;
+<a name="l00628"></a>00628     cpl_image* img2=NULL;
+<a name="l00629"></a>00629     cpl_image* img3=NULL;
+<a name="l00630"></a>00630     <span class="keywordtype">float</span>* p1data=NULL;
+<a name="l00631"></a>00631     <span class="keywordtype">float</span>* p2data=NULL;
+<a name="l00632"></a>00632     <span class="keywordtype">float</span>* p3data=NULL;
+<a name="l00633"></a>00633 
+<a name="l00634"></a>00634 
+<a name="l00635"></a>00635 
+<a name="l00636"></a>00636     inp1=cpl_imagelist_get_size(c1);
+<a name="l00637"></a>00637     i_img=cpl_imagelist_get(c1,0);
+<a name="l00638"></a>00638     ilx1=cpl_image_get_size_x(i_img);
+<a name="l00639"></a>00639     ily1=cpl_image_get_size_y(i_img);
+<a name="l00640"></a>00640 
+<a name="l00641"></a>00641 
+<a name="l00642"></a>00642     inp2=cpl_imagelist_get_size(c2);
+<a name="l00643"></a>00643     i_img=cpl_imagelist_get(c2,0);
+<a name="l00644"></a>00644     ilx2=cpl_image_get_size_x(i_img);
+<a name="l00645"></a>00645     ily2=cpl_image_get_size_y(i_img);
+<a name="l00646"></a>00646     <span class="keywordflow">if</span> ((ilx1 != ilx2) || (ily1 != ily2))
+<a name="l00647"></a>00647     {
+<a name="l00648"></a>00648     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"incompatible size: cannot add"</span>) ;
+<a name="l00649"></a>00649     <span class="keywordflow">return</span> NULL ;
+<a name="l00650"></a>00650     }
+<a name="l00651"></a>00651     <span class="keywordflow">if</span> ((inp2 != inp1) && (inp2 != 1))
+<a name="l00652"></a>00652     {
+<a name="l00653"></a>00653     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"cannot compute with these number of planes"</span>) ;
+<a name="l00654"></a>00654     <span class="keywordflow">return</span> NULL ;
+<a name="l00655"></a>00655     }
+<a name="l00656"></a>00656 
+<a name="l00657"></a>00657     <span class="keywordflow">if</span> (NULL == (c3 = cpl_imagelist_new()) )
+<a name="l00658"></a>00658     {
+<a name="l00659"></a>00659         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"cannot allocate new cube"</span>) ;
+<a name="l00660"></a>00660         <span class="keywordflow">return</span> NULL ;
+<a name="l00661"></a>00661     }
+<a name="l00662"></a>00662 
+<a name="l00663"></a>00663     <span class="keywordflow">for</span> (np=0 ; np < inp1 ; np++)
+<a name="l00664"></a>00664     {
+<a name="l00665"></a>00665       img3=cpl_image_new(ilx1,ily1,CPL_TYPE_FLOAT);
+<a name="l00666"></a>00666       cpl_imagelist_set(c3,img3,np);
+<a name="l00667"></a>00667     }
+<a name="l00668"></a>00668 
+<a name="l00669"></a>00669     <span class="keywordflow">for</span> (np=0 ; np < inp1 ; np++)
+<a name="l00670"></a>00670     {
+<a name="l00671"></a>00671       img1=cpl_imagelist_get(c1,np);
+<a name="l00672"></a>00672       p1data=cpl_image_get_data_float(img1);
+<a name="l00673"></a>00673       img2=cpl_imagelist_get(c2,np);
+<a name="l00674"></a>00674       p2data=cpl_image_get_data_float(img2);
+<a name="l00675"></a>00675       img3=cpl_imagelist_get(c3,np);
+<a name="l00676"></a>00676       p3data=cpl_image_get_data_float(img3);
+<a name="l00677"></a>00677         <span class="keywordflow">for</span> (i=0 ; i< (ulong32)ilx1*ily1 ; i++)
+<a name="l00678"></a>00678         {
+<a name="l00679"></a>00679         p3data[i] = p1data[i] + p2data[i] ;
+<a name="l00680"></a>00680         }
+<a name="l00681"></a>00681     }
+<a name="l00682"></a>00682 
+<a name="l00683"></a>00683     <span class="keywordflow">return</span> c3 ;
+<a name="l00684"></a>00684 }
+<a name="l00685"></a>00685 
+<a name="l00686"></a>00686 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00687"></a>00687 <span class="comment"> * Function    :    sinfo_new_cube_mul()</span>
+<a name="l00688"></a>00688 <span class="comment"> * In         :    two cubes</span>
+<a name="l00689"></a>00689 <span class="comment"> * Out         :    result cube</span>
+<a name="l00690"></a>00690 <span class="comment"> * Job        :    multiply 2 cubes</span>
+<a name="l00691"></a>00691 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00692"></a>00692 
+<a name="l00693"></a>00693 cpl_imagelist *
+<a name="l00694"></a>00694 sinfo_new_cube_mul(
+<a name="l00695"></a>00695     cpl_imagelist    *    c1,
+<a name="l00696"></a>00696     cpl_imagelist    *    c2
+<a name="l00697"></a>00697 )
+<a name="l00698"></a>00698 {
+<a name="l00699"></a>00699     cpl_imagelist             *c3 ;
+<a name="l00700"></a>00700     ulong32        i ;
+<a name="l00701"></a>00701     <span class="keywordtype">int</span>                np ;
+<a name="l00702"></a>00702     <span class="keywordtype">int</span> ilx1=0;
+<a name="l00703"></a>00703     <span class="keywordtype">int</span> ily1=0;
+<a name="l00704"></a>00704     <span class="keywordtype">int</span> inp1=0;
+<a name="l00705"></a>00705     <span class="keywordtype">int</span> ilx2=0;
+<a name="l00706"></a>00706     <span class="keywordtype">int</span> ily2=0;
+<a name="l00707"></a>00707     <span class="keywordtype">int</span> inp2=0;
+<a name="l00708"></a>00708 
+<a name="l00709"></a>00709 
+<a name="l00710"></a>00710     cpl_image* i_img=NULL;
+<a name="l00711"></a>00711     cpl_image* img1=NULL;
+<a name="l00712"></a>00712     cpl_image* img2=NULL;
+<a name="l00713"></a>00713     cpl_image* img3=NULL;
+<a name="l00714"></a>00714     <span class="keywordtype">float</span>* p1data=NULL;
+<a name="l00715"></a>00715     <span class="keywordtype">float</span>* p2data=NULL;
+<a name="l00716"></a>00716     <span class="keywordtype">float</span>* p3data=NULL;
+<a name="l00717"></a>00717 
+<a name="l00718"></a>00718 
+<a name="l00719"></a>00719 
+<a name="l00720"></a>00720 
+<a name="l00721"></a>00721     inp1=cpl_imagelist_get_size(c1);
+<a name="l00722"></a>00722     i_img=cpl_imagelist_get(c1,0);
+<a name="l00723"></a>00723     ilx1=cpl_image_get_size_x(i_img);
+<a name="l00724"></a>00724     ily1=cpl_image_get_size_y(i_img);
+<a name="l00725"></a>00725 
+<a name="l00726"></a>00726 
+<a name="l00727"></a>00727     inp2=cpl_imagelist_get_size(c2);
+<a name="l00728"></a>00728     i_img=cpl_imagelist_get(c2,0);
+<a name="l00729"></a>00729     ilx2=cpl_image_get_size_x(i_img);
+<a name="l00730"></a>00730     ily2=cpl_image_get_size_y(i_img);
+<a name="l00731"></a>00731 
+<a name="l00732"></a>00732     <span class="keywordflow">if</span> ((ilx1 != ilx2) || (ily1 != ily2))
+<a name="l00733"></a>00733     {
+<a name="l00734"></a>00734     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"incompatible size: cannot multiply"</span>) ;
+<a name="l00735"></a>00735     <span class="keywordflow">return</span> NULL ;
+<a name="l00736"></a>00736     }
+<a name="l00737"></a>00737 
+<a name="l00738"></a>00738     <span class="keywordflow">if</span> ((inp2 != inp1) && (inp2 != 1))
+<a name="l00739"></a>00739     {
+<a name="l00740"></a>00740     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"cannot compute with these number of planes"</span>) ;
+<a name="l00741"></a>00741     <span class="keywordflow">return</span> NULL ;
+<a name="l00742"></a>00742     }
+<a name="l00743"></a>00743 
+<a name="l00744"></a>00744     <span class="keywordflow">if</span> ( NULL == (c3 = cpl_imagelist_new()) )
+<a name="l00745"></a>00745     {
+<a name="l00746"></a>00746         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"cannot allocate new cube"</span> ) ;
+<a name="l00747"></a>00747         <span class="keywordflow">return</span> NULL ;
+<a name="l00748"></a>00748     }
+<a name="l00749"></a>00749 
+<a name="l00750"></a>00750 
+<a name="l00751"></a>00751     <span class="keywordflow">for</span> (np=0 ; np < inp1 ; np++)
+<a name="l00752"></a>00752     {
+<a name="l00753"></a>00753       img3=cpl_image_new(ilx1,ily1,CPL_TYPE_FLOAT);
+<a name="l00754"></a>00754       cpl_imagelist_set(c3,img3,np);
+<a name="l00755"></a>00755     }
+<a name="l00756"></a>00756 
+<a name="l00757"></a>00757     <span class="keywordflow">for</span> (np=0 ; np < inp1 ; np++)
+<a name="l00758"></a>00758     {
+<a name="l00759"></a>00759       img1=cpl_imagelist_get(c1,np);
+<a name="l00760"></a>00760       p1data=cpl_image_get_data_float(img1);
+<a name="l00761"></a>00761       img2=cpl_imagelist_get(c2,np);
+<a name="l00762"></a>00762       p2data=cpl_image_get_data_float(img2);
+<a name="l00763"></a>00763       img3=cpl_imagelist_get(c3,np);
+<a name="l00764"></a>00764       p3data=cpl_image_get_data_float(img3);
+<a name="l00765"></a>00765         <span class="keywordflow">for</span> (i=0 ; i< (ulong32)ilx1*ilx2 ; i++)
+<a name="l00766"></a>00766         {
+<a name="l00767"></a>00767             p3data[i] = p1data[i] * p2data[i] ;
+<a name="l00768"></a>00768         }
+<a name="l00769"></a>00769     }
+<a name="l00770"></a>00770 
+<a name="l00771"></a>00771     <span class="keywordflow">return</span> c3 ;
+<a name="l00772"></a>00772 }
+<a name="l00773"></a>00773 
+<a name="l00774"></a>00774 
+<a name="l00775"></a>00775 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00776"></a>00776 <span class="comment"> * Function    :    sinfo_new_cube_div()</span>
+<a name="l00777"></a>00777 <span class="comment"> * In         :    two cubes</span>
+<a name="l00778"></a>00778 <span class="comment"> * Out         :    result cube</span>
+<a name="l00779"></a>00779 <span class="comment"> * Job        :    divide 2 cubes</span>
+<a name="l00780"></a>00780 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00781"></a>00781 
+<a name="l00782"></a>00782 cpl_imagelist *
+<a name="l00783"></a>00783 sinfo_new_cube_div(
+<a name="l00784"></a>00784     cpl_imagelist    *    c1,
+<a name="l00785"></a>00785     cpl_imagelist    *    c2
+<a name="l00786"></a>00786 )
+<a name="l00787"></a>00787 {
+<a name="l00788"></a>00788     cpl_imagelist *           c3 ;
+<a name="l00789"></a>00789     ulong32        i ;
+<a name="l00790"></a>00790     <span class="keywordtype">int</span>         np ;
+<a name="l00791"></a>00791     <span class="keywordtype">int</span> ilx1=0;
+<a name="l00792"></a>00792     <span class="keywordtype">int</span> ily1=0;
+<a name="l00793"></a>00793     <span class="keywordtype">int</span> inp1=0;
+<a name="l00794"></a>00794     <span class="keywordtype">int</span> ilx2=0;
+<a name="l00795"></a>00795     <span class="keywordtype">int</span> ily2=0;
+<a name="l00796"></a>00796     <span class="keywordtype">int</span> inp2=0;
+<a name="l00797"></a>00797 
+<a name="l00798"></a>00798 
+<a name="l00799"></a>00799     cpl_image* i_img=NULL;
+<a name="l00800"></a>00800     cpl_image* img1=NULL;
+<a name="l00801"></a>00801     cpl_image* img2=NULL;
+<a name="l00802"></a>00802     cpl_image* img3=NULL;
+<a name="l00803"></a>00803     <span class="keywordtype">float</span>* p1data=NULL;
+<a name="l00804"></a>00804     <span class="keywordtype">float</span>* p2data=NULL;
+<a name="l00805"></a>00805     <span class="keywordtype">float</span>* p3data=NULL;
+<a name="l00806"></a>00806 
+<a name="l00807"></a>00807 
+<a name="l00808"></a>00808     inp1=cpl_imagelist_get_size(c1);
+<a name="l00809"></a>00809     i_img=cpl_imagelist_get(c1,0);
+<a name="l00810"></a>00810     ilx1=cpl_image_get_size_x(i_img);
+<a name="l00811"></a>00811     ily1=cpl_image_get_size_y(i_img);
+<a name="l00812"></a>00812 
+<a name="l00813"></a>00813 
+<a name="l00814"></a>00814     inp2=cpl_imagelist_get_size(c2);
+<a name="l00815"></a>00815     i_img=cpl_imagelist_get(c2,0);
+<a name="l00816"></a>00816     ilx2=cpl_image_get_size_x(i_img);
+<a name="l00817"></a>00817     ily2=cpl_image_get_size_y(i_img);
+<a name="l00818"></a>00818 
+<a name="l00819"></a>00819     <span class="keywordflow">if</span> ((ilx1 != ilx2) ||
+<a name="l00820"></a>00820     (ily1 != ily2))
+<a name="l00821"></a>00821     {
+<a name="l00822"></a>00822     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"incompatible size: cannot divide"</span>) ;
+<a name="l00823"></a>00823     <span class="keywordflow">return</span> NULL ;
+<a name="l00824"></a>00824     }
+<a name="l00825"></a>00825 
+<a name="l00826"></a>00826     <span class="keywordflow">if</span> ((inp2 != inp1) && (inp2 != 1))
+<a name="l00827"></a>00827     {
+<a name="l00828"></a>00828     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"cannot compute with these number of planes"</span>) ;
+<a name="l00829"></a>00829     <span class="keywordflow">return</span> NULL ;
+<a name="l00830"></a>00830     }
+<a name="l00831"></a>00831 
+<a name="l00832"></a>00832     <span class="keywordflow">if</span> (NULL == (c3 = cpl_imagelist_new()) )
+<a name="l00833"></a>00833     {
+<a name="l00834"></a>00834         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"cannot allocate a new cube"</span>) ;
+<a name="l00835"></a>00835         <span class="keywordflow">return</span> NULL ;
+<a name="l00836"></a>00836     }
+<a name="l00837"></a>00837 
+<a name="l00838"></a>00838     <span class="keywordflow">for</span> (np=0 ; np < inp1 ; np++)
+<a name="l00839"></a>00839     {
+<a name="l00840"></a>00840       img3=cpl_image_new(ilx1,ily1,CPL_TYPE_FLOAT);
+<a name="l00841"></a>00841       cpl_imagelist_set(c3,img3,np);
+<a name="l00842"></a>00842     }
+<a name="l00843"></a>00843 
+<a name="l00844"></a>00844     <span class="keywordflow">for</span> (np=0 ; np < inp1 ; np++)
+<a name="l00845"></a>00845     {
+<a name="l00846"></a>00846       img1=cpl_imagelist_get(c1,np);
+<a name="l00847"></a>00847       p1data=cpl_image_get_data_float(img1);
+<a name="l00848"></a>00848       img2=cpl_imagelist_get(c2,np);
+<a name="l00849"></a>00849       p2data=cpl_image_get_data_float(img2);
+<a name="l00850"></a>00850       img3=cpl_imagelist_get(c3,np);
+<a name="l00851"></a>00851       p3data=cpl_image_get_data_float(img3);
+<a name="l00852"></a>00852 
+<a name="l00853"></a>00853 
+<a name="l00854"></a>00854         <span class="keywordflow">for</span> (i=0 ; i< (ulong32) ilx1*ily1 ; i++)
+<a name="l00855"></a>00855         {
+<a name="l00856"></a>00856             <span class="keywordflow">if</span> (fabs((<span class="keywordtype">double</span>)p2data[i]) < 1e-10)
+<a name="l00857"></a>00857             {
+<a name="l00858"></a>00858             p3data[i] = 0.0 ;
+<a name="l00859"></a>00859             }
+<a name="l00860"></a>00860             <span class="keywordflow">else</span>
+<a name="l00861"></a>00861             {
+<a name="l00862"></a>00862                 p3data[i] = p1data[i] / p2data[i] ;
+<a name="l00863"></a>00863             }
+<a name="l00864"></a>00864         }
+<a name="l00865"></a>00865     }
+<a name="l00866"></a>00866 
+<a name="l00867"></a>00867     <span class="keywordflow">return</span> c3 ;
+<a name="l00868"></a>00868 }
+<a name="l00869"></a>00869 
+<a name="l00870"></a>00870 
+<a name="l00871"></a>00871 
+<a name="l00872"></a>00872 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00873"></a>00873 <span class="comment">   Function    :    sinfo_new_add_image_to_cube()</span>
+<a name="l00874"></a>00874 <span class="comment">   In         :    1 allocated cube, 1 allocated image</span>
+<a name="l00875"></a>00875 <span class="comment">   Out         :    result cube</span>
+<a name="l00876"></a>00876 <span class="comment">   Job        :    add an image to all planes in the cube</span>
+<a name="l00877"></a>00877 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00878"></a>00878 
+<a name="l00879"></a>00879 cpl_imagelist *
+<a name="l00880"></a>00880 sinfo_new_add_image_to_cube(cpl_imagelist * cu, cpl_image * im)
+<a name="l00881"></a>00881 {
+<a name="l00882"></a>00882     cpl_imagelist *   cube ;
+<a name="l00883"></a>00883     <span class="keywordtype">int</span>               i ;
+<a name="l00884"></a>00884     <span class="keywordtype">int</span> clx=0;
+<a name="l00885"></a>00885     <span class="keywordtype">int</span> cly=0;
+<a name="l00886"></a>00886     <span class="keywordtype">int</span> cnp=0;
+<a name="l00887"></a>00887     <span class="keywordtype">int</span> ilx=0;
+<a name="l00888"></a>00888     <span class="keywordtype">int</span> ily=0;
+<a name="l00889"></a>00889 
+<a name="l00890"></a>00890 
+<a name="l00891"></a>00891     cpl_image* i_img=NULL;
+<a name="l00892"></a>00892 
+<a name="l00893"></a>00893     <span class="keywordflow">if</span> (cu==NULL || im==NULL)
+<a name="l00894"></a>00894     {
+<a name="l00895"></a>00895        <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"null cube or null image"</span>) ;
+<a name="l00896"></a>00896        <span class="keywordflow">return</span> NULL ;
+<a name="l00897"></a>00897     }
+<a name="l00898"></a>00898     cnp=cpl_imagelist_get_size(cu);
+<a name="l00899"></a>00899     i_img=cpl_imagelist_get(cu,0);
+<a name="l00900"></a>00900     clx=cpl_image_get_size_x(i_img);
+<a name="l00901"></a>00901     cly=cpl_image_get_size_y(i_img);
+<a name="l00902"></a>00902 
+<a name="l00903"></a>00903     ilx=cpl_image_get_size_x(im);
+<a name="l00904"></a>00904     ily=cpl_image_get_size_y(im);
+<a name="l00905"></a>00905 
+<a name="l00906"></a>00906     <span class="keywordflow">if</span> ((clx != ilx) || (cly != ily))
+<a name="l00907"></a>00907     {
+<a name="l00908"></a>00908         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"incompatible size: cannot add image to cube"</span>) ;
+<a name="l00909"></a>00909     <span class="keywordflow">return</span> NULL ;
+<a name="l00910"></a>00910     }
+<a name="l00911"></a>00911 
+<a name="l00912"></a>00912     cube = cpl_imagelist_duplicate (cu) ;
+<a name="l00913"></a>00913 
+<a name="l00914"></a>00914     <span class="keywordflow">for</span> (i=0 ; i<cnp ; i++)
+<a name="l00915"></a>00915     {
+<a name="l00916"></a>00916       <span class="comment">/* AMO</span>
+<a name="l00917"></a>00917 <span class="comment">        here may be we have to use cpl_image_add_create and cpl_imagelist_set</span>
+<a name="l00918"></a>00918 <span class="comment">       */</span>
+<a name="l00919"></a>00919     cpl_image_add(cpl_imagelist_get(cube,i), im) ;
+<a name="l00920"></a>00920     }
+<a name="l00921"></a>00921 
+<a name="l00922"></a>00922     <span class="keywordflow">return</span> cube ;
+<a name="l00923"></a>00923 }
+<a name="l00924"></a>00924 
+<a name="l00925"></a>00925 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00926"></a>00926 <span class="comment">   Function    :    sinfo_new_sub_image_from_cube()</span>
+<a name="l00927"></a>00927 <span class="comment">   In         :    1 allocated cube, 1 allocated image</span>
+<a name="l00928"></a>00928 <span class="comment">   Out         :       result cube</span>
+<a name="l00929"></a>00929 <span class="comment">   Job        :    subtract an image from all planes in the cube</span>
+<a name="l00930"></a>00930 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00931"></a>00931 
+<a name="l00932"></a>00932 cpl_imagelist *
+<a name="l00933"></a>00933 sinfo_new_sub_image_from_cube (cpl_imagelist * cu, cpl_image * im)
+<a name="l00934"></a>00934 {
+<a name="l00935"></a>00935     cpl_imagelist   * cube ;
+<a name="l00936"></a>00936     <span class="keywordtype">int</span>               i ;
+<a name="l00937"></a>00937     <span class="keywordtype">int</span> clx=0;
+<a name="l00938"></a>00938     <span class="keywordtype">int</span> cly=0;
+<a name="l00939"></a>00939     <span class="keywordtype">int</span> cnp=0;
+<a name="l00940"></a>00940     <span class="keywordtype">int</span> ilx=0;
+<a name="l00941"></a>00941     <span class="keywordtype">int</span> ily=0;
+<a name="l00942"></a>00942 
+<a name="l00943"></a>00943 
+<a name="l00944"></a>00944     cpl_image* i_img=NULL;
+<a name="l00945"></a>00945 
+<a name="l00946"></a>00946     <span class="keywordflow">if</span> (cu==NULL || im==NULL)
+<a name="l00947"></a>00947     {
+<a name="l00948"></a>00948         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"null cube or null image"</span>) ;
+<a name="l00949"></a>00949         <span class="keywordflow">return</span> NULL ;
+<a name="l00950"></a>00950     }
+<a name="l00951"></a>00951     cnp=cpl_imagelist_get_size(cu);
+<a name="l00952"></a>00952     i_img=cpl_imagelist_get(cu,0);
+<a name="l00953"></a>00953     clx=cpl_image_get_size_x(i_img);
+<a name="l00954"></a>00954     cly=cpl_image_get_size_y(i_img);
+<a name="l00955"></a>00955 
+<a name="l00956"></a>00956     ilx=cpl_image_get_size_x(im);
+<a name="l00957"></a>00957     ily=cpl_image_get_size_y(im);
+<a name="l00958"></a>00958 
+<a name="l00959"></a>00959     <span class="keywordflow">if</span> ((clx != ilx) || (cly != ily))
+<a name="l00960"></a>00960     {
+<a name="l00961"></a>00961 
+<a name="l00962"></a>00962     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"incompatible size: cannot subtract image from cube"</span>) ;
+<a name="l00963"></a>00963         <span class="keywordflow">return</span> NULL ;
+<a name="l00964"></a>00964     }
+<a name="l00965"></a>00965 
+<a name="l00966"></a>00966     cube = cpl_imagelist_duplicate (cu) ;
+<a name="l00967"></a>00967 
+<a name="l00968"></a>00968     <span class="keywordflow">for</span> (i=0 ; i<cnp ; i++)
+<a name="l00969"></a>00969     {
+<a name="l00970"></a>00970       <span class="comment">/* AMO</span>
+<a name="l00971"></a>00971 <span class="comment">        here may be we have to use cpl_image_add_create and cpl_imagelist_set</span>
+<a name="l00972"></a>00972 <span class="comment">       */</span>
+<a name="l00973"></a>00973     cpl_image_subtract(cpl_imagelist_get(cube,i), im) ;
+<a name="l00974"></a>00974     }
+<a name="l00975"></a>00975     <span class="keywordflow">return</span> cube ;
+<a name="l00976"></a>00976 }
+<a name="l00977"></a>00977 
+<a name="l00978"></a>00978 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00979"></a>00979 <span class="comment">   Function    :    sinfo_new_mul_image_to_cube()</span>
+<a name="l00980"></a>00980 <span class="comment">   In         :    1 allocated cube, 1 allocated image</span>
+<a name="l00981"></a>00981 <span class="comment">   Out         :    result cube</span>
+<a name="l00982"></a>00982 <span class="comment">   Job        :    multiply an image to all planes in the cube</span>
+<a name="l00983"></a>00983 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00984"></a>00984 
+<a name="l00985"></a>00985 cpl_imagelist *
+<a name="l00986"></a>00986 sinfo_new_mul_image_to_cube(cpl_imagelist * cu, cpl_image * im)
+<a name="l00987"></a>00987 {
+<a name="l00988"></a>00988     cpl_imagelist   * cube ;
+<a name="l00989"></a>00989     <span class="keywordtype">int</span>               i ;
+<a name="l00990"></a>00990     <span class="keywordtype">int</span> clx=0;
+<a name="l00991"></a>00991     <span class="keywordtype">int</span> cly=0;
+<a name="l00992"></a>00992     <span class="keywordtype">int</span> cnp=0;
+<a name="l00993"></a>00993     <span class="keywordtype">int</span> ilx=0;
+<a name="l00994"></a>00994     <span class="keywordtype">int</span> ily=0;
+<a name="l00995"></a>00995 
+<a name="l00996"></a>00996 
+<a name="l00997"></a>00997     cpl_image* i_img=NULL;
+<a name="l00998"></a>00998 
+<a name="l00999"></a>00999     <span class="keywordflow">if</span> (cu==NULL || im==NULL)
+<a name="l01000"></a>01000     {
+<a name="l01001"></a>01001         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"null cube or null image"</span>) ;
+<a name="l01002"></a>01002         <span class="keywordflow">return</span> NULL ;
+<a name="l01003"></a>01003     }
+<a name="l01004"></a>01004     cnp=cpl_imagelist_get_size(cu);
+<a name="l01005"></a>01005     i_img=cpl_imagelist_get(cu,0);
+<a name="l01006"></a>01006     clx=cpl_image_get_size_x(i_img);
+<a name="l01007"></a>01007     cly=cpl_image_get_size_y(i_img);
+<a name="l01008"></a>01008 
+<a name="l01009"></a>01009     ilx=cpl_image_get_size_x(im);
+<a name="l01010"></a>01010     ily=cpl_image_get_size_y(im);
+<a name="l01011"></a>01011 
+<a name="l01012"></a>01012     <span class="keywordflow">if</span> ((clx != ilx) || (cly != ily))
+<a name="l01013"></a>01013     {
+<a name="l01014"></a>01014     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"incompatible size: cannot multiply image by cube"</span>) ;
+<a name="l01015"></a>01015     <span class="keywordflow">return</span> NULL ;
+<a name="l01016"></a>01016     }
+<a name="l01017"></a>01017 
+<a name="l01018"></a>01018     cube = cpl_imagelist_duplicate (cu) ;
+<a name="l01019"></a>01019 
+<a name="l01020"></a>01020     <span class="keywordflow">for</span> (i=0 ; i<cnp ; i++)
+<a name="l01021"></a>01021     {
+<a name="l01022"></a>01022       <span class="comment">/* AMO</span>
+<a name="l01023"></a>01023 <span class="comment">        here may be we have to use cpl_image_add_create and cpl_imagelist_set</span>
+<a name="l01024"></a>01024 <span class="comment">       */</span>
+<a name="l01025"></a>01025     cpl_image_multiply(cpl_imagelist_get(cube,i), im) ;
+<a name="l01026"></a>01026     }
+<a name="l01027"></a>01027 
+<a name="l01028"></a>01028     <span class="keywordflow">return</span> cube ;
+<a name="l01029"></a>01029 }
+<a name="l01030"></a>01030 
+<a name="l01031"></a>01031 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l01032"></a>01032 <span class="comment">   Function    :    sinfo_new_div_cube_by_image()</span>
+<a name="l01033"></a>01033 <span class="comment">   In         :    1 allocated cube, 1 allocated image</span>
+<a name="l01034"></a>01034 <span class="comment">   Out         :    result cube</span>
+<a name="l01035"></a>01035 <span class="comment">   Job        :    divide all planes in the cube by an image</span>
+<a name="l01036"></a>01036 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l01037"></a>01037 
+<a name="l01038"></a>01038 cpl_imagelist *
+<a name="l01039"></a>01039 sinfo_new_div_cube_by_image(cpl_imagelist * cu, cpl_image * im)
+<a name="l01040"></a>01040 {
+<a name="l01041"></a>01041     cpl_imagelist   * cube ;
+<a name="l01042"></a>01042     <span class="keywordtype">int</span>               i ;
+<a name="l01043"></a>01043     <span class="keywordtype">int</span> clx=0;
+<a name="l01044"></a>01044     <span class="keywordtype">int</span> cly=0;
+<a name="l01045"></a>01045     <span class="keywordtype">int</span> cnp=0;
+<a name="l01046"></a>01046     <span class="keywordtype">int</span> ilx=0;
+<a name="l01047"></a>01047     <span class="keywordtype">int</span> ily=0;
+<a name="l01048"></a>01048 
+<a name="l01049"></a>01049 
+<a name="l01050"></a>01050     cpl_image* i_img=NULL;
+<a name="l01051"></a>01051 
+<a name="l01052"></a>01052     <span class="keywordflow">if</span> (cu==NULL || im==NULL)
+<a name="l01053"></a>01053     {
+<a name="l01054"></a>01054         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"null cube or null image"</span>) ;
+<a name="l01055"></a>01055         <span class="keywordflow">return</span> NULL ;
+<a name="l01056"></a>01056     }
+<a name="l01057"></a>01057     cnp=cpl_imagelist_get_size(cu);
+<a name="l01058"></a>01058     i_img=cpl_imagelist_get(cu,0);
+<a name="l01059"></a>01059     clx=cpl_image_get_size_x(i_img);
+<a name="l01060"></a>01060     cly=cpl_image_get_size_y(i_img);
+<a name="l01061"></a>01061 
+<a name="l01062"></a>01062     ilx=cpl_image_get_size_x(im);
+<a name="l01063"></a>01063     ily=cpl_image_get_size_y(im);
+<a name="l01064"></a>01064 
+<a name="l01065"></a>01065     <span class="keywordflow">if</span> ((clx != ilx) || (cly != ily))
+<a name="l01066"></a>01066     {
+<a name="l01067"></a>01067     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"incompatible size: cannot divide cube by image"</span>) ;
+<a name="l01068"></a>01068     <span class="keywordflow">return</span> NULL ;
+<a name="l01069"></a>01069     }
+<a name="l01070"></a>01070 
+<a name="l01071"></a>01071     cube = cpl_imagelist_duplicate (cu) ;
+<a name="l01072"></a>01072 
+<a name="l01073"></a>01073     <span class="keywordflow">for</span> (i=0 ; i<cnp ; i++)
+<a name="l01074"></a>01074     {
+<a name="l01075"></a>01075       <span class="comment">/* AMO</span>
+<a name="l01076"></a>01076 <span class="comment">        here may be we have to use cpl_image_add_create and cpl_imagelist_set</span>
+<a name="l01077"></a>01077 <span class="comment">       */</span>
+<a name="l01078"></a>01078     cpl_image_divide(cpl_imagelist_get(cube,i), im) ;
+<a name="l01079"></a>01079     }
+<a name="l01080"></a>01080 
+<a name="l01081"></a>01081     <span class="keywordflow">return</span> cube ;
+<a name="l01082"></a>01082 }
+<a name="l01083"></a>01083 
+<a name="l01084"></a>01084 
+<a name="l01085"></a>01085 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l01086"></a>01086 <span class="comment">   Function    :    sinfo_new_add_spectrum_to_cube()</span>
+<a name="l01087"></a>01087 <span class="comment">   In         :    1 allocated cube, 1 allocated spectrum sinfo_vector</span>
+<a name="l01088"></a>01088 <span class="comment">   Out         :    result cube</span>
+<a name="l01089"></a>01089 <span class="comment">   Job        :    adds a spectrum (in z-direction) to all data</span>
+<a name="l01090"></a>01090 <span class="comment">                        points in a cube</span>
+<a name="l01091"></a>01091 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l01092"></a>01092 
+<a name="l01093"></a>01093 cpl_imagelist *
+<a name="l01094"></a>01094 sinfo_new_add_spectrum_to_cube(cpl_imagelist *cu, Vector *spec)
+<a name="l01095"></a>01095 {
+<a name="l01096"></a>01096     cpl_imagelist *   cube ;
+<a name="l01097"></a>01097     <span class="keywordtype">int</span>         i ,j ;
+<a name="l01098"></a>01098     <span class="keywordtype">int</span> ilx=0;
+<a name="l01099"></a>01099     <span class="keywordtype">int</span> ily=0;
+<a name="l01100"></a>01100     <span class="keywordtype">int</span> inp=0;
+<a name="l01101"></a>01101     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l01102"></a>01102     <span class="keywordtype">float</span>* podata=NULL;
+<a name="l01103"></a>01103     cpl_image* i_img=NULL;
+<a name="l01104"></a>01104     cpl_image* o_img=NULL;
+<a name="l01105"></a>01105 
+<a name="l01106"></a>01106     <span class="keywordflow">if</span> (cu == NULL || spec == NULL)
+<a name="l01107"></a>01107     {
+<a name="l01108"></a>01108         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"null cube or null spectrum"</span>) ;
+<a name="l01109"></a>01109         <span class="keywordflow">return</span> NULL ;
+<a name="l01110"></a>01110     }
+<a name="l01111"></a>01111     inp=cpl_imagelist_get_size(cu);
+<a name="l01112"></a>01112     i_img=cpl_imagelist_get(cu,0);
+<a name="l01113"></a>01113     ilx=cpl_image_get_size_x(i_img);
+<a name="l01114"></a>01114     ily=cpl_image_get_size_y(i_img);
+<a name="l01115"></a>01115 
+<a name="l01116"></a>01116     <span class="keywordflow">if</span> ( inp != spec -> n_elements )
+<a name="l01117"></a>01117     {
+<a name="l01118"></a>01118         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"cube length and spectrum length are not compatible"</span>) ;
+<a name="l01119"></a>01119         <span class="keywordflow">return</span> NULL ;
+<a name="l01120"></a>01120     }
+<a name="l01121"></a>01121 
+<a name="l01122"></a>01122     <span class="keywordflow">if</span> ( NULL == (cube = cpl_imagelist_new ()) )
+<a name="l01123"></a>01123     {
+<a name="l01124"></a>01124         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"cannot allocate new cube"</span> ) ;
+<a name="l01125"></a>01125         <span class="keywordflow">return</span> NULL ;
+<a name="l01126"></a>01126     }
+<a name="l01127"></a>01127     <span class="keywordflow">for</span> ( i = 0; i < inp; i++)
+<a name="l01128"></a>01128     {
+<a name="l01129"></a>01129       o_img=cpl_image_new(ilx,ily,CPL_TYPE_FLOAT);
+<a name="l01130"></a>01130       cpl_imagelist_set(cube,o_img,i);
+<a name="l01131"></a>01131     }
+<a name="l01132"></a>01132 
+<a name="l01133"></a>01133 
+<a name="l01134"></a>01134     <span class="keywordflow">for</span> ( i = 0; i < inp; i++)
+<a name="l01135"></a>01135     {
+<a name="l01136"></a>01136       i_img=cpl_imagelist_get(cu,i);
+<a name="l01137"></a>01137       pidata=cpl_image_get_data_float(i_img);
+<a name="l01138"></a>01138       o_img=cpl_imagelist_get(cube,i);
+<a name="l01139"></a>01139       podata=cpl_image_get_data_float(o_img);
+<a name="l01140"></a>01140         <span class="keywordflow">for</span> ( j = 0; j < (int) ilx*ily; j++)
+<a name="l01141"></a>01141         {
+<a name="l01142"></a>01142             podata[j] = pidata[j] + spec -> data[i] ;
+<a name="l01143"></a>01143         }
+<a name="l01144"></a>01144     }
+<a name="l01145"></a>01145 
+<a name="l01146"></a>01146     <span class="keywordflow">return</span> cube ;
+<a name="l01147"></a>01147 }
+<a name="l01148"></a>01148 
+<a name="l01149"></a>01149 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l01150"></a>01150 <span class="comment">   Function    :    sinfo_new_sub_spectrum_from_cube()</span>
+<a name="l01151"></a>01151 <span class="comment">   In         :    1 allocated cube, 1 allocated spectrum sinfo_vector</span>
+<a name="l01152"></a>01152 <span class="comment">   Out         :    result cube</span>
+<a name="l01153"></a>01153 <span class="comment">   Job        :    subtracts a spectrum (in z-direction) from all</span>
+<a name="l01154"></a>01154 <span class="comment">                        data points in a cube</span>
+<a name="l01155"></a>01155 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l01156"></a>01156 
+<a name="l01157"></a>01157 cpl_imagelist *
+<a name="l01158"></a>01158 sinfo_new_sub_spectrum_from_cube(cpl_imagelist *cu, Vector *spec)
+<a name="l01159"></a>01159 {
+<a name="l01160"></a>01160     cpl_imagelist *   cube ;
+<a name="l01161"></a>01161     <span class="keywordtype">int</span>         i ,j ;
+<a name="l01162"></a>01162     <span class="keywordtype">int</span> ilx=0;
+<a name="l01163"></a>01163     <span class="keywordtype">int</span> ily=0;
+<a name="l01164"></a>01164     <span class="keywordtype">int</span> inp=0;
+<a name="l01165"></a>01165     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l01166"></a>01166     <span class="keywordtype">float</span>* podata=NULL;
+<a name="l01167"></a>01167     cpl_image* i_img=NULL;
+<a name="l01168"></a>01168     cpl_image* o_img=NULL;
+<a name="l01169"></a>01169 
+<a name="l01170"></a>01170     <span class="keywordflow">if</span> (cu == NULL || spec == NULL)
+<a name="l01171"></a>01171     {
+<a name="l01172"></a>01172         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"null cube or null spectrum"</span>) ;
+<a name="l01173"></a>01173         <span class="keywordflow">return</span> NULL ;
+<a name="l01174"></a>01174     }
+<a name="l01175"></a>01175     inp=cpl_imagelist_get_size(cu);
+<a name="l01176"></a>01176     i_img=cpl_imagelist_get(cu,0);
+<a name="l01177"></a>01177     ilx=cpl_image_get_size_x(i_img);
+<a name="l01178"></a>01178     ily=cpl_image_get_size_y(i_img);
+<a name="l01179"></a>01179 
+<a name="l01180"></a>01180     <span class="keywordflow">if</span> ( inp != spec -> n_elements )
+<a name="l01181"></a>01181     {
+<a name="l01182"></a>01182         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"cube length and spectrum length are not compatible"</span>) ;
+<a name="l01183"></a>01183         <span class="keywordflow">return</span> NULL ;
+<a name="l01184"></a>01184     }
+<a name="l01185"></a>01185 
+<a name="l01186"></a>01186     <span class="keywordflow">if</span> ( NULL == (cube = cpl_imagelist_new()) )
+<a name="l01187"></a>01187     {
+<a name="l01188"></a>01188         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"cannot allocate new cube"</span> ) ;
+<a name="l01189"></a>01189         <span class="keywordflow">return</span> NULL ;
+<a name="l01190"></a>01190     }
+<a name="l01191"></a>01191     <span class="keywordflow">for</span> ( i = 0; i < inp; i++)
+<a name="l01192"></a>01192     {
+<a name="l01193"></a>01193       o_img=cpl_image_new(ilx,ily,CPL_TYPE_FLOAT);
+<a name="l01194"></a>01194       cpl_imagelist_set(cube,o_img,i);
+<a name="l01195"></a>01195     }
+<a name="l01196"></a>01196 
+<a name="l01197"></a>01197     <span class="keywordflow">for</span> ( i = 0; i < inp; i++)
+<a name="l01198"></a>01198     {
+<a name="l01199"></a>01199       i_img=cpl_imagelist_get(cu,i);
+<a name="l01200"></a>01200       pidata=cpl_image_get_data_float(i_img);
+<a name="l01201"></a>01201       o_img=cpl_imagelist_get(cube,i);
+<a name="l01202"></a>01202       podata=cpl_image_get_data_float(o_img);
+<a name="l01203"></a>01203         <span class="keywordflow">for</span> ( j = 0; j < (int) ilx*ily; j++)
+<a name="l01204"></a>01204         {
+<a name="l01205"></a>01205             <span class="keywordflow">if</span> ( isnan(pidata[j]) || isnan(spec -> data[i]) )
+<a name="l01206"></a>01206             {
+<a name="l01207"></a>01207                 podata[j] = ZERO ;
+<a name="l01208"></a>01208             }
+<a name="l01209"></a>01209             <span class="keywordflow">else</span>
+<a name="l01210"></a>01210             {
+<a name="l01211"></a>01211                 podata[j] = pidata[j] - spec -> data[i] ;
+<a name="l01212"></a>01212             }
+<a name="l01213"></a>01213         }
+<a name="l01214"></a>01214     }
+<a name="l01215"></a>01215 
+<a name="l01216"></a>01216     <span class="keywordflow">return</span> cube ;
+<a name="l01217"></a>01217 }
+<a name="l01218"></a>01218 
+<a name="l01219"></a>01219 
+<a name="l01220"></a>01220 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l01221"></a>01221 <span class="comment">   Function    :    sinfo_new_mul_spectrum_to_cube()</span>
+<a name="l01222"></a>01222 <span class="comment">   In         :    1 allocated cube, 1 allocated spectrum sinfo_vector</span>
+<a name="l01223"></a>01223 <span class="comment">   Out         :    result cube</span>
+<a name="l01224"></a>01224 <span class="comment">   Job        :    multiplies a spectrum (in z-direction) to all data</span>
+<a name="l01225"></a>01225 <span class="comment">                        points in a cube</span>
+<a name="l01226"></a>01226 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l01227"></a>01227 
+<a name="l01228"></a>01228 cpl_imagelist *
+<a name="l01229"></a>01229 sinfo_new_mul_spectrum_to_cube(cpl_imagelist *cu, Vector *spec)
+<a name="l01230"></a>01230 {
+<a name="l01231"></a>01231     cpl_imagelist *   cube ;
+<a name="l01232"></a>01232     <span class="keywordtype">int</span>         i ,j ;
+<a name="l01233"></a>01233     <span class="keywordtype">int</span> ilx=0;
+<a name="l01234"></a>01234     <span class="keywordtype">int</span> ily=0;
+<a name="l01235"></a>01235     <span class="keywordtype">int</span> inp=0;
+<a name="l01236"></a>01236     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l01237"></a>01237     <span class="keywordtype">float</span>* podata=NULL;
+<a name="l01238"></a>01238     cpl_image* i_img=NULL;
+<a name="l01239"></a>01239     cpl_image* o_img=NULL;
+<a name="l01240"></a>01240 
+<a name="l01241"></a>01241     <span class="keywordflow">if</span> (cu == NULL || spec == NULL)
+<a name="l01242"></a>01242     {
+<a name="l01243"></a>01243         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"null cube or null spectrum"</span>) ;
+<a name="l01244"></a>01244         <span class="keywordflow">return</span> NULL ;
+<a name="l01245"></a>01245     }
+<a name="l01246"></a>01246     inp=cpl_imagelist_get_size(cu);
+<a name="l01247"></a>01247     i_img=cpl_imagelist_get(cu,0);
+<a name="l01248"></a>01248     ilx=cpl_image_get_size_x(i_img);
+<a name="l01249"></a>01249     ily=cpl_image_get_size_y(i_img);
+<a name="l01250"></a>01250 
+<a name="l01251"></a>01251     <span class="keywordflow">if</span> ( inp != spec -> n_elements )
+<a name="l01252"></a>01252     {
+<a name="l01253"></a>01253         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"cube length and spectrum length are not compatible"</span>) ;
+<a name="l01254"></a>01254         <span class="keywordflow">return</span> NULL ;
+<a name="l01255"></a>01255     }
+<a name="l01256"></a>01256 
+<a name="l01257"></a>01257     <span class="keywordflow">if</span> ( NULL == (cube = cpl_imagelist_new ()) )
+<a name="l01258"></a>01258     {
+<a name="l01259"></a>01259         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"cannot allocate new cube"</span> ) ;
+<a name="l01260"></a>01260         <span class="keywordflow">return</span> NULL ;
+<a name="l01261"></a>01261     }
+<a name="l01262"></a>01262 
+<a name="l01263"></a>01263     <span class="keywordflow">for</span> ( i = 0; i < inp; i++)
+<a name="l01264"></a>01264     {
+<a name="l01265"></a>01265       o_img=cpl_image_new(ilx,ily,CPL_TYPE_FLOAT);
+<a name="l01266"></a>01266       cpl_imagelist_set(cube,o_img,i);
+<a name="l01267"></a>01267     }
+<a name="l01268"></a>01268 
+<a name="l01269"></a>01269     <span class="keywordflow">for</span> ( i = 0; i < inp; i++)
+<a name="l01270"></a>01270     {
+<a name="l01271"></a>01271       i_img=cpl_imagelist_get(cu,i);
+<a name="l01272"></a>01272       pidata=cpl_image_get_data_float(i_img);
+<a name="l01273"></a>01273       o_img=cpl_imagelist_get(cube,i);
+<a name="l01274"></a>01274       podata=cpl_image_get_data_float(o_img);
+<a name="l01275"></a>01275         <span class="keywordflow">for</span> ( j = 0; j < (int) ilx*ily; j++)
+<a name="l01276"></a>01276         {
+<a name="l01277"></a>01277             <span class="keywordflow">if</span> ( isnan(pidata[j]) || isnan(spec->data[i]) )
+<a name="l01278"></a>01278             {
+<a name="l01279"></a>01279                 podata[j] = ZERO ;
+<a name="l01280"></a>01280             }
+<a name="l01281"></a>01281             <span class="keywordflow">else</span>
+<a name="l01282"></a>01282             {
+<a name="l01283"></a>01283                 podata[j] = pidata[j] * spec -> data[i] ;
+<a name="l01284"></a>01284             }
+<a name="l01285"></a>01285         }
+<a name="l01286"></a>01286     }
+<a name="l01287"></a>01287 
+<a name="l01288"></a>01288     <span class="keywordflow">return</span> cube ;
+<a name="l01289"></a>01289 }
+<a name="l01290"></a>01290 
+<a name="l01291"></a>01291 
+<a name="l01292"></a>01292 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l01293"></a>01293 <span class="comment">   Function    :    sinfo_new_div_cube_by_spectrum()</span>
+<a name="l01294"></a>01294 <span class="comment">   In         :    1 allocated cube, 1 allocated spectrum sinfo_vector</span>
+<a name="l01295"></a>01295 <span class="comment">   Out         :    result cube</span>
+<a name="l01296"></a>01296 <span class="comment">   Job        :    divides all data points of a cube by a spectrum</span>
+<a name="l01297"></a>01297 <span class="comment">                        (in z-direction)</span>
+<a name="l01298"></a>01298 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l01299"></a>01299 
+<a name="l01300"></a>01300 cpl_imagelist *
+<a name="l01301"></a>01301 sinfo_new_div_cube_by_spectrum(cpl_imagelist *cu, Vector *spec)
+<a name="l01302"></a>01302 {
+<a name="l01303"></a>01303     cpl_imagelist *   cube ;
+<a name="l01304"></a>01304     <span class="keywordtype">float</span>       help ;
+<a name="l01305"></a>01305     <span class="keywordtype">int</span>         i ,j ;
+<a name="l01306"></a>01306     <span class="keywordtype">int</span> ilx=0;
+<a name="l01307"></a>01307     <span class="keywordtype">int</span> ily=0;
+<a name="l01308"></a>01308     <span class="keywordtype">int</span> inp=0;
+<a name="l01309"></a>01309     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l01310"></a>01310     <span class="keywordtype">float</span>* podata=NULL;
+<a name="l01311"></a>01311     cpl_image* i_img=NULL;
+<a name="l01312"></a>01312     cpl_image* o_img=NULL;
+<a name="l01313"></a>01313 
+<a name="l01314"></a>01314     <span class="keywordflow">if</span> (cu == NULL || spec == NULL)
+<a name="l01315"></a>01315     {
+<a name="l01316"></a>01316         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"null cube or null spectrum"</span>) ;
+<a name="l01317"></a>01317         <span class="keywordflow">return</span> NULL ;
+<a name="l01318"></a>01318     }
+<a name="l01319"></a>01319     inp=cpl_imagelist_get_size(cu);
+<a name="l01320"></a>01320     i_img=cpl_imagelist_get(cu,0);
+<a name="l01321"></a>01321     ilx=cpl_image_get_size_x(i_img);
+<a name="l01322"></a>01322     ily=cpl_image_get_size_y(i_img);
+<a name="l01323"></a>01323 
+<a name="l01324"></a>01324     <span class="keywordflow">if</span> ( inp != spec -> n_elements )
+<a name="l01325"></a>01325     {
+<a name="l01326"></a>01326         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"cube length and spectrum length are not compatible"</span>) ;
+<a name="l01327"></a>01327         <span class="keywordflow">return</span> NULL ;
+<a name="l01328"></a>01328     }
+<a name="l01329"></a>01329 
+<a name="l01330"></a>01330     <span class="keywordflow">if</span> (NULL == (cube = cpl_imagelist_new ()) )
+<a name="l01331"></a>01331     {
+<a name="l01332"></a>01332         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"cannot allocate new cube"</span>) ;
+<a name="l01333"></a>01333         <span class="keywordflow">return</span> NULL ;
+<a name="l01334"></a>01334     }
+<a name="l01335"></a>01335 
+<a name="l01336"></a>01336     <span class="keywordflow">for</span> ( i = 0; i < inp; i++)
+<a name="l01337"></a>01337     {
+<a name="l01338"></a>01338       o_img=cpl_image_new(ilx,ily,CPL_TYPE_FLOAT);
+<a name="l01339"></a>01339       cpl_imagelist_set(cube,o_img,i);
+<a name="l01340"></a>01340     }
+<a name="l01341"></a>01341 
+<a name="l01342"></a>01342     <span class="keywordflow">for</span> ( i = 0; i < inp; i++)
+<a name="l01343"></a>01343     {
+<a name="l01344"></a>01344 
+<a name="l01345"></a>01345       i_img=cpl_imagelist_get(cu,i);
+<a name="l01346"></a>01346       pidata=cpl_image_get_data_float(i_img);
+<a name="l01347"></a>01347       o_img=cpl_imagelist_get(cube,i);
+<a name="l01348"></a>01348       podata=cpl_image_get_data_float(o_img);
+<a name="l01349"></a>01349         <span class="keywordflow">for</span> ( j = 0; j < (int) ilx*ily; j++)
+<a name="l01350"></a>01350         {
+<a name="l01351"></a>01351             <span class="keywordflow">if</span> (!isnan(spec->data[i]) && spec->data[i] != 0.)
+<a name="l01352"></a>01352             {
+<a name="l01353"></a>01353                 help = 1/spec->data[i] ;
+<a name="l01354"></a>01354                 <span class="keywordflow">if</span> ( help > THRESH )
+<a name="l01355"></a>01355                 {
+<a name="l01356"></a>01356                     help = 1. ;
+<a name="l01357"></a>01357                 }
+<a name="l01358"></a>01358             }
+<a name="l01359"></a>01359             <span class="keywordflow">else</span>
+<a name="l01360"></a>01360             {
+<a name="l01361"></a>01361                 help = ZERO ;
+<a name="l01362"></a>01362             }
+<a name="l01363"></a>01363 
+<a name="l01364"></a>01364             <span class="keywordflow">if</span> ( isnan(help) || isnan(pidata[j]) )
+<a name="l01365"></a>01365             {
+<a name="l01366"></a>01366                 podata[j] = ZERO ;
+<a name="l01367"></a>01367             }
+<a name="l01368"></a>01368             <span class="keywordflow">else</span>
+<a name="l01369"></a>01369             {
+<a name="l01370"></a>01370                 podata[j] = pidata[j] * help ;
+<a name="l01371"></a>01371             }
+<a name="l01372"></a>01372         }
+<a name="l01373"></a>01373     }
+<a name="l01374"></a>01374     <span class="keywordflow">return</span> cube ;
+<a name="l01375"></a>01375 }
+<a name="l01376"></a>01376 
+<a name="l01377"></a>01377 
+<a name="l01378"></a>01378 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l01379"></a>01379 <span class="comment">   Function    :    sinfo_new_clean_mean_of_spectra()</span>
+<a name="l01380"></a>01380 <span class="comment">   In         :    1 allocated cube, position of rectangle in x-y plane ,</span>
+<a name="l01381"></a>01381 <span class="comment">                        low and high cut threshold</span>
+<a name="l01382"></a>01382 <span class="comment">   Out         :    result spectrum sinfo_vector</span>
+<a name="l01383"></a>01383 <span class="comment">   Job        :    averaging routine to get a better spectral S/N, sorts</span>
+<a name="l01384"></a>01384 <span class="comment">                        the values of the same z-position, cuts the lowest and</span>
+<a name="l01385"></a>01385 <span class="comment">                        highest values according to given thresholds and then</span>
+<a name="l01386"></a>01386 <span class="comment">                        takes the average within the x-y plane , cannot have</span>
+<a name="l01387"></a>01387 <span class="comment">                        a sum of low and high rejected values greater than 90%</span>
+<a name="l01388"></a>01388 <span class="comment">                        of all values</span>
+<a name="l01389"></a>01389 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l01390"></a>01390 
+<a name="l01391"></a>01391 Vector *
+<a name="l01392"></a>01392 sinfo_new_clean_mean_of_spectra(cpl_imagelist * cube,
+<a name="l01393"></a>01393                              <span class="keywordtype">int</span> llx,
+<a name="l01394"></a>01394                              <span class="keywordtype">int</span> lly,
+<a name="l01395"></a>01395                              <span class="keywordtype">int</span> urx,
+<a name="l01396"></a>01396                              <span class="keywordtype">int</span> ury,
+<a name="l01397"></a>01397                              <span class="keywordtype">double</span> lo_reject,
+<a name="l01398"></a>01398                              <span class="keywordtype">double</span> hi_reject)
+<a name="l01399"></a>01399 {
+<a name="l01400"></a>01400     Vector                           * mean ;
+<a name="l01401"></a>01401     pixelvalue                   *local_rectangle ;
+<a name="l01402"></a>01402     <span class="keywordtype">int</span>                    i, j, k, l, m ;
+<a name="l01403"></a>01403     <span class="keywordtype">int</span>             recsize, lo_n, hi_n, nv ;
+<a name="l01404"></a>01404     <span class="keywordtype">int</span> ilx=0;
+<a name="l01405"></a>01405     <span class="keywordtype">int</span> ily=0;
+<a name="l01406"></a>01406     <span class="keywordtype">int</span> inp=0;
+<a name="l01407"></a>01407     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l01408"></a>01408     cpl_image* i_img=NULL;
+<a name="l01409"></a>01409 
+<a name="l01410"></a>01410     <span class="keywordflow">if</span> ( cube == NULL || cpl_imagelist_get_size(cube) < 1 )
+<a name="l01411"></a>01411     {
+<a name="l01412"></a>01412         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"no cube to take the mean of his spectra"</span>) ;
+<a name="l01413"></a>01413         <span class="keywordflow">return</span> NullVector ;
+<a name="l01414"></a>01414     }
+<a name="l01415"></a>01415     inp=cpl_imagelist_get_size(cube);
+<a name="l01416"></a>01416     i_img=cpl_imagelist_get(cube,0);
+<a name="l01417"></a>01417     ilx=cpl_image_get_size_x(i_img);
+<a name="l01418"></a>01418     ily=cpl_image_get_size_y(i_img);
+<a name="l01419"></a>01419 
+<a name="l01420"></a>01420     <span class="keywordflow">if</span> ((llx<1) || (llx>ilx) ||
+<a name="l01421"></a>01421         (urx<1) || (urx>ilx) ||
+<a name="l01422"></a>01422         (lly<1) || (lly>ily) ||
+<a name="l01423"></a>01423         (ury<1) || (ury>ily) ||
+<a name="l01424"></a>01424         (llx>=urx) || (lly>=ury))
+<a name="l01425"></a>01425     {
+<a name="l01426"></a>01426         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"invalid rectangle coordinates:"</span>) ;
+<a name="l01427"></a>01427         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"lower left is [%d %d] upper right is [%d %d]"</span>,
+<a name="l01428"></a>01428                         llx, lly, urx, ury) ;
+<a name="l01429"></a>01429         <span class="keywordflow">return</span> NullVector ;
+<a name="l01430"></a>01430     }
+<a name="l01431"></a>01431 
+<a name="l01432"></a>01432     <span class="keywordflow">if</span> ((lo_reject + hi_reject) > 0.9)
+<a name="l01433"></a>01433     {
+<a name="l01434"></a>01434         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"illegal rejection thresholds: [%f] and [%f]"</span>,
+<a name="l01435"></a>01435                         lo_reject, hi_reject) ;
+<a name="l01436"></a>01436         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"threshold sum should not be over 0.9"</span>
+<a name="l01437"></a>01437                         <span class="stringliteral">" aborting average"</span>) ;
+<a name="l01438"></a>01438         <span class="keywordflow">return</span> NullVector ;
+<a name="l01439"></a>01439     }
+<a name="l01440"></a>01440 
+<a name="l01441"></a>01441     <span class="comment">/* shift from FITS coordinates to C coordinates */</span>
+<a name="l01442"></a>01442     llx -- ;
+<a name="l01443"></a>01443     lly -- ;
+<a name="l01444"></a>01444     urx -- ;
+<a name="l01445"></a>01445     ury -- ;
+<a name="l01446"></a>01446 
+<a name="l01447"></a>01447     recsize = (urx - llx + 1) * (ury - lly + 1) ;
+<a name="l01448"></a>01448 
+<a name="l01449"></a>01449     lo_n = (int) (recsize * lo_reject + 0.5) ;
+<a name="l01450"></a>01450     hi_n = (int) (recsize * hi_reject + 0.5) ;
+<a name="l01451"></a>01451 
+<a name="l01452"></a>01452     <span class="keywordflow">if</span> (lo_n + hi_n >= recsize)
+<a name="l01453"></a>01453     {
+<a name="l01454"></a>01454         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"everything would be rejected"</span>) ;
+<a name="l01455"></a>01455         <span class="keywordflow">return</span> NullVector;
+<a name="l01456"></a>01456     }
+<a name="l01457"></a>01457 
+<a name="l01458"></a>01458     <span class="comment">/* allocate a new sinfo_vector to store the average spectral values */</span>
+<a name="l01459"></a>01459     <span class="keywordflow">if</span> (NULL == (mean = sinfo_new_vector (inp)) )
+<a name="l01460"></a>01460     {
+<a name="l01461"></a>01461         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"cannot allocate a new sinfo_vector"</span>) ;
+<a name="l01462"></a>01462         <span class="keywordflow">return</span> NullVector ;
+<a name="l01463"></a>01463     }
+<a name="l01464"></a>01464 
+<a name="l01465"></a>01465     <span class="comment">/*------------------------------------------------------------------------</span>
+<a name="l01466"></a>01466 <span class="comment">     *  loop through the cube planes, through the x axis and the y-axis of the</span>
+<a name="l01467"></a>01467 <span class="comment">     *  plane rectangle and store pixel values in a buffer.</span>
+<a name="l01468"></a>01468 <span class="comment">     */</span>
+<a name="l01469"></a>01469     <span class="keywordflow">for</span> ( i = 0 ; i < inp ; i++ )
+<a name="l01470"></a>01470     {
+<a name="l01471"></a>01471       i_img=cpl_imagelist_get(cube,i);
+<a name="l01472"></a>01472       pidata=cpl_image_get_data_float(i_img);
+<a name="l01473"></a>01473       m = 0 ;
+<a name="l01474"></a>01474       local_rectangle=(pixelvalue *)cpl_calloc(recsize, <span class="keyword">sizeof</span> (pixelvalue*));
+<a name="l01475"></a>01475 
+<a name="l01476"></a>01476         <span class="keywordflow">for</span> ( j = lly ; j <= ury ; j++ )
+<a name="l01477"></a>01477         {
+<a name="l01478"></a>01478             <span class="keywordflow">for</span> ( k = llx ; k <= urx ; k++ )
+<a name="l01479"></a>01479             {
+<a name="l01480"></a>01480                 local_rectangle[m] = pidata[k + j * ilx] ;
+<a name="l01481"></a>01481                 m ++ ;
+<a name="l01482"></a>01482             }
+<a name="l01483"></a>01483         }
+<a name="l01484"></a>01484         <span class="comment">/*sorts the pixelvalues in the buffer*/</span>
+<a name="l01485"></a>01485         sinfo_pixel_qsort (local_rectangle, recsize) ;
+<a name="l01486"></a>01486 
+<a name="l01487"></a>01487         nv = 0 ;
+<a name="l01488"></a>01488         <span class="keywordflow">for</span> ( l = lo_n ; l < (recsize - hi_n) ; l++ )
+<a name="l01489"></a>01489         {
+<a name="l01490"></a>01490             mean -> data[i] += local_rectangle[l] ;
+<a name="l01491"></a>01491             nv ++;
+<a name="l01492"></a>01492         }
+<a name="l01493"></a>01493         mean -> data[i] /= nv ;
+<a name="l01494"></a>01494 
+<a name="l01495"></a>01495         cpl_free ( local_rectangle ) ;
+<a name="l01496"></a>01496     }
+<a name="l01497"></a>01497     <span class="keywordflow">return</span> mean ;
+<a name="l01498"></a>01498 }
+<a name="l01499"></a>01499 
+<a name="l01500"></a>01500 
+<a name="l01501"></a>01501 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l01502"></a>01502 <span class="comment">   Function    :sinfo_new_median_cube()</span>
+<a name="l01503"></a>01503 <span class="comment">   In         :1 allocated cube</span>
+<a name="l01504"></a>01504 <span class="comment">   Out         :result image</span>
+<a name="l01505"></a>01505 <span class="comment">   Job        :determines the sinfo_new_median value in every pixel position</span>
+<a name="l01506"></a>01506 <span class="comment">                 by considering all pixels along the third axis.</span>
+<a name="l01507"></a>01507 <span class="comment">                 ZERO pixels in a plane are not considered. If all</span>
+<a name="l01508"></a>01508 <span class="comment">                 pixels at a position are not valid the result will</span>
+<a name="l01509"></a>01509 <span class="comment">                 be 'ZERO'.</span>
+<a name="l01510"></a>01510 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l01511"></a>01511 cpl_image *
+<a name="l01512"></a>01512 sinfo_new_median_cube(cpl_imagelist * cube)
+<a name="l01513"></a>01513 {
+<a name="l01514"></a>01514     cpl_image  *         im ;
+<a name="l01515"></a>01515     pixelvalue *    buffer ;
+<a name="l01516"></a>01516     <span class="keywordtype">int</span>        i, j, k, nz ;
+<a name="l01517"></a>01517     <span class="keywordtype">int</span> ilx=0;
+<a name="l01518"></a>01518     <span class="keywordtype">int</span> ily=0;
+<a name="l01519"></a>01519     <span class="keywordtype">int</span> inp=0;
+<a name="l01520"></a>01520     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l01521"></a>01521     <span class="keywordtype">float</span>* podata=NULL;
+<a name="l01522"></a>01522     cpl_image* i_img=NULL;
+<a name="l01523"></a>01523 
+<a name="l01524"></a>01524     <span class="keywordflow">if</span> ( cube == NULL )
+<a name="l01525"></a>01525     {
+<a name="l01526"></a>01526         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"null cube"</span>) ;
+<a name="l01527"></a>01527         <span class="keywordflow">return</span> NULL ;
+<a name="l01528"></a>01528     }
+<a name="l01529"></a>01529     inp=cpl_imagelist_get_size(cube);
+<a name="l01530"></a>01530     i_img=cpl_imagelist_get(cube,0);
+<a name="l01531"></a>01531     ilx=cpl_image_get_size_x(i_img);
+<a name="l01532"></a>01532     ily=cpl_image_get_size_y(i_img);
+<a name="l01533"></a>01533 
+<a name="l01534"></a>01534     <span class="comment">/* allocate memory */</span>
+<a name="l01535"></a>01535     <span class="keywordflow">if</span> (NULL == (im = cpl_image_new (ilx, ily, CPL_TYPE_FLOAT )) )
+<a name="l01536"></a>01536     {
+<a name="l01537"></a>01537         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"cannot allocate new image"</span>) ;
+<a name="l01538"></a>01538         <span class="keywordflow">return</span> NULL ;
+<a name="l01539"></a>01539     }
+<a name="l01540"></a>01540 
+<a name="l01541"></a>01541     <span class="comment">/*------------------------------------------------------------------------</span>
+<a name="l01542"></a>01542 <span class="comment">     * transfer each sinfo_vector in z direction in a buffer and collect</span>
+<a name="l01543"></a>01543 <span class="comment">       only non-blank data.</span>
+<a name="l01544"></a>01544 <span class="comment">     */</span>
+<a name="l01545"></a>01545 
+<a name="l01546"></a>01546     podata=cpl_image_get_data_float(im);
+<a name="l01547"></a>01547     <span class="keywordflow">for</span> ( i = 0 ; i < (int) ilx*ily ; i++ )
+<a name="l01548"></a>01548     {
+<a name="l01549"></a>01549         buffer = (pixelvalue *) cpl_calloc (inp, <span class="keyword">sizeof</span> (pixelvalue *));
+<a name="l01550"></a>01550         k = 0 ;
+<a name="l01551"></a>01551         <span class="keywordflow">for</span> ( j = 0 ; j < inp ; j ++ )
+<a name="l01552"></a>01552         {
+<a name="l01553"></a>01553           i_img=cpl_imagelist_get(cube,j);
+<a name="l01554"></a>01554       pidata=cpl_image_get_data_float(i_img);
+<a name="l01555"></a>01555             <span class="keywordflow">if</span> ( !isnan(pidata[i]) )
+<a name="l01556"></a>01556             {
+<a name="l01557"></a>01557                 buffer[k] = pidata[i] ;
+<a name="l01558"></a>01558                 k ++ ;
+<a name="l01559"></a>01559             }
+<a name="l01560"></a>01560         }
+<a name="l01561"></a>01561         nz = k ;
+<a name="l01562"></a>01562 
+<a name="l01563"></a>01563         <span class="comment">/* proceed depending on the number of valid pixels */</span>
+<a name="l01564"></a>01564         <span class="keywordflow">if</span> ( nz > 2 )
+<a name="l01565"></a>01565         {
+<a name="l01566"></a>01566             podata[i] = sinfo_new_median ( buffer, nz ) ;
+<a name="l01567"></a>01567         }
+<a name="l01568"></a>01568         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (nz == 2)
+<a name="l01569"></a>01569         {
+<a name="l01570"></a>01570             podata[i] = (buffer[0] + buffer[1]) / 2. ;
+<a name="l01571"></a>01571         }
+<a name="l01572"></a>01572         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (nz == 1)
+<a name="l01573"></a>01573         {
+<a name="l01574"></a>01574             podata[i] = buffer[0] ;
+<a name="l01575"></a>01575         }
+<a name="l01576"></a>01576         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (nz == 0)
+<a name="l01577"></a>01577         {
+<a name="l01578"></a>01578             podata[i] = ZERO ;
+<a name="l01579"></a>01579         }
+<a name="l01580"></a>01580 
+<a name="l01581"></a>01581         cpl_free ( buffer ) ;
+<a name="l01582"></a>01582     }
+<a name="l01583"></a>01583 
+<a name="l01584"></a>01584     <span class="keywordflow">return</span> im ;
+<a name="l01585"></a>01585 }
+<a name="l01586"></a>01586 
+<a name="l01587"></a>01587 
+<a name="l01588"></a>01588 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l01589"></a>01589 <span class="comment">   Function    :    sinfo_new_average_cube_to_image()</span>
+<a name="l01590"></a>01590 <span class="comment">   In         :    1 allocated cube</span>
+<a name="l01591"></a>01591 <span class="comment">   Out         :    result image</span>
+<a name="l01592"></a>01592 <span class="comment">   Job        :    determines the average value in every pixel position</span>
+<a name="l01593"></a>01593 <span class="comment">                        by considering all pixels along the third axis.</span>
+<a name="l01594"></a>01594 <span class="comment">                        ZERO pixels in a plane are not considered. If all</span>
+<a name="l01595"></a>01595 <span class="comment">                        pixels at a position are not valid the result will</span>
+<a name="l01596"></a>01596 <span class="comment">                        be 'ZERO'.</span>
+<a name="l01597"></a>01597 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l01598"></a>01598 cpl_image *
+<a name="l01599"></a>01599 sinfo_new_average_cube_to_image(cpl_imagelist * cube)
+<a name="l01600"></a>01600 {
+<a name="l01601"></a>01601     cpl_image  *      im ;
+<a name="l01602"></a>01602     <span class="keywordtype">int</span>        i, j, nz ;
+<a name="l01603"></a>01603     <span class="keywordtype">int</span> ilx=0;
+<a name="l01604"></a>01604     <span class="keywordtype">int</span> ily=0;
+<a name="l01605"></a>01605     <span class="keywordtype">int</span> inp=0;
+<a name="l01606"></a>01606     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l01607"></a>01607     <span class="keywordtype">float</span>* podata=NULL;
+<a name="l01608"></a>01608     cpl_image* i_img=NULL;
+<a name="l01609"></a>01609 
+<a name="l01610"></a>01610     <span class="keywordflow">if</span> ( cube == NULL )
+<a name="l01611"></a>01611     {
+<a name="l01612"></a>01612         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"null cube"</span>) ;
+<a name="l01613"></a>01613         <span class="keywordflow">return</span> NULL ;
+<a name="l01614"></a>01614     }
+<a name="l01615"></a>01615     inp=cpl_imagelist_get_size(cube);
+<a name="l01616"></a>01616     i_img=cpl_imagelist_get(cube,0);
+<a name="l01617"></a>01617     ilx=cpl_image_get_size_x(i_img);
+<a name="l01618"></a>01618     ily=cpl_image_get_size_y(i_img);
+<a name="l01619"></a>01619 
+<a name="l01620"></a>01620     <span class="comment">/* allocate memory */</span>
+<a name="l01621"></a>01621     <span class="keywordflow">if</span> (NULL == (im = cpl_image_new (ilx, ily,CPL_TYPE_FLOAT )) )
+<a name="l01622"></a>01622     {
+<a name="l01623"></a>01623         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"cannot allocate new image"</span>) ;
+<a name="l01624"></a>01624         <span class="keywordflow">return</span> NULL ;
+<a name="l01625"></a>01625     }
+<a name="l01626"></a>01626 
+<a name="l01627"></a>01627     <span class="comment">/*------------------------------------------------------------------------</span>
+<a name="l01628"></a>01628 <span class="comment">     * transfer each vector in z direction in a buffer and collect</span>
+<a name="l01629"></a>01629 <span class="comment">       only non-blank data.</span>
+<a name="l01630"></a>01630 <span class="comment">     */</span>
+<a name="l01631"></a>01631 
+<a name="l01632"></a>01632     podata=cpl_image_get_data_float(im);
+<a name="l01633"></a>01633     <span class="keywordflow">for</span> ( i = 0 ; i < (int) ilx*ily ; i++ )
+<a name="l01634"></a>01634     {
+<a name="l01635"></a>01635         nz = 0 ;
+<a name="l01636"></a>01636         <span class="keywordflow">for</span> ( j = 0 ; j < inp ; j ++ )
+<a name="l01637"></a>01637         {
+<a name="l01638"></a>01638           i_img=cpl_imagelist_get(cube,j);
+<a name="l01639"></a>01639       pidata=cpl_image_get_data_float(i_img);
+<a name="l01640"></a>01640             <span class="keywordflow">if</span> ( !isnan(pidata[i]) )
+<a name="l01641"></a>01641             {
+<a name="l01642"></a>01642                 nz ++ ;
+<a name="l01643"></a>01643                 podata[i] += pidata[i] ;
+<a name="l01644"></a>01644             }
+<a name="l01645"></a>01645         }
+<a name="l01646"></a>01646 
+<a name="l01647"></a>01647         <span class="comment">/* proceed depending on the number of valid pixels */</span>
+<a name="l01648"></a>01648         <span class="keywordflow">if</span> ( nz >= 1 )
+<a name="l01649"></a>01649         {
+<a name="l01650"></a>01650             podata[i] /= nz ;
+<a name="l01651"></a>01651         }
+<a name="l01652"></a>01652         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (nz == 0)
+<a name="l01653"></a>01653         {
+<a name="l01654"></a>01654             podata[i] = ZERO ;
+<a name="l01655"></a>01655         }
+<a name="l01656"></a>01656     }
+<a name="l01657"></a>01657 
+<a name="l01658"></a>01658     <span class="keywordflow">return</span> im ;
+<a name="l01659"></a>01659 }
+<a name="l01660"></a>01660 
+<a name="l01661"></a>01661 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l01662"></a>01662 <span class="comment">   Function     :       sinfo_new_sum_cube_to_image()</span>
+<a name="l01663"></a>01663 <span class="comment">   In           :       1 allocated cube</span>
+<a name="l01664"></a>01664 <span class="comment">   Out          :       result image</span>
+<a name="l01665"></a>01665 <span class="comment">   Job          :       determines the sum value in every pixel position</span>
+<a name="l01666"></a>01666 <span class="comment">                        by considering all pixels along the third axis.</span>
+<a name="l01667"></a>01667 <span class="comment">                        ZERO pixels in a plane are not considered. If all</span>
+<a name="l01668"></a>01668 <span class="comment">                        pixels at a position are not valid the result will</span>
+<a name="l01669"></a>01669 <span class="comment">                        be 'ZERO'.</span>
+<a name="l01670"></a>01670 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l01671"></a>01671 cpl_image *
+<a name="l01672"></a>01672 sinfo_new_sum_cube_to_image(cpl_imagelist * cube)
+<a name="l01673"></a>01673 {
+<a name="l01674"></a>01674     cpl_image  *      im ;
+<a name="l01675"></a>01675     <span class="keywordtype">int</span>        i, j, nz ;
+<a name="l01676"></a>01676     <span class="keywordtype">int</span> ilx=0;
+<a name="l01677"></a>01677     <span class="keywordtype">int</span> ily=0;
+<a name="l01678"></a>01678     <span class="keywordtype">int</span> inp=0;
+<a name="l01679"></a>01679     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l01680"></a>01680     <span class="keywordtype">float</span>* podata=NULL;
+<a name="l01681"></a>01681     cpl_image* i_img=NULL;
+<a name="l01682"></a>01682 
+<a name="l01683"></a>01683     <span class="keywordflow">if</span> ( cube == NULL )
+<a name="l01684"></a>01684     {
+<a name="l01685"></a>01685         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"null cube"</span>) ;
+<a name="l01686"></a>01686         <span class="keywordflow">return</span> NULL ;
+<a name="l01687"></a>01687     }
+<a name="l01688"></a>01688     inp=cpl_imagelist_get_size(cube);
+<a name="l01689"></a>01689     i_img=cpl_imagelist_get(cube,0);
+<a name="l01690"></a>01690     ilx=cpl_image_get_size_x(i_img);
+<a name="l01691"></a>01691     ily=cpl_image_get_size_y(i_img);
+<a name="l01692"></a>01692 
+<a name="l01693"></a>01693     <span class="comment">/* allocate memory */</span>
+<a name="l01694"></a>01694     <span class="keywordflow">if</span> (NULL == (im = cpl_image_new (ilx, ily, CPL_TYPE_FLOAT )) )
+<a name="l01695"></a>01695     {
+<a name="l01696"></a>01696         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"cannot allocate new image"</span>) ;
+<a name="l01697"></a>01697         <span class="keywordflow">return</span> NULL ;
+<a name="l01698"></a>01698     }
+<a name="l01699"></a>01699 
+<a name="l01700"></a>01700     <span class="comment">/*-------------------------------------------------------------------------</span>
+<a name="l01701"></a>01701 <span class="comment">     * transfer each vector in z direction in a buffer and collect only</span>
+<a name="l01702"></a>01702 <span class="comment">       non-blank data.</span>
+<a name="l01703"></a>01703 <span class="comment">     */</span>
+<a name="l01704"></a>01704 
+<a name="l01705"></a>01705     podata=cpl_image_get_data_float(im);
+<a name="l01706"></a>01706     <span class="keywordflow">for</span> ( i = 0 ; i < (int) ilx*ily ; i++ )
+<a name="l01707"></a>01707     {
+<a name="l01708"></a>01708         nz = 0 ;
+<a name="l01709"></a>01709         <span class="keywordflow">for</span> ( j = 0 ; j < inp ; j ++ )
+<a name="l01710"></a>01710         {
+<a name="l01711"></a>01711           i_img=cpl_imagelist_get(cube,j);
+<a name="l01712"></a>01712       pidata=cpl_image_get_data_float(i_img);
+<a name="l01713"></a>01713             <span class="keywordflow">if</span> ( !isnan(pidata[i]) )
+<a name="l01714"></a>01714             {
+<a name="l01715"></a>01715                 nz++ ;
+<a name="l01716"></a>01716                 podata[i] += pidata[i] ;
+<a name="l01717"></a>01717             }
+<a name="l01718"></a>01718         }
+<a name="l01719"></a>01719 
+<a name="l01720"></a>01720         <span class="comment">/* proceed depending on the number of valid pixels */</span>
+<a name="l01721"></a>01721         <span class="keywordflow">if</span> (nz == 0)
+<a name="l01722"></a>01722         {
+<a name="l01723"></a>01723             podata[i] = ZERO ;
+<a name="l01724"></a>01724         }
+<a name="l01725"></a>01725     }
+<a name="l01726"></a>01726 
+<a name="l01727"></a>01727     <span class="keywordflow">return</span> im ;
+<a name="l01728"></a>01728 }
+<a name="l01729"></a>01729 
+<a name="l01730"></a>01730 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l01731"></a>01731 <span class="comment">   Function    sinfo_new_average_cube_to_image_between_waves()</span>
+<a name="l01732"></a>01732 <span class="comment">   In         cube: data cube to collapse</span>
+<a name="l01733"></a>01733 <span class="comment">                dispersion: dispersion per pixel in microns/pixel</span>
+<a name="l01734"></a>01734 <span class="comment">                (derived from fits header information)</span>
+<a name="l01735"></a>01735 <span class="comment">                centralWave: central wavelength in the cube in microns</span>
+<a name="l01736"></a>01736 <span class="comment">                                       (derived from fits header information)</span>
+<a name="l01737"></a>01737 <span class="comment">                initialLambda, finalLambda: wavelength values in microns</span>
+<a name="l01738"></a>01738 <span class="comment">                                            within which the cube is averaged</span>
+<a name="l01739"></a>01739 <span class="comment">   Out         :resulting averaged image</span>
+<a name="l01740"></a>01740 <span class="comment">   Job        :determines the average value in every pixel position</span>
+<a name="l01741"></a>01741 <span class="comment">                 by considering only the pixels along the third axis</span>
+<a name="l01742"></a>01742 <span class="comment">                 which lie between the given wavelength values.</span>
+<a name="l01743"></a>01743 <span class="comment">                 These values are first recalculated to plane indices</span>
+<a name="l01744"></a>01744 <span class="comment">                 by using the given dispersion and minimum wavelength in</span>
+<a name="l01745"></a>01745 <span class="comment">                 the cube.</span>
+<a name="l01746"></a>01746 <span class="comment">                 ZERO pixels in a plane are not considered. If all</span>
+<a name="l01747"></a>01747 <span class="comment">                 pixels at a position are not valid the result will</span>
+<a name="l01748"></a>01748 <span class="comment">                 be 'ZERO'.</span>
+<a name="l01749"></a>01749 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l01750"></a>01750 cpl_image *
+<a name="l01751"></a>01751 sinfo_new_average_cube_to_image_between_waves (cpl_imagelist * cube,
+<a name="l01752"></a>01752                                            <span class="keywordtype">float</span>     dispersion,
+<a name="l01753"></a>01753                                            <span class="keywordtype">float</span>     centralWave,
+<a name="l01754"></a>01754                                            <span class="keywordtype">float</span>     initialLambda,
+<a name="l01755"></a>01755                                            <span class="keywordtype">float</span>     finalLambda)
+<a name="l01756"></a>01756 {
+<a name="l01757"></a>01757     cpl_image  *      im ;
+<a name="l01758"></a>01758     <span class="keywordtype">int</span>        firstPlane ;
+<a name="l01759"></a>01759     <span class="keywordtype">int</span>        lastPlane ;
+<a name="l01760"></a>01760     <span class="keywordtype">int</span>        i, j, nz ;
+<a name="l01761"></a>01761     <span class="keywordtype">float</span>      minWave ;
+<a name="l01762"></a>01762     <span class="keywordtype">int</span> ilx=0;
+<a name="l01763"></a>01763     <span class="keywordtype">int</span> ily=0;
+<a name="l01764"></a>01764     <span class="keywordtype">int</span> inp=0;
+<a name="l01765"></a>01765     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l01766"></a>01766     <span class="keywordtype">float</span>* podata=NULL;
+<a name="l01767"></a>01767     cpl_image* i_img=NULL;
+<a name="l01768"></a>01768 
+<a name="l01769"></a>01769     <span class="keywordflow">if</span> ( cube == NULL )
+<a name="l01770"></a>01770     {
+<a name="l01771"></a>01771         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"null cube"</span>) ;
+<a name="l01772"></a>01772         <span class="keywordflow">return</span> NULL ;
+<a name="l01773"></a>01773     }
+<a name="l01774"></a>01774     i_img=cpl_imagelist_get(cube,0);
+<a name="l01775"></a>01775     ilx=cpl_image_get_size_x(i_img);
+<a name="l01776"></a>01776     ily=cpl_image_get_size_y(i_img);
+<a name="l01777"></a>01777 
+<a name="l01778"></a>01778     inp=cpl_imagelist_get_size(cube);
+<a name="l01779"></a>01779 
+<a name="l01780"></a>01780     minWave = centralWave - (float) (inp / 2)*dispersion ;
+<a name="l01781"></a>01781 
+<a name="l01782"></a>01782     <span class="keywordflow">if</span> ( dispersion <= 0. || minWave <= 0. )
+<a name="l01783"></a>01783     {
+<a name="l01784"></a>01784         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"wrong dispersion or minimum wavelength given"</span>) ;
+<a name="l01785"></a>01785         <span class="keywordflow">return</span> NULL ;
+<a name="l01786"></a>01786     }
+<a name="l01787"></a>01787 
+<a name="l01788"></a>01788     <span class="keywordflow">if</span> ( initialLambda < minWave ||
+<a name="l01789"></a>01789         (initialLambda >= minWave + dispersion * inp) )
+<a name="l01790"></a>01790     {
+<a name="l01791"></a>01791         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"wrong initial wavelength given"</span>) ;
+<a name="l01792"></a>01792         <span class="keywordflow">return</span> NULL ;
+<a name="l01793"></a>01793     }
+<a name="l01794"></a>01794 
+<a name="l01795"></a>01795     <span class="keywordflow">if</span> ( finalLambda <= minWave ||
+<a name="l01796"></a>01796         (finalLambda > minWave + dispersion * inp) )
+<a name="l01797"></a>01797     {
+<a name="l01798"></a>01798         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"wrong final wavelength given"</span>) ;
+<a name="l01799"></a>01799         <span class="keywordflow">return</span> NULL ;
+<a name="l01800"></a>01800     }
+<a name="l01801"></a>01801 
+<a name="l01802"></a>01802     <span class="comment">/* allocate memory */</span>
+<a name="l01803"></a>01803     <span class="keywordflow">if</span> (NULL == (im = cpl_image_new (ilx, ily, CPL_TYPE_FLOAT )) )
+<a name="l01804"></a>01804     {
+<a name="l01805"></a>01805         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"cannot allocate new image"</span>) ;
+<a name="l01806"></a>01806         <span class="keywordflow">return</span> NULL ;
+<a name="l01807"></a>01807     }
+<a name="l01808"></a>01808 
+<a name="l01809"></a>01809     <span class="comment">/* transfer the wavelength range to image plane indices */</span>
+<a name="l01810"></a>01810     firstPlane = sinfo_new_nint ((<span class="keywordtype">double</span>) ((initialLambda - minWave) /
+<a name="l01811"></a>01811                                           dispersion)) ;
+<a name="l01812"></a>01812     lastPlane  = sinfo_new_nint ((<span class="keywordtype">double</span>) ((finalLambda - minWave) /
+<a name="l01813"></a>01813                                           dispersion)) ;
+<a name="l01814"></a>01814 
+<a name="l01815"></a>01815     <span class="keywordflow">if</span> ( firstPlane < 0 || firstPlane >= inp ||
+<a name="l01816"></a>01816          lastPlane  < 0 || lastPlane  >  inp )
+<a name="l01817"></a>01817     {
+<a name="l01818"></a>01818         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"wrong values given!"</span>) ;
+<a name="l01819"></a>01819         <span class="keywordflow">return</span> NULL ;
+<a name="l01820"></a>01820     }
+<a name="l01821"></a>01821 
+<a name="l01822"></a>01822     <span class="comment">/*------------------------------------------------------------------------</span>
+<a name="l01823"></a>01823 <span class="comment">     * transfer each vector in z direction in a buffer and collect only</span>
+<a name="l01824"></a>01824 <span class="comment">       non-blank data.</span>
+<a name="l01825"></a>01825 <span class="comment">     */</span>
+<a name="l01826"></a>01826 
+<a name="l01827"></a>01827 
+<a name="l01828"></a>01828 
+<a name="l01829"></a>01829     podata=cpl_image_get_data_float(im);
+<a name="l01830"></a>01830     <span class="keywordflow">for</span> ( i = 0 ; i < (int) ilx*ily ; i++ )
+<a name="l01831"></a>01831     {
+<a name="l01832"></a>01832         nz = 0 ;
+<a name="l01833"></a>01833 
+<a name="l01834"></a>01834         <span class="keywordflow">for</span> ( j = firstPlane ; j <= lastPlane ; j ++ )
+<a name="l01835"></a>01835         {
+<a name="l01836"></a>01836           i_img=cpl_imagelist_get(cube,j);
+<a name="l01837"></a>01837       pidata=cpl_image_get_data_float(i_img);
+<a name="l01838"></a>01838             <span class="keywordflow">if</span> ( !isnan(pidata[i]) )
+<a name="l01839"></a>01839             {
+<a name="l01840"></a>01840                 nz ++ ;
+<a name="l01841"></a>01841                 podata[i] += pidata[i] ;
+<a name="l01842"></a>01842             }
+<a name="l01843"></a>01843         }
+<a name="l01844"></a>01844 
+<a name="l01845"></a>01845         <span class="comment">/* proceed depending on the number of valid pixels */</span>
+<a name="l01846"></a>01846         <span class="keywordflow">if</span> ( nz >= 1 )
+<a name="l01847"></a>01847         {
+<a name="l01848"></a>01848             podata[i] /= nz ;
+<a name="l01849"></a>01849         }
+<a name="l01850"></a>01850         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (nz == 0)
+<a name="l01851"></a>01851         {
+<a name="l01852"></a>01852             podata[i] = ZERO ;
+<a name="l01853"></a>01853         }
+<a name="l01854"></a>01854     }
+<a name="l01855"></a>01855 
+<a name="l01856"></a>01856     <span class="keywordflow">return</span> im ;
+<a name="l01857"></a>01857 }
+<a name="l01858"></a>01858 
+<a name="l01859"></a>01859 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l01860"></a>01860 <span class="comment">   Function    :    sinfo_new_extract_image_from_cube()</span>
+<a name="l01861"></a>01861 <span class="comment">   In         :    1 allocated cube</span>
+<a name="l01862"></a>01862 <span class="comment">                        index of cube plane</span>
+<a name="l01863"></a>01863 <span class="comment">   Out         :    extracted image</span>
+<a name="l01864"></a>01864 <span class="comment">   Job        :    returns the wanted image plane of the cube</span>
+<a name="l01865"></a>01865 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l01866"></a>01866 cpl_image *
+<a name="l01867"></a>01867 sinfo_new_extract_image_from_cube(cpl_imagelist * cube, <span class="keywordtype">int</span> plane_index)
+<a name="l01868"></a>01868 {
+<a name="l01869"></a>01869     <span class="keywordflow">if</span> ( cube == NULL )
+<a name="l01870"></a>01870     {
+<a name="l01871"></a>01871         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"null cube"</span>) ;
+<a name="l01872"></a>01872         <span class="keywordflow">return</span> NULL ;
+<a name="l01873"></a>01873     }
+<a name="l01874"></a>01874 
+<a name="l01875"></a>01875     <span class="keywordflow">if</span> ( plane_index < 0 || plane_index >= cpl_imagelist_get_size(cube) )
+<a name="l01876"></a>01876     {
+<a name="l01877"></a>01877         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"wrong plane index for image to be extracted"</span>) ;
+<a name="l01878"></a>01878         <span class="keywordflow">return</span> NULL ;
+<a name="l01879"></a>01879     }
+<a name="l01880"></a>01880 
+<a name="l01881"></a>01881     <span class="keywordflow">return</span> cpl_imagelist_get(cube,plane_index) ;
+<a name="l01882"></a>01882 }
+<a name="l01883"></a>01883 
+<a name="l01884"></a>01884 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l01885"></a>01885 <span class="comment">   Function    :sinfo_new_extract_spectrum_from_cube()</span>
+<a name="l01886"></a>01886 <span class="comment">   In         :cube: 1 allocated cube</span>
+<a name="l01887"></a>01887 <span class="comment">                 x_pos, y_pos: x, y pixel position of the</span>
+<a name="l01888"></a>01888 <span class="comment">                               spectrum counted from 0</span>
+<a name="l01889"></a>01889 <span class="comment">   Out         :extracted spectral sinfo_vector object</span>
+<a name="l01890"></a>01890 <span class="comment">   Job        :returns the wanted single spectrum of the cube</span>
+<a name="l01891"></a>01891 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l01892"></a>01892 Vector *
+<a name="l01893"></a>01893 sinfo_new_extract_spectrum_from_cube(cpl_imagelist * cube,
+<a name="l01894"></a>01894                                      <span class="keywordtype">int</span> x_pos, <span class="keywordtype">int</span> y_pos)
+<a name="l01895"></a>01895 {
+<a name="l01896"></a>01896     Vector * returnedSpectrum ;
+<a name="l01897"></a>01897     <span class="keywordtype">int</span> i ;
+<a name="l01898"></a>01898     <span class="keywordtype">int</span> ilx=0;
+<a name="l01899"></a>01899     <span class="keywordtype">int</span> ily=0;
+<a name="l01900"></a>01900     <span class="keywordtype">int</span> inp=0;
+<a name="l01901"></a>01901     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l01902"></a>01902     cpl_image* i_img=NULL;
+<a name="l01903"></a>01903 
+<a name="l01904"></a>01904     <span class="keywordflow">if</span> ( cube == NULL )
+<a name="l01905"></a>01905     {
+<a name="l01906"></a>01906         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"no cube given!"</span>) ;
+<a name="l01907"></a>01907         <span class="keywordflow">return</span> NullVector ;
+<a name="l01908"></a>01908     }
+<a name="l01909"></a>01909     i_img=cpl_imagelist_get(cube,0);
+<a name="l01910"></a>01910     ilx=cpl_image_get_size_x(i_img);
+<a name="l01911"></a>01911     ily=cpl_image_get_size_y(i_img);
+<a name="l01912"></a>01912     inp=cpl_imagelist_get_size(cube);
+<a name="l01913"></a>01913 
+<a name="l01914"></a>01914     <span class="keywordflow">if</span> ( x_pos < 0 || x_pos >= ilx )
+<a name="l01915"></a>01915     {
+<a name="l01916"></a>01916         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"wrong x-positon of spectrum given!"</span>) ;
+<a name="l01917"></a>01917         <span class="keywordflow">return</span> NullVector ;
+<a name="l01918"></a>01918     }
+<a name="l01919"></a>01919 
+<a name="l01920"></a>01920     <span class="keywordflow">if</span> ( y_pos < 0 || y_pos >= ily )
+<a name="l01921"></a>01921     {
+<a name="l01922"></a>01922         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"wrong y-positon of spectrum given!"</span>) ;
+<a name="l01923"></a>01923         <span class="keywordflow">return</span> NullVector ;
+<a name="l01924"></a>01924     }
+<a name="l01925"></a>01925 
+<a name="l01926"></a>01926     <span class="comment">/* allocate memory */</span>
+<a name="l01927"></a>01927     <span class="keywordflow">if</span> ( NULL == (returnedSpectrum = sinfo_new_vector ( inp )) )
+<a name="l01928"></a>01928     {
+<a name="l01929"></a>01929         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"cannot allocate new spectrum!"</span>) ;
+<a name="l01930"></a>01930         <span class="keywordflow">return</span> NullVector ;
+<a name="l01931"></a>01931     }
+<a name="l01932"></a>01932 
+<a name="l01933"></a>01933     <span class="keywordflow">for</span> ( i = 0 ; i < inp ; i++ )
+<a name="l01934"></a>01934     {
+<a name="l01935"></a>01935       i_img=cpl_imagelist_get(cube,i);
+<a name="l01936"></a>01936       pidata=cpl_image_get_data_float(i_img);
+<a name="l01937"></a>01937       returnedSpectrum -> data[i] = pidata[x_pos + ilx*y_pos] ;
+<a name="l01938"></a>01938     }
+<a name="l01939"></a>01939 
+<a name="l01940"></a>01940     <span class="keywordflow">return</span> returnedSpectrum ;
+<a name="l01941"></a>01941 }
+<a name="l01942"></a>01942 
+<a name="l01943"></a>01943 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l01944"></a>01944 <span class="comment">   Function     :       sinfo_new_combine_jittered_cubes()</span>
+<a name="l01945"></a>01945 <span class="comment">   In           :       cubes: list of jittered cubes to mosaic</span>
+<a name="l01946"></a>01946 <span class="comment">                        mergedCube: resulting merged cube containing the</span>
+<a name="l01947"></a>01947 <span class="comment">                                      jittered cubes</span>
+<a name="l01948"></a>01948 <span class="comment">                        n_cubes: number of cubes in the list to merge</span>
+<a name="l01949"></a>01949 <span class="comment">                        cumoffsetx,y: array of relative x, y pixel offsets</span>
+<a name="l01950"></a>01950 <span class="comment">                                      with respect to the first frame in the</span>
+<a name="l01951"></a>01951 <span class="comment">                                      same sequence as the cube list.</span>
+<a name="l01952"></a>01952 <span class="comment">                        exptimes: exposure times array giving the time</span>
+<a name="l01953"></a>01953 <span class="comment">                                  in the same sequence as the cube list</span>
+<a name="l01954"></a>01954 <span class="comment">                        kernel_type: the name of the interpolation kernel</span>
+<a name="l01955"></a>01955 <span class="comment">                                     that you want to generate using the</span>
+<a name="l01956"></a>01956 <span class="comment">                                     eclipse routine</span>
+<a name="l01957"></a>01957 <span class="comment">                                     sinfo_generate_interpolation_kernel()</span>
+<a name="l01958"></a>01958 <span class="comment">                                     Supported kernels are:</span>
+<a name="l01959"></a>01959 <span class="comment">                                     NULL:      default kernel, currently tanh</span>
+<a name="l01960"></a>01960 <span class="comment">                                     "default": dito</span>
+<a name="l01961"></a>01961 <span class="comment">                                     "tanh":    Hyperbolic tangent</span>
+<a name="l01962"></a>01962 <span class="comment">                                     "sinc2":   Square sinc</span>
+<a name="l01963"></a>01963 <span class="comment">                                     "lanczos": Lanczos2 kernel</span>
+<a name="l01964"></a>01964 <span class="comment">                                     "hamming": Hamming kernel</span>
+<a name="l01965"></a>01965 <span class="comment">                                     "hann":    Hann kernel</span>
+<a name="l01966"></a>01966 <span class="comment">   Out          :       mask: cube of the same size as combinedCube</span>
+<a name="l01967"></a>01967 <span class="comment">                              containing 0 for blank (ZERO pixels) and</span>
+<a name="l01968"></a>01968 <span class="comment">                              the summed integration times for</span>
+<a name="l01969"></a>01969 <span class="comment">                              overlapping regions</span>
+<a name="l01970"></a>01970 <span class="comment">                        mergedCube: final data cube containing the</span>
+<a name="l01971"></a>01971 <span class="comment">                                    jittered cubes</span>
+<a name="l01972"></a>01972 <span class="comment">   Job          :       merges jittered data cubes to one bigger cube</span>
+<a name="l01973"></a>01973 <span class="comment">                        by averaging the overlap regions weighted by</span>
+<a name="l01974"></a>01974 <span class="comment">                        the integration times. The x, y size of the final data</span>
+<a name="l01975"></a>01975 <span class="comment">                        cube is user given, and should be between 32 and 64</span>
+<a name="l01976"></a>01976 <span class="comment">                        pixels, while the relative pixel-offset (sub-pixel</span>
+<a name="l01977"></a>01977 <span class="comment">                        accuracy) of the single cubes with respect to the</span>
+<a name="l01978"></a>01978 <span class="comment">                        first cube in the list is read from the</span>
+<a name="l01979"></a>01979 <span class="comment">                        SEQ CUMOFFSETX,Y</span>
+<a name="l01980"></a>01980 <span class="comment">                        fits header keyword.</span>
+<a name="l01981"></a>01981 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l01982"></a>01982 cpl_imagelist *
+<a name="l01983"></a>01983 sinfo_new_combine_jittered_cubes ( cpl_imagelist ** cubes,
+<a name="l01984"></a>01984                                  cpl_imagelist  * mergedCube,
+<a name="l01985"></a>01985                                  <span class="keywordtype">int</span>        n_cubes,
+<a name="l01986"></a>01986                                  <span class="keywordtype">float</span>    * cumoffsetx,
+<a name="l01987"></a>01987                                  <span class="keywordtype">float</span>    * cumoffsety,
+<a name="l01988"></a>01988                                  <span class="keywordtype">float</span>    * exptimes,
+<a name="l01989"></a>01989                                  <span class="keywordtype">char</span>     * kernel_type )
+<a name="l01990"></a>01990 {
+<a name="l01991"></a>01991 
+<a name="l01992"></a>01992     <span class="keywordtype">int</span> i=0 ;
+<a name="l01993"></a>01993     <span class="keywordtype">int</span> x=0;
+<a name="l01994"></a>01994     <span class="keywordtype">int</span> y=0;
+<a name="l01995"></a>01995     <span class="keywordtype">int</span> z=0;
+<a name="l01996"></a>01996     <span class="keywordtype">int</span> llx0=0;
+<a name="l01997"></a>01997     <span class="keywordtype">int</span> lly0=0;
+<a name="l01998"></a>01998     <span class="keywordtype">int</span> posx=0;
+<a name="l01999"></a>01999     <span class="keywordtype">int</span> posy=0;
+<a name="l02000"></a>02000     <span class="keywordtype">float</span> weight=0;
+<a name="l02001"></a>02001     cpl_imagelist * mask=NULL;
+<a name="l02002"></a>02002     <span class="keywordtype">double</span> * kernel=NULL;
+<a name="l02003"></a>02003     <span class="comment">/*cpl_image * shiftedImage ;*/</span>
+<a name="l02004"></a>02004 
+<a name="l02005"></a>02005     <span class="keywordtype">int</span>* llx=NULL ;
+<a name="l02006"></a>02006     <span class="keywordtype">int</span>* lly=NULL ;
+<a name="l02007"></a>02007 
+<a name="l02008"></a>02008     <span class="keywordtype">float</span>* sub_offsetx=NULL ;
+<a name="l02009"></a>02009     <span class="keywordtype">float</span>* sub_offsety=NULL ;
+<a name="l02010"></a>02010 
+<a name="l02011"></a>02011     cpl_imagelist ** tmpcubes=NULL ;
+<a name="l02012"></a>02012     pixelvalue * tmpspace=NULL;
+<a name="l02013"></a>02013 
+<a name="l02014"></a>02014 
+<a name="l02015"></a>02015   <span class="keywordtype">int</span> ilx=0;
+<a name="l02016"></a>02016   <span class="keywordtype">int</span> ily=0;
+<a name="l02017"></a>02017   <span class="keywordtype">int</span> olx=0;
+<a name="l02018"></a>02018   <span class="keywordtype">int</span> oly=0;
+<a name="l02019"></a>02019   <span class="keywordtype">int</span> mlx=0;
+<a name="l02020"></a>02020   <span class="keywordtype">int</span> onp=0;
+<a name="l02021"></a>02021   <span class="keywordtype">int</span> inp=0;
+<a name="l02022"></a>02022 
+<a name="l02023"></a>02023 
+<a name="l02024"></a>02024 
+<a name="l02025"></a>02025   <span class="keywordtype">float</span>* podata=NULL;
+<a name="l02026"></a>02026   <span class="keywordtype">float</span>* pmdata=NULL;
+<a name="l02027"></a>02027   <span class="keywordtype">float</span>* ptdata=NULL;
+<a name="l02028"></a>02028 
+<a name="l02029"></a>02029   cpl_image* i_img=NULL;
+<a name="l02030"></a>02030   cpl_image* o_img=NULL;
+<a name="l02031"></a>02031   cpl_image* m_img=NULL;
+<a name="l02032"></a>02032   cpl_image* t_img=NULL;
+<a name="l02033"></a>02033 
+<a name="l02034"></a>02034 
+<a name="l02035"></a>02035     <span class="keywordflow">if</span> ( cubes == NULL )
+<a name="l02036"></a>02036     {
+<a name="l02037"></a>02037         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"no cube list given!"</span>) ;
+<a name="l02038"></a>02038         <span class="keywordflow">return</span> NULL ;
+<a name="l02039"></a>02039     }
+<a name="l02040"></a>02040     <span class="keywordflow">if</span> ( n_cubes <= 0 )
+<a name="l02041"></a>02041     {
+<a name="l02042"></a>02042         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"wrong number of data cubes in list!"</span>) ;
+<a name="l02043"></a>02043         <span class="keywordflow">return</span> NULL ;
+<a name="l02044"></a>02044     }
+<a name="l02045"></a>02045     <span class="keywordflow">if</span> ( cumoffsetx == NULL || cumoffsety == NULL )
+<a name="l02046"></a>02046     {
+<a name="l02047"></a>02047         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"no cumoffsetx/y given!"</span>) ;
+<a name="l02048"></a>02048         <span class="keywordflow">return</span> NULL ;
+<a name="l02049"></a>02049     }
+<a name="l02050"></a>02050     <span class="keywordflow">if</span> ( exptimes == NULL )
+<a name="l02051"></a>02051     {
+<a name="l02052"></a>02052         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"no exposure time array given!"</span>) ;
+<a name="l02053"></a>02053         <span class="keywordflow">return</span> NULL ;
+<a name="l02054"></a>02054     }
+<a name="l02055"></a>02055 
+<a name="l02056"></a>02056     o_img=cpl_imagelist_get(mergedCube,0);
+<a name="l02057"></a>02057     olx=cpl_image_get_size_x(o_img);
+<a name="l02058"></a>02058     oly=cpl_image_get_size_y(o_img);
+<a name="l02059"></a>02059     onp=cpl_imagelist_get_size(mergedCube);
+<a name="l02060"></a>02060     <span class="keywordflow">if</span> ( NULL == (mask = cpl_imagelist_new()) )
+<a name="l02061"></a>02061     {
+<a name="l02062"></a>02062         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"could not allocate cube!"</span>) ;
+<a name="l02063"></a>02063         <span class="keywordflow">return</span> NULL ;
+<a name="l02064"></a>02064     }
+<a name="l02065"></a>02065     <span class="keywordflow">for</span>(i=0;i<onp;i++){
+<a name="l02066"></a>02066       o_img=cpl_image_new(olx,oly,CPL_TYPE_FLOAT);
+<a name="l02067"></a>02067       cpl_imagelist_set(mergedCube,o_img,i);
+<a name="l02068"></a>02068     }
+<a name="l02069"></a>02069 
+<a name="l02070"></a>02070     i_img=cpl_imagelist_get(cubes[0],0);
+<a name="l02071"></a>02071     ilx=cpl_image_get_size_x(i_img);
+<a name="l02072"></a>02072     ily=cpl_image_get_size_y(i_img);
+<a name="l02073"></a>02073 
+<a name="l02074"></a>02074     inp=cpl_imagelist_get_size(cubes[0]);
+<a name="l02075"></a>02075 
+<a name="l02076"></a>02076     <span class="comment">/*--------------------------------------------------------------------</span>
+<a name="l02077"></a>02077 <span class="comment">     * center the cubes within the allocated big cube</span>
+<a name="l02078"></a>02078 <span class="comment">     * that means define the (0,0) positions of the cubes in the image planes</span>
+<a name="l02079"></a>02079 <span class="comment">     * to sub-pixel accuracy by using cumoffsetx,y and the reference cube</span>
+<a name="l02080"></a>02080 <span class="comment">     */</span>
+<a name="l02081"></a>02081     <span class="comment">/* position of first reference frame, centered in big cube */</span>
+<a name="l02082"></a>02082     llx0 = olx/2 - ilx/2 ;
+<a name="l02083"></a>02083     lly0 = oly/2 - ily/2 ;
+<a name="l02084"></a>02084 
+<a name="l02085"></a>02085     <span class="comment">/*--------------------------------------------------------------------</span>
+<a name="l02086"></a>02086 <span class="comment">     * go through the frame list and determine the lower left edge position</span>
+<a name="l02087"></a>02087 <span class="comment">     * of the shifted cubes. Additionnally, the sub-pixel offsets are</span>
+<a name="l02088"></a>02088 <span class="comment">     * determined.</span>
+<a name="l02089"></a>02089 <span class="comment">     */</span>
+<a name="l02090"></a>02090 
+<a name="l02091"></a>02091     llx=cpl_calloc(n_cubes,<span class="keyword">sizeof</span>(<span class="keywordtype">int</span>)); ;
+<a name="l02092"></a>02092     lly=cpl_calloc(n_cubes,<span class="keyword">sizeof</span>(<span class="keywordtype">int</span>)) ;
+<a name="l02093"></a>02093 
+<a name="l02094"></a>02094     sub_offsetx=cpl_calloc(n_cubes,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l02095"></a>02095     sub_offsety=cpl_calloc(n_cubes,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l02096"></a>02096 
+<a name="l02097"></a>02097     <span class="keywordflow">for</span> ( i = 0 ; i < n_cubes ; i++ )
+<a name="l02098"></a>02098     {
+<a name="l02099"></a>02099         llx[i] = llx0 - sinfo_new_nint(cumoffsetx[i]) ;
+<a name="l02100"></a>02100         sub_offsetx[i] = (float)sinfo_new_nint(cumoffsetx[i]) - cumoffsetx[i] ;
+<a name="l02101"></a>02101         lly[i] = lly0 - sinfo_new_nint(cumoffsety[i]) ;
+<a name="l02102"></a>02102         sub_offsety[i] = (float)sinfo_new_nint(cumoffsety[i]) - cumoffsety[i] ;
+<a name="l02103"></a>02103     }
+<a name="l02104"></a>02104 
+<a name="l02105"></a>02105 
+<a name="l02106"></a>02106     <span class="comment">/* -------------------------------------------------------------</span>
+<a name="l02107"></a>02107 <span class="comment">     * shift the cubes according to the computed sub-pixel offsets</span>
+<a name="l02108"></a>02108 <span class="comment">     * that means shift the single image planes of each cube</span>
+<a name="l02109"></a>02109 <span class="comment">     * first determine an interpolation kernel</span>
+<a name="l02110"></a>02110 <span class="comment">     */</span>
+<a name="l02111"></a>02111     <span class="keywordflow">if</span> ( NULL == (kernel = sinfo_generate_interpolation_kernel(kernel_type)))
+<a name="l02112"></a>02112     {
+<a name="l02113"></a>02113         <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a> (<span class="stringliteral">"could not generate desired interpolation kernel"</span>
+<a name="l02114"></a>02114                            <span class="stringliteral">" or no kernel_typ was given, the default kernel"</span>
+<a name="l02115"></a>02115                            <span class="stringliteral">" is used now!"</span>) ;
+<a name="l02116"></a>02116     }
+<a name="l02117"></a>02117     <span class="comment">/* go through the frame list */</span>
+<a name="l02118"></a>02118 
+<a name="l02119"></a>02119 
+<a name="l02120"></a>02120     tmpcubes=(cpl_imagelist**)cpl_calloc(n_cubes,<span class="keyword">sizeof</span>(cpl_imagelist*)) ;
+<a name="l02121"></a>02121 
+<a name="l02122"></a>02122     <span class="keywordflow">for</span> ( i = 0 ; i < n_cubes ; i++ )
+<a name="l02123"></a>02123     {
+<a name="l02124"></a>02124         tmpspace = cpl_calloc(ilx, ily*<span class="keyword">sizeof</span>(pixelvalue)) ;
+<a name="l02125"></a>02125         tmpcubes[i] = cpl_imagelist_new();
+<a name="l02126"></a>02126 
+<a name="l02127"></a>02127         <span class="keywordflow">for</span> ( z = 0 ; z < inp ; z++ )
+<a name="l02128"></a>02128         {
+<a name="l02129"></a>02129 
+<a name="l02130"></a>02130 
+<a name="l02131"></a>02131             t_img=sinfo_new_shift_image(cpl_imagelist_get(cubes[i],z),
+<a name="l02132"></a>02132                                   sub_offsetx[i], sub_offsety[i], kernel);
+<a name="l02133"></a>02133 
+<a name="l02134"></a>02134         <span class="keywordflow">if</span> (t_img==NULL)
+<a name="l02135"></a>02135             {
+<a name="l02136"></a>02136                 <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"could not shift image plane no %d"</span>
+<a name="l02137"></a>02137                                  <span class="stringliteral">" in cube no %d!"</span>, z, i) ;
+<a name="l02138"></a>02138                 cpl_imagelist_delete(mergedCube) ;
+<a name="l02139"></a>02139                 cpl_imagelist_delete(mask) ;
+<a name="l02140"></a>02140                 cpl_free(kernel) ;
+<a name="l02141"></a>02141                 <span class="keywordflow">return</span> NULL ;
+<a name="l02142"></a>02142             }
+<a name="l02143"></a>02143             cpl_imagelist_set(tmpcubes[i],t_img,z);
+<a name="l02144"></a>02144         }
+<a name="l02145"></a>02145     cpl_free(tmpspace);
+<a name="l02146"></a>02146     }
+<a name="l02147"></a>02147 
+<a name="l02148"></a>02148     <span class="comment">/*-------------------------------------------------------------------------</span>
+<a name="l02149"></a>02149 <span class="comment">     * Build the mask data cube.</span>
+<a name="l02150"></a>02150 <span class="comment">     * The mask is 0 where no data is available, otherwise the integration</span>
+<a name="l02151"></a>02151 <span class="comment">       time of one frame, respectively the summed integration</span>
+<a name="l02152"></a>02152 <span class="comment">     * times in the overlapping regions are inserted</span>
+<a name="l02153"></a>02153 <span class="comment">     */</span>
+<a name="l02154"></a>02154     <span class="comment">/* go through the frame list */</span>
+<a name="l02155"></a>02155     <span class="keywordflow">for</span> ( i = 0 ; i < n_cubes ; i++ )
+<a name="l02156"></a>02156     {
+<a name="l02157"></a>02157 
+<a name="l02158"></a>02158         <span class="comment">/* go through the first image plane of the big data cube */</span>
+<a name="l02159"></a>02159         <span class="keywordflow">for</span> ( y = 0 ; y < oly ; y++ )
+<a name="l02160"></a>02160         {
+<a name="l02161"></a>02161             <span class="keywordflow">for</span> ( x = 0 ; x < olx ; x++ )
+<a name="l02162"></a>02162             {
+<a name="l02163"></a>02163                 <span class="comment">/* find the position of the present cube and</span>
+<a name="l02164"></a>02164 <span class="comment">                   go through the single spectra */</span>
+<a name="l02165"></a>02165                 <span class="keywordflow">if</span> ( y >= lly[i] && y < lly[i]+ily &&
+<a name="l02166"></a>02166                      x >= llx[i] && x < llx[i]+ilx )
+<a name="l02167"></a>02167                 {
+<a name="l02168"></a>02168                     posx = x - llx[i] ;
+<a name="l02169"></a>02169                     posy = y - lly[i] ;
+<a name="l02170"></a>02170                     <span class="keywordflow">for</span> ( z = 0 ; z < onp ; z++ )
+<a name="l02171"></a>02171                     {
+<a name="l02172"></a>02172               t_img=cpl_imagelist_get(tmpcubes[i],z);
+<a name="l02173"></a>02173                       ptdata=cpl_image_get_data_float(t_img);
+<a name="l02174"></a>02174               m_img=cpl_imagelist_get(mask,z);
+<a name="l02175"></a>02175                       pmdata=cpl_image_get_data_float(m_img);
+<a name="l02176"></a>02176                         <span class="keywordflow">if</span> (!isnan(ptdata[posx+posy*ilx]) &&
+<a name="l02177"></a>02177                                          ptdata[posx+posy*ilx] != 0.)
+<a name="l02178"></a>02178                         {
+<a name="l02179"></a>02179                             pmdata[x+y*mlx] += exptimes[i] ;
+<a name="l02180"></a>02180                         }
+<a name="l02181"></a>02181                     }
+<a name="l02182"></a>02182                 }
+<a name="l02183"></a>02183             }
+<a name="l02184"></a>02184         }
+<a name="l02185"></a>02185     }
+<a name="l02186"></a>02186 
+<a name="l02187"></a>02187 
+<a name="l02188"></a>02188 
+<a name="l02189"></a>02189 
+<a name="l02190"></a>02190 
+<a name="l02191"></a>02191 
+<a name="l02192"></a>02192     <span class="comment">/* calculate a weighted average using the</span>
+<a name="l02193"></a>02193 <span class="comment">       exposure time of the single frames</span>
+<a name="l02194"></a>02194 <span class="comment">       of the overlapping regions of the cubes */</span>
+<a name="l02195"></a>02195     <span class="keywordflow">for</span> ( i = 0 ; i < n_cubes ; i++ )
+<a name="l02196"></a>02196     {
+<a name="l02197"></a>02197 
+<a name="l02198"></a>02198         <span class="comment">/* go through the first image plane of the big data cube */</span>
+<a name="l02199"></a>02199         <span class="keywordflow">for</span> ( y = 0 ; y < oly ; y++ )
+<a name="l02200"></a>02200         {
+<a name="l02201"></a>02201 
+<a name="l02202"></a>02202             <span class="keywordflow">for</span> ( x = 0 ; x < olx ; x++ )
+<a name="l02203"></a>02203             {
+<a name="l02204"></a>02204 
+<a name="l02205"></a>02205                 <span class="comment">/* find the position of the present cube</span>
+<a name="l02206"></a>02206 <span class="comment">                   and go through the single spectra */</span>
+<a name="l02207"></a>02207                 <span class="keywordflow">if</span> ( y >= lly[i] && y < lly[i]+ily &&
+<a name="l02208"></a>02208                      x >= llx[i] && x < llx[i]+ilx )
+<a name="l02209"></a>02209                 {
+<a name="l02210"></a>02210 
+<a name="l02211"></a>02211                     posx = x - llx[i] ;
+<a name="l02212"></a>02212                     posy = y - lly[i] ;
+<a name="l02213"></a>02213                     <span class="keywordflow">for</span> ( z = 0 ; z < onp ; z++ )
+<a name="l02214"></a>02214                     {
+<a name="l02215"></a>02215 
+<a name="l02216"></a>02216               t_img=cpl_imagelist_get(tmpcubes[i],z);
+<a name="l02217"></a>02217                       ptdata=cpl_image_get_data_float(t_img);
+<a name="l02218"></a>02218               m_img=cpl_imagelist_get(mask,z);
+<a name="l02219"></a>02219                       pmdata=cpl_image_get_data_float(m_img);
+<a name="l02220"></a>02220                       mlx=cpl_image_get_size_x(m_img);
+<a name="l02221"></a>02221 
+<a name="l02222"></a>02222               o_img=cpl_imagelist_get(mergedCube,z);
+<a name="l02223"></a>02223                       podata=cpl_image_get_data_float(o_img);
+<a name="l02224"></a>02224                       podata[x+y*olx]=0;
+<a name="l02225"></a>02225                         <span class="keywordflow">if</span> (!isnan(ptdata[posx+posy*ilx]))
+<a name="l02226"></a>02226                         {
+<a name="l02227"></a>02227                             <span class="keywordflow">if</span> (pmdata[x+y*mlx] != 0.)
+<a name="l02228"></a>02228                             {
+<a name="l02229"></a>02229                 <span class="comment">/* adjust the intensities to</span>
+<a name="l02230"></a>02230 <span class="comment">                                   the first reference cube */</span>
+<a name="l02231"></a>02231                                 weight = exptimes[0] / pmdata[x+y*mlx] ;
+<a name="l02232"></a>02232                             }
+<a name="l02233"></a>02233                             <span class="keywordflow">else</span>
+<a name="l02234"></a>02234                             {
+<a name="l02235"></a>02235                                 weight = 0. ;
+<a name="l02236"></a>02236                             }
+<a name="l02237"></a>02237                             podata[x+y*olx] +=
+<a name="l02238"></a>02238                                weight*ptdata[posx+posy*ilx] ;
+<a name="l02239"></a>02239                         }
+<a name="l02240"></a>02240                     }
+<a name="l02241"></a>02241                 }
+<a name="l02242"></a>02242             }
+<a name="l02243"></a>02243         }
+<a name="l02244"></a>02244     }
+<a name="l02245"></a>02245 
+<a name="l02246"></a>02246 
+<a name="l02247"></a>02247 
+<a name="l02248"></a>02248 
+<a name="l02249"></a>02249     <span class="comment">/* convert the "free space" in the cube to blank pixels */</span>
+<a name="l02250"></a>02250     <span class="comment">/* convert_0_to_ZERO_for_cubes(mergedCube) ; */</span>
+<a name="l02251"></a>02251     cpl_free(kernel) ; <span class="comment">/* originated by eclise-malloc */</span>
+<a name="l02252"></a>02252     <span class="keywordflow">for</span>( i = 0 ; i < n_cubes ; i++ )
+<a name="l02253"></a>02253     {
+<a name="l02254"></a>02254         cpl_imagelist_delete (tmpcubes[i]) ;
+<a name="l02255"></a>02255     }
+<a name="l02256"></a>02256 
+<a name="l02257"></a>02257     cpl_free(tmpcubes); ;
+<a name="l02258"></a>02258     cpl_free(llx); ;
+<a name="l02259"></a>02259     cpl_free(lly) ;
+<a name="l02260"></a>02260 
+<a name="l02261"></a>02261     cpl_free(sub_offsetx) ;
+<a name="l02262"></a>02262     cpl_free(sub_offsety) ;
+<a name="l02263"></a>02263 
+<a name="l02264"></a>02264     <span class="keywordflow">return</span> mask ;
+<a name="l02265"></a>02265 }
+<a name="l02266"></a>02266 
+<a name="l02267"></a>02267 
+<a name="l02268"></a>02268 
+<a name="l02269"></a>02269 
+<a name="l02270"></a>02270 
+<a name="l02271"></a>02271 
+<a name="l02272"></a>02272 
+<a name="l02273"></a>02273 
+<a name="l02303"></a>02303 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l02304"></a>02304 sinfo_build_mask_cube(<span class="keyword">const</span> <span class="keywordtype">int</span> z_min,
+<a name="l02305"></a>02305                       <span class="keyword">const</span> <span class="keywordtype">int</span> z_max,
+<a name="l02306"></a>02306                       <span class="keyword">const</span> <span class="keywordtype">int</span> olx,
+<a name="l02307"></a>02307                       <span class="keyword">const</span> <span class="keywordtype">int</span> oly,
+<a name="l02308"></a>02308                       <span class="keyword">const</span> <span class="keywordtype">int</span> n_cubes,
+<a name="l02309"></a>02309                       <span class="keyword">const</span> <span class="keywordtype">int</span>* llx,
+<a name="l02310"></a>02310                       <span class="keyword">const</span> <span class="keywordtype">int</span>* lly,
+<a name="l02311"></a>02311               <span class="keywordtype">double</span>    * exptimes,
+<a name="l02312"></a>02312                       cpl_imagelist** cubes,
+<a name="l02313"></a>02313                       cpl_imagelist** tmpcubes,
+<a name="l02314"></a>02314                       cpl_imagelist* mask)
+<a name="l02315"></a>02315 {
+<a name="l02316"></a>02316 
+<a name="l02317"></a>02317   <span class="keywordtype">int</span> i=0;
+<a name="l02318"></a>02318   <span class="keywordtype">int</span> y=0;
+<a name="l02319"></a>02319   <span class="keywordtype">int</span> z=0;
+<a name="l02320"></a>02320   <span class="keywordtype">int</span> ilx=0;
+<a name="l02321"></a>02321   <span class="keywordtype">int</span> ily=0;
+<a name="l02322"></a>02322   cpl_image* i_img=NULL;
+<a name="l02323"></a>02323   cpl_image* t_img=NULL;
+<a name="l02324"></a>02324   <span class="keywordtype">int</span> posx=0;
+<a name="l02325"></a>02325   <span class="keywordtype">int</span> posy=0;
+<a name="l02326"></a>02326   <span class="keywordtype">float</span>* ptdata=NULL;
+<a name="l02327"></a>02327   <span class="keywordtype">float</span>* pmdata=NULL;
+<a name="l02328"></a>02328   <span class="keywordtype">int</span> m=0;
+<a name="l02329"></a>02329   <span class="keywordtype">int</span> x=0;
+<a name="l02330"></a>02330   <span class="keywordtype">int</span> mlx=0;
+<a name="l02331"></a>02331   cpl_image* m_img=NULL;
+<a name="l02332"></a>02332 
+<a name="l02333"></a>02333 
+<a name="l02334"></a>02334   <span class="keywordflow">for</span> ( z = z_min, m=0 ; z < z_max ; z++, m++ ) {
+<a name="l02335"></a>02335 
+<a name="l02336"></a>02336     <span class="comment">// go through the first image plane of the big data cube</span>
+<a name="l02337"></a>02337     <span class="keywordflow">for</span> ( y = 0 ; y < oly ; y++ ) {
+<a name="l02338"></a>02338       <span class="keywordflow">for</span> ( x = 0 ; x < olx ; x++ ) {
+<a name="l02339"></a>02339     <span class="keywordflow">for</span> ( i = 0 ; i < n_cubes ; i++ ) {
+<a name="l02340"></a>02340 
+<a name="l02341"></a>02341           i_img=cpl_imagelist_get(cubes[i],0);
+<a name="l02342"></a>02342           ilx=cpl_image_get_size_x(i_img);
+<a name="l02343"></a>02343           ily=cpl_image_get_size_y(i_img);
+<a name="l02344"></a>02344 
+<a name="l02345"></a>02345 
+<a name="l02346"></a>02346       <span class="comment">// find the position of the present cube and go</span>
+<a name="l02347"></a>02347           <span class="comment">// through the single spectra */</span>
+<a name="l02348"></a>02348           <span class="keywordflow">if</span> ( y >= lly[i] && y < lly[i]+ily &&
+<a name="l02349"></a>02349                x >= llx[i] && x < llx[i]+ilx )
+<a name="l02350"></a>02350         {
+<a name="l02351"></a>02351           posx = x - llx[i] ;
+<a name="l02352"></a>02352           posy = y - lly[i] ;
+<a name="l02353"></a>02353 
+<a name="l02354"></a>02354 
+<a name="l02355"></a>02355               t_img=cpl_imagelist_get(tmpcubes[i],m);
+<a name="l02356"></a>02356               ptdata=cpl_image_get_data_float(t_img);
+<a name="l02357"></a>02357               m_img=cpl_imagelist_get(mask,z);
+<a name="l02358"></a>02358               pmdata=cpl_image_get_data_float(m_img);
+<a name="l02359"></a>02359           mlx=cpl_image_get_size_x(m_img);
+<a name="l02360"></a>02360 
+<a name="l02361"></a>02361               <span class="keywordflow">if</span> (!isnan(ptdata[posx+posy*ilx]) &&
+<a name="l02362"></a>02362                          ptdata[posx+posy*ilx] != 0.)
+<a name="l02363"></a>02363         {
+<a name="l02364"></a>02364           pmdata[x+y*mlx] += (float)exptimes[i] ;
+<a name="l02365"></a>02365         } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (isnan(ptdata[posx+posy*ilx])) {
+<a name="l02366"></a>02366         <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"ptdata %d, %d, %d is NAN\t"</span>,x,y,z);
+<a name="l02367"></a>02367           } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (ptdata[posx+posy*ilx] == 0.) {
+<a name="l02368"></a>02368         <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"ptdata %d, %d, %d is 0\t"</span>,x,y,z);
+<a name="l02369"></a>02369           }
+<a name="l02370"></a>02370 
+<a name="l02371"></a>02371         } <span class="keywordflow">else</span> {
+<a name="l02372"></a>02372         <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"point %d, %d, %d outside range\n"</span>,x,y,z);
+<a name="l02373"></a>02373       }
+<a name="l02374"></a>02374         }
+<a name="l02375"></a>02375       }
+<a name="l02376"></a>02376     }
+<a name="l02377"></a>02377   }
+<a name="l02378"></a>02378   <span class="keywordflow">return</span> 0;
+<a name="l02379"></a>02379 
+<a name="l02380"></a>02380 }
+<a name="l02381"></a>02381 
+<a name="l02382"></a>02382 
+<a name="l02383"></a>02383 
+<a name="l02384"></a>02384 
+<a name="l02385"></a>02385 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l02386"></a>02386 sinfo_build_mask_cube_thomas(<span class="keyword">const</span> <span class="keywordtype">int</span> z_min,
+<a name="l02387"></a>02387                       <span class="keyword">const</span> <span class="keywordtype">int</span> z_max,
+<a name="l02388"></a>02388                       <span class="keyword">const</span> <span class="keywordtype">int</span> olx,
+<a name="l02389"></a>02389                       <span class="keyword">const</span> <span class="keywordtype">int</span> oly,
+<a name="l02390"></a>02390                       <span class="keyword">const</span> <span class="keywordtype">int</span> n_cubes,
+<a name="l02391"></a>02391                       <span class="keyword">const</span> <span class="keywordtype">int</span>* llx,
+<a name="l02392"></a>02392                       <span class="keyword">const</span> <span class="keywordtype">int</span>* lly,
+<a name="l02393"></a>02393               <span class="keywordtype">double</span>    * exptimes,
+<a name="l02394"></a>02394                       cpl_imagelist** cubes,
+<a name="l02395"></a>02395                       cpl_imagelist** tmpcubes,
+<a name="l02396"></a>02396                       cpl_imagelist* mask)
+<a name="l02397"></a>02397 {
+<a name="l02398"></a>02398 
+<a name="l02399"></a>02399   <span class="keywordtype">int</span> i=0;
+<a name="l02400"></a>02400   <span class="keywordtype">int</span> y=0;
+<a name="l02401"></a>02401   <span class="keywordtype">int</span> z=0;
+<a name="l02402"></a>02402   <span class="keywordtype">int</span> ilx=0;
+<a name="l02403"></a>02403   <span class="keywordtype">int</span> ily=0;
+<a name="l02404"></a>02404   <span class="keywordtype">int</span> inp=0;
+<a name="l02405"></a>02405   cpl_image* i_img=NULL;
+<a name="l02406"></a>02406   cpl_image* t_img=NULL;
+<a name="l02407"></a>02407   <span class="keywordtype">int</span> posx=0;
+<a name="l02408"></a>02408   <span class="keywordtype">int</span> posy=0;
+<a name="l02409"></a>02409   <span class="keywordtype">float</span>* ptdata=NULL;
+<a name="l02410"></a>02410   <span class="keywordtype">float</span>* pmdata=NULL;
+<a name="l02411"></a>02411   <span class="keywordtype">int</span> m=0;
+<a name="l02412"></a>02412   <span class="keywordtype">int</span> x=0;
+<a name="l02413"></a>02413   <span class="keywordtype">int</span> mlx=0;
+<a name="l02414"></a>02414   cpl_image* m_img=NULL;
+<a name="l02415"></a>02415 
+<a name="l02416"></a>02416   <span class="keywordflow">for</span> ( i = 0 ; i < n_cubes ; i++ ) {
+<a name="l02417"></a>02417 
+<a name="l02418"></a>02418     i_img=cpl_imagelist_get(cubes[i],0);
+<a name="l02419"></a>02419     ilx=cpl_image_get_size_x(i_img);
+<a name="l02420"></a>02420     ily=cpl_image_get_size_y(i_img);
+<a name="l02421"></a>02421     inp=cpl_imagelist_get_size(cubes[i]);
+<a name="l02422"></a>02422 
+<a name="l02423"></a>02423     <span class="comment">//go through the first image plane of the big data cube</span>
+<a name="l02424"></a>02424     <span class="keywordflow">for</span> ( y = 0 ; y < oly ; y++ ){
+<a name="l02425"></a>02425       <span class="keywordflow">for</span> ( x = 0 ; x < olx ; x++ ){
+<a name="l02426"></a>02426     <span class="comment">// find the position of the present cube and go</span>
+<a name="l02427"></a>02427     <span class="comment">// through the single spectra</span>
+<a name="l02428"></a>02428         <span class="keywordflow">if</span> ( y >= lly[i] && y < lly[i]+ily &&
+<a name="l02429"></a>02429              x >= llx[i] && x < llx[i]+ilx ) {
+<a name="l02430"></a>02430       posx = x - llx[i] ;
+<a name="l02431"></a>02431           posy = y - lly[i] ;
+<a name="l02432"></a>02432 
+<a name="l02433"></a>02433       <span class="keywordflow">for</span> ( z = z_min,m=0 ; z < z_max ; z++,m++ ) {
+<a name="l02434"></a>02434         t_img=cpl_imagelist_get(tmpcubes[i],m);
+<a name="l02435"></a>02435             ptdata=cpl_image_get_data_float(t_img);
+<a name="l02436"></a>02436             m_img=cpl_imagelist_get(mask,z);
+<a name="l02437"></a>02437             pmdata=cpl_image_get_data_float(m_img);
+<a name="l02438"></a>02438             mlx=cpl_image_get_size_x(m_img);
+<a name="l02439"></a>02439 
+<a name="l02440"></a>02440             <span class="keywordflow">if</span> (!isnan(ptdata[posx+posy*ilx]) &&
+<a name="l02441"></a>02441         ptdata[posx+posy*ilx] != 0.) {
+<a name="l02442"></a>02442           pmdata[x+y*mlx] += (float)exptimes[i]  ;
+<a name="l02443"></a>02443         }
+<a name="l02444"></a>02444       }
+<a name="l02445"></a>02445     }
+<a name="l02446"></a>02446       }
+<a name="l02447"></a>02447     }
+<a name="l02448"></a>02448   }
+<a name="l02449"></a>02449   <span class="keywordflow">return</span> 0;
+<a name="l02450"></a>02450 }
+<a name="l02451"></a>02451 
+<a name="l02452"></a>02452 
+<a name="l02453"></a>02453 
+<a name="l02454"></a>02454 
+<a name="l02455"></a>02455 
+<a name="l02506"></a>02506 <span class="keywordtype">int</span>
+<a name="l02507"></a>02507 sinfo_new_combine_jittered_cubes_range ( cpl_imagelist ** cubes,
+<a name="l02508"></a>02508                                  cpl_imagelist  * mergedCube,
+<a name="l02509"></a>02509                                  cpl_imagelist  * mask,
+<a name="l02510"></a>02510                                  <span class="keywordtype">int</span>        n_cubes,
+<a name="l02511"></a>02511                                  <span class="keywordtype">float</span>    * cumoffsetx,
+<a name="l02512"></a>02512                                  <span class="keywordtype">float</span>    * cumoffsety,
+<a name="l02513"></a>02513                                  <span class="keywordtype">double</span>    * exptimes,
+<a name="l02514"></a>02514                                  <span class="keywordtype">char</span>     * kernel_type,
+<a name="l02515"></a>02515                                  <span class="keyword">const</span> <span class="keywordtype">int</span> z_min, <span class="keyword">const</span> <span class="keywordtype">int</span> z_max )
+<a name="l02516"></a>02516 {
+<a name="l02517"></a>02517 
+<a name="l02518"></a>02518   <span class="keywordtype">int</span> i;
+<a name="l02519"></a>02519   <span class="keywordtype">int</span> llx0, lly0 ;
+<a name="l02520"></a>02520   cpl_imagelist ** tmpcubes=NULL ;
+<a name="l02521"></a>02521   <span class="keywordtype">int</span>* llx=NULL ;
+<a name="l02522"></a>02522   <span class="keywordtype">int</span>* lly=NULL ;
+<a name="l02523"></a>02523   <span class="keywordtype">float</span>* sub_offsetx=NULL ;
+<a name="l02524"></a>02524   <span class="keywordtype">float</span>* sub_offsety=NULL ;
+<a name="l02525"></a>02525 
+<a name="l02526"></a>02526   <span class="keywordtype">int</span> ilx=0;
+<a name="l02527"></a>02527   <span class="keywordtype">int</span> ily=0;
+<a name="l02528"></a>02528   <span class="keywordtype">int</span> olx=0;
+<a name="l02529"></a>02529   <span class="keywordtype">int</span> oly=0;
+<a name="l02530"></a>02530   <span class="keywordtype">int</span> mlx=0;
+<a name="l02531"></a>02531   <span class="keywordtype">int</span> mly=0;
+<a name="l02532"></a>02532 
+<a name="l02533"></a>02533   cpl_image* i_img=NULL;
+<a name="l02534"></a>02534   cpl_image* o_img=NULL;
+<a name="l02535"></a>02535 
+<a name="l02536"></a>02536 
+<a name="l02537"></a>02537   <span class="keywordflow">if</span>(sinfo_check_input(cubes,n_cubes,cumoffsetx,cumoffsety,exptimes) == -1) {
+<a name="l02538"></a>02538     <span class="keywordflow">return</span> -1;
+<a name="l02539"></a>02539   }
+<a name="l02540"></a>02540 
+<a name="l02541"></a>02541     o_img=cpl_imagelist_get(mergedCube,z_min);
+<a name="l02542"></a>02542     olx=cpl_image_get_size_x(o_img);
+<a name="l02543"></a>02543     oly=cpl_image_get_size_y(o_img);
+<a name="l02544"></a>02544     i_img=cpl_imagelist_get(cubes[0],0);
+<a name="l02545"></a>02545     ilx=cpl_image_get_size_x(i_img);
+<a name="l02546"></a>02546     ily=cpl_image_get_size_y(i_img);
+<a name="l02547"></a>02547     mlx=olx;
+<a name="l02548"></a>02548     mly=oly;
+<a name="l02549"></a>02549 
+<a name="l02550"></a>02550 
+<a name="l02551"></a>02551     <span class="comment">/*--------------------------------------------------------------------</span>
+<a name="l02552"></a>02552 <span class="comment">     * center the cubes within the allocated big cube</span>
+<a name="l02553"></a>02553 <span class="comment">     * that means define the (0,0) positions of the cubes in the image planes</span>
+<a name="l02554"></a>02554 <span class="comment">     * to sub-pixel accuracy by using cumoffsetx,y and the reference cube</span>
+<a name="l02555"></a>02555 <span class="comment">     */</span>
+<a name="l02556"></a>02556     <span class="comment">/* position of first reference frame, centered in big cube */</span>
+<a name="l02557"></a>02557     llx0 = olx/2 - ilx/2 ;
+<a name="l02558"></a>02558     lly0 = oly/2 - ily/2 ;
+<a name="l02559"></a>02559 
+<a name="l02560"></a>02560     <span class="comment">/*--------------------------------------------------------------------</span>
+<a name="l02561"></a>02561 <span class="comment">     * go through the frame list and determine the lower left edge position</span>
+<a name="l02562"></a>02562 <span class="comment">     * of the shifted cubes. Additionnally, the sub-pixel offsets are</span>
+<a name="l02563"></a>02563 <span class="comment">     * determined.</span>
+<a name="l02564"></a>02564 <span class="comment">     */</span>
+<a name="l02565"></a>02565 
+<a name="l02566"></a>02566 
+<a name="l02567"></a>02567     llx=cpl_calloc(n_cubes,<span class="keyword">sizeof</span>(<span class="keywordtype">int</span>)) ;
+<a name="l02568"></a>02568     lly=cpl_calloc(n_cubes,<span class="keyword">sizeof</span>(<span class="keywordtype">int</span>)) ;
+<a name="l02569"></a>02569     sub_offsetx=cpl_calloc(n_cubes,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l02570"></a>02570     sub_offsety=cpl_calloc(n_cubes,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l02571"></a>02571 
+<a name="l02572"></a>02572     <span class="keywordflow">for</span> ( i = 0 ; i < n_cubes ; i++ )
+<a name="l02573"></a>02573     {
+<a name="l02574"></a>02574         llx[i] = llx0 - sinfo_new_nint(cumoffsetx[i]) ;
+<a name="l02575"></a>02575         sub_offsetx[i] = (float)sinfo_new_nint(cumoffsetx[i]) - cumoffsetx[i] ;
+<a name="l02576"></a>02576         lly[i] = lly0 - sinfo_new_nint(cumoffsety[i]) ;
+<a name="l02577"></a>02577         sub_offsety[i] = (float)sinfo_new_nint(cumoffsety[i]) - cumoffsety[i] ;
+<a name="l02578"></a>02578     }
+<a name="l02579"></a>02579 
+<a name="l02580"></a>02580     tmpcubes=(cpl_imagelist**)cpl_calloc(n_cubes,<span class="keyword">sizeof</span>(cpl_imagelist*)) ;
+<a name="l02581"></a>02581     <span class="comment">/* -------------------------------------------------------------</span>
+<a name="l02582"></a>02582 <span class="comment">     * shift the cubes according to the computed sub-pixel offsets</span>
+<a name="l02583"></a>02583 <span class="comment">     * that means shift the single image planes of each cube</span>
+<a name="l02584"></a>02584 <span class="comment">     * first determine an interpolation kernel</span>
+<a name="l02585"></a>02585 <span class="comment">     */</span>
+<a name="l02586"></a>02586     <span class="keywordflow">if</span>(sinfo_shift_cubes(tmpcubes,kernel_type,n_cubes,cubes,z_min, z_max,
+<a name="l02587"></a>02587              sub_offsetx,sub_offsety,mlx,mly,mask) == -1) {
+<a name="l02588"></a>02588       <span class="keywordflow">return</span> -1;
+<a name="l02589"></a>02589     }
+<a name="l02590"></a>02590 
+<a name="l02591"></a>02591 
+<a name="l02592"></a>02592     <span class="comment">/*-----------------------------------------------------------------------</span>
+<a name="l02593"></a>02593 <span class="comment">     * Build the mask data cube.</span>
+<a name="l02594"></a>02594 <span class="comment">     * The mask is 0 where no data is available, otherwise the</span>
+<a name="l02595"></a>02595 <span class="comment">       integration time of</span>
+<a name="l02596"></a>02596 <span class="comment">     * one frame, respectively the summed integration</span>
+<a name="l02597"></a>02597 <span class="comment">     * times in the overlapping regions are inserted</span>
+<a name="l02598"></a>02598 <span class="comment">     */</span>
+<a name="l02599"></a>02599     <span class="comment">/* go through the frame list */</span>
+<a name="l02600"></a>02600     sinfo_build_mask_cube(z_min,z_max,olx,oly,n_cubes,llx,lly,exptimes,
+<a name="l02601"></a>02601                           cubes,tmpcubes,mask);
+<a name="l02602"></a>02602 
+<a name="l02603"></a>02603 
+<a name="l02604"></a>02604     <span class="comment">/* calculate a weighted average using the exposure time of the</span>
+<a name="l02605"></a>02605 <span class="comment">       single frames of the overlapping regions of the cubes */</span>
+<a name="l02606"></a>02606 
+<a name="l02607"></a>02607     sinfo_compute_weight_average(z_min,z_max,ilx,ily,n_cubes,mergedCube,mask,
+<a name="l02608"></a>02608                                  tmpcubes,exptimes,llx,lly);
+<a name="l02609"></a>02609 
+<a name="l02610"></a>02610     <span class="comment">/* convert the "free space" in the cube to blank pixels */</span>
+<a name="l02611"></a>02611      <span class="comment">/* convert_0_to_ZERO_for_cubes(mergedCube) ; */</span>
+<a name="l02612"></a>02612 
+<a name="l02613"></a>02613     <span class="keywordflow">for</span>( i = 0 ; i < n_cubes ; i++ )
+<a name="l02614"></a>02614     {
+<a name="l02615"></a>02615         cpl_imagelist_delete (tmpcubes[i]) ;
+<a name="l02616"></a>02616     }
+<a name="l02617"></a>02617 
+<a name="l02618"></a>02618 
+<a name="l02619"></a>02619     cpl_free(tmpcubes) ;
+<a name="l02620"></a>02620     cpl_free(llx) ;
+<a name="l02621"></a>02621     cpl_free(lly) ;
+<a name="l02622"></a>02622     cpl_free(sub_offsetx) ;
+<a name="l02623"></a>02623     cpl_free(sub_offsety) ;
+<a name="l02624"></a>02624 
+<a name="l02625"></a>02625      <span class="keywordflow">return</span> 0 ;
+<a name="l02626"></a>02626 }
+<a name="l02627"></a>02627 
+<a name="l02645"></a>02645 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l02646"></a>02646 sinfo_check_input(cpl_imagelist** cubes,
+<a name="l02647"></a>02647                           <span class="keyword">const</span> <span class="keywordtype">int</span> n_cubes,
+<a name="l02648"></a>02648                           <span class="keywordtype">float</span>* cumoffsetx,
+<a name="l02649"></a>02649                           <span class="keywordtype">float</span>* cumoffsety,
+<a name="l02650"></a>02650               <span class="keywordtype">double</span>* exptimes)
+<a name="l02651"></a>02651 {
+<a name="l02652"></a>02652    <span class="keywordflow">if</span> ( cubes == NULL )
+<a name="l02653"></a>02653     {
+<a name="l02654"></a>02654         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"no cube list given!"</span>) ;
+<a name="l02655"></a>02655         <span class="keywordflow">return</span> -1 ;
+<a name="l02656"></a>02656     }
+<a name="l02657"></a>02657     <span class="keywordflow">if</span> ( n_cubes <= 0 )
+<a name="l02658"></a>02658     {
+<a name="l02659"></a>02659         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"wrong number of data cubes in list!"</span>) ;
+<a name="l02660"></a>02660         <span class="keywordflow">return</span> -1 ;
+<a name="l02661"></a>02661     }
+<a name="l02662"></a>02662     <span class="keywordflow">if</span> ( cumoffsetx == NULL || cumoffsety == NULL )
+<a name="l02663"></a>02663     {
+<a name="l02664"></a>02664         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"no cumoffsetx/y given!"</span>) ;
+<a name="l02665"></a>02665         <span class="keywordflow">return</span> -1;
+<a name="l02666"></a>02666     }
+<a name="l02667"></a>02667     <span class="keywordflow">if</span> ( exptimes == NULL )
+<a name="l02668"></a>02668     {
+<a name="l02669"></a>02669         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"no exposure time array given!"</span>) ;
+<a name="l02670"></a>02670         <span class="keywordflow">return</span> -1 ;
+<a name="l02671"></a>02671     }
+<a name="l02672"></a>02672 
+<a name="l02673"></a>02673     <span class="keywordflow">return</span> 0;
+<a name="l02674"></a>02674 }
+<a name="l02675"></a>02675 
+<a name="l02701"></a>02701 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l02702"></a>02702 sinfo_compute_weight_average(<span class="keyword">const</span> <span class="keywordtype">int</span> z_min,
+<a name="l02703"></a>02703                              <span class="keyword">const</span> <span class="keywordtype">int</span> z_max,
+<a name="l02704"></a>02704                              <span class="keyword">const</span> <span class="keywordtype">int</span> ilx,
+<a name="l02705"></a>02705                              <span class="keyword">const</span> <span class="keywordtype">int</span> ily,
+<a name="l02706"></a>02706                  <span class="keyword">const</span> <span class="keywordtype">int</span> n_cubes,
+<a name="l02707"></a>02707                              cpl_imagelist* mergedCube,
+<a name="l02708"></a>02708                              cpl_imagelist* mask,
+<a name="l02709"></a>02709                              cpl_imagelist** tmpcubes,
+<a name="l02710"></a>02710                  <span class="keywordtype">double</span>* exptimes,
+<a name="l02711"></a>02711                              <span class="keywordtype">int</span>* llx,
+<a name="l02712"></a>02712                              <span class="keywordtype">int</span>* lly)
+<a name="l02713"></a>02713 {
+<a name="l02714"></a>02714 
+<a name="l02715"></a>02715   <span class="keywordtype">int</span> m=0;
+<a name="l02716"></a>02716   <span class="keywordtype">int</span> x=0;
+<a name="l02717"></a>02717   <span class="keywordtype">int</span> y=0;
+<a name="l02718"></a>02718   <span class="keywordtype">int</span> z=0;
+<a name="l02719"></a>02719   <span class="keywordtype">int</span> i=0;
+<a name="l02720"></a>02720 
+<a name="l02721"></a>02721   <span class="keywordtype">int</span> mlx=0;
+<a name="l02722"></a>02722   <span class="keywordtype">int</span> mly=0;
+<a name="l02723"></a>02723   <span class="keywordtype">int</span> olx=0;
+<a name="l02724"></a>02724   <span class="keywordtype">int</span> oly=0;
+<a name="l02725"></a>02725 
+<a name="l02726"></a>02726   cpl_image* o_img=NULL;
+<a name="l02727"></a>02727   cpl_image* m_img=NULL;
+<a name="l02728"></a>02728   cpl_image* t_img=NULL;
+<a name="l02729"></a>02729 
+<a name="l02730"></a>02730   <span class="keywordtype">float</span>* podata=NULL;
+<a name="l02731"></a>02731   <span class="keywordtype">float</span>* pmdata=NULL;
+<a name="l02732"></a>02732   <span class="keywordtype">float</span>* ptdata=NULL;
+<a name="l02733"></a>02733   <span class="keywordtype">double</span> weight=0;
+<a name="l02734"></a>02734 
+<a name="l02735"></a>02735   <span class="keywordtype">int</span> posx=0;
+<a name="l02736"></a>02736   <span class="keywordtype">int</span> posy=0;
+<a name="l02737"></a>02737 
+<a name="l02738"></a>02738 
+<a name="l02739"></a>02739   o_img=cpl_imagelist_get(mergedCube,z_min);
+<a name="l02740"></a>02740   olx=cpl_image_get_size_x(o_img);
+<a name="l02741"></a>02741   oly=cpl_image_get_size_y(o_img);
+<a name="l02742"></a>02742   mlx=olx;
+<a name="l02743"></a>02743   mly=oly;
+<a name="l02744"></a>02744 
+<a name="l02745"></a>02745   <span class="comment">/* calculate a weighted average using the exposure time of the</span>
+<a name="l02746"></a>02746 <span class="comment">     single frames of the overlapping regions of the cubes */</span>
+<a name="l02747"></a>02747   <span class="keywordflow">for</span> ( z = z_min, m = 0 ; z < z_max ; z++, m++ ) {
+<a name="l02748"></a>02748     o_img=cpl_imagelist_get(mergedCube,z);
+<a name="l02749"></a>02749     podata=cpl_image_get_data_float(o_img);
+<a name="l02750"></a>02750     m_img=cpl_imagelist_get(mask,z);
+<a name="l02751"></a>02751     pmdata=cpl_image_get_data_float(m_img);
+<a name="l02752"></a>02752     mlx=cpl_image_get_size_x(m_img);
+<a name="l02753"></a>02753 
+<a name="l02754"></a>02754     <span class="comment">/* go through the first image plane of the big data cube */</span>
+<a name="l02755"></a>02755     <span class="keywordflow">for</span> ( y = 0 ; y < oly ; y++ ) {
+<a name="l02756"></a>02756       <span class="keywordflow">for</span> ( x = 0 ; x < olx ; x++ ) {
+<a name="l02757"></a>02757 
+<a name="l02758"></a>02758        <span class="comment">/* find the position of the present cube and</span>
+<a name="l02759"></a>02759 <span class="comment">          go through the single spectra */</span>
+<a name="l02760"></a>02760 
+<a name="l02761"></a>02761     <span class="keywordflow">for</span> ( i = 0 ; i < n_cubes ; i++ ) {
+<a name="l02762"></a>02762 
+<a name="l02763"></a>02763           <span class="keywordflow">if</span> ( y >= lly[i] && y < lly[i]+ily &&
+<a name="l02764"></a>02764                x >= llx[i] && x < llx[i]+ilx ) {
+<a name="l02765"></a>02765         posx = x - llx[i] ;
+<a name="l02766"></a>02766             posy = y - lly[i] ;
+<a name="l02767"></a>02767 
+<a name="l02768"></a>02768             t_img=cpl_imagelist_get(tmpcubes[i],m);
+<a name="l02769"></a>02769             ptdata=cpl_image_get_data_float(t_img);
+<a name="l02770"></a>02770             <span class="comment">/* To prevent black regions in peculiar batterfly cases</span>
+<a name="l02771"></a>02771 <span class="comment">              podata[x+y*olx]=0;</span>
+<a name="l02772"></a>02772 <span class="comment">            */</span>
+<a name="l02773"></a>02773         <span class="keywordflow">if</span> (!isnan(ptdata[posx+posy*ilx])) {
+<a name="l02774"></a>02774           <span class="keywordflow">if</span> (pmdata[x+y*mlx] != 0.) {
+<a name="l02775"></a>02775                 <span class="comment">/* adjust the intensities to the</span>
+<a name="l02776"></a>02776 <span class="comment">                   first reference cube */</span>
+<a name="l02777"></a>02777         weight = exptimes[0] / pmdata[x+y*mlx] ;
+<a name="l02778"></a>02778           } <span class="keywordflow">else</span> {
+<a name="l02779"></a>02779         weight = 0. ;
+<a name="l02780"></a>02780           }
+<a name="l02781"></a>02781               podata[x+y*olx] += weight*ptdata[posx+posy*ilx] ;
+<a name="l02782"></a>02782 
+<a name="l02783"></a>02783         }
+<a name="l02784"></a>02784       }
+<a name="l02785"></a>02785     }
+<a name="l02786"></a>02786       }
+<a name="l02787"></a>02787     }
+<a name="l02788"></a>02788   }
+<a name="l02789"></a>02789   <span class="keywordflow">return</span> 0;
+<a name="l02790"></a>02790 }
+<a name="l02791"></a>02791 
+<a name="l02792"></a>02792 
+<a name="l02832"></a>02832 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l02833"></a>02833 sinfo_shift_cubes(cpl_imagelist** tmpcubes,
+<a name="l02834"></a>02834                   <span class="keywordtype">char</span>* kernel_type,
+<a name="l02835"></a>02835                   <span class="keyword">const</span> <span class="keywordtype">int</span> n_cubes,
+<a name="l02836"></a>02836                   cpl_imagelist** cubes,
+<a name="l02837"></a>02837                   <span class="keyword">const</span> <span class="keywordtype">int</span> z_min,
+<a name="l02838"></a>02838                   <span class="keyword">const</span> <span class="keywordtype">int</span> z_max,
+<a name="l02839"></a>02839                   <span class="keywordtype">float</span>* sub_offsetx,
+<a name="l02840"></a>02840                   <span class="keywordtype">float</span>* sub_offsety,
+<a name="l02841"></a>02841                   <span class="keyword">const</span> <span class="keywordtype">int</span> mlx,
+<a name="l02842"></a>02842                   <span class="keyword">const</span> <span class="keywordtype">int</span> mly,
+<a name="l02843"></a>02843                   cpl_imagelist* mask)
+<a name="l02844"></a>02844 {
+<a name="l02845"></a>02845 
+<a name="l02846"></a>02846    <span class="keywordtype">double</span> * kernel ;
+<a name="l02847"></a>02847    <span class="keywordtype">int</span> i=0;
+<a name="l02848"></a>02848    cpl_image* i_img=NULL;
+<a name="l02849"></a>02849    <span class="keywordtype">int</span> ilx=0;
+<a name="l02850"></a>02850    <span class="keywordtype">int</span> ily=0;
+<a name="l02851"></a>02851    <span class="keywordtype">int</span> inp=0;
+<a name="l02852"></a>02852    pixelvalue * tmpspace;
+<a name="l02853"></a>02853    <span class="keywordtype">int</span> z=0;
+<a name="l02854"></a>02854    cpl_image* t_img=NULL;
+<a name="l02855"></a>02855    cpl_image* m_img=NULL;
+<a name="l02856"></a>02856    <span class="keywordtype">int</span> m=0;
+<a name="l02857"></a>02857 
+<a name="l02858"></a>02858     <span class="comment">/* -------------------------------------------------------------</span>
+<a name="l02859"></a>02859 <span class="comment">     * shift the cubes according to the computed sub-pixel offsets</span>
+<a name="l02860"></a>02860 <span class="comment">     * that means shift the single image planes of each cube</span>
+<a name="l02861"></a>02861 <span class="comment">     * first determine an interpolation kernel</span>
+<a name="l02862"></a>02862 <span class="comment">     */</span>
+<a name="l02863"></a>02863 
+<a name="l02864"></a>02864    <span class="keywordflow">if</span> ( NULL == (kernel = sinfo_generate_interpolation_kernel(kernel_type)) )
+<a name="l02865"></a>02865     {
+<a name="l02866"></a>02866         <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a> (<span class="stringliteral">"could not generate desired interpolation kernel"</span>
+<a name="l02867"></a>02867                            <span class="stringliteral">"or no kernel_typ was given, the default kernel"</span>
+<a name="l02868"></a>02868                            <span class="stringliteral">"is used now!"</span>) ;
+<a name="l02869"></a>02869     }
+<a name="l02870"></a>02870     <span class="comment">/* go through the frame list */</span>
+<a name="l02871"></a>02871 
+<a name="l02872"></a>02872     <span class="keywordflow">for</span> ( i = 0 ; i < n_cubes ; i++ )
+<a name="l02873"></a>02873     {
+<a name="l02874"></a>02874 
+<a name="l02875"></a>02875       i_img=cpl_imagelist_get(cubes[i],0);
+<a name="l02876"></a>02876       ilx=cpl_image_get_size_x(i_img);
+<a name="l02877"></a>02877       ily=cpl_image_get_size_y(i_img);
+<a name="l02878"></a>02878       inp=cpl_imagelist_get_size(cubes[i]);
+<a name="l02879"></a>02879       tmpspace = cpl_calloc(ilx, ily*<span class="keyword">sizeof</span>(pixelvalue)) ;
+<a name="l02880"></a>02880       tmpcubes[i]=cpl_imagelist_new();
+<a name="l02881"></a>02881 
+<a name="l02882"></a>02882         <span class="keywordflow">for</span> ( z = z_min, m=0 ; z < z_max ; z++, m++ )
+<a name="l02883"></a>02883         {
+<a name="l02884"></a>02884               t_img=sinfo_new_shift_image(cpl_imagelist_get(cubes[i],z),
+<a name="l02885"></a>02885                                           sub_offsetx[i],
+<a name="l02886"></a>02886                                           sub_offsety[i],
+<a name="l02887"></a>02887                                           kernel);
+<a name="l02888"></a>02888 
+<a name="l02889"></a>02889         <span class="keywordflow">if</span> (t_img==NULL)
+<a name="l02890"></a>02890             {
+<a name="l02891"></a>02891                 <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"could not shift image plane no %d "</span>
+<a name="l02892"></a>02892                                 <span class="stringliteral">"in cube no %d!"</span>, z, i) ;
+<a name="l02893"></a>02893                 cpl_free(kernel) ;
+<a name="l02894"></a>02894                 <span class="keywordflow">return</span> -1 ;
+<a name="l02895"></a>02895             }
+<a name="l02896"></a>02896 
+<a name="l02897"></a>02897             cpl_imagelist_set(tmpcubes[i],t_img,m);
+<a name="l02898"></a>02898             m_img=cpl_image_new(mlx,mly,CPL_TYPE_FLOAT);
+<a name="l02899"></a>02899             cpl_imagelist_set(mask,m_img,z);
+<a name="l02900"></a>02900         }
+<a name="l02901"></a>02901 
+<a name="l02902"></a>02902      cpl_free(tmpspace);
+<a name="l02903"></a>02903 
+<a name="l02904"></a>02904     }
+<a name="l02905"></a>02905     <span class="keywordflow">if</span>(kernel != NULL) cpl_free(kernel) ;
+<a name="l02906"></a>02906 
+<a name="l02907"></a>02907     <span class="keywordflow">return</span> 0;
+<a name="l02908"></a>02908 
+<a name="l02909"></a>02909 }
+<a name="l02910"></a>02910 
+<a name="l02911"></a>02911 
+<a name="l02912"></a>02912 <span class="comment">/* Temporally commented out as not yet used</span>
+<a name="l02913"></a>02913 <span class="comment">static int</span>
+<a name="l02914"></a>02914 <span class="comment">sinfo_ks_clip(</span>
+<a name="l02915"></a>02915 <span class="comment">          const int n_cubes,</span>
+<a name="l02916"></a>02916 <span class="comment">              const int nc,</span>
+<a name="l02917"></a>02917 <span class="comment">          const int ilx,</span>
+<a name="l02918"></a>02918 <span class="comment">          const int ily,</span>
+<a name="l02919"></a>02919 <span class="comment">          const double kappa,</span>
+<a name="l02920"></a>02920 <span class="comment">          int* llx,</span>
+<a name="l02921"></a>02921 <span class="comment">          int* lly,</span>
+<a name="l02922"></a>02922 <span class="comment">          double* exptimes,</span>
+<a name="l02923"></a>02923 <span class="comment">          cpl_imagelist** tmpcubes,</span>
+<a name="l02924"></a>02924 <span class="comment">              float* podata,</span>
+<a name="l02925"></a>02925 <span class="comment">              float* pmdata,</span>
+<a name="l02926"></a>02926 <span class="comment">          const int x,</span>
+<a name="l02927"></a>02927 <span class="comment">          const int y,</span>
+<a name="l02928"></a>02928 <span class="comment">          const int m,</span>
+<a name="l02929"></a>02929 <span class="comment">          const int mlx,</span>
+<a name="l02930"></a>02930 <span class="comment">          const int olx</span>
+<a name="l02931"></a>02931 <span class="comment">  )</span>
+<a name="l02932"></a>02932 <span class="comment">{</span>
+<a name="l02933"></a>02933 <span class="comment"></span>
+<a name="l02934"></a>02934 <span class="comment"></span>
+<a name="l02935"></a>02935 <span class="comment">  int posx=0;</span>
+<a name="l02936"></a>02936 <span class="comment">  int posy=0;</span>
+<a name="l02937"></a>02937 <span class="comment">  int i=0;</span>
+<a name="l02938"></a>02938 <span class="comment">  int nclip=0;</span>
+<a name="l02939"></a>02939 <span class="comment">  int ks=0;</span>
+<a name="l02940"></a>02940 <span class="comment"></span>
+<a name="l02941"></a>02941 <span class="comment">  float sig=0;</span>
+<a name="l02942"></a>02942 <span class="comment">  float med=0;</span>
+<a name="l02943"></a>02943 <span class="comment">  float ovr=0;</span>
+<a name="l02944"></a>02944 <span class="comment">  float avg=0;</span>
+<a name="l02945"></a>02945 <span class="comment"></span>
+<a name="l02946"></a>02946 <span class="comment">  float* ptdata=NULL;</span>
+<a name="l02947"></a>02947 <span class="comment">  float* pvdata=NULL;</span>
+<a name="l02948"></a>02948 <span class="comment"></span>
+<a name="l02949"></a>02949 <span class="comment">  cpl_image* t_img=NULL;</span>
+<a name="l02950"></a>02950 <span class="comment">  float  msk_sum=0;</span>
+<a name="l02951"></a>02951 <span class="comment">  float  val_msk_sum=0;</span>
+<a name="l02952"></a>02952 <span class="comment">  cpl_image* v_img=NULL;</span>
+<a name="l02953"></a>02953 <span class="comment"></span>
+<a name="l02954"></a>02954 <span class="comment">  cpl_vector* val=NULL;</span>
+<a name="l02955"></a>02955 <span class="comment">  cpl_vector* msk=NULL;</span>
+<a name="l02956"></a>02956 <span class="comment"></span>
+<a name="l02957"></a>02957 <span class="comment">  msk=cpl_vector_new(n_cubes);</span>
+<a name="l02958"></a>02958 <span class="comment">  for (i=0;i<n_cubes;i++) {</span>
+<a name="l02959"></a>02959 <span class="comment">    cpl_vector_set(msk,i,1);</span>
+<a name="l02960"></a>02960 <span class="comment">  }</span>
+<a name="l02961"></a>02961 <span class="comment"></span>
+<a name="l02962"></a>02962 <span class="comment">  // k-s clipping</span>
+<a name="l02963"></a>02963 <span class="comment">  nclip=0;</span>
+<a name="l02964"></a>02964 <span class="comment"></span>
+<a name="l02965"></a>02965 <span class="comment">  for (ks=0;ks<nc;ks++) {</span>
+<a name="l02966"></a>02966 <span class="comment"></span>
+<a name="l02967"></a>02967 <span class="comment">    sig=0;</span>
+<a name="l02968"></a>02968 <span class="comment">    med=0;</span>
+<a name="l02969"></a>02969 <span class="comment">    ovr=0;</span>
+<a name="l02970"></a>02970 <span class="comment">    if(nc-nclip >0) {</span>
+<a name="l02971"></a>02971 <span class="comment">      val=cpl_vector_new(nc-nclip);</span>
+<a name="l02972"></a>02972 <span class="comment">    }</span>
+<a name="l02973"></a>02973 <span class="comment"></span>
+<a name="l02974"></a>02974 <span class="comment">    // fill val</span>
+<a name="l02975"></a>02975 <span class="comment">    for ( i = 0 ; i < n_cubes ; i++ ) {</span>
+<a name="l02976"></a>02976 <span class="comment">      t_img=cpl_imagelist_get(tmpcubes[i],m);</span>
+<a name="l02977"></a>02977 <span class="comment">      ptdata=cpl_image_get_data_float(t_img);</span>
+<a name="l02978"></a>02978 <span class="comment">      if ( y >= lly[i] && y < lly[i]+ily &&</span>
+<a name="l02979"></a>02979 <span class="comment">       x >= llx[i] && x < llx[i]+ilx ) {</span>
+<a name="l02980"></a>02980 <span class="comment">    posx = x - llx[i] ;</span>
+<a name="l02981"></a>02981 <span class="comment">    posy = y - lly[i] ;</span>
+<a name="l02982"></a>02982 <span class="comment">    if (!isnan(ptdata[posx+posy*ilx]) &&</span>
+<a name="l02983"></a>02983 <span class="comment">        ptdata[posx+posy*ilx] != 0. &&</span>
+<a name="l02984"></a>02984 <span class="comment">        (cpl_vector_get(msk,i) != 0)) {</span>
+<a name="l02985"></a>02985 <span class="comment">      cpl_vector_set(val,ovr,(double)ptdata[posx+posy*ilx]);</span>
+<a name="l02986"></a>02986 <span class="comment">      ovr++;</span>
+<a name="l02987"></a>02987 <span class="comment">    }</span>
+<a name="l02988"></a>02988 <span class="comment">      }</span>
+<a name="l02989"></a>02989 <span class="comment">    }</span>
+<a name="l02990"></a>02990 <span class="comment"></span>
+<a name="l02991"></a>02991 <span class="comment">    // get avg, med, sig</span>
+<a name="l02992"></a>02992 <span class="comment">    if(ovr>0) {</span>
+<a name="l02993"></a>02993 <span class="comment">      avg=cpl_vector_get_mean(val);</span>
+<a name="l02994"></a>02994 <span class="comment">      med=cpl_vector_get_median_const(val);</span>
+<a name="l02995"></a>02995 <span class="comment">      if(ovr>1) {</span>
+<a name="l02996"></a>02996 <span class="comment">    sig=cpl_vector_get_stdev(val);</span>
+<a name="l02997"></a>02997 <span class="comment">      } else {</span>
+<a name="l02998"></a>02998 <span class="comment">    sig=0;</span>
+<a name="l02999"></a>02999 <span class="comment">      }</span>
+<a name="l03000"></a>03000 <span class="comment">      cpl_vector_delete(val);</span>
+<a name="l03001"></a>03001 <span class="comment">    }</span>
+<a name="l03002"></a>03002 <span class="comment"></span>
+<a name="l03003"></a>03003 <span class="comment">    for ( i = 0 ; i < n_cubes ; i++ ) {</span>
+<a name="l03004"></a>03004 <span class="comment">      t_img=cpl_imagelist_get(tmpcubes[i],m);</span>
+<a name="l03005"></a>03005 <span class="comment">      ptdata=cpl_image_get_data_float(t_img);</span>
+<a name="l03006"></a>03006 <span class="comment">      // Do k-s clipping at each pixel</span>
+<a name="l03007"></a>03007 <span class="comment">      if ( y >= lly[i] && y < lly[i]+ily &&</span>
+<a name="l03008"></a>03008 <span class="comment">       x >= llx[i] && x < llx[i]+ilx ) {</span>
+<a name="l03009"></a>03009 <span class="comment">    posx = x - llx[i] ;</span>
+<a name="l03010"></a>03010 <span class="comment">    posy = y - lly[i] ;</span>
+<a name="l03011"></a>03011 <span class="comment">    //sinfo_msg_warning("llx[%d]=%d lly[%d],=%d",i,llx[i],i,lly[i]);</span>
+<a name="l03012"></a>03012 <span class="comment">    //sinfo_msg_warning("posx=%d posy=%d",posx,posy);</span>
+<a name="l03013"></a>03013 <span class="comment">    if (!isnan(ptdata[posx+posy*ilx]) &&</span>
+<a name="l03014"></a>03014 <span class="comment">        ptdata[posx+posy*ilx] != 0. &&</span>
+<a name="l03015"></a>03015 <span class="comment">        (cpl_vector_get(msk,i) != 0)) {</span>
+<a name="l03016"></a>03016 <span class="comment">      if(abs((ptdata[posx+posy*ilx]-med))> kappa*sig) {</span>
+<a name="l03017"></a>03017 <span class="comment">        ptdata[posx+posy*ilx]=0;</span>
+<a name="l03018"></a>03018 <span class="comment"></span>
+<a name="l03019"></a>03019 <span class="comment">        pmdata[x+y*mlx] -= exptimes[i]  ;</span>
+<a name="l03020"></a>03020 <span class="comment"></span>
+<a name="l03021"></a>03021 <span class="comment">        cpl_vector_set(msk,i,0);</span>
+<a name="l03022"></a>03022 <span class="comment">        nclip++;</span>
+<a name="l03023"></a>03023 <span class="comment">      }</span>
+<a name="l03024"></a>03024 <span class="comment">    }</span>
+<a name="l03025"></a>03025 <span class="comment">      }</span>
+<a name="l03026"></a>03026 <span class="comment"></span>
+<a name="l03027"></a>03027 <span class="comment">    }</span>
+<a name="l03028"></a>03028 <span class="comment">  }</span>
+<a name="l03029"></a>03029 <span class="comment"></span>
+<a name="l03030"></a>03030 <span class="comment">  msk_sum=0;</span>
+<a name="l03031"></a>03031 <span class="comment">  val_msk_sum=0;</span>
+<a name="l03032"></a>03032 <span class="comment">  for ( i = 0 ; i < n_cubes ; i++ ) {</span>
+<a name="l03033"></a>03033 <span class="comment">    v_img=cpl_imagelist_get(tmpcubes[i],m);</span>
+<a name="l03034"></a>03034 <span class="comment">    pvdata=cpl_image_get_data_float(v_img);</span>
+<a name="l03035"></a>03035 <span class="comment">    // computes sky at each point</span>
+<a name="l03036"></a>03036 <span class="comment">    if ( y >= lly[i] && y < lly[i]+ily &&</span>
+<a name="l03037"></a>03037 <span class="comment">     x >= llx[i] && x < llx[i]+ilx ) {</span>
+<a name="l03038"></a>03038 <span class="comment">      posx = x - llx[i] ;</span>
+<a name="l03039"></a>03039 <span class="comment">      posy = y - lly[i] ;</span>
+<a name="l03040"></a>03040 <span class="comment">      if (!isnan(pvdata[posx+posy*ilx]) &&</span>
+<a name="l03041"></a>03041 <span class="comment">      pvdata[posx+posy*ilx] != 0. &&</span>
+<a name="l03042"></a>03042 <span class="comment">      (cpl_vector_get(msk,i) != 0)) {</span>
+<a name="l03043"></a>03043 <span class="comment"></span>
+<a name="l03044"></a>03044 <span class="comment">    msk_sum+= pmdata[x+y*mlx];</span>
+<a name="l03045"></a>03045 <span class="comment"></span>
+<a name="l03046"></a>03046 <span class="comment">    val_msk_sum+=pvdata[posx+posy*ilx]*</span>
+<a name="l03047"></a>03047 <span class="comment">      pmdata[x+y*mlx];</span>
+<a name="l03048"></a>03048 <span class="comment"></span>
+<a name="l03049"></a>03049 <span class="comment">      }</span>
+<a name="l03050"></a>03050 <span class="comment">    }</span>
+<a name="l03051"></a>03051 <span class="comment">  }</span>
+<a name="l03052"></a>03052 <span class="comment"></span>
+<a name="l03053"></a>03053 <span class="comment">  podata[x+y*olx]=val_msk_sum/msk_sum;</span>
+<a name="l03054"></a>03054 <span class="comment">  cpl_vector_delete(msk);</span>
+<a name="l03055"></a>03055 <span class="comment"></span>
+<a name="l03056"></a>03056 <span class="comment">  return 0;</span>
+<a name="l03057"></a>03057 <span class="comment"></span>
+<a name="l03058"></a>03058 <span class="comment">}</span>
+<a name="l03059"></a>03059 <span class="comment"></span>
+<a name="l03060"></a>03060 <span class="comment">*/</span>
+<a name="l03061"></a>03061 
+<a name="l03111"></a>03111 <span class="keywordtype">int</span>
+<a name="l03112"></a>03112 sinfo_new_combine_jittered_cubes_thomas_range(cpl_imagelist ** cubes,
+<a name="l03113"></a>03113                     cpl_imagelist  * mergedCube,
+<a name="l03114"></a>03114                     cpl_imagelist  * mask,
+<a name="l03115"></a>03115                     <span class="keywordtype">int</span>        n_cubes,
+<a name="l03116"></a>03116                     <span class="keywordtype">float</span>    * cumoffsetx,
+<a name="l03117"></a>03117                     <span class="keywordtype">float</span>    * cumoffsety,
+<a name="l03118"></a>03118                     <span class="keywordtype">double</span>    * exptimes,
+<a name="l03119"></a>03119                     <span class="keywordtype">char</span>     * kernel_type,
+<a name="l03120"></a>03120                     <span class="keyword">const</span> <span class="keywordtype">int</span> z_min,
+<a name="l03121"></a>03121                     <span class="keyword">const</span> <span class="keywordtype">int</span> z_max,
+<a name="l03122"></a>03122                                     <span class="keyword">const</span> <span class="keywordtype">double</span> kappa )
+<a name="l03123"></a>03123 {
+<a name="l03124"></a>03124     <span class="keyword">const</span> <span class="keywordtype">int</span> VERY_BIG_INT = 268431360;
+<a name="l03125"></a>03125   <span class="keywordtype">int</span> i ;
+<a name="l03126"></a>03126   <span class="keywordtype">int</span> llx0, lly0 ;
+<a name="l03127"></a>03127   <span class="keywordtype">int</span>* llx=NULL;
+<a name="l03128"></a>03128   <span class="keywordtype">int</span>* lly=NULL ;
+<a name="l03129"></a>03129   <span class="keywordtype">float</span>* sub_offsetx=NULL ;
+<a name="l03130"></a>03130   <span class="keywordtype">float</span>* sub_offsety=NULL ;
+<a name="l03131"></a>03131   cpl_imagelist ** tmpcubes=NULL ;
+<a name="l03132"></a>03132   <span class="keyword">const</span> <span class="keywordtype">int</span> z_siz=z_max-z_min;
+<a name="l03133"></a>03133   <span class="keywordtype">int</span> ilx=0;
+<a name="l03134"></a>03134   <span class="keywordtype">int</span> ily=0;
+<a name="l03135"></a>03135   <span class="keywordtype">int</span> olx=0;
+<a name="l03136"></a>03136   <span class="keywordtype">int</span> oly=0;
+<a name="l03137"></a>03137   <span class="keywordtype">int</span> mlx=0;
+<a name="l03138"></a>03138   <span class="keywordtype">int</span> mly=0;
+<a name="l03139"></a>03139   <span class="keywordtype">int</span> onp=0;
+<a name="l03140"></a>03140   cpl_image* i_img=NULL;
+<a name="l03141"></a>03141   cpl_image* o_img=NULL;
+<a name="l03142"></a>03142   <span class="keywordtype">int</span> min_lx = VERY_BIG_INT;
+<a name="l03143"></a>03143   <span class="keywordtype">int</span> min_ly = VERY_BIG_INT;
+<a name="l03144"></a>03144 
+<a name="l03145"></a>03145 
+<a name="l03146"></a>03146   <span class="keywordflow">if</span>(sinfo_check_input(cubes,n_cubes,cumoffsetx,cumoffsety,exptimes) == -1) {
+<a name="l03147"></a>03147     <span class="keywordflow">return</span> -1;
+<a name="l03148"></a>03148   }
+<a name="l03149"></a>03149 
+<a name="l03150"></a>03150   <span class="keywordflow">if</span> (z_siz <= 0 ){
+<a name="l03151"></a>03151     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"z_max <= z_min given!"</span>) ;
+<a name="l03152"></a>03152     <span class="keywordflow">return</span> -1 ;
+<a name="l03153"></a>03153   }
+<a name="l03154"></a>03154 
+<a name="l03155"></a>03155   i_img=cpl_imagelist_get(cubes[0],0);
+<a name="l03156"></a>03156   o_img=cpl_imagelist_get(mergedCube,0);
+<a name="l03157"></a>03157   ilx=cpl_image_get_size_x(i_img);
+<a name="l03158"></a>03158   ily=cpl_image_get_size_y(i_img);
+<a name="l03159"></a>03159   olx=cpl_image_get_size_x(o_img);
+<a name="l03160"></a>03160   oly=cpl_image_get_size_y(o_img);
+<a name="l03161"></a>03161   mlx=olx;
+<a name="l03162"></a>03162   mly=oly;
+<a name="l03163"></a>03163 <span class="comment">//  sinfo_msg_warning(" cube size [%d:%d] merged cube size[%d:%d]" , ilx, ily, olx, oly);</span>
+<a name="l03164"></a>03164   <span class="comment">/*--------------------------------------------------------------------</span>
+<a name="l03165"></a>03165 <span class="comment">   * center the cubes within the allocated big cube</span>
+<a name="l03166"></a>03166 <span class="comment">   * that means define the (0,0) positions of the cubes in the image planes</span>
+<a name="l03167"></a>03167 <span class="comment">   * to sub-pixel accuracy by using cumoffsetx,y and the reference cube</span>
+<a name="l03168"></a>03168 <span class="comment">   */</span>
+<a name="l03169"></a>03169   <span class="comment">/* position of first reference frame, centered in big cube */</span>
+<a name="l03170"></a>03170   llx0 = (1.0 * olx- 1.0 * ilx)/2.0 ;
+<a name="l03171"></a>03171   lly0 = (1.0 * oly - 1.0 * ily)/2.0 ;
+<a name="l03172"></a>03172 <span class="comment">//  sinfo_msg_warning(" zero point [%d:%d]" , llx0, lly0);</span>
+<a name="l03173"></a>03173   <span class="comment">/*--------------------------------------------------------------------</span>
+<a name="l03174"></a>03174 <span class="comment">   * go through the frame list and determine the lower left edge position</span>
+<a name="l03175"></a>03175 <span class="comment">   * of the shifted cubes. Additionnally, the sub-pixel offsets are</span>
+<a name="l03176"></a>03176 <span class="comment">   * determined.</span>
+<a name="l03177"></a>03177 <span class="comment">   */</span>
+<a name="l03178"></a>03178 
+<a name="l03179"></a>03179   llx=cpl_calloc(n_cubes,<span class="keyword">sizeof</span>(<span class="keywordtype">int</span>));
+<a name="l03180"></a>03180   lly=cpl_calloc(n_cubes,<span class="keyword">sizeof</span>(<span class="keywordtype">int</span>)) ;
+<a name="l03181"></a>03181   sub_offsetx=cpl_calloc(n_cubes,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l03182"></a>03182   sub_offsety=cpl_calloc(n_cubes,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l03183"></a>03183 
+<a name="l03184"></a>03184   <span class="keywordflow">for</span> ( i = 0 ; i < n_cubes ; i++ ) {
+<a name="l03185"></a>03185     llx[i] = llx0 - sinfo_new_nint(cumoffsetx[i]) ;
+<a name="l03186"></a>03186 
+<a name="l03187"></a>03187     sub_offsetx[i] = (float)sinfo_new_nint(cumoffsetx[i]) - cumoffsetx[i] ;
+<a name="l03188"></a>03188     lly[i] = lly0 - sinfo_new_nint(cumoffsety[i]) ;
+<a name="l03189"></a>03189     sub_offsety[i] = (float)sinfo_new_nint(cumoffsety[i]) - cumoffsety[i] ;
+<a name="l03190"></a>03190 <span class="comment">/*    sinfo_msg_warning("suboff[%d]= %f %f  ll[%d:%d] cumoffset[%f:%f]" ,</span>
+<a name="l03191"></a>03191 <span class="comment">            i,sub_offsetx[i],sub_offsety[i], llx[i], lly[i],</span>
+<a name="l03192"></a>03192 <span class="comment">            cumoffsetx[i], cumoffsety[i]);*/</span>
+<a name="l03193"></a>03193     <span class="keywordflow">if</span> (llx[i] < min_lx)
+<a name="l03194"></a>03194     {
+<a name="l03195"></a>03195         min_lx = llx[i];
+<a name="l03196"></a>03196     }
+<a name="l03197"></a>03197     <span class="keywordflow">if</span> (lly[i] < min_ly)
+<a name="l03198"></a>03198     {
+<a name="l03199"></a>03199         min_ly = lly[i];
+<a name="l03200"></a>03200     }
+<a name="l03201"></a>03201   }
+<a name="l03202"></a>03202   <span class="comment">/***********---------</span>
+<a name="l03203"></a>03203 <span class="comment">   * "normalize" the shift - minimum should be 0</span>
+<a name="l03204"></a>03204 <span class="comment">   **********************************************/</span>
+<a name="l03205"></a>03205   <span class="keywordflow">if</span> (min_lx != 0)
+<a name="l03206"></a>03206   {
+<a name="l03207"></a>03207     <span class="keywordflow">for</span> (i = 0 ; i < n_cubes ; i++ )
+<a name="l03208"></a>03208     {
+<a name="l03209"></a>03209         llx[i] = llx[i] - min_lx;
+<a name="l03210"></a>03210     }
+<a name="l03211"></a>03211   }
+<a name="l03212"></a>03212   <span class="keywordflow">if</span> (min_ly != 0)
+<a name="l03213"></a>03213   {
+<a name="l03214"></a>03214     <span class="keywordflow">for</span> (i = 0 ; i < n_cubes ; i++ )
+<a name="l03215"></a>03215     {
+<a name="l03216"></a>03216         lly[i] = lly[i] - min_ly;
+<a name="l03217"></a>03217     }
+<a name="l03218"></a>03218   }
+<a name="l03219"></a>03219 
+<a name="l03220"></a>03220   <span class="comment">/* -------------------------------------------------------------</span>
+<a name="l03221"></a>03221 <span class="comment">   * shift the cubes according to the computed sub-pixel offsets</span>
+<a name="l03222"></a>03222 <span class="comment">   * that means shift the single image planes of each cube</span>
+<a name="l03223"></a>03223 <span class="comment">   * first determine an interpolation kernel</span>
+<a name="l03224"></a>03224 <span class="comment">   */</span>
+<a name="l03225"></a>03225 
+<a name="l03226"></a>03226   tmpcubes=(cpl_imagelist**)cpl_calloc(n_cubes,<span class="keyword">sizeof</span>(cpl_imagelist*)) ;
+<a name="l03227"></a>03227 
+<a name="l03228"></a>03228   <span class="keywordflow">if</span>(sinfo_shift_cubes(tmpcubes,kernel_type,n_cubes,cubes,z_min, z_max,
+<a name="l03229"></a>03229                sub_offsetx,sub_offsety,mlx,mly,mask) == -1) {
+<a name="l03230"></a>03230     <span class="keywordflow">return</span> -1;
+<a name="l03231"></a>03231 
+<a name="l03232"></a>03232   }
+<a name="l03233"></a>03233 
+<a name="l03234"></a>03234 
+<a name="l03235"></a>03235   <span class="comment">/*-------------------------------------------------------------------------</span>
+<a name="l03236"></a>03236 <span class="comment">   * Build the mask data cube.</span>
+<a name="l03237"></a>03237 <span class="comment">   * The mask is 0 where no data is available, otherwise the integration</span>
+<a name="l03238"></a>03238 <span class="comment">   * time of one frame, respectively the summed integration</span>
+<a name="l03239"></a>03239 <span class="comment">   * times in the overlapping regions are inserted</span>
+<a name="l03240"></a>03240 <span class="comment">   */</span>
+<a name="l03241"></a>03241   <span class="comment">/* go through the frame list */</span>
+<a name="l03242"></a>03242 
+<a name="l03243"></a>03243 
+<a name="l03244"></a>03244   o_img=cpl_imagelist_get(mergedCube,0);
+<a name="l03245"></a>03245   olx=cpl_image_get_size_x(o_img);
+<a name="l03246"></a>03246   oly=cpl_image_get_size_y(o_img);
+<a name="l03247"></a>03247   onp=cpl_imagelist_get_size(mergedCube);
+<a name="l03248"></a>03248 
+<a name="l03249"></a>03249   <span class="keywordflow">if</span>(-1 == sinfo_build_mask_cube_thomas(z_min,z_max,olx,oly,n_cubes,llx,lly,
+<a name="l03250"></a>03250                     exptimes,cubes,tmpcubes,mask) ) {
+<a name="l03251"></a>03251     <span class="keywordflow">return</span> -1;
+<a name="l03252"></a>03252   }
+<a name="l03254"></a>03254 <span class="comment">/*</span>
+<a name="l03255"></a>03255 <span class="comment">  check_nomsg(sinfo_coadd_with_ks_clip_optimized(z_min,z_max,n_cubes,</span>
+<a name="l03256"></a>03256 <span class="comment">                                           kappa,llx,lly,</span>
+<a name="l03257"></a>03257 <span class="comment">                                           exptimes,mask,mergedCube,tmpcubes));</span>
+<a name="l03258"></a>03258 <span class="comment">*/</span>
+<a name="l03261"></a>03261   check_nomsg(sinfo_coadd_with_ks_clip2(z_min,z_max,ilx,ily,n_cubes,kappa,llx,lly,
+<a name="l03262"></a>03262                                         exptimes,mask,mergedCube,tmpcubes));
+<a name="l03263"></a>03263 
+<a name="l03265"></a>03265   <span class="comment">/* convert the "free space" in the cube to blank pixels */</span>
+<a name="l03266"></a>03266   <span class="comment">/* convert_0_to_ZERO_for_cubes(mergedCube) ; */</span>
+<a name="l03267"></a>03267   <span class="comment">/* convert_0_to_ZERO_for_cubes(mergedSky) ; */</span>
+<a name="l03268"></a>03268   <span class="comment">//cpl_free(kernel) ; /* originated by eclise-malloc */</span>
+<a name="l03269"></a>03269 
+<a name="l03270"></a>03270   cleanup:
+<a name="l03271"></a>03271 
+<a name="l03272"></a>03272   <span class="keywordflow">for</span>( i = 0 ; i < n_cubes ; i++ ) {
+<a name="l03273"></a>03273     cpl_imagelist_delete (tmpcubes[i]) ;
+<a name="l03274"></a>03274   }
+<a name="l03275"></a>03275 
+<a name="l03276"></a>03276   cpl_free(tmpcubes);
+<a name="l03277"></a>03277   cpl_free(llx);
+<a name="l03278"></a>03278   cpl_free(lly) ;
+<a name="l03279"></a>03279   cpl_free(sub_offsetx) ;
+<a name="l03280"></a>03280   cpl_free(sub_offsety) ;
+<a name="l03281"></a>03281   sinfo_print_rec_status(0);
+<a name="l03282"></a>03282 
+<a name="l03283"></a>03283   <span class="keywordflow">return</span> 0 ;
+<a name="l03284"></a>03284 }
+<a name="l03285"></a>03285 
+<a name="l03299"></a>03299 cpl_imagelist *
+<a name="l03300"></a>03300 sinfo_new_interpol_cube_simple( cpl_imagelist * cube,
+<a name="l03301"></a>03301                       cpl_imagelist * badcube,
+<a name="l03302"></a>03302                       <span class="keywordtype">int</span>       maxdist )
+<a name="l03303"></a>03303 {
+<a name="l03304"></a>03304   cpl_imagelist * intercube ;
+<a name="l03305"></a>03305   <span class="keywordtype">float</span>*     goodNeighbors=NULL ;
+<a name="l03306"></a>03306   <span class="keywordtype">int</span> z, row, col ;
+<a name="l03307"></a>03307   <span class="keywordtype">int</span> nx, ny, nz ;
+<a name="l03308"></a>03308   <span class="keywordtype">int</span> llx, lly, llz ;
+<a name="l03309"></a>03309   <span class="keywordtype">int</span> zi, coli, rowi ;
+<a name="l03310"></a>03310   <span class="keywordtype">int</span> n ;
+<a name="l03311"></a>03311 
+<a name="l03312"></a>03312 
+<a name="l03313"></a>03313 
+<a name="l03314"></a>03314 
+<a name="l03315"></a>03315   <span class="keywordtype">int</span> clx=0;
+<a name="l03316"></a>03316   <span class="keywordtype">int</span> cly=0;
+<a name="l03317"></a>03317   <span class="keywordtype">int</span> blx=0;
+<a name="l03318"></a>03318   <span class="keywordtype">int</span> bly=0;
+<a name="l03319"></a>03319 
+<a name="l03320"></a>03320   <span class="keywordtype">int</span> cnp=0;
+<a name="l03321"></a>03321 
+<a name="l03322"></a>03322 
+<a name="l03323"></a>03323   <span class="keywordtype">float</span>* pbdata=NULL;
+<a name="l03324"></a>03324   <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l03325"></a>03325   <span class="keywordtype">float</span>* pbzidata=NULL;
+<a name="l03326"></a>03326   <span class="keywordtype">float</span>* pczidata=NULL;
+<a name="l03327"></a>03327 
+<a name="l03328"></a>03328   cpl_image* c_img=NULL;
+<a name="l03329"></a>03329   cpl_image* b_img=NULL;
+<a name="l03330"></a>03330   cpl_image* i_img=NULL;
+<a name="l03331"></a>03331 
+<a name="l03332"></a>03332   cpl_image* bzi_img=NULL;
+<a name="l03333"></a>03333   cpl_image* czi_img=NULL;
+<a name="l03334"></a>03334 
+<a name="l03335"></a>03335 
+<a name="l03336"></a>03336 
+<a name="l03337"></a>03337     <span class="keywordflow">if</span> ( cube == NULL || badcube == NULL )
+<a name="l03338"></a>03338     {
+<a name="l03339"></a>03339         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no cube given!"</span>) ;
+<a name="l03340"></a>03340         <span class="keywordflow">return</span> NULL ;
+<a name="l03341"></a>03341     }
+<a name="l03342"></a>03342     <span class="keywordflow">if</span> ( maxdist < 1 )
+<a name="l03343"></a>03343     {
+<a name="l03344"></a>03344         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"wrong maxrad given!"</span>) ;
+<a name="l03345"></a>03345         <span class="keywordflow">return</span> NULL ;
+<a name="l03346"></a>03346     }
+<a name="l03347"></a>03347     intercube = cpl_imagelist_duplicate(cube) ;
+<a name="l03348"></a>03348 
+<a name="l03349"></a>03349     goodNeighbors=cpl_calloc((2*maxdist+1)*(2*maxdist+1)*(2*maxdist+1) -1,
+<a name="l03350"></a>03350                              <span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l03351"></a>03351 
+<a name="l03352"></a>03352     cnp=cpl_imagelist_get_size(cube);
+<a name="l03353"></a>03353     <span class="keywordflow">for</span> ( z = 0 ; z < cnp ; z++ )
+<a name="l03354"></a>03354     {
+<a name="l03355"></a>03355       b_img=cpl_imagelist_get(badcube,z);
+<a name="l03356"></a>03356       i_img=cpl_imagelist_get(intercube,z);
+<a name="l03357"></a>03357       pbdata=cpl_image_get_data_float(b_img);
+<a name="l03358"></a>03358       pidata=cpl_image_get_data_float(i_img);
+<a name="l03359"></a>03359       blx=cpl_image_get_size_x(b_img);
+<a name="l03360"></a>03360       bly=cpl_image_get_size_y(b_img);
+<a name="l03361"></a>03361 
+<a name="l03362"></a>03362       c_img=cpl_imagelist_get(cube,z);
+<a name="l03363"></a>03363       clx=cpl_image_get_size_x(c_img);
+<a name="l03364"></a>03364       cly=cpl_image_get_size_y(c_img);
+<a name="l03365"></a>03365 
+<a name="l03366"></a>03366         <span class="keywordflow">for</span> ( row = 0 ; row < cly ; row++ )
+<a name="l03367"></a>03367         {
+<a name="l03368"></a>03368             <span class="keywordflow">for</span> ( col = 0 ; col < clx ; col++ )
+<a name="l03369"></a>03369             {
+<a name="l03370"></a>03370                 <span class="keywordflow">if</span> ( pbdata[col+row*clx] == 0 )
+<a name="l03371"></a>03371                 {
+<a name="l03372"></a>03372                     <span class="comment">/* determine the lower left sinfo_edge of the cube */</span>
+<a name="l03373"></a>03373                     llx = col - maxdist ;
+<a name="l03374"></a>03374                     nx = 2*maxdist +1 ;
+<a name="l03375"></a>03375                     <span class="keywordflow">if</span> (llx < 0)
+<a name="l03376"></a>03376                     {
+<a name="l03377"></a>03377                        nx += llx ;
+<a name="l03378"></a>03378                        llx = 0 ;
+<a name="l03379"></a>03379                     }
+<a name="l03380"></a>03380                     <span class="keywordflow">if</span> ( llx + nx > clx )
+<a name="l03381"></a>03381                     {
+<a name="l03382"></a>03382                         nx -= (llx + nx - clx) ;
+<a name="l03383"></a>03383                     }
+<a name="l03384"></a>03384 
+<a name="l03385"></a>03385                     lly = row - maxdist ;
+<a name="l03386"></a>03386                     ny = 2*maxdist +1 ;
+<a name="l03387"></a>03387                     <span class="keywordflow">if</span> (lly < 0)
+<a name="l03388"></a>03388                     {
+<a name="l03389"></a>03389                        ny += lly ;
+<a name="l03390"></a>03390                        lly = 0 ;
+<a name="l03391"></a>03391                     }
+<a name="l03392"></a>03392                     <span class="keywordflow">if</span> ( lly + ny > cly )
+<a name="l03393"></a>03393                     {
+<a name="l03394"></a>03394                         ny -= (lly + ny - cly) ;
+<a name="l03395"></a>03395                     }
+<a name="l03396"></a>03396 
+<a name="l03397"></a>03397                     llz = z - maxdist ;
+<a name="l03398"></a>03398                     nz = 2*maxdist +1 ;
+<a name="l03399"></a>03399                     <span class="keywordflow">if</span> (llz < 0)
+<a name="l03400"></a>03400                     {
+<a name="l03401"></a>03401                        nz += llz ;
+<a name="l03402"></a>03402                        llz = 0 ;
+<a name="l03403"></a>03403                     }
+<a name="l03404"></a>03404                     <span class="keywordflow">if</span> ( llz + nz > cnp )
+<a name="l03405"></a>03405                     {
+<a name="l03406"></a>03406                         nz -= (llz + nz - cnp) ;
+<a name="l03407"></a>03407                     }
+<a name="l03408"></a>03408                     n = 0 ;
+<a name="l03409"></a>03409                     <span class="keywordflow">for</span> ( zi = llz ; zi < llz+nz ; zi++ )
+<a name="l03410"></a>03410                     {
+<a name="l03411"></a>03411               bzi_img=cpl_imagelist_get(badcube,zi);
+<a name="l03412"></a>03412               czi_img=cpl_imagelist_get(cube,zi);
+<a name="l03413"></a>03413                       pbzidata=cpl_image_get_data_float(bzi_img);
+<a name="l03414"></a>03414                       pczidata=cpl_image_get_data_float(czi_img);
+<a name="l03415"></a>03415 
+<a name="l03416"></a>03416                         <span class="keywordflow">for</span> ( rowi = lly ; rowi < lly+ny ; rowi++ )
+<a name="l03417"></a>03417                         {
+<a name="l03418"></a>03418                             <span class="keywordflow">for</span> ( coli = llx ; coli < llx+nx ; coli++ )
+<a name="l03419"></a>03419                             {
+<a name="l03420"></a>03420                                 <span class="keywordflow">if</span> ( pbzidata[coli+rowi*blx] == 1 )
+<a name="l03421"></a>03421                                 {
+<a name="l03422"></a>03422                   goodNeighbors[n] = pczidata[coli+rowi*clx] ;
+<a name="l03423"></a>03423                   n++ ;
+<a name="l03424"></a>03424                                 }
+<a name="l03425"></a>03425                             }
+<a name="l03426"></a>03426                         }
+<a name="l03427"></a>03427                     }
+<a name="l03428"></a>03428                     <span class="keywordflow">if</span> ( n > 0 )
+<a name="l03429"></a>03429                     {
+<a name="l03430"></a>03430                         pidata[col+row*clx]=sinfo_new_median(goodNeighbors,n);
+<a name="l03431"></a>03431                         pbdata[col+row*clx]=1 ;
+<a name="l03432"></a>03432                     }
+<a name="l03433"></a>03433                     <span class="keywordflow">else</span>
+<a name="l03434"></a>03434                     {
+<a name="l03435"></a>03435                         continue ;
+<a name="l03436"></a>03436                     }
+<a name="l03437"></a>03437                 }
+<a name="l03438"></a>03438             }
+<a name="l03439"></a>03439         }
+<a name="l03440"></a>03440     }
+<a name="l03441"></a>03441     cpl_free(goodNeighbors) ;
+<a name="l03442"></a>03442     <span class="keywordflow">return</span> intercube ;
+<a name="l03443"></a>03443 }
+<a name="l03444"></a>03444 
+<a name="l03445"></a>03445 
+<a name="l03446"></a>03446 
+<a name="l03447"></a>03447 
+<a name="l03448"></a>03448 
+<a name="l03501"></a>03501 cpl_imagelist *
+<a name="l03502"></a>03502 sinfo_new_combine_cubes ( cpl_imagelist ** cubes,
+<a name="l03503"></a>03503                          cpl_imagelist  * mergedCube,
+<a name="l03504"></a>03504                          <span class="keywordtype">int</span>        n_cubes,
+<a name="l03505"></a>03505                          <span class="keywordtype">float</span>    * cumoffsetx,
+<a name="l03506"></a>03506                          <span class="keywordtype">float</span>    * cumoffsety,
+<a name="l03507"></a>03507                          <span class="keywordtype">float</span>      factor,
+<a name="l03508"></a>03508                          <span class="keywordtype">char</span>     * kernel_type )
+<a name="l03509"></a>03509 {
+<a name="l03510"></a>03510   <span class="keywordtype">int</span> i=0 ;
+<a name="l03511"></a>03511   <span class="keywordtype">int</span> x=0;
+<a name="l03512"></a>03512   <span class="keywordtype">int</span> y=0;
+<a name="l03513"></a>03513   <span class="keywordtype">int</span> z=0;
+<a name="l03514"></a>03514   <span class="keywordtype">int</span> llx0=0;
+<a name="l03515"></a>03515   <span class="keywordtype">int</span> lly0=0;
+<a name="l03516"></a>03516   <span class="keywordtype">int</span> posx=0;
+<a name="l03517"></a>03517   <span class="keywordtype">int</span> posy=0;
+<a name="l03518"></a>03518   cpl_imagelist * mask=NULL ;
+<a name="l03519"></a>03519   <span class="keywordtype">double</span> * kernel=NULL ;
+<a name="l03520"></a>03520   cpl_image * shiftedImage=NULL ;
+<a name="l03521"></a>03521   <span class="keywordtype">int</span> n=0;
+<a name="l03522"></a>03522   <span class="keywordtype">int</span> ns=0;
+<a name="l03523"></a>03523   <span class="keywordtype">double</span> sum=0;
+<a name="l03524"></a>03524   <span class="keywordtype">double</span> sum2=0;
+<a name="l03525"></a>03525   <span class="keywordtype">double</span> mean=0;
+<a name="l03526"></a>03526   <span class="keywordtype">double</span> sigma=0;
+<a name="l03527"></a>03527 
+<a name="l03528"></a>03528   cpl_imagelist ** tmpcubes=NULL ;
+<a name="l03529"></a>03529 
+<a name="l03530"></a>03530   <span class="keywordtype">int</span>* llx=NULL ;
+<a name="l03531"></a>03531   <span class="keywordtype">int</span>* lly=NULL ;
+<a name="l03532"></a>03532 
+<a name="l03533"></a>03533   <span class="keywordtype">float</span>* sub_offsetx=NULL ;
+<a name="l03534"></a>03534   <span class="keywordtype">float</span>* sub_offsety=NULL ;
+<a name="l03535"></a>03535   <span class="keywordtype">float</span>* cubedata=NULL ;
+<a name="l03536"></a>03536 
+<a name="l03537"></a>03537   <span class="keywordtype">int</span> mlx=0;
+<a name="l03538"></a>03538   <span class="keywordtype">int</span> mly=0;
+<a name="l03539"></a>03539   <span class="keywordtype">int</span> clx=0;
+<a name="l03540"></a>03540   <span class="keywordtype">int</span> cly=0;
+<a name="l03541"></a>03541   <span class="keywordtype">int</span> mnp=0;
+<a name="l03542"></a>03542   <span class="keywordtype">int</span> cnp=0;
+<a name="l03543"></a>03543 
+<a name="l03544"></a>03544 
+<a name="l03545"></a>03545   <span class="keywordtype">float</span>* ptdata=NULL;
+<a name="l03546"></a>03546   <span class="keywordtype">float</span>* podata=NULL;
+<a name="l03547"></a>03547   <span class="keywordtype">float</span>* pmdata=NULL;
+<a name="l03548"></a>03548 
+<a name="l03549"></a>03549   cpl_image* tmp_img=NULL;
+<a name="l03550"></a>03550   cpl_image* o_img=NULL;
+<a name="l03551"></a>03551   cpl_image* m_img=NULL;
+<a name="l03552"></a>03552   cpl_image* c_img=NULL;
+<a name="l03553"></a>03553   cpl_image* t_img=NULL;
+<a name="l03554"></a>03554 
+<a name="l03555"></a>03555 
+<a name="l03556"></a>03556 
+<a name="l03557"></a>03557 
+<a name="l03558"></a>03558   <span class="keywordflow">if</span> ( cubes == NULL )
+<a name="l03559"></a>03559     {
+<a name="l03560"></a>03560         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"no cube list given!"</span>) ;
+<a name="l03561"></a>03561         <span class="keywordflow">return</span> NULL ;
+<a name="l03562"></a>03562     }
+<a name="l03563"></a>03563 
+<a name="l03564"></a>03564 
+<a name="l03565"></a>03565   <span class="keywordflow">if</span> ( mergedCube == NULL )
+<a name="l03566"></a>03566     {
+<a name="l03567"></a>03567         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"no out cube  given!"</span>) ;
+<a name="l03568"></a>03568         <span class="keywordflow">return</span> NULL ;
+<a name="l03569"></a>03569     }
+<a name="l03570"></a>03570 
+<a name="l03571"></a>03571 
+<a name="l03572"></a>03572     <span class="keywordflow">if</span> ( n_cubes <= 0 )
+<a name="l03573"></a>03573     {
+<a name="l03574"></a>03574         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"wrong number of data cubes in list!"</span>) ;
+<a name="l03575"></a>03575         <span class="keywordflow">return</span> NULL ;
+<a name="l03576"></a>03576     }
+<a name="l03577"></a>03577     <span class="keywordflow">if</span> ( cumoffsetx == NULL || cumoffsety == NULL )
+<a name="l03578"></a>03578     {
+<a name="l03579"></a>03579         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"no cumoffsetx/y given!"</span>) ;
+<a name="l03580"></a>03580         <span class="keywordflow">return</span> NULL;
+<a name="l03581"></a>03581     }
+<a name="l03582"></a>03582 
+<a name="l03583"></a>03583   <span class="keywordflow">if</span> ( factor <= 0. )
+<a name="l03584"></a>03584     {
+<a name="l03585"></a>03585         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"wrong factor given!"</span>) ;
+<a name="l03586"></a>03586         <span class="keywordflow">return</span> NULL ;
+<a name="l03587"></a>03587     }
+<a name="l03588"></a>03588 
+<a name="l03589"></a>03589   m_img=cpl_imagelist_get(mergedCube,0);
+<a name="l03590"></a>03590   mlx=cpl_image_get_size_x(m_img);
+<a name="l03591"></a>03591   mly=cpl_image_get_size_y(m_img);
+<a name="l03592"></a>03592   cnp=cpl_imagelist_get_size(cubes[0]);
+<a name="l03593"></a>03593   c_img=cpl_imagelist_get(cubes[0],0);
+<a name="l03594"></a>03594   clx=cpl_image_get_size_x(c_img);
+<a name="l03595"></a>03595   cly=cpl_image_get_size_y(c_img);
+<a name="l03596"></a>03596 
+<a name="l03597"></a>03597 
+<a name="l03598"></a>03598   tmpcubes=(cpl_imagelist**)cpl_calloc(n_cubes,<span class="keyword">sizeof</span>(cpl_imagelist*)) ;
+<a name="l03599"></a>03599 
+<a name="l03600"></a>03600         <span class="comment">/* allocation for a cube structure without the image planes  */</span>
+<a name="l03601"></a>03601     <span class="comment">/*</span>
+<a name="l03602"></a>03602 <span class="comment">   for ( i = 0 ; i < n_cubes ; i++ )</span>
+<a name="l03603"></a>03603 <span class="comment">    {</span>
+<a name="l03604"></a>03604 <span class="comment">         tmpcubes[i] = (cpl_imagelist*)cpl_malloc(sizeof(cpl_imagelist)) ;</span>
+<a name="l03605"></a>03605 <span class="comment">        tmpcubes[i]->plane = (cpl_image**)cpl_calloc(cubes[0]->np ,</span>
+<a name="l03606"></a>03606 <span class="comment">                              sizeof(cpl_image*)) ;</span>
+<a name="l03607"></a>03607 <span class="comment"></span>
+<a name="l03608"></a>03608 <span class="comment">        tmpcubes[i]->lx = cubes[0]->lx ;</span>
+<a name="l03609"></a>03609 <span class="comment">        tmpcubes[i]->ly = cubes[0]->ly ;</span>
+<a name="l03610"></a>03610 <span class="comment">        tmpcubes[i]->np = cubes[0]->np ;</span>
+<a name="l03611"></a>03611 <span class="comment">        tmpcubes[i]->nbpix = (ulong32)cubes[0]->lx *</span>
+<a name="l03612"></a>03612 <span class="comment">                             (ulong32)cubes[0]->ly *</span>
+<a name="l03613"></a>03613 <span class="comment">                             (ulong32)cubes[0]->np ;</span>
+<a name="l03614"></a>03614 <span class="comment">        tmpcubes[i]->history = (char*)NULL ;</span>
+<a name="l03615"></a>03615 <span class="comment">        tmpcubes[i]->n_comments = 0 ;</span>
+<a name="l03616"></a>03616 <span class="comment">        tmpcubes[i]->orig_ptype = BPP_DEFAULT ;</span>
+<a name="l03617"></a>03617 <span class="comment">        tmpcubes[i]->filename = NULL ;</span>
+<a name="l03618"></a>03618 <span class="comment">    }</span>
+<a name="l03619"></a>03619 <span class="comment">    */</span>
+<a name="l03620"></a>03620     tmpcubes[0]=cpl_imagelist_duplicate(cubes[0]);
+<a name="l03621"></a>03621 
+<a name="l03622"></a>03622     <span class="comment">/*--------------------------------------------------------------------</span>
+<a name="l03623"></a>03623 <span class="comment">     * center the cubes within the allocated big cube</span>
+<a name="l03624"></a>03624 <span class="comment">     * that means define the (0,0) positions of the cubes in the image planes</span>
+<a name="l03625"></a>03625 <span class="comment">     * to sub-pixel accuracy by using cumoffsetx,y and the reference cube</span>
+<a name="l03626"></a>03626 <span class="comment">     */</span>
+<a name="l03627"></a>03627     <span class="comment">/* position of first reference frame, centered in big cube */</span>
+<a name="l03628"></a>03628     llx0 = mlx/2 - clx/2 ;
+<a name="l03629"></a>03629     lly0 = mly/2 - cly/2 ;
+<a name="l03630"></a>03630 
+<a name="l03631"></a>03631     <span class="comment">/*--------------------------------------------------------------------</span>
+<a name="l03632"></a>03632 <span class="comment">     * go through the frame list and determine the lower left edge position</span>
+<a name="l03633"></a>03633 <span class="comment">     * of the shifted cubes. Additionnally, the sub-pixel offsets are</span>
+<a name="l03634"></a>03634 <span class="comment">     * determined.</span>
+<a name="l03635"></a>03635 <span class="comment">     */</span>
+<a name="l03636"></a>03636 
+<a name="l03637"></a>03637 
+<a name="l03638"></a>03638     llx=cpl_calloc(n_cubes,<span class="keyword">sizeof</span>(<span class="keywordtype">int</span>)) ;
+<a name="l03639"></a>03639     lly=cpl_calloc(n_cubes,<span class="keyword">sizeof</span>(<span class="keywordtype">int</span>)) ;
+<a name="l03640"></a>03640     sub_offsetx=cpl_calloc(n_cubes,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l03641"></a>03641     sub_offsety=cpl_calloc(n_cubes,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l03642"></a>03642 
+<a name="l03643"></a>03643     <span class="keywordflow">for</span> ( i = 0 ; i < n_cubes ; i++ )
+<a name="l03644"></a>03644     {
+<a name="l03645"></a>03645         llx[i] = llx0 - sinfo_new_nint(cumoffsetx[i]) ;
+<a name="l03646"></a>03646         sub_offsetx[i] = (float)sinfo_new_nint(cumoffsetx[i]) - cumoffsetx[i] ;
+<a name="l03647"></a>03647         lly[i] = lly0 - sinfo_new_nint(cumoffsety[i]) ;
+<a name="l03648"></a>03648         sub_offsety[i] = (float)sinfo_new_nint(cumoffsety[i]) - cumoffsety[i] ;
+<a name="l03649"></a>03649     }
+<a name="l03650"></a>03650 
+<a name="l03651"></a>03651     <span class="comment">/* -------------------------------------------------------------</span>
+<a name="l03652"></a>03652 <span class="comment">     * shift the cubes according to the computed sub-pixel offsets</span>
+<a name="l03653"></a>03653 <span class="comment">     * that means shift the single image planes of each cube</span>
+<a name="l03654"></a>03654 <span class="comment">     * first determine an interpolation kernel</span>
+<a name="l03655"></a>03655 <span class="comment">     */</span>
+<a name="l03656"></a>03656     <span class="keywordflow">if</span> ( NULL == (kernel = sinfo_generate_interpolation_kernel(kernel_type)) )
+<a name="l03657"></a>03657     {
+<a name="l03658"></a>03658         <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a> (<span class="stringliteral">"could not generate desired interpolation kernel"</span>
+<a name="l03659"></a>03659                            <span class="stringliteral">" or no kernel_typ was given, the default kernel"</span>
+<a name="l03660"></a>03660                            <span class="stringliteral">" is used now!"</span>) ;
+<a name="l03661"></a>03661     }
+<a name="l03662"></a>03662     <span class="comment">/* go through the frame list */</span>
+<a name="l03663"></a>03663     <span class="keywordflow">for</span> ( i = 0 ; i < n_cubes ; i++ )
+<a name="l03664"></a>03664     {
+<a name="l03665"></a>03665       <span class="comment">/* go through the image planes and shift each plane by a</span>
+<a name="l03666"></a>03666 <span class="comment">         sub-pixel value */</span>
+<a name="l03667"></a>03667       <span class="keywordflow">for</span> ( z = 0 ; z < cnp ; z++ )
+<a name="l03668"></a>03668         {
+<a name="l03669"></a>03669       tmp_img=cpl_imagelist_get(cubes[i],z);
+<a name="l03670"></a>03670       <span class="keywordflow">if</span> ( NULL == (shiftedImage = sinfo_new_shift_image(tmp_img,
+<a name="l03671"></a>03671                                sub_offsetx[i],
+<a name="l03672"></a>03672                                sub_offsety[i],
+<a name="l03673"></a>03673                                kernel ) ) )
+<a name="l03674"></a>03674             {
+<a name="l03675"></a>03675           <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"could not shift image plane no %d "</span>
+<a name="l03676"></a>03676                                <span class="stringliteral">"in cube no %d!"</span>, z, i) ;
+<a name="l03677"></a>03677           cpl_imagelist_delete(mergedCube) ;
+<a name="l03678"></a>03678           cpl_imagelist_delete(mask) ;
+<a name="l03679"></a>03679           cpl_free(kernel) ;
+<a name="l03680"></a>03680           <span class="keywordflow">return</span> NULL ;
+<a name="l03681"></a>03681             }
+<a name="l03682"></a>03682       cpl_imagelist_set(tmpcubes[i],shiftedImage,z);
+<a name="l03683"></a>03683         }
+<a name="l03684"></a>03684     }
+<a name="l03685"></a>03685 
+<a name="l03686"></a>03686     cubedata=cpl_calloc(n_cubes,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l03687"></a>03687 
+<a name="l03688"></a>03688     <span class="keywordflow">for</span> ( y = 0 ; y < mly ; y++ )
+<a name="l03689"></a>03689     {
+<a name="l03690"></a>03690         <span class="keywordflow">for</span> ( x = 0 ; x < mlx ; x++ )
+<a name="l03691"></a>03691         {
+<a name="l03692"></a>03692             <span class="keywordflow">for</span> ( z = 0 ; z < mnp ; z++ )
+<a name="l03693"></a>03693             {
+<a name="l03694"></a>03694                 sum = 0. ;
+<a name="l03695"></a>03695                 sum2 = 0. ;
+<a name="l03696"></a>03696                 n = 0 ;
+<a name="l03697"></a>03697                 <span class="keywordflow">for</span> ( i = 0 ; i < n_cubes ; i++ )
+<a name="l03698"></a>03698                 {
+<a name="l03699"></a>03699           c_img=cpl_imagelist_get(cubes[i],z);
+<a name="l03700"></a>03700 
+<a name="l03701"></a>03701           clx=cpl_image_get_size_x(c_img);
+<a name="l03702"></a>03702           cly=cpl_image_get_size_y(c_img);
+<a name="l03703"></a>03703 
+<a name="l03704"></a>03704           t_img=cpl_imagelist_get(tmpcubes[i],z);
+<a name="l03705"></a>03705                   ptdata=cpl_image_get_data_float(t_img);
+<a name="l03706"></a>03706 
+<a name="l03707"></a>03707           m_img=cpl_imagelist_get(mergedCube,z);
+<a name="l03708"></a>03708                   pmdata=cpl_image_get_data_float(m_img);
+<a name="l03709"></a>03709           o_img=cpl_imagelist_get(mask,z);
+<a name="l03710"></a>03710                   podata=cpl_image_get_data_float(o_img);
+<a name="l03711"></a>03711                   <span class="comment">/*</span>
+<a name="l03712"></a>03712 <span class="comment">                    find the position of the present cube and go</span>
+<a name="l03713"></a>03713 <span class="comment">                    through the single spectra</span>
+<a name="l03714"></a>03714 <span class="comment">                   */</span>
+<a name="l03715"></a>03715                     <span class="keywordflow">if</span> ( y >= lly[i] && y < lly[i]+cly &&
+<a name="l03716"></a>03716                          x >= llx[i] && x < llx[i]+clx )
+<a name="l03717"></a>03717                     {
+<a name="l03718"></a>03718                         posx = x - llx[i] ;
+<a name="l03719"></a>03719                         posy = y - lly[i] ;
+<a name="l03720"></a>03720                         <span class="keywordflow">if</span> (!isnan(ptdata[posx+posy*clx]))
+<a name="l03721"></a>03721                         {
+<a name="l03722"></a>03722                             sum += ptdata[posx+posy*clx] ;
+<a name="l03723"></a>03723                             sum2 += (ptdata[posx+posy*clx] *
+<a name="l03724"></a>03724                                      ptdata[posx+posy*clx]) ;
+<a name="l03725"></a>03725                             cubedata[n] = ptdata[posx+posy*clx] ;
+<a name="l03726"></a>03726                             n++ ;
+<a name="l03727"></a>03727                         }
+<a name="l03728"></a>03728                     }
+<a name="l03729"></a>03729                 }
+<a name="l03730"></a>03730 
+<a name="l03731"></a>03731                 <span class="keywordflow">if</span> ( n == 0 )
+<a name="l03732"></a>03732                 {
+<a name="l03733"></a>03733                     mean = 0. ;
+<a name="l03734"></a>03734                     sigma = 0. ;
+<a name="l03735"></a>03735                     pmdata[x+y*mlx] = 0. ;
+<a name="l03736"></a>03736                     podata[x+y*mlx] = 0 ;
+<a name="l03737"></a>03737                 }
+<a name="l03738"></a>03738                 <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( n == 1 )
+<a name="l03739"></a>03739                 {
+<a name="l03740"></a>03740                     mean = sum ;
+<a name="l03741"></a>03741                     sigma = 0. ;
+<a name="l03742"></a>03742                     pmdata[x+y*mlx] = mean ;
+<a name="l03743"></a>03743                     podata[x+y*mlx] = 1 ;
+<a name="l03744"></a>03744                 }
+<a name="l03745"></a>03745                 <span class="keywordflow">else</span>
+<a name="l03746"></a>03746                 {
+<a name="l03747"></a>03747                     mean = sum/(double)n ;
+<a name="l03748"></a>03748                     sigma = sqrt( (sum2 - sum*mean) / (<span class="keywordtype">double</span>)(n - 1) ) ;
+<a name="l03749"></a>03749                     ns = 0 ;
+<a name="l03750"></a>03750                     <span class="keywordflow">for</span> ( i = 0 ; i < n ; i++ )
+<a name="l03751"></a>03751                     {
+<a name="l03752"></a>03752                         <span class="keywordflow">if</span> ( cubedata[i] > mean+factor*sigma ||
+<a name="l03753"></a>03753                              cubedata[i] < mean-factor*sigma )
+<a name="l03754"></a>03754                         {
+<a name="l03755"></a>03755                             continue ;
+<a name="l03756"></a>03756                         }
+<a name="l03757"></a>03757                         <span class="keywordflow">else</span>
+<a name="l03758"></a>03758                         {
+<a name="l03759"></a>03759                             pmdata[x+y*mlx] += cubedata[i] ;
+<a name="l03760"></a>03760                             ns++ ;
+<a name="l03761"></a>03761                         }
+<a name="l03762"></a>03762                     }
+<a name="l03763"></a>03763                     <span class="keywordflow">if</span> ( ns == 0 )
+<a name="l03764"></a>03764                     {
+<a name="l03765"></a>03765                         pmdata[x+y*mlx] = 0. ;
+<a name="l03766"></a>03766                     }
+<a name="l03767"></a>03767                     <span class="keywordflow">else</span>
+<a name="l03768"></a>03768                     {
+<a name="l03769"></a>03769                         pmdata[x+y*mlx] /= (float)ns ;
+<a name="l03770"></a>03770                     }
+<a name="l03771"></a>03771                     podata[x+y*mlx] = (float)ns ;
+<a name="l03772"></a>03772                 }
+<a name="l03773"></a>03773             }
+<a name="l03774"></a>03774         }
+<a name="l03775"></a>03775     }
+<a name="l03776"></a>03776 
+<a name="l03777"></a>03777     <span class="keywordflow">for</span>( i = 0 ; i < n_cubes ; i++ )
+<a name="l03778"></a>03778     {
+<a name="l03779"></a>03779         cpl_imagelist_delete (tmpcubes[i]) ;
+<a name="l03780"></a>03780     }
+<a name="l03781"></a>03781     cpl_free(tmpcubes);
+<a name="l03782"></a>03782     cpl_free(llx);
+<a name="l03783"></a>03783     cpl_free(lly);
+<a name="l03784"></a>03784     cpl_free(sub_offsetx);
+<a name="l03785"></a>03785     cpl_free(sub_offsety);
+<a name="l03786"></a>03786     cpl_free(cubedata);
+<a name="l03787"></a>03787 
+<a name="l03788"></a>03788     <span class="comment">/* convert the "free space" in the cube to blank pixels */</span>
+<a name="l03789"></a>03789     sinfo_new_convert_0_to_ZERO_for_cubes(mergedCube) ;
+<a name="l03790"></a>03790     cpl_free(kernel) ;
+<a name="l03791"></a>03791     <span class="keywordflow">return</span> mask ;
+<a name="l03792"></a>03792 }
+<a name="l03793"></a>03793 
+<a name="l03794"></a>03794 cpl_imagelist *
+<a name="l03795"></a>03795 sinfo_new_bin_cube(cpl_imagelist *cu,
+<a name="l03796"></a>03796                              <span class="keywordtype">int</span> xscale,
+<a name="l03797"></a>03797                              <span class="keywordtype">int</span> yscale,
+<a name="l03798"></a>03798                              <span class="keywordtype">int</span> xmin,
+<a name="l03799"></a>03799                              <span class="keywordtype">int</span> xmax,
+<a name="l03800"></a>03800                              <span class="keywordtype">int</span> ymin,
+<a name="l03801"></a>03801                              <span class="keywordtype">int</span> ymax)
+<a name="l03802"></a>03802 {
+<a name="l03803"></a>03803   <span class="keywordtype">int</span> i,j,k;
+<a name="l03804"></a>03804   cpl_imagelist * cube;
+<a name="l03805"></a>03805   <span class="keywordtype">int</span> ilx=0;
+<a name="l03806"></a>03806   <span class="keywordtype">int</span> ily=0;
+<a name="l03807"></a>03807   <span class="keywordtype">int</span> olx=0;
+<a name="l03808"></a>03808   <span class="keywordtype">int</span> oly=0;
+<a name="l03809"></a>03809   <span class="keywordtype">int</span> inp=0;
+<a name="l03810"></a>03810 
+<a name="l03811"></a>03811   <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l03812"></a>03812   <span class="keywordtype">float</span>* podata=NULL;
+<a name="l03813"></a>03813   cpl_image* i_img=NULL;
+<a name="l03814"></a>03814   cpl_image* o_img=NULL;
+<a name="l03815"></a>03815 
+<a name="l03816"></a>03816 
+<a name="l03817"></a>03817   <span class="comment">/* old code</span>
+<a name="l03818"></a>03818 <span class="comment">  if (NULL == (cube = sinfo_newCube (xmax-xmin+1,ymax-ymin+1, cu->np)) )</span>
+<a name="l03819"></a>03819 <span class="comment">  {</span>
+<a name="l03820"></a>03820 <span class="comment">      sinfo_msg_error ("cannot allocate new cube") ;</span>
+<a name="l03821"></a>03821 <span class="comment">      return NULL ;</span>
+<a name="l03822"></a>03822 <span class="comment">  }</span>
+<a name="l03823"></a>03823 <span class="comment">  */</span>
+<a name="l03824"></a>03824   inp=cpl_imagelist_get_size(cu);
+<a name="l03825"></a>03825   i_img=cpl_imagelist_get(cu,0);
+<a name="l03826"></a>03826   ilx=cpl_image_get_size_x(i_img);
+<a name="l03827"></a>03827   ily=cpl_image_get_size_y(i_img);
+<a name="l03828"></a>03828   olx=xmax-xmin+1;
+<a name="l03829"></a>03829   oly=ymax-ymin+1;
+<a name="l03830"></a>03830 
+<a name="l03831"></a>03831 
+<a name="l03832"></a>03832   cube=cpl_imagelist_new();
+<a name="l03833"></a>03833   <span class="keywordflow">for</span> ( i = 0 ; i < inp ; i++ ) {
+<a name="l03834"></a>03834     o_img = cpl_image_new(olx,oly,CPL_TYPE_FLOAT);
+<a name="l03835"></a>03835     cpl_imagelist_set(cube,o_img,i);
+<a name="l03836"></a>03836   }
+<a name="l03837"></a>03837 
+<a name="l03838"></a>03838 
+<a name="l03839"></a>03839   <span class="keywordflow">for</span> (i=0;i<inp;i++){
+<a name="l03840"></a>03840       i_img=cpl_imagelist_get(cu,i);
+<a name="l03841"></a>03841       pidata=cpl_image_get_data_float(i_img);
+<a name="l03842"></a>03842       o_img=cpl_imagelist_get(cube,i);
+<a name="l03843"></a>03843       podata=cpl_image_get_data_float(o_img);
+<a name="l03844"></a>03844       <span class="keywordflow">for</span> (j=0 ; j < olx ; j++) {
+<a name="l03845"></a>03845           <span class="keywordflow">for</span> (k=0 ; k< oly ; k++) {
+<a name="l03846"></a>03846           podata[j+k*olx]=pidata[((int) (j+xmin)/xscale)+
+<a name="l03847"></a>03847                                      ((<span class="keywordtype">int</span>) (k+ymin)/yscale)*ilx]/
+<a name="l03848"></a>03848                                        (xscale*yscale);
+<a name="l03849"></a>03849       }
+<a name="l03850"></a>03850       }
+<a name="l03851"></a>03851   }
+<a name="l03852"></a>03852 
+<a name="l03853"></a>03853   <span class="keywordflow">return</span> cube;
+<a name="l03854"></a>03854 }
+<a name="l03855"></a>03855 
+<a name="l03856"></a>03856 
+<a name="l03857"></a>03857 cpl_imagelist *
+<a name="l03858"></a>03858 sinfo_new_scale_cube(cpl_imagelist *cu,
+<a name="l03859"></a>03859                                <span class="keywordtype">float</span> xscale,
+<a name="l03860"></a>03860                                <span class="keywordtype">float</span> yscale,
+<a name="l03861"></a>03861                                <span class="keywordtype">char</span> * kernel_type)
+<a name="l03862"></a>03862 {
+<a name="l03863"></a>03863     cpl_imagelist    *    cube ;
+<a name="l03864"></a>03864     <span class="keywordtype">int</span>             i, j, k, l ;
+<a name="l03865"></a>03865     <span class="keywordtype">int</span>             lx_out, ly_out ;
+<a name="l03866"></a>03866     <span class="keywordtype">double</span>           cur ;
+<a name="l03867"></a>03867     <span class="keywordtype">double</span>      *    invert_transform ;
+<a name="l03868"></a>03868     <span class="keywordtype">double</span>           neighbors[16] ;
+<a name="l03869"></a>03869     <span class="keywordtype">double</span>           rsc[8],
+<a name="l03870"></a>03870                     sumrs ;
+<a name="l03871"></a>03871     <span class="keywordtype">double</span>        param[6];
+<a name="l03872"></a>03872     <span class="keywordtype">double</span>           x, y ;
+<a name="l03873"></a>03873     <span class="keywordtype">int</span>             px, py ;
+<a name="l03874"></a>03874     <span class="keywordtype">int</span>             pos ;
+<a name="l03875"></a>03875     <span class="keywordtype">int</span>             tabx, taby ;
+<a name="l03876"></a>03876     <span class="keywordtype">double</span>      *    kernel ;
+<a name="l03877"></a>03877     <span class="keywordtype">int</span>                  leaps[16] ;
+<a name="l03878"></a>03878     <span class="keywordtype">int</span>                 ilx=0;
+<a name="l03879"></a>03879     <span class="keywordtype">int</span>                 ily=0;
+<a name="l03880"></a>03880     <span class="keywordtype">int</span>                 tlx=0;
+<a name="l03881"></a>03881     <span class="keywordtype">int</span>                 tly=0;
+<a name="l03882"></a>03882     <span class="keywordtype">int</span>                 inp;
+<a name="l03883"></a>03883     <span class="keywordtype">float</span>*              podata=0;
+<a name="l03884"></a>03884     cpl_image*          in_img=NULL;
+<a name="l03885"></a>03885     cpl_image*          ou_img=NULL;
+<a name="l03886"></a>03886 
+<a name="l03887"></a>03887 
+<a name="l03888"></a>03888     <span class="keywordflow">if</span> (cu == NULL)
+<a name="l03889"></a>03889     {
+<a name="l03890"></a>03890         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"null cube"</span>) ;
+<a name="l03891"></a>03891         <span class="keywordflow">return</span> NULL ;
+<a name="l03892"></a>03892     }
+<a name="l03893"></a>03893 
+<a name="l03894"></a>03894     param[0]=xscale;
+<a name="l03895"></a>03895     param[1]=0;
+<a name="l03896"></a>03896     param[2]=0;
+<a name="l03897"></a>03897     param[3]=0;
+<a name="l03898"></a>03898     param[4]=yscale;
+<a name="l03899"></a>03899     param[5]=0;
+<a name="l03900"></a>03900 
+<a name="l03901"></a>03901 
+<a name="l03902"></a>03902     invert_transform = sinfo_invert_linear_transform(param) ;
+<a name="l03903"></a>03903     <span class="keywordflow">if</span> (invert_transform == NULL) {
+<a name="l03904"></a>03904         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"cannot compute sinfo_invert transform: "</span>
+<a name="l03905"></a>03905                         <span class="stringliteral">"aborting warping"</span>) ;
+<a name="l03906"></a>03906         <span class="keywordflow">return</span> NULL ;
+<a name="l03907"></a>03907     }
+<a name="l03908"></a>03908 
+<a name="l03909"></a>03909     <span class="comment">/* Generate default interpolation kernel */</span>
+<a name="l03910"></a>03910     kernel = sinfo_generate_interpolation_kernel(kernel_type) ;
+<a name="l03911"></a>03911     <span class="keywordflow">if</span> (kernel == NULL) {
+<a name="l03912"></a>03912         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"cannot generate kernel: aborting resampling"</span>) ;
+<a name="l03913"></a>03913         <span class="keywordflow">return</span> NULL ;
+<a name="l03914"></a>03914     }
+<a name="l03915"></a>03915 
+<a name="l03916"></a>03916     <span class="comment">/* Compute new image size   */</span>
+<a name="l03917"></a>03917     <span class="comment">/* Compute new image size   */</span>
+<a name="l03918"></a>03918     ilx=cpl_image_get_size_x(cpl_imagelist_get(cu,0));
+<a name="l03919"></a>03919     ily=cpl_image_get_size_y(cpl_imagelist_get(cu,0));
+<a name="l03920"></a>03920     inp=cpl_imagelist_get_size(cu);
+<a name="l03921"></a>03921 
+<a name="l03922"></a>03922     lx_out = (int) ilx*xscale ;
+<a name="l03923"></a>03923     ly_out = (int) ily*yscale ;
+<a name="l03924"></a>03924 
+<a name="l03925"></a>03925     cube=cpl_imagelist_new();
+<a name="l03926"></a>03926     <span class="keywordflow">for</span> ( l = 0 ; l < inp ; i++ ) {
+<a name="l03927"></a>03927      in_img = cpl_image_new(ilx,ily,CPL_TYPE_FLOAT);
+<a name="l03928"></a>03928      cpl_imagelist_set(cube,in_img,l);
+<a name="l03929"></a>03929     }
+<a name="l03930"></a>03930 
+<a name="l03931"></a>03931     <span class="comment">/* old code</span>
+<a name="l03932"></a>03932 <span class="comment">    if (NULL == (cube = sinfo_newCube (lx_out, ly_out, cu->np)) )</span>
+<a name="l03933"></a>03933 <span class="comment">    {</span>
+<a name="l03934"></a>03934 <span class="comment">        sinfo_msg_error (" cannot allocate new cube") ;</span>
+<a name="l03935"></a>03935 <span class="comment">        return NULL ;</span>
+<a name="l03936"></a>03936 <span class="comment">    }</span>
+<a name="l03937"></a>03937 <span class="comment">    */</span>
+<a name="l03938"></a>03938 
+<a name="l03939"></a>03939     <span class="keywordflow">for</span> (l=0;l<inp;l++){
+<a name="l03940"></a>03940       in_img=cpl_imagelist_get(cu,l);
+<a name="l03941"></a>03941       ou_img=cpl_imagelist_get(cube,l);
+<a name="l03942"></a>03942       tlx=cpl_image_get_size_x(in_img);
+<a name="l03943"></a>03943       tly=cpl_image_get_size_y(in_img);
+<a name="l03944"></a>03944       podata=cpl_image_get_data_float(ou_img);
+<a name="l03945"></a>03945         <span class="comment">/* Pre compute leaps for 16 closest neighbors positions */</span>
+<a name="l03946"></a>03946         leaps[0] = -1 - tlx ;
+<a name="l03947"></a>03947         leaps[1] =    - tlx ;
+<a name="l03948"></a>03948         leaps[2] =  1 - tlx ;
+<a name="l03949"></a>03949         leaps[3] =  2 - tlx ;
+<a name="l03950"></a>03950 
+<a name="l03951"></a>03951         leaps[4] = -1 ;
+<a name="l03952"></a>03952         leaps[5] =  0 ;
+<a name="l03953"></a>03953         leaps[6] =  1 ;
+<a name="l03954"></a>03954         leaps[7] =  2 ;
+<a name="l03955"></a>03955 
+<a name="l03956"></a>03956         leaps[8] = -1 + tlx ;
+<a name="l03957"></a>03957         leaps[9] =      tlx ;
+<a name="l03958"></a>03958         leaps[10]=  1 + tlx ;
+<a name="l03959"></a>03959         leaps[11]=  2 + tlx ;
+<a name="l03960"></a>03960 
+<a name="l03961"></a>03961         leaps[12]= -1 + 2*tlx ;
+<a name="l03962"></a>03962         leaps[13]=      2*tlx ;
+<a name="l03963"></a>03963         leaps[14]=  1 + 2*tlx ;
+<a name="l03964"></a>03964         leaps[15]=  2 + 2*tlx ;
+<a name="l03965"></a>03965 
+<a name="l03966"></a>03966         <span class="comment">/* Double loop on the output image  */</span>
+<a name="l03967"></a>03967         <span class="keywordflow">for</span> (j=0 ; j < ly_out ; j++) {
+<a name="l03968"></a>03968             <span class="keywordflow">for</span> (i=0 ; i< lx_out ; i++) {
+<a name="l03969"></a>03969                 <span class="comment">/* Compute the original source for this pixel   */</span>
+<a name="l03970"></a>03970 
+<a name="l03971"></a>03971                 x = invert_transform[0] * (double)i +
+<a name="l03972"></a>03972                     invert_transform[1] * (<span class="keywordtype">double</span>)j +
+<a name="l03973"></a>03973                 invert_transform[2] ;
+<a name="l03974"></a>03974 
+<a name="l03975"></a>03975                 y = invert_transform[3] * (<span class="keywordtype">double</span>)i +
+<a name="l03976"></a>03976                 invert_transform[4] * (<span class="keywordtype">double</span>)j +
+<a name="l03977"></a>03977                 invert_transform[5] ;
+<a name="l03978"></a>03978 
+<a name="l03979"></a>03979             <span class="comment">/* Which is the closest integer positioned neighbor?    */</span>
+<a name="l03980"></a>03980                 px = (<span class="keywordtype">int</span>)x ;
+<a name="l03981"></a>03981         py = (<span class="keywordtype">int</span>)y ;
+<a name="l03982"></a>03982 
+<a name="l03983"></a>03983                 if ((px < 1) ||
+<a name="l03984"></a>03984                     (px > (tlx-2)) ||
+<a name="l03985"></a>03985                     (py < 1) ||
+<a name="l03986"></a>03986                     (py > (tly-2)))
+<a name="l03987"></a>03987                     podata[i+j*lx_out] = (pixelvalue)0.0 ;
+<a name="l03988"></a>03988                 else {
+<a name="l03989"></a>03989                     <span class="comment">/* Now feed the positions for the closest 16 neighbors  */</span>
+<a name="l03990"></a>03990                     pos = px + py * tlx ;
+<a name="l03991"></a>03991                     <span class="keywordflow">for</span> (k=0 ; k<16 ; k++){
+<a name="l03992"></a>03992                         <span class="keywordflow">if</span>(!isnan(podata[(<span class="keywordtype">int</span>)(pos+leaps[k])])) neighbors[k] =
+<a name="l03993"></a>03993                          (<span class="keywordtype">double</span>)(podata[(int)(pos+leaps[k])]) ;
+<a name="l03994"></a>03994                 <span class="keywordflow">else</span> neighbors[k]=0;
+<a name="l03995"></a>03995             }
+<a name="l03996"></a>03996 
+<a name="l03997"></a>03997                     <span class="comment">/* Which tabulated value index shall we use?    */</span>
+<a name="l03998"></a>03998                     tabx = (x - (double)px) * (double)(TABSPERPIX) ;
+<a name="l03999"></a>03999                     taby = (y - (double)py) * (double)(TABSPERPIX) ;
+<a name="l04000"></a>04000 
+<a name="l04001"></a>04001                     <span class="comment">/* Compute resampling coefficients  */</span>
+<a name="l04002"></a>04002                     <span class="comment">/* rsc[0..3] in x, rsc[4..7] in y   */</span>
+<a name="l04003"></a>04003 
+<a name="l04004"></a>04004                     rsc[0] = kernel[TABSPERPIX + tabx] ;
+<a name="l04005"></a>04005                     rsc[1] = kernel[tabx] ;
+<a name="l04006"></a>04006                     rsc[2] = kernel[TABSPERPIX - tabx] ;
+<a name="l04007"></a>04007                     rsc[3] = kernel[2 * TABSPERPIX - tabx] ;
+<a name="l04008"></a>04008                     rsc[4] = kernel[TABSPERPIX + taby] ;
+<a name="l04009"></a>04009                     rsc[5] = kernel[taby] ;
+<a name="l04010"></a>04010                     rsc[6] = kernel[TABSPERPIX - taby] ;
+<a name="l04011"></a>04011                     rsc[7] = kernel[2 * TABSPERPIX - taby] ;
+<a name="l04012"></a>04012 
+<a name="l04013"></a>04013                     sumrs = (rsc[0]+rsc[1]+rsc[2]+rsc[3]) *
+<a name="l04014"></a>04014                         (rsc[4]+rsc[5]+rsc[6]+rsc[7]) ;
+<a name="l04015"></a>04015 
+<a name="l04016"></a>04016                     <span class="comment">/* Compute interpolated pixel now   */</span>
+<a name="l04017"></a>04017                     cur =   rsc[4] * (  rsc[0]*neighbors[0] +
+<a name="l04018"></a>04018                                     rsc[1]*neighbors[1] +
+<a name="l04019"></a>04019                                     rsc[2]*neighbors[2] +
+<a name="l04020"></a>04020                                     rsc[3]*neighbors[3] ) +
+<a name="l04021"></a>04021                         rsc[5] * (  rsc[0]*neighbors[4] +
+<a name="l04022"></a>04022                                     rsc[1]*neighbors[5] +
+<a name="l04023"></a>04023                                     rsc[2]*neighbors[6] +
+<a name="l04024"></a>04024                                     rsc[3]*neighbors[7] ) +
+<a name="l04025"></a>04025                         rsc[6] * (  rsc[0]*neighbors[8] +
+<a name="l04026"></a>04026                                     rsc[1]*neighbors[9] +
+<a name="l04027"></a>04027                                     rsc[2]*neighbors[10] +
+<a name="l04028"></a>04028                                     rsc[3]*neighbors[11] ) +
+<a name="l04029"></a>04029                         rsc[7] * (  rsc[0]*neighbors[12] +
+<a name="l04030"></a>04030                                     rsc[1]*neighbors[13] +
+<a name="l04031"></a>04031                                     rsc[2]*neighbors[14] +
+<a name="l04032"></a>04032                                     rsc[3]*neighbors[15] ) ;
+<a name="l04033"></a>04033 
+<a name="l04034"></a>04034                     <span class="comment">/* Affect the value to the output image */</span>
+<a name="l04035"></a>04035                     podata[i+j*lx_out] = (pixelvalue)(cur/sumrs) ;
+<a name="l04036"></a>04036                     <span class="comment">/* done ! */</span>
+<a name="l04037"></a>04037                 }
+<a name="l04038"></a>04038             }
+<a name="l04039"></a>04039         }
+<a name="l04040"></a>04040     }
+<a name="l04041"></a>04041     cpl_free(kernel) ;
+<a name="l04042"></a>04042     cpl_free(invert_transform) ;
+<a name="l04043"></a>04043     <span class="keywordflow">return</span> cube ;
+<a name="l04044"></a>04044 }
+<a name="l04045"></a>04045 
+<a name="l04046"></a>04046 
+<a name="l04056"></a>04056 cpl_imagelist *
+<a name="l04057"></a>04057 sinfo_cube_zshift(<span class="keyword">const</span> cpl_imagelist * cube_inp,
+<a name="l04058"></a>04058                   <span class="keyword">const</span> <span class="keywordtype">double</span> shift,
+<a name="l04059"></a>04059                   <span class="keywordtype">double</span>* sub_shift)
+<a name="l04060"></a>04060 {
+<a name="l04061"></a>04061 
+<a name="l04062"></a>04062     cpl_imagelist * cube_out=NULL ;
+<a name="l04063"></a>04063     <span class="keyword">const</span> cpl_image* img_inp=NULL;
+<a name="l04064"></a>04064     cpl_image* img_out=NULL;
+<a name="l04065"></a>04065     <span class="keywordtype">int</span>        col, row,z ;
+<a name="l04066"></a>04066     <span class="keywordtype">int</span>        int_shift ;
+<a name="l04067"></a>04067     <span class="keywordtype">int</span> ilx=0;
+<a name="l04068"></a>04068     <span class="keywordtype">int</span> ily=0;
+<a name="l04069"></a>04069     <span class="keywordtype">int</span> ilz=0;
+<a name="l04070"></a>04070 
+<a name="l04071"></a>04071     <span class="keywordtype">int</span> olx=0;
+<a name="l04072"></a>04072     <span class="keywordtype">int</span> oly=0;
+<a name="l04073"></a>04073     <span class="keywordtype">int</span> olz=0;
+<a name="l04074"></a>04074     <span class="keywordtype">int</span> i=0;
+<a name="l04075"></a>04075     <span class="keyword">const</span> <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l04076"></a>04076     <span class="keywordtype">float</span>* podata=NULL;
+<a name="l04077"></a>04077 
+<a name="l04078"></a>04078     cknull(cube_inp,<span class="stringliteral">"no input cube given!"</span>) ;
+<a name="l04079"></a>04079     check_nomsg(img_inp=cpl_imagelist_get_const(cube_inp,0));
+<a name="l04080"></a>04080     check_nomsg(ilx=cpl_image_get_size_x(img_inp));
+<a name="l04081"></a>04081     check_nomsg(ily=cpl_image_get_size_y(img_inp));
+<a name="l04082"></a>04082     check_nomsg(ilz=cpl_imagelist_get_size(cube_inp));
+<a name="l04083"></a>04083 
+<a name="l04084"></a>04084     olx=ilx;
+<a name="l04085"></a>04085     oly=ily;
+<a name="l04086"></a>04086     olz=ilz;
+<a name="l04087"></a>04087 
+<a name="l04088"></a>04088     int_shift = sinfo_new_nint(shift) ;
+<a name="l04089"></a>04089     *sub_shift = shift - (double) int_shift ;
+<a name="l04090"></a>04090     <span class="keywordflow">if</span> ( int_shift == 0 )
+<a name="l04091"></a>04091     {
+<a name="l04092"></a>04092         cube_out =cpl_imagelist_duplicate(cube_inp) ;
+<a name="l04093"></a>04093         <span class="keywordflow">return</span> cube_out ;
+<a name="l04094"></a>04094     }
+<a name="l04095"></a>04095     <span class="keywordflow">else</span>
+<a name="l04096"></a>04096     {
+<a name="l04097"></a>04097       <span class="comment">/* allocate memory */</span>
+<a name="l04098"></a>04098       cknull(cube_out = cpl_imagelist_new(),<span class="stringliteral">"could not allocate memory!"</span>) ;
+<a name="l04099"></a>04099       <span class="keywordflow">for</span> ( i = 0 ; i < olz ; i++ ) {
+<a name="l04100"></a>04100         check_nomsg(img_out=cpl_image_new(olx,oly,CPL_TYPE_FLOAT));
+<a name="l04101"></a>04101         check_nomsg(cpl_imagelist_set(cube_out,img_out,i));
+<a name="l04102"></a>04102      }
+<a name="l04103"></a>04103     }
+<a name="l04104"></a>04104 
+<a name="l04105"></a>04105     <span class="keywordflow">for</span>(z=0; z< ilz; z++) {
+<a name="l04106"></a>04106       <span class="keywordflow">if</span> ( (z-int_shift >= 0 ) && (z - int_shift < olz) ) {
+<a name="l04107"></a>04107         check_nomsg(img_inp=cpl_imagelist_get_const(cube_inp,z));
+<a name="l04108"></a>04108         check_nomsg(img_out=cpl_imagelist_get(cube_out,z-int_shift));
+<a name="l04109"></a>04109     check_nomsg(pidata=cpl_image_get_data_float_const(img_inp));
+<a name="l04110"></a>04110     check_nomsg(podata=cpl_image_get_data_float(img_out));
+<a name="l04111"></a>04111     <span class="keywordflow">for</span> ( col = 0 ; col < ilx ; col++ ) {
+<a name="l04112"></a>04112       <span class="keywordflow">for</span> ( row = 0 ; row < ily ; row++ ) {
+<a name="l04113"></a>04113         podata[col+row*olx] = pidata[col+row*olx] ;
+<a name="l04114"></a>04114       }
+<a name="l04115"></a>04115     }
+<a name="l04116"></a>04116       }
+<a name="l04117"></a>04117     }
+<a name="l04118"></a>04118     <span class="keywordflow">return</span> cube_out ;
+<a name="l04119"></a>04119 
+<a name="l04120"></a>04120  cleanup:
+<a name="l04121"></a>04121     sinfo_free_imagelist(&cube_out);
+<a name="l04122"></a>04122     <span class="keywordflow">return</span> NULL ;
+<a name="l04123"></a>04123 }
+<a name="l04124"></a>04124 
+<a name="l04134"></a>04134 cpl_imagelist *
+<a name="l04135"></a>04135 sinfo_cube_zshift_poly(<span class="keyword">const</span> cpl_imagelist * cube_inp,
+<a name="l04136"></a>04136                        <span class="keyword">const</span> <span class="keywordtype">double</span> sub_shift,
+<a name="l04137"></a>04137                        <span class="keyword">const</span> <span class="keywordtype">int</span>    order)
+<a name="l04138"></a>04138 {
+<a name="l04139"></a>04139   cpl_imagelist * cube_out ;
+<a name="l04140"></a>04140 
+<a name="l04141"></a>04141   <span class="keywordtype">float</span>* spec=NULL ;
+<a name="l04142"></a>04142   <span class="keywordtype">float</span>* corrected_spec=NULL ;
+<a name="l04143"></a>04143   <span class="keywordtype">float</span>* xnum=NULL ;
+<a name="l04144"></a>04144 
+<a name="l04145"></a>04145   <span class="keywordtype">float</span> sum=0;
+<a name="l04146"></a>04146   <span class="keywordtype">float</span> new_sum=0 ;
+<a name="l04147"></a>04147   <span class="keywordtype">float</span> eval=0 ;
+<a name="l04148"></a>04148   <span class="keywordtype">float</span> * imageptr=NULL ;
+<a name="l04149"></a>04149   <span class="keywordtype">int</span> row=0;
+<a name="l04150"></a>04150   <span class="keywordtype">int</span> col=0 ;
+<a name="l04151"></a>04151   <span class="keywordtype">int</span> firstpos=0 ;
+<a name="l04152"></a>04152   <span class="keywordtype">int</span> n_points=0 ;
+<a name="l04153"></a>04153   <span class="keywordtype">int</span> i=0 ;
+<a name="l04154"></a>04154   <span class="keywordtype">int</span> flag=0;
+<a name="l04155"></a>04155   <span class="keywordtype">int</span> ilx=0;
+<a name="l04156"></a>04156   <span class="keywordtype">int</span> ily=0;
+<a name="l04157"></a>04157   <span class="keywordtype">int</span> ilz=0;
+<a name="l04158"></a>04158 
+<a name="l04159"></a>04159   <span class="keywordtype">int</span> olx=0;
+<a name="l04160"></a>04160   <span class="keywordtype">int</span> oly=0;
+<a name="l04161"></a>04161   <span class="keywordtype">int</span> olz=0;
+<a name="l04162"></a>04162   <span class="keywordtype">int</span> z=0;
+<a name="l04163"></a>04163 
+<a name="l04164"></a>04164   <span class="keyword">const</span> <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l04165"></a>04165   <span class="keywordtype">float</span>* podata=NULL;
+<a name="l04166"></a>04166   <span class="keyword">const</span> cpl_image* img_inp=NULL;
+<a name="l04167"></a>04167   cpl_image* img_out=NULL;
+<a name="l04168"></a>04168 
+<a name="l04169"></a>04169   <span class="keywordflow">if</span> ( cube_inp == NULL ) {
+<a name="l04170"></a>04170     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no imagelist given!"</span>) ;
+<a name="l04171"></a>04171     <span class="keywordflow">return</span> NULL ;
+<a name="l04172"></a>04172   }
+<a name="l04173"></a>04173 
+<a name="l04174"></a>04174   img_inp=cpl_imagelist_get_const(cube_inp,0);
+<a name="l04175"></a>04175 
+<a name="l04176"></a>04176   ilx=cpl_image_get_size_x(img_inp);
+<a name="l04177"></a>04177   ily=cpl_image_get_size_y(img_inp);
+<a name="l04178"></a>04178   ilz=cpl_imagelist_get_size(cube_inp);
+<a name="l04179"></a>04179 
+<a name="l04180"></a>04180   <span class="keywordflow">if</span> ( order <= 0 ) {
+<a name="l04181"></a>04181     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"wrong order of interpolation polynom given!"</span>) ;
+<a name="l04182"></a>04182     <span class="keywordflow">return</span> NULL ;
+<a name="l04183"></a>04183   }
+<a name="l04184"></a>04184 
+<a name="l04185"></a>04185 
+<a name="l04186"></a>04186   olx=ilx;
+<a name="l04187"></a>04187   oly=ily;
+<a name="l04188"></a>04188   olz=ilz;
+<a name="l04189"></a>04189   <span class="comment">/* allocate memory */</span>
+<a name="l04190"></a>04190 
+<a name="l04191"></a>04191   <span class="keywordflow">if</span> ( NULL == (cube_out = cpl_imagelist_new()) ) {
+<a name="l04192"></a>04192     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"could not allocate memory!"</span>) ;
+<a name="l04193"></a>04193     <span class="keywordflow">return</span> NULL ;
+<a name="l04194"></a>04194   } <span class="keywordflow">else</span> {
+<a name="l04195"></a>04195     <span class="keywordflow">for</span> ( i = 0 ; i < ilz ; i++ ) {
+<a name="l04196"></a>04196       img_out=cpl_image_new(olx,oly,CPL_TYPE_FLOAT);
+<a name="l04197"></a>04197       cpl_imagelist_set(cube_out,img_out,i);
+<a name="l04198"></a>04198     }
+<a name="l04199"></a>04199   }
+<a name="l04200"></a>04200 
+<a name="l04201"></a>04201 
+<a name="l04202"></a>04202   n_points = order + 1 ;
+<a name="l04203"></a>04203   <span class="keywordflow">if</span> ( n_points % 2 == 0 ) {
+<a name="l04204"></a>04204     firstpos = (int)(n_points/2) - 1 ;
+<a name="l04205"></a>04205   } <span class="keywordflow">else</span> {
+<a name="l04206"></a>04206     firstpos = (int)(n_points/2) ;
+<a name="l04207"></a>04207   }
+<a name="l04208"></a>04208 
+<a name="l04209"></a>04209   spec=cpl_calloc(ilz,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l04210"></a>04210   corrected_spec=cpl_calloc(ilz,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l04211"></a>04211   xnum=cpl_calloc(order+1,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l04212"></a>04212 
+<a name="l04213"></a>04213 
+<a name="l04214"></a>04214   <span class="comment">/* fill the xa[] array for the polint function */</span>
+<a name="l04215"></a>04215   <span class="keywordflow">for</span> ( i = 0 ; i < n_points ; i++ ) {
+<a name="l04216"></a>04216     xnum[i] = i ;
+<a name="l04217"></a>04217   }
+<a name="l04218"></a>04218 
+<a name="l04219"></a>04219   <span class="keywordflow">for</span> ( col = 0 ; col < ilx ; col++ ) {
+<a name="l04220"></a>04220     <span class="keywordflow">for</span> ( row = 0 ; row < ily ; row++ ) {
+<a name="l04221"></a>04221       <span class="keywordflow">for</span>( z=0; z< ilz; z++) {
+<a name="l04222"></a>04222         corrected_spec[z] = 0. ;
+<a name="l04223"></a>04223       }
+<a name="l04224"></a>04224       sum = 0. ;
+<a name="l04225"></a>04225       <span class="keywordflow">for</span> ( z = 0 ; z < ilz ; z++ ) {
+<a name="l04226"></a>04226     img_inp=cpl_imagelist_get_const(cube_inp,z);
+<a name="l04227"></a>04227         pidata=cpl_image_get_data_float_const(img_inp);
+<a name="l04228"></a>04228     spec[z] = pidata[col + row*ilx] ;
+<a name="l04229"></a>04229     <span class="keywordflow">if</span> (isnan(spec[z]) ) {
+<a name="l04230"></a>04230           spec[z] = 0. ;
+<a name="l04231"></a>04231 
+<a name="l04232"></a>04232       <span class="keywordflow">for</span> ( i = z - firstpos ; i < z-firstpos+n_points ; i++ ) {
+<a name="l04233"></a>04233         <span class="keywordflow">if</span> ( i < 0 ) continue ;
+<a name="l04234"></a>04234             <span class="keywordflow">if</span> ( i >= ilz) continue  ;
+<a name="l04235"></a>04235             corrected_spec[i] = ZERO ;
+<a name="l04236"></a>04236           }
+<a name="l04237"></a>04237         }
+<a name="l04238"></a>04238         <span class="keywordflow">if</span> ( z != 0 && z != ilz - 1 ) {
+<a name="l04239"></a>04239           sum += spec[z] ;
+<a name="l04240"></a>04240         }
+<a name="l04241"></a>04241 
+<a name="l04242"></a>04242       }
+<a name="l04243"></a>04243 
+<a name="l04244"></a>04244       new_sum = 0. ;
+<a name="l04245"></a>04245       <span class="keywordflow">for</span> ( z = 0 ; z < ilz ; z++ ) {
+<a name="l04246"></a>04246 
+<a name="l04247"></a>04247         <span class="comment">/* ---------------------------------------------------------------</span>
+<a name="l04248"></a>04248 <span class="comment">         * now determine the arrays of size n_points with which the</span>
+<a name="l04249"></a>04249 <span class="comment">         * polynom is determined and determine the position eval</span>
+<a name="l04250"></a>04250 <span class="comment">         * where the polynom is evaluated in polynomial interpolation.</span>
+<a name="l04251"></a>04251 <span class="comment">         * Take care of the points near the row edges!</span>
+<a name="l04252"></a>04252 <span class="comment">         */</span>
+<a name="l04253"></a>04253         <span class="keywordflow">if</span> (isnan(corrected_spec[z])) continue ;
+<a name="l04254"></a>04254         <span class="keywordflow">if</span> ( z - firstpos < 0 ) {
+<a name="l04255"></a>04255           imageptr = &spec[0] ;
+<a name="l04256"></a>04256           eval     = sub_shift + z ;
+<a name="l04257"></a>04257         } <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( z - firstpos + n_points >= ilz ) {
+<a name="l04258"></a>04258           imageptr = &spec[ilz - n_points] ;
+<a name="l04259"></a>04259           eval     = sub_shift + z + n_points - ilz ;
+<a name="l04260"></a>04260         } <span class="keywordflow">else</span> {
+<a name="l04261"></a>04261       imageptr = &spec[z-firstpos] ;
+<a name="l04262"></a>04262           eval     = sub_shift + firstpos ;
+<a name="l04263"></a>04263         }
+<a name="l04264"></a>04264 
+<a name="l04265"></a>04265         flag=0;
+<a name="l04266"></a>04266         corrected_spec[z]=sinfo_new_nev_ille(xnum,imageptr,order,eval,&flag);
+<a name="l04267"></a>04267         <span class="keywordflow">if</span> ( z != 0 && z != ilz - 1 ) {
+<a name="l04268"></a>04268           new_sum += corrected_spec[z] ;
+<a name="l04269"></a>04269         }
+<a name="l04270"></a>04270       }
+<a name="l04271"></a>04271 
+<a name="l04272"></a>04272       <span class="comment">/* fill the output spectrum */</span>
+<a name="l04273"></a>04273       <span class="keywordflow">for</span> (z = 0 ; z < ilz ; z++ )
+<a name="l04274"></a>04274       {
+<a name="l04275"></a>04275         img_out=cpl_imagelist_get(cube_out,z);
+<a name="l04276"></a>04276         podata=cpl_image_get_data_float(img_out);
+<a name="l04277"></a>04277         <span class="keywordflow">if</span> ( new_sum == 0. ) {
+<a name="l04278"></a>04278           new_sum = 1. ;
+<a name="l04279"></a>04279         }
+<a name="l04280"></a>04280         <span class="keywordflow">if</span> ( z == 0 ) {
+<a name="l04281"></a>04281           podata[col+row*olx] = ZERO ;
+<a name="l04282"></a>04282         } <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( z == ilz - 1 ) {
+<a name="l04283"></a>04283           podata[col+row*olx] = ZERO ;
+<a name="l04284"></a>04284         } <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( isnan(corrected_spec[z]) ) {
+<a name="l04285"></a>04285           podata[col+row*olx] = ZERO ;
+<a name="l04286"></a>04286         } <span class="keywordflow">else</span> {
+<a name="l04287"></a>04287           corrected_spec[z] *= sum / new_sum ;
+<a name="l04288"></a>04288           podata[col+row*olx] = corrected_spec[z] ;
+<a name="l04289"></a>04289     }
+<a name="l04290"></a>04290       }
+<a name="l04291"></a>04291 
+<a name="l04292"></a>04292     }
+<a name="l04293"></a>04293   }
+<a name="l04294"></a>04294 
+<a name="l04295"></a>04295   cpl_free(spec) ;
+<a name="l04296"></a>04296   cpl_free(corrected_spec) ;
+<a name="l04297"></a>04297   cpl_free(xnum) ;
+<a name="l04298"></a>04298   <span class="keywordflow">return</span> cube_out ;
+<a name="l04299"></a>04299 
+<a name="l04300"></a>04300 
+<a name="l04301"></a>04301 }
+<a name="l04302"></a>04302 
+<a name="l04311"></a>04311 cpl_imagelist *
+<a name="l04312"></a>04312 sinfo_cube_zshift_spline3(<span class="keyword">const</span> cpl_imagelist * cube_inp,
+<a name="l04313"></a>04313                           <span class="keyword">const</span> <span class="keywordtype">double</span> sub_shift)
+<a name="l04314"></a>04314 {
+<a name="l04315"></a>04315 
+<a name="l04316"></a>04316   cpl_imagelist * cube_out=NULL ;
+<a name="l04317"></a>04317   <span class="keywordtype">float</span>* spec=NULL ;
+<a name="l04318"></a>04318   <span class="keywordtype">float</span>* corrected_spec=NULL ;
+<a name="l04319"></a>04319   <span class="keywordtype">float</span>* xnum=NULL ;
+<a name="l04320"></a>04320   <span class="keywordtype">float</span>* eval=NULL ;
+<a name="l04321"></a>04321   <span class="keywordtype">float</span> sum=0;
+<a name="l04322"></a>04322   <span class="keywordtype">float</span> new_sum=0 ;
+<a name="l04323"></a>04323   <span class="keywordtype">int</span> row=0;
+<a name="l04324"></a>04324   <span class="keywordtype">int</span> col=0;
+<a name="l04325"></a>04325   <span class="keywordtype">int</span> i=0;
+<a name="l04326"></a>04326   <span class="keywordtype">int</span> z=0;
+<a name="l04327"></a>04327 
+<a name="l04328"></a>04328   <span class="keywordtype">int</span> ilx=0;
+<a name="l04329"></a>04329   <span class="keywordtype">int</span> ily=0;
+<a name="l04330"></a>04330   <span class="keywordtype">int</span> ilz=0;
+<a name="l04331"></a>04331   <span class="keywordtype">int</span> olx=0;
+<a name="l04332"></a>04332   <span class="keywordtype">int</span> oly=0;
+<a name="l04333"></a>04333   <span class="keywordtype">int</span> olz=0;
+<a name="l04334"></a>04334 
+<a name="l04335"></a>04335   <span class="keyword">const</span> <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l04336"></a>04336   <span class="keywordtype">float</span>* podata=NULL;
+<a name="l04337"></a>04337   <span class="keyword">const</span> cpl_image* img_inp=NULL;
+<a name="l04338"></a>04338   cpl_image* img_out=NULL;
+<a name="l04339"></a>04339 
+<a name="l04340"></a>04340   <span class="keywordflow">if</span> ( cube_inp == NULL ) {
+<a name="l04341"></a>04341     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no imagelist given!"</span>) ;
+<a name="l04342"></a>04342     <span class="keywordflow">return</span> NULL ;
+<a name="l04343"></a>04343   }
+<a name="l04344"></a>04344 
+<a name="l04345"></a>04345   img_inp=cpl_imagelist_get_const(cube_inp,0);
+<a name="l04346"></a>04346   ilx=cpl_image_get_size_x(img_inp);
+<a name="l04347"></a>04347   ily=cpl_image_get_size_y(img_inp);
+<a name="l04348"></a>04348   ilz=cpl_imagelist_get_size(cube_inp);
+<a name="l04349"></a>04349 
+<a name="l04350"></a>04350 
+<a name="l04351"></a>04351   olx=ilx;
+<a name="l04352"></a>04352   oly=ily;
+<a name="l04353"></a>04353   olz=ilz;
+<a name="l04354"></a>04354   <span class="comment">/* allocate memory */</span>
+<a name="l04355"></a>04355   <span class="keywordflow">if</span> ( NULL == (cube_out = cpl_imagelist_new()) ) {
+<a name="l04356"></a>04356     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"could not allocate memory!"</span>) ;
+<a name="l04357"></a>04357     <span class="keywordflow">return</span> NULL ;
+<a name="l04358"></a>04358   } <span class="keywordflow">else</span> {
+<a name="l04359"></a>04359     <span class="keywordflow">for</span> ( i = 0 ; i < ilz ; i++ ) {
+<a name="l04360"></a>04360       img_out=cpl_image_new(olx,oly,CPL_TYPE_FLOAT);
+<a name="l04361"></a>04361       cpl_imagelist_set(cube_out,img_out,i);
+<a name="l04362"></a>04362     }
+<a name="l04363"></a>04363   }
+<a name="l04364"></a>04364 
+<a name="l04365"></a>04365   xnum=cpl_calloc(ilz,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l04366"></a>04366   <span class="comment">/* fill the xa[] array for the spline function */</span>
+<a name="l04367"></a>04367   <span class="keywordflow">for</span> ( i = 0 ; i < ilz ; i++ ) {
+<a name="l04368"></a>04368     xnum[i] = i ;
+<a name="l04369"></a>04369   }
+<a name="l04370"></a>04370 
+<a name="l04371"></a>04371   spec=cpl_calloc(ilz,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l04372"></a>04372   corrected_spec=cpl_calloc(ilz,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l04373"></a>04373   eval=cpl_calloc(ilz,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l04374"></a>04374 
+<a name="l04375"></a>04375   <span class="keywordflow">for</span> ( col = 0 ; col < ilx ; col++ ) {
+<a name="l04376"></a>04376     <span class="keywordflow">for</span> ( row = 0 ; row < ily ; row++ ) {
+<a name="l04377"></a>04377       sum = 0. ;
+<a name="l04378"></a>04378       <span class="keywordflow">for</span> ( z = 0 ; z < ilz ; z++ ) {
+<a name="l04379"></a>04379     img_inp=cpl_imagelist_get_const(cube_inp,z);
+<a name="l04380"></a>04380         pidata=cpl_image_get_data_float_const(img_inp);
+<a name="l04381"></a>04381     spec[z] = pidata[col + row*ilx] ;
+<a name="l04382"></a>04382     <span class="keywordflow">if</span> (isnan(spec[z]) ) {
+<a name="l04383"></a>04383       <span class="keywordflow">for</span> ( i = z-1 ; i <= z+1 ; i++ ) {
+<a name="l04384"></a>04384         <span class="keywordflow">if</span> ( i < 0 ) continue ;
+<a name="l04385"></a>04385         <span class="keywordflow">if</span> ( i >= ilz) continue ;
+<a name="l04386"></a>04386         corrected_spec[i] = ZERO ;
+<a name="l04387"></a>04387       }
+<a name="l04388"></a>04388       spec[z] = 0. ;
+<a name="l04389"></a>04389     }
+<a name="l04390"></a>04390     sum += spec[z] ;
+<a name="l04391"></a>04391     eval[z] = (float)sub_shift+(<span class="keywordtype">float</span>)z ;
+<a name="l04392"></a>04392       }
+<a name="l04393"></a>04393       <span class="comment">/* now we do the spline interpolation*/</span>
+<a name="l04394"></a>04394       <span class="keywordflow">if</span> ( -1 == sinfo_function1d_natural_spline( xnum, spec, ilz, eval,
+<a name="l04395"></a>04395                                               corrected_spec, ilz ) )
+<a name="l04396"></a>04396         {
+<a name="l04397"></a>04397       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"error in spline interpolation!"</span>) ;
+<a name="l04398"></a>04398       <span class="keywordflow">return</span> NULL ;
+<a name="l04399"></a>04399         }
+<a name="l04400"></a>04400 
+<a name="l04401"></a>04401       new_sum = 0. ;
+<a name="l04402"></a>04402       <span class="keywordflow">for</span> ( z = 0 ; z < ilz ; z++ ) {
+<a name="l04403"></a>04403     <span class="keywordflow">if</span> ( isnan(corrected_spec[z]) ) {
+<a name="l04404"></a>04404       continue ;
+<a name="l04405"></a>04405     }
+<a name="l04406"></a>04406     new_sum += corrected_spec[z] ;
+<a name="l04407"></a>04407       }
+<a name="l04408"></a>04408       <span class="comment">/* fill output imagelist */</span>
+<a name="l04409"></a>04409       <span class="keywordflow">for</span> ( z = 0 ; z < ilz ; z++ ) {
+<a name="l04410"></a>04410         img_out=cpl_imagelist_get(cube_out,z);
+<a name="l04411"></a>04411         podata=cpl_image_get_data_float(img_out);
+<a name="l04412"></a>04412     <span class="keywordflow">if</span> ( new_sum == 0. ) new_sum =1. ;
+<a name="l04413"></a>04413     {
+<a name="l04414"></a>04414       <span class="keywordflow">if</span> ( isnan(corrected_spec[z]) ) {
+<a name="l04415"></a>04415         podata[col+row*olx] = ZERO ;
+<a name="l04416"></a>04416       } <span class="keywordflow">else</span> {
+<a name="l04417"></a>04417         corrected_spec[z] *= sum / new_sum ;
+<a name="l04418"></a>04418         podata[col+row*olx] = corrected_spec[z] ;
+<a name="l04419"></a>04419       }
+<a name="l04420"></a>04420     }
+<a name="l04421"></a>04421       }
+<a name="l04422"></a>04422     }
+<a name="l04423"></a>04423   }
+<a name="l04424"></a>04424   cpl_free(xnum);
+<a name="l04425"></a>04425   cpl_free(spec) ;
+<a name="l04426"></a>04426   cpl_free(corrected_spec) ;
+<a name="l04427"></a>04427   cpl_free(eval) ;
+<a name="l04428"></a>04428 
+<a name="l04429"></a>04429   <span class="keywordflow">return</span> cube_out ;
+<a name="l04430"></a>04430 }
+<a name="l04431"></a>04431 
+<a name="l04433"></a>04433 <span class="comment">/* The structure for stroing index data for kappa-sigma</span>
+<a name="l04434"></a>04434 <span class="comment"> *</span>
+<a name="l04435"></a>04435 <span class="comment"> * */</span>
+<a name="l04436"></a>04436 <span class="keyword">struct </span>_CubeData
+<a name="l04437"></a>04437 {
+<a name="l04438"></a>04438     <span class="keywordtype">int</span> iCubeNumber;
+<a name="l04439"></a>04439     <span class="keywordtype">int</span> iLocalX;
+<a name="l04440"></a>04440     <span class="keywordtype">int</span> iLocalY;
+<a name="l04441"></a>04441 };
+<a name="l04442"></a>04442 <span class="keyword">typedef</span> <span class="keyword">struct </span>_CubeData CubeData;
+<a name="l04443"></a>04443 
+<a name="l04444"></a>04444 <span class="keyword">struct </span>_CubeDataVector
+<a name="l04445"></a>04445 {
+<a name="l04446"></a>04446     <span class="keywordtype">int</span> size;
+<a name="l04447"></a>04447     CubeData** pdata;
+<a name="l04448"></a>04448 };
+<a name="l04449"></a>04449 <span class="keyword">typedef</span> <span class="keyword">struct </span>_CubeDataVector CubeDataVector;
+<a name="l04467"></a>04467 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_kappa_sigma_offset_with_mask(
+<a name="l04468"></a>04468         <span class="keywordtype">int</span> z_min,
+<a name="l04469"></a>04469         <span class="keywordtype">int</span> z_max,
+<a name="l04470"></a>04470         <span class="keywordtype">int</span> nCubes,
+<a name="l04471"></a>04471         cpl_imagelist** inputCubes,
+<a name="l04472"></a>04472         <span class="keywordtype">double</span>* exptimes,
+<a name="l04473"></a>04473         cpl_imagelist* imResult,
+<a name="l04474"></a>04474         <span class="keywordtype">int</span>* offsetX,
+<a name="l04475"></a>04475         <span class="keywordtype">int</span>* offsetY,
+<a name="l04476"></a>04476         cpl_imagelist* sky_mask,
+<a name="l04477"></a>04477         <span class="keyword">const</span> <span class="keywordtype">double</span> kappa
+<a name="l04478"></a>04478         );
+<a name="l04479"></a>04479 <span class="keywordtype">void</span> kappa_sigma_CubeDataVector(
+<a name="l04480"></a>04480         <span class="keywordtype">int</span> globalX,
+<a name="l04481"></a>04481         <span class="keywordtype">int</span> globalY,
+<a name="l04482"></a>04482         CubeDataVector* pCubeDataVector,
+<a name="l04483"></a>04483         cpl_imagelist* imlistResult,
+<a name="l04484"></a>04484         cpl_imagelist** input_cubes,
+<a name="l04485"></a>04485         cpl_imagelist* sky_mask,
+<a name="l04486"></a>04486         <span class="keywordtype">int</span> iPlanesNumber,
+<a name="l04487"></a>04487         <span class="keywordtype">int</span> z_min,
+<a name="l04488"></a>04488         <span class="keyword">const</span> <span class="keywordtype">double</span> kappa,
+<a name="l04489"></a>04489         <span class="keywordtype">double</span>* exptimes
+<a name="l04490"></a>04490         );
+<a name="l04491"></a>04491 
+<a name="l04492"></a>04492 <span class="keywordtype">double</span> kappa_sigma_array_with_mask(cpl_array* parray, <span class="keywordtype">int</span> szArray, <span class="keyword">const</span> <span class="keywordtype">double</span> kappa,cpl_image* imMask, <span class="keywordtype">double</span>* exptimes, <span class="keywordtype">int</span> x, <span class="keywordtype">int</span> y, <span class="keywordtype">double</span> mask_delta)
+<a name="l04493"></a>04493 {
+<a name="l04494"></a>04494     <span class="keywordtype">double</span> result = 0;
+<a name="l04495"></a>04495     <span class="keywordtype">int</span> nInvalidPoints = 0;
+<a name="l04496"></a>04496     <span class="keyword">const</span> <span class="keywordtype">double</span> EPS = 1E-10;
+<a name="l04497"></a>04497     <span class="comment">//sinfo_msg("kappa_sigma_array_with_mask, x[%d] y[%d]"</span>
+<a name="l04498"></a>04498     <span class="keywordtype">double</span> mask_adjustment = mask_delta;
+<a name="l04499"></a>04499     <span class="keywordflow">do</span>
+<a name="l04500"></a>04500     {
+<a name="l04501"></a>04501         <span class="keywordtype">double</span> median = 0;
+<a name="l04502"></a>04502         <span class="keywordtype">double</span> sig = 0;
+<a name="l04503"></a>04503         <span class="keywordtype">int</span> z = 0;
+<a name="l04504"></a>04504         nInvalidPoints = 0;
+<a name="l04505"></a>04505 
+<a name="l04506"></a>04506         check_nomsg(median = cpl_array_get_median(parray));
+<a name="l04507"></a>04507         check_nomsg(sig = cpl_array_get_stdev(parray));
+<a name="l04508"></a>04508         <span class="keywordflow">for</span> (z = 0; z < szArray; z++)
+<a name="l04509"></a>04509         {
+<a name="l04510"></a>04510             <span class="keywordtype">int</span> isnull = 0;
+<a name="l04511"></a>04511             <span class="keywordtype">double</span> value = 0;
+<a name="l04512"></a>04512             check_nomsg(value = cpl_array_get(parray, z, &isnull));
+<a name="l04513"></a>04513             <span class="keywordflow">if</span>(!isnull)
+<a name="l04514"></a>04514             {
+<a name="l04515"></a>04515                 <span class="keywordflow">if</span> (fabs(value - median) > (kappa * sig))
+<a name="l04516"></a>04516                 {
+<a name="l04517"></a>04517 
+<a name="l04518"></a>04518    <span class="comment">//                       sinfo_msg("entered");</span>
+<a name="l04519"></a>04519     <span class="comment">//        sinfo_msg("val=%g check=%g",</span>
+<a name="l04520"></a>04520     <span class="comment">//              fabs(value - median),(kappa * sig));</span>
+<a name="l04521"></a>04521 <span class="comment">//            sinfo_msg("kappa=%f sig=%g median=%g value=%g",</span>
+<a name="l04522"></a>04522 <span class="comment">//                  kappa,sig,median,value);</span>
+<a name="l04523"></a>04523 
+<a name="l04524"></a>04524                     <span class="comment">//double msk_new_value = 0;</span>
+<a name="l04525"></a>04525                     cpl_array_fill_window_invalid(parray, z, 1);
+<a name="l04526"></a>04526                     mask_adjustment += exptimes[z];
+<a name="l04527"></a>04527                     ++nInvalidPoints;
+<a name="l04528"></a>04528                 }
+<a name="l04529"></a>04529             }
+<a name="l04530"></a>04530         }
+<a name="l04531"></a>04531         <span class="comment">/*if (nInvalidPoints)</span>
+<a name="l04532"></a>04532 <span class="comment">        {</span>
+<a name="l04533"></a>04533 <span class="comment">            sinfo_msg("nInvalidPoints %d[%d][%d] median[%f] sig[%f]", nInvalidPoints,x,y, median, sig );</span>
+<a name="l04534"></a>04534 <span class="comment">        }*/</span>
+<a name="l04535"></a>04535 
+<a name="l04536"></a>04536     }
+<a name="l04537"></a>04537     <span class="keywordflow">while</span> (nInvalidPoints);
+<a name="l04538"></a>04538     <span class="keywordflow">if</span>(imMask && fabs(mask_adjustment) > EPS)
+<a name="l04539"></a>04539     {
+<a name="l04540"></a>04540         <span class="comment">// adjust mask image</span>
+<a name="l04541"></a>04541         <span class="keywordtype">int</span> px_rejected = 0;
+<a name="l04542"></a>04542         <span class="keywordtype">double</span> msk_value = 0;
+<a name="l04543"></a>04543         check_nomsg(msk_value = cpl_image_get(imMask, x, y, &px_rejected));
+<a name="l04544"></a>04544         check_nomsg(cpl_image_set(imMask, x,y, msk_value - mask_adjustment));
+<a name="l04545"></a>04545     }
+<a name="l04546"></a>04546     <span class="comment">// get a result value for the point</span>
+<a name="l04547"></a>04547     check_nomsg(result = cpl_array_get_mean(parray));
+<a name="l04548"></a>04548     <span class="keywordflow">return</span> result;
+<a name="l04549"></a>04549     cleanup:
+<a name="l04550"></a>04550     sinfo_msg(<span class="stringliteral">"Error in kappa_sigma_array_with_mask"</span>);
+<a name="l04551"></a>04551     <span class="keywordflow">return</span> 0;
+<a name="l04552"></a>04552 }
+<a name="l04553"></a>04553 
+<a name="l04554"></a>04554 
+<a name="l04555"></a>04555 <span class="keywordtype">int</span> sinfo_coadd_with_ks_clip_optimized(
+<a name="l04556"></a>04556             <span class="keyword">const</span> <span class="keywordtype">int</span> z_min,
+<a name="l04557"></a>04557             <span class="keyword">const</span> <span class="keywordtype">int</span> z_max,
+<a name="l04558"></a>04558             <span class="keyword">const</span> <span class="keywordtype">int</span> n_cubes,
+<a name="l04559"></a>04559             <span class="keyword">const</span> <span class="keywordtype">double</span> kappa,
+<a name="l04560"></a>04560             <span class="keywordtype">int</span>* llx,
+<a name="l04561"></a>04561             <span class="keywordtype">int</span>* lly,
+<a name="l04562"></a>04562             <span class="keywordtype">double</span>* exptimes,
+<a name="l04563"></a>04563             cpl_imagelist* sky_mask,
+<a name="l04564"></a>04564             cpl_imagelist* mergedCube,
+<a name="l04565"></a>04565             cpl_imagelist** tmpcubes
+<a name="l04566"></a>04566             )
+<a name="l04567"></a>04567 {
+<a name="l04568"></a>04568   <span class="comment">/*</span>
+<a name="l04569"></a>04569 <span class="comment">    sinfo_msg("sinfo_coadd_with_ks_clip_optimized() z_min[%d] z_max[%d] n_cubes[%d] kappa[%f] llx[%d] lly[%d] exptimes[%d] sky_mask[%d]",</span>
+<a name="l04570"></a>04570 <span class="comment">            z_min, z_max, ilx, ily, n_cubes, kappa,llx, lly,exptimes,sky_mask);</span>
+<a name="l04571"></a>04571 <span class="comment">  */</span>
+<a name="l04572"></a>04572    <span class="keywordtype">int</span> result=0;
+<a name="l04573"></a>04573    check_nomsg(result=sinfo_kappa_sigma_offset_with_mask(z_min, z_max, n_cubes, tmpcubes, exptimes, mergedCube, llx, lly, sky_mask, kappa));
+<a name="l04574"></a>04574 
+<a name="l04575"></a>04575   cleanup:
+<a name="l04576"></a>04576 
+<a name="l04577"></a>04577     <span class="keywordflow">return</span> result;
+<a name="l04578"></a>04578 
+<a name="l04579"></a>04579 }
+<a name="l04580"></a>04580 
+<a name="l04581"></a>04581 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_kappa_sigma_offset_with_mask(
+<a name="l04582"></a>04582         <span class="keywordtype">int</span> z_min,
+<a name="l04583"></a>04583         <span class="keywordtype">int</span> z_max,
+<a name="l04584"></a>04584         <span class="keywordtype">int</span> nCubes,
+<a name="l04585"></a>04585         cpl_imagelist** inputCubes,
+<a name="l04586"></a>04586         <span class="keywordtype">double</span>* exptimes,
+<a name="l04587"></a>04587         cpl_imagelist* imResult,
+<a name="l04588"></a>04588         <span class="keywordtype">int</span>* global_offsetX,
+<a name="l04589"></a>04589         <span class="keywordtype">int</span>* global_offsetY,
+<a name="l04590"></a>04590         cpl_imagelist* sky_mask,
+<a name="l04591"></a>04591         <span class="keyword">const</span> <span class="keywordtype">double</span> kappa
+<a name="l04592"></a>04592         )
+<a name="l04593"></a>04593 {
+<a name="l04594"></a>04594     <span class="keyword">const</span> <span class="keywordtype">int</span> BIG_ENOUGH_INT = 65535;
+<a name="l04595"></a>04595     CubeDataVector*** indexX = 0;
+<a name="l04596"></a>04596     <span class="keywordtype">int</span> x = 0;
+<a name="l04597"></a>04597     <span class="keywordtype">int</span> y = 0;
+<a name="l04598"></a>04598     <span class="keywordtype">int</span> z = 0;
+<a name="l04599"></a>04599     <span class="keywordtype">int</span> iPlanesNumber = z_max - z_min;
+<a name="l04600"></a>04600     <span class="keywordtype">int</span> nIndexXbytes = 0;
+<a name="l04601"></a>04601     <span class="keywordtype">int</span> globalSizeX = 0 ;
+<a name="l04602"></a>04602     <span class="keywordtype">int</span> globalSizeY = 0;
+<a name="l04603"></a>04603 
+<a name="l04604"></a>04604     <span class="keywordtype">int</span> xmax = -BIG_ENOUGH_INT;
+<a name="l04605"></a>04605     <span class="keywordtype">int</span> ymax = -BIG_ENOUGH_INT;
+<a name="l04606"></a>04606     <span class="keywordtype">int</span> xmin = BIG_ENOUGH_INT;
+<a name="l04607"></a>04607     <span class="keywordtype">int</span> ymin = BIG_ENOUGH_INT;
+<a name="l04608"></a>04608     <span class="keywordtype">int</span>* offsetX = 0; <span class="comment">// local offset of the cubes, normalized</span>
+<a name="l04609"></a>04609     <span class="keywordtype">int</span>* offsetY = 0;
+<a name="l04610"></a>04610     <span class="comment">//sinfo_msg(" starting kappa-sigma clipping for cubes[%d] planes[%d]", nCubes, z_max - z_min );</span>
+<a name="l04611"></a>04611     <span class="comment">// determine size of the coadded cube</span>
+<a name="l04612"></a>04612         sinfo_check_rec_status(0);
+<a name="l04613"></a>04613     <span class="keywordflow">for</span> (z = 0; z < nCubes; z++)
+<a name="l04614"></a>04614     {
+<a name="l04615"></a>04615 
+<a name="l04616"></a>04616         cpl_imagelist* pCube = inputCubes[z];
+<a name="l04617"></a>04617         cpl_image* pImage = 0;
+<a name="l04618"></a>04618         <span class="keywordtype">int</span> localMaxX = 0;
+<a name="l04619"></a>04619         <span class="keywordtype">int</span> localMaxY = 0;
+<a name="l04620"></a>04620         <span class="keywordtype">int</span> localMinX = 0;
+<a name="l04621"></a>04621         <span class="keywordtype">int</span> localMinY = 0;
+<a name="l04622"></a>04622 
+<a name="l04623"></a>04623         pImage = cpl_imagelist_get(pCube, 0);
+<a name="l04624"></a>04624 
+<a name="l04625"></a>04625         localMaxX = cpl_image_get_size_x(pImage) + global_offsetX[z];
+<a name="l04626"></a>04626         localMaxY = cpl_image_get_size_y(pImage) + global_offsetY[z];
+<a name="l04627"></a>04627         localMinX = global_offsetX[z];
+<a name="l04628"></a>04628         localMinY = global_offsetY[z];
+<a name="l04629"></a>04629 
+<a name="l04630"></a>04630         <span class="keywordflow">if</span>(localMaxX > xmax) xmax = localMaxX;
+<a name="l04631"></a>04631         <span class="keywordflow">if</span>(localMaxY > ymax) ymax = localMaxY;
+<a name="l04632"></a>04632 
+<a name="l04633"></a>04633         <span class="keywordflow">if</span>(localMinX < xmin) xmin = localMinX;
+<a name="l04634"></a>04634         <span class="keywordflow">if</span>(localMinY < ymin) ymin = localMinY;
+<a name="l04635"></a>04635     }
+<a name="l04636"></a>04636         sinfo_check_rec_status(1);
+<a name="l04637"></a>04637 
+<a name="l04638"></a>04638     <span class="comment">// DFS09121 xmax and ymax could be more then output cube - check and adjust</span>
+<a name="l04639"></a>04639     {
+<a name="l04640"></a>04640         <span class="keywordtype">int</span> msize_x = 0;
+<a name="l04641"></a>04641         <span class="keywordtype">int</span> msize_y = 0;
+<a name="l04642"></a>04642         <span class="comment">//sinfo_msg("DFS09121 before:  xmax=%d ymax=%d", xmax, ymax);</span>
+<a name="l04643"></a>04643         cpl_image * pmaskimage = cpl_imagelist_get(sky_mask, 0);
+<a name="l04644"></a>04644         msize_x = cpl_image_get_size_x(pmaskimage);
+<a name="l04645"></a>04645         msize_y = cpl_image_get_size_y(pmaskimage);
+<a name="l04646"></a>04646         xmax = msize_x < xmax ? msize_x : xmax;
+<a name="l04647"></a>04647         ymax = msize_y < ymax ? msize_y : ymax;
+<a name="l04648"></a>04648         <span class="comment">//sinfo_msg("DFS09121 after:  xmax=%d ymax=%d", xmax, ymax);</span>
+<a name="l04649"></a>04649     }
+<a name="l04650"></a>04650     <span class="comment">// rely on the data received outside</span>
+<a name="l04651"></a>04651     globalSizeX = xmax;<span class="comment">// - xmin;</span>
+<a name="l04652"></a>04652     globalSizeY = ymax;<span class="comment">// - ymin;</span>
+<a name="l04653"></a>04653     <span class="comment">// calculate local offset</span>
+<a name="l04654"></a>04654     check_nomsg(offsetX = cpl_malloc(<span class="keyword">sizeof</span>(offsetX[0]) * nCubes));
+<a name="l04655"></a>04655     check_nomsg(offsetY = cpl_malloc(<span class="keyword">sizeof</span>(offsetY[0]) * nCubes));
+<a name="l04656"></a>04656         sinfo_check_rec_status(2);
+<a name="l04657"></a>04657     <span class="keywordflow">for</span> (z = 0; z < nCubes; z++) <span class="comment">// use the offset from the caller</span>
+<a name="l04658"></a>04658     {
+<a name="l04659"></a>04659         offsetX[z] = global_offsetX[z];<span class="comment">// - xmin;</span>
+<a name="l04660"></a>04660         offsetY[z] = global_offsetY[z];<span class="comment">// - ymin;</span>
+<a name="l04661"></a>04661 <span class="comment">//      sinfo_msg("for cube [%d] offset X[%d : %d] Y[%d : %d]", z, offsetX[z], global_offsetX[z], offsetY[z], global_offsetY[z]);</span>
+<a name="l04662"></a>04662     }
+<a name="l04663"></a>04663         sinfo_check_rec_status(3);
+<a name="l04664"></a>04664     <span class="comment">// Because of DFS09121, the allocated size is taken +1</span>
+<a name="l04665"></a>04665     nIndexXbytes = <span class="keyword">sizeof</span>(CubeDataVector**) * (globalSizeX+1 );
+<a name="l04666"></a>04666 <span class="comment">//  sinfo_msg("   kappa_sigma_offset, globalSizeX[%d] globalSizeY[%d] nIndexXbytes[%d]", globalSizeX, globalSizeY, nIndexXbytes);</span>
+<a name="l04667"></a>04667     indexX = cpl_malloc(nIndexXbytes);
+<a name="l04668"></a>04668     memset(&indexX[0], 0, (globalSizeX+1 )* <span class="keyword">sizeof</span>(indexX[0]));
+<a name="l04669"></a>04669     <span class="comment">// prepare result planes and mask</span>
+<a name="l04670"></a>04670 
+<a name="l04671"></a>04671     <span class="comment">// 1. Fill indexes - do it only for a 0 plane in the cube</span>
+<a name="l04672"></a>04672     <span class="keywordflow">for</span> (z = 0; z < nCubes; z++)
+<a name="l04673"></a>04673     {
+<a name="l04674"></a>04674         <span class="keywordtype">int</span> iCubeSizeX = 0;
+<a name="l04675"></a>04675         <span class="keywordtype">int</span> iCubeSizeY = 0;
+<a name="l04676"></a>04676         <span class="keywordtype">int</span> iOffsetX = 0;
+<a name="l04677"></a>04677         <span class="keywordtype">int</span> iOffsetY = 0;
+<a name="l04678"></a>04678 
+<a name="l04679"></a>04679         cpl_imagelist* pCube = inputCubes[z];
+<a name="l04680"></a>04680         cpl_image* pImage = 0;
+<a name="l04681"></a>04681         pImage = cpl_imagelist_get(pCube, 0);
+<a name="l04682"></a>04682 
+<a name="l04683"></a>04683         iCubeSizeX = cpl_image_get_size_x(pImage);
+<a name="l04684"></a>04684         iCubeSizeY = cpl_image_get_size_y(pImage);
+<a name="l04685"></a>04685         iOffsetX = offsetX[z];
+<a name="l04686"></a>04686         iOffsetY = offsetY[z];
+<a name="l04687"></a>04687 <span class="comment">//      sinfo_msg("   processing cube [%d] offsetX[%d] offsetY[%d] iCubeSizeX[%d] iCubeSizeY[%d]", z, iOffsetX, iOffsetY, iCubeSizeX, iCubeSizeY);</span>
+<a name="l04688"></a>04688         <span class="keywordflow">for</span> (x = 1; x <= iCubeSizeX; x++)
+<a name="l04689"></a>04689         {
+<a name="l04690"></a>04690             <span class="keywordtype">int</span> iGlobalX = x + iOffsetX;
+<a name="l04691"></a>04691 
+<a name="l04692"></a>04692             CubeDataVector** ppVector = 0;
+<a name="l04693"></a>04693             <span class="keywordflow">if</span> (indexX[iGlobalX - 1] == 0)
+<a name="l04694"></a>04694             {
+<a name="l04695"></a>04695                 <span class="comment">// Because of DFS09121, the allocated size is taken +1</span>
+<a name="l04696"></a>04696                 <span class="keywordtype">int</span> nBytes = <span class="keyword">sizeof</span>(CubeDataVector*) * (globalSizeY+1 );
+<a name="l04697"></a>04697                 ppVector= cpl_malloc(nBytes);
+<a name="l04698"></a>04698                 memset(&ppVector[0],0,(globalSizeY+1) * <span class="keyword">sizeof</span>(ppVector[0]));
+<a name="l04699"></a>04699                 indexX[iGlobalX - 1] = ppVector;
+<a name="l04700"></a>04700             }
+<a name="l04701"></a>04701             <span class="keywordflow">else</span>
+<a name="l04702"></a>04702             {
+<a name="l04703"></a>04703                 ppVector = indexX[iGlobalX - 1];
+<a name="l04704"></a>04704             }
+<a name="l04705"></a>04705             <span class="keywordflow">for</span> (y = 1; y <=iCubeSizeY; y++)
+<a name="l04706"></a>04706             {
+<a name="l04707"></a>04707                 CubeData* pCubeData = 0;
+<a name="l04708"></a>04708                 <span class="keywordtype">int</span> iGlobalY = y + iOffsetY;
+<a name="l04709"></a>04709                 CubeDataVector* pVector = ppVector[iGlobalY - 1];
+<a name="l04710"></a>04710                 <span class="keywordflow">if</span>(pVector == 0)
+<a name="l04711"></a>04711                 {
+<a name="l04712"></a>04712                     <span class="keywordtype">int</span> nbytes = <span class="keyword">sizeof</span>(CubeDataVector);
+<a name="l04713"></a>04713                     check_nomsg(pVector = cpl_malloc(nbytes));
+<a name="l04714"></a>04714                     ppVector[iGlobalY - 1] = pVector;
+<a name="l04715"></a>04715                     pVector->size = 0;
+<a name="l04716"></a>04716                     nbytes = <span class="keyword">sizeof</span>(CubeData*) * nCubes;
+<a name="l04717"></a>04717                     pVector->pdata = cpl_malloc(nbytes);
+<a name="l04718"></a>04718 <span class="comment">//                  memset(&pVector->pdata[0], 0, nCubes * sizeof(pVector->pdata[0]));</span>
+<a name="l04719"></a>04719                 }
+<a name="l04720"></a>04720                 pCubeData = cpl_malloc(<span class="keyword">sizeof</span>(CubeData));
+<a name="l04721"></a>04721                 pVector->pdata[(pVector->size)++] = pCubeData;
+<a name="l04722"></a>04722                 pCubeData->iCubeNumber = z;
+<a name="l04723"></a>04723                 pCubeData->iLocalX = x;
+<a name="l04724"></a>04724                 pCubeData->iLocalY = y;
+<a name="l04725"></a>04725             }
+<a name="l04726"></a>04726         }
+<a name="l04727"></a>04727     }
+<a name="l04728"></a>04728         sinfo_check_rec_status(4);
+<a name="l04729"></a>04729 
+<a name="l04730"></a>04730     <span class="comment">// 2. for each index value in global coordinates (x,y) call kappa-sigma</span>
+<a name="l04731"></a>04731     <span class="keywordflow">for</span> (x = 1; x <= globalSizeX; x++)
+<a name="l04732"></a>04732     {
+<a name="l04733"></a>04733         CubeDataVector** pDataX = indexX[x - 1];
+<a name="l04734"></a>04734         <span class="keywordflow">if</span> (pDataX)
+<a name="l04735"></a>04735         {
+<a name="l04736"></a>04736             <span class="keywordflow">for</span> (y = 1; y <= globalSizeY; y++)
+<a name="l04737"></a>04737             {
+<a name="l04738"></a>04738                 CubeDataVector* pDataY = pDataX[y - 1];
+<a name="l04739"></a>04739                 <span class="keywordflow">if</span> (pDataY && pDataY->size)
+<a name="l04740"></a>04740                 {
+<a name="l04741"></a>04741                     kappa_sigma_CubeDataVector(x, y, pDataY, imResult, inputCubes, sky_mask, iPlanesNumber, z_min, kappa, exptimes);
+<a name="l04742"></a>04742                 }
+<a name="l04743"></a>04743                 <span class="keywordflow">if</span> (pDataY)
+<a name="l04744"></a>04744                 {
+<a name="l04745"></a>04745                     check_nomsg(cpl_free(pDataY->pdata));
+<a name="l04746"></a>04746                     check_nomsg(cpl_free(pDataY));
+<a name="l04747"></a>04747                 }
+<a name="l04748"></a>04748             }
+<a name="l04749"></a>04749             check_nomsg(cpl_free(pDataX));
+<a name="l04750"></a>04750         }
+<a name="l04751"></a>04751     }
+<a name="l04752"></a>04752     sinfo_check_rec_status(5);
+<a name="l04753"></a>04753     cleanup:
+<a name="l04754"></a>04754     cpl_free(indexX);
+<a name="l04755"></a>04755     cpl_free(offsetX);
+<a name="l04756"></a>04756     cpl_free(offsetY);
+<a name="l04757"></a>04757     <span class="keywordflow">return</span> 0;
+<a name="l04758"></a>04758 
+<a name="l04759"></a>04759 }
+<a name="l04760"></a>04760 
+<a name="l04761"></a>04761 <span class="keywordtype">void</span> kappa_sigma_CubeDataVector(
+<a name="l04762"></a>04762         <span class="keywordtype">int</span> globalX,
+<a name="l04763"></a>04763         <span class="keywordtype">int</span> globalY,
+<a name="l04764"></a>04764         CubeDataVector* pCubeDataVector,
+<a name="l04765"></a>04765         cpl_imagelist* imlistResult,
+<a name="l04766"></a>04766         cpl_imagelist** input_cubes,
+<a name="l04767"></a>04767         cpl_imagelist* sky_mask,
+<a name="l04768"></a>04768         <span class="keywordtype">int</span> iPlanesNumber,
+<a name="l04769"></a>04769         <span class="keywordtype">int</span> z_min,
+<a name="l04770"></a>04770         <span class="keyword">const</span> <span class="keywordtype">double</span> kappa,
+<a name="l04771"></a>04771         <span class="keywordtype">double</span>* exptimes
+<a name="l04772"></a>04772         )
+<a name="l04773"></a>04773 {
+<a name="l04774"></a>04774     <span class="keywordtype">int</span> plane = 0;
+<a name="l04775"></a>04775     <span class="keywordtype">int</span> z = 0;
+<a name="l04776"></a>04776 
+<a name="l04777"></a>04777     <span class="comment">// iterate through all planes</span>
+<a name="l04778"></a>04778     cpl_array* pArray = 0;
+<a name="l04779"></a>04779     check_nomsg(pArray = cpl_array_new(pCubeDataVector->size, CPL_TYPE_DOUBLE));
+<a name="l04780"></a>04780 
+<a name="l04781"></a>04781 
+<a name="l04782"></a>04782     <span class="keywordflow">for</span> (plane = z_min; plane < z_min + iPlanesNumber; plane++)
+<a name="l04783"></a>04783     {
+<a name="l04784"></a>04784         <span class="keywordtype">double</span> val_msk = 0; <span class="comment">// value of the mask in the point</span>
+<a name="l04785"></a>04785         <span class="keywordtype">int</span> px = 0;
+<a name="l04786"></a>04786         cpl_image* imResult = 0;
+<a name="l04787"></a>04787         cpl_image* imMask = 0;
+<a name="l04788"></a>04788         <span class="keywordtype">double</span> mask_adjustment = 0;
+<a name="l04789"></a>04789         <span class="keywordtype">int</span> nValidPoints = 0;
+<a name="l04790"></a>04790         cpl_array_fill_window_invalid(pArray, 0, pCubeDataVector->size);
+<a name="l04791"></a>04791         check_nomsg(imMask = cpl_imagelist_get(sky_mask, plane - z_min));
+<a name="l04792"></a>04792         check_nomsg(val_msk = cpl_image_get(imMask, globalX, globalY, &px));
+<a name="l04793"></a>04793         <span class="keywordflow">for</span> (z = 0; z < pCubeDataVector->size; z++) <span class="comment">// through all cubes for that point - prepare the array</span>
+<a name="l04794"></a>04794         {
+<a name="l04795"></a>04795 
+<a name="l04796"></a>04796             cpl_imagelist* pCube = 0;
+<a name="l04797"></a>04797             CubeData* pCubeData = pCubeDataVector->pdata[z];
+<a name="l04798"></a>04798             pCube = input_cubes[pCubeData->iCubeNumber];
+<a name="l04799"></a>04799             <span class="keywordflow">if</span> (pCube)
+<a name="l04800"></a>04800             {
+<a name="l04801"></a>04801                 cpl_image* pImage = cpl_imagelist_get(pCube, plane - z_min);
+<a name="l04802"></a>04802 
+<a name="l04803"></a>04803                 <span class="keywordflow">if</span> (pImage)
+<a name="l04804"></a>04804                 {
+<a name="l04805"></a>04805                     <span class="keywordtype">int</span> is_rejected = 0;
+<a name="l04806"></a>04806                     <span class="keywordtype">double</span> value = 0;
+<a name="l04807"></a>04807                     check_nomsg(value = cpl_image_get(pImage, pCubeData->iLocalX, pCubeData->iLocalY, &is_rejected));
+<a name="l04808"></a>04808                     <span class="keywordflow">if</span> (!isnan(value))
+<a name="l04809"></a>04809                     {
+<a name="l04810"></a>04810                         check_nomsg(cpl_array_set(pArray, z, value));
+<a name="l04811"></a>04811                         ++nValidPoints;
+<a name="l04812"></a>04812                     }
+<a name="l04813"></a>04813                     <span class="keywordflow">else</span>
+<a name="l04814"></a>04814                     {
+<a name="l04815"></a>04815                         mask_adjustment += exptimes[z];
+<a name="l04816"></a>04816                     }
+<a name="l04817"></a>04817                 }
+<a name="l04818"></a>04818                 <span class="keywordflow">else</span>
+<a name="l04819"></a>04819                 {
+<a name="l04820"></a>04820                     sinfo_msg(<span class="stringliteral">"kappa_sigma_CubeDataVector() - pImage is null"</span>);
+<a name="l04821"></a>04821                 }
+<a name="l04822"></a>04822             }
+<a name="l04823"></a>04823         }
+<a name="l04824"></a>04824         <span class="keywordflow">if</span>(nValidPoints)
+<a name="l04825"></a>04825         {
+<a name="l04826"></a>04826            kappa_sigma_array_with_mask(pArray, pCubeDataVector->size, kappa, imMask, exptimes, globalX, globalY, mask_adjustment);
+<a name="l04827"></a>04827            check_nomsg(imResult = cpl_imagelist_get(imlistResult, plane));
+<a name="l04828"></a>04828            <span class="keywordflow">if</span> (imResult)
+<a name="l04829"></a>04829            {
+<a name="l04830"></a>04830               check_nomsg(cpl_image_set(imResult, globalX, globalY, cpl_array_get_mean(pArray)));
+<a name="l04831"></a>04831            }
+<a name="l04832"></a>04832            <span class="keywordflow">else</span>
+<a name="l04833"></a>04833            {
+<a name="l04834"></a>04834               sinfo_msg(<span class="stringliteral">"kappa_sigma_CubeDataVector() - imResult is null"</span>);
+<a name="l04835"></a>04835            }
+<a name="l04836"></a>04836         } <span class="keywordflow">else</span>
+<a name="l04837"></a>04837         {
+<a name="l04838"></a>04838             <span class="comment">// adjust the mask</span>
+<a name="l04839"></a>04839             check_nomsg(cpl_image_set(imMask, globalX,globalY, 0));
+<a name="l04840"></a>04840         }
+<a name="l04841"></a>04841     }
+<a name="l04842"></a>04842     <span class="keywordflow">for</span> (z = 0; z < pCubeDataVector->size; z++) <span class="comment">// through all cubes  - delete the data</span>
+<a name="l04843"></a>04843     {
+<a name="l04844"></a>04844         CubeData* pCubeData = pCubeDataVector->pdata[z];
+<a name="l04845"></a>04845         cpl_free(pCubeData);
+<a name="l04846"></a>04846     }
+<a name="l04847"></a>04847     cpl_array_delete(pArray);
+<a name="l04848"></a>04848     <span class="keywordflow">return</span>;
+<a name="l04849"></a>04849     cleanup:
+<a name="l04850"></a>04850 <span class="comment">//  sinfo_msg("   -----cleanup from kappa_sigma_CubeDataVector");</span>
+<a name="l04851"></a>04851     <span class="keywordflow">return</span>;
+<a name="l04852"></a>04852 }
+<a name="l04853"></a>04853 
+<a name="l04854"></a>04854 
+<a name="l04855"></a>04855 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l04856"></a>04856 sinfo_coadd_with_ks_clip(<span class="keyword">const</span> <span class="keywordtype">int</span> z_min,
+<a name="l04857"></a>04857             <span class="keyword">const</span> <span class="keywordtype">int</span> z_max,
+<a name="l04858"></a>04858             <span class="keyword">const</span> <span class="keywordtype">int</span> ilx,
+<a name="l04859"></a>04859             <span class="keyword">const</span> <span class="keywordtype">int</span> ily,
+<a name="l04860"></a>04860             <span class="keyword">const</span> <span class="keywordtype">int</span> n_cubes,
+<a name="l04861"></a>04861             <span class="keyword">const</span> <span class="keywordtype">double</span> kappa,
+<a name="l04862"></a>04862             <span class="keywordtype">int</span>* llx,
+<a name="l04863"></a>04863             <span class="keywordtype">int</span>* lly,
+<a name="l04864"></a>04864                         <span class="keywordtype">double</span>* exptimes,
+<a name="l04865"></a>04865             cpl_imagelist* mask,
+<a name="l04866"></a>04866             cpl_imagelist* mergedCube,
+<a name="l04867"></a>04867                         cpl_imagelist** tmpcubes)
+<a name="l04868"></a>04868 
+<a name="l04869"></a>04869 {
+<a name="l04870"></a>04870 
+<a name="l04871"></a>04871   <span class="keywordtype">int</span> m=0;
+<a name="l04872"></a>04872   <span class="keywordtype">int</span> x=0;
+<a name="l04873"></a>04873   <span class="keywordtype">int</span> y=0;
+<a name="l04874"></a>04874   <span class="keywordtype">int</span> z=0;
+<a name="l04875"></a>04875 
+<a name="l04876"></a>04876   <span class="keywordtype">int</span> mlx=0;
+<a name="l04877"></a>04877   <span class="keywordtype">int</span> mly=0;
+<a name="l04878"></a>04878   <span class="keywordtype">int</span> nc=0;
+<a name="l04879"></a>04879   <span class="keywordtype">int</span> olx=0;
+<a name="l04880"></a>04880   <span class="keywordtype">int</span> oly=0;
+<a name="l04881"></a>04881   <span class="keywordtype">int</span> posx=0;
+<a name="l04882"></a>04882   <span class="keywordtype">int</span> posy=0;
+<a name="l04883"></a>04883   <span class="keywordtype">int</span> i=0;
+<a name="l04884"></a>04884   <span class="keywordtype">int</span> nclip=0;
+<a name="l04885"></a>04885   <span class="keywordtype">int</span> ks=0;
+<a name="l04886"></a>04886 
+<a name="l04887"></a>04887   <span class="keywordtype">float</span> sig=0;
+<a name="l04888"></a>04888   <span class="keywordtype">float</span> med=0;
+<a name="l04889"></a>04889   <span class="keywordtype">float</span> ovr=0;
+<a name="l04890"></a>04890   <span class="keywordtype">float</span>  msk_sum=0;
+<a name="l04891"></a>04891   <span class="keywordtype">float</span>  val_msk_sum=0;
+<a name="l04892"></a>04892   <span class="keywordtype">float</span> avg=0;
+<a name="l04893"></a>04893 
+<a name="l04894"></a>04894   <span class="keywordtype">float</span>* pmdata=NULL;
+<a name="l04895"></a>04895   <span class="keywordtype">float</span>* podata=NULL;
+<a name="l04896"></a>04896   <span class="keywordtype">float</span>* ptdata=NULL;
+<a name="l04897"></a>04897   <span class="keywordtype">float</span>* pvdata=NULL;
+<a name="l04898"></a>04898 
+<a name="l04899"></a>04899   cpl_image* m_img=NULL;
+<a name="l04900"></a>04900   cpl_image* o_img=NULL;
+<a name="l04901"></a>04901   cpl_image* t_img=NULL;
+<a name="l04902"></a>04902   cpl_image* v_img=NULL;
+<a name="l04903"></a>04903 
+<a name="l04904"></a>04904 
+<a name="l04905"></a>04905   cpl_vector* val=NULL;
+<a name="l04906"></a>04906   cpl_vector* msk=NULL;
+<a name="l04907"></a>04907 
+<a name="l04908"></a>04908 
+<a name="l04909"></a>04909   o_img=cpl_imagelist_get(mergedCube,0);
+<a name="l04910"></a>04910   olx=cpl_image_get_size_x(o_img);
+<a name="l04911"></a>04911   oly=cpl_image_get_size_y(o_img);
+<a name="l04912"></a>04912 
+<a name="l04913"></a>04913   m=0;
+<a name="l04914"></a>04914   <span class="keywordflow">for</span> ( z = z_min; z < z_max ; z++ ) {
+<a name="l04915"></a>04915     m_img=cpl_imagelist_get(mask,z);
+<a name="l04916"></a>04916     pmdata=cpl_image_get_data_float(m_img);
+<a name="l04917"></a>04917     o_img=cpl_imagelist_get(mergedCube,z);
+<a name="l04918"></a>04918     podata=cpl_image_get_data_float(o_img);
+<a name="l04919"></a>04919     mlx=cpl_image_get_size_x(m_img);
+<a name="l04920"></a>04920     mly=cpl_image_get_size_y(m_img);
+<a name="l04921"></a>04921     <span class="comment">// go through the first image plane of the big data cube </span>
+<a name="l04922"></a>04922     <span class="keywordflow">for</span> ( y = 0 ; y < oly ; y++ ) {
+<a name="l04923"></a>04923       <span class="keywordflow">for</span> ( x = 0 ; x < olx ; x++ ) {
+<a name="l04924"></a>04924     avg=0;
+<a name="l04925"></a>04925     nc=0;
+<a name="l04926"></a>04926     <span class="comment">// computes nc </span>
+<a name="l04927"></a>04927     <span class="keywordflow">for</span> ( i = 0 ; i < n_cubes ; i++ ) {
+<a name="l04928"></a>04928       t_img=cpl_imagelist_get(tmpcubes[i],m);
+<a name="l04929"></a>04929       ptdata=cpl_image_get_data_float(t_img);
+<a name="l04930"></a>04930           <span class="keywordflow">if</span> ( y >= lly[i] && y < lly[i]+ily &&
+<a name="l04931"></a>04931                x >= llx[i] && x < llx[i]+ilx ) {
+<a name="l04932"></a>04932         posx = x - llx[i] ;
+<a name="l04933"></a>04933         posy = y - lly[i] ;
+<a name="l04934"></a>04934             <span class="keywordflow">if</span> (!isnan(ptdata[posx+posy*ilx]) &&
+<a name="l04935"></a>04935                        ptdata[posx+posy*ilx] != 0.) {
+<a name="l04936"></a>04936           nc++;
+<a name="l04937"></a>04937         }
+<a name="l04938"></a>04938       }
+<a name="l04939"></a>04939     }
+<a name="l04940"></a>04940         <span class="keywordflow">if</span>( nc > 0 ) {
+<a name="l04941"></a>04941 
+<a name="l04942"></a>04942       
+<a name="l04943"></a>04943       msk=cpl_vector_new(n_cubes);
+<a name="l04944"></a>04944       <span class="keywordflow">for</span> (i=0;i<n_cubes;i++) {
+<a name="l04945"></a>04945         cpl_vector_set(msk,i,1);
+<a name="l04946"></a>04946       }
+<a name="l04947"></a>04947 
+<a name="l04948"></a>04948       <span class="comment">// k-s clipping </span>
+<a name="l04949"></a>04949       nclip=0;
+<a name="l04950"></a>04950 
+<a name="l04951"></a>04951 
+<a name="l04952"></a>04952       <span class="keywordflow">for</span> (ks=0;ks<nc;ks++) {
+<a name="l04953"></a>04953         sig=0;
+<a name="l04954"></a>04954         med=0;
+<a name="l04955"></a>04955         ovr=0;
+<a name="l04956"></a>04956         <span class="keywordflow">if</span>(nc-nclip >0) {
+<a name="l04957"></a>04957           val=cpl_vector_new(nc-nclip);
+<a name="l04958"></a>04958         }
+<a name="l04959"></a>04959         <span class="comment">// fill val </span>
+<a name="l04960"></a>04960         <span class="keywordflow">for</span> ( i = 0 ; i < n_cubes ; i++ ) {
+<a name="l04961"></a>04961           t_img=cpl_imagelist_get(tmpcubes[i],m);
+<a name="l04962"></a>04962           ptdata=cpl_image_get_data_float(t_img);
+<a name="l04963"></a>04963               <span class="keywordflow">if</span> ( y >= lly[i] && y < lly[i]+ily &&
+<a name="l04964"></a>04964                    x >= llx[i] && x < llx[i]+ilx ) {
+<a name="l04965"></a>04965         posx = x - llx[i] ;
+<a name="l04966"></a>04966         posy = y - lly[i] ;
+<a name="l04967"></a>04967                 <span class="keywordflow">if</span> (!isnan(ptdata[posx+posy*ilx]) &&
+<a name="l04968"></a>04968                            ptdata[posx+posy*ilx] != 0. &&
+<a name="l04969"></a>04969             (cpl_vector_get(msk,i) != 0)) {
+<a name="l04970"></a>04970           cpl_vector_set(val,ovr,(<span class="keywordtype">double</span>)ptdata[posx+posy*ilx]);
+<a name="l04971"></a>04971           ovr++;
+<a name="l04972"></a>04972         }
+<a name="l04973"></a>04973           }
+<a name="l04974"></a>04974         }
+<a name="l04975"></a>04975 
+<a name="l04976"></a>04976         <span class="comment">// get avg, med, sig </span>
+<a name="l04977"></a>04977         <span class="keywordflow">if</span>(ovr>0) {
+<a name="l04978"></a>04978           avg=cpl_vector_get_mean(val);
+<a name="l04979"></a>04979           med=cpl_vector_get_median_const(val);
+<a name="l04980"></a>04980           <span class="keywordflow">if</span>(ovr>1) {
+<a name="l04981"></a>04981         sig=cpl_vector_get_stdev(val);
+<a name="l04982"></a>04982           } <span class="keywordflow">else</span> {
+<a name="l04983"></a>04983         sig=0;
+<a name="l04984"></a>04984           }
+<a name="l04985"></a>04985           cpl_vector_delete(val);
+<a name="l04986"></a>04986         }
+<a name="l04987"></a>04987 
+<a name="l04988"></a>04988         <span class="keywordflow">for</span> ( i = 0 ; i < n_cubes ; i++ ) {
+<a name="l04989"></a>04989           t_img=cpl_imagelist_get(tmpcubes[i],m);
+<a name="l04990"></a>04990           ptdata=cpl_image_get_data_float(t_img);
+<a name="l04991"></a>04991           <span class="comment">// Do k-s clipping at each pixel </span>
+<a name="l04992"></a>04992               <span class="keywordflow">if</span> ( y >= lly[i] && y < lly[i]+ily &&
+<a name="l04993"></a>04993                    x >= llx[i] && x < llx[i]+ilx ) {
+<a name="l04994"></a>04994         posx = x - llx[i] ;
+<a name="l04995"></a>04995         posy = y - lly[i] ;
+<a name="l04996"></a>04996                 <span class="keywordflow">if</span> (!isnan(ptdata[posx+posy*ilx]) &&
+<a name="l04997"></a>04997                            ptdata[posx+posy*ilx] != 0. &&
+<a name="l04998"></a>04998             (cpl_vector_get(msk,i) != 0)) {
+<a name="l04999"></a>04999           <span class="keywordflow">if</span>(abs((ptdata[posx+posy*ilx]-med))> kappa*sig) {
+<a name="l05000"></a>05000                     ptdata[posx+posy*ilx]=0;
+<a name="l05001"></a>05001             pmdata[x+y*mlx] -= exptimes[i]  ;
+<a name="l05002"></a>05002             cpl_vector_set(msk,i,0);
+<a name="l05003"></a>05003             nclip++;
+<a name="l05004"></a>05004           }
+<a name="l05005"></a>05005         }
+<a name="l05006"></a>05006           }
+<a name="l05007"></a>05007         }
+<a name="l05008"></a>05008       } <span class="comment">// end of k-s clipping </span>
+<a name="l05009"></a>05009 
+<a name="l05010"></a>05010       msk_sum=0;
+<a name="l05011"></a>05011       val_msk_sum=0;
+<a name="l05012"></a>05012       <span class="keywordflow">for</span> ( i = 0 ; i < n_cubes ; i++ ) {
+<a name="l05013"></a>05013         v_img=cpl_imagelist_get(tmpcubes[i],m);
+<a name="l05014"></a>05014         pvdata=cpl_image_get_data_float(v_img);
+<a name="l05015"></a>05015         <span class="comment">// computes sky at each point </span>
+<a name="l05016"></a>05016             <span class="keywordflow">if</span> ( y >= lly[i] && y < lly[i]+ily &&
+<a name="l05017"></a>05017                  x >= llx[i] && x < llx[i]+ilx ) {
+<a name="l05018"></a>05018           posx = x - llx[i] ;
+<a name="l05019"></a>05019           posy = y - lly[i] ;
+<a name="l05020"></a>05020               <span class="comment">//sinfo_msg_warning("llx[%d]=%d lly[%d],=%d",i,llx[i],i,lly[i]);</span>
+<a name="l05021"></a>05021               <span class="comment">//sinfo_msg_warning("posx=%d posy=%d",posx,posy);</span>
+<a name="l05022"></a>05022               <span class="keywordflow">if</span> (!isnan(pvdata[posx+posy*ilx]) &&
+<a name="l05023"></a>05023                          pvdata[posx+posy*ilx] != 0. &&
+<a name="l05024"></a>05024           (cpl_vector_get(msk,i) != 0)) {
+<a name="l05025"></a>05025         msk_sum+=pmdata[x+y*mlx];
+<a name="l05026"></a>05026                 val_msk_sum+=pvdata[posx+posy*ilx]*
+<a name="l05027"></a>05027           pmdata[x+y*mlx];
+<a name="l05028"></a>05028           }
+<a name="l05029"></a>05029         }
+<a name="l05030"></a>05030       }
+<a name="l05031"></a>05031       podata[x+y*olx]=val_msk_sum/msk_sum;
+<a name="l05032"></a>05032       cpl_vector_delete(msk);
+<a name="l05033"></a>05033       <span class="comment">/*</span>
+<a name="l05034"></a>05034 <span class="comment">      sinfo_ks_clip(n_cubes,nc,ilx,ily,kappa,llx,lly,exptimes,</span>
+<a name="l05035"></a>05035 <span class="comment">            tmpcubes,podata,pmdata,x,y,m,mlx,oly);</span>
+<a name="l05036"></a>05036 <span class="comment"></span>
+<a name="l05037"></a>05037 <span class="comment">      */</span>
+<a name="l05038"></a>05038 
+<a name="l05039"></a>05039     } <span class="comment">// end check if overlap nc >0  </span>
+<a name="l05040"></a>05040       } <span class="comment">// end loop over x </span>
+<a name="l05041"></a>05041     } <span class="comment">// end loop over y </span>
+<a name="l05042"></a>05042     m++;
+<a name="l05043"></a>05043   } <span class="comment">// end loop over z </span>
+<a name="l05044"></a>05044 
+<a name="l05045"></a>05045   <span class="keywordflow">return</span> 0;
+<a name="l05046"></a>05046 
+<a name="l05047"></a>05047 
+<a name="l05048"></a>05048 }
+<a name="l05049"></a>05049 
+<a name="l05050"></a>05050 
+<a name="l05051"></a>05051 
+<a name="l05052"></a>05052 
+<a name="l05053"></a>05053 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l05054"></a>05054 sinfo_compute_contributes_at_pos(cpl_imagelist** tmpcubes, 
+<a name="l05055"></a>05055                                  <span class="keywordtype">int</span>* llx, <span class="keywordtype">int</span>* lly, 
+<a name="l05056"></a>05056                                  <span class="keyword">const</span> <span class="keywordtype">int</span> x, <span class="keyword">const</span> <span class="keywordtype">int</span> y,
+<a name="l05057"></a>05057                                  <span class="keyword">const</span> <span class="keywordtype">int</span> ilx, <span class="keyword">const</span> <span class="keywordtype">int</span> ily, 
+<a name="l05058"></a>05058                                  <span class="keyword">const</span> <span class="keywordtype">int</span> m,<span class="keyword">const</span> <span class="keywordtype">int</span> n_cubes)
+<a name="l05059"></a>05059 {
+<a name="l05060"></a>05060 
+<a name="l05061"></a>05061    <span class="keywordtype">int</span> result=0;
+<a name="l05062"></a>05062    <span class="keywordtype">int</span> i=0;
+<a name="l05063"></a>05063    <span class="keywordtype">int</span> lox=0;
+<a name="l05064"></a>05064    <span class="keywordtype">int</span> loy=0;
+<a name="l05065"></a>05065    <span class="keywordtype">int</span> upx=0;
+<a name="l05066"></a>05066    <span class="keywordtype">int</span> upy=0;
+<a name="l05067"></a>05067    <span class="keywordtype">int</span> post=0;
+<a name="l05068"></a>05068    <span class="keywordtype">int</span> posx=0;
+<a name="l05069"></a>05069    <span class="keywordtype">int</span> posy=0;
+<a name="l05070"></a>05070 
+<a name="l05071"></a>05071    <span class="keywordtype">float</span>* ptdata=NULL;
+<a name="l05072"></a>05072    cpl_image* t_img=NULL;
+<a name="l05073"></a>05073   
+<a name="l05074"></a>05074  
+<a name="l05075"></a>05075    <span class="comment">/* computes nc the number of intensity contributes from </span>
+<a name="l05076"></a>05076 <span class="comment">      each overlapping cube point intensity at x,y</span>
+<a name="l05077"></a>05077 <span class="comment">   */</span>
+<a name="l05078"></a>05078    <span class="keywordflow">for</span> ( i = 0 ; i < n_cubes ; i++ ) {
+<a name="l05079"></a>05079       t_img=cpl_imagelist_get(tmpcubes[i],m);
+<a name="l05080"></a>05080       ptdata=cpl_image_get_data_float(t_img);
+<a name="l05081"></a>05081       lox=llx[i];
+<a name="l05082"></a>05082       loy=lly[i];
+<a name="l05083"></a>05083       upx=llx[i]+ilx;
+<a name="l05084"></a>05084       upy=lly[i]+ily;
+<a name="l05085"></a>05085 
+<a name="l05086"></a>05086       <span class="keywordflow">if</span> ( y >= loy && y < upy && x >= lox && x < upx ) {
+<a name="l05087"></a>05087          posx = x - lox;
+<a name="l05088"></a>05088          posy = y - loy;
+<a name="l05089"></a>05089          post = posx+posy*ilx;
+<a name="l05090"></a>05090 
+<a name="l05091"></a>05091          <span class="keywordflow">if</span> (!isnan(ptdata[post]) && ptdata[post] != 0.) {
+<a name="l05092"></a>05092             result++;
+<a name="l05093"></a>05093          }
+<a name="l05094"></a>05094       }
+<a name="l05095"></a>05095    }
+<a name="l05096"></a>05096 
+<a name="l05097"></a>05097 
+<a name="l05098"></a>05098    <span class="keywordflow">return</span> result;
+<a name="l05099"></a>05099 
+<a name="l05100"></a>05100 }
+<a name="l05101"></a>05101 
+<a name="l05102"></a>05102 
+<a name="l05103"></a>05103 
+<a name="l05104"></a>05104 
+<a name="l05105"></a>05105 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l05106"></a>05106 sinfo_cubes_coadd_with_ks_clip(cpl_imagelist** tmpcubes, 
+<a name="l05107"></a>05107                                <span class="keyword">const</span> <span class="keywordtype">int</span> n_cubes,<span class="keyword">const</span> <span class="keywordtype">int</span> nc,
+<a name="l05108"></a>05108                                <span class="keyword">const</span> <span class="keywordtype">int</span> x, <span class="keyword">const</span> <span class="keywordtype">int</span> y, <span class="keyword">const</span> <span class="keywordtype">int</span> m,
+<a name="l05109"></a>05109                                <span class="keywordtype">int</span>* llx, <span class="keywordtype">int</span>* lly, 
+<a name="l05110"></a>05110                                <span class="keyword">const</span> <span class="keywordtype">int</span> ilx, <span class="keyword">const</span> <span class="keywordtype">int</span> ily,
+<a name="l05111"></a>05111                                <span class="keyword">const</span> <span class="keywordtype">double</span> kappa, 
+<a name="l05112"></a>05112                                <span class="keywordtype">double</span>* exptimes, <span class="keywordtype">float</span>** pmdata, 
+<a name="l05113"></a>05113                                cpl_vector** msk, <span class="keyword">const</span> <span class="keywordtype">int</span> mlx)
+<a name="l05114"></a>05114 
+<a name="l05115"></a>05115 
+<a name="l05116"></a>05116 {
+<a name="l05117"></a>05117 
+<a name="l05118"></a>05118  
+<a name="l05119"></a>05119    cpl_vector* val=NULL;
+<a name="l05120"></a>05120    cpl_image* t_img=NULL;
+<a name="l05121"></a>05121 
+<a name="l05122"></a>05122    <span class="keywordtype">int</span> i=0;
+<a name="l05123"></a>05123    <span class="keywordtype">int</span> nclip=0;
+<a name="l05124"></a>05124    <span class="keywordtype">int</span> ks=0;
+<a name="l05125"></a>05125    
+<a name="l05126"></a>05126    <span class="keywordtype">int</span> lox=0;
+<a name="l05127"></a>05127    <span class="keywordtype">int</span> loy=0;
+<a name="l05128"></a>05128    <span class="keywordtype">int</span> upx=0;
+<a name="l05129"></a>05129    <span class="keywordtype">int</span> upy=0;
+<a name="l05130"></a>05130 
+<a name="l05131"></a>05131    <span class="keywordtype">int</span> posx=0;
+<a name="l05132"></a>05132    <span class="keywordtype">int</span> posy=0;
+<a name="l05133"></a>05133    <span class="keywordtype">int</span> post=0;
+<a name="l05134"></a>05134 
+<a name="l05135"></a>05135    <span class="keywordtype">int</span> ovr=0;
+<a name="l05136"></a>05136 
+<a name="l05137"></a>05137    <span class="keywordtype">float</span> sig=0;
+<a name="l05138"></a>05138    <span class="keywordtype">float</span> avg=0;
+<a name="l05139"></a>05139    <span class="keywordtype">float</span> med=0;
+<a name="l05140"></a>05140 
+<a name="l05141"></a>05141    <span class="keywordtype">float</span>* ptdata=NULL;
+<a name="l05142"></a>05142    
+<a name="l05143"></a>05143 
+<a name="l05144"></a>05144    <span class="comment">// k-s clipping </span>
+<a name="l05145"></a>05145    nclip=0;
+<a name="l05146"></a>05146 
+<a name="l05147"></a>05147 
+<a name="l05148"></a>05148    <span class="keywordflow">for</span> (ks=0;ks<nc;ks++) {
+<a name="l05149"></a>05149       sig=0;
+<a name="l05150"></a>05150       med=0;
+<a name="l05151"></a>05151       ovr=0;
+<a name="l05152"></a>05152       <span class="keywordflow">if</span>(nc-nclip >0) {
+<a name="l05153"></a>05153          check_nomsg(val=cpl_vector_new(nc-nclip));
+<a name="l05154"></a>05154       }
+<a name="l05155"></a>05155       <span class="comment">// fill val </span>
+<a name="l05156"></a>05156       <span class="keywordflow">for</span> ( i = 0 ; i < n_cubes ; i++ ) {
+<a name="l05157"></a>05157          check_nomsg(t_img=cpl_imagelist_get(tmpcubes[i],m));
+<a name="l05158"></a>05158          check_nomsg(ptdata=cpl_image_get_data_float(t_img));
+<a name="l05159"></a>05159 
+<a name="l05160"></a>05160          lox=llx[i];
+<a name="l05161"></a>05161          loy=lly[i];
+<a name="l05162"></a>05162          upx=llx[i]+ilx;
+<a name="l05163"></a>05163          upy=lly[i]+ily;
+<a name="l05164"></a>05164 
+<a name="l05165"></a>05165          <span class="keywordflow">if</span> ( y >= loy && y < upy && x >= lox && x < upx ) {
+<a name="l05166"></a>05166             posx = x - lox ;
+<a name="l05167"></a>05167             posy = y - loy ;
+<a name="l05168"></a>05168             post=posx+posy*ilx;
+<a name="l05169"></a>05169 
+<a name="l05170"></a>05170             <span class="keywordflow">if</span> (!isnan(ptdata[post]) && ptdata[post] != 0. &&
+<a name="l05171"></a>05171                 (cpl_vector_get(*msk,i) != 0)) {
+<a name="l05172"></a>05172                cpl_vector_set(val,ovr,(<span class="keywordtype">double</span>)ptdata[post]);
+<a name="l05173"></a>05173                ovr++;
+<a name="l05174"></a>05174             }
+<a name="l05175"></a>05175          }
+<a name="l05176"></a>05176       }
+<a name="l05177"></a>05177 
+<a name="l05178"></a>05178       <span class="comment">// get avg, med, sig </span>
+<a name="l05179"></a>05179       <span class="keywordflow">if</span>(ovr>0) {
+<a name="l05180"></a>05180          check_nomsg(avg=cpl_vector_get_mean(val));
+<a name="l05181"></a>05181          med=cpl_vector_get_median_const(val);
+<a name="l05182"></a>05182          <span class="keywordflow">if</span>(ovr>1) {
+<a name="l05183"></a>05183             sig=cpl_vector_get_stdev(val);
+<a name="l05184"></a>05184          } <span class="keywordflow">else</span> {
+<a name="l05185"></a>05185             sig=0;
+<a name="l05186"></a>05186          }
+<a name="l05187"></a>05187          cpl_vector_delete(val);
+<a name="l05188"></a>05188       }
+<a name="l05189"></a>05189 
+<a name="l05190"></a>05190       <span class="keywordflow">for</span> ( i = 0 ; i < n_cubes ; i++ ) {
+<a name="l05191"></a>05191          t_img=cpl_imagelist_get(tmpcubes[i],m);
+<a name="l05192"></a>05192          ptdata=cpl_image_get_data_float(t_img);
+<a name="l05193"></a>05193 
+<a name="l05194"></a>05194          lox=llx[i];
+<a name="l05195"></a>05195          loy=lly[i];
+<a name="l05196"></a>05196          upx=llx[i]+ilx;
+<a name="l05197"></a>05197          upy=lly[i]+ily;
+<a name="l05198"></a>05198 
+<a name="l05199"></a>05199          <span class="comment">// Do k-s clipping at each pixel </span>
+<a name="l05200"></a>05200          <span class="keywordflow">if</span> ( y >= loy && y < upy && x >= lox && x < upx ) {
+<a name="l05201"></a>05201             posx = x - lox ;
+<a name="l05202"></a>05202             posy = y - loy ;
+<a name="l05203"></a>05203             post = posx+posy*ilx;
+<a name="l05204"></a>05204             <span class="keywordflow">if</span> (!isnan(ptdata[post]) && ptdata[post] != 0. &&
+<a name="l05205"></a>05205                 (cpl_vector_get(*msk,i) != 0)) {
+<a name="l05206"></a>05206                <span class="keywordflow">if</span>( abs( (ptdata[post]-med) ) > kappa*sig ) {
+<a name="l05207"></a>05207                   ptdata[post]=0;
+<a name="l05208"></a>05208                   (*pmdata)[x+y*mlx] -= exptimes[i]  ;
+<a name="l05209"></a>05209                   check_nomsg(cpl_vector_set(*msk,i,0));
+<a name="l05210"></a>05210                   nclip++;
+<a name="l05211"></a>05211                }
+<a name="l05212"></a>05212             }
+<a name="l05213"></a>05213          }
+<a name="l05214"></a>05214       }
+<a name="l05215"></a>05215    } <span class="comment">// end of k-s clipping </span>
+<a name="l05216"></a>05216 
+<a name="l05217"></a>05217   cleanup:
+<a name="l05218"></a>05218    <span class="keywordflow">return</span> 0;
+<a name="l05219"></a>05219 }
+<a name="l05220"></a>05220 
+<a name="l05243"></a>05243 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l05244"></a>05244 sinfo_coadd_with_ks_clip2(<span class="keyword">const</span> <span class="keywordtype">int</span> z_min,
+<a name="l05245"></a>05245             <span class="keyword">const</span> <span class="keywordtype">int</span> z_max,
+<a name="l05246"></a>05246             <span class="keyword">const</span> <span class="keywordtype">int</span> ilx,
+<a name="l05247"></a>05247             <span class="keyword">const</span> <span class="keywordtype">int</span> ily,
+<a name="l05248"></a>05248             <span class="keyword">const</span> <span class="keywordtype">int</span> n_cubes,
+<a name="l05249"></a>05249             <span class="keyword">const</span> <span class="keywordtype">double</span> kappa,
+<a name="l05250"></a>05250             <span class="keywordtype">int</span>* llx,
+<a name="l05251"></a>05251             <span class="keywordtype">int</span>* lly,
+<a name="l05252"></a>05252                         <span class="keywordtype">double</span>* exptimes,
+<a name="l05253"></a>05253             cpl_imagelist* mask,
+<a name="l05254"></a>05254             cpl_imagelist* mergedCube,
+<a name="l05255"></a>05255                         cpl_imagelist** tmpcubes)
+<a name="l05256"></a>05256 
+<a name="l05257"></a>05257 {
+<a name="l05258"></a>05258 
+<a name="l05259"></a>05259   <span class="keywordtype">int</span> m=0;
+<a name="l05260"></a>05260   <span class="keywordtype">int</span> x=0;
+<a name="l05261"></a>05261   <span class="keywordtype">int</span> y=0;
+<a name="l05262"></a>05262   <span class="keywordtype">int</span> z=0;
+<a name="l05263"></a>05263 
+<a name="l05264"></a>05264   <span class="keywordtype">int</span> mlx=0;
+<a name="l05265"></a>05265   <span class="keywordtype">int</span> mly=0;
+<a name="l05266"></a>05266   <span class="keywordtype">int</span> nc=0;
+<a name="l05267"></a>05267   <span class="keywordtype">int</span> olx=0;
+<a name="l05268"></a>05268   <span class="keywordtype">int</span> oly=0;
+<a name="l05269"></a>05269   <span class="keywordtype">int</span> posx=0;
+<a name="l05270"></a>05270   <span class="keywordtype">int</span> posy=0;
+<a name="l05271"></a>05271   <span class="keywordtype">int</span> i=0;
+<a name="l05272"></a>05272 
+<a name="l05273"></a>05273   <span class="keywordtype">float</span>  msk_sum=0;
+<a name="l05274"></a>05274   <span class="keywordtype">float</span>  val_msk_sum=0;
+<a name="l05275"></a>05275   <span class="keywordtype">float</span> avg=0;
+<a name="l05276"></a>05276 
+<a name="l05277"></a>05277   <span class="keywordtype">float</span>* pmdata=NULL;
+<a name="l05278"></a>05278   <span class="keywordtype">float</span>* podata=NULL;
+<a name="l05279"></a>05279   <span class="keywordtype">float</span>* pvdata=NULL;
+<a name="l05280"></a>05280 
+<a name="l05281"></a>05281   cpl_image* m_img=NULL;
+<a name="l05282"></a>05282   cpl_image* o_img=NULL;
+<a name="l05283"></a>05283   cpl_image* v_img=NULL;
+<a name="l05284"></a>05284 
+<a name="l05285"></a>05285 
+<a name="l05286"></a>05286   cpl_vector* msk=NULL;
+<a name="l05287"></a>05287 
+<a name="l05288"></a>05288 
+<a name="l05289"></a>05289   o_img=cpl_imagelist_get(mergedCube,0);
+<a name="l05290"></a>05290   olx=cpl_image_get_size_x(o_img);
+<a name="l05291"></a>05291   oly=cpl_image_get_size_y(o_img);
+<a name="l05292"></a>05292 
+<a name="l05293"></a>05293   m=0;
+<a name="l05294"></a>05294   <span class="keywordflow">for</span> ( z = z_min; z < z_max ; z++ ) {
+<a name="l05295"></a>05295     m_img=cpl_imagelist_get(mask,z);
+<a name="l05296"></a>05296     pmdata=cpl_image_get_data_float(m_img);
+<a name="l05297"></a>05297     o_img=cpl_imagelist_get(mergedCube,z);
+<a name="l05298"></a>05298     podata=cpl_image_get_data_float(o_img);
+<a name="l05299"></a>05299     mlx=cpl_image_get_size_x(m_img);
+<a name="l05300"></a>05300     mly=cpl_image_get_size_y(m_img);
+<a name="l05301"></a>05301     <span class="comment">// go through the first image plane of the big data cube </span>
+<a name="l05302"></a>05302     <span class="keywordflow">for</span> ( y = 0 ; y < oly ; y++ ) {
+<a name="l05303"></a>05303       <span class="keywordflow">for</span> ( x = 0 ; x < olx ; x++ ) {
+<a name="l05304"></a>05304     avg=0;
+<a name="l05305"></a>05305     nc=0;
+<a name="l05306"></a>05306     <span class="comment">// computes nc </span>
+<a name="l05307"></a>05307 
+<a name="l05308"></a>05308         nc=sinfo_compute_contributes_at_pos(tmpcubes,llx,lly,x,y,
+<a name="l05309"></a>05309                                             ilx,ily,m,n_cubes);
+<a name="l05310"></a>05310 
+<a name="l05311"></a>05311         <span class="keywordflow">if</span>( nc > 0 ) {
+<a name="l05312"></a>05312 
+<a name="l05313"></a>05313       
+<a name="l05314"></a>05314       msk=cpl_vector_new(n_cubes);
+<a name="l05315"></a>05315       <span class="keywordflow">for</span> (i=0;i<n_cubes;i++) {
+<a name="l05316"></a>05316         cpl_vector_set(msk,i,1);
+<a name="l05317"></a>05317       }
+<a name="l05318"></a>05318 
+<a name="l05319"></a>05319 
+<a name="l05320"></a>05320            sinfo_cubes_coadd_with_ks_clip(tmpcubes, n_cubes,nc,x,y,m,
+<a name="l05321"></a>05321                                           llx,lly,ilx,ily,kappa, 
+<a name="l05322"></a>05322                                           exptimes,&pmdata, &msk,mlx);
+<a name="l05323"></a>05323 
+<a name="l05324"></a>05324       msk_sum=0;
+<a name="l05325"></a>05325       val_msk_sum=0;
+<a name="l05326"></a>05326       <span class="keywordflow">for</span> ( i = 0 ; i < n_cubes ; i++ ) {
+<a name="l05327"></a>05327         v_img=cpl_imagelist_get(tmpcubes[i],m);
+<a name="l05328"></a>05328         pvdata=cpl_image_get_data_float(v_img);
+<a name="l05329"></a>05329         <span class="comment">// computes sky at each point </span>
+<a name="l05330"></a>05330             <span class="keywordflow">if</span> ( y >= lly[i] && y < lly[i]+ily &&
+<a name="l05331"></a>05331                  x >= llx[i] && x < llx[i]+ilx ) {
+<a name="l05332"></a>05332           posx = x - llx[i] ;
+<a name="l05333"></a>05333           posy = y - lly[i] ;
+<a name="l05334"></a>05334               <span class="comment">//sinfo_msg_warning("llx[%d]=%d lly[%d],=%d",i,llx[i],i,lly[i]);</span>
+<a name="l05335"></a>05335               <span class="comment">//sinfo_msg_warning("posx=%d posy=%d",posx,posy);</span>
+<a name="l05336"></a>05336               <span class="keywordflow">if</span> (!isnan(pvdata[posx+posy*ilx]) &&
+<a name="l05337"></a>05337                          pvdata[posx+posy*ilx] != 0. &&
+<a name="l05338"></a>05338           (cpl_vector_get(msk,i) != 0)) {
+<a name="l05339"></a>05339         msk_sum+=pmdata[x+y*mlx];
+<a name="l05340"></a>05340                 val_msk_sum+=pvdata[posx+posy*ilx]*
+<a name="l05341"></a>05341           pmdata[x+y*mlx];
+<a name="l05342"></a>05342           }
+<a name="l05343"></a>05343         }
+<a name="l05344"></a>05344       }
+<a name="l05345"></a>05345       podata[x+y*olx]=val_msk_sum/msk_sum;
+<a name="l05346"></a>05346       cpl_vector_delete(msk);
+<a name="l05347"></a>05347       <span class="comment">/*</span>
+<a name="l05348"></a>05348 <span class="comment">      sinfo_ks_clip(n_cubes,nc,ilx,ily,kappa,llx,lly,exptimes,</span>
+<a name="l05349"></a>05349 <span class="comment">            tmpcubes,podata,pmdata,x,y,m,mlx,oly);</span>
+<a name="l05350"></a>05350 <span class="comment"></span>
+<a name="l05351"></a>05351 <span class="comment">      */</span>
+<a name="l05352"></a>05352 
+<a name="l05353"></a>05353     } <span class="comment">// end check if overlap nc >0  </span>
+<a name="l05354"></a>05354       } <span class="comment">// end loop over x </span>
+<a name="l05355"></a>05355     } <span class="comment">// end loop over y </span>
+<a name="l05356"></a>05356     m++;
+<a name="l05357"></a>05357   } <span class="comment">// end loop over z </span>
+<a name="l05358"></a>05358 
+<a name="l05359"></a>05359   <span class="keywordflow">return</span> 0;
+<a name="l05360"></a>05360 
+<a name="l05361"></a>05361 
+<a name="l05362"></a>05362 }
+<a name="l05363"></a>05363 
+<a name="l05364"></a>05364 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__new__cube__ops_8h_source.html b/html/sinfo__new__cube__ops_8h_source.html
new file mode 100644
index 0000000..ed0a715
--- /dev/null
+++ b/html/sinfo__new__cube__ops_8h_source.html
@@ -0,0 +1,316 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_new_cube_ops.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_new_cube_ops.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#ifndef SINFO_NEW_CUBE_OPS_H</span>
+<a name="l00002"></a>00002 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_NEW_CUBE_OPS_H</span>
+<a name="l00003"></a>00003 <span class="preprocessor"></span><span class="comment">/*</span>
+<a name="l00004"></a>00004 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00005"></a>00005 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00006"></a>00006 <span class="comment"> *</span>
+<a name="l00007"></a>00007 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00008"></a>00008 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00009"></a>00009 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00010"></a>00010 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00011"></a>00011 <span class="comment"> *</span>
+<a name="l00012"></a>00012 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00013"></a>00013 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00014"></a>00014 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00015"></a>00015 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00016"></a>00016 <span class="comment"> *</span>
+<a name="l00017"></a>00017 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00018"></a>00018 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00019"></a>00019 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00020"></a>00020 <span class="comment"> */</span>
+<a name="l00021"></a>00021 <span class="comment">/************************************************************************</span>
+<a name="l00022"></a>00022 <span class="comment">* E.S.O. - VLT project</span>
+<a name="l00023"></a>00023 <span class="comment">*</span>
+<a name="l00024"></a>00024 <span class="comment">* who       when      what</span>
+<a name="l00025"></a>00025 <span class="comment">* --------  --------  ----------------------------------------------</span>
+<a name="l00026"></a>00026 <span class="comment">* schreib  18/05/00  created</span>
+<a name="l00027"></a>00027 <span class="comment">*/</span>
+<a name="l00028"></a>00028 
+<a name="l00029"></a>00029 <span class="comment">/************************************************************************</span>
+<a name="l00030"></a>00030 <span class="comment"> * sinfo_new_cube_ops.h</span>
+<a name="l00031"></a>00031 <span class="comment"> * cube arithmetic routines</span>
+<a name="l00032"></a>00032 <span class="comment"> *----------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment"> */</span>
+<a name="l00034"></a>00034 
+<a name="l00035"></a>00035 <span class="comment">/*</span>
+<a name="l00036"></a>00036 <span class="comment"> * header files</span>
+<a name="l00037"></a>00037 <span class="comment"> */</span>
+<a name="l00038"></a>00038 
+<a name="l00039"></a>00039 <span class="preprocessor">#include "sinfo_image_ops.h"</span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00042"></a>00042 
+<a name="l00043"></a>00043 
+<a name="l00044"></a>00044 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00045"></a>00045 <span class="comment"> *                        Function ANSI C prototypes</span>
+<a name="l00046"></a>00046 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00047"></a>00047 
+<a name="l00048"></a>00048 
+<a name="l00060"></a>00060 cpl_imagelist *
+<a name="l00061"></a>00061 sinfo_new_cube_ops(
+<a name="l00062"></a>00062     cpl_imagelist *  cube1,
+<a name="l00063"></a>00063     cpl_imagelist *   cube2,
+<a name="l00064"></a>00064     <span class="keywordtype">int</span>         operation);
+<a name="l00065"></a>00065 
+<a name="l00066"></a>00066 
+<a name="l00087"></a>00087 cpl_imagelist *
+<a name="l00088"></a>00088 sinfo_new_cube_const_ops(
+<a name="l00089"></a>00089     cpl_imagelist *  cube1,
+<a name="l00090"></a>00090     <span class="keywordtype">double</span>     constant,
+<a name="l00091"></a>00091     <span class="keywordtype">int</span>        operation);
+<a name="l00092"></a>00092 
+<a name="l00093"></a>00093 
+<a name="l00102"></a>00102 cpl_imagelist *
+<a name="l00103"></a>00103 sinfo_new_cube_sub(
+<a name="l00104"></a>00104     cpl_imagelist    *    c1,
+<a name="l00105"></a>00105     cpl_imagelist    *    c2
+<a name="l00106"></a>00106 ) ;
+<a name="l00107"></a>00107 
+<a name="l00108"></a>00108 
+<a name="l00109"></a>00109 
+<a name="l00118"></a>00118 cpl_imagelist *
+<a name="l00119"></a>00119 sinfo_new_cube_add(
+<a name="l00120"></a>00120     cpl_imagelist    *    c1,
+<a name="l00121"></a>00121     cpl_imagelist    *    c2
+<a name="l00122"></a>00122 ) ;
+<a name="l00123"></a>00123 
+<a name="l00124"></a>00124 
+<a name="l00133"></a>00133 cpl_imagelist *
+<a name="l00134"></a>00134 sinfo_new_cube_mul(
+<a name="l00135"></a>00135     cpl_imagelist    *    c1,
+<a name="l00136"></a>00136     cpl_imagelist    *    c2
+<a name="l00137"></a>00137 ) ;
+<a name="l00138"></a>00138 
+<a name="l00139"></a>00139 
+<a name="l00149"></a>00149 cpl_imagelist *
+<a name="l00150"></a>00150 sinfo_new_cube_div(
+<a name="l00151"></a>00151     cpl_imagelist    *    c1,
+<a name="l00152"></a>00152     cpl_imagelist    *    c2
+<a name="l00153"></a>00153 ) ;
+<a name="l00154"></a>00154 
+<a name="l00163"></a>00163 cpl_imagelist *
+<a name="l00164"></a>00164 sinfo_new_add_image_to_cube(cpl_imagelist * cu, cpl_image * im);
+<a name="l00165"></a>00165 
+<a name="l00174"></a>00174 cpl_imagelist *
+<a name="l00175"></a>00175 sinfo_new_sub_image_from_cube(cpl_imagelist * cu, cpl_image * im);
+<a name="l00176"></a>00176 
+<a name="l00185"></a>00185 cpl_imagelist *
+<a name="l00186"></a>00186 sinfo_new_mul_image_to_cube(cpl_imagelist * cu, cpl_image * im);
+<a name="l00187"></a>00187 
+<a name="l00196"></a>00196 cpl_imagelist *
+<a name="l00197"></a>00197 sinfo_new_div_cube_by_image(cpl_imagelist * cu, cpl_image * im);
+<a name="l00198"></a>00198 
+<a name="l00199"></a>00199 
+<a name="l00208"></a>00208 cpl_imagelist *
+<a name="l00209"></a>00209 sinfo_new_add_spectrum_to_cube(cpl_imagelist *cu, Vector *spec);
+<a name="l00210"></a>00210 
+<a name="l00211"></a>00211 
+<a name="l00220"></a>00220 cpl_imagelist *
+<a name="l00221"></a>00221 sinfo_new_sub_spectrum_from_cube(cpl_imagelist *cu, Vector *spec);
+<a name="l00222"></a>00222 
+<a name="l00223"></a>00223 
+<a name="l00232"></a>00232 cpl_imagelist *
+<a name="l00233"></a>00233 sinfo_new_mul_spectrum_to_cube(cpl_imagelist *cu, Vector *spec);
+<a name="l00234"></a>00234 
+<a name="l00235"></a>00235 
+<a name="l00244"></a>00244 cpl_imagelist *
+<a name="l00245"></a>00245 sinfo_new_div_cube_by_spectrum(cpl_imagelist *cu, Vector *spec);
+<a name="l00246"></a>00246 
+<a name="l00266"></a>00266 Vector *
+<a name="l00267"></a>00267 sinfo_new_clean_mean_of_spectra(cpl_imagelist * cube,
+<a name="l00268"></a>00268                              <span class="keywordtype">int</span> llx,
+<a name="l00269"></a>00269                              <span class="keywordtype">int</span> lly,
+<a name="l00270"></a>00270                              <span class="keywordtype">int</span> urx,
+<a name="l00271"></a>00271                              <span class="keywordtype">int</span> ury,
+<a name="l00272"></a>00272                              <span class="keywordtype">double</span> lo_reject,
+<a name="l00273"></a>00273                              <span class="keywordtype">double</span> hi_reject);
+<a name="l00274"></a>00274 
+<a name="l00286"></a>00286 cpl_image *
+<a name="l00287"></a>00287 sinfo_new_median_cube(cpl_imagelist * cube) ;
+<a name="l00288"></a>00288 
+<a name="l00300"></a>00300 cpl_image *
+<a name="l00301"></a>00301 sinfo_new_average_cube_to_image(cpl_imagelist * cube) ;
+<a name="l00302"></a>00302 
+<a name="l00313"></a>00313 cpl_image *
+<a name="l00314"></a>00314 sinfo_new_sum_cube_to_image(cpl_imagelist * cube) ;
+<a name="l00315"></a>00315 
+<a name="l00338"></a>00338 cpl_image *
+<a name="l00339"></a>00339 sinfo_new_average_cube_to_image_between_waves (cpl_imagelist * cube,
+<a name="l00340"></a>00340                                            <span class="keywordtype">float</span>     dispersion,
+<a name="l00341"></a>00341                                            <span class="keywordtype">float</span>     centralWave,
+<a name="l00342"></a>00342                                            <span class="keywordtype">float</span>     initialLambda,
+<a name="l00343"></a>00343                                            <span class="keywordtype">float</span>     finalLambda) ;
+<a name="l00344"></a>00344 
+<a name="l00352"></a>00352 cpl_image *
+<a name="l00353"></a>00353 sinfo_new_extract_image_from_cube(cpl_imagelist * cube, <span class="keywordtype">int</span> plane_index) ;
+<a name="l00354"></a>00354 
+<a name="l00363"></a>00363 Vector *
+<a name="l00364"></a>00364 sinfo_new_extract_spectrum_from_cube(cpl_imagelist * cube,
+<a name="l00365"></a>00365                                      <span class="keywordtype">int</span> x_pos,
+<a name="l00366"></a>00366                                      <span class="keywordtype">int</span> y_pos ) ;
+<a name="l00367"></a>00367 
+<a name="l00408"></a>00408 cpl_imagelist *
+<a name="l00409"></a>00409 sinfo_new_combine_jittered_cubes ( cpl_imagelist ** cubes,
+<a name="l00410"></a>00410                                  cpl_imagelist  * mergedCube,
+<a name="l00411"></a>00411                                  <span class="keywordtype">int</span>        n_cubes,
+<a name="l00412"></a>00412                                  <span class="keywordtype">float</span>    * cumoffsetx,
+<a name="l00413"></a>00413                                  <span class="keywordtype">float</span>    * cumoffsety,
+<a name="l00414"></a>00414                                  <span class="keywordtype">float</span>    * exptimes,
+<a name="l00415"></a>00415                    <span class="keywordtype">char</span>     * kernel_type );
+<a name="l00416"></a>00416 
+<a name="l00458"></a>00458 cpl_imagelist *
+<a name="l00459"></a>00459 new_combine_jittered_cubes_it ( cpl_imagelist ** cubes,
+<a name="l00460"></a>00460                                  cpl_imagelist *  mergedCube,
+<a name="l00461"></a>00461                                  cpl_imagelist *  mask,
+<a name="l00462"></a>00462                                  <span class="keywordtype">int</span>        n_cubes,
+<a name="l00463"></a>00463                                  <span class="keywordtype">float</span>    * cumoffsetx,
+<a name="l00464"></a>00464                                  <span class="keywordtype">float</span>    * cumoffsety,
+<a name="l00465"></a>00465                                  <span class="keywordtype">float</span>    * exptimes,
+<a name="l00466"></a>00466                                  <span class="keywordtype">char</span>     * kernel_type,
+<a name="l00467"></a>00467                                  <span class="keyword">const</span> <span class="keywordtype">int</span> z) ;
+<a name="l00468"></a>00468 
+<a name="l00469"></a>00469 
+<a name="l00511"></a>00511 <span class="keywordtype">int</span>
+<a name="l00512"></a>00512 sinfo_new_combine_jittered_cubes_thomas_range(cpl_imagelist ** cubes,
+<a name="l00513"></a>00513                     cpl_imagelist  * mergedCube,
+<a name="l00514"></a>00514                     cpl_imagelist  * mask,
+<a name="l00515"></a>00515                     <span class="keywordtype">int</span>        n_cubes,
+<a name="l00516"></a>00516                     <span class="keywordtype">float</span>    * cumoffsetx,
+<a name="l00517"></a>00517                     <span class="keywordtype">float</span>    * cumoffsety,
+<a name="l00518"></a>00518                     <span class="keywordtype">double</span>    * exptimes,
+<a name="l00519"></a>00519                     <span class="keywordtype">char</span>     * kernel_type,
+<a name="l00520"></a>00520                     <span class="keyword">const</span> <span class="keywordtype">int</span> z_min,
+<a name="l00521"></a>00521                     <span class="keyword">const</span> <span class="keywordtype">int</span> z_max,
+<a name="l00522"></a>00522                                     <span class="keyword">const</span> <span class="keywordtype">double</span> kappa );
+<a name="l00523"></a>00523 
+<a name="l00564"></a>00564 <span class="keywordtype">int</span>
+<a name="l00565"></a>00565 new_combine_jittered_cubes_sky_range (cpl_imagelist ** cubes,
+<a name="l00566"></a>00566                    cpl_imagelist  * mergedCube,
+<a name="l00567"></a>00567                    cpl_imagelist  * mask,
+<a name="l00568"></a>00568                    cpl_imagelist  * mergedSky,
+<a name="l00569"></a>00569                    cpl_imagelist  * mergedMsk,
+<a name="l00570"></a>00570                    cpl_imagelist  * mergeMed,
+<a name="l00571"></a>00571                    cpl_imagelist  * mergeAvg,
+<a name="l00572"></a>00572                    cpl_imagelist  * mergeStd,
+<a name="l00573"></a>00573                    cpl_imagelist  * mergeNc,
+<a name="l00574"></a>00574                    <span class="keywordtype">int</span>        n_cubes,
+<a name="l00575"></a>00575                    <span class="keywordtype">float</span>    * cumoffsetx,
+<a name="l00576"></a>00576                    <span class="keywordtype">float</span>    * cumoffsety,
+<a name="l00577"></a>00577                    <span class="keywordtype">float</span>    * exptimes,
+<a name="l00578"></a>00578                    <span class="keywordtype">char</span>     * kernel_type,
+<a name="l00579"></a>00579                    <span class="keyword">const</span> <span class="keywordtype">int</span> z_min,
+<a name="l00580"></a>00580                    <span class="keyword">const</span> <span class="keywordtype">int</span> z_max);
+<a name="l00581"></a>00581 
+<a name="l00621"></a>00621 <span class="keywordtype">int</span>
+<a name="l00622"></a>00622 sinfo_new_combine_jittered_cubes_range ( cpl_imagelist ** cubes,
+<a name="l00623"></a>00623                                  cpl_imagelist  * mergedCube,
+<a name="l00624"></a>00624                                  cpl_imagelist  * mask,
+<a name="l00625"></a>00625                                  <span class="keywordtype">int</span>        n_cubes,
+<a name="l00626"></a>00626                                  <span class="keywordtype">float</span>    * cumoffsetx,
+<a name="l00627"></a>00627                                  <span class="keywordtype">float</span>    * cumoffsety,
+<a name="l00628"></a>00628                                  <span class="keywordtype">double</span>    * exptimes,
+<a name="l00629"></a>00629                                  <span class="keywordtype">char</span>     * kernel_type,
+<a name="l00630"></a>00630                                  <span class="keyword">const</span> <span class="keywordtype">int</span> z_min, <span class="keyword">const</span> <span class="keywordtype">int</span> z_max );
+<a name="l00631"></a>00631 
+<a name="l00672"></a>00672 <span class="keywordtype">int</span>
+<a name="l00673"></a>00673 new_combine_jittered_cubes_sky_range2 (cpl_imagelist ** cubes,
+<a name="l00674"></a>00674                    cpl_imagelist  * mergedCube,
+<a name="l00675"></a>00675                    cpl_imagelist  * mask,
+<a name="l00676"></a>00676                    cpl_imagelist  * mergedSky,
+<a name="l00677"></a>00677                    cpl_imagelist  * mergedMsk,
+<a name="l00678"></a>00678                    cpl_imagelist  * mergeMed,
+<a name="l00679"></a>00679                    cpl_imagelist  * mergeAvg,
+<a name="l00680"></a>00680                    cpl_imagelist  * mergeStd,
+<a name="l00681"></a>00681                    cpl_imagelist  * mergeNc,
+<a name="l00682"></a>00682                    <span class="keywordtype">int</span>        n_cubes,
+<a name="l00683"></a>00683                    <span class="keywordtype">float</span>    * cumoffsetx,
+<a name="l00684"></a>00684                    <span class="keywordtype">float</span>    * cumoffsety,
+<a name="l00685"></a>00685                    <span class="keywordtype">double</span>    * exptimes,
+<a name="l00686"></a>00686                    <span class="keywordtype">char</span>     * kernel_type,
+<a name="l00687"></a>00687                    <span class="keyword">const</span> <span class="keywordtype">int</span> z_min,
+<a name="l00688"></a>00688                    <span class="keyword">const</span> <span class="keywordtype">int</span> z_max);
+<a name="l00689"></a>00689 
+<a name="l00690"></a>00690 
+<a name="l00703"></a>00703 cpl_imagelist *
+<a name="l00704"></a>00704 sinfo_new_interpol_cube_simple( cpl_imagelist * cube,
+<a name="l00705"></a>00705                               cpl_imagelist * badcube,
+<a name="l00706"></a>00706                               <span class="keywordtype">int</span>       maxdist ) ;
+<a name="l00707"></a>00707 
+<a name="l00744"></a>00744 cpl_imagelist *
+<a name="l00745"></a>00745 sinfo_new_combine_cubes ( cpl_imagelist ** cubes,
+<a name="l00746"></a>00746                          cpl_imagelist  * mergedCube,
+<a name="l00747"></a>00747                          <span class="keywordtype">int</span>        n_cubes,
+<a name="l00748"></a>00748                          <span class="keywordtype">float</span>    * cumoffsetx,
+<a name="l00749"></a>00749                          <span class="keywordtype">float</span>    * cumoffsety,
+<a name="l00750"></a>00750                          <span class="keywordtype">float</span>      factor,
+<a name="l00751"></a>00751                          <span class="keywordtype">char</span>     * kernel_type ) ;
+<a name="l00752"></a>00752 
+<a name="l00764"></a>00764 cpl_imagelist *
+<a name="l00765"></a>00765 sinfo_new_bin_cube(cpl_imagelist *cu,
+<a name="l00766"></a>00766                    <span class="keywordtype">int</span> xscale,
+<a name="l00767"></a>00767                    <span class="keywordtype">int</span> yscale,
+<a name="l00768"></a>00768                    <span class="keywordtype">int</span> xmin,
+<a name="l00769"></a>00769                    <span class="keywordtype">int</span> xmax,
+<a name="l00770"></a>00770                    <span class="keywordtype">int</span> ymin,
+<a name="l00771"></a>00771                    <span class="keywordtype">int</span> ymax);
+<a name="l00772"></a>00772 
+<a name="l00792"></a>00792 cpl_imagelist *
+<a name="l00793"></a>00793 sinfo_new_scale_cube(cpl_imagelist *cu,
+<a name="l00794"></a>00794                      <span class="keywordtype">float</span> xscale,
+<a name="l00795"></a>00795                      <span class="keywordtype">float</span> yscale,
+<a name="l00796"></a>00796                      <span class="keywordtype">char</span> * kernel_type);
+<a name="l00797"></a>00797 
+<a name="l00798"></a>00798 
+<a name="l00808"></a>00808 cpl_imagelist *
+<a name="l00809"></a>00809 sinfo_cube_zshift(<span class="keyword">const</span> cpl_imagelist * cube,
+<a name="l00810"></a>00810                   <span class="keyword">const</span> <span class="keywordtype">double</span> shift,
+<a name="l00811"></a>00811                   <span class="keywordtype">double</span>* rest);
+<a name="l00812"></a>00812 
+<a name="l00822"></a>00822 cpl_imagelist *
+<a name="l00823"></a>00823 sinfo_cube_zshift_poly(<span class="keyword">const</span> cpl_imagelist * cube,
+<a name="l00824"></a>00824                        <span class="keyword">const</span> <span class="keywordtype">double</span> shift,
+<a name="l00825"></a>00825                        <span class="keyword">const</span> <span class="keywordtype">int</span>    order);
+<a name="l00826"></a>00826 
+<a name="l00835"></a>00835 cpl_imagelist *
+<a name="l00836"></a>00836 sinfo_cube_zshift_spline3(<span class="keyword">const</span> cpl_imagelist * cube,
+<a name="l00837"></a>00837                           <span class="keyword">const</span> <span class="keywordtype">double</span> shift);
+<a name="l00838"></a>00838 
+<a name="l00839"></a>00839 
+<a name="l00840"></a>00840 <span class="keywordtype">int</span>
+<a name="l00841"></a>00841 sinfo_coadd_with_ks_clip_optimized(<span class="keyword">const</span> <span class="keywordtype">int</span> z_min,
+<a name="l00842"></a>00842             <span class="keyword">const</span> <span class="keywordtype">int</span> z_max,
+<a name="l00843"></a>00843             <span class="keyword">const</span> <span class="keywordtype">int</span> n_cubes,
+<a name="l00844"></a>00844             <span class="keyword">const</span> <span class="keywordtype">double</span> kappa,
+<a name="l00845"></a>00845             <span class="keywordtype">int</span>* llx,
+<a name="l00846"></a>00846             <span class="keywordtype">int</span>* lly,
+<a name="l00847"></a>00847                         <span class="keywordtype">double</span>* exptimes,
+<a name="l00848"></a>00848             cpl_imagelist* mask,
+<a name="l00849"></a>00849             cpl_imagelist* mergedCube,
+<a name="l00850"></a>00850                         cpl_imagelist** tmpcubes);
+<a name="l00851"></a>00851 
+<a name="l00852"></a>00852 <span class="keywordtype">double</span> kappa_sigma_array_with_mask(
+<a name="l00853"></a>00853         cpl_array* parray,
+<a name="l00854"></a>00854         <span class="keywordtype">int</span> szArray,
+<a name="l00855"></a>00855         <span class="keyword">const</span> <span class="keywordtype">double</span> kappa,
+<a name="l00856"></a>00856         cpl_image* imMask,
+<a name="l00857"></a>00857         <span class="keywordtype">double</span>* exptimes,
+<a name="l00858"></a>00858         <span class="keywordtype">int</span> x, <span class="keywordtype">int</span> y, <span class="keywordtype">double</span> mas_adjustment
+<a name="l00859"></a>00859         <span class="comment">/*, double* val_msk_sum*/</span>);
+<a name="l00860"></a>00860 <span class="preprocessor">#endif </span>
+<a name="l00864"></a>00864 <span class="preprocessor"></span><span class="comment">/*--------------------------------------------------------------------------*/</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__new__cubes__build_8c_source.html b/html/sinfo__new__cubes__build_8c_source.html
new file mode 100644
index 0000000..01aeea9
--- /dev/null
+++ b/html/sinfo__new__cubes__build_8c_source.html
@@ -0,0 +1,929 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_new_cubes_build.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_new_cubes_build.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment"></span>
+<a name="l00021"></a>00021 <span class="comment">File name    :       sinfo_new_cubes_build.c</span>
+<a name="l00022"></a>00022 <span class="comment">Author       :    J. Schreiber</span>
+<a name="l00023"></a>00023 <span class="comment">Created on   :    December 3, 2003</span>
+<a name="l00024"></a>00024 <span class="comment">Description  :    Creates data cubes or merges data cubes</span>
+<a name="l00025"></a>00025 <span class="comment">out of jittered object-sky</span>
+<a name="l00026"></a>00026 <span class="comment">nodding observations</span>
+<a name="l00027"></a>00027 <span class="comment">---------------------------------------------------------------------------*/</span>
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span>
+<a name="l00032"></a>00032 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">  Includes</span>
+<a name="l00034"></a>00034 <span class="comment">  ---------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 <span class="preprocessor">#include "sinfo_new_cubes_build.h"</span>
+<a name="l00036"></a>00036 <span class="preprocessor">#include "sinfo_pfits.h"</span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00038"></a>00038 <span class="preprocessor">#include "sinfo_pro_save.h"</span>
+<a name="l00039"></a>00039 <span class="preprocessor">#include "sinfo_objnod_ini_by_cpl.h"</span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include "sinfo_functions.h"</span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include "sinfo_hidden.h"</span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include "sinfo_utilities_scired.h"</span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include "sinfo_wave_calibration.h"</span>
+<a name="l00044"></a>00044 <span class="preprocessor">#include "sinfo_cube_construct.h"</span>
+<a name="l00045"></a>00045 <span class="preprocessor">#include "sinfo_skycor.h"</span>
+<a name="l00046"></a>00046 <span class="preprocessor">#include "sinfo_product_config.h"</span>
+<a name="l00047"></a>00047 <span class="preprocessor">#include "sinfo_error.h"</span>
+<a name="l00048"></a>00048 <span class="preprocessor">#include "sinfo_utils_wrappers.h"</span>
+<a name="l00049"></a>00049 <span class="preprocessor">#include "sinfo_atmo_disp.h"</span>
+<a name="l00050"></a>00050 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00051"></a>00051 <span class="comment">  Defines</span>
+<a name="l00052"></a>00052 <span class="comment">  ---------------------------------------------------------------------------*/</span>
+<a name="l00053"></a>00053 <span class="preprocessor">#define PI_NUMB        (3.1415926535897932384626433832795) </span><span class="comment">/* pi */</span>
+<a name="l00054"></a>00054 
+<a name="l00055"></a>00055 
+<a name="l00056"></a>00056 <span class="keyword">static</span> <span class="keywordtype">void</span> sinfo_atm_correction(cpl_imagelist** ppCube,
+<a name="l00057"></a>00057         cpl_frameset* sof,
+<a name="l00058"></a>00058         <span class="keyword">const</span> <span class="keywordtype">char</span>* polyshiftname,
+<a name="l00059"></a>00059         <span class="keywordtype">double</span> dis_cube,
+<a name="l00060"></a>00060         <span class="keywordtype">double</span> centralLambda_cube,
+<a name="l00061"></a>00061         <span class="keywordtype">int</span> centralpix_cube);
+<a name="l00062"></a>00062 
+<a name="l00063"></a>00063 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00064"></a>00064 <span class="comment">  Function Definitions</span>
+<a name="l00065"></a>00065 <span class="comment">  ---------------------------------------------------------------------------*/</span>
+<a name="l00066"></a>00066 <span class="comment">/* Temporally commented out as not used</span>
+<a name="l00067"></a>00067 <span class="comment">static cpl_image*</span>
+<a name="l00068"></a>00068 <span class="comment">sinfo_flux_corr(const cpl_image* inp,const cpl_image* wav,const double dis);</span>
+<a name="l00069"></a>00069 <span class="comment">*/</span>
+<a name="l00078"></a>00078 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00079"></a>00079 <span class="comment">  Function     : sinfo_new_cubes_build()</span>
+<a name="l00080"></a>00080 <span class="comment">  In           : ini_file: file name of according .ini file</span>
+<a name="l00081"></a>00081 <span class="comment">  Out          : integer (0 if it worked, -1 if it doesn't)</span>
+<a name="l00082"></a>00082 <span class="comment">  Job          : this routine carries through the data cube creation of an</span>
+<a name="l00083"></a>00083 <span class="comment">  object science observation using object-sky nodding</span>
+<a name="l00084"></a>00084 <span class="comment">  and jittering. This script expects jittered frames that</span>
+<a name="l00085"></a>00085 <span class="comment">  were already sky-subtracted</span>
+<a name="l00086"></a>00086 <span class="comment">  averaged, flatfielded, spectral tilt corrected and</span>
+<a name="l00087"></a>00087 <span class="comment">  interleaved if necessary</span>
+<a name="l00088"></a>00088 <span class="comment">  ---------------------------------------------------------------------------*/</span>
+<a name="l00089"></a>00089 <span class="keywordtype">int</span> sinfo_new_cubes_build (<span class="keyword">const</span> <span class="keywordtype">char</span>* plugin_id,cpl_parameterlist* config,
+<a name="l00090"></a>00090                cpl_frameset* sof, <span class="keyword">const</span> <span class="keywordtype">char</span>* procatg, <span class="keyword">const</span> <span class="keywordtype">int</span> frame_index)
+<a name="l00091"></a>00091 {
+<a name="l00092"></a>00092 
+<a name="l00093"></a>00093   object_config * cfg=NULL ;
+<a name="l00094"></a>00094   cpl_image * im=NULL ;
+<a name="l00095"></a>00095   cpl_image * wavemapim=NULL ;
+<a name="l00096"></a>00096   cpl_image * wim=NULL ;
+<a name="l00097"></a>00097   cpl_image * res_obj=NULL ;
+<a name="l00098"></a>00098   cpl_image * calim=NULL ;
+<a name="l00099"></a>00099   cpl_image * halospec=NULL ;
+<a name="l00100"></a>00100   cpl_image * sky_im=NULL;
+<a name="l00101"></a>00101   cpl_image* res_ima=NULL;
+<a name="l00102"></a>00102   cpl_image* res_wim=NULL;
+<a name="l00103"></a>00103   cpl_image* res_flat=NULL;
+<a name="l00104"></a>00104   cpl_image* res_sky=NULL;
+<a name="l00105"></a>00105   cpl_image* flat_im=NULL;
+<a name="l00106"></a>00106   cpl_image* eima_avg=NULL;
+<a name="l00107"></a>00107   cpl_image* eima_med=NULL;
+<a name="l00108"></a>00108   cpl_imagelist  * cube=NULL ;
+<a name="l00109"></a>00109   cpl_imagelist  * outcube=NULL ;
+<a name="l00110"></a>00110   cpl_imagelist  * outcube2=NULL ;
+<a name="l00111"></a>00111   cpl_imagelist* cflat=NULL;
+<a name="l00112"></a>00112   cpl_imagelist* cflat2=NULL;
+<a name="l00113"></a>00113   cpl_imagelist* csky=NULL;
+<a name="l00114"></a>00114   cpl_imagelist* csky2=NULL;
+<a name="l00115"></a>00115   cpl_propertylist* plist=NULL;
+<a name="l00116"></a>00116   cpl_frame* obj_frm=NULL;
+<a name="l00117"></a>00117   cpl_frame* sky_frm=NULL;
+<a name="l00118"></a>00118   cpl_imagelist* obj_cor=NULL;
+<a name="l00119"></a>00119 
+<a name="l00120"></a>00120   <span class="keywordtype">int</span> sky_cor=0;
+<a name="l00121"></a>00121   <span class="keywordtype">int</span> flux_cor=0;
+<a name="l00122"></a>00122   <span class="keywordtype">int</span> n=0 ;
+<a name="l00123"></a>00123   <span class="keywordtype">int</span> cpix=0 ;
+<a name="l00124"></a>00124   <span class="keywordtype">float</span> mi=0 ;
+<a name="l00125"></a>00125   <span class="keywordtype">float</span> ma=0 ;
+<a name="l00126"></a>00126   <span class="keywordtype">float</span> fcol=0 ;
+<a name="l00127"></a>00127   <span class="keywordtype">float</span> center_x=0;
+<a name="l00128"></a>00128   <span class="keywordtype">float</span> center_y=0;
+<a name="l00129"></a>00129   <span class="keywordtype">float</span> *  correct_dist=NULL ;
+<a name="l00130"></a>00130   <span class="keywordtype">float</span> * distances=NULL ;
+<a name="l00131"></a>00131   <span class="keywordtype">float</span> ** slit_edges=NULL ;
+<a name="l00132"></a>00132   <span class="keywordtype">int</span> nx=0;
+<a name="l00133"></a>00133   <span class="keywordtype">int</span> ny=0;
+<a name="l00134"></a>00134   cpl_image* dif=NULL;
+<a name="l00135"></a>00135   <span class="keywordtype">float</span>* pd=NULL;
+<a name="l00136"></a>00136   <span class="keywordtype">float</span>* pw=NULL;
+<a name="l00137"></a>00137   <span class="keywordtype">int</span> i=0;
+<a name="l00138"></a>00138   <span class="keywordtype">int</span> j=0;
+<a name="l00139"></a>00139 
+<a name="l00140"></a>00140   <span class="keywordtype">double</span> dis=0 ;
+<a name="l00141"></a>00141   <span class="keywordtype">double</span> cwav=0 ;
+<a name="l00142"></a>00142 
+<a name="l00143"></a>00143   <span class="keywordtype">char</span> pro_mjit[MAX_NAME_SIZE];
+<a name="l00144"></a>00144   <span class="keywordtype">char</span> pro_obs[MAX_NAME_SIZE];
+<a name="l00145"></a>00145   <span class="keywordtype">char</span> pro_med[MAX_NAME_SIZE];
+<a name="l00146"></a>00146 
+<a name="l00147"></a>00147 
+<a name="l00148"></a>00148   <span class="keywordtype">char</span> * name=NULL ;
+<a name="l00149"></a>00149   <span class="keywordtype">char</span> file_name[FILE_NAME_SZ];
+<a name="l00150"></a>00150 
+<a name="l00151"></a>00151   cpl_table* qclog_tbl=NULL;
+<a name="l00152"></a>00152   cpl_frameset* stk=NULL;
+<a name="l00153"></a>00153   cpl_parameter* p=NULL;
+<a name="l00154"></a>00154   <span class="keywordtype">int</span> pdensity=0;
+<a name="l00155"></a>00155   sinfo_skycor_qc* sqc=NULL;
+<a name="l00156"></a>00156   cpl_table* int_obj=NULL;
+<a name="l00157"></a>00157 
+<a name="l00158"></a>00158   check_nomsg(p=cpl_parameterlist_find(config,<span class="stringliteral">"sinfoni.product.density"</span>));
+<a name="l00159"></a>00159   check_nomsg(pdensity=cpl_parameter_get_int(p));
+<a name="l00160"></a>00160 
+<a name="l00161"></a>00161   <span class="keywordflow">if</span> (strcmp(procatg,PRO_COADD_STD) == 0) {
+<a name="l00162"></a>00162     strcpy(pro_mjit,PRO_MASK_COADD_STD);
+<a name="l00163"></a>00163     strcpy(pro_obs,PRO_OBS_STD);
+<a name="l00164"></a>00164     strcpy(pro_med,PRO_MED_COADD_STD);
+<a name="l00165"></a>00165 
+<a name="l00166"></a>00166   } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(procatg,PRO_COADD_PSF) == 0) {
+<a name="l00167"></a>00167     strcpy(pro_mjit,PRO_MASK_COADD_PSF);
+<a name="l00168"></a>00168     strcpy(pro_obs,PRO_OBS_PSF);
+<a name="l00169"></a>00169     strcpy(pro_med,PRO_MED_COADD_PSF);
+<a name="l00170"></a>00170   } <span class="keywordflow">else</span> {
+<a name="l00171"></a>00171     strcpy(pro_mjit,PRO_MASK_COADD_OBJ);
+<a name="l00172"></a>00172     strcpy(pro_obs,PRO_OBS_OBJ);
+<a name="l00173"></a>00173     strcpy(pro_med,PRO_MED_COADD_OBJ);
+<a name="l00174"></a>00174   }
+<a name="l00175"></a>00175 
+<a name="l00176"></a>00176 
+<a name="l00177"></a>00177   <span class="comment">/*----parse input data and parameters to set cube_config cfg---*/</span>
+<a name="l00178"></a>00178   check_nomsg(stk = cpl_frameset_new());
+<a name="l00179"></a>00179 
+<a name="l00180"></a>00180   cknull(cfg = sinfo_parse_cpl_input_objnod(config,sof,&stk),
+<a name="l00181"></a>00181      <span class="stringliteral">"Error setting parameter configuration"</span>);
+<a name="l00182"></a>00182 
+<a name="l00183"></a>00183   ck0(sinfo_check_input_data(cfg),<span class="stringliteral">"error checking input"</span>);
+<a name="l00184"></a>00184 
+<a name="l00185"></a>00185 
+<a name="l00186"></a>00186   check_nomsg(p=cpl_parameterlist_find(config,<span class="stringliteral">"sinfoni.objnod.fcol"</span>));
+<a name="l00187"></a>00187   check_nomsg(fcol=(<span class="keywordtype">float</span>)cpl_parameter_get_double(p));
+<a name="l00188"></a>00188 
+<a name="l00189"></a>00189   <span class="keywordflow">for</span> ( n = 0 ; n < cfg->nframes ; n++ )
+<a name="l00190"></a>00190     {
+<a name="l00191"></a>00191 
+<a name="l00192"></a>00192       <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"Read FITS information"</span>);
+<a name="l00193"></a>00193       name = cfg->framelist[n] ;
+<a name="l00194"></a>00194       <span class="keywordflow">if</span>( sinfo_is_fits_file(name) != 1) {
+<a name="l00195"></a>00195     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Input file %s is not FITS"</span>,name);
+<a name="l00196"></a>00196     <span class="keywordflow">goto</span> cleanup;
+<a name="l00197"></a>00197       }
+<a name="l00198"></a>00198 
+<a name="l00199"></a>00199 
+<a name="l00200"></a>00200       <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"frame no.: %d, name: %s\n"</span>, n, name) ;
+<a name="l00201"></a>00201       cknull(im = cpl_image_load(name,CPL_TYPE_FLOAT,0,0),
+<a name="l00202"></a>00202          <span class="stringliteral">" could not load frame %s!"</span>,name) ;
+<a name="l00203"></a>00203 
+<a name="l00204"></a>00204 
+<a name="l00205"></a>00205       <span class="comment">/*</span>
+<a name="l00206"></a>00206 <span class="comment">       *--------------------------------------------------------------</span>
+<a name="l00207"></a>00207 <span class="comment">       *---------------------RESAMPLING-------------------------------</span>
+<a name="l00208"></a>00208 <span class="comment">       *--------------------------------------------------------------</span>
+<a name="l00209"></a>00209 <span class="comment">       */</span>
+<a name="l00210"></a>00210       sinfo_msg(<span class="stringliteral">"Resampling object"</span>);
+<a name="l00211"></a>00211       cknull(wavemapim = cpl_image_load(cfg->wavemap,CPL_TYPE_FLOAT,0,0),
+<a name="l00212"></a>00212          <span class="stringliteral">"could not load wavemap"</span>);
+<a name="l00213"></a>00213       check_nomsg(wim=cpl_image_duplicate(wavemapim));
+<a name="l00214"></a>00214 
+<a name="l00215"></a>00215       check_nomsg(p=cpl_parameterlist_find(config,
+<a name="l00216"></a>00216                        <span class="stringliteral">"sinfoni.objnod.flux_cor"</span>));
+<a name="l00217"></a>00217       check_nomsg(flux_cor=cpl_parameter_get_bool(p));
+<a name="l00218"></a>00218 
+<a name="l00219"></a>00219 
+<a name="l00220"></a>00220       nx=cpl_image_get_size_x(wim);
+<a name="l00221"></a>00221       ny=cpl_image_get_size_y(wim);
+<a name="l00222"></a>00222       <span class="comment">/*</span>
+<a name="l00223"></a>00223 <span class="comment">        check_nomsg(pd=cpl_image_get_data(im));</span>
+<a name="l00224"></a>00224 <span class="comment">        //To compare statistics we make sure that the input image has all 1s</span>
+<a name="l00225"></a>00225 <span class="comment"></span>
+<a name="l00226"></a>00226 <span class="comment">    for(i=0;i<nx;i++) {</span>
+<a name="l00227"></a>00227 <span class="comment">    for(j=0;j<ny;j++) {</span>
+<a name="l00228"></a>00228 <span class="comment">    pd[nx*j+i]=1.;</span>
+<a name="l00229"></a>00229 <span class="comment">    }</span>
+<a name="l00230"></a>00230 <span class="comment">    }</span>
+<a name="l00231"></a>00231 <span class="comment">    cpl_image_save(im,"im.fits", CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT);</span>
+<a name="l00232"></a>00232 <span class="comment">      */</span>
+<a name="l00233"></a>00233 
+<a name="l00234"></a>00234       cknull(res_ima = sinfo_new_defined_resampling(im,
+<a name="l00235"></a>00235                             wim,
+<a name="l00236"></a>00236                             cfg->ncoeffs,
+<a name="l00237"></a>00237                             &cfg->nrows,
+<a name="l00238"></a>00238                             &dis,
+<a name="l00239"></a>00239                             &mi,
+<a name="l00240"></a>00240                             &ma,
+<a name="l00241"></a>00241                             &cwav,
+<a name="l00242"></a>00242                             &cpix),
+<a name="l00243"></a>00243          <span class="stringliteral">" sinfo_definedResampling() failed"</span> ) ;
+<a name="l00244"></a>00244 
+<a name="l00245"></a>00245 
+<a name="l00246"></a>00246 
+<a name="l00247"></a>00247       <span class="comment">//cpl_image_save(res_ima,"res_im.fits",</span>
+<a name="l00248"></a>00248       <span class="comment">//CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT);</span>
+<a name="l00249"></a>00249 
+<a name="l00250"></a>00250       <span class="comment">//We create an image with the derivatives</span>
+<a name="l00251"></a>00251       check_nomsg(dif=cpl_image_new(nx,ny,CPL_TYPE_FLOAT));
+<a name="l00252"></a>00252       pw=cpl_image_get_data(wim);
+<a name="l00253"></a>00253       pd=cpl_image_get_data(dif);
+<a name="l00254"></a>00254 
+<a name="l00255"></a>00255 
+<a name="l00256"></a>00256       <span class="keywordflow">for</span>(i=1;i<nx-1;i++) {
+<a name="l00257"></a>00257     <span class="keywordflow">for</span>(j=1;j<ny-1;j++) {
+<a name="l00258"></a>00258       <span class="keywordflow">if</span>(!isnan(pd[nx*j+i])) {
+<a name="l00259"></a>00259         pd[nx*j+i]=2.0*dis/(pw[nx*(j+1)+i]-pw[nx*(j-1)+i]);
+<a name="l00260"></a>00260       }
+<a name="l00261"></a>00261     }
+<a name="l00262"></a>00262     <span class="keywordflow">if</span>(!isnan(pd[i])) {
+<a name="l00263"></a>00263       pd[i]=dis/(pw[nx+i]-pw[i]);
+<a name="l00264"></a>00264     }
+<a name="l00265"></a>00265     <span class="keywordflow">if</span>(!isnan(pd[nx*(ny-1)+i])) {
+<a name="l00266"></a>00266       pd[nx*(ny-1)+i]=dis/(pw[nx*(ny-1)+i]-pw[nx*(ny-2)+i]);
+<a name="l00267"></a>00267     }
+<a name="l00268"></a>00268       }
+<a name="l00269"></a>00269 
+<a name="l00270"></a>00270 
+<a name="l00271"></a>00271       <span class="comment">//cpl_image_save(dif,"diff.fits",</span>
+<a name="l00272"></a>00272       <span class="comment">//CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT);</span>
+<a name="l00273"></a>00273 
+<a name="l00274"></a>00274 
+<a name="l00275"></a>00275 
+<a name="l00276"></a>00276       cknull(res_wim = sinfo_new_defined_resampling(dif,
+<a name="l00277"></a>00277                             wim,
+<a name="l00278"></a>00278                             cfg->ncoeffs,
+<a name="l00279"></a>00279                             &cfg->nrows,
+<a name="l00280"></a>00280                             &dis,
+<a name="l00281"></a>00281                             &mi,
+<a name="l00282"></a>00282                             &ma,
+<a name="l00283"></a>00283                             &cwav,
+<a name="l00284"></a>00284                             &cpix),
+<a name="l00285"></a>00285          <span class="stringliteral">" sinfo_definedResampling() failed"</span> ) ;
+<a name="l00286"></a>00286 
+<a name="l00287"></a>00287 
+<a name="l00288"></a>00288 
+<a name="l00289"></a>00289       <span class="comment">//cpl_image_save(res_wim,"res_diff.fits",</span>
+<a name="l00290"></a>00290       <span class="comment">//CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT);</span>
+<a name="l00291"></a>00291 
+<a name="l00292"></a>00292 
+<a name="l00293"></a>00293 
+<a name="l00294"></a>00294 
+<a name="l00295"></a>00295 
+<a name="l00296"></a>00296       <span class="comment">//To rescale in flux we divide the resampled image and</span>
+<a name="l00297"></a>00297       <span class="comment">//the resampled derivatives. At this point res_obj should have same</span>
+<a name="l00298"></a>00298       <span class="comment">//flux as input image (im.diff)</span>
+<a name="l00299"></a>00299 
+<a name="l00300"></a>00300       res_obj=cpl_image_duplicate(res_ima);
+<a name="l00301"></a>00301       sinfo_free_image(&res_ima);
+<a name="l00302"></a>00302       <span class="keywordflow">if</span>(flux_cor) {
+<a name="l00303"></a>00303     sinfo_msg(<span class="stringliteral">"Apply flux correction"</span>);
+<a name="l00304"></a>00304     cpl_image_divide(res_obj,res_wim);
+<a name="l00305"></a>00305       }
+<a name="l00306"></a>00306       <span class="comment">//cpl_image_save(res_obj,"res_obj.fits",</span>
+<a name="l00307"></a>00307       <span class="comment">//CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT);</span>
+<a name="l00308"></a>00308 
+<a name="l00309"></a>00309 
+<a name="l00310"></a>00310       sinfo_free_image(&wim);
+<a name="l00311"></a>00311 
+<a name="l00312"></a>00312       <span class="keywordflow">if</span>((pdensity == 3) || (pdensity == 2 && frame_index == 0)) {
+<a name="l00313"></a>00313     snprintf(file_name,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%d%s"</span>,
+<a name="l00314"></a>00314          RESAMPLED_OUT_OBJ_FILENAME,
+<a name="l00315"></a>00315          frame_index,<span class="stringliteral">".fits"</span>);
+<a name="l00316"></a>00316     ck0(sinfo_pro_save_ima(res_obj,sof,sof,file_name,
+<a name="l00317"></a>00317                    PRO_RESAMPLED_OBJ,
+<a name="l00318"></a>00318                                qclog_tbl,plugin_id,config),
+<a name="l00319"></a>00319         <span class="stringliteral">"cannot save image %s"</span>, file_name);
+<a name="l00320"></a>00320       }
+<a name="l00321"></a>00321 
+<a name="l00322"></a>00322 
+<a name="l00323"></a>00323       <span class="keywordflow">if</span>(strcmp(cfg->sky_dist,<span class="stringliteral">"no_sky"</span>)!=0) {
+<a name="l00324"></a>00324     sinfo_msg(<span class="stringliteral">"Resampling sky"</span>);
+<a name="l00325"></a>00325     check_nomsg(sky_im=cpl_image_load(cfg->sky_dist,CPL_TYPE_FLOAT,0,0));
+<a name="l00326"></a>00326     check_nomsg(wim=cpl_image_duplicate(wavemapim));
+<a name="l00327"></a>00327     cknull(res_ima = sinfo_new_defined_resampling(sky_im,
+<a name="l00328"></a>00328                               wim,
+<a name="l00329"></a>00329                               cfg->ncoeffs,
+<a name="l00330"></a>00330                               &cfg->nrows,
+<a name="l00331"></a>00331                               &dis,
+<a name="l00332"></a>00332                               &mi,
+<a name="l00333"></a>00333                               &ma,
+<a name="l00334"></a>00334                               &cwav,
+<a name="l00335"></a>00335                               &cpix),
+<a name="l00336"></a>00336            <span class="stringliteral">" sinfo_definedResampling() failed"</span> );
+<a name="l00337"></a>00337         res_sky=cpl_image_duplicate(res_ima);
+<a name="l00338"></a>00338         sinfo_free_image(&res_ima);
+<a name="l00339"></a>00339         <span class="keywordflow">if</span>(flux_cor) {
+<a name="l00340"></a>00340           sinfo_msg(<span class="stringliteral">"Apply flux correction"</span>);
+<a name="l00341"></a>00341       cpl_image_divide(res_sky,res_wim);
+<a name="l00342"></a>00342     }
+<a name="l00343"></a>00343 
+<a name="l00344"></a>00344     sinfo_free_image(&wim);
+<a name="l00345"></a>00345     sinfo_free_image(&sky_im) ;
+<a name="l00346"></a>00346     <span class="keywordflow">if</span>((pdensity == 3) || (pdensity == 2 && frame_index == 0)){
+<a name="l00347"></a>00347 
+<a name="l00348"></a>00348       snprintf(file_name,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%d%s"</span>,
+<a name="l00349"></a>00349            RESAMPLED_OUT_SKY_FILENAME,frame_index,<span class="stringliteral">".fits"</span>);
+<a name="l00350"></a>00350       ck0(sinfo_pro_save_ima(res_sky,sof,sof,file_name,
+<a name="l00351"></a>00351                  PRO_RESAMPLED_SKY,
+<a name="l00352"></a>00352                  qclog_tbl,plugin_id,config),
+<a name="l00353"></a>00353           <span class="stringliteral">"cannot save image %s"</span>, file_name);
+<a name="l00354"></a>00354     }
+<a name="l00355"></a>00355 
+<a name="l00356"></a>00356 
+<a name="l00357"></a>00357 
+<a name="l00358"></a>00358       }
+<a name="l00359"></a>00359 
+<a name="l00360"></a>00360 
+<a name="l00361"></a>00361       <span class="keywordflow">if</span>(n ==0) {
+<a name="l00362"></a>00362     <span class="keywordflow">if</span>(strcmp(cfg->mflat_dist,<span class="stringliteral">"not_found"</span>) != 0) {
+<a name="l00363"></a>00363       sinfo_msg(<span class="stringliteral">"Resampling master flat"</span>);
+<a name="l00364"></a>00364       cknull(flat_im=cpl_image_load(cfg->mflat_dist,CPL_TYPE_FLOAT,0,0),
+<a name="l00365"></a>00365          <span class="stringliteral">"Distorted master flat field not found\n"</span>
+<a name="l00366"></a>00366          <span class="stringliteral">"You may have set --stack-flat_ind=FALSE\n"</span>
+<a name="l00367"></a>00367          <span class="stringliteral">"Flat field resampling skipped"</span>);
+<a name="l00368"></a>00368       check_nomsg(wim=cpl_image_duplicate(wavemapim));
+<a name="l00369"></a>00369       cknull(res_ima = sinfo_new_defined_resampling(flat_im,
+<a name="l00370"></a>00370                             wim,
+<a name="l00371"></a>00371                             cfg->ncoeffs,
+<a name="l00372"></a>00372                             &cfg->nrows,
+<a name="l00373"></a>00373                             &dis,
+<a name="l00374"></a>00374                             &mi,
+<a name="l00375"></a>00375                             &ma,
+<a name="l00376"></a>00376                             &cwav,
+<a name="l00377"></a>00377                             &cpix),
+<a name="l00378"></a>00378          <span class="stringliteral">" sinfo_definedResampling() failed"</span> ) ;
+<a name="l00379"></a>00379 
+<a name="l00380"></a>00380 
+<a name="l00381"></a>00381       res_flat=cpl_image_duplicate(res_ima);
+<a name="l00382"></a>00382       sinfo_free_image(&res_ima);
+<a name="l00383"></a>00383       <span class="keywordflow">if</span>(flux_cor) {
+<a name="l00384"></a>00384         sinfo_msg(<span class="stringliteral">"Apply flux correction"</span>);
+<a name="l00385"></a>00385         cpl_image_divide(res_flat,res_wim);
+<a name="l00386"></a>00386       }
+<a name="l00387"></a>00387       sinfo_free_image(&wim);
+<a name="l00388"></a>00388       sinfo_free_image(&flat_im) ;
+<a name="l00389"></a>00389       <span class="keywordflow">if</span>((pdensity == 3) || (pdensity == 2 && frame_index == 0)) {
+<a name="l00390"></a>00390         snprintf(file_name,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%d%s"</span>,
+<a name="l00391"></a>00391              RESAMPLED_OUT_FLAT_FILENAME,frame_index,<span class="stringliteral">".fits"</span>);
+<a name="l00392"></a>00392         ck0(sinfo_pro_save_ima(res_flat,sof,sof,file_name,
+<a name="l00393"></a>00393                    PRO_RESAMPLED_FLAT_LAMP,
+<a name="l00394"></a>00394                    qclog_tbl,plugin_id,config),
+<a name="l00395"></a>00395         <span class="stringliteral">"cannot save image %s"</span>, file_name);
+<a name="l00396"></a>00396       }
+<a name="l00397"></a>00397 
+<a name="l00398"></a>00398 
+<a name="l00399"></a>00399     }
+<a name="l00400"></a>00400 
+<a name="l00401"></a>00401       }
+<a name="l00402"></a>00402 
+<a name="l00403"></a>00403       sinfo_msg(<span class="stringliteral">"wmin %f wmax %f wcent %f wstep %f cpix %d"</span>,
+<a name="l00404"></a>00404         mi,ma,cwav,dis,cpix);
+<a name="l00405"></a>00405       sinfo_free_image(&res_wim);
+<a name="l00406"></a>00406       sinfo_free_image(&im) ;
+<a name="l00407"></a>00407       sinfo_free_image(&wavemapim) ;
+<a name="l00408"></a>00408 
+<a name="l00409"></a>00409       <span class="comment">/*</span>
+<a name="l00410"></a>00410 <span class="comment">       *-------------------------------------------------------------------</span>
+<a name="l00411"></a>00411 <span class="comment">       *----------------Calibration----------------------------------------</span>
+<a name="l00412"></a>00412 <span class="comment">       *-------------------------------------------------------------------</span>
+<a name="l00413"></a>00413 <span class="comment">       */</span>
+<a name="l00414"></a>00414       <span class="comment">/*----Multiply with calibrated halogen lamp spectrum----*/</span>
+<a name="l00415"></a>00415       <span class="keywordflow">if</span> (cfg->halocorrectInd == 1)
+<a name="l00416"></a>00416         {
+<a name="l00417"></a>00417       sinfo_msg(<span class="stringliteral">"Calibration"</span>);
+<a name="l00418"></a>00418       check_nomsg(halospec = cpl_image_load(cfg->halospectrum,
+<a name="l00419"></a>00419                                                 CPL_TYPE_FLOAT,0,0)) ;
+<a name="l00420"></a>00420 
+<a name="l00421"></a>00421       cknull(calim = sinfo_new_multiply_image_with_spectrum(res_obj,
+<a name="l00422"></a>00422                                                                 halospec),
+<a name="l00423"></a>00423          <span class="stringliteral">" sinfo_new_multiply_image_with_spectrum() failed"</span> ) ;
+<a name="l00424"></a>00424 
+<a name="l00425"></a>00425       sinfo_free_image(&halospec) ;
+<a name="l00426"></a>00426       sinfo_free_image(&res_obj) ;
+<a name="l00427"></a>00427       res_obj = cpl_image_duplicate(calim) ;
+<a name="l00428"></a>00428       sinfo_free_image(&calim);
+<a name="l00429"></a>00429         }
+<a name="l00430"></a>00430 
+<a name="l00431"></a>00431       <span class="comment">/*</span>
+<a name="l00432"></a>00432 <span class="comment">       *-------------------------------------------------------------------</span>
+<a name="l00433"></a>00433 <span class="comment">       *------------------CUBECREATION-------------------------------------</span>
+<a name="l00434"></a>00434 <span class="comment">       *-------------------------------------------------------------------</span>
+<a name="l00435"></a>00435 <span class="comment">       */</span>
+<a name="l00436"></a>00436       sinfo_msg(<span class="stringliteral">"Cube creation"</span>);
+<a name="l00437"></a>00437       <span class="comment">/*---select north-south-test or fitting of slitlet edges--*/</span>
+<a name="l00438"></a>00438       <span class="keywordflow">if</span> (cfg->northsouthInd == 0) {
+<a name="l00439"></a>00439     sinfo_msg(<span class="stringliteral">"cfg->northsouthInd == 0"</span>);
+<a name="l00440"></a>00440     cknull(slit_edges=sinfo_read_slitlets_edges(cfg->nslits,cfg->poslist),
+<a name="l00441"></a>00441            <span class="stringliteral">"error reading slitlets edges"</span>);
+<a name="l00442"></a>00442       } <span class="keywordflow">else</span> {
+<a name="l00443"></a>00443     sinfo_msg(<span class="stringliteral">"cfg->northsouthInd != 0"</span>);
+<a name="l00444"></a>00444     cknull(distances = sinfo_read_distances(cfg->nslits,cfg->distlist),
+<a name="l00445"></a>00445            <span class="stringliteral">"error reading distances"</span>);
+<a name="l00446"></a>00446       }
+<a name="l00447"></a>00447 
+<a name="l00448"></a>00448       cknull(correct_dist = (<span class="keywordtype">float</span>*) cpl_calloc(cfg->nslits, sizeof (<span class="keywordtype">float</span>)),
+<a name="l00449"></a>00449          <span class="stringliteral">" could not allocate memory!"</span>) ;
+<a name="l00450"></a>00450 
+<a name="l00451"></a>00451       sinfo_msg(<span class="stringliteral">"Create cube object"</span>);
+<a name="l00452"></a>00452       <span class="keywordflow">if</span> (cfg->northsouthInd ==0 ) {
+<a name="l00453"></a>00453 
+<a name="l00454"></a>00454         cknull(cube = sinfo_new_make_cube_spi(res_obj,slit_edges,
+<a name="l00455"></a>00455                           correct_dist),
+<a name="l00456"></a>00456            <span class="stringliteral">"could not construct data cube!"</span>) ;
+<a name="l00457"></a>00457 
+<a name="l00458"></a>00458       }  <span class="keywordflow">else</span> {
+<a name="l00459"></a>00459     cknull(cube = sinfo_new_make_cube_dist(res_obj,fcol,distances,
+<a name="l00460"></a>00460                            correct_dist),
+<a name="l00461"></a>00461            <span class="stringliteral">"could not construct a data cube!"</span>) ;
+<a name="l00462"></a>00462       }
+<a name="l00463"></a>00463       sinfo_free_image(&res_obj);
+<a name="l00464"></a>00464 
+<a name="l00465"></a>00465 
+<a name="l00466"></a>00466       <span class="keywordflow">if</span>(strcmp(cfg->sky_dist,<span class="stringliteral">"no_sky"</span>)!=0) {
+<a name="l00467"></a>00467 
+<a name="l00468"></a>00468         sinfo_msg(<span class="stringliteral">"Create cube sky"</span>);
+<a name="l00469"></a>00469         <span class="keywordflow">if</span> (cfg->northsouthInd ==0 ) {
+<a name="l00470"></a>00470           cknull(csky = sinfo_new_make_cube_spi(res_sky,slit_edges,
+<a name="l00471"></a>00471                         correct_dist),
+<a name="l00472"></a>00472          <span class="stringliteral">"could not construct data cube!"</span>) ;
+<a name="l00473"></a>00473         }  <span class="keywordflow">else</span> {
+<a name="l00474"></a>00474           cknull(csky = sinfo_new_make_cube_dist(res_sky,fcol,distances,
+<a name="l00475"></a>00475                          correct_dist),
+<a name="l00476"></a>00476          <span class="stringliteral">"could not construct a data cube!"</span>) ;
+<a name="l00477"></a>00477         }
+<a name="l00478"></a>00478         sinfo_free_image(&res_sky);
+<a name="l00479"></a>00479       }
+<a name="l00480"></a>00480 
+<a name="l00481"></a>00481       <span class="keywordflow">if</span>(n==0) {
+<a name="l00482"></a>00482     <span class="keywordflow">if</span>(strcmp(cfg->mflat_dist,<span class="stringliteral">"not_found"</span>)!=0) {
+<a name="l00483"></a>00483       sinfo_msg(<span class="stringliteral">"Create cube master flat"</span>);
+<a name="l00484"></a>00484       <span class="keywordflow">if</span> (cfg->northsouthInd ==0 ) {
+<a name="l00485"></a>00485         cknull(cflat=sinfo_new_make_cube_spi(res_flat,slit_edges,
+<a name="l00486"></a>00486                          correct_dist),
+<a name="l00487"></a>00487            <span class="stringliteral">"could not construct data cube!"</span>) ;
+<a name="l00488"></a>00488       }  <span class="keywordflow">else</span> {
+<a name="l00489"></a>00489         cknull(cflat = sinfo_new_make_cube_dist(res_flat,fcol,distances,
+<a name="l00490"></a>00490                             correct_dist),
+<a name="l00491"></a>00491            <span class="stringliteral">"could not construct a data cube!"</span>) ;
+<a name="l00492"></a>00492       }
+<a name="l00493"></a>00493       sinfo_free_image(&res_flat);
+<a name="l00494"></a>00494     }
+<a name="l00495"></a>00495       }
+<a name="l00496"></a>00496 
+<a name="l00497"></a>00497       <span class="keywordflow">if</span> (cfg->northsouthInd ==0 )
+<a name="l00498"></a>00498     {
+<a name="l00499"></a>00499       sinfo_new_destroy_2Dfloatarray(&slit_edges,cfg->nslits);
+<a name="l00500"></a>00500     }
+<a name="l00501"></a>00501       <span class="keywordflow">else</span>
+<a name="l00502"></a>00502     {
+<a name="l00503"></a>00503       sinfo_new_destroy_array(&distances);
+<a name="l00504"></a>00504     }
+<a name="l00505"></a>00505 
+<a name="l00506"></a>00506       <span class="comment">/*</span>
+<a name="l00507"></a>00507 <span class="comment">       *--------------------------------------------------------------------</span>
+<a name="l00508"></a>00508 <span class="comment">       *------------------------FINETUNING----------------------------------</span>
+<a name="l00509"></a>00509 <span class="comment">       *--------------------------------------------------------------------</span>
+<a name="l00510"></a>00510 <span class="comment">       * shift the rows of the reconstructed images of the data cube to the</span>
+<a name="l00511"></a>00511 <span class="comment">       * correct sub pixel position select the shift method: polynomial</span>
+<a name="l00512"></a>00512 <span class="comment">       * interpolation, FFT or cubic spline interpolation</span>
+<a name="l00513"></a>00513 <span class="comment">       *--------------------------------------------------------------------</span>
+<a name="l00514"></a>00514 <span class="comment">       */</span>
+<a name="l00515"></a>00515 
+<a name="l00516"></a>00516       <span class="keywordflow">if</span>(strcmp(cfg->sky_dist,<span class="stringliteral">"no_sky"</span>)!=0) {
+<a name="l00517"></a>00517     <span class="keywordflow">if</span>(pdensity > 0) {
+<a name="l00518"></a>00518       cknull(csky2=sinfo_new_fine_tune(csky,
+<a name="l00519"></a>00519                        correct_dist,
+<a name="l00520"></a>00520                        cfg->method,
+<a name="l00521"></a>00521                        cfg->order,
+<a name="l00522"></a>00522                        cfg->nslits),
+<a name="l00523"></a>00523          <span class="stringliteral">" could not fine tune the data cube"</span>) ;
+<a name="l00524"></a>00524 
+<a name="l00525"></a>00525       sinfo_free_imagelist(&csky);
+<a name="l00526"></a>00526       sinfo_msg(<span class="stringliteral">"Stretch output cube along Y direction"</span>);
+<a name="l00527"></a>00527 
+<a name="l00528"></a>00528       cknull(csky = sinfo_new_bin_cube(csky2,1,2,0,63,0,63),
+<a name="l00529"></a>00529          <span class="stringliteral">"error rebinning sky cube"</span>);
+<a name="l00530"></a>00530       sinfo_free_imagelist(&csky2);
+<a name="l00531"></a>00531 
+<a name="l00532"></a>00532 
+<a name="l00533"></a>00533 
+<a name="l00534"></a>00534       snprintf(file_name,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%2.2d%s"</span>,<span class="stringliteral">"out_sky_cube"</span>,
+<a name="l00535"></a>00535            frame_index,<span class="stringliteral">".fits"</span>);
+<a name="l00536"></a>00536       ck0(sinfo_pro_save_ims(csky,sof,sof,file_name,
+<a name="l00537"></a>00537                  PRO_OBS_SKY,NULL,plugin_id,config),
+<a name="l00538"></a>00538           <span class="stringliteral">"cannot dump cube %s"</span>, file_name);
+<a name="l00539"></a>00539       cknull(eima_med=sinfo_new_median_cube(csky),
+<a name="l00540"></a>00540          <span class="stringliteral">"Creating an average image"</span>);
+<a name="l00541"></a>00541       check_nomsg(center_x = cpl_image_get_size_x(eima_med)/ 2. + 0.5);
+<a name="l00542"></a>00542       check_nomsg(center_y = cpl_image_get_size_y(eima_med)/ 2. + 0.5);
+<a name="l00543"></a>00543 
+<a name="l00544"></a>00544       sinfo_new_set_wcs_cube(csky,file_name, cwav,
+<a name="l00545"></a>00545                  dis, cpix, center_x, center_y);
+<a name="l00546"></a>00546 
+<a name="l00547"></a>00547       sinfo_free_imagelist(&csky) ;
+<a name="l00548"></a>00548 
+<a name="l00549"></a>00549       snprintf(file_name,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%2.2d%s"</span>,<span class="stringliteral">"out_sky_med"</span>,
+<a name="l00550"></a>00550            frame_index,<span class="stringliteral">".fits"</span>);
+<a name="l00551"></a>00551       ck0(sinfo_pro_save_ima(eima_med,sof,sof,file_name,
+<a name="l00552"></a>00552                  PRO_SKY_MED,NULL,plugin_id,config),
+<a name="l00553"></a>00553           <span class="stringliteral">"cannot save ima %s"</span>,file_name);
+<a name="l00554"></a>00554 
+<a name="l00555"></a>00555       check_nomsg(sinfo_new_set_wcs_image(eima_med,file_name, center_x, center_y));
+<a name="l00556"></a>00556       sinfo_free_image(&eima_med);
+<a name="l00557"></a>00557     }
+<a name="l00558"></a>00558       }
+<a name="l00559"></a>00559 
+<a name="l00560"></a>00560 
+<a name="l00561"></a>00561 
+<a name="l00562"></a>00562       <span class="keywordflow">if</span>(n==0) {
+<a name="l00563"></a>00563     <span class="keywordflow">if</span>(strcmp(cfg->mflat_dist,<span class="stringliteral">"not_found"</span>)!=0) {
+<a name="l00564"></a>00564       <span class="keywordflow">if</span>(pdensity > 1) {
+<a name="l00565"></a>00565         cknull(cflat2=sinfo_new_fine_tune(cflat,
+<a name="l00566"></a>00566                           correct_dist,
+<a name="l00567"></a>00567                           cfg->method,
+<a name="l00568"></a>00568                           cfg->order,
+<a name="l00569"></a>00569                           cfg->nslits),
+<a name="l00570"></a>00570            <span class="stringliteral">" could not fine tune the data cube"</span>) ;
+<a name="l00571"></a>00571 
+<a name="l00572"></a>00572         sinfo_free_imagelist(&cflat);
+<a name="l00573"></a>00573         sinfo_msg(<span class="stringliteral">"Stretch output cube along Y direction"</span>);
+<a name="l00574"></a>00574 
+<a name="l00575"></a>00575         cknull(cflat = sinfo_new_bin_cube(cflat2,1,2,0,63,0,63),
+<a name="l00576"></a>00576            <span class="stringliteral">"Error binning flat cube"</span>);
+<a name="l00577"></a>00577         sinfo_free_imagelist(&cflat2);
+<a name="l00578"></a>00578 
+<a name="l00579"></a>00579         ck0(sinfo_pro_save_ims(cflat,sof,sof,OBJNOD_OUT_MFLAT_CUBE_FILENAME,
+<a name="l00580"></a>00580                    PRO_MFLAT_CUBE,NULL,plugin_id,config),
+<a name="l00581"></a>00581         <span class="stringliteral">"cannot save cube %s"</span>, OBJNOD_OUT_MFLAT_CUBE_FILENAME);
+<a name="l00582"></a>00582 
+<a name="l00583"></a>00583         sinfo_new_set_wcs_cube(cflat,OBJNOD_OUT_MFLAT_CUBE_FILENAME,cwav, dis,
+<a name="l00584"></a>00584                    cpix, center_x, center_y);
+<a name="l00585"></a>00585 
+<a name="l00586"></a>00586         cknull(eima_avg=sinfo_new_average_cube_to_image(cflat),
+<a name="l00587"></a>00587            <span class="stringliteral">"Creating an average image"</span>);
+<a name="l00588"></a>00588 
+<a name="l00589"></a>00589         ck0(sinfo_pro_save_ima(eima_avg,sof,sof,<span class="stringliteral">"out_mflat_avg.fits"</span>,
+<a name="l00590"></a>00590                    <span class="stringliteral">"MFLAT_AVG"</span>,NULL,plugin_id,config),
+<a name="l00591"></a>00591         <span class="stringliteral">"cannot save ima %s"</span>, <span class="stringliteral">"out_mflat_avg.fits"</span>);
+<a name="l00592"></a>00592 
+<a name="l00593"></a>00593         sinfo_free_image(&eima_avg);
+<a name="l00594"></a>00594 
+<a name="l00595"></a>00595         cknull(eima_med=sinfo_new_median_cube(cflat),
+<a name="l00596"></a>00596            <span class="stringliteral">"Error computing median on cube flat"</span>);
+<a name="l00597"></a>00597 
+<a name="l00598"></a>00598         ck0(sinfo_pro_save_ima(eima_med,sof,sof,<span class="stringliteral">"out_mflat_med.fits"</span>,
+<a name="l00599"></a>00599                    <span class="stringliteral">"MFLAT_MED"</span>,NULL,plugin_id,config),
+<a name="l00600"></a>00600         <span class="stringliteral">"cannot save ima %s"</span>, <span class="stringliteral">"out_mflat_med.fits"</span>);
+<a name="l00601"></a>00601 
+<a name="l00602"></a>00602         sinfo_free_imagelist(&cflat);
+<a name="l00603"></a>00603         sinfo_free_image(&eima_med);
+<a name="l00604"></a>00604       }
+<a name="l00605"></a>00605     }
+<a name="l00606"></a>00606       }
+<a name="l00607"></a>00607 
+<a name="l00608"></a>00608       cknull(outcube2=sinfo_new_fine_tune(cube,
+<a name="l00609"></a>00609                       correct_dist,
+<a name="l00610"></a>00610                       cfg->method,
+<a name="l00611"></a>00611                       cfg->order,
+<a name="l00612"></a>00612                       cfg->nslits),
+<a name="l00613"></a>00613          <span class="stringliteral">" could not fine tune the data cube"</span>) ;
+<a name="l00614"></a>00614 
+<a name="l00615"></a>00615       sinfo_msg(<span class="stringliteral">"Stretch output cube along Y direction"</span>);
+<a name="l00616"></a>00616       cknull(outcube = sinfo_new_bin_cube(outcube2,1,2,0,63,0,63),
+<a name="l00617"></a>00617          <span class="stringliteral">"Error binning cube"</span>);
+<a name="l00618"></a>00618       sinfo_free_imagelist(&cube);
+<a name="l00619"></a>00619       cknull_nomsg(qclog_tbl=sinfo_qclog_init());
+<a name="l00620"></a>00620       sinfo_get_pupil_shift(outcube,n,&qclog_tbl);
+<a name="l00621"></a>00621       snprintf(file_name,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%2.2d%s"</span>,<span class="stringliteral">"out_cube_obj"</span>,
+<a name="l00622"></a>00622            frame_index,<span class="stringliteral">".fits"</span>);
+<a name="l00623"></a>00623 
+<a name="l00624"></a>00624       check_nomsg(center_x = cpl_image_get_size_x(
+<a name="l00625"></a>00625                           cpl_imagelist_get(outcube,0))/2.+0.5) ;
+<a name="l00626"></a>00626       check_nomsg(center_y = cpl_image_get_size_y(
+<a name="l00627"></a>00627                           cpl_imagelist_get(outcube,0))/2.+0.5 );
+<a name="l00628"></a>00628 
+<a name="l00629"></a>00629       <span class="comment">/*----------- atmospheric correction --------------*/</span>
+<a name="l00630"></a>00630       <span class="keywordflow">if</span> (cfg->polyshiftname && strlen(cfg->polyshiftname))
+<a name="l00631"></a>00631       {
+<a name="l00632"></a>00632           sinfo_atm_correction(&outcube,
+<a name="l00633"></a>00633                 sof,
+<a name="l00634"></a>00634                 cfg->polyshiftname,
+<a name="l00635"></a>00635                 dis,
+<a name="l00636"></a>00636                 cwav,
+<a name="l00637"></a>00637                 cpix);
+<a name="l00638"></a>00638       }
+<a name="l00639"></a>00639       <span class="comment">/*-------------------------------------------------*/</span>
+<a name="l00640"></a>00640 
+<a name="l00641"></a>00641       ck0(sinfo_pro_save_ims(outcube,sof,sof,file_name,
+<a name="l00642"></a>00642                  pro_obs,qclog_tbl,plugin_id,config),
+<a name="l00643"></a>00643       <span class="stringliteral">"cannot save cube %s"</span>, file_name);
+<a name="l00644"></a>00644 
+<a name="l00645"></a>00645       sinfo_new_set_wcs_cube(outcube, file_name, cwav, dis,
+<a name="l00646"></a>00646                  cpix, center_x, center_y);
+<a name="l00647"></a>00647       <span class="comment">/* free memory */</span>
+<a name="l00648"></a>00648       <span class="comment">/* to prevent error message comment next line */</span>
+<a name="l00649"></a>00649 
+<a name="l00650"></a>00650       check_nomsg(p=cpl_parameterlist_find(config,
+<a name="l00651"></a>00651                        <span class="stringliteral">"sinfoni.objnod.sky_cor"</span>));
+<a name="l00652"></a>00652 
+<a name="l00653"></a>00653       check_nomsg(sky_cor=cpl_parameter_get_bool(p));
+<a name="l00654"></a>00654       <span class="keywordflow">if</span>(sky_cor == 1 && (pdensity == 1 || pdensity == 3) &&
+<a name="l00655"></a>00655               strcmp(cfg->sky_dist,<span class="stringliteral">"no_sky"</span>)!=0)
+<a name="l00656"></a>00656       {
+<a name="l00657"></a>00657         obj_frm=cpl_frameset_find(sof,pro_obs);
+<a name="l00658"></a>00658         sky_frm=cpl_frameset_find(sof,PRO_OBS_SKY);
+<a name="l00659"></a>00659         sqc=sinfo_skycor_qc_new();
+<a name="l00660"></a>00660         ck0(sinfo_skycor(config, obj_frm,sky_frm,sqc,&obj_cor,&int_obj),
+<a name="l00661"></a>00661             <span class="stringliteral">"determining sky residuals corrected object"</span>);
+<a name="l00662"></a>00662         cpl_frameset_erase(sof,pro_obs);
+<a name="l00663"></a>00663         snprintf(file_name,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%2.2d%s"</span>,<span class="stringliteral">"out_cube_obj_cor"</span>,
+<a name="l00664"></a>00664              frame_index,<span class="stringliteral">".fits"</span>);
+<a name="l00665"></a>00665         ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,<span class="stringliteral">"QC SKYCOR THBKGFIT"</span>,
+<a name="l00666"></a>00666                           sqc->th_fit,<span class="stringliteral">"Thermal background fit success"</span>,<span class="stringliteral">"%d"</span>));
+<a name="l00667"></a>00667 
+<a name="l00668"></a>00668         ck0(sinfo_pro_save_ims(obj_cor,sof,sof,file_name,
+<a name="l00669"></a>00669                    pro_obs,qclog_tbl,plugin_id,config),
+<a name="l00670"></a>00670         <span class="stringliteral">"cannot save cube %s"</span>, file_name);
+<a name="l00671"></a>00671 
+<a name="l00672"></a>00672         sinfo_skycor_qc_delete(&sqc);
+<a name="l00673"></a>00673 
+<a name="l00674"></a>00674         sinfo_new_set_wcs_cube(obj_cor, file_name, cwav, dis,
+<a name="l00675"></a>00675                    cpix, center_x, center_y);
+<a name="l00676"></a>00676 
+<a name="l00677"></a>00677         sinfo_free_imagelist(&obj_cor) ;
+<a name="l00678"></a>00678         snprintf(file_name,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%2.2d%s"</span>,<span class="stringliteral">"out_int_obj"</span>,
+<a name="l00679"></a>00679          frame_index,<span class="stringliteral">".fits"</span>);
+<a name="l00680"></a>00680 
+<a name="l00681"></a>00681         ck0(sinfo_pro_save_tbl(int_obj,sof,sof,file_name,
+<a name="l00682"></a>00682                    PRO_SPECTRA_QC,qclog_tbl,plugin_id,config),
+<a name="l00683"></a>00683         <span class="stringliteral">"cannot save cube %s"</span>, file_name);
+<a name="l00684"></a>00684         sinfo_free_table(&int_obj) ;
+<a name="l00685"></a>00685       }
+<a name="l00686"></a>00686       sinfo_free_table(&qclog_tbl);
+<a name="l00687"></a>00687       sinfo_free_imagelist(&outcube2);
+<a name="l00688"></a>00688       sinfo_free_imagelist(&outcube) ;
+<a name="l00689"></a>00689       sinfo_free_float(&correct_dist) ;
+<a name="l00690"></a>00690 
+<a name="l00691"></a>00691     } <span class="comment">/* end loop over n (nframes) */</span>
+<a name="l00692"></a>00692 
+<a name="l00693"></a>00693   <span class="comment">/* free memory */</span>
+<a name="l00694"></a>00694   sinfo_objnod_free(&cfg);
+<a name="l00695"></a>00695   sinfo_free_frameset(&stk);
+<a name="l00696"></a>00696 
+<a name="l00697"></a>00697 
+<a name="l00698"></a>00698   <span class="keywordflow">return</span> 0;
+<a name="l00699"></a>00699 
+<a name="l00700"></a>00700  cleanup:
+<a name="l00701"></a>00701   sinfo_skycor_qc_delete(&sqc);
+<a name="l00702"></a>00702   sinfo_free_imagelist(&obj_cor) ;
+<a name="l00703"></a>00703   sinfo_free_propertylist(&plist);
+<a name="l00704"></a>00704   sinfo_free_imagelist(&outcube2) ;
+<a name="l00705"></a>00705   sinfo_free_imagelist(&outcube) ;
+<a name="l00706"></a>00706   sinfo_free_table(&qclog_tbl);
+<a name="l00707"></a>00707   sinfo_free_image(&eima_avg);
+<a name="l00708"></a>00708   sinfo_free_image(&eima_med);
+<a name="l00709"></a>00709   sinfo_free_imagelist(&cflat) ;
+<a name="l00710"></a>00710   sinfo_free_imagelist(&cflat2) ;
+<a name="l00711"></a>00711   sinfo_free_imagelist(&cube) ;
+<a name="l00712"></a>00712   sinfo_free_imagelist(&csky) ;
+<a name="l00713"></a>00713   sinfo_free_imagelist(&csky2) ;
+<a name="l00714"></a>00714 
+<a name="l00715"></a>00715   <span class="keywordflow">if</span>(cfg!=NULL) {
+<a name="l00716"></a>00716     <span class="keywordflow">if</span> (cfg->northsouthInd ==0 ) {
+<a name="l00717"></a>00717       <span class="keywordflow">if</span>(slit_edges != NULL) {
+<a name="l00718"></a>00718     sinfo_new_destroy_2Dfloatarray(&slit_edges,cfg->nslits);
+<a name="l00719"></a>00719       }
+<a name="l00720"></a>00720     } <span class="keywordflow">else</span> {
+<a name="l00721"></a>00721       <span class="keywordflow">if</span> (distances != NULL ) {
+<a name="l00722"></a>00722     sinfo_new_destroy_array(&distances);
+<a name="l00723"></a>00723       }
+<a name="l00724"></a>00724     }
+<a name="l00725"></a>00725   }
+<a name="l00726"></a>00726 
+<a name="l00727"></a>00727   sinfo_free_float(&correct_dist);
+<a name="l00728"></a>00728   sinfo_free_image(&res_flat);
+<a name="l00729"></a>00729   sinfo_free_image(&res_sky);
+<a name="l00730"></a>00730   sinfo_free_image(&res_wim);
+<a name="l00731"></a>00731   sinfo_free_image(&calim);
+<a name="l00732"></a>00732   sinfo_free_image(&halospec) ;
+<a name="l00733"></a>00733   sinfo_free_image(&sky_im) ;
+<a name="l00734"></a>00734   sinfo_free_image(&res_obj);
+<a name="l00735"></a>00735   sinfo_free_image(&flat_im) ;
+<a name="l00736"></a>00736   sinfo_free_image(&wavemapim);
+<a name="l00737"></a>00737   sinfo_free_image(&wim);
+<a name="l00738"></a>00738   sinfo_free_image(&im);
+<a name="l00739"></a>00739   sinfo_objnod_free(&cfg);
+<a name="l00740"></a>00740   sinfo_free_frameset(&stk);
+<a name="l00741"></a>00741 
+<a name="l00742"></a>00742   <span class="keywordflow">return</span> -1;
+<a name="l00743"></a>00743 
+<a name="l00744"></a>00744 
+<a name="l00745"></a>00745 
+<a name="l00746"></a>00746 }
+<a name="l00747"></a>00747 
+<a name="l00748"></a>00748 <span class="keyword">static</span> <span class="keywordtype">void</span> 
+<a name="l00749"></a>00749 sinfo_atm_correction(cpl_imagelist** ppCube,
+<a name="l00750"></a>00750         cpl_frameset* sof,
+<a name="l00751"></a>00751         <span class="keyword">const</span> <span class="keywordtype">char</span>* polyshiftname,
+<a name="l00752"></a>00752         <span class="keywordtype">double</span> dis_cube,
+<a name="l00753"></a>00753         <span class="keywordtype">double</span> centralLambda_cube,
+<a name="l00754"></a>00754         <span class="keywordtype">int</span> centralpix_cube)
+<a name="l00755"></a>00755 {
+<a name="l00756"></a>00756     cpl_polynomial* poly = NULL;
+<a name="l00757"></a>00757     cpl_frame* first_frame=NULL;
+<a name="l00758"></a>00758     <span class="keyword">const</span> <span class="keywordtype">char</span>* ref_file=NULL;
+<a name="l00759"></a>00759     cpl_propertylist *plist_cube = NULL;
+<a name="l00760"></a>00760     cpl_propertylist* ppolylist = NULL;
+<a name="l00761"></a>00761     cpl_imagelist* retcube = NULL;
+<a name="l00762"></a>00762 
+<a name="l00763"></a>00763         <span class="comment">/* we use the pointer outcube as a handle to  *ppCube </span>
+<a name="l00764"></a>00764 <span class="comment">             (don't initialize to NULL!)*/</span>
+<a name="l00765"></a>00765     cpl_imagelist* outcube = *ppCube; 
+<a name="l00766"></a>00766        <span class="comment">/* Get the reference file  */</span>
+<a name="l00767"></a>00767     first_frame = cpl_frameset_get_first(sof) ;
+<a name="l00768"></a>00768     ref_file = cpl_frame_get_filename(first_frame) ;
+<a name="l00769"></a>00769     <span class="keywordflow">if</span> (ref_file && strlen(ref_file))
+<a name="l00770"></a>00770     {
+<a name="l00771"></a>00771         <span class="comment">/* Get FITS header from reference file */</span>
+<a name="l00772"></a>00772         <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"adjusting atmospheric correction ref_file[%s]"</span>, ref_file);
+<a name="l00773"></a>00773         plist_cube = cpl_propertylist_load(ref_file, 0);
+<a name="l00774"></a>00774         <span class="keywordflow">if</span> (plist_cube)
+<a name="l00775"></a>00775         {
+<a name="l00776"></a>00776               <span class="comment">// check the OPTI1.NAME</span>
+<a name="l00777"></a>00777                 ppolylist = cpl_propertylist_load(polyshiftname,0);
+<a name="l00778"></a>00778             <span class="keywordflow">if</span> (ppolylist)
+<a name="l00779"></a>00779             {
+<a name="l00780"></a>00780                 <span class="keywordtype">double</span> pixelscale = sinfo_pfits_get_pixscale(plist_cube);
+<a name="l00781"></a>00781                 <span class="keywordtype">double</span> poly_pixelscale = sinfo_pfits_get_pixscale(ppolylist);
+<a name="l00782"></a>00782                 <span class="keywordflow">if</span> (fabs(poly_pixelscale - pixelscale) < 1E-8)
+<a name="l00783"></a>00783                 {
+<a name="l00784"></a>00784                     poly = sinfo_atmo_load_polynom(polyshiftname);
+<a name="l00785"></a>00785                     <span class="keywordflow">if</span> (!poly)
+<a name="l00786"></a>00786                     {
+<a name="l00787"></a>00787                         <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"Cannot load polynom from [%s]"</span>, polyshiftname);
+<a name="l00788"></a>00788                     }
+<a name="l00789"></a>00789                     <span class="keywordflow">else</span>
+<a name="l00790"></a>00790                     {
+<a name="l00791"></a>00791                         <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"polynom from [%s] is loaded"</span>, polyshiftname);
+<a name="l00792"></a>00792                     }
+<a name="l00793"></a>00793                 }
+<a name="l00794"></a>00794                 <span class="keywordflow">else</span>
+<a name="l00795"></a>00795                 {
+<a name="l00796"></a>00796                     <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"pixelscale for the polynomial fit "</span>
+<a name="l00797"></a>00797                             <span class="stringliteral">"is different: provided[%f] expected[%f]"</span>,
+<a name="l00798"></a>00798                             poly_pixelscale, pixelscale);
+<a name="l00799"></a>00799                 }
+<a name="l00800"></a>00800                 sinfo_free_propertylist(&ppolylist);
+<a name="l00801"></a>00801             }
+<a name="l00802"></a>00802             <span class="keywordflow">if</span> (!poly)
+<a name="l00803"></a>00803             {
+<a name="l00804"></a>00804                 <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"Pixel shift due atmospheric refraction"</span>
+<a name="l00805"></a>00805                       <span class="stringliteral">" would not be applied"</span>);
+<a name="l00806"></a>00806             }
+<a name="l00807"></a>00807         }
+<a name="l00808"></a>00808         <span class="keywordflow">else</span>
+<a name="l00809"></a>00809         {
+<a name="l00810"></a>00810             <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"cannot load propertylist for the frame"</span>);
+<a name="l00811"></a>00811         }
+<a name="l00812"></a>00812         <span class="keywordflow">if</span> (poly)
+<a name="l00813"></a>00813         {
+<a name="l00814"></a>00814             <span class="keywordtype">double</span> airmass = (
+<a name="l00815"></a>00815                   (cpl_propertylist_get_double(plist_cube, <span class="stringliteral">"ESO TEL AIRM START"</span>) +
+<a name="l00816"></a>00816                   cpl_propertylist_get_double(plist_cube, <span class="stringliteral">"ESO TEL AIRM END"</span>))
+<a name="l00817"></a>00817                   / 2
+<a name="l00818"></a>00818                   );
+<a name="l00819"></a>00819             <span class="keywordtype">double</span> angle = (
+<a name="l00820"></a>00820                   (cpl_propertylist_get_double(plist_cube, <span class="stringliteral">"ESO ADA ABSROT START"</span>) +
+<a name="l00821"></a>00821                   cpl_propertylist_get_double(plist_cube, <span class="stringliteral">"ESO ADA ABSROT END"</span>))
+<a name="l00822"></a>00822                   / 2
+<a name="l00823"></a>00823                   ) * PI_NUMB / 180;
+<a name="l00824"></a>00824             sinfo_msg(<span class="stringliteral">"dis_cube[%f] centralLambda_cube[%f] centralpix_cube[%d]"</span>,dis_cube,centralLambda_cube,centralpix_cube);
+<a name="l00825"></a>00825             retcube = sinfo_atmo_apply_cube_polynomial_shift(
+<a name="l00826"></a>00826                     poly, outcube,
+<a name="l00827"></a>00827                     centralLambda_cube,
+<a name="l00828"></a>00828                     airmass,
+<a name="l00829"></a>00829                     angle,
+<a name="l00830"></a>00830                     dis_cube,
+<a name="l00831"></a>00831                     centralpix_cube);
+<a name="l00832"></a>00832          sinfo_free_polynomial(&poly);
+<a name="l00833"></a>00833          <span class="keywordflow">if</span> (retcube)
+<a name="l00834"></a>00834          {
+<a name="l00835"></a>00835              sinfo_free_imagelist(&outcube);
+<a name="l00836"></a>00836              *ppCube = retcube;
+<a name="l00837"></a>00837          }
+<a name="l00838"></a>00838       }
+<a name="l00839"></a>00839       sinfo_free_propertylist(&plist_cube);
+<a name="l00840"></a>00840     }
+<a name="l00841"></a>00841 
+<a name="l00842"></a>00842 
+<a name="l00843"></a>00843     <span class="keywordflow">return</span>;
+<a name="l00844"></a>00844 }
+<a name="l00845"></a>00845 
+<a name="l00846"></a>00846 <span class="comment">/* Temporally commented out as not yet used</span>
+<a name="l00847"></a>00847 <span class="comment">static cpl_image*</span>
+<a name="l00848"></a>00848 <span class="comment">sinfo_flux_corr(const cpl_image* inp,const cpl_image* wav,const double dis)</span>
+<a name="l00849"></a>00849 <span class="comment">{</span>
+<a name="l00850"></a>00850 <span class="comment"></span>
+<a name="l00851"></a>00851 <span class="comment">  cpl_image* out=NULL;</span>
+<a name="l00852"></a>00852 <span class="comment">  cpl_image* dif=NULL;</span>
+<a name="l00853"></a>00853 <span class="comment">  const float* pi=NULL;</span>
+<a name="l00854"></a>00854 <span class="comment">  const float* pw=NULL;</span>
+<a name="l00855"></a>00855 <span class="comment">  float* po=NULL;</span>
+<a name="l00856"></a>00856 <span class="comment">  float* pd=NULL;</span>
+<a name="l00857"></a>00857 <span class="comment"></span>
+<a name="l00858"></a>00858 <span class="comment">  int i=0;</span>
+<a name="l00859"></a>00859 <span class="comment">  int j=0;</span>
+<a name="l00860"></a>00860 <span class="comment">  int nx=0;</span>
+<a name="l00861"></a>00861 <span class="comment">  int ny=0;</span>
+<a name="l00862"></a>00862 <span class="comment">  int stat=0;</span>
+<a name="l00863"></a>00863 <span class="comment">  nx=cpl_image_get_size_x(inp);</span>
+<a name="l00864"></a>00864 <span class="comment">  ny=cpl_image_get_size_y(inp);</span>
+<a name="l00865"></a>00865 <span class="comment"></span>
+<a name="l00866"></a>00866 <span class="comment">  out=cpl_image_new(nx,ny,CPL_TYPE_FLOAT);</span>
+<a name="l00867"></a>00867 <span class="comment">  dif=cpl_image_new(nx,ny,CPL_TYPE_FLOAT);</span>
+<a name="l00868"></a>00868 <span class="comment">  pi=cpl_image_get_data_const(inp);</span>
+<a name="l00869"></a>00869 <span class="comment">  pw=cpl_image_get_data_const(wav);</span>
+<a name="l00870"></a>00870 <span class="comment">  po=cpl_image_get_data(out);</span>
+<a name="l00871"></a>00871 <span class="comment">  pd=cpl_image_get_data(dif);</span>
+<a name="l00872"></a>00872 <span class="comment"></span>
+<a name="l00873"></a>00873 <span class="comment">  sinfo_msg("dif=%10.8f",2.*dis/(cpl_image_get(wav,500,501,&stat)-</span>
+<a name="l00874"></a>00874 <span class="comment">                 cpl_image_get(wav,500,499,&stat)));</span>
+<a name="l00875"></a>00875 <span class="comment"></span>
+<a name="l00876"></a>00876 <span class="comment">  sinfo_msg("dif=%10.8f",2.*dis/(cpl_image_get(wav,500,101,&stat)-</span>
+<a name="l00877"></a>00877 <span class="comment">                 cpl_image_get(wav,500,99,&stat)));</span>
+<a name="l00878"></a>00878 <span class="comment"></span>
+<a name="l00879"></a>00879 <span class="comment">  sinfo_msg("dif=%10.8f",2.*dis/(cpl_image_get(wav,500,1001,&stat)-</span>
+<a name="l00880"></a>00880 <span class="comment">                 cpl_image_get(wav,500,999,&stat)));</span>
+<a name="l00881"></a>00881 <span class="comment"></span>
+<a name="l00882"></a>00882 <span class="comment">  for(i=0;i<nx;i++) {</span>
+<a name="l00883"></a>00883 <span class="comment">    for(j=1;j<ny-1;j++) {</span>
+<a name="l00884"></a>00884 <span class="comment">      if(pi[nx*j+i] != ZERO || pw[nx*j+i] != ZERO) {</span>
+<a name="l00885"></a>00885 <span class="comment">    po[nx*j+i]=pi[nx*j+i]*dis/((pw[nx*(j+1)+i]-pw[nx*(j-1)+i])*0.5);</span>
+<a name="l00886"></a>00886 <span class="comment">    pd[nx*j+i]=dis/((pw[nx*(j+1)+i]-pw[nx*(j-1)+i])*0.5);</span>
+<a name="l00887"></a>00887 <span class="comment">      } else {</span>
+<a name="l00888"></a>00888 <span class="comment">    po[nx*j+i]=ZERO;</span>
+<a name="l00889"></a>00889 <span class="comment">    pd[nx*j+i]=ZERO;</span>
+<a name="l00890"></a>00890 <span class="comment">      }</span>
+<a name="l00891"></a>00891 <span class="comment">    }</span>
+<a name="l00892"></a>00892 <span class="comment"></span>
+<a name="l00893"></a>00893 <span class="comment"></span>
+<a name="l00894"></a>00894 <span class="comment">    if(pi[i] != ZERO || pw[i] != ZERO) {</span>
+<a name="l00895"></a>00895 <span class="comment">      po[i]=pi[i]*dis/(pw[nx+i]-pw[i]);</span>
+<a name="l00896"></a>00896 <span class="comment">      pd[i]=dis/(pw[nx+i]-pw[i]);</span>
+<a name="l00897"></a>00897 <span class="comment">    } else {</span>
+<a name="l00898"></a>00898 <span class="comment">      po[i]=ZERO;</span>
+<a name="l00899"></a>00899 <span class="comment">      pd[i]=ZERO;</span>
+<a name="l00900"></a>00900 <span class="comment">    }</span>
+<a name="l00901"></a>00901 <span class="comment"></span>
+<a name="l00902"></a>00902 <span class="comment"></span>
+<a name="l00903"></a>00903 <span class="comment"></span>
+<a name="l00904"></a>00904 <span class="comment">    if(pi[nx*(ny-1)+i] != ZERO || pw[nx*(ny-1)+i] != ZERO) {</span>
+<a name="l00905"></a>00905 <span class="comment">      po[nx*(ny-1)+i]=pi[nx*(ny-1)+i]*dis/(pw[nx*(ny-1)+i]-pw[nx*(ny-2)+i]);</span>
+<a name="l00906"></a>00906 <span class="comment">      pd[nx*(ny-1)+i]=dis/(pw[nx*(ny-1)+i]-pw[nx*(ny-2)+i]);</span>
+<a name="l00907"></a>00907 <span class="comment">    } else {</span>
+<a name="l00908"></a>00908 <span class="comment">      po[nx*(ny-1)+i]=ZERO;</span>
+<a name="l00909"></a>00909 <span class="comment">      pd[nx*(ny-1)+i]=ZERO;</span>
+<a name="l00910"></a>00910 <span class="comment">    }</span>
+<a name="l00911"></a>00911 <span class="comment"></span>
+<a name="l00912"></a>00912 <span class="comment">  }</span>
+<a name="l00913"></a>00913 <span class="comment">  //cpl_image_save(dif,"diff.fits", CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT);</span>
+<a name="l00914"></a>00914 <span class="comment"></span>
+<a name="l00915"></a>00915 <span class="comment">  sinfo_free_image(&dif);</span>
+<a name="l00916"></a>00916 <span class="comment"></span>
+<a name="l00917"></a>00917 <span class="comment"></span>
+<a name="l00918"></a>00918 <span class="comment">  return out;</span>
+<a name="l00919"></a>00919 <span class="comment"></span>
+<a name="l00920"></a>00920 <span class="comment">}</span>
+<a name="l00921"></a>00921 <span class="comment">*/</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__new__cubes__build_8h_source.html b/html/sinfo__new__cubes__build_8h_source.html
new file mode 100644
index 0000000..84dc9bc
--- /dev/null
+++ b/html/sinfo__new__cubes__build_8h_source.html
@@ -0,0 +1,91 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_new_cubes_build.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_new_cubes_build.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#ifndef SINFO_NEW_CUBES_BUILD_H</span>
+<a name="l00002"></a>00002 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_NEW_CUBES_BUILD_H</span>
+<a name="l00003"></a>00003 <span class="preprocessor"></span><span class="comment">/*</span>
+<a name="l00004"></a>00004 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00005"></a>00005 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00006"></a>00006 <span class="comment"> *</span>
+<a name="l00007"></a>00007 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00008"></a>00008 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00009"></a>00009 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00010"></a>00010 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00011"></a>00011 <span class="comment"> *</span>
+<a name="l00012"></a>00012 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00013"></a>00013 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00014"></a>00014 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00015"></a>00015 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00016"></a>00016 <span class="comment"> *</span>
+<a name="l00017"></a>00017 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00018"></a>00018 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00019"></a>00019 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00020"></a>00020 <span class="comment"> */</span>
+<a name="l00021"></a>00021 <span class="comment">/*******************************************************************************</span>
+<a name="l00022"></a>00022 <span class="comment">* E.S.O. - VLT project</span>
+<a name="l00023"></a>00023 <span class="comment">*</span>
+<a name="l00024"></a>00024 <span class="comment">* "@(#) $Id: sinfo_new_cubes_build.h,v 1.11 2007/06/06 07:10:45 amodigli Exp $"</span>
+<a name="l00025"></a>00025 <span class="comment">*</span>
+<a name="l00026"></a>00026 <span class="comment">* who       when      what</span>
+<a name="l00027"></a>00027 <span class="comment">* --------  --------  ----------------------------------------------</span>
+<a name="l00028"></a>00028 <span class="comment">* schreib  06/05/03  created</span>
+<a name="l00029"></a>00029 <span class="comment">*/</span>
+<a name="l00030"></a>00030 
+<a name="l00031"></a>00031 <span class="comment">/************************************************************************</span>
+<a name="l00032"></a>00032 <span class="comment"> * sinfo_cubes_build.h</span>
+<a name="l00033"></a>00033 <span class="comment"> * routines to create a data cube</span>
+<a name="l00034"></a>00034 <span class="comment"> *----------------------------------------------------------------------</span>
+<a name="l00035"></a>00035 <span class="comment"> */</span>
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="comment">/*</span>
+<a name="l00038"></a>00038 <span class="comment"> * header files</span>
+<a name="l00039"></a>00039 <span class="comment"> */</span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include <math.h></span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include <cpl.h></span>   
+<a name="l00042"></a>00042 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00043"></a>00043 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00044"></a>00044 <span class="comment"> *                        Function ANSI C prototypes</span>
+<a name="l00045"></a>00045 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00046"></a>00046 
+<a name="l00047"></a>00047 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00048"></a>00048 <span class="comment">   @name sinfo_new_cubes_build()</span>
+<a name="l00049"></a>00049 <span class="comment">   @param  plugin_id name of recipe plugin</span>
+<a name="l00050"></a>00050 <span class="comment">   @param  config input parameter list</span>
+<a name="l00051"></a>00051 <span class="comment">   @param  sof input frameset</span>
+<a name="l00052"></a>00052 <span class="comment">   @param  procatg</span>
+<a name="l00053"></a>00053 <span class="comment">   @param  frame_index index of processed frame</span>
+<a name="l00054"></a>00054 <span class="comment">   @return integer (0 if it worked, -1 if it doesn't) </span>
+<a name="l00055"></a>00055 <span class="comment">   @doc this routine does the resampling of an offset-corrected,</span>
+<a name="l00056"></a>00056 <span class="comment">        flatfielded, bad pixel corrected and</span>
+<a name="l00057"></a>00057 <span class="comment">        eventually interleaved data frame. Additionally, an intensity </span>
+<a name="l00058"></a>00058 <span class="comment">        calibration is carried through by using</span>
+<a name="l00059"></a>00059 <span class="comment">        a standard star or a black body measurement. </span>
+<a name="l00060"></a>00060 <span class="comment">        The spectral features of the flatfield halogen lamp are corrected.</span>
+<a name="l00061"></a>00061 <span class="comment">        Afterwards a data cube is created out of the resampled image.</span>
+<a name="l00062"></a>00062 <span class="comment">    It is the users choice to use either</span>
+<a name="l00063"></a>00063 <span class="comment">        the fitted sinfo_edge positions of the slitlets or the distances</span>
+<a name="l00064"></a>00064 <span class="comment">    of the slitlets gained from a north-south-test. </span>
+<a name="l00065"></a>00065 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00066"></a>00066 <span class="keywordtype">int</span> 
+<a name="l00067"></a>00067 sinfo_new_cubes_build (<span class="keyword">const</span> <span class="keywordtype">char</span>* plugin_id,
+<a name="l00068"></a>00068                        cpl_parameterlist* config, 
+<a name="l00069"></a>00069                        cpl_frameset* sof, 
+<a name="l00070"></a>00070                        <span class="keyword">const</span> <span class="keywordtype">char</span>* procatg, 
+<a name="l00071"></a>00071                        <span class="keyword">const</span> <span class="keywordtype">int</span> frame_index) ;
+<a name="l00072"></a>00072 
+<a name="l00073"></a>00073 
+<a name="l00074"></a>00074 <span class="preprocessor">#endif </span>
+<a name="l00076"></a>00076 <span class="preprocessor"></span><span class="comment">/*--------------------------------------------------------------------------*/</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__new__cubes__coadd_8c_source.html b/html/sinfo__new__cubes__coadd_8c_source.html
new file mode 100644
index 0000000..460b07c
--- /dev/null
+++ b/html/sinfo__new__cubes__coadd_8c_source.html
@@ -0,0 +1,649 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_new_cubes_coadd.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_new_cubes_coadd.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment"></span>
+<a name="l00021"></a>00021 <span class="comment">File name    :       sinfo_new_cubes_coadd.c</span>
+<a name="l00022"></a>00022 <span class="comment">Author       :    J. Schreiber</span>
+<a name="l00023"></a>00023 <span class="comment">Created on   :    December 3, 2003</span>
+<a name="l00024"></a>00024 <span class="comment">Description  :    Creates data cubes or merges data cubes</span>
+<a name="l00025"></a>00025 <span class="comment">out of jittered object-sky</span>
+<a name="l00026"></a>00026 <span class="comment">nodding observations</span>
+<a name="l00027"></a>00027 <span class="comment">---------------------------------------------------------------------------*/</span>
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span>
+<a name="l00032"></a>00032 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">  Includes</span>
+<a name="l00034"></a>00034 <span class="comment">  ---------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 <span class="preprocessor">#include "sinfo_new_cubes_coadd.h"</span>
+<a name="l00036"></a>00036 <span class="preprocessor">#include "sinfo_pfits.h"</span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include "sinfo_baryvel.h"</span>
+<a name="l00038"></a>00038 <span class="preprocessor">#include "sinfo_pro_save.h"</span>
+<a name="l00039"></a>00039 <span class="preprocessor">#include "sinfo_objnod_ini_by_cpl.h"</span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include "sinfo_functions.h"</span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include "sinfo_utilities_scired.h"</span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include "sinfo_wave_calibration.h"</span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include "sinfo_cube_construct.h"</span>
+<a name="l00044"></a>00044 <span class="preprocessor">#include "sinfo_error.h"</span>
+<a name="l00045"></a>00045 <span class="preprocessor">#include "sinfo_utils_wrappers.h"</span>
+<a name="l00046"></a>00046 <span class="comment">//Used only for sinfo_propertylist_has</span>
+<a name="l00047"></a>00047 <span class="preprocessor">#include "sinfo_dfs.h"</span>
+<a name="l00048"></a>00048 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00049"></a>00049 <span class="comment">  Defines</span>
+<a name="l00050"></a>00050 <span class="comment">  ---------------------------------------------------------------------------*/</span>
+<a name="l00051"></a>00051 <span class="preprocessor">#define PI_NUMB        (3.1415926535897932384626433832795) </span><span class="comment">/* pi */</span>
+<a name="l00052"></a>00052 
+<a name="l00053"></a>00053 
+<a name="l00054"></a>00054 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00055"></a>00055 <span class="comment">  Function Definitions</span>
+<a name="l00056"></a>00056 <span class="comment">  ---------------------------------------------------------------------------*/</span>
+<a name="l00057"></a>00057 
+<a name="l00066"></a>00066 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00067"></a>00067 <span class="comment">  Function     : sinfo_new_cubes_coadd()</span>
+<a name="l00068"></a>00068 <span class="comment">  In           : ini_file: file name of according .ini file</span>
+<a name="l00069"></a>00069 <span class="comment">  Out          : integer (0 if it worked, -1 if it doesn't)</span>
+<a name="l00070"></a>00070 <span class="comment">  Job          : this routine carries through the data cube creation of an</span>
+<a name="l00071"></a>00071 <span class="comment">  object science observation using object-sky nodding</span>
+<a name="l00072"></a>00072 <span class="comment">  and jittering. This script expects jittered frames that</span>
+<a name="l00073"></a>00073 <span class="comment">  were already sky-subtracted</span>
+<a name="l00074"></a>00074 <span class="comment">  averaged, flatfielded, spectral tilt corrected and</span>
+<a name="l00075"></a>00075 <span class="comment">  interleaved if necessary</span>
+<a name="l00076"></a>00076 <span class="comment">  ---------------------------------------------------------------------------*/</span>
+<a name="l00077"></a>00077 <span class="keywordtype">int</span>
+<a name="l00078"></a>00078 sinfo_new_cubes_coadd (<span class="keyword">const</span> <span class="keywordtype">char</span>* plugin_id,cpl_parameterlist* config,
+<a name="l00079"></a>00079                        cpl_frameset* sof, <span class="keyword">const</span> <span class="keywordtype">char</span>* procatg)
+<a name="l00080"></a>00080 {
+<a name="l00081"></a>00081 
+<a name="l00082"></a>00082    object_config * cfg=NULL ;
+<a name="l00083"></a>00083    cpl_image * im=NULL ;
+<a name="l00084"></a>00084    cpl_image* jitter_image=NULL;
+<a name="l00085"></a>00085    cpl_imagelist  ** cube_tmp=NULL ;
+<a name="l00086"></a>00086 
+<a name="l00087"></a>00087    cpl_imagelist  ** cubeobject=NULL ;
+<a name="l00088"></a>00088    cpl_imagelist  * jittercube=NULL ;
+<a name="l00089"></a>00089    cpl_imagelist  * maskcube=NULL ;
+<a name="l00090"></a>00090    cpl_propertylist* plist=NULL;
+<a name="l00091"></a>00091    <span class="keywordtype">int</span> sky_cor=0;
+<a name="l00092"></a>00092    <span class="keywordtype">int</span> pdensity=0;
+<a name="l00093"></a>00093 
+<a name="l00094"></a>00094    <span class="keywordtype">int</span> i=0;
+<a name="l00095"></a>00095    <span class="keywordtype">int</span> n=0 ;
+<a name="l00096"></a>00096    <span class="keywordtype">int</span> partind = 0 ;
+<a name="l00097"></a>00097    <span class="keywordtype">int</span> centralpix=0 ;
+<a name="l00098"></a>00098    <span class="keywordtype">int</span> z_siz=0;
+<a name="l00099"></a>00099    <span class="keywordtype">int</span> z_min=0;
+<a name="l00100"></a>00100    <span class="keywordtype">int</span> z_max=0;
+<a name="l00101"></a>00101    <span class="keywordtype">int</span> z=0;
+<a name="l00102"></a>00102    <span class="keywordtype">int</span> z_stp=100;
+<a name="l00103"></a>00103    <span class="keywordtype">int</span> scales_sky=0;
+<a name="l00104"></a>00104    <span class="keywordtype">int</span> ks_clip=0;
+<a name="l00105"></a>00105    <span class="keywordtype">double</span> kappa=2.0;
+<a name="l00106"></a>00106 
+<a name="l00107"></a>00107    <span class="keywordtype">float</span> ref_offx=0;
+<a name="l00108"></a>00108    <span class="keywordtype">float</span> ref_offy=0;
+<a name="l00109"></a>00109    <span class="keywordtype">float</span> newcenter_x=0 ;
+<a name="l00110"></a>00110    <span class="keywordtype">float</span> newcenter_y=0 ;
+<a name="l00111"></a>00111    <span class="keywordtype">float</span> cd1_1=0;
+<a name="l00112"></a>00112    <span class="keywordtype">float</span> cd1_2=0;
+<a name="l00113"></a>00113    <span class="keywordtype">float</span> cd2_1=0;
+<a name="l00114"></a>00114    <span class="keywordtype">float</span> cd2_2=0;
+<a name="l00115"></a>00115    <span class="keywordtype">double</span> pixelscale=0;
+<a name="l00116"></a>00116    <span class="keywordtype">double</span> angle=0;
+<a name="l00117"></a>00117    <span class="keywordtype">float</span> radangle=0 ;
+<a name="l00118"></a>00118    <span class="keywordtype">double</span> exptime=0 ;
+<a name="l00119"></a>00119 
+<a name="l00120"></a>00120    <span class="keywordtype">double</span> * times=NULL ;
+<a name="l00121"></a>00121    <span class="keywordtype">float</span> * offsetx=NULL;
+<a name="l00122"></a>00122    <span class="keywordtype">float</span> * offsety=NULL;
+<a name="l00123"></a>00123    <span class="keywordtype">float</span> offx_min=1.e10;
+<a name="l00124"></a>00124    <span class="keywordtype">float</span> offy_min=1.e10;
+<a name="l00125"></a>00125    <span class="keywordtype">float</span> offx_max=-1.e10;
+<a name="l00126"></a>00126    <span class="keywordtype">float</span> offy_max=-1.e10;
+<a name="l00127"></a>00127 
+<a name="l00128"></a>00128    <span class="keywordtype">double</span> dis=0 ;
+<a name="l00129"></a>00129    <span class="keywordtype">double</span> centralLambda=0 ;
+<a name="l00130"></a>00130    <span class="keywordtype">double</span> mjd_obs=0;
+<a name="l00131"></a>00131 
+<a name="l00132"></a>00132    <span class="keywordtype">char</span> name_jitter[MAX_NAME_SIZE] ;
+<a name="l00133"></a>00133    <span class="keywordtype">char</span> pro_mjit[MAX_NAME_SIZE];
+<a name="l00134"></a>00134    <span class="keywordtype">char</span> pro_obs[MAX_NAME_SIZE];
+<a name="l00135"></a>00135    <span class="keywordtype">char</span> pro_med[MAX_NAME_SIZE];
+<a name="l00136"></a>00136 
+<a name="l00137"></a>00137 
+<a name="l00138"></a>00138    <span class="keywordtype">char</span> * name=NULL ;
+<a name="l00139"></a>00139    <span class="keywordtype">char</span> * partname=NULL;
+<a name="l00140"></a>00140    <span class="keywordtype">char</span> * partname2=NULL ;
+<a name="l00141"></a>00141    <span class="keywordtype">char</span> file_name[MAX_NAME_SIZE];
+<a name="l00142"></a>00142    <span class="keywordtype">int</span> vllx=0;
+<a name="l00143"></a>00143    <span class="keywordtype">int</span> vlly=0;
+<a name="l00144"></a>00144    <span class="keywordtype">int</span> vurx=0;
+<a name="l00145"></a>00145    <span class="keywordtype">int</span> vury=0;
+<a name="l00146"></a>00146 
+<a name="l00147"></a>00147    <span class="keywordtype">int</span> onp=0;
+<a name="l00148"></a>00148    <span class="keywordtype">int</span> j=0;
+<a name="l00149"></a>00149    cpl_image* j_img=NULL;
+<a name="l00150"></a>00150    cpl_image* m_img=NULL;
+<a name="l00151"></a>00151    cpl_table* qclog_tbl=NULL;
+<a name="l00152"></a>00152    cpl_image* ill_cor=NULL;
+<a name="l00153"></a>00153    cpl_frame* frame=NULL;
+<a name="l00154"></a>00154    cpl_frameset* stk=NULL;
+<a name="l00155"></a>00155    cpl_parameter* p=NULL;
+<a name="l00156"></a>00156    <span class="keywordtype">int</span> mosaic_max_size=0;
+<a name="l00157"></a>00157    <span class="keywordtype">double</span> barycor=0;
+<a name="l00158"></a>00158    <span class="keywordtype">double</span> helicor=0;
+<a name="l00159"></a>00159    cpl_table* qclog=NULL;
+<a name="l00160"></a>00160 
+<a name="l00161"></a>00161    check_nomsg(p=cpl_parameterlist_find(config,
+<a name="l00162"></a>00162                                         <span class="stringliteral">"sinfoni.objnod.mosaic_max_size"</span>));
+<a name="l00163"></a>00163    check_nomsg(mosaic_max_size=cpl_parameter_get_int(p));
+<a name="l00164"></a>00164    check_nomsg(p=cpl_parameterlist_find(config,<span class="stringliteral">"sinfoni.product.density"</span>));
+<a name="l00165"></a>00165    check_nomsg(pdensity=cpl_parameter_get_int(p));
+<a name="l00166"></a>00166 
+<a name="l00167"></a>00167    <span class="keywordflow">if</span> (strcmp(procatg,PRO_COADD_STD) == 0) {
+<a name="l00168"></a>00168       strcpy(pro_mjit,PRO_MASK_COADD_STD);
+<a name="l00169"></a>00169       strcpy(pro_obs,PRO_OBS_STD);
+<a name="l00170"></a>00170       strcpy(pro_med,PRO_MED_COADD_STD);
+<a name="l00171"></a>00171 
+<a name="l00172"></a>00172    } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(procatg,PRO_COADD_PSF) == 0) {
+<a name="l00173"></a>00173       strcpy(pro_mjit,PRO_MASK_COADD_PSF);
+<a name="l00174"></a>00174       strcpy(pro_obs,PRO_OBS_PSF);
+<a name="l00175"></a>00175       strcpy(pro_med,PRO_MED_COADD_PSF);
+<a name="l00176"></a>00176    } <span class="keywordflow">else</span> {
+<a name="l00177"></a>00177       strcpy(pro_mjit,PRO_MASK_COADD_OBJ);
+<a name="l00178"></a>00178       strcpy(pro_obs,PRO_OBS_OBJ);
+<a name="l00179"></a>00179       strcpy(pro_med,PRO_MED_COADD_OBJ);
+<a name="l00180"></a>00180    }
+<a name="l00181"></a>00181 
+<a name="l00182"></a>00182    <span class="comment">/*----parse input data and parameters to set cube_config cfg---*/</span>
+<a name="l00183"></a>00183    check_nomsg(stk = cpl_frameset_new());
+<a name="l00184"></a>00184 
+<a name="l00185"></a>00185    cknull(cfg = sinfo_parse_cpl_input_objnod(config,sof,&stk),
+<a name="l00186"></a>00186           <span class="stringliteral">"Error setting parameter configuration"</span>);
+<a name="l00187"></a>00187 
+<a name="l00188"></a>00188    ck0(sinfo_check_input_data(cfg),<span class="stringliteral">"error checking input"</span>);
+<a name="l00189"></a>00189 
+<a name="l00190"></a>00190    <span class="keywordflow">if</span> ( cfg->jitterind == 1 )
+<a name="l00191"></a>00191    {
+<a name="l00192"></a>00192       cknull(times = (<span class="keywordtype">double</span>*) cpl_calloc (cfg->nframes, sizeof (<span class="keywordtype">double</span>)),
+<a name="l00193"></a>00193              <span class="stringliteral">" could not allocate memory!"</span>) ;
+<a name="l00194"></a>00194 
+<a name="l00195"></a>00195       cknull(offsetx = (<span class="keywordtype">float</span>*) cpl_calloc (cfg->nframes, <span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)),
+<a name="l00196"></a>00196              <span class="stringliteral">" could not allocate memory!"</span>) ;
+<a name="l00197"></a>00197 
+<a name="l00198"></a>00198       cknull(offsety = (<span class="keywordtype">float</span>*) cpl_calloc (cfg->nframes, <span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)),
+<a name="l00199"></a>00199              <span class="stringliteral">" could not allocate memory!"</span>) ;
+<a name="l00200"></a>00200    }
+<a name="l00201"></a>00201 
+<a name="l00202"></a>00202    <span class="keywordflow">if</span> (cfg->jitterind == 0)
+<a name="l00203"></a>00203    {
+<a name="l00204"></a>00204       <span class="keywordflow">if</span> ( NULL != (partname = strtok(cfg->outName, <span class="stringliteral">"."</span>)))
+<a name="l00205"></a>00205       {
+<a name="l00206"></a>00206          partname2 = strtok (NULL, <span class="stringliteral">"."</span>) ;
+<a name="l00207"></a>00207          partind = 1 ;
+<a name="l00208"></a>00208       }
+<a name="l00209"></a>00209    }
+<a name="l00210"></a>00210 
+<a name="l00211"></a>00211    ck0(sinfo_auto_size_cube5(cfg,&ref_offx,&ref_offy,
+<a name="l00212"></a>00212                              &offx_min,&offy_min,
+<a name="l00213"></a>00213                              &offx_max,&offy_max),
+<a name="l00214"></a>00214        <span class="stringliteral">"Error resizing cube"</span>);
+<a name="l00215"></a>00215 
+<a name="l00216"></a>00216    <span class="keywordflow">if</span>(NULL != cpl_frameset_find(sof,PRO_ILL_COR)) {
+<a name="l00217"></a>00217       frame = cpl_frameset_find(sof,PRO_ILL_COR);
+<a name="l00218"></a>00218       ill_cor=cpl_image_load(cpl_frame_get_filename(frame),CPL_TYPE_FLOAT,0,0);
+<a name="l00219"></a>00219    } <span class="keywordflow">else</span> {
+<a name="l00220"></a>00220       sinfo_msg(<span class="stringliteral">"Illumination correction image not provided"</span>);
+<a name="l00221"></a>00221       cpl_error_reset();
+<a name="l00222"></a>00222    }
+<a name="l00223"></a>00223 
+<a name="l00224"></a>00224    <span class="keywordflow">for</span> ( n = 0 ; n < cfg->nframes ; n++ )
+<a name="l00225"></a>00225    {
+<a name="l00226"></a>00226 
+<a name="l00227"></a>00227       <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"Read FITS information"</span>);
+<a name="l00228"></a>00228       name = cfg->framelist[n] ;
+<a name="l00229"></a>00229       <span class="keywordflow">if</span> (n == 0)
+<a name="l00230"></a>00230       {
+<a name="l00231"></a>00231          strcpy (name_jitter, name) ;
+<a name="l00232"></a>00232       }
+<a name="l00233"></a>00233       <span class="keywordflow">if</span>( sinfo_is_fits_file(name) != 1) {
+<a name="l00234"></a>00234          <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Input file %s is not FITS"</span>,name);
+<a name="l00235"></a>00235          <span class="keywordflow">goto</span> cleanup;
+<a name="l00236"></a>00236       }
+<a name="l00237"></a>00237 
+<a name="l00238"></a>00238 
+<a name="l00239"></a>00239       <span class="comment">/* get some header values and compute the CD-sinfo_matrix */</span>
+<a name="l00240"></a>00240       plist=cpl_propertylist_load(name,0);
+<a name="l00241"></a>00241 
+<a name="l00242"></a>00242       <span class="keywordflow">if</span> (sinfo_propertylist_has(plist, KEY_NAME_MJD_OBS)) {
+<a name="l00243"></a>00243          mjd_obs=cpl_propertylist_get_double(plist, KEY_NAME_MJD_OBS);
+<a name="l00244"></a>00244       } <span class="keywordflow">else</span> {
+<a name="l00245"></a>00245          <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"keyword %s does not exist"</span>,KEY_NAME_MJD_OBS);
+<a name="l00246"></a>00246          cpl_propertylist_delete(plist) ;
+<a name="l00247"></a>00247          <span class="keywordflow">return</span> -1;
+<a name="l00248"></a>00248       }
+<a name="l00249"></a>00249 
+<a name="l00250"></a>00250 
+<a name="l00251"></a>00251       pixelscale = sinfo_pfits_get_pixscale(plist) /2;
+<a name="l00252"></a>00252       angle = sinfo_pfits_get_posangle(plist) ;
+<a name="l00253"></a>00253       <span class="comment">/* in PUPIL data there is not posangle info: we reset the error */</span>
+<a name="l00254"></a>00254       <span class="keywordflow">if</span>(cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l00255"></a>00255          cpl_error_reset();
+<a name="l00256"></a>00256       }
+<a name="l00257"></a>00257 
+<a name="l00258"></a>00258       sinfo_free_propertylist(&plist);
+<a name="l00259"></a>00259       <span class="comment">// The following 5 lines are not really used here!</span>
+<a name="l00260"></a>00260       radangle = angle * PI_NUMB / 180. ;
+<a name="l00261"></a>00261       cd1_1 = cos(radangle) ;
+<a name="l00262"></a>00262       cd1_2 = sin(radangle) ;
+<a name="l00263"></a>00263       cd2_1 = -sin(radangle) ;
+<a name="l00264"></a>00264       cd2_2 = cos(radangle) ;
+<a name="l00265"></a>00265 
+<a name="l00266"></a>00266       <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"frame no.: %d, name: %s\n"</span>, n, name) ;
+<a name="l00267"></a>00267       cknull(im = cpl_image_load(name,CPL_TYPE_FLOAT,0,0),
+<a name="l00268"></a>00268              <span class="stringliteral">" could not load frame %s!"</span>,name) ;
+<a name="l00269"></a>00269 
+<a name="l00270"></a>00270       <span class="keywordflow">if</span> (cfg->jitterind == 1)
+<a name="l00271"></a>00271       {
+<a name="l00272"></a>00272          exptime = sinfo_pfits_get_ditndit(name) ;
+<a name="l00273"></a>00273 
+<a name="l00274"></a>00274          <span class="keywordflow">if</span> (exptime == FLAG)
+<a name="l00275"></a>00275          {
+<a name="l00276"></a>00276             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"could not read fits header keyword exptime!"</span>);
+<a name="l00277"></a>00277             <span class="keywordflow">goto</span> cleanup;
+<a name="l00278"></a>00278          }
+<a name="l00279"></a>00279          times[n] = exptime ;
+<a name="l00280"></a>00280 
+<a name="l00281"></a>00281          ck0(sinfo_new_assign_offset(n,name,offsetx,offsety,
+<a name="l00282"></a>00282                                      ref_offx,ref_offy),
+<a name="l00283"></a>00283              <span class="stringliteral">"Error assigning offsets"</span>);
+<a name="l00284"></a>00284 
+<a name="l00285"></a>00285       }
+<a name="l00286"></a>00286       sinfo_free_image(&im);
+<a name="l00287"></a>00287 
+<a name="l00288"></a>00288    } <span class="comment">/* end loop over n (nframes) */</span>
+<a name="l00289"></a>00289 
+<a name="l00290"></a>00290 
+<a name="l00291"></a>00291    <span class="comment">/* leak free */</span>
+<a name="l00292"></a>00292    <span class="keywordflow">if</span>(cfg->jitterind == 0) {
+<a name="l00293"></a>00293       <span class="keywordflow">goto</span> exit;
+<a name="l00294"></a>00294    }
+<a name="l00295"></a>00295 
+<a name="l00296"></a>00296    <span class="comment">/* Here in case of autojitter we estimate the sky */</span>
+<a name="l00297"></a>00297    <span class="keywordflow">if</span>( (cfg->size_x*cfg->size_y*cfg->nframes) > (100*mosaic_max_size) ) {
+<a name="l00298"></a>00298       <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"Coadd cube size:%d,%d. N frames: %d"</span>,
+<a name="l00299"></a>00299                         cfg->size_x,cfg->size_y,cfg->nframes);
+<a name="l00300"></a>00300       <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"Max allowed should be such "</span>
+<a name="l00301"></a>00301                         <span class="stringliteral">"that sixeX*sixeY*Nframes < 100*%d"</span>,mosaic_max_size);
+<a name="l00302"></a>00302       <span class="keywordflow">goto</span> exit;
+<a name="l00303"></a>00303    }
+<a name="l00304"></a>00304 
+<a name="l00305"></a>00305    <span class="keywordflow">if</span> ( cfg->jitterind == 1 )
+<a name="l00306"></a>00306    {
+<a name="l00307"></a>00307       check_nomsg(p = cpl_parameterlist_find(config, <span class="stringliteral">"sinfoni.objnod.vllx"</span>));
+<a name="l00308"></a>00308       check_nomsg(vllx = cpl_parameter_get_int(p));
+<a name="l00309"></a>00309       check_nomsg(p = cpl_parameterlist_find(config, <span class="stringliteral">"sinfoni.objnod.vlly"</span>));
+<a name="l00310"></a>00310       check_nomsg(vlly = cpl_parameter_get_int(p));
+<a name="l00311"></a>00311       check_nomsg(p = cpl_parameterlist_find(config, <span class="stringliteral">"sinfoni.objnod.vurx"</span>));
+<a name="l00312"></a>00312       check_nomsg(vurx = cpl_parameter_get_int(p));
+<a name="l00313"></a>00313       check_nomsg(p = cpl_parameterlist_find(config, <span class="stringliteral">"sinfoni.objnod.vury"</span>));
+<a name="l00314"></a>00314       check_nomsg(vury = cpl_parameter_get_int(p));
+<a name="l00315"></a>00315       cknull(cube_tmp = (cpl_imagelist**) cpl_calloc (cfg->nframes,
+<a name="l00316"></a>00316                                                       sizeof (cpl_imagelist*)),
+<a name="l00317"></a>00317              <span class="stringliteral">"Could not allocate memory for cube_tmp"</span>);
+<a name="l00318"></a>00318 
+<a name="l00319"></a>00319 
+<a name="l00320"></a>00320       cknull(cubeobject = (cpl_imagelist**) cpl_calloc (cfg->nframes,
+<a name="l00321"></a>00321                                                         sizeof (cpl_imagelist*)),
+<a name="l00322"></a>00322              <span class="stringliteral">"Could not allocate memory for cubeobject"</span>);
+<a name="l00323"></a>00323       check_nomsg(p=cpl_parameterlist_find(config,
+<a name="l00324"></a>00324                                            <span class="stringliteral">"sinfoni.objnod.sky_cor"</span>));
+<a name="l00325"></a>00325       check_nomsg(sky_cor=cpl_parameter_get_bool(p));
+<a name="l00326"></a>00326 
+<a name="l00327"></a>00327 
+<a name="l00328"></a>00328       <span class="keywordflow">for</span> ( n = 0 ; n < cfg->nframes ; n++ ) {
+<a name="l00329"></a>00329          <span class="keywordflow">if</span>(sky_cor == 1 && (pdensity == 1 || pdensity == 3) &&
+<a name="l00330"></a>00330             strcmp(cfg->sky_dist,<span class="stringliteral">"no_sky"</span>)!=0) {
+<a name="l00331"></a>00331             sinfo_msg(<span class="stringliteral">"load sky corrected cubes"</span>);
+<a name="l00332"></a>00332 
+<a name="l00333"></a>00333             snprintf(file_name,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%2.2d%s"</span>,<span class="stringliteral">"out_cube_obj_cor"</span>,
+<a name="l00334"></a>00334                      n,<span class="stringliteral">".fits"</span>);
+<a name="l00335"></a>00335 
+<a name="l00336"></a>00336          } <span class="keywordflow">else</span> {
+<a name="l00337"></a>00337             snprintf(file_name,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%2.2d%s"</span>,<span class="stringliteral">"out_cube_obj"</span>,n,
+<a name="l00338"></a>00338                      <span class="stringliteral">".fits"</span>);
+<a name="l00339"></a>00339          }
+<a name="l00340"></a>00340          check_nomsg(cube_tmp[n] = cpl_imagelist_load(file_name,
+<a name="l00341"></a>00341                                                       CPL_TYPE_FLOAT,0));
+<a name="l00342"></a>00342 
+<a name="l00343"></a>00343 
+<a name="l00344"></a>00344          check_nomsg(cubeobject[n] = sinfo_new_cube_getvig(
+<a name="l00345"></a>00345                              cube_tmp[n],
+<a name="l00346"></a>00346                              1+vllx,1+vlly,
+<a name="l00347"></a>00347                              64 - vurx, 64 - vury));
+<a name="l00348"></a>00348          check_nomsg(sinfo_free_imagelist(&cube_tmp[n]));
+<a name="l00349"></a>00349 
+<a name="l00350"></a>00350       }
+<a name="l00351"></a>00351       sinfo_free_array_imagelist(&cube_tmp);
+<a name="l00352"></a>00352 
+<a name="l00353"></a>00353 
+<a name="l00354"></a>00354    }
+<a name="l00355"></a>00355 
+<a name="l00356"></a>00356 
+<a name="l00357"></a>00357    <span class="comment">/*</span>
+<a name="l00358"></a>00358 <span class="comment">     ---------------------------------------------------------------------</span>
+<a name="l00359"></a>00359 <span class="comment">     ------------------------JITTERING------------------------------------</span>
+<a name="l00360"></a>00360 <span class="comment">     ---------------------------------------------------------------------</span>
+<a name="l00361"></a>00361 <span class="comment">   */</span>
+<a name="l00362"></a>00362 
+<a name="l00363"></a>00363    <span class="keywordflow">if</span> (cfg->jitterind == 1)
+<a name="l00364"></a>00364    {
+<a name="l00365"></a>00365       sinfo_msg(<span class="stringliteral">"Jittering..."</span>);
+<a name="l00366"></a>00366 
+<a name="l00367"></a>00367       sinfo_msg(<span class="stringliteral">"Coadded cube size. x: %d y: %d"</span>,
+<a name="l00368"></a>00368                 cfg->size_x,cfg->size_y);
+<a name="l00369"></a>00369       check_nomsg(jittercube = cpl_imagelist_new()) ;
+<a name="l00370"></a>00370 
+<a name="l00371"></a>00371 
+<a name="l00372"></a>00372       <span class="comment">/*</span>
+<a name="l00373"></a>00373 <span class="comment">         ---------------------------------------------------------------------</span>
+<a name="l00374"></a>00374 <span class="comment">         -------------------THOMAS ALGORITHM----------------------------------</span>
+<a name="l00375"></a>00375 <span class="comment">         ---------------------------------------------------------------------</span>
+<a name="l00376"></a>00376 <span class="comment">      */</span>
+<a name="l00377"></a>00377 
+<a name="l00378"></a>00378       check_nomsg(p=cpl_parameterlist_find(config,
+<a name="l00379"></a>00379                                            <span class="stringliteral">"sinfoni.objnod.scales_sky"</span>));
+<a name="l00380"></a>00380       check_nomsg(scales_sky=cpl_parameter_get_bool(p));
+<a name="l00381"></a>00381       check_nomsg(p=cpl_parameterlist_find(config,<span class="stringliteral">"sinfoni.objnod.ks_clip"</span>));
+<a name="l00382"></a>00382       check_nomsg(ks_clip = cpl_parameter_get_bool(p));
+<a name="l00383"></a>00383       check_nomsg(p=cpl_parameterlist_find(config,<span class="stringliteral">"sinfoni.objnod.kappa"</span>));
+<a name="l00384"></a>00384       check_nomsg(kappa = cpl_parameter_get_double(p));
+<a name="l00385"></a>00385 
+<a name="l00386"></a>00386 
+<a name="l00387"></a>00387       <span class="keywordflow">if</span>(scales_sky == 1) {
+<a name="l00388"></a>00388          sinfo_msg(<span class="stringliteral">"Subtract spatial sinfo_median to each cube plane"</span>);
+<a name="l00389"></a>00389          <span class="keywordflow">for</span>(n=0;n<cfg->nframes;n++) {
+<a name="l00390"></a>00390             sinfo_msg(<span class="stringliteral">"Process cube %d\n"</span>,n);
+<a name="l00391"></a>00391             sinfo_new_sinfoni_correct_median_it(&(cubeobject[n]));
+<a name="l00392"></a>00392          }
+<a name="l00393"></a>00393       }
+<a name="l00394"></a>00394 
+<a name="l00395"></a>00395 
+<a name="l00396"></a>00396       <span class="comment">/* AMO CHECK */</span>
+<a name="l00397"></a>00397 
+<a name="l00398"></a>00398       cknull(maskcube=cpl_imagelist_new(),<span class="stringliteral">"could not allocate cube!"</span>);
+<a name="l00399"></a>00399 
+<a name="l00400"></a>00400       <span class="comment">/* Illumination correction */</span>
+<a name="l00401"></a>00401       <span class="keywordflow">if</span>(ill_cor != NULL) {
+<a name="l00402"></a>00402          <span class="keywordflow">for</span>(n=0;n<cfg->nframes;n++) {
+<a name="l00403"></a>00403             cpl_imagelist_divide_image(cubeobject[n],ill_cor);
+<a name="l00404"></a>00404          }
+<a name="l00405"></a>00405       }
+<a name="l00406"></a>00406       sinfo_free_image(&ill_cor);
+<a name="l00407"></a>00407 
+<a name="l00408"></a>00408       sinfo_msg(<span class="stringliteral">"Combine jittered cubes"</span>);
+<a name="l00409"></a>00409 
+<a name="l00410"></a>00410 
+<a name="l00411"></a>00411       <span class="keywordflow">if</span>(ks_clip == 1) {
+<a name="l00412"></a>00412          sinfo_msg(<span class="stringliteral">"Cube coaddition with kappa-sigma"</span>);
+<a name="l00413"></a>00413       }
+<a name="l00414"></a>00414       check_nomsg(onp=cpl_imagelist_get_size(cubeobject[0]));
+<a name="l00415"></a>00415       <span class="keywordflow">for</span>(z=0;z<onp;z+=z_stp) {
+<a name="l00416"></a>00416          z_siz=(z_stp < (onp-z)) ? z_stp : (onp-z);
+<a name="l00417"></a>00417          z_min=z;
+<a name="l00418"></a>00418          z_max=z_min+z_siz;
+<a name="l00419"></a>00419          sinfo_msg(<span class="stringliteral">"Coadding cubes: range [%4.4d,%4.4d) of 0-%d\n"</span>,
+<a name="l00420"></a>00420                    z_min,z_max,onp);
+<a name="l00421"></a>00421 
+<a name="l00422"></a>00422          <span class="keywordflow">for</span>(j=z_min;j<z_max;j++) {
+<a name="l00423"></a>00423             check_nomsg(j_img=cpl_image_new(cfg->size_x,
+<a name="l00424"></a>00424                                             cfg->size_y,CPL_TYPE_FLOAT));
+<a name="l00425"></a>00425             check_nomsg(cpl_imagelist_set(jittercube,j_img,j));
+<a name="l00426"></a>00426             check_nomsg(m_img = cpl_image_new(cfg->size_x,
+<a name="l00427"></a>00427                                               cfg->size_y,CPL_TYPE_FLOAT));
+<a name="l00428"></a>00428             check_nomsg(cpl_imagelist_set(maskcube,m_img,j));
+<a name="l00429"></a>00429          }
+<a name="l00430"></a>00430          <span class="keywordflow">if</span>(ks_clip == 1) {
+<a name="l00431"></a>00431             sinfo_new_combine_jittered_cubes_thomas_range(cubeobject,
+<a name="l00432"></a>00432                                                           jittercube,
+<a name="l00433"></a>00433                                                           maskcube,
+<a name="l00434"></a>00434                                                           cfg->nframes,
+<a name="l00435"></a>00435                                                           offsetx,offsety,
+<a name="l00436"></a>00436                                                           times,
+<a name="l00437"></a>00437                                                           cfg->kernel_type,
+<a name="l00438"></a>00438                                                           z_min,
+<a name="l00439"></a>00439                                                           z_max,
+<a name="l00440"></a>00440                                                           kappa);
+<a name="l00441"></a>00441 
+<a name="l00442"></a>00442          } <span class="keywordflow">else</span> {
+<a name="l00443"></a>00443             sinfo_new_combine_jittered_cubes_range(cubeobject,
+<a name="l00444"></a>00444                                                    jittercube,
+<a name="l00445"></a>00445                                                    maskcube,
+<a name="l00446"></a>00446                                                    cfg->nframes,
+<a name="l00447"></a>00447                                                    offsetx,
+<a name="l00448"></a>00448                                                    offsety,
+<a name="l00449"></a>00449                                                    times,
+<a name="l00450"></a>00450                                                    cfg->kernel_type,
+<a name="l00451"></a>00451                                                    z_min,
+<a name="l00452"></a>00452                                                    z_max) ;
+<a name="l00453"></a>00453          }
+<a name="l00454"></a>00454       }
+<a name="l00455"></a>00455       sinfo_new_convert_0_to_ZERO_for_cubes(jittercube) ;
+<a name="l00456"></a>00456 
+<a name="l00457"></a>00457       <span class="keywordflow">if</span> (jittercube == NULL)
+<a name="l00458"></a>00458       {
+<a name="l00459"></a>00459          <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" could not allocate new data cube!"</span>) ;
+<a name="l00460"></a>00460          <span class="keywordflow">goto</span> cleanup;
+<a name="l00461"></a>00461       }
+<a name="l00462"></a>00462 
+<a name="l00463"></a>00463       <span class="keywordflow">if</span> (maskcube == NULL)
+<a name="l00464"></a>00464       {
+<a name="l00465"></a>00465          <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" could not merge the jittered data cubes\n"</span>) ;
+<a name="l00466"></a>00466          <span class="keywordflow">goto</span> cleanup;
+<a name="l00467"></a>00467       }
+<a name="l00468"></a>00468 
+<a name="l00469"></a>00469       <span class="keywordflow">for</span> ( i = 0 ; i <cfg->nframes  ; i++ ) {
+<a name="l00470"></a>00470          sinfo_free_imagelist(&cubeobject[i]);
+<a name="l00471"></a>00471          <span class="comment">//sinfo_msg("offx[%d]=%f,offy[%d]=%f",i,offsetx[i],i,offsety[i]);</span>
+<a name="l00472"></a>00472       }
+<a name="l00473"></a>00473       sinfo_free_array_imagelist(&cubeobject);
+<a name="l00474"></a>00474 
+<a name="l00475"></a>00475       <span class="comment">//Old setting</span>
+<a name="l00476"></a>00476       <span class="comment">//newcenter_x = cfg->size_x / 2. + 0.5 ;</span>
+<a name="l00477"></a>00477       <span class="comment">//newcenter_y = cfg->size_y / 2. + 0.5 ;</span>
+<a name="l00478"></a>00478 
+<a name="l00479"></a>00479 
+<a name="l00480"></a>00480       <span class="comment">/* new setting */</span>
+<a name="l00481"></a>00481       <span class="comment">/*</span>
+<a name="l00482"></a>00482 <span class="comment">        sinfo_msg("offx_min=%f,offy_min=%f",offx_min,offy_min);</span>
+<a name="l00483"></a>00483 <span class="comment">        sinfo_msg("offx_max=%f,offy_max=%f",offx_max,offy_max);</span>
+<a name="l00484"></a>00484 <span class="comment">        sinfo_msg("ref_offx=%f,ref_offy=%f",ref_offx,ref_offy);</span>
+<a name="l00485"></a>00485 <span class="comment"></span>
+<a name="l00486"></a>00486 <span class="comment">        newcenter_x=2*floor(fabs(offx_min)+0.5)+32+8;</span>
+<a name="l00487"></a>00487 <span class="comment">        newcenter_y=-2*floor(fabs(offy_max)+0.5)+32-2;</span>
+<a name="l00488"></a>00488 <span class="comment"></span>
+<a name="l00489"></a>00489 <span class="comment"></span>
+<a name="l00490"></a>00490 <span class="comment">        newcenter_x=cfg->size_x / 2. -offsetx[0];</span>
+<a name="l00491"></a>00491 <span class="comment">        newcenter_y=cfg->size_y / 2. -offsety[0];</span>
+<a name="l00492"></a>00492 <span class="comment">      */</span>
+<a name="l00493"></a>00493 
+<a name="l00494"></a>00494 
+<a name="l00495"></a>00495 
+<a name="l00496"></a>00496       <span class="keywordflow">if</span> (mjd_obs > 53825. ) {
+<a name="l00497"></a>00497          <span class="comment">/* April 1st 2006 */</span>
+<a name="l00498"></a>00498          newcenter_x=cfg->size_x / 2. +2*ref_offx;
+<a name="l00499"></a>00499          newcenter_y=cfg->size_y / 2. +2*ref_offy;
+<a name="l00500"></a>00500       } <span class="keywordflow">else</span> <span class="keywordflow">if</span> ((mjd_obs > 53421.58210082 ) && (mjd_obs <= 53825.)){
+<a name="l00501"></a>00501          <span class="comment">/* after detector's upgrade */</span>
+<a name="l00502"></a>00502          newcenter_x=cfg->size_x / 2. -2*ref_offx;
+<a name="l00503"></a>00503          newcenter_y=cfg->size_y / 2. +2*ref_offy;
+<a name="l00504"></a>00504       } <span class="keywordflow">else</span> {
+<a name="l00505"></a>00505          <span class="comment">/* before detector's upgrade */</span>
+<a name="l00506"></a>00506          newcenter_x=cfg->size_x / 2. +2*ref_offx;
+<a name="l00507"></a>00507          newcenter_y=cfg->size_y / 2. -2*ref_offy;
+<a name="l00508"></a>00508       }
+<a name="l00509"></a>00509 
+<a name="l00510"></a>00510 
+<a name="l00511"></a>00511       <span class="comment">//sinfo_msg("CRPIX=%f,%f", newcenter_x, newcenter_y);</span>
+<a name="l00512"></a>00512       <span class="comment">//newcenter_x=2*floor(fabs(ref_offx)+0.5);</span>
+<a name="l00513"></a>00513       <span class="comment">//newcenter_y=-2*floor(fabs(ref_offy)+0.5);</span>
+<a name="l00514"></a>00514       <span class="comment">//sinfo_msg_warning("Center image: %f %f",newcenter_x,newcenter_y);</span>
+<a name="l00515"></a>00515       cknull_nomsg(qclog = sinfo_qclog_init());
+<a name="l00516"></a>00516       plist=cpl_propertylist_load(file_name,0);
+<a name="l00517"></a>00517       <span class="keywordflow">if</span>(sinfo_baryvel(plist, &barycor,&helicor) != CPL_ERROR_NONE) {
+<a name="l00518"></a>00518          <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"Could not compute velocity corrections"</span>);
+<a name="l00519"></a>00519          cpl_error_reset();
+<a name="l00520"></a>00520       } <span class="keywordflow">else</span> {
+<a name="l00521"></a>00521 
+<a name="l00522"></a>00522          check_nomsg(sinfo_qclog_add_double(qclog,
+<a name="l00523"></a>00523                                             <span class="stringliteral">"QC VRAD BARYCOR"</span>,
+<a name="l00524"></a>00524                                             barycor,
+<a name="l00525"></a>00525                                             <span class="stringliteral">"Barycentric radial velocity correction "</span>,
+<a name="l00526"></a>00526                                             <span class="stringliteral">"%13.6f"</span>));
+<a name="l00527"></a>00527 
+<a name="l00528"></a>00528          check_nomsg(sinfo_qclog_add_double(qclog,
+<a name="l00529"></a>00529                                             <span class="stringliteral">"QC VRAD HELICOR"</span>,
+<a name="l00530"></a>00530                                             helicor,
+<a name="l00531"></a>00531                                             <span class="stringliteral">"Heliocentric radial velocity correction "</span>,
+<a name="l00532"></a>00532                                             <span class="stringliteral">"%13.6f"</span>));
+<a name="l00533"></a>00533          sinfo_msg(<span class="stringliteral">"Barycor=%g Helicor=%g"</span>,barycor,helicor);
+<a name="l00534"></a>00534 
+<a name="l00535"></a>00535          sinfo_free_propertylist(&plist);
+<a name="l00536"></a>00536 
+<a name="l00537"></a>00537       }
+<a name="l00538"></a>00538 
+<a name="l00539"></a>00539       ck0(sinfo_pro_save_ims(jittercube,sof,sof,cfg->outName,
+<a name="l00540"></a>00540                              procatg,qclog,plugin_id,config),
+<a name="l00541"></a>00541           <span class="stringliteral">"cannot save cube %s"</span>, cfg->outName);
+<a name="l00542"></a>00542 
+<a name="l00543"></a>00543       sinfo_free_table(&qclog);
+<a name="l00544"></a>00544 
+<a name="l00545"></a>00545       <span class="comment">/* we need to set again the following 3 */</span>
+<a name="l00546"></a>00546       plist=cpl_propertylist_load(file_name,0);
+<a name="l00547"></a>00547       dis=sinfo_pfits_get_cdelt3(plist);
+<a name="l00548"></a>00548       centralLambda=sinfo_pfits_get_crval3(plist);
+<a name="l00549"></a>00549       centralpix=sinfo_pfits_get_crpix3(plist);
+<a name="l00550"></a>00550       sinfo_free_propertylist(&plist);
+<a name="l00551"></a>00551       sinfo_new_set_wcs_cube(jittercube, cfg->outName,
+<a name="l00552"></a>00552                              centralLambda, dis,
+<a name="l00553"></a>00553                              centralpix, newcenter_x, newcenter_y);
+<a name="l00554"></a>00554 
+<a name="l00555"></a>00555       cknull(jitter_image = sinfo_new_median_cube(jittercube),
+<a name="l00556"></a>00556              <span class="stringliteral">" could not do sinfo_medianCube()"</span>);
+<a name="l00557"></a>00557       cknull_nomsg(qclog = sinfo_qclog_init());
+<a name="l00558"></a>00558       update_bad_pixel_map(jitter_image);
+<a name="l00559"></a>00559       check_nomsg(sinfo_qclog_add_double(qclog,
+<a name="l00560"></a>00560                                                <span class="stringliteral">"QC FRMDIF MEANSTD"</span>,
+<a name="l00561"></a>00561                                                cpl_image_get_mean(jitter_image),
+<a name="l00562"></a>00562                                                <span class="stringliteral">"mean of the collapesd cube"</span>,
+<a name="l00563"></a>00563                                                <span class="stringliteral">"%13.6f"</span>));
+<a name="l00564"></a>00564       check_nomsg(sinfo_qclog_add_double(qclog,
+<a name="l00565"></a>00565                                                <span class="stringliteral">"QC FRMDIF STDEV"</span>,
+<a name="l00566"></a>00566                                                cpl_image_get_stdev(jitter_image),
+<a name="l00567"></a>00567                                                <span class="stringliteral">"standard deviation of the collapesd cube"</span>,
+<a name="l00568"></a>00568                                                <span class="stringliteral">"%13.6f"</span>));
+<a name="l00569"></a>00569       ck0(sinfo_pro_save_ima(jitter_image,sof,sof,cfg->med_cube_name,
+<a name="l00570"></a>00570                              pro_med,qclog,plugin_id,config),
+<a name="l00571"></a>00571           <span class="stringliteral">"cannot save ima %s"</span>, cfg->outName);
+<a name="l00572"></a>00572       sinfo_free_table(&qclog);
+<a name="l00573"></a>00573 
+<a name="l00574"></a>00574       sinfo_new_set_wcs_image(jitter_image, cfg->med_cube_name,
+<a name="l00575"></a>00575                               newcenter_x,newcenter_y);
+<a name="l00576"></a>00576 
+<a name="l00577"></a>00577       sinfo_free_image(&jitter_image);
+<a name="l00578"></a>00578 
+<a name="l00579"></a>00579       ck0(sinfo_pro_save_ims(maskcube,sof,sof,cfg->maskname,
+<a name="l00580"></a>00580                              pro_mjit,NULL,plugin_id,config),
+<a name="l00581"></a>00581           <span class="stringliteral">"cannot save cube %s"</span>, cfg->maskname);
+<a name="l00582"></a>00582 
+<a name="l00583"></a>00583       sinfo_new_set_wcs_cube(maskcube, cfg->maskname,
+<a name="l00584"></a>00584                              centralLambda, dis, centralpix,
+<a name="l00585"></a>00585                              newcenter_x, newcenter_y);
+<a name="l00586"></a>00586 
+<a name="l00587"></a>00587       sinfo_free_double(&times) ;
+<a name="l00588"></a>00588       sinfo_free_float(&offsetx) ;
+<a name="l00589"></a>00589       sinfo_free_float(&offsety) ;
+<a name="l00590"></a>00590       sinfo_free_imagelist(&maskcube) ;
+<a name="l00591"></a>00591       sinfo_free_imagelist(&jittercube) ;
+<a name="l00592"></a>00592 
+<a name="l00593"></a>00593    } <span class="comment">/* end of jittering */</span>
+<a name="l00594"></a>00594 
+<a name="l00595"></a>00595   exit:
+<a name="l00596"></a>00596 
+<a name="l00597"></a>00597    <span class="comment">/* free memory */</span>
+<a name="l00598"></a>00598    sinfo_objnod_free(&cfg);
+<a name="l00599"></a>00599    sinfo_free_frameset(&stk);
+<a name="l00600"></a>00600    <span class="keywordflow">return</span> 0;
+<a name="l00601"></a>00601 
+<a name="l00602"></a>00602   cleanup:
+<a name="l00603"></a>00603 
+<a name="l00604"></a>00604    sinfo_free_image(&jitter_image);
+<a name="l00605"></a>00605    sinfo_free_imagelist(&jittercube) ;
+<a name="l00606"></a>00606    sinfo_free_imagelist(&maskcube) ;
+<a name="l00607"></a>00607    sinfo_free_table(&qclog);
+<a name="l00608"></a>00608 
+<a name="l00609"></a>00609    <span class="keywordflow">if</span>(cfg != NULL) {
+<a name="l00610"></a>00610       <span class="keywordflow">if</span>(cube_tmp != NULL) {
+<a name="l00611"></a>00611          <span class="keywordflow">for</span> ( n = 0 ; n < cfg->nframes ; n++ ) {
+<a name="l00612"></a>00612             sinfo_free_imagelist(&(cube_tmp[n]));
+<a name="l00613"></a>00613          }
+<a name="l00614"></a>00614          sinfo_free_array_imagelist(&cube_tmp);
+<a name="l00615"></a>00615       }
+<a name="l00616"></a>00616       <span class="keywordflow">if</span>(cubeobject != NULL) {
+<a name="l00617"></a>00617          <span class="keywordflow">for</span> ( n = 0 ; n < cfg->nframes ; n++ ) {
+<a name="l00618"></a>00618             sinfo_free_imagelist(&(cubeobject[n]));
+<a name="l00619"></a>00619          }
+<a name="l00620"></a>00620          sinfo_free_array_imagelist(&cubeobject);
+<a name="l00621"></a>00621       }
+<a name="l00622"></a>00622 
+<a name="l00623"></a>00623    }
+<a name="l00624"></a>00624    sinfo_free_table(&qclog_tbl);
+<a name="l00625"></a>00625    sinfo_free_image(&im);
+<a name="l00626"></a>00626    sinfo_free_image(&ill_cor);
+<a name="l00627"></a>00627    sinfo_free_float(&offsety);
+<a name="l00628"></a>00628    sinfo_free_float(&offsetx);
+<a name="l00629"></a>00629    sinfo_free_double(&times);
+<a name="l00630"></a>00630    sinfo_objnod_free(&cfg);
+<a name="l00631"></a>00631    sinfo_free_frameset(&stk);
+<a name="l00632"></a>00632 
+<a name="l00633"></a>00633    <span class="keywordflow">if</span> (cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l00634"></a>00634       sinfo_check_rec_status(0);
+<a name="l00635"></a>00635    }
+<a name="l00636"></a>00636    <span class="keywordflow">return</span> -1;
+<a name="l00637"></a>00637 
+<a name="l00638"></a>00638 
+<a name="l00639"></a>00639 
+<a name="l00640"></a>00640 }
+<a name="l00641"></a>00641 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__new__cubes__coadd_8h_source.html b/html/sinfo__new__cubes__coadd_8h_source.html
new file mode 100644
index 0000000..214ea8a
--- /dev/null
+++ b/html/sinfo__new__cubes__coadd_8h_source.html
@@ -0,0 +1,86 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_new_cubes_coadd.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_new_cubes_coadd.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#ifndef SINFO_NEW_CUBES_COADD_H</span>
+<a name="l00002"></a>00002 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_NEW_CUBES_COADD_H</span>
+<a name="l00003"></a>00003 <span class="preprocessor"></span><span class="comment">/*</span>
+<a name="l00004"></a>00004 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00005"></a>00005 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00006"></a>00006 <span class="comment"> *</span>
+<a name="l00007"></a>00007 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00008"></a>00008 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00009"></a>00009 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00010"></a>00010 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00011"></a>00011 <span class="comment"> *</span>
+<a name="l00012"></a>00012 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00013"></a>00013 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00014"></a>00014 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00015"></a>00015 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00016"></a>00016 <span class="comment"> *</span>
+<a name="l00017"></a>00017 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00018"></a>00018 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00019"></a>00019 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00020"></a>00020 <span class="comment"> */</span>
+<a name="l00021"></a>00021 <span class="comment">/*******************************************************************************</span>
+<a name="l00022"></a>00022 <span class="comment">* E.S.O. - VLT project</span>
+<a name="l00023"></a>00023 <span class="comment">*</span>
+<a name="l00024"></a>00024 <span class="comment">* "@(#) $Id: sinfo_new_cubes_coadd.h,v 1.10 2007/06/06 07:10:45 amodigli Exp $"</span>
+<a name="l00025"></a>00025 <span class="comment">*</span>
+<a name="l00026"></a>00026 <span class="comment">* who       when      what</span>
+<a name="l00027"></a>00027 <span class="comment">* --------  --------  ----------------------------------------------</span>
+<a name="l00028"></a>00028 <span class="comment">* schreib  06/05/03  created</span>
+<a name="l00029"></a>00029 <span class="comment">*/</span>
+<a name="l00030"></a>00030 
+<a name="l00031"></a>00031 <span class="comment">/************************************************************************</span>
+<a name="l00032"></a>00032 <span class="comment"> * sinfo_new_cubes_coadd.h</span>
+<a name="l00033"></a>00033 <span class="comment"> * routines to create a data cube</span>
+<a name="l00034"></a>00034 <span class="comment"> *----------------------------------------------------------------------</span>
+<a name="l00035"></a>00035 <span class="comment"> */</span>
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="comment">/*</span>
+<a name="l00038"></a>00038 <span class="comment"> * header files</span>
+<a name="l00039"></a>00039 <span class="comment"> */</span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include <math.h></span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include <cpl.h></span>   
+<a name="l00042"></a>00042 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00043"></a>00043 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00044"></a>00044 <span class="comment"> *                        Function ANSI C prototypes</span>
+<a name="l00045"></a>00045 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00046"></a>00046 
+<a name="l00047"></a>00047 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00048"></a>00048 <span class="comment">   @name sinfo_new_cubes_coadd()</span>
+<a name="l00049"></a>00049 <span class="comment">   @param ini_file: file name of according .ini file</span>
+<a name="l00050"></a>00050 <span class="comment">   @param integer (0 if it worked, -1 if it doesn't) </span>
+<a name="l00051"></a>00051 <span class="comment">   @doc this routine does the resampling of an offset-corrected,</span>
+<a name="l00052"></a>00052 <span class="comment">        flatfielded, bad pixel corrected and</span>
+<a name="l00053"></a>00053 <span class="comment">        eventually interleaved data frame. Additionally, an intensity </span>
+<a name="l00054"></a>00054 <span class="comment">    calibration is carried through by using</span>
+<a name="l00055"></a>00055 <span class="comment">        a standard star or a black body measurement. </span>
+<a name="l00056"></a>00056 <span class="comment">    The spectral features of the flatfield halogen lamp are corrected.</span>
+<a name="l00057"></a>00057 <span class="comment">        Afterwards a data cube is created out of the resampled image.</span>
+<a name="l00058"></a>00058 <span class="comment">    It is the users choice to use either</span>
+<a name="l00059"></a>00059 <span class="comment">        the fitted sinfo_edge positions of the slitlets or the distances</span>
+<a name="l00060"></a>00060 <span class="comment">    of the slitlets gained from a north-south-test. </span>
+<a name="l00061"></a>00061 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00062"></a>00062 <span class="keywordtype">int</span> 
+<a name="l00063"></a>00063 sinfo_new_cubes_coadd (<span class="keyword">const</span> <span class="keywordtype">char</span>* plugin_id,
+<a name="l00064"></a>00064                        cpl_parameterlist* config, 
+<a name="l00065"></a>00065                        cpl_frameset* sof, 
+<a name="l00066"></a>00066                        <span class="keyword">const</span> <span class="keywordtype">char</span>* procatg) ;
+<a name="l00067"></a>00067 
+<a name="l00068"></a>00068 
+<a name="l00069"></a>00069 <span class="preprocessor">#endif </span>
+<a name="l00071"></a>00071 <span class="preprocessor"></span><span class="comment">/*--------------------------------------------------------------------------*/</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__new__dark_8c_source.html b/html/sinfo__new__dark_8c_source.html
new file mode 100644
index 0000000..063dfc8
--- /dev/null
+++ b/html/sinfo__new__dark_8c_source.html
@@ -0,0 +1,725 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_new_dark.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_new_dark.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name    :       sinfo_new_dark.c</span>
+<a name="l00022"></a>00022 <span class="comment">   Author       :    A. Modigliani</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on   :    Sep 17, 2003</span>
+<a name="l00024"></a>00024 <span class="comment">   Description  :    Master sinfo_dark creation </span>
+<a name="l00025"></a>00025 <span class="comment"></span>
+<a name="l00026"></a>00026 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00027"></a>00027 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00029"></a>00029 <span class="preprocessor">#endif</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span>
+<a name="l00031"></a>00031 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00032"></a>00032 <span class="comment">                                Includes</span>
+<a name="l00033"></a>00033 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00034"></a>00034 <span class="preprocessor">#include "sinfo_new_dark.h"</span>
+<a name="l00035"></a>00035 <span class="preprocessor">#include "sinfo_utilities.h"</span>
+<a name="l00036"></a>00036 <span class="preprocessor">#include "sinfo_pro_save.h"</span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include "sinfo_dark_ini_by_cpl.h"</span>
+<a name="l00038"></a>00038 <span class="preprocessor">#include "sinfo_dfs.h"</span>
+<a name="l00039"></a>00039 <span class="preprocessor">#include "sinfo_pfits.h"</span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include "sinfo_error.h"</span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include "sinfo_utils_wrappers.h"</span>
+<a name="l00042"></a>00042 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00043"></a>00043 <span class="comment">                                Defines</span>
+<a name="l00044"></a>00044 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00045"></a>00045 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_dark_ron_reduce(cpl_frameset * framelist,
+<a name="l00046"></a>00046                             dark_config* cfg,
+<a name="l00047"></a>00047                             cpl_table* qclog);
+<a name="l00048"></a>00048 
+<a name="l00049"></a>00049 
+<a name="l00050"></a>00050 <span class="keyword">static</span> <span class="keywordtype">int</span> 
+<a name="l00051"></a>00051 sinfo_dark_compare(<span class="keyword">const</span> cpl_frame * frame1, <span class="keyword">const</span> cpl_frame * frame2);
+<a name="l00052"></a>00052 
+<a name="l00062"></a>00062 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00063"></a>00063 <span class="comment">                             Function Definitions</span>
+<a name="l00064"></a>00064 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00065"></a>00065 
+<a name="l00066"></a>00066 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00067"></a>00067 <span class="comment">   @name  sinfo_new_dark()</span>
+<a name="l00068"></a>00068 <span class="comment">   @param  plugin_id recipe id</span>
+<a name="l00069"></a>00069 <span class="comment">   @param  config input parameterlist</span>
+<a name="l00070"></a>00070 <span class="comment">   @param  sof    input set of frames</span>
+<a name="l00071"></a>00071 <span class="comment">   @return integer (0 if it worked, -1 if it doesn't) </span>
+<a name="l00072"></a>00072 <span class="comment">   @doc </span>
+<a name="l00073"></a>00073 <span class="comment">                  1) Sorts frames according to integration time</span>
+<a name="l00074"></a>00074 <span class="comment">                  2) Take the clean mean of a stack of frames with the </span>
+<a name="l00075"></a>00075 <span class="comment">                  same integration time</span>
+<a name="l00076"></a>00076 <span class="comment"></span>
+<a name="l00077"></a>00077 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00078"></a>00078 
+<a name="l00079"></a>00079 <span class="keywordtype">int</span> sinfo_new_dark (<span class="keyword">const</span> <span class="keywordtype">char</span>* plugin_id, cpl_parameterlist* config, 
+<a name="l00080"></a>00080           cpl_frameset* sof, <span class="keywordtype">char</span>* dark_name)
+<a name="l00081"></a>00081 {
+<a name="l00082"></a>00082     
+<a name="l00083"></a>00083     dark_config * cfg=NULL ;
+<a name="l00084"></a>00084     cpl_imagelist * image_list=NULL ;
+<a name="l00085"></a>00085     cpl_imagelist * object_list=NULL ;
+<a name="l00086"></a>00086 
+<a name="l00087"></a>00087    
+<a name="l00088"></a>00088     cpl_image * image=NULL ;
+<a name="l00089"></a>00089     cpl_image * eclipse_image=NULL ;
+<a name="l00090"></a>00090 
+<a name="l00091"></a>00091     cpl_image* dark_img=NULL;
+<a name="l00092"></a>00092     cpl_frame* first_frame=NULL;
+<a name="l00093"></a>00093     cpl_vector* qc_dark_median=NULL;
+<a name="l00094"></a>00094     cpl_frameset* raw=NULL;
+<a name="l00095"></a>00095     cpl_table* qclog_tbl=NULL;
+<a name="l00096"></a>00096     cpl_propertylist* rplist=NULL;
+<a name="l00097"></a>00097     cpl_frameset* f_one=NULL;
+<a name="l00098"></a>00098     <span class="keywordtype">int</span> no=0;
+<a name="l00099"></a>00099     <span class="keywordtype">float</span> lo_cut=0.;
+<a name="l00100"></a>00100     <span class="keywordtype">float</span> hi_cut=0.;
+<a name="l00101"></a>00101 
+<a name="l00102"></a>00102     <span class="keywordtype">int</span> i = 0;
+<a name="l00103"></a>00103     <span class="keywordtype">int</span> j = 0;
+<a name="l00104"></a>00104     <span class="keywordtype">int</span> n = 0;
+<a name="l00105"></a>00105     <span class="keywordtype">int</span> count = 0;
+<a name="l00106"></a>00106     <span class="keywordtype">int</span>* n_times=NULL;
+<a name="l00107"></a>00107     <span class="keywordtype">double</span> exp_time = 0.;    
+<a name="l00108"></a>00108     <span class="keywordtype">float</span>* int_time=NULL;   
+<a name="l00109"></a>00109     <span class="keywordtype">float</span> time_val = 0.; 
+<a name="l00110"></a>00110 
+<a name="l00111"></a>00111     <span class="keywordtype">char</span>   ref_file[MAX_NAME_SIZE];
+<a name="l00112"></a>00112     cpl_size zone_def[4];
+<a name="l00113"></a>00113     <span class="keywordtype">double</span> qc_ron_val=0;
+<a name="l00114"></a>00114     <span class="keywordtype">double</span> qc_ron_err=0;
+<a name="l00115"></a>00115     <span class="keywordtype">double</span> qc_darkmed_ave=0;
+<a name="l00116"></a>00116     <span class="keywordtype">double</span> qc_darkmed_stdev=0;
+<a name="l00117"></a>00117     <span class="keywordtype">double</span> fpn=0;
+<a name="l00118"></a>00118     cpl_size zone[4];
+<a name="l00119"></a>00119     <span class="keywordtype">int</span> naxis1=0;
+<a name="l00120"></a>00120     <span class="keywordtype">int</span> naxis2=0;
+<a name="l00121"></a>00121 
+<a name="l00122"></a>00122     cpl_size* selection=NULL;
+<a name="l00123"></a>00123     cpl_size nsets=0;
+<a name="l00124"></a>00124     <span class="comment">/* </span>
+<a name="l00125"></a>00125 <span class="comment">       -----------------------------------------------------------------</span>
+<a name="l00126"></a>00126 <span class="comment">       1) parse the file names and parameters to the dark_config data </span>
+<a name="l00127"></a>00127 <span class="comment">          structure cfg </span>
+<a name="l00128"></a>00128 <span class="comment">       -----------------------------------------------------------------</span>
+<a name="l00129"></a>00129 <span class="comment">     */</span>
+<a name="l00130"></a>00130  
+<a name="l00131"></a>00131     check_nomsg(raw=cpl_frameset_new());
+<a name="l00132"></a>00132     cknull(cfg = sinfo_parse_cpl_input_dark(config,sof,&raw),
+<a name="l00133"></a>00133            <span class="stringliteral">"could not parse cpl input!"</span>) ;
+<a name="l00134"></a>00134 
+<a name="l00135"></a>00135     <span class="comment">/* </span>
+<a name="l00136"></a>00136 <span class="comment">       -----------------------------------------------------------------</span>
+<a name="l00137"></a>00137 <span class="comment">       2) GET FRAMES AND SORT ACCORDING TO EXPOSURE TIME </span>
+<a name="l00138"></a>00138 <span class="comment">       -----------------------------------------------------------------</span>
+<a name="l00139"></a>00139 <span class="comment">     */</span>
+<a name="l00140"></a>00140      
+<a name="l00141"></a>00141     <span class="comment">/* </span>
+<a name="l00142"></a>00142 <span class="comment">       2.1) get the total integration time from the fits header and </span>
+<a name="l00143"></a>00143 <span class="comment">            store it in an array</span>
+<a name="l00144"></a>00144 <span class="comment">     */</span>
+<a name="l00145"></a>00145 
+<a name="l00146"></a>00146     <span class="comment">/* 2.1.1) get a data cube to stack darks */</span>
+<a name="l00147"></a>00147     sinfo_msg(<span class="stringliteral">"Build data cube"</span>);
+<a name="l00148"></a>00148     <span class="comment">/* take a clean mean of the frames */</span>
+<a name="l00149"></a>00149     check_nomsg(image_list = cpl_imagelist_new());
+<a name="l00150"></a>00150     int_time = (<span class="keywordtype">float</span>*) cpl_calloc(cfg -> nframes, <span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l00151"></a>00151     sinfo_check_rec_status(0);
+<a name="l00152"></a>00152  
+<a name="l00153"></a>00153     <span class="keywordflow">for</span> ( i = 0 ; i < cfg->nframes ; i++ )
+<a name="l00154"></a>00154     {
+<a name="l00155"></a>00155         <span class="keywordflow">if</span> (sinfo_is_fits_file (cfg->inFrameList[i]) != 1) {
+<a name="l00156"></a>00156        <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Input file %s is not FITS"</span>,cfg->inFrameList[i]);
+<a name="l00157"></a>00157            <span class="keywordflow">goto</span> cleanup;
+<a name="l00158"></a>00158         }
+<a name="l00159"></a>00159 
+<a name="l00160"></a>00160     check_nomsg(cpl_imagelist_set(image_list,
+<a name="l00161"></a>00161                     cpl_image_load(cfg->inFrameList[i],CPL_TYPE_FLOAT,0,0),i));
+<a name="l00162"></a>00162 
+<a name="l00163"></a>00163         exp_time = sinfo_pfits_get_exptime(cfg->inFrameList[i]);
+<a name="l00164"></a>00164     <span class="keywordflow">if</span>(cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l00165"></a>00165        <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"could not get exposure time from fits header!\n"</span>);
+<a name="l00166"></a>00166            <span class="keywordflow">goto</span> cleanup;
+<a name="l00167"></a>00167     }
+<a name="l00168"></a>00168         sinfo_new_array_set_value(int_time, (<span class="keywordtype">float</span>)exp_time, i);
+<a name="l00169"></a>00169     }
+<a name="l00170"></a>00170     no=cfg->nframes;
+<a name="l00171"></a>00171 
+<a name="l00172"></a>00172 
+<a name="l00173"></a>00173     <span class="comment">/*</span>
+<a name="l00174"></a>00174 <span class="comment">       2.2) find the number of frames with the same integration time</span>
+<a name="l00175"></a>00175 <span class="comment">     */</span>
+<a name="l00176"></a>00176     sinfo_msg(<span class="stringliteral">"Find frames with same tint"</span>);
+<a name="l00177"></a>00177     n = 0;
+<a name="l00178"></a>00178 
+<a name="l00179"></a>00179     n_times = (<span class="keywordtype">int</span>*) cpl_calloc(cfg -> nframes, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>));
+<a name="l00180"></a>00180     sinfo_msg(<span class="stringliteral">"Sort frames with same tint"</span>);
+<a name="l00181"></a>00181 
+<a name="l00182"></a>00182     <span class="keywordflow">for</span> ( i = 0 ; i < cfg->nframes-1 ; i++ )
+<a name="l00183"></a>00183     {
+<a name="l00184"></a>00184          <span class="keywordflow">if</span> ( sinfo_new_array_get_value(int_time, i+1) != 
+<a name="l00185"></a>00185               sinfo_new_array_get_value(int_time, i)
+<a name="l00186"></a>00186         ) {
+<a name="l00187"></a>00187 
+<a name="l00188"></a>00188     n_times[n] = i+1;
+<a name="l00189"></a>00189         n = n+1;
+<a name="l00190"></a>00190     }
+<a name="l00191"></a>00191     
+<a name="l00192"></a>00192     }
+<a name="l00193"></a>00193 
+<a name="l00194"></a>00194     <span class="comment">/* </span>
+<a name="l00195"></a>00195 <span class="comment">       2.3) store the images with the same tint in data cubes and take </span>
+<a name="l00196"></a>00196 <span class="comment">            clean means</span>
+<a name="l00197"></a>00197 <span class="comment">     */</span>
+<a name="l00198"></a>00198     sinfo_msg(<span class="stringliteral">"Do clean mean"</span>);
+<a name="l00199"></a>00199     <span class="keywordflow">if</span> ( n == 0 ) {
+<a name="l00200"></a>00200 
+<a name="l00201"></a>00201       sinfo_msg(<span class="stringliteral">"n == 0 "</span>);
+<a name="l00202"></a>00202        time_val = sinfo_new_array_get_value(int_time, 0);
+<a name="l00203"></a>00203 
+<a name="l00204"></a>00204       cknull(object_list = cpl_imagelist_new(),
+<a name="l00205"></a>00205          <span class="stringliteral">"could not allocate memory for object_list"</span>);
+<a name="l00206"></a>00206 
+<a name="l00207"></a>00207        <span class="comment">/* here we have a leak of 80 bytes */</span>
+<a name="l00208"></a>00208 
+<a name="l00209"></a>00209 
+<a name="l00210"></a>00210        count = 0;
+<a name="l00211"></a>00211        <span class="comment">/* do also QC log */</span>
+<a name="l00212"></a>00212        check_nomsg(qc_dark_median=cpl_vector_new(cfg->nframes));
+<a name="l00213"></a>00213 
+<a name="l00214"></a>00214        <span class="comment">/* AMo here there is a leak */</span>
+<a name="l00215"></a>00215        <span class="keywordflow">for</span> ( j = 0 ; j < cfg->nframes ; j++ ) {
+<a name="l00216"></a>00216      check_nomsg(cpl_imagelist_set(object_list,
+<a name="l00217"></a>00217                      cpl_image_duplicate(cpl_imagelist_get(image_list,j)),
+<a name="l00218"></a>00218                      count));
+<a name="l00219"></a>00219      check_nomsg(cpl_vector_set(qc_dark_median,j,
+<a name="l00220"></a>00220                      cpl_image_get_median(cpl_imagelist_get(image_list,j))));
+<a name="l00221"></a>00221          count = count + 1;
+<a name="l00222"></a>00222        }
+<a name="l00223"></a>00223 
+<a name="l00224"></a>00224 
+<a name="l00225"></a>00225  
+<a name="l00226"></a>00226        check_nomsg(qc_darkmed_ave=cpl_vector_get_mean(qc_dark_median));
+<a name="l00227"></a>00227        <span class="keywordflow">if</span> (cfg->nframes > 1) {
+<a name="l00228"></a>00228           check_nomsg(qc_darkmed_stdev=cpl_vector_get_stdev(qc_dark_median));
+<a name="l00229"></a>00229        }
+<a name="l00230"></a>00230        <span class="comment">/* </span>
+<a name="l00231"></a>00231 <span class="comment">        rms   = stdev * sqrt(1-1/(double)cpl_vector_get_size(myvector)); </span>
+<a name="l00232"></a>00232 <span class="comment">       qc_darkmed_stdev = qc_darkmed_stdev * </span>
+<a name="l00233"></a>00233 <span class="comment">                       sqrt(1-1/(double)cpl_vector_get_size(qc_dark_median));</span>
+<a name="l00234"></a>00234 <span class="comment">        */</span>  
+<a name="l00235"></a>00235 
+<a name="l00236"></a>00236        check_nomsg(no=cpl_imagelist_get_size(object_list));
+<a name="l00237"></a>00237        lo_cut=(floor)(cfg->lo_reject*no+0.5);
+<a name="l00238"></a>00238        hi_cut=(floor)(cfg->hi_reject*no+0.5);
+<a name="l00239"></a>00239 
+<a name="l00240"></a>00240  
+<a name="l00241"></a>00241   
+<a name="l00242"></a>00242        cknull(image=cpl_imagelist_collapse_minmax_create(object_list,
+<a name="l00243"></a>00243                                                          lo_cut,hi_cut),
+<a name="l00244"></a>00244           <span class="stringliteral">"sinfo_average_with_rejection failed"</span>);
+<a name="l00245"></a>00245 
+<a name="l00246"></a>00246        sinfo_free_imagelist(&object_list);
+<a name="l00247"></a>00247 
+<a name="l00248"></a>00248        sinfo_msg(<span class="stringliteral">"dark_name=%s\n"</span>,dark_name);
+<a name="l00249"></a>00249        
+<a name="l00250"></a>00250        check_nomsg(first_frame = cpl_frameset_get_frame(raw, 0)) ;
+<a name="l00251"></a>00251    
+<a name="l00252"></a>00252        strcpy(ref_file,cpl_frame_get_filename(first_frame)) ;
+<a name="l00253"></a>00253        cknull_nomsg(rplist = cpl_propertylist_load(ref_file, 0));
+<a name="l00254"></a>00254 
+<a name="l00255"></a>00255        check_nomsg(naxis1=cpl_propertylist_get_int(rplist,<span class="stringliteral">"NAXIS1"</span>));
+<a name="l00256"></a>00256        check_nomsg(naxis2=cpl_propertylist_get_int(rplist,<span class="stringliteral">"NAXIS1"</span>));
+<a name="l00257"></a>00257        sinfo_free_propertylist(&rplist);
+<a name="l00258"></a>00258 
+<a name="l00259"></a>00259        <span class="keywordflow">if</span>(cfg->qc_ron_xmin < 1) {
+<a name="l00260"></a>00260      <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"qc_ron_xmin %d < 1"</span>,cfg->qc_ron_xmin);
+<a name="l00261"></a>00261          <span class="keywordflow">goto</span> cleanup;
+<a name="l00262"></a>00262        }
+<a name="l00263"></a>00263 
+<a name="l00264"></a>00264        <span class="keywordflow">if</span>(cfg->qc_ron_xmax > naxis1) {
+<a name="l00265"></a>00265      <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"qc_ron_xmax %d > %d"</span>,cfg->qc_ron_xmax,naxis1);
+<a name="l00266"></a>00266          <span class="keywordflow">goto</span> cleanup;
+<a name="l00267"></a>00267        }
+<a name="l00268"></a>00268 
+<a name="l00269"></a>00269        <span class="keywordflow">if</span>(cfg->qc_ron_ymin < 1) {
+<a name="l00270"></a>00270      <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"qc_ron_ymin %d < 1"</span>,cfg->qc_ron_ymin);
+<a name="l00271"></a>00271          <span class="keywordflow">goto</span> cleanup;
+<a name="l00272"></a>00272        }
+<a name="l00273"></a>00273 
+<a name="l00274"></a>00274        <span class="keywordflow">if</span>(cfg->qc_ron_ymax > naxis2) {
+<a name="l00275"></a>00275      <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"qc_ron_ymax %d > %d"</span>,cfg->qc_ron_ymax,naxis2);
+<a name="l00276"></a>00276          <span class="keywordflow">goto</span> cleanup;
+<a name="l00277"></a>00277        }
+<a name="l00278"></a>00278 
+<a name="l00279"></a>00279        zone_def[0]=cfg->qc_ron_xmin;
+<a name="l00280"></a>00280        zone_def[1]=cfg->qc_ron_xmax;
+<a name="l00281"></a>00281        zone_def[2]=cfg->qc_ron_ymin;
+<a name="l00282"></a>00282        zone_def[3]=cfg->qc_ron_ymax;
+<a name="l00283"></a>00283 
+<a name="l00284"></a>00284 
+<a name="l00285"></a>00285 
+<a name="l00286"></a>00286        check(cpl_flux_get_noise_window(image,
+<a name="l00287"></a>00287                        zone_def,
+<a name="l00288"></a>00288                        cfg->qc_ron_hsize,
+<a name="l00289"></a>00289                        cfg->qc_ron_nsamp,
+<a name="l00290"></a>00290                        &qc_ron_val,
+<a name="l00291"></a>00291                        &qc_ron_err),
+<a name="l00292"></a>00292          <span class="stringliteral">"In computation RON on image %s"</span>,dark_name);
+<a name="l00293"></a>00293       
+<a name="l00294"></a>00294  
+<a name="l00295"></a>00295 
+<a name="l00296"></a>00296        <span class="keywordflow">if</span>(cfg->qc_fpn_xmin < 1) {
+<a name="l00297"></a>00297      <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"qc_fpn_xmin %d < 1"</span>,cfg->qc_fpn_xmin);
+<a name="l00298"></a>00298          <span class="keywordflow">goto</span> cleanup;
+<a name="l00299"></a>00299        }
+<a name="l00300"></a>00300 
+<a name="l00301"></a>00301        <span class="keywordflow">if</span>(cfg->qc_fpn_xmax > naxis1) {
+<a name="l00302"></a>00302      <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"qc_fpn_xmax %d > %d"</span>,cfg->qc_fpn_xmax,naxis1);
+<a name="l00303"></a>00303          <span class="keywordflow">goto</span> cleanup;
+<a name="l00304"></a>00304        }
+<a name="l00305"></a>00305 
+<a name="l00306"></a>00306        <span class="keywordflow">if</span>(cfg->qc_fpn_ymin < 1) {
+<a name="l00307"></a>00307      <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"qc_fpn_ymin %d < 1"</span>,cfg->qc_fpn_ymin);
+<a name="l00308"></a>00308          <span class="keywordflow">goto</span> cleanup;
+<a name="l00309"></a>00309        }
+<a name="l00310"></a>00310 
+<a name="l00311"></a>00311        <span class="keywordflow">if</span>(cfg->qc_fpn_ymax > naxis2) {
+<a name="l00312"></a>00312      <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"qc_fpn_ymax %d > %d"</span>,cfg->qc_fpn_ymax,naxis2);
+<a name="l00313"></a>00313          <span class="keywordflow">goto</span> cleanup;
+<a name="l00314"></a>00314        }
+<a name="l00315"></a>00315 
+<a name="l00316"></a>00316        zone[0]=cfg->qc_fpn_xmin;
+<a name="l00317"></a>00317        zone[1]=cfg->qc_fpn_xmax;
+<a name="l00318"></a>00318        zone[2]=cfg->qc_fpn_ymin;
+<a name="l00319"></a>00319        zone[3]=cfg->qc_fpn_ymax;
+<a name="l00320"></a>00320        check(cpl_flux_get_noise_window(image, zone, cfg->qc_fpn_hsize,
+<a name="l00321"></a>00321                        cfg->qc_fpn_nsamp, &fpn, NULL),
+<a name="l00322"></a>00322          <span class="stringliteral">"Error computing noise in a window"</span>);
+<a name="l00323"></a>00323 
+<a name="l00324"></a>00324        <span class="comment">/* QC LOG */</span>
+<a name="l00325"></a>00325        cknull_nomsg(qclog_tbl = sinfo_qclog_init());
+<a name="l00326"></a>00326 
+<a name="l00327"></a>00327        ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,<span class="stringliteral">"QC DARKMED AVE"</span>,
+<a name="l00328"></a>00328              qc_darkmed_ave,<span class="stringliteral">"Average of raw darks medians"</span>,<span class="stringliteral">"%f"</span>));
+<a name="l00329"></a>00329 
+<a name="l00330"></a>00330        ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,<span class="stringliteral">"QC DARKMED STDEV"</span>,
+<a name="l00331"></a>00331                      qc_darkmed_stdev,<span class="stringliteral">"STDEV of raw darks medians"</span>,<span class="stringliteral">"%f"</span>));
+<a name="l00332"></a>00332 
+<a name="l00333"></a>00333        ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,<span class="stringliteral">"QC RON"</span>,
+<a name="l00334"></a>00334                      qc_ron_val,<span class="stringliteral">"Read Out Noise"</span>,<span class="stringliteral">"%f"</span>));
+<a name="l00335"></a>00335        
+<a name="l00336"></a>00336        ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,<span class="stringliteral">"QC RONRMS"</span>,
+<a name="l00337"></a>00337                      qc_ron_err,<span class="stringliteral">"RMS on Read Out Noise"</span>,<span class="stringliteral">"%f"</span>));
+<a name="l00338"></a>00338 
+<a name="l00339"></a>00339        ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,<span class="stringliteral">"QC DARKFPN"</span>,
+<a name="l00340"></a>00340                      fpn,<span class="stringliteral">"Fixed Pattern Noise of combined frames"</span>,<span class="stringliteral">"%g"</span>));
+<a name="l00341"></a>00341 
+<a name="l00342"></a>00342  
+<a name="l00343"></a>00343        <span class="comment">/* special way to calculate RON: for each couple */</span>
+<a name="l00344"></a>00344        
+<a name="l00345"></a>00345        check(selection = cpl_frameset_labelise(raw,sinfo_dark_compare,&nsets),
+<a name="l00346"></a>00346          <span class="stringliteral">"Error labelizing"</span>);
+<a name="l00347"></a>00347 
+<a name="l00348"></a>00348 
+<a name="l00349"></a>00349 
+<a name="l00350"></a>00350        <span class="keywordflow">for</span> ( i = 0 ; i < nsets ; i++ ) {
+<a name="l00351"></a>00351          sinfo_msg(<span class="stringliteral">"Reduce data set no %d out of %"</span> CPL_SIZE_FORMAT <span class="stringliteral">""</span>, i+1, nsets);
+<a name="l00352"></a>00352          cpl_msg_indent_more();
+<a name="l00353"></a>00353      check_nomsg(f_one = cpl_frameset_extract(raw,selection,i));
+<a name="l00354"></a>00354          <span class="keywordflow">if</span> (cpl_frameset_get_size(f_one) < 2) {
+<a name="l00355"></a>00355            <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"Skip %d set. One frame, not enough "</span>
+<a name="l00356"></a>00356                              <span class="stringliteral">"to get ron"</span>,i+1);
+<a name="l00357"></a>00357      } <span class="keywordflow">else</span> {
+<a name="l00358"></a>00358            <span class="keywordflow">if</span> (sinfo_dark_ron_reduce(f_one,cfg,qclog_tbl) ) {
+<a name="l00359"></a>00359          <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>( <span class="stringliteral">"Cannot reduce set number %d"</span>, i+1) ;
+<a name="l00360"></a>00360        }
+<a name="l00361"></a>00361      }
+<a name="l00362"></a>00362          sinfo_free_frameset(&f_one);
+<a name="l00363"></a>00363          cpl_msg_indent_less();
+<a name="l00364"></a>00364 
+<a name="l00365"></a>00365        }
+<a name="l00366"></a>00366        cpl_free(selection);
+<a name="l00367"></a>00367 
+<a name="l00368"></a>00368 
+<a name="l00369"></a>00369        <span class="comment">/* generate a dummy_set with the master dark and a dummy </span>
+<a name="l00370"></a>00370 <span class="comment">              dark=2*master_dark */</span>
+<a name="l00371"></a>00371 
+<a name="l00372"></a>00372        ck0(sinfo_pro_save_ima(image,raw,sof,dark_name,
+<a name="l00373"></a>00373                  PRO_MASTER_DARK,qclog_tbl,plugin_id,config),
+<a name="l00374"></a>00374                            <span class="stringliteral">"cannot save ima %s"</span>, dark_name);
+<a name="l00375"></a>00375        sinfo_free_table(&qclog_tbl);
+<a name="l00376"></a>00376        sinfo_free_image(&image);
+<a name="l00377"></a>00377  
+<a name="l00378"></a>00378     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (n == 1) {
+<a name="l00379"></a>00379 
+<a name="l00380"></a>00380        sinfo_msg(<span class="stringliteral">"n == 1"</span>);
+<a name="l00381"></a>00381        time_val = sinfo_new_array_get_value(int_time, 0);
+<a name="l00382"></a>00382        cknull(object_list = cpl_imagelist_new(),
+<a name="l00383"></a>00383            <span class="stringliteral">"could not allocate memory"</span>);
+<a name="l00384"></a>00384 
+<a name="l00385"></a>00385        count = 0;
+<a name="l00386"></a>00386 
+<a name="l00387"></a>00387        <span class="keywordflow">for</span> (j =0; j < n_times[0]; j++) {
+<a name="l00388"></a>00388 
+<a name="l00389"></a>00389      check_nomsg(cpl_imagelist_set(object_list,
+<a name="l00390"></a>00390                      cpl_image_duplicate(cpl_imagelist_get(image_list,j)),
+<a name="l00391"></a>00391                      count));
+<a name="l00392"></a>00392      count = count + 1;
+<a name="l00393"></a>00393        }
+<a name="l00394"></a>00394 
+<a name="l00395"></a>00395 
+<a name="l00396"></a>00396        check_nomsg(no=cpl_imagelist_get_size(object_list));
+<a name="l00397"></a>00397        lo_cut=(floor)(cfg->lo_reject*no+0.5);
+<a name="l00398"></a>00398        hi_cut=(floor)(cfg->hi_reject*no+0.5);
+<a name="l00399"></a>00399        check(image=cpl_imagelist_collapse_minmax_create(object_list,
+<a name="l00400"></a>00400                                                         lo_cut,hi_cut),
+<a name="l00401"></a>00401                                  <span class="stringliteral">"sinfo_average_with_rejection failed!"</span>);
+<a name="l00402"></a>00402 
+<a name="l00403"></a>00403        sinfo_free_imagelist(&object_list);
+<a name="l00404"></a>00404 
+<a name="l00405"></a>00405        cknull_nomsg(qclog_tbl = sinfo_qclog_init());
+<a name="l00406"></a>00406        ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,<span class="stringliteral">"QC NAME"</span>,1,
+<a name="l00407"></a>00407                                      <span class="stringliteral">"A description"</span>,<span class="stringliteral">"%d"</span>));
+<a name="l00408"></a>00408 
+<a name="l00409"></a>00409        ck0(sinfo_pro_save_ima(image,raw,sof,dark_name,
+<a name="l00410"></a>00410                   PRO_MASTER_DARK,qclog_tbl,plugin_id,config),
+<a name="l00411"></a>00411                           <span class="stringliteral">"cannot save ima %s"</span>, dark_name);
+<a name="l00412"></a>00412 
+<a name="l00413"></a>00413 
+<a name="l00414"></a>00414        sinfo_free_image(&image);
+<a name="l00415"></a>00415        sinfo_free_table(&qclog_tbl);
+<a name="l00416"></a>00416 
+<a name="l00417"></a>00417        time_val = sinfo_new_array_get_value(int_time, n_times[0]);
+<a name="l00418"></a>00418        cknull(object_list = cpl_imagelist_new(),
+<a name="l00419"></a>00419           <span class="stringliteral">"could not allocate memory"</span>);
+<a name="l00420"></a>00420        count = 0;
+<a name="l00421"></a>00421 
+<a name="l00422"></a>00422 
+<a name="l00423"></a>00423        <span class="keywordflow">for</span> (j = n_times[0]; j < cfg->nframes; j++) {
+<a name="l00424"></a>00424 
+<a name="l00425"></a>00425      check_nomsg(cpl_imagelist_set(object_list,
+<a name="l00426"></a>00426                      cpl_image_duplicate(cpl_imagelist_get(image_list,j)),
+<a name="l00427"></a>00427                      count));
+<a name="l00428"></a>00428          count = count + 1;
+<a name="l00429"></a>00429        }
+<a name="l00430"></a>00430 
+<a name="l00431"></a>00431 
+<a name="l00432"></a>00432        check_nomsg(no=cpl_imagelist_get_size(object_list));
+<a name="l00433"></a>00433        lo_cut=(floor)(cfg->lo_reject*no+0.5);
+<a name="l00434"></a>00434        hi_cut=(floor)(cfg->hi_reject*no+0.5);
+<a name="l00435"></a>00435        cknull(eclipse_image=cpl_imagelist_collapse_minmax_create(object_list,
+<a name="l00436"></a>00436                                                                  lo_cut,hi_cut),
+<a name="l00437"></a>00437           <span class="stringliteral">"sinfo_average_with_rejection failed!"</span>);
+<a name="l00438"></a>00438 
+<a name="l00439"></a>00439        sinfo_free_imagelist(&object_list);
+<a name="l00440"></a>00440 
+<a name="l00441"></a>00441 
+<a name="l00442"></a>00442        cknull_nomsg(qclog_tbl = sinfo_qclog_init());
+<a name="l00443"></a>00443        ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,<span class="stringliteral">"QC NAME"</span>,1,
+<a name="l00444"></a>00444                                      <span class="stringliteral">"A description"</span>,<span class="stringliteral">"%d"</span>));
+<a name="l00445"></a>00445 
+<a name="l00446"></a>00446        ck0(sinfo_pro_save_ima(eclipse_image,raw,sof,dark_name,
+<a name="l00447"></a>00447                   PRO_MASTER_DARK,qclog_tbl,plugin_id,config),
+<a name="l00448"></a>00448                           <span class="stringliteral">"cannot save ima %s"</span>, dark_name);
+<a name="l00449"></a>00449 
+<a name="l00450"></a>00450        sinfo_free_image(&eclipse_image);
+<a name="l00451"></a>00451        sinfo_free_table(&qclog_tbl);
+<a name="l00452"></a>00452 
+<a name="l00453"></a>00453     } <span class="keywordflow">else</span> {
+<a name="l00454"></a>00454 
+<a name="l00455"></a>00455        sinfo_msg(<span class="stringliteral">"n==else\n"</span>);
+<a name="l00456"></a>00456 
+<a name="l00457"></a>00457        <span class="keywordflow">for</span> (i= 0; i < n+1; i++) {
+<a name="l00458"></a>00458          <span class="keywordflow">if</span> ( i == 0 ) {
+<a name="l00459"></a>00459            time_val = sinfo_new_array_get_value(int_time, 0);
+<a name="l00460"></a>00460         check(object_list = cpl_imagelist_new(),
+<a name="l00461"></a>00461                <span class="stringliteral">"could not allocate memory"</span>);
+<a name="l00462"></a>00462 
+<a name="l00463"></a>00463             count = 0;
+<a name="l00464"></a>00464             <span class="keywordflow">for</span> (j = 0; j < n_times[0]; j++) {
+<a name="l00465"></a>00465           check_nomsg(cpl_imagelist_set(object_list,
+<a name="l00466"></a>00466                           cpl_image_duplicate(cpl_imagelist_get(image_list,j)),
+<a name="l00467"></a>00467                           count));
+<a name="l00468"></a>00468           count = count + 1;
+<a name="l00469"></a>00469         }
+<a name="l00470"></a>00470         check_nomsg(no=cpl_imagelist_get_size(object_list));
+<a name="l00471"></a>00471         lo_cut=(floor)(cfg->lo_reject*no+0.5);
+<a name="l00472"></a>00472         hi_cut=(floor)(cfg->hi_reject*no+0.5);
+<a name="l00473"></a>00473             check(image=cpl_imagelist_collapse_minmax_create(object_list,
+<a name="l00474"></a>00474                                                              lo_cut,hi_cut),
+<a name="l00475"></a>00475                                     <span class="stringliteral">"Error computing average with rejection"</span>);
+<a name="l00476"></a>00476             sinfo_free_imagelist(&object_list);
+<a name="l00477"></a>00477 
+<a name="l00478"></a>00478             sinfo_msg(<span class="stringliteral">"dark_name-%s\n"</span>,dark_name);
+<a name="l00479"></a>00479             cknull_nomsg(qclog_tbl = sinfo_qclog_init());
+<a name="l00480"></a>00480             ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,<span class="stringliteral">"QC NAME"</span>,1,
+<a name="l00481"></a>00481                                           <span class="stringliteral">"A description"</span>,<span class="stringliteral">"%d"</span>));
+<a name="l00482"></a>00482 
+<a name="l00483"></a>00483             ck0(sinfo_pro_save_ima(image,raw,sof,dark_name,
+<a name="l00484"></a>00484                    PRO_MASTER_DARK,qclog_tbl,plugin_id,config),
+<a name="l00485"></a>00485               <span class="stringliteral">"cannot save ima %s"</span>, dark_name);
+<a name="l00486"></a>00486 
+<a name="l00487"></a>00487 
+<a name="l00488"></a>00488             sinfo_free_table(&qclog_tbl);
+<a name="l00489"></a>00489             sinfo_free_image(&image);
+<a name="l00490"></a>00490      } <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( i == n ) {
+<a name="l00491"></a>00491             time_val = sinfo_new_array_get_value(int_time, n_times[n-1]);
+<a name="l00492"></a>00492             cknull(object_list = cpl_imagelist_new(), 
+<a name="l00493"></a>00493                <span class="stringliteral">"could not allocate memory"</span>);
+<a name="l00494"></a>00494 
+<a name="l00495"></a>00495             count = 0;
+<a name="l00496"></a>00496             <span class="keywordflow">for</span> (j = n_times[n-1]; j < cfg->nframes; j++) {
+<a name="l00497"></a>00497           check_nomsg(cpl_imagelist_set(object_list,
+<a name="l00498"></a>00498                           cpl_image_duplicate(cpl_imagelist_get(image_list,j)),
+<a name="l00499"></a>00499                           count));
+<a name="l00500"></a>00500           count = count + 1;
+<a name="l00501"></a>00501         }
+<a name="l00502"></a>00502         check_nomsg(no=cpl_imagelist_get_size(object_list));
+<a name="l00503"></a>00503         lo_cut=(floor)(cfg->lo_reject*no+0.5);
+<a name="l00504"></a>00504         hi_cut=(floor)(cfg->hi_reject*no+0.5);
+<a name="l00505"></a>00505             check(image=cpl_imagelist_collapse_minmax_create(object_list,
+<a name="l00506"></a>00506                                                              lo_cut,hi_cut),
+<a name="l00507"></a>00507                   <span class="stringliteral">"Error computing average with rejection"</span>);
+<a name="l00508"></a>00508 
+<a name="l00509"></a>00509             sinfo_free_imagelist(&object_list);
+<a name="l00510"></a>00510 
+<a name="l00511"></a>00511             cknull_nomsg(qclog_tbl = sinfo_qclog_init());
+<a name="l00512"></a>00512             ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,<span class="stringliteral">"QC NAME"</span>,1,
+<a name="l00513"></a>00513                                           <span class="stringliteral">"A description"</span>,<span class="stringliteral">"%d"</span>));
+<a name="l00514"></a>00514 
+<a name="l00515"></a>00515             ck0(sinfo_pro_save_ima(image,raw,sof,dark_name,
+<a name="l00516"></a>00516                    PRO_MASTER_DARK,qclog_tbl,plugin_id,config),
+<a name="l00517"></a>00517         <span class="stringliteral">"cannot save ima %s"</span>, dark_name);
+<a name="l00518"></a>00518             sinfo_free_table(&qclog_tbl);
+<a name="l00519"></a>00519             sinfo_free_image(&image);
+<a name="l00520"></a>00520     } <span class="keywordflow">else</span> {
+<a name="l00521"></a>00521         time_val = sinfo_new_array_get_value(int_time, n_times[i-1]);
+<a name="l00522"></a>00522         cknull(object_list = cpl_imagelist_new(), 
+<a name="l00523"></a>00523                    <span class="stringliteral">"could not allocate memory"</span>);
+<a name="l00524"></a>00524 
+<a name="l00525"></a>00525             count = 0;
+<a name="l00526"></a>00526             <span class="keywordflow">for</span> (j = n_times[i-1]; j < n_times[i]; j++) {
+<a name="l00527"></a>00527           check_nomsg(cpl_imagelist_set(object_list,
+<a name="l00528"></a>00528                           cpl_image_duplicate(cpl_imagelist_get(image_list,j)),
+<a name="l00529"></a>00529                           count));
+<a name="l00530"></a>00530           count = count + 1;
+<a name="l00531"></a>00531         }
+<a name="l00532"></a>00532         check_nomsg(no=cpl_imagelist_get_size(object_list));
+<a name="l00533"></a>00533         lo_cut=(floor)(cfg->lo_reject*no+0.5);
+<a name="l00534"></a>00534         hi_cut=(floor)(cfg->hi_reject*no+0.5);
+<a name="l00535"></a>00535             cknull(image=cpl_imagelist_collapse_minmax_create(object_list,
+<a name="l00536"></a>00536                                                               lo_cut,hi_cut),
+<a name="l00537"></a>00537                                      <span class="stringliteral">"Error computing average with rejection"</span>);
+<a name="l00538"></a>00538 
+<a name="l00539"></a>00539             sinfo_free_imagelist(&object_list);
+<a name="l00540"></a>00540 
+<a name="l00541"></a>00541             cknull_nomsg(qclog_tbl = sinfo_qclog_init());
+<a name="l00542"></a>00542             ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,<span class="stringliteral">"QC NAME"</span>,1,
+<a name="l00543"></a>00543                                           <span class="stringliteral">"A description"</span>,<span class="stringliteral">"%d"</span>));
+<a name="l00544"></a>00544 
+<a name="l00545"></a>00545             ck0(sinfo_pro_save_ima(image,raw,sof,dark_name,
+<a name="l00546"></a>00546                    PRO_MASTER_DARK,qclog_tbl,plugin_id,config),
+<a name="l00547"></a>00547                                    <span class="stringliteral">"cannot save ima %s"</span>, dark_name);
+<a name="l00548"></a>00548 
+<a name="l00549"></a>00549             sinfo_free_image(&image);
+<a name="l00550"></a>00550             sinfo_free_table(&qclog_tbl);
+<a name="l00551"></a>00551     }
+<a name="l00552"></a>00552        
+<a name="l00553"></a>00553        } <span class="comment">/* end for loop */</span>
+<a name="l00554"></a>00554     } <span class="comment">/* end else over n */</span>
+<a name="l00555"></a>00555 
+<a name="l00556"></a>00556  
+<a name="l00557"></a>00557 
+<a name="l00558"></a>00558        sinfo_free_imagelist(&image_list);
+<a name="l00559"></a>00559        sinfo_free_my_vector(&qc_dark_median);
+<a name="l00560"></a>00560        sinfo_free_int(&n_times);
+<a name="l00561"></a>00561        sinfo_free_float(&int_time);
+<a name="l00562"></a>00562        sinfo_dark_free(&cfg);
+<a name="l00563"></a>00563        sinfo_free_frameset(&raw);
+<a name="l00564"></a>00564 
+<a name="l00565"></a>00565       <span class="keywordflow">return</span> 0;
+<a name="l00566"></a>00566 
+<a name="l00567"></a>00567  cleanup:
+<a name="l00568"></a>00568        sinfo_free_frameset(&f_one);
+<a name="l00569"></a>00569        cpl_free(selection);
+<a name="l00570"></a>00570        sinfo_free_image(&eclipse_image);
+<a name="l00571"></a>00571        sinfo_free_table(&qclog_tbl);
+<a name="l00572"></a>00572        sinfo_free_image(&dark_img);
+<a name="l00573"></a>00573        sinfo_free_image(&image);
+<a name="l00574"></a>00574        sinfo_free_propertylist(&rplist);
+<a name="l00575"></a>00575        sinfo_free_my_vector(&qc_dark_median);
+<a name="l00576"></a>00576        sinfo_free_imagelist(&object_list);
+<a name="l00577"></a>00577        sinfo_free_int(&n_times);
+<a name="l00578"></a>00578        sinfo_free_float(&int_time);
+<a name="l00579"></a>00579        sinfo_free_imagelist(&image_list);
+<a name="l00580"></a>00580        sinfo_dark_free(&cfg);
+<a name="l00581"></a>00581        sinfo_free_frameset(&raw);
+<a name="l00582"></a>00582 
+<a name="l00583"></a>00583        <span class="keywordflow">return</span> -1;
+<a name="l00584"></a>00584 
+<a name="l00585"></a>00585 }
+<a name="l00586"></a>00586 
+<a name="l00587"></a>00587 
+<a name="l00588"></a>00588 
+<a name="l00589"></a>00589 
+<a name="l00590"></a>00590 
+<a name="l00591"></a>00591 
+<a name="l00592"></a>00592 <span class="comment">/*--------------------------------------------------------------------*/</span>
+<a name="l00599"></a>00599 <span class="comment">/*--------------------------------------------------------------------*/</span>
+<a name="l00600"></a>00600  <span class="keyword">static</span> <span class="keywordtype">int</span> 
+<a name="l00601"></a>00601 sinfo_dark_ron_reduce(cpl_frameset    *   framelist,
+<a name="l00602"></a>00602               dark_config     *   cfg,
+<a name="l00603"></a>00603               cpl_table       *   qclog_tbl)
+<a name="l00604"></a>00604 {
+<a name="l00605"></a>00605   cpl_imagelist   *   iset =NULL;
+<a name="l00606"></a>00606   <span class="keywordtype">int</span>                 i =0;
+<a name="l00607"></a>00607   <span class="keywordtype">double</span>* ron=NULL;
+<a name="l00608"></a>00608   <span class="comment">/* int nraw=0; */</span>
+<a name="l00609"></a>00609   <span class="keywordtype">int</span> niset=0;
+<a name="l00610"></a>00610   <span class="keywordtype">char</span> key_name[MAX_NAME_SIZE];
+<a name="l00611"></a>00611   <span class="comment">/* Test entries */</span>
+<a name="l00612"></a>00612 
+<a name="l00613"></a>00613   cknull_nomsg(framelist);
+<a name="l00614"></a>00614 
+<a name="l00615"></a>00615   <span class="comment">/* Load the current set */</span>
+<a name="l00616"></a>00616   <span class="keywordflow">if</span> ((iset = sinfo_new_frameset_to_iset(framelist)) == NULL) {
+<a name="l00617"></a>00617     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>( <span class="stringliteral">"Cannot load the data"</span>) ;
+<a name="l00618"></a>00618     <span class="keywordflow">return</span> -1 ;
+<a name="l00619"></a>00619   }
+<a name="l00620"></a>00620   <span class="comment">/* Loop on all pairs */</span>
+<a name="l00621"></a>00621   <span class="comment">/* nraw = cpl_table_get_nrow(qclog_tbl); */</span>
+<a name="l00622"></a>00622   niset=cpl_imagelist_get_size(iset);
+<a name="l00623"></a>00623 
+<a name="l00624"></a>00624   ron = cpl_calloc(niset,<span class="keyword">sizeof</span>(<span class="keywordtype">double</span>));
+<a name="l00625"></a>00625 
+<a name="l00626"></a>00626   sinfo_get_ron(framelist,
+<a name="l00627"></a>00627                 cfg->qc_ron_xmin,cfg->qc_ron_xmax,
+<a name="l00628"></a>00628                 cfg->qc_ron_ymin,cfg->qc_ron_ymax,
+<a name="l00629"></a>00629                 cfg->qc_ron_hsize,cfg->qc_ron_nsamp,
+<a name="l00630"></a>00630                 &ron);
+<a name="l00631"></a>00631 
+<a name="l00632"></a>00632   <span class="keywordflow">for</span> (i=0 ; i<niset-1 ; i++) {
+<a name="l00633"></a>00633 
+<a name="l00634"></a>00634     <span class="comment">/* Write the paf file on disk */</span>
+<a name="l00635"></a>00635     <span class="comment">/* Write QC LOG */</span>
+<a name="l00636"></a>00636 
+<a name="l00637"></a>00637     snprintf(key_name,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%d"</span>,<span class="stringliteral">"QC RON"</span>,i+1);
+<a name="l00638"></a>00638     sinfo_qclog_add_double(qclog_tbl,key_name,ron[i],
+<a name="l00639"></a>00639                <span class="stringliteral">"Read Out Noise"</span>,<span class="stringliteral">"%f"</span>);
+<a name="l00640"></a>00640 
+<a name="l00641"></a>00641   }
+<a name="l00642"></a>00642 
+<a name="l00643"></a>00643   cpl_free(ron);
+<a name="l00644"></a>00644   sinfo_free_imagelist(&iset) ;
+<a name="l00645"></a>00645 
+<a name="l00646"></a>00646   <span class="keywordflow">return</span> 0 ;
+<a name="l00647"></a>00647  cleanup:
+<a name="l00648"></a>00648   cpl_free(ron);
+<a name="l00649"></a>00649   ron=NULL;
+<a name="l00650"></a>00650   sinfo_free_imagelist(&iset) ;
+<a name="l00651"></a>00651 
+<a name="l00652"></a>00652   <span class="keywordflow">return</span> -1;
+<a name="l00653"></a>00653 
+<a name="l00654"></a>00654 }
+<a name="l00655"></a>00655 
+<a name="l00656"></a>00656 
+<a name="l00657"></a>00657 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00664"></a>00664 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00665"></a>00665 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_dark_compare(
+<a name="l00666"></a>00666         <span class="keyword">const</span> cpl_frame   *   frame1,
+<a name="l00667"></a>00667         <span class="keyword">const</span> cpl_frame   *   frame2)
+<a name="l00668"></a>00668 {
+<a name="l00669"></a>00669     <span class="keywordtype">int</span>                 comparison=0 ;
+<a name="l00670"></a>00670     cpl_propertylist *  plist1=NULL;
+<a name="l00671"></a>00671     cpl_propertylist *  plist2=NULL;
+<a name="l00672"></a>00672 
+<a name="l00673"></a>00673     <span class="keywordtype">char</span>            *   sval ;
+<a name="l00674"></a>00674     <span class="keywordtype">char</span>                mode1[512] ;
+<a name="l00675"></a>00675     <span class="keywordtype">char</span>                mode2[512] ;
+<a name="l00676"></a>00676     <span class="keywordtype">double</span>              dval1=0;
+<a name="l00677"></a>00677     <span class="keywordtype">double</span>              dval2=0;
+<a name="l00678"></a>00678     <span class="keywordtype">int</span>                 ival1=0;
+<a name="l00679"></a>00679     <span class="keywordtype">int</span>                 ival2=0;
+<a name="l00680"></a>00680 
+<a name="l00681"></a>00681     <span class="comment">/* Test entries */</span>
+<a name="l00682"></a>00682     <span class="keywordflow">if</span> (frame1==NULL || frame2==NULL) <span class="keywordflow">return</span> -1 ;
+<a name="l00683"></a>00683 
+<a name="l00684"></a>00684     <span class="comment">/* Get property lists */</span>
+<a name="l00685"></a>00685     cknull(plist1=cpl_propertylist_load(cpl_frame_get_filename(frame1),0),
+<a name="l00686"></a>00686         <span class="stringliteral">"getting header from reference frame"</span>);
+<a name="l00687"></a>00687 
+<a name="l00688"></a>00688     cknull(plist2=cpl_propertylist_load(cpl_frame_get_filename(frame2),0),
+<a name="l00689"></a>00689         <span class="stringliteral">"getting header from reference frame"</span>);
+<a name="l00690"></a>00690      
+<a name="l00691"></a>00691     <span class="comment">/* Compare exposure time */</span>
+<a name="l00692"></a>00692     comparison = 1 ;
+<a name="l00693"></a>00693     check(dval1=sinfo_pfits_get_exp_time(plist1),<span class="stringliteral">"To get exptime"</span>);
+<a name="l00694"></a>00694     check(dval2=sinfo_pfits_get_exp_time(plist2),<span class="stringliteral">"To get exptime"</span>);
+<a name="l00695"></a>00695 
+<a name="l00696"></a>00696     <span class="keywordflow">if</span> (fabs(dval1-dval2) > 1e-5) comparison = 0 ;
+<a name="l00697"></a>00697 
+<a name="l00698"></a>00698     <span class="comment">/* Compare the readout mode */</span>
+<a name="l00699"></a>00699     check(ival1=sinfo_pfits_get_rom(plist1),<span class="stringliteral">"to get read out mode"</span>);
+<a name="l00700"></a>00700     check(ival2=sinfo_pfits_get_rom(plist2),<span class="stringliteral">"to get read out mode"</span>);
+<a name="l00701"></a>00701     <span class="keywordflow">if</span> (ival1 != ival2) comparison = 0 ;
+<a name="l00702"></a>00702 
+<a name="l00703"></a>00703 
+<a name="l00704"></a>00704     <span class="comment">/* Compare the detector mode */</span>
+<a name="l00705"></a>00705     cknull(sval=sinfo_pfits_get_mode(plist1),<span class="stringliteral">"to get detector mode"</span>);
+<a name="l00706"></a>00706     strcpy(mode1, sval) ;
+<a name="l00707"></a>00707 
+<a name="l00708"></a>00708     cknull(sval=sinfo_pfits_get_mode(plist2),<span class="stringliteral">"to get detector mode"</span>);
+<a name="l00709"></a>00709     strcpy(mode2, sval) ;
+<a name="l00710"></a>00710 
+<a name="l00711"></a>00711 
+<a name="l00712"></a>00712     <span class="keywordflow">if</span> (strcmp(mode1, mode2)) comparison = 0 ;
+<a name="l00713"></a>00713 
+<a name="l00714"></a>00714     <span class="comment">/* Files have to be consequtive */</span>
+<a name="l00715"></a>00715     <span class="comment">/*</span>
+<a name="l00716"></a>00716 <span class="comment">    check(ival1 = sinfo_pfits_get_expno(plist1),"to get exposure number");</span>
+<a name="l00717"></a>00717 <span class="comment">    check(ival2 = sinfo_pfits_get_expno(plist1),"to get exposure number");</span>
+<a name="l00718"></a>00718 <span class="comment">    if (ival1 != ival2) comparison = 0 ;</span>
+<a name="l00719"></a>00719 <span class="comment">    */</span>
+<a name="l00720"></a>00720     sinfo_free_propertylist(&plist1);
+<a name="l00721"></a>00721     sinfo_free_propertylist(&plist2);
+<a name="l00722"></a>00722 
+<a name="l00723"></a>00723     <span class="keywordflow">return</span> comparison ;
+<a name="l00724"></a>00724  cleanup:
+<a name="l00725"></a>00725     sinfo_free_propertylist(&plist1);
+<a name="l00726"></a>00726     sinfo_free_propertylist(&plist2);
+<a name="l00727"></a>00727     <span class="keywordflow">return</span> -1 ;
+<a name="l00728"></a>00728 
+<a name="l00729"></a>00729 
+<a name="l00730"></a>00730 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__new__dark_8h_source.html b/html/sinfo__new__dark_8h_source.html
new file mode 100644
index 0000000..c2f7d2f
--- /dev/null
+++ b/html/sinfo__new__dark_8h_source.html
@@ -0,0 +1,80 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_new_dark.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_new_dark.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#ifndef SINFO_NEW_DARK_H</span>
+<a name="l00002"></a>00002 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_NEW_DARK_H</span>
+<a name="l00003"></a>00003 <span class="preprocessor"></span><span class="comment">/*</span>
+<a name="l00004"></a>00004 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00005"></a>00005 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00006"></a>00006 <span class="comment"> *</span>
+<a name="l00007"></a>00007 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00008"></a>00008 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00009"></a>00009 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00010"></a>00010 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00011"></a>00011 <span class="comment"> *</span>
+<a name="l00012"></a>00012 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00013"></a>00013 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00014"></a>00014 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00015"></a>00015 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00016"></a>00016 <span class="comment"> *</span>
+<a name="l00017"></a>00017 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00018"></a>00018 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00019"></a>00019 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00020"></a>00020 <span class="comment"> */</span>
+<a name="l00021"></a>00021 <span class="comment">/*****************************************************************************</span>
+<a name="l00022"></a>00022 <span class="comment">* E.S.O. - VLT project</span>
+<a name="l00023"></a>00023 <span class="comment">*</span>
+<a name="l00024"></a>00024 <span class="comment">* "@(#) $Id: sinfo_new_dark.h,v 1.6 2007/06/06 07:10:45 amodigli Exp $"</span>
+<a name="l00025"></a>00025 <span class="comment">*</span>
+<a name="l00026"></a>00026 <span class="comment">* who       when      what</span>
+<a name="l00027"></a>00027 <span class="comment">* --------  --------  ----------------------------------------------</span>
+<a name="l00028"></a>00028 <span class="comment">* amodigli  17/09/03  created</span>
+<a name="l00029"></a>00029 <span class="comment">*/</span>
+<a name="l00030"></a>00030 
+<a name="l00031"></a>00031 <span class="comment">/************************************************************************</span>
+<a name="l00032"></a>00032 <span class="comment"> * sinfo_dark.h</span>
+<a name="l00033"></a>00033 <span class="comment"> * routines to create a master sinfo_dark</span>
+<a name="l00034"></a>00034 <span class="comment"> *----------------------------------------------------------------------</span>
+<a name="l00035"></a>00035 <span class="comment"> */</span>
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="comment">/*</span>
+<a name="l00038"></a>00038 <span class="comment"> * header files</span>
+<a name="l00039"></a>00039 <span class="comment"> */</span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include <cpl.h></span>    
+<a name="l00041"></a>00041 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00042"></a>00042 <span class="comment">/*@-skipposixheaders@*/</span>
+<a name="l00043"></a>00043 <span class="comment">/*@=skipposixheaders@*/</span>
+<a name="l00044"></a>00044 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00045"></a>00045 <span class="comment"> *                        Function ANSI C prototypes</span>
+<a name="l00046"></a>00046 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00047"></a>00047 
+<a name="l00048"></a>00048 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00049"></a>00049 <span class="comment">   @name cpl_dark()</span>
+<a name="l00050"></a>00050 <span class="comment">   @param ini_file: file name of according .ini file</span>
+<a name="l00051"></a>00051 <span class="comment">   @param cpl_parameterlist: structure containing recipe's parameters</span>
+<a name="l00052"></a>00052 <span class="comment">   @param cpl_frameset: structure containing recipe's input files</span>
+<a name="l00053"></a>00053 <span class="comment">   @result integer (0 if it worked, -1 if it doesn't) </span>
+<a name="l00054"></a>00054 <span class="comment">   @doc Sorts frames according to integration time</span>
+<a name="l00055"></a>00055 <span class="comment">        Take the clean mean of a stack of frames with the same</span>
+<a name="l00056"></a>00056 <span class="comment">        integration time</span>
+<a name="l00057"></a>00057 <span class="comment"></span>
+<a name="l00058"></a>00058 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00059"></a>00059 <span class="keywordtype">int</span> 
+<a name="l00060"></a>00060 sinfo_new_dark (<span class="keyword">const</span> <span class="keywordtype">char</span>* plugin_id, cpl_parameterlist* config, 
+<a name="l00061"></a>00061           cpl_frameset* <span class="keyword">set</span>, <span class="keywordtype">char</span>* dark_name);
+<a name="l00062"></a>00062 <span class="preprocessor">#endif </span>
+<a name="l00063"></a>00063 <span class="preprocessor"></span>
+<a name="l00064"></a>00064 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__new__find__distortions_8c_source.html b/html/sinfo__new__find__distortions_8c_source.html
new file mode 100644
index 0000000..72d0768
--- /dev/null
+++ b/html/sinfo__new__find__distortions_8c_source.html
@@ -0,0 +1,766 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_new_find_distortions.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_new_find_distortions.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment"></span>
+<a name="l00021"></a>00021 <span class="comment">   File name    :       sinfo_find_distortions.c</span>
+<a name="l00022"></a>00022 <span class="comment">   Author       :    A. Modigliani</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on   :    Aug 12, 2004</span>
+<a name="l00024"></a>00024 <span class="comment">   Description  :</span>
+<a name="l00025"></a>00025 <span class="comment"></span>
+<a name="l00026"></a>00026 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00027"></a>00027 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00029"></a>00029 <span class="preprocessor">#endif</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span><span class="preprocessor">#include <sinfo_cpl_size.h></span>
+<a name="l00031"></a>00031 
+<a name="l00032"></a>00032 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                                Includes</span>
+<a name="l00034"></a>00034 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 
+<a name="l00036"></a>00036 <span class="preprocessor">#include "sinfo_new_find_distortions.h"</span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include "sinfo_pro_save.h"</span>
+<a name="l00038"></a>00038 <span class="preprocessor">#include "sinfo_pro_types.h"</span>
+<a name="l00039"></a>00039 <span class="preprocessor">#include "sinfo_finddist_ini_by_cpl.h"</span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include "sinfo_wave_calibration.h"</span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include "sinfo_cube_construct.h"</span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include "sinfo_absolute.h"</span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include "sinfo_distortion.h"</span>
+<a name="l00044"></a>00044 <span class="preprocessor">#include "sinfo_utilities.h"</span>
+<a name="l00045"></a>00045 <span class="preprocessor">#include "sinfo_recipes.h"</span>
+<a name="l00046"></a>00046 <span class="preprocessor">#include "sinfo_utils_wrappers.h"</span>
+<a name="l00047"></a>00047 <span class="preprocessor">#include "sinfo_error.h"</span>
+<a name="l00048"></a>00048 <span class="preprocessor">#include "sinfo_globals.h"</span>
+<a name="l00049"></a>00049 
+<a name="l00050"></a>00050 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00051"></a>00051 <span class="comment">                                Defines</span>
+<a name="l00052"></a>00052 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00053"></a>00053 <span class="preprocessor">#define SINFO_ARC_SATURATION                 100000</span>
+<a name="l00054"></a>00054 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_ARC_MAX_WIDTH                  64</span>
+<a name="l00055"></a>00055 <span class="preprocessor"></span>
+<a name="l00056"></a>00056 
+<a name="l00065"></a>00065 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00066"></a>00066 <span class="comment">                             Function Definitions</span>
+<a name="l00067"></a>00067 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00068"></a>00068 
+<a name="l00069"></a>00069 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00070"></a>00070 <span class="comment">   Function     :       sinfo_find_distortions()</span>
+<a name="l00071"></a>00071 <span class="comment">   In           :</span>
+<a name="l00072"></a>00072 <span class="comment">   Out          :</span>
+<a name="l00073"></a>00073 <span class="comment">   Job          :</span>
+<a name="l00074"></a>00074 <span class="comment"></span>
+<a name="l00075"></a>00075 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00076"></a>00076 <span class="keyword">static</span> <span class="keywordtype">double</span>
+<a name="l00077"></a>00077 new_compute_shift(<span class="keywordtype">double</span> x,
+<a name="l00078"></a>00078           <span class="keywordtype">double</span> y,
+<a name="l00079"></a>00079           <span class="keywordtype">double</span> c00,
+<a name="l00080"></a>00080           <span class="keywordtype">double</span> c10,
+<a name="l00081"></a>00081           <span class="keywordtype">double</span> c01,
+<a name="l00082"></a>00082           <span class="keywordtype">double</span> c11,
+<a name="l00083"></a>00083           <span class="keywordtype">double</span> c20,
+<a name="l00084"></a>00084           <span class="keywordtype">double</span> c02,
+<a name="l00085"></a>00085           <span class="keywordtype">double</span> c21,
+<a name="l00086"></a>00086           <span class="keywordtype">double</span> c12,
+<a name="l00087"></a>00087           <span class="keywordtype">double</span> c30,
+<a name="l00088"></a>00088           <span class="keywordtype">double</span> c03);
+<a name="l00089"></a>00089 
+<a name="l00090"></a>00090 <span class="keywordtype">int</span>
+<a name="l00091"></a>00091 sinfo_new_find_distortions(<span class="keyword">const</span> <span class="keywordtype">char</span>* plugin_id,
+<a name="l00092"></a>00092                            cpl_parameterlist* config,
+<a name="l00093"></a>00093                            cpl_frameset* sof,
+<a name="l00094"></a>00094                cpl_frameset* set_fibre_ns)
+<a name="l00095"></a>00095 {
+<a name="l00096"></a>00096 
+<a name="l00097"></a>00097   finddist_config * cfg=NULL ;
+<a name="l00098"></a>00098   cpl_image * imonind=NULL ;
+<a name="l00099"></a>00099   cpl_image * impoly=NULL ;
+<a name="l00100"></a>00100   cpl_image * im=NULL ;
+<a name="l00101"></a>00101   cpl_image *  map=NULL ;
+<a name="l00102"></a>00102   cpl_image *  mask=NULL ;
+<a name="l00103"></a>00103 
+<a name="l00104"></a>00104   <span class="keywordtype">int</span>*            degx=NULL;
+<a name="l00105"></a>00105   <span class="keywordtype">int</span>*            degy=NULL;
+<a name="l00106"></a>00106   <span class="keywordtype">int</span>* n_found_lines=NULL;
+<a name="l00107"></a>00107   <span class="keywordtype">int</span>* sum_pointer=NULL;
+<a name="l00108"></a>00108   <span class="keywordtype">int</span>** row_clean=NULL;
+<a name="l00109"></a>00109   <span class="keywordtype">int</span> pdensity=0;
+<a name="l00110"></a>00110 
+<a name="l00111"></a>00111 
+<a name="l00112"></a>00112   <span class="keywordtype">int</span> x_l=SIZEX/4*1;
+<a name="l00113"></a>00113   <span class="keywordtype">int</span> x_u=SIZEX/4*3;
+<a name="l00114"></a>00114   <span class="keywordtype">int</span> y_l=SIZEY/4*1;
+<a name="l00115"></a>00115   <span class="keywordtype">int</span> y_u=SIZEY/4*3;
+<a name="l00116"></a>00116   <span class="keywordtype">int</span> x_c=SIZEX/4*2;
+<a name="l00117"></a>00117   <span class="keywordtype">int</span> y_c=SIZEY/4*2;
+<a name="l00118"></a>00118   <span class="keyword">const</span> <span class="keywordtype">int</span> pdx=4;
+<a name="l00119"></a>00119   <span class="keyword">const</span> <span class="keywordtype">int</span> pdy=4;
+<a name="l00120"></a>00120   <span class="keywordtype">int</span> check = 0;
+<a name="l00121"></a>00121   <span class="keywordtype">int</span> i = 0;
+<a name="l00122"></a>00122   <span class="keywordtype">int</span> lx=0;
+<a name="l00123"></a>00123   <span class="keywordtype">int</span> ly=0;
+<a name="l00124"></a>00124 
+<a name="l00125"></a>00125 
+<a name="l00126"></a>00126   <span class="keywordtype">int</span> sum=0;
+<a name="l00127"></a>00127   <span class="keywordtype">int</span> n_lines=0;
+<a name="l00128"></a>00128   <span class="keywordtype">int</span> fit=0;
+<a name="l00129"></a>00129   <span class="keywordtype">int</span> n=0;
+<a name="l00130"></a>00130   <span class="keywordtype">int</span> j=0;
+<a name="l00131"></a>00131   cpl_size coef_pow[2];
+<a name="l00132"></a>00132   <span class="keywordtype">int</span> arcs_window_size=0;
+<a name="l00133"></a>00133 
+<a name="l00134"></a>00134   <span class="keywordtype">float</span> value=0;
+<a name="l00135"></a>00135   <span class="keywordtype">float</span> newval=0;
+<a name="l00136"></a>00136   <span class="keywordtype">float</span> total_dist=0;
+<a name="l00137"></a>00137   <span class="keywordtype">float</span> shift=0;
+<a name="l00138"></a>00138 
+<a name="l00139"></a>00139   <span class="keywordtype">float</span>* distances=NULL;
+<a name="l00140"></a>00140   <span class="keywordtype">float</span>** wavelength_clean=NULL;
+<a name="l00141"></a>00141   <span class="keywordtype">float</span>** slit_pos=NULL;
+<a name="l00142"></a>00142   <span class="keywordtype">float</span>** acoefs=NULL;
+<a name="l00143"></a>00143   <span class="keywordtype">float</span>* wave=NULL;
+<a name="l00144"></a>00144   <span class="keywordtype">float</span>* intens=NULL;
+<a name="l00145"></a>00145   <span class="keywordtype">float</span>* first =NULL;
+<a name="l00146"></a>00146 
+<a name="l00147"></a>00147   <span class="keywordtype">double</span>*         coef=NULL;
+<a name="l00148"></a>00148 
+<a name="l00149"></a>00149   <span class="keywordtype">double</span> xshift=0.;
+<a name="l00150"></a>00150   <span class="keywordtype">double</span> arcs_thres_factor=0;
+<a name="l00151"></a>00151 
+<a name="l00152"></a>00152   <span class="keywordtype">double</span> arcs_min_arclen_factor=0;
+<a name="l00153"></a>00153   <span class="keywordtype">double</span> pcf[pdx][pdy];
+<a name="l00154"></a>00154 
+<a name="l00155"></a>00155 
+<a name="l00156"></a>00156   <span class="keywordtype">char</span> tbl_name[FILE_NAME_SZ];
+<a name="l00157"></a>00157   <span class="keywordtype">char</span> key_name[FILE_NAME_SZ];
+<a name="l00158"></a>00158 
+<a name="l00159"></a>00159   cpl_table* poly_tbl=NULL;
+<a name="l00160"></a>00160   cpl_table* tbl_spos=NULL;
+<a name="l00161"></a>00161   cpl_table* tbl_line_list=NULL;
+<a name="l00162"></a>00162 
+<a name="l00163"></a>00163   FitParams** par=NULL;
+<a name="l00164"></a>00164 
+<a name="l00165"></a>00165   cpl_frameset* stk=NULL;
+<a name="l00166"></a>00166   cpl_table* qclog_tbl=NULL;
+<a name="l00167"></a>00167 
+<a name="l00168"></a>00168   cpl_polynomial* distor_poly=NULL;
+<a name="l00169"></a>00169   cpl_apertures       *   arcs=NULL ;
+<a name="l00170"></a>00170   cpl_parameter* p=NULL;
+<a name="l00171"></a>00171   <span class="keywordtype">int</span> smooth_rad=0;
+<a name="l00172"></a>00172 
+<a name="l00173"></a>00173 
+<a name="l00174"></a>00174   check_nomsg(p=cpl_parameterlist_find(config,<span class="stringliteral">"sinfoni.product.density"</span>));
+<a name="l00175"></a>00175   check_nomsg(pdensity=cpl_parameter_get_int(p));
+<a name="l00176"></a>00176 
+<a name="l00177"></a>00177   <span class="comment">/*</span>
+<a name="l00178"></a>00178 <span class="comment">    parse the file names and parameters to the finddist_config</span>
+<a name="l00179"></a>00179 <span class="comment">    data structure cfg</span>
+<a name="l00180"></a>00180 <span class="comment">   */</span>
+<a name="l00181"></a>00181   check_nomsg(stk=cpl_frameset_new());
+<a name="l00182"></a>00182   cknull(cfg = sinfo_parse_cpl_input_finddist(config,sof,&stk),
+<a name="l00183"></a>00183      <span class="stringliteral">"could not parse CPL input!"</span>);
+<a name="l00184"></a>00184 
+<a name="l00185"></a>00185   <span class="keywordflow">if</span>(sinfo_is_fits_file (cfg->inFrame) != 1) {
+<a name="l00186"></a>00186     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Input file %s is not FITS"</span>,cfg->inFrame);
+<a name="l00187"></a>00187     <span class="keywordflow">goto</span> cleanup;
+<a name="l00188"></a>00188   }
+<a name="l00189"></a>00189 
+<a name="l00190"></a>00190   <span class="comment">/* load the emission line frame--- */</span>
+<a name="l00191"></a>00191   check(im = cpl_image_load(cfg->inFrame,CPL_TYPE_FLOAT,0,0),
+<a name="l00192"></a>00192     <span class="stringliteral">"could not load arc image"</span>);
+<a name="l00193"></a>00193 
+<a name="l00194"></a>00194   <span class="comment">/* load the fake on - fake off frame--- */</span>
+<a name="l00195"></a>00195   check(imonind = cpl_image_load(cfg->nsFrame,CPL_TYPE_FLOAT,0,0),
+<a name="l00196"></a>00196     <span class="stringliteral">"could not load on-off fake image"</span>);
+<a name="l00197"></a>00197 
+<a name="l00198"></a>00198   check(impoly  = cpl_image_load(cfg->nsFrame,CPL_TYPE_FLOAT,0,0),
+<a name="l00199"></a>00199     <span class="stringliteral">"could not load on-off fake image"</span>);
+<a name="l00200"></a>00200 
+<a name="l00201"></a>00201   <span class="comment">/* load the fake on - fake off frame--- */</span>
+<a name="l00202"></a>00202   check(mask = cpl_image_load(cfg->mask,CPL_TYPE_FLOAT,0,0),
+<a name="l00203"></a>00203     <span class="stringliteral">"could not load mask image"</span>);
+<a name="l00204"></a>00204 
+<a name="l00205"></a>00205   check(cpl_image_multiply (im,mask),
+<a name="l00206"></a>00206     <span class="stringliteral">"Failing to correct arc ima by bp mask"</span>);
+<a name="l00207"></a>00207 
+<a name="l00208"></a>00208   check(cpl_image_multiply (imonind,mask),
+<a name="l00209"></a>00209     <span class="stringliteral">"Failing to correct on-off fake ima by bp mask"</span>);
+<a name="l00210"></a>00210 
+<a name="l00211"></a>00211   check(cpl_image_multiply(impoly,mask),
+<a name="l00212"></a>00212     <span class="stringliteral">"Failing to correct on-off fake ima by bp mask"</span>);
+<a name="l00213"></a>00213 
+<a name="l00214"></a>00214   sinfo_free_image(&mask);
+<a name="l00215"></a>00215 
+<a name="l00216"></a>00216   check_nomsg(lx = cpl_image_get_size_x(im));
+<a name="l00217"></a>00217   check_nomsg(ly = cpl_image_get_size_y(im));
+<a name="l00218"></a>00218   <span class="comment">/* TO BE CHENGED THE FOLLOWING INPUT */</span>
+<a name="l00219"></a>00219   <span class="comment">/* open the line list and read the number of lines */</span>
+<a name="l00220"></a>00220   check(tbl_line_list = cpl_table_load(cfg->lineList,1,0),
+<a name="l00221"></a>00221     <span class="stringliteral">"problems loading table %s"</span>,cfg->lineList);
+<a name="l00222"></a>00222 
+<a name="l00223"></a>00223   check_nomsg(n_lines = cpl_table_get_nrow(tbl_line_list));
+<a name="l00224"></a>00224   check_nomsg(wave=cpl_table_get_data_float(tbl_line_list,<span class="stringliteral">"wave"</span>));
+<a name="l00225"></a>00225   check_nomsg(intens = cpl_table_get_data_float(tbl_line_list,<span class="stringliteral">"int"</span>));
+<a name="l00226"></a>00226 
+<a name="l00227"></a>00227   <span class="comment">/*</span>
+<a name="l00228"></a>00228 <span class="comment">       #---------------------------------------------------------------------</span>
+<a name="l00229"></a>00229 <span class="comment">       #---------------------------FINDLINES---------------------------------</span>
+<a name="l00230"></a>00230 <span class="comment">       #---------------------------------------------------------------------</span>
+<a name="l00231"></a>00231 <span class="comment">  */</span>
+<a name="l00232"></a>00232 
+<a name="l00233"></a>00233   sinfo_msg(<span class="stringliteral">"Find Lines"</span>);
+<a name="l00234"></a>00234   <span class="comment">/*</span>
+<a name="l00235"></a>00235 <span class="comment">       do the wavelength calibration, that means:</span>
+<a name="l00236"></a>00236 <span class="comment">       find the dispersion relation and parameterize its coefficients</span>
+<a name="l00237"></a>00237 <span class="comment">  */</span>
+<a name="l00238"></a>00238 
+<a name="l00239"></a>00239   acoefs  = sinfo_new_2Dfloatarray(cfg->nrDispCoefficients, lx);
+<a name="l00240"></a>00240   <span class="comment">/* allocate memory */</span>
+<a name="l00241"></a>00241   n_found_lines    = sinfo_new_intarray(lx);
+<a name="l00242"></a>00242   row_clean        = sinfo_new_2Dintarray(lx, n_lines);
+<a name="l00243"></a>00243   wavelength_clean = sinfo_new_2Dfloatarray(lx, n_lines);
+<a name="l00244"></a>00244   sum_pointer      = sinfo_new_intarray(1);
+<a name="l00245"></a>00245 
+<a name="l00246"></a>00246   <span class="comment">/* find the emission lines in each image column */</span>
+<a name="l00247"></a>00247   sinfo_new_intarray_set_value(sum_pointer, 0, 0);
+<a name="l00248"></a>00248 
+<a name="l00249"></a>00249   ck0(check = sinfo_new_find_lines(im,
+<a name="l00250"></a>00250                    wave,
+<a name="l00251"></a>00251                    intens,
+<a name="l00252"></a>00252                    n_lines,
+<a name="l00253"></a>00253                    row_clean,
+<a name="l00254"></a>00254                    wavelength_clean,
+<a name="l00255"></a>00255                    cfg->guessBeginWavelength,
+<a name="l00256"></a>00256                    cfg->guessDispersion1,
+<a name="l00257"></a>00257                    cfg->guessDispersion2,
+<a name="l00258"></a>00258                    cfg->mindiff,
+<a name="l00259"></a>00259                    cfg->halfWidth,
+<a name="l00260"></a>00260                    n_found_lines,
+<a name="l00261"></a>00261                    cfg->sigma,
+<a name="l00262"></a>00262                    sum_pointer ),
+<a name="l00263"></a>00263       <span class="stringliteral">"FindLines failed!"</span>);
+<a name="l00264"></a>00264 
+<a name="l00265"></a>00265   sinfo_free_table(&tbl_line_list);
+<a name="l00266"></a>00266 
+<a name="l00267"></a>00267   <span class="comment">/*</span>
+<a name="l00268"></a>00268 <span class="comment">   #-------------------------------------------------------------------------</span>
+<a name="l00269"></a>00269 <span class="comment">   #---------------------------WAVECALIB-------------------------------------</span>
+<a name="l00270"></a>00270 <span class="comment">   #-------------------------------------------------------------------------</span>
+<a name="l00271"></a>00271 <span class="comment">    */</span>
+<a name="l00272"></a>00272   sinfo_msg(<span class="stringliteral">"Do wave calib"</span>);
+<a name="l00273"></a>00273   sum = sinfo_new_intarray_get_value(sum_pointer,0);
+<a name="l00274"></a>00274 
+<a name="l00275"></a>00275   <span class="comment">/* #allocate memory for the fit parameters */</span>
+<a name="l00276"></a>00276   cknull(par = sinfo_new_fit_params( sum ),
+<a name="l00277"></a>00277      <span class="stringliteral">"sinfo_new_fit_params failed!"</span>);
+<a name="l00278"></a>00278 
+<a name="l00279"></a>00279   <span class="comment">/*</span>
+<a name="l00280"></a>00280 <span class="comment">      fit each line, make a polynomial fit and fit the resulting fit</span>
+<a name="l00281"></a>00281 <span class="comment">       coefficients across the columns of the slitlet</span>
+<a name="l00282"></a>00282 <span class="comment">  */</span>
+<a name="l00283"></a>00283   cknull(map = sinfo_new_wave_cal(im,
+<a name="l00284"></a>00284                              par,
+<a name="l00285"></a>00285                       acoefs,
+<a name="l00286"></a>00286                       cfg->nslitlets,
+<a name="l00287"></a>00287                       row_clean,
+<a name="l00288"></a>00288                       wavelength_clean,
+<a name="l00289"></a>00289                       n_found_lines,
+<a name="l00290"></a>00290                       cfg->guessDispersion1,
+<a name="l00291"></a>00291                       cfg->halfWidth,
+<a name="l00292"></a>00292                       cfg->minAmplitude,
+<a name="l00293"></a>00293                       cfg->maxResidual,
+<a name="l00294"></a>00294                       cfg->fwhm,
+<a name="l00295"></a>00295                       cfg->nrDispCoefficients,
+<a name="l00296"></a>00296                       cfg->nrCoefCoefficients,
+<a name="l00297"></a>00297                       cfg->sigmaFactor,
+<a name="l00298"></a>00298                       cfg->pixeldist,
+<a name="l00299"></a>00299                       cfg->pixel_tolerance),
+<a name="l00300"></a>00300      <span class="stringliteral">"sinfo_waveCal failed!"</span>);
+<a name="l00301"></a>00301   <span class="comment">/* here mem leak */</span>
+<a name="l00302"></a>00302 
+<a name="l00303"></a>00303   sinfo_msg(<span class="stringliteral">"Check line positions"</span>);
+<a name="l00304"></a>00304   shift = sinfo_new_check_line_positions (im, acoefs,
+<a name="l00305"></a>00305                                           cfg->nrDispCoefficients,
+<a name="l00306"></a>00306                                           cfg->guessDispersion1,par);
+<a name="l00307"></a>00307 
+<a name="l00308"></a>00308   <span class="keywordflow">if</span> (FLAG == shift) {
+<a name="l00309"></a>00309     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> ( <span class="stringliteral">"checkForLinePositions failed!"</span>);
+<a name="l00310"></a>00310     <span class="keywordflow">goto</span> cleanup;
+<a name="l00311"></a>00311   }
+<a name="l00312"></a>00312   sinfo_free_image(&map);
+<a name="l00313"></a>00313 
+<a name="l00314"></a>00314 
+<a name="l00315"></a>00315  <span class="comment">/* free memory */</span>
+<a name="l00316"></a>00316   sinfo_new_destroy_2Dfloatarray ( &wavelength_clean, lx );
+<a name="l00317"></a>00317   sinfo_new_destroy_2Dintarray (&row_clean, lx);
+<a name="l00318"></a>00318   sinfo_new_destroy_intarray(&n_found_lines );
+<a name="l00319"></a>00319   sinfo_new_destroy_intarray(&sum_pointer );
+<a name="l00320"></a>00320   sinfo_new_destroy_2Dfloatarray ( &acoefs, cfg->nrDispCoefficients );
+<a name="l00321"></a>00321   <span class="comment">/*</span>
+<a name="l00322"></a>00322 <span class="comment">  sinfo_new_destroy_array (& wave );</span>
+<a name="l00323"></a>00323 <span class="comment">  sinfo_new_destroy_array (& intens );</span>
+<a name="l00324"></a>00324 <span class="comment">  */</span>
+<a name="l00325"></a>00325   <span class="comment">/*</span>
+<a name="l00326"></a>00326 <span class="comment">  #----------------------------------------------------------------------------</span>
+<a name="l00327"></a>00327 <span class="comment">  #-------------------------SLITFITS-------------------------------------------</span>
+<a name="l00328"></a>00328 <span class="comment">  #----------------------------------------------------------------------------</span>
+<a name="l00329"></a>00329 <span class="comment">  #--fit the slitlet sinfo_edge positions if desired--</span>
+<a name="l00330"></a>00330 <span class="comment">  */</span>
+<a name="l00331"></a>00331 
+<a name="l00332"></a>00332   sinfo_msg(<span class="stringliteral">"Find slit pos"</span>);
+<a name="l00333"></a>00333   <span class="comment">/*allocate memory for the slitlet position array */</span>
+<a name="l00334"></a>00334   slit_pos = sinfo_new_2Dfloatarray(32,2);
+<a name="l00335"></a>00335 
+<a name="l00336"></a>00336   fit = <a class="code" href="group__sinfo__boltzmann.html#gab3549f7bb876fb4091ba3c0bd64d267d" title="fits the beginning and end position of the slitlets by using non-linear least square...">sinfo_new_fit_slits_boltz</a>( im, par, slit_pos, cfg->boxLength,
+<a name="l00337"></a>00337                       cfg->yBox, cfg->diffTol );
+<a name="l00338"></a>00338 
+<a name="l00339"></a>00339 
+<a name="l00340"></a>00340   <span class="keywordflow">if</span> (fit < 0) {
+<a name="l00341"></a>00341     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>( <span class="stringliteral">"sinfo_fitSlitsBoltz failed"</span> );
+<a name="l00342"></a>00342     <span class="keywordflow">goto</span> cleanup;
+<a name="l00343"></a>00343   }
+<a name="l00344"></a>00344   sinfo_new_destroy_fit_params(&par);
+<a name="l00345"></a>00345 
+<a name="l00346"></a>00346   check_nomsg(tbl_spos=cpl_table_new(32));
+<a name="l00347"></a>00347   check_nomsg(cpl_table_new_column(tbl_spos,<span class="stringliteral">"pos1"</span>, CPL_TYPE_DOUBLE));
+<a name="l00348"></a>00348   check_nomsg(cpl_table_new_column(tbl_spos,<span class="stringliteral">"pos2"</span>, CPL_TYPE_DOUBLE));
+<a name="l00349"></a>00349   check_nomsg(cpl_table_set_column_format(tbl_spos,<span class="stringliteral">"pos1"</span>, <span class="stringliteral">"15.9f"</span>));
+<a name="l00350"></a>00350   check_nomsg(cpl_table_set_column_format(tbl_spos,<span class="stringliteral">"pos2"</span>, <span class="stringliteral">"15.9f"</span>));
+<a name="l00351"></a>00351 
+<a name="l00352"></a>00352   <span class="keywordflow">for</span> (i =0; i< 32; i++) {
+<a name="l00353"></a>00353       check_nomsg(cpl_table_set_double(tbl_spos,<span class="stringliteral">"pos1"</span>,i,
+<a name="l00354"></a>00354                                 sinfo_new_array2D_get_value(slit_pos,i,0)));
+<a name="l00355"></a>00355       check_nomsg(cpl_table_set_double(tbl_spos,<span class="stringliteral">"pos2"</span>,i,
+<a name="l00356"></a>00356                                 sinfo_new_array2D_get_value(slit_pos,i,1)));
+<a name="l00357"></a>00357 
+<a name="l00358"></a>00358   }
+<a name="l00359"></a>00359 
+<a name="l00360"></a>00360   <span class="keywordflow">if</span>(pdensity > 2) {
+<a name="l00361"></a>00361     strcpy(tbl_name,<span class="stringliteral">"out_slitlets_pos_predist.fits"</span>);
+<a name="l00362"></a>00362     ck0(sinfo_pro_save_tbl(tbl_spos,set_fibre_ns,sof,tbl_name,
+<a name="l00363"></a>00363                PRO_SLITLETS_POS_PREDIST,NULL,plugin_id,config),
+<a name="l00364"></a>00364     <span class="stringliteral">"cannot save tbl %s"</span>, tbl_name);
+<a name="l00365"></a>00365   }
+<a name="l00366"></a>00366   sinfo_free_table(&tbl_spos);
+<a name="l00367"></a>00367 
+<a name="l00368"></a>00368   <span class="comment">/*</span>
+<a name="l00369"></a>00369 <span class="comment">  #---------------------------------------------------------</span>
+<a name="l00370"></a>00370 <span class="comment">  # do the north - south - test</span>
+<a name="l00371"></a>00371 <span class="comment">  #---------------------------------------------------------</span>
+<a name="l00372"></a>00372 <span class="comment">  */</span>
+<a name="l00373"></a>00373   sinfo_msg(<span class="stringliteral">"Do north south test"</span>);
+<a name="l00374"></a>00374   <span class="comment">/*</span>
+<a name="l00375"></a>00375 <span class="comment">  sinfo_msg("cfg->nslits =%d\n", cfg->nslits);</span>
+<a name="l00376"></a>00376 <span class="comment">  sinfo_msg("cfg->nshalfWidth =%d\n", cfg->nshalfWidth);</span>
+<a name="l00377"></a>00377 <span class="comment">  sinfo_msg("cfg->nsfwhm=%f\n",cfg->nsfwhm );</span>
+<a name="l00378"></a>00378 <span class="comment">  sinfo_msg("cfg->minDiff=%f\n", cfg->minDiff);</span>
+<a name="l00379"></a>00379 <span class="comment">  sinfo_msg("cfg->estimated_dist=%f\n", cfg->estimated_dist);</span>
+<a name="l00380"></a>00380 <span class="comment">  sinfo_msg("cfg->devtol=%f\n", cfg->devtol);</span>
+<a name="l00381"></a>00381 <span class="comment">  sinfo_msg("cfg->loPos=%d\n", cfg->loPos);</span>
+<a name="l00382"></a>00382 <span class="comment">  sinfo_msg("cfg->hiPos=%d\n",cfg->hiPos);</span>
+<a name="l00383"></a>00383 <span class="comment">  */</span>
+<a name="l00384"></a>00384   cknull(distances = sinfo_north_south_test(imonind,
+<a name="l00385"></a>00385                       cfg->nslits,
+<a name="l00386"></a>00386                       cfg->nshalfWidth,
+<a name="l00387"></a>00387                       cfg->nsfwhm ,
+<a name="l00388"></a>00388                       cfg->minDiff,
+<a name="l00389"></a>00389                       cfg->estimated_dist,
+<a name="l00390"></a>00390                       cfg->devtol,
+<a name="l00391"></a>00391                       cfg->loPos,
+<a name="l00392"></a>00392                       cfg->hiPos),
+<a name="l00393"></a>00393      <span class="stringliteral">"north_south_test failed"</span>);
+<a name="l00394"></a>00394 
+<a name="l00395"></a>00395   sinfo_free_image(&imonind);
+<a name="l00396"></a>00396 
+<a name="l00397"></a>00397   <span class="comment">/*</span>
+<a name="l00398"></a>00398 <span class="comment">  #---------------------------------------------------------</span>
+<a name="l00399"></a>00399 <span class="comment">  # get firstcol</span>
+<a name="l00400"></a>00400 <span class="comment">  #---------------------------------------------------------</span>
+<a name="l00401"></a>00401 <span class="comment">  */</span>
+<a name="l00402"></a>00402   sinfo_msg(<span class="stringliteral">"get first col"</span>);
+<a name="l00403"></a>00403   first = sinfo_new_floatarray(61);
+<a name="l00404"></a>00404   total_dist=0;
+<a name="l00405"></a>00405   n=0;
+<a name="l00406"></a>00406 
+<a name="l00407"></a>00407   <span class="keywordflow">for</span> (i=0; i< 31; i++) {
+<a name="l00408"></a>00408     total_dist=total_dist+sinfo_new_array_get_value(distances,i);
+<a name="l00409"></a>00409 
+<a name="l00410"></a>00410     <span class="keywordflow">for</span> (j=0; j< 2; j++) {
+<a name="l00411"></a>00411       <span class="keywordflow">if</span> (j == 0) {
+<a name="l00412"></a>00412         <span class="keywordflow">if</span> (i != 30) {
+<a name="l00413"></a>00413       newval = sinfo_new_array2D_get_value(slit_pos,i+1,j) - total_dist;
+<a name="l00414"></a>00414       sinfo_new_array_set_value(first, newval, n);
+<a name="l00415"></a>00415       n = n+1;
+<a name="l00416"></a>00416         }
+<a name="l00417"></a>00417       }
+<a name="l00418"></a>00418       <span class="keywordflow">if</span> (j == 1) {
+<a name="l00419"></a>00419         newval = sinfo_new_array2D_get_value(slit_pos,i,j) - total_dist;
+<a name="l00420"></a>00420         sinfo_new_array_set_value(first, newval, n);
+<a name="l00421"></a>00421         n = n+1;
+<a name="l00422"></a>00422       }
+<a name="l00423"></a>00423     }
+<a name="l00424"></a>00424   }
+<a name="l00425"></a>00425   value = sinfo_new_f_median(first,61);
+<a name="l00426"></a>00426   sinfo_msg(<span class="stringliteral">"Firstcol =%f"</span>, value);
+<a name="l00427"></a>00427   sinfo_new_destroy_array(&first);
+<a name="l00428"></a>00428   sinfo_new_destroy_array(&distances);
+<a name="l00429"></a>00429   sinfo_new_destroy_2Dfloatarray ( &slit_pos, 32 );
+<a name="l00430"></a>00430 
+<a name="l00431"></a>00431   <span class="comment">/*</span>
+<a name="l00432"></a>00432 <span class="comment">  #---------------------------------------------------------</span>
+<a name="l00433"></a>00433 <span class="comment">  # Determine distortions</span>
+<a name="l00434"></a>00434 <span class="comment">  #---------------------------------------------------------</span>
+<a name="l00435"></a>00435 <span class="comment">  */</span>
+<a name="l00436"></a>00436   sinfo_msg(<span class="stringliteral">"Determine distortions"</span>);
+<a name="l00437"></a>00437   degx=cpl_calloc(8,<span class="keyword">sizeof</span>(<span class="keywordtype">int</span>));
+<a name="l00438"></a>00438   degy=cpl_calloc(8,<span class="keyword">sizeof</span>(<span class="keywordtype">int</span>));
+<a name="l00439"></a>00439   coef=cpl_calloc(8,<span class="keyword">sizeof</span>(<span class="keywordtype">double</span>));
+<a name="l00440"></a>00440 
+<a name="l00441"></a>00441   check_nomsg(p=cpl_parameterlist_find(config,
+<a name="l00442"></a>00442                 <span class="stringliteral">"sinfoni.distortion.arcs_thresh_factor"</span>));
+<a name="l00443"></a>00443   check_nomsg(arcs_thres_factor=cpl_parameter_get_double(p));
+<a name="l00444"></a>00444 
+<a name="l00445"></a>00445   check_nomsg(p=cpl_parameterlist_find(config,
+<a name="l00446"></a>00446                 <span class="stringliteral">"sinfoni.distortion.arcs_min_arclen_factor"</span>));
+<a name="l00447"></a>00447   check_nomsg(arcs_min_arclen_factor=cpl_parameter_get_double(p));
+<a name="l00448"></a>00448 
+<a name="l00449"></a>00449   check_nomsg(p=cpl_parameterlist_find(config,
+<a name="l00450"></a>00450                 <span class="stringliteral">"sinfoni.distortion.arcs_window_size"</span>));
+<a name="l00451"></a>00451   check_nomsg(arcs_window_size=cpl_parameter_get_int(p));
+<a name="l00452"></a>00452 
+<a name="l00453"></a>00453   check_nomsg(p=cpl_parameterlist_find(config,
+<a name="l00454"></a>00454                 <span class="stringliteral">"sinfoni.distortion.smooth_rad"</span>));
+<a name="l00455"></a>00455   check_nomsg(smooth_rad=cpl_parameter_get_int(p));
+<a name="l00456"></a>00456 
+<a name="l00457"></a>00457 
+<a name="l00458"></a>00458   cknull(distor_poly=sinfo_distortion_estimate_new(impoly,
+<a name="l00459"></a>00459                            0,
+<a name="l00460"></a>00460                            0,
+<a name="l00461"></a>00461                                                  cpl_image_get_size_x(impoly),
+<a name="l00462"></a>00462                                                  cpl_image_get_size_y(impoly),
+<a name="l00463"></a>00463                                                    FALSE,
+<a name="l00464"></a>00464                                                    SINFO_ARC_SATURATION,
+<a name="l00465"></a>00465                                                    SINFO_ARC_MAX_WIDTH,
+<a name="l00466"></a>00466                                                    arcs_thres_factor,
+<a name="l00467"></a>00467                                                    arcs_min_arclen_factor,
+<a name="l00468"></a>00468                                                    arcs_window_size,
+<a name="l00469"></a>00469                                                    smooth_rad,
+<a name="l00470"></a>00470                                                    3,
+<a name="l00471"></a>00471                                                    (<span class="keywordtype">double</span>)value,
+<a name="l00472"></a>00472                                                    &arcs),
+<a name="l00473"></a>00473      <span class="stringliteral">"cannot estimage distortion"</span>) ;
+<a name="l00474"></a>00474   <span class="comment">/*AMo: additional mem leaks */</span>
+<a name="l00475"></a>00475 
+<a name="l00476"></a>00476   sinfo_free_apertures(&arcs);
+<a name="l00477"></a>00477   coef_pow[0]=0;
+<a name="l00478"></a>00478   coef_pow[1]=0;
+<a name="l00479"></a>00479   check_nomsg(pcf[0][0]=cpl_polynomial_get_coeff(distor_poly,coef_pow));
+<a name="l00480"></a>00480   sinfo_msg(<span class="stringliteral">"Polynomial fit results: coeff[%d][%d]=%g"</span>,0,0,pcf[0][0]);
+<a name="l00481"></a>00481   <span class="comment">/*</span>
+<a name="l00482"></a>00482 <span class="comment">  pcf[0][0]+=value;</span>
+<a name="l00483"></a>00483 <span class="comment">  */</span>
+<a name="l00484"></a>00484   sinfo_msg(<span class="stringliteral">"Polynomial fit results: coeff[%d][%d]=%g"</span>,0,0,pcf[0][0]);
+<a name="l00485"></a>00485   check_nomsg(cpl_polynomial_set_coeff(distor_poly,coef_pow,pcf[0][0]));
+<a name="l00486"></a>00486 
+<a name="l00487"></a>00487   <span class="comment">/* up to here ok */</span>
+<a name="l00488"></a>00488   <span class="comment">/* To check mem leaks */</span>
+<a name="l00489"></a>00489   sinfo_free_image(&impoly);
+<a name="l00490"></a>00490 
+<a name="l00491"></a>00491   <span class="comment">//sinfo_msg("Polynomial fit results: deg=%d",</span>
+<a name="l00492"></a>00492   <span class="comment">//      cpl_polynomial_get_degree(distor_poly));</span>
+<a name="l00493"></a>00493 
+<a name="l00494"></a>00494 
+<a name="l00495"></a>00495   coef_pow[0]=0;
+<a name="l00496"></a>00496   coef_pow[1]=0;
+<a name="l00497"></a>00497   check_nomsg(pcf[0][0]=cpl_polynomial_get_coeff(distor_poly,coef_pow));
+<a name="l00498"></a>00498   <span class="comment">//sinfo_msg("Polynomial fit results: coeff[%d][%d]=%g",0,0,pcf[0][0]);</span>
+<a name="l00499"></a>00499 
+<a name="l00500"></a>00500   coef_pow[0]=1;
+<a name="l00501"></a>00501   coef_pow[1]=0;
+<a name="l00502"></a>00502   check_nomsg(pcf[1][0]=cpl_polynomial_get_coeff(distor_poly,coef_pow));
+<a name="l00503"></a>00503   <span class="comment">//sinfo_msg("Polynomial fit results: coeff[%d][%d]=%g",1,0,pcf[1][0]);</span>
+<a name="l00504"></a>00504 
+<a name="l00505"></a>00505   coef_pow[0]=0;
+<a name="l00506"></a>00506   coef_pow[1]=1;
+<a name="l00507"></a>00507   check_nomsg(pcf[0][1]=cpl_polynomial_get_coeff(distor_poly,coef_pow));
+<a name="l00508"></a>00508   <span class="comment">//sinfo_msg("Polynomial fit results: coeff[%d][%d]=%g",0,1,pcf[0][1]);</span>
+<a name="l00509"></a>00509 
+<a name="l00510"></a>00510   coef_pow[0]=1;
+<a name="l00511"></a>00511   coef_pow[1]=1;
+<a name="l00512"></a>00512   check_nomsg(pcf[1][1]=cpl_polynomial_get_coeff(distor_poly,coef_pow));
+<a name="l00513"></a>00513   <span class="comment">//sinfo_msg("Polynomial fit results: coeff[%d][%d]=%g",1,1,pcf[1][1]);</span>
+<a name="l00514"></a>00514 
+<a name="l00515"></a>00515   coef_pow[0]=2;
+<a name="l00516"></a>00516   coef_pow[1]=0;
+<a name="l00517"></a>00517   check_nomsg(pcf[2][0]=cpl_polynomial_get_coeff(distor_poly,coef_pow));
+<a name="l00518"></a>00518   <span class="comment">//sinfo_msg("Polynomial fit results: coeff[%d][%d]=%g",2,0,pcf[2][0]);</span>
+<a name="l00519"></a>00519 
+<a name="l00520"></a>00520   coef_pow[0]=0;
+<a name="l00521"></a>00521   coef_pow[1]=2;
+<a name="l00522"></a>00522   check_nomsg(pcf[0][2]=cpl_polynomial_get_coeff(distor_poly,coef_pow));
+<a name="l00523"></a>00523   <span class="comment">//sinfo_msg("Polynomial fit results: coeff[%d][%d]=%g",0,2,pcf[0][2]);</span>
+<a name="l00524"></a>00524 
+<a name="l00525"></a>00525   coef_pow[0]=2;
+<a name="l00526"></a>00526   coef_pow[1]=1;
+<a name="l00527"></a>00527   check_nomsg(pcf[2][1]=cpl_polynomial_get_coeff(distor_poly,coef_pow));
+<a name="l00528"></a>00528   <span class="comment">//sinfo_msg("Polynomial fit results: coeff[%d][%d]=%g",2,1,pcf[2][1]);</span>
+<a name="l00529"></a>00529 
+<a name="l00530"></a>00530   coef_pow[0]=1;
+<a name="l00531"></a>00531   coef_pow[1]=2;
+<a name="l00532"></a>00532   check_nomsg(pcf[1][2]=cpl_polynomial_get_coeff(distor_poly,coef_pow));
+<a name="l00533"></a>00533   <span class="comment">//sinfo_msg("Polynomial fit results: coeff[%d][%d]=%g",1,2,pcf[1][2]);</span>
+<a name="l00534"></a>00534 
+<a name="l00535"></a>00535   coef_pow[0]=3;
+<a name="l00536"></a>00536   coef_pow[1]=0;
+<a name="l00537"></a>00537   check_nomsg(pcf[3][0]=cpl_polynomial_get_coeff(distor_poly,coef_pow));
+<a name="l00538"></a>00538   <span class="comment">//sinfo_msg("Polynomial fit results: coeff[%d][%d]=%g",3,0,pcf[3][0]);</span>
+<a name="l00539"></a>00539 
+<a name="l00540"></a>00540   coef_pow[0]=0;
+<a name="l00541"></a>00541   coef_pow[1]=3;
+<a name="l00542"></a>00542   check_nomsg(pcf[0][3]=cpl_polynomial_get_coeff(distor_poly,coef_pow));
+<a name="l00543"></a>00543   <span class="comment">//sinfo_msg("Polynomial fit results: coeff[%d][%d]=%g",0,3,pcf[0][3]);</span>
+<a name="l00544"></a>00544 
+<a name="l00545"></a>00545   sinfo_msg(<span class="stringliteral">"Save results"</span>);
+<a name="l00546"></a>00546 
+<a name="l00547"></a>00547   check_nomsg(poly_tbl=cpl_table_new(10));
+<a name="l00548"></a>00548   check_nomsg(cpl_table_new_column(poly_tbl,<span class="stringliteral">"degx"</span>, CPL_TYPE_INT));
+<a name="l00549"></a>00549   check_nomsg(cpl_table_new_column(poly_tbl,<span class="stringliteral">"degy"</span>, CPL_TYPE_INT));
+<a name="l00550"></a>00550   check_nomsg(cpl_table_new_column(poly_tbl,<span class="stringliteral">"coeff"</span>, CPL_TYPE_DOUBLE));
+<a name="l00551"></a>00551   check_nomsg(cpl_table_set_int(poly_tbl,<span class="stringliteral">"degx"</span>,0,0));
+<a name="l00552"></a>00552   check_nomsg(cpl_table_set_int(poly_tbl,<span class="stringliteral">"degx"</span>,1,1));
+<a name="l00553"></a>00553   check_nomsg(cpl_table_set_int(poly_tbl,<span class="stringliteral">"degx"</span>,2,0));
+<a name="l00554"></a>00554   check_nomsg(cpl_table_set_int(poly_tbl,<span class="stringliteral">"degx"</span>,3,1));
+<a name="l00555"></a>00555   check_nomsg(cpl_table_set_int(poly_tbl,<span class="stringliteral">"degx"</span>,4,2));
+<a name="l00556"></a>00556   check_nomsg(cpl_table_set_int(poly_tbl,<span class="stringliteral">"degx"</span>,5,0));
+<a name="l00557"></a>00557   check_nomsg(cpl_table_set_int(poly_tbl,<span class="stringliteral">"degx"</span>,6,2));
+<a name="l00558"></a>00558   check_nomsg(cpl_table_set_int(poly_tbl,<span class="stringliteral">"degx"</span>,7,1));
+<a name="l00559"></a>00559   check_nomsg(cpl_table_set_int(poly_tbl,<span class="stringliteral">"degx"</span>,8,3));
+<a name="l00560"></a>00560   check_nomsg(cpl_table_set_int(poly_tbl,<span class="stringliteral">"degx"</span>,9,0));
+<a name="l00561"></a>00561 
+<a name="l00562"></a>00562   check_nomsg(cpl_table_set_int(poly_tbl,<span class="stringliteral">"degy"</span>,0,0));
+<a name="l00563"></a>00563   check_nomsg(cpl_table_set_int(poly_tbl,<span class="stringliteral">"degy"</span>,1,0));
+<a name="l00564"></a>00564   check_nomsg(cpl_table_set_int(poly_tbl,<span class="stringliteral">"degy"</span>,2,1));
+<a name="l00565"></a>00565   check_nomsg(cpl_table_set_int(poly_tbl,<span class="stringliteral">"degy"</span>,3,1));
+<a name="l00566"></a>00566   check_nomsg(cpl_table_set_int(poly_tbl,<span class="stringliteral">"degy"</span>,4,0));
+<a name="l00567"></a>00567   check_nomsg(cpl_table_set_int(poly_tbl,<span class="stringliteral">"degy"</span>,5,2));
+<a name="l00568"></a>00568   check_nomsg(cpl_table_set_int(poly_tbl,<span class="stringliteral">"degy"</span>,6,1));
+<a name="l00569"></a>00569   check_nomsg(cpl_table_set_int(poly_tbl,<span class="stringliteral">"degy"</span>,7,2));
+<a name="l00570"></a>00570   check_nomsg(cpl_table_set_int(poly_tbl,<span class="stringliteral">"degy"</span>,8,0));
+<a name="l00571"></a>00571   check_nomsg(cpl_table_set_int(poly_tbl,<span class="stringliteral">"degy"</span>,9,3));
+<a name="l00572"></a>00572 
+<a name="l00573"></a>00573   check_nomsg(cpl_table_set_double(poly_tbl,<span class="stringliteral">"coeff"</span>,0,pcf[0][0]));
+<a name="l00574"></a>00574   check_nomsg(cpl_table_set_double(poly_tbl,<span class="stringliteral">"coeff"</span>,1,pcf[1][0]));
+<a name="l00575"></a>00575   check_nomsg(cpl_table_set_double(poly_tbl,<span class="stringliteral">"coeff"</span>,2,pcf[0][1]));
+<a name="l00576"></a>00576   check_nomsg(cpl_table_set_double(poly_tbl,<span class="stringliteral">"coeff"</span>,3,pcf[1][1]));
+<a name="l00577"></a>00577   check_nomsg(cpl_table_set_double(poly_tbl,<span class="stringliteral">"coeff"</span>,4,pcf[2][0]));
+<a name="l00578"></a>00578   check_nomsg(cpl_table_set_double(poly_tbl,<span class="stringliteral">"coeff"</span>,5,pcf[0][2]));
+<a name="l00579"></a>00579   check_nomsg(cpl_table_set_double(poly_tbl,<span class="stringliteral">"coeff"</span>,6,pcf[2][1]));
+<a name="l00580"></a>00580   check_nomsg(cpl_table_set_double(poly_tbl,<span class="stringliteral">"coeff"</span>,7,pcf[1][2]));
+<a name="l00581"></a>00581   check_nomsg(cpl_table_set_double(poly_tbl,<span class="stringliteral">"coeff"</span>,8,pcf[3][0]));
+<a name="l00582"></a>00582   check_nomsg(cpl_table_set_double(poly_tbl,<span class="stringliteral">"coeff"</span>,9,pcf[0][3]));
+<a name="l00583"></a>00583 
+<a name="l00584"></a>00584   <span class="comment">//sinfo_msg("Polynomial distortion coefficients \n");</span>
+<a name="l00585"></a>00585   <span class="comment">//sinfo_msg("c= %g   %g  %g  %g  %g  %g  %g  %g %g %g\n",</span>
+<a name="l00586"></a>00586   <span class="comment">//       pcf[0][0],pcf[1][0],pcf[0][1],pcf[1][1],</span>
+<a name="l00587"></a>00587   <span class="comment">//           pcf[2][0],pcf[0][2],pcf[2][1],pcf[1][2],pcf[3][0],pcf[0][3]);</span>
+<a name="l00588"></a>00588 
+<a name="l00589"></a>00589   <span class="comment">/* QC LOG */</span>
+<a name="l00590"></a>00590   check_nomsg(qclog_tbl = sinfo_qclog_init());
+<a name="l00591"></a>00591   snprintf(key_name,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%d%d"</span>,<span class="stringliteral">"QC COEFF"</span>,0,0);
+<a name="l00592"></a>00592   ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,key_name,pcf[0][0],
+<a name="l00593"></a>00593              <span class="stringliteral">"Polynomial distortion coefficient"</span>,<span class="stringliteral">"%g"</span>));
+<a name="l00594"></a>00594 
+<a name="l00595"></a>00595   snprintf(key_name,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%d%d"</span>,<span class="stringliteral">"QC COEFF"</span>,1,0);
+<a name="l00596"></a>00596   ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,key_name,pcf[1][0],
+<a name="l00597"></a>00597              <span class="stringliteral">"Polynomial distortion coefficient"</span>,<span class="stringliteral">"%g"</span>));
+<a name="l00598"></a>00598 
+<a name="l00599"></a>00599   snprintf(key_name,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%d%d"</span>,<span class="stringliteral">"QC COEFF"</span>,0,1);
+<a name="l00600"></a>00600   ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,key_name,pcf[0][1],
+<a name="l00601"></a>00601              <span class="stringliteral">"Polynomial distortion coefficient"</span>,<span class="stringliteral">"%g"</span>));
+<a name="l00602"></a>00602 
+<a name="l00603"></a>00603   snprintf(key_name,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%d%d"</span>,<span class="stringliteral">"QC COEFF"</span>,1,1);
+<a name="l00604"></a>00604   ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,key_name,pcf[1][1],
+<a name="l00605"></a>00605              <span class="stringliteral">"Polynomial distortion coefficient"</span>,<span class="stringliteral">"%g"</span>));
+<a name="l00606"></a>00606 
+<a name="l00607"></a>00607   snprintf(key_name,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%d%d"</span>,<span class="stringliteral">"QC COEFF"</span>,2,0);
+<a name="l00608"></a>00608   ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,key_name,pcf[2][0],
+<a name="l00609"></a>00609              <span class="stringliteral">"Polynomial distortion coefficient"</span>,<span class="stringliteral">"%g"</span>));
+<a name="l00610"></a>00610 
+<a name="l00611"></a>00611   snprintf(key_name,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%d%d"</span>,<span class="stringliteral">"QC COEFF"</span>,0,2);
+<a name="l00612"></a>00612   ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,key_name,pcf[0][2],
+<a name="l00613"></a>00613              <span class="stringliteral">"Polynomial distortion coefficient"</span>,<span class="stringliteral">"%g"</span>));
+<a name="l00614"></a>00614 
+<a name="l00615"></a>00615   snprintf(key_name,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%d%d"</span>,<span class="stringliteral">"QC COEFF"</span>,2,1);
+<a name="l00616"></a>00616   ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,key_name,pcf[2][1],
+<a name="l00617"></a>00617              <span class="stringliteral">"Polynomial distortion coefficient"</span>,<span class="stringliteral">"%g"</span>));
+<a name="l00618"></a>00618 
+<a name="l00619"></a>00619   snprintf(key_name,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%d%d"</span>,<span class="stringliteral">"QC COEFF"</span>,1,2);
+<a name="l00620"></a>00620   ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,key_name,pcf[1][2],
+<a name="l00621"></a>00621              <span class="stringliteral">"Polynomial distortion coefficient"</span>,<span class="stringliteral">"%g"</span>));
+<a name="l00622"></a>00622 
+<a name="l00623"></a>00623   snprintf(key_name,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%d%d"</span>,<span class="stringliteral">"QC COEFF"</span>,3,0);
+<a name="l00624"></a>00624   ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,key_name,pcf[3][0],
+<a name="l00625"></a>00625              <span class="stringliteral">"Polynomial distortion coefficient"</span>,<span class="stringliteral">"%g"</span>));
+<a name="l00626"></a>00626 
+<a name="l00627"></a>00627   snprintf(key_name,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%d%d"</span>,<span class="stringliteral">"QC COEFF"</span>,0,3);
+<a name="l00628"></a>00628   ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,key_name,pcf[0][3],
+<a name="l00629"></a>00629              <span class="stringliteral">"Polynomial distortion coefficient"</span>,<span class="stringliteral">"%g"</span>));
+<a name="l00630"></a>00630 
+<a name="l00631"></a>00631   snprintf(key_name,MAX_NAME_SIZE-1,<span class="stringliteral">"%s"</span>,<span class="stringliteral">"QC OFFSET"</span>);
+<a name="l00632"></a>00632   ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,key_name,value,
+<a name="l00633"></a>00633              <span class="stringliteral">"Polynomial distortion coefficient"</span>,<span class="stringliteral">"%g"</span>));
+<a name="l00634"></a>00634 
+<a name="l00635"></a>00635   xshift=new_compute_shift(x_c,y_c,pcf[0][0],pcf[1][0],pcf[0][1],
+<a name="l00636"></a>00636                                    pcf[1][1],pcf[2][0],pcf[0][2],
+<a name="l00637"></a>00637                                    pcf[2][1],pcf[1][2],pcf[3][0],pcf[0][3]);
+<a name="l00638"></a>00638 
+<a name="l00639"></a>00639   ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,<span class="stringliteral">"QC XSHIFT CC"</span>,xshift,
+<a name="l00640"></a>00640                                    <span class="stringliteral">"X shift in x_c,y_c"</span>,<span class="stringliteral">"%g"</span>));
+<a name="l00641"></a>00641 
+<a name="l00642"></a>00642 
+<a name="l00643"></a>00643   xshift=new_compute_shift(x_l,y_l,pcf[0][0],pcf[1][0],pcf[0][1],
+<a name="l00644"></a>00644                                    pcf[1][1],pcf[2][0],pcf[0][2],
+<a name="l00645"></a>00645                                    pcf[2][1],pcf[1][2],pcf[3][0],pcf[0][3]);
+<a name="l00646"></a>00646 
+<a name="l00647"></a>00647   ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,<span class="stringliteral">"QC XSHIFT LL"</span>,xshift,
+<a name="l00648"></a>00648                                    <span class="stringliteral">"X shift in x_l,y_l"</span>,<span class="stringliteral">"%g"</span>));
+<a name="l00649"></a>00649 
+<a name="l00650"></a>00650   xshift=new_compute_shift(x_l,y_u,pcf[0][0],pcf[1][0],pcf[0][1],
+<a name="l00651"></a>00651                                    pcf[1][1],pcf[2][0],pcf[0][2],
+<a name="l00652"></a>00652                                    pcf[2][1],pcf[1][2],pcf[3][0],pcf[0][3]);
+<a name="l00653"></a>00653 
+<a name="l00654"></a>00654   ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,<span class="stringliteral">"QC XSHIFT UL"</span>,xshift,
+<a name="l00655"></a>00655                                    <span class="stringliteral">"X shift in x_l,y_u"</span>,<span class="stringliteral">"%g"</span>));
+<a name="l00656"></a>00656 
+<a name="l00657"></a>00657   xshift=new_compute_shift(x_u,y_u,pcf[0][0],pcf[1][0],pcf[0][1],
+<a name="l00658"></a>00658                                    pcf[1][1],pcf[2][0],pcf[0][2],
+<a name="l00659"></a>00659                                    pcf[2][1],pcf[1][2],pcf[3][0],pcf[0][3]);
+<a name="l00660"></a>00660 
+<a name="l00661"></a>00661   ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,<span class="stringliteral">"QC XSHIFT UR"</span>,xshift,
+<a name="l00662"></a>00662                                    <span class="stringliteral">"X shift in x_u,y_u"</span>,<span class="stringliteral">"%g"</span>));
+<a name="l00663"></a>00663 
+<a name="l00664"></a>00664 
+<a name="l00665"></a>00665   xshift=new_compute_shift(x_u,y_l,pcf[0][0],pcf[1][0],pcf[0][1],
+<a name="l00666"></a>00666                                    pcf[1][1],pcf[2][0],pcf[0][2],
+<a name="l00667"></a>00667                                    pcf[2][1],pcf[1][2],pcf[3][0],pcf[0][3]);
+<a name="l00668"></a>00668 
+<a name="l00669"></a>00669   ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,<span class="stringliteral">"QC XSHIFT LR"</span>,xshift,
+<a name="l00670"></a>00670                                    <span class="stringliteral">"X shift in x_u,y_l"</span>,<span class="stringliteral">"%g"</span>));
+<a name="l00671"></a>00671 
+<a name="l00672"></a>00672 
+<a name="l00673"></a>00673   ck0(sinfo_pro_save_tbl(poly_tbl,set_fibre_ns,sof,cfg->outName,
+<a name="l00674"></a>00674              PRO_DISTORTION,qclog_tbl,plugin_id,config),
+<a name="l00675"></a>00675       <span class="stringliteral">"cannot dump tbl %s"</span>, cfg->outName);
+<a name="l00676"></a>00676 
+<a name="l00677"></a>00677   sinfo_free_table(&poly_tbl);
+<a name="l00678"></a>00678   sinfo_free_table(&qclog_tbl);
+<a name="l00679"></a>00679   sinfo_free_polynomial(&distor_poly);
+<a name="l00680"></a>00680   sinfo_free_int(&degx);
+<a name="l00681"></a>00681   sinfo_free_int(&degy);
+<a name="l00682"></a>00682   sinfo_free_double(&coef);
+<a name="l00683"></a>00683   sinfo_free_image(&im);
+<a name="l00684"></a>00684   sinfo_free_frameset(&stk);
+<a name="l00685"></a>00685   sinfo_finddist_free (&cfg);
+<a name="l00686"></a>00686 
+<a name="l00687"></a>00687   <span class="keywordflow">return</span> 0;
+<a name="l00688"></a>00688 
+<a name="l00689"></a>00689  cleanup:
+<a name="l00690"></a>00690   sinfo_free_table(&poly_tbl);
+<a name="l00691"></a>00691   sinfo_free_table(&qclog_tbl);
+<a name="l00692"></a>00692   sinfo_free_polynomial(&distor_poly);
+<a name="l00693"></a>00693   sinfo_free_int(&degx);
+<a name="l00694"></a>00694   sinfo_free_int(&degy);
+<a name="l00695"></a>00695   sinfo_free_double(&coef);
+<a name="l00696"></a>00696   sinfo_free_apertures(&arcs);
+<a name="l00697"></a>00697 
+<a name="l00698"></a>00698 
+<a name="l00699"></a>00699 
+<a name="l00700"></a>00700   <span class="comment">/*if(wave != NULL) sinfo_new_destroy_array (& wave );*/</span>
+<a name="l00701"></a>00701   <span class="comment">/*if(intens != NULL) sinfo_new_destroy_array (& intens );*/</span>
+<a name="l00702"></a>00702   <span class="keywordflow">if</span>(first != NULL) sinfo_new_destroy_array(&first);
+<a name="l00703"></a>00703   sinfo_free_table(&tbl_spos);
+<a name="l00704"></a>00704   <span class="keywordflow">if</span>(slit_pos != NULL) sinfo_new_destroy_2Dfloatarray (&slit_pos,32);
+<a name="l00705"></a>00705   <span class="keywordflow">if</span>(distances != NULL) sinfo_new_destroy_array(&distances);
+<a name="l00706"></a>00706   <span class="keywordflow">if</span>(par!=NULL) sinfo_new_destroy_fit_params(&par);
+<a name="l00707"></a>00707   <span class="keywordflow">if</span>(n_found_lines != NULL) sinfo_new_destroy_intarray(&n_found_lines );
+<a name="l00708"></a>00708   <span class="keywordflow">if</span>(row_clean != NULL) sinfo_new_destroy_2Dintarray(&row_clean, lx);
+<a name="l00709"></a>00709   <span class="keywordflow">if</span>(wavelength_clean != NULL) {
+<a name="l00710"></a>00710       sinfo_new_destroy_2Dfloatarray(&wavelength_clean,lx);
+<a name="l00711"></a>00711   }
+<a name="l00712"></a>00712   <span class="keywordflow">if</span>(sum_pointer != NULL) sinfo_new_destroy_intarray(&sum_pointer);
+<a name="l00713"></a>00713   <span class="keywordflow">if</span>(acoefs != NULL) {
+<a name="l00714"></a>00714       sinfo_new_destroy_2Dfloatarray(&acoefs, cfg->nrDispCoefficients );
+<a name="l00715"></a>00715   }
+<a name="l00716"></a>00716   sinfo_free_table(&tbl_line_list);
+<a name="l00717"></a>00717   sinfo_free_image(&mask);
+<a name="l00718"></a>00718   sinfo_free_image(&impoly);
+<a name="l00719"></a>00719   sinfo_free_image(&imonind);
+<a name="l00720"></a>00720   sinfo_free_image(&map);
+<a name="l00721"></a>00721   sinfo_free_image(&im);
+<a name="l00722"></a>00722   sinfo_finddist_free (&cfg);
+<a name="l00723"></a>00723   sinfo_free_frameset(&stk);
+<a name="l00724"></a>00724   <span class="keywordflow">return</span> -1;
+<a name="l00725"></a>00725 
+<a name="l00726"></a>00726 }
+<a name="l00727"></a>00727 
+<a name="l00728"></a>00728 
+<a name="l00729"></a>00729 <span class="keyword">static</span> <span class="keywordtype">double</span>
+<a name="l00730"></a>00730 new_compute_shift(<span class="keywordtype">double</span> x,
+<a name="l00731"></a>00731               <span class="keywordtype">double</span> y,
+<a name="l00732"></a>00732               <span class="keywordtype">double</span> c00,
+<a name="l00733"></a>00733               <span class="keywordtype">double</span> c10,
+<a name="l00734"></a>00734               <span class="keywordtype">double</span> c01,
+<a name="l00735"></a>00735               <span class="keywordtype">double</span> c11,
+<a name="l00736"></a>00736               <span class="keywordtype">double</span> c20,
+<a name="l00737"></a>00737               <span class="keywordtype">double</span> c02,
+<a name="l00738"></a>00738               <span class="keywordtype">double</span> c21,
+<a name="l00739"></a>00739               <span class="keywordtype">double</span> c12,
+<a name="l00740"></a>00740               <span class="keywordtype">double</span> c30,
+<a name="l00741"></a>00741               <span class="keywordtype">double</span> c03)
+<a name="l00742"></a>00742 {
+<a name="l00743"></a>00743 
+<a name="l00744"></a>00744   <span class="keywordtype">double</span> x_shift=0;
+<a name="l00745"></a>00745   <span class="keywordtype">double</span> shift=0;
+<a name="l00746"></a>00746   <span class="comment">//sinfo_msg("c= %g   %g  %g  %g  %g  %g  %g  %g %g %g\n",</span>
+<a name="l00747"></a>00747   <span class="comment">//       c00,c10,c01,c11,</span>
+<a name="l00748"></a>00748   <span class="comment">//       c20,c02,c21,c12,c30,c03);</span>
+<a name="l00749"></a>00749 
+<a name="l00750"></a>00750   shift=c00+c10*x+c01*y+
+<a name="l00751"></a>00751         c11*x*y+c20*x*x+c02*y*y+
+<a name="l00752"></a>00752         c21*x*x*y+c12*x*y*y+c30*x*x*x+c03*y*y*y;
+<a name="l00753"></a>00753   x_shift=x-shift;
+<a name="l00754"></a>00754   <span class="keywordflow">return</span> x_shift;
+<a name="l00755"></a>00755 
+<a name="l00756"></a>00756 
+<a name="l00757"></a>00757 
+<a name="l00758"></a>00758 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__new__find__distortions_8h_source.html b/html/sinfo__new__find__distortions_8h_source.html
new file mode 100644
index 0000000..4e1d50b
--- /dev/null
+++ b/html/sinfo__new__find__distortions_8h_source.html
@@ -0,0 +1,81 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_new_find_distortions.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_new_find_distortions.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#ifndef SINFO_NEW_FIND_DISTORTIONS_H</span>
+<a name="l00002"></a>00002 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_NEW_FIND_DISTORTIONS_H</span>
+<a name="l00003"></a>00003 <span class="preprocessor"></span><span class="comment">/*</span>
+<a name="l00004"></a>00004 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00005"></a>00005 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00006"></a>00006 <span class="comment"> *</span>
+<a name="l00007"></a>00007 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00008"></a>00008 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00009"></a>00009 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00010"></a>00010 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00011"></a>00011 <span class="comment"> *</span>
+<a name="l00012"></a>00012 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00013"></a>00013 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00014"></a>00014 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00015"></a>00015 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00016"></a>00016 <span class="comment"> *</span>
+<a name="l00017"></a>00017 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00018"></a>00018 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00019"></a>00019 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00020"></a>00020 <span class="comment"> */</span>
+<a name="l00021"></a>00021 <span class="comment">/****************************************************************************</span>
+<a name="l00022"></a>00022 <span class="comment">* E.S.O. - VLT project</span>
+<a name="l00023"></a>00023 <span class="comment">*</span>
+<a name="l00024"></a>00024 <span class="comment">* "@(#) $Id: sinfo_new_find_distortions.h,v 1.9 2007/09/14 14:40:04 amodigli Exp $"</span>
+<a name="l00025"></a>00025 <span class="comment">*</span>
+<a name="l00026"></a>00026 <span class="comment">* who       when      what</span>
+<a name="l00027"></a>00027 <span class="comment">* --------  --------  ----------------------------------------------</span>
+<a name="l00028"></a>00028 <span class="comment">* amodigli  12/08/04  created</span>
+<a name="l00029"></a>00029 <span class="comment">*/</span>
+<a name="l00030"></a>00030 
+<a name="l00031"></a>00031 <span class="comment">/************************************************************************</span>
+<a name="l00032"></a>00032 <span class="comment"> * sinfo_find_distortions.h</span>
+<a name="l00033"></a>00033 <span class="comment"></span>
+<a name="l00034"></a>00034 <span class="comment"> *----------------------------------------------------------------------</span>
+<a name="l00035"></a>00035 <span class="comment"> */</span>
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="comment">/*</span>
+<a name="l00038"></a>00038 <span class="comment"> * header files</span>
+<a name="l00039"></a>00039 <span class="comment"> */</span>
+<a name="l00040"></a>00040 
+<a name="l00041"></a>00041 <span class="preprocessor">#include <cpl.h></span>   
+<a name="l00042"></a>00042 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00043"></a>00043 
+<a name="l00044"></a>00044 
+<a name="l00045"></a>00045 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00046"></a>00046 <span class="comment"> *                        Function ANSI C prototypes</span>
+<a name="l00047"></a>00047 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00048"></a>00048 
+<a name="l00049"></a>00049 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00050"></a>00050 <span class="comment">   Function     :       sinfo_find_distortions()</span>
+<a name="l00051"></a>00051 <span class="comment">   In           :       </span>
+<a name="l00052"></a>00052 <span class="comment">   Out          :        </span>
+<a name="l00053"></a>00053 <span class="comment">   Job          :</span>
+<a name="l00054"></a>00054 <span class="comment"></span>
+<a name="l00055"></a>00055 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00056"></a>00056 <span class="keywordtype">int</span> 
+<a name="l00057"></a>00057 sinfo_new_find_distortions (<span class="keyword">const</span> <span class="keywordtype">char</span>* plugin_id,
+<a name="l00058"></a>00058                             cpl_parameterlist* config, 
+<a name="l00059"></a>00059                             cpl_frameset* sof,
+<a name="l00060"></a>00060                 cpl_frameset* set_fibre_ns) ;
+<a name="l00061"></a>00061 
+<a name="l00062"></a>00062 
+<a name="l00063"></a>00063 <span class="preprocessor">#endif </span>
+<a name="l00064"></a>00064 <span class="preprocessor"></span>
+<a name="l00065"></a>00065 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__new__lamp__flats_8c_source.html b/html/sinfo__new__lamp__flats_8c_source.html
new file mode 100644
index 0000000..ef66bf1
--- /dev/null
+++ b/html/sinfo__new__lamp__flats_8c_source.html
@@ -0,0 +1,1017 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_new_lamp_flats.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_new_lamp_flats.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment"> </span>
+<a name="l00021"></a>00021 <span class="comment">     File name    :       sinfo_new_lamp_flats.c</span>
+<a name="l00022"></a>00022 <span class="comment">   Author       :    A. Modigliani</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on   :    Sep 29, 2003</span>
+<a name="l00024"></a>00024 <span class="comment">   Description  : </span>
+<a name="l00025"></a>00025 <span class="comment"></span>
+<a name="l00026"></a>00026 <span class="comment"> * this step handles stacks of lamp flat fields, </span>
+<a name="l00027"></a>00027 <span class="comment"> *  o it takes a clean mean,</span>
+<a name="l00028"></a>00028 <span class="comment"> *  o subtracts the off- from the on-frames, </span>
+<a name="l00029"></a>00029 <span class="comment"> *  o corrects for static bad pixels and normalizes for a master flat field. </span>
+<a name="l00030"></a>00030 <span class="comment"> *  o It distinguishes the spectrally dithered frames and </span>
+<a name="l00031"></a>00031 <span class="comment"> *  o treats them the same way. </span>
+<a name="l00032"></a>00032 <span class="comment"> *  o It can also generate a static bad pixel mask if wished.</span>
+<a name="l00033"></a>00033 <span class="comment"></span>
+<a name="l00034"></a>00034 <span class="comment"></span>
+<a name="l00035"></a>00035 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00038"></a>00038 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00039"></a>00039 <span class="preprocessor">#endif</span>
+<a name="l00040"></a>00040 <span class="preprocessor"></span>
+<a name="l00041"></a>00041 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00042"></a>00042 <span class="comment">                                Includes</span>
+<a name="l00043"></a>00043 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00044"></a>00044 <span class="preprocessor">#include "sinfo_new_lamp_flats.h"</span>
+<a name="l00045"></a>00045 <span class="preprocessor">#include "sinfo_flat_ini_by_cpl.h"</span>
+<a name="l00046"></a>00046 <span class="preprocessor">#include "sinfo_pro_save.h"</span>
+<a name="l00047"></a>00047 <span class="preprocessor">#include "sinfo_pro_types.h"</span>
+<a name="l00048"></a>00048 <span class="preprocessor">#include "sinfo_functions.h"</span>
+<a name="l00049"></a>00049 <span class="preprocessor">#include "sinfo_new_cube_ops.h"</span>
+<a name="l00050"></a>00050 <span class="preprocessor">#include "sinfo_error.h"</span>
+<a name="l00051"></a>00051 <span class="preprocessor">#include "sinfo_utils_wrappers.h"</span>
+<a name="l00052"></a>00052 <span class="preprocessor">#include "sinfo_image_ops.h"</span>
+<a name="l00053"></a>00053 <span class="preprocessor">#include "sinfo_utilities.h"</span>
+<a name="l00054"></a>00054 <span class="preprocessor">#include "sinfo_globals.h"</span>
+<a name="l00055"></a>00055 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00056"></a>00056 <span class="comment">                                Defines</span>
+<a name="l00057"></a>00057 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00058"></a>00058 
+<a name="l00059"></a>00059 <span class="keyword">static</span> <span class="keywordtype">int</span> 
+<a name="l00060"></a>00060 new_qc_get_cnt(cpl_frameset* on_set, cpl_frameset* of_set, flat_config* cfg);
+<a name="l00061"></a>00061 <span class="keyword">static</span> <span class="keywordtype">int</span> 
+<a name="l00062"></a>00062 new_lamp_flats_det_ncounts(cpl_frameset* raw, flat_config* config);
+<a name="l00063"></a>00063 
+<a name="l00064"></a>00064 <span class="keyword">static</span> <span class="keyword">struct </span>{
+<a name="l00065"></a>00065 
+<a name="l00066"></a>00066   <span class="keywordtype">double</span> avg_on; 
+<a name="l00067"></a>00067   <span class="keywordtype">double</span> std_on;
+<a name="l00068"></a>00068   <span class="keywordtype">double</span> avg_of; 
+<a name="l00069"></a>00069   <span class="keywordtype">double</span> std_of;
+<a name="l00070"></a>00070   <span class="keywordtype">double</span> avg_di; 
+<a name="l00071"></a>00071   <span class="keywordtype">double</span> std_di;
+<a name="l00072"></a>00072   <span class="keywordtype">double</span> nsat_on;
+<a name="l00073"></a>00073   <span class="keywordtype">double</span> noise_on;
+<a name="l00074"></a>00074   <span class="keywordtype">double</span> noise_of;
+<a name="l00075"></a>00075   <span class="keywordtype">double</span> flux_on;
+<a name="l00076"></a>00076   <span class="keywordtype">double</span>    nsat;
+<a name="l00077"></a>00077 
+<a name="l00078"></a>00078 } qc_lampflat;
+<a name="l00079"></a>00079 
+<a name="l00080"></a>00080 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00081"></a>00081 <span class="comment">                             Function Definitions</span>
+<a name="l00082"></a>00082 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00090"></a>00090 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00091"></a>00091 <span class="comment">   @name  sinfo_new_lamp_flats()</span>
+<a name="l00092"></a>00092 <span class="comment">   @param  plugin_id recipe id</span>
+<a name="l00093"></a>00093 <span class="comment">   @param  config input parameterlist</span>
+<a name="l00094"></a>00094 <span class="comment">   @param  sof    input set of frames</span>
+<a name="l00095"></a>00095 <span class="comment">   @return integer (0 if it worked, -1 if it doesn't) </span>
+<a name="l00096"></a>00096 <span class="comment">   @doc </span>
+<a name="l00097"></a>00097 <span class="comment"></span>
+<a name="l00098"></a>00098 <span class="comment"> * this step handles stacks of lamp flat fields, </span>
+<a name="l00099"></a>00099 <span class="comment"> *  o it takes a clean mean,</span>
+<a name="l00100"></a>00100 <span class="comment"> *  o subtracts the off- from the on-frames, </span>
+<a name="l00101"></a>00101 <span class="comment"> *  o corrects for static bad pixels and normalizes for a master flat field. </span>
+<a name="l00102"></a>00102 <span class="comment"> *  o It distinguishes the spectrally dithered frames and </span>
+<a name="l00103"></a>00103 <span class="comment"> *  o treats them the same way. </span>
+<a name="l00104"></a>00104 <span class="comment"> *  o It can also generate a static bad pixel mask if wished.</span>
+<a name="l00105"></a>00105 <span class="comment"></span>
+<a name="l00106"></a>00106 <span class="comment"></span>
+<a name="l00107"></a>00107 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00108"></a>00108 
+<a name="l00109"></a>00109 
+<a name="l00110"></a>00110 
+<a name="l00111"></a>00111 
+<a name="l00112"></a>00112 <span class="keywordtype">int</span> 
+<a name="l00113"></a>00113 sinfo_new_lamp_flats (<span class="keyword">const</span> <span class="keywordtype">char</span>* plugin_id, 
+<a name="l00114"></a>00114                       cpl_parameterlist* config, 
+<a name="l00115"></a>00115                       cpl_frameset* sof,
+<a name="l00116"></a>00116                       cpl_frameset* ref_set)
+<a name="l00117"></a>00117 {
+<a name="l00118"></a>00118   flat_config * cfg =NULL;
+<a name="l00119"></a>00119   cpl_imagelist* list_object=NULL;
+<a name="l00120"></a>00120   cpl_imagelist* list_dither_object=NULL ;
+<a name="l00121"></a>00121   cpl_imagelist* list_sky=NULL ;
+<a name="l00122"></a>00122   cpl_imagelist* list_dither_sky=NULL;
+<a name="l00123"></a>00123   cpl_image ** im=NULL ;
+<a name="l00124"></a>00124   cpl_image * norm_dith =NULL;
+<a name="l00125"></a>00125   cpl_image * im_obj =NULL;
+<a name="l00126"></a>00126   cpl_image * int_im =NULL;
+<a name="l00127"></a>00127   cpl_image * int_im_dith =NULL;
+<a name="l00128"></a>00128   cpl_image * im_sky =NULL;
+<a name="l00129"></a>00129   cpl_image * im_dither =NULL;
+<a name="l00130"></a>00130   cpl_image * im_obj_sub =NULL;
+<a name="l00131"></a>00131   cpl_image * im_dither_sub =NULL;
+<a name="l00132"></a>00132   cpl_image * im_dither_sky =NULL;
+<a name="l00133"></a>00133   cpl_image ** imMed=NULL ;
+<a name="l00134"></a>00134   cpl_image * colImage =NULL;
+<a name="l00135"></a>00135   cpl_image * mask_im =NULL;
+<a name="l00136"></a>00136   cpl_image * norm =NULL;
+<a name="l00137"></a>00137   cpl_image * compImage =NULL;
+<a name="l00138"></a>00138   cpl_image * maskImage =NULL;
+<a name="l00139"></a>00139   cpl_image * threshIm =NULL;
+<a name="l00140"></a>00140 
+<a name="l00141"></a>00141   <span class="keywordtype">char</span> name[MAX_NAME_SIZE];
+<a name="l00142"></a>00142 
+<a name="l00143"></a>00143   <span class="keywordtype">int</span> typ;
+<a name="l00144"></a>00144   Stats * stats =NULL;
+<a name="l00145"></a>00145   <span class="keywordtype">int</span> i = 0;
+<a name="l00146"></a>00146   <span class="keywordtype">int</span>* n=NULL;
+<a name="l00147"></a>00147   <span class="keywordtype">int</span> nob =0;
+<a name="l00148"></a>00148   <span class="keywordtype">int</span> nsky = 0; 
+<a name="l00149"></a>00149   <span class="keywordtype">int</span> nobjdith = 0;
+<a name="l00150"></a>00150   <span class="keywordtype">int</span> nskydith = 0; 
+<a name="l00151"></a>00151   <span class="keywordtype">int</span> n_badpixels =0;
+<a name="l00152"></a>00152   <span class="keywordtype">int</span> pos =0;
+<a name="l00153"></a>00153 
+<a name="l00154"></a>00154   <span class="keywordtype">float</span>** slit_edges=NULL;
+<a name="l00155"></a>00155   <span class="keywordtype">float</span> local_clean_mean =0.;
+<a name="l00156"></a>00156   <span class="keywordtype">float</span> clean_stdev =0.;
+<a name="l00157"></a>00157   <span class="keywordtype">float</span> mean_factor =0.;
+<a name="l00158"></a>00158   <span class="keywordtype">float</span> val_x=0;
+<a name="l00159"></a>00159   <span class="keywordtype">float</span> val_y=0;
+<a name="l00160"></a>00160 
+<a name="l00161"></a>00161   <span class="keywordtype">char</span> outNameDither[MAX_NAME_SIZE];
+<a name="l00162"></a>00162   <span class="keywordtype">char</span> name_list[MAX_NAME_SIZE];
+<a name="l00163"></a>00163   <span class="keywordtype">char</span> tbl_slitpos_name[MAX_NAME_SIZE];
+<a name="l00164"></a>00164 
+<a name="l00165"></a>00165   cpl_table* tbl_slitpos=NULL;
+<a name="l00166"></a>00166   <span class="keywordtype">int</span>* status=NULL;
+<a name="l00167"></a>00167 
+<a name="l00168"></a>00168   <span class="keywordtype">int</span> n_im_med=0;
+<a name="l00169"></a>00169   cpl_frameset* raw=NULL;
+<a name="l00170"></a>00170 
+<a name="l00171"></a>00171   cpl_table* qclog_tbl=NULL;
+<a name="l00172"></a>00172   <span class="keywordtype">int</span> naxis1=0;
+<a name="l00173"></a>00173   <span class="keywordtype">int</span> naxis2=0;
+<a name="l00174"></a>00174   <span class="keywordtype">double</span> fpn_stdev1=0;
+<a name="l00175"></a>00175   <span class="keywordtype">double</span> fpn_stdev2=0;
+<a name="l00176"></a>00176 
+<a name="l00177"></a>00177   <span class="keywordtype">int</span> no=0;
+<a name="l00178"></a>00178   <span class="keywordtype">float</span> lo_cut=0;
+<a name="l00179"></a>00179   <span class="keywordtype">float</span> hi_cut=0;
+<a name="l00180"></a>00180 
+<a name="l00181"></a>00181   <span class="comment">/*</span>
+<a name="l00182"></a>00182 <span class="comment">       -----------------------------------------------------------------</span>
+<a name="l00183"></a>00183 <span class="comment">       1) parse the file names and parameters to the tilt_config data </span>
+<a name="l00184"></a>00184 <span class="comment">          structure cfg </span>
+<a name="l00185"></a>00185 <span class="comment">       -----------------------------------------------------------------</span>
+<a name="l00186"></a>00186 <span class="comment">  */</span>
+<a name="l00187"></a>00187 
+<a name="l00188"></a>00188   cknull_nomsg(raw=cpl_frameset_new());
+<a name="l00189"></a>00189 
+<a name="l00190"></a>00190   cknull(cfg = sinfo_parse_cpl_input_flat(config,sof,&raw),
+<a name="l00191"></a>00191      <span class="stringliteral">"could not parse cpl input!"</span>);
+<a name="l00192"></a>00192 
+<a name="l00193"></a>00193   <span class="keywordflow">if</span> (cfg->interpolInd == 1) {
+<a name="l00194"></a>00194     <span class="keywordflow">if</span>(sinfo_is_fits_file(cfg->mask) != 1) {
+<a name="l00195"></a>00195       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Input file %s is not FITS"</span>,cfg->mask);
+<a name="l00196"></a>00196       <span class="keywordflow">goto</span> cleanup;
+<a name="l00197"></a>00197     }
+<a name="l00198"></a>00198     <span class="keywordflow">if</span> (sinfo_is_fits_file(cfg->slitposList) != 1) {
+<a name="l00199"></a>00199       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Input file %s is not FITS"</span>,cfg->slitposList);
+<a name="l00200"></a>00200       <span class="keywordflow">goto</span> cleanup;
+<a name="l00201"></a>00201     }
+<a name="l00202"></a>00202   }
+<a name="l00203"></a>00203 
+<a name="l00204"></a>00204   <span class="comment">/*</span>
+<a name="l00205"></a>00205 <span class="comment">    #---------------------------------------------------------</span>
+<a name="l00206"></a>00206 <span class="comment">    # Take a clean mean of several images</span>
+<a name="l00207"></a>00207 <span class="comment">    # input is 1 or more similar images</span>
+<a name="l00208"></a>00208 <span class="comment">    #---------------------------------------------------------</span>
+<a name="l00209"></a>00209 <span class="comment">  */</span>
+<a name="l00210"></a>00210   sinfo_msg(<span class="stringliteral">"Takes clean mean of several images"</span>);
+<a name="l00211"></a>00211   <span class="comment">/* #allocate memory for lists of object, sky and dithered frames--*/</span>
+<a name="l00212"></a>00212   cknull(list_object = cpl_imagelist_new (),<span class="stringliteral">"could not allocate memory"</span>);
+<a name="l00213"></a>00213 
+<a name="l00214"></a>00214   <span class="keywordflow">if</span> (cfg->contains_dither == 1) {
+<a name="l00215"></a>00215     cknull(list_dither_object=cpl_imagelist_new(),<span class="stringliteral">"could not allocate memory"</span>);
+<a name="l00216"></a>00216   }
+<a name="l00217"></a>00217 
+<a name="l00218"></a>00218   <span class="keywordflow">if</span> (cfg->contains_sky == 1) {
+<a name="l00219"></a>00219     cknull(list_sky=cpl_imagelist_new(),<span class="stringliteral">"could not allocate memory"</span>);
+<a name="l00220"></a>00220   }
+<a name="l00221"></a>00221 
+<a name="l00222"></a>00222   <span class="keywordflow">if</span> (cfg->contains_dither == 1 && cfg->nditheroff > 0) {
+<a name="l00223"></a>00223     cknull(list_dither_sky=cpl_imagelist_new(),<span class="stringliteral">"could not allocate memory"</span>);
+<a name="l00224"></a>00224   }
+<a name="l00225"></a>00225 
+<a name="l00226"></a>00226   <span class="keywordflow">if</span> (cfg->contains_dither == 0 && cfg->nditheroff > 0){
+<a name="l00227"></a>00227     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"please use non-dithered off-frames, remove the 2!"</span>);
+<a name="l00228"></a>00228     <span class="keywordflow">goto</span> cleanup;
+<a name="l00229"></a>00229   }
+<a name="l00230"></a>00230  
+<a name="l00231"></a>00231 
+<a name="l00232"></a>00232   <span class="comment">/* problem with im as image holder: cleanup then does not work */</span>
+<a name="l00233"></a>00233   im = (cpl_image**) cpl_calloc (cfg -> nframes, <span class="keyword">sizeof</span>(cpl_image*)); 
+<a name="l00234"></a>00234 
+<a name="l00235"></a>00235   <span class="keywordflow">for</span> (i=0; i< cfg->nframes; i++) {
+<a name="l00236"></a>00236     strcpy(name,cfg->framelist[i]);
+<a name="l00237"></a>00237     <span class="keywordflow">if</span>(sinfo_is_fits_file(name) != 1) {
+<a name="l00238"></a>00238       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"PP Input file %s %d is not FITS"</span>,name,i);
+<a name="l00239"></a>00239       <span class="keywordflow">goto</span> cleanup;
+<a name="l00240"></a>00240     }
+<a name="l00241"></a>00241     im[i]=cpl_image_load(name,CPL_TYPE_FLOAT,0,0);
+<a name="l00242"></a>00242 
+<a name="l00243"></a>00243   }
+<a name="l00244"></a>00244 
+<a name="l00245"></a>00245   <span class="keywordflow">for</span> (i=0; i< cfg->nframes; i++) {
+<a name="l00246"></a>00246     typ = cfg->frametype[i];
+<a name="l00247"></a>00247     pos = cfg->frameposition[i];
+<a name="l00248"></a>00248     cknull(im[i],<span class="stringliteral">"could not load image %d"</span>,i);
+<a name="l00249"></a>00249     <span class="keywordflow">if</span> (pos == 2) {
+<a name="l00250"></a>00250       <span class="keywordflow">if</span> (typ == 1) {
+<a name="l00251"></a>00251         cpl_imagelist_set( list_object, cpl_image_duplicate(im[i]), nob );  
+<a name="l00252"></a>00252         nob = nob + 1;
+<a name="l00253"></a>00253       } <span class="keywordflow">else</span> {
+<a name="l00254"></a>00254         cpl_imagelist_set( list_sky, cpl_image_duplicate(im[i]), nsky );
+<a name="l00255"></a>00255         nsky = nsky + 1 ;
+<a name="l00256"></a>00256       }
+<a name="l00257"></a>00257     } <span class="keywordflow">else</span> {
+<a name="l00258"></a>00258       <span class="keywordflow">if</span> (typ == 1) {
+<a name="l00259"></a>00259         cpl_imagelist_set(list_dither_object, 
+<a name="l00260"></a>00260                           cpl_image_duplicate(im[i]), nobjdith );  
+<a name="l00261"></a>00261         nobjdith = nobjdith + 1;
+<a name="l00262"></a>00262       } <span class="keywordflow">else</span> {
+<a name="l00263"></a>00263         cpl_imagelist_set( list_dither_sky, 
+<a name="l00264"></a>00264                           cpl_image_duplicate(im[i]), nskydith );
+<a name="l00265"></a>00265         nskydith = nskydith + 1 ;
+<a name="l00266"></a>00266       }
+<a name="l00267"></a>00267     }
+<a name="l00268"></a>00268   }
+<a name="l00269"></a>00269 
+<a name="l00270"></a>00270 
+<a name="l00271"></a>00271   <span class="keywordflow">if</span> (nob != cfg->nobj || cfg->noff != nsky || 
+<a name="l00272"></a>00272       nobjdith != cfg->nditherobj || nskydith != cfg->nditheroff) {
+<a name="l00273"></a>00273       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"something is wrong with the number of "</span>
+<a name="l00274"></a>00274                       <span class="stringliteral">"the different types of frames"</span>);
+<a name="l00275"></a>00275       <span class="keywordflow">goto</span> cleanup;
+<a name="l00276"></a>00276   }
+<a name="l00277"></a>00277 
+<a name="l00278"></a>00278   <span class="comment">/* # create and fill cubes with the different image lists- */</span>
+<a name="l00279"></a>00279   sinfo_msg(<span class="stringliteral">"Creates and fills cubes with the different image lists"</span>);
+<a name="l00280"></a>00280   cknull(list_object,<span class="stringliteral">"could not create data cube!"</span>);
+<a name="l00281"></a>00281 
+<a name="l00282"></a>00282   <span class="keywordflow">if</span> (cfg->contains_dither == 1) {
+<a name="l00283"></a>00283     cknull(list_dither_object,<span class="stringliteral">"could not create data cube!"</span>);
+<a name="l00284"></a>00284   }
+<a name="l00285"></a>00285   <span class="keywordflow">if</span> (cfg->contains_sky == 1 && nsky > 0) {
+<a name="l00286"></a>00286     cknull(list_sky,<span class="stringliteral">"could not create data cube!"</span>);
+<a name="l00287"></a>00287   }
+<a name="l00288"></a>00288 
+<a name="l00289"></a>00289   <span class="keywordflow">if</span> (cfg->contains_dither == 1 && nskydith > 0) {
+<a name="l00290"></a>00290     cknull(list_dither_sky,<span class="stringliteral">"could not create data cube!"</span>);
+<a name="l00291"></a>00291   }
+<a name="l00292"></a>00292 
+<a name="l00293"></a>00293  
+<a name="l00294"></a>00294   <span class="comment">/*-take the average of the different cubes -*/</span>
+<a name="l00295"></a>00295   sinfo_msg(<span class="stringliteral">"Takes the average of the different cubes"</span>);
+<a name="l00296"></a>00296   <span class="keywordflow">if</span> (cfg->loReject*cfg->nobj < 1. && cfg->hiReject *cfg->nobj < 1.) {
+<a name="l00297"></a>00297     cknull(im_obj = sinfo_new_average_cube_to_image(list_object ),
+<a name="l00298"></a>00298           <span class="stringliteral">"sinfo_averageCubeToImage failed"</span> );
+<a name="l00299"></a>00299   } <span class="keywordflow">else</span> {
+<a name="l00300"></a>00300 
+<a name="l00301"></a>00301     no=cpl_imagelist_get_size(list_object);
+<a name="l00302"></a>00302     lo_cut=(floor)(cfg->loReject*no+0.5);
+<a name="l00303"></a>00303     hi_cut=(floor)(cfg->hiReject*no+0.5);
+<a name="l00304"></a>00304     cknull(im_obj=cpl_imagelist_collapse_minmax_create(list_object,
+<a name="l00305"></a>00305                                                       lo_cut,
+<a name="l00306"></a>00306                                                       hi_cut),
+<a name="l00307"></a>00307                  <span class="stringliteral">"sinfo_average_with_rejection failed"</span> );
+<a name="l00308"></a>00308   }
+<a name="l00309"></a>00309    sinfo_free_imagelist(&list_object);
+<a name="l00310"></a>00310 
+<a name="l00311"></a>00311   <span class="keywordflow">if</span> (cfg->contains_sky == 1) {
+<a name="l00312"></a>00312     <span class="keywordflow">if</span> (cfg->loReject * nsky < 1. && cfg->hiReject * nsky < 1.) {
+<a name="l00313"></a>00313       cknull(im_sky = sinfo_new_average_cube_to_image(list_sky ),
+<a name="l00314"></a>00314       <span class="stringliteral">"sinfo_new_average_cube_to_image failed"</span> );
+<a name="l00315"></a>00315     } <span class="keywordflow">else</span> {
+<a name="l00316"></a>00316 
+<a name="l00317"></a>00317     no=cpl_imagelist_get_size(list_sky);
+<a name="l00318"></a>00318     lo_cut=(floor)(cfg->loReject*no+0.5);
+<a name="l00319"></a>00319     hi_cut=(floor)(cfg->hiReject*no+0.5);
+<a name="l00320"></a>00320     cknull(im_sky=cpl_imagelist_collapse_minmax_create(list_sky,lo_cut,hi_cut),
+<a name="l00321"></a>00321            <span class="stringliteral">"sinfo_average_with_rejection failed"</span> );
+<a name="l00322"></a>00322     }
+<a name="l00323"></a>00323     sinfo_free_imagelist(&list_sky);
+<a name="l00324"></a>00324   }
+<a name="l00325"></a>00325 
+<a name="l00326"></a>00326   <span class="keywordflow">if</span> (cfg->contains_dither == 1) {
+<a name="l00327"></a>00327     <span class="keywordflow">if</span> (cfg->loReject*nobjdith < 1. && cfg->hiReject * nobjdith < 1.) {
+<a name="l00328"></a>00328       cknull(im_dither = sinfo_new_average_cube_to_image(list_dither_object ),
+<a name="l00329"></a>00329              <span class="stringliteral">"sinfo_new_average_cube_to_image failed"</span> );
+<a name="l00330"></a>00330    } <span class="keywordflow">else</span> {
+<a name="l00331"></a>00331 
+<a name="l00332"></a>00332 
+<a name="l00333"></a>00333      no=cpl_imagelist_get_size(list_dither_object);
+<a name="l00334"></a>00334      lo_cut=(floor)(cfg->loReject*no+0.5);
+<a name="l00335"></a>00335      hi_cut=(floor)(cfg->hiReject*no+0.5);
+<a name="l00336"></a>00336      cknull(im_dither=cpl_imagelist_collapse_minmax_create(list_dither_object,
+<a name="l00337"></a>00337                                                            lo_cut,hi_cut),
+<a name="l00338"></a>00338                                       <span class="stringliteral">"sinfo_average_with_rejection failed"</span> );
+<a name="l00339"></a>00339    }
+<a name="l00340"></a>00340    sinfo_free_imagelist(&list_dither_object);
+<a name="l00341"></a>00341   }
+<a name="l00342"></a>00342 
+<a name="l00343"></a>00343   <span class="keywordflow">if</span> (cfg->contains_dither == 1 && nskydith > 0 ) {
+<a name="l00344"></a>00344     <span class="keywordflow">if</span> (cfg->loReject*nskydith < 1. && cfg->hiReject*nskydith < 1.) {
+<a name="l00345"></a>00345       cknull(im_dither_sky = sinfo_new_average_cube_to_image(list_dither_sky ),
+<a name="l00346"></a>00346             <span class="stringliteral">"sinfo_new_average_cube_to_image failed"</span> );
+<a name="l00347"></a>00347     } <span class="keywordflow">else</span> {
+<a name="l00348"></a>00348       no=cpl_imagelist_get_size(list_dither_sky);
+<a name="l00349"></a>00349       lo_cut=(floor)(cfg->loReject*no+0.5);
+<a name="l00350"></a>00350       hi_cut=(floor)(cfg->hiReject*no+0.5);
+<a name="l00351"></a>00351       cknull(im_dither_sky=cpl_imagelist_collapse_minmax_create(list_dither_sky,
+<a name="l00352"></a>00352                                                                 lo_cut,hi_cut),
+<a name="l00353"></a>00353                                           <span class="stringliteral">"new_average_with_rejection failed"</span> );
+<a name="l00354"></a>00354     }
+<a name="l00355"></a>00355     sinfo_free_imagelist(&list_dither_sky);
+<a name="l00356"></a>00356   }   
+<a name="l00357"></a>00357 
+<a name="l00358"></a>00358   <span class="comment">/*</span>
+<a name="l00359"></a>00359 <span class="comment">  #---------------------------------------------------------</span>
+<a name="l00360"></a>00360 <span class="comment">  # Subtract the resulting off-frame (sky) from the on-frame </span>
+<a name="l00361"></a>00361 <span class="comment">  #-------------------------------------------------------</span>
+<a name="l00362"></a>00362 <span class="comment">  #finally, subtract off from on frames and store the result in the </span>
+<a name="l00363"></a>00363 <span class="comment">  # object cube----------------</span>
+<a name="l00364"></a>00364 <span class="comment">  */</span>
+<a name="l00365"></a>00365 
+<a name="l00366"></a>00366   sinfo_msg(<span class="stringliteral">"Subtracts the resulting off-frame (sky) from the on-frame"</span>);
+<a name="l00367"></a>00367   <span class="keywordflow">if</span> (cfg->contains_sky == 1) {
+<a name="l00368"></a>00368      cknull(im_obj_sub = cpl_image_subtract_create(im_obj, im_sky),
+<a name="l00369"></a>00369             <span class="stringliteral">"could not sinfo_sub_image"</span>);
+<a name="l00370"></a>00370      sinfo_free_image(&im_obj);
+<a name="l00371"></a>00371      <span class="keywordflow">if</span> (((cfg->contains_dither == 1) && (nskydith > 0)) || 
+<a name="l00372"></a>00372          (cfg->contains_dither == 0)) {
+<a name="l00373"></a>00373        sinfo_free_image(&im_sky);
+<a name="l00374"></a>00374      }
+<a name="l00375"></a>00375      im_obj = im_obj_sub;
+<a name="l00376"></a>00376   }
+<a name="l00377"></a>00377 
+<a name="l00378"></a>00378   <span class="keywordflow">if</span> (cfg->contains_dither == 1 && nskydith > 0) {
+<a name="l00379"></a>00379      cknull(im_dither_sub=cpl_image_subtract_create(im_dither, im_dither_sky),
+<a name="l00380"></a>00380             <span class="stringliteral">"could not sinfo_sub_image"</span>);
+<a name="l00381"></a>00381      sinfo_free_image(&im_dither);
+<a name="l00382"></a>00382      sinfo_free_image(&im_dither_sky);
+<a name="l00383"></a>00383      im_dither = im_dither_sub;
+<a name="l00384"></a>00384    } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (cfg->contains_dither == 1 && 
+<a name="l00385"></a>00385                           nskydith == 0 && 
+<a name="l00386"></a>00386               cfg->contains_sky == 1) {
+<a name="l00387"></a>00387      cknull(im_dither_sub = cpl_image_subtract_create(im_dither, im_sky),
+<a name="l00388"></a>00388         <span class="stringliteral">"could not sinfo_sub_image"</span>);
+<a name="l00389"></a>00389      sinfo_free_image(&im_dither);
+<a name="l00390"></a>00390      sinfo_free_image(&im_sky);
+<a name="l00391"></a>00391      im_dither = im_dither_sub;
+<a name="l00392"></a>00392    }
+<a name="l00393"></a>00393    <span class="comment">/*</span>
+<a name="l00394"></a>00394 <span class="comment">   #---------------------------------------------------------</span>
+<a name="l00395"></a>00395 <span class="comment">   # Generating a static bad pixel mask:</span>
+<a name="l00396"></a>00396 <span class="comment">   # remove the intensity tilt from every column</span>
+<a name="l00397"></a>00397 <span class="comment">   # and compute the standard deviation on a rectangular zone</span>
+<a name="l00398"></a>00398 <span class="comment">   #---------------------------------------------------------</span>
+<a name="l00399"></a>00399 <span class="comment">   */</span>
+<a name="l00400"></a>00400 
+<a name="l00401"></a>00401    sinfo_msg(<span class="stringliteral">"Generating a static bad pixel mask"</span>);
+<a name="l00402"></a>00402    n_im_med = cfg->iterations+1;
+<a name="l00403"></a>00403 
+<a name="l00404"></a>00404    imMed=(cpl_image**) cpl_calloc(n_im_med, <span class="keyword">sizeof</span>(cpl_image*));
+<a name="l00405"></a>00405 
+<a name="l00406"></a>00406    <span class="keywordflow">if</span> (cfg->badInd == 1) {
+<a name="l00407"></a>00407      sinfo_msg(<span class="stringliteral">"removes the intensity tilt from every column and"</span>);
+<a name="l00408"></a>00408      sinfo_msg(<span class="stringliteral">"computes the standard deviation on a rectangular zone"</span>);
+<a name="l00409"></a>00409 
+<a name="l00410"></a>00410      <span class="comment">/* this call originates 36 bytes leaks */</span>
+<a name="l00411"></a>00411      cknull(colImage  = sinfo_new_col_tilt( im_obj, cfg->sigmaFactor ),
+<a name="l00412"></a>00412         <span class="stringliteral">"sinfo_colTilt failed"</span> );
+<a name="l00413"></a>00413 
+<a name="l00414"></a>00414      cknull(stats = sinfo_new_image_stats_on_rectangle(colImage, 
+<a name="l00415"></a>00415                                    cfg->badLoReject, 
+<a name="l00416"></a>00416                                    cfg->badHiReject, 
+<a name="l00417"></a>00417                                    cfg->llx, 
+<a name="l00418"></a>00418                                    cfg->lly, 
+<a name="l00419"></a>00419                                    cfg->urx, 
+<a name="l00420"></a>00420                                cfg->ury),
+<a name="l00421"></a>00421                                    <span class="stringliteral">"sinfo_get_image_stats_on_vig failed\n"</span>);
+<a name="l00422"></a>00422      
+<a name="l00423"></a>00423      local_clean_mean = stats->cleanmean;
+<a name="l00424"></a>00424      clean_stdev = stats->cleanstdev;
+<a name="l00425"></a>00425 
+<a name="l00426"></a>00426 
+<a name="l00427"></a>00427      <span class="comment">/* indicate pixels with great deviations from the clean mean as bad */</span>
+<a name="l00428"></a>00428      <span class="keywordflow">if</span> (cfg->threshInd == 1) {
+<a name="l00429"></a>00429          cknull(threshIm = sinfo_new_thresh_image(colImage, 
+<a name="l00430"></a>00430             local_clean_mean-mean_factor*clean_stdev,
+<a name="l00431"></a>00431             local_clean_mean+mean_factor*clean_stdev),
+<a name="l00432"></a>00432         <span class="stringliteral">" sinfo_threshImage failed\n"</span> );
+<a name="l00433"></a>00433      }
+<a name="l00434"></a>00434      <span class="keywordflow">if</span> (cfg->threshInd == 0) {
+<a name="l00435"></a>00435         threshIm = colImage;
+<a name="l00436"></a>00436      }
+<a name="l00437"></a>00437 
+<a name="l00438"></a>00438      <span class="comment">/*</span>
+<a name="l00439"></a>00439 <span class="comment">     filter iteratively the images by a sinfo_median filter of the nearest </span>
+<a name="l00440"></a>00440 <span class="comment">     neighbors under the condition of a deviation greater than a factor </span>
+<a name="l00441"></a>00441 <span class="comment">     times the standard deviation</span>
+<a name="l00442"></a>00442 <span class="comment">     */</span>
+<a name="l00443"></a>00443 
+<a name="l00444"></a>00444      cknull(imMed[0]= sinfo_new_median_image(threshIm,-cfg->factor*clean_stdev),
+<a name="l00445"></a>00445                                             <span class="stringliteral">" sinfo_medianImage failed"</span> );
+<a name="l00446"></a>00446      
+<a name="l00447"></a>00447 
+<a name="l00448"></a>00448        <span class="comment">/* AMO check again if here the loop start and ending point are proper */</span>
+<a name="l00449"></a>00449 
+<a name="l00450"></a>00450      <span class="keywordflow">for</span> (i=1; i< cfg->iterations+1; i++) {
+<a name="l00451"></a>00451        cknull(imMed[i]=sinfo_new_median_image(imMed[i-1], 
+<a name="l00452"></a>00452                           -cfg->factor*clean_stdev),
+<a name="l00453"></a>00453                                           <span class="stringliteral">"sinfo_medianImage failed"</span> );
+<a name="l00454"></a>00454      }
+<a name="l00455"></a>00455 
+<a name="l00456"></a>00456      <span class="comment">/* compare the filtered image with the input image */</span>
+<a name="l00457"></a>00457      cknull(compImage=sinfo_new_compare_images(threshIm, 
+<a name="l00458"></a>00458                                                imMed[cfg->iterations], 
+<a name="l00459"></a>00459                                                im_obj),
+<a name="l00460"></a>00460         <span class="stringliteral">"sinfo_compareImages failed"</span> );
+<a name="l00461"></a>00461 
+<a name="l00462"></a>00462      <span class="comment">/*---generate the bad pixel mask */</span>
+<a name="l00463"></a>00463      n = (<span class="keywordtype">int</span>*)cpl_calloc(1,<span class="keyword">sizeof</span>(<span class="keywordtype">int</span>));
+<a name="l00464"></a>00464      cknull(maskImage = sinfo_new_promote_image_to_mask( compImage, n ),
+<a name="l00465"></a>00465             <span class="stringliteral">"error in sinfo_promoteImageToMask"</span> );
+<a name="l00466"></a>00466 
+<a name="l00467"></a>00467 
+<a name="l00468"></a>00468      n_badpixels = n[0];
+<a name="l00469"></a>00469      sinfo_msg(<span class="stringliteral">"No of bad pixels: %d"</span>, n_badpixels);
+<a name="l00470"></a>00470 
+<a name="l00471"></a>00471      cknull_nomsg(qclog_tbl = sinfo_qclog_init());
+<a name="l00472"></a>00472      ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,<span class="stringliteral">"QC BP-MAP NBADPIX"</span>,n_badpixels,
+<a name="l00473"></a>00473                                    <span class="stringliteral">"No of bad pixels"</span>,<span class="stringliteral">"%d"</span>));
+<a name="l00474"></a>00474 
+<a name="l00475"></a>00475      ck0(sinfo_pro_save_ima(maskImage,ref_set,sof,cfg->maskname,
+<a name="l00476"></a>00476                   PRO_BP_MAP,qclog_tbl,plugin_id,config),
+<a name="l00477"></a>00477                <span class="stringliteral">"cannot save ima %s"</span>, cfg->maskname);
+<a name="l00478"></a>00478 
+<a name="l00479"></a>00479 
+<a name="l00480"></a>00480      <span class="comment">/* free memory */</span>
+<a name="l00481"></a>00481      sinfo_free_table(&qclog_tbl);
+<a name="l00482"></a>00482  
+<a name="l00483"></a>00483      sinfo_new_del_Stats(stats);
+<a name="l00484"></a>00484      sinfo_free_int(&n);
+<a name="l00485"></a>00485      sinfo_free_image(&threshIm); <span class="comment">/* */</span>
+<a name="l00486"></a>00486      <span class="keywordflow">if</span> (cfg->threshInd == 1) {
+<a name="l00487"></a>00487        sinfo_free_image(&colImage);
+<a name="l00488"></a>00488      }
+<a name="l00489"></a>00489      sinfo_free_image(&compImage);
+<a name="l00490"></a>00490      sinfo_free_image(&maskImage);
+<a name="l00491"></a>00491 
+<a name="l00492"></a>00492      <span class="keywordflow">for</span> (i=0; i< cfg->iterations+1; i++) {
+<a name="l00493"></a>00493        sinfo_free_image(&imMed[i]);
+<a name="l00494"></a>00494      }
+<a name="l00495"></a>00495 
+<a name="l00496"></a>00496    }
+<a name="l00497"></a>00497 
+<a name="l00498"></a>00498    cpl_free(imMed);
+<a name="l00499"></a>00499    imMed=NULL;
+<a name="l00500"></a>00500 
+<a name="l00501"></a>00501    <span class="comment">/*</span>
+<a name="l00502"></a>00502 <span class="comment">   #---------------------------------------------------------</span>
+<a name="l00503"></a>00503 <span class="comment">   # Master flat field: static bad pixel correction and normalizing</span>
+<a name="l00504"></a>00504 <span class="comment">   #---------------------------------------------------------</span>
+<a name="l00505"></a>00505 <span class="comment">   */</span>
+<a name="l00506"></a>00506 
+<a name="l00507"></a>00507    sinfo_msg(<span class="stringliteral">"Creates a Master flat field"</span>);
+<a name="l00508"></a>00508    <span class="keywordflow">if</span> (cfg->interpolInd == 1) {
+<a name="l00509"></a>00509      cknull(mask_im = cpl_image_load(cfg->mask,CPL_TYPE_FLOAT,0,0),
+<a name="l00510"></a>00510         <span class="stringliteral">"could not load static bad pixel mask"</span> );
+<a name="l00511"></a>00511 
+<a name="l00512"></a>00512       <span class="comment">/* open the ASCII list of the slitlet positions */</span>
+<a name="l00513"></a>00513 
+<a name="l00514"></a>00514       <span class="comment">/* slit_edges = sinfo_new_2Dfloat_array(32, 2) ; */</span>
+<a name="l00515"></a>00515       slit_edges = (<span class="keywordtype">float</span> **) cpl_calloc( 32, <span class="keyword">sizeof</span> (<span class="keywordtype">float</span>*) ) ;
+<a name="l00516"></a>00516       <span class="keywordflow">for</span> ( i = 0 ; i < 32 ; i++ )
+<a name="l00517"></a>00517         {
+<a name="l00518"></a>00518             slit_edges[i] = (<span class="keywordtype">float</span> *) cpl_calloc( 2, <span class="keyword">sizeof</span> (<span class="keywordtype">float</span>)) ;
+<a name="l00519"></a>00519         }
+<a name="l00520"></a>00520       <span class="comment">/*READ TFITS TABLE*/</span>
+<a name="l00521"></a>00521       <span class="keywordflow">if</span>(sinfo_is_fits_file(cfg->slitposList) !=1 ) {
+<a name="l00522"></a>00522           <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Input file %s is not FITS"</span>, cfg->slitposList);
+<a name="l00523"></a>00523           <span class="keywordflow">goto</span> cleanup;
+<a name="l00524"></a>00524       }
+<a name="l00525"></a>00525       strcpy(tbl_slitpos_name,cfg->slitposList);
+<a name="l00526"></a>00526       check(tbl_slitpos = cpl_table_load(tbl_slitpos_name,1,0),
+<a name="l00527"></a>00527          <span class="stringliteral">"error loading tbl %s"</span>,tbl_slitpos_name);
+<a name="l00528"></a>00528 
+<a name="l00529"></a>00529       <span class="keywordflow">for</span> (i =0 ; i< 32; i++){
+<a name="l00530"></a>00530             val_x=cpl_table_get_double(tbl_slitpos,<span class="stringliteral">"pos1"</span>,i,status);
+<a name="l00531"></a>00531             val_y=cpl_table_get_double(tbl_slitpos,<span class="stringliteral">"pos2"</span>,i,status);
+<a name="l00532"></a>00532             slit_edges[i][0]=val_x;
+<a name="l00533"></a>00533         slit_edges[i][1]=val_y;
+<a name="l00534"></a>00534       }
+<a name="l00535"></a>00535       sinfo_free_table(&tbl_slitpos);
+<a name="l00536"></a>00536 
+<a name="l00537"></a>00537       cknull(int_im = sinfo_interpol_source_image (im_obj, mask_im, 
+<a name="l00538"></a>00538                                                  cfg->maxRad, slit_edges),
+<a name="l00539"></a>00539                          <span class="stringliteral">"could not carry out sinfo_interpolSourceImage"</span> );
+<a name="l00540"></a>00540       
+<a name="l00541"></a>00541       sinfo_free_image(&im_obj);
+<a name="l00542"></a>00542       cknull(norm = sinfo_new_normalize_to_central_pixel(int_im),
+<a name="l00543"></a>00543              <span class="stringliteral">"could not normalize flatfield"</span> );
+<a name="l00544"></a>00544       sinfo_free_image(&int_im);
+<a name="l00545"></a>00545       im_obj = norm; 
+<a name="l00546"></a>00546 
+<a name="l00547"></a>00547       <span class="keywordflow">if</span> (cfg->contains_dither == 1) {
+<a name="l00548"></a>00548         cknull(int_im_dith = sinfo_interpol_source_image(im_dither, 
+<a name="l00549"></a>00549                                mask_im,
+<a name="l00550"></a>00550                                cfg->maxRad,
+<a name="l00551"></a>00551                                slit_edges),
+<a name="l00552"></a>00552            <span class="stringliteral">"could not carry out sinfo_interpolSourceImage"</span> );
+<a name="l00553"></a>00553       
+<a name="l00554"></a>00554         cpl_image_delete(im_dither);
+<a name="l00555"></a>00555         cknull(norm_dith = sinfo_new_normalize_to_central_pixel(int_im_dith),
+<a name="l00556"></a>00556            <span class="stringliteral">"could not normalize flatfield"</span> );
+<a name="l00557"></a>00557         sinfo_free_image(&int_im_dith);
+<a name="l00558"></a>00558         im_dither = norm_dith;
+<a name="l00559"></a>00559       }
+<a name="l00560"></a>00560       <span class="comment">/* sinfo_new_destroy_2Dfloatarray(slit_edges, 32); */</span>    
+<a name="l00561"></a>00561       <span class="keywordflow">for</span> ( i = 0 ; i < 32 ; i++ )
+<a name="l00562"></a>00562         {
+<a name="l00563"></a>00563             cpl_free( slit_edges[i] );
+<a name="l00564"></a>00564         }
+<a name="l00565"></a>00565       cpl_free( slit_edges ) ;
+<a name="l00566"></a>00566       sinfo_free_image(&mask_im);
+<a name="l00567"></a>00567 
+<a name="l00568"></a>00568    }
+<a name="l00569"></a>00569 
+<a name="l00570"></a>00570    <span class="keywordflow">if</span> (cfg->interpolInd != 1) {
+<a name="l00571"></a>00571      cknull(norm = sinfo_new_normalize_to_central_pixel(im_obj),
+<a name="l00572"></a>00572             <span class="stringliteral">"could not normalize flatfield"</span> );
+<a name="l00573"></a>00573       sinfo_free_image(&im_obj);
+<a name="l00574"></a>00574       im_obj = norm; 
+<a name="l00575"></a>00575 
+<a name="l00576"></a>00576       <span class="keywordflow">if</span> (cfg->contains_dither == 1) {
+<a name="l00577"></a>00577         cknull(norm_dith = sinfo_new_normalize_to_central_pixel(im_dither),
+<a name="l00578"></a>00578            <span class="stringliteral">"could not normalize flatfield"</span> );
+<a name="l00579"></a>00579         sinfo_free_image(&im_dither);
+<a name="l00580"></a>00580         im_dither = norm_dith;
+<a name="l00581"></a>00581       }
+<a name="l00582"></a>00582    }
+<a name="l00583"></a>00583 
+<a name="l00584"></a>00584    naxis1=cpl_image_get_size_x(im_obj);
+<a name="l00585"></a>00585    naxis2=cpl_image_get_size_y(im_obj);
+<a name="l00586"></a>00586 
+<a name="l00587"></a>00587 
+<a name="l00588"></a>00588    <span class="keywordflow">if</span>(cfg->qc_fpn_xmin1 < 1) {
+<a name="l00589"></a>00589      <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"qc_ron_xmin < 1"</span>);
+<a name="l00590"></a>00590      <span class="keywordflow">goto</span> cleanup;
+<a name="l00591"></a>00591    }
+<a name="l00592"></a>00592 
+<a name="l00593"></a>00593    <span class="keywordflow">if</span>(cfg->qc_fpn_xmax1 > naxis1) {
+<a name="l00594"></a>00594      <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"qc_ron_xmax < %d"</span>,naxis1);
+<a name="l00595"></a>00595      <span class="keywordflow">goto</span> cleanup;
+<a name="l00596"></a>00596    }
+<a name="l00597"></a>00597 
+<a name="l00598"></a>00598    <span class="keywordflow">if</span>(cfg->qc_fpn_ymin1 < 1) {
+<a name="l00599"></a>00599      <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"qc_ron_ymin < 1"</span>);
+<a name="l00600"></a>00600      <span class="keywordflow">goto</span> cleanup;
+<a name="l00601"></a>00601    }
+<a name="l00602"></a>00602 
+<a name="l00603"></a>00603    <span class="keywordflow">if</span>(cfg->qc_fpn_ymax1 > naxis2) {
+<a name="l00604"></a>00604      <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"qc_ron_ymax < %d"</span>,naxis2);
+<a name="l00605"></a>00605      <span class="keywordflow">goto</span> cleanup;
+<a name="l00606"></a>00606    }
+<a name="l00607"></a>00607    fpn_stdev1 = cpl_image_get_stdev_window(im_obj,
+<a name="l00608"></a>00608                        cfg->qc_fpn_xmin1,
+<a name="l00609"></a>00609                        cfg->qc_fpn_ymin1,
+<a name="l00610"></a>00610                        cfg->qc_fpn_xmax1,
+<a name="l00611"></a>00611                        cfg->qc_fpn_ymax1);
+<a name="l00612"></a>00612 
+<a name="l00613"></a>00613 
+<a name="l00614"></a>00614    <span class="keywordflow">if</span>(cfg->qc_fpn_xmin2 < 1) {
+<a name="l00615"></a>00615      <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"qc_ron_xmin < %d"</span>,1);
+<a name="l00616"></a>00616      <span class="keywordflow">goto</span> cleanup;
+<a name="l00617"></a>00617    }
+<a name="l00618"></a>00618 
+<a name="l00619"></a>00619 
+<a name="l00620"></a>00620    <span class="keywordflow">if</span>(cfg->qc_fpn_xmax2 > naxis1) {
+<a name="l00621"></a>00621      <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"qc_ron_xmax < %d"</span>,naxis1);
+<a name="l00622"></a>00622      <span class="keywordflow">goto</span> cleanup;
+<a name="l00623"></a>00623    }
+<a name="l00624"></a>00624 
+<a name="l00625"></a>00625    <span class="keywordflow">if</span>(cfg->qc_fpn_ymin2 < 1) {
+<a name="l00626"></a>00626      <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"qc_ron_ymin < 1"</span>);
+<a name="l00627"></a>00627      <span class="keywordflow">goto</span> cleanup;
+<a name="l00628"></a>00628    }
+<a name="l00629"></a>00629 
+<a name="l00630"></a>00630    <span class="keywordflow">if</span>(cfg->qc_fpn_ymax2 > naxis2) {
+<a name="l00631"></a>00631      <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"qc_ron_ymax < %d"</span>,naxis2);
+<a name="l00632"></a>00632      <span class="keywordflow">goto</span> cleanup;
+<a name="l00633"></a>00633    }
+<a name="l00634"></a>00634    fpn_stdev2 = cpl_image_get_stdev_window(im_obj,
+<a name="l00635"></a>00635                        cfg->qc_fpn_xmin2,
+<a name="l00636"></a>00636                        cfg->qc_fpn_ymin2,
+<a name="l00637"></a>00637                        cfg->qc_fpn_xmax2,
+<a name="l00638"></a>00638                        cfg->qc_fpn_ymax2);
+<a name="l00639"></a>00639 
+<a name="l00640"></a>00640 
+<a name="l00641"></a>00641 
+<a name="l00642"></a>00642    ck0(new_lamp_flats_det_ncounts(raw,cfg),<span class="stringliteral">"error computing number of counts"</span>);
+<a name="l00643"></a>00643    cknull_nomsg(qclog_tbl = sinfo_qclog_init());
+<a name="l00644"></a>00644    ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,<span class="stringliteral">"QC SPECFLAT NCNTSAVG"</span>,
+<a name="l00645"></a>00645                                     qc_lampflat.avg_di,<span class="stringliteral">"Average counts"</span>,<span class="stringliteral">"%g"</span>));
+<a name="l00646"></a>00646    ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,<span class="stringliteral">"QC SPECFLAT NCNTSSTD"</span>,
+<a name="l00647"></a>00647                                     qc_lampflat.std_di,<span class="stringliteral">"Stdev counts"</span>,<span class="stringliteral">"%g"</span>));
+<a name="l00648"></a>00648    ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,<span class="stringliteral">"QC SPECFLAT OFFFLUX"</span>,
+<a name="l00649"></a>00649                                     qc_lampflat.avg_of,
+<a name="l00650"></a>00650                                     <span class="stringliteral">"Average flux off frames"</span>,<span class="stringliteral">"%g"</span>));
+<a name="l00651"></a>00651 
+<a name="l00652"></a>00652     ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,
+<a name="l00653"></a>00653                                      <span class="stringliteral">"QC LFLAT FPN1"</span>,
+<a name="l00654"></a>00654                                      fpn_stdev1,
+<a name="l00655"></a>00655                                      <span class="stringliteral">"Fixed Pattern Noise of combined frames"</span>,
+<a name="l00656"></a>00656                                      <span class="stringliteral">"%f"</span>));
+<a name="l00657"></a>00657 
+<a name="l00658"></a>00658     ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,
+<a name="l00659"></a>00659                                      <span class="stringliteral">"QC LFLAT FPN2"</span>,
+<a name="l00660"></a>00660                                      fpn_stdev2,
+<a name="l00661"></a>00661                                      <span class="stringliteral">"Fixed Pattern Noise of combined frames"</span>,
+<a name="l00662"></a>00662                                      <span class="stringliteral">"%f"</span>));
+<a name="l00663"></a>00663 
+<a name="l00664"></a>00664       ck0(sinfo_pro_save_ima(im_obj,ref_set,sof,cfg->outName,
+<a name="l00665"></a>00665                  PRO_MASTER_FLAT_LAMP,qclog_tbl,plugin_id,config),
+<a name="l00666"></a>00666       <span class="stringliteral">"cannot save ima %s"</span>, cfg->outName);
+<a name="l00667"></a>00667 
+<a name="l00668"></a>00668     sinfo_free_table(&qclog_tbl);
+<a name="l00669"></a>00669     sinfo_free_image(&im_obj);
+<a name="l00670"></a>00670 
+<a name="l00671"></a>00671  
+<a name="l00672"></a>00672     <span class="keywordflow">if</span> (cfg->contains_dither == 1) {
+<a name="l00673"></a>00673 
+<a name="l00674"></a>00674       <span class="keywordflow">if</span> (strstr(cfg->outName, <span class="stringliteral">".fits"</span> ) != NULL ) {
+<a name="l00675"></a>00675 
+<a name="l00676"></a>00676     snprintf(name_list, MAX_NAME_SIZE-1,<span class="stringliteral">"%s%s"</span>, 
+<a name="l00677"></a>00677          sinfo_new_get_rootname(cfg->outName),
+<a name="l00678"></a>00678                 <span class="stringliteral">"_dither"</span>);
+<a name="l00679"></a>00679         strcpy(outNameDither,name_list);
+<a name="l00680"></a>00680         strcat(outNameDither,strstr(cfg->outName,<span class="stringliteral">".fits"</span>));
+<a name="l00681"></a>00681        
+<a name="l00682"></a>00682       } <span class="keywordflow">else</span> {
+<a name="l00683"></a>00683         strcpy(outNameDither,cfg->outName);
+<a name="l00684"></a>00684         strcat(outNameDither,<span class="stringliteral">"_dither"</span>);
+<a name="l00685"></a>00685       }
+<a name="l00686"></a>00686 
+<a name="l00687"></a>00687 
+<a name="l00688"></a>00688       naxis1=cpl_image_get_size_x(im_dither);
+<a name="l00689"></a>00689       naxis2=cpl_image_get_size_y(im_dither);
+<a name="l00690"></a>00690 
+<a name="l00691"></a>00691 
+<a name="l00692"></a>00692       <span class="keywordflow">if</span>(cfg->qc_fpn_xmin1 < 1) {
+<a name="l00693"></a>00693      <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"qc_ron_xmin1 < 1"</span>);
+<a name="l00694"></a>00694          <span class="keywordflow">goto</span> cleanup;
+<a name="l00695"></a>00695       }
+<a name="l00696"></a>00696 
+<a name="l00697"></a>00697       <span class="keywordflow">if</span>(cfg->qc_fpn_xmax1 > naxis1) {
+<a name="l00698"></a>00698      <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"qc_ron_xmax1 < %d"</span>,naxis1);
+<a name="l00699"></a>00699          <span class="keywordflow">goto</span> cleanup;
+<a name="l00700"></a>00700       }
+<a name="l00701"></a>00701 
+<a name="l00702"></a>00702       <span class="keywordflow">if</span>(cfg->qc_fpn_ymin1 < 1) {
+<a name="l00703"></a>00703      <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"qc_ron_ymin1 < 1"</span>);
+<a name="l00704"></a>00704          <span class="keywordflow">goto</span> cleanup;
+<a name="l00705"></a>00705       }
+<a name="l00706"></a>00706 
+<a name="l00707"></a>00707       <span class="keywordflow">if</span>(cfg->qc_fpn_ymax1 > naxis2) {
+<a name="l00708"></a>00708      <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"qc_ron_ymax1 < %d"</span>,naxis2);
+<a name="l00709"></a>00709          <span class="keywordflow">goto</span> cleanup;
+<a name="l00710"></a>00710       }
+<a name="l00711"></a>00711 
+<a name="l00712"></a>00712  
+<a name="l00713"></a>00713       fpn_stdev1 = cpl_image_get_stdev_window(im_dither,
+<a name="l00714"></a>00714                           cfg->qc_fpn_xmin1,
+<a name="l00715"></a>00715                           cfg->qc_fpn_ymin1,
+<a name="l00716"></a>00716                           cfg->qc_fpn_xmax1,
+<a name="l00717"></a>00717                           cfg->qc_fpn_ymax1);
+<a name="l00718"></a>00718 
+<a name="l00719"></a>00719       <span class="keywordflow">if</span>(cfg->qc_fpn_xmin2 < 1) {
+<a name="l00720"></a>00720      <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"qc_ron_xmin2 < 1"</span>);
+<a name="l00721"></a>00721          <span class="keywordflow">goto</span> cleanup;
+<a name="l00722"></a>00722       }
+<a name="l00723"></a>00723 
+<a name="l00724"></a>00724       <span class="keywordflow">if</span>(cfg->qc_fpn_xmax2 > naxis1) {
+<a name="l00725"></a>00725      <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"qc_ron_xmax2 < %d"</span>,naxis1);
+<a name="l00726"></a>00726          <span class="keywordflow">goto</span> cleanup;
+<a name="l00727"></a>00727       }
+<a name="l00728"></a>00728 
+<a name="l00729"></a>00729       <span class="keywordflow">if</span>(cfg->qc_fpn_ymin2 < 1) {
+<a name="l00730"></a>00730      <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"qc_ron_ymin2 < 1"</span>);
+<a name="l00731"></a>00731          <span class="keywordflow">goto</span> cleanup;
+<a name="l00732"></a>00732       }
+<a name="l00733"></a>00733 
+<a name="l00734"></a>00734       <span class="keywordflow">if</span>(cfg->qc_fpn_ymax2 > naxis2) {
+<a name="l00735"></a>00735      <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"qc_ron_ymax2 < %d"</span>,naxis2);
+<a name="l00736"></a>00736          <span class="keywordflow">goto</span> cleanup;
+<a name="l00737"></a>00737       }
+<a name="l00738"></a>00738  
+<a name="l00739"></a>00739       fpn_stdev2 = cpl_image_get_stdev_window(im_dither,
+<a name="l00740"></a>00740                           cfg->qc_fpn_xmin2,
+<a name="l00741"></a>00741                           cfg->qc_fpn_ymin2,
+<a name="l00742"></a>00742                           cfg->qc_fpn_xmax2,
+<a name="l00743"></a>00743                           cfg->qc_fpn_ymax2);
+<a name="l00744"></a>00744 
+<a name="l00745"></a>00745 
+<a name="l00746"></a>00746       ck0(new_lamp_flats_det_ncounts(raw,cfg),<span class="stringliteral">"error computing ncounts"</span>);
+<a name="l00747"></a>00747       cknull_nomsg(qclog_tbl = sinfo_qclog_init());
+<a name="l00748"></a>00748       ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,<span class="stringliteral">"QC SPECFLAT NCNTSAVG"</span>,
+<a name="l00749"></a>00749                        qc_lampflat.avg_di,<span class="stringliteral">"Average counts"</span>,<span class="stringliteral">"%g"</span>));
+<a name="l00750"></a>00750 
+<a name="l00751"></a>00751       ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,<span class="stringliteral">"QC SPECFLAT NCNTSSTD"</span>,
+<a name="l00752"></a>00752                        qc_lampflat.std_di,<span class="stringliteral">"Stdev counts"</span>,<span class="stringliteral">"%g"</span>));
+<a name="l00753"></a>00753 
+<a name="l00754"></a>00754       ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,<span class="stringliteral">"QC SPECFLAT OFFFLUX"</span>,
+<a name="l00755"></a>00755                        qc_lampflat.avg_of,<span class="stringliteral">"Average flux off frames"</span>,<span class="stringliteral">"%g"</span>));
+<a name="l00756"></a>00756 
+<a name="l00757"></a>00757       ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,<span class="stringliteral">"QC LFLAT FPN1"</span>,fpn_stdev1,
+<a name="l00758"></a>00758                        <span class="stringliteral">"Fixed Pattern Noise of combined frames"</span>,<span class="stringliteral">"%f"</span>));
+<a name="l00759"></a>00759 
+<a name="l00760"></a>00760       ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,<span class="stringliteral">"QC LFLAT FPN2"</span>,fpn_stdev2,
+<a name="l00761"></a>00761                        <span class="stringliteral">"Fixed Pattern Noise of combined frames"</span>,<span class="stringliteral">"%f"</span>));
+<a name="l00762"></a>00762  
+<a name="l00763"></a>00763 
+<a name="l00764"></a>00764     ck0(sinfo_pro_save_ima(im_dither,ref_set,sof,outNameDither,
+<a name="l00765"></a>00765                    PRO_MASTER_FLAT_LAMP,qclog_tbl,plugin_id,config),
+<a name="l00766"></a>00766         <span class="stringliteral">"cannot save ima %s"</span>, outNameDither);
+<a name="l00767"></a>00767 
+<a name="l00768"></a>00768       sinfo_free_table(&qclog_tbl);
+<a name="l00769"></a>00769       sinfo_free_image(&im_dither);
+<a name="l00770"></a>00770 
+<a name="l00771"></a>00771     }
+<a name="l00772"></a>00772 
+<a name="l00773"></a>00773 
+<a name="l00774"></a>00774     <span class="comment">/* could be done earlier? */</span>
+<a name="l00775"></a>00775     sinfo_free_image_array(&im,cfg->nframes);
+<a name="l00776"></a>00776     sinfo_free_frameset(&raw);
+<a name="l00777"></a>00777     sinfo_flat_free(&cfg);
+<a name="l00778"></a>00778     <span class="keywordflow">return</span> 0;
+<a name="l00779"></a>00779 
+<a name="l00780"></a>00780 cleanup:
+<a name="l00781"></a>00781 
+<a name="l00782"></a>00782 
+<a name="l00783"></a>00783     <span class="comment">/* free memory */</span>
+<a name="l00784"></a>00784     <span class="keywordflow">if</span>(slit_edges != NULL) {
+<a name="l00785"></a>00785       <span class="keywordflow">for</span> ( i = 0 ; i < 32 ; i++ )
+<a name="l00786"></a>00786         {
+<a name="l00787"></a>00787       <span class="keywordflow">if</span>(slit_edges[i] != NULL) {
+<a name="l00788"></a>00788             cpl_free( slit_edges[i] );
+<a name="l00789"></a>00789       }
+<a name="l00790"></a>00790           slit_edges[i]=NULL;
+<a name="l00791"></a>00791         }
+<a name="l00792"></a>00792       cpl_free( slit_edges ) ;
+<a name="l00793"></a>00793     }
+<a name="l00794"></a>00794     sinfo_free_image(&mask_im);
+<a name="l00795"></a>00795     sinfo_free_table(&qclog_tbl);
+<a name="l00796"></a>00796     <span class="keywordflow">if</span>(stats) {
+<a name="l00797"></a>00797       sinfo_new_del_Stats(stats);
+<a name="l00798"></a>00798     }
+<a name="l00799"></a>00799     sinfo_free_int(&n);
+<a name="l00800"></a>00800     sinfo_free_image(&threshIm);
+<a name="l00801"></a>00801     sinfo_free_image(&maskImage);
+<a name="l00802"></a>00802     <span class="keywordflow">if</span>(imMed != NULL) sinfo_free_image_array(&imMed,cfg->iterations);
+<a name="l00803"></a>00803     <span class="keywordflow">if</span>(stats!= NULL) {
+<a name="l00804"></a>00804         sinfo_new_del_Stats(stats);
+<a name="l00805"></a>00805         stats=NULL;
+<a name="l00806"></a>00806     }
+<a name="l00807"></a>00807     sinfo_free_image(&compImage);
+<a name="l00808"></a>00808     sinfo_free_image(&colImage);
+<a name="l00809"></a>00809     sinfo_free_imagelist(&list_dither_object);
+<a name="l00810"></a>00810     sinfo_free_imagelist(&list_dither_sky);
+<a name="l00811"></a>00811     <span class="keywordflow">if</span>(list_sky != NULL) {
+<a name="l00812"></a>00812        sinfo_free_imagelist(&list_sky);
+<a name="l00813"></a>00813     }
+<a name="l00814"></a>00814     sinfo_free_imagelist(&list_object);
+<a name="l00815"></a>00815     sinfo_free_image(&im_dither);
+<a name="l00816"></a>00816     sinfo_free_image(&im_dither_sky);
+<a name="l00817"></a>00817     sinfo_free_image(&im_obj);
+<a name="l00818"></a>00818     sinfo_free_image(&im_sky);
+<a name="l00819"></a>00819     <span class="keywordflow">if</span>(im != NULL) sinfo_free_image_array(&im,cfg->nframes);
+<a name="l00820"></a>00820     sinfo_free_frameset(&raw);
+<a name="l00821"></a>00821     <span class="keywordflow">if</span>(cfg != NULL) {
+<a name="l00822"></a>00822       sinfo_flat_free(&cfg);
+<a name="l00823"></a>00823     }
+<a name="l00824"></a>00824     <span class="keywordflow">return</span> -1;
+<a name="l00825"></a>00825 
+<a name="l00826"></a>00826 }
+<a name="l00827"></a>00827 
+<a name="l00828"></a>00828 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00829"></a>00829 new_lamp_flats_det_ncounts(cpl_frameset* raw, flat_config* cfg)
+<a name="l00830"></a>00830 {
+<a name="l00831"></a>00831  <span class="keywordtype">int</span> i=0;
+<a name="l00832"></a>00832  <span class="keywordtype">int</span> j=0;
+<a name="l00833"></a>00833 
+<a name="l00834"></a>00834  <span class="keywordtype">int</span> nraw=0;
+<a name="l00835"></a>00835  <span class="keywordtype">int</span> non=0;
+<a name="l00836"></a>00836  <span class="keywordtype">int</span> noff=0;
+<a name="l00837"></a>00837 
+<a name="l00838"></a>00838  <span class="keywordtype">double</span> mjd_on=0;
+<a name="l00839"></a>00839  <span class="keywordtype">double</span> mjd_of=0;
+<a name="l00840"></a>00840  <span class="keywordtype">double</span> mjd_of_frm=0;
+<a name="l00841"></a>00841 
+<a name="l00842"></a>00842  <span class="keywordtype">char</span> filename[MAX_NAME_SIZE];
+<a name="l00843"></a>00843 
+<a name="l00844"></a>00844  cpl_frame* frm=NULL;
+<a name="l00845"></a>00845  cpl_frame* frm_dup=NULL;
+<a name="l00846"></a>00846  cpl_frame* on_frm=NULL;
+<a name="l00847"></a>00847  cpl_frame* of_frm=NULL;
+<a name="l00848"></a>00848  cpl_frame* tmp_of_frm=NULL;
+<a name="l00849"></a>00849 
+<a name="l00850"></a>00850 
+<a name="l00851"></a>00851  cpl_frameset* on_set=NULL;
+<a name="l00852"></a>00852  cpl_frameset* of_set=NULL;
+<a name="l00853"></a>00853  cpl_frameset* wrk_set=NULL;
+<a name="l00854"></a>00854 
+<a name="l00855"></a>00855  on_set=cpl_frameset_new();
+<a name="l00856"></a>00856  of_set=cpl_frameset_new();
+<a name="l00857"></a>00857 
+<a name="l00858"></a>00858  nraw = cpl_frameset_get_size(raw);
+<a name="l00859"></a>00859 
+<a name="l00860"></a>00860  <span class="keywordflow">for</span> (i=0; i< nraw; i++) {
+<a name="l00861"></a>00861    frm = cpl_frameset_get_frame(raw,i);
+<a name="l00862"></a>00862    frm_dup = cpl_frame_duplicate(frm);
+<a name="l00863"></a>00863    <span class="keywordflow">if</span>(sinfo_frame_is_on(frm) == 1) {
+<a name="l00864"></a>00864      cpl_frameset_insert(on_set,frm_dup);
+<a name="l00865"></a>00865      non++;
+<a name="l00866"></a>00866    } <span class="keywordflow">else</span> {
+<a name="l00867"></a>00867      cpl_frameset_insert(of_set,frm_dup);
+<a name="l00868"></a>00868      noff++;
+<a name="l00869"></a>00869    }
+<a name="l00870"></a>00870  }
+<a name="l00871"></a>00871 
+<a name="l00872"></a>00872 
+<a name="l00873"></a>00873  <span class="keywordflow">if</span> (non == noff) {
+<a name="l00874"></a>00874    new_qc_get_cnt(on_set,of_set,cfg);
+<a name="l00875"></a>00875 
+<a name="l00876"></a>00876  } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (non == 0) {
+<a name="l00877"></a>00877    sinfo_msg(<span class="stringliteral">"non == 0"</span>);
+<a name="l00878"></a>00878    <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"QC SPECFLAT NCNTAVG/NCTNTSTD/OFFFLUX=0 "</span>);
+<a name="l00879"></a>00879  
+<a name="l00880"></a>00880  } <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( noff == 0 ) {
+<a name="l00881"></a>00881    sinfo_msg(<span class="stringliteral">"noff == 0"</span>);
+<a name="l00882"></a>00882    <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"QC SPECFLAT NCNTAVG/NCTNTSTD/OFFFLUX=0 "</span>);
+<a name="l00883"></a>00883 
+<a name="l00884"></a>00884  } <span class="keywordflow">else</span> {
+<a name="l00885"></a>00885 
+<a name="l00886"></a>00886    <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"non != noff, => QC SPECFLAT NCNTAVG/NCTNTSTD/OFFFLUX=0 "</span>);
+<a name="l00887"></a>00887 
+<a name="l00888"></a>00888     <span class="keywordflow">for</span> (i=0;i<non;i++) {
+<a name="l00889"></a>00889        wrk_set=cpl_frameset_new();
+<a name="l00890"></a>00890        on_frm=cpl_frameset_get_frame(on_set,i);
+<a name="l00891"></a>00891        mjd_on=sinfo_get_mjd_obs(on_frm);
+<a name="l00892"></a>00892        of_frm=cpl_frameset_get_frame(of_set,0);
+<a name="l00893"></a>00893        mjd_of=sinfo_get_mjd_obs(of_frm);
+<a name="l00894"></a>00894        strcpy(filename,cpl_frame_get_filename(of_frm));
+<a name="l00895"></a>00895        <span class="keywordflow">for</span> (j=1;j<noff;j++) {
+<a name="l00896"></a>00896           tmp_of_frm = cpl_frameset_get_frame(of_set,j);
+<a name="l00897"></a>00897           mjd_of_frm = sinfo_get_mjd_obs(tmp_of_frm);
+<a name="l00898"></a>00898 
+<a name="l00899"></a>00899           <span class="keywordflow">if</span>(1000.*(mjd_of_frm-mjd_on)*(mjd_of_frm-mjd_on) <
+<a name="l00900"></a>00900              1000.*(mjd_of-    mjd_on)*(mjd_of-    mjd_on) ) {
+<a name="l00901"></a>00901             mjd_of=mjd_of_frm;
+<a name="l00902"></a>00902              of_frm=cpl_frame_duplicate(tmp_of_frm);
+<a name="l00903"></a>00903        }
+<a name="l00904"></a>00904        }
+<a name="l00905"></a>00905        strcpy(filename,cpl_frame_get_filename(of_frm));
+<a name="l00906"></a>00906        frm_dup=cpl_frame_duplicate(of_frm);
+<a name="l00907"></a>00907        cpl_frameset_insert(wrk_set,frm_dup);
+<a name="l00908"></a>00908        strcpy(filename,cpl_frame_get_filename(of_frm));
+<a name="l00909"></a>00909     }
+<a name="l00910"></a>00910     <span class="comment">/* Commented out as algorithm non robust if non != noff */</span>
+<a name="l00911"></a>00911     new_qc_get_cnt(on_set,wrk_set,cfg); 
+<a name="l00912"></a>00912 
+<a name="l00913"></a>00913  }
+<a name="l00914"></a>00914 
+<a name="l00915"></a>00915  cpl_frameset_delete(wrk_set);
+<a name="l00916"></a>00916  cpl_frameset_delete(on_set);
+<a name="l00917"></a>00917  cpl_frameset_delete(of_set);
+<a name="l00918"></a>00918  <span class="keywordflow">return</span> 0;
+<a name="l00919"></a>00919 
+<a name="l00920"></a>00920 
+<a name="l00921"></a>00921 }
+<a name="l00922"></a>00922 
+<a name="l00923"></a>00923 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00924"></a>00924 new_qc_get_cnt(cpl_frameset* on_set, cpl_frameset* of_set, flat_config* cfg)
+<a name="l00925"></a>00925 {
+<a name="l00926"></a>00926 
+<a name="l00927"></a>00927   <span class="keywordtype">int</span> i=0;
+<a name="l00928"></a>00928   <span class="keywordtype">int</span> nsat=0;
+<a name="l00929"></a>00929   <span class="keywordtype">int</span> non=0;
+<a name="l00930"></a>00930   <span class="keywordtype">int</span> nof=0;
+<a name="l00931"></a>00931   <span class="keywordtype">int</span> nfr=0;
+<a name="l00932"></a>00932 
+<a name="l00933"></a>00933   <span class="keywordtype">char</span> name[MAX_NAME_SIZE];
+<a name="l00934"></a>00934   cpl_vector* vec_on=NULL;
+<a name="l00935"></a>00935   cpl_vector* vec_of=NULL;
+<a name="l00936"></a>00936   cpl_vector* vec_di=NULL;
+<a name="l00937"></a>00937   cpl_vector* vec_nsat=NULL;
+<a name="l00938"></a>00938   cpl_frame* on_frm=NULL;
+<a name="l00939"></a>00939   cpl_frame* of_frm=NULL;
+<a name="l00940"></a>00940 
+<a name="l00941"></a>00941   cpl_image* dif_ima=NULL;
+<a name="l00942"></a>00942   cpl_image* on_ima=NULL;
+<a name="l00943"></a>00943   cpl_image* of_ima=NULL;
+<a name="l00944"></a>00944   cpl_image* tmp_ima=NULL;
+<a name="l00945"></a>00945 
+<a name="l00946"></a>00946   <span class="keywordtype">double</span> med=0;
+<a name="l00947"></a>00947     non = cpl_frameset_get_size(on_set);
+<a name="l00948"></a>00948     nof = cpl_frameset_get_size(of_set);
+<a name="l00949"></a>00949     nfr = (non <= nof) ? non : nof;
+<a name="l00950"></a>00950     vec_on = cpl_vector_new(nfr);
+<a name="l00951"></a>00951     vec_of = cpl_vector_new(nfr);
+<a name="l00952"></a>00952     vec_di = cpl_vector_new(nfr);
+<a name="l00953"></a>00953     vec_nsat = cpl_vector_new(nfr);
+<a name="l00954"></a>00954 
+<a name="l00955"></a>00955 
+<a name="l00956"></a>00956     <span class="keywordflow">for</span> (i=0; i< nfr; i++) {
+<a name="l00957"></a>00957       on_frm = cpl_frameset_get_frame(on_set,i);
+<a name="l00958"></a>00958       strcpy(name,cpl_frame_get_filename(on_frm));
+<a name="l00959"></a>00959       on_ima = cpl_image_load(name,CPL_TYPE_FLOAT,0,0);
+<a name="l00960"></a>00960       med= cpl_image_get_median(on_ima);
+<a name="l00961"></a>00961       cpl_vector_set(vec_on,i,med);
+<a name="l00962"></a>00962 
+<a name="l00963"></a>00963       tmp_ima = cpl_image_duplicate(on_ima);
+<a name="l00964"></a>00964       cpl_image_threshold(tmp_ima,SINFO_DBL_MIN,
+<a name="l00965"></a>00965                           cfg->qc_thresh_max,0,1);
+<a name="l00966"></a>00966       nsat=cpl_image_get_flux(tmp_ima);
+<a name="l00967"></a>00967       cpl_vector_set(vec_nsat,i,nsat);
+<a name="l00968"></a>00968 
+<a name="l00969"></a>00969    <span class="comment">/* Are you sure to have same frames off as on ? */</span>
+<a name="l00970"></a>00970       of_frm = cpl_frameset_get_frame(of_set,i);
+<a name="l00971"></a>00971       strcpy(name,cpl_frame_get_filename(of_frm));
+<a name="l00972"></a>00972       of_ima = cpl_image_load(name,CPL_TYPE_FLOAT,0,0);
+<a name="l00973"></a>00973       med= cpl_image_get_median(of_ima);
+<a name="l00974"></a>00974       cpl_vector_set(vec_of,i,med);
+<a name="l00975"></a>00975       dif_ima = cpl_image_subtract_create(on_ima,of_ima);
+<a name="l00976"></a>00976       med= cpl_image_get_median(dif_ima);
+<a name="l00977"></a>00977       cpl_vector_set(vec_di,i,med);
+<a name="l00978"></a>00978 
+<a name="l00979"></a>00979     cpl_image_delete(on_ima);
+<a name="l00980"></a>00980     cpl_image_delete(of_ima);
+<a name="l00981"></a>00981     cpl_image_delete(dif_ima);
+<a name="l00982"></a>00982     cpl_image_delete(tmp_ima);
+<a name="l00983"></a>00983     }
+<a name="l00984"></a>00984     qc_lampflat.avg_on=cpl_vector_get_mean(vec_on);
+<a name="l00985"></a>00985     qc_lampflat.avg_of=cpl_vector_get_mean(vec_of);
+<a name="l00986"></a>00986     qc_lampflat.avg_di=cpl_vector_get_mean(vec_di);
+<a name="l00987"></a>00987     <span class="keywordflow">if</span>(nfr > 1 ) {
+<a name="l00988"></a>00988        qc_lampflat.std_on=cpl_vector_get_stdev(vec_on);
+<a name="l00989"></a>00989        qc_lampflat.std_of=cpl_vector_get_stdev(vec_of);
+<a name="l00990"></a>00990        qc_lampflat.std_di=cpl_vector_get_stdev(vec_di);
+<a name="l00991"></a>00991     }
+<a name="l00992"></a>00992     qc_lampflat.nsat=cpl_vector_get_mean(vec_nsat);
+<a name="l00993"></a>00993     cpl_vector_delete(vec_on);
+<a name="l00994"></a>00994     cpl_vector_delete(vec_of);
+<a name="l00995"></a>00995     cpl_vector_delete(vec_di);
+<a name="l00996"></a>00996     cpl_vector_delete(vec_nsat);
+<a name="l00997"></a>00997     <span class="comment">/*</span>
+<a name="l00998"></a>00998 <span class="comment">    sinfo_msg( "sinfo_qc_get_cnt","avg_on=%g std_on=%g ",</span>
+<a name="l00999"></a>00999 <span class="comment">                      qc_lampflat.avg_on,qc_lampflat.std_on);</span>
+<a name="l01000"></a>01000 <span class="comment">    sinfo_msg( "sinfo_qc_get_cnt","avg_of=%g std_of=%g ",</span>
+<a name="l01001"></a>01001 <span class="comment">                      qc_lampflat.avg_of,qc_lampflat.std_of);</span>
+<a name="l01002"></a>01002 <span class="comment">    sinfo_msg( "sinfo_qc_get_cnt","avg_di=%g std_di=%g ",</span>
+<a name="l01003"></a>01003 <span class="comment">                      qc_lampflat.avg_di,qc_lampflat.std_di);</span>
+<a name="l01004"></a>01004 <span class="comment">    sinfo_msg( "sinfo_qc_get_cnt","nsat=%g ",qc_lampflat.nsat);</span>
+<a name="l01005"></a>01005 <span class="comment">    */</span>
+<a name="l01006"></a>01006     <span class="keywordflow">return</span> 0;
+<a name="l01007"></a>01007 }
+<a name="l01008"></a>01008 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__new__lamp__flats_8h_source.html b/html/sinfo__new__lamp__flats_8h_source.html
new file mode 100644
index 0000000..9938759
--- /dev/null
+++ b/html/sinfo__new__lamp__flats_8h_source.html
@@ -0,0 +1,93 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_new_lamp_flats.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_new_lamp_flats.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#ifndef SINFO_NEW_LAMP_FLATS_H</span>
+<a name="l00002"></a>00002 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_NEW_LAMP_FLATS_H</span>
+<a name="l00003"></a>00003 <span class="preprocessor"></span><span class="comment">/*</span>
+<a name="l00004"></a>00004 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00005"></a>00005 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00006"></a>00006 <span class="comment"> *</span>
+<a name="l00007"></a>00007 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00008"></a>00008 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00009"></a>00009 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00010"></a>00010 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00011"></a>00011 <span class="comment"> *</span>
+<a name="l00012"></a>00012 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00013"></a>00013 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00014"></a>00014 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00015"></a>00015 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00016"></a>00016 <span class="comment"> *</span>
+<a name="l00017"></a>00017 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00018"></a>00018 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00019"></a>00019 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00020"></a>00020 <span class="comment"> */</span>
+<a name="l00021"></a>00021 <span class="comment">/*****************************************************************************</span>
+<a name="l00022"></a>00022 <span class="comment">* E.S.O. - VLT project</span>
+<a name="l00023"></a>00023 <span class="comment">*</span>
+<a name="l00024"></a>00024 <span class="comment">* "@(#) $Id: sinfo_new_lamp_flats.h,v 1.9 2007/09/21 14:13:43 amodigli Exp $"</span>
+<a name="l00025"></a>00025 <span class="comment">*</span>
+<a name="l00026"></a>00026 <span class="comment">* who       when      what</span>
+<a name="l00027"></a>00027 <span class="comment">* --------  --------  ----------------------------------------------</span>
+<a name="l00028"></a>00028 <span class="comment">* amodigli  17/09/03  created</span>
+<a name="l00029"></a>00029 <span class="comment">*/</span>
+<a name="l00030"></a>00030 
+<a name="l00031"></a>00031 <span class="comment">/************************************************************************</span>
+<a name="l00032"></a>00032 <span class="comment"> * sinfo_new_lamp_flats.h</span>
+<a name="l00033"></a>00033 <span class="comment"> * this step handles stacks of lamp flat fields, </span>
+<a name="l00034"></a>00034 <span class="comment"> *  o it takes a clean mean,</span>
+<a name="l00035"></a>00035 <span class="comment"> *  o subtracts the off- from the on-frames, </span>
+<a name="l00036"></a>00036 <span class="comment"> *  o corrects for static bad pixels and normalizes for a master flat field. </span>
+<a name="l00037"></a>00037 <span class="comment"> *  o It distinguishes the spectrally dithered frames and </span>
+<a name="l00038"></a>00038 <span class="comment"> *  o treats them the same way. </span>
+<a name="l00039"></a>00039 <span class="comment"> *  o It can also generate a static bad pixel mask if wished.</span>
+<a name="l00040"></a>00040 <span class="comment"> *----------------------------------------------------------------------</span>
+<a name="l00041"></a>00041 <span class="comment"> */</span>
+<a name="l00042"></a>00042 
+<a name="l00043"></a>00043 <span class="comment">/*</span>
+<a name="l00044"></a>00044 <span class="comment"> * header files</span>
+<a name="l00045"></a>00045 <span class="comment"> */</span>
+<a name="l00046"></a>00046 <span class="preprocessor">#include <cpl.h></span> 
+<a name="l00047"></a>00047 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00048"></a>00048 
+<a name="l00049"></a>00049 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00050"></a>00050 <span class="comment"> *                        Function ANSI C prototypes</span>
+<a name="l00051"></a>00051 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00052"></a>00052 
+<a name="l00053"></a>00053 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00054"></a>00054 <span class="comment">   Function     :       sinfo_new_lamp_flats()</span>
+<a name="l00055"></a>00055 <span class="comment">   In           :       ini_file: file name of according .ini file</span>
+<a name="l00056"></a>00056 <span class="comment">   Out          :       integer (0 if it worked, -1 if it doesn't) </span>
+<a name="l00057"></a>00057 <span class="comment">   Job          :</span>
+<a name="l00058"></a>00058 <span class="comment">       </span>
+<a name="l00059"></a>00059 <span class="comment"> * this step handles stacks of lamp flat fields, </span>
+<a name="l00060"></a>00060 <span class="comment"> *  o it takes a clean mean,</span>
+<a name="l00061"></a>00061 <span class="comment"> *  o subtracts the off- from the on-frames, </span>
+<a name="l00062"></a>00062 <span class="comment"> *  o corrects for static bad pixels and normalizes for a master flat field. </span>
+<a name="l00063"></a>00063 <span class="comment"> *  o It distinguishes the spectrally dithered frames and </span>
+<a name="l00064"></a>00064 <span class="comment"> *  o treats them the same way. </span>
+<a name="l00065"></a>00065 <span class="comment"> *  o It can also generate a static bad pixel mask if wished.</span>
+<a name="l00066"></a>00066 <span class="comment"></span>
+<a name="l00067"></a>00067 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00068"></a>00068 <span class="keywordtype">int</span> 
+<a name="l00069"></a>00069 sinfo_new_lamp_flats (<span class="keyword">const</span> <span class="keywordtype">char</span>* plugin_id,
+<a name="l00070"></a>00070                       cpl_parameterlist* config, 
+<a name="l00071"></a>00071                       cpl_frameset* sof,
+<a name="l00072"></a>00072                       cpl_frameset* ref_set) ;
+<a name="l00073"></a>00073 
+<a name="l00074"></a>00074 
+<a name="l00075"></a>00075 <span class="preprocessor">#endif </span>
+<a name="l00076"></a>00076 <span class="preprocessor"></span>
+<a name="l00077"></a>00077 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__new__nst_8c_source.html b/html/sinfo__new__nst_8c_source.html
new file mode 100644
index 0000000..d81b9ce
--- /dev/null
+++ b/html/sinfo__new__nst_8c_source.html
@@ -0,0 +1,398 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_new_nst.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_new_nst.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment"> </span>
+<a name="l00021"></a>00021 <span class="comment">     File name    :       spiffi_north_south_test.c</span>
+<a name="l00022"></a>00022 <span class="comment">   Author       :    A. Modigliani</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on   :    Sep 17, 2003</span>
+<a name="l00024"></a>00024 <span class="comment">   Description  : </span>
+<a name="l00025"></a>00025 <span class="comment"></span>
+<a name="l00026"></a>00026 <span class="comment"> * nsh.h</span>
+<a name="l00027"></a>00027 <span class="comment"> * Result of a north-south test exposure are 32 continuum spectra of a </span>
+<a name="l00028"></a>00028 <span class="comment"> * pinhole that means one spectrum in each slitlet at the same spatial </span>
+<a name="l00029"></a>00029 <span class="comment"> * position.</span>
+<a name="l00030"></a>00030 <span class="comment"> * Each spectrum is fitted in sp[atial direction by a Gaussian to get the </span>
+<a name="l00031"></a>00031 <span class="comment"> * sub-pixel positions for each row.</span>
+<a name="l00032"></a>00032 <span class="comment"> *</span>
+<a name="l00033"></a>00033 <span class="comment"> * Then the distances are determined in each row and averaged</span>
+<a name="l00034"></a>00034 <span class="comment"> *</span>
+<a name="l00035"></a>00035 <span class="comment"> * Result: are distances of each slitlet from each other => 31 values stored </span>
+<a name="l00036"></a>00036 <span class="comment"> *  in an ASCII file this Python script needs a frame of a pinhole source with </span>
+<a name="l00037"></a>00037 <span class="comment"> *  a continuous spectrum, that is shifted exactly perpendicular to the </span>
+<a name="l00038"></a>00038 <span class="comment"> *  slitlets. It fits the spectra in spatial direction by a Gaussian fit </span>
+<a name="l00039"></a>00039 <span class="comment"> *  function and therefore determines the sub-pixel position of the source.</span>
+<a name="l00040"></a>00040 <span class="comment"> *</span>
+<a name="l00041"></a>00041 <span class="comment"> *  Then the distances of the slitlets from each other are determined and </span>
+<a name="l00042"></a>00042 <span class="comment"> *   saved in an ASCII list. </span>
+<a name="l00043"></a>00043 <span class="comment"> *</span>
+<a name="l00044"></a>00044 <span class="comment"></span>
+<a name="l00045"></a>00045 <span class="comment"></span>
+<a name="l00046"></a>00046 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00047"></a>00047 
+<a name="l00048"></a>00048 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00049"></a>00049 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00050"></a>00050 <span class="preprocessor">#endif</span>
+<a name="l00051"></a>00051 <span class="preprocessor"></span><span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00052"></a>00052 <span class="comment">                                Includes</span>
+<a name="l00053"></a>00053 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00054"></a>00054 <span class="preprocessor">#include "sinfo_new_nst.h"</span>
+<a name="l00055"></a>00055 <span class="preprocessor">#include "sinfo_pro_save.h"</span>
+<a name="l00056"></a>00056 <span class="preprocessor">#include "sinfo_pro_types.h"</span>
+<a name="l00057"></a>00057 <span class="preprocessor">#include "sinfo_functions.h"</span>
+<a name="l00058"></a>00058 <span class="preprocessor">#include "sinfo_ns_ini_by_cpl.h"</span>
+<a name="l00059"></a>00059 <span class="preprocessor">#include "sinfo_cube_construct.h"</span>
+<a name="l00060"></a>00060 <span class="preprocessor">#include "sinfo_utilities.h"</span>
+<a name="l00061"></a>00061 <span class="preprocessor">#include "sinfo_utils_wrappers.h"</span>
+<a name="l00062"></a>00062 <span class="preprocessor">#include "sinfo_error.h"</span>
+<a name="l00063"></a>00063 <span class="preprocessor">#include "sinfo_globals.h"</span>
+<a name="l00064"></a>00064 
+<a name="l00065"></a>00065 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00066"></a>00066 <span class="comment">                                Defines</span>
+<a name="l00067"></a>00067 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00068"></a>00068 
+<a name="l00076"></a>00076 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00077"></a>00077 <span class="comment">                             Function Definitions</span>
+<a name="l00078"></a>00078 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00079"></a>00079 
+<a name="l00080"></a>00080 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00081"></a>00081 <span class="comment">   Function     :       north_south_test()</span>
+<a name="l00082"></a>00082 <span class="comment">   In           :       ini_file: file name of according .ini file</span>
+<a name="l00083"></a>00083 <span class="comment">   Out          :       integer (0 if it worked, -1 if it doesn't) </span>
+<a name="l00084"></a>00084 <span class="comment">   Job          : Result of a north-south test exposure are 32 continuum </span>
+<a name="l00085"></a>00085 <span class="comment">                  spectra of a pinhole    that means one spectrum in each </span>
+<a name="l00086"></a>00086 <span class="comment">                  slitlet at the same spatial position.</span>
+<a name="l00087"></a>00087 <span class="comment"></span>
+<a name="l00088"></a>00088 <span class="comment">                  Each spectrum is fitted in sp[atial direction by a Gaussian</span>
+<a name="l00089"></a>00089 <span class="comment">                  to get the sub-pixel positions for each row.</span>
+<a name="l00090"></a>00090 <span class="comment"></span>
+<a name="l00091"></a>00091 <span class="comment">                  Then the distances are determined in each row and averaged</span>
+<a name="l00092"></a>00092 <span class="comment"></span>
+<a name="l00093"></a>00093 <span class="comment">                  Result: are distances of each slitlet from each other =></span>
+<a name="l00094"></a>00094 <span class="comment">                          31 values stored in an ASCII file</span>
+<a name="l00095"></a>00095 <span class="comment"></span>
+<a name="l00096"></a>00096 <span class="comment"></span>
+<a name="l00097"></a>00097 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00098"></a>00098 <span class="keywordtype">int</span> 
+<a name="l00099"></a>00099 sinfo_new_nst(<span class="keyword">const</span> <span class="keywordtype">char</span>* plugin_id, 
+<a name="l00100"></a>00100               cpl_parameterlist* config, 
+<a name="l00101"></a>00101               cpl_frameset* sof,
+<a name="l00102"></a>00102               cpl_frameset* ref_set)
+<a name="l00103"></a>00103 {
+<a name="l00104"></a>00104   ns_config * cfg=NULL ;
+<a name="l00105"></a>00105   cpl_imagelist * list_object=NULL ;
+<a name="l00106"></a>00106   cpl_imagelist * list_off=NULL;
+<a name="l00107"></a>00107   cpl_image * im_on=NULL;
+<a name="l00108"></a>00108   cpl_image * im_on_sub=NULL ;
+<a name="l00109"></a>00109   cpl_image * im_on_ind=NULL ;
+<a name="l00110"></a>00110   cpl_image * im_on_gauss=NULL ;
+<a name="l00111"></a>00111   cpl_image * im_mask=NULL ;
+<a name="l00112"></a>00112   cpl_image * im_off=NULL ;
+<a name="l00113"></a>00113 
+<a name="l00114"></a>00114   <span class="keywordtype">char</span>* name=NULL;
+<a name="l00115"></a>00115   <span class="keywordtype">char</span> tbl_name[MAX_NAME_SIZE];
+<a name="l00116"></a>00116   <span class="keywordtype">int</span> typ=0;
+<a name="l00117"></a>00117   <span class="keywordtype">int</span> i = 0;
+<a name="l00118"></a>00118 
+<a name="l00119"></a>00119   <span class="keywordtype">int</span> nob =0;
+<a name="l00120"></a>00120   <span class="keywordtype">int</span> nof =0;
+<a name="l00121"></a>00121 
+<a name="l00122"></a>00122   <span class="keywordtype">float</span>* distances=NULL;
+<a name="l00123"></a>00123   cpl_table* tbl_dist=NULL;
+<a name="l00124"></a>00124 
+<a name="l00125"></a>00125   cpl_vector* qc_dist=NULL;
+<a name="l00126"></a>00126 
+<a name="l00127"></a>00127   <span class="keywordtype">double</span>  qc_dist_mean=0;
+<a name="l00128"></a>00128   <span class="keywordtype">double</span>  qc_dist_stdev=0;
+<a name="l00129"></a>00129   cpl_frameset* raw=NULL;
+<a name="l00130"></a>00130 
+<a name="l00131"></a>00131   cpl_table* qclog_tbl=NULL;
+<a name="l00132"></a>00132   <span class="keywordtype">char</span> key_value[MAX_NAME_SIZE];
+<a name="l00133"></a>00133   <span class="keywordtype">char</span> key_name[MAX_NAME_SIZE];
+<a name="l00134"></a>00134   <span class="keywordtype">int</span>  no=0;
+<a name="l00135"></a>00135   <span class="keywordtype">double</span> lo_cut=0.;
+<a name="l00136"></a>00136   <span class="keywordtype">double</span> hi_cut=0.;
+<a name="l00137"></a>00137   <span class="keywordtype">int</span> pdensity=0;
+<a name="l00138"></a>00138 
+<a name="l00139"></a>00139   <span class="comment">/* </span>
+<a name="l00140"></a>00140 <span class="comment">       -----------------------------------------------------------------</span>
+<a name="l00141"></a>00141 <span class="comment">       1) parse the file names and parameters to the ns_config data </span>
+<a name="l00142"></a>00142 <span class="comment">          structure cfg</span>
+<a name="l00143"></a>00143 <span class="comment">       -----------------------------------------------------------------</span>
+<a name="l00144"></a>00144 <span class="comment">  */</span>
+<a name="l00145"></a>00145 
+<a name="l00146"></a>00146   <span class="comment">/* </span>
+<a name="l00147"></a>00147 <span class="comment">      parse the file names and parameters to the ns_config data structure cfg </span>
+<a name="l00148"></a>00148 <span class="comment">  */</span>
+<a name="l00149"></a>00149 
+<a name="l00150"></a>00150   sinfo_msg(<span class="stringliteral">"Parse cpl input"</span>);
+<a name="l00151"></a>00151   check_nomsg(raw=cpl_frameset_new());
+<a name="l00152"></a>00152   cknull(cfg = sinfo_parse_cpl_input_ns(config,sof,&raw),
+<a name="l00153"></a>00153      <span class="stringliteral">"could not parse cpl input!"</span>) ;
+<a name="l00154"></a>00154 
+<a name="l00155"></a>00155   <span class="keywordflow">if</span> (cfg->maskInd == 1) {
+<a name="l00156"></a>00156     <span class="keywordflow">if</span>(sinfo_is_fits_file(cfg->mask) != 1) {
+<a name="l00157"></a>00157       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Input file %s is not FITS"</span>,cfg->mask); 
+<a name="l00158"></a>00158       <span class="keywordflow">goto</span> cleanup;
+<a name="l00159"></a>00159     }
+<a name="l00160"></a>00160   }
+<a name="l00161"></a>00161   <span class="comment">/*</span>
+<a name="l00162"></a>00162 <span class="comment">     --------------------------------------------------------------------</span>
+<a name="l00163"></a>00163 <span class="comment">     stack the frames in data cubes and take the clean mean of all frames</span>
+<a name="l00164"></a>00164 <span class="comment">     --------------------------------------------------------------------</span>
+<a name="l00165"></a>00165 <span class="comment">  */</span>
+<a name="l00166"></a>00166   <span class="comment">/* allocate memory for lists of object and off-frames */</span>
+<a name="l00167"></a>00167   sinfo_msg(<span class="stringliteral">"stack the frames in data cubes"</span>);
+<a name="l00168"></a>00168   check(list_object = cpl_imagelist_new(),
+<a name="l00169"></a>00169           <span class="stringliteral">"could not allocate memory"</span>);
+<a name="l00170"></a>00170 
+<a name="l00171"></a>00171   <span class="keywordflow">if</span> (cfg->noff > 0 ) {
+<a name="l00172"></a>00172     check(list_off = cpl_imagelist_new(),
+<a name="l00173"></a>00173       <span class="stringliteral">"could not allocate memory"</span>);
+<a name="l00174"></a>00174   }
+<a name="l00175"></a>00175  
+<a name="l00176"></a>00176   <span class="comment">/*</span>
+<a name="l00177"></a>00177 <span class="comment">      #build different image lists for the different cases----</span>
+<a name="l00178"></a>00178 <span class="comment">  */</span>
+<a name="l00179"></a>00179   sinfo_msg(<span class="stringliteral">"build different image lists for the different cases"</span>);
+<a name="l00180"></a>00180   nob = 0;
+<a name="l00181"></a>00181   nof = 0;
+<a name="l00182"></a>00182 
+<a name="l00183"></a>00183   <span class="keywordflow">for</span> (i=0; i< cfg->nframes; i++){
+<a name="l00184"></a>00184     name = cfg->framelist[i];
+<a name="l00185"></a>00185     <span class="keywordflow">if</span>(sinfo_is_fits_file(name) != 1) {
+<a name="l00186"></a>00186       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Input file %s is not FITS"</span>,name);
+<a name="l00187"></a>00187       <span class="keywordflow">goto</span> cleanup;
+<a name="l00188"></a>00188     } <span class="keywordflow">else</span> {
+<a name="l00189"></a>00189       typ = sinfo_new_intarray_get_value( cfg->frametype, i );
+<a name="l00190"></a>00190       <span class="keywordflow">if</span> (typ == 1) {
+<a name="l00191"></a>00191     cpl_imagelist_set(list_object,
+<a name="l00192"></a>00192                           cpl_image_load(name,CPL_TYPE_FLOAT,0,0),nob);
+<a name="l00193"></a>00193     nob = nob + 1;
+<a name="l00194"></a>00194       } <span class="keywordflow">else</span> {
+<a name="l00195"></a>00195     cpl_imagelist_set(list_off,
+<a name="l00196"></a>00196                           cpl_image_load(name,CPL_TYPE_FLOAT,0,0),nof);
+<a name="l00197"></a>00197     nof = nof + 1;
+<a name="l00198"></a>00198       }
+<a name="l00199"></a>00199     }
+<a name="l00200"></a>00200   }
+<a name="l00201"></a>00201 
+<a name="l00202"></a>00202   <span class="keywordflow">if</span> (cfg->noff != nof || cfg->nobj != nob ){       
+<a name="l00203"></a>00203       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"something wrong with the number of the "</span>
+<a name="l00204"></a>00204                       <span class="stringliteral">"different types of frames"</span>);
+<a name="l00205"></a>00205       <span class="keywordflow">goto</span> cleanup;
+<a name="l00206"></a>00206   }
+<a name="l00207"></a>00207   
+<a name="l00208"></a>00208   <span class="comment">/*</span>
+<a name="l00209"></a>00209 <span class="comment">  #---take the average of the different cubes -------------</span>
+<a name="l00210"></a>00210 <span class="comment">  */</span>
+<a name="l00211"></a>00211   sinfo_msg(<span class="stringliteral">"take the average of the different cubes"</span>);
+<a name="l00212"></a>00212 
+<a name="l00213"></a>00213   check_nomsg(no=cpl_imagelist_get_size(list_object));
+<a name="l00214"></a>00214   lo_cut=(floor)(cfg->loReject*no+0.5);
+<a name="l00215"></a>00215   hi_cut=(floor)(cfg->hiReject*no+0.5);
+<a name="l00216"></a>00216   check(im_on=cpl_imagelist_collapse_minmax_create(list_object,lo_cut,hi_cut),
+<a name="l00217"></a>00217               <span class="stringliteral">"sinfo_average_with_rejection failed"</span> );
+<a name="l00218"></a>00218 
+<a name="l00219"></a>00219   <span class="keywordflow">if</span> (cfg->noff != 0) {
+<a name="l00220"></a>00220     <span class="comment">/*</span>
+<a name="l00221"></a>00221 <span class="comment">      im_off = sinfo_average_with_rejection( cube_off, </span>
+<a name="l00222"></a>00222 <span class="comment">                                       cfg->loReject, cfg->hiReject );</span>
+<a name="l00223"></a>00223 <span class="comment">    */</span>
+<a name="l00224"></a>00224     check_nomsg(no=cpl_imagelist_get_size(list_off));
+<a name="l00225"></a>00225     lo_cut=(floor)(cfg->loReject*no+0.5);
+<a name="l00226"></a>00226     hi_cut=(floor)(cfg->hiReject*no+0.5);
+<a name="l00227"></a>00227     check(im_off=cpl_imagelist_collapse_minmax_create(list_off,lo_cut,hi_cut),
+<a name="l00228"></a>00228       <span class="stringliteral">"sinfo_average_with_rejection failed"</span> );
+<a name="l00229"></a>00229       sinfo_free_imagelist(&list_off);
+<a name="l00230"></a>00230   }
+<a name="l00231"></a>00231   sinfo_free_imagelist(&list_object);
+<a name="l00232"></a>00232 
+<a name="l00233"></a>00233   <span class="comment">/*</span>
+<a name="l00234"></a>00234 <span class="comment">  #finally, subtract off from on frames and store the result in the object cube</span>
+<a name="l00235"></a>00235 <span class="comment">  */</span>
+<a name="l00236"></a>00236 
+<a name="l00237"></a>00237   <span class="keywordflow">if</span> (cfg->noff != 0) {
+<a name="l00238"></a>00238     sinfo_msg(<span class="stringliteral">"subtract off from on frames"</span>);
+<a name="l00239"></a>00239     check(im_on_sub = cpl_image_subtract_create(im_on, im_off),
+<a name="l00240"></a>00240       <span class="stringliteral">"sinfo_sub_image failed"</span> );
+<a name="l00241"></a>00241 
+<a name="l00242"></a>00242     sinfo_free_image(&im_on);
+<a name="l00243"></a>00243     sinfo_free_image(&im_off);
+<a name="l00244"></a>00244   } <span class="keywordflow">else</span> {
+<a name="l00245"></a>00245     check_nomsg(im_on_sub = cpl_image_duplicate(im_on));
+<a name="l00246"></a>00246     sinfo_free_image(&im_on);
+<a name="l00247"></a>00247   }
+<a name="l00248"></a>00248 
+<a name="l00249"></a>00249   <span class="comment">/*</span>
+<a name="l00250"></a>00250 <span class="comment">  #---------------------------------------------------------</span>
+<a name="l00251"></a>00251 <span class="comment">  # convolution with Gaussian if recommended</span>
+<a name="l00252"></a>00252 <span class="comment">  #---------------------------------------------------------</span>
+<a name="l00253"></a>00253 <span class="comment">  */</span>
+<a name="l00254"></a>00254   <span class="keywordflow">if</span> (cfg->gaussInd == 1) {
+<a name="l00255"></a>00255     sinfo_msg(<span class="stringliteral">"convolution with Gaussian"</span>);
+<a name="l00256"></a>00256     cknull(im_on_gauss = sinfo_new_convolve_ns_image_by_gauss(im_on_sub, 
+<a name="l00257"></a>00257                                                               cfg->hw),
+<a name="l00258"></a>00258                      <span class="stringliteral">"could not carry out sinfo_convolveNSImageByGauss"</span> );
+<a name="l00259"></a>00259 
+<a name="l00260"></a>00260     sinfo_free_image(&im_on_sub);
+<a name="l00261"></a>00261     check_nomsg(im_on_sub = cpl_image_duplicate(im_on_gauss));
+<a name="l00262"></a>00262     sinfo_free_image(&im_on_gauss);
+<a name="l00263"></a>00263   }
+<a name="l00264"></a>00264 
+<a name="l00265"></a>00265   <span class="comment">/*</span>
+<a name="l00266"></a>00266 <span class="comment">  #---------------------------------------------------------</span>
+<a name="l00267"></a>00267 <span class="comment">  # static bad pixel indication</span>
+<a name="l00268"></a>00268 <span class="comment">  #---------------------------------------------------------</span>
+<a name="l00269"></a>00269 <span class="comment">  */</span>
+<a name="l00270"></a>00270 
+<a name="l00271"></a>00271    <span class="keywordflow">if</span> (cfg->maskInd == 1) {
+<a name="l00272"></a>00272      sinfo_msg(<span class="stringliteral">"static bad pixel indication"</span>);
+<a name="l00273"></a>00273      check(im_mask = cpl_image_load(cfg->mask,CPL_TYPE_FLOAT,0,0),
+<a name="l00274"></a>00274        <span class="stringliteral">"could not load static bad pixel mask"</span> );
+<a name="l00275"></a>00275      cknull(im_on_ind = sinfo_new_mult_image_by_mask(im_on_sub, im_mask),
+<a name="l00276"></a>00276         <span class="stringliteral">"could not carry out sinfo_multImageByMask"</span> );
+<a name="l00277"></a>00277      sinfo_free_image(&im_mask);
+<a name="l00278"></a>00278      sinfo_free_image(&im_on_sub);
+<a name="l00279"></a>00279   
+<a name="l00280"></a>00280    } <span class="keywordflow">else</span> {
+<a name="l00281"></a>00281       check_nomsg(im_on_ind = cpl_image_duplicate(im_on_sub));
+<a name="l00282"></a>00282       sinfo_free_image(&im_on_sub);
+<a name="l00283"></a>00283    }
+<a name="l00284"></a>00284 
+<a name="l00285"></a>00285    <span class="keywordflow">if</span>(pdensity > 1 && strcmp(plugin_id,<span class="stringliteral">"sinfo_rec_distortion"</span>)!=0) {
+<a name="l00286"></a>00286      ck0(sinfo_pro_save_ima(im_on_ind,ref_set,sof,cfg->fitsname,
+<a name="l00287"></a>00287                 PRO_MASTER_SLIT,NULL,plugin_id,config),
+<a name="l00288"></a>00288      <span class="stringliteral">"cannot save ima %s"</span>, cfg->fitsname);
+<a name="l00289"></a>00289    }
+<a name="l00290"></a>00290  
+<a name="l00291"></a>00291    <span class="comment">/*</span>
+<a name="l00292"></a>00292 <span class="comment">   #---------------------------------------------------------</span>
+<a name="l00293"></a>00293 <span class="comment">   # do the north - south - test</span>
+<a name="l00294"></a>00294 <span class="comment">   #---------------------------------------------------------</span>
+<a name="l00295"></a>00295 <span class="comment">   */</span>
+<a name="l00296"></a>00296    sinfo_msg(<span class="stringliteral">"Do the north - south - test"</span>);
+<a name="l00297"></a>00297 
+<a name="l00298"></a>00298    cknull(distances = sinfo_north_south_test(im_on_ind, 
+<a name="l00299"></a>00299                        cfg->nslits,
+<a name="l00300"></a>00300                        cfg->halfWidth,
+<a name="l00301"></a>00301                        cfg->fwhm ,
+<a name="l00302"></a>00302                        cfg->minDiff,
+<a name="l00303"></a>00303                        cfg->estimated_dist,
+<a name="l00304"></a>00304                                            cfg->devtol, 
+<a name="l00305"></a>00305                                            IMA_PIX_START, 
+<a name="l00306"></a>00306                                            IMA_PIX_END ),
+<a name="l00307"></a>00307       <span class="stringliteral">"North South Test distance determination failed"</span>);
+<a name="l00308"></a>00308    sinfo_free_image(&im_on_ind);
+<a name="l00309"></a>00309     <span class="comment">/*</span>
+<a name="l00310"></a>00310 <span class="comment">   sinfo_new_parameter_to_ascii(distances, cfg->nslits - 1, cfg->outName);</span>
+<a name="l00311"></a>00311 <span class="comment">   */</span>
+<a name="l00312"></a>00312    check_nomsg(tbl_dist = cpl_table_new(cfg->nslits - 1));
+<a name="l00313"></a>00313    check_nomsg(cpl_table_new_column(tbl_dist,<span class="stringliteral">"slitlet_distance"</span>,
+<a name="l00314"></a>00314                     CPL_TYPE_FLOAT));
+<a name="l00315"></a>00315    check_nomsg(cpl_table_copy_data_float(tbl_dist,<span class="stringliteral">"slitlet_distance"</span>,
+<a name="l00316"></a>00316                      distances));
+<a name="l00317"></a>00317 
+<a name="l00318"></a>00318    strcpy(tbl_name,cfg->outName);
+<a name="l00319"></a>00319 
+<a name="l00320"></a>00320    check_nomsg(qclog_tbl = cpl_table_new(cfg->nslits + 1));
+<a name="l00321"></a>00321    check_nomsg(cpl_table_new_column(qclog_tbl,<span class="stringliteral">"key_name"</span>, CPL_TYPE_STRING));
+<a name="l00322"></a>00322    check_nomsg(cpl_table_new_column(qclog_tbl,<span class="stringliteral">"key_type"</span>, CPL_TYPE_STRING));
+<a name="l00323"></a>00323    check_nomsg(cpl_table_new_column(qclog_tbl,<span class="stringliteral">"key_value"</span>, CPL_TYPE_STRING));
+<a name="l00324"></a>00324    check_nomsg(cpl_table_new_column(qclog_tbl,<span class="stringliteral">"key_help"</span>, CPL_TYPE_STRING));
+<a name="l00325"></a>00325 
+<a name="l00326"></a>00326    check_nomsg(qc_dist=cpl_vector_new(cfg->nslits - 1));
+<a name="l00327"></a>00327  
+<a name="l00328"></a>00328    <span class="keywordflow">for</span>(i=0;i<cfg->nslits - 1;i++) {
+<a name="l00329"></a>00329          snprintf(key_name,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%i"</span>,<span class="stringliteral">"QC SL DIST"</span>,i);
+<a name="l00330"></a>00330          cpl_table_set_string(qclog_tbl,<span class="stringliteral">"key_name"</span>,i,key_name);
+<a name="l00331"></a>00331          cpl_table_set_string(qclog_tbl,<span class="stringliteral">"key_type"</span>,i,<span class="stringliteral">"CPL_TYPE_DOUBLE"</span>);
+<a name="l00332"></a>00332          snprintf(key_value,MAX_NAME_SIZE-1,<span class="stringliteral">"%g"</span>,distances[i]);
+<a name="l00333"></a>00333          cpl_table_set_string(qclog_tbl,<span class="stringliteral">"key_value"</span>,i,key_value);
+<a name="l00334"></a>00334          cpl_table_set_string(qclog_tbl,<span class="stringliteral">"key_help"</span>,i,<span class="stringliteral">"Slitlet distance"</span>);
+<a name="l00335"></a>00335 
+<a name="l00336"></a>00336          cpl_vector_set(qc_dist,i,distances[i]);
+<a name="l00337"></a>00337    }
+<a name="l00338"></a>00338    check_nomsg(qc_dist_mean=cpl_vector_get_mean(qc_dist));
+<a name="l00339"></a>00339    check_nomsg(qc_dist_stdev=cpl_vector_get_stdev(qc_dist));
+<a name="l00340"></a>00340 
+<a name="l00341"></a>00341    cpl_table_set_string(qclog_tbl,<span class="stringliteral">"key_name"</span>,cfg->nslits-1,<span class="stringliteral">"QC SL DISTAVG"</span>);
+<a name="l00342"></a>00342    cpl_table_set_string(qclog_tbl,<span class="stringliteral">"key_type"</span>,cfg->nslits-1,<span class="stringliteral">"CPL_TYPE_DOUBLE"</span>);
+<a name="l00343"></a>00343    snprintf(key_value,MAX_NAME_SIZE-1,<span class="stringliteral">"%g"</span>,cpl_vector_get_mean(qc_dist));
+<a name="l00344"></a>00344    cpl_table_set_string(qclog_tbl,<span class="stringliteral">"key_value"</span>,cfg->nslits-1,key_value);
+<a name="l00345"></a>00345    cpl_table_set_string(qclog_tbl,<span class="stringliteral">"key_help"</span>,cfg->nslits-1,
+<a name="l00346"></a>00346                                   <span class="stringliteral">"Average Slitlet distance"</span>);
+<a name="l00347"></a>00347 
+<a name="l00348"></a>00348    cpl_table_set_string(qclog_tbl,<span class="stringliteral">"key_name"</span>,cfg->nslits,<span class="stringliteral">"QC SL DISTRMS"</span>);
+<a name="l00349"></a>00349    cpl_table_set_string(qclog_tbl,<span class="stringliteral">"key_type"</span>,cfg->nslits,<span class="stringliteral">"CPL_TYPE_DOUBLE"</span>);
+<a name="l00350"></a>00350    snprintf(key_value,MAX_NAME_SIZE-1,<span class="stringliteral">"%g"</span>,qc_dist_stdev);
+<a name="l00351"></a>00351    cpl_table_set_string(qclog_tbl,<span class="stringliteral">"key_value"</span>,cfg->nslits,key_value);
+<a name="l00352"></a>00352    cpl_table_set_string(qclog_tbl,<span class="stringliteral">"key_help"</span>,cfg->nslits,
+<a name="l00353"></a>00353                         <span class="stringliteral">"RMS Slitlet distance"</span>);
+<a name="l00354"></a>00354 
+<a name="l00355"></a>00355    ck0(sinfo_pro_save_tbl(tbl_dist,ref_set,sof,tbl_name,
+<a name="l00356"></a>00356            PRO_SLITLETS_DISTANCE,qclog_tbl,plugin_id,config),
+<a name="l00357"></a>00357        <span class="stringliteral">"cannot dump tbl %s"</span>, tbl_name);
+<a name="l00358"></a>00358 
+<a name="l00359"></a>00359    sinfo_free_my_vector(&qc_dist);
+<a name="l00360"></a>00360    sinfo_free_table(&tbl_dist);
+<a name="l00361"></a>00361    sinfo_free_table(&qclog_tbl);
+<a name="l00362"></a>00362    sinfo_free_float(&distances);
+<a name="l00363"></a>00363    sinfo_ns_free (&cfg);
+<a name="l00364"></a>00364    sinfo_free_frameset(&raw);
+<a name="l00365"></a>00365 
+<a name="l00366"></a>00366   <span class="keywordflow">return</span> 0;
+<a name="l00367"></a>00367 
+<a name="l00368"></a>00368   cleanup:
+<a name="l00369"></a>00369   sinfo_free_my_vector(&qc_dist);
+<a name="l00370"></a>00370   sinfo_free_table(&tbl_dist);
+<a name="l00371"></a>00371   sinfo_free_table(&qclog_tbl);
+<a name="l00372"></a>00372   sinfo_free_float(&distances);
+<a name="l00373"></a>00373   sinfo_free_table(&tbl_dist);
+<a name="l00374"></a>00374   sinfo_free_table(&qclog_tbl);
+<a name="l00375"></a>00375   sinfo_free_imagelist(&list_object);
+<a name="l00376"></a>00376   sinfo_free_imagelist(&list_off);
+<a name="l00377"></a>00377   sinfo_free_image(&im_on);
+<a name="l00378"></a>00378   sinfo_free_image(&im_mask);
+<a name="l00379"></a>00379   sinfo_free_image(&im_on_gauss);
+<a name="l00380"></a>00380   sinfo_free_image(&im_on_sub);
+<a name="l00381"></a>00381   sinfo_free_image(&im_off);
+<a name="l00382"></a>00382   sinfo_free_image(&im_on_ind);
+<a name="l00383"></a>00383   sinfo_ns_free (&cfg);
+<a name="l00384"></a>00384   sinfo_free_frameset(&raw);
+<a name="l00385"></a>00385   <span class="keywordflow">return</span> -1;
+<a name="l00386"></a>00386 
+<a name="l00387"></a>00387 
+<a name="l00388"></a>00388 }
+<a name="l00389"></a>00389 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__new__nst_8h_source.html b/html/sinfo__new__nst_8h_source.html
new file mode 100644
index 0000000..20b7eea
--- /dev/null
+++ b/html/sinfo__new__nst_8h_source.html
@@ -0,0 +1,103 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_new_nst.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_new_nst.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#ifndef SINFO_NEW_NST_H</span>
+<a name="l00002"></a>00002 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_NEW_NST_H</span>
+<a name="l00003"></a>00003 <span class="preprocessor"></span><span class="comment">/*</span>
+<a name="l00004"></a>00004 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00005"></a>00005 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00006"></a>00006 <span class="comment"> *</span>
+<a name="l00007"></a>00007 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00008"></a>00008 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00009"></a>00009 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00010"></a>00010 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00011"></a>00011 <span class="comment"> *</span>
+<a name="l00012"></a>00012 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00013"></a>00013 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00014"></a>00014 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00015"></a>00015 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00016"></a>00016 <span class="comment"> *</span>
+<a name="l00017"></a>00017 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00018"></a>00018 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00019"></a>00019 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00020"></a>00020 <span class="comment"> */</span>
+<a name="l00021"></a>00021 <span class="comment">/*****************************************************************************</span>
+<a name="l00022"></a>00022 <span class="comment">* E.S.O. - VLT project</span>
+<a name="l00023"></a>00023 <span class="comment">*</span>
+<a name="l00024"></a>00024 <span class="comment">* "@(#) $Id: sinfo_new_nst.h,v 1.7 2007/09/21 14:49:00 amodigli Exp $"</span>
+<a name="l00025"></a>00025 <span class="comment">*</span>
+<a name="l00026"></a>00026 <span class="comment">* who       when      what</span>
+<a name="l00027"></a>00027 <span class="comment">* --------  --------  ----------------------------------------------</span>
+<a name="l00028"></a>00028 <span class="comment">* amodigli  17/09/03  created</span>
+<a name="l00029"></a>00029 <span class="comment">*/</span>
+<a name="l00030"></a>00030 
+<a name="l00031"></a>00031 <span class="comment">/************************************************************************</span>
+<a name="l00032"></a>00032 <span class="comment"> * new_nsh.h</span>
+<a name="l00033"></a>00033 <span class="comment"> * Result of a north-south test exposure are 32 continuum spectra of a </span>
+<a name="l00034"></a>00034 <span class="comment"> * pinhole that means one spectrum in each slitlet at the same spatial </span>
+<a name="l00035"></a>00035 <span class="comment"> * position.</span>
+<a name="l00036"></a>00036 <span class="comment"> * Each spectrum is fitted in sp[atial direction by a Gaussian to get the </span>
+<a name="l00037"></a>00037 <span class="comment"> * sub-pixel positions for each row.</span>
+<a name="l00038"></a>00038 <span class="comment"> *</span>
+<a name="l00039"></a>00039 <span class="comment"> * Then the distances are determined in each row and averaged</span>
+<a name="l00040"></a>00040 <span class="comment"> *</span>
+<a name="l00041"></a>00041 <span class="comment"> * Result: are distances of each slitlet from each other => 31 values stored </span>
+<a name="l00042"></a>00042 <span class="comment"> *  in an ASCII file this Python script needs a frame of a pinhole source with </span>
+<a name="l00043"></a>00043 <span class="comment"> *  a continuous spectrum, that is shifted exactly perpendicular to the </span>
+<a name="l00044"></a>00044 <span class="comment"> *  slitlets. It fits the spectra in spatial direction by a Gaussian fit </span>
+<a name="l00045"></a>00045 <span class="comment"> *  function and therefore determines the sub-pixel position of the source.</span>
+<a name="l00046"></a>00046 <span class="comment"> *</span>
+<a name="l00047"></a>00047 <span class="comment"> *  Then the distances of the slitlets from each other are determined and </span>
+<a name="l00048"></a>00048 <span class="comment"> *   saved in an ASCII list. </span>
+<a name="l00049"></a>00049 <span class="comment"> *</span>
+<a name="l00050"></a>00050 <span class="comment"> *----------------------------------------------------------------------</span>
+<a name="l00051"></a>00051 <span class="comment"> */</span>
+<a name="l00052"></a>00052 
+<a name="l00053"></a>00053 <span class="comment">/*</span>
+<a name="l00054"></a>00054 <span class="comment"> * header files</span>
+<a name="l00055"></a>00055 <span class="comment"> */</span>
+<a name="l00056"></a>00056 <span class="preprocessor">#include <cpl.h></span>  
+<a name="l00057"></a>00057 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00058"></a>00058 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00059"></a>00059 <span class="comment"> *                        Function ANSI C prototypes</span>
+<a name="l00060"></a>00060 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00061"></a>00061 
+<a name="l00062"></a>00062 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00063"></a>00063 <span class="comment">   Function     :       sinfo_nst()</span>
+<a name="l00064"></a>00064 <span class="comment">   In           :       ini_file: file name of according .ini file</span>
+<a name="l00065"></a>00065 <span class="comment">   Out          :       integer (0 if it worked, -1 if it doesn't) </span>
+<a name="l00066"></a>00066 <span class="comment">   Job          :</span>
+<a name="l00067"></a>00067 <span class="comment">       </span>
+<a name="l00068"></a>00068 <span class="comment"> * Result of a north-south test exposure are 32 continuum spectra of a </span>
+<a name="l00069"></a>00069 <span class="comment"> * pinhole that means one spectrum in each slitlet at the same spatial </span>
+<a name="l00070"></a>00070 <span class="comment"> * position.</span>
+<a name="l00071"></a>00071 <span class="comment"> * Each spectrum is fitted in sp[atial direction by a Gaussian to get the </span>
+<a name="l00072"></a>00072 <span class="comment"> * sub-pixel positions for each row.</span>
+<a name="l00073"></a>00073 <span class="comment"> *</span>
+<a name="l00074"></a>00074 <span class="comment"> * Then the distances are determined in each row and averaged </span>
+<a name="l00075"></a>00075 <span class="comment"></span>
+<a name="l00076"></a>00076 <span class="comment"></span>
+<a name="l00077"></a>00077 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00078"></a>00078 <span class="keywordtype">int</span> 
+<a name="l00079"></a>00079 sinfo_new_nst (<span class="keyword">const</span> <span class="keywordtype">char</span>* plugin_id, 
+<a name="l00080"></a>00080                cpl_parameterlist* config,
+<a name="l00081"></a>00081                cpl_frameset* <span class="keyword">set</span>,
+<a name="l00082"></a>00082                cpl_frameset* ref_set) ;
+<a name="l00083"></a>00083 
+<a name="l00084"></a>00084 
+<a name="l00085"></a>00085 <span class="preprocessor">#endif </span>
+<a name="l00086"></a>00086 <span class="preprocessor"></span>
+<a name="l00087"></a>00087 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__new__objnod_8c_source.html b/html/sinfo__new__objnod_8c_source.html
new file mode 100644
index 0000000..8679917
--- /dev/null
+++ b/html/sinfo__new__objnod_8c_source.html
@@ -0,0 +1,884 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_new_objnod.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_new_objnod.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name    :       sinfo_new_objnod.c</span>
+<a name="l00022"></a>00022 <span class="comment">   Author       :    J. Schreiber</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on   :    December 3, 2003</span>
+<a name="l00024"></a>00024 <span class="comment">   Description  :    Creates data cubes or merges data cubes </span>
+<a name="l00025"></a>00025 <span class="comment">                        out of jittered object-sky</span>
+<a name="l00026"></a>00026 <span class="comment">                        nodding observations </span>
+<a name="l00027"></a>00027 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span>
+<a name="l00032"></a>00032 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                                Includes</span>
+<a name="l00034"></a>00034 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 <span class="preprocessor">#include "sinfo_new_objnod.h"</span>
+<a name="l00036"></a>00036 <span class="preprocessor">#include "sinfo_hidden.h"</span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include "sinfo_pro_save.h"</span>
+<a name="l00038"></a>00038 <span class="preprocessor">#include "sinfo_objnod_ini_by_cpl.h"</span>
+<a name="l00039"></a>00039 <span class="preprocessor">#include "sinfo_functions.h"</span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include "sinfo_pfits.h"</span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include "sinfo_utilities_scired.h"</span> 
+<a name="l00042"></a>00042 <span class="preprocessor">#include "sinfo_wave_calibration.h"</span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include "sinfo_cube_construct.h"</span>
+<a name="l00044"></a>00044 <span class="preprocessor">#include "sinfo_error.h"</span>
+<a name="l00045"></a>00045 <span class="preprocessor">#include "sinfo_utils_wrappers.h"</span>
+<a name="l00046"></a>00046 
+<a name="l00047"></a>00047 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00048"></a>00048 <span class="comment">                                Defines</span>
+<a name="l00049"></a>00049 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00050"></a>00050 <span class="preprocessor">#define PI_NUMB        (3.1415926535897932384626433832795) </span><span class="comment">/* pi */</span>
+<a name="l00051"></a>00051 
+<a name="l00052"></a>00052 
+<a name="l00053"></a>00053 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00054"></a>00054 <span class="comment">                             Function Definitions</span>
+<a name="l00055"></a>00055 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00056"></a>00056 
+<a name="l00065"></a>00065 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00066"></a>00066 <span class="comment">   Function     : sinfo_new_objnod()</span>
+<a name="l00067"></a>00067 <span class="comment">   In           : ini_file: file name of according .ini file</span>
+<a name="l00068"></a>00068 <span class="comment">   Out          : integer (0 if it worked, -1 if it doesn't) </span>
+<a name="l00069"></a>00069 <span class="comment">   Job          : this routine carries through the data cube creation of an </span>
+<a name="l00070"></a>00070 <span class="comment">                  object science observation using object-sky nodding</span>
+<a name="l00071"></a>00071 <span class="comment">                  and jittering. This script expects jittered frames that</span>
+<a name="l00072"></a>00072 <span class="comment">          were already sky-subtracted</span>
+<a name="l00073"></a>00073 <span class="comment">                  averaged, flatfielded, spectral tilt corrected and </span>
+<a name="l00074"></a>00074 <span class="comment">        interleaved if necessary</span>
+<a name="l00075"></a>00075 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00076"></a>00076 <span class="keywordtype">int</span> sinfo_new_objnod (<span class="keyword">const</span> <span class="keywordtype">char</span>* plugin_id,cpl_parameterlist* config, 
+<a name="l00077"></a>00077             cpl_frameset* sof, <span class="keyword">const</span> <span class="keywordtype">char</span>* procatg)
+<a name="l00078"></a>00078 {
+<a name="l00079"></a>00079 
+<a name="l00080"></a>00080     object_config * cfg=NULL ;
+<a name="l00081"></a>00081     cpl_image * im=NULL ;
+<a name="l00082"></a>00082     cpl_image * wavemapim=NULL ;
+<a name="l00083"></a>00083     cpl_image * resampledImage=NULL ;
+<a name="l00084"></a>00084     cpl_image * calim=NULL ;
+<a name="l00085"></a>00085     cpl_image * halospec=NULL ;
+<a name="l00086"></a>00086     cpl_image * sky_im=NULL;
+<a name="l00087"></a>00087     cpl_image* res_flat=NULL;
+<a name="l00088"></a>00088     cpl_image* res_sky=NULL;
+<a name="l00089"></a>00089     cpl_image* flat_im=NULL;
+<a name="l00090"></a>00090     cpl_image* jitter_image=NULL;
+<a name="l00091"></a>00091     cpl_image* eima_avg=NULL;
+<a name="l00092"></a>00092     cpl_image* eima_med=NULL;
+<a name="l00093"></a>00093     cpl_imagelist  * cube=NULL ;
+<a name="l00094"></a>00094     cpl_imagelist  * outcube=NULL ;
+<a name="l00095"></a>00095     cpl_imagelist  * outcube2=NULL ;
+<a name="l00096"></a>00096     cpl_imagelist  ** cubeobject=NULL ;
+<a name="l00097"></a>00097     cpl_imagelist  ** cube_tmp=NULL ;
+<a name="l00098"></a>00098     cpl_imagelist  * jittercube=NULL ;
+<a name="l00099"></a>00099     cpl_imagelist  * maskcube=NULL ;
+<a name="l00100"></a>00100     cpl_imagelist* cflat=NULL;
+<a name="l00101"></a>00101     cpl_imagelist* cflat2=NULL;
+<a name="l00102"></a>00102     cpl_imagelist* csky=NULL;
+<a name="l00103"></a>00103     cpl_imagelist* csky2=NULL;
+<a name="l00104"></a>00104 
+<a name="l00105"></a>00105 
+<a name="l00106"></a>00106     <span class="keywordtype">int</span> i=0;
+<a name="l00107"></a>00107     <span class="keywordtype">int</span> n=0;
+<a name="l00108"></a>00108     <span class="keywordtype">int</span> partind = 0 ;
+<a name="l00109"></a>00109     <span class="keywordtype">int</span> centralpix=0 ;
+<a name="l00110"></a>00110     <span class="keywordtype">int</span> z_siz=0;
+<a name="l00111"></a>00111     <span class="keywordtype">int</span> z_min=0;
+<a name="l00112"></a>00112     <span class="keywordtype">int</span> z_max=0;
+<a name="l00113"></a>00113     <span class="keywordtype">int</span> z=0;
+<a name="l00114"></a>00114     <span class="keywordtype">int</span> z_stp=100;
+<a name="l00115"></a>00115     <span class="keywordtype">int</span> scales_sky=0;
+<a name="l00116"></a>00116     <span class="keywordtype">int</span> ks_clip=0;
+<a name="l00117"></a>00117     <span class="keywordtype">double</span> kappa=2.0;
+<a name="l00118"></a>00118 
+<a name="l00119"></a>00119     <span class="keywordtype">float</span> ref_offx=0;
+<a name="l00120"></a>00120     <span class="keywordtype">float</span> ref_offy=0;
+<a name="l00121"></a>00121     <span class="keywordtype">float</span> mi=0 ;
+<a name="l00122"></a>00122     <span class="keywordtype">float</span> ma=0 ;
+<a name="l00123"></a>00123     <span class="keywordtype">float</span> fcol=0 ;
+<a name="l00124"></a>00124     <span class="keywordtype">float</span> center_x=0;
+<a name="l00125"></a>00125     <span class="keywordtype">float</span> newcenter_x=0 ;
+<a name="l00126"></a>00126     <span class="keywordtype">float</span> center_y=0;
+<a name="l00127"></a>00127     <span class="keywordtype">float</span> newcenter_y=0;
+<a name="l00128"></a>00128     <span class="keywordtype">float</span> cd1_1=0;
+<a name="l00129"></a>00129     <span class="keywordtype">float</span> cd1_2=0;
+<a name="l00130"></a>00130     <span class="keywordtype">float</span> cd2_1=0;
+<a name="l00131"></a>00131     <span class="keywordtype">float</span> cd2_2=0;
+<a name="l00132"></a>00132     <span class="keywordtype">float</span> pixelscale=0;
+<a name="l00133"></a>00133     <span class="keywordtype">float</span> angle=0;
+<a name="l00134"></a>00134     <span class="keywordtype">float</span> radangle=0;
+<a name="l00135"></a>00135     <span class="keywordtype">double</span> exptime=0;
+<a name="l00136"></a>00136 
+<a name="l00137"></a>00137     <span class="keywordtype">float</span> *  correct_dist=NULL ;
+<a name="l00138"></a>00138     <span class="keywordtype">float</span> * distances=NULL ;
+<a name="l00139"></a>00139     <span class="keywordtype">double</span> * times=NULL ;
+<a name="l00140"></a>00140     <span class="keywordtype">float</span> * offsetx=NULL;
+<a name="l00141"></a>00141     <span class="keywordtype">float</span> * offsety=NULL;
+<a name="l00142"></a>00142     <span class="keywordtype">float</span> ** slit_edges=NULL ;
+<a name="l00143"></a>00143     <span class="keywordtype">float</span> offx_min=1.e10;
+<a name="l00144"></a>00144     <span class="keywordtype">float</span> offy_min=1.e10;
+<a name="l00145"></a>00145     <span class="keywordtype">float</span> offx_max=-1.e10;
+<a name="l00146"></a>00146     <span class="keywordtype">float</span> offy_max=-1.e10;
+<a name="l00147"></a>00147 
+<a name="l00148"></a>00148     <span class="keywordtype">double</span> dis=0;
+<a name="l00149"></a>00149     <span class="keywordtype">double</span> centralLambda=0;
+<a name="l00150"></a>00150 
+<a name="l00151"></a>00151     <span class="keywordtype">char</span> name_jitter[MAX_NAME_SIZE] ;
+<a name="l00152"></a>00152     <span class="keywordtype">char</span> pro_mjit[MAX_NAME_SIZE];
+<a name="l00153"></a>00153     <span class="keywordtype">char</span> pro_obs[MAX_NAME_SIZE];
+<a name="l00154"></a>00154     <span class="keywordtype">char</span> pro_med[MAX_NAME_SIZE];
+<a name="l00155"></a>00155 
+<a name="l00156"></a>00156 
+<a name="l00157"></a>00157     <span class="keywordtype">char</span> * name=NULL ;
+<a name="l00158"></a>00158     <span class="keywordtype">char</span> * partname=NULL;
+<a name="l00159"></a>00159     <span class="keywordtype">char</span> * partname2=NULL;
+<a name="l00160"></a>00160     <span class="keywordtype">char</span> file_name[MAX_NAME_SIZE];
+<a name="l00161"></a>00161     <span class="keywordtype">int</span> vllx=0;
+<a name="l00162"></a>00162     <span class="keywordtype">int</span> vlly=0;
+<a name="l00163"></a>00163     <span class="keywordtype">int</span> vurx=0;
+<a name="l00164"></a>00164     <span class="keywordtype">int</span> vury=0;
+<a name="l00165"></a>00165 
+<a name="l00166"></a>00166     <span class="keywordtype">int</span> onp=0;
+<a name="l00167"></a>00167     <span class="keywordtype">int</span> j=0;
+<a name="l00168"></a>00168     cpl_image* j_img=NULL;
+<a name="l00169"></a>00169     cpl_image* m_img=NULL;
+<a name="l00170"></a>00170     cpl_table* qclog_tbl=NULL;
+<a name="l00171"></a>00171     cpl_image* ill_cor=NULL;
+<a name="l00172"></a>00172     cpl_frame* frame=NULL;
+<a name="l00173"></a>00173     cpl_frameset* stk=NULL;
+<a name="l00174"></a>00174     cpl_parameter* p=NULL;
+<a name="l00175"></a>00175     cpl_propertylist* plist=NULL;
+<a name="l00176"></a>00176     <span class="keywordtype">int</span> mosaic_max_size=0;
+<a name="l00177"></a>00177 
+<a name="l00178"></a>00178     check_nomsg(p=cpl_parameterlist_find(config,
+<a name="l00179"></a>00179                      <span class="stringliteral">"sinfoni.objnod.mosaic_max_size"</span>));
+<a name="l00180"></a>00180     check_nomsg(mosaic_max_size=cpl_parameter_get_int(p));
+<a name="l00181"></a>00181 
+<a name="l00182"></a>00182      <span class="keywordflow">if</span> (strcmp(procatg,PRO_COADD_STD) == 0) {
+<a name="l00183"></a>00183     strcpy(pro_mjit,PRO_MASK_COADD_STD);
+<a name="l00184"></a>00184     strcpy(pro_obs,PRO_OBS_STD);
+<a name="l00185"></a>00185     strcpy(pro_med,PRO_MED_COADD_STD);
+<a name="l00186"></a>00186 
+<a name="l00187"></a>00187     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(procatg,PRO_COADD_PSF) == 0) {
+<a name="l00188"></a>00188     strcpy(pro_mjit,PRO_MASK_COADD_PSF);
+<a name="l00189"></a>00189     strcpy(pro_obs,PRO_OBS_PSF);
+<a name="l00190"></a>00190     strcpy(pro_med,PRO_MED_COADD_PSF);
+<a name="l00191"></a>00191     } <span class="keywordflow">else</span> {
+<a name="l00192"></a>00192     strcpy(pro_mjit,PRO_MASK_COADD_OBJ);
+<a name="l00193"></a>00193     strcpy(pro_obs,PRO_OBS_OBJ);
+<a name="l00194"></a>00194     strcpy(pro_med,PRO_MED_COADD_OBJ);
+<a name="l00195"></a>00195     }
+<a name="l00196"></a>00196 
+<a name="l00197"></a>00197 
+<a name="l00198"></a>00198     <span class="comment">/*----parse input data and parameters to set cube_config cfg---*/</span>
+<a name="l00199"></a>00199     check_nomsg(stk = cpl_frameset_new());
+<a name="l00200"></a>00200 
+<a name="l00201"></a>00201     cknull(cfg = sinfo_parse_cpl_input_objnod(config,sof,&stk),
+<a name="l00202"></a>00202        <span class="stringliteral">"Error setting parameter configuration"</span>);
+<a name="l00203"></a>00203  
+<a name="l00204"></a>00204     ck0(sinfo_check_input_data(cfg),<span class="stringliteral">"error checking input"</span>);
+<a name="l00205"></a>00205 
+<a name="l00206"></a>00206     <span class="keywordflow">if</span> ( cfg->jitterind == 1 )
+<a name="l00207"></a>00207     {
+<a name="l00208"></a>00208         cknull(times = (<span class="keywordtype">double</span>*) cpl_calloc (cfg->nframes, sizeof (<span class="keywordtype">double</span>)), 
+<a name="l00209"></a>00209            <span class="stringliteral">" could not allocate memory!"</span>) ;
+<a name="l00210"></a>00210  
+<a name="l00211"></a>00211         cknull(offsetx = (<span class="keywordtype">float</span>*) cpl_calloc (cfg->nframes, <span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)),
+<a name="l00212"></a>00212            <span class="stringliteral">" could not allocate memory!"</span>) ;
+<a name="l00213"></a>00213 
+<a name="l00214"></a>00214         cknull(offsety = (<span class="keywordtype">float</span>*) cpl_calloc (cfg->nframes, <span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)),
+<a name="l00215"></a>00215            <span class="stringliteral">" could not allocate memory!"</span>) ;
+<a name="l00216"></a>00216     }
+<a name="l00217"></a>00217   
+<a name="l00218"></a>00218     <span class="keywordflow">if</span> (cfg->jitterind == 0)
+<a name="l00219"></a>00219     {
+<a name="l00220"></a>00220         <span class="keywordflow">if</span> ( NULL != (partname = strtok(cfg->outName, <span class="stringliteral">"."</span>))) 
+<a name="l00221"></a>00221         {
+<a name="l00222"></a>00222             partname2 = strtok (NULL, <span class="stringliteral">"."</span>) ;
+<a name="l00223"></a>00223             partind = 1 ;
+<a name="l00224"></a>00224         }
+<a name="l00225"></a>00225     }
+<a name="l00226"></a>00226 
+<a name="l00227"></a>00227     ck0(sinfo_auto_size_cube5(cfg,&ref_offx,&ref_offy,
+<a name="l00228"></a>00228                                 &offx_min,&offy_min,
+<a name="l00229"></a>00229                                 &offx_max,&offy_max),
+<a name="l00230"></a>00230                              <span class="stringliteral">"Error resizing cube"</span>);
+<a name="l00231"></a>00231   
+<a name="l00232"></a>00232 
+<a name="l00233"></a>00233 
+<a name="l00234"></a>00234     check_nomsg(p=cpl_parameterlist_find(config,<span class="stringliteral">"sinfoni.objnod.fcol"</span>));
+<a name="l00235"></a>00235     check_nomsg(fcol=cpl_parameter_get_double(p));
+<a name="l00236"></a>00236    
+<a name="l00237"></a>00237     <span class="keywordflow">if</span>(NULL != cpl_frameset_find(sof,PRO_ILL_COR)) {
+<a name="l00238"></a>00238      sinfo_msg(<span class="stringliteral">"Illumination correction cube is provided"</span>);
+<a name="l00239"></a>00239      frame = cpl_frameset_find(sof,PRO_ILL_COR);
+<a name="l00240"></a>00240      ill_cor=cpl_image_load(cpl_frame_get_filename(frame),CPL_TYPE_FLOAT,0,0);
+<a name="l00241"></a>00241     } <span class="keywordflow">else</span> {
+<a name="l00242"></a>00242      sinfo_msg(<span class="stringliteral">"Illumination correction cube not provided"</span>);
+<a name="l00243"></a>00243      cpl_error_reset();
+<a name="l00244"></a>00244     }
+<a name="l00245"></a>00245 
+<a name="l00246"></a>00246      <span class="keywordflow">for</span> ( n = 0 ; n < cfg->nframes ; n++ )
+<a name="l00247"></a>00247      {
+<a name="l00248"></a>00248 
+<a name="l00249"></a>00249         sinfo_msg(<span class="stringliteral">"Read FITS information"</span>);
+<a name="l00250"></a>00250         name = cfg->framelist[n] ;    
+<a name="l00251"></a>00251         <span class="keywordflow">if</span> (n == 0)
+<a name="l00252"></a>00252     {
+<a name="l00253"></a>00253         strcpy (name_jitter, name) ;
+<a name="l00254"></a>00254     }   
+<a name="l00255"></a>00255         <span class="keywordflow">if</span>( sinfo_is_fits_file(name) != 1) {
+<a name="l00256"></a>00256           <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Input file %s is not FITS"</span>,name);
+<a name="l00257"></a>00257           <span class="keywordflow">goto</span> cleanup;
+<a name="l00258"></a>00258     }
+<a name="l00259"></a>00259     
+<a name="l00260"></a>00260     <span class="comment">/* get some header values and compute the CD-sinfo_matrix */</span>
+<a name="l00261"></a>00261         plist=cpl_propertylist_load(name,0);
+<a name="l00262"></a>00262     pixelscale = sinfo_pfits_get_pixscale(plist) /2;
+<a name="l00263"></a>00263     angle = sinfo_pfits_get_posangle(plist) ;
+<a name="l00264"></a>00264         <span class="comment">/* in PUPIL data there is not posangle info: we reset the error */</span>
+<a name="l00265"></a>00265         <span class="keywordflow">if</span>(cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l00266"></a>00266       cpl_error_reset();
+<a name="l00267"></a>00267         }
+<a name="l00268"></a>00268     sinfo_free_propertylist(&plist);
+<a name="l00269"></a>00269     radangle = angle * PI_NUMB / 180. ;
+<a name="l00270"></a>00270     cd1_1 = cos(radangle) ;
+<a name="l00271"></a>00271     cd1_2 = sin(radangle) ;
+<a name="l00272"></a>00272     cd2_1 = -sin(radangle) ;
+<a name="l00273"></a>00273     cd2_2 = cos(radangle) ;
+<a name="l00274"></a>00274     
+<a name="l00275"></a>00275     sinfo_msg(<span class="stringliteral">"frame no.: %d, name: %s\n"</span>, n, name) ;
+<a name="l00276"></a>00276     cknull(im = cpl_image_load(name,CPL_TYPE_FLOAT,0,0),
+<a name="l00277"></a>00277            <span class="stringliteral">" could not load frame %s!"</span>,name) ;
+<a name="l00278"></a>00278 
+<a name="l00279"></a>00279     <span class="keywordflow">if</span> (cfg->jitterind == 1)
+<a name="l00280"></a>00280     {
+<a name="l00281"></a>00281       exptime = sinfo_pfits_get_ditndit(name) ;
+<a name="l00282"></a>00282 
+<a name="l00283"></a>00283       <span class="keywordflow">if</span> (exptime == FLAG)
+<a name="l00284"></a>00284         {
+<a name="l00285"></a>00285           <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"could not read fits header keyword exptime!"</span>);
+<a name="l00286"></a>00286           <span class="keywordflow">goto</span> cleanup;
+<a name="l00287"></a>00287         }
+<a name="l00288"></a>00288       times[n] = exptime ;
+<a name="l00289"></a>00289           ck0(sinfo_new_assign_offset(n,name,offsetx,offsety,
+<a name="l00290"></a>00290                                       ref_offx,ref_offy),
+<a name="l00291"></a>00291                                       <span class="stringliteral">"Error assigning offsets"</span>);
+<a name="l00292"></a>00292 
+<a name="l00293"></a>00293     }
+<a name="l00294"></a>00294 
+<a name="l00295"></a>00295         <span class="comment">/*</span>
+<a name="l00296"></a>00296 <span class="comment">         *--------------------------------------------------------------    </span>
+<a name="l00297"></a>00297 <span class="comment">         *---------------------RESAMPLING-------------------------------</span>
+<a name="l00298"></a>00298 <span class="comment">     *--------------------------------------------------------------</span>
+<a name="l00299"></a>00299 <span class="comment">         */</span>
+<a name="l00300"></a>00300         sinfo_msg(<span class="stringliteral">"Resampling object"</span>);
+<a name="l00301"></a>00301     cknull(wavemapim = cpl_image_load(cfg->wavemap,CPL_TYPE_FLOAT,0,0),
+<a name="l00302"></a>00302            <span class="stringliteral">"could not load wavemap"</span>);
+<a name="l00303"></a>00303 
+<a name="l00304"></a>00304         cknull(resampledImage = sinfo_new_defined_resampling( im, 
+<a name="l00305"></a>00305                                   wavemapim, 
+<a name="l00306"></a>00306                                   cfg->ncoeffs,
+<a name="l00307"></a>00307                                   &cfg->nrows,
+<a name="l00308"></a>00308                                   &dis,
+<a name="l00309"></a>00309                                   &mi,
+<a name="l00310"></a>00310                                   &ma,
+<a name="l00311"></a>00311                                   &centralLambda,
+<a name="l00312"></a>00312                                   &centralpix),
+<a name="l00313"></a>00313            <span class="stringliteral">" sinfo_definedResampling() failed"</span> ) ;
+<a name="l00314"></a>00314 
+<a name="l00315"></a>00315  
+<a name="l00316"></a>00316     <span class="keywordflow">if</span>(n ==0) {
+<a name="l00317"></a>00317           <span class="keywordflow">if</span>(strcmp(cfg->mflat_dist,<span class="stringliteral">"not_found"</span>) != 0) {
+<a name="l00318"></a>00318         sinfo_msg(<span class="stringliteral">"Resampling master flat"</span>);
+<a name="l00319"></a>00319         cknull(flat_im=cpl_image_load(cfg->mflat_dist,CPL_TYPE_FLOAT,0,0),
+<a name="l00320"></a>00320                    <span class="stringliteral">"Distorted master flat field not found\n"</span>
+<a name="l00321"></a>00321                    <span class="stringliteral">"You may have set --stack-flat_ind=FALSE\n"</span>
+<a name="l00322"></a>00322                    <span class="stringliteral">"Flat field resampling skipped"</span>);
+<a name="l00323"></a>00323             cknull(res_flat = sinfo_new_defined_resampling(flat_im, 
+<a name="l00324"></a>00324                                wavemapim,
+<a name="l00325"></a>00325                                cfg->ncoeffs,
+<a name="l00326"></a>00326                                &cfg->nrows,
+<a name="l00327"></a>00327                                &dis,
+<a name="l00328"></a>00328                                &mi,
+<a name="l00329"></a>00329                                &ma,
+<a name="l00330"></a>00330                                &centralLambda,
+<a name="l00331"></a>00331                                &centralpix),
+<a name="l00332"></a>00332            <span class="stringliteral">" sinfo_definedResampling() failed"</span> ) ;
+<a name="l00333"></a>00333 
+<a name="l00334"></a>00334             sinfo_free_image(&flat_im) ;
+<a name="l00335"></a>00335       }
+<a name="l00336"></a>00336      
+<a name="l00337"></a>00337       <span class="keywordflow">if</span>(strcmp(cfg->sky_dist,<span class="stringliteral">"no_sky"</span>)!=0) {
+<a name="l00338"></a>00338         sinfo_msg(<span class="stringliteral">"Resampling sky"</span>);
+<a name="l00339"></a>00339         check_nomsg(sky_im=cpl_image_load(cfg->sky_dist,
+<a name="l00340"></a>00340                                               CPL_TYPE_FLOAT,0,0));
+<a name="l00341"></a>00341         cknull(res_sky = sinfo_new_defined_resampling(sky_im,
+<a name="l00342"></a>00342                               wavemapim,
+<a name="l00343"></a>00343                               cfg->ncoeffs,
+<a name="l00344"></a>00344                               &cfg->nrows,
+<a name="l00345"></a>00345                               &dis,
+<a name="l00346"></a>00346                               &mi,
+<a name="l00347"></a>00347                               &ma,
+<a name="l00348"></a>00348                               &centralLambda,
+<a name="l00349"></a>00349                               &centralpix),
+<a name="l00350"></a>00350            <span class="stringliteral">" sinfo_definedResampling() failed"</span> );
+<a name="l00351"></a>00351 
+<a name="l00352"></a>00352         sinfo_free_image(&sky_im) ;
+<a name="l00353"></a>00353 
+<a name="l00354"></a>00354        
+<a name="l00355"></a>00355       }
+<a name="l00356"></a>00356     }
+<a name="l00357"></a>00357 
+<a name="l00358"></a>00358         sinfo_msg (<span class="stringliteral">"dispersion %f\n"</span>, dis) ;
+<a name="l00359"></a>00359         sinfo_msg (<span class="stringliteral">"lambda min %f max %f cent %f\n"</span>, mi,ma,centralLambda ) ;
+<a name="l00360"></a>00360         sinfo_msg (<span class="stringliteral">"central pixel %d\n"</span>, centralpix) ; 
+<a name="l00361"></a>00361 
+<a name="l00362"></a>00362         sinfo_free_image(&im) ;
+<a name="l00363"></a>00363         sinfo_free_image(&wavemapim) ;
+<a name="l00364"></a>00364 
+<a name="l00365"></a>00365     <span class="comment">/*</span>
+<a name="l00366"></a>00366 <span class="comment">         *-------------------------------------------------------------------</span>
+<a name="l00367"></a>00367 <span class="comment">         *----------------Calibration----------------------------------------</span>
+<a name="l00368"></a>00368 <span class="comment">         *-------------------------------------------------------------------</span>
+<a name="l00369"></a>00369 <span class="comment">    */</span>
+<a name="l00370"></a>00370         <span class="comment">/*----Multiply with calibrated halogen lamp spectrum----*/</span> 
+<a name="l00371"></a>00371         <span class="keywordflow">if</span> (cfg->halocorrectInd == 1)
+<a name="l00372"></a>00372         {     
+<a name="l00373"></a>00373       sinfo_msg(<span class="stringliteral">"Calibration"</span>);
+<a name="l00374"></a>00374       check_nomsg(halospec = cpl_image_load(cfg->halospectrum,
+<a name="l00375"></a>00375                                                 CPL_TYPE_FLOAT,0,0)) ;
+<a name="l00376"></a>00376 
+<a name="l00377"></a>00377       cknull(calim = sinfo_new_multiply_image_with_spectrum(resampledImage,
+<a name="l00378"></a>00378                                                                 halospec),
+<a name="l00379"></a>00379                         <span class="stringliteral">" sinfo_new_multiply_image_with_spectrum() failed"</span> ) ;
+<a name="l00380"></a>00380 
+<a name="l00381"></a>00381       sinfo_free_image(&halospec) ;
+<a name="l00382"></a>00382       sinfo_free_image(&resampledImage) ;
+<a name="l00383"></a>00383       resampledImage = cpl_image_duplicate(calim) ;
+<a name="l00384"></a>00384       sinfo_free_image(&calim);
+<a name="l00385"></a>00385         }
+<a name="l00386"></a>00386     
+<a name="l00387"></a>00387         <span class="comment">/*</span>
+<a name="l00388"></a>00388 <span class="comment">         *-------------------------------------------------------------------</span>
+<a name="l00389"></a>00389 <span class="comment">         *------------------CUBECREATION-------------------------------------</span>
+<a name="l00390"></a>00390 <span class="comment">         *-------------------------------------------------------------------</span>
+<a name="l00391"></a>00391 <span class="comment">     */</span>
+<a name="l00392"></a>00392     sinfo_msg(<span class="stringliteral">"Cube creation"</span>);
+<a name="l00393"></a>00393     <span class="comment">/*---select north-south-test or fitting of slitlet edges--*/</span>
+<a name="l00394"></a>00394     <span class="keywordflow">if</span> (cfg->northsouthInd == 0) {
+<a name="l00395"></a>00395       sinfo_msg(<span class="stringliteral">"cfg->northsouthInd == 0"</span>);
+<a name="l00396"></a>00396       cknull(slit_edges = sinfo_read_slitlets_edges(cfg->nslits,cfg->poslist),
+<a name="l00397"></a>00397          <span class="stringliteral">"error reading slitlets edges"</span>);
+<a name="l00398"></a>00398     } <span class="keywordflow">else</span> {
+<a name="l00399"></a>00399       sinfo_msg(<span class="stringliteral">"cfg->northsouthInd != 0"</span>);
+<a name="l00400"></a>00400       cknull(distances = sinfo_read_distances(cfg->nslits,cfg->distlist),
+<a name="l00401"></a>00401          <span class="stringliteral">"error reading distances"</span>);
+<a name="l00402"></a>00402     }
+<a name="l00403"></a>00403  
+<a name="l00404"></a>00404     cknull(correct_dist = (<span class="keywordtype">float</span>*) cpl_calloc(cfg->nslits, sizeof (<span class="keywordtype">float</span>)),
+<a name="l00405"></a>00405            <span class="stringliteral">" could not allocate memory!"</span>) ;
+<a name="l00406"></a>00406 
+<a name="l00407"></a>00407     sinfo_msg(<span class="stringliteral">"Create cube object"</span>);
+<a name="l00408"></a>00408     <span class="keywordflow">if</span> (cfg->northsouthInd ==0 ) {
+<a name="l00409"></a>00409 
+<a name="l00410"></a>00410         cknull(cube = sinfo_new_make_cube_spi(resampledImage,
+<a name="l00411"></a>00411                                                   slit_edges,
+<a name="l00412"></a>00412                                                   correct_dist),
+<a name="l00413"></a>00413                                  <span class="stringliteral">" could not construct data cube!"</span>) ;
+<a name="l00414"></a>00414 
+<a name="l00415"></a>00415     }  <span class="keywordflow">else</span> {
+<a name="l00416"></a>00416        cknull(cube = sinfo_new_make_cube_dist(resampledImage,
+<a name="l00417"></a>00417                                                   fcol,
+<a name="l00418"></a>00418                                                   distances,
+<a name="l00419"></a>00419                                                   correct_dist),
+<a name="l00420"></a>00420                                          <span class="stringliteral">" could not construct a data cube!"</span>) ;
+<a name="l00421"></a>00421     }
+<a name="l00422"></a>00422     sinfo_free_image(&resampledImage);
+<a name="l00423"></a>00423 
+<a name="l00424"></a>00424     <span class="keywordflow">if</span>(n==0) {
+<a name="l00425"></a>00425       <span class="keywordflow">if</span>(strcmp(cfg->mflat_dist,<span class="stringliteral">"not_found"</span>)!=0) {
+<a name="l00426"></a>00426         sinfo_msg(<span class="stringliteral">"Create cube master flat"</span>);
+<a name="l00427"></a>00427         <span class="keywordflow">if</span> (cfg->northsouthInd ==0 ) {
+<a name="l00428"></a>00428           cknull(cflat=sinfo_new_make_cube_spi(res_flat,
+<a name="l00429"></a>00429                                                    slit_edges,
+<a name="l00430"></a>00430                                                    correct_dist),
+<a name="l00431"></a>00431                                 <span class="stringliteral">" could not construct data cube!"</span>) ;
+<a name="l00432"></a>00432         }  <span class="keywordflow">else</span> {
+<a name="l00433"></a>00433           cknull(cflat = sinfo_new_make_cube_dist(res_flat,
+<a name="l00434"></a>00434                                                       fcol,
+<a name="l00435"></a>00435                                                       distances,
+<a name="l00436"></a>00436                                                       correct_dist),
+<a name="l00437"></a>00437                                         <span class="stringliteral">" could not construct a data cube!"</span>) ;
+<a name="l00438"></a>00438         }
+<a name="l00439"></a>00439         sinfo_free_image(&res_flat);
+<a name="l00440"></a>00440       }
+<a name="l00441"></a>00441       <span class="keywordflow">if</span>(strcmp(cfg->sky_dist,<span class="stringliteral">"no_sky"</span>)!=0) {
+<a name="l00442"></a>00442 
+<a name="l00443"></a>00443         sinfo_msg(<span class="stringliteral">"Create cube sky"</span>);
+<a name="l00444"></a>00444         <span class="keywordflow">if</span> (cfg->northsouthInd ==0 ) {
+<a name="l00445"></a>00445           cknull(csky = sinfo_new_make_cube_spi(res_sky,
+<a name="l00446"></a>00446                                                     slit_edges,
+<a name="l00447"></a>00447                                                     correct_dist),
+<a name="l00448"></a>00448                                            <span class="stringliteral">" could not construct data cube!"</span>) ;
+<a name="l00449"></a>00449         }  <span class="keywordflow">else</span> {
+<a name="l00450"></a>00450           cknull(csky = sinfo_new_make_cube_dist(res_sky,
+<a name="l00451"></a>00451                                                      fcol,
+<a name="l00452"></a>00452                                                      distances,
+<a name="l00453"></a>00453                                                      correct_dist),
+<a name="l00454"></a>00454                                          <span class="stringliteral">" could not construct a data cube!"</span>) ;
+<a name="l00455"></a>00455         }
+<a name="l00456"></a>00456         sinfo_free_image(&res_sky);
+<a name="l00457"></a>00457       }
+<a name="l00458"></a>00458     }
+<a name="l00459"></a>00459 
+<a name="l00460"></a>00460 
+<a name="l00461"></a>00461         <span class="keywordflow">if</span> (cfg->northsouthInd ==0 )
+<a name="l00462"></a>00462      {
+<a name="l00463"></a>00463        sinfo_new_destroy_2Dfloatarray(&slit_edges,cfg->nslits);
+<a name="l00464"></a>00464      }
+<a name="l00465"></a>00465     <span class="keywordflow">else</span>
+<a name="l00466"></a>00466       {
+<a name="l00467"></a>00467             sinfo_new_destroy_array(&distances);
+<a name="l00468"></a>00468       }
+<a name="l00469"></a>00469 
+<a name="l00470"></a>00470         <span class="comment">/*</span>
+<a name="l00471"></a>00471 <span class="comment">         *--------------------------------------------------------------------</span>
+<a name="l00472"></a>00472 <span class="comment">         *------------------------FINETUNING----------------------------------</span>
+<a name="l00473"></a>00473 <span class="comment">         *--------------------------------------------------------------------</span>
+<a name="l00474"></a>00474 <span class="comment">         * shift the rows of the reconstructed images of the data cube to the </span>
+<a name="l00475"></a>00475 <span class="comment">         * correct sub pixel position select the shift method: polynomial </span>
+<a name="l00476"></a>00476 <span class="comment">         * interpolation, FFT or cubic spline interpolation</span>
+<a name="l00477"></a>00477 <span class="comment">         *--------------------------------------------------------------------</span>
+<a name="l00478"></a>00478 <span class="comment">         */</span>
+<a name="l00479"></a>00479  
+<a name="l00480"></a>00480     <span class="keywordflow">if</span>(n==0) {
+<a name="l00481"></a>00481       <span class="keywordflow">if</span>(strcmp(cfg->sky_dist,<span class="stringliteral">"no_sky"</span>)!=0) {
+<a name="l00482"></a>00482          cknull(csky2=sinfo_new_fine_tune(csky,
+<a name="l00483"></a>00483                                              correct_dist,
+<a name="l00484"></a>00484                                              cfg->method,
+<a name="l00485"></a>00485                                              cfg->order,
+<a name="l00486"></a>00486                           cfg->nslits),
+<a name="l00487"></a>00487             <span class="stringliteral">" could not fine tune the data cube"</span>) ;
+<a name="l00488"></a>00488 
+<a name="l00489"></a>00489          sinfo_free_imagelist(&csky);
+<a name="l00490"></a>00490          sinfo_msg(<span class="stringliteral">"Stretch output cube along Y direction"</span>);
+<a name="l00491"></a>00491  
+<a name="l00492"></a>00492          cknull(csky = sinfo_new_bin_cube(csky2,1,2,0,63,0,63),
+<a name="l00493"></a>00493             <span class="stringliteral">"error rebinning sky cube"</span>);
+<a name="l00494"></a>00494          sinfo_free_imagelist(&csky2);
+<a name="l00495"></a>00495 
+<a name="l00496"></a>00496        
+<a name="l00497"></a>00497      
+<a name="l00498"></a>00498          ck0(sinfo_pro_save_ims(csky,sof,sof,<span class="stringliteral">"out_sky_cube.fits"</span>,
+<a name="l00499"></a>00499                     PRO_OBS_SKY,NULL,plugin_id,config),
+<a name="l00500"></a>00500          <span class="stringliteral">"cannot dump cube %s"</span>, <span class="stringliteral">"out_sky_cube.fits"</span>);
+<a name="l00501"></a>00501  
+<a name="l00502"></a>00502          cknull(eima_med=sinfo_new_median_cube(csky),
+<a name="l00503"></a>00503                 <span class="stringliteral">"Creating an average image"</span>);
+<a name="l00504"></a>00504          check_nomsg(center_x = cpl_image_get_size_x(eima_med)/ 2. + 0.5);
+<a name="l00505"></a>00505          check_nomsg(center_y = cpl_image_get_size_y(eima_med)/ 2. + 0.5);
+<a name="l00506"></a>00506 
+<a name="l00507"></a>00507             sinfo_new_set_wcs_cube(csky, <span class="stringliteral">"out_sky_cube.fits"</span>, centralLambda, 
+<a name="l00508"></a>00508                           dis, centralpix, center_x, center_y);
+<a name="l00509"></a>00509 
+<a name="l00510"></a>00510          sinfo_free_imagelist(&csky) ;
+<a name="l00511"></a>00511 
+<a name="l00512"></a>00512          ck0(sinfo_pro_save_ima(eima_med,sof,sof,<span class="stringliteral">"out_sky_med.fits"</span>,
+<a name="l00513"></a>00513                     PRO_SKY_MED,NULL,plugin_id,config),
+<a name="l00514"></a>00514          <span class="stringliteral">"cannot save ima %s"</span>, <span class="stringliteral">"out_sky_med.fits"</span>);
+<a name="l00515"></a>00515 
+<a name="l00516"></a>00516             sinfo_new_set_wcs_image(eima_med,<span class="stringliteral">"out_sky_med.fits"</span>, 
+<a name="l00517"></a>00517                                      center_x, center_y);
+<a name="l00518"></a>00518          sinfo_free_image(&eima_med);
+<a name="l00519"></a>00519       }
+<a name="l00520"></a>00520 
+<a name="l00521"></a>00521 
+<a name="l00522"></a>00522       <span class="keywordflow">if</span>(strcmp(cfg->mflat_dist,<span class="stringliteral">"not_found"</span>)!=0) {
+<a name="l00523"></a>00523 
+<a name="l00524"></a>00524         cknull(cflat2=sinfo_new_fine_tune(cflat,correct_dist,
+<a name="l00525"></a>00525                                               cfg->method,cfg->order,
+<a name="l00526"></a>00526                                               cfg->nslits),
+<a name="l00527"></a>00527                                        <span class="stringliteral">" could not fine tune the data cube"</span>) ;
+<a name="l00528"></a>00528 
+<a name="l00529"></a>00529         sinfo_free_imagelist(&cflat);
+<a name="l00530"></a>00530         sinfo_msg(<span class="stringliteral">"Stretch output cube along Y direction"</span>);
+<a name="l00531"></a>00531  
+<a name="l00532"></a>00532         cknull(cflat = sinfo_new_bin_cube(cflat2,1,2,0,63,0,63),
+<a name="l00533"></a>00533            <span class="stringliteral">"Error binning flat cube"</span>);
+<a name="l00534"></a>00534         sinfo_free_imagelist(&cflat2);
+<a name="l00535"></a>00535 
+<a name="l00536"></a>00536         ck0(sinfo_pro_save_ims(cflat,sof,sof,OBJNOD_OUT_MFLAT_CUBE_FILENAME,
+<a name="l00537"></a>00537                    PRO_MFLAT_CUBE,NULL,plugin_id,config),
+<a name="l00538"></a>00538         <span class="stringliteral">"cannot save cube %s"</span>, OBJNOD_OUT_MFLAT_CUBE_FILENAME);
+<a name="l00539"></a>00539 
+<a name="l00540"></a>00540         cknull(eima_avg=sinfo_new_average_cube_to_image(cflat),
+<a name="l00541"></a>00541                <span class="stringliteral">"Creating an average image"</span>);
+<a name="l00542"></a>00542 
+<a name="l00543"></a>00543         ck0(sinfo_pro_save_ima(eima_avg,sof,sof,<span class="stringliteral">"out_mflat_avg.fits"</span>,
+<a name="l00544"></a>00544                    <span class="stringliteral">"MFLAT_AVG"</span>,NULL,plugin_id,config),
+<a name="l00545"></a>00545         <span class="stringliteral">"cannot save ima %s"</span>, <span class="stringliteral">"out_mflat_avg.fits"</span>);
+<a name="l00546"></a>00546 
+<a name="l00547"></a>00547         sinfo_free_image(&eima_avg);
+<a name="l00548"></a>00548 
+<a name="l00549"></a>00549         cknull(eima_med=sinfo_new_median_cube(cflat),
+<a name="l00550"></a>00550            <span class="stringliteral">"Error computing median on cube flat"</span>);
+<a name="l00551"></a>00551 
+<a name="l00552"></a>00552         ck0(sinfo_pro_save_ima(eima_med,sof,sof,<span class="stringliteral">"out_mflat_med.fits"</span>,
+<a name="l00553"></a>00553                    <span class="stringliteral">"MFLAT_MED"</span>,NULL,plugin_id,config),
+<a name="l00554"></a>00554         <span class="stringliteral">"cannot save ima %s"</span>, <span class="stringliteral">"out_mflat_med.fits"</span>);
+<a name="l00555"></a>00555 
+<a name="l00556"></a>00556         sinfo_free_imagelist(&cflat); 
+<a name="l00557"></a>00557         sinfo_free_image(&eima_med);
+<a name="l00558"></a>00558       }
+<a name="l00559"></a>00559     }
+<a name="l00560"></a>00560        
+<a name="l00561"></a>00561 
+<a name="l00562"></a>00562         cknull(outcube2=sinfo_new_fine_tune(cube,
+<a name="l00563"></a>00563                                             correct_dist,
+<a name="l00564"></a>00564                                             cfg->method,
+<a name="l00565"></a>00565                                             cfg->order,
+<a name="l00566"></a>00566                                             cfg->nslits),
+<a name="l00567"></a>00567                                      <span class="stringliteral">" could not fine tune the data cube"</span>) ;
+<a name="l00568"></a>00568 
+<a name="l00569"></a>00569         sinfo_msg(<span class="stringliteral">"Stretch output cube along Y direction"</span>);
+<a name="l00570"></a>00570         cknull(outcube = sinfo_new_bin_cube(outcube2,1,2,0,63,0,63),
+<a name="l00571"></a>00571            <span class="stringliteral">"Error binning cube"</span>);
+<a name="l00572"></a>00572         sinfo_free_imagelist(&cube);
+<a name="l00573"></a>00573         cknull_nomsg(qclog_tbl=sinfo_qclog_init());
+<a name="l00574"></a>00574         sinfo_get_pupil_shift(outcube,n,&qclog_tbl);
+<a name="l00575"></a>00575         snprintf(file_name,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%2.2d%s"</span>,
+<a name="l00576"></a>00576          <span class="stringliteral">"out_cube_obj"</span>,n,<span class="stringliteral">".fits"</span>);
+<a name="l00577"></a>00577         ck0(sinfo_pro_save_ims(outcube,sof,sof,file_name,
+<a name="l00578"></a>00578                    pro_obs,qclog_tbl,plugin_id,config),
+<a name="l00579"></a>00579         <span class="stringliteral">"cannot save cube %s"</span>, file_name);
+<a name="l00580"></a>00580 
+<a name="l00581"></a>00581 
+<a name="l00582"></a>00582         sinfo_free_table(&qclog_tbl);
+<a name="l00583"></a>00583     check_nomsg(center_x = cpl_image_get_size_x(
+<a name="l00584"></a>00584                                cpl_imagelist_get(outcube,0))/2.+0.5) ;
+<a name="l00585"></a>00585     check_nomsg(center_y = cpl_image_get_size_y(
+<a name="l00586"></a>00586                                cpl_imagelist_get(outcube,0))/2.+0.5 );
+<a name="l00587"></a>00587    
+<a name="l00588"></a>00588 
+<a name="l00589"></a>00589     sinfo_new_set_wcs_cube(outcube, file_name, centralLambda, dis, 
+<a name="l00590"></a>00590                      centralpix, center_x, center_y);
+<a name="l00591"></a>00591 
+<a name="l00592"></a>00592        <span class="comment">/* free memory */</span>
+<a name="l00593"></a>00593         <span class="comment">/* to prevent error message comment next line */</span>
+<a name="l00594"></a>00594         sinfo_free_imagelist(&outcube2);
+<a name="l00595"></a>00595         sinfo_free_imagelist(&outcube) ;
+<a name="l00596"></a>00596     sinfo_free_float(&correct_dist) ;
+<a name="l00597"></a>00597 
+<a name="l00598"></a>00598 
+<a name="l00599"></a>00599     } <span class="comment">/* end loop over n (nframes) */</span>
+<a name="l00600"></a>00600  
+<a name="l00601"></a>00601     <span class="comment">/* leak free */</span>
+<a name="l00602"></a>00602     <span class="keywordflow">if</span>(cfg->jitterind == 0) {
+<a name="l00603"></a>00603       <span class="keywordflow">goto</span> exit;
+<a name="l00604"></a>00604     }   
+<a name="l00605"></a>00605      
+<a name="l00606"></a>00606     <span class="comment">/* Here in case of autojitter we estimate the sky */</span>
+<a name="l00607"></a>00607     <span class="keywordflow">if</span>( (cfg->size_x*cfg->size_y*cfg->nframes) > (100*mosaic_max_size) ) {
+<a name="l00608"></a>00608       <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"Coadd cube size:%d,%d. N frames: %d"</span>,
+<a name="l00609"></a>00609                            cfg->size_x,cfg->size_y,cfg->nframes);
+<a name="l00610"></a>00610       <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"Max allowed should be such that "</span>
+<a name="l00611"></a>00611                         <span class="stringliteral">"sixeX*sixeY*Nframes < 100*%d"</span>,mosaic_max_size);
+<a name="l00612"></a>00612       <span class="keywordflow">goto</span> exit;
+<a name="l00613"></a>00613     } 
+<a name="l00614"></a>00614  
+<a name="l00615"></a>00615     <span class="keywordflow">if</span> ( cfg->jitterind == 1 )
+<a name="l00616"></a>00616     {  
+<a name="l00617"></a>00617         check_nomsg(p = cpl_parameterlist_find(config, <span class="stringliteral">"sinfoni.objnod.vllx"</span>));
+<a name="l00618"></a>00618         check_nomsg(vllx = cpl_parameter_get_int(p));
+<a name="l00619"></a>00619         check_nomsg(p = cpl_parameterlist_find(config, <span class="stringliteral">"sinfoni.objnod.vlly"</span>));
+<a name="l00620"></a>00620         check_nomsg(vlly = cpl_parameter_get_int(p));
+<a name="l00621"></a>00621         check_nomsg(p = cpl_parameterlist_find(config, <span class="stringliteral">"sinfoni.objnod.vurx"</span>));
+<a name="l00622"></a>00622         check_nomsg(vurx = cpl_parameter_get_int(p));
+<a name="l00623"></a>00623         check_nomsg(p = cpl_parameterlist_find(config, <span class="stringliteral">"sinfoni.objnod.vury"</span>));
+<a name="l00624"></a>00624         check_nomsg(vury = cpl_parameter_get_int(p));
+<a name="l00625"></a>00625  
+<a name="l00626"></a>00626         cknull(cube_tmp =(cpl_imagelist**) cpl_calloc(cfg->nframes, 
+<a name="l00627"></a>00627                                                       sizeof (cpl_imagelist*)),
+<a name="l00628"></a>00628                                      <span class="stringliteral">"Could not allocate memory for cube_tmp"</span>);
+<a name="l00629"></a>00629         cknull(cubeobject =(cpl_imagelist**) cpl_calloc(cfg->nframes, 
+<a name="l00630"></a>00630                                                         <span class="keyword">sizeof</span>(cpl_imagelist*)),
+<a name="l00631"></a>00631                                     <span class="stringliteral">"Could not allocate memory for cubeobject"</span>);
+<a name="l00632"></a>00632 
+<a name="l00633"></a>00633     <span class="keywordflow">for</span> ( n = 0 ; n < cfg->nframes ; n++ ) {
+<a name="l00634"></a>00634           snprintf(file_name,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%2.2d%s"</span>,<span class="stringliteral">"out_cube_obj"</span>,
+<a name="l00635"></a>00635                      n,<span class="stringliteral">".fits"</span>);
+<a name="l00636"></a>00636       check_nomsg(cube_tmp[n] = cpl_imagelist_load(file_name,
+<a name="l00637"></a>00637                                CPL_TYPE_FLOAT,0));
+<a name="l00638"></a>00638       check_nomsg(cubeobject[n] = sinfo_new_cube_getvig(cube_tmp[n],
+<a name="l00639"></a>00639                                 1+vllx,1+vlly,
+<a name="l00640"></a>00640                                 64-vurx,64-vury));
+<a name="l00641"></a>00641           check_nomsg(sinfo_free_imagelist(&cube_tmp[n]));
+<a name="l00642"></a>00642     }
+<a name="l00643"></a>00643         sinfo_free_array_imagelist(&cube_tmp);
+<a name="l00644"></a>00644 
+<a name="l00645"></a>00645     }
+<a name="l00646"></a>00646 
+<a name="l00647"></a>00647     <span class="comment">/*</span>
+<a name="l00648"></a>00648 <span class="comment">        ---------------------------------------------------------------------</span>
+<a name="l00649"></a>00649 <span class="comment">        ------------------------JITTERING------------------------------------</span>
+<a name="l00650"></a>00650 <span class="comment">        ---------------------------------------------------------------------</span>
+<a name="l00651"></a>00651 <span class="comment">    */</span>
+<a name="l00652"></a>00652 
+<a name="l00653"></a>00653     <span class="keywordflow">if</span> (cfg->jitterind == 1)
+<a name="l00654"></a>00654     {
+<a name="l00655"></a>00655     sinfo_msg(<span class="stringliteral">"Jittering..."</span>);
+<a name="l00656"></a>00656 
+<a name="l00657"></a>00657         sinfo_msg(<span class="stringliteral">"Coadded cube size. x: %d y: %d"</span>,
+<a name="l00658"></a>00658              cfg->size_x,cfg->size_y);
+<a name="l00659"></a>00659         check_nomsg(jittercube = cpl_imagelist_new()) ;
+<a name="l00660"></a>00660 
+<a name="l00661"></a>00661 
+<a name="l00662"></a>00662     <span class="comment">/* </span>
+<a name="l00663"></a>00663 <span class="comment">        ---------------------------------------------------------------------</span>
+<a name="l00664"></a>00664 <span class="comment">        -------------------THOMAS ALGORITHM----------------------------------</span>
+<a name="l00665"></a>00665 <span class="comment">        ---------------------------------------------------------------------</span>
+<a name="l00666"></a>00666 <span class="comment">    */</span>
+<a name="l00667"></a>00667        
+<a name="l00668"></a>00668         check_nomsg(p=cpl_parameterlist_find(config,
+<a name="l00669"></a>00669                                              <span class="stringliteral">"sinfoni.objnod.scales_sky"</span>));
+<a name="l00670"></a>00670         check_nomsg(scales_sky=cpl_parameter_get_bool(p));
+<a name="l00671"></a>00671         check_nomsg(p=cpl_parameterlist_find(config,<span class="stringliteral">"sinfoni.objnod.ks_clip"</span>));
+<a name="l00672"></a>00672         check_nomsg(ks_clip = cpl_parameter_get_bool(p));
+<a name="l00673"></a>00673         check_nomsg(p=cpl_parameterlist_find(config,<span class="stringliteral">"sinfoni.objnod.kappa"</span>));
+<a name="l00674"></a>00674         check_nomsg(kappa = cpl_parameter_get_double(p));
+<a name="l00675"></a>00675 
+<a name="l00676"></a>00676 
+<a name="l00677"></a>00677     <span class="keywordflow">if</span>(scales_sky == 1) {
+<a name="l00678"></a>00678       sinfo_msg(<span class="stringliteral">"Subtract spatial sinfo_median to each cube plane"</span>);
+<a name="l00679"></a>00679       <span class="keywordflow">for</span>(n=0;n<cfg->nframes;n++) {
+<a name="l00680"></a>00680         sinfo_msg(<span class="stringliteral">"process cube %d\n"</span>,n);
+<a name="l00681"></a>00681         sinfo_new_sinfoni_correct_median_it(&(cubeobject[n]));
+<a name="l00682"></a>00682       }
+<a name="l00683"></a>00683     }
+<a name="l00684"></a>00684 
+<a name="l00685"></a>00685 
+<a name="l00686"></a>00686         <span class="comment">/* AMO CHECK */</span>
+<a name="l00687"></a>00687 
+<a name="l00688"></a>00688         cknull(maskcube=cpl_imagelist_new(),<span class="stringliteral">"could not allocate cube!"</span>);
+<a name="l00689"></a>00689         
+<a name="l00690"></a>00690     <span class="comment">/* Illumination correction */</span> 
+<a name="l00691"></a>00691         <span class="keywordflow">if</span>(ill_cor != NULL) {
+<a name="l00692"></a>00692       <span class="keywordflow">for</span>(n=0;n<cfg->nframes;n++) {
+<a name="l00693"></a>00693         sinfo_msg(<span class="stringliteral">"Illumination correction is applied"</span>);
+<a name="l00694"></a>00694         cpl_imagelist_divide_image(cubeobject[n],ill_cor);
+<a name="l00695"></a>00695       }
+<a name="l00696"></a>00696     }
+<a name="l00697"></a>00697         sinfo_free_image(&ill_cor);
+<a name="l00698"></a>00698     
+<a name="l00699"></a>00699     sinfo_msg(<span class="stringliteral">"Combine jittered cubes"</span>);
+<a name="l00700"></a>00700 
+<a name="l00701"></a>00701 
+<a name="l00702"></a>00702     <span class="keywordflow">if</span>(ks_clip == 1) {
+<a name="l00703"></a>00703       sinfo_msg(<span class="stringliteral">"Cube coaddition with kappa-sigma"</span>);
+<a name="l00704"></a>00704     }
+<a name="l00705"></a>00705         check_nomsg(onp=cpl_imagelist_get_size(cubeobject[0]));
+<a name="l00706"></a>00706     <span class="keywordflow">for</span>(z=0;z<onp;z+=z_stp) {
+<a name="l00707"></a>00707       z_siz=(z_stp < (onp-z)) ? z_stp : (onp-z);
+<a name="l00708"></a>00708       z_min=z;
+<a name="l00709"></a>00709       z_max=z_min+z_siz;
+<a name="l00710"></a>00710       sinfo_msg(<span class="stringliteral">"Coadding cubes: range [%4.4d,%4.4d) of 0-%d\n"</span>,
+<a name="l00711"></a>00711                            z_min,z_max,onp);
+<a name="l00712"></a>00712 
+<a name="l00713"></a>00713       <span class="keywordflow">for</span>(j=z_min;j<z_max;j++) {
+<a name="l00714"></a>00714             check_nomsg(j_img=cpl_image_new(cfg->size_x,
+<a name="l00715"></a>00715                                             cfg->size_y,CPL_TYPE_FLOAT));
+<a name="l00716"></a>00716         check_nomsg(cpl_imagelist_set(jittercube,j_img,j));
+<a name="l00717"></a>00717             check_nomsg(m_img = cpl_image_new(cfg->size_x,
+<a name="l00718"></a>00718                                               cfg->size_y,CPL_TYPE_FLOAT));
+<a name="l00719"></a>00719             check_nomsg(cpl_imagelist_set(maskcube,m_img,j));
+<a name="l00720"></a>00720       }
+<a name="l00721"></a>00721       <span class="keywordflow">if</span>(ks_clip == 1) {
+<a name="l00722"></a>00722         sinfo_new_combine_jittered_cubes_thomas_range(cubeobject,
+<a name="l00723"></a>00723                             jittercube,
+<a name="l00724"></a>00724                             maskcube,
+<a name="l00725"></a>00725                             cfg->nframes,
+<a name="l00726"></a>00726                             offsetx,offsety,
+<a name="l00727"></a>00727                             times,
+<a name="l00728"></a>00728                             cfg->kernel_type,
+<a name="l00729"></a>00729                             z_min,
+<a name="l00730"></a>00730                             z_max,
+<a name="l00731"></a>00731                             kappa);
+<a name="l00732"></a>00732 
+<a name="l00733"></a>00733       } <span class="keywordflow">else</span> {
+<a name="l00734"></a>00734         sinfo_new_combine_jittered_cubes_range(cubeobject, 
+<a name="l00735"></a>00735                                              jittercube,
+<a name="l00736"></a>00736                                              maskcube,
+<a name="l00737"></a>00737                          cfg->nframes,
+<a name="l00738"></a>00738                                              offsetx,
+<a name="l00739"></a>00739                          offsety, 
+<a name="l00740"></a>00740                                              times,
+<a name="l00741"></a>00741                          cfg->kernel_type,
+<a name="l00742"></a>00742                                              z_min,
+<a name="l00743"></a>00743                                              z_max) ;
+<a name="l00744"></a>00744       }
+<a name="l00745"></a>00745     }
+<a name="l00746"></a>00746         sinfo_new_convert_0_to_ZERO_for_cubes(jittercube) ; 
+<a name="l00747"></a>00747 
+<a name="l00748"></a>00748       <span class="keywordflow">if</span> (jittercube == NULL)
+<a name="l00749"></a>00749     {
+<a name="l00750"></a>00750         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" could not allocate new data cube!"</span>) ;
+<a name="l00751"></a>00751         <span class="keywordflow">goto</span> cleanup;
+<a name="l00752"></a>00752     }
+<a name="l00753"></a>00753 
+<a name="l00754"></a>00754         <span class="keywordflow">if</span> (maskcube == NULL)
+<a name="l00755"></a>00755     {
+<a name="l00756"></a>00756         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" could not merge the jittered data cubes\n"</span>) ;
+<a name="l00757"></a>00757             <span class="keywordflow">goto</span> cleanup;
+<a name="l00758"></a>00758     }
+<a name="l00759"></a>00759 
+<a name="l00760"></a>00760     <span class="keywordflow">for</span> ( i = 0 ; i <cfg->nframes  ; i++ ) {
+<a name="l00761"></a>00761       sinfo_free_imagelist(&cubeobject[i]);
+<a name="l00762"></a>00762     }
+<a name="l00763"></a>00763     sinfo_free_array_imagelist(&cubeobject);
+<a name="l00764"></a>00764 
+<a name="l00765"></a>00765         newcenter_x = cfg->size_x / 2. + 0.5 ;
+<a name="l00766"></a>00766     newcenter_y = cfg->size_y / 2. + 0.5 ;
+<a name="l00767"></a>00767 
+<a name="l00768"></a>00768         ck0(sinfo_pro_save_ims(jittercube,sof,sof,cfg->outName,
+<a name="l00769"></a>00769                    procatg,NULL,plugin_id,config),
+<a name="l00770"></a>00770         <span class="stringliteral">"cannot save cube %s"</span>, cfg->outName);
+<a name="l00771"></a>00771 
+<a name="l00772"></a>00772       sinfo_new_set_wcs_cube(jittercube, cfg->outName, centralLambda, 
+<a name="l00773"></a>00773                                dis, centralpix, center_x, center_y);
+<a name="l00774"></a>00774 
+<a name="l00775"></a>00775         cknull(jitter_image = sinfo_new_median_cube(jittercube),
+<a name="l00776"></a>00776                <span class="stringliteral">" could not do sinfo_medianCube()"</span>);
+<a name="l00777"></a>00777 
+<a name="l00778"></a>00778 
+<a name="l00779"></a>00779         ck0(sinfo_pro_save_ima(jitter_image,sof,sof,cfg->med_cube_name,
+<a name="l00780"></a>00780                    pro_med,NULL,plugin_id,config),
+<a name="l00781"></a>00781         <span class="stringliteral">"cannot save ima %s"</span>, cfg->outName);
+<a name="l00782"></a>00782 
+<a name="l00783"></a>00783       sinfo_new_set_wcs_image(jitter_image, cfg->med_cube_name,
+<a name="l00784"></a>00784                                 center_x,center_y);
+<a name="l00785"></a>00785 
+<a name="l00786"></a>00786         sinfo_free_image(&jitter_image);
+<a name="l00787"></a>00787 
+<a name="l00788"></a>00788         ck0(sinfo_pro_save_ims(maskcube,sof,sof,cfg->maskname,
+<a name="l00789"></a>00789                    pro_mjit,NULL,plugin_id,config),
+<a name="l00790"></a>00790         <span class="stringliteral">"cannot save cube %s"</span>, cfg->maskname);
+<a name="l00791"></a>00791 
+<a name="l00792"></a>00792      sinfo_new_set_wcs_cube(maskcube, cfg->maskname, centralLambda, 
+<a name="l00793"></a>00793                                dis, centralpix, center_x, center_y);
+<a name="l00794"></a>00794 
+<a name="l00795"></a>00795         sinfo_free_double(&times) ;
+<a name="l00796"></a>00796         sinfo_free_float(&offsetx) ;
+<a name="l00797"></a>00797         sinfo_free_float(&offsety) ;
+<a name="l00798"></a>00798         sinfo_free_imagelist(&maskcube) ;
+<a name="l00799"></a>00799         sinfo_free_imagelist(&jittercube) ;         
+<a name="l00800"></a>00800 
+<a name="l00801"></a>00801     } <span class="comment">/* end of jittering */</span>
+<a name="l00802"></a>00802 
+<a name="l00803"></a>00803  exit:
+<a name="l00804"></a>00804 
+<a name="l00805"></a>00805  <span class="comment">/* free memory */</span>
+<a name="l00806"></a>00806     sinfo_objnod_free(&cfg);
+<a name="l00807"></a>00807     sinfo_free_frameset(&stk);
+<a name="l00808"></a>00808     <span class="keywordflow">return</span> 0;   
+<a name="l00809"></a>00809 
+<a name="l00810"></a>00810  cleanup:
+<a name="l00811"></a>00811     sinfo_free_propertylist(&plist);
+<a name="l00812"></a>00812     sinfo_free_image(&jitter_image);
+<a name="l00813"></a>00813     sinfo_free_imagelist(&jittercube) ;
+<a name="l00814"></a>00814     sinfo_free_imagelist(&maskcube) ;
+<a name="l00815"></a>00815 
+<a name="l00816"></a>00816     <span class="keywordflow">if</span>(cfg != NULL) {
+<a name="l00817"></a>00817       <span class="keywordflow">if</span>(cube_tmp != NULL) {
+<a name="l00818"></a>00818     <span class="keywordflow">for</span> ( n = 0 ; n < cfg->nframes ; n++ ) {
+<a name="l00819"></a>00819       sinfo_free_imagelist(&(cube_tmp[n]));
+<a name="l00820"></a>00820     }
+<a name="l00821"></a>00821         sinfo_free_array_imagelist(&cube_tmp);
+<a name="l00822"></a>00822       }
+<a name="l00823"></a>00823       <span class="keywordflow">if</span>(cubeobject != NULL) {
+<a name="l00824"></a>00824     <span class="keywordflow">for</span> ( n = 0 ; n < cfg->nframes ; n++ ) {
+<a name="l00825"></a>00825       sinfo_free_imagelist(&(cubeobject[n]));
+<a name="l00826"></a>00826     }
+<a name="l00827"></a>00827         sinfo_free_array_imagelist(&cubeobject);
+<a name="l00828"></a>00828       }
+<a name="l00829"></a>00829 
+<a name="l00830"></a>00830     }
+<a name="l00831"></a>00831 
+<a name="l00832"></a>00832     sinfo_free_imagelist(&outcube2) ;
+<a name="l00833"></a>00833     sinfo_free_imagelist(&outcube) ;
+<a name="l00834"></a>00834     sinfo_free_table(&qclog_tbl);
+<a name="l00835"></a>00835     sinfo_free_image(&eima_avg);
+<a name="l00836"></a>00836     sinfo_free_image(&eima_med);
+<a name="l00837"></a>00837     sinfo_free_imagelist(&cflat) ;
+<a name="l00838"></a>00838     sinfo_free_imagelist(&cflat2) ;
+<a name="l00839"></a>00839     sinfo_free_imagelist(&cube) ;
+<a name="l00840"></a>00840     sinfo_free_imagelist(&csky) ;
+<a name="l00841"></a>00841     sinfo_free_imagelist(&csky2) ;
+<a name="l00842"></a>00842 
+<a name="l00843"></a>00843     <span class="keywordflow">if</span>(cfg!=NULL) {
+<a name="l00844"></a>00844       <span class="keywordflow">if</span> (cfg->northsouthInd ==0 ) {
+<a name="l00845"></a>00845     <span class="keywordflow">if</span>(slit_edges != NULL) {
+<a name="l00846"></a>00846        sinfo_new_destroy_2Dfloatarray(&slit_edges,cfg->nslits);
+<a name="l00847"></a>00847     }
+<a name="l00848"></a>00848       } <span class="keywordflow">else</span> {
+<a name="l00849"></a>00849     <span class="keywordflow">if</span> (distances != NULL ) {
+<a name="l00850"></a>00850             sinfo_new_destroy_array(&distances);
+<a name="l00851"></a>00851     }
+<a name="l00852"></a>00852       }
+<a name="l00853"></a>00853     }
+<a name="l00854"></a>00854 
+<a name="l00855"></a>00855     sinfo_free_float(&correct_dist);
+<a name="l00856"></a>00856     sinfo_free_image(&res_flat);
+<a name="l00857"></a>00857     sinfo_free_image(&res_sky);
+<a name="l00858"></a>00858     sinfo_free_image(&calim);
+<a name="l00859"></a>00859     sinfo_free_image(&halospec) ;
+<a name="l00860"></a>00860     sinfo_free_image(&sky_im) ;
+<a name="l00861"></a>00861     sinfo_free_image(&resampledImage);
+<a name="l00862"></a>00862     sinfo_free_image(&flat_im) ;
+<a name="l00863"></a>00863     sinfo_free_image(&wavemapim);
+<a name="l00864"></a>00864     sinfo_free_image(&im);
+<a name="l00865"></a>00865     sinfo_free_image(&ill_cor);
+<a name="l00866"></a>00866     sinfo_free_float(&offsety);
+<a name="l00867"></a>00867     sinfo_free_float(&offsetx);
+<a name="l00868"></a>00868     sinfo_free_double(&times);
+<a name="l00869"></a>00869     sinfo_objnod_free(&cfg);
+<a name="l00870"></a>00870     sinfo_free_frameset(&stk);
+<a name="l00871"></a>00871 
+<a name="l00872"></a>00872     <span class="keywordflow">return</span> -1;   
+<a name="l00873"></a>00873 
+<a name="l00874"></a>00874 
+<a name="l00875"></a>00875 
+<a name="l00876"></a>00876 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__new__objnod_8h_source.html b/html/sinfo__new__objnod_8h_source.html
new file mode 100644
index 0000000..963441b
--- /dev/null
+++ b/html/sinfo__new__objnod_8h_source.html
@@ -0,0 +1,86 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_new_objnod.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_new_objnod.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#ifndef SINFO_NEW_OBJNOD_H</span>
+<a name="l00002"></a>00002 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_NEW_OBJNOD_H</span>
+<a name="l00003"></a>00003 <span class="preprocessor"></span><span class="comment">/*</span>
+<a name="l00004"></a>00004 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00005"></a>00005 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00006"></a>00006 <span class="comment"> *</span>
+<a name="l00007"></a>00007 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00008"></a>00008 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00009"></a>00009 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00010"></a>00010 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00011"></a>00011 <span class="comment"> *</span>
+<a name="l00012"></a>00012 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00013"></a>00013 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00014"></a>00014 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00015"></a>00015 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00016"></a>00016 <span class="comment"> *</span>
+<a name="l00017"></a>00017 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00018"></a>00018 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00019"></a>00019 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00020"></a>00020 <span class="comment"> */</span>
+<a name="l00021"></a>00021 <span class="comment">/************************************************************************</span>
+<a name="l00022"></a>00022 <span class="comment">* E.S.O. - VLT project</span>
+<a name="l00023"></a>00023 <span class="comment">*</span>
+<a name="l00024"></a>00024 <span class="comment">* "@(#) $Id: sinfo_new_objnod.h,v 1.8 2007/06/06 07:10:45 amodigli Exp $"</span>
+<a name="l00025"></a>00025 <span class="comment">*</span>
+<a name="l00026"></a>00026 <span class="comment">* who       when      what</span>
+<a name="l00027"></a>00027 <span class="comment">* --------  --------  ----------------------------------------------</span>
+<a name="l00028"></a>00028 <span class="comment">* schreib  06/05/03  created</span>
+<a name="l00029"></a>00029 <span class="comment">*/</span>
+<a name="l00030"></a>00030 
+<a name="l00031"></a>00031 <span class="comment">/************************************************************************</span>
+<a name="l00032"></a>00032 <span class="comment"> * sinfo_objnod.h</span>
+<a name="l00033"></a>00033 <span class="comment"> * routines to create a data cube</span>
+<a name="l00034"></a>00034 <span class="comment"> *----------------------------------------------------------------------</span>
+<a name="l00035"></a>00035 <span class="comment"> */</span>
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="comment">/*</span>
+<a name="l00038"></a>00038 <span class="comment"> * header files</span>
+<a name="l00039"></a>00039 <span class="comment"> */</span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include <math.h></span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include <cpl.h></span>   
+<a name="l00042"></a>00042 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00043"></a>00043 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00044"></a>00044 <span class="comment"> *                        Function ANSI C prototypes</span>
+<a name="l00045"></a>00045 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00046"></a>00046 
+<a name="l00047"></a>00047 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00048"></a>00048 <span class="comment">   @name sinfo_new_objnod()</span>
+<a name="l00049"></a>00049 <span class="comment">   @param ini_file: file name of according .ini file</span>
+<a name="l00050"></a>00050 <span class="comment">   @return integer (0 if it worked, -1 if it doesn't) </span>
+<a name="l00051"></a>00051 <span class="comment">   @doc this routine does the resampling of an offset-corrected,</span>
+<a name="l00052"></a>00052 <span class="comment">        flatfielded, bad pixel corrected and</span>
+<a name="l00053"></a>00053 <span class="comment">        eventually interleaved data frame. Additionally, an intensity </span>
+<a name="l00054"></a>00054 <span class="comment">    calibration is carried through by using</span>
+<a name="l00055"></a>00055 <span class="comment">        a standard star or a black body measurement. </span>
+<a name="l00056"></a>00056 <span class="comment">    The spectral features of the flatfield halogen lamp are corrected.</span>
+<a name="l00057"></a>00057 <span class="comment">        Afterwards a data cube is created out of the resampled image.</span>
+<a name="l00058"></a>00058 <span class="comment">    It is the users choice to use either</span>
+<a name="l00059"></a>00059 <span class="comment">        the fitted sinfo_edge positions of the slitlets or the distances</span>
+<a name="l00060"></a>00060 <span class="comment">    of the slitlets gained from a north-south-test. </span>
+<a name="l00061"></a>00061 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00062"></a>00062 <span class="keywordtype">int</span> 
+<a name="l00063"></a>00063 sinfo_new_objnod (<span class="keyword">const</span> <span class="keywordtype">char</span>* plugin_id,
+<a name="l00064"></a>00064                   cpl_parameterlist* config, 
+<a name="l00065"></a>00065                   cpl_frameset* sof, 
+<a name="l00066"></a>00066                   <span class="keyword">const</span> <span class="keywordtype">char</span>* procatg) ;
+<a name="l00067"></a>00067 
+<a name="l00068"></a>00068 
+<a name="l00069"></a>00069 <span class="preprocessor">#endif </span>
+<a name="l00071"></a>00071 <span class="preprocessor"></span><span class="comment">/*--------------------------------------------------------------------------*/</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__new__prepare__stacked__frames_8c_source.html b/html/sinfo__new__prepare__stacked__frames_8c_source.html
new file mode 100644
index 0000000..4c8f916
--- /dev/null
+++ b/html/sinfo__new__prepare__stacked__frames_8c_source.html
@@ -0,0 +1,1415 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_new_prepare_stacked_frames.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_new_prepare_stacked_frames.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment"></span>
+<a name="l00021"></a>00021 <span class="comment">     File name    :       sinfo_new_prepare_stacked_frames.c</span>
+<a name="l00022"></a>00022 <span class="comment">   Author       :    A. Modigliani</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on   :    Sep 17, 2003</span>
+<a name="l00024"></a>00024 <span class="comment">   Description  :</span>
+<a name="l00025"></a>00025 <span class="comment"></span>
+<a name="l00026"></a>00026 <span class="comment">  this handles stacks of input frames, that means it takes a clean mean,</span>
+<a name="l00027"></a>00027 <span class="comment">  subtracts the off- from the on-frames, flatfields, corrects for static bad</span>
+<a name="l00028"></a>00028 <span class="comment">  pixels, corrects for a linear tilt of the spectra if necessary, and finally,</span>
+<a name="l00029"></a>00029 <span class="comment">  interleaves dithered exposures or convolves a single exposure with a</span>
+<a name="l00030"></a>00030 <span class="comment">  Gaussian, respectively.</span>
+<a name="l00031"></a>00031 <span class="comment"></span>
+<a name="l00032"></a>00032 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00033"></a>00033 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00034"></a>00034 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00035"></a>00035 <span class="preprocessor">#endif</span>
+<a name="l00036"></a>00036 <span class="preprocessor"></span>
+<a name="l00037"></a>00037 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00038"></a>00038 <span class="comment">                                Includes</span>
+<a name="l00039"></a>00039 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include "sinfo_new_prepare_stacked_frames.h"</span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include "sinfo_stack_ini_by_cpl.h"</span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include "sinfo_coltilt.h"</span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include "sinfo_image_ops.h"</span>
+<a name="l00044"></a>00044 <span class="preprocessor">#include "sinfo_merge.h"</span>
+<a name="l00045"></a>00045 <span class="preprocessor">#include "sinfo_utilities.h"</span>
+<a name="l00046"></a>00046 <span class="preprocessor">#include "sinfo_wave_calibration.h"</span>
+<a name="l00047"></a>00047 <span class="preprocessor">#include "sinfo_new_bezier.h"</span>
+<a name="l00048"></a>00048 <span class="preprocessor">#include "sinfo_shift_images.h"</span>
+<a name="l00049"></a>00049 <span class="preprocessor">#include "sinfo_product_config.h"</span>
+<a name="l00050"></a>00050 
+<a name="l00051"></a>00051 <span class="preprocessor">#include "sinfo_pro_save.h"</span>
+<a name="l00052"></a>00052 <span class="preprocessor">#include "sinfo_globals.h"</span>
+<a name="l00053"></a>00053 <span class="preprocessor">#include "sinfo_utilities.h"</span>
+<a name="l00054"></a>00054 <span class="preprocessor">#include "sinfo_dfs.h"</span>
+<a name="l00055"></a>00055 <span class="preprocessor">#include "sinfo_raw_types.h"</span>
+<a name="l00056"></a>00056 <span class="preprocessor">#include "sinfo_wcal_functions.h"</span>
+<a name="l00057"></a>00057 <span class="preprocessor">#include "sinfo_new_bezier.h"</span>
+<a name="l00058"></a>00058 
+<a name="l00059"></a>00059 <span class="preprocessor">#include "sinfo_hidden.h"</span>
+<a name="l00060"></a>00060 <span class="preprocessor">#include "sinfo_pro_types.h"</span>
+<a name="l00061"></a>00061 <span class="preprocessor">#include "sinfo_functions.h"</span>
+<a name="l00062"></a>00062 <span class="preprocessor">#include "sinfo_utils_wrappers.h"</span>
+<a name="l00063"></a>00063 <span class="preprocessor">#include "sinfo_error.h"</span>
+<a name="l00064"></a>00064 
+<a name="l00065"></a>00065 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00066"></a>00066 <span class="comment">                                Defines</span>
+<a name="l00067"></a>00067 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00077"></a>00077 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00078"></a>00078 <span class="comment">                             Function Definitions</span>
+<a name="l00079"></a>00079 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00080"></a>00080 
+<a name="l00081"></a>00081 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00082"></a>00082 <span class="comment">   Function     :       sinfo_new_prepare_stacked_frames()</span>
+<a name="l00083"></a>00083 <span class="comment">   In           :       ini_file: file name of according .ini file</span>
+<a name="l00084"></a>00084 <span class="comment">   Out          :       integer (0 if it worked, -1 if it doesn't)</span>
+<a name="l00085"></a>00085 <span class="comment">   Job          :</span>
+<a name="l00086"></a>00086 <span class="comment">  this handles stacks of input frames, that means it takes a clean mean,</span>
+<a name="l00087"></a>00087 <span class="comment">  subtracts the off- from the on-frames, flatfields, corrects for static bad</span>
+<a name="l00088"></a>00088 <span class="comment">  pixels, corrects for a linear tilt of the spectra if necessary, and finally,</span>
+<a name="l00089"></a>00089 <span class="comment">  interleaves dithered exposures or convolves a single exposure with a</span>
+<a name="l00090"></a>00090 <span class="comment">  Gaussian, respectively.</span>
+<a name="l00091"></a>00091 <span class="comment"></span>
+<a name="l00092"></a>00092 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00093"></a>00093 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00094"></a>00094 new_get_names(<span class="keyword">const</span> <span class="keywordtype">char</span>* pcatg, <span class="keyword">const</span> <span class="keywordtype">int</span> ind, stack_config_n ** cfg);
+<a name="l00095"></a>00095 
+<a name="l00096"></a>00096 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00097"></a>00097 new_get_names(<span class="keyword">const</span> <span class="keywordtype">char</span>* pcatg, <span class="keyword">const</span> <span class="keywordtype">int</span> ind, stack_config_n **  cfg){
+<a name="l00098"></a>00098 
+<a name="l00099"></a>00099   <span class="keywordflow">if</span> (strcmp(pcatg,PRO_FIBRE_NS_STACKED_OFF) == 0) {
+<a name="l00100"></a>00100      strcpy((*cfg)->outName,DISTORTION_STACK_OFF_OUT_FILENAME);
+<a name="l00101"></a>00101   }
+<a name="l00102"></a>00102   <span class="keywordflow">if</span> (strcmp(pcatg,PRO_FIBRE_NS_STACKED_ON)  == 0) {
+<a name="l00103"></a>00103      strcpy((*cfg)->outName,<span class="stringliteral">"out_ns_stack_on.fits"</span>);
+<a name="l00104"></a>00104   }
+<a name="l00105"></a>00105   <span class="keywordflow">if</span> (strcmp(pcatg,PRO_FIBRE_NS_STACKED)     == 0) {
+<a name="l00106"></a>00106      strcpy((*cfg)->outName,<span class="stringliteral">"out_ns_stack.fits"</span>);
+<a name="l00107"></a>00107   }
+<a name="l00108"></a>00108   <span class="keywordflow">if</span> (strcmp(pcatg,PRO_WAVE_LAMP_STACKED)    == 0) {
+<a name="l00109"></a>00109      strcpy((*cfg)->outName,<span class="stringliteral">"out_wcal_stack.fits"</span>);
+<a name="l00110"></a>00110   }
+<a name="l00111"></a>00111   <span class="keywordflow">if</span> (strcmp(pcatg,PRO_FIBRE_NS_STACKED_DIST)== 0) {
+<a name="l00112"></a>00112      strcpy((*cfg)->outName,<span class="stringliteral">"out_ns_stack_warp.fits"</span>);
+<a name="l00113"></a>00113   }
+<a name="l00114"></a>00114   <span class="keywordflow">if</span> (strcmp(pcatg,PRO_WAVE_SLITPOS_STACKED) == 0) {
+<a name="l00115"></a>00115      strcpy((*cfg)->outName,<span class="stringliteral">"out_slit_pos_stack.fits"</span>);
+<a name="l00116"></a>00116   }
+<a name="l00117"></a>00117 
+<a name="l00118"></a>00118   <span class="keywordflow">if</span> (strcmp(pcatg,PRO_PSF_CALIBRATOR_STACKED)== 0) {
+<a name="l00119"></a>00119      snprintf((*cfg)->outName,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%d%s"</span>,<span class="stringliteral">"out_stack"</span>,ind,<span class="stringliteral">".fits"</span>);
+<a name="l00120"></a>00120   }
+<a name="l00121"></a>00121   <span class="keywordflow">if</span> (strcmp(pcatg,PRO_SKY_PSF_CALIBRATOR_STACKED)== 0) {
+<a name="l00122"></a>00122      strcpy((*cfg)->outName,STACKED_OUT_FILENAME);
+<a name="l00123"></a>00123   }
+<a name="l00124"></a>00124   <span class="keywordflow">if</span> (strcmp(pcatg,PRO_STD_NODDING_STACKED) == 0) {
+<a name="l00125"></a>00125      snprintf((*cfg)->outName,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%d%s"</span>,<span class="stringliteral">"out_stack"</span>,ind,<span class="stringliteral">".fits"</span>);
+<a name="l00126"></a>00126   }
+<a name="l00127"></a>00127   <span class="comment">/* only 1 frame</span>
+<a name="l00128"></a>00128 <span class="comment">  if (strcmp(pcatg,PRO_STD_NODDING_STACKED) == 0) {</span>
+<a name="l00129"></a>00129 <span class="comment">    strcpy((*cfg)->outName,STACKED_OUT_FILENAME);</span>
+<a name="l00130"></a>00130 <span class="comment">  }</span>
+<a name="l00131"></a>00131 <span class="comment">  */</span>
+<a name="l00132"></a>00132 
+<a name="l00133"></a>00133   <span class="keywordflow">if</span> (strcmp(pcatg,PRO_SKY_NODDING_STACKED) == 0) {
+<a name="l00134"></a>00134     strcpy((*cfg)->outName,STACKED_OUT_FILENAME); <span class="comment">/*STD*/</span>
+<a name="l00135"></a>00135   }
+<a name="l00136"></a>00136   <span class="keywordflow">if</span> (strcmp(pcatg,PRO_OBJECT_NODDING_STACKED) == 0) {
+<a name="l00137"></a>00137     snprintf((*cfg)->outName,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%d%s"</span>,<span class="stringliteral">"out_stack"</span>,ind,<span class="stringliteral">".fits"</span>);
+<a name="l00138"></a>00138   }
+<a name="l00139"></a>00139   <span class="keywordflow">if</span> (strcmp(pcatg,PRO_PUPIL_LAMP_STACKED) == 0) {
+<a name="l00140"></a>00140     snprintf((*cfg)->outName,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%d%s"</span>,<span class="stringliteral">"out_stack"</span>,ind,<span class="stringliteral">".fits"</span>);
+<a name="l00141"></a>00141   }
+<a name="l00142"></a>00142   <span class="keywordflow">if</span> (strcmp(pcatg,PRO_STACKED) == 0) {
+<a name="l00143"></a>00143     snprintf((*cfg)->outName,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%d%s"</span>,<span class="stringliteral">"out_stack"</span>,ind,<span class="stringliteral">".fits"</span>);
+<a name="l00144"></a>00144   }
+<a name="l00145"></a>00145 
+<a name="l00146"></a>00146   snprintf((*cfg)->sky_name,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%d%s"</span>,<span class="stringliteral">"out_sky"</span>,ind,<span class="stringliteral">".fits"</span>);
+<a name="l00147"></a>00147 
+<a name="l00148"></a>00148   <span class="keywordflow">return</span> 0;
+<a name="l00149"></a>00149 
+<a name="l00150"></a>00150 }
+<a name="l00151"></a>00151 
+<a name="l00152"></a>00152 
+<a name="l00153"></a>00153 <span class="keywordtype">int</span> sinfo_new_prepare_stacked_frames (<span class="keyword">const</span> <span class="keywordtype">char</span>* plugin_id,
+<a name="l00154"></a>00154                                 cpl_parameterlist* config,
+<a name="l00155"></a>00155                                 cpl_frameset* sof,
+<a name="l00156"></a>00156                                 cpl_frameset* ref_set,
+<a name="l00157"></a>00157                                 <span class="keyword">const</span> <span class="keywordtype">char</span>* frm_pro_ctg,
+<a name="l00158"></a>00158                                 <span class="keyword">const</span> <span class="keywordtype">int</span> frm_ind,
+<a name="l00159"></a>00159                                 fake* fk)
+<a name="l00160"></a>00160 {
+<a name="l00161"></a>00161 
+<a name="l00162"></a>00162 
+<a name="l00163"></a>00163   stack_config_n * cfg =NULL;
+<a name="l00164"></a>00164   cpl_imagelist * list_object=NULL ;
+<a name="l00165"></a>00165   cpl_imagelist * list_dither_object=NULL;
+<a name="l00166"></a>00166   cpl_imagelist * list_dither_sky=NULL;
+<a name="l00167"></a>00167   cpl_imagelist * list_sky=NULL;
+<a name="l00168"></a>00168   cpl_imagelist * list_dark=NULL;
+<a name="l00169"></a>00169   new_Lookup* lookup=NULL;
+<a name="l00170"></a>00170   cpl_image * im3=NULL ;
+<a name="l00171"></a>00171   cpl_image * im4=NULL ;
+<a name="l00172"></a>00172   cpl_image * im5=NULL ;
+<a name="l00173"></a>00173   cpl_image * im6=NULL ;
+<a name="l00174"></a>00174   cpl_image * im7=NULL ;
+<a name="l00175"></a>00175   cpl_image * im8=NULL ;
+<a name="l00176"></a>00176   cpl_image * im9=NULL ;
+<a name="l00177"></a>00177 
+<a name="l00178"></a>00178   cpl_image * ref_im1=NULL ;
+<a name="l00179"></a>00179   cpl_image * ref_im2=NULL ;
+<a name="l00180"></a>00180   cpl_image ** im=NULL ;
+<a name="l00181"></a>00181   cpl_image * im_obj=NULL ;
+<a name="l00182"></a>00182   cpl_image* simg=NULL;
+<a name="l00183"></a>00183 
+<a name="l00184"></a>00184   cpl_image * im_dark=NULL ;
+<a name="l00185"></a>00185   cpl_image * im_sky=NULL ;
+<a name="l00186"></a>00186   cpl_image * im_dither=NULL ;
+<a name="l00187"></a>00187   cpl_image * im_dither_sky=NULL ;
+<a name="l00188"></a>00188   cpl_image * im_obj_sub=NULL ;
+<a name="l00189"></a>00189   cpl_image * im_obj_flat=NULL ;
+<a name="l00190"></a>00190   cpl_image * im_dither_sub=NULL ;
+<a name="l00191"></a>00191   cpl_image * im_dither_flat=NULL ;
+<a name="l00192"></a>00192   cpl_image * int_im_shifted=NULL ;
+<a name="l00193"></a>00193   cpl_image * int_im_dith_shifted=NULL ;
+<a name="l00194"></a>00194   cpl_image * im_conv=NULL ;
+<a name="l00195"></a>00195   <span class="keywordtype">int</span> sy=0;
+<a name="l00196"></a>00196 
+<a name="l00197"></a>00197   cpl_image * mask_im=NULL ;
+<a name="l00198"></a>00198   cpl_image * flat_smooth=NULL ;
+<a name="l00199"></a>00199   cpl_image * flat1=NULL ;
+<a name="l00200"></a>00200   cpl_image * flat2=NULL ;
+<a name="l00201"></a>00201   cpl_image * int_im=NULL ;
+<a name="l00202"></a>00202   cpl_image * int_im_dith=NULL ;
+<a name="l00203"></a>00203   cpl_image * sky_img_flat=NULL;
+<a name="l00204"></a>00204   cpl_image * sky_dist=NULL;
+<a name="l00205"></a>00205 
+<a name="l00206"></a>00206 
+<a name="l00207"></a>00207   cpl_imagelist * iCube=NULL ;
+<a name="l00208"></a>00208   cpl_imagelist * jCube=NULL ;
+<a name="l00209"></a>00209   cpl_image * X=NULL ;
+<a name="l00210"></a>00210   cpl_image * hX=NULL ;
+<a name="l00211"></a>00211   cpl_image * Y=NULL ;
+<a name="l00212"></a>00212   cpl_image * Z=NULL ;
+<a name="l00213"></a>00213   cpl_table * qclog_tbl=NULL;
+<a name="l00214"></a>00214   cpl_image* sky_img=NULL;
+<a name="l00215"></a>00215   cpl_image* mdark=NULL;
+<a name="l00216"></a>00216 
+<a name="l00217"></a>00217   <span class="keywordtype">char</span>* name=NULL;
+<a name="l00218"></a>00218   <span class="keywordtype">int</span> typ=0;
+<a name="l00219"></a>00219   <span class="keywordtype">int</span> pos=0;
+<a name="l00220"></a>00220   <span class="keywordtype">int</span> i = 0;
+<a name="l00221"></a>00221   <span class="keywordtype">int</span> n = 0;
+<a name="l00222"></a>00222   <span class="keywordtype">int</span> cnt = 0 ;
+<a name="l00223"></a>00223   <span class="keywordtype">float</span> val_x=0;
+<a name="l00224"></a>00224   <span class="keywordtype">float</span> val_y=0;
+<a name="l00225"></a>00225   <span class="keywordtype">int</span> status=0;
+<a name="l00226"></a>00226 
+<a name="l00227"></a>00227   <span class="keywordtype">float</span>** slit_edges=NULL;
+<a name="l00228"></a>00228   <span class="keywordtype">char</span>** in_nam=NULL;
+<a name="l00229"></a>00229 
+<a name="l00230"></a>00230   <span class="keywordtype">int</span> nob = 0;
+<a name="l00231"></a>00231   <span class="keywordtype">int</span> nsky = 0;
+<a name="l00232"></a>00232   <span class="keywordtype">int</span> nobjdith = 0;
+<a name="l00233"></a>00233   <span class="keywordtype">int</span> nskydith = 0;
+<a name="l00234"></a>00234   <span class="keywordtype">int</span> nda = 0;
+<a name="l00235"></a>00235   <span class="keywordtype">char</span> name_list[MAX_NAME_SIZE];
+<a name="l00236"></a>00236   <span class="keywordtype">char</span> fake_sky_name[MAX_NAME_SIZE];
+<a name="l00237"></a>00237   <span class="keywordtype">int</span> no=0;
+<a name="l00238"></a>00238   <span class="keywordtype">float</span> lo_cut=0;
+<a name="l00239"></a>00239   <span class="keywordtype">float</span> hi_cut=0;
+<a name="l00240"></a>00240 
+<a name="l00241"></a>00241   cpl_imagelist* list_object_tmp=NULL;
+<a name="l00242"></a>00242   cpl_imagelist* list_dither_object_tmp=NULL;
+<a name="l00243"></a>00243   cpl_imagelist* list_sky_tmp=NULL;
+<a name="l00244"></a>00244   cpl_imagelist* list_dither_sky_tmp=NULL;
+<a name="l00245"></a>00245 
+<a name="l00246"></a>00246   cpl_image* flat1_dist=NULL;
+<a name="l00247"></a>00247   cpl_image* flat2_dist=NULL;
+<a name="l00248"></a>00248 
+<a name="l00249"></a>00249   cpl_frameset* raw=NULL;
+<a name="l00250"></a>00250 
+<a name="l00251"></a>00251   <span class="keywordtype">char</span> file_name[MAX_NAME_SIZE];
+<a name="l00252"></a>00252   cpl_table* tbl_index = NULL;
+<a name="l00253"></a>00253   cpl_table* tbl_slitpos=NULL;
+<a name="l00254"></a>00254   <span class="keywordtype">int</span> rhead=0;
+<a name="l00255"></a>00255 
+<a name="l00256"></a>00256   cpl_frame*     sky_frame = NULL;
+<a name="l00257"></a>00257   <span class="keywordtype">char</span>* sky_name  = NULL;
+<a name="l00258"></a>00258   <span class="keywordtype">char</span>* sky_tag   = NULL;
+<a name="l00259"></a>00259   qc_wcal* qc=sinfo_qc_wcal_new();
+<a name="l00260"></a>00260 
+<a name="l00261"></a>00261   cpl_parameter* p=NULL;
+<a name="l00262"></a>00262   <span class="keywordtype">int</span> pdensity=0;
+<a name="l00263"></a>00263   <span class="keywordtype">int</span> mflat_norm_smooth=FALSE;
+<a name="l00264"></a>00264 
+<a name="l00265"></a>00265   <span class="keywordtype">int</span> smooth_rad=16;
+<a name="l00266"></a>00266   <span class="keywordtype">int</span> sub_raw_sky=1;
+<a name="l00267"></a>00267 
+<a name="l00268"></a>00268   <span class="comment">/*</span>
+<a name="l00269"></a>00269 <span class="comment">       -----------------------------------------------------------------</span>
+<a name="l00270"></a>00270 <span class="comment">       1) parse the file names and parameters to the psf_config data</span>
+<a name="l00271"></a>00271 <span class="comment">          structure cfg</span>
+<a name="l00272"></a>00272 <span class="comment">       -----------------------------------------------------------------</span>
+<a name="l00273"></a>00273 <span class="comment">  */</span>
+<a name="l00274"></a>00274 
+<a name="l00275"></a>00275 
+<a name="l00276"></a>00276   check_nomsg(p=cpl_parameterlist_find(config,<span class="stringliteral">"sinfoni.product.density"</span>));
+<a name="l00277"></a>00277   check_nomsg(pdensity=cpl_parameter_get_int(p));
+<a name="l00278"></a>00278 
+<a name="l00279"></a>00279 
+<a name="l00280"></a>00280 
+<a name="l00281"></a>00281   check_nomsg(p=cpl_parameterlist_find(config,
+<a name="l00282"></a>00282                        <span class="stringliteral">"sinfoni.stacked.mflat_norm_smooth"</span>));
+<a name="l00283"></a>00283   check_nomsg(mflat_norm_smooth=cpl_parameter_get_int(p));
+<a name="l00284"></a>00284 
+<a name="l00285"></a>00285 
+<a name="l00286"></a>00286 
+<a name="l00287"></a>00287   check_nomsg(p=cpl_parameterlist_find(config,
+<a name="l00288"></a>00288                        <span class="stringliteral">"sinfoni.stacked.mflat_smooth_rad"</span>));
+<a name="l00289"></a>00289   check_nomsg(smooth_rad=cpl_parameter_get_int(p));
+<a name="l00290"></a>00290 
+<a name="l00291"></a>00291   check_nomsg(p=cpl_parameterlist_find(config,<span class="stringliteral">"sinfoni.stacked.sub_raw_sky"</span>));
+<a name="l00292"></a>00292   check_nomsg(sub_raw_sky=cpl_parameter_get_bool(p));
+<a name="l00293"></a>00293 
+<a name="l00294"></a>00294 
+<a name="l00295"></a>00295   check_nomsg(raw=cpl_frameset_new());
+<a name="l00296"></a>00296   cknull(cfg = sinfo_parse_cpl_input_stack(config,sof,&raw, fk),
+<a name="l00297"></a>00297         <span class="stringliteral">"could not parse cpl input file!"</span>) ;
+<a name="l00298"></a>00298 
+<a name="l00299"></a>00299   ck0(sinfo_det_ncounts(raw, cfg->qc_thresh_max,qc),<span class="stringliteral">"computing det ncounts"</span>);
+<a name="l00300"></a>00300 
+<a name="l00301"></a>00301 
+<a name="l00302"></a>00302   <span class="keywordflow">if</span>(ref_set != NULL) {
+<a name="l00303"></a>00303     sinfo_free_frameset(&raw);
+<a name="l00304"></a>00304     raw=cpl_frameset_duplicate(ref_set);
+<a name="l00305"></a>00305   }
+<a name="l00306"></a>00306   <span class="comment">/* defines output file name for stack set i */</span>
+<a name="l00307"></a>00307   ck0_nomsg(new_get_names(frm_pro_ctg, frm_ind, &cfg));
+<a name="l00308"></a>00308 
+<a name="l00309"></a>00309   <span class="keywordflow">if</span> (cfg->flatInd == 1){
+<a name="l00310"></a>00310     <span class="keywordflow">if</span>(sinfo_is_fits_file(cfg->flatfield1) != 1) {
+<a name="l00311"></a>00311        <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Input FF file %s is not FITS"</span>,cfg->flatfield1);
+<a name="l00312"></a>00312        <span class="keywordflow">goto</span> cleanup;
+<a name="l00313"></a>00313     }
+<a name="l00314"></a>00314 
+<a name="l00315"></a>00315   }
+<a name="l00316"></a>00316   <span class="keywordflow">if</span> (cfg->maskInd == 1) {
+<a name="l00317"></a>00317     <span class="keywordflow">if</span>(sinfo_is_fits_file(cfg->mask) != 1) {
+<a name="l00318"></a>00318          <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Input mask file %s is not FITS"</span>,cfg->mask);
+<a name="l00319"></a>00319          <span class="keywordflow">goto</span> cleanup;
+<a name="l00320"></a>00320     }
+<a name="l00321"></a>00321     <span class="keywordflow">if</span>(cfg -> indind == 0) {
+<a name="l00322"></a>00322       <span class="keywordflow">if</span>(sinfo_is_fits_file(cfg->slitposList) != 1) {
+<a name="l00323"></a>00323     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Input slitpos file %s is not FITS"</span>,cfg->slitposList);
+<a name="l00324"></a>00324     <span class="keywordflow">goto</span> cleanup;
+<a name="l00325"></a>00325       }
+<a name="l00326"></a>00326     }
+<a name="l00327"></a>00327   }
+<a name="l00328"></a>00328 
+<a name="l00329"></a>00329   <span class="comment">/*</span>
+<a name="l00330"></a>00330 <span class="comment">   #---------------------------------------------------------</span>
+<a name="l00331"></a>00331 <span class="comment">   # Take a clean mean of several images</span>
+<a name="l00332"></a>00332 <span class="comment">   # input is 1 or more similar images</span>
+<a name="l00333"></a>00333 <span class="comment">   #---------------------------------------------------------</span>
+<a name="l00334"></a>00334 <span class="comment">  */</span>
+<a name="l00335"></a>00335 
+<a name="l00336"></a>00336   <span class="keywordflow">if</span> (cfg->sfInd == 1){
+<a name="l00337"></a>00337     <span class="keywordflow">if</span> (cfg->contains_dark == 0) {
+<a name="l00338"></a>00338       <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"no sinfo_dark frames given!"</span>);
+<a name="l00339"></a>00339     }
+<a name="l00340"></a>00340     <span class="keywordflow">if</span> (cfg->contains_ref == 0) {
+<a name="l00341"></a>00341       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no reference frames given!"</span>);
+<a name="l00342"></a>00342       <span class="keywordflow">goto</span> cleanup;
+<a name="l00343"></a>00343     }
+<a name="l00344"></a>00344   }
+<a name="l00345"></a>00345 
+<a name="l00346"></a>00346   <span class="comment">/* allocate memory for lists of object, sky and dithered frames */</span>
+<a name="l00347"></a>00347   check(list_object=cpl_imagelist_new(),
+<a name="l00348"></a>00348         <span class="stringliteral">"could not allocate memory for object frame"</span>);
+<a name="l00349"></a>00349 
+<a name="l00350"></a>00350   <span class="keywordflow">if</span> (cfg->contains_dither == 1) {
+<a name="l00351"></a>00351     check(list_dither_object=cpl_imagelist_new(),
+<a name="l00352"></a>00352           <span class="stringliteral">"could not allocate memory for dither object frame"</span>);
+<a name="l00353"></a>00353   }
+<a name="l00354"></a>00354 
+<a name="l00355"></a>00355   <span class="keywordflow">if</span> (cfg->contains_sky == 1) {
+<a name="l00356"></a>00356     check(list_sky = cpl_imagelist_new(),
+<a name="l00357"></a>00357        <span class="stringliteral">"could not allocate memory for off frame list"</span>);
+<a name="l00358"></a>00358   }
+<a name="l00359"></a>00359 
+<a name="l00360"></a>00360   <span class="keywordflow">if</span> (cfg->contains_dither == 1 && cfg->nditheroff > 0) {
+<a name="l00361"></a>00361      check(list_dither_sky = cpl_imagelist_new(),
+<a name="l00362"></a>00362        <span class="stringliteral">"could not allocate memory for dither frame list"</span>);
+<a name="l00363"></a>00363   }
+<a name="l00364"></a>00364 
+<a name="l00365"></a>00365   <span class="keywordflow">if</span> (cfg->contains_dark == 1 && cfg->sfInd == 1) {
+<a name="l00366"></a>00366      check(list_dark = cpl_imagelist_new(),
+<a name="l00367"></a>00367        <span class="stringliteral">"could not allocate memory for sinfo_dark frame"</span>);
+<a name="l00368"></a>00368   }
+<a name="l00369"></a>00369 
+<a name="l00370"></a>00370   <span class="keywordflow">if</span> (cfg->contains_dither == 0 && cfg->nditheroff > 0) {
+<a name="l00371"></a>00371      <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"please use non-dithered off-frames, remove the 2!"</span>);
+<a name="l00372"></a>00372      <span class="keywordflow">goto</span> cleanup;
+<a name="l00373"></a>00373   }
+<a name="l00374"></a>00374 
+<a name="l00375"></a>00375   <span class="comment">/* build different image lists for the different cases */</span>
+<a name="l00376"></a>00376   cknull_nomsg(im=(cpl_image**)cpl_calloc(cfg -> nframes, <span class="keyword">sizeof</span>(cpl_image*)));
+<a name="l00377"></a>00377 
+<a name="l00378"></a>00378   <span class="keywordflow">for</span> (i=0; i< cfg->nframes; i++) {
+<a name="l00379"></a>00379      name = cfg->framelist[i];
+<a name="l00380"></a>00380      <span class="keywordflow">if</span>(sinfo_is_fits_file(name) != 1) {
+<a name="l00381"></a>00381        <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Input file %s is not FITS"</span>,name);
+<a name="l00382"></a>00382        <span class="keywordflow">goto</span> cleanup;
+<a name="l00383"></a>00383      }
+<a name="l00384"></a>00384      check_nomsg(im[i] = cpl_image_load( name,CPL_TYPE_FLOAT,0,0));
+<a name="l00385"></a>00385   }
+<a name="l00386"></a>00386 
+<a name="l00387"></a>00387   <span class="comment">/* up to here leak free */</span>
+<a name="l00388"></a>00388   rhead=0;
+<a name="l00389"></a>00389   <span class="keywordflow">for</span> (i=0; i< cfg->nframes; i++) {
+<a name="l00390"></a>00390     typ = sinfo_new_intarray_get_value( cfg->frametype, i );
+<a name="l00391"></a>00391     pos = sinfo_new_intarray_get_value( cfg->frameposition, i );
+<a name="l00392"></a>00392     cknull(im[i],<span class="stringliteral">"could not load image"</span>);
+<a name="l00393"></a>00393 
+<a name="l00394"></a>00394     <span class="keywordflow">if</span> (pos == 2) {
+<a name="l00395"></a>00395       <span class="keywordflow">if</span> (typ == 1) {
+<a name="l00396"></a>00396         check_nomsg(cpl_imagelist_set(list_object,
+<a name="l00397"></a>00397                                       cpl_image_duplicate(im[i]),nob));
+<a name="l00398"></a>00398         nob = nob + 1;
+<a name="l00399"></a>00399       }
+<a name="l00400"></a>00400       <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( typ == 0 ) {
+<a name="l00401"></a>00401         check_nomsg(cpl_imagelist_set(list_sky,
+<a name="l00402"></a>00402                     cpl_image_duplicate(im[i]),nsky));
+<a name="l00403"></a>00403         nsky = nsky + 1;
+<a name="l00404"></a>00404     <span class="keywordflow">if</span>(pdensity > 0) {
+<a name="l00405"></a>00405       <span class="keywordflow">if</span>(fk->is_fake_sky==1) {
+<a name="l00406"></a>00406         snprintf(fake_sky_name,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%d%s"</span>,<span class="stringliteral">"out_fake_sky"</span>,
+<a name="l00407"></a>00407              frm_ind,<span class="stringliteral">".fits"</span>);
+<a name="l00408"></a>00408         check_nomsg(sky_img=cpl_image_load(fake_sky_name,CPL_TYPE_FLOAT,0,0));
+<a name="l00409"></a>00409         ck0(sinfo_pro_save_ima(sky_img,raw,sof,fake_sky_name,
+<a name="l00410"></a>00410                    PRO_SKY_DUMMY,NULL,
+<a name="l00411"></a>00411                    plugin_id,config),
+<a name="l00412"></a>00412         <span class="stringliteral">"cannot save sky ima %s"</span>, fake_sky_name);
+<a name="l00413"></a>00413 
+<a name="l00414"></a>00414         sinfo_free_image(&sky_img);
+<a name="l00415"></a>00415       }
+<a name="l00416"></a>00416     }
+<a name="l00417"></a>00417 
+<a name="l00418"></a>00418 
+<a name="l00419"></a>00419         <span class="keywordflow">if</span>((pdensity == 3) || (pdensity == 1) ||
+<a name="l00420"></a>00420            (pdensity == 2 && frm_ind == 0)) {
+<a name="l00421"></a>00421       check_nomsg(sky_frame = cpl_frameset_get_frame(raw,i));
+<a name="l00422"></a>00422       check_nomsg(sky_name  = (<span class="keywordtype">char</span>*) cpl_frame_get_filename(sky_frame));
+<a name="l00423"></a>00423       check_nomsg(sky_tag   = (<span class="keywordtype">char</span>*) cpl_frame_get_tag(sky_frame));
+<a name="l00424"></a>00424 
+<a name="l00425"></a>00425           <span class="keywordflow">if</span> ( (strstr(frm_pro_ctg,<span class="stringliteral">"OBJECT"</span>) != NULL) ||
+<a name="l00426"></a>00426                (strstr(frm_pro_ctg,<span class="stringliteral">"PSF"</span>) != NULL) ||
+<a name="l00427"></a>00427                (strstr(frm_pro_ctg,<span class="stringliteral">"STD"</span>) != NULL) ) {
+<a name="l00428"></a>00428         check_nomsg(sky_img = cpl_image_load(sky_name,CPL_TYPE_FLOAT,0,0));
+<a name="l00429"></a>00429         snprintf(sky_name,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%2.2d%s"</span>,<span class="stringliteral">"out_sky"</span>,
+<a name="l00430"></a>00430              frm_ind,<span class="stringliteral">".fits"</span>);
+<a name="l00431"></a>00431         ck0(sinfo_pro_save_ima(sky_img,raw,sof,sky_name,
+<a name="l00432"></a>00432                    PRO_SKY_STACKED_DUMMY,NULL,
+<a name="l00433"></a>00433                                    plugin_id,config),
+<a name="l00434"></a>00434         <span class="stringliteral">"cannot save sky ima %s"</span>, sky_name);
+<a name="l00435"></a>00435 
+<a name="l00436"></a>00436         sinfo_free_image(&sky_img);
+<a name="l00437"></a>00437         <span class="keywordflow">if</span> (cfg->flatInd == 1) {
+<a name="l00438"></a>00438           sinfo_msg(<span class="stringliteral">"Sky Flatfielding"</span>);
+<a name="l00439"></a>00439           check(flat1=cpl_image_load(cfg->flatfield1,CPL_TYPE_FLOAT,0,0 ),
+<a name="l00440"></a>00440             <span class="stringliteral">"could not load flatfield image"</span> );
+<a name="l00441"></a>00441 
+<a name="l00442"></a>00442               <span class="keywordflow">if</span>(mflat_norm_smooth != 0) {
+<a name="l00443"></a>00443 
+<a name="l00444"></a>00444                 <span class="keywordflow">if</span>(mflat_norm_smooth == 1) {
+<a name="l00445"></a>00445 
+<a name="l00446"></a>00446                    sy=cpl_image_get_size_y(flat1);
+<a name="l00447"></a>00447 
+<a name="l00448"></a>00448                    cknull(flat_smooth=sinfo_image_smooth_fft(flat1,sy/smooth_rad),
+<a name="l00449"></a>00449                <span class="stringliteral">"could not smooth flatfield"</span> );
+<a name="l00450"></a>00450                 } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(mflat_norm_smooth == 2) {
+<a name="l00451"></a>00451                    cknull(flat_smooth = sinfo_image_smooth_median_y(flat1,
+<a name="l00452"></a>00452                                                                     smooth_rad),
+<a name="l00453"></a>00453                           <span class="stringliteral">"could not smooth flatfield"</span> );
+<a name="l00454"></a>00454                  }
+<a name="l00455"></a>00455 
+<a name="l00456"></a>00456             check_nomsg(cpl_image_divide(flat1,flat_smooth));
+<a name="l00457"></a>00457             sinfo_free_image(&flat_smooth);
+<a name="l00458"></a>00458 
+<a name="l00459"></a>00459           }
+<a name="l00460"></a>00460 
+<a name="l00461"></a>00461           check_nomsg(simg = cpl_image_load(sky_name,CPL_TYPE_FLOAT,0,0 ));
+<a name="l00462"></a>00462 
+<a name="l00463"></a>00463           cknull(sky_img_flat=sinfo_new_div_images_robust(simg,flat1),
+<a name="l00464"></a>00464              <span class="stringliteral">"could not carry out flatfield division"</span> );
+<a name="l00465"></a>00465           sinfo_free_image(&simg);
+<a name="l00466"></a>00466           sinfo_free_image(&flat1);
+<a name="l00467"></a>00467 
+<a name="l00468"></a>00468           <span class="comment">/* if (frm_ind == 0) { */</span>
+<a name="l00469"></a>00469           <span class="keywordflow">if</span> (cfg->warpfixInd == 1){
+<a name="l00470"></a>00470         sinfo_msg(<span class="stringliteral">"Correct sky for distortions"</span>);
+<a name="l00471"></a>00471                 snprintf(file_name,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%d%s"</span>,
+<a name="l00472"></a>00472                          STACK_SKY_DIST_OUT_FILENAME,frm_ind,<span class="stringliteral">".fits"</span>);
+<a name="l00473"></a>00473         sky_dist = sinfo_new_image_warp_fits(sky_img_flat,
+<a name="l00474"></a>00474                              cfg->kernel,
+<a name="l00475"></a>00475                              cfg->polyFile);
+<a name="l00476"></a>00476 
+<a name="l00477"></a>00477         ck0(sinfo_pro_save_ima(sky_dist,raw,sof,
+<a name="l00478"></a>00478                        file_name,
+<a name="l00479"></a>00479                        PRO_STACK_SKY_DIST,NULL,plugin_id,
+<a name="l00480"></a>00480                        config),<span class="stringliteral">"cannot save ima %s"</span>,
+<a name="l00481"></a>00481             STACK_SKY_DIST_OUT_FILENAME);
+<a name="l00482"></a>00482 
+<a name="l00483"></a>00483         sinfo_free_image(&sky_dist);
+<a name="l00484"></a>00484           }
+<a name="l00485"></a>00485           <span class="comment">/* } */</span>
+<a name="l00486"></a>00486           sinfo_free_image(&sky_img_flat);
+<a name="l00487"></a>00487         } <span class="comment">/* end check on flatind */</span>
+<a name="l00488"></a>00488       } <span class="comment">/* end check on procatg */</span>
+<a name="l00489"></a>00489     }
+<a name="l00490"></a>00490       } <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( typ == 5 ) {
+<a name="l00491"></a>00491     <span class="keywordflow">if</span> (cfg->sfInd == 1) {
+<a name="l00492"></a>00492       check_nomsg(cpl_imagelist_set(list_dark,
+<a name="l00493"></a>00493                       cpl_image_duplicate(im[i]),nda));
+<a name="l00494"></a>00494       nda = nda + 1;
+<a name="l00495"></a>00495     } <span class="keywordflow">else</span> {
+<a name="l00496"></a>00496       sinfo_free_image(&(im[i]));
+<a name="l00497"></a>00497     }
+<a name="l00498"></a>00498       } <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( typ == 4 ) {
+<a name="l00499"></a>00499     <span class="keywordflow">if</span> ( cfg->sfInd == 1) {
+<a name="l00500"></a>00500       ref_im1 = im[i];
+<a name="l00501"></a>00501     } <span class="keywordflow">else</span> {
+<a name="l00502"></a>00502       sinfo_free_image(&(im[i]));
+<a name="l00503"></a>00503     }
+<a name="l00504"></a>00504       }
+<a name="l00505"></a>00505     } <span class="keywordflow">else</span> {
+<a name="l00506"></a>00506       <span class="keywordflow">if</span> (typ == 1) {
+<a name="l00507"></a>00507        check_nomsg(cpl_imagelist_set(list_dither_object,
+<a name="l00508"></a>00508                                      cpl_image_duplicate(im[i]),nobjdith));
+<a name="l00509"></a>00509        nobjdith = nobjdith + 1;
+<a name="l00510"></a>00510       } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (typ == 0) {
+<a name="l00511"></a>00511     check_nomsg(cpl_imagelist_set(list_dither_object,
+<a name="l00512"></a>00512                                      cpl_image_duplicate(im[i]),nskydith));
+<a name="l00513"></a>00513     nskydith = nskydith + 1;
+<a name="l00514"></a>00514       } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (typ == 4) {
+<a name="l00515"></a>00515     <span class="keywordflow">if</span> (cfg->sfInd == 1) {
+<a name="l00516"></a>00516       ref_im2 = cpl_image_duplicate(im[i]);
+<a name="l00517"></a>00517     } <span class="keywordflow">else</span> {
+<a name="l00518"></a>00518       sinfo_free_image(&(im[i]));
+<a name="l00519"></a>00519     }
+<a name="l00520"></a>00520       }
+<a name="l00521"></a>00521     }
+<a name="l00522"></a>00522   } <span class="comment">/* end for loop on i */</span>
+<a name="l00523"></a>00523 
+<a name="l00524"></a>00524   <span class="keywordflow">if</span> (nob != cfg->nobj ||
+<a name="l00525"></a>00525       cfg->noff != nsky ||
+<a name="l00526"></a>00526       nobjdith != cfg->nditherobj ||
+<a name="l00527"></a>00527       nskydith != cfg->nditheroff) {
+<a name="l00528"></a>00528     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"something is wrong with the number of the"</span>);
+<a name="l00529"></a>00529     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"different types of frames"</span>);
+<a name="l00530"></a>00530     <span class="comment">/* free memory */</span>
+<a name="l00531"></a>00531     <span class="keywordflow">goto</span> cleanup;
+<a name="l00532"></a>00532 
+<a name="l00533"></a>00533   }
+<a name="l00534"></a>00534 
+<a name="l00535"></a>00535   <span class="keywordflow">if</span> (cfg->sfInd == 1 && nda != cfg->ndark) {
+<a name="l00536"></a>00536     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"something is wrong with the number of sinfo_dark frames"</span>);
+<a name="l00537"></a>00537     <span class="keywordflow">goto</span> cleanup;
+<a name="l00538"></a>00538   }
+<a name="l00539"></a>00539   sinfo_msg(<span class="stringliteral">"Create and fill cubes with the different images"</span>);
+<a name="l00540"></a>00540 
+<a name="l00541"></a>00541   <span class="comment">/* create and fill cubes with the different image lists */</span>
+<a name="l00542"></a>00542   cknull(list_object,<span class="stringliteral">"could not create object data cube!"</span>);
+<a name="l00543"></a>00543 
+<a name="l00544"></a>00544   <span class="comment">/* shift the images in the cubes-if indicated-in spectral direction</span>
+<a name="l00545"></a>00545 <span class="comment">     with respect to the reference image</span>
+<a name="l00546"></a>00546 <span class="comment">  */</span>
+<a name="l00547"></a>00547   <span class="keywordflow">if</span> (cfg->sfInd == 1) {
+<a name="l00548"></a>00548 
+<a name="l00549"></a>00549   <span class="comment">/*</span>
+<a name="l00550"></a>00550 <span class="comment">      first take the mean of the sinfo_dark frames and subtract the result</span>
+<a name="l00551"></a>00551 <span class="comment">      from all cubes</span>
+<a name="l00552"></a>00552 <span class="comment">  */</span>
+<a name="l00553"></a>00553   sinfo_msg(<span class="stringliteral">"Shift cube images in spectral direction with "</span>
+<a name="l00554"></a>00554             <span class="stringliteral">"respect to reference"</span>);
+<a name="l00555"></a>00555 
+<a name="l00556"></a>00556   <span class="keywordflow">if</span> (cfg->contains_dark == 1) {
+<a name="l00557"></a>00557     sinfo_msg(<span class="stringliteral">"cfg->contains_dark == 1"</span>);
+<a name="l00558"></a>00558     <span class="keywordflow">if</span> (cfg->loReject*cfg->ndark < 1. && cfg->hiReject * cfg->ndark < 1.) {
+<a name="l00559"></a>00559       <span class="comment">/*</span>
+<a name="l00560"></a>00560 <span class="comment">          im_dark = sinfo_new_average_cube_to_image( list_dark );</span>
+<a name="l00561"></a>00561 <span class="comment">      */</span>
+<a name="l00562"></a>00562       check(im_dark = cpl_imagelist_collapse_create( list_dark ),
+<a name="l00563"></a>00563      <span class="stringliteral">"sinfo_averageCubeToImage failed"</span> );
+<a name="l00564"></a>00564      }
+<a name="l00565"></a>00565      <span class="keywordflow">else</span> {
+<a name="l00566"></a>00566 
+<a name="l00567"></a>00567        check_nomsg(no=cpl_imagelist_get_size(list_dark));
+<a name="l00568"></a>00568        lo_cut=(floor)( cfg->loReject*no+0.5);
+<a name="l00569"></a>00569        hi_cut=(floor)( cfg->hiReject*no+0.5);
+<a name="l00570"></a>00570        check(im_dark=cpl_imagelist_collapse_minmax_create(list_dark,lo_cut,
+<a name="l00571"></a>00571                                                           hi_cut),
+<a name="l00572"></a>00572                                      <span class="stringliteral">"sinfo_average_with_rejection failed"</span> );
+<a name="l00573"></a>00573 
+<a name="l00574"></a>00574      }
+<a name="l00575"></a>00575      sinfo_free_imagelist(&list_dark);
+<a name="l00576"></a>00576      check_nomsg(list_object_tmp = cpl_imagelist_duplicate (list_object));
+<a name="l00577"></a>00577      check(cpl_imagelist_subtract_image (list_object_tmp, im_dark),
+<a name="l00578"></a>00578             <span class="stringliteral">"cpl_imagelist_subtract_image failed"</span> );
+<a name="l00579"></a>00579      <span class="comment">/*</span>
+<a name="l00580"></a>00580 <span class="comment">       cube_object_tmp = sinfo_subImageFromCube (cube_object, im_dark);</span>
+<a name="l00581"></a>00581 <span class="comment">     */</span>
+<a name="l00582"></a>00582   } <span class="keywordflow">else</span> {
+<a name="l00583"></a>00583      sinfo_msg(<span class="stringliteral">"cfg->contains_dark == 0"</span>);
+<a name="l00584"></a>00584      check_nomsg(list_object_tmp = cpl_imagelist_duplicate(list_object));
+<a name="l00585"></a>00585   }
+<a name="l00586"></a>00586   sinfo_free_imagelist(&list_object);
+<a name="l00587"></a>00587 
+<a name="l00588"></a>00588   cknull(list_object = sinfo_align_cube_to_reference (list_object_tmp,
+<a name="l00589"></a>00589                               ref_im1,
+<a name="l00590"></a>00590                               cfg->sfOrder,
+<a name="l00591"></a>00591                               cfg->sfType),
+<a name="l00592"></a>00592      <span class="stringliteral">"sinfo_align_cube_to_reference failed"</span> );
+<a name="l00593"></a>00593 
+<a name="l00594"></a>00594   sinfo_free_imagelist(&list_object_tmp);
+<a name="l00595"></a>00595   <span class="keywordflow">if</span> (cfg->contains_dither == 1) {
+<a name="l00596"></a>00596     <span class="keywordflow">if</span> (cfg->contains_dark == 1) {
+<a name="l00597"></a>00597        check_nomsg(list_dither_object_tmp =
+<a name="l00598"></a>00598                    cpl_imagelist_duplicate(list_dither_object));
+<a name="l00599"></a>00599        check(cpl_imagelist_subtract_image(list_dither_object_tmp,im_dark),
+<a name="l00600"></a>00600              <span class="stringliteral">"sinfo_average_with_rejection failed"</span> );
+<a name="l00601"></a>00601 
+<a name="l00602"></a>00602        <span class="comment">/*</span>
+<a name="l00603"></a>00603 <span class="comment">        list_dither_object_tmp =</span>
+<a name="l00604"></a>00604 <span class="comment">              sinfo_new_sub_image_from_cube(list_dither_object,</span>
+<a name="l00605"></a>00605 <span class="comment">                                                    im_dark);</span>
+<a name="l00606"></a>00606 <span class="comment">    */</span>
+<a name="l00607"></a>00607 
+<a name="l00608"></a>00608     } <span class="keywordflow">else</span> {
+<a name="l00609"></a>00609        check_nomsg(list_dither_object_tmp=
+<a name="l00610"></a>00610                    cpl_imagelist_duplicate(list_dither_object));
+<a name="l00611"></a>00611     }
+<a name="l00612"></a>00612     sinfo_free_imagelist(&list_dither_object);
+<a name="l00613"></a>00613 
+<a name="l00614"></a>00614     cknull(list_dither_object=
+<a name="l00615"></a>00615             sinfo_align_cube_to_reference (list_dither_object_tmp,
+<a name="l00616"></a>00616                                  ref_im2,
+<a name="l00617"></a>00617                                  cfg->sfOrder,
+<a name="l00618"></a>00618                                  cfg->sfType),
+<a name="l00619"></a>00619        <span class="stringliteral">"sinfo_align_cube_to_reference failed"</span> );
+<a name="l00620"></a>00620 
+<a name="l00621"></a>00621     sinfo_free_imagelist(&list_dither_object_tmp);
+<a name="l00622"></a>00622   }
+<a name="l00623"></a>00623   <span class="keywordflow">if</span> (cfg->contains_sky == 1) {
+<a name="l00624"></a>00624     <span class="keywordflow">if</span> (cfg->contains_dark == 1) {
+<a name="l00625"></a>00625        check_nomsg(list_sky_tmp = cpl_imagelist_duplicate(list_sky));
+<a name="l00626"></a>00626        check(cpl_imagelist_subtract_image (list_sky_tmp, im_dark),
+<a name="l00627"></a>00627          <span class="stringliteral">"sinfo_average_with_rejection failed"</span> );
+<a name="l00628"></a>00628        <span class="comment">/*</span>
+<a name="l00629"></a>00629 <span class="comment">      cube_sky_tmp = sinfo_subImageFromCube (cube_sky, im_dark);</span>
+<a name="l00630"></a>00630 <span class="comment">       */</span>
+<a name="l00631"></a>00631 
+<a name="l00632"></a>00632     } <span class="keywordflow">else</span> {
+<a name="l00633"></a>00633        check_nomsg(list_sky_tmp = cpl_imagelist_duplicate(list_sky));
+<a name="l00634"></a>00634     }
+<a name="l00635"></a>00635     check_nomsg(list_sky_tmp=cpl_imagelist_duplicate(list_sky));
+<a name="l00636"></a>00636 
+<a name="l00637"></a>00637     check(list_sky = sinfo_align_cube_to_reference (list_sky_tmp,
+<a name="l00638"></a>00638                             ref_im1,
+<a name="l00639"></a>00639                             cfg->sfOrder,
+<a name="l00640"></a>00640                             cfg->sfType),
+<a name="l00641"></a>00641       <span class="stringliteral">"sinfo_alignCubeToReference failed"</span> );
+<a name="l00642"></a>00642 
+<a name="l00643"></a>00643     check_nomsg(cpl_imagelist_delete(list_sky_tmp));
+<a name="l00644"></a>00644   }
+<a name="l00645"></a>00645   <span class="keywordflow">if</span> (cfg->contains_dither == 1 && cfg->contains_sky == 1) {
+<a name="l00646"></a>00646     <span class="keywordflow">if</span> (cfg->contains_dark == 1) {
+<a name="l00647"></a>00647       check_nomsg(list_dither_sky_tmp=cpl_imagelist_duplicate(list_dither_sky));
+<a name="l00648"></a>00648       check(cpl_imagelist_subtract_image(list_dither_sky_tmp,im_dark),
+<a name="l00649"></a>00649         <span class="stringliteral">"sinfo_average_with_rejection failed"</span> );
+<a name="l00650"></a>00650        <span class="comment">/*</span>
+<a name="l00651"></a>00651 <span class="comment">       cube_dither_sky_tmp = sinfo_subImageFromCube (cube_dither_sky, im_dark);</span>
+<a name="l00652"></a>00652 <span class="comment">       */</span>
+<a name="l00653"></a>00653 
+<a name="l00654"></a>00654     } <span class="keywordflow">else</span> {
+<a name="l00655"></a>00655       check_nomsg(list_dither_sky_tmp=cpl_imagelist_duplicate(list_dither_sky));
+<a name="l00656"></a>00656     }
+<a name="l00657"></a>00657     sinfo_free_imagelist(&list_dither_sky);
+<a name="l00658"></a>00658 
+<a name="l00659"></a>00659     check(list_dither_sky=sinfo_align_cube_to_reference(list_dither_sky_tmp,
+<a name="l00660"></a>00660                                 ref_im2,
+<a name="l00661"></a>00661                                 cfg->sfOrder,
+<a name="l00662"></a>00662                                 cfg->sfType),
+<a name="l00663"></a>00663       <span class="stringliteral">"sinfo_alignCubeToReference failed"</span> );
+<a name="l00664"></a>00664 
+<a name="l00665"></a>00665     sinfo_free_imagelist(&list_dither_sky_tmp);
+<a name="l00666"></a>00666   }
+<a name="l00667"></a>00667   sinfo_free_image(&ref_im1);
+<a name="l00668"></a>00668   <span class="keywordflow">if</span> (cfg->contains_dither == 1) {
+<a name="l00669"></a>00669     sinfo_free_image(&ref_im2);
+<a name="l00670"></a>00670   }
+<a name="l00671"></a>00671   <span class="keywordflow">if</span> (cfg->contains_dark == 1) {
+<a name="l00672"></a>00672     sinfo_free_image(&im_dark);
+<a name="l00673"></a>00673   }
+<a name="l00674"></a>00674 
+<a name="l00675"></a>00675   } <span class="comment">/* end if over sfInd */</span>
+<a name="l00676"></a>00676 
+<a name="l00677"></a>00677   <span class="comment">/* subtracts the master dark from different frames if present */</span>
+<a name="l00678"></a>00678   <span class="keywordflow">if</span>(cfg->mdark_ind==1){
+<a name="l00679"></a>00679     sinfo_msg(<span class="stringliteral">"Subtract master dark %s "</span>,cfg->mdark);
+<a name="l00680"></a>00680 
+<a name="l00681"></a>00681     check_nomsg(mdark=cpl_image_load(cfg->mdark,CPL_TYPE_FLOAT,0,0));
+<a name="l00682"></a>00682     <span class="keywordflow">if</span> (list_object !=NULL) {
+<a name="l00683"></a>00683       cpl_imagelist_subtract_image (list_object, mdark);
+<a name="l00684"></a>00684     }
+<a name="l00685"></a>00685     <span class="keywordflow">if</span> (list_sky !=NULL) {
+<a name="l00686"></a>00686       cpl_imagelist_subtract_image (list_sky, mdark);
+<a name="l00687"></a>00687     }
+<a name="l00688"></a>00688     sinfo_free_image(&mdark);
+<a name="l00689"></a>00689   }
+<a name="l00690"></a>00690   <span class="comment">/* take the average with rejection of the different cubes */</span>
+<a name="l00691"></a>00691   sinfo_msg(<span class="stringliteral">"Take the average of the different cubes"</span>);
+<a name="l00692"></a>00692 
+<a name="l00693"></a>00693   <span class="keywordflow">if</span> (cfg->loReject*cfg->nobj < 1. && cfg->hiReject * cfg->nobj < 1.) {
+<a name="l00694"></a>00694     check(im_obj = cpl_imagelist_collapse_create(list_object),
+<a name="l00695"></a>00695       <span class="stringliteral">"Average with rejection failed"</span> );
+<a name="l00696"></a>00696   } <span class="keywordflow">else</span> {
+<a name="l00697"></a>00697 
+<a name="l00698"></a>00698     check_nomsg(no=cpl_imagelist_get_size(list_object));
+<a name="l00699"></a>00699     lo_cut=(floor)( cfg->loReject*no+0.5);
+<a name="l00700"></a>00700     hi_cut=(floor)( cfg->hiReject*no+0.5);
+<a name="l00701"></a>00701     check(im_obj=cpl_imagelist_collapse_minmax_create(list_object,
+<a name="l00702"></a>00702                  lo_cut,hi_cut),<span class="stringliteral">"Average with rejection failed"</span> );
+<a name="l00703"></a>00703 
+<a name="l00704"></a>00704   }
+<a name="l00705"></a>00705   sinfo_free_imagelist(&list_object);
+<a name="l00706"></a>00706 
+<a name="l00707"></a>00707   <span class="keywordflow">if</span> (cfg->contains_sky == 1) {
+<a name="l00708"></a>00708     <span class="keywordflow">if</span> (cfg->loReject*nsky < 1. && cfg->hiReject*nsky < 1.) {
+<a name="l00709"></a>00709       <span class="comment">/* here might explode in dither mode */</span>
+<a name="l00710"></a>00710       cknull(im_sky = cpl_imagelist_collapse_create( list_sky ),
+<a name="l00711"></a>00711          <span class="stringliteral">"Average with rejection failed"</span>);
+<a name="l00712"></a>00712     } <span class="keywordflow">else</span> {
+<a name="l00713"></a>00713 
+<a name="l00714"></a>00714       check_nomsg(no=cpl_imagelist_get_size(list_sky));
+<a name="l00715"></a>00715       lo_cut=(floor)( cfg->loReject*no+0.5);
+<a name="l00716"></a>00716       hi_cut=(floor)( cfg->hiReject*no+0.5);
+<a name="l00717"></a>00717       check(im_sky=cpl_imagelist_collapse_minmax_create(list_sky,lo_cut,hi_cut),
+<a name="l00718"></a>00718          <span class="stringliteral">"Average with rejection failed"</span>);
+<a name="l00719"></a>00719     }
+<a name="l00720"></a>00720     sinfo_free_imagelist(&list_sky);
+<a name="l00721"></a>00721   }
+<a name="l00722"></a>00722 
+<a name="l00723"></a>00723   <span class="keywordflow">if</span> (cfg->contains_dither == 1) {
+<a name="l00724"></a>00724     <span class="keywordflow">if</span> (cfg->loReject*nobjdith < 1. && cfg->hiReject*nobjdith < 1.) {
+<a name="l00725"></a>00725       check(im_dither = cpl_imagelist_collapse_create( list_dither_object ),
+<a name="l00726"></a>00726         <span class="stringliteral">"Average with rejection failed"</span>);
+<a name="l00727"></a>00727     } <span class="keywordflow">else</span> {
+<a name="l00728"></a>00728 
+<a name="l00729"></a>00729       check_nomsg(no=cpl_imagelist_get_size(list_dither_object));
+<a name="l00730"></a>00730       lo_cut=(floor)( cfg->loReject*no+0.5);
+<a name="l00731"></a>00731       hi_cut=(floor)( cfg->hiReject*no+0.5);
+<a name="l00732"></a>00732       check(im_dither=cpl_imagelist_collapse_minmax_create(list_dither_object,
+<a name="l00733"></a>00733                                lo_cut,hi_cut),
+<a name="l00734"></a>00734         <span class="stringliteral">"Average with rejection failed"</span>);
+<a name="l00735"></a>00735 
+<a name="l00736"></a>00736     }
+<a name="l00737"></a>00737     sinfo_free_imagelist(&list_dither_object);
+<a name="l00738"></a>00738   }
+<a name="l00739"></a>00739 
+<a name="l00740"></a>00740   <span class="keywordflow">if</span> (cfg->contains_dither == 1 && nskydith > 0) {
+<a name="l00741"></a>00741     <span class="keywordflow">if</span> (cfg->loReject*nskydith < 1. && cfg->hiReject*nskydith < 1.) {
+<a name="l00742"></a>00742       check(im_dither_sky = cpl_imagelist_collapse_create( list_dither_sky ),
+<a name="l00743"></a>00743         <span class="stringliteral">"Average with rejection failed"</span>);
+<a name="l00744"></a>00744     } <span class="keywordflow">else</span> {
+<a name="l00745"></a>00745 
+<a name="l00746"></a>00746       check_nomsg(no=cpl_imagelist_get_size(list_dither_sky));
+<a name="l00747"></a>00747       lo_cut=(floor)( cfg->loReject*no+0.5);
+<a name="l00748"></a>00748       hi_cut=(floor)( cfg->hiReject*no+0.5);
+<a name="l00749"></a>00749       check(im_dither_sky=cpl_imagelist_collapse_minmax_create(list_dither_sky,
+<a name="l00750"></a>00750                                    lo_cut,hi_cut),
+<a name="l00751"></a>00751         <span class="stringliteral">"Average with rejection failed"</span>);
+<a name="l00752"></a>00752     }
+<a name="l00753"></a>00753     sinfo_free_imagelist(&list_dither_sky);
+<a name="l00754"></a>00754   }
+<a name="l00755"></a>00755 
+<a name="l00756"></a>00756   <span class="comment">/*</span>
+<a name="l00757"></a>00757 <span class="comment">  #---------------------------------------------------------</span>
+<a name="l00758"></a>00758 <span class="comment">  # Subtract the resulting off-frame (sky) from the on-frame</span>
+<a name="l00759"></a>00759 <span class="comment">  #-------------------------------------------------------</span>
+<a name="l00760"></a>00760 <span class="comment">  # finally, subtract off from on frames and store the result</span>
+<a name="l00761"></a>00761 <span class="comment">  # in the object cube</span>
+<a name="l00762"></a>00762 <span class="comment">  */</span>
+<a name="l00763"></a>00763 
+<a name="l00764"></a>00764   <span class="keywordflow">if</span>(sub_raw_sky == 1 ) {
+<a name="l00765"></a>00765     <span class="keywordflow">if</span> (cfg->contains_sky == 1) {
+<a name="l00766"></a>00766       sinfo_msg(<span class="stringliteral">"Subtract the off-frame (sky) from the on-frame"</span>);
+<a name="l00767"></a>00767       check_nomsg(im_obj_sub = cpl_image_duplicate(im_obj));
+<a name="l00768"></a>00768       check(cpl_image_subtract(im_obj_sub, im_sky),
+<a name="l00769"></a>00769         <span class="stringliteral">"could not sinfo_sub_image"</span>);
+<a name="l00770"></a>00770 
+<a name="l00771"></a>00771       sinfo_free_image(&im_obj);
+<a name="l00772"></a>00772       <span class="keywordflow">if</span> (((cfg->contains_dither == 1) && (nskydith > 0)) ||
+<a name="l00773"></a>00773           cfg->contains_dither == 0) {
+<a name="l00774"></a>00774     sinfo_free_image(&im_sky);
+<a name="l00775"></a>00775     im_obj = cpl_image_duplicate(im_obj_sub);
+<a name="l00776"></a>00776       }
+<a name="l00777"></a>00777     }
+<a name="l00778"></a>00778 
+<a name="l00779"></a>00779     <span class="keywordflow">if</span> (cfg->contains_dither == 1 && nskydith > 0) {
+<a name="l00780"></a>00780       check_nomsg(im_dither_sub = cpl_image_duplicate(im_dither));
+<a name="l00781"></a>00781       check(cpl_image_subtract(im_dither_sub, im_dither_sky),
+<a name="l00782"></a>00782         <span class="stringliteral">"could not sinfo_sub_image"</span>);
+<a name="l00783"></a>00783 
+<a name="l00784"></a>00784       sinfo_free_image(&im_dither);
+<a name="l00785"></a>00785       sinfo_free_image(&im_dither_sky);
+<a name="l00786"></a>00786       im_dither = cpl_image_duplicate(im_dither_sub);
+<a name="l00787"></a>00787 
+<a name="l00788"></a>00788     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (cfg->contains_dither == 1 &&
+<a name="l00789"></a>00789            nskydith == 0 &&
+<a name="l00790"></a>00790            cfg->contains_sky == 1) {
+<a name="l00791"></a>00791       check_nomsg(im_dither_sub = cpl_image_duplicate(im_dither));
+<a name="l00792"></a>00792       check(cpl_image_subtract(im_dither_sub, im_sky),
+<a name="l00793"></a>00793         <span class="stringliteral">"could not sinfo_sub_image"</span>);
+<a name="l00794"></a>00794 
+<a name="l00795"></a>00795       sinfo_free_image(&im_dither);
+<a name="l00796"></a>00796       sinfo_free_image(&im_sky);
+<a name="l00797"></a>00797       im_dither = cpl_image_duplicate(im_dither_sub);
+<a name="l00798"></a>00798     }
+<a name="l00799"></a>00799   }
+<a name="l00800"></a>00800 
+<a name="l00801"></a>00801   <span class="comment">/*</span>
+<a name="l00802"></a>00802 <span class="comment">  #---------------------------------------------------------</span>
+<a name="l00803"></a>00803 <span class="comment">  # Flatfielding</span>
+<a name="l00804"></a>00804 <span class="comment">  #---------------------------------------------------------</span>
+<a name="l00805"></a>00805 <span class="comment">  */</span>
+<a name="l00806"></a>00806 
+<a name="l00807"></a>00807   <span class="keywordflow">if</span> (cfg->flatInd == 1) {
+<a name="l00808"></a>00808     sinfo_msg(<span class="stringliteral">"Flatfielding"</span>);
+<a name="l00809"></a>00809     check(flat1 = cpl_image_load (cfg->flatfield1,CPL_TYPE_FLOAT,0,0),
+<a name="l00810"></a>00810       <span class="stringliteral">"could not load flatfield image"</span> );
+<a name="l00811"></a>00811 
+<a name="l00812"></a>00812     <span class="keywordflow">if</span>(mflat_norm_smooth) {
+<a name="l00813"></a>00813 
+<a name="l00814"></a>00814       <span class="comment">//We normalize the flat by a smoothed flat</span>
+<a name="l00815"></a>00815       cknull(flat_smooth = sinfo_image_smooth_median_y(flat1,smooth_rad),
+<a name="l00816"></a>00816          <span class="stringliteral">"could not smooth flatfield"</span> );
+<a name="l00817"></a>00817       check_nomsg(cpl_image_divide(flat1,flat_smooth));
+<a name="l00818"></a>00818       sinfo_free_image(&flat_smooth);
+<a name="l00819"></a>00819     }
+<a name="l00820"></a>00820 
+<a name="l00821"></a>00821     cknull(im_obj_flat = sinfo_new_div_images_robust( im_obj, flat1),
+<a name="l00822"></a>00822        <span class="stringliteral">"could not carry out flatfield division"</span> );
+<a name="l00823"></a>00823 
+<a name="l00824"></a>00824     <span class="comment">/* AMO ** */</span>
+<a name="l00825"></a>00825     <span class="keywordflow">if</span>(pdensity > 1) {
+<a name="l00826"></a>00826       <span class="keywordflow">if</span> (frm_ind == 0) {
+<a name="l00827"></a>00827     <span class="keywordflow">if</span> (cfg->warpfixInd == 1){
+<a name="l00828"></a>00828       sinfo_msg(<span class="stringliteral">"Correct FF for distortions"</span>);
+<a name="l00829"></a>00829       <span class="comment">/* AMO check */</span>
+<a name="l00830"></a>00830       cknull_nomsg(flat1_dist=sinfo_new_image_warp_fits(flat1,cfg->kernel,
+<a name="l00831"></a>00831                                 cfg->polyFile));
+<a name="l00832"></a>00832 
+<a name="l00833"></a>00833       ck0(sinfo_pro_save_ima(flat1_dist,raw,sof,
+<a name="l00834"></a>00834                  STACK_MFLAT_DIST_OUT_FILENAME,
+<a name="l00835"></a>00835                  PRO_STACK_MFLAT_DIST,NULL,plugin_id,config),
+<a name="l00836"></a>00836           <span class="stringliteral">"cannot save ima %s"</span>, STACK_MFLAT_DIST_OUT_FILENAME);
+<a name="l00837"></a>00837       sinfo_free_image(&flat1_dist);
+<a name="l00838"></a>00838     }
+<a name="l00839"></a>00839       }
+<a name="l00840"></a>00840     }
+<a name="l00841"></a>00841     sinfo_free_image(&flat1);
+<a name="l00842"></a>00842     sinfo_free_image(&im_obj);
+<a name="l00843"></a>00843     im_obj = cpl_image_duplicate(im_obj_flat);
+<a name="l00844"></a>00844 
+<a name="l00845"></a>00845     <span class="keywordflow">if</span>(pdensity > 1) {
+<a name="l00846"></a>00846       <span class="keywordflow">if</span> (cfg->contains_dither == 1) {
+<a name="l00847"></a>00847     check(flat2 = cpl_image_load (cfg->flatfield2,CPL_TYPE_FLOAT,0,0),
+<a name="l00848"></a>00848           <span class="stringliteral">"could not load flatfield image"</span> );
+<a name="l00849"></a>00849 
+<a name="l00850"></a>00850     <span class="keywordflow">if</span>(mflat_norm_smooth) {
+<a name="l00851"></a>00851 
+<a name="l00852"></a>00852       <span class="comment">//We normalize the flat by a smoothed flat</span>
+<a name="l00853"></a>00853       cknull(flat_smooth = sinfo_image_smooth_median_y(flat2,smooth_rad),
+<a name="l00854"></a>00854          <span class="stringliteral">"could not smooth flatfield"</span> );
+<a name="l00855"></a>00855       check_nomsg(cpl_image_divide(flat2,flat_smooth));
+<a name="l00856"></a>00856       sinfo_free_image(&flat_smooth);
+<a name="l00857"></a>00857 
+<a name="l00858"></a>00858     }
+<a name="l00859"></a>00859 
+<a name="l00860"></a>00860 
+<a name="l00861"></a>00861     cknull(im_dither_flat = sinfo_new_div_images_robust( im_dither, flat2),
+<a name="l00862"></a>00862            <span class="stringliteral">"could not carry out flatfield division"</span> );
+<a name="l00863"></a>00863 
+<a name="l00864"></a>00864     <span class="keywordflow">if</span> (frm_ind == 0) {
+<a name="l00865"></a>00865       <span class="keywordflow">if</span> (cfg->warpfixInd == 1) {
+<a name="l00866"></a>00866         sinfo_msg(<span class="stringliteral">"Correct FF for distortions"</span>);
+<a name="l00867"></a>00867         flat2_dist = sinfo_new_image_warp_fits(flat2,
+<a name="l00868"></a>00868                            cfg->kernel, cfg->polyFile);
+<a name="l00869"></a>00869 
+<a name="l00870"></a>00870         ck0(sinfo_pro_save_ima(flat2_dist,raw,sof,
+<a name="l00871"></a>00871                    STACK_MFLAT_DITHER_DIST_OUT_FILENAME,
+<a name="l00872"></a>00872                    PRO_STACK_MFLAT_DITHER_DIST,
+<a name="l00873"></a>00873                    NULL,plugin_id,config),
+<a name="l00874"></a>00874         <span class="stringliteral">"cannot save ima %s"</span>, STACK_MFLAT_DITHER_DIST_OUT_FILENAME);
+<a name="l00875"></a>00875         sinfo_free_image(&flat2_dist);
+<a name="l00876"></a>00876       }
+<a name="l00877"></a>00877     }
+<a name="l00878"></a>00878     sinfo_free_image(&flat2);
+<a name="l00879"></a>00879     sinfo_free_image(&im_dither);
+<a name="l00880"></a>00880     im_dither = cpl_image_duplicate(im_dither_flat);
+<a name="l00881"></a>00881       }
+<a name="l00882"></a>00882     }
+<a name="l00883"></a>00883   }
+<a name="l00884"></a>00884 
+<a name="l00885"></a>00885   <span class="comment">/*</span>
+<a name="l00886"></a>00886 <span class="comment">  #---------------------------------------------------------</span>
+<a name="l00887"></a>00887 <span class="comment">  # static bad pixel correction</span>
+<a name="l00888"></a>00888 <span class="comment">  #---------------------------------------------------------</span>
+<a name="l00889"></a>00889 <span class="comment">   */</span>
+<a name="l00890"></a>00890 
+<a name="l00891"></a>00891   <span class="keywordflow">if</span> (cfg->maskInd == 1) {
+<a name="l00892"></a>00892     sinfo_msg(<span class="stringliteral">"Static bad pixel correction"</span>);
+<a name="l00893"></a>00893     check(mask_im = cpl_image_load(cfg->mask,CPL_TYPE_FLOAT,0,0),
+<a name="l00894"></a>00894       <span class="stringliteral">"could not load static bad pixel mask"</span> );
+<a name="l00895"></a>00895 
+<a name="l00896"></a>00896     ck0(sinfo_new_change_mask(mask_im, im_obj),
+<a name="l00897"></a>00897     <span class="stringliteral">"sinfo_changeMask failed"</span> );
+<a name="l00898"></a>00898 
+<a name="l00899"></a>00899     <span class="keywordflow">if</span> (cfg->indind == 0) {
+<a name="l00900"></a>00900       <span class="comment">/* open the ASCII list of the slitlet positions */</span>
+<a name="l00901"></a>00901       <span class="comment">/*READ TFITS TABLE*/</span>
+<a name="l00902"></a>00902       strcpy(file_name,cfg->slitposList);
+<a name="l00903"></a>00903       check(tbl_slitpos = cpl_table_load(file_name,1,0),
+<a name="l00904"></a>00904         <span class="stringliteral">"error loading slitpos tbl %s "</span>,file_name);
+<a name="l00905"></a>00905       <span class="keywordflow">if</span>(cpl_table_has_column(tbl_slitpos,<span class="stringliteral">"pos1"</span>) != 1) {
+<a name="l00906"></a>00906         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Column 'pos1' not found in %s table %s"</span>,
+<a name="l00907"></a>00907                       PRO_SLIT_POS,file_name);
+<a name="l00908"></a>00908     <span class="keywordflow">goto</span> cleanup;
+<a name="l00909"></a>00909       }
+<a name="l00910"></a>00910       <span class="keywordflow">if</span>(cpl_table_has_column(tbl_slitpos,<span class="stringliteral">"pos2"</span>) != 1) {
+<a name="l00911"></a>00911         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Column 'pos2' not found in %s table %s"</span>,
+<a name="l00912"></a>00912                       PRO_SLIT_POS,file_name);
+<a name="l00913"></a>00913     <span class="keywordflow">goto</span> cleanup;
+<a name="l00914"></a>00914       }
+<a name="l00915"></a>00915 
+<a name="l00916"></a>00916       check_nomsg(n = cpl_table_get_nrow(tbl_slitpos));
+<a name="l00917"></a>00917       cknull_nomsg(slit_edges = sinfo_new_2Dfloatarray(n, 2));
+<a name="l00918"></a>00918       <span class="keywordflow">for</span> (i =0 ; i< n; i++){
+<a name="l00919"></a>00919      check_nomsg(val_x=cpl_table_get_double(tbl_slitpos,<span class="stringliteral">"pos1"</span>,i,&status));
+<a name="l00920"></a>00920     check_nomsg(val_y=cpl_table_get_double(tbl_slitpos,<span class="stringliteral">"pos2"</span>,i,&status));
+<a name="l00921"></a>00921     check_nomsg(sinfo_new_array2D_set_value(slit_edges,val_x,i,0));
+<a name="l00922"></a>00922     check_nomsg(sinfo_new_array2D_set_value(slit_edges,val_y,i,1));
+<a name="l00923"></a>00923       }
+<a name="l00924"></a>00924 
+<a name="l00925"></a>00925       sinfo_free_table(&tbl_slitpos);
+<a name="l00926"></a>00926       cknull(int_im = sinfo_interpol_source_image (im_obj,
+<a name="l00927"></a>00927                          mask_im,
+<a name="l00928"></a>00928                          cfg->maxRad,
+<a name="l00929"></a>00929                          slit_edges),
+<a name="l00930"></a>00930      <span class="stringliteral">"could not carry out sinfo_interpolSourceImage"</span> );
+<a name="l00931"></a>00931 
+<a name="l00932"></a>00932       sinfo_free_image(&im_obj);
+<a name="l00933"></a>00933       im_obj = cpl_image_duplicate(int_im);
+<a name="l00934"></a>00934 
+<a name="l00935"></a>00935      <span class="keywordflow">if</span> (cfg->contains_dither == 1) {
+<a name="l00936"></a>00936        cknull(int_im_dith = sinfo_interpol_source_image (im_dither,
+<a name="l00937"></a>00937                                mask_im,
+<a name="l00938"></a>00938                                cfg->maxRad,
+<a name="l00939"></a>00939                                slit_edges),
+<a name="l00940"></a>00940           <span class="stringliteral">"could not carry out sinfo_interpolSourceImage"</span> );
+<a name="l00941"></a>00941 
+<a name="l00942"></a>00942        sinfo_free_image(&im_dither);
+<a name="l00943"></a>00943        im_dither = cpl_image_duplicate(int_im_dith);
+<a name="l00944"></a>00944      }
+<a name="l00945"></a>00945      sinfo_new_destroy_2Dfloatarray(&slit_edges, 32);
+<a name="l00946"></a>00946     } <span class="keywordflow">else</span> {
+<a name="l00947"></a>00947       cknull(int_im = sinfo_new_mult_image_by_mask(im_obj, mask_im),
+<a name="l00948"></a>00948          <span class="stringliteral">"could not carry out sinfo_multImageByMask"</span> );
+<a name="l00949"></a>00949 
+<a name="l00950"></a>00950       sinfo_free_image(&im_obj);
+<a name="l00951"></a>00951       im_obj = cpl_image_duplicate(int_im);
+<a name="l00952"></a>00952       <span class="keywordflow">if</span> (cfg->contains_dither == 1) {
+<a name="l00953"></a>00953     cknull(int_im_dith=sinfo_new_mult_image_by_mask(im_dither, mask_im),
+<a name="l00954"></a>00954            <span class="stringliteral">"could not carry out sinfo_multImageByMask"</span> );
+<a name="l00955"></a>00955 
+<a name="l00956"></a>00956     sinfo_free_image(&im_dither);
+<a name="l00957"></a>00957     im_dither = cpl_image_duplicate(int_im_dith);
+<a name="l00958"></a>00958       }
+<a name="l00959"></a>00959     }
+<a name="l00960"></a>00960     sinfo_free_image(&mask_im);
+<a name="l00961"></a>00961   }
+<a name="l00962"></a>00962 
+<a name="l00963"></a>00963   <span class="comment">/*</span>
+<a name="l00964"></a>00964 <span class="comment">  #---------------------------------------------------------</span>
+<a name="l00965"></a>00965 <span class="comment">  # static bad pixel correction BEZIER</span>
+<a name="l00966"></a>00966 <span class="comment">  #---------------------------------------------------------</span>
+<a name="l00967"></a>00967 <span class="comment">  */</span>
+<a name="l00968"></a>00968 
+<a name="l00969"></a>00969   <span class="keywordflow">if</span> (cfg->maskInd == 2){
+<a name="l00970"></a>00970     sinfo_msg(<span class="stringliteral">"Static bad pixel correction BEZIER"</span>);
+<a name="l00971"></a>00971     check(mask_im = cpl_image_load(cfg->mask,CPL_TYPE_FLOAT,0,0),
+<a name="l00972"></a>00972       <span class="stringliteral">"could not load static bad pixel mask"</span> );
+<a name="l00973"></a>00973 
+<a name="l00974"></a>00974     ck0(sinfo_new_change_mask(mask_im, im_obj),
+<a name="l00975"></a>00975     <span class="stringliteral">"sinfo_changeMask failed"</span> );
+<a name="l00976"></a>00976 
+<a name="l00977"></a>00977     <span class="comment">/* #open the FITS table of the slitlet positions-*/</span>
+<a name="l00978"></a>00978     strcpy(file_name,cfg->slitposList);
+<a name="l00979"></a>00979     check_nomsg(tbl_slitpos = cpl_table_load(file_name,1,0));
+<a name="l00980"></a>00980 
+<a name="l00981"></a>00981     check_nomsg(n = cpl_table_get_nrow(tbl_slitpos));
+<a name="l00982"></a>00982     slit_edges = sinfo_new_2Dfloatarray(n, 2);
+<a name="l00983"></a>00983 
+<a name="l00984"></a>00984     <span class="keywordflow">for</span> (i =0 ; i< n; i++){
+<a name="l00985"></a>00985       val_x=cpl_table_get_double(tbl_slitpos,<span class="stringliteral">"pos1"</span>,i,&status);
+<a name="l00986"></a>00986       val_y=cpl_table_get_double(tbl_slitpos,<span class="stringliteral">"pos2"</span>,i,&status);
+<a name="l00987"></a>00987       sinfo_new_array2D_set_value(slit_edges,val_x,i,0);
+<a name="l00988"></a>00988       sinfo_new_array2D_set_value(slit_edges,val_y,i,1);
+<a name="l00989"></a>00989     }
+<a name="l00990"></a>00990     sinfo_free_table(&tbl_slitpos);
+<a name="l00991"></a>00991 
+<a name="l00992"></a>00992     strcpy(file_name,cfg->indexlist);
+<a name="l00993"></a>00993 
+<a name="l00994"></a>00994     check_nomsg(tbl_index = cpl_table_load(file_name,1,0));
+<a name="l00995"></a>00995 
+<a name="l00996"></a>00996     check_nomsg(n = cpl_table_get_nrow(tbl_index));
+<a name="l00997"></a>00997 
+<a name="l00998"></a>00998     cknull_nomsg(in_nam = (<span class="keywordtype">char</span>**) cpl_calloc(n,<span class="keyword">sizeof</span>(<span class="keywordtype">char</span>*)));
+<a name="l00999"></a>00999 
+<a name="l01000"></a>01000     <span class="keywordflow">for</span> (i =0 ; i< n; i++){
+<a name="l01001"></a>01001       strcpy(in_nam[i],cpl_table_get_string(tbl_index,<span class="stringliteral">"name"</span>,i));
+<a name="l01002"></a>01002     }
+<a name="l01003"></a>01003     sinfo_free_table(&tbl_index);
+<a name="l01004"></a>01004 
+<a name="l01005"></a>01005     <span class="keywordflow">for</span> (i=0;i<cnt;i++) {
+<a name="l01006"></a>01006       <span class="keywordflow">if</span> (strcmp(<span class="stringliteral">"ICube.fits"</span>, name) != 0){
+<a name="l01007"></a>01007     check_nomsg(iCube=cpl_imagelist_load (<span class="stringliteral">"ICube.fits"</span>,CPL_TYPE_FLOAT,0));
+<a name="l01008"></a>01008       }
+<a name="l01009"></a>01009       <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(<span class="stringliteral">"JCube.fits"</span>, name) != 0) {
+<a name="l01010"></a>01010     check_nomsg(jCube = cpl_imagelist_load (<span class="stringliteral">"JCube.fits"</span>,CPL_TYPE_FLOAT,0));
+<a name="l01011"></a>01011       }
+<a name="l01012"></a>01012       <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(<span class="stringliteral">"X.fits"</span>,  name) != 0) {
+<a name="l01013"></a>01013     check_nomsg(X=cpl_image_load(<span class="stringliteral">"X.fits"</span>,CPL_TYPE_FLOAT,0,0));
+<a name="l01014"></a>01014       }
+<a name="l01015"></a>01015       <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(<span class="stringliteral">"Y.fits"</span>,  name) != 0) {
+<a name="l01016"></a>01016     check_nomsg(Y=cpl_image_load(<span class="stringliteral">"Y.fits"</span>,CPL_TYPE_FLOAT,0,0));
+<a name="l01017"></a>01017       }
+<a name="l01018"></a>01018       <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(<span class="stringliteral">"Z.fits"</span>,  name) != 0) {
+<a name="l01019"></a>01019     check_nomsg(Z=cpl_image_load(<span class="stringliteral">"Z.fits"</span>,CPL_TYPE_FLOAT,0,0));
+<a name="l01020"></a>01020       }
+<a name="l01021"></a>01021       <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(<span class="stringliteral">"cX.fits"</span>, name) != 0) {
+<a name="l01022"></a>01022     check_nomsg(hX=cpl_image_load(<span class="stringliteral">"cX.fits"</span>,CPL_TYPE_FLOAT,0,0));
+<a name="l01023"></a>01023       }
+<a name="l01024"></a>01024       <span class="keywordflow">else</span> {
+<a name="l01025"></a>01025     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"wrong name in index list or needed file not there!"</span>);
+<a name="l01026"></a>01026     <span class="keywordflow">goto</span> cleanup;
+<a name="l01027"></a>01027       }
+<a name="l01028"></a>01028     }
+<a name="l01029"></a>01029     lookup = sinfo_new_lookup();
+<a name="l01030"></a>01030 
+<a name="l01031"></a>01031     lookup->id=iCube;
+<a name="l01032"></a>01032     lookup->jd=jCube;
+<a name="l01033"></a>01033     lookup->X=X;
+<a name="l01034"></a>01034     lookup->Y=Y;
+<a name="l01035"></a>01035     lookup->Z=Z;
+<a name="l01036"></a>01036     lookup->hX=hX;
+<a name="l01037"></a>01037 
+<a name="l01038"></a>01038 
+<a name="l01039"></a>01039     cknull(im_obj=sinfo_new_c_bezier_interpolate_image(im_obj,
+<a name="l01040"></a>01040                                                        mask_im,
+<a name="l01041"></a>01041                                                        lookup,
+<a name="l01042"></a>01042                                cfg->maxRad,
+<a name="l01043"></a>01043                                cfg->maxRad,
+<a name="l01044"></a>01044                                                        cfg->maxRad,
+<a name="l01045"></a>01045                                                        2,
+<a name="l01046"></a>01046                                                        slit_edges),
+<a name="l01047"></a>01047        <span class="stringliteral">"could not carry out sinfo_new_c_bezier_interpolate_image"</span> );
+<a name="l01048"></a>01048 
+<a name="l01049"></a>01049 
+<a name="l01050"></a>01050     cknull(im_obj=sinfo_new_c_bezier_find_bad( im_obj,
+<a name="l01051"></a>01051                            mask_im,
+<a name="l01052"></a>01052                            cfg->maxRad,
+<a name="l01053"></a>01053                            cfg->maxRad,
+<a name="l01054"></a>01054                            cfg->maxRad,
+<a name="l01055"></a>01055                            0,
+<a name="l01056"></a>01056                            cpl_image_get_size_x(im_obj),
+<a name="l01057"></a>01057                            0,
+<a name="l01058"></a>01058                            cpl_image_get_size_y(im_obj),
+<a name="l01059"></a>01059                            cfg->sigmaFactor),
+<a name="l01060"></a>01060        <span class="stringliteral">"could not carry out sinfo_new_c_bezier_find_bad"</span> );
+<a name="l01061"></a>01061 
+<a name="l01062"></a>01062 
+<a name="l01063"></a>01063     <span class="keywordflow">if</span> (cfg->contains_dither == 1) {
+<a name="l01064"></a>01064          cknull(im_dither=sinfo_new_c_bezier_interpolate_image(im_dither,
+<a name="l01065"></a>01065                                    mask_im,
+<a name="l01066"></a>01066                                    lookup,
+<a name="l01067"></a>01067                                    cfg->maxRad,
+<a name="l01068"></a>01068                                    cfg->maxRad,
+<a name="l01069"></a>01069                                    cfg->maxRad,
+<a name="l01070"></a>01070                                                                2,
+<a name="l01071"></a>01071                                                                slit_edges),
+<a name="l01072"></a>01072     <span class="stringliteral">"could not carry out new_c_bezier_Interpolate_Image on dithered frame"</span> );
+<a name="l01073"></a>01073 
+<a name="l01074"></a>01074      cknull(im_dither=sinfo_new_c_bezier_find_bad(im_dither,
+<a name="l01075"></a>01075                               mask_im,
+<a name="l01076"></a>01076                               cfg->maxRad,
+<a name="l01077"></a>01077                               cfg->maxRad,
+<a name="l01078"></a>01078                               cfg->maxRad,
+<a name="l01079"></a>01079                               0,
+<a name="l01080"></a>01080                               cpl_image_get_size_x(im_obj),
+<a name="l01081"></a>01081                               0,
+<a name="l01082"></a>01082                               cpl_image_get_size_y(im_obj),
+<a name="l01083"></a>01083                               cfg->sigmaFactor),
+<a name="l01084"></a>01084         <span class="stringliteral">"could not carry out new_c_bezier_find_bad on dithered frame"</span>);
+<a name="l01085"></a>01085 
+<a name="l01086"></a>01086     }
+<a name="l01087"></a>01087     sinfo_new_destroy_2Dfloatarray(&slit_edges, 32);
+<a name="l01088"></a>01088     sinfo_free_image(&mask_im);
+<a name="l01089"></a>01089     sinfo_free_imagelist(&iCube);
+<a name="l01090"></a>01090     sinfo_free_imagelist(&jCube);
+<a name="l01091"></a>01091     sinfo_free_image(&lookup->X);
+<a name="l01092"></a>01092     sinfo_free_image(&lookup->X);
+<a name="l01093"></a>01093     sinfo_free_image(&lookup->Y);
+<a name="l01094"></a>01094     sinfo_free_image(&lookup->hX);
+<a name="l01095"></a>01095     sinfo_new_destroy_lookup(lookup);
+<a name="l01096"></a>01096   }
+<a name="l01097"></a>01097 
+<a name="l01098"></a>01098   <span class="keywordflow">if</span> (cfg->maskInd == 3) {
+<a name="l01099"></a>01099     cknull(mask_im = cpl_image_load(cfg->mask,CPL_TYPE_FLOAT,0,0),
+<a name="l01100"></a>01100        <span class="stringliteral">"could not load static bad pixel mask"</span> );
+<a name="l01101"></a>01101 
+<a name="l01102"></a>01102     <span class="comment">/* #open the ASCII list of the slitlet positions-- */</span>
+<a name="l01103"></a>01103     strcpy(file_name,cfg->slitposList);
+<a name="l01104"></a>01104     check_nomsg(tbl_slitpos = cpl_table_load(file_name,1,0));
+<a name="l01105"></a>01105     <span class="keywordflow">if</span>(cpl_table_has_column(tbl_slitpos,<span class="stringliteral">"pos1"</span>) != 1) {
+<a name="l01106"></a>01106       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Column 'pos1' not found in %s table %s"</span>,
+<a name="l01107"></a>01107                       PRO_SLIT_POS,file_name);
+<a name="l01108"></a>01108       <span class="keywordflow">goto</span> cleanup;
+<a name="l01109"></a>01109     }
+<a name="l01110"></a>01110 
+<a name="l01111"></a>01111     <span class="keywordflow">if</span>(cpl_table_has_column(tbl_slitpos,<span class="stringliteral">"pos2"</span>) != 1) {
+<a name="l01112"></a>01112        <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Column 'pos2' not found in %s table %s"</span>,
+<a name="l01113"></a>01113                       PRO_SLIT_POS,file_name);
+<a name="l01114"></a>01114        <span class="keywordflow">goto</span> cleanup;
+<a name="l01115"></a>01115     }
+<a name="l01116"></a>01116 
+<a name="l01117"></a>01117     check_nomsg(n = cpl_table_get_nrow(tbl_slitpos));
+<a name="l01118"></a>01118     slit_edges = sinfo_new_2Dfloatarray(n, 2);
+<a name="l01119"></a>01119 
+<a name="l01120"></a>01120     <span class="keywordflow">for</span> (i =0 ; i< n; i++) {
+<a name="l01121"></a>01121       val_x=cpl_table_get_double(tbl_slitpos,<span class="stringliteral">"pos1"</span>,i,&status);
+<a name="l01122"></a>01122       val_y=cpl_table_get_double(tbl_slitpos,<span class="stringliteral">"pos2"</span>,i,&status);
+<a name="l01123"></a>01123       sinfo_new_array2D_set_value(slit_edges,val_x,i,0);
+<a name="l01124"></a>01124       sinfo_new_array2D_set_value(slit_edges,val_y,i,1);
+<a name="l01125"></a>01125     }
+<a name="l01126"></a>01126     sinfo_free_table(&tbl_slitpos);
+<a name="l01127"></a>01127 
+<a name="l01128"></a>01128     strcpy(file_name,cfg->indexlist);
+<a name="l01129"></a>01129     check_nomsg(tbl_index = cpl_table_load(file_name,1,0));
+<a name="l01130"></a>01130     check_nomsg(n = cpl_table_get_nrow(tbl_index));
+<a name="l01131"></a>01131     cknull_nomsg(in_nam = (<span class="keywordtype">char</span>**) cpl_calloc(n,<span class="keyword">sizeof</span>(<span class="keywordtype">char</span>*)));
+<a name="l01132"></a>01132 
+<a name="l01133"></a>01133     <span class="keywordflow">for</span> (i =0 ; i< n; i++){
+<a name="l01134"></a>01134        strcpy(in_nam[i],cpl_table_get_string(tbl_index,<span class="stringliteral">"name"</span>,i));
+<a name="l01135"></a>01135     }
+<a name="l01136"></a>01136     sinfo_free_table(&tbl_index);
+<a name="l01137"></a>01137 
+<a name="l01138"></a>01138     <span class="keywordflow">for</span> (i=0;i<cnt;i++){
+<a name="l01139"></a>01139       <span class="keywordflow">if</span> (strcmp(<span class="stringliteral">"ICube.fits"</span>, in_nam[i]) != 0){
+<a name="l01140"></a>01140        check_nomsg(iCube=cpl_imagelist_load(<span class="stringliteral">"ICube.fits"</span>,CPL_TYPE_FLOAT,0));
+<a name="l01141"></a>01141       }
+<a name="l01142"></a>01142       <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(<span class="stringliteral">"JCube.fits"</span>, in_nam[i]) != 0){
+<a name="l01143"></a>01143       check_nomsg(jCube=cpl_imagelist_load(<span class="stringliteral">"JCube.fits"</span>,CPL_TYPE_FLOAT,0));
+<a name="l01144"></a>01144       }
+<a name="l01145"></a>01145       <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(<span class="stringliteral">"X.fits"</span>, in_nam[i]) != 0){
+<a name="l01146"></a>01146     check_nomsg(X=cpl_image_load(<span class="stringliteral">"X.fits"</span>,CPL_TYPE_FLOAT,0,0));
+<a name="l01147"></a>01147       }
+<a name="l01148"></a>01148       <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(<span class="stringliteral">"Y.fits"</span>, in_nam[i]) != 0){
+<a name="l01149"></a>01149     check_nomsg(Y=cpl_image_load(<span class="stringliteral">"Y.fits"</span>,CPL_TYPE_FLOAT,0,0));
+<a name="l01150"></a>01150       }
+<a name="l01151"></a>01151       <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(<span class="stringliteral">"Z.fits"</span>, in_nam[i]) != 0){
+<a name="l01152"></a>01152     check_nomsg(Z=cpl_image_load(<span class="stringliteral">"Z.fits"</span>,CPL_TYPE_FLOAT,0,0));
+<a name="l01153"></a>01153       }
+<a name="l01154"></a>01154       <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(<span class="stringliteral">"cX.fits"</span>, in_nam[i]) != 0) {
+<a name="l01155"></a>01155     check_nomsg(hX=cpl_image_load(<span class="stringliteral">"cX.fits"</span>,CPL_TYPE_FLOAT,0,0));
+<a name="l01156"></a>01156       } <span class="keywordflow">else</span> {
+<a name="l01157"></a>01157      <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"wrong name in index list or needed file not there!"</span>);
+<a name="l01158"></a>01158      <span class="keywordflow">goto</span> cleanup;
+<a name="l01159"></a>01159       }
+<a name="l01160"></a>01160     }
+<a name="l01161"></a>01161     lookup = sinfo_new_lookup();
+<a name="l01162"></a>01162     lookup->id=iCube;
+<a name="l01163"></a>01163     lookup->jd=jCube;
+<a name="l01164"></a>01164     lookup->X=X;
+<a name="l01165"></a>01165     lookup->Y=Y;
+<a name="l01166"></a>01166     lookup->Z=Z;
+<a name="l01167"></a>01167     lookup->hX=hX;
+<a name="l01168"></a>01168 
+<a name="l01169"></a>01169     cknull(im_obj = sinfo_new_c_bezier_interpolate_image(im_obj,
+<a name="l01170"></a>01170                              mask_im,
+<a name="l01171"></a>01171                              lookup,
+<a name="l01172"></a>01172                              cfg->maxRad,
+<a name="l01173"></a>01173                              cfg->maxRad,
+<a name="l01174"></a>01174                              cfg->maxRad,
+<a name="l01175"></a>01175                              2,
+<a name="l01176"></a>01176                              slit_edges ),
+<a name="l01177"></a>01177        <span class="stringliteral">"could not carry out sinfo_new_c_bezier_interpolate_image"</span> );
+<a name="l01178"></a>01178 
+<a name="l01179"></a>01179     <span class="keywordflow">if</span> (cfg->contains_dither == 1) {
+<a name="l01180"></a>01180         cknull(im_dither=sinfo_new_c_bezier_interpolate_image( im_dither,
+<a name="l01181"></a>01181                                    mask_im,
+<a name="l01182"></a>01182                                    lookup,
+<a name="l01183"></a>01183                                    cfg->maxRad,
+<a name="l01184"></a>01184                                    cfg->maxRad,
+<a name="l01185"></a>01185                                    cfg->maxRad,
+<a name="l01186"></a>01186                                    2,
+<a name="l01187"></a>01187                                    slit_edges ),
+<a name="l01188"></a>01188                   <span class="stringliteral">"could not carry out sinfo_new_c_bezier_interpolate_image"</span>
+<a name="l01189"></a>01189                   <span class="stringliteral">" on dithered frame"</span> );
+<a name="l01190"></a>01190 
+<a name="l01191"></a>01191     }
+<a name="l01192"></a>01192     sinfo_new_destroy_2Dfloatarray(&slit_edges, 32);
+<a name="l01193"></a>01193     sinfo_free_image(&mask_im);
+<a name="l01194"></a>01194     sinfo_free_imagelist(&iCube);
+<a name="l01195"></a>01195     sinfo_free_imagelist(&jCube);
+<a name="l01196"></a>01196     sinfo_free_image(&lookup->X);
+<a name="l01197"></a>01197     sinfo_free_image(&lookup->Y);
+<a name="l01198"></a>01198     sinfo_free_image(&lookup->Z);
+<a name="l01199"></a>01199     sinfo_free_image(&lookup->hX);
+<a name="l01200"></a>01200     sinfo_new_destroy_lookup(lookup);
+<a name="l01201"></a>01201   }
+<a name="l01202"></a>01202 
+<a name="l01203"></a>01203 
+<a name="l01204"></a>01204   <span class="comment">/*</span>
+<a name="l01205"></a>01205 <span class="comment">  #---------------------------------------------------------</span>
+<a name="l01206"></a>01206 <span class="comment">  # correction of distortions</span>
+<a name="l01207"></a>01207 <span class="comment">  #---------------------------------------------------------</span>
+<a name="l01208"></a>01208 <span class="comment">  */</span>
+<a name="l01209"></a>01209 
+<a name="l01210"></a>01210   <span class="comment">/* here memory leak */</span>
+<a name="l01211"></a>01211   <span class="comment">//sinfo_msg("cfg->warpfixInd=%d",cfg->warpfixInd);</span>
+<a name="l01212"></a>01212   <span class="keywordflow">if</span> (cfg->warpfixInd == 1){
+<a name="l01213"></a>01213     <span class="comment">/*#open ASCII file containing the slope parameter and read it*/</span>
+<a name="l01214"></a>01214     sinfo_msg(<span class="stringliteral">"Correct object for distortions"</span>);
+<a name="l01215"></a>01215     cknull(int_im_shifted=sinfo_new_image_warp_fits(im_obj,
+<a name="l01216"></a>01216                                                     cfg->kernel,
+<a name="l01217"></a>01217                                                     cfg->polyFile),
+<a name="l01218"></a>01218                                 <span class="stringliteral">"could not carry out sinfo_image_warp_fits"</span> );
+<a name="l01219"></a>01219 
+<a name="l01220"></a>01220     sinfo_free_image(&im_obj);
+<a name="l01221"></a>01221     im_obj = cpl_image_duplicate(int_im_shifted);
+<a name="l01222"></a>01222     <span class="keywordflow">if</span> (cfg->contains_dither == 1){
+<a name="l01223"></a>01223       cknull(int_im_dith_shifted=sinfo_new_image_warp_fits(im_dither,
+<a name="l01224"></a>01224                                                            cfg->kernel,
+<a name="l01225"></a>01225                                                            cfg->polyFile),
+<a name="l01226"></a>01226                                  <span class="stringliteral">"could not carry out sinfo_image_warp_fits"</span> );
+<a name="l01227"></a>01227       sinfo_free_image(&im_dither);
+<a name="l01228"></a>01228       im_dither = cpl_image_duplicate(int_im_dith_shifted);
+<a name="l01229"></a>01229     }
+<a name="l01230"></a>01230   }
+<a name="l01231"></a>01231 
+<a name="l01232"></a>01232   <span class="comment">/*</span>
+<a name="l01233"></a>01233 <span class="comment">  #---------------------------------------------------------</span>
+<a name="l01234"></a>01234 <span class="comment">  # merge (interleave) both resulting frames</span>
+<a name="l01235"></a>01235 <span class="comment">  #---------------------------------------------------------</span>
+<a name="l01236"></a>01236 <span class="comment">  */</span>
+<a name="l01237"></a>01237   <span class="keywordflow">if</span> (cfg->interInd == 1 && cfg->contains_dither == 1){
+<a name="l01238"></a>01238     <span class="keywordflow">if</span>( pdensity>1) {
+<a name="l01239"></a>01239       sinfo_msg(<span class="stringliteral">"Merge (interleave) frames"</span>);
+<a name="l01240"></a>01240       cknull(im3 = cpl_image_new(cpl_image_get_size_x(im_obj),
+<a name="l01241"></a>01241                  cpl_image_get_size_y(im_obj),CPL_TYPE_FLOAT),
+<a name="l01242"></a>01242          <span class="stringliteral">"could not allocate an image"</span> );
+<a name="l01243"></a>01243       cknull(im4=sinfo_new_remove_general_offset( im_obj, im_dither,
+<a name="l01244"></a>01244                           im3, cfg->noRows ),
+<a name="l01245"></a>01245          <span class="stringliteral">"sinfo_removeGeneralOffset failed"</span> );
+<a name="l01246"></a>01246 
+<a name="l01247"></a>01247       cknull(im5 = sinfo_new_remove_regional_tilt ( im_obj, im4, im3 ),
+<a name="l01248"></a>01248          <span class="stringliteral">"sinfo_removeRegionalTilt failed"</span> );
+<a name="l01249"></a>01249 
+<a name="l01250"></a>01250       cknull(im6 = sinfo_new_remove_column_offset ( im_obj, im5, im3 ),
+<a name="l01251"></a>01251          <span class="stringliteral">"sinfo_removeColumnOffset failed"</span> );
+<a name="l01252"></a>01252 
+<a name="l01253"></a>01253       cknull(im7 = sinfo_new_remove_residual_tilt ( im6, im3 ),
+<a name="l01254"></a>01254          <span class="stringliteral">"sinfo_removeResidualTilt failed"</span> );
+<a name="l01255"></a>01255 
+<a name="l01256"></a>01256       cknull(im8 = sinfo_new_remove_residual_offset ( im7, im3 ),
+<a name="l01257"></a>01257          <span class="stringliteral">"sinfo_removeResidualOffset failed"</span>);
+<a name="l01258"></a>01258       cknull(im9 = sinfo_sinfo_merge_images(im_obj, im8, im3),
+<a name="l01259"></a>01259          <span class="stringliteral">"sinfo_mergeImages failed"</span> );
+<a name="l01260"></a>01260 
+<a name="l01261"></a>01261       ck0(sinfo_pro_save_ima(im9,raw,sof,cfg->outName,
+<a name="l01262"></a>01262                  frm_pro_ctg,NULL,plugin_id,config),
+<a name="l01263"></a>01263       <span class="stringliteral">"cannot save ima %s"</span>, cfg->outName);
+<a name="l01264"></a>01264 
+<a name="l01265"></a>01265       sinfo_free_image(&im3);
+<a name="l01266"></a>01266       sinfo_free_image(&im4);
+<a name="l01267"></a>01267       sinfo_free_image(&im5);
+<a name="l01268"></a>01268       sinfo_free_image(&im6);
+<a name="l01269"></a>01269       sinfo_free_image(&im7);
+<a name="l01270"></a>01270       sinfo_free_image(&im8);
+<a name="l01271"></a>01271       sinfo_free_image(&im9);
+<a name="l01272"></a>01272       sinfo_free_image(&im_obj);
+<a name="l01273"></a>01273       sinfo_free_image(&im_dither);
+<a name="l01274"></a>01274     }
+<a name="l01275"></a>01275     <span class="comment">/*</span>
+<a name="l01276"></a>01276 <span class="comment">    #---------------------------------------------------------</span>
+<a name="l01277"></a>01277 <span class="comment">    # convolve spectra with Gaussian</span>
+<a name="l01278"></a>01278 <span class="comment">    #---------------------------------------------------------</span>
+<a name="l01279"></a>01279 <span class="comment">    */</span>
+<a name="l01280"></a>01280   } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (cfg->gaussInd == 1 && cfg->interInd == 0) {
+<a name="l01281"></a>01281     sinfo_msg(<span class="stringliteral">"Convolve spectra with Gaussian"</span>);
+<a name="l01282"></a>01282     <span class="keywordflow">if</span>(pdensity > 1) {
+<a name="l01283"></a>01283       cknull(im_conv = sinfo_new_convolve_image_by_gauss ( im_obj, cfg->hw ),
+<a name="l01284"></a>01284          <span class="stringliteral">"sinfo_convolveImageByGauss failed"</span> );
+<a name="l01285"></a>01285 
+<a name="l01286"></a>01286       ck0(sinfo_pro_save_ima(im_conv,raw,sof,cfg->outName,
+<a name="l01287"></a>01287                  frm_pro_ctg,NULL,plugin_id,config),
+<a name="l01288"></a>01288       <span class="stringliteral">"cannot save ima %s"</span>, cfg->outName);
+<a name="l01289"></a>01289 
+<a name="l01290"></a>01290       sinfo_free_image(&im_obj);
+<a name="l01291"></a>01291       sinfo_free_image(&im_conv);
+<a name="l01292"></a>01292       <span class="keywordflow">if</span> (cfg->contains_dither == 1){
+<a name="l01293"></a>01293     sinfo_free_image(&im_dither);
+<a name="l01294"></a>01294       }
+<a name="l01295"></a>01295     }
+<a name="l01296"></a>01296   } <span class="keywordflow">else</span> {
+<a name="l01297"></a>01297 
+<a name="l01298"></a>01298     sinfo_msg(<span class="stringliteral">"Add QC LOG"</span>);
+<a name="l01299"></a>01299     <span class="comment">/* add QC-LOG */</span>
+<a name="l01300"></a>01300     <span class="comment">/* sinfo_det_ncounts(raw, cfg->qc_thresh_max); */</span>
+<a name="l01301"></a>01301     cknull_nomsg(qclog_tbl = sinfo_qclog_init());
+<a name="l01302"></a>01302 
+<a name="l01303"></a>01303     ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,<span class="stringliteral">"QC FRMON MEANFLUX"</span>,
+<a name="l01304"></a>01304                      qc->avg_on,<span class="stringliteral">"Average of flux"</span>,<span class="stringliteral">"%g"</span>));
+<a name="l01305"></a>01305 <span class="comment">/*    ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC FRMON MEANFLUX",</span>
+<a name="l01306"></a>01306 <span class="comment">                     qc->avg_on,"Average of flux","%g"));*/</span>
+<a name="l01307"></a>01307     ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,<span class="stringliteral">"QC FRMOFF MEANFLUX"</span>,
+<a name="l01308"></a>01308                      qc->avg_of,<span class="stringliteral">"Average of flux"</span>,<span class="stringliteral">"%g"</span>));
+<a name="l01309"></a>01309     ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,<span class="stringliteral">"QC FRMDIF MEANFLUX"</span>,
+<a name="l01310"></a>01310                      qc->avg_di,<span class="stringliteral">"Average of flux"</span>,<span class="stringliteral">"%g"</span>));
+<a name="l01311"></a>01311     ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,<span class="stringliteral">"QC FRMON MAXFLUX"</span>,
+<a name="l01312"></a>01312                      qc->max_on,<span class="stringliteral">"Max of flux"</span>,<span class="stringliteral">"%g"</span>));
+<a name="l01313"></a>01313     ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,<span class="stringliteral">"QC FRMOFF MAXFLUX"</span>,
+<a name="l01314"></a>01314                      qc->max_of,<span class="stringliteral">"Max of flux"</span>,<span class="stringliteral">"%g"</span>));
+<a name="l01315"></a>01315     ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,<span class="stringliteral">"QC FRMDIF MAXFLUX"</span>,
+<a name="l01316"></a>01316                      qc->max_di,<span class="stringliteral">"Max of flux"</span>,<span class="stringliteral">"%g"</span>));
+<a name="l01317"></a>01317     ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,<span class="stringliteral">"QC FRMON NPIXSAT"</span>,
+<a name="l01318"></a>01318                   qc->nsat,
+<a name="l01319"></a>01319                   <span class="stringliteral">"Number of saturated pixels"</span>,<span class="stringliteral">"%d"</span>));
+<a name="l01320"></a>01320     update_bad_pixel_map(im_obj);
+<a name="l01321"></a>01321     ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,<span class="stringliteral">"QC FRMDIF MEANSTD"</span>,
+<a name="l01322"></a>01322                      cpl_image_get_mean(im_obj),<span class="stringliteral">"mean of the image"</span>,<span class="stringliteral">"%13.6f"</span>));
+<a name="l01323"></a>01323 
+<a name="l01324"></a>01324     ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,
+<a name="l01325"></a>01325                                              <span class="stringliteral">"QC FRMDIF STDEV"</span>,
+<a name="l01326"></a>01326                                              cpl_image_get_stdev(im_obj),
+<a name="l01327"></a>01327                                              <span class="stringliteral">"standard deviation of the image"</span>,
+<a name="l01328"></a>01328                                              <span class="stringliteral">"%13.6f"</span>));
+<a name="l01329"></a>01329 
+<a name="l01330"></a>01330     ck0(sinfo_pro_save_ima(im_obj,raw,sof,cfg->outName,
+<a name="l01331"></a>01331                frm_pro_ctg,qclog_tbl,plugin_id,config),
+<a name="l01332"></a>01332     <span class="stringliteral">"cannot dump ima %s"</span>, cfg->outName);
+<a name="l01333"></a>01333 
+<a name="l01334"></a>01334     sinfo_free_image(&im_obj);
+<a name="l01335"></a>01335     sinfo_free_table(&qclog_tbl);
+<a name="l01336"></a>01336 
+<a name="l01337"></a>01337     <span class="keywordflow">if</span> (cfg->contains_dither == 1 && cfg->interInd == 0) {
+<a name="l01338"></a>01338       <span class="keywordflow">if</span> (strstr(cfg->outName, <span class="stringliteral">".fits"</span> ) != NULL ) {
+<a name="l01339"></a>01339     snprintf(name_list, MAX_NAME_SIZE-1,<span class="stringliteral">"%s%s"</span>,
+<a name="l01340"></a>01340          sinfo_new_get_rootname(cfg->outName), <span class="stringliteral">"_dith.fits"</span>);
+<a name="l01341"></a>01341     strcpy(cfg->outName,name_list);
+<a name="l01342"></a>01342       } <span class="keywordflow">else</span> {
+<a name="l01343"></a>01343     strcat(cfg->outName,<span class="stringliteral">"_dith"</span>);
+<a name="l01344"></a>01344       }
+<a name="l01345"></a>01345       cpl_free(name_list);
+<a name="l01346"></a>01346 
+<a name="l01347"></a>01347 
+<a name="l01348"></a>01348 
+<a name="l01349"></a>01349       ck0(sinfo_pro_save_ima(im_dither,raw,sof,cfg->outName,
+<a name="l01350"></a>01350                  frm_pro_ctg,NULL,plugin_id,config),
+<a name="l01351"></a>01351       <span class="stringliteral">"cannot save ima %s"</span>, cfg->outName);
+<a name="l01352"></a>01352 
+<a name="l01353"></a>01353       <span class="keywordflow">if</span> (cfg->contains_dither == 1) {
+<a name="l01354"></a>01354     sinfo_free_image(&im_dither);
+<a name="l01355"></a>01355       }
+<a name="l01356"></a>01356     }
+<a name="l01357"></a>01357 
+<a name="l01358"></a>01358   }
+<a name="l01359"></a>01359 
+<a name="l01360"></a>01360   <span class="comment">/* the following generates a valgrind error</span>
+<a name="l01361"></a>01361 <span class="comment">     but without it 8 bytes are leaked */</span>
+<a name="l01362"></a>01362   sinfo_free_image_array(&im,cfg->nframes);
+<a name="l01363"></a>01363 
+<a name="l01364"></a>01364   <span class="comment">/*AMO: check if those images can be deleted before */</span>
+<a name="l01365"></a>01365   sinfo_free_image(&int_im_shifted);
+<a name="l01366"></a>01366   sinfo_free_image(&int_im);
+<a name="l01367"></a>01367   sinfo_free_image(&im_obj_flat);
+<a name="l01368"></a>01368   sinfo_free_image(&im_obj_sub);
+<a name="l01369"></a>01369 
+<a name="l01370"></a>01370   sinfo_stack_free(&cfg);
+<a name="l01371"></a>01371   sinfo_free_frameset(&raw);
+<a name="l01372"></a>01372   sinfo_qc_wcal_delete(&qc);
+<a name="l01373"></a>01373 
+<a name="l01374"></a>01374   <span class="keywordflow">return</span> 0;
+<a name="l01375"></a>01375 
+<a name="l01376"></a>01376  cleanup:
+<a name="l01377"></a>01377   sinfo_free_table(&qclog_tbl);
+<a name="l01378"></a>01378   sinfo_free_table(&tbl_slitpos);
+<a name="l01379"></a>01379   sinfo_free_table(&tbl_index);
+<a name="l01380"></a>01380   <span class="keywordflow">if</span>(slit_edges!=NULL) sinfo_new_destroy_2Dfloatarray(&slit_edges, 32);
+<a name="l01381"></a>01381   sinfo_free_image(&flat1_dist);
+<a name="l01382"></a>01382   sinfo_free_image(&flat1);
+<a name="l01383"></a>01383   sinfo_free_image(&flat_smooth);
+<a name="l01384"></a>01384   sinfo_free_image(&flat2_dist);
+<a name="l01385"></a>01385   sinfo_free_image(&int_im);
+<a name="l01386"></a>01386   sinfo_free_image(&int_im_dith);
+<a name="l01387"></a>01387   sinfo_free_image(&int_im_shifted);
+<a name="l01388"></a>01388   sinfo_free_image(&im_dither);
+<a name="l01389"></a>01389   sinfo_free_image(&flat2);
+<a name="l01390"></a>01390   sinfo_free_image(&im_obj_flat);
+<a name="l01391"></a>01391   sinfo_free_image(&im_obj_sub);
+<a name="l01392"></a>01392   sinfo_free_image(&im_obj);
+<a name="l01393"></a>01393   sinfo_free_image(&mask_im);
+<a name="l01394"></a>01394   sinfo_free_image(&im_sky);
+<a name="l01395"></a>01395   sinfo_free_imagelist(&list_object_tmp);
+<a name="l01396"></a>01396   sinfo_free_image(&sky_img_flat);
+<a name="l01397"></a>01397   sinfo_free_image(&sky_dist);
+<a name="l01398"></a>01398   sinfo_free_image(&sky_img);
+<a name="l01399"></a>01399   sinfo_free_imagelist(&list_object);
+<a name="l01400"></a>01400   sinfo_free_imagelist(&list_sky);
+<a name="l01401"></a>01401   <span class="keywordflow">if</span>(im != NULL) sinfo_free_image_array(&im,cfg->nframes);
+<a name="l01402"></a>01402   sinfo_stack_free(&cfg);
+<a name="l01403"></a>01403   sinfo_free_frameset(&raw);
+<a name="l01404"></a>01404   sinfo_qc_wcal_delete(&qc);
+<a name="l01405"></a>01405 
+<a name="l01406"></a>01406   <span class="keywordflow">return</span> -1 ;
+<a name="l01407"></a>01407 
+<a name="l01408"></a>01408 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__new__prepare__stacked__frames_8h_source.html b/html/sinfo__new__prepare__stacked__frames_8h_source.html
new file mode 100644
index 0000000..592b25b
--- /dev/null
+++ b/html/sinfo__new__prepare__stacked__frames_8h_source.html
@@ -0,0 +1,97 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_new_prepare_stacked_frames.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_new_prepare_stacked_frames.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#ifndef SINFO_NEW_PREPARE_STACKED_FRAMES_H</span>
+<a name="l00002"></a>00002 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_NEW_PREPARE_STACKED_FRAMES_H</span>
+<a name="l00003"></a>00003 <span class="preprocessor"></span><span class="comment">/*</span>
+<a name="l00004"></a>00004 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00005"></a>00005 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00006"></a>00006 <span class="comment"> *</span>
+<a name="l00007"></a>00007 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00008"></a>00008 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00009"></a>00009 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00010"></a>00010 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00011"></a>00011 <span class="comment"> *</span>
+<a name="l00012"></a>00012 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00013"></a>00013 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00014"></a>00014 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00015"></a>00015 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00016"></a>00016 <span class="comment"> *</span>
+<a name="l00017"></a>00017 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00018"></a>00018 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00019"></a>00019 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00020"></a>00020 <span class="comment"> */</span>
+<a name="l00021"></a>00021 <span class="comment">/*****************************************************************************</span>
+<a name="l00022"></a>00022 <span class="comment">* E.S.O. - VLT project</span>
+<a name="l00023"></a>00023 <span class="comment">*</span>
+<a name="l00024"></a>00024 <span class="comment">* "@(#) $Id: sinfo_new_prepare_stacked_frames.h,v 1.7 2007/09/21 14:48:10 amodigli Exp $"</span>
+<a name="l00025"></a>00025 <span class="comment">*</span>
+<a name="l00026"></a>00026 <span class="comment">* who       when      what</span>
+<a name="l00027"></a>00027 <span class="comment">* --------  --------  ----------------------------------------------</span>
+<a name="l00028"></a>00028 <span class="comment">* amodigli  17/09/03  created</span>
+<a name="l00029"></a>00029 <span class="comment">*/</span>
+<a name="l00030"></a>00030 
+<a name="l00031"></a>00031 <span class="comment">/************************************************************************</span>
+<a name="l00032"></a>00032 <span class="comment"> * preapare_stacked_frames.h</span>
+<a name="l00033"></a>00033 <span class="comment"></span>
+<a name="l00034"></a>00034 <span class="comment"> sinfo_prepare_stacked_frames</span>
+<a name="l00035"></a>00035 <span class="comment"></span>
+<a name="l00036"></a>00036 <span class="comment">  this handles stacks of input frames, that means it takes a clean mean,</span>
+<a name="l00037"></a>00037 <span class="comment">  subtracts the off- from the on-frames, flatfields, corrects for static bad </span>
+<a name="l00038"></a>00038 <span class="comment">  pixels, corrects for a linear tilt of the spectra if necessary, and finally, </span>
+<a name="l00039"></a>00039 <span class="comment">  interleaves dithered exposures or convolves a single exposure with a </span>
+<a name="l00040"></a>00040 <span class="comment">  Gaussian, respectively.</span>
+<a name="l00041"></a>00041 <span class="comment"></span>
+<a name="l00042"></a>00042 <span class="comment"> *----------------------------------------------------------------------</span>
+<a name="l00043"></a>00043 <span class="comment"> */</span>
+<a name="l00044"></a>00044 
+<a name="l00045"></a>00045 <span class="comment">/*</span>
+<a name="l00046"></a>00046 <span class="comment"> * header files</span>
+<a name="l00047"></a>00047 <span class="comment"> */</span>
+<a name="l00048"></a>00048 <span class="preprocessor">#include <cpl.h></span>   
+<a name="l00049"></a>00049 <span class="preprocessor">#include "sinfo_globals.h"</span>
+<a name="l00050"></a>00050 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00051"></a>00051 
+<a name="l00052"></a>00052 
+<a name="l00053"></a>00053 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00054"></a>00054 <span class="comment"> *                        Function ANSI C prototypes</span>
+<a name="l00055"></a>00055 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00056"></a>00056 
+<a name="l00057"></a>00057 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00058"></a>00058 <span class="comment">   Function     :       sinfo_new_prepare_stacked_frames()</span>
+<a name="l00059"></a>00059 <span class="comment">   In           :       ini_file: file name of according .ini file</span>
+<a name="l00060"></a>00060 <span class="comment">   Out          :       integer (0 if it worked, -1 if it doesn't) </span>
+<a name="l00061"></a>00061 <span class="comment">   Job          :</span>
+<a name="l00062"></a>00062 <span class="comment"></span>
+<a name="l00063"></a>00063 <span class="comment">  this handles stacks of input frames, that means it takes a clean mean,</span>
+<a name="l00064"></a>00064 <span class="comment">  subtracts the off- from the on-frames, flatfields, corrects for static bad </span>
+<a name="l00065"></a>00065 <span class="comment">  pixels, corrects for a linear tilt of the spectra if necessary, and finally, </span>
+<a name="l00066"></a>00066 <span class="comment">  interleaves dithered exposures or convolves a single exposure with a </span>
+<a name="l00067"></a>00067 <span class="comment">  Gaussian, respectively.</span>
+<a name="l00068"></a>00068 <span class="comment"></span>
+<a name="l00069"></a>00069 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00070"></a>00070 <span class="keywordtype">int</span> 
+<a name="l00071"></a>00071 sinfo_new_prepare_stacked_frames (<span class="keyword">const</span> <span class="keywordtype">char</span>* plugin_id,
+<a name="l00072"></a>00072                                   cpl_parameterlist* config, 
+<a name="l00073"></a>00073                                   cpl_frameset* sof, 
+<a name="l00074"></a>00074                                   cpl_frameset* ref_set, 
+<a name="l00075"></a>00075                                   <span class="keyword">const</span> <span class="keywordtype">char</span>* procatg,
+<a name="l00076"></a>00076                                   <span class="keyword">const</span> <span class="keywordtype">int</span> frm_ind, 
+<a name="l00077"></a>00077                                   fake* fk) ;
+<a name="l00078"></a>00078 
+<a name="l00079"></a>00079 <span class="preprocessor">#endif </span>
+<a name="l00080"></a>00080 <span class="preprocessor"></span>
+<a name="l00081"></a>00081 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__new__psf_8c_source.html b/html/sinfo__new__psf_8c_source.html
new file mode 100644
index 0000000..1d91349
--- /dev/null
+++ b/html/sinfo__new__psf_8c_source.html
@@ -0,0 +1,2518 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_new_psf.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_new_psf.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment"></span>
+<a name="l00021"></a>00021 <span class="comment">     File name    :       sinfo_new_psf.c</span>
+<a name="l00022"></a>00022 <span class="comment">   Author       :    A. Modigliani</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on   :    Sep 17, 2003</span>
+<a name="l00024"></a>00024 <span class="comment">   Description  :</span>
+<a name="l00025"></a>00025 <span class="comment"></span>
+<a name="l00026"></a>00026 <span class="comment"> sinfo_new_psf.py does the image reconstruction of a set of</span>
+<a name="l00027"></a>00027 <span class="comment"> sky-subtracted, flatfielded,</span>
+<a name="l00028"></a>00028 <span class="comment"> bad pixel corrected and slope of the spectra aligned exposures of a bright</span>
+<a name="l00029"></a>00029 <span class="comment"> star with continuum spectrum. The resulting image can be used to determine</span>
+<a name="l00030"></a>00030 <span class="comment"> the PSF</span>
+<a name="l00031"></a>00031 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00032"></a>00032 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00033"></a>00033 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00034"></a>00034 <span class="preprocessor">#endif</span>
+<a name="l00035"></a>00035 <span class="preprocessor"></span>
+<a name="l00036"></a>00036 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00037"></a>00037 <span class="comment">                                Includes</span>
+<a name="l00038"></a>00038 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00039"></a>00039 <span class="preprocessor">#define _GNU_SOURCE</span>
+<a name="l00040"></a>00040 <span class="preprocessor"></span><span class="preprocessor">#include <math.h></span>
+<a name="l00041"></a>00041 
+<a name="l00042"></a>00042 <span class="preprocessor">#include <assert.h></span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include <sinfo_cpl_size.h></span>
+<a name="l00044"></a>00044 
+<a name="l00045"></a>00045 <span class="preprocessor">#include <irplib_utils.h></span>
+<a name="l00046"></a>00046 <span class="preprocessor">#include <irplib_strehl.h></span>
+<a name="l00047"></a>00047 <span class="preprocessor">#include "sinfo_new_psf.h"</span>
+<a name="l00048"></a>00048 <span class="preprocessor">#include "sinfo_pro_save.h"</span>
+<a name="l00049"></a>00049 <span class="preprocessor">#include "sinfo_hidden.h"</span>
+<a name="l00050"></a>00050 <span class="preprocessor">#include "sinfo_key_names.h"</span>
+<a name="l00051"></a>00051 <span class="preprocessor">#include "sinfo_psf_ini.h"</span>
+<a name="l00052"></a>00052 <span class="preprocessor">#include "sinfo_psf_ini_by_cpl.h"</span>
+<a name="l00053"></a>00053 <span class="preprocessor">#include "sinfo_utilities_scired.h"</span>
+<a name="l00054"></a>00054 <span class="preprocessor">#include "sinfo_hidden.h"</span>
+<a name="l00055"></a>00055 <span class="preprocessor">#include "sinfo_pfits.h"</span>
+<a name="l00056"></a>00056 <span class="preprocessor">#include "sinfo_functions.h"</span>
+<a name="l00057"></a>00057 <span class="preprocessor">#include "sinfo_error.h"</span>
+<a name="l00058"></a>00058 <span class="preprocessor">#include "sinfo_utils_wrappers.h"</span>
+<a name="l00059"></a>00059 <span class="preprocessor">#include "sinfo_globals.h"</span>
+<a name="l00060"></a>00060 <span class="comment">//Used only for sinfo_propertylist_has</span>
+<a name="l00061"></a>00061 <span class="preprocessor">#include "sinfo_dfs.h"</span>
+<a name="l00062"></a>00062 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00063"></a>00063 <span class="comment">                                Defines</span>
+<a name="l00064"></a>00064 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00065"></a>00065                                                    <span class="comment">//PSO</span>
+<a name="l00066"></a>00066 <span class="preprocessor">#define SINFO_MATH_PI   3.1415926535897932384626433832795028841971693993751058</span>
+<a name="l00067"></a>00067 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_MATH_PI_2 1.5707963267948966192313216916397514420985846996875529</span>
+<a name="l00068"></a>00068 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_MATH_PI_4 0.7853981633974483096156608458198757210492923498437765</span>
+<a name="l00069"></a>00069 <span class="preprocessor"></span>
+<a name="l00070"></a>00070 
+<a name="l00071"></a>00071 
+<a name="l00072"></a>00072 <span class="preprocessor">#define SINFO_STREHL_M1                       8.0  //7.9</span>
+<a name="l00073"></a>00073 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_STREHL_M2                       1.1  //1.33</span>
+<a name="l00074"></a>00074 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_STREHL_BOX_SIZE                 64</span>
+<a name="l00075"></a>00075 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_STREHL_WINDOW                   6</span>
+<a name="l00076"></a>00076 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_PSF_SZ                          4</span>
+<a name="l00077"></a>00077 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_RSTAR                           32//25</span>
+<a name="l00078"></a>00078 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_BKG_R1                          32//25</span>
+<a name="l00079"></a>00079 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_BKG_R2                          33//27</span>
+<a name="l00080"></a>00080 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_STREHL_ERROR_COEFFICIENT    SINFO_MATH_PI * 0.007 / 0.0271</span>
+<a name="l00081"></a>00081 <span class="preprocessor"></span><span class="preprocessor">#ifndef SINFO_STREHL_RAD_CENTRAL</span>
+<a name="l00082"></a>00082 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_STREHL_RAD_CENTRAL 5</span>
+<a name="l00083"></a>00083 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
+<a name="l00084"></a>00084 <span class="preprocessor"></span>
+<a name="l00085"></a>00085 <span class="comment">//constants for perfect PSF generation</span>
+<a name="l00086"></a>00086 <span class="comment">// Dimension of the support for generating the perfect PFS</span>
+<a name="l00087"></a>00087 <span class="preprocessor">#define SINFO_PSF_DIM   1024//256</span>
+<a name="l00088"></a>00088 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_PSF_BLOCKS   63//11</span>
+<a name="l00089"></a>00089 <span class="preprocessor"></span>
+<a name="l00090"></a>00090 <span class="preprocessor">#define SINFO_PSF_BIN    16 // Pixels over "pixel_size"</span>
+<a name="l00091"></a>00091 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_PSF_NPOINT 10000// number of encircled energy sampling points</span>
+<a name="l00092"></a>00092 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_BKG_BOX_SZ 8</span>
+<a name="l00093"></a>00093 <span class="preprocessor"></span><span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00094"></a>00094 <span class="comment">                             Function Definitions</span>
+<a name="l00095"></a>00095 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00096"></a>00096 <span class="keyword">static</span> cpl_error_code
+<a name="l00097"></a>00097 sinfo_add_com_psf_qclog(<span class="keyword">const</span> <span class="keywordtype">char</span>* fname,cpl_table** qclog_tbl);
+<a name="l00098"></a>00098 
+<a name="l00099"></a>00099 
+<a name="l00100"></a>00100 <span class="keyword">static</span> cpl_error_code
+<a name="l00101"></a>00101 sinfo_get_star_features(<span class="keyword">const</span> cpl_image* im,
+<a name="l00102"></a>00102                         <span class="keyword">const</span> <span class="keywordtype">int</span> radius,
+<a name="l00103"></a>00103             <span class="keyword">const</span> <span class="keywordtype">int</span> xpos,
+<a name="l00104"></a>00104             <span class="keyword">const</span> <span class="keywordtype">int</span> ypos,
+<a name="l00105"></a>00105                         <span class="keywordtype">double</span>* xc,
+<a name="l00106"></a>00106                         <span class="keywordtype">double</span>* yc,
+<a name="l00107"></a>00107                         <span class="keywordtype">double</span>* pick,
+<a name="l00108"></a>00108                         <span class="keywordtype">double</span>* flux,
+<a name="l00109"></a>00109                         <span class="keywordtype">double</span>* bkg);
+<a name="l00110"></a>00110 
+<a name="l00111"></a>00111 <span class="keyword">static</span> <span class="keywordtype">double</span>
+<a name="l00112"></a>00112 sinfo_find_min_of_four(<span class="keyword">const</span> <span class="keywordtype">double</span> n1,
+<a name="l00113"></a>00113                        <span class="keyword">const</span> <span class="keywordtype">double</span> n2,
+<a name="l00114"></a>00114                        <span class="keyword">const</span> <span class="keywordtype">double</span> n3,
+<a name="l00115"></a>00115                        <span class="keyword">const</span> <span class="keywordtype">double</span> n4);
+<a name="l00116"></a>00116 
+<a name="l00117"></a>00117 <span class="keyword">static</span> cpl_table*
+<a name="l00118"></a>00118 sinfo_get_strehl_from_2images(cpl_image* ima1,
+<a name="l00119"></a>00119                              cpl_image* ima2,
+<a name="l00120"></a>00120                              cpl_frame* frm1,
+<a name="l00121"></a>00121                   cpl_frame* frm2);
+<a name="l00122"></a>00122 
+<a name="l00123"></a>00123 
+<a name="l00124"></a>00124 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00125"></a>00125 sinfo_get_strehl_input1(cpl_frame* frm1,
+<a name="l00126"></a>00126                 <span class="keywordtype">double</span>* dispersion,
+<a name="l00127"></a>00127                 <span class="keywordtype">double</span>* centralWave,
+<a name="l00128"></a>00128                 <span class="keywordtype">double</span>* ws,
+<a name="l00129"></a>00129                 <span class="keywordtype">double</span>* we,
+<a name="l00130"></a>00130                 <span class="keywordtype">double</span>* pscale,
+<a name="l00131"></a>00131                 <span class="keywordtype">double</span>* exptime,
+<a name="l00132"></a>00132             <span class="keywordtype">double</span>* strehl_star_rad,
+<a name="l00133"></a>00133                 <span class="keywordtype">double</span>* strehl_bg_rmin,
+<a name="l00134"></a>00134                 <span class="keywordtype">double</span>* strehl_bg_rmax);
+<a name="l00135"></a>00135 
+<a name="l00136"></a>00136 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00137"></a>00137 sinfo_get_strehl_input2(cpl_frame* frm1,cpl_frame* frm2,
+<a name="l00138"></a>00138                <span class="keywordtype">double</span>* dispersion,
+<a name="l00139"></a>00139                <span class="keywordtype">double</span>* centralWave,
+<a name="l00140"></a>00140                <span class="keywordtype">double</span>* ws,
+<a name="l00141"></a>00141                <span class="keywordtype">double</span>* we,
+<a name="l00142"></a>00142                <span class="keywordtype">double</span>* pscale1,
+<a name="l00143"></a>00143                <span class="keywordtype">double</span>* pscale2,
+<a name="l00144"></a>00144                <span class="keywordtype">double</span>* exptime1,
+<a name="l00145"></a>00145                <span class="keywordtype">double</span>* exptime2,
+<a name="l00146"></a>00146                <span class="keywordtype">double</span>* strehl_star_rad1,
+<a name="l00147"></a>00147                <span class="keywordtype">double</span>* strehl_star_rad2,
+<a name="l00148"></a>00148                <span class="keywordtype">double</span>* strehl_bg_rmin1,
+<a name="l00149"></a>00149                <span class="keywordtype">double</span>* strehl_bg_rmin2,
+<a name="l00150"></a>00150                <span class="keywordtype">double</span>* strehl_bg_rmax1,
+<a name="l00151"></a>00151                <span class="keywordtype">double</span>* strehl_bg_rmax2);
+<a name="l00152"></a>00152 
+<a name="l00153"></a>00153 
+<a name="l00154"></a>00154 <span class="keyword">static</span> <span class="keywordtype">void</span>
+<a name="l00155"></a>00155 sinfo_check_borders(cpl_size* val,<span class="keyword">const</span> <span class="keywordtype">int</span> max,<span class="keyword">const</span> <span class="keywordtype">int</span> thresh);
+<a name="l00156"></a>00156 
+<a name="l00157"></a>00157 <span class="keyword">static</span> <span class="keywordtype">void</span>
+<a name="l00158"></a>00158 sinfo_get_safe_box(<span class="keywordtype">int</span>* llx,
+<a name="l00159"></a>00159                    <span class="keywordtype">int</span>* lly,
+<a name="l00160"></a>00160                    <span class="keywordtype">int</span>* urx,
+<a name="l00161"></a>00161                    <span class="keywordtype">int</span>* ury,
+<a name="l00162"></a>00162                    <span class="keyword">const</span> <span class="keywordtype">int</span> xpos,
+<a name="l00163"></a>00163                    <span class="keyword">const</span> <span class="keywordtype">int</span> ypos,
+<a name="l00164"></a>00164                    <span class="keyword">const</span> <span class="keywordtype">int</span> box,
+<a name="l00165"></a>00165                    <span class="keyword">const</span> <span class="keywordtype">int</span> szx,
+<a name="l00166"></a>00166                    <span class="keyword">const</span> <span class="keywordtype">int</span> szy);
+<a name="l00167"></a>00167 
+<a name="l00168"></a>00168 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00169"></a>00169 sinfo_get_strehl_from_slice(cpl_imagelist* cube,
+<a name="l00170"></a>00170                             <span class="keywordtype">double</span> disp,
+<a name="l00171"></a>00171                             <span class="keywordtype">double</span> cWave,
+<a name="l00172"></a>00172                             <span class="keywordtype">double</span> ws,
+<a name="l00173"></a>00173                             <span class="keywordtype">double</span> we,
+<a name="l00174"></a>00174                             <span class="keywordtype">double</span> pscale,
+<a name="l00175"></a>00175                             <span class="keywordtype">double</span> strehl_star_radius,
+<a name="l00176"></a>00176                             <span class="keywordtype">double</span> strehl_bg_r1,
+<a name="l00177"></a>00177                             <span class="keywordtype">double</span> strehl_bg_r2,
+<a name="l00178"></a>00178                             <span class="keywordtype">double</span>* strehl,
+<a name="l00179"></a>00179                             <span class="keywordtype">double</span>* strehl_err);
+<a name="l00180"></a>00180 
+<a name="l00181"></a>00181 
+<a name="l00182"></a>00182 <span class="keyword">static</span> cpl_table*
+<a name="l00183"></a>00183 sinfo_get_encircled_energy(cpl_frameset* sof,
+<a name="l00184"></a>00184                            cpl_image* img,
+<a name="l00185"></a>00185                            <span class="keywordtype">double</span>* fwhm_x,
+<a name="l00186"></a>00186                <span class="keywordtype">double</span>* fwhm_y,
+<a name="l00187"></a>00187                            cpl_table** qclog);
+<a name="l00188"></a>00188 
+<a name="l00189"></a>00189 <span class="keyword">static</span> <span class="keywordtype">double</span>
+<a name="l00190"></a>00190 sinfo_get_strehl_from_ima(cpl_image* ima,
+<a name="l00191"></a>00191                           cpl_frame* frame);
+<a name="l00192"></a>00192 
+<a name="l00193"></a>00193 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00194"></a>00194 sinfo_get_strehl_from_image(cpl_image* img,
+<a name="l00195"></a>00195                             <span class="keywordtype">double</span> ws,
+<a name="l00196"></a>00196                             <span class="keywordtype">double</span> we,
+<a name="l00197"></a>00197                             <span class="keywordtype">double</span> pscale,
+<a name="l00198"></a>00198                             <span class="keywordtype">double</span> strehl_star_radius,
+<a name="l00199"></a>00199                             <span class="keywordtype">double</span> strehl_bg_r1,
+<a name="l00200"></a>00200                             <span class="keywordtype">double</span> strehl_bg_r2,
+<a name="l00201"></a>00201                             <span class="keywordtype">double</span>* strehl,
+<a name="l00202"></a>00202                 <span class="keywordtype">double</span>* strehl_err);
+<a name="l00203"></a>00203 
+<a name="l00204"></a>00204 
+<a name="l00205"></a>00205 
+<a name="l00206"></a>00206 <span class="keyword">static</span> cpl_table*
+<a name="l00207"></a>00207 sinfo_get_strehl_from_cube(cpl_imagelist* cube,
+<a name="l00208"></a>00208                            <span class="keywordtype">char</span>* name,
+<a name="l00209"></a>00209                            cpl_frame* frame);
+<a name="l00210"></a>00210 
+<a name="l00211"></a>00211 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00212"></a>00212 sinfo_get_frm12(cpl_frameset* sof,cpl_frame** frm1,cpl_frame** frm2);
+<a name="l00213"></a>00213 
+<a name="l00214"></a>00214 
+<a name="l00223"></a>00223 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00224"></a>00224 <span class="comment">   Function     :       sinfo_new_psf()</span>
+<a name="l00225"></a>00225 <span class="comment">   In           :       ini_file: file name of according .ini file</span>
+<a name="l00226"></a>00226 <span class="comment">   Out          :       integer (0 if it worked, -1 if it doesn't)</span>
+<a name="l00227"></a>00227 <span class="comment">   Job          :</span>
+<a name="l00228"></a>00228 <span class="comment"></span>
+<a name="l00229"></a>00229 <span class="comment"> sinfo_new_psf.py does the image reconstruction of a set of sky-subtracted,</span>
+<a name="l00230"></a>00230 <span class="comment"> flatfielded,</span>
+<a name="l00231"></a>00231 <span class="comment"> bad pixel corrected and slope of the spectra aligned exposures of a bright</span>
+<a name="l00232"></a>00232 <span class="comment"> star with continuum spectrum. The resulting image can be used to determine</span>
+<a name="l00233"></a>00233 <span class="comment"> the PSF</span>
+<a name="l00234"></a>00234 <span class="comment"></span>
+<a name="l00235"></a>00235 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00236"></a>00236 
+<a name="l00237"></a>00237 <span class="keywordtype">int</span>
+<a name="l00238"></a>00238 sinfo_new_psf (<span class="keyword">const</span> <span class="keywordtype">char</span>* plugin_id,
+<a name="l00239"></a>00239                cpl_parameterlist* config,
+<a name="l00240"></a>00240                cpl_frameset* sof, cpl_frameset* ref_set)
+<a name="l00241"></a>00241 {
+<a name="l00242"></a>00242 
+<a name="l00243"></a>00243   cpl_imagelist* cube1=NULL;
+<a name="l00244"></a>00244   cpl_imagelist* cube2=NULL;
+<a name="l00245"></a>00245   cpl_image * med_img1=NULL ;
+<a name="l00246"></a>00246   cpl_image * med_img2=NULL ;
+<a name="l00247"></a>00247 
+<a name="l00248"></a>00248   cpl_table* ao_performance=NULL;
+<a name="l00249"></a>00249   cpl_table* enc_energy=NULL;
+<a name="l00250"></a>00250 
+<a name="l00251"></a>00251   cpl_frame* frm1=NULL;
+<a name="l00252"></a>00252   cpl_frame* frm2=NULL;
+<a name="l00253"></a>00253 
+<a name="l00254"></a>00254   cpl_table* qclog_tbl=NULL;
+<a name="l00255"></a>00255   cpl_frameset* stk=NULL;
+<a name="l00256"></a>00256   cpl_propertylist* plist =NULL;
+<a name="l00257"></a>00257 
+<a name="l00258"></a>00258   psf_config * cfg =NULL;
+<a name="l00259"></a>00259 
+<a name="l00260"></a>00260   <span class="keywordtype">int</span> nsample=0;
+<a name="l00261"></a>00261   <span class="keywordtype">int</span> i = 0;
+<a name="l00262"></a>00262   <span class="keywordtype">int</span> status=0;
+<a name="l00263"></a>00263 
+<a name="l00264"></a>00264 
+<a name="l00265"></a>00265 
+<a name="l00266"></a>00266   <span class="keywordtype">int</span> strehl_sw=0;
+<a name="l00267"></a>00267   <span class="keywordtype">int</span> ilx1=0;
+<a name="l00268"></a>00268   <span class="keywordtype">int</span> ily1=0;
+<a name="l00269"></a>00269   <span class="keywordtype">int</span> ilx2=0;
+<a name="l00270"></a>00270   <span class="keywordtype">int</span> ily2=0;
+<a name="l00271"></a>00271 
+<a name="l00272"></a>00272   <span class="keywordtype">float</span> cx1=0;
+<a name="l00273"></a>00273   <span class="keywordtype">float</span> cy1=0;
+<a name="l00274"></a>00274   <span class="keywordtype">float</span> cx2=0;
+<a name="l00275"></a>00275   <span class="keywordtype">float</span> cy2=0;
+<a name="l00276"></a>00276 
+<a name="l00277"></a>00277   <span class="keywordtype">double</span> fwhm_x=0;
+<a name="l00278"></a>00278   <span class="keywordtype">double</span> fwhm_y=0;
+<a name="l00279"></a>00279   <span class="keywordtype">double</span> lam=0;
+<a name="l00280"></a>00280   <span class="keywordtype">double</span> strehl=0;
+<a name="l00281"></a>00281   <span class="keywordtype">double</span> strehl1=0;
+<a name="l00282"></a>00282   <span class="keywordtype">double</span> strehl2=0;
+<a name="l00283"></a>00283 
+<a name="l00284"></a>00284   <span class="keywordtype">char</span> fname1[MAX_NAME_SIZE];
+<a name="l00285"></a>00285   <span class="keywordtype">char</span> fname2[MAX_NAME_SIZE];
+<a name="l00286"></a>00286 
+<a name="l00287"></a>00287   <span class="keywordtype">char</span> key_name[MAX_NAME_SIZE];
+<a name="l00288"></a>00288 
+<a name="l00289"></a>00289   <span class="keywordtype">char</span> obs_name1[MAX_NAME_SIZE];
+<a name="l00290"></a>00290   <span class="keywordtype">char</span> hlamp_st=<span class="charliteral">'F'</span>;
+<a name="l00291"></a>00291   <span class="keywordtype">char</span> shut2_st=<span class="charliteral">'F'</span>;
+<a name="l00292"></a>00292   cpl_table* tmp_tbl=NULL;
+<a name="l00293"></a>00293 
+<a name="l00294"></a>00294 
+<a name="l00295"></a>00295   <span class="comment">/*</span>
+<a name="l00296"></a>00296 <span class="comment">       -----------------------------------------------------------------</span>
+<a name="l00297"></a>00297 <span class="comment">       1) parse the file names and parameters to the psf_config data</span>
+<a name="l00298"></a>00298 <span class="comment">          structure cfg</span>
+<a name="l00299"></a>00299 <span class="comment">       -----------------------------------------------------------------</span>
+<a name="l00300"></a>00300 <span class="comment">  */</span>
+<a name="l00301"></a>00301 
+<a name="l00302"></a>00302   sinfo_msg(<span class="stringliteral">"Parsing cpl input"</span>);
+<a name="l00303"></a>00303   check_nomsg(stk=cpl_frameset_new());
+<a name="l00304"></a>00304 
+<a name="l00305"></a>00305   cknull(cfg = sinfo_parse_cpl_input_psf(sof,&stk),
+<a name="l00306"></a>00306       <span class="stringliteral">"error parsing cpl input"</span>);
+<a name="l00307"></a>00307 
+<a name="l00308"></a>00308   <span class="comment">/* TODO the following generate a small leak of 72 bytes */</span>
+<a name="l00309"></a>00309   strehl_sw=sinfo_get_strehl_type(sof);
+<a name="l00310"></a>00310   <span class="keywordflow">if</span>(strehl_sw==0) {
+<a name="l00311"></a>00311     sinfo_msg(<span class="stringliteral">"One target Strehl computation"</span>);
+<a name="l00312"></a>00312     <span class="keywordflow">if</span>(sinfo_is_fits_file(cfg->inFrame) != 1) {
+<a name="l00313"></a>00313       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Input file %s is not FITS"</span>,cfg->inFrame);
+<a name="l00314"></a>00314       <span class="keywordflow">goto</span> cleanup;
+<a name="l00315"></a>00315     } <span class="keywordflow">else</span> {
+<a name="l00316"></a>00316       strcpy(fname1,cfg->inFrame);
+<a name="l00317"></a>00317     }
+<a name="l00318"></a>00318 
+<a name="l00319"></a>00319      <span class="keywordflow">if</span>(NULL != cpl_frameset_find(sof,PRO_COADD_PSF)) {
+<a name="l00320"></a>00320       frm1 = cpl_frameset_find(sof,PRO_COADD_PSF);
+<a name="l00321"></a>00321     } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(NULL != cpl_frameset_find(sof,PRO_OBS_PSF)) {
+<a name="l00322"></a>00322       frm1 = cpl_frameset_find(sof,PRO_OBS_PSF);
+<a name="l00323"></a>00323     } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(NULL != cpl_frameset_find(sof,PRO_COADD_STD)) {
+<a name="l00324"></a>00324       frm1 = cpl_frameset_find(sof,PRO_COADD_STD);
+<a name="l00325"></a>00325     } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(NULL != cpl_frameset_find(sof,PRO_OBS_STD)) {
+<a name="l00326"></a>00326       frm1 = cpl_frameset_find(sof,PRO_OBS_STD);
+<a name="l00327"></a>00327     } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(NULL != cpl_frameset_find(sof,PRO_COADD_OBJ)) {
+<a name="l00328"></a>00328       frm1 = cpl_frameset_find(sof,PRO_COADD_OBJ);
+<a name="l00329"></a>00329     } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(NULL != cpl_frameset_find(sof,PRO_OBS_OBJ)) {
+<a name="l00330"></a>00330       frm1 = cpl_frameset_find(sof,PRO_OBS_OBJ);
+<a name="l00331"></a>00331     } <span class="keywordflow">else</span> {
+<a name="l00332"></a>00332       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Frame %s  or %s or %s  or %s or %s  or %s not found!"</span>,
+<a name="l00333"></a>00333               PRO_COADD_PSF,PRO_OBS_PSF,
+<a name="l00334"></a>00334               PRO_COADD_STD,PRO_OBS_STD,
+<a name="l00335"></a>00335               PRO_COADD_OBJ,PRO_OBS_OBJ);
+<a name="l00336"></a>00336       <span class="keywordflow">goto</span> cleanup;
+<a name="l00337"></a>00337     }
+<a name="l00338"></a>00338 
+<a name="l00339"></a>00339     sinfo_get_obsname(frm1,obs_name1);
+<a name="l00340"></a>00340     check_nomsg(hlamp_st=sinfo_get_keyvalue_bool(frm1,KEY_NAME_LAMP_HALO));
+<a name="l00341"></a>00341     check_nomsg(shut2_st=sinfo_get_keyvalue_bool(frm1,KEY_NAME_SHUT2_ST));
+<a name="l00342"></a>00342 
+<a name="l00343"></a>00343 
+<a name="l00344"></a>00344     check_nomsg(cube1 = cpl_imagelist_load(fname1,CPL_TYPE_FLOAT,0));
+<a name="l00345"></a>00345     cknull(med_img1=sinfo_new_median_cube(cube1),
+<a name="l00346"></a>00346       <span class="stringliteral">" could not do sinfo_medianCube()"</span>);
+<a name="l00347"></a>00347 
+<a name="l00348"></a>00348     check_nomsg(ilx1=cpl_image_get_size_x(med_img1));
+<a name="l00349"></a>00349     check_nomsg(ily1=cpl_image_get_size_y(med_img1));
+<a name="l00350"></a>00350 
+<a name="l00351"></a>00351     cx1 = ilx1 / 2. + 0.5;
+<a name="l00352"></a>00352     cy1 = ily1 / 2. + 0.5;
+<a name="l00353"></a>00353 
+<a name="l00354"></a>00354     cknull(ao_performance=sinfo_get_strehl_from_cube(cube1,fname1,frm1),
+<a name="l00355"></a>00355        <span class="stringliteral">"error computing strehl"</span>);
+<a name="l00356"></a>00356     strehl=sinfo_get_strehl_from_ima(med_img1,frm1);
+<a name="l00357"></a>00357     sinfo_free_imagelist(&cube1);
+<a name="l00358"></a>00358   } <span class="keywordflow">else</span> {
+<a name="l00359"></a>00359     sinfo_msg(<span class="stringliteral">"Two target Strehl computation"</span>);
+<a name="l00360"></a>00360     sinfo_get_frm12(sof,&frm1,&frm2);
+<a name="l00361"></a>00361     strcpy(fname1,cpl_frame_get_filename(frm1));
+<a name="l00362"></a>00362     strcpy(fname2,cpl_frame_get_filename(frm2));
+<a name="l00363"></a>00363 
+<a name="l00364"></a>00364     check_nomsg(cube1 = cpl_imagelist_load(fname1,CPL_TYPE_FLOAT,0));
+<a name="l00365"></a>00365     check_nomsg(cube2 = cpl_imagelist_load(fname2,CPL_TYPE_FLOAT,0));
+<a name="l00366"></a>00366     cknull(med_img1=sinfo_new_median_cube(cube1),<span class="stringliteral">"Computing median on cube"</span>);
+<a name="l00367"></a>00367     cknull(med_img2=sinfo_new_median_cube(cube2),<span class="stringliteral">"Computing median on cube"</span>);
+<a name="l00368"></a>00368     check_nomsg(cpl_image_save(med_img1,<span class="stringliteral">"med_img1.fits"</span>,CPL_BPP_IEEE_FLOAT,
+<a name="l00369"></a>00369                    NULL,CPL_IO_DEFAULT));
+<a name="l00370"></a>00370     check_nomsg(cpl_image_save(med_img2,<span class="stringliteral">"med_img2.fits"</span>,CPL_BPP_IEEE_FLOAT,
+<a name="l00371"></a>00371                    NULL,CPL_IO_DEFAULT));
+<a name="l00372"></a>00372 
+<a name="l00373"></a>00373 
+<a name="l00374"></a>00374     check_nomsg(ilx1=cpl_image_get_size_x(med_img1));
+<a name="l00375"></a>00375     check_nomsg(ily1=cpl_image_get_size_y(med_img1));
+<a name="l00376"></a>00376     check_nomsg(ilx2=cpl_image_get_size_x(med_img2));
+<a name="l00377"></a>00377     check_nomsg(ily2=cpl_image_get_size_y(med_img2));
+<a name="l00378"></a>00378 
+<a name="l00379"></a>00379     cx1 = ilx1 / 2. + 0.5;
+<a name="l00380"></a>00380     cy1 = ily1 / 2. + 0.5;
+<a name="l00381"></a>00381     cx2 = ilx2 / 2. + 0.5;
+<a name="l00382"></a>00382     cy2 = ily2 / 2. + 0.5;
+<a name="l00383"></a>00383 
+<a name="l00384"></a>00384 
+<a name="l00385"></a>00385     sinfo_free_imagelist(&cube1);
+<a name="l00386"></a>00386     sinfo_free_imagelist(&cube2);
+<a name="l00387"></a>00387 
+<a name="l00388"></a>00388     cknull(tmp_tbl=sinfo_get_strehl_from_2images(med_img1,med_img2,frm1,frm2),
+<a name="l00389"></a>00389        <span class="stringliteral">"Computing strehl"</span>);
+<a name="l00390"></a>00390     check_nomsg(strehl=cpl_table_get_double(tmp_tbl,<span class="stringliteral">"strehl"</span>,0,&status));
+<a name="l00391"></a>00391     sinfo_free_table(&tmp_tbl);
+<a name="l00392"></a>00392     strehl1=sinfo_get_strehl_from_ima(med_img1,frm1);
+<a name="l00393"></a>00393     <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"Strehl on 1st image=%f"</span>,strehl);
+<a name="l00394"></a>00394     strehl2=sinfo_get_strehl_from_ima(med_img2,frm2);
+<a name="l00395"></a>00395     <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"Strehl on 2nd image=%f"</span>,strehl);
+<a name="l00396"></a>00396 
+<a name="l00397"></a>00397     cknull_nomsg(qclog_tbl = sinfo_qclog_init());
+<a name="l00398"></a>00398     check_nomsg(sinfo_add_com_psf_qclog(fname1,&qclog_tbl));
+<a name="l00399"></a>00399     <span class="keywordflow">if</span>(<a class="code" href="group__irplib__utils.html#ga804bfc739b5d55f9797ab881b1034ae4" title="portable isnan">irplib_isnan</a>(strehl1)) strehl1=-100.;
+<a name="l00400"></a>00400     ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,<span class="stringliteral">"QC STREHL025"</span>,strehl1,
+<a name="l00401"></a>00401             <span class="stringliteral">"STREHL 25 mas"</span>,<span class="stringliteral">"%f"</span>));
+<a name="l00402"></a>00402     ck0(sinfo_pro_save_ima(med_img1,ref_set,sof,PSF_MED_CUB_025_FILENAME,
+<a name="l00403"></a>00403                PRO_MED_COADD_PSF,qclog_tbl,plugin_id,config),
+<a name="l00404"></a>00404     <span class="stringliteral">"cannot save ima %s"</span>, PSF_MED_CUB_100_FILENAME);
+<a name="l00405"></a>00405     sinfo_free_table(&qclog_tbl);
+<a name="l00406"></a>00406 
+<a name="l00407"></a>00407 
+<a name="l00408"></a>00408     cknull_nomsg(qclog_tbl = sinfo_qclog_init());
+<a name="l00409"></a>00409     check_nomsg(sinfo_add_com_psf_qclog(fname2,&qclog_tbl));
+<a name="l00410"></a>00410     <span class="keywordflow">if</span>(<a class="code" href="group__irplib__utils.html#ga804bfc739b5d55f9797ab881b1034ae4" title="portable isnan">irplib_isnan</a>(strehl2)) strehl2=-100.;
+<a name="l00411"></a>00411     ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,<span class="stringliteral">"QC STREHL100"</span>,strehl2,
+<a name="l00412"></a>00412             <span class="stringliteral">"STREHL 100 mas"</span>,<span class="stringliteral">"%f"</span>));
+<a name="l00413"></a>00413 
+<a name="l00414"></a>00414     <span class="keywordflow">if</span>(<a class="code" href="group__irplib__utils.html#ga804bfc739b5d55f9797ab881b1034ae4" title="portable isnan">irplib_isnan</a>(strehl)) strehl=-100.;
+<a name="l00415"></a>00415 
+<a name="l00416"></a>00416     ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,<span class="stringliteral">"QC STREHL"</span>,strehl,
+<a name="l00417"></a>00417             <span class="stringliteral">"STREHL from both pixel scale images"</span>,<span class="stringliteral">"%f"</span>));
+<a name="l00418"></a>00418     ck0(sinfo_pro_save_ima(med_img2,ref_set,sof,PSF_MED_CUB_100_FILENAME,
+<a name="l00419"></a>00419                PRO_MED_COADD_PSF,qclog_tbl,plugin_id,config),
+<a name="l00420"></a>00420     <span class="stringliteral">"cannot save ima %s"</span>, PSF_MED_CUB_100_FILENAME);
+<a name="l00421"></a>00421 
+<a name="l00422"></a>00422     sinfo_free_table(&qclog_tbl);
+<a name="l00423"></a>00423     sinfo_free_image(&med_img2);
+<a name="l00424"></a>00424 
+<a name="l00425"></a>00425   }
+<a name="l00426"></a>00426   <span class="comment">/* STREHL computation */</span>
+<a name="l00427"></a>00427 
+<a name="l00428"></a>00428   check_nomsg(nsample=cpl_table_get_nrow(ao_performance));
+<a name="l00429"></a>00429   cknull_nomsg(qclog_tbl = sinfo_qclog_init());
+<a name="l00430"></a>00430   check_nomsg(sinfo_add_com_psf_qclog(fname1,&qclog_tbl));
+<a name="l00431"></a>00431 
+<a name="l00432"></a>00432   <span class="keywordflow">if</span>(strehl_sw==0) {
+<a name="l00433"></a>00433     <span class="keywordflow">if</span>(<a class="code" href="group__irplib__utils.html#ga804bfc739b5d55f9797ab881b1034ae4" title="portable isnan">irplib_isnan</a>(strehl)) strehl=-100.;
+<a name="l00434"></a>00434 
+<a name="l00435"></a>00435   ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,<span class="stringliteral">"QC STREHL"</span>,strehl,
+<a name="l00436"></a>00436             <span class="stringliteral">"STREHL from image"</span>,<span class="stringliteral">"%f"</span>));
+<a name="l00437"></a>00437 
+<a name="l00438"></a>00438   }
+<a name="l00439"></a>00439 
+<a name="l00440"></a>00440   check_nomsg(strehl=cpl_table_get_column_median(ao_performance,<span class="stringliteral">"strehl"</span>));
+<a name="l00441"></a>00441 
+<a name="l00442"></a>00442   ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,<span class="stringliteral">"QC STREHL MED"</span>,strehl,
+<a name="l00443"></a>00443             <span class="stringliteral">"STREHL MEDIAN"</span>,<span class="stringliteral">"%f"</span>));
+<a name="l00444"></a>00444 
+<a name="l00445"></a>00445   check_nomsg(strehl=cpl_table_get_column_mean(ao_performance,<span class="stringliteral">"strehl"</span>));
+<a name="l00446"></a>00446 
+<a name="l00447"></a>00447   ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,<span class="stringliteral">"QC STREHL AVG"</span>,strehl,
+<a name="l00448"></a>00448             <span class="stringliteral">"STREHL AVERAGE"</span>,<span class="stringliteral">"%f"</span>));
+<a name="l00449"></a>00449   <span class="comment">/*</span>
+<a name="l00450"></a>00450 <span class="comment">  strehl=sinfo_get_strehl_from_ima(med_img1,frm1);</span>
+<a name="l00451"></a>00451 <span class="comment"></span>
+<a name="l00452"></a>00452 <span class="comment">  ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC STREHL AVG",strehl,</span>
+<a name="l00453"></a>00453 <span class="comment">            "STREHL AVERAGE","%f"));</span>
+<a name="l00454"></a>00454 <span class="comment">  */</span>
+<a name="l00455"></a>00455   <span class="keywordflow">for</span>(i=1;i<nsample;i++) {
+<a name="l00456"></a>00456 
+<a name="l00457"></a>00457     check_nomsg(strehl=cpl_table_get_double(ao_performance,<span class="stringliteral">"strehl"</span>,
+<a name="l00458"></a>00458                                             i,&status));
+<a name="l00459"></a>00459     <span class="keywordflow">if</span>(<a class="code" href="group__irplib__utils.html#ga804bfc739b5d55f9797ab881b1034ae4" title="portable isnan">irplib_isnan</a>(strehl)) strehl=-100.;
+<a name="l00460"></a>00460 
+<a name="l00461"></a>00461     snprintf(key_name,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%d"</span>,<span class="stringliteral">"QC STREHL"</span>,i);
+<a name="l00462"></a>00462     ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,key_name,strehl,<span class="stringliteral">"STREHL"</span>,<span class="stringliteral">"%f"</span>));
+<a name="l00463"></a>00463 
+<a name="l00464"></a>00464     check_nomsg(lam=cpl_table_get_double(ao_performance,<span class="stringliteral">"wavelength"</span>,
+<a name="l00465"></a>00465                                          i,&status));
+<a name="l00466"></a>00466     snprintf(key_name,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%d"</span>,<span class="stringliteral">"QC LAMBDA"</span>,i);
+<a name="l00467"></a>00467     ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,key_name,lam,
+<a name="l00468"></a>00468                                      <span class="stringliteral">"WAVELENGTH"</span>,<span class="stringliteral">"%f"</span>));
+<a name="l00469"></a>00469 
+<a name="l00470"></a>00470   }
+<a name="l00471"></a>00471 
+<a name="l00472"></a>00472   check_nomsg(strehl=cpl_table_get_column_median(ao_performance,
+<a name="l00473"></a>00473                                                  <span class="stringliteral">"strehl_error"</span>));
+<a name="l00474"></a>00474   ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,<span class="stringliteral">"QC STREHL MEDERR"</span>,strehl,
+<a name="l00475"></a>00475                                    <span class="stringliteral">"STREHL ERROR MEDIAN"</span>,<span class="stringliteral">"%f"</span>));
+<a name="l00476"></a>00476   ck0_nomsg(sinfo_qclog_add_string(qclog_tbl,<span class="stringliteral">"OBS NAME"</span>,obs_name1,
+<a name="l00477"></a>00477                                    <span class="stringliteral">"OB name"</span>,<span class="stringliteral">"%s"</span>));
+<a name="l00478"></a>00478   ck0_nomsg(sinfo_qclog_add_bool(qclog_tbl,PAF_NAME_LAMP_HALO,hlamp_st,
+<a name="l00479"></a>00479                                   KEY_NAME_LAMP_HALO,<span class="stringliteral">"%d"</span>));
+<a name="l00480"></a>00480   ck0_nomsg(sinfo_qclog_add_bool(qclog_tbl,PAF_NAME_SHUT2_ST,shut2_st,
+<a name="l00481"></a>00481                                   KEY_NAME_SHUT2_ST,<span class="stringliteral">"%d"</span>));
+<a name="l00482"></a>00482 
+<a name="l00483"></a>00483   ck0(sinfo_pro_save_tbl(ao_performance,ref_set,sof,
+<a name="l00484"></a>00484                   PSF_AO_PERFORMANCE_OUT_FILENAME,
+<a name="l00485"></a>00485              PRO_AO_PERFORMANCE,qclog_tbl,plugin_id,config),
+<a name="l00486"></a>00486     <span class="stringliteral">"cannot save tbl %s"</span>, PSF_AO_PERFORMANCE_OUT_FILENAME);
+<a name="l00487"></a>00487 
+<a name="l00488"></a>00488   sinfo_free_table(&qclog_tbl);
+<a name="l00489"></a>00489   sinfo_free_table(&ao_performance);
+<a name="l00490"></a>00490 
+<a name="l00491"></a>00491   <span class="comment">/* Encircled energy & FWHM computation */</span>
+<a name="l00492"></a>00492   cknull_nomsg(qclog_tbl=sinfo_qclog_init());
+<a name="l00493"></a>00493   cknull(enc_energy=sinfo_get_encircled_energy(sof,
+<a name="l00494"></a>00494                            med_img1,
+<a name="l00495"></a>00495                            &fwhm_x,
+<a name="l00496"></a>00496                            &fwhm_y,
+<a name="l00497"></a>00497                            &qclog_tbl),
+<a name="l00498"></a>00498            <span class="stringliteral">"Computing encircled energy"</span>);
+<a name="l00499"></a>00499 
+<a name="l00500"></a>00500   ck0(sinfo_pro_save_tbl(enc_energy,ref_set,sof,PSF_ENC_ENERGY_OUT_FILENAME,
+<a name="l00501"></a>00501              PRO_ENC_ENERGY,qclog_tbl,plugin_id,config),
+<a name="l00502"></a>00502       <span class="stringliteral">"cannot save tbl %s"</span>, PSF_ENC_ENERGY_OUT_FILENAME);
+<a name="l00503"></a>00503 
+<a name="l00504"></a>00504   sinfo_free_table(&qclog_tbl);
+<a name="l00505"></a>00505   sinfo_free_table(&enc_energy);
+<a name="l00506"></a>00506 
+<a name="l00507"></a>00507   <span class="comment">/* QC log */</span>
+<a name="l00508"></a>00508   cknull_nomsg(qclog_tbl = sinfo_qclog_init());
+<a name="l00509"></a>00509   ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,<span class="stringliteral">"QC FWHMX"</span>,fwhm_x,
+<a name="l00510"></a>00510                                    <span class="stringliteral">"QC FWHM X"</span>,<span class="stringliteral">"%f"</span>));
+<a name="l00511"></a>00511   ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,<span class="stringliteral">"QC FWHMY"</span>,fwhm_y,
+<a name="l00512"></a>00512                                    <span class="stringliteral">"QC FWHM Y"</span>,<span class="stringliteral">"%f"</span>));
+<a name="l00513"></a>00513   ck0_nomsg(sinfo_qclog_add_bool(qclog_tbl,PAF_NAME_LAMP_HALO,
+<a name="l00514"></a>00514                                  hlamp_st,KEY_NAME_LAMP_HALO,<span class="stringliteral">"%d"</span>));
+<a name="l00515"></a>00515   ck0_nomsg(sinfo_qclog_add_bool(qclog_tbl,PAF_NAME_SHUT2_ST,shut2_st,
+<a name="l00516"></a>00516                                  KEY_NAME_SHUT2_ST,<span class="stringliteral">"%d"</span>));
+<a name="l00517"></a>00517 
+<a name="l00518"></a>00518   ck0(sinfo_pro_save_ima(med_img1,ref_set,sof,cfg->outName,PRO_PSF,
+<a name="l00519"></a>00519              qclog_tbl,plugin_id,config),
+<a name="l00520"></a>00520       <span class="stringliteral">"cannot save ima %s"</span>, cfg->outName);
+<a name="l00521"></a>00521 
+<a name="l00522"></a>00522   sinfo_free_table(&qclog_tbl);
+<a name="l00523"></a>00523   sinfo_new_set_wcs_image(med_img1,cfg->outName,cx1, cy1);
+<a name="l00524"></a>00524   sinfo_free_image(&med_img1);
+<a name="l00525"></a>00525   sinfo_free_frameset(&stk);
+<a name="l00526"></a>00526   sinfo_free_psf(&cfg);
+<a name="l00527"></a>00527   <span class="keywordflow">return</span> 0;
+<a name="l00528"></a>00528 
+<a name="l00529"></a>00529  cleanup:
+<a name="l00530"></a>00530 
+<a name="l00531"></a>00531   sinfo_free_table(&qclog_tbl);
+<a name="l00532"></a>00532   sinfo_free_imagelist(&cube2);
+<a name="l00533"></a>00533   sinfo_free_imagelist(&cube1);
+<a name="l00534"></a>00534   sinfo_free_table(&enc_energy);
+<a name="l00535"></a>00535   sinfo_free_image(&med_img1);
+<a name="l00536"></a>00536   sinfo_free_table(&ao_performance);
+<a name="l00537"></a>00537   sinfo_free_propertylist(&plist) ;
+<a name="l00538"></a>00538   sinfo_free_psf(&cfg);
+<a name="l00539"></a>00539   sinfo_free_frameset(&stk);
+<a name="l00540"></a>00540 
+<a name="l00541"></a>00541   <span class="keywordflow">return</span> -1 ;
+<a name="l00542"></a>00542 
+<a name="l00543"></a>00543 }
+<a name="l00544"></a>00544 
+<a name="l00545"></a>00545 
+<a name="l00546"></a>00546 
+<a name="l00547"></a>00547 
+<a name="l00548"></a>00548 <span class="keyword">static</span> cpl_error_code
+<a name="l00549"></a>00549 sinfo_add_com_psf_qclog(<span class="keyword">const</span> <span class="keywordtype">char</span>* fname,cpl_table** qclog_tbl)
+<a name="l00550"></a>00550 {
+<a name="l00551"></a>00551 
+<a name="l00552"></a>00552   cpl_propertylist* plist=NULL;
+<a name="l00553"></a>00553 
+<a name="l00554"></a>00554   <span class="comment">/* QC log */</span>
+<a name="l00555"></a>00555   cknull(plist = cpl_propertylist_load(fname, 0),
+<a name="l00556"></a>00556      <span class="stringliteral">"getting header from reference ima frame %s"</span>,fname);
+<a name="l00557"></a>00557 
+<a name="l00558"></a>00558   <span class="keywordflow">if</span> (sinfo_propertylist_has(plist, KEY_NAME_LOOP_STATE)) {
+<a name="l00559"></a>00559     sinfo_qclog_add_string(*qclog_tbl,KEY_NAME_LOOP_STATE,
+<a name="l00560"></a>00560                       cpl_propertylist_get_string(plist,KEY_NAME_LOOP_STATE),
+<a name="l00561"></a>00561                       KEY_HELP_LOOP_STATE,<span class="stringliteral">"%s"</span>);
+<a name="l00562"></a>00562   }
+<a name="l00563"></a>00563 
+<a name="l00564"></a>00564 
+<a name="l00565"></a>00565 
+<a name="l00566"></a>00566   <span class="keywordflow">if</span> (sinfo_propertylist_has(plist, KEY_NAME_LOOP_LGS)) {
+<a name="l00567"></a>00567     sinfo_qclog_add_int(*qclog_tbl,KEY_NAME_LOOP_LGS,
+<a name="l00568"></a>00568                       cpl_propertylist_get_int(plist,KEY_NAME_LOOP_LGS),
+<a name="l00569"></a>00569                       KEY_HELP_LOOP_LGS,<span class="stringliteral">"%d"</span>);
+<a name="l00570"></a>00570   }
+<a name="l00571"></a>00571 
+<a name="l00572"></a>00572 
+<a name="l00573"></a>00573   <span class="keywordflow">if</span> (sinfo_propertylist_has(plist, KEY_NAME_INS1_MODE)) {
+<a name="l00574"></a>00574     sinfo_qclog_add_string(*qclog_tbl,KEY_NAME_INS1_MODE,
+<a name="l00575"></a>00575                       cpl_propertylist_get_string(plist,KEY_NAME_INS1_MODE),
+<a name="l00576"></a>00576                       KEY_HELP_INS1_MODE,<span class="stringliteral">"%s"</span>);
+<a name="l00577"></a>00577   }
+<a name="l00578"></a>00578 
+<a name="l00579"></a>00579 
+<a name="l00580"></a>00580  cleanup:
+<a name="l00581"></a>00581   sinfo_free_propertylist(&plist);
+<a name="l00582"></a>00582 
+<a name="l00583"></a>00583   <span class="keywordflow">if</span> (cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l00584"></a>00584     <span class="keywordflow">return</span> cpl_error_get_code();
+<a name="l00585"></a>00585   } <span class="keywordflow">else</span> {
+<a name="l00586"></a>00586     <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l00587"></a>00587   }
+<a name="l00588"></a>00588 
+<a name="l00589"></a>00589 
+<a name="l00590"></a>00590 }
+<a name="l00591"></a>00591 
+<a name="l00592"></a>00592 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00593"></a>00593 sinfo_get_strehl_from_image(cpl_image* img,
+<a name="l00594"></a>00594                             <span class="keywordtype">double</span> ws,
+<a name="l00595"></a>00595                             <span class="keywordtype">double</span> we,
+<a name="l00596"></a>00596                             <span class="keywordtype">double</span> pscale,
+<a name="l00597"></a>00597                             <span class="keywordtype">double</span> strehl_star_radius,
+<a name="l00598"></a>00598                             <span class="keywordtype">double</span> strehl_bg_r1,
+<a name="l00599"></a>00599                             <span class="keywordtype">double</span> strehl_bg_r2,
+<a name="l00600"></a>00600                             <span class="keywordtype">double</span>* strehl,
+<a name="l00601"></a>00601                             <span class="keywordtype">double</span>* strehl_err)
+<a name="l00602"></a>00602 {
+<a name="l00603"></a>00603   cpl_errorstate clean_state = cpl_errorstate_get();
+<a name="l00604"></a>00604 
+<a name="l00605"></a>00605   cpl_image* img_dup=NULL;
+<a name="l00606"></a>00606 
+<a name="l00607"></a>00607   <span class="keywordtype">double</span> dlam=0.;
+<a name="l00608"></a>00608   <span class="keywordtype">double</span> lam=0.;
+<a name="l00609"></a>00609 
+<a name="l00610"></a>00610   <span class="keywordtype">double</span> max_ima_cx=0.;
+<a name="l00611"></a>00611   <span class="keywordtype">double</span> max_ima_cy=0.;
+<a name="l00612"></a>00612 
+<a name="l00613"></a>00613   <span class="keywordtype">double</span> psf_peak=0.;
+<a name="l00614"></a>00614   <span class="keywordtype">double</span> psf_flux=0.;
+<a name="l00615"></a>00615   <span class="keywordtype">double</span> bkg_noise=0.;
+<a name="l00616"></a>00616   <span class="keywordtype">double</span> star_bkg=0.;
+<a name="l00617"></a>00617   <span class="keywordtype">double</span> star_peak=0.;
+<a name="l00618"></a>00618   <span class="keywordtype">double</span> star_flux=0.;
+<a name="l00619"></a>00619 
+<a name="l00620"></a>00620   cpl_size max_ima_x=0;
+<a name="l00621"></a>00621   cpl_size max_ima_y=0;
+<a name="l00622"></a>00622   <span class="keywordtype">int</span> wllx=0;
+<a name="l00623"></a>00623   <span class="keywordtype">int</span> wlly=0;
+<a name="l00624"></a>00624   <span class="keywordtype">int</span> wurx=0;
+<a name="l00625"></a>00625   <span class="keywordtype">int</span> wury=0;
+<a name="l00626"></a>00626   <span class="keywordtype">int</span> ima_szx=0;
+<a name="l00627"></a>00627   <span class="keywordtype">int</span> ima_szy=0;
+<a name="l00628"></a>00628 
+<a name="l00629"></a>00629 
+<a name="l00630"></a>00630   lam = (double)0.5*(ws+we);
+<a name="l00631"></a>00631   dlam=we-ws;
+<a name="l00632"></a>00632   <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"ws=%f we=%f dl=%f"</span>,ws,we,dlam);
+<a name="l00633"></a>00633   check_nomsg(img_dup=cpl_image_duplicate(img));
+<a name="l00634"></a>00634   sinfo_clean_nan(&img_dup);
+<a name="l00635"></a>00635   check_nomsg(cpl_image_get_maxpos(img_dup,&max_ima_x,&max_ima_y));
+<a name="l00636"></a>00636   sinfo_free_image(&img_dup);
+<a name="l00637"></a>00637 
+<a name="l00638"></a>00638   check_nomsg(ima_szx=cpl_image_get_size_x(img));
+<a name="l00639"></a>00639   check_nomsg(ima_szy=cpl_image_get_size_y(img));
+<a name="l00640"></a>00640   sinfo_check_borders(&max_ima_x,ima_szx,SINFO_STREHL_WINDOW);
+<a name="l00641"></a>00641   sinfo_check_borders(&max_ima_y,ima_szy,SINFO_STREHL_WINDOW);
+<a name="l00642"></a>00642   sinfo_get_safe_box(&wllx,&wlly,&wurx,&wury,max_ima_x,max_ima_y,SINFO_PSF_SZ,
+<a name="l00643"></a>00643   ima_szx,ima_szy);
+<a name="l00644"></a>00644 
+<a name="l00645"></a>00645   <span class="comment">//cpl_image_get_maxpos_window(img,wllx,wlly,wurx,wury,&max_ima_x,&max_ima_y);</span>
+<a name="l00646"></a>00646 
+<a name="l00647"></a>00647   check_nomsg(max_ima_cx=cpl_image_get_centroid_x_window(img,wllx,wlly,
+<a name="l00648"></a>00648                                                          wurx,wury));
+<a name="l00649"></a>00649   check_nomsg(max_ima_cy=cpl_image_get_centroid_y_window(img,wllx,wlly,
+<a name="l00650"></a>00650   wurx,wury));
+<a name="l00651"></a>00651 
+<a name="l00652"></a>00652 
+<a name="l00653"></a>00653   <span class="keywordflow">if</span>(CPL_ERROR_NONE != sinfo_strehl_compute_one(img,
+<a name="l00654"></a>00654                         SINFO_STREHL_M1,
+<a name="l00655"></a>00655                         SINFO_STREHL_M2,
+<a name="l00656"></a>00656                         lam,
+<a name="l00657"></a>00657                         dlam,
+<a name="l00658"></a>00658                         pscale,
+<a name="l00659"></a>00659                         max_ima_x,
+<a name="l00660"></a>00660                         max_ima_y,
+<a name="l00661"></a>00661                         strehl_star_radius,
+<a name="l00662"></a>00662                         strehl_bg_r1,
+<a name="l00663"></a>00663                         strehl_bg_r2,
+<a name="l00664"></a>00664                         SINFO_STREHL_BOX_SIZE,
+<a name="l00665"></a>00665                         strehl,
+<a name="l00666"></a>00666                         strehl_err,
+<a name="l00667"></a>00667                         &star_bkg,
+<a name="l00668"></a>00668                         &star_peak,
+<a name="l00669"></a>00669                         &star_flux,
+<a name="l00670"></a>00670                         &psf_peak,
+<a name="l00671"></a>00671                         &psf_flux,
+<a name="l00672"></a>00672                         &bkg_noise)) {
+<a name="l00673"></a>00673 
+<a name="l00674"></a>00674 
+<a name="l00675"></a>00675     *strehl=-1;
+<a name="l00676"></a>00676     *strehl_err=0;
+<a name="l00677"></a>00677     irplib_error_recover(clean_state,<span class="stringliteral">"Problem computing strehl"</span>);
+<a name="l00678"></a>00678 
+<a name="l00679"></a>00679   }
+<a name="l00680"></a>00680 
+<a name="l00681"></a>00681   <span class="keywordflow">return</span> 0;
+<a name="l00682"></a>00682 
+<a name="l00683"></a>00683  cleanup:
+<a name="l00684"></a>00684 
+<a name="l00685"></a>00685   <span class="keywordflow">return</span> -1;
+<a name="l00686"></a>00686 
+<a name="l00687"></a>00687 }
+<a name="l00688"></a>00688 
+<a name="l00689"></a>00689 
+<a name="l00690"></a>00690 
+<a name="l00691"></a>00691 
+<a name="l00692"></a>00692 
+<a name="l00693"></a>00693 
+<a name="l00694"></a>00694 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00695"></a>00695 sinfo_get_strehl_from_slice(cpl_imagelist* cube,
+<a name="l00696"></a>00696                             <span class="keywordtype">double</span> disp,
+<a name="l00697"></a>00697                             <span class="keywordtype">double</span> cWave,
+<a name="l00698"></a>00698                             <span class="keywordtype">double</span> ws,
+<a name="l00699"></a>00699                             <span class="keywordtype">double</span> we,
+<a name="l00700"></a>00700                             <span class="keywordtype">double</span> pscale,
+<a name="l00701"></a>00701                             <span class="keywordtype">double</span> strehl_star_radius,
+<a name="l00702"></a>00702                             <span class="keywordtype">double</span> strehl_bg_r1,
+<a name="l00703"></a>00703                             <span class="keywordtype">double</span> strehl_bg_r2,
+<a name="l00704"></a>00704                             <span class="keywordtype">double</span>* strehl,
+<a name="l00705"></a>00705                             <span class="keywordtype">double</span>* strehl_err)
+<a name="l00706"></a>00706 {
+<a name="l00707"></a>00707 
+<a name="l00708"></a>00708 
+<a name="l00709"></a>00709   cpl_errorstate clean_state = cpl_errorstate_get();
+<a name="l00710"></a>00710 
+<a name="l00711"></a>00711 
+<a name="l00712"></a>00712   cpl_image* img_dup=NULL;
+<a name="l00713"></a>00713   cpl_image* img=NULL;
+<a name="l00714"></a>00714 
+<a name="l00715"></a>00715   <span class="keywordtype">double</span> dlam=0.;
+<a name="l00716"></a>00716   <span class="keywordtype">double</span> lam=0.;
+<a name="l00717"></a>00717 
+<a name="l00718"></a>00718   <span class="keywordtype">double</span> max_ima_cx=0.;
+<a name="l00719"></a>00719   <span class="keywordtype">double</span> max_ima_cy=0.;
+<a name="l00720"></a>00720   <span class="keywordtype">double</span> psf_peak=0.;
+<a name="l00721"></a>00721   <span class="keywordtype">double</span> psf_flux=0.;
+<a name="l00722"></a>00722   <span class="keywordtype">double</span> bkg_noise=0.;
+<a name="l00723"></a>00723   <span class="keywordtype">double</span> star_bkg=0.;
+<a name="l00724"></a>00724   <span class="keywordtype">double</span> star_peak=0.;
+<a name="l00725"></a>00725   <span class="keywordtype">double</span> star_flux=0.;
+<a name="l00726"></a>00726 
+<a name="l00727"></a>00727   cpl_size max_ima_x=0;
+<a name="l00728"></a>00728   cpl_size max_ima_y=0;
+<a name="l00729"></a>00729   <span class="keywordtype">int</span> wllx=0;
+<a name="l00730"></a>00730   <span class="keywordtype">int</span> wlly=0;
+<a name="l00731"></a>00731   <span class="keywordtype">int</span> wurx=0;
+<a name="l00732"></a>00732   <span class="keywordtype">int</span> wury=0;
+<a name="l00733"></a>00733   <span class="keywordtype">int</span> ima_szx=0;
+<a name="l00734"></a>00734   <span class="keywordtype">int</span> ima_szy=0;
+<a name="l00735"></a>00735 
+<a name="l00736"></a>00736 
+<a name="l00737"></a>00737   lam = (double)0.5*(ws+we);
+<a name="l00738"></a>00738   dlam=we-ws;
+<a name="l00739"></a>00739 
+<a name="l00740"></a>00740 
+<a name="l00741"></a>00741   img=sinfo_new_average_cube_to_image_between_waves(cube,disp,cWave,ws,we);
+<a name="l00742"></a>00742   check_nomsg(img_dup=cpl_image_duplicate(img));
+<a name="l00743"></a>00743   sinfo_clean_nan(&img_dup);
+<a name="l00744"></a>00744   check_nomsg(cpl_image_get_maxpos(img_dup,&max_ima_x,&max_ima_y));
+<a name="l00745"></a>00745   check_nomsg(cpl_image_delete(img_dup));
+<a name="l00746"></a>00746 
+<a name="l00747"></a>00747 
+<a name="l00748"></a>00748   check_nomsg(ima_szx=cpl_image_get_size_x(img));
+<a name="l00749"></a>00749   check_nomsg(ima_szy=cpl_image_get_size_y(img));
+<a name="l00750"></a>00750   sinfo_check_borders(&max_ima_x,ima_szx,SINFO_STREHL_WINDOW);
+<a name="l00751"></a>00751   sinfo_check_borders(&max_ima_y,ima_szy,SINFO_STREHL_WINDOW);
+<a name="l00752"></a>00752 
+<a name="l00753"></a>00753 
+<a name="l00754"></a>00754   sinfo_get_safe_box(&wllx,&wlly,&wurx,&wury,max_ima_x,max_ima_y,SINFO_PSF_SZ,
+<a name="l00755"></a>00755                                ima_szx,ima_szy);
+<a name="l00756"></a>00756 
+<a name="l00757"></a>00757   <span class="comment">/*</span>
+<a name="l00758"></a>00758 <span class="comment">  cpl_image_get_maxpos_window(img,wllx,wlly,wurx,wury,&max_ima_x,&max_ima_y);</span>
+<a name="l00759"></a>00759 <span class="comment">   */</span>
+<a name="l00760"></a>00760   check_nomsg(max_ima_cx=cpl_image_get_centroid_x_window(img,wllx,wlly,
+<a name="l00761"></a>00761                                                          wurx,wury));
+<a name="l00762"></a>00762 
+<a name="l00763"></a>00763 
+<a name="l00764"></a>00764 
+<a name="l00765"></a>00765   check_nomsg(max_ima_cy=cpl_image_get_centroid_y_window(img,wllx,wlly,
+<a name="l00766"></a>00766                                                          wurx,wury));
+<a name="l00767"></a>00767 
+<a name="l00768"></a>00768 
+<a name="l00769"></a>00769 
+<a name="l00770"></a>00770   <span class="keywordflow">if</span>(CPL_ERROR_NONE != irplib_strehl_mark_bad_and_compute(img,
+<a name="l00771"></a>00771                                              SINFO_STREHL_M1,
+<a name="l00772"></a>00772                                              SINFO_STREHL_M2,
+<a name="l00773"></a>00773                                              lam,
+<a name="l00774"></a>00774                                              dlam,
+<a name="l00775"></a>00775                                              pscale,
+<a name="l00776"></a>00776                                              SINFO_STREHL_BOX_SIZE,
+<a name="l00777"></a>00777                                              max_ima_x,
+<a name="l00778"></a>00778                                              max_ima_y,
+<a name="l00779"></a>00779                                              strehl_star_radius,
+<a name="l00780"></a>00780                                              strehl_bg_r1,
+<a name="l00781"></a>00781                                              strehl_bg_r2,
+<a name="l00782"></a>00782                                              NOISE_HSIZE,
+<a name="l00783"></a>00783                                              NOISE_NSAMPLES,
+<a name="l00784"></a>00784                                              strehl,
+<a name="l00785"></a>00785                                              strehl_err,
+<a name="l00786"></a>00786                                              &star_bkg,
+<a name="l00787"></a>00787                                              &star_peak,
+<a name="l00788"></a>00788                                              &star_flux,
+<a name="l00789"></a>00789                                              &psf_peak,
+<a name="l00790"></a>00790                                              &psf_flux,
+<a name="l00791"></a>00791                                              &bkg_noise)) {
+<a name="l00792"></a>00792 
+<a name="l00793"></a>00793 
+<a name="l00794"></a>00794      *strehl=-1;
+<a name="l00795"></a>00795      *strehl_err=0;
+<a name="l00796"></a>00796       irplib_error_recover(clean_state,<span class="stringliteral">"Problem computing strehl"</span>);
+<a name="l00797"></a>00797 
+<a name="l00798"></a>00798   }
+<a name="l00799"></a>00799 
+<a name="l00800"></a>00800   <span class="comment">/*</span>
+<a name="l00801"></a>00801 <span class="comment">  cpl_msg_info(__func__,"stehl=%f err=%f star_bkg=%f star_peak=%f star_flux=%f",</span>
+<a name="l00802"></a>00802 <span class="comment">                          *strehl,*strehl_err,star_bkg,star_peak,star_flux);</span>
+<a name="l00803"></a>00803 <span class="comment">  cpl_msg_info(__func__,"psf_peak=%f psf_flux=%f bkg_noise=%f",</span>
+<a name="l00804"></a>00804 <span class="comment">                         psf_peak,psf_flux,bkg_noise);</span>
+<a name="l00805"></a>00805 <span class="comment">  */</span>
+<a name="l00806"></a>00806   sinfo_free_image(&img);
+<a name="l00807"></a>00807 
+<a name="l00808"></a>00808 
+<a name="l00809"></a>00809   <span class="keywordflow">return</span> 0;
+<a name="l00810"></a>00810 
+<a name="l00811"></a>00811  cleanup:
+<a name="l00812"></a>00812   <span class="keywordflow">return</span> -1;
+<a name="l00813"></a>00813 
+<a name="l00814"></a>00814 }
+<a name="l00815"></a>00815 
+<a name="l00816"></a>00816 
+<a name="l00817"></a>00817 
+<a name="l00818"></a>00818 cpl_table* sinfo_get_encircled_energy(cpl_frameset* sof,
+<a name="l00819"></a>00819                                       cpl_image* img,
+<a name="l00820"></a>00820                                       <span class="keywordtype">double</span>* fwhm_x,
+<a name="l00821"></a>00821                                       <span class="keywordtype">double</span>* fwhm_y,
+<a name="l00822"></a>00822                                       cpl_table** qclog_tbl)
+<a name="l00823"></a>00823 {
+<a name="l00824"></a>00824 
+<a name="l00825"></a>00825   cpl_errorstate clean_state = cpl_errorstate_get();
+<a name="l00826"></a>00826 
+<a name="l00827"></a>00827   cpl_image* img_dup=NULL;
+<a name="l00828"></a>00828   cpl_size max_ima_x=0;
+<a name="l00829"></a>00829   cpl_size max_ima_y=0;
+<a name="l00830"></a>00830   <span class="keywordtype">int</span> wllx=0;
+<a name="l00831"></a>00831   <span class="keywordtype">int</span> wlly=0;
+<a name="l00832"></a>00832   <span class="keywordtype">int</span> wurx=0;
+<a name="l00833"></a>00833   <span class="keywordtype">int</span> wury=0;
+<a name="l00834"></a>00834   <span class="keyword">const</span> <span class="keywordtype">double</span> d_mirror = 8.;
+<a name="l00835"></a>00835   <span class="keyword">const</span> <span class="keywordtype">double</span> factor = 180/PI_NUMB*3600.;
+<a name="l00836"></a>00836   <span class="keywordtype">double</span> max_ima_cx=0;
+<a name="l00837"></a>00837   <span class="keywordtype">double</span> max_ima_cy=0;
+<a name="l00838"></a>00838 
+<a name="l00839"></a>00839   <span class="keywordtype">double</span> norm=0.;
+<a name="l00840"></a>00840   <span class="keywordtype">double</span> xc=0.;
+<a name="l00841"></a>00841   <span class="keywordtype">double</span> yc=0.;
+<a name="l00842"></a>00842   <span class="keywordtype">double</span> sx=0.;
+<a name="l00843"></a>00843   <span class="keywordtype">double</span> sy=0.;
+<a name="l00844"></a>00844 
+<a name="l00845"></a>00845   <span class="keywordtype">double</span> flux=0;
+<a name="l00846"></a>00846   <span class="keywordtype">double</span> flux_max=0;
+<a name="l00847"></a>00847   <span class="keywordtype">double</span> pix_scale=0;
+<a name="l00848"></a>00848   <span class="keywordtype">double</span> lam=0.;
+<a name="l00849"></a>00849   <span class="keywordtype">double</span> pscale=0.;
+<a name="l00850"></a>00850   <span class="keywordtype">int</span> dr_difr=0;
+<a name="l00851"></a>00851 
+<a name="l00852"></a>00852   <span class="keywordtype">double</span> r=0.;
+<a name="l00853"></a>00853   <span class="keywordtype">double</span> bkg=0.;
+<a name="l00854"></a>00854   <span class="keywordtype">int</span> i=0;
+<a name="l00855"></a>00855   <span class="keywordtype">int</span> ni=0;
+<a name="l00856"></a>00856   <span class="keywordtype">int</span> ir_difr=0;
+<a name="l00857"></a>00857   <span class="keywordtype">int</span> dr=0;
+<a name="l00858"></a>00858   <span class="keywordtype">int</span> rmin=0;
+<a name="l00859"></a>00859 
+<a name="l00860"></a>00860   <span class="keywordtype">char</span> band[MAX_NAME_SIZE];
+<a name="l00861"></a>00861   <span class="keywordtype">char</span> spat_res[MAX_NAME_SIZE];
+<a name="l00862"></a>00862 
+<a name="l00863"></a>00863   cpl_table* enc_energy=NULL;
+<a name="l00864"></a>00864   cpl_frame* frame=NULL;
+<a name="l00865"></a>00865 
+<a name="l00866"></a>00866   <span class="keywordtype">int</span> ima_szx=0;
+<a name="l00867"></a>00867   <span class="keywordtype">int</span> ima_szy=0;
+<a name="l00868"></a>00868 
+<a name="l00869"></a>00869 
+<a name="l00870"></a>00870 
+<a name="l00871"></a>00871   <span class="keywordflow">if</span>(NULL != cpl_frameset_find(sof,PRO_COADD_PSF)) {
+<a name="l00872"></a>00872     frame = cpl_frameset_find(sof,PRO_COADD_PSF);
+<a name="l00873"></a>00873   } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(NULL != cpl_frameset_find(sof,PRO_OBS_PSF)) {
+<a name="l00874"></a>00874     frame = cpl_frameset_find(sof,PRO_OBS_PSF);
+<a name="l00875"></a>00875   } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(NULL != cpl_frameset_find(sof,PRO_COADD_STD)) {
+<a name="l00876"></a>00876     frame = cpl_frameset_find(sof,PRO_COADD_STD);
+<a name="l00877"></a>00877   } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(NULL != cpl_frameset_find(sof,PRO_OBS_STD)) {
+<a name="l00878"></a>00878     frame = cpl_frameset_find(sof,PRO_OBS_STD);
+<a name="l00879"></a>00879   } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(NULL != cpl_frameset_find(sof,PRO_COADD_OBJ)) {
+<a name="l00880"></a>00880     frame = cpl_frameset_find(sof,PRO_COADD_OBJ);
+<a name="l00881"></a>00881   } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(NULL != cpl_frameset_find(sof,PRO_OBS_OBJ)) {
+<a name="l00882"></a>00882     frame = cpl_frameset_find(sof,PRO_OBS_OBJ);
+<a name="l00883"></a>00883   } <span class="keywordflow">else</span> {
+<a name="l00884"></a>00884     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Frame %s  or %s or  %s  or %s or %s  or %s not found!"</span>,
+<a name="l00885"></a>00885             PRO_COADD_PSF,PRO_OBS_PSF,
+<a name="l00886"></a>00886             PRO_COADD_STD, PRO_OBS_STD,
+<a name="l00887"></a>00887             PRO_COADD_OBJ, PRO_OBS_OBJ);
+<a name="l00888"></a>00888     <span class="keywordflow">return</span> NULL;
+<a name="l00889"></a>00889   }
+<a name="l00890"></a>00890 
+<a name="l00891"></a>00891   sinfo_get_spatial_res(frame,spat_res);
+<a name="l00892"></a>00892   sinfo_get_band(frame,band);
+<a name="l00893"></a>00893   pix_scale=atof(spat_res);
+<a name="l00894"></a>00894   lam=sinfo_get_wave_cent(band);
+<a name="l00895"></a>00895   <span class="comment">/* factor 2 due to change of detector to 2K */</span>
+<a name="l00896"></a>00896   pscale=0.5*pix_scale;
+<a name="l00897"></a>00897 
+<a name="l00898"></a>00898 
+<a name="l00899"></a>00899 
+<a name="l00900"></a>00900   dr_difr=factor*1.22*lam*1.e-6/d_mirror/pscale;
+<a name="l00901"></a>00901   ir_difr=floor(dr_difr+0.5);
+<a name="l00902"></a>00902   <span class="keywordflow">if</span> (pix_scale==0.025) {
+<a name="l00903"></a>00903     ni=10;
+<a name="l00904"></a>00904     rmin=ir_difr;
+<a name="l00905"></a>00905     dr=rmin;
+<a name="l00906"></a>00906   } <span class="keywordflow">else</span> {
+<a name="l00907"></a>00907     ni=15;
+<a name="l00908"></a>00908     <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"Reset diffraction limit"</span>);
+<a name="l00909"></a>00909     ir_difr=10;
+<a name="l00910"></a>00910     rmin=1;
+<a name="l00911"></a>00911     dr=2;
+<a name="l00912"></a>00912   }
+<a name="l00913"></a>00913 
+<a name="l00914"></a>00914   sinfo_msg(<span class="stringliteral">"Diffraction limit: %d"</span>,ir_difr);
+<a name="l00915"></a>00915 
+<a name="l00916"></a>00916   check_nomsg(img_dup=cpl_image_duplicate(img));
+<a name="l00917"></a>00917   sinfo_clean_nan(&img_dup);
+<a name="l00918"></a>00918   check_nomsg(cpl_image_get_maxpos(img_dup,&max_ima_x,&max_ima_y));
+<a name="l00919"></a>00919   sinfo_free_image(&img_dup);
+<a name="l00920"></a>00920 
+<a name="l00921"></a>00921 
+<a name="l00922"></a>00922 
+<a name="l00923"></a>00923   check_nomsg(ima_szx=cpl_image_get_size_x(img));
+<a name="l00924"></a>00924   check_nomsg(ima_szy=cpl_image_get_size_y(img));
+<a name="l00925"></a>00925   sinfo_check_borders(&max_ima_x,ima_szx,SINFO_STREHL_WINDOW);
+<a name="l00926"></a>00926   sinfo_check_borders(&max_ima_y,ima_szy,SINFO_STREHL_WINDOW);
+<a name="l00927"></a>00927   sinfo_get_safe_box(&wllx,&wlly,&wurx,&wury,max_ima_x,max_ima_y,SINFO_PSF_SZ,
+<a name="l00928"></a>00928                                ima_szx,ima_szy);
+<a name="l00929"></a>00929 
+<a name="l00930"></a>00930   check_nomsg(max_ima_cx=cpl_image_get_centroid_x_window(img,wllx,wlly,
+<a name="l00931"></a>00931                                                          wurx,wury));
+<a name="l00932"></a>00932   check_nomsg(max_ima_cy=cpl_image_get_centroid_y_window(img,wllx,wlly,
+<a name="l00933"></a>00933                                                          wurx,wury));
+<a name="l00934"></a>00934 
+<a name="l00935"></a>00935 
+<a name="l00936"></a>00936   cpl_image_save(img, <span class="stringliteral">"bad_image_psf_c.fits"</span>,CPL_BPP_IEEE_DOUBLE, NULL, CPL_IO_CREATE);
+<a name="l00937"></a>00937   sinfo_msg(<span class="stringliteral">"@@@@ sinfo_get_encircled_energy() max_ima_x[%"</span> CPL_SIZE_FORMAT <span class="stringliteral">"] max_ima_y[%"</span> CPL_SIZE_FORMAT <span class="stringliteral">"] psf_sz[%d]"</span>, max_ima_x,
+<a name="l00938"></a>00938           max_ima_y,
+<a name="l00939"></a>00939           SINFO_PSF_SZ);
+<a name="l00940"></a>00940   <span class="keywordflow">if</span>(CPL_ERROR_NONE != cpl_image_fit_gaussian(img,max_ima_x,max_ima_y,
+<a name="l00941"></a>00941                                               SINFO_PSF_SZ,
+<a name="l00942"></a>00942                                               &norm,&xc,&yc,&sx,&sy,
+<a name="l00943"></a>00943                                               fwhm_x,fwhm_y)) {
+<a name="l00944"></a>00944 
+<a name="l00945"></a>00945 
+<a name="l00946"></a>00946       irplib_error_recover(clean_state,<span class="stringliteral">"Gaussian fit failed"</span>);
+<a name="l00947"></a>00947 
+<a name="l00948"></a>00948   }
+<a name="l00949"></a>00949 
+<a name="l00950"></a>00950  check_nomsg(enc_energy = cpl_table_new(ni));
+<a name="l00951"></a>00951  check_nomsg(cpl_table_new_column(enc_energy,<span class="stringliteral">"r_pix"</span>, CPL_TYPE_INT));
+<a name="l00952"></a>00952  check_nomsg(cpl_table_new_column(enc_energy,<span class="stringliteral">"r_mas"</span>, CPL_TYPE_DOUBLE));
+<a name="l00953"></a>00953  check_nomsg(cpl_table_new_column(enc_energy,<span class="stringliteral">"r_dif"</span>, CPL_TYPE_DOUBLE));
+<a name="l00954"></a>00954  check_nomsg(cpl_table_new_column(enc_energy,<span class="stringliteral">"abs_energy"</span> , CPL_TYPE_DOUBLE));
+<a name="l00955"></a>00955  check_nomsg(cpl_table_new_column(enc_energy,<span class="stringliteral">"rel_energy"</span> , CPL_TYPE_DOUBLE));
+<a name="l00956"></a>00956  <span class="comment">/* encircled energy computation */</span>
+<a name="l00957"></a>00957  check_nomsg(bkg=irplib_strehl_ring_background(img,max_ima_x,max_ima_y,
+<a name="l00958"></a>00958                     SINFO_BKG_R1,SINFO_BKG_R2,IRPLIB_BG_METHOD_AVER_REJ)) ;
+<a name="l00959"></a>00959  r=rmin+(ni-1)*dr;
+<a name="l00960"></a>00960  check_nomsg(flux_max=irplib_strehl_disk_flux(img,max_ima_x,max_ima_y,r,bkg));
+<a name="l00961"></a>00961  r=rmin;
+<a name="l00962"></a>00962 
+<a name="l00963"></a>00963  <span class="keywordflow">for</span>(i=0; i<ni; i++)
+<a name="l00964"></a>00964    {
+<a name="l00965"></a>00965      check_nomsg(flux=irplib_strehl_disk_flux(img,max_ima_x,max_ima_y,r,bkg));
+<a name="l00966"></a>00966      check_nomsg(cpl_table_set_int(enc_energy,<span class="stringliteral">"r_pix"</span>,i,r));
+<a name="l00967"></a>00967      check_nomsg(cpl_table_set_double(enc_energy,<span class="stringliteral">"r_mas"</span>,i,r*pscale));
+<a name="l00968"></a>00968      check_nomsg(cpl_table_set_double(enc_energy,<span class="stringliteral">"r_dif"</span>,i,r/ir_difr));
+<a name="l00969"></a>00969      check_nomsg(cpl_table_set_double(enc_energy,<span class="stringliteral">"abs_energy"</span>,i,flux));
+<a name="l00970"></a>00970      check_nomsg(cpl_table_set_double(enc_energy,<span class="stringliteral">"rel_energy"</span>,i,flux/flux_max));
+<a name="l00971"></a>00971      r+=dr;
+<a name="l00972"></a>00972 
+<a name="l00973"></a>00973    }
+<a name="l00974"></a>00974 
+<a name="l00975"></a>00975  <span class="comment">//sinfo_msg("max ima=%d %d\n",max_ima_x,max_ima_y);</span>
+<a name="l00976"></a>00976  <span class="comment">//sinfo_msg("centroid ima=%f %f\n",max_ima_cx,max_ima_cy);</span>
+<a name="l00977"></a>00977  <span class="comment">//sinfo_msg("gauss info=%f %f %f %f %f %f %f\n",</span>
+<a name="l00978"></a>00978  <span class="comment">//                         norm,xc,yc,sx,sy,*fwhm_x,*fwhm_y);</span>
+<a name="l00979"></a>00979 
+<a name="l00980"></a>00980  check_nomsg(flux=irplib_strehl_disk_flux(img,max_ima_x,max_ima_y,
+<a name="l00981"></a>00981                                           ir_difr,bkg));
+<a name="l00982"></a>00982  ck0_nomsg(sinfo_qclog_add_double(*qclog_tbl,<span class="stringliteral">"QC ENC CORE"</span>,
+<a name="l00983"></a>00983                                   flux/flux_max,
+<a name="l00984"></a>00984                                   <span class="stringliteral">"Encircled energy within PSF core"</span>,<span class="stringliteral">"%f"</span>));
+<a name="l00985"></a>00985 
+<a name="l00986"></a>00986  <span class="keywordflow">return</span> enc_energy;
+<a name="l00987"></a>00987 
+<a name="l00988"></a>00988  cleanup:
+<a name="l00989"></a>00989   sinfo_free_image(&img_dup);
+<a name="l00990"></a>00990 
+<a name="l00991"></a>00991   <span class="keywordflow">return</span> NULL;
+<a name="l00992"></a>00992 }
+<a name="l00993"></a>00993 
+<a name="l00994"></a>00994 
+<a name="l00995"></a>00995 <span class="keyword">static</span> cpl_table* sinfo_get_strehl_from_cube(cpl_imagelist* cube,
+<a name="l00996"></a>00996                                             <span class="keywordtype">char</span>* name,
+<a name="l00997"></a>00997                                             cpl_frame* frame)
+<a name="l00998"></a>00998 {
+<a name="l00999"></a>00999   cpl_table* strehl_tbl=NULL;
+<a name="l01000"></a>01000 
+<a name="l01001"></a>01001   <span class="keywordtype">double</span> dispersion=0.;
+<a name="l01002"></a>01002   <span class="keywordtype">double</span> centralWave=0.;
+<a name="l01003"></a>01003   <span class="keywordtype">double</span> wrange=0;
+<a name="l01004"></a>01004   <span class="keywordtype">double</span> wstart=0;
+<a name="l01005"></a>01005   <span class="keywordtype">double</span> wstep=0;
+<a name="l01006"></a>01006   <span class="keywordtype">double</span> wend=0;
+<a name="l01007"></a>01007   <span class="keywordtype">double</span> ws=0;
+<a name="l01008"></a>01008   <span class="keywordtype">double</span> we=0;
+<a name="l01009"></a>01009   <span class="keywordtype">double</span> pix_scale=0;
+<a name="l01010"></a>01010   <span class="keywordtype">double</span> lam=0;
+<a name="l01011"></a>01011   <span class="keywordtype">double</span> dlam=0;
+<a name="l01012"></a>01012   <span class="keywordtype">double</span> pscale = 0;
+<a name="l01013"></a>01013 
+<a name="l01014"></a>01014   <span class="keywordtype">double</span> strehl_star_radius=0;
+<a name="l01015"></a>01015   <span class="keywordtype">double</span> strehl_bg_r1=0;
+<a name="l01016"></a>01016   <span class="keywordtype">double</span> strehl_bg_r2=0;
+<a name="l01017"></a>01017   <span class="keywordtype">double</span> strehl=0;
+<a name="l01018"></a>01018   <span class="keywordtype">double</span> strehl_err=0;
+<a name="l01019"></a>01019   <span class="keywordtype">char</span> spat_res[MAX_NAME_SIZE];
+<a name="l01020"></a>01020   cpl_propertylist* plist=NULL;
+<a name="l01021"></a>01021 
+<a name="l01022"></a>01022   <span class="keywordtype">int</span> naxis3=0;
+<a name="l01023"></a>01023   <span class="keywordtype">int</span> nsample=0;
+<a name="l01024"></a>01024   <span class="keywordtype">int</span> i=0;
+<a name="l01025"></a>01025 
+<a name="l01026"></a>01026 
+<a name="l01027"></a>01027   sinfo_get_spatial_res(frame,spat_res);
+<a name="l01028"></a>01028   pix_scale=atof(spat_res);
+<a name="l01029"></a>01029   sinfo_msg(<span class="stringliteral">"Camera pixel scale=%f"</span>,pix_scale);
+<a name="l01030"></a>01030   <span class="comment">/* factor 2 due to change of detector to 2K */</span>
+<a name="l01031"></a>01031   pscale=0.5*pix_scale;
+<a name="l01032"></a>01032 
+<a name="l01033"></a>01033   strehl_star_radius=SINFO_BKG_R1*pscale;
+<a name="l01034"></a>01034   strehl_bg_r1=SINFO_BKG_R1*pscale;
+<a name="l01035"></a>01035   strehl_bg_r2=SINFO_BKG_R2*pscale;
+<a name="l01036"></a>01036 
+<a name="l01037"></a>01037   plist=cpl_propertylist_load(name,0);
+<a name="l01038"></a>01038   dispersion=sinfo_pfits_get_cdelt3(plist);
+<a name="l01039"></a>01039   centralWave=sinfo_pfits_get_crval3(plist);
+<a name="l01040"></a>01040   naxis3=sinfo_pfits_get_naxis3(plist);
+<a name="l01041"></a>01041   sinfo_free_propertylist(&plist);
+<a name="l01042"></a>01042   wrange=dispersion*naxis3;
+<a name="l01043"></a>01043 
+<a name="l01044"></a>01044   wstart = centralWave - (float) (cpl_imagelist_get_size(cube) / 2)*
+<a name="l01045"></a>01045                                  dispersion+dispersion;
+<a name="l01046"></a>01046   wend  =wstart + dispersion * cpl_imagelist_get_size(cube);
+<a name="l01047"></a>01047   wstep=0.025;
+<a name="l01048"></a>01048  <span class="comment">/*</span>
+<a name="l01049"></a>01049 <span class="comment">   note:</span>
+<a name="l01050"></a>01050 <span class="comment">    -wstep as we do not hit the borders where the</span>
+<a name="l01051"></a>01051 <span class="comment">    sinfo_gaussian fit has a problem</span>
+<a name="l01052"></a>01052 <span class="comment">  */</span>
+<a name="l01053"></a>01053   nsample=(int)((wend-wstart-wstep)/wstep);
+<a name="l01054"></a>01054   check_nomsg(strehl_tbl = cpl_table_new(nsample));
+<a name="l01055"></a>01055   check_nomsg(cpl_table_new_column(strehl_tbl,<span class="stringliteral">"wavelength"</span>,CPL_TYPE_DOUBLE));
+<a name="l01056"></a>01056   check_nomsg(cpl_table_new_column(strehl_tbl,<span class="stringliteral">"strehl"</span>,CPL_TYPE_DOUBLE));
+<a name="l01057"></a>01057   check_nomsg(cpl_table_new_column(strehl_tbl,<span class="stringliteral">"strehl_error"</span>,CPL_TYPE_DOUBLE));
+<a name="l01058"></a>01058 
+<a name="l01059"></a>01059 
+<a name="l01060"></a>01060   <span class="keywordflow">for</span>(i=1;i<nsample;i++) {
+<a name="l01061"></a>01061 
+<a name="l01062"></a>01062     ws=wstart+wstep*i;
+<a name="l01063"></a>01063     we=ws+wstep;
+<a name="l01064"></a>01064 
+<a name="l01065"></a>01065     lam = (double)0.5*(ws+we);
+<a name="l01066"></a>01066     dlam=wstep;
+<a name="l01067"></a>01067 
+<a name="l01068"></a>01068     check(sinfo_get_strehl_from_slice(cube,
+<a name="l01069"></a>01069                                 dispersion,
+<a name="l01070"></a>01070                                 centralWave,
+<a name="l01071"></a>01071                                 ws,
+<a name="l01072"></a>01072                                 we,
+<a name="l01073"></a>01073                                 pscale,
+<a name="l01074"></a>01074                                 strehl_star_radius,
+<a name="l01075"></a>01075                                 strehl_bg_r1,
+<a name="l01076"></a>01076                                 strehl_bg_r2,
+<a name="l01077"></a>01077                                 &strehl,
+<a name="l01078"></a>01078                       &strehl_err),<span class="stringliteral">"Error computing strehl"</span>);
+<a name="l01079"></a>01079 
+<a name="l01080"></a>01080 
+<a name="l01081"></a>01081        <span class="keywordflow">if</span>((isnan(lam) ==0) &&
+<a name="l01082"></a>01082           (isnan(lam) ==0) &&
+<a name="l01083"></a>01083           (isnan(lam) ==0)) {
+<a name="l01084"></a>01084      check_nomsg(cpl_table_set_double(strehl_tbl,<span class="stringliteral">"wavelength"</span>,i,lam));
+<a name="l01085"></a>01085      check_nomsg(cpl_table_set_double(strehl_tbl,<span class="stringliteral">"strehl"</span>,i,strehl));
+<a name="l01086"></a>01086      check_nomsg(cpl_table_set_double(strehl_tbl,<span class="stringliteral">"strehl_error"</span>,i,
+<a name="l01087"></a>01087                      strehl_err));
+<a name="l01088"></a>01088 
+<a name="l01089"></a>01089        }
+<a name="l01090"></a>01090   }
+<a name="l01091"></a>01091 
+<a name="l01092"></a>01092   <span class="keywordflow">return</span> strehl_tbl;
+<a name="l01093"></a>01093 
+<a name="l01094"></a>01094  cleanup:
+<a name="l01095"></a>01095   <span class="keywordflow">return</span> NULL;
+<a name="l01096"></a>01096 
+<a name="l01097"></a>01097 
+<a name="l01098"></a>01098 }
+<a name="l01099"></a>01099 
+<a name="l01100"></a>01100 
+<a name="l01101"></a>01101 <span class="keyword">static</span> <span class="keywordtype">double</span>
+<a name="l01102"></a>01102 sinfo_get_strehl_from_ima(cpl_image* ima,
+<a name="l01103"></a>01103                                         cpl_frame* frame)
+<a name="l01104"></a>01104 {
+<a name="l01105"></a>01105 
+<a name="l01106"></a>01106   <span class="keywordtype">double</span> dispersion=0.;
+<a name="l01107"></a>01107   <span class="keywordtype">double</span> centralWave=0.;
+<a name="l01108"></a>01108   <span class="keywordtype">double</span> wstart=0;
+<a name="l01109"></a>01109   <span class="keywordtype">double</span> wend=0;
+<a name="l01110"></a>01110   <span class="keywordtype">double</span> pscale = 0;
+<a name="l01111"></a>01111 
+<a name="l01112"></a>01112   <span class="keywordtype">double</span> strehl_star_radius=0;
+<a name="l01113"></a>01113   <span class="keywordtype">double</span> strehl_bg_r1=0;
+<a name="l01114"></a>01114   <span class="keywordtype">double</span> strehl_bg_r2=0;
+<a name="l01115"></a>01115   <span class="keywordtype">double</span> strehl=0;
+<a name="l01116"></a>01116   <span class="keywordtype">double</span> strehl_err=0;
+<a name="l01117"></a>01117   <span class="keywordtype">double</span> exptime=0;
+<a name="l01118"></a>01118 
+<a name="l01119"></a>01119 
+<a name="l01120"></a>01120 
+<a name="l01121"></a>01121   ck0_nomsg(sinfo_get_strehl_input1(frame,&dispersion,&centralWave,
+<a name="l01122"></a>01122                                    &wstart,&wend,&pscale,&exptime,
+<a name="l01123"></a>01123                            &strehl_star_radius,&strehl_bg_r1,
+<a name="l01124"></a>01124                     &strehl_bg_r2));
+<a name="l01125"></a>01125 
+<a name="l01126"></a>01126 
+<a name="l01127"></a>01127   check(sinfo_get_strehl_from_image(ima,
+<a name="l01128"></a>01128                                 wstart,
+<a name="l01129"></a>01129                                 wend,
+<a name="l01130"></a>01130                                 pscale,
+<a name="l01131"></a>01131                                 strehl_star_radius,
+<a name="l01132"></a>01132                                 strehl_bg_r1,
+<a name="l01133"></a>01133                                 strehl_bg_r2,
+<a name="l01134"></a>01134                                 &strehl,
+<a name="l01135"></a>01135                 &strehl_err),<span class="stringliteral">"Computing Strehl"</span>);
+<a name="l01136"></a>01136 
+<a name="l01137"></a>01137 
+<a name="l01138"></a>01138 
+<a name="l01139"></a>01139 
+<a name="l01140"></a>01140 
+<a name="l01141"></a>01141  cleanup:
+<a name="l01142"></a>01142   <span class="keywordflow">return</span> strehl;
+<a name="l01143"></a>01143 
+<a name="l01144"></a>01144 
+<a name="l01145"></a>01145 }
+<a name="l01146"></a>01146 
+<a name="l01147"></a>01147 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l01148"></a>01148 sinfo_get_frm12(cpl_frameset* sof,cpl_frame** frm1,cpl_frame** frm2){
+<a name="l01149"></a>01149 
+<a name="l01150"></a>01150   cpl_frameset* obs=NULL;
+<a name="l01151"></a>01151   <span class="keywordtype">int</span> nobs=0;
+<a name="l01152"></a>01152   <span class="keywordtype">float</span> eps=0.0001;
+<a name="l01153"></a>01153   <span class="keywordtype">float</span>* pix_scale=NULL;
+<a name="l01154"></a>01154   <span class="keywordtype">int</span> i=0;
+<a name="l01155"></a>01155   cpl_frame* frame=NULL;
+<a name="l01156"></a>01156 
+<a name="l01157"></a>01157   obs = cpl_frameset_new();
+<a name="l01158"></a>01158   sinfo_contains_frames_kind(sof,obs,PRO_OBS_PSF);
+<a name="l01159"></a>01159   nobs=cpl_frameset_get_size(obs);
+<a name="l01160"></a>01160   <span class="keywordflow">if</span> (nobs < 1) {
+<a name="l01161"></a>01161      sinfo_contains_frames_kind(sof,obs,PRO_OBS_STD);
+<a name="l01162"></a>01162      nobs=cpl_frameset_get_size(obs);
+<a name="l01163"></a>01163   }
+<a name="l01164"></a>01164 
+<a name="l01165"></a>01165   nobs=cpl_frameset_get_size(obs);
+<a name="l01166"></a>01166 
+<a name="l01167"></a>01167 
+<a name="l01168"></a>01168   <span class="keywordflow">if</span> (nobs < 1) {
+<a name="l01169"></a>01169      sinfo_contains_frames_kind(sof,obs,PRO_OBS_OBJ);
+<a name="l01170"></a>01170      nobs=cpl_frameset_get_size(obs);
+<a name="l01171"></a>01171   }
+<a name="l01172"></a>01172 
+<a name="l01173"></a>01173   nobs=cpl_frameset_get_size(obs);
+<a name="l01174"></a>01174 
+<a name="l01175"></a>01175   <span class="keywordflow">if</span> (nobs < 1) {
+<a name="l01176"></a>01176     <span class="keywordflow">return</span> -1;
+<a name="l01177"></a>01177   } <span class="keywordflow">else</span> {
+<a name="l01178"></a>01178     pix_scale=cpl_calloc(nobs,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>));
+<a name="l01179"></a>01179     <span class="keywordflow">for</span>(i=0;i<nobs;i++) {
+<a name="l01180"></a>01180       frame=cpl_frameset_get_frame(obs,i);
+<a name="l01181"></a>01181       pix_scale[i]=sinfo_pfits_get_pixelscale(
+<a name="l01182"></a>01182                            (<span class="keywordtype">char</span>*)cpl_frame_get_filename(frame));
+<a name="l01183"></a>01183       <span class="keywordflow">if</span>(fabs(pix_scale[i]-0.025)< eps) {
+<a name="l01184"></a>01184         *frm1=cpl_frame_duplicate(frame);
+<a name="l01185"></a>01185       } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (fabs(pix_scale[i]-0.1) <eps) {
+<a name="l01186"></a>01186         *frm2=cpl_frame_duplicate(frame);
+<a name="l01187"></a>01187       } <span class="keywordflow">else</span> {
+<a name="l01188"></a>01188         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"No proper frame found for strehl computation"</span>);
+<a name="l01189"></a>01189     <span class="keywordflow">return</span> -1;
+<a name="l01190"></a>01190       }
+<a name="l01191"></a>01191     }
+<a name="l01192"></a>01192   }
+<a name="l01193"></a>01193   cpl_free(pix_scale);
+<a name="l01194"></a>01194   cpl_frameset_delete(obs);
+<a name="l01195"></a>01195 
+<a name="l01196"></a>01196   <span class="keywordflow">return</span> 0;
+<a name="l01197"></a>01197 
+<a name="l01198"></a>01198 }
+<a name="l01199"></a>01199 
+<a name="l01200"></a>01200 
+<a name="l01201"></a>01201 
+<a name="l01202"></a>01202 
+<a name="l01203"></a>01203 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l01204"></a>01204 sinfo_get_strehl_input1(cpl_frame* frm,
+<a name="l01205"></a>01205                <span class="keywordtype">double</span>* dispersion,
+<a name="l01206"></a>01206                <span class="keywordtype">double</span>* centralWave,
+<a name="l01207"></a>01207                <span class="keywordtype">double</span>* wstart,
+<a name="l01208"></a>01208                <span class="keywordtype">double</span>* wend,
+<a name="l01209"></a>01209                <span class="keywordtype">double</span>* pscale,
+<a name="l01210"></a>01210                <span class="keywordtype">double</span>* exptime,
+<a name="l01211"></a>01211                <span class="keywordtype">double</span>* strehl_star_rad,
+<a name="l01212"></a>01212                <span class="keywordtype">double</span>* strehl_bg_rmin,
+<a name="l01213"></a>01213                <span class="keywordtype">double</span>* strehl_bg_rmax)
+<a name="l01214"></a>01214 
+<a name="l01215"></a>01215 {
+<a name="l01216"></a>01216 
+<a name="l01217"></a>01217   cpl_propertylist* plist=NULL;
+<a name="l01218"></a>01218   <span class="keywordtype">char</span> res[MAX_NAME_SIZE];
+<a name="l01219"></a>01219   <span class="keywordtype">double</span> pix_scale=0;
+<a name="l01220"></a>01220   <span class="keywordtype">double</span> wrange=0;
+<a name="l01221"></a>01221   <span class="keywordtype">char</span> fname[MAX_NAME_SIZE];
+<a name="l01222"></a>01222   <span class="keywordtype">int</span> naxis3=0;
+<a name="l01223"></a>01223 
+<a name="l01224"></a>01224   sinfo_get_spatial_res(frm,res);
+<a name="l01225"></a>01225   pix_scale=atof(res);
+<a name="l01226"></a>01226 
+<a name="l01227"></a>01227   <span class="comment">/* factor 2 due to change of detector to 2K</span>
+<a name="l01228"></a>01228 <span class="comment">  *pscale=0.5*pix_scale;</span>
+<a name="l01229"></a>01229 <span class="comment">  */</span>
+<a name="l01230"></a>01230 
+<a name="l01231"></a>01231 
+<a name="l01232"></a>01232   *pscale=pix_scale;
+<a name="l01233"></a>01233 
+<a name="l01234"></a>01234   *strehl_star_rad=SINFO_RSTAR*(*pscale);
+<a name="l01235"></a>01235   *strehl_bg_rmin=SINFO_BKG_R1*(*pscale);
+<a name="l01236"></a>01236   *strehl_bg_rmax=SINFO_BKG_R2*(*pscale);
+<a name="l01237"></a>01237 
+<a name="l01238"></a>01238   strcpy(fname,cpl_frame_get_filename(frm));
+<a name="l01239"></a>01239   check_nomsg(plist=cpl_propertylist_load(fname,0));
+<a name="l01240"></a>01240   check_nomsg(*dispersion=sinfo_pfits_get_cdelt3(plist));
+<a name="l01241"></a>01241   *centralWave=sinfo_pfits_get_crval3(plist);
+<a name="l01242"></a>01242   check_nomsg(naxis3=sinfo_pfits_get_naxis3(plist));
+<a name="l01243"></a>01243   *exptime=sinfo_pfits_get_exp_time(plist);
+<a name="l01244"></a>01244   sinfo_free_propertylist(&plist);
+<a name="l01245"></a>01245 
+<a name="l01246"></a>01246   wrange=(*dispersion)*naxis3;
+<a name="l01247"></a>01247 
+<a name="l01248"></a>01248   *wstart = *centralWave - (wrange / 2) +(*dispersion);
+<a name="l01249"></a>01249   *wend   = *wstart + wrange;
+<a name="l01250"></a>01250 
+<a name="l01251"></a>01251 
+<a name="l01252"></a>01252  cleanup:
+<a name="l01253"></a>01253   <span class="keywordflow">if</span> (cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l01254"></a>01254     <span class="keywordflow">return</span> -1;
+<a name="l01255"></a>01255   } <span class="keywordflow">else</span> {
+<a name="l01256"></a>01256     <span class="keywordflow">return</span> 0;
+<a name="l01257"></a>01257   }
+<a name="l01258"></a>01258 
+<a name="l01259"></a>01259 }
+<a name="l01260"></a>01260 
+<a name="l01261"></a>01261 
+<a name="l01262"></a>01262 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l01263"></a>01263 sinfo_get_strehl_input2(cpl_frame* frm1,
+<a name="l01264"></a>01264                        cpl_frame* frm2,
+<a name="l01265"></a>01265                <span class="keywordtype">double</span>* dispersion,
+<a name="l01266"></a>01266                <span class="keywordtype">double</span>* centralWave,
+<a name="l01267"></a>01267                <span class="keywordtype">double</span>* wstart,
+<a name="l01268"></a>01268                <span class="keywordtype">double</span>* wend,
+<a name="l01269"></a>01269                <span class="keywordtype">double</span>* pscale1,
+<a name="l01270"></a>01270                <span class="keywordtype">double</span>* pscale2,
+<a name="l01271"></a>01271                <span class="keywordtype">double</span>* exptime1,
+<a name="l01272"></a>01272                <span class="keywordtype">double</span>* exptime2,
+<a name="l01273"></a>01273                <span class="keywordtype">double</span>* strehl_star_rad1,
+<a name="l01274"></a>01274                <span class="keywordtype">double</span>* strehl_star_rad2,
+<a name="l01275"></a>01275                <span class="keywordtype">double</span>* strehl_bg_rmin1,
+<a name="l01276"></a>01276                <span class="keywordtype">double</span>* strehl_bg_rmin2,
+<a name="l01277"></a>01277                <span class="keywordtype">double</span>* strehl_bg_rmax1,
+<a name="l01278"></a>01278                <span class="keywordtype">double</span>* strehl_bg_rmax2)
+<a name="l01279"></a>01279 
+<a name="l01280"></a>01280 {
+<a name="l01281"></a>01281 
+<a name="l01282"></a>01282   cpl_propertylist* plist=NULL;
+<a name="l01283"></a>01283   <span class="keywordtype">char</span> res1[MAX_NAME_SIZE];
+<a name="l01284"></a>01284   <span class="keywordtype">char</span> res2[MAX_NAME_SIZE];
+<a name="l01285"></a>01285   <span class="keywordtype">double</span> pix_scale1=0;
+<a name="l01286"></a>01286   <span class="keywordtype">double</span> pix_scale2=0;
+<a name="l01287"></a>01287   <span class="keywordtype">double</span> wrange=0;
+<a name="l01288"></a>01288   <span class="keywordtype">char</span> fname1[MAX_NAME_SIZE];
+<a name="l01289"></a>01289   <span class="keywordtype">char</span> fname2[MAX_NAME_SIZE];
+<a name="l01290"></a>01290   <span class="keywordtype">int</span> naxis3=0;
+<a name="l01291"></a>01291 
+<a name="l01292"></a>01292   sinfo_get_spatial_res(frm1,res1);
+<a name="l01293"></a>01293   sinfo_get_spatial_res(frm2,res2);
+<a name="l01294"></a>01294   pix_scale1=atof(res1);
+<a name="l01295"></a>01295   pix_scale2=atof(res2);
+<a name="l01296"></a>01296   <span class="comment">/* factor 2 due to change of detector to 2K</span>
+<a name="l01297"></a>01297 <span class="comment">  *pscale1=0.5*pix_scale1;</span>
+<a name="l01298"></a>01298 <span class="comment">  *pscale2=0.5*pix_scale2;</span>
+<a name="l01299"></a>01299 <span class="comment">  */</span>
+<a name="l01300"></a>01300 
+<a name="l01301"></a>01301   *pscale1=pix_scale1;
+<a name="l01302"></a>01302   *pscale2=pix_scale2;
+<a name="l01303"></a>01303 
+<a name="l01304"></a>01304 
+<a name="l01305"></a>01305   *strehl_star_rad1=SINFO_RSTAR*(*pscale1);
+<a name="l01306"></a>01306   *strehl_bg_rmin1=SINFO_BKG_R1*(*pscale1);
+<a name="l01307"></a>01307   *strehl_bg_rmax1=SINFO_BKG_R2*(*pscale1);
+<a name="l01308"></a>01308 
+<a name="l01309"></a>01309   *strehl_star_rad2=SINFO_RSTAR*(*pscale2);
+<a name="l01310"></a>01310   *strehl_bg_rmin2=SINFO_BKG_R1*(*pscale2);
+<a name="l01311"></a>01311   *strehl_bg_rmax2=SINFO_BKG_R2*(*pscale2);
+<a name="l01312"></a>01312 
+<a name="l01313"></a>01313   strcpy(fname1,cpl_frame_get_filename(frm1));
+<a name="l01314"></a>01314   check_nomsg(plist=cpl_propertylist_load(fname1,0));
+<a name="l01315"></a>01315   check_nomsg(*dispersion=sinfo_pfits_get_cdelt3(plist));
+<a name="l01316"></a>01316   *centralWave=sinfo_pfits_get_crval3(plist);
+<a name="l01317"></a>01317   check_nomsg(naxis3=sinfo_pfits_get_naxis3(plist));
+<a name="l01318"></a>01318   *exptime1=sinfo_pfits_get_exp_time(plist);
+<a name="l01319"></a>01319   sinfo_free_propertylist(&plist);
+<a name="l01320"></a>01320   strcpy(fname2,cpl_frame_get_filename(frm2));
+<a name="l01321"></a>01321 
+<a name="l01322"></a>01322 
+<a name="l01323"></a>01323   check_nomsg(plist=cpl_propertylist_load(fname2,0));
+<a name="l01324"></a>01324   *exptime2=sinfo_pfits_get_exp_time(plist);
+<a name="l01325"></a>01325   sinfo_free_propertylist(&plist);
+<a name="l01326"></a>01326 
+<a name="l01327"></a>01327 
+<a name="l01328"></a>01328 
+<a name="l01329"></a>01329   wrange=(*dispersion)*naxis3;
+<a name="l01330"></a>01330 
+<a name="l01331"></a>01331   *wstart = *centralWave - (wrange / 2) +(*dispersion);
+<a name="l01332"></a>01332   *wend   = *wstart + wrange;
+<a name="l01333"></a>01333 
+<a name="l01334"></a>01334 
+<a name="l01335"></a>01335  cleanup:
+<a name="l01336"></a>01336   <span class="keywordflow">if</span> (cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l01337"></a>01337     <span class="keywordflow">return</span> -1;
+<a name="l01338"></a>01338   } <span class="keywordflow">else</span> {
+<a name="l01339"></a>01339     <span class="keywordflow">return</span> 0;
+<a name="l01340"></a>01340   }
+<a name="l01341"></a>01341 
+<a name="l01342"></a>01342 }
+<a name="l01343"></a>01343 
+<a name="l01344"></a>01344 
+<a name="l01345"></a>01345 
+<a name="l01346"></a>01346 <span class="keyword">static</span> cpl_table*
+<a name="l01347"></a>01347 sinfo_get_strehl_from_2images(cpl_image* ima1,
+<a name="l01348"></a>01348                   cpl_image* ima2,
+<a name="l01349"></a>01349                   cpl_frame* frm1,
+<a name="l01350"></a>01350                   cpl_frame* frm2)
+<a name="l01351"></a>01351 {
+<a name="l01352"></a>01352 
+<a name="l01353"></a>01353   cpl_table* strehl_tbl=NULL;
+<a name="l01354"></a>01354 
+<a name="l01355"></a>01355 
+<a name="l01356"></a>01356   <span class="keywordtype">double</span> dispersion=0.;
+<a name="l01357"></a>01357   <span class="keywordtype">double</span> centralWave=0.;
+<a name="l01358"></a>01358   <span class="keywordtype">double</span> wstart=0;
+<a name="l01359"></a>01359   <span class="keywordtype">double</span> wstep=0;
+<a name="l01360"></a>01360   <span class="keywordtype">double</span> wend=0;
+<a name="l01361"></a>01361   <span class="keywordtype">double</span> lam=0;
+<a name="l01362"></a>01362   <span class="keywordtype">double</span> dlam=0;
+<a name="l01363"></a>01363   <span class="keywordtype">double</span> pscale1 = 0;
+<a name="l01364"></a>01364   <span class="keywordtype">double</span> pscale2 = 0;
+<a name="l01365"></a>01365 
+<a name="l01366"></a>01366   <span class="keywordtype">double</span> strehl_star_rad1=0;
+<a name="l01367"></a>01367   <span class="keywordtype">double</span> strehl_star_rad2=0;
+<a name="l01368"></a>01368   <span class="keywordtype">double</span> strehl_bg_rmin1=0;
+<a name="l01369"></a>01369   <span class="keywordtype">double</span> strehl_bg_rmin2=0;
+<a name="l01370"></a>01370   <span class="keywordtype">double</span> strehl_bg_rmax1=0;
+<a name="l01371"></a>01371   <span class="keywordtype">double</span> strehl_bg_rmax2=0;
+<a name="l01372"></a>01372   <span class="keywordtype">double</span> strehl=0;
+<a name="l01373"></a>01373   <span class="keywordtype">double</span> strehl_err=0;
+<a name="l01374"></a>01374 
+<a name="l01375"></a>01375   <span class="keywordtype">int</span> nsample=1;
+<a name="l01376"></a>01376   <span class="keywordtype">double</span> exptime1=0;
+<a name="l01377"></a>01377   <span class="keywordtype">double</span> exptime2=0;
+<a name="l01378"></a>01378   cpl_image* img_dup=NULL;
+<a name="l01379"></a>01379 
+<a name="l01380"></a>01380   cpl_size max_ima1_x=0;
+<a name="l01381"></a>01381   cpl_size max_ima1_y=0;
+<a name="l01382"></a>01382 
+<a name="l01383"></a>01383   cpl_size max_ima2_x=0;
+<a name="l01384"></a>01384 
+<a name="l01385"></a>01385 
+<a name="l01386"></a>01386   cpl_size max_ima2_y=0;
+<a name="l01387"></a>01387   <span class="keywordtype">double</span> star_bkg=0;
+<a name="l01388"></a>01388   <span class="keywordtype">double</span> star_peak=0;
+<a name="l01389"></a>01389   <span class="keywordtype">double</span> star_flux=0;
+<a name="l01390"></a>01390 
+<a name="l01391"></a>01391   <span class="keywordtype">double</span> psf_peak=0;
+<a name="l01392"></a>01392   <span class="keywordtype">double</span> psf_flux=0;
+<a name="l01393"></a>01393   <span class="keywordtype">double</span> bkg_noise=0;
+<a name="l01394"></a>01394 
+<a name="l01395"></a>01395   cpl_errorstate clean_state = cpl_errorstate_get();
+<a name="l01396"></a>01396 
+<a name="l01397"></a>01397   ck0_nomsg(sinfo_get_strehl_input2(frm1,frm2,&dispersion, &centralWave,
+<a name="l01398"></a>01398                                    &wstart,&wend,&pscale1,&pscale2,
+<a name="l01399"></a>01399                                    &exptime1,&exptime2,
+<a name="l01400"></a>01400                                    &strehl_star_rad1,&strehl_star_rad2,
+<a name="l01401"></a>01401                                    &strehl_bg_rmin1,&strehl_bg_rmin2,
+<a name="l01402"></a>01402                                    &strehl_bg_rmax1,&strehl_bg_rmax2));
+<a name="l01403"></a>01403 
+<a name="l01404"></a>01404 
+<a name="l01405"></a>01405 
+<a name="l01406"></a>01406 
+<a name="l01407"></a>01407 
+<a name="l01408"></a>01408   check_nomsg(img_dup=cpl_image_duplicate(ima1));
+<a name="l01409"></a>01409   sinfo_clean_nan(&img_dup);
+<a name="l01410"></a>01410   check_nomsg(cpl_image_get_maxpos(img_dup,&max_ima1_x,&max_ima1_y));
+<a name="l01411"></a>01411   sinfo_free_image(&img_dup);
+<a name="l01412"></a>01412 
+<a name="l01413"></a>01413 
+<a name="l01414"></a>01414   check_nomsg(img_dup=cpl_image_duplicate(ima2));
+<a name="l01415"></a>01415   sinfo_clean_nan(&img_dup);
+<a name="l01416"></a>01416   check_nomsg(cpl_image_get_maxpos(img_dup,&max_ima2_x,&max_ima2_y));
+<a name="l01417"></a>01417   sinfo_free_image(&img_dup);
+<a name="l01418"></a>01418 
+<a name="l01419"></a>01419   <span class="comment">/*</span>
+<a name="l01420"></a>01420 <span class="comment">     note:</span>
+<a name="l01421"></a>01421 <span class="comment">     -wstep as we do not hit the borders where the</span>
+<a name="l01422"></a>01422 <span class="comment">     sinfo_gaussian fit has a problem</span>
+<a name="l01423"></a>01423 <span class="comment">  */</span>
+<a name="l01424"></a>01424 
+<a name="l01425"></a>01425 
+<a name="l01426"></a>01426 
+<a name="l01427"></a>01427   check_nomsg(strehl_tbl = cpl_table_new(nsample));
+<a name="l01428"></a>01428   check_nomsg(cpl_table_new_column(strehl_tbl,<span class="stringliteral">"wavelength"</span>,CPL_TYPE_DOUBLE));
+<a name="l01429"></a>01429   check_nomsg(cpl_table_new_column(strehl_tbl,<span class="stringliteral">"strehl"</span>,CPL_TYPE_DOUBLE));
+<a name="l01430"></a>01430   check_nomsg(cpl_table_new_column(strehl_tbl,<span class="stringliteral">"strehl_error"</span>,CPL_TYPE_DOUBLE));
+<a name="l01431"></a>01431   wstep  = wend-wstart;
+<a name="l01432"></a>01432 
+<a name="l01433"></a>01433 
+<a name="l01434"></a>01434 
+<a name="l01435"></a>01435   lam = (double)0.5*(wstart+wend);
+<a name="l01436"></a>01436   dlam=wstep;
+<a name="l01437"></a>01437   sinfo_msg(<span class="stringliteral">"lambda=%f dlambda=%f"</span>,lam,dlam);
+<a name="l01438"></a>01438   sinfo_msg(<span class="stringliteral">"wstart=%f wend=%f"</span>,wstart,wend);
+<a name="l01439"></a>01439   sinfo_msg(<span class="stringliteral">"wstep=%f"</span>,wstep);
+<a name="l01440"></a>01440 
+<a name="l01441"></a>01441 
+<a name="l01442"></a>01442   <span class="keywordflow">if</span>(CPL_ERROR_NONE != sinfo_strehl_compute_two(ima1,ima2,
+<a name="l01443"></a>01443                         SINFO_STREHL_M1,SINFO_STREHL_M2,
+<a name="l01444"></a>01444                         lam,
+<a name="l01445"></a>01445                         pscale1,pscale2,
+<a name="l01446"></a>01446                         exptime1,exptime2,
+<a name="l01447"></a>01447                         max_ima1_x,max_ima1_y,
+<a name="l01448"></a>01448                         max_ima2_x,max_ima2_y,
+<a name="l01449"></a>01449                         strehl_star_rad1,
+<a name="l01450"></a>01450                                             strehl_bg_rmin1,
+<a name="l01451"></a>01451                         strehl_bg_rmax1,
+<a name="l01452"></a>01452                         &strehl,&strehl_err,&star_bkg,
+<a name="l01453"></a>01453                         &star_peak,&star_flux,
+<a name="l01454"></a>01454                         &psf_peak,&psf_flux,&bkg_noise))
+<a name="l01455"></a>01455     {
+<a name="l01456"></a>01456 
+<a name="l01457"></a>01457       strehl=-1;
+<a name="l01458"></a>01458       strehl_err=0;
+<a name="l01459"></a>01459       irplib_error_recover(clean_state,
+<a name="l01460"></a>01460                <span class="stringliteral">"Problem computing strehl, set it to -1"</span>);
+<a name="l01461"></a>01461 
+<a name="l01462"></a>01462     }
+<a name="l01463"></a>01463 
+<a name="l01464"></a>01464 
+<a name="l01465"></a>01465   <span class="keywordflow">if</span>((isnan(lam) ==0) &&
+<a name="l01466"></a>01466      (isnan(lam) ==0) &&
+<a name="l01467"></a>01467      (isnan(lam) ==0)) {
+<a name="l01468"></a>01468     check_nomsg(cpl_table_set_double(strehl_tbl,<span class="stringliteral">"wavelength"</span>,0,lam));
+<a name="l01469"></a>01469     check_nomsg(cpl_table_set_double(strehl_tbl,<span class="stringliteral">"strehl"</span>,0,strehl));
+<a name="l01470"></a>01470     check_nomsg(cpl_table_set_double(strehl_tbl,<span class="stringliteral">"strehl_error"</span>,
+<a name="l01471"></a>01471                      0,strehl_err));
+<a name="l01472"></a>01472 
+<a name="l01473"></a>01473   }
+<a name="l01474"></a>01474 
+<a name="l01475"></a>01475 
+<a name="l01476"></a>01476 
+<a name="l01477"></a>01477   <span class="keywordflow">return</span> strehl_tbl;
+<a name="l01478"></a>01478  cleanup:
+<a name="l01479"></a>01479 
+<a name="l01480"></a>01480 
+<a name="l01481"></a>01481   <span class="keywordflow">return</span> NULL;
+<a name="l01482"></a>01482 }
+<a name="l01483"></a>01483 
+<a name="l01484"></a>01484 
+<a name="l01485"></a>01485 
+<a name="l01486"></a>01486 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l01521"></a>01521 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l01522"></a>01522 <span class="preprocessor">#define irplib_assure_code cpl_ensure_code</span>
+<a name="l01523"></a>01523 <span class="preprocessor"></span><span class="keywordtype">int</span> sinfo_strehl_compute_two(
+<a name="l01524"></a>01524         <span class="keyword">const</span> cpl_image *   im1,
+<a name="l01525"></a>01525         <span class="keyword">const</span> cpl_image *   im2,
+<a name="l01526"></a>01526         <span class="keywordtype">double</span>              m1,
+<a name="l01527"></a>01527         <span class="keywordtype">double</span>              m2,
+<a name="l01528"></a>01528         <span class="keywordtype">double</span>              lam,
+<a name="l01529"></a>01529         <span class="keywordtype">double</span>              pscale1,
+<a name="l01530"></a>01530         <span class="keywordtype">double</span>              pscale2,
+<a name="l01531"></a>01531         <span class="keywordtype">double</span>              exptime1,
+<a name="l01532"></a>01532         <span class="keywordtype">double</span>              exptime2,
+<a name="l01533"></a>01533         <span class="keywordtype">int</span>                 xpos1,
+<a name="l01534"></a>01534         <span class="keywordtype">int</span>                 ypos1,
+<a name="l01535"></a>01535         <span class="keywordtype">int</span>                 xpos2,
+<a name="l01536"></a>01536         <span class="keywordtype">int</span>                 ypos2,
+<a name="l01537"></a>01537         <span class="keywordtype">double</span>              r1,
+<a name="l01538"></a>01538         <span class="keywordtype">double</span>              r2,
+<a name="l01539"></a>01539         <span class="keywordtype">double</span>              r3,
+<a name="l01540"></a>01540         <span class="keywordtype">double</span>          *   strehl,
+<a name="l01541"></a>01541         <span class="keywordtype">double</span>          *   strehl_err,
+<a name="l01542"></a>01542         <span class="keywordtype">double</span>          *   star_bkg,
+<a name="l01543"></a>01543         <span class="keywordtype">double</span>          *   star_peak,
+<a name="l01544"></a>01544         <span class="keywordtype">double</span>          *   star_flux,
+<a name="l01545"></a>01545         <span class="keywordtype">double</span>          *   psf_peak,
+<a name="l01546"></a>01546         <span class="keywordtype">double</span>          *   psf_flux,
+<a name="l01547"></a>01547         <span class="keywordtype">double</span>          *   bg_noise)
+<a name="l01548"></a>01548 {
+<a name="l01549"></a>01549     <span class="keywordtype">double</span> psf_peak1=0;
+<a name="l01550"></a>01550     <span class="keywordtype">double</span> psf_peak2=0;
+<a name="l01551"></a>01551     <span class="keywordtype">double</span> psf_flux1=0;
+<a name="l01552"></a>01552     <span class="keywordtype">double</span> psf_flux2=0;
+<a name="l01553"></a>01553     <span class="keywordtype">double</span> star_bkg1=0;
+<a name="l01554"></a>01554     <span class="keywordtype">double</span> star_bkg2=0;
+<a name="l01555"></a>01555     <span class="keywordtype">double</span> star_flux1=0;
+<a name="l01556"></a>01556     <span class="keywordtype">double</span> star_flux2=0;
+<a name="l01557"></a>01557     <span class="keywordtype">double</span> star_peak1=0;
+<a name="l01558"></a>01558     <span class="keywordtype">double</span> star_peak2=0;
+<a name="l01559"></a>01559 
+<a name="l01560"></a>01560     <span class="keyword">const</span> <span class="keywordtype">double</span>   window_size = 5.0 ;
+<a name="l01561"></a>01561     <span class="keywordtype">double</span>         star_radius, max_radius ;
+<a name="l01562"></a>01562     <span class="keywordtype">double</span>       ring[4];
+<a name="l01563"></a>01563 
+<a name="l01564"></a>01564     <span class="keywordtype">double</span> prat=pscale2/pscale1;
+<a name="l01565"></a>01565     <span class="keywordtype">double</span> prat2=prat*prat;
+<a name="l01566"></a>01566     <span class="keywordtype">double</span> trat=exptime1/exptime2;
+<a name="l01567"></a>01567     <span class="keywordtype">double</span> frat=sinfo_scale_flux(pscale1,pscale2,exptime1,exptime2);
+<a name="l01568"></a>01568     <span class="keywordtype">double</span> xc=0;
+<a name="l01569"></a>01569     <span class="keywordtype">double</span> yc=0;
+<a name="l01570"></a>01570 
+<a name="l01571"></a>01571     <span class="keywordtype">int</span> sx=0;
+<a name="l01572"></a>01572     <span class="keywordtype">int</span> sy=0;
+<a name="l01573"></a>01573     <span class="keywordtype">int</span> d=16;
+<a name="l01574"></a>01574     cpl_errorstate initial_errorstate = cpl_errorstate_get();
+<a name="l01575"></a>01575 
+<a name="l01576"></a>01576 
+<a name="l01577"></a>01577     <span class="comment">/* Test inputs */</span>
+<a name="l01578"></a>01578     irplib_assure_code(im1 != NULL,         CPL_ERROR_NULL_INPUT);
+<a name="l01579"></a>01579     irplib_assure_code(im2 != NULL,         CPL_ERROR_NULL_INPUT);
+<a name="l01580"></a>01580     irplib_assure_code(strehl != NULL,     CPL_ERROR_NULL_INPUT);
+<a name="l01581"></a>01581     irplib_assure_code(strehl_err != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l01582"></a>01582     irplib_assure_code(star_bkg != NULL,    CPL_ERROR_NULL_INPUT);
+<a name="l01583"></a>01583     irplib_assure_code(star_peak != NULL,  CPL_ERROR_NULL_INPUT);
+<a name="l01584"></a>01584     irplib_assure_code(star_flux != NULL,  CPL_ERROR_NULL_INPUT);
+<a name="l01585"></a>01585     irplib_assure_code(psf_peak != NULL,   CPL_ERROR_NULL_INPUT);
+<a name="l01586"></a>01586     irplib_assure_code(psf_flux != NULL,   CPL_ERROR_NULL_INPUT);
+<a name="l01587"></a>01587 
+<a name="l01588"></a>01588     irplib_assure_code(pscale1 > 0.0,      CPL_ERROR_ILLEGAL_INPUT);
+<a name="l01589"></a>01589     irplib_assure_code(pscale2 > 0.0,      CPL_ERROR_ILLEGAL_INPUT);
+<a name="l01590"></a>01590 
+<a name="l01591"></a>01591     irplib_assure_code(xpos1-window_size > 0, CPL_ERROR_ACCESS_OUT_OF_RANGE);
+<a name="l01592"></a>01592     irplib_assure_code(ypos1-window_size > 0, CPL_ERROR_ACCESS_OUT_OF_RANGE);
+<a name="l01593"></a>01593     irplib_assure_code(xpos2-window_size > 0, CPL_ERROR_ACCESS_OUT_OF_RANGE);
+<a name="l01594"></a>01594     irplib_assure_code(ypos2-window_size > 0, CPL_ERROR_ACCESS_OUT_OF_RANGE);
+<a name="l01595"></a>01595 
+<a name="l01596"></a>01596     irplib_assure_code(xpos1+window_size <= cpl_image_get_size_x(im1),
+<a name="l01597"></a>01597                        CPL_ERROR_ACCESS_OUT_OF_RANGE);
+<a name="l01598"></a>01598     irplib_assure_code(ypos1+window_size <= cpl_image_get_size_y(im1),
+<a name="l01599"></a>01599                        CPL_ERROR_ACCESS_OUT_OF_RANGE);
+<a name="l01600"></a>01600 
+<a name="l01601"></a>01601     irplib_assure_code(xpos2+window_size <= cpl_image_get_size_x(im2),
+<a name="l01602"></a>01602                        CPL_ERROR_ACCESS_OUT_OF_RANGE);
+<a name="l01603"></a>01603     irplib_assure_code(ypos2+window_size <= cpl_image_get_size_y(im2),
+<a name="l01604"></a>01604                        CPL_ERROR_ACCESS_OUT_OF_RANGE);
+<a name="l01605"></a>01605 
+<a name="l01606"></a>01606     irplib_assure_code(r1 > 0.0,      CPL_ERROR_ILLEGAL_INPUT);
+<a name="l01607"></a>01607     irplib_assure_code(r2 > 0.0,      CPL_ERROR_ILLEGAL_INPUT);
+<a name="l01608"></a>01608     irplib_assure_code(r3 > r2,       CPL_ERROR_ILLEGAL_INPUT);
+<a name="l01609"></a>01609 
+<a name="l01610"></a>01610     <span class="comment">/* Computing a Strehl ratio is a story between an ideal PSF */</span>
+<a name="l01611"></a>01611     <span class="comment">/* and a candidate image supposed to approximate this ideal PSF. */</span>
+<a name="l01612"></a>01612 
+<a name="l01613"></a>01613     <span class="comment">/* Generate first appropriate PSF to find max peak: same pscale as</span>
+<a name="l01614"></a>01614 <span class="comment">       the one of the image where we compute the flux */</span>
+<a name="l01615"></a>01615 
+<a name="l01616"></a>01616 
+<a name="l01617"></a>01617     sx=cpl_image_get_size_x(im1);
+<a name="l01618"></a>01618     sy=cpl_image_get_size_y(im1);
+<a name="l01619"></a>01619 
+<a name="l01620"></a>01620 
+<a name="l01621"></a>01621     psf_flux1 = 1.0; <span class="comment">// The psf flux, cpl_image_get_flux(psf), is always 1</span>
+<a name="l01622"></a>01622     psf_flux2 = 1.0; <span class="comment">// The psf flux, cpl_image_get_flux(psf), is always 1</span>
+<a name="l01623"></a>01623     *psf_flux=1.0;
+<a name="l01624"></a>01624     ring[0] = xpos2;
+<a name="l01625"></a>01625     ring[1] = ypos2;
+<a name="l01626"></a>01626     ring[2] = r2/pscale2;
+<a name="l01627"></a>01627     ring[3] = r3/pscale2;
+<a name="l01628"></a>01628 
+<a name="l01629"></a>01629     <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"star_pos=%d %d %d %d"</span>,xpos1,ypos1,xpos2,ypos2);
+<a name="l01630"></a>01630     <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"star_ring=%f %f %f %f"</span>,ring[0],ring[1],ring[2],ring[3]);
+<a name="l01631"></a>01631 
+<a name="l01632"></a>01632     <span class="comment">/* Compute star_radius in pixels */</span>
+<a name="l01633"></a>01633     star_radius = r1/pscale2;
+<a name="l01634"></a>01634 
+<a name="l01635"></a>01635      <span class="comment">/* Find the peak value on the central part of the candidate image */</span>
+<a name="l01636"></a>01636 
+<a name="l01637"></a>01637 
+<a name="l01638"></a>01638     <span class="comment">/* Find the peak value on the central part of the candidate image */</span>
+<a name="l01639"></a>01639     max_radius = window_size < star_radius ? window_size : star_radius;
+<a name="l01640"></a>01640 
+<a name="l01641"></a>01641     check_nomsg(sinfo_get_star_features(im1,d,xpos1,ypos1,&xc,&yc,
+<a name="l01642"></a>01642                                         &star_peak1,&star_flux1,&star_bkg1));
+<a name="l01643"></a>01643 
+<a name="l01644"></a>01644 
+<a name="l01645"></a>01645     *star_peak=star_peak1;
+<a name="l01646"></a>01646 
+<a name="l01647"></a>01647     check_nomsg(sinfo_compute_psf(m1,m2/m1,lam*1.e-6,pscale1,xc,yc,1.,
+<a name="l01648"></a>01648                   &psf_peak1));
+<a name="l01649"></a>01649 
+<a name="l01650"></a>01650     check_nomsg(sinfo_get_star_features(im2,d,xpos2,ypos2,&xc,&yc,
+<a name="l01651"></a>01651                                         &star_peak2,&star_flux2,&star_bkg2));
+<a name="l01652"></a>01652 
+<a name="l01653"></a>01653     *star_flux=star_flux2;
+<a name="l01654"></a>01654     *star_bkg=star_bkg2;
+<a name="l01655"></a>01655 
+<a name="l01656"></a>01656     check_nomsg(sinfo_compute_psf(m1,m2/m1,lam*1.e-6,pscale2,xc,yc,1.,
+<a name="l01657"></a>01657                   &psf_peak2));
+<a name="l01658"></a>01658 
+<a name="l01659"></a>01659 
+<a name="l01660"></a>01660 
+<a name="l01661"></a>01661 
+<a name="l01662"></a>01662     <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"p1=%g p2=%g"</span>,*star_peak,star_peak2);
+<a name="l01663"></a>01663     <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"corr peak: p1=%g p2=%g"</span>,*star_peak,star_peak2/frat);
+<a name="l01664"></a>01664     <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"corr bkg: bkg1=%g bkg2=%g"</span>,star_bkg1/frat,*star_bkg);
+<a name="l01665"></a>01665     <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"rel diff: %g"</span>,
+<a name="l01666"></a>01666               fabs(star_peak2/frat- *star_peak)/(star_peak2/frat));
+<a name="l01667"></a>01667 
+<a name="l01668"></a>01668 
+<a name="l01669"></a>01669 
+<a name="l01670"></a>01670     <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"Rescaled star_flux1=%g star_flux2=%g"</span>,
+<a name="l01671"></a>01671                  star_flux1*trat,*star_flux);
+<a name="l01672"></a>01672 
+<a name="l01673"></a>01673     <span class="comment">//Check that flux value as measured on im1 and on 1m2 are close one</span>
+<a name="l01674"></a>01674     <span class="comment">//to another. Note that flux1, measured on im1, need to be rescaled</span>
+<a name="l01675"></a>01675     <span class="comment">//by exposure time to match to flux2=star_flux</span>
+<a name="l01676"></a>01676     <span class="keywordflow">if</span> ( fabs((star_flux1*frat-*star_flux)/(*star_flux)) > 0.25) {
+<a name="l01677"></a>01677       <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"Star flux rel diff: %g"</span>,
+<a name="l01678"></a>01678                         fabs((star_flux1*frat-*star_flux)/(*star_flux)));
+<a name="l01679"></a>01679     }
+<a name="l01680"></a>01680 
+<a name="l01681"></a>01681     <span class="comment">//Check that pick value as measured on im1 and on 1m2 are close one</span>
+<a name="l01682"></a>01682     <span class="comment">//to another. Note that peak2, measured on im2, need to be rescaled</span>
+<a name="l01683"></a>01683     <span class="comment">//by exposure time and pixel scale to match to peak1=star_peak</span>
+<a name="l01684"></a>01684     <span class="keywordflow">if</span> ( fabs(star_peak2-star_peak1*frat)/(star_peak2) > 0.25) {
+<a name="l01685"></a>01685       <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"Star pick rel diff: %g"</span>,
+<a name="l01686"></a>01686                         fabs(star_peak2-star_peak1*frat)/(star_peak2));
+<a name="l01687"></a>01687     }
+<a name="l01688"></a>01688     <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"ak1 star peak=%g"</span>,*star_peak);
+<a name="l01689"></a>01689     irplib_assure_code(*star_peak > 0.0,      CPL_ERROR_ILLEGAL_OUTPUT);
+<a name="l01690"></a>01690     *star_peak=star_peak1;
+<a name="l01691"></a>01691 
+<a name="l01692"></a>01692     *star_bkg=star_bkg2;
+<a name="l01693"></a>01693     *star_flux=star_flux2;
+<a name="l01694"></a>01694 
+<a name="l01695"></a>01695     <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"ak2"</span>);
+<a name="l01696"></a>01696 
+<a name="l01697"></a>01697     <span class="comment">//psf1 = irplib_strehl_generate_psf(m1, m2, lam, dlam, pscale1, size*4);</span>
+<a name="l01698"></a>01698     <span class="comment">//psf_peak1 = cpl_image_get_max(psf1) ;</span>
+<a name="l01699"></a>01699 
+<a name="l01700"></a>01700 
+<a name="l01701"></a>01701 
+<a name="l01702"></a>01702     <span class="comment">/* Compute Strehl */</span>
+<a name="l01703"></a>01703     <span class="comment">//*strehl = (*star_peak *prat2/trat/ *star_flux) / (*psf_peak / *psf_flux);</span>
+<a name="l01704"></a>01704     *strehl = (*star_peak/(*star_flux*trat)) / (psf_peak1 );
+<a name="l01705"></a>01705     <span class="comment">//*strehl = (*star_peak/(*star_flux)) / (psf_peak1 / *psf_flux) ;</span>
+<a name="l01706"></a>01706     <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"peak=%g flux1=%f flux2=%f flux=%f cflux=%g "</span>
+<a name="l01707"></a>01707                     <span class="stringliteral">"fct=%g psf_peak=%g"</span>,
+<a name="l01708"></a>01708           *star_peak,star_flux1,star_flux2,*star_flux,
+<a name="l01709"></a>01709               *star_flux/frat*prat2,prat2/frat,psf_peak1);
+<a name="l01710"></a>01710     <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"=======strehl=%g"</span>,*strehl);
+<a name="l01711"></a>01711     <span class="comment">/*</span>
+<a name="l01712"></a>01712 <span class="comment">    if (*strehl > 1)</span>
+<a name="l01713"></a>01713 <span class="comment">        cpl_msg_warning(cpl_func, "Extreme Strehl-ratio=%g, star_peak=%g, "</span>
+<a name="l01714"></a>01714 <span class="comment">                        "star_flux=%g, psf_peak=%g, psf_flux=%g", *strehl,</span>
+<a name="l01715"></a>01715 <span class="comment">                        *star_peak, *star_flux, *psf_peak, *psf_flux);</span>
+<a name="l01716"></a>01716 <span class="comment"></span>
+<a name="l01717"></a>01717 <span class="comment"></span>
+<a name="l01718"></a>01718 <span class="comment">    // Compute Strehl error</span>
+<a name="l01719"></a>01719 <span class="comment">    if (cpl_flux_get_noise_ring(im2, ring, noise_box_sz, noise_nsamples,</span>
+<a name="l01720"></a>01720 <span class="comment">                                bg_noise, NULL) == CPL_ERROR_NONE) {</span>
+<a name="l01721"></a>01721 <span class="comment">        *strehl_err = SINFO_STREHL_ERROR_COEFFICIENT * (*bg_noise) * pscale2 *</span>
+<a name="l01722"></a>01722 <span class="comment">            star_radius * star_radius / *star_flux;</span>
+<a name="l01723"></a>01723 <span class="comment">        irplib_assure_code(*strehl_err >= 0.0,       CPL_ERROR_ILLEGAL_OUTPUT);</span>
+<a name="l01724"></a>01724 <span class="comment">    } else {</span>
+<a name="l01725"></a>01725 <span class="comment">      sinfo_msg_warning("Problem computing noise");</span>
+<a name="l01726"></a>01726 <span class="comment">    }</span>
+<a name="l01727"></a>01727 <span class="comment">    */</span>
+<a name="l01728"></a>01728     *bg_noise=0;
+<a name="l01729"></a>01729 
+<a name="l01730"></a>01730     cleanup:
+<a name="l01731"></a>01731 
+<a name="l01732"></a>01732 
+<a name="l01733"></a>01733     <span class="keywordflow">if</span> (!cpl_errorstate_is_equal(initial_errorstate)) {
+<a name="l01734"></a>01734         <span class="comment">/* Dump the error history since recipe execution start.</span>
+<a name="l01735"></a>01735 <span class="comment">           At this point the recipe cannot recover from the error */</span>
+<a name="l01736"></a>01736         cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
+<a name="l01737"></a>01737     }
+<a name="l01738"></a>01738 
+<a name="l01739"></a>01739   <span class="keywordflow">if</span> (cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l01740"></a>01740     <span class="keywordflow">return</span> cpl_error_get_code();
+<a name="l01741"></a>01741   } <span class="keywordflow">else</span> {
+<a name="l01742"></a>01742     <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l01743"></a>01743   }
+<a name="l01744"></a>01744 
+<a name="l01745"></a>01745 }
+<a name="l01746"></a>01746 
+<a name="l01747"></a>01747 
+<a name="l01748"></a>01748 
+<a name="l01749"></a>01749 
+<a name="l01750"></a>01750 <span class="keyword">static</span> cpl_error_code
+<a name="l01751"></a>01751 sinfo_get_star_features(<span class="keyword">const</span> cpl_image* im,
+<a name="l01752"></a>01752                         <span class="keyword">const</span> <span class="keywordtype">int</span> radius,
+<a name="l01753"></a>01753             <span class="keyword">const</span> <span class="keywordtype">int</span> xpos,
+<a name="l01754"></a>01754             <span class="keyword">const</span> <span class="keywordtype">int</span> ypos,
+<a name="l01755"></a>01755                         <span class="keywordtype">double</span>* xc,
+<a name="l01756"></a>01756                         <span class="keywordtype">double</span>* yc,
+<a name="l01757"></a>01757                         <span class="keywordtype">double</span>* peak,
+<a name="l01758"></a>01758                         <span class="keywordtype">double</span>* flux,
+<a name="l01759"></a>01759                         <span class="keywordtype">double</span>* bkg)
+<a name="l01760"></a>01760 {
+<a name="l01761"></a>01761   <span class="keywordtype">int</span> sx=0;
+<a name="l01762"></a>01762   <span class="keywordtype">int</span> sy=0;
+<a name="l01763"></a>01763   <span class="keywordtype">int</span> ixm=0;
+<a name="l01764"></a>01764   <span class="keywordtype">int</span> iym=0;
+<a name="l01765"></a>01765   <span class="keywordtype">int</span> llx=0;
+<a name="l01766"></a>01766   <span class="keywordtype">int</span> lly=0;
+<a name="l01767"></a>01767   <span class="keywordtype">int</span> urx=0;
+<a name="l01768"></a>01768   <span class="keywordtype">int</span> ury=0;
+<a name="l01769"></a>01769   <span class="keywordtype">int</span> dim_new=0;
+<a name="l01770"></a>01770   <span class="keywordtype">double</span> kappa=2;
+<a name="l01771"></a>01771   <span class="keywordtype">double</span> xm=0;
+<a name="l01772"></a>01772   <span class="keywordtype">double</span> ym=0;
+<a name="l01773"></a>01773   <span class="keywordtype">double</span> bkg_stdev=0;
+<a name="l01774"></a>01774   <span class="keywordtype">int</span> bkg_sx=SINFO_BKG_BOX_SZ;
+<a name="l01775"></a>01775   <span class="keywordtype">int</span> bkg_sy=SINFO_BKG_BOX_SZ;
+<a name="l01776"></a>01776 
+<a name="l01777"></a>01777   cpl_bivector* iqe=NULL;
+<a name="l01778"></a>01778   <span class="keywordtype">double</span>* piqe=NULL;
+<a name="l01779"></a>01779   cpl_image* im_new=NULL;
+<a name="l01780"></a>01780 
+<a name="l01781"></a>01781   sx=cpl_image_get_size_x(im);
+<a name="l01782"></a>01782   sy=cpl_image_get_size_y(im);
+<a name="l01783"></a>01783 
+<a name="l01784"></a>01784   <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"star_radius=%d"</span>,radius);
+<a name="l01785"></a>01785   <span class="comment">//We find the image centroid</span>
+<a name="l01786"></a>01786   <span class="keywordflow">if</span>(NULL != (iqe=cpl_image_iqe(im,sx/2-radius,sy/2-radius,
+<a name="l01787"></a>01787                 sx/2+radius,sy/2+radius))) {
+<a name="l01788"></a>01788 
+<a name="l01789"></a>01789 
+<a name="l01790"></a>01790     piqe=cpl_bivector_get_x_data(iqe);
+<a name="l01791"></a>01791     <span class="comment">//*star_peak=piqe[5];</span>
+<a name="l01792"></a>01792     xm=piqe[0];
+<a name="l01793"></a>01793     ym=piqe[1];
+<a name="l01794"></a>01794     <span class="comment">//Extract a square sub-image of minimal size not to hit the image borders</span>
+<a name="l01795"></a>01795     <span class="comment">//centered on the previous image centroid</span>
+<a name="l01796"></a>01796     <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"Max ima: %g %g"</span>,xm,ym);
+<a name="l01797"></a>01797     <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"Find min of: %g %g %g %g"</span>,xm,sx-xm,ym,sy-ym);
+<a name="l01798"></a>01798     ixm=floor(xm);
+<a name="l01799"></a>01799     iym=floor(ym);
+<a name="l01800"></a>01800     <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"ixm=%d iym=%d"</span>,ixm,iym);
+<a name="l01801"></a>01801     dim_new=floor(sinfo_find_min_of_four(xm,sx-xm,ym,sy-ym));
+<a name="l01802"></a>01802     <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"dim_new=%d"</span>,dim_new);
+<a name="l01803"></a>01803     llx=(ixm-dim_new > 1) ? ixm-dim_new : 1;
+<a name="l01804"></a>01804     lly=(iym-dim_new > 1) ? iym-dim_new : 1;
+<a name="l01805"></a>01805     urx=(ixm+dim_new < sx) ? ixm+dim_new : sx;
+<a name="l01806"></a>01806     ury=(iym+dim_new < sy) ? iym+dim_new : sy;
+<a name="l01807"></a>01807     <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"llx=%d lly=%d urx=%d ury=%d"</span>,llx,lly,urx,ury);
+<a name="l01808"></a>01808     check_nomsg(im_new=cpl_image_extract(im,llx,lly,urx,ury));
+<a name="l01809"></a>01809 
+<a name="l01810"></a>01810     <span class="comment">//compute the background of this last image</span>
+<a name="l01811"></a>01811     check_nomsg(sinfo_get_bkg_4corners(im_new,bkg_sx,bkg_sy,bkg,&bkg_stdev));
+<a name="l01812"></a>01812 
+<a name="l01813"></a>01813 
+<a name="l01814"></a>01814 
+<a name="l01815"></a>01815     sinfo_free_bivector(&iqe);
+<a name="l01816"></a>01816 
+<a name="l01817"></a>01817     <span class="comment">//Determine the image pick on the new coordinate system</span>
+<a name="l01818"></a>01818     iqe=cpl_image_iqe(im_new,dim_new-radius,dim_new-radius,
+<a name="l01819"></a>01819               dim_new+radius,dim_new+radius);
+<a name="l01820"></a>01820     <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"xc=%g yc=%g"</span>,piqe[0],piqe[1]);
+<a name="l01821"></a>01821     *xc=piqe[0]-dim_new-1;
+<a name="l01822"></a>01822     *yc=piqe[1]-dim_new-1;
+<a name="l01823"></a>01823 
+<a name="l01824"></a>01824 
+<a name="l01825"></a>01825     <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"xc=%g yc=%g"</span>,*xc,*yc);
+<a name="l01826"></a>01826     <span class="comment">//*peak=piqe[5];</span>
+<a name="l01827"></a>01827     *peak=cpl_image_get_max_window(im_new,dim_new-radius,dim_new-radius,
+<a name="l01828"></a>01828                    dim_new+radius,dim_new+radius);
+<a name="l01829"></a>01829 
+<a name="l01830"></a>01830     sinfo_get_flux_above_bkg(im_new,kappa,bkg_stdev,flux);
+<a name="l01831"></a>01831     *peak -= (*bkg);
+<a name="l01832"></a>01832     <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"star peak=%g bkg=%g"</span>,*peak,*bkg);
+<a name="l01833"></a>01833 
+<a name="l01834"></a>01834 
+<a name="l01835"></a>01835     sinfo_free_bivector(&iqe);
+<a name="l01836"></a>01836 
+<a name="l01837"></a>01837 
+<a name="l01838"></a>01838   } <span class="keywordflow">else</span> {
+<a name="l01839"></a>01839     <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"IQE fit failed"</span>);
+<a name="l01840"></a>01840     cpl_error_reset();
+<a name="l01841"></a>01841     <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"xc=%d yc=%d radius=%d"</span>,xpos,ypos,radius);
+<a name="l01842"></a>01842     *xc=xpos-sx/2;
+<a name="l01843"></a>01843     *yc=ypos-sy/2;
+<a name="l01844"></a>01844     <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"xc=%g yc=%g"</span>,*xc,*yc);
+<a name="l01845"></a>01845     check_nomsg(sinfo_get_bkg_4corners(im,bkg_sx,bkg_sy,bkg,&bkg_stdev));
+<a name="l01846"></a>01846     check_nomsg(sinfo_get_safe_box(&llx, &lly, &urx, &ury, xpos,ypos,radius,
+<a name="l01847"></a>01847                    64,64));
+<a name="l01848"></a>01848     check_nomsg(*peak=cpl_image_get_max_window(im,llx,lly,urx,ury)-(*bkg));
+<a name="l01849"></a>01849     sinfo_get_flux_above_bkg(im,kappa,bkg_stdev,flux);
+<a name="l01850"></a>01850     <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"star peak=%g bkg=%g"</span>,*peak,*bkg);
+<a name="l01851"></a>01851 
+<a name="l01852"></a>01852 
+<a name="l01853"></a>01853   }
+<a name="l01854"></a>01854 
+<a name="l01855"></a>01855 
+<a name="l01856"></a>01856 
+<a name="l01857"></a>01857  cleanup:
+<a name="l01858"></a>01858   sinfo_free_image(&im_new);
+<a name="l01859"></a>01859   sinfo_free_bivector(&iqe);
+<a name="l01860"></a>01860 
+<a name="l01861"></a>01861 
+<a name="l01862"></a>01862 
+<a name="l01863"></a>01863 
+<a name="l01864"></a>01864   <span class="keywordflow">if</span> (cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l01865"></a>01865     <span class="keywordflow">return</span> cpl_error_get_code();
+<a name="l01866"></a>01866   } <span class="keywordflow">else</span> {
+<a name="l01867"></a>01867     <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l01868"></a>01868   }
+<a name="l01869"></a>01869 
+<a name="l01870"></a>01870 }
+<a name="l01871"></a>01871 
+<a name="l01872"></a>01872 
+<a name="l01873"></a>01873 
+<a name="l01874"></a>01874 
+<a name="l01875"></a>01875 
+<a name="l01876"></a>01876 
+<a name="l01877"></a>01877 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01904"></a>01904 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l01905"></a>01905 cpl_error_code
+<a name="l01906"></a>01906 sinfo_strehl_compute_one(<span class="keyword">const</span> cpl_image *   im,
+<a name="l01907"></a>01907                                      <span class="keywordtype">double</span>              m1,
+<a name="l01908"></a>01908                                      <span class="keywordtype">double</span>              m2,
+<a name="l01909"></a>01909                                      <span class="keywordtype">double</span>              lam,
+<a name="l01910"></a>01910                                      <span class="keywordtype">double</span>              dlam,
+<a name="l01911"></a>01911                                      <span class="keywordtype">double</span>              pscale,
+<a name="l01912"></a>01912                                      <span class="keywordtype">int</span>                 xpos,
+<a name="l01913"></a>01913                                      <span class="keywordtype">int</span>                 ypos,
+<a name="l01914"></a>01914                                      <span class="keywordtype">double</span>              r1,
+<a name="l01915"></a>01915                                      <span class="keywordtype">double</span>              r2,
+<a name="l01916"></a>01916                                      <span class="keywordtype">double</span>              r3,
+<a name="l01917"></a>01917                                      <span class="keywordtype">int</span>                 size,
+<a name="l01918"></a>01918                                      <span class="keywordtype">double</span>          *   strehl,
+<a name="l01919"></a>01919                                      <span class="keywordtype">double</span>          *   strehl_err,
+<a name="l01920"></a>01920                                      <span class="keywordtype">double</span>          *   star_bkg,
+<a name="l01921"></a>01921                                      <span class="keywordtype">double</span>          *   star_peak,
+<a name="l01922"></a>01922                                      <span class="keywordtype">double</span>          *   star_flux,
+<a name="l01923"></a>01923                                      <span class="keywordtype">double</span>          *   psf_peak,
+<a name="l01924"></a>01924                                      <span class="keywordtype">double</span>          *   psf_flux,
+<a name="l01925"></a>01925                                      <span class="keywordtype">double</span>          *   bg_noise)
+<a name="l01926"></a>01926 {
+<a name="l01927"></a>01927     cpl_image  * psf;
+<a name="l01928"></a>01928     <span class="keywordtype">double</span>       star_radius;
+<a name="l01929"></a>01929 
+<a name="l01930"></a>01930     <span class="comment">/* FIXME: Arbitrary choice of image border */</span>
+<a name="l01931"></a>01931     <span class="keyword">const</span> <span class="keywordtype">double</span> window_size = (double)(SINFO_STREHL_RAD_CENTRAL);
+<a name="l01932"></a>01932 
+<a name="l01933"></a>01933     <span class="comment">/* Determined empirically by C. Lidman for Strehl error computation */</span>
+<a name="l01934"></a>01934     <span class="comment">//Commented as not used</span>
+<a name="l01935"></a>01935     <span class="comment">//const double strehl_error_coefficient = SINFO_MATH_PI * 0.007 / 0.0271;</span>
+<a name="l01936"></a>01936 
+<a name="l01937"></a>01937 <span class="preprocessor">#if defined CPL_VERSION_CODE && CPL_VERSION_CODE >= CPL_VERSION(4, 0, 0)</span>
+<a name="l01938"></a>01938 <span class="preprocessor"></span>    <span class="keywordtype">double</span>       ring[4];
+<a name="l01939"></a>01939 <span class="preprocessor">#else</span>
+<a name="l01940"></a>01940 <span class="preprocessor"></span>    <span class="comment">/* FIXME: Remove this branch once CPL 3.X is no longer supported */</span>
+<a name="l01941"></a>01941     <span class="keywordtype">int</span>          ring[4];
+<a name="l01942"></a>01942 <span class="preprocessor">#endif</span>
+<a name="l01943"></a>01943 <span class="preprocessor"></span>    cpl_bivector* iqe1=NULL;
+<a name="l01944"></a>01944     <span class="keywordtype">double</span> xc=0;
+<a name="l01945"></a>01945     <span class="keywordtype">double</span> yc=0;
+<a name="l01946"></a>01946     <span class="keywordtype">int</span> d=16;
+<a name="l01947"></a>01947 
+<a name="l01948"></a>01948 
+<a name="l01949"></a>01949 
+<a name="l01950"></a>01950     <span class="comment">/* Check compile-time constant */</span>
+<a name="l01951"></a>01951     cpl_ensure_code(window_size > 0.0,  CPL_ERROR_ILLEGAL_INPUT);
+<a name="l01952"></a>01952 
+<a name="l01953"></a>01953     <span class="comment">/* Test inputs */</span>
+<a name="l01954"></a>01954     cpl_ensure_code(im != NULL,         CPL_ERROR_NULL_INPUT);
+<a name="l01955"></a>01955     cpl_ensure_code(strehl != NULL,     CPL_ERROR_NULL_INPUT);
+<a name="l01956"></a>01956     cpl_ensure_code(strehl_err != NULL, CPL_ERROR_NULL_INPUT);
+<a name="l01957"></a>01957     cpl_ensure_code(star_bkg != NULL,    CPL_ERROR_NULL_INPUT);
+<a name="l01958"></a>01958     cpl_ensure_code(star_peak != NULL,  CPL_ERROR_NULL_INPUT);
+<a name="l01959"></a>01959     cpl_ensure_code(star_flux != NULL,  CPL_ERROR_NULL_INPUT);
+<a name="l01960"></a>01960     cpl_ensure_code(psf_peak != NULL,   CPL_ERROR_NULL_INPUT);
+<a name="l01961"></a>01961     cpl_ensure_code(psf_flux != NULL,   CPL_ERROR_NULL_INPUT);
+<a name="l01962"></a>01962 
+<a name="l01963"></a>01963     cpl_ensure_code(pscale > 0.0,      CPL_ERROR_ILLEGAL_INPUT);
+<a name="l01964"></a>01964 
+<a name="l01965"></a>01965 
+<a name="l01966"></a>01966     cpl_ensure_code(r1 > 0.0,      CPL_ERROR_ILLEGAL_INPUT);
+<a name="l01967"></a>01967     cpl_ensure_code(r2 > 0.0,      CPL_ERROR_ILLEGAL_INPUT);
+<a name="l01968"></a>01968 
+<a name="l01969"></a>01969     cpl_ensure_code(r3 > r2,       CPL_ERROR_ILLEGAL_INPUT);
+<a name="l01970"></a>01970 
+<a name="l01971"></a>01971 
+<a name="l01972"></a>01972     <span class="comment">/* Computing a Strehl ratio is a story between an ideal PSF */</span>
+<a name="l01973"></a>01973     check_nomsg(sinfo_compute_psf(m1,m2/m1,lam*1.e-6,pscale,xc,yc,
+<a name="l01974"></a>01974                   1.,psf_peak));
+<a name="l01975"></a>01975   <span class="comment">/* and a candidate image supposed to approximate this ideal PSF. */</span>
+<a name="l01976"></a>01976 
+<a name="l01977"></a>01977     <span class="comment">/* Generate first appropriate PSF to find max peak */</span>
+<a name="l01978"></a>01978 
+<a name="l01979"></a>01979     psf = irplib_strehl_generate_psf(m1, m2, lam, dlam, pscale, size);
+<a name="l01980"></a>01980     cpl_ensure_code(psf != NULL,      CPL_ERROR_ILLEGAL_OUTPUT);
+<a name="l01981"></a>01981 
+<a name="l01982"></a>01982     <span class="comment">/* Compute flux in PSF and find max peak */</span>
+<a name="l01983"></a>01983     *psf_peak = cpl_image_get_max(psf);
+<a name="l01984"></a>01984 
+<a name="l01985"></a>01985     cpl_image_delete(psf);
+<a name="l01986"></a>01986 
+<a name="l01987"></a>01987 
+<a name="l01988"></a>01988 
+<a name="l01989"></a>01989 
+<a name="l01990"></a>01990     assert( *psf_peak > 0.0); <span class="comment">/* The ideal PSF has a positive maximum */</span>
+<a name="l01991"></a>01991     *psf_flux = 1.0; <span class="comment">/* The psf flux, cpl_image_get_flux(psf), is always 1 */</span>
+<a name="l01992"></a>01992 
+<a name="l01993"></a>01993 
+<a name="l01994"></a>01994     <span class="comment">/* Compute star_radius in pixels */</span>
+<a name="l01995"></a>01995     star_radius = r1/pscale;
+<a name="l01996"></a>01996 
+<a name="l01997"></a>01997 
+<a name="l01998"></a>01998     check_nomsg(sinfo_get_star_features(im,d,xpos,ypos,&xc,&yc,
+<a name="l01999"></a>01999                     star_peak,star_flux,star_bkg));
+<a name="l02000"></a>02000 
+<a name="l02001"></a>02001 
+<a name="l02002"></a>02002     check_nomsg(sinfo_compute_psf(m1,m2/m1,lam*1.e-6,pscale,xc,yc,1.,psf_peak));
+<a name="l02003"></a>02003 
+<a name="l02004"></a>02004 
+<a name="l02005"></a>02005 
+<a name="l02006"></a>02006     *star_peak -= *star_bkg;
+<a name="l02007"></a>02007 
+<a name="l02008"></a>02008 
+<a name="l02009"></a>02009     cpl_ensure_code(*star_peak > 0.0,      CPL_ERROR_ILLEGAL_OUTPUT);
+<a name="l02010"></a>02010 
+<a name="l02011"></a>02011 
+<a name="l02012"></a>02012     <span class="comment">/* Compute Strehl */</span>
+<a name="l02013"></a>02013     <span class="comment">/* (StarPeak / StarFlux) / (PsfPeak / PsfFlux) */</span>
+<a name="l02014"></a>02014     <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"Star flux=%g"</span>, *star_flux);
+<a name="l02015"></a>02015     <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"Star peak=%g"</span>, *star_peak);
+<a name="l02016"></a>02016     <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"PSF  flux=%g"</span>, *psf_flux);
+<a name="l02017"></a>02017     <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"PSF  peak=%g"</span>, *psf_peak);
+<a name="l02018"></a>02018 
+<a name="l02019"></a>02019     *strehl = (*star_peak * *psf_flux ) / ( *star_flux * *psf_peak);
+<a name="l02020"></a>02020 
+<a name="l02021"></a>02021 
+<a name="l02022"></a>02022 
+<a name="l02023"></a>02023      <span class="keywordflow">if</span> (*strehl > 1)
+<a name="l02024"></a>02024         cpl_msg_warning(cpl_func, <span class="stringliteral">"Extreme Strehl-ratio=%g, star_peak=%g, "</span>
+<a name="l02025"></a>02025                         <span class="stringliteral">"star_flux=%g, psf_peak=%g, psf_flux=%g"</span>, *strehl,
+<a name="l02026"></a>02026                         *star_peak, *star_flux, *psf_peak, *psf_flux);
+<a name="l02027"></a>02027 
+<a name="l02028"></a>02028     <span class="comment">/* Compute Strehl error */</span>
+<a name="l02029"></a>02029     ring[0] = xpos;
+<a name="l02030"></a>02030     ring[1] = ypos;
+<a name="l02031"></a>02031     ring[2] = r2/pscale;
+<a name="l02032"></a>02032     ring[3] = r3/pscale;
+<a name="l02033"></a>02033     <span class="comment">/*</span>
+<a name="l02034"></a>02034 <span class="comment">    *strehl_err = strehl_error_coefficient * (*bg_noise) * pscale *</span>
+<a name="l02035"></a>02035 <span class="comment">        star_radius * star_radius / *star_flux;</span>
+<a name="l02036"></a>02036 <span class="comment"></span>
+<a name="l02037"></a>02037 <span class="comment">    // This check should not be able to fail, but just to be sure</span>
+<a name="l02038"></a>02038 <span class="comment">    cpl_ensure_code(*strehl_err >= 0.0,       CPL_ERROR_ILLEGAL_OUTPUT);</span>
+<a name="l02039"></a>02039 <span class="comment">    */</span>
+<a name="l02040"></a>02040     *bg_noise=0;
+<a name="l02041"></a>02041 
+<a name="l02042"></a>02042 
+<a name="l02043"></a>02043  cleanup:
+<a name="l02044"></a>02044     sinfo_free_bivector(&iqe1);
+<a name="l02045"></a>02045     <span class="keywordflow">if</span> (cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l02046"></a>02046       <span class="keywordflow">return</span> cpl_error_get_code();
+<a name="l02047"></a>02047     } <span class="keywordflow">else</span> {
+<a name="l02048"></a>02048       <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l02049"></a>02049     }
+<a name="l02050"></a>02050 
+<a name="l02051"></a>02051 
+<a name="l02052"></a>02052 }
+<a name="l02053"></a>02053 
+<a name="l02054"></a>02054 
+<a name="l02055"></a>02055 
+<a name="l02056"></a>02056 <span class="keyword">static</span> <span class="keywordtype">void</span>
+<a name="l02057"></a>02057 sinfo_check_borders(cpl_size* val,<span class="keyword">const</span> <span class="keywordtype">int</span> max,<span class="keyword">const</span> <span class="keywordtype">int</span> thresh)
+<a name="l02058"></a>02058 {
+<a name="l02059"></a>02059 
+<a name="l02060"></a>02060   *val = ((*val-thresh) > 0) ? *val : thresh;
+<a name="l02061"></a>02061   *val = ((*val+thresh) < max) ? *val : max-thresh-1;
+<a name="l02062"></a>02062   <span class="keywordflow">return</span>;
+<a name="l02063"></a>02063 }
+<a name="l02064"></a>02064 
+<a name="l02065"></a>02065 <span class="keyword">static</span> <span class="keywordtype">void</span>
+<a name="l02066"></a>02066 sinfo_get_safe_box(<span class="keywordtype">int</span>* llx,
+<a name="l02067"></a>02067                    <span class="keywordtype">int</span>* lly,
+<a name="l02068"></a>02068                    <span class="keywordtype">int</span>* urx,
+<a name="l02069"></a>02069                    <span class="keywordtype">int</span>* ury,
+<a name="l02070"></a>02070                    <span class="keyword">const</span> <span class="keywordtype">int</span> xpos,
+<a name="l02071"></a>02071                    <span class="keyword">const</span> <span class="keywordtype">int</span> ypos,
+<a name="l02072"></a>02072                    <span class="keyword">const</span> <span class="keywordtype">int</span> box,
+<a name="l02073"></a>02073                    <span class="keyword">const</span> <span class="keywordtype">int</span> szx,
+<a name="l02074"></a>02074                    <span class="keyword">const</span> <span class="keywordtype">int</span> szy)
+<a name="l02075"></a>02075 
+<a name="l02076"></a>02076 {
+<a name="l02077"></a>02077   *llx= ((xpos-box)>0)   ? (xpos-box) : 1;
+<a name="l02078"></a>02078   *lly= ((ypos-box)>0)   ? (ypos-box) : 1;
+<a name="l02079"></a>02079   *urx= ((xpos+box)<szx) ? (xpos+box) : szx-1 ;
+<a name="l02080"></a>02080   *ury= ((ypos+box)<szy) ? (ypos+box) : szy-1 ;
+<a name="l02081"></a>02081 
+<a name="l02082"></a>02082   <span class="keywordflow">return</span>;
+<a name="l02083"></a>02083 }
+<a name="l02084"></a>02084 
+<a name="l02085"></a>02085 
+<a name="l02086"></a>02086 
+<a name="l02087"></a>02087 
+<a name="l02088"></a>02088 
+<a name="l02089"></a>02089 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l02099"></a>02099 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l02100"></a>02100 cpl_error_code
+<a name="l02101"></a>02101 sinfo_get_bkg_4corners(<span class="keyword">const</span> cpl_image *img,
+<a name="l02102"></a>02102                <span class="keyword">const</span> <span class="keywordtype">int</span> bkg_sx,
+<a name="l02103"></a>02103                        <span class="keyword">const</span> <span class="keywordtype">int</span> bkg_sy,
+<a name="l02104"></a>02104                        <span class="keywordtype">double</span>* bkg,
+<a name="l02105"></a>02105                        <span class="keywordtype">double</span>* std)
+<a name="l02106"></a>02106 {
+<a name="l02107"></a>02107 
+<a name="l02108"></a>02108   <span class="keywordtype">int</span> sx=0;
+<a name="l02109"></a>02109   <span class="keywordtype">int</span> sy=0;
+<a name="l02110"></a>02110   cpl_image* img_bkg=NULL;
+<a name="l02111"></a>02111   *bkg=0;
+<a name="l02112"></a>02112 
+<a name="l02113"></a>02113   cknull(img,<span class="stringliteral">"NULL input image!"</span>);
+<a name="l02114"></a>02114   check_nomsg(sx=cpl_image_get_size_x(img));
+<a name="l02115"></a>02115   check_nomsg(sy=cpl_image_get_size_y(img));
+<a name="l02116"></a>02116 
+<a name="l02117"></a>02117   check_nomsg(img_bkg=cpl_image_new(2*bkg_sx,2*bkg_sy,CPL_TYPE_FLOAT));
+<a name="l02118"></a>02118   check_nomsg(cpl_image_copy(img_bkg,cpl_image_extract(img,1,1,bkg_sx,bkg_sy),
+<a name="l02119"></a>02119                  1,1));
+<a name="l02120"></a>02120 
+<a name="l02121"></a>02121   check_nomsg(cpl_image_copy(img_bkg,cpl_image_extract(img,sx-bkg_sx,1,
+<a name="l02122"></a>02122                                sx,bkg_sy),bkg_sx+1,1));
+<a name="l02123"></a>02123   check_nomsg(cpl_image_copy(img_bkg,cpl_image_extract(img,1,sy-bkg_sy,
+<a name="l02124"></a>02124                                bkg_sx,sy),1,bkg_sy+1));
+<a name="l02125"></a>02125 
+<a name="l02126"></a>02126   check_nomsg(cpl_image_copy(img_bkg,
+<a name="l02127"></a>02127                  cpl_image_extract(img,sx-bkg_sx,sy-bkg_sy,sx,sy),
+<a name="l02128"></a>02128                  bkg_sx+1,bkg_sy+1));
+<a name="l02129"></a>02129 
+<a name="l02130"></a>02130   check_nomsg(*bkg=cpl_image_get_median(img_bkg));
+<a name="l02131"></a>02131   check_nomsg(*std=cpl_image_get_stdev(img_bkg));
+<a name="l02132"></a>02132   <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"sky bkg: %f"</span>,*bkg);
+<a name="l02133"></a>02133   <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"sky stdev: %f"</span>,*std);
+<a name="l02134"></a>02134 
+<a name="l02135"></a>02135 
+<a name="l02136"></a>02136 cleanup:
+<a name="l02137"></a>02137   sinfo_free_image(&img_bkg);
+<a name="l02138"></a>02138 
+<a name="l02139"></a>02139   <span class="keywordflow">if</span> (cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l02140"></a>02140     <span class="keywordflow">return</span> cpl_error_get_code();
+<a name="l02141"></a>02141   } <span class="keywordflow">else</span> {
+<a name="l02142"></a>02142     <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l02143"></a>02143   }
+<a name="l02144"></a>02144 
+<a name="l02145"></a>02145 
+<a name="l02146"></a>02146 }
+<a name="l02147"></a>02147 
+<a name="l02160"></a>02160 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l02161"></a>02161 cpl_error_code
+<a name="l02162"></a>02162 sinfo_compute_psf(<span class="keyword">const</span> <span class="keywordtype">double</span> dia,
+<a name="l02163"></a>02163           <span class="keyword">const</span> <span class="keywordtype">double</span> occ,
+<a name="l02164"></a>02164           <span class="keyword">const</span> <span class="keywordtype">double</span> lambda,
+<a name="l02165"></a>02165           <span class="keyword">const</span> <span class="keywordtype">double</span> psize,
+<a name="l02166"></a>02166           <span class="keyword">const</span> <span class="keywordtype">double</span> cx,
+<a name="l02167"></a>02167           <span class="keyword">const</span> <span class="keywordtype">double</span> cy,
+<a name="l02168"></a>02168           <span class="keyword">const</span> <span class="keywordtype">double</span> anamorph,
+<a name="l02169"></a>02169           <span class="keywordtype">double</span>* psf_peak)
+<a name="l02170"></a>02170 {
+<a name="l02171"></a>02171 
+<a name="l02172"></a>02172   <span class="keywordtype">int</span> bin=SINFO_PSF_BIN;
+<a name="l02173"></a>02173   <span class="keywordtype">int</span> npoints=SINFO_PSF_NPOINT;
+<a name="l02174"></a>02174 
+<a name="l02175"></a>02175   <span class="keywordtype">int</span> dim=SINFO_PSF_DIM;
+<a name="l02176"></a>02176   <span class="keywordtype">int</span> blocks=SINFO_PSF_BLOCKS;
+<a name="l02177"></a>02177   <span class="keywordtype">int</span> sx=dim;
+<a name="l02178"></a>02178   <span class="keywordtype">int</span> sy=dim;
+<a name="l02179"></a>02179 
+<a name="l02180"></a>02180 
+<a name="l02181"></a>02181   <span class="keywordtype">int</span> i=0;
+<a name="l02182"></a>02182   <span class="keywordtype">int</span> j=0;
+<a name="l02183"></a>02183   <span class="keywordtype">double</span> k=0;
+<a name="l02184"></a>02184 
+<a name="l02185"></a>02185   <span class="keywordtype">int</span> ii=0;
+<a name="l02186"></a>02186   <span class="keywordtype">int</span> jj=0;
+<a name="l02187"></a>02187   <span class="keywordtype">int</span> start=0;
+<a name="l02188"></a>02188 
+<a name="l02189"></a>02189   <span class="keywordtype">double</span> nyquist=lambda/dia/2.*206265/psize*bin;
+<a name="l02190"></a>02190   <span class="keywordtype">double</span> cor=0.;
+<a name="l02191"></a>02191   <span class="keywordtype">double</span> v0=0;
+<a name="l02192"></a>02192   <span class="keywordtype">double</span> ll[npoints];
+<a name="l02193"></a>02193   <span class="keywordtype">double</span> part[npoints];
+<a name="l02194"></a>02194   <span class="keywordtype">double</span> ee;
+<a name="l02195"></a>02195   <span class="keywordtype">double</span> dll=0;
+<a name="l02196"></a>02196   <span class="keywordtype">double</span> tot1=0;
+<a name="l02197"></a>02197   <span class="keywordtype">double</span> tot2=0;
+<a name="l02198"></a>02198 
+<a name="l02199"></a>02199 
+<a name="l02200"></a>02200   <span class="keywordtype">double</span> fct=0;
+<a name="l02201"></a>02201 
+<a name="l02202"></a>02202   <span class="keywordtype">double</span>* pxx=NULL;
+<a name="l02203"></a>02203   <span class="keywordtype">double</span>* pyy=NULL;
+<a name="l02204"></a>02204   <span class="keywordtype">double</span>* prr=NULL;
+<a name="l02205"></a>02205   <span class="keywordtype">double</span>* ppsf0=NULL;
+<a name="l02206"></a>02206 
+<a name="l02207"></a>02207   <span class="keywordtype">double</span>* pcor=NULL;
+<a name="l02208"></a>02208   <span class="keywordtype">double</span>* pairy=NULL;
+<a name="l02209"></a>02209   <span class="keywordtype">double</span>* pw=NULL;
+<a name="l02210"></a>02210 
+<a name="l02211"></a>02211   cpl_image* img_xx=NULL;
+<a name="l02212"></a>02212   cpl_image* img_yy=NULL;
+<a name="l02213"></a>02213   cpl_image* img_rr=NULL;
+<a name="l02214"></a>02214   cpl_image* img_rrcor=NULL;
+<a name="l02215"></a>02215   cpl_image* img_airy=NULL;
+<a name="l02216"></a>02216   cpl_image* img_w=NULL;
+<a name="l02217"></a>02217   cpl_image* img_psf0=NULL;
+<a name="l02218"></a>02218 
+<a name="l02219"></a>02219 
+<a name="l02220"></a>02220 
+<a name="l02221"></a>02221   <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"lambda=%g"</span>,lambda);
+<a name="l02222"></a>02222   <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"dia=%f"</span>,dia);
+<a name="l02223"></a>02223   <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"psize=%f"</span>,psize);
+<a name="l02224"></a>02224   <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"bin=%d"</span>,bin);
+<a name="l02225"></a>02225   <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"nyquist=%f"</span>,nyquist);
+<a name="l02226"></a>02226 
+<a name="l02227"></a>02227   check_nomsg(img_xx=cpl_image_new(sx,sy,CPL_TYPE_DOUBLE));
+<a name="l02228"></a>02228   img_yy=cpl_image_new(sx,sy,CPL_TYPE_DOUBLE);
+<a name="l02229"></a>02229   img_rr=cpl_image_new(sx,sy,CPL_TYPE_DOUBLE);
+<a name="l02230"></a>02230   img_rrcor=cpl_image_new(sx,sy,CPL_TYPE_DOUBLE);
+<a name="l02231"></a>02231 
+<a name="l02232"></a>02232   pxx=cpl_image_get_data_double(img_xx);
+<a name="l02233"></a>02233   pyy=cpl_image_get_data_double(img_yy);
+<a name="l02234"></a>02234   prr=cpl_image_get_data_double(img_rr);
+<a name="l02235"></a>02235 
+<a name="l02236"></a>02236   <span class="keywordflow">for</span>(j=0;j<sy;j++) {
+<a name="l02237"></a>02237     <span class="keywordflow">for</span>(i=0;i<sx;i++) {
+<a name="l02238"></a>02238       <span class="comment">//xz plane increasing along y</span>
+<a name="l02239"></a>02239       pxx[j*sx+i]=(i-sx/2-cx*bin)/nyquist*SINFO_MATH_PI/2;
+<a name="l02240"></a>02240       <span class="comment">//yz plane increasing along x</span>
+<a name="l02241"></a>02241       pyy[j*sx+i]=(j-sy/2-cy*bin)/nyquist*SINFO_MATH_PI/2*anamorph;
+<a name="l02242"></a>02242 
+<a name="l02243"></a>02243       <span class="comment">//combinex xyz surface</span>
+<a name="l02244"></a>02244       prr[j*sx+i]=sqrt(pxx[j*sx+i]*pxx[j*sx+i]+pyy[j*sx+i]*pyy[j*sx+i]);
+<a name="l02245"></a>02245     }
+<a name="l02246"></a>02246   }
+<a name="l02247"></a>02247 
+<a name="l02248"></a>02248   <span class="comment">/*</span>
+<a name="l02249"></a>02249 <span class="comment">  check_nomsg(cpl_image_save(img_xx,"out_xx.fits", CPL_BPP_IEEE_DOUBLE,</span>
+<a name="l02250"></a>02250 <span class="comment">                 NULL,CPL_IO_DEFAULT));</span>
+<a name="l02251"></a>02251 <span class="comment"></span>
+<a name="l02252"></a>02252 <span class="comment">  check_nomsg(cpl_image_save(img_yy,"out_yy.fits", CPL_BPP_IEEE_DOUBLE,</span>
+<a name="l02253"></a>02253 <span class="comment">                 NULL,CPL_IO_DEFAULT));</span>
+<a name="l02254"></a>02254 <span class="comment"></span>
+<a name="l02255"></a>02255 <span class="comment">  check_nomsg(cpl_image_save(img_rr,"out_rr.fits", CPL_BPP_IEEE_DOUBLE,</span>
+<a name="l02256"></a>02256 <span class="comment">                 NULL,CPL_IO_DEFAULT));</span>
+<a name="l02257"></a>02257 <span class="comment"></span>
+<a name="l02258"></a>02258 <span class="comment">  */</span>
+<a name="l02259"></a>02259 
+<a name="l02260"></a>02260   img_rrcor=cpl_image_new(sx,sy,CPL_TYPE_DOUBLE);
+<a name="l02261"></a>02261 
+<a name="l02262"></a>02262   cor=1./(1.-occ*occ);
+<a name="l02263"></a>02263   cor*=cor;
+<a name="l02264"></a>02264 
+<a name="l02265"></a>02265   img_rrcor=cpl_image_duplicate(img_rr);
+<a name="l02266"></a>02266   cpl_image_multiply_scalar(img_rrcor,cor);
+<a name="l02267"></a>02267   pcor=cpl_image_get_data_double(img_rrcor);
+<a name="l02268"></a>02268 
+<a name="l02269"></a>02269   <span class="comment">/*</span>
+<a name="l02270"></a>02270 <span class="comment">  check_nomsg(cpl_image_save(img_rrcor,"out_rrcor.fits", CPL_BPP_IEEE_DOUBLE,</span>
+<a name="l02271"></a>02271 <span class="comment">                 NULL,CPL_IO_DEFAULT));</span>
+<a name="l02272"></a>02272 <span class="comment">  */</span>
+<a name="l02273"></a>02273 
+<a name="l02274"></a>02274   img_airy=cpl_image_new(sx,sy,CPL_TYPE_DOUBLE);
+<a name="l02275"></a>02275   pairy=cpl_image_get_data_double(img_airy);
+<a name="l02276"></a>02276 
+<a name="l02277"></a>02277 
+<a name="l02278"></a>02278   <span class="keywordflow">if</span> (occ == 0.0) {
+<a name="l02279"></a>02279 
+<a name="l02280"></a>02280     <span class="keywordflow">for</span>(j=0;j<sx;j++) {
+<a name="l02281"></a>02281       <span class="keywordflow">for</span>(i=0;i<sy;i++) {
+<a name="l02282"></a>02282     fct=(2.*j1(prr[j*sx+i])/prr[j*sx+i]);
+<a name="l02283"></a>02283     pairy[j*sx+i]=fct*fct;
+<a name="l02284"></a>02284 
+<a name="l02285"></a>02285       }
+<a name="l02286"></a>02286     }
+<a name="l02287"></a>02287 
+<a name="l02288"></a>02288   } <span class="keywordflow">else</span> {
+<a name="l02289"></a>02289     <span class="keywordflow">for</span>(j=0;j<sy;j++) {
+<a name="l02290"></a>02290       <span class="keywordflow">for</span>(i=0;i<sx;i++) {
+<a name="l02291"></a>02291 
+<a name="l02292"></a>02292     fct=(2.*j1(prr[j*sx+i])/prr[j*sx+i]-occ*occ*2.*j1(pcor[j*sx+i])/pcor[j*sx+i]);
+<a name="l02293"></a>02293     pairy[j*sx+i]=cor*fct*fct;
+<a name="l02294"></a>02294 
+<a name="l02295"></a>02295       }
+<a name="l02296"></a>02296     }
+<a name="l02297"></a>02297   }
+<a name="l02298"></a>02298 
+<a name="l02299"></a>02299   <span class="comment">/*</span>
+<a name="l02300"></a>02300 <span class="comment">  check_nomsg(cpl_image_save(img_airy,"out_airy.fits", CPL_BPP_IEEE_DOUBLE,</span>
+<a name="l02301"></a>02301 <span class="comment">                 NULL,CPL_IO_DEFAULT));</span>
+<a name="l02302"></a>02302 <span class="comment"></span>
+<a name="l02303"></a>02303 <span class="comment">  */</span>
+<a name="l02304"></a>02304 
+<a name="l02305"></a>02305   <span class="comment">//To remove an expected NAN value at the PSF centre we re-set PSF(centre)=1</span>
+<a name="l02306"></a>02306   img_w=cpl_image_duplicate(img_airy);
+<a name="l02307"></a>02307   pw=cpl_image_get_data_double(img_w);
+<a name="l02308"></a>02308   pairy=cpl_image_get_data_double(img_airy);
+<a name="l02309"></a>02309 
+<a name="l02310"></a>02310   <span class="keywordflow">for</span>(j=0;j<sy;j++) {
+<a name="l02311"></a>02311     <span class="keywordflow">for</span>(i=0;i<sx;i++) {
+<a name="l02312"></a>02312       <span class="keywordflow">if</span>(!<a class="code" href="group__irplib__utils.html#ga804bfc739b5d55f9797ab881b1034ae4" title="portable isnan">irplib_isnan</a>(pairy[i+j*sx]) && (pairy[i+j*sx] ==0)) {
+<a name="l02313"></a>02313     pairy[i+j*sx]=1.;
+<a name="l02314"></a>02314         <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"====> %f"</span>,pairy[i+j*sx]);
+<a name="l02315"></a>02315       }
+<a name="l02316"></a>02316     }
+<a name="l02317"></a>02317   }
+<a name="l02318"></a>02318   pairy[sx/2+sy/2*sx]=1.;
+<a name="l02319"></a>02319 
+<a name="l02320"></a>02320   <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"total-airy=%f"</span>,cpl_image_get_flux(img_airy));
+<a name="l02321"></a>02321 
+<a name="l02322"></a>02322   <span class="comment">/*</span>
+<a name="l02323"></a>02323 <span class="comment">  check_nomsg(cpl_image_save(img_airy,"out_airy1.fits", CPL_BPP_IEEE_DOUBLE,</span>
+<a name="l02324"></a>02324 <span class="comment">                 NULL,CPL_IO_DEFAULT));</span>
+<a name="l02325"></a>02325 <span class="comment"></span>
+<a name="l02326"></a>02326 <span class="comment">  */</span>
+<a name="l02327"></a>02327 
+<a name="l02328"></a>02328 
+<a name="l02329"></a>02329   <span class="comment">// Computation of EE</span>
+<a name="l02330"></a>02330 
+<a name="l02331"></a>02331 
+<a name="l02332"></a>02332   v0=prr[0+dim/4-1];
+<a name="l02333"></a>02333   <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"v0=%12.10g"</span>,v0);
+<a name="l02334"></a>02334   <span class="keywordflow">for</span>(i=0;i<npoints;i++) {
+<a name="l02335"></a>02335     ll[i]=(double)i/npoints*v0;
+<a name="l02336"></a>02336    }
+<a name="l02337"></a>02337   dll=ll[1]-ll[0];
+<a name="l02338"></a>02338   cor=1./(1.-occ*occ);
+<a name="l02339"></a>02339 
+<a name="l02340"></a>02340   <span class="keywordflow">for</span>(i=0;i<npoints;i++) {
+<a name="l02341"></a>02341     part[i]=2.*j1(ll[i])/ll[i];
+<a name="l02342"></a>02342   }
+<a name="l02343"></a>02343   part[0]=1.0;
+<a name="l02344"></a>02344 
+<a name="l02345"></a>02345   tot1=0.;
+<a name="l02346"></a>02346   <span class="keywordflow">for</span>(i=0;i<npoints;i++) {
+<a name="l02347"></a>02347     tot1+=j1(occ*ll[i])*part[i]*dll;
+<a name="l02348"></a>02348   }
+<a name="l02349"></a>02349   <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"tot=%10.8f"</span>,tot1);
+<a name="l02350"></a>02350 
+<a name="l02351"></a>02351 
+<a name="l02352"></a>02352   <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"cor=%10.8f"</span>,cor);
+<a name="l02353"></a>02353 
+<a name="l02354"></a>02354   ee=(1.-j0(v0)*j0(v0));
+<a name="l02355"></a>02355 
+<a name="l02356"></a>02356   <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"(1-j0(v0)*j0(v0))=%10.8f"</span>,ee);
+<a name="l02357"></a>02357 
+<a name="l02358"></a>02358 
+<a name="l02359"></a>02359   ee-=(j1(v0))*(j1(v0));
+<a name="l02360"></a>02360   <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"j1^2=%10.8f"</span>,(j1(v0))*(j1(v0)));
+<a name="l02361"></a>02361   <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"ee=%10.8f"</span>,ee);
+<a name="l02362"></a>02362 
+<a name="l02363"></a>02363   <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"factor=%10.8f"</span>,
+<a name="l02364"></a>02364           occ*occ*(1-j0(occ*v0)*j0(occ*v0)-j1(occ*v0)*j1(occ*v0)));
+<a name="l02365"></a>02365 
+<a name="l02366"></a>02366 
+<a name="l02367"></a>02367   ee+=occ*occ*(1-j0(occ*v0)*j0(occ*v0)-j1(occ*v0)*j1(occ*v0));
+<a name="l02368"></a>02368   <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"ee=%10.8f"</span>,ee);
+<a name="l02369"></a>02369 
+<a name="l02370"></a>02370   ee-=2.*occ*tot1;
+<a name="l02371"></a>02371   <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"ee=%10.8f"</span>,ee);
+<a name="l02372"></a>02372 
+<a name="l02373"></a>02373   ee*=cor;
+<a name="l02374"></a>02374   <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"ee=%10.8f"</span>,ee);
+<a name="l02375"></a>02375 
+<a name="l02376"></a>02376 
+<a name="l02377"></a>02377   tot1=0;
+<a name="l02378"></a>02378   pairy=cpl_image_get_data_double(img_airy);
+<a name="l02379"></a>02379   prr=cpl_image_get_data_double(img_rr);
+<a name="l02380"></a>02380   <span class="keywordflow">for</span>(j=0;j<sy;j++) {
+<a name="l02381"></a>02381     <span class="keywordflow">for</span>(i=0;i<sx;i++) {
+<a name="l02382"></a>02382       <span class="keywordflow">if</span>(!<a class="code" href="group__irplib__utils.html#ga804bfc739b5d55f9797ab881b1034ae4" title="portable isnan">irplib_isnan</a>(pairy[i+j*sx]) && (prr[i+j*sx] <v0)) {
+<a name="l02383"></a>02383     tot1+=pairy[i+j*sx]*ee;
+<a name="l02384"></a>02384     <span class="comment">//sinfo_msg_debug("tot=%f",tot1);</span>
+<a name="l02385"></a>02385 
+<a name="l02386"></a>02386       }
+<a name="l02387"></a>02387     }
+<a name="l02388"></a>02388   }
+<a name="l02389"></a>02389 
+<a name="l02390"></a>02390   <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"tot=%10.8f"</span>,tot1);
+<a name="l02391"></a>02391   cpl_image_divide_scalar(img_airy,tot1);
+<a name="l02392"></a>02392 
+<a name="l02393"></a>02393   <span class="comment">/*</span>
+<a name="l02394"></a>02394 <span class="comment">  check_nomsg(cpl_image_save(img_airy,"out_airy2.fits", CPL_BPP_IEEE_DOUBLE,</span>
+<a name="l02395"></a>02395 <span class="comment">                 NULL,CPL_IO_DEFAULT));</span>
+<a name="l02396"></a>02396 <span class="comment"></span>
+<a name="l02397"></a>02397 <span class="comment">  */</span>
+<a name="l02398"></a>02398 
+<a name="l02399"></a>02399 
+<a name="l02400"></a>02400   <span class="comment">// Computation of maximum</span>
+<a name="l02401"></a>02401 
+<a name="l02402"></a>02402   <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"dim=%d blocks=%d,bin=%d"</span>,dim,blocks,bin);
+<a name="l02403"></a>02403   start=(dim/2-1)-(blocks/2*bin-1)-bin/2;
+<a name="l02404"></a>02404   <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"start=%d"</span>,start);
+<a name="l02405"></a>02405 
+<a name="l02406"></a>02406   img_psf0=cpl_image_new(blocks,blocks,CPL_TYPE_DOUBLE);
+<a name="l02407"></a>02407   ppsf0=cpl_image_get_data_double(img_psf0);
+<a name="l02408"></a>02408   tot1=0.;
+<a name="l02409"></a>02409   tot2=0.;
+<a name="l02410"></a>02410 
+<a name="l02411"></a>02411   <span class="keywordflow">for</span>(j=0;j<blocks;j++) {
+<a name="l02412"></a>02412     <span class="keywordflow">for</span>(i=0;i<blocks;i++) {
+<a name="l02413"></a>02413       tot1=0;
+<a name="l02414"></a>02414       <span class="keywordflow">for</span>(jj=start+j*bin;jj<start+(j+1)*bin-1;jj++){
+<a name="l02415"></a>02415     <span class="keywordflow">for</span>(ii=start+i*bin;ii<start+(i+1)*bin-1;ii++){
+<a name="l02416"></a>02416           <span class="keywordflow">if</span>(!<a class="code" href="group__irplib__utils.html#ga804bfc739b5d55f9797ab881b1034ae4" title="portable isnan">irplib_isnan</a>(pairy[ii+jj*sx])) {
+<a name="l02417"></a>02417         tot1+=pairy[ii+jj*sx];
+<a name="l02418"></a>02418       }
+<a name="l02419"></a>02419     }
+<a name="l02420"></a>02420       }
+<a name="l02421"></a>02421       ppsf0[i+j*blocks]=tot1;
+<a name="l02422"></a>02422       tot2+=tot1;
+<a name="l02423"></a>02423     }
+<a name="l02424"></a>02424   }
+<a name="l02425"></a>02425 
+<a name="l02426"></a>02426   cpl_image_divide_scalar(img_psf0,tot2);
+<a name="l02427"></a>02427   <span class="comment">/*</span>
+<a name="l02428"></a>02428 <span class="comment">  check_nomsg(cpl_image_save(img_psf0,"out_psf0.fits", CPL_BPP_IEEE_DOUBLE,</span>
+<a name="l02429"></a>02429 <span class="comment">                 NULL,CPL_IO_DEFAULT));</span>
+<a name="l02430"></a>02430 <span class="comment"></span>
+<a name="l02431"></a>02431 <span class="comment">  */</span>
+<a name="l02432"></a>02432   k=180.*3600./SINFO_MATH_PI;
+<a name="l02433"></a>02433   <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"k=%f"</span>,k);
+<a name="l02434"></a>02434   <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"radius of first zero: 1.22*lambda/d*k:=%f"</span>,
+<a name="l02435"></a>02435             1.22*lambda/dia*k);
+<a name="l02436"></a>02436   <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"tot: %f"</span>,tot2);
+<a name="l02437"></a>02437   <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"max: %f"</span>,cpl_image_get_max(img_psf0)*tot2);
+<a name="l02438"></a>02438   <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"max/tot: %f"</span>,cpl_image_get_max(img_psf0));
+<a name="l02439"></a>02439   *psf_peak=cpl_image_get_max(img_psf0);
+<a name="l02440"></a>02440 
+<a name="l02441"></a>02441   <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"d=%g ob=%g w=%g ps=%g cx=%g cy=%g a=%g peak=%10.8g"</span>,
+<a name="l02442"></a>02442             dia,occ,lambda,psize,cx,cy,anamorph,*psf_peak);
+<a name="l02443"></a>02443 
+<a name="l02444"></a>02444 
+<a name="l02445"></a>02445 
+<a name="l02446"></a>02446  cleanup:
+<a name="l02447"></a>02447   sinfo_free_image(&img_xx);
+<a name="l02448"></a>02448   sinfo_free_image(&img_yy);
+<a name="l02449"></a>02449   sinfo_free_image(&img_rr);
+<a name="l02450"></a>02450   sinfo_free_image(&img_rrcor);
+<a name="l02451"></a>02451   sinfo_free_image(&img_airy);
+<a name="l02452"></a>02452 
+<a name="l02453"></a>02453 
+<a name="l02454"></a>02454   <span class="keywordflow">if</span> (cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l02455"></a>02455     <span class="keywordflow">return</span> cpl_error_get_code();
+<a name="l02456"></a>02456   } <span class="keywordflow">else</span> {
+<a name="l02457"></a>02457     <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l02458"></a>02458   }
+<a name="l02459"></a>02459 
+<a name="l02460"></a>02460 }
+<a name="l02461"></a>02461 
+<a name="l02462"></a>02462 
+<a name="l02463"></a>02463 cpl_error_code
+<a name="l02464"></a>02464 sinfo_get_flux_above_bkg(<span class="keyword">const</span> cpl_image* img,
+<a name="l02465"></a>02465                          <span class="keyword">const</span> <span class="keywordtype">float</span> kappa,
+<a name="l02466"></a>02466                          <span class="keyword">const</span> <span class="keywordtype">float</span> std,
+<a name="l02467"></a>02467                          <span class="keywordtype">double</span>* f)
+<a name="l02468"></a>02468 {
+<a name="l02469"></a>02469 
+<a name="l02470"></a>02470   <span class="keyword">const</span> <span class="keywordtype">float</span>* pimg=NULL;
+<a name="l02471"></a>02471   <span class="keywordtype">int</span> sx=0;
+<a name="l02472"></a>02472   <span class="keywordtype">int</span> sy=0;
+<a name="l02473"></a>02473   <span class="keywordtype">int</span> i=0;
+<a name="l02474"></a>02474   <span class="keywordtype">int</span> j=0;
+<a name="l02475"></a>02475   <span class="keywordtype">int</span> k=0;
+<a name="l02476"></a>02476   <span class="keywordtype">float</span> tot=0;
+<a name="l02477"></a>02477 
+<a name="l02478"></a>02478   cpl_image* timg=NULL;
+<a name="l02479"></a>02479   <span class="keywordtype">double</span> sky_bkg=0;
+<a name="l02480"></a>02480   <span class="keywordtype">double</span> sky_std=0;
+<a name="l02481"></a>02481 
+<a name="l02482"></a>02482   timg=cpl_image_duplicate(img);
+<a name="l02483"></a>02483   cpl_image_subtract_scalar(timg,std);
+<a name="l02484"></a>02484   check_nomsg(sinfo_get_bkg_4corners(timg,SINFO_BKG_BOX_SZ,SINFO_BKG_BOX_SZ,
+<a name="l02485"></a>02485                      &sky_bkg,&sky_std));
+<a name="l02486"></a>02486 
+<a name="l02487"></a>02487   check_nomsg(pimg=cpl_image_get_data_float_const(timg));
+<a name="l02488"></a>02488 
+<a name="l02489"></a>02489   sx=cpl_image_get_size_x(img);
+<a name="l02490"></a>02490   sy=cpl_image_get_size_y(img);
+<a name="l02491"></a>02491 
+<a name="l02492"></a>02492   <span class="keywordflow">for</span>(j=0;j<sy;j++) {
+<a name="l02493"></a>02493     <span class="keywordflow">for</span>(i=0;i<sx;i++) {
+<a name="l02494"></a>02494       <span class="keywordflow">if</span>(!<a class="code" href="group__irplib__utils.html#ga804bfc739b5d55f9797ab881b1034ae4" title="portable isnan">irplib_isnan</a>(pimg[i+j*sx]) &&
+<a name="l02495"></a>02495           (pimg[i+j*sx]>(sky_bkg+kappa*sky_std))) {
+<a name="l02496"></a>02496     tot+=(double)pimg[i+j*sx];
+<a name="l02497"></a>02497     k++;
+<a name="l02498"></a>02498       }
+<a name="l02499"></a>02499     }
+<a name="l02500"></a>02500   }
+<a name="l02501"></a>02501 
+<a name="l02502"></a>02502   *f=(double)(tot-k*sky_bkg);
+<a name="l02503"></a>02503 
+<a name="l02504"></a>02504  cleanup:
+<a name="l02505"></a>02505   sinfo_free_image(&timg);
+<a name="l02506"></a>02506 
+<a name="l02507"></a>02507   <span class="keywordflow">if</span> (cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l02508"></a>02508     <span class="keywordflow">return</span> cpl_error_get_code();
+<a name="l02509"></a>02509   } <span class="keywordflow">else</span> {
+<a name="l02510"></a>02510     <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l02511"></a>02511   }
+<a name="l02512"></a>02512 
+<a name="l02513"></a>02513 }
+<a name="l02514"></a>02514 
+<a name="l02515"></a>02515 
+<a name="l02516"></a>02516 
+<a name="l02517"></a>02517 <span class="comment">/*</span>
+<a name="l02518"></a>02518 <span class="comment">cpl_error_code</span>
+<a name="l02519"></a>02519 <span class="comment">sinfo_get_centroid(const cpl_image* img,</span>
+<a name="l02520"></a>02520 <span class="comment">                   const int d,</span>
+<a name="l02521"></a>02521 <span class="comment">                   const double xc,</span>
+<a name="l02522"></a>02522 <span class="comment">                   const double yc,</span>
+<a name="l02523"></a>02523 <span class="comment">                   double* xcen,</span>
+<a name="l02524"></a>02524 <span class="comment">                   double* ycen,</span>
+<a name="l02525"></a>02525 <span class="comment">                   double* xfwhm,</span>
+<a name="l02526"></a>02526 <span class="comment">                   double* yfwhm,</span>
+<a name="l02527"></a>02527 <span class="comment">                   double* angle)</span>
+<a name="l02528"></a>02528 <span class="comment">{</span>
+<a name="l02529"></a>02529 <span class="comment"></span>
+<a name="l02530"></a>02530 <span class="comment">  cpl_bivector* q=NULL;</span>
+<a name="l02531"></a>02531 <span class="comment">  int sx=0;</span>
+<a name="l02532"></a>02532 <span class="comment">  int sy=0;</span>
+<a name="l02533"></a>02533 <span class="comment">  double* pq=NULL;</span>
+<a name="l02534"></a>02534 <span class="comment">  double peak=0;</span>
+<a name="l02535"></a>02535 <span class="comment">  double bkg=0;</span>
+<a name="l02536"></a>02536 <span class="comment"></span>
+<a name="l02537"></a>02537 <span class="comment">  check_nomsg(sx=cpl_image_get_size_x(img));</span>
+<a name="l02538"></a>02538 <span class="comment">  check_nomsg(sy=cpl_image_get_size_y(img));</span>
+<a name="l02539"></a>02539 <span class="comment"></span>
+<a name="l02540"></a>02540 <span class="comment">  check_nomsg(q=cpl_image_iqe(img,sx/2-d,sy/2-d,sx/2+d,sy/2+d));</span>
+<a name="l02541"></a>02541 <span class="comment">  pq=cpl_bivector_get_data(q);</span>
+<a name="l02542"></a>02542 <span class="comment"></span>
+<a name="l02543"></a>02543 <span class="comment">  *xcen=pq[0];</span>
+<a name="l02544"></a>02544 <span class="comment">  *ycen=pq[1];</span>
+<a name="l02545"></a>02545 <span class="comment">  *xfwhm=pq[2];</span>
+<a name="l02546"></a>02546 <span class="comment">  *yfwhm=pq[3];</span>
+<a name="l02547"></a>02547 <span class="comment">  *angle=pq[4];</span>
+<a name="l02548"></a>02548 <span class="comment">  peak=pq[5];</span>
+<a name="l02549"></a>02549 <span class="comment">  bkg=pq[6];</span>
+<a name="l02550"></a>02550 <span class="comment"></span>
+<a name="l02551"></a>02551 <span class="comment"></span>
+<a name="l02552"></a>02552 <span class="comment"> cleanup:</span>
+<a name="l02553"></a>02553 <span class="comment"></span>
+<a name="l02554"></a>02554 <span class="comment">  sinfo_free_bivector(&q);</span>
+<a name="l02555"></a>02555 <span class="comment"></span>
+<a name="l02556"></a>02556 <span class="comment">  if (cpl_error_get_code() != CPL_ERROR_NONE) {</span>
+<a name="l02557"></a>02557 <span class="comment">    return cpl_error_get_code();</span>
+<a name="l02558"></a>02558 <span class="comment">  } else {</span>
+<a name="l02559"></a>02559 <span class="comment">    return CPL_ERROR_NONE;</span>
+<a name="l02560"></a>02560 <span class="comment">  }</span>
+<a name="l02561"></a>02561 <span class="comment"></span>
+<a name="l02562"></a>02562 <span class="comment">}</span>
+<a name="l02563"></a>02563 <span class="comment">*/</span>
+<a name="l02564"></a>02564 
+<a name="l02565"></a>02565 
+<a name="l02566"></a>02566 
+<a name="l02567"></a>02567 <span class="keyword">static</span> <span class="keywordtype">double</span>
+<a name="l02568"></a>02568 sinfo_find_min_of_four(<span class="keyword">const</span> <span class="keywordtype">double</span> n1,
+<a name="l02569"></a>02569                        <span class="keyword">const</span> <span class="keywordtype">double</span> n2,
+<a name="l02570"></a>02570                        <span class="keyword">const</span> <span class="keywordtype">double</span> n3,
+<a name="l02571"></a>02571                        <span class="keyword">const</span> <span class="keywordtype">double</span> n4)
+<a name="l02572"></a>02572 {
+<a name="l02573"></a>02573   <span class="keywordtype">double</span> min=0;
+<a name="l02574"></a>02574   min = (n1 < n2) ? n1 : n2;
+<a name="l02575"></a>02575   min = (min < n3) ? min : n3;
+<a name="l02576"></a>02576   min = (min < n4) ? min : n4;
+<a name="l02577"></a>02577   <span class="keywordflow">return</span> min;
+<a name="l02578"></a>02578 }
+<a name="l02579"></a>02579 
+<a name="l02580"></a>02580 <span class="keywordtype">double</span>
+<a name="l02581"></a>02581 sinfo_scale_flux(<span class="keyword">const</span> <span class="keywordtype">double</span> p1,
+<a name="l02582"></a>02582                  <span class="keyword">const</span> <span class="keywordtype">double</span> p2,
+<a name="l02583"></a>02583                  <span class="keyword">const</span> <span class="keywordtype">double</span> t1,
+<a name="l02584"></a>02584                  <span class="keyword">const</span> <span class="keywordtype">double</span> t2)
+<a name="l02585"></a>02585 {
+<a name="l02586"></a>02586 
+<a name="l02587"></a>02587   <span class="keywordflow">return</span> (p2/p1)*(p2/p1)*(t2/t1);
+<a name="l02588"></a>02588 
+<a name="l02589"></a>02589 }
+<a name="l02590"></a>02590 
+<a name="l02591"></a>02591 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__new__psf_8h_source.html b/html/sinfo__new__psf_8h_source.html
new file mode 100644
index 0000000..f755a25
--- /dev/null
+++ b/html/sinfo__new__psf_8h_source.html
@@ -0,0 +1,171 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_new_psf.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_new_psf.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#ifndef SINFO_NEW_PSF_H</span>
+<a name="l00002"></a>00002 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_NEW_PSF_H</span>
+<a name="l00003"></a>00003 <span class="preprocessor"></span><span class="comment">/*</span>
+<a name="l00004"></a>00004 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00005"></a>00005 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00006"></a>00006 <span class="comment"> *</span>
+<a name="l00007"></a>00007 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00008"></a>00008 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00009"></a>00009 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00010"></a>00010 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00011"></a>00011 <span class="comment"> *</span>
+<a name="l00012"></a>00012 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00013"></a>00013 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00014"></a>00014 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00015"></a>00015 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00016"></a>00016 <span class="comment"> *</span>
+<a name="l00017"></a>00017 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00018"></a>00018 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00019"></a>00019 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00020"></a>00020 <span class="comment"> */</span>
+<a name="l00021"></a>00021 <span class="comment">/*****************************************************************************</span>
+<a name="l00022"></a>00022 <span class="comment">* E.S.O. - VLT project</span>
+<a name="l00023"></a>00023 <span class="comment">*</span>
+<a name="l00024"></a>00024 <span class="comment">* "@(#) $Id: sinfo_new_psf.h,v 1.12 2008/02/12 16:33:50 amodigli Exp $"</span>
+<a name="l00025"></a>00025 <span class="comment">*</span>
+<a name="l00026"></a>00026 <span class="comment">* who       when      what</span>
+<a name="l00027"></a>00027 <span class="comment">* --------  --------  ----------------------------------------------</span>
+<a name="l00028"></a>00028 <span class="comment">* amodigli  17/09/03  created</span>
+<a name="l00029"></a>00029 <span class="comment">*/</span>
+<a name="l00030"></a>00030 
+<a name="l00031"></a>00031 <span class="comment">/************************************************************************</span>
+<a name="l00032"></a>00032 <span class="comment"> * sinfo_new_psf.h</span>
+<a name="l00033"></a>00033 <span class="comment"></span>
+<a name="l00034"></a>00034 <span class="comment"> sinfo_psf.py does the image reconstruction of a set of sky-subtracted, </span>
+<a name="l00035"></a>00035 <span class="comment"> flatfielded, </span>
+<a name="l00036"></a>00036 <span class="comment"> bad pixel corrected and slope of the spectra aligned exposures of a bright </span>
+<a name="l00037"></a>00037 <span class="comment"> star with continuum spectrum. The resulting image can be used to determine </span>
+<a name="l00038"></a>00038 <span class="comment"> the PSF</span>
+<a name="l00039"></a>00039 <span class="comment"> *----------------------------------------------------------------------</span>
+<a name="l00040"></a>00040 <span class="comment"> */</span>
+<a name="l00041"></a>00041 
+<a name="l00042"></a>00042 <span class="comment">/*</span>
+<a name="l00043"></a>00043 <span class="comment"> * header files</span>
+<a name="l00044"></a>00044 <span class="comment"> */</span>
+<a name="l00045"></a>00045 
+<a name="l00046"></a>00046 <span class="preprocessor">#include <cpl.h></span> 
+<a name="l00047"></a>00047 <span class="preprocessor">#include <irplib_strehl.h></span>
+<a name="l00048"></a>00048 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00049"></a>00049 
+<a name="l00050"></a>00050 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00051"></a>00051 <span class="comment"> *                        Function ANSI C prototypes</span>
+<a name="l00052"></a>00052 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00053"></a>00053 
+<a name="l00054"></a>00054 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00055"></a>00055 <span class="comment">   Function     :       sinfo_new_psf()</span>
+<a name="l00056"></a>00056 <span class="comment">   In           :       ini_file: file name of according .ini file</span>
+<a name="l00057"></a>00057 <span class="comment">   Out          :       integer (0 if it worked, -1 if it doesn't) </span>
+<a name="l00058"></a>00058 <span class="comment">   Job          :</span>
+<a name="l00059"></a>00059 <span class="comment"></span>
+<a name="l00060"></a>00060 <span class="comment"> sinfo_psf.py does the image reconstruction of a set of sky-subtracted, </span>
+<a name="l00061"></a>00061 <span class="comment"> flatfielded, bad pixel corrected and slope of the spectra aligned exposures </span>
+<a name="l00062"></a>00062 <span class="comment"> of a bright star with continuum spectrum. The resulting image can be used </span>
+<a name="l00063"></a>00063 <span class="comment"> to determine the PSF</span>
+<a name="l00064"></a>00064 <span class="comment"></span>
+<a name="l00065"></a>00065 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00066"></a>00066 <span class="keywordtype">int</span> 
+<a name="l00067"></a>00067 sinfo_new_psf(<span class="keyword">const</span> <span class="keywordtype">char</span>* plugin_id,
+<a name="l00068"></a>00068               cpl_parameterlist* config,
+<a name="l00069"></a>00069               cpl_frameset* sof,
+<a name="l00070"></a>00070               cpl_frameset* ref_set) ;
+<a name="l00071"></a>00071 
+<a name="l00072"></a>00072 
+<a name="l00073"></a>00073 <span class="keywordtype">int</span> sinfo_strehl_compute_two(
+<a name="l00074"></a>00074               <span class="keyword">const</span> cpl_image *   im1,
+<a name="l00075"></a>00075               <span class="keyword">const</span> cpl_image *   im2,
+<a name="l00076"></a>00076               <span class="keywordtype">double</span>              m1,
+<a name="l00077"></a>00077               <span class="keywordtype">double</span>              m2,
+<a name="l00078"></a>00078               <span class="keywordtype">double</span>              lam,
+<a name="l00079"></a>00079               <span class="keywordtype">double</span>              pscale1,
+<a name="l00080"></a>00080               <span class="keywordtype">double</span>              pscale2,
+<a name="l00081"></a>00081               <span class="keywordtype">double</span>              exptime1,
+<a name="l00082"></a>00082               <span class="keywordtype">double</span>              exptime2,
+<a name="l00083"></a>00083               <span class="keywordtype">int</span>                 xpos1,
+<a name="l00084"></a>00084               <span class="keywordtype">int</span>                 ypos1,
+<a name="l00085"></a>00085               <span class="keywordtype">int</span>                 xpos2,
+<a name="l00086"></a>00086               <span class="keywordtype">int</span>                 ypos2,
+<a name="l00087"></a>00087               <span class="keywordtype">double</span>              r1,
+<a name="l00088"></a>00088               <span class="keywordtype">double</span>              r2,
+<a name="l00089"></a>00089               <span class="keywordtype">double</span>              r3,
+<a name="l00090"></a>00090               <span class="keywordtype">double</span>          *   strehl,
+<a name="l00091"></a>00091               <span class="keywordtype">double</span>          *   strehl_err,
+<a name="l00092"></a>00092               <span class="keywordtype">double</span>          *   star_bg,
+<a name="l00093"></a>00093               <span class="keywordtype">double</span>          *   star_peak,
+<a name="l00094"></a>00094               <span class="keywordtype">double</span>          *   star_flux,
+<a name="l00095"></a>00095               <span class="keywordtype">double</span>          *   psf_peak,
+<a name="l00096"></a>00096               <span class="keywordtype">double</span>          *   psf_flux,
+<a name="l00097"></a>00097               <span class="keywordtype">double</span>          *   bg_noise);
+<a name="l00098"></a>00098 
+<a name="l00099"></a>00099 cpl_error_code 
+<a name="l00100"></a>00100 sinfo_strehl_compute_one(<span class="keyword">const</span> cpl_image *   im,
+<a name="l00101"></a>00101              <span class="keywordtype">double</span>              m1,
+<a name="l00102"></a>00102              <span class="keywordtype">double</span>              m2,
+<a name="l00103"></a>00103              <span class="keywordtype">double</span>              lam,
+<a name="l00104"></a>00104              <span class="keywordtype">double</span>              dlam,
+<a name="l00105"></a>00105              <span class="keywordtype">double</span>              pscale,
+<a name="l00106"></a>00106              <span class="keywordtype">int</span>                 xpos,
+<a name="l00107"></a>00107              <span class="keywordtype">int</span>                 ypos,
+<a name="l00108"></a>00108              <span class="keywordtype">double</span>              r1,
+<a name="l00109"></a>00109              <span class="keywordtype">double</span>              r2,
+<a name="l00110"></a>00110              <span class="keywordtype">double</span>              r3,
+<a name="l00111"></a>00111                          <span class="keywordtype">int</span>                 noise_box_sz,
+<a name="l00112"></a>00112              <span class="keywordtype">double</span>          *   strehl,
+<a name="l00113"></a>00113              <span class="keywordtype">double</span>          *   strehl_err,
+<a name="l00114"></a>00114              <span class="keywordtype">double</span>          *   star_bg,
+<a name="l00115"></a>00115              <span class="keywordtype">double</span>          *   star_peak,
+<a name="l00116"></a>00116              <span class="keywordtype">double</span>          *   star_flux,
+<a name="l00117"></a>00117              <span class="keywordtype">double</span>          *   psf_peak,
+<a name="l00118"></a>00118              <span class="keywordtype">double</span>          *   psf_flux,
+<a name="l00119"></a>00119              <span class="keywordtype">double</span>          *   bg_noise);
+<a name="l00120"></a>00120 
+<a name="l00121"></a>00121 
+<a name="l00122"></a>00122 
+<a name="l00123"></a>00123 
+<a name="l00124"></a>00124 cpl_error_code 
+<a name="l00125"></a>00125 sinfo_get_bkg_4corners(<span class="keyword">const</span> cpl_image *img,
+<a name="l00126"></a>00126                <span class="keyword">const</span> <span class="keywordtype">int</span> bkg_sx,
+<a name="l00127"></a>00127                        <span class="keyword">const</span> <span class="keywordtype">int</span> bkg_sy,
+<a name="l00128"></a>00128                        <span class="keywordtype">double</span>* bkg,
+<a name="l00129"></a>00129                        <span class="keywordtype">double</span>* std);
+<a name="l00130"></a>00130 
+<a name="l00131"></a>00131 cpl_error_code
+<a name="l00132"></a>00132 sinfo_compute_psf(<span class="keyword">const</span> <span class="keywordtype">double</span> dia, 
+<a name="l00133"></a>00133           <span class="keyword">const</span> <span class="keywordtype">double</span> occ,
+<a name="l00134"></a>00134           <span class="keyword">const</span> <span class="keywordtype">double</span> lambda,
+<a name="l00135"></a>00135           <span class="keyword">const</span> <span class="keywordtype">double</span> psize,
+<a name="l00136"></a>00136           <span class="keyword">const</span> <span class="keywordtype">double</span> cx,
+<a name="l00137"></a>00137           <span class="keyword">const</span> <span class="keywordtype">double</span> cy,
+<a name="l00138"></a>00138           <span class="keyword">const</span> <span class="keywordtype">double</span> anamorph,
+<a name="l00139"></a>00139           <span class="keywordtype">double</span>* psf_peak);
+<a name="l00140"></a>00140 cpl_error_code
+<a name="l00141"></a>00141 sinfo_get_flux_above_bkg(<span class="keyword">const</span> cpl_image* img, 
+<a name="l00142"></a>00142                          <span class="keyword">const</span> <span class="keywordtype">float</span> kappa, 
+<a name="l00143"></a>00143                          <span class="keyword">const</span> <span class="keywordtype">float</span> std, 
+<a name="l00144"></a>00144                          <span class="keywordtype">double</span>* f);
+<a name="l00145"></a>00145 
+<a name="l00146"></a>00146 
+<a name="l00147"></a>00147 <span class="keywordtype">double</span>
+<a name="l00148"></a>00148 sinfo_scale_flux(<span class="keyword">const</span> <span class="keywordtype">double</span> p1, 
+<a name="l00149"></a>00149                  <span class="keyword">const</span> <span class="keywordtype">double</span> p2, 
+<a name="l00150"></a>00150                  <span class="keyword">const</span> <span class="keywordtype">double</span> t1, 
+<a name="l00151"></a>00151                  <span class="keyword">const</span> <span class="keywordtype">double</span> t2);
+<a name="l00152"></a>00152 
+<a name="l00153"></a>00153 <span class="preprocessor">#endif </span>
+<a name="l00154"></a>00154 <span class="preprocessor"></span>
+<a name="l00155"></a>00155 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__new__resampling_8c_source.html b/html/sinfo__new__resampling_8c_source.html
new file mode 100644
index 0000000..6bfccb6
--- /dev/null
+++ b/html/sinfo__new__resampling_8c_source.html
@@ -0,0 +1,452 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_new_resampling.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_new_resampling.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 
+<a name="l00020"></a>00020 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00021"></a>00021 <span class="comment">   </span>
+<a name="l00022"></a>00022 <span class="comment">   File name     :    sinfo_new_resampling.c</span>
+<a name="l00023"></a>00023 <span class="comment">   Author         :    Nicolas Devillard</span>
+<a name="l00024"></a>00024 <span class="comment">   Created on    :    Jan 04, 1996</span>
+<a name="l00025"></a>00025 <span class="comment">   Description    :    resampling routines</span>
+<a name="l00026"></a>00026 <span class="comment"></span>
+<a name="l00027"></a>00027 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00028"></a>00028 
+<a name="l00029"></a>00029 <span class="comment">/*</span>
+<a name="l00030"></a>00030 <span class="comment">    $Id: sinfo_new_resampling.c,v 1.10 2012/03/03 09:50:08 amodigli Exp $</span>
+<a name="l00031"></a>00031 <span class="comment">    $Author: amodigli $</span>
+<a name="l00032"></a>00032 <span class="comment">    $Date: 2012/03/03 09:50:08 $</span>
+<a name="l00033"></a>00033 <span class="comment">    $Revision: 1.10 $</span>
+<a name="l00034"></a>00034 <span class="comment"> */</span>
+<a name="l00035"></a>00035 
+<a name="l00036"></a>00036 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00037"></a>00037 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00038"></a>00038 <span class="preprocessor">#endif</span>
+<a name="l00039"></a>00039 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00040"></a>00040 <span class="comment">                                  Includes</span>
+<a name="l00041"></a>00041 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include <math.h></span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include "sinfo_new_resampling.h"</span>
+<a name="l00044"></a>00044 <span class="preprocessor">#include "sinfo_pixel_handling.h"</span>
+<a name="l00045"></a>00045 <span class="preprocessor">#include "sinfo_globals.h"</span>
+<a name="l00046"></a>00046 <span class="comment">/* #include "my_pi.h" */</span>
+<a name="l00047"></a>00047 <span class="preprocessor">#include "sinfo_resampling.h"</span>
+<a name="l00048"></a>00048 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00049"></a>00049 <span class="comment">                              Private functions</span>
+<a name="l00050"></a>00050 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00051"></a>00051 
+<a name="l00052"></a>00052 <span class="keyword">static</span> <span class="keywordtype">void</span> new_reverse_tanh_kernel(<span class="keywordtype">double</span> * data, <span class="keywordtype">int</span> nn) ;
+<a name="l00053"></a>00053 <span class="keyword">static</span> <span class="keywordtype">double</span> sinfo_new_sinc(<span class="keywordtype">double</span> x);
+<a name="l00054"></a>00054 
+<a name="l00055"></a>00055 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00056"></a>00056 <span class="comment">                              Function codes</span>
+<a name="l00057"></a>00057 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00058"></a>00058 
+<a name="l00066"></a>00066 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l00090"></a>00090 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00091"></a>00091 
+<a name="l00092"></a>00092 <span class="keywordtype">double</span>   *
+<a name="l00093"></a>00093 sinfo_new_generate_interpolation_kernel(<span class="keyword">const</span> <span class="keywordtype">char</span> * kernel_type)
+<a name="l00094"></a>00094 {
+<a name="l00095"></a>00095     <span class="keywordtype">double</span>  *    tab ;
+<a name="l00096"></a>00096     <span class="keywordtype">int</span>         i ;
+<a name="l00097"></a>00097     <span class="keywordtype">double</span>      x ;
+<a name="l00098"></a>00098     <span class="keywordtype">double</span>        alpha ;
+<a name="l00099"></a>00099     <span class="keywordtype">double</span>        inv_norm ;
+<a name="l00100"></a>00100     <span class="keywordtype">int</span>         samples = KERNEL_SAMPLES ;
+<a name="l00101"></a>00101 
+<a name="l00102"></a>00102     <span class="keywordflow">if</span> (kernel_type==NULL) {
+<a name="l00103"></a>00103         tab = sinfo_new_generate_interpolation_kernel(<span class="stringliteral">"tanh"</span>) ;
+<a name="l00104"></a>00104     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!strcmp(kernel_type, <span class="stringliteral">"default"</span>)) {
+<a name="l00105"></a>00105         tab = sinfo_new_generate_interpolation_kernel(<span class="stringliteral">"tanh"</span>) ;
+<a name="l00106"></a>00106     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!strcmp(kernel_type, <span class="stringliteral">"sinfo_new_sinc"</span>)) {
+<a name="l00107"></a>00107         tab = cpl_malloc(samples * <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>)) ;
+<a name="l00108"></a>00108         tab[0] = 1.0 ;
+<a name="l00109"></a>00109         tab[samples-1] = 0.0 ;
+<a name="l00110"></a>00110         <span class="keywordflow">for</span> (i=1 ; i<samples ; i++) {
+<a name="l00111"></a>00111             x = (double)KERNEL_WIDTH * (<span class="keywordtype">double</span>)i/(double)(samples-1) ;
+<a name="l00112"></a>00112             tab[i] = sinfo_new_sinc(x) ;
+<a name="l00113"></a>00113         }
+<a name="l00114"></a>00114     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!strcmp(kernel_type, <span class="stringliteral">"sinc2"</span>)) {
+<a name="l00115"></a>00115         tab = cpl_malloc(samples * <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>)) ;
+<a name="l00116"></a>00116         tab[0] = 1.0 ;
+<a name="l00117"></a>00117         tab[samples-1] = 0.0 ;
+<a name="l00118"></a>00118         <span class="keywordflow">for</span> (i=1 ; i<samples ; i++) {
+<a name="l00119"></a>00119             x = 2.0 * (double)i/(<span class="keywordtype">double</span>)(samples-1) ;
+<a name="l00120"></a>00120             tab[i] = sinfo_new_sinc(x) ;
+<a name="l00121"></a>00121             tab[i] *= tab[i] ;
+<a name="l00122"></a>00122         }
+<a name="l00123"></a>00123     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!strcmp(kernel_type, <span class="stringliteral">"lanczos"</span>)) {
+<a name="l00124"></a>00124         tab = cpl_malloc(samples * <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>)) ;
+<a name="l00125"></a>00125         <span class="keywordflow">for</span> (i=0 ; i<samples ; i++) {
+<a name="l00126"></a>00126             x = (double)KERNEL_WIDTH * (<span class="keywordtype">double</span>)i/(double)(samples-1) ;
+<a name="l00127"></a>00127             <span class="keywordflow">if</span> (fabs(x)<2) {
+<a name="l00128"></a>00128                 tab[i] = sinfo_new_sinc(x) * sinfo_new_sinc(x/2) ;
+<a name="l00129"></a>00129             } <span class="keywordflow">else</span> {
+<a name="l00130"></a>00130                 tab[i] = 0.00 ;
+<a name="l00131"></a>00131             }
+<a name="l00132"></a>00132         }
+<a name="l00133"></a>00133     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!strcmp(kernel_type, <span class="stringliteral">"hamming"</span>)) {
+<a name="l00134"></a>00134         tab = cpl_malloc(samples * <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>)) ;
+<a name="l00135"></a>00135         alpha = 0.54 ;
+<a name="l00136"></a>00136         inv_norm  = 1.00 / (double)(samples - 1) ;
+<a name="l00137"></a>00137         <span class="keywordflow">for</span> (i=0 ; i<samples ; i++) {
+<a name="l00138"></a>00138             x = (double)i ;
+<a name="l00139"></a>00139             <span class="keywordflow">if</span> (i<(samples-1)/2) {
+<a name="l00140"></a>00140                 tab[i] = alpha + (1-alpha) * cos(2.0*PI_NUMB*x*inv_norm) ;
+<a name="l00141"></a>00141             } <span class="keywordflow">else</span> {
+<a name="l00142"></a>00142                 tab[i] = 0.0 ;
+<a name="l00143"></a>00143             }
+<a name="l00144"></a>00144         }
+<a name="l00145"></a>00145     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!strcmp(kernel_type, <span class="stringliteral">"hann"</span>)) {
+<a name="l00146"></a>00146         tab = cpl_malloc(samples * <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>)) ;
+<a name="l00147"></a>00147         alpha = 0.50 ;
+<a name="l00148"></a>00148         inv_norm  = 1.00 / (double)(samples - 1) ;
+<a name="l00149"></a>00149         <span class="keywordflow">for</span> (i=0 ; i<samples ; i++) {
+<a name="l00150"></a>00150             x = (double)i ;
+<a name="l00151"></a>00151             <span class="keywordflow">if</span> (i<(samples-1)/2) {
+<a name="l00152"></a>00152                 tab[i] = alpha + (1-alpha) * cos(2.0*PI_NUMB*x*inv_norm) ;
+<a name="l00153"></a>00153             } <span class="keywordflow">else</span> {
+<a name="l00154"></a>00154                 tab[i] = 0.0 ;
+<a name="l00155"></a>00155             }
+<a name="l00156"></a>00156         }
+<a name="l00157"></a>00157     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!strcmp(kernel_type, <span class="stringliteral">"tanh"</span>)) {
+<a name="l00158"></a>00158         tab = sinfo_new_generate_tanh_kernel(TANH_STEEPNESS) ;
+<a name="l00159"></a>00159     } <span class="keywordflow">else</span> {
+<a name="l00160"></a>00160         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"unrecognized kernel type [%s]: aborting generation"</span>,
+<a name="l00161"></a>00161                 kernel_type) ;
+<a name="l00162"></a>00162         <span class="keywordflow">return</span> NULL ;
+<a name="l00163"></a>00163     }
+<a name="l00164"></a>00164 
+<a name="l00165"></a>00165     <span class="keywordflow">return</span> tab ;
+<a name="l00166"></a>00166 }
+<a name="l00167"></a>00167 
+<a name="l00168"></a>00168 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l00179"></a>00179 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00180"></a>00180 
+<a name="l00181"></a>00181 <span class="keywordtype">double</span>
+<a name="l00182"></a>00182 sinfo_new_sinc(<span class="keywordtype">double</span> x)
+<a name="l00183"></a>00183 {
+<a name="l00184"></a>00184     <span class="keywordflow">if</span> (fabs(x)<1e-4)
+<a name="l00185"></a>00185         <span class="keywordflow">return</span> (<span class="keywordtype">double</span>)1.00 ;
+<a name="l00186"></a>00186     <span class="keywordflow">else</span>
+<a name="l00187"></a>00187         <span class="keywordflow">return</span> ((sin(x * (<span class="keywordtype">double</span>)PI_NUMB)) / (x * (<span class="keywordtype">double</span>)PI_NUMB)) ;
+<a name="l00188"></a>00188 }
+<a name="l00189"></a>00189 
+<a name="l00190"></a>00190 
+<a name="l00191"></a>00191 
+<a name="l00192"></a>00192 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l00228"></a>00228 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00229"></a>00229 
+<a name="l00230"></a>00230 cpl_image *
+<a name="l00231"></a>00231 sinfo_new_warp_image_generic(
+<a name="l00232"></a>00232     cpl_image         *    image_in,
+<a name="l00233"></a>00233     <span class="keywordtype">char</span>          *    kernel_type,
+<a name="l00234"></a>00234     cpl_polynomial    *    poly_u,
+<a name="l00235"></a>00235     cpl_polynomial    *    poly_v
+<a name="l00236"></a>00236 )
+<a name="l00237"></a>00237 {
+<a name="l00238"></a>00238     cpl_image    *    image_out ;
+<a name="l00239"></a>00239     <span class="keywordtype">int</span>             i, j, k ;
+<a name="l00240"></a>00240     <span class="keywordtype">int</span>             lx_out, ly_out ;
+<a name="l00241"></a>00241     <span class="keywordtype">double</span>           cur ;
+<a name="l00242"></a>00242     <span class="keywordtype">double</span>           neighbors[16] ;
+<a name="l00243"></a>00243     <span class="keywordtype">double</span>           rsc[8],
+<a name="l00244"></a>00244                     sumrs ;
+<a name="l00245"></a>00245     <span class="keywordtype">double</span>           x, y ;
+<a name="l00246"></a>00246     <span class="keywordtype">int</span>             px, py ;
+<a name="l00247"></a>00247     <span class="keywordtype">int</span>             pos ;
+<a name="l00248"></a>00248     <span class="keywordtype">int</span>             tabx, taby ;
+<a name="l00249"></a>00249     <span class="keywordtype">double</span>      *    kernel ;
+<a name="l00250"></a>00250     <span class="keywordtype">int</span>                  leaps[16] ;
+<a name="l00251"></a>00251     <span class="keywordtype">int</span> ilx=0;
+<a name="l00252"></a>00252     <span class="keywordtype">int</span> ily=0;
+<a name="l00253"></a>00253     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l00254"></a>00254     <span class="keywordtype">float</span>* podata=NULL;
+<a name="l00255"></a>00255     cpl_vector* vx=NULL;
+<a name="l00256"></a>00256     <span class="keywordflow">if</span> (image_in == NULL) <span class="keywordflow">return</span> NULL ;
+<a name="l00257"></a>00257 
+<a name="l00258"></a>00258 
+<a name="l00259"></a>00259     <span class="comment">/* Generate default interpolation kernel */</span>
+<a name="l00260"></a>00260     kernel = sinfo_new_generate_interpolation_kernel(kernel_type) ;
+<a name="l00261"></a>00261     <span class="keywordflow">if</span> (kernel == NULL) {
+<a name="l00262"></a>00262         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"cannot generate kernel: aborting resampling"</span>) ;
+<a name="l00263"></a>00263         <span class="keywordflow">return</span> NULL ;
+<a name="l00264"></a>00264     }
+<a name="l00265"></a>00265     ilx=cpl_image_get_size_x(image_in);
+<a name="l00266"></a>00266     ily=cpl_image_get_size_y(image_in);
+<a name="l00267"></a>00267     pidata=cpl_image_get_data_float(image_in);
+<a name="l00268"></a>00268 
+<a name="l00269"></a>00269     <span class="comment">/* Compute new image size   */</span>
+<a name="l00270"></a>00270     lx_out = (int)ilx ;
+<a name="l00271"></a>00271     ly_out = (int)ily ;
+<a name="l00272"></a>00272 
+<a name="l00273"></a>00273     image_out = cpl_image_new(lx_out, ly_out,CPL_TYPE_FLOAT) ;
+<a name="l00274"></a>00274     podata=cpl_image_get_data_float(image_out);
+<a name="l00275"></a>00275 
+<a name="l00276"></a>00276     <span class="comment">/* Pre compute leaps for 16 closest neighbors positions */</span>
+<a name="l00277"></a>00277 
+<a name="l00278"></a>00278     leaps[0] = -1 - ilx ;
+<a name="l00279"></a>00279     leaps[1] =    - ilx ;
+<a name="l00280"></a>00280     leaps[2] =  1 - ilx ;
+<a name="l00281"></a>00281     leaps[3] =  2 - ilx ;
+<a name="l00282"></a>00282 
+<a name="l00283"></a>00283     leaps[4] = -1 ;
+<a name="l00284"></a>00284     leaps[5] =  0 ;
+<a name="l00285"></a>00285     leaps[6] =  1 ;
+<a name="l00286"></a>00286     leaps[7] =  2 ;
+<a name="l00287"></a>00287 
+<a name="l00288"></a>00288     leaps[8] = -1 + ilx ;
+<a name="l00289"></a>00289     leaps[9] =      ilx ;
+<a name="l00290"></a>00290     leaps[10]=  1 + ilx ;
+<a name="l00291"></a>00291     leaps[11]=  2 + ilx ;
+<a name="l00292"></a>00292 
+<a name="l00293"></a>00293     leaps[12]= -1 + 2*ilx ;
+<a name="l00294"></a>00294     leaps[13]=      2*ilx ;
+<a name="l00295"></a>00295     leaps[14]=  1 + 2*ilx ;
+<a name="l00296"></a>00296     leaps[15]=  2 + 2*ilx ;
+<a name="l00297"></a>00297 
+<a name="l00298"></a>00298     vx=cpl_vector_new(2); <span class="comment">/* vector of size 2 = polynomial dimension */</span>
+<a name="l00299"></a>00299     <span class="comment">/* Double loop on the output image  */</span>
+<a name="l00300"></a>00300     <span class="keywordflow">for</span> (j=0 ; j < ly_out ; j++) {
+<a name="l00301"></a>00301         <span class="keywordflow">for</span> (i=0 ; i< lx_out ; i++) {
+<a name="l00302"></a>00302             <span class="comment">/* Compute the original source for this pixel   */</span>
+<a name="l00303"></a>00303       cpl_vector_set(vx,0,(<span class="keywordtype">double</span>)i);
+<a name="l00304"></a>00304       cpl_vector_set(vx,1,(<span class="keywordtype">double</span>)j);
+<a name="l00305"></a>00305             x = cpl_polynomial_eval(poly_u, vx);
+<a name="l00306"></a>00306             y = cpl_polynomial_eval(poly_v, vx);
+<a name="l00307"></a>00307 
+<a name="l00308"></a>00308             <span class="comment">/* Which is the closest integer positioned neighbor?    */</span>
+<a name="l00309"></a>00309             px = (int)x ;
+<a name="l00310"></a>00310             py = (int)y ;
+<a name="l00311"></a>00311 
+<a name="l00312"></a>00312             <span class="keywordflow">if</span> ((px < 1) ||
+<a name="l00313"></a>00313                 (px > (ilx-3)) ||
+<a name="l00314"></a>00314                 (py < 1) ||
+<a name="l00315"></a>00315                 (py > (ily-3)))
+<a name="l00316"></a>00316                 podata[i+j*lx_out] = (pixelvalue)0.0/0.0 ;
+<a name="l00317"></a>00317             <span class="keywordflow">else</span> {
+<a name="l00318"></a>00318                 <span class="comment">/* Now feed the positions for the closest 16 neighbors  */</span>
+<a name="l00319"></a>00319                 pos = px + py * ilx ;
+<a name="l00320"></a>00320                 <span class="keywordflow">for</span> (k=0 ; k<16 ; k++)
+<a name="l00321"></a>00321                     neighbors[k] = (<span class="keywordtype">double</span>)(pidata[(int)(pos+leaps[k])]) ;
+<a name="l00322"></a>00322 
+<a name="l00323"></a>00323                 <span class="comment">/* Which tabulated value index shall we use?    */</span>
+<a name="l00324"></a>00324                 tabx = (x - (double)px) * (double)(TABSPERPIX) ; 
+<a name="l00325"></a>00325                 taby = (y - (double)py) * (double)(TABSPERPIX) ; 
+<a name="l00326"></a>00326 
+<a name="l00327"></a>00327                 <span class="comment">/* Compute resampling coefficients  */</span>
+<a name="l00328"></a>00328                 <span class="comment">/* rsc[0..3] in x, rsc[4..7] in y   */</span>
+<a name="l00329"></a>00329 
+<a name="l00330"></a>00330                 rsc[0] = kernel[TABSPERPIX + tabx] ;
+<a name="l00331"></a>00331                 rsc[1] = kernel[tabx] ;
+<a name="l00332"></a>00332                 rsc[2] = kernel[TABSPERPIX - tabx] ;
+<a name="l00333"></a>00333                 rsc[3] = kernel[2 * TABSPERPIX - tabx] ;
+<a name="l00334"></a>00334                 rsc[4] = kernel[TABSPERPIX + taby] ;
+<a name="l00335"></a>00335                 rsc[5] = kernel[taby] ;
+<a name="l00336"></a>00336                 rsc[6] = kernel[TABSPERPIX - taby] ;
+<a name="l00337"></a>00337                 rsc[7] = kernel[2 * TABSPERPIX - taby] ;
+<a name="l00338"></a>00338 
+<a name="l00339"></a>00339                 sumrs = (rsc[0]+rsc[1]+rsc[2]+rsc[3]) *
+<a name="l00340"></a>00340                         (rsc[4]+rsc[5]+rsc[6]+rsc[7]) ;
+<a name="l00341"></a>00341 
+<a name="l00342"></a>00342                 <span class="comment">/* Compute interpolated pixel now   */</span>
+<a name="l00343"></a>00343                 cur =   rsc[4] * (  rsc[0]*neighbors[0] +
+<a name="l00344"></a>00344                                     rsc[1]*neighbors[1] +
+<a name="l00345"></a>00345                                     rsc[2]*neighbors[2] +
+<a name="l00346"></a>00346                                     rsc[3]*neighbors[3] ) +
+<a name="l00347"></a>00347                         rsc[5] * (  rsc[0]*neighbors[4] +
+<a name="l00348"></a>00348                                     rsc[1]*neighbors[5] +
+<a name="l00349"></a>00349                                     rsc[2]*neighbors[6] +
+<a name="l00350"></a>00350                                     rsc[3]*neighbors[7] ) +
+<a name="l00351"></a>00351                         rsc[6] * (  rsc[0]*neighbors[8] +
+<a name="l00352"></a>00352                                     rsc[1]*neighbors[9] +
+<a name="l00353"></a>00353                                     rsc[2]*neighbors[10] +
+<a name="l00354"></a>00354                                     rsc[3]*neighbors[11] ) +
+<a name="l00355"></a>00355                         rsc[7] * (  rsc[0]*neighbors[12] +
+<a name="l00356"></a>00356                                     rsc[1]*neighbors[13] +
+<a name="l00357"></a>00357                                     rsc[2]*neighbors[14] +
+<a name="l00358"></a>00358                                     rsc[3]*neighbors[15] ) ; 
+<a name="l00359"></a>00359 
+<a name="l00360"></a>00360                 <span class="comment">/* Affect the value to the output image */</span>
+<a name="l00361"></a>00361                 podata[i+j*lx_out] = (pixelvalue)(cur/sumrs) ;
+<a name="l00362"></a>00362                 <span class="comment">/* done ! */</span>
+<a name="l00363"></a>00363             }       
+<a name="l00364"></a>00364         }
+<a name="l00365"></a>00365     }
+<a name="l00366"></a>00366     cpl_vector_delete(vx);
+<a name="l00367"></a>00367     cpl_free(kernel) ;
+<a name="l00368"></a>00368     <span class="keywordflow">return</span> image_out ;
+<a name="l00369"></a>00369 }
+<a name="l00370"></a>00370 
+<a name="l00371"></a>00371 
+<a name="l00372"></a>00372 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l00393"></a>00393 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00394"></a>00394 
+<a name="l00395"></a>00395 <span class="preprocessor">#define hk_gen(x,s) (((tanh(s*(x+0.5))+1)/2)*((tanh(s*(-x+0.5))+1)/2))</span>
+<a name="l00396"></a>00396 <span class="preprocessor"></span>
+<a name="l00397"></a>00397 <span class="keywordtype">double</span> * sinfo_new_generate_tanh_kernel(<span class="keywordtype">double</span> steep)
+<a name="l00398"></a>00398 {
+<a name="l00399"></a>00399     <span class="keywordtype">double</span>  *   kernel ;
+<a name="l00400"></a>00400     <span class="keywordtype">double</span>  *   x ;
+<a name="l00401"></a>00401     <span class="keywordtype">double</span>      width ;
+<a name="l00402"></a>00402     <span class="keywordtype">double</span>      inv_np ;
+<a name="l00403"></a>00403     <span class="keywordtype">double</span>      ind ;
+<a name="l00404"></a>00404     <span class="keywordtype">int</span>         i ;
+<a name="l00405"></a>00405     <span class="keywordtype">int</span>         np ;
+<a name="l00406"></a>00406     <span class="keywordtype">int</span>         samples ;
+<a name="l00407"></a>00407 
+<a name="l00408"></a>00408     width   = (double)TABSPERPIX / 2.0 ; 
+<a name="l00409"></a>00409     samples = KERNEL_SAMPLES ;
+<a name="l00410"></a>00410     np      = 32768 ; <span class="comment">/* Hardcoded: should never be changed */</span>
+<a name="l00411"></a>00411     inv_np  = 1.00 / (double)np ;
+<a name="l00412"></a>00412 
+<a name="l00413"></a>00413     <span class="comment">/*</span>
+<a name="l00414"></a>00414 <span class="comment">     * Generate the kernel expression in Fourier space</span>
+<a name="l00415"></a>00415 <span class="comment">     * with a correct frequency ordering to allow standard FT</span>
+<a name="l00416"></a>00416 <span class="comment">     */</span>
+<a name="l00417"></a>00417     x = cpl_malloc((2*np+1)*<span class="keyword">sizeof</span>(<span class="keywordtype">double</span>)) ;
+<a name="l00418"></a>00418     <span class="keywordflow">for</span> (i=0 ; i<np/2 ; i++) {
+<a name="l00419"></a>00419         ind      = (double)i * 2.0 * width * inv_np ;
+<a name="l00420"></a>00420         x[2*i]   = hk_gen(ind, steep) ;
+<a name="l00421"></a>00421         x[2*i+1] = 0.00 ;
+<a name="l00422"></a>00422     }
+<a name="l00423"></a>00423     <span class="keywordflow">for</span> (i=np/2 ; i<np ; i++) {
+<a name="l00424"></a>00424         ind      = (double)(i-np) * 2.0 * width * inv_np ;
+<a name="l00425"></a>00425         x[2*i]   = hk_gen(ind, steep) ;
+<a name="l00426"></a>00426         x[2*i+1] = 0.00 ;
+<a name="l00427"></a>00427     }
+<a name="l00428"></a>00428 
+<a name="l00429"></a>00429     <span class="comment">/* </span>
+<a name="l00430"></a>00430 <span class="comment">     * Reverse Fourier to come back to image space</span>
+<a name="l00431"></a>00431 <span class="comment">     */</span>
+<a name="l00432"></a>00432     new_reverse_tanh_kernel(x, np) ;
+<a name="l00433"></a>00433 
+<a name="l00434"></a>00434     <span class="comment">/*</span>
+<a name="l00435"></a>00435 <span class="comment">     * Allocate and fill in returned array</span>
+<a name="l00436"></a>00436 <span class="comment">     */</span>
+<a name="l00437"></a>00437     kernel = cpl_malloc(samples * <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>)) ;
+<a name="l00438"></a>00438     <span class="keywordflow">for</span> (i=0 ; i<samples ; i++) {
+<a name="l00439"></a>00439         kernel[i] = 2.0 * width * x[2*i] * inv_np ;
+<a name="l00440"></a>00440     }
+<a name="l00441"></a>00441     cpl_free(x) ;
+<a name="l00442"></a>00442     <span class="keywordflow">return</span> kernel ;
+<a name="l00443"></a>00443 }
+<a name="l00444"></a>00444 
+<a name="l00445"></a>00445 
+<a name="l00446"></a>00446 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l00458"></a>00458 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00459"></a>00459 
+<a name="l00460"></a>00460 <span class="preprocessor">#define KERNEL_SW(a,b) tempr=(a);(a)=(b);(b)=tempr</span>
+<a name="l00461"></a>00461 <span class="preprocessor"></span><span class="keyword">static</span> <span class="keywordtype">void</span> new_reverse_tanh_kernel(<span class="keywordtype">double</span> * data, <span class="keywordtype">int</span> nn)
+<a name="l00462"></a>00462 {
+<a name="l00463"></a>00463     <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>   n,
+<a name="l00464"></a>00464                     mmax,
+<a name="l00465"></a>00465                     m,
+<a name="l00466"></a>00466                     i, j,
+<a name="l00467"></a>00467                     istep ;
+<a name="l00468"></a>00468     <span class="keywordtype">double</span>  wtemp,
+<a name="l00469"></a>00469             wr,
+<a name="l00470"></a>00470             wpr,
+<a name="l00471"></a>00471             wpi,
+<a name="l00472"></a>00472             wi,
+<a name="l00473"></a>00473             theta;
+<a name="l00474"></a>00474     <span class="keywordtype">double</span>  tempr,
+<a name="l00475"></a>00475             tempi;
+<a name="l00476"></a>00476 
+<a name="l00477"></a>00477     n = (<span class="keywordtype">unsigned</span> long)nn << 1;
+<a name="l00478"></a>00478     j = 1;
+<a name="l00479"></a>00479     <span class="keywordflow">for</span> (i=1 ; i<n ; i+=2) {
+<a name="l00480"></a>00480         <span class="keywordflow">if</span> (j > i) {
+<a name="l00481"></a>00481             KERNEL_SW(data[j-1],data[i-1]);
+<a name="l00482"></a>00482             KERNEL_SW(data[j],data[i]);
+<a name="l00483"></a>00483         }
+<a name="l00484"></a>00484         m = n >> 1;
+<a name="l00485"></a>00485         <span class="keywordflow">while</span> (m>=2 && j>m) {
+<a name="l00486"></a>00486             j -= m;
+<a name="l00487"></a>00487             m >>= 1;
+<a name="l00488"></a>00488         }
+<a name="l00489"></a>00489         j += m;
+<a name="l00490"></a>00490     }
+<a name="l00491"></a>00491     mmax = 2;
+<a name="l00492"></a>00492     <span class="keywordflow">while</span> (n > mmax) {
+<a name="l00493"></a>00493         istep = mmax << 1;
+<a name="l00494"></a>00494         theta = 2 * PI_NUMB / mmax;
+<a name="l00495"></a>00495         wtemp = sin(0.5 * theta);
+<a name="l00496"></a>00496         wpr = -2.0 * wtemp * wtemp;
+<a name="l00497"></a>00497         wpi = sin(theta);
+<a name="l00498"></a>00498         wr  = 1.0;
+<a name="l00499"></a>00499         wi  = 0.0;
+<a name="l00500"></a>00500         <span class="keywordflow">for</span> (m=1 ; m<mmax ; m+=2) {
+<a name="l00501"></a>00501             <span class="keywordflow">for</span> (i=m ; i<=n ; i+=istep) {
+<a name="l00502"></a>00502                 j = i + mmax;
+<a name="l00503"></a>00503                 tempr = wr * data[j-1] - wi * data[j];
+<a name="l00504"></a>00504                 tempi = wr * data[j]   + wi * data[j-1];
+<a name="l00505"></a>00505                 data[j-1] = data[i-1] - tempr;
+<a name="l00506"></a>00506                 data[j]   = data[i]   - tempi;
+<a name="l00507"></a>00507                 data[i-1] += tempr;
+<a name="l00508"></a>00508                 data[i]   += tempi;
+<a name="l00509"></a>00509             }
+<a name="l00510"></a>00510             wr = (wtemp = wr) * wpr - wi * wpi + wr;
+<a name="l00511"></a>00511             wi = wi * wpr + wtemp * wpi + wi;
+<a name="l00512"></a>00512         }
+<a name="l00513"></a>00513         mmax = istep;
+<a name="l00514"></a>00514     }
+<a name="l00515"></a>00515 }
+<a name="l00516"></a>00516 <span class="preprocessor">#undef KERNEL_SW</span>
+<a name="l00517"></a>00517 <span class="preprocessor"></span>
+<a name="l00518"></a>00518 
+<a name="l00519"></a>00519 
+<a name="l00520"></a>00520 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l00533"></a>00533 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00534"></a>00534 
+<a name="l00535"></a>00535 <span class="keywordtype">void</span> sinfo_new_show_interpolation_kernel(<span class="keywordtype">char</span> * kernel_name)
+<a name="l00536"></a>00536 {
+<a name="l00537"></a>00537     <span class="keywordtype">double</span>    *    ker ;
+<a name="l00538"></a>00538     <span class="keywordtype">int</span>            i ;
+<a name="l00539"></a>00539     <span class="keywordtype">double</span>        x ;
+<a name="l00540"></a>00540 
+<a name="l00541"></a>00541 
+<a name="l00542"></a>00542     ker = sinfo_new_generate_interpolation_kernel(kernel_name) ;
+<a name="l00543"></a>00543     <span class="keywordflow">if</span> (ker == NULL)
+<a name="l00544"></a>00544         return ;
+<a name="l00545"></a>00545 
+<a name="l00546"></a>00546     (void)fprintf(stdout, <span class="stringliteral">"# Kernel is %s\n"</span>, kernel_name) ;
+<a name="l00547"></a>00547     x = 0.00 ;
+<a name="l00548"></a>00548     <span class="keywordflow">for</span> (i=0 ; i<KERNEL_SAMPLES ; i++) {
+<a name="l00549"></a>00549         (void)fprintf(stdout, <span class="stringliteral">"%g %g\n"</span>, x, ker[i]) ;
+<a name="l00550"></a>00550         x += 1.00 / (double)TABSPERPIX ;
+<a name="l00551"></a>00551     }
+<a name="l00552"></a>00552     cpl_free(ker) ;
+<a name="l00553"></a>00553     return ;
+<a name="l00554"></a>00554 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__new__resampling_8h_source.html b/html/sinfo__new__resampling_8h_source.html
new file mode 100644
index 0000000..ee18479
--- /dev/null
+++ b/html/sinfo__new__resampling_8h_source.html
@@ -0,0 +1,135 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_new_resampling.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_new_resampling.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 
+<a name="l00020"></a>00020 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00021"></a>00021 <span class="comment">   </span>
+<a name="l00022"></a>00022 <span class="comment">   File name     :    sinfo_resampling.h</span>
+<a name="l00023"></a>00023 <span class="comment">   Author         :    Nicolas Devillard</span>
+<a name="l00024"></a>00024 <span class="comment">   Created on    :    Jan 04, 1996</span>
+<a name="l00025"></a>00025 <span class="comment">   Description    :    resampling routines</span>
+<a name="l00026"></a>00026 <span class="comment"></span>
+<a name="l00027"></a>00027 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00028"></a>00028 
+<a name="l00029"></a>00029 <span class="comment">/*</span>
+<a name="l00030"></a>00030 <span class="comment"></span>
+<a name="l00031"></a>00031 <span class="comment"> $Id: sinfo_new_resampling.h,v 1.9 2007/06/06 07:10:45 amodigli Exp $</span>
+<a name="l00032"></a>00032 <span class="comment"> $Author: amodigli $</span>
+<a name="l00033"></a>00033 <span class="comment"> $Date: 2007/06/06 07:10:45 $</span>
+<a name="l00034"></a>00034 <span class="comment"> $Revision: 1.9 $</span>
+<a name="l00035"></a>00035 <span class="comment"></span>
+<a name="l00036"></a>00036 <span class="comment"> */</span>
+<a name="l00037"></a>00037 
+<a name="l00038"></a>00038 <span class="preprocessor">#ifndef SINFO_NEW_RESAMPLING_H</span>
+<a name="l00039"></a>00039 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_NEW_RESAMPLING_H</span>
+<a name="l00040"></a>00040 <span class="preprocessor"></span>
+<a name="l00041"></a>00041 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00042"></a>00042 <span class="comment">                                  Includes</span>
+<a name="l00043"></a>00043 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00044"></a>00044 
+<a name="l00045"></a>00045 <span class="comment">/*</span>
+<a name="l00046"></a>00046 <span class="comment">#include "my_image_handling.h"</span>
+<a name="l00047"></a>00047 <span class="comment">#include "sinfo_matrix.h"</span>
+<a name="l00048"></a>00048 <span class="comment">*/</span>
+<a name="l00049"></a>00049 <span class="preprocessor">#include "sinfo_poly2d.h"</span>
+<a name="l00050"></a>00050 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00051"></a>00051 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00052"></a>00052 
+<a name="l00053"></a>00053 
+<a name="l00054"></a>00054 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00055"></a>00055 <span class="comment">                                  Defines</span>
+<a name="l00056"></a>00056 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00057"></a>00057 
+<a name="l00058"></a>00058 
+<a name="l00059"></a>00059 <span class="preprocessor">#define TRANSFO_AFFINE          0</span>
+<a name="l00060"></a>00060 <span class="preprocessor"></span><span class="preprocessor">#define TRANSFO_DEG2            1</span>
+<a name="l00061"></a>00061 <span class="preprocessor"></span><span class="preprocessor">#define TRANSFO_HOMOGRAPHIC     2</span>
+<a name="l00062"></a>00062 <span class="preprocessor"></span>
+<a name="l00063"></a>00063 <span class="comment">/* Number of pixels set to 0 by the shift resampling */</span>
+<a name="l00064"></a>00064 <span class="preprocessor">#define    SHIFT_REJECT_L            2</span>
+<a name="l00065"></a>00065 <span class="preprocessor"></span><span class="preprocessor">#define    SHIFT_REJECT_R            2</span>
+<a name="l00066"></a>00066 <span class="preprocessor"></span><span class="preprocessor">#define    SHIFT_REJECT_T            2</span>
+<a name="l00067"></a>00067 <span class="preprocessor"></span><span class="preprocessor">#define    SHIFT_REJECT_B            2</span>
+<a name="l00068"></a>00068 <span class="preprocessor"></span>
+<a name="l00069"></a>00069 <span class="comment">/*</span>
+<a name="l00070"></a>00070 <span class="comment"> * Kernel definition in terms of sampling</span>
+<a name="l00071"></a>00071 <span class="comment"> */</span>
+<a name="l00072"></a>00072 
+<a name="l00073"></a>00073 
+<a name="l00074"></a>00074 <span class="comment">/* Number of tabulations in kernel  */</span>
+<a name="l00075"></a>00075 <span class="preprocessor">#define TABSPERPIX      (1000)</span>
+<a name="l00076"></a>00076 <span class="preprocessor"></span><span class="preprocessor">#define KERNEL_WIDTH    (2.0)</span>
+<a name="l00077"></a>00077 <span class="preprocessor"></span><span class="preprocessor">#define KERNEL_SAMPLES  (1+(int)(TABSPERPIX * KERNEL_WIDTH))</span>
+<a name="l00078"></a>00078 <span class="preprocessor"></span>
+<a name="l00079"></a>00079 <span class="preprocessor">#define TANH_STEEPNESS    (5.0)</span>
+<a name="l00080"></a>00080 <span class="preprocessor"></span>
+<a name="l00081"></a>00081 
+<a name="l00082"></a>00082 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00083"></a>00083 <span class="comment">                         Function ANSI C prototypes</span>
+<a name="l00084"></a>00084 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00085"></a>00085 
+<a name="l00086"></a>00086 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l00110"></a>00110 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00111"></a>00111 
+<a name="l00112"></a>00112 
+<a name="l00113"></a>00113 <span class="keywordtype">double</span>   *
+<a name="l00114"></a>00114 sinfo_new_generate_interpolation_kernel(<span class="keyword">const</span> <span class="keywordtype">char</span> * kernel_type) ;
+<a name="l00115"></a>00115 
+<a name="l00116"></a>00116 
+<a name="l00117"></a>00117 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l00153"></a>00153 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00154"></a>00154 
+<a name="l00155"></a>00155 
+<a name="l00156"></a>00156 cpl_image *
+<a name="l00157"></a>00157 sinfo_new_warp_image_generic(
+<a name="l00158"></a>00158     cpl_image       *    image_in,
+<a name="l00159"></a>00159     <span class="keywordtype">char</span>        *    kernel_type,
+<a name="l00160"></a>00160     cpl_polynomial  *    poly_u,
+<a name="l00161"></a>00161     cpl_polynomial  *    poly_v
+<a name="l00162"></a>00162 ) ;
+<a name="l00163"></a>00163 
+<a name="l00164"></a>00164 
+<a name="l00165"></a>00165 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l00186"></a>00186 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00187"></a>00187 
+<a name="l00188"></a>00188 <span class="keywordtype">double</span> * sinfo_new_generate_tanh_kernel(<span class="keywordtype">double</span> steep) ;
+<a name="l00189"></a>00189 
+<a name="l00190"></a>00190 
+<a name="l00191"></a>00191 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l00204"></a>00204 <span class="comment">/*--------------------------------------------------------------------------*/</span> 
+<a name="l00205"></a>00205 
+<a name="l00206"></a>00206 <span class="keywordtype">void</span> sinfo_new_show_interpolation_kernel(<span class="keywordtype">char</span> * kernel_name) ;
+<a name="l00207"></a>00207 
+<a name="l00208"></a>00208 
+<a name="l00209"></a>00209 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__new__slit__pos_8c_source.html b/html/sinfo__new__slit__pos_8c_source.html
new file mode 100644
index 0000000..20ac143
--- /dev/null
+++ b/html/sinfo__new__slit__pos_8c_source.html
@@ -0,0 +1,734 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_new_slit_pos.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_new_slit_pos.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00002"></a>00002 <span class="comment"> </span>
+<a name="l00003"></a>00003 <span class="comment">   File name    :       sinfo_new_slit_pos.c</span>
+<a name="l00004"></a>00004 <span class="comment">   Author       :    A. Modigliani</span>
+<a name="l00005"></a>00005 <span class="comment">   Created on   :    Sep 17, 2003</span>
+<a name="l00006"></a>00006 <span class="comment">   Description  : </span>
+<a name="l00007"></a>00007 <span class="comment"></span>
+<a name="l00008"></a>00008 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00009"></a>00009 <span class="comment">/*</span>
+<a name="l00010"></a>00010 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00011"></a>00011 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00012"></a>00012 <span class="comment"> *</span>
+<a name="l00013"></a>00013 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00014"></a>00014 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00015"></a>00015 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00016"></a>00016 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00017"></a>00017 <span class="comment"> *</span>
+<a name="l00018"></a>00018 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00019"></a>00019 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00020"></a>00020 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00021"></a>00021 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00022"></a>00022 <span class="comment"> *</span>
+<a name="l00023"></a>00023 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00024"></a>00024 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00025"></a>00025 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00029"></a>00029 <span class="preprocessor">#endif</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span>
+<a name="l00031"></a>00031 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00032"></a>00032 <span class="comment">                                Includes</span>
+<a name="l00033"></a>00033 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00034"></a>00034 <span class="preprocessor">#include "sinfo_new_slit_pos.h"</span>
+<a name="l00035"></a>00035 <span class="preprocessor">#include "sinfo_pro_save.h"</span>
+<a name="l00036"></a>00036 <span class="preprocessor">#include "sinfo_pro_types.h"</span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include "sinfo_wavecal_ini_by_cpl.h"</span>
+<a name="l00038"></a>00038 <span class="preprocessor">#include "sinfo_wcal_functions.h"</span>
+<a name="l00039"></a>00039 <span class="preprocessor">#include "sinfo_wave_calibration.h"</span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include "sinfo_utilities.h"</span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include "sinfo_utils_wrappers.h"</span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include "sinfo_hidden.h"</span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include "sinfo_error.h"</span>
+<a name="l00044"></a>00044 <span class="preprocessor">#include "sinfo_globals.h"</span>
+<a name="l00045"></a>00045 
+<a name="l00046"></a>00046 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00047"></a>00047 <span class="comment">                                Defines</span>
+<a name="l00048"></a>00048 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00049"></a>00049 
+<a name="l00050"></a>00050 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00051"></a>00051 <span class="comment">                             Function Definitions</span>
+<a name="l00052"></a>00052 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00060"></a>00060 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00061"></a>00061 <span class="comment">   Function     :       sinfo_new_slit_pos()</span>
+<a name="l00062"></a>00062 <span class="comment">   In           :       ini_file: file name of according .ini file</span>
+<a name="l00063"></a>00063 <span class="comment">   Out          :       integer (0 if it worked, -1 if it doesn't) </span>
+<a name="l00064"></a>00064 <span class="comment">   Job          :</span>
+<a name="l00065"></a>00065 <span class="comment"></span>
+<a name="l00066"></a>00066 <span class="comment"></span>
+<a name="l00067"></a>00067 <span class="comment">  Normal method:</span>
+<a name="l00068"></a>00068 <span class="comment"></span>
+<a name="l00069"></a>00069 <span class="comment">  does the wavelength calibration and the fitting of the slitlet sinfo_edge </span>
+<a name="l00070"></a>00070 <span class="comment">  positions (ASCII file 32 x 2 values) if wished</span>
+<a name="l00071"></a>00071 <span class="comment">  produces an array of the bcoefs and of the fit parameters if wished and a </span>
+<a name="l00072"></a>00072 <span class="comment">  wavelength calibration map input is an emission line frame and a line list</span>
+<a name="l00073"></a>00073 <span class="comment"></span>
+<a name="l00074"></a>00074 <span class="comment"></span>
+<a name="l00075"></a>00075 <span class="comment">  o searching for lines by cross sinfo_correlation with a line list</span>
+<a name="l00076"></a>00076 <span class="comment">  o Gaussian fitting of emission lines in each column->positions of the lines-></span>
+<a name="l00077"></a>00077 <span class="comment">    resulting fit parameters can be stored in an ASCII file</span>
+<a name="l00078"></a>00078 <span class="comment">  o Fitting of a polynomial to the line positions for each column</span>
+<a name="l00079"></a>00079 <span class="comment">  o Smoothing: fitting of each polynomial coefficient by another polynomial</span>
+<a name="l00080"></a>00080 <span class="comment">    across the whole frame -> resulting polynomial coefficients can be stored </span>
+<a name="l00081"></a>00081 <span class="comment">    in an ASCII file.</span>
+<a name="l00082"></a>00082 <span class="comment">  o Wavelength calibration map (micron value for each frame pixel) can be</span>
+<a name="l00083"></a>00083 <span class="comment">    produced by using these coefficients and a cross sinfo_correlation to the</span>
+<a name="l00084"></a>00084 <span class="comment">    original frame</span>
+<a name="l00085"></a>00085 <span class="comment"></span>
+<a name="l00086"></a>00086 <span class="comment">  o The slitlet sinfo_edge positions can be fitted:</span>
+<a name="l00087"></a>00087 <span class="comment">    1) Automatically (not really stable) or by using guess sinfo_edge positions</span>
+<a name="l00088"></a>00088 <span class="comment">    2) By using a Boltzmann or a linear slope function</span>
+<a name="l00089"></a>00089 <span class="comment"></span>
+<a name="l00090"></a>00090 <span class="comment">  Slit method:</span>
+<a name="l00091"></a>00091 <span class="comment"></span>
+<a name="l00092"></a>00092 <span class="comment">  does the wavelength calibration and the fitting of the slitlet sinfo_edge </span>
+<a name="l00093"></a>00093 <span class="comment">  positions (ASCII file 32 x 2 values) if wished produces a list of the fit </span>
+<a name="l00094"></a>00094 <span class="comment">  parameters and of the smoothed coefficients if wished and a wavelength </span>
+<a name="l00095"></a>00095 <span class="comment">  calibration map input is an emission line frame and a line list</span>
+<a name="l00096"></a>00096 <span class="comment"></span>
+<a name="l00097"></a>00097 <span class="comment">  o Does the same as other method but smoothes the found polynomial </span>
+<a name="l00098"></a>00098 <span class="comment">    coefficients within each slitlet and not over the whole frame.</span>
+<a name="l00099"></a>00099 <span class="comment"></span>
+<a name="l00100"></a>00100 <span class="comment">  o Produces always a wavelength calibration map and does not crosscorrelate.</span>
+<a name="l00101"></a>00101 <span class="comment"></span>
+<a name="l00102"></a>00102 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00103"></a>00103 
+<a name="l00104"></a>00104 
+<a name="l00105"></a>00105 
+<a name="l00106"></a>00106 <span class="keywordtype">int</span> sinfo_new_slit_pos (cpl_parameterlist* config, cpl_frameset* sof)
+<a name="l00107"></a>00107 {
+<a name="l00108"></a>00108     wave_config * cfg =NULL;
+<a name="l00109"></a>00109     <span class="keywordtype">int</span> check = 0;
+<a name="l00110"></a>00110     <span class="keywordtype">int</span> lx = 0;
+<a name="l00111"></a>00111     <span class="keywordtype">int</span> ly = 0;
+<a name="l00112"></a>00112     <span class="keywordtype">int</span> n_lines=0;
+<a name="l00113"></a>00113     <span class="keywordtype">int</span> i = 0;
+<a name="l00114"></a>00114     <span class="keywordtype">int</span> j = 0;
+<a name="l00115"></a>00115     <span class="keywordtype">int</span> n = 0;
+<a name="l00116"></a>00116 
+<a name="l00117"></a>00117     <span class="keywordtype">int</span> sum=0;
+<a name="l00118"></a>00118 
+<a name="l00119"></a>00119     <span class="keywordtype">int</span>* n_found_lines=NULL;
+<a name="l00120"></a>00120     <span class="keywordtype">int</span>* sum_pointer=NULL;
+<a name="l00121"></a>00121     <span class="keywordtype">int</span>** row_clean=NULL;
+<a name="l00122"></a>00122 
+<a name="l00123"></a>00123     <span class="keywordtype">float</span> a=0;
+<a name="l00124"></a>00124     <span class="keywordtype">float</span> shift=0;
+<a name="l00125"></a>00125     <span class="keywordtype">float</span>* wave=NULL;
+<a name="l00126"></a>00126     <span class="keywordtype">float</span>* intens=NULL;
+<a name="l00127"></a>00127 
+<a name="l00128"></a>00128     <span class="keywordtype">float</span>** acoefs=NULL;
+<a name="l00129"></a>00129     <span class="keywordtype">float</span>** wavelength_clean=NULL;
+<a name="l00130"></a>00130 
+<a name="l00131"></a>00131     <span class="keywordtype">float</span>** sinfo_slit_pos=NULL;
+<a name="l00132"></a>00132  
+<a name="l00133"></a>00133     cpl_image *  map=NULL ;
+<a name="l00134"></a>00134     cpl_image * im=NULL ;
+<a name="l00135"></a>00135 
+<a name="l00136"></a>00136     FitParams** par=NULL;
+<a name="l00137"></a>00137 
+<a name="l00138"></a>00138     cpl_table* tbl_wcal=NULL;
+<a name="l00139"></a>00139     cpl_table* tbl_spos=NULL;
+<a name="l00140"></a>00140 
+<a name="l00141"></a>00141     <span class="keywordtype">char</span>* col_name=NULL;
+<a name="l00142"></a>00142     <span class="keywordtype">char</span>* tbl_name=NULL;
+<a name="l00143"></a>00143 
+<a name="l00144"></a>00144     <span class="keywordtype">char</span>* tbl_line_list_name=NULL;
+<a name="l00145"></a>00145     cpl_table* tbl_line_list = NULL;
+<a name="l00146"></a>00146     <span class="keywordtype">int</span>* status=NULL;
+<a name="l00147"></a>00147  
+<a name="l00148"></a>00148     cpl_frameset* raw=NULL;
+<a name="l00149"></a>00149 
+<a name="l00150"></a>00150 
+<a name="l00151"></a>00151     cpl_table * tbl_fp =NULL;
+<a name="l00152"></a>00152     <span class="keywordtype">char</span>* col=NULL;
+<a name="l00153"></a>00153     cpl_table* qclog_tbl=NULL;
+<a name="l00154"></a>00154     <span class="keywordtype">char</span>* key_name=NULL;
+<a name="l00155"></a>00155     <span class="keywordtype">double</span> fwhm_med=0;
+<a name="l00156"></a>00156     <span class="keywordtype">double</span> fwhm_avg=0;
+<a name="l00157"></a>00157     <span class="keywordtype">double</span> coef_med=0;
+<a name="l00158"></a>00158     <span class="keywordtype">double</span> coef_avg=0;
+<a name="l00159"></a>00159     <span class="keywordtype">int</span> trow=0;
+<a name="l00160"></a>00160     qc_wcal* qc=sinfo_qc_wcal_new();
+<a name="l00161"></a>00161     <span class="comment">/*        -----------------------------------------------------------------</span>
+<a name="l00162"></a>00162 <span class="comment">       1) parse the file names and parameters to the ns_config data </span>
+<a name="l00163"></a>00163 <span class="comment">          structure cfg</span>
+<a name="l00164"></a>00164 <span class="comment">       -----------------------------------------------------------------</span>
+<a name="l00165"></a>00165 <span class="comment">     */</span>
+<a name="l00166"></a>00166 
+<a name="l00167"></a>00167     sinfo_msg(<span class="stringliteral">"Parsing cpl input"</span>);
+<a name="l00168"></a>00168     cfg = sinfo_parse_cpl_input_wave(config,sof,&raw) ;
+<a name="l00169"></a>00169     
+<a name="l00170"></a>00170     <span class="keywordflow">if</span>(cfg!=NULL) {
+<a name="l00171"></a>00171        cfg->nslitlets=32;
+<a name="l00172"></a>00172        cfg->calibIndicator=1;
+<a name="l00173"></a>00173        cfg->wavemapInd=0;
+<a name="l00174"></a>00174        cfg->slitposIndicator=1;
+<a name="l00175"></a>00175     }
+<a name="l00176"></a>00176     <span class="keywordflow">if</span>(cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l00177"></a>00177       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>((<span class="keywordtype">char</span>* ) cpl_error_get_message());
+<a name="l00178"></a>00178       sinfo_qc_wcal_delete(&qc);
+<a name="l00179"></a>00179       <span class="keywordflow">return</span> -1;
+<a name="l00180"></a>00180     }
+<a name="l00181"></a>00181    
+<a name="l00182"></a>00182     <span class="keywordflow">if</span> (cfg == NULL)
+<a name="l00183"></a>00183     {
+<a name="l00184"></a>00184         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"could not parse cpl input!\n"</span>) ;
+<a name="l00185"></a>00185         sinfo_qc_wcal_delete(&qc);
+<a name="l00186"></a>00186         <span class="keywordflow">return</span> -1 ;
+<a name="l00187"></a>00187     }
+<a name="l00188"></a>00188     <span class="keywordflow">if</span>(sinfo_is_fits_file(cfg->inFrame) != 1) {
+<a name="l00189"></a>00189       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Input file %s is not FITS"</span>,cfg->inFrame);
+<a name="l00190"></a>00190       sinfo_qc_wcal_delete(&qc);
+<a name="l00191"></a>00191       <span class="keywordflow">return</span> -1;
+<a name="l00192"></a>00192     }
+<a name="l00193"></a>00193 
+<a name="l00194"></a>00194 
+<a name="l00195"></a>00195     <span class="keywordflow">if</span> (cfg->slitposIndicator == 1 && cfg->estimateIndicator == 1) {
+<a name="l00196"></a>00196       <span class="keywordflow">if</span> (sinfo_is_fits_file(cfg->slitposGuessName) != 1) {
+<a name="l00197"></a>00197         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"slitlet position guess list not given!"</span>);
+<a name="l00198"></a>00198         sinfo_qc_wcal_delete(&qc);
+<a name="l00199"></a>00199         <span class="keywordflow">return</span> -1;
+<a name="l00200"></a>00200       }
+<a name="l00201"></a>00201     }
+<a name="l00202"></a>00202 
+<a name="l00203"></a>00203     <span class="keywordflow">if</span> (cfg->calibIndicator == 0 && cfg->wavemapInd == 1) {
+<a name="l00204"></a>00204       <span class="keywordflow">if</span> (sinfo_is_fits_file(cfg->coeffsName) != 1) {
+<a name="l00205"></a>00205         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"coefficients list not given!"</span>);
+<a name="l00206"></a>00206         sinfo_qc_wcal_delete(&qc);
+<a name="l00207"></a>00207         <span class="keywordflow">return</span> -1;
+<a name="l00208"></a>00208       }
+<a name="l00209"></a>00209     }
+<a name="l00210"></a>00210 
+<a name="l00211"></a>00211 
+<a name="l00212"></a>00212     <span class="keywordflow">if</span> (cfg->slitposIndicator == 1) {
+<a name="l00213"></a>00213       <span class="keywordflow">if</span> (cfg->calibIndicator != 1 && cfg->estimateIndicator != 1) {
+<a name="l00214"></a>00214        
+<a name="l00215"></a>00215         <span class="keywordflow">if</span> (sinfo_is_fits_file(cfg->paramsList) != 1) {
+<a name="l00216"></a>00216       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"parameter list not given!"</span>);
+<a name="l00217"></a>00217           sinfo_qc_wcal_delete(&qc);
+<a name="l00218"></a>00218       <span class="keywordflow">return</span> -1;
+<a name="l00219"></a>00219     }
+<a name="l00220"></a>00220     
+<a name="l00221"></a>00221       }
+<a name="l00222"></a>00222     }
+<a name="l00223"></a>00223 
+<a name="l00224"></a>00224 <span class="comment">/*---load the emission line frame---*/</span>
+<a name="l00225"></a>00225     im = cpl_image_load(cfg->inFrame,CPL_TYPE_FLOAT,0,0);
+<a name="l00226"></a>00226     <span class="keywordflow">if</span> (im == NULL) {
+<a name="l00227"></a>00227       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"could not load image\n"</span>);
+<a name="l00228"></a>00228       sinfo_qc_wcal_delete(&qc);
+<a name="l00229"></a>00229       <span class="keywordflow">return</span> -1;
+<a name="l00230"></a>00230     }
+<a name="l00231"></a>00231 
+<a name="l00232"></a>00232 
+<a name="l00233"></a>00233     lx = cpl_image_get_size_x(im);
+<a name="l00234"></a>00234     ly = cpl_image_get_size_y(im);
+<a name="l00235"></a>00235 
+<a name="l00236"></a>00236 
+<a name="l00237"></a>00237 
+<a name="l00238"></a>00238 <span class="keywordflow">if</span> (cfg->calibIndicator == 1 || cfg->wavemapInd == 1) {
+<a name="l00239"></a>00239     <span class="comment">/*---open the line list and read the number of lines---*/</span>
+<a name="l00240"></a>00240 
+<a name="l00241"></a>00241     <span class="keywordflow">if</span>(cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l00242"></a>00242       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>((<span class="keywordtype">char</span>* ) cpl_error_get_message());
+<a name="l00243"></a>00243       sinfo_qc_wcal_delete(&qc);
+<a name="l00244"></a>00244       <span class="keywordflow">return</span> -1;
+<a name="l00245"></a>00245     }
+<a name="l00246"></a>00246 
+<a name="l00247"></a>00247     tbl_line_list_name=cfg->lineList;
+<a name="l00248"></a>00248     tbl_line_list = cpl_table_load(tbl_line_list_name,1,0);
+<a name="l00249"></a>00249     <span class="keywordflow">if</span>(cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l00250"></a>00250       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>((<span class="keywordtype">char</span>* ) cpl_error_get_message());
+<a name="l00251"></a>00251       sinfo_qc_wcal_delete(&qc);
+<a name="l00252"></a>00252       <span class="keywordflow">return</span> -1;
+<a name="l00253"></a>00253     }
+<a name="l00254"></a>00254     n = cpl_table_get_nrow(tbl_line_list);
+<a name="l00255"></a>00255     n_lines = n;
+<a name="l00256"></a>00256     <span class="keywordflow">if</span>(cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l00257"></a>00257       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>((<span class="keywordtype">char</span>* ) cpl_error_get_message());
+<a name="l00258"></a>00258       sinfo_qc_wcal_delete(&qc);
+<a name="l00259"></a>00259       <span class="keywordflow">return</span> -1;
+<a name="l00260"></a>00260     }
+<a name="l00261"></a>00261 
+<a name="l00262"></a>00262     <span class="comment">/* THIS ORIGINATES A MEMORY LEAK </span>
+<a name="l00263"></a>00263 <span class="comment">    wave   = sinfo_new_floatarray (n);</span>
+<a name="l00264"></a>00264 <span class="comment">    intens = sinfo_new_floatarray (n);</span>
+<a name="l00265"></a>00265 <span class="comment">    if (wave == NULL || intens == NULL) {</span>
+<a name="l00266"></a>00266 <span class="comment">      sinfo_msg_error("could not allocate memory for the line list values\n" );</span>
+<a name="l00267"></a>00267 <span class="comment">      sinfo_qc_wcal_delete(&qc);</span>
+<a name="l00268"></a>00268 <span class="comment">      return -1;</span>
+<a name="l00269"></a>00269 <span class="comment">    }</span>
+<a name="l00270"></a>00270 <span class="comment">    */</span>
+<a name="l00271"></a>00271 
+<a name="l00272"></a>00272     wave   = cpl_table_get_data_float(tbl_line_list,<span class="stringliteral">"wave"</span>);
+<a name="l00273"></a>00273     <span class="keywordflow">if</span>(cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l00274"></a>00274       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>((<span class="keywordtype">char</span>* ) cpl_error_get_message());
+<a name="l00275"></a>00275       sinfo_qc_wcal_delete(&qc);
+<a name="l00276"></a>00276       <span class="keywordflow">return</span> -1;
+<a name="l00277"></a>00277     }
+<a name="l00278"></a>00278 
+<a name="l00279"></a>00279     intens = cpl_table_get_data_float(tbl_line_list,<span class="stringliteral">"int"</span>);
+<a name="l00280"></a>00280     <span class="keywordflow">if</span>(cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l00281"></a>00281       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>((<span class="keywordtype">char</span>* ) cpl_error_get_message());
+<a name="l00282"></a>00282       sinfo_qc_wcal_delete(&qc);
+<a name="l00283"></a>00283       <span class="keywordflow">return</span> -1;
+<a name="l00284"></a>00284     }
+<a name="l00285"></a>00285     
+<a name="l00286"></a>00286 }
+<a name="l00287"></a>00287 
+<a name="l00288"></a>00288 
+<a name="l00289"></a>00289 
+<a name="l00290"></a>00290 <span class="comment">/*</span>
+<a name="l00291"></a>00291 <span class="comment"> ----------------------------------------------------------------------</span>
+<a name="l00292"></a>00292 <span class="comment"> ---------------------------FINDLINES----------------------------------</span>
+<a name="l00293"></a>00293 <span class="comment"> ----------------------------------------------------------------------</span>
+<a name="l00294"></a>00294 <span class="comment"> */</span>
+<a name="l00295"></a>00295 
+<a name="l00296"></a>00296 
+<a name="l00297"></a>00297 <span class="comment">/*if not yet done:</span>
+<a name="l00298"></a>00298 <span class="comment">  do the wavelength calibration, that means: </span>
+<a name="l00299"></a>00299 <span class="comment">  find the dispersion relation and parameterize its coefficients</span>
+<a name="l00300"></a>00300 <span class="comment"> */</span>
+<a name="l00301"></a>00301 <span class="comment">/*</span>
+<a name="l00302"></a>00302 <span class="comment"> sinfo_msg("guessBeginWave=%g",cfg->guessBeginWavelength);</span>
+<a name="l00303"></a>00303 <span class="comment"> sinfo_msg("guessDisp1=%g",cfg->guessDispersion1);</span>
+<a name="l00304"></a>00304 <span class="comment"> sinfo_msg("guessDisp2=%g",cfg->guessDispersion2);</span>
+<a name="l00305"></a>00305 <span class="comment">*/</span>
+<a name="l00306"></a>00306 <span class="keywordflow">if</span> (cfg->calibIndicator == 1 && cfg->wavemapInd == 0) {
+<a name="l00307"></a>00307    sinfo_msg(<span class="stringliteral">"Findlines"</span>);
+<a name="l00308"></a>00308    acoefs  = sinfo_new_2Dfloatarray(cfg->nrDispCoefficients, lx);
+<a name="l00309"></a>00309    <span class="comment">/*allocate memory*/</span>
+<a name="l00310"></a>00310    n_found_lines    = sinfo_new_intarray(lx); 
+<a name="l00311"></a>00311    row_clean        = sinfo_new_2Dintarray(lx, n_lines);
+<a name="l00312"></a>00312    wavelength_clean = sinfo_new_2Dfloatarray(lx, n_lines);
+<a name="l00313"></a>00313    sum_pointer      = sinfo_new_intarray(1) ;
+<a name="l00314"></a>00314    <span class="comment">/*find the emission lines in each image column*/</span>
+<a name="l00315"></a>00315    sinfo_new_intarray_set_value(sum_pointer, 0, 0);
+<a name="l00316"></a>00316    check = sinfo_new_find_lines(im, wave, intens, n_lines, row_clean, 
+<a name="l00317"></a>00317                       wavelength_clean, cfg->guessBeginWavelength, 
+<a name="l00318"></a>00318              cfg->guessDispersion1, cfg->guessDispersion2,
+<a name="l00319"></a>00319                       cfg->mindiff, cfg->halfWidth, 
+<a name="l00320"></a>00320                       n_found_lines, cfg->sigma, sum_pointer );
+<a name="l00321"></a>00321    <span class="keywordflow">if</span> (-1 == check) {
+<a name="l00322"></a>00322            <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"sinfo_findLines failed!\n"</span>);
+<a name="l00323"></a>00323            sinfo_qc_wcal_delete(&qc);
+<a name="l00324"></a>00324            <span class="keywordflow">return</span> -1;
+<a name="l00325"></a>00325    }
+<a name="l00326"></a>00326       
+<a name="l00327"></a>00327 
+<a name="l00328"></a>00328 <span class="comment">/*---------------------------------------------------------------------</span>
+<a name="l00329"></a>00329 <span class="comment"> *-----------------------WAVE_CALIB-------------------------------------</span>
+<a name="l00330"></a>00330 <span class="comment"> *---------------------------------------------------------------------</span>
+<a name="l00331"></a>00331 <span class="comment"> */</span>
+<a name="l00332"></a>00332 
+<a name="l00333"></a>00333      
+<a name="l00334"></a>00334    sinfo_msg(<span class="stringliteral">"Wave Calibration"</span>);
+<a name="l00335"></a>00335    sum = sinfo_new_intarray_get_value(sum_pointer,0);
+<a name="l00336"></a>00336    <span class="comment">/* allocate memory for the fit parameters */</span>
+<a name="l00337"></a>00337    par = sinfo_new_fit_params( sum );
+<a name="l00338"></a>00338    <span class="keywordflow">if</span> (par == NULL) {
+<a name="l00339"></a>00339         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"sinfo_newFitParams failed!\n"</span>);
+<a name="l00340"></a>00340         sinfo_qc_wcal_delete(&qc);
+<a name="l00341"></a>00341         <span class="keywordflow">return</span> -1;
+<a name="l00342"></a>00342    }
+<a name="l00343"></a>00343 
+<a name="l00344"></a>00344   <span class="comment">/*</span>
+<a name="l00345"></a>00345 <span class="comment">   fit each line, make a polynomial fit and fit the resulting fit </span>
+<a name="l00346"></a>00346 <span class="comment">   coefficients across the columns of the slitlet</span>
+<a name="l00347"></a>00347 <span class="comment">   */</span>
+<a name="l00348"></a>00348    sinfo_slit_pos = sinfo_new_2Dfloatarray(32,2);
+<a name="l00349"></a>00349 
+<a name="l00350"></a>00350    map = sinfo_new_spred_wave_cal(im, 
+<a name="l00351"></a>00351                  par, 
+<a name="l00352"></a>00352                  acoefs, 
+<a name="l00353"></a>00353                  cfg->nslitlets, 
+<a name="l00354"></a>00354                  row_clean, 
+<a name="l00355"></a>00355                  wavelength_clean, 
+<a name="l00356"></a>00356                  n_found_lines, 
+<a name="l00357"></a>00357                  cfg->guessDispersion1, 
+<a name="l00358"></a>00358                  cfg->halfWidth, 
+<a name="l00359"></a>00359                  cfg->minAmplitude, 
+<a name="l00360"></a>00360                  cfg->maxResidual, 
+<a name="l00361"></a>00361                  cfg->fwhm, 
+<a name="l00362"></a>00362                  cfg->nrDispCoefficients, 
+<a name="l00363"></a>00363                  cfg->nrCoefCoefficients, 
+<a name="l00364"></a>00364                  cfg->sigmaFactor, 
+<a name="l00365"></a>00365                  cfg->pixeldist, 
+<a name="l00366"></a>00366                  cfg->pixel_tolerance,
+<a name="l00367"></a>00367                  sinfo_slit_pos);
+<a name="l00368"></a>00368 
+<a name="l00369"></a>00369  
+<a name="l00370"></a>00370    <span class="keywordflow">if</span> (map == NULL ) { 
+<a name="l00371"></a>00371           <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"sinfo_wave_cal failed!\n"</span>);
+<a name="l00372"></a>00372           sinfo_qc_wcal_delete(&qc);
+<a name="l00373"></a>00373       <span class="keywordflow">return</span> -1;
+<a name="l00374"></a>00374    }
+<a name="l00375"></a>00375    sinfo_msg(<span class="stringliteral">"Check line positions"</span>);
+<a name="l00376"></a>00376   
+<a name="l00377"></a>00377    shift = sinfo_new_check_line_positions (im, acoefs, 
+<a name="l00378"></a>00378                                           cfg->nrDispCoefficients,
+<a name="l00379"></a>00379                                           cfg->guessDispersion1, par);
+<a name="l00380"></a>00380    <span class="keywordflow">if</span> (FLAG == shift){ 
+<a name="l00381"></a>00381       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"checkForLinePositions failed!\n"</span>);
+<a name="l00382"></a>00382    }
+<a name="l00383"></a>00383 
+<a name="l00384"></a>00384 
+<a name="l00385"></a>00385     sinfo_det_ncounts(raw, cfg->qc_thresh_max,qc);
+<a name="l00386"></a>00386     qclog_tbl = sinfo_qclog_init();
+<a name="l00387"></a>00387     ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,<span class="stringliteral">"QC WAVE ALL"</span>,
+<a name="l00388"></a>00388                   n_lines,<span class="stringliteral">"Number of found lines"</span>,<span class="stringliteral">"%d"</span>));
+<a name="l00389"></a>00389 
+<a name="l00390"></a>00390     ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,<span class="stringliteral">"QC WAVE NPIXSAT"</span>,
+<a name="l00391"></a>00391                   qc->nsat,<span class="stringliteral">"Number of saturated pixels"</span>,<span class="stringliteral">"%d"</span>));
+<a name="l00392"></a>00392 
+<a name="l00393"></a>00393     ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,<span class="stringliteral">"QC WAVE MAXFLUX"</span>,
+<a name="l00394"></a>00394                 qc->max_di,<span class="stringliteral">"Max int off-lamp subracted frm"</span>,<span class="stringliteral">"%g"</span>));
+<a name="l00395"></a>00395 
+<a name="l00396"></a>00396    <span class="keywordflow">if</span>(-1 == sinfo_pro_save_ima(map,raw,sof,cfg->outName,
+<a name="l00397"></a>00397          PRO_WAVE_MAP,qclog_tbl,cpl_func,config)) {
+<a name="l00398"></a>00398          <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"cannot save ima %s"</span>, cfg->outName);
+<a name="l00399"></a>00399     }
+<a name="l00400"></a>00400    sinfo_free_table(&qclog_tbl);
+<a name="l00401"></a>00401  
+<a name="l00402"></a>00402  
+<a name="l00403"></a>00403    <span class="comment">/*</span>
+<a name="l00404"></a>00404 <span class="comment">    #store the resulting polynomial fit coefficients in an </span>
+<a name="l00405"></a>00405 <span class="comment">     ASCII file if wished</span>
+<a name="l00406"></a>00406 <span class="comment">    */</span>
+<a name="l00407"></a>00407 
+<a name="l00408"></a>00408    <span class="keywordflow">if</span> (cfg->writeCoeffsInd == 1) {
+<a name="l00409"></a>00409          col_name = (<span class="keywordtype">char</span>*) cpl_calloc(MAX_NAME_SIZE,<span class="keyword">sizeof</span>(<span class="keywordtype">char</span>*));
+<a name="l00410"></a>00410          tbl_name = (<span class="keywordtype">char</span>*) cpl_calloc(MAX_NAME_SIZE,<span class="keyword">sizeof</span>(<span class="keywordtype">char</span>*));
+<a name="l00411"></a>00411          tbl_wcal = cpl_table_new(lx);
+<a name="l00412"></a>00412          <span class="keywordflow">for</span> (i=0; i< cfg->nrDispCoefficients; i++) {
+<a name="l00413"></a>00413              snprintf(col_name,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%d"</span>,<span class="stringliteral">"coeff"</span>,i);
+<a name="l00414"></a>00414              cpl_table_new_column(tbl_wcal,col_name, CPL_TYPE_DOUBLE);
+<a name="l00415"></a>00415      }
+<a name="l00416"></a>00416 
+<a name="l00417"></a>00417 
+<a name="l00418"></a>00418          qclog_tbl = sinfo_qclog_init();
+<a name="l00419"></a>00419          key_name  = cpl_calloc(FILE_NAME_SZ,<span class="keyword">sizeof</span>(<span class="keywordtype">char</span>));
+<a name="l00420"></a>00420          ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,<span class="stringliteral">"QC WAVE ALL"</span>,
+<a name="l00421"></a>00421                n_lines,<span class="stringliteral">"Number of found lines"</span>,<span class="stringliteral">"%d"</span>));
+<a name="l00422"></a>00422 
+<a name="l00423"></a>00423 
+<a name="l00424"></a>00424 
+<a name="l00425"></a>00425          <span class="keywordflow">for</span> (j=0; j< lx; j++) { 
+<a name="l00426"></a>00426         <span class="keywordflow">for</span> (i=0; i< cfg->nrDispCoefficients; i++) {
+<a name="l00427"></a>00427                 snprintf(col_name,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%d"</span>,<span class="stringliteral">"coeff"</span>,i);
+<a name="l00428"></a>00428             a = sinfo_new_array2D_get_value(acoefs, i, j);
+<a name="l00429"></a>00429         <span class="comment">/* fprintf(acoefs_file, "%15.13g ", a) ; */</span>
+<a name="l00430"></a>00430                 cpl_table_set_double(tbl_wcal,col_name,j,a);
+<a name="l00431"></a>00431         }
+<a name="l00432"></a>00432 
+<a name="l00433"></a>00433 
+<a name="l00434"></a>00434      }
+<a name="l00435"></a>00435 
+<a name="l00436"></a>00436 
+<a name="l00437"></a>00437      <span class="keywordflow">for</span> (i=0; i< cfg->nrDispCoefficients; i++) {
+<a name="l00438"></a>00438             snprintf(col_name,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%d"</span>,<span class="stringliteral">"coeff"</span>,i);
+<a name="l00439"></a>00439             coef_avg=cpl_table_get_column_mean(tbl_wcal,col_name);
+<a name="l00440"></a>00440             coef_med=cpl_table_get_column_median(tbl_wcal,col_name);
+<a name="l00441"></a>00441 
+<a name="l00442"></a>00442             trow=1+i;
+<a name="l00443"></a>00443             snprintf(key_name,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%d%s"</span>,<span class="stringliteral">"QC COEF"</span>,i,<span class="stringliteral">" AVG"</span>);
+<a name="l00444"></a>00444             ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,key_name,coef_avg,
+<a name="l00445"></a>00445                          <span class="stringliteral">"Average wavecal Coef"</span>,<span class="stringliteral">"%g"</span>));
+<a name="l00446"></a>00446 
+<a name="l00447"></a>00447             trow=1+i+cfg->nrDispCoefficients;
+<a name="l00448"></a>00448             snprintf(key_name,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%d%s"</span>,<span class="stringliteral">"QC COEF"</span>,i,<span class="stringliteral">" MED"</span>);
+<a name="l00449"></a>00449             ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,key_name,coef_med,
+<a name="l00450"></a>00450                          <span class="stringliteral">"Median wavecal Coef"</span>,<span class="stringliteral">"%g"</span>));
+<a name="l00451"></a>00451 
+<a name="l00452"></a>00452      }
+<a name="l00453"></a>00453 
+<a name="l00454"></a>00454      <span class="comment">/*</span>
+<a name="l00455"></a>00455 <span class="comment">         fclose(acoefs_file);</span>
+<a name="l00456"></a>00456 <span class="comment">     */</span>
+<a name="l00457"></a>00457          strcpy(tbl_name,cfg->coeffsName);
+<a name="l00458"></a>00458 
+<a name="l00459"></a>00459          <span class="keywordflow">if</span>(-1 == sinfo_pro_save_tbl(tbl_wcal,raw,sof,tbl_name,
+<a name="l00460"></a>00460              PRO_WAVE_COEF_SLIT,qclog_tbl,cpl_func,config)) {
+<a name="l00461"></a>00461          <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"cannot save tbl %s"</span>, tbl_name);
+<a name="l00462"></a>00462          }
+<a name="l00463"></a>00463          sinfo_free_table(&tbl_wcal);
+<a name="l00464"></a>00464          sinfo_free_table(&qclog_tbl);
+<a name="l00465"></a>00465          cpl_free(key_name);
+<a name="l00466"></a>00466 
+<a name="l00467"></a>00467          cpl_free(col_name);
+<a name="l00468"></a>00468          cpl_free(tbl_name);
+<a name="l00469"></a>00469 
+<a name="l00470"></a>00470    }
+<a name="l00471"></a>00471 
+<a name="l00472"></a>00472 
+<a name="l00473"></a>00473    <span class="comment">/*</span>
+<a name="l00474"></a>00474 <span class="comment">    #store the resulting Gaussian fit parameters in an ASCII file if wished</span>
+<a name="l00475"></a>00475 <span class="comment">   */</span>
+<a name="l00476"></a>00476    <span class="keywordflow">if</span> (cfg->writeParInd == 1) {
+<a name="l00477"></a>00477 
+<a name="l00478"></a>00478 
+<a name="l00479"></a>00479       sinfo_new_dump_fit_params_to_ascii(par,WAVECAL_FIT_PARAMS_OUT_FILEASCII);
+<a name="l00480"></a>00480  
+<a name="l00481"></a>00481       <span class="keywordflow">if</span> ( NULL == par )
+<a name="l00482"></a>00482       {
+<a name="l00483"></a>00483          <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"no fit parameters available!"</span>) ;
+<a name="l00484"></a>00484          sinfo_qc_wcal_delete(&qc);
+<a name="l00485"></a>00485          <span class="keywordflow">return</span> -1;
+<a name="l00486"></a>00486       }
+<a name="l00487"></a>00487 
+<a name="l00488"></a>00488       <span class="keywordflow">if</span> ( NULL == cfg->paramsList )
+<a name="l00489"></a>00489       {
+<a name="l00490"></a>00490          <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"no filename available!"</span>) ;
+<a name="l00491"></a>00491          sinfo_qc_wcal_delete(&qc);
+<a name="l00492"></a>00492          <span class="keywordflow">return</span> -1;
+<a name="l00493"></a>00493       }
+<a name="l00494"></a>00494 
+<a name="l00495"></a>00495       tbl_fp = cpl_table_new(par[0] -> n_params);
+<a name="l00496"></a>00496       cpl_table_new_column(tbl_fp,<span class="stringliteral">"n_params"</span>, CPL_TYPE_INT);
+<a name="l00497"></a>00497       cpl_table_new_column(tbl_fp,<span class="stringliteral">"column"</span>, CPL_TYPE_INT);
+<a name="l00498"></a>00498       cpl_table_new_column(tbl_fp,<span class="stringliteral">"line"</span>, CPL_TYPE_INT);
+<a name="l00499"></a>00499       col = (<span class="keywordtype">char</span>*) cpl_calloc(MAX_NAME_SIZE,<span class="keyword">sizeof</span>(<span class="keywordtype">char</span>*));
+<a name="l00500"></a>00500 
+<a name="l00501"></a>00501       <span class="keywordflow">for</span>(j=0;j<4;j++) {
+<a name="l00502"></a>00502          snprintf(col,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%d"</span>,<span class="stringliteral">"fpar"</span>,j);
+<a name="l00503"></a>00503          cpl_table_new_column(tbl_fp,col, CPL_TYPE_DOUBLE);
+<a name="l00504"></a>00504          snprintf(col,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%d"</span>,<span class="stringliteral">"dpar"</span>,j);
+<a name="l00505"></a>00505          cpl_table_new_column(tbl_fp,col, CPL_TYPE_DOUBLE);
+<a name="l00506"></a>00506       }
+<a name="l00507"></a>00507 
+<a name="l00508"></a>00508 
+<a name="l00509"></a>00509 
+<a name="l00510"></a>00510     qclog_tbl = sinfo_qclog_init();
+<a name="l00511"></a>00511     ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,<span class="stringliteral">"QC NLINES"</span>,n_lines,
+<a name="l00512"></a>00512                   <span class="stringliteral">"Number of Found lines"</span>,<span class="stringliteral">"%d"</span>));
+<a name="l00513"></a>00513 
+<a name="l00514"></a>00514       <span class="keywordflow">for</span> ( i = 0 ; i < par[0] -> n_params ; i++ )
+<a name="l00515"></a>00515       {
+<a name="l00516"></a>00516          cpl_table_set_int(tbl_fp,<span class="stringliteral">"n_params"</span>,i,par[i]->n_params);
+<a name="l00517"></a>00517          cpl_table_set_int(tbl_fp,<span class="stringliteral">"column"</span>,i,par[i]->column);
+<a name="l00518"></a>00518          cpl_table_set_int(tbl_fp,<span class="stringliteral">"line"</span>,i,par[i]->line);
+<a name="l00519"></a>00519 
+<a name="l00520"></a>00520 
+<a name="l00521"></a>00521          <span class="keywordflow">for</span>(j=0;j<4;j++) {
+<a name="l00522"></a>00522         snprintf(col,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%d"</span>,<span class="stringliteral">"fpar"</span>,j);
+<a name="l00523"></a>00523             cpl_table_set_double(tbl_fp,col,i,par[i]->fit_par[j]);
+<a name="l00524"></a>00524         snprintf(col,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%d"</span>,<span class="stringliteral">"dpar"</span>,j);
+<a name="l00525"></a>00525             cpl_table_set_double(tbl_fp,col,i,par[i]->derv_par[j]);
+<a name="l00526"></a>00526      }
+<a name="l00527"></a>00527       }
+<a name="l00528"></a>00528 
+<a name="l00529"></a>00529       fwhm_avg = cpl_table_get_column_mean(tbl_fp,<span class="stringliteral">"fpar1"</span>);
+<a name="l00530"></a>00530       fwhm_med = cpl_table_get_column_median(tbl_fp,<span class="stringliteral">"fpar1"</span>);
+<a name="l00531"></a>00531       ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,<span class="stringliteral">"QC FWHM MED"</span>,fwhm_med,
+<a name="l00532"></a>00532                        <span class="stringliteral">"Median FWHM of found lines"</span>,<span class="stringliteral">"%f"</span>));
+<a name="l00533"></a>00533 
+<a name="l00534"></a>00534       ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,<span class="stringliteral">"QC FWHM AVG"</span>,fwhm_avg,
+<a name="l00535"></a>00535                        <span class="stringliteral">"Average FWHM of found lines"</span>,<span class="stringliteral">"%f"</span>));
+<a name="l00536"></a>00536 
+<a name="l00537"></a>00537 
+<a name="l00538"></a>00538       <span class="keywordflow">if</span>(-1 == sinfo_pro_save_tbl(tbl_fp,raw,sof,cfg->paramsList,
+<a name="l00539"></a>00539          PRO_WAVE_PAR_LIST,qclog_tbl,cpl_func,config)) {
+<a name="l00540"></a>00540          <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"cannot save tbl %s"</span>, cfg->paramsList);
+<a name="l00541"></a>00541       }
+<a name="l00542"></a>00542       sinfo_free_table(&qclog_tbl);
+<a name="l00543"></a>00543 
+<a name="l00544"></a>00544       sinfo_free_table(&tbl_fp) ;
+<a name="l00545"></a>00545       cpl_free(col);
+<a name="l00546"></a>00546 
+<a name="l00547"></a>00547    }
+<a name="l00548"></a>00548    <span class="comment">/* free memory */</span>
+<a name="l00549"></a>00549    sinfo_new_destroy_2Dfloatarray ( &wavelength_clean, lx );
+<a name="l00550"></a>00550    sinfo_new_destroy_2Dintarray (&row_clean, lx);
+<a name="l00551"></a>00551    sinfo_new_destroy_intarray(&n_found_lines );
+<a name="l00552"></a>00552    sinfo_new_destroy_intarray(&sum_pointer );
+<a name="l00553"></a>00553    sinfo_new_destroy_2Dfloatarray ( &acoefs, cfg->nrDispCoefficients );
+<a name="l00554"></a>00554 
+<a name="l00555"></a>00555 <span class="comment">/*----------------------------------------------------------------------</span>
+<a name="l00556"></a>00556 <span class="comment"> *-------------------WAVEMAP--------------------------------------------</span>
+<a name="l00557"></a>00557 <span class="comment"> *----------------------------------------------------------------------</span>
+<a name="l00558"></a>00558 <span class="comment"> */</span>
+<a name="l00559"></a>00559 
+<a name="l00560"></a>00560 <span class="comment">/*</span>
+<a name="l00561"></a>00561 <span class="comment">#---now do the cross sinfo_correlation and produce a wavelength map---</span>
+<a name="l00562"></a>00562 <span class="comment"> */</span>
+<a name="l00563"></a>00563 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (cfg->wavemapInd == 1 && cfg->calibIndicator == 0) { 
+<a name="l00564"></a>00564   sinfo_msg(<span class="stringliteral">"Wavemap"</span>);
+<a name="l00565"></a>00565   acoefs = sinfo_new_2Dfloatarray ( cfg->nrDispCoefficients, lx);
+<a name="l00566"></a>00566    <span class="comment">/* #read the parameterized dispersion relation */</span>
+<a name="l00567"></a>00567 
+<a name="l00568"></a>00568    tbl_name = (<span class="keywordtype">char</span>*) cpl_calloc(MAX_NAME_SIZE,<span class="keyword">sizeof</span>(<span class="keywordtype">char</span>*));
+<a name="l00569"></a>00569    col_name = (<span class="keywordtype">char</span>*) cpl_calloc(MAX_NAME_SIZE,<span class="keyword">sizeof</span>(<span class="keywordtype">char</span>*));
+<a name="l00570"></a>00570    strcpy(tbl_name,cfg->coeffsName);
+<a name="l00571"></a>00571    tbl_wcal = cpl_table_load(tbl_name,1,0);
+<a name="l00572"></a>00572     <span class="keywordflow">if</span>(cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l00573"></a>00573       sinfo_msg(<span class="stringliteral">"cannot load table %s"</span>,tbl_name);
+<a name="l00574"></a>00574       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>((<span class="keywordtype">char</span>* ) cpl_error_get_message());
+<a name="l00575"></a>00575       sinfo_qc_wcal_delete(&qc);
+<a name="l00576"></a>00576       <span class="keywordflow">return</span> -1;
+<a name="l00577"></a>00577     }
+<a name="l00578"></a>00578    <span class="keywordflow">for</span> (i =0; i < lx; i++) {
+<a name="l00579"></a>00579       <span class="keywordflow">for</span> (j = 0; j< cfg->nrDispCoefficients; j++) {
+<a name="l00580"></a>00580             snprintf(col_name,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%d"</span>,<span class="stringliteral">"coeff"</span>,j);
+<a name="l00581"></a>00581             acoefs[j][i]=cpl_table_get_double(tbl_wcal,col_name,i,status);
+<a name="l00582"></a>00582       }
+<a name="l00583"></a>00583    }
+<a name="l00584"></a>00584     <span class="keywordflow">if</span>(cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l00585"></a>00585       sinfo_msg(<span class="stringliteral">"cannot read table %s"</span>,tbl_name);
+<a name="l00586"></a>00586       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>((<span class="keywordtype">char</span>* ) cpl_error_get_message());
+<a name="l00587"></a>00587       sinfo_qc_wcal_delete(&qc);
+<a name="l00588"></a>00588       <span class="keywordflow">return</span> -1;
+<a name="l00589"></a>00589     }
+<a name="l00590"></a>00590     cpl_free(col_name);
+<a name="l00591"></a>00591     cpl_free(tbl_name);
+<a name="l00592"></a>00592     sinfo_free_table(&tbl_wcal);
+<a name="l00593"></a>00593 
+<a name="l00594"></a>00594     map = sinfo_new_create_shifted_slit_wavemap2 ( im, 
+<a name="l00595"></a>00595                                           acoefs, 
+<a name="l00596"></a>00596                                           cfg->nrDispCoefficients,
+<a name="l00597"></a>00597                                           wave, 
+<a name="l00598"></a>00598                                           intens, 
+<a name="l00599"></a>00599                                           n_lines, 
+<a name="l00600"></a>00600                                           cfg->magFactor, 
+<a name="l00601"></a>00601                       cfg->guessDispersion1, 
+<a name="l00602"></a>00602                                           cfg->pixeldist );
+<a name="l00603"></a>00603    <span class="keywordflow">if</span> (map == NULL) {
+<a name="l00604"></a>00604            <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"sinfo_createShiftedSlitWavemap2 failed!\n"</span>);
+<a name="l00605"></a>00605            sinfo_qc_wcal_delete(&qc);
+<a name="l00606"></a>00606            <span class="keywordflow">return</span> -1;
+<a name="l00607"></a>00607    }
+<a name="l00608"></a>00608 
+<a name="l00609"></a>00609    par = sinfo_new_fit_params(15*n_lines);
+<a name="l00610"></a>00610    sinfo_msg(<span class="stringliteral">"Check shifts"</span>);
+<a name="l00611"></a>00611 
+<a name="l00612"></a>00612    shift = sinfo_new_check_correlated_line_positions ( im, acoefs, 
+<a name="l00613"></a>00613                                            cfg->nrDispCoefficients, 
+<a name="l00614"></a>00614                                            wave, 
+<a name="l00615"></a>00615                                            intens, 
+<a name="l00616"></a>00616                                            n_lines, 
+<a name="l00617"></a>00617                                            cfg->fwhm, 
+<a name="l00618"></a>00618                                            cfg->halfWidth, 
+<a name="l00619"></a>00619                                            cfg->minAmplitude, 
+<a name="l00620"></a>00620                                            cfg->guessDispersion1, 
+<a name="l00621"></a>00621                                            par );
+<a name="l00622"></a>00622 
+<a name="l00623"></a>00623 
+<a name="l00624"></a>00624    <span class="keywordflow">if</span> (FLAG == shift){
+<a name="l00625"></a>00625       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"sinfo_checkCorrelatedLinePositions failed!\n"</span>);
+<a name="l00626"></a>00626    }
+<a name="l00627"></a>00627 
+<a name="l00628"></a>00628 
+<a name="l00629"></a>00629     sinfo_det_ncounts(raw, cfg->qc_thresh_max,qc);
+<a name="l00630"></a>00630     qclog_tbl = sinfo_qclog_init();
+<a name="l00631"></a>00631     ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,<span class="stringliteral">"QC NLINES"</span>,n_lines,
+<a name="l00632"></a>00632                   <span class="stringliteral">"Number of found lines"</span>,<span class="stringliteral">"%d"</span>));
+<a name="l00633"></a>00633 
+<a name="l00634"></a>00634 
+<a name="l00635"></a>00635 
+<a name="l00636"></a>00636     fwhm_avg = cpl_table_get_column_mean(tbl_fp,<span class="stringliteral">"fpar1"</span>);
+<a name="l00637"></a>00637     fwhm_med = cpl_table_get_column_median(tbl_fp,<span class="stringliteral">"fpar1"</span>);
+<a name="l00638"></a>00638 
+<a name="l00639"></a>00639     ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,<span class="stringliteral">"QC FWHM MED"</span>,fwhm_med,
+<a name="l00640"></a>00640                      <span class="stringliteral">"Median FWHM of found lines"</span>,<span class="stringliteral">"%f"</span>));
+<a name="l00641"></a>00641     ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,<span class="stringliteral">"QC FWHM AVG"</span>,fwhm_avg,
+<a name="l00642"></a>00642                      <span class="stringliteral">"Average FWHM of found lines"</span>,<span class="stringliteral">"%f"</span>));
+<a name="l00643"></a>00643 
+<a name="l00644"></a>00644 
+<a name="l00645"></a>00645     <span class="keywordflow">if</span>(-1 == sinfo_pro_save_ima(map,raw,sof,cfg->outName,
+<a name="l00646"></a>00646          PRO_WAVE_MAP,qclog_tbl,cpl_func,config)) {
+<a name="l00647"></a>00647          <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"cannot save ima %s"</span>, cfg->outName);
+<a name="l00648"></a>00648     }
+<a name="l00649"></a>00649     sinfo_free_table(&qclog_tbl);
+<a name="l00650"></a>00650 
+<a name="l00651"></a>00651 
+<a name="l00652"></a>00652    <span class="comment">/* # ---free memory--- */</span>
+<a name="l00653"></a>00653    sinfo_new_destroy_2Dfloatarray ( &acoefs, cfg->nrDispCoefficients );
+<a name="l00654"></a>00654    <span class="comment">/* To fix a memory bug we comment the following. But check! */</span>
+<a name="l00655"></a>00655 
+<a name="l00656"></a>00656 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (cfg->wavemapInd == 1 && cfg->calibIndicator == 1) {
+<a name="l00657"></a>00657    <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"give either wavemapIndicator = yes and calibIndicator = no \</span>
+<a name="l00658"></a>00658 <span class="stringliteral">                or wavemapIndicator = no and calibIndicator = yes"</span>) ;
+<a name="l00659"></a>00659    sinfo_qc_wcal_delete(&qc);
+<a name="l00660"></a>00660    <span class="keywordflow">return</span> -1;
+<a name="l00661"></a>00661 }
+<a name="l00662"></a>00662 
+<a name="l00663"></a>00663 
+<a name="l00664"></a>00664 <span class="comment">/*-------------------------------------------------------------------</span>
+<a name="l00665"></a>00665 <span class="comment"> *-------------------SLITFITS----------------------------------------</span>
+<a name="l00666"></a>00666 <span class="comment"> *-------------------------------------------------------------------</span>
+<a name="l00667"></a>00667 <span class="comment"> #--fit the slitlet sinfo_edge positions if desired--</span>
+<a name="l00668"></a>00668 <span class="comment"> */</span>
+<a name="l00669"></a>00669 <span class="keywordflow">if</span> (cfg->slitposIndicator == 1) {
+<a name="l00670"></a>00670   sinfo_msg(<span class="stringliteral">"fit the slitlet sinfo_edge positions"</span>);
+<a name="l00671"></a>00671 
+<a name="l00672"></a>00672 
+<a name="l00673"></a>00673     <span class="comment">/* #store the resulting sitlet positions in an TFITS table */</span>
+<a name="l00674"></a>00674    tbl_name = (<span class="keywordtype">char</span>*) cpl_calloc(MAX_NAME_SIZE,<span class="keyword">sizeof</span>(<span class="keywordtype">char</span>*));
+<a name="l00675"></a>00675    tbl_spos = cpl_table_new(32);
+<a name="l00676"></a>00676    cpl_table_new_column(tbl_spos,<span class="stringliteral">"pos1"</span>, CPL_TYPE_DOUBLE);
+<a name="l00677"></a>00677    cpl_table_new_column(tbl_spos,<span class="stringliteral">"pos2"</span>, CPL_TYPE_DOUBLE);
+<a name="l00678"></a>00678    cpl_table_set_column_format(tbl_spos,<span class="stringliteral">"pos1"</span>, <span class="stringliteral">"15.9f"</span>);
+<a name="l00679"></a>00679    cpl_table_set_column_format(tbl_spos,<span class="stringliteral">"pos2"</span>, <span class="stringliteral">"15.9f"</span>);
+<a name="l00680"></a>00680 
+<a name="l00681"></a>00681     <span class="keywordflow">for</span> (i =0; i< 32; i++) {
+<a name="l00682"></a>00682      <span class="comment">/*</span>
+<a name="l00683"></a>00683 <span class="comment">     fprintf( slitpos_file, "%15.9f %15.9f \n",</span>
+<a name="l00684"></a>00684 <span class="comment">      sinfo_new_array2D_get_value(sinfo_slit_pos,i,0),</span>
+<a name="l00685"></a>00685 <span class="comment">                        sinfo_new_array2D_get_value(sinfo_slit_pos,i,1));</span>
+<a name="l00686"></a>00686 <span class="comment">     */</span>
+<a name="l00687"></a>00687       cpl_table_set_double(tbl_spos,<span class="stringliteral">"pos1"</span>,i,
+<a name="l00688"></a>00688                            sinfo_new_array2D_get_value(sinfo_slit_pos,i,0));
+<a name="l00689"></a>00689       cpl_table_set_double(tbl_spos,<span class="stringliteral">"pos2"</span>,i,
+<a name="l00690"></a>00690                            sinfo_new_array2D_get_value(sinfo_slit_pos,i,1));
+<a name="l00691"></a>00691      
+<a name="l00692"></a>00692    }
+<a name="l00693"></a>00693     <span class="comment">/* strcpy(tbl_name,cfg->slitposName); */</span>
+<a name="l00694"></a>00694     strcpy(tbl_name,<span class="stringliteral">"out_guess_slit_pos.fits"</span>);
+<a name="l00695"></a>00695     <span class="keywordflow">if</span>(-1 == sinfo_pro_save_tbl(tbl_spos,raw,sof,tbl_name,
+<a name="l00696"></a>00696          PRO_SLIT_POS,NULL,cpl_func,config)) {
+<a name="l00697"></a>00697          <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"cannot save tbl %s"</span>, tbl_name);
+<a name="l00698"></a>00698     }
+<a name="l00699"></a>00699     sinfo_free_table(&tbl_spos);
+<a name="l00700"></a>00700     cpl_free(tbl_name);
+<a name="l00701"></a>00701    <span class="comment">/*# free memory*/</span>
+<a name="l00702"></a>00702    sinfo_new_destroy_2Dfloatarray ( &sinfo_slit_pos, 32 );
+<a name="l00703"></a>00703    
+<a name="l00704"></a>00704    
+<a name="l00705"></a>00705 }
+<a name="l00706"></a>00706 
+<a name="l00707"></a>00707 <span class="comment">/* #-----free the rest memory--*/</span>
+<a name="l00708"></a>00708 <span class="keywordflow">if</span> ( (cfg->slitposIndicator == 1 && cfg->estimateIndicator != 1) || 
+<a name="l00709"></a>00709      (cfg->calibIndicator == 1)  || (cfg->wavemapInd == 1) ){
+<a name="l00710"></a>00710      sinfo_new_destroy_fit_params(&par);
+<a name="l00711"></a>00711 }
+<a name="l00712"></a>00712 sinfo_free_image( &im );
+<a name="l00713"></a>00713 sinfo_free_image( &map );
+<a name="l00714"></a>00714 sinfo_wavecal_free(&cfg);
+<a name="l00715"></a>00715 sinfo_qc_wcal_delete(&qc);
+<a name="l00716"></a>00716 
+<a name="l00717"></a>00717  <span class="keywordflow">return</span> 0;
+<a name="l00718"></a>00718 
+<a name="l00719"></a>00719  cleanup:
+<a name="l00720"></a>00720  <span class="keywordflow">return</span> -1;
+<a name="l00721"></a>00721 
+<a name="l00722"></a>00722 
+<a name="l00723"></a>00723 
+<a name="l00724"></a>00724 }
+<a name="l00725"></a>00725 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__new__slit__pos_8h_source.html b/html/sinfo__new__slit__pos_8h_source.html
new file mode 100644
index 0000000..40a143b
--- /dev/null
+++ b/html/sinfo__new__slit__pos_8h_source.html
@@ -0,0 +1,146 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_new_slit_pos.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_new_slit_pos.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#ifndef SINFO_NEW_SLIT_POS_H</span>
+<a name="l00002"></a>00002 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_NEW_SLIT_POS_H</span>
+<a name="l00003"></a>00003 <span class="preprocessor"></span><span class="comment">/*</span>
+<a name="l00004"></a>00004 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00005"></a>00005 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00006"></a>00006 <span class="comment"> *</span>
+<a name="l00007"></a>00007 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00008"></a>00008 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00009"></a>00009 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00010"></a>00010 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00011"></a>00011 <span class="comment"> *</span>
+<a name="l00012"></a>00012 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00013"></a>00013 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00014"></a>00014 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00015"></a>00015 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00016"></a>00016 <span class="comment"> *</span>
+<a name="l00017"></a>00017 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00018"></a>00018 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00019"></a>00019 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00020"></a>00020 <span class="comment"> */</span>
+<a name="l00021"></a>00021 <span class="comment">/*****************************************************************************</span>
+<a name="l00022"></a>00022 <span class="comment">* E.S.O. - VLT project</span>
+<a name="l00023"></a>00023 <span class="comment">*</span>
+<a name="l00024"></a>00024 <span class="comment">* "@(#) $Id: sinfo_new_slit_pos.h,v 1.5 2007/06/06 07:10:45 amodigli Exp $"</span>
+<a name="l00025"></a>00025 <span class="comment">*</span>
+<a name="l00026"></a>00026 <span class="comment">* who       when      what</span>
+<a name="l00027"></a>00027 <span class="comment">* --------  --------  ----------------------------------------------</span>
+<a name="l00028"></a>00028 <span class="comment">* amodigli  17/09/03  created</span>
+<a name="l00029"></a>00029 <span class="comment">*/</span>
+<a name="l00030"></a>00030 
+<a name="l00031"></a>00031 <span class="comment">/************************************************************************</span>
+<a name="l00032"></a>00032 <span class="comment"> * sinfo_new_slit_pos.h</span>
+<a name="l00033"></a>00033 <span class="comment"></span>
+<a name="l00034"></a>00034 <span class="comment">  Normal method:</span>
+<a name="l00035"></a>00035 <span class="comment"></span>
+<a name="l00036"></a>00036 <span class="comment">  does the wavelength calibration and the fitting of the slitlet sinfo_edge </span>
+<a name="l00037"></a>00037 <span class="comment">  positions (ASCII file 32 x 2 values) if wished</span>
+<a name="l00038"></a>00038 <span class="comment">  produces an array of the bcoefs and of the fit parameters if wished and a </span>
+<a name="l00039"></a>00039 <span class="comment">  wavelength calibration map input is an emission line frame and a line list</span>
+<a name="l00040"></a>00040 <span class="comment"></span>
+<a name="l00041"></a>00041 <span class="comment">  o searching for lines by cross sinfo_correlation with a line list</span>
+<a name="l00042"></a>00042 <span class="comment">  o Gaussian fitting of emission lines in each column->positions of the lines-></span>
+<a name="l00043"></a>00043 <span class="comment">    resulting fit parameters can be stored in an ASCII file</span>
+<a name="l00044"></a>00044 <span class="comment">  o Fitting of a polynomial to the line positions for each column</span>
+<a name="l00045"></a>00045 <span class="comment">  o Smoothing: fitting of each polynomial coefficient by another polynomial</span>
+<a name="l00046"></a>00046 <span class="comment">    across the whole frame -> resulting polynomial coefficients can be stored </span>
+<a name="l00047"></a>00047 <span class="comment">    in an ASCII file.</span>
+<a name="l00048"></a>00048 <span class="comment">  o Wavelength calibration map (micron value for each frame pixel) can be</span>
+<a name="l00049"></a>00049 <span class="comment">    produced by using these coefficients and a cross sinfo_correlation to the</span>
+<a name="l00050"></a>00050 <span class="comment">    original frame</span>
+<a name="l00051"></a>00051 <span class="comment"></span>
+<a name="l00052"></a>00052 <span class="comment">  o The slitlet sinfo_edge positions can be fitted:</span>
+<a name="l00053"></a>00053 <span class="comment">    1) Automatically (not really stable) or by using guess sinfo_edge positions</span>
+<a name="l00054"></a>00054 <span class="comment">    2) By using a Boltzmann or a linear slope function</span>
+<a name="l00055"></a>00055 <span class="comment"></span>
+<a name="l00056"></a>00056 <span class="comment"></span>
+<a name="l00057"></a>00057 <span class="comment">  Slit method:</span>
+<a name="l00058"></a>00058 <span class="comment"></span>
+<a name="l00059"></a>00059 <span class="comment">  does the wavelength calibration and the fitting of the slitlet sinfo_edge </span>
+<a name="l00060"></a>00060 <span class="comment">  positions (ASCII file 32 x 2 values) if wished produces a list of the fit </span>
+<a name="l00061"></a>00061 <span class="comment">  parameters and of the smoothed coefficients if wished and a wavelength </span>
+<a name="l00062"></a>00062 <span class="comment">  calibration map input is an emission line frame and a line list</span>
+<a name="l00063"></a>00063 <span class="comment"></span>
+<a name="l00064"></a>00064 <span class="comment">  o Does the same as other method but smoothes the found polynomial </span>
+<a name="l00065"></a>00065 <span class="comment">    coefficients within each slitlet and not over the whole frame.</span>
+<a name="l00066"></a>00066 <span class="comment"></span>
+<a name="l00067"></a>00067 <span class="comment">  o Produces always a wavelength calibration map and does not crosscorrelate.</span>
+<a name="l00068"></a>00068 <span class="comment"></span>
+<a name="l00069"></a>00069 <span class="comment"> *----------------------------------------------------------------------</span>
+<a name="l00070"></a>00070 <span class="comment"> */</span>
+<a name="l00071"></a>00071 
+<a name="l00072"></a>00072 <span class="comment">/*</span>
+<a name="l00073"></a>00073 <span class="comment"> * header files</span>
+<a name="l00074"></a>00074 <span class="comment"> */</span>
+<a name="l00075"></a>00075 <span class="preprocessor">#include <cpl.h></span>   
+<a name="l00076"></a>00076 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00077"></a>00077 
+<a name="l00078"></a>00078 
+<a name="l00079"></a>00079 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00080"></a>00080 <span class="comment"> *                        Function ANSI C prototypes</span>
+<a name="l00081"></a>00081 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00082"></a>00082 
+<a name="l00083"></a>00083 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00084"></a>00084 <span class="comment">   Function     :       sinfo_new_slit_pos()</span>
+<a name="l00085"></a>00085 <span class="comment">   In           :       ini_file: file name of according .ini file</span>
+<a name="l00086"></a>00086 <span class="comment">   Out          :       integer (0 if it worked, -1 if it doesn't) </span>
+<a name="l00087"></a>00087 <span class="comment">   Job          :</span>
+<a name="l00088"></a>00088 <span class="comment"></span>
+<a name="l00089"></a>00089 <span class="comment"></span>
+<a name="l00090"></a>00090 <span class="comment">  Normal method:</span>
+<a name="l00091"></a>00091 <span class="comment"></span>
+<a name="l00092"></a>00092 <span class="comment">  does the wavelength calibration and the fitting of the slitlet sinfo_edge </span>
+<a name="l00093"></a>00093 <span class="comment">  positions (ASCII file 32 x 2 values) if wished</span>
+<a name="l00094"></a>00094 <span class="comment">  produces an array of the bcoefs and of the fit parameters if wished and a </span>
+<a name="l00095"></a>00095 <span class="comment">  wavelength calibration map input is an emission line frame and a line list</span>
+<a name="l00096"></a>00096 <span class="comment"></span>
+<a name="l00097"></a>00097 <span class="comment"></span>
+<a name="l00098"></a>00098 <span class="comment">  o searching for lines by cross sinfo_correlation with a line list</span>
+<a name="l00099"></a>00099 <span class="comment">  o Gaussian fitting of emission lines in each column->positions of the lines-></span>
+<a name="l00100"></a>00100 <span class="comment">    resulting fit parameters can be stored in an ASCII file</span>
+<a name="l00101"></a>00101 <span class="comment">  o Fitting of a polynomial to the line positions for each column</span>
+<a name="l00102"></a>00102 <span class="comment">  o Smoothing: fitting of each polynomial coefficient by another polynomial</span>
+<a name="l00103"></a>00103 <span class="comment">    across the whole frame -> resulting polynomial coefficients can be stored </span>
+<a name="l00104"></a>00104 <span class="comment">    in an ASCII file.</span>
+<a name="l00105"></a>00105 <span class="comment">  o Wavelength calibration map (micron value for each frame pixel) can be</span>
+<a name="l00106"></a>00106 <span class="comment">    produced by using these coefficients and a cross sinfo_correlation to the</span>
+<a name="l00107"></a>00107 <span class="comment">    original frame</span>
+<a name="l00108"></a>00108 <span class="comment"></span>
+<a name="l00109"></a>00109 <span class="comment">  o The slitlet sinfo_edge positions can be fitted:</span>
+<a name="l00110"></a>00110 <span class="comment">    1) Automatically (not really stable) or by using guess sinfo_edge positions</span>
+<a name="l00111"></a>00111 <span class="comment">    2) By using a Boltzmann or a linear slope function</span>
+<a name="l00112"></a>00112 <span class="comment"></span>
+<a name="l00113"></a>00113 <span class="comment">  Slit method:</span>
+<a name="l00114"></a>00114 <span class="comment"></span>
+<a name="l00115"></a>00115 <span class="comment">  does the wavelength calibration and the fitting of the slitlet sinfo_edge </span>
+<a name="l00116"></a>00116 <span class="comment">  positions (ASCII file 32 x 2 values) if wished produces a list of the fit </span>
+<a name="l00117"></a>00117 <span class="comment">  parameters and of the smoothed coefficients if wished and a wavelength </span>
+<a name="l00118"></a>00118 <span class="comment">  calibration map input is an emission line frame and a line list</span>
+<a name="l00119"></a>00119 <span class="comment"></span>
+<a name="l00120"></a>00120 <span class="comment">  o Does the same as other method but smoothes the found polynomial </span>
+<a name="l00121"></a>00121 <span class="comment">    coefficients within each slitlet and not over the whole frame.</span>
+<a name="l00122"></a>00122 <span class="comment"></span>
+<a name="l00123"></a>00123 <span class="comment">  o Produces always a wavelength calibration map and does not crosscorrelate.</span>
+<a name="l00124"></a>00124 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00125"></a>00125 <span class="keywordtype">int</span> sinfo_new_slit_pos (cpl_parameterlist* config, cpl_frameset* sof) ;
+<a name="l00126"></a>00126 
+<a name="l00127"></a>00127 
+<a name="l00128"></a>00128 <span class="preprocessor">#endif </span>
+<a name="l00129"></a>00129 <span class="preprocessor"></span>
+<a name="l00130"></a>00130 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__new__stdstar_8c_source.html b/html/sinfo__new__stdstar_8c_source.html
new file mode 100644
index 0000000..feb4159
--- /dev/null
+++ b/html/sinfo__new__stdstar_8c_source.html
@@ -0,0 +1,668 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_new_stdstar.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_new_stdstar.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment"></span>
+<a name="l00021"></a>00021 <span class="comment">   File name    :       sinfo_new_stdstar.c</span>
+<a name="l00022"></a>00022 <span class="comment">   Author       :    J. Schreiber</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on   :    December 3, 2003</span>
+<a name="l00024"></a>00024 <span class="comment">   Description  :    this routine doess the optimal extraction of a spectrum</span>
+<a name="l00025"></a>00025 <span class="comment">                        of an already reduced data cube of a standard star</span>
+<a name="l00026"></a>00026 <span class="comment">                        observation. Additionally, a conversion factor from</span>
+<a name="l00027"></a>00027 <span class="comment">                        mag to counts/sec can be determined if the magnitude</span>
+<a name="l00028"></a>00028 <span class="comment">                        of the standard star is known.</span>
+<a name="l00029"></a>00029 <span class="comment">                        This is done for a number of jittered data cubes and</span>
+<a name="l00030"></a>00030 <span class="comment">                        the results are averaged by rejecting the extreme</span>
+<a name="l00031"></a>00031 <span class="comment">                        values</span>
+<a name="l00032"></a>00032 <span class="comment"></span>
+<a name="l00033"></a>00033 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00034"></a>00034 
+<a name="l00035"></a>00035 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00036"></a>00036 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00037"></a>00037 <span class="preprocessor">#endif</span>
+<a name="l00038"></a>00038 <span class="preprocessor"></span><span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00039"></a>00039 <span class="comment">                                Includes</span>
+<a name="l00040"></a>00040 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include <math.h></span>
+<a name="l00042"></a>00042 
+<a name="l00043"></a>00043 <span class="comment">//Used only for sinfo_propertylist_has</span>
+<a name="l00044"></a>00044 <span class="preprocessor">#include <irplib_stdstar.h></span>
+<a name="l00045"></a>00045 <span class="preprocessor">#include <sinfo_cpl_size.h></span>
+<a name="l00046"></a>00046 <span class="preprocessor">#include "irplib_utils.h"</span>
+<a name="l00047"></a>00047 <span class="preprocessor">#include "sinfo_dfs.h"</span>
+<a name="l00048"></a>00048 <span class="preprocessor">#include "sinfo_tpl_utils.h"</span>
+<a name="l00049"></a>00049 
+<a name="l00050"></a>00050 <span class="preprocessor">#include "sinfo_new_stdstar.h"</span>
+<a name="l00051"></a>00051 <span class="preprocessor">#include "sinfo_standstar_ini_by_cpl.h"</span>
+<a name="l00052"></a>00052 <span class="preprocessor">#include "sinfo_pro_save.h"</span>
+<a name="l00053"></a>00053 <span class="preprocessor">#include "sinfo_pfits.h"</span>
+<a name="l00054"></a>00054 <span class="preprocessor">#include "sinfo_utilities_scired.h"</span>
+<a name="l00055"></a>00055 <span class="preprocessor">#include "sinfo_spectrum_ops.h"</span>
+<a name="l00056"></a>00056 <span class="preprocessor">#include "sinfo_hidden.h"</span>
+<a name="l00057"></a>00057 <span class="preprocessor">#include "sinfo_functions.h"</span>
+<a name="l00058"></a>00058 <span class="preprocessor">#include "sinfo_utl_efficiency.h"</span>
+<a name="l00059"></a>00059 <span class="preprocessor">#include "sinfo_error.h"</span>
+<a name="l00060"></a>00060 <span class="preprocessor">#include "sinfo_utils_wrappers.h"</span>
+<a name="l00061"></a>00061 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00062"></a>00062 <span class="comment">                                Defines</span>
+<a name="l00063"></a>00063 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00064"></a>00064 
+<a name="l00065"></a>00065 
+<a name="l00066"></a>00066 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00067"></a>00067 <span class="comment">                             Function Definitions</span>
+<a name="l00068"></a>00068 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00069"></a>00069 <span class="comment">/* temporally commented out as not yet used</span>
+<a name="l00070"></a>00070 <span class="comment">static int</span>
+<a name="l00071"></a>00071 <span class="comment">sinfo_compute_efficiency(cpl_frameset* sof,</span>
+<a name="l00072"></a>00072 <span class="comment">                              const char* name,</span>
+<a name="l00073"></a>00073 <span class="comment">                  standstar_config ** cfg,</span>
+<a name="l00074"></a>00074 <span class="comment">                  cpl_imagelist  * cube,</span>
+<a name="l00075"></a>00075 <span class="comment">             cpl_table** tbl_spectrum);</span>
+<a name="l00076"></a>00076 <span class="comment"></span>
+<a name="l00077"></a>00077 <span class="comment">*/</span>
+<a name="l00078"></a>00078 
+<a name="l00086"></a>00086 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00087"></a>00087 <span class="comment">   Function     :       sinfo_stdstar()</span>
+<a name="l00088"></a>00088 <span class="comment">   In           :       ini_file: file name of according .ini file</span>
+<a name="l00089"></a>00089 <span class="comment">   Out          :       integer (0 if it worked, -1 if it doesn't)</span>
+<a name="l00090"></a>00090 <span class="comment">   Job          :     this routine carries through the data cube creation of an</span>
+<a name="l00091"></a>00091 <span class="comment">                        object science observation using object-sky nodding</span>
+<a name="l00092"></a>00092 <span class="comment">                        and jittering. This script expects jittered frames that</span>
+<a name="l00093"></a>00093 <span class="comment">                were already sky-subtracted</span>
+<a name="l00094"></a>00094 <span class="comment">                        averaged, flatfielded, spectral tilt corrected and</span>
+<a name="l00095"></a>00095 <span class="comment">            interleaved if necessary</span>
+<a name="l00096"></a>00096 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00097"></a>00097 <span class="keywordtype">int</span>
+<a name="l00098"></a>00098 sinfo_new_stdstar(<span class="keyword">const</span> <span class="keywordtype">char</span>* plugin_id,
+<a name="l00099"></a>00099                   cpl_parameterlist* config,
+<a name="l00100"></a>00100                   cpl_frameset* sof,cpl_frameset* ref_set)
+<a name="l00101"></a>00101 {
+<a name="l00102"></a>00102 
+<a name="l00103"></a>00103   cpl_errorstate clean_state = cpl_errorstate_get();
+<a name="l00104"></a>00104     standstar_config * cfg=NULL ;
+<a name="l00105"></a>00105     cpl_imagelist  * cube=NULL ;
+<a name="l00106"></a>00106 
+<a name="l00107"></a>00107     cpl_imagelist  * list_object=NULL ;
+<a name="l00108"></a>00108     cpl_image ** spectrum=NULL ;
+<a name="l00109"></a>00109     cpl_image * img_spct=NULL ;
+<a name="l00110"></a>00110 
+<a name="l00111"></a>00111 
+<a name="l00112"></a>00112 
+<a name="l00113"></a>00113     cpl_frameset* raw=NULL;
+<a name="l00114"></a>00114     cpl_frame* frame=NULL;
+<a name="l00115"></a>00115     cpl_image* std_med_ima=NULL;
+<a name="l00116"></a>00116     cpl_image* std_med_dup=NULL;
+<a name="l00117"></a>00117 
+<a name="l00118"></a>00118     cpl_table* qclog_tbl=NULL;
+<a name="l00119"></a>00119     cpl_table* tbl_spectrum=NULL;
+<a name="l00120"></a>00120     cpl_propertylist* plist=NULL;
+<a name="l00121"></a>00121     <span class="comment">//char band[FILE_NAME_SZ];</span>
+<a name="l00122"></a>00122 
+<a name="l00123"></a>00123     <span class="keywordtype">char</span> * name=NULL ;
+<a name="l00124"></a>00124     <span class="keywordtype">int</span> fra=0;
+<a name="l00125"></a>00125     <span class="keywordtype">float</span> exptime=0 ;
+<a name="l00126"></a>00126     <span class="keywordtype">double</span> convfactor=0;
+<a name="l00127"></a>00127     <span class="keywordtype">double</span> cleanfactor=0;
+<a name="l00128"></a>00128     <span class="keywordtype">float</span>* factor=NULL;
+<a name="l00129"></a>00129 
+<a name="l00130"></a>00130     <span class="keywordtype">char</span> std_med_filename[MAX_NAME_SIZE];
+<a name="l00131"></a>00131     <span class="keywordtype">char</span> std_cub_filename[MAX_NAME_SIZE];
+<a name="l00132"></a>00132 
+<a name="l00133"></a>00133     <span class="keywordtype">double</span> max_ima_cx=0;
+<a name="l00134"></a>00134     <span class="keywordtype">double</span> max_ima_cy=0;
+<a name="l00135"></a>00135     cpl_size max_ima_x=0;
+<a name="l00136"></a>00136     cpl_size max_ima_y=0;
+<a name="l00137"></a>00137     <span class="keywordtype">double</span> norm=0;
+<a name="l00138"></a>00138     <span class="keywordtype">double</span> xcen=0;
+<a name="l00139"></a>00139     <span class="keywordtype">double</span> ycen=0;
+<a name="l00140"></a>00140     <span class="keywordtype">double</span> sig_x=0;
+<a name="l00141"></a>00141     <span class="keywordtype">double</span> sig_y=0;
+<a name="l00142"></a>00142     <span class="keywordtype">double</span> fwhm_x=0;
+<a name="l00143"></a>00143     <span class="keywordtype">double</span> fwhm_y=0;
+<a name="l00144"></a>00144     <span class="keywordtype">double</span> disp=0;
+<a name="l00145"></a>00145     <span class="keywordtype">double</span> dispersion=0;
+<a name="l00146"></a>00146     <span class="keywordtype">int</span> i=0;
+<a name="l00147"></a>00147     <span class="keywordtype">int</span> wllx=0;
+<a name="l00148"></a>00148     <span class="keywordtype">int</span> wlly=0;
+<a name="l00149"></a>00149     <span class="keywordtype">int</span> wurx=0;
+<a name="l00150"></a>00150     <span class="keywordtype">int</span> wury=0;
+<a name="l00151"></a>00151     <span class="keywordtype">int</span> psf_sz=40;
+<a name="l00152"></a>00152     <span class="keywordtype">int</span> qc_info=0;
+<a name="l00153"></a>00153     <span class="keywordtype">int</span> ima_szx=0;
+<a name="l00154"></a>00154     <span class="keywordtype">int</span> ima_szy=0;
+<a name="l00155"></a>00155     <span class="keywordtype">int</span> check1=0;
+<a name="l00156"></a>00156     <span class="keywordtype">int</span> check2=0;
+<a name="l00157"></a>00157     <span class="keywordtype">int</span> check3=0;
+<a name="l00158"></a>00158     <span class="keywordtype">int</span> check4=0;
+<a name="l00159"></a>00159     <span class="keywordtype">double</span> xshift=0;
+<a name="l00160"></a>00160     <span class="keywordtype">double</span> yshift=0;
+<a name="l00161"></a>00161 
+<a name="l00162"></a>00162     <span class="keywordtype">float</span> cenpix = 0;
+<a name="l00163"></a>00163     <span class="keywordtype">float</span> cenLambda = 0;
+<a name="l00164"></a>00164 
+<a name="l00165"></a>00165     <span class="keywordtype">int</span> no=0;
+<a name="l00166"></a>00166     <span class="keywordtype">double</span> lo_cut=0.;
+<a name="l00167"></a>00167     <span class="keywordtype">double</span> hi_cut=0.;
+<a name="l00168"></a>00168 
+<a name="l00169"></a>00169     <span class="keyword">const</span> <span class="keywordtype">char</span>* stdstars=NULL;
+<a name="l00170"></a>00170     <span class="keyword">const</span> <span class="keywordtype">char</span>* sed=NULL;
+<a name="l00171"></a>00171     cpl_frame* frm_sci=NULL;
+<a name="l00172"></a>00172     cpl_frame* frm_atmext=NULL;
+<a name="l00173"></a>00173     cpl_frame* frm_std_cat=NULL;
+<a name="l00174"></a>00174     cpl_table* tot_eff=NULL;
+<a name="l00175"></a>00175     <span class="keywordtype">double</span> fpar[7];
+<a name="l00176"></a>00176     <span class="keywordtype">double</span> dpar[7];
+<a name="l00177"></a>00177     <span class="keywordtype">int</span> mpar[7];
+<a name="l00178"></a>00178     <span class="keywordtype">int</span> do_compute_eff=0;
+<a name="l00179"></a>00179     cpl_parameter* p=NULL;
+<a name="l00180"></a>00180 
+<a name="l00181"></a>00181 
+<a name="l00182"></a>00182     <span class="comment">//For new way to compute efficiency</span>
+<a name="l00183"></a>00183     <span class="comment">//char band[80];</span>
+<a name="l00184"></a>00184     <span class="comment">//const char  *   seds_file=NULL;</span>
+<a name="l00185"></a>00185     <span class="comment">//const char  *   filter=NULL;</span>
+<a name="l00186"></a>00186     <span class="comment">//cpl_table* tbl_eff=NULL;</span>
+<a name="l00187"></a>00187     <span class="comment">/*</span>
+<a name="l00188"></a>00188 <span class="comment">       parse the file names and parameters to the cube_config</span>
+<a name="l00189"></a>00189 <span class="comment">       data structure cfg</span>
+<a name="l00190"></a>00190 <span class="comment">     */</span>
+<a name="l00191"></a>00191 
+<a name="l00192"></a>00192     <span class="comment">/* sinfo_msg("Parse cpl input"); */</span>
+<a name="l00193"></a>00193      check_nomsg(raw=cpl_frameset_new());
+<a name="l00194"></a>00194 
+<a name="l00195"></a>00195     cknull(cfg=sinfo_parse_cpl_input_standstar(config,sof,&raw),
+<a name="l00196"></a>00196        <span class="stringliteral">"could not parse cpl input!"</span>) ;
+<a name="l00197"></a>00197 
+<a name="l00198"></a>00198  
+<a name="l00199"></a>00199     cknull_nomsg(p = cpl_parameterlist_find(config,
+<a name="l00200"></a>00200                      <span class="stringliteral">"sinfoni.std_star.compute_eff"</span>));
+<a name="l00201"></a>00201  
+<a name="l00202"></a>00202     check_nomsg(do_compute_eff = cpl_parameter_get_bool(p));
+<a name="l00203"></a>00203      cknull(list_object = cpl_imagelist_new (),
+<a name="l00204"></a>00204        <span class="stringliteral">"could not allocate memory"</span>);
+<a name="l00205"></a>00205 
+<a name="l00206"></a>00206 
+<a name="l00207"></a>00207     sed = sinfo_extract_filename(sof, SINFO_CALIB_SED) ;
+<a name="l00208"></a>00208     stdstars = sinfo_extract_filename(sof, SINFO_CALIB_STDSTARS) ;
+<a name="l00209"></a>00209 
+<a name="l00210"></a>00210 
+<a name="l00211"></a>00211     <span class="keywordflow">if</span> (cfg->convInd == 1) {
+<a name="l00212"></a>00212       factor = sinfo_new_floatarray(cfg->nframes);
+<a name="l00213"></a>00213     }
+<a name="l00214"></a>00214 
+<a name="l00215"></a>00215     <span class="keywordflow">if</span>(NULL != cpl_frameset_find(sof,PRO_COADD_STD)) {
+<a name="l00216"></a>00216       frame = cpl_frameset_find(sof,PRO_COADD_STD);
+<a name="l00217"></a>00217       strcpy(std_cub_filename,cpl_frame_get_filename(frame));
+<a name="l00218"></a>00218     } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(NULL != cpl_frameset_find(sof,PRO_COADD_PSF)) {
+<a name="l00219"></a>00219       frame = cpl_frameset_find(sof,PRO_COADD_PSF);
+<a name="l00220"></a>00220       strcpy(std_cub_filename,cpl_frame_get_filename(frame));
+<a name="l00221"></a>00221     } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(NULL != cpl_frameset_find(sof,PRO_COADD_OBJ)) {
+<a name="l00222"></a>00222       frame = cpl_frameset_find(sof,PRO_COADD_OBJ);
+<a name="l00223"></a>00223       strcpy(std_cub_filename,cpl_frame_get_filename(frame));
+<a name="l00224"></a>00224     } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(NULL != cpl_frameset_find(sof,PRO_COADD_PUPIL)) {
+<a name="l00225"></a>00225       frame = cpl_frameset_find(sof,PRO_COADD_PUPIL);
+<a name="l00226"></a>00226       strcpy(std_cub_filename,cpl_frame_get_filename(frame));
+<a name="l00227"></a>00227     } <span class="keywordflow">else</span> {
+<a name="l00228"></a>00228       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Frame %s, %s, %s or %s not found! Exit!"</span>,
+<a name="l00229"></a>00229                        PRO_COADD_STD,PRO_COADD_PSF,
+<a name="l00230"></a>00230                        PRO_COADD_OBJ,PRO_COADD_PUPIL );
+<a name="l00231"></a>00231       <span class="keywordflow">goto</span> cleanup;
+<a name="l00232"></a>00232     }
+<a name="l00233"></a>00233 
+<a name="l00234"></a>00234 
+<a name="l00235"></a>00235     cknull(plist = cpl_propertylist_load(std_cub_filename, 0),
+<a name="l00236"></a>00236       <span class="stringliteral">"getting header from reference ima frame %s"</span>,std_cub_filename);
+<a name="l00237"></a>00237 
+<a name="l00238"></a>00238     cenpix = sinfo_pfits_get_crpix3(plist);
+<a name="l00239"></a>00239     cenLambda = sinfo_pfits_get_crval3(plist);
+<a name="l00240"></a>00240     dispersion = sinfo_pfits_get_cdelt3(plist);
+<a name="l00241"></a>00241 
+<a name="l00242"></a>00242 
+<a name="l00243"></a>00243     <span class="keywordflow">if</span> (sinfo_propertylist_has(plist, KEY_NAME_CDELT3)) {
+<a name="l00244"></a>00244       disp=cpl_propertylist_get_double(plist, KEY_NAME_CDELT3);
+<a name="l00245"></a>00245     } <span class="keywordflow">else</span> {
+<a name="l00246"></a>00246       <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"Keyword %s not found."</span>,KEY_NAME_CDELT3);
+<a name="l00247"></a>00247     }
+<a name="l00248"></a>00248 
+<a name="l00249"></a>00249 
+<a name="l00250"></a>00250     sinfo_free_propertylist(&plist) ;
+<a name="l00251"></a>00251 
+<a name="l00252"></a>00252     <span class="comment">/* we find automatiocally extraction parameters */</span>
+<a name="l00253"></a>00253 
+<a name="l00254"></a>00254 
+<a name="l00255"></a>00255     <span class="keywordflow">if</span>(NULL != cpl_frameset_find(sof,PRO_MED_COADD_STD)) {
+<a name="l00256"></a>00256       frame = cpl_frameset_find(sof,PRO_MED_COADD_STD);
+<a name="l00257"></a>00257       strcpy(std_med_filename,cpl_frame_get_filename(frame));
+<a name="l00258"></a>00258       check_nomsg(std_med_ima=cpl_image_load(std_med_filename,
+<a name="l00259"></a>00259                                              CPL_TYPE_FLOAT,0,0));
+<a name="l00260"></a>00260     } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(NULL != cpl_frameset_find(sof,PRO_OBS_STD)) {
+<a name="l00261"></a>00261       check_nomsg(frame = cpl_frameset_find(sof,PRO_OBS_STD));
+<a name="l00262"></a>00262       strcpy(std_cub_filename,cpl_frame_get_filename(frame));
+<a name="l00263"></a>00263       check_nomsg(cube = cpl_imagelist_load(std_cub_filename,
+<a name="l00264"></a>00264                                              CPL_TYPE_FLOAT,0));
+<a name="l00265"></a>00265       strcpy(std_med_filename,STDSTAR_OUT_MED_CUBE);
+<a name="l00266"></a>00266       check_nomsg(std_med_ima=cpl_imagelist_collapse_median_create(cube));
+<a name="l00267"></a>00267       sinfo_free_imagelist(&cube);
+<a name="l00268"></a>00268 
+<a name="l00269"></a>00269       ck0(sinfo_pro_save_ima(std_med_ima,ref_set,sof,STDSTAR_OUT_MED_CUBE,
+<a name="l00270"></a>00270                  PRO_MED_OBS_PSF,NULL,plugin_id,config),
+<a name="l00271"></a>00271       <span class="stringliteral">"Error saving image %s tag %s"</span>,STDSTAR_OUT_MED_CUBE,PRO_MED_OBS_PSF);
+<a name="l00272"></a>00272 
+<a name="l00273"></a>00273     } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(NULL != cpl_frameset_find(sof,PRO_MED_COADD_PSF)) {
+<a name="l00274"></a>00274       check_nomsg(frame = cpl_frameset_find(sof,PRO_MED_COADD_PSF));
+<a name="l00275"></a>00275       strcpy(std_med_filename,cpl_frame_get_filename(frame));
+<a name="l00276"></a>00276       check_nomsg(std_med_ima=cpl_image_load(std_med_filename,
+<a name="l00277"></a>00277                                              CPL_TYPE_FLOAT,0,0));
+<a name="l00278"></a>00278     } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(NULL != cpl_frameset_find(sof,PRO_OBS_PSF)) {
+<a name="l00279"></a>00279       check_nomsg(frame = cpl_frameset_find(sof,PRO_OBS_PSF));
+<a name="l00280"></a>00280       strcpy(std_cub_filename,cpl_frame_get_filename(frame));
+<a name="l00281"></a>00281       check_nomsg(cube=cpl_imagelist_load(std_cub_filename,CPL_TYPE_FLOAT,0));
+<a name="l00282"></a>00282       strcpy(std_med_filename,STDSTAR_OUT_MED_CUBE);
+<a name="l00283"></a>00283       check_nomsg(std_med_ima=cpl_imagelist_collapse_median_create(cube));
+<a name="l00284"></a>00284       sinfo_free_imagelist(&cube);
+<a name="l00285"></a>00285 
+<a name="l00286"></a>00286       ck0(sinfo_pro_save_ima(std_med_ima,ref_set,sof,STDSTAR_OUT_MED_CUBE,
+<a name="l00287"></a>00287                  PRO_MED_OBS_PSF,NULL,plugin_id,config),
+<a name="l00288"></a>00288       <span class="stringliteral">"Error saving image %s tag %s"</span>,STDSTAR_OUT_MED_CUBE,PRO_MED_OBS_PSF);
+<a name="l00289"></a>00289 
+<a name="l00290"></a>00290     } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(NULL != cpl_frameset_find(sof,PRO_MED_COADD_OBJ)) {
+<a name="l00291"></a>00291       check_nomsg(frame = cpl_frameset_find(sof,PRO_MED_COADD_OBJ));
+<a name="l00292"></a>00292       strcpy(std_med_filename,cpl_frame_get_filename(frame));
+<a name="l00293"></a>00293       check_nomsg(std_med_ima=cpl_image_load(std_med_filename,
+<a name="l00294"></a>00294                                              CPL_TYPE_FLOAT,0,0));
+<a name="l00295"></a>00295     } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(NULL != cpl_frameset_find(sof,PRO_OBS_OBJ)) {
+<a name="l00296"></a>00296       check_nomsg(frame = cpl_frameset_find(sof,PRO_OBS_OBJ));
+<a name="l00297"></a>00297       strcpy(std_cub_filename,cpl_frame_get_filename(frame));
+<a name="l00298"></a>00298       check_nomsg(cube = cpl_imagelist_load(std_cub_filename,
+<a name="l00299"></a>00299                                              CPL_TYPE_FLOAT,0));
+<a name="l00300"></a>00300       strcpy(std_med_filename,STDSTAR_OUT_MED_CUBE);
+<a name="l00301"></a>00301       check_nomsg(std_med_ima=cpl_imagelist_collapse_median_create(cube));
+<a name="l00302"></a>00302       sinfo_free_imagelist(&cube);
+<a name="l00303"></a>00303 
+<a name="l00304"></a>00304       ck0(sinfo_pro_save_ima(std_med_ima,ref_set,sof,STDSTAR_OUT_MED_CUBE,
+<a name="l00305"></a>00305                  PRO_MED_OBS_OBJ,NULL,plugin_id,config),
+<a name="l00306"></a>00306       <span class="stringliteral">"Error saving image %s tag %s"</span>,STDSTAR_OUT_MED_CUBE,PRO_MED_OBS_OBJ);
+<a name="l00307"></a>00307     } <span class="keywordflow">else</span> {
+<a name="l00308"></a>00308       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Frame %s %s %s %s %s %s not found! Exit!"</span>,
+<a name="l00309"></a>00309               PRO_MED_COADD_STD, PRO_OBS_STD,
+<a name="l00310"></a>00310                       PRO_MED_COADD_PSF, PRO_OBS_PSF,
+<a name="l00311"></a>00311                       PRO_MED_COADD_OBJ, PRO_OBS_OBJ);
+<a name="l00312"></a>00312       <span class="keywordflow">goto</span> cleanup;
+<a name="l00313"></a>00313     }
+<a name="l00314"></a>00314 
+<a name="l00315"></a>00315 
+<a name="l00316"></a>00316     check_nomsg(std_med_dup=cpl_image_duplicate(std_med_ima));
+<a name="l00317"></a>00317     sinfo_clean_nan(&std_med_dup);
+<a name="l00318"></a>00318     check_nomsg(cpl_image_get_maxpos(std_med_dup,&max_ima_x,&max_ima_y));
+<a name="l00319"></a>00319     sinfo_free_image(&std_med_dup);
+<a name="l00320"></a>00320 
+<a name="l00321"></a>00321 
+<a name="l00322"></a>00322     ima_szx=cpl_image_get_size_x(std_med_ima);
+<a name="l00323"></a>00323     ima_szy=cpl_image_get_size_y(std_med_ima);
+<a name="l00324"></a>00324     wllx= ((max_ima_x-psf_sz)>0)       ? (max_ima_x-psf_sz) : 1;
+<a name="l00325"></a>00325     wlly= ((max_ima_y-psf_sz)>0)       ? (max_ima_y-psf_sz) : 1;
+<a name="l00326"></a>00326     wurx= ((max_ima_x+psf_sz)<ima_szx) ? (max_ima_x+psf_sz) : ima_szx ;
+<a name="l00327"></a>00327     wury= ((max_ima_y+psf_sz)<ima_szy) ? (max_ima_y+psf_sz) : ima_szy ;
+<a name="l00328"></a>00328     <span class="comment">/*</span>
+<a name="l00329"></a>00329 <span class="comment">    sinfo_msg("wllx=%d wlly=%d wurx=%d wury=%d\n",wllx,wlly,wurx,wury);</span>
+<a name="l00330"></a>00330 <span class="comment">    cpl_image_get_maxpos_window(std_med_ima,wllx,wlly,wurx,wury,</span>
+<a name="l00331"></a>00331 <span class="comment">                                &max_ima_x,&max_ima_y);</span>
+<a name="l00332"></a>00332 <span class="comment">    */</span>
+<a name="l00333"></a>00333     check_nomsg(qclog_tbl = sinfo_qclog_init());
+<a name="l00334"></a>00334     check_nomsg(max_ima_cx=cpl_image_get_centroid_x_window(std_med_ima,wllx,
+<a name="l00335"></a>00335                                                            wlly,wurx,wury));
+<a name="l00336"></a>00336     check_nomsg(max_ima_cy=cpl_image_get_centroid_y_window(std_med_ima,wllx,
+<a name="l00337"></a>00337                                                              wlly,wurx,wury));
+<a name="l00338"></a>00338 
+<a name="l00339"></a>00339 
+<a name="l00340"></a>00340       xshift=max_ima_cx-ima_szx/2;
+<a name="l00341"></a>00341       yshift=max_ima_cy-ima_szy/2;
+<a name="l00342"></a>00342 
+<a name="l00343"></a>00343       ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,<span class="stringliteral">"QC SHIFTX"</span>,xshift,
+<a name="l00344"></a>00344                                        <span class="stringliteral">"X shift centroid - center image"</span>,<span class="stringliteral">"%f"</span>));
+<a name="l00345"></a>00345 
+<a name="l00346"></a>00346       ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,<span class="stringliteral">"QC SHIFTY"</span>,yshift,
+<a name="l00347"></a>00347                                        <span class="stringliteral">"Y shift centroid - center image"</span>,<span class="stringliteral">"%f"</span>));
+<a name="l00348"></a>00348 
+<a name="l00349"></a>00349     <span class="keywordflow">if</span>(
+<a name="l00350"></a>00350           ((max_ima_x-psf_sz) < 1) ||
+<a name="l00351"></a>00351           ((max_ima_y-psf_sz) < 1) ||
+<a name="l00352"></a>00352           ((max_ima_x+psf_sz) > ima_szx) ||
+<a name="l00353"></a>00353           ((max_ima_x+psf_sz) > ima_szy)
+<a name="l00354"></a>00354       )
+<a name="l00355"></a>00355       {
+<a name="l00356"></a>00356         psf_sz = (psf_sz < (max_ima_x-1))     ? psf_sz : (max_ima_x-1);
+<a name="l00357"></a>00357         psf_sz = (psf_sz < (max_ima_y-1))     ? psf_sz : (max_ima_y-1);
+<a name="l00358"></a>00358         psf_sz = (psf_sz < ima_szx-max_ima_x) ? psf_sz : (ima_szx-max_ima_x);
+<a name="l00359"></a>00359         psf_sz = (psf_sz < ima_szy-max_ima_y) ? psf_sz : (ima_szy-max_ima_y);
+<a name="l00360"></a>00360         <span class="comment">//added to prevent seg fault by cpl_image_fit_gaussian</span>
+<a name="l00361"></a>00361         psf_sz = (psf_sz > 4) ? psf_sz : 4;
+<a name="l00362"></a>00362       }
+<a name="l00363"></a>00363 
+<a name="l00364"></a>00364 
+<a name="l00365"></a>00365       ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,<span class="stringliteral">"QC FWHM LLX"</span>,cfg->llx,
+<a name="l00366"></a>00366                                     <span class="stringliteral">"STD star FWHM LLX"</span>,<span class="stringliteral">"%d"</span>));
+<a name="l00367"></a>00367       ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,<span class="stringliteral">"QC FWHM LLY"</span>,cfg->lly,
+<a name="l00368"></a>00368                                     <span class="stringliteral">"STD star FWHM LLY"</span>,<span class="stringliteral">"%d"</span>));
+<a name="l00369"></a>00369       ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,<span class="stringliteral">"QC FWHM HBX"</span>,cfg->halfbox_x,
+<a name="l00370"></a>00370                                     <span class="stringliteral">"STD star FWHM HBX"</span>,<span class="stringliteral">"%d"</span>));
+<a name="l00371"></a>00371       ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,<span class="stringliteral">"QC FWHM HBX"</span>,cfg->halfbox_y,
+<a name="l00372"></a>00372                                     <span class="stringliteral">"STD star FWHM HBY"</span>,<span class="stringliteral">"%d"</span>));
+<a name="l00373"></a>00373 
+<a name="l00374"></a>00374 
+<a name="l00375"></a>00375     <span class="comment">/* call the 2D-Gaussian fit routine */</span>
+<a name="l00376"></a>00376     <span class="keywordflow">for</span> ( i = 0 ; i < 7 ; i++ )
+<a name="l00377"></a>00377     {
+<a name="l00378"></a>00378         mpar[i] = 1 ;
+<a name="l00379"></a>00379     }
+<a name="l00380"></a>00380 
+<a name="l00381"></a>00381 
+<a name="l00382"></a>00382      <span class="keywordflow">if</span>(-1 == sinfo_new_fit_2d_gaussian(std_med_ima,
+<a name="l00383"></a>00383                                   fpar,
+<a name="l00384"></a>00384                                   dpar,
+<a name="l00385"></a>00385                                   mpar,
+<a name="l00386"></a>00386                                   cfg->llx,
+<a name="l00387"></a>00387                                   cfg->lly,
+<a name="l00388"></a>00388                                   cfg->halfbox_x,
+<a name="l00389"></a>00389                                   cfg->halfbox_y,
+<a name="l00390"></a>00390                                   &check4 ) ) {
+<a name="l00391"></a>00391       irplib_error_recover(clean_state,<span class="stringliteral">"2d Gaussian fit failed"</span>);
+<a name="l00392"></a>00392       <span class="comment">/* return 0; */</span>
+<a name="l00393"></a>00393 
+<a name="l00394"></a>00394      } <span class="keywordflow">else</span> {
+<a name="l00395"></a>00395 
+<a name="l00396"></a>00396       ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,<span class="stringliteral">"QC FWHM MAJ"</span>,fpar[4],
+<a name="l00397"></a>00397                                        <span class="stringliteral">"STD star FWHM on major axis"</span>,<span class="stringliteral">"%f"</span>));
+<a name="l00398"></a>00398       ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,<span class="stringliteral">"QC FWHM MIN"</span>,fpar[5],
+<a name="l00399"></a>00399                                        <span class="stringliteral">"STD star FWHM on minor axis"</span>,<span class="stringliteral">"%f"</span>));
+<a name="l00400"></a>00400       ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,<span class="stringliteral">"QC THETA"</span>,fpar[6],
+<a name="l00401"></a>00401                                        <span class="stringliteral">"STD star ellipsis angle theta"</span>,<span class="stringliteral">"%f"</span>));
+<a name="l00402"></a>00402 
+<a name="l00403"></a>00403 
+<a name="l00404"></a>00404      }
+<a name="l00405"></a>00405 
+<a name="l00406"></a>00406 
+<a name="l00407"></a>00407     <span class="comment">/*</span>
+<a name="l00408"></a>00408 <span class="comment">    sinfo_msg("Gauss fit params: xc,yc,amp,bkg,fwhm_x,fwhm_y,angle\n");</span>
+<a name="l00409"></a>00409 <span class="comment">    for ( i = 0 ; i < 7 ; i++ )</span>
+<a name="l00410"></a>00410 <span class="comment">      {</span>
+<a name="l00411"></a>00411 <span class="comment">        sinfo_msg("fpar[%d]=%f dpar[%d]=%f\n",i,fpar[i],i,dpar[i]);</span>
+<a name="l00412"></a>00412 <span class="comment">      }</span>
+<a name="l00413"></a>00413 <span class="comment">    */</span>
+<a name="l00414"></a>00414     <span class="keywordflow">if</span>(CPL_ERROR_NONE == cpl_image_fit_gaussian(std_med_ima,
+<a name="l00415"></a>00415                                                 max_ima_x,
+<a name="l00416"></a>00416                                                 max_ima_y,
+<a name="l00417"></a>00417                                                 psf_sz,
+<a name="l00418"></a>00418                                                 &norm,
+<a name="l00419"></a>00419                                                 &xcen,
+<a name="l00420"></a>00420                                                 &ycen,
+<a name="l00421"></a>00421                                                 &sig_x,
+<a name="l00422"></a>00422                                                 &sig_y,
+<a name="l00423"></a>00423                                                 &fwhm_x,
+<a name="l00424"></a>00424                                                 &fwhm_y)) {
+<a name="l00425"></a>00425 
+<a name="l00426"></a>00426 
+<a name="l00427"></a>00427       ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,<span class="stringliteral">"QC FWHMX"</span>,fwhm_x,
+<a name="l00428"></a>00428                                        <span class="stringliteral">"STD star FWHM on X"</span>,<span class="stringliteral">"%f"</span>));
+<a name="l00429"></a>00429       ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,<span class="stringliteral">"QC FWHMY"</span>,fwhm_y,
+<a name="l00430"></a>00430                                        <span class="stringliteral">"STD star FWHM on Y"</span>,<span class="stringliteral">"%f"</span>));
+<a name="l00431"></a>00431 
+<a name="l00432"></a>00432       cfg -> halfbox_x =  (floor)(0.5*(fwhm_x+fwhm_y)*cfg->fwhm_factor+0.5);
+<a name="l00433"></a>00433 
+<a name="l00434"></a>00434       cfg -> halfbox_y =  (floor)(0.5*(fwhm_x+fwhm_y)*cfg->fwhm_factor+0.5);
+<a name="l00435"></a>00435 
+<a name="l00436"></a>00436     } <span class="keywordflow">else</span> {
+<a name="l00437"></a>00437 
+<a name="l00438"></a>00438       irplib_error_recover(clean_state,<span class="stringliteral">"Problem fitting Gaussian"</span>);
+<a name="l00439"></a>00439       cpl_error_reset();
+<a name="l00440"></a>00440 
+<a name="l00441"></a>00441     }
+<a name="l00442"></a>00442     sinfo_free_image(&std_med_ima);
+<a name="l00443"></a>00443 
+<a name="l00444"></a>00444       <span class="comment">/*</span>
+<a name="l00445"></a>00445 <span class="comment">      sinfo_msg("max ima=%d %d psf_sz=%d\n",max_ima_x,max_ima_y,psf_sz);</span>
+<a name="l00446"></a>00446 <span class="comment">      sinfo_msg("centroid ima=%f %f\n",max_ima_cx,max_ima_cy);</span>
+<a name="l00447"></a>00447 <span class="comment">      sinfo_msg("gauss=norm=%f xcen=%f ycen=%f sig_x=%f "</span>
+<a name="l00448"></a>00448 <span class="comment">                "sig_y=%f fwhm_x=%f fwhm_y=%f\n",</span>
+<a name="l00449"></a>00449 <span class="comment">                          norm,xcen,ycen,sig_x,sig_y,fwhm_x,fwhm_y);</span>
+<a name="l00450"></a>00450 <span class="comment">      */</span>
+<a name="l00451"></a>00451 
+<a name="l00452"></a>00452       cfg -> llx = (int)(xcen-cfg->halfbox_x);
+<a name="l00453"></a>00453       cfg -> llx = (cfg -> llx  > 0 ) ? cfg -> llx  : 1;
+<a name="l00454"></a>00454 
+<a name="l00455"></a>00455       <span class="keywordflow">if</span>((cfg->llx+2*cfg->halfbox_x) >= ima_szx) {
+<a name="l00456"></a>00456     cfg -> halfbox_x=(int) ((ima_szx-cfg->llx-1)/2);
+<a name="l00457"></a>00457         check1++;
+<a name="l00458"></a>00458       }
+<a name="l00459"></a>00459 
+<a name="l00460"></a>00460       cfg -> lly = (int)(ycen-cfg->halfbox_y);
+<a name="l00461"></a>00461       cfg -> lly = (cfg -> lly  > 0 ) ? cfg -> lly  : 1;
+<a name="l00462"></a>00462       <span class="keywordflow">if</span>((cfg->lly+2*cfg->halfbox_y) >= ima_szy) {
+<a name="l00463"></a>00463     cfg -> halfbox_y=(int) ((ima_szy-cfg->lly-1)/2);
+<a name="l00464"></a>00464         check1++;
+<a name="l00465"></a>00465       }
+<a name="l00466"></a>00466      ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,<span class="stringliteral">"QC CHECK1"</span>,check1,
+<a name="l00467"></a>00467                                     <span class="stringliteral">"Check on evaluation box"</span>,<span class="stringliteral">"%d"</span>));
+<a name="l00468"></a>00468 
+<a name="l00469"></a>00469 
+<a name="l00470"></a>00470     <span class="comment">/*</span>
+<a name="l00471"></a>00471 <span class="comment">      sinfo_msg("llx= %d lly= %d\n",cfg->llx, cfg->lly);</span>
+<a name="l00472"></a>00472 <span class="comment">      sinfo_msg("halfbox_x=%d halfbox_y=%d\n",cfg->halfbox_x,cfg->halfbox_y);</span>
+<a name="l00473"></a>00473 <span class="comment">     */</span>
+<a name="l00474"></a>00474 
+<a name="l00475"></a>00475     <span class="comment">/*</span>
+<a name="l00476"></a>00476 <span class="comment">#----------------------------------------------------------------------</span>
+<a name="l00477"></a>00477 <span class="comment">#---------------------------EXTRACTION---------------------------------</span>
+<a name="l00478"></a>00478 <span class="comment">#----------------------------------------------------------------------</span>
+<a name="l00479"></a>00479 <span class="comment">    */</span>
+<a name="l00480"></a>00480 
+<a name="l00481"></a>00481       sinfo_msg(<span class="stringliteral">"Extraction"</span>);
+<a name="l00482"></a>00482       cknull(spectrum = (cpl_image**) cpl_calloc (cfg -> nframes,
+<a name="l00483"></a>00483                                                   <span class="keyword">sizeof</span>(cpl_image*)),
+<a name="l00484"></a>00484                             <span class="stringliteral">"Could not allocate memory for spectrum image"</span>);
+<a name="l00485"></a>00485 
+<a name="l00486"></a>00486       <span class="keywordflow">for</span> (fra=0; fra < cfg->nframes; fra++) {
+<a name="l00487"></a>00487          name = cfg->inFrameList[fra];
+<a name="l00488"></a>00488          <span class="keywordflow">if</span>(sinfo_is_fits_file(name) != 1) {
+<a name="l00489"></a>00489             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Input file %s is not FITS"</span>,name);
+<a name="l00490"></a>00490             <span class="keywordflow">goto</span> cleanup;
+<a name="l00491"></a>00491      }
+<a name="l00492"></a>00492          cknull(cube = cpl_imagelist_load(name,CPL_TYPE_FLOAT,0),
+<a name="l00493"></a>00493         <span class="stringliteral">"could not load data cube"</span> );
+<a name="l00494"></a>00494 
+<a name="l00495"></a>00495          <span class="keywordflow">if</span> (exptime == FLAG) {
+<a name="l00496"></a>00496        <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"could not find exposure time in the fits header"</span>);
+<a name="l00497"></a>00497        <span class="keywordflow">return</span> -1;
+<a name="l00498"></a>00498      }
+<a name="l00499"></a>00499          exptime = sinfo_pfits_get_ditndit(name);
+<a name="l00500"></a>00500 
+<a name="l00501"></a>00501          sinfo_msg(<span class="stringliteral">"cfg->gain %f"</span>,cfg->gain);
+<a name="l00502"></a>00502          check_nomsg(tbl_spectrum=cpl_table_new(cpl_imagelist_get_size(cube)));
+<a name="l00503"></a>00503         <span class="keywordflow">if</span>(NULL==(spectrum[fra]=sinfo_new_optimal_extraction_from_cube( cube,
+<a name="l00504"></a>00504                                       cfg->llx,
+<a name="l00505"></a>00505                                       cfg->lly,
+<a name="l00506"></a>00506                                       cfg->halfbox_x,
+<a name="l00507"></a>00507                                       cfg->halfbox_y,
+<a name="l00508"></a>00508                                       cfg->fwhm_factor,
+<a name="l00509"></a>00509                                       BKG_VARIANCE,
+<a name="l00510"></a>00510                                       SKY_FLUX,
+<a name="l00511"></a>00511                                       cfg->gain,
+<a name="l00512"></a>00512                                       exptime,
+<a name="l00513"></a>00513                                       name,
+<a name="l00514"></a>00514                                       &tbl_spectrum,
+<a name="l00515"></a>00515                                       qc_info,
+<a name="l00516"></a>00516                                       &check2))){
+<a name="l00517"></a>00517 
+<a name="l00518"></a>00518       irplib_error_recover(clean_state,
+<a name="l00519"></a>00519                <span class="stringliteral">"could not do sinfo_optimalExtractionFromCube"</span>);
+<a name="l00520"></a>00520      } <span class="keywordflow">else</span> {
+<a name="l00521"></a>00521      check_nomsg(cpl_imagelist_set(list_object,
+<a name="l00522"></a>00522                      cpl_image_duplicate(spectrum[fra]), fra));
+<a name="l00523"></a>00523 
+<a name="l00524"></a>00524      }
+<a name="l00525"></a>00525 
+<a name="l00526"></a>00526 
+<a name="l00527"></a>00527 
+<a name="l00528"></a>00528     ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,<span class="stringliteral">"QC CHECK2"</span>,
+<a name="l00529"></a>00529                                        check2,<span class="stringliteral">"Check on evaluation box"</span>,<span class="stringliteral">"%d"</span>));
+<a name="l00530"></a>00530 
+<a name="l00531"></a>00531 
+<a name="l00532"></a>00532         ck0(sinfo_pro_save_tbl(tbl_spectrum,ref_set,sof,
+<a name="l00533"></a>00533                                       (<span class="keywordtype">char</span>*)STDSTAR_OUT_TABLE,
+<a name="l00534"></a>00534                       PRO_STD_STAR_SPECTRA,qclog_tbl,
+<a name="l00535"></a>00535                 plugin_id,config),
+<a name="l00536"></a>00536          <span class="stringliteral">"cannot dump ima %s"</span>, <span class="stringliteral">"out_std_star_spectrum.fits"</span>);
+<a name="l00537"></a>00537 
+<a name="l00538"></a>00538 
+<a name="l00539"></a>00539      sinfo_free_table(&qclog_tbl);
+<a name="l00540"></a>00540 
+<a name="l00541"></a>00541      <span class="keywordflow">if</span> (do_compute_eff!=0 && frm_std_cat !=NULL && frm_atmext != NULL) {
+<a name="l00542"></a>00542         sinfo_msg(<span class="stringliteral">"compute efficiency"</span>);
+<a name="l00543"></a>00543         frm_sci     = cpl_frameset_find(sof,PRO_STD_STAR_SPECTRA);
+<a name="l00544"></a>00544         frm_std_cat = cpl_frameset_find(sof,FLUX_STD_CATALOG);
+<a name="l00545"></a>00545         frm_atmext  = cpl_frameset_find(sof,EXTCOEFF_TABLE);
+<a name="l00546"></a>00546 
+<a name="l00547"></a>00547 
+<a name="l00548"></a>00548 
+<a name="l00549"></a>00549         check_nomsg(tot_eff=sinfo_efficiency_compute(frm_sci,frm_std_cat,
+<a name="l00550"></a>00550                                                      frm_atmext));
+<a name="l00551"></a>00551         ck0(sinfo_pro_save_tbl(tot_eff,ref_set,sof,(<span class="keywordtype">char</span>*)EFFICIENCY_FILENAME,
+<a name="l00552"></a>00552                                PRO_EFFICIENCY,qclog_tbl,plugin_id,config),
+<a name="l00553"></a>00553             <span class="stringliteral">"cannot dump ima %s"</span>, <span class="stringliteral">"out_.fits"</span>);
+<a name="l00554"></a>00554      }
+<a name="l00555"></a>00555 
+<a name="l00556"></a>00556 
+<a name="l00557"></a>00557 
+<a name="l00558"></a>00558 
+<a name="l00559"></a>00559      <span class="comment">/*</span>
+<a name="l00560"></a>00560 <span class="comment">         if(spectrum[fra] != NULL ) {</span>
+<a name="l00561"></a>00561 <span class="comment">         sinfo_free_image(&(spectrum)[fra]);</span>
+<a name="l00562"></a>00562 <span class="comment">         }</span>
+<a name="l00563"></a>00563 <span class="comment">     */</span>
+<a name="l00564"></a>00564      <span class="comment">/*----determine the intensity conversion factor if wished--------*/</span>
+<a name="l00565"></a>00565      <span class="keywordflow">if</span> (cfg->convInd == 1) {
+<a name="l00566"></a>00566        sinfo_msg(<span class="stringliteral">"Determines convertion factor"</span>);
+<a name="l00567"></a>00567 
+<a name="l00568"></a>00568            convfactor = sinfo_new_determine_conversion_factor( cube,
+<a name="l00569"></a>00569                                                 cfg->mag,
+<a name="l00570"></a>00570                                                 exptime,
+<a name="l00571"></a>00571                                                 cfg->llx,
+<a name="l00572"></a>00572                                                 cfg->lly,
+<a name="l00573"></a>00573                                                 cfg->halfbox_x,
+<a name="l00574"></a>00574                                                 cfg->halfbox_y,
+<a name="l00575"></a>00575                                                 &check3 );
+<a name="l00576"></a>00576 
+<a name="l00577"></a>00577 
+<a name="l00578"></a>00578             <span class="keywordflow">if</span> (convfactor < -100000.) {
+<a name="l00579"></a>00579             <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"could not do sinfo_determineConversionFactor!"</span> );
+<a name="l00580"></a>00580            <span class="comment">/* goto cleanup; */</span>
+<a name="l00581"></a>00581         } <span class="keywordflow">else</span> {
+<a name="l00582"></a>00582              sinfo_new_array_set_value(factor, convfactor, fra);
+<a name="l00583"></a>00583         }
+<a name="l00584"></a>00584      }
+<a name="l00585"></a>00585      sinfo_free_imagelist(&cube);
+<a name="l00586"></a>00586       } <span class="comment">/* end loop over fra */</span>
+<a name="l00587"></a>00587 
+<a name="l00588"></a>00588       sinfo_free_table(&tbl_spectrum);
+<a name="l00589"></a>00589       sinfo_free_image_array(&spectrum,cfg->nframes);
+<a name="l00590"></a>00590       <span class="keywordflow">if</span> (cfg->convInd == 1) {
+<a name="l00591"></a>00591     sinfo_msg(<span class="stringliteral">"Determines clean factor"</span>);
+<a name="l00592"></a>00592         cleanfactor = sinfo_new_clean_mean(factor,
+<a name="l00593"></a>00593                                  cfg->nframes,
+<a name="l00594"></a>00594                                  cfg->lo_reject*100.,
+<a name="l00595"></a>00595                  cfg->hi_reject*100.);
+<a name="l00596"></a>00596       }
+<a name="l00597"></a>00597       <span class="keywordflow">if</span> (cleanfactor > 100000. || cleanfactor == FLAG) {
+<a name="l00598"></a>00598     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"could not do sinfo_clean_mean!"</span> );
+<a name="l00599"></a>00599         <span class="keywordflow">goto</span> cleanup;
+<a name="l00600"></a>00600       }
+<a name="l00601"></a>00601 
+<a name="l00602"></a>00602 
+<a name="l00603"></a>00603   <span class="comment">/*---read the fits header to change the gain and noise parameter-----*/</span>
+<a name="l00604"></a>00604       sinfo_msg(<span class="stringliteral">"Average with rejection"</span>);
+<a name="l00605"></a>00605 
+<a name="l00606"></a>00606       no=cpl_imagelist_get_size(list_object);
+<a name="l00607"></a>00607       lo_cut=(floor)(cfg->lo_reject*no+0.5);
+<a name="l00608"></a>00608       hi_cut=(floor)(cfg->hi_reject*no+0.5);
+<a name="l00609"></a>00609       <span class="keywordflow">if</span>(no > 0) {
+<a name="l00610"></a>00610          cknull(img_spct=cpl_imagelist_collapse_minmax_create(list_object,
+<a name="l00611"></a>00611                                                               lo_cut,hi_cut),
+<a name="l00612"></a>00612                           <span class="stringliteral">"sinfo_average_with_rejection failed"</span> );
+<a name="l00613"></a>00613       }
+<a name="l00614"></a>00614 
+<a name="l00615"></a>00615       sinfo_free_imagelist(&list_object);
+<a name="l00616"></a>00616       <span class="keywordflow">if</span>(no > 0) {
+<a name="l00617"></a>00617     check_nomsg(qclog_tbl = sinfo_qclog_init());
+<a name="l00618"></a>00618 
+<a name="l00619"></a>00619         ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,<span class="stringliteral">"QC CONVFCT"</span>,cleanfactor,
+<a name="l00620"></a>00620                                          <span class="stringliteral">"Conversion factor"</span>,<span class="stringliteral">"%g"</span>));
+<a name="l00621"></a>00621 
+<a name="l00622"></a>00622         ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,<span class="stringliteral">"QC CHECK3"</span>,check3,
+<a name="l00623"></a>00623                                       <span class="stringliteral">"Check evaluation box"</span>,<span class="stringliteral">"%d"</span>));
+<a name="l00624"></a>00624 
+<a name="l00625"></a>00625 
+<a name="l00626"></a>00626         ck0(sinfo_pro_save_ima(img_spct,ref_set,sof,cfg->outName,
+<a name="l00627"></a>00627                     PRO_STD_STAR_SPECTRUM,qclog_tbl,
+<a name="l00628"></a>00628                  plugin_id,config),
+<a name="l00629"></a>00629         <span class="stringliteral">"cannot dump ima %s"</span>, cfg->outName);
+<a name="l00630"></a>00630 
+<a name="l00631"></a>00631         sinfo_new_set_wcs_spectrum(img_spct,cfg->outName,cenLambda,disp,cenpix);
+<a name="l00632"></a>00632         sinfo_free_table(&qclog_tbl);
+<a name="l00633"></a>00633       }
+<a name="l00634"></a>00634       <span class="comment">/*#---free memory---*/</span>
+<a name="l00635"></a>00635       <span class="keywordflow">if</span>(factor != NULL) sinfo_new_destroy_array(&factor);
+<a name="l00636"></a>00636       sinfo_free_image(&img_spct);
+<a name="l00637"></a>00637       sinfo_stdstar_free(&cfg);
+<a name="l00638"></a>00638       sinfo_free_frameset(&raw);
+<a name="l00639"></a>00639 
+<a name="l00640"></a>00640       <span class="keywordflow">return</span> 0;
+<a name="l00641"></a>00641 
+<a name="l00642"></a>00642  cleanup:
+<a name="l00643"></a>00643       sinfo_free_table(&tbl_spectrum);
+<a name="l00644"></a>00644       sinfo_free_table(&qclog_tbl);
+<a name="l00645"></a>00645       sinfo_free_imagelist(&list_object);
+<a name="l00646"></a>00646       <span class="keywordflow">if</span>(spectrum != NULL) sinfo_free_image_array(&spectrum,cfg->nframes);
+<a name="l00647"></a>00647       sinfo_free_image(&std_med_ima);
+<a name="l00648"></a>00648       sinfo_free_image(&std_med_dup);
+<a name="l00649"></a>00649       sinfo_free_imagelist(&cube);
+<a name="l00650"></a>00650       sinfo_free_propertylist(&plist) ;
+<a name="l00651"></a>00651       <span class="keywordflow">if</span>(factor != NULL) sinfo_new_destroy_array(&factor);
+<a name="l00652"></a>00652       sinfo_free_image(&img_spct);
+<a name="l00653"></a>00653       sinfo_stdstar_free (&cfg);
+<a name="l00654"></a>00654       sinfo_free_frameset(&raw);
+<a name="l00655"></a>00655     <span class="keywordflow">return</span> -1;
+<a name="l00656"></a>00656 
+<a name="l00657"></a>00657 }
+<a name="l00658"></a>00658 
+<a name="l00659"></a>00659 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__new__stdstar_8h_source.html b/html/sinfo__new__stdstar_8h_source.html
new file mode 100644
index 0000000..717e651
--- /dev/null
+++ b/html/sinfo__new__stdstar_8h_source.html
@@ -0,0 +1,84 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_new_stdstar.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_new_stdstar.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#ifndef SINFO_NEW_STDSTAR_H</span>
+<a name="l00002"></a>00002 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_NEW_STDSTAR_H</span>
+<a name="l00003"></a>00003 <span class="preprocessor"></span><span class="comment">/*</span>
+<a name="l00004"></a>00004 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00005"></a>00005 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00006"></a>00006 <span class="comment"> *</span>
+<a name="l00007"></a>00007 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00008"></a>00008 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00009"></a>00009 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00010"></a>00010 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00011"></a>00011 <span class="comment"> *</span>
+<a name="l00012"></a>00012 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00013"></a>00013 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00014"></a>00014 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00015"></a>00015 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00016"></a>00016 <span class="comment"> *</span>
+<a name="l00017"></a>00017 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00018"></a>00018 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00019"></a>00019 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00020"></a>00020 <span class="comment"> */</span>
+<a name="l00021"></a>00021 <span class="comment">/*******************************************************************************</span>
+<a name="l00022"></a>00022 <span class="comment">* E.S.O. - VLT project</span>
+<a name="l00023"></a>00023 <span class="comment">*</span>
+<a name="l00024"></a>00024 <span class="comment">* "@(#) $Id: sinfo_new_stdstar.h,v 1.11 2007/09/21 14:13:43 amodigli Exp $"</span>
+<a name="l00025"></a>00025 <span class="comment">*</span>
+<a name="l00026"></a>00026 <span class="comment">* who       when      what</span>
+<a name="l00027"></a>00027 <span class="comment">* --------  --------  ----------------------------------------------</span>
+<a name="l00028"></a>00028 <span class="comment">* schreib  06/05/03  created</span>
+<a name="l00029"></a>00029 <span class="comment">*/</span>
+<a name="l00030"></a>00030 
+<a name="l00031"></a>00031 <span class="comment">/************************************************************************</span>
+<a name="l00032"></a>00032 <span class="comment"> * sinfo_new_stdstar.h</span>
+<a name="l00033"></a>00033 <span class="comment"> * routines to create a data cube</span>
+<a name="l00034"></a>00034 <span class="comment"> *----------------------------------------------------------------------</span>
+<a name="l00035"></a>00035 <span class="comment"> */</span>
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="comment">/*</span>
+<a name="l00038"></a>00038 <span class="comment"> * header files</span>
+<a name="l00039"></a>00039 <span class="comment"> */</span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include <cpl.h></span>  
+<a name="l00041"></a>00041 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include <sinfo_standstar_cfg.h></span>
+<a name="l00043"></a>00043 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00044"></a>00044 <span class="comment"> *                        Function ANSI C prototypes</span>
+<a name="l00045"></a>00045 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00046"></a>00046 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00047"></a>00047 <span class="comment">   Function     :       sinfo_new_stdstar()</span>
+<a name="l00048"></a>00048 <span class="comment">   In           :       ini_file: file name of according .ini file</span>
+<a name="l00049"></a>00049 <span class="comment">   Out          :       integer (0 if it worked, -1 if it doesn't) </span>
+<a name="l00050"></a>00050 <span class="comment">   Description  :    this routine does the optimal extraction of a spectrum </span>
+<a name="l00051"></a>00051 <span class="comment">                        of an already reduced data cube of a standard star </span>
+<a name="l00052"></a>00052 <span class="comment">                        observation. Additionally, a conversion factor from </span>
+<a name="l00053"></a>00053 <span class="comment">                        mag to counts/sec can be determined if the magnitude </span>
+<a name="l00054"></a>00054 <span class="comment">                        of the standard star is known. </span>
+<a name="l00055"></a>00055 <span class="comment">                        This is done for a number of jittered data cubes and </span>
+<a name="l00056"></a>00056 <span class="comment">                        the results are averaged by rejecting the extreme </span>
+<a name="l00057"></a>00057 <span class="comment">                        values</span>
+<a name="l00058"></a>00058 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00059"></a>00059 <span class="keywordtype">int</span> 
+<a name="l00060"></a>00060 sinfo_new_stdstar (<span class="keyword">const</span> <span class="keywordtype">char</span>* plugin_id,
+<a name="l00061"></a>00061                    cpl_parameterlist* config,
+<a name="l00062"></a>00062                    cpl_frameset* sof,cpl_frameset* ref_set) ;
+<a name="l00063"></a>00063 
+<a name="l00064"></a>00064 
+<a name="l00065"></a>00065 
+<a name="l00066"></a>00066 
+<a name="l00067"></a>00067 <span class="preprocessor">#endif </span>
+<a name="l00069"></a>00069 <span class="preprocessor"></span><span class="comment">/*--------------------------------------------------------------------------*/</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__new__wave__cal__slit2_8c_source.html b/html/sinfo__new__wave__cal__slit2_8c_source.html
new file mode 100644
index 0000000..35c9353
--- /dev/null
+++ b/html/sinfo__new__wave__cal__slit2_8c_source.html
@@ -0,0 +1,863 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_new_wave_cal_slit2.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_new_wave_cal_slit2.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment"> </span>
+<a name="l00021"></a>00021 <span class="comment">   File name    :       sinfo_new_wave_cal_slit2.c</span>
+<a name="l00022"></a>00022 <span class="comment">   Author       :    A. Modigliani</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on   :    Sep 17, 2003</span>
+<a name="l00024"></a>00024 <span class="comment">   Description  : </span>
+<a name="l00025"></a>00025 <span class="comment"></span>
+<a name="l00026"></a>00026 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span><span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00032"></a>00032 <span class="comment">                                Includes</span>
+<a name="l00033"></a>00033 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00034"></a>00034 <span class="preprocessor">#include "sinfo_new_wave_cal_slit2.h"</span>
+<a name="l00035"></a>00035 <span class="preprocessor">#include "sinfo_pro_save.h"</span>
+<a name="l00036"></a>00036 <span class="preprocessor">#include "sinfo_pro_types.h"</span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include "sinfo_wavecal_ini_by_cpl.h"</span>
+<a name="l00038"></a>00038 <span class="preprocessor">#include "sinfo_wcal_functions.h"</span>
+<a name="l00039"></a>00039 <span class="preprocessor">#include "sinfo_absolute.h"</span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include "sinfo_wave_calibration.h"</span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include "sinfo_wavecal.h"</span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include "sinfo_globals.h"</span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include "sinfo_hidden.h"</span>
+<a name="l00044"></a>00044 
+<a name="l00045"></a>00045 <span class="preprocessor">#include "sinfo_utilities.h"</span>
+<a name="l00046"></a>00046 <span class="preprocessor">#include "sinfo_utils_wrappers.h"</span>
+<a name="l00047"></a>00047 <span class="preprocessor">#include "sinfo_error.h"</span>
+<a name="l00048"></a>00048 
+<a name="l00049"></a>00049 
+<a name="l00050"></a>00050 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00051"></a>00051 <span class="comment">                                Defines</span>
+<a name="l00052"></a>00052 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00053"></a>00053 
+<a name="l00054"></a>00054 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00055"></a>00055 <span class="comment">                             Function Definitions</span>
+<a name="l00056"></a>00056 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00057"></a>00057 <span class="keyword">static</span> cpl_error_code
+<a name="l00058"></a>00058 sinfo_image_resample(<span class="keyword">const</span> <span class="keywordtype">char</span>* plugin_id,
+<a name="l00059"></a>00059                      cpl_parameterlist* config,
+<a name="l00060"></a>00060                      cpl_frameset* sof,
+<a name="l00061"></a>00061                      cpl_frameset* ref_set);
+<a name="l00062"></a>00062 
+<a name="l00070"></a>00070 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00071"></a>00071 <span class="comment">   Function     :       sinfo_wave_cal_slit()</span>
+<a name="l00072"></a>00072 <span class="comment">   In           :       ini_file: file name of according .ini file</span>
+<a name="l00073"></a>00073 <span class="comment">   Out          :       integer (0 if it worked, -1 if it doesn't) </span>
+<a name="l00074"></a>00074 <span class="comment">   Job          :</span>
+<a name="l00075"></a>00075 <span class="comment"></span>
+<a name="l00076"></a>00076 <span class="comment"></span>
+<a name="l00077"></a>00077 <span class="comment">  Normal method:</span>
+<a name="l00078"></a>00078 <span class="comment"></span>
+<a name="l00079"></a>00079 <span class="comment">  does the wavelength calibration and the fitting of the slitlet sinfo_edge </span>
+<a name="l00080"></a>00080 <span class="comment">  positions (ASCII file 32 x 2 values) if wished</span>
+<a name="l00081"></a>00081 <span class="comment">  produces an array of the bcoefs and of the fit parameters if wished and a </span>
+<a name="l00082"></a>00082 <span class="comment">  wavelength calibration map input is an emission line frame and a line list</span>
+<a name="l00083"></a>00083 <span class="comment"></span>
+<a name="l00084"></a>00084 <span class="comment"></span>
+<a name="l00085"></a>00085 <span class="comment">  o searching for lines by cross sinfo_correlation with a line list</span>
+<a name="l00086"></a>00086 <span class="comment">  o Gaussian fitting of emission lines in each column->positions of the lines-></span>
+<a name="l00087"></a>00087 <span class="comment">    resulting fit parameters can be stored in an ASCII file</span>
+<a name="l00088"></a>00088 <span class="comment">  o Fitting of a polynomial to the line positions for each column</span>
+<a name="l00089"></a>00089 <span class="comment">  o Smoothing: fitting of each polynomial coefficient by another polynomial</span>
+<a name="l00090"></a>00090 <span class="comment">    across the whole frame -> resulting polynomial coefficients can be stored </span>
+<a name="l00091"></a>00091 <span class="comment">    in an ASCII file.</span>
+<a name="l00092"></a>00092 <span class="comment">  o Wavelength calibration map (micron value for each frame pixel) can be</span>
+<a name="l00093"></a>00093 <span class="comment">    produced by using these coefficients and a cross sinfo_correlation to the</span>
+<a name="l00094"></a>00094 <span class="comment">    original frame</span>
+<a name="l00095"></a>00095 <span class="comment"></span>
+<a name="l00096"></a>00096 <span class="comment">  o The slitlet sinfo_edge positions can be fitted:</span>
+<a name="l00097"></a>00097 <span class="comment">    1) Automatically (not really stable) or by using guess sinfo_edge positions</span>
+<a name="l00098"></a>00098 <span class="comment">    2) By using a Boltzmann or a linear slope function</span>
+<a name="l00099"></a>00099 <span class="comment"></span>
+<a name="l00100"></a>00100 <span class="comment">  Slit method:</span>
+<a name="l00101"></a>00101 <span class="comment"></span>
+<a name="l00102"></a>00102 <span class="comment">  does the wavelength calibration and the fitting of the slitlet sinfo_edge </span>
+<a name="l00103"></a>00103 <span class="comment">  positions (ASCII file 32 x 2 values) if wished produces a list of the fit </span>
+<a name="l00104"></a>00104 <span class="comment">  parameters and of the smoothed coefficients if wished and a wavelength </span>
+<a name="l00105"></a>00105 <span class="comment">  calibration map input is an emission line frame and a line list</span>
+<a name="l00106"></a>00106 <span class="comment"></span>
+<a name="l00107"></a>00107 <span class="comment">  o Does the same as other method but smoothes the found polynomial </span>
+<a name="l00108"></a>00108 <span class="comment">    coefficients within each slitlet and not over the whole frame.</span>
+<a name="l00109"></a>00109 <span class="comment"></span>
+<a name="l00110"></a>00110 <span class="comment">  o Produces always a wavelength calibration map and does not crosscorrelate.</span>
+<a name="l00111"></a>00111 <span class="comment"></span>
+<a name="l00112"></a>00112 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00113"></a>00113 
+<a name="l00114"></a>00114 
+<a name="l00115"></a>00115 <span class="keywordtype">int</span> 
+<a name="l00116"></a>00116 sinfo_new_wave_cal_slit2(<span class="keyword">const</span> <span class="keywordtype">char</span>* plugin_id,
+<a name="l00117"></a>00117                         cpl_parameterlist* config, 
+<a name="l00118"></a>00118                         cpl_frameset* sof,cpl_frameset* ref_set)
+<a name="l00119"></a>00119 {
+<a name="l00120"></a>00120   wave_config * cfg =NULL;
+<a name="l00121"></a>00121   <span class="keywordtype">char</span> col_name[MAX_NAME_SIZE];
+<a name="l00122"></a>00122   <span class="keywordtype">char</span> tbl_name[MAX_NAME_SIZE];
+<a name="l00123"></a>00123   <span class="keywordtype">char</span> tbl_fitpar_name[MAX_NAME_SIZE];
+<a name="l00124"></a>00124   <span class="keywordtype">char</span> tbl_line_list_name[MAX_NAME_SIZE];
+<a name="l00125"></a>00125   <span class="keywordtype">char</span> tbl_slitpos_guess_name[MAX_NAME_SIZE];
+<a name="l00126"></a>00126   <span class="keywordtype">char</span> key_name[MAX_NAME_SIZE];
+<a name="l00127"></a>00127   <span class="keywordtype">char</span> col[MAX_NAME_SIZE];
+<a name="l00128"></a>00128   <span class="keywordtype">int</span> check = 0;
+<a name="l00129"></a>00129   <span class="keywordtype">int</span> lx = 0;
+<a name="l00130"></a>00130   <span class="keywordtype">int</span> ly = 0;
+<a name="l00131"></a>00131   <span class="keywordtype">int</span> n_lines=0;
+<a name="l00132"></a>00132   <span class="keywordtype">int</span> i = 0;
+<a name="l00133"></a>00133   <span class="keywordtype">int</span> j = 0;
+<a name="l00134"></a>00134   <span class="keywordtype">int</span> n = 0;
+<a name="l00135"></a>00135   <span class="keywordtype">int</span> readsum=0;
+<a name="l00136"></a>00136   <span class="keywordtype">int</span> sum=0;
+<a name="l00137"></a>00137   <span class="keywordtype">int</span> fit=0;
+<a name="l00138"></a>00138   <span class="keywordtype">int</span> sw=0;
+<a name="l00139"></a>00139  
+<a name="l00140"></a>00140   <span class="keywordtype">int</span>* status=NULL;
+<a name="l00141"></a>00141   <span class="keywordtype">int</span>* n_found_lines=NULL;
+<a name="l00142"></a>00142   <span class="keywordtype">int</span>* sum_pointer=NULL;
+<a name="l00143"></a>00143   <span class="keywordtype">int</span>** row_clean=NULL;
+<a name="l00144"></a>00144 
+<a name="l00145"></a>00145   <span class="keywordtype">float</span> a=0;
+<a name="l00146"></a>00146   <span class="keywordtype">float</span> shift=0;
+<a name="l00147"></a>00147   <span class="keywordtype">float</span> val_x=0;
+<a name="l00148"></a>00148   <span class="keywordtype">float</span> val_y=0;
+<a name="l00149"></a>00149 
+<a name="l00150"></a>00150   <span class="keywordtype">float</span>* wave=NULL;
+<a name="l00151"></a>00151   <span class="keywordtype">float</span>* intens=NULL;
+<a name="l00152"></a>00152 
+<a name="l00153"></a>00153   <span class="keywordtype">float</span>** acoefs=NULL;
+<a name="l00154"></a>00154   <span class="keywordtype">float</span>** wavelength_clean=NULL;
+<a name="l00155"></a>00155   <span class="keywordtype">float</span>** sinfo_slit_pos=NULL;
+<a name="l00156"></a>00156 
+<a name="l00157"></a>00157   <span class="keywordtype">double</span> fwhm_med=0;
+<a name="l00158"></a>00158   <span class="keywordtype">double</span> fwhm_avg=0;
+<a name="l00159"></a>00159   <span class="keywordtype">double</span> coef_med=0;
+<a name="l00160"></a>00160   <span class="keywordtype">double</span> coef_avg=0;
+<a name="l00161"></a>00161  
+<a name="l00162"></a>00162   cpl_image * im=NULL ;
+<a name="l00163"></a>00163 
+<a name="l00164"></a>00164   FitParams** par=NULL;
+<a name="l00165"></a>00165 
+<a name="l00166"></a>00166   cpl_table* tbl_wcal=NULL;
+<a name="l00167"></a>00167   cpl_table* tbl_spos=NULL;
+<a name="l00168"></a>00168   cpl_table* tbl_fitpar = NULL;
+<a name="l00169"></a>00169   cpl_table* tbl_line_list = NULL;
+<a name="l00170"></a>00170   cpl_table* tbl_slitpos_guess=NULL;
+<a name="l00171"></a>00171   cpl_table * tbl_fp =NULL;
+<a name="l00172"></a>00172   cpl_table* qclog_tbl=NULL;
+<a name="l00173"></a>00173 
+<a name="l00174"></a>00174   cpl_image* map_img=NULL;
+<a name="l00175"></a>00175 
+<a name="l00176"></a>00176   cpl_frameset* raw=NULL;
+<a name="l00177"></a>00177   cpl_parameter* p=NULL;
+<a name="l00178"></a>00178 
+<a name="l00179"></a>00179   qc_wcal* qc=sinfo_qc_wcal_new();
+<a name="l00180"></a>00180   <span class="keywordtype">int</span> pdensity=0;
+<a name="l00181"></a>00181 
+<a name="l00182"></a>00182   <span class="comment">/*   -----------------------------------------------------------------</span>
+<a name="l00183"></a>00183 <span class="comment">       1) parse the file names and parameters to the ns_config data </span>
+<a name="l00184"></a>00184 <span class="comment">          structure cfg</span>
+<a name="l00185"></a>00185 <span class="comment">       -----------------------------------------------------------------</span>
+<a name="l00186"></a>00186 <span class="comment">  */</span>
+<a name="l00187"></a>00187 
+<a name="l00188"></a>00188   check_nomsg(p=cpl_parameterlist_find(config,<span class="stringliteral">"sinfoni.product.density"</span>));
+<a name="l00189"></a>00189   check_nomsg(pdensity=cpl_parameter_get_int(p));
+<a name="l00190"></a>00190 
+<a name="l00191"></a>00191 
+<a name="l00192"></a>00192   sinfo_msg(<span class="stringliteral">"Parsing cpl input"</span>);
+<a name="l00193"></a>00193   check_nomsg(raw=cpl_frameset_new());
+<a name="l00194"></a>00194   cknull(cfg = sinfo_parse_cpl_input_wave(config,sof,&raw),
+<a name="l00195"></a>00195      <span class="stringliteral">"could not parse cpl input!"</span>) ;
+<a name="l00196"></a>00196  
+<a name="l00197"></a>00197   check_nomsg(p = cpl_parameterlist_find(config,
+<a name="l00198"></a>00198                                          <span class="stringliteral">"sinfoni.wavecal.slitpos_boostrap"</span>));
+<a name="l00199"></a>00199   check_nomsg(sw=cpl_parameter_get_bool(p));
+<a name="l00200"></a>00200 
+<a name="l00201"></a>00201   <span class="keywordflow">if</span>(sw==1) {
+<a name="l00202"></a>00202      cfg->nslitlets=32;
+<a name="l00203"></a>00203      cfg->calibIndicator=1;
+<a name="l00204"></a>00204      cfg->wavemapInd=0;
+<a name="l00205"></a>00205      cfg->slitposIndicator=1;
+<a name="l00206"></a>00206      sinfo_msg(<span class="stringliteral">"***********************************"</span>);
+<a name="l00207"></a>00207      sinfo_msg(<span class="stringliteral">"parameter setting for %s"</span>,PRO_WAVE_SLITPOS_STACKED);
+<a name="l00208"></a>00208      sinfo_msg(<span class="stringliteral">"***********************************"</span>);
+<a name="l00209"></a>00209   }
+<a name="l00210"></a>00210 
+<a name="l00211"></a>00211   <span class="keywordflow">if</span>(sinfo_is_fits_file(cfg->inFrame) != 1) {
+<a name="l00212"></a>00212     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Input file cfg->inFrame %s is not FITS"</span>,cfg->inFrame);
+<a name="l00213"></a>00213     <span class="keywordflow">goto</span> cleanup;
+<a name="l00214"></a>00214   }
+<a name="l00215"></a>00215 
+<a name="l00216"></a>00216 
+<a name="l00217"></a>00217   <span class="keywordflow">if</span> (cfg->slitposIndicator == 1 && cfg->estimateIndicator == 1) {
+<a name="l00218"></a>00218     <span class="keywordflow">if</span> (sinfo_is_fits_file(cfg->slitposGuessName) != 1) {
+<a name="l00219"></a>00219       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"slitlet position guess list not given!"</span>);
+<a name="l00220"></a>00220       <span class="keywordflow">goto</span> cleanup;
+<a name="l00221"></a>00221     }
+<a name="l00222"></a>00222   }
+<a name="l00223"></a>00223 
+<a name="l00224"></a>00224   <span class="keywordflow">if</span> (cfg->calibIndicator == 0 && cfg->wavemapInd == 1) {
+<a name="l00225"></a>00225     <span class="keywordflow">if</span> (sinfo_is_fits_file(cfg->coeffsName) != 1) {
+<a name="l00226"></a>00226       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"coefficients list not given!"</span>);
+<a name="l00227"></a>00227       <span class="keywordflow">goto</span> cleanup;
+<a name="l00228"></a>00228     }
+<a name="l00229"></a>00229   }
+<a name="l00230"></a>00230 
+<a name="l00231"></a>00231   <span class="keywordflow">if</span> (cfg->slitposIndicator == 1) {
+<a name="l00232"></a>00232     <span class="keywordflow">if</span> (cfg->calibIndicator != 1 && cfg->estimateIndicator != 1) {
+<a name="l00233"></a>00233       <span class="keywordflow">if</span> (sinfo_is_fits_file(cfg->paramsList) != 1) {
+<a name="l00234"></a>00234     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"parameter list not given!"</span>);
+<a name="l00235"></a>00235     <span class="keywordflow">goto</span> cleanup;
+<a name="l00236"></a>00236       }
+<a name="l00237"></a>00237     }
+<a name="l00238"></a>00238   }
+<a name="l00239"></a>00239  
+<a name="l00240"></a>00240   <span class="comment">/*---load the emission line frame---*/</span>
+<a name="l00241"></a>00241   check(im = cpl_image_load(cfg->inFrame,CPL_TYPE_FLOAT,0,0)
+<a name="l00242"></a>00242         ,<span class="stringliteral">"could not load image"</span>);
+<a name="l00243"></a>00243   lx = cpl_image_get_size_x(im);
+<a name="l00244"></a>00244   ly = cpl_image_get_size_y(im);
+<a name="l00245"></a>00245 
+<a name="l00246"></a>00246   <span class="keywordflow">if</span> (cfg->calibIndicator == 1 || cfg->wavemapInd == 1) {
+<a name="l00247"></a>00247     <span class="comment">/*---open the line list and read the number of lines---*/</span>
+<a name="l00248"></a>00248     strcpy(tbl_line_list_name,cfg->lineList);
+<a name="l00249"></a>00249     check_nomsg(tbl_line_list = cpl_table_load(tbl_line_list_name,1,0));
+<a name="l00250"></a>00250     check_nomsg(n = cpl_table_get_nrow(tbl_line_list));
+<a name="l00251"></a>00251     n_lines = n;
+<a name="l00252"></a>00252 
+<a name="l00253"></a>00253     check_nomsg(wave   = cpl_table_get_data_float(tbl_line_list,<span class="stringliteral">"wave"</span>));
+<a name="l00254"></a>00254     check_nomsg(intens = cpl_table_get_data_float(tbl_line_list,<span class="stringliteral">"int"</span>));
+<a name="l00255"></a>00255   }
+<a name="l00256"></a>00256 
+<a name="l00257"></a>00257   <span class="comment">/*</span>
+<a name="l00258"></a>00258 <span class="comment">  ----------------------------------------------------------------------</span>
+<a name="l00259"></a>00259 <span class="comment">  ---------------------------FINDLINES----------------------------------</span>
+<a name="l00260"></a>00260 <span class="comment">  ----------------------------------------------------------------------</span>
+<a name="l00261"></a>00261 <span class="comment">  */</span>
+<a name="l00262"></a>00262 
+<a name="l00263"></a>00263   <span class="comment">/*if not yet done:</span>
+<a name="l00264"></a>00264 <span class="comment">    do the wavelength calibration, that means: </span>
+<a name="l00265"></a>00265 <span class="comment">    find the dispersion relation and parameterize its coefficients</span>
+<a name="l00266"></a>00266 <span class="comment">  */</span>
+<a name="l00267"></a>00267   <span class="comment">/*</span>
+<a name="l00268"></a>00268 <span class="comment">  sinfo_msg("guessBeginWave=%g",cfg->guessBeginWavelength);</span>
+<a name="l00269"></a>00269 <span class="comment">  sinfo_msg("guessDisp1=%g",cfg->guessDispersion1);</span>
+<a name="l00270"></a>00270 <span class="comment">  sinfo_msg("guessDisp2=%g",cfg->guessDispersion2);</span>
+<a name="l00271"></a>00271 <span class="comment">  */</span>
+<a name="l00272"></a>00272   <span class="keywordflow">if</span> (cfg->calibIndicator == 1 && cfg->wavemapInd == 0) {
+<a name="l00273"></a>00273     sinfo_msg(<span class="stringliteral">"Findlines"</span>);
+<a name="l00274"></a>00274     acoefs  = sinfo_new_2Dfloatarray(cfg->nrDispCoefficients, lx);
+<a name="l00275"></a>00275 
+<a name="l00276"></a>00276     <span class="comment">/*allocate memory*/</span>
+<a name="l00277"></a>00277     n_found_lines    = sinfo_new_intarray(lx); 
+<a name="l00278"></a>00278     row_clean        = sinfo_new_2Dintarray(lx, n_lines);
+<a name="l00279"></a>00279     wavelength_clean = sinfo_new_2Dfloatarray(lx, n_lines);
+<a name="l00280"></a>00280     sum_pointer      = sinfo_new_intarray(1) ;
+<a name="l00281"></a>00281 
+<a name="l00282"></a>00282     <span class="comment">/*find the emission lines in each image column*/</span>
+<a name="l00283"></a>00283     sinfo_new_intarray_set_value(sum_pointer, 0, 0);
+<a name="l00284"></a>00284  
+<a name="l00285"></a>00285     ck0(check = sinfo_new_find_lines(im, 
+<a name="l00286"></a>00286                                 wave, 
+<a name="l00287"></a>00287                                 intens, 
+<a name="l00288"></a>00288                                 n_lines, 
+<a name="l00289"></a>00289                                 row_clean, 
+<a name="l00290"></a>00290                                 wavelength_clean, 
+<a name="l00291"></a>00291                                 cfg->guessBeginWavelength, 
+<a name="l00292"></a>00292                         cfg->guessDispersion1, 
+<a name="l00293"></a>00293                                 cfg->guessDispersion2,
+<a name="l00294"></a>00294                                 cfg->mindiff, 
+<a name="l00295"></a>00295                                 cfg->halfWidth, 
+<a name="l00296"></a>00296                                 n_found_lines, 
+<a name="l00297"></a>00297                                 cfg->sigma, 
+<a name="l00298"></a>00298                                 sum_pointer),
+<a name="l00299"></a>00299     <span class="stringliteral">"sinfo_findLines failed!"</span>);
+<a name="l00300"></a>00300 
+<a name="l00301"></a>00301     <span class="comment">/*---------------------------------------------------------------------</span>
+<a name="l00302"></a>00302 <span class="comment">     *-----------------------WAVE_CALIB-------------------------------------</span>
+<a name="l00303"></a>00303 <span class="comment">     *---------------------------------------------------------------------</span>
+<a name="l00304"></a>00304 <span class="comment">    */</span>
+<a name="l00305"></a>00305     sinfo_msg(<span class="stringliteral">"Wave Calibration"</span>);
+<a name="l00306"></a>00306     sum = sinfo_new_intarray_get_value(sum_pointer,0);
+<a name="l00307"></a>00307     <span class="comment">/* allocate memory for the fit parameters */</span>
+<a name="l00308"></a>00308     cknull(par = sinfo_new_fit_params( sum ),
+<a name="l00309"></a>00309        <span class="stringliteral">"sinfo_newFitParams failed!"</span>);
+<a name="l00310"></a>00310 
+<a name="l00311"></a>00311   <span class="comment">/*</span>
+<a name="l00312"></a>00312 <span class="comment">   fit each line, make a polynomial fit and fit the resulting fit </span>
+<a name="l00313"></a>00313 <span class="comment">   coefficients across the columns of the slitlet</span>
+<a name="l00314"></a>00314 <span class="comment">   */</span>
+<a name="l00315"></a>00315    cknull(map_img = sinfo_new_wave_cal(im, 
+<a name="l00316"></a>00316                   par, 
+<a name="l00317"></a>00317                   acoefs,
+<a name="l00318"></a>00318                   cfg->nslitlets, 
+<a name="l00319"></a>00319                   row_clean,
+<a name="l00320"></a>00320                   wavelength_clean,
+<a name="l00321"></a>00321                   n_found_lines,
+<a name="l00322"></a>00322                   cfg->guessDispersion1,
+<a name="l00323"></a>00323                   cfg->halfWidth,
+<a name="l00324"></a>00324                   cfg->minAmplitude,
+<a name="l00325"></a>00325                   cfg->maxResidual,
+<a name="l00326"></a>00326                   cfg->fwhm,
+<a name="l00327"></a>00327                   cfg->nrDispCoefficients, 
+<a name="l00328"></a>00328                   cfg->nrCoefCoefficients,
+<a name="l00329"></a>00329                   cfg->sigmaFactor,
+<a name="l00330"></a>00330                   cfg->pixeldist,
+<a name="l00331"></a>00331                   cfg->pixel_tolerance),
+<a name="l00332"></a>00332       <span class="stringliteral">"sinfo_wave_cal failed!"</span>);
+<a name="l00333"></a>00333 
+<a name="l00334"></a>00334    sinfo_msg(<span class="stringliteral">"Check line positions"</span>);
+<a name="l00335"></a>00335 
+<a name="l00336"></a>00336    shift=sinfo_new_check_line_positions(im,acoefs,cfg->nrDispCoefficients,
+<a name="l00337"></a>00337                     cfg->guessDispersion1,par);
+<a name="l00338"></a>00338    <span class="keywordflow">if</span> (FLAG == shift){ 
+<a name="l00339"></a>00339       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"checkForLinePositions failed!\n"</span>);
+<a name="l00340"></a>00340    }
+<a name="l00341"></a>00341 
+<a name="l00342"></a>00342 
+<a name="l00343"></a>00343    sinfo_det_ncounts(raw, cfg->qc_thresh_max, qc);
+<a name="l00344"></a>00344 
+<a name="l00345"></a>00345    cknull_nomsg(qclog_tbl = sinfo_qclog_init());
+<a name="l00346"></a>00346    ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,<span class="stringliteral">"QC WAVE ALL"</span>,n_lines,
+<a name="l00347"></a>00347                                  <span class="stringliteral">"Number of found lines"</span>,<span class="stringliteral">"%d"</span>));
+<a name="l00348"></a>00348    ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,<span class="stringliteral">"QC WAVE NPIXSAT"</span>,qc->nsat,
+<a name="l00349"></a>00349                                  <span class="stringliteral">"Number of saturated pixels"</span>,<span class="stringliteral">"%d"</span>));
+<a name="l00350"></a>00350    ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,<span class="stringliteral">"QC WAVE MAXFLUX"</span>,qc->max_di,
+<a name="l00351"></a>00351                                  <span class="stringliteral">"Max int off-lamp subtracted frm"</span>,<span class="stringliteral">"%g"</span>));
+<a name="l00352"></a>00352    ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,<span class="stringliteral">"QC WAVE POSERR"</span>,shift,
+<a name="l00353"></a>00353                                  <span class="stringliteral">"Overall positioning error in mum"</span>,<span class="stringliteral">"%g"</span>));
+<a name="l00354"></a>00354 
+<a name="l00355"></a>00355    ck0(sinfo_pro_save_ima(map_img,ref_set,sof,cfg->outName,
+<a name="l00356"></a>00356               PRO_WAVE_MAP,qclog_tbl,plugin_id,config),
+<a name="l00357"></a>00357        <span class="stringliteral">"cannot save ima %s"</span>, cfg->outName);
+<a name="l00358"></a>00358 
+<a name="l00359"></a>00359    sinfo_free_table(&qclog_tbl);
+<a name="l00360"></a>00360    sinfo_free_image(&map_img);
+<a name="l00361"></a>00361 
+<a name="l00362"></a>00362    <span class="comment">/*</span>
+<a name="l00363"></a>00363 <span class="comment">    #store the resulting polynomial fit coefficients in an </span>
+<a name="l00364"></a>00364 <span class="comment">     ASCII file if wished</span>
+<a name="l00365"></a>00365 <span class="comment">   */</span>
+<a name="l00366"></a>00366 
+<a name="l00367"></a>00367    <span class="keywordflow">if</span> (cfg->writeCoeffsInd == 1) {
+<a name="l00368"></a>00368      check_nomsg(tbl_wcal = cpl_table_new(lx));
+<a name="l00369"></a>00369      <span class="keywordflow">for</span> (i=0; i< cfg->nrDispCoefficients; i++) {
+<a name="l00370"></a>00370        snprintf(col_name,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%d"</span>,<span class="stringliteral">"coeff"</span>,i);
+<a name="l00371"></a>00371        check_nomsg(cpl_table_new_column(tbl_wcal,col_name, CPL_TYPE_DOUBLE));
+<a name="l00372"></a>00372      }
+<a name="l00373"></a>00373 
+<a name="l00374"></a>00374      cknull_nomsg(qclog_tbl = sinfo_qclog_init());
+<a name="l00375"></a>00375      ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,<span class="stringliteral">"QC WAVE ALL"</span>,n_lines,
+<a name="l00376"></a>00376                                    <span class="stringliteral">"Number found lines"</span>,<span class="stringliteral">"%d"</span>));
+<a name="l00377"></a>00377 
+<a name="l00378"></a>00378      <span class="keywordflow">for</span> (j=0; j< lx; j++) {
+<a name="l00379"></a>00379        <span class="keywordflow">for</span> (i=0; i< cfg->nrDispCoefficients; i++) {
+<a name="l00380"></a>00380      snprintf(col_name,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%d"</span>,<span class="stringliteral">"coeff"</span>,i);
+<a name="l00381"></a>00381      a = sinfo_new_array2D_get_value(acoefs, i, j);
+<a name="l00382"></a>00382      <span class="comment">/* fprintf(acoefs_file, "%15.13g ", a) ; */</span>
+<a name="l00383"></a>00383      cpl_table_set_double(tbl_wcal,col_name,j,a);
+<a name="l00384"></a>00384        }
+<a name="l00385"></a>00385      }
+<a name="l00386"></a>00386      <span class="keywordflow">for</span> (i=0; i< cfg->nrDispCoefficients; i++) {
+<a name="l00387"></a>00387        snprintf(col_name,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%d"</span>,<span class="stringliteral">"coeff"</span>,i);
+<a name="l00388"></a>00388        check_nomsg(coef_avg=cpl_table_get_column_mean(tbl_wcal,col_name));
+<a name="l00389"></a>00389        check_nomsg(coef_med=cpl_table_get_column_median(tbl_wcal,col_name));
+<a name="l00390"></a>00390 
+<a name="l00391"></a>00391        snprintf(key_name,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%d%s"</span>,<span class="stringliteral">"QC COEF"</span>,i,<span class="stringliteral">" AVG"</span>);
+<a name="l00392"></a>00392        ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,key_name,coef_avg,
+<a name="l00393"></a>00393                                         <span class="stringliteral">"Average wavecal Coef"</span>,<span class="stringliteral">"%g"</span>));
+<a name="l00394"></a>00394 
+<a name="l00395"></a>00395        snprintf(key_name,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%d%s"</span>,<span class="stringliteral">"QC COEF"</span>,i,<span class="stringliteral">" MED"</span>);
+<a name="l00396"></a>00396        ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,key_name,coef_med,
+<a name="l00397"></a>00397                                         <span class="stringliteral">"Median wavecal Coef"</span>,<span class="stringliteral">"%g"</span>));
+<a name="l00398"></a>00398 
+<a name="l00399"></a>00399      }
+<a name="l00400"></a>00400      <span class="keywordflow">if</span>(pdensity >1) {
+<a name="l00401"></a>00401      strcpy(tbl_name,cfg->coeffsName);
+<a name="l00402"></a>00402      ck0(sinfo_pro_save_tbl(tbl_wcal,ref_set,sof,tbl_name,
+<a name="l00403"></a>00403                 PRO_WAVE_COEF_SLIT,qclog_tbl,plugin_id,config),
+<a name="l00404"></a>00404      <span class="stringliteral">"cannot save tbl %s"</span>, tbl_name);
+<a name="l00405"></a>00405      sinfo_free_table(&tbl_wcal);
+<a name="l00406"></a>00406      sinfo_free_table(&qclog_tbl);
+<a name="l00407"></a>00407      }
+<a name="l00408"></a>00408 
+<a name="l00409"></a>00409    }
+<a name="l00410"></a>00410 
+<a name="l00411"></a>00411    <span class="comment">/*</span>
+<a name="l00412"></a>00412 <span class="comment">    #store the resulting Gaussian fit parameters in an ASCII file if wished</span>
+<a name="l00413"></a>00413 <span class="comment">   */</span>
+<a name="l00414"></a>00414    <span class="keywordflow">if</span> (cfg->writeParInd == 1) {
+<a name="l00415"></a>00415       sinfo_new_dump_fit_params_to_ascii(par,WAVECAL_FIT_PARAMS_OUT_FILEASCII);
+<a name="l00416"></a>00416  
+<a name="l00417"></a>00417       cknull(par,<span class="stringliteral">"no fit parameters available!"</span>) ;
+<a name="l00418"></a>00418       cknull(cfg->paramsList,<span class="stringliteral">"no filename available!"</span>) ;
+<a name="l00419"></a>00419       check_nomsg(tbl_fp = cpl_table_new(par[0] -> n_params));
+<a name="l00420"></a>00420       check_nomsg(cpl_table_new_column(tbl_fp,<span class="stringliteral">"n_params"</span>, CPL_TYPE_INT));
+<a name="l00421"></a>00421       check_nomsg(cpl_table_new_column(tbl_fp,<span class="stringliteral">"column"</span>, CPL_TYPE_INT));
+<a name="l00422"></a>00422       check_nomsg(cpl_table_new_column(tbl_fp,<span class="stringliteral">"line"</span>, CPL_TYPE_INT));
+<a name="l00423"></a>00423  
+<a name="l00424"></a>00424       <span class="keywordflow">for</span>(j=0;j<4;j++) {
+<a name="l00425"></a>00425          snprintf(col,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%d"</span>,<span class="stringliteral">"fpar"</span>,j);
+<a name="l00426"></a>00426          cpl_table_new_column(tbl_fp,col, CPL_TYPE_DOUBLE);
+<a name="l00427"></a>00427          snprintf(col,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%d"</span>,<span class="stringliteral">"dpar"</span>,j);
+<a name="l00428"></a>00428          cpl_table_new_column(tbl_fp,col, CPL_TYPE_DOUBLE);
+<a name="l00429"></a>00429       }
+<a name="l00430"></a>00430 
+<a name="l00431"></a>00431       cknull_nomsg(qclog_tbl = sinfo_qclog_init());
+<a name="l00432"></a>00432       ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,<span class="stringliteral">"QC NLINES"</span>,n_lines,
+<a name="l00433"></a>00433                                     <span class="stringliteral">"Number of found lines"</span>,<span class="stringliteral">"%d"</span>));
+<a name="l00434"></a>00434 
+<a name="l00435"></a>00435      <span class="keywordflow">for</span> ( i = 0 ; i < par[0] -> n_params ; i++ ) {
+<a name="l00436"></a>00436       
+<a name="l00437"></a>00437          check_nomsg(cpl_table_set_int(tbl_fp,<span class="stringliteral">"n_params"</span>,i,par[i]->n_params));
+<a name="l00438"></a>00438          check_nomsg(cpl_table_set_int(tbl_fp,<span class="stringliteral">"column"</span>,i,par[i]->column));
+<a name="l00439"></a>00439          check_nomsg(cpl_table_set_int(tbl_fp,<span class="stringliteral">"line"</span>,i,par[i]->line));
+<a name="l00440"></a>00440 
+<a name="l00441"></a>00441          <span class="keywordflow">for</span>(j=0;j<4;j++) {
+<a name="l00442"></a>00442        snprintf(col,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%d"</span>,<span class="stringliteral">"fpar"</span>,j);
+<a name="l00443"></a>00443        <span class="keywordflow">if</span>(isnan(par[i]->fit_par[j])) {
+<a name="l00444"></a>00444          cpl_table_set_invalid(tbl_fp,col,i);
+<a name="l00445"></a>00445        } <span class="keywordflow">else</span> {
+<a name="l00446"></a>00446          cpl_table_set_double(tbl_fp,col,i,par[i]->fit_par[j]);
+<a name="l00447"></a>00447        }
+<a name="l00448"></a>00448        snprintf(col,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%d"</span>,<span class="stringliteral">"dpar"</span>,j);
+<a name="l00449"></a>00449        <span class="keywordflow">if</span>(isnan(par[i]->derv_par[j])) {
+<a name="l00450"></a>00450          cpl_table_set_invalid(tbl_fp,col,i);
+<a name="l00451"></a>00451        } <span class="keywordflow">else</span> {
+<a name="l00452"></a>00452          cpl_table_set_double(tbl_fp,col,i,par[i]->derv_par[j]);
+<a name="l00453"></a>00453        }
+<a name="l00454"></a>00454      }
+<a name="l00455"></a>00455       }
+<a name="l00456"></a>00456 
+<a name="l00457"></a>00457       check_nomsg(fwhm_avg = cpl_table_get_column_mean(tbl_fp,<span class="stringliteral">"fpar1"</span>));
+<a name="l00458"></a>00458       check_nomsg(fwhm_med = cpl_table_get_column_median(tbl_fp,<span class="stringliteral">"fpar1"</span>));
+<a name="l00459"></a>00459       ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,<span class="stringliteral">"QC FWHM MED"</span>,fwhm_med,
+<a name="l00460"></a>00460                                        <span class="stringliteral">"Median FWHM of found lines"</span>,<span class="stringliteral">"%f"</span>));
+<a name="l00461"></a>00461       ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,<span class="stringliteral">"QC FWHM AVG"</span>,fwhm_avg,
+<a name="l00462"></a>00462                                        <span class="stringliteral">"Average FWHM of found lines"</span>,<span class="stringliteral">"%f"</span>));
+<a name="l00463"></a>00463 
+<a name="l00464"></a>00464       <span class="keywordflow">if</span>(pdensity > 1) {
+<a name="l00465"></a>00465       ck0(sinfo_pro_save_tbl(tbl_fp,ref_set,sof,cfg->paramsList,
+<a name="l00466"></a>00466                  PRO_WAVE_PAR_LIST,qclog_tbl,plugin_id,config),
+<a name="l00467"></a>00467       <span class="stringliteral">"cannot save tbl %s"</span>, cfg->paramsList);
+<a name="l00468"></a>00468       }
+<a name="l00469"></a>00469 
+<a name="l00470"></a>00470       sinfo_free_table(&qclog_tbl);
+<a name="l00471"></a>00471       sinfo_free_table(&tbl_fp) ;
+<a name="l00472"></a>00472 
+<a name="l00473"></a>00473    }
+<a name="l00474"></a>00474 
+<a name="l00475"></a>00475    <span class="comment">/* free memory */</span>
+<a name="l00476"></a>00476    sinfo_new_destroy_2Dfloatarray ( &wavelength_clean, lx );
+<a name="l00477"></a>00477    sinfo_new_destroy_2Dintarray (&row_clean, lx);
+<a name="l00478"></a>00478    sinfo_new_destroy_intarray(&n_found_lines );
+<a name="l00479"></a>00479    sinfo_new_destroy_intarray(&sum_pointer );
+<a name="l00480"></a>00480    sinfo_new_destroy_2Dfloatarray ( &acoefs, cfg->nrDispCoefficients );
+<a name="l00481"></a>00481    sinfo_free_table(&tbl_line_list);
+<a name="l00482"></a>00482 
+<a name="l00483"></a>00483    <span class="comment">/*----------------------------------------------------------------------</span>
+<a name="l00484"></a>00484 <span class="comment">    *-------------------WAVEMAP--------------------------------------------</span>
+<a name="l00485"></a>00485 <span class="comment">    *----------------------------------------------------------------------</span>
+<a name="l00486"></a>00486 <span class="comment">    */</span>
+<a name="l00487"></a>00487 
+<a name="l00488"></a>00488    <span class="comment">/*</span>
+<a name="l00489"></a>00489 <span class="comment">    #---now do the cross sinfo_correlation and produce a wavelength map---</span>
+<a name="l00490"></a>00490 <span class="comment">   */</span>
+<a name="l00491"></a>00491 
+<a name="l00492"></a>00492   } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (cfg->wavemapInd == 1 && cfg->calibIndicator == 0) { 
+<a name="l00493"></a>00493     sinfo_msg(<span class="stringliteral">"Wavemap"</span>);
+<a name="l00494"></a>00494     acoefs = sinfo_new_2Dfloatarray ( cfg->nrDispCoefficients, lx);
+<a name="l00495"></a>00495     <span class="comment">/* #read the parameterized dispersion relation */</span>
+<a name="l00496"></a>00496 
+<a name="l00497"></a>00497     strcpy(tbl_name,cfg->coeffsName);
+<a name="l00498"></a>00498     check_nomsg(tbl_wcal = cpl_table_load(tbl_name,1,0));
+<a name="l00499"></a>00499 
+<a name="l00500"></a>00500     <span class="keywordflow">for</span> (i =0; i < lx; i++) {
+<a name="l00501"></a>00501       <span class="keywordflow">for</span> (j = 0; j< cfg->nrDispCoefficients; j++) {
+<a name="l00502"></a>00502     snprintf(col_name,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%d"</span>,<span class="stringliteral">"coeff"</span>,j);
+<a name="l00503"></a>00503     acoefs[j][i]=cpl_table_get_double(tbl_wcal,col_name,i,status);
+<a name="l00504"></a>00504       }
+<a name="l00505"></a>00505     }
+<a name="l00506"></a>00506     sinfo_free_table(&tbl_wcal);
+<a name="l00507"></a>00507 
+<a name="l00508"></a>00508     cknull(map_img = sinfo_new_create_shifted_slit_wavemap2(im,
+<a name="l00509"></a>00509                            acoefs,
+<a name="l00510"></a>00510                            cfg->nrDispCoefficients,
+<a name="l00511"></a>00511                            wave,
+<a name="l00512"></a>00512                            intens,
+<a name="l00513"></a>00513                            n_lines,
+<a name="l00514"></a>00514                            cfg->magFactor,
+<a name="l00515"></a>00515                            cfg->guessDispersion1,
+<a name="l00516"></a>00516                            cfg->pixeldist ),
+<a name="l00517"></a>00517            <span class="stringliteral">"sinfo_createShiftedSlitWavemap2 failed!"</span>);
+<a name="l00518"></a>00518 
+<a name="l00519"></a>00519     par = sinfo_new_fit_params(15*n_lines);
+<a name="l00520"></a>00520     sinfo_msg(<span class="stringliteral">"Check shifts"</span>);
+<a name="l00521"></a>00521 
+<a name="l00522"></a>00522     shift = sinfo_new_check_correlated_line_positions ( im, acoefs, 
+<a name="l00523"></a>00523                          cfg->nrDispCoefficients, 
+<a name="l00524"></a>00524                          wave,
+<a name="l00525"></a>00525                          intens,
+<a name="l00526"></a>00526                          n_lines,
+<a name="l00527"></a>00527                          cfg->fwhm,
+<a name="l00528"></a>00528                          cfg->halfWidth,
+<a name="l00529"></a>00529                          cfg->minAmplitude,
+<a name="l00530"></a>00530                          cfg->guessDispersion1,
+<a name="l00531"></a>00531                          par );
+<a name="l00532"></a>00532 
+<a name="l00533"></a>00533     <span class="keywordflow">if</span> (FLAG == shift){
+<a name="l00534"></a>00534       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"sinfo_checkCorrelatedLinePositions failed!\n"</span>);
+<a name="l00535"></a>00535     }
+<a name="l00536"></a>00536 
+<a name="l00537"></a>00537     sinfo_det_ncounts(raw, cfg->qc_thresh_max,qc);
+<a name="l00538"></a>00538     cknull_nomsg(qclog_tbl = sinfo_qclog_init());
+<a name="l00539"></a>00539 
+<a name="l00540"></a>00540     ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,<span class="stringliteral">"QC NLINES"</span>,n_lines,
+<a name="l00541"></a>00541                                   <span class="stringliteral">"Number of found lines"</span>,<span class="stringliteral">"%d"</span>));
+<a name="l00542"></a>00542 
+<a name="l00543"></a>00543     check_nomsg(fwhm_avg = cpl_table_get_column_mean(tbl_fp,<span class="stringliteral">"fpar1"</span>));
+<a name="l00544"></a>00544     check_nomsg(fwhm_med = cpl_table_get_column_median(tbl_fp,<span class="stringliteral">"fpar1"</span>));
+<a name="l00545"></a>00545 
+<a name="l00546"></a>00546     ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,<span class="stringliteral">"QC FWHM MED"</span>,fwhm_med,
+<a name="l00547"></a>00547                                   <span class="stringliteral">"Median FWHM of found lines"</span>,<span class="stringliteral">"%f"</span>));
+<a name="l00548"></a>00548     ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,<span class="stringliteral">"QC FWHM AVG"</span>,fwhm_avg,
+<a name="l00549"></a>00549                                   <span class="stringliteral">"Average FWHM of found lines"</span>,<span class="stringliteral">"%f"</span>));
+<a name="l00550"></a>00550 
+<a name="l00551"></a>00551     ck0(sinfo_pro_save_ima(map_img,ref_set,sof,cfg->outName,
+<a name="l00552"></a>00552                PRO_WAVE_MAP,qclog_tbl,plugin_id,config),
+<a name="l00553"></a>00553     <span class="stringliteral">"cannot save ima %s"</span>, cfg->outName);
+<a name="l00554"></a>00554 
+<a name="l00555"></a>00555     sinfo_free_table(&qclog_tbl);
+<a name="l00556"></a>00556     sinfo_free_image(&map_img);
+<a name="l00557"></a>00557 
+<a name="l00558"></a>00558     <span class="comment">/* # ---free memory--- */</span>
+<a name="l00559"></a>00559     sinfo_new_destroy_2Dfloatarray ( &acoefs, cfg->nrDispCoefficients );
+<a name="l00560"></a>00560     <span class="comment">/* To fix a memory bug we comment the following. But check! */</span>
+<a name="l00561"></a>00561     <span class="comment">/* cpl_free ( wave ); */</span>
+<a name="l00562"></a>00562     <span class="comment">/* cpl_free ( intens ); */</span>
+<a name="l00563"></a>00563 
+<a name="l00564"></a>00564   } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (cfg->wavemapInd == 1 && cfg->calibIndicator == 1) {
+<a name="l00565"></a>00565     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"give either wavemapIndicator = yes and calibIndicator"</span>);
+<a name="l00566"></a>00566     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"= no or wavemapIndicator = no and calibIndicator = yes"</span>) ;
+<a name="l00567"></a>00567     <span class="keywordflow">goto</span> cleanup;
+<a name="l00568"></a>00568   }
+<a name="l00569"></a>00569 
+<a name="l00570"></a>00570   <span class="comment">/*-------------------------------------------------------------------</span>
+<a name="l00571"></a>00571 <span class="comment">   *-------------------SLITFITS----------------------------------------</span>
+<a name="l00572"></a>00572 <span class="comment">   *-------------------------------------------------------------------</span>
+<a name="l00573"></a>00573 <span class="comment">   #--fit the slitlet sinfo_edge positions if desired--</span>
+<a name="l00574"></a>00574 <span class="comment">  */</span>
+<a name="l00575"></a>00575   <span class="keywordflow">if</span> (cfg->slitposIndicator == 1) {
+<a name="l00576"></a>00576   sinfo_msg(<span class="stringliteral">"fit the slitlet sinfo_edge positions"</span>);
+<a name="l00577"></a>00577   <span class="keywordflow">if</span> (cfg->calibIndicator != 1 && cfg->estimateIndicator != 1) {
+<a name="l00578"></a>00578 
+<a name="l00579"></a>00579     <span class="comment">/*</span>
+<a name="l00580"></a>00580 <span class="comment">      #read the first integer to determine the number of fit </span>
+<a name="l00581"></a>00581 <span class="comment">      parameters to allocate</span>
+<a name="l00582"></a>00582 <span class="comment">    */</span>
+<a name="l00583"></a>00583 
+<a name="l00584"></a>00584      <span class="keywordflow">if</span>(sinfo_is_fits_file(cfg->paramsList) !=1 ) {
+<a name="l00585"></a>00585        <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"cannot read FITS file %s "</span>,cfg->paramsList);
+<a name="l00586"></a>00586        <span class="keywordflow">goto</span> cleanup;
+<a name="l00587"></a>00587      }
+<a name="l00588"></a>00588      strcpy(tbl_fitpar_name,cfg->paramsList);
+<a name="l00589"></a>00589      check_nomsg(tbl_fitpar = cpl_table_load(tbl_fitpar_name,1,0));
+<a name="l00590"></a>00590 
+<a name="l00591"></a>00591      check_nomsg(readsum=cpl_table_get_int(tbl_fitpar,<span class="stringliteral">"n_params"</span>,1,status));
+<a name="l00592"></a>00592      sinfo_free_table(&tbl_fitpar);
+<a name="l00593"></a>00593  
+<a name="l00594"></a>00594      cknull(sinfo_new_fit_params( readsum ),<span class="stringliteral">"sinfo_new_fit_params failed!"</span>);
+<a name="l00595"></a>00595 
+<a name="l00596"></a>00596      ck0(sinfo_dumpTblToFitParams(par, cfg->paramsList),
+<a name="l00597"></a>00597      <span class="stringliteral">"reading tbl %s "</span>, cfg->paramsList);
+<a name="l00598"></a>00598   }
+<a name="l00599"></a>00599 
+<a name="l00600"></a>00600   <span class="comment">/* #allocate memory for the slitlet position array */</span>
+<a name="l00601"></a>00601   sinfo_slit_pos = sinfo_new_2Dfloatarray(32,2);
+<a name="l00602"></a>00602   <span class="comment">/* #now decide which fit model function you want to use by </span>
+<a name="l00603"></a>00603 <span class="comment">     reading a given character</span>
+<a name="l00604"></a>00604 <span class="comment">  */</span>
+<a name="l00605"></a>00605   <span class="comment">/*</span>
+<a name="l00606"></a>00606 <span class="comment">  sinfo_msg("cfg->fitBoltzIndicator=%d\n",cfg->fitBoltzIndicator);</span>
+<a name="l00607"></a>00607 <span class="comment">  sinfo_msg("cfg->estimateIndicator=%d\n",cfg->estimateIndicator);</span>
+<a name="l00608"></a>00608 <span class="comment">  sinfo_msg("cfg->fitEdgeIndicator=%d\n",cfg->fitEdgeIndicator);</span>
+<a name="l00609"></a>00609 <span class="comment">  */</span>
+<a name="l00610"></a>00610   <span class="keywordflow">if</span> (cfg->fitBoltzIndicator == 1) {
+<a name="l00611"></a>00611     <span class="keywordflow">if</span> (cfg->estimateIndicator == 1) {
+<a name="l00612"></a>00612       <span class="comment">/* #open the ASCII list of the slitlet positions--- */</span>
+<a name="l00613"></a>00613       <span class="comment">/*READ TFITS TABLE*/</span>
+<a name="l00614"></a>00614       strcpy(tbl_slitpos_guess_name,cfg->slitposGuessName);
+<a name="l00615"></a>00615       check_nomsg(tbl_slitpos_guess=cpl_table_load(tbl_slitpos_guess_name,1,0));
+<a name="l00616"></a>00616       check_nomsg(n = cpl_table_get_nrow(tbl_slitpos_guess));
+<a name="l00617"></a>00617 
+<a name="l00618"></a>00618       <span class="keywordflow">for</span> (i =0 ; i< 32; i++){
+<a name="l00619"></a>00619         val_x=cpl_table_get_double(tbl_slitpos_guess,<span class="stringliteral">"pos1"</span>,i,status);
+<a name="l00620"></a>00620         val_y=cpl_table_get_double(tbl_slitpos_guess,<span class="stringliteral">"pos2"</span>,i,status);
+<a name="l00621"></a>00621     sinfo_new_array2D_set_value(sinfo_slit_pos,val_x,i,0);
+<a name="l00622"></a>00622     sinfo_new_array2D_set_value(sinfo_slit_pos,val_y,i,1);
+<a name="l00623"></a>00623       }
+<a name="l00624"></a>00624       sinfo_free_table(&tbl_slitpos_guess);
+<a name="l00625"></a>00625 
+<a name="l00626"></a>00626       sinfo_msg(<span class="stringliteral">"sinfo_new_fit_slits_boltz_with_estimate"</span>);
+<a name="l00627"></a>00627       fit = <a class="code" href="group__sinfo__boltzmann.html#ga1851d695a240ae0d23d20657f02867bb" title="its the beginning and end position of the slitlets by using non-linear least square...">sinfo_new_fit_slits_boltz_with_estimate</a>(im, 
+<a name="l00628"></a>00628                                             sinfo_slit_pos, 
+<a name="l00629"></a>00629                                   cfg->boxLength, 
+<a name="l00630"></a>00630                                             cfg->yBox, 
+<a name="l00631"></a>00631                                             cfg->diffTol, 
+<a name="l00632"></a>00632                                             cfg->loPos, 
+<a name="l00633"></a>00633                                             cfg->hiPos );
+<a name="l00634"></a>00634       <span class="keywordflow">if</span> (fit < 0){
+<a name="l00635"></a>00635     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"sinfo_new_fit_slits_boltz_with_estimate failed"</span> );
+<a name="l00636"></a>00636     <span class="keywordflow">goto</span> cleanup;
+<a name="l00637"></a>00637       }
+<a name="l00638"></a>00638     } <span class="keywordflow">else</span> {
+<a name="l00639"></a>00639     sinfo_msg(<span class="stringliteral">"sinfo_new_fit_slits_boltz"</span>);
+<a name="l00640"></a>00640     fit = <a class="code" href="group__sinfo__boltzmann.html#gab3549f7bb876fb4091ba3c0bd64d267d" title="fits the beginning and end position of the slitlets by using non-linear least square...">sinfo_new_fit_slits_boltz</a>(im, 
+<a name="l00641"></a>00641                                   par, 
+<a name="l00642"></a>00642                                   sinfo_slit_pos, 
+<a name="l00643"></a>00643                                   cfg->boxLength, 
+<a name="l00644"></a>00644                                   cfg->yBox, 
+<a name="l00645"></a>00645                                   cfg->diffTol );
+<a name="l00646"></a>00646 
+<a name="l00647"></a>00647     <span class="keywordflow">if</span> (fit < 0) {
+<a name="l00648"></a>00648       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> ( <span class="stringliteral">"sinfo_new_fit_slits_boltz failed"</span> );
+<a name="l00649"></a>00649       <span class="keywordflow">goto</span> cleanup;
+<a name="l00650"></a>00650     }
+<a name="l00651"></a>00651     }
+<a name="l00652"></a>00652   } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (cfg->fitEdgeIndicator == 1) {
+<a name="l00653"></a>00653 
+<a name="l00654"></a>00654     <span class="keywordflow">if</span> (cfg->estimateIndicator == 1){
+<a name="l00655"></a>00655       <span class="comment">/*READ TFITS TABLE*/</span>
+<a name="l00656"></a>00656       strcpy(tbl_slitpos_guess_name,cfg->slitposGuessName);
+<a name="l00657"></a>00657       check_nomsg(tbl_slitpos_guess=cpl_table_load(tbl_slitpos_guess_name,1,0));
+<a name="l00658"></a>00658       check_nomsg(n = cpl_table_get_nrow(tbl_slitpos_guess));
+<a name="l00659"></a>00659 
+<a name="l00660"></a>00660       <span class="keywordflow">for</span> (i =0 ; i< 32; i++){
+<a name="l00661"></a>00661     val_x=cpl_table_get_double(tbl_slitpos_guess,<span class="stringliteral">"pos1"</span>,i,status);
+<a name="l00662"></a>00662     val_y=cpl_table_get_double(tbl_slitpos_guess,<span class="stringliteral">"pos2"</span>,i,status);
+<a name="l00663"></a>00663     sinfo_new_array2D_set_value(sinfo_slit_pos,val_x,i,0);
+<a name="l00664"></a>00664     sinfo_new_array2D_set_value(sinfo_slit_pos,val_y,i,1);
+<a name="l00665"></a>00665       }
+<a name="l00666"></a>00666       cpl_table_delete(tbl_slitpos_guess);
+<a name="l00667"></a>00667 
+<a name="l00668"></a>00668       sinfo_msg(<span class="stringliteral">"sinfo_new_fit_slits_edge_with_estimate"</span>);
+<a name="l00669"></a>00669       fit = sinfo_new_fit_slits_edge_with_estimate(im, 
+<a name="l00670"></a>00670                                            sinfo_slit_pos,
+<a name="l00671"></a>00671                                            cfg->boxLength, 
+<a name="l00672"></a>00672                                            cfg->yBox, 
+<a name="l00673"></a>00673                                            cfg->diffTol, 
+<a name="l00674"></a>00674                                            cfg->loPos, 
+<a name="l00675"></a>00675                                  cfg->hiPos );
+<a name="l00676"></a>00676       <span class="keywordflow">if</span> (fit < 0) {
+<a name="l00677"></a>00677      <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>( <span class="stringliteral">"sinfo_new_fit_slits_boltz failed"</span> );
+<a name="l00678"></a>00678          <span class="keywordflow">goto</span> cleanup;
+<a name="l00679"></a>00679       }
+<a name="l00680"></a>00680     } <span class="keywordflow">else</span> {
+<a name="l00681"></a>00681       sinfo_msg(<span class="stringliteral">"sinfo_new_fit_slits_edge"</span>);
+<a name="l00682"></a>00682       fit = sinfo_new_fit_slits_edge(im, 
+<a name="l00683"></a>00683                                par, 
+<a name="l00684"></a>00684                                sinfo_slit_pos, 
+<a name="l00685"></a>00685                                cfg->boxLength, 
+<a name="l00686"></a>00686                                cfg->yBox, 
+<a name="l00687"></a>00687                                cfg->diffTol );
+<a name="l00688"></a>00688       <span class="keywordflow">if</span> (fit < 0) {
+<a name="l00689"></a>00689     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"sinfo_new_fit_slits_edge failed"</span> );
+<a name="l00690"></a>00690         <span class="keywordflow">goto</span> cleanup;
+<a name="l00691"></a>00691       }
+<a name="l00692"></a>00692     }
+<a name="l00693"></a>00693   } <span class="keywordflow">else</span> {
+<a name="l00694"></a>00694     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no indication of desired fit function given"</span> );
+<a name="l00695"></a>00695     <span class="keywordflow">goto</span> cleanup;
+<a name="l00696"></a>00696   }
+<a name="l00697"></a>00697   sinfo_free_image(&im);
+<a name="l00698"></a>00698 
+<a name="l00699"></a>00699   <span class="comment">/* #store the resulting sitlet positions in an TFITS table */</span>
+<a name="l00700"></a>00700   check_nomsg(tbl_spos = cpl_table_new(32));
+<a name="l00701"></a>00701   check_nomsg(cpl_table_new_column(tbl_spos,<span class="stringliteral">"pos1"</span>, CPL_TYPE_DOUBLE));
+<a name="l00702"></a>00702   check_nomsg(cpl_table_new_column(tbl_spos,<span class="stringliteral">"pos2"</span>, CPL_TYPE_DOUBLE));
+<a name="l00703"></a>00703   check_nomsg(cpl_table_set_column_format(tbl_spos,<span class="stringliteral">"pos1"</span>, <span class="stringliteral">"15.9f"</span>));
+<a name="l00704"></a>00704   check_nomsg(cpl_table_set_column_format(tbl_spos,<span class="stringliteral">"pos2"</span>, <span class="stringliteral">"15.9f"</span>));
+<a name="l00705"></a>00705 
+<a name="l00706"></a>00706   <span class="keywordflow">for</span> (i =0; i< 32; i++) {
+<a name="l00707"></a>00707     cpl_table_set_double(tbl_spos,<span class="stringliteral">"pos1"</span>,i,
+<a name="l00708"></a>00708                          sinfo_new_array2D_get_value(sinfo_slit_pos,i,0));
+<a name="l00709"></a>00709     cpl_table_set_double(tbl_spos,<span class="stringliteral">"pos2"</span>,i,
+<a name="l00710"></a>00710                          sinfo_new_array2D_get_value(sinfo_slit_pos,i,1));
+<a name="l00711"></a>00711      
+<a name="l00712"></a>00712   }
+<a name="l00713"></a>00713   <span class="keywordflow">if</span>(sw == 1) {
+<a name="l00714"></a>00714     strcpy(tbl_name,<span class="stringliteral">"out_slitpos_guess.fits"</span>);
+<a name="l00715"></a>00715     ck0(sinfo_pro_save_tbl(tbl_spos,ref_set,sof,tbl_name,
+<a name="l00716"></a>00716                PRO_SLIT_POS_GUESS,NULL,plugin_id,config),
+<a name="l00717"></a>00717     <span class="stringliteral">"cannot save tbl %s"</span>, tbl_name);
+<a name="l00718"></a>00718   } <span class="keywordflow">else</span> {
+<a name="l00719"></a>00719     strcpy(tbl_name,cfg->slitposName);
+<a name="l00720"></a>00720     ck0(sinfo_pro_save_tbl(tbl_spos,ref_set,sof,tbl_name,
+<a name="l00721"></a>00721                PRO_SLIT_POS,NULL,plugin_id,config),
+<a name="l00722"></a>00722     <span class="stringliteral">"cannot save tbl %s"</span>, tbl_name);
+<a name="l00723"></a>00723   }
+<a name="l00724"></a>00724   sinfo_free_table(&tbl_spos);
+<a name="l00725"></a>00725   sinfo_new_destroy_2Dfloatarray ( &sinfo_slit_pos, 32 );
+<a name="l00726"></a>00726   }
+<a name="l00727"></a>00727 
+<a name="l00728"></a>00728   <span class="keywordflow">if</span> ( (cfg->slitposIndicator == 1 && cfg->estimateIndicator != 1) || 
+<a name="l00729"></a>00729        (cfg->calibIndicator == 1)  || (cfg->wavemapInd == 1) ){
+<a name="l00730"></a>00730     sinfo_new_destroy_fit_params(&par);
+<a name="l00731"></a>00731   }
+<a name="l00732"></a>00732 
+<a name="l00733"></a>00733 
+<a name="l00734"></a>00734 
+<a name="l00735"></a>00735 
+<a name="l00736"></a>00736 
+<a name="l00737"></a>00737   <span class="keywordflow">if</span>(pdensity > 1) {
+<a name="l00738"></a>00738      check_nomsg(sinfo_image_resample(plugin_id,config,sof,ref_set));
+<a name="l00739"></a>00739 
+<a name="l00740"></a>00740 
+<a name="l00796"></a>00796   }
+<a name="l00797"></a>00797   sinfo_free_frameset(&raw);
+<a name="l00798"></a>00798   sinfo_qc_wcal_delete(&qc);
+<a name="l00799"></a>00799   sinfo_wavecal_free(&cfg);
+<a name="l00800"></a>00800 
+<a name="l00801"></a>00801   <span class="keywordflow">return</span> 0;
+<a name="l00802"></a>00802 
+<a name="l00803"></a>00803   cleanup:
+<a name="l00804"></a>00804   sinfo_free_image(&map_img);
+<a name="l00805"></a>00805   <span class="comment">//sinfo_free_image(&wstk_img);</span>
+<a name="l00806"></a>00806   sinfo_free_table(&tbl_spos);
+<a name="l00807"></a>00807   sinfo_free_table(&tbl_fitpar);
+<a name="l00808"></a>00808   sinfo_free_image(&map_img);
+<a name="l00809"></a>00809   sinfo_free_table(&tbl_wcal);
+<a name="l00810"></a>00810   sinfo_free_table(&tbl_fp) ;
+<a name="l00811"></a>00811   sinfo_free_table(&tbl_line_list);
+<a name="l00812"></a>00812   sinfo_free_table(&tbl_wcal);
+<a name="l00813"></a>00813   sinfo_free_table(&qclog_tbl);
+<a name="l00814"></a>00814   sinfo_free_image(&map_img);
+<a name="l00815"></a>00815   sinfo_new_destroy_fit_params(&par);
+<a name="l00816"></a>00816   sinfo_new_destroy_2Dfloatarray ( &sinfo_slit_pos, 32 );
+<a name="l00817"></a>00817   sinfo_new_destroy_2Dfloatarray ( &wavelength_clean, lx );
+<a name="l00818"></a>00818   sinfo_new_destroy_2Dintarray (&row_clean, lx);
+<a name="l00819"></a>00819   sinfo_new_destroy_intarray(&n_found_lines );
+<a name="l00820"></a>00820   sinfo_new_destroy_intarray(&sum_pointer );
+<a name="l00821"></a>00821   <span class="keywordflow">if</span>(acoefs!=NULL) {
+<a name="l00822"></a>00822      sinfo_new_destroy_2Dfloatarray(&acoefs,cfg->nrDispCoefficients);
+<a name="l00823"></a>00823   }
+<a name="l00824"></a>00824   sinfo_free_table(&tbl_line_list);
+<a name="l00825"></a>00825   sinfo_free_image(&im);
+<a name="l00826"></a>00826   sinfo_wavecal_free(&cfg);
+<a name="l00827"></a>00827   sinfo_free_frameset(&raw);
+<a name="l00828"></a>00828   sinfo_qc_wcal_delete(&qc);
+<a name="l00829"></a>00829   <span class="keywordflow">return</span> -1 ;
+<a name="l00830"></a>00830 
+<a name="l00831"></a>00831 }
+<a name="l00832"></a>00832 
+<a name="l00833"></a>00833 
+<a name="l00834"></a>00834 
+<a name="l00835"></a>00835 
+<a name="l00836"></a>00836 
+<a name="l00837"></a>00837 
+<a name="l00838"></a>00838 
+<a name="l00839"></a>00839 
+<a name="l00840"></a>00840 
+<a name="l00841"></a>00841 
+<a name="l00842"></a>00842 
+<a name="l00843"></a>00843 
+<a name="l00844"></a>00844 <span class="keyword">static</span> cpl_error_code
+<a name="l00845"></a>00845 sinfo_image_resample(<span class="keyword">const</span> <span class="keywordtype">char</span>* plugin_id,
+<a name="l00846"></a>00846                      cpl_parameterlist* config,
+<a name="l00847"></a>00847                      cpl_frameset* sof,
+<a name="l00848"></a>00848                      cpl_frameset* ref_set)
+<a name="l00849"></a>00849 {
+<a name="l00850"></a>00850   <span class="comment">//RESAMPLE ThAr frame for QC</span>
+<a name="l00851"></a>00851   <span class="keywordtype">double</span> dis=0;
+<a name="l00852"></a>00852   <span class="keywordtype">float</span> mi=0;
+<a name="l00853"></a>00853   <span class="keywordtype">float</span> ma=0;
+<a name="l00854"></a>00854   <span class="keywordtype">double</span> cwav=0;
+<a name="l00855"></a>00855   <span class="keywordtype">int</span> cpix=0;
+<a name="l00856"></a>00856   <span class="keyword">const</span> cpl_frame* frm=NULL;
+<a name="l00857"></a>00857   <span class="keywordtype">char</span> wstk_name[80];
+<a name="l00858"></a>00858   <span class="keywordtype">char</span> map_name[80];
+<a name="l00859"></a>00859   cpl_image* res_ima=NULL;
+<a name="l00860"></a>00860   <span class="keywordtype">int</span> ncoeffs=3;
+<a name="l00861"></a>00861   <span class="keywordtype">int</span> nrows=SINFO_RESAMP_NROWS;
+<a name="l00862"></a>00862   cpl_parameter* p=NULL;
+<a name="l00863"></a>00863   cpl_image* wstk_img=NULL;
+<a name="l00864"></a>00864   cpl_image* map_img=NULL;
+<a name="l00865"></a>00865 
+<a name="l00866"></a>00866   check_nomsg(p = cpl_parameterlist_find(config,
+<a name="l00867"></a>00867                                          <span class="stringliteral">"sinfoni.wavecal.n_coeffs"</span>));
+<a name="l00868"></a>00868 
+<a name="l00869"></a>00869   check_nomsg(ncoeffs=cpl_parameter_get_int(p));
+<a name="l00870"></a>00870 
+<a name="l00871"></a>00871   check_nomsg(frm=cpl_frameset_find_const(sof,PRO_WAVE_LAMP_STACKED));
+<a name="l00872"></a>00872   check_nomsg(strcpy(wstk_name,cpl_frame_get_filename(frm)));
+<a name="l00873"></a>00873   check_nomsg(wstk_img=cpl_image_load(wstk_name,CPL_TYPE_FLOAT,0,0));
+<a name="l00874"></a>00874 
+<a name="l00875"></a>00875 
+<a name="l00876"></a>00876 
+<a name="l00877"></a>00877   check_nomsg(frm=cpl_frameset_find_const(sof,PRO_WAVE_MAP));
+<a name="l00878"></a>00878   check_nomsg(strcpy(map_name,cpl_frame_get_filename(frm)));
+<a name="l00879"></a>00879   check_nomsg(map_img=cpl_image_load(map_name,CPL_TYPE_FLOAT,0,0));
+<a name="l00880"></a>00880 
+<a name="l00881"></a>00881 
+<a name="l00882"></a>00882 
+<a name="l00883"></a>00883   cknull(res_ima = sinfo_new_defined_resampling(wstk_img, 
+<a name="l00884"></a>00884                         map_img, 
+<a name="l00885"></a>00885                         ncoeffs,
+<a name="l00886"></a>00886                         &nrows,
+<a name="l00887"></a>00887                         &dis,
+<a name="l00888"></a>00888                         &mi,
+<a name="l00889"></a>00889                         &ma,
+<a name="l00890"></a>00890                         &cwav,
+<a name="l00891"></a>00891                         &cpix),
+<a name="l00892"></a>00892      <span class="stringliteral">" sinfo_definedResampling() failed"</span> ) ;
+<a name="l00893"></a>00893 
+<a name="l00894"></a>00894 
+<a name="l00895"></a>00895 
+<a name="l00896"></a>00896   ck0(sinfo_pro_save_ima(res_ima,ref_set,sof,WAVECAL_RESAMPLED_OUT_FILENAME,
+<a name="l00897"></a>00897              PRO_RESAMPLED_WAVE,NULL,plugin_id,config),
+<a name="l00898"></a>00898       <span class="stringliteral">"cannot save ima %s"</span>,WAVECAL_RESAMPLED_OUT_FILENAME);
+<a name="l00899"></a>00899 
+<a name="l00900"></a>00900 
+<a name="l00901"></a>00901   cleanup:
+<a name="l00902"></a>00902 
+<a name="l00903"></a>00903   sinfo_free_image(&map_img);
+<a name="l00904"></a>00904   sinfo_free_image(&res_ima);
+<a name="l00905"></a>00905   sinfo_free_image(&wstk_img);
+<a name="l00906"></a>00906   <span class="keywordflow">return</span> cpl_error_get_code();
+<a name="l00907"></a>00907 
+<a name="l00908"></a>00908 
+<a name="l00909"></a>00909 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__new__wave__cal__slit2_8h_source.html b/html/sinfo__new__wave__cal__slit2_8h_source.html
new file mode 100644
index 0000000..8318ed9
--- /dev/null
+++ b/html/sinfo__new__wave__cal__slit2_8h_source.html
@@ -0,0 +1,149 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_new_wave_cal_slit2.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_new_wave_cal_slit2.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#ifndef SINFO_NEW_WAVE_CAL_SLIT2_H</span>
+<a name="l00002"></a>00002 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_NEW_WAVE_CAL_SLIT2_H</span>
+<a name="l00003"></a>00003 <span class="preprocessor"></span><span class="comment">/*</span>
+<a name="l00004"></a>00004 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00005"></a>00005 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00006"></a>00006 <span class="comment"> *</span>
+<a name="l00007"></a>00007 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00008"></a>00008 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00009"></a>00009 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00010"></a>00010 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00011"></a>00011 <span class="comment"> *</span>
+<a name="l00012"></a>00012 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00013"></a>00013 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00014"></a>00014 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00015"></a>00015 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00016"></a>00016 <span class="comment"> *</span>
+<a name="l00017"></a>00017 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00018"></a>00018 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00019"></a>00019 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00020"></a>00020 <span class="comment"> */</span>
+<a name="l00021"></a>00021 <span class="comment">/****************************************************************************</span>
+<a name="l00022"></a>00022 <span class="comment">* E.S.O. - VLT project</span>
+<a name="l00023"></a>00023 <span class="comment">*</span>
+<a name="l00024"></a>00024 <span class="comment">* "@(#) $Id: sinfo_new_wave_cal_slit2.h,v 1.7 2007/09/21 14:13:43 amodigli Exp $"</span>
+<a name="l00025"></a>00025 <span class="comment">*</span>
+<a name="l00026"></a>00026 <span class="comment">* who       when      what</span>
+<a name="l00027"></a>00027 <span class="comment">* --------  --------  ----------------------------------------------</span>
+<a name="l00028"></a>00028 <span class="comment">* amodigli  17/09/03  created</span>
+<a name="l00029"></a>00029 <span class="comment">*/</span>
+<a name="l00030"></a>00030 
+<a name="l00031"></a>00031 <span class="comment">/************************************************************************</span>
+<a name="l00032"></a>00032 <span class="comment"> * sinfo_new_wave_cal_slit2.h</span>
+<a name="l00033"></a>00033 <span class="comment"></span>
+<a name="l00034"></a>00034 <span class="comment">  Normal method:</span>
+<a name="l00035"></a>00035 <span class="comment"></span>
+<a name="l00036"></a>00036 <span class="comment">  does the wavelength calibration and the fitting of the slitlet sinfo_edge </span>
+<a name="l00037"></a>00037 <span class="comment">  positions (ASCII file 32 x 2 values) if wished</span>
+<a name="l00038"></a>00038 <span class="comment">  produces an array of the bcoefs and of the fit parameters if wished and a </span>
+<a name="l00039"></a>00039 <span class="comment">  wavelength calibration map input is an emission line frame and a line list</span>
+<a name="l00040"></a>00040 <span class="comment"></span>
+<a name="l00041"></a>00041 <span class="comment">  o searching for lines by cross sinfo_correlation with a line list</span>
+<a name="l00042"></a>00042 <span class="comment">  o Gaussian fitting of emission lines in each column->positions of the lines-></span>
+<a name="l00043"></a>00043 <span class="comment">    resulting fit parameters can be stored in an ASCII file</span>
+<a name="l00044"></a>00044 <span class="comment">  o Fitting of a polynomial to the line positions for each column</span>
+<a name="l00045"></a>00045 <span class="comment">  o Smoothing: fitting of each polynomial coefficient by another polynomial</span>
+<a name="l00046"></a>00046 <span class="comment">    across the whole frame -> resulting polynomial coefficients can be stored </span>
+<a name="l00047"></a>00047 <span class="comment">    in an ASCII file.</span>
+<a name="l00048"></a>00048 <span class="comment">  o Wavelength calibration map (micron value for each frame pixel) can be</span>
+<a name="l00049"></a>00049 <span class="comment">    produced by using these coefficients and a cross sinfo_correlation to the</span>
+<a name="l00050"></a>00050 <span class="comment">    original frame</span>
+<a name="l00051"></a>00051 <span class="comment"></span>
+<a name="l00052"></a>00052 <span class="comment">  o The slitlet sinfo_edge positions can be fitted:</span>
+<a name="l00053"></a>00053 <span class="comment">    1) Automatically (not really stable) or by using guess sinfo_edge positions</span>
+<a name="l00054"></a>00054 <span class="comment">    2) By using a Boltzmann or a linear slope function</span>
+<a name="l00055"></a>00055 <span class="comment"></span>
+<a name="l00056"></a>00056 <span class="comment"></span>
+<a name="l00057"></a>00057 <span class="comment">  Slit method:</span>
+<a name="l00058"></a>00058 <span class="comment"></span>
+<a name="l00059"></a>00059 <span class="comment">  does the wavelength calibration and the fitting of the slitlet sinfo_edge </span>
+<a name="l00060"></a>00060 <span class="comment">  positions (ASCII file 32 x 2 values) if wished produces a list of the fit </span>
+<a name="l00061"></a>00061 <span class="comment">  parameters and of the smoothed coefficients if wished and a wavelength </span>
+<a name="l00062"></a>00062 <span class="comment">  calibration map input is an emission line frame and a line list</span>
+<a name="l00063"></a>00063 <span class="comment"></span>
+<a name="l00064"></a>00064 <span class="comment">  o Does the same as other method but smoothes the found polynomial </span>
+<a name="l00065"></a>00065 <span class="comment">    coefficients within each slitlet and not over the whole frame.</span>
+<a name="l00066"></a>00066 <span class="comment"></span>
+<a name="l00067"></a>00067 <span class="comment">  o Produces always a wavelength calibration map and does not crosscorrelate.</span>
+<a name="l00068"></a>00068 <span class="comment"></span>
+<a name="l00069"></a>00069 <span class="comment"> *----------------------------------------------------------------------</span>
+<a name="l00070"></a>00070 <span class="comment"> */</span>
+<a name="l00071"></a>00071 
+<a name="l00072"></a>00072 <span class="comment">/*</span>
+<a name="l00073"></a>00073 <span class="comment"> * header files</span>
+<a name="l00074"></a>00074 <span class="comment"> */</span>
+<a name="l00075"></a>00075 
+<a name="l00076"></a>00076 <span class="preprocessor">#include <cpl.h></span>   
+<a name="l00077"></a>00077 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00078"></a>00078 
+<a name="l00079"></a>00079 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00080"></a>00080 <span class="comment"> *                        Function ANSI C prototypes</span>
+<a name="l00081"></a>00081 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00082"></a>00082 
+<a name="l00083"></a>00083 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00084"></a>00084 <span class="comment">   Function     :       sinfo_new_wave_cal_slit2()</span>
+<a name="l00085"></a>00085 <span class="comment">   In           :       ini_file: file name of according .ini file</span>
+<a name="l00086"></a>00086 <span class="comment">   Out          :       integer (0 if it worked, -1 if it doesn't) </span>
+<a name="l00087"></a>00087 <span class="comment">   Job          :</span>
+<a name="l00088"></a>00088 <span class="comment"></span>
+<a name="l00089"></a>00089 <span class="comment"></span>
+<a name="l00090"></a>00090 <span class="comment">  Normal method:</span>
+<a name="l00091"></a>00091 <span class="comment"></span>
+<a name="l00092"></a>00092 <span class="comment">  does the wavelength calibration and the fitting of the slitlet sinfo_edge </span>
+<a name="l00093"></a>00093 <span class="comment">  positions (ASCII file 32 x 2 values) if wished</span>
+<a name="l00094"></a>00094 <span class="comment">  produces an array of the bcoefs and of the fit parameters if wished and a </span>
+<a name="l00095"></a>00095 <span class="comment">  wavelength calibration map input is an emission line frame and a line list</span>
+<a name="l00096"></a>00096 <span class="comment"></span>
+<a name="l00097"></a>00097 <span class="comment"></span>
+<a name="l00098"></a>00098 <span class="comment">  o searching for lines by cross sinfo_correlation with a line list</span>
+<a name="l00099"></a>00099 <span class="comment">  o Gaussian fitting of emission lines in each column->positions of the lines-></span>
+<a name="l00100"></a>00100 <span class="comment">    resulting fit parameters can be stored in an ASCII file</span>
+<a name="l00101"></a>00101 <span class="comment">  o Fitting of a polynomial to the line positions for each column</span>
+<a name="l00102"></a>00102 <span class="comment">  o Smoothing: fitting of each polynomial coefficient by another polynomial</span>
+<a name="l00103"></a>00103 <span class="comment">    across the whole frame -> resulting polynomial coefficients can be stored </span>
+<a name="l00104"></a>00104 <span class="comment">    in an ASCII file.</span>
+<a name="l00105"></a>00105 <span class="comment">  o Wavelength calibration map (micron value for each frame pixel) can be</span>
+<a name="l00106"></a>00106 <span class="comment">    produced by using these coefficients and a cross sinfo_correlation to the</span>
+<a name="l00107"></a>00107 <span class="comment">    original frame</span>
+<a name="l00108"></a>00108 <span class="comment"></span>
+<a name="l00109"></a>00109 <span class="comment">  o The slitlet sinfo_edge positions can be fitted:</span>
+<a name="l00110"></a>00110 <span class="comment">    1) Automatically (not really stable) or by using guess sinfo_edge positions</span>
+<a name="l00111"></a>00111 <span class="comment">    2) By using a Boltzmann or a linear slope function</span>
+<a name="l00112"></a>00112 <span class="comment"></span>
+<a name="l00113"></a>00113 <span class="comment">  Slit method:</span>
+<a name="l00114"></a>00114 <span class="comment"></span>
+<a name="l00115"></a>00115 <span class="comment">  does the wavelength calibration and the fitting of the slitlet sinfo_edge </span>
+<a name="l00116"></a>00116 <span class="comment">  positions (ASCII file 32 x 2 values) if wished produces a list of the fit </span>
+<a name="l00117"></a>00117 <span class="comment">  parameters and of the smoothed coefficients if wished and a wavelength </span>
+<a name="l00118"></a>00118 <span class="comment">  calibration map input is an emission line frame and a line list</span>
+<a name="l00119"></a>00119 <span class="comment"></span>
+<a name="l00120"></a>00120 <span class="comment">  o Does the same as other method but smoothes the found polynomial </span>
+<a name="l00121"></a>00121 <span class="comment">    coefficients within each slitlet and not over the whole frame.</span>
+<a name="l00122"></a>00122 <span class="comment"></span>
+<a name="l00123"></a>00123 <span class="comment">  o Produces always a wavelength calibration map and does not crosscorrelate.</span>
+<a name="l00124"></a>00124 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00125"></a>00125 <span class="keywordtype">int</span> 
+<a name="l00126"></a>00126 sinfo_new_wave_cal_slit2 (<span class="keyword">const</span> <span class="keywordtype">char</span>* plugin_id,
+<a name="l00127"></a>00127                           cpl_parameterlist* config, 
+<a name="l00128"></a>00128                           cpl_frameset* sof,cpl_frameset* ref_set) ;
+<a name="l00129"></a>00129 
+<a name="l00130"></a>00130 
+<a name="l00131"></a>00131 <span class="preprocessor">#endif </span>
+<a name="l00132"></a>00132 <span class="preprocessor"></span>
+<a name="l00133"></a>00133 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__north__south__test__config_8c_source.html b/html/sinfo__north__south__test__config_8c_source.html
new file mode 100644
index 0000000..6bd3929
--- /dev/null
+++ b/html/sinfo__north__south__test__config_8c_source.html
@@ -0,0 +1,164 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_north_south_test_config.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_north_south_test_config.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_north_south_test_config.c,v 1.5 2012/03/03 09:50:08 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the CPL (Common Pipeline Library)</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
+<a name="l00007"></a>00007 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span>
+<a name="l00008"></a>00008 <span class="comment"> * License as published by the Free Software Foundation; either</span>
+<a name="l00009"></a>00009 <span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
+<a name="l00014"></a>00014 <span class="comment"> * Lesser General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
+<a name="l00017"></a>00017 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2012/03/03 09:50:08 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.5 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> */</span>
+<a name="l00026"></a>00026 
+<a name="l00027"></a>00027  <span class="comment">/****************************************************************</span>
+<a name="l00028"></a>00028 <span class="comment">  *   North_South_Test Frames Data Reduction Parameter Initialization        *</span>
+<a name="l00029"></a>00029 <span class="comment">  ****************************************************************/</span>
+<a name="l00030"></a>00030 
+<a name="l00031"></a>00031 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00032"></a>00032 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00033"></a>00033 <span class="preprocessor">#endif</span>
+<a name="l00034"></a>00034 <span class="preprocessor"></span><span class="preprocessor">#include "sinfo_north_south_test_config.h"</span>
+<a name="l00049"></a>00049 <span class="keywordtype">void</span>
+<a name="l00050"></a>00050  sinfo_north_south_test_config_add(cpl_parameterlist *list)
+<a name="l00051"></a>00051 {
+<a name="l00052"></a>00052 
+<a name="l00053"></a>00053   cpl_parameter *p;
+<a name="l00054"></a>00054 
+<a name="l00055"></a>00055   <span class="keywordflow">if</span> (!list) {
+<a name="l00056"></a>00056     <span class="keywordflow">return</span>;
+<a name="l00057"></a>00057   }
+<a name="l00058"></a>00058   <span class="comment">/* Clean Mean */</span>
+<a name="l00059"></a>00059   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.north_south_test.low_rejection"</span>,
+<a name="l00060"></a>00060                   CPL_TYPE_DOUBLE,
+<a name="l00061"></a>00061                               <span class="stringliteral">"lower rejection: "</span>
+<a name="l00062"></a>00062                               <span class="stringliteral">"percentage of rejected low intensity pixels "</span>
+<a name="l00063"></a>00063                               <span class="stringliteral">"before averaging"</span>,
+<a name="l00064"></a>00064                               <span class="stringliteral">"sinfoni.north_south_test"</span>,
+<a name="l00065"></a>00065                                0.1,0.0,1.0);
+<a name="l00066"></a>00066 
+<a name="l00067"></a>00067   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"ns-lo_rej"</span>);
+<a name="l00068"></a>00068   cpl_parameterlist_append(list, p);
+<a name="l00069"></a>00069 
+<a name="l00070"></a>00070   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.north_south_test.high_rejection"</span>,
+<a name="l00071"></a>00071                   CPL_TYPE_DOUBLE,
+<a name="l00072"></a>00072                               <span class="stringliteral">"higher rejection: "</span>
+<a name="l00073"></a>00073                               <span class="stringliteral">"percentage of rejected high intensity pixels "</span>
+<a name="l00074"></a>00074                               <span class="stringliteral">"before averaging"</span>,
+<a name="l00075"></a>00075                               <span class="stringliteral">"sinfoni.north_south_test"</span>,
+<a name="l00076"></a>00076                               0.1,0.0,1.0);
+<a name="l00077"></a>00077 
+<a name="l00078"></a>00078   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"ns-hi_rej"</span>);
+<a name="l00079"></a>00079   cpl_parameterlist_append(list, p);
+<a name="l00080"></a>00080 
+<a name="l00081"></a>00081 
+<a name="l00082"></a>00082   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.north_south_test.mask_ind"</span>,
+<a name="l00083"></a>00083                   CPL_TYPE_BOOL,
+<a name="l00084"></a>00084                               <span class="stringliteral">"Mask Index: "</span>
+<a name="l00085"></a>00085                              <span class="stringliteral">"indicator if a bad pixel mask is applied or not"</span>,
+<a name="l00086"></a>00086                               <span class="stringliteral">"sinfoni.north_south_test"</span>,
+<a name="l00087"></a>00087                               FALSE);
+<a name="l00088"></a>00088 
+<a name="l00089"></a>00089   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"ns-mask_ind"</span>);
+<a name="l00090"></a>00090   cpl_parameterlist_append(list, p);
+<a name="l00091"></a>00091 
+<a name="l00092"></a>00092 
+<a name="l00093"></a>00093 
+<a name="l00094"></a>00094   <span class="comment">/* Gauss Convolution */</span>
+<a name="l00095"></a>00095   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.north_south_test.gauss_ind"</span>,
+<a name="l00096"></a>00096                   CPL_TYPE_BOOL,
+<a name="l00097"></a>00097                               <span class="stringliteral">"Gauss Index: "</span>,
+<a name="l00098"></a>00098                               <span class="stringliteral">"sinfoni.north_south_test"</span>,
+<a name="l00099"></a>00099                               FALSE);
+<a name="l00100"></a>00100 
+<a name="l00101"></a>00101   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"ns-gauss_ind"</span>);
+<a name="l00102"></a>00102   cpl_parameterlist_append(list, p);
+<a name="l00103"></a>00103 
+<a name="l00104"></a>00104   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.north_south_test.kernel_half_width"</span>,
+<a name="l00105"></a>00105                   CPL_TYPE_INT,
+<a name="l00106"></a>00106                               <span class="stringliteral">"Kernel Half Width "</span>
+<a name="l00107"></a>00107                               <span class="stringliteral">"kernel half width of the Gaussian "</span>
+<a name="l00108"></a>00108                               <span class="stringliteral">"response function"</span>,
+<a name="l00109"></a>00109                               <span class="stringliteral">"sinfoni.north_south_test"</span>,
+<a name="l00110"></a>00110                                2);
+<a name="l00111"></a>00111 
+<a name="l00112"></a>00112   cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"ns-khw"</span>);
+<a name="l00113"></a>00113   cpl_parameterlist_append(list, p);
+<a name="l00114"></a>00114 
+<a name="l00115"></a>00115 
+<a name="l00116"></a>00116 
+<a name="l00117"></a>00117   <span class="comment">/* North South Test */</span>
+<a name="l00118"></a>00118 
+<a name="l00119"></a>00119 
+<a name="l00120"></a>00120   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.north_south_test.half_width"</span>,
+<a name="l00121"></a>00121                   CPL_TYPE_INT,
+<a name="l00122"></a>00122                               <span class="stringliteral">"Half Width"</span>,
+<a name="l00123"></a>00123                               <span class="stringliteral">"sinfoni.north_south_test"</span>,
+<a name="l00124"></a>00124                                4);
+<a name="l00125"></a>00125 
+<a name="l00126"></a>00126   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"ns-hw"</span>);
+<a name="l00127"></a>00127   cpl_parameterlist_append(list, p);
+<a name="l00128"></a>00128 
+<a name="l00129"></a>00129   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.north_south_test.fwhm"</span>,
+<a name="l00130"></a>00130                   CPL_TYPE_DOUBLE,
+<a name="l00131"></a>00131                               <span class="stringliteral">"FWHM"</span>,
+<a name="l00132"></a>00132                               <span class="stringliteral">"sinfoni.north_south_test"</span>,
+<a name="l00133"></a>00133                                2.);
+<a name="l00134"></a>00134 
+<a name="l00135"></a>00135   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"ns-fwhm"</span>);
+<a name="l00136"></a>00136   cpl_parameterlist_append(list, p);
+<a name="l00137"></a>00137 
+<a name="l00138"></a>00138 
+<a name="l00139"></a>00139   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.north_south_test.min_diff"</span>,
+<a name="l00140"></a>00140                   CPL_TYPE_DOUBLE,
+<a name="l00141"></a>00141                               <span class="stringliteral">"Minimum of Difference"</span>,
+<a name="l00142"></a>00142                               <span class="stringliteral">"sinfoni.north_south_test"</span>,
+<a name="l00143"></a>00143                               1.);
+<a name="l00144"></a>00144 
+<a name="l00145"></a>00145   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"ns-min_diff"</span>);
+<a name="l00146"></a>00146   cpl_parameterlist_append(list, p);
+<a name="l00147"></a>00147 
+<a name="l00148"></a>00148 
+<a name="l00149"></a>00149 
+<a name="l00150"></a>00150   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.north_south_test.dev_tol"</span>,
+<a name="l00151"></a>00151                   CPL_TYPE_DOUBLE,
+<a name="l00152"></a>00152                               <span class="stringliteral">"Dev Tol"</span>,
+<a name="l00153"></a>00153                               <span class="stringliteral">"sinfoni.north_south_test"</span>,
+<a name="l00154"></a>00154                               20.);
+<a name="l00155"></a>00155 
+<a name="l00156"></a>00156 
+<a name="l00157"></a>00157   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"ns-dev_tol"</span>);
+<a name="l00158"></a>00158   cpl_parameterlist_append(list, p);
+<a name="l00159"></a>00159 
+<a name="l00160"></a>00160 
+<a name="l00161"></a>00161 
+<a name="l00162"></a>00162 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__north__south__test__config_8h_source.html b/html/sinfo__north__south__test__config_8h_source.html
new file mode 100644
index 0000000..7c410f4
--- /dev/null
+++ b/html/sinfo__north__south__test__config_8h_source.html
@@ -0,0 +1,50 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_north_south_test_config.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_north_south_test_config.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_north_south_test_config.h,v 1.1 2006/10/20 08:06:32 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the CPL (Common Pipeline Library)</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
+<a name="l00007"></a>00007 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span>
+<a name="l00008"></a>00008 <span class="comment"> * License as published by the Free Software Foundation; either</span>
+<a name="l00009"></a>00009 <span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
+<a name="l00014"></a>00014 <span class="comment"> * Lesser General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
+<a name="l00017"></a>00017 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2006/10/20 08:06:32 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.1 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> */</span>
+<a name="l00026"></a>00026 
+<a name="l00027"></a>00027  <span class="comment">/****************************************************************</span>
+<a name="l00028"></a>00028 <span class="comment">  *   North_South_Test Frames Data Reduction Parameter Initialization        *</span>
+<a name="l00029"></a>00029 <span class="comment">  ****************************************************************/</span>
+<a name="l00030"></a>00030 <span class="preprocessor">#include "cpl.h"</span>    <span class="comment">/* defines parlist structure */</span>
+<a name="l00031"></a>00031 
+<a name="l00032"></a>00032 <span class="keywordtype">void</span>
+<a name="l00033"></a>00033 sinfo_north_south_test_config_add(cpl_parameterlist *list);
+<a name="l00034"></a>00034 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__ns__cfg_8c_source.html b/html/sinfo__ns__cfg_8c_source.html
new file mode 100644
index 0000000..84306f4
--- /dev/null
+++ b/html/sinfo__ns__cfg_8c_source.html
@@ -0,0 +1,90 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_ns_cfg.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_ns_cfg.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 
+<a name="l00020"></a>00020 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00021"></a>00021 <span class="comment">   </span>
+<a name="l00022"></a>00022 <span class="comment">   File name     :    sinfo_ns_cfg.c</span>
+<a name="l00023"></a>00023 <span class="comment">   Author     :       Juergen Schreiber</span>
+<a name="l00024"></a>00024 <span class="comment">   Created on    :    November 2001</span>
+<a name="l00025"></a>00025 <span class="comment">   Description    :    configuration handling tools for the north-south test</span>
+<a name="l00026"></a>00026 <span class="comment"></span>
+<a name="l00027"></a>00027 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span>
+<a name="l00032"></a>00032 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                                   Includes</span>
+<a name="l00034"></a>00034 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 
+<a name="l00036"></a>00036 <span class="preprocessor">#include "sinfo_ns_cfg.h"</span>
+<a name="l00037"></a>00037 
+<a name="l00038"></a>00038 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00039"></a>00039 <span class="comment">                              Function codes</span>
+<a name="l00040"></a>00040 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00048"></a>00048 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00049"></a>00049 <span class="comment">   Function :   sinfo_ns_cfg_create()</span>
+<a name="l00050"></a>00050 <span class="comment">   In       :   void</span>
+<a name="l00051"></a>00051 <span class="comment">   Out      :   pointer to allocated base ns_config structure</span>
+<a name="l00052"></a>00052 <span class="comment">   Job      :   allocate memory for a ns_config struct</span>
+<a name="l00053"></a>00053 <span class="comment">   Notice   :   only the main (base) structure is allocated</span>
+<a name="l00054"></a>00054 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00055"></a>00055 
+<a name="l00056"></a>00056 ns_config * sinfo_ns_cfg_create(<span class="keywordtype">void</span>)
+<a name="l00057"></a>00057 {
+<a name="l00058"></a>00058     <span class="keywordflow">return</span> cpl_calloc(1, <span class="keyword">sizeof</span>(ns_config));
+<a name="l00059"></a>00059 }
+<a name="l00060"></a>00060 
+<a name="l00061"></a>00061 
+<a name="l00062"></a>00062 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00063"></a>00063 <span class="comment">   Function :   sinfo_ns_cfg_destroy()</span>
+<a name="l00064"></a>00064 <span class="comment">   In       :   ns_config to deallocate</span>
+<a name="l00065"></a>00065 <span class="comment">   Out      :   void</span>
+<a name="l00066"></a>00066 <span class="comment">   Job      :   deallocate all memory associated with a ns_config data structure</span>
+<a name="l00067"></a>00067 <span class="comment">   Notice   :   </span>
+<a name="l00068"></a>00068 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00069"></a>00069 
+<a name="l00070"></a>00070 <span class="keywordtype">void</span> sinfo_ns_cfg_destroy(ns_config * nc)
+<a name="l00071"></a>00071 {
+<a name="l00072"></a>00072     <span class="keywordflow">if</span> (nc==NULL) return ;
+<a name="l00073"></a>00073 
+<a name="l00074"></a>00074     <span class="comment">/*cpl_free(nc->frametype);*/</span>
+<a name="l00075"></a>00075 
+<a name="l00076"></a>00076     <span class="comment">/* Free main struct */</span>
+<a name="l00077"></a>00077     cpl_free(nc);
+<a name="l00078"></a>00078 
+<a name="l00079"></a>00079     return ;
+<a name="l00080"></a>00080 }
+<a name="l00081"></a>00081 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__ns__cfg_8h_source.html b/html/sinfo__ns__cfg_8h_source.html
new file mode 100644
index 0000000..cde4550
--- /dev/null
+++ b/html/sinfo__ns__cfg_8h_source.html
@@ -0,0 +1,120 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_ns_cfg.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_ns_cfg.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name     :    sinfo_ns_cfg.h</span>
+<a name="l00022"></a>00022 <span class="comment">   Author    :    Juergen Schreiber</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on    :    November 2001</span>
+<a name="l00024"></a>00024 <span class="comment">   Description    :    ns_ini definitions + handling prototypes</span>
+<a name="l00025"></a>00025 <span class="comment"></span>
+<a name="l00026"></a>00026 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00027"></a>00027 <span class="preprocessor">#ifndef SINFO_NS_CFG_H</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_NS_CFG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00030"></a>00030 <span class="comment">                                   Includes</span>
+<a name="l00031"></a>00031 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00032"></a>00032 <span class="preprocessor">#include <stdlib.h></span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include "sinfo_globals.h"</span>
+<a name="l00034"></a>00034 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00035"></a>00035 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00036"></a>00036 <span class="comment">                                   Defines</span>
+<a name="l00037"></a>00037 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00038"></a>00038 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00039"></a>00039 <span class="comment">                                   New types</span>
+<a name="l00040"></a>00040 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00041"></a>00041 <span class="comment">/*</span>
+<a name="l00042"></a>00042 <span class="comment">  data cube creation blackboard container</span>
+<a name="l00043"></a>00043 <span class="comment"></span>
+<a name="l00044"></a>00044 <span class="comment">  This structure holds all information related to the cube creation</span>
+<a name="l00045"></a>00045 <span class="comment">  routine. It is used as a container for the flux of ancillary data,</span>
+<a name="l00046"></a>00046 <span class="comment">  computed values, and algorithm status. Pixel flux is separated from</span>
+<a name="l00047"></a>00047 <span class="comment">  the blackboard.</span>
+<a name="l00048"></a>00048 <span class="comment">  */</span>
+<a name="l00049"></a>00049 
+<a name="l00050"></a>00050 <span class="keyword">typedef</span> <span class="keyword">struct </span>ns_config {
+<a name="l00051"></a>00051 <span class="comment">/*-------General---------*/</span>
+<a name="l00052"></a>00052         <span class="keywordtype">char</span> inList[FILE_NAME_SZ] ;  <span class="comment">/* name of the input file list </span>
+<a name="l00053"></a>00053 <span class="comment">                                        containing the on and off-frames */</span> 
+<a name="l00054"></a>00054         <span class="keywordtype">char</span> outName[FILE_NAME_SZ] ; <span class="comment">/* output name of the ASCII list </span>
+<a name="l00055"></a>00055 <span class="comment">                                        containing the determined distances */</span>
+<a name="l00056"></a>00056         <span class="keywordtype">char</span> ** framelist ; <span class="comment">/* list of frames */</span>
+<a name="l00057"></a>00057         <span class="keywordtype">int</span>  *  frametype ; <span class="comment">/* list of frame types on or off */</span>
+<a name="l00058"></a>00058         <span class="keywordtype">int</span>     nframes ;   <span class="comment">/* number of frames in frame list */</span>
+<a name="l00059"></a>00059         <span class="keywordtype">int</span>     nobj ;      <span class="comment">/* number of object frames in frame list */</span>
+<a name="l00060"></a>00060         <span class="keywordtype">int</span>     noff ;      <span class="comment">/* number of off frames in frame list */</span>
+<a name="l00061"></a>00061 
+<a name="l00062"></a>00062 <span class="comment">/*------ CleanMean ------*/</span>
+<a name="l00063"></a>00063         <span class="comment">/* percentage of rejected low intensity pixels */</span>
+<a name="l00064"></a>00064         <span class="keywordtype">float</span> loReject ;
+<a name="l00065"></a>00065         <span class="comment">/* percentage of rejected high intensity pixels */</span>
+<a name="l00066"></a>00066         <span class="keywordtype">float</span> hiReject ;
+<a name="l00067"></a>00067         <span class="comment">/* indicator if a bad pixel mask is applied or not */</span>
+<a name="l00068"></a>00068         <span class="keywordtype">int</span> maskInd ;
+<a name="l00069"></a>00069         <span class="comment">/* file name of the bad pixel mask fits file */</span>
+<a name="l00070"></a>00070         <span class="keywordtype">char</span> mask[FILE_NAME_SZ] ;
+<a name="l00071"></a>00071 <span class="comment">/*------ GaussConvolution ------*/</span>
+<a name="l00072"></a>00072         <span class="comment">/* indicator if Gaussian convolution is applied or not */</span>
+<a name="l00073"></a>00073         <span class="keywordtype">int</span> gaussInd ;
+<a name="l00074"></a>00074         <span class="comment">/* kernel half width of the Gaussian response function */</span>
+<a name="l00075"></a>00075         <span class="keywordtype">int</span> hw ;
+<a name="l00076"></a>00076 <span class="comment">/*------ NorthSouthTest ------*/</span>
+<a name="l00077"></a>00077         <span class="comment">/* name of the averaged output fits frame */</span>
+<a name="l00078"></a>00078         <span class="keywordtype">char</span> fitsname[FILE_NAME_SZ] ;      
+<a name="l00079"></a>00079         <span class="comment">/* number of slitlets */</span>
+<a name="l00080"></a>00080         <span class="keywordtype">int</span> nslits ;      
+<a name="l00081"></a>00081         <span class="comment">/* pixel half width of a box within which the spatial profile </span>
+<a name="l00082"></a>00082 <span class="comment">           is fitted by a Gaussian */</span>
+<a name="l00083"></a>00083         <span class="keywordtype">int</span> halfWidth ;
+<a name="l00084"></a>00084         <span class="comment">/* first guess of the fwhm of the Gaussian fit function */</span>
+<a name="l00085"></a>00085         <span class="keywordtype">float</span> fwhm ;
+<a name="l00086"></a>00086         <span class="comment">/* minimum amplitude above which the fit is carried out */</span>
+<a name="l00087"></a>00087         <span class="keywordtype">float</span> minDiff ;
+<a name="l00088"></a>00088         <span class="comment">/* estimated average distance of spectra */</span>
+<a name="l00089"></a>00089         <span class="keywordtype">float</span> estimated_dist ;
+<a name="l00090"></a>00090         <span class="comment">/* maximal pixel tolerance of the slitlet distances */</span>
+<a name="l00091"></a>00091         <span class="keywordtype">float</span> devtol ;
+<a name="l00092"></a>00092 } ns_config ;
+<a name="l00093"></a>00093 
+<a name="l00094"></a>00094 
+<a name="l00095"></a>00095 
+<a name="l00096"></a>00096 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00097"></a>00097 <span class="comment">                               Function prototypes</span>
+<a name="l00098"></a>00098 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00106"></a>00106 ns_config * 
+<a name="l00107"></a>00107 sinfo_ns_cfg_create(<span class="keywordtype">void</span>);
+<a name="l00115"></a>00115 <span class="keywordtype">void</span> 
+<a name="l00116"></a>00116 sinfo_ns_cfg_destroy(ns_config * nc);
+<a name="l00117"></a>00117 
+<a name="l00118"></a>00118 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__ns__ini_8h_source.html b/html/sinfo__ns__ini_8h_source.html
new file mode 100644
index 0000000..732a642
--- /dev/null
+++ b/html/sinfo__ns__ini_8h_source.html
@@ -0,0 +1,67 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_ns_ini.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_ns_ini.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name    :   sinfo_ns_ini.h</span>
+<a name="l00022"></a>00022 <span class="comment">   Author       :    Juergen Schreiber</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on   :    Nov 29, 2001</span>
+<a name="l00024"></a>00024 <span class="comment">   Description  :    ini file handling for the north-south-test, that means</span>
+<a name="l00025"></a>00025 <span class="comment">                        the determination of the distances of the slitlets to </span>
+<a name="l00026"></a>00026 <span class="comment">                        each other.</span>
+<a name="l00027"></a>00027 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00028"></a>00028 <span class="preprocessor">#ifndef SINFO_NS_INI_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_NS_INI_H</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00031"></a>00031 <span class="comment">                                Includes</span>
+<a name="l00032"></a>00032 <span class="comment">---------------------------------------------------------------------------*/</span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00034"></a>00034 <span class="preprocessor">#include "sinfo_ns_cfg.h"</span>
+<a name="l00035"></a>00035 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00036"></a>00036 <span class="comment">                                Defines</span>
+<a name="l00037"></a>00037 <span class="comment">---------------------------------------------------------------------------*/</span>
+<a name="l00038"></a>00038 <span class="preprocessor">#define FRAME_ON   1     </span><span class="comment">/* object frames */</span>
+<a name="l00039"></a>00039 <span class="preprocessor">#define FRAME_OFF  0     </span><span class="comment">/* off frames */</span>
+<a name="l00040"></a>00040 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00041"></a>00041 <span class="comment">                             Function prototypes </span>
+<a name="l00042"></a>00042 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00057"></a>00057 <span class="keywordtype">int</span> generateNS_ini_file(
+<a name="l00058"></a>00058         <span class="keywordtype">char</span> * ini_name,
+<a name="l00059"></a>00059         <span class="keywordtype">char</span> * name_i,
+<a name="l00060"></a>00060         <span class="keywordtype">char</span> * name_o
+<a name="l00061"></a>00061 );
+<a name="l00062"></a>00062 
+<a name="l00074"></a>00074 ns_config * parse_ns_ini_file(<span class="keywordtype">char</span> * ini_name) ;
+<a name="l00075"></a>00075 
+<a name="l00076"></a>00076 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__ns__ini__by__cpl_8c_source.html b/html/sinfo__ns__ini__by__cpl_8c_source.html
new file mode 100644
index 0000000..1910e38
--- /dev/null
+++ b/html/sinfo__ns__ini__by__cpl_8c_source.html
@@ -0,0 +1,360 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_ns_ini_by_cpl.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_ns_ini_by_cpl.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 
+<a name="l00020"></a>00020 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00021"></a>00021 <span class="comment">   </span>
+<a name="l00022"></a>00022 <span class="comment">   File name    :   sinfo_ns_ini_by_cpl.c</span>
+<a name="l00023"></a>00023 <span class="comment">   Author       :   Andrea Modigliani</span>
+<a name="l00024"></a>00024 <span class="comment">   Created on   :   May 19, 2003</span>
+<a name="l00025"></a>00025 <span class="comment">   Description  :   cpl input handling for the north-south test</span>
+<a name="l00026"></a>00026 <span class="comment"></span>
+<a name="l00027"></a>00027 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00028"></a>00028 
+<a name="l00029"></a>00029 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00031"></a>00031 <span class="preprocessor">#endif</span>
+<a name="l00032"></a>00032 <span class="preprocessor"></span>
+<a name="l00033"></a>00033 
+<a name="l00034"></a>00034 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00035"></a>00035 <span class="comment">                                Includes</span>
+<a name="l00036"></a>00036 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00037"></a>00037 
+<a name="l00038"></a>00038 <span class="preprocessor">#include <string.h></span>
+<a name="l00039"></a>00039 <span class="preprocessor">#include "sinfo_ns_ini_by_cpl.h"</span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include "sinfo_pro_types.h"</span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include "sinfo_hidden.h"</span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include "sinfo_functions.h"</span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include "sinfo_file_handling.h"</span>
+<a name="l00044"></a>00044 
+<a name="l00045"></a>00045 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00046"></a>00046 <span class="comment">                    Functions private to this module</span>
+<a name="l00047"></a>00047 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00048"></a>00048 <span class="keywordtype">void</span> sinfo_ns_free_alloc(ns_config * cfg);
+<a name="l00049"></a>00049 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00050"></a>00050 parse_section_frames (ns_config *,cpl_parameterlist* cpl_cfg,cpl_frameset* sof,
+<a name="l00051"></a>00051                      cpl_frameset** raw, <span class="keywordtype">int</span>* status);
+<a name="l00052"></a>00052 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00053"></a>00053 parse_section_cleanmean (ns_config *,cpl_parameterlist* cpl_cfg);
+<a name="l00054"></a>00054 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00055"></a>00055 parse_section_gaussconvolution (ns_config *,cpl_parameterlist* cpl_cfg);
+<a name="l00056"></a>00056 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00057"></a>00057 parse_section_northsouthtest(ns_config *,cpl_parameterlist* cpl_cfg);
+<a name="l00058"></a>00058 
+<a name="l00059"></a>00059 
+<a name="l00069"></a>00069 <span class="comment">/* removed generateNS_ini_file */</span>
+<a name="l00070"></a>00070 
+<a name="l00071"></a>00071 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l00082"></a>00082 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00083"></a>00083 
+<a name="l00084"></a>00084 ns_config * 
+<a name="l00085"></a>00085 sinfo_parse_cpl_input_ns(cpl_parameterlist * cpl_cfg, cpl_frameset* sof, 
+<a name="l00086"></a>00086                    cpl_frameset** raw)
+<a name="l00087"></a>00087 {
+<a name="l00088"></a>00088         ns_config   *         cfg = sinfo_ns_cfg_create();
+<a name="l00089"></a>00089         <span class="keywordtype">int</span> status=0;
+<a name="l00090"></a>00090         <span class="comment">/*</span>
+<a name="l00091"></a>00091 <span class="comment">         * Perform sanity checks, fill up the structure with what was</span>
+<a name="l00092"></a>00092 <span class="comment">         * found in the ini file</span>
+<a name="l00093"></a>00093 <span class="comment">         */</span>
+<a name="l00094"></a>00094 
+<a name="l00095"></a>00095         parse_section_cleanmean        (cfg,cpl_cfg);
+<a name="l00096"></a>00096         parse_section_gaussconvolution (cfg,cpl_cfg);
+<a name="l00097"></a>00097         parse_section_northsouthtest   (cfg,cpl_cfg);
+<a name="l00098"></a>00098         parse_section_frames           (cfg,cpl_cfg,sof,raw,&status);
+<a name="l00099"></a>00099 
+<a name="l00100"></a>00100         <span class="keywordflow">if</span> (status > 0) {
+<a name="l00101"></a>00101                 <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"parsing cpl input"</span>);
+<a name="l00102"></a>00102                 sinfo_ns_cfg_destroy(cfg);
+<a name="l00103"></a>00103                 cfg = NULL ;
+<a name="l00104"></a>00104                 <span class="keywordflow">return</span> NULL ;
+<a name="l00105"></a>00105         }
+<a name="l00106"></a>00106         <span class="keywordflow">return</span> cfg ;
+<a name="l00107"></a>00107 }
+<a name="l00108"></a>00108 
+<a name="l00109"></a>00109 
+<a name="l00110"></a>00110 
+<a name="l00111"></a>00111 
+<a name="l00112"></a>00112 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00113"></a>00113 parse_section_frames(ns_config * cfg,
+<a name="l00114"></a>00114              cpl_parameterlist * cpl_cfg,
+<a name="l00115"></a>00115              cpl_frameset * sof,
+<a name="l00116"></a>00116              cpl_frameset ** raw,
+<a name="l00117"></a>00117                      <span class="keywordtype">int</span>* status)
+<a name="l00118"></a>00118 {
+<a name="l00119"></a>00119    <span class="keywordtype">int</span>                     i;
+<a name="l00120"></a>00120    <span class="keywordtype">int</span>                     nobj ;
+<a name="l00121"></a>00121    <span class="keywordtype">int</span>                     noff ;
+<a name="l00122"></a>00122     <span class="keywordtype">int</span> nraw=0;
+<a name="l00123"></a>00123    <span class="keywordtype">char</span>* tag;
+<a name="l00124"></a>00124    cpl_frame* frame   = NULL;
+<a name="l00125"></a>00125    cpl_parameter *p;   
+<a name="l00126"></a>00126   <span class="keywordtype">char</span> spat_res[FILE_NAME_SZ];
+<a name="l00127"></a>00127    <span class="keywordtype">char</span> lamp_status[FILE_NAME_SZ];
+<a name="l00128"></a>00128    <span class="keywordtype">char</span> band[FILE_NAME_SZ];
+<a name="l00129"></a>00129    <span class="keywordtype">int</span> ins_set=0;
+<a name="l00130"></a>00130    nstpar* nstp=sinfo_nstpar_new();
+<a name="l00131"></a>00131   
+<a name="l00132"></a>00132    sinfo_extract_raw_frames_type(sof,raw,PRO_FIBRE_NS_STACKED_DIST);
+<a name="l00133"></a>00133   
+<a name="l00134"></a>00134    nraw    = cpl_frameset_get_size(*raw);
+<a name="l00135"></a>00135 
+<a name="l00136"></a>00136     <span class="keywordflow">if</span>(nraw == 0) {
+<a name="l00137"></a>00137      <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"No input raw frames"</span>);
+<a name="l00138"></a>00138      sinfo_nstpar_delete(nstp);
+<a name="l00139"></a>00139      (*status)++;
+<a name="l00140"></a>00140      <span class="keywordflow">return</span>;
+<a name="l00141"></a>00141    }
+<a name="l00142"></a>00142 
+<a name="l00143"></a>00143    <span class="comment">/* Allocate structures to go into the blackboard */</span>
+<a name="l00144"></a>00144    cfg->framelist     = cpl_malloc(nraw * <span class="keyword">sizeof</span>(<span class="keywordtype">char</span>*));
+<a name="l00145"></a>00145    cfg->frametype     = cpl_malloc(nraw * <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>));
+<a name="l00146"></a>00146 
+<a name="l00147"></a>00147 
+<a name="l00148"></a>00148     
+<a name="l00149"></a>00149    <span class="comment">/* Browse through the charmatrix to get names and file types */</span>
+<a name="l00150"></a>00150    i=0 ;
+<a name="l00151"></a>00151    nobj = 0 ;
+<a name="l00152"></a>00152    noff = 0 ;
+<a name="l00153"></a>00153    
+<a name="l00154"></a>00154    <span class="keywordflow">for</span> (i=0 ; i<nraw ; i++) {
+<a name="l00155"></a>00155       frame = cpl_frameset_get_frame(*raw,i);
+<a name="l00156"></a>00156       <span class="keywordflow">if</span>(sinfo_file_exists((<span class="keywordtype">char</span>*) cpl_frame_get_filename(frame))==1) 
+<a name="l00157"></a>00157     {
+<a name="l00158"></a>00158       <span class="comment">/* to go on the file must exist */</span>
+<a name="l00159"></a>00159        tag=(<span class="keywordtype">char</span>*) cpl_frame_get_tag(frame);
+<a name="l00160"></a>00160       <span class="keywordflow">if</span>(cpl_frame_get_tag(frame) != NULL) {
+<a name="l00161"></a>00161         <span class="comment">/* If the frame has a tag we process it. Else it is an object */</span> 
+<a name="l00162"></a>00162             <span class="keywordflow">if</span>((sinfo_frame_is_on(frame)  == 0)) 
+<a name="l00163"></a>00163           {
+<a name="l00164"></a>00164             cfg->framelist[i]=(<span class="keywordtype">char</span>*) cpl_frame_get_filename(frame);
+<a name="l00165"></a>00165             cfg->frametype[i] = FRAME_OFF ;
+<a name="l00166"></a>00166             noff++;
+<a name="l00167"></a>00167           }
+<a name="l00168"></a>00168             <span class="keywordflow">else</span> <span class="keywordflow">if</span>(sinfo_is_sky_flat(tag))
+<a name="l00169"></a>00169           {
+<a name="l00170"></a>00170             cfg->framelist[i]=(<span class="keywordtype">char</span>*) cpl_frame_get_filename(frame);
+<a name="l00171"></a>00171             cfg->frametype[i] = FRAME_OFF ;
+<a name="l00172"></a>00172             noff++;
+<a name="l00173"></a>00173           }
+<a name="l00174"></a>00174             <span class="keywordflow">else</span> <span class="keywordflow">if</span>((sinfo_frame_is_on(frame)  == 1)) 
+<a name="l00175"></a>00175           {
+<a name="l00176"></a>00176             cfg->framelist[i]=(<span class="keywordtype">char</span>*) cpl_frame_get_filename(frame);
+<a name="l00177"></a>00177             cfg->frametype[i] = FRAME_ON ;
+<a name="l00178"></a>00178             nobj++;
+<a name="l00179"></a>00179           }
+<a name="l00180"></a>00180             <span class="keywordflow">else</span>  
+<a name="l00181"></a>00181               {
+<a name="l00182"></a>00182           <span class="comment">/* without label the frame is assumed on */</span>
+<a name="l00183"></a>00183           cfg->framelist[i]=(<span class="keywordtype">char</span>*) cpl_frame_get_filename(frame);
+<a name="l00184"></a>00184           cfg->frametype[i] = FRAME_ON ;
+<a name="l00185"></a>00185           nobj++;
+<a name="l00186"></a>00186         }
+<a name="l00187"></a>00187       }
+<a name="l00188"></a>00188         <span class="keywordflow">else</span> 
+<a name="l00189"></a>00189       {
+<a name="l00190"></a>00190         <span class="comment">/* without label the frame is assumed on */</span>
+<a name="l00191"></a>00191           cfg->framelist[i]=(<span class="keywordtype">char</span>*) cpl_frame_get_filename(frame);
+<a name="l00192"></a>00192           cfg->frametype[i] = FRAME_ON ;
+<a name="l00193"></a>00193           nobj++;
+<a name="l00194"></a>00194       }
+<a name="l00195"></a>00195        <span class="comment">/* Store file name into framelist */</span>
+<a name="l00196"></a>00196     }
+<a name="l00197"></a>00197       <span class="keywordflow">else</span> {
+<a name="l00198"></a>00198       <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"file %s does not exist"</span>,
+<a name="l00199"></a>00199           cpl_frame_get_filename(frame));
+<a name="l00200"></a>00200     }
+<a name="l00201"></a>00201         
+<a name="l00202"></a>00202     }
+<a name="l00203"></a>00203 
+<a name="l00204"></a>00204 
+<a name="l00205"></a>00205    <span class="keywordflow">if</span>((noff == 0) && (nobj == 0)) {
+<a name="l00206"></a>00206      <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Wrong input frames"</span>);
+<a name="l00207"></a>00207      sinfo_nstpar_delete(nstp);
+<a name="l00208"></a>00208      sinfo_ns_free_alloc(cfg);
+<a name="l00209"></a>00209      (*status)++;
+<a name="l00210"></a>00210      <span class="keywordflow">return</span>;
+<a name="l00211"></a>00211    }
+<a name="l00212"></a>00212    <span class="comment">/* Copy relevant information into the blackboard */</span>
+<a name="l00213"></a>00213    cfg->nframes         = nraw ;
+<a name="l00214"></a>00214    cfg->nobj            = nobj ;
+<a name="l00215"></a>00215    cfg->noff            = noff ;
+<a name="l00216"></a>00216 
+<a name="l00217"></a>00217    strcpy(cfg -> outName, NS_TEST_DISTANCES_OUT_FILENAME);
+<a name="l00218"></a>00218 
+<a name="l00219"></a>00219 
+<a name="l00220"></a>00220    frame = cpl_frameset_get_frame(*raw,0);
+<a name="l00221"></a>00221    sinfo_get_spatial_res(frame,spat_res);
+<a name="l00222"></a>00222  
+<a name="l00223"></a>00223    <span class="keywordflow">switch</span>(sinfo_frame_is_on(frame)) 
+<a name="l00224"></a>00224      {
+<a name="l00225"></a>00225    <span class="keywordflow">case</span> 0: 
+<a name="l00226"></a>00226       strcpy(lamp_status,<span class="stringliteral">"on"</span>);
+<a name="l00227"></a>00227       <span class="keywordflow">break</span>;
+<a name="l00228"></a>00228     <span class="keywordflow">case</span> 1: 
+<a name="l00229"></a>00229       strcpy(lamp_status,<span class="stringliteral">"off"</span>);
+<a name="l00230"></a>00230       <span class="keywordflow">break</span>;
+<a name="l00231"></a>00231     <span class="keywordflow">case</span> -1:
+<a name="l00232"></a>00232       strcpy(lamp_status,<span class="stringliteral">"undefined"</span>);
+<a name="l00233"></a>00233       <span class="keywordflow">break</span>;
+<a name="l00234"></a>00234     <span class="keywordflow">default</span>: 
+<a name="l00235"></a>00235       strcpy(lamp_status,<span class="stringliteral">"undefined"</span>);
+<a name="l00236"></a>00236       <span class="keywordflow">break</span>;
+<a name="l00237"></a>00237 
+<a name="l00238"></a>00238 
+<a name="l00239"></a>00239      }
+<a name="l00240"></a>00240 
+<a name="l00241"></a>00241    sinfo_get_band(frame,band);
+<a name="l00242"></a>00242    sinfo_msg(<span class="stringliteral">"Spatial resolution: %s lamp_status: %s band: %s \n"</span>,
+<a name="l00243"></a>00243                      spat_res,    lamp_status,    band);
+<a name="l00244"></a>00244 
+<a name="l00245"></a>00245 
+<a name="l00246"></a>00246    sinfo_get_ins_set(band,&ins_set);
+<a name="l00247"></a>00247 
+<a name="l00248"></a>00248 
+<a name="l00249"></a>00249    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.north_south_test.fwhm"</span>);
+<a name="l00250"></a>00250    <span class="keywordflow">if</span>(cpl_parameter_get_double(p) != cpl_parameter_get_default_double(p)) {
+<a name="l00251"></a>00251      cfg -> fwhm = cpl_parameter_get_double(p);
+<a name="l00252"></a>00252    } <span class="keywordflow">else</span> {
+<a name="l00253"></a>00253      cfg -> fwhm = nstp->fwhm[ins_set];
+<a name="l00254"></a>00254    }
+<a name="l00255"></a>00255 
+<a name="l00256"></a>00256    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.north_south_test.min_diff"</span>);
+<a name="l00257"></a>00257    <span class="keywordflow">if</span>(cpl_parameter_get_double(p) != cpl_parameter_get_default_double(p)) {
+<a name="l00258"></a>00258      cfg -> minDiff = cpl_parameter_get_double(p);
+<a name="l00259"></a>00259    } <span class="keywordflow">else</span> {
+<a name="l00260"></a>00260      cfg -> minDiff = nstp->min_dif[ins_set];
+<a name="l00261"></a>00261    }
+<a name="l00262"></a>00262     sinfo_nstpar_delete(nstp);
+<a name="l00263"></a>00263 
+<a name="l00264"></a>00264 
+<a name="l00265"></a>00265    <span class="keywordflow">if</span>(cfg -> maskInd) {
+<a name="l00266"></a>00266       <span class="keywordflow">if</span>(NULL != cpl_frameset_find(sof,PRO_BP_MAP_DI)) {
+<a name="l00267"></a>00267          frame = cpl_frameset_find(sof,PRO_BP_MAP_DI);
+<a name="l00268"></a>00268          strcpy(cfg -> mask,cpl_frame_get_filename(frame));
+<a name="l00269"></a>00269       } <span class="keywordflow">else</span> {
+<a name="l00270"></a>00270          <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Frame %s not found! Exit!"</span>, PRO_BP_MAP_DI);
+<a name="l00271"></a>00271          sinfo_ns_free_alloc(cfg);
+<a name="l00272"></a>00272          (*status)++;
+<a name="l00273"></a>00273          <span class="keywordflow">return</span>;
+<a name="l00274"></a>00274       }
+<a name="l00275"></a>00275    }
+<a name="l00276"></a>00276 
+<a name="l00277"></a>00277  
+<a name="l00278"></a>00278      return ;
+<a name="l00279"></a>00279 }
+<a name="l00280"></a>00280 
+<a name="l00281"></a>00281 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00282"></a>00282 parse_section_cleanmean(ns_config * cfg,cpl_parameterlist * cpl_cfg)
+<a name="l00283"></a>00283 {
+<a name="l00284"></a>00284 
+<a name="l00285"></a>00285    cpl_parameter *p;                  
+<a name="l00286"></a>00286    p = cpl_parameterlist_find(cpl_cfg, 
+<a name="l00287"></a>00287                              <span class="stringliteral">"sinfoni.north_south_test.low_rejection"</span>);
+<a name="l00288"></a>00288    cfg -> loReject = cpl_parameter_get_double(p);
+<a name="l00289"></a>00289 
+<a name="l00290"></a>00290    p = cpl_parameterlist_find(cpl_cfg, 
+<a name="l00291"></a>00291                               <span class="stringliteral">"sinfoni.north_south_test.high_rejection"</span>);
+<a name="l00292"></a>00292    cfg -> hiReject = cpl_parameter_get_double(p);
+<a name="l00293"></a>00293 
+<a name="l00294"></a>00294    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.north_south_test.mask_ind"</span>);
+<a name="l00295"></a>00295    cfg -> maskInd = cpl_parameter_get_bool(p);
+<a name="l00296"></a>00296 
+<a name="l00297"></a>00297    return ;
+<a name="l00298"></a>00298 }
+<a name="l00299"></a>00299 
+<a name="l00300"></a>00300 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00301"></a>00301 parse_section_gaussconvolution(ns_config * cfg,cpl_parameterlist * cpl_cfg)
+<a name="l00302"></a>00302 {
+<a name="l00303"></a>00303    cpl_parameter *p;     
+<a name="l00304"></a>00304    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.north_south_test.gauss_ind"</span>);
+<a name="l00305"></a>00305    cfg -> gaussInd = cpl_parameter_get_bool(p);
+<a name="l00306"></a>00306 
+<a name="l00307"></a>00307    p = cpl_parameterlist_find(cpl_cfg, 
+<a name="l00308"></a>00308                               <span class="stringliteral">"sinfoni.north_south_test.kernel_half_width"</span>);
+<a name="l00309"></a>00309    cfg -> hw = cpl_parameter_get_int(p);
+<a name="l00310"></a>00310 
+<a name="l00311"></a>00311 }
+<a name="l00312"></a>00312 
+<a name="l00313"></a>00313 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00314"></a>00314 parse_section_northsouthtest(ns_config  * cfg,cpl_parameterlist * cpl_cfg)
+<a name="l00315"></a>00315 {
+<a name="l00316"></a>00316 
+<a name="l00317"></a>00317    cpl_parameter *p;     
+<a name="l00318"></a>00318    strcat(cfg -> fitsname, NS_TEST_OUT_FILENAME);
+<a name="l00319"></a>00319    cfg -> nslits = NSLITLETS;
+<a name="l00320"></a>00320 
+<a name="l00321"></a>00321    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.north_south_test.half_width"</span>);
+<a name="l00322"></a>00322    cfg -> halfWidth = cpl_parameter_get_int(p);
+<a name="l00323"></a>00323 
+<a name="l00324"></a>00324    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.north_south_test.fwhm"</span>);
+<a name="l00325"></a>00325    cfg -> fwhm = cpl_parameter_get_double(p);
+<a name="l00326"></a>00326 
+<a name="l00327"></a>00327    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.north_south_test.min_diff"</span>);
+<a name="l00328"></a>00328    cfg -> minDiff = cpl_parameter_get_double(p);
+<a name="l00329"></a>00329 
+<a name="l00330"></a>00330    cfg -> estimated_dist = ESTIMATED_SLITLETS_DISTANCE;
+<a name="l00331"></a>00331 
+<a name="l00332"></a>00332    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.north_south_test.dev_tol"</span>);
+<a name="l00333"></a>00333    cfg -> devtol = cpl_parameter_get_double(p);
+<a name="l00334"></a>00334 
+<a name="l00335"></a>00335    return ;
+<a name="l00336"></a>00336 }
+<a name="l00337"></a>00337 
+<a name="l00338"></a>00338 <span class="keywordtype">void</span>
+<a name="l00339"></a>00339 sinfo_ns_free(ns_config ** cfg)
+<a name="l00340"></a>00340 {  
+<a name="l00341"></a>00341   <span class="keywordflow">if</span>(*cfg!=NULL) { 
+<a name="l00342"></a>00342     sinfo_ns_free_alloc(*cfg);
+<a name="l00343"></a>00343     sinfo_ns_cfg_destroy(*cfg);
+<a name="l00344"></a>00344     *cfg=NULL;
+<a name="l00345"></a>00345   } 
+<a name="l00346"></a>00346   <span class="keywordflow">return</span>;
+<a name="l00347"></a>00347 
+<a name="l00348"></a>00348 }
+<a name="l00349"></a>00349 <span class="keywordtype">void</span>
+<a name="l00350"></a>00350 sinfo_ns_free_alloc(ns_config * cfg)
+<a name="l00351"></a>00351 {
+<a name="l00352"></a>00352     <span class="keywordflow">if</span>(cfg->framelist != NULL) {
+<a name="l00353"></a>00353       cpl_free(cfg->framelist);
+<a name="l00354"></a>00354       cfg->framelist=NULL;
+<a name="l00355"></a>00355     }
+<a name="l00356"></a>00356     <span class="keywordflow">if</span>(cfg->frametype != NULL) {
+<a name="l00357"></a>00357       cpl_free(cfg->frametype);
+<a name="l00358"></a>00358       cfg->frametype=NULL;
+<a name="l00359"></a>00359     }
+<a name="l00360"></a>00360   
+<a name="l00361"></a>00361   <span class="keywordflow">return</span>;
+<a name="l00362"></a>00362 
+<a name="l00363"></a>00363 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__ns__ini__by__cpl_8h_source.html b/html/sinfo__ns__ini__by__cpl_8h_source.html
new file mode 100644
index 0000000..6f9786f
--- /dev/null
+++ b/html/sinfo__ns__ini__by__cpl_8h_source.html
@@ -0,0 +1,67 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_ns_ini_by_cpl.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_ns_ini_by_cpl.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name    :   sinfo_ns_ini.h</span>
+<a name="l00022"></a>00022 <span class="comment">   Author       :   Andrea Modigliani</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on   :   May 19, 2004</span>
+<a name="l00024"></a>00024 <span class="comment">   Description  :    parse cpl input for the north-south-test, that means</span>
+<a name="l00025"></a>00025 <span class="comment">                        the determination of the distances of the slitlets to </span>
+<a name="l00026"></a>00026 <span class="comment">                        each other.</span>
+<a name="l00027"></a>00027 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00028"></a>00028 <span class="preprocessor">#ifndef SINFO_NS_INI_BY_CPL_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_NS_INI_BY_CPL_H</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00031"></a>00031 <span class="comment">                                Includes</span>
+<a name="l00032"></a>00032 <span class="comment">---------------------------------------------------------------------------*/</span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00034"></a>00034 <span class="preprocessor">#include "sinfo_ns_cfg.h"</span>
+<a name="l00035"></a>00035 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00036"></a>00036 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00037"></a>00037 <span class="comment">                                Defines</span>
+<a name="l00038"></a>00038 <span class="comment">---------------------------------------------------------------------------*/</span>
+<a name="l00039"></a>00039 <span class="preprocessor">#define FRAME_ON   1     </span><span class="comment">/* object frames */</span>
+<a name="l00040"></a>00040 <span class="preprocessor">#define FRAME_OFF  0     </span><span class="comment">/* off frames */</span>
+<a name="l00041"></a>00041 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00042"></a>00042 <span class="comment">                             Function prototypes </span>
+<a name="l00043"></a>00043 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00056"></a>00056 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00057"></a>00057 
+<a name="l00058"></a>00058 ns_config * 
+<a name="l00059"></a>00059 sinfo_parse_cpl_input_ns(cpl_parameterlist * cpl_cfg, 
+<a name="l00060"></a>00060                          cpl_frameset* sof, 
+<a name="l00061"></a>00061              cpl_frameset** raw);
+<a name="l00068"></a>00068 <span class="keywordtype">void</span> sinfo_ns_free(ns_config ** cfg);
+<a name="l00069"></a>00069 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__object__cfg_8c_source.html b/html/sinfo__object__cfg_8c_source.html
new file mode 100644
index 0000000..e53bbeb
--- /dev/null
+++ b/html/sinfo__object__cfg_8c_source.html
@@ -0,0 +1,91 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_object_cfg.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_object_cfg.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 
+<a name="l00020"></a>00020 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00021"></a>00021 <span class="comment">   </span>
+<a name="l00022"></a>00022 <span class="comment">   File name     :   sinfo_object_cfg.c</span>
+<a name="l00023"></a>00023 <span class="comment">   Author     :   Juergen Schreiber</span>
+<a name="l00024"></a>00024 <span class="comment">   Created on    :   April 2002</span>
+<a name="l00025"></a>00025 <span class="comment">   Description    :   configuration handling tools for the creation of an object</span>
+<a name="l00026"></a>00026 <span class="comment">                    data cube</span>
+<a name="l00027"></a>00027 <span class="comment"></span>
+<a name="l00028"></a>00028 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00029"></a>00029 
+<a name="l00030"></a>00030 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00032"></a>00032 <span class="preprocessor">#endif</span>
+<a name="l00033"></a>00033 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00034"></a>00034 <span class="comment">                                   Includes</span>
+<a name="l00035"></a>00035 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="preprocessor">#include "sinfo_object_cfg.h"</span>
+<a name="l00038"></a>00038 
+<a name="l00039"></a>00039 
+<a name="l00040"></a>00040 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00041"></a>00041 <span class="comment">                              Function codes</span>
+<a name="l00042"></a>00042 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00050"></a>00050 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00051"></a>00051 <span class="comment">   Function :   sinfo_object_cfg_create()</span>
+<a name="l00052"></a>00052 <span class="comment">   In       :   void</span>
+<a name="l00053"></a>00053 <span class="comment">   Out      :   pointer to allocated base object_config structure</span>
+<a name="l00054"></a>00054 <span class="comment">   Job      :   allocate memory for an object_config struct</span>
+<a name="l00055"></a>00055 <span class="comment">   Notice   :   only the main (base) structure is allocated</span>
+<a name="l00056"></a>00056 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00057"></a>00057 
+<a name="l00058"></a>00058 object_config * sinfo_object_cfg_create(<span class="keywordtype">void</span>)
+<a name="l00059"></a>00059 {
+<a name="l00060"></a>00060     <span class="keywordflow">return</span> cpl_calloc(1, <span class="keyword">sizeof</span>(object_config));
+<a name="l00061"></a>00061 }
+<a name="l00062"></a>00062 
+<a name="l00063"></a>00063 
+<a name="l00064"></a>00064 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00065"></a>00065 <span class="comment">   Function :   sinfo_object_cfg_destroy()</span>
+<a name="l00066"></a>00066 <span class="comment">   In       :   object_config to deallocate</span>
+<a name="l00067"></a>00067 <span class="comment">   Out      :   void</span>
+<a name="l00068"></a>00068 <span class="comment">   Job      :   deallocate all memory associated with an </span>
+<a name="l00069"></a>00069 <span class="comment">                object_config data structure</span>
+<a name="l00070"></a>00070 <span class="comment">   Notice   :   </span>
+<a name="l00071"></a>00071 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00072"></a>00072 
+<a name="l00073"></a>00073 <span class="keywordtype">void</span> sinfo_object_cfg_destroy(object_config * cc)
+<a name="l00074"></a>00074 {
+<a name="l00075"></a>00075     <span class="keywordflow">if</span> (cc==NULL) return ;
+<a name="l00076"></a>00076 
+<a name="l00077"></a>00077     <span class="comment">/* Free main struct */</span>
+<a name="l00078"></a>00078     cpl_free(cc);
+<a name="l00079"></a>00079 
+<a name="l00080"></a>00080     return ;
+<a name="l00081"></a>00081 }
+<a name="l00082"></a>00082 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__object__cfg_8h_source.html b/html/sinfo__object__cfg_8h_source.html
new file mode 100644
index 0000000..a5d5ecb
--- /dev/null
+++ b/html/sinfo__object__cfg_8h_source.html
@@ -0,0 +1,162 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_object_cfg.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_object_cfg.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment"></span>
+<a name="l00021"></a>00021 <span class="comment">   File name     :    sinfo_object_cfg.h</span>
+<a name="l00022"></a>00022 <span class="comment">   Author    :    Juergen Schreiber</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on    :    April 2002</span>
+<a name="l00024"></a>00024 <span class="comment">   Description    :    object_ini definitions + handling prototypes</span>
+<a name="l00025"></a>00025 <span class="comment"></span>
+<a name="l00026"></a>00026 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00027"></a>00027 <span class="preprocessor">#ifndef SINFO_OBJECT_CFG_H</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_OBJECT_CFG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00030"></a>00030 <span class="comment">                                   Includes</span>
+<a name="l00031"></a>00031 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00032"></a>00032 <span class="preprocessor">#include <stdlib.h></span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include "sinfo_globals.h"</span>
+<a name="l00034"></a>00034 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00035"></a>00035 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00036"></a>00036 <span class="comment">                                   Defines</span>
+<a name="l00037"></a>00037 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00038"></a>00038 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00039"></a>00039 <span class="comment">                                   New types</span>
+<a name="l00040"></a>00040 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00041"></a>00041 <span class="comment">/*</span>
+<a name="l00042"></a>00042 <span class="comment">  data cube creation blackboard container</span>
+<a name="l00043"></a>00043 <span class="comment"></span>
+<a name="l00044"></a>00044 <span class="comment">  This structure holds all information related to the object</span>
+<a name="l00045"></a>00045 <span class="comment">  data cube creation routine. It is used as a container for the</span>
+<a name="l00046"></a>00046 <span class="comment">  flux of ancillary data, computed values, and algorithm status.</span>
+<a name="l00047"></a>00047 <span class="comment">  Pixel flux is separated from the blackboard.</span>
+<a name="l00048"></a>00048 <span class="comment">  */</span>
+<a name="l00049"></a>00049 
+<a name="l00050"></a>00050 <span class="keyword">typedef</span> <span class="keyword">struct </span>object_config {
+<a name="l00051"></a>00051 <span class="comment">/*-------General---------*/</span>
+<a name="l00052"></a>00052    <span class="keywordtype">char</span> inFile[FILE_NAME_SZ]  ; <span class="comment">/* input file of reduced jittered</span>
+<a name="l00053"></a>00053 <span class="comment">                                        data cubes of a standard star */</span>
+<a name="l00054"></a>00054    <span class="keywordtype">char</span> ** framelist ; <span class="comment">/* input averaged, bad pixel corrected, sky</span>
+<a name="l00055"></a>00055 <span class="comment">                               subtracted, flatfielded and interleaved</span>
+<a name="l00056"></a>00056 <span class="comment">                               jittered frame list */</span>
+<a name="l00057"></a>00057    <span class="keywordtype">char</span> wavemap[FILE_NAME_SZ] ; <span class="comment">/* input wavelength calibration map */</span>
+<a name="l00058"></a>00058    <span class="keywordtype">char</span> mflat[FILE_NAME_SZ] ;   <span class="comment">/* input master flat field  */</span>
+<a name="l00059"></a>00059    <span class="keywordtype">char</span> outName[FILE_NAME_SZ] ; <span class="comment">/* output name of resulting fits</span>
+<a name="l00060"></a>00060 <span class="comment">                                        data cube(s) */</span>
+<a name="l00061"></a>00061    <span class="keywordtype">char</span> sky_dist[FILE_NAME_SZ] ; <span class="comment">/* master flat corrected for distortion */</span>
+<a name="l00062"></a>00062    <span class="keywordtype">char</span> mflat_dist[FILE_NAME_SZ] ; <span class="comment">/* master flat corrected for distortion */</span>
+<a name="l00063"></a>00063    <span class="keywordtype">char</span> mflat_dither_dist[FILE_NAME_SZ] ; <span class="comment">/* master flat dithered</span>
+<a name="l00064"></a>00064 <span class="comment">                                                  corrected for distortion */</span>
+<a name="l00065"></a>00065    <span class="keywordtype">int</span>     nframes ; <span class="comment">/* number of jittered frames */</span>
+<a name="l00066"></a>00066 
+<a name="l00067"></a>00067 <span class="comment">/*------ jittering ------*/</span>
+<a name="l00068"></a>00068    <span class="comment">/* jitter mode indicator: 0 for user jittering mode,</span>
+<a name="l00069"></a>00069 <span class="comment">           1 for auto jittering mode */</span>
+<a name="l00070"></a>00070    <span class="keywordtype">int</span> jitterind ;
+<a name="l00071"></a>00071    <span class="comment">/* x-pixel size of the final combined data cube */</span>
+<a name="l00072"></a>00072    <span class="keywordtype">int</span> size_x ;
+<a name="l00073"></a>00073    <span class="comment">/* y-pixel size of the final combined data cube */</span>
+<a name="l00074"></a>00074    <span class="keywordtype">int</span> size_y ;
+<a name="l00075"></a>00075    <span class="comment">/* the name of the interpolation kernel */</span>
+<a name="l00076"></a>00076    <span class="keywordtype">char</span> kernel_type[FILE_NAME_SZ] ;
+<a name="l00077"></a>00077    <span class="comment">/* the name of the final image sinfo_median of cube */</span>
+<a name="l00078"></a>00078    <span class="keywordtype">char</span> med_cube_name[FILE_NAME_SZ] ;
+<a name="l00079"></a>00079    <span class="comment">/* the name of the final mask cube */</span>
+<a name="l00080"></a>00080    <span class="keywordtype">char</span> maskname[FILE_NAME_SZ] ;
+<a name="l00081"></a>00081    <span class="comment">/* the name of the fits file with the polynom for the shift</span>
+<a name="l00082"></a>00082 <span class="comment">    * due atmospheric refraction */</span>
+<a name="l00083"></a>00083    <span class="keywordtype">char</span> polyshiftname[FILE_NAME_SZ] ;
+<a name="l00084"></a>00084 
+<a name="l00085"></a>00085 <span class="comment">/*------ Resampling ------*/</span>
+<a name="l00086"></a>00086    <span class="comment">/* number of coefficients for the polynomial</span>
+<a name="l00087"></a>00087 <span class="comment">   interpolation (order + 1) */</span>
+<a name="l00088"></a>00088    <span class="keywordtype">int</span> ncoeffs ;
+<a name="l00089"></a>00089    <span class="comment">/* number of rows in the resulting resampled</span>
+<a name="l00090"></a>00090 <span class="comment">           image = number of spectral bins */</span>
+<a name="l00091"></a>00091    <span class="keywordtype">int</span> nrows ;
+<a name="l00092"></a>00092 
+<a name="l00093"></a>00093 <span class="comment">/*------ Calibration ------*/</span>
+<a name="l00094"></a>00094    <span class="comment">/* indicates if the halogen lamp feature from</span>
+<a name="l00095"></a>00095 <span class="comment">           flatfielding should be corrected for or not */</span>
+<a name="l00096"></a>00096    <span class="keywordtype">int</span> halocorrectInd ;
+<a name="l00097"></a>00097    <span class="comment">/* name of the fits file of the calibrated halogen lamp spectrum */</span>
+<a name="l00098"></a>00098    <span class="keywordtype">char</span> halospectrum[FILE_NAME_SZ] ;
+<a name="l00099"></a>00099 
+<a name="l00100"></a>00100 <span class="comment">/*------ CubeCreation ------*/</span>
+<a name="l00101"></a>00101    <span class="comment">/* indicates if the slitlet distances are determined</span>
+<a name="l00102"></a>00102 <span class="comment">           by a north-south test (1)</span>
+<a name="l00103"></a>00103 <span class="comment">           or slitlet edge fits (0) */</span>
+<a name="l00104"></a>00104    <span class="keywordtype">int</span> northsouthInd  ;
+<a name="l00105"></a>00105    <span class="comment">/* name of the ASCII list of the distances of the slitlets */</span>
+<a name="l00106"></a>00106    <span class="keywordtype">char</span> distlist[FILE_NAME_SZ] ;
+<a name="l00107"></a>00107    <span class="comment">/* name of the ASCII list of the fitted slitlet sinfo_edge positions */</span>
+<a name="l00108"></a>00108    <span class="keywordtype">char</span> poslist[FILE_NAME_SZ] ;
+<a name="l00109"></a>00109    <span class="comment">/* number of slitlets (32) */</span>
+<a name="l00110"></a>00110    <span class="keywordtype">int</span> nslits ;
+<a name="l00111"></a>00111    <span class="comment">/* sub pixel position of the column position of the left sinfo_edge of</span>
+<a name="l00112"></a>00112 <span class="comment">           the first slitlet needed if the slitlet distances were determined</span>
+<a name="l00113"></a>00113 <span class="comment">           by a north south test */</span>
+<a name="l00114"></a>00114    <span class="keywordtype">char</span> firstCol[FILE_NAME_SZ] ;
+<a name="l00115"></a>00115 
+<a name="l00116"></a>00116 <span class="comment">/*------ FineTuning ------*/</span>
+<a name="l00117"></a>00117    <span class="comment">/* indicator for the shifting method to use */</span>
+<a name="l00118"></a>00118    <span class="keywordtype">char</span>  method[FILE_NAME_SZ] ;
+<a name="l00119"></a>00119    <span class="comment">/* order of polynomial if the polynomial interpolation shifting</span>
+<a name="l00120"></a>00120 <span class="comment">           method is used */</span>
+<a name="l00121"></a>00121    <span class="keywordtype">int</span> order ;
+<a name="l00122"></a>00122 
+<a name="l00123"></a>00123 <span class="comment">/*------ SkyExtraction ------*/</span>
+<a name="l00124"></a>00124    <span class="comment">/* percentage of rejected low value pixels when averaging the</span>
+<a name="l00125"></a>00125 <span class="comment">           sky spectra */</span>
+<a name="l00126"></a>00126    <span class="keywordtype">float</span>  loReject ;
+<a name="l00127"></a>00127    <span class="comment">/* percentage of rejected high value pixels when averaging the</span>
+<a name="l00128"></a>00128 <span class="comment">           sky spectra */</span>
+<a name="l00129"></a>00129    <span class="keywordtype">float</span>  hiReject ;
+<a name="l00130"></a>00130    <span class="comment">/* pixel distance tolerance to the dividing diagonal line,</span>
+<a name="l00131"></a>00131 <span class="comment">           these pixels are not considered to be sure to get only</span>
+<a name="l00132"></a>00132 <span class="comment">           "clean" sky pixels */</span>
+<a name="l00133"></a>00133    <span class="keywordtype">int</span>    tolerance ;
+<a name="l00134"></a>00134 } object_config ;
+<a name="l00135"></a>00135 
+<a name="l00136"></a>00136 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00137"></a>00137 <span class="comment">                               Function prototypes</span>
+<a name="l00138"></a>00138 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00146"></a>00146 object_config *
+<a name="l00147"></a>00147 sinfo_object_cfg_create(<span class="keywordtype">void</span>);
+<a name="l00148"></a>00148 
+<a name="l00149"></a>00149 
+<a name="l00156"></a>00156 <span class="keywordtype">void</span>
+<a name="l00157"></a>00157 sinfo_object_cfg_destroy(object_config * cc);
+<a name="l00158"></a>00158 
+<a name="l00159"></a>00159 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__object__ini_8h_source.html b/html/sinfo__object__ini_8h_source.html
new file mode 100644
index 0000000..376eb93
--- /dev/null
+++ b/html/sinfo__object__ini_8h_source.html
@@ -0,0 +1,63 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_object_ini.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_object_ini.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name    :   sinfo_object_ini.h</span>
+<a name="l00022"></a>00022 <span class="comment">   Author       :    Juergen Schreiber</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on   :    April 03, 2002</span>
+<a name="l00024"></a>00024 <span class="comment">   Description  :    ini file handling for SPIFFIs creation of a data cube</span>
+<a name="l00025"></a>00025 <span class="comment">                        from a science object observation</span>
+<a name="l00026"></a>00026 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00027"></a>00027 <span class="preprocessor">#ifndef SINFO_OBJECT_INI_H</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_OBJECT_INI_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00030"></a>00030 <span class="comment">                                Includes</span>
+<a name="l00031"></a>00031 <span class="comment">---------------------------------------------------------------------------*/</span>
+<a name="l00032"></a>00032 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include "sinfo_object_cfg.h"</span>
+<a name="l00034"></a>00034 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00035"></a>00035 <span class="comment">                             Function prototypes </span>
+<a name="l00036"></a>00036 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00054"></a>00054 <span class="keywordtype">int</span> generateObject_ini_file(
+<a name="l00055"></a>00055         <span class="keywordtype">char</span> * ini_name,
+<a name="l00056"></a>00056         <span class="keywordtype">char</span> * name_i,
+<a name="l00057"></a>00057         <span class="keywordtype">char</span> * name_o,
+<a name="l00058"></a>00058         <span class="keywordtype">char</span> * name_c
+<a name="l00059"></a>00059 );
+<a name="l00060"></a>00060 
+<a name="l00072"></a>00072 object_config * 
+<a name="l00073"></a>00073 parse_object_ini_file(<span class="keywordtype">char</span> * ini_name) ;
+<a name="l00074"></a>00074 
+<a name="l00075"></a>00075 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__objnod__config_8c_source.html b/html/sinfo__objnod__config_8c_source.html
new file mode 100644
index 0000000..6fe3e2f
--- /dev/null
+++ b/html/sinfo__objnod__config_8c_source.html
@@ -0,0 +1,414 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_objnod_config.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_objnod_config.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_objnod_config.c,v 1.11 2012/03/03 09:50:08 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the CPL (Common Pipeline Library)</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
+<a name="l00007"></a>00007 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span>
+<a name="l00008"></a>00008 <span class="comment"> * License as published by the Free Software Foundation; either</span>
+<a name="l00009"></a>00009 <span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
+<a name="l00014"></a>00014 <span class="comment"> * Lesser General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
+<a name="l00017"></a>00017 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2012/03/03 09:50:08 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.11 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> */</span>
+<a name="l00026"></a>00026 
+<a name="l00027"></a>00027  <span class="comment">/****************************************************************</span>
+<a name="l00028"></a>00028 <span class="comment">  *   Objnod Frames Data Reduction Parameter Initialization        *</span>
+<a name="l00029"></a>00029 <span class="comment">  ****************************************************************/</span>
+<a name="l00030"></a>00030 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00032"></a>00032 <span class="preprocessor">#endif</span>
+<a name="l00033"></a>00033 <span class="preprocessor"></span>
+<a name="l00034"></a>00034 <span class="preprocessor">#include "sinfo_objnod_config.h"</span>
+<a name="l00048"></a>00048 <span class="keywordtype">void</span>
+<a name="l00049"></a>00049  sinfo_objnod_config_add(cpl_parameterlist *list)
+<a name="l00050"></a>00050 {
+<a name="l00051"></a>00051 
+<a name="l00052"></a>00052   cpl_parameter *p;
+<a name="l00053"></a>00053 
+<a name="l00054"></a>00054   <span class="keywordflow">if</span> (!list) {
+<a name="l00055"></a>00055     <span class="keywordflow">return</span>;
+<a name="l00056"></a>00056   }
+<a name="l00057"></a>00057 
+<a name="l00058"></a>00058 
+<a name="l00059"></a>00059 
+<a name="l00060"></a>00060 
+<a name="l00061"></a>00061   <span class="comment">/* Science */</span>
+<a name="l00062"></a>00062   p = cpl_parameter_new_enum(<span class="stringliteral">"sinfoni.objnod.autojitter_method"</span>,
+<a name="l00063"></a>00063                   CPL_TYPE_INT,
+<a name="l00064"></a>00064                               <span class="stringliteral">"Method to reduce autojitter template frames "</span>
+<a name="l00065"></a>00065                               <span class="stringliteral">"Raw frames are object only exposures. "</span>
+<a name="l00066"></a>00066                               <span class="stringliteral">"object-fake_sky pairs are generated. "</span>
+<a name="l00067"></a>00067                               <span class="stringliteral">"0: no sky for all objects "</span>,
+<a name="l00068"></a>00068                               <span class="stringliteral">"1: fake_sky is next object, "</span>
+<a name="l00069"></a>00069                               <span class="stringliteral">"2: fake_sky is sinfo_median of all objects "</span>
+<a name="l00070"></a>00070                               <span class="stringliteral">"sinfoni.objnod"</span>,
+<a name="l00071"></a>00071                                1,3,0,1,2);
+<a name="l00072"></a>00072 
+<a name="l00073"></a>00073   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"objnod-aj_method"</span>);
+<a name="l00074"></a>00074   cpl_parameterlist_append(list, p);
+<a name="l00075"></a>00075 
+<a name="l00076"></a>00076 
+<a name="l00077"></a>00077   <span class="comment">/* Science */</span>
+<a name="l00078"></a>00078   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.objnod.scales_sky"</span>,
+<a name="l00079"></a>00079                   CPL_TYPE_BOOL,
+<a name="l00080"></a>00080                               <span class="stringliteral">"Spatial median (sky) subtraction from cube: "</span>
+<a name="l00081"></a>00081                               <span class="stringliteral">"(If autojitter_method==1),"</span>
+<a name="l00082"></a>00082                               <span class="stringliteral">"indicates if the spatial median of each plane "</span>
+<a name="l00083"></a>00083                               <span class="stringliteral">"should be subtracted (TRUE) or not (FALSE) "</span>
+<a name="l00084"></a>00084                               <span class="stringliteral">"from each cube plane"</span>,
+<a name="l00085"></a>00085                               <span class="stringliteral">"sinfoni.objnod"</span>,
+<a name="l00086"></a>00086                               FALSE);
+<a name="l00087"></a>00087 
+<a name="l00088"></a>00088   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"objnod-scales_sky"</span>);
+<a name="l00089"></a>00089   cpl_parameterlist_append(list, p);
+<a name="l00090"></a>00090 
+<a name="l00091"></a>00091 
+<a name="l00092"></a>00092 
+<a name="l00093"></a>00093   <span class="comment">/* Science */</span>
+<a name="l00094"></a>00094   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.objnod.ks_clip"</span>,
+<a name="l00095"></a>00095                   CPL_TYPE_BOOL,
+<a name="l00096"></a>00096                               <span class="stringliteral">"Kappa-sigma clipping of coadded cube: "</span>
+<a name="l00097"></a>00097                               <span class="stringliteral">"indicates if a kappa-sigma clipping "</span>
+<a name="l00098"></a>00098                               <span class="stringliteral">"should be performed (TRUE) or not (FALSE) "</span>
+<a name="l00099"></a>00099                               <span class="stringliteral">"on each plane of the coadded cube"</span>,
+<a name="l00100"></a>00100                               <span class="stringliteral">"sinfoni.objnod"</span>,
+<a name="l00101"></a>00101                               TRUE);
+<a name="l00102"></a>00102 
+<a name="l00103"></a>00103   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"objnod-ks_clip"</span>);
+<a name="l00104"></a>00104   cpl_parameterlist_append(list, p);
+<a name="l00105"></a>00105 
+<a name="l00106"></a>00106 
+<a name="l00107"></a>00107   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.objnod.kappa"</span>,
+<a name="l00108"></a>00108                   CPL_TYPE_DOUBLE,
+<a name="l00109"></a>00109                               <span class="stringliteral">"kappa value for kappa-sigma clipping "</span>
+<a name="l00110"></a>00110                               <span class="stringliteral">"of coadded cube"</span>,
+<a name="l00111"></a>00111                               <span class="stringliteral">"sinfoni.objnod"</span>,
+<a name="l00112"></a>00112                               2.0);
+<a name="l00113"></a>00113 
+<a name="l00114"></a>00114   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"objnod-kappa"</span>);
+<a name="l00115"></a>00115   cpl_parameterlist_append(list, p);
+<a name="l00116"></a>00116 
+<a name="l00117"></a>00117 
+<a name="l00118"></a>00118 
+<a name="l00119"></a>00119   <span class="comment">/*x-pixel size of the final combined data cube, must lie between 64 and 128 */</span>
+<a name="l00120"></a>00120   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.objnod.size_x"</span>,
+<a name="l00121"></a>00121                   CPL_TYPE_INT,
+<a name="l00122"></a>00122                               <span class="stringliteral">"Cube x size: "</span>
+<a name="l00123"></a>00123                               <span class="stringliteral">"x-pixel size of the final combined data cube,"</span>
+<a name="l00124"></a>00124                               <span class="stringliteral">"must lie between 64 and 128. "</span>
+<a name="l00125"></a>00125                               <span class="stringliteral">"If 0 it is computed automatically"</span>,
+<a name="l00126"></a>00126                               <span class="stringliteral">"sinfoni.objnod"</span>,
+<a name="l00127"></a>00127                               0);
+<a name="l00128"></a>00128 
+<a name="l00129"></a>00129   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"objnod-size_x"</span>);
+<a name="l00130"></a>00130   cpl_parameterlist_append(list, p);
+<a name="l00131"></a>00131 
+<a name="l00132"></a>00132 
+<a name="l00133"></a>00133   <span class="comment">/*y-pixel size of the final combined data cube, must lie between 64 and 128 */</span>
+<a name="l00134"></a>00134   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.objnod.size_y"</span>,
+<a name="l00135"></a>00135                   CPL_TYPE_INT,
+<a name="l00136"></a>00136                               <span class="stringliteral">"Cube y size: "</span>
+<a name="l00137"></a>00137                               <span class="stringliteral">"y-pixel size of the final combined data cube,"</span>
+<a name="l00138"></a>00138                               <span class="stringliteral">"must lie between 64 and 128."</span>
+<a name="l00139"></a>00139                               <span class="stringliteral">"If 0 it is computed automatically"</span>,
+<a name="l00140"></a>00140                               <span class="stringliteral">"sinfoni.objnod"</span>,
+<a name="l00141"></a>00141                               0);
+<a name="l00142"></a>00142 
+<a name="l00143"></a>00143   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"objnod-size_y"</span>);
+<a name="l00144"></a>00144   cpl_parameterlist_append(list, p);
+<a name="l00145"></a>00145 
+<a name="l00146"></a>00146   <span class="comment">/*Resampling */</span>
+<a name="l00147"></a>00147  <span class="comment">/* number of coefficients for the polynomial interpolation */</span>
+<a name="l00148"></a>00148   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.objnod.n_coeffs"</span>,
+<a name="l00149"></a>00149                   CPL_TYPE_INT,
+<a name="l00150"></a>00150                               <span class="stringliteral">"number of coefficients for the polynomial "</span>
+<a name="l00151"></a>00151                               <span class="stringliteral">"interpolation "</span>,
+<a name="l00152"></a>00152                               <span class="stringliteral">"sinfoni.objnod"</span>,
+<a name="l00153"></a>00153                                3);
+<a name="l00154"></a>00154 
+<a name="l00155"></a>00155   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"objnod-no_coeffs"</span>);
+<a name="l00156"></a>00156   cpl_parameterlist_append(list, p);
+<a name="l00157"></a>00157 
+<a name="l00158"></a>00158 
+<a name="l00159"></a>00159   <span class="comment">/* Calibration */</span>
+<a name="l00160"></a>00160   <span class="comment">/* indicates if the halogen lamp features from flatfielding should be </span>
+<a name="l00161"></a>00161 <span class="comment">     corrected for or not */</span>
+<a name="l00162"></a>00162   <span class="comment">/*</span>
+<a name="l00163"></a>00163 <span class="comment">  p = cpl_parameter_new_value("sinfoni.objnod.halo_correct_index",</span>
+<a name="l00164"></a>00164 <span class="comment">                  CPL_TYPE_BOOL,</span>
+<a name="l00165"></a>00165 <span class="comment">                              "Halo Correct Index: "</span>
+<a name="l00166"></a>00166 <span class="comment">                              "indicates if the halogen lamp features from "</span>
+<a name="l00167"></a>00167 <span class="comment">                              "flatfielding should be corrected for (TRUE) "</span>
+<a name="l00168"></a>00168 <span class="comment">                              "or not (FALSE)",</span>
+<a name="l00169"></a>00169 <span class="comment">                              "sinfoni.objnod",</span>
+<a name="l00170"></a>00170 <span class="comment">                              FALSE);</span>
+<a name="l00171"></a>00171 <span class="comment"></span>
+<a name="l00172"></a>00172 <span class="comment">  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"objnod-halo_corr_ind");</span>
+<a name="l00173"></a>00173 <span class="comment">  cpl_parameterlist_append(list, p);</span>
+<a name="l00174"></a>00174 <span class="comment">  */</span>
+<a name="l00175"></a>00175 
+<a name="l00176"></a>00176   <span class="comment">/* Cube Creation */</span>
+<a name="l00177"></a>00177   <span class="comment">/*indicates if the slitlet distances are determined by a north-south-test </span>
+<a name="l00178"></a>00178 <span class="comment">     (yes) or slitlet edge fits (no)</span>
+<a name="l00179"></a>00179 <span class="comment">  */</span>
+<a name="l00180"></a>00180   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.objnod.nord_south_index"</span>,
+<a name="l00181"></a>00181                   CPL_TYPE_BOOL,
+<a name="l00182"></a>00182                               <span class="stringliteral">"Nord South Index Switch: "</span>
+<a name="l00183"></a>00183                               <span class="stringliteral">"indicates if the slitlet distances are "</span>
+<a name="l00184"></a>00184                               <span class="stringliteral">"determined by a north-south-test (TRUE) "</span>
+<a name="l00185"></a>00185                               <span class="stringliteral">"or slitlet edge fits (FALSE)"</span>,
+<a name="l00186"></a>00186                               <span class="stringliteral">"sinfoni.objnod"</span>,
+<a name="l00187"></a>00187                               TRUE);
+<a name="l00188"></a>00188 
+<a name="l00189"></a>00189 
+<a name="l00190"></a>00190   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"objnod-ns_ind"</span>);
+<a name="l00191"></a>00191   cpl_parameterlist_append(list, p);
+<a name="l00192"></a>00192 
+<a name="l00193"></a>00193   <span class="comment">/* Fine tuning */</span>
+<a name="l00194"></a>00194   <span class="comment">/* Method */</span>
+<a name="l00195"></a>00195   p = cpl_parameter_new_enum(<span class="stringliteral">"sinfoni.objnod.fine_tuning_method"</span>,
+<a name="l00196"></a>00196                   CPL_TYPE_STRING,
+<a name="l00197"></a>00197                               <span class="stringliteral">"Fine Tuning Method: "</span>
+<a name="l00198"></a>00198                               <span class="stringliteral">"indicator for the shifting method to use "</span>
+<a name="l00199"></a>00199                               <span class="stringliteral">"(P: polynomial interpolation, "</span>
+<a name="l00200"></a>00200                  <span class="comment">/* " F: FFT, " */</span>
+<a name="l00201"></a>00201                               <span class="stringliteral">" S: cubic spline interpolation)"</span>,
+<a name="l00202"></a>00202                               <span class="stringliteral">"sinfoni.objnod"</span>,
+<a name="l00203"></a>00203                               <span class="stringliteral">"P"</span>,
+<a name="l00204"></a>00204                                2,
+<a name="l00205"></a>00205                               <span class="stringliteral">"P"</span>,<span class="stringliteral">"S"</span>);
+<a name="l00206"></a>00206 
+<a name="l00207"></a>00207   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"objnod-fine_tune_mtd"</span>);
+<a name="l00208"></a>00208   cpl_parameterlist_append(list, p);
+<a name="l00209"></a>00209 
+<a name="l00210"></a>00210   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.objnod.order"</span>,
+<a name="l00211"></a>00211                   CPL_TYPE_INT,
+<a name="l00212"></a>00212                               <span class="stringliteral">"Fine Tuning polynomial order: "</span> 
+<a name="l00213"></a>00213                               <span class="stringliteral">"order of the polynomial if the polynomial "</span>
+<a name="l00214"></a>00214                               <span class="stringliteral">"interpolation shifting method is used."</span>,
+<a name="l00215"></a>00215                               <span class="stringliteral">"sinfoni.objnod"</span>,
+<a name="l00216"></a>00216                               2);
+<a name="l00217"></a>00217 
+<a name="l00218"></a>00218   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"objnod-order"</span>);
+<a name="l00219"></a>00219   cpl_parameterlist_append(list, p);
+<a name="l00220"></a>00220 
+<a name="l00221"></a>00221   <span class="comment">/* Sky Extraction */</span>
+<a name="l00222"></a>00222   <span class="comment">/*Reconstruction */</span>
+<a name="l00223"></a>00223  <span class="comment">/* the fraction [0...1] of rejected low intensity pixels when taking </span>
+<a name="l00224"></a>00224 <span class="comment">the average of columns */</span>
+<a name="l00225"></a>00225   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.objnod.low_rejection"</span>,
+<a name="l00226"></a>00226                   CPL_TYPE_DOUBLE,
+<a name="l00227"></a>00227                               <span class="stringliteral">"lower rejection: "</span>
+<a name="l00228"></a>00228                               <span class="stringliteral">"percentage of rejected low value pixels "</span>
+<a name="l00229"></a>00229                               <span class="stringliteral">"for averaging the sky spectra"</span>,
+<a name="l00230"></a>00230                               <span class="stringliteral">"sinfoni.objnod"</span>,
+<a name="l00231"></a>00231                               10.);
+<a name="l00232"></a>00232 
+<a name="l00233"></a>00233   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"objnod-lo_rej"</span>);
+<a name="l00234"></a>00234   cpl_parameterlist_append(list, p);
+<a name="l00235"></a>00235  <span class="comment">/* the fraction [0...1] of rejected high intensity pixels when taking </span>
+<a name="l00236"></a>00236 <span class="comment">the average of columns */</span>
+<a name="l00237"></a>00237 
+<a name="l00238"></a>00238   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.objnod.high_rejection"</span>,
+<a name="l00239"></a>00239                   CPL_TYPE_DOUBLE,
+<a name="l00240"></a>00240                               <span class="stringliteral">"higher rejection: "</span>
+<a name="l00241"></a>00241                               <span class="stringliteral">"percentage of rejected high value pixels "</span>
+<a name="l00242"></a>00242                               <span class="stringliteral">"for averaging the sky spectra"</span>,
+<a name="l00243"></a>00243                               <span class="stringliteral">"sinfoni.objnod"</span>,
+<a name="l00244"></a>00244                               10.);
+<a name="l00245"></a>00245 
+<a name="l00246"></a>00246   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"objnod-hi_rej"</span>);
+<a name="l00247"></a>00247   cpl_parameterlist_append(list, p);
+<a name="l00248"></a>00248   <span class="comment">/* pixel tolerance, this distance tolerance to the diagonal dividing </span>
+<a name="l00249"></a>00249 <span class="comment">     line is not considered for the sky extraction to be sure to have a clean</span>
+<a name="l00250"></a>00250 <span class="comment">     sky due to positioning tolerance and crossing through pixels</span>
+<a name="l00251"></a>00251 <span class="comment">  */</span>
+<a name="l00252"></a>00252   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.objnod.tolerance"</span>,
+<a name="l00253"></a>00253                   CPL_TYPE_INT,
+<a name="l00254"></a>00254                               <span class="stringliteral">"Tolerance: "</span>
+<a name="l00255"></a>00255                               <span class="stringliteral">"pixel tolerance, this distance tolerance to "</span>
+<a name="l00256"></a>00256                               <span class="stringliteral">"the diagonal dividing line is not considered "</span>
+<a name="l00257"></a>00257                               <span class="stringliteral">"for the sky extraction to be sure to have a "</span>
+<a name="l00258"></a>00258                               <span class="stringliteral">"clean sky due to positioning tolerance and "</span>
+<a name="l00259"></a>00259                               <span class="stringliteral">"crossing through pixels"</span>,
+<a name="l00260"></a>00260                               <span class="stringliteral">"sinfoni.objnod"</span>,
+<a name="l00261"></a>00261                               2);
+<a name="l00262"></a>00262 
+<a name="l00263"></a>00263   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"objnod-tol"</span>);
+<a name="l00264"></a>00264   cpl_parameterlist_append(list, p);
+<a name="l00265"></a>00265   <span class="comment">/* Jittering */</span>
+<a name="l00266"></a>00266   <span class="comment">/* jitter mode indicator: yes: Auto-Jitter, no: user defined jitter</span>
+<a name="l00267"></a>00267 <span class="comment">     The next three parameters are only used if jitterInd is set to yes, </span>
+<a name="l00268"></a>00268 <span class="comment">     that means in auto-jittering mode!</span>
+<a name="l00269"></a>00269 <span class="comment">  */</span>
+<a name="l00270"></a>00270   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.objnod.jitter_index"</span>,
+<a name="l00271"></a>00271                   CPL_TYPE_BOOL,
+<a name="l00272"></a>00272                               <span class="stringliteral">"Jitter Index: "</span>
+<a name="l00273"></a>00273                               <span class="stringliteral">"jitter mode indicator: "</span>
+<a name="l00274"></a>00274                               <span class="stringliteral">"TRUE: Auto-Jitter, "</span>
+<a name="l00275"></a>00275                               <span class="stringliteral">"FALSE: user defined jitter"</span>
+<a name="l00276"></a>00276                               <span class="stringliteral">"The size_x size_y kernel_type parameters "</span>
+<a name="l00277"></a>00277                               <span class="stringliteral">"are only used if jitterInd is set to yes, "</span>
+<a name="l00278"></a>00278                               <span class="stringliteral">"that means in auto-jittering mode!"</span>,
+<a name="l00279"></a>00279                               <span class="stringliteral">"sinfoni.objnod"</span>,
+<a name="l00280"></a>00280                               TRUE);
+<a name="l00281"></a>00281 
+<a name="l00282"></a>00282   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"objnod-jit_ind"</span>);
+<a name="l00283"></a>00283   cpl_parameterlist_append(list, p);
+<a name="l00284"></a>00284 
+<a name="l00285"></a>00285   <span class="comment">/* Kernel Type */</span>
+<a name="l00286"></a>00286   <span class="comment">/* the name of the interpolation kernel to shift the single cubes  to the </span>
+<a name="l00287"></a>00287 <span class="comment">     correct places inside the big combined cube. That you want to generate </span>
+<a name="l00288"></a>00288 <span class="comment">     using the eclipse routine sinfo_generate_interpolation_kernel()</span>
+<a name="l00289"></a>00289 <span class="comment">     Supported kernels are:</span>
+<a name="l00290"></a>00290 <span class="comment"></span>
+<a name="l00291"></a>00291 <span class="comment">                                     NULL:      default kernel, currently tanh</span>
+<a name="l00292"></a>00292 <span class="comment">                                     default: dito</span>
+<a name="l00293"></a>00293 <span class="comment">                                     tanh:    Hyperbolic tangent</span>
+<a name="l00294"></a>00294 <span class="comment">                                     sinc2:   Square sinc</span>
+<a name="l00295"></a>00295 <span class="comment">                                     lanczos: Lanczos2 kernel</span>
+<a name="l00296"></a>00296 <span class="comment">                                     hamming: Hamming kernel</span>
+<a name="l00297"></a>00297 <span class="comment">                                     hann:    Hann kernel</span>
+<a name="l00298"></a>00298 <span class="comment">  */</span>
+<a name="l00299"></a>00299   p = cpl_parameter_new_enum(<span class="stringliteral">"sinfoni.objnod.kernel_type"</span>,
+<a name="l00300"></a>00300                   CPL_TYPE_STRING,
+<a name="l00301"></a>00301                               <span class="stringliteral">"Kernel Type:"</span>
+<a name="l00302"></a>00302                               <span class="stringliteral">"the name of the interpolation kernel to shift "</span>
+<a name="l00303"></a>00303                               <span class="stringliteral">"the single cubes  to the correct places inside "</span>
+<a name="l00304"></a>00304                  <span class="stringliteral">"the big combined cube"</span>,
+<a name="l00305"></a>00305                               <span class="stringliteral">"sinfoni.objnod"</span>,
+<a name="l00306"></a>00306                               <span class="stringliteral">"tanh"</span>,
+<a name="l00307"></a>00307                                7,
+<a name="l00308"></a>00308                               <span class="stringliteral">"NULL"</span>,<span class="stringliteral">"default"</span>,<span class="stringliteral">"tanh"</span>,<span class="stringliteral">"sinc2"</span>,
+<a name="l00309"></a>00309                               <span class="stringliteral">"lanczos"</span>,<span class="stringliteral">"hamming"</span>,<span class="stringliteral">"hann"</span>);
+<a name="l00310"></a>00310 
+<a name="l00311"></a>00311   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"objnod-kernel_typ"</span>);
+<a name="l00312"></a>00312   cpl_parameterlist_append(list, p);
+<a name="l00313"></a>00313 
+<a name="l00314"></a>00314 
+<a name="l00315"></a>00315 <span class="comment">/* amount of vignetting from output cube before coaddition */</span>
+<a name="l00316"></a>00316   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.objnod.vllx"</span>,
+<a name="l00317"></a>00317                   CPL_TYPE_INT,
+<a name="l00318"></a>00318                               <span class="stringliteral">"Vignetting on llx: "</span>
+<a name="l00319"></a>00319                               <span class="stringliteral">"pixels vignetted from lower left corner "</span>
+<a name="l00320"></a>00320                               <span class="stringliteral">"X coordinate "</span>
+<a name="l00321"></a>00321                               <span class="stringliteral">"of contributing cubes before coaddition "</span>,
+<a name="l00322"></a>00322                               <span class="stringliteral">"sinfoni.objnod"</span>,
+<a name="l00323"></a>00323                               0,0,63);
+<a name="l00324"></a>00324 
+<a name="l00325"></a>00325   cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"objnod-vllx"</span>);
+<a name="l00326"></a>00326   cpl_parameterlist_append(list, p);
+<a name="l00327"></a>00327 
+<a name="l00328"></a>00328 
+<a name="l00329"></a>00329   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.objnod.vlly"</span>,
+<a name="l00330"></a>00330                   CPL_TYPE_INT,
+<a name="l00331"></a>00331                               <span class="stringliteral">"Vignetting on lly: "</span>
+<a name="l00332"></a>00332                               <span class="stringliteral">"pixels vignetted from lower left corner "</span>
+<a name="l00333"></a>00333                               <span class="stringliteral">"Y coordinate "</span>
+<a name="l00334"></a>00334                               <span class="stringliteral">"of contributing cubes before coaddition "</span>,
+<a name="l00335"></a>00335                               <span class="stringliteral">"sinfoni.objnod"</span>,
+<a name="l00336"></a>00336                               0,0,63);
+<a name="l00337"></a>00337 
+<a name="l00338"></a>00338   cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"objnod-vlly"</span>);
+<a name="l00339"></a>00339   cpl_parameterlist_append(list, p);
+<a name="l00340"></a>00340 
+<a name="l00341"></a>00341 
+<a name="l00342"></a>00342   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.objnod.vurx"</span>,
+<a name="l00343"></a>00343                   CPL_TYPE_INT,
+<a name="l00344"></a>00344                               <span class="stringliteral">"Vignetting on urx: "</span>
+<a name="l00345"></a>00345                               <span class="stringliteral">"pixels vignetted from upper right corner "</span>
+<a name="l00346"></a>00346                               <span class="stringliteral">"X coordinate "</span>
+<a name="l00347"></a>00347                               <span class="stringliteral">"of contributing cubes before coaddition "</span>,
+<a name="l00348"></a>00348                               <span class="stringliteral">"sinfoni.objnod"</span>,
+<a name="l00349"></a>00349                               0,0,63);
+<a name="l00350"></a>00350 
+<a name="l00351"></a>00351   cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"objnod-vurx"</span>);
+<a name="l00352"></a>00352   cpl_parameterlist_append(list, p);
+<a name="l00353"></a>00353 
+<a name="l00354"></a>00354 
+<a name="l00355"></a>00355   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.objnod.vury"</span>,
+<a name="l00356"></a>00356                   CPL_TYPE_INT,
+<a name="l00357"></a>00357                               <span class="stringliteral">"Vignetting on ury: "</span>
+<a name="l00358"></a>00358                               <span class="stringliteral">"pixels vignetted from upper right corner "</span>
+<a name="l00359"></a>00359                               <span class="stringliteral">"Y coordinate "</span>
+<a name="l00360"></a>00360                               <span class="stringliteral">"of contributing cubes before coaddition "</span>,
+<a name="l00361"></a>00361                               <span class="stringliteral">"sinfoni.objnod"</span>,
+<a name="l00362"></a>00362                               0,0,63);
+<a name="l00363"></a>00363 
+<a name="l00364"></a>00364   cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"objnod-vury"</span>);
+<a name="l00365"></a>00365   cpl_parameterlist_append(list, p);
+<a name="l00366"></a>00366 
+<a name="l00367"></a>00367 
+<a name="l00368"></a>00368   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.objnod.fcol"</span>,
+<a name="l00369"></a>00369             CPL_TYPE_DOUBLE,
+<a name="l00370"></a>00370             <span class="stringliteral">"First column offset: "</span>,
+<a name="l00371"></a>00371                         <span class="stringliteral">"sinfoni.objnod"</span>,
+<a name="l00372"></a>00372                          0.);
+<a name="l00373"></a>00373 
+<a name="l00374"></a>00374   cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"objnod-fcol"</span>);
+<a name="l00375"></a>00375   cpl_parameterlist_append(list, p);
+<a name="l00376"></a>00376 
+<a name="l00377"></a>00377   <span class="comment">/* switch to activate the sky residuals correction */</span>
+<a name="l00378"></a>00378   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.objnod.sky_cor"</span>,
+<a name="l00379"></a>00379                   CPL_TYPE_BOOL,
+<a name="l00380"></a>00380                               <span class="stringliteral">"Sky residuals correction: "</span>,
+<a name="l00381"></a>00381                               <span class="stringliteral">"sinfoni.objnod"</span>,
+<a name="l00382"></a>00382                               TRUE);
+<a name="l00383"></a>00383 
+<a name="l00384"></a>00384   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"objnod-sky_cor"</span>);
+<a name="l00385"></a>00385   cpl_parameterlist_append(list, p);
+<a name="l00386"></a>00386 
+<a name="l00387"></a>00387 
+<a name="l00388"></a>00388   <span class="comment">/* switch to activate the flux correction correction */</span>
+<a name="l00389"></a>00389   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.objnod.flux_cor"</span>,
+<a name="l00390"></a>00390                   CPL_TYPE_BOOL,
+<a name="l00391"></a>00391                               <span class="stringliteral">"Apply flux correction after rebinning: "</span>,
+<a name="l00392"></a>00392                               <span class="stringliteral">"sinfoni.objnod"</span>,
+<a name="l00393"></a>00393                               TRUE);
+<a name="l00394"></a>00394 
+<a name="l00395"></a>00395   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"objnod-flux_cor"</span>);
+<a name="l00396"></a>00396   cpl_parameterlist_append(list, p);
+<a name="l00397"></a>00397 
+<a name="l00398"></a>00398 
+<a name="l00399"></a>00399   <span class="comment">/* switch to activate the flux correction correction */</span>
+<a name="l00400"></a>00400   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.objnod.mosaic_max_size"</span>,
+<a name="l00401"></a>00401                   CPL_TYPE_INT,
+<a name="l00402"></a>00402                               <span class="stringliteral">"Maximum allowed size for cubes mosaic is "</span>
+<a name="l00403"></a>00403                               <span class="stringliteral">"100*mosaic_max_size "</span>,
+<a name="l00404"></a>00404                               <span class="stringliteral">"sinfoni.objnod"</span>,
+<a name="l00405"></a>00405                               14196);
+<a name="l00406"></a>00406 
+<a name="l00407"></a>00407   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"objnod-mosaic_max_size"</span>);
+<a name="l00408"></a>00408   cpl_parameterlist_append(list, p);
+<a name="l00409"></a>00409 
+<a name="l00410"></a>00410 
+<a name="l00411"></a>00411 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__objnod__config_8h_source.html b/html/sinfo__objnod__config_8h_source.html
new file mode 100644
index 0000000..e5b005b
--- /dev/null
+++ b/html/sinfo__objnod__config_8h_source.html
@@ -0,0 +1,48 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_objnod_config.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_objnod_config.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_objnod_config.h,v 1.1 2006/10/20 08:06:32 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the CPL (Common Pipeline Library)</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
+<a name="l00007"></a>00007 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span>
+<a name="l00008"></a>00008 <span class="comment"> * License as published by the Free Software Foundation; either</span>
+<a name="l00009"></a>00009 <span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
+<a name="l00014"></a>00014 <span class="comment"> * Lesser General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
+<a name="l00017"></a>00017 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2006/10/20 08:06:32 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.1 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> */</span>
+<a name="l00026"></a>00026 
+<a name="l00027"></a>00027  <span class="comment">/****************************************************************</span>
+<a name="l00028"></a>00028 <span class="comment">  *   Objnod Frames Data Reduction Parameter Initialization        *</span>
+<a name="l00029"></a>00029 <span class="comment">  ****************************************************************/</span>
+<a name="l00030"></a>00030 <span class="preprocessor">#include "cpl.h"</span>    <span class="comment">/* defines parlist structure */</span>
+<a name="l00031"></a>00031 
+<a name="l00032"></a>00032 <span class="keywordtype">void</span> sinfo_objnod_config_add(cpl_parameterlist *list);
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__objnod__ini__by__cpl_8c_source.html b/html/sinfo__objnod__ini__by__cpl_8c_source.html
new file mode 100644
index 0000000..89110be
--- /dev/null
+++ b/html/sinfo__objnod__ini__by__cpl_8c_source.html
@@ -0,0 +1,421 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_objnod_ini_by_cpl.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_objnod_ini_by_cpl.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 
+<a name="l00020"></a>00020 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00021"></a>00021 <span class="comment"></span>
+<a name="l00022"></a>00022 <span class="comment">   File name    :   sinfo_object_ini_by_cpl.c</span>
+<a name="l00023"></a>00023 <span class="comment">   Author       :   Andrea Modigliani</span>
+<a name="l00024"></a>00024 <span class="comment">   Created on   :   May 22, 2004</span>
+<a name="l00025"></a>00025 <span class="comment">   Description  :   object cube creation cpl input handling for SPIFFI</span>
+<a name="l00026"></a>00026 <span class="comment"></span>
+<a name="l00027"></a>00027 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00028"></a>00028 
+<a name="l00029"></a>00029 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00031"></a>00031 <span class="preprocessor">#endif</span>
+<a name="l00032"></a>00032 <span class="preprocessor"></span>
+<a name="l00033"></a>00033 
+<a name="l00034"></a>00034 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00035"></a>00035 <span class="comment">                                Includes</span>
+<a name="l00036"></a>00036 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00037"></a>00037 
+<a name="l00038"></a>00038 <span class="preprocessor">#include <string.h></span>
+<a name="l00039"></a>00039 <span class="preprocessor">#include "sinfo_objnod_ini_by_cpl.h"</span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include "sinfo_pro_types.h"</span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include "sinfo_hidden.h"</span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include "sinfo_globals.h"</span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include "sinfo_functions.h"</span>
+<a name="l00044"></a>00044 
+<a name="l00045"></a>00045 <span class="preprocessor">#include "sinfo_file_handling.h"</span>
+<a name="l00046"></a>00046 
+<a name="l00047"></a>00047 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00048"></a>00048 <span class="comment">                    Functions private to this module</span>
+<a name="l00049"></a>00049 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00050"></a>00050 <span class="keyword">static</span> <span class="keywordtype">void</span>
+<a name="l00051"></a>00051 parse_section_frames(object_config *,cpl_frameset* sof,
+<a name="l00052"></a>00052                      cpl_frameset** stk,  <span class="keywordtype">int</span>* status);
+<a name="l00053"></a>00053 <span class="keyword">static</span> <span class="keywordtype">void</span> parse_section_jittering(object_config *,
+<a name="l00054"></a>00054                      cpl_parameterlist * cpl_cfg);
+<a name="l00055"></a>00055 <span class="keyword">static</span> <span class="keywordtype">void</span> parse_section_resampling(object_config *,
+<a name="l00056"></a>00056                      cpl_parameterlist * cpl_cfg);
+<a name="l00057"></a>00057 <span class="keyword">static</span> <span class="keywordtype">void</span> parse_section_calibration(object_config *);
+<a name="l00058"></a>00058 <span class="keyword">static</span> <span class="keywordtype">void</span> parse_section_cubecreation(object_config *,
+<a name="l00059"></a>00059                      cpl_parameterlist * cpl_cfg);
+<a name="l00060"></a>00060 <span class="keyword">static</span> <span class="keywordtype">void</span> parse_section_finetuning(object_config *,
+<a name="l00061"></a>00061                      cpl_parameterlist * cpl_cfg);
+<a name="l00062"></a>00062 <span class="keyword">static</span> <span class="keywordtype">void</span> parse_section_skyextraction(object_config *,
+<a name="l00063"></a>00063                      cpl_parameterlist * cpl_cfg);
+<a name="l00073"></a>00073 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l00084"></a>00084 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00085"></a>00085 
+<a name="l00086"></a>00086 object_config *
+<a name="l00087"></a>00087 sinfo_parse_cpl_input_objnod(cpl_parameterlist * cpl_cfg,cpl_frameset* sof,
+<a name="l00088"></a>00088                cpl_frameset** stk)
+<a name="l00089"></a>00089 {
+<a name="l00090"></a>00090    object_config   * cfg = sinfo_object_cfg_create();
+<a name="l00091"></a>00091    <span class="keywordtype">int</span> status=0;
+<a name="l00092"></a>00092    <span class="comment">/*</span>
+<a name="l00093"></a>00093 <span class="comment">    * Perform sanity checks, fill up the structure with what was</span>
+<a name="l00094"></a>00094 <span class="comment">    * found in the ini file</span>
+<a name="l00095"></a>00095 <span class="comment">    */</span>
+<a name="l00096"></a>00096 
+<a name="l00097"></a>00097 
+<a name="l00098"></a>00098    parse_section_resampling   (cfg, cpl_cfg);
+<a name="l00099"></a>00099    parse_section_calibration  (cfg);
+<a name="l00100"></a>00100    parse_section_cubecreation (cfg, cpl_cfg);
+<a name="l00101"></a>00101    parse_section_finetuning   (cfg, cpl_cfg);
+<a name="l00102"></a>00102    parse_section_skyextraction(cfg, cpl_cfg);
+<a name="l00103"></a>00103    parse_section_jittering    (cfg, cpl_cfg);
+<a name="l00104"></a>00104    parse_section_frames       (cfg, sof,stk,&status);
+<a name="l00105"></a>00105    <span class="keywordflow">if</span> (status > 0) {
+<a name="l00106"></a>00106                 <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"parsing cpl input"</span>);
+<a name="l00107"></a>00107                 sinfo_objnod_free(&cfg);
+<a name="l00108"></a>00108                 cfg = NULL ;
+<a name="l00109"></a>00109                 <span class="keywordflow">return</span> NULL ;
+<a name="l00110"></a>00110    }
+<a name="l00111"></a>00111 
+<a name="l00112"></a>00112    <span class="keywordflow">return</span> cfg ;
+<a name="l00113"></a>00113 }
+<a name="l00114"></a>00114 
+<a name="l00115"></a>00115 <span class="keyword">static</span> <span class="keywordtype">void</span>
+<a name="l00116"></a>00116 parse_section_frames(object_config * cfg,
+<a name="l00117"></a>00117              cpl_frameset* sof,
+<a name="l00118"></a>00118                      cpl_frameset** stk,
+<a name="l00119"></a>00119                      <span class="keywordtype">int</span>* status)
+<a name="l00120"></a>00120 {
+<a name="l00121"></a>00121    <span class="keywordtype">int</span>                     nraw_good =0;
+<a name="l00122"></a>00122 
+<a name="l00123"></a>00123 
+<a name="l00124"></a>00124 
+<a name="l00125"></a>00125    <span class="keywordtype">int</span> nframes=0;
+<a name="l00126"></a>00126    <span class="keywordtype">int</span> nraw=0;
+<a name="l00127"></a>00127    cpl_frame* frame   = NULL;
+<a name="l00128"></a>00128    <span class="keywordtype">int</span> nstk=0;
+<a name="l00129"></a>00129    <span class="keywordtype">int</span> i=0;
+<a name="l00130"></a>00130     <span class="keywordtype">char</span> spat_res[FILE_NAME_SZ];
+<a name="l00131"></a>00131    <span class="keywordtype">char</span> lamp_status[FILE_NAME_SZ];
+<a name="l00132"></a>00132    <span class="keywordtype">char</span> band[FILE_NAME_SZ];
+<a name="l00133"></a>00133    <span class="keywordtype">int</span> ins_set=0;
+<a name="l00134"></a>00134 
+<a name="l00135"></a>00135    nframes = cpl_frameset_get_size(sof);
+<a name="l00136"></a>00136 
+<a name="l00137"></a>00137    sinfo_contains_frames_type(sof,stk,PRO_NODDING_STACKED);
+<a name="l00138"></a>00138    nstk = cpl_frameset_get_size(*stk);
+<a name="l00139"></a>00139 
+<a name="l00140"></a>00140    <span class="keywordflow">if</span> (nstk == 0) {
+<a name="l00141"></a>00141       sinfo_contains_frames_type(sof,stk,PRO_PSF_CALIBRATOR_STACKED);
+<a name="l00142"></a>00142       nstk = cpl_frameset_get_size(*stk);
+<a name="l00143"></a>00143    }
+<a name="l00144"></a>00144    <span class="keywordflow">if</span> (nstk == 0) {
+<a name="l00145"></a>00145       sinfo_contains_frames_type(sof,stk,PRO_PUPIL_LAMP_STACKED);
+<a name="l00146"></a>00146       nstk = cpl_frameset_get_size(*stk);
+<a name="l00147"></a>00147    }
+<a name="l00148"></a>00148    <span class="keywordflow">if</span> (nstk == 0) {
+<a name="l00149"></a>00149         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>( <span class="stringliteral">"Cannot find good frames"</span>) ;
+<a name="l00150"></a>00150         (*status)++;
+<a name="l00151"></a>00151         return ;
+<a name="l00152"></a>00152    }
+<a name="l00153"></a>00153 
+<a name="l00154"></a>00154 
+<a name="l00155"></a>00155 
+<a name="l00156"></a>00156    <span class="comment">/* TEMPORALLY COMMENTED OUT */</span>
+<a name="l00157"></a>00157     nraw    = cpl_frameset_get_size(*stk);
+<a name="l00158"></a>00158     <span class="comment">/* Test if the rawframes have been found */</span>
+<a name="l00159"></a>00159      <span class="keywordflow">if</span> (nraw < 1) {
+<a name="l00160"></a>00160         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Cannot find input stacked frames in the input list"</span>) ;
+<a name="l00161"></a>00161         (*status)++;
+<a name="l00162"></a>00162         return ;
+<a name="l00163"></a>00163     }
+<a name="l00164"></a>00164 
+<a name="l00165"></a>00165    nraw    = cpl_frameset_get_size(*stk);
+<a name="l00166"></a>00166    <span class="keywordflow">if</span> (nraw < 1) {
+<a name="l00167"></a>00167      <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>( <span class="stringliteral">"no raw frame in input, something wrong!"</span>);
+<a name="l00168"></a>00168      (*status)++;
+<a name="l00169"></a>00169      return ;
+<a name="l00170"></a>00170    }
+<a name="l00171"></a>00171 
+<a name="l00172"></a>00172    <span class="comment">/* Allocate structures to go into the blackboard */</span>
+<a name="l00173"></a>00173    cfg->framelist     = cpl_malloc(nraw * <span class="keyword">sizeof</span>(<span class="keywordtype">char</span>*));
+<a name="l00174"></a>00174 
+<a name="l00175"></a>00175   <span class="comment">/* read input frames */</span>
+<a name="l00176"></a>00176    <span class="keywordflow">for</span> (i=0 ; i<nraw ; i++) {
+<a name="l00177"></a>00177       frame = cpl_frameset_get_frame(*stk,i);
+<a name="l00178"></a>00178       <span class="keywordflow">if</span>(sinfo_file_exists((<span class="keywordtype">char</span>*)cpl_frame_get_filename(frame))==1)
+<a name="l00179"></a>00179     {
+<a name="l00180"></a>00180           cfg->framelist[i]=cpl_strdup(cpl_frame_get_filename(frame));
+<a name="l00181"></a>00181               nraw_good++;
+<a name="l00182"></a>00182     }
+<a name="l00183"></a>00183       <span class="comment">/* Store file name into framelist */</span>
+<a name="l00184"></a>00184    }
+<a name="l00185"></a>00185 
+<a name="l00186"></a>00186 
+<a name="l00187"></a>00187    <span class="keywordflow">if</span> (nraw_good < 1) {
+<a name="l00188"></a>00188      <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no good raw frame in input!"</span>);
+<a name="l00189"></a>00189         (*status)++;
+<a name="l00190"></a>00190      <span class="keywordflow">return</span>;
+<a name="l00191"></a>00191    }
+<a name="l00192"></a>00192    <span class="comment">/* Copy relevant information into the blackboard */</span>
+<a name="l00193"></a>00193    cfg->nframes         = nraw ;
+<a name="l00194"></a>00194 
+<a name="l00195"></a>00195    strcpy(cfg -> outName,  OBJNOD_OUT_FILENAME);
+<a name="l00196"></a>00196    strcpy(cfg -> maskname, OBJNOD_OUT_BPMAP);
+<a name="l00197"></a>00197    strcpy(cfg -> med_cube_name, OBJNOD_OUT_MED_CUBE);
+<a name="l00198"></a>00198 
+<a name="l00199"></a>00199 
+<a name="l00200"></a>00200    frame = cpl_frameset_get_frame(*stk,0);
+<a name="l00201"></a>00201 
+<a name="l00202"></a>00202    sinfo_get_spatial_res(frame,spat_res);
+<a name="l00203"></a>00203   <span class="keywordflow">switch</span>(sinfo_frame_is_on(frame))
+<a name="l00204"></a>00204     {
+<a name="l00205"></a>00205 
+<a name="l00206"></a>00206     <span class="keywordflow">case</span> 0:
+<a name="l00207"></a>00207       strcpy(lamp_status,<span class="stringliteral">"on"</span>);
+<a name="l00208"></a>00208       <span class="keywordflow">break</span>;
+<a name="l00209"></a>00209     <span class="keywordflow">case</span> 1:
+<a name="l00210"></a>00210       strcpy(lamp_status,<span class="stringliteral">"off"</span>);
+<a name="l00211"></a>00211       <span class="keywordflow">break</span>;
+<a name="l00212"></a>00212     <span class="keywordflow">case</span> -1:
+<a name="l00213"></a>00213       strcpy(lamp_status,<span class="stringliteral">"undefined"</span>);
+<a name="l00214"></a>00214       <span class="keywordflow">break</span>;
+<a name="l00215"></a>00215     <span class="keywordflow">default</span>:
+<a name="l00216"></a>00216       strcpy(lamp_status,<span class="stringliteral">"undefined"</span>);
+<a name="l00217"></a>00217       <span class="keywordflow">break</span>;
+<a name="l00218"></a>00218     }
+<a name="l00219"></a>00219    sinfo_get_band(frame,band);
+<a name="l00220"></a>00220    sinfo_msg(<span class="stringliteral">"Spatial resolution: %s lamp_status: %s band: %s"</span>,
+<a name="l00221"></a>00221                      spat_res,    lamp_status,    band);
+<a name="l00222"></a>00222 
+<a name="l00223"></a>00223 
+<a name="l00224"></a>00224    sinfo_get_ins_set(band,&ins_set);
+<a name="l00225"></a>00225 
+<a name="l00226"></a>00226    <span class="keywordflow">if</span>(NULL != cpl_frameset_find(sof,PRO_WAVE_MAP)) {
+<a name="l00227"></a>00227      frame = cpl_frameset_find(sof,PRO_WAVE_MAP);
+<a name="l00228"></a>00228      strcpy(cfg -> wavemap, cpl_frame_get_filename(frame));
+<a name="l00229"></a>00229    } <span class="keywordflow">else</span> {
+<a name="l00230"></a>00230      sinfo_msg(<span class="stringliteral">"Frame %s not found!"</span>, PRO_WAVE_MAP);
+<a name="l00231"></a>00231      <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>((<span class="keywordtype">char</span>* ) cpl_error_get_message());
+<a name="l00232"></a>00232      (*status)++;
+<a name="l00233"></a>00233      return ;
+<a name="l00234"></a>00234    }
+<a name="l00235"></a>00235 
+<a name="l00236"></a>00236    <span class="keywordflow">if</span>(NULL != cpl_frameset_find(sof,PRO_MASTER_FLAT_LAMP)) {
+<a name="l00237"></a>00237      frame = cpl_frameset_find(sof,PRO_MASTER_FLAT_LAMP);
+<a name="l00238"></a>00238      strcpy(cfg -> mflat, cpl_frame_get_filename(frame));
+<a name="l00239"></a>00239    } <span class="keywordflow">else</span> {
+<a name="l00240"></a>00240      sinfo_msg(<span class="stringliteral">"Frame %s not found!"</span>, PRO_MASTER_FLAT_LAMP);
+<a name="l00241"></a>00241      <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>((<span class="keywordtype">char</span>* ) cpl_error_get_message());
+<a name="l00242"></a>00242      (*status)++;
+<a name="l00243"></a>00243      return ;
+<a name="l00244"></a>00244    }
+<a name="l00245"></a>00245 
+<a name="l00246"></a>00246    <span class="keywordflow">if</span>(NULL != cpl_frameset_find(sof,PRO_STACK_SKY_DIST)) {
+<a name="l00247"></a>00247      frame = cpl_frameset_find(sof,PRO_STACK_SKY_DIST);
+<a name="l00248"></a>00248      strcpy(cfg -> sky_dist, cpl_frame_get_filename(frame));
+<a name="l00249"></a>00249    } <span class="keywordflow">else</span> {
+<a name="l00250"></a>00250      <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"Frame %s not found!"</span>, PRO_STACK_SKY_DIST);
+<a name="l00251"></a>00251      strcpy(cfg -> sky_dist,<span class="stringliteral">"no_sky"</span>);
+<a name="l00252"></a>00252    }
+<a name="l00253"></a>00253 
+<a name="l00254"></a>00254    <span class="keywordflow">if</span>(NULL != cpl_frameset_find(sof,PRO_STACK_MFLAT_DIST)) {
+<a name="l00255"></a>00255      frame = cpl_frameset_find(sof,PRO_STACK_MFLAT_DIST);
+<a name="l00256"></a>00256      strcpy(cfg -> mflat_dist, cpl_frame_get_filename(frame));
+<a name="l00257"></a>00257    } <span class="keywordflow">else</span> {
+<a name="l00258"></a>00258      strcpy(cfg -> mflat_dist, <span class="stringliteral">"not_found"</span>);
+<a name="l00259"></a>00259      sinfo_msg(<span class="stringliteral">"Frame %s not found!"</span>, PRO_STACK_MFLAT_DIST);
+<a name="l00260"></a>00260    }
+<a name="l00261"></a>00261 
+<a name="l00262"></a>00262 
+<a name="l00263"></a>00263    <span class="keywordflow">if</span>(NULL != cpl_frameset_find(sof,PRO_STACK_MFLAT_DITHER_DIST)) {
+<a name="l00264"></a>00264      frame = cpl_frameset_find(sof,PRO_STACK_MFLAT_DITHER_DIST);
+<a name="l00265"></a>00265      strcpy(cfg -> mflat_dither_dist, cpl_frame_get_filename(frame));
+<a name="l00266"></a>00266    } <span class="keywordflow">else</span> {
+<a name="l00267"></a>00267      strcpy(cfg -> mflat_dither_dist, <span class="stringliteral">"not_found"</span>);
+<a name="l00268"></a>00268      sinfo_msg(<span class="stringliteral">"Frame %s not found!"</span>, PRO_STACK_MFLAT_DITHER_DIST);
+<a name="l00269"></a>00269    }
+<a name="l00270"></a>00270 
+<a name="l00271"></a>00271 
+<a name="l00272"></a>00272    <span class="keywordflow">if</span>(cfg -> northsouthInd) {
+<a name="l00273"></a>00273 
+<a name="l00274"></a>00274      <span class="keywordflow">if</span>(NULL != cpl_frameset_find(sof,PRO_SLITLETS_DISTANCE)) {
+<a name="l00275"></a>00275        frame = cpl_frameset_find(sof,PRO_SLITLETS_DISTANCE);
+<a name="l00276"></a>00276        strcpy(cfg -> distlist, cpl_frame_get_filename(frame));
+<a name="l00277"></a>00277      } <span class="keywordflow">else</span> {
+<a name="l00278"></a>00278        sinfo_msg(<span class="stringliteral">"Frame %s not found!"</span>, PRO_SLITLETS_DISTANCE);
+<a name="l00279"></a>00279        (*status)++;
+<a name="l00280"></a>00280        return ;
+<a name="l00281"></a>00281      }
+<a name="l00282"></a>00282 
+<a name="l00283"></a>00283    } <span class="keywordflow">else</span> {
+<a name="l00284"></a>00284 
+<a name="l00285"></a>00285      <span class="keywordflow">if</span>(NULL != cpl_frameset_find(sof,PRO_SLIT_POS)) {
+<a name="l00286"></a>00286        frame = cpl_frameset_find(sof,PRO_SLIT_POS);
+<a name="l00287"></a>00287        strcpy(cfg -> poslist, cpl_frame_get_filename(frame));
+<a name="l00288"></a>00288      } <span class="keywordflow">else</span> {
+<a name="l00289"></a>00289        sinfo_msg(<span class="stringliteral">"Frame %s not found!"</span>, PRO_SLIT_POS);
+<a name="l00290"></a>00290        (*status)++;
+<a name="l00291"></a>00291        return ;
+<a name="l00292"></a>00292      }
+<a name="l00293"></a>00293 
+<a name="l00294"></a>00294    }
+<a name="l00295"></a>00295    <span class="keywordflow">if</span>(cfg -> halocorrectInd) {
+<a name="l00296"></a>00296      <span class="keywordflow">if</span>(NULL != cpl_frameset_find(sof,PRO_HALO_SPECT)) {
+<a name="l00297"></a>00297        frame = cpl_frameset_find(sof,PRO_HALO_SPECT);
+<a name="l00298"></a>00298        strcpy(cfg -> halospectrum, cpl_frame_get_filename(frame));
+<a name="l00299"></a>00299      } <span class="keywordflow">else</span> {
+<a name="l00300"></a>00300        sinfo_msg(<span class="stringliteral">"Frame %s not found!"</span>, PRO_HALO_SPECT);
+<a name="l00301"></a>00301        (*status)++;
+<a name="l00302"></a>00302        return ;
+<a name="l00303"></a>00303      }
+<a name="l00304"></a>00304 
+<a name="l00305"></a>00305    }
+<a name="l00306"></a>00306    <span class="keywordflow">if</span>(NULL != cpl_frameset_find(sof, PRO_REF_ATM_REF_CORR))
+<a name="l00307"></a>00307    {
+<a name="l00308"></a>00308        frame = cpl_frameset_find(sof, PRO_REF_ATM_REF_CORR);
+<a name="l00309"></a>00309        strcpy(cfg->polyshiftname, cpl_frame_get_filename(frame));
+<a name="l00310"></a>00310    } <span class="keywordflow">else</span>
+<a name="l00311"></a>00311    {
+<a name="l00312"></a>00312        sinfo_msg(<span class="stringliteral">"Frame %s not found, shift due atmospheric refraction "</span>
+<a name="l00313"></a>00313                <span class="stringliteral">"would not be applied!"</span>, PRO_REF_ATM_REF_CORR);
+<a name="l00314"></a>00314        cfg->polyshiftname[0] = 0;
+<a name="l00315"></a>00315 <span class="comment">//       (*status)++;</span>
+<a name="l00316"></a>00316    }
+<a name="l00317"></a>00317    <span class="comment">/*</span>
+<a name="l00318"></a>00318 <span class="comment">   sinfo_msg("cfg -> wavemap  %s",cfg -> wavemap);</span>
+<a name="l00319"></a>00319 <span class="comment">   sinfo_msg("cfg -> poslist  %s",cfg -> poslist);</span>
+<a name="l00320"></a>00320 <span class="comment">   sinfo_msg("cfg -> firstCol %s",cfg -> firstCol);</span>
+<a name="l00321"></a>00321 <span class="comment">   */</span>
+<a name="l00322"></a>00322    <span class="keywordflow">return</span>;
+<a name="l00323"></a>00323 }
+<a name="l00324"></a>00324 
+<a name="l00325"></a>00325 
+<a name="l00326"></a>00326 <span class="keyword">static</span> <span class="keywordtype">void</span>
+<a name="l00327"></a>00327 parse_section_jittering(object_config * cfg,cpl_parameterlist * cpl_cfg)
+<a name="l00328"></a>00328 {
+<a name="l00329"></a>00329    cpl_parameter* p;
+<a name="l00330"></a>00330 
+<a name="l00331"></a>00331    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.objnod.jitter_index"</span>);
+<a name="l00332"></a>00332    cfg -> jitterind = cpl_parameter_get_bool(p);
+<a name="l00333"></a>00333 
+<a name="l00334"></a>00334    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.objnod.size_x"</span>);
+<a name="l00335"></a>00335    cfg -> size_x = cpl_parameter_get_int(p);
+<a name="l00336"></a>00336 
+<a name="l00337"></a>00337    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.objnod.size_y"</span>);
+<a name="l00338"></a>00338    cfg -> size_y = cpl_parameter_get_int(p);
+<a name="l00339"></a>00339 
+<a name="l00340"></a>00340    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.objnod.kernel_type"</span>);
+<a name="l00341"></a>00341    strcpy(cfg -> kernel_type, cpl_parameter_get_string(p));
+<a name="l00342"></a>00342 
+<a name="l00343"></a>00343 }
+<a name="l00344"></a>00344 
+<a name="l00345"></a>00345 <span class="keyword">static</span> <span class="keywordtype">void</span>
+<a name="l00346"></a>00346 parse_section_resampling(object_config * cfg,cpl_parameterlist* cpl_cfg)
+<a name="l00347"></a>00347 {
+<a name="l00348"></a>00348    cpl_parameter* p;
+<a name="l00349"></a>00349 
+<a name="l00350"></a>00350    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.objnod.n_coeffs"</span>);
+<a name="l00351"></a>00351    cfg -> ncoeffs = cpl_parameter_get_int(p);
+<a name="l00352"></a>00352 
+<a name="l00353"></a>00353    cfg -> nrows = SINFO_RESAMP_NROWS;
+<a name="l00354"></a>00354    return ;
+<a name="l00355"></a>00355 }
+<a name="l00356"></a>00356 
+<a name="l00357"></a>00357 <span class="keyword">static</span> <span class="keywordtype">void</span>
+<a name="l00358"></a>00358 parse_section_calibration(object_config * cfg)
+<a name="l00359"></a>00359 {
+<a name="l00360"></a>00360   cfg -> halocorrectInd=0;
+<a name="l00361"></a>00361 
+<a name="l00362"></a>00362 
+<a name="l00363"></a>00363 }
+<a name="l00364"></a>00364 
+<a name="l00365"></a>00365 <span class="keyword">static</span> <span class="keywordtype">void</span>
+<a name="l00366"></a>00366 parse_section_cubecreation(object_config * cfg,cpl_parameterlist* cpl_cfg)
+<a name="l00367"></a>00367 {
+<a name="l00368"></a>00368    cpl_parameter* p;
+<a name="l00369"></a>00369    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.objnod.nord_south_index"</span>);
+<a name="l00370"></a>00370    cfg -> northsouthInd = cpl_parameter_get_bool(p);
+<a name="l00371"></a>00371    cfg -> nslits = NSLITLETS;
+<a name="l00372"></a>00372 
+<a name="l00373"></a>00373    return ;
+<a name="l00374"></a>00374 }
+<a name="l00375"></a>00375 
+<a name="l00376"></a>00376 <span class="keyword">static</span> <span class="keywordtype">void</span>
+<a name="l00377"></a>00377 parse_section_finetuning(object_config * cfg,cpl_parameterlist* cpl_cfg)
+<a name="l00378"></a>00378 {
+<a name="l00379"></a>00379    cpl_parameter* p;
+<a name="l00380"></a>00380 
+<a name="l00381"></a>00381    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.objnod.fine_tuning_method"</span>);
+<a name="l00382"></a>00382    strcpy(cfg -> method, cpl_parameter_get_string(p));
+<a name="l00383"></a>00383 
+<a name="l00384"></a>00384    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.objnod.order"</span>);
+<a name="l00385"></a>00385    cfg -> order = cpl_parameter_get_int(p);
+<a name="l00386"></a>00386 
+<a name="l00387"></a>00387 }
+<a name="l00388"></a>00388 
+<a name="l00389"></a>00389 <span class="keyword">static</span> <span class="keywordtype">void</span>
+<a name="l00390"></a>00390 parse_section_skyextraction(object_config * cfg,cpl_parameterlist* cpl_cfg)
+<a name="l00391"></a>00391 {
+<a name="l00392"></a>00392 
+<a name="l00393"></a>00393    cpl_parameter* p;
+<a name="l00394"></a>00394    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.objnod.low_rejection"</span>);
+<a name="l00395"></a>00395    cfg -> loReject = cpl_parameter_get_double(p);
+<a name="l00396"></a>00396 
+<a name="l00397"></a>00397    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.objnod.high_rejection"</span>);
+<a name="l00398"></a>00398    cfg -> hiReject = cpl_parameter_get_double(p);
+<a name="l00399"></a>00399 
+<a name="l00400"></a>00400    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.objnod.tolerance"</span>);
+<a name="l00401"></a>00401    cfg -> tolerance = cpl_parameter_get_int(p);
+<a name="l00402"></a>00402 
+<a name="l00403"></a>00403 }
+<a name="l00404"></a>00404 
+<a name="l00405"></a>00405 <span class="comment">/*-----------------------------------------------------------------*/</span>
+<a name="l00406"></a>00406 <span class="keywordtype">void</span>
+<a name="l00407"></a>00407 sinfo_objnod_free(object_config ** cfg) {
+<a name="l00408"></a>00408   <span class="keywordtype">int</span> i=0;
+<a name="l00409"></a>00409   <span class="keywordflow">if</span>(*cfg != NULL) {
+<a name="l00410"></a>00410     <span class="keywordflow">for</span>(i=0;i<(*cfg)->nframes;i++) {
+<a name="l00411"></a>00411       <span class="keywordflow">if</span>((*cfg)->framelist[i]!=NULL) {
+<a name="l00412"></a>00412     cpl_free((*cfg)->framelist[i]);
+<a name="l00413"></a>00413     (*cfg)->framelist[i]=NULL;
+<a name="l00414"></a>00414       }
+<a name="l00415"></a>00415     }
+<a name="l00416"></a>00416     <span class="keywordflow">if</span>((*cfg)->framelist != NULL) {
+<a name="l00417"></a>00417       cpl_free((*cfg)->framelist);
+<a name="l00418"></a>00418       (*cfg)->framelist=NULL;
+<a name="l00419"></a>00419     }
+<a name="l00420"></a>00420     sinfo_object_cfg_destroy (*cfg);
+<a name="l00421"></a>00421     *cfg=NULL;
+<a name="l00422"></a>00422   }
+<a name="l00423"></a>00423   <span class="keywordflow">return</span>;
+<a name="l00424"></a>00424 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__objnod__ini__by__cpl_8h_source.html b/html/sinfo__objnod__ini__by__cpl_8h_source.html
new file mode 100644
index 0000000..b7590f3
--- /dev/null
+++ b/html/sinfo__objnod__ini__by__cpl_8h_source.html
@@ -0,0 +1,65 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_objnod_ini_by_cpl.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_objnod_ini_by_cpl.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name    :   sinfo_object_ini_by_cpl.h</span>
+<a name="l00022"></a>00022 <span class="comment">   Author       :   Andrea Modigliani</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on   :   May 04, 2004</span>
+<a name="l00024"></a>00024 <span class="comment">   Description  :   cpl input handling for SPIFFIs creation of a data cube</span>
+<a name="l00025"></a>00025 <span class="comment">                        from a science object observation</span>
+<a name="l00026"></a>00026 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00027"></a>00027 <span class="preprocessor">#ifndef SINFO_OBJNOD_INI_BY_CPL_H</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_OBJNOD_INI_BY_CPL_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00030"></a>00030 <span class="comment">                                Includes</span>
+<a name="l00031"></a>00031 <span class="comment">---------------------------------------------------------------------------*/</span>
+<a name="l00032"></a>00032 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00034"></a>00034 <span class="preprocessor">#include "sinfo_object_cfg.h"</span>
+<a name="l00035"></a>00035 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00036"></a>00036 <span class="comment">                             Function prototypes </span>
+<a name="l00037"></a>00037 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00038"></a>00038 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l00051"></a>00051 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00052"></a>00052 
+<a name="l00053"></a>00053 object_config * 
+<a name="l00054"></a>00054 sinfo_parse_cpl_input_objnod(cpl_parameterlist * cpl_cfg, 
+<a name="l00055"></a>00055                              cpl_frameset* sof, 
+<a name="l00056"></a>00056                              cpl_frameset** stk) ;
+<a name="l00057"></a>00057 
+<a name="l00065"></a>00065 <span class="keywordtype">void</span> 
+<a name="l00066"></a>00066 sinfo_objnod_free(object_config ** cfg);
+<a name="l00067"></a>00067 
+<a name="l00068"></a>00068 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__objspider__config_8c_source.html b/html/sinfo__objspider__config_8c_source.html
new file mode 100644
index 0000000..2a97b90
--- /dev/null
+++ b/html/sinfo__objspider__config_8c_source.html
@@ -0,0 +1,314 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_objspider_config.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_objspider_config.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_objspider_config.c,v 1.7 2012/03/03 09:50:08 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the CPL (Common Pipeline Library)</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
+<a name="l00007"></a>00007 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span>
+<a name="l00008"></a>00008 <span class="comment"> * License as published by the Free Software Foundation; either</span>
+<a name="l00009"></a>00009 <span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
+<a name="l00014"></a>00014 <span class="comment"> * Lesser General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
+<a name="l00017"></a>00017 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2012/03/03 09:50:08 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.7 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> */</span>
+<a name="l00026"></a>00026 
+<a name="l00027"></a>00027  <span class="comment">/****************************************************************</span>
+<a name="l00028"></a>00028 <span class="comment">  *   Objspider Frames Data Reduction Parameter Initialization        *</span>
+<a name="l00029"></a>00029 <span class="comment">  ****************************************************************/</span>
+<a name="l00030"></a>00030 
+<a name="l00031"></a>00031 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00032"></a>00032 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00033"></a>00033 <span class="preprocessor">#endif</span>
+<a name="l00034"></a>00034 <span class="preprocessor"></span>
+<a name="l00035"></a>00035 <span class="preprocessor">#include "sinfo_objspider_config.h"</span>
+<a name="l00050"></a>00050 <span class="keywordtype">void</span>
+<a name="l00051"></a>00051  sinfo_objspider_config_add(cpl_parameterlist *list)
+<a name="l00052"></a>00052 {
+<a name="l00053"></a>00053 
+<a name="l00054"></a>00054   cpl_parameter *p;
+<a name="l00055"></a>00055 
+<a name="l00056"></a>00056   <span class="keywordflow">if</span> (!list) {
+<a name="l00057"></a>00057     <span class="keywordflow">return</span>;
+<a name="l00058"></a>00058   }
+<a name="l00059"></a>00059 
+<a name="l00060"></a>00060 
+<a name="l00061"></a>00061   <span class="comment">/* Input file name */</span>
+<a name="l00062"></a>00062   <span class="comment">/* Output file name */</span>
+<a name="l00063"></a>00063   <span class="comment">/* output name of resulting fits wavelength map */</span>
+<a name="l00064"></a>00064   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.objspider.out_filename"</span>,
+<a name="l00065"></a>00065                   CPL_TYPE_STRING,
+<a name="l00066"></a>00066                               <span class="stringliteral">"Output File Name: "</span>,
+<a name="l00067"></a>00067                               <span class="stringliteral">"sinfoni.objspider"</span>,
+<a name="l00068"></a>00068                               SKYSPIDER_OUT_FILENAME);
+<a name="l00069"></a>00069 
+<a name="l00070"></a>00070 
+<a name="l00071"></a>00071   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"out-skyspider_filename"</span>);
+<a name="l00072"></a>00072   cpl_parameterlist_append(list, p);
+<a name="l00073"></a>00073 
+<a name="l00074"></a>00074 
+<a name="l00075"></a>00075   <span class="comment">/*Resampling */</span>
+<a name="l00076"></a>00076  <span class="comment">/* number of coefficients for the polynomial interpolation */</span>
+<a name="l00077"></a>00077   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.objspider.n_coeffs"</span>,
+<a name="l00078"></a>00078                   CPL_TYPE_INT,
+<a name="l00079"></a>00079                               <span class="stringliteral">"number of coefficients for the polynomial "</span>
+<a name="l00080"></a>00080                               <span class="stringliteral">"interpolation "</span>,
+<a name="l00081"></a>00081                               <span class="stringliteral">"sinfoni.objspider"</span>,
+<a name="l00082"></a>00082                                3);
+<a name="l00083"></a>00083 
+<a name="l00084"></a>00084   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"objspider-no-coeffs"</span>);
+<a name="l00085"></a>00085   cpl_parameterlist_append(list, p);
+<a name="l00086"></a>00086 
+<a name="l00087"></a>00087 
+<a name="l00088"></a>00088   <span class="comment">/* Calibration */</span>
+<a name="l00089"></a>00089   <span class="comment">/* indicates if the halogen lamp features from flatfielding should be </span>
+<a name="l00090"></a>00090 <span class="comment">     corrected for or not */</span>
+<a name="l00091"></a>00091   <span class="comment">/*</span>
+<a name="l00092"></a>00092 <span class="comment">  p = cpl_parameter_new_value("sinfoni.objspider.halo_correct_index",</span>
+<a name="l00093"></a>00093 <span class="comment">                  CPL_TYPE_BOOL,</span>
+<a name="l00094"></a>00094 <span class="comment">                              "Halo Correct Index: "</span>
+<a name="l00095"></a>00095 <span class="comment">                               "indicates if the halogen lamp features from "</span>
+<a name="l00096"></a>00096 <span class="comment">                              "flatfielding should be corrected for (TRUE) "</span>
+<a name="l00097"></a>00097 <span class="comment">                              "or not (FALSE)",</span>
+<a name="l00098"></a>00098 <span class="comment">                              "sinfoni.objspider",</span>
+<a name="l00099"></a>00099 <span class="comment">                              FALSE);</span>
+<a name="l00100"></a>00100 <span class="comment"></span>
+<a name="l00101"></a>00101 <span class="comment">  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"objspider-halo-corr-ind");</span>
+<a name="l00102"></a>00102 <span class="comment">  cpl_parameterlist_append(list, p);</span>
+<a name="l00103"></a>00103 <span class="comment">  */</span>
+<a name="l00104"></a>00104 
+<a name="l00105"></a>00105 
+<a name="l00106"></a>00106   <span class="comment">/* Cube Creation */</span>
+<a name="l00107"></a>00107   <span class="comment">/*indicates if the slitlet distances are determined by a north-south-test </span>
+<a name="l00108"></a>00108 <span class="comment">     (yes) or slitlet edge fits (no)</span>
+<a name="l00109"></a>00109 <span class="comment">  */</span>
+<a name="l00110"></a>00110   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.objspider.nord_south_index"</span>,
+<a name="l00111"></a>00111                   CPL_TYPE_BOOL,
+<a name="l00112"></a>00112                               <span class="stringliteral">"Nord South Index Switch: "</span>
+<a name="l00113"></a>00113                                <span class="stringliteral">"indicates if the slitlet distances are "</span>
+<a name="l00114"></a>00114                               <span class="stringliteral">"determined by a north-south-test (TRUE) "</span>
+<a name="l00115"></a>00115                               <span class="stringliteral">"or slitlet edge fits (FALSE)"</span>,
+<a name="l00116"></a>00116                               <span class="stringliteral">"sinfoni.objspider"</span>,
+<a name="l00117"></a>00117                               TRUE);
+<a name="l00118"></a>00118 
+<a name="l00119"></a>00119 
+<a name="l00120"></a>00120   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"objspider-ns-ind"</span>);
+<a name="l00121"></a>00121   cpl_parameterlist_append(list, p);
+<a name="l00122"></a>00122 
+<a name="l00123"></a>00123   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.objspider.slitlets_position_list"</span>,
+<a name="l00124"></a>00124                   CPL_TYPE_STRING,
+<a name="l00125"></a>00125                               <span class="stringliteral">"Slitlets positions filename: "</span>
+<a name="l00126"></a>00126                                <span class="stringliteral">"list of the fitted slitlet edge positions "</span>
+<a name="l00127"></a>00127                               <span class="stringliteral">"or the distances of the slitlets"</span>,
+<a name="l00128"></a>00128                               <span class="stringliteral">"sinfoni.objspider"</span>,
+<a name="l00129"></a>00129                               <span class="stringliteral">"distances.fits"</span>);
+<a name="l00130"></a>00130 
+<a name="l00131"></a>00131 
+<a name="l00132"></a>00132   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"objspider-pos-list"</span>);
+<a name="l00133"></a>00133   cpl_parameterlist_append(list, p);
+<a name="l00134"></a>00134 
+<a name="l00135"></a>00135   <span class="comment">/* number of slitlets (32) */</span>
+<a name="l00136"></a>00136   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.objspider.nslits"</span>,
+<a name="l00137"></a>00137                   CPL_TYPE_INT,
+<a name="l00138"></a>00138                               <span class="stringliteral">"Number of slitlets: "</span>,
+<a name="l00139"></a>00139                               <span class="stringliteral">"sinfoni.objspider"</span>,
+<a name="l00140"></a>00140                               32);
+<a name="l00141"></a>00141 
+<a name="l00142"></a>00142   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"objspider-pos-nslits"</span>);
+<a name="l00143"></a>00143   cpl_parameterlist_append(list, p);
+<a name="l00144"></a>00144 
+<a name="l00145"></a>00145   <span class="comment">/* Fine tuning */</span>
+<a name="l00146"></a>00146   <span class="comment">/* Method */</span>
+<a name="l00147"></a>00147 
+<a name="l00148"></a>00148   p = cpl_parameter_new_enum(<span class="stringliteral">"sinfoni.objspider.fine_tuning_method"</span>,
+<a name="l00149"></a>00149                   CPL_TYPE_STRING,
+<a name="l00150"></a>00150                               <span class="stringliteral">"Fine Tuning Method: "</span>
+<a name="l00151"></a>00151                                <span class="stringliteral">"indicator for the shifting method to use "</span>
+<a name="l00152"></a>00152                               <span class="stringliteral">"(P: polynomial interpolation, "</span>
+<a name="l00153"></a>00153                               <span class="stringliteral">" F: FFT, "</span>
+<a name="l00154"></a>00154                               <span class="stringliteral">" S: cubic spline interpolation)"</span>,
+<a name="l00155"></a>00155                               <span class="stringliteral">"sinfoni.objspider"</span>,
+<a name="l00156"></a>00156                               <span class="stringliteral">"P"</span>,
+<a name="l00157"></a>00157                                3,<span class="stringliteral">"P"</span>,<span class="stringliteral">"F"</span>,<span class="stringliteral">"S"</span>);
+<a name="l00158"></a>00158 
+<a name="l00159"></a>00159   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"objspider-fine-tune-mtd"</span>);
+<a name="l00160"></a>00160   cpl_parameterlist_append(list, p);
+<a name="l00161"></a>00161 
+<a name="l00162"></a>00162   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.objspider.order"</span>,
+<a name="l00163"></a>00163                   CPL_TYPE_INT,
+<a name="l00164"></a>00164                               <span class="stringliteral">"Fine Tuning polynomial order: "</span> 
+<a name="l00165"></a>00165                               <span class="stringliteral">"order of the polynomial if the polynomial "</span>
+<a name="l00166"></a>00166                               <span class="stringliteral">"interpolation shifting method is used."</span>,
+<a name="l00167"></a>00167                               <span class="stringliteral">"sinfoni.objspider"</span>,
+<a name="l00168"></a>00168                               2);
+<a name="l00169"></a>00169 
+<a name="l00170"></a>00170   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"objspider-order"</span>);
+<a name="l00171"></a>00171   cpl_parameterlist_append(list, p);
+<a name="l00172"></a>00172 
+<a name="l00173"></a>00173   <span class="comment">/* Sky Extraction */</span>
+<a name="l00174"></a>00174   <span class="comment">/*Reconstruction */</span>
+<a name="l00175"></a>00175  <span class="comment">/* the fraction [0...1] of rejected low intensity pixels when taking </span>
+<a name="l00176"></a>00176 <span class="comment">the average of columns */</span>
+<a name="l00177"></a>00177   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.objspider.lower_rejection"</span>,
+<a name="l00178"></a>00178                   CPL_TYPE_DOUBLE,
+<a name="l00179"></a>00179                               <span class="stringliteral">"lower rejection: "</span>
+<a name="l00180"></a>00180                               <span class="stringliteral">"percentage of rejected low value pixels "</span>
+<a name="l00181"></a>00181                               <span class="stringliteral">"for averaging the sky spectra"</span>,
+<a name="l00182"></a>00182                               <span class="stringliteral">"sinfoni.objspider"</span>,
+<a name="l00183"></a>00183                               10.);
+<a name="l00184"></a>00184 
+<a name="l00185"></a>00185   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"objspider-lo-rejection"</span>);
+<a name="l00186"></a>00186   cpl_parameterlist_append(list, p);
+<a name="l00187"></a>00187 
+<a name="l00188"></a>00188  <span class="comment">/* the fraction [0...1] of rejected high intensity pixels when taking </span>
+<a name="l00189"></a>00189 <span class="comment">the average of columns */</span>
+<a name="l00190"></a>00190   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.objspider.higher_rejection"</span>,
+<a name="l00191"></a>00191                   CPL_TYPE_DOUBLE,
+<a name="l00192"></a>00192                               <span class="stringliteral">"higher rejection: "</span>
+<a name="l00193"></a>00193                               <span class="stringliteral">"percentage of rejected high value pixels "</span>
+<a name="l00194"></a>00194                               <span class="stringliteral">"for averaging the sky spectra"</span>,
+<a name="l00195"></a>00195                               <span class="stringliteral">"sinfoni.objspider"</span>,
+<a name="l00196"></a>00196                               10.);
+<a name="l00197"></a>00197 
+<a name="l00198"></a>00198   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"objspider-hi-rejection"</span>);
+<a name="l00199"></a>00199   cpl_parameterlist_append(list, p);
+<a name="l00200"></a>00200 
+<a name="l00201"></a>00201   <span class="comment">/* pixel tolerance, this distance tolerance to the diagonal dividing </span>
+<a name="l00202"></a>00202 <span class="comment">     line is not considered for the sky extraction to be sure to have a clean</span>
+<a name="l00203"></a>00203 <span class="comment">     sky due to positioning tolerance and crossing through pixels</span>
+<a name="l00204"></a>00204 <span class="comment">  */</span>
+<a name="l00205"></a>00205 
+<a name="l00206"></a>00206   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.objspider.tolerance"</span>,
+<a name="l00207"></a>00207                   CPL_TYPE_INT,
+<a name="l00208"></a>00208                               <span class="stringliteral">"Tolerance: "</span>
+<a name="l00209"></a>00209                               <span class="stringliteral">"pixel tolerance, this distance tolerance to "</span>
+<a name="l00210"></a>00210                               <span class="stringliteral">"the diagonal dividing line is not considered "</span>
+<a name="l00211"></a>00211                               <span class="stringliteral">"for the sky extraction to be sure to have a "</span>
+<a name="l00212"></a>00212                               <span class="stringliteral">"clean sky due to positioning tolerance and "</span>
+<a name="l00213"></a>00213                               <span class="stringliteral">"crossing through pixels"</span>,
+<a name="l00214"></a>00214                               <span class="stringliteral">"sinfoni.objspider"</span>,
+<a name="l00215"></a>00215                               2);
+<a name="l00216"></a>00216 
+<a name="l00217"></a>00217   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"objspider-tol"</span>);
+<a name="l00218"></a>00218   cpl_parameterlist_append(list, p);
+<a name="l00219"></a>00219 
+<a name="l00220"></a>00220   <span class="comment">/* Jittering */</span>
+<a name="l00221"></a>00221   <span class="comment">/* jitter mode indicator: yes: Auto-Jitter, no: user defined jitter</span>
+<a name="l00222"></a>00222 <span class="comment">     The next three parameters are only used if jitterInd is set to yes, </span>
+<a name="l00223"></a>00223 <span class="comment">     that means in auto-jittering mode!</span>
+<a name="l00224"></a>00224 <span class="comment">  */</span>
+<a name="l00225"></a>00225 
+<a name="l00226"></a>00226   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.objspider.jitter_index"</span>,
+<a name="l00227"></a>00227                   CPL_TYPE_BOOL,
+<a name="l00228"></a>00228                               <span class="stringliteral">"Jitter Index: "</span>
+<a name="l00229"></a>00229                               <span class="stringliteral">"jitter mode indicator: "</span>
+<a name="l00230"></a>00230                               <span class="stringliteral">"TRUE: Auto-Jitter, "</span>
+<a name="l00231"></a>00231                               <span class="stringliteral">"FALSE: user defined jitter"</span>
+<a name="l00232"></a>00232                               <span class="stringliteral">"The size_x size_y kernel_type parameters "</span>
+<a name="l00233"></a>00233                               <span class="stringliteral">"are only used if jitterInd is set to yes, "</span>
+<a name="l00234"></a>00234                               <span class="stringliteral">"that means in auto-jittering mode!"</span>,
+<a name="l00235"></a>00235                                <span class="stringliteral">"sinfoni.objspider"</span>,
+<a name="l00236"></a>00236                               FALSE);
+<a name="l00237"></a>00237 
+<a name="l00238"></a>00238   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"objspider-jit-ind"</span>);
+<a name="l00239"></a>00239   cpl_parameterlist_append(list, p);
+<a name="l00240"></a>00240   <span class="comment">/*x-pixel size of the final combined data cube, must lie between 64 and 128 */</span>
+<a name="l00241"></a>00241 
+<a name="l00242"></a>00242   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.objspider.size_x"</span>,
+<a name="l00243"></a>00243                   CPL_TYPE_INT,
+<a name="l00244"></a>00244                               <span class="stringliteral">"Cube x size: "</span>
+<a name="l00245"></a>00245                               <span class="stringliteral">"x-pixel size of the final combined data cube,"</span>
+<a name="l00246"></a>00246                               <span class="stringliteral">"must lie between 64 and 128. "</span>
+<a name="l00247"></a>00247                               <span class="stringliteral">"If 0 automatic setting."</span>,
+<a name="l00248"></a>00248                               <span class="stringliteral">"sinfoni.objspider"</span>,
+<a name="l00249"></a>00249                               0);
+<a name="l00250"></a>00250 
+<a name="l00251"></a>00251   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"objspider-size-x"</span>);
+<a name="l00252"></a>00252   cpl_parameterlist_append(list, p);
+<a name="l00253"></a>00253   <span class="comment">/*y-pixel size of the final combined data cube, must lie between 64 and 128 */</span>
+<a name="l00254"></a>00254 
+<a name="l00255"></a>00255   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.objspider.size_y"</span>,
+<a name="l00256"></a>00256                   CPL_TYPE_INT,
+<a name="l00257"></a>00257                               <span class="stringliteral">"Cube y size: "</span>
+<a name="l00258"></a>00258                               <span class="stringliteral">"y-pixel size of the final combined data cube,"</span>
+<a name="l00259"></a>00259                               <span class="stringliteral">"must lie between 64 and 128. "</span>
+<a name="l00260"></a>00260                               <span class="stringliteral">"If 0 automatic setting."</span>,
+<a name="l00261"></a>00261                               <span class="stringliteral">"sinfoni.objspider"</span>,
+<a name="l00262"></a>00262                               0);
+<a name="l00263"></a>00263 
+<a name="l00264"></a>00264   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"objspider-size-y"</span>);
+<a name="l00265"></a>00265   cpl_parameterlist_append(list, p);
+<a name="l00266"></a>00266 
+<a name="l00267"></a>00267   <span class="comment">/* Kernel Type */</span>
+<a name="l00268"></a>00268   <span class="comment">/* the name of the interpolation kernel to shift the single cubes  to the </span>
+<a name="l00269"></a>00269 <span class="comment">     correct places inside the big combined cube. That you want to generate </span>
+<a name="l00270"></a>00270 <span class="comment">     using the eclipse routine sinfo_generate_interpolation_kernel()</span>
+<a name="l00271"></a>00271 <span class="comment">     Supported kernels are:</span>
+<a name="l00272"></a>00272 <span class="comment"></span>
+<a name="l00273"></a>00273 <span class="comment">                                     NULL:      default kernel, currently tanh</span>
+<a name="l00274"></a>00274 <span class="comment">                                     default: dito</span>
+<a name="l00275"></a>00275 <span class="comment">                                     tanh:    Hyperbolic tangent</span>
+<a name="l00276"></a>00276 <span class="comment">                                     sinc2:   Square sinc</span>
+<a name="l00277"></a>00277 <span class="comment">                                     lanczos: Lanczos2 kernel</span>
+<a name="l00278"></a>00278 <span class="comment">                                     hamming: Hamming kernel</span>
+<a name="l00279"></a>00279 <span class="comment">                                     hann:    Hann kernel</span>
+<a name="l00280"></a>00280 <span class="comment">  */</span>
+<a name="l00281"></a>00281   p = cpl_parameter_new_enum(<span class="stringliteral">"sinfoni.objspider.kernel_type"</span>,
+<a name="l00282"></a>00282                   CPL_TYPE_STRING,
+<a name="l00283"></a>00283                               <span class="stringliteral">"Kernel Type:"</span>
+<a name="l00284"></a>00284                               <span class="stringliteral">"the name of the interpolation kernel to shift "</span>
+<a name="l00285"></a>00285                               <span class="stringliteral">"the single cubes  to the correct places inside "</span>
+<a name="l00286"></a>00286                  <span class="stringliteral">"the big combined cube"</span>,
+<a name="l00287"></a>00287                               <span class="stringliteral">"sinfoni.objspider"</span>,
+<a name="l00288"></a>00288                               <span class="stringliteral">"tanh"</span>,
+<a name="l00289"></a>00289                                6,<span class="stringliteral">"NULL"</span>,<span class="stringliteral">"default"</span>,<span class="stringliteral">"tanh"</span>,
+<a name="l00290"></a>00290                                <span class="stringliteral">"sinc2"</span>,<span class="stringliteral">"lanczos"</span>,<span class="stringliteral">"hamming"</span>,<span class="stringliteral">"hann"</span>);
+<a name="l00291"></a>00291 
+<a name="l00292"></a>00292   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"objspider-kernel-typ"</span>);
+<a name="l00293"></a>00293   cpl_parameterlist_append(list, p);
+<a name="l00294"></a>00294 
+<a name="l00295"></a>00295   <span class="comment">/* name of the final mask data cube, pixel value 0 if no data available,</span>
+<a name="l00296"></a>00296 <span class="comment">     sum of exposure times in the overlapping regions</span>
+<a name="l00297"></a>00297 <span class="comment">  */</span>
+<a name="l00298"></a>00298 
+<a name="l00299"></a>00299  p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.objspider.mask_name"</span>,
+<a name="l00300"></a>00300                   CPL_TYPE_STRING,
+<a name="l00301"></a>00301                               <span class="stringliteral">"Mask Name: "</span>
+<a name="l00302"></a>00302                               <span class="stringliteral">"name of the final mask data cube, "</span>
+<a name="l00303"></a>00303                               <span class="stringliteral">"pixel value 0 if no data available,"</span>
+<a name="l00304"></a>00304                               <span class="stringliteral">"sum of exposure times in the overlapping "</span>
+<a name="l00305"></a>00305                               <span class="stringliteral">"regions "</span>,
+<a name="l00306"></a>00306                               <span class="stringliteral">"sinfoni.objspider"</span>,
+<a name="l00307"></a>00307                               SKYSPIDER_MASK_OUT_FILENAME);
+<a name="l00308"></a>00308 
+<a name="l00309"></a>00309   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"objspider-mask"</span>);
+<a name="l00310"></a>00310   cpl_parameterlist_append(list, p);
+<a name="l00311"></a>00311 
+<a name="l00312"></a>00312 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__objspider__config_8h_source.html b/html/sinfo__objspider__config_8h_source.html
new file mode 100644
index 0000000..1659a4f
--- /dev/null
+++ b/html/sinfo__objspider__config_8h_source.html
@@ -0,0 +1,49 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_objspider_config.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_objspider_config.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_objspider_config.h,v 1.1 2006/10/20 08:06:32 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the CPL (Common Pipeline Library)</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
+<a name="l00007"></a>00007 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span>
+<a name="l00008"></a>00008 <span class="comment"> * License as published by the Free Software Foundation; either</span>
+<a name="l00009"></a>00009 <span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
+<a name="l00014"></a>00014 <span class="comment"> * Lesser General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
+<a name="l00017"></a>00017 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2006/10/20 08:06:32 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.1 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> */</span>
+<a name="l00026"></a>00026 
+<a name="l00027"></a>00027  <span class="comment">/****************************************************************</span>
+<a name="l00028"></a>00028 <span class="comment">  *   Objspider Frames Data Reduction Parameter Initialization        *</span>
+<a name="l00029"></a>00029 <span class="comment">  ****************************************************************/</span>
+<a name="l00030"></a>00030 <span class="preprocessor">#include "cpl.h"</span>    <span class="comment">/* defines parlist structure */</span>
+<a name="l00031"></a>00031 <span class="preprocessor">#include "sinfo_hidden.h"</span>
+<a name="l00032"></a>00032 <span class="keywordtype">void</span>
+<a name="l00033"></a>00033 sinfo_objspider_config_add(cpl_parameterlist *list);
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__objspider__ini__by__cpl_8c_source.html b/html/sinfo__objspider__ini__by__cpl_8c_source.html
new file mode 100644
index 0000000..0ee80e4
--- /dev/null
+++ b/html/sinfo__objspider__ini__by__cpl_8c_source.html
@@ -0,0 +1,394 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_objspider_ini_by_cpl.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_objspider_ini_by_cpl.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 
+<a name="l00020"></a>00020 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00021"></a>00021 <span class="comment">   </span>
+<a name="l00022"></a>00022 <span class="comment">   File name    :   sinfo_objspider_ini_by_cpl.c</span>
+<a name="l00023"></a>00023 <span class="comment">   Author       :   Andrea Modigliani</span>
+<a name="l00024"></a>00024 <span class="comment">   Created on   :   May 22, 2004</span>
+<a name="l00025"></a>00025 <span class="comment">   Description  :   object cube creation cpl input handling for SPIFFI</span>
+<a name="l00026"></a>00026 <span class="comment"></span>
+<a name="l00027"></a>00027 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00028"></a>00028 
+<a name="l00029"></a>00029 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00031"></a>00031 <span class="preprocessor">#endif</span>
+<a name="l00032"></a>00032 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                                Includes</span>
+<a name="l00034"></a>00034 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 <span class="preprocessor">#include <string.h></span>
+<a name="l00036"></a>00036 <span class="preprocessor">#include "sinfo_objspider_ini_by_cpl.h"</span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include "sinfo_functions.h"</span>
+<a name="l00038"></a>00038 <span class="preprocessor">#include "sinfo_pro_types.h"</span>
+<a name="l00039"></a>00039 <span class="preprocessor">#include "sinfo_hidden.h"</span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include "sinfo_cpl_size.h"</span>
+<a name="l00041"></a>00041 
+<a name="l00042"></a>00042 <span class="preprocessor">#include "sinfo_file_handling.h"</span>
+<a name="l00043"></a>00043 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00044"></a>00044 <span class="comment">                    Functions private to this module</span>
+<a name="l00045"></a>00045 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00046"></a>00046 
+<a name="l00047"></a>00047 <span class="keyword">static</span> <span class="keywordtype">void</span> 
+<a name="l00048"></a>00048 parse_section_frames(object_config *,
+<a name="l00049"></a>00049                      cpl_frameset* sof, cpl_frameset**stk, <span class="keywordtype">int</span>* status);
+<a name="l00050"></a>00050 <span class="keyword">static</span> <span class="keywordtype">void</span> 
+<a name="l00051"></a>00051 parse_section_jittering(object_config *, cpl_parameterlist * cpl_cfg);
+<a name="l00052"></a>00052 <span class="keyword">static</span> <span class="keywordtype">void</span> 
+<a name="l00053"></a>00053 parse_section_resampling(object_config *, cpl_parameterlist * cpl_cfg);
+<a name="l00054"></a>00054 <span class="keyword">static</span> <span class="keywordtype">void</span> 
+<a name="l00055"></a>00055 parse_section_calibration(object_config *);
+<a name="l00056"></a>00056 <span class="keyword">static</span> <span class="keywordtype">void</span> 
+<a name="l00057"></a>00057 parse_section_cubecreation(object_config *, cpl_parameterlist * cpl_cfg);
+<a name="l00058"></a>00058 <span class="keyword">static</span> <span class="keywordtype">void</span> 
+<a name="l00059"></a>00059 parse_section_finetuning(object_config *, cpl_parameterlist * cpl_cfg);
+<a name="l00060"></a>00060 <span class="keyword">static</span> <span class="keywordtype">void</span> 
+<a name="l00061"></a>00061 parse_section_skyextraction(object_config *, cpl_parameterlist * cpl_cfg);
+<a name="l00071"></a>00071 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l00082"></a>00082 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00083"></a>00083 
+<a name="l00084"></a>00084 object_config * 
+<a name="l00085"></a>00085 sinfo_parse_cpl_input_objspider(cpl_parameterlist * cpl_cfg,cpl_frameset* sof,
+<a name="l00086"></a>00086               cpl_frameset** stk)
+<a name="l00087"></a>00087 {
+<a name="l00088"></a>00088    object_config   *  cfg = sinfo_object_cfg_create();
+<a name="l00089"></a>00089    <span class="keywordtype">int</span> status=0;
+<a name="l00090"></a>00090    <span class="comment">/*</span>
+<a name="l00091"></a>00091 <span class="comment">    * Perform sanity checks, fill up the structure with what was</span>
+<a name="l00092"></a>00092 <span class="comment">    * found in the ini file</span>
+<a name="l00093"></a>00093 <span class="comment">    */</span>
+<a name="l00094"></a>00094 
+<a name="l00095"></a>00095    
+<a name="l00096"></a>00096    parse_section_resampling   (cfg, cpl_cfg);
+<a name="l00097"></a>00097    parse_section_calibration  (cfg);
+<a name="l00098"></a>00098    parse_section_cubecreation (cfg, cpl_cfg);
+<a name="l00099"></a>00099    parse_section_finetuning   (cfg, cpl_cfg); 
+<a name="l00100"></a>00100    parse_section_skyextraction(cfg, cpl_cfg); 
+<a name="l00101"></a>00101    parse_section_jittering    (cfg, cpl_cfg);
+<a name="l00102"></a>00102    parse_section_frames       (cfg, sof,stk,&status);
+<a name="l00103"></a>00103    <span class="keywordflow">if</span> (status > 0) {
+<a name="l00104"></a>00104                 <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"parsing cpl input"</span>);
+<a name="l00105"></a>00105                 sinfo_object_cfg_destroy(cfg);
+<a name="l00106"></a>00106                 cfg = NULL ;
+<a name="l00107"></a>00107                 <span class="keywordflow">return</span> NULL ;
+<a name="l00108"></a>00108    }
+<a name="l00109"></a>00109  
+<a name="l00110"></a>00110    <span class="keywordflow">return</span> cfg ;
+<a name="l00111"></a>00111 }
+<a name="l00112"></a>00112 
+<a name="l00113"></a>00113 <span class="keyword">static</span> <span class="keywordtype">void</span>      
+<a name="l00114"></a>00114 parse_section_frames(object_config * cfg, 
+<a name="l00115"></a>00115              cpl_frameset* sof,
+<a name="l00116"></a>00116                      cpl_frameset** stk,
+<a name="l00117"></a>00117                      <span class="keywordtype">int</span>* status)
+<a name="l00118"></a>00118 {
+<a name="l00119"></a>00119    <span class="keywordtype">int</span>                     nraw_good =0;
+<a name="l00120"></a>00120 
+<a name="l00121"></a>00121 
+<a name="l00122"></a>00122 
+<a name="l00123"></a>00123    <span class="keywordtype">int</span> nframes=0;
+<a name="l00124"></a>00124    <span class="keywordtype">int</span> nraw=0;
+<a name="l00125"></a>00125    cpl_frame* frame   = NULL;
+<a name="l00126"></a>00126    <span class="keywordtype">int</span> nstk=0;
+<a name="l00127"></a>00127    cpl_size             *   labels=NULL ;
+<a name="l00128"></a>00128    cpl_size                 nlabels=0 ;
+<a name="l00129"></a>00129    cpl_frameset    *   cur_set=NULL ;
+<a name="l00130"></a>00130    cpl_frame       *   cur_frame=NULL ;
+<a name="l00131"></a>00131    <span class="keywordtype">char</span> * tag=NULL;
+<a name="l00132"></a>00132    <span class="keywordtype">int</span> i=0;
+<a name="l00133"></a>00133    <span class="keywordtype">int</span> wave_map=0;
+<a name="l00134"></a>00134    <span class="keywordtype">int</span> pos_slit=0;
+<a name="l00135"></a>00135    <span class="keywordtype">int</span> first_col=0;
+<a name="l00136"></a>00136    <span class="keywordtype">int</span> halo_sp=0;
+<a name="l00137"></a>00137    <span class="keywordtype">char</span> spat_res[FILE_NAME_SZ];
+<a name="l00138"></a>00138    <span class="keywordtype">char</span> lamp_status[FILE_NAME_SZ];
+<a name="l00139"></a>00139    <span class="keywordtype">char</span> band[FILE_NAME_SZ];
+<a name="l00140"></a>00140    <span class="keywordtype">int</span> ins_set=0;
+<a name="l00141"></a>00141 
+<a name="l00142"></a>00142    nframes = cpl_frameset_get_size(sof);
+<a name="l00143"></a>00143 
+<a name="l00144"></a>00144    <span class="comment">/* Get the raw and the calibration files */</span>
+<a name="l00145"></a>00145    <span class="comment">/* Labelise the input frames according to their tags */</span>
+<a name="l00146"></a>00146    labels = cpl_frameset_labelise(sof, sinfo_compare_tags,&nlabels );
+<a name="l00147"></a>00147    <span class="keywordflow">if</span> (labels == NULL) {
+<a name="l00148"></a>00148      <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>( <span class="stringliteral">"Cannot labelise the input frames"</span>) ;
+<a name="l00149"></a>00149      (*status)++;
+<a name="l00150"></a>00150      return ;
+<a name="l00151"></a>00151    }
+<a name="l00152"></a>00152    <span class="keywordflow">if</span> (nlabels == 1) {
+<a name="l00153"></a>00153       <span class="comment">/* Only one label - all images are objects observations */</span>
+<a name="l00154"></a>00154       <span class="comment">/* Verify that it is really an observation */</span>
+<a name="l00155"></a>00155       cur_frame = cpl_frameset_get_frame(sof, 0) ;
+<a name="l00156"></a>00156       tag = (<span class="keywordtype">char</span>*)cpl_frame_get_tag(cur_frame) ;
+<a name="l00157"></a>00157       <span class="keywordflow">if</span> (sinfo_is_stack(tag)) {
+<a name="l00158"></a>00158     *stk = cpl_frameset_duplicate(sof) ;
+<a name="l00159"></a>00159     nstk++;
+<a name="l00160"></a>00160       }
+<a name="l00161"></a>00161    } <span class="keywordflow">else</span> {
+<a name="l00162"></a>00162      <span class="comment">/* For each label */</span>
+<a name="l00163"></a>00163      <span class="keywordflow">for</span> (i=0 ; i<nlabels ; i++) {
+<a name="l00164"></a>00164        cur_set = cpl_frameset_extract(sof, labels, i) ;
+<a name="l00165"></a>00165        cur_frame = cpl_frameset_get_frame(cur_set, 0) ;
+<a name="l00166"></a>00166        tag = (<span class="keywordtype">char</span>*)cpl_frame_get_tag(cur_frame) ;
+<a name="l00167"></a>00167        <span class="keywordflow">if</span> (sinfo_is_stack(tag) == 1) {
+<a name="l00168"></a>00168      <span class="comment">/* Stacked frame */</span>
+<a name="l00169"></a>00169      *stk = cpl_frameset_duplicate(cur_set) ;
+<a name="l00170"></a>00170      nstk++;
+<a name="l00171"></a>00171        } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (sinfo_is_wavemap(tag)) {
+<a name="l00172"></a>00172      <span class="comment">/* pos slit calibration file */</span>
+<a name="l00173"></a>00173      strcpy(cfg -> wavemap,cpl_strdup(cpl_frame_get_filename(cur_frame)));
+<a name="l00174"></a>00174      wave_map=1;
+<a name="l00175"></a>00175        } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (sinfo_is_distlist(tag)) {
+<a name="l00176"></a>00176      <span class="comment">/* pos slit calibration file */</span>
+<a name="l00177"></a>00177      strcpy(cfg -> poslist,cpl_strdup(cpl_frame_get_filename(cur_frame)));
+<a name="l00178"></a>00178      pos_slit=1;
+<a name="l00179"></a>00179        } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (sinfo_is_firstcol(tag)) { 
+<a name="l00180"></a>00180      <span class="comment">/* first col calibration file */</span>
+<a name="l00181"></a>00181      strcpy(cfg -> firstCol,cpl_strdup(cpl_frame_get_filename(cur_frame)));
+<a name="l00182"></a>00182      first_col=1;
+<a name="l00183"></a>00183        } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (sinfo_is_halosp(tag)) { 
+<a name="l00184"></a>00184      <span class="comment">/* first col calibration file */</span>
+<a name="l00185"></a>00185      strcpy(cfg->halospectrum,cpl_strdup(cpl_frame_get_filename(cur_frame)));
+<a name="l00186"></a>00186      halo_sp=1;
+<a name="l00187"></a>00187        }
+<a name="l00188"></a>00188        cpl_frameset_delete(cur_set) ;
+<a name="l00189"></a>00189      }
+<a name="l00190"></a>00190    }
+<a name="l00191"></a>00191    cpl_free(labels) ;
+<a name="l00192"></a>00192    <span class="keywordflow">if</span> (nstk == 0) {
+<a name="l00193"></a>00193      <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>( <span class="stringliteral">"Cannot find good input frames"</span>) ;
+<a name="l00194"></a>00194      (*status)++;
+<a name="l00195"></a>00195      return ;
+<a name="l00196"></a>00196    }
+<a name="l00197"></a>00197 
+<a name="l00198"></a>00198    <span class="keywordflow">if</span> (wave_map == 0) {
+<a name="l00199"></a>00199      <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>( <span class="stringliteral">"Cannot find wave map"</span>);
+<a name="l00200"></a>00200      (*status)++;
+<a name="l00201"></a>00201      return ;
+<a name="l00202"></a>00202    }
+<a name="l00203"></a>00203    <span class="keywordflow">if</span> (pos_slit == 0) {
+<a name="l00204"></a>00204      <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>( <span class="stringliteral">"Cannot find pos slit"</span>) ;
+<a name="l00205"></a>00205      (*status)++;
+<a name="l00206"></a>00206      return ;
+<a name="l00207"></a>00207    }
+<a name="l00208"></a>00208    <span class="keywordflow">if</span> (first_col == 0) {
+<a name="l00209"></a>00209      <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>( <span class="stringliteral">"Cannot find first col"</span>) ;
+<a name="l00210"></a>00210      (*status)++;
+<a name="l00211"></a>00211      return ;
+<a name="l00212"></a>00212    }
+<a name="l00213"></a>00213 
+<a name="l00214"></a>00214 
+<a name="l00215"></a>00215    <span class="comment">/* TEMPORALLY COMMENTED OUT */</span>
+<a name="l00216"></a>00216    nraw    = cpl_frameset_get_size(*stk);
+<a name="l00217"></a>00217    <span class="comment">/* Test if the rawframes have been found */</span>
+<a name="l00218"></a>00218    <span class="keywordflow">if</span> (nraw < 1) {
+<a name="l00219"></a>00219      <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Cannot find input stacked frames in the input list"</span>) ;
+<a name="l00220"></a>00220      (*status)++;
+<a name="l00221"></a>00221      return ;
+<a name="l00222"></a>00222    }
+<a name="l00223"></a>00223 
+<a name="l00224"></a>00224    nraw    = cpl_frameset_get_size(*stk);
+<a name="l00225"></a>00225    <span class="keywordflow">if</span> (nraw < 1) {
+<a name="l00226"></a>00226      <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no raw frame in input, something wrong!"</span>);
+<a name="l00227"></a>00227      exit(-1);
+<a name="l00228"></a>00228    }
+<a name="l00229"></a>00229 
+<a name="l00230"></a>00230    <span class="comment">/* Allocate structures to go into the blackboard */</span>
+<a name="l00231"></a>00231    cfg->framelist     = cpl_malloc(nraw * <span class="keyword">sizeof</span>(<span class="keywordtype">char</span>*));
+<a name="l00232"></a>00232 
+<a name="l00233"></a>00233   <span class="comment">/* read input frames */</span>
+<a name="l00234"></a>00234    <span class="keywordflow">for</span> (i=0 ; i<nraw ; i++) {
+<a name="l00235"></a>00235      frame = cpl_frameset_get_frame(*stk,i);
+<a name="l00236"></a>00236      <span class="keywordflow">if</span>(sinfo_file_exists((<span class="keywordtype">char</span>*) cpl_frame_get_filename(frame))==1) {
+<a name="l00237"></a>00237        cfg->framelist[i]=cpl_strdup(cpl_frame_get_filename(frame));
+<a name="l00238"></a>00238        nraw_good++;
+<a name="l00239"></a>00239      }
+<a name="l00240"></a>00240      <span class="comment">/* Store file name into framelist */</span>
+<a name="l00241"></a>00241    }
+<a name="l00242"></a>00242    <span class="keywordflow">if</span> (nraw_good < 1) {
+<a name="l00243"></a>00243      <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no good raw frame in input!"</span>);
+<a name="l00244"></a>00244      (*status)++;
+<a name="l00245"></a>00245      <span class="keywordflow">return</span>;
+<a name="l00246"></a>00246    }
+<a name="l00247"></a>00247    <span class="comment">/* Copy relevant information into the blackboard */</span>
+<a name="l00248"></a>00248    cfg->nframes         = nraw ;
+<a name="l00249"></a>00249 
+<a name="l00250"></a>00250    strcpy(cfg -> outName, SKYSPIDER_OUT_FILENAME);
+<a name="l00251"></a>00251    strcpy(cfg -> maskname, SKYSPIDER_MASK_OUT_FILENAME);
+<a name="l00252"></a>00252 
+<a name="l00253"></a>00253 
+<a name="l00254"></a>00254    frame = cpl_frameset_get_frame(*stk,0);
+<a name="l00255"></a>00255 
+<a name="l00256"></a>00256    sinfo_get_spatial_res(frame,spat_res);
+<a name="l00257"></a>00257    <span class="keywordflow">switch</span>(sinfo_frame_is_on(frame)) {
+<a name="l00258"></a>00258 
+<a name="l00259"></a>00259    <span class="keywordflow">case</span> 0: 
+<a name="l00260"></a>00260      strcpy(lamp_status,<span class="stringliteral">"on"</span>);
+<a name="l00261"></a>00261      <span class="keywordflow">break</span>;
+<a name="l00262"></a>00262    <span class="keywordflow">case</span> 1: 
+<a name="l00263"></a>00263      strcpy(lamp_status,<span class="stringliteral">"off"</span>);
+<a name="l00264"></a>00264      <span class="keywordflow">break</span>;
+<a name="l00265"></a>00265    <span class="keywordflow">case</span> -1:
+<a name="l00266"></a>00266      strcpy(lamp_status,<span class="stringliteral">"undefined"</span>);
+<a name="l00267"></a>00267      <span class="keywordflow">break</span>;
+<a name="l00268"></a>00268    <span class="keywordflow">default</span>: 
+<a name="l00269"></a>00269      strcpy(lamp_status,<span class="stringliteral">"undefined"</span>);
+<a name="l00270"></a>00270      <span class="keywordflow">break</span>;
+<a name="l00271"></a>00271    }
+<a name="l00272"></a>00272    sinfo_get_band(frame,band);
+<a name="l00273"></a>00273    sinfo_msg(<span class="stringliteral">"Spatial resolution: %s lamp_status: %s band: %s "</span>,
+<a name="l00274"></a>00274            spat_res,    lamp_status,    band);
+<a name="l00275"></a>00275 
+<a name="l00276"></a>00276 
+<a name="l00277"></a>00277    sinfo_get_ins_set(band,&ins_set);
+<a name="l00278"></a>00278 
+<a name="l00279"></a>00279 
+<a name="l00280"></a>00280 
+<a name="l00281"></a>00281    <span class="keywordflow">return</span>;
+<a name="l00282"></a>00282 }
+<a name="l00283"></a>00283 
+<a name="l00284"></a>00284 
+<a name="l00285"></a>00285 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00286"></a>00286 parse_section_jittering(object_config * cfg,cpl_parameterlist * cpl_cfg)
+<a name="l00287"></a>00287 {
+<a name="l00288"></a>00288   cpl_parameter* p;
+<a name="l00289"></a>00289 
+<a name="l00290"></a>00290   p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.objspider.jitter_index"</span>);
+<a name="l00291"></a>00291   cfg -> jitterind = cpl_parameter_get_bool(p);
+<a name="l00292"></a>00292 
+<a name="l00293"></a>00293   p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.objspider.size_x"</span>);
+<a name="l00294"></a>00294   cfg -> size_x = cpl_parameter_get_int(p);
+<a name="l00295"></a>00295 
+<a name="l00296"></a>00296   p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.objspider.size_y"</span>);
+<a name="l00297"></a>00297   cfg -> size_y = cpl_parameter_get_int(p);
+<a name="l00298"></a>00298 
+<a name="l00299"></a>00299   p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.objspider.kernel_type"</span>);
+<a name="l00300"></a>00300   strcpy(cfg -> kernel_type, cpl_parameter_get_string(p));
+<a name="l00301"></a>00301 
+<a name="l00302"></a>00302   <span class="comment">/*</span>
+<a name="l00303"></a>00303 <span class="comment">  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.mask");</span>
+<a name="l00304"></a>00304 <span class="comment">  strcpy(cfg -> maskname, cpl_parameter_get_string(p));</span>
+<a name="l00305"></a>00305 <span class="comment">  */</span>
+<a name="l00306"></a>00306 
+<a name="l00307"></a>00307 }
+<a name="l00308"></a>00308 
+<a name="l00309"></a>00309 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00310"></a>00310 parse_section_resampling(object_config * cfg,cpl_parameterlist* cpl_cfg)
+<a name="l00311"></a>00311 {
+<a name="l00312"></a>00312   cpl_parameter* p;
+<a name="l00313"></a>00313 
+<a name="l00314"></a>00314   p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.objspider.n_coeffs"</span>);
+<a name="l00315"></a>00315   cfg -> ncoeffs = cpl_parameter_get_int(p);
+<a name="l00316"></a>00316   cfg -> nrows=SINFO_RESAMP_NROWS;
+<a name="l00317"></a>00317 
+<a name="l00318"></a>00318 
+<a name="l00319"></a>00319   return ;
+<a name="l00320"></a>00320 }
+<a name="l00321"></a>00321 
+<a name="l00322"></a>00322 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00323"></a>00323 parse_section_calibration(object_config * cfg)
+<a name="l00324"></a>00324 {
+<a name="l00325"></a>00325   <span class="comment">/*</span>
+<a name="l00326"></a>00326 <span class="comment">  cpl_parameter* p;</span>
+<a name="l00327"></a>00327 <span class="comment">  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.halo_correct_index");</span>
+<a name="l00328"></a>00328 <span class="comment">  cfg -> halocorrectInd = cpl_parameter_get_bool(p);</span>
+<a name="l00329"></a>00329 <span class="comment">  */</span>
+<a name="l00330"></a>00330   cfg -> halocorrectInd=0;
+<a name="l00331"></a>00331 
+<a name="l00332"></a>00332   <span class="comment">/*</span>
+<a name="l00333"></a>00333 <span class="comment">  p=cpl_parameterlist_find(cpl_cfg,"sinfoni.objspider.halo_spectrum_filename");</span>
+<a name="l00334"></a>00334 <span class="comment">  strcpy(cfg -> halospectrum, cpl_parameter_get_string(p));</span>
+<a name="l00335"></a>00335 <span class="comment">  */</span>
+<a name="l00336"></a>00336 
+<a name="l00337"></a>00337 }
+<a name="l00338"></a>00338 
+<a name="l00339"></a>00339 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00340"></a>00340 parse_section_cubecreation(object_config * cfg,cpl_parameterlist* cpl_cfg)
+<a name="l00341"></a>00341 {
+<a name="l00342"></a>00342   cpl_parameter* p;
+<a name="l00343"></a>00343   p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.objspider.nord_south_index"</span>);
+<a name="l00344"></a>00344   cfg -> northsouthInd = cpl_parameter_get_bool(p);
+<a name="l00345"></a>00345 
+<a name="l00346"></a>00346   <span class="comment">/*</span>
+<a name="l00347"></a>00347 <span class="comment">  p=cpl_parameterlist_find(cpl_cfg,"sinfoni.objspider.slitlets_position_list");</span>
+<a name="l00348"></a>00348 <span class="comment">  strcpy(cfg -> poslist, cpl_parameter_get_string(p));</span>
+<a name="l00349"></a>00349 <span class="comment">  */</span>
+<a name="l00350"></a>00350 
+<a name="l00351"></a>00351   p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.objspider.nslits"</span>);
+<a name="l00352"></a>00352   cfg -> nslits = cpl_parameter_get_int(p);
+<a name="l00353"></a>00353 
+<a name="l00354"></a>00354   <span class="comment">/*</span>
+<a name="l00355"></a>00355 <span class="comment">  p=cpl_parameterlist_find(cpl_cfg,"sinfoni.objspider.first_column_filename");</span>
+<a name="l00356"></a>00356 <span class="comment">  strcpy(cfg -> firstCol, cpl_parameter_get_string(p));</span>
+<a name="l00357"></a>00357 <span class="comment">  */</span>
+<a name="l00358"></a>00358 
+<a name="l00359"></a>00359    return ;
+<a name="l00360"></a>00360 }
+<a name="l00361"></a>00361 
+<a name="l00362"></a>00362 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00363"></a>00363 parse_section_finetuning(object_config * cfg,cpl_parameterlist* cpl_cfg)
+<a name="l00364"></a>00364 {
+<a name="l00365"></a>00365   cpl_parameter* p;
+<a name="l00366"></a>00366 
+<a name="l00367"></a>00367   p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.objspider.fine_tuning_method"</span>);
+<a name="l00368"></a>00368   strcpy(cfg -> method, cpl_parameter_get_string(p));
+<a name="l00369"></a>00369 
+<a name="l00370"></a>00370   p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.objspider.order"</span>);
+<a name="l00371"></a>00371   cfg -> order = cpl_parameter_get_int(p);
+<a name="l00372"></a>00372 
+<a name="l00373"></a>00373 }
+<a name="l00374"></a>00374 
+<a name="l00375"></a>00375 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00376"></a>00376 parse_section_skyextraction(object_config * cfg,cpl_parameterlist* cpl_cfg)
+<a name="l00377"></a>00377 {
+<a name="l00378"></a>00378 
+<a name="l00379"></a>00379   cpl_parameter* p;
+<a name="l00380"></a>00380   p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.objspider.lower_rejection"</span>);
+<a name="l00381"></a>00381   cfg -> loReject = (float) cpl_parameter_get_double(p);
+<a name="l00382"></a>00382 
+<a name="l00383"></a>00383   p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.objspider.higher_rejection"</span>);
+<a name="l00384"></a>00384   cfg -> hiReject = (float) cpl_parameter_get_double(p);
+<a name="l00385"></a>00385 
+<a name="l00386"></a>00386   p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.objspider.tolerance"</span>);
+<a name="l00387"></a>00387   cfg -> tolerance = cpl_parameter_get_int(p);
+<a name="l00388"></a>00388 
+<a name="l00389"></a>00389 }
+<a name="l00390"></a>00390 
+<a name="l00391"></a>00391 <span class="comment">/*-----------------------------------------------------------------*/</span>
+<a name="l00392"></a>00392 <span class="keywordtype">void</span>
+<a name="l00393"></a>00393 sinfo_objspider_free(object_config * cfg) {
+<a name="l00394"></a>00394   cpl_free(cfg->framelist);
+<a name="l00395"></a>00395   sinfo_object_cfg_destroy (cfg);
+<a name="l00396"></a>00396   <span class="keywordflow">return</span>;
+<a name="l00397"></a>00397 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__objspider__ini__by__cpl_8h_source.html b/html/sinfo__objspider__ini__by__cpl_8h_source.html
new file mode 100644
index 0000000..33316f5
--- /dev/null
+++ b/html/sinfo__objspider__ini__by__cpl_8h_source.html
@@ -0,0 +1,63 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_objspider_ini_by_cpl.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_objspider_ini_by_cpl.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name    :   sinfo_object_ini_by_cpl.h</span>
+<a name="l00022"></a>00022 <span class="comment">   Author       :   Andrea Modigliani</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on   :   May 04, 2004</span>
+<a name="l00024"></a>00024 <span class="comment">   Description  :   cpl input handling for SPIFFIs creation of a data cube</span>
+<a name="l00025"></a>00025 <span class="comment">                        from a science object observation</span>
+<a name="l00026"></a>00026 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00027"></a>00027 <span class="preprocessor">#ifndef SINFO_OBJSPIDER_INI_BY_CPL_H</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_OBJSPIDER_INI_BY_CPL_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00030"></a>00030 <span class="comment">                                Includes</span>
+<a name="l00031"></a>00031 <span class="comment">---------------------------------------------------------------------------*/</span>
+<a name="l00032"></a>00032 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include "sinfo_object_cfg.h"</span>
+<a name="l00034"></a>00034 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00035"></a>00035 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00036"></a>00036 <span class="comment">                             Function prototypes </span>
+<a name="l00037"></a>00037 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00038"></a>00038 
+<a name="l00052"></a>00052 object_config * 
+<a name="l00053"></a>00053 sinfo_parse_cpl_input_objspider(cpl_parameterlist * cpl_cfg, 
+<a name="l00054"></a>00054                                 cpl_frameset* sof, 
+<a name="l00055"></a>00055                                 cpl_frameset** stk) ;
+<a name="l00056"></a>00056 
+<a name="l00064"></a>00064 <span class="keywordtype">void</span> 
+<a name="l00065"></a>00065 sinfo_objspider_free(object_config * cfg);
+<a name="l00066"></a>00066 
+<a name="l00067"></a>00067 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__pfits_8c_source.html b/html/sinfo__pfits_8c_source.html
new file mode 100644
index 0000000..b203cc5
--- /dev/null
+++ b/html/sinfo__pfits_8c_source.html
@@ -0,0 +1,743 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_pfits.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_pfits.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_pfits.c,v 1.14 2012/05/04 08:11:07 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the SINFONI Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2012/05/04 08:11:07 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.14 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span><span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00032"></a>00032 <span class="comment">                                   Includes</span>
+<a name="l00033"></a>00033 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00034"></a>00034 <span class="preprocessor">#include <ctype.h></span>
+<a name="l00035"></a>00035 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00036"></a>00036 <span class="preprocessor">#include "sinfo_pfits.h"</span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include "sinfo_key_names.h"</span>
+<a name="l00038"></a>00038 <span class="preprocessor">#include "sinfo_utils_wrappers.h"</span>
+<a name="l00039"></a>00039 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include <string.h></span>
+<a name="l00041"></a>00041 
+<a name="l00042"></a>00042 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00043"></a>00043 <span class="preprocessor">#define ASCIILINESZ                         1024</span>
+<a name="l00044"></a>00044 <span class="preprocessor"></span><span class="preprocessor">#define PAF_MAGIC_SZ               13</span>
+<a name="l00045"></a>00045 <span class="preprocessor"></span><span class="preprocessor">#define PAF_MAGIC       "PAF.HDR.START"</span>
+<a name="l00046"></a>00046 <span class="preprocessor"></span>
+<a name="l00047"></a>00047 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00048"></a>00048 <span class="comment">                              Function codes</span>
+<a name="l00049"></a>00049 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00050"></a>00050 <span class="keywordtype">char</span> * sinfo_paf_query(
+<a name="l00051"></a>00051         <span class="keywordtype">char</span>    *   filename,
+<a name="l00052"></a>00052         <span class="keywordtype">char</span>    *   key) ;
+<a name="l00053"></a>00053 
+<a name="l00054"></a>00054 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_is_paf_file(<span class="keywordtype">char</span> * filename) ;
+<a name="l00055"></a>00055 
+<a name="l00056"></a>00056 <span class="keyword">static</span> <span class="keywordtype">char</span> * sinfo_strcrop(<span class="keywordtype">char</span> * s);
+<a name="l00057"></a>00057 
+<a name="l00058"></a>00058 
+<a name="l00067"></a>00067 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00080"></a>00080 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00081"></a>00081 <span class="keyword">static</span> <span class="keywordtype">char</span> * sinfo_strcrop(<span class="keywordtype">char</span> * s)
+<a name="l00082"></a>00082 {
+<a name="l00083"></a>00083     <span class="keyword">static</span> <span class="keywordtype">char</span> l[ASCIILINESZ+1];
+<a name="l00084"></a>00084     <span class="keywordtype">char</span> * last ;
+<a name="l00085"></a>00085 
+<a name="l00086"></a>00086     <span class="keywordflow">if</span> (s==NULL) <span class="keywordflow">return</span> NULL ;
+<a name="l00087"></a>00087     memset(l, 0, ASCIILINESZ+1);
+<a name="l00088"></a>00088     strcpy(l, s);
+<a name="l00089"></a>00089     last = l + strlen(l);
+<a name="l00090"></a>00090     <span class="keywordflow">while</span> (last > l) {
+<a name="l00091"></a>00091         <span class="keywordflow">if</span> (!isspace((<span class="keywordtype">int</span>)*(last-1)))
+<a name="l00092"></a>00092             break ;
+<a name="l00093"></a>00093         last -- ;
+<a name="l00094"></a>00094     }
+<a name="l00095"></a>00095     *last = (char)0;
+<a name="l00096"></a>00096     <span class="keywordflow">return</span> l ;
+<a name="l00097"></a>00097 }
+<a name="l00098"></a>00098 
+<a name="l00099"></a>00099 
+<a name="l00100"></a>00100 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00113"></a>00113 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00114"></a>00114 <span class="keywordtype">char</span> * sinfo_paf_query(
+<a name="l00115"></a>00115         <span class="keywordtype">char</span>    *   filename, 
+<a name="l00116"></a>00116         <span class="keywordtype">char</span>    *   key)
+<a name="l00117"></a>00117 {
+<a name="l00118"></a>00118     <span class="keyword">static</span> <span class="keywordtype">char</span> value[ASCIILINESZ];
+<a name="l00119"></a>00119     FILE    *    paf ;
+<a name="l00120"></a>00120     <span class="keywordtype">char</span>        line[ASCIILINESZ+1];
+<a name="l00121"></a>00121     <span class="keywordtype">char</span>        val[ASCIILINESZ+1];
+<a name="l00122"></a>00122     <span class="keywordtype">char</span>        head[ASCIILINESZ+1];
+<a name="l00123"></a>00123     <span class="keywordtype">int</span>            found ;
+<a name="l00124"></a>00124     <span class="keywordtype">int</span>            len ;
+<a name="l00125"></a>00125 
+<a name="l00126"></a>00126     <span class="comment">/* Check inputs */</span>
+<a name="l00127"></a>00127     <span class="keywordflow">if</span> (filename==NULL || key==NULL) <span class="keywordflow">return</span> NULL ;
+<a name="l00128"></a>00128 
+<a name="l00129"></a>00129     <span class="comment">/* Check PAF validity */</span>
+<a name="l00130"></a>00130     <span class="keywordflow">if</span> (sinfo_is_paf_file(filename)!=1) {
+<a name="l00131"></a>00131         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"not a PAF file: [%s]"</span>, filename);
+<a name="l00132"></a>00132         <span class="keywordflow">return</span> NULL ;
+<a name="l00133"></a>00133     }
+<a name="l00134"></a>00134 
+<a name="l00135"></a>00135     <span class="comment">/* Open file and read it */</span>
+<a name="l00136"></a>00136     paf = fopen(filename, <span class="stringliteral">"r"</span>);
+<a name="l00137"></a>00137     <span class="keywordflow">if</span> (paf==NULL) {
+<a name="l00138"></a>00138         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"opening [%s]"</span>, filename);
+<a name="l00139"></a>00139         <span class="keywordflow">return</span> NULL ;
+<a name="l00140"></a>00140     }
+<a name="l00141"></a>00141     
+<a name="l00142"></a>00142     found = 0 ;
+<a name="l00143"></a>00143     <span class="keywordflow">while</span> (fgets(line, ASCIILINESZ, paf)!=NULL) {
+<a name="l00144"></a>00144         sscanf(line, <span class="stringliteral">"%[^ ]"</span>, head);
+<a name="l00145"></a>00145         <span class="keywordflow">if</span> (!strcmp(head, key)) {
+<a name="l00146"></a>00146             <span class="comment">/* Get value */</span>
+<a name="l00147"></a>00147             sscanf(line, <span class="stringliteral">"%*[^ ] %[^;]"</span>, value);
+<a name="l00148"></a>00148             found ++ ;
+<a name="l00149"></a>00149             break ;
+<a name="l00150"></a>00150         }
+<a name="l00151"></a>00151     }
+<a name="l00152"></a>00152     <span class="keywordflow">if</span> (!found) {
+<a name="l00153"></a>00153       fclose(paf);
+<a name="l00154"></a>00154       <span class="keywordflow">return</span> NULL ;
+<a name="l00155"></a>00155     }
+<a name="l00156"></a>00156     
+<a name="l00157"></a>00157     <span class="comment">/* Remove trailing blanks */</span>
+<a name="l00158"></a>00158     strcpy(val, sinfo_strcrop(value));
+<a name="l00159"></a>00159     <span class="comment">/* Get rid of possible quotes */</span>
+<a name="l00160"></a>00160     len = strlen(val);
+<a name="l00161"></a>00161     <span class="keywordflow">if</span> (val[0]==<span class="charliteral">'\"'</span> && val[len-1]==<span class="charliteral">'\"'</span>) {
+<a name="l00162"></a>00162         strncpy(value, val+1, len-2);
+<a name="l00163"></a>00163         value[len-2]=(char)0;
+<a name="l00164"></a>00164     } <span class="keywordflow">else</span> {
+<a name="l00165"></a>00165         strcpy(value, val);
+<a name="l00166"></a>00166     }
+<a name="l00167"></a>00167     <span class="keywordflow">if</span>(paf!=NULL){
+<a name="l00168"></a>00168        fclose(paf);
+<a name="l00169"></a>00169     }
+<a name="l00170"></a>00170     <span class="keywordflow">return</span> value ;
+<a name="l00171"></a>00171 }
+<a name="l00172"></a>00172 
+<a name="l00173"></a>00173 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00182"></a>00182 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00183"></a>00183 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_is_paf_file(<span class="keywordtype">char</span> * filename)
+<a name="l00184"></a>00184 {
+<a name="l00185"></a>00185     FILE    *    fp ;
+<a name="l00186"></a>00186     <span class="keywordtype">int</span>            is_paf ;
+<a name="l00187"></a>00187     <span class="keywordtype">char</span>        line[ASCIILINESZ] ;
+<a name="l00188"></a>00188     
+<a name="l00189"></a>00189     <span class="keywordflow">if</span> (filename==NULL) <span class="keywordflow">return</span> -1 ;
+<a name="l00190"></a>00190 
+<a name="l00191"></a>00191     <span class="comment">/* Initialize is_paf */</span>
+<a name="l00192"></a>00192     is_paf = 0 ;
+<a name="l00193"></a>00193 
+<a name="l00194"></a>00194     <span class="comment">/* Open file */</span>
+<a name="l00195"></a>00195     <span class="keywordflow">if</span> ((fp = fopen(filename, <span class="stringliteral">"r"</span>))==NULL) {
+<a name="l00196"></a>00196         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"cannot open file [%s]"</span>, filename) ;
+<a name="l00197"></a>00197         <span class="keywordflow">return</span> -1 ;
+<a name="l00198"></a>00198     }
+<a name="l00199"></a>00199 
+<a name="l00200"></a>00200     <span class="comment">/* Parse file */</span>
+<a name="l00201"></a>00201     <span class="keywordflow">while</span> (fgets(line, ASCIILINESZ, fp) != NULL) {
+<a name="l00202"></a>00202         <span class="keywordflow">if</span> (line[0] != <span class="charliteral">'#'</span>) {
+<a name="l00203"></a>00203            <span class="keywordflow">if</span> (!strncmp(line, PAF_MAGIC, PAF_MAGIC_SZ)) is_paf = 1 ;
+<a name="l00204"></a>00204              (void)fclose(fp) ;
+<a name="l00205"></a>00205             <span class="keywordflow">return</span> is_paf ;
+<a name="l00206"></a>00206         }
+<a name="l00207"></a>00207     }
+<a name="l00208"></a>00208 
+<a name="l00209"></a>00209     (void)fclose(fp) ;
+<a name="l00210"></a>00210     <span class="keywordflow">return</span> is_paf ;
+<a name="l00211"></a>00211 }
+<a name="l00212"></a>00212 
+<a name="l00213"></a>00213 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00219"></a>00219 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00220"></a>00220 <span class="keywordtype">char</span> * sinfo_pfits_get_mode(<span class="keyword">const</span> cpl_propertylist * plist)
+<a name="l00221"></a>00221 {
+<a name="l00222"></a>00222 
+<a name="l00223"></a>00223    <span class="keywordflow">return</span> (<span class="keywordtype">char</span>*) cpl_propertylist_get_string(plist,<span class="stringliteral">"ESO DET MODE NAME"</span>);
+<a name="l00224"></a>00224   
+<a name="l00225"></a>00225 }
+<a name="l00226"></a>00226 
+<a name="l00227"></a>00227 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00233"></a>00233 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00234"></a>00234 <span class="keywordtype">double</span> sinfo_pfits_get_exp_time(<span class="keyword">const</span> cpl_propertylist* plist)
+<a name="l00235"></a>00235 {
+<a name="l00236"></a>00236   
+<a name="l00237"></a>00237     <span class="keywordflow">return</span> cpl_propertylist_get_double(plist,<span class="stringliteral">"EXPTIME"</span>);
+<a name="l00238"></a>00238 
+<a name="l00239"></a>00239 }
+<a name="l00240"></a>00240 
+<a name="l00241"></a>00241 
+<a name="l00242"></a>00242 
+<a name="l00243"></a>00243 
+<a name="l00244"></a>00244 
+<a name="l00245"></a>00245 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00246"></a>00246 <span class="comment">   Function     :       sinfo_pfits_get_ditndit()</span>
+<a name="l00247"></a>00247 <span class="comment">   In           :       fits file name</span>
+<a name="l00248"></a>00248 <span class="comment">   Out          :       total integration time in sec</span>
+<a name="l00249"></a>00249 <span class="comment">   Job          :       reads the product dit*ndit from the FITS-header </span>
+<a name="l00250"></a>00250 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00251"></a>00251 <span class="keywordtype">double</span> sinfo_pfits_get_ditndit(<span class="keyword">const</span> <span class="keywordtype">char</span>* name)
+<a name="l00252"></a>00252 {
+<a name="l00253"></a>00253   <span class="keywordtype">double</span> dit;
+<a name="l00254"></a>00254   <span class="keywordtype">int</span> ndit=0;
+<a name="l00255"></a>00255   cpl_propertylist* plist=NULL;
+<a name="l00256"></a>00256   plist=cpl_propertylist_load(name,0);
+<a name="l00257"></a>00257 
+<a name="l00258"></a>00258   dit = cpl_propertylist_get_double(plist,<span class="stringliteral">"ESO DET DIT"</span>);
+<a name="l00259"></a>00259   ndit = cpl_propertylist_get_int(plist,<span class="stringliteral">"ESO DET NDIT"</span>);
+<a name="l00260"></a>00260   sinfo_free_propertylist(&plist);
+<a name="l00261"></a>00261   <span class="keywordflow">return</span> dit*ndit ;
+<a name="l00262"></a>00262 
+<a name="l00263"></a>00263 }
+<a name="l00264"></a>00264 
+<a name="l00265"></a>00265 
+<a name="l00266"></a>00266 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00272"></a>00272 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00273"></a>00273 <span class="keywordtype">double</span> sinfo_pfits_get_exptime(<span class="keyword">const</span> <span class="keywordtype">char</span> * filename)
+<a name="l00274"></a>00274 {
+<a name="l00275"></a>00275     <span class="keywordtype">double</span> exptime ;
+<a name="l00276"></a>00276     cpl_propertylist* plist=NULL;
+<a name="l00277"></a>00277     plist=cpl_propertylist_load(filename,0);
+<a name="l00278"></a>00278     exptime = cpl_propertylist_get_double(plist,<span class="stringliteral">"EXPTIME"</span>);
+<a name="l00279"></a>00279     sinfo_free_propertylist(&plist);
+<a name="l00280"></a>00280     
+<a name="l00281"></a>00281     <span class="keywordflow">return</span> exptime;
+<a name="l00282"></a>00282 }
+<a name="l00283"></a>00283 
+<a name="l00284"></a>00284 
+<a name="l00285"></a>00285 
+<a name="l00286"></a>00286 
+<a name="l00287"></a>00287 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00293"></a>00293 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00294"></a>00294 <span class="keywordtype">int</span> sinfo_pfits_get_rom(<span class="keyword">const</span> cpl_propertylist * plist)
+<a name="l00295"></a>00295 {
+<a name="l00296"></a>00296 
+<a name="l00297"></a>00297     <span class="keywordflow">return</span>  cpl_propertylist_get_int(plist,<span class="stringliteral">"ESO DET NCORRS"</span>);
+<a name="l00298"></a>00298 
+<a name="l00299"></a>00299 }
+<a name="l00300"></a>00300 
+<a name="l00301"></a>00301 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00307"></a>00307 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00308"></a>00308 <span class="keywordtype">int</span> sinfo_pfits_get_expno(<span class="keyword">const</span> cpl_propertylist * plist)
+<a name="l00309"></a>00309 {
+<a name="l00310"></a>00310     
+<a name="l00311"></a>00311    <span class="keywordflow">return</span> cpl_propertylist_get_int(plist,<span class="stringliteral">"ESO TPL EXPNO"</span>);
+<a name="l00312"></a>00312 
+<a name="l00313"></a>00313 }
+<a name="l00314"></a>00314 
+<a name="l00315"></a>00315 
+<a name="l00316"></a>00316 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00322"></a>00322 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00323"></a>00323 <span class="keywordtype">double</span> sinfo_pfits_get_airmass_start(<span class="keyword">const</span> cpl_propertylist * plist)
+<a name="l00324"></a>00324 {
+<a name="l00325"></a>00325 
+<a name="l00326"></a>00326     <span class="keywordflow">return</span> cpl_propertylist_get_double(plist,<span class="stringliteral">"ESO TEL AIRM START"</span>);
+<a name="l00327"></a>00327 
+<a name="l00328"></a>00328 }
+<a name="l00329"></a>00329 
+<a name="l00330"></a>00330 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00336"></a>00336 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00337"></a>00337 <span class="keywordtype">double</span> sinfo_pfits_get_airmass_end(<span class="keyword">const</span> cpl_propertylist * plist)
+<a name="l00338"></a>00338 {
+<a name="l00339"></a>00339     <span class="keywordflow">return</span> cpl_propertylist_get_double(plist,<span class="stringliteral">"ESO TEL AIRM END"</span>);
+<a name="l00340"></a>00340 
+<a name="l00341"></a>00341 }
+<a name="l00342"></a>00342 
+<a name="l00343"></a>00343 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00349"></a>00349 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00350"></a>00350 <span class="keywordtype">double</span> sinfo_pfits_get_alpha(<span class="keyword">const</span> cpl_propertylist * plist)
+<a name="l00351"></a>00351 {
+<a name="l00352"></a>00352   <span class="keywordflow">return</span> cpl_propertylist_get_double(plist,<span class="stringliteral">"ESO TEL TARG OFFSETALPHA"</span>);
+<a name="l00353"></a>00353 }
+<a name="l00354"></a>00354 
+<a name="l00355"></a>00355 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00361"></a>00361 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00362"></a>00362 <span class="keywordtype">double</span> sinfo_pfits_get_targ_alpha(<span class="keyword">const</span> cpl_propertylist * plist)
+<a name="l00363"></a>00363 {
+<a name="l00364"></a>00364   <span class="keywordflow">return</span> cpl_propertylist_get_double(plist,<span class="stringliteral">"ESO INS TARG ALPHA"</span>);
+<a name="l00365"></a>00365 }
+<a name="l00366"></a>00366 
+<a name="l00367"></a>00367 
+<a name="l00368"></a>00368 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00374"></a>00374 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00375"></a>00375 <span class="keywordtype">double</span> sinfo_pfits_get_targ_delta(<span class="keyword">const</span> cpl_propertylist * plist)
+<a name="l00376"></a>00376 {
+<a name="l00377"></a>00377   <span class="keywordflow">return</span> cpl_propertylist_get_double(plist,<span class="stringliteral">"ESO INS TARG DELTA"</span>);
+<a name="l00378"></a>00378 }
+<a name="l00379"></a>00379 
+<a name="l00380"></a>00380 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00386"></a>00386 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00387"></a>00387 <span class="keyword">const</span> <span class="keywordtype">char</span> * sinfo_pfits_get_arcfile(<span class="keyword">const</span> cpl_propertylist * plist)
+<a name="l00388"></a>00388 {
+<a name="l00389"></a>00389     <span class="keywordflow">return</span> (<span class="keyword">const</span> <span class="keywordtype">char</span>*) cpl_propertylist_get_string(plist,KEY_NAME_ARCFILE);
+<a name="l00390"></a>00390 }
+<a name="l00391"></a>00391 
+<a name="l00392"></a>00392 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00398"></a>00398 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00399"></a>00399 <span class="keyword">const</span> <span class="keywordtype">char</span> * sinfo_pfits_get_rec1raw1name(<span class="keyword">const</span> cpl_propertylist * plist)
+<a name="l00400"></a>00400 {
+<a name="l00401"></a>00401     <span class="keywordflow">return</span> (<span class="keyword">const</span> <span class="keywordtype">char</span>*) cpl_propertylist_get_string(plist,
+<a name="l00402"></a>00402                                                   KEY_NAME_PRO_REC1_RAW1_NAME);
+<a name="l00403"></a>00403 }
+<a name="l00404"></a>00404 
+<a name="l00405"></a>00405 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00411"></a>00411 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00412"></a>00412 <span class="keyword">const</span> <span class="keywordtype">char</span> * sinfo_pfits_get_ins_setup(<span class="keyword">const</span> cpl_propertylist * plist)
+<a name="l00413"></a>00413 {
+<a name="l00414"></a>00414   <span class="keywordflow">if</span>(cpl_propertylist_get_string(plist,<span class="stringliteral">"ESO INS SETUP ID"</span>)) {
+<a name="l00415"></a>00415     <span class="keywordflow">return</span> (<span class="keyword">const</span> <span class="keywordtype">char</span>*) cpl_propertylist_get_string(plist,<span class="stringliteral">"ESO INS SETUP ID"</span>);
+<a name="l00416"></a>00416   } <span class="keywordflow">else</span> {
+<a name="l00417"></a>00417     cpl_error_reset();
+<a name="l00418"></a>00418     <span class="keywordflow">return</span> <span class="stringliteral">"Dark"</span>;
+<a name="l00419"></a>00419   }
+<a name="l00420"></a>00420 
+<a name="l00421"></a>00421 }
+<a name="l00422"></a>00422 
+<a name="l00423"></a>00423 
+<a name="l00424"></a>00424 
+<a name="l00425"></a>00425 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00431"></a>00431 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00432"></a>00432 <span class="keywordtype">double</span> sinfo_pfits_get_wlen(<span class="keyword">const</span> cpl_propertylist * plist)
+<a name="l00433"></a>00433 {
+<a name="l00434"></a>00434 
+<a name="l00435"></a>00435     <span class="keywordflow">return</span> cpl_propertylist_get_double(plist,<span class="stringliteral">"ESO INS GRAT1 WLEN"</span>);
+<a name="l00436"></a>00436 }
+<a name="l00437"></a>00437 
+<a name="l00438"></a>00438 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00444"></a>00444 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00445"></a>00445 <span class="keywordtype">int</span> sinfo_pfits_get_chop_ncycles(<span class="keyword">const</span> cpl_propertylist * plist)
+<a name="l00446"></a>00446 {
+<a name="l00447"></a>00447 
+<a name="l00448"></a>00448     <span class="keywordflow">return</span> cpl_propertylist_get_int(plist,<span class="stringliteral">"ESO DET CHOP NCYCLES"</span>);
+<a name="l00449"></a>00449 
+<a name="l00450"></a>00450 }
+<a name="l00451"></a>00451 
+<a name="l00452"></a>00452 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00458"></a>00458 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00459"></a>00459 <span class="keywordtype">double</span> sinfo_pfits_get_pixscale(<span class="keyword">const</span> cpl_propertylist * plist)
+<a name="l00460"></a>00460 {
+<a name="l00461"></a>00461   <span class="keyword">const</span> <span class="keywordtype">char</span>* val=NULL;
+<a name="l00462"></a>00462   val=cpl_propertylist_get_string(plist,<span class="stringliteral">"ESO INS OPTI1 NAME"</span>);
+<a name="l00463"></a>00463   <span class="keywordflow">return</span> atof(val);
+<a name="l00464"></a>00464 }
+<a name="l00465"></a>00465 
+<a name="l00466"></a>00466 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00472"></a>00472 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00473"></a>00473 <span class="keywordtype">double</span> sinfo_pfits_get_posangle(<span class="keyword">const</span> cpl_propertylist * plist)
+<a name="l00474"></a>00474 {
+<a name="l00475"></a>00475     <span class="keywordflow">return</span> cpl_propertylist_get_double(plist,<span class="stringliteral">"ESO ADA POSANG"</span>);
+<a name="l00476"></a>00476 }
+<a name="l00477"></a>00477 
+<a name="l00478"></a>00478 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00484"></a>00484 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00485"></a>00485 <span class="keywordtype">double</span> sinfo_pfits_get_DEC(<span class="keyword">const</span> cpl_propertylist * plist)
+<a name="l00486"></a>00486 {
+<a name="l00487"></a>00487     <span class="keywordflow">return</span> cpl_propertylist_get_double(plist,<span class="stringliteral">"DEC"</span>);
+<a name="l00488"></a>00488 }
+<a name="l00489"></a>00489 
+<a name="l00490"></a>00490 
+<a name="l00491"></a>00491 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00497"></a>00497 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00498"></a>00498 <span class="keywordtype">double</span> sinfo_pfits_get_cumoffsetx(<span class="keyword">const</span> cpl_propertylist * plist)
+<a name="l00499"></a>00499 {
+<a name="l00500"></a>00500     <span class="keywordflow">return</span> cpl_propertylist_get_double(plist,<span class="stringliteral">"ESO SEQ CUMOFFSETX"</span>);
+<a name="l00501"></a>00501 }
+<a name="l00502"></a>00502 
+<a name="l00503"></a>00503 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00509"></a>00509 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00510"></a>00510 <span class="keywordtype">double</span> sinfo_pfits_get_cumoffsety(<span class="keyword">const</span> cpl_propertylist * plist)
+<a name="l00511"></a>00511 {
+<a name="l00512"></a>00512     <span class="keywordflow">return</span> cpl_propertylist_get_double(plist,<span class="stringliteral">"ESO SEQ CUMOFFSETY"</span>);
+<a name="l00513"></a>00513 }
+<a name="l00514"></a>00514 
+<a name="l00515"></a>00515 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00521"></a>00521 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00522"></a>00522 <span class="keyword">const</span> <span class="keywordtype">char</span> * sinfo_pfits_get_date_obs(<span class="keyword">const</span> cpl_propertylist * plist)
+<a name="l00523"></a>00523 {
+<a name="l00524"></a>00524 
+<a name="l00525"></a>00525     <span class="keywordflow">return</span> (<span class="keyword">const</span> <span class="keywordtype">char</span>*) cpl_propertylist_get_string(plist,<span class="stringliteral">"DATE-OBS"</span>);
+<a name="l00526"></a>00526 
+<a name="l00527"></a>00527 }
+<a name="l00528"></a>00528         
+<a name="l00529"></a>00529 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00535"></a>00535 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00536"></a>00536 <span class="keywordtype">double</span>  sinfo_pfits_get_delta(<span class="keyword">const</span> cpl_propertylist * plist)
+<a name="l00537"></a>00537 {
+<a name="l00538"></a>00538 
+<a name="l00539"></a>00539     <span class="keywordflow">return</span> cpl_propertylist_get_double(plist,<span class="stringliteral">"ESO TEL TARG OFFSETDELTA"</span>);
+<a name="l00540"></a>00540 
+<a name="l00541"></a>00541 }
+<a name="l00542"></a>00542 
+<a name="l00543"></a>00543 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00549"></a>00549 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00550"></a>00550 <span class="keywordtype">double</span>  sinfo_pfits_get_dec(<span class="keyword">const</span> cpl_propertylist * plist)
+<a name="l00551"></a>00551 {
+<a name="l00552"></a>00552     <span class="keywordflow">return</span> cpl_propertylist_get_double(plist,<span class="stringliteral">"DEC"</span>);
+<a name="l00553"></a>00553 }
+<a name="l00554"></a>00554 
+<a name="l00555"></a>00555 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00562"></a>00562 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00563"></a>00563 <span class="keywordtype">double</span> sinfo_pfits_get_dit(<span class="keyword">const</span> cpl_propertylist * plist)
+<a name="l00564"></a>00564 {
+<a name="l00565"></a>00565     <span class="keywordflow">return</span> cpl_propertylist_get_double(plist,<span class="stringliteral">"ESO DET DIT"</span>);
+<a name="l00566"></a>00566 }
+<a name="l00567"></a>00567 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00573"></a>00573 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00574"></a>00574 <span class="keywordtype">float</span> sinfo_pfits_get_pixelscale(<span class="keyword">const</span> <span class="keywordtype">char</span> * name)
+<a name="l00575"></a>00575 {
+<a name="l00576"></a>00576   cpl_propertylist* plist=NULL;
+<a name="l00577"></a>00577   <span class="keywordtype">float</span> pixscale=0;
+<a name="l00578"></a>00578   <span class="keyword">const</span> <span class="keywordtype">char</span>* scale=NULL;
+<a name="l00579"></a>00579   plist=cpl_propertylist_load(name,0);
+<a name="l00580"></a>00580   scale= cpl_propertylist_get_string(plist,<span class="stringliteral">"ESO INS OPTI1 NAME"</span>);
+<a name="l00581"></a>00581   pixscale=atof(scale);
+<a name="l00582"></a>00582   sinfo_free_propertylist(&plist);
+<a name="l00583"></a>00583   <span class="keywordflow">return</span> pixscale;
+<a name="l00584"></a>00584 }
+<a name="l00585"></a>00585 
+<a name="l00586"></a>00586 
+<a name="l00587"></a>00587 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00594"></a>00594 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00595"></a>00595 <span class="keyword">const</span> <span class="keywordtype">char</span> * sinfo_pfits_get_ncorrs_name(<span class="keyword">const</span> cpl_propertylist * plist)
+<a name="l00596"></a>00596 {
+<a name="l00597"></a>00597     <span class="keywordflow">return</span> cpl_propertylist_get_string(plist,<span class="stringliteral">"ESO DET NCORRS NAME"</span>);
+<a name="l00598"></a>00598 }
+<a name="l00599"></a>00599 
+<a name="l00600"></a>00600 
+<a name="l00601"></a>00601 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00608"></a>00608 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00609"></a>00609 <span class="keyword">const</span> <span class="keywordtype">char</span> * sinfo_pfits_get_band(<span class="keyword">const</span> cpl_propertylist * plist)
+<a name="l00610"></a>00610 {
+<a name="l00611"></a>00611     <span class="keywordflow">return</span> cpl_propertylist_get_string(plist,<span class="stringliteral">"ESO INS FILT1 NAME"</span>);
+<a name="l00612"></a>00612 }
+<a name="l00613"></a>00613 
+<a name="l00614"></a>00614 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00620"></a>00620 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00621"></a>00621 <span class="keyword">const</span> <span class="keywordtype">char</span> * sinfo_pfits_get_dpr_catg(<span class="keyword">const</span> cpl_propertylist * plist)
+<a name="l00622"></a>00622 {
+<a name="l00623"></a>00623     <span class="keywordflow">return</span> cpl_propertylist_get_string(plist,<span class="stringliteral">"ESO DPR CATG"</span>);
+<a name="l00624"></a>00624 }
+<a name="l00625"></a>00625 
+<a name="l00626"></a>00626 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00632"></a>00632 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00633"></a>00633 <span class="keyword">const</span> <span class="keywordtype">char</span> * sinfo_pfits_get_dpr_tech(<span class="keyword">const</span> cpl_propertylist * plist)
+<a name="l00634"></a>00634 {
+<a name="l00635"></a>00635     <span class="keywordflow">return</span> cpl_propertylist_get_string(plist,<span class="stringliteral">"ESO DPR TECH"</span>);
+<a name="l00636"></a>00636 }
+<a name="l00637"></a>00637 
+<a name="l00638"></a>00638 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00644"></a>00644 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00645"></a>00645 <span class="keyword">const</span> <span class="keywordtype">char</span> * sinfo_pfits_get_dpr_type(<span class="keyword">const</span> cpl_propertylist * plist)
+<a name="l00646"></a>00646 {
+<a name="l00647"></a>00647     <span class="keywordflow">return</span> cpl_propertylist_get_string(plist,<span class="stringliteral">"ESO DPR TYPE"</span>);
+<a name="l00648"></a>00648 }
+<a name="l00649"></a>00649 
+<a name="l00650"></a>00650 
+<a name="l00651"></a>00651 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00657"></a>00657 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00658"></a>00658 <span class="keyword">const</span> <span class="keywordtype">char</span> * sinfo_pfits_get_filter_im(<span class="keyword">const</span> cpl_propertylist * plist)
+<a name="l00659"></a>00659 {
+<a name="l00660"></a>00660   <span class="keywordflow">return</span> cpl_propertylist_get_string(plist,<span class="stringliteral">"ESO INS FILT1 NAME"</span>);
+<a name="l00661"></a>00661 }
+<a name="l00662"></a>00662 
+<a name="l00663"></a>00663 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00669"></a>00669 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00670"></a>00670 <span class="keyword">const</span> <span class="keywordtype">char</span> * sinfo_pfits_get_filter_spec(<span class="keyword">const</span> cpl_propertylist * plist)
+<a name="l00671"></a>00671 {
+<a name="l00672"></a>00672     <span class="keywordflow">return</span> cpl_propertylist_get_string(plist,<span class="stringliteral">"ESO INS FILT2 NAME"</span>);
+<a name="l00673"></a>00673 }
+<a name="l00674"></a>00674 
+<a name="l00675"></a>00675 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00681"></a>00681 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00682"></a>00682 <span class="keywordtype">double</span> sinfo_pfits_get_focus(<span class="keyword">const</span> cpl_propertylist * plist)
+<a name="l00683"></a>00683 {
+<a name="l00684"></a>00684     <span class="keywordflow">return</span> cpl_propertylist_get_double(plist,<span class="stringliteral">"ESO TEL FOCU LEN"</span>);
+<a name="l00685"></a>00685 }
+<a name="l00686"></a>00686 
+<a name="l00687"></a>00687 
+<a name="l00688"></a>00688 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00694"></a>00694 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00695"></a>00695 <span class="keyword">const</span> <span class="keywordtype">char</span> * sinfo_pfits_get_frame_type(<span class="keyword">const</span> cpl_propertylist * plist)
+<a name="l00696"></a>00696 {
+<a name="l00697"></a>00697     <span class="keywordflow">return</span> cpl_propertylist_get_string(plist,<span class="stringliteral">"ESO DET FRAM TYPE"</span>);
+<a name="l00698"></a>00698 }
+<a name="l00699"></a>00699 
+<a name="l00700"></a>00700 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00706"></a>00706 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00707"></a>00707 <span class="keyword">const</span> <span class="keywordtype">char</span> * sinfo_pfits_get_instrument(<span class="keyword">const</span> cpl_propertylist * plist)
+<a name="l00708"></a>00708 {
+<a name="l00709"></a>00709     <span class="keywordflow">return</span> cpl_propertylist_get_string(plist,<span class="stringliteral">"INSTRUME"</span>);
+<a name="l00710"></a>00710 }
+<a name="l00711"></a>00711 
+<a name="l00712"></a>00712 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00718"></a>00718 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00719"></a>00719 <span class="keywordtype">double</span> sinfo_pfits_get_mjdobs(<span class="keyword">const</span> cpl_propertylist * plist)
+<a name="l00720"></a>00720 {
+<a name="l00721"></a>00721     <span class="keywordflow">return</span> cpl_propertylist_get_double(plist,<span class="stringliteral">"MJD-OBS"</span>);
+<a name="l00722"></a>00722 }
+<a name="l00723"></a>00723 
+<a name="l00724"></a>00724 
+<a name="l00725"></a>00725 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00731"></a>00731 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00732"></a>00732 <span class="keywordtype">double</span> sinfo_pfits_get_monoc_pos(<span class="keyword">const</span> cpl_propertylist * plist)
+<a name="l00733"></a>00733 {
+<a name="l00734"></a>00734     <span class="keywordflow">return</span> cpl_propertylist_get_double(plist,<span class="stringliteral">"INS MONOC1 POS"</span>);
+<a name="l00735"></a>00735 }
+<a name="l00736"></a>00736 
+<a name="l00737"></a>00737 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00743"></a>00743 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00744"></a>00744 <span class="keywordtype">int</span> sinfo_pfits_get_ndit(<span class="keyword">const</span> cpl_propertylist * plist)
+<a name="l00745"></a>00745 {
+<a name="l00746"></a>00746     <span class="keywordflow">return</span> cpl_propertylist_get_int(plist,<span class="stringliteral">"ESO DET NDIT"</span>);
+<a name="l00747"></a>00747 }
+<a name="l00748"></a>00748 
+<a name="l00749"></a>00749 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00755"></a>00755 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00756"></a>00756 <span class="keywordtype">int</span> sinfo_pfits_get_naxis1(<span class="keyword">const</span> cpl_propertylist * plist)
+<a name="l00757"></a>00757 {
+<a name="l00758"></a>00758     <span class="keywordflow">return</span> cpl_propertylist_get_int(plist,<span class="stringliteral">"NAXIS1"</span>);
+<a name="l00759"></a>00759 }
+<a name="l00760"></a>00760 
+<a name="l00761"></a>00761 
+<a name="l00762"></a>00762 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00768"></a>00768 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00769"></a>00769 <span class="keywordtype">int</span> sinfo_pfits_get_naxis2(<span class="keyword">const</span> cpl_propertylist * plist)
+<a name="l00770"></a>00770 {
+<a name="l00771"></a>00771     <span class="keywordflow">return</span> cpl_propertylist_get_int(plist,<span class="stringliteral">"NAXIS2"</span>);
+<a name="l00772"></a>00772 }
+<a name="l00773"></a>00773 
+<a name="l00774"></a>00774 
+<a name="l00775"></a>00775 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00781"></a>00781 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00782"></a>00782 <span class="keywordtype">int</span> sinfo_pfits_get_naxis3(<span class="keyword">const</span> cpl_propertylist * plist)
+<a name="l00783"></a>00783 {
+<a name="l00784"></a>00784     <span class="keywordflow">return</span> cpl_propertylist_get_int(plist,<span class="stringliteral">"NAXIS3"</span>);
+<a name="l00785"></a>00785 }
+<a name="l00786"></a>00786 
+<a name="l00787"></a>00787 
+<a name="l00788"></a>00788 
+<a name="l00789"></a>00789 
+<a name="l00790"></a>00790 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00796"></a>00796 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00797"></a>00797 <span class="keywordtype">double</span> sinfo_pfits_get_crpix1(<span class="keyword">const</span> cpl_propertylist * plist)
+<a name="l00798"></a>00798 {
+<a name="l00799"></a>00799     <span class="keywordflow">return</span> cpl_propertylist_get_double(plist,<span class="stringliteral">"CRPIX1"</span>);
+<a name="l00800"></a>00800 }
+<a name="l00801"></a>00801 
+<a name="l00802"></a>00802 
+<a name="l00803"></a>00803 
+<a name="l00804"></a>00804 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00810"></a>00810 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00811"></a>00811 <span class="keywordtype">double</span> sinfo_pfits_get_crpix2(<span class="keyword">const</span> cpl_propertylist * plist)
+<a name="l00812"></a>00812 {
+<a name="l00813"></a>00813     <span class="keywordflow">return</span> cpl_propertylist_get_double(plist,<span class="stringliteral">"CRPIX2"</span>);
+<a name="l00814"></a>00814 }
+<a name="l00815"></a>00815 
+<a name="l00816"></a>00816 
+<a name="l00817"></a>00817 
+<a name="l00818"></a>00818 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00824"></a>00824 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00825"></a>00825 <span class="keywordtype">double</span> sinfo_pfits_get_crpix3(<span class="keyword">const</span> cpl_propertylist * plist)
+<a name="l00826"></a>00826 {
+<a name="l00827"></a>00827     <span class="keywordflow">return</span> cpl_propertylist_get_double(plist,<span class="stringliteral">"CRPIX3"</span>);
+<a name="l00828"></a>00828 }
+<a name="l00829"></a>00829 
+<a name="l00830"></a>00830 
+<a name="l00831"></a>00831 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00837"></a>00837 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00838"></a>00838 <span class="keywordtype">double</span> sinfo_pfits_get_cdelt1(<span class="keyword">const</span> cpl_propertylist * plist)
+<a name="l00839"></a>00839 {
+<a name="l00840"></a>00840     <span class="keywordflow">return</span> cpl_propertylist_get_double(plist,<span class="stringliteral">"CDELT1"</span>);
+<a name="l00841"></a>00841 }
+<a name="l00842"></a>00842 
+<a name="l00843"></a>00843 
+<a name="l00844"></a>00844 
+<a name="l00845"></a>00845 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00851"></a>00851 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00852"></a>00852 <span class="keywordtype">double</span> sinfo_pfits_get_cdelt2(<span class="keyword">const</span> cpl_propertylist * plist)
+<a name="l00853"></a>00853 {
+<a name="l00854"></a>00854     <span class="keywordflow">return</span> cpl_propertylist_get_double(plist,<span class="stringliteral">"CDELT2"</span>);
+<a name="l00855"></a>00855 }
+<a name="l00856"></a>00856 
+<a name="l00857"></a>00857 
+<a name="l00858"></a>00858 
+<a name="l00859"></a>00859 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00865"></a>00865 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00866"></a>00866 <span class="keywordtype">double</span> sinfo_pfits_get_cdelt3(<span class="keyword">const</span> cpl_propertylist * plist)
+<a name="l00867"></a>00867 {
+<a name="l00868"></a>00868     <span class="keywordflow">return</span> cpl_propertylist_get_double(plist,<span class="stringliteral">"CDELT3"</span>);
+<a name="l00869"></a>00869 }
+<a name="l00870"></a>00870 
+<a name="l00871"></a>00871 
+<a name="l00872"></a>00872 
+<a name="l00873"></a>00873 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00879"></a>00879 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00880"></a>00880 <span class="keywordtype">double</span> sinfo_pfits_get_crval1(<span class="keyword">const</span> cpl_propertylist * plist)
+<a name="l00881"></a>00881 {
+<a name="l00882"></a>00882     <span class="keywordflow">return</span> cpl_propertylist_get_double(plist,<span class="stringliteral">"CRVAL1"</span>);
+<a name="l00883"></a>00883 }
+<a name="l00884"></a>00884 
+<a name="l00885"></a>00885 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00891"></a>00891 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00892"></a>00892 <span class="keywordtype">double</span> sinfo_pfits_get_crval2(<span class="keyword">const</span> cpl_propertylist * plist)
+<a name="l00893"></a>00893 {
+<a name="l00894"></a>00894     <span class="keywordflow">return</span> cpl_propertylist_get_double(plist,<span class="stringliteral">"CRVAL2"</span>);
+<a name="l00895"></a>00895 }
+<a name="l00896"></a>00896 
+<a name="l00897"></a>00897 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00903"></a>00903 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00904"></a>00904 <span class="keywordtype">double</span> sinfo_pfits_get_crval3(<span class="keyword">const</span> cpl_propertylist * plist)
+<a name="l00905"></a>00905 {
+<a name="l00906"></a>00906     <span class="keywordflow">return</span> cpl_propertylist_get_double(plist,<span class="stringliteral">"CRVAL3"</span>);
+<a name="l00907"></a>00907 }
+<a name="l00908"></a>00908 
+<a name="l00909"></a>00909 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00915"></a>00915 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00916"></a>00916 <span class="keywordtype">int</span> sinfo_pfits_get_numbexp(<span class="keyword">const</span> cpl_propertylist * plist)
+<a name="l00917"></a>00917 {
+<a name="l00918"></a>00918     <span class="keywordflow">return</span> cpl_propertylist_get_int(plist,<span class="stringliteral">"ESO TPL NEXP"</span>);
+<a name="l00919"></a>00919 }
+<a name="l00920"></a>00920 
+<a name="l00921"></a>00921 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00927"></a>00927 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00928"></a>00928 <span class="keyword">const</span> <span class="keywordtype">char</span> * sinfo_pfits_get_obs_id(<span class="keyword">const</span> cpl_propertylist * plist)
+<a name="l00929"></a>00929 {
+<a name="l00930"></a>00930     <span class="keywordflow">return</span> cpl_propertylist_get_string(plist,<span class="stringliteral">"ESO OBS ID"</span>);
+<a name="l00931"></a>00931 }
+<a name="l00932"></a>00932 
+<a name="l00933"></a>00933 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00939"></a>00939 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00940"></a>00940 <span class="keywordtype">int</span> sinfo_pfits_get_nodpos(<span class="keyword">const</span> cpl_propertylist * plist)
+<a name="l00941"></a>00941 {
+<a name="l00942"></a>00942     <span class="keywordflow">return</span> cpl_propertylist_get_int(plist,<span class="stringliteral">"ESO SEQ NODPOS"</span>);
+<a name="l00943"></a>00943 }
+<a name="l00944"></a>00944 
+<a name="l00945"></a>00945 
+<a name="l00946"></a>00946 
+<a name="l00947"></a>00947 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00953"></a>00953 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00954"></a>00954 <span class="keywordtype">double</span> sinfo_pfits_get_ra(<span class="keyword">const</span> cpl_propertylist * plist)
+<a name="l00955"></a>00955 {
+<a name="l00956"></a>00956     <span class="keywordflow">return</span> cpl_propertylist_get_double(plist,<span class="stringliteral">"RA"</span>);
+<a name="l00957"></a>00957 }
+<a name="l00958"></a>00958 
+<a name="l00959"></a>00959 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00965"></a>00965 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00966"></a>00966 <span class="keyword">const</span> <span class="keywordtype">char</span> * sinfo_pfits_get_starname(<span class="keyword">const</span> cpl_propertylist * plist)
+<a name="l00967"></a>00967 {
+<a name="l00968"></a>00968     <span class="keywordflow">return</span> cpl_propertylist_get_string(plist,<span class="stringliteral">"ESO OBS TARG NAME"</span>);
+<a name="l00969"></a>00969 }
+<a name="l00970"></a>00970 
+<a name="l00971"></a>00971 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00977"></a>00977 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00978"></a>00978 <span class="keywordtype">double</span> sinfo_pfits_get_resol(<span class="keyword">const</span> cpl_propertylist * plist)
+<a name="l00979"></a>00979 {
+<a name="l00980"></a>00980     <span class="keywordflow">return</span> cpl_propertylist_get_double(plist,<span class="stringliteral">"ESO INS RESOL"</span>);
+<a name="l00981"></a>00981 }
+<a name="l00982"></a>00982 
+<a name="l00983"></a>00983 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00989"></a>00989 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00990"></a>00990 <span class="keyword">const</span> <span class="keywordtype">char</span> * sinfo_pfits_get_templateid(<span class="keyword">const</span> cpl_propertylist * plist)
+<a name="l00991"></a>00991 {
+<a name="l00992"></a>00992     <span class="keywordflow">return</span> (<span class="keyword">const</span> <span class="keywordtype">char</span>*) cpl_propertylist_get_string(plist,<span class="stringliteral">"ESO TPL ID"</span>); 
+<a name="l00993"></a>00993 }
+<a name="l01002"></a>01002 <span class="keyword">static</span> cpl_error_code
+<a name="l01003"></a>01003 sinfo_plist_set_extra_common_keys(cpl_propertylist* plist)
+<a name="l01004"></a>01004 {
+<a name="l01005"></a>01005 
+<a name="l01006"></a>01006     cpl_propertylist_append_string(plist,<span class="stringliteral">"HDUCLASS"</span>, <span class="stringliteral">"ESO"</span>) ;
+<a name="l01007"></a>01007     cpl_propertylist_set_comment(plist,<span class="stringliteral">"HDUCLASS"</span>,<span class="stringliteral">"hdu classification"</span>) ;
+<a name="l01008"></a>01008 
+<a name="l01009"></a>01009     cpl_propertylist_append_string(plist,<span class="stringliteral">"HDUDOC"</span>, <span class="stringliteral">"DICD"</span>) ;
+<a name="l01010"></a>01010     cpl_propertylist_set_comment(plist,<span class="stringliteral">"HDUDOC"</span>,<span class="stringliteral">"hdu reference document"</span>) ;
+<a name="l01011"></a>01011 
+<a name="l01012"></a>01012     cpl_propertylist_append_string(plist,<span class="stringliteral">"HDUVERS"</span>, <span class="stringliteral">"DICD V6.0"</span>) ;
+<a name="l01013"></a>01013     cpl_propertylist_set_comment(plist,<span class="stringliteral">"HDUVERS"</span>,<span class="stringliteral">"hdu reference document version"</span>) ;
+<a name="l01014"></a>01014 
+<a name="l01015"></a>01015     <span class="keywordflow">return</span> cpl_error_get_code();
+<a name="l01016"></a>01016 }
+<a name="l01017"></a>01017 
+<a name="l01030"></a>01030 cpl_error_code
+<a name="l01031"></a>01031 sinfo_plist_set_extra_keys(cpl_propertylist* plist,
+<a name="l01032"></a>01032              <span class="keyword">const</span> <span class="keywordtype">char</span>* hduclas1,
+<a name="l01033"></a>01033              <span class="keyword">const</span> <span class="keywordtype">char</span>* hduclas2,
+<a name="l01034"></a>01034              <span class="keyword">const</span> <span class="keywordtype">char</span>* hduclas3,
+<a name="l01035"></a>01035              <span class="keyword">const</span> <span class="keywordtype">char</span>* scidata,
+<a name="l01036"></a>01036              <span class="keyword">const</span> <span class="keywordtype">char</span>* errdata,
+<a name="l01037"></a>01037              <span class="keyword">const</span> <span class="keywordtype">char</span>* qualdata,
+<a name="l01038"></a>01038                          <span class="keyword">const</span> <span class="keywordtype">int</span> type)
+<a name="l01039"></a>01039 {
+<a name="l01040"></a>01040 
+<a name="l01041"></a>01041   cpl_ensure_code(type<3,CPL_ERROR_ILLEGAL_INPUT);
+<a name="l01042"></a>01042   cpl_ensure_code(type>=0,CPL_ERROR_ILLEGAL_INPUT);
+<a name="l01043"></a>01043 
+<a name="l01044"></a>01044   sinfo_plist_set_extra_common_keys(plist);
+<a name="l01045"></a>01045 
+<a name="l01046"></a>01046   cpl_propertylist_append_string(plist,<span class="stringliteral">"HDUCLAS1"</span>,hduclas1) ;
+<a name="l01047"></a>01047   cpl_propertylist_set_comment(plist,<span class="stringliteral">"HDUCLAS1"</span>,<span class="stringliteral">"hdu format classification"</span>) ;
+<a name="l01048"></a>01048 
+<a name="l01049"></a>01049   cpl_propertylist_append_string(plist,<span class="stringliteral">"HDUCLAS2"</span>,hduclas2) ;
+<a name="l01050"></a>01050   cpl_propertylist_set_comment(plist,<span class="stringliteral">"HDUCLAS2"</span>,<span class="stringliteral">"hdu type classification"</span>) ;
+<a name="l01051"></a>01051 
+<a name="l01052"></a>01052   <span class="keywordflow">if</span>(type!=0) {
+<a name="l01053"></a>01053     cpl_propertylist_append_string(plist,<span class="stringliteral">"HDUCLAS3"</span>,hduclas3) ;
+<a name="l01054"></a>01054     cpl_propertylist_set_comment(plist,<span class="stringliteral">"HDUCLAS3"</span>,<span class="stringliteral">"hdu info classification"</span>) ;
+<a name="l01055"></a>01055     cpl_propertylist_append_string(plist,<span class="stringliteral">"SCIDATA"</span>,scidata) ;
+<a name="l01056"></a>01056     cpl_propertylist_set_comment(plist,<span class="stringliteral">"SCIDATA"</span>,<span class="stringliteral">"name of data extension"</span>) ;
+<a name="l01057"></a>01057   }
+<a name="l01058"></a>01058 
+<a name="l01059"></a>01059   <span class="keywordflow">if</span>(type!=1) {
+<a name="l01060"></a>01060 <span class="comment">/* CASA prefers to have these not set if the extension actually does not exist</span>
+<a name="l01061"></a>01061 <span class="comment">    cpl_propertylist_append_string(plist,"ERRDATA",errdata) ;</span>
+<a name="l01062"></a>01062 <span class="comment">    cpl_propertylist_set_comment(plist,"ERRDATA","name of errs extension") ;</span>
+<a name="l01063"></a>01063 <span class="comment">*/</span>
+<a name="l01064"></a>01064   }
+<a name="l01065"></a>01065 
+<a name="l01066"></a>01066   <span class="keywordflow">if</span>(type!=2) {
+<a name="l01067"></a>01067 <span class="comment">/* CASA prefers to have these not set if the extension actually does not exist</span>
+<a name="l01068"></a>01068 <span class="comment">    cpl_propertylist_append_string(plist,"QUALDATA",qualdata) ;</span>
+<a name="l01069"></a>01069 <span class="comment">    cpl_propertylist_set_comment(plist,"QUALDATA","name of qual extension") ;</span>
+<a name="l01070"></a>01070 <span class="comment">*/</span>
+<a name="l01071"></a>01071   }
+<a name="l01072"></a>01072 
+<a name="l01073"></a>01073   <span class="keywordflow">return</span> cpl_error_get_code();
+<a name="l01074"></a>01074 }
+<a name="l01075"></a>01075 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__pfits_8h_source.html b/html/sinfo__pfits_8h_source.html
new file mode 100644
index 0000000..84e9e0c
--- /dev/null
+++ b/html/sinfo__pfits_8h_source.html
@@ -0,0 +1,143 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_pfits.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_pfits.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_pfits.h,v 1.6 2012/03/22 15:26:10 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the NACO Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2012/03/22 15:26:10 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.6 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifndef SINFO_PFITS_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_PFITS_H</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span>
+<a name="l00031"></a>00031 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00032"></a>00032 <span class="comment">                                   Includes</span>
+<a name="l00033"></a>00033 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00034"></a>00034 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00035"></a>00035 
+<a name="l00036"></a>00036 <span class="comment">/*</span>
+<a name="l00037"></a>00037 <span class="comment">#include <sinfo_dfs.h></span>
+<a name="l00038"></a>00038 <span class="comment">*/</span>
+<a name="l00039"></a>00039 
+<a name="l00040"></a>00040 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00041"></a>00041 <span class="comment">                                   Functions prototypes</span>
+<a name="l00042"></a>00042 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00043"></a>00043 
+<a name="l00044"></a>00044 CPL_BEGIN_DECLS
+<a name="l00045"></a>00045 <span class="keyword">const</span> <span class="keywordtype">char</span> * sinfo_pfits_get_rec1raw1name(<span class="keyword">const</span> cpl_propertylist * plist) ;
+<a name="l00046"></a>00046 <span class="keyword">const</span> <span class="keywordtype">char</span> * sinfo_pfits_get_band(<span class="keyword">const</span> cpl_propertylist * plist);
+<a name="l00047"></a>00047 <span class="keywordtype">float</span> sinfo_pfits_get_pixelscale (<span class="keyword">const</span> <span class="keywordtype">char</span> * filename );
+<a name="l00048"></a>00048 <span class="keywordtype">double</span> sinfo_pfits_get_targ_alpha(<span class="keyword">const</span> cpl_propertylist * plist);
+<a name="l00049"></a>00049 <span class="keywordtype">double</span> sinfo_pfits_get_targ_delta(<span class="keyword">const</span> cpl_propertylist * plist);
+<a name="l00050"></a>00050 
+<a name="l00051"></a>00051 <span class="comment">/*</span>
+<a name="l00052"></a>00052 <span class="comment">char * sinfo_pfits_get_rec1raw1name(const char * filename) ;</span>
+<a name="l00053"></a>00053 <span class="comment">*/</span>
+<a name="l00054"></a>00054 <span class="keywordtype">int</span> sinfo_pfits_get_expno(<span class="keyword">const</span> cpl_propertylist *) ;
+<a name="l00055"></a>00055 <span class="keywordtype">double</span>  sinfo_pfits_get_exptime(<span class="keyword">const</span> <span class="keywordtype">char</span> *) ;
+<a name="l00056"></a>00056 <span class="keywordtype">char</span> * sinfo_pfits_get_mode(<span class="keyword">const</span> cpl_propertylist *) ;
+<a name="l00057"></a>00057 
+<a name="l00058"></a>00058 <span class="keywordtype">double</span> sinfo_pfits_get_pixscale(<span class="keyword">const</span> cpl_propertylist * plist);
+<a name="l00059"></a>00059 <span class="keywordtype">double</span> sinfo_pfits_get_exp_time(<span class="keyword">const</span> cpl_propertylist* plist);
+<a name="l00060"></a>00060 <span class="keywordtype">double</span> sinfo_pfits_get_DEC(<span class="keyword">const</span> cpl_propertylist * plist);
+<a name="l00061"></a>00061 <span class="keywordtype">double</span> sinfo_pfits_get_posangle(<span class="keyword">const</span> cpl_propertylist * plist);
+<a name="l00062"></a>00062 <span class="keywordtype">int</span> sinfo_pfits_get_rom(<span class="keyword">const</span> cpl_propertylist * propertylist);
+<a name="l00063"></a>00063 <span class="keyword">const</span> <span class="keywordtype">char</span> * sinfo_pfits_get_ncorrs_name(<span class="keyword">const</span> cpl_propertylist * plist) ;
+<a name="l00064"></a>00064 <span class="keyword">const</span> <span class="keywordtype">char</span> * sinfo_pfits_get_date_obs(<span class="keyword">const</span> cpl_propertylist * plist) ;
+<a name="l00065"></a>00065 <span class="keyword">const</span> <span class="keywordtype">char</span> * sinfo_pfits_get_ins_setup(<span class="keyword">const</span> cpl_propertylist * plist);
+<a name="l00066"></a>00066 <span class="keywordtype">double</span> sinfo_pfits_get_airmass_start(<span class="keyword">const</span> cpl_propertylist * plist) ;
+<a name="l00067"></a>00067 <span class="keyword">const</span> <span class="keywordtype">char</span> * sinfo_pfits_get_templateid(<span class="keyword">const</span> cpl_propertylist * plist) ;
+<a name="l00068"></a>00068 <span class="keywordtype">double</span> sinfo_pfits_get_dit(<span class="keyword">const</span> cpl_propertylist * plist) ;
+<a name="l00069"></a>00069 <span class="keywordtype">int</span>    sinfo_pfits_get_ndit(<span class="keyword">const</span> cpl_propertylist * plist) ;
+<a name="l00070"></a>00070 <span class="keyword">const</span> <span class="keywordtype">char</span> * sinfo_pfits_get_dpr_catg(<span class="keyword">const</span> cpl_propertylist * plist) ;
+<a name="l00071"></a>00071 <span class="keyword">const</span> <span class="keywordtype">char</span> * sinfo_pfits_get_dpr_tech(<span class="keyword">const</span> cpl_propertylist * plist) ;
+<a name="l00072"></a>00072 <span class="keyword">const</span> <span class="keywordtype">char</span> * sinfo_pfits_get_dpr_type(<span class="keyword">const</span> cpl_propertylist * plist) ;
+<a name="l00073"></a>00073 <span class="keyword">const</span> <span class="keywordtype">char</span> * sinfo_pfits_get_arcfile(<span class="keyword">const</span> cpl_propertylist * plist) ;
+<a name="l00074"></a>00074 <span class="keywordtype">double</span> sinfo_pfits_get_ditndit(<span class="keyword">const</span> <span class="keywordtype">char</span>* name);
+<a name="l00075"></a>00075 <span class="comment">/* not used */</span>
+<a name="l00076"></a>00076 <span class="keywordtype">int</span> sinfo_pfits_get_nodpos(<span class="keyword">const</span> cpl_propertylist *) ;
+<a name="l00077"></a>00077 <span class="keywordtype">double</span> sinfo_pfits_get_ra(<span class="keyword">const</span> cpl_propertylist *) ;
+<a name="l00078"></a>00078 <span class="keywordtype">double</span> sinfo_pfits_get_resol(<span class="keyword">const</span> cpl_propertylist *) ;
+<a name="l00079"></a>00079 <span class="keyword">const</span> <span class="keywordtype">char</span> * sinfo_pfits_get_starname(<span class="keyword">const</span> cpl_propertylist *) ;
+<a name="l00080"></a>00080 <span class="keyword">const</span> <span class="keywordtype">char</span> * sinfo_pfits_get_obs_id(<span class="keyword">const</span> cpl_propertylist *) ;
+<a name="l00081"></a>00081 <span class="keyword">const</span> <span class="keywordtype">char</span> * sinfo_pfits_get_instrument(<span class="keyword">const</span> cpl_propertylist *) ;
+<a name="l00082"></a>00082 <span class="keyword">const</span> <span class="keywordtype">char</span> * sinfo_pfits_get_filter_spec(<span class="keyword">const</span> cpl_propertylist *) ;
+<a name="l00083"></a>00083 <span class="keyword">const</span> <span class="keywordtype">char</span> * sinfo_pfits_get_filter_im(<span class="keyword">const</span> cpl_propertylist *) ;
+<a name="l00084"></a>00084 <span class="keyword">const</span> <span class="keywordtype">char</span> * sinfo_pfits_get_frame_type(<span class="keyword">const</span> cpl_propertylist *) ;
+<a name="l00085"></a>00085 <span class="keywordtype">int</span> sinfo_pfits_get_numbexp(<span class="keyword">const</span> cpl_propertylist *) ;
+<a name="l00086"></a>00086 <span class="keywordtype">double</span> sinfo_pfits_get_mjdobs(<span class="keyword">const</span> cpl_propertylist *) ;
+<a name="l00087"></a>00087 <span class="keywordtype">double</span> sinfo_pfits_get_focus(<span class="keyword">const</span> cpl_propertylist *) ;
+<a name="l00088"></a>00088 <span class="keywordtype">double</span> sinfo_pfits_get_cumoffsetx(<span class="keyword">const</span> cpl_propertylist *) ;
+<a name="l00089"></a>00089 <span class="keywordtype">double</span> sinfo_pfits_get_cumoffsety(<span class="keyword">const</span> cpl_propertylist *) ;
+<a name="l00090"></a>00090 <span class="keywordtype">double</span> sinfo_pfits_get_alpha(<span class="keyword">const</span> cpl_propertylist *) ;
+<a name="l00091"></a>00091 <span class="keywordtype">double</span> sinfo_pfits_get_airmass_end(<span class="keyword">const</span> cpl_propertylist *) ;
+<a name="l00092"></a>00092 <span class="keywordtype">double</span> sinfo_pfits_get_dec(<span class="keyword">const</span> cpl_propertylist *) ;
+<a name="l00093"></a>00093 <span class="keywordtype">double</span> sinfo_pfits_get_wlen(<span class="keyword">const</span> cpl_propertylist *) ;
+<a name="l00094"></a>00094 <span class="keywordtype">double</span> sinfo_pfits_get_delta(<span class="keyword">const</span> cpl_propertylist *) ;
+<a name="l00095"></a>00095 <span class="keywordtype">int</span> sinfo_pfits_get_naxis1(<span class="keyword">const</span> cpl_propertylist *) ;
+<a name="l00096"></a>00096 <span class="keywordtype">int</span> sinfo_pfits_get_naxis2(<span class="keyword">const</span> cpl_propertylist *) ;
+<a name="l00097"></a>00097 <span class="keywordtype">int</span> sinfo_pfits_get_naxis3(<span class="keyword">const</span> cpl_propertylist *) ;
+<a name="l00098"></a>00098 
+<a name="l00099"></a>00099 
+<a name="l00100"></a>00100 <span class="keywordtype">double</span> sinfo_pfits_get_crval1(<span class="keyword">const</span> cpl_propertylist *) ;
+<a name="l00101"></a>00101 <span class="keywordtype">double</span> sinfo_pfits_get_crval2(<span class="keyword">const</span> cpl_propertylist *) ;
+<a name="l00102"></a>00102 <span class="keywordtype">double</span> sinfo_pfits_get_crval3(<span class="keyword">const</span> cpl_propertylist *) ;
+<a name="l00103"></a>00103 
+<a name="l00104"></a>00104 <span class="keywordtype">double</span> sinfo_pfits_get_crpix1(<span class="keyword">const</span> cpl_propertylist *) ;
+<a name="l00105"></a>00105 <span class="keywordtype">double</span> sinfo_pfits_get_crpix2(<span class="keyword">const</span> cpl_propertylist *) ;
+<a name="l00106"></a>00106 <span class="keywordtype">double</span> sinfo_pfits_get_crpix3(<span class="keyword">const</span> cpl_propertylist *) ;
+<a name="l00107"></a>00107 
+<a name="l00108"></a>00108 <span class="keywordtype">double</span> sinfo_pfits_get_cdelt1(<span class="keyword">const</span> cpl_propertylist *) ;
+<a name="l00109"></a>00109 <span class="keywordtype">double</span> sinfo_pfits_get_cdelt2(<span class="keyword">const</span> cpl_propertylist *) ;
+<a name="l00110"></a>00110 <span class="keywordtype">double</span> sinfo_pfits_get_cdelt3(<span class="keyword">const</span> cpl_propertylist *) ;
+<a name="l00111"></a>00111 
+<a name="l00112"></a>00112 
+<a name="l00113"></a>00113 <span class="comment">/* keys not existent */</span>
+<a name="l00114"></a>00114 <span class="keywordtype">int</span> sinfo_pfits_get_chop_ncycles(<span class="keyword">const</span> cpl_propertylist * plist) ;
+<a name="l00115"></a>00115 <span class="keywordtype">double</span> sinfo_pfits_get_monoc_pos(<span class="keyword">const</span> cpl_propertylist *) ;
+<a name="l00116"></a>00116 cpl_error_code
+<a name="l00117"></a>00117 sinfo_plist_set_extra_keys(cpl_propertylist* plist,
+<a name="l00118"></a>00118              <span class="keyword">const</span> <span class="keywordtype">char</span>* hduclas1,
+<a name="l00119"></a>00119              <span class="keyword">const</span> <span class="keywordtype">char</span>* hduclas2,
+<a name="l00120"></a>00120              <span class="keyword">const</span> <span class="keywordtype">char</span>* hduclas3,
+<a name="l00121"></a>00121              <span class="keyword">const</span> <span class="keywordtype">char</span>* scidata,
+<a name="l00122"></a>00122              <span class="keyword">const</span> <span class="keywordtype">char</span>* errdata,
+<a name="l00123"></a>00123              <span class="keyword">const</span> <span class="keywordtype">char</span>* qualdata,
+<a name="l00124"></a>00124                          <span class="keyword">const</span> <span class="keywordtype">int</span> type);
+<a name="l00125"></a>00125 CPL_END_DECLS
+<a name="l00126"></a>00126 
+<a name="l00127"></a>00127 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__pixel__handling_8c_source.html b/html/sinfo__pixel__handling_8c_source.html
new file mode 100644
index 0000000..ad3e779
--- /dev/null
+++ b/html/sinfo__pixel__handling_8c_source.html
@@ -0,0 +1,136 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_pixel_handling.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_pixel_handling.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019  <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name     :    pixel_handling.c</span>
+<a name="l00022"></a>00022 <span class="comment">   Author         :    Nicolas Devillard</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on    :    March 04, 1997</span>
+<a name="l00024"></a>00024 <span class="comment">   Description    :    Functions processing arrays of pixels.</span>
+<a name="l00025"></a>00025 <span class="comment"></span>
+<a name="l00026"></a>00026 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00027"></a>00027 <span class="comment">/*</span>
+<a name="l00028"></a>00028 <span class="comment"></span>
+<a name="l00029"></a>00029 <span class="comment"> $Id: sinfo_pixel_handling.c,v 1.6 2012/03/03 09:50:08 amodigli Exp $</span>
+<a name="l00030"></a>00030 <span class="comment"> $Author: amodigli $</span>
+<a name="l00031"></a>00031 <span class="comment"> $Date: 2012/03/03 09:50:08 $</span>
+<a name="l00032"></a>00032 <span class="comment"> $Revision: 1.6 $</span>
+<a name="l00033"></a>00033 <span class="comment"></span>
+<a name="l00034"></a>00034 <span class="comment"> */</span>
+<a name="l00035"></a>00035 
+<a name="l00036"></a>00036 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00037"></a>00037 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00038"></a>00038 <span class="preprocessor">#endif</span>
+<a name="l00039"></a>00039 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00040"></a>00040 <span class="comment">                                  Includes</span>
+<a name="l00041"></a>00041 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include "sinfo_pixel_handling.h"</span>
+<a name="l00053"></a>00053 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00054"></a>00054 <span class="comment">                                Function codes</span>
+<a name="l00055"></a>00055 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00067"></a>00067 <span class="preprocessor">#define PIX_SWAP(a,b) { pixelvalue temp=(a);(a)=(b);(b)=temp; }</span>
+<a name="l00068"></a>00068 <span class="preprocessor"></span><span class="preprocessor">#define PIX_STACK_SIZE 50</span>
+<a name="l00069"></a>00069 <span class="preprocessor"></span>
+<a name="l00070"></a>00070 <span class="keywordtype">void</span> 
+<a name="l00071"></a>00071 sinfo_pixel_qsort(pixelvalue *pix_arr, <span class="keywordtype">int</span> npix)
+<a name="l00072"></a>00072 {
+<a name="l00073"></a>00073     <span class="keywordtype">int</span>         i,
+<a name="l00074"></a>00074                 ir,
+<a name="l00075"></a>00075                 j,
+<a name="l00076"></a>00076                 k,
+<a name="l00077"></a>00077                 l;
+<a name="l00078"></a>00078     <span class="keywordtype">int</span>        i_stack[PIX_STACK_SIZE*<span class="keyword">sizeof</span>(pixelvalue)] ;
+<a name="l00079"></a>00079     <span class="keywordtype">int</span>         j_stack ;
+<a name="l00080"></a>00080     pixelvalue  a ;
+<a name="l00081"></a>00081 
+<a name="l00082"></a>00082     ir = npix ;
+<a name="l00083"></a>00083     l = 1 ;
+<a name="l00084"></a>00084     j_stack = 0 ;
+<a name="l00085"></a>00085     <span class="keywordflow">for</span> (;;) {
+<a name="l00086"></a>00086         <span class="keywordflow">if</span> (ir-l < 7) {
+<a name="l00087"></a>00087             <span class="keywordflow">for</span> (j=l+1 ; j<=ir ; j++) {
+<a name="l00088"></a>00088                 a = pix_arr[j-1];
+<a name="l00089"></a>00089                 <span class="keywordflow">for</span> (i=j-1 ; i>=1 ; i--) {
+<a name="l00090"></a>00090                     <span class="keywordflow">if</span> (pix_arr[i-1] <= a) <span class="keywordflow">break</span>;
+<a name="l00091"></a>00091                     pix_arr[i] = pix_arr[i-1];
+<a name="l00092"></a>00092                 }
+<a name="l00093"></a>00093                 pix_arr[i] = a;
+<a name="l00094"></a>00094             }
+<a name="l00095"></a>00095             <span class="keywordflow">if</span> (j_stack == 0) <span class="keywordflow">break</span>;
+<a name="l00096"></a>00096             ir = i_stack[j_stack-- -1];
+<a name="l00097"></a>00097             l  = i_stack[j_stack-- -1];
+<a name="l00098"></a>00098         } <span class="keywordflow">else</span> {
+<a name="l00099"></a>00099             k = (l+ir) >> 1;
+<a name="l00100"></a>00100             PIX_SWAP(pix_arr[k-1], pix_arr[l])
+<a name="l00101"></a>00101             <span class="keywordflow">if</span> (pix_arr[l] > pix_arr[ir-1]) {
+<a name="l00102"></a>00102                 PIX_SWAP(pix_arr[l], pix_arr[ir-1])
+<a name="l00103"></a>00103             }
+<a name="l00104"></a>00104             <span class="keywordflow">if</span> (pix_arr[l-1] > pix_arr[ir-1]) {
+<a name="l00105"></a>00105                 PIX_SWAP(pix_arr[l-1], pix_arr[ir-1])
+<a name="l00106"></a>00106             }
+<a name="l00107"></a>00107             <span class="keywordflow">if</span> (pix_arr[l] > pix_arr[l-1]) {
+<a name="l00108"></a>00108                 PIX_SWAP(pix_arr[l], pix_arr[l-1])
+<a name="l00109"></a>00109             }
+<a name="l00110"></a>00110             i = l+1;
+<a name="l00111"></a>00111             j = ir;
+<a name="l00112"></a>00112             a = pix_arr[l-1];
+<a name="l00113"></a>00113             <span class="keywordflow">for</span> (;;) {
+<a name="l00114"></a>00114                 <span class="keywordflow">do</span> i++; <span class="keywordflow">while</span> (pix_arr[i-1] < a);
+<a name="l00115"></a>00115                 <span class="keywordflow">do</span> j--; <span class="keywordflow">while</span> (pix_arr[j-1] > a);
+<a name="l00116"></a>00116                 <span class="keywordflow">if</span> (j < i) <span class="keywordflow">break</span>;
+<a name="l00117"></a>00117                 PIX_SWAP(pix_arr[i-1], pix_arr[j-1]);
+<a name="l00118"></a>00118             }
+<a name="l00119"></a>00119             pix_arr[l-1] = pix_arr[j-1];
+<a name="l00120"></a>00120             pix_arr[j-1] = a;
+<a name="l00121"></a>00121             j_stack += 2;
+<a name="l00122"></a>00122             <span class="keywordflow">if</span> (j_stack > PIX_STACK_SIZE) {
+<a name="l00123"></a>00123                 <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"stack too small : aborting"</span>);
+<a name="l00124"></a>00124                 exit(-2001) ;
+<a name="l00125"></a>00125             }
+<a name="l00126"></a>00126             <span class="keywordflow">if</span> (ir-i+1 >= j-l) {
+<a name="l00127"></a>00127                 i_stack[j_stack-1] = ir;
+<a name="l00128"></a>00128                 i_stack[j_stack-2] = i;
+<a name="l00129"></a>00129                 ir = j-1;
+<a name="l00130"></a>00130             } <span class="keywordflow">else</span> {
+<a name="l00131"></a>00131                 i_stack[j_stack-1] = j-1;
+<a name="l00132"></a>00132                 i_stack[j_stack-2] = l;
+<a name="l00133"></a>00133                 l = i;
+<a name="l00134"></a>00134             }
+<a name="l00135"></a>00135         }
+<a name="l00136"></a>00136     }
+<a name="l00137"></a>00137 }
+<a name="l00138"></a>00138 <span class="preprocessor">#undef PIX_STACK_SIZE</span>
+<a name="l00139"></a>00139 <span class="preprocessor"></span><span class="preprocessor">#undef PIX_SWAP</span>
+<a name="l00140"></a>00140 <span class="preprocessor"></span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__pixel__handling_8h_source.html b/html/sinfo__pixel__handling_8h_source.html
new file mode 100644
index 0000000..df211ba
--- /dev/null
+++ b/html/sinfo__pixel__handling_8h_source.html
@@ -0,0 +1,61 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_pixel_handling.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_pixel_handling.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019  <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name     :    sinfo_pixel_handling.c</span>
+<a name="l00022"></a>00022 <span class="comment">   Author         :    Nicolas Devillard</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on    :    March 4th, 1997</span>
+<a name="l00024"></a>00024 <span class="comment">   Description    :    Functions to handle list of pixels and their use</span>
+<a name="l00025"></a>00025 <span class="comment"></span>
+<a name="l00026"></a>00026 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00027"></a>00027 <span class="comment">/*</span>
+<a name="l00028"></a>00028 <span class="comment"> $Id: sinfo_pixel_handling.h,v 1.5 2007/06/06 07:10:45 amodigli Exp $</span>
+<a name="l00029"></a>00029 <span class="comment"> $Author: amodigli $</span>
+<a name="l00030"></a>00030 <span class="comment"> $Date: 2007/06/06 07:10:45 $</span>
+<a name="l00031"></a>00031 <span class="comment"> $Revision: 1.5 $</span>
+<a name="l00032"></a>00032 <span class="comment"> */</span>
+<a name="l00033"></a>00033 <span class="preprocessor">#ifndef SINFO_PIXEL_HANDLING_H</span>
+<a name="l00034"></a>00034 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_PIXEL_HANDLING_H</span>
+<a name="l00035"></a>00035 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00036"></a>00036 <span class="comment">                                   Includes</span>
+<a name="l00037"></a>00037 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00038"></a>00038 <span class="preprocessor">#include "sinfo_local_types.h"</span>
+<a name="l00039"></a>00039 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00040"></a>00040 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00041"></a>00041 <span class="comment">                                 Function ANSI prototypes</span>
+<a name="l00042"></a>00042 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00055"></a>00055 <span class="keywordtype">void</span> 
+<a name="l00056"></a>00056 sinfo_pixel_qsort(pixelvalue *pix_arr, <span class="keywordtype">int</span> npix) ;
+<a name="l00057"></a>00057 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__poly2d_8c_source.html b/html/sinfo__poly2d_8c_source.html
new file mode 100644
index 0000000..31c23ad
--- /dev/null
+++ b/html/sinfo__poly2d_8c_source.html
@@ -0,0 +1,72 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_poly2d.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_poly2d.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name     :    poly2d.c</span>
+<a name="l00022"></a>00022 <span class="comment">   Author         :    N. Devillard</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on    :    22 Jun 1999</span>
+<a name="l00024"></a>00024 <span class="comment">   Description    :    2D polynomial handling</span>
+<a name="l00025"></a>00025 <span class="comment"></span>
+<a name="l00026"></a>00026 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00027"></a>00027 <span class="comment">/*</span>
+<a name="l00028"></a>00028 <span class="comment">    $Id: sinfo_poly2d.c,v 1.4 2012/03/03 09:50:08 amodigli Exp $</span>
+<a name="l00029"></a>00029 <span class="comment">    $Author: amodigli $</span>
+<a name="l00030"></a>00030 <span class="comment">    $Date: 2012/03/03 09:50:08 $</span>
+<a name="l00031"></a>00031 <span class="comment">    $Revision: 1.4 $</span>
+<a name="l00032"></a>00032 <span class="comment">*/</span>
+<a name="l00033"></a>00033 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00034"></a>00034 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00035"></a>00035 <span class="preprocessor">#endif</span>
+<a name="l00036"></a>00036 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00037"></a>00037 <span class="comment">                                   Includes</span>
+<a name="l00038"></a>00038 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00039"></a>00039 <span class="preprocessor">#include "sinfo_poly2d.h"</span>
+<a name="l00062"></a>00062 <span class="keywordtype">double</span>
+<a name="l00063"></a>00063 sinfo_poly2d_compute(
+<a name="l00064"></a>00064     poly2d    *    p,
+<a name="l00065"></a>00065     <span class="keywordtype">double</span>        x,
+<a name="l00066"></a>00066     <span class="keywordtype">double</span>        y
+<a name="l00067"></a>00067 )
+<a name="l00068"></a>00068 {
+<a name="l00069"></a>00069     <span class="keywordtype">double</span>    z ;
+<a name="l00070"></a>00070     <span class="keywordtype">int</span>        i ;
+<a name="l00071"></a>00071 
+<a name="l00072"></a>00072     z = 0.00 ;
+<a name="l00073"></a>00073 
+<a name="l00074"></a>00074     <span class="keywordflow">for</span> (i=0 ; i<p->nc ; i++) {
+<a name="l00075"></a>00075         z += p->c[i] * sinfo_ipow(x, p->px[i]) * sinfo_ipow(y, p->py[i]) ;
+<a name="l00076"></a>00076     }
+<a name="l00077"></a>00077     <span class="keywordflow">return</span> z ;
+<a name="l00078"></a>00078 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__poly2d_8h_source.html b/html/sinfo__poly2d_8h_source.html
new file mode 100644
index 0000000..a79e447
--- /dev/null
+++ b/html/sinfo__poly2d_8h_source.html
@@ -0,0 +1,90 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_poly2d.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_poly2d.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 
+<a name="l00020"></a>00020 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00021"></a>00021 <span class="comment">   </span>
+<a name="l00022"></a>00022 <span class="comment">   File name     :    sinfo_poly2d.h</span>
+<a name="l00023"></a>00023 <span class="comment">   Author         :    N. Devillard</span>
+<a name="l00024"></a>00024 <span class="comment">   Created on    :    22 Jun 1999</span>
+<a name="l00025"></a>00025 <span class="comment">   Description    :    2D polynomial handling</span>
+<a name="l00026"></a>00026 <span class="comment"></span>
+<a name="l00027"></a>00027 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00028"></a>00028 
+<a name="l00029"></a>00029 <span class="comment">/*</span>
+<a name="l00030"></a>00030 <span class="comment">    $Id: sinfo_poly2d.h,v 1.4 2007/06/06 07:10:45 amodigli Exp $</span>
+<a name="l00031"></a>00031 <span class="comment">    $Author: amodigli $</span>
+<a name="l00032"></a>00032 <span class="comment">    $Date: 2007/06/06 07:10:45 $</span>
+<a name="l00033"></a>00033 <span class="comment">    $Revision: 1.4 $</span>
+<a name="l00034"></a>00034 <span class="comment">*/</span>
+<a name="l00035"></a>00035 
+<a name="l00036"></a>00036 <span class="preprocessor">#ifndef SINFO_POLY2D_H</span>
+<a name="l00037"></a>00037 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_POLY2D_H</span>
+<a name="l00038"></a>00038 <span class="preprocessor"></span>
+<a name="l00039"></a>00039 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00040"></a>00040 <span class="comment">                                   Includes</span>
+<a name="l00041"></a>00041 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include <stdio.h></span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include <stdlib.h></span>
+<a name="l00044"></a>00044 <span class="preprocessor">#include <string.h></span>
+<a name="l00045"></a>00045 <span class="preprocessor">#include "sinfo_ipow.h"</span>
+<a name="l00046"></a>00046 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00047"></a>00047 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00048"></a>00048 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00049"></a>00049 <span class="comment">                                   New types</span>
+<a name="l00050"></a>00050 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00051"></a>00051 
+<a name="l00094"></a>00094 <span class="keyword">struct </span>_2D_POLY_ {
+<a name="l00095"></a>00095     <span class="keywordtype">int</span>            nc ;        <span class="comment">/* number of coefficients in px, py, c */</span>
+<a name="l00096"></a>00096     <span class="keywordtype">int</span>        *    px ;        <span class="comment">/* powers of x                         */</span>
+<a name="l00097"></a>00097     <span class="keywordtype">int</span>        *    py ;        <span class="comment">/* powers of y                         */</span>
+<a name="l00098"></a>00098     <span class="keywordtype">double</span>    *    c ;            <span class="comment">/* polynomial coefficients             */</span>
+<a name="l00099"></a>00099 } ;
+<a name="l00100"></a>00100 
+<a name="l00101"></a>00101 <span class="keyword">typedef</span> <span class="keyword">struct </span>_2D_POLY_ poly2d ;
+<a name="l00102"></a>00102 
+<a name="l00103"></a>00103 
+<a name="l00104"></a>00104 
+<a name="l00105"></a>00105 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00106"></a>00106 <span class="comment">                               Function codes    </span>
+<a name="l00107"></a>00107 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00108"></a>00108 
+<a name="l00122"></a>00122 <span class="keywordtype">double</span>
+<a name="l00123"></a>00123 sinfo_poly2d_compute(
+<a name="l00124"></a>00124     poly2d    *    p,
+<a name="l00125"></a>00125     <span class="keywordtype">double</span>        x,
+<a name="l00126"></a>00126     <span class="keywordtype">double</span>        y
+<a name="l00127"></a>00127 );
+<a name="l00128"></a>00128 
+<a name="l00129"></a>00129 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__prepare__stacked__frames__config_8c_source.html b/html/sinfo__prepare__stacked__frames__config_8c_source.html
new file mode 100644
index 0000000..e58dedb
--- /dev/null
+++ b/html/sinfo__prepare__stacked__frames__config_8c_source.html
@@ -0,0 +1,359 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_prepare_stacked_frames_config.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_prepare_stacked_frames_config.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_prepare_stacked_frames_config.c,v 1.8 2008/02/27 15:10:05 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the CPL (Common Pipeline Library)</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
+<a name="l00007"></a>00007 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span>
+<a name="l00008"></a>00008 <span class="comment"> * License as published by the Free Software Foundation; either</span>
+<a name="l00009"></a>00009 <span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
+<a name="l00014"></a>00014 <span class="comment"> * Lesser General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
+<a name="l00017"></a>00017 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2008/02/27 15:10:05 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.8 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> */</span>
+<a name="l00026"></a>00026 
+<a name="l00027"></a>00027  <span class="comment">/**************************************************************************</span>
+<a name="l00028"></a>00028 <span class="comment">  * Prepare_Stacked_Frames Frames Data Reduction Parameter Initialization  *</span>
+<a name="l00029"></a>00029 <span class="comment">  **************************************************************************/</span>
+<a name="l00030"></a>00030 
+<a name="l00031"></a>00031 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00032"></a>00032 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00033"></a>00033 <span class="preprocessor">#endif</span>
+<a name="l00034"></a>00034 <span class="preprocessor"></span>
+<a name="l00035"></a>00035 <span class="preprocessor">#include "sinfo_prepare_stacked_frames_config.h"</span>
+<a name="l00049"></a>00049 <span class="keywordtype">void</span>
+<a name="l00050"></a>00050  sinfo_prepare_stacked_frames_config_add(cpl_parameterlist *list)
+<a name="l00051"></a>00051 {
+<a name="l00052"></a>00052 
+<a name="l00053"></a>00053   cpl_parameter *p;
+<a name="l00054"></a>00054 
+<a name="l00055"></a>00055   <span class="keywordflow">if</span> (!list) {
+<a name="l00056"></a>00056     <span class="keywordflow">return</span>;
+<a name="l00057"></a>00057   }
+<a name="l00058"></a>00058 
+<a name="l00059"></a>00059 <span class="comment">/*</span>
+<a name="l00060"></a>00060 <span class="comment">  --------------------------------------------------------------------------</span>
+<a name="l00061"></a>00061 <span class="comment">  Clean Mean </span>
+<a name="l00062"></a>00062 <span class="comment">  --------------------------------------------------------------------------</span>
+<a name="l00063"></a>00063 <span class="comment"> */</span>
+<a name="l00064"></a>00064 <span class="comment">/* the fraction [0...1] of rejected low intensity pixels when taking </span>
+<a name="l00065"></a>00065 <span class="comment">the average of columns */</span>
+<a name="l00066"></a>00066   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.stacked.low_rejection"</span>,
+<a name="l00067"></a>00067                   CPL_TYPE_DOUBLE,
+<a name="l00068"></a>00068                               <span class="stringliteral">"lower rejection"</span>,
+<a name="l00069"></a>00069                               <span class="stringliteral">"sinfoni.stacked"</span>,
+<a name="l00070"></a>00070                               0.1,0.0,1.0);
+<a name="l00071"></a>00071 
+<a name="l00072"></a>00072   cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"stack-lo_rej"</span>);
+<a name="l00073"></a>00073   cpl_parameterlist_append(list, p);
+<a name="l00074"></a>00074 
+<a name="l00075"></a>00075  <span class="comment">/* the fraction [0...1] of rejected high intensity pixels when taking </span>
+<a name="l00076"></a>00076 <span class="comment">the average of columns */</span>
+<a name="l00077"></a>00077   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.stacked.high_rejection"</span>,
+<a name="l00078"></a>00078                   CPL_TYPE_DOUBLE,
+<a name="l00079"></a>00079                               <span class="stringliteral">"higher rejection"</span>,
+<a name="l00080"></a>00080                               <span class="stringliteral">"sinfoni.stacked"</span>,
+<a name="l00081"></a>00081                               0.1,0.0,1.0);
+<a name="l00082"></a>00082 
+<a name="l00083"></a>00083   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"stack-hi_rej"</span>);
+<a name="l00084"></a>00084   cpl_parameterlist_append(list, p);
+<a name="l00085"></a>00085 
+<a name="l00086"></a>00086 
+<a name="l00087"></a>00087 <span class="comment">/*</span>
+<a name="l00088"></a>00088 <span class="comment">  --------------------------------------------------------------------------</span>
+<a name="l00089"></a>00089 <span class="comment">  Flat Field </span>
+<a name="l00090"></a>00090 <span class="comment">  --------------------------------------------------------------------------</span>
+<a name="l00091"></a>00091 <span class="comment"> */</span>
+<a name="l00092"></a>00092 <span class="comment">/* indicates if flatfielding is carried through or not */</span>
+<a name="l00093"></a>00093   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.stacked.flat_index"</span>,
+<a name="l00094"></a>00094                   CPL_TYPE_BOOL,
+<a name="l00095"></a>00095                               <span class="stringliteral">"Flat Index: "</span>,
+<a name="l00096"></a>00096                               <span class="stringliteral">"sinfoni.stacked"</span>,
+<a name="l00097"></a>00097                               TRUE);
+<a name="l00098"></a>00098 
+<a name="l00099"></a>00099   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"stack-flat_ind"</span>);
+<a name="l00100"></a>00100   cpl_parameterlist_append(list, p);
+<a name="l00101"></a>00101 
+<a name="l00102"></a>00102 
+<a name="l00103"></a>00103 <span class="comment">/* indicates if flatfield is normalized to itself </span>
+<a name="l00104"></a>00104 <span class="comment">   (to remove lamp response curve) */</span>
+<a name="l00105"></a>00105   p = cpl_parameter_new_enum(<span class="stringliteral">"sinfoni.stacked.mflat_norm_smooth"</span>,
+<a name="l00106"></a>00106                               CPL_TYPE_INT,
+<a name="l00107"></a>00107                               <span class="stringliteral">"Normalize master flat to its smoothed value "</span>
+<a name="l00108"></a>00108                               <span class="stringliteral">"(to remove lamp response curve). "</span>
+<a name="l00109"></a>00109                               <span class="stringliteral">"0 (no smooth). 1 (apply fft filter along y)."</span>
+<a name="l00110"></a>00110                               <span class="stringliteral">"2 (apply running median filter along y)."</span>,
+<a name="l00111"></a>00111                               <span class="stringliteral">"sinfoni.stacked"</span>,
+<a name="l00112"></a>00112                              0,3,0,1,2);
+<a name="l00113"></a>00113 
+<a name="l00114"></a>00114   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"stack-mflat_norm_smooth"</span>);
+<a name="l00115"></a>00115   cpl_parameterlist_append(list, p);
+<a name="l00116"></a>00116 
+<a name="l00117"></a>00117 
+<a name="l00118"></a>00118 <span class="comment">/* indicates if flatfield is normalized to itself </span>
+<a name="l00119"></a>00119 <span class="comment">   (to remove lamp response curve) */</span>
+<a name="l00120"></a>00120   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.stacked.mflat_smooth_rad"</span>,
+<a name="l00121"></a>00121                   CPL_TYPE_INT,
+<a name="l00122"></a>00122                               <span class="stringliteral">"Normalization smoothing radii "</span>,
+<a name="l00123"></a>00123                               <span class="stringliteral">"sinfoni.stacked"</span>,
+<a name="l00124"></a>00124                               16,3,2048);
+<a name="l00125"></a>00125 
+<a name="l00126"></a>00126   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"stack-mflat_smooth_rad"</span>);
+<a name="l00127"></a>00127   cpl_parameterlist_append(list, p);
+<a name="l00128"></a>00128 
+<a name="l00129"></a>00129 
+<a name="l00130"></a>00130 <span class="comment">/*</span>
+<a name="l00131"></a>00131 <span class="comment">  --------------------------------------------------------------------------</span>
+<a name="l00132"></a>00132 <span class="comment">  Bad Pixel </span>
+<a name="l00133"></a>00133 <span class="comment">  --------------------------------------------------------------------------</span>
+<a name="l00134"></a>00134 <span class="comment"> */</span>
+<a name="l00135"></a>00135 <span class="comment">/* indicates if the bad pixels should be interpolated or not */</span>
+<a name="l00136"></a>00136   p = cpl_parameter_new_enum(<span class="stringliteral">"sinfoni.stacked.mask_index"</span>,
+<a name="l00137"></a>00137                   CPL_TYPE_INT,
+<a name="l00138"></a>00138                               <span class="stringliteral">"BP Mask Interpolation Switch: "</span>
+<a name="l00139"></a>00139                               <span class="stringliteral">"indicates if the bad pixel mask should be "</span>
+<a name="l00140"></a>00140                  <span class="stringliteral">"applied (1) or not (0) "</span>,
+<a name="l00141"></a>00141                  <span class="comment">/*</span>
+<a name="l00142"></a>00142 <span class="comment">                              "2: indicates that "</span>
+<a name="l00143"></a>00143 <span class="comment">                              "the bad pixels should be interpolated by "</span>
+<a name="l00144"></a>00144 <span class="comment">                              "using bezier splines",</span>
+<a name="l00145"></a>00145 <span class="comment">                 */</span>
+<a name="l00146"></a>00146                               <span class="stringliteral">"sinfoni.stacked"</span>,
+<a name="l00147"></a>00147                                1,
+<a name="l00148"></a>00148                  2,0,1); <span class="comment">/* there was also 2 allowed */</span>
+<a name="l00149"></a>00149 
+<a name="l00150"></a>00150   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"stack-mask_ind"</span>);
+<a name="l00151"></a>00151   cpl_parameterlist_append(list, p);
+<a name="l00152"></a>00152 
+<a name="l00153"></a>00153 <span class="comment">/* indicates if the bad pixels should be indicated (TRUE) or </span>
+<a name="l00154"></a>00154 <span class="comment">   interpolated (FALSE)*/</span>
+<a name="l00155"></a>00155   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.stacked.ind_index"</span>,
+<a name="l00156"></a>00156                   CPL_TYPE_BOOL,
+<a name="l00157"></a>00157                               <span class="stringliteral">"indicates if the bad pixels should be "</span>
+<a name="l00158"></a>00158                               <span class="stringliteral">"indicated (yes) or interpolated (no)"</span>,
+<a name="l00159"></a>00159                               <span class="stringliteral">"sinfoni.stacked"</span>,
+<a name="l00160"></a>00160                               FALSE);
+<a name="l00161"></a>00161 
+<a name="l00162"></a>00162   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"stack-ind_ind"</span>);
+<a name="l00163"></a>00163   cpl_parameterlist_append(list, p);
+<a name="l00164"></a>00164 
+<a name="l00165"></a>00165 
+<a name="l00166"></a>00166 <span class="comment">/* maximal pixel distance from bad pixel to take valid pixels */</span>
+<a name="l00167"></a>00167   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.stacked.mask_rad"</span>,
+<a name="l00168"></a>00168                   CPL_TYPE_INT,
+<a name="l00169"></a>00169                               <span class="stringliteral">"Max distance bad-good pix: "</span>,
+<a name="l00170"></a>00170                               <span class="stringliteral">"sinfoni.stacked"</span>,
+<a name="l00171"></a>00171                               4);
+<a name="l00172"></a>00172 
+<a name="l00173"></a>00173   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"stack-mask_rad"</span>);
+<a name="l00174"></a>00174   cpl_parameterlist_append(list, p);
+<a name="l00175"></a>00175 
+<a name="l00176"></a>00176   <span class="comment">/* Temporally removed options: index_list, sigma-factor, </span>
+<a name="l00177"></a>00177 <span class="comment">     used if mask_ind=2,3 */</span>
+<a name="l00178"></a>00178   <span class="comment">/* file list containing the index files for bezier interpolation */</span>
+<a name="l00179"></a>00179   <span class="comment">/*</span>
+<a name="l00180"></a>00180 <span class="comment">  p = cpl_parameter_new_value("sinfoni.stacked.index_list",</span>
+<a name="l00181"></a>00181 <span class="comment">                  CPL_TYPE_STRING,</span>
+<a name="l00182"></a>00182 <span class="comment">                              "Contain Index Files: ",</span>
+<a name="l00183"></a>00183 <span class="comment">                              "sinfoni.stacked",</span>
+<a name="l00184"></a>00184 <span class="comment">                              "indexlist");</span>
+<a name="l00185"></a>00185 <span class="comment"></span>
+<a name="l00186"></a>00186 <span class="comment">  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"stack-index_list");</span>
+<a name="l00187"></a>00187 <span class="comment">  cpl_parameterlist_append(list, p);</span>
+<a name="l00188"></a>00188 <span class="comment">  */</span>
+<a name="l00189"></a>00189 
+<a name="l00190"></a>00190   <span class="comment">/* sigmaFactor for bad pixel search in method maskInd = 3 */</span>
+<a name="l00191"></a>00191   <span class="comment">/*</span>
+<a name="l00192"></a>00192 <span class="comment">  p = cpl_parameter_new_value("sinfoni.stacked.sigma_factor",</span>
+<a name="l00193"></a>00193 <span class="comment">                  CPL_TYPE_DOUBLE,</span>
+<a name="l00194"></a>00194 <span class="comment">                              "Sigma Factor for bp search: ",</span>
+<a name="l00195"></a>00195 <span class="comment">                              "sinfoni.stacked",</span>
+<a name="l00196"></a>00196 <span class="comment">                              3.);</span>
+<a name="l00197"></a>00197 <span class="comment"></span>
+<a name="l00198"></a>00198 <span class="comment">  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"stack-sigma_factor");</span>
+<a name="l00199"></a>00199 <span class="comment">  cpl_parameterlist_append(list, p);</span>
+<a name="l00200"></a>00200 <span class="comment">  */</span>
+<a name="l00201"></a>00201  
+<a name="l00202"></a>00202 <span class="comment">/*</span>
+<a name="l00203"></a>00203 <span class="comment">  --------------------------------------------------------------------------</span>
+<a name="l00204"></a>00204 <span class="comment">  Interleaving: only to support dither mode. We comment </span>
+<a name="l00205"></a>00205 <span class="comment">  --------------------------------------------------------------------------</span>
+<a name="l00206"></a>00206 <span class="comment"> */</span>
+<a name="l00207"></a>00207   <span class="comment">/* indicates if interleaving should be carried through */</span>
+<a name="l00208"></a>00208   <span class="comment">/*</span>
+<a name="l00209"></a>00209 <span class="comment">  p = cpl_parameter_new_value("sinfoni.stacked.inter_index",</span>
+<a name="l00210"></a>00210 <span class="comment">                  CPL_TYPE_BOOL,</span>
+<a name="l00211"></a>00211 <span class="comment">                              "Interleaving Switch: ",</span>
+<a name="l00212"></a>00212 <span class="comment">                              "sinfoni.stacked",</span>
+<a name="l00213"></a>00213 <span class="comment">                              FALSE);</span>
+<a name="l00214"></a>00214 <span class="comment"></span>
+<a name="l00215"></a>00215 <span class="comment">  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"stack-inter_ind");</span>
+<a name="l00216"></a>00216 <span class="comment">  cpl_parameterlist_append(list, p);</span>
+<a name="l00217"></a>00217 <span class="comment">  */</span>
+<a name="l00218"></a>00218 
+<a name="l00219"></a>00219 <span class="comment">/* number of image rows from which the general offset between the frames is </span>
+<a name="l00220"></a>00220 <span class="comment">   determined */</span>
+<a name="l00221"></a>00221 <span class="comment">/*</span>
+<a name="l00222"></a>00222 <span class="comment">  p = cpl_parameter_new_value("sinfoni.stacked.no_rows",</span>
+<a name="l00223"></a>00223 <span class="comment">                  CPL_TYPE_INT,</span>
+<a name="l00224"></a>00224 <span class="comment">                              "Number Of Rows",</span>
+<a name="l00225"></a>00225 <span class="comment">                              "sinfoni.stacked",</span>
+<a name="l00226"></a>00226 <span class="comment">                              400);</span>
+<a name="l00227"></a>00227 <span class="comment"></span>
+<a name="l00228"></a>00228 <span class="comment">  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"stack-no_rows");</span>
+<a name="l00229"></a>00229 <span class="comment">  cpl_parameterlist_append(list, p);</span>
+<a name="l00230"></a>00230 <span class="comment">*/</span>
+<a name="l00231"></a>00231 
+<a name="l00232"></a>00232 <span class="comment">/*</span>
+<a name="l00233"></a>00233 <span class="comment">  --------------------------------------------------------------------------</span>
+<a name="l00234"></a>00234 <span class="comment">  Gauss Convolution</span>
+<a name="l00235"></a>00235 <span class="comment">  --------------------------------------------------------------------------</span>
+<a name="l00236"></a>00236 <span class="comment"> */</span>
+<a name="l00237"></a>00237   <span class="comment">/* indicates if a Gaussian convolution is applied or not */</span>
+<a name="l00238"></a>00238   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.stacked.gauss_index"</span>,
+<a name="l00239"></a>00239                   CPL_TYPE_BOOL,
+<a name="l00240"></a>00240                               <span class="stringliteral">"Gaussian Convolution Switch: "</span>,
+<a name="l00241"></a>00241                               <span class="stringliteral">"sinfoni.stacked"</span>,
+<a name="l00242"></a>00242                               FALSE);
+<a name="l00243"></a>00243 
+<a name="l00244"></a>00244   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"stack-gauss_ind"</span>);
+<a name="l00245"></a>00245   cpl_parameterlist_append(list, p);
+<a name="l00246"></a>00246 
+<a name="l00247"></a>00247 <span class="comment">/* kernel half width of the Gaussian response function */</span>
+<a name="l00248"></a>00248   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.stacked.kernel_half_width"</span>,
+<a name="l00249"></a>00249                   CPL_TYPE_INT,
+<a name="l00250"></a>00250                               <span class="stringliteral">"Kernel Half Width"</span>,
+<a name="l00251"></a>00251                               <span class="stringliteral">"sinfoni.stacked"</span>,
+<a name="l00252"></a>00252                                2);
+<a name="l00253"></a>00253 
+<a name="l00254"></a>00254   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"stack-khw"</span>);
+<a name="l00255"></a>00255   cpl_parameterlist_append(list, p);
+<a name="l00256"></a>00256 <span class="comment">/*</span>
+<a name="l00257"></a>00257 <span class="comment">  --------------------------------------------------------------------------</span>
+<a name="l00258"></a>00258 <span class="comment">  Shift Frames (To be used?)</span>
+<a name="l00259"></a>00259 <span class="comment">  --------------------------------------------------------------------------</span>
+<a name="l00260"></a>00260 <span class="comment"> */</span>
+<a name="l00261"></a>00261   <span class="comment">/* Suppressed in release 1.1.0 */</span>
+<a name="l00262"></a>00262   <span class="comment">/* indicates if a Gaussian convolution is applied or not */</span>
+<a name="l00263"></a>00263   <span class="comment">/*</span>
+<a name="l00264"></a>00264 <span class="comment">  p = cpl_parameter_new_value("sinfoni.stacked.shift_frame_index",</span>
+<a name="l00265"></a>00265 <span class="comment">                  CPL_TYPE_BOOL,</span>
+<a name="l00266"></a>00266 <span class="comment">                              "Shift Frame Switch: ",</span>
+<a name="l00267"></a>00267 <span class="comment">                              "sinfoni.stacked",</span>
+<a name="l00268"></a>00268 <span class="comment">                              FALSE);</span>
+<a name="l00269"></a>00269 <span class="comment"></span>
+<a name="l00270"></a>00270 <span class="comment">  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"stack-shft_ind");</span>
+<a name="l00271"></a>00271 <span class="comment">  cpl_parameterlist_append(list, p);</span>
+<a name="l00272"></a>00272 <span class="comment">  */</span>
+<a name="l00273"></a>00273   <span class="comment">/*type of interpolation to be used (0=polynomial , 1=cubic spline) */</span>
+<a name="l00274"></a>00274   <span class="comment">/*</span>
+<a name="l00275"></a>00275 <span class="comment">  p = cpl_parameter_new_enum("sinfoni.stacked.shift_frame_type",</span>
+<a name="l00276"></a>00276 <span class="comment">                  CPL_TYPE_INT,</span>
+<a name="l00277"></a>00277 <span class="comment">                              "Shift Frame Type: 0 polynomial, 1 cubic,",</span>
+<a name="l00278"></a>00278 <span class="comment">                              "sinfoni.stacked",</span>
+<a name="l00279"></a>00279 <span class="comment">                   1,</span>
+<a name="l00280"></a>00280 <span class="comment">                               2,0,1);</span>
+<a name="l00281"></a>00281 <span class="comment"></span>
+<a name="l00282"></a>00282 <span class="comment">  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"stack-shft_typ");</span>
+<a name="l00283"></a>00283 <span class="comment">  cpl_parameterlist_append(list, p);</span>
+<a name="l00284"></a>00284 <span class="comment">  */</span>
+<a name="l00285"></a>00285   <span class="comment">/* order of the interpolation for the spectral shift of frames */</span>
+<a name="l00286"></a>00286   <span class="comment">/*</span>
+<a name="l00287"></a>00287 <span class="comment">  p = cpl_parameter_new_value("sinfoni.stacked.shift_frame_order",</span>
+<a name="l00288"></a>00288 <span class="comment">                  CPL_TYPE_INT,</span>
+<a name="l00289"></a>00289 <span class="comment">                              "Shift Frame Order",</span>
+<a name="l00290"></a>00290 <span class="comment">                              "sinfoni.stacked",</span>
+<a name="l00291"></a>00291 <span class="comment">                               2);</span>
+<a name="l00292"></a>00292 <span class="comment"></span>
+<a name="l00293"></a>00293 <span class="comment">  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"stack-shft_ord");</span>
+<a name="l00294"></a>00294 <span class="comment">  cpl_parameterlist_append(list, p);</span>
+<a name="l00295"></a>00295 <span class="comment">  */</span>
+<a name="l00296"></a>00296 
+<a name="l00297"></a>00297 <span class="comment">/*</span>
+<a name="l00298"></a>00298 <span class="comment">  --------------------------------------------------------------------------</span>
+<a name="l00299"></a>00299 <span class="comment">  WarpFix</span>
+<a name="l00300"></a>00300 <span class="comment">  --------------------------------------------------------------------------</span>
+<a name="l00301"></a>00301 <span class="comment"> */</span>
+<a name="l00302"></a>00302   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.stacked.warpfix_ind"</span>,
+<a name="l00303"></a>00303                   CPL_TYPE_BOOL,
+<a name="l00304"></a>00304                               <span class="stringliteral">"Warp Fix Index: "</span>,
+<a name="l00305"></a>00305                               <span class="stringliteral">"sinfoni.stacked"</span>,
+<a name="l00306"></a>00306                               TRUE);
+<a name="l00307"></a>00307 
+<a name="l00308"></a>00308   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"stack-warpfix_ind"</span>);
+<a name="l00309"></a>00309   cpl_parameterlist_append(list, p);
+<a name="l00310"></a>00310 
+<a name="l00311"></a>00311  
+<a name="l00312"></a>00312   p = cpl_parameter_new_enum(<span class="stringliteral">"sinfoni.stacked.warpfix_kernel"</span>,
+<a name="l00313"></a>00313                   CPL_TYPE_STRING,
+<a name="l00314"></a>00314                  <span class="stringliteral">"Warpfix kernel: "</span>,
+<a name="l00315"></a>00315                               <span class="stringliteral">"sinfoni.stacked"</span>,
+<a name="l00316"></a>00316                  <span class="stringliteral">"tanh"</span>,
+<a name="l00317"></a>00317                                6,<span class="stringliteral">"tanh"</span>,<span class="stringliteral">"sinc"</span>,<span class="stringliteral">"sinc2"</span>,
+<a name="l00318"></a>00318                               <span class="stringliteral">"lanczos"</span>,<span class="stringliteral">"hamming"</span>,<span class="stringliteral">"hann"</span>);
+<a name="l00319"></a>00319 
+<a name="l00320"></a>00320   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"stack-warpfix_kernel"</span>);
+<a name="l00321"></a>00321   cpl_parameterlist_append(list, p);
+<a name="l00322"></a>00322 
+<a name="l00323"></a>00323 
+<a name="l00324"></a>00324  p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.stacked.qc_thresh_min"</span>,
+<a name="l00325"></a>00325                   CPL_TYPE_INT,
+<a name="l00326"></a>00326                               <span class="stringliteral">"qc_thresh_min"</span>,
+<a name="l00327"></a>00327                               <span class="stringliteral">"sinfoni.stack"</span>,
+<a name="l00328"></a>00328                               0);
+<a name="l00329"></a>00329 
+<a name="l00330"></a>00330   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"stack-qc_thresh_min"</span>);
+<a name="l00331"></a>00331   cpl_parameterlist_append(list, p);
+<a name="l00332"></a>00332 
+<a name="l00333"></a>00333 
+<a name="l00334"></a>00334   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.stacked.qc_thresh_max"</span>,
+<a name="l00335"></a>00335                   CPL_TYPE_INT,
+<a name="l00336"></a>00336                               <span class="stringliteral">"qc_thresh_max"</span>,
+<a name="l00337"></a>00337                               <span class="stringliteral">"sinfoni.stack"</span>,
+<a name="l00338"></a>00338                               49000);
+<a name="l00339"></a>00339 
+<a name="l00340"></a>00340   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"stack-qc_thresh_max"</span>);
+<a name="l00341"></a>00341   cpl_parameterlist_append(list, p);
+<a name="l00342"></a>00342 
+<a name="l00343"></a>00343 
+<a name="l00344"></a>00344 
+<a name="l00345"></a>00345   <span class="comment">/* indicates if sky raw frame should be subtracted (TRUE) or not (FALSE) */</span>
+<a name="l00346"></a>00346   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.stacked.sub_raw_sky"</span>,
+<a name="l00347"></a>00347                   CPL_TYPE_BOOL,
+<a name="l00348"></a>00348                               <span class="stringliteral">"indicates if the raw sky frame should be "</span>
+<a name="l00349"></a>00349                               <span class="stringliteral">"subtracted (TRUE) or (FALSE)"</span>,
+<a name="l00350"></a>00350                               <span class="stringliteral">"sinfoni.stacked"</span>,
+<a name="l00351"></a>00351                               TRUE);
+<a name="l00352"></a>00352 
+<a name="l00353"></a>00353   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"stack-sub_raw_sky"</span>);
+<a name="l00354"></a>00354   cpl_parameterlist_append(list, p);
+<a name="l00355"></a>00355 
+<a name="l00356"></a>00356 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__prepare__stacked__frames__config_8h_source.html b/html/sinfo__prepare__stacked__frames__config_8h_source.html
new file mode 100644
index 0000000..5830aeb
--- /dev/null
+++ b/html/sinfo__prepare__stacked__frames__config_8h_source.html
@@ -0,0 +1,49 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_prepare_stacked_frames_config.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_prepare_stacked_frames_config.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_prepare_stacked_frames_config.h,v 1.1 2006/10/20 08:06:33 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the CPL (Common Pipeline Library)</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
+<a name="l00007"></a>00007 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span>
+<a name="l00008"></a>00008 <span class="comment"> * License as published by the Free Software Foundation; either</span>
+<a name="l00009"></a>00009 <span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
+<a name="l00014"></a>00014 <span class="comment"> * Lesser General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
+<a name="l00017"></a>00017 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2006/10/20 08:06:33 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.1 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> */</span>
+<a name="l00026"></a>00026 
+<a name="l00027"></a>00027  <span class="comment">/****************************************************************</span>
+<a name="l00028"></a>00028 <span class="comment">  *   Prepare_Stacked_Frames Frames Data Reduction Parameter Initialization </span>
+<a name="l00029"></a>00029 <span class="comment">  ****************************************************************/</span>
+<a name="l00030"></a>00030 <span class="preprocessor">#include "cpl.h"</span>    <span class="comment">/* defines parlist structure */</span>
+<a name="l00031"></a>00031 
+<a name="l00032"></a>00032 <span class="keywordtype">void</span>
+<a name="l00033"></a>00033 sinfo_prepare_stacked_frames_config_add(cpl_parameterlist *list);
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__pro__save_8c_source.html b/html/sinfo__pro__save_8c_source.html
new file mode 100644
index 0000000..d5d6f6a
--- /dev/null
+++ b/html/sinfo__pro__save_8c_source.html
@@ -0,0 +1,1049 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_pro_save.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_pro_save.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00020"></a>00020 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00021"></a>00021 <span class="preprocessor">#endif</span>
+<a name="l00022"></a>00022 <span class="preprocessor"></span>
+<a name="l00023"></a>00023 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00024"></a>00024 <span class="preprocessor">#include "sinfo_pro_save.h"</span>
+<a name="l00025"></a>00025 <span class="preprocessor">#include "sinfo_key_names.h"</span>
+<a name="l00026"></a>00026 <span class="preprocessor">#include "sinfo_functions.h"</span>
+<a name="l00027"></a>00027 <span class="preprocessor">#include "sinfo_utilities.h"</span> 
+<a name="l00028"></a>00028 <span class="preprocessor">#include "sinfo_globals.h"</span> 
+<a name="l00029"></a>00029 
+<a name="l00030"></a>00030 <span class="keyword">static</span> <span class="keywordtype">int</span> 
+<a name="l00031"></a>00031 sinfo_pfits_put_qc(
+<a name="l00032"></a>00032            cpl_propertylist       *   plist,
+<a name="l00033"></a>00033            cpl_table          *   qclog);
+<a name="l00034"></a>00034 
+<a name="l00035"></a>00035 <span class="keyword">static</span> <span class="keywordtype">void</span>
+<a name="l00036"></a>00036 sinfo_log_pro(<span class="keywordtype">char</span>* name_o,
+<a name="l00037"></a>00037               <span class="keyword">const</span> <span class="keywordtype">char</span>* pro_catg, 
+<a name="l00038"></a>00038               <span class="keywordtype">int</span> frm_type, 
+<a name="l00039"></a>00039               cpl_frameset* ref_set,
+<a name="l00040"></a>00040               cpl_frameset** out_set, 
+<a name="l00041"></a>00041               cpl_propertylist** plist,
+<a name="l00042"></a>00042               cpl_parameterlist* parlist, 
+<a name="l00043"></a>00043               <span class="keyword">const</span> <span class="keywordtype">char</span>* recid);
+<a name="l00044"></a>00044 
+<a name="l00045"></a>00045 
+<a name="l00046"></a>00046 <span class="keyword">static</span> <span class="keywordtype">void</span>
+<a name="l00047"></a>00047 sinfo_check_name(<span class="keyword">const</span> <span class="keywordtype">char</span>* in, <span class="keywordtype">char</span>** ou, <span class="keywordtype">int</span> type, <span class="keywordtype">char</span>** paf);
+<a name="l00048"></a>00048 
+<a name="l00049"></a>00049 <span class="keyword">static</span> <span class="keywordtype">void</span>
+<a name="l00050"></a>00050 sinfo_clean_header(cpl_propertylist** header);
+<a name="l00051"></a>00051 <span class="keyword">static</span> <span class="keywordtype">void</span>
+<a name="l00052"></a>00052 sinfo_clean_cube_header(cpl_propertylist** header);
+<a name="l00053"></a>00053 
+<a name="l00054"></a>00054 
+<a name="l00055"></a>00055 <span class="keyword">static</span> FILE * 
+<a name="l00056"></a>00056 sinfo_paf_print_header(
+<a name="l00057"></a>00057                <span class="keyword">const</span> <span class="keywordtype">char</span>    *   filename,
+<a name="l00058"></a>00058                <span class="keyword">const</span> <span class="keywordtype">char</span>    *   paf_id,
+<a name="l00059"></a>00059                <span class="keyword">const</span> <span class="keywordtype">char</span>    *   paf_desc,
+<a name="l00060"></a>00060                <span class="keyword">const</span> <span class="keywordtype">char</span>    *   login_name,
+<a name="l00061"></a>00061                <span class="keywordtype">char</span>    *   datetime) ;
+<a name="l00062"></a>00062 
+<a name="l00063"></a>00063 
+<a name="l00064"></a>00064 
+<a name="l00071"></a>00071 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00096"></a>00096 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00097"></a>00097 <span class="keyword">static</span> FILE * 
+<a name="l00098"></a>00098 sinfo_paf_print_header(
+<a name="l00099"></a>00099                <span class="keyword">const</span> <span class="keywordtype">char</span>    *   filename,
+<a name="l00100"></a>00100                <span class="keyword">const</span> <span class="keywordtype">char</span>    *      paf_id,
+<a name="l00101"></a>00101                <span class="keyword">const</span> <span class="keywordtype">char</span>    *    paf_desc,
+<a name="l00102"></a>00102                <span class="keyword">const</span> <span class="keywordtype">char</span>    *   login_name,
+<a name="l00103"></a>00103                <span class="keywordtype">char</span>    *   datetime)
+<a name="l00104"></a>00104 {
+<a name="l00105"></a>00105   FILE * paf ;
+<a name="l00106"></a>00106     
+<a name="l00107"></a>00107   <span class="keywordflow">if</span> ((paf=fopen(filename, <span class="stringliteral">"w"</span>))==NULL) {
+<a name="l00108"></a>00108     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"cannot create PAF file [%s]"</span>, filename);
+<a name="l00109"></a>00109     <span class="keywordflow">return</span> NULL ;
+<a name="l00110"></a>00110   }
+<a name="l00111"></a>00111   fprintf(paf, <span class="stringliteral">"PAF.HDR.START         ;# start of header\n"</span>);
+<a name="l00112"></a>00112   fprintf(paf, <span class="stringliteral">"PAF.TYPE              \"pipeline product\" ;\n"</span>);
+<a name="l00113"></a>00113   fprintf(paf, <span class="stringliteral">"PAF.ID                \"%s\"\n"</span>, paf_id);
+<a name="l00114"></a>00114   fprintf(paf, <span class="stringliteral">"PAF.NAME              \"%s\"\n"</span>, filename);
+<a name="l00115"></a>00115   fprintf(paf, <span class="stringliteral">"PAF.DESC              \"%s\"\n"</span>, paf_desc);
+<a name="l00116"></a>00116   fprintf(paf, <span class="stringliteral">"PAF.CRTE.NAME         \"%s\"\n"</span>, login_name) ;
+<a name="l00117"></a>00117   fprintf(paf, <span class="stringliteral">"PAF.CRTE.DAYTIM       \"%s\"\n"</span>, datetime) ;
+<a name="l00118"></a>00118   fprintf(paf, <span class="stringliteral">"PAF.LCHG.NAME         \"%s\"\n"</span>, login_name) ;
+<a name="l00119"></a>00119   fprintf(paf, <span class="stringliteral">"PAF.LCHG.DAYTIM       \"%s\"\n"</span>, datetime) ;
+<a name="l00120"></a>00120   fprintf(paf, <span class="stringliteral">"PAF.CHCK.CHECKSUM     \"\"\n"</span>);
+<a name="l00121"></a>00121   fprintf(paf, <span class="stringliteral">"PAF.HDR.END           ;# end of header\n"</span>);
+<a name="l00122"></a>00122   fprintf(paf, <span class="stringliteral">"\n"</span>);
+<a name="l00123"></a>00123   <span class="keywordflow">return</span> paf ;
+<a name="l00124"></a>00124 }
+<a name="l00134"></a>00134 <span class="keywordtype">int</span> 
+<a name="l00135"></a>00135 sinfo_update_fits_card_int(<span class="keyword">const</span> <span class="keywordtype">char</span>* file,<span class="keyword">const</span> <span class="keywordtype">char</span>* card,<span class="keywordtype">int</span> value)
+<a name="l00136"></a>00136 {
+<a name="l00137"></a>00137   cpl_propertylist *   plist =NULL;
+<a name="l00138"></a>00138   <span class="keywordflow">if</span> ((plist = cpl_propertylist_load(file, 0)) == NULL) {
+<a name="l00139"></a>00139     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>( <span class="stringliteral">"getting header from file %s"</span>,file);
+<a name="l00140"></a>00140     cpl_propertylist_delete(plist) ;
+<a name="l00141"></a>00141     <span class="keywordflow">return</span> -1 ;
+<a name="l00142"></a>00142   }
+<a name="l00143"></a>00143 
+<a name="l00144"></a>00144   <span class="keywordflow">if</span> (CPL_ERROR_NONE!=cpl_propertylist_set_int(plist,card,value)){
+<a name="l00145"></a>00145     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>( <span class="stringliteral">"setting header of file %s"</span>,file);
+<a name="l00146"></a>00146     cpl_propertylist_delete(plist) ;
+<a name="l00147"></a>00147     <span class="keywordflow">return</span> -1 ;
+<a name="l00148"></a>00148   }
+<a name="l00149"></a>00149   cpl_propertylist_delete(plist) ;
+<a name="l00150"></a>00150   <span class="keywordflow">return</span> 0;
+<a name="l00151"></a>00151 }
+<a name="l00152"></a>00152 
+<a name="l00162"></a>00162 <span class="keywordtype">int</span> 
+<a name="l00163"></a>00163 sinfo_update_fits_card_float(<span class="keyword">const</span> <span class="keywordtype">char</span>* file,<span class="keyword">const</span> <span class="keywordtype">char</span>* card,<span class="keywordtype">float</span> value)
+<a name="l00164"></a>00164 {
+<a name="l00165"></a>00165   cpl_propertylist *   plist =NULL;
+<a name="l00166"></a>00166   <span class="keywordflow">if</span> ((plist = cpl_propertylist_load(file, 0)) == NULL) {
+<a name="l00167"></a>00167     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>( <span class="stringliteral">"getting header from file %s"</span>,file);
+<a name="l00168"></a>00168     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>((<span class="keywordtype">char</span>* ) cpl_error_get_message());
+<a name="l00169"></a>00169     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>((<span class="keywordtype">char</span>* ) cpl_error_get_where());
+<a name="l00170"></a>00170     cpl_propertylist_delete(plist) ;
+<a name="l00171"></a>00171     <span class="keywordflow">return</span> -1 ;
+<a name="l00172"></a>00172   }
+<a name="l00173"></a>00173 
+<a name="l00174"></a>00174   <span class="keywordflow">if</span> (CPL_ERROR_NONE!=cpl_propertylist_set_float(plist,card,value)){
+<a name="l00175"></a>00175     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>( <span class="stringliteral">"setting header of file %s"</span>,file);
+<a name="l00176"></a>00176     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>((<span class="keywordtype">char</span>* ) cpl_error_get_message());
+<a name="l00177"></a>00177     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>((<span class="keywordtype">char</span>* ) cpl_error_get_where());
+<a name="l00178"></a>00178     cpl_propertylist_delete(plist) ;
+<a name="l00179"></a>00179     <span class="keywordflow">return</span> -1 ;
+<a name="l00180"></a>00180   }
+<a name="l00181"></a>00181   cpl_propertylist_delete(plist) ;
+<a name="l00182"></a>00182   <span class="keywordflow">return</span> 0;
+<a name="l00183"></a>00183 }
+<a name="l00184"></a>00184 
+<a name="l00185"></a>00185 
+<a name="l00195"></a>00195 <span class="keywordtype">int</span> 
+<a name="l00196"></a>00196 sinfo_update_fits_card_double(<span class="keyword">const</span> <span class="keywordtype">char</span>* file,<span class="keyword">const</span> <span class="keywordtype">char</span>* card,<span class="keywordtype">double</span> value)
+<a name="l00197"></a>00197 {
+<a name="l00198"></a>00198   cpl_propertylist *   plist =NULL;
+<a name="l00199"></a>00199   <span class="keywordflow">if</span> ((plist = cpl_propertylist_load(file, 0)) == NULL) {
+<a name="l00200"></a>00200     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>( <span class="stringliteral">"getting header from file %s"</span>,file);
+<a name="l00201"></a>00201     cpl_propertylist_delete(plist) ;
+<a name="l00202"></a>00202     <span class="keywordflow">return</span> -1 ;
+<a name="l00203"></a>00203   }
+<a name="l00204"></a>00204 
+<a name="l00205"></a>00205   <span class="keywordflow">if</span> (CPL_ERROR_NONE!=cpl_propertylist_set_double(plist,card,value)){
+<a name="l00206"></a>00206     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>( <span class="stringliteral">"gsetting header of file %s"</span>,file);
+<a name="l00207"></a>00207     cpl_propertylist_delete(plist) ;
+<a name="l00208"></a>00208     <span class="keywordflow">return</span> -1 ;
+<a name="l00209"></a>00209   }
+<a name="l00210"></a>00210   cpl_propertylist_delete(plist) ;
+<a name="l00211"></a>00211   <span class="keywordflow">return</span> 0;
+<a name="l00212"></a>00212 }
+<a name="l00213"></a>00213 
+<a name="l00223"></a>00223 <span class="keywordtype">int</span> 
+<a name="l00224"></a>00224 sinfo_update_fits_card_long(<span class="keyword">const</span> <span class="keywordtype">char</span>* file,<span class="keyword">const</span> <span class="keywordtype">char</span>* card,<span class="keywordtype">long</span> value)
+<a name="l00225"></a>00225 {
+<a name="l00226"></a>00226   cpl_propertylist *   plist =NULL;
+<a name="l00227"></a>00227   <span class="keywordflow">if</span> ((plist = cpl_propertylist_load(file, 0)) == NULL) {
+<a name="l00228"></a>00228     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>( <span class="stringliteral">"getting header from file %s"</span>,file);
+<a name="l00229"></a>00229     cpl_propertylist_delete(plist) ;
+<a name="l00230"></a>00230     <span class="keywordflow">return</span> -1 ;
+<a name="l00231"></a>00231   }
+<a name="l00232"></a>00232   <span class="keywordflow">if</span> (CPL_ERROR_NONE!=cpl_propertylist_set_long(plist,card,value)){
+<a name="l00233"></a>00233     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>( <span class="stringliteral">"setting header of file %s"</span>,file);
+<a name="l00234"></a>00234     cpl_propertylist_delete(plist) ;
+<a name="l00235"></a>00235     <span class="keywordflow">return</span> -1 ;
+<a name="l00236"></a>00236   }
+<a name="l00237"></a>00237   cpl_propertylist_delete(plist) ;
+<a name="l00238"></a>00238   <span class="keywordflow">return</span> 0;
+<a name="l00239"></a>00239 }
+<a name="l00240"></a>00240 
+<a name="l00250"></a>00250 <span class="keywordtype">int</span> 
+<a name="l00251"></a>00251 sinfo_update_ims_fits_card_string(cpl_imagelist* iml,
+<a name="l00252"></a>00252                                   <span class="keyword">const</span> <span class="keywordtype">char</span>* file, 
+<a name="l00253"></a>00253                                   <span class="keyword">const</span> <span class="keywordtype">char</span>* card,
+<a name="l00254"></a>00254                                   <span class="keyword">const</span> <span class="keywordtype">char</span>* value)
+<a name="l00255"></a>00255 {
+<a name="l00256"></a>00256 
+<a name="l00257"></a>00257   cpl_propertylist *   plist =NULL;
+<a name="l00258"></a>00258   <span class="keywordflow">if</span> ((plist = cpl_propertylist_load(file, 0)) == NULL) {
+<a name="l00259"></a>00259     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>( <span class="stringliteral">"getting header from reference ima frame %s"</span>,file);
+<a name="l00260"></a>00260     cpl_propertylist_delete(plist) ;
+<a name="l00261"></a>00261     <span class="keywordflow">return</span> -1 ;
+<a name="l00262"></a>00262   }
+<a name="l00263"></a>00263 
+<a name="l00264"></a>00264 
+<a name="l00265"></a>00265   <span class="keywordflow">if</span> (CPL_ERROR_NONE!=cpl_propertylist_set_string(plist,card,value)){
+<a name="l00266"></a>00266     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>( <span class="stringliteral">"getting header from reference ima frame %s"</span>,file);
+<a name="l00267"></a>00267     cpl_propertylist_delete(plist) ;
+<a name="l00268"></a>00268     <span class="keywordflow">return</span> -1 ;
+<a name="l00269"></a>00269   }
+<a name="l00270"></a>00270 
+<a name="l00271"></a>00271   <span class="keywordflow">if</span> (cpl_imagelist_save(iml,file,CPL_BPP_IEEE_FLOAT,
+<a name="l00272"></a>00272                          plist,CPL_IO_DEFAULT)!=CPL_ERROR_NONE) {
+<a name="l00273"></a>00273     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>( <span class="stringliteral">"getting header from reference ima frame %s"</span>,file);
+<a name="l00274"></a>00274     cpl_propertylist_delete(plist) ;
+<a name="l00275"></a>00275   }
+<a name="l00276"></a>00276   cpl_propertylist_delete(plist) ;
+<a name="l00277"></a>00277   <span class="keywordflow">return</span> 0;
+<a name="l00278"></a>00278 }
+<a name="l00279"></a>00279 <span class="comment">/* Not used </span>
+<a name="l00280"></a>00280 <span class="comment">static int sinfo_save_paf(char* name_p, </span>
+<a name="l00281"></a>00281 <span class="comment">              const char* rec_id, </span>
+<a name="l00282"></a>00282 <span class="comment">              cpl_table* qclog,</span>
+<a name="l00283"></a>00283 <span class="comment">              cpl_propertylist*   plist,</span>
+<a name="l00284"></a>00284 <span class="comment">              const char*      pro_catg)</span>
+<a name="l00285"></a>00285 <span class="comment">{</span>
+<a name="l00286"></a>00286 <span class="comment"></span>
+<a name="l00287"></a>00287 <span class="comment"></span>
+<a name="l00288"></a>00288 <span class="comment"></span>
+<a name="l00289"></a>00289 <span class="comment">  FILE            *   paf ;</span>
+<a name="l00290"></a>00290 <span class="comment">  const char            *   sval ;</span>
+<a name="l00291"></a>00291 <span class="comment">  char            key_name[FILE_NAME_SZ] ;</span>
+<a name="l00292"></a>00292 <span class="comment">  char            key_paf[FILE_NAME_SZ] ;</span>
+<a name="l00293"></a>00293 <span class="comment">  char            key_dpaf[FILE_NAME_SZ] ;</span>
+<a name="l00294"></a>00294 <span class="comment">  char            key_type[FILE_NAME_SZ] ;</span>
+<a name="l00295"></a>00295 <span class="comment">  char            key_value[FILE_NAME_SZ] ;</span>
+<a name="l00296"></a>00296 <span class="comment">  double dval=0;</span>
+<a name="l00297"></a>00297 <span class="comment"></span>
+<a name="l00298"></a>00298 <span class="comment">  int i =0;</span>
+<a name="l00299"></a>00299 <span class="comment">  int n=0;</span>
+<a name="l00300"></a>00300 <span class="comment">  sinfo_msg( "Writing %s" , name_p) ;</span>
+<a name="l00301"></a>00301 <span class="comment">  // Create the default PAF header</span>
+<a name="l00302"></a>00302 <span class="comment">  if ((paf = sinfo_paf_print_header(name_p,rec_id,"QC file","login-name",</span>
+<a name="l00303"></a>00303 <span class="comment">                    sinfo_get_datetime_iso8601())) == NULL) {</span>
+<a name="l00304"></a>00304 <span class="comment">    sinfo_msg_error( "cannot open file [%s] for output", name_p) ;</span>
+<a name="l00305"></a>00305 <span class="comment">    return -1 ;</span>
+<a name="l00306"></a>00306 <span class="comment">  }</span>
+<a name="l00307"></a>00307 <span class="comment">  if (sinfo_check_rec_status(0) == -1) {</span>
+<a name="l00308"></a>00308 <span class="comment">    sinfo_msg_error( "Something was wrong") ;</span>
+<a name="l00309"></a>00309 <span class="comment">    return -1 ;</span>
+<a name="l00310"></a>00310 <span class="comment">  }</span>
+<a name="l00311"></a>00311 <span class="comment"></span>
+<a name="l00312"></a>00312 <span class="comment">  // Test entries</span>
+<a name="l00313"></a>00313 <span class="comment">  sinfo_blank2dot(PAF_NAME_PIPE_ID,key_dpaf);</span>
+<a name="l00314"></a>00314 <span class="comment">  fprintf(paf,"%-21s \"%s\" ;# %s\" \n", key_dpaf,</span>
+<a name="l00315"></a>00315 <span class="comment">      VERSION,KEY_HELP_PIPE_ID);</span>
+<a name="l00316"></a>00316 <span class="comment"></span>
+<a name="l00317"></a>00317 <span class="comment">  strcpy(key_name,KEY_NAME_PIPEFILE);        </span>
+<a name="l00318"></a>00318 <span class="comment">  strcpy(key_paf,KEY_NAME_PIPEFILE);        </span>
+<a name="l00319"></a>00319 <span class="comment">  sinfo_blank2dot(key_paf,key_dpaf);</span>
+<a name="l00320"></a>00320 <span class="comment">  if (sinfo_propertylist_has(plist, key_name)) {</span>
+<a name="l00321"></a>00321 <span class="comment">    fprintf(paf,"%-21s \"%s\" ;# %s\" \n",key_dpaf,</span>
+<a name="l00322"></a>00322 <span class="comment">        cpl_propertylist_get_string(plist,key_name),KEY_HELP_PIPEFILE);</span>
+<a name="l00323"></a>00323 <span class="comment">  }</span>
+<a name="l00324"></a>00324 <span class="comment"></span>
+<a name="l00325"></a>00325 <span class="comment">  // Value: "TEMPORARY", "PREPROCESSED", "REDUCED" or "QCPARAM".</span>
+<a name="l00326"></a>00326 <span class="comment">  strcpy(key_name,KEY_NAME_PRO_TYPE);</span>
+<a name="l00327"></a>00327 <span class="comment">  strcpy(key_paf,PAF_NAME_PRO_TYPE);    </span>
+<a name="l00328"></a>00328 <span class="comment">  sinfo_blank2dot(key_paf,key_dpaf);</span>
+<a name="l00329"></a>00329 <span class="comment">  if (sinfo_propertylist_has(plist, key_name)) {</span>
+<a name="l00330"></a>00330 <span class="comment">    fprintf(paf,"%-21s \"%s\" ;# %s\" \n", key_dpaf,</span>
+<a name="l00331"></a>00331 <span class="comment">        cpl_propertylist_get_string(plist,key_name),KEY_HELP_PRO_TYPE);</span>
+<a name="l00332"></a>00332 <span class="comment">  }</span>
+<a name="l00333"></a>00333 <span class="comment"></span>
+<a name="l00334"></a>00334 <span class="comment">  strcpy(key_name,KEY_NAME_PRO_DATANCOM); </span>
+<a name="l00335"></a>00335 <span class="comment">  strcpy(key_paf,PAF_NAME_PRO_DATANCOM); </span>
+<a name="l00336"></a>00336 <span class="comment">  sinfo_blank2dot(key_paf,key_dpaf);</span>
+<a name="l00337"></a>00337 <span class="comment">  if (sinfo_propertylist_has(plist,key_name)) {</span>
+<a name="l00338"></a>00338 <span class="comment">    fprintf(paf,"%-21s %d ;# %s\" \n",key_dpaf,</span>
+<a name="l00339"></a>00339 <span class="comment">        cpl_propertylist_get_int(plist,key_name),KEY_HELP_PRO_DATANCOM);</span>
+<a name="l00340"></a>00340 <span class="comment">  }</span>
+<a name="l00341"></a>00341 <span class="comment">     </span>
+<a name="l00342"></a>00342 <span class="comment">  strcpy(key_name,KEY_NAME_NCORRS_NAME);</span>
+<a name="l00343"></a>00343 <span class="comment">  strcpy(key_paf,PAF_NAME_NCORRS_NAME);</span>
+<a name="l00344"></a>00344 <span class="comment">  sinfo_blank2dot(key_paf,key_dpaf);</span>
+<a name="l00345"></a>00345 <span class="comment">  if (sinfo_propertylist_has(plist, key_name)) {</span>
+<a name="l00346"></a>00346 <span class="comment">    fprintf(paf,"%-21s \"%s\" ;# %s \n", key_dpaf,</span>
+<a name="l00347"></a>00347 <span class="comment">        cpl_propertylist_get_string(plist,key_name),KEY_HELP_NCORRS_NAME);</span>
+<a name="l00348"></a>00348 <span class="comment">  }</span>
+<a name="l00349"></a>00349 <span class="comment"></span>
+<a name="l00350"></a>00350 <span class="comment">  strcpy(key_name,KEY_NAME_DET_NDSAMPLES);</span>
+<a name="l00351"></a>00351 <span class="comment">  strcpy(key_paf,PAF_NAME_DET_NDSAMPLES);</span>
+<a name="l00352"></a>00352 <span class="comment">  sinfo_blank2dot(key_paf,key_dpaf);        </span>
+<a name="l00353"></a>00353 <span class="comment">  if (sinfo_propertylist_has(plist, key_name)) {</span>
+<a name="l00354"></a>00354 <span class="comment">    fprintf(paf,"%-21s %d ;# %s \n",key_dpaf, </span>
+<a name="l00355"></a>00355 <span class="comment">        cpl_propertylist_get_int(plist,key_name),KEY_HELP_DET_NDSAMPLES);</span>
+<a name="l00356"></a>00356 <span class="comment">  }</span>
+<a name="l00357"></a>00357 <span class="comment"></span>
+<a name="l00358"></a>00358 <span class="comment">  strcpy(key_name,KEY_NAME_FILT_NAME);      </span>
+<a name="l00359"></a>00359 <span class="comment">  strcpy(key_paf,PAF_NAME_FILT_NAME);      </span>
+<a name="l00360"></a>00360 <span class="comment">  sinfo_blank2dot(key_paf,key_dpaf);        </span>
+<a name="l00361"></a>00361 <span class="comment">  if (sinfo_propertylist_has(plist, key_name)) {</span>
+<a name="l00362"></a>00362 <span class="comment">    fprintf(paf,"%-21s \"%s\" ;# %s \n", key_dpaf,</span>
+<a name="l00363"></a>00363 <span class="comment">        cpl_propertylist_get_string(plist,key_name),KEY_HELP_FILT_NAME);</span>
+<a name="l00364"></a>00364 <span class="comment">  }</span>
+<a name="l00365"></a>00365 <span class="comment"></span>
+<a name="l00366"></a>00366 <span class="comment">  strcpy(key_name,KEY_NAME_FILT_ID);        </span>
+<a name="l00367"></a>00367 <span class="comment">  strcpy(key_paf,PAF_NAME_FILT_ID);        </span>
+<a name="l00368"></a>00368 <span class="comment">  sinfo_blank2dot(key_paf,key_dpaf);        </span>
+<a name="l00369"></a>00369 <span class="comment">  if (sinfo_propertylist_has(plist, key_name)) {</span>
+<a name="l00370"></a>00370 <span class="comment">    fprintf(paf,"%-21s \"%s\" ;# %s \n",key_dpaf, </span>
+<a name="l00371"></a>00371 <span class="comment">        cpl_propertylist_get_string(plist,key_name),KEY_HELP_FILT_ID);</span>
+<a name="l00372"></a>00372 <span class="comment">  }</span>
+<a name="l00373"></a>00373 <span class="comment"></span>
+<a name="l00374"></a>00374 <span class="comment">  strcpy(key_name,KEY_NAME_PREOPTICS);        </span>
+<a name="l00375"></a>00375 <span class="comment">  strcpy(key_paf,PAF_NAME_PREOPTICS);        </span>
+<a name="l00376"></a>00376 <span class="comment">  sinfo_blank2dot(key_paf,key_dpaf);        </span>
+<a name="l00377"></a>00377 <span class="comment">  if (sinfo_propertylist_has(plist, key_name)) {</span>
+<a name="l00378"></a>00378 <span class="comment">    fprintf(paf,"%-21s \"%s\" ;# %s \n",key_dpaf, </span>
+<a name="l00379"></a>00379 <span class="comment">        cpl_propertylist_get_string(plist,key_name),KEY_HELP_PREOPTICS);</span>
+<a name="l00380"></a>00380 <span class="comment">  }</span>
+<a name="l00381"></a>00381 <span class="comment"></span>
+<a name="l00382"></a>00382 <span class="comment">  strcpy(key_name,KEY_NAME_GRAT_NAME);        </span>
+<a name="l00383"></a>00383 <span class="comment">  strcpy(key_paf,PAF_NAME_GRAT_NAME);        </span>
+<a name="l00384"></a>00384 <span class="comment">  sinfo_blank2dot(key_paf,key_dpaf);        </span>
+<a name="l00385"></a>00385 <span class="comment">  if (sinfo_propertylist_has(plist, key_name)) {</span>
+<a name="l00386"></a>00386 <span class="comment">    fprintf(paf, "%-21s \"%s\" ;# %s \n",key_dpaf, </span>
+<a name="l00387"></a>00387 <span class="comment">        cpl_propertylist_get_string(plist,key_name),KEY_HELP_GRAT_NAME);</span>
+<a name="l00388"></a>00388 <span class="comment">  }</span>
+<a name="l00389"></a>00389 <span class="comment">    </span>
+<a name="l00390"></a>00390 <span class="comment">  strcpy(key_name,KEY_NAME_GRAT_WLEN);        </span>
+<a name="l00391"></a>00391 <span class="comment">  strcpy(key_paf,PAF_NAME_GRAT_WLEN);        </span>
+<a name="l00392"></a>00392 <span class="comment">  sinfo_blank2dot(key_paf,key_dpaf);        </span>
+<a name="l00393"></a>00393 <span class="comment">  if (sinfo_propertylist_has(plist, key_name)) {</span>
+<a name="l00394"></a>00394 <span class="comment">    fprintf(paf, "%-21s %f ;# %s \n", key_dpaf,</span>
+<a name="l00395"></a>00395 <span class="comment">        cpl_propertylist_get_double(plist,key_name),KEY_HELP_GRAT_WLEN);</span>
+<a name="l00396"></a>00396 <span class="comment">  }</span>
+<a name="l00397"></a>00397 <span class="comment"></span>
+<a name="l00398"></a>00398 <span class="comment">  strcpy(key_name,KEY_NAME_PRO_RECID);  </span>
+<a name="l00399"></a>00399 <span class="comment">  strcpy(key_paf,PAF_NAME_PRO_RECID);  </span>
+<a name="l00400"></a>00400 <span class="comment">  sinfo_blank2dot(key_paf,key_dpaf);        </span>
+<a name="l00401"></a>00401 <span class="comment">  if (sinfo_propertylist_has(plist, key_name)) {</span>
+<a name="l00402"></a>00402 <span class="comment">    fprintf(paf,"%-21s \"%s\" ;# %s \n", key_dpaf,</span>
+<a name="l00403"></a>00403 <span class="comment">        cpl_propertylist_get_string(plist,key_name),KEY_HELP_PRO_RECID);</span>
+<a name="l00404"></a>00404 <span class="comment">  }</span>
+<a name="l00405"></a>00405 <span class="comment"></span>
+<a name="l00406"></a>00406 <span class="comment"></span>
+<a name="l00407"></a>00407 <span class="comment">  // snprintf(cval, MAX_NAME_SIZE-1,"CPL-%s", get_cpl_version());</span>
+<a name="l00408"></a>00408 <span class="comment">  strcpy(key_name,KEY_NAME_PRO_DRSID); </span>
+<a name="l00409"></a>00409 <span class="comment">  strcpy(key_paf,PAF_NAME_PRO_DRSID); </span>
+<a name="l00410"></a>00410 <span class="comment">  sinfo_blank2dot(key_paf,key_dpaf);        </span>
+<a name="l00411"></a>00411 <span class="comment">  if (sinfo_propertylist_has(plist, key_name)) {</span>
+<a name="l00412"></a>00412 <span class="comment">    fprintf(paf,"%-21s \"%s\" ;# %s \n",key_dpaf, </span>
+<a name="l00413"></a>00413 <span class="comment">        cpl_propertylist_get_string(plist,key_name),KEY_HELP_PRO_DRSID);</span>
+<a name="l00414"></a>00414 <span class="comment">  }</span>
+<a name="l00415"></a>00415 <span class="comment"></span>
+<a name="l00416"></a>00416 <span class="comment">  if (sinfo_propertylist_has(plist,KEY_NAME_DATE_OBS)) {</span>
+<a name="l00417"></a>00417 <span class="comment">    sval = sinfo_pfits_get_date_obs(plist);</span>
+<a name="l00418"></a>00418 <span class="comment">    strcpy(key_paf,KEY_NAME_DATE_OBS); </span>
+<a name="l00419"></a>00419 <span class="comment">    sinfo_blank2dot(key_paf,key_dpaf);        </span>
+<a name="l00420"></a>00420 <span class="comment">    fprintf(paf, "%-21s \"%s\" ;# %s\n",key_dpaf, </span>
+<a name="l00421"></a>00421 <span class="comment">        sval,KEY_HELP_DATE_OBS) ;</span>
+<a name="l00422"></a>00422 <span class="comment">  }</span>
+<a name="l00423"></a>00423 <span class="comment"></span>
+<a name="l00424"></a>00424 <span class="comment">  </span>
+<a name="l00425"></a>00425 <span class="comment">  if (sinfo_propertylist_has(plist,KEY_NAME_TEL_AIRM_START)) {</span>
+<a name="l00426"></a>00426 <span class="comment">    dval = sinfo_pfits_get_airmass_start(plist);</span>
+<a name="l00427"></a>00427 <span class="comment">    strcpy(key_paf,PAF_NAME_TEL_AIRM_START); </span>
+<a name="l00428"></a>00428 <span class="comment">    sinfo_blank2dot(key_paf,key_dpaf);        </span>
+<a name="l00429"></a>00429 <span class="comment">    fprintf(paf, "%-21s \"%f\" ;# %s \n",key_dpaf, </span>
+<a name="l00430"></a>00430 <span class="comment">        dval,KEY_HELP_TEL_AIRM_START) ;</span>
+<a name="l00431"></a>00431 <span class="comment">  }</span>
+<a name="l00432"></a>00432 <span class="comment">   </span>
+<a name="l00433"></a>00433 <span class="comment">  if (sinfo_propertylist_has(plist,KEY_NAME_ARCFILE)) {</span>
+<a name="l00434"></a>00434 <span class="comment">    sval = sinfo_pfits_get_arcfile(plist);</span>
+<a name="l00435"></a>00435 <span class="comment">    strcpy(key_paf,KEY_NAME_ARCFILE);</span>
+<a name="l00436"></a>00436 <span class="comment">    sinfo_blank2dot(key_paf,key_dpaf);      </span>
+<a name="l00437"></a>00437 <span class="comment">    fprintf(paf, "%-21s \"%s\" ;# %s \n", key_dpaf,sval,KEY_HELP_ARCFILE) ;</span>
+<a name="l00438"></a>00438 <span class="comment"></span>
+<a name="l00439"></a>00439 <span class="comment">  } else if (sinfo_propertylist_has(plist,KEY_NAME_PRO_REC1_RAW1_NAME)) {</span>
+<a name="l00440"></a>00440 <span class="comment">    sval = sinfo_pfits_get_rec1raw1name(plist);</span>
+<a name="l00441"></a>00441 <span class="comment">    strcpy(key_paf,KEY_NAME_ARCFILE);</span>
+<a name="l00442"></a>00442 <span class="comment">    sinfo_blank2dot(key_paf,key_dpaf);       </span>
+<a name="l00443"></a>00443 <span class="comment">    fprintf(paf, "%-21s \"%s\" ;# %s \n", key_dpaf,sval,KEY_HELP_ARCFILE) ;</span>
+<a name="l00444"></a>00444 <span class="comment">  } else {</span>
+<a name="l00445"></a>00445 <span class="comment">    sinfo_msg_error("%s is missing QC LOG will fail!",KEY_NAME_ARCFILE);</span>
+<a name="l00446"></a>00446 <span class="comment">  }</span>
+<a name="l00447"></a>00447 <span class="comment"></span>
+<a name="l00448"></a>00448 <span class="comment">  if (sinfo_propertylist_has(plist,KEY_NAME_TPL_ID)) {</span>
+<a name="l00449"></a>00449 <span class="comment">    sval = sinfo_pfits_get_templateid(plist);</span>
+<a name="l00450"></a>00450 <span class="comment">    strcpy(key_paf,PAF_NAME_TPL_ID);</span>
+<a name="l00451"></a>00451 <span class="comment">    sinfo_blank2dot(key_paf,key_dpaf);       </span>
+<a name="l00452"></a>00452 <span class="comment">    fprintf(paf, "%-21s \"%s\" ; # %s\n", key_dpaf,</span>
+<a name="l00453"></a>00453 <span class="comment">        sval,KEY_HELP_TPL_ID) ;</span>
+<a name="l00454"></a>00454 <span class="comment"> </span>
+<a name="l00455"></a>00455 <span class="comment">  }</span>
+<a name="l00456"></a>00456 <span class="comment"></span>
+<a name="l00457"></a>00457 <span class="comment">  if (sinfo_propertylist_has(plist,KEY_NAME_DET_DIT)) { </span>
+<a name="l00458"></a>00458 <span class="comment">    strcpy(key_paf,PAF_NAME_DET_DIT); </span>
+<a name="l00459"></a>00459 <span class="comment">    sinfo_blank2dot(key_paf,key_dpaf);        </span>
+<a name="l00460"></a>00460 <span class="comment">    fprintf(paf,"%-21s %f ; # %s\n", key_dpaf,</span>
+<a name="l00461"></a>00461 <span class="comment">        sinfo_pfits_get_dit(plist),KEY_HELP_DET_DIT) ;</span>
+<a name="l00462"></a>00462 <span class="comment">  }</span>
+<a name="l00463"></a>00463 <span class="comment"></span>
+<a name="l00464"></a>00464 <span class="comment"></span>
+<a name="l00465"></a>00465 <span class="comment">  if (sinfo_propertylist_has(plist,KEY_NAME_DET_NDIT)) {</span>
+<a name="l00466"></a>00466 <span class="comment">    strcpy(key_paf,PAF_NAME_DET_NDIT); </span>
+<a name="l00467"></a>00467 <span class="comment">    sinfo_blank2dot(key_paf,key_dpaf); </span>
+<a name="l00468"></a>00468 <span class="comment">    fprintf(paf,"%-21s %d ; # %s\n", key_dpaf,</span>
+<a name="l00469"></a>00469 <span class="comment">        sinfo_pfits_get_ndit(plist),KEY_HELP_DET_NDIT) ;</span>
+<a name="l00470"></a>00470 <span class="comment">  }</span>
+<a name="l00471"></a>00471 <span class="comment"></span>
+<a name="l00472"></a>00472 <span class="comment">  if (sinfo_propertylist_has(plist,KEY_NAME_NCORRS_NAME)) {</span>
+<a name="l00473"></a>00473 <span class="comment">    sval = sinfo_pfits_get_ncorrs_name(plist);</span>
+<a name="l00474"></a>00474 <span class="comment">    strcpy(key_paf,PAF_NAME_NCORRS_NAME); </span>
+<a name="l00475"></a>00475 <span class="comment">    sinfo_blank2dot(key_paf,key_dpaf);        </span>
+<a name="l00476"></a>00476 <span class="comment"></span>
+<a name="l00477"></a>00477 <span class="comment">    fprintf(paf, "%-21s \"%s\" ; # %s\n", key_dpaf,</span>
+<a name="l00478"></a>00478 <span class="comment">        sval, KEY_HELP_NCORRS_NAME) ;</span>
+<a name="l00479"></a>00479 <span class="comment">  }</span>
+<a name="l00480"></a>00480 <span class="comment">    </span>
+<a name="l00481"></a>00481 <span class="comment">  if (sinfo_propertylist_has(plist,KEY_NAME_DPR_TYPE)) {</span>
+<a name="l00482"></a>00482 <span class="comment">    sval = sinfo_pfits_get_dpr_type(plist);</span>
+<a name="l00483"></a>00483 <span class="comment">    strcpy(key_paf,PAF_NAME_DPR_TYPE); </span>
+<a name="l00484"></a>00484 <span class="comment">    sinfo_blank2dot(key_paf,key_dpaf);        </span>
+<a name="l00485"></a>00485 <span class="comment">    fprintf(paf, "%-21s \"%s\" ; # %s\n", key_dpaf,</span>
+<a name="l00486"></a>00486 <span class="comment">        sval, KEY_HELP_DPR_TYPE) ;</span>
+<a name="l00487"></a>00487 <span class="comment">  }</span>
+<a name="l00488"></a>00488 <span class="comment"></span>
+<a name="l00489"></a>00489 <span class="comment">  if (sinfo_propertylist_has(plist,KEY_NAME_DPR_TECH)) {</span>
+<a name="l00490"></a>00490 <span class="comment">    sval = sinfo_pfits_get_dpr_tech(plist);</span>
+<a name="l00491"></a>00491 <span class="comment">    strcpy(key_paf,PAF_NAME_DPR_TECH); </span>
+<a name="l00492"></a>00492 <span class="comment">    sinfo_blank2dot(key_paf,key_dpaf);   </span>
+<a name="l00493"></a>00493 <span class="comment">    fprintf(paf, "%-21s \"%s\" ; # %s\n", key_dpaf,</span>
+<a name="l00494"></a>00494 <span class="comment">        sval, KEY_HELP_DPR_TECH) ;</span>
+<a name="l00495"></a>00495 <span class="comment">  }</span>
+<a name="l00496"></a>00496 <span class="comment">    </span>
+<a name="l00497"></a>00497 <span class="comment"></span>
+<a name="l00498"></a>00498 <span class="comment">  if (sinfo_propertylist_has(plist,KEY_NAME_DPR_CATG)) {</span>
+<a name="l00499"></a>00499 <span class="comment">    sval = sinfo_pfits_get_dpr_catg(plist);</span>
+<a name="l00500"></a>00500 <span class="comment">    strcpy(key_paf,PAF_NAME_DPR_CATG); </span>
+<a name="l00501"></a>00501 <span class="comment">    sinfo_blank2dot(key_paf,key_dpaf); </span>
+<a name="l00502"></a>00502 <span class="comment">    fprintf(paf, "%-21s \"%s\" ; # %s\n", key_dpaf,</span>
+<a name="l00503"></a>00503 <span class="comment">        sval, KEY_HELP_DPR_CATG) ;</span>
+<a name="l00504"></a>00504 <span class="comment">  }</span>
+<a name="l00505"></a>00505 <span class="comment">    </span>
+<a name="l00506"></a>00506 <span class="comment">  strcpy(key_paf,PAF_NAME_PRO_CATG); </span>
+<a name="l00507"></a>00507 <span class="comment">  sinfo_blank2dot(key_paf,key_dpaf); </span>
+<a name="l00508"></a>00508 <span class="comment">  fprintf(paf, "%-21s \"%s\" ; # %s\n", key_dpaf,</span>
+<a name="l00509"></a>00509 <span class="comment">      pro_catg, KEY_HELP_PRO_CATG) ;</span>
+<a name="l00510"></a>00510 <span class="comment"></span>
+<a name="l00511"></a>00511 <span class="comment">  if (sinfo_propertylist_has(plist,KEY_NAME_INS_SETUP)) {</span>
+<a name="l00512"></a>00512 <span class="comment">    sval = sinfo_pfits_get_ins_setup(plist);</span>
+<a name="l00513"></a>00513 <span class="comment">    strcpy(key_paf,PAF_NAME_INS_SETUP); </span>
+<a name="l00514"></a>00514 <span class="comment">    sinfo_blank2dot(key_paf,key_dpaf); </span>
+<a name="l00515"></a>00515 <span class="comment">    fprintf(paf, "%-21s \"%s\" ; # %s\n", key_dpaf,</span>
+<a name="l00516"></a>00516 <span class="comment">        sval, KEY_HELP_INS_SETUP) ;</span>
+<a name="l00517"></a>00517 <span class="comment">  }</span>
+<a name="l00518"></a>00518 <span class="comment"></span>
+<a name="l00519"></a>00519 <span class="comment">  n=cpl_table_get_nrow(qclog);</span>
+<a name="l00520"></a>00520 <span class="comment">  for(i=0;i<n;i++) {</span>
+<a name="l00521"></a>00521 <span class="comment">    strcpy(key_paf,cpl_table_get_string(qclog,"key_name",i));</span>
+<a name="l00522"></a>00522 <span class="comment">    sinfo_blank2dot(key_paf,key_name);</span>
+<a name="l00523"></a>00523 <span class="comment">    strcpy(key_type,cpl_table_get_string(qclog,"key_type",i));</span>
+<a name="l00524"></a>00524 <span class="comment">    strcpy(key_value,cpl_table_get_string(qclog,"key_value",i));</span>
+<a name="l00525"></a>00525 <span class="comment">    if(strcmp(key_type,"CPL_TYPE_STRING") == 0) {</span>
+<a name="l00526"></a>00526 <span class="comment">      strcat(key_name,"               \"%s\"\n");</span>
+<a name="l00527"></a>00527 <span class="comment">      fprintf(paf, key_name, key_value) ;</span>
+<a name="l00528"></a>00528 <span class="comment">    } else if(strcmp(key_type,"CPL_TYPE_BOOL") == 0) {</span>
+<a name="l00529"></a>00529 <span class="comment">      strcat(key_name,"               ");</span>
+<a name="l00530"></a>00530 <span class="comment">      strcat(key_name,"%c\n");</span>
+<a name="l00531"></a>00531 <span class="comment">      fprintf(paf, key_name, atoi(key_value)) ;</span>
+<a name="l00532"></a>00532 <span class="comment">    } else if(strcmp(key_type,"CPL_TYPE_INT") == 0) {</span>
+<a name="l00533"></a>00533 <span class="comment">      strcat(key_name,"               ");</span>
+<a name="l00534"></a>00534 <span class="comment">      strcat(key_name,"%d\n");</span>
+<a name="l00535"></a>00535 <span class="comment">      fprintf(paf, key_name, atoi(key_value)) ;</span>
+<a name="l00536"></a>00536 <span class="comment">    } else if(strcmp(key_type,"CPL_TYPE_FLOAT") == 0) {</span>
+<a name="l00537"></a>00537 <span class="comment">      strcat(key_name,"               ");</span>
+<a name="l00538"></a>00538 <span class="comment">      strcat(key_name,"%g\n");</span>
+<a name="l00539"></a>00539 <span class="comment">      fprintf(paf, key_name, (float) atof(key_value)) ;</span>
+<a name="l00540"></a>00540 <span class="comment">    } else if(strcmp(key_type,"CPL_TYPE_DOUBLE") == 0) {</span>
+<a name="l00541"></a>00541 <span class="comment">      strcat(key_name,"               ");</span>
+<a name="l00542"></a>00542 <span class="comment">      strcat(key_name,"%g\n");</span>
+<a name="l00543"></a>00543 <span class="comment">      fprintf(paf, key_name, atof(key_value)) ;</span>
+<a name="l00544"></a>00544 <span class="comment">    }</span>
+<a name="l00545"></a>00545 <span class="comment"></span>
+<a name="l00546"></a>00546 <span class="comment">  }</span>
+<a name="l00547"></a>00547 <span class="comment">  fprintf(paf, "\n");</span>
+<a name="l00548"></a>00548 <span class="comment">  fclose(paf) ;</span>
+<a name="l00549"></a>00549 <span class="comment"></span>
+<a name="l00550"></a>00550 <span class="comment">  if (sinfo_check_rec_status(1) == -1) {</span>
+<a name="l00551"></a>00551 <span class="comment">    sinfo_msg_error( "Something was wrong reading FITS keys") ;</span>
+<a name="l00552"></a>00552 <span class="comment">    return -1 ;</span>
+<a name="l00553"></a>00553 <span class="comment">  }</span>
+<a name="l00554"></a>00554 <span class="comment">  return 0;</span>
+<a name="l00555"></a>00555 <span class="comment"></span>
+<a name="l00556"></a>00556 <span class="comment">}</span>
+<a name="l00557"></a>00557 <span class="comment"></span>
+<a name="l00558"></a>00558 <span class="comment">*/</span>
+<a name="l00559"></a>00559 
+<a name="l00560"></a>00560 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00573"></a>00573 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00574"></a>00574 
+<a name="l00575"></a>00575 
+<a name="l00576"></a>00576 <span class="keywordtype">int</span> sinfo_pro_save_ima(
+<a name="l00577"></a>00577                cpl_image       *   ima,
+<a name="l00578"></a>00578                cpl_frameset    *   ref,
+<a name="l00579"></a>00579                cpl_frameset    *   <span class="keyword">set</span>,
+<a name="l00580"></a>00580                <span class="keyword">const</span> <span class="keywordtype">char</span>      *   out_file,
+<a name="l00581"></a>00581                <span class="keyword">const</span> <span class="keywordtype">char</span>      *   pro_catg,
+<a name="l00582"></a>00582                cpl_table       *   qclog,
+<a name="l00583"></a>00583                <span class="keyword">const</span> <span class="keywordtype">char</span>      *   recid,
+<a name="l00584"></a>00584                cpl_parameterlist* parlist)
+<a name="l00585"></a>00585 
+<a name="l00586"></a>00586 {
+<a name="l00587"></a>00587   <span class="keywordtype">char</span>      *         name_o ;
+<a name="l00588"></a>00588   <span class="keywordtype">char</span>      *         name_p ;
+<a name="l00589"></a>00589 
+<a name="l00590"></a>00590   cpl_propertylist *   plist =NULL;
+<a name="l00591"></a>00591   cpl_frame       *   first_frame=NULL;
+<a name="l00592"></a>00592   <span class="keywordtype">char</span>            *   ref_file=NULL;
+<a name="l00593"></a>00593 
+<a name="l00594"></a>00594   <span class="comment">/* Get the reference file  */</span>
+<a name="l00595"></a>00595   first_frame = cpl_frameset_get_first(ref) ;
+<a name="l00596"></a>00596   ref_file = (<span class="keywordtype">char</span>*) cpl_strdup(cpl_frame_get_filename(first_frame)) ;
+<a name="l00597"></a>00597  
+<a name="l00598"></a>00598   name_o = cpl_malloc(FILE_NAME_SZ * <span class="keyword">sizeof</span>(<span class="keywordtype">char</span>));
+<a name="l00599"></a>00599   name_p = cpl_malloc(FILE_NAME_SZ * <span class="keyword">sizeof</span>(<span class="keywordtype">char</span>));
+<a name="l00600"></a>00600   sinfo_check_name(out_file, &name_o, CPL_FRAME_TYPE_IMAGE, &name_p);
+<a name="l00601"></a>00601   sinfo_msg( <span class="stringliteral">"Writing ima %s pro catg %s"</span> , name_o, pro_catg) ;
+<a name="l00602"></a>00602 
+<a name="l00603"></a>00603   <span class="comment">/* Get FITS header from reference file */</span>
+<a name="l00604"></a>00604   <span class="keywordflow">if</span> ((cpl_error_code)((plist=cpl_propertylist_load(ref_file, 0)) == NULL)) {
+<a name="l00605"></a>00605     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>( <span class="stringliteral">"getting header from reference ima frame %s"</span>,ref_file);
+<a name="l00606"></a>00606     cpl_propertylist_delete(plist) ;
+<a name="l00607"></a>00607     cpl_free(ref_file);
+<a name="l00608"></a>00608     <span class="keywordflow">return</span> -1 ;
+<a name="l00609"></a>00609   }
+<a name="l00610"></a>00610 
+<a name="l00611"></a>00611   sinfo_clean_header(&plist);
+<a name="l00612"></a>00612   <span class="keywordflow">if</span> ( ( strstr(pro_catg,<span class="stringliteral">"MASTER_PSF"</span>) != NULL ) || 
+<a name="l00613"></a>00613        ( strstr(pro_catg,<span class="stringliteral">"STD_STAR_SPECTRUM"</span>) != NULL ) || 
+<a name="l00614"></a>00614        ( strstr(pro_catg,<span class="stringliteral">"STD_STAR_SPECTRA"</span>) != NULL ) ) {
+<a name="l00615"></a>00615     sinfo_clean_cube_header(&plist);
+<a name="l00616"></a>00616   }
+<a name="l00617"></a>00617 
+<a name="l00618"></a>00618   <span class="comment">/* Add DataFlow keywords and log the saved file in the input frameset */</span>
+<a name="l00619"></a>00619   sinfo_log_pro(name_o, pro_catg, CPL_FRAME_TYPE_IMAGE, 
+<a name="l00620"></a>00620         ref,&<span class="keyword">set</span>,&plist,parlist,recid);
+<a name="l00621"></a>00621   <span class="keywordflow">if</span>(qclog != NULL) {
+<a name="l00622"></a>00622     sinfo_pfits_put_qc(plist, qclog) ;
+<a name="l00623"></a>00623   }
+<a name="l00624"></a>00624 
+<a name="l00625"></a>00625   <span class="comment">/* Save the file */</span>
+<a name="l00626"></a>00626   <span class="keywordflow">if</span> (cpl_image_save(ima, name_o, CPL_BPP_IEEE_FLOAT, 
+<a name="l00627"></a>00627              plist,CPL_IO_DEFAULT)!=CPL_ERROR_NONE) {
+<a name="l00628"></a>00628     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>( <span class="stringliteral">"Cannot save the product %s"</span>,name_o);
+<a name="l00629"></a>00629     cpl_propertylist_delete(plist) ;
+<a name="l00630"></a>00630     cpl_free(ref_file);
+<a name="l00631"></a>00631     cpl_free(name_o);
+<a name="l00632"></a>00632     cpl_free(name_p);
+<a name="l00633"></a>00633     <span class="keywordflow">return</span> -1 ;
+<a name="l00634"></a>00634   }
+<a name="l00635"></a>00635 
+<a name="l00636"></a>00636   <span class="comment">/* THE PAF FILE FOR QC PARAMETERS </span>
+<a name="l00637"></a>00637 <span class="comment">     if( qclog != NULL) {</span>
+<a name="l00638"></a>00638 <span class="comment">     sinfo_save_paf(name_p,recid,qclog,plist,pro_catg);  </span>
+<a name="l00639"></a>00639 <span class="comment">     }</span>
+<a name="l00640"></a>00640 <span class="comment">  */</span>
+<a name="l00641"></a>00641 
+<a name="l00642"></a>00642   cpl_propertylist_delete(plist) ;
+<a name="l00643"></a>00643   cpl_msg_indent_less() ;
+<a name="l00644"></a>00644   cpl_free(name_o);
+<a name="l00645"></a>00645   cpl_free(name_p);
+<a name="l00646"></a>00646   cpl_free(ref_file);
+<a name="l00647"></a>00647 
+<a name="l00648"></a>00648   <span class="keywordflow">return</span> 0 ;
+<a name="l00649"></a>00649 }
+<a name="l00650"></a>00650 
+<a name="l00651"></a>00651 
+<a name="l00652"></a>00652 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00665"></a>00665 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00666"></a>00666 
+<a name="l00667"></a>00667 
+<a name="l00668"></a>00668 
+<a name="l00669"></a>00669 <span class="keywordtype">int</span> sinfo_pro_save_tbl(
+<a name="l00670"></a>00670                cpl_table       *   table,
+<a name="l00671"></a>00671                cpl_frameset    *   ref,
+<a name="l00672"></a>00672                cpl_frameset    *   <span class="keyword">set</span>,
+<a name="l00673"></a>00673                <span class="keyword">const</span> <span class="keywordtype">char</span>      *   out_file,
+<a name="l00674"></a>00674                <span class="keyword">const</span> <span class="keywordtype">char</span>      *   pro_catg,      
+<a name="l00675"></a>00675                cpl_table       *   qclog,
+<a name="l00676"></a>00676                <span class="keyword">const</span> <span class="keywordtype">char</span>      *   recid,
+<a name="l00677"></a>00677                cpl_parameterlist* parlist)
+<a name="l00678"></a>00678 
+<a name="l00679"></a>00679 {
+<a name="l00680"></a>00680   <span class="keywordtype">char</span> *    name_o =NULL;
+<a name="l00681"></a>00681   <span class="keywordtype">char</span> *    name_p =NULL;
+<a name="l00682"></a>00682   cpl_propertylist *   plist=NULL ;
+<a name="l00683"></a>00683   cpl_frame* first_frame=NULL;
+<a name="l00684"></a>00684   <span class="keywordtype">char</span>* ref_file=NULL;
+<a name="l00685"></a>00685   <span class="comment">/* Get the reference file  */</span>
+<a name="l00686"></a>00686   first_frame = cpl_frameset_get_first(ref) ;
+<a name="l00687"></a>00687   ref_file = cpl_strdup(cpl_frame_get_filename(first_frame)) ;
+<a name="l00688"></a>00688  
+<a name="l00689"></a>00689   name_o = cpl_malloc(FILE_NAME_SZ * <span class="keyword">sizeof</span>(<span class="keywordtype">char</span>));
+<a name="l00690"></a>00690   name_p = cpl_malloc(FILE_NAME_SZ * <span class="keyword">sizeof</span>(<span class="keywordtype">char</span>));
+<a name="l00691"></a>00691   sinfo_check_name(out_file, &name_o, CPL_FRAME_TYPE_TABLE, &name_p);
+<a name="l00692"></a>00692   sinfo_msg( <span class="stringliteral">"Writing tbl %s pro catg %s"</span> , name_o, pro_catg) ;
+<a name="l00693"></a>00693 
+<a name="l00694"></a>00694   <span class="comment">/* Get FITS header from reference file */</span>
+<a name="l00695"></a>00695   <span class="keywordflow">if</span> ((cpl_error_code)((plist = cpl_propertylist_load(ref_file,0)) == NULL)) 
+<a name="l00696"></a>00696     {
+<a name="l00697"></a>00697       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>( <span class="stringliteral">"getting header from tbl frame %s"</span>,ref_file);
+<a name="l00698"></a>00698       cpl_propertylist_delete(plist) ;
+<a name="l00699"></a>00699       cpl_free(ref_file);
+<a name="l00700"></a>00700       cpl_free(name_o);
+<a name="l00701"></a>00701       cpl_free(name_p);
+<a name="l00702"></a>00702       <span class="keywordflow">return</span> -1 ;
+<a name="l00703"></a>00703     }
+<a name="l00704"></a>00704   sinfo_clean_header(&plist);
+<a name="l00705"></a>00705 
+<a name="l00706"></a>00706   <span class="comment">/* Add DataFlow keywords and log the saved file in the input frameset */</span>
+<a name="l00707"></a>00707   sinfo_log_pro(name_o, pro_catg, CPL_FRAME_TYPE_TABLE, 
+<a name="l00708"></a>00708         ref,&<span class="keyword">set</span>,&plist,parlist,recid);
+<a name="l00709"></a>00709   <span class="keywordflow">if</span>(qclog != NULL) {
+<a name="l00710"></a>00710     sinfo_pfits_put_qc(plist, qclog) ;
+<a name="l00711"></a>00711   }
+<a name="l00712"></a>00712   <span class="comment">/* Save the file */</span>
+<a name="l00713"></a>00713   <span class="keywordflow">if</span> (cpl_table_save(table, plist, NULL, name_o, CPL_IO_DEFAULT) 
+<a name="l00714"></a>00714       != CPL_ERROR_NONE) {
+<a name="l00715"></a>00715     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>( <span class="stringliteral">"Cannot save the product: %s"</span>, name_o);
+<a name="l00716"></a>00716     cpl_propertylist_delete(plist) ;
+<a name="l00717"></a>00717     cpl_free(ref_file);
+<a name="l00718"></a>00718     cpl_free(name_o);
+<a name="l00719"></a>00719     cpl_free(name_p);
+<a name="l00720"></a>00720     <span class="keywordflow">return</span> -1 ;
+<a name="l00721"></a>00721   }
+<a name="l00722"></a>00722 
+<a name="l00723"></a>00723  
+<a name="l00724"></a>00724   <span class="comment">/* THE PAF FILE FOR QC PARAMETERS </span>
+<a name="l00725"></a>00725 <span class="comment">     if (qclog != NULL) {</span>
+<a name="l00726"></a>00726 <span class="comment">     sinfo_save_paf(name_p,recid,qclog,plist,pro_catg);</span>
+<a name="l00727"></a>00727 <span class="comment">     }</span>
+<a name="l00728"></a>00728 <span class="comment">  */</span>
+<a name="l00729"></a>00729   cpl_propertylist_delete(plist) ;
+<a name="l00730"></a>00730   cpl_msg_indent_less() ;
+<a name="l00731"></a>00731   cpl_free(name_o);
+<a name="l00732"></a>00732   cpl_free(name_p);
+<a name="l00733"></a>00733   cpl_free(ref_file);
+<a name="l00734"></a>00734   <span class="keywordflow">return</span> 0 ;
+<a name="l00735"></a>00735 }
+<a name="l00736"></a>00736 
+<a name="l00737"></a>00737 
+<a name="l00738"></a>00738 
+<a name="l00739"></a>00739 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00752"></a>00752 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00753"></a>00753 
+<a name="l00754"></a>00754 
+<a name="l00755"></a>00755 
+<a name="l00756"></a>00756 <span class="keywordtype">int</span> sinfo_pro_save_ims(
+<a name="l00757"></a>00757                cpl_imagelist   *   ims,
+<a name="l00758"></a>00758                cpl_frameset    *   ref,
+<a name="l00759"></a>00759                cpl_frameset    *   <span class="keyword">set</span>,
+<a name="l00760"></a>00760                <span class="keyword">const</span> <span class="keywordtype">char</span>      *   out_file,
+<a name="l00761"></a>00761                <span class="keyword">const</span> <span class="keywordtype">char</span>      *   pro_catg,      
+<a name="l00762"></a>00762                cpl_table       *   qclog,
+<a name="l00763"></a>00763                <span class="keyword">const</span> <span class="keywordtype">char</span>      *   recid,
+<a name="l00764"></a>00764                cpl_parameterlist* parlist)
+<a name="l00765"></a>00765 
+<a name="l00766"></a>00766 {
+<a name="l00767"></a>00767   <span class="keywordtype">char</span> *               name_o=NULL;
+<a name="l00768"></a>00768   <span class="keywordtype">char</span> *               name_p=NULL;
+<a name="l00769"></a>00769 
+<a name="l00770"></a>00770   cpl_propertylist * plist=NULL ;
+<a name="l00771"></a>00771   cpl_frame* first_frame=NULL;
+<a name="l00772"></a>00772   <span class="keywordtype">char</span>* ref_file=NULL;
+<a name="l00773"></a>00773     
+<a name="l00774"></a>00774   <span class="comment">/* Get the reference file  */</span>
+<a name="l00775"></a>00775   first_frame = cpl_frameset_get_first(ref) ;
+<a name="l00776"></a>00776   ref_file = cpl_strdup(cpl_frame_get_filename(first_frame)) ;
+<a name="l00777"></a>00777 
+<a name="l00778"></a>00778   name_o = cpl_malloc(FILE_NAME_SZ * <span class="keyword">sizeof</span>(<span class="keywordtype">char</span>));
+<a name="l00779"></a>00779   name_p = cpl_malloc(FILE_NAME_SZ * <span class="keyword">sizeof</span>(<span class="keywordtype">char</span>));
+<a name="l00780"></a>00780   sinfo_check_name(out_file, &name_o, CPL_FRAME_TYPE_IMAGE, &name_p);
+<a name="l00781"></a>00781   sinfo_msg( <span class="stringliteral">"Writing ims %s pro catg %s"</span> , name_o, pro_catg) ;
+<a name="l00782"></a>00782   <span class="comment">/* Get FITS header from reference file */</span>
+<a name="l00783"></a>00783   <span class="keywordflow">if</span> ((cpl_error_code)((plist = cpl_propertylist_load(ref_file, 0)) == NULL))
+<a name="l00784"></a>00784     {
+<a name="l00785"></a>00785       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>( <span class="stringliteral">"getting header from ims frame %s"</span>,ref_file);
+<a name="l00786"></a>00786       cpl_propertylist_delete(plist) ;
+<a name="l00787"></a>00787       cpl_free(ref_file);
+<a name="l00788"></a>00788       cpl_free(name_o);
+<a name="l00789"></a>00789       cpl_free(name_p);
+<a name="l00790"></a>00790       <span class="keywordflow">return</span> -1 ;
+<a name="l00791"></a>00791     }
+<a name="l00792"></a>00792   sinfo_clean_header(&plist);
+<a name="l00793"></a>00793   <span class="keywordflow">if</span> ( ( strstr(pro_catg,<span class="stringliteral">"STD"</span>) != NULL ) || 
+<a name="l00794"></a>00794        ( strstr(pro_catg,<span class="stringliteral">"PSF"</span>) != NULL ) || 
+<a name="l00795"></a>00795        ( strstr(pro_catg,<span class="stringliteral">"OBJ"</span>) != NULL ) ) {
+<a name="l00796"></a>00796     sinfo_clean_cube_header(&plist);
+<a name="l00797"></a>00797   }
+<a name="l00798"></a>00798 
+<a name="l00799"></a>00799   <span class="comment">/* Add DataFlow keywords and log the saved file in the input frameset */</span>
+<a name="l00800"></a>00800   sinfo_log_pro(name_o, pro_catg, CPL_FRAME_TYPE_IMAGE, 
+<a name="l00801"></a>00801         ref,&<span class="keyword">set</span>,&plist,parlist,recid);
+<a name="l00802"></a>00802    
+<a name="l00803"></a>00803   <span class="keywordflow">if</span>(qclog != NULL) {
+<a name="l00804"></a>00804     sinfo_pfits_put_qc(plist, qclog) ;
+<a name="l00805"></a>00805   }
+<a name="l00806"></a>00806    
+<a name="l00807"></a>00807 
+<a name="l00808"></a>00808   <span class="comment">/* Save the file */</span>
+<a name="l00809"></a>00809   <span class="keywordflow">if</span> (cpl_imagelist_save(ims, name_o, CPL_BPP_IEEE_FLOAT, 
+<a name="l00810"></a>00810              plist,CPL_IO_DEFAULT)!=CPL_ERROR_NONE) {
+<a name="l00811"></a>00811     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>( <span class="stringliteral">"Cannot save the product %s"</span>,name_o);
+<a name="l00812"></a>00812     cpl_propertylist_delete(plist) ;
+<a name="l00813"></a>00813     cpl_free(ref_file);
+<a name="l00814"></a>00814     cpl_free(name_o);
+<a name="l00815"></a>00815     cpl_free(name_p);
+<a name="l00816"></a>00816     <span class="keywordflow">return</span> -1 ;
+<a name="l00817"></a>00817   }
+<a name="l00818"></a>00818 
+<a name="l00819"></a>00819   <span class="comment">/* THE PAF FILE FOR QC PARAMETERS </span>
+<a name="l00820"></a>00820 <span class="comment">     if (qclog != NULL) {</span>
+<a name="l00821"></a>00821 <span class="comment">     sinfo_save_paf(name_p,recid,qclog,plist,pro_catg);</span>
+<a name="l00822"></a>00822 <span class="comment">     }</span>
+<a name="l00823"></a>00823 <span class="comment">  */</span>
+<a name="l00824"></a>00824   cpl_propertylist_delete(plist) ;
+<a name="l00825"></a>00825   cpl_msg_indent_less() ;
+<a name="l00826"></a>00826   cpl_free(name_o);
+<a name="l00827"></a>00827   cpl_free(name_p);
+<a name="l00828"></a>00828   cpl_free(ref_file);
+<a name="l00829"></a>00829   <span class="keywordflow">return</span> 0 ;
+<a name="l00830"></a>00830 }
+<a name="l00831"></a>00831 
+<a name="l00832"></a>00832 
+<a name="l00833"></a>00833 
+<a name="l00834"></a>00834 <span class="keyword">static</span> <span class="keywordtype">void</span>
+<a name="l00835"></a>00835 sinfo_log_pro(<span class="keywordtype">char</span>* name_o, 
+<a name="l00836"></a>00836               <span class="keyword">const</span> <span class="keywordtype">char</span>* pro_catg, 
+<a name="l00837"></a>00837               <span class="keywordtype">int</span> frm_type, 
+<a name="l00838"></a>00838               cpl_frameset* ref_set,
+<a name="l00839"></a>00839               cpl_frameset** out_set,
+<a name="l00840"></a>00840               cpl_propertylist** plist,
+<a name="l00841"></a>00841               cpl_parameterlist* parlist, 
+<a name="l00842"></a>00842               <span class="keyword">const</span> <span class="keywordtype">char</span>* recid)
+<a name="l00843"></a>00843 {
+<a name="l00844"></a>00844   cpl_frame* product_frame = NULL ;
+<a name="l00845"></a>00845   <span class="keywordtype">char</span> * pipe_id=NULL;
+<a name="l00846"></a>00846   cpl_errorstate initial_errorstate = cpl_errorstate_get();
+<a name="l00847"></a>00847 
+<a name="l00848"></a>00848   pipe_id = cpl_calloc(FILE_NAME_SZ,<span class="keyword">sizeof</span>(<span class="keywordtype">char</span>));
+<a name="l00849"></a>00849   snprintf(pipe_id,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%s"</span>,<span class="stringliteral">"sinfo/"</span>,PACKAGE_VERSION);
+<a name="l00850"></a>00850   product_frame = cpl_frame_new() ;
+<a name="l00851"></a>00851   cpl_frame_set_filename(product_frame, name_o) ;
+<a name="l00852"></a>00852   cpl_frame_set_tag(product_frame, pro_catg) ;
+<a name="l00853"></a>00853   cpl_frame_set_type(product_frame, frm_type);
+<a name="l00854"></a>00854   cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT);
+<a name="l00855"></a>00855   cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL);
+<a name="l00856"></a>00856 
+<a name="l00857"></a>00857 <span class="preprocessor">#if defined CPL_VERSION_CODE && CPL_VERSION_CODE >= CPL_VERSION(4, 8, 0) </span>
+<a name="l00858"></a>00858 <span class="preprocessor"></span>  <span class="keywordflow">if</span>(cpl_dfs_setup_product_header(*plist,product_frame,ref_set,parlist,recid,
+<a name="l00859"></a>00859                   pipe_id,KEY_VALUE_HPRO_DID,NULL) != CPL_ERROR_NONE) {
+<a name="l00860"></a>00860     <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"Problem in the product DFS-compliance"</span>);
+<a name="l00861"></a>00861     <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>((<span class="keywordtype">char</span>* ) cpl_error_get_message());
+<a name="l00862"></a>00862     cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
+<a name="l00863"></a>00863     cpl_error_reset();
+<a name="l00864"></a>00864   }
+<a name="l00865"></a>00865 <span class="preprocessor">#else</span>
+<a name="l00866"></a>00866 <span class="preprocessor"></span>  <span class="keywordflow">if</span>(cpl_dfs_setup_product_header(*plist,product_frame,ref_set,parlist,recid,
+<a name="l00867"></a>00867                   pipe_id,KEY_VALUE_HPRO_DID) != CPL_ERROR_NONE) {
+<a name="l00868"></a>00868     <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"Problem in the product DFS-compliance"</span>);
+<a name="l00869"></a>00869     <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>((<span class="keywordtype">char</span>* ) cpl_error_get_message());
+<a name="l00870"></a>00870     cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
+<a name="l00871"></a>00871     cpl_error_reset();
+<a name="l00872"></a>00872   }
+<a name="l00873"></a>00873 <span class="preprocessor">#endif</span>
+<a name="l00874"></a>00874 <span class="preprocessor"></span>  cpl_frameset_insert(*out_set, product_frame);
+<a name="l00875"></a>00875   cpl_free(pipe_id);
+<a name="l00876"></a>00876 
+<a name="l00877"></a>00877 }
+<a name="l00878"></a>00878 
+<a name="l00879"></a>00879 <span class="keyword">static</span> <span class="keywordtype">void</span>
+<a name="l00880"></a>00880 sinfo_check_name(<span class="keyword">const</span> <span class="keywordtype">char</span>* in, <span class="keywordtype">char</span>** ou, <span class="keywordtype">int</span> type, <span class="keywordtype">char</span>** paf) {
+<a name="l00881"></a>00881 
+<a name="l00882"></a>00882   <span class="keywordtype">char</span>* tmp=NULL;
+<a name="l00883"></a>00883   <span class="keywordtype">char</span>  name_b[512] ;
+<a name="l00884"></a>00884   <span class="keywordflow">if</span> (strstr(in, <span class="stringliteral">"."</span> ) != NULL ) {
+<a name="l00885"></a>00885     tmp = sinfo_new_get_rootname(in);
+<a name="l00886"></a>00886     strcpy(name_b,tmp);
+<a name="l00887"></a>00887   } <span class="keywordflow">else</span> {
+<a name="l00888"></a>00888     snprintf(name_b, MAX_NAME_SIZE-1,in) ;
+<a name="l00889"></a>00889   }
+<a name="l00890"></a>00890   strcpy(*ou,name_b);
+<a name="l00891"></a>00891   <span class="keywordflow">if</span> (type == CPL_FRAME_TYPE_TABLE) {
+<a name="l00892"></a>00892     strcat(*ou,<span class="stringliteral">".fits"</span>);
+<a name="l00893"></a>00893   } <span class="keywordflow">else</span> {
+<a name="l00894"></a>00894     strcat(*ou,<span class="stringliteral">".fits"</span>);
+<a name="l00895"></a>00895   }
+<a name="l00896"></a>00896   strcpy(*paf,name_b);
+<a name="l00897"></a>00897   strcat(*paf,<span class="stringliteral">".paf"</span>);
+<a name="l00898"></a>00898 
+<a name="l00899"></a>00899 }
+<a name="l00900"></a>00900 
+<a name="l00901"></a>00901 
+<a name="l00902"></a>00902 <span class="keyword">static</span> <span class="keywordtype">void</span>
+<a name="l00903"></a>00903 sinfo_clean_header(cpl_propertylist** header)
+<a name="l00904"></a>00904 {
+<a name="l00905"></a>00905   cpl_propertylist_erase_regexp(*header, <span class="stringliteral">"^ESO PRO .*"</span>,0);
+<a name="l00906"></a>00906 
+<a name="l00907"></a>00907 }
+<a name="l00908"></a>00908 
+<a name="l00909"></a>00909 
+<a name="l00910"></a>00910 <span class="keyword">static</span> <span class="keywordtype">void</span>
+<a name="l00911"></a>00911 sinfo_clean_cube_header(cpl_propertylist** header)
+<a name="l00912"></a>00912 {
+<a name="l00913"></a>00913   cpl_propertylist_erase_regexp(*header, <span class="stringliteral">"^CRVAL*"</span>,0);
+<a name="l00914"></a>00914   cpl_propertylist_erase_regexp(*header, <span class="stringliteral">"^CRPIX*"</span>,0);
+<a name="l00915"></a>00915   cpl_propertylist_erase_regexp(*header, <span class="stringliteral">"^CTYPE*"</span>,0);
+<a name="l00916"></a>00916   cpl_propertylist_erase_regexp(*header, <span class="stringliteral">"^CUNIT*"</span>,0);
+<a name="l00917"></a>00917   cpl_propertylist_erase_regexp(*header, <span class="stringliteral">"^CD1_1"</span>,0);
+<a name="l00918"></a>00918   cpl_propertylist_erase_regexp(*header, <span class="stringliteral">"^CD1_2"</span>,0);
+<a name="l00919"></a>00919   cpl_propertylist_erase_regexp(*header, <span class="stringliteral">"^CD2_1"</span>,0);
+<a name="l00920"></a>00920   cpl_propertylist_erase_regexp(*header, <span class="stringliteral">"^CD2_2"</span>,0);
+<a name="l00921"></a>00921 
+<a name="l00922"></a>00922 }
+<a name="l00923"></a>00923 
+<a name="l00924"></a>00924 
+<a name="l00925"></a>00925 
+<a name="l00926"></a>00926 
+<a name="l00927"></a>00927 
+<a name="l00928"></a>00928 
+<a name="l00929"></a>00929 <span class="keyword">static</span> <span class="keywordtype">int</span> 
+<a name="l00930"></a>00930 sinfo_pfits_put_qc(
+<a name="l00931"></a>00931            cpl_propertylist       *   plist,
+<a name="l00932"></a>00932            cpl_table          *   qclog)
+<a name="l00933"></a>00933 {
+<a name="l00934"></a>00934   <span class="keywordtype">char</span>            key_name[FILE_NAME_SZ];
+<a name="l00935"></a>00935   <span class="keywordtype">char</span>            key_value[FILE_NAME_SZ];
+<a name="l00936"></a>00936   <span class="keywordtype">char</span>            key_type[FILE_NAME_SZ];
+<a name="l00937"></a>00937   <span class="keywordtype">char</span>            key_help[FILE_NAME_SZ] ;
+<a name="l00938"></a>00938 
+<a name="l00939"></a>00939   <span class="keywordtype">int</span>             i =0;
+<a name="l00940"></a>00940   <span class="keywordtype">int</span> n =0;
+<a name="l00941"></a>00941   <span class="comment">/* Test entries */</span>
+<a name="l00942"></a>00942   <span class="keywordflow">if</span> (plist == NULL) {
+<a name="l00943"></a>00943     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"plist=NULL, something strange"</span>);
+<a name="l00944"></a>00944     <span class="keywordflow">return</span> -1 ;
+<a name="l00945"></a>00945   }
+<a name="l00946"></a>00946   <span class="comment">/* Parameter Name:    PIPEFILE */</span>
+<a name="l00947"></a>00947 
+<a name="l00948"></a>00948   n=cpl_table_get_nrow(qclog);
+<a name="l00949"></a>00949   <span class="keywordflow">for</span>(i=0;i<n;i++) {
+<a name="l00950"></a>00950     strcpy(key_name,<span class="stringliteral">"ESO "</span>);
+<a name="l00951"></a>00951     strcat(key_name,cpl_table_get_string(qclog,<span class="stringliteral">"key_name"</span>,i));
+<a name="l00952"></a>00952     strcpy(key_type,cpl_table_get_string(qclog,<span class="stringliteral">"key_type"</span>,i));
+<a name="l00953"></a>00953     strcpy(key_value,cpl_table_get_string(qclog,<span class="stringliteral">"key_value"</span>,i));
+<a name="l00954"></a>00954     strcpy(key_help,cpl_table_get_string(qclog,<span class="stringliteral">"key_help"</span>,i));
+<a name="l00955"></a>00955 
+<a name="l00956"></a>00956     <span class="comment">/* sinfo_msg("name=%s type=%s value=%s\n",key_name,key_type,key_value); */</span>
+<a name="l00957"></a>00957     <span class="keywordflow">if</span>(!sinfo_propertylist_has(plist,key_name)) {
+<a name="l00958"></a>00958       <span class="keywordflow">if</span>(strcmp(key_type,<span class="stringliteral">"CPL_TYPE_STRING"</span>) == 0) {
+<a name="l00959"></a>00959     cpl_propertylist_append_string(plist, key_name,key_value) ;
+<a name="l00960"></a>00960     cpl_propertylist_set_comment(plist, key_name,key_help) ;
+<a name="l00961"></a>00961       } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(strcmp(key_type,<span class="stringliteral">"CPL_TYPE_BOOL"</span>) == 0) {
+<a name="l00962"></a>00962     cpl_propertylist_append_bool(plist, key_name,atoi(key_value)) ;
+<a name="l00963"></a>00963     cpl_propertylist_set_comment(plist, key_name,key_help) ;
+<a name="l00964"></a>00964       } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(strcmp(key_type,<span class="stringliteral">"CPL_TYPE_INT"</span>) == 0) {
+<a name="l00965"></a>00965     cpl_propertylist_append_int(plist,key_name,atoi(key_value)) ;
+<a name="l00966"></a>00966     cpl_propertylist_set_comment(plist, key_name,key_help) ;
+<a name="l00967"></a>00967       } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(strcmp(key_type,<span class="stringliteral">"CPL_TYPE_FLOAT"</span>) == 0) {
+<a name="l00968"></a>00968         cpl_propertylist_append_float(plist, key_name,(<span class="keywordtype">float</span>)atof(key_value)) ;
+<a name="l00969"></a>00969         cpl_propertylist_set_comment(plist, key_name,key_help) ;
+<a name="l00970"></a>00970       } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(strcmp(key_type,<span class="stringliteral">"CPL_TYPE_DOUBLE"</span>) == 0) {
+<a name="l00971"></a>00971         cpl_propertylist_append_double(plist, key_name,atof(key_value)) ;
+<a name="l00972"></a>00972         cpl_propertylist_set_comment(plist, key_name,key_help) ;
+<a name="l00973"></a>00973       }
+<a name="l00974"></a>00974     }
+<a name="l00975"></a>00975 
+<a name="l00976"></a>00976   }
+<a name="l00977"></a>00977 
+<a name="l00978"></a>00978   <span class="keywordflow">return</span> 0 ;
+<a name="l00979"></a>00979 }
+<a name="l00980"></a>00980 
+<a name="l00981"></a>00981 
+<a name="l00982"></a>00982 
+<a name="l00983"></a>00983 
+<a name="l00984"></a>00984 
+<a name="l00985"></a>00985 
+<a name="l00986"></a>00986 
+<a name="l00987"></a>00987 cpl_table *
+<a name="l00988"></a>00988 sinfo_qclog_init(<span class="keywordtype">void</span>)
+<a name="l00989"></a>00989 {
+<a name="l00990"></a>00990 
+<a name="l00991"></a>00991   cpl_table *table;
+<a name="l00992"></a>00992 
+<a name="l00993"></a>00993   table = cpl_table_new(0);
+<a name="l00994"></a>00994   cpl_table_new_column(table,<span class="stringliteral">"key_name"</span>, CPL_TYPE_STRING);
+<a name="l00995"></a>00995   cpl_table_new_column(table,<span class="stringliteral">"key_type"</span>, CPL_TYPE_STRING);
+<a name="l00996"></a>00996   cpl_table_new_column(table,<span class="stringliteral">"key_value"</span>, CPL_TYPE_STRING);
+<a name="l00997"></a>00997   cpl_table_new_column(table,<span class="stringliteral">"key_help"</span>, CPL_TYPE_STRING);
+<a name="l00998"></a>00998 
+<a name="l00999"></a>00999   <span class="keywordflow">return</span> table;
+<a name="l01000"></a>01000 }
+<a name="l01001"></a>01001 
+<a name="l01002"></a>01002 
+<a name="l01003"></a>01003 
+<a name="l01004"></a>01004 
+<a name="l01005"></a>01005 
+<a name="l01006"></a>01006 <span class="keywordtype">int</span>
+<a name="l01007"></a>01007 sinfo_qclog_add_int(cpl_table* table,
+<a name="l01008"></a>01008             <span class="keyword">const</span> <span class="keywordtype">char</span>*  key_name,  
+<a name="l01009"></a>01009             <span class="keyword">const</span> <span class="keywordtype">int</span>    value,
+<a name="l01010"></a>01010             <span class="keyword">const</span> <span class="keywordtype">char</span>*  key_help,
+<a name="l01011"></a>01011             <span class="keyword">const</span> <span class="keywordtype">char</span>*  format)
+<a name="l01012"></a>01012 {
+<a name="l01013"></a>01013   <span class="keywordtype">int</span> sz = cpl_table_get_nrow(table);
+<a name="l01014"></a>01014   <span class="keywordtype">int</span> raw = sz;
+<a name="l01015"></a>01015   <span class="keywordtype">char</span> key_value[FILE_NAME_SZ];
+<a name="l01016"></a>01016   <span class="keywordtype">char</span> key_type[FILE_NAME_SZ];
+<a name="l01017"></a>01017 
+<a name="l01018"></a>01018   snprintf(key_value,MAX_NAME_SIZE-1,format,value);
+<a name="l01019"></a>01019   strcpy(key_type,<span class="stringliteral">"CPL_TYPE_INT"</span>); 
+<a name="l01020"></a>01020  
+<a name="l01021"></a>01021   cpl_table_set_size(table,sz+1);
+<a name="l01022"></a>01022 
+<a name="l01023"></a>01023   cpl_table_set_string(table,<span class="stringliteral">"key_name"</span> ,raw,key_name);
+<a name="l01024"></a>01024   cpl_table_set_string(table,<span class="stringliteral">"key_type"</span> ,raw,key_type);
+<a name="l01025"></a>01025   cpl_table_set_string(table,<span class="stringliteral">"key_value"</span>,raw,key_value);
+<a name="l01026"></a>01026   cpl_table_set_string(table,<span class="stringliteral">"key_help"</span> ,raw,key_help);
+<a name="l01027"></a>01027 
+<a name="l01028"></a>01028   <span class="keywordflow">return</span> 0;
+<a name="l01029"></a>01029 
+<a name="l01030"></a>01030 }
+<a name="l01031"></a>01031 
+<a name="l01032"></a>01032 
+<a name="l01033"></a>01033 
+<a name="l01034"></a>01034 <span class="keywordtype">int</span>
+<a name="l01035"></a>01035 sinfo_qclog_add_bool(cpl_table* table,
+<a name="l01036"></a>01036              <span class="keyword">const</span> <span class="keywordtype">char</span>*  key_name,  
+<a name="l01037"></a>01037              <span class="keyword">const</span> <span class="keywordtype">char</span>   value,
+<a name="l01038"></a>01038              <span class="keyword">const</span> <span class="keywordtype">char</span>*  key_help,
+<a name="l01039"></a>01039              <span class="keyword">const</span> <span class="keywordtype">char</span>*  format)
+<a name="l01040"></a>01040 {
+<a name="l01041"></a>01041   <span class="keywordtype">int</span> sz = cpl_table_get_nrow(table);
+<a name="l01042"></a>01042   <span class="keywordtype">int</span> raw = sz;
+<a name="l01043"></a>01043   <span class="keywordtype">char</span> key_value[FILE_NAME_SZ];
+<a name="l01044"></a>01044   <span class="keywordtype">char</span> key_type[FILE_NAME_SZ];
+<a name="l01045"></a>01045 
+<a name="l01046"></a>01046   snprintf(key_value,MAX_NAME_SIZE-1,format,value);
+<a name="l01047"></a>01047   strcpy(key_type,<span class="stringliteral">"CPL_TYPE_BOOL"</span>); 
+<a name="l01048"></a>01048 
+<a name="l01049"></a>01049   cpl_table_set_size(table,sz+1);
+<a name="l01050"></a>01050 
+<a name="l01051"></a>01051   cpl_table_set_string(table,<span class="stringliteral">"key_name"</span> ,raw,key_name);
+<a name="l01052"></a>01052   cpl_table_set_string(table,<span class="stringliteral">"key_type"</span> ,raw,key_type);
+<a name="l01053"></a>01053   cpl_table_set_string(table,<span class="stringliteral">"key_value"</span>,raw,key_value);
+<a name="l01054"></a>01054   cpl_table_set_string(table,<span class="stringliteral">"key_help"</span> ,raw,key_help);
+<a name="l01055"></a>01055 
+<a name="l01056"></a>01056   <span class="keywordflow">return</span> 0;
+<a name="l01057"></a>01057 
+<a name="l01058"></a>01058 }
+<a name="l01059"></a>01059 
+<a name="l01060"></a>01060 
+<a name="l01061"></a>01061 
+<a name="l01062"></a>01062 <span class="keywordtype">int</span>
+<a name="l01063"></a>01063 sinfo_qclog_add_float(cpl_table* table,
+<a name="l01064"></a>01064               <span class="keyword">const</span> <span class="keywordtype">char</span>*  key_name,  
+<a name="l01065"></a>01065               <span class="keyword">const</span> <span class="keywordtype">float</span>  value,
+<a name="l01066"></a>01066               <span class="keyword">const</span> <span class="keywordtype">char</span>*  key_help,
+<a name="l01067"></a>01067               <span class="keyword">const</span> <span class="keywordtype">char</span>*  format)
+<a name="l01068"></a>01068 {
+<a name="l01069"></a>01069   <span class="keywordtype">int</span> sz = cpl_table_get_nrow(table);
+<a name="l01070"></a>01070   <span class="keywordtype">int</span> raw = sz;
+<a name="l01071"></a>01071   <span class="keywordtype">char</span> key_value[FILE_NAME_SZ];
+<a name="l01072"></a>01072   <span class="keywordtype">char</span> key_type[FILE_NAME_SZ];
+<a name="l01073"></a>01073 
+<a name="l01074"></a>01074   snprintf(key_value,MAX_NAME_SIZE-1,format,value);
+<a name="l01075"></a>01075   strcpy(key_type,<span class="stringliteral">"CPL_TYPE_FLOAT"</span>); 
+<a name="l01076"></a>01076  
+<a name="l01077"></a>01077   cpl_table_set_size(table,sz+1);
+<a name="l01078"></a>01078 
+<a name="l01079"></a>01079   cpl_table_set_string(table,<span class="stringliteral">"key_name"</span> ,raw,key_name);
+<a name="l01080"></a>01080   cpl_table_set_string(table,<span class="stringliteral">"key_type"</span> ,raw,key_type);
+<a name="l01081"></a>01081   cpl_table_set_string(table,<span class="stringliteral">"key_value"</span>,raw,key_value);
+<a name="l01082"></a>01082   cpl_table_set_string(table,<span class="stringliteral">"key_help"</span> ,raw,key_help);
+<a name="l01083"></a>01083 
+<a name="l01084"></a>01084   <span class="keywordflow">return</span> 0;
+<a name="l01085"></a>01085 
+<a name="l01086"></a>01086 }
+<a name="l01087"></a>01087 
+<a name="l01088"></a>01088 
+<a name="l01089"></a>01089 
+<a name="l01090"></a>01090 <span class="keywordtype">int</span>
+<a name="l01091"></a>01091 sinfo_qclog_add_double(cpl_table* table,
+<a name="l01092"></a>01092                <span class="keyword">const</span> <span class="keywordtype">char</span>*  key_name,  
+<a name="l01093"></a>01093                <span class="keyword">const</span> <span class="keywordtype">double</span> value,
+<a name="l01094"></a>01094                <span class="keyword">const</span> <span class="keywordtype">char</span>*  key_help,
+<a name="l01095"></a>01095                <span class="keyword">const</span> <span class="keywordtype">char</span>*  format)
+<a name="l01096"></a>01096 {
+<a name="l01097"></a>01097   <span class="keywordtype">int</span> sz = cpl_table_get_nrow(table);
+<a name="l01098"></a>01098   <span class="keywordtype">int</span> raw = sz;
+<a name="l01099"></a>01099   <span class="keywordtype">char</span> key_value[FILE_NAME_SZ];
+<a name="l01100"></a>01100   <span class="keywordtype">char</span> key_type[FILE_NAME_SZ];
+<a name="l01101"></a>01101 
+<a name="l01102"></a>01102   snprintf(key_value,MAX_NAME_SIZE-1,format,value);
+<a name="l01103"></a>01103   strcpy(key_type,<span class="stringliteral">"CPL_TYPE_DOUBLE"</span>); 
+<a name="l01104"></a>01104  
+<a name="l01105"></a>01105   cpl_table_set_size(table,sz+1);
+<a name="l01106"></a>01106 
+<a name="l01107"></a>01107   cpl_table_set_string(table,<span class="stringliteral">"key_name"</span> ,raw,key_name);
+<a name="l01108"></a>01108   cpl_table_set_string(table,<span class="stringliteral">"key_type"</span> ,raw,key_type);
+<a name="l01109"></a>01109   cpl_table_set_string(table,<span class="stringliteral">"key_value"</span>,raw,key_value);
+<a name="l01110"></a>01110   cpl_table_set_string(table,<span class="stringliteral">"key_help"</span> ,raw,key_help);
+<a name="l01111"></a>01111 
+<a name="l01112"></a>01112   <span class="keywordflow">return</span> 0;
+<a name="l01113"></a>01113 
+<a name="l01114"></a>01114 }
+<a name="l01115"></a>01115 
+<a name="l01116"></a>01116 <span class="keywordtype">int</span>
+<a name="l01117"></a>01117 sinfo_qclog_add_string(cpl_table* table,
+<a name="l01118"></a>01118                <span class="keyword">const</span> <span class="keywordtype">char</span>*  key_name,  
+<a name="l01119"></a>01119                <span class="keyword">const</span> <span class="keywordtype">char</span>*  value,
+<a name="l01120"></a>01120                <span class="keyword">const</span> <span class="keywordtype">char</span>*  key_help,
+<a name="l01121"></a>01121                <span class="keyword">const</span> <span class="keywordtype">char</span>*  format)
+<a name="l01122"></a>01122 {
+<a name="l01123"></a>01123   <span class="keywordtype">int</span> sz = cpl_table_get_nrow(table);
+<a name="l01124"></a>01124   <span class="keywordtype">int</span> raw = sz;
+<a name="l01125"></a>01125   <span class="keywordtype">char</span> key_value[FILE_NAME_SZ];
+<a name="l01126"></a>01126   <span class="keywordtype">char</span> key_type[FILE_NAME_SZ];
+<a name="l01127"></a>01127 
+<a name="l01128"></a>01128   snprintf(key_value,MAX_NAME_SIZE-1,format,value);
+<a name="l01129"></a>01129   strcpy(key_type,<span class="stringliteral">"CPL_TYPE_STRING"</span>); 
+<a name="l01130"></a>01130  
+<a name="l01131"></a>01131   cpl_table_set_size(table,sz+1);
+<a name="l01132"></a>01132 
+<a name="l01133"></a>01133   cpl_table_set_string(table,<span class="stringliteral">"key_name"</span> ,raw,key_name);
+<a name="l01134"></a>01134   cpl_table_set_string(table,<span class="stringliteral">"key_type"</span> ,raw,key_type);
+<a name="l01135"></a>01135   cpl_table_set_string(table,<span class="stringliteral">"key_value"</span>,raw,key_value);
+<a name="l01136"></a>01136   cpl_table_set_string(table,<span class="stringliteral">"key_help"</span> ,raw,key_help);
+<a name="l01137"></a>01137 
+<a name="l01138"></a>01138   <span class="keywordflow">return</span> 0;
+<a name="l01139"></a>01139 
+<a name="l01140"></a>01140 }
+<a name="l01141"></a>01141 
+<a name="l01142"></a>01142 
+<a name="l01143"></a>01143 
+<a name="l01144"></a>01144 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__pro__save_8h_source.html b/html/sinfo__pro__save_8h_source.html
new file mode 100644
index 0000000..05903f6
--- /dev/null
+++ b/html/sinfo__pro__save_8h_source.html
@@ -0,0 +1,228 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_pro_save.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_pro_save.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#ifndef SINFO_PRO_SAVE_H</span>
+<a name="l00002"></a>00002 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_PRO_SAVE_H</span>
+<a name="l00003"></a>00003 <span class="preprocessor"></span>
+<a name="l00004"></a>00004 <span class="comment">/*</span>
+<a name="l00005"></a>00005 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00006"></a>00006 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00007"></a>00007 <span class="comment"> *</span>
+<a name="l00008"></a>00008 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00009"></a>00009 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00010"></a>00010 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00011"></a>00011 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00012"></a>00012 <span class="comment"> *</span>
+<a name="l00013"></a>00013 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00014"></a>00014 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00015"></a>00015 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00016"></a>00016 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00017"></a>00017 <span class="comment"> *</span>
+<a name="l00018"></a>00018 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00019"></a>00019 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00020"></a>00020 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00021"></a>00021 <span class="comment"> */</span>
+<a name="l00022"></a>00022 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00023"></a>00023 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>
+<a name="l00024"></a>00024 <span class="preprocessor">#endif</span>
+<a name="l00025"></a>00025 <span class="preprocessor"></span>
+<a name="l00026"></a>00026 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00027"></a>00027 <span class="preprocessor">#include "sinfo_pfits.h"</span>
+<a name="l00028"></a>00028 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00036"></a>00036 <span class="keywordtype">int</span> 
+<a name="l00037"></a>00037 sinfo_update_fits_card_int(<span class="keyword">const</span> <span class="keywordtype">char</span>* file,<span class="keyword">const</span> <span class="keywordtype">char</span>* card,<span class="keywordtype">int</span> value);
+<a name="l00038"></a>00038 
+<a name="l00046"></a>00046 <span class="keywordtype">int</span> 
+<a name="l00047"></a>00047 sinfo_update_fits_card_float(<span class="keyword">const</span> <span class="keywordtype">char</span>* file,<span class="keyword">const</span> <span class="keywordtype">char</span>* card,<span class="keywordtype">float</span> value);
+<a name="l00048"></a>00048 
+<a name="l00056"></a>00056 <span class="keywordtype">int</span> 
+<a name="l00057"></a>00057 sinfo_update_fits_card_double(<span class="keyword">const</span> <span class="keywordtype">char</span>* file,<span class="keyword">const</span> <span class="keywordtype">char</span>* card,<span class="keywordtype">double</span> value);
+<a name="l00058"></a>00058 
+<a name="l00059"></a>00059 
+<a name="l00067"></a>00067 <span class="keywordtype">int</span> 
+<a name="l00068"></a>00068 sinfo_update_fits_card_long(<span class="keyword">const</span> <span class="keywordtype">char</span>* file,<span class="keyword">const</span> <span class="keywordtype">char</span>* card,<span class="keywordtype">long</span> value);
+<a name="l00069"></a>00069 
+<a name="l00077"></a>00077 <span class="keywordtype">int</span> sinfo_update_ims_fits_card_string(cpl_imagelist* iml, 
+<a name="l00078"></a>00078                                       <span class="keyword">const</span> <span class="keywordtype">char</span>* file,
+<a name="l00079"></a>00079                                       <span class="keyword">const</span> <span class="keywordtype">char</span>* card,
+<a name="l00080"></a>00080                                       <span class="keyword">const</span> <span class="keywordtype">char</span>* value);
+<a name="l00081"></a>00081 
+<a name="l00082"></a>00082 
+<a name="l00096"></a>00096 <span class="keywordtype">int</span>
+<a name="l00097"></a>00097 sinfo_pro_save_tbl(
+<a name="l00098"></a>00098     cpl_table* tbl,
+<a name="l00099"></a>00099         cpl_frameset* ref,
+<a name="l00100"></a>00100         cpl_frameset* sof,
+<a name="l00101"></a>00101         <span class="keyword">const</span> <span class="keywordtype">char</span>* name, 
+<a name="l00102"></a>00102         <span class="keyword">const</span> <span class="keywordtype">char</span>* proid, 
+<a name="l00103"></a>00103         cpl_table* qclog,
+<a name="l00104"></a>00104         <span class="keyword">const</span> <span class="keywordtype">char</span>* recid,
+<a name="l00105"></a>00105         cpl_parameterlist* parlist);
+<a name="l00106"></a>00106 
+<a name="l00107"></a>00107 
+<a name="l00122"></a>00122 <span class="keywordtype">int</span>
+<a name="l00123"></a>00123 sinfo_pro_save_ima(
+<a name="l00124"></a>00124         cpl_image* ima,
+<a name="l00125"></a>00125         cpl_frameset* ref,
+<a name="l00126"></a>00126         cpl_frameset* sof,
+<a name="l00127"></a>00127         <span class="keyword">const</span> <span class="keywordtype">char</span>* name, 
+<a name="l00128"></a>00128         <span class="keyword">const</span> <span class="keywordtype">char</span>* proid, 
+<a name="l00129"></a>00129         cpl_table* qclog,
+<a name="l00130"></a>00130         <span class="keyword">const</span> <span class="keywordtype">char</span>* recid,
+<a name="l00131"></a>00131         cpl_parameterlist* parlist);
+<a name="l00132"></a>00132 
+<a name="l00146"></a>00146 <span class="keywordtype">int</span>
+<a name="l00147"></a>00147 sinfo_pro_save_ims(
+<a name="l00148"></a>00148         cpl_imagelist* ims,
+<a name="l00149"></a>00149         cpl_frameset* ref,
+<a name="l00150"></a>00150         cpl_frameset* sof,
+<a name="l00151"></a>00151         <span class="keyword">const</span> <span class="keywordtype">char</span>* name, 
+<a name="l00152"></a>00152         <span class="keyword">const</span> <span class="keywordtype">char</span>* proid, 
+<a name="l00153"></a>00153         cpl_table* qclog,
+<a name="l00154"></a>00154         <span class="keyword">const</span> <span class="keywordtype">char</span>* recid,
+<a name="l00155"></a>00155         cpl_parameterlist* parlist);
+<a name="l00156"></a>00156 
+<a name="l00157"></a>00157 
+<a name="l00158"></a>00158 
+<a name="l00159"></a>00159 
+<a name="l00160"></a>00160 
+<a name="l00161"></a>00161 
+<a name="l00162"></a>00162 
+<a name="l00176"></a>00176 <span class="keywordtype">int</span>
+<a name="l00177"></a>00177 sinfo_save_pro_tbl(
+<a name="l00178"></a>00178     cpl_table* tbl,
+<a name="l00179"></a>00179         cpl_frameset* ref,
+<a name="l00180"></a>00180         cpl_frameset* sof,
+<a name="l00181"></a>00181         <span class="keyword">const</span> <span class="keywordtype">char</span>* name, 
+<a name="l00182"></a>00182         <span class="keyword">const</span> <span class="keywordtype">char</span>* proid, 
+<a name="l00183"></a>00183         cpl_propertylist* qclog,
+<a name="l00184"></a>00184         <span class="keyword">const</span> <span class="keywordtype">char</span>* recid,
+<a name="l00185"></a>00185         cpl_parameterlist* parlist);
+<a name="l00186"></a>00186 
+<a name="l00187"></a>00187 
+<a name="l00202"></a>00202 <span class="keywordtype">int</span>
+<a name="l00203"></a>00203 sinfo_save_pro_ima(
+<a name="l00204"></a>00204         cpl_image* ima,
+<a name="l00205"></a>00205         cpl_frameset* ref,
+<a name="l00206"></a>00206         cpl_frameset* sof,
+<a name="l00207"></a>00207         <span class="keyword">const</span> <span class="keywordtype">char</span>* name, 
+<a name="l00208"></a>00208         <span class="keyword">const</span> <span class="keywordtype">char</span>* proid, 
+<a name="l00209"></a>00209         cpl_propertylist* qclog,
+<a name="l00210"></a>00210         <span class="keyword">const</span> <span class="keywordtype">char</span>* recid,
+<a name="l00211"></a>00211         cpl_parameterlist* parlist);
+<a name="l00212"></a>00212 
+<a name="l00226"></a>00226 <span class="keywordtype">int</span>
+<a name="l00227"></a>00227 sinfo_save_pro_ims(
+<a name="l00228"></a>00228         cpl_imagelist* ims,
+<a name="l00229"></a>00229         cpl_frameset* ref,
+<a name="l00230"></a>00230         cpl_frameset* sof,
+<a name="l00231"></a>00231         <span class="keyword">const</span> <span class="keywordtype">char</span>* name, 
+<a name="l00232"></a>00232         <span class="keyword">const</span> <span class="keywordtype">char</span>* proid, 
+<a name="l00233"></a>00233         cpl_propertylist* qclog,
+<a name="l00234"></a>00234         <span class="keyword">const</span> <span class="keywordtype">char</span>* recid,
+<a name="l00235"></a>00235         cpl_parameterlist* parlist);
+<a name="l00236"></a>00236 
+<a name="l00237"></a>00237 
+<a name="l00238"></a>00238 
+<a name="l00239"></a>00239 
+<a name="l00240"></a>00240 
+<a name="l00241"></a>00241 cpl_table* sinfo_qclog_init(<span class="keywordtype">void</span>);
+<a name="l00242"></a>00242 
+<a name="l00243"></a>00243 <span class="keywordtype">int</span>
+<a name="l00244"></a>00244 sinfo_qclog_add_int(cpl_table* table,
+<a name="l00245"></a>00245                  <span class="keyword">const</span> <span class="keywordtype">char</span>* name,  
+<a name="l00246"></a>00246                  <span class="keyword">const</span> <span class="keywordtype">int</span>   value,
+<a name="l00247"></a>00247                  <span class="keyword">const</span> <span class="keywordtype">char</span>* help,
+<a name="l00248"></a>00248          <span class="keyword">const</span> <span class="keywordtype">char</span>* format);
+<a name="l00249"></a>00249 
+<a name="l00250"></a>00250 
+<a name="l00251"></a>00251 <span class="keywordtype">int</span>
+<a name="l00252"></a>00252 sinfo_qclog_add_bool(cpl_table* table,
+<a name="l00253"></a>00253                  <span class="keyword">const</span> <span class="keywordtype">char</span>* name,  
+<a name="l00254"></a>00254                  <span class="keyword">const</span> <span class="keywordtype">char</span>  value,
+<a name="l00255"></a>00255                  <span class="keyword">const</span> <span class="keywordtype">char</span>* help,
+<a name="l00256"></a>00256          <span class="keyword">const</span> <span class="keywordtype">char</span>* format);
+<a name="l00257"></a>00257 
+<a name="l00258"></a>00258 
+<a name="l00259"></a>00259 <span class="keywordtype">int</span>
+<a name="l00260"></a>00260 sinfo_qclog_add_float(cpl_table* table,
+<a name="l00261"></a>00261                  <span class="keyword">const</span> <span class="keywordtype">char</span>* name,  
+<a name="l00262"></a>00262                  <span class="keyword">const</span> <span class="keywordtype">float</span>   value,
+<a name="l00263"></a>00263                  <span class="keyword">const</span> <span class="keywordtype">char</span>* help,
+<a name="l00264"></a>00264          <span class="keyword">const</span> <span class="keywordtype">char</span>* format);
+<a name="l00265"></a>00265 
+<a name="l00266"></a>00266 
+<a name="l00267"></a>00267 <span class="keywordtype">int</span>
+<a name="l00268"></a>00268 sinfo_qclog_add_double(cpl_table* table,
+<a name="l00269"></a>00269                  <span class="keyword">const</span> <span class="keywordtype">char</span>* name,  
+<a name="l00270"></a>00270                  <span class="keyword">const</span> <span class="keywordtype">double</span>   value,
+<a name="l00271"></a>00271                  <span class="keyword">const</span> <span class="keywordtype">char</span>* help,
+<a name="l00272"></a>00272          <span class="keyword">const</span> <span class="keywordtype">char</span>* format);
+<a name="l00273"></a>00273 
+<a name="l00274"></a>00274 
+<a name="l00275"></a>00275 <span class="keywordtype">int</span>
+<a name="l00276"></a>00276 sinfo_qclog_add_string(cpl_table* table,
+<a name="l00277"></a>00277                  <span class="keyword">const</span> <span class="keywordtype">char</span>* name,  
+<a name="l00278"></a>00278                  <span class="keyword">const</span> <span class="keywordtype">char</span>*   value,
+<a name="l00279"></a>00279                  <span class="keyword">const</span> <span class="keywordtype">char</span>* help,
+<a name="l00280"></a>00280          <span class="keyword">const</span> <span class="keywordtype">char</span>* format);
+<a name="l00281"></a>00281 
+<a name="l00282"></a>00282 
+<a name="l00283"></a>00283 
+<a name="l00284"></a>00284 cpl_propertylist* sinfo_qc_init(<span class="keywordtype">void</span>);
+<a name="l00285"></a>00285 
+<a name="l00286"></a>00286 <span class="keywordtype">int</span>
+<a name="l00287"></a>00287 sinfo_qc_add_int(cpl_propertylist* table,
+<a name="l00288"></a>00288                  <span class="keyword">const</span> <span class="keywordtype">char</span>* name,  
+<a name="l00289"></a>00289                  <span class="keyword">const</span> <span class="keywordtype">int</span>   value,
+<a name="l00290"></a>00290                  <span class="keyword">const</span> <span class="keywordtype">char</span>* help,
+<a name="l00291"></a>00291          <span class="keyword">const</span> <span class="keywordtype">char</span>* format);
+<a name="l00292"></a>00292 
+<a name="l00293"></a>00293 
+<a name="l00294"></a>00294 <span class="keywordtype">int</span>
+<a name="l00295"></a>00295 sinfo_qc_add_bool(cpl_propertylist* table,
+<a name="l00296"></a>00296                  <span class="keyword">const</span> <span class="keywordtype">char</span>* name,  
+<a name="l00297"></a>00297                  <span class="keyword">const</span> <span class="keywordtype">char</span>  value,
+<a name="l00298"></a>00298                  <span class="keyword">const</span> <span class="keywordtype">char</span>* help,
+<a name="l00299"></a>00299          <span class="keyword">const</span> <span class="keywordtype">char</span>* format);
+<a name="l00300"></a>00300 
+<a name="l00301"></a>00301 
+<a name="l00302"></a>00302 <span class="keywordtype">int</span>
+<a name="l00303"></a>00303 sinfo_qc_add_float(cpl_propertylist* table,
+<a name="l00304"></a>00304                  <span class="keyword">const</span> <span class="keywordtype">char</span>* name,  
+<a name="l00305"></a>00305                  <span class="keyword">const</span> <span class="keywordtype">float</span>   value,
+<a name="l00306"></a>00306                  <span class="keyword">const</span> <span class="keywordtype">char</span>* help,
+<a name="l00307"></a>00307          <span class="keyword">const</span> <span class="keywordtype">char</span>* format);
+<a name="l00308"></a>00308 
+<a name="l00309"></a>00309 
+<a name="l00310"></a>00310 <span class="keywordtype">int</span>
+<a name="l00311"></a>00311 sinfo_qc_add_double(cpl_propertylist* table,
+<a name="l00312"></a>00312                  <span class="keyword">const</span> <span class="keywordtype">char</span>* name,  
+<a name="l00313"></a>00313                  <span class="keyword">const</span> <span class="keywordtype">double</span>   value,
+<a name="l00314"></a>00314                  <span class="keyword">const</span> <span class="keywordtype">char</span>* help,
+<a name="l00315"></a>00315          <span class="keyword">const</span> <span class="keywordtype">char</span>* format);
+<a name="l00316"></a>00316 
+<a name="l00317"></a>00317 
+<a name="l00318"></a>00318 <span class="keywordtype">int</span>
+<a name="l00319"></a>00319 sinfo_qc_add_string(cpl_propertylist* table,
+<a name="l00320"></a>00320                  <span class="keyword">const</span> <span class="keywordtype">char</span>* name,  
+<a name="l00321"></a>00321                  <span class="keyword">const</span> <span class="keywordtype">char</span>*   value,
+<a name="l00322"></a>00322                  <span class="keyword">const</span> <span class="keywordtype">char</span>* help,
+<a name="l00323"></a>00323          <span class="keyword">const</span> <span class="keywordtype">char</span>* format);
+<a name="l00324"></a>00324 
+<a name="l00325"></a>00325 
+<a name="l00326"></a>00326 
+<a name="l00327"></a>00327 <span class="preprocessor">#endif </span><span class="comment">/* SINFO_PRO_SAVE */</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__pro__types_8h_source.html b/html/sinfo__pro__types_8h_source.html
new file mode 100644
index 0000000..7ba4a33
--- /dev/null
+++ b/html/sinfo__pro__types_8h_source.html
@@ -0,0 +1,207 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_pro_types.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_pro_types.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_pro_types.h,v 1.10 2010/02/12 17:57:38 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the SINFONI Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This proram is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later verrtd sion.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2010/02/12 17:57:38 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.10 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifndef SINFO_PRO_TYPES_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_PRO_TYPES_H</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span>
+<a name="l00031"></a>00031 CPL_BEGIN_DECLS
+<a name="l00032"></a>00032 
+<a name="l00033"></a>00033 <span class="preprocessor">#define PRO_LIN_DET_INFO                   "LIN_DET_INFO"</span>
+<a name="l00034"></a>00034 <span class="preprocessor"></span><span class="preprocessor">#define PRO_GAIN_INFO                      "GAIN_INFO"</span>
+<a name="l00035"></a>00035 <span class="preprocessor"></span><span class="preprocessor">#define PRO_AO_INFO                        "AO_INFO"</span>
+<a name="l00036"></a>00036 <span class="preprocessor"></span><span class="preprocessor">#define PRO_AO_PERFORMANCE                 "AO_PERFORMANCE"</span>
+<a name="l00037"></a>00037 <span class="preprocessor"></span><span class="preprocessor">#define PRO_ENC_ENERGY                     "ENC_ENERGY"</span>
+<a name="l00038"></a>00038 <span class="preprocessor"></span><span class="preprocessor">#define PRO_OBS_SKY                        "OBS_SKY"</span>
+<a name="l00039"></a>00039 <span class="preprocessor"></span><span class="preprocessor">#define PRO_SKY_MED                        "SKY_MED"</span>
+<a name="l00040"></a>00040 <span class="preprocessor"></span><span class="preprocessor">#define PRO_SKY_DUMMY                      "SKY_DUMMY"</span>
+<a name="l00041"></a>00041 <span class="preprocessor"></span><span class="preprocessor">#define PRO_SKY_STACKED_DUMMY              "SKY_STACKED_DUMMY"</span>
+<a name="l00042"></a>00042 <span class="preprocessor"></span><span class="preprocessor">#define PRO_DEFAULT                        "DEFAULT"</span>
+<a name="l00043"></a>00043 <span class="preprocessor"></span><span class="preprocessor">#define PRO_INT_COL_TILT_COR               "INT_COL_TILT_COR"</span>
+<a name="l00044"></a>00044 <span class="preprocessor"></span><span class="preprocessor">#define PRO_STD_STACKED                    "STD_STACKED"</span>
+<a name="l00045"></a>00045 <span class="preprocessor"></span><span class="preprocessor">#define PRO_SKY_STD_STACKED                "SKY_STD_STACKED"</span>
+<a name="l00046"></a>00046 <span class="preprocessor"></span><span class="preprocessor">#define PRO_SKY_OH_STACKED                 "SKY_OH_STACKED"</span>
+<a name="l00047"></a>00047 <span class="preprocessor"></span><span class="preprocessor">#define PRO_SKY_PSF_CALIBRATOR_STACKED     "SKY_PSF_CALIBRATOR_STACKED"</span>
+<a name="l00048"></a>00048 <span class="preprocessor"></span><span class="preprocessor">#define PRO_STD_STAR_STACKED               "STD_STAR_STACKED"</span>
+<a name="l00049"></a>00049 <span class="preprocessor"></span><span class="preprocessor">#define PRO_STD_STAR_DITHER_STACKED        "STD_STAR_DITHER_STACKED"</span>
+<a name="l00050"></a>00050 <span class="preprocessor"></span><span class="preprocessor">#define PRO_SKY_STACKED                    "SKY_STACKED"</span>
+<a name="l00051"></a>00051 <span class="preprocessor"></span><span class="preprocessor">#define PRO_NODDING_STACKED                "_NODDING_STACKED"</span>
+<a name="l00052"></a>00052 <span class="preprocessor"></span><span class="preprocessor">#define PRO_ILLUMCORR                      "ILLUMCORR"</span>
+<a name="l00053"></a>00053 <span class="preprocessor"></span>
+<a name="l00054"></a>00054 <span class="preprocessor">#define SINFO_UTL_STDSTARS_RES             "STDSTARS_CATS"</span>
+<a name="l00055"></a>00055 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_UTL_SEDS_RES                 "SEDS"</span>
+<a name="l00056"></a>00056 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_CALIB_STDSTARS               "STDSTARS_CATS"</span>
+<a name="l00057"></a>00057 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_CALIB_SED                    "SEDS"</span>
+<a name="l00058"></a>00058 <span class="preprocessor"></span>
+<a name="l00059"></a>00059 <span class="preprocessor">#define PRO_STACKED                        "_STACKED"</span>
+<a name="l00060"></a>00060 <span class="preprocessor"></span>
+<a name="l00061"></a>00061 <span class="preprocessor">#define PRO_STACK_SKY_DIST                 "SKY_STACKED_DIST"</span>
+<a name="l00062"></a>00062 <span class="preprocessor"></span><span class="preprocessor">#define PRO_STACK_MFLAT_DIST               "MFLAT_STACKED_DIST"</span>
+<a name="l00063"></a>00063 <span class="preprocessor"></span><span class="preprocessor">#define PRO_STACK_MFLAT_DITHER_DIST        "MFLAT_DITHER_STACKED_DIST"</span>
+<a name="l00064"></a>00064 <span class="preprocessor"></span>
+<a name="l00065"></a>00065 <span class="preprocessor">#define PRO_MFLAT_CUBE                     "MFLAT_CUBE"</span>
+<a name="l00066"></a>00066 <span class="preprocessor"></span><span class="preprocessor">#define PRO_MFLAT_AVG                      "MFLAT_AVG"</span>
+<a name="l00067"></a>00067 <span class="preprocessor"></span><span class="preprocessor">#define PRO_MFLAT_MED                      "MFLAT_MED"</span>
+<a name="l00068"></a>00068 <span class="preprocessor"></span>
+<a name="l00069"></a>00069 
+<a name="l00070"></a>00070 <span class="preprocessor">#define PRO_ILL_COR                        "ILLUMINATION_CORRECTION"</span>
+<a name="l00071"></a>00071 <span class="preprocessor"></span><span class="preprocessor">#define PRO_BP_MAP                         "BP_MAP"</span>
+<a name="l00072"></a>00072 <span class="preprocessor"></span><span class="preprocessor">#define PRO_BP_MAP_HP                      "BP_MAP_HP"</span>
+<a name="l00073"></a>00073 <span class="preprocessor"></span><span class="preprocessor">#define PRO_BP_MAP_NL                      "BP_MAP_NL"</span>
+<a name="l00074"></a>00074 <span class="preprocessor"></span><span class="preprocessor">#define PRO_BP_MAP_NO                      "BP_MAP_NO"</span>
+<a name="l00075"></a>00075 <span class="preprocessor"></span><span class="preprocessor">#define PRO_BP_MAP_DI                      "BP_MAP_DI"</span>
+<a name="l00076"></a>00076 <span class="preprocessor"></span><span class="preprocessor">#define PRO_BP_MAP_SKY                     "BP_MAP_SKY"</span>
+<a name="l00077"></a>00077 <span class="preprocessor"></span><span class="preprocessor">#define PRO_MASTER_BP_MAP                  "MASTER_BP_MAP"</span>
+<a name="l00078"></a>00078 <span class="preprocessor"></span><span class="preprocessor">#define PRO_BP_MAP                         "BP_MAP"</span>
+<a name="l00079"></a>00079 <span class="preprocessor"></span><span class="preprocessor">#define PRO_MASTER_DARK                    "MASTER_DARK"</span>
+<a name="l00080"></a>00080 <span class="preprocessor"></span><span class="preprocessor">#define PRO_SLOPE                          "SLOPE"</span>
+<a name="l00081"></a>00081 <span class="preprocessor"></span><span class="preprocessor">#define PRO_DISTORTION                     "DISTORTION"</span>
+<a name="l00082"></a>00082 <span class="preprocessor"></span><span class="preprocessor">#define PRO_SLITLETS_DISTANCE              "SLITLETS_DISTANCE"</span>
+<a name="l00083"></a>00083 <span class="preprocessor"></span><span class="preprocessor">#define PRO_MASTER_SLIT                    "MASTER_SLIT"</span>
+<a name="l00084"></a>00084 <span class="preprocessor"></span><span class="preprocessor">#define PRO_MASTER_FLAT_LAMP               "MASTER_FLAT_LAMP"</span>
+<a name="l00085"></a>00085 <span class="preprocessor"></span><span class="preprocessor">#define PRO_MASTER_FLAT_LAMP1              "MASTER_FLAT_LAMP1"</span>
+<a name="l00086"></a>00086 <span class="preprocessor"></span><span class="preprocessor">#define PRO_MASTER_FLAT_LAMP2              "MASTER_FLAT_LAMP2"</span>
+<a name="l00087"></a>00087 <span class="preprocessor"></span><span class="preprocessor">#define PRO_SLIT_POS                       "SLIT_POS"</span>
+<a name="l00088"></a>00088 <span class="preprocessor"></span><span class="preprocessor">#define PRO_REF_ATM_REF_CORR               "ATM_REF_CORR"</span>
+<a name="l00089"></a>00089 <span class="preprocessor"></span><span class="preprocessor">#define PRO_SLITLETS_POS_PREDIST           "SLITLETS_POS_PREDIST"</span>
+<a name="l00090"></a>00090 <span class="preprocessor"></span><span class="preprocessor">#define PRO_SLIT_POS_GUESS                 "SLIT_POS_GUESS"</span>
+<a name="l00091"></a>00091 <span class="preprocessor"></span><span class="preprocessor">#define PRO_FIBRE_EW_STACKED               "FIBRE_EW_STACKED"</span>
+<a name="l00092"></a>00092 <span class="preprocessor"></span><span class="preprocessor">#define PRO_FIBRE_NS_STACKED_ON            "FIBRE_NS_STACKED_ON"</span>
+<a name="l00093"></a>00093 <span class="preprocessor"></span><span class="preprocessor">#define PRO_FIBRE_NS_STACKED_OFF           "FIBRE_NS_STACKED_OFF"</span>
+<a name="l00094"></a>00094 <span class="preprocessor"></span><span class="preprocessor">#define PRO_FIBRE_NS_STACKED               "FIBRE_NS_STACKED"</span>
+<a name="l00095"></a>00095 <span class="preprocessor"></span><span class="preprocessor">#define PRO_FIBRE_NS_STACKED_DIST          "FIBRE_NS_STACKED_DIST"</span>
+<a name="l00096"></a>00096 <span class="preprocessor"></span><span class="preprocessor">#define PRO_FIBRE_LAMP_STACKED             "FIBRE_LAMP_STACKED"</span>
+<a name="l00097"></a>00097 <span class="preprocessor"></span><span class="preprocessor">#define PRO_SLIT_LAMP_STACKED              "SLIT_LAMP_STACKED"</span>
+<a name="l00098"></a>00098 <span class="preprocessor"></span><span class="preprocessor">#define PRO_FLUX_LAMP_STACKED              "FLUX_LAMP_STACKED"</span>
+<a name="l00099"></a>00099 <span class="preprocessor"></span><span class="preprocessor">#define PRO_WAVE_LAMP_STACKED              "WAVE_LAMP_STACKED"</span>
+<a name="l00100"></a>00100 <span class="preprocessor"></span><span class="preprocessor">#define PRO_WAVE_SLITPOS_STACKED           "WAVE_LAMP_SLITPOS_STACKED"</span>
+<a name="l00101"></a>00101 <span class="preprocessor"></span><span class="preprocessor">#define PRO_WAVE_LAMP_DITHER_STACKED       "WAVE_LAMP_DITHER_STACKED"</span>
+<a name="l00102"></a>00102 <span class="preprocessor"></span><span class="preprocessor">#define PRO_WAVE_NS_STACKED                "WAVE_NS_STACKED"</span>
+<a name="l00103"></a>00103 <span class="preprocessor"></span><span class="preprocessor">#define PRO_WAVE_NS_DITHER_STACKED         "WAVE_NS_DITHER_STACKED"</span>
+<a name="l00104"></a>00104 <span class="preprocessor"></span><span class="preprocessor">#define PRO_WAVE_PAR_LIST                  "WAVE_FIT_PARAMS"</span>
+<a name="l00105"></a>00105 <span class="preprocessor"></span><span class="preprocessor">#define PRO_WAVE_COEF_SLIT                 "WAVE_COEF_SLIT"</span>
+<a name="l00106"></a>00106 <span class="preprocessor"></span><span class="preprocessor">#define PRO_PSF_CALIBRATOR_STACKED         "PSF_CALIBRATOR_STACKED"</span>
+<a name="l00107"></a>00107 <span class="preprocessor"></span><span class="preprocessor">#define PRO_FOCUS_STACKED                  "FOCUS_STACKED"</span>
+<a name="l00108"></a>00108 <span class="preprocessor"></span><span class="preprocessor">#define PRO_OBJECT_NODDING_STACKED         "OBJECT_NODDING_STACKED"</span>
+<a name="l00109"></a>00109 <span class="preprocessor"></span><span class="preprocessor">#define PRO_OBJECT_SKYSPIDER_STACKED       "OBJECT_SKYSPIDER_STACKED"</span>
+<a name="l00110"></a>00110 <span class="preprocessor"></span>
+<a name="l00111"></a>00111 
+<a name="l00112"></a>00112 <span class="preprocessor">#define PRO_RESAMPLED_WAVE                 "RESAMPLED_WAVE"</span>
+<a name="l00113"></a>00113 <span class="preprocessor"></span><span class="preprocessor">#define PRO_RESAMPLED_OBJ                  "RESAMPLED_OBJ"</span>
+<a name="l00114"></a>00114 <span class="preprocessor"></span><span class="preprocessor">#define PRO_RESAMPLED_SKY                  "RESAMPLED_SKY"</span>
+<a name="l00115"></a>00115 <span class="preprocessor"></span><span class="preprocessor">#define PRO_RESAMPLED_FLAT_LAMP            "RESAMPLED_FLAT_LAMP"</span>
+<a name="l00116"></a>00116 <span class="preprocessor"></span>
+<a name="l00117"></a>00117 <span class="preprocessor">#define PRO_OBS_CUBE_SKY                   "OBS_CUBE_SKY"</span>
+<a name="l00118"></a>00118 <span class="preprocessor"></span><span class="preprocessor">#define PRO_STD_CUBE_SKY                   "STD_CUBE_SKY"</span>
+<a name="l00119"></a>00119 <span class="preprocessor"></span><span class="preprocessor">#define PRO_PSF_CUBE_SKY                   "PSF_CUBE_SKY"</span>
+<a name="l00120"></a>00120 <span class="preprocessor"></span><span class="preprocessor">#define PRO_PUPIL_CUBE_SKY                 "PUPIL_CUBE_SKY"</span>
+<a name="l00121"></a>00121 <span class="preprocessor"></span>
+<a name="l00122"></a>00122 <span class="preprocessor">#define PRO_PUPIL_CUBE                     "PUPIL_LAMP_CUBE"</span>
+<a name="l00123"></a>00123 <span class="preprocessor"></span>
+<a name="l00124"></a>00124 
+<a name="l00125"></a>00125 <span class="preprocessor">#define PRO_OBS_MED_SKY                    "OBS_MED_SKY"</span>
+<a name="l00126"></a>00126 <span class="preprocessor"></span><span class="preprocessor">#define PRO_STD_MED_SKY                    "STD_MED_SKY"</span>
+<a name="l00127"></a>00127 <span class="preprocessor"></span><span class="preprocessor">#define PRO_PSF_MED_SKY                    "PSF_MED_SKY"</span>
+<a name="l00128"></a>00128 <span class="preprocessor"></span><span class="preprocessor">#define PRO_PUPIL_MED_SKY                  "PUPIL_MED_SKY"</span>
+<a name="l00129"></a>00129 <span class="preprocessor"></span>
+<a name="l00130"></a>00130 <span class="preprocessor">#define PRO_PUPIL_LAMP_STACKED             "PUPIL_LAMP_STACKED"</span>
+<a name="l00131"></a>00131 <span class="preprocessor"></span><span class="preprocessor">#define PRO_SKY_NODDING_STACKED            "SKY_NODDING_STACKED"</span>
+<a name="l00132"></a>00132 <span class="preprocessor"></span><span class="preprocessor">#define PRO_STD_NODDING_STACKED            "STD_NODDING_STACKED"</span>
+<a name="l00133"></a>00133 <span class="preprocessor"></span><span class="preprocessor">#define PRO_MASTER_LAMP_SPEC               "MASTER_LAMP_SPEC"</span>
+<a name="l00134"></a>00134 <span class="preprocessor"></span><span class="preprocessor">#define PRO_MASTER_TWIFLAT                 "MASTER_TWIFLAT"</span>
+<a name="l00135"></a>00135 <span class="preprocessor"></span><span class="preprocessor">#define PRO_COEFF_LIST                     "COEFF_LIST"</span>
+<a name="l00136"></a>00136 <span class="preprocessor"></span><span class="preprocessor">#define PRO_INDEX_LIST                     "INDEX_LIST"</span>
+<a name="l00137"></a>00137 <span class="preprocessor"></span><span class="preprocessor">#define PRO_HALO_SPECT                     "HALO_SPECT"</span>
+<a name="l00138"></a>00138 <span class="preprocessor"></span><span class="preprocessor">#define PRO_FIRST_COL                      "FIRST_COL"</span>
+<a name="l00139"></a>00139 <span class="preprocessor"></span><span class="preprocessor">#define PRO_MASK_CUBE                      "MASK_CUBE"  </span><span class="comment">/* not used*/</span>
+<a name="l00140"></a>00140 <span class="preprocessor">#define PRO_PSF                            "MASTER_PSF"</span>
+<a name="l00141"></a>00141 <span class="preprocessor"></span>
+<a name="l00142"></a>00142 <span class="preprocessor">#define TMP_FOCUS                          "FOCUS_STACKED"</span>
+<a name="l00143"></a>00143 <span class="preprocessor"></span><span class="preprocessor">#define TMP_FOCUS_ON                       "FOCUS_ON_STACKED"</span>
+<a name="l00144"></a>00144 <span class="preprocessor"></span><span class="preprocessor">#define TMP_FOCUS_OFF                      "FOCUS_OFF_STACKED"</span>
+<a name="l00145"></a>00145 <span class="preprocessor"></span>
+<a name="l00146"></a>00146 <span class="preprocessor">#define PRO_FOCUS                          "MASTER_FOCUS"</span>
+<a name="l00147"></a>00147 <span class="preprocessor"></span><span class="preprocessor">#define PRO_FOCUS_GAUSS                    "FOCUS_GAUSS"</span>
+<a name="l00148"></a>00148 <span class="preprocessor"></span><span class="preprocessor">#define PRO_WAVE_MAP                       "WAVE_MAP"</span>
+<a name="l00149"></a>00149 <span class="preprocessor"></span><span class="preprocessor">#define PRO_STD_STAR_SPECTRA               "STD_STAR_SPECTRA"</span>
+<a name="l00150"></a>00150 <span class="preprocessor"></span><span class="preprocessor">#define PRO_STD_STAR_SPECTRUM              "STD_STAR_SPECTRUM"</span>
+<a name="l00151"></a>00151 <span class="preprocessor"></span>
+<a name="l00152"></a>00152 <span class="preprocessor">#define PRO_CUBE                           "CUBE"</span>
+<a name="l00153"></a>00153 <span class="preprocessor"></span><span class="preprocessor">#define PRO_IMA                            "IMA"</span>
+<a name="l00154"></a>00154 <span class="preprocessor"></span><span class="preprocessor">#define PRO_SPECTRUM                       "SPECTRUM"</span>
+<a name="l00155"></a>00155 <span class="preprocessor"></span><span class="preprocessor">#define PRO_COADD_SKY                      "COADD_SKY"</span>
+<a name="l00156"></a>00156 <span class="preprocessor"></span><span class="preprocessor">#define PRO_COADD_PSF                      "COADD_PSF"</span>
+<a name="l00157"></a>00157 <span class="preprocessor"></span><span class="preprocessor">#define PRO_COADD_STD                      "COADD_STD"</span>
+<a name="l00158"></a>00158 <span class="preprocessor"></span><span class="preprocessor">#define PRO_COADD_OBJ                      "COADD_OBJ"</span>
+<a name="l00159"></a>00159 <span class="preprocessor"></span><span class="preprocessor">#define PRO_COADD_PUPIL                    "COADD_PUPIL"</span>
+<a name="l00160"></a>00160 <span class="preprocessor"></span>
+<a name="l00161"></a>00161 <span class="preprocessor">#define PRO_OBS_PSF                        "OBS_PSF"</span>
+<a name="l00162"></a>00162 <span class="preprocessor"></span><span class="preprocessor">#define PRO_OBS_STD                        "OBS_STD"</span>
+<a name="l00163"></a>00163 <span class="preprocessor"></span><span class="preprocessor">#define PRO_OBS_OBJ                        "OBS_OBJ"</span>
+<a name="l00164"></a>00164 <span class="preprocessor"></span><span class="preprocessor">#define PRO_OBS_PUPIL                      "OBS_PUPIL"</span>
+<a name="l00165"></a>00165 <span class="preprocessor"></span><span class="preprocessor">#define PRO_SPECTRA_QC                     "SPECTRA_QC"</span>
+<a name="l00166"></a>00166 <span class="preprocessor"></span>
+<a name="l00167"></a>00167 <span class="preprocessor">#define PRO_MED_COADD_PSF                  "MED_COADD_PSF"</span>
+<a name="l00168"></a>00168 <span class="preprocessor"></span><span class="preprocessor">#define PRO_MED_COADD_STD                  "MED_COADD_STD"</span>
+<a name="l00169"></a>00169 <span class="preprocessor"></span><span class="preprocessor">#define PRO_MED_COADD_OBJ                  "MED_COADD_OBJ"</span>
+<a name="l00170"></a>00170 <span class="preprocessor"></span><span class="preprocessor">#define PRO_MED_COADD_PUPIL                "MED_COADD_PUPIL"</span>
+<a name="l00171"></a>00171 <span class="preprocessor"></span>
+<a name="l00172"></a>00172 
+<a name="l00173"></a>00173 <span class="preprocessor">#define PRO_MED_OBS_PSF                    "MED_OBS_PSF"</span>
+<a name="l00174"></a>00174 <span class="preprocessor"></span><span class="preprocessor">#define PRO_MED_OBS_STD                    "MED_OBS_STD"</span>
+<a name="l00175"></a>00175 <span class="preprocessor"></span><span class="preprocessor">#define PRO_MED_OBS_OBJ                    "MED_OBS_OBJ"</span>
+<a name="l00176"></a>00176 <span class="preprocessor"></span><span class="preprocessor">#define PRO_MED_OBS_PUPIL                  "MED_OBS_PUPIL"</span>
+<a name="l00177"></a>00177 <span class="preprocessor"></span>
+<a name="l00178"></a>00178 
+<a name="l00179"></a>00179 <span class="preprocessor">#define PRO_CUBE_COLL                      "CUBE_COLL"</span>
+<a name="l00180"></a>00180 <span class="preprocessor"></span><span class="preprocessor">#define PRO_SLOPEX                         "CUBE_COLL_SLOPEX"</span>
+<a name="l00181"></a>00181 <span class="preprocessor"></span><span class="preprocessor">#define PRO_SLOPEY                         "CUBE_COLL_SLOPEY"</span>
+<a name="l00182"></a>00182 <span class="preprocessor"></span><span class="preprocessor">#define PRO_MASK_CUBE                      "MASK_CUBE"</span>
+<a name="l00183"></a>00183 <span class="preprocessor"></span><span class="preprocessor">#define PRO_MASK_COADD_PSF                 "MASK_COADD_PSF"</span>
+<a name="l00184"></a>00184 <span class="preprocessor"></span><span class="preprocessor">#define PRO_MASK_COADD_STD                 "MASK_COADD_STD"</span>
+<a name="l00185"></a>00185 <span class="preprocessor"></span><span class="preprocessor">#define PRO_MASK_COADD_OBJ                 "MASK_COADD_OBJ"</span>
+<a name="l00186"></a>00186 <span class="preprocessor"></span><span class="preprocessor">#define PRO_MASK_COADD_PUPIL               "MASK_COADD_PUPIL"</span>
+<a name="l00187"></a>00187 <span class="preprocessor"></span><span class="preprocessor">#define PRO_OBJ_CUBE                       "OBJ_CUBE"</span>
+<a name="l00188"></a>00188 <span class="preprocessor"></span><span class="preprocessor">#define PRO_BP_COEFF                       "BP_COEFF"</span>
+<a name="l00189"></a>00189 <span class="preprocessor"></span><span class="preprocessor">#define PRO_EFFICIENCY                     "EFFICIENCY"</span>
+<a name="l00190"></a>00190 <span class="preprocessor"></span>CPL_END_DECLS
+<a name="l00191"></a>00191 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__product__config_8c_source.html b/html/sinfo__product__config_8c_source.html
new file mode 100644
index 0000000..41717d5
--- /dev/null
+++ b/html/sinfo__product__config_8c_source.html
@@ -0,0 +1,81 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_product_config.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_product_config.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_product_config.c,v 1.7 2012/03/03 09:50:08 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the CPL (Common Pipeline Library)</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
+<a name="l00007"></a>00007 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span>
+<a name="l00008"></a>00008 <span class="comment"> * License as published by the Free Software Foundation; either</span>
+<a name="l00009"></a>00009 <span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
+<a name="l00014"></a>00014 <span class="comment"> * Lesser General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
+<a name="l00017"></a>00017 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2012/03/03 09:50:08 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.7 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> */</span>
+<a name="l00026"></a>00026 
+<a name="l00027"></a>00027  <span class="comment">/****************************************************************</span>
+<a name="l00028"></a>00028 <span class="comment">  *           Bad pixel search  (normal method)                  *</span>
+<a name="l00029"></a>00029 <span class="comment">  ****************************************************************/</span>
+<a name="l00030"></a>00030 
+<a name="l00031"></a>00031 
+<a name="l00032"></a>00032 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00033"></a>00033 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00034"></a>00034 <span class="preprocessor">#endif</span>
+<a name="l00035"></a>00035 <span class="preprocessor"></span>
+<a name="l00036"></a>00036 <span class="preprocessor">#include "sinfo_product_config.h"</span>
+<a name="l00037"></a>00037 
+<a name="l00056"></a>00056   <span class="comment">/* General data reduction parameters */</span>
+<a name="l00057"></a>00057 
+<a name="l00058"></a>00058 <span class="keywordtype">void</span>
+<a name="l00059"></a>00059  sinfo_product_config_add(cpl_parameterlist *list)
+<a name="l00060"></a>00060 {
+<a name="l00061"></a>00061 
+<a name="l00062"></a>00062   cpl_parameter *p;
+<a name="l00063"></a>00063 
+<a name="l00064"></a>00064   <span class="keywordflow">if</span> (!list) {
+<a name="l00065"></a>00065     <span class="keywordflow">return</span>;
+<a name="l00066"></a>00066   }
+<a name="l00067"></a>00067 
+<a name="l00068"></a>00068   <span class="comment">/* indicates if parameters will be overwritten */</span>
+<a name="l00069"></a>00069   p = cpl_parameter_new_enum(<span class="stringliteral">"sinfoni.product.density"</span>,
+<a name="l00070"></a>00070                  CPL_TYPE_INT,
+<a name="l00071"></a>00071                               <span class="stringliteral">"Density of pipeline products: "</span>
+<a name="l00072"></a>00072                               <span class="stringliteral">"0 (low), 1 (low+skycor), 2 (med-QC), "</span>
+<a name="l00073"></a>00073                               <span class="stringliteral">"3 (high-debug+skycor)"</span>,
+<a name="l00074"></a>00074                               <span class="stringliteral">"sinfoni.product"</span>,
+<a name="l00075"></a>00075                  2,4,0,1,2,3);
+<a name="l00076"></a>00076 
+<a name="l00077"></a>00077   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"product-density"</span>);
+<a name="l00078"></a>00078   cpl_parameterlist_append(list, p);
+<a name="l00079"></a>00079 
+<a name="l00080"></a>00080 
+<a name="l00081"></a>00081   <span class="keywordflow">return</span>;
+<a name="l00082"></a>00082 
+<a name="l00083"></a>00083 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__product__config_8h_source.html b/html/sinfo__product__config_8h_source.html
new file mode 100644
index 0000000..f61d2f2
--- /dev/null
+++ b/html/sinfo__product__config_8h_source.html
@@ -0,0 +1,53 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_product_config.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_product_config.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_product_config.h,v 1.1 2006/10/20 08:06:33 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the CPL (Common Pipeline Library)</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
+<a name="l00007"></a>00007 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span>
+<a name="l00008"></a>00008 <span class="comment"> * License as published by the Free Software Foundation; either</span>
+<a name="l00009"></a>00009 <span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
+<a name="l00014"></a>00014 <span class="comment"> * Lesser General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
+<a name="l00017"></a>00017 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2006/10/20 08:06:33 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.1 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> */</span>
+<a name="l00026"></a>00026 
+<a name="l00027"></a>00027  <span class="comment">/****************************************************************</span>
+<a name="l00028"></a>00028 <span class="comment">  *           Bad pixel search  (noise method)                  *</span>
+<a name="l00029"></a>00029 <span class="comment">  ****************************************************************/</span>
+<a name="l00030"></a>00030 <span class="preprocessor">#ifndef SINFO_PRODUCT_CONFIG_H</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_PRODUCT_CONFIG_H</span>
+<a name="l00032"></a>00032 <span class="preprocessor"></span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include <cpl.h></span>   
+<a name="l00034"></a>00034 
+<a name="l00035"></a>00035 <span class="keywordtype">void</span> sinfo_product_config_add(cpl_parameterlist *list);
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__psf__cfg_8c_source.html b/html/sinfo__psf__cfg_8c_source.html
new file mode 100644
index 0000000..156d9f2
--- /dev/null
+++ b/html/sinfo__psf__cfg_8c_source.html
@@ -0,0 +1,88 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_psf_cfg.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_psf_cfg.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name     :    sinfo_psf_cfg.c</span>
+<a name="l00022"></a>00022 <span class="comment">   Author     :       Juergen Schreiber</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on    :    February 2002</span>
+<a name="l00024"></a>00024 <span class="comment">   Description    :    configuration handling tools for the </span>
+<a name="l00025"></a>00025 <span class="comment">                        psf image reconstruction of a star.</span>
+<a name="l00026"></a>00026 <span class="comment"></span>
+<a name="l00027"></a>00027 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span>
+<a name="l00032"></a>00032 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                                   Includes</span>
+<a name="l00034"></a>00034 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 
+<a name="l00036"></a>00036 <span class="preprocessor">#include "sinfo_psf_cfg.h"</span>
+<a name="l00044"></a>00044 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00045"></a>00045 <span class="comment">                              Function codes</span>
+<a name="l00046"></a>00046 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00047"></a>00047 
+<a name="l00048"></a>00048 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00049"></a>00049 <span class="comment">   Function :   sinfo_psf_cfg_create()</span>
+<a name="l00050"></a>00050 <span class="comment">   In       :   void</span>
+<a name="l00051"></a>00051 <span class="comment">   Out      :   pointer to allocated base psf_config structure</span>
+<a name="l00052"></a>00052 <span class="comment">   Job      :   allocate memory for a psf_config struct</span>
+<a name="l00053"></a>00053 <span class="comment">   Notice   :   only the main (base) structure is allocated</span>
+<a name="l00054"></a>00054 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00055"></a>00055 
+<a name="l00056"></a>00056 psf_config * sinfo_psf_cfg_create(<span class="keywordtype">void</span>)
+<a name="l00057"></a>00057 {
+<a name="l00058"></a>00058     <span class="keywordflow">return</span> cpl_calloc(1, <span class="keyword">sizeof</span>(psf_config));
+<a name="l00059"></a>00059 }
+<a name="l00060"></a>00060 
+<a name="l00061"></a>00061 
+<a name="l00062"></a>00062 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00063"></a>00063 <span class="comment">   Function :   sinfo_psf_cfg_destroy()</span>
+<a name="l00064"></a>00064 <span class="comment">   In       :   psf_config to deallocate</span>
+<a name="l00065"></a>00065 <span class="comment">   Out      :   void</span>
+<a name="l00066"></a>00066 <span class="comment">   Job      :   deallocate all memory associated with a config data structure</span>
+<a name="l00067"></a>00067 <span class="comment">   Notice   :   </span>
+<a name="l00068"></a>00068 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00069"></a>00069 
+<a name="l00070"></a>00070 <span class="keywordtype">void</span> sinfo_psf_cfg_destroy(psf_config * cc)
+<a name="l00071"></a>00071 {
+<a name="l00072"></a>00072     <span class="keywordflow">if</span> (cc==NULL) return ;
+<a name="l00073"></a>00073 
+<a name="l00074"></a>00074     <span class="comment">/* Free main struct */</span>
+<a name="l00075"></a>00075     cpl_free(cc);
+<a name="l00076"></a>00076 
+<a name="l00077"></a>00077     return ;
+<a name="l00078"></a>00078 }
+<a name="l00079"></a>00079 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__psf__cfg_8h_source.html b/html/sinfo__psf__cfg_8h_source.html
new file mode 100644
index 0000000..f1534cc
--- /dev/null
+++ b/html/sinfo__psf__cfg_8h_source.html
@@ -0,0 +1,108 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_psf_cfg.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_psf_cfg.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name     :    sinfo_psf_cfg.h</span>
+<a name="l00022"></a>00022 <span class="comment">   Author    :    Juergen Schreiber</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on    :    February 2002</span>
+<a name="l00024"></a>00024 <span class="comment">   Description    :    psf_cfg.c definitions + handling prototypes</span>
+<a name="l00025"></a>00025 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00026"></a>00026 <span class="preprocessor">#ifndef SINFO_PSF_CFG_H</span>
+<a name="l00027"></a>00027 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_PSF_CFG_H</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00029"></a>00029 <span class="comment">                                   Includes</span>
+<a name="l00030"></a>00030 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00031"></a>00031 <span class="preprocessor">#include <stdlib.h></span>
+<a name="l00032"></a>00032 <span class="preprocessor">#include "sinfo_globals.h"</span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00034"></a>00034 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00035"></a>00035 <span class="comment">                                   Defines</span>
+<a name="l00036"></a>00036 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00037"></a>00037 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00038"></a>00038 <span class="comment">                                   New types</span>
+<a name="l00039"></a>00039 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00040"></a>00040 <span class="comment">/*</span>
+<a name="l00041"></a>00041 <span class="comment">  PSF star image reconstruction blackboard container</span>
+<a name="l00042"></a>00042 <span class="comment"></span>
+<a name="l00043"></a>00043 <span class="comment">  This structure holds all information related to the sinfo_psf reconstruction</span>
+<a name="l00044"></a>00044 <span class="comment">  routine. It is used as a container for the flux of ancillary data,</span>
+<a name="l00045"></a>00045 <span class="comment">  computed values, and algorithm status. Pixel flux is separated from</span>
+<a name="l00046"></a>00046 <span class="comment">  the blackboard.</span>
+<a name="l00047"></a>00047 <span class="comment">  */</span>
+<a name="l00048"></a>00048 
+<a name="l00049"></a>00049 <span class="keyword">typedef</span> <span class="keyword">struct </span>psf_config {
+<a name="l00050"></a>00050 <span class="comment">/*-------General---------*/</span>
+<a name="l00051"></a>00051         <span class="keywordtype">char</span> inFrame[FILE_NAME_SZ] ; <span class="comment">/* input averaged, bad pixel corrected, </span>
+<a name="l00052"></a>00052 <span class="comment">                                        off subtracted, flatfielded, spectral </span>
+<a name="l00053"></a>00053 <span class="comment">                                        tilt corrected list of frames */</span>
+<a name="l00054"></a>00054         <span class="keywordtype">char</span> outName[FILE_NAME_SZ] ; <span class="comment">/* output name of resulting fits </span>
+<a name="l00055"></a>00055 <span class="comment">                                        data cube */</span>
+<a name="l00056"></a>00056 
+<a name="l00057"></a>00057 <span class="comment">/*------ Reconstruction ------*/</span>
+<a name="l00058"></a>00058         <span class="comment">/* the fraction [0...1] of rejected low intensity pixels when taking </span>
+<a name="l00059"></a>00059 <span class="comment">           the average of columns */</span>
+<a name="l00060"></a>00060         <span class="keywordtype">float</span> lo_reject ;
+<a name="l00061"></a>00061         <span class="comment">/* the fraction [0...1] of rejected high intensity pixels when taking </span>
+<a name="l00062"></a>00062 <span class="comment">           the average of columns */</span>
+<a name="l00063"></a>00063         <span class="keywordtype">float</span> hi_reject ;
+<a name="l00064"></a>00064         <span class="comment">/* indicates if the slitlet distances are determined by a </span>
+<a name="l00065"></a>00065 <span class="comment">           north-south test (1) or slitlet edge fits (0) */</span> 
+<a name="l00066"></a>00066         <span class="keywordtype">int</span> northsouthInd  ;
+<a name="l00067"></a>00067         <span class="comment">/* name of the ASCII list of the fitted slitlet edge positions or </span>
+<a name="l00068"></a>00068 <span class="comment">           the distances of the slitlets */</span>
+<a name="l00069"></a>00069         <span class="keywordtype">char</span> poslist[FILE_NAME_SZ] ;
+<a name="l00070"></a>00070         <span class="comment">/* number of slitlets (32) */</span>
+<a name="l00071"></a>00071         <span class="keywordtype">int</span> nslits ;
+<a name="l00072"></a>00072         <span class="comment">/* sub pixel position of the column position of the left sinfo_edge of </span>
+<a name="l00073"></a>00073 <span class="comment">           the first slitlet needed if the slitlet distances were determined </span>
+<a name="l00074"></a>00074 <span class="comment">           by a north south test */</span>
+<a name="l00075"></a>00075         <span class="keywordtype">char</span>  firstCol[FILE_NAME_SZ] ;
+<a name="l00076"></a>00076     <span class="comment">/* indicator for the shifting method to use */</span>
+<a name="l00077"></a>00077     <span class="keywordtype">char</span>  method[1] ;
+<a name="l00078"></a>00078         <span class="comment">/* order of polynomial if the polynomial interpolation shifting </span>
+<a name="l00079"></a>00079 <span class="comment">           method is used */</span>
+<a name="l00080"></a>00080         <span class="keywordtype">int</span> order ;
+<a name="l00081"></a>00081 } psf_config ;
+<a name="l00082"></a>00082 
+<a name="l00083"></a>00083 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00084"></a>00084 <span class="comment">                               Function prototypes</span>
+<a name="l00085"></a>00085 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00093"></a>00093 psf_config * 
+<a name="l00094"></a>00094 sinfo_psf_cfg_create(<span class="keywordtype">void</span>);
+<a name="l00095"></a>00095 
+<a name="l00102"></a>00102 <span class="keywordtype">void</span> 
+<a name="l00103"></a>00103 sinfo_psf_cfg_destroy(psf_config * cc);
+<a name="l00104"></a>00104 
+<a name="l00105"></a>00105 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__psf__config_8c_source.html b/html/sinfo__psf__config_8c_source.html
new file mode 100644
index 0000000..b793264
--- /dev/null
+++ b/html/sinfo__psf__config_8c_source.html
@@ -0,0 +1,74 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_psf_config.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_psf_config.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_psf_config.c,v 1.5 2012/03/03 09:50:08 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the CPL (Common Pipeline Library)</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
+<a name="l00007"></a>00007 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span>
+<a name="l00008"></a>00008 <span class="comment"> * License as published by the Free Software Foundation; either</span>
+<a name="l00009"></a>00009 <span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
+<a name="l00014"></a>00014 <span class="comment"> * Lesser General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
+<a name="l00017"></a>00017 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2012/03/03 09:50:08 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.5 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> */</span>
+<a name="l00026"></a>00026 
+<a name="l00027"></a>00027  <span class="comment">/****************************************************************</span>
+<a name="l00028"></a>00028 <span class="comment">  *   Psf Frames Data Reduction Parameter Initialization        *</span>
+<a name="l00029"></a>00029 <span class="comment">  ****************************************************************/</span>
+<a name="l00030"></a>00030 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00032"></a>00032 <span class="preprocessor">#endif</span>
+<a name="l00033"></a>00033 <span class="preprocessor"></span>
+<a name="l00034"></a>00034 <span class="preprocessor">#include "sinfo_psf_config.h"</span>
+<a name="l00049"></a>00049 <span class="keywordtype">void</span>
+<a name="l00050"></a>00050  sinfo_psf_config_add(cpl_parameterlist *list)
+<a name="l00051"></a>00051 {
+<a name="l00052"></a>00052 
+<a name="l00053"></a>00053   cpl_parameter *p;
+<a name="l00054"></a>00054   <span class="keywordflow">if</span> (!list) {
+<a name="l00055"></a>00055     <span class="keywordflow">return</span>;
+<a name="l00056"></a>00056   }
+<a name="l00057"></a>00057 
+<a name="l00058"></a>00058   <span class="comment">/* Input file name */</span>
+<a name="l00059"></a>00059 
+<a name="l00060"></a>00060   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.psf.switch"</span>,
+<a name="l00061"></a>00061                   CPL_TYPE_BOOL,
+<a name="l00062"></a>00062                               <span class="stringliteral">"Switch to activate PSF-related "</span>
+<a name="l00063"></a>00063                               <span class="stringliteral">"(Strehl/Encircled energy) computation"</span>,
+<a name="l00064"></a>00064                               <span class="stringliteral">"sinfoni.psf"</span>,
+<a name="l00065"></a>00065                               TRUE);
+<a name="l00066"></a>00066 
+<a name="l00067"></a>00067   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"psf-switch"</span>);
+<a name="l00068"></a>00068   cpl_parameterlist_append(list, p);
+<a name="l00069"></a>00069 
+<a name="l00070"></a>00070 
+<a name="l00071"></a>00071 
+<a name="l00072"></a>00072 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__psf__config_8h_source.html b/html/sinfo__psf__config_8h_source.html
new file mode 100644
index 0000000..d28365e
--- /dev/null
+++ b/html/sinfo__psf__config_8h_source.html
@@ -0,0 +1,48 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_psf_config.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_psf_config.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_psf_config.h,v 1.1 2006/10/20 08:06:33 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the CPL (Common Pipeline Library)</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
+<a name="l00007"></a>00007 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span>
+<a name="l00008"></a>00008 <span class="comment"> * License as published by the Free Software Foundation; either</span>
+<a name="l00009"></a>00009 <span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
+<a name="l00014"></a>00014 <span class="comment"> * Lesser General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
+<a name="l00017"></a>00017 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2006/10/20 08:06:33 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.1 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> */</span>
+<a name="l00026"></a>00026 
+<a name="l00027"></a>00027  <span class="comment">/****************************************************************</span>
+<a name="l00028"></a>00028 <span class="comment">  *   Psf Frames Data Reduction Parameter Initialization        *</span>
+<a name="l00029"></a>00029 <span class="comment">  ****************************************************************/</span>
+<a name="l00030"></a>00030 <span class="preprocessor">#include "cpl.h"</span>    <span class="comment">/* defines parlist structure */</span>
+<a name="l00031"></a>00031 <span class="keywordtype">void</span>
+<a name="l00032"></a>00032 sinfo_psf_config_add(cpl_parameterlist *list);
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__psf__ini_8h_source.html b/html/sinfo__psf__ini_8h_source.html
new file mode 100644
index 0000000..5b76cdb
--- /dev/null
+++ b/html/sinfo__psf__ini_8h_source.html
@@ -0,0 +1,63 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_psf_ini.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_psf_ini.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name    :  psf_ini.h</span>
+<a name="l00022"></a>00022 <span class="comment">   Author       :    Juergen Schreiber</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on   :    Feb 18, 2002</span>
+<a name="l00024"></a>00024 <span class="comment">   Description  :    ini file handling for SINFONI  PSF star </span>
+<a name="l00025"></a>00025 <span class="comment">                        image reconstruction</span>
+<a name="l00026"></a>00026 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00027"></a>00027 <span class="preprocessor">#ifndef SINFO_PSF_INI_H</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_PSF_INI_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00030"></a>00030 <span class="comment">                                Includes</span>
+<a name="l00031"></a>00031 <span class="comment">---------------------------------------------------------------------------*/</span>
+<a name="l00032"></a>00032 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include "sinfo_psf_cfg.h"</span>
+<a name="l00034"></a>00034 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00035"></a>00035 <span class="comment">                             Function prototypes </span>
+<a name="l00036"></a>00036 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00054"></a>00054 <span class="keywordtype">int</span> 
+<a name="l00055"></a>00055 generatePSF_ini_file(
+<a name="l00056"></a>00056         <span class="keywordtype">char</span> * ini_name,
+<a name="l00057"></a>00057         <span class="keywordtype">char</span> * name_i,
+<a name="l00058"></a>00058         <span class="keywordtype">char</span> * name_o
+<a name="l00059"></a>00059 );
+<a name="l00060"></a>00060 
+<a name="l00073"></a>00073 psf_config * 
+<a name="l00074"></a>00074 parse_psf_ini_file(<span class="keywordtype">char</span> * ini_name) ;
+<a name="l00075"></a>00075 
+<a name="l00076"></a>00076 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__psf__ini__by__cpl_8c_source.html b/html/sinfo__psf__ini__by__cpl_8c_source.html
new file mode 100644
index 0000000..9509a3b
--- /dev/null
+++ b/html/sinfo__psf__ini__by__cpl_8c_source.html
@@ -0,0 +1,205 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_psf_ini_by_cpl.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_psf_ini_by_cpl.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name    :   sinfo_psf_ini_by_cpl.c</span>
+<a name="l00022"></a>00022 <span class="comment">   Author       :   Andrea Modigliani</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on   :   May 20, 2004</span>
+<a name="l00024"></a>00024 <span class="comment">   Description  :   cpl input for sinfo_psf step for SPIFFI</span>
+<a name="l00025"></a>00025 <span class="comment"></span>
+<a name="l00026"></a>00026 <span class="comment"></span>
+<a name="l00027"></a>00027 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00028"></a>00028 
+<a name="l00029"></a>00029 
+<a name="l00030"></a>00030 
+<a name="l00031"></a>00031 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00032"></a>00032 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00033"></a>00033 <span class="preprocessor">#endif</span>
+<a name="l00034"></a>00034 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00035"></a>00035 <span class="comment">                                Includes</span>
+<a name="l00036"></a>00036 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00037"></a>00037 
+<a name="l00038"></a>00038 <span class="preprocessor">#include "sinfo_psf_ini_by_cpl.h"</span>
+<a name="l00039"></a>00039 <span class="preprocessor">#include "sinfo_hidden.h"</span>
+<a name="l00040"></a>00040 
+<a name="l00041"></a>00041 
+<a name="l00042"></a>00042 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00043"></a>00043 <span class="comment">                    Functions private to this module</span>
+<a name="l00044"></a>00044 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00045"></a>00045 <span class="keyword">static</span> <span class="keywordtype">void</span>      parse_section_frames(psf_config *, 
+<a name="l00046"></a>00046                    cpl_frameset* sof,cpl_frameset** stk,<span class="keywordtype">int</span>* status);
+<a name="l00047"></a>00047 <span class="keyword">static</span> <span class="keywordtype">void</span>     parse_section_reconstruction(psf_config *);
+<a name="l00048"></a>00048 
+<a name="l00049"></a>00049 
+<a name="l00058"></a>00058 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l00069"></a>00069 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00070"></a>00070 
+<a name="l00071"></a>00071 psf_config * sinfo_parse_cpl_input_psf(cpl_frameset* sof, 
+<a name="l00072"></a>00072                  cpl_frameset** stk)
+<a name="l00073"></a>00073 {
+<a name="l00074"></a>00074         psf_config  *       cfg =NULL;
+<a name="l00075"></a>00075         <span class="keywordtype">int</span> status=0;
+<a name="l00076"></a>00076         <span class="comment">/*</span>
+<a name="l00077"></a>00077 <span class="comment">         * Perform sanity checks, fill up the structure with what was</span>
+<a name="l00078"></a>00078 <span class="comment">         * found in the ini file</span>
+<a name="l00079"></a>00079 <span class="comment">         */</span>
+<a name="l00080"></a>00080 
+<a name="l00081"></a>00081         cfg = sinfo_psf_cfg_create();
+<a name="l00082"></a>00082         parse_section_reconstruction   (cfg);
+<a name="l00083"></a>00083          parse_section_frames       (cfg, sof,stk,&status);
+<a name="l00084"></a>00084         <span class="keywordflow">if</span> (status > 0) {
+<a name="l00085"></a>00085                 <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"parsing cpl input"</span>);
+<a name="l00086"></a>00086                 sinfo_psf_cfg_destroy(cfg);
+<a name="l00087"></a>00087                 cfg = NULL ;
+<a name="l00088"></a>00088                 <span class="keywordflow">return</span> NULL ;
+<a name="l00089"></a>00089         }
+<a name="l00090"></a>00090         <span class="keywordflow">return</span> cfg ;
+<a name="l00091"></a>00091 }
+<a name="l00092"></a>00092 
+<a name="l00093"></a>00093 <span class="keyword">static</span> <span class="keywordtype">void</span>
+<a name="l00094"></a>00094 parse_section_frames(psf_config * cfg, 
+<a name="l00095"></a>00095              cpl_frameset* sof,
+<a name="l00096"></a>00096                      cpl_frameset** stk,
+<a name="l00097"></a>00097                      <span class="keywordtype">int</span>* status)
+<a name="l00098"></a>00098 {
+<a name="l00099"></a>00099    cpl_frame* frame   = NULL;
+<a name="l00100"></a>00100 
+<a name="l00101"></a>00101    <span class="keywordtype">int</span>                 npsf=0;
+<a name="l00102"></a>00102    <span class="keywordtype">int</span> nraw=0;
+<a name="l00103"></a>00103    <span class="keywordtype">char</span> spat_res[FILE_NAME_SZ];
+<a name="l00104"></a>00104    <span class="keywordtype">char</span> lamp_status[FILE_NAME_SZ];
+<a name="l00105"></a>00105    <span class="keywordtype">char</span> band[FILE_NAME_SZ];
+<a name="l00106"></a>00106    <span class="keywordtype">int</span> ins_set=0;
+<a name="l00107"></a>00107 
+<a name="l00108"></a>00108      sinfo_contains_frames_type(sof,stk,PRO_PSF_CALIBRATOR_STACKED);
+<a name="l00109"></a>00109      npsf = cpl_frameset_get_size(*stk);
+<a name="l00110"></a>00110      <span class="keywordflow">if</span> (npsf < 1) {
+<a name="l00111"></a>00111        sinfo_contains_frames_type(sof,stk,PRO_STD_NODDING_STACKED);
+<a name="l00112"></a>00112        npsf = cpl_frameset_get_size(*stk);
+<a name="l00113"></a>00113      }
+<a name="l00114"></a>00114 
+<a name="l00115"></a>00115      npsf = cpl_frameset_get_size(*stk);
+<a name="l00116"></a>00116      <span class="keywordflow">if</span> (npsf < 1) {
+<a name="l00117"></a>00117        sinfo_contains_frames_type(sof,stk,PRO_OBJECT_NODDING_STACKED);
+<a name="l00118"></a>00118        npsf = cpl_frameset_get_size(*stk);
+<a name="l00119"></a>00119      }
+<a name="l00120"></a>00120 
+<a name="l00121"></a>00121 
+<a name="l00122"></a>00122      npsf = cpl_frameset_get_size(*stk);
+<a name="l00123"></a>00123      <span class="keywordflow">if</span> (npsf < 1) {
+<a name="l00124"></a>00124        sinfo_contains_frames_type(sof,stk,PRO_PUPIL_LAMP_STACKED);
+<a name="l00125"></a>00125        npsf = cpl_frameset_get_size(*stk);
+<a name="l00126"></a>00126      }
+<a name="l00127"></a>00127 
+<a name="l00128"></a>00128      npsf = cpl_frameset_get_size(*stk);
+<a name="l00129"></a>00129      <span class="keywordflow">if</span> (npsf < 1) {
+<a name="l00130"></a>00130          <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Cannot find input stacked frames"</span>) ;
+<a name="l00131"></a>00131          (*status)++;
+<a name="l00132"></a>00132          <span class="keywordflow">return</span>;
+<a name="l00133"></a>00133      }
+<a name="l00134"></a>00134 
+<a name="l00135"></a>00135     <span class="keywordflow">if</span>(NULL != cpl_frameset_find(sof,PRO_COADD_PSF)) {
+<a name="l00136"></a>00136       frame = cpl_frameset_find(sof,PRO_COADD_PSF);
+<a name="l00137"></a>00137       strcpy(cfg -> inFrame,cpl_frame_get_filename(frame));
+<a name="l00138"></a>00138     } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(NULL != cpl_frameset_find(sof,PRO_OBS_PSF)) {
+<a name="l00139"></a>00139       frame = cpl_frameset_find(sof,PRO_OBS_PSF);
+<a name="l00140"></a>00140       strcpy(cfg -> inFrame,cpl_frame_get_filename(frame));
+<a name="l00141"></a>00141     } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(NULL != cpl_frameset_find(sof,PRO_COADD_STD)) {
+<a name="l00142"></a>00142       frame = cpl_frameset_find(sof,PRO_COADD_STD);
+<a name="l00143"></a>00143       strcpy(cfg -> inFrame,cpl_frame_get_filename(frame));
+<a name="l00144"></a>00144     } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(NULL != cpl_frameset_find(sof,PRO_OBS_STD)) {
+<a name="l00145"></a>00145       frame = cpl_frameset_find(sof,PRO_OBS_STD);
+<a name="l00146"></a>00146       strcpy(cfg -> inFrame,cpl_frame_get_filename(frame));
+<a name="l00147"></a>00147     } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(NULL != cpl_frameset_find(sof,PRO_COADD_OBJ)) {
+<a name="l00148"></a>00148       frame = cpl_frameset_find(sof,PRO_COADD_OBJ);
+<a name="l00149"></a>00149       strcpy(cfg -> inFrame,cpl_frame_get_filename(frame));
+<a name="l00150"></a>00150     } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(NULL != cpl_frameset_find(sof,PRO_OBS_OBJ)) {
+<a name="l00151"></a>00151       frame = cpl_frameset_find(sof,PRO_OBS_OBJ);
+<a name="l00152"></a>00152       strcpy(cfg -> inFrame,cpl_frame_get_filename(frame));
+<a name="l00153"></a>00153     } <span class="keywordflow">else</span> {
+<a name="l00154"></a>00154       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Frame %s or %s or %s or %s or %s or %s not found!"</span>, 
+<a name="l00155"></a>00155        PRO_COADD_PSF,PRO_OBS_PSF,
+<a name="l00156"></a>00156        PRO_COADD_STD,PRO_OBS_STD,
+<a name="l00157"></a>00157        PRO_COADD_OBJ,PRO_OBS_OBJ);
+<a name="l00158"></a>00158       (*status)++;
+<a name="l00159"></a>00159       <span class="keywordflow">return</span>;
+<a name="l00160"></a>00160     }
+<a name="l00161"></a>00161 
+<a name="l00162"></a>00162    strcpy(cfg -> outName, PSF_OUT_FILENAME);
+<a name="l00163"></a>00163    nraw    = cpl_frameset_get_size(*stk);
+<a name="l00164"></a>00164    frame = cpl_frameset_get_frame(*stk,0);
+<a name="l00165"></a>00165 
+<a name="l00166"></a>00166    sinfo_get_spatial_res(frame,spat_res);
+<a name="l00167"></a>00167    <span class="keywordflow">switch</span>(sinfo_frame_is_on(frame))
+<a name="l00168"></a>00168      {
+<a name="l00169"></a>00169 
+<a name="l00170"></a>00170     <span class="keywordflow">case</span> 0: 
+<a name="l00171"></a>00171       strcpy(lamp_status,<span class="stringliteral">"on"</span>);
+<a name="l00172"></a>00172       <span class="keywordflow">break</span>;
+<a name="l00173"></a>00173     <span class="keywordflow">case</span> 1: 
+<a name="l00174"></a>00174       strcpy(lamp_status,<span class="stringliteral">"off"</span>);
+<a name="l00175"></a>00175       <span class="keywordflow">break</span>;
+<a name="l00176"></a>00176     <span class="keywordflow">case</span> -1:
+<a name="l00177"></a>00177       strcpy(lamp_status,<span class="stringliteral">"undefined"</span>);
+<a name="l00178"></a>00178       <span class="keywordflow">break</span>;
+<a name="l00179"></a>00179     <span class="keywordflow">default</span>: 
+<a name="l00180"></a>00180       strcpy(lamp_status,<span class="stringliteral">"undefined"</span>);
+<a name="l00181"></a>00181       <span class="keywordflow">break</span>;
+<a name="l00182"></a>00182 
+<a name="l00183"></a>00183      }
+<a name="l00184"></a>00184 
+<a name="l00185"></a>00185    sinfo_get_band(frame,band);
+<a name="l00186"></a>00186    sinfo_msg(<span class="stringliteral">"Spatial resolution: %s lamp status: %s band: %s \n"</span>,
+<a name="l00187"></a>00187                      spat_res,    lamp_status,    band);
+<a name="l00188"></a>00188 
+<a name="l00189"></a>00189    sinfo_get_ins_set(band,&ins_set);
+<a name="l00190"></a>00190 
+<a name="l00191"></a>00191    <span class="keywordflow">return</span>;
+<a name="l00192"></a>00192 
+<a name="l00193"></a>00193 }
+<a name="l00194"></a>00194 
+<a name="l00195"></a>00195 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00196"></a>00196 parse_section_reconstruction(psf_config * cfg)
+<a name="l00197"></a>00197 {
+<a name="l00198"></a>00198    cfg -> nslits = NSLITLETS;
+<a name="l00199"></a>00199    <span class="keywordflow">return</span>;
+<a name="l00200"></a>00200 }
+<a name="l00201"></a>00201 
+<a name="l00202"></a>00202 <span class="keywordtype">void</span>
+<a name="l00203"></a>00203 sinfo_free_psf(psf_config ** cfg) {
+<a name="l00204"></a>00204    sinfo_psf_cfg_destroy (*cfg);
+<a name="l00205"></a>00205    *cfg=NULL;
+<a name="l00206"></a>00206   <span class="keywordflow">return</span>;
+<a name="l00207"></a>00207 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__psf__ini__by__cpl_8h_source.html b/html/sinfo__psf__ini__by__cpl_8h_source.html
new file mode 100644
index 0000000..e45445d
--- /dev/null
+++ b/html/sinfo__psf__ini__by__cpl_8h_source.html
@@ -0,0 +1,59 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_psf_ini_by_cpl.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_psf_ini_by_cpl.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name    :  sinfo_psf_ini_by_cpl.h</span>
+<a name="l00022"></a>00022 <span class="comment">   Author       :  Andrea Modigliani</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on   :  May 20, 2004</span>
+<a name="l00024"></a>00024 <span class="comment">   Description  :    ini file handling for SPIFFIs PSF star image reconstruction</span>
+<a name="l00025"></a>00025 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00026"></a>00026 <span class="preprocessor">#ifndef SINFO_PSF_INI_BY_CPL_H</span>
+<a name="l00027"></a>00027 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_PSF_INI_BY_CPL_H</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00029"></a>00029 <span class="comment">                                Includes</span>
+<a name="l00030"></a>00030 <span class="comment">---------------------------------------------------------------------------*/</span>
+<a name="l00031"></a>00031 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00032"></a>00032 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include "sinfo_dfs.h"</span>
+<a name="l00034"></a>00034 <span class="preprocessor">#include "sinfo_psf_cfg.h"</span>
+<a name="l00035"></a>00035 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00036"></a>00036 <span class="comment">                             Function prototypes </span>
+<a name="l00037"></a>00037 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00051"></a>00051 psf_config * 
+<a name="l00052"></a>00052 sinfo_parse_cpl_input_psf(cpl_frameset* sof, cpl_frameset** stk);
+<a name="l00053"></a>00053 
+<a name="l00061"></a>00061 <span class="keywordtype">void</span> 
+<a name="l00062"></a>00062 sinfo_free_psf(psf_config ** cfg);
+<a name="l00063"></a>00063 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__qr_8c_source.html b/html/sinfo__qr_8c_source.html
new file mode 100644
index 0000000..982ee7b
--- /dev/null
+++ b/html/sinfo__qr_8c_source.html
@@ -0,0 +1,277 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_qr.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_qr.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_qr.c,v 1.5 2012/03/03 10:18:26 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the SINFONI Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2012/03/03 10:18:26 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.5 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00035"></a>00035 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00036"></a>00036 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00037"></a>00037 <span class="preprocessor">#endif</span>
+<a name="l00038"></a>00038 <span class="preprocessor"></span>
+<a name="l00039"></a>00039 <span class="preprocessor">#include "sinfo_solve_poly_root.h"</span>
+<a name="l00040"></a>00040 <span class="comment">//#include "sinfoni_recipes_defaults.h"</span>
+<a name="l00041"></a>00041 
+<a name="l00042"></a>00042 <span class="preprocessor">#define GSL_SET_COMPLEX_PACKED(zp,n,x,y) \</span>
+<a name="l00043"></a>00043 <span class="preprocessor"> do {*((zp)+2*(n))=(x); *((zp)+(2*(n)+1))=(y);} while(0)</span>
+<a name="l00044"></a>00044 <span class="preprocessor"></span><span class="preprocessor">#define GSL_DBL_EPSILON        2.2204460492503131e-16</span>
+<a name="l00045"></a>00045 <span class="preprocessor"></span>
+<a name="l00046"></a>00046 
+<a name="l00047"></a>00047 <span class="keywordtype">int</span>
+<a name="l00048"></a>00048 sinfo_qr_companion (<span class="keywordtype">double</span> *h, <span class="keywordtype">size_t</span> nc, gsl_complex_packed_ptr zroot)
+<a name="l00049"></a>00049 {
+<a name="l00050"></a>00050   <span class="keywordtype">double</span> t = 0.0;
+<a name="l00051"></a>00051 
+<a name="l00052"></a>00052   <span class="keywordtype">size_t</span> iterations, e, i, j, k, m;
+<a name="l00053"></a>00053 
+<a name="l00054"></a>00054   <span class="keywordtype">double</span> w, x, y, s, z;
+<a name="l00055"></a>00055 
+<a name="l00056"></a>00056   <span class="keywordtype">double</span> p = 0, q = 0, r = 0; 
+<a name="l00057"></a>00057 
+<a name="l00058"></a>00058   <span class="comment">/* FIXME: if p,q,r, are not set to zero then the compiler complains</span>
+<a name="l00059"></a>00059 <span class="comment">     that they ``might be used uninitialized in this</span>
+<a name="l00060"></a>00060 <span class="comment">     function''. Looking at the code this does seem possible, so this</span>
+<a name="l00061"></a>00061 <span class="comment">     should be checked. */</span>
+<a name="l00062"></a>00062 
+<a name="l00063"></a>00063   <span class="keywordtype">int</span> notlast;
+<a name="l00064"></a>00064 
+<a name="l00065"></a>00065   <span class="keywordtype">size_t</span> n = nc;
+<a name="l00066"></a>00066 
+<a name="l00067"></a>00067 next_root:
+<a name="l00068"></a>00068 
+<a name="l00069"></a>00069   <span class="keywordflow">if</span> (n == 0)
+<a name="l00070"></a>00070     <span class="keywordflow">return</span> 1 ;
+<a name="l00071"></a>00071 
+<a name="l00072"></a>00072   iterations = 0;
+<a name="l00073"></a>00073 
+<a name="l00074"></a>00074 next_iteration:
+<a name="l00075"></a>00075 
+<a name="l00076"></a>00076   <span class="keywordflow">for</span> (e = n; e >= 2; e--)
+<a name="l00077"></a>00077     {
+<a name="l00078"></a>00078       <span class="keywordtype">double</span> a1 = fabs (FMAT (h, e, e - 1, nc));
+<a name="l00079"></a>00079       <span class="keywordtype">double</span> a2 = fabs (FMAT (h, e - 1, e - 1, nc));
+<a name="l00080"></a>00080       <span class="keywordtype">double</span> a3 = fabs (FMAT (h, e, e, nc));
+<a name="l00081"></a>00081 
+<a name="l00082"></a>00082       <span class="keywordflow">if</span> (a1 <= GSL_DBL_EPSILON * (a2 + a3))
+<a name="l00083"></a>00083     <span class="keywordflow">break</span>;
+<a name="l00084"></a>00084     }
+<a name="l00085"></a>00085 
+<a name="l00086"></a>00086   x = FMAT (h, n, n, nc);
+<a name="l00087"></a>00087 
+<a name="l00088"></a>00088   <span class="keywordflow">if</span> (e == n)
+<a name="l00089"></a>00089     {
+<a name="l00090"></a>00090       GSL_SET_COMPLEX_PACKED (zroot, n-1, x + t, 0); <span class="comment">/* one real root */</span>
+<a name="l00091"></a>00091       n--;
+<a name="l00092"></a>00092       <span class="keywordflow">goto</span> next_root;
+<a name="l00093"></a>00093       <span class="comment">/*continue;*/</span>
+<a name="l00094"></a>00094     }
+<a name="l00095"></a>00095 
+<a name="l00096"></a>00096   y = FMAT (h, n - 1, n - 1, nc);
+<a name="l00097"></a>00097   w = FMAT (h, n - 1, n, nc) * FMAT (h, n, n - 1, nc);
+<a name="l00098"></a>00098 
+<a name="l00099"></a>00099   <span class="keywordflow">if</span> (e == n - 1)
+<a name="l00100"></a>00100     {
+<a name="l00101"></a>00101       p = (y - x) / 2;
+<a name="l00102"></a>00102       q = p * p + w;
+<a name="l00103"></a>00103       y = sqrt (fabs (q));
+<a name="l00104"></a>00104 
+<a name="l00105"></a>00105       x += t;
+<a name="l00106"></a>00106 
+<a name="l00107"></a>00107       <span class="keywordflow">if</span> (q > 0)        <span class="comment">/* two real roots */</span>
+<a name="l00108"></a>00108     {
+<a name="l00109"></a>00109       <span class="keywordflow">if</span> (p < 0)
+<a name="l00110"></a>00110         y = -y;
+<a name="l00111"></a>00111       y += p;
+<a name="l00112"></a>00112 
+<a name="l00113"></a>00113       GSL_SET_COMPLEX_PACKED (zroot, n-1, x - w / y, 0);
+<a name="l00114"></a>00114           GSL_SET_COMPLEX_PACKED (zroot, n-2, x + y, 0);
+<a name="l00115"></a>00115     }
+<a name="l00116"></a>00116       <span class="keywordflow">else</span>
+<a name="l00117"></a>00117     {
+<a name="l00118"></a>00118       GSL_SET_COMPLEX_PACKED (zroot, n-1, x + p, -y);
+<a name="l00119"></a>00119       GSL_SET_COMPLEX_PACKED (zroot, n-2, x + p, y);
+<a name="l00120"></a>00120     }
+<a name="l00121"></a>00121       n -= 2;
+<a name="l00122"></a>00122 
+<a name="l00123"></a>00123       <span class="keywordflow">goto</span> next_root;
+<a name="l00124"></a>00124       <span class="comment">/*continue;*/</span>
+<a name="l00125"></a>00125     }
+<a name="l00126"></a>00126 
+<a name="l00127"></a>00127   <span class="comment">/* No more roots found yet, do another iteration */</span>
+<a name="l00128"></a>00128 
+<a name="l00129"></a>00129   <span class="keywordflow">if</span> (iterations == 60)  <span class="comment">/* increased from 30 to 60 */</span>
+<a name="l00130"></a>00130     {
+<a name="l00131"></a>00131       <span class="comment">/* too many iterations - give up! */</span>
+<a name="l00132"></a>00132       cpl_msg_error(<span class="stringliteral">"qr:"</span>,<span class="stringliteral">"too many iterations-give up"</span>) ;
+<a name="l00133"></a>00133       <span class="keywordflow">return</span> -1 ;
+<a name="l00134"></a>00134     }
+<a name="l00135"></a>00135 
+<a name="l00136"></a>00136   <span class="keywordflow">if</span> (iterations % 10 == 0 && iterations > 0)
+<a name="l00137"></a>00137     {
+<a name="l00138"></a>00138       <span class="comment">/* use an exceptional shift */</span>
+<a name="l00139"></a>00139 
+<a name="l00140"></a>00140       t += x;
+<a name="l00141"></a>00141 
+<a name="l00142"></a>00142       <span class="keywordflow">for</span> (i = 1; i <= n; i++)
+<a name="l00143"></a>00143     {
+<a name="l00144"></a>00144       FMAT (h, i, i, nc) -= x;
+<a name="l00145"></a>00145     }
+<a name="l00146"></a>00146 
+<a name="l00147"></a>00147       s = fabs (FMAT (h, n, n - 1, nc)) + fabs (FMAT (h, n - 1, n - 2, nc));
+<a name="l00148"></a>00148       y = 0.75 * s;
+<a name="l00149"></a>00149       x = y;
+<a name="l00150"></a>00150       w = -0.4375 * s * s;
+<a name="l00151"></a>00151     }
+<a name="l00152"></a>00152 
+<a name="l00153"></a>00153   iterations++;
+<a name="l00154"></a>00154 
+<a name="l00155"></a>00155   <span class="keywordflow">for</span> (m = n - 2; m >= e; m--)
+<a name="l00156"></a>00156     {
+<a name="l00157"></a>00157       <span class="keywordtype">double</span> a1, a2, a3;
+<a name="l00158"></a>00158 
+<a name="l00159"></a>00159       z = FMAT (h, m, m, nc);
+<a name="l00160"></a>00160       r = x - z;
+<a name="l00161"></a>00161       s = y - z;
+<a name="l00162"></a>00162       p = FMAT (h, m, m + 1, nc) + (r * s - w) / FMAT (h, m + 1, m, nc);
+<a name="l00163"></a>00163       q = FMAT (h, m + 1, m + 1, nc) - z - r - s;
+<a name="l00164"></a>00164       r = FMAT (h, m + 2, m + 1, nc);
+<a name="l00165"></a>00165       s = fabs (p) + fabs (q) + fabs (r);
+<a name="l00166"></a>00166       p /= s;
+<a name="l00167"></a>00167       q /= s;
+<a name="l00168"></a>00168       r /= s;
+<a name="l00169"></a>00169 
+<a name="l00170"></a>00170       <span class="keywordflow">if</span> (m == e)
+<a name="l00171"></a>00171     <span class="keywordflow">break</span>;
+<a name="l00172"></a>00172       
+<a name="l00173"></a>00173       a1 = fabs (FMAT (h, m, m - 1, nc));
+<a name="l00174"></a>00174       a2 = fabs (FMAT (h, m - 1, m - 1, nc));
+<a name="l00175"></a>00175       a3 = fabs (FMAT (h, m + 1, m + 1, nc));
+<a name="l00176"></a>00176 
+<a name="l00177"></a>00177       <span class="keywordflow">if</span> (a1 * (fabs (q) + fabs (r)) <= GSL_DBL_EPSILON * fabs (p) * (a2 + a3))
+<a name="l00178"></a>00178         <span class="keywordflow">break</span>;
+<a name="l00179"></a>00179     }
+<a name="l00180"></a>00180 
+<a name="l00181"></a>00181   <span class="keywordflow">for</span> (i = m + 2; i <= n; i++)
+<a name="l00182"></a>00182     {
+<a name="l00183"></a>00183       FMAT (h, i, i - 2, nc) = 0;
+<a name="l00184"></a>00184     }
+<a name="l00185"></a>00185 
+<a name="l00186"></a>00186   <span class="keywordflow">for</span> (i = m + 3; i <= n; i++)
+<a name="l00187"></a>00187     {
+<a name="l00188"></a>00188       FMAT (h, i, i - 3, nc) = 0;
+<a name="l00189"></a>00189     }
+<a name="l00190"></a>00190 
+<a name="l00191"></a>00191   <span class="comment">/* double QR step */</span>
+<a name="l00192"></a>00192 
+<a name="l00193"></a>00193   <span class="keywordflow">for</span> (k = m; k <= n - 1; k++)
+<a name="l00194"></a>00194     {
+<a name="l00195"></a>00195       notlast = (k != n - 1);
+<a name="l00196"></a>00196 
+<a name="l00197"></a>00197       <span class="keywordflow">if</span> (k != m)
+<a name="l00198"></a>00198     {
+<a name="l00199"></a>00199       p = FMAT (h, k, k - 1, nc);
+<a name="l00200"></a>00200       q = FMAT (h, k + 1, k - 1, nc);
+<a name="l00201"></a>00201       r = notlast ? FMAT (h, k + 2, k - 1, nc) : 0.0;
+<a name="l00202"></a>00202 
+<a name="l00203"></a>00203       x = fabs (p) + fabs (q) + fabs (r);
+<a name="l00204"></a>00204 
+<a name="l00205"></a>00205       <span class="keywordflow">if</span> (x == 0)
+<a name="l00206"></a>00206         <span class="keywordflow">continue</span>;        <span class="comment">/* FIXME????? */</span>
+<a name="l00207"></a>00207 
+<a name="l00208"></a>00208       p /= x;
+<a name="l00209"></a>00209       q /= x;
+<a name="l00210"></a>00210       r /= x;
+<a name="l00211"></a>00211     }
+<a name="l00212"></a>00212 
+<a name="l00213"></a>00213       s = sqrt (p * p + q * q + r * r);
+<a name="l00214"></a>00214 
+<a name="l00215"></a>00215       <span class="keywordflow">if</span> (p < 0)
+<a name="l00216"></a>00216     s = -s;
+<a name="l00217"></a>00217 
+<a name="l00218"></a>00218       <span class="keywordflow">if</span> (k != m)
+<a name="l00219"></a>00219     {
+<a name="l00220"></a>00220       FMAT (h, k, k - 1, nc) = -s * x;
+<a name="l00221"></a>00221     }
+<a name="l00222"></a>00222       <span class="keywordflow">else</span> <span class="keywordflow">if</span> (e != m)
+<a name="l00223"></a>00223     {
+<a name="l00224"></a>00224       FMAT (h, k, k - 1, nc) *= -1;
+<a name="l00225"></a>00225     }
+<a name="l00226"></a>00226 
+<a name="l00227"></a>00227       p += s;
+<a name="l00228"></a>00228       x = p / s;
+<a name="l00229"></a>00229       y = q / s;
+<a name="l00230"></a>00230       z = r / s;
+<a name="l00231"></a>00231       q /= p;
+<a name="l00232"></a>00232       r /= p;
+<a name="l00233"></a>00233 
+<a name="l00234"></a>00234       <span class="comment">/* do row modifications */</span>
+<a name="l00235"></a>00235 
+<a name="l00236"></a>00236       <span class="keywordflow">for</span> (j = k; j <= n; j++)
+<a name="l00237"></a>00237     {
+<a name="l00238"></a>00238       p = FMAT (h, k, j, nc) + q * FMAT (h, k + 1, j, nc);
+<a name="l00239"></a>00239 
+<a name="l00240"></a>00240       <span class="keywordflow">if</span> (notlast)
+<a name="l00241"></a>00241         {
+<a name="l00242"></a>00242           p += r * FMAT (h, k + 2, j, nc);
+<a name="l00243"></a>00243           FMAT (h, k + 2, j, nc) -= p * z;
+<a name="l00244"></a>00244         }
+<a name="l00245"></a>00245 
+<a name="l00246"></a>00246       FMAT (h, k + 1, j, nc) -= p * y;
+<a name="l00247"></a>00247       FMAT (h, k, j, nc) -= p * x;
+<a name="l00248"></a>00248     }
+<a name="l00249"></a>00249 
+<a name="l00250"></a>00250       j = (k + 3 < n) ? (k + 3) : n;
+<a name="l00251"></a>00251 
+<a name="l00252"></a>00252       <span class="comment">/* do column modifications */</span>
+<a name="l00253"></a>00253 
+<a name="l00254"></a>00254       <span class="keywordflow">for</span> (i = e; i <= j; i++)
+<a name="l00255"></a>00255     {
+<a name="l00256"></a>00256       p = x * FMAT (h, i, k, nc) + y * FMAT (h, i, k + 1, nc);
+<a name="l00257"></a>00257 
+<a name="l00258"></a>00258       <span class="keywordflow">if</span> (notlast)
+<a name="l00259"></a>00259         {
+<a name="l00260"></a>00260           p += z * FMAT (h, i, k + 2, nc);
+<a name="l00261"></a>00261           FMAT (h, i, k + 2, nc) -= p * r;
+<a name="l00262"></a>00262         }
+<a name="l00263"></a>00263       FMAT (h, i, k + 1, nc) -= p * q;
+<a name="l00264"></a>00264       FMAT (h, i, k, nc) -= p;
+<a name="l00265"></a>00265     }
+<a name="l00266"></a>00266     }
+<a name="l00267"></a>00267 
+<a name="l00268"></a>00268   <span class="keywordflow">goto</span> next_iteration;
+<a name="l00269"></a>00269 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__raw__types_8h_source.html b/html/sinfo__raw__types_8h_source.html
new file mode 100644
index 0000000..9a1ce58
--- /dev/null
+++ b/html/sinfo__raw__types_8h_source.html
@@ -0,0 +1,129 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_raw_types.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_raw_types.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_raw_types.h,v 1.5 2008/07/04 13:06:02 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the SINFONI Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This proram is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2008/07/04 13:06:02 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.5 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifndef SINFO_RAW_TYPES_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_RAW_TYPES_H</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span>
+<a name="l00031"></a>00031 <span class="comment">/*------------------------------------------------------------------------</span>
+<a name="l00032"></a>00032 <span class="comment">                                   Raw TYPES</span>
+<a name="l00033"></a>00033 <span class="comment"> --------------------------------------------------------------------------*/</span>
+<a name="l00034"></a>00034 
+<a name="l00035"></a>00035 <span class="comment">/*------------------------------------------------------------------------</span>
+<a name="l00036"></a>00036 <span class="comment">                                   Raw Frames</span>
+<a name="l00037"></a>00037 <span class="comment"> --------------------------------------------------------------------------*/</span>
+<a name="l00038"></a>00038 CPL_BEGIN_DECLS
+<a name="l00039"></a>00039 
+<a name="l00040"></a>00040 <span class="preprocessor">#define RAW_LINEARITY_LAMP                 "LINEARITY_LAMP"</span>
+<a name="l00041"></a>00041 <span class="preprocessor"></span><span class="preprocessor">#define RAW_DARK                           "DARK"</span>
+<a name="l00042"></a>00042 <span class="preprocessor"></span>
+<a name="l00043"></a>00043 <span class="preprocessor">#define RAW_PINHOLE_LAMP                   "PINHOLE_LAMP"</span>
+<a name="l00044"></a>00044 <span class="preprocessor"></span><span class="preprocessor">#define RAW_SLIT_LAMP                      "SLIT_LAMP"      </span><span class="comment">/* ?? */</span>
+<a name="l00045"></a>00045 <span class="preprocessor">#define RAW_FIBRE_PSF                      "FIBRE_PSF"    </span>
+<a name="l00046"></a>00046 <span class="preprocessor"></span><span class="preprocessor">#define RAW_FIBRE_DARK                     "FIBRE_DARK"    </span>
+<a name="l00047"></a>00047 <span class="preprocessor"></span><span class="preprocessor">#define RAW_FIBRE_LAMP                     "FIBRE_LAMP"    </span>
+<a name="l00048"></a>00048 <span class="preprocessor"></span><span class="preprocessor">#define RAW_FIBRE_NS                       "FIBRE_NS"      </span>
+<a name="l00049"></a>00049 <span class="preprocessor"></span><span class="preprocessor">#define RAW_FIBRE_EW                       "FIBRE_EW"      </span>
+<a name="l00050"></a>00050 <span class="preprocessor"></span><span class="preprocessor">#define RAW_WAVE_LAMP                      "WAVE_LAMP"</span>
+<a name="l00051"></a>00051 <span class="preprocessor"></span><span class="preprocessor">#define RAW_WAVE_LAMP_DITHER               "WAVE_LAMP_DITHER"</span>
+<a name="l00052"></a>00052 <span class="preprocessor"></span><span class="preprocessor">#define RAW_WAVE_NS                        "WAVE_NS"</span>
+<a name="l00053"></a>00053 <span class="preprocessor"></span><span class="preprocessor">#define RAW_WAVE_NS_DITHER                 "WAVE_NS_DITHER"</span>
+<a name="l00054"></a>00054 <span class="preprocessor"></span>
+<a name="l00055"></a>00055 <span class="preprocessor">#define RAW_FLAT_LAMP                      "FLAT_LAMP"</span>
+<a name="l00056"></a>00056 <span class="preprocessor"></span><span class="preprocessor">#define RAW_FLAT_LAMP_DITHER               "FLAT_LAMP_DITHER"</span>
+<a name="l00057"></a>00057 <span class="preprocessor"></span><span class="preprocessor">#define RAW_FLAT_NS                        "FLAT_NS"</span>
+<a name="l00058"></a>00058 <span class="preprocessor"></span><span class="preprocessor">#define RAW_FLAT_NS_DITHER                 "FLAT_NS_DITHER"</span>
+<a name="l00059"></a>00059 <span class="preprocessor"></span><span class="preprocessor">#define RAW_FLAT_SKY                       "FLAT_SKY"</span>
+<a name="l00060"></a>00060 <span class="preprocessor"></span><span class="preprocessor">#define RAW_FLUX_LAMP                      "FLUX_LAMP"</span>
+<a name="l00061"></a>00061 <span class="preprocessor"></span><span class="preprocessor">#define RAW_PSF_CALIBRATOR                 "PSF_CALIBRATOR"</span>
+<a name="l00062"></a>00062 <span class="preprocessor"></span><span class="preprocessor">#define RAW_FOCUS                          "FOCUS"</span>
+<a name="l00063"></a>00063 <span class="preprocessor"></span><span class="preprocessor">#define RAW_SKY_DUMMY                      "SKY_DUMMY"</span>
+<a name="l00064"></a>00064 <span class="preprocessor"></span>
+<a name="l00065"></a>00065 <span class="preprocessor">#define RAW_PUPIL_LAMP                     "PUPIL_LAMP"</span>
+<a name="l00066"></a>00066 <span class="preprocessor"></span><span class="preprocessor">#define RAW_OBJECT                         "OBJECT"</span>
+<a name="l00067"></a>00067 <span class="preprocessor"></span><span class="preprocessor">#define RAW_IMAGE_PRE_OBJECT               "IMAGE_PRE_OBJECT"</span>
+<a name="l00068"></a>00068 <span class="preprocessor"></span><span class="preprocessor">#define RAW_IMAGE_PRE_SKY                  "IMAGE_PRE_SKY"</span>
+<a name="l00069"></a>00069 <span class="preprocessor"></span><span class="preprocessor">#define RAW_OBJECT_SKYSPIDER               "OBJECT_SKYSPIDER"</span>
+<a name="l00070"></a>00070 <span class="preprocessor"></span><span class="preprocessor">#define RAW_OBJECT_SKYSPIDER_DITHER        "OBJECT_SKYSPIDER_DITHER"</span>
+<a name="l00071"></a>00071 <span class="preprocessor"></span>
+<a name="l00072"></a>00072 <span class="preprocessor">#define RAW_OBJECT_NODDING                 "OBJECT_NODDING"</span>
+<a name="l00073"></a>00073 <span class="preprocessor"></span><span class="preprocessor">#define RAW_SKY_NODDING                    "SKY_NODDING"</span>
+<a name="l00074"></a>00074 <span class="preprocessor"></span><span class="preprocessor">#define RAW_OBJECT_JITTER                  "OBJECT_JITTER"</span>
+<a name="l00075"></a>00075 <span class="preprocessor"></span><span class="preprocessor">#define RAW_SKY_JITTER                     "SKY_JITTER"</span>
+<a name="l00076"></a>00076 <span class="preprocessor"></span><span class="preprocessor">#define RAW_OBJECT_NODDING_DITHER          "OBJECT_NODDING_DITHER"</span>
+<a name="l00077"></a>00077 <span class="preprocessor"></span><span class="preprocessor">#define RAW_OBJECT_JITTER_DITHER           "OBJECT_JITTER_DITHER"</span>
+<a name="l00078"></a>00078 <span class="preprocessor"></span><span class="preprocessor">#define RAW_SKY_NODDING_DITHER             "SKY_NODDING_DITHER"</span>
+<a name="l00079"></a>00079 <span class="preprocessor"></span><span class="preprocessor">#define RAW_SKY_JITTER_DITHER              "SKY_JITTER_DITHER"</span>
+<a name="l00080"></a>00080 <span class="preprocessor"></span>
+<a name="l00081"></a>00081 
+<a name="l00082"></a>00082 <span class="preprocessor">#define RAW_ACQUISITION_SKY                "ACQUISITION_SKY"</span>
+<a name="l00083"></a>00083 <span class="preprocessor"></span><span class="preprocessor">#define RAW_ACQUISITION_OBJECT             "ACQUISITION_OBJECT"</span>
+<a name="l00084"></a>00084 <span class="preprocessor"></span>
+<a name="l00085"></a>00085 
+<a name="l00086"></a>00086 <span class="preprocessor">#define RAW_STD                            "STD"</span>
+<a name="l00087"></a>00087 <span class="preprocessor"></span><span class="preprocessor">#define RAW_STACKED_SLITPOS                "STACKED_SLITPOS"</span>
+<a name="l00088"></a>00088 <span class="preprocessor"></span><span class="preprocessor">#define RAW_SKY_STD                        "SKY_STD"</span>
+<a name="l00089"></a>00089 <span class="preprocessor"></span><span class="preprocessor">#define RAW_SKY_OH                         "SKY_OH"</span>
+<a name="l00090"></a>00090 <span class="preprocessor"></span><span class="preprocessor">#define RAW_SKY_PSF_CALIBRATOR             "SKY_PSF_CALIBRATOR"</span>
+<a name="l00091"></a>00091 <span class="preprocessor"></span><span class="preprocessor">#define RAW_STD_STAR                       "STD_STAR"</span>
+<a name="l00092"></a>00092 <span class="preprocessor"></span><span class="preprocessor">#define RAW_STD_STAR_DITHER                "STD_STAR_DITHER"</span>
+<a name="l00093"></a>00093 <span class="preprocessor"></span>
+<a name="l00094"></a>00094 <span class="preprocessor">#define SINFO_UTL_STDSTARS_RAW             "STDSTAR_CAT"</span>
+<a name="l00095"></a>00095 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_UTL_SEDS_RAW                 "SED"</span>
+<a name="l00096"></a>00096 <span class="preprocessor"></span>
+<a name="l00097"></a>00097 <span class="comment">/* next are TBD */</span>
+<a name="l00098"></a>00098 <span class="preprocessor">#define RAW_OFF                            "RAW_OFF"</span>
+<a name="l00099"></a>00099 <span class="preprocessor"></span><span class="preprocessor">#define RAW_OFF1                           "OFF1"</span>
+<a name="l00100"></a>00100 <span class="preprocessor"></span><span class="preprocessor">#define RAW_OFF2                           "OFF2"</span>
+<a name="l00101"></a>00101 <span class="preprocessor"></span>
+<a name="l00102"></a>00102 <span class="preprocessor">#define RAW_SKY                            "SKY"</span>
+<a name="l00103"></a>00103 <span class="preprocessor"></span><span class="preprocessor">#define RAW_SKY1                           "SKY1"</span>
+<a name="l00104"></a>00104 <span class="preprocessor"></span><span class="preprocessor">#define RAW_SKY2                           "SKY2"</span>
+<a name="l00105"></a>00105 <span class="preprocessor"></span>
+<a name="l00106"></a>00106 <span class="preprocessor">#define RAW_ON                             "RAW_ON"</span>
+<a name="l00107"></a>00107 <span class="preprocessor"></span><span class="preprocessor">#define RAW_ON1                            "ON1"</span>
+<a name="l00108"></a>00108 <span class="preprocessor"></span><span class="preprocessor">#define RAW_ON2                            "ON2"</span>
+<a name="l00109"></a>00109 <span class="preprocessor"></span><span class="preprocessor">#define RAW_INT_ON                         "INT_ON"</span>
+<a name="l00110"></a>00110 <span class="preprocessor"></span><span class="preprocessor">#define RAW_INT_OFF                        "INT_OFF"</span>
+<a name="l00111"></a>00111 <span class="preprocessor"></span>CPL_END_DECLS
+<a name="l00112"></a>00112 
+<a name="l00113"></a>00113 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__rec__detlin_8c_source.html b/html/sinfo__rec__detlin_8c_source.html
new file mode 100644
index 0000000..83d66f1
--- /dev/null
+++ b/html/sinfo__rec__detlin_8c_source.html
@@ -0,0 +1,268 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_rec_detlin.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_rec_detlin.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_rec_detlin.c,v 1.21 2008/02/04 17:23:02 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the SINFONI Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2008/02/04 17:23:02 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.21 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00031"></a>00031 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00034"></a>00034  <span class="comment">/****************************************************************</span>
+<a name="l00035"></a>00035 <span class="comment">  *           Bad pixel search  (normal method)                  *</span>
+<a name="l00036"></a>00036 <span class="comment">  ****************************************************************/</span>
+<a name="l00037"></a>00037 
+<a name="l00038"></a>00038 <span class="comment">/* --------------------------------------------------------------- </span>
+<a name="l00039"></a>00039 <span class="comment">                         INCLUDES</span>
+<a name="l00040"></a>00040 <span class="comment">   --------------------------------------------------------------- */</span>
+<a name="l00041"></a>00041 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00042"></a>00042 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>
+<a name="l00043"></a>00043 <span class="preprocessor">#endif</span>
+<a name="l00044"></a>00044 <span class="preprocessor"></span>
+<a name="l00045"></a>00045 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00046"></a>00046 <span class="comment">                                Includes</span>
+<a name="l00047"></a>00047 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00048"></a>00048 
+<a name="l00049"></a>00049 <span class="comment">/* std libraries */</span>
+<a name="l00050"></a>00050 <span class="preprocessor">#include <strings.h></span>
+<a name="l00051"></a>00051 <span class="preprocessor">#include <string.h></span>
+<a name="l00052"></a>00052 <span class="preprocessor">#include <stdio.h></span>
+<a name="l00053"></a>00053 
+<a name="l00054"></a>00054 <span class="comment">/* cpl */</span>
+<a name="l00055"></a>00055 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00056"></a>00056 
+<a name="l00057"></a>00057 <span class="comment">/* irplib */</span>
+<a name="l00058"></a>00058 <span class="preprocessor">#include <irplib_utils.h></span>
+<a name="l00059"></a>00059 
+<a name="l00060"></a>00060 
+<a name="l00061"></a>00061 <span class="comment">/* sinfoni */</span>
+<a name="l00062"></a>00062 <span class="preprocessor">#include <sinfo_utilities.h></span>
+<a name="l00063"></a>00063 <span class="preprocessor">#include <sinfo_general_config.h></span>
+<a name="l00064"></a>00064 <span class="preprocessor">#include <sinfo_bp_lin_config.h></span>
+<a name="l00065"></a>00065 <span class="preprocessor">#include <sinfo_bp_config.h></span>
+<a name="l00066"></a>00066 <span class="preprocessor">#include <sinfo_bp_lin.h></span>
+<a name="l00067"></a>00067 <span class="preprocessor">#include <sinfo_product_config.h></span>
+<a name="l00068"></a>00068 
+<a name="l00069"></a>00069 <span class="preprocessor">#include <sinfo_bp_lin.h></span> 
+<a name="l00070"></a>00070 <span class="preprocessor">#include <sinfo_tpl_utils.h></span>
+<a name="l00071"></a>00071 <span class="preprocessor">#include <sinfo_functions.h></span>
+<a name="l00072"></a>00072 <span class="preprocessor">#include <sinfo_tpl_dfs.h></span>
+<a name="l00073"></a>00073 <span class="preprocessor">#include <sinfo_msg.h></span>
+<a name="l00074"></a>00074 <span class="preprocessor">#include <sinfo_error.h></span>
+<a name="l00075"></a>00075 <span class="preprocessor">#include <sinfo_utils_wrappers.h></span>
+<a name="l00076"></a>00076 
+<a name="l00077"></a>00077 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00078"></a>00078 <span class="comment">                            Functions prototypes</span>
+<a name="l00079"></a>00079 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00080"></a>00080 
+<a name="l00081"></a>00081 
+<a name="l00082"></a>00082 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_detlin_create(cpl_plugin *plugin);
+<a name="l00083"></a>00083 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_detlin_exec(cpl_plugin *plugin);
+<a name="l00084"></a>00084 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_detlin_destroy(cpl_plugin *plugin);
+<a name="l00085"></a>00085 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_detlin(cpl_parameterlist *, cpl_frameset *);
+<a name="l00086"></a>00086 
+<a name="l00087"></a>00087 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00088"></a>00088 <span class="comment">                            Static variables</span>
+<a name="l00089"></a>00089 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00090"></a>00090 
+<a name="l00091"></a>00091 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_rec_detlin_description[] =
+<a name="l00092"></a>00092 <span class="stringliteral">"This recipe computes detector non linearities and a bad pixel map.\n"</span>
+<a name="l00093"></a>00093 <span class="stringliteral">"The input files are increasing intensity raw flats\n"</span>
+<a name="l00094"></a>00094 <span class="stringliteral">"their associated tags should be LINEARITY_LAMP.\n"</span>
+<a name="l00095"></a>00095 <span class="stringliteral">"The output are: \n"</span>
+<a name="l00096"></a>00096 <span class="stringliteral">"A table (PRO.CATG=LIN_DET_INFO) with information \n"</span>
+<a name="l00097"></a>00097 <span class="stringliteral">"on the detector non linearities\n"</span>
+<a name="l00098"></a>00098 <span class="stringliteral">"A table (PRO.CATG=GAIN_INFO) with information on the detector gain\n"</span>
+<a name="l00099"></a>00099 <span class="stringliteral">"A cube (PRO.CATG=BP_COEFF) with the polynomial fit parameters \n"</span>
+<a name="l00100"></a>00100 <span class="stringliteral">"of the detector non linearities\n"</span>
+<a name="l00101"></a>00101 <span class="stringliteral">"A bad pixel map (PRO.CATG=BP_MAP_NL)\n"</span>
+<a name="l00102"></a>00102 <span class="stringliteral">"Information on relevant parameters can be found with\n"</span>
+<a name="l00103"></a>00103 <span class="stringliteral">"esorex --params sinfo_rec_detlin\n"</span>
+<a name="l00104"></a>00104 <span class="stringliteral">"esorex --help sinfo_rec_detlin\n"</span>
+<a name="l00105"></a>00105 <span class="stringliteral">"\n"</span>;
+<a name="l00106"></a>00106 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00107"></a>00107 <span class="comment">                                Functions code</span>
+<a name="l00108"></a>00108 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00109"></a>00109 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00118"></a>00118 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00119"></a>00119 
+<a name="l00120"></a>00120 
+<a name="l00121"></a><a class="code" href="group__sinfo__rec__detlin.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693">00121</a> <span class="keywordtype">int</span> <a class="code" href="group__sinfo__rec__detlin.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693" title="Build the list of available plugins, for this module.">cpl_plugin_get_info</a>(cpl_pluginlist *list)
+<a name="l00122"></a>00122 {
+<a name="l00123"></a>00123 
+<a name="l00124"></a>00124   cpl_recipe *recipe = cpl_calloc(1, <span class="keyword">sizeof</span> *recipe);
+<a name="l00125"></a>00125   cpl_plugin *plugin = &recipe->interface;
+<a name="l00126"></a>00126 
+<a name="l00127"></a>00127 
+<a name="l00128"></a>00128   cpl_plugin_init(plugin,
+<a name="l00129"></a>00129           CPL_PLUGIN_API,
+<a name="l00130"></a>00130           SINFONI_BINARY_VERSION,
+<a name="l00131"></a>00131           CPL_PLUGIN_TYPE_RECIPE,
+<a name="l00132"></a>00132           <span class="stringliteral">"sinfo_rec_detlin"</span>,
+<a name="l00133"></a>00133           <span class="stringliteral">"Detector's linearity & non linear bad pixels determination."</span>,
+<a name="l00134"></a>00134           sinfo_rec_detlin_description,
+<a name="l00135"></a>00135           <span class="stringliteral">"Andrea Modigliani"</span>,
+<a name="l00136"></a>00136           <span class="stringliteral">"Andrea.Modigliani at eso.org"</span>,
+<a name="l00137"></a>00137           sinfo_get_license(),
+<a name="l00138"></a>00138           sinfo_rec_detlin_create,
+<a name="l00139"></a>00139           sinfo_rec_detlin_exec,
+<a name="l00140"></a>00140           sinfo_rec_detlin_destroy);
+<a name="l00141"></a>00141 
+<a name="l00142"></a>00142   cpl_pluginlist_append(list, plugin);
+<a name="l00143"></a>00143 
+<a name="l00144"></a>00144   <span class="keywordflow">return</span> 0;
+<a name="l00145"></a>00145 
+<a name="l00146"></a>00146 }
+<a name="l00147"></a>00147 
+<a name="l00148"></a>00148 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00156"></a>00156 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00157"></a>00157 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_detlin_create(cpl_plugin *plugin)
+<a name="l00158"></a>00158 {
+<a name="l00159"></a>00159 
+<a name="l00160"></a>00160   <span class="comment">/*</span>
+<a name="l00161"></a>00161 <span class="comment">   * We have to provide the option we accept to the application.</span>
+<a name="l00162"></a>00162 <span class="comment">   * We need to setup our parameter list and hook it into the recipe</span>
+<a name="l00163"></a>00163 <span class="comment">   * interface.</span>
+<a name="l00164"></a>00164 <span class="comment">   */</span>
+<a name="l00165"></a>00165 
+<a name="l00166"></a>00166 
+<a name="l00167"></a>00167     cpl_recipe      * recipe ;
+<a name="l00168"></a>00168 
+<a name="l00169"></a>00169     <span class="comment">/* Check that the plugin is part of a valid recipe */</span>
+<a name="l00170"></a>00170     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00171"></a>00171         recipe = (cpl_recipe *)plugin ;
+<a name="l00172"></a>00172     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00173"></a>00173 
+<a name="l00174"></a>00174     cpl_error_reset();
+<a name="l00175"></a>00175     <a class="code" href="group__irplib__utils.html#gaf9d392144014e2363054bc3f83c8e47e" title="Reset IRPLIB state.">irplib_reset</a>();
+<a name="l00176"></a>00176     <span class="comment">/* Create the parameters list in the cpl_recipe object */</span>
+<a name="l00177"></a>00177     recipe->parameters = cpl_parameterlist_new() ; 
+<a name="l00178"></a>00178 
+<a name="l00179"></a>00179     sinfo_general_config_add(recipe->parameters);
+<a name="l00180"></a>00180     sinfo_product_config_add(recipe->parameters);
+<a name="l00181"></a>00181     sinfo_bp_lin_config_add(recipe->parameters); 
+<a name="l00182"></a>00182   
+<a name="l00183"></a>00183     <span class="keywordflow">return</span> 0;
+<a name="l00184"></a>00184 
+<a name="l00185"></a>00185 }
+<a name="l00186"></a>00186 
+<a name="l00187"></a>00187 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00193"></a>00193 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00194"></a>00194 
+<a name="l00195"></a>00195 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_detlin_exec(cpl_plugin *plugin)
+<a name="l00196"></a>00196 {
+<a name="l00197"></a>00197      cpl_recipe  *   recipe ;
+<a name="l00198"></a>00198     
+<a name="l00199"></a>00199     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00200"></a>00200     cpl_errorstate initial_errorstate = cpl_errorstate_get();
+<a name="l00201"></a>00201 
+<a name="l00202"></a>00202     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00203"></a>00203         recipe = (cpl_recipe *)plugin ;
+<a name="l00204"></a>00204     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00205"></a>00205   
+<a name="l00206"></a>00206     <span class="keywordflow">if</span> (!cpl_errorstate_is_equal(initial_errorstate)) {                      
+<a name="l00207"></a>00207         <span class="comment">/* Dump the error history since recipe execution start.                </span>
+<a name="l00208"></a>00208 <span class="comment">           At this point the recipe cannot recover from the error */</span>           
+<a name="l00209"></a>00209         cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);              
+<a name="l00210"></a>00210     } 
+<a name="l00211"></a>00211 
+<a name="l00212"></a>00212   <span class="keywordflow">return</span> sinfo_rec_detlin(recipe->parameters, recipe->frames);
+<a name="l00213"></a>00213 
+<a name="l00214"></a>00214 }
+<a name="l00215"></a>00215 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00221"></a>00221 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00222"></a>00222 
+<a name="l00223"></a>00223 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_detlin_destroy(cpl_plugin *plugin)
+<a name="l00224"></a>00224 {
+<a name="l00225"></a>00225      cpl_recipe  *   recipe ;
+<a name="l00226"></a>00226     
+<a name="l00227"></a>00227     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00228"></a>00228     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00229"></a>00229         recipe = (cpl_recipe *)plugin ;
+<a name="l00230"></a>00230     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00231"></a>00231 
+<a name="l00232"></a>00232     cpl_parameterlist_delete(recipe->parameters) ; 
+<a name="l00233"></a>00233 
+<a name="l00234"></a>00234   <span class="keywordflow">return</span> 0;
+<a name="l00235"></a>00235 
+<a name="l00236"></a>00236 }
+<a name="l00237"></a>00237 
+<a name="l00238"></a>00238 <span class="comment">/*</span>
+<a name="l00239"></a>00239 <span class="comment"> * The actual recipe actually start here.</span>
+<a name="l00240"></a>00240 <span class="comment"> */</span>
+<a name="l00241"></a>00241 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00262"></a>00262 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00263"></a>00263 
+<a name="l00264"></a>00264 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_detlin(cpl_parameterlist *config, cpl_frameset *<span class="keyword">set</span>)
+<a name="l00265"></a>00265 {
+<a name="l00266"></a>00266   cpl_parameter *p=NULL;          
+<a name="l00267"></a>00267   <span class="keywordtype">int</span> line_cor=0;
+<a name="l00268"></a>00268 
+<a name="l00269"></a>00269   sinfo_msg(<span class="stringliteral">"Welcome to SINFONI Pipeline release %d.%d.%d"</span>,
+<a name="l00270"></a>00270         SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
+<a name="l00271"></a>00271   <span class="comment">/* Hidden parameters */</span>
+<a name="l00272"></a>00272   <span class="comment">/* name of the data cube storing the found polynomial coefficients */</span>
+<a name="l00273"></a>00273   sinfo_bp_config_add(config);  
+<a name="l00274"></a>00274   check_nomsg(p = cpl_parameterlist_find(config,<span class="stringliteral">"sinfoni.bp.method"</span>));
+<a name="l00275"></a>00275   check_nomsg(cpl_parameter_set_string(p,<span class="stringliteral">"Linear"</span>));   
+<a name="l00276"></a>00276 
+<a name="l00277"></a>00277   ck0(sinfo_dfs_set_groups(<span class="keyword">set</span>),<span class="stringliteral">"Cannot indentify RAW and CALIB frames"</span>) ;
+<a name="l00278"></a>00278 
+<a name="l00279"></a>00279   check_nomsg(p=cpl_parameterlist_find(config, <span class="stringliteral">"sinfoni.general.lc_sw"</span>));
+<a name="l00280"></a>00280   check_nomsg(line_cor=cpl_parameter_get_bool(p));
+<a name="l00281"></a>00281   <span class="keywordflow">if</span>(line_cor==1) {
+<a name="l00282"></a>00282      check_nomsg(sinfo_ima_line_cor(config,<span class="keyword">set</span>));
+<a name="l00283"></a>00283   }
+<a name="l00284"></a>00284 
+<a name="l00285"></a>00285 
+<a name="l00286"></a>00286   sinfo_msg(<span class="stringliteral">"---------------------------------------"</span>);
+<a name="l00287"></a>00287   sinfo_msg(<span class="stringliteral">"BP_MAP_NL BAD PIXEL MAP DETERMINATION  "</span>);
+<a name="l00288"></a>00288   sinfo_msg(<span class="stringliteral">"---------------------------------------"</span>);
+<a name="l00289"></a>00289   ck0(sinfo_new_bp_search_lin(cpl_func,config,<span class="keyword">set</span>),
+<a name="l00290"></a>00290     <span class="stringliteral">"BP_MAP_NL BAD PIXEL MAP DETERMINATION FAILED"</span>) ;
+<a name="l00291"></a>00291   sinfo_msg(<span class="stringliteral">"BP_MAP_NL BAD PIXEL MAP DETERMINATION SUCCESS"</span>) ;
+<a name="l00292"></a>00292 
+<a name="l00293"></a>00293  cleanup:
+<a name="l00294"></a>00294 
+<a name="l00295"></a>00295   <span class="keywordflow">if</span> (cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l00296"></a>00296     <span class="keywordflow">return</span> -1;
+<a name="l00297"></a>00297   } <span class="keywordflow">else</span> {
+<a name="l00298"></a>00298     <span class="keywordflow">return</span> 0;
+<a name="l00299"></a>00299   }
+<a name="l00300"></a>00300 
+<a name="l00301"></a>00301 }
+<a name="l00302"></a>00302 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__rec__distortion_8c_source.html b/html/sinfo__rec__distortion_8c_source.html
new file mode 100644
index 0000000..a8199d3
--- /dev/null
+++ b/html/sinfo__rec__distortion_8c_source.html
@@ -0,0 +1,828 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_rec_distortion.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_rec_distortion.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_rec_distortion.c,v 1.42 2011/11/16 13:36:19 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the SINFONI Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2011/11/16 13:36:19 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.42 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028  <span class="comment">/****************************************************************</span>
+<a name="l00029"></a>00029 <span class="comment">  *          Distortions Frames Data Reduction                          *</span>
+<a name="l00030"></a>00030 <span class="comment">  ****************************************************************/</span>
+<a name="l00031"></a>00031 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00032"></a>00032 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>          <span class="comment">/* allows the program compilation */</span>
+<a name="l00033"></a>00033 <span class="preprocessor">#endif</span>
+<a name="l00034"></a>00034 <span class="preprocessor"></span>
+<a name="l00035"></a>00035 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00036"></a>00036 <span class="comment">                                Includes</span>
+<a name="l00037"></a>00037 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00038"></a>00038 <span class="comment">/* std */</span>
+<a name="l00039"></a>00039 <span class="preprocessor">#include <strings.h></span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include <string.h></span>
+<a name="l00041"></a>00041 
+<a name="l00042"></a>00042 <span class="preprocessor">#include <stdio.h></span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include <math.h></span>
+<a name="l00044"></a>00044 
+<a name="l00045"></a>00045 <span class="comment">/* cpl */</span>       
+<a name="l00046"></a>00046 <span class="preprocessor">#include <cpl.h></span>       
+<a name="l00047"></a>00047 
+<a name="l00048"></a>00048 <span class="comment">/* irplib */</span>
+<a name="l00049"></a>00049 <span class="preprocessor">#include <irplib_utils.h></span>
+<a name="l00050"></a>00050 
+<a name="l00051"></a>00051 <span class="preprocessor">#include <sinfo_hidden.h></span>
+<a name="l00052"></a>00052 <span class="preprocessor">#include <sinfo_pro_types.h></span>
+<a name="l00053"></a>00053 <span class="preprocessor">#include <sinfo_raw_types.h></span>
+<a name="l00054"></a>00054 <span class="preprocessor">#include <sinfo_key_names.h></span>
+<a name="l00055"></a>00055 
+<a name="l00056"></a>00056 <span class="preprocessor">#include <sinfo_globals.h></span>
+<a name="l00057"></a>00057 <span class="preprocessor">#include <sinfo_general_config.h></span>
+<a name="l00058"></a>00058 <span class="preprocessor">#include <sinfo_utilities.h></span>
+<a name="l00059"></a>00059 <span class="preprocessor">#include <sinfo_product_config.h></span>
+<a name="l00060"></a>00060 <span class="preprocessor">#include <sinfo_lamp_flats_config.h></span>
+<a name="l00061"></a>00061 <span class="preprocessor">#include <sinfo_bp_config.h></span>
+<a name="l00062"></a>00062 <span class="preprocessor">#include <sinfo_bp_dist_config.h></span>
+<a name="l00063"></a>00063 <span class="preprocessor">#include <sinfo_prepare_stacked_frames_config.h></span>
+<a name="l00064"></a>00064 
+<a name="l00065"></a>00065 <span class="preprocessor">#include <sinfo_north_south_test_config.h></span>
+<a name="l00066"></a>00066 <span class="preprocessor">#include <sinfo_distortion_config.h></span>
+<a name="l00067"></a>00067 <span class="preprocessor">#include <sinfo_new_lamp_flats.h></span>
+<a name="l00068"></a>00068 <span class="preprocessor">#include <sinfo_bp_norm.h></span>
+<a name="l00069"></a>00069 <span class="preprocessor">#include <sinfo_new_prepare_stacked_frames.h></span>
+<a name="l00070"></a>00070 <span class="preprocessor">#include <sinfo_new_find_distortions.h></span>
+<a name="l00071"></a>00071 <span class="preprocessor">#include <sinfo_new_nst.h></span>
+<a name="l00072"></a>00072 
+<a name="l00073"></a>00073 <span class="preprocessor">#include <sinfo_functions.h></span>
+<a name="l00074"></a>00074 <span class="preprocessor">#include <sinfo_tpl_utils.h></span>
+<a name="l00075"></a>00075 <span class="preprocessor">#include <sinfo_tpl_dfs.h></span>
+<a name="l00076"></a>00076 <span class="preprocessor">#include <sinfo_msg.h></span>
+<a name="l00077"></a>00077 <span class="preprocessor">#include <sinfo_error.h></span>
+<a name="l00078"></a>00078 <span class="preprocessor">#include <sinfo_utils_wrappers.h></span>
+<a name="l00079"></a>00079 <span class="comment">//Only for sinfo_propertylist_has</span>
+<a name="l00080"></a>00080 <span class="preprocessor">#include <sinfo_dfs.h></span>
+<a name="l00081"></a>00081 
+<a name="l00082"></a>00082 
+<a name="l00083"></a>00083 
+<a name="l00084"></a>00084 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00085"></a>00085 <span class="comment">                            Functions prototypes</span>
+<a name="l00086"></a>00086 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00087"></a>00087 
+<a name="l00088"></a>00088 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_distortion_create(cpl_plugin *plugin);
+<a name="l00089"></a>00089 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_distortion_exec(cpl_plugin *plugin);
+<a name="l00090"></a>00090 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_distortion_destroy(cpl_plugin *plugin);
+<a name="l00091"></a>00091 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_distortion(cpl_parameterlist *config, cpl_frameset *<span class="keyword">set</span>);
+<a name="l00092"></a>00092 <span class="keyword">static</span> <span class="keywordtype">int</span> new_pre_process(cpl_frameset* <span class="keyword">set</span>, 
+<a name="l00093"></a>00093         <span class="keyword">const</span> <span class="keywordtype">float</span> lo_rej, <span class="keyword">const</span> <span class="keywordtype">float</span> hi_rej, <span class="keyword">const</span> <span class="keywordtype">char</span>* name_o);
+<a name="l00094"></a>00094 
+<a name="l00095"></a>00095 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00096"></a>00096 <span class="comment">                            Static variables</span>
+<a name="l00097"></a>00097 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00098"></a>00098 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_rec_distortion_description1[] =
+<a name="l00099"></a>00099 <span class="stringliteral">"This recipe determines the optical distortions and the slitlets distances.\n"</span>
+<a name="l00100"></a>00100 <span class="stringliteral">"Necessary input are:\n"</span>
+<a name="l00101"></a>00101 <span class="stringliteral">"Several (usually 75) raw frames classified as FIBRE_NS\n"</span>
+<a name="l00102"></a>00102 <span class="stringliteral">"Standard (an 'ON' and an 'OFF') flat frames having classified as FLAT_NS\n"</span>
+<a name="l00103"></a>00103 <span class="stringliteral">"Standard (an 'ON' and an 'OFF') arc lamp frames having classified as WAVE_NS\n"</span>
+<a name="l00104"></a>00104 <span class="stringliteral">"A corresponding (band) reference arc line list classified as REF_LINE_ARC\n"</span>
+<a name="l00105"></a>00105 <span class="stringliteral">"A reference table with data reduction parameters classified as DRS_SETUP_WAVE.\n"</span>;
+<a name="l00106"></a>00106 
+<a name="l00107"></a>00107 
+<a name="l00108"></a>00108 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_rec_distortion_description2[] =
+<a name="l00109"></a>00109 <span class="stringliteral">"Default output are (with their PRO.CATG)\n"</span>
+<a name="l00110"></a>00110 <span class="stringliteral">"A master flat: MASTER_FLAT_LAMP\n"</span>
+<a name="l00111"></a>00111 <span class="stringliteral">"A Bad pixel map: BP_MAP_DI\n"</span>
+<a name="l00112"></a>00112 <span class="stringliteral">"A fake-off fibre stacked frame: FIBRE_NS_STACKED_OFF\n"</span>
+<a name="l00113"></a>00113 <span class="stringliteral">"A fake-on fibre  stacked frame: FIBRE_NS_STACKED_ON\n"</span>
+<a name="l00114"></a>00114 <span class="stringliteral">"A fake on-off fibre  stacked frame: FIBRE_NS_STACKED\n"</span>
+<a name="l00115"></a>00115 <span class="stringliteral">"A table with optical distortion coefficients: DISTORTION\n"</span>;
+<a name="l00116"></a>00116 
+<a name="l00117"></a>00117 
+<a name="l00118"></a>00118 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_rec_distortion_description3[] =
+<a name="l00119"></a>00119 <span class="stringliteral">"A distortion corrected frame: FIBRE_NS_STACKED_DIST\n"</span>
+<a name="l00120"></a>00120 <span class="stringliteral">"A temporary frame: MASTER_SLIT\n"</span>
+<a name="l00121"></a>00121 <span class="stringliteral">"A table with the slitlets distances: SLITLETS_DISTANCE\n"</span>
+<a name="l00122"></a>00122 <span class="stringliteral">"Information on relevant parameters can be found with:\n"</span>
+<a name="l00123"></a>00123 <span class="stringliteral">"esorex --params sinfo_rec_distortion\n"</span>
+<a name="l00124"></a>00124 <span class="stringliteral">"esorex --help sinfo_rec_distortion\n"</span>
+<a name="l00125"></a>00125 <span class="stringliteral">"\n"</span>;
+<a name="l00126"></a>00126 
+<a name="l00127"></a>00127 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_rec_distortion_description[1300];
+<a name="l00128"></a>00128 
+<a name="l00129"></a>00129 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00130"></a>00130 <span class="comment">                                Functions code</span>
+<a name="l00131"></a>00131 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00132"></a>00132 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00136"></a>00136 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00138"></a>00138 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00147"></a>00147 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00148"></a>00148 <span class="keywordtype">int</span>
+<a name="l00149"></a><a class="code" href="group__sinfo__rec__distortion.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693">00149</a> <a class="code" href="group__sinfo__rec__detlin.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693" title="Build the list of available plugins, for this module.">cpl_plugin_get_info</a>(cpl_pluginlist *list)
+<a name="l00150"></a>00150 {
+<a name="l00151"></a>00151 
+<a name="l00152"></a>00152   cpl_recipe *recipe = cpl_calloc(1, <span class="keyword">sizeof</span> *recipe);
+<a name="l00153"></a>00153   cpl_plugin *plugin = &recipe->interface;
+<a name="l00154"></a>00154   strcpy(sinfo_rec_distortion_description,sinfo_rec_distortion_description1);
+<a name="l00155"></a>00155   strcat(sinfo_rec_distortion_description,sinfo_rec_distortion_description2);
+<a name="l00156"></a>00156   strcat(sinfo_rec_distortion_description,sinfo_rec_distortion_description3);
+<a name="l00157"></a>00157  
+<a name="l00158"></a>00158 
+<a name="l00159"></a>00159   cpl_plugin_init(plugin,
+<a name="l00160"></a>00160           CPL_PLUGIN_API,
+<a name="l00161"></a>00161           SINFONI_BINARY_VERSION,
+<a name="l00162"></a>00162           CPL_PLUGIN_TYPE_RECIPE,
+<a name="l00163"></a>00163           <span class="stringliteral">"sinfo_rec_distortion"</span>,
+<a name="l00164"></a>00164           <span class="stringliteral">"Finds optical distortions and slitlets distances"</span>,
+<a name="l00165"></a>00165           sinfo_rec_distortion_description,
+<a name="l00166"></a>00166           <span class="stringliteral">"Andrea Modigliani"</span>,
+<a name="l00167"></a>00167           <span class="stringliteral">"Andrea.Modigliani at eso.org"</span>,
+<a name="l00168"></a>00168           sinfo_get_license(),
+<a name="l00169"></a>00169           sinfo_rec_distortion_create,
+<a name="l00170"></a>00170           sinfo_rec_distortion_exec,
+<a name="l00171"></a>00171           sinfo_rec_distortion_destroy);
+<a name="l00172"></a>00172 
+<a name="l00173"></a>00173   cpl_pluginlist_append(list, plugin);
+<a name="l00174"></a>00174 
+<a name="l00175"></a>00175   <span class="keywordflow">return</span> 0;
+<a name="l00176"></a>00176 
+<a name="l00177"></a>00177 }
+<a name="l00178"></a>00178 
+<a name="l00179"></a>00179 
+<a name="l00180"></a>00180 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00188"></a>00188 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00189"></a>00189 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_distortion_create(cpl_plugin *plugin)
+<a name="l00190"></a>00190 {
+<a name="l00191"></a>00191     cpl_recipe      * recipe ;
+<a name="l00192"></a>00192 
+<a name="l00193"></a>00193     <span class="comment">/* Check that the plugin is part of a valid recipe */</span>
+<a name="l00194"></a>00194     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00195"></a>00195         recipe = (cpl_recipe *)plugin ;
+<a name="l00196"></a>00196     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00197"></a>00197     cpl_error_reset();
+<a name="l00198"></a>00198     <a class="code" href="group__irplib__utils.html#gaf9d392144014e2363054bc3f83c8e47e" title="Reset IRPLIB state.">irplib_reset</a>();
+<a name="l00199"></a>00199 
+<a name="l00200"></a>00200     <span class="comment">/* Create the parameters list in the cpl_recipe object */</span>
+<a name="l00201"></a>00201     recipe->parameters = cpl_parameterlist_new() ; 
+<a name="l00202"></a>00202 
+<a name="l00203"></a>00203 
+<a name="l00204"></a>00204   <span class="comment">/*</span>
+<a name="l00205"></a>00205 <span class="comment">   * Fill the parameter list.</span>
+<a name="l00206"></a>00206 <span class="comment">   */</span>
+<a name="l00207"></a>00207 
+<a name="l00208"></a>00208 
+<a name="l00209"></a>00209   <span class="comment">/* Output file name */</span>
+<a name="l00210"></a>00210   sinfo_general_config_add(recipe->parameters);
+<a name="l00211"></a>00211   sinfo_product_config_add(recipe->parameters);
+<a name="l00212"></a>00212   sinfo_lamp_flats_config_add(recipe->parameters);
+<a name="l00213"></a>00213   sinfo_bp_config_add(recipe->parameters);  
+<a name="l00214"></a>00214   <a class="code" href="group__sinfo__bad__pix__search.html#ga4f320ea65a00f127ece79fd2c6416a15" title="Adds parameters for the spectrum extraction.">sinfo_bp_dist_config_add</a>(recipe->parameters); 
+<a name="l00215"></a>00215   sinfo_prepare_stacked_frames_config_add(recipe->parameters);
+<a name="l00216"></a>00216   sinfo_distortion_config_add(recipe->parameters);
+<a name="l00217"></a>00217   sinfo_north_south_test_config_add(recipe->parameters);
+<a name="l00218"></a>00218   
+<a name="l00219"></a>00219 
+<a name="l00220"></a>00220   <span class="keywordflow">return</span> 0;
+<a name="l00221"></a>00221 
+<a name="l00222"></a>00222 }
+<a name="l00223"></a>00223 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00229"></a>00229 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00230"></a>00230 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_distortion_exec(cpl_plugin *plugin)
+<a name="l00231"></a>00231 {
+<a name="l00232"></a>00232     cpl_recipe  *   recipe ;
+<a name="l00233"></a>00233     <span class="keywordtype">int</span> status=0;
+<a name="l00234"></a>00234 
+<a name="l00235"></a>00235     cpl_errorstate initial_errorstate = cpl_errorstate_get();
+<a name="l00236"></a>00236 
+<a name="l00237"></a>00237     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00238"></a>00238     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00239"></a>00239         recipe = (cpl_recipe *)plugin ;
+<a name="l00240"></a>00240     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00241"></a>00241     status=sinfo_rec_distortion(recipe->parameters, recipe->frames);
+<a name="l00242"></a>00242 
+<a name="l00243"></a>00243     <span class="keywordflow">if</span> (!cpl_errorstate_is_equal(initial_errorstate)) {                      
+<a name="l00244"></a>00244         <span class="comment">/* Dump the error history since recipe execution start.                </span>
+<a name="l00245"></a>00245 <span class="comment">           At this point the recipe cannot recover from the error */</span>           
+<a name="l00246"></a>00246         cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);              
+<a name="l00247"></a>00247     } 
+<a name="l00248"></a>00248   <span class="keywordflow">return</span> status;
+<a name="l00249"></a>00249 
+<a name="l00250"></a>00250 }
+<a name="l00251"></a>00251 
+<a name="l00252"></a>00252 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00258"></a>00258 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00259"></a>00259 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_distortion_destroy(cpl_plugin *plugin)
+<a name="l00260"></a>00260 {
+<a name="l00261"></a>00261     cpl_recipe  *   recipe ;
+<a name="l00262"></a>00262     
+<a name="l00263"></a>00263     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00264"></a>00264     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00265"></a>00265         recipe = (cpl_recipe *)plugin ;
+<a name="l00266"></a>00266     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00267"></a>00267 
+<a name="l00268"></a>00268   cpl_parameterlist_delete(recipe->parameters);
+<a name="l00269"></a>00269 
+<a name="l00270"></a>00270   <span class="keywordflow">return</span> 0;
+<a name="l00271"></a>00271 
+<a name="l00272"></a>00272 }
+<a name="l00273"></a>00273 
+<a name="l00274"></a>00274 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00281"></a>00281 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00282"></a>00282 <span class="comment">/*</span>
+<a name="l00283"></a>00283 <span class="comment"> * The actual recipe actually start here.</span>
+<a name="l00284"></a>00284 <span class="comment"> */</span>
+<a name="l00285"></a>00285 
+<a name="l00286"></a>00286 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00287"></a>00287 sinfo_rec_distortion(cpl_parameterlist *config, cpl_frameset *<span class="keyword">set</span>)
+<a name="l00288"></a>00288 {
+<a name="l00289"></a>00289  
+<a name="l00290"></a>00290   cpl_parameter *p=NULL;
+<a name="l00291"></a>00291   cpl_frame* frame=NULL;
+<a name="l00292"></a>00292   cpl_propertylist* plist=NULL;
+<a name="l00293"></a>00293   cpl_image* ima=NULL;
+<a name="l00294"></a>00294   cpl_frameset* raw_set=NULL;
+<a name="l00295"></a>00295   cpl_frameset* set_off=NULL;
+<a name="l00296"></a>00296   cpl_frameset* set_on=NULL;
+<a name="l00297"></a>00297   cpl_frameset* set_fibre_ns=NULL;
+<a name="l00298"></a>00298   cpl_frameset* set_flat_ns=NULL;
+<a name="l00299"></a>00299   cpl_frameset* set_wave_ns=NULL;
+<a name="l00300"></a>00300   <span class="keywordtype">char</span> file_name[FILE_NAME_SZ];
+<a name="l00301"></a>00301 
+<a name="l00302"></a>00302   fake* fk=sinfo_fake_new();
+<a name="l00303"></a>00303   <span class="keywordtype">int</span> pdensity=0;
+<a name="l00304"></a>00304   <span class="keywordtype">int</span> line_cor=0;
+<a name="l00305"></a>00305 
+<a name="l00306"></a>00306   check_nomsg(p=cpl_parameterlist_find(config,<span class="stringliteral">"sinfoni.product.density"</span>));
+<a name="l00307"></a>00307   check_nomsg(pdensity=cpl_parameter_get_int(p));
+<a name="l00308"></a>00308 
+<a name="l00309"></a>00309 
+<a name="l00310"></a>00310   sinfo_msg(<span class="stringliteral">"Welcome to SINFONI Pipeline release %d.%d.%d"</span>,
+<a name="l00311"></a>00311         SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
+<a name="l00312"></a>00312   <span class="keywordflow">if</span>(sinfo_dfs_set_groups(<span class="keyword">set</span>)) {
+<a name="l00313"></a>00313     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Cannot indentify RAW and CALIB frames"</span>) ;
+<a name="l00314"></a>00314     <span class="keywordflow">return</span> -1;
+<a name="l00315"></a>00315   }
+<a name="l00316"></a>00316 
+<a name="l00317"></a>00317   check_nomsg(p=cpl_parameterlist_find(config, <span class="stringliteral">"sinfoni.general.lc_sw"</span>));
+<a name="l00318"></a>00318   check_nomsg(line_cor=cpl_parameter_get_bool(p));
+<a name="l00319"></a>00319   <span class="keywordflow">if</span>(line_cor==1) {
+<a name="l00320"></a>00320      check_nomsg(sinfo_ima_line_cor(config,<span class="keyword">set</span>));
+<a name="l00321"></a>00321   }
+<a name="l00322"></a>00322 
+<a name="l00323"></a>00323   cknull_nomsg(set_fibre_ns=sinfo_frameset_extract(<span class="keyword">set</span>,RAW_FIBRE_NS));
+<a name="l00324"></a>00324   cknull_nomsg(set_flat_ns=sinfo_frameset_extract(<span class="keyword">set</span>,RAW_FLAT_NS));
+<a name="l00325"></a>00325   cknull_nomsg(set_wave_ns=sinfo_frameset_extract(<span class="keyword">set</span>,RAW_WAVE_NS));
+<a name="l00326"></a>00326   check_nomsg(p=cpl_parameterlist_find(config,<span class="stringliteral">"sinfoni.bp.method"</span>));
+<a name="l00327"></a>00327   check_nomsg(cpl_parameter_set_string(p,<span class="stringliteral">"Normal"</span>));   
+<a name="l00328"></a>00328   check_nomsg(raw_set=cpl_frameset_duplicate(<span class="keyword">set</span>));
+<a name="l00329"></a>00329     
+<a name="l00330"></a>00330   sinfo_msg(<span class="stringliteral">"-----------------------------"</span>);
+<a name="l00331"></a>00331   sinfo_msg(<span class="stringliteral">"  DETERMINE MASTER_LAMP_NS "</span>);
+<a name="l00332"></a>00332   sinfo_msg(<span class="stringliteral">"-----------------------------"</span>);
+<a name="l00333"></a>00333 
+<a name="l00334"></a>00334   sinfo_msg(<span class="stringliteral">"REDUCE LAMPFLAT"</span>) ;    
+<a name="l00335"></a>00335   ck0(sinfo_new_lamp_flats(cpl_func,config, <span class="keyword">set</span>,set_flat_ns ),
+<a name="l00336"></a>00336       <span class="stringliteral">"reducing lampflats"</span>) ;
+<a name="l00337"></a>00337   sinfo_msg(<span class="stringliteral">"SUCCES: DETERMINATION MASTER_LAMP_NS"</span>) ; 
+<a name="l00338"></a>00338 
+<a name="l00339"></a>00339   sinfo_msg(<span class="stringliteral">"-----------------------------"</span>);
+<a name="l00340"></a>00340   sinfo_msg(<span class="stringliteral">"  DETERMINE BP_MAP_DI        "</span>);
+<a name="l00341"></a>00341   sinfo_msg(<span class="stringliteral">"-----------------------------"</span>);
+<a name="l00342"></a>00342   
+<a name="l00343"></a>00343   check_nomsg(p=cpl_parameterlist_find(config,<span class="stringliteral">"sinfoni.bp.method"</span>));
+<a name="l00344"></a>00344   check_nomsg(cpl_parameter_set_string(p,<span class="stringliteral">"Normal"</span>));   
+<a name="l00345"></a>00345        
+<a name="l00346"></a>00346   ck0(sinfo_new_bp_search_normal(cpl_func,config,<span class="keyword">set</span>,set_flat_ns,
+<a name="l00347"></a>00347                  PRO_BP_MAP_DI),
+<a name="l00348"></a>00348       <span class="stringliteral">"determining %s"</span>,PRO_BP_MAP_DI);
+<a name="l00349"></a>00349   sinfo_msg(<span class="stringliteral">"SUCCESS DETERMINATION %s"</span>,PRO_BP_MAP_DI);
+<a name="l00350"></a>00350   <span class="comment">/* </span>
+<a name="l00351"></a>00351 <span class="comment">       ---------------------------------------------------------</span>
+<a name="l00352"></a>00352 <span class="comment">        pre iteration: get a collassed frame </span>
+<a name="l00353"></a>00353 <span class="comment">       ---------------------------------------------------------</span>
+<a name="l00354"></a>00354 <span class="comment">   */</span>
+<a name="l00355"></a>00355 
+<a name="l00356"></a>00356    check_nomsg(set_off=cpl_frameset_duplicate(raw_set));
+<a name="l00357"></a>00357    ck0_nomsg(new_pre_process(set_off, 0.0, 0.2,<span class="stringliteral">"out_fibre_off.fits"</span>));
+<a name="l00358"></a>00358 
+<a name="l00359"></a>00359   
+<a name="l00360"></a>00360    <span class="comment">/* add the off artificial frame to the frameset */</span>
+<a name="l00361"></a>00361    <span class="keywordflow">if</span>(NULL != cpl_frameset_find(set_off,RAW_FIBRE_NS)) {
+<a name="l00362"></a>00362        frame = cpl_frameset_find(set_off,RAW_FIBRE_NS);
+<a name="l00363"></a>00363        cpl_frameset_erase(<span class="keyword">set</span>,RAW_FIBRE_NS);
+<a name="l00364"></a>00364        cpl_frameset_insert(<span class="keyword">set</span>,cpl_frame_duplicate(frame));
+<a name="l00365"></a>00365    } <span class="keywordflow">else</span> {
+<a name="l00366"></a>00366        <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Frame %s not found!"</span>, RAW_FIBRE_NS);
+<a name="l00367"></a>00367        <span class="keywordflow">goto</span> cleanup;
+<a name="l00368"></a>00368    }
+<a name="l00369"></a>00369  
+<a name="l00370"></a>00370  
+<a name="l00371"></a>00371    <span class="comment">/* </span>
+<a name="l00372"></a>00372 <span class="comment">       ---------------------------------------------------------</span>
+<a name="l00373"></a>00373 <span class="comment">        1st iteration: get off frame </span>
+<a name="l00374"></a>00374 <span class="comment">       ---------------------------------------------------------</span>
+<a name="l00375"></a>00375 <span class="comment">    */</span>
+<a name="l00376"></a>00376 
+<a name="l00377"></a>00377    sinfo_msg(<span class="stringliteral">"STACK FIBRE,NS TO GET FAKE OFF\n"</span>) ; 
+<a name="l00378"></a>00378    strcpy(fk->pro_class,RAW_FIBRE_NS);
+<a name="l00379"></a>00379    fk->frm_switch=1;
+<a name="l00380"></a>00380    fk->mask_index=0;
+<a name="l00381"></a>00381    fk->ind_index=0;
+<a name="l00382"></a>00382    fk->flat_index=0;
+<a name="l00383"></a>00383    fk->wfix_index=0;
+<a name="l00384"></a>00384    fk->low_rej=0.0;
+<a name="l00385"></a>00385    fk->hig_rej=0.2;
+<a name="l00386"></a>00386 
+<a name="l00387"></a>00387  
+<a name="l00388"></a>00388    ck0(sinfo_new_prepare_stacked_frames(cpl_func,config, <span class="keyword">set</span>, set_fibre_ns,
+<a name="l00389"></a>00389                                         PRO_FIBRE_NS_STACKED_OFF,0,fk),
+<a name="l00390"></a>00390        <span class="stringliteral">"Error stacking frame %s"</span>,PRO_FIBRE_NS_STACKED_OFF);
+<a name="l00391"></a>00391 
+<a name="l00392"></a>00392    strcpy(file_name,<span class="stringliteral">"out_fibre_off.fits"</span>);
+<a name="l00393"></a>00393    check_nomsg(ima=cpl_image_load(file_name,CPL_TYPE_FLOAT,0,0));
+<a name="l00394"></a>00394    sinfo_free_frameset(&set_off);
+<a name="l00395"></a>00395 
+<a name="l00396"></a>00396    cknull(plist = cpl_propertylist_load(file_name, 0),
+<a name="l00397"></a>00397            <span class="stringliteral">"getting header from reference ima frame %s"</span>,file_name);
+<a name="l00398"></a>00398 
+<a name="l00399"></a>00399      <span class="keywordflow">if</span> (sinfo_propertylist_has(plist, KEY_NAME_LAMP_HALO)) {
+<a name="l00400"></a>00400        cpl_propertylist_set_bool(plist, KEY_NAME_LAMP_HALO, LAMP_OFF);
+<a name="l00401"></a>00401      } <span class="keywordflow">else</span> {
+<a name="l00402"></a>00402        cpl_propertylist_append_bool(plist, KEY_NAME_LAMP_HALO,LAMP_OFF);
+<a name="l00403"></a>00403      }
+<a name="l00404"></a>00404 
+<a name="l00405"></a>00405    sinfo_free_propertylist(&plist);
+<a name="l00406"></a>00406    sinfo_free_image(&ima);
+<a name="l00407"></a>00407    sinfo_msg(<span class="stringliteral">"SUCCESS: STACKED FIBRE,NS TO GET FAKE OFF\n"</span>) ;      
+<a name="l00408"></a>00408 
+<a name="l00409"></a>00409    <span class="comment">/* </span>
+<a name="l00410"></a>00410 <span class="comment">       ---------------------------------------------------------</span>
+<a name="l00411"></a>00411 <span class="comment">        2nd iteration: get on frame </span>
+<a name="l00412"></a>00412 <span class="comment">       ---------------------------------------------------------</span>
+<a name="l00413"></a>00413 <span class="comment">    */</span>
+<a name="l00414"></a>00414 
+<a name="l00415"></a>00415    check_nomsg(set_on=cpl_frameset_duplicate(raw_set));
+<a name="l00416"></a>00416 
+<a name="l00417"></a>00417    ck0_nomsg(new_pre_process(set_on, 0.0, 0.0,<span class="stringliteral">"out_fibre_on.fits"</span>));
+<a name="l00418"></a>00418 
+<a name="l00419"></a>00419    <span class="keywordflow">if</span>(NULL != cpl_frameset_find(set_on,RAW_FIBRE_NS)) {
+<a name="l00420"></a>00420      frame = cpl_frameset_find(set_on,RAW_FIBRE_NS);
+<a name="l00421"></a>00421      cpl_frameset_erase(<span class="keyword">set</span>,RAW_FIBRE_NS);
+<a name="l00422"></a>00422      cpl_frameset_insert(<span class="keyword">set</span>,cpl_frame_duplicate(frame));
+<a name="l00423"></a>00423    } <span class="keywordflow">else</span> {
+<a name="l00424"></a>00424      <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Frame %s not found!"</span>, RAW_FIBRE_NS);
+<a name="l00425"></a>00425      <span class="keywordflow">goto</span> cleanup;
+<a name="l00426"></a>00426    }
+<a name="l00427"></a>00427 
+<a name="l00428"></a>00428 
+<a name="l00429"></a>00429    sinfo_msg(<span class="stringliteral">"STACK FIBRE,NS TO GET FAKE ON\n"</span>) ; 
+<a name="l00430"></a>00430 
+<a name="l00431"></a>00431    strcpy(fk->pro_class,RAW_FIBRE_NS);
+<a name="l00432"></a>00432    fk->frm_switch=1;
+<a name="l00433"></a>00433    fk->mask_index=0;
+<a name="l00434"></a>00434    fk->ind_index=0;
+<a name="l00435"></a>00435    fk->flat_index=0;
+<a name="l00436"></a>00436    fk->wfix_index=0;
+<a name="l00437"></a>00437    fk->low_rej=0.0;
+<a name="l00438"></a>00438    fk->hig_rej=0.0;
+<a name="l00439"></a>00439 
+<a name="l00440"></a>00440 
+<a name="l00441"></a>00441    ck0(sinfo_new_prepare_stacked_frames(cpl_func,config, <span class="keyword">set</span>, set_fibre_ns,
+<a name="l00442"></a>00442                                         PRO_FIBRE_NS_STACKED_ON,0,fk),
+<a name="l00443"></a>00443                         <span class="stringliteral">"error stacking frame %s"</span>,PRO_FIBRE_NS_STACKED_ON);
+<a name="l00444"></a>00444         sinfo_msg(<span class="stringliteral">"SUCCESS DETERMINATION %s"</span>,PRO_FIBRE_NS_STACKED_ON) ; 
+<a name="l00445"></a>00445 
+<a name="l00446"></a>00446    <span class="comment">/* cpl_frameset_erase(set,RAW_FIBRE_NS); */</span>
+<a name="l00447"></a>00447    sinfo_free_frameset(&set_on);
+<a name="l00448"></a>00448 
+<a name="l00449"></a>00449    <span class="comment">/* here we have a problem with pipefile of following step product */</span>
+<a name="l00450"></a>00450    <span class="comment">/* </span>
+<a name="l00451"></a>00451 <span class="comment">       ---------------------------------------------------------</span>
+<a name="l00452"></a>00452 <span class="comment">                3rd iteration combines on and off fake frames</span>
+<a name="l00453"></a>00453 <span class="comment">       ---------------------------------------------------------</span>
+<a name="l00454"></a>00454 <span class="comment">   */</span>
+<a name="l00455"></a>00455 
+<a name="l00456"></a>00456    sinfo_msg(<span class="stringliteral">"COMBINES FAKE ON AND OFF\n"</span>) ; 
+<a name="l00457"></a>00457    strcpy(fk->pro_class,PRO_FIBRE_NS_STACKED);
+<a name="l00458"></a>00458    fk->frm_switch=1;
+<a name="l00459"></a>00459    fk->mask_index=0;
+<a name="l00460"></a>00460    fk->ind_index=0;
+<a name="l00461"></a>00461    fk->flat_index=1;
+<a name="l00462"></a>00462    fk->wfix_index=0;
+<a name="l00463"></a>00463    fk->low_rej=0.0;
+<a name="l00464"></a>00464    fk->hig_rej=0.0;
+<a name="l00465"></a>00465 
+<a name="l00466"></a>00466    ck0(sinfo_new_prepare_stacked_frames(cpl_func,config, <span class="keyword">set</span>, set_fibre_ns,
+<a name="l00467"></a>00467                                         PRO_FIBRE_NS_STACKED,0,fk),
+<a name="l00468"></a>00468                           <span class="stringliteral">"Stacking frame %s"</span>,PRO_FIBRE_NS_STACKED);
+<a name="l00469"></a>00469    sinfo_msg(<span class="stringliteral">"SUCCESS DETERMINATION %s"</span>,PRO_FIBRE_NS_STACKED) ; 
+<a name="l00470"></a>00470 
+<a name="l00471"></a>00471    <span class="comment">/* cpl_frameset_erase(set,RAW_FIBRE_NS); */</span>
+<a name="l00472"></a>00472 
+<a name="l00473"></a>00473    <span class="comment">/* </span>
+<a name="l00474"></a>00474 <span class="comment">       ---------------------------------------------------------</span>
+<a name="l00475"></a>00475 <span class="comment">                STACK WAVECAL</span>
+<a name="l00476"></a>00476 <span class="comment">       ---------------------------------------------------------</span>
+<a name="l00477"></a>00477 <span class="comment">   */</span>
+<a name="l00478"></a>00478  
+<a name="l00479"></a>00479    sinfo_msg(<span class="stringliteral">"STACK on WAVE frame\n"</span>) ;
+<a name="l00480"></a>00480    strcpy(fk->pro_class,RAW_WAVE_NS);
+<a name="l00481"></a>00481    fk->frm_switch=1;
+<a name="l00482"></a>00482    fk->mask_index=0;
+<a name="l00483"></a>00483    fk->ind_index=0;
+<a name="l00484"></a>00484    fk->flat_index=1;
+<a name="l00485"></a>00485    fk->wfix_index=0;
+<a name="l00486"></a>00486    fk->low_rej=0.1;
+<a name="l00487"></a>00487    fk->hig_rej=0.1;
+<a name="l00488"></a>00488    
+<a name="l00489"></a>00489    sinfo_msg(<span class="stringliteral">"STACK on WAVE frame\n"</span>) ; 
+<a name="l00490"></a>00490    ck0(sinfo_new_prepare_stacked_frames(cpl_func,config, <span class="keyword">set</span>, set_wave_ns,
+<a name="l00491"></a>00491                                         PRO_WAVE_LAMP_STACKED,0,fk),
+<a name="l00492"></a>00492                           <span class="stringliteral">"spacking frame %s"</span>,PRO_WAVE_LAMP_STACKED);
+<a name="l00493"></a>00493    sinfo_msg(<span class="stringliteral">"SUCCESS DETERMINATION %s"</span>,PRO_WAVE_LAMP_STACKED) ; 
+<a name="l00494"></a>00494 
+<a name="l00495"></a>00495    <span class="keywordflow">if</span>(pdensity < 2) {
+<a name="l00496"></a>00496      cpl_frameset_erase(<span class="keyword">set</span>,PRO_FIBRE_NS_STACKED_OFF);
+<a name="l00497"></a>00497      cpl_frameset_erase(<span class="keyword">set</span>,PRO_FIBRE_NS_STACKED_ON);
+<a name="l00498"></a>00498      cpl_frameset_erase(<span class="keyword">set</span>,PRO_MASTER_FLAT_LAMP);
+<a name="l00499"></a>00499    }
+<a name="l00500"></a>00500    <span class="comment">/* </span>
+<a name="l00501"></a>00501 <span class="comment">       ---------------------------------------------------------</span>
+<a name="l00502"></a>00502 <span class="comment">                DISTORTIONS </span>
+<a name="l00503"></a>00503 <span class="comment">       ---------------------------------------------------------</span>
+<a name="l00504"></a>00504 <span class="comment">   */</span>
+<a name="l00505"></a>00505 
+<a name="l00506"></a>00506    sinfo_msg(<span class="stringliteral">"COMPUTE DISTORTIONS\n"</span>) ; 
+<a name="l00507"></a>00507    ck0(sinfo_new_find_distortions(cpl_func,config, <span class="keyword">set</span>,set_fibre_ns),
+<a name="l00508"></a>00508        <span class="stringliteral">"computing distortions"</span>);
+<a name="l00509"></a>00509 
+<a name="l00510"></a>00510 
+<a name="l00511"></a>00511    <span class="keywordflow">if</span>(NULL != cpl_frameset_find(<span class="keyword">set</span>,PRO_FIBRE_NS_STACKED)) {
+<a name="l00512"></a>00512      frame = cpl_frameset_find(<span class="keyword">set</span>,PRO_FIBRE_NS_STACKED);
+<a name="l00513"></a>00513      strcpy(file_name,cpl_frame_get_filename(frame));
+<a name="l00514"></a>00514    } <span class="keywordflow">else</span> {
+<a name="l00515"></a>00515      <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Frame %s not found!"</span>, PRO_FIBRE_NS_STACKED);
+<a name="l00516"></a>00516      <span class="keywordflow">goto</span> cleanup;
+<a name="l00517"></a>00517    }
+<a name="l00518"></a>00518    check_nomsg(ima=cpl_image_load(file_name,CPL_TYPE_FLOAT,0,0));
+<a name="l00519"></a>00519 
+<a name="l00520"></a>00520    check(plist = cpl_propertylist_load(file_name, 0),
+<a name="l00521"></a>00521      <span class="stringliteral">"getting header from reference ima frame %s"</span>,file_name);
+<a name="l00522"></a>00522 
+<a name="l00523"></a>00523 
+<a name="l00524"></a>00524      <span class="keywordflow">if</span> (cpl_propertylist_has(plist, KEY_NAME_LAMP_HALO)) {
+<a name="l00525"></a>00525        cpl_propertylist_set_bool(plist, KEY_NAME_LAMP_HALO, LAMP_ON);
+<a name="l00526"></a>00526      } <span class="keywordflow">else</span> {
+<a name="l00527"></a>00527        cpl_propertylist_append_bool(plist, KEY_NAME_LAMP_HALO,LAMP_ON);
+<a name="l00528"></a>00528      }
+<a name="l00529"></a>00529 
+<a name="l00530"></a>00530 
+<a name="l00531"></a>00531    <span class="comment">/* Save the file */</span>
+<a name="l00532"></a>00532    <span class="comment">/*</span>
+<a name="l00533"></a>00533 <span class="comment">   if (cpl_image_save(ima, file_name, CPL_BPP_IEEE_FLOAT, </span>
+<a name="l00534"></a>00534 <span class="comment">                      plist,CPL_IO_DEFAULT)!=CPL_ERROR_NONE) {</span>
+<a name="l00535"></a>00535 <span class="comment">       sinfo_msg_error("Cannot save the product %s",file_name);</span>
+<a name="l00536"></a>00536 <span class="comment">       goto cleanup;</span>
+<a name="l00537"></a>00537 <span class="comment"></span>
+<a name="l00538"></a>00538 <span class="comment">   }</span>
+<a name="l00539"></a>00539 <span class="comment">   */</span>
+<a name="l00540"></a>00540      
+<a name="l00541"></a>00541    sinfo_free_image(&ima);
+<a name="l00542"></a>00542    sinfo_free_propertylist(&plist);
+<a name="l00543"></a>00543    sinfo_msg(<span class="stringliteral">"SUCCESS: COMPUTED DISTORTIONS\n"</span>) ; 
+<a name="l00544"></a>00544 
+<a name="l00545"></a>00545    <span class="comment">/* </span>
+<a name="l00546"></a>00546 <span class="comment">       ---------------------------------------------------------</span>
+<a name="l00547"></a>00547 <span class="comment">       4th iteration: distort fake frame</span>
+<a name="l00548"></a>00548 <span class="comment">       ---------------------------------------------------------</span>
+<a name="l00549"></a>00549 <span class="comment">   */</span>
+<a name="l00550"></a>00550 
+<a name="l00551"></a>00551 
+<a name="l00552"></a>00552    
+<a name="l00553"></a>00553    sinfo_msg(<span class="stringliteral">"DISTORT FAKE FRAME\n"</span>) ; 
+<a name="l00554"></a>00554 
+<a name="l00555"></a>00555    strcpy(fk->pro_class,PRO_FIBRE_NS_STACKED_DIST);
+<a name="l00556"></a>00556    fk->frm_switch=1;
+<a name="l00557"></a>00557    fk->mask_index=1;
+<a name="l00558"></a>00558    fk->ind_index=1;
+<a name="l00559"></a>00559    fk->flat_index=0;
+<a name="l00560"></a>00560    fk->wfix_index=1;
+<a name="l00561"></a>00561    fk->low_rej=0.0;
+<a name="l00562"></a>00562    fk->hig_rej=0.0;
+<a name="l00563"></a>00563 
+<a name="l00564"></a>00564    ck0(sinfo_new_prepare_stacked_frames(cpl_func,config, <span class="keyword">set</span>, set_fibre_ns,
+<a name="l00565"></a>00565                                         PRO_FIBRE_NS_STACKED_DIST,0,fk),
+<a name="l00566"></a>00566                         <span class="stringliteral">"Stacking frame %s"</span>,PRO_FIBRE_NS_STACKED_DIST);
+<a name="l00567"></a>00567 
+<a name="l00568"></a>00568    sinfo_msg(<span class="stringliteral">"SUCCESS: DISTORTED FAKE FRAME\n"</span>) ;
+<a name="l00569"></a>00569 
+<a name="l00570"></a>00570  
+<a name="l00571"></a>00571  
+<a name="l00572"></a>00572    <span class="keywordflow">if</span>(NULL != cpl_frameset_find(<span class="keyword">set</span>,PRO_FIBRE_NS_STACKED_DIST)) {
+<a name="l00573"></a>00573      frame = cpl_frameset_find(<span class="keyword">set</span>,PRO_FIBRE_NS_STACKED_DIST);
+<a name="l00574"></a>00574      strcpy(file_name,cpl_frame_get_filename(frame));
+<a name="l00575"></a>00575    } <span class="keywordflow">else</span> {
+<a name="l00576"></a>00576      <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Frame %s not found!"</span>, PRO_FIBRE_NS_STACKED_DIST);
+<a name="l00577"></a>00577      <span class="keywordflow">goto</span> cleanup;
+<a name="l00578"></a>00578    }
+<a name="l00579"></a>00579    check_nomsg(ima=cpl_image_load(file_name,CPL_TYPE_FLOAT,0,0));
+<a name="l00580"></a>00580    check(plist = cpl_propertylist_load(file_name, 0),
+<a name="l00581"></a>00581      <span class="stringliteral">"getting header from reference ima frame %s"</span>,file_name);
+<a name="l00582"></a>00582 
+<a name="l00583"></a>00583 
+<a name="l00584"></a>00584      <span class="keywordflow">if</span> (cpl_propertylist_has(plist, KEY_NAME_LAMP_HALO)) {
+<a name="l00585"></a>00585        cpl_propertylist_set_bool(plist, KEY_NAME_LAMP_HALO, LAMP_ON);
+<a name="l00586"></a>00586      } <span class="keywordflow">else</span> {
+<a name="l00587"></a>00587        cpl_propertylist_append_bool(plist, KEY_NAME_LAMP_HALO,LAMP_ON);
+<a name="l00588"></a>00588      }
+<a name="l00589"></a>00589 
+<a name="l00590"></a>00590    <span class="comment">/* Save the file */</span>
+<a name="l00591"></a>00591    <span class="comment">/*</span>
+<a name="l00592"></a>00592 <span class="comment">      if (cpl_image_save(ima, file_name, CPL_BPP_IEEE_FLOAT, </span>
+<a name="l00593"></a>00593 <span class="comment">                         plist,CPL_IO_DEFAULT)!=CPL_ERROR_NONE) {</span>
+<a name="l00594"></a>00594 <span class="comment">       sinfo_msg_error("Cannot save the product %s",file_name);</span>
+<a name="l00595"></a>00595 <span class="comment">       goto cleanup;</span>
+<a name="l00596"></a>00596 <span class="comment">      }</span>
+<a name="l00597"></a>00597 <span class="comment">   */</span>
+<a name="l00598"></a>00598    sinfo_free_propertylist(&plist);
+<a name="l00599"></a>00599    sinfo_free_image(&ima);
+<a name="l00600"></a>00600 
+<a name="l00601"></a>00601    <span class="comment">/* </span>
+<a name="l00602"></a>00602 <span class="comment">       ---------------------------------------------------------</span>
+<a name="l00603"></a>00603 <span class="comment">                               NST </span>
+<a name="l00604"></a>00604 <span class="comment">       ---------------------------------------------------------</span>
+<a name="l00605"></a>00605 <span class="comment">   */</span>
+<a name="l00606"></a>00606  
+<a name="l00607"></a>00607    <span class="keywordflow">if</span>(pdensity < 2) {
+<a name="l00608"></a>00608      cpl_frameset_erase(<span class="keyword">set</span>,PRO_BP_MAP_DI);
+<a name="l00609"></a>00609      cpl_frameset_erase(<span class="keyword">set</span>,PRO_FIBRE_NS_STACKED);
+<a name="l00610"></a>00610      cpl_frameset_erase(<span class="keyword">set</span>,PRO_WAVE_LAMP_STACKED);
+<a name="l00611"></a>00611    }
+<a name="l00612"></a>00612 
+<a name="l00613"></a>00613   
+<a name="l00614"></a>00614    sinfo_msg(<span class="stringliteral">"RUN NORD SOUTH TEST\n"</span>) ; 
+<a name="l00615"></a>00615    ck0(sinfo_new_nst(cpl_func,config, <span class="keyword">set</span>,set_fibre_ns),
+<a name="l00616"></a>00616        <span class="stringliteral">"Running north south test"</span>);
+<a name="l00617"></a>00617 
+<a name="l00618"></a>00618 
+<a name="l00619"></a>00619    <span class="keywordflow">if</span>(pdensity < 2) {
+<a name="l00620"></a>00620      cpl_frameset_erase(<span class="keyword">set</span>,PRO_FIBRE_NS_STACKED_DIST);
+<a name="l00621"></a>00621    }
+<a name="l00622"></a>00622 
+<a name="l00623"></a>00623    sinfo_msg(<span class="stringliteral">"SUCCESS: RUNNED NORD SUD TEST\n"</span>) ; 
+<a name="l00624"></a>00624    sinfo_msg(<span class="stringliteral">"SUCCESS: RECIPE\n"</span>) ; 
+<a name="l00625"></a>00625 
+<a name="l00626"></a>00626    sinfo_free_frameset(&raw_set);
+<a name="l00627"></a>00627    sinfo_fake_delete(&fk);
+<a name="l00628"></a>00628 
+<a name="l00629"></a>00629 
+<a name="l00630"></a>00630  cleanup:
+<a name="l00631"></a>00631 
+<a name="l00632"></a>00632    sinfo_free_frameset(&set_on);
+<a name="l00633"></a>00633    sinfo_free_frameset(&set_fibre_ns);
+<a name="l00634"></a>00634    sinfo_free_frameset(&set_wave_ns);
+<a name="l00635"></a>00635    sinfo_free_frameset(&set_flat_ns);
+<a name="l00636"></a>00636    sinfo_free_image(&ima);
+<a name="l00637"></a>00637    sinfo_free_propertylist(&plist) ;
+<a name="l00638"></a>00638    sinfo_free_frameset(&set_off);
+<a name="l00639"></a>00639    sinfo_free_frameset(&raw_set);
+<a name="l00640"></a>00640    sinfo_free_frameset(&raw_set);
+<a name="l00641"></a>00641    sinfo_fake_delete(&fk);
+<a name="l00642"></a>00642 
+<a name="l00643"></a>00643   <span class="keywordflow">if</span> (cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l00644"></a>00644     <span class="keywordflow">return</span> -1;
+<a name="l00645"></a>00645   } <span class="keywordflow">else</span> {
+<a name="l00646"></a>00646     <span class="keywordflow">return</span> 0;
+<a name="l00647"></a>00647   }
+<a name="l00648"></a>00648 
+<a name="l00649"></a>00649 
+<a name="l00650"></a>00650 }
+<a name="l00651"></a>00651 
+<a name="l00652"></a>00652 
+<a name="l00653"></a>00653 
+<a name="l00654"></a>00654 <span class="keyword">static</span> <span class="keywordtype">int</span> 
+<a name="l00655"></a>00655 new_pre_process(cpl_frameset* <span class="keyword">set</span>, 
+<a name="l00656"></a>00656 <span class="keyword">const</span> <span class="keywordtype">float</span> lo_rej, <span class="keyword">const</span> <span class="keywordtype">float</span> hi_rej, <span class="keyword">const</span> <span class="keywordtype">char</span>* name_o)
+<a name="l00657"></a>00657 {
+<a name="l00658"></a>00658 
+<a name="l00659"></a>00659   <span class="keywordtype">int</span> nf=0;
+<a name="l00660"></a>00660   <span class="keywordtype">int</span> ng=10;
+<a name="l00661"></a>00661   <span class="keywordtype">int</span> ns=0;
+<a name="l00662"></a>00662   <span class="keywordtype">int</span> nr=0;
+<a name="l00663"></a>00663   <span class="keywordtype">int</span> nt=0;
+<a name="l00664"></a>00664 
+<a name="l00665"></a>00665   <span class="keywordtype">int</span> i=0;
+<a name="l00666"></a>00666   <span class="keywordtype">int</span> j=0;
+<a name="l00667"></a>00667   <span class="keywordtype">int</span> k=0;
+<a name="l00668"></a>00668   <span class="keywordtype">int</span> lo_cut=0;
+<a name="l00669"></a>00669   <span class="keywordtype">int</span> hi_cut=0;
+<a name="l00670"></a>00670 
+<a name="l00671"></a>00671 
+<a name="l00672"></a>00672   cpl_frame* frame=NULL;
+<a name="l00673"></a>00673   cpl_frame* pframe=NULL;
+<a name="l00674"></a>00674   cpl_frameset* sof=NULL;
+<a name="l00675"></a>00675   cpl_frameset* fibre_raw_set=NULL;
+<a name="l00676"></a>00676   <span class="keywordtype">char</span>* file_name=NULL;
+<a name="l00677"></a>00677 
+<a name="l00678"></a>00678   cpl_propertylist* plist=NULL;
+<a name="l00679"></a>00679   cpl_imagelist* imset_tmp=NULL;
+<a name="l00680"></a>00680   cpl_imagelist* imset_tot=NULL;
+<a name="l00681"></a>00681   cpl_image** avg_img_list=NULL;
+<a name="l00682"></a>00682 
+<a name="l00683"></a>00683   cpl_image* img=NULL;
+<a name="l00684"></a>00684   cpl_image* img_tmp=NULL;
+<a name="l00685"></a>00685   cpl_image* img_dup=NULL;
+<a name="l00686"></a>00686 
+<a name="l00687"></a>00687   cpl_image** img_list=NULL;
+<a name="l00688"></a>00688 
+<a name="l00689"></a>00689 
+<a name="l00690"></a>00690   sof = cpl_frameset_duplicate(<span class="keyword">set</span>);
+<a name="l00691"></a>00691   fibre_raw_set = cpl_frameset_new();
+<a name="l00692"></a>00692 
+<a name="l00693"></a>00693   sinfo_contains_frames_kind(sof,fibre_raw_set,RAW_FIBRE_NS);
+<a name="l00694"></a>00694 
+<a name="l00695"></a>00695   nf = cpl_frameset_get_size(fibre_raw_set);
+<a name="l00696"></a>00696   <span class="keywordflow">if</span>(nf < 1) {
+<a name="l00697"></a>00697     <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"No input frames in data set"</span>);
+<a name="l00698"></a>00698     sinfo_free_frameset(&sof);
+<a name="l00699"></a>00699     sinfo_free_frameset(&fibre_raw_set);
+<a name="l00700"></a>00700     <span class="keywordflow">return</span> -1;
+<a name="l00701"></a>00701   }
+<a name="l00702"></a>00702   frame = cpl_frameset_get_frame(fibre_raw_set,0);
+<a name="l00703"></a>00703   file_name=(<span class="keywordtype">char</span>*) cpl_frame_get_filename(frame);
+<a name="l00704"></a>00704 
+<a name="l00705"></a>00705 
+<a name="l00706"></a>00706   <span class="keywordflow">if</span> ((plist = cpl_propertylist_load(file_name, 0)) == NULL) {
+<a name="l00707"></a>00707     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"getting header from  ima frame %s"</span>,file_name);
+<a name="l00708"></a>00708     <span class="keywordflow">return</span> -1 ;
+<a name="l00709"></a>00709   }
+<a name="l00710"></a>00710 
+<a name="l00711"></a>00711 
+<a name="l00712"></a>00712   <span class="keywordflow">if</span>( nf > ng) {
+<a name="l00713"></a>00713 
+<a name="l00714"></a>00714     sinfo_msg(<span class="stringliteral">"Total raw frames nf=%d > max frm per group ng=%d"</span>,nf,ng);
+<a name="l00715"></a>00715     ns = (nf+1)/ng;
+<a name="l00716"></a>00716     nr = nf-ns*ng;
+<a name="l00717"></a>00717     imset_tot=cpl_imagelist_new();
+<a name="l00718"></a>00718     avg_img_list=cpl_malloc((ns+1) * <span class="keyword">sizeof</span>(cpl_image *));
+<a name="l00719"></a>00719 
+<a name="l00720"></a>00720 
+<a name="l00721"></a>00721     <span class="keywordflow">for</span> (i=0;i<ns;i++) {
+<a name="l00722"></a>00722       sinfo_msg(<span class="stringliteral">"iteration i=%d\n"</span>,i);
+<a name="l00723"></a>00723       imset_tmp=cpl_imagelist_new();
+<a name="l00724"></a>00724       img_list=cpl_malloc(ng * <span class="keyword">sizeof</span>(cpl_image *));
+<a name="l00725"></a>00725 
+<a name="l00726"></a>00726 
+<a name="l00727"></a>00727       <span class="keywordflow">for</span> (j=0;j<ng;j++) {
+<a name="l00728"></a>00728     k=i*ng+j;
+<a name="l00729"></a>00729         frame = cpl_frameset_get_frame(fibre_raw_set,k);
+<a name="l00730"></a>00730         file_name=(<span class="keywordtype">char</span>*)cpl_frame_get_filename(frame);
+<a name="l00731"></a>00731         img_tmp=cpl_image_load(file_name,CPL_TYPE_FLOAT,0,0);
+<a name="l00732"></a>00732         img_dup=cpl_image_duplicate(img_tmp); 
+<a name="l00733"></a>00733         cpl_imagelist_set(imset_tmp,img_dup,j);
+<a name="l00734"></a>00734         cpl_image_delete(img_tmp);
+<a name="l00735"></a>00735       }
+<a name="l00736"></a>00736 
+<a name="l00737"></a>00737          
+<a name="l00738"></a>00738       nt=cpl_imagelist_get_size(imset_tmp);
+<a name="l00739"></a>00739       lo_cut=(floor)(lo_rej*nt+0.5);
+<a name="l00740"></a>00740       hi_cut=(floor)(hi_rej*nt+0.5);
+<a name="l00741"></a>00741       avg_img_list[i]=cpl_imagelist_collapse_minmax_create(imset_tmp,
+<a name="l00742"></a>00742                                                            lo_cut,hi_cut);
+<a name="l00743"></a>00743       cpl_imagelist_set(imset_tot,avg_img_list[i],i);
+<a name="l00744"></a>00744       cpl_imagelist_delete(imset_tmp);
+<a name="l00745"></a>00745       cpl_free(img_list);
+<a name="l00746"></a>00746 
+<a name="l00747"></a>00747     }
+<a name="l00748"></a>00748  
+<a name="l00749"></a>00749     <span class="keywordflow">if</span>(ns*ng<nf) {
+<a name="l00750"></a>00750       imset_tmp=cpl_imagelist_new();
+<a name="l00751"></a>00751       img_list=cpl_malloc((nf-ns*ng) * <span class="keyword">sizeof</span>(cpl_image *));
+<a name="l00752"></a>00752       <span class="keywordflow">for</span>(i=0;i<nr;i++) {
+<a name="l00753"></a>00753     k=i+ns*ng;
+<a name="l00754"></a>00754         frame = cpl_frameset_get_frame(fibre_raw_set,k);
+<a name="l00755"></a>00755         file_name  = (<span class="keywordtype">char</span>*) cpl_frame_get_filename(frame);
+<a name="l00756"></a>00756 
+<a name="l00757"></a>00757         img_list[i]=cpl_image_load(file_name,CPL_TYPE_FLOAT,0,0);
+<a name="l00758"></a>00758         cpl_imagelist_set(imset_tmp,img_list[i],i);
+<a name="l00759"></a>00759       }
+<a name="l00760"></a>00760       nt=cpl_imagelist_get_size(imset_tmp);
+<a name="l00761"></a>00761       lo_cut=(floor)(lo_rej*nt+0.5);
+<a name="l00762"></a>00762       hi_cut=(floor)(hi_rej*nt+0.5);
+<a name="l00763"></a>00763 
+<a name="l00764"></a>00764       avg_img_list[ns]=cpl_imagelist_collapse_minmax_create(imset_tmp,
+<a name="l00765"></a>00765                                                             lo_cut,hi_cut);
+<a name="l00766"></a>00766       cpl_imagelist_set(imset_tot,avg_img_list[ns],ns);
+<a name="l00767"></a>00767 
+<a name="l00768"></a>00768       cpl_free(img);
+<a name="l00769"></a>00769       cpl_imagelist_delete(imset_tmp);
+<a name="l00770"></a>00770       cpl_free(img_list);
+<a name="l00771"></a>00771     }
+<a name="l00772"></a>00772  
+<a name="l00773"></a>00773   } <span class="keywordflow">else</span> {
+<a name="l00774"></a>00774 
+<a name="l00775"></a>00775     sinfo_msg(<span class="stringliteral">"Total raw frames nf=%d < max frm per group ng=%d"</span>,nf,ng);
+<a name="l00776"></a>00776     imset_tot=cpl_imagelist_new();
+<a name="l00777"></a>00777     img_list=cpl_malloc(nf * <span class="keyword">sizeof</span>(cpl_image *));
+<a name="l00778"></a>00778     <span class="keywordflow">for</span> (i=0;i<nf;i++) {
+<a name="l00779"></a>00779       frame = cpl_frameset_get_frame(fibre_raw_set,i);
+<a name="l00780"></a>00780       file_name  = (<span class="keywordtype">char</span>*) cpl_frame_get_filename(frame);
+<a name="l00781"></a>00781       img_list[i]=cpl_image_load(file_name,CPL_TYPE_FLOAT,0,0);
+<a name="l00782"></a>00782       cpl_imagelist_set(imset_tot,img_list[i],i);
+<a name="l00783"></a>00783     }
+<a name="l00784"></a>00784     cpl_free(img_list);
+<a name="l00785"></a>00785   }
+<a name="l00786"></a>00786   cpl_free(avg_img_list);
+<a name="l00787"></a>00787 
+<a name="l00788"></a>00788   cpl_frameset_delete(fibre_raw_set);
+<a name="l00789"></a>00789   nt=cpl_imagelist_get_size(imset_tot);
+<a name="l00790"></a>00790   lo_cut=(floor)(lo_rej*nt+0.5);
+<a name="l00791"></a>00791   hi_cut=(floor)(hi_rej*nt+0.5);
+<a name="l00792"></a>00792 
+<a name="l00793"></a>00793   <span class="keywordflow">if</span>( (img = cpl_imagelist_collapse_minmax_create(imset_tot,
+<a name="l00794"></a>00794                                                   lo_cut,hi_cut)) == NULL) {
+<a name="l00795"></a>00795     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Error code"</span>);
+<a name="l00796"></a>00796     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>((<span class="keywordtype">char</span>* ) cpl_error_get_message());
+<a name="l00797"></a>00797     cpl_imagelist_delete(imset_tot);
+<a name="l00798"></a>00798     cpl_frameset_delete(sof);
+<a name="l00799"></a>00799     cpl_propertylist_delete(plist) ;
+<a name="l00800"></a>00800     <span class="keywordflow">return</span> -1;
+<a name="l00801"></a>00801   }
+<a name="l00802"></a>00802 
+<a name="l00803"></a>00803   <span class="keywordflow">if</span> (cpl_image_save(img,name_o, CPL_BPP_IEEE_FLOAT,
+<a name="l00804"></a>00804              plist,CPL_IO_DEFAULT)!=CPL_ERROR_NONE) {
+<a name="l00805"></a>00805     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Cannot save the product %s"</span>,name_o);
+<a name="l00806"></a>00806     cpl_imagelist_delete(imset_tot);
+<a name="l00807"></a>00807     cpl_frameset_delete(sof);
+<a name="l00808"></a>00808     cpl_propertylist_delete(plist) ;
+<a name="l00809"></a>00809     <span class="keywordflow">return</span> -1 ;
+<a name="l00810"></a>00810   }
+<a name="l00811"></a>00811   cpl_imagelist_delete(imset_tot);
+<a name="l00812"></a>00812   cpl_frameset_erase(<span class="keyword">set</span>,RAW_FIBRE_NS);
+<a name="l00813"></a>00813          
+<a name="l00814"></a>00814   <span class="comment">/* Create product frame */</span>
+<a name="l00815"></a>00815   pframe = cpl_frame_new();
+<a name="l00816"></a>00816   cpl_frame_set_filename(pframe, name_o) ;
+<a name="l00817"></a>00817   cpl_frame_set_tag(pframe, <span class="stringliteral">"FIBRE_NS"</span>) ;
+<a name="l00818"></a>00818   cpl_frame_set_type(pframe, CPL_FRAME_TYPE_IMAGE) ;
+<a name="l00819"></a>00819   cpl_frame_set_group(pframe, CPL_FRAME_GROUP_RAW) ;
+<a name="l00820"></a>00820   cpl_frame_set_level(pframe, CPL_FRAME_LEVEL_FINAL) ;
+<a name="l00821"></a>00821   <span class="keywordflow">if</span> (cpl_error_get_code()) {
+<a name="l00822"></a>00822     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Error while initialising the product frame"</span>) ;
+<a name="l00823"></a>00823     cpl_propertylist_delete(plist) ;
+<a name="l00824"></a>00824     cpl_frame_delete(pframe) ;
+<a name="l00825"></a>00825     cpl_image_delete(img) ;
+<a name="l00826"></a>00826     <span class="keywordflow">return</span> -1 ;
+<a name="l00827"></a>00827   }
+<a name="l00828"></a>00828     
+<a name="l00829"></a>00829 
+<a name="l00830"></a>00830   <span class="comment">/* Save the file */</span>
+<a name="l00831"></a>00831   <span class="keywordflow">if</span> (cpl_image_save(img, name_o, CPL_BPP_IEEE_FLOAT, plist,
+<a name="l00832"></a>00832              CPL_IO_DEFAULT) != CPL_ERROR_NONE) {
+<a name="l00833"></a>00833     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Could not save product"</span>);
+<a name="l00834"></a>00834     cpl_propertylist_delete(plist) ;
+<a name="l00835"></a>00835     cpl_frame_delete(pframe) ;
+<a name="l00836"></a>00836     cpl_image_delete(img) ;
+<a name="l00837"></a>00837     <span class="keywordflow">return</span> -1 ;
+<a name="l00838"></a>00838   }
+<a name="l00839"></a>00839   cpl_propertylist_delete(plist) ;
+<a name="l00840"></a>00840   cpl_image_delete(img) ;
+<a name="l00841"></a>00841 
+<a name="l00842"></a>00842   <span class="comment">/* Log the saved file in the input frameset */</span>
+<a name="l00843"></a>00843   cpl_frameset_insert(<span class="keyword">set</span>, pframe) ;
+<a name="l00844"></a>00844   cpl_frameset_delete(sof);
+<a name="l00845"></a>00845 
+<a name="l00846"></a>00846   <span class="keywordflow">return</span> 0;
+<a name="l00847"></a>00847 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__rec__jitter_8c_source.html b/html/sinfo__rec__jitter_8c_source.html
new file mode 100644
index 0000000..d928772
--- /dev/null
+++ b/html/sinfo__rec__jitter_8c_source.html
@@ -0,0 +1,366 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_rec_jitter.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_rec_jitter.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_rec_jitter.c,v 1.33 2009/10/20 14:32:56 kmirny Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the SINFONI Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: kmirny $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2009/10/20 14:32:56 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.33 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> */</span>
+<a name="l00026"></a>00026 
+<a name="l00027"></a>00027  <span class="comment">/****************************************************************</span>
+<a name="l00028"></a>00028 <span class="comment">  *           Object Data reduction                              *</span>
+<a name="l00029"></a>00029 <span class="comment">  ****************************************************************/</span>
+<a name="l00030"></a>00030 
+<a name="l00031"></a>00031 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00032"></a>00032 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>          <span class="comment">/* allows the program compilation */</span>
+<a name="l00033"></a>00033 <span class="preprocessor">#endif</span>
+<a name="l00034"></a>00034 <span class="preprocessor"></span>
+<a name="l00035"></a>00035 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00036"></a>00036 <span class="comment">                                Includes</span>
+<a name="l00037"></a>00037 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00038"></a>00038 
+<a name="l00039"></a>00039 <span class="comment">/* std */</span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include <strings.h></span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include <string.h></span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include <stdio.h></span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include <math.h></span>
+<a name="l00044"></a>00044 <span class="preprocessor">#include <libgen.h></span>
+<a name="l00045"></a>00045 
+<a name="l00046"></a>00046 
+<a name="l00047"></a>00047 <span class="comment">/* cpl */</span>
+<a name="l00048"></a>00048 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00049"></a>00049 
+<a name="l00050"></a>00050 <span class="comment">/* irplib */</span>
+<a name="l00051"></a>00051 <span class="preprocessor">#include <irplib_utils.h></span>
+<a name="l00052"></a>00052 
+<a name="l00053"></a>00053 <span class="comment">/* sinfoni */</span>
+<a name="l00054"></a>00054 <span class="preprocessor">#include <sinfo_utilities.h></span>
+<a name="l00055"></a>00055 <span class="preprocessor">#include <sinfo_pro_types.h></span>
+<a name="l00056"></a>00056 <span class="preprocessor">#include <sinfo_general_config.h></span>
+<a name="l00057"></a>00057 <span class="preprocessor">#include <sinfo_product_config.h></span>
+<a name="l00058"></a>00058 <span class="preprocessor">#include <sinfo_prepare_stacked_frames_config.h></span>
+<a name="l00059"></a>00059 <span class="preprocessor">#include <sinfo_objnod_config.h></span>
+<a name="l00060"></a>00060 <span class="preprocessor">#include <sinfo_skycor_config.h></span>
+<a name="l00061"></a>00061 <span class="preprocessor">#include <sinfo_psf_config.h></span>
+<a name="l00062"></a>00062 <span class="preprocessor">#include <sinfo_standard_star_config.h></span>
+<a name="l00063"></a>00063 <span class="preprocessor">#include <sinfo_new_prepare_stacked_frames.h></span>
+<a name="l00064"></a>00064 <span class="preprocessor">#include <sinfo_new_cubes_coadd.h></span>
+<a name="l00065"></a>00065 <span class="preprocessor">#include <sinfo_new_stdstar.h></span>
+<a name="l00066"></a>00066 <span class="preprocessor">#include <sinfo_new_psf.h></span>
+<a name="l00067"></a>00067 <span class="preprocessor">#include <sinfo_key_names.h></span>
+<a name="l00068"></a>00068 <span class="preprocessor">#include <sinfo_raw_types.h></span>
+<a name="l00069"></a>00069 <span class="preprocessor">#include <sinfo_functions.h></span>
+<a name="l00070"></a>00070 <span class="preprocessor">#include <sinfo_tpl_utils.h></span>
+<a name="l00071"></a>00071 <span class="preprocessor">#include <sinfo_tpl_dfs.h></span>
+<a name="l00072"></a>00072 <span class="preprocessor">#include <sinfo_hidden.h></span>
+<a name="l00073"></a>00073 <span class="preprocessor">#include <sinfo_globals.h></span>
+<a name="l00074"></a>00074 <span class="preprocessor">#include <sinfo_msg.h></span>
+<a name="l00075"></a>00075 <span class="preprocessor">#include <sinfo_rec_utils.h></span>
+<a name="l00076"></a>00076 <span class="preprocessor">#include <sinfo_error.h></span>
+<a name="l00077"></a>00077 <span class="preprocessor">#include <sinfo_utils_wrappers.h></span>
+<a name="l00078"></a>00078 
+<a name="l00079"></a>00079 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00080"></a>00080 <span class="comment">                            Functions prototypes</span>
+<a name="l00081"></a>00081 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00082"></a>00082 
+<a name="l00083"></a>00083 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_jitter_create(cpl_plugin *) ;
+<a name="l00084"></a>00084 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_jitter_exec(cpl_plugin *) ;
+<a name="l00085"></a>00085 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_jitter_destroy(cpl_plugin *) ;
+<a name="l00086"></a>00086 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_jitter(cpl_parameterlist *config, cpl_frameset *<span class="keyword">set</span>);
+<a name="l00087"></a>00087 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00088"></a>00088 <span class="comment">                            Static variables</span>
+<a name="l00089"></a>00089 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00090"></a>00090 
+<a name="l00091"></a>00091 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_rec_jitter_description1[] =
+<a name="l00092"></a>00092 <span class="stringliteral">"This recipe performs science data reduction.\n"</span>
+<a name="l00093"></a>00093 <span class="stringliteral">"The input files are:\n"</span>
+<a name="l00094"></a>00094 <span class="stringliteral">"science object and sky frames with tags OBJECT_NODDING and SKY_NODDING or\n"</span>
+<a name="l00095"></a>00095 <span class="stringliteral">"Telluric standard star frames and sky frames with tags STD and SKY_STD or\n"</span>
+<a name="l00096"></a>00096 <span class="stringliteral">"PSF standard star and sky frames with tags \n"</span>
+<a name="l00097"></a>00097 <span class="stringliteral">"PSF_CALIBRATOR and SKY_PSF_CALIBRATOR\n"</span>
+<a name="l00098"></a>00098 <span class="stringliteral">"and Master calibration frames:\n"</span>;
+<a name="l00099"></a>00099 
+<a name="l00100"></a>00100 
+<a name="l00101"></a>00101 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_rec_jitter_description2[] =
+<a name="l00102"></a>00102 <span class="stringliteral">"A corresponding (band,preoptics) wavelength map image with tag WAVE_MAP\n"</span>
+<a name="l00103"></a>00103 <span class="stringliteral">"A corresponding (band,preoptics) master flat field with tag MASTER_FLAT_LAMP\n"</span>
+<a name="l00104"></a>00104 <span class="stringliteral">"A corresponding (band,preoptics) master bad pixel map with tag MASTER_BP_MAP\n"</span>
+<a name="l00105"></a>00105 <span class="stringliteral">"A corresponding (band,preoptics) slitlets position frame with tag SLIT_POS\n"</span>
+<a name="l00106"></a>00106 <span class="stringliteral">"A corresponding (band) distortion table with tag DISTORTION\n"</span>
+<a name="l00107"></a>00107 <span class="stringliteral">"A corresponding (band) slitlet distance table with tag SLITLETS_DISTANCE\n"</span>;
+<a name="l00108"></a>00108 
+<a name="l00109"></a>00109 
+<a name="l00110"></a>00110 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_rec_jitter_description3[] =
+<a name="l00111"></a>00111 <span class="stringliteral">"The output is an image resulting from the IMA1 op IMA2 where op indicates\n"</span>
+<a name="l00112"></a>00112 <span class="stringliteral">"A reference table with the position of the first "</span>
+<a name="l00113"></a>00113 <span class="stringliteral">"column with tag FIRST_COLUMN\n"</span>
+<a name="l00114"></a>00114 <span class="stringliteral">"Relevant outputs are:\n"</span>
+<a name="l00115"></a>00115 <span class="stringliteral">"combined cubes (PRO.CATG=x_OBS x=STD,OBJ,PSF)\n"</span>
+<a name="l00116"></a>00116 <span class="stringliteral">"reconstructed cube (PRO.CATG=COADD_x_OBS x=STD,OBJ,PSF)\n"</span>
+<a name="l00117"></a>00117 <span class="stringliteral">"An average along Z of the reconstructed cube \n"</span>
+<a name="l00118"></a>00118 <span class="stringliteral">"(PRO.CATG=MED_x_OBS x=STD,OBJ,PSF)\n"</span>
+<a name="l00119"></a>00119 <span class="stringliteral">"The bad pixel map associated to the cube \n"</span>
+<a name="l00120"></a>00120 <span class="stringliteral">"(PRO.CATG=BP_MAP_COADD_x_OBS x=STD,OBJ,PSF)\n"</span>;
+<a name="l00121"></a>00121 
+<a name="l00122"></a>00122 
+<a name="l00123"></a>00123 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_rec_jitter_description4[] =
+<a name="l00124"></a>00124 <span class="stringliteral">"Information on relevant parameters can be found with\n"</span>
+<a name="l00125"></a>00125 <span class="stringliteral">"esorex --params sinfo_rec_jitter\n"</span>
+<a name="l00126"></a>00126 <span class="stringliteral">"esorex --help sinfo_rec_jitter\n"</span>
+<a name="l00127"></a>00127 <span class="stringliteral">"\n"</span>;
+<a name="l00128"></a>00128 
+<a name="l00129"></a>00129 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_rec_jitter_description[1400];
+<a name="l00130"></a>00130 
+<a name="l00131"></a>00131 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00132"></a>00132 <span class="comment">                                Functions code</span>
+<a name="l00133"></a>00133 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00134"></a>00134 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00138"></a>00138 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00140"></a>00140 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00149"></a>00149 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00150"></a>00150 
+<a name="l00151"></a>00151 <span class="keywordtype">int</span>
+<a name="l00152"></a><a class="code" href="group__sinfo__rec__jitter.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693">00152</a> <a class="code" href="group__sinfo__rec__detlin.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693" title="Build the list of available plugins, for this module.">cpl_plugin_get_info</a>(cpl_pluginlist *list)
+<a name="l00153"></a>00153 {
+<a name="l00154"></a>00154 
+<a name="l00155"></a>00155   cpl_recipe *recipe = cpl_calloc(1, <span class="keyword">sizeof</span> *recipe);
+<a name="l00156"></a>00156   cpl_plugin *plugin = &recipe->interface;
+<a name="l00157"></a>00157 
+<a name="l00158"></a>00158   strcpy(sinfo_rec_jitter_description,sinfo_rec_jitter_description1);
+<a name="l00159"></a>00159   strcat(sinfo_rec_jitter_description,sinfo_rec_jitter_description2);
+<a name="l00160"></a>00160   strcat(sinfo_rec_jitter_description,sinfo_rec_jitter_description3);
+<a name="l00161"></a>00161   strcat(sinfo_rec_jitter_description,sinfo_rec_jitter_description4);
+<a name="l00162"></a>00162 
+<a name="l00163"></a>00163   cpl_plugin_init(plugin,
+<a name="l00164"></a>00164           CPL_PLUGIN_API,
+<a name="l00165"></a>00165           SINFONI_BINARY_VERSION,
+<a name="l00166"></a>00166           CPL_PLUGIN_TYPE_RECIPE,
+<a name="l00167"></a>00167           <span class="stringliteral">"sinfo_rec_jitter"</span>,
+<a name="l00168"></a>00168           <span class="stringliteral">"Object or STD star or PSF star data reduction"</span>,
+<a name="l00169"></a>00169            sinfo_rec_jitter_description,
+<a name="l00170"></a>00170           <span class="stringliteral">"Andrea Modigliani"</span>,
+<a name="l00171"></a>00171           <span class="stringliteral">"Andrea.Mdigliani at eso.org"</span>,
+<a name="l00172"></a>00172           sinfo_get_license(),
+<a name="l00173"></a>00173           sinfo_rec_jitter_create,
+<a name="l00174"></a>00174           sinfo_rec_jitter_exec,
+<a name="l00175"></a>00175           sinfo_rec_jitter_destroy);
+<a name="l00176"></a>00176 
+<a name="l00177"></a>00177   cpl_pluginlist_append(list, plugin);
+<a name="l00178"></a>00178 
+<a name="l00179"></a>00179   <span class="keywordflow">return</span> 0;
+<a name="l00180"></a>00180 
+<a name="l00181"></a>00181 }
+<a name="l00182"></a>00182 
+<a name="l00183"></a>00183 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00191"></a>00191 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00192"></a>00192 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_jitter_create(cpl_plugin *plugin)
+<a name="l00193"></a>00193 {
+<a name="l00194"></a>00194     cpl_recipe      * recipe ;
+<a name="l00195"></a>00195 
+<a name="l00196"></a>00196 
+<a name="l00197"></a>00197     <span class="comment">/* Check that the plugin is part of a valid recipe */</span>
+<a name="l00198"></a>00198     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
+<a name="l00199"></a>00199         recipe = (cpl_recipe *)plugin ;
+<a name="l00200"></a>00200     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00201"></a>00201   cpl_error_reset();
+<a name="l00202"></a>00202   <a class="code" href="group__irplib__utils.html#gaf9d392144014e2363054bc3f83c8e47e" title="Reset IRPLIB state.">irplib_reset</a>();
+<a name="l00203"></a>00203 
+<a name="l00204"></a>00204     <span class="comment">/* Create the parameters list in the cpl_recipe object */</span>
+<a name="l00205"></a>00205     recipe->parameters = cpl_parameterlist_new() ;
+<a name="l00206"></a>00206 
+<a name="l00207"></a>00207 
+<a name="l00208"></a>00208   <span class="comment">/*</span>
+<a name="l00209"></a>00209 <span class="comment">   * Fill the parameter list.</span>
+<a name="l00210"></a>00210 <span class="comment">   */</span>
+<a name="l00211"></a>00211 
+<a name="l00212"></a>00212   sinfo_general_config_add(recipe->parameters);
+<a name="l00213"></a>00213   sinfo_product_config_add(recipe->parameters);
+<a name="l00214"></a>00214   sinfo_prepare_stacked_frames_config_add(recipe->parameters);
+<a name="l00215"></a>00215   sinfo_objnod_config_add(recipe->parameters);
+<a name="l00216"></a>00216   sinfo_skycor_config_add(recipe->parameters);
+<a name="l00217"></a>00217   sinfo_standard_star_config_add(recipe->parameters);
+<a name="l00218"></a>00218   sinfo_psf_config_add(recipe->parameters);
+<a name="l00219"></a>00219 
+<a name="l00220"></a>00220 
+<a name="l00221"></a>00221 
+<a name="l00222"></a>00222   <span class="keywordflow">return</span> 0;
+<a name="l00223"></a>00223 
+<a name="l00224"></a>00224 }
+<a name="l00225"></a>00225 
+<a name="l00226"></a>00226 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00232"></a>00232 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00233"></a>00233 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_jitter_exec(cpl_plugin *plugin)
+<a name="l00234"></a>00234 {
+<a name="l00235"></a>00235 
+<a name="l00236"></a>00236   cpl_recipe *recipe = (cpl_recipe *) plugin;
+<a name="l00237"></a>00237 
+<a name="l00238"></a>00238     cpl_errorstate initial_errorstate = cpl_errorstate_get();
+<a name="l00239"></a>00239 
+<a name="l00240"></a>00240   <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00241"></a>00241   <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
+<a name="l00242"></a>00242       recipe = (cpl_recipe *)plugin ;
+<a name="l00243"></a>00243   <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00244"></a>00244 
+<a name="l00245"></a>00245     <span class="keywordflow">if</span> (!cpl_errorstate_is_equal(initial_errorstate)) {
+<a name="l00246"></a>00246         <span class="comment">/* Dump the error history since recipe execution start.</span>
+<a name="l00247"></a>00247 <span class="comment">           At this point the recipe cannot recover from the error */</span>
+<a name="l00248"></a>00248         cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
+<a name="l00249"></a>00249     }
+<a name="l00250"></a>00250   <span class="keywordflow">return</span> sinfo_rec_jitter(recipe->parameters, recipe->frames);
+<a name="l00251"></a>00251 
+<a name="l00252"></a>00252 }
+<a name="l00253"></a>00253 
+<a name="l00254"></a>00254 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00260"></a>00260 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00261"></a>00261 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_jitter_destroy(cpl_plugin *plugin)
+<a name="l00262"></a>00262 {
+<a name="l00263"></a>00263 
+<a name="l00264"></a>00264    cpl_recipe  *   recipe ;
+<a name="l00265"></a>00265 
+<a name="l00266"></a>00266     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00267"></a>00267     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
+<a name="l00268"></a>00268         recipe = (cpl_recipe *)plugin ;
+<a name="l00269"></a>00269     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00270"></a>00270 
+<a name="l00271"></a>00271   cpl_parameterlist_delete(recipe->parameters);
+<a name="l00272"></a>00272 
+<a name="l00273"></a>00273   <span class="keywordflow">return</span> 0;
+<a name="l00274"></a>00274 
+<a name="l00275"></a>00275 }
+<a name="l00276"></a>00276 
+<a name="l00277"></a>00277 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00284"></a>00284 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00285"></a>00285 
+<a name="l00286"></a>00286 <span class="comment">/*</span>
+<a name="l00287"></a>00287 <span class="comment"> * The actual recipe actually start here.</span>
+<a name="l00288"></a>00288 <span class="comment"> */</span>
+<a name="l00289"></a>00289 
+<a name="l00290"></a>00290 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_jitter(cpl_parameterlist *config, cpl_frameset *<span class="keyword">set</span>)
+<a name="l00291"></a>00291 {
+<a name="l00292"></a>00292   <span class="keyword">const</span> <span class="keywordtype">char</span>* pro_ctg_cube;
+<a name="l00293"></a>00293   cpl_parameter* p=NULL;
+<a name="l00294"></a>00294   <span class="keywordtype">int</span> psf_sw=0;
+<a name="l00295"></a>00295   <span class="keywordtype">int</span> std_sw=0;
+<a name="l00296"></a>00296   cpl_frameset* ref_set=NULL;
+<a name="l00297"></a>00297   <span class="keywordtype">int</span> line_cor=0;
+<a name="l00298"></a>00298 
+<a name="l00299"></a>00299   sinfo_msg(<span class="stringliteral">"Welcome to SINFONI Pipeline release %d.%d.%d"</span>,
+<a name="l00300"></a>00300         SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
+<a name="l00301"></a>00301 
+<a name="l00302"></a>00302   <span class="keywordflow">if</span>(sinfo_dfs_set_groups(<span class="keyword">set</span>)) {
+<a name="l00303"></a>00303     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Cannot indentify RAW and CALIB frames"</span>) ;
+<a name="l00304"></a>00304     <span class="keywordflow">return</span> -1;
+<a name="l00305"></a>00305   }
+<a name="l00306"></a>00306 
+<a name="l00307"></a>00307   check_nomsg(p=cpl_parameterlist_find(config, <span class="stringliteral">"sinfoni.general.lc_sw"</span>));
+<a name="l00308"></a>00308   check_nomsg(line_cor=cpl_parameter_get_bool(p));
+<a name="l00309"></a>00309   <span class="keywordflow">if</span>(line_cor==1) {
+<a name="l00310"></a>00310      check_nomsg(sinfo_ima_line_cor(config,<span class="keyword">set</span>));
+<a name="l00311"></a>00311   }
+<a name="l00312"></a>00312 
+<a name="l00313"></a>00313   check_nomsg(ref_set=cpl_frameset_duplicate(<span class="keyword">set</span>));
+<a name="l00314"></a>00314   <span class="comment">/* ===============================================================</span>
+<a name="l00315"></a>00315 <span class="comment">     Defines several framesets each with a pair obj-sky,</span>
+<a name="l00316"></a>00316 <span class="comment">     stack each pair, put the results in set</span>
+<a name="l00317"></a>00317 <span class="comment">     =============================================================== */</span>
+<a name="l00318"></a>00318   ck0(sinfo_cub_stk_frames(config,&<span class="keyword">set</span>,cpl_func,&pro_ctg_cube),
+<a name="l00319"></a>00319       <span class="stringliteral">"Cannot stack RAW frames"</span>) ;
+<a name="l00320"></a>00320 
+<a name="l00321"></a>00321   <span class="comment">/* ===============================================================</span>
+<a name="l00322"></a>00322 <span class="comment">     SCI OBJNOD</span>
+<a name="l00323"></a>00323 <span class="comment">     =============================================================== */</span>
+<a name="l00324"></a>00324      sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ;
+<a name="l00325"></a>00325      sinfo_msg(<span class="stringliteral">"COADDING CUBES"</span>);
+<a name="l00326"></a>00326      sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ;
+<a name="l00327"></a>00327      ck0(sinfo_new_cubes_coadd(cpl_func,config, <span class="keyword">set</span>, pro_ctg_cube),
+<a name="l00328"></a>00328      <span class="stringliteral">"COADDING CUBES"</span>) ;
+<a name="l00329"></a>00329 
+<a name="l00330"></a>00330      sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ;
+<a name="l00331"></a>00331      sinfo_msg(<span class="stringliteral">"COADDED CUBES"</span>);
+<a name="l00332"></a>00332      sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ;
+<a name="l00333"></a>00333 
+<a name="l00334"></a>00334   <span class="comment">/* ===============================================================</span>
+<a name="l00335"></a>00335 <span class="comment">     PSF</span>
+<a name="l00336"></a>00336 <span class="comment">     =============================================================== */</span>
+<a name="l00337"></a>00337 
+<a name="l00338"></a>00338   <span class="keywordflow">if</span>((strcmp(pro_ctg_cube,PRO_COADD_PSF) == 0) ||
+<a name="l00339"></a>00339      (strcmp(pro_ctg_cube,PRO_COADD_STD) == 0) ||
+<a name="l00340"></a>00340      (strcmp(pro_ctg_cube,PRO_COADD_PUPIL) == 0) ) {
+<a name="l00341"></a>00341 
+<a name="l00342"></a>00342 
+<a name="l00343"></a>00343     p = cpl_parameterlist_find(config, <span class="stringliteral">"sinfoni.psf.switch"</span>);
+<a name="l00344"></a>00344     psf_sw = cpl_parameter_get_bool(p);
+<a name="l00345"></a>00345     sinfo_msg(<span class="stringliteral">"switch=%d"</span>,psf_sw);
+<a name="l00346"></a>00346     <span class="keywordflow">if</span>(psf_sw) {
+<a name="l00347"></a>00347       sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ;
+<a name="l00348"></a>00348       sinfo_msg(<span class="stringliteral">"REDUCE PSF STD STAR FRAMES"</span>);
+<a name="l00349"></a>00349       sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ;
+<a name="l00350"></a>00350       <span class="keywordflow">if</span> ( -1 == sinfo_new_psf(cpl_func,config,<span class="keyword">set</span>,<span class="keyword">set</span>) ) {
+<a name="l00351"></a>00351     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"REDUCING PSF STD STAR FRAMES"</span>) ;
+<a name="l00352"></a>00352         cpl_error_reset();
+<a name="l00353"></a>00353       } <span class="keywordflow">else</span> {
+<a name="l00354"></a>00354     sinfo_msg(<span class="stringliteral">"SUCCESS REDUCE PSF STD STAR FRAMES"</span>) ;
+<a name="l00355"></a>00355       }
+<a name="l00356"></a>00356     }
+<a name="l00357"></a>00357 
+<a name="l00358"></a>00358     p = cpl_parameterlist_find(config, <span class="stringliteral">"sinfoni.std_star.switch"</span>);
+<a name="l00359"></a>00359     std_sw = cpl_parameter_get_bool(p);
+<a name="l00360"></a>00360     sinfo_msg(<span class="stringliteral">"switch=%d"</span>,std_sw);
+<a name="l00361"></a>00361     <span class="keywordflow">if</span>(std_sw) {
+<a name="l00362"></a>00362       sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ;
+<a name="l00363"></a>00363       sinfo_msg(<span class="stringliteral">"STD STAR DATA REDUCTION"</span>);
+<a name="l00364"></a>00364       sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ;
+<a name="l00365"></a>00365       <span class="keywordflow">if</span> ( -1 == sinfo_new_stdstar(cpl_func,config, <span class="keyword">set</span>,<span class="keyword">set</span> ) ) {
+<a name="l00366"></a>00366     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"REDUCING STD STAR DATA"</span>) ;
+<a name="l00367"></a>00367         cpl_error_reset();
+<a name="l00368"></a>00368       } <span class="keywordflow">else</span> {
+<a name="l00369"></a>00369     sinfo_msg(<span class="stringliteral">"STD STAR DATA REDUCTION SUCCESS"</span>) ;
+<a name="l00370"></a>00370       }
+<a name="l00371"></a>00371     }
+<a name="l00372"></a>00372   }
+<a name="l00373"></a>00373 
+<a name="l00374"></a>00374  cleanup:
+<a name="l00375"></a>00375   sinfo_free_frameset(&ref_set);
+<a name="l00376"></a>00376   <span class="keywordflow">if</span> (cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l00377"></a>00377     sinfo_check_rec_status(0);
+<a name="l00378"></a>00378     <span class="keywordflow">return</span> -1;
+<a name="l00379"></a>00379   } <span class="keywordflow">else</span> {
+<a name="l00380"></a>00380     <span class="keywordflow">return</span> 0;
+<a name="l00381"></a>00381   }
+<a name="l00382"></a>00382 
+<a name="l00383"></a>00383 
+<a name="l00384"></a>00384 }
+<a name="l00385"></a>00385 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__rec__lingain_8c_source.html b/html/sinfo__rec__lingain_8c_source.html
new file mode 100644
index 0000000..a855cef
--- /dev/null
+++ b/html/sinfo__rec__lingain_8c_source.html
@@ -0,0 +1,183 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_rec_lingain.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_rec_lingain.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_rec_lingain.c,v 1.22 2012/03/03 10:38:03 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the DETMON Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2012/03/03 10:38:03 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.22 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span>
+<a name="l00032"></a>00032 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                             Includes and Defines</span>
+<a name="l00034"></a>00034 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 
+<a name="l00036"></a>00036 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include "sinfo_irplib_cpl_wrp.h"</span>
+<a name="l00038"></a>00038 
+<a name="l00039"></a>00039 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include "sinfo_utils_wrappers.h"</span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include "sinfo_error.h"</span>
+<a name="l00042"></a>00042 
+<a name="l00043"></a>00043 <span class="comment">/* Define here the DO.CATG keywords */</span>
+<a name="l00044"></a>00044 <span class="preprocessor">#define SINFO_LINGAIN_ON_RAW                    "LINEARITY_LAMP_ON"</span>
+<a name="l00045"></a>00045 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_LINGAIN_OFF_RAW           "LINEARITY_LAMP_OFF"</span>
+<a name="l00046"></a>00046 <span class="preprocessor"></span>
+<a name="l00047"></a>00047 <span class="preprocessor">#define RECIPE_NAME "sinfo_rec_lingain"</span>
+<a name="l00048"></a>00048 <span class="preprocessor"></span>
+<a name="l00049"></a>00049 <span class="comment">/* Copy here instrument specific keywords which need to be in the PAF file */</span>
+<a name="l00050"></a>00050 <span class="preprocessor">#define INSTREGEXP   "ESO INS SETUP ID"</span>
+<a name="l00051"></a>00051 <span class="preprocessor"></span>
+<a name="l00052"></a>00052 <span class="preprocessor">#define PAFREGEXP    "^(" REGEXP "|" INSTREGEXP ")$"</span>
+<a name="l00053"></a>00053 <span class="preprocessor"></span><span class="preprocessor">#define NIR TRUE</span>
+<a name="l00054"></a>00054 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_BPMBIN 1</span>
+<a name="l00055"></a>00055 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_KAPPA 9</span>
+<a name="l00056"></a>00056 <span class="preprocessor"></span>
+<a name="l00057"></a>00057 
+<a name="l00058"></a>00058 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00059"></a>00059 <span class="comment">                 Functions prototypes</span>
+<a name="l00060"></a>00060 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00061"></a>00061 
+<a name="l00063"></a>00063 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00067"></a>00067 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00068"></a>00068 
+<a name="l00069"></a>00069 cpl_error_code
+<a name="l00070"></a>00070 sinfo_lingain_fill_parlist_default(cpl_parameterlist * parlist);
+<a name="l00071"></a>00071 
+<a name="l00072"></a>00072 CPL_RECIPE_DEFINE(sinfo_rec_lingain, SINFONI_BINARY_VERSION,
+<a name="l00073"></a>00073              <span class="comment">/* Replace DETMON_BINARY_VERSION with</span>
+<a name="l00074"></a>00074 <span class="comment">            corresponding pipeline macro */</span>
+<a name="l00075"></a>00075                      sinfo_lingain_fill_parlist_default(recipe->parameters),
+<a name="l00076"></a>00076              <span class="comment">/* Replace "sinfoni" with PACKAGE_TARNAME</span>
+<a name="l00077"></a>00077 <span class="comment">            when moved into SINFONI */</span>
+<a name="l00078"></a>00078                      <span class="stringliteral">"Lander de Bilbao"</span>, <span class="stringliteral">"lbilbao at eso.org"</span>, <span class="stringliteral">"2008"</span>,
+<a name="l00079"></a>00079                      <span class="stringliteral">"Linearity/Gain recipe for the IR domain"</span>,
+<a name="l00080"></a>00080                      LG_DESCR(RECIPE_NAME, <span class="stringliteral">"SINFONI"</span>,
+<a name="l00081"></a>00081                                                       SINFO_LINGAIN_ON_RAW,
+<a name="l00082"></a>00082                                                       SINFO_LINGAIN_OFF_RAW));
+<a name="l00083"></a>00083 
+<a name="l00084"></a>00084 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00085"></a>00085 <span class="comment">/*</span>
+<a name="l00086"></a>00086 <span class="comment">  @brief    Interpret the command line options and execute the data processing</span>
+<a name="l00087"></a>00087 <span class="comment">  @param    frameset    the frames list</span>
+<a name="l00088"></a>00088 <span class="comment">  @param    parlist     the parameters list</span>
+<a name="l00089"></a>00089 <span class="comment">  @return   0 if everything is ok</span>
+<a name="l00090"></a>00090 <span class="comment"> */</span>
+<a name="l00091"></a>00091 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00092"></a>00092 
+<a name="l00093"></a>00093 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_lingain(cpl_frameset            * frameset,
+<a name="l00094"></a>00094              <span class="keyword">const</span> cpl_parameterlist * parlist)
+<a name="l00095"></a>00095 {
+<a name="l00096"></a>00096   <span class="keyword">const</span> <span class="keywordtype">char</span>* name_o=NULL;
+<a name="l00097"></a>00097   cpl_frame* frm=NULL;
+<a name="l00098"></a>00098   cpl_image* ima=NULL;
+<a name="l00099"></a>00099   cpl_error_code error = CPL_ERROR_NONE;
+<a name="l00100"></a>00100   cpl_propertylist* plist=NULL;
+<a name="l00101"></a>00101    cpl_propertylist * lintbl;
+<a name="l00102"></a>00102    cpl_propertylist * gaintbl;
+<a name="l00103"></a>00103    cpl_propertylist * coeffscube;
+<a name="l00104"></a>00104    cpl_propertylist * bpm;
+<a name="l00105"></a>00105    cpl_propertylist * corr;
+<a name="l00106"></a>00106    cpl_propertylist * diff_flat;
+<a name="l00107"></a>00107 
+<a name="l00108"></a>00108 
+<a name="l00109"></a>00109    lintbl =  DETMON_FILL_PROLIST(<span class="stringliteral">"DET_LIN_INFO"</span>, <span class="stringliteral">"TYPE"</span>, <span class="stringliteral">"TECH"</span>, CPL_TRUE);
+<a name="l00110"></a>00110    gaintbl = DETMON_FILL_PROLIST(<span class="stringliteral">"GAIN_INFO"</span>,    <span class="stringliteral">"TYPE"</span>, <span class="stringliteral">"TECH"</span>, CPL_TRUE);
+<a name="l00111"></a>00111    coeffscube = DETMON_FILL_PROLIST(<span class="stringliteral">"COEFFS_CUBE"</span>,  <span class="stringliteral">"TYPE"</span>, <span class="stringliteral">"TECH"</span>, CPL_TRUE);
+<a name="l00112"></a>00112    bpm = DETMON_FILL_PROLIST(<span class="stringliteral">"BP_MAP_NL"</span>,    <span class="stringliteral">"TYPE"</span>, <span class="stringliteral">"TECH"</span>, CPL_TRUE);
+<a name="l00113"></a>00113    corr = DETMON_FILL_PROLIST(<span class="stringliteral">"AUTOCORR"</span>,     <span class="stringliteral">"TYPE"</span>, <span class="stringliteral">"TECH"</span>, CPL_TRUE);
+<a name="l00114"></a>00114    diff_flat = DETMON_FILL_PROLIST(<span class="stringliteral">"DIFF_FLAT"</span>,    <span class="stringliteral">"TYPE"</span>, <span class="stringliteral">"TECH"</span>, CPL_TRUE);
+<a name="l00115"></a>00115 
+<a name="l00116"></a>00116    error = DETMON_LG(frameset,
+<a name="l00117"></a>00117                                                   parlist,
+<a name="l00118"></a>00118                                                   SINFO_LINGAIN_ON_RAW,
+<a name="l00119"></a>00119                                                   SINFO_LINGAIN_OFF_RAW,
+<a name="l00120"></a>00120                                                   RECIPE_NAME,
+<a name="l00121"></a>00121     <span class="comment">/* Replace this string ("sinfoni") with */</span>    PACKAGE_TARNAME,
+<a name="l00122"></a>00122     <span class="comment">/* PACKAGE_TARNAME when moved into SINFONI */</span> PAFREGEXP,
+<a name="l00123"></a>00123                                                   lintbl, gaintbl,
+<a name="l00124"></a>00124                                               coeffscube, bpm,
+<a name="l00125"></a>00125                           corr, diff_flat,
+<a name="l00126"></a>00126                                                   PACKAGE <span class="stringliteral">"/"</span> PACKAGE_VERSION,
+<a name="l00127"></a>00127                                                   NULL, NULL, NIR);
+<a name="l00128"></a>00128     sinfo_free_propertylist(&lintbl);
+<a name="l00129"></a>00129     sinfo_free_propertylist(&gaintbl);
+<a name="l00130"></a>00130     sinfo_free_propertylist(&coeffscube);
+<a name="l00131"></a>00131     sinfo_free_propertylist(&bpm);
+<a name="l00132"></a>00132     sinfo_free_propertylist(&corr);
+<a name="l00133"></a>00133     sinfo_free_propertylist(&diff_flat);
+<a name="l00134"></a>00134 
+<a name="l00135"></a>00135     check_nomsg(frm=cpl_frameset_find(frameset,<span class="stringliteral">"BP_MAP_NL"</span>));
+<a name="l00136"></a>00136     check_nomsg(name_o=cpl_frame_get_filename(frm));
+<a name="l00137"></a>00137     check_nomsg(plist=cpl_propertylist_load(name_o,0));
+<a name="l00138"></a>00138     check_nomsg(ima=cpl_image_load(name_o,CPL_TYPE_FLOAT,0,0));
+<a name="l00139"></a>00139     check_nomsg(cpl_image_threshold(ima,0.1,0.9,1,0));
+<a name="l00140"></a>00140     check_nomsg(cpl_image_save(ima,name_o,CPL_BPP_IEEE_FLOAT,plist,CPL_IO_DEFAULT));
+<a name="l00141"></a>00141 
+<a name="l00142"></a>00142   cleanup:
+<a name="l00143"></a>00143     sinfo_free_propertylist(&plist);
+<a name="l00144"></a>00144     sinfo_free_image(&ima);
+<a name="l00145"></a>00145 
+<a name="l00146"></a>00146     <span class="comment">/* Propagate the error, if any */</span>
+<a name="l00147"></a>00147     cpl_ensure_code(!error, error);
+<a name="l00148"></a>00148 
+<a name="l00149"></a>00149     <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l00150"></a>00150 }
+<a name="l00151"></a>00151 
+<a name="l00152"></a>00152 cpl_error_code
+<a name="l00153"></a>00153 sinfo_lingain_fill_parlist_default(cpl_parameterlist * parlist)
+<a name="l00154"></a>00154 {
+<a name="l00155"></a>00155 
+<a name="l00156"></a>00156    cpl_error_code error = CPL_ERROR_NONE;
+<a name="l00157"></a>00157    cpl_parameter * p;
+<a name="l00158"></a>00158    error = DETMON_LG_FILL_PARLIST_NIR_DEFAULT(parlist,RECIPE_NAME,
+<a name="l00159"></a>00159                                                  PACKAGE_TARNAME);
+<a name="l00160"></a>00160     cpl_ensure_code(!error, error);
+<a name="l00161"></a>00161     p = cpl_parameterlist_find(parlist, PACKAGE_TARNAME <span class="stringliteral">"."</span> RECIPE_NAME <span class="stringliteral">".bpmbin"</span>);
+<a name="l00162"></a>00162     cpl_ensure_code(p != NULL, CPL_ERROR_DATA_NOT_FOUND);
+<a name="l00163"></a>00163     error = cpl_parameter_set_default_bool(p, SINFO_BPMBIN);
+<a name="l00164"></a>00164     p = cpl_parameterlist_find(parlist, PACKAGE_TARNAME <span class="stringliteral">"."</span> RECIPE_NAME <span class="stringliteral">".kappa"</span>);
+<a name="l00165"></a>00165     cpl_ensure_code(p != NULL, CPL_ERROR_DATA_NOT_FOUND);
+<a name="l00166"></a>00166     error = cpl_parameter_set_default_double(p, SINFO_KAPPA);
+<a name="l00167"></a>00167     cpl_ensure_code(!error, error);
+<a name="l00168"></a>00168     <span class="keywordflow">return</span> error;
+<a name="l00169"></a>00169 
+<a name="l00170"></a>00170 }
+<a name="l00171"></a>00171 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__rec__mdark_8c_source.html b/html/sinfo__rec__mdark_8c_source.html
new file mode 100644
index 0000000..b518bcc
--- /dev/null
+++ b/html/sinfo__rec__mdark_8c_source.html
@@ -0,0 +1,424 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_rec_mdark.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_rec_mdark.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_rec_mdark.c,v 1.22 2008/02/28 10:36:10 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the SINFONI Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2008/02/28 10:36:10 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.22 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028  <span class="comment">/****************************************************************</span>
+<a name="l00029"></a>00029 <span class="comment">  *          Dark Frames Data Reduction                          *</span>
+<a name="l00030"></a>00030 <span class="comment">  ****************************************************************/</span>
+<a name="l00031"></a>00031 
+<a name="l00032"></a>00032 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00033"></a>00033 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>          <span class="comment">/* allows the program compilation */</span>
+<a name="l00034"></a>00034 <span class="preprocessor">#endif</span>
+<a name="l00035"></a>00035 <span class="preprocessor"></span>
+<a name="l00036"></a>00036 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00037"></a>00037 <span class="comment">                                Includes</span>
+<a name="l00038"></a>00038 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00039"></a>00039 
+<a name="l00040"></a>00040 <span class="comment">/* std */</span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include <strings.h></span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include <string.h></span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include <stdio.h></span>
+<a name="l00044"></a>00044 
+<a name="l00045"></a>00045 <span class="comment">/* cpl */</span>
+<a name="l00046"></a>00046 <span class="preprocessor">#include <cpl.h></span>    
+<a name="l00047"></a>00047 
+<a name="l00048"></a>00048 <span class="comment">/* irplib */</span>
+<a name="l00049"></a>00049 <span class="preprocessor">#include <irplib_utils.h></span>
+<a name="l00050"></a>00050 
+<a name="l00051"></a>00051 <span class="comment">/* sinfoni */</span>
+<a name="l00052"></a>00052 <span class="preprocessor">#include <sinfo_bp_noise.h></span> <span class="comment">/* */</span>
+<a name="l00053"></a>00053 <span class="preprocessor">#include <sinfo_new_dark.h></span>     <span class="comment">/*  */</span> 
+<a name="l00054"></a>00054 <span class="preprocessor">#include <sinfo_utilities.h></span>
+<a name="l00055"></a>00055 <span class="preprocessor">#include <sinfo_general_config.h></span>
+<a name="l00056"></a>00056 <span class="preprocessor">#include <sinfo_bp_config.h></span>
+<a name="l00057"></a>00057 <span class="preprocessor">#include <sinfo_bp_noise_config.h></span>
+<a name="l00058"></a>00058 <span class="preprocessor">#include <sinfo_dark_config.h></span> 
+<a name="l00059"></a>00059 <span class="preprocessor">#include <sinfo_tpl_utils.h></span>
+<a name="l00060"></a>00060 <span class="preprocessor">#include <sinfo_tpl_dfs.h></span>
+<a name="l00061"></a>00061 <span class="preprocessor">#include <sinfo_pfits.h></span>
+<a name="l00062"></a>00062 <span class="preprocessor">#include <sinfo_functions.h></span>
+<a name="l00063"></a>00063 <span class="preprocessor">#include <sinfo_pfits.h></span>
+<a name="l00064"></a>00064 <span class="preprocessor">#include <sinfo_msg.h></span>
+<a name="l00065"></a>00065 <span class="preprocessor">#include <sinfo_error.h></span>
+<a name="l00066"></a>00066 <span class="preprocessor">#include <sinfo_utils_wrappers.h></span>
+<a name="l00067"></a>00067 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00068"></a>00068 <span class="comment">                            Functions prototypes</span>
+<a name="l00069"></a>00069 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00070"></a>00070 
+<a name="l00071"></a>00071 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_mdark_create(cpl_plugin *plugin);
+<a name="l00072"></a>00072 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_mdark_exec(cpl_plugin *plugin);
+<a name="l00073"></a>00073 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_mdark_destroy(cpl_plugin *plugin);
+<a name="l00074"></a>00074 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_mdark(cpl_parameterlist *config, cpl_frameset *<span class="keyword">set</span>);
+<a name="l00075"></a>00075 <span class="keyword">static</span> <span class="keywordtype">int</span> count_diff_ndit(cpl_frameset *<span class="keyword">set</span>, cpl_vector** dit_val);
+<a name="l00076"></a>00076 
+<a name="l00077"></a>00077 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00078"></a>00078 <span class="comment">                            Static variables</span>
+<a name="l00079"></a>00079 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00080"></a>00080 
+<a name="l00081"></a>00081 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_rec_mdark_description[] =
+<a name="l00082"></a>00082 <span class="stringliteral">"This recipe perform raw sinfo_dark data reduction.\n"</span>
+<a name="l00083"></a>00083 <span class="stringliteral">"The input files are raw sinfo_dark images\n"</span>
+<a name="l00084"></a>00084 <span class="stringliteral">"Their associated tags should be DARK.\n"</span>
+<a name="l00085"></a>00085 <span class="stringliteral">"The output are a master sinfo_dark (PRO.CATG=MASTER_DARK) and\n"</span>
+<a name="l00086"></a>00086 <span class="stringliteral">"a hot pixels bad pixel map (PRO.CATG=BP_MAP_HP)\n"</span>
+<a name="l00087"></a>00087 <span class="stringliteral">"Information on relevant parameters may be found with\n"</span>
+<a name="l00088"></a>00088 <span class="stringliteral">"esorex --params sinfo_rec_mdark\n"</span>
+<a name="l00089"></a>00089 <span class="stringliteral">"esorex --help sinfo_rec_mdark\n"</span>
+<a name="l00090"></a>00090 <span class="stringliteral">"\n"</span>;
+<a name="l00091"></a>00091 
+<a name="l00092"></a>00092 
+<a name="l00093"></a>00093 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00094"></a>00094 <span class="comment">                                Functions code</span>
+<a name="l00095"></a>00095 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00096"></a>00096 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00100"></a>00100 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00102"></a>00102 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00111"></a>00111 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00112"></a>00112 <span class="keywordtype">int</span>
+<a name="l00113"></a><a class="code" href="group__sinfo__rec__mdark.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693">00113</a> <a class="code" href="group__sinfo__rec__detlin.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693" title="Build the list of available plugins, for this module.">cpl_plugin_get_info</a>(cpl_pluginlist *list)
+<a name="l00114"></a>00114 {
+<a name="l00115"></a>00115 
+<a name="l00116"></a>00116   cpl_recipe *recipe = cpl_calloc(1, <span class="keyword">sizeof</span> *recipe);
+<a name="l00117"></a>00117   cpl_plugin *plugin = &recipe->interface;
+<a name="l00118"></a>00118 
+<a name="l00119"></a>00119 
+<a name="l00120"></a>00120   cpl_plugin_init(plugin,
+<a name="l00121"></a>00121           CPL_PLUGIN_API,
+<a name="l00122"></a>00122           SINFONI_BINARY_VERSION,
+<a name="l00123"></a>00123           CPL_PLUGIN_TYPE_RECIPE,
+<a name="l00124"></a>00124           <span class="stringliteral">"sinfo_rec_mdark"</span>,
+<a name="l00125"></a>00125           <span class="stringliteral">"Master dark and hot pixels mask generation."</span>,
+<a name="l00126"></a>00126           sinfo_rec_mdark_description,
+<a name="l00127"></a>00127           <span class="stringliteral">"Andrea Modigliani"</span>,
+<a name="l00128"></a>00128           <span class="stringliteral">"Andrea.Modigliani at eso.org"</span>,
+<a name="l00129"></a>00129           sinfo_get_license(),
+<a name="l00130"></a>00130           sinfo_rec_mdark_create,
+<a name="l00131"></a>00131           sinfo_rec_mdark_exec,
+<a name="l00132"></a>00132           sinfo_rec_mdark_destroy);
+<a name="l00133"></a>00133 
+<a name="l00134"></a>00134   cpl_pluginlist_append(list, plugin);
+<a name="l00135"></a>00135 
+<a name="l00136"></a>00136   <span class="keywordflow">return</span> 0;
+<a name="l00137"></a>00137 
+<a name="l00138"></a>00138 }
+<a name="l00139"></a>00139 
+<a name="l00140"></a>00140 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00148"></a>00148 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00149"></a>00149 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_mdark_create(cpl_plugin *plugin)
+<a name="l00150"></a>00150 {
+<a name="l00151"></a>00151     cpl_recipe      * recipe ;
+<a name="l00152"></a>00152 
+<a name="l00153"></a>00153     <span class="comment">/* Check that the plugin is part of a valid recipe */</span>
+<a name="l00154"></a>00154     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00155"></a>00155         recipe = (cpl_recipe *)plugin ;
+<a name="l00156"></a>00156     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00157"></a>00157     cpl_error_reset();
+<a name="l00158"></a>00158     <a class="code" href="group__irplib__utils.html#gaf9d392144014e2363054bc3f83c8e47e" title="Reset IRPLIB state.">irplib_reset</a>();
+<a name="l00159"></a>00159 
+<a name="l00160"></a>00160     <span class="comment">/* Create the parameters list in the cpl_recipe object */</span>
+<a name="l00161"></a>00161     recipe->parameters = cpl_parameterlist_new() ; 
+<a name="l00162"></a>00162 
+<a name="l00163"></a>00163 
+<a name="l00164"></a>00164   <span class="comment">/*</span>
+<a name="l00165"></a>00165 <span class="comment">   * Fill the parameter list.</span>
+<a name="l00166"></a>00166 <span class="comment">   */</span>
+<a name="l00167"></a>00167   sinfo_general_config_add(recipe->parameters);
+<a name="l00168"></a>00168   <a class="code" href="group__sinfo__bad__pix__search.html#gaa86bb476f2328523607038df849c2beb" title="Adds parameters for the spectrum extraction.">sinfo_bp_noise_config_add</a>(recipe->parameters);
+<a name="l00169"></a>00169   sinfo_dark_config_add(recipe->parameters);
+<a name="l00170"></a>00170   <span class="keywordflow">return</span> 0;
+<a name="l00171"></a>00171 
+<a name="l00172"></a>00172 }
+<a name="l00173"></a>00173 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00179"></a>00179 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00180"></a>00180 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_mdark_exec(cpl_plugin *plugin)
+<a name="l00181"></a>00181 {
+<a name="l00182"></a>00182     cpl_recipe  *   recipe ;
+<a name="l00183"></a>00183 
+<a name="l00184"></a>00184     cpl_errorstate initial_errorstate = cpl_errorstate_get();
+<a name="l00185"></a>00185 
+<a name="l00186"></a>00186     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00187"></a>00187     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00188"></a>00188         recipe = (cpl_recipe *)plugin ;
+<a name="l00189"></a>00189     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00190"></a>00190 
+<a name="l00191"></a>00191     <span class="keywordflow">if</span> (!cpl_errorstate_is_equal(initial_errorstate)) {                      
+<a name="l00192"></a>00192         <span class="comment">/* Dump the error history since recipe execution start.                </span>
+<a name="l00193"></a>00193 <span class="comment">           At this point the recipe cannot recover from the error */</span>           
+<a name="l00194"></a>00194         cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);              
+<a name="l00195"></a>00195     } 
+<a name="l00196"></a>00196 
+<a name="l00197"></a>00197     <span class="keywordflow">return</span> sinfo_rec_mdark(recipe->parameters, recipe->frames);
+<a name="l00198"></a>00198 
+<a name="l00199"></a>00199 }
+<a name="l00200"></a>00200 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00206"></a>00206 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00207"></a>00207 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_mdark_destroy(cpl_plugin *plugin)
+<a name="l00208"></a>00208 {
+<a name="l00209"></a>00209     cpl_recipe  *   recipe ;
+<a name="l00210"></a>00210     
+<a name="l00211"></a>00211     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00212"></a>00212     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00213"></a>00213         recipe = (cpl_recipe *)plugin ;
+<a name="l00214"></a>00214     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00215"></a>00215 
+<a name="l00216"></a>00216     cpl_parameterlist_delete(recipe->parameters) ; 
+<a name="l00217"></a>00217     <span class="keywordflow">return</span> 0 ;
+<a name="l00218"></a>00218 
+<a name="l00219"></a>00219 }
+<a name="l00220"></a>00220 
+<a name="l00221"></a>00221 
+<a name="l00222"></a>00222 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00229"></a>00229 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00230"></a>00230 <span class="comment">/*</span>
+<a name="l00231"></a>00231 <span class="comment"> * The actual recipe actually start here.</span>
+<a name="l00232"></a>00232 <span class="comment"> */</span>
+<a name="l00233"></a>00233 
+<a name="l00234"></a>00234 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00235"></a>00235 sinfo_rec_mdark(cpl_parameterlist *config, cpl_frameset *<span class="keyword">set</span>)
+<a name="l00236"></a>00236 {
+<a name="l00237"></a>00237  
+<a name="l00238"></a>00238   cpl_parameter* p=NULL;
+<a name="l00239"></a>00239   <span class="keywordtype">int</span> nset=0;
+<a name="l00240"></a>00240   cpl_frameset  * wrk_set=NULL;
+<a name="l00241"></a>00241   cpl_frameset  * cdb_set=NULL;
+<a name="l00242"></a>00242   cpl_frameset  * tot_set=NULL;
+<a name="l00243"></a>00243 
+<a name="l00244"></a>00244   cpl_frame* tmp_frm=NULL;
+<a name="l00245"></a>00245   cpl_frame* dup_frm=NULL;
+<a name="l00246"></a>00246   cpl_frame* cdb_frm=NULL;
+<a name="l00247"></a>00247 
+<a name="l00248"></a>00248   <span class="keywordtype">char</span> tmp_name[FILE_NAME_SZ];
+<a name="l00249"></a>00249   <span class="keywordtype">char</span> out_bpmap_name[FILE_NAME_SZ];
+<a name="l00250"></a>00250   <span class="keywordtype">char</span> out_dark_name[FILE_NAME_SZ];
+<a name="l00251"></a>00251   <span class="keywordtype">double</span> tmp_dit=0;
+<a name="l00252"></a>00252   <span class="keywordtype">double</span> ref_dit=0;
+<a name="l00253"></a>00253 
+<a name="l00254"></a>00254   cpl_vector* dit_val=NULL;
+<a name="l00255"></a>00255   cpl_propertylist* plist=NULL;
+<a name="l00256"></a>00256 
+<a name="l00257"></a>00257   <span class="keywordtype">int</span> i=0;
+<a name="l00258"></a>00258   <span class="keywordtype">int</span> j=0;
+<a name="l00259"></a>00259   <span class="keywordtype">int</span> line_cor=0;
+<a name="l00260"></a>00260 
+<a name="l00261"></a>00261 
+<a name="l00262"></a>00262   <span class="keywordtype">int</span> nraw=0;
+<a name="l00263"></a>00263   <span class="keywordtype">int</span> ncdb=0;
+<a name="l00264"></a>00264   <span class="keywordtype">int</span> nred=0;
+<a name="l00265"></a>00265   <span class="keywordtype">int</span> ntot=0;
+<a name="l00266"></a>00266   sinfo_msg(<span class="stringliteral">"Welcome to SINFONI Pipeline release %d.%d.%d"</span>,
+<a name="l00267"></a>00267         SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
+<a name="l00268"></a>00268   ck0(sinfo_dfs_set_groups(<span class="keyword">set</span>),<span class="stringliteral">"Cannot indentify RAW and CALIB frames"</span>);
+<a name="l00269"></a>00269 
+<a name="l00270"></a>00270   check_nomsg(p=cpl_parameterlist_find(config, <span class="stringliteral">"sinfoni.general.lc_sw"</span>));
+<a name="l00271"></a>00271   check_nomsg(line_cor=cpl_parameter_get_bool(p));
+<a name="l00272"></a>00272   <span class="keywordflow">if</span>(line_cor==1) {
+<a name="l00273"></a>00273      check_nomsg(sinfo_ima_line_cor(config,<span class="keyword">set</span>));
+<a name="l00274"></a>00274   }
+<a name="l00275"></a>00275 
+<a name="l00276"></a>00276 
+<a name="l00277"></a>00277   check_nomsg(cdb_set=cpl_frameset_new());
+<a name="l00278"></a>00278   check_nomsg(tot_set=cpl_frameset_new());
+<a name="l00279"></a>00279 
+<a name="l00280"></a>00280 
+<a name="l00281"></a>00281   sinfo_extract_mst_frames(<span class="keyword">set</span>,cdb_set);
+<a name="l00282"></a>00282   sinfo_bp_config_add(config);
+<a name="l00283"></a>00283   nset=count_diff_ndit(<span class="keyword">set</span>,&dit_val);
+<a name="l00284"></a>00284 
+<a name="l00285"></a>00285   check_nomsg(nraw=cpl_frameset_get_size(<span class="keyword">set</span>));
+<a name="l00286"></a>00286   check_nomsg(ncdb=cpl_frameset_get_size(cdb_set));
+<a name="l00287"></a>00287 
+<a name="l00288"></a>00288   <span class="keywordflow">for</span>(i=0;i<nset;i++) {
+<a name="l00289"></a>00289     check_nomsg(wrk_set=cpl_frameset_new());
+<a name="l00290"></a>00290     check_nomsg(ref_dit=cpl_vector_get(dit_val,i));
+<a name="l00291"></a>00291 
+<a name="l00292"></a>00292 
+<a name="l00293"></a>00293     <span class="keywordflow">for</span>(j=0;j<nraw;j++) {
+<a name="l00294"></a>00294       check_nomsg(tmp_frm=cpl_frameset_get_frame(<span class="keyword">set</span>,j));
+<a name="l00295"></a>00295       check_nomsg(strcpy(tmp_name,cpl_frame_get_filename(tmp_frm)));
+<a name="l00296"></a>00296       plist=cpl_propertylist_load(tmp_name,0);
+<a name="l00297"></a>00297       tmp_dit=sinfo_pfits_get_dit(plist);
+<a name="l00298"></a>00298       sinfo_free_propertylist(&plist);
+<a name="l00299"></a>00299 
+<a name="l00300"></a>00300       <span class="keywordflow">if</span>(tmp_dit==ref_dit) {
+<a name="l00301"></a>00301         check_nomsg(cpl_frameset_insert(wrk_set,cpl_frame_duplicate(tmp_frm)));
+<a name="l00302"></a>00302       }
+<a name="l00303"></a>00303     }
+<a name="l00304"></a>00304 
+<a name="l00305"></a>00305     <span class="keywordflow">for</span>(j=0;j<ncdb;j++) {
+<a name="l00306"></a>00306       check_nomsg(cdb_frm=cpl_frameset_get_frame(cdb_set,j));
+<a name="l00307"></a>00307       check_nomsg(cpl_frameset_insert(wrk_set,cpl_frame_duplicate(cdb_frm)));
+<a name="l00308"></a>00308     }
+<a name="l00309"></a>00309 
+<a name="l00310"></a>00310     <span class="comment">/* reduce data */</span>
+<a name="l00311"></a>00311     ck0(sinfo_dfs_set_groups(wrk_set),<span class="stringliteral">"Cannot indentify RAW and CALIB frames"</span>);
+<a name="l00312"></a>00312 
+<a name="l00313"></a>00313     <span class="comment">/* Hidden parameters */</span>
+<a name="l00314"></a>00314     check_nomsg(p = cpl_parameterlist_find(config,<span class="stringliteral">"sinfoni.bp.method"</span>));
+<a name="l00315"></a>00315     check_nomsg(cpl_parameter_set_string(p,<span class="stringliteral">"Noise"</span>));
+<a name="l00316"></a>00316     ck0(sinfo_dfs_set_groups(<span class="keyword">set</span>),<span class="stringliteral">"Cannot indentify RAW and CALIB frames"</span>) ;
+<a name="l00317"></a>00317  
+<a name="l00318"></a>00318     <span class="keywordflow">if</span> (nset>1) {
+<a name="l00319"></a>00319       sprintf(out_bpmap_name,<span class="stringliteral">"%s%d%s"</span>,<span class="stringliteral">"out_bp_noise"</span>,i,<span class="stringliteral">".fits"</span>);
+<a name="l00320"></a>00320     } <span class="keywordflow">else</span> {
+<a name="l00321"></a>00321       strcpy(out_bpmap_name,<span class="stringliteral">"out_bp_noise.fits"</span>);
+<a name="l00322"></a>00322     }
+<a name="l00323"></a>00323 
+<a name="l00324"></a>00324     sinfo_msg(<span class="stringliteral">"-----------------------------------------------"</span>);
+<a name="l00325"></a>00325     sinfo_msg(<span class="stringliteral">"BP_MAP_HP BAD PIXEL MAP DETERMINATION          "</span>);
+<a name="l00326"></a>00326     sinfo_msg(<span class="stringliteral">"-----------------------------------------------"</span>);
+<a name="l00327"></a>00327    
+<a name="l00328"></a>00328     ck0(sinfo_new_bp_search_noise(cpl_func,config,wrk_set,out_bpmap_name),
+<a name="l00329"></a>00329     <span class="stringliteral">"computing BP_MAP_HP"</span>) ;
+<a name="l00330"></a>00330     sinfo_msg(<span class="stringliteral">"BP_MAP_HP BAD PIXEL MAP DETERMINATION SUCCESS"</span>) ; 
+<a name="l00331"></a>00331     
+<a name="l00332"></a>00332     sinfo_msg(<span class="stringliteral">"-----------------------------------------------"</span>);
+<a name="l00333"></a>00333     sinfo_msg(<span class="stringliteral">"MASTER DARK DETERMINATION                      "</span>);
+<a name="l00334"></a>00334     sinfo_msg(<span class="stringliteral">"-----------------------------------------------"</span>);
+<a name="l00335"></a>00335 
+<a name="l00336"></a>00336     <span class="keywordflow">if</span> (nset>1) {
+<a name="l00337"></a>00337       sprintf(out_dark_name,<span class="stringliteral">"%s%d%s"</span>,<span class="stringliteral">"out_dark"</span>,i,<span class="stringliteral">".fits"</span>);
+<a name="l00338"></a>00338     } <span class="keywordflow">else</span> {
+<a name="l00339"></a>00339       strcpy(out_dark_name,<span class="stringliteral">"out_dark.fits"</span>);
+<a name="l00340"></a>00340     }
+<a name="l00341"></a>00341 
+<a name="l00342"></a>00342     ck0(sinfo_new_dark(cpl_func,config, wrk_set, out_dark_name),
+<a name="l00343"></a>00343      <span class="stringliteral">"Computing master dark"</span>) ;
+<a name="l00344"></a>00344     sinfo_msg(<span class="stringliteral">"MASTER DARK DETERMINATION SUCCESS"</span>) ;
+<a name="l00345"></a>00345 
+<a name="l00346"></a>00346     nred=cpl_frameset_get_size(wrk_set);
+<a name="l00347"></a>00347     <span class="keywordflow">for</span>(j=0;j<nred;j++) {
+<a name="l00348"></a>00348       check_nomsg(tmp_frm=cpl_frameset_get_frame(wrk_set,j));
+<a name="l00349"></a>00349       check_nomsg(cpl_frameset_insert(tot_set,cpl_frame_duplicate(tmp_frm)));
+<a name="l00350"></a>00350     }
+<a name="l00351"></a>00351     sinfo_free_frameset(&wrk_set);
+<a name="l00352"></a>00352 
+<a name="l00353"></a>00353   }
+<a name="l00354"></a>00354 
+<a name="l00355"></a>00355   check_nomsg(ntot=cpl_frameset_get_size(tot_set));
+<a name="l00356"></a>00356   <span class="keywordflow">for</span>(j=0;j<ntot;j++) {
+<a name="l00357"></a>00357     check_nomsg(tmp_frm=cpl_frameset_get_frame(tot_set,j));
+<a name="l00358"></a>00358     check_nomsg(cpl_frameset_insert(<span class="keyword">set</span>,cpl_frame_duplicate(tmp_frm)));
+<a name="l00359"></a>00359   }
+<a name="l00360"></a>00360 
+<a name="l00361"></a>00361   sinfo_free_frameset(&tot_set);
+<a name="l00362"></a>00362   sinfo_free_my_vector(&dit_val);
+<a name="l00363"></a>00363   sinfo_free_frameset(&cdb_set);
+<a name="l00364"></a>00364 
+<a name="l00365"></a>00365 
+<a name="l00366"></a>00366 
+<a name="l00367"></a>00367 
+<a name="l00368"></a>00368 
+<a name="l00369"></a>00369 
+<a name="l00370"></a>00370  cleanup:
+<a name="l00371"></a>00371 
+<a name="l00372"></a>00372   sinfo_free_propertylist(&plist);
+<a name="l00373"></a>00373   sinfo_free_frame(&dup_frm);
+<a name="l00374"></a>00374   sinfo_free_frameset(&wrk_set);
+<a name="l00375"></a>00375   sinfo_free_frameset(&tot_set);
+<a name="l00376"></a>00376   sinfo_free_my_vector(&dit_val);
+<a name="l00377"></a>00377   sinfo_free_frameset(&cdb_set);
+<a name="l00378"></a>00378 
+<a name="l00379"></a>00379 
+<a name="l00380"></a>00380   <span class="keywordflow">if</span> (cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l00381"></a>00381     <span class="keywordflow">return</span> -1;
+<a name="l00382"></a>00382   } <span class="keywordflow">else</span> {
+<a name="l00383"></a>00383     <span class="keywordflow">return</span> 0;
+<a name="l00384"></a>00384   }
+<a name="l00385"></a>00385 
+<a name="l00386"></a>00386 
+<a name="l00387"></a>00387 
+<a name="l00388"></a>00388 }
+<a name="l00389"></a>00389 
+<a name="l00390"></a>00390 <span class="keyword">static</span> <span class="keywordtype">int</span> count_diff_ndit(cpl_frameset *<span class="keyword">set</span>, cpl_vector** dit_val)
+<a name="l00391"></a>00391 {
+<a name="l00392"></a>00392   cpl_frame* tmp_frm=NULL;
+<a name="l00393"></a>00393   cpl_frame* dup_frm=NULL;
+<a name="l00394"></a>00394 
+<a name="l00395"></a>00395 
+<a name="l00396"></a>00396   <span class="keywordtype">char</span>  tmp_name[FILE_NAME_SZ];
+<a name="l00397"></a>00397   <span class="keywordtype">int</span> nraw=0;
+<a name="l00398"></a>00398   <span class="keywordtype">int</span> i=0;
+<a name="l00399"></a>00399   <span class="keywordtype">int</span> ndit=1;
+<a name="l00400"></a>00400   <span class="keywordtype">double</span> ref_dit=0;
+<a name="l00401"></a>00401   cpl_vector* dit=NULL; 
+<a name="l00402"></a>00402   cpl_propertylist* plist=NULL;
+<a name="l00403"></a>00403 
+<a name="l00404"></a>00404   nraw=cpl_frameset_get_size(<span class="keyword">set</span>);
+<a name="l00405"></a>00405   dit=cpl_vector_new(nraw);
+<a name="l00406"></a>00406   <span class="keywordflow">for</span>(i=0;i<nraw;i++) {
+<a name="l00407"></a>00407      tmp_frm = cpl_frameset_get_frame(<span class="keyword">set</span>, i);
+<a name="l00408"></a>00408      strcpy(tmp_name,cpl_frame_get_filename(tmp_frm));
+<a name="l00409"></a>00409      plist= cpl_propertylist_load(tmp_name,0);
+<a name="l00410"></a>00410      cpl_vector_set(dit,i,sinfo_pfits_get_dit(plist));
+<a name="l00411"></a>00411      sinfo_free_propertylist(&plist);
+<a name="l00412"></a>00412   }
+<a name="l00413"></a>00413 
+<a name="l00414"></a>00414 
+<a name="l00415"></a>00415   cpl_vector_sort(dit,1);
+<a name="l00416"></a>00416   ref_dit=cpl_vector_get(dit,0);
+<a name="l00417"></a>00417 
+<a name="l00418"></a>00418 
+<a name="l00419"></a>00419   <span class="keywordflow">for</span>(i=1;i<nraw;i++) {
+<a name="l00420"></a>00420     <span class="keywordflow">if</span>(ref_dit != cpl_vector_get(dit,i)) {
+<a name="l00421"></a>00421       ref_dit=cpl_vector_get(dit,i);
+<a name="l00422"></a>00422       ndit++;
+<a name="l00423"></a>00423     }
+<a name="l00424"></a>00424   }
+<a name="l00425"></a>00425   *dit_val=cpl_vector_new(ndit);
+<a name="l00426"></a>00426   ref_dit=cpl_vector_get(dit,0);
+<a name="l00427"></a>00427   cpl_vector_set(*dit_val,0,cpl_vector_get(dit,0));
+<a name="l00428"></a>00428   ndit=1;
+<a name="l00429"></a>00429 
+<a name="l00430"></a>00430    <span class="keywordflow">for</span>(i=1;i<nraw;i++) {
+<a name="l00431"></a>00431     <span class="keywordflow">if</span>(ref_dit != cpl_vector_get(dit,i)) {
+<a name="l00432"></a>00432       cpl_vector_set(*dit_val,ndit,cpl_vector_get(dit,i));
+<a name="l00433"></a>00433       ref_dit=cpl_vector_get(dit,i);
+<a name="l00434"></a>00434       ndit++;
+<a name="l00435"></a>00435     }
+<a name="l00436"></a>00436   }
+<a name="l00437"></a>00437 
+<a name="l00438"></a>00438   cpl_vector_delete(dit);
+<a name="l00439"></a>00439   cpl_frame_delete(dup_frm);
+<a name="l00440"></a>00440 
+<a name="l00441"></a>00441   <span class="keywordflow">return</span> ndit;
+<a name="l00442"></a>00442 }
+<a name="l00443"></a>00443 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__rec__mdark__detmon_8c_source.html b/html/sinfo__rec__mdark__detmon_8c_source.html
new file mode 100644
index 0000000..51b8bfb
--- /dev/null
+++ b/html/sinfo__rec__mdark__detmon_8c_source.html
@@ -0,0 +1,103 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_rec_mdark_detmon.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_rec_mdark_detmon.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_rec_mdark_detmon.c,v 1.4 2012/01/12 11:53:24 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the DETMON Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2012/01/12 11:53:24 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.4 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>
+<a name="l00029"></a>00029 <span class="preprocessor">#endif</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span>
+<a name="l00031"></a>00031 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00032"></a>00032 <span class="comment">                             Includes</span>
+<a name="l00033"></a>00033 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00034"></a>00034 
+<a name="l00035"></a>00035 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="preprocessor">#include "irplib_detmon.h"</span>
+<a name="l00038"></a>00038 <span class="preprocessor">#include "irplib_plugin.h"</span>
+<a name="l00039"></a>00039 
+<a name="l00040"></a>00040 <span class="comment">/* Define here the DO.CATG keywords */</span>
+<a name="l00041"></a>00041 <span class="preprocessor">#define SINFONI_DARK_RAW                    "DARK"</span>
+<a name="l00042"></a>00042 <span class="preprocessor"></span>
+<a name="l00043"></a>00043 <span class="preprocessor">#define RECIPE_NAME "sinfo_rec_mdark_detmon"</span>
+<a name="l00044"></a>00044 <span class="preprocessor"></span>
+<a name="l00045"></a>00045 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00046"></a>00046 <span class="comment">                Functions prototypes</span>
+<a name="l00047"></a>00047 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00048"></a>00048 
+<a name="l00049"></a>00049 CPL_RECIPE_DEFINE(sinfo_rec_mdark_detmon, SINFONI_BINARY_VERSION,
+<a name="l00050"></a>00050                      irplib_detmon_fill_dark_params_default(recipe->parameters,
+<a name="l00051"></a>00051                                                        <span class="stringliteral">"sinfo_rec_mdark_detmon"</span>,
+<a name="l00052"></a>00052                                                        <span class="stringliteral">"sinfo"</span>),
+<a name="l00053"></a>00053                      <span class="stringliteral">"Lander de Bilbao"</span>, <span class="stringliteral">"lbilbao at eso.org"</span>, <span class="stringliteral">"2008"</span>, 
+<a name="l00054"></a>00054                      <span class="stringliteral">"Master dark and detector signal non uniformity map"</span>,
+<a name="l00055"></a>00055                      irplib_detmon_dark_get_description(RECIPE_NAME,
+<a name="l00056"></a>00056                                                            <span class="stringliteral">"SINFONI"</span>,
+<a name="l00057"></a>00057                                                            SINFONI_DARK_RAW));
+<a name="l00058"></a>00058 
+<a name="l00059"></a>00059 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00060"></a>00060 <span class="comment">/*</span>
+<a name="l00061"></a>00061 <span class="comment">  @brief    Interpret the command line options and execute the data processing</span>
+<a name="l00062"></a>00062 <span class="comment">  @param    frameset    the frames list</span>
+<a name="l00063"></a>00063 <span class="comment">  @param    parlist     the parameters list</span>
+<a name="l00064"></a>00064 <span class="comment">  @return   0 if everything is ok</span>
+<a name="l00065"></a>00065 <span class="comment"> */</span>
+<a name="l00066"></a>00066 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00067"></a>00067 
+<a name="l00068"></a>00068 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_mdark_detmon(cpl_frameset            * frameset,
+<a name="l00069"></a>00069                <span class="keyword">const</span> cpl_parameterlist * parlist)
+<a name="l00070"></a>00070 {
+<a name="l00071"></a>00071     <span class="keyword">const</span> cpl_error_code error = irplib_detmon_dark(frameset,
+<a name="l00072"></a>00072                             parlist,
+<a name="l00073"></a>00073                             SINFONI_DARK_RAW,
+<a name="l00074"></a>00074                             RECIPE_NAME,
+<a name="l00075"></a>00075                             PACKAGE_TARNAME,
+<a name="l00076"></a>00076                             <span class="stringliteral">"MASTER_DARK"</span>,
+<a name="l00077"></a>00077                             <span class="stringliteral">"DSNU_MAP"</span>,
+<a name="l00078"></a>00078                             <span class="stringliteral">"DSNU_TABLE"</span>,
+<a name="l00079"></a>00079                                                        PACKAGE <span class="stringliteral">"/"</span> PACKAGE_VERSION,
+<a name="l00080"></a>00080                                                        NULL);
+<a name="l00081"></a>00081 
+<a name="l00082"></a>00082 
+<a name="l00083"></a>00083     <span class="comment">/* Propagate the error, if any */</span>
+<a name="l00084"></a>00084     cpl_ensure_code(!error, error);
+<a name="l00085"></a>00085 
+<a name="l00086"></a>00086     <span class="keywordflow">return</span> CPL_ERROR_NONE;
+<a name="l00087"></a>00087 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__rec__mflat_8c_source.html b/html/sinfo__rec__mflat_8c_source.html
new file mode 100644
index 0000000..7916662
--- /dev/null
+++ b/html/sinfo__rec__mflat_8c_source.html
@@ -0,0 +1,296 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_rec_mflat.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_rec_mflat.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_rec_mflat.c,v 1.22 2008/02/05 08:13:05 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the SINFONI Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2008/02/05 08:13:05 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.22 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> */</span>
+<a name="l00026"></a>00026 
+<a name="l00027"></a>00027  <span class="comment">/****************************************************************</span>
+<a name="l00028"></a>00028 <span class="comment">  *          Rec_Lampflats Frames Data Reduction                          *</span>
+<a name="l00029"></a>00029 <span class="comment">  ****************************************************************/</span>
+<a name="l00030"></a>00030 
+<a name="l00031"></a>00031 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00032"></a>00032 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>          <span class="comment">/* allows the program compilation */</span>
+<a name="l00033"></a>00033 <span class="preprocessor">#endif</span>
+<a name="l00034"></a>00034 <span class="preprocessor"></span>
+<a name="l00035"></a>00035 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00036"></a>00036 <span class="comment">                                Includes</span>
+<a name="l00037"></a>00037 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00038"></a>00038 
+<a name="l00039"></a>00039 <span class="comment">/* std */</span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include <strings.h></span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include <string.h></span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include <stdio.h></span>
+<a name="l00043"></a>00043 
+<a name="l00044"></a>00044 <span class="comment">/* cpl */</span>
+<a name="l00045"></a>00045 <span class="preprocessor">#include <cpl.h></span>    
+<a name="l00046"></a>00046 <span class="preprocessor">#include <irplib_utils.h></span>
+<a name="l00047"></a>00047 <span class="comment">/* sinfoni */</span>
+<a name="l00048"></a>00048 <span class="preprocessor">#include <sinfo_pro_types.h></span>
+<a name="l00049"></a>00049 <span class="preprocessor">#include <sinfo_utilities.h></span>
+<a name="l00050"></a>00050 <span class="preprocessor">#include <sinfo_general_config.h></span>
+<a name="l00051"></a>00051 <span class="preprocessor">#include <sinfo_product_config.h></span>
+<a name="l00052"></a>00052 <span class="preprocessor">#include <sinfo_bp_config.h></span>
+<a name="l00053"></a>00053 <span class="preprocessor">#include <sinfo_bp_norm_config.h></span>
+<a name="l00054"></a>00054 <span class="preprocessor">#include <sinfo_lamp_flats_config.h></span>
+<a name="l00055"></a>00055 <span class="preprocessor">#include <sinfo_bp_norm.h></span>
+<a name="l00056"></a>00056 <span class="preprocessor">#include <sinfo_new_lamp_flats.h></span>
+<a name="l00057"></a>00057 <span class="preprocessor">#include <sinfo_functions.h></span>
+<a name="l00058"></a>00058 <span class="preprocessor">#include <sinfo_new_add_bp_map.h></span>
+<a name="l00059"></a>00059 <span class="preprocessor">#include <sinfo_tpl_utils.h></span>
+<a name="l00060"></a>00060 <span class="preprocessor">#include <sinfo_tpl_dfs.h></span>
+<a name="l00061"></a>00061 <span class="preprocessor">#include <sinfo_msg.h></span>
+<a name="l00062"></a>00062 <span class="preprocessor">#include <sinfo_error.h></span>
+<a name="l00063"></a>00063 <span class="preprocessor">#include <sinfo_utils_wrappers.h></span>
+<a name="l00064"></a>00064 
+<a name="l00065"></a>00065 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00066"></a>00066 <span class="comment">                            Functions prototypes</span>
+<a name="l00067"></a>00067 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00068"></a>00068 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_mflat_create(cpl_plugin *);
+<a name="l00069"></a>00069 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_mflat_exec(cpl_plugin *);
+<a name="l00070"></a>00070 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_mflat_destroy(cpl_plugin *);
+<a name="l00071"></a>00071 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_mflat(cpl_parameterlist *, cpl_frameset *);
+<a name="l00072"></a>00072 
+<a name="l00073"></a>00073 
+<a name="l00074"></a>00074 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00075"></a>00075 <span class="comment">                            Static variables</span>
+<a name="l00076"></a>00076 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00077"></a>00077 
+<a name="l00078"></a>00078 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_rec_mflat_description[] =
+<a name="l00079"></a>00079 <span class="stringliteral">"This recipe reduce normal raw flat fields.\n"</span>
+<a name="l00080"></a>00080 <span class="stringliteral">"The input files are a set of flat fields with tag FLAT_LAMP\n"</span>
+<a name="l00081"></a>00081 <span class="stringliteral">"optionally one may have in input also several bad pixel maps to be coadded.\n"</span>
+<a name="l00082"></a>00082 <span class="stringliteral">"The main products are a master flat field (PRO.CATG=MASTER_FLAT_LAMP) image\n"</span>
+<a name="l00083"></a>00083 <span class="stringliteral">"a bad pixel map (PRO.CATG=BP_MAP_NO), "</span>
+<a name="l00084"></a>00084 <span class="stringliteral">"a master bad pixel map (PRO.CATG=MASTER_BP_MAP) resulting by the coaddition\n"</span>
+<a name="l00085"></a>00085 <span class="stringliteral">"of all bad pixel maps.\n"</span>
+<a name="l00086"></a>00086 <span class="stringliteral">"Information on relevant parameters can be found with\n"</span>
+<a name="l00087"></a>00087 <span class="stringliteral">"esorex --params sinfo_rec_mflat\n"</span>
+<a name="l00088"></a>00088 <span class="stringliteral">"esorex --help sinfo_rec_mflat\n"</span>
+<a name="l00089"></a>00089 <span class="stringliteral">"\n"</span>;
+<a name="l00090"></a>00090 
+<a name="l00091"></a>00091 
+<a name="l00092"></a>00092 
+<a name="l00093"></a>00093 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00094"></a>00094 <span class="comment">                                Functions code</span>
+<a name="l00095"></a>00095 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00096"></a>00096 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00100"></a>00100 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00102"></a>00102 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00111"></a>00111 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00112"></a>00112 
+<a name="l00113"></a><a class="code" href="group__sinfo__rec__mflat.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693">00113</a> <span class="keywordtype">int</span> <a class="code" href="group__sinfo__rec__detlin.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693" title="Build the list of available plugins, for this module.">cpl_plugin_get_info</a>(cpl_pluginlist *list)
+<a name="l00114"></a>00114 {
+<a name="l00115"></a>00115 
+<a name="l00116"></a>00116   cpl_recipe *recipe = cpl_calloc(1, <span class="keyword">sizeof</span> *recipe);
+<a name="l00117"></a>00117   cpl_plugin *plugin = &recipe->interface;
+<a name="l00118"></a>00118 
+<a name="l00119"></a>00119 
+<a name="l00120"></a>00120   cpl_plugin_init(plugin,
+<a name="l00121"></a>00121           CPL_PLUGIN_API,
+<a name="l00122"></a>00122           SINFONI_BINARY_VERSION,
+<a name="l00123"></a>00123           CPL_PLUGIN_TYPE_RECIPE,
+<a name="l00124"></a>00124           <span class="stringliteral">"sinfo_rec_mflat"</span>,
+<a name="l00125"></a>00125           <span class="stringliteral">"Master flat determination"</span>,
+<a name="l00126"></a>00126           sinfo_rec_mflat_description,
+<a name="l00127"></a>00127           <span class="stringliteral">"Andrea Modigliani"</span>,
+<a name="l00128"></a>00128           <span class="stringliteral">"Andrea.Modigliani at eso.org"</span>,
+<a name="l00129"></a>00129           sinfo_get_license(),
+<a name="l00130"></a>00130           sinfo_rec_mflat_create,
+<a name="l00131"></a>00131           sinfo_rec_mflat_exec,
+<a name="l00132"></a>00132           sinfo_rec_mflat_destroy);
+<a name="l00133"></a>00133 
+<a name="l00134"></a>00134   cpl_pluginlist_append(list, plugin);
+<a name="l00135"></a>00135 
+<a name="l00136"></a>00136   <span class="keywordflow">return</span> 0;
+<a name="l00137"></a>00137 
+<a name="l00138"></a>00138 }
+<a name="l00139"></a>00139 
+<a name="l00140"></a>00140 
+<a name="l00141"></a>00141 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00149"></a>00149 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00150"></a>00150 
+<a name="l00151"></a>00151 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_mflat_create(cpl_plugin *plugin)
+<a name="l00152"></a>00152 {
+<a name="l00153"></a>00153 
+<a name="l00154"></a>00154     cpl_recipe      * recipe ;
+<a name="l00155"></a>00155 
+<a name="l00156"></a>00156     <span class="comment">/* Check that the plugin is part of a valid recipe */</span>
+<a name="l00157"></a>00157     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00158"></a>00158         recipe = (cpl_recipe *)plugin ;
+<a name="l00159"></a>00159     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00160"></a>00160 
+<a name="l00161"></a>00161    <span class="comment">/* Create the parameters list in the cpl_recipe object */</span>
+<a name="l00162"></a>00162     recipe->parameters = cpl_parameterlist_new() ; 
+<a name="l00163"></a>00163 
+<a name="l00164"></a>00164   <span class="comment">/*</span>
+<a name="l00165"></a>00165 <span class="comment">   * Fill the parameter list.</span>
+<a name="l00166"></a>00166 <span class="comment">   */</span>
+<a name="l00167"></a>00167   sinfo_general_config_add(recipe->parameters);
+<a name="l00168"></a>00168   sinfo_product_config_add(recipe->parameters);
+<a name="l00169"></a>00169   <a class="code" href="group__sinfo__bad__pix__search.html#ga6f49eed82217a86089ff7f23465ae3e0" title="Adds parameters for the spectrum extraction.">sinfo_bp_norm_config_add</a>(recipe->parameters);
+<a name="l00170"></a>00170   sinfo_lamp_flats_config_add(recipe->parameters);
+<a name="l00171"></a>00171 
+<a name="l00172"></a>00172   <span class="keywordflow">return</span> 0;
+<a name="l00173"></a>00173 
+<a name="l00174"></a>00174 }
+<a name="l00175"></a>00175 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00181"></a>00181 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00182"></a>00182 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_mflat_exec(cpl_plugin *plugin)
+<a name="l00183"></a>00183 {
+<a name="l00184"></a>00184     cpl_recipe  *   recipe ;
+<a name="l00185"></a>00185     cpl_errorstate initial_errorstate = cpl_errorstate_get();
+<a name="l00186"></a>00186     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00187"></a>00187     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00188"></a>00188         recipe = (cpl_recipe *)plugin ;
+<a name="l00189"></a>00189     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00190"></a>00190     cpl_error_reset();
+<a name="l00191"></a>00191     <a class="code" href="group__irplib__utils.html#gaf9d392144014e2363054bc3f83c8e47e" title="Reset IRPLIB state.">irplib_reset</a>();
+<a name="l00192"></a>00192 
+<a name="l00193"></a>00193     <span class="keywordflow">if</span> (!cpl_errorstate_is_equal(initial_errorstate)) {                      
+<a name="l00194"></a>00194         <span class="comment">/* Dump the error history since recipe execution start.                </span>
+<a name="l00195"></a>00195 <span class="comment">           At this point the recipe cannot recover from the error */</span>           
+<a name="l00196"></a>00196         cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);              
+<a name="l00197"></a>00197     } 
+<a name="l00198"></a>00198   <span class="keywordflow">return</span> sinfo_rec_mflat(recipe->parameters, recipe->frames);
+<a name="l00199"></a>00199 
+<a name="l00200"></a>00200 }
+<a name="l00201"></a>00201 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00207"></a>00207 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00208"></a>00208 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_mflat_destroy(cpl_plugin *plugin)
+<a name="l00209"></a>00209 {
+<a name="l00210"></a>00210 
+<a name="l00211"></a>00211   cpl_recipe *recipe = (cpl_recipe *) plugin;
+<a name="l00212"></a>00212 
+<a name="l00213"></a>00213   <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00214"></a>00214   <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00215"></a>00215       recipe = (cpl_recipe *)plugin ;
+<a name="l00216"></a>00216   <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00217"></a>00217 
+<a name="l00218"></a>00218   cpl_parameterlist_delete(recipe->parameters);
+<a name="l00219"></a>00219   <span class="keywordflow">return</span> 0;
+<a name="l00220"></a>00220 
+<a name="l00221"></a>00221 }
+<a name="l00222"></a>00222 
+<a name="l00223"></a>00223 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00230"></a>00230 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00231"></a>00231 <span class="comment">/*</span>
+<a name="l00232"></a>00232 <span class="comment"> * The actual recipe actually start here.</span>
+<a name="l00233"></a>00233 <span class="comment"> */</span>
+<a name="l00234"></a>00234 
+<a name="l00235"></a>00235 
+<a name="l00236"></a>00236 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00237"></a>00237 sinfo_rec_mflat(cpl_parameterlist *config, cpl_frameset *<span class="keyword">set</span>)
+<a name="l00238"></a>00238 {
+<a name="l00239"></a>00239  
+<a name="l00240"></a>00240   cpl_parameter* p;
+<a name="l00241"></a>00241   cpl_frameset* ref_set=NULL;
+<a name="l00242"></a>00242   <span class="keywordtype">int</span> pdensity=0;
+<a name="l00243"></a>00243   <span class="keywordtype">int</span> line_cor=0;
+<a name="l00244"></a>00244 
+<a name="l00245"></a>00245   check_nomsg(p=cpl_parameterlist_find(config,<span class="stringliteral">"sinfoni.product.density"</span>));
+<a name="l00246"></a>00246   check_nomsg(pdensity=cpl_parameter_get_int(p));
+<a name="l00247"></a>00247 
+<a name="l00248"></a>00248   sinfo_msg(<span class="stringliteral">"Welcome to SINFONI Pipeline release %d.%d.%d"</span>,
+<a name="l00249"></a>00249         SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
+<a name="l00250"></a>00250   ck0(sinfo_dfs_set_groups(<span class="keyword">set</span>),<span class="stringliteral">"Cannot indentify RAW and CALIB frames"</span>) ;
+<a name="l00251"></a>00251 
+<a name="l00252"></a>00252   check_nomsg(p=cpl_parameterlist_find(config, <span class="stringliteral">"sinfoni.general.lc_sw"</span>));
+<a name="l00253"></a>00253   check_nomsg(line_cor=cpl_parameter_get_bool(p));
+<a name="l00254"></a>00254   <span class="keywordflow">if</span>(line_cor==1) {
+<a name="l00255"></a>00255      check_nomsg(sinfo_ima_line_cor(config,<span class="keyword">set</span>));
+<a name="l00256"></a>00256   }
+<a name="l00257"></a>00257 
+<a name="l00258"></a>00258 
+<a name="l00259"></a>00259 
+<a name="l00260"></a>00260   check_nomsg(ref_set=cpl_frameset_duplicate(<span class="keyword">set</span>));
+<a name="l00261"></a>00261   sinfo_bp_config_add(config);  
+<a name="l00262"></a>00262   check_nomsg(p = cpl_parameterlist_find(config,<span class="stringliteral">"sinfoni.bp.method"</span>));
+<a name="l00263"></a>00263   check_nomsg(cpl_parameter_set_string(p,<span class="stringliteral">"Normal"</span>));   
+<a name="l00264"></a>00264   <span class="comment">/* </span>
+<a name="l00265"></a>00265 <span class="comment">       ---------------------------------------------------------</span>
+<a name="l00266"></a>00266 <span class="comment">                MASTER_FLAT</span>
+<a name="l00267"></a>00267 <span class="comment">       ---------------------------------------------------------</span>
+<a name="l00268"></a>00268 <span class="comment">  */</span>
+<a name="l00269"></a>00269  
+<a name="l00270"></a>00270   sinfo_msg(<span class="stringliteral">"-------------------------------------------"</span>);
+<a name="l00271"></a>00271   sinfo_msg(<span class="stringliteral">"MASTER FLAT DETERMINATION                  "</span>);
+<a name="l00272"></a>00272   sinfo_msg(<span class="stringliteral">"-------------------------------------------"</span>);
+<a name="l00273"></a>00273     
+<a name="l00274"></a>00274   ck0(sinfo_new_lamp_flats(cpl_func,config,<span class="keyword">set</span>,ref_set),
+<a name="l00275"></a>00275       <span class="stringliteral">"MASTER FLAT DETERMINATION FAILED"</span>);
+<a name="l00276"></a>00276   sinfo_msg(<span class="stringliteral">"MASTER FLAT DETERMINATION SUCCESS"</span>) ; 
+<a name="l00277"></a>00277 
+<a name="l00278"></a>00278   sinfo_msg(<span class="stringliteral">"-------------------------------------------"</span>);
+<a name="l00279"></a>00279   sinfo_msg(<span class="stringliteral">"BP_MAP_NO BAD PIXEL MAP DETERMINATION      "</span>);
+<a name="l00280"></a>00280   sinfo_msg(<span class="stringliteral">"-------------------------------------------"</span>);
+<a name="l00281"></a>00281   <span class="comment">/* </span>
+<a name="l00282"></a>00282 <span class="comment">       ---------------------------------------------------------</span>
+<a name="l00283"></a>00283 <span class="comment">                BP_SEARCH</span>
+<a name="l00284"></a>00284 <span class="comment">       ---------------------------------------------------------</span>
+<a name="l00285"></a>00285 <span class="comment">  */</span>
+<a name="l00286"></a>00286    
+<a name="l00287"></a>00287   check_nomsg(p = cpl_parameterlist_find(config,<span class="stringliteral">"sinfoni.bp.method"</span>));
+<a name="l00288"></a>00288   check_nomsg(cpl_parameter_set_string(p,<span class="stringliteral">"Normal"</span>));   
+<a name="l00289"></a>00289   ck0(sinfo_new_bp_search_normal(cpl_func,config,<span class="keyword">set</span>,ref_set,PRO_BP_MAP_NO),
+<a name="l00290"></a>00290   <span class="stringliteral">"BP_MAP_NO BAD PIXEL MAP DETERMINATION FAILED"</span>) ;
+<a name="l00291"></a>00291     
+<a name="l00292"></a>00292   sinfo_msg(<span class="stringliteral">"------------------------------------------"</span>);
+<a name="l00293"></a>00293   sinfo_msg(<span class="stringliteral">"MASTER_BP_MAP BAD PIXEL MAP DETERMINATION "</span>);
+<a name="l00294"></a>00294   sinfo_msg(<span class="stringliteral">"------------------------------------------"</span>);
+<a name="l00295"></a>00295   ck0(sinfo_new_add_bp_map(cpl_func,config, <span class="keyword">set</span>,ref_set),
+<a name="l00296"></a>00296      <span class="stringliteral">"MASTER_BP_MAP BAD PIXEL MAP FAILED"</span>) ;
+<a name="l00297"></a>00297   sinfo_msg(<span class="stringliteral">"MASTER_BP_MAP BAD PIXEL MAP DETERMINATION SUCCESS"</span>);
+<a name="l00298"></a>00298     
+<a name="l00299"></a>00299 
+<a name="l00300"></a>00300   <span class="keywordflow">if</span>(pdensity < 2) {
+<a name="l00301"></a>00301      check_nomsg(cpl_frameset_erase(<span class="keyword">set</span>,PRO_BP_MAP_NO));
+<a name="l00302"></a>00302   }
+<a name="l00303"></a>00303 
+<a name="l00304"></a>00304  cleanup:
+<a name="l00305"></a>00305 
+<a name="l00306"></a>00306   sinfo_free_frameset(&ref_set);
+<a name="l00307"></a>00307 
+<a name="l00308"></a>00308   <span class="keywordflow">if</span> (cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l00309"></a>00309     <span class="keywordflow">return</span> -1;
+<a name="l00310"></a>00310   } <span class="keywordflow">else</span> {
+<a name="l00311"></a>00311     <span class="keywordflow">return</span> 0;
+<a name="l00312"></a>00312   }
+<a name="l00313"></a>00313 
+<a name="l00314"></a>00314 }
+<a name="l00315"></a>00315 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__rec__objnod_8c_source.html b/html/sinfo__rec__objnod_8c_source.html
new file mode 100644
index 0000000..c06181b
--- /dev/null
+++ b/html/sinfo__rec__objnod_8c_source.html
@@ -0,0 +1,299 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_rec_objnod.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_rec_objnod.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_rec_objnod.c,v 1.24 2007/10/26 09:40:28 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the SINFONI Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2007/10/26 09:40:28 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.24 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028  <span class="comment">/****************************************************************</span>
+<a name="l00029"></a>00029 <span class="comment">  *           Object Data reduction                              *</span>
+<a name="l00030"></a>00030 <span class="comment">  ****************************************************************/</span>
+<a name="l00031"></a>00031 
+<a name="l00032"></a>00032 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00033"></a>00033 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>          <span class="comment">/* allows the program compilation */</span>
+<a name="l00034"></a>00034 <span class="preprocessor">#endif</span>
+<a name="l00035"></a>00035 <span class="preprocessor"></span>
+<a name="l00036"></a>00036 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00037"></a>00037 <span class="comment">                                Includes</span>
+<a name="l00038"></a>00038 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00039"></a>00039 
+<a name="l00040"></a>00040 <span class="comment">/* std */</span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include <strings.h></span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include <string.h></span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include <stdio.h></span>
+<a name="l00044"></a>00044 <span class="preprocessor">#include <math.h></span>
+<a name="l00045"></a>00045 <span class="preprocessor">#include <libgen.h></span>
+<a name="l00046"></a>00046 
+<a name="l00047"></a>00047 
+<a name="l00048"></a>00048 <span class="comment">/* cpl */</span>
+<a name="l00049"></a>00049 <span class="preprocessor">#include <cpl.h></span>  
+<a name="l00050"></a>00050 <span class="preprocessor">#include <irplib_utils.h></span>  
+<a name="l00051"></a>00051 
+<a name="l00052"></a>00052 
+<a name="l00053"></a>00053 
+<a name="l00054"></a>00054 <span class="comment">/* sinfoni */</span>
+<a name="l00055"></a>00055 <span class="preprocessor">#include <sinfo_pro_types.h></span>
+<a name="l00056"></a>00056 <span class="preprocessor">#include <sinfo_product_config.h></span>
+<a name="l00057"></a>00057 <span class="preprocessor">#include <sinfo_prepare_stacked_frames_config.h></span>
+<a name="l00058"></a>00058 <span class="preprocessor">#include <sinfo_objnod_config.h></span>
+<a name="l00059"></a>00059 <span class="preprocessor">#include <sinfo_new_cubes_coadd.h></span>
+<a name="l00060"></a>00060 <span class="preprocessor">#include <sinfo_new_prepare_stacked_frames.h></span>
+<a name="l00061"></a>00061 <span class="preprocessor">#include <sinfo_skycor_config.h></span>
+<a name="l00062"></a>00062 <span class="preprocessor">#include <sinfo_key_names.h></span>
+<a name="l00063"></a>00063 <span class="preprocessor">#include <sinfo_raw_types.h></span>
+<a name="l00064"></a>00064 <span class="preprocessor">#include <sinfo_functions.h></span>
+<a name="l00065"></a>00065 <span class="preprocessor">#include <sinfo_tpl_utils.h></span>
+<a name="l00066"></a>00066 <span class="preprocessor">#include <sinfo_tpl_dfs.h></span>
+<a name="l00067"></a>00067 <span class="preprocessor">#include <sinfo_hidden.h></span>
+<a name="l00068"></a>00068 <span class="preprocessor">#include <sinfo_globals.h></span>
+<a name="l00069"></a>00069 <span class="preprocessor">#include <sinfo_msg.h></span>
+<a name="l00070"></a>00070 <span class="preprocessor">#include <sinfo_rec_utils.h></span>
+<a name="l00071"></a>00071 <span class="preprocessor">#include <sinfo_error.h></span>
+<a name="l00072"></a>00072 <span class="preprocessor">#include <sinfo_utils_wrappers.h></span>
+<a name="l00073"></a>00073 
+<a name="l00074"></a>00074 
+<a name="l00075"></a>00075 
+<a name="l00076"></a>00076 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00077"></a>00077 <span class="comment">                            Functions prototypes</span>
+<a name="l00078"></a>00078 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00079"></a>00079 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_objnod_create(cpl_plugin *) ;
+<a name="l00080"></a>00080 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_objnod_exec(cpl_plugin *) ;
+<a name="l00081"></a>00081 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_objnod_destroy(cpl_plugin *) ;
+<a name="l00082"></a>00082 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_objnod(cpl_parameterlist *, cpl_frameset *);
+<a name="l00083"></a>00083 
+<a name="l00084"></a>00084 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00085"></a>00085 <span class="comment">                            Static variables</span>
+<a name="l00086"></a>00086 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00087"></a>00087 
+<a name="l00088"></a>00088 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_rec_objnod_description1[] =
+<a name="l00089"></a>00089 <span class="stringliteral">"This recipe performs science data reduction.\n"</span>
+<a name="l00090"></a>00090 <span class="stringliteral">"The input files are science object and sky frames with tags \n"</span>
+<a name="l00091"></a>00091 <span class="stringliteral">"OBJECT_NODDING and SKY_NODDING\n"</span>
+<a name="l00092"></a>00092 <span class="stringliteral">"Master calibration frames:\n"</span>;
+<a name="l00093"></a>00093 
+<a name="l00094"></a>00094 
+<a name="l00095"></a>00095 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_rec_objnod_description2[] =
+<a name="l00096"></a>00096 <span class="stringliteral">"A corresponding (band,preoptics) wavelength map image with tag WAVE_MAP\n"</span>
+<a name="l00097"></a>00097 <span class="stringliteral">"A corresponding (band,preoptics) master flat field with tag MASTER_FLAT_LAMP\n"</span>
+<a name="l00098"></a>00098 <span class="stringliteral">"A corresponding (band,preoptics) master bad pixel map with tag MASTER_BP_MAP\n"</span>
+<a name="l00099"></a>00099 <span class="stringliteral">"A corresponding (band,preoptics) slitlets position frame with tag SLIT_POS\n"</span>
+<a name="l00100"></a>00100 <span class="stringliteral">"A corresponding (band) distortion table with tag DISTORTION\n"</span>
+<a name="l00101"></a>00101 <span class="stringliteral">"A corresponding (band) slitlet distance table with tag SLITLETS_DISTANCE\n"</span>;
+<a name="l00102"></a>00102 
+<a name="l00103"></a>00103 
+<a name="l00104"></a>00104 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_rec_objnod_description3[] =
+<a name="l00105"></a>00105 <span class="stringliteral">"The output is an image resulting from the IMA1 op IMA2 where op indicates\n"</span>
+<a name="l00106"></a>00106 <span class="stringliteral">"A reference table with the position of the first "</span>
+<a name="l00107"></a>00107 <span class="stringliteral">"column with tag FIRST_COLUMN\n"</span>
+<a name="l00108"></a>00108 <span class="stringliteral">"Relevant outputs are:\n"</span>
+<a name="l00109"></a>00109 <span class="stringliteral">"combined cubes (PRO.CATG=x_OBS x=STD,OBJ,PSF)\n"</span>
+<a name="l00110"></a>00110 <span class="stringliteral">"reconstructed cube (PRO.CATG=COADD_x_OBS x=STD,OBJ,PSF)\n"</span>
+<a name="l00111"></a>00111 <span class="stringliteral">"An average along Z of the reconstructed cube \n"</span>
+<a name="l00112"></a>00112 <span class="stringliteral">"(PRO.CATG=MED_x_OBS x=STD,OBJ,PSF)\n"</span>
+<a name="l00113"></a>00113 <span class="stringliteral">"The bad pixel map associated to the cube \n"</span>
+<a name="l00114"></a>00114 <span class="stringliteral">"(PRO.CATG=BP_MAP_COADD_x_OBS x=STD,OBJ,PSF)\n"</span>;
+<a name="l00115"></a>00115 
+<a name="l00116"></a>00116 
+<a name="l00117"></a>00117 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_rec_objnod_description4[] =
+<a name="l00118"></a>00118 <span class="stringliteral">"Information on relevant parameters can be found with\n"</span>
+<a name="l00119"></a>00119 <span class="stringliteral">"esorex --params sinfo_rec_objnod\n"</span>
+<a name="l00120"></a>00120 <span class="stringliteral">"esorex --help sinfo_rec_objnod\n"</span>
+<a name="l00121"></a>00121 <span class="stringliteral">"\n"</span>;
+<a name="l00122"></a>00122 
+<a name="l00123"></a>00123 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_rec_objnod_description[1300];
+<a name="l00124"></a>00124 
+<a name="l00125"></a>00125 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00126"></a>00126 <span class="comment">                                Functions code</span>
+<a name="l00127"></a>00127 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00128"></a>00128 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00132"></a>00132 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00134"></a>00134 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00143"></a>00143 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00144"></a>00144 
+<a name="l00145"></a>00145 
+<a name="l00146"></a>00146 <span class="keywordtype">int</span>
+<a name="l00147"></a><a class="code" href="group__sinfo__rec__objnod.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693">00147</a> <a class="code" href="group__sinfo__rec__detlin.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693" title="Build the list of available plugins, for this module.">cpl_plugin_get_info</a>(cpl_pluginlist *list)
+<a name="l00148"></a>00148 {
+<a name="l00149"></a>00149 
+<a name="l00150"></a>00150   cpl_recipe *recipe = cpl_calloc(1, <span class="keyword">sizeof</span> *recipe);
+<a name="l00151"></a>00151   cpl_plugin *plugin = &recipe->interface;
+<a name="l00152"></a>00152 
+<a name="l00153"></a>00153   strcpy(sinfo_rec_objnod_description,sinfo_rec_objnod_description1);
+<a name="l00154"></a>00154   strcat(sinfo_rec_objnod_description,sinfo_rec_objnod_description2);
+<a name="l00155"></a>00155   strcat(sinfo_rec_objnod_description,sinfo_rec_objnod_description3);
+<a name="l00156"></a>00156   strcat(sinfo_rec_objnod_description,sinfo_rec_objnod_description4);
+<a name="l00157"></a>00157 
+<a name="l00158"></a>00158   cpl_plugin_init(plugin,
+<a name="l00159"></a>00159           CPL_PLUGIN_API,
+<a name="l00160"></a>00160           SINFONI_BINARY_VERSION,
+<a name="l00161"></a>00161           CPL_PLUGIN_TYPE_RECIPE,
+<a name="l00162"></a>00162           <span class="stringliteral">"sinfo_rec_objnod"</span>,
+<a name="l00163"></a>00163           <span class="stringliteral">"Object data reduction"</span>,
+<a name="l00164"></a>00164            sinfo_rec_objnod_description,
+<a name="l00165"></a>00165           <span class="stringliteral">"Andrea Modigliani"</span>,
+<a name="l00166"></a>00166           <span class="stringliteral">"Andrea.Mdigliani at eso.org"</span>,
+<a name="l00167"></a>00167           sinfo_get_license(),
+<a name="l00168"></a>00168           sinfo_rec_objnod_create,
+<a name="l00169"></a>00169           sinfo_rec_objnod_exec,
+<a name="l00170"></a>00170           sinfo_rec_objnod_destroy);
+<a name="l00171"></a>00171 
+<a name="l00172"></a>00172   cpl_pluginlist_append(list, plugin);
+<a name="l00173"></a>00173 
+<a name="l00174"></a>00174   <span class="keywordflow">return</span> 0;
+<a name="l00175"></a>00175 
+<a name="l00176"></a>00176 }
+<a name="l00177"></a>00177 
+<a name="l00178"></a>00178 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00186"></a>00186 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00187"></a>00187 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_objnod_create(cpl_plugin *plugin)
+<a name="l00188"></a>00188 {
+<a name="l00189"></a>00189     cpl_recipe      * recipe ;
+<a name="l00190"></a>00190 
+<a name="l00191"></a>00191     <span class="comment">/* Check that the plugin is part of a valid recipe */</span>
+<a name="l00192"></a>00192     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00193"></a>00193         recipe = (cpl_recipe *)plugin ;
+<a name="l00194"></a>00194     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00195"></a>00195     <a class="code" href="group__irplib__utils.html#gaf9d392144014e2363054bc3f83c8e47e" title="Reset IRPLIB state.">irplib_reset</a>();
+<a name="l00196"></a>00196     cpl_error_reset();
+<a name="l00197"></a>00197 
+<a name="l00198"></a>00198    <span class="comment">/* Create the parameters list in the cpl_recipe object */</span>
+<a name="l00199"></a>00199     recipe->parameters = cpl_parameterlist_new() ; 
+<a name="l00200"></a>00200 
+<a name="l00201"></a>00201   <span class="comment">/*</span>
+<a name="l00202"></a>00202 <span class="comment">   * Fill the parameter list.</span>
+<a name="l00203"></a>00203 <span class="comment">   */</span>
+<a name="l00204"></a>00204 
+<a name="l00205"></a>00205   sinfo_product_config_add(recipe->parameters);
+<a name="l00206"></a>00206   sinfo_prepare_stacked_frames_config_add(recipe->parameters);
+<a name="l00207"></a>00207   sinfo_objnod_config_add(recipe->parameters); 
+<a name="l00208"></a>00208   sinfo_skycor_config_add(recipe->parameters); 
+<a name="l00209"></a>00209 
+<a name="l00210"></a>00210   <span class="keywordflow">return</span> 0;
+<a name="l00211"></a>00211 
+<a name="l00212"></a>00212 }
+<a name="l00213"></a>00213 
+<a name="l00214"></a>00214 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00220"></a>00220 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00221"></a>00221 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_objnod_exec(cpl_plugin *plugin)
+<a name="l00222"></a>00222 {
+<a name="l00223"></a>00223      cpl_recipe  *   recipe ;
+<a name="l00224"></a>00224 
+<a name="l00225"></a>00225     cpl_errorstate initial_errorstate = cpl_errorstate_get();
+<a name="l00226"></a>00226 
+<a name="l00227"></a>00227     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00228"></a>00228     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00229"></a>00229         recipe = (cpl_recipe *)plugin ;
+<a name="l00230"></a>00230     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00231"></a>00231 
+<a name="l00232"></a>00232     <span class="keywordflow">if</span> (!cpl_errorstate_is_equal(initial_errorstate)) {                      
+<a name="l00233"></a>00233         <span class="comment">/* Dump the error history since recipe execution start.                </span>
+<a name="l00234"></a>00234 <span class="comment">           At this point the recipe cannot recover from the error */</span>           
+<a name="l00235"></a>00235         cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);              
+<a name="l00236"></a>00236     } 
+<a name="l00237"></a>00237 
+<a name="l00238"></a>00238   <span class="keywordflow">return</span> sinfo_rec_objnod(recipe->parameters, recipe->frames);
+<a name="l00239"></a>00239 
+<a name="l00240"></a>00240 }
+<a name="l00241"></a>00241 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00247"></a>00247 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00248"></a>00248 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_objnod_destroy(cpl_plugin *plugin)
+<a name="l00249"></a>00249 {
+<a name="l00250"></a>00250   cpl_recipe *recipe = (cpl_recipe *) plugin;
+<a name="l00251"></a>00251 
+<a name="l00252"></a>00252     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00253"></a>00253     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00254"></a>00254         recipe = (cpl_recipe *)plugin ;
+<a name="l00255"></a>00255     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00256"></a>00256 
+<a name="l00257"></a>00257   cpl_parameterlist_delete(recipe->parameters);
+<a name="l00258"></a>00258 
+<a name="l00259"></a>00259   <span class="keywordflow">return</span> 0;
+<a name="l00260"></a>00260 
+<a name="l00261"></a>00261 }
+<a name="l00262"></a>00262 
+<a name="l00263"></a>00263 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00270"></a>00270 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00271"></a>00271 
+<a name="l00272"></a>00272 <span class="comment">/*</span>
+<a name="l00273"></a>00273 <span class="comment"> * The actual recipe actually start here.</span>
+<a name="l00274"></a>00274 <span class="comment"> */</span>
+<a name="l00275"></a>00275 
+<a name="l00276"></a>00276 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_objnod(cpl_parameterlist *config, cpl_frameset *<span class="keyword">set</span>)
+<a name="l00277"></a>00277 {
+<a name="l00278"></a>00278   <span class="keyword">const</span> <span class="keywordtype">char</span>* pro_ctg_cube;
+<a name="l00279"></a>00279   sinfo_msg(<span class="stringliteral">"Welcome to SINFONI Pipeline release %d.%d.%d"</span>,
+<a name="l00280"></a>00280         SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
+<a name="l00281"></a>00281 
+<a name="l00282"></a>00282   <span class="keywordflow">if</span>(sinfo_dfs_set_groups(<span class="keyword">set</span>)) {
+<a name="l00283"></a>00283     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Cannot indentify RAW and CALIB frames"</span>) ;
+<a name="l00284"></a>00284     <span class="keywordflow">return</span> -1;
+<a name="l00285"></a>00285   }
+<a name="l00286"></a>00286 
+<a name="l00287"></a>00287   <span class="comment">/* =============================================================== </span>
+<a name="l00288"></a>00288 <span class="comment">     Defines several framesets each with a pair obj-sky, </span>
+<a name="l00289"></a>00289 <span class="comment">     stack each pair, put the results in set </span>
+<a name="l00290"></a>00290 <span class="comment">     =============================================================== */</span>
+<a name="l00291"></a>00291    ck0(sinfo_cub_stk_frames(config,&<span class="keyword">set</span>,cpl_func,&pro_ctg_cube),
+<a name="l00292"></a>00292        <span class="stringliteral">"Cannot stack RAW frames"</span>) ;
+<a name="l00293"></a>00293  
+<a name="l00294"></a>00294   
+<a name="l00295"></a>00295   <span class="comment">/* =============================================================== </span>
+<a name="l00296"></a>00296 <span class="comment">     SCI OBJNOD </span>
+<a name="l00297"></a>00297 <span class="comment">     =============================================================== */</span>
+<a name="l00298"></a>00298       
+<a name="l00299"></a>00299    sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ; 
+<a name="l00300"></a>00300    sinfo_msg(<span class="stringliteral">"COADDING CUBES"</span>);
+<a name="l00301"></a>00301    sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ; 
+<a name="l00302"></a>00302 
+<a name="l00303"></a>00303 
+<a name="l00304"></a>00304    ck0(sinfo_new_cubes_coadd(cpl_func,config, <span class="keyword">set</span>, pro_ctg_cube),
+<a name="l00305"></a>00305        <span class="stringliteral">"COADDING CUBES"</span>) ;
+<a name="l00306"></a>00306        
+<a name="l00307"></a>00307    sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ; 
+<a name="l00308"></a>00308    sinfo_msg(<span class="stringliteral">"COADDED CUBES"</span>);
+<a name="l00309"></a>00309    sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ; 
+<a name="l00310"></a>00310 
+<a name="l00311"></a>00311  cleanup:
+<a name="l00312"></a>00312   <span class="keywordflow">if</span> (cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l00313"></a>00313     <span class="keywordflow">return</span> -1;
+<a name="l00314"></a>00314   } <span class="keywordflow">else</span> {
+<a name="l00315"></a>00315     <span class="keywordflow">return</span> 0;
+<a name="l00316"></a>00316   }
+<a name="l00317"></a>00317 
+<a name="l00318"></a>00318 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__rec__psf_8c_source.html b/html/sinfo__rec__psf_8c_source.html
new file mode 100644
index 0000000..ad08f8f
--- /dev/null
+++ b/html/sinfo__rec__psf_8c_source.html
@@ -0,0 +1,307 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_rec_psf.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_rec_psf.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_rec_psf.c,v 1.22 2008/02/12 14:56:50 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the SINFONI Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 
+<a name="l00022"></a>00022 <span class="comment">/*</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Date: 2008/02/12 14:56:50 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Revision: 1.22 $</span>
+<a name="l00026"></a>00026 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00027"></a>00027 <span class="comment"> */</span>
+<a name="l00028"></a>00028 
+<a name="l00029"></a>00029  <span class="comment">/****************************************************************</span>
+<a name="l00030"></a>00030 <span class="comment">  *          Psf Frames Data Reduction                          *</span>
+<a name="l00031"></a>00031 <span class="comment">  ****************************************************************/</span>
+<a name="l00032"></a>00032 
+<a name="l00033"></a>00033 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00034"></a>00034 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>          <span class="comment">/* allows the program compilation */</span>
+<a name="l00035"></a>00035 <span class="preprocessor">#endif</span>
+<a name="l00036"></a>00036 <span class="preprocessor"></span><span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00037"></a>00037 <span class="comment">                                Includes</span>
+<a name="l00038"></a>00038 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00039"></a>00039 
+<a name="l00040"></a>00040 <span class="comment">/* std */</span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include <strings.h></span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include <string.h></span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include <stdio.h></span>
+<a name="l00044"></a>00044 
+<a name="l00045"></a>00045 <span class="comment">/* cpl */</span>
+<a name="l00046"></a>00046 <span class="preprocessor">#include <cpl.h></span>  
+<a name="l00047"></a>00047  
+<a name="l00048"></a>00048 <span class="comment">/* irplib */</span>
+<a name="l00049"></a>00049 <span class="preprocessor">#include <irplib_utils.h></span>
+<a name="l00050"></a>00050 
+<a name="l00051"></a>00051 <span class="comment">/* sinfoni */</span>
+<a name="l00052"></a>00052 <span class="preprocessor">#include <sinfo_pro_types.h></span>
+<a name="l00053"></a>00053 <span class="preprocessor">#include <sinfo_product_config.h></span>
+<a name="l00054"></a>00054 <span class="preprocessor">#include <sinfo_prepare_stacked_frames_config.h></span>
+<a name="l00055"></a>00055 <span class="preprocessor">#include <sinfo_objnod_config.h></span>
+<a name="l00056"></a>00056 <span class="preprocessor">#include <sinfo_skycor_config.h></span>
+<a name="l00057"></a>00057 <span class="preprocessor">#include <sinfo_functions.h></span>
+<a name="l00058"></a>00058 <span class="preprocessor">#include <sinfo_new_prepare_stacked_frames.h></span>
+<a name="l00059"></a>00059 <span class="preprocessor">#include <sinfo_new_cubes_coadd.h></span>
+<a name="l00060"></a>00060 <span class="preprocessor">#include <sinfo_new_stdstar.h></span>
+<a name="l00061"></a>00061 <span class="preprocessor">#include <sinfo_new_psf.h></span>
+<a name="l00062"></a>00062 <span class="preprocessor">#include <sinfo_tpl_utils.h></span>
+<a name="l00063"></a>00063 <span class="preprocessor">#include <sinfo_tpl_dfs.h></span>
+<a name="l00064"></a>00064 <span class="preprocessor">#include <sinfo_hidden.h></span>
+<a name="l00065"></a>00065 <span class="preprocessor">#include <sinfo_globals.h></span>
+<a name="l00066"></a>00066 <span class="preprocessor">#include <sinfo_msg.h></span>
+<a name="l00067"></a>00067 <span class="preprocessor">#include <sinfo_rec_utils.h></span>
+<a name="l00068"></a>00068 <span class="preprocessor">#include <sinfo_error.h></span>
+<a name="l00069"></a>00069 <span class="preprocessor">#include <sinfo_utils_wrappers.h></span>
+<a name="l00070"></a>00070 
+<a name="l00071"></a>00071 
+<a name="l00072"></a>00072 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00073"></a>00073 <span class="comment">                            Functions prototypes</span>
+<a name="l00074"></a>00074 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00075"></a>00075 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_psf_create(cpl_plugin *) ;
+<a name="l00076"></a>00076 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_psf_exec(cpl_plugin *) ;
+<a name="l00077"></a>00077 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_psf_destroy(cpl_plugin *) ;
+<a name="l00078"></a>00078 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_psf(cpl_parameterlist *, cpl_frameset *);
+<a name="l00079"></a>00079 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00080"></a>00080 <span class="comment">                            Static variables</span>
+<a name="l00081"></a>00081 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00082"></a>00082 
+<a name="l00083"></a>00083 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_rec_psf_description1[] =
+<a name="l00084"></a>00084 <span class="stringliteral">"This recipe performs psf standard data reduction.\n"</span>
+<a name="l00085"></a>00085 <span class="stringliteral">"The input files are science object and sky frames with tags\n"</span>
+<a name="l00086"></a>00086 <span class="stringliteral">"PSF_CALIBRATOR and SKY_PSF_CALIBRATOR\n"</span>
+<a name="l00087"></a>00087 <span class="stringliteral">"Master calibration frames:\n"</span>;
+<a name="l00088"></a>00088 
+<a name="l00089"></a>00089 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_rec_psf_description2[] =
+<a name="l00090"></a>00090 <span class="stringliteral">"Master calibration frames:\n"</span>
+<a name="l00091"></a>00091 <span class="stringliteral">"A corresponding (band,preoptics) wavelength map image (tag=WAVE_MAP)\n"</span>
+<a name="l00092"></a>00092 <span class="stringliteral">"A corresponding (band,preoptics) master flat field (tag=MASTER_FLAT_LAMP)\n"</span>
+<a name="l00093"></a>00093 <span class="stringliteral">"A corresponding (band,preoptics) master bad pixel map (tag=MASTER_BP_MAP)\n"</span>
+<a name="l00094"></a>00094 <span class="stringliteral">"A corresponding (band,preoptics) slitlets position frame (tag=SLIT_POS)\n"</span>
+<a name="l00095"></a>00095 <span class="stringliteral">"A corresponding (band) distortion table (tag=DISTORTION)\n"</span>
+<a name="l00096"></a>00096 <span class="stringliteral">"A corresponding (band) slitlet distance table (tag=SLITLETS_DISTANCE)\n"</span>;
+<a name="l00097"></a>00097 
+<a name="l00098"></a>00098 
+<a name="l00099"></a>00099 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_rec_psf_description3[] =
+<a name="l00100"></a>00100 <span class="stringliteral">"The output is an image resulting from the IMA1 op IMA2 where op indicates\n"</span>
+<a name="l00101"></a>00101 <span class="stringliteral">"the chosen operation\n"</span>
+<a name="l00102"></a>00102 <span class="stringliteral">"A reference table with the position of the first column (tag=FIRST_COLUMN)\n"</span>
+<a name="l00103"></a>00103 <span class="stringliteral">"Relevant outputs are:\n"</span>
+<a name="l00104"></a>00104 <span class="stringliteral">"combined cubes (PRO.CATG=x_OBS x=STD,OBJ,PSF)\n"</span>
+<a name="l00105"></a>00105 <span class="stringliteral">"reconstructed cube (PRO.CATG=COADD_x_OBS x=STD,OBJ,PSF)\n"</span>
+<a name="l00106"></a>00106 <span class="stringliteral">"An average along Z of the reconstructed cube \n"</span>
+<a name="l00107"></a>00107 <span class="stringliteral">"(PRO.CATG=MED_x_OBS x=STD,OBJ,PSF)\n"</span>
+<a name="l00108"></a>00108 <span class="stringliteral">"The bad pixel map associated to the cube \n"</span>
+<a name="l00109"></a>00109 <span class="stringliteral">"(PRO.CATG=BP_MAP_COADD_x_OBS x=STD,OBJ,PSF)\n"</span>;
+<a name="l00110"></a>00110 
+<a name="l00111"></a>00111 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_rec_psf_description4[] =
+<a name="l00112"></a>00112 <span class="stringliteral">"Information on relevant parameters can be found with\n"</span>
+<a name="l00113"></a>00113 <span class="stringliteral">"esorex --params sinfo_rec_psf\n"</span>
+<a name="l00114"></a>00114 <span class="stringliteral">"esorex --help sinfo_rec_psf\n"</span>
+<a name="l00115"></a>00115 <span class="stringliteral">"\n"</span>;
+<a name="l00116"></a>00116 
+<a name="l00117"></a>00117 
+<a name="l00118"></a>00118 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_rec_psf_description[1300];
+<a name="l00119"></a>00119 
+<a name="l00120"></a>00120 
+<a name="l00121"></a>00121 
+<a name="l00122"></a>00122 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00123"></a>00123 <span class="comment">                                Functions code</span>
+<a name="l00124"></a>00124 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00125"></a>00125 
+<a name="l00126"></a>00126 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00130"></a>00130 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00132"></a>00132 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00141"></a>00141 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00142"></a>00142 
+<a name="l00143"></a>00143 
+<a name="l00144"></a>00144 
+<a name="l00145"></a>00145 <span class="keywordtype">int</span>
+<a name="l00146"></a><a class="code" href="group__sinfo__rec__psf.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693">00146</a> <a class="code" href="group__sinfo__rec__detlin.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693" title="Build the list of available plugins, for this module.">cpl_plugin_get_info</a>(cpl_pluginlist *list)
+<a name="l00147"></a>00147 {
+<a name="l00148"></a>00148 
+<a name="l00149"></a>00149   cpl_recipe *recipe = cpl_calloc(1, <span class="keyword">sizeof</span> *recipe);
+<a name="l00150"></a>00150   cpl_plugin *plugin = &recipe->interface;
+<a name="l00151"></a>00151   strcpy(sinfo_rec_psf_description,sinfo_rec_psf_description1);
+<a name="l00152"></a>00152   strcat(sinfo_rec_psf_description,sinfo_rec_psf_description2);
+<a name="l00153"></a>00153   strcat(sinfo_rec_psf_description,sinfo_rec_psf_description3);
+<a name="l00154"></a>00154   strcat(sinfo_rec_psf_description,sinfo_rec_psf_description4);
+<a name="l00155"></a>00155 
+<a name="l00156"></a>00156   cpl_plugin_init(plugin,
+<a name="l00157"></a>00157           CPL_PLUGIN_API,
+<a name="l00158"></a>00158           SINFONI_BINARY_VERSION,
+<a name="l00159"></a>00159           CPL_PLUGIN_TYPE_RECIPE,
+<a name="l00160"></a>00160           <span class="stringliteral">"sinfo_rec_psf"</span>,
+<a name="l00161"></a>00161           <span class="stringliteral">"PSF star data reduction"</span>,
+<a name="l00162"></a>00162           sinfo_rec_psf_description,
+<a name="l00163"></a>00163           <span class="stringliteral">"Andrea Modigliani"</span>,
+<a name="l00164"></a>00164           <span class="stringliteral">"Andrea.Modigliani at eso.org"</span>,
+<a name="l00165"></a>00165           sinfo_get_license(),
+<a name="l00166"></a>00166           sinfo_rec_psf_create,
+<a name="l00167"></a>00167           sinfo_rec_psf_exec,
+<a name="l00168"></a>00168           sinfo_rec_psf_destroy);
+<a name="l00169"></a>00169 
+<a name="l00170"></a>00170   cpl_pluginlist_append(list, plugin);
+<a name="l00171"></a>00171 
+<a name="l00172"></a>00172   <span class="keywordflow">return</span> 0;
+<a name="l00173"></a>00173 
+<a name="l00174"></a>00174 }
+<a name="l00175"></a>00175 
+<a name="l00176"></a>00176 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00184"></a>00184 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00185"></a>00185 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_psf_create(cpl_plugin *plugin)
+<a name="l00186"></a>00186 {
+<a name="l00187"></a>00187     cpl_recipe      * recipe ;
+<a name="l00188"></a>00188 
+<a name="l00189"></a>00189     <span class="comment">/* Check that the plugin is part of a valid recipe */</span>
+<a name="l00190"></a>00190     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00191"></a>00191         recipe = (cpl_recipe *)plugin ;
+<a name="l00192"></a>00192     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00193"></a>00193     <a class="code" href="group__irplib__utils.html#gaf9d392144014e2363054bc3f83c8e47e" title="Reset IRPLIB state.">irplib_reset</a>();
+<a name="l00194"></a>00194 
+<a name="l00195"></a>00195     <span class="comment">/* Create the parameters list in the cpl_recipe object */</span>
+<a name="l00196"></a>00196     recipe->parameters = cpl_parameterlist_new() ; 
+<a name="l00197"></a>00197 
+<a name="l00198"></a>00198   <span class="comment">/*</span>
+<a name="l00199"></a>00199 <span class="comment">   * Fill the parameter list.</span>
+<a name="l00200"></a>00200 <span class="comment">   */</span>
+<a name="l00201"></a>00201   sinfo_product_config_add(recipe->parameters);
+<a name="l00202"></a>00202   sinfo_prepare_stacked_frames_config_add(recipe->parameters);
+<a name="l00203"></a>00203   sinfo_objnod_config_add(recipe->parameters); 
+<a name="l00204"></a>00204   sinfo_skycor_config_add(recipe->parameters); 
+<a name="l00205"></a>00205  <span class="keywordflow">return</span> 0;
+<a name="l00206"></a>00206 
+<a name="l00207"></a>00207 }
+<a name="l00208"></a>00208 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00214"></a>00214 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00215"></a>00215 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_psf_exec(cpl_plugin *plugin)
+<a name="l00216"></a>00216 {
+<a name="l00217"></a>00217     cpl_recipe  *   recipe ;
+<a name="l00218"></a>00218     cpl_errorstate initial_errorstate = cpl_errorstate_get();
+<a name="l00219"></a>00219     
+<a name="l00220"></a>00220     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00221"></a>00221     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00222"></a>00222         recipe = (cpl_recipe *)plugin ;
+<a name="l00223"></a>00223     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00224"></a>00224 
+<a name="l00225"></a>00225     <span class="keywordflow">if</span> (!cpl_errorstate_is_equal(initial_errorstate)) {                      
+<a name="l00226"></a>00226         <span class="comment">/* Dump the error history since recipe execution start.                </span>
+<a name="l00227"></a>00227 <span class="comment">           At this point the recipe cannot recover from the error */</span>           
+<a name="l00228"></a>00228         cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);              
+<a name="l00229"></a>00229     } 
+<a name="l00230"></a>00230   <span class="keywordflow">return</span> sinfo_rec_psf(recipe->parameters, recipe->frames);
+<a name="l00231"></a>00231 
+<a name="l00232"></a>00232 }
+<a name="l00233"></a>00233 
+<a name="l00234"></a>00234 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00240"></a>00240 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00241"></a>00241 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_psf_destroy(cpl_plugin *plugin)
+<a name="l00242"></a>00242 {
+<a name="l00243"></a>00243     cpl_recipe  *   recipe ;
+<a name="l00244"></a>00244     
+<a name="l00245"></a>00245     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00246"></a>00246     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00247"></a>00247         recipe = (cpl_recipe *)plugin ;
+<a name="l00248"></a>00248     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00249"></a>00249 
+<a name="l00250"></a>00250   cpl_parameterlist_delete(recipe->parameters);
+<a name="l00251"></a>00251 
+<a name="l00252"></a>00252   <span class="keywordflow">return</span> 0;
+<a name="l00253"></a>00253 
+<a name="l00254"></a>00254 }
+<a name="l00255"></a>00255 
+<a name="l00256"></a>00256 
+<a name="l00257"></a>00257 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00264"></a>00264 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00265"></a>00265 
+<a name="l00266"></a>00266 <span class="comment">/*</span>
+<a name="l00267"></a>00267 <span class="comment"> * The actual recipe actually start here.</span>
+<a name="l00268"></a>00268 <span class="comment"> */</span>
+<a name="l00269"></a>00269 
+<a name="l00270"></a>00270 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00271"></a>00271 sinfo_rec_psf(cpl_parameterlist *config, cpl_frameset *<span class="keyword">set</span>)
+<a name="l00272"></a>00272 {
+<a name="l00273"></a>00273 
+<a name="l00274"></a>00274 
+<a name="l00275"></a>00275   <span class="keyword">const</span> <span class="keywordtype">char</span>* pro_ctg_cube;
+<a name="l00276"></a>00276   sinfo_msg(<span class="stringliteral">"Welcome to SINFONI Pipeline release %d.%d.%d"</span>,
+<a name="l00277"></a>00277         SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
+<a name="l00278"></a>00278 
+<a name="l00279"></a>00279   <span class="keywordflow">if</span>(sinfo_dfs_set_groups(<span class="keyword">set</span>)) {
+<a name="l00280"></a>00280     sinfo_msg(<span class="stringliteral">"Cannot indentify RAW and CALIB frames"</span>) ;
+<a name="l00281"></a>00281     <span class="keywordflow">return</span> -1;
+<a name="l00282"></a>00282   }
+<a name="l00283"></a>00283 
+<a name="l00284"></a>00284   <span class="comment">/* =============================================================== </span>
+<a name="l00285"></a>00285 <span class="comment">     Defines several framesets each with a pair obj-sky, </span>
+<a name="l00286"></a>00286 <span class="comment">     stack each pair, put the results in set </span>
+<a name="l00287"></a>00287 <span class="comment">     =============================================================== */</span>
+<a name="l00288"></a>00288   ck0(sinfo_cub_stk_frames(config,&<span class="keyword">set</span>,cpl_func,&pro_ctg_cube),
+<a name="l00289"></a>00289                            <span class="stringliteral">"Cannot stack RAW frames"</span>) ;
+<a name="l00290"></a>00290  
+<a name="l00291"></a>00291   <span class="comment">/* =============================================================== </span>
+<a name="l00292"></a>00292 <span class="comment">     SCI OBJNOD </span>
+<a name="l00293"></a>00293 <span class="comment">     =============================================================== */</span>
+<a name="l00294"></a>00294   sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ;
+<a name="l00295"></a>00295   sinfo_msg(<span class="stringliteral">"COADDING CUBES"</span>);
+<a name="l00296"></a>00296   sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ;
+<a name="l00297"></a>00297 
+<a name="l00298"></a>00298   ck0(sinfo_new_cubes_coadd(cpl_func,config, <span class="keyword">set</span>, pro_ctg_cube),
+<a name="l00299"></a>00299       <span class="stringliteral">"COADDING CUBES"</span>);
+<a name="l00300"></a>00300   sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ;
+<a name="l00301"></a>00301   sinfo_msg(<span class="stringliteral">"COADDED CUBES"</span>);
+<a name="l00302"></a>00302   sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ;
+<a name="l00303"></a>00303 
+<a name="l00304"></a>00304   <span class="comment">/* =============================================================== </span>
+<a name="l00305"></a>00305 <span class="comment">     PSF</span>
+<a name="l00306"></a>00306 <span class="comment">     =============================================================== */</span>
+<a name="l00307"></a>00307 
+<a name="l00308"></a>00308   sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ;
+<a name="l00309"></a>00309   sinfo_msg(<span class="stringliteral">"REDUCE PSF STD STAR FRAMES"</span>);
+<a name="l00310"></a>00310   sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ; 
+<a name="l00311"></a>00311   ck0(sinfo_new_psf(cpl_func,config,<span class="keyword">set</span>),<span class="stringliteral">"REDUCING PSF STD STAR FRAMES"</span>);
+<a name="l00312"></a>00312   sinfo_msg(<span class="stringliteral">"SUCCESS REDUCE PSF STD STAR FRAMES"</span>) ; 
+<a name="l00313"></a>00313 
+<a name="l00314"></a>00314 
+<a name="l00315"></a>00315  cleanup:
+<a name="l00316"></a>00316 
+<a name="l00317"></a>00317 
+<a name="l00318"></a>00318   <span class="keywordflow">if</span> (cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l00319"></a>00319     <span class="keywordflow">return</span> -1;
+<a name="l00320"></a>00320   } <span class="keywordflow">else</span> {
+<a name="l00321"></a>00321     <span class="keywordflow">return</span> 0;
+<a name="l00322"></a>00322   }
+<a name="l00323"></a>00323 
+<a name="l00324"></a>00324 
+<a name="l00325"></a>00325 
+<a name="l00326"></a>00326 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__rec__pupil_8c_source.html b/html/sinfo__rec__pupil_8c_source.html
new file mode 100644
index 0000000..c55725e
--- /dev/null
+++ b/html/sinfo__rec__pupil_8c_source.html
@@ -0,0 +1,280 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_rec_pupil.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_rec_pupil.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_rec_pupil.c,v 1.17 2008/02/12 14:56:50 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the SINFONI Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020  
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2008/02/12 14:56:50 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.17 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028  <span class="comment">/****************************************************************</span>
+<a name="l00029"></a>00029 <span class="comment">  *          Wave_Cal Frames Data Reduction                          *</span>
+<a name="l00030"></a>00030 <span class="comment">  ****************************************************************/</span>
+<a name="l00031"></a>00031 
+<a name="l00032"></a>00032 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                                Includes</span>
+<a name="l00034"></a>00034 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 
+<a name="l00036"></a>00036 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00037"></a>00037 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>          <span class="comment">/* allows the program compilation */</span>
+<a name="l00038"></a>00038 <span class="preprocessor">#endif</span>
+<a name="l00039"></a>00039 <span class="preprocessor"></span>
+<a name="l00040"></a>00040 <span class="comment">/* std */</span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include <strings.h></span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include <string.h></span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include <stdio.h></span>
+<a name="l00044"></a>00044 
+<a name="l00045"></a>00045 
+<a name="l00046"></a>00046 <span class="comment">/* cpl */</span>
+<a name="l00047"></a>00047 <span class="preprocessor">#include <cpl.h></span>      
+<a name="l00048"></a>00048 
+<a name="l00049"></a>00049 <span class="comment">/* irplib */</span>
+<a name="l00050"></a>00050 <span class="preprocessor">#include <irplib_utils.h></span>
+<a name="l00051"></a>00051 
+<a name="l00052"></a>00052 
+<a name="l00053"></a>00053 <span class="comment">/* sinfoni */</span>
+<a name="l00054"></a>00054 <span class="preprocessor">#include <sinfo_pro_types.h></span>
+<a name="l00055"></a>00055 <span class="preprocessor">#include <sinfo_product_config.h></span>
+<a name="l00056"></a>00056 <span class="preprocessor">#include <sinfo_prepare_stacked_frames_config.h></span>
+<a name="l00057"></a>00057 <span class="preprocessor">#include <sinfo_objnod_config.h></span>
+<a name="l00058"></a>00058 <span class="preprocessor">#include <sinfo_raw_types.h></span>
+<a name="l00059"></a>00059 <span class="preprocessor">#include <sinfo_tpl_utils.h></span>
+<a name="l00060"></a>00060 <span class="preprocessor">#include <sinfo_tpl_dfs.h></span>
+<a name="l00061"></a>00061 <span class="preprocessor">#include <sinfo_hidden.h></span>
+<a name="l00062"></a>00062 <span class="preprocessor">#include <sinfo_globals.h></span>
+<a name="l00063"></a>00063 <span class="preprocessor">#include <sinfo_functions.h></span>
+<a name="l00064"></a>00064 <span class="preprocessor">#include <sinfo_msg.h></span>
+<a name="l00065"></a>00065 <span class="preprocessor">#include <sinfo_new_prepare_stacked_frames.h></span>
+<a name="l00066"></a>00066 <span class="preprocessor">#include <sinfo_new_objnod.h></span>
+<a name="l00067"></a>00067 <span class="preprocessor">#include <sinfo_error.h></span>
+<a name="l00068"></a>00068 <span class="preprocessor">#include <sinfo_utils_wrappers.h></span>
+<a name="l00069"></a>00069 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00070"></a>00070 <span class="comment">                            Functions prototypes</span>
+<a name="l00071"></a>00071 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00072"></a>00072 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_pupil_create(cpl_plugin *);
+<a name="l00073"></a>00073 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_pupil_exec(cpl_plugin *);
+<a name="l00074"></a>00074 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_pupil_destroy(cpl_plugin *);
+<a name="l00075"></a>00075 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_pupil(cpl_parameterlist *, cpl_frameset *);
+<a name="l00076"></a>00076 
+<a name="l00077"></a>00077 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00078"></a>00078 <span class="comment">                            Static variables</span>
+<a name="l00079"></a>00079 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00080"></a>00080 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_rec_pupil_description1[] =
+<a name="l00081"></a>00081 <span class="stringliteral">"This recipe performs science data reduction.\n"</span>
+<a name="l00082"></a>00082 <span class="stringliteral">"The input files are science object and sky frames \n"</span>
+<a name="l00083"></a>00083 <span class="stringliteral">"with tags OBJECT_NODDING and SKY_NODDING\n"</span>
+<a name="l00084"></a>00084 <span class="stringliteral">"Master calibration frames:\n"</span>;
+<a name="l00085"></a>00085 
+<a name="l00086"></a>00086 
+<a name="l00087"></a>00087 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_rec_pupil_description2[] =
+<a name="l00088"></a>00088 <span class="stringliteral">"A corresponding (band,preoptics) wavelength map image with tag WAVE_MAP\n"</span>
+<a name="l00089"></a>00089 <span class="stringliteral">"A corresponding (band,preoptics) master flat field with tag MASTER_FLAT_LAMP\n"</span>
+<a name="l00090"></a>00090 <span class="stringliteral">"A corresponding (band,preoptics) master bad pixel map with tag MASTER_BP_MAP\n"</span>
+<a name="l00091"></a>00091 <span class="stringliteral">"A corresponding (band,preoptics) slitlets position frame with tag SLIT_POS\n"</span>
+<a name="l00092"></a>00092 <span class="stringliteral">"A corresponding (band) distortion table with tag DISTORTION\n"</span>
+<a name="l00093"></a>00093 <span class="stringliteral">"A corresponding (band) slitlet distance table with tag SLITLETS_DISTANCE\n"</span>;
+<a name="l00094"></a>00094 
+<a name="l00095"></a>00095 
+<a name="l00096"></a>00096 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_rec_pupil_description3[] =
+<a name="l00097"></a>00097 <span class="stringliteral">"The output is an image resulting from the IMA1 op IMA2 where op indicates\n"</span>
+<a name="l00098"></a>00098 <span class="stringliteral">"A reference table with the position of the 1st column with tag FIRST_COLUMN\n"</span>
+<a name="l00099"></a>00099 <span class="stringliteral">"Relevant outputs are:\n"</span>
+<a name="l00100"></a>00100 <span class="stringliteral">"combined cubes (PRO.CATG=x_OBS x=STD,OBJ,PSF)\n"</span>
+<a name="l00101"></a>00101 <span class="stringliteral">"reconstructed cube (PRO.CATG=COADD_x_OBS x=STD,OBJ,PSF)\n"</span>
+<a name="l00102"></a>00102 <span class="stringliteral">"An average along Z of the reconstructed cube \n"</span>
+<a name="l00103"></a>00103 <span class="stringliteral">"(PRO.CATG=MED_x_OBS x=STD,OBJ,PSF)\n"</span>
+<a name="l00104"></a>00104 <span class="stringliteral">"The bad pixel map associated to the cube \n"</span>
+<a name="l00105"></a>00105 <span class="stringliteral">"(PRO.CATG=BP_MAP_COADD_x_OBS x=STD,OBJ,PSF)\n"</span>;
+<a name="l00106"></a>00106 
+<a name="l00107"></a>00107 
+<a name="l00108"></a>00108 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_rec_pupil_description4[] =
+<a name="l00109"></a>00109 <span class="stringliteral">"Information on relevant parameters can be found with\n"</span>
+<a name="l00110"></a>00110 <span class="stringliteral">"esorex --params sinfo_rec_pupil\n"</span>
+<a name="l00111"></a>00111 <span class="stringliteral">"esorex --help sinfo_rec_pupil\n"</span>
+<a name="l00112"></a>00112 <span class="stringliteral">"\n"</span>;
+<a name="l00113"></a>00113 
+<a name="l00114"></a>00114 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_rec_pupil_description[1300];
+<a name="l00115"></a>00115 
+<a name="l00116"></a>00116 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00117"></a>00117 <span class="comment">                                Functions code</span>
+<a name="l00118"></a>00118 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00119"></a>00119 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00123"></a>00123 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00125"></a>00125 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00134"></a>00134 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00135"></a>00135 
+<a name="l00136"></a>00136 <span class="keywordtype">int</span>
+<a name="l00137"></a><a class="code" href="group__sinfo__rec__pupil.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693">00137</a> <a class="code" href="group__sinfo__rec__detlin.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693" title="Build the list of available plugins, for this module.">cpl_plugin_get_info</a>(cpl_pluginlist *list)
+<a name="l00138"></a>00138 {
+<a name="l00139"></a>00139 
+<a name="l00140"></a>00140   cpl_recipe *recipe = cpl_calloc(1, <span class="keyword">sizeof</span> *recipe);
+<a name="l00141"></a>00141   cpl_plugin *plugin = &recipe->interface;
+<a name="l00142"></a>00142 
+<a name="l00143"></a>00143 
+<a name="l00144"></a>00144   strcpy(sinfo_rec_pupil_description,sinfo_rec_pupil_description1);
+<a name="l00145"></a>00145   strcat(sinfo_rec_pupil_description,sinfo_rec_pupil_description2);
+<a name="l00146"></a>00146   strcat(sinfo_rec_pupil_description,sinfo_rec_pupil_description3);
+<a name="l00147"></a>00147   strcat(sinfo_rec_pupil_description,sinfo_rec_pupil_description4);
+<a name="l00148"></a>00148 
+<a name="l00149"></a>00149   cpl_plugin_init(plugin,
+<a name="l00150"></a>00150           CPL_PLUGIN_API,
+<a name="l00151"></a>00151           SINFONI_BINARY_VERSION,
+<a name="l00152"></a>00152           CPL_PLUGIN_TYPE_RECIPE,
+<a name="l00153"></a>00153           <span class="stringliteral">"sinfo_rec_pupil"</span>,
+<a name="l00154"></a>00154           <span class="stringliteral">"Pupil data reduction"</span>,
+<a name="l00155"></a>00155           sinfo_rec_pupil_description,
+<a name="l00156"></a>00156           <span class="stringliteral">"Andrea Modigliani"</span>,
+<a name="l00157"></a>00157           <span class="stringliteral">"Andrea.Modigliani at eso.org"</span>,
+<a name="l00158"></a>00158           sinfo_get_license(),
+<a name="l00159"></a>00159           sinfo_rec_pupil_create,
+<a name="l00160"></a>00160           sinfo_rec_pupil_exec,
+<a name="l00161"></a>00161           sinfo_rec_pupil_destroy);
+<a name="l00162"></a>00162  
+<a name="l00163"></a>00163   cpl_pluginlist_append(list, plugin);
+<a name="l00164"></a>00164 
+<a name="l00165"></a>00165   <span class="keywordflow">return</span> 0;
+<a name="l00166"></a>00166 
+<a name="l00167"></a>00167 }
+<a name="l00168"></a>00168 
+<a name="l00169"></a>00169 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00177"></a>00177 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00178"></a>00178  
+<a name="l00179"></a>00179 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_pupil_create(cpl_plugin *plugin)
+<a name="l00180"></a>00180 {
+<a name="l00181"></a>00181    cpl_recipe      * recipe ;
+<a name="l00182"></a>00182 
+<a name="l00183"></a>00183     <span class="comment">/* Check that the plugin is part of a valid recipe */</span>
+<a name="l00184"></a>00184     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00185"></a>00185         recipe = (cpl_recipe *)plugin ;
+<a name="l00186"></a>00186     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00187"></a>00187     cpl_error_reset();
+<a name="l00188"></a>00188     <a class="code" href="group__irplib__utils.html#gaf9d392144014e2363054bc3f83c8e47e" title="Reset IRPLIB state.">irplib_reset</a>();
+<a name="l00189"></a>00189 
+<a name="l00190"></a>00190     <span class="comment">/* Create the parameters list in the cpl_recipe object */</span>
+<a name="l00191"></a>00191     recipe->parameters = cpl_parameterlist_new() ; 
+<a name="l00192"></a>00192 
+<a name="l00193"></a>00193 
+<a name="l00194"></a>00194   <span class="comment">/*</span>
+<a name="l00195"></a>00195 <span class="comment">   * Fill the parameter list.</span>
+<a name="l00196"></a>00196 <span class="comment">   */</span>  
+<a name="l00197"></a>00197 
+<a name="l00198"></a>00198   sinfo_product_config_add(recipe->parameters);
+<a name="l00199"></a>00199   sinfo_prepare_stacked_frames_config_add(recipe->parameters);
+<a name="l00200"></a>00200   sinfo_objnod_config_add(recipe->parameters);
+<a name="l00201"></a>00201   <span class="keywordflow">return</span> 0;
+<a name="l00202"></a>00202 
+<a name="l00203"></a>00203 }
+<a name="l00204"></a>00204 
+<a name="l00205"></a>00205 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00211"></a>00211 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00212"></a>00212 
+<a name="l00213"></a>00213 
+<a name="l00214"></a>00214 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_pupil_exec(cpl_plugin *plugin)
+<a name="l00215"></a>00215 {
+<a name="l00216"></a>00216 
+<a name="l00217"></a>00217   cpl_recipe *recipe = (cpl_recipe *) plugin;
+<a name="l00218"></a>00218    <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00219"></a>00219     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00220"></a>00220         recipe = (cpl_recipe *)plugin ;
+<a name="l00221"></a>00221     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00222"></a>00222 
+<a name="l00223"></a>00223   <span class="keywordflow">return</span> sinfo_rec_pupil(recipe->parameters, recipe->frames);
+<a name="l00224"></a>00224 
+<a name="l00225"></a>00225 }
+<a name="l00226"></a>00226 
+<a name="l00227"></a>00227 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00233"></a>00233 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00234"></a>00234 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_pupil_destroy(cpl_plugin *plugin)
+<a name="l00235"></a>00235 {
+<a name="l00236"></a>00236   cpl_recipe  *   recipe ;
+<a name="l00237"></a>00237     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00238"></a>00238     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00239"></a>00239         recipe = (cpl_recipe *)plugin ;
+<a name="l00240"></a>00240     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00241"></a>00241 
+<a name="l00242"></a>00242   cpl_parameterlist_delete(recipe->parameters);
+<a name="l00243"></a>00243 
+<a name="l00244"></a>00244   <span class="keywordflow">return</span> 0;
+<a name="l00245"></a>00245 
+<a name="l00246"></a>00246 }
+<a name="l00247"></a>00247 
+<a name="l00248"></a>00248 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00255"></a>00255 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00256"></a>00256 <span class="comment">/*</span>
+<a name="l00257"></a>00257 <span class="comment"> * The actual recipe actually start here.</span>
+<a name="l00258"></a>00258 <span class="comment"> */</span>
+<a name="l00259"></a>00259 
+<a name="l00260"></a>00260 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_pupil(cpl_parameterlist *config, cpl_frameset *<span class="keyword">set</span>)
+<a name="l00261"></a>00261 {
+<a name="l00262"></a>00262  
+<a name="l00263"></a>00263   fake* fk=NULL;
+<a name="l00264"></a>00264   fk=sinfo_fake_new();
+<a name="l00265"></a>00265 
+<a name="l00266"></a>00266    sinfo_msg(<span class="stringliteral">"Welcome to SINFONI Pipeline release %d.%d.%d"</span>,
+<a name="l00267"></a>00267         SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
+<a name="l00268"></a>00268 
+<a name="l00269"></a>00269    ck0(sinfo_dfs_set_groups(<span class="keyword">set</span>),<span class="stringliteral">"Cannot indentify RAW and CALIB frames"</span>) ;
+<a name="l00270"></a>00270 
+<a name="l00271"></a>00271    <span class="comment">/* hidden parameters */</span>
+<a name="l00272"></a>00272    sinfo_msg(<span class="stringliteral">"---------------------------------------------"</span>);
+<a name="l00273"></a>00273    sinfo_msg(<span class="stringliteral">"%s FRAME DETERMINATION"</span>, PRO_PUPIL_LAMP_STACKED);
+<a name="l00274"></a>00274    sinfo_msg(<span class="stringliteral">"---------------------------------------------"</span>);
+<a name="l00275"></a>00275   
+<a name="l00276"></a>00276    ck0(sinfo_new_prepare_stacked_frames(cpl_func,config, <span class="keyword">set</span>, NULL,
+<a name="l00277"></a>00277                     PRO_PUPIL_LAMP_STACKED,0,fk ),
+<a name="l00278"></a>00278        <span class="stringliteral">"Failed %s FRAME DETERMINATION"</span>, PRO_PUPIL_LAMP_STACKED);
+<a name="l00279"></a>00279    sinfo_msg(<span class="stringliteral">"%s FRAME DETERMINATION SUCCESS"</span>, PRO_PUPIL_LAMP_STACKED);
+<a name="l00280"></a>00280   
+<a name="l00281"></a>00281    sinfo_msg(<span class="stringliteral">"---------------------------------------------"</span>);
+<a name="l00282"></a>00282    sinfo_msg(<span class="stringliteral">"PUPIL DATA REDUCTION"</span>);
+<a name="l00283"></a>00283    sinfo_msg(<span class="stringliteral">"---------------------------------------------"</span>);
+<a name="l00284"></a>00284   
+<a name="l00285"></a>00285    ck0(sinfo_new_objnod(cpl_func,config, <span class="keyword">set</span>,PRO_COADD_PUPIL),
+<a name="l00286"></a>00286        <span class="stringliteral">"Failed PUPIL DATA REDUCTION"</span>) ;
+<a name="l00287"></a>00287    sinfo_msg(<span class="stringliteral">"PUPIL DATA REDUCTION SUCCESS"</span>);
+<a name="l00288"></a>00288  
+<a name="l00289"></a>00289  cleanup:
+<a name="l00290"></a>00290   sinfo_fake_delete(&fk);
+<a name="l00291"></a>00291 
+<a name="l00292"></a>00292   <span class="keywordflow">if</span> (cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l00293"></a>00293     <span class="keywordflow">return</span> -1;
+<a name="l00294"></a>00294   } <span class="keywordflow">else</span> {
+<a name="l00295"></a>00295     <span class="keywordflow">return</span> 0;
+<a name="l00296"></a>00296   }
+<a name="l00297"></a>00297 
+<a name="l00298"></a>00298 
+<a name="l00299"></a>00299 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__rec__stdstar_8c_source.html b/html/sinfo__rec__stdstar_8c_source.html
new file mode 100644
index 0000000..371c783
--- /dev/null
+++ b/html/sinfo__rec__stdstar_8c_source.html
@@ -0,0 +1,316 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_rec_stdstar.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_rec_stdstar.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_rec_stdstar.c,v 1.22 2008/02/12 14:56:50 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the SINFONI Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2008/02/12 14:56:50 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.22 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028  <span class="comment">/****************************************************************</span>
+<a name="l00029"></a>00029 <span class="comment">  *          Standard_Star Frames Data Reduction                          *</span>
+<a name="l00030"></a>00030 <span class="comment">  ****************************************************************/</span>
+<a name="l00031"></a>00031 
+<a name="l00032"></a>00032 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                                Includes</span>
+<a name="l00034"></a>00034 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 
+<a name="l00036"></a>00036 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00037"></a>00037 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>          <span class="comment">/* allows the program compilation */</span>
+<a name="l00038"></a>00038 <span class="preprocessor">#endif</span>
+<a name="l00039"></a>00039 <span class="preprocessor"></span>
+<a name="l00040"></a>00040 <span class="comment">/* std */</span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include <strings.h></span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include <string.h></span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include <stdio.h></span>
+<a name="l00044"></a>00044 
+<a name="l00045"></a>00045 
+<a name="l00046"></a>00046 <span class="comment">/* cpl */</span>
+<a name="l00047"></a>00047 <span class="preprocessor">#include <cpl.h></span>      
+<a name="l00048"></a>00048 
+<a name="l00049"></a>00049 <span class="comment">/* irplib */</span>
+<a name="l00050"></a>00050 <span class="preprocessor">#include <irplib_utils.h></span>
+<a name="l00051"></a>00051 
+<a name="l00052"></a>00052 <span class="comment">/* sinfoni */</span>
+<a name="l00053"></a>00053 <span class="preprocessor">#include <sinfo_pro_types.h></span>
+<a name="l00054"></a>00054 <span class="preprocessor">#include <sinfo_product_config.h></span>
+<a name="l00055"></a>00055 <span class="preprocessor">#include <sinfo_prepare_stacked_frames_config.h></span>
+<a name="l00056"></a>00056 <span class="preprocessor">#include <sinfo_objnod_config.h></span>
+<a name="l00057"></a>00057 <span class="preprocessor">#include <sinfo_skycor_config.h></span>
+<a name="l00058"></a>00058 <span class="preprocessor">#include <sinfo_standard_star_config.h></span>
+<a name="l00059"></a>00059 <span class="preprocessor">#include <sinfo_new_prepare_stacked_frames.h></span>
+<a name="l00060"></a>00060 <span class="preprocessor">#include <sinfo_new_cubes_coadd.h></span>
+<a name="l00061"></a>00061 <span class="preprocessor">#include <sinfo_new_stdstar.h></span>
+<a name="l00062"></a>00062 <span class="preprocessor">#include <sinfo_functions.h></span>
+<a name="l00063"></a>00063 <span class="preprocessor">#include <sinfo_tpl_utils.h></span>
+<a name="l00064"></a>00064 <span class="preprocessor">#include <sinfo_tpl_dfs.h></span>
+<a name="l00065"></a>00065 <span class="preprocessor">#include <sinfo_hidden.h></span>
+<a name="l00066"></a>00066 <span class="preprocessor">#include <sinfo_globals.h></span>
+<a name="l00067"></a>00067 <span class="preprocessor">#include <sinfo_msg.h></span>
+<a name="l00068"></a>00068 <span class="preprocessor">#include <sinfo_rec_utils.h></span>
+<a name="l00069"></a>00069 <span class="preprocessor">#include <sinfo_error.h></span>
+<a name="l00070"></a>00070 <span class="preprocessor">#include <sinfo_utils_wrappers.h></span>
+<a name="l00071"></a>00071 
+<a name="l00072"></a>00072 
+<a name="l00073"></a>00073 
+<a name="l00074"></a>00074 
+<a name="l00075"></a>00075 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00076"></a>00076 <span class="comment">                            Functions prototypes</span>
+<a name="l00077"></a>00077 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00078"></a>00078 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_stdstar_create(cpl_plugin *) ;
+<a name="l00079"></a>00079 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_stdstar_exec(cpl_plugin *) ;
+<a name="l00080"></a>00080 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_stdstar_destroy(cpl_plugin *) ;
+<a name="l00081"></a>00081 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_stdstar(cpl_parameterlist *, cpl_frameset *);
+<a name="l00082"></a>00082 
+<a name="l00083"></a>00083 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00084"></a>00084 <span class="comment">                            Static variables</span>
+<a name="l00085"></a>00085 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00086"></a>00086 
+<a name="l00087"></a>00087 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_rec_stdstar_description1[] =
+<a name="l00088"></a>00088 <span class="stringliteral">"This recipe performs science data reduction.\n"</span>
+<a name="l00089"></a>00089 <span class="stringliteral">"The input files are science object and sky frames \n"</span>
+<a name="l00090"></a>00090 <span class="stringliteral">"with tags STD_NODDING and SKY_STD_NODDING\n"</span>;
+<a name="l00091"></a>00091 
+<a name="l00092"></a>00092 
+<a name="l00093"></a>00093 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_rec_stdstar_description2[] =
+<a name="l00094"></a>00094 <span class="stringliteral">"Master calibration frames:\n"</span>
+<a name="l00095"></a>00095 <span class="stringliteral">"A corresponding (band,preoptics) wavelength map image with tag WAVE_MAP\n"</span>
+<a name="l00096"></a>00096 <span class="stringliteral">"A corresponding (band,preoptics) master flat field with tag MASTER_FLAT_LAMP\n"</span>
+<a name="l00097"></a>00097 <span class="stringliteral">"A corresponding (band,preoptics) master bad pixel map with tag MASTER_BP_MAP\n"</span>
+<a name="l00098"></a>00098 <span class="stringliteral">"A corresponding (band,preoptics) slitlets position frame with tag SLIT_POS\n"</span>
+<a name="l00099"></a>00099 <span class="stringliteral">"A corresponding (band) distortion table with tag DISTORTION\n"</span>
+<a name="l00100"></a>00100 <span class="stringliteral">"A corresponding (band) slitlet distance table with tag SLITLETS_DISTANCE\n"</span>;
+<a name="l00101"></a>00101 
+<a name="l00102"></a>00102 
+<a name="l00103"></a>00103 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_rec_stdstar_description3[] =
+<a name="l00104"></a>00104 <span class="stringliteral">"The output is an image resulting from the IMA1 op IMA2 where op indicates\n"</span>
+<a name="l00105"></a>00105 <span class="stringliteral">"A reference table with the position of the first  column \n"</span>
+<a name="l00106"></a>00106 <span class="stringliteral">"with tag FIRST_COLUMN\n"</span> 
+<a name="l00107"></a>00107 <span class="stringliteral">"Relevant outputs are:\n"</span>
+<a name="l00108"></a>00108 <span class="stringliteral">"combined cubes (PRO.CATG=x_OBS x=STD,OBJ,PSF)\n"</span>
+<a name="l00109"></a>00109 <span class="stringliteral">"reconstructed cube (PRO.CATG=COADD_x_OBS x=STD,OBJ,PSF)\n"</span>;
+<a name="l00110"></a>00110 
+<a name="l00111"></a>00111 
+<a name="l00112"></a>00112 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_rec_stdstar_description4[] =
+<a name="l00113"></a>00113 <span class="stringliteral">"An average along Z of the reconstructed cube \n"</span>
+<a name="l00114"></a>00114 <span class="stringliteral">"(PRO.CATG=MED_x_OBS x=STD,OBJ,PSF)\n"</span>
+<a name="l00115"></a>00115 <span class="stringliteral">"The bad pixel map associated to the cube \n"</span>
+<a name="l00116"></a>00116 <span class="stringliteral">"(PRO.CATG=BP_MAP_COADD_x_OBS x=STD,OBJ,PSF)\n"</span>
+<a name="l00117"></a>00117 <span class="stringliteral">"The std star spectrum image (PRO.CATG=STD_SPECTRUM)\n"</span>
+<a name="l00118"></a>00118 <span class="stringliteral">"The std start spectrum and efficiency spectrum table (PRO.CATG=STD_SPECTRA)\n"</span>
+<a name="l00119"></a>00119 <span class="stringliteral">"Information on relevant parameters can be found with\n"</span>
+<a name="l00120"></a>00120 <span class="stringliteral">"esorex --params sinfo_rec_stdstar\n"</span>
+<a name="l00121"></a>00121 <span class="stringliteral">"esorex --help sinfo_rec_stdstar\n"</span>
+<a name="l00122"></a>00122 <span class="stringliteral">"\n"</span>;
+<a name="l00123"></a>00123 
+<a name="l00124"></a>00124 
+<a name="l00125"></a>00125 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_rec_stdstar_description[1300];
+<a name="l00126"></a>00126 
+<a name="l00127"></a>00127 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00128"></a>00128 <span class="comment">                                Functions code</span>
+<a name="l00129"></a>00129 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00130"></a>00130 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00134"></a>00134 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00136"></a>00136 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00145"></a>00145 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00146"></a>00146 
+<a name="l00147"></a>00147 
+<a name="l00148"></a>00148 <span class="keywordtype">int</span>
+<a name="l00149"></a><a class="code" href="group__sinfo__rec__stdstar.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693">00149</a> <a class="code" href="group__sinfo__rec__detlin.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693" title="Build the list of available plugins, for this module.">cpl_plugin_get_info</a>(cpl_pluginlist *list)
+<a name="l00150"></a>00150 {
+<a name="l00151"></a>00151 
+<a name="l00152"></a>00152   cpl_recipe *recipe = cpl_calloc(1, <span class="keyword">sizeof</span> *recipe);
+<a name="l00153"></a>00153   cpl_plugin *plugin = &recipe->interface;
+<a name="l00154"></a>00154 
+<a name="l00155"></a>00155   strcpy(sinfo_rec_stdstar_description,sinfo_rec_stdstar_description1);
+<a name="l00156"></a>00156   strcat(sinfo_rec_stdstar_description,sinfo_rec_stdstar_description2);
+<a name="l00157"></a>00157   strcat(sinfo_rec_stdstar_description,sinfo_rec_stdstar_description3);
+<a name="l00158"></a>00158   strcat(sinfo_rec_stdstar_description,sinfo_rec_stdstar_description4);
+<a name="l00159"></a>00159 
+<a name="l00160"></a>00160 
+<a name="l00161"></a>00161   cpl_plugin_init(plugin,
+<a name="l00162"></a>00162           CPL_PLUGIN_API,
+<a name="l00163"></a>00163           SINFONI_BINARY_VERSION,
+<a name="l00164"></a>00164           CPL_PLUGIN_TYPE_RECIPE,
+<a name="l00165"></a>00165           <span class="stringliteral">"sinfo_rec_stdstar"</span>,
+<a name="l00166"></a>00166           <span class="stringliteral">"Standard star data reduction"</span>,
+<a name="l00167"></a>00167           sinfo_rec_stdstar_description,
+<a name="l00168"></a>00168           <span class="stringliteral">"Andrea Modigliani"</span>,
+<a name="l00169"></a>00169           <span class="stringliteral">"Andrea.Modigliani at eso.org"</span>,
+<a name="l00170"></a>00170           sinfo_get_license(),
+<a name="l00171"></a>00171           sinfo_rec_stdstar_create,
+<a name="l00172"></a>00172           sinfo_rec_stdstar_exec,
+<a name="l00173"></a>00173           sinfo_rec_stdstar_destroy);
+<a name="l00174"></a>00174 
+<a name="l00175"></a>00175   cpl_pluginlist_append(list, plugin);
+<a name="l00176"></a>00176 
+<a name="l00177"></a>00177   <span class="keywordflow">return</span> 0;
+<a name="l00178"></a>00178 
+<a name="l00179"></a>00179 }
+<a name="l00180"></a>00180 
+<a name="l00181"></a>00181 
+<a name="l00182"></a>00182 
+<a name="l00183"></a>00183 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00191"></a>00191 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00192"></a>00192 
+<a name="l00193"></a>00193 
+<a name="l00194"></a>00194 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_stdstar_create(cpl_plugin *plugin)
+<a name="l00195"></a>00195 {
+<a name="l00196"></a>00196     cpl_recipe      * recipe ;
+<a name="l00197"></a>00197 
+<a name="l00198"></a>00198     <span class="comment">/* Check that the plugin is part of a valid recipe */</span>
+<a name="l00199"></a>00199     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00200"></a>00200         recipe = (cpl_recipe *)plugin ;
+<a name="l00201"></a>00201     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00202"></a>00202     cpl_error_reset();
+<a name="l00203"></a>00203     <a class="code" href="group__irplib__utils.html#gaf9d392144014e2363054bc3f83c8e47e" title="Reset IRPLIB state.">irplib_reset</a>();
+<a name="l00204"></a>00204 
+<a name="l00205"></a>00205     <span class="comment">/* Create the parameters list in the cpl_recipe object */</span>
+<a name="l00206"></a>00206     recipe->parameters = cpl_parameterlist_new() ; 
+<a name="l00207"></a>00207 
+<a name="l00208"></a>00208 
+<a name="l00209"></a>00209   <span class="comment">/*</span>
+<a name="l00210"></a>00210 <span class="comment">   * Fill the parameter list.</span>
+<a name="l00211"></a>00211 <span class="comment">   */</span>
+<a name="l00212"></a>00212   sinfo_product_config_add(recipe->parameters);
+<a name="l00213"></a>00213   sinfo_prepare_stacked_frames_config_add(recipe->parameters);
+<a name="l00214"></a>00214   sinfo_objnod_config_add(recipe->parameters); 
+<a name="l00215"></a>00215   sinfo_skycor_config_add(recipe->parameters); 
+<a name="l00216"></a>00216   sinfo_standard_star_config_add(recipe->parameters);
+<a name="l00217"></a>00217   
+<a name="l00218"></a>00218   <span class="keywordflow">return</span> 0;
+<a name="l00219"></a>00219 
+<a name="l00220"></a>00220 }
+<a name="l00221"></a>00221 
+<a name="l00222"></a>00222 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00228"></a>00228 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00229"></a>00229 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_stdstar_exec(cpl_plugin *plugin)
+<a name="l00230"></a>00230 {
+<a name="l00231"></a>00231     cpl_recipe  *   recipe ;
+<a name="l00232"></a>00232     
+<a name="l00233"></a>00233     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00234"></a>00234     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00235"></a>00235         recipe = (cpl_recipe *)plugin ;
+<a name="l00236"></a>00236     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00237"></a>00237 
+<a name="l00238"></a>00238   <span class="keywordflow">return</span> sinfo_rec_stdstar(recipe->parameters, recipe->frames);
+<a name="l00239"></a>00239 
+<a name="l00240"></a>00240 }
+<a name="l00241"></a>00241 
+<a name="l00242"></a>00242 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00248"></a>00248 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00249"></a>00249 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_stdstar_destroy(cpl_plugin *plugin)
+<a name="l00250"></a>00250 {
+<a name="l00251"></a>00251     cpl_recipe  *   recipe ;
+<a name="l00252"></a>00252     
+<a name="l00253"></a>00253     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00254"></a>00254     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00255"></a>00255         recipe = (cpl_recipe *)plugin ;
+<a name="l00256"></a>00256     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00257"></a>00257 
+<a name="l00258"></a>00258   cpl_parameterlist_delete(recipe->parameters);
+<a name="l00259"></a>00259   <span class="keywordflow">return</span> 0;
+<a name="l00260"></a>00260 
+<a name="l00261"></a>00261 }
+<a name="l00262"></a>00262 
+<a name="l00263"></a>00263 
+<a name="l00264"></a>00264 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00271"></a>00271 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00272"></a>00272 
+<a name="l00273"></a>00273 
+<a name="l00274"></a>00274 <span class="comment">/*</span>
+<a name="l00275"></a>00275 <span class="comment"> * The actual recipe actually start here.</span>
+<a name="l00276"></a>00276 <span class="comment"> */</span>
+<a name="l00277"></a>00277 
+<a name="l00278"></a>00278 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00279"></a>00279 sinfo_rec_stdstar(cpl_parameterlist *config, cpl_frameset *<span class="keyword">set</span>)
+<a name="l00280"></a>00280 {
+<a name="l00281"></a>00281  
+<a name="l00282"></a>00282 
+<a name="l00283"></a>00283   <span class="keyword">const</span> <span class="keywordtype">char</span>* pro_ctg_cube;
+<a name="l00284"></a>00284   sinfo_msg(<span class="stringliteral">"Welcome to SINFONI Pipeline release %d.%d.%d"</span>,
+<a name="l00285"></a>00285         SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
+<a name="l00286"></a>00286 
+<a name="l00287"></a>00287   <span class="keywordflow">if</span>(sinfo_dfs_set_groups(<span class="keyword">set</span>)) {
+<a name="l00288"></a>00288     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Cannot indentify RAW and CALIB frames"</span>) ;
+<a name="l00289"></a>00289     <span class="keywordflow">return</span> -1;
+<a name="l00290"></a>00290   }
+<a name="l00291"></a>00291 
+<a name="l00292"></a>00292   <span class="comment">/* =============================================================== </span>
+<a name="l00293"></a>00293 <span class="comment">     Defines several framesets each with a pair obj-sky, </span>
+<a name="l00294"></a>00294 <span class="comment">     stack each pair, put the results in set </span>
+<a name="l00295"></a>00295 <span class="comment">     =============================================================== */</span>
+<a name="l00296"></a>00296   ck0(sinfo_cub_stk_frames(config,&<span class="keyword">set</span>,cpl_func,&pro_ctg_cube),
+<a name="l00297"></a>00297       <span class="stringliteral">"Cannot stack RAW frames"</span>);
+<a name="l00298"></a>00298 
+<a name="l00299"></a>00299   <span class="comment">/* =============================================================== </span>
+<a name="l00300"></a>00300 <span class="comment">     SCI SCIENCE </span>
+<a name="l00301"></a>00301 <span class="comment">     =============================================================== */</span>
+<a name="l00302"></a>00302   
+<a name="l00303"></a>00303   sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ;
+<a name="l00304"></a>00304   sinfo_msg(<span class="stringliteral">"COADDING CUBES"</span>);
+<a name="l00305"></a>00305   sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ;
+<a name="l00306"></a>00306 
+<a name="l00307"></a>00307   ck0(sinfo_new_cubes_coadd(cpl_func,config, <span class="keyword">set</span>, pro_ctg_cube),
+<a name="l00308"></a>00308       <span class="stringliteral">"COADDING CUBES"</span>) ;
+<a name="l00309"></a>00309 
+<a name="l00310"></a>00310   sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ;
+<a name="l00311"></a>00311   sinfo_msg(<span class="stringliteral">"COADDED CUBES"</span>);
+<a name="l00312"></a>00312   sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ; 
+<a name="l00313"></a>00313 
+<a name="l00314"></a>00314   <span class="comment">/* =============================================================== </span>
+<a name="l00315"></a>00315 <span class="comment">     STDSTAR </span>
+<a name="l00316"></a>00316 <span class="comment">     =============================================================== */</span>
+<a name="l00317"></a>00317   sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ;
+<a name="l00318"></a>00318   sinfo_msg(<span class="stringliteral">"STD STAR DATA REDUCTION"</span>);
+<a name="l00319"></a>00319   sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ;
+<a name="l00320"></a>00320 
+<a name="l00321"></a>00321   ck0(sinfo_new_stdstar(cpl_func,config, <span class="keyword">set</span> ),<span class="stringliteral">"REDUCING STD STAR DATA"</span>) ;
+<a name="l00322"></a>00322   sinfo_msg(<span class="stringliteral">"STD STAR DATA REDUCTION SUCCESS"</span>) ; 
+<a name="l00323"></a>00323 
+<a name="l00324"></a>00324 
+<a name="l00325"></a>00325  cleanup:
+<a name="l00326"></a>00326 
+<a name="l00327"></a>00327   <span class="keywordflow">if</span> (cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l00328"></a>00328     <span class="keywordflow">return</span> -1;
+<a name="l00329"></a>00329   } <span class="keywordflow">else</span> {
+<a name="l00330"></a>00330     <span class="keywordflow">return</span> 0;
+<a name="l00331"></a>00331   }
+<a name="l00332"></a>00332 
+<a name="l00333"></a>00333 
+<a name="l00334"></a>00334 }
+<a name="l00335"></a>00335 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__rec__utils_8c_source.html b/html/sinfo__rec__utils_8c_source.html
new file mode 100644
index 0000000..29150e0
--- /dev/null
+++ b/html/sinfo__rec__utils_8c_source.html
@@ -0,0 +1,1381 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_rec_utils.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_rec_utils.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_rec_utils.c,v 1.14 2012/03/03 10:18:26 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the SINFONI Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2012/03/03 10:18:26 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.14 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> */</span>
+<a name="l00026"></a>00026 
+<a name="l00027"></a>00027  <span class="comment">/****************************************************************</span>
+<a name="l00028"></a>00028 <span class="comment">  *           Object Data reduction                              *</span>
+<a name="l00029"></a>00029 <span class="comment">  ****************************************************************/</span>
+<a name="l00030"></a>00030 
+<a name="l00031"></a>00031 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00032"></a>00032 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>          <span class="comment">/* allows the program compilation */</span>
+<a name="l00033"></a>00033 <span class="preprocessor">#endif</span>
+<a name="l00034"></a>00034 <span class="preprocessor"></span>
+<a name="l00035"></a>00035 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00036"></a>00036 <span class="comment">                                Includes</span>
+<a name="l00037"></a>00037 <span class="comment">-----------------------------------------------------------------------------*/</span>
+<a name="l00038"></a>00038 <span class="comment">//Used only for sinfo_propertylist_has</span>
+<a name="l00039"></a>00039 <span class="preprocessor">#include "sinfo_dfs.h"</span>
+<a name="l00040"></a>00040 
+<a name="l00041"></a>00041 <span class="preprocessor">#include <stdio.h></span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include <sinfo_rec_utils.h></span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include <sinfo_functions.h></span>
+<a name="l00044"></a>00044 <span class="preprocessor">#include <sinfo_new_cubes_build.h></span>
+<a name="l00045"></a>00045 <span class="preprocessor">#include <sinfo_error.h></span>
+<a name="l00046"></a>00046 <span class="preprocessor">#include <sinfo_globals.h></span>
+<a name="l00047"></a>00047 <span class="preprocessor">#include <sinfo_utils_wrappers.h></span>
+<a name="l00048"></a>00048 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00049"></a>00049 <span class="comment">                            Functions prototypes</span>
+<a name="l00050"></a>00050 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00052"></a>00052 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00056"></a>00056 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00057"></a>00057 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span>* sinfo_new_set_stk_procatg(<span class="keyword">const</span> <span class="keywordtype">char</span>* tag);
+<a name="l00058"></a>00058 <span class="comment">/*</span>
+<a name="l00059"></a>00059 <span class="comment">static int</span>
+<a name="l00060"></a>00060 <span class="comment">sinfo_get_obj_sky_frm_pair(cpl_frameset** obj_set,</span>
+<a name="l00061"></a>00061 <span class="comment">                           const int i,</span>
+<a name="l00062"></a>00062 <span class="comment">                           cpl_frame** obj_frm,</span>
+<a name="l00063"></a>00063 <span class="comment">                           cpl_frame** sky_frm);</span>
+<a name="l00064"></a>00064 <span class="comment">*/</span>
+<a name="l00065"></a>00065 
+<a name="l00066"></a>00066 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00067"></a>00067 <span class="comment">                            Static variables</span>
+<a name="l00068"></a>00068 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00069"></a>00069 
+<a name="l00070"></a>00070 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00071"></a>00071 <span class="comment">                                Functions code</span>
+<a name="l00072"></a>00072 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00073"></a>00073 
+<a name="l00074"></a>00074 <span class="keywordtype">int</span>
+<a name="l00075"></a>00075 sinfo_new_stack_frames(cpl_parameterlist* cfg,
+<a name="l00076"></a>00076                        cpl_frameset* <span class="keyword">set</span>,
+<a name="l00077"></a>00077                        <span class="keyword">const</span> <span class="keywordtype">char</span>* procatg,
+<a name="l00078"></a>00078                        <span class="keyword">const</span> <span class="keywordtype">int</span> <span class="keywordtype">id</span>,
+<a name="l00079"></a>00079                        fake* fk,
+<a name="l00080"></a>00080                        <span class="keyword">const</span> <span class="keywordtype">char</span>* plugin_id)
+<a name="l00081"></a>00081 {
+<a name="l00082"></a>00082   <span class="keywordtype">int</span> ind=0;
+<a name="l00083"></a>00083   sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ;
+<a name="l00084"></a>00084   sinfo_msg(<span class="stringliteral">"PREPARE STACKED SET %d"</span>,<span class="keywordtype">id</span>) ;
+<a name="l00085"></a>00085   sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ;
+<a name="l00086"></a>00086   ck0(ind=sinfo_new_prepare_stacked_frames(plugin_id,cfg, <span class="keyword">set</span>, NULL,procatg,
+<a name="l00087"></a>00087                        <span class="keywordtype">id</span>,fk),<span class="stringliteral">" no: %d"</span>, ind) ;
+<a name="l00088"></a>00088   sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ;
+<a name="l00089"></a>00089   sinfo_msg(<span class="stringliteral">"PREPARED STACKED SET %d"</span>,<span class="keywordtype">id</span>) ;
+<a name="l00090"></a>00090   sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ;
+<a name="l00091"></a>00091   <span class="keywordflow">return</span> 0;
+<a name="l00092"></a>00092 
+<a name="l00093"></a>00093  cleanup:
+<a name="l00094"></a>00094   <span class="keywordflow">return</span> -1;
+<a name="l00095"></a>00095 
+<a name="l00096"></a>00096 }
+<a name="l00097"></a>00097 
+<a name="l00098"></a>00098 cpl_frame*
+<a name="l00099"></a>00099 sinfo_new_get_dummy_sky(cpl_frameset* obj_set)
+<a name="l00100"></a>00100 {
+<a name="l00101"></a>00101 
+<a name="l00102"></a>00102   cpl_imagelist* obj_list=NULL;
+<a name="l00103"></a>00103   cpl_image* fake_sky=NULL;
+<a name="l00104"></a>00104   cpl_frame* frame=NULL;
+<a name="l00105"></a>00105   cpl_frame* sky_frame=NULL;
+<a name="l00106"></a>00106 
+<a name="l00107"></a>00107   cpl_propertylist* plist=NULL;
+<a name="l00108"></a>00108   <span class="keywordtype">char</span> filename[FILE_NAME_SZ];
+<a name="l00109"></a>00109 
+<a name="l00110"></a>00110   check_nomsg(obj_list=cpl_imagelist_load_frameset(obj_set,CPL_TYPE_FLOAT,0,0));
+<a name="l00111"></a>00111   check_nomsg(fake_sky = cpl_imagelist_collapse_median_create(obj_list));
+<a name="l00112"></a>00112 
+<a name="l00113"></a>00113   check_nomsg(frame = cpl_frameset_get_frame(obj_set,0));
+<a name="l00114"></a>00114   strcpy(filename,cpl_frame_get_filename(frame));
+<a name="l00115"></a>00115 
+<a name="l00116"></a>00116   check(plist = cpl_propertylist_load(filename, 0),
+<a name="l00117"></a>00117     <span class="stringliteral">"getting header from reference ima frame %s"</span>,filename);
+<a name="l00118"></a>00118 
+<a name="l00119"></a>00119   <span class="keywordflow">if</span> (sinfo_propertylist_has(plist, KEY_NAME_DPR_TYPE)) {
+<a name="l00120"></a>00120     cpl_propertylist_set_string(plist, KEY_NAME_DPR_TYPE, <span class="stringliteral">"SKY"</span>);
+<a name="l00121"></a>00121   } <span class="keywordflow">else</span> {
+<a name="l00122"></a>00122     cpl_propertylist_append_string(plist, KEY_NAME_DPR_TYPE,<span class="stringliteral">"SKY"</span>) ;
+<a name="l00123"></a>00123   }
+<a name="l00124"></a>00124 
+<a name="l00125"></a>00125   check(cpl_image_save(fake_sky, <span class="stringliteral">"out_fake_sky.fits"</span>, CPL_BPP_IEEE_FLOAT,
+<a name="l00126"></a>00126                plist,CPL_IO_DEFAULT),
+<a name="l00127"></a>00127     <span class="stringliteral">"Cannot save the product %s"</span>,<span class="stringliteral">"out_fake_sky.fits"</span>);
+<a name="l00128"></a>00128 
+<a name="l00129"></a>00129   sinfo_free_propertylist(&plist);
+<a name="l00130"></a>00130 
+<a name="l00131"></a>00131   check_nomsg(sky_frame = cpl_frame_new()) ;
+<a name="l00132"></a>00132   check_nomsg(cpl_frame_set_filename(sky_frame, <span class="stringliteral">"out_fake_sky.fits"</span>)) ;
+<a name="l00133"></a>00133   check_nomsg(cpl_frame_set_tag(sky_frame, PRO_SKY_DUMMY)) ;
+<a name="l00134"></a>00134   check_nomsg(cpl_frame_set_type(sky_frame, CPL_FRAME_TYPE_IMAGE));
+<a name="l00135"></a>00135   <span class="comment">/*</span>
+<a name="l00136"></a>00136 <span class="comment">  check_nomsg(cpl_frame_set_group(sky_frame, CPL_FRAME_GROUP_PRODUCT));</span>
+<a name="l00137"></a>00137 <span class="comment">  */</span>
+<a name="l00138"></a>00138   check_nomsg(cpl_frame_set_level(sky_frame, CPL_FRAME_LEVEL_FINAL));
+<a name="l00139"></a>00139   sinfo_free_image(&fake_sky);
+<a name="l00140"></a>00140   sinfo_free_imagelist(&obj_list);
+<a name="l00141"></a>00141 
+<a name="l00142"></a>00142   <span class="keywordflow">return</span> sky_frame;
+<a name="l00143"></a>00143 
+<a name="l00144"></a>00144  cleanup:
+<a name="l00145"></a>00145 
+<a name="l00146"></a>00146   sinfo_free_propertylist(&plist) ;
+<a name="l00147"></a>00147 
+<a name="l00148"></a>00148   <span class="keywordflow">return</span> NULL;
+<a name="l00149"></a>00149 
+<a name="l00150"></a>00150 }
+<a name="l00151"></a>00151 
+<a name="l00152"></a>00152 
+<a name="l00153"></a>00153 
+<a name="l00154"></a>00154 <span class="keywordtype">int</span>
+<a name="l00155"></a>00155 sinfo_new_get_dummy_obj_sky_stacked(cpl_frameset* obj_set,cpl_frameset** <span class="keyword">set</span>,
+<a name="l00156"></a>00156 cpl_parameterlist* config,fake* fk, <span class="keywordtype">char</span>* pro_ctg, <span class="keyword">const</span> <span class="keywordtype">char</span>* plugin_id)
+<a name="l00157"></a>00157 {
+<a name="l00158"></a>00158   <span class="keywordtype">int</span> nobj=0;
+<a name="l00159"></a>00159   <span class="keywordtype">int</span> ncdb=0;
+<a name="l00160"></a>00160   <span class="keywordtype">int</span> ntot=0;
+<a name="l00161"></a>00161   <span class="keywordtype">int</span> nstk=0;
+<a name="l00162"></a>00162   <span class="keywordtype">int</span> nwrk=0;
+<a name="l00163"></a>00163   <span class="keywordtype">int</span> i=0;
+<a name="l00164"></a>00164   <span class="keywordtype">int</span> k=0;
+<a name="l00165"></a>00165 
+<a name="l00166"></a>00166   <span class="keywordtype">double</span> mjd_obj=0;
+<a name="l00167"></a>00167   <span class="keywordtype">double</span> mjd_sky_inf=0;
+<a name="l00168"></a>00168   <span class="keywordtype">double</span> mjd_sky_sup=0;
+<a name="l00169"></a>00169   <span class="keywordtype">char</span> sky_name[FILE_NAME_SZ];
+<a name="l00170"></a>00170   <span class="keywordtype">char</span> out_name[FILE_NAME_SZ];
+<a name="l00171"></a>00171 
+<a name="l00172"></a>00172   <span class="keywordtype">char</span> fake_sky_name[FILE_NAME_SZ];
+<a name="l00173"></a>00173 
+<a name="l00174"></a>00174   cpl_frame* obj_frm=NULL;
+<a name="l00175"></a>00175   cpl_frame* sky_frm=NULL;
+<a name="l00176"></a>00176   cpl_frame* cdb_frm=NULL;
+<a name="l00177"></a>00177   cpl_frame* wrk_frm=NULL;
+<a name="l00178"></a>00178   cpl_frame* tot_frm=NULL;
+<a name="l00179"></a>00179   cpl_frame* dup_frm=NULL;
+<a name="l00180"></a>00180 
+<a name="l00181"></a>00181   cpl_frame* sky_frm_inf=NULL;
+<a name="l00182"></a>00182   cpl_frame* sky_frm_sup=NULL;
+<a name="l00183"></a>00183 
+<a name="l00184"></a>00184   cpl_propertylist* plist=NULL;
+<a name="l00185"></a>00185   cpl_frameset* wrk_set=NULL;
+<a name="l00186"></a>00186   cpl_frameset* cdb_set=NULL;
+<a name="l00187"></a>00187   cpl_frameset* tot_set=NULL;
+<a name="l00188"></a>00188   cpl_frameset* stk_set=NULL;
+<a name="l00189"></a>00189   cpl_image* sky_ima=NULL;
+<a name="l00190"></a>00190   <span class="keywordtype">double</span> obj_cumx=0;
+<a name="l00191"></a>00191   <span class="keywordtype">double</span> obj_cumy=0;
+<a name="l00192"></a>00192 
+<a name="l00193"></a>00193   <span class="keywordtype">double</span> sky_sup_cumx=0;
+<a name="l00194"></a>00194   <span class="keywordtype">double</span> sky_sup_cumy=0;
+<a name="l00195"></a>00195 
+<a name="l00196"></a>00196   <span class="keywordtype">double</span> sky_inf_cumx=0;
+<a name="l00197"></a>00197   <span class="keywordtype">double</span> sky_inf_cumy=0;
+<a name="l00198"></a>00198   <span class="keywordtype">double</span> cum_thres=0.5;
+<a name="l00199"></a>00199 
+<a name="l00200"></a>00200   check_nomsg(cdb_set=cpl_frameset_new());
+<a name="l00201"></a>00201   ck0(sinfo_extract_mst_frames(*<span class="keyword">set</span>,cdb_set),<span class="stringliteral">"Error extracting CDB frames"</span>);
+<a name="l00202"></a>00202   nobj=cpl_frameset_get_size(obj_set);
+<a name="l00203"></a>00203   ncdb=cpl_frameset_get_size(cdb_set);
+<a name="l00204"></a>00204 
+<a name="l00205"></a>00205 
+<a name="l00206"></a>00206   check_nomsg(tot_set=cpl_frameset_new());
+<a name="l00207"></a>00207 
+<a name="l00208"></a>00208   <span class="keywordflow">for</span>(i=0;i<nobj;i++) {
+<a name="l00209"></a>00209 
+<a name="l00210"></a>00210 
+<a name="l00211"></a>00211 
+<a name="l00212"></a>00212 
+<a name="l00213"></a>00213     check_nomsg(obj_frm=cpl_frameset_get_frame(obj_set,i));
+<a name="l00214"></a>00214     mjd_obj    = sinfo_get_mjd_obs(obj_frm);
+<a name="l00215"></a>00215     obj_cumx=sinfo_get_cumoffsetx(obj_frm);
+<a name="l00216"></a>00216     obj_cumy=sinfo_get_cumoffsety(obj_frm);
+<a name="l00217"></a>00217 
+<a name="l00218"></a>00218     <span class="keywordflow">if</span>(i>0) {
+<a name="l00219"></a>00219        check_nomsg(sky_frm_inf=cpl_frameset_get_frame(obj_set,i-1));
+<a name="l00220"></a>00220        mjd_sky_inf = sinfo_get_mjd_obs(sky_frm_inf);
+<a name="l00221"></a>00221        sky_inf_cumx=sinfo_get_cumoffsetx(sky_frm_inf);
+<a name="l00222"></a>00222        sky_inf_cumy=sinfo_get_cumoffsety(sky_frm_inf);
+<a name="l00223"></a>00223     }
+<a name="l00224"></a>00224 
+<a name="l00225"></a>00225     <span class="keywordflow">if</span>(i<nobj-1) {
+<a name="l00226"></a>00226       check_nomsg(sky_frm_sup=cpl_frameset_get_frame(obj_set,i+1));
+<a name="l00227"></a>00227       mjd_sky_sup = sinfo_get_mjd_obs(sky_frm_sup);
+<a name="l00228"></a>00228       sky_sup_cumx=sinfo_get_cumoffsetx(sky_frm_sup);
+<a name="l00229"></a>00229       sky_sup_cumy=sinfo_get_cumoffsety(sky_frm_sup);
+<a name="l00230"></a>00230     }
+<a name="l00231"></a>00231 
+<a name="l00232"></a>00232 
+<a name="l00233"></a>00233 
+<a name="l00234"></a>00234     <span class="keywordflow">if</span>(i==0) {
+<a name="l00235"></a>00235          sky_frm = sky_frm_sup;
+<a name="l00236"></a>00236     }
+<a name="l00237"></a>00237     <span class="keywordflow">else</span> <span class="keywordflow">if</span>(i==(nobj-1)) {
+<a name="l00238"></a>00238          sky_frm = sky_frm_inf;
+<a name="l00239"></a>00239     } <span class="keywordflow">else</span> {
+<a name="l00240"></a>00240        <span class="keywordflow">if</span>( fabs( mjd_sky_inf - mjd_obj ) <
+<a name="l00241"></a>00241            fabs( mjd_sky_sup - mjd_obj ) ) {
+<a name="l00242"></a>00242          <span class="keywordflow">if</span>((fabs(sky_inf_cumx-obj_cumx) > cum_thres) ||
+<a name="l00243"></a>00243             (fabs(sky_inf_cumy-obj_cumy) > cum_thres)) {
+<a name="l00244"></a>00244        sky_frm = sky_frm_inf;
+<a name="l00245"></a>00245      } <span class="keywordflow">else</span> {
+<a name="l00246"></a>00246        sky_frm = sky_frm_sup;
+<a name="l00247"></a>00247      }
+<a name="l00248"></a>00248        } <span class="keywordflow">else</span> {
+<a name="l00249"></a>00249          <span class="keywordflow">if</span>((fabs(sky_sup_cumx-obj_cumx) > cum_thres) ||
+<a name="l00250"></a>00250             (fabs(sky_sup_cumy-obj_cumy) > cum_thres)) {
+<a name="l00251"></a>00251        sky_frm = sky_frm_sup;
+<a name="l00252"></a>00252      } <span class="keywordflow">else</span> {
+<a name="l00253"></a>00253        sky_frm = sky_frm_inf;
+<a name="l00254"></a>00254      }
+<a name="l00255"></a>00255        }
+<a name="l00256"></a>00256     }
+<a name="l00257"></a>00257 
+<a name="l00258"></a>00258     strcpy(sky_name,cpl_frame_get_filename(sky_frm));
+<a name="l00259"></a>00259 
+<a name="l00260"></a>00260     sinfo_msg(<span class="stringliteral">"obj: %s"</span>,cpl_frame_get_filename(obj_frm));
+<a name="l00261"></a>00261     sinfo_msg(<span class="stringliteral">"sky: %s"</span>,sky_name);
+<a name="l00262"></a>00262 
+<a name="l00263"></a>00263     <span class="keywordflow">if</span> (strstr(sky_name, <span class="stringliteral">"."</span> ) != NULL ) {
+<a name="l00264"></a>00264       <span class="comment">/*snprintf(fake_sky_name,MAX_NAME_SIZE-1,"%s%s","fake_",</span>
+<a name="l00265"></a>00265 <span class="comment">        basename(sky_name)); */</span>
+<a name="l00266"></a>00266       snprintf(fake_sky_name,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%d%s"</span>,<span class="stringliteral">"out_fake_sky"</span>,i,<span class="stringliteral">".fits"</span>);
+<a name="l00267"></a>00267     } <span class="keywordflow">else</span> {
+<a name="l00268"></a>00268        snprintf(fake_sky_name, MAX_NAME_SIZE-1,sky_name) ;
+<a name="l00269"></a>00269     }
+<a name="l00270"></a>00270 
+<a name="l00271"></a>00271     check_nomsg(sky_ima=cpl_image_load(sky_name,CPL_TYPE_FLOAT,0,0));
+<a name="l00272"></a>00272 
+<a name="l00273"></a>00273     cknull(plist = cpl_propertylist_load(sky_name, 0),
+<a name="l00274"></a>00274       <span class="stringliteral">"getting header from reference ima frame %s"</span>,sky_name);
+<a name="l00275"></a>00275 
+<a name="l00276"></a>00276     <span class="keywordflow">if</span> (sinfo_propertylist_has(plist, KEY_NAME_DPR_TYPE)) {
+<a name="l00277"></a>00277       cpl_propertylist_set_string(plist, KEY_NAME_DPR_TYPE, <span class="stringliteral">"SKY"</span>);
+<a name="l00278"></a>00278     } <span class="keywordflow">else</span> {
+<a name="l00279"></a>00279       cpl_propertylist_append_string(plist, KEY_NAME_DPR_TYPE,<span class="stringliteral">"SKY"</span>) ;
+<a name="l00280"></a>00280     }
+<a name="l00281"></a>00281 
+<a name="l00282"></a>00282     check(cpl_image_save(sky_ima, fake_sky_name, CPL_BPP_IEEE_FLOAT,
+<a name="l00283"></a>00283                    plist,CPL_IO_DEFAULT),
+<a name="l00284"></a>00284                 <span class="stringliteral">"Cannot save the product %s"</span>,fake_sky_name);
+<a name="l00285"></a>00285 
+<a name="l00286"></a>00286     sinfo_free_propertylist(&plist);
+<a name="l00287"></a>00287     sinfo_free_image(&sky_ima);
+<a name="l00288"></a>00288 
+<a name="l00289"></a>00289     check_nomsg(cpl_frame_set_filename(sky_frm, fake_sky_name)) ;
+<a name="l00290"></a>00290     <span class="comment">/* The following makes program crash</span>
+<a name="l00291"></a>00291 <span class="comment">       check_nomsg(cpl_frame_set_tag(sky_frm, PRO_SKY_DUMMY)) ;</span>
+<a name="l00292"></a>00292 <span class="comment">    */</span>
+<a name="l00293"></a>00293     check_nomsg(cpl_frame_set_type(sky_frm, CPL_FRAME_TYPE_IMAGE));
+<a name="l00294"></a>00294     <span class="comment">/* check_nomsg(cpl_frame_set_group(sky_frm, CPL_FRAME_GROUP_PRODUCT)); */</span>
+<a name="l00295"></a>00295     check_nomsg(cpl_frame_set_level(sky_frm, CPL_FRAME_LEVEL_FINAL));
+<a name="l00296"></a>00296 
+<a name="l00297"></a>00297 
+<a name="l00298"></a>00298     check_nomsg(wrk_set=cpl_frameset_new());
+<a name="l00299"></a>00299 
+<a name="l00300"></a>00300     check_nomsg(dup_frm=cpl_frame_duplicate(obj_frm));
+<a name="l00301"></a>00301     check_nomsg(cpl_frameset_insert(wrk_set,dup_frm));
+<a name="l00302"></a>00302 
+<a name="l00303"></a>00303     check_nomsg(dup_frm=cpl_frame_duplicate(sky_frm));
+<a name="l00304"></a>00304     check_nomsg(cpl_frameset_insert(wrk_set,dup_frm));
+<a name="l00305"></a>00305 
+<a name="l00306"></a>00306 
+<a name="l00307"></a>00307     <span class="keywordflow">for</span>(k=0;k<ncdb;k++) {
+<a name="l00308"></a>00308       check_nomsg(cdb_frm=cpl_frameset_get_frame(cdb_set,k));
+<a name="l00309"></a>00309       check_nomsg(dup_frm=cpl_frame_duplicate(cdb_frm));
+<a name="l00310"></a>00310       check_nomsg(cpl_frameset_insert(wrk_set,dup_frm));
+<a name="l00311"></a>00311     }
+<a name="l00312"></a>00312     snprintf(out_name,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%d%s"</span>,<span class="stringliteral">"out_stack"</span>,i,<span class="stringliteral">".fits"</span>);
+<a name="l00313"></a>00313     nwrk=cpl_frameset_get_size(wrk_set);
+<a name="l00314"></a>00314 
+<a name="l00315"></a>00315 
+<a name="l00316"></a>00316     ck0(sinfo_new_stack_frames(config,wrk_set,pro_ctg,i,fk,plugin_id),
+<a name="l00317"></a>00317         <span class="stringliteral">"Error stacking frames"</span>);
+<a name="l00318"></a>00318 
+<a name="l00319"></a>00319     check_nomsg(cpl_frame_set_filename(sky_frm, sky_name)) ;
+<a name="l00320"></a>00320     <span class="comment">/* This commented as was screwing up the catalogue.</span>
+<a name="l00321"></a>00321 <span class="comment">    check_nomsg(cpl_frame_set_tag(sky_frm, RAW_OBJECT_NODDING)) ;</span>
+<a name="l00322"></a>00322 <span class="comment">    */</span>
+<a name="l00323"></a>00323     check_nomsg(stk_set=cpl_frameset_new());
+<a name="l00324"></a>00324     sinfo_contains_frames_kind(wrk_set,stk_set,PRO_STACKED);
+<a name="l00325"></a>00325     nstk=cpl_frameset_get_size(stk_set);
+<a name="l00326"></a>00326     <span class="keywordflow">for</span>(k=0;k<nstk;k++) {
+<a name="l00327"></a>00327       check_nomsg(wrk_frm=cpl_frameset_get_frame(stk_set,k));
+<a name="l00328"></a>00328       check_nomsg(dup_frm=cpl_frame_duplicate(wrk_frm));
+<a name="l00329"></a>00329       check_nomsg(cpl_frameset_insert(tot_set,dup_frm));
+<a name="l00330"></a>00330     }
+<a name="l00331"></a>00331     sinfo_free_frameset(&stk_set);
+<a name="l00332"></a>00332     sinfo_free_frameset(&wrk_set);
+<a name="l00333"></a>00333 
+<a name="l00334"></a>00334   }
+<a name="l00335"></a>00335   ntot=cpl_frameset_get_size(tot_set);
+<a name="l00336"></a>00336   <span class="keywordflow">for</span>(k=0;k<ntot;k++) {
+<a name="l00337"></a>00337     check_nomsg(tot_frm=cpl_frameset_get_frame(tot_set,k));
+<a name="l00338"></a>00338     check_nomsg(dup_frm=cpl_frame_duplicate(tot_frm));
+<a name="l00339"></a>00339     check_nomsg(cpl_frameset_insert(*<span class="keyword">set</span>,dup_frm));
+<a name="l00340"></a>00340   }
+<a name="l00341"></a>00341 
+<a name="l00342"></a>00342   sinfo_free_frameset(&cdb_set);
+<a name="l00343"></a>00343   sinfo_free_frameset(&tot_set);
+<a name="l00344"></a>00344 
+<a name="l00345"></a>00345   <span class="keywordflow">return</span> 0;
+<a name="l00346"></a>00346 
+<a name="l00347"></a>00347  cleanup:
+<a name="l00348"></a>00348   sinfo_free_propertylist(&plist) ;
+<a name="l00349"></a>00349   sinfo_free_frameset(&cdb_set);
+<a name="l00350"></a>00350   sinfo_free_frameset(&tot_set);
+<a name="l00351"></a>00351   <span class="keywordflow">return</span> -1;
+<a name="l00352"></a>00352 
+<a name="l00353"></a>00353 }
+<a name="l00354"></a>00354 
+<a name="l00355"></a>00355 <span class="keywordtype">int</span>
+<a name="l00356"></a>00356 sinfo_get_dummy_obj_sky_stacked_and_cubes(cpl_frameset* obj_set,
+<a name="l00357"></a>00357                                           cpl_frameset** <span class="keyword">set</span>,
+<a name="l00358"></a>00358                                           cpl_parameterlist* config,
+<a name="l00359"></a>00359                                           fake* fk,
+<a name="l00360"></a>00360                                           <span class="keywordtype">char</span>* pro_ctg,
+<a name="l00361"></a>00361                                           <span class="keyword">const</span> <span class="keywordtype">char</span>* plugin_id)
+<a name="l00362"></a>00362 {
+<a name="l00363"></a>00363   <span class="keywordtype">int</span> nobj=0;
+<a name="l00364"></a>00364   <span class="keywordtype">int</span> ncdb=0;
+<a name="l00365"></a>00365   <span class="keywordtype">int</span> nwrk=0;
+<a name="l00366"></a>00366   <span class="keywordtype">int</span> i=0;
+<a name="l00367"></a>00367   <span class="keywordtype">int</span> k=0;
+<a name="l00368"></a>00368   <span class="keywordtype">int</span> ind=0;
+<a name="l00369"></a>00369 
+<a name="l00370"></a>00370   <span class="keywordtype">double</span> mjd_obj=0;
+<a name="l00371"></a>00371   <span class="keywordtype">double</span> mjd_sky_inf=0;
+<a name="l00372"></a>00372   <span class="keywordtype">double</span> mjd_sky_sup=0;
+<a name="l00373"></a>00373   <span class="keywordtype">char</span> sky_name[FILE_NAME_SZ];
+<a name="l00374"></a>00374   <span class="keywordtype">char</span> out_name[FILE_NAME_SZ];
+<a name="l00375"></a>00375 
+<a name="l00376"></a>00376   <span class="keywordtype">char</span> fake_sky_name[FILE_NAME_SZ];
+<a name="l00377"></a>00377 
+<a name="l00378"></a>00378   cpl_frame* obj_frm=NULL;
+<a name="l00379"></a>00379   cpl_frame* sky_frm=NULL;
+<a name="l00380"></a>00380   cpl_frame* cdb_frm=NULL;
+<a name="l00381"></a>00381   cpl_frame* dup_frm=NULL;
+<a name="l00382"></a>00382 
+<a name="l00383"></a>00383   cpl_frame* sky_frm_inf=NULL;
+<a name="l00384"></a>00384   cpl_frame* sky_frm_sup=NULL;
+<a name="l00385"></a>00385 
+<a name="l00386"></a>00386   cpl_propertylist* plist=NULL;
+<a name="l00387"></a>00387   cpl_frameset* wrk_set=NULL;
+<a name="l00388"></a>00388   cpl_frameset* cdb_set=NULL;
+<a name="l00389"></a>00389   cpl_frameset* tot_set=NULL;
+<a name="l00390"></a>00390   cpl_frameset* pro_set=NULL;
+<a name="l00391"></a>00391   cpl_image* sky_ima=NULL;
+<a name="l00392"></a>00392   <span class="keywordtype">double</span> obj_cumx=0;
+<a name="l00393"></a>00393   <span class="keywordtype">double</span> obj_cumy=0;
+<a name="l00394"></a>00394 
+<a name="l00395"></a>00395   <span class="keywordtype">double</span> sky_sup_cumx=0;
+<a name="l00396"></a>00396   <span class="keywordtype">double</span> sky_sup_cumy=0;
+<a name="l00397"></a>00397 
+<a name="l00398"></a>00398   <span class="keywordtype">double</span> sky_inf_cumx=0;
+<a name="l00399"></a>00399   <span class="keywordtype">double</span> sky_inf_cumy=0;
+<a name="l00400"></a>00400   <span class="keywordtype">double</span> cum_thres=0.5;
+<a name="l00401"></a>00401 
+<a name="l00402"></a>00402   check_nomsg(cdb_set=cpl_frameset_new());
+<a name="l00403"></a>00403   ck0(sinfo_extract_mst_frames(*<span class="keyword">set</span>,cdb_set),<span class="stringliteral">"Error extracting CDB frames"</span>);
+<a name="l00404"></a>00404   nobj=cpl_frameset_get_size(obj_set);
+<a name="l00405"></a>00405   ncdb=cpl_frameset_get_size(cdb_set);
+<a name="l00406"></a>00406 
+<a name="l00407"></a>00407 
+<a name="l00408"></a>00408   check_nomsg(tot_set=cpl_frameset_new());
+<a name="l00409"></a>00409 
+<a name="l00410"></a>00410   <span class="keywordflow">for</span>(i=0;i<nobj;i++) {
+<a name="l00411"></a>00411 
+<a name="l00412"></a>00412     check_nomsg(obj_frm=cpl_frameset_get_frame(obj_set,i));
+<a name="l00413"></a>00413     mjd_obj    = sinfo_get_mjd_obs(obj_frm);
+<a name="l00414"></a>00414     obj_cumx=sinfo_get_cumoffsetx(obj_frm);
+<a name="l00415"></a>00415     obj_cumy=sinfo_get_cumoffsety(obj_frm);
+<a name="l00416"></a>00416 
+<a name="l00417"></a>00417     <span class="keywordflow">if</span>(i>0) {
+<a name="l00418"></a>00418        check_nomsg(sky_frm_inf=cpl_frameset_get_frame(obj_set,i-1));
+<a name="l00419"></a>00419        mjd_sky_inf = sinfo_get_mjd_obs(sky_frm_inf);
+<a name="l00420"></a>00420        sky_inf_cumx=sinfo_get_cumoffsetx(sky_frm_inf);
+<a name="l00421"></a>00421        sky_inf_cumy=sinfo_get_cumoffsety(sky_frm_inf);
+<a name="l00422"></a>00422     }
+<a name="l00423"></a>00423 
+<a name="l00424"></a>00424     <span class="keywordflow">if</span>(i<nobj-1) {
+<a name="l00425"></a>00425       check_nomsg(sky_frm_sup=cpl_frameset_get_frame(obj_set,i+1));
+<a name="l00426"></a>00426       mjd_sky_sup = sinfo_get_mjd_obs(sky_frm_sup);
+<a name="l00427"></a>00427       sky_sup_cumx=sinfo_get_cumoffsetx(sky_frm_sup);
+<a name="l00428"></a>00428       sky_sup_cumy=sinfo_get_cumoffsety(sky_frm_sup);
+<a name="l00429"></a>00429     }
+<a name="l00430"></a>00430 
+<a name="l00431"></a>00431 
+<a name="l00432"></a>00432 
+<a name="l00433"></a>00433     <span class="keywordflow">if</span>(i==0) {
+<a name="l00434"></a>00434          sky_frm = sky_frm_sup;
+<a name="l00435"></a>00435     }
+<a name="l00436"></a>00436     <span class="keywordflow">else</span> <span class="keywordflow">if</span>(i==(nobj-1)) {
+<a name="l00437"></a>00437          sky_frm = sky_frm_inf;
+<a name="l00438"></a>00438     } <span class="keywordflow">else</span> {
+<a name="l00439"></a>00439        <span class="keywordflow">if</span>( fabs( mjd_sky_inf - mjd_obj ) <
+<a name="l00440"></a>00440            fabs( mjd_sky_sup - mjd_obj ) ) {
+<a name="l00441"></a>00441          <span class="keywordflow">if</span>((fabs(sky_inf_cumx-obj_cumx) > cum_thres) ||
+<a name="l00442"></a>00442             (fabs(sky_inf_cumy-obj_cumy) > cum_thres)) {
+<a name="l00443"></a>00443        sky_frm = sky_frm_inf;
+<a name="l00444"></a>00444      } <span class="keywordflow">else</span> {
+<a name="l00445"></a>00445        sky_frm = sky_frm_sup;
+<a name="l00446"></a>00446      }
+<a name="l00447"></a>00447        } <span class="keywordflow">else</span> {
+<a name="l00448"></a>00448          <span class="keywordflow">if</span>((fabs(sky_sup_cumx-obj_cumx) > cum_thres) ||
+<a name="l00449"></a>00449             (fabs(sky_sup_cumy-obj_cumy) > cum_thres)) {
+<a name="l00450"></a>00450        sky_frm = sky_frm_sup;
+<a name="l00451"></a>00451      } <span class="keywordflow">else</span> {
+<a name="l00452"></a>00452        sky_frm = sky_frm_inf;
+<a name="l00453"></a>00453      }
+<a name="l00454"></a>00454        }
+<a name="l00455"></a>00455     }
+<a name="l00456"></a>00456 
+<a name="l00457"></a>00457 
+<a name="l00458"></a>00458     strcpy(sky_name,cpl_frame_get_filename(sky_frm));
+<a name="l00459"></a>00459     sinfo_msg(<span class="stringliteral">"obj: %s"</span>,cpl_frame_get_filename(obj_frm));
+<a name="l00460"></a>00460     sinfo_msg(<span class="stringliteral">"sky: %s"</span>,sky_name);
+<a name="l00461"></a>00461     <span class="keywordflow">if</span> (strstr(sky_name, <span class="stringliteral">"."</span> ) != NULL ) {
+<a name="l00462"></a>00462       <span class="comment">/*snprintf(fake_sky_name,MAX_NAME_SIZE-1,"%s%s",</span>
+<a name="l00463"></a>00463 <span class="comment">                 "fake_",basename(sky_name)); */</span>
+<a name="l00464"></a>00464       snprintf(fake_sky_name,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%d%s"</span>,<span class="stringliteral">"out_fake_sky"</span>,i,<span class="stringliteral">".fits"</span>);
+<a name="l00465"></a>00465     } <span class="keywordflow">else</span> {
+<a name="l00466"></a>00466        snprintf(fake_sky_name, MAX_NAME_SIZE-1,sky_name) ;
+<a name="l00467"></a>00467     }
+<a name="l00468"></a>00468 
+<a name="l00469"></a>00469     check_nomsg(sky_ima=cpl_image_load(sky_name,CPL_TYPE_FLOAT,0,0));
+<a name="l00470"></a>00470 
+<a name="l00471"></a>00471     cknull(plist = cpl_propertylist_load(sky_name, 0),
+<a name="l00472"></a>00472       <span class="stringliteral">"getting header from reference ima frame %s"</span>,sky_name);
+<a name="l00473"></a>00473 
+<a name="l00474"></a>00474     <span class="keywordflow">if</span> (sinfo_propertylist_has(plist, KEY_NAME_DPR_TYPE)) {
+<a name="l00475"></a>00475       cpl_propertylist_set_string(plist, KEY_NAME_DPR_TYPE, <span class="stringliteral">"SKY"</span>);
+<a name="l00476"></a>00476     } <span class="keywordflow">else</span> {
+<a name="l00477"></a>00477       cpl_propertylist_append_string(plist, KEY_NAME_DPR_TYPE,<span class="stringliteral">"SKY"</span>) ;
+<a name="l00478"></a>00478     }
+<a name="l00479"></a>00479     check(cpl_image_save(sky_ima, fake_sky_name, CPL_BPP_IEEE_FLOAT,
+<a name="l00480"></a>00480                    plist,CPL_IO_DEFAULT),
+<a name="l00481"></a>00481                 <span class="stringliteral">"Cannot save the product %s"</span>,fake_sky_name);
+<a name="l00482"></a>00482 
+<a name="l00483"></a>00483     sinfo_free_propertylist(&plist);
+<a name="l00484"></a>00484     sinfo_free_image(&sky_ima);
+<a name="l00485"></a>00485 
+<a name="l00486"></a>00486     check_nomsg(cpl_frame_set_filename(sky_frm, fake_sky_name)) ;
+<a name="l00487"></a>00487     <span class="comment">/* The following makes program crash</span>
+<a name="l00488"></a>00488 <span class="comment">       check_nomsg(cpl_frame_set_tag(sky_frm, PRO_SKY_DUMMY)) ;</span>
+<a name="l00489"></a>00489 <span class="comment">    */</span>
+<a name="l00490"></a>00490     check_nomsg(cpl_frame_set_type(sky_frm, CPL_FRAME_TYPE_IMAGE));
+<a name="l00491"></a>00491     <span class="comment">/* check_nomsg(cpl_frame_set_group(sky_frm, CPL_FRAME_GROUP_PRODUCT)); */</span>
+<a name="l00492"></a>00492     check_nomsg(cpl_frame_set_level(sky_frm, CPL_FRAME_LEVEL_FINAL));
+<a name="l00493"></a>00493 
+<a name="l00494"></a>00494 
+<a name="l00495"></a>00495     check_nomsg(wrk_set=cpl_frameset_new());
+<a name="l00496"></a>00496 
+<a name="l00497"></a>00497     check_nomsg(dup_frm=cpl_frame_duplicate(obj_frm));
+<a name="l00498"></a>00498     check_nomsg(cpl_frameset_insert(wrk_set,dup_frm));
+<a name="l00499"></a>00499 
+<a name="l00500"></a>00500     check_nomsg(dup_frm=cpl_frame_duplicate(sky_frm));
+<a name="l00501"></a>00501     check_nomsg(cpl_frameset_insert(wrk_set,dup_frm));
+<a name="l00502"></a>00502 
+<a name="l00503"></a>00503     <span class="keywordflow">for</span>(k=0;k<ncdb;k++) {
+<a name="l00504"></a>00504       check_nomsg(cdb_frm=cpl_frameset_get_frame(cdb_set,k));
+<a name="l00505"></a>00505       check_nomsg(dup_frm=cpl_frame_duplicate(cdb_frm));
+<a name="l00506"></a>00506       check_nomsg(cpl_frameset_insert(wrk_set,dup_frm));
+<a name="l00507"></a>00507     }
+<a name="l00508"></a>00508     snprintf(out_name,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%d%s"</span>,<span class="stringliteral">"out_stack"</span>,i,<span class="stringliteral">".fits"</span>);
+<a name="l00509"></a>00509     nwrk=cpl_frameset_get_size(wrk_set);
+<a name="l00510"></a>00510 
+<a name="l00511"></a>00511 
+<a name="l00512"></a>00512     ck0(sinfo_new_stack_frames(config,wrk_set,pro_ctg,i,fk,plugin_id),
+<a name="l00513"></a>00513         <span class="stringliteral">"Error stacking frames"</span>);
+<a name="l00514"></a>00514 
+<a name="l00515"></a>00515 
+<a name="l00516"></a>00516     check_nomsg(cpl_frame_set_filename(sky_frm, sky_name)) ;
+<a name="l00517"></a>00517     <span class="comment">/* This commented as was screwing up the catalogue.</span>
+<a name="l00518"></a>00518 <span class="comment">    check_nomsg(cpl_frame_set_tag(sky_frm, RAW_OBJECT_NODDING)) ;</span>
+<a name="l00519"></a>00519 <span class="comment">    */</span>
+<a name="l00520"></a>00520     sinfo_msg(<span class="stringliteral">"--------------------------------------"</span>);
+<a name="l00521"></a>00521     sinfo_msg(<span class="stringliteral">"BUILDING CUBE %d"</span>,i);
+<a name="l00522"></a>00522     sinfo_msg(<span class="stringliteral">"--------------------------------------"</span>);
+<a name="l00523"></a>00523 
+<a name="l00524"></a>00524     <span class="comment">/* cube generation */</span>
+<a name="l00525"></a>00525     ck0(ind=sinfo_new_cubes_build(plugin_id,config,wrk_set,pro_ctg,i),
+<a name="l00526"></a>00526     <span class="stringliteral">"GENERATING CUBE no. %d\n"</span>, ind) ;
+<a name="l00527"></a>00527     sinfo_msg(<span class="stringliteral">"--------------------------------------"</span>);
+<a name="l00528"></a>00528     sinfo_msg(<span class="stringliteral">"BUILT CUBE %d"</span>,i);
+<a name="l00529"></a>00529     sinfo_msg(<span class="stringliteral">"--------------------------------------"</span>);
+<a name="l00530"></a>00530 
+<a name="l00531"></a>00531 
+<a name="l00532"></a>00532     check_nomsg(sinfo_extract_frames_group_type(wrk_set,&pro_set,
+<a name="l00533"></a>00533                                                 CPL_FRAME_GROUP_PRODUCT));
+<a name="l00534"></a>00534     check_nomsg(sinfo_frameset_merge(tot_set,pro_set));
+<a name="l00535"></a>00535     sinfo_free_frameset(&pro_set);
+<a name="l00536"></a>00536     sinfo_free_frameset(&wrk_set);
+<a name="l00537"></a>00537 
+<a name="l00538"></a>00538   } <span class="comment">/* end loop over object frames */</span>
+<a name="l00539"></a>00539 
+<a name="l00540"></a>00540   check_nomsg(sinfo_extract_frames_group_type(tot_set,&pro_set,
+<a name="l00541"></a>00541                                               CPL_FRAME_GROUP_PRODUCT));
+<a name="l00542"></a>00542   check_nomsg(sinfo_frameset_merge(*<span class="keyword">set</span>,pro_set));
+<a name="l00543"></a>00543   sinfo_free_frameset(&pro_set);
+<a name="l00544"></a>00544   sinfo_free_frameset(&tot_set);
+<a name="l00545"></a>00545   sinfo_free_frameset(&cdb_set);
+<a name="l00546"></a>00546 
+<a name="l00547"></a>00547   <span class="keywordflow">return</span> 0;
+<a name="l00548"></a>00548 
+<a name="l00549"></a>00549  cleanup:
+<a name="l00550"></a>00550   sinfo_free_image(&sky_ima);
+<a name="l00551"></a>00551   sinfo_free_propertylist(&plist) ;
+<a name="l00552"></a>00552   sinfo_free_frameset(&wrk_set);
+<a name="l00553"></a>00553   sinfo_free_frameset(&pro_set);
+<a name="l00554"></a>00554   sinfo_free_frameset(&cdb_set);
+<a name="l00555"></a>00555   sinfo_free_frameset(&tot_set);
+<a name="l00556"></a>00556   <span class="keywordflow">return</span> -1;
+<a name="l00557"></a>00557 
+<a name="l00558"></a>00558 }
+<a name="l00559"></a>00559 
+<a name="l00560"></a>00560 
+<a name="l00561"></a>00561 <span class="keywordtype">int</span> sinfo_new_sci_stk_frames(cpl_parameterlist* config,
+<a name="l00562"></a>00562                                  cpl_frameset** <span class="keyword">set</span>,
+<a name="l00563"></a>00563                                  <span class="keyword">const</span> <span class="keywordtype">char</span>* recipe_id,
+<a name="l00564"></a>00564                                  <span class="keyword">const</span> <span class="keywordtype">char</span>** pro_ctg_cube)
+<a name="l00565"></a>00565 {
+<a name="l00566"></a>00566   <span class="keywordtype">char</span> tag[FILE_NAME_SZ];
+<a name="l00567"></a>00567   <span class="keywordtype">char</span> pro_ctg_stack[FILE_NAME_SZ];
+<a name="l00568"></a>00568   <span class="keywordtype">char</span> outname[FILE_NAME_SZ];
+<a name="l00569"></a>00569   <span class="keywordtype">char</span> filename[FILE_NAME_SZ];
+<a name="l00570"></a>00570 
+<a name="l00571"></a>00571 
+<a name="l00572"></a>00572   cpl_frameset * obj_set=NULL;
+<a name="l00573"></a>00573   cpl_frameset * sky_set=NULL;
+<a name="l00574"></a>00574   cpl_frameset * cdb_set=NULL;
+<a name="l00575"></a>00575   cpl_frameset * wrk_set=NULL;
+<a name="l00576"></a>00576   cpl_frameset * stk_set=NULL;
+<a name="l00577"></a>00577   cpl_frameset * tot_set=NULL;
+<a name="l00578"></a>00578   cpl_frame     * obj_frm=NULL;
+<a name="l00579"></a>00579   cpl_frame    * sky_frm=NULL;
+<a name="l00580"></a>00580   cpl_frame    * cdb_frm=NULL;
+<a name="l00581"></a>00581   cpl_frame    * wrk_frm=NULL;
+<a name="l00582"></a>00582   cpl_frame    * dup_frm=NULL;
+<a name="l00583"></a>00583 
+<a name="l00584"></a>00584   <span class="keywordtype">int</span> nsky=0;
+<a name="l00585"></a>00585   <span class="keywordtype">int</span> nobj=0;
+<a name="l00586"></a>00586   <span class="keywordtype">int</span> ncdb=0;
+<a name="l00587"></a>00587   <span class="keywordtype">int</span> ntot=0;
+<a name="l00588"></a>00588   <span class="keywordtype">int</span> nstk=0;
+<a name="l00589"></a>00589 
+<a name="l00590"></a>00590   <span class="keywordtype">int</span> i=0;
+<a name="l00591"></a>00591   <span class="keywordtype">int</span> j=0;
+<a name="l00592"></a>00592   <span class="keywordtype">int</span> k=0;
+<a name="l00593"></a>00593   <span class="keywordtype">int</span> aj_meth=0;
+<a name="l00594"></a>00594 
+<a name="l00595"></a>00595 
+<a name="l00596"></a>00596   <span class="keywordtype">double</span> mjd_obj=0;
+<a name="l00597"></a>00597   <span class="keywordtype">double</span> mjd_sky=0;
+<a name="l00598"></a>00598   <span class="keywordtype">double</span> mjd_sky_frm=0;
+<a name="l00599"></a>00599   cpl_parameter* p=NULL;
+<a name="l00600"></a>00600   fake* fk=sinfo_fake_new();
+<a name="l00601"></a>00601 
+<a name="l00602"></a>00602   check_nomsg(obj_set=cpl_frameset_new());
+<a name="l00603"></a>00603   check_nomsg(sky_set=cpl_frameset_new());
+<a name="l00604"></a>00604   check_nomsg(cdb_set=cpl_frameset_new());
+<a name="l00605"></a>00605 
+<a name="l00606"></a>00606   sinfo_extract_obj_frames(*<span class="keyword">set</span>,obj_set);
+<a name="l00607"></a>00607   sinfo_extract_sky_frames(*<span class="keyword">set</span>,sky_set);
+<a name="l00608"></a>00608   sinfo_extract_mst_frames(*<span class="keyword">set</span>,cdb_set);
+<a name="l00609"></a>00609 
+<a name="l00610"></a>00610 
+<a name="l00611"></a>00611   cknull(obj_frm = cpl_frameset_get_frame(obj_set,0),
+<a name="l00612"></a>00612          <span class="stringliteral">"No object frames in input set."</span>);
+<a name="l00613"></a>00613 
+<a name="l00614"></a>00614   strcpy(tag,cpl_frame_get_tag(obj_frm));
+<a name="l00615"></a>00615   <span class="keywordflow">if</span>(NULL!=sinfo_new_set_obj_procatg(tag)){
+<a name="l00616"></a>00616     *pro_ctg_cube=sinfo_new_set_obj_procatg(tag);
+<a name="l00617"></a>00617   } <span class="keywordflow">else</span> {
+<a name="l00618"></a>00618     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Frame tag %s not supported."</span>,tag);
+<a name="l00619"></a>00619     <span class="keywordflow">goto</span> cleanup;
+<a name="l00620"></a>00620   }
+<a name="l00621"></a>00621 
+<a name="l00622"></a>00622 
+<a name="l00623"></a>00623   <span class="keywordflow">if</span>(NULL!=sinfo_new_set_stk_procatg(tag)){
+<a name="l00624"></a>00624     strcpy(pro_ctg_stack,sinfo_new_set_stk_procatg(tag));
+<a name="l00625"></a>00625   } <span class="keywordflow">else</span> {
+<a name="l00626"></a>00626     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Frame tag %s not supported."</span>,tag);
+<a name="l00627"></a>00627     <span class="keywordflow">goto</span> cleanup;
+<a name="l00628"></a>00628   }
+<a name="l00629"></a>00629 
+<a name="l00630"></a>00630   nobj=cpl_frameset_get_size(obj_set);
+<a name="l00631"></a>00631   nsky=cpl_frameset_get_size(sky_set);
+<a name="l00632"></a>00632   ncdb=cpl_frameset_get_size(cdb_set);
+<a name="l00633"></a>00633 
+<a name="l00634"></a>00634   <span class="keywordflow">if</span> ((nobj==0) && (nsky==0)) {
+<a name="l00635"></a>00635     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Empty input set"</span>);
+<a name="l00636"></a>00636     <span class="keywordflow">goto</span> cleanup;
+<a name="l00637"></a>00637   }
+<a name="l00638"></a>00638 
+<a name="l00639"></a>00639 
+<a name="l00640"></a>00640   <span class="keywordflow">if</span> ( (nobj != 0) && (nsky != 0) ) {
+<a name="l00641"></a>00641     <span class="comment">/* We have either OBJ and SKY: we need to create OBJ-SKY pairs */</span>
+<a name="l00642"></a>00642     sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ;
+<a name="l00643"></a>00643     sinfo_msg(<span class="stringliteral">"Generates OBJ-SKY pairs"</span>);
+<a name="l00644"></a>00644     sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ;
+<a name="l00645"></a>00645     check_nomsg(tot_set=cpl_frameset_new());
+<a name="l00646"></a>00646     check_nomsg(p=cpl_parameterlist_find(config,
+<a name="l00647"></a>00647                                          <span class="stringliteral">"sinfoni.objnod.autojitter_method"</span>));
+<a name="l00648"></a>00648     check_nomsg(cpl_parameter_set_int(p,0));
+<a name="l00649"></a>00649     cpl_msg_warning(cpl_func , <span class="stringliteral">"******** 1 *********"</span>);
+<a name="l00650"></a>00650 
+<a name="l00651"></a>00651 
+<a name="l00652"></a>00652     <span class="keywordflow">for</span> (i=0;i<nobj;i++) {
+<a name="l00653"></a>00653 
+<a name="l00654"></a>00654        check_nomsg(wrk_set=cpl_frameset_new());
+<a name="l00655"></a>00655 
+<a name="l00656"></a>00656        check_nomsg(obj_frm=cpl_frameset_get_frame(obj_set,i));
+<a name="l00657"></a>00657        mjd_obj=sinfo_get_mjd_obs(obj_frm);
+<a name="l00658"></a>00658        check_nomsg(sky_frm=cpl_frameset_get_frame(sky_set,0));
+<a name="l00659"></a>00659        mjd_sky=sinfo_get_mjd_obs(sky_frm);
+<a name="l00660"></a>00660        strcpy(filename,cpl_frame_get_filename(obj_frm));
+<a name="l00661"></a>00661 
+<a name="l00662"></a>00662 
+<a name="l00663"></a>00663        <span class="keywordflow">for</span> (j=1;j<nsky;j++) {
+<a name="l00664"></a>00664           check_nomsg(mjd_sky_frm=sinfo_get_mjd_obs(
+<a name="l00665"></a>00665                                   cpl_frameset_get_frame(sky_set,j)));
+<a name="l00666"></a>00666           <span class="keywordflow">if</span>(1000.*(mjd_sky_frm-mjd_obj)*(mjd_sky_frm-mjd_obj) <
+<a name="l00667"></a>00667              1000.*(mjd_sky-    mjd_obj)*(mjd_sky-    mjd_obj) ) {
+<a name="l00668"></a>00668             mjd_sky=mjd_sky_frm;
+<a name="l00669"></a>00669              check_nomsg(sky_frm=cpl_frameset_get_frame(sky_set,j));
+<a name="l00670"></a>00670        }
+<a name="l00671"></a>00671        }
+<a name="l00672"></a>00672 
+<a name="l00673"></a>00673        strcpy(filename,cpl_frame_get_filename(sky_frm));
+<a name="l00674"></a>00674 
+<a name="l00675"></a>00675 
+<a name="l00676"></a>00676 
+<a name="l00677"></a>00677        <span class="comment">/* monitors whih obj-sky frames are inserted in each wrk_set */</span>
+<a name="l00678"></a>00678        check_nomsg(dup_frm=cpl_frame_duplicate(obj_frm));
+<a name="l00679"></a>00679        check_nomsg(cpl_frameset_insert(wrk_set,dup_frm));
+<a name="l00680"></a>00680        check_nomsg(dup_frm=cpl_frame_duplicate(sky_frm));
+<a name="l00681"></a>00681        check_nomsg(cpl_frameset_insert(wrk_set,dup_frm));
+<a name="l00682"></a>00682 
+<a name="l00683"></a>00683        <span class="comment">/* merged CDB frames to work set */</span>
+<a name="l00684"></a>00684           <span class="keywordflow">for</span>(k=0;k<ncdb;k++) {
+<a name="l00685"></a>00685             check_nomsg(cdb_frm=cpl_frameset_get_frame(cdb_set,k));
+<a name="l00686"></a>00686             check_nomsg(dup_frm=cpl_frame_duplicate(cdb_frm));
+<a name="l00687"></a>00687         check_nomsg(cpl_frameset_insert(wrk_set,dup_frm));
+<a name="l00688"></a>00688       }
+<a name="l00689"></a>00689 
+<a name="l00690"></a>00690 
+<a name="l00691"></a>00691        <span class="comment">/* defines a new name for the output stacked frame */</span>
+<a name="l00692"></a>00692        snprintf(outname,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%d%s"</span>,<span class="stringliteral">"out_stack"</span>,i,<span class="stringliteral">".fits"</span>);
+<a name="l00693"></a>00693        ck0(sinfo_new_stack_frames(config,wrk_set,pro_ctg_stack,i,fk,recipe_id),
+<a name="l00694"></a>00694      <span class="stringliteral">"Cannot stack frames"</span>);
+<a name="l00695"></a>00695 
+<a name="l00696"></a>00696        check_nomsg(stk_set=cpl_frameset_new());
+<a name="l00697"></a>00697        sinfo_contains_frames_kind(wrk_set,stk_set,PRO_STACKED);
+<a name="l00698"></a>00698        nstk=cpl_frameset_get_size(stk_set);
+<a name="l00699"></a>00699 
+<a name="l00700"></a>00700        <span class="keywordflow">for</span>(k=0;k<nstk;k++) {
+<a name="l00701"></a>00701          check_nomsg(wrk_frm=cpl_frameset_get_frame(stk_set,k));
+<a name="l00702"></a>00702          check_nomsg(dup_frm = cpl_frame_duplicate(wrk_frm));
+<a name="l00703"></a>00703      check_nomsg(cpl_frameset_insert(tot_set,dup_frm));
+<a name="l00704"></a>00704        }
+<a name="l00705"></a>00705        sinfo_free_frameset(&stk_set);
+<a name="l00706"></a>00706        sinfo_free_frameset(&wrk_set);
+<a name="l00707"></a>00707 
+<a name="l00708"></a>00708      }
+<a name="l00709"></a>00709 
+<a name="l00710"></a>00710     ntot=cpl_frameset_get_size(tot_set);
+<a name="l00711"></a>00711     <span class="keywordflow">for</span>(k=0;k<ntot;k++) {
+<a name="l00712"></a>00712       check_nomsg(wrk_frm=cpl_frameset_get_frame(tot_set,k));
+<a name="l00713"></a>00713       check_nomsg(dup_frm=cpl_frame_duplicate(wrk_frm));
+<a name="l00714"></a>00714       check_nomsg(cpl_frameset_insert(*<span class="keyword">set</span>,dup_frm));
+<a name="l00715"></a>00715     }
+<a name="l00716"></a>00716     sinfo_free_frameset(&tot_set);
+<a name="l00717"></a>00717 
+<a name="l00718"></a>00718   }
+<a name="l00719"></a>00719 
+<a name="l00720"></a>00720  <span class="keywordflow">if</span> ( (nobj == 0) && (nsky != 0) ) {
+<a name="l00721"></a>00721 
+<a name="l00722"></a>00722      <span class="comment">/* ===============================================================</span>
+<a name="l00723"></a>00723 <span class="comment">        SKY FRAMES STACKING</span>
+<a name="l00724"></a>00724 <span class="comment">        =============================================================== */</span>
+<a name="l00725"></a>00725 
+<a name="l00726"></a>00726     {
+<a name="l00727"></a>00727     sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ;
+<a name="l00728"></a>00728     sinfo_msg(<span class="stringliteral">"SKY ONLY FRAMES DATA REDUCTION NOT SUPPORTED"</span>) ;
+<a name="l00729"></a>00729     sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ;
+<a name="l00730"></a>00730         <span class="keywordflow">goto</span> cleanup;
+<a name="l00731"></a>00731     }
+<a name="l00732"></a>00732 
+<a name="l00733"></a>00733   }
+<a name="l00734"></a>00734 
+<a name="l00735"></a>00735 
+<a name="l00736"></a>00736 
+<a name="l00737"></a>00737   <span class="keywordflow">if</span> ( (nobj != 0) && (nsky == 0) ) {
+<a name="l00738"></a>00738 
+<a name="l00739"></a>00739      <span class="comment">/* ===============================================================</span>
+<a name="l00740"></a>00740 <span class="comment">        OBJ FRAMES STACKING</span>
+<a name="l00741"></a>00741 <span class="comment">        =============================================================== */</span>
+<a name="l00742"></a>00742     check_nomsg(p = cpl_parameterlist_find(config,
+<a name="l00743"></a>00743                                            <span class="stringliteral">"sinfoni.objnod.autojitter_method"</span>));
+<a name="l00744"></a>00744     check_nomsg(aj_meth =  cpl_parameter_get_int(p));
+<a name="l00745"></a>00745     <span class="keywordflow">if</span>(strcmp(pro_ctg_stack,PRO_PUPIL_LAMP_STACKED) == 0) {
+<a name="l00746"></a>00746 
+<a name="l00747"></a>00747       aj_meth = 0;
+<a name="l00748"></a>00748 
+<a name="l00749"></a>00749     }
+<a name="l00750"></a>00750 
+<a name="l00751"></a>00751     <span class="keywordflow">if</span>(aj_meth == 2) {
+<a name="l00752"></a>00752 
+<a name="l00753"></a>00753       sinfo_msg(<span class="stringliteral">"Dummy sky case"</span>);
+<a name="l00754"></a>00754       sinfo_msg(<span class="stringliteral">"Fake sky is coming from median of all objects"</span>);
+<a name="l00755"></a>00755       cknull(sky_frm = sinfo_new_get_dummy_sky(obj_set),
+<a name="l00756"></a>00756          <span class="stringliteral">"Problem to get dummy frame"</span>);
+<a name="l00757"></a>00757 
+<a name="l00758"></a>00758       sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ;
+<a name="l00759"></a>00759       sinfo_msg(<span class="stringliteral">"Generates OBJ-SKY pairs"</span>);
+<a name="l00760"></a>00760       sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ;
+<a name="l00761"></a>00761       check_nomsg(tot_set=cpl_frameset_new());
+<a name="l00762"></a>00762 
+<a name="l00763"></a>00763 
+<a name="l00764"></a>00764 
+<a name="l00765"></a>00765       <span class="keywordflow">for</span> (i=0;i<nobj;i++) {
+<a name="l00766"></a>00766 
+<a name="l00767"></a>00767     check_nomsg(wrk_set=cpl_frameset_new());
+<a name="l00768"></a>00768     check_nomsg(obj_frm=cpl_frameset_get_frame(obj_set,i));
+<a name="l00769"></a>00769         check_nomsg(dup_frm=cpl_frame_duplicate(obj_frm));
+<a name="l00770"></a>00770     check_nomsg(cpl_frameset_insert(wrk_set,dup_frm));
+<a name="l00771"></a>00771         check_nomsg(dup_frm=cpl_frame_duplicate(sky_frm));
+<a name="l00772"></a>00772     check_nomsg(cpl_frameset_insert(wrk_set,dup_frm));
+<a name="l00773"></a>00773     <span class="keywordflow">for</span>(k=0;k<ncdb;k++) {
+<a name="l00774"></a>00774       check_nomsg(cdb_frm=cpl_frameset_get_frame(cdb_set,k));
+<a name="l00775"></a>00775           check_nomsg(dup_frm=cpl_frame_duplicate(cdb_frm));
+<a name="l00776"></a>00776       check_nomsg(cpl_frameset_insert(wrk_set,dup_frm));
+<a name="l00777"></a>00777     }
+<a name="l00778"></a>00778 
+<a name="l00779"></a>00779     snprintf(outname,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%d%s"</span>,<span class="stringliteral">"out_stack"</span>,i,<span class="stringliteral">".fits"</span>);
+<a name="l00780"></a>00780         ck0(sinfo_new_stack_frames(config,wrk_set,pro_ctg_stack,
+<a name="l00781"></a>00781                                    i,fk,recipe_id),
+<a name="l00782"></a>00782                                    <span class="stringliteral">"Error Stacking frame %d"</span>,i);
+<a name="l00783"></a>00783 
+<a name="l00784"></a>00784     check_nomsg(stk_set=cpl_frameset_new());
+<a name="l00785"></a>00785     sinfo_contains_frames_kind(wrk_set,stk_set,PRO_STACKED);
+<a name="l00786"></a>00786     nstk=cpl_frameset_get_size(stk_set);
+<a name="l00787"></a>00787     <span class="keywordflow">for</span>(k=0;k<nstk;k++) {
+<a name="l00788"></a>00788       check_nomsg(wrk_frm=cpl_frameset_get_frame(stk_set,k));
+<a name="l00789"></a>00789           check_nomsg(dup_frm=cpl_frame_duplicate(wrk_frm));
+<a name="l00790"></a>00790       check_nomsg(cpl_frameset_insert(tot_set,dup_frm));
+<a name="l00791"></a>00791     }
+<a name="l00792"></a>00792         sinfo_free_frameset(&stk_set);
+<a name="l00793"></a>00793         sinfo_free_frameset(&wrk_set);
+<a name="l00794"></a>00794 
+<a name="l00795"></a>00795       }
+<a name="l00796"></a>00796       check_nomsg(ntot=cpl_frameset_get_size(tot_set));
+<a name="l00797"></a>00797       <span class="keywordflow">for</span>(k=0;k<ntot;k++) {
+<a name="l00798"></a>00798     check_nomsg(wrk_frm=cpl_frameset_get_frame(tot_set,k));
+<a name="l00799"></a>00799         check_nomsg(dup_frm=cpl_frame_duplicate(wrk_frm));
+<a name="l00800"></a>00800     check_nomsg(cpl_frameset_insert(*<span class="keyword">set</span>,dup_frm));
+<a name="l00801"></a>00801       }
+<a name="l00802"></a>00802       sinfo_free_frameset(&tot_set);
+<a name="l00803"></a>00803       sinfo_free_frame(&sky_frm);
+<a name="l00804"></a>00804 
+<a name="l00805"></a>00805     } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(aj_meth == 1 ) {
+<a name="l00806"></a>00806 
+<a name="l00807"></a>00807       sinfo_msg(<span class="stringliteral">"Dummy obj-sky case"</span>);
+<a name="l00808"></a>00808       sinfo_msg(<span class="stringliteral">"Fake sky is coming from each next object"</span>);
+<a name="l00809"></a>00809 
+<a name="l00810"></a>00810     <span class="keywordflow">if</span>(nobj > 1) {
+<a name="l00811"></a>00811       fk->is_fake_sky=1;
+<a name="l00812"></a>00812       ck0(sinfo_new_get_dummy_obj_sky_stacked(obj_set,&(*<span class="keyword">set</span>),config,
+<a name="l00813"></a>00813                           fk,pro_ctg_stack,recipe_id),
+<a name="l00814"></a>00814       <span class="stringliteral">"Found error to get obj-sky-stacked frame"</span>);
+<a name="l00815"></a>00815     } <span class="keywordflow">else</span> {
+<a name="l00816"></a>00816       sinfo_msg(<span class="stringliteral">"Only one object frame, no sky"</span>);
+<a name="l00817"></a>00817           ck0(sinfo_new_stack_frames(config,*<span class="keyword">set</span>,pro_ctg_stack,0,fk,recipe_id),
+<a name="l00818"></a>00818               <span class="stringliteral">"Error stacking frame"</span>);
+<a name="l00819"></a>00819     }
+<a name="l00820"></a>00820 
+<a name="l00821"></a>00821     } <span class="keywordflow">else</span> {
+<a name="l00822"></a>00822 
+<a name="l00823"></a>00823       sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ;
+<a name="l00824"></a>00824       sinfo_msg(<span class="stringliteral">"staks each OBJECT "</span>);
+<a name="l00825"></a>00825       sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ;
+<a name="l00826"></a>00826       tot_set=cpl_frameset_new();
+<a name="l00827"></a>00827 
+<a name="l00828"></a>00828       <span class="keywordflow">for</span> (i=0;i<nobj;i++) {
+<a name="l00829"></a>00829 
+<a name="l00830"></a>00830     check_nomsg(wrk_set=cpl_frameset_new());
+<a name="l00831"></a>00831     check_nomsg(obj_frm=cpl_frameset_get_frame(obj_set,i));
+<a name="l00832"></a>00832         check_nomsg(dup_frm=cpl_frame_duplicate(obj_frm));
+<a name="l00833"></a>00833     check_nomsg(cpl_frameset_insert(wrk_set,dup_frm));
+<a name="l00834"></a>00834     <span class="keywordflow">for</span>(k=0;k<ncdb;k++) {
+<a name="l00835"></a>00835       check_nomsg(cdb_frm=cpl_frameset_get_frame(cdb_set,k));
+<a name="l00836"></a>00836           check_nomsg(dup_frm=cpl_frame_duplicate(cdb_frm));
+<a name="l00837"></a>00837       check_nomsg(cpl_frameset_insert(wrk_set,dup_frm));
+<a name="l00838"></a>00838     }
+<a name="l00839"></a>00839 
+<a name="l00840"></a>00840 
+<a name="l00841"></a>00841     snprintf(outname,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%d%s"</span>,<span class="stringliteral">"out_stack"</span>,i,<span class="stringliteral">".fits"</span>);
+<a name="l00842"></a>00842         ck0(sinfo_new_stack_frames(config,wrk_set,pro_ctg_stack,
+<a name="l00843"></a>00843                                    i,fk,recipe_id),<span class="stringliteral">"Error stacking frame %d"</span>,i);
+<a name="l00844"></a>00844 
+<a name="l00845"></a>00845     check_nomsg(stk_set=cpl_frameset_new());
+<a name="l00846"></a>00846     sinfo_contains_frames_kind(wrk_set,stk_set,PRO_STACKED);
+<a name="l00847"></a>00847     check_nomsg(nstk=cpl_frameset_get_size(stk_set));
+<a name="l00848"></a>00848     <span class="keywordflow">for</span>(k=0;k<nstk;k++) {
+<a name="l00849"></a>00849       check_nomsg(wrk_frm=cpl_frameset_get_frame(stk_set,k));
+<a name="l00850"></a>00850       check_nomsg(dup_frm=cpl_frame_duplicate(wrk_frm));
+<a name="l00851"></a>00851       check_nomsg(cpl_frameset_insert(tot_set,dup_frm));
+<a name="l00852"></a>00852     }
+<a name="l00853"></a>00853         sinfo_free_frameset(&stk_set);
+<a name="l00854"></a>00854         sinfo_free_frameset(&wrk_set);
+<a name="l00855"></a>00855 
+<a name="l00856"></a>00856       }
+<a name="l00857"></a>00857 
+<a name="l00858"></a>00858       check_nomsg(ntot=cpl_frameset_get_size(tot_set));
+<a name="l00859"></a>00859       <span class="keywordflow">for</span>(k=0;k<ntot;k++) {
+<a name="l00860"></a>00860     check_nomsg(wrk_frm=cpl_frameset_get_frame(tot_set,k));
+<a name="l00861"></a>00861     check_nomsg(dup_frm=cpl_frame_duplicate(wrk_frm));
+<a name="l00862"></a>00862     check_nomsg(cpl_frameset_insert(*<span class="keyword">set</span>,dup_frm));
+<a name="l00863"></a>00863       }
+<a name="l00864"></a>00864       sinfo_free_frameset(&tot_set);
+<a name="l00865"></a>00865     }
+<a name="l00866"></a>00866   }
+<a name="l00867"></a>00867 
+<a name="l00868"></a>00868   sinfo_free_frameset(&obj_set);
+<a name="l00869"></a>00869   sinfo_free_frameset(&sky_set);
+<a name="l00870"></a>00870   sinfo_free_frameset(&cdb_set);
+<a name="l00871"></a>00871   sinfo_fake_delete(&fk);
+<a name="l00872"></a>00872 
+<a name="l00873"></a>00873   <span class="keywordflow">return</span> 0;
+<a name="l00874"></a>00874 
+<a name="l00875"></a>00875 
+<a name="l00876"></a>00876 
+<a name="l00877"></a>00877  cleanup:
+<a name="l00878"></a>00878 
+<a name="l00879"></a>00879     sinfo_free_frame(&sky_frm);
+<a name="l00880"></a>00880     sinfo_free_frameset(&wrk_set);
+<a name="l00881"></a>00881     sinfo_free_frameset(&tot_set);
+<a name="l00882"></a>00882     sinfo_free_frameset(&obj_set);
+<a name="l00883"></a>00883     sinfo_free_frameset(&sky_set);
+<a name="l00884"></a>00884     sinfo_free_frameset(&cdb_set);
+<a name="l00885"></a>00885     sinfo_fake_delete(&fk);
+<a name="l00886"></a>00886     <span class="keywordflow">return</span> -1;
+<a name="l00887"></a>00887 
+<a name="l00888"></a>00888 }
+<a name="l00889"></a>00889 
+<a name="l00890"></a>00890 
+<a name="l00891"></a>00891 
+<a name="l00892"></a>00892 
+<a name="l00893"></a>00893 
+<a name="l00894"></a>00894 
+<a name="l00895"></a>00895 
+<a name="l00896"></a>00896 <span class="keywordtype">int</span> sinfo_cub_stk_frames(cpl_parameterlist* config,
+<a name="l00897"></a>00897                                  cpl_frameset** <span class="keyword">set</span>,
+<a name="l00898"></a>00898                                  <span class="keyword">const</span> <span class="keywordtype">char</span>* recipe_id,
+<a name="l00899"></a>00899                                  <span class="keyword">const</span> <span class="keywordtype">char</span>** pro_ctg_cube)
+<a name="l00900"></a>00900 {
+<a name="l00901"></a>00901   cpl_frame     * obj_frm=NULL;
+<a name="l00902"></a>00902   <span class="keywordtype">char</span> tag[FILE_NAME_SZ];
+<a name="l00903"></a>00903   <span class="keywordtype">char</span> pro_ctg_stack[FILE_NAME_SZ];
+<a name="l00904"></a>00904   <span class="keywordtype">char</span> outname[FILE_NAME_SZ];
+<a name="l00905"></a>00905   <span class="keywordtype">char</span> filename[FILE_NAME_SZ];
+<a name="l00906"></a>00906 
+<a name="l00907"></a>00907 
+<a name="l00908"></a>00908   cpl_frameset * obj_set=NULL;
+<a name="l00909"></a>00909   cpl_frameset * sky_set=NULL;
+<a name="l00910"></a>00910   cpl_frameset * cdb_set=NULL;
+<a name="l00911"></a>00911   cpl_frameset * wrk_set=NULL;
+<a name="l00912"></a>00912   cpl_frameset * tot_set=NULL;
+<a name="l00913"></a>00913   cpl_frameset * pro_set=NULL;
+<a name="l00914"></a>00914   cpl_frame    * sky_frm=NULL;
+<a name="l00915"></a>00915   cpl_frame    * cdb_frm=NULL;
+<a name="l00916"></a>00916   cpl_frame    * dup_frm=NULL;
+<a name="l00917"></a>00917 
+<a name="l00918"></a>00918   <span class="keywordtype">int</span> nsky=0;
+<a name="l00919"></a>00919   <span class="keywordtype">int</span> nobj=0;
+<a name="l00920"></a>00920   <span class="keywordtype">int</span> ncdb=0;
+<a name="l00921"></a>00921 
+<a name="l00922"></a>00922   <span class="keywordtype">int</span> i=0;
+<a name="l00923"></a>00923   <span class="keywordtype">int</span> j=0;
+<a name="l00924"></a>00924   <span class="keywordtype">int</span> k=0;
+<a name="l00925"></a>00925   <span class="keywordtype">int</span> aj_meth=0;
+<a name="l00926"></a>00926   <span class="keywordtype">int</span> ind=0;
+<a name="l00927"></a>00927 
+<a name="l00928"></a>00928   <span class="keywordtype">double</span> mjd_obj=0;
+<a name="l00929"></a>00929   <span class="keywordtype">double</span> mjd_sky=0;
+<a name="l00930"></a>00930   <span class="keywordtype">double</span> mjd_sky_frm=0;
+<a name="l00931"></a>00931   cpl_parameter* p=NULL;
+<a name="l00932"></a>00932   fake* fk=sinfo_fake_new();
+<a name="l00933"></a>00933 
+<a name="l00934"></a>00934   obj_set=cpl_frameset_new();
+<a name="l00935"></a>00935   sky_set=cpl_frameset_new();
+<a name="l00936"></a>00936   cdb_set=cpl_frameset_new();
+<a name="l00937"></a>00937 
+<a name="l00938"></a>00938   sinfo_extract_obj_frames(*<span class="keyword">set</span>,obj_set);
+<a name="l00939"></a>00939   sinfo_extract_sky_frames(*<span class="keyword">set</span>,sky_set);
+<a name="l00940"></a>00940   sinfo_extract_mst_frames(*<span class="keyword">set</span>,cdb_set);
+<a name="l00941"></a>00941 
+<a name="l00942"></a>00942   cknull(obj_frm = cpl_frameset_get_frame(obj_set,0),
+<a name="l00943"></a>00943          <span class="stringliteral">"No object frames in input set."</span>);
+<a name="l00944"></a>00944 
+<a name="l00945"></a>00945 
+<a name="l00946"></a>00946   strcpy(tag,cpl_frame_get_tag(obj_frm));
+<a name="l00947"></a>00947   <span class="keywordflow">if</span>(NULL!=sinfo_new_set_obj_procatg(tag)){
+<a name="l00948"></a>00948     *pro_ctg_cube=sinfo_new_set_obj_procatg(tag);
+<a name="l00949"></a>00949   } <span class="keywordflow">else</span> {
+<a name="l00950"></a>00950     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Frame tag %s not supported."</span>,tag);
+<a name="l00951"></a>00951     <span class="keywordflow">goto</span> cleanup;
+<a name="l00952"></a>00952   }
+<a name="l00953"></a>00953 
+<a name="l00954"></a>00954 
+<a name="l00955"></a>00955   <span class="keywordflow">if</span>(NULL!=sinfo_new_set_stk_procatg(tag)){
+<a name="l00956"></a>00956     strcpy(pro_ctg_stack,sinfo_new_set_stk_procatg(tag));
+<a name="l00957"></a>00957   } <span class="keywordflow">else</span> {
+<a name="l00958"></a>00958     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Frame tag %s not supported."</span>,tag);
+<a name="l00959"></a>00959     <span class="keywordflow">goto</span> cleanup;
+<a name="l00960"></a>00960   }
+<a name="l00961"></a>00961 
+<a name="l00962"></a>00962   nobj=cpl_frameset_get_size(obj_set);
+<a name="l00963"></a>00963   nsky=cpl_frameset_get_size(sky_set);
+<a name="l00964"></a>00964   ncdb=cpl_frameset_get_size(cdb_set);
+<a name="l00965"></a>00965 
+<a name="l00966"></a>00966   <span class="keywordflow">if</span> ((nobj==0) && (nsky==0)) {
+<a name="l00967"></a>00967     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Empty input set"</span>);
+<a name="l00968"></a>00968     <span class="keywordflow">goto</span> cleanup;
+<a name="l00969"></a>00969   }
+<a name="l00970"></a>00970 
+<a name="l00971"></a>00971 
+<a name="l00972"></a>00972   <span class="keywordflow">if</span> ( (nobj != 0) && (nsky != 0) ) {
+<a name="l00973"></a>00973     <span class="comment">/* We have either OBJ and SKY: we need to create OBJ-SKY pairs */</span>
+<a name="l00974"></a>00974     sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ;
+<a name="l00975"></a>00975     sinfo_msg(<span class="stringliteral">"Generates OBJ-SKY pairs"</span>);
+<a name="l00976"></a>00976     sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ;
+<a name="l00977"></a>00977 
+<a name="l00978"></a>00978     check_nomsg(tot_set=cpl_frameset_new());
+<a name="l00979"></a>00979     check_nomsg(p = cpl_parameterlist_find(config,
+<a name="l00980"></a>00980                                            <span class="stringliteral">"sinfoni.objnod.autojitter_method"</span>));
+<a name="l00981"></a>00981     check_nomsg(cpl_parameter_set_int(p,0));
+<a name="l00982"></a>00982 
+<a name="l00983"></a>00983     <span class="keywordflow">for</span> (i=0;i<nobj;i++) {
+<a name="l00984"></a>00984 
+<a name="l00985"></a>00985        cknull_nomsg(wrk_set=cpl_frameset_new());
+<a name="l00986"></a>00986        check_nomsg(obj_frm=cpl_frameset_get_frame(obj_set,i));
+<a name="l00987"></a>00987        mjd_obj=sinfo_get_mjd_obs(obj_frm);
+<a name="l00988"></a>00988        check_nomsg(sky_frm=cpl_frameset_get_frame(sky_set,0));
+<a name="l00989"></a>00989        mjd_sky=sinfo_get_mjd_obs(sky_frm);
+<a name="l00990"></a>00990        strcpy(filename,cpl_frame_get_filename(obj_frm));
+<a name="l00991"></a>00991 
+<a name="l00992"></a>00992 
+<a name="l00993"></a>00993        <span class="keywordflow">for</span> (j=1;j<nsky;j++) {
+<a name="l00994"></a>00994           mjd_sky_frm = sinfo_get_mjd_obs(cpl_frameset_get_frame(sky_set,j));
+<a name="l00995"></a>00995           <span class="keywordflow">if</span>(1000.*(mjd_sky_frm-mjd_obj)*(mjd_sky_frm-mjd_obj) <
+<a name="l00996"></a>00996              1000.*(mjd_sky-    mjd_obj)*(mjd_sky-    mjd_obj) ) {
+<a name="l00997"></a>00997             mjd_sky=mjd_sky_frm;
+<a name="l00998"></a>00998              check_nomsg(sky_frm=cpl_frameset_get_frame(sky_set,j));
+<a name="l00999"></a>00999        }
+<a name="l01000"></a>01000        }
+<a name="l01001"></a>01001        strcpy(filename,cpl_frame_get_filename(sky_frm));
+<a name="l01002"></a>01002 
+<a name="l01003"></a>01003 
+<a name="l01004"></a>01004 
+<a name="l01005"></a>01005        <span class="comment">/* monitors whih obj-sky frames are inserted in each wrk_set */</span>
+<a name="l01006"></a>01006        cknull_nomsg(dup_frm=cpl_frame_duplicate(obj_frm));
+<a name="l01007"></a>01007        check_nomsg(cpl_frameset_insert(wrk_set,dup_frm));
+<a name="l01008"></a>01008        cknull_nomsg(dup_frm=cpl_frame_duplicate(sky_frm));
+<a name="l01009"></a>01009        check_nomsg(cpl_frameset_insert(wrk_set,dup_frm));
+<a name="l01010"></a>01010 
+<a name="l01011"></a>01011        <span class="comment">/* merged CDB frames to work set */</span>
+<a name="l01012"></a>01012           <span class="keywordflow">for</span>(k=0;k<ncdb;k++) {
+<a name="l01013"></a>01013             check_nomsg(cdb_frm=cpl_frameset_get_frame(cdb_set,k));
+<a name="l01014"></a>01014             check_nomsg(dup_frm=cpl_frame_duplicate(cdb_frm));
+<a name="l01015"></a>01015         check_nomsg(cpl_frameset_insert(wrk_set,dup_frm));
+<a name="l01016"></a>01016       }
+<a name="l01017"></a>01017 
+<a name="l01018"></a>01018 
+<a name="l01019"></a>01019        <span class="comment">/* defines a new name for the output stacked frame */</span>
+<a name="l01020"></a>01020        snprintf(outname,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%d%s"</span>,<span class="stringliteral">"out_stack"</span>,i,<span class="stringliteral">".fits"</span>);
+<a name="l01021"></a>01021        ck0(sinfo_new_stack_frames(config,wrk_set,pro_ctg_stack,i,fk,recipe_id),
+<a name="l01022"></a>01022        <span class="stringliteral">"Cannot stack frames"</span>);
+<a name="l01023"></a>01023 
+<a name="l01024"></a>01024        <span class="comment">/* cube generation */</span>
+<a name="l01025"></a>01025        ck0(ind=sinfo_new_cubes_build(recipe_id,config,wrk_set,
+<a name="l01026"></a>01026                      *pro_ctg_cube,i),
+<a name="l01027"></a>01027        <span class="stringliteral">"GENERATING CUBE no. %d\n"</span>, ind) ;
+<a name="l01028"></a>01028 
+<a name="l01029"></a>01029        check_nomsg(sinfo_extract_frames_group_type(wrk_set,
+<a name="l01030"></a>01030                                                    &pro_set,
+<a name="l01031"></a>01031                                                    CPL_FRAME_GROUP_PRODUCT));
+<a name="l01032"></a>01032        check_nomsg(sinfo_frameset_merge(tot_set,pro_set));
+<a name="l01033"></a>01033        sinfo_free_frameset(&pro_set);
+<a name="l01034"></a>01034        sinfo_free_frameset(&wrk_set);
+<a name="l01035"></a>01035 
+<a name="l01036"></a>01036 
+<a name="l01037"></a>01037     }
+<a name="l01038"></a>01038 
+<a name="l01039"></a>01039     check_nomsg(sinfo_extract_frames_group_type(tot_set,
+<a name="l01040"></a>01040                                                 &pro_set,
+<a name="l01041"></a>01041                                                 CPL_FRAME_GROUP_PRODUCT));
+<a name="l01042"></a>01042     check_nomsg(sinfo_frameset_merge(*<span class="keyword">set</span>,pro_set));
+<a name="l01043"></a>01043     sinfo_free_frameset(&pro_set);
+<a name="l01044"></a>01044     sinfo_free_frameset(&tot_set);
+<a name="l01045"></a>01045 
+<a name="l01046"></a>01046   }
+<a name="l01047"></a>01047 
+<a name="l01048"></a>01048 
+<a name="l01049"></a>01049  <span class="keywordflow">if</span> ( (nobj == 0) && (nsky != 0) ) {
+<a name="l01050"></a>01050 
+<a name="l01051"></a>01051      <span class="comment">/* ===============================================================</span>
+<a name="l01052"></a>01052 <span class="comment">        SKY FRAMES STACKING</span>
+<a name="l01053"></a>01053 <span class="comment">        =============================================================== */</span>
+<a name="l01054"></a>01054 
+<a name="l01055"></a>01055     {
+<a name="l01056"></a>01056     sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ;
+<a name="l01057"></a>01057     sinfo_msg(<span class="stringliteral">"SKY ONLY FRAMES DATA REDUCTION NOT SUPPORTED"</span>) ;
+<a name="l01058"></a>01058     sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ;
+<a name="l01059"></a>01059         <span class="keywordflow">goto</span> cleanup;
+<a name="l01060"></a>01060     }
+<a name="l01061"></a>01061 
+<a name="l01062"></a>01062 
+<a name="l01063"></a>01063   }
+<a name="l01064"></a>01064 
+<a name="l01065"></a>01065 
+<a name="l01066"></a>01066 
+<a name="l01067"></a>01067   <span class="keywordflow">if</span> ( (nobj != 0) && (nsky == 0) ) {
+<a name="l01068"></a>01068 
+<a name="l01069"></a>01069      <span class="comment">/* ===============================================================</span>
+<a name="l01070"></a>01070 <span class="comment">        OBJ FRAMES STACKING</span>
+<a name="l01071"></a>01071 <span class="comment">        =============================================================== */</span>
+<a name="l01072"></a>01072       check_nomsg(p=cpl_parameterlist_find(config,
+<a name="l01073"></a>01073                                            <span class="stringliteral">"sinfoni.objnod.autojitter_method"</span>));
+<a name="l01074"></a>01074       check_nomsg(aj_meth =  cpl_parameter_get_int(p));
+<a name="l01075"></a>01075       <span class="keywordflow">if</span>(strcmp(pro_ctg_stack,PRO_PUPIL_LAMP_STACKED) == 0) {
+<a name="l01076"></a>01076 
+<a name="l01077"></a>01077     aj_meth = 0;
+<a name="l01078"></a>01078 
+<a name="l01079"></a>01079       }
+<a name="l01080"></a>01080 
+<a name="l01081"></a>01081     <span class="keywordflow">if</span>(aj_meth == 2) {
+<a name="l01082"></a>01082 
+<a name="l01083"></a>01083       sinfo_msg(<span class="stringliteral">"Dummy sky case"</span>);
+<a name="l01084"></a>01084       sinfo_msg(<span class="stringliteral">"Fake sky is coming from median of all objects"</span>);
+<a name="l01085"></a>01085       <span class="keywordflow">if</span>( (sky_frm = sinfo_new_get_dummy_sky(obj_set)) == NULL) {
+<a name="l01086"></a>01086 
+<a name="l01087"></a>01087      <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Problem to get dummy frame"</span>);
+<a name="l01088"></a>01088 
+<a name="l01089"></a>01089     <span class="keywordflow">return</span> -1;
+<a name="l01090"></a>01090 
+<a name="l01091"></a>01091       }
+<a name="l01092"></a>01092       sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ;
+<a name="l01093"></a>01093       sinfo_msg(<span class="stringliteral">"Generates OBJ-SKY pairs"</span>);
+<a name="l01094"></a>01094       sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ;
+<a name="l01095"></a>01095 
+<a name="l01096"></a>01096       check_nomsg(tot_set=cpl_frameset_new());
+<a name="l01097"></a>01097 
+<a name="l01098"></a>01098 
+<a name="l01099"></a>01099       <span class="keywordflow">for</span> (i=0;i<nobj;i++) {
+<a name="l01100"></a>01100 
+<a name="l01101"></a>01101     check_nomsg(wrk_set=cpl_frameset_new());
+<a name="l01102"></a>01102     check_nomsg(obj_frm=cpl_frameset_get_frame(obj_set,i));
+<a name="l01103"></a>01103         check_nomsg(dup_frm=cpl_frame_duplicate(obj_frm));
+<a name="l01104"></a>01104     check_nomsg(cpl_frameset_insert(wrk_set,dup_frm));
+<a name="l01105"></a>01105         check_nomsg(dup_frm=cpl_frame_duplicate(sky_frm));
+<a name="l01106"></a>01106     check_nomsg(cpl_frameset_insert(wrk_set,dup_frm));
+<a name="l01107"></a>01107     <span class="keywordflow">for</span>(k=0;k<ncdb;k++) {
+<a name="l01108"></a>01108       check_nomsg(cdb_frm=cpl_frameset_get_frame(cdb_set,k));
+<a name="l01109"></a>01109           check_nomsg(dup_frm=cpl_frame_duplicate(cdb_frm));
+<a name="l01110"></a>01110       check_nomsg(cpl_frameset_insert(wrk_set,dup_frm));
+<a name="l01111"></a>01111     }
+<a name="l01112"></a>01112 
+<a name="l01113"></a>01113     snprintf(outname,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%d%s"</span>,<span class="stringliteral">"out_stack"</span>,i,<span class="stringliteral">".fits"</span>);
+<a name="l01114"></a>01114         ck0(sinfo_new_stack_frames(config,wrk_set,pro_ctg_stack,
+<a name="l01115"></a>01115                                    i,fk,recipe_id),<span class="stringliteral">"Error Stacking frame %d"</span>,i);
+<a name="l01116"></a>01116 
+<a name="l01117"></a>01117 
+<a name="l01118"></a>01118         <span class="comment">/* cube generation */</span>
+<a name="l01119"></a>01119         ck0(ind=sinfo_new_cubes_build(recipe_id,config,wrk_set,
+<a name="l01120"></a>01120                       *pro_ctg_cube,i),
+<a name="l01121"></a>01121         <span class="stringliteral">"Error GENERATING CUBE no. %d\n"</span>, ind) ;
+<a name="l01122"></a>01122 
+<a name="l01123"></a>01123 
+<a name="l01124"></a>01124 
+<a name="l01125"></a>01125 
+<a name="l01126"></a>01126         check_nomsg(sinfo_extract_frames_group_type(wrk_set,
+<a name="l01127"></a>01127                                                     &pro_set,
+<a name="l01128"></a>01128                                                     CPL_FRAME_GROUP_PRODUCT));
+<a name="l01129"></a>01129         check_nomsg(sinfo_frameset_merge(tot_set,pro_set));
+<a name="l01130"></a>01130         sinfo_free_frameset(&pro_set);
+<a name="l01131"></a>01131         sinfo_free_frameset(&wrk_set);
+<a name="l01132"></a>01132 
+<a name="l01133"></a>01133 
+<a name="l01134"></a>01134       }
+<a name="l01135"></a>01135       check_nomsg(sinfo_extract_frames_group_type(tot_set,
+<a name="l01136"></a>01136                                                   &pro_set,
+<a name="l01137"></a>01137                                                   CPL_FRAME_GROUP_PRODUCT));
+<a name="l01138"></a>01138       check_nomsg(sinfo_frameset_merge(*<span class="keyword">set</span>,pro_set));
+<a name="l01139"></a>01139       sinfo_free_frameset(&pro_set);
+<a name="l01140"></a>01140       sinfo_free_frameset(&tot_set);
+<a name="l01141"></a>01141       sinfo_free_frame(&sky_frm);
+<a name="l01142"></a>01142     } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(aj_meth == 1 ) {
+<a name="l01143"></a>01143 
+<a name="l01144"></a>01144 
+<a name="l01145"></a>01145         sinfo_msg(<span class="stringliteral">"Dummy obj-sky case"</span>);
+<a name="l01146"></a>01146         sinfo_msg(<span class="stringliteral">"Fake sky is coming from each next object"</span>);
+<a name="l01147"></a>01147 
+<a name="l01148"></a>01148     <span class="keywordflow">if</span>(nobj > 1) {
+<a name="l01149"></a>01149       fk->is_fake_sky=1;
+<a name="l01150"></a>01150       ck0(sinfo_get_dummy_obj_sky_stacked_and_cubes(obj_set,&(*<span class="keyword">set</span>),config,
+<a name="l01151"></a>01151                           fk,pro_ctg_stack,recipe_id),
+<a name="l01152"></a>01152          <span class="stringliteral">"Found error to get obj-sky-stacked frame"</span>);
+<a name="l01153"></a>01153 
+<a name="l01154"></a>01154     } <span class="keywordflow">else</span> {
+<a name="l01155"></a>01155       sinfo_msg(<span class="stringliteral">"Only one object frame, no sky"</span>);
+<a name="l01156"></a>01156       check_nomsg(p=cpl_parameterlist_find(config,
+<a name="l01157"></a>01157             <span class="stringliteral">"sinfoni.sinfo_utl_skycor.rot_cor"</span>));
+<a name="l01158"></a>01158       check_nomsg(cpl_parameter_set_bool(p,FALSE));
+<a name="l01159"></a>01159 
+<a name="l01160"></a>01160           ck0(sinfo_new_stack_frames(config,*<span class="keyword">set</span>,pro_ctg_stack,0,fk,recipe_id),
+<a name="l01161"></a>01161               <span class="stringliteral">"Error stacking frame"</span>);
+<a name="l01162"></a>01162 
+<a name="l01163"></a>01163       <span class="comment">/* cube generation */</span>
+<a name="l01164"></a>01164       sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ;
+<a name="l01165"></a>01165       sinfo_msg(<span class="stringliteral">"BUILDING CUBE %d"</span>,i);
+<a name="l01166"></a>01166       sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ;
+<a name="l01167"></a>01167       ck0(sinfo_new_cubes_build(recipe_id,config,*<span class="keyword">set</span>,*pro_ctg_cube,i),
+<a name="l01168"></a>01168           <span class="stringliteral">"Error GENERATING CUBE %d"</span>, i) ;
+<a name="l01169"></a>01169 
+<a name="l01170"></a>01170       sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ;
+<a name="l01171"></a>01171       sinfo_msg(<span class="stringliteral">"BUILT CUBE %d"</span>,i);
+<a name="l01172"></a>01172       sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ;
+<a name="l01173"></a>01173 
+<a name="l01174"></a>01174     }
+<a name="l01175"></a>01175 
+<a name="l01176"></a>01176     } <span class="keywordflow">else</span> { <span class="comment">/* aj_meth == 0 */</span>
+<a name="l01177"></a>01177 
+<a name="l01178"></a>01178       sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ;
+<a name="l01179"></a>01179       sinfo_msg(<span class="stringliteral">"staks each OBJECT "</span>);
+<a name="l01180"></a>01180       sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ;
+<a name="l01181"></a>01181       check_nomsg(tot_set=cpl_frameset_new());
+<a name="l01182"></a>01182 
+<a name="l01183"></a>01183       <span class="keywordflow">for</span> (i=0;i<nobj;i++) {
+<a name="l01184"></a>01184 
+<a name="l01185"></a>01185     check_nomsg(wrk_set=cpl_frameset_new());
+<a name="l01186"></a>01186     check_nomsg(obj_frm=cpl_frameset_get_frame(obj_set,i));
+<a name="l01187"></a>01187         check_nomsg(dup_frm=cpl_frame_duplicate(obj_frm));
+<a name="l01188"></a>01188     check_nomsg(cpl_frameset_insert(wrk_set,dup_frm));
+<a name="l01189"></a>01189     <span class="keywordflow">for</span>(k=0;k<ncdb;k++) {
+<a name="l01190"></a>01190       check_nomsg(cdb_frm=cpl_frameset_get_frame(cdb_set,k));
+<a name="l01191"></a>01191           check_nomsg(dup_frm=cpl_frame_duplicate(cdb_frm));
+<a name="l01192"></a>01192       check_nomsg(cpl_frameset_insert(wrk_set,dup_frm));
+<a name="l01193"></a>01193     }
+<a name="l01194"></a>01194 
+<a name="l01195"></a>01195 
+<a name="l01196"></a>01196     snprintf(outname,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%d%s"</span>,<span class="stringliteral">"out_stack"</span>,i,<span class="stringliteral">".fits"</span>);
+<a name="l01197"></a>01197         ck0(sinfo_new_stack_frames(config,wrk_set,pro_ctg_stack,
+<a name="l01198"></a>01198                                    i,fk,recipe_id),<span class="stringliteral">"Error stacking frame %d"</span>,i);
+<a name="l01199"></a>01199 
+<a name="l01200"></a>01200 
+<a name="l01201"></a>01201         <span class="comment">/* cube generation */</span>
+<a name="l01202"></a>01202       sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ;
+<a name="l01203"></a>01203       sinfo_msg(<span class="stringliteral">"BUILDING CUBE %d"</span>,i);
+<a name="l01204"></a>01204       sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ;
+<a name="l01205"></a>01205         ck0(ind=sinfo_new_cubes_build(recipe_id,config,wrk_set,
+<a name="l01206"></a>01206                       *pro_ctg_cube,i),
+<a name="l01207"></a>01207         <span class="stringliteral">"Error GENERATING CUBE no. %d\n"</span>, ind) ;
+<a name="l01208"></a>01208 
+<a name="l01209"></a>01209       sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ;
+<a name="l01210"></a>01210       sinfo_msg(<span class="stringliteral">"BUILT CUBE %d"</span>,i);
+<a name="l01211"></a>01211       sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ;
+<a name="l01212"></a>01212         check_nomsg(sinfo_extract_frames_group_type(wrk_set,
+<a name="l01213"></a>01213                                                     &pro_set,
+<a name="l01214"></a>01214                                                     CPL_FRAME_GROUP_PRODUCT));
+<a name="l01215"></a>01215         check_nomsg(sinfo_frameset_merge(tot_set,pro_set));
+<a name="l01216"></a>01216         sinfo_free_frameset(&pro_set);
+<a name="l01217"></a>01217         sinfo_free_frameset(&wrk_set);
+<a name="l01218"></a>01218 
+<a name="l01219"></a>01219 
+<a name="l01220"></a>01220       }
+<a name="l01221"></a>01221 
+<a name="l01222"></a>01222 
+<a name="l01223"></a>01223      check_nomsg(sinfo_extract_frames_group_type(tot_set,
+<a name="l01224"></a>01224                                                  &pro_set,
+<a name="l01225"></a>01225                                                  CPL_FRAME_GROUP_PRODUCT));
+<a name="l01226"></a>01226      check_nomsg(sinfo_frameset_merge(*<span class="keyword">set</span>,pro_set));
+<a name="l01227"></a>01227      sinfo_free_frameset(&pro_set);
+<a name="l01228"></a>01228      sinfo_free_frameset(&tot_set);
+<a name="l01229"></a>01229 
+<a name="l01230"></a>01230     }
+<a name="l01231"></a>01231   }
+<a name="l01232"></a>01232   sinfo_free_frameset(&obj_set);
+<a name="l01233"></a>01233   sinfo_free_frameset(&sky_set);
+<a name="l01234"></a>01234   sinfo_free_frameset(&cdb_set);
+<a name="l01235"></a>01235   sinfo_fake_delete(&fk);
+<a name="l01236"></a>01236 
+<a name="l01237"></a>01237   <span class="keywordflow">return</span> 0;
+<a name="l01238"></a>01238 
+<a name="l01239"></a>01239  cleanup:
+<a name="l01240"></a>01240 
+<a name="l01241"></a>01241     sinfo_free_frameset(&wrk_set);
+<a name="l01242"></a>01242     sinfo_free_frameset(&tot_set);
+<a name="l01243"></a>01243     sinfo_free_frameset(&obj_set);
+<a name="l01244"></a>01244     sinfo_free_frameset(&sky_set);
+<a name="l01245"></a>01245     sinfo_free_frameset(&cdb_set);
+<a name="l01246"></a>01246     sinfo_fake_delete(&fk);
+<a name="l01247"></a>01247     <span class="keywordflow">return</span> -1;
+<a name="l01248"></a>01248 
+<a name="l01249"></a>01249 
+<a name="l01250"></a>01250 }
+<a name="l01251"></a>01251 
+<a name="l01252"></a>01252 
+<a name="l01253"></a>01253 
+<a name="l01254"></a>01254 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span>* sinfo_new_set_stk_procatg(<span class="keyword">const</span> <span class="keywordtype">char</span>* tag)
+<a name="l01255"></a>01255 {
+<a name="l01256"></a>01256 
+<a name="l01257"></a>01257   <span class="keyword">const</span> <span class="keywordtype">char</span>* pro_ctg_stack=NULL;
+<a name="l01258"></a>01258 
+<a name="l01259"></a>01259   <span class="keywordflow">if</span>(strstr(tag,<span class="stringliteral">"OBJ"</span>) != NULL) {
+<a name="l01260"></a>01260     pro_ctg_stack=PRO_OBJECT_NODDING_STACKED;
+<a name="l01261"></a>01261   } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(strstr(tag,<span class="stringliteral">"PSF"</span>) != NULL) {
+<a name="l01262"></a>01262     pro_ctg_stack=PRO_PSF_CALIBRATOR_STACKED;
+<a name="l01263"></a>01263   } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(strstr(tag,<span class="stringliteral">"STD"</span>) != NULL) {
+<a name="l01264"></a>01264     pro_ctg_stack=PRO_STD_NODDING_STACKED;
+<a name="l01265"></a>01265   } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(strstr(tag,<span class="stringliteral">"PUPIL"</span>) != NULL) {
+<a name="l01266"></a>01266     pro_ctg_stack=PRO_PUPIL_LAMP_STACKED;
+<a name="l01267"></a>01267   } <span class="keywordflow">else</span> {
+<a name="l01268"></a>01268     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"frame tag %s not supported"</span>,tag);
+<a name="l01269"></a>01269     <span class="keywordflow">return</span> NULL;
+<a name="l01270"></a>01270   }
+<a name="l01271"></a>01271 
+<a name="l01272"></a>01272   <span class="keywordflow">return</span> pro_ctg_stack;
+<a name="l01273"></a>01273 
+<a name="l01274"></a>01274 }
+<a name="l01275"></a>01275 <span class="keyword">const</span> <span class="keywordtype">char</span>* sinfo_new_set_obj_procatg(<span class="keyword">const</span> <span class="keywordtype">char</span>* tag)
+<a name="l01276"></a>01276 {
+<a name="l01277"></a>01277   <span class="keyword">const</span> <span class="keywordtype">char</span>* pro_ctg_cube=NULL;
+<a name="l01278"></a>01278 
+<a name="l01279"></a>01279   <span class="keywordflow">if</span>(strstr(tag,<span class="stringliteral">"OBJ"</span>) != NULL) {
+<a name="l01280"></a>01280     pro_ctg_cube=PRO_COADD_OBJ;
+<a name="l01281"></a>01281   } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(strstr(tag,<span class="stringliteral">"PSF"</span>) != NULL) {
+<a name="l01282"></a>01282     pro_ctg_cube=PRO_COADD_PSF;
+<a name="l01283"></a>01283   } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(strstr(tag,<span class="stringliteral">"STD"</span>) != NULL) {
+<a name="l01284"></a>01284     pro_ctg_cube=PRO_COADD_STD;
+<a name="l01285"></a>01285   } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(strstr(tag,<span class="stringliteral">"PUPIL"</span>) != NULL) {
+<a name="l01286"></a>01286     pro_ctg_cube=PRO_COADD_PUPIL;
+<a name="l01287"></a>01287   } <span class="keywordflow">else</span> {
+<a name="l01288"></a>01288     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"frame tag %s not supported"</span>,tag);
+<a name="l01289"></a>01289     <span class="keywordflow">return</span> NULL;
+<a name="l01290"></a>01290   }
+<a name="l01291"></a>01291 
+<a name="l01292"></a>01292   <span class="keywordflow">return</span> pro_ctg_cube;
+<a name="l01293"></a>01293 
+<a name="l01294"></a>01294 }
+<a name="l01295"></a>01295 
+<a name="l01296"></a>01296 <span class="comment">/*</span>
+<a name="l01297"></a>01297 <span class="comment">static int</span>
+<a name="l01298"></a>01298 <span class="comment">sinfo_get_obj_sky_frm_pair(</span>
+<a name="l01299"></a>01299 <span class="comment">cpl_frameset** obj_set,</span>
+<a name="l01300"></a>01300 <span class="comment">const int i,</span>
+<a name="l01301"></a>01301 <span class="comment">cpl_frame** obj_frm,</span>
+<a name="l01302"></a>01302 <span class="comment">cpl_frame** sky_frm)</span>
+<a name="l01303"></a>01303 <span class="comment">{</span>
+<a name="l01304"></a>01304 <span class="comment">  double mjd_obj=0;</span>
+<a name="l01305"></a>01305 <span class="comment">  double mjd_sky_inf=0;</span>
+<a name="l01306"></a>01306 <span class="comment">  double mjd_sky_sup=0;</span>
+<a name="l01307"></a>01307 <span class="comment"></span>
+<a name="l01308"></a>01308 <span class="comment"></span>
+<a name="l01309"></a>01309 <span class="comment">  double obj_cumx=0;</span>
+<a name="l01310"></a>01310 <span class="comment">  double obj_cumy=0;</span>
+<a name="l01311"></a>01311 <span class="comment"></span>
+<a name="l01312"></a>01312 <span class="comment">  double sky_sup_cumx=0;</span>
+<a name="l01313"></a>01313 <span class="comment">  double sky_sup_cumy=0;</span>
+<a name="l01314"></a>01314 <span class="comment"></span>
+<a name="l01315"></a>01315 <span class="comment">  double sky_inf_cumx=0;</span>
+<a name="l01316"></a>01316 <span class="comment">  double sky_inf_cumy=0;</span>
+<a name="l01317"></a>01317 <span class="comment">  double cum_thres=0.5;</span>
+<a name="l01318"></a>01318 <span class="comment">  int nobj=0;</span>
+<a name="l01319"></a>01319 <span class="comment">  cpl_frame* sky_frm_inf=NULL;</span>
+<a name="l01320"></a>01320 <span class="comment">  cpl_frame* sky_frm_sup=NULL;</span>
+<a name="l01321"></a>01321 <span class="comment"></span>
+<a name="l01322"></a>01322 <span class="comment">  check_nomsg(*obj_frm=cpl_frameset_get_frame(*obj_set,i));</span>
+<a name="l01323"></a>01323 <span class="comment">  mjd_obj    = sinfo_get_mjd_obs(*obj_frm);</span>
+<a name="l01324"></a>01324 <span class="comment">  obj_cumx=sinfo_get_cumoffsetx(*obj_frm);</span>
+<a name="l01325"></a>01325 <span class="comment">  obj_cumy=sinfo_get_cumoffsety(*obj_frm);</span>
+<a name="l01326"></a>01326 <span class="comment"></span>
+<a name="l01327"></a>01327 <span class="comment">  if(i>0) {</span>
+<a name="l01328"></a>01328 <span class="comment">    check_nomsg(sky_frm_inf=cpl_frameset_get_frame(*obj_set,i-1));</span>
+<a name="l01329"></a>01329 <span class="comment">    mjd_sky_inf = sinfo_get_mjd_obs(sky_frm_inf);</span>
+<a name="l01330"></a>01330 <span class="comment">    sky_inf_cumx=sinfo_get_cumoffsetx(sky_frm_inf);</span>
+<a name="l01331"></a>01331 <span class="comment">    sky_inf_cumy=sinfo_get_cumoffsety(sky_frm_inf);</span>
+<a name="l01332"></a>01332 <span class="comment">  }</span>
+<a name="l01333"></a>01333 <span class="comment"></span>
+<a name="l01334"></a>01334 <span class="comment">  if(i<nobj-1) {</span>
+<a name="l01335"></a>01335 <span class="comment">    check_nomsg(sky_frm_sup=cpl_frameset_get_frame(*obj_set,i+1));</span>
+<a name="l01336"></a>01336 <span class="comment">    mjd_sky_sup = sinfo_get_mjd_obs(sky_frm_sup);</span>
+<a name="l01337"></a>01337 <span class="comment">    sky_sup_cumx=sinfo_get_cumoffsetx(sky_frm_sup);</span>
+<a name="l01338"></a>01338 <span class="comment">    sky_sup_cumy=sinfo_get_cumoffsety(sky_frm_sup);</span>
+<a name="l01339"></a>01339 <span class="comment">  }</span>
+<a name="l01340"></a>01340 <span class="comment"></span>
+<a name="l01341"></a>01341 <span class="comment">  if(i==0) {</span>
+<a name="l01342"></a>01342 <span class="comment">    *sky_frm = sky_frm_sup;</span>
+<a name="l01343"></a>01343 <span class="comment">  } else if(i==(nobj-1)) {</span>
+<a name="l01344"></a>01344 <span class="comment">    *sky_frm = sky_frm_inf;</span>
+<a name="l01345"></a>01345 <span class="comment">  } else {</span>
+<a name="l01346"></a>01346 <span class="comment">       if( fabs( mjd_sky_inf - mjd_obj ) <</span>
+<a name="l01347"></a>01347 <span class="comment">           fabs( mjd_sky_sup - mjd_obj ) ) {</span>
+<a name="l01348"></a>01348 <span class="comment">         if((fabs(sky_inf_cumx-obj_cumx) > cum_thres) ||</span>
+<a name="l01349"></a>01349 <span class="comment">            (fabs(sky_inf_cumy-obj_cumy) > cum_thres)) {</span>
+<a name="l01350"></a>01350 <span class="comment">       *sky_frm = sky_frm_inf;</span>
+<a name="l01351"></a>01351 <span class="comment">     } else {</span>
+<a name="l01352"></a>01352 <span class="comment">       *sky_frm = sky_frm_sup;</span>
+<a name="l01353"></a>01353 <span class="comment">     }</span>
+<a name="l01354"></a>01354 <span class="comment">       } else {</span>
+<a name="l01355"></a>01355 <span class="comment">         if((fabs(sky_sup_cumx-obj_cumx) > cum_thres) ||</span>
+<a name="l01356"></a>01356 <span class="comment">            (fabs(sky_sup_cumy-obj_cumy) > cum_thres)) {</span>
+<a name="l01357"></a>01357 <span class="comment">       *sky_frm = sky_frm_sup;</span>
+<a name="l01358"></a>01358 <span class="comment">     } else {</span>
+<a name="l01359"></a>01359 <span class="comment">       *sky_frm = sky_frm_inf;</span>
+<a name="l01360"></a>01360 <span class="comment">     }</span>
+<a name="l01361"></a>01361 <span class="comment">       }</span>
+<a name="l01362"></a>01362 <span class="comment">  }</span>
+<a name="l01363"></a>01363 <span class="comment">  return 0;</span>
+<a name="l01364"></a>01364 <span class="comment"></span>
+<a name="l01365"></a>01365 <span class="comment"> cleanup:</span>
+<a name="l01366"></a>01366 <span class="comment">  return -1;</span>
+<a name="l01367"></a>01367 <span class="comment"></span>
+<a name="l01368"></a>01368 <span class="comment">}</span>
+<a name="l01369"></a>01369 <span class="comment">*/</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__rec__utils_8h_source.html b/html/sinfo__rec__utils_8h_source.html
new file mode 100644
index 0000000..9eb6e68
--- /dev/null
+++ b/html/sinfo__rec__utils_8h_source.html
@@ -0,0 +1,124 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_rec_utils.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_rec_utils.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#ifndef SINFO_REC_UTILS_H</span>
+<a name="l00002"></a>00002 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_REC_UTILS_H</span>
+<a name="l00003"></a>00003 <span class="preprocessor"></span>
+<a name="l00004"></a>00004 <span class="comment">/* $Id: sinfo_rec_utils.h,v 1.2 2007/06/06 07:10:45 amodigli Exp $</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This file is part of the CPL (Common Pipeline Library)</span>
+<a name="l00007"></a>00007 <span class="comment"> * Copyright (C) 2002 European Southern Observatory</span>
+<a name="l00008"></a>00008 <span class="comment"> *</span>
+<a name="l00009"></a>00009 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
+<a name="l00010"></a>00010 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span>
+<a name="l00011"></a>00011 <span class="comment"> * License as published by the Free Software Foundation; either</span>
+<a name="l00012"></a>00012 <span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span>
+<a name="l00013"></a>00013 <span class="comment"> *</span>
+<a name="l00014"></a>00014 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
+<a name="l00015"></a>00015 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00016"></a>00016 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
+<a name="l00017"></a>00017 <span class="comment"> * Lesser General Public License for more details.</span>
+<a name="l00018"></a>00018 <span class="comment"> *</span>
+<a name="l00019"></a>00019 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
+<a name="l00020"></a>00020 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
+<a name="l00021"></a>00021 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00022"></a>00022 <span class="comment"> */</span>
+<a name="l00023"></a>00023 <span class="comment">/*</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Date: 2007/06/06 07:10:45 $</span>
+<a name="l00026"></a>00026 <span class="comment"> * $Revision: 1.2 $</span>
+<a name="l00027"></a>00027 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00028"></a>00028 <span class="comment"> */</span>
+<a name="l00029"></a>00029 
+<a name="l00030"></a>00030  <span class="comment">/****************************************************************</span>
+<a name="l00031"></a>00031 <span class="comment">  *           Object Data reduction                              *</span>
+<a name="l00032"></a>00032 <span class="comment">  ****************************************************************/</span>
+<a name="l00033"></a>00033 
+<a name="l00034"></a>00034 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00035"></a>00035 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>          <span class="comment">/* allows the program compilation */</span>
+<a name="l00036"></a>00036 <span class="preprocessor">#endif</span>
+<a name="l00037"></a>00037 <span class="preprocessor"></span>
+<a name="l00038"></a>00038 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00039"></a>00039 <span class="comment">                                Includes</span>
+<a name="l00040"></a>00040 <span class="comment">-----------------------------------------------------------------------------*/</span>
+<a name="l00041"></a>00041 
+<a name="l00042"></a>00042 <span class="comment">/* std */</span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include <strings.h></span>
+<a name="l00044"></a>00044 <span class="preprocessor">#include <string.h></span>
+<a name="l00045"></a>00045 <span class="preprocessor">#include <stdio.h></span>
+<a name="l00046"></a>00046 <span class="preprocessor">#include <math.h></span>
+<a name="l00047"></a>00047 <span class="preprocessor">#include <libgen.h></span>
+<a name="l00048"></a>00048 
+<a name="l00049"></a>00049 <span class="comment">/* cpl */</span>
+<a name="l00050"></a>00050 <span class="preprocessor">#include <cpl.h></span>  
+<a name="l00051"></a>00051 
+<a name="l00052"></a>00052 <span class="comment">/* sinfoni */</span>
+<a name="l00053"></a>00053 <span class="preprocessor">#include <sinfo_pro_types.h></span>
+<a name="l00054"></a>00054 <span class="preprocessor">#include <sinfo_key_names.h></span>
+<a name="l00055"></a>00055 <span class="preprocessor">#include <sinfo_raw_types.h></span>
+<a name="l00056"></a>00056 <span class="preprocessor">#include <sinfo_globals.h></span>
+<a name="l00057"></a>00057 <span class="preprocessor">#include <sinfo_new_prepare_stacked_frames.h></span>
+<a name="l00058"></a>00058 <span class="preprocessor">#include <sinfo_functions.h></span>
+<a name="l00059"></a>00059 
+<a name="l00060"></a>00060 
+<a name="l00061"></a>00061 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00062"></a>00062 <span class="comment">                            Functions prototypes</span>
+<a name="l00063"></a>00063 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00064"></a>00064 
+<a name="l00065"></a>00065 
+<a name="l00066"></a>00066 <span class="keywordtype">int</span> 
+<a name="l00067"></a>00067 sinfo_new_get_dummy_obj_sky_stacked(cpl_frameset* obj_set,
+<a name="l00068"></a>00068                                     cpl_frameset** <span class="keyword">set</span>, 
+<a name="l00069"></a>00069                                     cpl_parameterlist* config,
+<a name="l00070"></a>00070                                     fake* fk,
+<a name="l00071"></a>00071                                     <span class="keywordtype">char</span>* pro_ctg, 
+<a name="l00072"></a>00072                                     <span class="keyword">const</span> <span class="keywordtype">char</span>* plugin_id);
+<a name="l00073"></a>00073 
+<a name="l00074"></a>00074 cpl_frame* 
+<a name="l00075"></a>00075 sinfo_new_get_dummy_sky(cpl_frameset* obj_set);
+<a name="l00076"></a>00076 
+<a name="l00077"></a>00077 <span class="keywordtype">int</span> 
+<a name="l00078"></a>00078 sinfo_new_sci_stk_frames(cpl_parameterlist* config,
+<a name="l00079"></a>00079                          cpl_frameset** <span class="keyword">set</span>,
+<a name="l00080"></a>00080                          <span class="keyword">const</span> <span class="keywordtype">char</span>* recipe_id,
+<a name="l00081"></a>00081              <span class="keyword">const</span> <span class="keywordtype">char</span>** pro_ctg_cube);
+<a name="l00082"></a>00082 
+<a name="l00083"></a>00083 <span class="keywordtype">int</span> 
+<a name="l00084"></a>00084 sinfo_cub_stk_frames(cpl_parameterlist* config,
+<a name="l00085"></a>00085                      cpl_frameset** <span class="keyword">set</span>,
+<a name="l00086"></a>00086                      <span class="keyword">const</span> <span class="keywordtype">char</span>* recipe_id,
+<a name="l00087"></a>00087              <span class="keyword">const</span> <span class="keywordtype">char</span>** pro_ctg_cube);
+<a name="l00088"></a>00088 
+<a name="l00089"></a>00089 
+<a name="l00090"></a>00090 <span class="keywordtype">int</span>
+<a name="l00091"></a>00091 sinfo_new_stack_frames(cpl_parameterlist* cfg, 
+<a name="l00092"></a>00092                        cpl_frameset* <span class="keyword">set</span>, 
+<a name="l00093"></a>00093                        <span class="keyword">const</span> <span class="keywordtype">char</span>* procatg,
+<a name="l00094"></a>00094                        <span class="keyword">const</span> <span class="keywordtype">int</span> <span class="keywordtype">id</span>, 
+<a name="l00095"></a>00095                        fake* fk, 
+<a name="l00096"></a>00096                        <span class="keyword">const</span> <span class="keywordtype">char</span>* plugin_id);
+<a name="l00097"></a>00097 
+<a name="l00098"></a>00098 <span class="keyword">const</span> <span class="keywordtype">char</span>* 
+<a name="l00099"></a>00099 sinfo_new_set_obj_procatg(<span class="keyword">const</span> <span class="keywordtype">char</span>* tag);
+<a name="l00100"></a>00100 
+<a name="l00101"></a>00101 <span class="keywordtype">int</span>
+<a name="l00102"></a>00102 sinfo_get_dummy_obj_sky_stacked_and_cubes(cpl_frameset* obj_set,
+<a name="l00103"></a>00103                                           cpl_frameset** <span class="keyword">set</span>, 
+<a name="l00104"></a>00104                                           cpl_parameterlist* config,
+<a name="l00105"></a>00105                                           fake* fk, 
+<a name="l00106"></a>00106                                           <span class="keywordtype">char</span>* pro_ctg, 
+<a name="l00107"></a>00107                                           <span class="keyword">const</span> <span class="keywordtype">char</span>* plugin_id);
+<a name="l00108"></a>00108 <span class="preprocessor">#endif </span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__rec__wavecal_8c_source.html b/html/sinfo__rec__wavecal_8c_source.html
new file mode 100644
index 0000000..228ff48
--- /dev/null
+++ b/html/sinfo__rec__wavecal_8c_source.html
@@ -0,0 +1,429 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_rec_wavecal.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_rec_wavecal.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_rec_wavecal.c,v 1.30 2009/09/02 12:00:56 kmirny Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the SINFONI Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: kmirny $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2009/09/02 12:00:56 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.30 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028  <span class="comment">/****************************************************************</span>
+<a name="l00029"></a>00029 <span class="comment">  *          Wave_Cal Frames Data Reduction                          *</span>
+<a name="l00030"></a>00030 <span class="comment">  ****************************************************************/</span>
+<a name="l00031"></a>00031 
+<a name="l00032"></a>00032 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                                Includes</span>
+<a name="l00034"></a>00034 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 
+<a name="l00036"></a>00036 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00037"></a>00037 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>          <span class="comment">/* allows the program compilation */</span>
+<a name="l00038"></a>00038 <span class="preprocessor">#endif</span>
+<a name="l00039"></a>00039 <span class="preprocessor"></span>
+<a name="l00040"></a>00040 <span class="comment">/* std */</span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include <strings.h></span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include <string.h></span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include <stdio.h></span>
+<a name="l00044"></a>00044 
+<a name="l00045"></a>00045 
+<a name="l00046"></a>00046 <span class="comment">/* cpl */</span>
+<a name="l00047"></a>00047 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00048"></a>00048 
+<a name="l00049"></a>00049 <span class="comment">/* irplib */</span>
+<a name="l00050"></a>00050 <span class="preprocessor">#include <irplib_utils.h></span>
+<a name="l00051"></a>00051 
+<a name="l00052"></a>00052 <span class="comment">/* sinfoni */</span>
+<a name="l00053"></a>00053 <span class="preprocessor">#include <sinfo_pro_types.h></span>
+<a name="l00054"></a>00054 <span class="preprocessor">#include <sinfo_general_config.h></span>
+<a name="l00055"></a>00055 <span class="preprocessor">#include <sinfo_utilities.h></span>
+<a name="l00056"></a>00056 <span class="preprocessor">#include <sinfo_product_config.h></span>
+<a name="l00057"></a>00057 <span class="preprocessor">#include <sinfo_prepare_stacked_frames_config.h></span>
+<a name="l00058"></a>00058 <span class="preprocessor">#include <sinfo_wavecal_config.h></span>
+<a name="l00059"></a>00059 <span class="preprocessor">#include <sinfo_raw_types.h></span>
+<a name="l00060"></a>00060 <span class="preprocessor">#include <sinfo_tpl_utils.h></span>
+<a name="l00061"></a>00061 <span class="preprocessor">#include <sinfo_tpl_dfs.h></span>
+<a name="l00062"></a>00062 <span class="preprocessor">#include <sinfo_hidden.h></span>
+<a name="l00063"></a>00063 <span class="preprocessor">#include <sinfo_globals.h></span>
+<a name="l00064"></a>00064 <span class="preprocessor">#include <sinfo_functions.h></span>
+<a name="l00065"></a>00065 <span class="preprocessor">#include <sinfo_msg.h></span>
+<a name="l00066"></a>00066 <span class="preprocessor">#include <sinfo_new_prepare_stacked_frames.h></span>
+<a name="l00067"></a>00067 <span class="preprocessor">#include <sinfo_new_wave_cal_slit2.h></span>
+<a name="l00068"></a>00068 <span class="preprocessor">#include <sinfo_error.h></span>
+<a name="l00069"></a>00069 <span class="preprocessor">#include <sinfo_utils_wrappers.h></span>
+<a name="l00070"></a>00070 
+<a name="l00071"></a>00071 <span class="preprocessor">#include <sinfo_key_names.h></span>
+<a name="l00072"></a>00072 
+<a name="l00073"></a>00073 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00074"></a>00074 <span class="comment">                            Functions prototypes</span>
+<a name="l00075"></a>00075 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00076"></a>00076 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_wavecal_create(cpl_plugin *);
+<a name="l00077"></a>00077 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_wavecal_exec(cpl_plugin *);
+<a name="l00078"></a>00078 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_wavecal_destroy(cpl_plugin *);
+<a name="l00079"></a>00079 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_wavecal(cpl_parameterlist *, cpl_frameset *);
+<a name="l00080"></a>00080 
+<a name="l00081"></a>00081 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00082"></a>00082 <span class="comment">                            Static variables</span>
+<a name="l00083"></a>00083 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00084"></a>00084 
+<a name="l00085"></a>00085 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_rec_wavecal_description1[] =
+<a name="l00086"></a>00086 <span class="stringliteral">"This recipe performs wavelength calibration.\n"</span>
+<a name="l00087"></a>00087 <span class="stringliteral">"The input files are on/off arc lamp frames with tag WAVE_LAMP\n"</span>
+<a name="l00088"></a>00088 <span class="stringliteral">"Master calibration frame input is:\n"</span>
+<a name="l00089"></a>00089 <span class="stringliteral">"A corresponding (band) reference line table with tag REF_LINE_ARC\n"</span>
+<a name="l00090"></a>00090 <span class="stringliteral">"A corresponding (band) distortion table with tag DISTORTION\n"</span>
+<a name="l00091"></a>00091 <span class="stringliteral">"A corresponding (band,preoptic) master flat with tag MASTER_FLAT_LAMP\n"</span>
+<a name="l00092"></a>00092 <span class="stringliteral">"A corresponding (band,preoptics) master bad "</span>
+<a name="l00093"></a>00093 <span class="stringliteral">"pixel map with tag MASTER_BP_MAP\n"</span>;
+<a name="l00094"></a>00094 
+<a name="l00095"></a>00095 
+<a name="l00096"></a>00096 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_rec_wavecal_description2[] =
+<a name="l00097"></a>00097 <span class="stringliteral">"If wcal-estimate_ind=TRUE, a corresponding (band,preoptics) slitlet position\n"</span>
+<a name="l00098"></a>00098 <span class="stringliteral">"guess table SLIT_POS_GUESS (for example a copy of the SLIT_POS product)\n"</span>
+<a name="l00099"></a>00099 <span class="stringliteral">"If wcal-calib_indicator=FALSE, a corresponding (band,preoptics) parabolic \n"</span>
+<a name="l00100"></a>00100 <span class="stringliteral">"fit coefficients table WAVE_COEF_SLIT\n"</span>
+<a name="l00101"></a>00101 <span class="stringliteral">"If sinfoni.wavecal.slitpos_boostrap_switch=FALSE \n"</span>
+<a name="l00102"></a>00102 <span class="stringliteral">"(wcal-calib-slitpos_bootstrap=0),\n"</span>
+<a name="l00103"></a>00103 <span class="stringliteral">"a corresponding (band,preoptics) slitlets position table with tag SLIT_POS\n"</span>;
+<a name="l00104"></a>00104 
+<a name="l00105"></a>00105 
+<a name="l00106"></a>00106 
+<a name="l00107"></a>00107 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_rec_wavecal_description3[] =
+<a name="l00108"></a>00108 <span class="stringliteral">"The main products are:\n"</span>
+<a name="l00109"></a>00109 <span class="stringliteral">"The master flat field corrected for distortions \n"</span>
+<a name="l00110"></a>00110 <span class="stringliteral">"(PRO.CATG=MFLAT_STACKED_DIST)\n"</span>
+<a name="l00111"></a>00111 <span class="stringliteral">"The arc lamp frames stacked (PRO.CATG=WAVE_LAMP_STACKED)\n"</span>
+<a name="l00112"></a>00112 <span class="stringliteral">"The wavelength map (PRO.CATG=WAVE_MAP)\n"</span>
+<a name="l00113"></a>00113 <span class="stringliteral">"The slitlet position table (PRO.CATG=SLIT_POS)\n"</span>
+<a name="l00114"></a>00114 <span class="stringliteral">"A parabolic fit coefficients table (PRO.CATG=WAVE_COEF_SLIT)\n"</span>
+<a name="l00115"></a>00115 <span class="stringliteral">"Parameters relative to arc lamp line fit: (PRO.CATG=WAVE_FIT_PARAMS)\n"</span>
+<a name="l00116"></a>00116 <span class="stringliteral">"Information on relevant parameters can be found with\n"</span>
+<a name="l00117"></a>00117 <span class="stringliteral">"esorex --params sinfo_rec_wavecal\n"</span>
+<a name="l00118"></a>00118 <span class="stringliteral">"esorex --help sinfo_rec_wavecal\n"</span>
+<a name="l00119"></a>00119 <span class="stringliteral">"\n"</span>;
+<a name="l00120"></a>00120 
+<a name="l00121"></a>00121 
+<a name="l00122"></a>00122 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_rec_wavecal_description[1500];
+<a name="l00123"></a>00123 
+<a name="l00124"></a>00124 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00125"></a>00125 <span class="comment">                                Functions code</span>
+<a name="l00126"></a>00126 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00127"></a>00127 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00131"></a>00131 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00132"></a>00132 
+<a name="l00134"></a>00134 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00143"></a>00143 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00144"></a>00144 
+<a name="l00145"></a>00145 <span class="keywordtype">int</span>
+<a name="l00146"></a><a class="code" href="group__sinfo__rec__wavecal.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693">00146</a> <a class="code" href="group__sinfo__rec__detlin.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693" title="Build the list of available plugins, for this module.">cpl_plugin_get_info</a>(cpl_pluginlist *list)
+<a name="l00147"></a>00147 {
+<a name="l00148"></a>00148 
+<a name="l00149"></a>00149   cpl_recipe *recipe = cpl_calloc(1, <span class="keyword">sizeof</span> *recipe);
+<a name="l00150"></a>00150   cpl_plugin *plugin = &recipe->interface;
+<a name="l00151"></a>00151 
+<a name="l00152"></a>00152 
+<a name="l00153"></a>00153   strcpy(sinfo_rec_wavecal_description,sinfo_rec_wavecal_description1);
+<a name="l00154"></a>00154   strcat(sinfo_rec_wavecal_description,sinfo_rec_wavecal_description2);
+<a name="l00155"></a>00155   strcat(sinfo_rec_wavecal_description,sinfo_rec_wavecal_description3);
+<a name="l00156"></a>00156 
+<a name="l00157"></a>00157   cpl_plugin_init(plugin,
+<a name="l00158"></a>00158           CPL_PLUGIN_API,
+<a name="l00159"></a>00159           SINFONI_BINARY_VERSION,
+<a name="l00160"></a>00160           CPL_PLUGIN_TYPE_RECIPE,
+<a name="l00161"></a>00161           <span class="stringliteral">"sinfo_rec_wavecal"</span>,
+<a name="l00162"></a>00162           <span class="stringliteral">"Wavelength calibration and slitpos determination"</span>,
+<a name="l00163"></a>00163           sinfo_rec_wavecal_description,
+<a name="l00164"></a>00164           <span class="stringliteral">"Andrea Modigliani"</span>,
+<a name="l00165"></a>00165           <span class="stringliteral">"Andrea.Modigliani at eso.org"</span>,
+<a name="l00166"></a>00166           sinfo_get_license(),
+<a name="l00167"></a>00167           sinfo_rec_wavecal_create,
+<a name="l00168"></a>00168           sinfo_rec_wavecal_exec,
+<a name="l00169"></a>00169           sinfo_rec_wavecal_destroy);
+<a name="l00170"></a>00170 
+<a name="l00171"></a>00171   cpl_pluginlist_append(list, plugin);
+<a name="l00172"></a>00172 
+<a name="l00173"></a>00173   <span class="keywordflow">return</span> 0;
+<a name="l00174"></a>00174 
+<a name="l00175"></a>00175 }
+<a name="l00176"></a>00176 
+<a name="l00177"></a>00177 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00185"></a>00185 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00186"></a>00186 
+<a name="l00187"></a>00187 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_wavecal_create(cpl_plugin *plugin)
+<a name="l00188"></a>00188 {
+<a name="l00189"></a>00189    cpl_recipe      * recipe ;
+<a name="l00190"></a>00190 
+<a name="l00191"></a>00191     <span class="comment">/* Check that the plugin is part of a valid recipe */</span>
+<a name="l00192"></a>00192     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
+<a name="l00193"></a>00193         recipe = (cpl_recipe *)plugin ;
+<a name="l00194"></a>00194     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00195"></a>00195     cpl_error_reset();
+<a name="l00196"></a>00196     <a class="code" href="group__irplib__utils.html#gaf9d392144014e2363054bc3f83c8e47e" title="Reset IRPLIB state.">irplib_reset</a>();
+<a name="l00197"></a>00197 
+<a name="l00198"></a>00198     <span class="comment">/* Create the parameters list in the cpl_recipe object */</span>
+<a name="l00199"></a>00199     recipe->parameters = cpl_parameterlist_new() ;
+<a name="l00200"></a>00200 
+<a name="l00201"></a>00201 
+<a name="l00202"></a>00202   <span class="comment">/*</span>
+<a name="l00203"></a>00203 <span class="comment">   * Fill the parameter list.</span>
+<a name="l00204"></a>00204 <span class="comment">   */</span>
+<a name="l00205"></a>00205 
+<a name="l00206"></a>00206   <span class="comment">/* Wavelength calibration  */</span>
+<a name="l00207"></a>00207   sinfo_general_config_add(recipe->parameters);
+<a name="l00208"></a>00208   sinfo_product_config_add(recipe->parameters);
+<a name="l00209"></a>00209   sinfo_prepare_stacked_frames_config_add(recipe->parameters);
+<a name="l00210"></a>00210   sinfo_wavecal_config_add(recipe->parameters);
+<a name="l00211"></a>00211   <span class="keywordflow">return</span> 0;
+<a name="l00212"></a>00212 
+<a name="l00213"></a>00213 }
+<a name="l00214"></a>00214 
+<a name="l00215"></a>00215 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00221"></a>00221 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00222"></a>00222 
+<a name="l00223"></a>00223 
+<a name="l00224"></a>00224 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_wavecal_exec(cpl_plugin *plugin)
+<a name="l00225"></a>00225 {
+<a name="l00226"></a>00226 
+<a name="l00227"></a>00227   cpl_recipe *recipe = (cpl_recipe *) plugin;
+<a name="l00228"></a>00228 
+<a name="l00229"></a>00229   <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00230"></a>00230   <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
+<a name="l00231"></a>00231       recipe = (cpl_recipe *)plugin ;
+<a name="l00232"></a>00232   <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00233"></a>00233 
+<a name="l00234"></a>00234   <span class="keywordflow">return</span> sinfo_rec_wavecal(recipe->parameters, recipe->frames);
+<a name="l00235"></a>00235 
+<a name="l00236"></a>00236 }
+<a name="l00237"></a>00237 
+<a name="l00238"></a>00238 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00244"></a>00244 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00245"></a>00245 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_wavecal_destroy(cpl_plugin *plugin)
+<a name="l00246"></a>00246 {
+<a name="l00247"></a>00247   cpl_recipe  *   recipe ;
+<a name="l00248"></a>00248     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00249"></a>00249     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
+<a name="l00250"></a>00250         recipe = (cpl_recipe *)plugin ;
+<a name="l00251"></a>00251     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00252"></a>00252 
+<a name="l00253"></a>00253   cpl_parameterlist_delete(recipe->parameters);
+<a name="l00254"></a>00254 
+<a name="l00255"></a>00255   <span class="keywordflow">return</span> 0;
+<a name="l00256"></a>00256 
+<a name="l00257"></a>00257 }
+<a name="l00258"></a>00258 
+<a name="l00259"></a>00259 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00266"></a>00266 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00267"></a>00267 <span class="comment">/*</span>
+<a name="l00268"></a>00268 <span class="comment"> * The actual recipe actually start here.</span>
+<a name="l00269"></a>00269 <span class="comment"> */</span>
+<a name="l00270"></a>00270 
+<a name="l00271"></a>00271 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_rec_wavecal(cpl_parameterlist *config, cpl_frameset *<span class="keyword">set</span>)
+<a name="l00272"></a>00272 {
+<a name="l00273"></a>00273 
+<a name="l00274"></a>00274   <span class="keywordtype">int</span> sw=0;
+<a name="l00275"></a>00275   fake* fk=NULL;
+<a name="l00276"></a>00276   cpl_parameter* p=NULL;
+<a name="l00277"></a>00277   cpl_frameset* wrk_set=NULL;
+<a name="l00278"></a>00278   cpl_frame* frame=NULL;
+<a name="l00279"></a>00279   <span class="keywordtype">int</span> ind_index=0;
+<a name="l00280"></a>00280   cpl_frameset* ref_set=NULL;
+<a name="l00281"></a>00281   <span class="keywordtype">int</span> pdensity=0;
+<a name="l00282"></a>00282   <span class="keywordtype">int</span> line_cor=0;
+<a name="l00283"></a>00283 
+<a name="l00284"></a>00284   fk=sinfo_fake_new();
+<a name="l00285"></a>00285 
+<a name="l00286"></a>00286    sinfo_msg(<span class="stringliteral">"Welcome to SINFONI Pipeline release %d.%d.%d"</span>,
+<a name="l00287"></a>00287         SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
+<a name="l00288"></a>00288 
+<a name="l00289"></a>00289 
+<a name="l00290"></a>00290 
+<a name="l00291"></a>00291   ck0(sinfo_dfs_set_groups(<span class="keyword">set</span>),<span class="stringliteral">"Cannot indentify RAW and CALIB frames"</span>) ;
+<a name="l00292"></a>00292   check_nomsg(p=cpl_parameterlist_find(config, <span class="stringliteral">"sinfoni.general.lc_sw"</span>));
+<a name="l00293"></a>00293   check_nomsg(line_cor=cpl_parameter_get_bool(p));
+<a name="l00294"></a>00294   <span class="keywordflow">if</span>(line_cor==1) {
+<a name="l00295"></a>00295      check_nomsg(sinfo_ima_line_cor(config,<span class="keyword">set</span>));
+<a name="l00296"></a>00296   }
+<a name="l00297"></a>00297 
+<a name="l00298"></a>00298 
+<a name="l00299"></a>00299   check_nomsg(ref_set=cpl_frameset_duplicate(<span class="keyword">set</span>));
+<a name="l00300"></a>00300 
+<a name="l00301"></a>00301 
+<a name="l00302"></a>00302   check_nomsg(p=cpl_parameterlist_find(config,<span class="stringliteral">"sinfoni.product.density"</span>));
+<a name="l00303"></a>00303   check_nomsg(pdensity=cpl_parameter_get_int(p));
+<a name="l00304"></a>00304 
+<a name="l00305"></a>00305   <span class="comment">/* hidden parameters */</span>
+<a name="l00306"></a>00306   check_nomsg(p=cpl_parameterlist_find(config,
+<a name="l00307"></a>00307                                        <span class="stringliteral">"sinfoni.wavecal.slitpos_boostrap"</span>));
+<a name="l00308"></a>00308   check_nomsg(sw=cpl_parameter_get_bool(p));
+<a name="l00309"></a>00309   <span class="keywordflow">if</span>( (sw == 1) ) {
+<a name="l00310"></a>00310     check_nomsg(wrk_set=cpl_frameset_duplicate(<span class="keyword">set</span>));
+<a name="l00311"></a>00311 
+<a name="l00312"></a>00312     check_nomsg(p=cpl_parameterlist_find(config,<span class="stringliteral">"sinfoni.stacked.ind_index"</span>));
+<a name="l00313"></a>00313     check_nomsg(ind_index=cpl_parameter_get_bool(p));
+<a name="l00314"></a>00314     check_nomsg(cpl_parameter_set_bool(p,TRUE));
+<a name="l00315"></a>00315 
+<a name="l00316"></a>00316     sinfo_msg(<span class="stringliteral">"---------------------------------------"</span>);
+<a name="l00317"></a>00317     sinfo_msg(<span class="stringliteral">"%s FRAME DETERMINATION"</span>, PRO_WAVE_LAMP_STACKED);
+<a name="l00318"></a>00318     sinfo_msg(<span class="stringliteral">"---------------------------------------"</span>);
+<a name="l00319"></a>00319     ck0(sinfo_new_prepare_stacked_frames(cpl_func,config, wrk_set, NULL,
+<a name="l00320"></a>00320                      PRO_WAVE_LAMP_STACKED,0,fk),
+<a name="l00321"></a>00321        <span class="stringliteral">"FAILED STACKING FRAME %s"</span>,PRO_WAVE_LAMP_STACKED);
+<a name="l00322"></a>00322 
+<a name="l00323"></a>00323     sinfo_msg(<span class="stringliteral">"%s FRAME DETERMINATION SUCCESS"</span>, PRO_WAVE_LAMP_STACKED);
+<a name="l00324"></a>00324 
+<a name="l00325"></a>00325     ck0(sinfo_new_wave_cal_slit2(cpl_func,config, wrk_set,ref_set),
+<a name="l00326"></a>00326     <span class="stringliteral">"FIRST PART OF WAVELENGTH CALIBRATION FAILED"</span>) ;
+<a name="l00327"></a>00327     sinfo_msg(<span class="stringliteral">"FIRST PART OF WAVELENGTH CALIBRATION"</span>) ;
+<a name="l00328"></a>00328 
+<a name="l00329"></a>00329     check_nomsg(frame = cpl_frameset_find(wrk_set,PRO_SLIT_POS_GUESS));
+<a name="l00330"></a>00330     check_nomsg(cpl_frameset_insert(<span class="keyword">set</span>,cpl_frame_duplicate(frame)));
+<a name="l00331"></a>00331     check_nomsg(p=cpl_parameterlist_find(config,<span class="stringliteral">"sinfoni.stacked.ind_index"</span>));
+<a name="l00332"></a>00332     <span class="keywordflow">if</span>(ind_index == 1) {
+<a name="l00333"></a>00333        check_nomsg(cpl_parameter_set_bool(p,TRUE));
+<a name="l00334"></a>00334        check_nomsg(p=cpl_parameterlist_find(config,
+<a name="l00335"></a>00335                                            <span class="stringliteral">"sinfoni.wavecal.slitpos_boostrap"</span>));
+<a name="l00336"></a>00336        check_nomsg(cpl_parameter_set_bool(p,TRUE));
+<a name="l00337"></a>00337        sinfo_msg(<span class="stringliteral">"Set ind_index to TRUE"</span>);
+<a name="l00338"></a>00338     } <span class="keywordflow">else</span> {
+<a name="l00339"></a>00339        check_nomsg(cpl_parameter_set_bool(p,FALSE));
+<a name="l00340"></a>00340        check_nomsg(p=cpl_parameterlist_find(config,
+<a name="l00341"></a>00341                                           <span class="stringliteral">"sinfoni.wavecal.slitpos_boostrap"</span>));
+<a name="l00342"></a>00342        check_nomsg(cpl_parameter_set_bool(p,FALSE));
+<a name="l00343"></a>00343        sinfo_msg(<span class="stringliteral">"Set ind_index to FALSE"</span>);
+<a name="l00344"></a>00344     }
+<a name="l00345"></a>00345     sinfo_free_frameset(&wrk_set);
+<a name="l00346"></a>00346   }
+<a name="l00347"></a>00347 
+<a name="l00348"></a>00348 
+<a name="l00349"></a>00349   sinfo_msg(<span class="stringliteral">"---------------------------------------------"</span>);
+<a name="l00350"></a>00350   sinfo_msg(<span class="stringliteral">"%s FRAME DETERMINATION"</span>, PRO_WAVE_LAMP_STACKED);
+<a name="l00351"></a>00351   sinfo_msg(<span class="stringliteral">"---------------------------------------------"</span>);
+<a name="l00352"></a>00352 
+<a name="l00353"></a>00353   <span class="comment">/*</span>
+<a name="l00354"></a>00354 <span class="comment">   *  Modified code begins here...</span>
+<a name="l00355"></a>00355 <span class="comment">   */</span>
+<a name="l00356"></a>00356   {
+<a name="l00357"></a>00357       <span class="keywordtype">int</span> i, nsky, ndark, nwave, non=0;
+<a name="l00358"></a>00358       cpl_frame * fr;
+<a name="l00359"></a>00359       <span class="keyword">const</span> <span class="keywordtype">char</span> * tag, * fname;
+<a name="l00360"></a>00360       <span class="keywordtype">char</span> name[32];
+<a name="l00361"></a>00361       cpl_image * im;
+<a name="l00362"></a>00362       cpl_propertylist * plist;
+<a name="l00363"></a>00363 
+<a name="l00364"></a>00364       nsky = cpl_frameset_count_tags (<span class="keyword">set</span>, RAW_SKY_NODDING);
+<a name="l00365"></a>00365       nwave = cpl_frameset_count_tags (<span class="keyword">set</span>, RAW_WAVE_LAMP);
+<a name="l00366"></a>00366       ndark = cpl_frameset_count_tags (<span class="keyword">set</span>, PRO_MASTER_DARK);
+<a name="l00367"></a>00367 
+<a name="l00368"></a>00368       <span class="keywordflow">if</span> ( (nwave == 0) & (nsky>0) ) {
+<a name="l00369"></a>00369         sinfo_msg (<span class="stringliteral">"No arc lamp frames found, using sky frames instead"</span>);
+<a name="l00370"></a>00370         <span class="keywordflow">if</span> (ndark == 0)
+<a name="l00371"></a>00371           sinfo_msg (<span class="stringliteral">"Including Master dark is recommended when running wavecal on sky frames"</span>);
+<a name="l00372"></a>00372 
+<a name="l00373"></a>00373         i = 0;
+<a name="l00374"></a>00374         <span class="keywordflow">while</span> (i < cpl_frameset_get_size(<span class="keyword">set</span>)) {
+<a name="l00375"></a>00375           fr = cpl_frameset_get_frame(<span class="keyword">set</span>,i);
+<a name="l00376"></a>00376           tag = cpl_frame_get_tag (fr);
+<a name="l00377"></a>00377 
+<a name="l00378"></a>00378           <span class="keywordflow">if</span> (strcmp(tag, RAW_SKY_NODDING)==0)
+<a name="l00379"></a>00379           {
+<a name="l00380"></a>00380                 cpl_frame * frnew = 0;
+<a name="l00381"></a>00381                 fname = cpl_frame_get_filename(fr);
+<a name="l00382"></a>00382                 sprintf (&name[0], <span class="stringliteral">"fakelamp_%d.fits"</span>, non++);
+<a name="l00383"></a>00383                 im = cpl_image_load(fname, CPL_TYPE_FLOAT, 0, 0);
+<a name="l00384"></a>00384                 plist = cpl_propertylist_load(fname,0);
+<a name="l00385"></a>00385 
+<a name="l00386"></a>00386                 <span class="comment">/* Both if these needs to be changed to make sure the sky frame is</span>
+<a name="l00387"></a>00387 <span class="comment">                   interprated as ON-frame in sinfo_dfs.c</span>
+<a name="l00388"></a>00388 <span class="comment"></span>
+<a name="l00389"></a>00389 <span class="comment">                   The selection of KEY_NAME_LAMP_XE is arbitrary, but one of</span>
+<a name="l00390"></a>00390 <span class="comment">                   KEY_NAME_LAMP_* has to be set */</span>
+<a name="l00391"></a>00391                 cpl_propertylist_set_bool (plist, KEY_NAME_LAMP_XE, 1);
+<a name="l00392"></a>00392                 cpl_propertylist_set_string (plist, KEY_NAME_DPR_TYPE, <span class="stringliteral">"WAVE,LAMP"</span>);
+<a name="l00393"></a>00393 
+<a name="l00394"></a>00394                 cpl_image_save (im, name, CPL_BPP_IEEE_FLOAT, plist, CPL_IO_DEFAULT);
+<a name="l00395"></a>00395                 cpl_image_delete (im);
+<a name="l00396"></a>00396                 cpl_propertylist_delete(plist);
+<a name="l00397"></a>00397 
+<a name="l00398"></a>00398                 <span class="comment">/* Looks like it's not possible to modify the frame directly</span>
+<a name="l00399"></a>00399 <span class="comment">                   without duplicating it first. */</span>
+<a name="l00400"></a>00400                 frnew = cpl_frame_duplicate (fr);
+<a name="l00401"></a>00401                 cpl_frame_set_filename(frnew, name);
+<a name="l00402"></a>00402                 cpl_frame_set_tag (frnew, RAW_WAVE_LAMP);
+<a name="l00403"></a>00403                 cpl_frameset_erase_frame (<span class="keyword">set</span>, fr);
+<a name="l00404"></a>00404                 cpl_frameset_insert (<span class="keyword">set</span>, frnew);
+<a name="l00405"></a>00405           }
+<a name="l00406"></a>00406           <span class="keywordflow">else</span>
+<a name="l00407"></a>00407         i++;
+<a name="l00408"></a>00408         }
+<a name="l00409"></a>00409       }
+<a name="l00410"></a>00410 
+<a name="l00411"></a>00411       <span class="comment">/*</span>
+<a name="l00412"></a>00412 <span class="comment">       * Modified code ends here</span>
+<a name="l00413"></a>00413 <span class="comment">       */</span>
+<a name="l00414"></a>00414   }
+<a name="l00415"></a>00415   ck0(sinfo_new_prepare_stacked_frames(cpl_func,config, <span class="keyword">set</span>, NULL,
+<a name="l00416"></a>00416                        PRO_WAVE_LAMP_STACKED,0,fk),
+<a name="l00417"></a>00417       <span class="stringliteral">"%s FRAME DETERMINATION FAILED"</span>,PRO_WAVE_LAMP_STACKED);
+<a name="l00418"></a>00418   sinfo_msg(<span class="stringliteral">"%s FRAME DETERMINATION SUCCESS"</span>, PRO_WAVE_LAMP_STACKED);
+<a name="l00419"></a>00419 
+<a name="l00420"></a>00420   sinfo_msg(<span class="stringliteral">"---------------------------------------------"</span>);
+<a name="l00421"></a>00421   sinfo_msg(<span class="stringliteral">"WAVELENGTH CALIBRATION"</span>);
+<a name="l00422"></a>00422   sinfo_msg(<span class="stringliteral">"---------------------------------------------"</span>);
+<a name="l00423"></a>00423 
+<a name="l00424"></a>00424 
+<a name="l00425"></a>00425   ck0(sinfo_new_wave_cal_slit2(cpl_func,config, <span class="keyword">set</span>,ref_set),
+<a name="l00426"></a>00426       <span class="stringliteral">"FAILED WAVELENGTH CALIBRATION"</span>);
+<a name="l00427"></a>00427   sinfo_msg(<span class="stringliteral">"SUCCESS WAVELENGTH CALIBRATION"</span>);
+<a name="l00428"></a>00428 
+<a name="l00429"></a>00429   sinfo_fake_delete(&fk);
+<a name="l00430"></a>00430    <span class="keywordflow">if</span>(pdensity < 2) {
+<a name="l00431"></a>00431      check_nomsg(cpl_frameset_erase(<span class="keyword">set</span>,PRO_STACK_MFLAT_DIST));
+<a name="l00432"></a>00432      check_nomsg(cpl_frameset_erase(<span class="keyword">set</span>,PRO_WAVE_LAMP_STACKED));
+<a name="l00433"></a>00433    }
+<a name="l00434"></a>00434 
+<a name="l00435"></a>00435  cleanup:
+<a name="l00436"></a>00436 
+<a name="l00437"></a>00437   sinfo_free_frameset(&ref_set);
+<a name="l00438"></a>00438   sinfo_free_frameset(&wrk_set);
+<a name="l00439"></a>00439   sinfo_fake_delete(&fk);
+<a name="l00440"></a>00440 
+<a name="l00441"></a>00441 
+<a name="l00442"></a>00442   <span class="keywordflow">if</span> (cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l00443"></a>00443     <span class="keywordflow">return</span> -1;
+<a name="l00444"></a>00444   } <span class="keywordflow">else</span> {
+<a name="l00445"></a>00445     <span class="keywordflow">return</span> 0;
+<a name="l00446"></a>00446   }
+<a name="l00447"></a>00447 
+<a name="l00448"></a>00448 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__recipes_8c_source.html b/html/sinfo__recipes_8c_source.html
new file mode 100644
index 0000000..c527090
--- /dev/null
+++ b/html/sinfo__recipes_8c_source.html
@@ -0,0 +1,1257 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_recipes.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_recipes.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/***************************************************************************</span>
+<a name="l00020"></a>00020 <span class="comment">* E.S.O. - VLT project</span>
+<a name="l00021"></a>00021 <span class="comment">*</span>
+<a name="l00022"></a>00022 <span class="comment">*</span>
+<a name="l00023"></a>00023 <span class="comment">*</span>
+<a name="l00024"></a>00024 <span class="comment">* who       when      what</span>
+<a name="l00025"></a>00025 <span class="comment">* --------  --------  ----------------------------------------------</span>
+<a name="l00026"></a>00026 <span class="comment">* schreib  05/06/00  created</span>
+<a name="l00027"></a>00027 <span class="comment">*/</span>
+<a name="l00028"></a>00028 
+<a name="l00029"></a>00029 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00031"></a>00031 <span class="preprocessor">#endif</span>
+<a name="l00032"></a>00032 <span class="preprocessor"></span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include "sinfo_vltPort.h"</span>
+<a name="l00034"></a>00034 
+<a name="l00035"></a>00035 <span class="comment">/*</span>
+<a name="l00036"></a>00036 <span class="comment"> * System Headers</span>
+<a name="l00037"></a>00037 <span class="comment"> */</span>
+<a name="l00038"></a>00038 
+<a name="l00039"></a>00039 <span class="comment">/*</span>
+<a name="l00040"></a>00040 <span class="comment"> * Local Headers</span>
+<a name="l00041"></a>00041 <span class="comment"> */</span>
+<a name="l00042"></a>00042 
+<a name="l00043"></a>00043 <span class="preprocessor">#include "sinfo_recipes.h"</span>
+<a name="l00044"></a>00044 <span class="preprocessor">#include "sinfo_globals.h"</span>
+<a name="l00045"></a>00045 
+<a name="l00046"></a>00046 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00047"></a>00047 <span class="comment"> *                                    Local variables</span>
+<a name="l00048"></a>00048 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00049"></a>00049 
+<a name="l00050"></a>00050 <span class="keyword">static</span> <span class="keywordtype">float</span>  sqrarg ;
+<a name="l00051"></a>00051 
+<a name="l00052"></a>00052 <span class="keyword">static</span> <span class="keywordtype">double</span> chi1 ;                    <span class="comment">/* old reduced chi-squared */</span>
+<a name="l00053"></a>00053 <span class="keyword">static</span> <span class="keywordtype">double</span> sinfo_chi2 ;                    <span class="comment">/* new reduced chi-squared */</span>
+<a name="l00054"></a>00054 <span class="keyword">static</span> <span class="keywordtype">double</span> labda ;                   <span class="comment">/* mixing parameter */</span>
+<a name="l00055"></a>00055 <span class="keyword">static</span> <span class="keywordtype">double</span> vec[MAXPAR] ;             <span class="comment">/* correction sinfo_vector */</span>
+<a name="l00056"></a>00056 <span class="keyword">static</span> <span class="keywordtype">double</span> matrix1[MAXPAR][MAXPAR] ; <span class="comment">/* original sinfo_matrix */</span>
+<a name="l00057"></a>00057 <span class="keyword">static</span> <span class="keywordtype">double</span> matrix2[MAXPAR][MAXPAR] ; <span class="comment">/* inverse of matrix1 */</span>
+<a name="l00058"></a>00058 <span class="keyword">static</span> <span class="keywordtype">int</span>    nfree ;                   <span class="comment">/* number of free parameters */</span>
+<a name="l00059"></a>00059 <span class="keyword">static</span> <span class="keywordtype">int</span>    parptr[MAXPAR] ;          <span class="comment">/* parameter pointer */</span>
+<a name="l00060"></a>00060 
+<a name="l00061"></a>00061 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00062"></a>00062 <span class="comment"> *                                 Defines</span>
+<a name="l00063"></a>00063 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00064"></a>00064 
+<a name="l00065"></a>00065 <span class="preprocessor">#define SQR(a) (sqrarg = (a) , sqrarg*sqrarg)</span>
+<a name="l00066"></a>00066 <span class="preprocessor"></span>
+<a name="l00067"></a>00067 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00068"></a>00068 <span class="comment"> *                    Functions private to this module</span>
+<a name="l00069"></a>00069 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00070"></a>00070 
+<a name="l00071"></a>00071 
+<a name="l00072"></a>00072 <span class="keyword">static</span> <span class="keywordtype">int</span> new_inv_mat (<span class="keywordtype">void</span>) ;
+<a name="l00073"></a>00073 
+<a name="l00074"></a>00074 <span class="keyword">static</span> <span class="keywordtype">void</span> new_get_mat ( <span class="keywordtype">float</span>  * xdat,
+<a name="l00075"></a>00075                      <span class="keywordtype">int</span>    * xdim,
+<a name="l00076"></a>00076                      <span class="keywordtype">float</span>  * ydat,
+<a name="l00077"></a>00077                      <span class="keywordtype">float</span>  * wdat,
+<a name="l00078"></a>00078                      <span class="keywordtype">int</span>    * ndat,
+<a name="l00079"></a>00079                      <span class="keywordtype">float</span>  * fpar,
+<a name="l00080"></a>00080                      <span class="keywordtype">float</span>  * epar<span class="comment">/*,</span>
+<a name="l00081"></a>00081 <span class="comment">                     int    * npar */</span>) ;
+<a name="l00082"></a>00082 
+<a name="l00083"></a>00083 <span class="keyword">static</span> <span class="keywordtype">int</span> new_get_vec ( <span class="keywordtype">float</span>  * xdat,
+<a name="l00084"></a>00084                     <span class="keywordtype">int</span>    * xdim,
+<a name="l00085"></a>00085                     <span class="keywordtype">float</span>  * ydat,
+<a name="l00086"></a>00086                     <span class="keywordtype">float</span>  * wdat,
+<a name="l00087"></a>00087                     <span class="keywordtype">int</span>    * ndat,
+<a name="l00088"></a>00088                     <span class="keywordtype">float</span>  * fpar,
+<a name="l00089"></a>00089                     <span class="keywordtype">float</span>  * epar,
+<a name="l00090"></a>00090                     <span class="keywordtype">int</span>    * npar ) ;
+<a name="l00091"></a>00091 
+<a name="l00092"></a>00092 <span class="keyword">static</span> <span class="keywordtype">float</span> 
+<a name="l00093"></a>00093 new_gaussian ( <span class="keywordtype">float</span> * xdat, <span class="keywordtype">float</span> * parlist<span class="comment">/*, int * npar*/</span> );
+<a name="l00094"></a>00094 <span class="keyword">static</span> <span class="keywordtype">void</span> 
+<a name="l00095"></a>00095 new_gaussian_deriv( <span class="keywordtype">float</span> * xdat, <span class="keywordtype">float</span> * parlist, 
+<a name="l00096"></a>00096                     <span class="keywordtype">float</span> * dervs<span class="comment">/*, int * npar*/</span> );
+<a name="l00097"></a>00097 
+<a name="l00098"></a>00098 
+<a name="l00099"></a>00099 
+<a name="l00107"></a>00107 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00108"></a>00108 <span class="comment"> *                            Function codes</span>
+<a name="l00109"></a>00109 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00110"></a>00110 
+<a name="l00111"></a>00111 
+<a name="l00112"></a>00112 <span class="keywordtype">float</span> sinfo_new_f_median(<span class="keywordtype">float</span> * array, <span class="keywordtype">int</span> n)
+<a name="l00113"></a>00113 {
+<a name="l00114"></a>00114  pixelvalue p_array[100];
+<a name="l00115"></a>00115  <span class="keywordtype">int</span> i;
+<a name="l00116"></a>00116  
+<a name="l00117"></a>00117  <span class="keywordflow">for</span> (i=0;i<n;i++)
+<a name="l00118"></a>00118      p_array[i]= (pixelvalue) array[i];
+<a name="l00119"></a>00119 
+<a name="l00120"></a>00120  <span class="keywordflow">return</span> (<span class="keywordtype">float</span>) sinfo_new_median(p_array, n);
+<a name="l00121"></a>00121 }
+<a name="l00122"></a>00122 
+<a name="l00123"></a>00123 
+<a name="l00140"></a>00140 <span class="keywordtype">float</span> sinfo_new_clean_mean( <span class="keywordtype">float</span> * array, 
+<a name="l00141"></a>00141                   <span class="keywordtype">int</span>     n_elements,
+<a name="l00142"></a>00142                   <span class="keywordtype">float</span>   throwaway_low,
+<a name="l00143"></a>00143                   <span class="keywordtype">float</span>   throwaway_high )
+<a name="l00144"></a>00144 {
+<a name="l00145"></a>00145     <span class="keywordtype">int</span> i, n ;
+<a name="l00146"></a>00146     <span class="keywordtype">int</span> lo_n, hi_n ;
+<a name="l00147"></a>00147     <span class="keywordtype">float</span> sum ;
+<a name="l00148"></a>00148     
+<a name="l00149"></a>00149     <span class="keywordflow">if</span> ( array == NULL )
+<a name="l00150"></a>00150     {
+<a name="l00151"></a>00151         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" no array given in sinfo_clean_mean!"</span>) ;
+<a name="l00152"></a>00152         <span class="keywordflow">return</span> FLT_MAX ;
+<a name="l00153"></a>00153     }
+<a name="l00154"></a>00154   
+<a name="l00155"></a>00155     <span class="keywordflow">if</span> ( n_elements <= 0 )
+<a name="l00156"></a>00156     {
+<a name="l00157"></a>00157         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"wrong number of elements given"</span>) ;
+<a name="l00158"></a>00158         <span class="keywordflow">return</span> FLT_MAX ;
+<a name="l00159"></a>00159     }
+<a name="l00160"></a>00160 
+<a name="l00161"></a>00161     <span class="keywordflow">if</span> ( throwaway_low < 0. || throwaway_high < 0. ||
+<a name="l00162"></a>00162          throwaway_low + throwaway_high >= 100. )
+<a name="l00163"></a>00163     {
+<a name="l00164"></a>00164         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"wrong throw away percentage given!"</span>) ;
+<a name="l00165"></a>00165         <span class="keywordflow">return</span> FLT_MAX ;
+<a name="l00166"></a>00166     }
+<a name="l00167"></a>00167 
+<a name="l00168"></a>00168     lo_n = (int) (throwaway_low * (<span class="keywordtype">float</span>)n_elements / 100.) ;
+<a name="l00169"></a>00169     hi_n = (int) (throwaway_high * (<span class="keywordtype">float</span>)n_elements / 100.) ;
+<a name="l00170"></a>00170 
+<a name="l00171"></a>00171     <span class="comment">/* sort the array */</span>
+<a name="l00172"></a>00172     sinfo_pixel_qsort( array, n_elements ) ;
+<a name="l00173"></a>00173 
+<a name="l00174"></a>00174     n = 0 ;
+<a name="l00175"></a>00175     sum = 0. ;
+<a name="l00176"></a>00176     <span class="keywordflow">for</span> ( i = lo_n ; i < n_elements - hi_n ; i++ )
+<a name="l00177"></a>00177     {
+<a name="l00178"></a>00178         <span class="keywordflow">if</span> ( !isnan(array[i]) )
+<a name="l00179"></a>00179         {
+<a name="l00180"></a>00180             sum += array[i] ;
+<a name="l00181"></a>00181             n++ ;
+<a name="l00182"></a>00182         }
+<a name="l00183"></a>00183     }
+<a name="l00184"></a>00184     <span class="keywordflow">if</span> ( n == 0 )  
+<a name="l00185"></a>00185     {
+<a name="l00186"></a>00186         <span class="keywordflow">return</span> FLAG ;
+<a name="l00187"></a>00187     }
+<a name="l00188"></a>00188     <span class="keywordflow">else</span>
+<a name="l00189"></a>00189     {
+<a name="l00190"></a>00190         <span class="keywordflow">return</span> sum/(float)n ;
+<a name="l00191"></a>00191     }
+<a name="l00192"></a>00192 }
+<a name="l00193"></a>00193 
+<a name="l00194"></a>00194 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00207"></a>00207 pixelvalue sinfo_new_median(pixelvalue * array, <span class="keywordtype">int</span> n)
+<a name="l00208"></a>00208 {
+<a name="l00209"></a>00209     pixelvalue med ;
+<a name="l00210"></a>00210     
+<a name="l00211"></a>00211     <span class="keywordflow">if</span> ( array == NULL || n <= 0 )
+<a name="l00212"></a>00212     {
+<a name="l00213"></a>00213         <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"nothing in the pixelvalue array, ZERO returned"</span>);
+<a name="l00214"></a>00214         <span class="keywordflow">return</span> ZERO ;
+<a name="l00215"></a>00215     }
+<a name="l00216"></a>00216     
+<a name="l00217"></a>00217     <span class="keywordflow">if</span> ( n == 1 )
+<a name="l00218"></a>00218     {
+<a name="l00219"></a>00219         <span class="keywordflow">return</span> array[0] ;
+<a name="l00220"></a>00220     }
+<a name="l00221"></a>00221  
+<a name="l00222"></a>00222     sinfo_pixel_qsort((<span class="keywordtype">float</span>*) array, n) ;
+<a name="l00223"></a>00223     <span class="keywordflow">if</span> ( n % 2 == 1 )
+<a name="l00224"></a>00224     {
+<a name="l00225"></a>00225         med = array[n/2] ;
+<a name="l00226"></a>00226     }
+<a name="l00227"></a>00227     <span class="keywordflow">else</span>
+<a name="l00228"></a>00228     {
+<a name="l00229"></a>00229         med = (array[n/2] + array[n/2 - 1])/2. ;
+<a name="l00230"></a>00230     }
+<a name="l00231"></a>00231     <span class="keywordflow">return</span> med ;
+<a name="l00232"></a>00232 }
+<a name="l00233"></a>00233 
+<a name="l00234"></a>00234 
+<a name="l00235"></a>00235 
+<a name="l00236"></a>00236 
+<a name="l00237"></a>00237 
+<a name="l00285"></a>00285 <span class="keywordtype">int</span> sinfo_new_lsqfit_c ( <span class="keywordtype">float</span> * xdat,
+<a name="l00286"></a>00286                <span class="keywordtype">int</span>   * xdim,
+<a name="l00287"></a>00287                <span class="keywordtype">float</span> * ydat,
+<a name="l00288"></a>00288                <span class="keywordtype">float</span> * wdat,
+<a name="l00289"></a>00289                <span class="keywordtype">int</span>   * ndat,
+<a name="l00290"></a>00290                <span class="keywordtype">float</span> * fpar,
+<a name="l00291"></a>00291                <span class="keywordtype">float</span> * epar,
+<a name="l00292"></a>00292                <span class="keywordtype">int</span>   * mpar,
+<a name="l00293"></a>00293                <span class="keywordtype">int</span>   * npar,
+<a name="l00294"></a>00294                <span class="keywordtype">float</span> * tol ,
+<a name="l00295"></a>00295                <span class="keywordtype">int</span>   * its ,
+<a name="l00296"></a>00296                <span class="keywordtype">float</span> * lab  )
+<a name="l00297"></a>00297 {
+<a name="l00298"></a>00298     <span class="keywordtype">int</span> i, n, r ;
+<a name="l00299"></a>00299     <span class="keywordtype">int</span> itc ;                      <span class="comment">/* fate of fit */</span>
+<a name="l00300"></a>00300     <span class="keywordtype">int</span> found ;                    <span class="comment">/* fit converged: 1, not yet converged: 0 */</span>
+<a name="l00301"></a>00301     <span class="keywordtype">int</span>  nuse ;                    <span class="comment">/* number of useable data points */</span>
+<a name="l00302"></a>00302     <span class="keywordtype">double</span> tolerance ;             <span class="comment">/* accuracy */</span>
+<a name="l00303"></a>00303 
+<a name="l00304"></a>00304     itc   = 0 ;                    <span class="comment">/* fate of fit */</span>
+<a name="l00305"></a>00305     found = 0 ;                    <span class="comment">/* reset */</span>
+<a name="l00306"></a>00306     nfree = 0 ;                    <span class="comment">/* number of free parameters */</span>
+<a name="l00307"></a>00307     nuse  = 0 ;                    <span class="comment">/* number of legal data points */</span>
+<a name="l00308"></a>00308 
+<a name="l00309"></a>00309     <span class="keywordflow">if</span> ( *tol < (FLT_EPSILON * 10.0 ) )
+<a name="l00310"></a>00310     {
+<a name="l00311"></a>00311         tolerance = FLT_EPSILON * 10.0 ;  <span class="comment">/* default tolerance */</span>
+<a name="l00312"></a>00312     }
+<a name="l00313"></a>00313     <span class="keywordflow">else</span>
+<a name="l00314"></a>00314     {
+<a name="l00315"></a>00315         tolerance = *tol ;                <span class="comment">/* tolerance */</span>
+<a name="l00316"></a>00316     }
+<a name="l00317"></a>00317     
+<a name="l00318"></a>00318     labda = fabs( *lab ) * LABFAC ;   <span class="comment">/* start value for mixing parameter */</span>
+<a name="l00319"></a>00319     <span class="keywordflow">for</span> ( i = 0 ; i < (*npar) ; i++ )
+<a name="l00320"></a>00320     {
+<a name="l00321"></a>00321         <span class="keywordflow">if</span> ( mpar[i] )
+<a name="l00322"></a>00322         {
+<a name="l00323"></a>00323             <span class="keywordflow">if</span> ( nfree > MAXPAR )         <span class="comment">/* too many free parameters */</span>
+<a name="l00324"></a>00324             {
+<a name="l00325"></a>00325                 <span class="keywordflow">return</span> -1 ;
+<a name="l00326"></a>00326             }
+<a name="l00327"></a>00327             parptr[nfree++] = i ;         <span class="comment">/* a free parameter */</span>
+<a name="l00328"></a>00328         }
+<a name="l00329"></a>00329     }
+<a name="l00330"></a>00330     
+<a name="l00331"></a>00331     <span class="keywordflow">if</span> (nfree == 0)                       <span class="comment">/* no free parameters */</span>     
+<a name="l00332"></a>00332     {
+<a name="l00333"></a>00333         <span class="keywordflow">return</span> -2 ;
+<a name="l00334"></a>00334     }
+<a name="l00335"></a>00335     
+<a name="l00336"></a>00336     <span class="keywordflow">for</span> ( n = 0 ; n < (*ndat) ; n++ )
+<a name="l00337"></a>00337     {
+<a name="l00338"></a>00338         <span class="keywordflow">if</span> ( wdat[n] > 0.0 )              <span class="comment">/* legal weight */</span>
+<a name="l00339"></a>00339         {
+<a name="l00340"></a>00340             nuse ++ ;
+<a name="l00341"></a>00341         }
+<a name="l00342"></a>00342     }
+<a name="l00343"></a>00343     
+<a name="l00344"></a>00344     <span class="keywordflow">if</span> ( nfree >= nuse )
+<a name="l00345"></a>00345     {
+<a name="l00346"></a>00346         <span class="keywordflow">return</span> -3 ;                       <span class="comment">/* no degrees of freedom */</span>
+<a name="l00347"></a>00347     }
+<a name="l00348"></a>00348     <span class="keywordflow">if</span> ( labda == 0.0 )                   <span class="comment">/* linear fit */</span>
+<a name="l00349"></a>00349     {
+<a name="l00350"></a>00350         <span class="comment">/* initialize fpar array */</span>
+<a name="l00351"></a>00351         <span class="keywordflow">for</span> ( i = 0 ; i < nfree ; fpar[parptr[i++]] = 0.0 ) ;  
+<a name="l00352"></a>00352         new_get_mat ( xdat, xdim, ydat, wdat, ndat, fpar, epar<span class="comment">/*, npar*/</span> ) ;
+<a name="l00353"></a>00353         r =  new_get_vec ( xdat, xdim, ydat, wdat, ndat, fpar, epar, npar ) ;
+<a name="l00354"></a>00354         <span class="keywordflow">if</span> ( r )                         <span class="comment">/* error */</span>
+<a name="l00355"></a>00355         {
+<a name="l00356"></a>00356             <span class="keywordflow">return</span> r ;
+<a name="l00357"></a>00357         }
+<a name="l00358"></a>00358         <span class="keywordflow">for</span> ( i = 0 ; i < (*npar) ; i++ )
+<a name="l00359"></a>00359         {
+<a name="l00360"></a>00360             fpar[i] = epar[i] ;           <span class="comment">/* save new parameters */</span>
+<a name="l00361"></a>00361             epar[i] = 0.0 ;               <span class="comment">/* and set errors to zero */</span>
+<a name="l00362"></a>00362         }
+<a name="l00363"></a>00363         chi1 = sqrt( chi1 / (<span class="keywordtype">double</span>) (nuse - nfree) ) ;
+<a name="l00364"></a>00364         <span class="keywordflow">for</span> ( i = 0 ; i < nfree ; i++ )
+<a name="l00365"></a>00365         {
+<a name="l00366"></a>00366             <span class="keywordflow">if</span> ( (matrix1[i][i] <= 0.0 ) || (matrix2[i][i] <= 0.0) )
+<a name="l00367"></a>00367             {
+<a name="l00368"></a>00368                 <span class="keywordflow">return</span> -7 ;
+<a name="l00369"></a>00369             }
+<a name="l00370"></a>00370             epar[parptr[i]] = chi1 * sqrt( matrix2[i][i] ) / 
+<a name="l00371"></a>00371                                      sqrt( matrix1[i][i] ) ;
+<a name="l00372"></a>00372         }
+<a name="l00373"></a>00373     }
+<a name="l00374"></a>00374     <span class="keywordflow">else</span>                                  <span class="comment">/* non-linear fit */</span>
+<a name="l00375"></a>00375     {
+<a name="l00376"></a>00376         <span class="comment">/*----------------------------------------------------------------</span>
+<a name="l00377"></a>00377 <span class="comment">         * the non-linear fit uses the steepest descent method in combination</span>
+<a name="l00378"></a>00378 <span class="comment">         * with the Taylor method. The mixing of these methods is controlled</span>
+<a name="l00379"></a>00379 <span class="comment">         * by labda. In the outer loop ( called the iteration loop ) we build</span>
+<a name="l00380"></a>00380 <span class="comment">         * the matrix and calculate the correction vector. In the inner loop</span>
+<a name="l00381"></a>00381 <span class="comment">         * (called the interpolation loop) we check whether we have obtained a</span>
+<a name="l00382"></a>00382 <span class="comment">         * better solution than the previous one. If so, we leave the inner </span>
+<a name="l00383"></a>00383 <span class="comment">           loop else we increase labda (give more weight to the steepest </span>
+<a name="l00384"></a>00384 <span class="comment">           descent method) calculate the correction vector and check again. </span>
+<a name="l00385"></a>00385 <span class="comment">           After the inner loop we do a final check on the goodness of the </span>
+<a name="l00386"></a>00386 <span class="comment">           fit and if this satisfies</span>
+<a name="l00387"></a>00387 <span class="comment">         * the tolerance we calculate the errors of the fitted parameters.</span>
+<a name="l00388"></a>00388 <span class="comment">         */</span>
+<a name="l00389"></a>00389         <span class="keywordflow">while</span> ( !found )                  <span class="comment">/* iteration loop */</span>
+<a name="l00390"></a>00390         {      
+<a name="l00391"></a>00391             <span class="keywordflow">if</span> ( itc++ == (*its) )        <span class="comment">/* increase iteration counter */</span>
+<a name="l00392"></a>00392             {
+<a name="l00393"></a>00393                 <span class="keywordflow">return</span> -4 ;               
+<a name="l00394"></a>00394             }
+<a name="l00395"></a>00395             new_get_mat( xdat, xdim, ydat, wdat, ndat, fpar, epar<span class="comment">/*, npar */</span>) ;
+<a name="l00396"></a>00396             
+<a name="l00397"></a>00397             <span class="comment">/*-------------------------------------------------------------</span>
+<a name="l00398"></a>00398 <span class="comment">             * here we decrease labda since we may assume that each iteration</span>
+<a name="l00399"></a>00399 <span class="comment">             * brings us closer to the answer.</span>
+<a name="l00400"></a>00400 <span class="comment">             */</span>
+<a name="l00401"></a>00401             <span class="keywordflow">if</span> ( labda > LABMIN )
+<a name="l00402"></a>00402             {
+<a name="l00403"></a>00403                 labda = labda / LABFAC ;         <span class="comment">/* decrease labda */</span>
+<a name="l00404"></a>00404             }
+<a name="l00405"></a>00405             r = new_get_vec( xdat, xdim, ydat, wdat, ndat, fpar, epar, npar ) ;
+<a name="l00406"></a>00406             <span class="keywordflow">if</span> ( r )                      <span class="comment">/* error */</span>
+<a name="l00407"></a>00407             {
+<a name="l00408"></a>00408                 <span class="keywordflow">return</span> r ;
+<a name="l00409"></a>00409             }
+<a name="l00410"></a>00410 
+<a name="l00411"></a>00411             <span class="keywordflow">while</span> ( chi1 >= sinfo_chi2 )        <span class="comment">/* interpolation loop */</span>
+<a name="l00412"></a>00412             {
+<a name="l00413"></a>00413                 <span class="comment">/*-----------------------------------------------------------</span>
+<a name="l00414"></a>00414 <span class="comment">                 * The next statement is based on experience, not on the </span>
+<a name="l00415"></a>00415 <span class="comment">                   mathematics of the problem. It is assumed that we have </span>
+<a name="l00416"></a>00416 <span class="comment">                   reached convergence when the pure steepest descent method </span>
+<a name="l00417"></a>00417 <span class="comment">                   does not produce a better solution.</span>
+<a name="l00418"></a>00418 <span class="comment">                 */</span>
+<a name="l00419"></a>00419                 <span class="keywordflow">if</span> ( labda > LABMAX )    <span class="comment">/* assume solution found */</span>
+<a name="l00420"></a>00420                 {
+<a name="l00421"></a>00421                     break ;
+<a name="l00422"></a>00422                 }
+<a name="l00423"></a>00423                 labda = labda * LABFAC ;     <span class="comment">/* increase mixing parameter */</span>
+<a name="l00424"></a>00424                 r = new_get_vec(xdat,xdim,ydat,wdat,ndat,fpar,epar,npar) ;
+<a name="l00425"></a>00425                 <span class="keywordflow">if</span> ( r )                  <span class="comment">/* error */</span>
+<a name="l00426"></a>00426                 {
+<a name="l00427"></a>00427                     <span class="keywordflow">return</span> r ;
+<a name="l00428"></a>00428                 }
+<a name="l00429"></a>00429             }
+<a name="l00430"></a>00430 
+<a name="l00431"></a>00431             <span class="keywordflow">if</span> ( labda <= LABMAX )        <span class="comment">/* save old parameters */</span>
+<a name="l00432"></a>00432             {
+<a name="l00433"></a>00433                 <span class="keywordflow">for</span> ( i = 0 ; i < *npar ; i++ )
+<a name="l00434"></a>00434                 {
+<a name="l00435"></a>00435                     fpar[i] = epar[i] ;
+<a name="l00436"></a>00436                 }
+<a name="l00437"></a>00437             }
+<a name="l00438"></a>00438             <span class="keywordflow">if</span> ( (fabs( sinfo_chi2 - chi1 ) <= (tolerance * chi1)) || 
+<a name="l00439"></a>00439                  (labda > LABMAX) )
+<a name="l00440"></a>00440             {
+<a name="l00441"></a>00441                 <span class="comment">/*-------------------------------------------------------------</span>
+<a name="l00442"></a>00442 <span class="comment">                 * we have a satisfying solution, so now we need to calculate </span>
+<a name="l00443"></a>00443 <span class="comment">                   the correct errors of the fitted parameters. This we do by </span>
+<a name="l00444"></a>00444 <span class="comment">                   using the pure Taylor method because we are very close to </span>
+<a name="l00445"></a>00445 <span class="comment">                   the real solution.</span>
+<a name="l00446"></a>00446 <span class="comment">                 */</span>
+<a name="l00447"></a>00447                 labda = 0.0 ;              <span class="comment">/* for Taylor solution */</span>
+<a name="l00448"></a>00448                 new_get_mat(xdat,xdim,ydat,wdat,ndat,fpar,epar<span class="comment">/*, npar */</span>) ;
+<a name="l00449"></a>00449                 r = new_get_vec(xdat,xdim,ydat,wdat,ndat,fpar,epar,npar) ;
+<a name="l00450"></a>00450 
+<a name="l00451"></a>00451                 <span class="keywordflow">if</span> ( r )                    <span class="comment">/* error */</span>
+<a name="l00452"></a>00452                 {
+<a name="l00453"></a>00453                     <span class="keywordflow">return</span> r ;
+<a name="l00454"></a>00454                 }
+<a name="l00455"></a>00455                 <span class="keywordflow">for</span> ( i = 0 ; i < (*npar) ; i++ )
+<a name="l00456"></a>00456                 {
+<a name="l00457"></a>00457                     epar[i] = 0.0 ;          <span class="comment">/* set error to zero */</span>
+<a name="l00458"></a>00458                 }
+<a name="l00459"></a>00459                 sinfo_chi2 = sqrt ( sinfo_chi2 / (<span class="keywordtype">double</span>) (nuse - nfree) ) ;
+<a name="l00460"></a>00460 
+<a name="l00461"></a>00461                 <span class="keywordflow">for</span> ( i = 0 ; i < nfree ; i++ )
+<a name="l00462"></a>00462                 {
+<a name="l00463"></a>00463                     <span class="keywordflow">if</span> ( (matrix1[i][i] <= 0.0) || (matrix2[i][i] <= 0.0) )
+<a name="l00464"></a>00464                     {
+<a name="l00465"></a>00465                         <span class="keywordflow">return</span> -7 ;
+<a name="l00466"></a>00466                     }
+<a name="l00467"></a>00467                     epar[parptr[i]] = sinfo_chi2 * sqrt( matrix2[i][i] ) / 
+<a name="l00468"></a>00468                                                    sqrt( matrix1[i][i] ) ;
+<a name="l00469"></a>00469                 }
+<a name="l00470"></a>00470                 found = 1 ;                  <span class="comment">/* we found a solution */</span>
+<a name="l00471"></a>00471             }
+<a name="l00472"></a>00472         }
+<a name="l00473"></a>00473     }
+<a name="l00474"></a>00474     <span class="keywordflow">return</span> itc ;                             <span class="comment">/* return number of iterations */</span>
+<a name="l00475"></a>00475 }
+<a name="l00476"></a>00476 
+<a name="l00477"></a>00477 
+<a name="l00478"></a>00478 
+<a name="l00485"></a>00485 <span class="keywordtype">void</span> sinfo_new_convert_ZEROs_to_0_for_images(cpl_image * im)
+<a name="l00486"></a>00486 {
+<a name="l00487"></a>00487     <span class="keywordtype">int</span> i ;
+<a name="l00488"></a>00488     <span class="keywordtype">int</span> ilx=0;
+<a name="l00489"></a>00489     <span class="keywordtype">int</span> ily=0;
+<a name="l00490"></a>00490     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l00491"></a>00491 
+<a name="l00492"></a>00492     <span class="keywordflow">if</span> ( im == NULL )
+<a name="l00493"></a>00493     {
+<a name="l00494"></a>00494         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no input image given!\n"</span>) ; 
+<a name="l00495"></a>00495         return ;
+<a name="l00496"></a>00496     }
+<a name="l00497"></a>00497     ilx=cpl_image_get_size_x(im);
+<a name="l00498"></a>00498     ily=cpl_image_get_size_y(im);
+<a name="l00499"></a>00499     pidata=cpl_image_get_data(im);
+<a name="l00500"></a>00500     <span class="keywordflow">for</span> ( i = 0 ; i < (int) ilx*ily ; i++ )
+<a name="l00501"></a>00501     {
+<a name="l00502"></a>00502         <span class="keywordflow">if</span>( isnan(pidata[i]) )
+<a name="l00503"></a>00503         {
+<a name="l00504"></a>00504             pidata[i] = 0. ;
+<a name="l00505"></a>00505         }
+<a name="l00506"></a>00506     }
+<a name="l00507"></a>00507     return ;
+<a name="l00508"></a>00508 }
+<a name="l00509"></a>00509 
+<a name="l00518"></a>00518 <span class="keywordtype">void</span> sinfo_new_convert_ZEROs_to_0_for_cubes(cpl_imagelist * cube)
+<a name="l00519"></a>00519 {
+<a name="l00520"></a>00520     <span class="keywordtype">int</span> i ;
+<a name="l00521"></a>00521     <span class="keywordtype">int</span> inp=0;
+<a name="l00522"></a>00522     cpl_image* i_img=NULL;  
+<a name="l00523"></a>00523 
+<a name="l00524"></a>00524     <span class="keywordflow">if</span> ( cube == NULL )
+<a name="l00525"></a>00525     {
+<a name="l00526"></a>00526         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no input cube given!"</span>) ; 
+<a name="l00527"></a>00527         return ;
+<a name="l00528"></a>00528     }
+<a name="l00529"></a>00529     inp=cpl_imagelist_get_size(cube);
+<a name="l00530"></a>00530 
+<a name="l00531"></a>00531     <span class="keywordflow">for</span> ( i = 0 ; i < inp ; i++ )
+<a name="l00532"></a>00532     {
+<a name="l00533"></a>00533       i_img=cpl_imagelist_get(cube,i);
+<a name="l00534"></a>00534       sinfo_new_convert_ZEROs_to_0_for_images(i_img) ;
+<a name="l00535"></a>00535       cpl_imagelist_set(cube,i_img,i);
+<a name="l00536"></a>00536     }
+<a name="l00537"></a>00537     return ;
+<a name="l00538"></a>00538 }
+<a name="l00539"></a>00539 
+<a name="l00540"></a>00540 
+<a name="l00549"></a>00549 <span class="keywordtype">void</span> 
+<a name="l00550"></a>00550 sinfo_new_convert_ZEROs_to_0_for_cubes_range(cpl_imagelist * cube,
+<a name="l00551"></a>00551                                              <span class="keyword">const</span> <span class="keywordtype">int</span> z_min,<span class="keyword">const</span> <span class="keywordtype">int</span> z_max)
+<a name="l00552"></a>00552 {
+<a name="l00553"></a>00553     <span class="keywordtype">int</span> i ;
+<a name="l00554"></a>00554     cpl_image* i_img=NULL;  
+<a name="l00555"></a>00555 
+<a name="l00556"></a>00556     <span class="keywordflow">if</span> ( cube == NULL )
+<a name="l00557"></a>00557     {
+<a name="l00558"></a>00558         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no input cube given!"</span>) ; 
+<a name="l00559"></a>00559         return ;
+<a name="l00560"></a>00560     }
+<a name="l00561"></a>00561     <span class="keywordflow">for</span> ( i = z_min ; i < z_max ; i++ )
+<a name="l00562"></a>00562     {
+<a name="l00563"></a>00563       i_img=cpl_imagelist_get(cube,i);
+<a name="l00564"></a>00564       sinfo_new_convert_ZEROs_to_0_for_images(i_img) ;
+<a name="l00565"></a>00565       cpl_imagelist_set(cube,i_img,i);
+<a name="l00566"></a>00566     }
+<a name="l00567"></a>00567     return ;
+<a name="l00568"></a>00568 }
+<a name="l00575"></a>00575 <span class="keywordtype">void</span> sinfo_new_convert_0_to_ZEROs_for_images(cpl_image * im)
+<a name="l00576"></a>00576 {
+<a name="l00577"></a>00577     <span class="keywordtype">int</span> i ;
+<a name="l00578"></a>00578     <span class="keywordtype">int</span> ilx=0;
+<a name="l00579"></a>00579     <span class="keywordtype">int</span> ily=0;
+<a name="l00580"></a>00580     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l00581"></a>00581 
+<a name="l00582"></a>00582     <span class="keywordflow">if</span> ( im == NULL )
+<a name="l00583"></a>00583     {
+<a name="l00584"></a>00584         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no input image given!"</span>) ;
+<a name="l00585"></a>00585         return ;
+<a name="l00586"></a>00586     }
+<a name="l00587"></a>00587     ilx=cpl_image_get_size_x(im);
+<a name="l00588"></a>00588     ily=cpl_image_get_size_y(im);
+<a name="l00589"></a>00589     pidata=cpl_image_get_data(im);
+<a name="l00590"></a>00590     <span class="keywordflow">for</span> ( i = 0 ; i < (int) ilx*ily ; i++ )
+<a name="l00591"></a>00591     {
+<a name="l00592"></a>00592         <span class="keywordflow">if</span>( pidata[i] == 0. )
+<a name="l00593"></a>00593         {
+<a name="l00594"></a>00594             pidata[i] = ZERO ;
+<a name="l00595"></a>00595         }
+<a name="l00596"></a>00596     }
+<a name="l00597"></a>00597     return ;
+<a name="l00598"></a>00598 }
+<a name="l00599"></a>00599 
+<a name="l00606"></a>00606 <span class="keywordtype">void</span> sinfo_new_convert_0_to_ZERO_for_cubes(cpl_imagelist * cube)
+<a name="l00607"></a>00607 {
+<a name="l00608"></a>00608     <span class="keywordtype">int</span> i ;
+<a name="l00609"></a>00609     <span class="keywordtype">int</span> inp=0;
+<a name="l00610"></a>00610     cpl_image* i_img=NULL;
+<a name="l00611"></a>00611 
+<a name="l00612"></a>00612     <span class="keywordflow">if</span> ( cube == NULL )
+<a name="l00613"></a>00613     {
+<a name="l00614"></a>00614         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no input cube given!"</span>) ;
+<a name="l00615"></a>00615         return ;
+<a name="l00616"></a>00616     }
+<a name="l00617"></a>00617     inp=cpl_imagelist_get_size(cube);
+<a name="l00618"></a>00618     <span class="keywordflow">for</span> ( i = 0 ; i < inp ; i++ )
+<a name="l00619"></a>00619     {
+<a name="l00620"></a>00620       i_img=cpl_imagelist_get(cube,i);
+<a name="l00621"></a>00621       sinfo_new_convert_0_to_ZEROs_for_images(i_img) ;
+<a name="l00622"></a>00622       cpl_imagelist_set(cube,i_img,i);
+<a name="l00623"></a>00623     }
+<a name="l00624"></a>00624     return ;
+<a name="l00625"></a>00625 }
+<a name="l00626"></a>00626 
+<a name="l00627"></a>00627 
+<a name="l00636"></a>00636 <span class="keywordtype">void</span> 
+<a name="l00637"></a>00637 sinfo_new_convert_0_to_ZERO_for_cubes_range(cpl_imagelist * cube,
+<a name="l00638"></a>00638                                             <span class="keyword">const</span> <span class="keywordtype">int</span> z_min,<span class="keyword">const</span> <span class="keywordtype">int</span> z_max)
+<a name="l00639"></a>00639 {
+<a name="l00640"></a>00640     <span class="keywordtype">int</span> i ;
+<a name="l00641"></a>00641     <span class="keywordtype">int</span> inp=0;
+<a name="l00642"></a>00642     cpl_image* i_img=NULL;
+<a name="l00643"></a>00643 
+<a name="l00644"></a>00644     <span class="keywordflow">if</span> ( cube == NULL )
+<a name="l00645"></a>00645     {
+<a name="l00646"></a>00646         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no input cube given!"</span>) ;
+<a name="l00647"></a>00647         return ;
+<a name="l00648"></a>00648     }
+<a name="l00649"></a>00649     inp=cpl_imagelist_get_size(cube);
+<a name="l00650"></a>00650     <span class="keywordflow">for</span> ( i = z_min ; i < z_max ; i++ )
+<a name="l00651"></a>00651     {
+<a name="l00652"></a>00652       i_img=cpl_imagelist_get(cube,i);
+<a name="l00653"></a>00653       sinfo_new_convert_0_to_ZEROs_for_images(i_img) ;
+<a name="l00654"></a>00654       cpl_imagelist_set(cube,i_img,i);
+<a name="l00655"></a>00655     }
+<a name="l00656"></a>00656     return ;
+<a name="l00657"></a>00657 }
+<a name="l00664"></a>00664 <span class="keywordtype">void</span> sinfo_new_invert(cpl_image * im)
+<a name="l00665"></a>00665 {
+<a name="l00666"></a>00666     <span class="keywordtype">int</span> i ;
+<a name="l00667"></a>00667     <span class="keywordtype">int</span> ilx=0;
+<a name="l00668"></a>00668     <span class="keywordtype">int</span> ily=0;
+<a name="l00669"></a>00669     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l00670"></a>00670 
+<a name="l00671"></a>00671     ilx=cpl_image_get_size_x(im);
+<a name="l00672"></a>00672     ily=cpl_image_get_size_y(im);
+<a name="l00673"></a>00673     pidata=cpl_image_get_data(im);
+<a name="l00674"></a>00674 
+<a name="l00675"></a>00675     <span class="keywordflow">for</span> ( i = 0 ; i < (int) ilx*ily ; i++ )
+<a name="l00676"></a>00676     {
+<a name="l00677"></a>00677         pidata[i] = -pidata[i] ;
+<a name="l00678"></a>00678     }
+<a name="l00679"></a>00679     return ;
+<a name="l00680"></a>00680 }
+<a name="l00681"></a>00681 
+<a name="l00689"></a>00689 <span class="keywordtype">int</span> sinfo_new_nint ( <span class="keywordtype">double</span> x ) 
+<a name="l00690"></a>00690 {
+<a name="l00691"></a>00691     <span class="keywordtype">int</span> k ;
+<a name="l00692"></a>00692 
+<a name="l00693"></a>00693     k = x ;
+<a name="l00694"></a>00694     <span class="keywordflow">if</span> ( x >= 0. )
+<a name="l00695"></a>00695     {
+<a name="l00696"></a>00696         <span class="keywordflow">if</span> ( (x - (<span class="keywordtype">double</span>) k) <= 0.5 )
+<a name="l00697"></a>00697         {
+<a name="l00698"></a>00698             <span class="keywordflow">return</span> k ;
+<a name="l00699"></a>00699         }
+<a name="l00700"></a>00700         <span class="keywordflow">else</span>
+<a name="l00701"></a>00701         {
+<a name="l00702"></a>00702             <span class="keywordflow">return</span> k + 1 ;
+<a name="l00703"></a>00703         }
+<a name="l00704"></a>00704     }
+<a name="l00705"></a>00705     <span class="keywordflow">else</span>
+<a name="l00706"></a>00706     {
+<a name="l00707"></a>00707         <span class="keywordflow">if</span> ( (x - (<span class="keywordtype">double</span>) k) <= -0.5 )
+<a name="l00708"></a>00708         {
+<a name="l00709"></a>00709             <span class="keywordflow">return</span> k - 1;
+<a name="l00710"></a>00710         }
+<a name="l00711"></a>00711         <span class="keywordflow">else</span>
+<a name="l00712"></a>00712         {
+<a name="l00713"></a>00713             <span class="keywordflow">return</span> k ;
+<a name="l00714"></a>00714         }
+<a name="l00715"></a>00715     }
+<a name="l00716"></a>00716 }
+<a name="l00717"></a>00717 
+<a name="l00718"></a>00718 
+<a name="l00732"></a>00732 <span class="preprocessor">#define STEP_MIN        (-half_search)</span>
+<a name="l00733"></a>00733 <span class="preprocessor"></span><span class="preprocessor">#define STEP_MAX        (half_search)</span>
+<a name="l00734"></a>00734 <span class="preprocessor"></span>
+<a name="l00735"></a>00735 <span class="keywordtype">double</span> * sinfo_new_xcorrel(
+<a name="l00736"></a>00736     <span class="keywordtype">float</span>      *    line_i,
+<a name="l00737"></a>00737     <span class="keywordtype">int</span>             width_i,
+<a name="l00738"></a>00738     <span class="keywordtype">float</span>      *    line_t,
+<a name="l00739"></a>00739     <span class="keywordtype">int</span>             width_t,
+<a name="l00740"></a>00740     <span class="keywordtype">int</span>             half_search,
+<a name="l00741"></a>00741     <span class="keywordtype">int</span>     *       delta,
+<a name="l00742"></a>00742     <span class="keywordtype">int</span>       *     maxpos,
+<a name="l00743"></a>00743     <span class="keywordtype">double</span>     *    xcorr_max 
+<a name="l00744"></a>00744     
+<a name="l00745"></a>00745 )
+<a name="l00746"></a>00746 {
+<a name="l00747"></a>00747     <span class="keywordtype">double</span>  * xcorr ;
+<a name="l00748"></a>00748     <span class="keywordtype">double</span>   mean_i, mean_t ;
+<a name="l00749"></a>00749     <span class="keywordtype">double</span>   rms_i, rms_t ;
+<a name="l00750"></a>00750     <span class="keywordtype">double</span>   sum, sqsum ;
+<a name="l00751"></a>00751     <span class="keywordtype">double</span>   norm ;
+<a name="l00752"></a>00752     <span class="keywordtype">int</span>      nsteps ;
+<a name="l00753"></a>00753     <span class="keywordtype">int</span>      i ;
+<a name="l00754"></a>00754     <span class="keywordtype">int</span>      step ;
+<a name="l00755"></a>00755     <span class="keywordtype">int</span>      nval ;
+<a name="l00756"></a>00756     <span class="comment">/*double   r;*/</span>
+<a name="l00757"></a>00757 
+<a name="l00758"></a>00758 
+<a name="l00759"></a>00759     <span class="comment">/* Compute normalization factors */</span>
+<a name="l00760"></a>00760     sum = sqsum = 0.00 ;
+<a name="l00761"></a>00761     <span class="keywordflow">for</span> (i=0 ; i<width_i ; i++) {
+<a name="l00762"></a>00762         sum += (double)line_i[i] ;
+<a name="l00763"></a>00763         sqsum += (double)line_i[i] * (<span class="keywordtype">double</span>)line_i[i];
+<a name="l00764"></a>00764     }
+<a name="l00765"></a>00765     mean_i = sum / (double)width_i ;
+<a name="l00766"></a>00766     sqsum /= (double)width_i ;
+<a name="l00767"></a>00767     rms_i = sqsum - mean_i*mean_i ;
+<a name="l00768"></a>00768 
+<a name="l00769"></a>00769     sum = sqsum = 0.00 ;
+<a name="l00770"></a>00770     <span class="keywordflow">for</span> (i=0 ; i<width_t ; i++) {
+<a name="l00771"></a>00771         sum += (double)line_t[i] ;
+<a name="l00772"></a>00772         sqsum += (double)line_t[i] * (<span class="keywordtype">double</span>)line_t[i];
+<a name="l00773"></a>00773     }
+<a name="l00774"></a>00774     mean_t = sum / (double)width_t ;
+<a name="l00775"></a>00775     sqsum /= (double)width_t ;
+<a name="l00776"></a>00776     rms_t = sqsum - mean_t*mean_t ;
+<a name="l00777"></a>00777 
+<a name="l00778"></a>00778     norm = 1.00 / sqrt(rms_i * rms_t);
+<a name="l00779"></a>00779 
+<a name="l00780"></a>00780     nsteps = (STEP_MAX - STEP_MIN)  ;
+<a name="l00781"></a>00781     xcorr = cpl_malloc(nsteps * <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>));
+<a name="l00782"></a>00782     <span class="keywordflow">for</span> (step=STEP_MIN ; step<STEP_MAX ; step++) {
+<a name="l00783"></a>00783         xcorr[step-STEP_MIN] = 0.00 ;
+<a name="l00784"></a>00784         nval = 0 ;
+<a name="l00785"></a>00785         <span class="keywordflow">for</span> (i=0 ; i<width_t ; i++) {
+<a name="l00786"></a>00786             <span class="keywordflow">if</span> ((i+step >= 0) &&
+<a name="l00787"></a>00787                 (i+step < width_i)) {
+<a name="l00788"></a>00788             xcorr[step-STEP_MIN] += ((double)line_t[i] - mean_t) *
+<a name="l00789"></a>00789                                     ((double)line_i[i+step] - mean_i) *
+<a name="l00790"></a>00790                                     norm ;
+<a name="l00791"></a>00791                 nval++ ;
+<a name="l00792"></a>00792             }
+<a name="l00793"></a>00793         }
+<a name="l00794"></a>00794         xcorr[step-STEP_MIN] /= (double)nval ;
+<a name="l00795"></a>00795     }
+<a name="l00796"></a>00796     *xcorr_max = xcorr[0] ;
+<a name="l00797"></a>00797     *maxpos    = 0 ;
+<a name="l00798"></a>00798     <span class="keywordflow">for</span> (i=0 ; i<nsteps ; i++) {
+<a name="l00799"></a>00799         <span class="keywordflow">if</span> (xcorr[i]>*xcorr_max) {
+<a name="l00800"></a>00800             *maxpos = i ;
+<a name="l00801"></a>00801             *xcorr_max = xcorr[i];
+<a name="l00802"></a>00802         }
+<a name="l00803"></a>00803     }
+<a name="l00804"></a>00804     (*delta) = + (STEP_MIN + *maxpos);
+<a name="l00805"></a>00805     <span class="keywordflow">return</span> xcorr ;
+<a name="l00806"></a>00806 }
+<a name="l00807"></a>00807 
+<a name="l00808"></a>00808 <span class="comment">/* FILE ELEMENT: sinfo_nev_ille.c                                           */</span>
+<a name="l00809"></a>00809 <span class="comment">/*                                                                    */</span>
+<a name="l00810"></a>00810 <span class="comment">/**********************************************************************/</span>
+<a name="l00811"></a>00811 <span class="comment">/*                                                                    */</span>
+<a name="l00812"></a>00812 <span class="comment">/*                      double sinfo_nev_ille()                             */</span>
+<a name="l00813"></a>00813 <span class="comment">/*                                                                    */</span>
+<a name="l00814"></a>00814 <span class="comment">/**********************************************************************/</span>
+<a name="l00815"></a>00815 <span class="comment">/*                                                                    */</span>
+<a name="l00816"></a>00816 <span class="comment">/*  DESCRIPTION:                                                      */</span>
+<a name="l00817"></a>00817 <span class="comment">/*  For a given table (x , f(x )), i = 0(1)n  and a given argument z  */</span>
+<a name="l00818"></a>00818 <span class="comment">/*  the function computes the interpolated value for the argument z   */</span>
+<a name="l00819"></a>00819 <span class="comment">/*  using Neville's interpolation/ extrapolation algorithm.           */</span>
+<a name="l00820"></a>00820 <span class="comment">/*                                                                    */</span>
+<a name="l00821"></a>00821 <span class="comment">/*  FUNCTIONS CALLED:                                                 */</span>
+<a name="l00822"></a>00822 <span class="comment">/*  System library: <stdio.h> printf(), fabs();                       */</span>
+<a name="l00823"></a>00823 <span class="comment">/*  Numlib library: None                                              */</span>
+<a name="l00824"></a>00824 <span class="comment">/*  Local functions: nevtable();                                      */</span>
+<a name="l00825"></a>00825 <span class="comment">/*  User supplied: None                                               */</span>
+<a name="l00826"></a>00826 <span class="comment">/*                                                                    */</span>
+<a name="l00827"></a>00827 <span class="comment">/*  PROGRAMMED BY: T.Haavie                                           */</span>
+<a name="l00828"></a>00828 <span class="comment">/*  DATE/VERSION: 88-07-06/1.0                                        */</span>
+<a name="l00829"></a>00829 <span class="comment">/*                                                                    */</span>
+<a name="l00830"></a>00830 <span class="comment">/**********************************************************************/</span>
+<a name="l00831"></a>00831 <span class="keywordtype">double</span> sinfo_nev_ille(<span class="keywordtype">double</span> x[], <span class="keywordtype">double</span> f[], <span class="keywordtype">int</span> n, <span class="keywordtype">double</span> z, <span class="keywordtype">int</span>* flag)
+<a name="l00832"></a>00832                <span class="comment">/* PARAMETERS(input):                                  */</span>
+<a name="l00833"></a>00833 <span class="comment">/* double x[];     Abscissae values in the table.                      */</span>
+<a name="l00834"></a>00834 <span class="comment">/* double f[];     Function values in the table.                       */</span>
+<a name="l00835"></a>00835 <span class="comment">/* int n;         The number of elements in the table is n+1.         */</span>
+<a name="l00836"></a>00836 <span class="comment">/* double z;       Argument to be used in interpolation/extrapolation. */</span>
+<a name="l00837"></a>00837 
+<a name="l00838"></a>00838 
+<a name="l00839"></a>00839 <span class="comment">/*                PARAMETERS(input/output):                           */</span>
+<a name="l00840"></a>00840 <span class="comment">/* int *flag;    Flag parameter(output):                             */</span>
+<a name="l00841"></a>00841                <span class="comment">/* = 0, n < 0 and/or eps < 0, should be positive+.     */</span>
+<a name="l00842"></a>00842                <span class="comment">/* = 1, required rel.err. is not obtained.             */</span>
+<a name="l00843"></a>00843                <span class="comment">/* = 2, required rel. err. is obtained.                */</span>
+<a name="l00844"></a>00844 
+<a name="l00845"></a>00845 <span class="comment">/* the computed estimate for the interpolated/extrapolated  value re- */</span>
+<a name="l00846"></a>00846 <span class="comment">/* turned through function name sinfo_nev_ille.                             */</span>
+<a name="l00847"></a>00847 
+<a name="l00848"></a>00848 {
+<a name="l00849"></a>00849         <span class="keywordtype">double</span> p[11]; <span class="comment">/* Array used for storing the new row elements */</span>
+<a name="l00850"></a>00850                        <span class="comment">/* in the interpolation/extrapolation table.   */</span>
+<a name="l00851"></a>00851         <span class="keywordtype">double</span> q[11]; <span class="comment">/* Array used for storing the old row elements */</span>
+<a name="l00852"></a>00852                        <span class="comment">/* in the interpolation/extrapolation table    */</span>
+<a name="l00853"></a>00853 
+<a name="l00854"></a>00854         <span class="keywordtype">double</span> factor;
+<a name="l00855"></a>00855         <span class="keywordtype">int</span> m, k;
+<a name="l00856"></a>00856 
+<a name="l00857"></a>00857        
+<a name="l00858"></a>00858 
+<a name="l00859"></a>00859         <span class="keywordflow">if</span> (n < 0 )
+<a name="l00860"></a>00860         {
+<a name="l00861"></a>00861                 *flag = 0;
+<a name="l00862"></a>00862                 <span class="keywordflow">return</span>(0.);
+<a name="l00863"></a>00863         }
+<a name="l00864"></a>00864 
+<a name="l00865"></a>00865 
+<a name="l00866"></a>00866         q[0] = f[0];               <span class="comment">/* Set initial value in the table. */</span>
+<a name="l00867"></a>00867 
+<a name="l00868"></a>00868         <span class="keywordflow">for</span> (k = 1; k <= n; k++)   <span class="comment">/* k counts rows in the table.     */</span>
+<a name="l00869"></a>00869         {
+<a name="l00870"></a>00870                 p[0] = f[k];
+<a name="l00871"></a>00871                 <span class="keywordflow">for</span> (m = 1; m <= k; m++) <span class="comment">/* m counts element in row.  */</span>
+<a name="l00872"></a>00872                 {
+<a name="l00873"></a>00873                         factor = (z - x[k]) / (x[k] - x[k-m]);
+<a name="l00874"></a>00874                         p[m] = p[m-1] + factor * (p[m-1] - q[m-1]);
+<a name="l00875"></a>00875                 }
+<a name="l00876"></a>00876 
+<a name="l00877"></a>00877 
+<a name="l00878"></a>00878                 <span class="keywordflow">for</span> (m = 0; m <= k; m++) <span class="comment">/* Shift old row to new row.  */</span>
+<a name="l00879"></a>00879                         q[m] = p[m];
+<a name="l00880"></a>00880 
+<a name="l00881"></a>00881         } <span class="comment">/* End of k-loop. */</span>
+<a name="l00882"></a>00882 
+<a name="l00883"></a>00883         *flag = 1;              <span class="comment">/* Required rel.error is not obtained. */</span>
+<a name="l00884"></a>00884         <span class="keywordflow">return</span>(p[n]);
+<a name="l00885"></a>00885 
+<a name="l00886"></a>00886 } <span class="comment">/* End of sinfo_nev_ille(). */</span>
+<a name="l00887"></a>00887 
+<a name="l00888"></a>00888 
+<a name="l00889"></a>00889 
+<a name="l00890"></a>00890 <span class="keywordtype">float</span> sinfo_new_nev_ille(<span class="keywordtype">float</span> x[], <span class="keywordtype">float</span> f[], <span class="keywordtype">int</span> n, <span class="keywordtype">float</span> z, <span class="keywordtype">int</span>* flag)
+<a name="l00891"></a>00891                <span class="comment">/* PARAMETERS(input):                                  */</span>
+<a name="l00892"></a>00892 <span class="comment">/* float x[];     Abscissae values in the table.                      */</span>
+<a name="l00893"></a>00893 <span class="comment">/* float f[];     Function values in the table.                       */</span>
+<a name="l00894"></a>00894 <span class="comment">/* int n;         The number of elements in the table is n+1.         */</span>
+<a name="l00895"></a>00895 <span class="comment">/* float z;       Argument to be used in interpolation/extrapolation. */</span>
+<a name="l00896"></a>00896 
+<a name="l00897"></a>00897 
+<a name="l00898"></a>00898 <span class="comment">/*                PARAMETERS(input/output):                           */</span>
+<a name="l00899"></a>00899 <span class="comment">/* int *flag;    Flag parameter(output):                             */</span>
+<a name="l00900"></a>00900                <span class="comment">/* = 0, n < 0 and/or eps < 0, should be positive+.     */</span>
+<a name="l00901"></a>00901                <span class="comment">/* = 1, required rel.err. is not obtained.             */</span>
+<a name="l00902"></a>00902                <span class="comment">/* = 2, required rel. err. is obtained.                */</span>
+<a name="l00903"></a>00903 
+<a name="l00904"></a>00904 <span class="comment">/* the computed estimate for the interpolated/extrapolated  value re- */</span>
+<a name="l00905"></a>00905 <span class="comment">/* turned through function name sinfo_nev_ille.                             */</span>
+<a name="l00906"></a>00906 
+<a name="l00907"></a>00907 {
+<a name="l00908"></a>00908         <span class="keywordtype">float</span> p[11]; <span class="comment">/* Array used for storing the new row elements */</span>
+<a name="l00909"></a>00909                        <span class="comment">/* in the interpolation/extrapolation table.   */</span>
+<a name="l00910"></a>00910         <span class="keywordtype">float</span> q[11]; <span class="comment">/* Array used for storing the old row elements */</span>
+<a name="l00911"></a>00911                        <span class="comment">/* in the interpolation/extrapolation table    */</span>
+<a name="l00912"></a>00912 
+<a name="l00913"></a>00913         <span class="keywordtype">float</span> factor;
+<a name="l00914"></a>00914         <span class="keywordtype">int</span> m, k;
+<a name="l00915"></a>00915 
+<a name="l00916"></a>00916        
+<a name="l00917"></a>00917 
+<a name="l00918"></a>00918         <span class="keywordflow">if</span> (n < 0 )
+<a name="l00919"></a>00919         {
+<a name="l00920"></a>00920                 *flag = 0;
+<a name="l00921"></a>00921                 <span class="keywordflow">return</span>(0.);
+<a name="l00922"></a>00922         }
+<a name="l00923"></a>00923 
+<a name="l00924"></a>00924 
+<a name="l00925"></a>00925         q[0] = f[0];               <span class="comment">/* Set initial value in the table. */</span>
+<a name="l00926"></a>00926 
+<a name="l00927"></a>00927         <span class="keywordflow">for</span> (k = 1; k <= n; k++)   <span class="comment">/* k counts rows in the table.     */</span>
+<a name="l00928"></a>00928         {
+<a name="l00929"></a>00929                 p[0] = f[k];
+<a name="l00930"></a>00930                 <span class="keywordflow">for</span> (m = 1; m <= k; m++) <span class="comment">/* m counts element in row.  */</span>
+<a name="l00931"></a>00931                 {
+<a name="l00932"></a>00932                         factor = (z - x[k]) / (x[k] - x[k-m]);
+<a name="l00933"></a>00933                         p[m] = p[m-1] + factor * (p[m-1] - q[m-1]);
+<a name="l00934"></a>00934                 }
+<a name="l00935"></a>00935 
+<a name="l00936"></a>00936 
+<a name="l00937"></a>00937                 <span class="keywordflow">for</span> (m = 0; m <= k; m++) <span class="comment">/* Shift old row to new row.  */</span>
+<a name="l00938"></a>00938                         q[m] = p[m];
+<a name="l00939"></a>00939 
+<a name="l00940"></a>00940         } <span class="comment">/* End of k-loop. */</span>
+<a name="l00941"></a>00941 
+<a name="l00942"></a>00942         *flag = 1;              <span class="comment">/* Required rel.error is not obtained. */</span>
+<a name="l00943"></a>00943         <span class="keywordflow">return</span>(p[n]);
+<a name="l00944"></a>00944 
+<a name="l00945"></a>00945 } <span class="comment">/* End of sinfo_nev_ille(). */</span>
+<a name="l00946"></a>00946 
+<a name="l00947"></a>00947 
+<a name="l00972"></a>00972 <span class="keyword">static</span> <span class="keywordtype">int</span> new_get_vec ( <span class="keywordtype">float</span> * xdat,
+<a name="l00973"></a>00973                     <span class="keywordtype">int</span>   * xdim,
+<a name="l00974"></a>00974                     <span class="keywordtype">float</span> * ydat,
+<a name="l00975"></a>00975                     <span class="keywordtype">float</span> * wdat,
+<a name="l00976"></a>00976                     <span class="keywordtype">int</span>   * ndat,
+<a name="l00977"></a>00977                     <span class="keywordtype">float</span> * fpar,
+<a name="l00978"></a>00978                     <span class="keywordtype">float</span> * epar,
+<a name="l00979"></a>00979                     <span class="keywordtype">int</span>   * npar )
+<a name="l00980"></a>00980 {
+<a name="l00981"></a>00981     <span class="keywordtype">double</span> dj ;
+<a name="l00982"></a>00982     <span class="keywordtype">double</span> dy ;
+<a name="l00983"></a>00983     <span class="keywordtype">double</span> mii ;
+<a name="l00984"></a>00984     <span class="keywordtype">double</span> mji ;
+<a name="l00985"></a>00985     <span class="keywordtype">double</span> mjj ;
+<a name="l00986"></a>00986     <span class="keywordtype">double</span> wn ;
+<a name="l00987"></a>00987     <span class="keywordtype">int</span> i, j, n, r ;
+<a name="l00988"></a>00988 
+<a name="l00989"></a>00989     <span class="comment">/* loop to modify and scale the sinfo_matrix */</span>
+<a name="l00990"></a>00990     <span class="keywordflow">for</span> ( j = 0 ; j < nfree ; j++ )
+<a name="l00991"></a>00991     {
+<a name="l00992"></a>00992         mjj = matrix1[j][j] ;
+<a name="l00993"></a>00993         <span class="keywordflow">if</span> ( mjj <= 0.0 )             <span class="comment">/* diagonal element wrong */</span>
+<a name="l00994"></a>00994         {
+<a name="l00995"></a>00995             <span class="keywordflow">return</span> -5 ;
+<a name="l00996"></a>00996         }
+<a name="l00997"></a>00997         mjj = sqrt( mjj ) ;
+<a name="l00998"></a>00998         <span class="keywordflow">for</span> ( i = 0 ; i < j ; i++ )
+<a name="l00999"></a>00999         {
+<a name="l01000"></a>01000             mji = matrix1[j][i] / mjj / sqrt( matrix1[i][i] ) ;
+<a name="l01001"></a>01001             matrix2[i][j] = matrix2[j][i] = mji ;
+<a name="l01002"></a>01002         }
+<a name="l01003"></a>01003         matrix2[j][j] = 1.0 + labda ;  <span class="comment">/* scaled value on diagonal */</span>
+<a name="l01004"></a>01004     }    
+<a name="l01005"></a>01005     
+<a name="l01006"></a>01006     <span class="keywordflow">if</span> ( (r = new_inv_mat()) )       <span class="comment">/* sinfo_invert sinfo_matrix inlace */</span>
+<a name="l01007"></a>01007     {
+<a name="l01008"></a>01008         <span class="keywordflow">return</span> r ;
+<a name="l01009"></a>01009     }
+<a name="l01010"></a>01010     
+<a name="l01011"></a>01011     <span class="keywordflow">for</span> ( i = 0 ; i < (*npar) ; i ++ )
+<a name="l01012"></a>01012     {
+<a name="l01013"></a>01013         epar[i] = fpar[i] ;
+<a name="l01014"></a>01014     }
+<a name="l01015"></a>01015     
+<a name="l01016"></a>01016     <span class="comment">/* loop to calculate correction sinfo_vector */</span>
+<a name="l01017"></a>01017     <span class="keywordflow">for</span> ( j = 0 ; j < nfree ; j++ )
+<a name="l01018"></a>01018     {
+<a name="l01019"></a>01019         dj = 0.0 ;
+<a name="l01020"></a>01020         mjj = matrix1[j][j] ;
+<a name="l01021"></a>01021         <span class="keywordflow">if</span> ( mjj <= 0.0)               <span class="comment">/* not allowed */</span>
+<a name="l01022"></a>01022         {
+<a name="l01023"></a>01023             <span class="keywordflow">return</span> -7 ;
+<a name="l01024"></a>01024         }
+<a name="l01025"></a>01025         mjj = sqrt ( mjj ) ;
+<a name="l01026"></a>01026         <span class="keywordflow">for</span> ( i = 0 ; i < nfree ; i++ )
+<a name="l01027"></a>01027         {
+<a name="l01028"></a>01028             mii = matrix1[i][i] ;
+<a name="l01029"></a>01029             <span class="keywordflow">if</span> ( mii <= 0.0 )
+<a name="l01030"></a>01030             {
+<a name="l01031"></a>01031                 <span class="keywordflow">return</span> -7 ;
+<a name="l01032"></a>01032             }
+<a name="l01033"></a>01033             mii = sqrt( mii ) ;
+<a name="l01034"></a>01034             dj += vec[i] * matrix2[j][i] / mjj / mii ;
+<a name="l01035"></a>01035         }
+<a name="l01036"></a>01036         epar[parptr[j]] += dj ;       <span class="comment">/* new parameters */</span>
+<a name="l01037"></a>01037     }    
+<a name="l01038"></a>01038     chi1 = 0.0 ;                      <span class="comment">/* reset reduced chi-squared */</span>
+<a name="l01039"></a>01039  
+<a name="l01040"></a>01040     <span class="comment">/* loop through the data points */</span>
+<a name="l01041"></a>01041     <span class="keywordflow">for</span> ( n = 0 ; n < (*ndat) ; n++ )
+<a name="l01042"></a>01042     {
+<a name="l01043"></a>01043         wn = wdat[n] ;               <span class="comment">/* get weight */</span>
+<a name="l01044"></a>01044         <span class="keywordflow">if</span> ( wn > 0.0 )              <span class="comment">/* legal weight */</span>
+<a name="l01045"></a>01045         {
+<a name="l01046"></a>01046             dy = ydat[n] - new_gaussian( &xdat[(*xdim) * n], epar<span class="comment">/*, npar*/</span> ) ;
+<a name="l01047"></a>01047             chi1 += wdat[n] * dy * dy ;
+<a name="l01048"></a>01048         }
+<a name="l01049"></a>01049     }
+<a name="l01050"></a>01050     <span class="keywordflow">return</span> 0 ;
+<a name="l01051"></a>01051 }   
+<a name="l01052"></a>01052     
+<a name="l01053"></a>01053 
+<a name="l01069"></a>01069 <span class="keyword">static</span> <span class="keywordtype">void</span> new_get_mat ( <span class="keywordtype">float</span> * xdat,
+<a name="l01070"></a>01070                      <span class="keywordtype">int</span>   * xdim,
+<a name="l01071"></a>01071                      <span class="keywordtype">float</span> * ydat,
+<a name="l01072"></a>01072                      <span class="keywordtype">float</span> * wdat,
+<a name="l01073"></a>01073                      <span class="keywordtype">int</span>   * ndat,
+<a name="l01074"></a>01074                      <span class="keywordtype">float</span> * fpar,
+<a name="l01075"></a>01075                      <span class="keywordtype">float</span> * epar<span class="comment">/*,</span>
+<a name="l01076"></a>01076 <span class="comment">                     int   * npar */</span>)
+<a name="l01077"></a>01077 {
+<a name="l01078"></a>01078     <span class="keywordtype">double</span> wd ;
+<a name="l01079"></a>01079     <span class="keywordtype">double</span> wn ;
+<a name="l01080"></a>01080     <span class="keywordtype">double</span> yd ;
+<a name="l01081"></a>01081     <span class="keywordtype">int</span> i, j, n ;
+<a name="l01082"></a>01082 
+<a name="l01083"></a>01083     <span class="keywordflow">for</span> ( j = 0 ; j < nfree ; j++ )
+<a name="l01084"></a>01084     {
+<a name="l01085"></a>01085         vec[j] = 0.0 ; <span class="comment">/* zero sinfo_vector */</span>
+<a name="l01086"></a>01086         <span class="keywordflow">for</span> ( i = 0 ; i<= j ; i++ )   
+<a name="l01087"></a>01087         <span class="comment">/* zero sinfo_matrix only on and below diagonal */</span>
+<a name="l01088"></a>01088         {
+<a name="l01089"></a>01089             matrix1[j][i] = 0.0 ;
+<a name="l01090"></a>01090         }
+<a name="l01091"></a>01091     }
+<a name="l01092"></a>01092     sinfo_chi2 = 0.0 ;  <span class="comment">/* reset reduced chi-squared */</span>
+<a name="l01093"></a>01093     
+<a name="l01094"></a>01094     <span class="comment">/* loop through data points */</span>
+<a name="l01095"></a>01095     <span class="keywordflow">for</span> ( n = 0 ; n < (*ndat) ; n++ )
+<a name="l01096"></a>01096     {
+<a name="l01097"></a>01097         wn = wdat[n] ;
+<a name="l01098"></a>01098         <span class="keywordflow">if</span> ( wn > 0.0 )  <span class="comment">/* legal weight ? */</span>
+<a name="l01099"></a>01099         {
+<a name="l01100"></a>01100             yd = ydat[n] - new_gaussian( &xdat[(*xdim) * n], fpar<span class="comment">/*, npar*/</span> ) ;
+<a name="l01101"></a>01101             new_gaussian_deriv( &xdat[(*xdim) * n], fpar, epar<span class="comment">/*, npar*/</span> ) ;
+<a name="l01102"></a>01102             sinfo_chi2 += yd * yd * wn ; <span class="comment">/* add to chi-squared */</span>
+<a name="l01103"></a>01103             <span class="keywordflow">for</span> ( j = 0 ; j < nfree ; j++ )
+<a name="l01104"></a>01104             {
+<a name="l01105"></a>01105                 wd = epar[parptr[j]] * wn ;  <span class="comment">/* weighted derivative */</span>
+<a name="l01106"></a>01106                 vec[j] += yd * wd ;       <span class="comment">/* fill sinfo_vector */</span>
+<a name="l01107"></a>01107                 <span class="keywordflow">for</span> ( i = 0 ; i <= j ; i++ ) <span class="comment">/* fill sinfo_matrix */</span>
+<a name="l01108"></a>01108                 {
+<a name="l01109"></a>01109                     matrix1[j][i] += epar[parptr[i]] * wd ;
+<a name="l01110"></a>01110                 }
+<a name="l01111"></a>01111             }
+<a name="l01112"></a>01112         }
+<a name="l01113"></a>01113     }                   
+<a name="l01114"></a>01114 }  
+<a name="l01115"></a>01115    
+<a name="l01116"></a>01116 
+<a name="l01117"></a>01117 
+<a name="l01118"></a>01118 
+<a name="l01119"></a>01119 
+<a name="l01120"></a>01120  
+<a name="l01129"></a>01129 <span class="keyword">static</span> <span class="keywordtype">int</span> new_inv_mat (<span class="keywordtype">void</span>)
+<a name="l01130"></a>01130 {
+<a name="l01131"></a>01131     <span class="keywordtype">double</span> even ;
+<a name="l01132"></a>01132     <span class="keywordtype">double</span> hv[MAXPAR] ;
+<a name="l01133"></a>01133     <span class="keywordtype">double</span> mjk ;
+<a name="l01134"></a>01134     <span class="keywordtype">double</span> rowmax ;
+<a name="l01135"></a>01135     <span class="keywordtype">int</span> evin ;
+<a name="l01136"></a>01136     <span class="keywordtype">int</span> i, j, k, row ;
+<a name="l01137"></a>01137     <span class="keywordtype">int</span> per[MAXPAR] ;
+<a name="l01138"></a>01138    
+<a name="l01139"></a>01139     <span class="comment">/* set permutation array */</span>
+<a name="l01140"></a>01140     <span class="keywordflow">for</span> ( i = 0 ; i < nfree ; i++ )
+<a name="l01141"></a>01141     {
+<a name="l01142"></a>01142         per[i] = i ;
+<a name="l01143"></a>01143     }
+<a name="l01144"></a>01144     
+<a name="l01145"></a>01145     <span class="keywordflow">for</span> ( j = 0 ; j < nfree ; j++ ) <span class="comment">/* in j-th column */</span>
+<a name="l01146"></a>01146     {
+<a name="l01147"></a>01147         <span class="comment">/* determine largest element of a row */</span>                               
+<a name="l01148"></a>01148         rowmax = fabs ( matrix2[j][j] ) ;
+<a name="l01149"></a>01149         row = j ;                         
+<a name="l01150"></a>01150 
+<a name="l01151"></a>01151         <span class="keywordflow">for</span> ( i = j + 1 ; i < nfree ; i++ )
+<a name="l01152"></a>01152         {
+<a name="l01153"></a>01153             <span class="keywordflow">if</span> ( fabs ( matrix2[i][j] ) > rowmax )
+<a name="l01154"></a>01154             {
+<a name="l01155"></a>01155                 rowmax = fabs( matrix2[i][j] ) ;
+<a name="l01156"></a>01156                 row = i ;
+<a name="l01157"></a>01157             }
+<a name="l01158"></a>01158         }
+<a name="l01159"></a>01159 
+<a name="l01160"></a>01160         <span class="comment">/* determinant is zero! */</span>
+<a name="l01161"></a>01161         <span class="keywordflow">if</span> ( matrix2[row][j] == 0.0 )
+<a name="l01162"></a>01162         {
+<a name="l01163"></a>01163             <span class="keywordflow">return</span> -6 ;
+<a name="l01164"></a>01164         }
+<a name="l01165"></a>01165         
+<a name="l01166"></a>01166         <span class="comment">/*if the largest element is not on the diagonal, then permutate rows */</span>
+<a name="l01167"></a>01167         <span class="keywordflow">if</span> ( row > j )
+<a name="l01168"></a>01168         {
+<a name="l01169"></a>01169             <span class="keywordflow">for</span> ( k = 0 ; k < nfree ; k++ )
+<a name="l01170"></a>01170             {
+<a name="l01171"></a>01171                 even = matrix2[j][k] ;
+<a name="l01172"></a>01172                 matrix2[j][k] = matrix2[row][k] ;
+<a name="l01173"></a>01173                 matrix2[row][k] = even ;
+<a name="l01174"></a>01174             }
+<a name="l01175"></a>01175             <span class="comment">/* keep track of permutation */</span>
+<a name="l01176"></a>01176             evin = per[j] ;
+<a name="l01177"></a>01177             per[j] = per[row] ;
+<a name="l01178"></a>01178             per[row] = evin ;
+<a name="l01179"></a>01179         }
+<a name="l01180"></a>01180         
+<a name="l01181"></a>01181         <span class="comment">/* modify column */</span>
+<a name="l01182"></a>01182         even = 1.0 / matrix2[j][j] ;
+<a name="l01183"></a>01183         <span class="keywordflow">for</span> ( i = 0 ; i < nfree ; i++ )
+<a name="l01184"></a>01184         {
+<a name="l01185"></a>01185             matrix2[i][j] *= even ;
+<a name="l01186"></a>01186         }
+<a name="l01187"></a>01187         matrix2[j][j] = even ;
+<a name="l01188"></a>01188         
+<a name="l01189"></a>01189         <span class="keywordflow">for</span> ( k = 0 ; k < j ; k++ )
+<a name="l01190"></a>01190         {
+<a name="l01191"></a>01191             mjk = matrix2[j][k] ;
+<a name="l01192"></a>01192             <span class="keywordflow">for</span> ( i = 0 ; i < j ; i++ )
+<a name="l01193"></a>01193             {
+<a name="l01194"></a>01194                 matrix2[i][k] -= matrix2[i][j] * mjk ;
+<a name="l01195"></a>01195             }
+<a name="l01196"></a>01196             <span class="keywordflow">for</span> ( i = j + 1 ; i < nfree ; i++ )
+<a name="l01197"></a>01197             {
+<a name="l01198"></a>01198                 matrix2[i][k] -= matrix2[i][j] * mjk ;
+<a name="l01199"></a>01199             }
+<a name="l01200"></a>01200             matrix2[j][k] = -even * mjk ;
+<a name="l01201"></a>01201         }
+<a name="l01202"></a>01202     
+<a name="l01203"></a>01203         <span class="keywordflow">for</span> ( k = j + 1 ; k < nfree ; k++ )
+<a name="l01204"></a>01204         {
+<a name="l01205"></a>01205             mjk = matrix2[j][k] ;
+<a name="l01206"></a>01206             <span class="keywordflow">for</span> ( i = 0 ; i < j ; i++ )
+<a name="l01207"></a>01207             {
+<a name="l01208"></a>01208                 matrix2[i][k]  -= matrix2[i][j] * mjk ;
+<a name="l01209"></a>01209             }
+<a name="l01210"></a>01210             <span class="keywordflow">for</span> ( i = j + 1 ; i < nfree ; i++ )
+<a name="l01211"></a>01211             {
+<a name="l01212"></a>01212                 matrix2[i][k]  -= matrix2[i][j] * mjk ;
+<a name="l01213"></a>01213             }
+<a name="l01214"></a>01214             matrix2[j][k] = -even * mjk ;
+<a name="l01215"></a>01215         }
+<a name="l01216"></a>01216     }
+<a name="l01217"></a>01217     
+<a name="l01218"></a>01218     <span class="comment">/* finally, repermute the columns */</span>
+<a name="l01219"></a>01219     <span class="keywordflow">for</span> ( i = 0 ; i < nfree ; i++ )
+<a name="l01220"></a>01220     {
+<a name="l01221"></a>01221         <span class="keywordflow">for</span> ( k = 0 ; k < nfree ; k++ )
+<a name="l01222"></a>01222         {
+<a name="l01223"></a>01223             hv[per[k]] = matrix2[i][k] ;
+<a name="l01224"></a>01224         }
+<a name="l01225"></a>01225         <span class="keywordflow">for</span> ( k = 0 ; k < nfree ; k++ )
+<a name="l01226"></a>01226         {
+<a name="l01227"></a>01227             matrix2[i][k] = hv[k] ;
+<a name="l01228"></a>01228         }
+<a name="l01229"></a>01229     }
+<a name="l01230"></a>01230         
+<a name="l01231"></a>01231     <span class="comment">/* all is well */</span>
+<a name="l01232"></a>01232     <span class="keywordflow">return</span> 0 ;
+<a name="l01233"></a>01233 }       
+<a name="l01234"></a>01234 
+<a name="l01235"></a>01235 
+<a name="l01236"></a>01236 
+<a name="l01237"></a>01237 
+<a name="l01258"></a>01258 <span class="keywordtype">float</span> new_gaussian ( <span class="keywordtype">float</span> * xdat, <span class="keywordtype">float</span> * parlist<span class="comment">/*, int * npar*/</span> )
+<a name="l01259"></a>01259 {
+<a name="l01260"></a>01260     <span class="keywordtype">double</span>  xd ;  <span class="comment">/* FWHM's of gauss function */</span>
+<a name="l01261"></a>01261     <span class="keywordtype">double</span>   x ;  <span class="comment">/* position */</span>
+<a name="l01262"></a>01262 
+<a name="l01263"></a>01263     xd = fabs((<span class="keywordtype">double</span>) parlist[1]) ;
+<a name="l01264"></a>01264     x  = (double) xdat[0] - (<span class="keywordtype">double</span>) parlist[2] ;
+<a name="l01265"></a>01265     <span class="keywordflow">return</span> (<span class="keywordtype">float</span>) (
+<a name="l01266"></a>01266            (double) parlist[0] * exp( -4.0 * log(2.0) * (x/xd) * (x/xd) )
+<a name="l01267"></a>01267            + (<span class="keywordtype">double</span>) parlist[3] ) ;
+<a name="l01268"></a>01268 }
+<a name="l01269"></a>01269       
+<a name="l01270"></a>01270        
+<a name="l01295"></a>01295 <span class="keywordtype">void</span> 
+<a name="l01296"></a>01296 new_gaussian_deriv(<span class="keywordtype">float</span> * xdat,<span class="keywordtype">float</span> * parlist,<span class="keywordtype">float</span> * dervs<span class="comment">/*, int * npar*/</span> )
+<a name="l01297"></a>01297 {
+<a name="l01298"></a>01298     <span class="keywordtype">double</span> xd ; <span class="comment">/* FWHM of sinfo_gaussian */</span>
+<a name="l01299"></a>01299     <span class="keywordtype">double</span> x, expon ; <span class="comment">/* position and exponent */</span>
+<a name="l01300"></a>01300 
+<a name="l01301"></a>01301     xd = fabs( (<span class="keywordtype">double</span>) parlist[1] ) ;
+<a name="l01302"></a>01302     
+<a name="l01303"></a>01303     <span class="comment">/* offset from peak position */</span>
+<a name="l01304"></a>01304     x = (double) xdat[0] - (<span class="keywordtype">double</span>) parlist[2] ;
+<a name="l01305"></a>01305 
+<a name="l01306"></a>01306     <span class="comment">/* determine the derivatives: */</span>
+<a name="l01307"></a>01307     expon = -4.0 * log(2.0) * (x/xd) * (x/xd) ;
+<a name="l01308"></a>01308     expon = exp( expon ) ;
+<a name="l01309"></a>01309 
+<a name="l01310"></a>01310     <span class="comment">/* partial derivative by the amplitude */</span>
+<a name="l01311"></a>01311     dervs[0] = (float) expon ;
+<a name="l01312"></a>01312 
+<a name="l01313"></a>01313     <span class="comment">/* calculate a * exp(-arg) */</span>
+<a name="l01314"></a>01314     expon = (double) parlist[0] * expon ;
+<a name="l01315"></a>01315 
+<a name="l01316"></a>01316     <span class="comment">/* partial derivative by FWHM */</span>
+<a name="l01317"></a>01317     dervs[1] = (float) ( expon * 8.0 * log(2.0) * x*x / (xd*xd*xd) ) ;
+<a name="l01318"></a>01318 
+<a name="l01319"></a>01319     <span class="comment">/* partial derivative by the x position (parlist[2]) */</span>
+<a name="l01320"></a>01320     dervs[2] = (float) (expon * 8.0 * log(2.0) * x/(xd*xd) ) ;
+<a name="l01321"></a>01321 
+<a name="l01322"></a>01322     <span class="comment">/* partial derivative by the zero level */</span>
+<a name="l01323"></a>01323     dervs[3] = 1.0 ;
+<a name="l01324"></a>01324 }
+<a name="l01325"></a>01325 
+<a name="l01326"></a>01326 
+<a name="l01327"></a>01327 <span class="comment">/*==================================================================*/</span>
+<a name="l01328"></a>01328 
+<a name="l01329"></a>01329 
+<a name="l01349"></a>01349 <span class="keywordtype">void</span> 
+<a name="l01350"></a>01350 sinfo_my_fit(<span class="keywordtype">float</span> x[], <span class="keywordtype">float</span> y[], <span class="keywordtype">int</span> ndata, <span class="keywordtype">float</span> sig[], <span class="keywordtype">int</span> mwt, <span class="keywordtype">float</span> *a, 
+<a name="l01351"></a>01351            <span class="keywordtype">float</span> *b, <span class="keywordtype">float</span> *siga, <span class="keywordtype">float</span> *sigb, <span class="keywordtype">float</span> *chi2, <span class="keywordtype">float</span> *q)
+<a name="l01352"></a>01352 {
+<a name="l01353"></a>01353     <span class="keywordtype">int</span> i ;
+<a name="l01354"></a>01354     <span class="keywordtype">float</span> wt, t, sxoss, sx=0., sy=0., st2=0., ss, sigdat ;
+<a name="l01355"></a>01355 
+<a name="l01356"></a>01356     *b = 0. ;             <span class="comment">/*accumulate sums ...*/</span>
+<a name="l01357"></a>01357     <span class="keywordflow">if</span> ( mwt )
+<a name="l01358"></a>01358     {
+<a name="l01359"></a>01359         ss = 0. ;
+<a name="l01360"></a>01360         <span class="keywordflow">for</span> ( i = 0 ; i < ndata ; i++ )  <span class="comment">/*... with weights*/</span>
+<a name="l01361"></a>01361         {
+<a name="l01362"></a>01362             wt = 1./SQR(sig[i]) ;
+<a name="l01363"></a>01363             ss += wt ;
+<a name="l01364"></a>01364             sx += x[i]*wt ;
+<a name="l01365"></a>01365             sy += y[i]*wt ;
+<a name="l01366"></a>01366         }
+<a name="l01367"></a>01367     }
+<a name="l01368"></a>01368     <span class="keywordflow">else</span>
+<a name="l01369"></a>01369     {
+<a name="l01370"></a>01370         <span class="keywordflow">for</span> ( i = 0 ; i < ndata ; i++ ) <span class="comment">/*... or without weights*/</span>
+<a name="l01371"></a>01371         {
+<a name="l01372"></a>01372              sx += x[i] ;
+<a name="l01373"></a>01373              sy += y[i] ;
+<a name="l01374"></a>01374         }
+<a name="l01375"></a>01375         ss = ndata ;
+<a name="l01376"></a>01376     }
+<a name="l01377"></a>01377     sxoss = sx/ss ;
+<a name="l01378"></a>01378              
+<a name="l01379"></a>01379     <span class="keywordflow">if</span> ( mwt )
+<a name="l01380"></a>01380     {
+<a name="l01381"></a>01381         <span class="keywordflow">for</span> ( i = 0 ; i < ndata ; i ++ )
+<a name="l01382"></a>01382         {
+<a name="l01383"></a>01383             t = (x[i] - sxoss)/sig[i] ;
+<a name="l01384"></a>01384             st2 += t*t ;
+<a name="l01385"></a>01385             *b += t*y[i]/sig[i] ;
+<a name="l01386"></a>01386         }
+<a name="l01387"></a>01387     }
+<a name="l01388"></a>01388     <span class="keywordflow">else</span>
+<a name="l01389"></a>01389     {
+<a name="l01390"></a>01390         <span class="keywordflow">for</span> ( i = 0 ; i < ndata ; i++ )
+<a name="l01391"></a>01391         {
+<a name="l01392"></a>01392             t = x[i] - sxoss ;
+<a name="l01393"></a>01393             st2 += t*t ;
+<a name="l01394"></a>01394             *b += t*y[i] ;           
+<a name="l01395"></a>01395         }
+<a name="l01396"></a>01396     }
+<a name="l01397"></a>01397 
+<a name="l01398"></a>01398     *b /= st2 ;
+<a name="l01399"></a>01399     *a = (sy - sx*(*b))/ss ;
+<a name="l01400"></a>01400     *siga = sqrt ((1.0 + sx*sx/(ss*st2))/ss) ;
+<a name="l01401"></a>01401     *sigb = sqrt (1.0/st2) ;
+<a name="l01402"></a>01402     *chi2 = 0.0 ;  <span class="comment">/*calculate chi-square*/</span>
+<a name="l01403"></a>01403     <span class="keywordflow">if</span> ( mwt == 0 )
+<a name="l01404"></a>01404     {
+<a name="l01405"></a>01405         <span class="keywordflow">for</span> ( i = 0 ; i < ndata ; i++ )
+<a name="l01406"></a>01406         {
+<a name="l01407"></a>01407             *chi2 += SQR (y[i] - (*a) - (*b)*x[i]) ;
+<a name="l01408"></a>01408         }
+<a name="l01409"></a>01409         *q = 1. ;
+<a name="l01410"></a>01410         
+<a name="l01411"></a>01411         <span class="comment">/*------------------------------------------------------------------</span>
+<a name="l01412"></a>01412 <span class="comment">         * for unweighted data evaluate typical sig using chi2, and adjust</span>
+<a name="l01413"></a>01413 <span class="comment">         * the standard deviation</span>
+<a name="l01414"></a>01414 <span class="comment">         */</span>
+<a name="l01415"></a>01415         sigdat = sqrt ((*chi2)/(ndata - 2)) ;
+<a name="l01416"></a>01416         *siga *= sigdat ;
+<a name="l01417"></a>01417         *sigb *= sigdat ;
+<a name="l01418"></a>01418     }
+<a name="l01419"></a>01419     <span class="keywordflow">else</span>
+<a name="l01420"></a>01420     {
+<a name="l01421"></a>01421         <span class="keywordflow">for</span> (i = 0 ; i < ndata ; i++)
+<a name="l01422"></a>01422         {
+<a name="l01423"></a>01423             *chi2 += SQR ((y[i] - (*a) - (*b) * x[i])/sig[i]) ;
+<a name="l01424"></a>01424         }    
+<a name="l01425"></a>01425         *q = 1. ; <span class="comment">/* delete rest of lines. q is not a good value */</span>
+<a name="l01426"></a>01426     }
+<a name="l01427"></a>01427 }
+<a name="l01428"></a>01428 
+<a name="l01443"></a>01443 <span class="keywordtype">int</span> sinfo_new_correlation ( <span class="keywordtype">float</span> * data1, <span class="keywordtype">float</span> * data2, <span class="keywordtype">int</span> ndata )
+<a name="l01444"></a>01444 {
+<a name="l01445"></a>01445     <span class="comment">/*float help[3*ndata] ; </span>
+<a name="l01446"></a>01446 <span class="comment">    float corsum[3*ndata] ;*/</span>
+<a name="l01447"></a>01447     <span class="keywordtype">float</span>* help=NULL ; 
+<a name="l01448"></a>01448     <span class="keywordtype">float</span>* corsum=NULL ;
+<a name="l01449"></a>01449     <span class="keywordtype">float</span> maxval ;
+<a name="l01450"></a>01450     <span class="keywordtype">int</span> i, j, k, position, shift ;
+<a name="l01451"></a>01451     <span class="keywordtype">int</span> <span class="comment">/*start,end,size,*/</span>ndata3,limit;
+<a name="l01452"></a>01452     
+<a name="l01453"></a>01453     
+<a name="l01454"></a>01454     <span class="comment">/*ndata3=3*ndata;*/</span>
+<a name="l01455"></a>01455     ndata3=ndata+300;
+<a name="l01456"></a>01456 
+<a name="l01457"></a>01457     <span class="keywordflow">if</span> ( NULL == data1 || NULL == data2 || ndata <= 1 )
+<a name="l01458"></a>01458     {
+<a name="l01459"></a>01459         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" wrong input for sinfo_correlation\n"</span>) ;
+<a name="l01460"></a>01460         <span class="keywordflow">return</span> INT32_MAX ;
+<a name="l01461"></a>01461     }
+<a name="l01462"></a>01462 
+<a name="l01463"></a>01463     <span class="comment">/* initialize the help arrays with zeros */</span>
+<a name="l01464"></a>01464     help=cpl_calloc(ndata+300,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>));
+<a name="l01465"></a>01465     <span class="keywordflow">for</span> ( i = 0 ; i < ndata3 ; i++ )
+<a name="l01466"></a>01466     {
+<a name="l01467"></a>01467         help[i] = 0. ;
+<a name="l01468"></a>01468     }
+<a name="l01469"></a>01469 
+<a name="l01470"></a>01470     <span class="comment">/* shift the second data array by ndata in the help array */</span>
+<a name="l01471"></a>01471     <span class="keywordflow">for</span> ( i = 0 ; i < ndata ; i++ )
+<a name="l01472"></a>01472     {
+<a name="l01473"></a>01473         help[(300/2) + i] = data2[i] ;
+<a name="l01474"></a>01474     }
+<a name="l01475"></a>01475 
+<a name="l01476"></a>01476     <span class="comment">/* compute the cross sinfo_correlation sum array */</span>
+<a name="l01477"></a>01477     corsum=cpl_calloc(ndata+300,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>));
+<a name="l01478"></a>01478     <span class="keywordflow">for</span> ( j = 0 ; j < ndata3 ; j++ )
+<a name="l01479"></a>01479     {
+<a name="l01480"></a>01480         <span class="keywordflow">if</span> ( ndata3-j <= ndata) 
+<a name="l01481"></a>01481         limit = ndata3-j;
+<a name="l01482"></a>01482     <span class="keywordflow">else</span>
+<a name="l01483"></a>01483         limit = ndata;
+<a name="l01484"></a>01484         corsum[j] = 0. ;
+<a name="l01485"></a>01485         <span class="keywordflow">for</span> ( k = 0 ; k < limit ; k++ )
+<a name="l01486"></a>01486         {
+<a name="l01487"></a>01487             <span class="comment">/*if ( k + j >= ndata3 )</span>
+<a name="l01488"></a>01488 <span class="comment">            {</span>
+<a name="l01489"></a>01489 <span class="comment">                break ;</span>
+<a name="l01490"></a>01490 <span class="comment">            }*/</span>
+<a name="l01491"></a>01491             corsum[j] += data1[k] * help[k + j] ;
+<a name="l01492"></a>01492         }
+<a name="l01493"></a>01493     }
+<a name="l01494"></a>01494 
+<a name="l01495"></a>01495     <span class="comment">/* search for the maximal corsum value and determine its position */</span>
+<a name="l01496"></a>01496     maxval = -FLT_MAX ;
+<a name="l01497"></a>01497     position = -1 ;
+<a name="l01498"></a>01498     <span class="keywordflow">for</span> ( i = 0 ; i < ndata3 ; i++ )
+<a name="l01499"></a>01499     {
+<a name="l01500"></a>01500         <span class="keywordflow">if</span> ( maxval < corsum[i] )
+<a name="l01501"></a>01501         {
+<a name="l01502"></a>01502             maxval = corsum[i] ;
+<a name="l01503"></a>01503             position = i ;
+<a name="l01504"></a>01504         }
+<a name="l01505"></a>01505     }
+<a name="l01506"></a>01506     
+<a name="l01507"></a>01507     <span class="comment">/* determine shift of data2 relative to the data1 array */</span>
+<a name="l01508"></a>01508     shift = position - 300/2 ;
+<a name="l01509"></a>01509     cpl_free(help);
+<a name="l01510"></a>01510     cpl_free(corsum);
+<a name="l01511"></a>01511  
+<a name="l01512"></a>01512     <span class="keywordflow">return</span> shift ;
+<a name="l01513"></a>01513 }
+<a name="l01514"></a>01514 
+<a name="l01515"></a>01515 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__recipes_8h_source.html b/html/sinfo__recipes_8h_source.html
new file mode 100644
index 0000000..8e23a33
--- /dev/null
+++ b/html/sinfo__recipes_8h_source.html
@@ -0,0 +1,163 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_recipes.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_recipes.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#ifndef SINFO_RECIPES_H</span>
+<a name="l00002"></a>00002 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_RECIPES_H</span>
+<a name="l00003"></a>00003 <span class="preprocessor"></span><span class="comment">/*</span>
+<a name="l00004"></a>00004 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00005"></a>00005 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00006"></a>00006 <span class="comment"> *</span>
+<a name="l00007"></a>00007 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00008"></a>00008 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00009"></a>00009 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00010"></a>00010 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00011"></a>00011 <span class="comment"> *</span>
+<a name="l00012"></a>00012 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00013"></a>00013 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00014"></a>00014 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00015"></a>00015 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00016"></a>00016 <span class="comment"> *</span>
+<a name="l00017"></a>00017 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00018"></a>00018 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00019"></a>00019 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00020"></a>00020 <span class="comment"> */</span>
+<a name="l00021"></a>00021 <span class="comment">/*******************************************************************************</span>
+<a name="l00022"></a>00022 <span class="comment">* E.S.O. - VLT project</span>
+<a name="l00023"></a>00023 <span class="comment">*</span>
+<a name="l00024"></a>00024 <span class="comment">* "@(#) $Id: sinfo_recipes.h,v 1.7 2008/02/12 13:29:09 amodigli Exp $"</span>
+<a name="l00025"></a>00025 <span class="comment">*</span>
+<a name="l00026"></a>00026 <span class="comment">* who       when      what</span>
+<a name="l00027"></a>00027 <span class="comment">* --------  --------  ----------------------------------------------</span>
+<a name="l00028"></a>00028 <span class="comment">* schreib  05/06/00  created</span>
+<a name="l00029"></a>00029 <span class="comment">*/</span>
+<a name="l00030"></a>00030 
+<a name="l00031"></a>00031 <span class="comment">/************************************************************************</span>
+<a name="l00032"></a>00032 <span class="comment"> * recipes.h</span>
+<a name="l00033"></a>00033 <span class="comment"> * some numerical recipes</span>
+<a name="l00034"></a>00034 <span class="comment"> *----------------------------------------------------------------------</span>
+<a name="l00035"></a>00035 <span class="comment"> */</span>
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="comment">/*</span>
+<a name="l00038"></a>00038 <span class="comment"> * header files</span>
+<a name="l00039"></a>00039 <span class="comment"> */</span>
+<a name="l00040"></a>00040 
+<a name="l00041"></a>00041 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include <inttypes.h></span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include <float.h></span>
+<a name="l00044"></a>00044 <span class="preprocessor">#include <math.h></span>
+<a name="l00045"></a>00045 <span class="preprocessor">#include "sinfo_pixel_handling.h"</span>
+<a name="l00046"></a>00046 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00047"></a>00047 
+<a name="l00048"></a>00048 
+<a name="l00049"></a>00049 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00050"></a>00050 <span class="comment"> *                        defines</span>
+<a name="l00051"></a>00051 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00052"></a>00052 <span class="comment">/* definitions of initial values for sinfo_lsqfit_c in sinfo_linefit() </span>
+<a name="l00053"></a>00053 <span class="comment">   (wave_calibration) */</span>
+<a name="l00054"></a>00054 <span class="preprocessor">#define XDIM         1         </span><span class="comment">/* dimension of the x values */</span>
+<a name="l00055"></a>00055 <span class="preprocessor">#define TOL          0.001     </span><span class="comment">/* fitting tolerance */</span>
+<a name="l00056"></a>00056 <span class="preprocessor">#define LAB          0.1       </span><span class="comment">/* labda parameter */</span>
+<a name="l00057"></a>00057 <span class="preprocessor">#define ITS          200       </span><span class="comment">/* maximum number of iterations */</span>
+<a name="l00058"></a>00058 <span class="preprocessor">#define MAXPAR       4         </span><span class="comment">/* number of free parameters */</span>
+<a name="l00059"></a>00059 <span class="preprocessor">#define LABFAC       10.0      </span><span class="comment">/* labda step factor */</span>
+<a name="l00060"></a>00060 <span class="preprocessor">#define LABMAX       1.0e+10   </span><span class="comment">/* maximum value for labda */</span>
+<a name="l00061"></a>00061 <span class="preprocessor">#define LABMIN       1.0e-10   </span><span class="comment">/* minimum value for labda */</span>
+<a name="l00062"></a>00062 
+<a name="l00063"></a>00063 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00064"></a>00064 <span class="comment"> *                        Function ANSI C prototypes</span>
+<a name="l00065"></a>00065 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00066"></a>00066 <span class="keywordtype">double</span> sinfo_nev_ille(<span class="keywordtype">double</span> x[], <span class="keywordtype">double</span> f[], <span class="keywordtype">int</span> n, <span class="keywordtype">double</span> z, <span class="keywordtype">int</span>* flag);
+<a name="l00067"></a>00067 
+<a name="l00068"></a>00068 <span class="keywordtype">float</span> 
+<a name="l00069"></a>00069 sinfo_new_f_median(<span class="keywordtype">float</span> * array, <span class="keywordtype">int</span> n);
+<a name="l00070"></a>00070 
+<a name="l00071"></a>00071 <span class="keywordtype">float</span> 
+<a name="l00072"></a>00072 sinfo_new_clean_mean( <span class="keywordtype">float</span> * array,
+<a name="l00073"></a>00073                   <span class="keywordtype">int</span>     n_elements,
+<a name="l00074"></a>00074                   <span class="keywordtype">float</span>   throwaway_low,
+<a name="l00075"></a>00075                   <span class="keywordtype">float</span>   throwaway_high ) ;
+<a name="l00076"></a>00076 
+<a name="l00077"></a>00077 
+<a name="l00088"></a>00088 pixelvalue 
+<a name="l00089"></a>00089 sinfo_new_median(pixelvalue * array, <span class="keywordtype">int</span> n) ;
+<a name="l00134"></a>00134 <span class="keywordtype">int</span> sinfo_new_lsqfit_c ( <span class="keywordtype">float</span>  * xdat,
+<a name="l00135"></a>00135                <span class="keywordtype">int</span>    * xdim,
+<a name="l00136"></a>00136                <span class="keywordtype">float</span>  * ydat,
+<a name="l00137"></a>00137                <span class="keywordtype">float</span>  * wdat,
+<a name="l00138"></a>00138                <span class="keywordtype">int</span>    * ndat,
+<a name="l00139"></a>00139                <span class="keywordtype">float</span>  * fpar,
+<a name="l00140"></a>00140                <span class="keywordtype">float</span>  * epar,
+<a name="l00141"></a>00141                <span class="keywordtype">int</span>    * mpar,
+<a name="l00142"></a>00142                <span class="keywordtype">int</span>    * npar,
+<a name="l00143"></a>00143                <span class="keywordtype">float</span>  * tol ,
+<a name="l00144"></a>00144                <span class="keywordtype">int</span>    * its ,
+<a name="l00145"></a>00145                <span class="keywordtype">float</span>  * lab  ) ;
+<a name="l00146"></a>00146 
+<a name="l00163"></a>00163 <span class="keywordtype">void</span> 
+<a name="l00164"></a>00164 sinfo_my_fit (<span class="keywordtype">float</span> x[], <span class="keywordtype">float</span> y[], <span class="keywordtype">int</span> ndata, <span class="keywordtype">float</span> sig[], <span class="keywordtype">int</span> mwt, <span class="keywordtype">float</span> *a,
+<a name="l00165"></a>00165            <span class="keywordtype">float</span> *b, <span class="keywordtype">float</span> *siga, <span class="keywordtype">float</span> *sigb, <span class="keywordtype">float</span> *chi2, <span class="keywordtype">float</span> *q) ;
+<a name="l00166"></a>00166 
+<a name="l00174"></a>00174 <span class="keywordtype">int</span> 
+<a name="l00175"></a>00175 sinfo_new_nint ( <span class="keywordtype">double</span> x ) ;
+<a name="l00176"></a>00176 
+<a name="l00190"></a>00190 <span class="keywordtype">int</span> 
+<a name="l00191"></a>00191 sinfo_new_correlation ( <span class="keywordtype">float</span> * data1, <span class="keywordtype">float</span> * data2, <span class="keywordtype">int</span> ndata ) ;
+<a name="l00192"></a>00192 
+<a name="l00200"></a>00200 <span class="keywordtype">void</span> 
+<a name="l00201"></a>00201 sinfo_new_convert_ZEROs_to_0_for_images(cpl_image * im) ;
+<a name="l00202"></a>00202 
+<a name="l00210"></a>00210 <span class="keywordtype">void</span> 
+<a name="l00211"></a>00211 sinfo_new_convert_ZEROs_to_0_for_cubes_range(cpl_imagelist * cube,
+<a name="l00212"></a>00212                                              <span class="keyword">const</span> <span class="keywordtype">int</span> z_min,
+<a name="l00213"></a>00213                                              <span class="keyword">const</span> <span class="keywordtype">int</span> z_max);
+<a name="l00214"></a>00214 
+<a name="l00224"></a>00224 <span class="keywordtype">void</span> 
+<a name="l00225"></a>00225 sinfo_new_convert_0_to_ZERO_for_cubes_range(cpl_imagelist * cube,
+<a name="l00226"></a>00226                                             <span class="keyword">const</span> <span class="keywordtype">int</span> z_min,
+<a name="l00227"></a>00227                                             <span class="keyword">const</span> <span class="keywordtype">int</span> z_max);
+<a name="l00235"></a>00235 <span class="keywordtype">void</span> 
+<a name="l00236"></a>00236 sinfo_new_convert_ZEROs_to_0_for_cubes(cpl_imagelist * cube) ;
+<a name="l00237"></a>00237 
+<a name="l00238"></a>00238 
+<a name="l00246"></a>00246 <span class="keywordtype">void</span> 
+<a name="l00247"></a>00247 sinfo_new_convert_0_to_ZEROs_for_images(cpl_image * im) ;
+<a name="l00248"></a>00248 
+<a name="l00256"></a>00256 <span class="keywordtype">void</span> 
+<a name="l00257"></a>00257 sinfo_new_convert_0_to_ZERO_for_cubes(cpl_imagelist * cube) ;
+<a name="l00258"></a>00258 
+<a name="l00266"></a>00266 <span class="keywordtype">void</span> sinfo_new_invert(cpl_image * im) ;
+<a name="l00267"></a>00267 
+<a name="l00268"></a>00268 
+<a name="l00283"></a>00283 <span class="keywordtype">double</span> * 
+<a name="l00284"></a>00284 sinfo_new_xcorrel(
+<a name="l00285"></a>00285     <span class="keywordtype">float</span>      *    line_i,
+<a name="l00286"></a>00286     <span class="keywordtype">int</span>             width_i,
+<a name="l00287"></a>00287     <span class="keywordtype">float</span>      *    line_t,
+<a name="l00288"></a>00288     <span class="keywordtype">int</span>             width_t,
+<a name="l00289"></a>00289     <span class="keywordtype">int</span>             half_search,
+<a name="l00290"></a>00290     <span class="keywordtype">int</span>     *       delta,
+<a name="l00291"></a>00291     <span class="keywordtype">int</span>        *    maxpos,
+<a name="l00292"></a>00292     <span class="keywordtype">double</span>     *    xcorr_max
+<a name="l00293"></a>00293 
+<a name="l00294"></a>00294 ) ;
+<a name="l00295"></a>00295 
+<a name="l00296"></a>00296 <span class="keywordtype">float</span> 
+<a name="l00297"></a>00297 sinfo_new_nev_ille(<span class="keywordtype">float</span> [], <span class="keywordtype">float</span> [], <span class="keywordtype">int</span>, <span class="keywordtype">float</span>, <span class="keywordtype">int</span> *);
+<a name="l00298"></a>00298 
+<a name="l00299"></a>00299 
+<a name="l00300"></a>00300 <span class="preprocessor">#endif </span>
+<a name="l00302"></a>00302 <span class="preprocessor"></span><span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00303"></a>00303 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__ref__types_8h_source.html b/html/sinfo__ref__types_8h_source.html
new file mode 100644
index 0000000..2722882
--- /dev/null
+++ b/html/sinfo__ref__types_8h_source.html
@@ -0,0 +1,61 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_ref_types.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_ref_types.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_ref_types.h,v 1.4 2010/02/12 17:56:53 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the SINFONI Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This proram is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2010/02/12 17:56:53 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.4 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifndef SINFO_REF_TYPES_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_REF_TYPES_H</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span>CPL_BEGIN_DECLS
+<a name="l00031"></a>00031 <span class="comment">/* reference frames */</span>
+<a name="l00032"></a>00032 
+<a name="l00033"></a>00033 <span class="preprocessor">#define RAW_REF                            "REF"</span>
+<a name="l00034"></a>00034 <span class="preprocessor"></span><span class="preprocessor">#define REF_LINE_ARC                       "REF_LINE_ARC"</span>
+<a name="l00035"></a>00035 <span class="preprocessor"></span><span class="preprocessor">#define REF_BP_MAP                         "REF_BP_MAP"</span>
+<a name="l00036"></a>00036 <span class="preprocessor"></span><span class="preprocessor">#define REF_SLIT_POS                       "REF_SLIT_POS"</span>
+<a name="l00037"></a>00037 <span class="preprocessor"></span><span class="preprocessor">#define DRS_SETUP_WAVE                     "DRS_SETUP_WAVE"</span>
+<a name="l00038"></a>00038 <span class="preprocessor"></span><span class="preprocessor">#define EXTCOEFF_TABLE                     "EXTCOEFF_TABLE"</span>
+<a name="l00039"></a>00039 <span class="preprocessor"></span><span class="preprocessor">#define FLUX_STD_TABLE                     "FLUX_STD_TABLE"</span>
+<a name="l00040"></a>00040 <span class="preprocessor"></span><span class="comment">/* catalog of flux of standard stars*/</span>
+<a name="l00041"></a>00041 <span class="preprocessor">#define FLUX_STD_CATALOG           "FLUX_STD_CATALOG"</span>
+<a name="l00042"></a>00042 <span class="preprocessor"></span>
+<a name="l00043"></a>00043 CPL_END_DECLS
+<a name="l00044"></a>00044 
+<a name="l00045"></a>00045 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__remove__crh__single_8c_source.html b/html/sinfo__remove__crh__single_8c_source.html
new file mode 100644
index 0000000..f2d0664
--- /dev/null
+++ b/html/sinfo__remove__crh__single_8c_source.html
@@ -0,0 +1,483 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_remove_crh_single.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_remove_crh_single.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*                                                                            *</span>
+<a name="l00002"></a>00002 <span class="comment"> *   This file is part of the ESO X-shooter Pipeline                          *</span>
+<a name="l00003"></a>00003 <span class="comment"> *   Copyright (C) 2006 European Southern Observatory                         *</span>
+<a name="l00004"></a>00004 <span class="comment"> *                                                                            *</span>
+<a name="l00005"></a>00005 <span class="comment"> *   This library is free software; you can redistribute it and/or modify     *</span>
+<a name="l00006"></a>00006 <span class="comment"> *   it under the terms of the GNU General Public License as published by     *</span>
+<a name="l00007"></a>00007 <span class="comment"> *   the Free Software Foundation; either version 2 of the License, or        *</span>
+<a name="l00008"></a>00008 <span class="comment"> *   (at your option) any later version.                                      *</span>
+<a name="l00009"></a>00009 <span class="comment"> *                                                                            *</span>
+<a name="l00010"></a>00010 <span class="comment"> *   This program is distributed in the hope that it will be useful,          *</span>
+<a name="l00011"></a>00011 <span class="comment"> *   but WITHOUT ANY WARRANTY; without even the implied warranty of           *</span>
+<a name="l00012"></a>00012 <span class="comment"> *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *</span>
+<a name="l00013"></a>00013 <span class="comment"> *   GNU General Public License for more details.                             *</span>
+<a name="l00014"></a>00014 <span class="comment"> *                                                                            *</span>
+<a name="l00015"></a>00015 <span class="comment"> *   You should have received a copy of the GNU General Public License        *</span>
+<a name="l00016"></a>00016 <span class="comment"> *   along with this program; if not, write to the Free Software              *</span>
+<a name="l00017"></a>00017 <span class="comment"> *   Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA     *</span>
+<a name="l00018"></a>00018 <span class="comment"> *                                                                            */</span>
+<a name="l00019"></a>00019 
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"></span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2012/03/03 10:18:26 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.5 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Log: sinfo_remove_crh_single.c,v $</span>
+<a name="l00026"></a>00026 <span class="comment"> * Revision 1.5  2012/03/03 10:18:26  amodigli</span>
+<a name="l00027"></a>00027 <span class="comment"> * fixed some doxygen warnings</span>
+<a name="l00028"></a>00028 <span class="comment"> *</span>
+<a name="l00029"></a>00029 <span class="comment"> * Revision 1.4  2010/12/29 12:29:05  amodigli</span>
+<a name="l00030"></a>00030 <span class="comment"> * fixed doxygen warning, and bug in kernel filter indexing</span>
+<a name="l00031"></a>00031 <span class="comment"> *</span>
+<a name="l00032"></a>00032 <span class="comment"> * Revision 1.3  2009/09/03 15:04:48  kmirny</span>
+<a name="l00033"></a>00033 <span class="comment"> * replacing deprecated functions</span>
+<a name="l00034"></a>00034 <span class="comment"> *</span>
+<a name="l00035"></a>00035 <span class="comment"> * Revision 1.2  2009/02/18 10:33:07  amodigli</span>
+<a name="l00036"></a>00036 <span class="comment"> * fixed compiler warning</span>
+<a name="l00037"></a>00037 <span class="comment"> *</span>
+<a name="l00038"></a>00038 <span class="comment"> * Revision 1.1  2009/01/02 08:27:58  amodigli</span>
+<a name="l00039"></a>00039 <span class="comment"> * added to repository</span>
+<a name="l00040"></a>00040 <span class="comment"> *</span>
+<a name="l00041"></a>00041 <span class="comment"> *</span>
+<a name="l00042"></a>00042 <span class="comment"> */</span>
+<a name="l00043"></a>00043 
+<a name="l00044"></a>00044 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00045"></a>00045 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00046"></a>00046 <span class="preprocessor">#endif</span>
+<a name="l00047"></a>00047 <span class="preprocessor"></span>
+<a name="l00049"></a>00049 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00056"></a>00056 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00057"></a>00057 
+<a name="l00058"></a>00058 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00059"></a>00059 <span class="comment">  Includes</span>
+<a name="l00060"></a>00060 <span class="comment">-----------------------------------------------------------------------------*/</span>
+<a name="l00061"></a>00061 
+<a name="l00062"></a>00062 <span class="preprocessor">#include <math.h></span>
+<a name="l00063"></a>00063 
+<a name="l00064"></a>00064 
+<a name="l00065"></a>00065 <span class="preprocessor">#include <sinfo_error.h></span>
+<a name="l00066"></a>00066 <span class="preprocessor">#include <sinfo_msg.h></span>
+<a name="l00067"></a>00067 <span class="preprocessor">#include <sinfo_utils_wrappers.h></span>
+<a name="l00068"></a>00068 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00069"></a>00069 <span class="preprocessor">#include "sinfo_utilities.h"</span>
+<a name="l00070"></a>00070 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00071"></a>00071 <span class="comment">  Functions prototypes</span>
+<a name="l00072"></a>00072 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00073"></a>00073 cpl_image * sinfo_remove_crh_single( cpl_image * sci_image,
+<a name="l00074"></a>00074                      <span class="keywordtype">double</span> crh_frac_max,
+<a name="l00075"></a>00075                      <span class="keywordtype">double</span> sigma_lim,
+<a name="l00076"></a>00076                      <span class="keywordtype">double</span> f_lim,
+<a name="l00077"></a>00077                      <span class="keywordtype">int</span> max_iter,
+<a name="l00078"></a>00078                      <span class="keywordtype">double</span> gain,
+<a name="l00079"></a>00079                      <span class="keywordtype">double</span> ron);
+<a name="l00080"></a>00080 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00081"></a>00081 <span class="comment">  Implementation</span>
+<a name="l00082"></a>00082 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00083"></a>00083 
+<a name="l00084"></a>00084 <span class="comment">/* This should be defined in a more clever way, a parameter for example */</span>
+<a name="l00085"></a>00085 <span class="preprocessor">#define MAX_ITERATIONS 6</span>
+<a name="l00086"></a>00086 <span class="preprocessor"></span>
+<a name="l00087"></a>00087 
+<a name="l00109"></a>00109 cpl_image * sinfo_remove_crh_single( cpl_image * sci_image,
+<a name="l00110"></a>00110                      <span class="keywordtype">double</span> crh_frac_max,
+<a name="l00111"></a>00111                      <span class="keywordtype">double</span> sigma_lim,
+<a name="l00112"></a>00112                      <span class="keywordtype">double</span> f_lim,
+<a name="l00113"></a>00113                      <span class="keywordtype">int</span> max_iter,
+<a name="l00114"></a>00114                      <span class="keywordtype">double</span> gain,
+<a name="l00115"></a>00115                      <span class="keywordtype">double</span> ron)
+<a name="l00116"></a>00116 {
+<a name="l00117"></a>00117   <span class="keywordtype">int</span> i,j,k,l,m;
+<a name="l00118"></a>00118   <span class="keywordtype">double</span>  frac = 0. ;
+<a name="l00119"></a>00119   <span class="comment">/* Only pointers */</span>
+<a name="l00120"></a>00120 
+<a name="l00121"></a>00121   <span class="comment">/* Need to be free */</span>
+<a name="l00122"></a>00122   <span class="comment">//xsh_localization_list * loc_list = NULL ;</span>
+<a name="l00123"></a>00123   cpl_image* laplacian_image = NULL;
+<a name="l00124"></a>00124   cpl_image* laplacian_redu_image = NULL;
+<a name="l00125"></a>00125   cpl_image* two_sub_sample = NULL;
+<a name="l00126"></a>00126   cpl_image* sci_median5_image = NULL;
+<a name="l00127"></a>00127   cpl_image* noise_image = NULL;
+<a name="l00128"></a>00128   cpl_image* s_image = NULL;
+<a name="l00129"></a>00129   cpl_image* s_median_image = NULL;
+<a name="l00130"></a>00130   cpl_image* s2_image = NULL;
+<a name="l00131"></a>00131   cpl_image* sci_median3_image = NULL;
+<a name="l00132"></a>00132   cpl_image* sci_median3_7_image = NULL;
+<a name="l00133"></a>00133   cpl_image* f_image = NULL;
+<a name="l00134"></a>00134   cpl_image* r_image = NULL;
+<a name="l00135"></a>00135   <span class="keywordtype">int</span> two_sub_sample_nx = 0;
+<a name="l00136"></a>00136   <span class="keywordtype">int</span> two_sub_sample_ny = 0;
+<a name="l00137"></a>00137   <span class="comment">/* Only pointers */</span>
+<a name="l00138"></a>00138   <span class="keywordtype">float</span>* sci_data = NULL;
+<a name="l00139"></a>00139   <span class="keywordtype">float</span>* two_sub_sample_data = NULL;
+<a name="l00140"></a>00140   <span class="keywordtype">float</span>* laplacian_data = NULL;
+<a name="l00141"></a>00141   <span class="keywordtype">float</span>* laplacian_redu_data = NULL;
+<a name="l00142"></a>00142   <span class="keywordtype">float</span>* sci_median5_data = NULL;
+<a name="l00143"></a>00143   <span class="keywordtype">float</span>* sci_median3_data = NULL;
+<a name="l00144"></a>00144   <span class="keywordtype">float</span>* sci_median3_7_data = NULL;
+<a name="l00145"></a>00145   <span class="keywordtype">float</span>* noise_data = NULL;
+<a name="l00146"></a>00146   <span class="keywordtype">float</span>* s_data = NULL;
+<a name="l00147"></a>00147   <span class="keywordtype">float</span>* s_median_data = NULL;
+<a name="l00148"></a>00148   <span class="keywordtype">float</span>* s2_data = NULL;
+<a name="l00149"></a>00149   <span class="keywordtype">float</span>* f_data = NULL;
+<a name="l00150"></a>00150   <span class="keywordtype">float</span>* r_data = NULL;
+<a name="l00151"></a>00151   <span class="comment">/* Need to be free */</span>
+<a name="l00152"></a>00152   <span class="keywordtype">float</span>* cosmic_data = NULL;
+<a name="l00153"></a>00153 
+<a name="l00154"></a>00154   cpl_matrix* laplacian_kernel = NULL;
+<a name="l00155"></a>00155   cpl_matrix* median3_kernel = NULL;
+<a name="l00156"></a>00156   cpl_matrix* median5_kernel = NULL;
+<a name="l00157"></a>00157   cpl_matrix* median7_kernel = NULL;
+<a name="l00158"></a>00158   <span class="keywordtype">int</span> new_crh =1, nb_crh = 0;
+<a name="l00159"></a>00159   <span class="keywordtype">int</span> nbiter = 1 ;
+<a name="l00160"></a>00160   cpl_vector* median = NULL;
+<a name="l00161"></a>00161   <span class="comment">//const char * tag = NULL ;</span>
+<a name="l00162"></a>00162   <span class="keywordtype">int</span> nx=0;
+<a name="l00163"></a>00163   <span class="keywordtype">int</span> ny=0;
+<a name="l00164"></a>00164   cpl_image* res_image=NULL;
+<a name="l00165"></a>00165 
+<a name="l00166"></a>00166   <span class="comment">/* Check parameters */</span>
+<a name="l00167"></a>00167   cknull( sci_image,<span class="stringliteral">"null input image"</span> ) ; ;
+<a name="l00168"></a>00168 
+<a name="l00169"></a>00169   sinfo_msg( <span class="stringliteral">"Entering sinfo_remove_crh_single"</span>);
+<a name="l00170"></a>00170   sinfo_msg( <span class="stringliteral">"  Params: frac_max %.1f, sigma_lim %.2f f_lim %.2f, iter %d"</span>,
+<a name="l00171"></a>00171        crh_frac_max, sigma_lim, f_lim, max_iter);
+<a name="l00172"></a>00172 
+<a name="l00173"></a>00173   <span class="comment">/* Preparing different kernels */</span>
+<a name="l00174"></a>00174   nx=cpl_image_get_size_x(sci_image);
+<a name="l00175"></a>00175   ny=cpl_image_get_size_y(sci_image);
+<a name="l00176"></a>00176 
+<a name="l00177"></a>00177   <span class="comment">/* Laplacian */</span>
+<a name="l00178"></a>00178   check_nomsg( laplacian_kernel = cpl_matrix_new(3,3));
+<a name="l00179"></a>00179   cpl_matrix_set( laplacian_kernel,0,0,0.0);
+<a name="l00180"></a>00180   cpl_matrix_set( laplacian_kernel,0,1,-1.0);
+<a name="l00181"></a>00181   cpl_matrix_set( laplacian_kernel,0,2,0.0);
+<a name="l00182"></a>00182   cpl_matrix_set( laplacian_kernel,1,0,-1.0);
+<a name="l00183"></a>00183   cpl_matrix_set( laplacian_kernel,1,1,4.0);
+<a name="l00184"></a>00184   cpl_matrix_set( laplacian_kernel,1,2,-1.0);
+<a name="l00185"></a>00185   cpl_matrix_set( laplacian_kernel,2,0,0.0);
+<a name="l00186"></a>00186   cpl_matrix_set( laplacian_kernel,2,1,-1.0);
+<a name="l00187"></a>00187   cpl_matrix_set( laplacian_kernel,2,2,0.0);
+<a name="l00188"></a>00188   cpl_matrix_divide_scalar( laplacian_kernel, 4.0);
+<a name="l00189"></a>00189 <span class="comment">/*</span>
+<a name="l00190"></a>00190 <span class="comment">  cpl_matrix_set( laplacian_kernel,0,0,-1.0);</span>
+<a name="l00191"></a>00191 <span class="comment">  cpl_matrix_set( laplacian_kernel,0,1,-1.0);</span>
+<a name="l00192"></a>00192 <span class="comment">  cpl_matrix_set( laplacian_kernel,0,2,-1.0);</span>
+<a name="l00193"></a>00193 <span class="comment">  cpl_matrix_set( laplacian_kernel,1,0,-1.0);</span>
+<a name="l00194"></a>00194 <span class="comment">  cpl_matrix_set( laplacian_kernel,1,1,8.0);</span>
+<a name="l00195"></a>00195 <span class="comment">  cpl_matrix_set( laplacian_kernel,1,2,-1.0);</span>
+<a name="l00196"></a>00196 <span class="comment">  cpl_matrix_set( laplacian_kernel,2,0,-1.0);</span>
+<a name="l00197"></a>00197 <span class="comment">  cpl_matrix_set( laplacian_kernel,2,1,-1.0);</span>
+<a name="l00198"></a>00198 <span class="comment">  cpl_matrix_set( laplacian_kernel,2,2,-1.0);</span>
+<a name="l00199"></a>00199 <span class="comment">  cpl_matrix_divide_scalar( laplacian_kernel, 8.0);</span>
+<a name="l00200"></a>00200 <span class="comment">*/</span>
+<a name="l00201"></a>00201   <span class="comment">/* Median 3x3*/</span>
+<a name="l00202"></a>00202   check_nomsg( median3_kernel = cpl_matrix_new(3,3));
+<a name="l00203"></a>00203   <span class="keywordflow">for</span>(j=0; j< 3; j++){
+<a name="l00204"></a>00204     <span class="keywordflow">for</span>(i=0; i< 3; i++){
+<a name="l00205"></a>00205       cpl_matrix_set( median3_kernel, i,j,1.0);
+<a name="l00206"></a>00206     }
+<a name="l00207"></a>00207   }
+<a name="l00208"></a>00208 
+<a name="l00209"></a>00209   <span class="comment">/* Median 5x5 */</span>
+<a name="l00210"></a>00210   check_nomsg( median5_kernel = cpl_matrix_new(5,5));
+<a name="l00211"></a>00211   <span class="keywordflow">for</span>(j=0; j< 5; j++){
+<a name="l00212"></a>00212     <span class="keywordflow">for</span>(i=0; i< 5; i++){
+<a name="l00213"></a>00213       cpl_matrix_set( median5_kernel, i,j,1.0);
+<a name="l00214"></a>00214     }
+<a name="l00215"></a>00215   }
+<a name="l00216"></a>00216 
+<a name="l00217"></a>00217   <span class="comment">/* Median 7x7 */</span>
+<a name="l00218"></a>00218   check_nomsg( median7_kernel = cpl_matrix_new(7,7));
+<a name="l00219"></a>00219   <span class="keywordflow">for</span>(j=0; j< 7; j++){
+<a name="l00220"></a>00220     <span class="keywordflow">for</span>(i=0; i< 7; i++){
+<a name="l00221"></a>00221       cpl_matrix_set( median7_kernel, i,j,1.0);
+<a name="l00222"></a>00222     }
+<a name="l00223"></a>00223   }
+<a name="l00224"></a>00224 
+<a name="l00225"></a>00225   check_nomsg (res_image = cpl_image_duplicate( sci_image));
+<a name="l00226"></a>00226 
+<a name="l00227"></a>00227   <span class="comment">/* Allocate images and pointers */</span>
+<a name="l00228"></a>00228   check_nomsg (sci_data = cpl_image_get_data_float( res_image));
+<a name="l00229"></a>00229 
+<a name="l00230"></a>00230   two_sub_sample_nx = nx*2;
+<a name="l00231"></a>00231   two_sub_sample_ny = ny*2;
+<a name="l00232"></a>00232   check_nomsg( two_sub_sample = cpl_image_new( two_sub_sample_nx,
+<a name="l00233"></a>00233     two_sub_sample_ny, CPL_TYPE_FLOAT));
+<a name="l00234"></a>00234   check_nomsg(two_sub_sample_data = cpl_image_get_data_float( two_sub_sample));
+<a name="l00235"></a>00235   check_nomsg( laplacian_redu_image = cpl_image_new(nx,ny, CPL_TYPE_FLOAT));
+<a name="l00236"></a>00236   check_nomsg(laplacian_redu_data = cpl_image_get_data_float(
+<a name="l00237"></a>00237     laplacian_redu_image));
+<a name="l00238"></a>00238   check_nomsg( noise_image = cpl_image_new(nx,ny, CPL_TYPE_FLOAT));
+<a name="l00239"></a>00239   check_nomsg( noise_data = cpl_image_get_data_float( noise_image));
+<a name="l00240"></a>00240   check_nomsg( s_image = cpl_image_new(nx,ny, CPL_TYPE_FLOAT));
+<a name="l00241"></a>00241   check_nomsg( s_data = cpl_image_get_data_float( s_image));
+<a name="l00242"></a>00242   check_nomsg( s2_image = cpl_image_new(nx,ny, CPL_TYPE_FLOAT));
+<a name="l00243"></a>00243   check_nomsg( s2_data = cpl_image_get_data_float( s2_image));
+<a name="l00244"></a>00244   check_nomsg( f_image = cpl_image_new(nx,ny, CPL_TYPE_FLOAT));
+<a name="l00245"></a>00245   check_nomsg( f_data = cpl_image_get_data_float( f_image));
+<a name="l00246"></a>00246   check_nomsg( r_image = cpl_image_new(nx,ny, CPL_TYPE_FLOAT));
+<a name="l00247"></a>00247   check_nomsg( r_data = cpl_image_get_data_float( r_image));
+<a name="l00248"></a>00248   cosmic_data=cpl_calloc(nx*ny, <span class="keyword">sizeof</span>(<span class="keywordtype">float</span>));
+<a name="l00249"></a>00249 
+<a name="l00250"></a>00250   <span class="comment">/* LGG - Added limit on frac_max AND limit on nb iterations */</span>
+<a name="l00251"></a>00251   <span class="keywordflow">while</span>( new_crh > 0 && frac < crh_frac_max && nbiter <= max_iter ){
+<a name="l00252"></a>00252     sinfo_msg(<span class="stringliteral">"Iteration %d"</span>,nbiter );
+<a name="l00253"></a>00253     <span class="comment">/* Create a 2n x 2n images like this</span>
+<a name="l00254"></a>00254 <span class="comment">        | 1 | 2 |  =>  | 1 | 1 | 2 | 2 |</span>
+<a name="l00255"></a>00255 <span class="comment">        | 3 | 4 |      | 1 | 1 | 2 | 2 |</span>
+<a name="l00256"></a>00256 <span class="comment">                       | 3 | 3 | 4 | 4 |</span>
+<a name="l00257"></a>00257 <span class="comment">                       | 3 | 3 | 4 | 4 | */</span>
+<a name="l00258"></a>00258     <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"Create a 2n images"</span>);
+<a name="l00259"></a>00259     <span class="keywordflow">for</span>( j=0; j< ny; j++){
+<a name="l00260"></a>00260       <span class="keywordflow">for</span>( i=0; i< nx; i++){
+<a name="l00261"></a>00261         <span class="keywordtype">float</span> val = sci_data[i+j*nx];
+<a name="l00262"></a>00262 
+<a name="l00263"></a>00263     <span class="keywordflow">if</span> ( val < 0. ) val = 0. ;
+<a name="l00264"></a>00264         two_sub_sample_data[i*2+j*2*two_sub_sample_nx] = val;
+<a name="l00265"></a>00265         two_sub_sample_data[i*2+1+j*2*two_sub_sample_nx] = val;
+<a name="l00266"></a>00266         two_sub_sample_data[i*2+(j*2+1)*two_sub_sample_nx] = val;
+<a name="l00267"></a>00267         two_sub_sample_data[i*2+1+(j*2+1)*two_sub_sample_nx] = val;
+<a name="l00268"></a>00268       }
+<a name="l00269"></a>00269     }
+<a name="l00270"></a>00270     <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"Doing laplacian convolution"</span>);
+<a name="l00271"></a>00271     <span class="comment">/* Doing the laplacian convolution</span>
+<a name="l00272"></a>00272 <span class="comment">        0  -1   0</span>
+<a name="l00273"></a>00273 <span class="comment">       -1   4  -1</span>
+<a name="l00274"></a>00274 <span class="comment">        0  -1   0 */</span>
+<a name="l00275"></a>00275     laplacian_image = sinfo_image_filter_linear( two_sub_sample,
+<a name="l00276"></a>00276       laplacian_kernel);
+<a name="l00277"></a>00277 
+<a name="l00278"></a>00278     <span class="comment">/* multiply by two to normalize correctly the laplacian [RD5]</span>
+<a name="l00279"></a>00279 <span class="comment">       and filter negative values */</span>
+<a name="l00280"></a>00280     <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"Normalize laplacian"</span>);
+<a name="l00281"></a>00281     check_nomsg (laplacian_data = cpl_image_get_data_float( laplacian_image));
+<a name="l00282"></a>00282     <span class="keywordflow">for</span> ( i=0; i< two_sub_sample_nx*two_sub_sample_ny; i++){
+<a name="l00283"></a>00283       <span class="keywordflow">if</span> (laplacian_data[i] > 0.0){
+<a name="l00284"></a>00284         laplacian_data[i] = 2.0 * laplacian_data[i];
+<a name="l00285"></a>00285       }
+<a name="l00286"></a>00286       <span class="keywordflow">else</span>{
+<a name="l00287"></a>00287         laplacian_data[i] = 0.0;
+<a name="l00288"></a>00288       }
+<a name="l00289"></a>00289     }
+<a name="l00290"></a>00290     <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"Save Lpositive"</span>);
+<a name="l00291"></a>00291     cpl_image_save(laplacian_image, <span class="stringliteral">"Lpositive.fits"</span>, CPL_BPP_IEEE_FLOAT, NULL,
+<a name="l00292"></a>00292       CPL_IO_DEFAULT);
+<a name="l00293"></a>00293 
+<a name="l00294"></a>00294     <span class="comment">/* resample to the original size</span>
+<a name="l00295"></a>00295 <span class="comment">       | 1 | 1 | 2 | 2 |    | 1 | 2 |</span>
+<a name="l00296"></a>00296 <span class="comment">       | 1 | 1 | 2 | 2 |    | 3 | 4 |</span>
+<a name="l00297"></a>00297 <span class="comment">       | 3 | 3 | 4 | 4 | =></span>
+<a name="l00298"></a>00298 <span class="comment">       | 3 | 3 | 4 | 4 |               */</span>
+<a name="l00299"></a>00299 
+<a name="l00300"></a>00300     <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"Resample to the original size"</span>);
+<a name="l00301"></a>00301 
+<a name="l00302"></a>00302     <span class="keywordflow">for</span>( j=0; j< ny; j++){
+<a name="l00303"></a>00303       <span class="keywordflow">for</span>( i=0; i< nx; i++){
+<a name="l00304"></a>00304         laplacian_redu_data[i+j*nx] =
+<a name="l00305"></a>00305           (laplacian_data[i*2+j*2*two_sub_sample_nx]+
+<a name="l00306"></a>00306            laplacian_data[i*2+1+j*2*two_sub_sample_nx]+
+<a name="l00307"></a>00307            laplacian_data[i*2+(j*2+1)*two_sub_sample_nx]+
+<a name="l00308"></a>00308            laplacian_data[i*2+1+(j*2+1)*two_sub_sample_nx])/4.0;
+<a name="l00309"></a>00309       }
+<a name="l00310"></a>00310     }
+<a name="l00311"></a>00311 
+<a name="l00312"></a>00312     cpl_image_save(laplacian_redu_image, <span class="stringliteral">"Lplus.fits"</span>, CPL_BPP_IEEE_FLOAT,
+<a name="l00313"></a>00313       NULL, CPL_IO_DEFAULT);
+<a name="l00314"></a>00314 
+<a name="l00315"></a>00315     <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"Apply median filter"</span>);
+<a name="l00316"></a>00316     <span class="comment">/* Apply 5x5 median filter on data */</span>
+<a name="l00317"></a>00317     check_nomsg( sci_median5_image = sinfo_image_filter_median( sci_image,
+<a name="l00318"></a>00318       median5_kernel));
+<a name="l00319"></a>00319     check_nomsg (sci_median5_data = cpl_image_get_data_float( sci_median5_image));
+<a name="l00320"></a>00320 
+<a name="l00321"></a>00321     <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"Compute noise"</span>);
+<a name="l00322"></a>00322     <span class="comment">/* computes the noise image */</span>
+<a name="l00323"></a>00323     <span class="keywordflow">for</span>( i=0; i< nx*ny; i++){
+<a name="l00324"></a>00324       noise_data[i] = sqrt(sci_median5_data[i]*gain+
+<a name="l00325"></a>00325         ron*ron)/ gain;
+<a name="l00326"></a>00326     }
+<a name="l00327"></a>00327 
+<a name="l00328"></a>00328     <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"Compute S"</span>);
+<a name="l00329"></a>00329     <span class="comment">/* compute S image */</span>
+<a name="l00330"></a>00330     <span class="keywordflow">for</span>( i=0; i< nx*ny; i++){
+<a name="l00331"></a>00331       s_data[i] = laplacian_redu_data[i] / (2.0*noise_data[i]);
+<a name="l00332"></a>00332     }
+<a name="l00333"></a>00333 
+<a name="l00334"></a>00334     <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"Compute S median"</span>);
+<a name="l00335"></a>00335     <span class="comment">/* compute S median image */</span>
+<a name="l00336"></a>00336     check_nomsg( s_median_image = sinfo_image_filter_median( s_image,
+<a name="l00337"></a>00337       median5_kernel));
+<a name="l00338"></a>00338     check_nomsg( s_median_data = cpl_image_get_data_float( s_median_image));
+<a name="l00339"></a>00339 
+<a name="l00340"></a>00340     <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"Compute s2"</span>);
+<a name="l00341"></a>00341     <span class="comment">/* compute s2 */</span>
+<a name="l00342"></a>00342     <span class="keywordflow">for</span>( i=0; i< nx*ny; i++){
+<a name="l00343"></a>00343       s2_data[i] = s_data[i] -s_median_data[i];
+<a name="l00344"></a>00344     }
+<a name="l00345"></a>00345 
+<a name="l00346"></a>00346        cpl_image_save( s2_image, <span class="stringliteral">"S2.fits"</span>, CPL_BPP_IEEE_FLOAT, NULL,
+<a name="l00347"></a>00347      CPL_IO_DEFAULT);
+<a name="l00348"></a>00348 
+<a name="l00349"></a>00349     <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"Apply 3x3 filter"</span>);
+<a name="l00350"></a>00350     <span class="comment">/* Apply 3x3 median filter on data */</span>
+<a name="l00351"></a>00351     check_nomsg( sci_median3_image = sinfo_image_filter_median( sci_image,
+<a name="l00352"></a>00352       median3_kernel));
+<a name="l00353"></a>00353 
+<a name="l00354"></a>00354     <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"Apply 7x7 filter"</span>);
+<a name="l00355"></a>00355     <span class="comment">/* Apply 7x7 median filter */</span>
+<a name="l00356"></a>00356     check_nomsg( sci_median3_7_image = sinfo_image_filter_median( sci_median3_image,
+<a name="l00357"></a>00357       median7_kernel));
+<a name="l00358"></a>00358     <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"Apply 7x7 filter ok"</span>);
+<a name="l00359"></a>00359     check_nomsg ( sci_median3_data = cpl_image_get_data_float( sci_median3_image));
+<a name="l00360"></a>00360     check_nomsg ( sci_median3_7_data = cpl_image_get_data_float(
+<a name="l00361"></a>00361       sci_median3_7_image));
+<a name="l00362"></a>00362 
+<a name="l00363"></a>00363     <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"Compute F"</span>);
+<a name="l00364"></a>00364     <span class="comment">/* compute F */</span>
+<a name="l00365"></a>00365     <span class="keywordflow">for</span>( i=0; i< nx*ny; i++){
+<a name="l00366"></a>00366       f_data[i] = sci_median3_data[i] -sci_median3_7_data[i];
+<a name="l00367"></a>00367       <span class="keywordflow">if</span> (f_data[i] < 0.01){
+<a name="l00368"></a>00368         f_data[i] = 0.01;
+<a name="l00369"></a>00369       }
+<a name="l00370"></a>00370     }
+<a name="l00371"></a>00371     cpl_image_save( f_image, <span class="stringliteral">"F.fits"</span>, CPL_BPP_IEEE_FLOAT, NULL,
+<a name="l00372"></a>00372       CPL_IO_DEFAULT);
+<a name="l00373"></a>00373 
+<a name="l00374"></a>00374     <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"Compute R"</span>);
+<a name="l00375"></a>00375     <span class="comment">/* compute R */</span>
+<a name="l00376"></a>00376     <span class="keywordflow">for</span>( i=0; i< nx*ny; i++){
+<a name="l00377"></a>00377       r_data[i] = laplacian_redu_data[i]/f_data[i];
+<a name="l00378"></a>00378     }
+<a name="l00379"></a>00379 
+<a name="l00380"></a>00380     cpl_image_save( r_image, <span class="stringliteral">"R.fits"</span>, CPL_BPP_IEEE_FLOAT, NULL,
+<a name="l00381"></a>00381       CPL_IO_DEFAULT);
+<a name="l00382"></a>00382 
+<a name="l00383"></a>00383     <span class="comment">/* Search for cosmics */</span>
+<a name="l00384"></a>00384 
+<a name="l00385"></a>00385     <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"Search for cosmic"</span>);
+<a name="l00386"></a>00386     new_crh = 0;
+<a name="l00387"></a>00387     median = cpl_vector_new(24);
+<a name="l00388"></a>00388 
+<a name="l00389"></a>00389     <span class="keywordflow">for</span>( j=1; j< ny-1; j++){
+<a name="l00390"></a>00390       <span class="keywordtype">double</span> *data = NULL;
+<a name="l00391"></a>00391       cpl_vector* med_vect = NULL;
+<a name="l00392"></a>00392 
+<a name="l00393"></a>00393       <span class="keywordflow">for</span>( i=1; i< nx-1; i++){
+<a name="l00394"></a>00394         <span class="keywordflow">if</span> ( (s2_data[i+j*nx] >= sigma_lim) &&
+<a name="l00395"></a>00395           (r_data[i+j*nx] >= f_lim)){
+<a name="l00396"></a>00396           <span class="keywordtype">int</span> li,lj,ui,uj;
+<a name="l00397"></a>00397           cosmic_data[i+j*nx] = 1.0;
+<a name="l00398"></a>00398           new_crh++;
+<a name="l00399"></a>00399           li = i-2;
+<a name="l00400"></a>00400           lj = j-2;
+<a name="l00401"></a>00401           ui = i+2;
+<a name="l00402"></a>00402           uj = j+2;
+<a name="l00403"></a>00403           m = 0;
+<a name="l00404"></a>00404           <span class="keywordflow">if</span> (li < 0) li = 0;
+<a name="l00405"></a>00405           <span class="keywordflow">if</span> (ui >= nx) ui = nx-1;
+<a name="l00406"></a>00406           <span class="keywordflow">if</span> (lj < 0) lj = 0;
+<a name="l00407"></a>00407           <span class="keywordflow">if</span> (uj >= ny) uj = ny-1;
+<a name="l00408"></a>00408           <span class="keywordflow">for</span>( k=lj; k <= uj; k++){
+<a name="l00409"></a>00409             <span class="keywordflow">for</span>( l=li; l <= ui; l++){
+<a name="l00410"></a>00410               <span class="comment">//sinfo_msg("REGDEBUG k %d l %d m %d", k, l, m);</span>
+<a name="l00411"></a>00411               <span class="keywordflow">if</span> ( k < j){
+<a name="l00412"></a>00412                 cpl_vector_set(median, m, sci_data[l+k*nx]);
+<a name="l00413"></a>00413                 m++;
+<a name="l00414"></a>00414               }
+<a name="l00415"></a>00415               <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( (k == j) && ( l < i)){
+<a name="l00416"></a>00416                  cpl_vector_set(median, m, sci_data[l+k*nx]);
+<a name="l00417"></a>00417                 m++;
+<a name="l00418"></a>00418               }
+<a name="l00419"></a>00419               <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( l!=i && k!=j && (s2_data[l+k*nx] < sigma_lim)
+<a name="l00420"></a>00420                 && (r_data[l+k*nx] < f_lim)){
+<a name="l00421"></a>00421                 cpl_vector_set(median, m, sci_data[l+k*nx]);
+<a name="l00422"></a>00422                 m++;
+<a name="l00423"></a>00423               }
+<a name="l00424"></a>00424             }
+<a name="l00425"></a>00425           }
+<a name="l00426"></a>00426           check_nomsg( data = cpl_vector_get_data( median));
+<a name="l00427"></a>00427           <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"REGDEBUG i %d j %d m %d"</span>, i, j ,m);
+<a name="l00428"></a>00428           check_nomsg( med_vect = cpl_vector_wrap( m, data));
+<a name="l00429"></a>00429           check_nomsg( sci_data[i+j*nx] = cpl_vector_get_median( med_vect));
+<a name="l00430"></a>00430           cpl_vector_unwrap( med_vect);
+<a name="l00431"></a>00431         }
+<a name="l00432"></a>00432       }
+<a name="l00433"></a>00433     }
+<a name="l00434"></a>00434     sinfoni_free_vector( &median ) ;
+<a name="l00435"></a>00435     nb_crh += new_crh;
+<a name="l00436"></a>00436     frac = (double)nb_crh/(<span class="keywordtype">double</span>)(nx*ny) ;
+<a name="l00437"></a>00437     sinfo_msg(<span class="stringliteral">"   new cosmics %d, total %d, frac %.4f [%d pixels]"</span>,new_crh,nb_crh,
+<a name="l00438"></a>00438         frac, nx*ny);
+<a name="l00439"></a>00439     nbiter++;
+<a name="l00440"></a>00440     sinfo_free_image( &laplacian_image);
+<a name="l00441"></a>00441     sinfo_free_image( &sci_median3_7_image ) ;
+<a name="l00442"></a>00442     sinfo_free_image( &sci_median3_image ) ;
+<a name="l00443"></a>00443     sinfo_free_image( &s_median_image ) ;
+<a name="l00444"></a>00444     sinfo_free_image( &sci_median5_image ) ;
+<a name="l00445"></a>00445   }
+<a name="l00446"></a>00446   {
+<a name="l00447"></a>00447     FILE *debug = NULL;
+<a name="l00448"></a>00448 
+<a name="l00449"></a>00449     debug = fopen(<span class="stringliteral">"cosmic.log"</span>,<span class="stringliteral">"w"</span>);
+<a name="l00450"></a>00450 
+<a name="l00451"></a>00451     <span class="keywordflow">for</span>( j=0; j< ny; j++){
+<a name="l00452"></a>00452       <span class="keywordflow">for</span>( i=0; i< nx; i++){
+<a name="l00453"></a>00453         <span class="keywordflow">if</span> ( cosmic_data[i+j*nx] == 1.0){
+<a name="l00454"></a>00454           fprintf(debug,<span class="stringliteral">"%.1f %.1f\n"</span>,i+1.0,j+1.0);
+<a name="l00455"></a>00455         }
+<a name="l00456"></a>00456       }
+<a name="l00457"></a>00457     }
+<a name="l00458"></a>00458     fclose(debug);
+<a name="l00459"></a>00459   }
+<a name="l00460"></a>00460 
+<a name="l00461"></a>00461   <span class="comment">//check_nomsg( res_frame = cpl_frame_duplicate( sci_frame ) ) ;</span>
+<a name="l00462"></a>00462   <span class="comment">//sinfo_msg( "Saving Result Frame '%s'", res_name ) ;</span>
+<a name="l00463"></a>00463   <span class="comment">//check_nomsg( add_qc_crh( sci_pre, nb_crh, 1, instrument ) ) ;</span>
+<a name="l00464"></a>00464   <span class="comment">//check_nomsg( res_frame = xsh_pre_save( sci_pre, res_name, 1 ) ) ;</span>
+<a name="l00465"></a>00465   <span class="comment">//tag = cpl_frame_get_tag( in_sci_frame ) ;</span>
+<a name="l00466"></a>00466   <span class="comment">//check_nomsg( cpl_frame_set_tag( res_frame, tag ) ) ;</span>
+<a name="l00467"></a>00467 
+<a name="l00468"></a>00468   cleanup:
+<a name="l00469"></a>00469   <span class="comment">//xsh_pre_free( &sci_pre);</span>
+<a name="l00470"></a>00470   <span class="comment">//xsh_localization_list_free( &loc_list ) ;</span>
+<a name="l00471"></a>00471 
+<a name="l00472"></a>00472     <span class="comment">/* free kernel */</span>
+<a name="l00473"></a>00473     sinfoni_free_matrix( &laplacian_kernel);
+<a name="l00474"></a>00474     sinfoni_free_matrix( &median3_kernel);
+<a name="l00475"></a>00475     sinfoni_free_matrix( &median5_kernel);
+<a name="l00476"></a>00476     sinfoni_free_matrix( &median7_kernel);
+<a name="l00477"></a>00477     <span class="comment">/* free images */</span>
+<a name="l00478"></a>00478     sinfo_free_image( &laplacian_image);
+<a name="l00479"></a>00479     sinfo_free_image( &laplacian_redu_image);
+<a name="l00480"></a>00480     sinfo_free_image( &two_sub_sample);
+<a name="l00481"></a>00481     sinfo_free_image( &sci_median5_image);
+<a name="l00482"></a>00482     sinfo_free_image( &noise_image);
+<a name="l00483"></a>00483     sinfo_free_image( &s_image);
+<a name="l00484"></a>00484     sinfo_free_image( &s_median_image);
+<a name="l00485"></a>00485     sinfo_free_image( &s2_image);
+<a name="l00486"></a>00486     sinfo_free_image( &sci_median3_image);
+<a name="l00487"></a>00487     sinfo_free_image( &sci_median3_7_image);
+<a name="l00488"></a>00488     sinfo_free_image( &f_image);
+<a name="l00489"></a>00489     sinfo_free_image( &r_image);
+<a name="l00490"></a>00490     <span class="comment">/* free vector */</span>
+<a name="l00491"></a>00491     sinfoni_free_vector( &median);
+<a name="l00492"></a>00492     <span class="comment">/* free tab */</span>
+<a name="l00493"></a>00493     <span class="keywordflow">if</span>(cosmic_data!=NULL) cpl_free( cosmic_data);
+<a name="l00494"></a>00494     <span class="keywordflow">return</span> res_image;
+<a name="l00495"></a>00495 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__remove__crh__single_8h_source.html b/html/sinfo__remove__crh__single_8h_source.html
new file mode 100644
index 0000000..544fdfb
--- /dev/null
+++ b/html/sinfo__remove__crh__single_8h_source.html
@@ -0,0 +1,23 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_remove_crh_single.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_remove_crh_single.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 cpl_image * sinfo_remove_crh_single( cpl_image * sci_image, 
+<a name="l00002"></a>00002                    <span class="keywordtype">double</span> frac_max,
+<a name="l00003"></a>00003                    <span class="keywordtype">double</span> sigma_lim,
+<a name="l00004"></a>00004                    <span class="keywordtype">double</span> f_lim,
+<a name="l00005"></a>00005                      <span class="keywordtype">int</span> max_iter,
+<a name="l00006"></a>00006                      <span class="keywordtype">double</span> gain,
+<a name="l00007"></a>00007                      <span class="keywordtype">double</span> ron);
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__resampling_8c_source.html b/html/sinfo__resampling_8c_source.html
new file mode 100644
index 0000000..99e7bc1
--- /dev/null
+++ b/html/sinfo__resampling_8c_source.html
@@ -0,0 +1,289 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_resampling.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_resampling.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name     :    resampling.c</span>
+<a name="l00022"></a>00022 <span class="comment">   Author         :    Nicolas Devillard</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on    :    Jan 04, 1996</span>
+<a name="l00024"></a>00024 <span class="comment">   Description    :    resampling routines</span>
+<a name="l00025"></a>00025 <span class="comment"></span>
+<a name="l00026"></a>00026 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="comment">/*</span>
+<a name="l00029"></a>00029 <span class="comment">    $Id: sinfo_resampling.c,v 1.6 2012/03/03 10:18:26 amodigli Exp $</span>
+<a name="l00030"></a>00030 <span class="comment">    $Author: amodigli $</span>
+<a name="l00031"></a>00031 <span class="comment">    $Date: 2012/03/03 10:18:26 $</span>
+<a name="l00032"></a>00032 <span class="comment">    $Revision: 1.6 $</span>
+<a name="l00033"></a>00033 <span class="comment"> */</span>
+<a name="l00034"></a>00034 
+<a name="l00035"></a>00035 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00036"></a>00036 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00037"></a>00037 <span class="preprocessor">#endif</span>
+<a name="l00038"></a>00038 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00039"></a>00039 <span class="comment">                                  Includes</span>
+<a name="l00040"></a>00040 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include <string.h></span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include "sinfo_resampling.h"</span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include <math.h></span>
+<a name="l00044"></a>00044 <span class="preprocessor">#include "sinfo_globals.h"</span>
+<a name="l00045"></a>00045 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00046"></a>00046 <span class="comment">                              Private functions</span>
+<a name="l00047"></a>00047 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00048"></a>00048 <span class="keyword">static</span> <span class="keywordtype">void</span> reverse_tanh_kernel(<span class="keywordtype">double</span> * data, <span class="keywordtype">int</span> nn) ;
+<a name="l00049"></a>00049 <span class="keyword">static</span> <span class="keywordtype">double</span> * sinfo_generate_tanh_kernel(<span class="keywordtype">double</span> steep);
+<a name="l00050"></a>00050 
+<a name="l00060"></a>00060 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00061"></a>00061 <span class="comment">                              Function codes</span>
+<a name="l00062"></a>00062 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00063"></a>00063 
+<a name="l00088"></a>00088 <span class="keywordtype">double</span>   *
+<a name="l00089"></a>00089 sinfo_generate_interpolation_kernel(<span class="keyword">const</span> <span class="keywordtype">char</span> * kernel_type)
+<a name="l00090"></a>00090 {
+<a name="l00091"></a>00091     <span class="keywordtype">double</span>  *    tab ;
+<a name="l00092"></a>00092     <span class="keywordtype">int</span>         i ;
+<a name="l00093"></a>00093     <span class="keywordtype">double</span>      x ;
+<a name="l00094"></a>00094     <span class="keywordtype">double</span>        alpha ;
+<a name="l00095"></a>00095     <span class="keywordtype">double</span>        inv_norm ;
+<a name="l00096"></a>00096     <span class="keywordtype">int</span>         samples = KERNEL_SAMPLES ;
+<a name="l00097"></a>00097 
+<a name="l00098"></a>00098     <span class="keywordflow">if</span> (kernel_type==NULL) {
+<a name="l00099"></a>00099         tab = sinfo_generate_interpolation_kernel(<span class="stringliteral">"tanh"</span>) ;
+<a name="l00100"></a>00100     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!strcmp(kernel_type, <span class="stringliteral">"default"</span>)) {
+<a name="l00101"></a>00101         tab = sinfo_generate_interpolation_kernel(<span class="stringliteral">"tanh"</span>) ;
+<a name="l00102"></a>00102     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!strcmp(kernel_type, <span class="stringliteral">"sinc"</span>)) {
+<a name="l00103"></a>00103         tab = cpl_malloc(samples * <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>)) ;
+<a name="l00104"></a>00104         tab[0] = 1.0 ;
+<a name="l00105"></a>00105         tab[samples-1] = 0.0 ;
+<a name="l00106"></a>00106         <span class="keywordflow">for</span> (i=1 ; i<samples ; i++) {
+<a name="l00107"></a>00107             x = (double)KERNEL_WIDTH * (<span class="keywordtype">double</span>)i/(double)(samples-1) ;
+<a name="l00108"></a>00108             tab[i] = sinfo_sinc(x) ;
+<a name="l00109"></a>00109         }
+<a name="l00110"></a>00110     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!strcmp(kernel_type, <span class="stringliteral">"sinc2"</span>)) {
+<a name="l00111"></a>00111         tab = cpl_malloc(samples * <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>)) ;
+<a name="l00112"></a>00112         tab[0] = 1.0 ;
+<a name="l00113"></a>00113         tab[samples-1] = 0.0 ;
+<a name="l00114"></a>00114         <span class="keywordflow">for</span> (i=1 ; i<samples ; i++) {
+<a name="l00115"></a>00115             x = 2.0 * (double)i/(<span class="keywordtype">double</span>)(samples-1) ;
+<a name="l00116"></a>00116             tab[i] = sinfo_sinc(x) ;
+<a name="l00117"></a>00117             tab[i] *= tab[i] ;
+<a name="l00118"></a>00118         }
+<a name="l00119"></a>00119     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!strcmp(kernel_type, <span class="stringliteral">"lanczos"</span>)) {
+<a name="l00120"></a>00120         tab = cpl_malloc(samples * <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>)) ;
+<a name="l00121"></a>00121         <span class="keywordflow">for</span> (i=0 ; i<samples ; i++) {
+<a name="l00122"></a>00122             x = (double)KERNEL_WIDTH * (<span class="keywordtype">double</span>)i/(double)(samples-1) ;
+<a name="l00123"></a>00123             <span class="keywordflow">if</span> (fabs(x)<2) {
+<a name="l00124"></a>00124                 tab[i] = sinfo_sinc(x) * sinfo_sinc(x/2) ;
+<a name="l00125"></a>00125             } <span class="keywordflow">else</span> {
+<a name="l00126"></a>00126                 tab[i] = 0.00 ;
+<a name="l00127"></a>00127             }
+<a name="l00128"></a>00128         }
+<a name="l00129"></a>00129     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!strcmp(kernel_type, <span class="stringliteral">"hamming"</span>)) {
+<a name="l00130"></a>00130         tab = cpl_malloc(samples * <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>)) ;
+<a name="l00131"></a>00131         alpha = 0.54 ;
+<a name="l00132"></a>00132         inv_norm  = 1.00 / (double)(samples - 1) ;
+<a name="l00133"></a>00133         <span class="keywordflow">for</span> (i=0 ; i<samples ; i++) {
+<a name="l00134"></a>00134             x = (double)i ;
+<a name="l00135"></a>00135             <span class="keywordflow">if</span> (i<(samples-1)/2) {
+<a name="l00136"></a>00136                 tab[i] = alpha + (1-alpha) * cos(2.0*PI_NUMB*x*inv_norm) ;
+<a name="l00137"></a>00137             } <span class="keywordflow">else</span> {
+<a name="l00138"></a>00138                 tab[i] = 0.0 ;
+<a name="l00139"></a>00139             }
+<a name="l00140"></a>00140         }
+<a name="l00141"></a>00141     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!strcmp(kernel_type, <span class="stringliteral">"hann"</span>)) {
+<a name="l00142"></a>00142         tab = cpl_malloc(samples * <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>)) ;
+<a name="l00143"></a>00143         alpha = 0.50 ;
+<a name="l00144"></a>00144         inv_norm  = 1.00 / (double)(samples - 1) ;
+<a name="l00145"></a>00145         <span class="keywordflow">for</span> (i=0 ; i<samples ; i++) {
+<a name="l00146"></a>00146             x = (double)i ;
+<a name="l00147"></a>00147             <span class="keywordflow">if</span> (i<(samples-1)/2) {
+<a name="l00148"></a>00148                 tab[i] = alpha + (1-alpha) * cos(2.0*PI_NUMB*x*inv_norm) ;
+<a name="l00149"></a>00149             } <span class="keywordflow">else</span> {
+<a name="l00150"></a>00150                 tab[i] = 0.0 ;
+<a name="l00151"></a>00151             }
+<a name="l00152"></a>00152         }
+<a name="l00153"></a>00153     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!strcmp(kernel_type, <span class="stringliteral">"tanh"</span>)) {
+<a name="l00154"></a>00154         tab = sinfo_generate_tanh_kernel(TANH_STEEPNESS) ;
+<a name="l00155"></a>00155     } <span class="keywordflow">else</span> {
+<a name="l00156"></a>00156         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"unrecognized kernel type [%s]: aborting generation"</span>,
+<a name="l00157"></a>00157                 kernel_type) ;
+<a name="l00158"></a>00158         <span class="keywordflow">return</span> NULL ;
+<a name="l00159"></a>00159     }
+<a name="l00160"></a>00160 
+<a name="l00161"></a>00161     <span class="keywordflow">return</span> tab ;
+<a name="l00162"></a>00162 }
+<a name="l00163"></a>00163 
+<a name="l00175"></a>00175 <span class="keywordtype">double</span>
+<a name="l00176"></a>00176 sinfo_sinc(<span class="keywordtype">double</span> x)
+<a name="l00177"></a>00177 {
+<a name="l00178"></a>00178     <span class="keywordflow">if</span> (fabs(x)<1e-4)
+<a name="l00179"></a>00179         <span class="keywordflow">return</span> (<span class="keywordtype">double</span>)1.00 ;
+<a name="l00180"></a>00180     <span class="keywordflow">else</span>
+<a name="l00181"></a>00181         <span class="keywordflow">return</span> ((sin(x * (<span class="keywordtype">double</span>)PI_NUMB)) / (x * (<span class="keywordtype">double</span>)PI_NUMB)) ;
+<a name="l00182"></a>00182 }
+<a name="l00183"></a>00183 
+<a name="l00205"></a>00205 <span class="preprocessor">#define hk_gen(x,s) (((tanh(s*(x+0.5))+1)/2)*((tanh(s*(-x+0.5))+1)/2))</span>
+<a name="l00206"></a>00206 <span class="preprocessor"></span>
+<a name="l00207"></a>00207 <span class="keyword">static</span> <span class="keywordtype">double</span> * 
+<a name="l00208"></a>00208 sinfo_generate_tanh_kernel(<span class="keywordtype">double</span> steep)
+<a name="l00209"></a>00209 {
+<a name="l00210"></a>00210     <span class="keywordtype">double</span>  *   kernel ;
+<a name="l00211"></a>00211     <span class="keywordtype">double</span>  *   x ;
+<a name="l00212"></a>00212     <span class="keywordtype">double</span>      width ;
+<a name="l00213"></a>00213     <span class="keywordtype">double</span>      inv_np ;
+<a name="l00214"></a>00214     <span class="keywordtype">double</span>      ind ;
+<a name="l00215"></a>00215     <span class="keywordtype">int</span>         i ;
+<a name="l00216"></a>00216     <span class="keywordtype">int</span>         np ;
+<a name="l00217"></a>00217     <span class="keywordtype">int</span>         samples ;
+<a name="l00218"></a>00218 
+<a name="l00219"></a>00219     width   = (double)TABSPERPIX / 2.0 ; 
+<a name="l00220"></a>00220     samples = KERNEL_SAMPLES ;
+<a name="l00221"></a>00221     np      = 32768 ; <span class="comment">/* Hardcoded: should never be changed */</span>
+<a name="l00222"></a>00222     inv_np  = 1.00 / (double)np ;
+<a name="l00223"></a>00223 
+<a name="l00224"></a>00224     <span class="comment">/*</span>
+<a name="l00225"></a>00225 <span class="comment">     * Generate the kernel expression in Fourier space</span>
+<a name="l00226"></a>00226 <span class="comment">     * with a correct frequency ordering to allow standard FT</span>
+<a name="l00227"></a>00227 <span class="comment">     */</span>
+<a name="l00228"></a>00228     x = cpl_malloc((2*np+1)*<span class="keyword">sizeof</span>(<span class="keywordtype">double</span>)) ;
+<a name="l00229"></a>00229     <span class="keywordflow">for</span> (i=0 ; i<np/2 ; i++) {
+<a name="l00230"></a>00230         ind      = (double)i * 2.0 * width * inv_np ;
+<a name="l00231"></a>00231         x[2*i]   = hk_gen(ind, steep) ;
+<a name="l00232"></a>00232         x[2*i+1] = 0.00 ;
+<a name="l00233"></a>00233     }
+<a name="l00234"></a>00234     <span class="keywordflow">for</span> (i=np/2 ; i<np ; i++) {
+<a name="l00235"></a>00235         ind      = (double)(i-np) * 2.0 * width * inv_np ;
+<a name="l00236"></a>00236         x[2*i]   = hk_gen(ind, steep) ;
+<a name="l00237"></a>00237         x[2*i+1] = 0.00 ;
+<a name="l00238"></a>00238     }
+<a name="l00239"></a>00239 
+<a name="l00240"></a>00240     <span class="comment">/* </span>
+<a name="l00241"></a>00241 <span class="comment">     * Reverse Fourier to come back to image space</span>
+<a name="l00242"></a>00242 <span class="comment">     */</span>
+<a name="l00243"></a>00243     reverse_tanh_kernel(x, np) ;
+<a name="l00244"></a>00244 
+<a name="l00245"></a>00245     <span class="comment">/*</span>
+<a name="l00246"></a>00246 <span class="comment">     * Allocate and fill in returned array</span>
+<a name="l00247"></a>00247 <span class="comment">     */</span>
+<a name="l00248"></a>00248     kernel = cpl_malloc(samples * <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>)) ;
+<a name="l00249"></a>00249     <span class="keywordflow">for</span> (i=0 ; i<samples ; i++) {
+<a name="l00250"></a>00250         kernel[i] = 2.0 * width * x[2*i] * inv_np ;
+<a name="l00251"></a>00251     }
+<a name="l00252"></a>00252     cpl_free(x) ;
+<a name="l00253"></a>00253     <span class="keywordflow">return</span> kernel ;
+<a name="l00254"></a>00254 }
+<a name="l00255"></a>00255 
+<a name="l00268"></a>00268 <span class="preprocessor">#define KERNEL_SW(a,b) tempr=(a);(a)=(b);(b)=tempr</span>
+<a name="l00269"></a>00269 <span class="preprocessor"></span><span class="keyword">static</span> <span class="keywordtype">void</span> 
+<a name="l00270"></a>00270 reverse_tanh_kernel(<span class="keywordtype">double</span> * data, <span class="keywordtype">int</span> nn)
+<a name="l00271"></a>00271 {
+<a name="l00272"></a>00272     <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>   n,
+<a name="l00273"></a>00273                     mmax,
+<a name="l00274"></a>00274                     m,
+<a name="l00275"></a>00275                     i, j,
+<a name="l00276"></a>00276                     istep ;
+<a name="l00277"></a>00277     <span class="keywordtype">double</span>  wtemp,
+<a name="l00278"></a>00278             wr,
+<a name="l00279"></a>00279             wpr,
+<a name="l00280"></a>00280             wpi,
+<a name="l00281"></a>00281             wi,
+<a name="l00282"></a>00282             theta;
+<a name="l00283"></a>00283     <span class="keywordtype">double</span>  tempr,
+<a name="l00284"></a>00284             tempi;
+<a name="l00285"></a>00285 
+<a name="l00286"></a>00286     n = (<span class="keywordtype">unsigned</span> long)nn << 1;
+<a name="l00287"></a>00287     j = 1;
+<a name="l00288"></a>00288     <span class="keywordflow">for</span> (i=1 ; i<n ; i+=2) {
+<a name="l00289"></a>00289         <span class="keywordflow">if</span> (j > i) {
+<a name="l00290"></a>00290             KERNEL_SW(data[j-1],data[i-1]);
+<a name="l00291"></a>00291             KERNEL_SW(data[j],data[i]);
+<a name="l00292"></a>00292         }
+<a name="l00293"></a>00293         m = n >> 1;
+<a name="l00294"></a>00294         <span class="keywordflow">while</span> (m>=2 && j>m) {
+<a name="l00295"></a>00295             j -= m;
+<a name="l00296"></a>00296             m >>= 1;
+<a name="l00297"></a>00297         }
+<a name="l00298"></a>00298         j += m;
+<a name="l00299"></a>00299     }
+<a name="l00300"></a>00300     mmax = 2;
+<a name="l00301"></a>00301     <span class="keywordflow">while</span> (n > mmax) {
+<a name="l00302"></a>00302         istep = mmax << 1;
+<a name="l00303"></a>00303         theta = 2 * PI_NUMB / mmax;
+<a name="l00304"></a>00304         wtemp = sin(0.5 * theta);
+<a name="l00305"></a>00305         wpr = -2.0 * wtemp * wtemp;
+<a name="l00306"></a>00306         wpi = sin(theta);
+<a name="l00307"></a>00307         wr  = 1.0;
+<a name="l00308"></a>00308         wi  = 0.0;
+<a name="l00309"></a>00309         <span class="keywordflow">for</span> (m=1 ; m<mmax ; m+=2) {
+<a name="l00310"></a>00310             <span class="keywordflow">for</span> (i=m ; i<=n ; i+=istep) {
+<a name="l00311"></a>00311                 j = i + mmax;
+<a name="l00312"></a>00312                 tempr = wr * data[j-1] - wi * data[j];
+<a name="l00313"></a>00313                 tempi = wr * data[j]   + wi * data[j-1];
+<a name="l00314"></a>00314                 data[j-1] = data[i-1] - tempr;
+<a name="l00315"></a>00315                 data[j]   = data[i]   - tempi;
+<a name="l00316"></a>00316                 data[i-1] += tempr;
+<a name="l00317"></a>00317                 data[i]   += tempi;
+<a name="l00318"></a>00318             }
+<a name="l00319"></a>00319             wr = (wtemp = wr) * wpr - wi * wpi + wr;
+<a name="l00320"></a>00320             wi = wi * wpr + wtemp * wpi + wi;
+<a name="l00321"></a>00321         }
+<a name="l00322"></a>00322         mmax = istep;
+<a name="l00323"></a>00323     }
+<a name="l00324"></a>00324 }
+<a name="l00325"></a>00325 <span class="preprocessor">#undef KERNEL_SW</span>
+<a name="l00326"></a>00326 <span class="preprocessor"></span>
+<a name="l00364"></a>00364 <span class="keywordtype">double</span> *
+<a name="l00365"></a>00365 sinfo_invert_linear_transform(<span class="keywordtype">double</span> *trans)
+<a name="l00366"></a>00366 {
+<a name="l00367"></a>00367     <span class="keywordtype">double</span>   *    i_trans ;
+<a name="l00368"></a>00368     <span class="keywordtype">double</span>       det ;
+<a name="l00369"></a>00369 
+<a name="l00370"></a>00370     <span class="keywordflow">if</span> (trans==NULL) <span class="keywordflow">return</span> NULL ;
+<a name="l00371"></a>00371     det = (trans[0] * trans[4]) - (trans[1] * trans[3]) ;
+<a name="l00372"></a>00372     <span class="keywordflow">if</span> (fabs(det) < 1e-6) {
+<a name="l00373"></a>00373         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"NULL determinant: cannot sinfo_invert transform"</span>) ;
+<a name="l00374"></a>00374         <span class="keywordflow">return</span> NULL ;
+<a name="l00375"></a>00375     }
+<a name="l00376"></a>00376 
+<a name="l00377"></a>00377     i_trans = cpl_calloc(6, <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>)) ;
+<a name="l00378"></a>00378 
+<a name="l00379"></a>00379     i_trans[0] =  trans[4] / det ; 
+<a name="l00380"></a>00380     i_trans[1] = -trans[1] / det ;
+<a name="l00381"></a>00381     i_trans[2] = ((trans[1] * trans[5]) - (trans[2] * trans[4])) / det ;
+<a name="l00382"></a>00382     i_trans[3] = -trans[3] / det ;
+<a name="l00383"></a>00383     i_trans[4] =  trans[0] / det ;
+<a name="l00384"></a>00384     i_trans[5] = ((trans[2] * trans[3]) - (trans[0] * trans[5])) / det ;
+<a name="l00385"></a>00385 
+<a name="l00386"></a>00386     <span class="keywordflow">return</span> i_trans ;
+<a name="l00387"></a>00387 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__resampling_8h_source.html b/html/sinfo__resampling_8h_source.html
new file mode 100644
index 0000000..9ee725d
--- /dev/null
+++ b/html/sinfo__resampling_8h_source.html
@@ -0,0 +1,101 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_resampling.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_resampling.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name     :    sinfo_resampling.h</span>
+<a name="l00022"></a>00022 <span class="comment">   Author         :    Nicolas Devillard</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on    :    Jan 04, 1996</span>
+<a name="l00024"></a>00024 <span class="comment">   Description    :    resampling routines</span>
+<a name="l00025"></a>00025 <span class="comment"></span>
+<a name="l00026"></a>00026 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="comment">/*</span>
+<a name="l00029"></a>00029 <span class="comment"></span>
+<a name="l00030"></a>00030 <span class="comment"> $Id: sinfo_resampling.h,v 1.4 2007/06/06 07:10:45 amodigli Exp $</span>
+<a name="l00031"></a>00031 <span class="comment"> $Author: amodigli $</span>
+<a name="l00032"></a>00032 <span class="comment"> $Date: 2007/06/06 07:10:45 $</span>
+<a name="l00033"></a>00033 <span class="comment"> $Revision: 1.4 $</span>
+<a name="l00034"></a>00034 <span class="comment"></span>
+<a name="l00035"></a>00035 <span class="comment"> */</span>
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="preprocessor">#ifndef SINFO_RESAMPLING_H</span>
+<a name="l00038"></a>00038 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_RESAMPLING_H</span>
+<a name="l00039"></a>00039 <span class="preprocessor"></span>
+<a name="l00040"></a>00040 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00041"></a>00041 <span class="comment">                                  Includes</span>
+<a name="l00042"></a>00042 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00043"></a>00043 
+<a name="l00044"></a>00044 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00045"></a>00045 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00046"></a>00046 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00047"></a>00047 <span class="comment">                                  Defines</span>
+<a name="l00048"></a>00048 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00049"></a>00049 <span class="preprocessor">#define TRANSFO_AFFINE          0</span>
+<a name="l00050"></a>00050 <span class="preprocessor"></span><span class="preprocessor">#define TRANSFO_DEG2            1</span>
+<a name="l00051"></a>00051 <span class="preprocessor"></span><span class="preprocessor">#define TRANSFO_HOMOGRAPHIC     2</span>
+<a name="l00052"></a>00052 <span class="preprocessor"></span>
+<a name="l00053"></a>00053 <span class="comment">/* Number of pixels set to 0 by the shift resampling */</span>
+<a name="l00054"></a>00054 <span class="preprocessor">#define    SHIFT_REJECT_L            2</span>
+<a name="l00055"></a>00055 <span class="preprocessor"></span><span class="preprocessor">#define    SHIFT_REJECT_R            2</span>
+<a name="l00056"></a>00056 <span class="preprocessor"></span><span class="preprocessor">#define    SHIFT_REJECT_T            2</span>
+<a name="l00057"></a>00057 <span class="preprocessor"></span><span class="preprocessor">#define    SHIFT_REJECT_B            2</span>
+<a name="l00058"></a>00058 <span class="preprocessor"></span>
+<a name="l00059"></a>00059 <span class="comment">/*</span>
+<a name="l00060"></a>00060 <span class="comment"> * Kernel definition in terms of sampling</span>
+<a name="l00061"></a>00061 <span class="comment"> */</span>
+<a name="l00062"></a>00062 
+<a name="l00063"></a>00063 
+<a name="l00064"></a>00064 <span class="comment">/* Number of tabulations in kernel  */</span>
+<a name="l00065"></a>00065 <span class="preprocessor">#define TABSPERPIX      (1000)</span>
+<a name="l00066"></a>00066 <span class="preprocessor"></span><span class="preprocessor">#define KERNEL_WIDTH    (2.0)</span>
+<a name="l00067"></a>00067 <span class="preprocessor"></span><span class="preprocessor">#define KERNEL_SAMPLES  (1+(int)(TABSPERPIX * KERNEL_WIDTH))</span>
+<a name="l00068"></a>00068 <span class="preprocessor"></span>
+<a name="l00069"></a>00069 <span class="preprocessor">#define TANH_STEEPNESS    (5.0)</span>
+<a name="l00070"></a>00070 <span class="preprocessor"></span>
+<a name="l00071"></a>00071 
+<a name="l00072"></a>00072 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00073"></a>00073 <span class="comment">                         Function ANSI C prototypes</span>
+<a name="l00074"></a>00074 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00075"></a>00075 
+<a name="l00100"></a>00100 <span class="keywordtype">double</span>   *
+<a name="l00101"></a>00101 sinfo_generate_interpolation_kernel(<span class="keyword">const</span> <span class="keywordtype">char</span> * kernel_type) ;
+<a name="l00102"></a>00102 
+<a name="l00103"></a>00103 
+<a name="l00115"></a>00115 <span class="keywordtype">double</span>
+<a name="l00116"></a>00116 sinfo_sinc(<span class="keywordtype">double</span> x) ;
+<a name="l00117"></a>00117 
+<a name="l00155"></a>00155 <span class="keywordtype">double</span> *
+<a name="l00156"></a>00156 sinfo_invert_linear_transform(<span class="keywordtype">double</span> *trans) ;
+<a name="l00157"></a>00157 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__shift__images_8c_source.html b/html/sinfo__shift__images_8c_source.html
new file mode 100644
index 0000000..d4dd1e8
--- /dev/null
+++ b/html/sinfo__shift__images_8c_source.html
@@ -0,0 +1,749 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_shift_images.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_shift_images.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*************************************************************************</span>
+<a name="l00020"></a>00020 <span class="comment">* E.S.O. - VLT project</span>
+<a name="l00021"></a>00021 <span class="comment">*</span>
+<a name="l00022"></a>00022 <span class="comment">*</span>
+<a name="l00023"></a>00023 <span class="comment">*</span>
+<a name="l00024"></a>00024 <span class="comment">* who       when      what</span>
+<a name="l00025"></a>00025 <span class="comment">* --------  --------  ----------------------------------------------</span>
+<a name="l00026"></a>00026 <span class="comment">* schreib  05/03/03  created</span>
+<a name="l00027"></a>00027 <span class="comment">*/</span>
+<a name="l00028"></a>00028 
+<a name="l00029"></a>00029 <span class="comment">/************************************************************************</span>
+<a name="l00030"></a>00030 <span class="comment">*   NAME</span>
+<a name="l00031"></a>00031 <span class="comment">*        sinfo_shift_images.c -</span>
+<a name="l00032"></a>00032 <span class="comment">*        some procedures to shift images in spectral direction</span>
+<a name="l00033"></a>00033 <span class="comment">*</span>
+<a name="l00034"></a>00034 <span class="comment">*   SYNOPSIS</span>
+<a name="l00035"></a>00035 <span class="comment">*   #include "sinfo_shift_images.h"</span>
+<a name="l00036"></a>00036 <span class="comment">*</span>
+<a name="l00037"></a>00037 <span class="comment">*   1) double sinfo_new_determine_shift_by_correlation ( cpl_image * refImage, </span>
+<a name="l00038"></a>00038 <span class="comment">*                                           cpl_image * shiftedImage )</span>
+<a name="l00039"></a>00039 <span class="comment">*   2) cpl_image * sinfo_new_shift_image_in_spec ( cpl_image * shiftedImage, </span>
+<a name="l00040"></a>00040 <span class="comment">                                                   double shift, </span>
+<a name="l00041"></a>00041 <span class="comment">                                                   double * sub_shift )</span>
+<a name="l00042"></a>00042 <span class="comment">*   3) cpl_image * </span>
+<a name="l00043"></a>00043 <span class="comment">       sinfo_new_fine_shift_image_in_spec_poly(cpl_image * shiftedImage, </span>
+<a name="l00044"></a>00044 <span class="comment">                                                           double sub_shift, </span>
+<a name="l00045"></a>00045 <span class="comment">                                                           int order )</span>
+<a name="l00046"></a>00046 <span class="comment">*   4) cpl_image * </span>
+<a name="l00047"></a>00047 <span class="comment">       sinfo_new_fine_shift_image_in_spec_cubicspline(cpl_image * shiftedImage, </span>
+<a name="l00048"></a>00048 <span class="comment">                                                      double sub_shift )</span>
+<a name="l00049"></a>00049 <span class="comment">*   5) cpl_imagelist * sinfo_align_cube_to_reference(cpl_imagelist * cube, </span>
+<a name="l00050"></a>00050 <span class="comment">*                                       cpl_image * refIm,</span>
+<a name="l00051"></a>00051 <span class="comment">*                                       int order,</span>
+<a name="l00052"></a>00052 <span class="comment">*                                       int shift_indicator )</span>
+<a name="l00053"></a>00053 <span class="comment">*</span>
+<a name="l00054"></a>00054 <span class="comment">*</span>
+<a name="l00055"></a>00055 <span class="comment">*   DESCRIPTION</span>
+<a name="l00056"></a>00056 <span class="comment">*</span>
+<a name="l00057"></a>00057 <span class="comment">*   1) determines the sub-pixel shift of to emission line</span>
+<a name="l00058"></a>00058 <span class="comment">*      frames by cross sinfo_correlation and fitting the sinfo_correlation</span>
+<a name="l00059"></a>00059 <span class="comment">*      function by a Gaussian</span>
+<a name="l00060"></a>00060 <span class="comment">*   2) shifts an image by a given amount to integer pixel accuracy</span>
+<a name="l00061"></a>00061 <span class="comment">*   3) shifts an image by a given amount to sub-pixel accuracy</span>
+<a name="l00062"></a>00062 <span class="comment">*   4) shifts an image by a given amount to sub-pixel accuracy</span>
+<a name="l00063"></a>00063 <span class="comment">*   5) shifts images stacked in a cube by a given amount to sub-pixel accuracy</span>
+<a name="l00064"></a>00064 <span class="comment">*</span>
+<a name="l00065"></a>00065 <span class="comment">*   FILES</span>
+<a name="l00066"></a>00066 <span class="comment">*</span>
+<a name="l00067"></a>00067 <span class="comment">*   ENVIRONMENT</span>
+<a name="l00068"></a>00068 <span class="comment">*</span>
+<a name="l00069"></a>00069 <span class="comment">*   RETURN VALUES</span>
+<a name="l00070"></a>00070 <span class="comment">*</span>
+<a name="l00071"></a>00071 <span class="comment">*   CAUTIONS</span>
+<a name="l00072"></a>00072 <span class="comment">*</span>
+<a name="l00073"></a>00073 <span class="comment">*   EXAMPLES</span>
+<a name="l00074"></a>00074 <span class="comment">*</span>
+<a name="l00075"></a>00075 <span class="comment">*   SEE ALSO</span>
+<a name="l00076"></a>00076 <span class="comment">*</span>
+<a name="l00077"></a>00077 <span class="comment">*   BUGS</span>
+<a name="l00078"></a>00078 <span class="comment">*</span>
+<a name="l00079"></a>00079 <span class="comment">*------------------------------------------------------------------------</span>
+<a name="l00080"></a>00080 <span class="comment">*/</span>
+<a name="l00081"></a>00081 
+<a name="l00082"></a>00082 <span class="comment">/*</span>
+<a name="l00083"></a>00083 <span class="comment"> * System Headers</span>
+<a name="l00084"></a>00084 <span class="comment"> */</span>
+<a name="l00085"></a>00085 
+<a name="l00086"></a>00086 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00087"></a>00087 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00088"></a>00088 <span class="preprocessor">#endif</span>
+<a name="l00089"></a>00089 <span class="preprocessor"></span><span class="preprocessor">#include "sinfo_vltPort.h"</span>
+<a name="l00090"></a>00090 <span class="preprocessor">#define POSIX_SOURCE 1</span>
+<a name="l00091"></a>00091 <span class="preprocessor"></span><span class="comment">/*</span>
+<a name="l00092"></a>00092 <span class="comment"> * Local Headers</span>
+<a name="l00093"></a>00093 <span class="comment"> */</span>
+<a name="l00094"></a>00094 <span class="preprocessor">#include "sinfo_function_1d.h"</span>
+<a name="l00095"></a>00095 <span class="preprocessor">#include "sinfo_shift_images.h"</span>
+<a name="l00096"></a>00096 <span class="preprocessor">#include "sinfo_new_resampling.h"</span>
+<a name="l00097"></a>00097 <span class="preprocessor">#include "sinfo_globals.h"</span>
+<a name="l00098"></a>00098 
+<a name="l00099"></a>00099 
+<a name="l00100"></a>00100 <span class="keyword">static</span> <span class="keywordtype">int</span> filecounter ;
+<a name="l00108"></a>00108 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00109"></a>00109 <span class="comment"> *                            Function codes</span>
+<a name="l00110"></a>00110 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00111"></a>00111 
+<a name="l00123"></a>00123 <span class="keywordtype">double</span> sinfo_new_determine_shift_by_correlation ( cpl_image * refImage, 
+<a name="l00124"></a>00124                                      cpl_image * shiftedImage )
+<a name="l00125"></a>00125 {
+<a name="l00126"></a>00126     <span class="keywordtype">int</span>          col, row ;
+<a name="l00127"></a>00127     <span class="keywordtype">int</span>           i, j, k, width;
+<a name="l00128"></a>00128     <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> convsize ;
+<a name="l00129"></a>00129     <span class="keywordtype">float</span>       * lineref ;
+<a name="l00130"></a>00130     <span class="keywordtype">float</span>       * line ;
+<a name="l00131"></a>00131     <span class="keywordtype">float</span>       * offset2 ;
+<a name="l00132"></a>00132     <span class="keywordtype">double</span>      * result ;
+<a name="l00133"></a>00133     <span class="keywordtype">double</span>       mean_offset2 ;
+<a name="l00134"></a>00134     <span class="comment">/*int          magFactor ;*/</span>
+<a name="l00135"></a>00135     <span class="keywordtype">int</span>          maxlag ;
+<a name="l00136"></a>00136     <span class="keywordtype">float</span>      * refres ;
+<a name="l00137"></a>00137     <span class="keywordtype">float</span>      * myres ;
+<a name="l00138"></a>00138     <span class="keywordtype">int</span>          halfsearch ;
+<a name="l00139"></a>00139     <span class="keywordtype">int</span>          delta ;
+<a name="l00140"></a>00140     <span class="keywordtype">double</span>       xcorr_max ;
+<a name="l00141"></a>00141     <span class="comment">/*float        arg ;*/</span>
+<a name="l00142"></a>00142     <span class="keywordtype">float</span>      par[MAXPAR] ;
+<a name="l00143"></a>00143     <span class="keywordtype">float</span>      derv_par[MAXPAR] ;
+<a name="l00144"></a>00144     <span class="keywordtype">int</span>        iters, xdim, ndat ;
+<a name="l00145"></a>00145     <span class="keywordtype">int</span>        numpar, its ;
+<a name="l00146"></a>00146     <span class="keywordtype">int</span>        * mpar ;
+<a name="l00147"></a>00147     <span class="keywordtype">float</span>      tol, lab ;
+<a name="l00148"></a>00148     <span class="keywordtype">float</span>      * xdat, * wdat ;
+<a name="l00149"></a>00149     Vector     * peak;
+<a name="l00150"></a>00150     <span class="keywordtype">char</span>       filename[FILE_NAME_SZ] ;
+<a name="l00151"></a>00151     FILE       * fp ;
+<a name="l00152"></a>00152 
+<a name="l00153"></a>00153     <span class="keywordtype">int</span> rlx=0;
+<a name="l00154"></a>00154     <span class="keywordtype">int</span> rly=0;
+<a name="l00155"></a>00155     <span class="keywordtype">int</span> slx=0;
+<a name="l00156"></a>00156     <span class="keywordtype">int</span> sly=0;
+<a name="l00157"></a>00157     <span class="keywordtype">float</span>* prdata=NULL;
+<a name="l00158"></a>00158     <span class="keywordtype">float</span>* psdata=NULL;
+<a name="l00159"></a>00159 
+<a name="l00160"></a>00160     <span class="keywordflow">if</span> ( NULL == refImage || NULL == shiftedImage )
+<a name="l00161"></a>00161     {
+<a name="l00162"></a>00162         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"image not given!"</span>) ;
+<a name="l00163"></a>00163         <span class="keywordflow">return</span> ZERO ;
+<a name="l00164"></a>00164     }
+<a name="l00165"></a>00165     rlx=cpl_image_get_size_x(refImage);
+<a name="l00166"></a>00166     rly=cpl_image_get_size_x(refImage);
+<a name="l00167"></a>00167     prdata=cpl_image_get_data_float(refImage);
+<a name="l00168"></a>00168     slx=cpl_image_get_size_x(shiftedImage);
+<a name="l00169"></a>00169     sly=cpl_image_get_size_x(shiftedImage);
+<a name="l00170"></a>00170     psdata=cpl_image_get_data_float(shiftedImage);
+<a name="l00171"></a>00171 
+<a name="l00172"></a>00172     <span class="keywordflow">if</span> ( rlx != slx || rly != sly )
+<a name="l00173"></a>00173     {
+<a name="l00174"></a>00174         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"image size not compatible!"</span>) ;
+<a name="l00175"></a>00175         <span class="keywordflow">return</span> ZERO ;
+<a name="l00176"></a>00176     }
+<a name="l00177"></a>00177     snprintf(filename, MAX_NAME_SIZE-1,<span class="stringliteral">"offset%d.list"</span>, filecounter) ;
+<a name="l00178"></a>00178 
+<a name="l00179"></a>00179     fp = fopen(filename, <span class="stringliteral">"w"</span>) ;
+<a name="l00180"></a>00180 
+<a name="l00181"></a>00181     convsize = sly;
+<a name="l00182"></a>00182 
+<a name="l00183"></a>00183     lineref = (<span class="keywordtype">float</span>*) cpl_calloc(convsize, <span class="keyword">sizeof</span>(<span class="keywordtype">float</span>) ) ;
+<a name="l00184"></a>00184     line = (<span class="keywordtype">float</span>*) cpl_calloc(convsize, <span class="keyword">sizeof</span>(<span class="keywordtype">float</span>) ) ;
+<a name="l00185"></a>00185 
+<a name="l00186"></a>00186     offset2 = (<span class="keywordtype">float</span>*) cpl_calloc(slx, <span class="keyword">sizeof</span>(<span class="keywordtype">float</span>) ) ;
+<a name="l00187"></a>00187 
+<a name="l00188"></a>00188     <span class="keywordflow">for</span> ( col = 0 ; col < slx ; col++ )
+<a name="l00189"></a>00189     {
+<a name="l00190"></a>00190         <span class="comment">/* initialize arrays */</span>
+<a name="l00191"></a>00191         <span class="keywordflow">for</span> ( row = 0 ;  row < (int) convsize ; row++ )
+<a name="l00192"></a>00192         {
+<a name="l00193"></a>00193             lineref[row] = 0. ;
+<a name="l00194"></a>00194             line[row] = 0. ;
+<a name="l00195"></a>00195         }
+<a name="l00196"></a>00196 
+<a name="l00197"></a>00197         <span class="comment">/* magnify spectral sinfo_vector by magFactor */</span>
+<a name="l00198"></a>00198         <span class="keywordflow">for</span> ( row = 0 ; row < (sly) ; row++ )
+<a name="l00199"></a>00199         {
+<a name="l00200"></a>00200       lineref[row] = prdata[col+row*slx] ;   <span class="comment">/* AM: why slx? */</span>
+<a name="l00201"></a>00201       line[row] = psdata[col+row*slx] ;
+<a name="l00202"></a>00202         }
+<a name="l00203"></a>00203 
+<a name="l00204"></a>00204         myres = sinfo_function1d_filter_lowpass(line, convsize, 
+<a name="l00205"></a>00205                                                 LOW_PASS_GAUSSIAN, 3) ;
+<a name="l00206"></a>00206         refres = sinfo_function1d_filter_lowpass(lineref, convsize, 
+<a name="l00207"></a>00207                                                  LOW_PASS_GAUSSIAN, 4) ;
+<a name="l00208"></a>00208 
+<a name="l00209"></a>00209         <span class="comment">/*  now do a cross correlaton of both convolved spectral vectors */</span>
+<a name="l00210"></a>00210         halfsearch = convsize / 2 ;
+<a name="l00211"></a>00211         result = sinfo_new_xcorrel( myres, convsize, refres, convsize, 
+<a name="l00212"></a>00212                                     halfsearch, &delta, &maxlag, &xcorr_max ) ;
+<a name="l00213"></a>00213 
+<a name="l00214"></a>00214         <span class="keywordflow">if</span> ( xcorr_max < 0. )
+<a name="l00215"></a>00215         {
+<a name="l00216"></a>00216             sinfo_function1d_del ( refres ) ;
+<a name="l00217"></a>00217             sinfo_function1d_del ( myres ) ;
+<a name="l00218"></a>00218             cpl_free (result) ; 
+<a name="l00219"></a>00219             continue ;
+<a name="l00220"></a>00220         }
+<a name="l00221"></a>00221 
+<a name="l00222"></a>00222         <span class="comment">/* in this section, we fit the sinfo_correlation function with a </span>
+<a name="l00223"></a>00223 <span class="comment">           gauss, and find its peak, th</span>
+<a name="l00224"></a>00224 <span class="comment">           us getting subpixel-accuracy */</span>
+<a name="l00225"></a>00225 
+<a name="l00226"></a>00226         i = maxlag; j = i+1;
+<a name="l00227"></a>00227         <span class="keywordflow">while</span> (result[j] < result[i]) 
+<a name="l00228"></a>00228         {
+<a name="l00229"></a>00229             i++; j++;
+<a name="l00230"></a>00230         }
+<a name="l00231"></a>00231         i = maxlag; k = i-1;
+<a name="l00232"></a>00232         <span class="keywordflow">while</span> (result[k] < result[i]) 
+<a name="l00233"></a>00233         {
+<a name="l00234"></a>00234             i--; k--;
+<a name="l00235"></a>00235         }
+<a name="l00236"></a>00236         width = j-k+1;
+<a name="l00237"></a>00237         <span class="comment">/* allocate memory for the spectral sinfo_vector */</span>
+<a name="l00238"></a>00238         <span class="keywordflow">if</span> ( NULL == (peak = sinfo_new_vector (width)) )
+<a name="l00239"></a>00239         {
+<a name="l00240"></a>00240             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"cannot allocate new Vector "</span>) ;
+<a name="l00241"></a>00241             fclose(fp);
+<a name="l00242"></a>00242             <span class="keywordflow">return</span> ZERO ;
+<a name="l00243"></a>00243         }
+<a name="l00244"></a>00244 
+<a name="l00245"></a>00245 
+<a name="l00246"></a>00246         <span class="comment">/* allocate memory */</span>
+<a name="l00247"></a>00247         xdat = (<span class="keywordtype">float</span> *) cpl_calloc( peak -> n_elements, <span class="keyword">sizeof</span> (<span class="keywordtype">float</span>) ) ;
+<a name="l00248"></a>00248         wdat = (<span class="keywordtype">float</span> *) cpl_calloc( peak -> n_elements, <span class="keyword">sizeof</span> (<span class="keywordtype">float</span>) ) ;
+<a name="l00249"></a>00249         mpar = (<span class="keywordtype">int</span> *)   cpl_calloc( MAXPAR, <span class="keyword">sizeof</span> (<span class="keywordtype">int</span>) ) ;
+<a name="l00250"></a>00250 
+<a name="l00251"></a>00251         <span class="comment">/* determine the values of the spectral sinfo_vector given as input */</span>
+<a name="l00252"></a>00252         <span class="comment">/* go through the chosen column */</span>
+<a name="l00253"></a>00253 
+<a name="l00254"></a>00254         <span class="keywordflow">for</span> ( i = 0 ; i < width ; i++ )
+<a name="l00255"></a>00255         {
+<a name="l00256"></a>00256             peak -> data[i] = result[k+i] ;
+<a name="l00257"></a>00257             xdat[i] = i;
+<a name="l00258"></a>00258             wdat[i] = 1.0;
+<a name="l00259"></a>00259         }
+<a name="l00260"></a>00260 
+<a name="l00261"></a>00261         <span class="comment">/* set initial values for the fitting routine */</span>
+<a name="l00262"></a>00262         xdim     = XDIM;
+<a name="l00263"></a>00263         ndat     = peak -> n_elements ;
+<a name="l00264"></a>00264         numpar   = MAXPAR ;
+<a name="l00265"></a>00265         tol      = TOL ;
+<a name="l00266"></a>00266         lab      = LAB ;
+<a name="l00267"></a>00267         its      = ITS ;
+<a name="l00268"></a>00268         par[1] = width/2.0 ;
+<a name="l00269"></a>00269         par[2] = (float) (maxlag - k) ;
+<a name="l00270"></a>00270         par[3] = (peak -> data[0] + peak -> data[peak->n_elements - 1]) / 2.0 ;
+<a name="l00271"></a>00271         par[0]  = result[maxlag] - (par[3]) ;
+<a name="l00272"></a>00272 
+<a name="l00273"></a>00273         <span class="keywordflow">for</span> ( i = 0 ; i < MAXPAR ; i++ )
+<a name="l00274"></a>00274         {
+<a name="l00275"></a>00275             derv_par[i] = 0.0 ;
+<a name="l00276"></a>00276             mpar[i] = 1 ;
+<a name="l00277"></a>00277         }
+<a name="l00278"></a>00278 
+<a name="l00279"></a>00279         <span class="comment">/* finally, do the least square fit using a sinfo_gaussian */</span>
+<a name="l00280"></a>00280         <span class="keywordflow">if</span> ( 0 > ( iters = sinfo_new_lsqfit_c( xdat, &xdim, peak -> data, wdat, 
+<a name="l00281"></a>00281                                          &ndat, par, derv_par, mpar,
+<a name="l00282"></a>00282                                          &numpar, &tol, &its, &lab )) )
+<a name="l00283"></a>00283         {
+<a name="l00284"></a>00284             <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a> (<span class="stringliteral">"sinfo_new_lsqfit_c: least squares fit failed "</span>
+<a name="l00285"></a>00285                                <span class="stringliteral">"in col: %d, error no.: %d"</span>, col, iters) ;
+<a name="l00286"></a>00286             sinfo_new_destroy_vector ( peak ) ;
+<a name="l00287"></a>00287             cpl_free ( xdat ) ;
+<a name="l00288"></a>00288             cpl_free ( wdat ) ;
+<a name="l00289"></a>00289             cpl_free ( mpar ) ;
+<a name="l00290"></a>00290             sinfo_function1d_del ( refres ) ;
+<a name="l00291"></a>00291             sinfo_function1d_del ( myres ) ;
+<a name="l00292"></a>00292             cpl_free (result) ; 
+<a name="l00293"></a>00293             continue ;
+<a name="l00294"></a>00294         }
+<a name="l00295"></a>00295 
+<a name="l00296"></a>00296         sinfo_new_destroy_vector ( peak ) ;
+<a name="l00297"></a>00297         cpl_free (xdat) ;
+<a name="l00298"></a>00298         cpl_free (wdat) ;
+<a name="l00299"></a>00299         cpl_free (mpar) ;
+<a name="l00300"></a>00300         sinfo_function1d_del ( refres ) ;
+<a name="l00301"></a>00301         sinfo_function1d_del ( myres ) ;
+<a name="l00302"></a>00302         cpl_free (result) ; 
+<a name="l00303"></a>00303  
+<a name="l00304"></a>00304         offset2[col] = (float)( k+par[2] - sly/2) ;
+<a name="l00305"></a>00305         fprintf(fp, <span class="stringliteral">"offset: %f in col: %d\n"</span>, offset2[col], col) ;
+<a name="l00306"></a>00306     }
+<a name="l00307"></a>00307 
+<a name="l00308"></a>00308     mean_offset2 = (double)sinfo_new_clean_mean (offset2, slx, 15., 15. ) ;
+<a name="l00309"></a>00309     fprintf(fp, <span class="stringliteral">"mean offset: %f\n"</span>, mean_offset2) ;
+<a name="l00310"></a>00310     fclose(fp) ;
+<a name="l00311"></a>00311 
+<a name="l00312"></a>00312     cpl_free ( lineref ) ;
+<a name="l00313"></a>00313     cpl_free ( line ) ;
+<a name="l00314"></a>00314     cpl_free ( offset2 ) ; 
+<a name="l00315"></a>00315     filecounter++ ;
+<a name="l00316"></a>00316     <span class="keywordflow">if</span> (filecounter > 100 ) filecounter = 0 ;
+<a name="l00317"></a>00317 
+<a name="l00318"></a>00318     <span class="keywordflow">return</span> mean_offset2 ;
+<a name="l00319"></a>00319 }
+<a name="l00320"></a>00320 
+<a name="l00321"></a>00321 
+<a name="l00332"></a>00332 cpl_image * 
+<a name="l00333"></a>00333 sinfo_new_shift_image_in_spec ( cpl_image * shiftedImage, 
+<a name="l00334"></a>00334                                 <span class="keywordtype">double</span> shift, 
+<a name="l00335"></a>00335                                 <span class="keywordtype">double</span> * sub_shift )
+<a name="l00336"></a>00336 {
+<a name="l00337"></a>00337     cpl_image * retIm ;
+<a name="l00338"></a>00338     <span class="keywordtype">int</span>        col, row ;
+<a name="l00339"></a>00339     <span class="keywordtype">int</span>        intshift ;
+<a name="l00340"></a>00340     <span class="keywordtype">int</span> ilx=0;
+<a name="l00341"></a>00341     <span class="keywordtype">int</span> ily=0;
+<a name="l00342"></a>00342     <span class="keywordtype">int</span> olx=0;
+<a name="l00343"></a>00343     <span class="keywordtype">int</span> oly=0;
+<a name="l00344"></a>00344 
+<a name="l00345"></a>00345     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l00346"></a>00346     <span class="keywordtype">float</span>* podata=NULL;
+<a name="l00347"></a>00347 
+<a name="l00348"></a>00348     <span class="keywordflow">if</span> ( shiftedImage == NULL )
+<a name="l00349"></a>00349     {
+<a name="l00350"></a>00350         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no image given!"</span>) ;
+<a name="l00351"></a>00351         <span class="keywordflow">return</span> NULL ;
+<a name="l00352"></a>00352     }
+<a name="l00353"></a>00353 
+<a name="l00354"></a>00354     ilx=cpl_image_get_size_x(shiftedImage);
+<a name="l00355"></a>00355     ily=cpl_image_get_size_y(shiftedImage);
+<a name="l00356"></a>00356     pidata=cpl_image_get_data_float(shiftedImage);
+<a name="l00357"></a>00357 
+<a name="l00358"></a>00358     intshift = sinfo_new_nint (shift) ;
+<a name="l00359"></a>00359     *sub_shift = shift - (double) intshift ;
+<a name="l00360"></a>00360     <span class="keywordflow">if</span> ( intshift == 0 )
+<a name="l00361"></a>00361     {
+<a name="l00362"></a>00362         retIm =cpl_image_duplicate ( shiftedImage ) ;
+<a name="l00363"></a>00363         <span class="keywordflow">return</span> retIm ;
+<a name="l00364"></a>00364     }
+<a name="l00365"></a>00365     <span class="keywordflow">else</span>
+<a name="l00366"></a>00366     {
+<a name="l00367"></a>00367         <span class="keywordflow">if</span> ( NULL == (retIm = cpl_image_new(ilx,ily,CPL_TYPE_FLOAT)) )
+<a name="l00368"></a>00368         {
+<a name="l00369"></a>00369             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"could not allocate memory!"</span>) ;
+<a name="l00370"></a>00370             <span class="keywordflow">return</span> NULL ;
+<a name="l00371"></a>00371         }
+<a name="l00372"></a>00372     }
+<a name="l00373"></a>00373 
+<a name="l00374"></a>00374     olx=cpl_image_get_size_x(retIm);
+<a name="l00375"></a>00375     oly=cpl_image_get_size_y(retIm);
+<a name="l00376"></a>00376     podata=cpl_image_get_data_float(retIm);
+<a name="l00377"></a>00377 
+<a name="l00378"></a>00378     <span class="keywordflow">for</span> ( col = 0 ; col < ilx ; col++ )
+<a name="l00379"></a>00379     {
+<a name="l00380"></a>00380         <span class="keywordflow">for</span> ( row = 0 ; row < ily ; row++ )
+<a name="l00381"></a>00381         {
+<a name="l00382"></a>00382             <span class="keywordflow">if</span> ( (row-intshift >= 0 ) && (row - intshift < oly) )
+<a name="l00383"></a>00383             {
+<a name="l00384"></a>00384                 podata[col+(row-intshift)*olx] = pidata[col+row*olx] ;
+<a name="l00385"></a>00385             }
+<a name="l00386"></a>00386         }
+<a name="l00387"></a>00387     }
+<a name="l00388"></a>00388     <span class="keywordflow">return</span> retIm ;
+<a name="l00389"></a>00389 }
+<a name="l00390"></a>00390 
+<a name="l00400"></a>00400 cpl_image * 
+<a name="l00401"></a>00401 sinfo_new_fine_shift_image_in_spec_poly ( cpl_image * shiftedImage, 
+<a name="l00402"></a>00402                                           <span class="keywordtype">double</span> sub_shift, 
+<a name="l00403"></a>00403                                           <span class="keywordtype">int</span> order )
+<a name="l00404"></a>00404 {
+<a name="l00405"></a>00405     cpl_image * retIm ;
+<a name="l00406"></a>00406 
+<a name="l00407"></a>00407     <span class="keywordtype">float</span>* spec=NULL ;
+<a name="l00408"></a>00408     <span class="keywordtype">float</span>* corrected_spec=NULL ;
+<a name="l00409"></a>00409     <span class="keywordtype">float</span>* xnum=NULL ;
+<a name="l00410"></a>00410 
+<a name="l00411"></a>00411     <span class="keywordtype">float</span> sum, new_sum ;
+<a name="l00412"></a>00412     <span class="keywordtype">float</span> eval<span class="comment">/*, dy*/</span> ;
+<a name="l00413"></a>00413     <span class="keywordtype">float</span> * imageptr ;
+<a name="l00414"></a>00414     <span class="keywordtype">int</span> row, col ;
+<a name="l00415"></a>00415     <span class="keywordtype">int</span> firstpos ;
+<a name="l00416"></a>00416     <span class="keywordtype">int</span> n_points ;
+<a name="l00417"></a>00417     <span class="keywordtype">int</span> i ;
+<a name="l00418"></a>00418     <span class="keywordtype">int</span> flag;
+<a name="l00419"></a>00419     <span class="keywordtype">int</span> ilx=0;
+<a name="l00420"></a>00420     <span class="keywordtype">int</span> ily=0;
+<a name="l00421"></a>00421     <span class="keywordtype">int</span> olx=0;
+<a name="l00422"></a>00422     <span class="keywordtype">int</span> oly=0;
+<a name="l00423"></a>00423 
+<a name="l00424"></a>00424     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l00425"></a>00425     <span class="keywordtype">float</span>* podata=NULL;
+<a name="l00426"></a>00426 
+<a name="l00427"></a>00427     <span class="keywordflow">if</span> ( shiftedImage == NULL )
+<a name="l00428"></a>00428     {
+<a name="l00429"></a>00429         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no image given!"</span>) ;
+<a name="l00430"></a>00430         <span class="keywordflow">return</span> NULL ;
+<a name="l00431"></a>00431     }
+<a name="l00432"></a>00432     ilx=cpl_image_get_size_x(shiftedImage);
+<a name="l00433"></a>00433     ily=cpl_image_get_size_y(shiftedImage);
+<a name="l00434"></a>00434     pidata=cpl_image_get_data_float(shiftedImage);
+<a name="l00435"></a>00435 
+<a name="l00436"></a>00436     <span class="keywordflow">if</span> ( order <= 0 )
+<a name="l00437"></a>00437     {
+<a name="l00438"></a>00438         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"wrong order of interpolation polynom given!"</span>) ;
+<a name="l00439"></a>00439         <span class="keywordflow">return</span> NULL ;
+<a name="l00440"></a>00440     }
+<a name="l00441"></a>00441 
+<a name="l00442"></a>00442     <span class="comment">/* allocate memory */</span>
+<a name="l00443"></a>00443     <span class="keywordflow">if</span> ( NULL == (retIm = cpl_image_new(ilx, ily,CPL_TYPE_FLOAT)) )
+<a name="l00444"></a>00444     {
+<a name="l00445"></a>00445         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"could not allocate memory!"</span>) ;
+<a name="l00446"></a>00446         <span class="keywordflow">return</span> NULL ;
+<a name="l00447"></a>00447     }
+<a name="l00448"></a>00448 
+<a name="l00449"></a>00449     olx=cpl_image_get_size_x(retIm);
+<a name="l00450"></a>00450     oly=cpl_image_get_size_y(retIm);
+<a name="l00451"></a>00451     podata=cpl_image_get_data_float(retIm);
+<a name="l00452"></a>00452 
+<a name="l00453"></a>00453     n_points = order + 1 ;
+<a name="l00454"></a>00454     <span class="keywordflow">if</span> ( n_points % 2 == 0 )
+<a name="l00455"></a>00455     {
+<a name="l00456"></a>00456         firstpos = (int)(n_points/2) - 1 ;
+<a name="l00457"></a>00457     }
+<a name="l00458"></a>00458     <span class="keywordflow">else</span>
+<a name="l00459"></a>00459     {
+<a name="l00460"></a>00460         firstpos = (int)(n_points/2) ;
+<a name="l00461"></a>00461     }
+<a name="l00462"></a>00462 
+<a name="l00463"></a>00463     spec=cpl_calloc(ily,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l00464"></a>00464     corrected_spec=cpl_calloc(ily,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l00465"></a>00465     xnum=cpl_calloc(order+1,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l00466"></a>00466 
+<a name="l00467"></a>00467 
+<a name="l00468"></a>00468     <span class="comment">/* fill the xa[] array for the polint function */</span>
+<a name="l00469"></a>00469     <span class="keywordflow">for</span> ( i = 0 ; i < n_points ; i++ )
+<a name="l00470"></a>00470     {
+<a name="l00471"></a>00471         xnum[i] = i ;
+<a name="l00472"></a>00472     }
+<a name="l00473"></a>00473 
+<a name="l00474"></a>00474     <span class="keywordflow">for</span> ( col = 0 ; col < ilx ; col++ )
+<a name="l00475"></a>00475     {
+<a name="l00476"></a>00476         <span class="keywordflow">for</span> ( row = 0 ; row < ily ; row++ )
+<a name="l00477"></a>00477         {
+<a name="l00478"></a>00478             corrected_spec[row] = 0. ;
+<a name="l00479"></a>00479         }
+<a name="l00480"></a>00480         sum = 0. ;
+<a name="l00481"></a>00481         <span class="keywordflow">for</span> ( row = 0 ; row < ily ; row++ )
+<a name="l00482"></a>00482         {
+<a name="l00483"></a>00483             spec[row] = pidata[col + row*ilx] ;
+<a name="l00484"></a>00484             <span class="keywordflow">if</span> (isnan(spec[row]) )
+<a name="l00485"></a>00485             {
+<a name="l00486"></a>00486                 spec[row] = 0. ;
+<a name="l00487"></a>00487                   
+<a name="l00488"></a>00488                 <span class="keywordflow">for</span> ( i = row - firstpos ; i < row-firstpos+n_points ; i++ )
+<a name="l00489"></a>00489                 {
+<a name="l00490"></a>00490                     <span class="keywordflow">if</span> ( i < 0 ) continue ;
+<a name="l00491"></a>00491                     <span class="keywordflow">if</span> ( i >= ily) continue  ;
+<a name="l00492"></a>00492                     corrected_spec[i] = ZERO ;
+<a name="l00493"></a>00493                 }
+<a name="l00494"></a>00494             }
+<a name="l00495"></a>00495             <span class="keywordflow">if</span> ( row != 0 && row != ily - 1 )
+<a name="l00496"></a>00496             {
+<a name="l00497"></a>00497                 sum += spec[row] ;
+<a name="l00498"></a>00498             }
+<a name="l00499"></a>00499         }
+<a name="l00500"></a>00500         
+<a name="l00501"></a>00501         new_sum = 0. ;
+<a name="l00502"></a>00502         <span class="keywordflow">for</span> ( row = 0 ; row < ily ; row++ )
+<a name="l00503"></a>00503         {
+<a name="l00504"></a>00504             <span class="comment">/* ---------------------------------------------------------------</span>
+<a name="l00505"></a>00505 <span class="comment">             * now determine the arrays of size n_points with which the</span>
+<a name="l00506"></a>00506 <span class="comment">             * polynom is determined and determine the position eval</span>
+<a name="l00507"></a>00507 <span class="comment">             * where the polynom is evaluated in polynomial interpolation.</span>
+<a name="l00508"></a>00508 <span class="comment">             * Take care of the points near the row edges!</span>
+<a name="l00509"></a>00509 <span class="comment">             */</span>
+<a name="l00510"></a>00510             <span class="keywordflow">if</span> (isnan(corrected_spec[row])) continue ;
+<a name="l00511"></a>00511             <span class="keywordflow">if</span> ( row - firstpos < 0 )
+<a name="l00512"></a>00512             {
+<a name="l00513"></a>00513                 imageptr = &spec[0] ;
+<a name="l00514"></a>00514                 eval     = sub_shift + row ;
+<a name="l00515"></a>00515             }
+<a name="l00516"></a>00516             <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( row - firstpos + n_points >= ily )
+<a name="l00517"></a>00517             {
+<a name="l00518"></a>00518                 imageptr = &spec[ily - n_points] ;
+<a name="l00519"></a>00519                 eval     = sub_shift + row + n_points - ily ;
+<a name="l00520"></a>00520             }
+<a name="l00521"></a>00521             <span class="keywordflow">else</span>
+<a name="l00522"></a>00522             {
+<a name="l00523"></a>00523                 imageptr = &spec[row-firstpos] ;
+<a name="l00524"></a>00524                 eval     = sub_shift + firstpos ;
+<a name="l00525"></a>00525             }
+<a name="l00526"></a>00526 
+<a name="l00527"></a>00527         flag=0;
+<a name="l00528"></a>00528             corrected_spec[row]=sinfo_new_nev_ille( xnum, imageptr, 
+<a name="l00529"></a>00529                                                     order, eval, &flag) ;
+<a name="l00530"></a>00530             <span class="keywordflow">if</span> ( row != 0 && row != ily - 1 )
+<a name="l00531"></a>00531             {
+<a name="l00532"></a>00532                 new_sum += corrected_spec[row] ;
+<a name="l00533"></a>00533             }
+<a name="l00534"></a>00534         }
+<a name="l00535"></a>00535 
+<a name="l00536"></a>00536         <span class="keywordflow">for</span> ( row = 0 ; row < ily ; row++ )
+<a name="l00537"></a>00537         {
+<a name="l00538"></a>00538             <span class="keywordflow">if</span> ( new_sum == 0. )
+<a name="l00539"></a>00539             {
+<a name="l00540"></a>00540                 new_sum = 1. ;
+<a name="l00541"></a>00541             }
+<a name="l00542"></a>00542             <span class="keywordflow">if</span> ( row == 0 )
+<a name="l00543"></a>00543             {
+<a name="l00544"></a>00544                 podata[col+row*olx] = ZERO ;
+<a name="l00545"></a>00545             }
+<a name="l00546"></a>00546             <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( row == ily - 1 )
+<a name="l00547"></a>00547             {
+<a name="l00548"></a>00548                 podata[col+row*olx] = ZERO ;
+<a name="l00549"></a>00549             }
+<a name="l00550"></a>00550             <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( isnan(corrected_spec[row]) )
+<a name="l00551"></a>00551             {
+<a name="l00552"></a>00552                 podata[col+row*olx] = ZERO ;
+<a name="l00553"></a>00553             }
+<a name="l00554"></a>00554             <span class="keywordflow">else</span>
+<a name="l00555"></a>00555             {
+<a name="l00556"></a>00556                 corrected_spec[row] *= sum / new_sum ;
+<a name="l00557"></a>00557                 podata[col+row*olx] = corrected_spec[row] ;
+<a name="l00558"></a>00558             }
+<a name="l00559"></a>00559         }
+<a name="l00560"></a>00560     }
+<a name="l00561"></a>00561     cpl_free(spec) ;
+<a name="l00562"></a>00562     cpl_free(corrected_spec) ;
+<a name="l00563"></a>00563     cpl_free(xnum) ;
+<a name="l00564"></a>00564     <span class="keywordflow">return</span> retIm ;
+<a name="l00565"></a>00565 }
+<a name="l00574"></a>00574 cpl_image * 
+<a name="l00575"></a>00575 sinfo_new_fine_shift_image_in_spec_cubic_spline ( cpl_image * shiftedImage, 
+<a name="l00576"></a>00576                                                   <span class="keywordtype">double</span> sub_shift )
+<a name="l00577"></a>00577 {
+<a name="l00578"></a>00578     cpl_image * retIm ;
+<a name="l00579"></a>00579     <span class="comment">/*float second_deriv[shiftedImage -> ly] ;*/</span>
+<a name="l00580"></a>00580     <span class="keywordtype">float</span>* spec=NULL ;
+<a name="l00581"></a>00581     <span class="keywordtype">float</span>* corrected_spec=NULL ;
+<a name="l00582"></a>00582     <span class="keywordtype">float</span>* xnum=NULL ;
+<a name="l00583"></a>00583     <span class="keywordtype">float</span>* eval=NULL ;
+<a name="l00584"></a>00584     <span class="keywordtype">float</span> sum, new_sum ;
+<a name="l00585"></a>00585     <span class="keywordtype">int</span> row, col ;
+<a name="l00586"></a>00586     <span class="keywordtype">int</span> i ;
+<a name="l00587"></a>00587     <span class="keywordtype">int</span> ilx=0;
+<a name="l00588"></a>00588     <span class="keywordtype">int</span> ily=0;
+<a name="l00589"></a>00589     <span class="keywordtype">int</span> olx=0;
+<a name="l00590"></a>00590     <span class="keywordtype">int</span> oly=0;
+<a name="l00591"></a>00591 
+<a name="l00592"></a>00592     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l00593"></a>00593     <span class="keywordtype">float</span>* podata=NULL;
+<a name="l00594"></a>00594 
+<a name="l00595"></a>00595     <span class="keywordflow">if</span> ( shiftedImage == NULL )
+<a name="l00596"></a>00596     {
+<a name="l00597"></a>00597         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no image given!"</span>) ;
+<a name="l00598"></a>00598         <span class="keywordflow">return</span> NULL ;
+<a name="l00599"></a>00599     }
+<a name="l00600"></a>00600     ilx=cpl_image_get_size_x(shiftedImage);
+<a name="l00601"></a>00601     ily=cpl_image_get_size_y(shiftedImage);
+<a name="l00602"></a>00602     pidata=cpl_image_get_data_float(shiftedImage);
+<a name="l00603"></a>00603 
+<a name="l00604"></a>00604     <span class="comment">/* allocate memory */</span>
+<a name="l00605"></a>00605     <span class="keywordflow">if</span> ( NULL == (retIm = cpl_image_new(ilx,ily,CPL_TYPE_FLOAT)) )
+<a name="l00606"></a>00606     {
+<a name="l00607"></a>00607         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"could not allocate memory!"</span>) ;
+<a name="l00608"></a>00608         <span class="keywordflow">return</span> NULL ;
+<a name="l00609"></a>00609     }
+<a name="l00610"></a>00610     olx=cpl_image_get_size_x(retIm);
+<a name="l00611"></a>00611     oly=cpl_image_get_size_y(retIm);
+<a name="l00612"></a>00612     podata=cpl_image_get_data_float(retIm);
+<a name="l00613"></a>00613 
+<a name="l00614"></a>00614     xnum=cpl_calloc(ily,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l00615"></a>00615     <span class="comment">/* fill the xa[] array for the spline function */</span>
+<a name="l00616"></a>00616     <span class="keywordflow">for</span> ( i = 0 ; i < ily ; i++ )
+<a name="l00617"></a>00617     {
+<a name="l00618"></a>00618         xnum[i] = i ;
+<a name="l00619"></a>00619     }
+<a name="l00620"></a>00620 
+<a name="l00621"></a>00621     spec=cpl_calloc(ily,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l00622"></a>00622     corrected_spec=cpl_calloc(ily,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l00623"></a>00623     eval=cpl_calloc(ily,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l00624"></a>00624 
+<a name="l00625"></a>00625     <span class="keywordflow">for</span> ( col = 0 ; col < ilx ; col++ )
+<a name="l00626"></a>00626     {
+<a name="l00627"></a>00627         sum = 0. ;
+<a name="l00628"></a>00628         <span class="keywordflow">for</span> ( row = 0 ; row < ily ; row++ )
+<a name="l00629"></a>00629         {
+<a name="l00630"></a>00630             spec[row] = pidata[col + row*ilx] ;
+<a name="l00631"></a>00631             <span class="keywordflow">if</span> (isnan(spec[row]) )
+<a name="l00632"></a>00632             {
+<a name="l00633"></a>00633                 <span class="keywordflow">for</span> ( i = row-1 ; i <= row+1 ; i++ )
+<a name="l00634"></a>00634                 {
+<a name="l00635"></a>00635                     <span class="keywordflow">if</span> ( i < 0 ) continue ;
+<a name="l00636"></a>00636                     <span class="keywordflow">if</span> ( i >= ily) continue ;
+<a name="l00637"></a>00637                     corrected_spec[i] = ZERO ;
+<a name="l00638"></a>00638                 }  
+<a name="l00639"></a>00639         spec[row] = 0. ;
+<a name="l00640"></a>00640             }
+<a name="l00641"></a>00641             sum += spec[row] ;
+<a name="l00642"></a>00642             eval[row] = (float)sub_shift+(<span class="keywordtype">float</span>)row ;
+<a name="l00643"></a>00643         }
+<a name="l00644"></a>00644         <span class="comment">/* now we do the spline interpolation*/</span>
+<a name="l00645"></a>00645         <span class="keywordflow">if</span> ( -1 == sinfo_function1d_natural_spline( xnum, spec, ily, eval, 
+<a name="l00646"></a>00646                                               corrected_spec, ily ) )
+<a name="l00647"></a>00647         {
+<a name="l00648"></a>00648             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"error in spline interpolation!"</span>) ;
+<a name="l00649"></a>00649             <span class="keywordflow">return</span> NULL ;
+<a name="l00650"></a>00650         }
+<a name="l00651"></a>00651         
+<a name="l00652"></a>00652         new_sum = 0. ;
+<a name="l00653"></a>00653         <span class="keywordflow">for</span> ( row = 0 ; row < ily ; row++ )
+<a name="l00654"></a>00654         {
+<a name="l00655"></a>00655             <span class="keywordflow">if</span> ( isnan(corrected_spec[row]) )
+<a name="l00656"></a>00656             {
+<a name="l00657"></a>00657                 continue ;
+<a name="l00658"></a>00658             }   
+<a name="l00659"></a>00659         new_sum += corrected_spec[row] ;
+<a name="l00660"></a>00660         }
+<a name="l00661"></a>00661 
+<a name="l00662"></a>00662         <span class="keywordflow">for</span> ( row = 0 ; row < ily ; row++ )
+<a name="l00663"></a>00663         {
+<a name="l00664"></a>00664             <span class="keywordflow">if</span> ( new_sum == 0. ) new_sum =1. ;
+<a name="l00665"></a>00665             {
+<a name="l00666"></a>00666                 <span class="keywordflow">if</span> ( isnan(corrected_spec[row]) )
+<a name="l00667"></a>00667                 {
+<a name="l00668"></a>00668                     podata[col+row*olx] = ZERO ;
+<a name="l00669"></a>00669                 }
+<a name="l00670"></a>00670                 <span class="keywordflow">else</span>
+<a name="l00671"></a>00671                 {
+<a name="l00672"></a>00672                     corrected_spec[row] *= sum / new_sum ;
+<a name="l00673"></a>00673                     podata[col+row*olx] = corrected_spec[row] ;
+<a name="l00674"></a>00674                 }
+<a name="l00675"></a>00675             }
+<a name="l00676"></a>00676         }
+<a name="l00677"></a>00677     }
+<a name="l00678"></a>00678     cpl_free(xnum);
+<a name="l00679"></a>00679     cpl_free(spec) ;
+<a name="l00680"></a>00680     cpl_free(corrected_spec) ;
+<a name="l00681"></a>00681     cpl_free(eval) ;
+<a name="l00682"></a>00682 
+<a name="l00683"></a>00683     <span class="keywordflow">return</span> retIm ;
+<a name="l00684"></a>00684 }
+<a name="l00685"></a>00685 
+<a name="l00697"></a>00697 cpl_imagelist * sinfo_align_cube_to_reference (cpl_imagelist * cube, 
+<a name="l00698"></a>00698                                  cpl_image * refIm,
+<a name="l00699"></a>00699                                  <span class="keywordtype">int</span> order,
+<a name="l00700"></a>00700                                  <span class="keywordtype">int</span> shift_indicator )
+<a name="l00701"></a>00701 {
+<a name="l00702"></a>00702     cpl_imagelist * retCube=NULL ;
+<a name="l00703"></a>00703     cpl_image * shiftedIm=NULL ;
+<a name="l00704"></a>00704     cpl_image * fineShiftedIm=NULL ;
+<a name="l00705"></a>00705     <span class="keywordtype">double</span> shift=0 ;
+<a name="l00706"></a>00706     <span class="keywordtype">double</span>  sub_shift=0 ;
+<a name="l00707"></a>00707     <span class="keywordtype">int</span> z=0;
+<a name="l00708"></a>00708     <span class="keywordtype">double</span> * ker=NULL ;
+<a name="l00709"></a>00709     cpl_image* img=NULL;
+<a name="l00710"></a>00710 
+<a name="l00711"></a>00711     <span class="keywordflow">if</span> (cube == NULL)
+<a name="l00712"></a>00712     { 
+<a name="l00713"></a>00713         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no input cube given!"</span>) ;
+<a name="l00714"></a>00714         <span class="keywordflow">return</span> NULL ;
+<a name="l00715"></a>00715     }
+<a name="l00716"></a>00716     <span class="keywordflow">if</span> (refIm == NULL)
+<a name="l00717"></a>00717     { 
+<a name="l00718"></a>00718         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no input ref. image given!"</span>) ;
+<a name="l00719"></a>00719         <span class="keywordflow">return</span> NULL ;
+<a name="l00720"></a>00720     }
+<a name="l00721"></a>00721 
+<a name="l00722"></a>00722     <span class="comment">/* allocation for a cube structure without the image planes  */</span>
+<a name="l00723"></a>00723     retCube = cpl_imagelist_new() ;
+<a name="l00724"></a>00724 
+<a name="l00725"></a>00725     <span class="keywordflow">if</span> ( shift_indicator != 0 && shift_indicator != 1 )
+<a name="l00726"></a>00726     {
+<a name="l00727"></a>00727         ker = sinfo_new_generate_interpolation_kernel(<span class="stringliteral">"tanh"</span>) ;
+<a name="l00728"></a>00728         <span class="keywordflow">if</span> (ker == NULL)
+<a name="l00729"></a>00729         {
+<a name="l00730"></a>00730             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"kernel generation failure: aborting resampling"</span>) ;
+<a name="l00731"></a>00731             <span class="keywordflow">return</span> NULL ;
+<a name="l00732"></a>00732         }
+<a name="l00733"></a>00733     }
+<a name="l00734"></a>00734     
+<a name="l00735"></a>00735     <span class="keywordflow">for</span> ( z = 0 ; z < cpl_imagelist_get_size(cube) ; z++ )
+<a name="l00736"></a>00736     {
+<a name="l00737"></a>00737       <span class="comment">/* first determine the shift by correlation with the reference image */</span>
+<a name="l00738"></a>00738       img=cpl_imagelist_get(cube,z);
+<a name="l00739"></a>00739       <span class="keywordflow">if</span> (isnan( shift=sinfo_new_determine_shift_by_correlation(refIm,img)))
+<a name="l00740"></a>00740         { 
+<a name="l00741"></a>00741             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"error in sinfo_determineShiftByCorrelation()!"</span>) ;
+<a name="l00742"></a>00742             <span class="keywordflow">return</span> NULL ;
+<a name="l00743"></a>00743         }
+<a name="l00744"></a>00744 
+<a name="l00745"></a>00745         <span class="keywordflow">if</span> ( NULL == (shiftedIm = sinfo_new_shift_image_in_spec(img,shift,
+<a name="l00746"></a>00746                                                                 &sub_shift)) ) 
+<a name="l00747"></a>00747         { 
+<a name="l00748"></a>00748             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"error in sinfo_shiftImageInSpec()!"</span>) ;
+<a name="l00749"></a>00749             <span class="keywordflow">return</span> NULL ;
+<a name="l00750"></a>00750         }
+<a name="l00751"></a>00751         <span class="keywordflow">if</span> ( shift_indicator == 0 )
+<a name="l00752"></a>00752         {
+<a name="l00753"></a>00753             <span class="keywordflow">if</span> ( NULL == (fineShiftedIm = 
+<a name="l00754"></a>00754                  sinfo_new_fine_shift_image_in_spec_poly (shiftedIm, 
+<a name="l00755"></a>00755                                                           sub_shift, order)))
+<a name="l00756"></a>00756             {
+<a name="l00757"></a>00757                 <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"error in sinfo_fineShiftImageInSpecPoly()!"</span>) ;
+<a name="l00758"></a>00758                 <span class="keywordflow">return</span> NULL ;
+<a name="l00759"></a>00759             }
+<a name="l00760"></a>00760         }
+<a name="l00761"></a>00761         <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( shift_indicator == 1)
+<a name="l00762"></a>00762         {
+<a name="l00763"></a>00763           <span class="keywordflow">if</span> ( NULL == (fineShiftedIm = 
+<a name="l00764"></a>00764                sinfo_new_fine_shift_image_in_spec_cubic_spline (shiftedIm, 
+<a name="l00765"></a>00765                                                                   sub_shift)))
+<a name="l00766"></a>00766           {
+<a name="l00767"></a>00767             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"error in fineShiftImageInSpecCubicspline()!"</span>) ;
+<a name="l00768"></a>00768             <span class="keywordflow">return</span> NULL ;
+<a name="l00769"></a>00769           }
+<a name="l00770"></a>00770         }
+<a name="l00771"></a>00771         
+<a name="l00772"></a>00772     <span class="keywordflow">else</span>
+<a name="l00773"></a>00773     {
+<a name="l00774"></a>00774       <span class="keywordflow">if</span> ( NULL == (fineShiftedIm = 
+<a name="l00775"></a>00775                sinfo_new_shift_image(shiftedIm,0.,sub_shift, ker ) ) )
+<a name="l00776"></a>00776           {
+<a name="l00777"></a>00777            <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"error in fineShiftImageInSpecCubicspline()!"</span>) ;
+<a name="l00778"></a>00778            <span class="keywordflow">return</span> NULL ;
+<a name="l00779"></a>00779           }     
+<a name="l00780"></a>00780     }
+<a name="l00781"></a>00781     cpl_imagelist_set(retCube,fineShiftedIm,z);
+<a name="l00782"></a>00782         cpl_image_delete (shiftedIm) ;
+<a name="l00783"></a>00783         cpl_image_delete (fineShiftedIm) ;
+<a name="l00784"></a>00784     }
+<a name="l00785"></a>00785     <span class="keywordflow">if</span> ( shift_indicator != 0 && shift_indicator != 1 ) cpl_free(ker) ;
+<a name="l00786"></a>00786     <span class="keywordflow">return</span> retCube ;
+<a name="l00787"></a>00787 }
+<a name="l00788"></a>00788 
+<a name="l00789"></a>00789 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__shift__images_8h_source.html b/html/sinfo__shift__images_8h_source.html
new file mode 100644
index 0000000..819f434
--- /dev/null
+++ b/html/sinfo__shift__images_8h_source.html
@@ -0,0 +1,97 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_shift_images.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_shift_images.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#ifndef SINFO_SHIFT_IMAGES_H</span>
+<a name="l00002"></a>00002 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_SHIFT_IMAGES_H</span>
+<a name="l00003"></a>00003 <span class="preprocessor"></span><span class="comment">/*</span>
+<a name="l00004"></a>00004 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00005"></a>00005 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00006"></a>00006 <span class="comment"> *</span>
+<a name="l00007"></a>00007 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00008"></a>00008 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00009"></a>00009 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00010"></a>00010 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00011"></a>00011 <span class="comment"> *</span>
+<a name="l00012"></a>00012 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00013"></a>00013 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00014"></a>00014 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00015"></a>00015 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00016"></a>00016 <span class="comment"> *</span>
+<a name="l00017"></a>00017 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00018"></a>00018 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00019"></a>00019 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00020"></a>00020 <span class="comment"> */</span>
+<a name="l00021"></a>00021 
+<a name="l00022"></a>00022 <span class="comment">/***************************************************************************</span>
+<a name="l00023"></a>00023 <span class="comment">* E.S.O. - VLT project</span>
+<a name="l00024"></a>00024 <span class="comment">*</span>
+<a name="l00025"></a>00025 <span class="comment">* "@(#) $Id: sinfo_shift_images.h,v 1.5 2008/02/12 14:21:57 amodigli Exp $"</span>
+<a name="l00026"></a>00026 <span class="comment">*</span>
+<a name="l00027"></a>00027 <span class="comment">* who       when      what</span>
+<a name="l00028"></a>00028 <span class="comment">* --------  --------  ----------------------------------------------</span>
+<a name="l00029"></a>00029 <span class="comment">* schreib  05/03/03  created</span>
+<a name="l00030"></a>00030 <span class="comment">*/</span>
+<a name="l00031"></a>00031 
+<a name="l00032"></a>00032 <span class="comment">/************************************************************************</span>
+<a name="l00033"></a>00033 <span class="comment"> * sinfo_shift_images.h</span>
+<a name="l00034"></a>00034 <span class="comment"> * shift two emission line images on each other</span>
+<a name="l00035"></a>00035 <span class="comment"> *----------------------------------------------------------------------</span>
+<a name="l00036"></a>00036 <span class="comment"> */</span>
+<a name="l00037"></a>00037 
+<a name="l00038"></a>00038 <span class="comment">/*</span>
+<a name="l00039"></a>00039 <span class="comment"> * header files</span>
+<a name="l00040"></a>00040 <span class="comment"> */</span>
+<a name="l00041"></a>00041 
+<a name="l00042"></a>00042 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include "sinfo_spectrum_ops.h"</span>
+<a name="l00044"></a>00044 <span class="preprocessor">#include "sinfo_recipes.h"</span>
+<a name="l00045"></a>00045 <span class="preprocessor">#include "sinfo_image_ops.h"</span>
+<a name="l00046"></a>00046 
+<a name="l00047"></a>00047 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00048"></a>00048 <span class="comment"> *                        Function ANSI C prototypes</span>
+<a name="l00049"></a>00049 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00050"></a>00050 
+<a name="l00062"></a>00062 <span class="keywordtype">double</span> 
+<a name="l00063"></a>00063 sinfo_new_determine_shift_by_correlation (cpl_image * refImage,
+<a name="l00064"></a>00064                                      cpl_image * shiftedImage ) ;
+<a name="l00065"></a>00065 
+<a name="l00066"></a>00066 
+<a name="l00078"></a>00078 cpl_image * 
+<a name="l00079"></a>00079 sinfo_new_shift_image_in_spec (cpl_image * shiftedImage, 
+<a name="l00080"></a>00080                                <span class="keywordtype">double</span> shift, 
+<a name="l00081"></a>00081                                <span class="keywordtype">double</span> * sub_shift ) ;
+<a name="l00082"></a>00082 
+<a name="l00083"></a>00083 
+<a name="l00093"></a>00093 cpl_image * 
+<a name="l00094"></a>00094 sinfo_new_fine_shift_image_in_spec_poly (cpl_image * shiftedImage, 
+<a name="l00095"></a>00095                                          <span class="keywordtype">double</span> sub_shift, 
+<a name="l00096"></a>00096                                          <span class="keywordtype">int</span> order ) ;
+<a name="l00097"></a>00097 
+<a name="l00107"></a>00107 cpl_image * 
+<a name="l00108"></a>00108 sinfo_new_fine_shift_image_in_spec_cubic_spline (cpl_image * shiftedImage, 
+<a name="l00109"></a>00109                                                  <span class="keywordtype">double</span> sub_shift ) ;
+<a name="l00110"></a>00110 
+<a name="l00111"></a>00111 
+<a name="l00125"></a>00125 cpl_imagelist  * 
+<a name="l00126"></a>00126 sinfo_align_cube_to_reference (cpl_imagelist * cube,
+<a name="l00127"></a>00127                                  cpl_image * refIm,
+<a name="l00128"></a>00128                                  <span class="keywordtype">int</span> order,
+<a name="l00129"></a>00129                                  <span class="keywordtype">int</span> shift_indicator ) ;
+<a name="l00130"></a>00130 
+<a name="l00131"></a>00131 
+<a name="l00132"></a>00132 
+<a name="l00133"></a>00133 <span class="preprocessor">#endif </span>
+<a name="l00135"></a>00135 <span class="preprocessor"></span><span class="comment">/*--------------------------------------------------------------------------*/</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__skycor_8c_source.html b/html/sinfo__skycor_8c_source.html
new file mode 100644
index 0000000..a8cb022
--- /dev/null
+++ b/html/sinfo__skycor_8c_source.html
@@ -0,0 +1,6541 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_skycor.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_skycor.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_skycor.c,v 1.50 2012/05/04 08:11:35 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the SINFONI Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2012/05/04 08:11:35 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.50 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span>
+<a name="l00032"></a>00032 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                                Includes</span>
+<a name="l00034"></a>00034 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 <span class="preprocessor">#include <math.h></span>
+<a name="l00036"></a>00036 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include <sinfo_cpl_size.h></span>
+<a name="l00038"></a>00038 
+<a name="l00039"></a>00039 <span class="preprocessor">#include <irplib_utils.h></span>
+<a name="l00040"></a>00040 
+<a name="l00041"></a>00041 <span class="preprocessor">#include <sinfo_skycor.h></span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include <sinfo_new_cube_ops.h></span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include "sinfo_pfits.h"</span>
+<a name="l00044"></a>00044 <span class="preprocessor">#include "sinfo_functions.h"</span>
+<a name="l00045"></a>00045 
+<a name="l00046"></a>00046 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00047"></a>00047 <span class="preprocessor">#include "sinfo_error.h"</span>
+<a name="l00048"></a>00048 <span class="preprocessor">#include "sinfo_globals.h"</span>
+<a name="l00049"></a>00049 <span class="preprocessor">#include "sinfo_utils_wrappers.h"</span>
+<a name="l00050"></a>00050 <span class="preprocessor">#include "sinfo_utl_cube2spectrum.h"</span>
+<a name="l00051"></a>00051 <span class="preprocessor">#include "sinfo_pro_types.h"</span>
+<a name="l00052"></a>00052 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00053"></a>00053 <span class="comment">                                Defines</span>
+<a name="l00054"></a>00054 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00055"></a>00055 
+<a name="l00056"></a>00056 <span class="preprocessor">#define BAND_H_WAVE_MIN 1.445 //not used</span>
+<a name="l00057"></a>00057 <span class="preprocessor"></span><span class="preprocessor">#define BAND_H_WAVE_MAX 1.820 //not used</span>
+<a name="l00058"></a>00058 <span class="preprocessor"></span>
+<a name="l00059"></a>00059 <span class="preprocessor">#define BAND_K_WAVE_MIN 1.945 //not used</span>
+<a name="l00060"></a>00060 <span class="preprocessor"></span><span class="preprocessor">#define BAND_K_WAVE_MAX 2.460 //not used</span>
+<a name="l00061"></a>00061 <span class="preprocessor"></span>
+<a name="l00062"></a>00062 <span class="preprocessor">#define BAND_J_WAVE_MIN 1.445 //not used</span>
+<a name="l00063"></a>00063 <span class="preprocessor"></span><span class="preprocessor">#define BAND_J_WAVE_MAX 1.82  //not used</span>
+<a name="l00064"></a>00064 <span class="preprocessor"></span>
+<a name="l00065"></a>00065 <span class="preprocessor">#define SINFO_FIT_BKG_TEMP 280.</span>
+<a name="l00066"></a>00066 <span class="preprocessor"></span><span class="preprocessor">#define SKY_THRES 0.95</span>
+<a name="l00067"></a>00067 <span class="preprocessor"></span><span class="preprocessor">#define SKY_LINE_MAX_CUT 4      </span><span class="comment">/* this should be 4 */</span>
+<a name="l00068"></a>00068 <span class="preprocessor">#define SKY_LINE_MIN_CUT 4      </span><span class="comment">/* this should be 4 */</span>
+<a name="l00069"></a>00069 
+<a name="l00070"></a>00070 
+<a name="l00071"></a>00071 <span class="preprocessor">#define XCOR_YSHIFT_KS_CLIP 5      </span><span class="comment">/* this should be 5 */</span>
+<a name="l00072"></a>00072 
+<a name="l00073"></a>00073 
+<a name="l00074"></a>00074 <span class="preprocessor">#define HPLANK 6.62606876e-34;   // J s</span>
+<a name="l00075"></a>00075 <span class="preprocessor"></span><span class="preprocessor">#define CLIGHT 2.99792458e+08;   // m / s</span>
+<a name="l00076"></a>00076 <span class="preprocessor"></span><span class="preprocessor">#define KBOLTZ 1.3806503e-23;    // J / K</span>
+<a name="l00077"></a>00077 <span class="preprocessor"></span><span class="preprocessor">#define AMOEBA_FTOL 1.e-5</span>
+<a name="l00078"></a>00078 <span class="preprocessor"></span><span class="preprocessor">#define NBOUND 14</span>
+<a name="l00079"></a>00079 <span class="preprocessor"></span><span class="preprocessor">#define NROT   25</span>
+<a name="l00080"></a>00080 <span class="preprocessor"></span><span class="preprocessor">#define N_ITER_FIT_LM 15</span>
+<a name="l00081"></a>00081 <span class="preprocessor"></span><span class="preprocessor">#define N_ITER_FIT_AMOEBA 10</span>
+<a name="l00082"></a>00082 <span class="preprocessor"></span>
+<a name="l00083"></a>00083 <span class="keywordtype">double</span> sinfo_scale_fct=1;
+<a name="l00084"></a>00084 <span class="keyword">static</span> cpl_vector* sa_vx=NULL;
+<a name="l00085"></a>00085 <span class="keyword">static</span> cpl_vector* sa_vy=NULL;
+<a name="l00086"></a>00086 
+<a name="l00087"></a>00087 <span class="keyword">static</span> cpl_vector* sa_ox=NULL;
+<a name="l00088"></a>00088 <span class="keyword">static</span> cpl_vector* sa_oy=NULL;
+<a name="l00089"></a>00089 <span class="keyword">static</span> cpl_vector* sa_sy=NULL;
+<a name="l00090"></a>00090 
+<a name="l00091"></a>00091 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00092"></a>00092 <span class="comment">                            Functions prototypes</span>
+<a name="l00093"></a>00093 <span class="comment">-----------------------------------------------------------------------------*/</span>
+<a name="l00094"></a>00094 cpl_vector* sinfo_sky_background_estimate(cpl_vector *spectrum,
+<a name="l00095"></a>00095                                              <span class="keywordtype">int</span> msize,
+<a name="l00096"></a>00096                                              <span class="keywordtype">int</span> fsize);
+<a name="l00097"></a>00097 
+<a name="l00098"></a>00098 
+<a name="l00099"></a>00099 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00100"></a>00100 sinfo_scales_obj_sky_cubes(cpl_imagelist* obj_cub,
+<a name="l00101"></a>00101                             cpl_imagelist* sky_cub,
+<a name="l00102"></a>00102                             cpl_table* bkg,
+<a name="l00103"></a>00103                             cpl_table* rscale,
+<a name="l00104"></a>00104                             cpl_imagelist** obj_cor);
+<a name="l00105"></a>00105 
+<a name="l00106"></a>00106 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00107"></a>00107 sinfo_sub_thr_bkg_from_obj_cube(cpl_imagelist* obj_cub,
+<a name="l00108"></a>00108                 cpl_table* int_sky,
+<a name="l00109"></a>00109                 cpl_imagelist** obj_cor);
+<a name="l00110"></a>00110 
+<a name="l00111"></a>00111 <span class="keyword">static</span> cpl_vector*
+<a name="l00112"></a>00112 sinfo_filter_min(<span class="keyword">const</span> cpl_vector* vi, <span class="keyword">const</span> <span class="keywordtype">int</span> size);
+<a name="l00113"></a>00113 
+<a name="l00114"></a>00114 <span class="keyword">static</span> cpl_vector*
+<a name="l00115"></a>00115 sinfo_filter_max(<span class="keyword">const</span> cpl_vector* vi, <span class="keyword">const</span> <span class="keywordtype">int</span> size);
+<a name="l00116"></a>00116 
+<a name="l00117"></a>00117 <span class="keyword">static</span> cpl_vector*
+<a name="l00118"></a>00118 sinfo_filter_smo(<span class="keyword">const</span> cpl_vector* vi, <span class="keyword">const</span> <span class="keywordtype">int</span> size);
+<a name="l00119"></a>00119 
+<a name="l00120"></a>00120 <span class="keyword">static</span> cpl_imagelist*
+<a name="l00121"></a>00121 sinfo_cube_zshift_simple(cpl_imagelist* inp,
+<a name="l00122"></a>00122                         <span class="keyword">const</span> <span class="keywordtype">float</span> shift);
+<a name="l00123"></a>00123 
+<a name="l00124"></a>00124 <span class="keyword">static</span> <span class="keywordtype">void</span>
+<a name="l00125"></a>00125 sinfo_optimise_sky_sub(<span class="keyword">const</span> <span class="keywordtype">double</span> wtol,
+<a name="l00126"></a>00126                        <span class="keyword">const</span> <span class="keywordtype">double</span> line_hw,
+<a name="l00127"></a>00127                        <span class="keyword">const</span> <span class="keywordtype">int</span> method,
+<a name="l00128"></a>00128                        <span class="keyword">const</span> <span class="keywordtype">int</span> do_rot,
+<a name="l00129"></a>00129                        cpl_table* lrange,
+<a name="l00130"></a>00130                        cpl_table* lambda,
+<a name="l00131"></a>00131                        cpl_table* lr41,
+<a name="l00132"></a>00132                        cpl_table* lr52,
+<a name="l00133"></a>00133                        cpl_table* lr63,
+<a name="l00134"></a>00134                        cpl_table* lr74,
+<a name="l00135"></a>00135                        cpl_table* lr02,
+<a name="l00136"></a>00136                        cpl_table* lr85,
+<a name="l00137"></a>00137                        cpl_table* lr20,
+<a name="l00138"></a>00138                        cpl_table* lr31,
+<a name="l00139"></a>00139                        cpl_table* lr42,
+<a name="l00140"></a>00140                        cpl_table* lr53,
+<a name="l00141"></a>00141                        cpl_table* lr64,
+<a name="l00142"></a>00142                        cpl_table* lr75,
+<a name="l00143"></a>00143                        cpl_table* lr86,
+<a name="l00144"></a>00144                        cpl_table* lr97,
+<a name="l00145"></a>00145                        cpl_table* lr00,
+<a name="l00146"></a>00146                        cpl_table** int_obj,
+<a name="l00147"></a>00147                        cpl_table** int_sky,
+<a name="l00148"></a>00148                        cpl_table** rscale);
+<a name="l00149"></a>00149 
+<a name="l00150"></a>00150 <span class="keyword">static</span> <span class="keywordtype">void</span>
+<a name="l00151"></a>00151 sinfo_shift_sky(cpl_frame** sky_frm,
+<a name="l00152"></a>00152                 cpl_table** int_sky,
+<a name="l00153"></a>00153                 <span class="keyword">const</span> <span class="keywordtype">double</span> zshift);
+<a name="l00154"></a>00154 
+<a name="l00155"></a>00155 <span class="keyword">static</span> <span class="keywordtype">double</span>
+<a name="l00156"></a>00156 sinfo_xcorr(cpl_table* int_obj,
+<a name="l00157"></a>00157             cpl_table* int_sky,
+<a name="l00158"></a>00158             cpl_table* lambda,
+<a name="l00159"></a>00159             <span class="keyword">const</span> <span class="keywordtype">double</span> dispersion,
+<a name="l00160"></a>00160             <span class="keyword">const</span> <span class="keywordtype">double</span> line_hw);
+<a name="l00161"></a>00161 
+<a name="l00162"></a>00162 <span class="keyword">static</span> cpl_table*
+<a name="l00163"></a>00163 sinfo_interpolate_sky(<span class="keyword">const</span> cpl_table* inp,<span class="keyword">const</span> cpl_table* lambdas);
+<a name="l00164"></a>00164 
+<a name="l00165"></a>00165 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00166"></a>00166 sinfo_check_screw_values(cpl_table** int_obj,
+<a name="l00167"></a>00167                          cpl_table** int_sky,
+<a name="l00168"></a>00168                          cpl_table* grange,
+<a name="l00169"></a>00169                          <span class="keyword">const</span> <span class="keywordtype">double</span> wtol);
+<a name="l00170"></a>00170 
+<a name="l00171"></a>00171 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00172"></a>00172 sinfo_choose_good_sky_pixels(cpl_frame* obj_frm,
+<a name="l00173"></a>00173                              cpl_image* r_img,
+<a name="l00174"></a>00174                              cpl_image* g_img,
+<a name="l00175"></a>00175                              <span class="keyword">const</span> <span class="keywordtype">double</span> min_frac,
+<a name="l00176"></a>00176                              cpl_image** mask);
+<a name="l00177"></a>00177 
+<a name="l00178"></a>00178 
+<a name="l00179"></a>00179 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00180"></a>00180 sinfo_sum_spectra(<span class="keyword">const</span> cpl_frame* obj,
+<a name="l00181"></a>00181                   <span class="keyword">const</span> cpl_frame* sky,
+<a name="l00182"></a>00182                   cpl_image* mask,
+<a name="l00183"></a>00183                   cpl_table* wrange,
+<a name="l00184"></a>00184                   <span class="keyword">const</span> <span class="keywordtype">int</span> llx,
+<a name="l00185"></a>00185                   <span class="keyword">const</span> <span class="keywordtype">int</span> lly,
+<a name="l00186"></a>00186                   <span class="keyword">const</span> <span class="keywordtype">int</span> urx,
+<a name="l00187"></a>00187                   <span class="keyword">const</span> <span class="keywordtype">int</span> ury,
+<a name="l00188"></a>00188                   cpl_table** int_obj,
+<a name="l00189"></a>00189                   cpl_table** int_sky);
+<a name="l00190"></a>00190 
+<a name="l00191"></a>00191 <span class="keywordtype">int</span>
+<a name="l00192"></a>00192 sinfo_thermal_background2(cpl_table* int_sky,
+<a name="l00193"></a>00193                          cpl_table* lambda,
+<a name="l00194"></a>00194                          cpl_table* lrange,
+<a name="l00195"></a>00195               cpl_table** bkg);
+<a name="l00196"></a>00196 
+<a name="l00197"></a>00197 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00198"></a>00198 sinfo_thermal_background(cpl_table* int_sky,
+<a name="l00199"></a>00199                          cpl_table* lambda,
+<a name="l00200"></a>00200                          cpl_table* lrange,
+<a name="l00201"></a>00201                          <span class="keyword">const</span> <span class="keywordtype">double</span> temp,
+<a name="l00202"></a>00202                          <span class="keyword">const</span> <span class="keywordtype">int</span> niter,
+<a name="l00203"></a>00203                          <span class="keyword">const</span> <span class="keywordtype">int</span> filter_width,
+<a name="l00204"></a>00204                          <span class="keyword">const</span> <span class="keywordtype">double</span> wtol,
+<a name="l00205"></a>00205                          cpl_table** bkg,
+<a name="l00206"></a>00206                          <span class="keywordtype">int</span>* success_fit);
+<a name="l00207"></a>00207 
+<a name="l00208"></a>00208 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00209"></a>00209 sinfo_object_flag_sky_pixels(cpl_frame* obj_frm,
+<a name="l00210"></a>00210                              cpl_table* lambda,
+<a name="l00211"></a>00211                              cpl_table* mrange,
+<a name="l00212"></a>00212                  cpl_imagelist* flag_data,
+<a name="l00213"></a>00213                              <span class="keyword">const</span> <span class="keywordtype">double</span> tol,
+<a name="l00214"></a>00214                              cpl_image** g_img,
+<a name="l00215"></a>00215                              cpl_image** r_img,
+<a name="l00216"></a>00216                              cpl_image** image);
+<a name="l00217"></a>00217 
+<a name="l00218"></a>00218 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00219"></a>00219 sinfo_object_flag_low_values(cpl_frame* obj_frm,
+<a name="l00220"></a>00220                              <span class="keyword">const</span> <span class="keywordtype">double</span> cnt,
+<a name="l00221"></a>00221                              <span class="keyword">const</span> <span class="keywordtype">double</span> sig,
+<a name="l00222"></a>00222                              cpl_imagelist** flag_data);
+<a name="l00223"></a>00223 
+<a name="l00224"></a>00224 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00225"></a>00225 sinfo_object_estimate_noise(cpl_frame* obj_frm, <span class="keyword">const</span> <span class="keywordtype">int</span> obj_noise_fit,
+<a name="l00226"></a>00226                             <span class="keywordtype">double</span>* centre, <span class="keywordtype">double</span>* noise);
+<a name="l00227"></a>00227 
+<a name="l00228"></a>00228 
+<a name="l00229"></a>00229 
+<a name="l00230"></a>00230 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00231"></a>00231 sinfo_set_ranges(cpl_frame* obj_frm,
+<a name="l00232"></a>00232                  cpl_frame* sky_frm,
+<a name="l00233"></a>00233                  cpl_parameterlist* cfg,
+<a name="l00234"></a>00234                  cpl_table** lambda,
+<a name="l00235"></a>00235                  cpl_table** lr41,
+<a name="l00236"></a>00236                  cpl_table** lr52,
+<a name="l00237"></a>00237                  cpl_table** lr63,
+<a name="l00238"></a>00238                  cpl_table** lr74,
+<a name="l00239"></a>00239                  cpl_table** lr02,
+<a name="l00240"></a>00240                  cpl_table** lr85,
+<a name="l00241"></a>00241                  cpl_table** lr20,
+<a name="l00242"></a>00242                  cpl_table** lr31,
+<a name="l00243"></a>00243                  cpl_table** lr42,
+<a name="l00244"></a>00244                  cpl_table** lr53,
+<a name="l00245"></a>00245                  cpl_table** lr64,
+<a name="l00246"></a>00246                  cpl_table** lr75,
+<a name="l00247"></a>00247                  cpl_table** lr86,
+<a name="l00248"></a>00248                  cpl_table** lr97,
+<a name="l00249"></a>00249                  cpl_table** lr00,
+<a name="l00250"></a>00250                  cpl_table** lrange,
+<a name="l00251"></a>00251                  cpl_table** grange,
+<a name="l00252"></a>00252                  cpl_table** lambdas,
+<a name="l00253"></a>00253                  cpl_table** mrange,
+<a name="l00254"></a>00254                  <span class="keywordtype">int</span>* sky_interp_sw,
+<a name="l00255"></a>00255                  <span class="keywordtype">double</span>* dispersion);
+<a name="l00256"></a>00256 
+<a name="l00257"></a>00257 
+<a name="l00258"></a>00258 <span class="keyword">static</span> cpl_table*
+<a name="l00259"></a>00259 sinfo_table_extract_rest(cpl_table* inp,
+<a name="l00260"></a>00260                          cpl_table* low,
+<a name="l00261"></a>00261                          cpl_table* med,
+<a name="l00262"></a>00262                          <span class="keyword">const</span> <span class="keywordtype">double</span> wtol);
+<a name="l00263"></a>00263 
+<a name="l00264"></a>00264 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00265"></a>00265 sinfo_get_sub_regions(cpl_table* sky,
+<a name="l00266"></a>00266                       cpl_table* x1,
+<a name="l00267"></a>00267                       cpl_table* pos,
+<a name="l00268"></a>00268                       <span class="keyword">const</span> <span class="keywordtype">double</span> wtol,
+<a name="l00269"></a>00269                       <span class="keyword">const</span> <span class="keywordtype">int</span> npixw,
+<a name="l00270"></a>00270                       cpl_table** sub_regions);
+<a name="l00271"></a>00271 
+<a name="l00272"></a>00272 
+<a name="l00273"></a>00273 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00274"></a>00274 sinfo_get_obj_sky_wav_sub(cpl_table* obj,
+<a name="l00275"></a>00275                           cpl_table* sky,
+<a name="l00276"></a>00276                           cpl_table* wav,
+<a name="l00277"></a>00277                           cpl_table* sel,
+<a name="l00278"></a>00278                           <span class="keyword">const</span> <span class="keywordtype">double</span> wtol,
+<a name="l00279"></a>00279                           cpl_table** sub_obj,
+<a name="l00280"></a>00280                           cpl_table** sub_sky,
+<a name="l00281"></a>00281                           cpl_table** sub_wav);
+<a name="l00282"></a>00282 
+<a name="l00283"></a>00283 
+<a name="l00284"></a>00284 <span class="keyword">static</span> cpl_table*
+<a name="l00285"></a>00285 sinfo_find_rot_waves(<span class="keyword">const</span> <span class="keywordtype">double</span> w_rot[],
+<a name="l00286"></a>00286                      <span class="keyword">const</span> <span class="keywordtype">int</span> npix_w,
+<a name="l00287"></a>00287                      <span class="keyword">const</span> <span class="keywordtype">double</span> w_step,
+<a name="l00288"></a>00288                      cpl_table* range);
+<a name="l00289"></a>00289 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00290"></a>00290 sinfo_compute_line_ratio(cpl_table* obj,
+<a name="l00291"></a>00291                          cpl_table* sky,
+<a name="l00292"></a>00292                          <span class="keyword">const</span> <span class="keywordtype">double</span> wtol,
+<a name="l00293"></a>00293                          <span class="keyword">const</span> <span class="keywordtype">int</span> meth,
+<a name="l00294"></a>00294                          <span class="keyword">const</span> cpl_table* sel_regions,
+<a name="l00295"></a>00295                          cpl_table* cont_regions,
+<a name="l00296"></a>00296                          <span class="keywordtype">double</span>* r);
+<a name="l00297"></a>00297 
+<a name="l00298"></a>00298 <span class="keyword">static</span> cpl_table*
+<a name="l00299"></a>00299 sinfo_table_subtract_continuum(cpl_table* lin,cpl_table* cnt);
+<a name="l00300"></a>00300 
+<a name="l00301"></a>00301 <span class="keyword">static</span> <span class="keywordtype">double</span>
+<a name="l00302"></a>00302 sinfo_fit_bkg(<span class="keywordtype">double</span> p[]);
+<a name="l00303"></a>00303 
+<a name="l00304"></a>00304 <span class="keyword">static</span> <span class="keywordtype">double</span>
+<a name="l00305"></a>00305 sinfo_fit_sky(<span class="keywordtype">double</span> p[]);
+<a name="l00306"></a>00306 
+<a name="l00307"></a>00307 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00308"></a>00308 sinfo_get_line_ratio_amoeba(cpl_table* obj,
+<a name="l00309"></a>00309                             cpl_table* sky,
+<a name="l00310"></a>00310                             <span class="keywordtype">double</span>* r);
+<a name="l00311"></a>00311 
+<a name="l00312"></a>00312 <span class="keyword">static</span> cpl_table*
+<a name="l00313"></a>00313 sinfo_table_interpol(cpl_table* obj_lin,
+<a name="l00314"></a>00314                      cpl_table* obj_cnt,
+<a name="l00315"></a>00315                      cpl_table* sky_lin,
+<a name="l00316"></a>00316                      cpl_table* sky_cnt,
+<a name="l00317"></a>00317                      <span class="keyword">const</span> <span class="keywordtype">double</span> r);
+<a name="l00318"></a>00318 
+<a name="l00319"></a>00319 
+<a name="l00320"></a>00320 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00321"></a>00321 sinfo_get_line_ratio(cpl_table* obj_lin,
+<a name="l00322"></a>00322                      cpl_table* obj_cnt,
+<a name="l00323"></a>00323                      cpl_table* sky_lin,
+<a name="l00324"></a>00324                      cpl_table* sky_cnt,
+<a name="l00325"></a>00325                      <span class="keyword">const</span> <span class="keywordtype">int</span> method,
+<a name="l00326"></a>00326                      <span class="keywordtype">double</span>* r);
+<a name="l00327"></a>00327 
+<a name="l00328"></a>00328 <span class="keyword">static</span> cpl_table*
+<a name="l00329"></a>00329 sinfo_table_shift_simple(cpl_table* inp,
+<a name="l00330"></a>00330                          <span class="keyword">const</span> <span class="keywordtype">char</span>* col,
+<a name="l00331"></a>00331                          <span class="keyword">const</span> <span class="keywordtype">double</span> shift);
+<a name="l00332"></a>00332 <span class="comment">/*</span>
+<a name="l00333"></a>00333 <span class="comment">static int</span>
+<a name="l00334"></a>00334 <span class="comment">sinfo_table_set_column_invalid(cpl_table** int_sky,const char* col);</span>
+<a name="l00335"></a>00335 <span class="comment">*/</span>
+<a name="l00336"></a>00336 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00337"></a>00337 sinfo_table_set(cpl_table** out,
+<a name="l00338"></a>00338                 <span class="keyword">const</span> cpl_table* ref,
+<a name="l00339"></a>00339                 <span class="keyword">const</span> <span class="keywordtype">double</span> val,
+<a name="l00340"></a>00340                 <span class="keyword">const</span> <span class="keywordtype">double</span> tol);
+<a name="l00341"></a>00341 
+<a name="l00342"></a>00342 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00343"></a>00343 sinfo_table_threshold(cpl_table** t,
+<a name="l00344"></a>00344                       <span class="keyword">const</span> <span class="keywordtype">char</span>* column,
+<a name="l00345"></a>00345                       <span class="keyword">const</span> <span class="keywordtype">double</span> low_cut,
+<a name="l00346"></a>00346                       <span class="keyword">const</span> <span class="keywordtype">double</span> hig_cut,
+<a name="l00347"></a>00347                       <span class="keyword">const</span> <span class="keywordtype">double</span> low_ass,
+<a name="l00348"></a>00348                       <span class="keyword">const</span> <span class="keywordtype">double</span> hig_ass);
+<a name="l00349"></a>00349 
+<a name="l00350"></a>00350 
+<a name="l00351"></a>00351 
+<a name="l00352"></a>00352 
+<a name="l00353"></a>00353 <span class="keyword">static</span> <span class="keywordtype">double</span> sinfo_fac(<span class="keyword">const</span> <span class="keywordtype">double</span> x, <span class="keyword">const</span> <span class="keywordtype">double</span> t);
+<a name="l00354"></a>00354 
+<a name="l00355"></a>00355 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_fitbkg(<span class="keyword">const</span> <span class="keywordtype">double</span> x[],
+<a name="l00356"></a>00356                         <span class="keyword">const</span> <span class="keywordtype">double</span> a[],
+<a name="l00357"></a>00357                         <span class="keywordtype">double</span> *result);
+<a name="l00358"></a>00358 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_fitbkg_derivative(<span class="keyword">const</span> <span class="keywordtype">double</span> x[],
+<a name="l00359"></a>00359                                    <span class="keyword">const</span> <span class="keywordtype">double</span> a[],
+<a name="l00360"></a>00360                        <span class="keywordtype">double</span> result[]);
+<a name="l00361"></a>00361 
+<a name="l00362"></a>00362 
+<a name="l00363"></a>00363 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00364"></a>00364 sinfo_convolve_kernel(cpl_table** t, <span class="keyword">const</span> <span class="keywordtype">int</span> rad);
+<a name="l00365"></a>00365 <span class="keywordtype">int</span>
+<a name="l00366"></a>00366 sinfo_convolve_kernel2(cpl_table** t, <span class="keyword">const</span> <span class="keywordtype">int</span> rad);
+<a name="l00367"></a>00367 
+<a name="l00368"></a>00368 <span class="keywordtype">int</span>
+<a name="l00369"></a>00369 sinfo_convolve_gauss(cpl_table** t, <span class="keyword">const</span> <span class="keywordtype">int</span> rad, <span class="keyword">const</span> <span class="keywordtype">double</span> fwhm);
+<a name="l00370"></a>00370 <span class="keywordtype">int</span>
+<a name="l00371"></a>00371 sinfo_convolve_exp(cpl_table** t, <span class="keyword">const</span> <span class="keywordtype">int</span> rad, <span class="keyword">const</span> <span class="keywordtype">double</span> fwhm);
+<a name="l00372"></a>00372 
+<a name="l00373"></a>00373 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00374"></a>00374 sinfo_table_sky_obj_flag_nan(cpl_table** s,cpl_table** o, cpl_table** w);
+<a name="l00375"></a>00375 
+<a name="l00376"></a>00376 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00377"></a>00377 sinfo_table_set_nan_out_min_max(cpl_table** s,
+<a name="l00378"></a>00378                                 <span class="keyword">const</span> <span class="keywordtype">char</span>* c,
+<a name="l00379"></a>00379                                 <span class="keyword">const</span> <span class="keywordtype">double</span> min,
+<a name="l00380"></a>00380                                 <span class="keyword">const</span> <span class="keywordtype">double</span> max);
+<a name="l00381"></a>00381 
+<a name="l00382"></a>00382 
+<a name="l00383"></a>00383 
+<a name="l00384"></a>00384 
+<a name="l00385"></a>00385 <span class="keyword">static</span> <span class="keywordtype">double</span>
+<a name="l00386"></a>00386 sinfo_gaussian_amp(<span class="keywordtype">double</span> area,<span class="keywordtype">double</span> sigma,<span class="keywordtype">double</span> x,<span class="keywordtype">double</span> x0,<span class="keywordtype">double</span> off);
+<a name="l00387"></a>00387 <span class="keyword">static</span> <span class="keywordtype">double</span>
+<a name="l00388"></a>00388 sinfo_gaussian_area(<span class="keywordtype">double</span> amp,<span class="keywordtype">double</span> sigma,<span class="keywordtype">double</span> x,<span class="keywordtype">double</span> x0,<span class="keywordtype">double</span> off);
+<a name="l00389"></a>00389 
+<a name="l00390"></a>00390 <span class="keywordtype">int</span>
+<a name="l00391"></a>00391 sinfo_table_smooth_column(cpl_table** t, <span class="keyword">const</span> <span class="keywordtype">char</span>* c, <span class="keyword">const</span> <span class="keywordtype">int</span> r);
+<a name="l00392"></a>00392 
+<a name="l00393"></a>00393 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00394"></a>00394 sinfo_image_flag_nan(cpl_image** im);
+<a name="l00395"></a>00395 
+<a name="l00396"></a>00396 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00397"></a>00397 sinfo_table_flag_nan(cpl_table** t,<span class="keyword">const</span> <span class="keywordtype">char</span>* label);
+<a name="l00398"></a>00398 
+<a name="l00399"></a>00399 
+<a name="l00400"></a>00400 
+<a name="l00401"></a>00401 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00402"></a>00402 sinfo_cnt_mask_thresh_and_obj_finite(<span class="keyword">const</span> cpl_image* mask,
+<a name="l00403"></a>00403                                      <span class="keyword">const</span> <span class="keywordtype">double</span> t,
+<a name="l00404"></a>00404                                      <span class="keyword">const</span> cpl_image* obj);
+<a name="l00405"></a>00405 
+<a name="l00406"></a>00406 
+<a name="l00407"></a>00407 
+<a name="l00408"></a>00408 
+<a name="l00409"></a>00409 <span class="keyword">static</span> cpl_table*
+<a name="l00410"></a>00410 sinfo_interpolate(<span class="keyword">const</span> cpl_table* inp,
+<a name="l00411"></a>00411                   <span class="keyword">const</span> cpl_table* lambdas,
+<a name="l00412"></a>00412                   <span class="keyword">const</span> <span class="keywordtype">char</span>* name,
+<a name="l00413"></a>00413                   <span class="keyword">const</span> <span class="keywordtype">char</span>* method);
+<a name="l00414"></a>00414 
+<a name="l00415"></a>00415 <span class="keyword">static</span> cpl_table*
+<a name="l00416"></a>00416 sinfo_image2table(<span class="keyword">const</span> cpl_image* im);
+<a name="l00417"></a>00417 
+<a name="l00418"></a>00418 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00419"></a>00419 sinfo_table_extract_finite(<span class="keyword">const</span> cpl_table* in1,
+<a name="l00420"></a>00420                            <span class="keyword">const</span> cpl_table* in2,
+<a name="l00421"></a>00421                                  cpl_table** ou1,
+<a name="l00422"></a>00422                                  cpl_table** ou2);
+<a name="l00423"></a>00423 
+<a name="l00424"></a>00424 <span class="keyword">static</span> cpl_table*
+<a name="l00425"></a>00425 sinfo_slice_z(<span class="keyword">const</span> cpl_imagelist* cin,<span class="keyword">const</span> <span class="keywordtype">int</span> i,<span class="keyword">const</span> <span class="keywordtype">int</span> j);
+<a name="l00426"></a>00426 
+<a name="l00427"></a>00427 
+<a name="l00428"></a>00428 
+<a name="l00429"></a>00429 <span class="keyword">static</span> cpl_imagelist*
+<a name="l00430"></a>00430 sinfo_imagelist_select_range(<span class="keyword">const</span> cpl_imagelist* inp,
+<a name="l00431"></a>00431                                   <span class="keyword">const</span> cpl_table* full,
+<a name="l00432"></a>00432                                   <span class="keyword">const</span> cpl_table* good,
+<a name="l00433"></a>00433                                   <span class="keyword">const</span> <span class="keywordtype">double</span> tol);
+<a name="l00434"></a>00434 
+<a name="l00435"></a>00435 
+<a name="l00436"></a>00436 
+<a name="l00437"></a>00437 <span class="keyword">static</span> cpl_table*
+<a name="l00438"></a>00438 sinfo_table_select_range(cpl_table* inp,
+<a name="l00439"></a>00439                               cpl_table* ref,
+<a name="l00440"></a>00440                               <span class="keyword">const</span> <span class="keywordtype">double</span> tol);
+<a name="l00441"></a>00441 
+<a name="l00442"></a>00442 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00443"></a>00443 sinfo_table_fill_column_over_range(cpl_table** inp,
+<a name="l00444"></a>00444                                    <span class="keyword">const</span> cpl_table* ref,
+<a name="l00445"></a>00445                                    <span class="keyword">const</span> <span class="keywordtype">char</span>* col,
+<a name="l00446"></a>00446                                    <span class="keyword">const</span> <span class="keywordtype">double</span> val,
+<a name="l00447"></a>00447                                    <span class="keyword">const</span> <span class="keywordtype">double</span> tol);
+<a name="l00448"></a>00448 
+<a name="l00449"></a>00449 
+<a name="l00450"></a>00450 
+<a name="l00451"></a>00451 
+<a name="l00452"></a>00452 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00453"></a>00453 sinfo_table_column_dindgen(cpl_table** t, <span class="keyword">const</span> <span class="keywordtype">char</span>* label);
+<a name="l00454"></a>00454 
+<a name="l00455"></a>00455 
+<a name="l00456"></a>00456 
+<a name="l00457"></a>00457 
+<a name="l00458"></a>00458 
+<a name="l00459"></a>00459 
+<a name="l00460"></a>00460 
+<a name="l00461"></a>00461 
+<a name="l00462"></a>00462 
+<a name="l00463"></a>00463 
+<a name="l00464"></a>00464 
+<a name="l00465"></a>00465 
+<a name="l00466"></a>00466 
+<a name="l00467"></a>00467 
+<a name="l00469"></a>00469 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00474"></a>00474 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00475"></a>00475 
+<a name="l00482"></a>00482 sinfo_skycor_qc*
+<a name="l00483"></a>00483 sinfo_skycor_qc_new(<span class="keywordtype">void</span>)
+<a name="l00484"></a>00484  {
+<a name="l00485"></a>00485    sinfo_skycor_qc * sqc;
+<a name="l00486"></a>00486    sqc= cpl_malloc(<span class="keyword">sizeof</span>(sinfo_skycor_qc));
+<a name="l00487"></a>00487 
+<a name="l00488"></a>00488    sqc->th_fit=0;
+<a name="l00489"></a>00489 
+<a name="l00490"></a>00490    <span class="keywordflow">return</span> sqc;
+<a name="l00491"></a>00491 
+<a name="l00492"></a>00492 }
+<a name="l00499"></a>00499 <span class="keywordtype">void</span>
+<a name="l00500"></a>00500 sinfo_skycor_qc_delete(sinfo_skycor_qc** sqc)
+<a name="l00501"></a>00501 {
+<a name="l00502"></a>00502   <span class="keywordflow">if</span>((*sqc) != NULL) {
+<a name="l00503"></a>00503     cpl_free(*sqc);
+<a name="l00504"></a>00504     *sqc=NULL;
+<a name="l00505"></a>00505   }
+<a name="l00506"></a>00506 }
+<a name="l00507"></a>00507 
+<a name="l00508"></a>00508 
+<a name="l00509"></a>00509 
+<a name="l00520"></a>00520 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00521"></a>00521 <span class="keywordtype">int</span>
+<a name="l00522"></a>00522 sinfo_skycor(cpl_parameterlist * config,
+<a name="l00523"></a>00523              cpl_frame* obj_frm,
+<a name="l00524"></a>00524              cpl_frame* sky_frm,
+<a name="l00525"></a>00525              sinfo_skycor_qc* sqc,
+<a name="l00526"></a>00526              cpl_imagelist** obj_cor,
+<a name="l00527"></a>00527              cpl_table** int_obj)
+<a name="l00528"></a>00528 {
+<a name="l00529"></a>00529 
+<a name="l00530"></a>00530   cpl_table* bkg=NULL;
+<a name="l00531"></a>00531 
+<a name="l00532"></a>00532   cpl_table* lambda=NULL;
+<a name="l00533"></a>00533   cpl_table* lr41=NULL;
+<a name="l00534"></a>00534   cpl_table* lr52=NULL;
+<a name="l00535"></a>00535   cpl_table* lr63=NULL;
+<a name="l00536"></a>00536   cpl_table* lr74=NULL;
+<a name="l00537"></a>00537   cpl_table* lr02=NULL;
+<a name="l00538"></a>00538   cpl_table* lr85=NULL;
+<a name="l00539"></a>00539   cpl_table* lr20=NULL;
+<a name="l00540"></a>00540   cpl_table* lr31=NULL;
+<a name="l00541"></a>00541   cpl_table* lr42=NULL;
+<a name="l00542"></a>00542   cpl_table* lr53=NULL;
+<a name="l00543"></a>00543   cpl_table* lr64=NULL;
+<a name="l00544"></a>00544   cpl_table* lr75=NULL;
+<a name="l00545"></a>00545   cpl_table* lr86=NULL;
+<a name="l00546"></a>00546   cpl_table* lr97=NULL;
+<a name="l00547"></a>00547   cpl_table* lr00=NULL;
+<a name="l00548"></a>00548   cpl_table* lrange=NULL;
+<a name="l00549"></a>00549   cpl_table* mrange=NULL;
+<a name="l00550"></a>00550   cpl_table* grange=NULL;
+<a name="l00551"></a>00551   cpl_table* lambdas=NULL;
+<a name="l00552"></a>00552 
+<a name="l00553"></a>00553   cpl_table* int_sky=NULL;
+<a name="l00554"></a>00554 
+<a name="l00555"></a>00555   cpl_image* mask=NULL;
+<a name="l00556"></a>00556   cpl_image* gpix=NULL;
+<a name="l00557"></a>00557   cpl_image* ratio=NULL;
+<a name="l00558"></a>00558   cpl_image* ima_sky=NULL;
+<a name="l00559"></a>00559   cpl_imagelist* fdata=NULL;
+<a name="l00560"></a>00560   cpl_table* rscale=NULL;
+<a name="l00561"></a>00561   cpl_parameter* p=NULL;
+<a name="l00562"></a>00562 
+<a name="l00563"></a>00563   <span class="keywordtype">int</span> th_fit=0;
+<a name="l00564"></a>00564   <span class="keywordtype">double</span> dispersion=0;
+<a name="l00565"></a>00565   <span class="keywordtype">double</span> noise=0;
+<a name="l00566"></a>00566   <span class="comment">//double temp=252.69284;</span>
+<a name="l00567"></a>00567   <span class="keywordtype">double</span> centre=0;
+<a name="l00568"></a>00568   <span class="keywordtype">int</span> sky_interp_sw=0;
+<a name="l00569"></a>00569   <span class="keywordtype">double</span> wshift=0;
+<a name="l00570"></a>00570   <span class="keywordtype">double</span> pshift=0;
+<a name="l00571"></a>00571   <span class="keywordtype">int</span> method=0;
+<a name="l00572"></a>00572   <span class="keywordtype">int</span> do_rot=0;
+<a name="l00573"></a>00573   <span class="keywordtype">int</span> obj_noise_fit=0;
+<a name="l00574"></a>00574   <span class="keywordtype">int</span> niter=3;
+<a name="l00575"></a>00575   <span class="keywordtype">double</span> min_frac=0.8;
+<a name="l00576"></a>00576   <span class="keywordtype">double</span> line_hw=7;
+<a name="l00577"></a>00577   <span class="keywordtype">double</span> fit_temp=280;
+<a name="l00578"></a>00578   <span class="keywordtype">int</span> filter_width=SINFO_SKY_BKG_FILTER_WIDTH;
+<a name="l00579"></a>00579   <span class="keywordtype">int</span> llx=0;
+<a name="l00580"></a>00580   <span class="keywordtype">int</span> lly=0;
+<a name="l00581"></a>00581   <span class="keywordtype">int</span> urx=64;
+<a name="l00582"></a>00582   <span class="keywordtype">int</span> ury=64;
+<a name="l00583"></a>00583   cpl_imagelist* obj_cub=NULL;
+<a name="l00584"></a>00584   cpl_imagelist* sky_cub=NULL;
+<a name="l00585"></a>00585   <span class="keywordtype">int</span> sub_thr_bkg=0;
+<a name="l00586"></a>00586 
+<a name="l00587"></a>00587 
+<a name="l00588"></a>00588   check_nomsg(p=cpl_parameterlist_find(config,
+<a name="l00589"></a>00589                 <span class="stringliteral">"sinfoni.sinfo_utl_skycor.min_frac"</span>));
+<a name="l00590"></a>00590   check_nomsg(min_frac=cpl_parameter_get_double(p));
+<a name="l00591"></a>00591 
+<a name="l00592"></a>00592   check_nomsg(p=cpl_parameterlist_find(config,
+<a name="l00593"></a>00593                 <span class="stringliteral">"sinfoni.sinfo_utl_skycor.line_half_width"</span>));
+<a name="l00594"></a>00594   check_nomsg(line_hw=cpl_parameter_get_double(p));
+<a name="l00595"></a>00595 
+<a name="l00596"></a>00596 
+<a name="l00597"></a>00597 
+<a name="l00598"></a>00598   check_nomsg(p=cpl_parameterlist_find(config,
+<a name="l00599"></a>00599                 <span class="stringliteral">"sinfoni.sinfo_utl_skycor.sky_bkg_filter_width"</span>));
+<a name="l00600"></a>00600   check_nomsg(filter_width=cpl_parameter_get_int(p));
+<a name="l00601"></a>00601 
+<a name="l00602"></a>00602   check_nomsg(p=cpl_parameterlist_find(config,
+<a name="l00603"></a>00603                 <span class="stringliteral">"sinfoni.sinfo_utl_skycor.scale_method"</span>));
+<a name="l00604"></a>00604   check_nomsg(method=cpl_parameter_get_int(p));
+<a name="l00605"></a>00605 
+<a name="l00606"></a>00606 
+<a name="l00607"></a>00607 
+<a name="l00608"></a>00608   check_nomsg(p=cpl_parameterlist_find(config,
+<a name="l00609"></a>00609                 <span class="stringliteral">"sinfoni.sinfo_utl_skycor.rot_cor"</span>));
+<a name="l00610"></a>00610   check_nomsg(do_rot=cpl_parameter_get_bool(p));
+<a name="l00611"></a>00611 
+<a name="l00612"></a>00612 
+<a name="l00613"></a>00613   check_nomsg(p=cpl_parameterlist_find(config,
+<a name="l00614"></a>00614                 <span class="stringliteral">"sinfoni.sinfo_utl_skycor.sub_thr_bkg_from_obj"</span>));
+<a name="l00615"></a>00615   check_nomsg(sub_thr_bkg=cpl_parameter_get_bool(p));
+<a name="l00616"></a>00616 
+<a name="l00617"></a>00617 
+<a name="l00618"></a>00618   check_nomsg(p=cpl_parameterlist_find(config,
+<a name="l00619"></a>00619                 <span class="stringliteral">"sinfoni.sinfo_utl_skycor.fit_obj_noise"</span>));
+<a name="l00620"></a>00620   check_nomsg(obj_noise_fit=cpl_parameter_get_bool(p));
+<a name="l00621"></a>00621 
+<a name="l00622"></a>00622 
+<a name="l00623"></a>00623   check_nomsg(p=cpl_parameterlist_find(config,
+<a name="l00624"></a>00624                 <span class="stringliteral">"sinfoni.sinfo_utl_skycor.niter"</span>));
+<a name="l00625"></a>00625   check_nomsg(niter=cpl_parameter_get_int(p));
+<a name="l00626"></a>00626 
+<a name="l00627"></a>00627 
+<a name="l00628"></a>00628   check_nomsg(p=cpl_parameterlist_find(config,
+<a name="l00629"></a>00629                 <span class="stringliteral">"sinfoni.sinfo_utl_skycor.pshift"</span>));
+<a name="l00630"></a>00630   check_nomsg(pshift=cpl_parameter_get_double(p));
+<a name="l00631"></a>00631 
+<a name="l00632"></a>00632 
+<a name="l00633"></a>00633 
+<a name="l00634"></a>00634   check_nomsg(p=cpl_parameterlist_find(config,
+<a name="l00635"></a>00635                 <span class="stringliteral">"sinfoni.sinfo_utl_skycor.llx"</span>));
+<a name="l00636"></a>00636   check_nomsg(llx=cpl_parameter_get_int(p));
+<a name="l00637"></a>00637 
+<a name="l00638"></a>00638 
+<a name="l00639"></a>00639   check_nomsg(p=cpl_parameterlist_find(config,
+<a name="l00640"></a>00640                 <span class="stringliteral">"sinfoni.sinfo_utl_skycor.lly"</span>));
+<a name="l00641"></a>00641   check_nomsg(lly=cpl_parameter_get_int(p));
+<a name="l00642"></a>00642 
+<a name="l00643"></a>00643 
+<a name="l00644"></a>00644   check_nomsg(p=cpl_parameterlist_find(config,
+<a name="l00645"></a>00645                 <span class="stringliteral">"sinfoni.sinfo_utl_skycor.urx"</span>));
+<a name="l00646"></a>00646   check_nomsg(urx=cpl_parameter_get_int(p));
+<a name="l00647"></a>00647 
+<a name="l00648"></a>00648 
+<a name="l00649"></a>00649   check_nomsg(p=cpl_parameterlist_find(config,
+<a name="l00650"></a>00650                 <span class="stringliteral">"sinfoni.sinfo_utl_skycor.ury"</span>));
+<a name="l00651"></a>00651   check_nomsg(ury=cpl_parameter_get_int(p));
+<a name="l00652"></a>00652 
+<a name="l00653"></a>00653   <span class="comment">// set wavelength ranges</span>
+<a name="l00654"></a>00654   sinfo_msg(<span class="stringliteral">"Set wavelength ranges"</span>);
+<a name="l00655"></a>00655   ck0(sinfo_set_ranges(obj_frm,sky_frm,config,&lambda,
+<a name="l00656"></a>00656                        &lr41,&lr52,&lr63,&lr74,&lr02,&lr85,&lr20,&lr31,&lr42,
+<a name="l00657"></a>00657                        &lr53,&lr64,&lr75,&lr86,&lr97,&lr00,
+<a name="l00658"></a>00658                        &lrange,&grange,&lambdas,&mrange,&sky_interp_sw,
+<a name="l00659"></a>00659                        &dispersion),<span class="stringliteral">"Setting wavelength ranges"</span>);
+<a name="l00660"></a>00660   <span class="comment">//check_nomsg(cpl_table_save(grange, NULL, NULL, "out_grange.fits",</span>
+<a name="l00661"></a>00661   <span class="comment">//CPL_IO_DEFAULT));</span>
+<a name="l00662"></a>00662 
+<a name="l00663"></a>00663   <span class="comment">/*</span>
+<a name="l00664"></a>00664 <span class="comment">  sinfo_msg("lr20=%d",cpl_table_get_nrow(lr20));</span>
+<a name="l00665"></a>00665 <span class="comment">  sinfo_msg("lr31=%d",cpl_table_get_nrow(lr31));</span>
+<a name="l00666"></a>00666 <span class="comment">  sinfo_msg("lr42=%d",cpl_table_get_nrow(lr42));</span>
+<a name="l00667"></a>00667 <span class="comment">  sinfo_msg("lr53=%d",cpl_table_get_nrow(lr53));</span>
+<a name="l00668"></a>00668 <span class="comment">  sinfo_msg("lr64=%d",cpl_table_get_nrow(lr64));</span>
+<a name="l00669"></a>00669 <span class="comment">  sinfo_msg("lr75=%d",cpl_table_get_nrow(lr75));</span>
+<a name="l00670"></a>00670 <span class="comment">  sinfo_msg("lr86=%d",cpl_table_get_nrow(lr86));</span>
+<a name="l00671"></a>00671 <span class="comment">  sinfo_msg("lr97=%d",cpl_table_get_nrow(lr97));</span>
+<a name="l00672"></a>00672 <span class="comment">  sinfo_msg("lr00=%d",cpl_table_get_nrow(lr00));</span>
+<a name="l00673"></a>00673 <span class="comment"></span>
+<a name="l00674"></a>00674 <span class="comment">  sinfo_msg("min_lrange=%f",cpl_table_get_column_min(lrange,"INDEX"));</span>
+<a name="l00675"></a>00675 <span class="comment">  sinfo_msg("min_grange=%f",cpl_table_get_column_min(grange,"INDEX"));</span>
+<a name="l00676"></a>00676 <span class="comment">  sinfo_msg("min_srange=%f",cpl_table_get_column_min(lambdas,"WAVE"));</span>
+<a name="l00677"></a>00677 <span class="comment">  sinfo_msg("min_mrange=%f",cpl_table_get_column_min(mrange,"INDEX"));</span>
+<a name="l00678"></a>00678 <span class="comment"></span>
+<a name="l00679"></a>00679 <span class="comment">  sinfo_msg("max_lrange=%f",cpl_table_get_column_max(lrange,"INDEX"));</span>
+<a name="l00680"></a>00680 <span class="comment">  sinfo_msg("max_grange=%f",cpl_table_get_column_max(grange,"INDEX"));</span>
+<a name="l00681"></a>00681 <span class="comment">  sinfo_msg("max_srange=%f",cpl_table_get_column_max(lambdas,"WAVE"));</span>
+<a name="l00682"></a>00682 <span class="comment">  sinfo_msg("max_mrange=%f",cpl_table_get_column_max(mrange,"INDEX"));</span>
+<a name="l00683"></a>00683 <span class="comment">  */</span>
+<a name="l00684"></a>00684 
+<a name="l00685"></a>00685   sinfo_msg(<span class="stringliteral">"Estimate noise"</span>);
+<a name="l00686"></a>00686   ck0(sinfo_object_estimate_noise(obj_frm,obj_noise_fit,&centre,&noise),
+<a name="l00687"></a>00687                                   <span class="stringliteral">"Estimating noise"</span>);
+<a name="l00688"></a>00688 
+<a name="l00689"></a>00689   sinfo_msg(<span class="stringliteral">"Background=%f Noise=%f"</span>,centre,noise);
+<a name="l00690"></a>00690   sinfo_msg(<span class="stringliteral">"Flag object low_levels"</span>);
+<a name="l00691"></a>00691   ck0(sinfo_object_flag_low_values(obj_frm,centre,noise,&fdata),
+<a name="l00692"></a>00692       <span class="stringliteral">"Flagging low pix"</span>);
+<a name="l00693"></a>00693 
+<a name="l00694"></a>00694   <span class="comment">//cpl_imagelist_save(fdata,"out_fdata.fits",</span>
+<a name="l00695"></a>00695   <span class="comment">//                   CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT);</span>
+<a name="l00696"></a>00696 
+<a name="l00697"></a>00697 
+<a name="l00698"></a>00698   sinfo_msg(<span class="stringliteral">"Flag sky pixels"</span>);
+<a name="l00699"></a>00699   ck0(sinfo_object_flag_sky_pixels(obj_frm,lambda,mrange,fdata,dispersion,
+<a name="l00700"></a>00700                                    &gpix,&ratio,&ima_sky),
+<a name="l00701"></a>00701                                    <span class="stringliteral">"Flagging sky pixels"</span>);
+<a name="l00702"></a>00702 
+<a name="l00703"></a>00703   <span class="comment">//cpl_image_save(gpix,"out_gpix.fits",CPL_BPP_IEEE_FLOAT,</span>
+<a name="l00704"></a>00704   <span class="comment">//                 NULL,CPL_IO_DEFAULT);</span>
+<a name="l00705"></a>00705   <span class="comment">//cpl_image_save(ratio,"out_ratio.fits",CPL_BPP_IEEE_FLOAT,</span>
+<a name="l00706"></a>00706   <span class="comment">//                 NULL,CPL_IO_DEFAULT);</span>
+<a name="l00707"></a>00707   <span class="comment">//cpl_image_save(ima_sky,"out_ima_sky.fits",</span>
+<a name="l00708"></a>00708   <span class="comment">//               CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT);</span>
+<a name="l00709"></a>00709 
+<a name="l00710"></a>00710 
+<a name="l00711"></a>00711 
+<a name="l00712"></a>00712 
+<a name="l00713"></a>00713   <span class="comment">// choose pixels which seems to be good sky pixels</span>
+<a name="l00714"></a>00714   <span class="comment">// (95% spectral pixels are flagged)</span>
+<a name="l00715"></a>00715   sinfo_msg(<span class="stringliteral">"Choose good sky (with > 95%% good spectral) pixels"</span>);
+<a name="l00716"></a>00716   ck0(sinfo_choose_good_sky_pixels(obj_frm,ratio,gpix,min_frac,&mask),
+<a name="l00717"></a>00717       <span class="stringliteral">"Choosing good sky pixels"</span>);
+<a name="l00718"></a>00718 
+<a name="l00719"></a>00719   <span class="comment">//cpl_image_save(mask,"out_mask.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT);</span>
+<a name="l00720"></a>00720 
+<a name="l00721"></a>00721   <span class="comment">// threshold ratio for fraction 'minfract' of spatial pixels to be 'sky'</span>
+<a name="l00722"></a>00722   <span class="comment">//sinfo_msg("To do: flag_threshold_sky_pixels");</span>
+<a name="l00723"></a>00723 
+<a name="l00724"></a>00724 
+<a name="l00725"></a>00725   <span class="comment">// sum spectra of flagged pixels in object and sky frames</span>
+<a name="l00726"></a>00726   sinfo_msg(<span class="stringliteral">"Sum obj and sky spectra"</span>);
+<a name="l00727"></a>00727   ck0(sinfo_sum_spectra(obj_frm,sky_frm,mask,lambda,llx,lly,urx,ury,int_obj,
+<a name="l00728"></a>00728             &int_sky),<span class="stringliteral">"summing obj & sky spectra"</span>);
+<a name="l00729"></a>00729 
+<a name="l00730"></a>00730   <span class="comment">//check_nomsg(cpl_table_save(*int_obj, NULL, NULL, "out_int_obj.fits",</span>
+<a name="l00731"></a>00731   <span class="comment">// CPL_IO_DEFAULT));</span>
+<a name="l00732"></a>00732   <span class="comment">//check_nomsg(cpl_table_save(int_sky, NULL, NULL, "out_int_sky.fits",</span>
+<a name="l00733"></a>00733   <span class="comment">//CPL_IO_DEFAULT));</span>
+<a name="l00734"></a>00734 
+<a name="l00735"></a>00735    <span class="comment">// Computes thermal background</span>
+<a name="l00736"></a>00736   sinfo_msg(<span class="stringliteral">"Computes thermal background"</span>);
+<a name="l00737"></a>00737   <span class="comment">/*</span>
+<a name="l00738"></a>00738 <span class="comment">  ck0(sinfo_thermal_background2(int_sky,lambda,lrange,&bkg),</span>
+<a name="l00739"></a>00739 <span class="comment">     "getting termal bkg");</span>
+<a name="l00740"></a>00740 <span class="comment">  */</span>
+<a name="l00741"></a>00741 
+<a name="l00742"></a>00742   ck0(sinfo_thermal_background(int_sky,lambda,lrange,fit_temp,niter,
+<a name="l00743"></a>00743                                filter_width,dispersion,&bkg,&th_fit),
+<a name="l00744"></a>00744       <span class="stringliteral">"getting termal bkg"</span>);
+<a name="l00745"></a>00745 
+<a name="l00746"></a>00746 
+<a name="l00747"></a>00747   check_nomsg(cpl_table_duplicate_column(*int_obj,<span class="stringliteral">"INT_SKY_ORG"</span>,int_sky,<span class="stringliteral">"INT"</span>));
+<a name="l00748"></a>00748   check_nomsg(cpl_table_duplicate_column(*int_obj,<span class="stringliteral">"INT_BKG_FIT"</span>,bkg,<span class="stringliteral">"INT2"</span>));
+<a name="l00749"></a>00749   check_nomsg(cpl_table_duplicate_column(*int_obj,<span class="stringliteral">"INT_BKG_SMO"</span>,int_sky,
+<a name="l00750"></a>00750                                          <span class="stringliteral">"INT_BKG_SMO"</span>));
+<a name="l00751"></a>00751 
+<a name="l00752"></a>00752   sqc->th_fit=th_fit;
+<a name="l00753"></a>00753   <span class="comment">//check_nomsg(cpl_table_save(bkg,NULL,NULL,"out_thermal_background.fits",</span>
+<a name="l00754"></a>00754   <span class="comment">//CPL_IO_DEFAULT));</span>
+<a name="l00755"></a>00755 
+<a name="l00756"></a>00756 
+<a name="l00757"></a>00757   <span class="comment">/*</span>
+<a name="l00758"></a>00758 <span class="comment">  ck0(sinfo_pro_save_tbl(bkg,set,set,"out_thermal_background.fits",</span>
+<a name="l00759"></a>00759 <span class="comment">             "THERMAL_BACKGROUND",NULL,cpl_func,config),</span>
+<a name="l00760"></a>00760 <span class="comment">      "Error saving %s","THERMAL_BACKGROUND");</span>
+<a name="l00761"></a>00761 <span class="comment">  */</span>
+<a name="l00762"></a>00762 
+<a name="l00763"></a>00763   sinfo_msg(<span class="stringliteral">"Subtracts thermal background from integrated OH spectrum"</span>);
+<a name="l00764"></a>00764   <span class="comment">//sinfo_msg("nrow=%d %d",cpl_table_get_nrow(int_sky),</span>
+<a name="l00765"></a>00765   <span class="comment">//                       cpl_table_get_nrow(bkg));</span>
+<a name="l00766"></a>00766   check_nomsg(cpl_table_duplicate_column(int_sky,<span class="stringliteral">"BKG"</span>,bkg,<span class="stringliteral">"INT2"</span>));
+<a name="l00767"></a>00767   check_nomsg(cpl_table_duplicate_column(int_sky,<span class="stringliteral">"INT0"</span>,int_sky,<span class="stringliteral">"INT"</span>));
+<a name="l00768"></a>00768   check_nomsg(cpl_table_subtract_columns(int_sky,<span class="stringliteral">"INT"</span>,<span class="stringliteral">"BKG"</span>));
+<a name="l00769"></a>00769 
+<a name="l00770"></a>00770 
+<a name="l00771"></a>00771 
+<a name="l00772"></a>00772   <span class="comment">//check_nomsg(cpl_table_duplicate_column(int_obj,"INT",</span>
+<a name="l00773"></a>00773   <span class="comment">//                                         int_obj,"INT_OBJ_COR"));</span>
+<a name="l00774"></a>00774 
+<a name="l00775"></a>00775   <span class="keywordflow">if</span>(sub_thr_bkg == 1) {
+<a name="l00776"></a>00776     check_nomsg(cpl_table_duplicate_column(*int_obj,<span class="stringliteral">"THR_BKG"</span>,bkg,<span class="stringliteral">"INT2"</span>));
+<a name="l00777"></a>00777     check_nomsg(cpl_table_subtract_columns(*int_obj,<span class="stringliteral">"INT"</span>,<span class="stringliteral">"THR_BKG"</span>));
+<a name="l00778"></a>00778   }
+<a name="l00779"></a>00779 
+<a name="l00780"></a>00780   <span class="comment">//check_nomsg(cpl_table_save(*int_obj, NULL, NULL, "out_int_obj.fits",</span>
+<a name="l00781"></a>00781   <span class="comment">//CPL_IO_DEFAULT));</span>
+<a name="l00782"></a>00782   <span class="comment">//check_nomsg(cpl_table_save(int_sky, NULL, NULL, "out_int_sky.fits",</span>
+<a name="l00783"></a>00783   <span class="comment">//CPL_IO_DEFAULT));</span>
+<a name="l00784"></a>00784 
+<a name="l00785"></a>00785 
+<a name="l00786"></a>00786   <span class="comment">//check_nomsg(cpl_table_erase_column(int_sky,"BKG"));</span>
+<a name="l00787"></a>00787   <span class="comment">//check_nomsg(cpl_table_save(grange, NULL, NULL, "out_grange_6.fits",</span>
+<a name="l00788"></a>00788   <span class="comment">//CPL_IO_DEFAULT));</span>
+<a name="l00789"></a>00789 
+<a name="l00790"></a>00790    <span class="comment">//check_nomsg(cpl_table_save(int_sky, NULL, NULL, "out_int_sky_sub.fits",</span>
+<a name="l00791"></a>00791    <span class="comment">//CPL_IO_DEFAULT));</span>
+<a name="l00792"></a>00792 
+<a name="l00793"></a>00793 
+<a name="l00794"></a>00794 
+<a name="l00795"></a>00795   <span class="comment">// check for screw values at ends of spectrum</span>
+<a name="l00796"></a>00796   sinfo_msg(<span class="stringliteral">"Checks for screw values at ends of spectrum"</span>);
+<a name="l00797"></a>00797   sinfo_check_screw_values(int_obj,&int_sky,grange,dispersion);
+<a name="l00798"></a>00798   <span class="comment">//check_nomsg(cpl_table_save(grange, NULL, NULL, "out_grange_7.fits",</span>
+<a name="l00799"></a>00799   <span class="comment">//CPL_IO_DEFAULT));</span>
+<a name="l00800"></a>00800   <span class="comment">//check_nomsg(cpl_table_save(*int_obj, NULL, NULL, "out_int_obj_chk.fits",</span>
+<a name="l00801"></a>00801   <span class="comment">//CPL_IO_DEFAULT));</span>
+<a name="l00802"></a>00802   <span class="comment">//check_nomsg(cpl_table_save(int_sky, NULL, NULL, "out_int_sky_chk.fits",</span>
+<a name="l00803"></a>00803   <span class="comment">//CPL_IO_DEFAULT));</span>
+<a name="l00804"></a>00804 
+<a name="l00805"></a>00805 
+<a name="l00806"></a>00806 
+<a name="l00807"></a>00807   <span class="keywordflow">if</span>(sky_interp_sw == 1) {
+<a name="l00808"></a>00808     sinfo_msg(<span class="stringliteral">"Interpolate sky if necessary"</span>);
+<a name="l00809"></a>00809     sinfo_interpolate_sky(int_sky,lambdas);
+<a name="l00810"></a>00810   }
+<a name="l00811"></a>00811 
+<a name="l00812"></a>00812 
+<a name="l00813"></a>00813   sinfo_msg(<span class="stringliteral">"Crosscorrelate obj & sky to check for lambda offset"</span>);
+<a name="l00814"></a>00814   <span class="comment">//check_nomsg(cpl_table_save(*int_obj, NULL, NULL, "out_int_obj_chk.fits",</span>
+<a name="l00815"></a>00815   <span class="comment">//CPL_IO_DEFAULT));</span>
+<a name="l00816"></a>00816   <span class="comment">//check_nomsg(cpl_table_save(int_sky, NULL, NULL, "out_int_sky_chk.fits",</span>
+<a name="l00817"></a>00817   <span class="comment">//CPL_IO_DEFAULT));</span>
+<a name="l00818"></a>00818   check_nomsg(wshift=sinfo_xcorr(*int_obj,int_sky,lambda,dispersion,line_hw));
+<a name="l00819"></a>00819 
+<a name="l00820"></a>00820 
+<a name="l00821"></a>00821   <span class="comment">//wshift=-1.7164495*dispersion;</span>
+<a name="l00822"></a>00822   sinfo_msg(<span class="stringliteral">"Dispersion=%f"</span>,dispersion);
+<a name="l00823"></a>00823   <span class="keywordflow">if</span>(pshift == 0) {
+<a name="l00824"></a>00824     pshift=wshift/dispersion;
+<a name="l00825"></a>00825   }
+<a name="l00826"></a>00826   sinfo_msg(<span class="stringliteral">"Shift sky of %f pixels toward object"</span>,pshift);
+<a name="l00827"></a>00827 
+<a name="l00828"></a>00828   check_nomsg(sinfo_shift_sky(&sky_frm,&int_sky,pshift));
+<a name="l00829"></a>00829   <span class="comment">//check_nomsg(cpl_table_save(*int_obj, NULL, NULL, "out_pip3_int_obj.fits",</span>
+<a name="l00830"></a>00830   <span class="comment">//CPL_IO_DEFAULT));</span>
+<a name="l00831"></a>00831   <span class="comment">//check_nomsg(cpl_table_save(int_sky, NULL, NULL, "out_pip3_int_sky.fits",</span>
+<a name="l00832"></a>00832   <span class="comment">//CPL_IO_DEFAULT));</span>
+<a name="l00833"></a>00833 
+<a name="l00834"></a>00834 
+<a name="l00835"></a>00835   <span class="comment">//DEBUG</span>
+<a name="l00836"></a>00836   sinfo_msg(<span class="stringliteral">"Optimise sky subtraction"</span>);
+<a name="l00837"></a>00837   check_nomsg(sinfo_optimise_sky_sub(dispersion,line_hw,method,do_rot,
+<a name="l00838"></a>00838                                      lrange,lambda,
+<a name="l00839"></a>00839                                      lr41,lr52,lr63,lr74,lr02,lr85,
+<a name="l00840"></a>00840                                      lr20,lr31,lr42,lr53,lr64,lr75,
+<a name="l00841"></a>00841                      lr86,lr97,lr00,int_obj,&int_sky,
+<a name="l00842"></a>00842                      &rscale));
+<a name="l00843"></a>00843 
+<a name="l00844"></a>00844 
+<a name="l00845"></a>00845   <span class="comment">//check_nomsg(cpl_table_save(*int_obj, NULL, NULL, "out_int_obj.fits",</span>
+<a name="l00846"></a>00846   <span class="comment">//CPL_IO_DEFAULT));</span>
+<a name="l00847"></a>00847   <span class="comment">//check_nomsg(cpl_table_save(int_sky, NULL, NULL, "out_int_sky.fits",</span>
+<a name="l00848"></a>00848   <span class="comment">//CPL_IO_DEFAULT));</span>
+<a name="l00849"></a>00849 
+<a name="l00850"></a>00850 
+<a name="l00851"></a>00851   sinfo_msg(<span class="stringliteral">"Apply same scaling to whole cubes"</span>);
+<a name="l00852"></a>00852 
+<a name="l00853"></a>00853 
+<a name="l00854"></a>00854   cknull_nomsg(obj_cub=cpl_imagelist_load(cpl_frame_get_filename(obj_frm),
+<a name="l00855"></a>00855                                           CPL_TYPE_DOUBLE,0));
+<a name="l00856"></a>00856   cknull_nomsg(sky_cub=cpl_imagelist_load(cpl_frame_get_filename(sky_frm),
+<a name="l00857"></a>00857                                           CPL_TYPE_DOUBLE,0));
+<a name="l00858"></a>00858 
+<a name="l00859"></a>00859 
+<a name="l00860"></a>00860 
+<a name="l00861"></a>00861 
+<a name="l00862"></a>00862   <span class="keywordflow">if</span>(sub_thr_bkg == 1) {
+<a name="l00863"></a>00863     ck0_nomsg(sinfo_sub_thr_bkg_from_obj_cube(obj_cub,int_sky,obj_cor));
+<a name="l00864"></a>00864   } <span class="keywordflow">else</span> {
+<a name="l00865"></a>00865     check_nomsg(*obj_cor=cpl_imagelist_duplicate(obj_cub));
+<a name="l00866"></a>00866   }
+<a name="l00867"></a>00867 
+<a name="l00868"></a>00868   ck0_nomsg(sinfo_scales_obj_sky_cubes(*obj_cor,sky_cub,bkg,rscale,obj_cor));
+<a name="l00869"></a>00869 
+<a name="l00870"></a>00870   check_nomsg(cpl_table_name_column(*int_obj,<span class="stringliteral">"INT"</span>,<span class="stringliteral">"INT_OBJ_ORG"</span>));
+<a name="l00871"></a>00871   check_nomsg(cpl_table_name_column(*int_obj,<span class="stringliteral">"INTC"</span>,<span class="stringliteral">"INT_OBJ_COR"</span>));
+<a name="l00872"></a>00872   check_nomsg(cpl_table_name_column(*int_obj,<span class="stringliteral">"SKYC"</span>,<span class="stringliteral">"INT_SKY_COR"</span>));
+<a name="l00873"></a>00873 
+<a name="l00874"></a>00874 
+<a name="l00875"></a>00875  cleanup:
+<a name="l00876"></a>00876   sinfo_free_table(&rscale);
+<a name="l00877"></a>00877   sinfo_free_imagelist(&fdata);
+<a name="l00878"></a>00878 
+<a name="l00879"></a>00879   sinfo_free_table(&bkg);
+<a name="l00880"></a>00880   sinfo_free_table(&lambda);
+<a name="l00881"></a>00881   sinfo_free_table(&lrange);
+<a name="l00882"></a>00882   sinfo_free_table(&mrange);
+<a name="l00883"></a>00883   sinfo_free_table(&grange);
+<a name="l00884"></a>00884   sinfo_free_table(&lambdas);
+<a name="l00885"></a>00885   sinfo_free_image(&mask);
+<a name="l00886"></a>00886 
+<a name="l00887"></a>00887   sinfo_free_table(&lr41);
+<a name="l00888"></a>00888   sinfo_free_table(&lr52);
+<a name="l00889"></a>00889   sinfo_free_table(&lr63);
+<a name="l00890"></a>00890   sinfo_free_table(&lr74);
+<a name="l00891"></a>00891   sinfo_free_table(&lr02);
+<a name="l00892"></a>00892   sinfo_free_table(&lr85);
+<a name="l00893"></a>00893   sinfo_free_table(&lr20);
+<a name="l00894"></a>00894   sinfo_free_table(&lr31);
+<a name="l00895"></a>00895   sinfo_free_table(&lr42);
+<a name="l00896"></a>00896   sinfo_free_table(&lr53);
+<a name="l00897"></a>00897   sinfo_free_table(&lr64);
+<a name="l00898"></a>00898   sinfo_free_table(&lr75);
+<a name="l00899"></a>00899   sinfo_free_table(&lr86);
+<a name="l00900"></a>00900   sinfo_free_table(&lr97);
+<a name="l00901"></a>00901   sinfo_free_table(&lr00);
+<a name="l00902"></a>00902 
+<a name="l00903"></a>00903   sinfo_free_image(&gpix);
+<a name="l00904"></a>00904   sinfo_free_image(&ratio);
+<a name="l00905"></a>00905   sinfo_free_image(&ima_sky);
+<a name="l00906"></a>00906   <span class="comment">//sinfo_free_table(&int_obj);</span>
+<a name="l00907"></a>00907   sinfo_free_table(&int_sky);
+<a name="l00908"></a>00908 
+<a name="l00909"></a>00909   sinfo_free_imagelist(&obj_cub);
+<a name="l00910"></a>00910   sinfo_free_imagelist(&sky_cub);
+<a name="l00911"></a>00911 
+<a name="l00912"></a>00912   <span class="keywordflow">if</span> (cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l00913"></a>00913     <span class="keywordflow">return</span> -1;
+<a name="l00914"></a>00914   } <span class="keywordflow">else</span> {
+<a name="l00915"></a>00915     <span class="keywordflow">return</span> 0;
+<a name="l00916"></a>00916   }
+<a name="l00917"></a>00917 
+<a name="l00918"></a>00918 
+<a name="l00919"></a>00919 }
+<a name="l00920"></a>00920 
+<a name="l00921"></a>00921 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l00933"></a>00933 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00934"></a>00934 
+<a name="l00935"></a>00935 
+<a name="l00936"></a>00936 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00937"></a>00937 sinfo_sub_thr_bkg_from_obj_cube(cpl_imagelist* obj_cub,
+<a name="l00938"></a>00938                 cpl_table* int_sky,
+<a name="l00939"></a>00939                 cpl_imagelist** obj_cor)
+<a name="l00940"></a>00940 
+<a name="l00941"></a>00941 {
+<a name="l00942"></a>00942   <span class="keywordtype">double</span>* pthr_bkg=NULL;
+<a name="l00943"></a>00943   <span class="keywordtype">int</span> zsz=0;
+<a name="l00944"></a>00944   <span class="keywordtype">int</span> k=0;
+<a name="l00945"></a>00945   cpl_image* imgo=NULL;
+<a name="l00946"></a>00946 
+<a name="l00947"></a>00947   check_nomsg(pthr_bkg=cpl_table_get_data_double(int_sky,<span class="stringliteral">"BKG"</span>));
+<a name="l00948"></a>00948   check_nomsg(zsz=cpl_imagelist_get_size(obj_cub));
+<a name="l00949"></a>00949   check_nomsg(*obj_cor=cpl_imagelist_duplicate(obj_cub));
+<a name="l00950"></a>00950 
+<a name="l00951"></a>00951   <span class="keywordflow">for</span>(k=0;k<zsz;k++) {
+<a name="l00952"></a>00952     check_nomsg(imgo=cpl_imagelist_get(obj_cub,k));
+<a name="l00953"></a>00953     check_nomsg(cpl_image_subtract_scalar(imgo,pthr_bkg[k]));
+<a name="l00954"></a>00954     check_nomsg(cpl_imagelist_set(*obj_cor,imgo,k));
+<a name="l00955"></a>00955   }
+<a name="l00956"></a>00956 
+<a name="l00957"></a>00957  cleanup:
+<a name="l00958"></a>00958   <span class="keywordflow">if</span> (cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l00959"></a>00959     <span class="keywordflow">return</span> -1;
+<a name="l00960"></a>00960   } <span class="keywordflow">else</span> {
+<a name="l00961"></a>00961     <span class="keywordflow">return</span> 0;
+<a name="l00962"></a>00962   }
+<a name="l00963"></a>00963 
+<a name="l00964"></a>00964 }
+<a name="l00965"></a>00965 
+<a name="l00966"></a>00966 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l00997"></a>00997 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00998"></a>00998 
+<a name="l00999"></a>00999 
+<a name="l01000"></a>01000 <span class="keywordtype">int</span>
+<a name="l01001"></a>01001 sinfo_set_ranges(cpl_frame* obj_frm,
+<a name="l01002"></a>01002                  cpl_frame* sky_frm,
+<a name="l01003"></a>01003                  cpl_parameterlist* cfg,
+<a name="l01004"></a>01004                  cpl_table** lambda,
+<a name="l01005"></a>01005                  cpl_table** lr41,
+<a name="l01006"></a>01006                  cpl_table** lr52,
+<a name="l01007"></a>01007                  cpl_table** lr63,
+<a name="l01008"></a>01008                  cpl_table** lr74,
+<a name="l01009"></a>01009                  cpl_table** lr02,
+<a name="l01010"></a>01010                  cpl_table** lr85,
+<a name="l01011"></a>01011                  cpl_table** lr20,
+<a name="l01012"></a>01012                  cpl_table** lr31,
+<a name="l01013"></a>01013                  cpl_table** lr42,
+<a name="l01014"></a>01014                  cpl_table** lr53,
+<a name="l01015"></a>01015                  cpl_table** lr64,
+<a name="l01016"></a>01016                  cpl_table** lr75,
+<a name="l01017"></a>01017                  cpl_table** lr86,
+<a name="l01018"></a>01018                  cpl_table** lr97,
+<a name="l01019"></a>01019                  cpl_table** lr00,
+<a name="l01020"></a>01020                  cpl_table** lrange,
+<a name="l01021"></a>01021                  cpl_table** grange,
+<a name="l01022"></a>01022                  cpl_table** lambdas,
+<a name="l01023"></a>01023                  cpl_table** mrange,
+<a name="l01024"></a>01024                  <span class="keywordtype">int</span>* sky_interp_sw,
+<a name="l01025"></a>01025                  <span class="keywordtype">double</span>* dispersion)
+<a name="l01026"></a>01026 
+<a name="l01027"></a>01027 {
+<a name="l01028"></a>01028 
+<a name="l01029"></a>01029   cpl_propertylist* plist=NULL;
+<a name="l01030"></a>01030   <span class="keywordtype">double</span> crval_obj=0;
+<a name="l01031"></a>01031   <span class="keywordtype">double</span> cdelt_obj=0;
+<a name="l01032"></a>01032   <span class="keywordtype">double</span> crpix_obj=0;
+<a name="l01033"></a>01033   <span class="keywordtype">int</span> xsize_obj=0;
+<a name="l01034"></a>01034   <span class="keywordtype">int</span> ysize_obj=0;
+<a name="l01035"></a>01035   <span class="keywordtype">int</span> zsize_obj=0;
+<a name="l01036"></a>01036 
+<a name="l01037"></a>01037 
+<a name="l01038"></a>01038   <span class="keywordtype">double</span> crval_sky=0;
+<a name="l01039"></a>01039   <span class="keywordtype">double</span> cdelt_sky=0;
+<a name="l01040"></a>01040   <span class="keywordtype">double</span> crpix_sky=0;
+<a name="l01041"></a>01041   <span class="keywordtype">int</span> xsize_sky=0;
+<a name="l01042"></a>01042   <span class="keywordtype">int</span> ysize_sky=0;
+<a name="l01043"></a>01043   <span class="keywordtype">int</span> zsize_sky=0;
+<a name="l01044"></a>01044 
+<a name="l01045"></a>01045   <span class="keywordtype">int</span> nrow=0;
+<a name="l01046"></a>01046   <span class="comment">/* wavelength min-max J-H-K band */</span>
+<a name="l01047"></a>01047   <span class="keyword">const</span> <span class="keywordtype">double</span> w_j_min=1.100;
+<a name="l01048"></a>01048   <span class="keyword">const</span> <span class="keywordtype">double</span> w_j_max=1.400;
+<a name="l01049"></a>01049   <span class="keyword">const</span> <span class="keywordtype">double</span> w_h_min=1.445;
+<a name="l01050"></a>01050   <span class="keyword">const</span> <span class="keywordtype">double</span> w_h_max=1.820;
+<a name="l01051"></a>01051   <span class="keyword">const</span> <span class="keywordtype">double</span> w_k_min=1.945;
+<a name="l01052"></a>01052   <span class="keyword">const</span> <span class="keywordtype">double</span> w_k_max=2.460;
+<a name="l01053"></a>01053 
+<a name="l01054"></a>01054   <span class="keywordtype">double</span> ws=0;
+<a name="l01055"></a>01055   <span class="keywordtype">double</span> we=0;
+<a name="l01056"></a>01056   <span class="keywordtype">double</span> mean=0;
+<a name="l01057"></a>01057 
+<a name="l01058"></a>01058   cpl_parameter* p=NULL;
+<a name="l01059"></a>01059 
+<a name="l01060"></a>01060   <span class="comment">/* wavelength boundaries between line groups corresponding</span>
+<a name="l01061"></a>01061 <span class="comment">     to transitions 5-2 to 9-7 */</span>
+<a name="l01062"></a>01062   <span class="keywordtype">double</span> w_bound[NBOUND]={1.067,1.125,1.196,1.252,1.289,
+<a name="l01063"></a>01063                           1.400,1.472,1.5543,1.6356,1.7253,
+<a name="l01064"></a>01064                           1.840,1.9570,2.095,2.300};
+<a name="l01065"></a>01065 
+<a name="l01066"></a>01066   cpl_table* tmp_tbl=NULL;
+<a name="l01067"></a>01067   cpl_table* add1=NULL;
+<a name="l01068"></a>01068 
+<a name="l01069"></a>01069 
+<a name="l01070"></a>01070 
+<a name="l01071"></a>01071   <span class="comment">/* Get Object relevant information */</span>
+<a name="l01072"></a>01072   cknull_nomsg(plist=cpl_propertylist_load(cpl_frame_get_filename(obj_frm),0));
+<a name="l01073"></a>01073   check_nomsg(crval_obj=sinfo_pfits_get_crval3(plist));
+<a name="l01074"></a>01074   check_nomsg(cdelt_obj=sinfo_pfits_get_cdelt3(plist));
+<a name="l01075"></a>01075   check_nomsg(crpix_obj=sinfo_pfits_get_crpix3(plist));
+<a name="l01076"></a>01076   check_nomsg(xsize_obj=sinfo_pfits_get_naxis1(plist));
+<a name="l01077"></a>01077   check_nomsg(ysize_obj=sinfo_pfits_get_naxis2(plist));
+<a name="l01078"></a>01078   check_nomsg(zsize_obj=sinfo_pfits_get_naxis3(plist));
+<a name="l01079"></a>01079 
+<a name="l01080"></a>01080   sinfo_free_propertylist(&plist);
+<a name="l01081"></a>01081   *dispersion=cdelt_obj;
+<a name="l01082"></a>01082 
+<a name="l01083"></a>01083   <span class="comment">/* defines object related wavelength ranges */</span>
+<a name="l01084"></a>01084   check_nomsg(*lambda=cpl_table_new(zsize_obj));
+<a name="l01085"></a>01085   cpl_table_new_column(*lambda,<span class="stringliteral">"WAVE"</span>,CPL_TYPE_DOUBLE);
+<a name="l01086"></a>01086   cpl_table_new_column(*lambda,<span class="stringliteral">"INDEX"</span>,CPL_TYPE_DOUBLE);
+<a name="l01087"></a>01087   check_nomsg(sinfo_table_column_dindgen(lambda,<span class="stringliteral">"INDEX"</span>));
+<a name="l01088"></a>01088   check_nomsg(sinfo_table_column_dindgen(lambda,<span class="stringliteral">"WAVE"</span>));
+<a name="l01089"></a>01089 
+<a name="l01090"></a>01090   check_nomsg(cpl_table_add_scalar(*lambda,<span class="stringliteral">"WAVE"</span>,1.));
+<a name="l01091"></a>01091   check_nomsg(cpl_table_subtract_scalar(*lambda,<span class="stringliteral">"WAVE"</span>,crpix_obj));
+<a name="l01092"></a>01092   check_nomsg(cpl_table_multiply_scalar(*lambda,<span class="stringliteral">"WAVE"</span>,cdelt_obj));
+<a name="l01093"></a>01093   check_nomsg(cpl_table_add_scalar(*lambda,<span class="stringliteral">"WAVE"</span>,crval_obj));
+<a name="l01094"></a>01094 
+<a name="l01095"></a>01095 
+<a name="l01096"></a>01096 
+<a name="l01097"></a>01097 
+<a name="l01098"></a>01098   cknull_nomsg(*lr41=sinfo_where_tab_min_max(*lambda,
+<a name="l01099"></a>01099                                              <span class="stringliteral">"WAVE"</span>,
+<a name="l01100"></a>01100                                              CPL_NOT_LESS_THAN,
+<a name="l01101"></a>01101                                              w_j_min,
+<a name="l01102"></a>01102                                              CPL_LESS_THAN,
+<a name="l01103"></a>01103                                              w_bound[0]));
+<a name="l01104"></a>01104 
+<a name="l01105"></a>01105   cknull_nomsg(*lr52=sinfo_where_tab_min_max(*lambda,
+<a name="l01106"></a>01106                                              <span class="stringliteral">"WAVE"</span>,
+<a name="l01107"></a>01107                                              CPL_NOT_LESS_THAN,
+<a name="l01108"></a>01108                                              w_bound[0],
+<a name="l01109"></a>01109                                              CPL_LESS_THAN,
+<a name="l01110"></a>01110                                              w_bound[1]));
+<a name="l01111"></a>01111 
+<a name="l01112"></a>01112   cknull_nomsg(*lr63=sinfo_where_tab_min_max(*lambda,
+<a name="l01113"></a>01113                                              <span class="stringliteral">"WAVE"</span>,
+<a name="l01114"></a>01114                                              CPL_NOT_LESS_THAN,
+<a name="l01115"></a>01115                                              w_bound[1],
+<a name="l01116"></a>01116                                              CPL_LESS_THAN,
+<a name="l01117"></a>01117                                              w_bound[2]));
+<a name="l01118"></a>01118 
+<a name="l01119"></a>01119 
+<a name="l01120"></a>01120   cknull_nomsg(*lr74=sinfo_where_tab_min_max(*lambda,
+<a name="l01121"></a>01121                                              <span class="stringliteral">"WAVE"</span>,
+<a name="l01122"></a>01122                                              CPL_NOT_LESS_THAN,
+<a name="l01123"></a>01123                                              w_bound[2],
+<a name="l01124"></a>01124                                              CPL_LESS_THAN,
+<a name="l01125"></a>01125                                              w_bound[3]));
+<a name="l01126"></a>01126 
+<a name="l01127"></a>01127  cknull_nomsg(*lr20=sinfo_where_tab_min_max(*lambda,
+<a name="l01128"></a>01128                                              <span class="stringliteral">"WAVE"</span>,
+<a name="l01129"></a>01129                                              CPL_NOT_LESS_THAN,
+<a name="l01130"></a>01130                                              w_bound[3],
+<a name="l01131"></a>01131                                              CPL_LESS_THAN,
+<a name="l01132"></a>01132                                              w_bound[4]));
+<a name="l01133"></a>01133 
+<a name="l01134"></a>01134  cknull_nomsg(*lr02=sinfo_where_tab_min_max(*lambda,
+<a name="l01135"></a>01135                                              <span class="stringliteral">"WAVE"</span>,
+<a name="l01136"></a>01136                                              CPL_NOT_LESS_THAN,
+<a name="l01137"></a>01137                                              w_bound[4],
+<a name="l01138"></a>01138                                              CPL_LESS_THAN,
+<a name="l01139"></a>01139                                              w_bound[5]));
+<a name="l01140"></a>01140 
+<a name="l01141"></a>01141 
+<a name="l01142"></a>01142  cknull_nomsg(*lr85=sinfo_where_tab_min_max(*lambda,
+<a name="l01143"></a>01143                                              <span class="stringliteral">"WAVE"</span>,
+<a name="l01144"></a>01144                                              CPL_NOT_LESS_THAN,
+<a name="l01145"></a>01145                                              w_bound[5],
+<a name="l01146"></a>01146                                              CPL_LESS_THAN,
+<a name="l01147"></a>01147                                              w_bound[6]));
+<a name="l01148"></a>01148 
+<a name="l01149"></a>01149   cknull_nomsg(*lr31=sinfo_where_tab_min_max(*lambda,
+<a name="l01150"></a>01150                                              <span class="stringliteral">"WAVE"</span>,
+<a name="l01151"></a>01151                                              CPL_NOT_LESS_THAN,
+<a name="l01152"></a>01152                                              w_bound[6],
+<a name="l01153"></a>01153                                              CPL_LESS_THAN,
+<a name="l01154"></a>01154                                              w_bound[7]));
+<a name="l01155"></a>01155 
+<a name="l01156"></a>01156   cknull_nomsg(*lr42=sinfo_where_tab_min_max(*lambda,
+<a name="l01157"></a>01157                                              <span class="stringliteral">"WAVE"</span>,
+<a name="l01158"></a>01158                                              CPL_NOT_LESS_THAN,
+<a name="l01159"></a>01159                                              w_bound[7],
+<a name="l01160"></a>01160                                              CPL_LESS_THAN,
+<a name="l01161"></a>01161                                              w_bound[8]));
+<a name="l01162"></a>01162 
+<a name="l01163"></a>01163   cknull_nomsg(*lr53=sinfo_where_tab_min_max(*lambda,
+<a name="l01164"></a>01164                                              <span class="stringliteral">"WAVE"</span>,
+<a name="l01165"></a>01165                                              CPL_NOT_LESS_THAN,
+<a name="l01166"></a>01166                                              w_bound[8],
+<a name="l01167"></a>01167                                              CPL_LESS_THAN,
+<a name="l01168"></a>01168                                              w_bound[9]));
+<a name="l01169"></a>01169 
+<a name="l01170"></a>01170   cknull_nomsg(*lr64=sinfo_where_tab_min_max(*lambda,
+<a name="l01171"></a>01171                                              <span class="stringliteral">"WAVE"</span>,
+<a name="l01172"></a>01172                                              CPL_NOT_LESS_THAN,
+<a name="l01173"></a>01173                                              w_bound[0],
+<a name="l01174"></a>01174                                              CPL_LESS_THAN,
+<a name="l01175"></a>01175                                              w_bound[10]));
+<a name="l01176"></a>01176 
+<a name="l01177"></a>01177   cknull_nomsg(*lr75=sinfo_where_tab_min_max(*lambda,
+<a name="l01178"></a>01178                                              <span class="stringliteral">"WAVE"</span>,
+<a name="l01179"></a>01179                                              CPL_NOT_LESS_THAN,
+<a name="l01180"></a>01180                                              w_bound[10],
+<a name="l01181"></a>01181                                              CPL_LESS_THAN,
+<a name="l01182"></a>01182                                              w_bound[11]));
+<a name="l01183"></a>01183 
+<a name="l01184"></a>01184   cknull_nomsg(*lr86=sinfo_where_tab_min_max(*lambda,
+<a name="l01185"></a>01185                                              <span class="stringliteral">"WAVE"</span>,
+<a name="l01186"></a>01186                                              CPL_NOT_LESS_THAN,
+<a name="l01187"></a>01187                                              w_bound[11],
+<a name="l01188"></a>01188                                              CPL_LESS_THAN,
+<a name="l01189"></a>01189                                              w_bound[12]));
+<a name="l01190"></a>01190 
+<a name="l01191"></a>01191   cknull_nomsg(*lr97=sinfo_where_tab_min_max(*lambda,
+<a name="l01192"></a>01192                                              <span class="stringliteral">"WAVE"</span>,
+<a name="l01193"></a>01193                                              CPL_NOT_LESS_THAN,
+<a name="l01194"></a>01194                                              w_bound[12],
+<a name="l01195"></a>01195                                              CPL_LESS_THAN,
+<a name="l01196"></a>01196                                              w_bound[13]));
+<a name="l01197"></a>01197 
+<a name="l01198"></a>01198   cknull_nomsg(*lr00=sinfo_where_tab_min_max(*lambda,
+<a name="l01199"></a>01199                                              <span class="stringliteral">"WAVE"</span>,
+<a name="l01200"></a>01200                                               CPL_NOT_LESS_THAN,
+<a name="l01201"></a>01201                                               w_bound[13],
+<a name="l01202"></a>01202                                               CPL_LESS_THAN,
+<a name="l01203"></a>01203                                               w_k_max));
+<a name="l01204"></a>01204 
+<a name="l01205"></a>01205   <span class="comment">/* lrange */</span>
+<a name="l01206"></a>01206   cknull_nomsg(*lrange=sinfo_where_tab_min_max(*lambda,
+<a name="l01207"></a>01207                                                <span class="stringliteral">"WAVE"</span>,
+<a name="l01208"></a>01208                                                CPL_NOT_LESS_THAN,
+<a name="l01209"></a>01209                                                w_j_min,
+<a name="l01210"></a>01210                                                CPL_NOT_GREATER_THAN,
+<a name="l01211"></a>01211                                                w_j_max));
+<a name="l01212"></a>01212 
+<a name="l01213"></a>01213 
+<a name="l01214"></a>01214 
+<a name="l01215"></a>01215   cknull_nomsg(add1=sinfo_where_tab_min_max(*lambda,
+<a name="l01216"></a>01216                                                <span class="stringliteral">"WAVE"</span>,
+<a name="l01217"></a>01217                                                CPL_NOT_LESS_THAN,
+<a name="l01218"></a>01218                                                w_h_min,
+<a name="l01219"></a>01219                                                CPL_NOT_GREATER_THAN,
+<a name="l01220"></a>01220                                                w_h_max));
+<a name="l01221"></a>01221 
+<a name="l01222"></a>01222   check_nomsg(nrow=cpl_table_get_nrow(*lrange));
+<a name="l01223"></a>01223   check_nomsg(cpl_table_insert(*lrange,add1,nrow));
+<a name="l01224"></a>01224   sinfo_free_table(&add1);
+<a name="l01225"></a>01225 
+<a name="l01226"></a>01226   cknull_nomsg(add1=sinfo_where_tab_min_max(*lambda,
+<a name="l01227"></a>01227                                                <span class="stringliteral">"WAVE"</span>,
+<a name="l01228"></a>01228                                                CPL_NOT_LESS_THAN,
+<a name="l01229"></a>01229                                                w_k_min,
+<a name="l01230"></a>01230                                                CPL_NOT_GREATER_THAN,
+<a name="l01231"></a>01231                                                w_k_max));
+<a name="l01232"></a>01232 
+<a name="l01233"></a>01233 
+<a name="l01234"></a>01234   check_nomsg(nrow=cpl_table_get_nrow(*lrange));
+<a name="l01235"></a>01235   check_nomsg(cpl_table_insert(*lrange,add1,nrow));
+<a name="l01236"></a>01236   sinfo_free_table(&add1);
+<a name="l01237"></a>01237 
+<a name="l01238"></a>01238 
+<a name="l01239"></a>01239   <span class="comment">/* mrange */</span>
+<a name="l01240"></a>01240   cknull_nomsg(*grange=sinfo_where_tab_min_max(*lambda,
+<a name="l01241"></a>01241                                                <span class="stringliteral">"WAVE"</span>,
+<a name="l01242"></a>01242                                                CPL_NOT_LESS_THAN,
+<a name="l01243"></a>01243                                                1.10,
+<a name="l01244"></a>01244                                                CPL_NOT_GREATER_THAN,
+<a name="l01245"></a>01245                                                1.35));
+<a name="l01246"></a>01246 
+<a name="l01247"></a>01247 
+<a name="l01248"></a>01248 
+<a name="l01249"></a>01249 
+<a name="l01250"></a>01250   cknull_nomsg(add1=sinfo_where_tab_min_max(*lambda,
+<a name="l01251"></a>01251                                                <span class="stringliteral">"WAVE"</span>,
+<a name="l01252"></a>01252                                                CPL_NOT_LESS_THAN,
+<a name="l01253"></a>01253                                                1.5,
+<a name="l01254"></a>01254                                                CPL_NOT_GREATER_THAN,
+<a name="l01255"></a>01255                                                1.7));
+<a name="l01256"></a>01256 
+<a name="l01257"></a>01257   check_nomsg(nrow=cpl_table_get_nrow(*grange));
+<a name="l01258"></a>01258   check_nomsg(cpl_table_insert(*grange,add1,nrow));
+<a name="l01259"></a>01259   sinfo_free_table(&add1);
+<a name="l01260"></a>01260 
+<a name="l01261"></a>01261 
+<a name="l01262"></a>01262 
+<a name="l01263"></a>01263   cknull_nomsg(add1=sinfo_where_tab_min_max(*lambda,
+<a name="l01264"></a>01264                                             <span class="stringliteral">"WAVE"</span>,
+<a name="l01265"></a>01265                                             CPL_NOT_LESS_THAN,
+<a name="l01266"></a>01266                                             2.0,
+<a name="l01267"></a>01267                                             CPL_NOT_GREATER_THAN,
+<a name="l01268"></a>01268                                             2.3));
+<a name="l01269"></a>01269 
+<a name="l01270"></a>01270   check_nomsg(nrow=cpl_table_get_nrow(*grange));
+<a name="l01271"></a>01271   check_nomsg(cpl_table_insert(*grange,add1,nrow));
+<a name="l01272"></a>01272   sinfo_free_table(&add1);
+<a name="l01273"></a>01273 
+<a name="l01274"></a>01274 
+<a name="l01275"></a>01275   <span class="comment">/* Get Sky relevant information */</span>
+<a name="l01276"></a>01276   cknull_nomsg(plist=cpl_propertylist_load(cpl_frame_get_filename(sky_frm),0));
+<a name="l01277"></a>01277   check_nomsg(crval_sky=sinfo_pfits_get_crval3(plist));
+<a name="l01278"></a>01278   check_nomsg(cdelt_sky=sinfo_pfits_get_cdelt3(plist));
+<a name="l01279"></a>01279   check_nomsg(crpix_sky=sinfo_pfits_get_crpix3(plist));
+<a name="l01280"></a>01280   check_nomsg(xsize_sky=sinfo_pfits_get_naxis1(plist));
+<a name="l01281"></a>01281   check_nomsg(ysize_sky=sinfo_pfits_get_naxis2(plist));
+<a name="l01282"></a>01282   check_nomsg(zsize_sky=sinfo_pfits_get_naxis3(plist));
+<a name="l01283"></a>01283   sinfo_free_propertylist(&plist);
+<a name="l01284"></a>01284 
+<a name="l01285"></a>01285   <span class="comment">/* defines sky related wavelength ranges */</span>
+<a name="l01286"></a>01286   check_nomsg(*lambdas=cpl_table_new(zsize_sky));
+<a name="l01287"></a>01287   cpl_table_new_column(*lambdas,<span class="stringliteral">"WAVE"</span>,CPL_TYPE_DOUBLE);
+<a name="l01288"></a>01288   check_nomsg(sinfo_table_column_dindgen(lambdas,<span class="stringliteral">"WAVE"</span>));
+<a name="l01289"></a>01289 
+<a name="l01290"></a>01290   check_nomsg(cpl_table_add_scalar(*lambdas,<span class="stringliteral">"WAVE"</span>,1.));
+<a name="l01291"></a>01291   check_nomsg(cpl_table_subtract_scalar(*lambdas,<span class="stringliteral">"WAVE"</span>,crpix_sky));
+<a name="l01292"></a>01292   check_nomsg(cpl_table_multiply_scalar(*lambdas,<span class="stringliteral">"WAVE"</span>,cdelt_sky));
+<a name="l01293"></a>01293   check_nomsg(cpl_table_add_scalar(*lambdas,<span class="stringliteral">"WAVE"</span>,crval_sky));
+<a name="l01294"></a>01294 
+<a name="l01295"></a>01295   check_nomsg(p=cpl_parameterlist_find(cfg,<span class="stringliteral">"sinfoni.sinfo_utl_skycor.mask_ws"</span>));
+<a name="l01296"></a>01296   check_nomsg(ws=cpl_parameter_get_double(p));
+<a name="l01297"></a>01297   check_nomsg(p=cpl_parameterlist_find(cfg,<span class="stringliteral">"sinfoni.sinfo_utl_skycor.mask_we"</span>));
+<a name="l01298"></a>01298   check_nomsg(we=cpl_parameter_get_double(p));
+<a name="l01299"></a>01299   <span class="keywordflow">if</span>((ws != SINFO_MASK_WAVE_MIN) || (we != SINFO_MASK_WAVE_MAX)) {
+<a name="l01300"></a>01300     cknull_nomsg(*mrange=sinfo_where_tab_min_max(*lambda,<span class="stringliteral">"WAVE"</span>,
+<a name="l01301"></a>01301                                                  CPL_NOT_LESS_THAN,ws,
+<a name="l01302"></a>01302                                                  CPL_NOT_GREATER_THAN,we));
+<a name="l01303"></a>01303    } <span class="keywordflow">else</span> {
+<a name="l01304"></a>01304      check_nomsg(*mrange=cpl_table_duplicate(*lrange));
+<a name="l01305"></a>01305   }
+<a name="l01306"></a>01306 
+<a name="l01307"></a>01307 
+<a name="l01308"></a>01308   check_nomsg(cpl_table_duplicate_column(*lambda,<span class="stringliteral">"WDIFF"</span>,*lambdas,<span class="stringliteral">"WAVE"</span>));
+<a name="l01309"></a>01309   check_nomsg(cpl_table_subtract_columns(*lambda,<span class="stringliteral">"WDIFF"</span>,<span class="stringliteral">"WAVE"</span>));
+<a name="l01310"></a>01310   check_nomsg(mean=cpl_table_get_column_mean(*lambda,<span class="stringliteral">"WDIFF"</span>));
+<a name="l01311"></a>01311   check_nomsg(nrow=cpl_table_get_nrow(*lambda));
+<a name="l01312"></a>01312   <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"diff %f"</span>,nrow*mean);
+<a name="l01313"></a>01313   <span class="keywordflow">if</span>((fabs(nrow*mean) > 0) || (zsize_obj != zsize_sky)) {
+<a name="l01314"></a>01314     sinfo_msg(<span class="stringliteral">"We have to interpolate sky frame - this is not good"</span>);
+<a name="l01315"></a>01315     *sky_interp_sw=1;
+<a name="l01316"></a>01316   }
+<a name="l01317"></a>01317 
+<a name="l01318"></a>01318 
+<a name="l01319"></a>01319   <span class="keywordflow">return</span> 0;
+<a name="l01320"></a>01320 
+<a name="l01321"></a>01321  cleanup:
+<a name="l01322"></a>01322   sinfo_free_table(&add1);
+<a name="l01323"></a>01323   sinfo_free_table(&tmp_tbl);
+<a name="l01324"></a>01324   sinfo_free_propertylist(&plist);
+<a name="l01325"></a>01325   <span class="keywordflow">return</span> -1;
+<a name="l01326"></a>01326 
+<a name="l01327"></a>01327 }
+<a name="l01328"></a>01328 
+<a name="l01329"></a>01329 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l01340"></a>01340 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l01341"></a>01341 
+<a name="l01342"></a>01342 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l01343"></a>01343 sinfo_table_column_dindgen(cpl_table** t, <span class="keyword">const</span> <span class="keywordtype">char</span>* label)
+<a name="l01344"></a>01344 {
+<a name="l01345"></a>01345 
+<a name="l01346"></a>01346   <span class="keywordtype">int</span> sz=0;
+<a name="l01347"></a>01347   <span class="keywordtype">int</span> i=0;
+<a name="l01348"></a>01348 
+<a name="l01349"></a>01349   cknull(*t,<span class="stringliteral">"Null input vector"</span>);
+<a name="l01350"></a>01350   check(sz=cpl_table_get_nrow(*t),<span class="stringliteral">"Getting size of a vector"</span>);
+<a name="l01351"></a>01351   <span class="keywordflow">for</span>(i=0;i<sz;i++) {
+<a name="l01352"></a>01352     cpl_table_set(*t,label,i,(<span class="keywordtype">double</span>)i);
+<a name="l01353"></a>01353   }
+<a name="l01354"></a>01354 
+<a name="l01355"></a>01355   <span class="keywordflow">return</span> 0;
+<a name="l01356"></a>01356  cleanup:
+<a name="l01357"></a>01357   <span class="keywordflow">return</span> -1;
+<a name="l01358"></a>01358 
+<a name="l01359"></a>01359 }
+<a name="l01360"></a>01360 
+<a name="l01361"></a>01361 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l01372"></a>01372 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l01373"></a>01373 
+<a name="l01374"></a>01374 
+<a name="l01375"></a>01375 <span class="keywordtype">int</span>
+<a name="l01376"></a>01376 sinfo_sum_spectra(<span class="keyword">const</span> cpl_frame* obj_frm,
+<a name="l01377"></a>01377                   <span class="keyword">const</span> cpl_frame* sky_frm,
+<a name="l01378"></a>01378                   cpl_image* mask,
+<a name="l01379"></a>01379                   cpl_table* wrange,
+<a name="l01380"></a>01380                   <span class="keyword">const</span> <span class="keywordtype">int</span> llx,
+<a name="l01381"></a>01381                   <span class="keyword">const</span> <span class="keywordtype">int</span> lly,
+<a name="l01382"></a>01382                   <span class="keyword">const</span> <span class="keywordtype">int</span> urx,
+<a name="l01383"></a>01383                   <span class="keyword">const</span> <span class="keywordtype">int</span> ury,
+<a name="l01384"></a>01384                   cpl_table** int_obj,
+<a name="l01385"></a>01385                   cpl_table** int_sky)
+<a name="l01386"></a>01386 {
+<a name="l01387"></a>01387 
+<a name="l01388"></a>01388 
+<a name="l01389"></a>01389 
+<a name="l01390"></a>01390   cpl_image* obj_slice=NULL;
+<a name="l01391"></a>01391   cpl_image* sky_slice=NULL;
+<a name="l01392"></a>01392   cpl_image* gslice=NULL;
+<a name="l01393"></a>01393   cpl_image* pos_tmp=NULL;
+<a name="l01394"></a>01394   cpl_image* msk_tmp=NULL;
+<a name="l01395"></a>01395   cpl_imagelist* obj=NULL;
+<a name="l01396"></a>01396   cpl_imagelist* sky=NULL;
+<a name="l01397"></a>01397 
+<a name="l01398"></a>01398 
+<a name="l01399"></a>01399   cpl_table* loop=NULL;
+<a name="l01400"></a>01400   cpl_table* opos_tbl=NULL;
+<a name="l01401"></a>01401   cpl_table* spos_tbl=NULL;
+<a name="l01402"></a>01402   cpl_table* tmp_tbl=NULL;
+<a name="l01403"></a>01403   cpl_table* loop_tbl=NULL;
+<a name="l01404"></a>01404 
+<a name="l01405"></a>01405   <span class="keywordtype">double</span> med=0;
+<a name="l01406"></a>01406   <span class="keywordtype">double</span> sdv=0;
+<a name="l01407"></a>01407   <span class="keywordtype">double</span> avg=0;
+<a name="l01408"></a>01408 
+<a name="l01409"></a>01409   <span class="keywordtype">int</span> zsize=0;
+<a name="l01410"></a>01410   <span class="keywordtype">int</span> i=0;
+<a name="l01411"></a>01411   <span class="keywordtype">int</span> pos_i=0;
+<a name="l01412"></a>01412 
+<a name="l01413"></a>01413   <span class="comment">// sum spectra of flagged spaxels</span>
+<a name="l01414"></a>01414 
+<a name="l01415"></a>01415   cknull_nomsg(obj=cpl_imagelist_load(cpl_frame_get_filename(obj_frm),
+<a name="l01416"></a>01416                                       CPL_TYPE_DOUBLE,0));
+<a name="l01417"></a>01417   cknull_nomsg(sky=cpl_imagelist_load(cpl_frame_get_filename(sky_frm),
+<a name="l01418"></a>01418                                       CPL_TYPE_DOUBLE,0));
+<a name="l01419"></a>01419 
+<a name="l01420"></a>01420   check_nomsg(zsize=cpl_imagelist_get_size(obj));
+<a name="l01421"></a>01421   check_nomsg(*int_obj = cpl_table_new(zsize));
+<a name="l01422"></a>01422   check_nomsg(*int_sky = cpl_table_new(zsize));
+<a name="l01423"></a>01423   check_nomsg(cpl_table_duplicate_column(*int_obj,<span class="stringliteral">"WAVE"</span>,wrange,<span class="stringliteral">"WAVE"</span>));
+<a name="l01424"></a>01424   check_nomsg(cpl_table_duplicate_column(*int_sky,<span class="stringliteral">"WAVE"</span>,wrange,<span class="stringliteral">"WAVE"</span>));
+<a name="l01425"></a>01425   check_nomsg(cpl_table_new_column(*int_obj,<span class="stringliteral">"INT"</span>,CPL_TYPE_DOUBLE));
+<a name="l01426"></a>01426   check_nomsg(cpl_table_new_column(*int_sky,<span class="stringliteral">"INT"</span>,CPL_TYPE_DOUBLE));
+<a name="l01427"></a>01427   check_nomsg(cpl_table_fill_column_window_double(*int_obj,<span class="stringliteral">"INT"</span>,0,zsize,0));
+<a name="l01428"></a>01428   check_nomsg(cpl_table_fill_column_window_double(*int_sky,<span class="stringliteral">"INT"</span>,0,zsize,0));
+<a name="l01429"></a>01429 
+<a name="l01430"></a>01430   <span class="comment">//loop = where(mask > 0.5);</span>
+<a name="l01431"></a>01431   <span class="comment">//TO BE REMOVED: loop_tbl is not used</span>
+<a name="l01432"></a>01432   cknull_nomsg(loop_tbl=sinfo_image2table(mask));
+<a name="l01433"></a>01433   check_nomsg(cpl_table_and_selected_double(loop_tbl,<span class="stringliteral">"VALUE"</span>,
+<a name="l01434"></a>01434                                             CPL_GREATER_THAN,0.5));
+<a name="l01435"></a>01435   check_nomsg(loop=cpl_table_extract_selected(loop_tbl));
+<a name="l01436"></a>01436   sinfo_free_table(&loop_tbl);
+<a name="l01437"></a>01437   sinfo_free_table(&loop);
+<a name="l01438"></a>01438 
+<a name="l01439"></a>01439   <span class="comment">//Determines object spectrum</span>
+<a name="l01440"></a>01440   <span class="keywordflow">for</span> (i=0;i<zsize;i++) {
+<a name="l01441"></a>01441     check_nomsg(obj_slice = cpl_imagelist_get(obj,i));
+<a name="l01442"></a>01442 
+<a name="l01443"></a>01443     <span class="comment">//pos = where(mask > 0.5 && finite(obj_slice),pos_i);</span>
+<a name="l01444"></a>01444     pos_i=sinfo_cnt_mask_thresh_and_obj_finite(mask,0.5,obj_slice);
+<a name="l01445"></a>01445     <span class="keywordflow">if</span> (pos_i >= 1) {
+<a name="l01446"></a>01446       <span class="keywordflow">if</span> ((pos_i) < 3 ) {
+<a name="l01447"></a>01447     <span class="comment">//int_obj[i] = mean(obj_slice[pos]);</span>
+<a name="l01448"></a>01448         <span class="comment">//TODO here obj_slice should be considered only on pos:</span>
+<a name="l01449"></a>01449         <span class="comment">//     one should do a selection/thresholding</span>
+<a name="l01450"></a>01450         check_nomsg(cpl_table_set_double(*int_obj,<span class="stringliteral">"INT"</span>,i,
+<a name="l01451"></a>01451                      cpl_image_get_mean_window(obj_slice,
+<a name="l01452"></a>01452                                    llx,lly,
+<a name="l01453"></a>01453                                    urx,ury)));
+<a name="l01454"></a>01454       } <span class="keywordflow">else</span> {
+<a name="l01455"></a>01455         <span class="comment">// select only poisitions where mask>0.5 and obj is finite</span>
+<a name="l01456"></a>01456     <span class="comment">// gslice = obj_slice[pos];</span>
+<a name="l01457"></a>01457         <span class="comment">//sinfo_msg("obj pos_i=%d",pos_i);</span>
+<a name="l01458"></a>01458 
+<a name="l01459"></a>01459         check_nomsg(gslice = cpl_image_duplicate(obj_slice));
+<a name="l01460"></a>01460         check_nomsg(sinfo_image_flag_nan(&gslice));
+<a name="l01461"></a>01461     <span class="comment">/*</span>
+<a name="l01462"></a>01462 <span class="comment">        sinfo_msg("obj: min=%f max=%f",</span>
+<a name="l01463"></a>01463 <span class="comment">                  cpl_image_get_min(obj_slice),</span>
+<a name="l01464"></a>01464 <span class="comment">          cpl_image_get_max(obj_slice));</span>
+<a name="l01465"></a>01465 <span class="comment">    */</span>
+<a name="l01466"></a>01466         <span class="comment">//check_nomsg(cpl_image_threshold(gslice,SINFO_DBL_MIN,3.0e6,1,0));</span>
+<a name="l01467"></a>01467         <span class="comment">//check_nomsg(cpl_image_multiply(gslice,mask));</span>
+<a name="l01468"></a>01468         <span class="keywordflow">if</span>(cpl_image_count_rejected(gslice) < 2048) { <span class="comment">//2048=64*64/2</span>
+<a name="l01469"></a>01469 
+<a name="l01470"></a>01470       check_nomsg(med = cpl_image_get_median_window(gslice,llx,lly,urx,ury));
+<a name="l01471"></a>01471       check_nomsg(sdv = cpl_image_get_stdev_window(gslice,llx,lly,urx,ury));
+<a name="l01472"></a>01472       <span class="comment">//sinfo_msg("med=%f sdv=%f",med,sdv);</span>
+<a name="l01473"></a>01473       <span class="comment">//avg = mean(gslice[where(gslice < med+3*sdv && gslice > med-3*sdv)]);</span>
+<a name="l01474"></a>01474       check_nomsg(cpl_image_threshold(gslice,med-3*sdv,med+3*sdv,0,0));
+<a name="l01475"></a>01475       check_nomsg(avg= cpl_image_get_mean_window(gslice,llx,lly,urx,ury));
+<a name="l01476"></a>01476       check_nomsg(cpl_table_set_double(*int_obj,<span class="stringliteral">"INT"</span>,i,avg));
+<a name="l01477"></a>01477     } <span class="keywordflow">else</span> {
+<a name="l01478"></a>01478       check_nomsg(cpl_table_set_invalid(*int_obj,<span class="stringliteral">"INT"</span>,i));
+<a name="l01479"></a>01479     }
+<a name="l01480"></a>01480 
+<a name="l01481"></a>01481         sinfo_free_image(&gslice);
+<a name="l01482"></a>01482         <span class="comment">//sinfo_msg("sky int=%f",avg);</span>
+<a name="l01483"></a>01483       }
+<a name="l01484"></a>01484     }
+<a name="l01485"></a>01485 
+<a name="l01486"></a>01486     <span class="comment">//Determines sky spectrum</span>
+<a name="l01487"></a>01487     check_nomsg(sky_slice = cpl_imagelist_get(sky,i));
+<a name="l01488"></a>01488     <span class="comment">//pos = where(mask > 0.5 and finite(sky_slice),pos_i);</span>
+<a name="l01489"></a>01489     pos_i=sinfo_cnt_mask_thresh_and_obj_finite(mask,0.5,sky_slice);
+<a name="l01490"></a>01490     <span class="keywordflow">if</span> (pos_i >= 1) {
+<a name="l01491"></a>01491       <span class="keywordflow">if</span> ((pos_i) < 3) {
+<a name="l01492"></a>01492     <span class="comment">//int_obj[i] = mean(obj_slice[pos]);</span>
+<a name="l01493"></a>01493         <span class="comment">//TODO here obj_slice should be considered only on pos:</span>
+<a name="l01494"></a>01494         <span class="comment">//     one should do a selection/thresholding</span>
+<a name="l01495"></a>01495         check_nomsg(cpl_table_set_double(*int_sky,<span class="stringliteral">"INT"</span>,i,
+<a name="l01496"></a>01496                      cpl_image_get_mean_window(sky_slice,
+<a name="l01497"></a>01497                                    llx,lly,
+<a name="l01498"></a>01498                                    urx,ury)));
+<a name="l01499"></a>01499       } <span class="keywordflow">else</span> {
+<a name="l01500"></a>01500         <span class="comment">//sinfo_msg("pos_i=%d",pos_i);</span>
+<a name="l01501"></a>01501         <span class="comment">// select only poisitions where mask>0.5 and obj is finite</span>
+<a name="l01502"></a>01502     <span class="comment">// gslice = obj_slice[pos];</span>
+<a name="l01503"></a>01503         check_nomsg(gslice = cpl_image_duplicate(sky_slice));
+<a name="l01504"></a>01504         check_nomsg(sinfo_image_flag_nan(&gslice));
+<a name="l01505"></a>01505         <span class="comment">//check_nomsg(cpl_image_threshold(gslice,SINFO_DBL_MIN,3.0e6,1,0));</span>
+<a name="l01506"></a>01506         <span class="comment">//check_nomsg(cpl_image_multiply(gslice,mask));</span>
+<a name="l01507"></a>01507         <span class="keywordflow">if</span>(cpl_image_count_rejected(gslice) < 2048) { <span class="comment">//2048=64*64/2</span>
+<a name="l01508"></a>01508 
+<a name="l01509"></a>01509     check_nomsg(med = cpl_image_get_median_window(gslice,llx,lly,urx,ury));
+<a name="l01510"></a>01510     check_nomsg(sdv = cpl_image_get_stdev_window(gslice,llx,lly,urx,ury));
+<a name="l01511"></a>01511         <span class="comment">//avg = mean(gslice[where(gslice < med+3*sdv && gslice > med-3*sdv)]);</span>
+<a name="l01512"></a>01512         check_nomsg(cpl_image_threshold(gslice,med-3*sdv,med+3*sdv,0,0));
+<a name="l01513"></a>01513     check_nomsg(avg= cpl_image_get_mean_window(gslice,llx,lly,urx,ury));
+<a name="l01514"></a>01514         check_nomsg(cpl_table_set_double(*int_sky,<span class="stringliteral">"INT"</span>,i,avg));
+<a name="l01515"></a>01515     } <span class="keywordflow">else</span> {
+<a name="l01516"></a>01516       check_nomsg(cpl_table_set_invalid(*int_sky,<span class="stringliteral">"INT"</span>,i));
+<a name="l01517"></a>01517     }
+<a name="l01518"></a>01518         sinfo_free_image(&gslice);
+<a name="l01519"></a>01519     <span class="comment">/*</span>
+<a name="l01520"></a>01520 <span class="comment">        if(i<100) {</span>
+<a name="l01521"></a>01521 <span class="comment">           sinfo_msg("sky: wave=%f int=%f",</span>
+<a name="l01522"></a>01522 <span class="comment">                      cpl_table_get_double(*int_sky,"WAVE",i,&status),avg);</span>
+<a name="l01523"></a>01523 <span class="comment"></span>
+<a name="l01524"></a>01524 <span class="comment">    }</span>
+<a name="l01525"></a>01525 <span class="comment">    */</span>
+<a name="l01526"></a>01526       }
+<a name="l01527"></a>01527     }
+<a name="l01528"></a>01528   }
+<a name="l01529"></a>01529 
+<a name="l01530"></a>01530   sinfo_free_imagelist(&obj);
+<a name="l01531"></a>01531   sinfo_free_imagelist(&sky);
+<a name="l01532"></a>01532 
+<a name="l01533"></a>01533 
+<a name="l01534"></a>01534   <span class="keywordflow">return</span> 0;
+<a name="l01535"></a>01535 
+<a name="l01536"></a>01536  cleanup:
+<a name="l01537"></a>01537   sinfo_free_image(&gslice);
+<a name="l01538"></a>01538   sinfo_free_image(&pos_tmp);
+<a name="l01539"></a>01539   sinfo_free_image(&msk_tmp);
+<a name="l01540"></a>01540   sinfo_free_table(&tmp_tbl);
+<a name="l01541"></a>01541   sinfo_free_table(&opos_tbl);
+<a name="l01542"></a>01542   sinfo_free_table(&spos_tbl);
+<a name="l01543"></a>01543   sinfo_free_table(&loop_tbl);
+<a name="l01544"></a>01544   sinfo_free_table(&loop);
+<a name="l01545"></a>01545   sinfo_free_imagelist(&obj);
+<a name="l01546"></a>01546   sinfo_free_imagelist(&sky);
+<a name="l01547"></a>01547 
+<a name="l01548"></a>01548   <span class="keywordflow">return</span> -1;
+<a name="l01549"></a>01549 }
+<a name="l01550"></a>01550 
+<a name="l01551"></a>01551 
+<a name="l01552"></a>01552 
+<a name="l01553"></a>01553 
+<a name="l01554"></a>01554 
+<a name="l01555"></a>01555 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l01566"></a>01566 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l01567"></a>01567 
+<a name="l01568"></a>01568 
+<a name="l01569"></a>01569 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l01570"></a>01570 sinfo_cnt_mask_thresh_and_obj_finite(<span class="keyword">const</span> cpl_image* mask,
+<a name="l01571"></a>01571                                      <span class="keyword">const</span> <span class="keywordtype">double</span> t,
+<a name="l01572"></a>01572                                      <span class="keyword">const</span> cpl_image* obj)
+<a name="l01573"></a>01573 {
+<a name="l01574"></a>01574 
+<a name="l01575"></a>01575   <span class="keywordtype">int</span> cnt=0;
+<a name="l01576"></a>01576   <span class="keywordtype">int</span> sxm=0;
+<a name="l01577"></a>01577   <span class="keywordtype">int</span> sym=0;
+<a name="l01578"></a>01578   <span class="keywordtype">int</span> sxo=0;
+<a name="l01579"></a>01579   <span class="keywordtype">int</span> syo=0;
+<a name="l01580"></a>01580   <span class="keywordtype">int</span> i=0;
+<a name="l01581"></a>01581   <span class="keyword">const</span> <span class="keywordtype">double</span>* pm=NULL;
+<a name="l01582"></a>01582   <span class="keyword">const</span> <span class="keywordtype">double</span>* po=NULL;
+<a name="l01583"></a>01583 
+<a name="l01584"></a>01584   check_nomsg(sxm=cpl_image_get_size_x(mask));
+<a name="l01585"></a>01585   check_nomsg(sym=cpl_image_get_size_y(mask));
+<a name="l01586"></a>01586   check_nomsg(sxo=cpl_image_get_size_x(obj));
+<a name="l01587"></a>01587   check_nomsg(syo=cpl_image_get_size_y(obj));
+<a name="l01588"></a>01588   <span class="keywordflow">if</span>( sxm != sxo || sym != syo) {
+<a name="l01589"></a>01589     <span class="keywordflow">goto</span> cleanup;
+<a name="l01590"></a>01590   }
+<a name="l01591"></a>01591   check_nomsg(pm=cpl_image_get_data_double_const(mask));
+<a name="l01592"></a>01592   check_nomsg(po=cpl_image_get_data_double_const(obj));
+<a name="l01593"></a>01593 
+<a name="l01594"></a>01594   <span class="keywordflow">for</span>(i=0;i<sxm*sym;i++) {
+<a name="l01595"></a>01595 
+<a name="l01596"></a>01596     <span class="keywordflow">if</span>( (pm[i] > t) && (!<a class="code" href="group__irplib__utils.html#ga804bfc739b5d55f9797ab881b1034ae4" title="portable isnan">irplib_isnan</a>(po[i]))) { cnt++; }
+<a name="l01597"></a>01597 
+<a name="l01598"></a>01598   }
+<a name="l01599"></a>01599 
+<a name="l01600"></a>01600   <span class="keywordflow">return</span> cnt;
+<a name="l01601"></a>01601  cleanup:
+<a name="l01602"></a>01602   <span class="keywordflow">return</span> -1;
+<a name="l01603"></a>01603 
+<a name="l01604"></a>01604 }
+<a name="l01605"></a>01605 
+<a name="l01606"></a>01606 
+<a name="l01607"></a>01607 
+<a name="l01608"></a>01608 
+<a name="l01609"></a>01609 
+<a name="l01610"></a>01610 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l01621"></a>01621 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l01622"></a>01622 
+<a name="l01623"></a>01623 
+<a name="l01624"></a>01624 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l01625"></a>01625 sinfo_image_flag_nan(cpl_image** im)
+<a name="l01626"></a>01626 {
+<a name="l01627"></a>01627 
+<a name="l01628"></a>01628   <span class="keywordtype">int</span> cnt=0;
+<a name="l01629"></a>01629   <span class="keywordtype">int</span> sx=0;
+<a name="l01630"></a>01630   <span class="keywordtype">int</span> sy=0;
+<a name="l01631"></a>01631   <span class="keywordtype">int</span> i=0;
+<a name="l01632"></a>01632   <span class="keywordtype">int</span> j=0;
+<a name="l01633"></a>01633 
+<a name="l01634"></a>01634   <span class="keywordtype">double</span>* pi=NULL;
+<a name="l01635"></a>01635 
+<a name="l01636"></a>01636   check_nomsg(sx=cpl_image_get_size_x(*im));
+<a name="l01637"></a>01637   check_nomsg(sy=cpl_image_get_size_y(*im));
+<a name="l01638"></a>01638   check_nomsg(pi=cpl_image_get_data_double(*im));
+<a name="l01639"></a>01639 
+<a name="l01640"></a>01640   <span class="keywordflow">for</span>(j=0;j<sy;j++) {
+<a name="l01641"></a>01641     <span class="keywordflow">for</span>(i=0;i<sx;i++) {
+<a name="l01642"></a>01642      <span class="keywordflow">if</span>(<a class="code" href="group__irplib__utils.html#ga804bfc739b5d55f9797ab881b1034ae4" title="portable isnan">irplib_isnan</a>(pi[j*sx+i])) {
+<a name="l01643"></a>01643     check_nomsg(cpl_image_reject(*im,i+1,j+1));
+<a name="l01644"></a>01644     cnt++;
+<a name="l01645"></a>01645       }
+<a name="l01646"></a>01646     }
+<a name="l01647"></a>01647   }
+<a name="l01648"></a>01648   <span class="comment">//sinfo_msg("No bad pixels: %d",cnt);</span>
+<a name="l01649"></a>01649   <span class="keywordflow">return</span> cnt;
+<a name="l01650"></a>01650  cleanup:
+<a name="l01651"></a>01651   <span class="keywordflow">return</span> -1;
+<a name="l01652"></a>01652 
+<a name="l01653"></a>01653 }
+<a name="l01654"></a>01654 
+<a name="l01655"></a>01655 
+<a name="l01656"></a>01656 
+<a name="l01657"></a>01657 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l01669"></a>01669 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l01670"></a>01670 
+<a name="l01671"></a>01671 <span class="keywordtype">int</span>
+<a name="l01672"></a>01672 sinfo_object_estimate_noise(cpl_frame* obj_frm,
+<a name="l01673"></a>01673                             <span class="keyword">const</span> <span class="keywordtype">int</span> obj_noise_fit,
+<a name="l01674"></a>01674                             <span class="keywordtype">double</span>* centre,
+<a name="l01675"></a>01675                             <span class="keywordtype">double</span>* noise)
+<a name="l01676"></a>01676 {
+<a name="l01677"></a>01677 
+<a name="l01678"></a>01678   <span class="keyword">const</span> <span class="keywordtype">int</span> nbins=HISTO_NBINS;
+<a name="l01679"></a>01679 
+<a name="l01680"></a>01680   <span class="keywordtype">int</span> xsz=0;
+<a name="l01681"></a>01681   <span class="keywordtype">int</span> ysz=0;
+<a name="l01682"></a>01682   <span class="keywordtype">int</span> zsz=0;
+<a name="l01683"></a>01683   <span class="keywordtype">int</span> n=0;
+<a name="l01684"></a>01684   <span class="keywordtype">int</span> i=0;
+<a name="l01685"></a>01685   <span class="keywordtype">int</span> k=0;
+<a name="l01686"></a>01686   <span class="keywordtype">int</span> r=0;
+<a name="l01687"></a>01687 
+<a name="l01688"></a>01688   <span class="keywordtype">int</span> max_h=0;
+<a name="l01689"></a>01689   <span class="keywordtype">int</span> min_x=0;
+<a name="l01690"></a>01690   <span class="keywordtype">int</span> max_x=0;
+<a name="l01691"></a>01691   <span class="keywordtype">int</span> status=0;
+<a name="l01692"></a>01692   <span class="keywordtype">int</span> max_pos=0;
+<a name="l01693"></a>01693   <span class="keywordtype">int</span> min_pos=0;
+<a name="l01694"></a>01694   <span class="keywordtype">int</span> min_xi_sz=0;
+<a name="l01695"></a>01695   <span class="keywordtype">int</span> ndist=0;
+<a name="l01696"></a>01696 
+<a name="l01697"></a>01697   <span class="keywordtype">double</span> avg_d=0;
+<a name="l01698"></a>01698   <span class="keywordtype">double</span> std_d=0;
+<a name="l01699"></a>01699   <span class="keywordtype">double</span> hmin=0;
+<a name="l01700"></a>01700   <span class="keywordtype">double</span> hmax=0;
+<a name="l01701"></a>01701   <span class="keywordtype">double</span> kappa=3;
+<a name="l01702"></a>01702 
+<a name="l01703"></a>01703   <span class="keywordtype">double</span>* pdata=NULL;
+<a name="l01704"></a>01704   <span class="keywordtype">double</span>* disth=NULL;
+<a name="l01705"></a>01705   <span class="keywordtype">double</span>* distx=NULL;
+<a name="l01706"></a>01706 
+<a name="l01707"></a>01707   <span class="keywordtype">double</span> peak=0;
+<a name="l01708"></a>01708   <span class="keywordtype">double</span> tempc=0;
+<a name="l01709"></a>01709   <span class="keywordtype">double</span> value=0;
+<a name="l01710"></a>01710   <span class="keywordtype">double</span> thres=0;
+<a name="l01711"></a>01711   <span class="keywordtype">double</span> val=0;
+<a name="l01712"></a>01712   <span class="keywordtype">double</span> x0=0;
+<a name="l01713"></a>01713   <span class="keywordtype">double</span> sigma=0;
+<a name="l01714"></a>01714   <span class="keywordtype">double</span> area=0;
+<a name="l01715"></a>01715   <span class="keywordtype">double</span> offset=0;
+<a name="l01716"></a>01716   <span class="comment">//double mse=0;</span>
+<a name="l01717"></a>01717   <span class="comment">//double chired=0;</span>
+<a name="l01718"></a>01718 
+<a name="l01719"></a>01719   cpl_propertylist* plist=NULL;
+<a name="l01720"></a>01720   cpl_imagelist* obj_cub=NULL;
+<a name="l01721"></a>01721   cpl_table* data_tbl=NULL;
+<a name="l01722"></a>01722   cpl_table* histo=NULL;
+<a name="l01723"></a>01723   cpl_image* img=NULL;
+<a name="l01724"></a>01724   cpl_table* dist=NULL;
+<a name="l01725"></a>01725   cpl_table* min_xi=NULL;
+<a name="l01726"></a>01726   cpl_table* tmp_tbl1=NULL;
+<a name="l01727"></a>01727   cpl_table* tmp_tbl2=NULL;
+<a name="l01728"></a>01728   cpl_vector* vx=NULL;
+<a name="l01729"></a>01729   cpl_vector* vy=NULL;
+<a name="l01730"></a>01730   cpl_vector* sx=NULL;
+<a name="l01731"></a>01731   cpl_vector* sy=NULL;
+<a name="l01732"></a>01732   <span class="keywordtype">int</span> counter=0;
+<a name="l01733"></a>01733 
+<a name="l01734"></a>01734   <span class="comment">// Get Object relevant information</span>
+<a name="l01735"></a>01735   cknull_nomsg(plist=cpl_propertylist_load(cpl_frame_get_filename(obj_frm),0));
+<a name="l01736"></a>01736   check_nomsg(xsz=sinfo_pfits_get_naxis1(plist));
+<a name="l01737"></a>01737   check_nomsg(ysz=sinfo_pfits_get_naxis2(plist));
+<a name="l01738"></a>01738   check_nomsg(zsz=sinfo_pfits_get_naxis3(plist));
+<a name="l01739"></a>01739   sinfo_free_propertylist(&plist);
+<a name="l01740"></a>01740 
+<a name="l01741"></a>01741   cknull_nomsg(obj_cub=cpl_imagelist_load(cpl_frame_get_filename(obj_frm),
+<a name="l01742"></a>01742                                           CPL_TYPE_DOUBLE,0));
+<a name="l01743"></a>01743 
+<a name="l01744"></a>01744   n=xsz*ysz*zsz;
+<a name="l01745"></a>01745   check_nomsg(data_tbl=cpl_table_new(n));
+<a name="l01746"></a>01746   check_nomsg(cpl_table_new_column(data_tbl,<span class="stringliteral">"DATA"</span>,CPL_TYPE_DOUBLE));
+<a name="l01747"></a>01747 
+<a name="l01748"></a>01748 
+<a name="l01749"></a>01749   <span class="keywordflow">for</span>(k=0;k<zsz;k++) {
+<a name="l01750"></a>01750     check_nomsg(img=cpl_imagelist_get(obj_cub,k));
+<a name="l01751"></a>01751     check_nomsg(pdata=cpl_image_get_data(img));
+<a name="l01752"></a>01752     <span class="keywordflow">for</span>(i=0;i<xsz*ysz;i++) {
+<a name="l01753"></a>01753       <span class="keywordflow">if</span>(!<a class="code" href="group__irplib__utils.html#ga804bfc739b5d55f9797ab881b1034ae4" title="portable isnan">irplib_isnan</a>(pdata[i])) {
+<a name="l01754"></a>01754     cpl_table_set_double(data_tbl,<span class="stringliteral">"DATA"</span>,r,pdata[i]);
+<a name="l01755"></a>01755         r++;
+<a name="l01756"></a>01756       }
+<a name="l01757"></a>01757     }
+<a name="l01758"></a>01758   }
+<a name="l01759"></a>01759   sinfo_free_imagelist(&obj_cub);
+<a name="l01760"></a>01760 
+<a name="l01761"></a>01761   check_nomsg(cpl_table_erase_invalid(data_tbl));
+<a name="l01762"></a>01762   check_nomsg(avg_d=cpl_table_get_column_mean(data_tbl,<span class="stringliteral">"DATA"</span>));
+<a name="l01763"></a>01763   check_nomsg(std_d=cpl_table_get_column_stdev(data_tbl,<span class="stringliteral">"DATA"</span>));
+<a name="l01764"></a>01764 
+<a name="l01765"></a>01765   <span class="comment">//cpl_table_save(data_tbl, NULL, NULL, "out_data.fits",CPL_IO_DEFAULT);</span>
+<a name="l01766"></a>01766   hmin=avg_d-kappa*std_d;
+<a name="l01767"></a>01767   hmax=avg_d+kappa*std_d;
+<a name="l01768"></a>01768   <span class="comment">//sinfo_msg("mean=%f stdv=%f",avg_d,std_d);</span>
+<a name="l01769"></a>01769   <span class="comment">//sinfo_msg("hmin=%f hmax=%f",hmin,hmax);</span>
+<a name="l01770"></a>01770   sinfo_msg(<span class="stringliteral">"Computes histogram"</span>);
+<a name="l01771"></a>01771   ck0(sinfo_histogram(data_tbl,nbins,hmin,hmax,&histo),<span class="stringliteral">"building histogram"</span>);
+<a name="l01772"></a>01772 
+<a name="l01773"></a>01773   value=(double)(hmax-hmin)/nbins/2.;
+<a name="l01774"></a>01774   <span class="comment">//sinfo_msg("value=%10.8f",value);</span>
+<a name="l01775"></a>01775 
+<a name="l01776"></a>01776 
+<a name="l01777"></a>01777   <span class="keywordflow">while</span>(min_xi_sz < HISTO_MIN_SIZE && counter < 10) {
+<a name="l01778"></a>01778     counter++;
+<a name="l01779"></a>01779     check_nomsg(max_h=cpl_table_get_column_max(histo,<span class="stringliteral">"HY"</span>));
+<a name="l01780"></a>01780     <span class="comment">//cpl_table_save(histo, NULL, NULL, "out_pippo.fits", CPL_IO_DEFAULT);</span>
+<a name="l01781"></a>01781     check_nomsg(max_pos=sinfo_table_get_index_of_max(histo,<span class="stringliteral">"HY"</span>,CPL_TYPE_INT));
+<a name="l01782"></a>01782     <span class="comment">//sinfo_msg("max_pos=%d",max_pos);</span>
+<a name="l01783"></a>01783 
+<a name="l01784"></a>01784     <span class="comment">/*</span>
+<a name="l01785"></a>01785 <span class="comment">    check_nomsg(max_pos=sinfo_extract_table_rows(histo,"HY",</span>
+<a name="l01786"></a>01786 <span class="comment">                                                 CPL_EQUAL_TO,max_h));</span>
+<a name="l01787"></a>01787 <span class="comment">    sinfo_msg("size max_pos %d",cpl_table_get_nrow(max_pos));</span>
+<a name="l01788"></a>01788 <span class="comment">    sinfo_msg("value max_pos %d",cpl_table_get_int(max_pos,"HY",0,&status));</span>
+<a name="l01789"></a>01789 <span class="comment">    */</span>
+<a name="l01790"></a>01790     min_x=max_pos-1;
+<a name="l01791"></a>01791     max_x=max_pos+2;
+<a name="l01792"></a>01792     <span class="comment">//sinfo_msg("min_x=%d max_x=%d",min_x,max_x);</span>
+<a name="l01793"></a>01793 
+<a name="l01794"></a>01794     sinfo_free_table(&tmp_tbl1);
+<a name="l01795"></a>01795     <span class="comment">//sinfo_msg("x selection threshold: %f %d",</span>
+<a name="l01796"></a>01796     <span class="comment">//          cpl_table_get(histo,"HL",max_pos,&status),max_pos);</span>
+<a name="l01797"></a>01797     check_nomsg(tmp_tbl1=sinfo_extract_table_rows(histo,<span class="stringliteral">"HL"</span>,
+<a name="l01798"></a>01798                                                   CPL_LESS_THAN,
+<a name="l01799"></a>01799                                  cpl_table_get(histo,<span class="stringliteral">"HL"</span>,max_pos,&status)));
+<a name="l01800"></a>01800     thres=cpl_table_get_column_max(tmp_tbl1,<span class="stringliteral">"HY"</span>)/HISTO_Y_CUT;
+<a name="l01801"></a>01801     <span class="comment">//sinfo_msg("threshold=%f",thres);</span>
+<a name="l01802"></a>01802 
+<a name="l01803"></a>01803 
+<a name="l01804"></a>01804     sinfo_free_table(&min_xi);
+<a name="l01805"></a>01805     check_nomsg(min_xi=sinfo_extract_table_rows(tmp_tbl1,<span class="stringliteral">"HY"</span>,
+<a name="l01806"></a>01806                                                 CPL_GREATER_THAN,thres));
+<a name="l01807"></a>01807 
+<a name="l01808"></a>01808     <span class="comment">//cpl_table_save(min_xi, NULL, NULL, "out_min_xi.fits", CPL_IO_DEFAULT);</span>
+<a name="l01809"></a>01809 
+<a name="l01810"></a>01810 
+<a name="l01811"></a>01811 
+<a name="l01812"></a>01812     min_xi_sz=cpl_table_get_nrow(min_xi);
+<a name="l01813"></a>01813     val=cpl_table_get(min_xi,<span class="stringliteral">"HL"</span>,0,&status);
+<a name="l01814"></a>01814 
+<a name="l01815"></a>01815     check_nomsg(min_pos=sinfo_table_get_index_of_val(histo,<span class="stringliteral">"HL"</span>,val,
+<a name="l01816"></a>01816                                                      CPL_TYPE_DOUBLE));
+<a name="l01817"></a>01817     <span class="comment">//sinfo_msg("min_pos=%d max_pos=%d max(h)=%d min_xi_sz=%d x[maxpos[0]]=%f",</span>
+<a name="l01818"></a>01818     <span class="comment">//           min_pos,   max_pos,   max_h,    min_xi_sz, val);</span>
+<a name="l01819"></a>01819 
+<a name="l01820"></a>01820 
+<a name="l01821"></a>01821 
+<a name="l01822"></a>01822     <span class="keywordflow">if</span> (min_xi_sz > 0) {
+<a name="l01823"></a>01823       min_x = min_pos-HISTO_X_LEFT_CUT*(max_pos-min_pos);
+<a name="l01824"></a>01824       max_x = max_pos+HISTO_X_RIGHT_CUT*(max_pos-min_pos);
+<a name="l01825"></a>01825     }
+<a name="l01826"></a>01826 
+<a name="l01827"></a>01827     <span class="comment">//sinfo_msg("min_x=%d max_x=%d",min_x,max_x);</span>
+<a name="l01828"></a>01828     check_nomsg(hmin=sinfo_table_column_interpolate(histo,<span class="stringliteral">"HL"</span>,min_x));
+<a name="l01829"></a>01829     check_nomsg(hmax=sinfo_table_column_interpolate(histo,<span class="stringliteral">"HL"</span>,max_x));
+<a name="l01830"></a>01830     <span class="comment">//sinfo_msg("hmin=%f hmax=%f min_xi_sz=%d",hmin,hmax,min_xi_sz);</span>
+<a name="l01831"></a>01831     <span class="comment">//cpl_table_save(histo, NULL, NULL, "out_histo.fits", CPL_IO_DEFAULT);</span>
+<a name="l01832"></a>01832     sinfo_free_table(&histo);
+<a name="l01833"></a>01833     ck0(sinfo_histogram(data_tbl,nbins,hmin,hmax,&histo),<span class="stringliteral">"building histogram"</span>);
+<a name="l01834"></a>01834     <span class="comment">//cpl_table_save(histo, NULL, NULL, "out_histo1.fits", CPL_IO_DEFAULT);</span>
+<a name="l01835"></a>01835     check_nomsg(cpl_table_add_scalar(histo,<span class="stringliteral">"HL"</span>,(hmax-hmin)/nbins/2));
+<a name="l01836"></a>01836     <span class="comment">//cpl_table_save(histo, NULL, NULL, "out_histo2.fits", CPL_IO_DEFAULT);</span>
+<a name="l01837"></a>01837 
+<a name="l01838"></a>01838 
+<a name="l01839"></a>01839 
+<a name="l01840"></a>01840   }
+<a name="l01841"></a>01841   sinfo_free_table(&data_tbl);
+<a name="l01842"></a>01842   sinfo_free_table(&min_xi);
+<a name="l01843"></a>01843 
+<a name="l01844"></a>01844   <span class="comment">//cpl_table_save(histo, NULL, NULL, "out_histo.fits", CPL_IO_DEFAULT);</span>
+<a name="l01845"></a>01845 
+<a name="l01846"></a>01846   check_nomsg(peak=cpl_table_get_column_max(histo,<span class="stringliteral">"HY"</span>));
+<a name="l01847"></a>01847   <span class="comment">//sinfo_msg("peak=%f",peak);</span>
+<a name="l01848"></a>01848   sinfo_free_table(&tmp_tbl1);
+<a name="l01849"></a>01849 
+<a name="l01850"></a>01850   check_nomsg(tmp_tbl1=sinfo_extract_table_rows(histo,<span class="stringliteral">"HY"</span>,CPL_EQUAL_TO,peak));
+<a name="l01851"></a>01851 
+<a name="l01852"></a>01852   <span class="comment">//cpl_table_save(tmp_tbl1, NULL, NULL, "out_tmp_tbl1.fits", CPL_IO_DEFAULT);</span>
+<a name="l01853"></a>01853 
+<a name="l01854"></a>01854 
+<a name="l01855"></a>01855   check_nomsg(*centre=cpl_table_get_column_mean(tmp_tbl1,<span class="stringliteral">"HL"</span>));
+<a name="l01856"></a>01856   <span class="comment">//sinfo_msg("Background level=%f",*centre);</span>
+<a name="l01857"></a>01857 
+<a name="l01858"></a>01858   sinfo_free_table(&tmp_tbl1);
+<a name="l01859"></a>01859   check_nomsg(tmp_tbl1=sinfo_extract_table_rows(histo,<span class="stringliteral">"HY"</span>,
+<a name="l01860"></a>01860                                                 CPL_GREATER_THAN,
+<a name="l01861"></a>01861                                                 peak/HISTO_Y_CUT));
+<a name="l01862"></a>01862   sinfo_free_table(&tmp_tbl2);
+<a name="l01863"></a>01863   check_nomsg(tmp_tbl2=sinfo_extract_table_rows(tmp_tbl1,<span class="stringliteral">"HY"</span>,
+<a name="l01864"></a>01864                                                 CPL_LESS_THAN,peak));
+<a name="l01865"></a>01865   sinfo_free_table(&tmp_tbl1);
+<a name="l01866"></a>01866 
+<a name="l01867"></a>01867   check_nomsg(tempc=*centre-cpl_table_get_column_min(tmp_tbl2,<span class="stringliteral">"HL"</span>));
+<a name="l01868"></a>01868   <span class="comment">//sinfo_msg("min HX %f",cpl_table_get_column_min(tmp_tbl2,"HL"));</span>
+<a name="l01869"></a>01869   sinfo_free_table(&tmp_tbl2);
+<a name="l01870"></a>01870   <span class="comment">//sinfo_msg("Tempc=%f",tempc);</span>
+<a name="l01871"></a>01871   check_nomsg(dist=sinfo_where_tab_min_max(histo,<span class="stringliteral">"HL"</span>,
+<a name="l01872"></a>01872                  CPL_GREATER_THAN,*centre-HISTO_DIST_TEMPC_MIN_FCT*tempc,
+<a name="l01873"></a>01873                  CPL_NOT_GREATER_THAN,*centre+HISTO_DIST_TEMPC_MAX_FCT*tempc));
+<a name="l01874"></a>01874 
+<a name="l01875"></a>01875   offset=cpl_table_get_column_min(histo,<span class="stringliteral">"HY"</span>);
+<a name="l01876"></a>01876   sinfo_free_table(&histo);
+<a name="l01877"></a>01877 
+<a name="l01878"></a>01878 
+<a name="l01879"></a>01879   check_nomsg(ndist=cpl_table_get_nrow(dist));
+<a name="l01880"></a>01880   check_nomsg(cpl_table_cast_column(dist,<span class="stringliteral">"HY"</span>,<span class="stringliteral">"HYdouble"</span>,CPL_TYPE_DOUBLE));
+<a name="l01881"></a>01881   check_nomsg(disth=cpl_table_get_data_double(dist,<span class="stringliteral">"HYdouble"</span>));
+<a name="l01882"></a>01882   check_nomsg(distx=cpl_table_get_data_double(dist,<span class="stringliteral">"HL"</span>));
+<a name="l01883"></a>01883   <span class="comment">//cpl_table_save(dist, NULL, NULL, "out_dist.fits", CPL_IO_DEFAULT);</span>
+<a name="l01884"></a>01884 
+<a name="l01885"></a>01885   <span class="comment">//TODO</span>
+<a name="l01886"></a>01886   <span class="comment">//gaussfit(distx,disty,dista,nterms=3);</span>
+<a name="l01887"></a>01887   <span class="comment">//*noise=dista[2];</span>
+<a name="l01888"></a>01888   *noise=tempc/2;
+<a name="l01889"></a>01889   <span class="comment">/* THIS DOES NOT WORK */</span>
+<a name="l01890"></a>01890   <span class="comment">//sinfo_msg("FWHM/2=%f",*noise);</span>
+<a name="l01891"></a>01891 
+<a name="l01892"></a>01892   <span class="keywordflow">if</span>(obj_noise_fit == 1) {
+<a name="l01893"></a>01893     check_nomsg(vy=cpl_vector_wrap(ndist,disth));
+<a name="l01894"></a>01894     check_nomsg(vx=cpl_vector_wrap(ndist,distx));
+<a name="l01895"></a>01895     check_nomsg(sx=cpl_vector_new(ndist));
+<a name="l01896"></a>01896     check_nomsg(cpl_vector_fill(sx,1.));
+<a name="l01897"></a>01897     check_nomsg(sy=cpl_vector_duplicate(sx));
+<a name="l01898"></a>01898     x0=*centre;
+<a name="l01899"></a>01899     sigma=tempc/2;
+<a name="l01900"></a>01900 
+<a name="l01901"></a>01901     check_nomsg(cpl_vector_fit_gaussian(vx,NULL,
+<a name="l01902"></a>01902                                         vy,NULL,
+<a name="l01903"></a>01903                                         CPL_FIT_ALL,
+<a name="l01904"></a>01904                                         &x0,&sigma,&area,&offset,
+<a name="l01905"></a>01905                                         NULL,NULL,NULL));
+<a name="l01906"></a>01906     <span class="comment">//sinfo_msg("Gauss fit parameters:"</span>
+<a name="l01907"></a>01907     <span class="comment">//          "x0=%f sigma=%f area=%f offset=%f mse=%f chired=%f",</span>
+<a name="l01908"></a>01908     <span class="comment">//           x0,sigma,area,offset,mse,chired);</span>
+<a name="l01909"></a>01909     <span class="comment">//sinfo_msg("Background level=%f",*centre);</span>
+<a name="l01910"></a>01910     <span class="comment">//sinfo_msg("Noise=%f",sigma);</span>
+<a name="l01911"></a>01911     *noise=sigma;
+<a name="l01912"></a>01912     sinfo_unwrap_vector(&vx);
+<a name="l01913"></a>01913     sinfo_unwrap_vector(&vy);
+<a name="l01914"></a>01914     sinfo_free_my_vector(&sx);
+<a name="l01915"></a>01915     sinfo_free_my_vector(&sy);
+<a name="l01916"></a>01916   }
+<a name="l01917"></a>01917   sinfo_free_table(&dist);
+<a name="l01918"></a>01918   <span class="comment">//*noise=18.7448;</span>
+<a name="l01919"></a>01919   <span class="comment">//*noise=20.585946;</span>
+<a name="l01920"></a>01920   <span class="keywordflow">return</span> 0;
+<a name="l01921"></a>01921 
+<a name="l01922"></a>01922  cleanup:
+<a name="l01923"></a>01923   sinfo_free_imagelist(&obj_cub);
+<a name="l01924"></a>01924   sinfo_free_propertylist(&plist);
+<a name="l01925"></a>01925   sinfo_free_table(&min_xi);
+<a name="l01926"></a>01926   sinfo_free_table(&tmp_tbl1);
+<a name="l01927"></a>01927   sinfo_free_table(&tmp_tbl2);
+<a name="l01928"></a>01928   sinfo_free_table(&histo);
+<a name="l01929"></a>01929   sinfo_free_table(&dist);
+<a name="l01930"></a>01930   sinfo_free_table(&data_tbl);
+<a name="l01931"></a>01931   sinfo_free_my_vector(&sx);
+<a name="l01932"></a>01932   sinfo_free_my_vector(&sy);
+<a name="l01933"></a>01933   sinfo_unwrap_vector(&vx);
+<a name="l01934"></a>01934   sinfo_unwrap_vector(&vy);
+<a name="l01935"></a>01935 
+<a name="l01936"></a>01936   <span class="keywordflow">return</span> -1;
+<a name="l01937"></a>01937 
+<a name="l01938"></a>01938 }
+<a name="l01939"></a>01939 
+<a name="l01940"></a>01940 
+<a name="l01953"></a>01953 cpl_table*
+<a name="l01954"></a>01954 sinfo_where_tab_min_max(cpl_table* t,
+<a name="l01955"></a>01955                         <span class="keyword">const</span> <span class="keywordtype">char</span>* col,
+<a name="l01956"></a>01956                         cpl_table_select_operator op1,
+<a name="l01957"></a>01957                         <span class="keyword">const</span> <span class="keywordtype">double</span> v1,
+<a name="l01958"></a>01958                         cpl_table_select_operator op2,
+<a name="l01959"></a>01959                         <span class="keyword">const</span> <span class="keywordtype">double</span> v2)
+<a name="l01960"></a>01960 {
+<a name="l01961"></a>01961 
+<a name="l01962"></a>01962   cpl_table* res=NULL;
+<a name="l01963"></a>01963   cpl_table* tmp=NULL;
+<a name="l01964"></a>01964 
+<a name="l01965"></a>01965   check_nomsg(cpl_table_and_selected_double(t,col,op1,v1));
+<a name="l01966"></a>01966   check_nomsg(tmp=cpl_table_extract_selected(t));
+<a name="l01967"></a>01967   check_nomsg(cpl_table_and_selected_double(tmp,col,op2,v2));
+<a name="l01968"></a>01968   check_nomsg(res=cpl_table_extract_selected(tmp));
+<a name="l01969"></a>01969   check_nomsg(cpl_table_select_all(t));
+<a name="l01970"></a>01970   sinfo_free_table(&tmp);
+<a name="l01971"></a>01971 
+<a name="l01972"></a>01972   <span class="keywordflow">return</span> res;
+<a name="l01973"></a>01973 
+<a name="l01974"></a>01974  cleanup:
+<a name="l01975"></a>01975   sinfo_free_table(&tmp);
+<a name="l01976"></a>01976   sinfo_free_table(&res);
+<a name="l01977"></a>01977 
+<a name="l01978"></a>01978   <span class="keywordflow">return</span> NULL;
+<a name="l01979"></a>01979 
+<a name="l01980"></a>01980 }
+<a name="l01981"></a>01981 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l02005"></a>02005 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l02006"></a>02006 
+<a name="l02007"></a>02007 <span class="keywordtype">int</span>
+<a name="l02008"></a>02008 sinfo_histogram(<span class="keyword">const</span> cpl_table* data,
+<a name="l02009"></a>02009                 <span class="keyword">const</span> <span class="keywordtype">int</span> nbins,
+<a name="l02010"></a>02010                 <span class="keyword">const</span> <span class="keywordtype">double</span> min,
+<a name="l02011"></a>02011                 <span class="keyword">const</span> <span class="keywordtype">double</span> max,
+<a name="l02012"></a>02012                 cpl_table** histo)
+<a name="l02013"></a>02013 {
+<a name="l02014"></a>02014   cpl_table* tmp_tbl1=NULL;
+<a name="l02015"></a>02015   cpl_table* tmp_tbl2=NULL;
+<a name="l02016"></a>02016   cpl_table* dat=NULL;
+<a name="l02017"></a>02017   <span class="keywordtype">int</span> ntot=0;
+<a name="l02018"></a>02018   <span class="keywordtype">int</span> i=0;
+<a name="l02019"></a>02019   <span class="keywordtype">int</span>* phy=NULL;
+<a name="l02020"></a>02020   <span class="keywordtype">double</span>* pdt=NULL;
+<a name="l02021"></a>02021   <span class="comment">/* double* phx=NULL; */</span>
+<a name="l02022"></a>02022 
+<a name="l02023"></a>02023   <span class="keywordtype">double</span> vtmp=0;
+<a name="l02024"></a>02024   <span class="keywordtype">double</span> vstp=0;
+<a name="l02025"></a>02025   <span class="keywordtype">double</span> vmax=0;
+<a name="l02026"></a>02026   <span class="keywordtype">double</span> vmin=0;
+<a name="l02027"></a>02027 
+<a name="l02028"></a>02028   <span class="keywordtype">int</span> h=0;
+<a name="l02029"></a>02029   check_nomsg(dat=cpl_table_duplicate(data));
+<a name="l02030"></a>02030   check_nomsg(cpl_table_cast_column(dat,<span class="stringliteral">"DATA"</span>,<span class="stringliteral">"DDATA"</span>,CPL_TYPE_DOUBLE));
+<a name="l02031"></a>02031   <span class="comment">/*</span>
+<a name="l02032"></a>02032 <span class="comment">  sinfo_msg("min=%f max=%f",</span>
+<a name="l02033"></a>02033 <span class="comment">            cpl_table_get_column_min(dat,"DDATA"),</span>
+<a name="l02034"></a>02034 <span class="comment">            cpl_table_get_column_max(dat,"DDATA"));</span>
+<a name="l02035"></a>02035 <span class="comment">  */</span>
+<a name="l02036"></a>02036   check_nomsg(cpl_table_and_selected_double(dat,<span class="stringliteral">"DDATA"</span>,
+<a name="l02037"></a>02037                                             CPL_NOT_GREATER_THAN,max));
+<a name="l02038"></a>02038   <span class="comment">/*</span>
+<a name="l02039"></a>02039 <span class="comment">  check_nomsg(cpl_table_and_selected_double(dat,"DDATA",CPL_LESS_THAN,max));</span>
+<a name="l02040"></a>02040 <span class="comment">  */</span>
+<a name="l02041"></a>02041   check_nomsg(tmp_tbl1=cpl_table_extract_selected(dat));
+<a name="l02042"></a>02042   <span class="comment">/*</span>
+<a name="l02043"></a>02043 <span class="comment">  sinfo_msg("min=%f max=%f",</span>
+<a name="l02044"></a>02044 <span class="comment">             cpl_table_get_column_min(tmp_tbl1,"DDATA"),</span>
+<a name="l02045"></a>02045 <span class="comment">             cpl_table_get_column_max(tmp_tbl1,"DDATA"));</span>
+<a name="l02046"></a>02046 <span class="comment">  */</span>
+<a name="l02047"></a>02047   <span class="comment">/*</span>
+<a name="l02048"></a>02048 <span class="comment">  check_nomsg(cpl_table_and_selected_double(tmp_tbl1,"DDATA",</span>
+<a name="l02049"></a>02049 <span class="comment">                                            CPL_NOT_LESS_THAN,min));</span>
+<a name="l02050"></a>02050 <span class="comment">  */</span>
+<a name="l02051"></a>02051   check_nomsg(cpl_table_and_selected_double(tmp_tbl1,<span class="stringliteral">"DDATA"</span>,
+<a name="l02052"></a>02052                                             CPL_GREATER_THAN,min));
+<a name="l02053"></a>02053   check_nomsg(tmp_tbl2=cpl_table_extract_selected(tmp_tbl1));
+<a name="l02054"></a>02054   <span class="comment">/*</span>
+<a name="l02055"></a>02055 <span class="comment">  sinfo_msg("min=%f max=%f",</span>
+<a name="l02056"></a>02056 <span class="comment">             cpl_table_get_column_min(tmp_tbl2,"DDATA"),</span>
+<a name="l02057"></a>02057 <span class="comment">             cpl_table_get_column_max(tmp_tbl2,"DDATA"));</span>
+<a name="l02058"></a>02058 <span class="comment">  */</span>
+<a name="l02059"></a>02059   sinfo_free_table(&tmp_tbl1);
+<a name="l02060"></a>02060   <span class="comment">/*</span>
+<a name="l02061"></a>02061 <span class="comment">  check_nomsg(tmp_tbl1=sinfo_extract_table_rows(dat,"DDATA",</span>
+<a name="l02062"></a>02062 <span class="comment">                                                CPL_NOT_GREATER_THAN,max));</span>
+<a name="l02063"></a>02063 <span class="comment">  check_nomsg(tmp_tbl2=sinfo_extract_table_rows(tmp_tbl1,"DDATA",</span>
+<a name="l02064"></a>02064 <span class="comment">                                                CPL_NOT_LESS_THAN,min));</span>
+<a name="l02065"></a>02065 <span class="comment">  */</span>
+<a name="l02066"></a>02066 
+<a name="l02067"></a>02067   check_nomsg(ntot=cpl_table_get_nrow(tmp_tbl2));
+<a name="l02068"></a>02068   <span class="comment">/* not necessry to sort:</span>
+<a name="l02069"></a>02069 <span class="comment">    check_nomsg(sinfo_sort_table_1(tmp_tbl2,"DDATA",FALSE));*/</span>
+<a name="l02070"></a>02070   check_nomsg(vmin=cpl_table_get_column_min(tmp_tbl2,<span class="stringliteral">"DDATA"</span>));
+<a name="l02071"></a>02071   check_nomsg(vmax=cpl_table_get_column_max(tmp_tbl2,<span class="stringliteral">"DDATA"</span>));
+<a name="l02072"></a>02072   vstp=(vmax-vmin)/(nbins-1);
+<a name="l02073"></a>02073   <span class="comment">/* sinfo_msg("vmin=%f vmax=%f step=%f",vmin,vmax,vstp); */</span>
+<a name="l02074"></a>02074   check_nomsg(*histo=cpl_table_new(nbins));
+<a name="l02075"></a>02075   check_nomsg(cpl_table_new_column(*histo,<span class="stringliteral">"HX"</span>,CPL_TYPE_DOUBLE));
+<a name="l02076"></a>02076   check_nomsg(cpl_table_new_column(*histo,<span class="stringliteral">"HL"</span>,CPL_TYPE_DOUBLE));
+<a name="l02077"></a>02077   check_nomsg(cpl_table_new_column(*histo,<span class="stringliteral">"HY"</span>,CPL_TYPE_INT));
+<a name="l02078"></a>02078 
+<a name="l02079"></a>02079   <span class="comment">/*check_nomsg(cpl_table_fill_column_window(*histo,"HX",0,nbins,0)); */</span>
+<a name="l02080"></a>02080   check_nomsg(cpl_table_fill_column_window(*histo,<span class="stringliteral">"HL"</span>,0,nbins,0));
+<a name="l02081"></a>02081   check_nomsg(cpl_table_fill_column_window(*histo,<span class="stringliteral">"HY"</span>,0,nbins,0));
+<a name="l02082"></a>02082 
+<a name="l02083"></a>02083   check_nomsg(phy=cpl_table_get_data_int(*histo,<span class="stringliteral">"HY"</span>));
+<a name="l02084"></a>02084   <span class="comment">/*check_nomsg(phx=cpl_table_get_data_double(*histo,"HX")); */</span>
+<a name="l02085"></a>02085   check_nomsg(pdt=cpl_table_get_data_double(dat,<span class="stringliteral">"DATA"</span>));
+<a name="l02086"></a>02086 
+<a name="l02087"></a>02087   <span class="keywordflow">for</span>(i=0;i<nbins;i++) {
+<a name="l02088"></a>02088     cpl_table_set_double(*histo,<span class="stringliteral">"HX"</span>,i,(<span class="keywordtype">double</span>)i);
+<a name="l02089"></a>02089     vtmp=vmin+i*vstp;
+<a name="l02090"></a>02090     cpl_table_set_double(*histo,<span class="stringliteral">"HL"</span>,i,vtmp);
+<a name="l02091"></a>02091   }
+<a name="l02092"></a>02092   h=0;
+<a name="l02093"></a>02093 
+<a name="l02094"></a>02094   <span class="keywordflow">for</span>(i=0;i<ntot;i++) {
+<a name="l02095"></a>02095     h=floor((pdt[i]-vmin)/vstp);
+<a name="l02096"></a>02096     <span class="keywordflow">if</span>((h<nbins) && (h>-1)) {
+<a name="l02097"></a>02097       phy[h]++;
+<a name="l02098"></a>02098     }
+<a name="l02099"></a>02099   }
+<a name="l02100"></a>02100   <span class="comment">//cpl_table_save(*histo, NULL, NULL, "out_histo_p5.fits", CPL_IO_DEFAULT);</span>
+<a name="l02101"></a>02101 
+<a name="l02102"></a>02102   sinfo_free_table(&tmp_tbl2);
+<a name="l02103"></a>02103   sinfo_free_table(&dat);
+<a name="l02104"></a>02104 
+<a name="l02105"></a>02105 
+<a name="l02106"></a>02106   <span class="keywordflow">return</span> 0;
+<a name="l02107"></a>02107  cleanup:
+<a name="l02108"></a>02108   sinfo_free_table(&tmp_tbl1);
+<a name="l02109"></a>02109   sinfo_free_table(&tmp_tbl2);
+<a name="l02110"></a>02110   sinfo_free_table(&dat);
+<a name="l02111"></a>02111 
+<a name="l02112"></a>02112   <span class="keywordflow">return</span> -1;
+<a name="l02113"></a>02113 
+<a name="l02114"></a>02114 }
+<a name="l02115"></a>02115 
+<a name="l02116"></a>02116 
+<a name="l02117"></a>02117 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l02127"></a>02127 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l02128"></a>02128 
+<a name="l02129"></a>02129 <span class="keywordtype">int</span>
+<a name="l02130"></a>02130 sinfo_object_flag_low_values(cpl_frame* obj_frm,
+<a name="l02131"></a>02131                              <span class="keyword">const</span> <span class="keywordtype">double</span> cnt,
+<a name="l02132"></a>02132                              <span class="keyword">const</span> <span class="keywordtype">double</span> sig,
+<a name="l02133"></a>02133                              cpl_imagelist** flag_data)
+<a name="l02134"></a>02134 {
+<a name="l02135"></a>02135 
+<a name="l02136"></a>02136   <span class="keywordtype">int</span> xsz=0;
+<a name="l02137"></a>02137   <span class="keywordtype">int</span> ysz=0;
+<a name="l02138"></a>02138   <span class="keywordtype">int</span> zsz=0;
+<a name="l02139"></a>02139   <span class="keywordtype">int</span> n=0;
+<a name="l02140"></a>02140   <span class="keywordtype">int</span> i=0;
+<a name="l02141"></a>02141   <span class="keywordtype">int</span> k=0;
+<a name="l02142"></a>02142   <span class="keywordtype">int</span> r=0;
+<a name="l02143"></a>02143 
+<a name="l02144"></a>02144   cpl_propertylist* plist=NULL;
+<a name="l02145"></a>02145   cpl_table* data_tbl=NULL;
+<a name="l02146"></a>02146   cpl_table* flag_tbl=NULL;
+<a name="l02147"></a>02147   cpl_image* img=NULL;
+<a name="l02148"></a>02148   cpl_imagelist* obj_cub=NULL;
+<a name="l02149"></a>02149 
+<a name="l02150"></a>02150   <span class="keywordtype">double</span>* pdata=NULL;
+<a name="l02151"></a>02151   <span class="keywordtype">double</span>* pflag=NULL;
+<a name="l02152"></a>02152 
+<a name="l02153"></a>02153  <span class="comment">/* Get Object relevant information */</span>
+<a name="l02154"></a>02154   cknull_nomsg(plist=cpl_propertylist_load(cpl_frame_get_filename(obj_frm),0));
+<a name="l02155"></a>02155   check_nomsg(xsz=sinfo_pfits_get_naxis1(plist));
+<a name="l02156"></a>02156   check_nomsg(ysz=sinfo_pfits_get_naxis2(plist));
+<a name="l02157"></a>02157   check_nomsg(zsz=sinfo_pfits_get_naxis3(plist));
+<a name="l02158"></a>02158   sinfo_free_propertylist(&plist);
+<a name="l02159"></a>02159 
+<a name="l02160"></a>02160   cknull_nomsg(obj_cub=cpl_imagelist_load(cpl_frame_get_filename(obj_frm),
+<a name="l02161"></a>02161                                           CPL_TYPE_DOUBLE,0));
+<a name="l02162"></a>02162 
+<a name="l02163"></a>02163   n=xsz*ysz*zsz;
+<a name="l02164"></a>02164   check_nomsg(data_tbl=cpl_table_new(n));
+<a name="l02165"></a>02165   check_nomsg(cpl_table_new_column(data_tbl,<span class="stringliteral">"DATA"</span>,CPL_TYPE_DOUBLE));
+<a name="l02166"></a>02166 
+<a name="l02167"></a>02167   <span class="keywordflow">for</span>(k=0;k<zsz;k++) {
+<a name="l02168"></a>02168     check_nomsg(img=cpl_imagelist_get(obj_cub,k));
+<a name="l02169"></a>02169     check_nomsg(pdata=cpl_image_get_data_double(img));
+<a name="l02170"></a>02170     <span class="keywordflow">for</span>(i=0;i<xsz*ysz;i++) {
+<a name="l02171"></a>02171       <span class="keywordflow">if</span>(!<a class="code" href="group__irplib__utils.html#ga804bfc739b5d55f9797ab881b1034ae4" title="portable isnan">irplib_isnan</a>(pdata[i])) {
+<a name="l02172"></a>02172     check_nomsg(cpl_table_set_double(data_tbl,<span class="stringliteral">"DATA"</span>,r,pdata[i]));
+<a name="l02173"></a>02173         r++;
+<a name="l02174"></a>02174       }
+<a name="l02175"></a>02175     }
+<a name="l02176"></a>02176   }
+<a name="l02177"></a>02177 
+<a name="l02178"></a>02178   check_nomsg(cpl_table_erase_invalid(data_tbl));
+<a name="l02179"></a>02179   <span class="comment">//sinfo_msg("Background level: %f Noise: %f",cnt,sig);</span>
+<a name="l02180"></a>02180   check_nomsg(cpl_table_and_selected_double(data_tbl,<span class="stringliteral">"DATA"</span>,
+<a name="l02181"></a>02181                                            CPL_LESS_THAN,cnt+2*sig));
+<a name="l02182"></a>02182   check_nomsg(flag_tbl=cpl_table_extract_selected(data_tbl));
+<a name="l02183"></a>02183   sinfo_free_table(&data_tbl);
+<a name="l02184"></a>02184   <span class="comment">//check_nomsg(cpl_table_save(flag_tbl,NULL,NULL,</span>
+<a name="l02185"></a>02185   <span class="comment">//                             "out_flag.fits",CPL_IO_DEFAULT));</span>
+<a name="l02186"></a>02186   sinfo_free_table(&flag_tbl);
+<a name="l02187"></a>02187 
+<a name="l02188"></a>02188   check_nomsg(*flag_data=cpl_imagelist_new());
+<a name="l02189"></a>02189   <span class="keywordflow">for</span>(i=0;i<zsz;i++) {
+<a name="l02190"></a>02190     check_nomsg(img=cpl_image_new(xsz,ysz,CPL_TYPE_DOUBLE));
+<a name="l02191"></a>02191     check_nomsg(cpl_image_add_scalar(img,0));
+<a name="l02192"></a>02192     check_nomsg(cpl_imagelist_set(*flag_data,cpl_image_duplicate(img),i));
+<a name="l02193"></a>02193     sinfo_free_image(&img);
+<a name="l02194"></a>02194   }
+<a name="l02195"></a>02195   <span class="keywordflow">for</span>(k=0;k<zsz;k++) {
+<a name="l02196"></a>02196     check_nomsg(img=cpl_imagelist_get(*flag_data,k));
+<a name="l02197"></a>02197     pflag=cpl_image_get_data_double(cpl_imagelist_get(*flag_data,k));
+<a name="l02198"></a>02198     pdata=cpl_image_get_data_double(cpl_imagelist_get(obj_cub,k));
+<a name="l02199"></a>02199     <span class="keywordflow">for</span>(i=0;i<xsz*ysz;i++) {
+<a name="l02200"></a>02200       <span class="keywordflow">if</span>((!<a class="code" href="group__irplib__utils.html#ga804bfc739b5d55f9797ab881b1034ae4" title="portable isnan">irplib_isnan</a>(pdata[i])) && pdata[i] < (cnt+2*sig)) {
+<a name="l02201"></a>02201         pflag[i]=1;
+<a name="l02202"></a>02202       }
+<a name="l02203"></a>02203     }
+<a name="l02204"></a>02204   }
+<a name="l02205"></a>02205 
+<a name="l02206"></a>02206   sinfo_free_imagelist(&obj_cub);
+<a name="l02207"></a>02207 
+<a name="l02208"></a>02208 
+<a name="l02209"></a>02209 
+<a name="l02210"></a>02210 
+<a name="l02211"></a>02211   <span class="keywordflow">return</span> 0;
+<a name="l02212"></a>02212 
+<a name="l02213"></a>02213  cleanup:
+<a name="l02214"></a>02214   sinfo_free_propertylist(&plist);
+<a name="l02215"></a>02215   sinfo_free_imagelist(&obj_cub);
+<a name="l02216"></a>02216   sinfo_free_table(&data_tbl);
+<a name="l02217"></a>02217   sinfo_free_table(&flag_tbl);
+<a name="l02218"></a>02218 
+<a name="l02219"></a>02219   <span class="keywordflow">return</span> -1;
+<a name="l02220"></a>02220 }
+<a name="l02221"></a>02221 
+<a name="l02222"></a>02222 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l02236"></a>02236 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l02237"></a>02237 
+<a name="l02238"></a>02238 
+<a name="l02239"></a>02239 <span class="keywordtype">int</span>
+<a name="l02240"></a>02240 sinfo_object_flag_sky_pixels(cpl_frame* obj_frm,
+<a name="l02241"></a>02241                              cpl_table* lambda,
+<a name="l02242"></a>02242                              cpl_table* mrange,
+<a name="l02243"></a>02243                  cpl_imagelist* flag_data,
+<a name="l02244"></a>02244                              <span class="keyword">const</span> <span class="keywordtype">double</span> tol,
+<a name="l02245"></a>02245                              cpl_image** g_img,
+<a name="l02246"></a>02246                              cpl_image** r_img,
+<a name="l02247"></a>02247                              cpl_image** image)
+<a name="l02248"></a>02248 {
+<a name="l02249"></a>02249 
+<a name="l02250"></a>02250   <span class="keywordtype">int</span> xsz=0;
+<a name="l02251"></a>02251   <span class="keywordtype">int</span> ysz=0;
+<a name="l02252"></a>02252   <span class="keywordtype">int</span> zsz=0;
+<a name="l02253"></a>02253   <span class="keywordtype">int</span> i=0;
+<a name="l02254"></a>02254   <span class="keywordtype">int</span> j=0;
+<a name="l02255"></a>02255   <span class="keywordtype">int</span> gpix_i=0;
+<a name="l02256"></a>02256   <span class="keywordtype">double</span> tot=0;
+<a name="l02257"></a>02257   <span class="keywordtype">double</span> all_pix=0;
+<a name="l02258"></a>02258   <span class="keywordtype">double</span> flag_pix=0;
+<a name="l02259"></a>02259   <span class="keywordtype">double</span> ratio=0;
+<a name="l02260"></a>02260 
+<a name="l02261"></a>02261   <span class="keywordtype">double</span>* pr_img=NULL;
+<a name="l02262"></a>02262   <span class="keywordtype">double</span>* pg_img=NULL;
+<a name="l02263"></a>02263   <span class="keywordtype">double</span>* pimage=NULL;
+<a name="l02264"></a>02264   cpl_propertylist* plist=NULL;
+<a name="l02265"></a>02265   cpl_imagelist* osel=NULL;
+<a name="l02266"></a>02266   cpl_imagelist* fsel=NULL;
+<a name="l02267"></a>02267   cpl_table* gpix=NULL;
+<a name="l02268"></a>02268   cpl_table* gspec=NULL;
+<a name="l02269"></a>02269   cpl_table* fspec=NULL;
+<a name="l02270"></a>02270   cpl_table* ospec=NULL;
+<a name="l02271"></a>02271 
+<a name="l02272"></a>02272   cpl_imagelist* obj_cub=NULL;
+<a name="l02273"></a>02273 
+<a name="l02274"></a>02274   <span class="comment">/* Get Object relevant information */</span>
+<a name="l02275"></a>02275   cknull_nomsg(plist=cpl_propertylist_load(cpl_frame_get_filename(obj_frm),0));
+<a name="l02276"></a>02276 
+<a name="l02277"></a>02277   check_nomsg(xsz=sinfo_pfits_get_naxis1(plist));
+<a name="l02278"></a>02278   check_nomsg(ysz=sinfo_pfits_get_naxis2(plist));
+<a name="l02279"></a>02279   check_nomsg(zsz=sinfo_pfits_get_naxis3(plist));
+<a name="l02280"></a>02280   sinfo_free_propertylist(&plist);
+<a name="l02281"></a>02281   cknull_nomsg(obj_cub=cpl_imagelist_load(cpl_frame_get_filename(obj_frm),
+<a name="l02282"></a>02282                                                       CPL_TYPE_DOUBLE,0));
+<a name="l02283"></a>02283 
+<a name="l02284"></a>02284   <span class="comment">/* Flag sky pixels in data cube */</span>
+<a name="l02285"></a>02285   <span class="comment">/* create images */</span>
+<a name="l02286"></a>02286   check_nomsg(*r_img=cpl_image_new(xsz,ysz,CPL_TYPE_DOUBLE));
+<a name="l02287"></a>02287   check_nomsg(*g_img=cpl_image_new(xsz,ysz,CPL_TYPE_DOUBLE));
+<a name="l02288"></a>02288   check_nomsg(*image=cpl_image_new(xsz,ysz,CPL_TYPE_DOUBLE));
+<a name="l02289"></a>02289 
+<a name="l02290"></a>02290   cknull_nomsg(pr_img=cpl_image_get_data_double(*r_img));
+<a name="l02291"></a>02291   cknull_nomsg(pg_img=cpl_image_get_data_double(*g_img));
+<a name="l02292"></a>02292   cknull_nomsg(pimage=cpl_image_get_data_double(*image));
+<a name="l02293"></a>02293 
+<a name="l02294"></a>02294   <span class="comment">/* TODO */</span>
+<a name="l02295"></a>02295   <span class="comment">// fill image points:</span>
+<a name="l02296"></a>02296   <span class="comment">// g_img: mask with at least half good pixels along spectral range</span>
+<a name="l02297"></a>02297   <span class="comment">// r_img: mask with ratio of good pixels along spectral range</span>
+<a name="l02298"></a>02298   <span class="comment">// image: image with mean of spectrum over good pixels</span>
+<a name="l02299"></a>02299 
+<a name="l02300"></a>02300   <span class="comment">//check_nomsg(cpl_table_save(lambda, NULL, NULL,</span>
+<a name="l02301"></a>02301   <span class="comment">//                             "out_lambda.fits", CPL_IO_DEFAULT));</span>
+<a name="l02302"></a>02302   <span class="comment">//check_nomsg(cpl_table_save(mrange, NULL, NULL,</span>
+<a name="l02303"></a>02303   <span class="comment">//                             "out_mrange.fits", CPL_IO_DEFAULT));</span>
+<a name="l02304"></a>02304 
+<a name="l02305"></a>02305   cknull_nomsg(osel=sinfo_imagelist_select_range(obj_cub,lambda,
+<a name="l02306"></a>02306                                                       mrange,tol));
+<a name="l02307"></a>02307 
+<a name="l02308"></a>02308   sinfo_free_imagelist(&obj_cub);
+<a name="l02309"></a>02309 
+<a name="l02310"></a>02310   cknull_nomsg(fsel=sinfo_imagelist_select_range(flag_data,lambda,
+<a name="l02311"></a>02311                                                       mrange,tol));
+<a name="l02312"></a>02312 
+<a name="l02313"></a>02313   <span class="comment">//check_nomsg(cpl_imagelist_save(osel,"out_osel.fits",</span>
+<a name="l02314"></a>02314   <span class="comment">//                               CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT));</span>
+<a name="l02315"></a>02315   <span class="comment">//check_nomsg(cpl_imagelist_save(fsel,"out_fsel.fits",</span>
+<a name="l02316"></a>02316   <span class="comment">//                               CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT));</span>
+<a name="l02317"></a>02317 
+<a name="l02318"></a>02318   <span class="keywordflow">for</span>(j=0;j<ysz;j++) {
+<a name="l02319"></a>02319     <span class="keywordflow">for</span>(i=0;i<xsz;i++) {
+<a name="l02320"></a>02320       <span class="comment">// consider only planes in the proper wavelegth ranges</span>
+<a name="l02321"></a>02321       cknull_nomsg(ospec=sinfo_slice_z(osel,i,j));
+<a name="l02322"></a>02322       cknull_nomsg(fspec=sinfo_slice_z(fsel,i,j));
+<a name="l02323"></a>02323       <span class="comment">// consider only finite pixels</span>
+<a name="l02324"></a>02324       check_nomsg(gpix_i=sinfo_table_extract_finite(ospec,fspec,&gpix,&gspec));
+<a name="l02325"></a>02325       <span class="comment">//sinfo_msg("gpix_i=%d",gpix_i);</span>
+<a name="l02326"></a>02326       <span class="keywordflow">if</span>(gpix_i > 0) {
+<a name="l02327"></a>02327         <span class="comment">// build two arrays of proper size</span>
+<a name="l02328"></a>02328         all_pix=(double)gpix_i;
+<a name="l02329"></a>02329     <span class="comment">/*</span>
+<a name="l02330"></a>02330 <span class="comment">        sinfo_msg("flagspec: min=%f max=%f",</span>
+<a name="l02331"></a>02331 <span class="comment">                  cpl_table_get_column_min(fspec,"VALUE"),</span>
+<a name="l02332"></a>02332 <span class="comment">                  cpl_table_get_column_max(fspec,"VALUE"));</span>
+<a name="l02333"></a>02333 <span class="comment">        sinfo_msg("good flagspec: min=%f max=%f",</span>
+<a name="l02334"></a>02334 <span class="comment">                  cpl_table_get_column_min(gspec,"VALUE"),</span>
+<a name="l02335"></a>02335 <span class="comment">                  cpl_table_get_column_max(gspec,"VALUE"));</span>
+<a name="l02336"></a>02336 <span class="comment">        sinfo_msg("nfspec=%d",cpl_table_get_nrow(fspec));</span>
+<a name="l02337"></a>02337 <span class="comment">        check_nomsg(cpl_table_save(fspec, NULL, NULL,</span>
+<a name="l02338"></a>02338 <span class="comment">                    "out_fspec.fits",CPL_IO_DEFAULT));</span>
+<a name="l02339"></a>02339 <span class="comment">        check_nomsg(cpl_table_save(gspec, NULL, NULL,</span>
+<a name="l02340"></a>02340 <span class="comment">                    "out_gspec.fits", CPL_IO_DEFAULT));</span>
+<a name="l02341"></a>02341 <span class="comment">    */</span>
+<a name="l02342"></a>02342         <span class="comment">//check_nomsg(flag_pix=cpl_table_and_selected_double(fspec,"VALUE",</span>
+<a name="l02343"></a>02343         <span class="comment">//                                              CPL_GREATER_THAN,0.5));</span>
+<a name="l02344"></a>02344         <span class="comment">//sinfo_msg("all_pix=%f flag_pix=%f",all_pix,flag_pix);</span>
+<a name="l02345"></a>02345 
+<a name="l02346"></a>02346         check_nomsg(flag_pix=cpl_table_and_selected_double(gspec,<span class="stringliteral">"VALUE"</span>,
+<a name="l02347"></a>02347                                                         CPL_GREATER_THAN,0.5));
+<a name="l02348"></a>02348         <span class="comment">//sinfo_msg("all_pix=%f flag_pix=%f",all_pix,flag_pix);</span>
+<a name="l02349"></a>02349         <span class="comment">// flag_pix = float(n_elements(where(fspec[gpix] > 0.5)));</span>
+<a name="l02350"></a>02350         <span class="comment">// compute the ratio between the two arrays</span>
+<a name="l02351"></a>02351         ratio=flag_pix/all_pix;
+<a name="l02352"></a>02352         <span class="comment">// considers only pixels with have at least half good pixels</span>
+<a name="l02353"></a>02353         <span class="keywordflow">if</span>(all_pix > cpl_table_get_nrow(mrange)/2) {
+<a name="l02354"></a>02354           pg_img[i+j*xsz]=1;
+<a name="l02355"></a>02355           pr_img[i+j*xsz]=ratio;
+<a name="l02356"></a>02356         }
+<a name="l02357"></a>02357         <span class="comment">//mean(ospec(gpix))</span>
+<a name="l02358"></a>02358         check_nomsg(pimage[i+j*xsz]=cpl_table_get_column_mean(gpix,<span class="stringliteral">"VALUE"</span>));
+<a name="l02359"></a>02359         <span class="comment">//sinfo_msg("ix=%d iy=%d r=%f",i,j,ratio);</span>
+<a name="l02360"></a>02360       }
+<a name="l02361"></a>02361       sinfo_free_table(&ospec);
+<a name="l02362"></a>02362       sinfo_free_table(&fspec);
+<a name="l02363"></a>02363       sinfo_free_table(&gpix);
+<a name="l02364"></a>02364       sinfo_free_table(&gspec);
+<a name="l02365"></a>02365 
+<a name="l02366"></a>02366     } <span class="comment">/* end for over i */</span>
+<a name="l02367"></a>02367   } <span class="comment">/* end for over j */</span>
+<a name="l02368"></a>02368   sinfo_free_imagelist(&osel);
+<a name="l02369"></a>02369   sinfo_free_imagelist(&fsel);
+<a name="l02370"></a>02370 
+<a name="l02371"></a>02371   <span class="comment">/*</span>
+<a name="l02372"></a>02372 <span class="comment">  cpl_image_save(*r_img,"out_r_img.fits",CPL_BPP_IEEE_FLOAT,</span>
+<a name="l02373"></a>02373 <span class="comment">                 NULL,CPL_IO_DEFAULT);</span>
+<a name="l02374"></a>02374 <span class="comment">  cpl_image_save(*g_img,"out_g_img.fits",CPL_BPP_IEEE_FLOAT,</span>
+<a name="l02375"></a>02375 <span class="comment">                 NULL,CPL_IO_DEFAULT);</span>
+<a name="l02376"></a>02376 <span class="comment">  cpl_image_save(*image,"out_image.fits",CPL_BPP_IEEE_FLOAT,</span>
+<a name="l02377"></a>02377 <span class="comment">                 NULL,CPL_IO_DEFAULT);</span>
+<a name="l02378"></a>02378 <span class="comment">  */</span>
+<a name="l02379"></a>02379   <span class="comment">// get total(g_arr)</span>
+<a name="l02380"></a>02380   check_nomsg(tot=cpl_image_get_flux(*g_img));
+<a name="l02381"></a>02381   <span class="keywordflow">if</span>(tot < 1) {
+<a name="l02382"></a>02382     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no good spaxel"</span>);
+<a name="l02383"></a>02383     <span class="keywordflow">goto</span> cleanup;
+<a name="l02384"></a>02384   }
+<a name="l02385"></a>02385 
+<a name="l02386"></a>02386   <span class="keywordflow">return</span> 0;
+<a name="l02387"></a>02387 
+<a name="l02388"></a>02388 
+<a name="l02389"></a>02389  cleanup:
+<a name="l02390"></a>02390   sinfo_free_propertylist(&plist);
+<a name="l02391"></a>02391   sinfo_free_imagelist(&obj_cub);
+<a name="l02392"></a>02392   sinfo_free_imagelist(&osel);
+<a name="l02393"></a>02393   sinfo_free_imagelist(&fsel);
+<a name="l02394"></a>02394    sinfo_free_table(&ospec);
+<a name="l02395"></a>02395   sinfo_free_table(&fspec);
+<a name="l02396"></a>02396   sinfo_free_table(&gpix);
+<a name="l02397"></a>02397   sinfo_free_table(&gspec);
+<a name="l02398"></a>02398 
+<a name="l02399"></a>02399   <span class="keywordflow">return</span> -1;
+<a name="l02400"></a>02400 
+<a name="l02401"></a>02401 
+<a name="l02402"></a>02402 }
+<a name="l02403"></a>02403 
+<a name="l02412"></a>02412 <span class="keywordtype">int</span>
+<a name="l02413"></a>02413 sinfo_choose_good_sky_pixels(cpl_frame* obj_frm,
+<a name="l02414"></a>02414                              cpl_image* r_img,
+<a name="l02415"></a>02415                              cpl_image* g_img,
+<a name="l02416"></a>02416                              <span class="keyword">const</span> <span class="keywordtype">double</span> min_frac,
+<a name="l02417"></a>02417                              cpl_image** mask)
+<a name="l02418"></a>02418 {
+<a name="l02419"></a>02419 
+<a name="l02420"></a>02420   <span class="keywordtype">int</span> xsz=0;
+<a name="l02421"></a>02421   <span class="keywordtype">int</span> ysz=0;
+<a name="l02422"></a>02422   <span class="keywordtype">int</span> zsz=0;
+<a name="l02423"></a>02423   <span class="keywordtype">int</span> r2i=0;
+<a name="l02424"></a>02424   <span class="keywordtype">int</span> status=0;
+<a name="l02425"></a>02425   <span class="keywordtype">double</span> tot=0;
+<a name="l02426"></a>02426   <span class="keywordtype">double</span> thres=SKY_THRES;
+<a name="l02427"></a>02427   <span class="keywordtype">double</span> cum_x_max=0;
+<a name="l02428"></a>02428 
+<a name="l02429"></a>02429   cpl_image* r2img=NULL;
+<a name="l02430"></a>02430   cpl_propertylist* plist=NULL;
+<a name="l02431"></a>02431   cpl_table* cum=NULL;
+<a name="l02432"></a>02432   cpl_table* hcum=NULL;
+<a name="l02433"></a>02433   cpl_table* thres_tbl=NULL;
+<a name="l02434"></a>02434 
+<a name="l02435"></a>02435   cknull_nomsg(plist=cpl_propertylist_load(cpl_frame_get_filename(obj_frm),0));
+<a name="l02436"></a>02436   check_nomsg(xsz=sinfo_pfits_get_naxis1(plist));
+<a name="l02437"></a>02437   check_nomsg(ysz=sinfo_pfits_get_naxis2(plist));
+<a name="l02438"></a>02438   check_nomsg(zsz=sinfo_pfits_get_naxis3(plist));
+<a name="l02439"></a>02439   sinfo_free_propertylist(&plist);
+<a name="l02440"></a>02440 
+<a name="l02441"></a>02441   <span class="comment">// choose pixels which seem to be sky (ie 95% of spectral pixels are flagged)</span>
+<a name="l02442"></a>02442   check_nomsg(*mask=cpl_image_new(xsz,ysz,CPL_TYPE_DOUBLE));
+<a name="l02443"></a>02443   <span class="comment">//r2 = where(r_img >= thres,r2i);</span>
+<a name="l02444"></a>02444   <span class="comment">// count good pixels: set to 0 what < thres and to 1 what > thres</span>
+<a name="l02445"></a>02445   check_nomsg(r2img=cpl_image_duplicate(r_img));
+<a name="l02446"></a>02446   check_nomsg(cpl_image_threshold(r2img,thres,thres,0,1));
+<a name="l02447"></a>02447   check_nomsg(r2i=cpl_image_get_flux(r2img));
+<a name="l02448"></a>02448 
+<a name="l02449"></a>02449   <span class="keywordflow">if</span>(r2i>0) {
+<a name="l02450"></a>02450     sinfo_free_image(&(*mask));
+<a name="l02451"></a>02451     check_nomsg(*mask=cpl_image_duplicate(r2img));
+<a name="l02452"></a>02452   }
+<a name="l02453"></a>02453   sinfo_free_image(&r2img);
+<a name="l02454"></a>02454   check_nomsg(r2img=cpl_image_duplicate(r_img));
+<a name="l02455"></a>02455   check_nomsg(cpl_image_threshold(r2img,thres,SINFO_DBL_MAX,0,SINFO_DBL_MAX));
+<a name="l02456"></a>02456   sinfo_free_image(&r2img);
+<a name="l02457"></a>02457 
+<a name="l02458"></a>02458   check_nomsg(tot=cpl_image_get_flux(g_img));
+<a name="l02459"></a>02459 
+<a name="l02460"></a>02460 
+<a name="l02461"></a>02461    sinfo_msg(<span class="stringliteral">"%2.2d spaxels (%4.1f %% of good pixels) are designated as sky"</span>,
+<a name="l02462"></a>02462              r2i,100.*r2i/tot);
+<a name="l02463"></a>02463 
+<a name="l02464"></a>02464    <span class="comment">//threshold ratio for fraction 'minfrac' of spatial pixels to be 'sky'</span>
+<a name="l02465"></a>02465    <span class="keywordflow">if</span> (1.*r2i/tot < min_frac) {
+<a name="l02466"></a>02466      sinfo_msg(<span class="stringliteral">"this is too small - will increase it to %4.1f %%"</span>,
+<a name="l02467"></a>02467            100.*min_frac);
+<a name="l02468"></a>02468      check_nomsg(cum=cpl_table_new(xsz*ysz));
+<a name="l02469"></a>02469      check_nomsg(cpl_table_new_column(cum,<span class="stringliteral">"X"</span>,CPL_TYPE_DOUBLE));
+<a name="l02470"></a>02470      sinfo_table_column_dindgen(&cum,<span class="stringliteral">"X"</span>);
+<a name="l02471"></a>02471      check_nomsg(cpl_table_add_scalar(cum,<span class="stringliteral">"X"</span>,1.));
+<a name="l02472"></a>02472 
+<a name="l02473"></a>02473      <span class="comment">//hcum = r_img(sort(r_img));</span>
+<a name="l02474"></a>02474      hcum = sinfo_image2table(r_img);
+<a name="l02475"></a>02475      check_nomsg(sinfo_sort_table_1(hcum,<span class="stringliteral">"VALUE"</span>,FALSE));
+<a name="l02476"></a>02476 
+<a name="l02477"></a>02477      <span class="comment">//thresh = hcum[where(xcum/max(xcum) >= 1.-min_frac)];</span>
+<a name="l02478"></a>02478      check_nomsg(cpl_table_duplicate_column(cum,<span class="stringliteral">"H"</span>,hcum,<span class="stringliteral">"VALUE"</span>));
+<a name="l02479"></a>02479      check_nomsg(cum_x_max=cpl_table_get_column_max(cum,<span class="stringliteral">"X"</span>));
+<a name="l02480"></a>02480      check_nomsg(cpl_table_duplicate_column(cum,<span class="stringliteral">"R"</span>,cum,<span class="stringliteral">"X"</span>));
+<a name="l02481"></a>02481      check_nomsg(cpl_table_divide_scalar(cum,<span class="stringliteral">"R"</span>,cum_x_max));
+<a name="l02482"></a>02482      check_nomsg(cpl_table_and_selected_double(cum,<span class="stringliteral">"R"</span>,
+<a name="l02483"></a>02483                                               CPL_NOT_LESS_THAN,
+<a name="l02484"></a>02484                                               (1.-min_frac)));
+<a name="l02485"></a>02485      check_nomsg(thres_tbl=cpl_table_extract_selected(cum));
+<a name="l02486"></a>02486 
+<a name="l02487"></a>02487      check_nomsg(thres = cpl_table_get(thres_tbl,<span class="stringliteral">"R"</span>,0,&status));
+<a name="l02488"></a>02488      <span class="comment">//*mask[where(r_img >= thresh)] = 1;</span>
+<a name="l02489"></a>02489      sinfo_free_image(&(*mask));
+<a name="l02490"></a>02490 
+<a name="l02491"></a>02491 
+<a name="l02492"></a>02492      check_nomsg(*mask=cpl_image_duplicate(r_img));
+<a name="l02493"></a>02493      check_nomsg(cpl_image_threshold(*mask,thres,thres,0,1));
+<a name="l02494"></a>02494   }
+<a name="l02495"></a>02495   sinfo_free_table(&cum);
+<a name="l02496"></a>02496   sinfo_free_table(&hcum);
+<a name="l02497"></a>02497   sinfo_free_table(&thres_tbl);
+<a name="l02498"></a>02498 
+<a name="l02499"></a>02499   <span class="keywordflow">return</span> 0;
+<a name="l02500"></a>02500  cleanup:
+<a name="l02501"></a>02501 
+<a name="l02502"></a>02502   sinfo_free_propertylist(&plist);
+<a name="l02503"></a>02503   sinfo_free_image(&r2img);
+<a name="l02504"></a>02504   sinfo_free_table(&cum);
+<a name="l02505"></a>02505   sinfo_free_table(&hcum);
+<a name="l02506"></a>02506   sinfo_free_table(&thres_tbl);
+<a name="l02507"></a>02507 
+<a name="l02508"></a>02508   <span class="keywordflow">return</span> -1;
+<a name="l02509"></a>02509 
+<a name="l02510"></a>02510 }
+<a name="l02511"></a>02511 
+<a name="l02512"></a>02512 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l02521"></a>02521 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l02522"></a>02522 
+<a name="l02523"></a>02523 <span class="keyword">static</span> <span class="keywordtype">double</span>
+<a name="l02524"></a>02524 sinfo_fit_bkg(<span class="keywordtype">double</span> p[])
+<a name="l02525"></a>02525 
+<a name="l02526"></a>02526 {
+<a name="l02527"></a>02527  <span class="keywordtype">double</span>* px=NULL;
+<a name="l02528"></a>02528   <span class="keywordtype">double</span>* py=NULL;
+<a name="l02529"></a>02529   <span class="keywordtype">double</span>* pv=NULL;
+<a name="l02530"></a>02530   cpl_vector* vtmp=NULL;
+<a name="l02531"></a>02531   <span class="keywordtype">double</span> max=0;
+<a name="l02532"></a>02532   <span class="keywordtype">int</span> i=0;
+<a name="l02533"></a>02533   <span class="keywordtype">int</span> np=0;
+<a name="l02534"></a>02534 
+<a name="l02535"></a>02535   <span class="keywordtype">double</span> chi2=0;
+<a name="l02536"></a>02536 
+<a name="l02537"></a>02537   check_nomsg(px= cpl_vector_get_data(sa_vx));
+<a name="l02538"></a>02538   check_nomsg(py= cpl_vector_get_data(sa_vy));
+<a name="l02539"></a>02539   check_nomsg(np= cpl_vector_get_size(sa_vx));
+<a name="l02540"></a>02540   check_nomsg(vtmp=cpl_vector_duplicate(sa_vy));
+<a name="l02541"></a>02541   check_nomsg(pv=cpl_vector_get_data(vtmp));
+<a name="l02542"></a>02542 
+<a name="l02543"></a>02543   <span class="keywordflow">for</span>(i=0;i<np;i++) {
+<a name="l02544"></a>02544     pv[i]=sinfo_fac(px[i],p[2]);
+<a name="l02545"></a>02545     <span class="comment">//sinfo_msg("x=%g p=%g",px[i],pv[i]);</span>
+<a name="l02546"></a>02546   }
+<a name="l02547"></a>02547   check_nomsg(max=cpl_vector_get_max(vtmp));
+<a name="l02548"></a>02548   <span class="keywordflow">if</span>(max> 0) {
+<a name="l02549"></a>02549     check_nomsg(cpl_vector_divide_scalar(vtmp,max));
+<a name="l02550"></a>02550     check_nomsg(cpl_vector_multiply_scalar(vtmp,p[1]));
+<a name="l02551"></a>02551     check_nomsg(cpl_vector_add_scalar(vtmp,p[0]));
+<a name="l02552"></a>02552   }
+<a name="l02553"></a>02553 
+<a name="l02554"></a>02554 
+<a name="l02555"></a>02555   <span class="keywordflow">for</span>(i=0;i<np;i++) {
+<a name="l02556"></a>02556     chi2+=(py[i]-pv[i])*(py[i]-pv[i]);
+<a name="l02557"></a>02557   }
+<a name="l02558"></a>02558   sinfo_free_my_vector(&vtmp);
+<a name="l02559"></a>02559   <span class="keywordflow">return</span> chi2;
+<a name="l02560"></a>02560  cleanup:
+<a name="l02561"></a>02561   sinfo_free_my_vector(&vtmp);
+<a name="l02562"></a>02562   <span class="keywordflow">return</span> -1;
+<a name="l02563"></a>02563 
+<a name="l02564"></a>02564 }
+<a name="l02565"></a>02565 
+<a name="l02566"></a>02566 
+<a name="l02567"></a>02567 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l02579"></a>02579 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l02580"></a>02580 
+<a name="l02581"></a>02581 <span class="keywordtype">int</span>
+<a name="l02582"></a>02582 sinfo_thermal_background2(cpl_table* int_sky,
+<a name="l02583"></a>02583                          cpl_table* lambda,
+<a name="l02584"></a>02584                          cpl_table* lrange,
+<a name="l02585"></a>02585                          cpl_table** bkg)
+<a name="l02586"></a>02586 {
+<a name="l02587"></a>02587 
+<a name="l02588"></a>02588   <span class="keywordtype">int</span> n2=0;
+<a name="l02589"></a>02589   <span class="keywordtype">int</span> i=0;
+<a name="l02590"></a>02590   <span class="keywordtype">int</span> j=0;
+<a name="l02591"></a>02591   <span class="keywordtype">int</span> nrow=0;
+<a name="l02592"></a>02592 
+<a name="l02593"></a>02593   cpl_table* tmp1=NULL;
+<a name="l02594"></a>02594   cpl_table* tmp2=NULL;
+<a name="l02595"></a>02595 
+<a name="l02596"></a>02596   <span class="keywordtype">double</span> max=0;
+<a name="l02597"></a>02597   <span class="keywordtype">double</span> wmin=0;
+<a name="l02598"></a>02598   <span class="keywordtype">double</span> wmax=0;
+<a name="l02599"></a>02599   <span class="keywordtype">double</span> p0[3];
+<a name="l02600"></a>02600   <span class="keyword">const</span> <span class="keywordtype">int</span> MP=4;
+<a name="l02601"></a>02601   <span class="keyword">const</span> <span class="keywordtype">int</span> NP=3;
+<a name="l02602"></a>02602   <span class="keywordtype">double</span> y[MP];
+<a name="l02603"></a>02603   <span class="keywordtype">double</span>** ap=NULL;
+<a name="l02604"></a>02604   <span class="keywordtype">int</span> nfunc=0;
+<a name="l02605"></a>02605   <span class="keywordtype">int</span> status=0;
+<a name="l02606"></a>02606   <span class="keywordtype">int</span> row=0;
+<a name="l02607"></a>02607   <span class="keywordtype">double</span> bkg_min=0;
+<a name="l02608"></a>02608   <span class="keywordtype">double</span> bkg_max=0;
+<a name="l02609"></a>02609   <span class="keywordtype">double</span> p0_min=0;
+<a name="l02610"></a>02610   <span class="keywordtype">double</span> p0_max=0;
+<a name="l02611"></a>02611   <span class="keywordtype">double</span> p1_min=0;
+<a name="l02612"></a>02612   <span class="keywordtype">double</span> p1_max=0;
+<a name="l02613"></a>02613   <span class="keywordtype">double</span> p2_min=0;
+<a name="l02614"></a>02614   <span class="keywordtype">double</span> p2_max=0;
+<a name="l02615"></a>02615   <span class="keywordtype">double</span>* pw=NULL;
+<a name="l02616"></a>02616   <span class="keywordtype">double</span>* pf=NULL;
+<a name="l02617"></a>02617 
+<a name="l02618"></a>02618   ap=(<span class="keywordtype">double</span>**) cpl_calloc(MP,<span class="keyword">sizeof</span>(<span class="keywordtype">double</span>*));
+<a name="l02619"></a>02619 
+<a name="l02620"></a>02620   <span class="keywordflow">for</span>(i=0;i<MP;i++) {
+<a name="l02621"></a>02621     ap[i]=cpl_calloc(NP,<span class="keyword">sizeof</span>(<span class="keywordtype">double</span>));
+<a name="l02622"></a>02622   }
+<a name="l02623"></a>02623 
+<a name="l02624"></a>02624   cknull(int_sky,<span class="stringliteral">"Null input table sky"</span>);
+<a name="l02625"></a>02625   cknull(lambda,<span class="stringliteral">"Null input table lambda"</span>);
+<a name="l02626"></a>02626   cknull(lrange,<span class="stringliteral">"Null input table lrange"</span>);
+<a name="l02627"></a>02627 
+<a name="l02628"></a>02628 
+<a name="l02629"></a>02629   <span class="comment">//TO BE FIXED: Why lrange to gat wave min and max: int_sky is sufficient</span>
+<a name="l02630"></a>02630   check_nomsg(wmin=cpl_table_get_column_min(lrange,<span class="stringliteral">"WAVE"</span>));
+<a name="l02631"></a>02631   check_nomsg(wmax=cpl_table_get_column_max(lrange,<span class="stringliteral">"WAVE"</span>));
+<a name="l02632"></a>02632   check_nomsg(cpl_table_and_selected_double(int_sky,<span class="stringliteral">"WAVE"</span>,
+<a name="l02633"></a>02633               CPL_NOT_LESS_THAN,wmin));
+<a name="l02634"></a>02634   check_nomsg(cpl_table_and_selected_double(int_sky,<span class="stringliteral">"WAVE"</span>,
+<a name="l02635"></a>02635               CPL_NOT_GREATER_THAN,wmax));
+<a name="l02636"></a>02636   check_nomsg(tmp1=cpl_table_extract_selected(int_sky));
+<a name="l02637"></a>02637 
+<a name="l02638"></a>02638   check_nomsg(row=sinfo_table_get_index_of_val(tmp1,<span class="stringliteral">"WAVE"</span>,
+<a name="l02639"></a>02639                                                wmax,CPL_TYPE_DOUBLE));
+<a name="l02640"></a>02640   check_nomsg(max=cpl_table_get_double(tmp1,<span class="stringliteral">"INT"</span>,row,&status));
+<a name="l02641"></a>02641   check_nomsg(sinfo_table_flag_nan(&tmp1,<span class="stringliteral">"INT"</span>));
+<a name="l02642"></a>02642   check_nomsg(cpl_table_erase_invalid(tmp1));
+<a name="l02643"></a>02643   check_nomsg(cpl_table_and_selected_double(tmp1,<span class="stringliteral">"INT"</span>,CPL_NOT_EQUAL_TO,0));
+<a name="l02644"></a>02644   check_nomsg(tmp2=cpl_table_extract_selected(tmp1));
+<a name="l02645"></a>02645 
+<a name="l02646"></a>02646   sinfo_free_table(&tmp1);
+<a name="l02647"></a>02647   check_nomsg(n2=cpl_table_get_nrow(tmp2));
+<a name="l02648"></a>02648   check_nomsg(sa_vx=cpl_vector_wrap(n2,
+<a name="l02649"></a>02649               cpl_table_get_data_double(tmp2,<span class="stringliteral">"WAVE"</span>)));
+<a name="l02650"></a>02650   check_nomsg(sa_vy=cpl_vector_wrap(n2,
+<a name="l02651"></a>02651               cpl_table_get_data_double(tmp2,<span class="stringliteral">"INT"</span>)));
+<a name="l02652"></a>02652 
+<a name="l02653"></a>02653 
+<a name="l02654"></a>02654   <span class="keywordflow">for</span>(i=0;i<MP;i++) {
+<a name="l02655"></a>02655     <span class="keywordflow">for</span>(j=0;j<NP;j++) {
+<a name="l02656"></a>02656       ap[i][j]=0;
+<a name="l02657"></a>02657     }
+<a name="l02658"></a>02658   }
+<a name="l02659"></a>02659 
+<a name="l02660"></a>02660   check_nomsg(bkg_min=cpl_table_get_column_min(tmp2,<span class="stringliteral">"INT"</span>));
+<a name="l02661"></a>02661   check_nomsg(bkg_max=cpl_table_get_double(tmp2,<span class="stringliteral">"INT"</span>,row,&status));
+<a name="l02662"></a>02662 
+<a name="l02663"></a>02663 
+<a name="l02664"></a>02664   <span class="comment">//Init amoeba fit parameters</span>
+<a name="l02665"></a>02665   p0_min=bkg_min*0.9;
+<a name="l02666"></a>02666   p0_max=bkg_min*1.1;
+<a name="l02667"></a>02667   p1_min=bkg_max*0.9;
+<a name="l02668"></a>02668   p1_max=bkg_max*1.1;
+<a name="l02669"></a>02669   p1_min=200;
+<a name="l02670"></a>02670   p2_max=300;
+<a name="l02671"></a>02671 
+<a name="l02672"></a>02672   ap[0][0]=p0_min; ap[0][1]=p1_min; ap[0][2]=p2_min;
+<a name="l02673"></a>02673   ap[1][0]=p0_max; ap[1][1]=p1_min; ap[1][2]=p2_min;
+<a name="l02674"></a>02674   ap[2][0]=p0_min; ap[2][1]=p1_max; ap[2][2]=p2_min;
+<a name="l02675"></a>02675   ap[3][0]=p0_min; ap[3][1]=p1_min; ap[3][2]=p2_max;
+<a name="l02676"></a>02676 
+<a name="l02677"></a>02677   sinfo_msg(<span class="stringliteral">"Before amoeba fit"</span>);
+<a name="l02678"></a>02678   <span class="keywordflow">for</span>(i=0;i<MP;i++) {
+<a name="l02679"></a>02679     <span class="keywordflow">for</span>(j=0;j<NP;j++) {
+<a name="l02680"></a>02680       sinfo_msg(<span class="stringliteral">"ap[%d][%d]=%g"</span>,i,j,ap[i][j]);
+<a name="l02681"></a>02681     }
+<a name="l02682"></a>02682   }
+<a name="l02683"></a>02683 
+<a name="l02684"></a>02684 
+<a name="l02685"></a>02685 
+<a name="l02686"></a>02686 
+<a name="l02687"></a>02687   <span class="keywordflow">for</span>(i=0;i<MP;i++) {
+<a name="l02688"></a>02688     p0[0]=ap[i][0];
+<a name="l02689"></a>02689     p0[1]=ap[i][1];
+<a name="l02690"></a>02690     p0[2]=ap[i][2];
+<a name="l02691"></a>02691     y[i]=sinfo_fit_bkg(p0);
+<a name="l02692"></a>02692   }
+<a name="l02693"></a>02693 
+<a name="l02694"></a>02694   sinfo_msg(<span class="stringliteral">"p0=%g %g %g"</span>,p0[0],p0[1],p0[2]);
+<a name="l02695"></a>02695   <span class="keywordflow">for</span>(i=0;i<N_ITER_FIT_AMOEBA;i++) {
+<a name="l02696"></a>02696     check_nomsg(sinfo_fit_amoeba(ap,y,NP,AMOEBA_FTOL,sinfo_fit_bkg,&nfunc));
+<a name="l02697"></a>02697     sinfo_msg(<span class="stringliteral">"After amoeba fit"</span>);
+<a name="l02698"></a>02698     sinfo_msg(<span class="stringliteral">"iter=%d ap=%g %g %g"</span>,i,ap[0][0],ap[0][1],ap[0][2]);
+<a name="l02699"></a>02699   }
+<a name="l02700"></a>02700   sinfo_unwrap_vector(&sa_vx);
+<a name="l02701"></a>02701   sinfo_unwrap_vector(&sa_vy);
+<a name="l02702"></a>02702   sinfo_free_table(&tmp2);
+<a name="l02703"></a>02703 
+<a name="l02704"></a>02704 
+<a name="l02705"></a>02705   sinfo_msg(<span class="stringliteral">"After amoeba fit"</span>);
+<a name="l02706"></a>02706   <span class="keywordflow">for</span>(i=0;i<MP;i++) {
+<a name="l02707"></a>02707     <span class="keywordflow">for</span>(j=0;j<NP;j++) {
+<a name="l02708"></a>02708       sinfo_msg(<span class="stringliteral">"ap[%d][%d]=%g"</span>,i,j,ap[i][j]);
+<a name="l02709"></a>02709     }
+<a name="l02710"></a>02710     sinfo_msg(<span class="stringliteral">"y[%d]=%g"</span>,i,y[i]);
+<a name="l02711"></a>02711   }
+<a name="l02712"></a>02712 
+<a name="l02713"></a>02713 
+<a name="l02714"></a>02714 
+<a name="l02715"></a>02715   check_nomsg(nrow=cpl_table_get_nrow(lambda));
+<a name="l02716"></a>02716   check_nomsg(*bkg=cpl_table_new(nrow));
+<a name="l02717"></a>02717   check_nomsg(cpl_table_duplicate_column(*bkg,<span class="stringliteral">"WAVE"</span>,lambda,<span class="stringliteral">"WAVE"</span>));
+<a name="l02718"></a>02718   check_nomsg(cpl_table_new_column(*bkg,<span class="stringliteral">"INT2"</span>,CPL_TYPE_DOUBLE));
+<a name="l02719"></a>02719   cpl_table_fill_column_window(*bkg,<span class="stringliteral">"INT2"</span>,0,nrow,0.);
+<a name="l02720"></a>02720   check_nomsg(pw=cpl_table_get_data_double(*bkg,<span class="stringliteral">"WAVE"</span>));
+<a name="l02721"></a>02721   check_nomsg(pf=cpl_table_get_data_double(*bkg,<span class="stringliteral">"INT2"</span>));
+<a name="l02722"></a>02722 
+<a name="l02723"></a>02723   <span class="keywordflow">for</span>(i=0;i<nrow;i++) {
+<a name="l02724"></a>02724     pf[i]=sinfo_fac(pw[i],ap[0][2]);
+<a name="l02725"></a>02725   }
+<a name="l02726"></a>02726   check_nomsg(max=cpl_table_get_column_max(*bkg,<span class="stringliteral">"INT2"</span>));
+<a name="l02727"></a>02727 
+<a name="l02728"></a>02728   <span class="keywordflow">if</span>(max != 0) {
+<a name="l02729"></a>02729      check_nomsg(cpl_table_divide_scalar(*bkg,<span class="stringliteral">"INT2"</span>,max));
+<a name="l02730"></a>02730   }
+<a name="l02731"></a>02731   check_nomsg(cpl_table_multiply_scalar(*bkg,<span class="stringliteral">"INT2"</span>,ap[0][1]));
+<a name="l02732"></a>02732   check_nomsg(cpl_table_add_scalar(*bkg,<span class="stringliteral">"INT2"</span>,ap[0][0]));
+<a name="l02733"></a>02733   <span class="comment">//check_nomsg(cpl_table_save(*bkg,NULL,NULL,</span>
+<a name="l02734"></a>02734   <span class="comment">//"out_amoeba5.fits",CPL_IO_DEFAULT ));</span>
+<a name="l02735"></a>02735   sinfo_new_destroy_2Ddoublearray(&ap,MP);
+<a name="l02736"></a>02736 
+<a name="l02737"></a>02737 
+<a name="l02738"></a>02738   <span class="keywordflow">return</span> 0;
+<a name="l02739"></a>02739 
+<a name="l02740"></a>02740  cleanup:
+<a name="l02741"></a>02741   sinfo_new_destroy_2Ddoublearray(&ap,MP);
+<a name="l02742"></a>02742   sinfo_free_table(&tmp1);
+<a name="l02743"></a>02743   sinfo_free_table(&tmp2);
+<a name="l02744"></a>02744   sinfo_unwrap_vector(&sa_vx);
+<a name="l02745"></a>02745   sinfo_unwrap_vector(&sa_vy);
+<a name="l02746"></a>02746   <span class="keywordflow">return</span> -1;
+<a name="l02747"></a>02747 
+<a name="l02748"></a>02748 }
+<a name="l02749"></a>02749 
+<a name="l02750"></a>02750 
+<a name="l02751"></a>02751 
+<a name="l02752"></a>02752 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l02764"></a>02764 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l02765"></a>02765 
+<a name="l02766"></a>02766 <span class="keywordtype">int</span>
+<a name="l02767"></a>02767 sinfo_thermal_background(cpl_table* int_sky,
+<a name="l02768"></a>02768                          cpl_table* lambda,
+<a name="l02769"></a>02769                          cpl_table* lrange,
+<a name="l02770"></a>02770                          <span class="keyword">const</span> <span class="keywordtype">double</span> temp,
+<a name="l02771"></a>02771                          <span class="keyword">const</span> <span class="keywordtype">int</span> niter,
+<a name="l02772"></a>02772                          <span class="keyword">const</span> <span class="keywordtype">int</span> filter_width,
+<a name="l02773"></a>02773                          <span class="keyword">const</span> <span class="keywordtype">double</span> tol,
+<a name="l02774"></a>02774                          cpl_table** bkg,
+<a name="l02775"></a>02775                          <span class="keywordtype">int</span>* success_fit)
+<a name="l02776"></a>02776 {
+<a name="l02777"></a>02777 
+<a name="l02778"></a>02778   <span class="keywordtype">int</span> npix=0;
+<a name="l02779"></a>02779   <span class="keywordtype">int</span> i=0;
+<a name="l02780"></a>02780   <span class="keywordtype">int</span> row=0;
+<a name="l02781"></a>02781   <span class="keyword">const</span> <span class="keywordtype">int</span> ndim=3;<span class="comment">/* There are 3 parameters */</span>
+<a name="l02782"></a>02782     <span class="keywordtype">int</span> ia[ndim];
+<a name="l02783"></a>02783 
+<a name="l02784"></a>02784   <span class="keywordtype">int</span> NPOINTS=0;
+<a name="l02785"></a>02785 
+<a name="l02786"></a>02786 
+<a name="l02787"></a>02787   <span class="keywordtype">double</span> temp1=0;
+<a name="l02788"></a>02788   <span class="keywordtype">double</span> temp2=0;
+<a name="l02789"></a>02789 
+<a name="l02790"></a>02790   <span class="comment">//double r0=80.306773;</span>
+<a name="l02791"></a>02791   <span class="comment">//double r1=450.50027;</span>
+<a name="l02792"></a>02792   <span class="comment">//double r2=252.17949;</span>
+<a name="l02793"></a>02793   <span class="keywordtype">double</span> max_tmp2=0;
+<a name="l02794"></a>02794   <span class="keywordtype">double</span>* ptmp1=NULL;
+<a name="l02795"></a>02795   <span class="keywordtype">double</span> thermal=0;
+<a name="l02796"></a>02796   <span class="keywordtype">double</span>* pw=NULL;
+<a name="l02797"></a>02797   <span class="keywordtype">double</span> p0[3];
+<a name="l02798"></a>02798   <span class="keywordtype">double</span> wmin=0;
+<a name="l02799"></a>02799   <span class="keywordtype">double</span> wmax=0;
+<a name="l02800"></a>02800   <span class="keywordtype">double</span> ga0=0;
+<a name="l02801"></a>02801   <span class="keywordtype">double</span> ga1=0;
+<a name="l02802"></a>02802   <span class="comment">//double ga1=0;</span>
+<a name="l02803"></a>02803   <span class="keywordtype">double</span> ga2=0;
+<a name="l02804"></a>02804   <span class="keywordtype">double</span> mse=0;
+<a name="l02805"></a>02805   <span class="keywordtype">double</span> chired=0;
+<a name="l02806"></a>02806 
+<a name="l02807"></a>02807 
+<a name="l02808"></a>02808   cpl_vector *a = cpl_vector_new(ndim);
+<a name="l02809"></a>02809   cpl_table* xlr=NULL;
+<a name="l02810"></a>02810   cpl_table* ylr=NULL;
+<a name="l02811"></a>02811   cpl_table* wlr=NULL;
+<a name="l02812"></a>02812   cpl_table* tmp=NULL;
+<a name="l02813"></a>02813   cpl_table* temp2_tbl=NULL;
+<a name="l02814"></a>02814 
+<a name="l02815"></a>02815   cpl_vector* y=NULL;
+<a name="l02816"></a>02816   cpl_vector* fy=NULL;
+<a name="l02817"></a>02817 
+<a name="l02818"></a>02818   cpl_vector* sy=NULL;
+<a name="l02819"></a>02819 
+<a name="l02820"></a>02820   cpl_matrix* x_matrix=NULL;
+<a name="l02821"></a>02821   <span class="keywordtype">double</span> bkg_min=0;
+<a name="l02822"></a>02822   <span class="keywordtype">double</span> bkg_max=0;
+<a name="l02823"></a>02823   <span class="keywordtype">int</span> status=0;
+<a name="l02824"></a>02824   <span class="keywordtype">double</span> avg=0;
+<a name="l02825"></a>02825   <span class="keywordtype">double</span> sdv=0;
+<a name="l02826"></a>02826   <span class="keywordtype">double</span> med=0;
+<a name="l02827"></a>02827   <span class="keywordtype">double</span>* pif=NULL;
+<a name="l02828"></a>02828   <span class="keywordtype">double</span>* pwf=NULL;
+<a name="l02829"></a>02829   <span class="keywordtype">double</span>* pws=NULL;
+<a name="l02830"></a>02830   <span class="keywordtype">int</span> k=0;
+<a name="l02831"></a>02831   <span class="keywordtype">int</span> nrow=0;
+<a name="l02832"></a>02832 
+<a name="l02833"></a>02833   <span class="comment">//check_nomsg(cpl_table_save(int_sky,NULL,NULL,</span>
+<a name="l02834"></a>02834   <span class="comment">//"out_pippo.fits", CPL_IO_DEFAULT));</span>
+<a name="l02835"></a>02835   check_nomsg(wmin=cpl_table_get_column_min(lrange,<span class="stringliteral">"WAVE"</span>));
+<a name="l02836"></a>02836   check_nomsg(wmax=cpl_table_get_column_max(lrange,<span class="stringliteral">"WAVE"</span>));
+<a name="l02837"></a>02837 
+<a name="l02838"></a>02838   bkg_min=sinfo_fac(wmin,temp);
+<a name="l02839"></a>02839   bkg_max=sinfo_fac(wmax,temp);
+<a name="l02840"></a>02840   <span class="comment">//sinfo_msg("bkg: min=%g max=%g",bkg_min,bkg_max);</span>
+<a name="l02841"></a>02841   <span class="comment">//sinfo_scale_fct=sinfo_scale_fct*bkg_max;</span>
+<a name="l02842"></a>02842   <span class="comment">//sinfo_scale_fct=sinfo_scale_fct;</span>
+<a name="l02843"></a>02843 
+<a name="l02844"></a>02844   check_nomsg(cpl_table_and_selected_double(lambda,<span class="stringliteral">"WAVE"</span>,
+<a name="l02845"></a>02845                                             CPL_NOT_LESS_THAN,wmin));
+<a name="l02846"></a>02846   check_nomsg(tmp=cpl_table_extract_selected(lambda));
+<a name="l02847"></a>02847 
+<a name="l02848"></a>02848   check_nomsg(cpl_table_and_selected_double(tmp,<span class="stringliteral">"WAVE"</span>,
+<a name="l02849"></a>02849                                             CPL_NOT_GREATER_THAN,wmax));
+<a name="l02850"></a>02850   check_nomsg(xlr=cpl_table_extract_selected(tmp));
+<a name="l02851"></a>02851   sinfo_free_table(&tmp);
+<a name="l02852"></a>02852 
+<a name="l02853"></a>02853 
+<a name="l02854"></a>02854   check_nomsg(cpl_table_and_selected_double(int_sky,<span class="stringliteral">"WAVE"</span>,
+<a name="l02855"></a>02855                                             CPL_NOT_LESS_THAN,wmin));
+<a name="l02856"></a>02856   check_nomsg(tmp=cpl_table_extract_selected(int_sky));
+<a name="l02857"></a>02857   check_nomsg(cpl_table_and_selected_double(tmp,<span class="stringliteral">"WAVE"</span>,
+<a name="l02858"></a>02858                                             CPL_NOT_GREATER_THAN,wmax));
+<a name="l02859"></a>02859 
+<a name="l02860"></a>02860 
+<a name="l02861"></a>02861   <span class="comment">//To be sure one has not strange cases</span>
+<a name="l02862"></a>02862   check_nomsg(cpl_table_and_selected_double(tmp,<span class="stringliteral">"INT"</span>,CPL_GREATER_THAN,-2));
+<a name="l02863"></a>02863   check_nomsg(ylr=cpl_table_extract_selected(tmp));
+<a name="l02864"></a>02864   <span class="comment">//check_nomsg(cpl_table_save(ylr,NULL,NULL,"out_ylr_0.fits",CPL_IO_DEFAULT));</span>
+<a name="l02865"></a>02865   sinfo_free_table(&tmp);
+<a name="l02866"></a>02866   check_nomsg(tmp=cpl_table_duplicate(ylr));
+<a name="l02867"></a>02867   sinfo_free_table(&ylr);
+<a name="l02868"></a>02868 
+<a name="l02869"></a>02869   check_nomsg(avg=cpl_table_get_column_mean(tmp,<span class="stringliteral">"INT"</span>));
+<a name="l02870"></a>02870   check_nomsg(sdv=cpl_table_get_column_stdev(tmp,<span class="stringliteral">"INT"</span>));
+<a name="l02871"></a>02871   check_nomsg(cpl_table_and_selected_double(tmp,<span class="stringliteral">"INT"</span>,
+<a name="l02872"></a>02872                         CPL_LESS_THAN,avg+10*sdv));
+<a name="l02873"></a>02873 
+<a name="l02874"></a>02874   check_nomsg(ylr=cpl_table_extract_selected(tmp));
+<a name="l02875"></a>02875   sinfo_free_table(&tmp);
+<a name="l02876"></a>02876 
+<a name="l02877"></a>02877 
+<a name="l02878"></a>02878   <span class="comment">/*</span>
+<a name="l02879"></a>02879 <span class="comment">  check_nomsg(xlr=sinfo_table_select_range(lambda,lrange,0.003));</span>
+<a name="l02880"></a>02880 <span class="comment">  check_nomsg(ylr=sinfo_table_select_range(int_sky,lrange,0.003));</span>
+<a name="l02881"></a>02881 <span class="comment">  */</span>
+<a name="l02882"></a>02882   check_nomsg(cpl_table_and_selected_double(ylr,<span class="stringliteral">"INT"</span>,CPL_NOT_EQUAL_TO,0));
+<a name="l02883"></a>02883 
+<a name="l02884"></a>02884   check_nomsg(wlr=cpl_table_extract_selected(ylr));
+<a name="l02885"></a>02885 
+<a name="l02886"></a>02886 
+<a name="l02887"></a>02887   check_nomsg(p0[0]=cpl_table_get_column_min(wlr,<span class="stringliteral">"INT"</span>));
+<a name="l02888"></a>02888   check_nomsg(row=sinfo_table_get_index_of_val(ylr,<span class="stringliteral">"WAVE"</span>,
+<a name="l02889"></a>02889                                                wmax,CPL_TYPE_DOUBLE));
+<a name="l02890"></a>02890   check_nomsg(p0[1]=cpl_table_get_double(ylr,<span class="stringliteral">"INT"</span>,row,&status));
+<a name="l02891"></a>02891   p0[2]=temp;
+<a name="l02892"></a>02892 
+<a name="l02893"></a>02893 
+<a name="l02894"></a>02894   ga0=p0[0];
+<a name="l02895"></a>02895   ga1=p0[1]/bkg_max;
+<a name="l02896"></a>02896   <span class="comment">//ga1=p0[1];</span>
+<a name="l02897"></a>02897   ga2=p0[2];
+<a name="l02898"></a>02898 
+<a name="l02899"></a>02899   <span class="comment">//sinfo_msg("p= %g %g %g",p0[0],p0[1],p0[2]);</span>
+<a name="l02900"></a>02900   check_nomsg(sinfo_table_flag_nan(&wlr,<span class="stringliteral">"INT"</span>));
+<a name="l02901"></a>02901   check_nomsg(cpl_table_erase_invalid(wlr));
+<a name="l02902"></a>02902   <span class="comment">//check_nomsg(cpl_table_save(xlr,NULL,NULL,"out_xlr.fits",CPL_IO_DEFAULT));</span>
+<a name="l02903"></a>02903   <span class="comment">//check_nomsg(cpl_table_save(ylr,NULL,NULL,"out_ylr.fits",CPL_IO_DEFAULT));</span>
+<a name="l02904"></a>02904   <span class="comment">//check_nomsg(cpl_table_save(wlr,NULL,NULL,"out_wlr.fits",CPL_IO_DEFAULT));</span>
+<a name="l02905"></a>02905 
+<a name="l02906"></a>02906 
+<a name="l02907"></a>02907   check_nomsg(NPOINTS=cpl_table_get_nrow(ylr));
+<a name="l02908"></a>02908 
+<a name="l02909"></a>02909   check_nomsg(x_matrix = cpl_matrix_wrap(NPOINTS,1,
+<a name="l02910"></a>02910                                        cpl_table_get_data_double(ylr,<span class="stringliteral">"WAVE"</span>)));
+<a name="l02911"></a>02911   check_nomsg(y=cpl_vector_wrap(NPOINTS,cpl_table_get_data_double(ylr,<span class="stringliteral">"INT"</span>)));
+<a name="l02912"></a>02912   <span class="comment">//check_nomsg(fy=cpl_vector_filter_median_create(y,1));</span>
+<a name="l02913"></a>02913   <span class="comment">//check_nomsg(fy=cpl_vector_filter_lowpass_create(y,CPL_LOWPASS_LINEAR,3));</span>
+<a name="l02914"></a>02914   <span class="comment">//check_nomsg(cpl_table_save(ylr,NULL,NULL,"out_ylr1.fits",CPL_IO_DEFAULT));</span>
+<a name="l02915"></a>02915   check_nomsg(fy=sinfo_sky_background_estimate(y,filter_width,filter_width));
+<a name="l02916"></a>02916   <span class="comment">//check_nomsg(cpl_table_save(ylr,NULL,NULL,"out_ylr2.fits",CPL_IO_DEFAULT));</span>
+<a name="l02917"></a>02917   pif=cpl_vector_get_data(fy);
+<a name="l02918"></a>02918   pwf=cpl_table_get_data_double(ylr,<span class="stringliteral">"WAVE"</span>);
+<a name="l02919"></a>02919 
+<a name="l02920"></a>02920 
+<a name="l02921"></a>02921   check_nomsg(cpl_table_new_column(int_sky,<span class="stringliteral">"INT_BKG_SMO"</span>,CPL_TYPE_DOUBLE));
+<a name="l02922"></a>02922   check_nomsg(cpl_table_new_column(int_sky,<span class="stringliteral">"WAVE_SMO"</span>,CPL_TYPE_DOUBLE));
+<a name="l02923"></a>02923   pws=cpl_table_get_data_double(int_sky,<span class="stringliteral">"WAVE"</span>);
+<a name="l02924"></a>02924 
+<a name="l02925"></a>02925   k=0;
+<a name="l02926"></a>02926   i=0;
+<a name="l02927"></a>02927   check_nomsg(nrow=cpl_table_get_nrow(int_sky));
+<a name="l02928"></a>02928   <span class="keywordflow">if</span>((pws[0]-pwf[0])>0) {
+<a name="l02929"></a>02929     <span class="keywordflow">for</span>(i=0;i<NPOINTS;i++) {
+<a name="l02930"></a>02930       <span class="keywordflow">if</span>(fabs(pws[k]-pwf[i]) < tol) {
+<a name="l02931"></a>02931     check_nomsg(cpl_table_set_double(int_sky,<span class="stringliteral">"INT_BKG_SMO"</span>,k,pif[i]));
+<a name="l02932"></a>02932     check_nomsg(cpl_table_set_double(int_sky,<span class="stringliteral">"WAVE_SMO"</span>,k,pws[i]));
+<a name="l02933"></a>02933     k++;
+<a name="l02934"></a>02934       }
+<a name="l02935"></a>02935     }
+<a name="l02936"></a>02936   } <span class="keywordflow">else</span> {
+<a name="l02937"></a>02937     <span class="keywordflow">for</span>(k=0;k<nrow;k++) {
+<a name="l02938"></a>02938       <span class="keywordflow">if</span>((i<NPOINTS) && (fabs(pws[k]-pwf[i]) < tol)) {
+<a name="l02939"></a>02939     check_nomsg(cpl_table_set_double(int_sky,<span class="stringliteral">"INT_BKG_SMO"</span>,k,pif[i]));
+<a name="l02940"></a>02940     check_nomsg(cpl_table_set_double(int_sky,<span class="stringliteral">"WAVE_SMO"</span>,k,pws[i]));
+<a name="l02941"></a>02941     i++;
+<a name="l02942"></a>02942       }
+<a name="l02943"></a>02943     }
+<a name="l02944"></a>02944 
+<a name="l02945"></a>02945   }
+<a name="l02946"></a>02946 
+<a name="l02947"></a>02947   <span class="comment">//check_nomsg(cpl_table_save(ylr,NULL,NULL,"out_ylr3.fits",CPL_IO_DEFAULT));</span>
+<a name="l02948"></a>02948 
+<a name="l02949"></a>02949 
+<a name="l02950"></a>02950   check_nomsg(cpl_vector_set(a, 0, ga0));
+<a name="l02951"></a>02951   check_nomsg(cpl_vector_set(a, 1, ga1));
+<a name="l02952"></a>02952   check_nomsg(cpl_vector_set(a, 2, ga2));
+<a name="l02953"></a>02953 
+<a name="l02954"></a>02954   check_nomsg(sy=cpl_vector_duplicate(y));
+<a name="l02955"></a>02955   check_nomsg(cpl_vector_power(sy,2));
+<a name="l02956"></a>02956   check_nomsg(cpl_vector_power(sy,0.5));
+<a name="l02957"></a>02957   <span class="comment">//check_nomsg(cpl_vector_fill(sy,0.001));</span>
+<a name="l02958"></a>02958 
+<a name="l02959"></a>02959   ia[0] = 1;
+<a name="l02960"></a>02960   ia[1] = 1;
+<a name="l02961"></a>02961   ia[2] = 1;
+<a name="l02962"></a>02962 
+<a name="l02963"></a>02963 
+<a name="l02964"></a>02964   <span class="keywordflow">for</span>(i=0;i<niter;i++) {
+<a name="l02965"></a>02965 
+<a name="l02966"></a>02966     <span class="comment">/*</span>
+<a name="l02967"></a>02967 <span class="comment">    sinfo_msg("before fit: a=%g %g %g",</span>
+<a name="l02968"></a>02968 <span class="comment">              cpl_vector_get(a,0),</span>
+<a name="l02969"></a>02969 <span class="comment">              cpl_vector_get(a,1),</span>
+<a name="l02970"></a>02970 <span class="comment">              cpl_vector_get(a,2));</span>
+<a name="l02971"></a>02971 <span class="comment">    */</span>
+<a name="l02972"></a>02972     <span class="keywordflow">if</span>(CPL_ERROR_NONE != sinfo_fit_lm(x_matrix,NULL,fy,sy,a,ia,sinfo_fitbkg,
+<a name="l02973"></a>02973                       sinfo_fitbkg_derivative,
+<a name="l02974"></a>02974                       &mse,&chired,NULL)) {
+<a name="l02975"></a>02975       <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"Thermal background fit failed"</span>);
+<a name="l02976"></a>02976       cpl_error_reset();
+<a name="l02977"></a>02977       *success_fit=1;
+<a name="l02978"></a>02978 
+<a name="l02979"></a>02979       <span class="keywordflow">goto</span> recover;
+<a name="l02980"></a>02980     }
+<a name="l02981"></a>02981 
+<a name="l02982"></a>02982     <span class="comment">//bkg_max=sinfo_fac(wmax,cpl_vector_get(a,2));</span>
+<a name="l02983"></a>02983     <span class="comment">//sinfo_scale_fct=sinfo_scale_fct*bkg_max;</span>
+<a name="l02984"></a>02984     <span class="comment">/*</span>
+<a name="l02985"></a>02985 <span class="comment">    sinfo_msg("after fit: a=%g %g %g chired=%g",</span>
+<a name="l02986"></a>02986 <span class="comment">              cpl_vector_get(a,0),</span>
+<a name="l02987"></a>02987 <span class="comment">          cpl_vector_get(a,1),</span>
+<a name="l02988"></a>02988 <span class="comment">              cpl_vector_get(a,2),</span>
+<a name="l02989"></a>02989 <span class="comment">              chired);</span>
+<a name="l02990"></a>02990 <span class="comment"></span>
+<a name="l02991"></a>02991 <span class="comment">    */</span>
+<a name="l02992"></a>02992 
+<a name="l02993"></a>02993   }
+<a name="l02994"></a>02994 
+<a name="l02995"></a>02995     sinfo_msg(<span class="stringliteral">"Last fit: a=%g %g %g chired=%g"</span>,
+<a name="l02996"></a>02996               cpl_vector_get(a,0),
+<a name="l02997"></a>02997           cpl_vector_get(a,1),
+<a name="l02998"></a>02998               cpl_vector_get(a,2),
+<a name="l02999"></a>02999               chired);
+<a name="l03000"></a>03000 
+<a name="l03001"></a>03001   sinfo_free_my_vector(&fy);
+<a name="l03002"></a>03002   sinfo_unwrap_vector(&y);
+<a name="l03003"></a>03003   sinfo_free_my_vector(&sy);
+<a name="l03004"></a>03004   sinfo_unwrap_matrix(&x_matrix);
+<a name="l03005"></a>03005   sinfo_free_table(&xlr);
+<a name="l03006"></a>03006   sinfo_free_table(&ylr);
+<a name="l03007"></a>03007   sinfo_free_table(&wlr);
+<a name="l03008"></a>03008 
+<a name="l03009"></a>03009   ga0=cpl_vector_get(a,0);
+<a name="l03010"></a>03010   ga1=cpl_vector_get(a,1);
+<a name="l03011"></a>03011   ga2=cpl_vector_get(a,2);
+<a name="l03012"></a>03012   <span class="comment">//ga2=252.69284;</span>
+<a name="l03013"></a>03013   check_nomsg(npix=cpl_table_get_nrow(lrange));
+<a name="l03014"></a>03014   check_nomsg(pw=cpl_table_get_data_double(lrange,<span class="stringliteral">"WAVE"</span>));
+<a name="l03015"></a>03015   check_nomsg(temp2_tbl=cpl_table_new(npix));
+<a name="l03016"></a>03016   check_nomsg(cpl_table_new_column(temp2_tbl,<span class="stringliteral">"TEMP2"</span>,CPL_TYPE_DOUBLE));
+<a name="l03017"></a>03017 
+<a name="l03018"></a>03018   <span class="keywordflow">for</span>(i=0;i<npix;i++) {
+<a name="l03019"></a>03019     temp2=sinfo_fac(pw[i],ga2);
+<a name="l03020"></a>03020     check_nomsg(cpl_table_set_double(temp2_tbl,<span class="stringliteral">"TEMP2"</span>,i,temp2));
+<a name="l03021"></a>03021   }
+<a name="l03022"></a>03022   check_nomsg(max_tmp2=cpl_table_get_column_max(temp2_tbl,<span class="stringliteral">"TEMP2"</span>));
+<a name="l03023"></a>03023   sinfo_free_table(&temp2_tbl);
+<a name="l03024"></a>03024 
+<a name="l03025"></a>03025 
+<a name="l03026"></a>03026 
+<a name="l03027"></a>03027   check_nomsg(npix=cpl_table_get_nrow(lambda));
+<a name="l03028"></a>03028   check_nomsg(pw=cpl_table_get_data_double(lambda,<span class="stringliteral">"WAVE"</span>));
+<a name="l03029"></a>03029   check_nomsg(*bkg=cpl_table_new(npix));
+<a name="l03030"></a>03030   check_nomsg(cpl_table_new_column(*bkg,<span class="stringliteral">"WAVE"</span>,CPL_TYPE_DOUBLE));
+<a name="l03031"></a>03031   check_nomsg(cpl_table_new_column(*bkg,<span class="stringliteral">"TEMP1"</span>,CPL_TYPE_DOUBLE));
+<a name="l03032"></a>03032   check_nomsg(cpl_table_new_column(*bkg,<span class="stringliteral">"INT"</span>,CPL_TYPE_DOUBLE));
+<a name="l03033"></a>03033   check_nomsg(cpl_table_new_column(*bkg,<span class="stringliteral">"INT2"</span>,CPL_TYPE_DOUBLE));
+<a name="l03034"></a>03034 
+<a name="l03035"></a>03035   <span class="keywordflow">for</span>(i=0;i<npix;i++) {
+<a name="l03036"></a>03036     check_nomsg(cpl_table_set_double(*bkg,<span class="stringliteral">"WAVE"</span>,i,pw[i]));
+<a name="l03037"></a>03037     temp1=sinfo_fac(pw[i],ga2);
+<a name="l03038"></a>03038     check_nomsg(cpl_table_set_double(*bkg,<span class="stringliteral">"TEMP1"</span>,i,temp1));
+<a name="l03039"></a>03039   }
+<a name="l03040"></a>03040 
+<a name="l03041"></a>03041   check_nomsg(ptmp1=cpl_table_get_data_double(*bkg,<span class="stringliteral">"TEMP1"</span>));
+<a name="l03042"></a>03042   <span class="comment">//bkg_max=sinfo_fac(wmax,ga2);</span>
+<a name="l03043"></a>03043 
+<a name="l03044"></a>03044   <span class="keywordflow">for</span>(i=0;i<npix;i++) {
+<a name="l03045"></a>03045     thermal=ga0+ptmp1[i]/max_tmp2*ga1;
+<a name="l03046"></a>03046     check_nomsg(cpl_table_set_double(*bkg,<span class="stringliteral">"INT"</span>,i,thermal));
+<a name="l03047"></a>03047     thermal=ga0+ga1*sinfo_fac(pw[i],ga2);
+<a name="l03048"></a>03048     check_nomsg(cpl_table_set_double(*bkg,<span class="stringliteral">"INT2"</span>,i,thermal));
+<a name="l03049"></a>03049   }
+<a name="l03050"></a>03050   sinfo_free_my_vector(&a);
+<a name="l03051"></a>03051 
+<a name="l03052"></a>03052   <span class="keywordflow">return</span> 0;
+<a name="l03053"></a>03053 
+<a name="l03054"></a>03054  recover:
+<a name="l03055"></a>03055   <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"Recover fit of thermal background"</span>);
+<a name="l03056"></a>03056   check_nomsg(npix=cpl_table_get_nrow(lambda));
+<a name="l03057"></a>03057   check_nomsg(*bkg=cpl_table_new(npix));
+<a name="l03058"></a>03058   check_nomsg(cpl_table_new_column(*bkg,<span class="stringliteral">"TEMP1"</span>,CPL_TYPE_DOUBLE));
+<a name="l03059"></a>03059   check_nomsg(cpl_table_new_column(*bkg,<span class="stringliteral">"INT"</span>,CPL_TYPE_DOUBLE));
+<a name="l03060"></a>03060   check_nomsg(cpl_table_new_column(*bkg,<span class="stringliteral">"INT2"</span>,CPL_TYPE_DOUBLE));
+<a name="l03061"></a>03061 
+<a name="l03062"></a>03062   med=cpl_table_get_column_median(ylr,<span class="stringliteral">"INT"</span>);
+<a name="l03063"></a>03063   <span class="keywordflow">for</span>(i=0;i<npix;i++) {
+<a name="l03064"></a>03064     check_nomsg(cpl_table_set_double(*bkg,<span class="stringliteral">"INT"</span>,i,med));
+<a name="l03065"></a>03065     check_nomsg(cpl_table_set_double(*bkg,<span class="stringliteral">"INT2"</span>,i,med));
+<a name="l03066"></a>03066   }
+<a name="l03067"></a>03067 
+<a name="l03068"></a>03068   sinfo_free_my_vector(&a);
+<a name="l03069"></a>03069   sinfo_unwrap_vector(&y);
+<a name="l03070"></a>03070   sinfo_free_my_vector(&sy);
+<a name="l03071"></a>03071   sinfo_unwrap_matrix(&x_matrix);
+<a name="l03072"></a>03072   sinfo_free_table(&xlr);
+<a name="l03073"></a>03073   sinfo_free_table(&ylr);
+<a name="l03074"></a>03074   sinfo_free_table(&wlr);
+<a name="l03075"></a>03075   sinfo_free_table(&tmp);
+<a name="l03076"></a>03076 
+<a name="l03077"></a>03077   <span class="keywordflow">return</span> 0;
+<a name="l03078"></a>03078 
+<a name="l03079"></a>03079 
+<a name="l03080"></a>03080  cleanup:
+<a name="l03081"></a>03081   sinfo_free_my_vector(&a);
+<a name="l03082"></a>03082   sinfo_unwrap_vector(&y);
+<a name="l03083"></a>03083   sinfo_free_my_vector(&sy);
+<a name="l03084"></a>03084   sinfo_unwrap_matrix(&x_matrix);
+<a name="l03085"></a>03085 
+<a name="l03086"></a>03086   sinfo_free_table(&xlr);
+<a name="l03087"></a>03087   sinfo_free_table(&ylr);
+<a name="l03088"></a>03088   sinfo_free_table(&wlr);
+<a name="l03089"></a>03089   sinfo_free_table(&tmp);
+<a name="l03090"></a>03090   sinfo_free_table(&temp2_tbl);
+<a name="l03091"></a>03091 
+<a name="l03092"></a>03092   <span class="keywordflow">return</span> -1;
+<a name="l03093"></a>03093 
+<a name="l03094"></a>03094 }
+<a name="l03095"></a>03095 
+<a name="l03107"></a>03107 <span class="keyword">static</span> cpl_vector*
+<a name="l03108"></a>03108 sinfo_filter_min(<span class="keyword">const</span> cpl_vector* vi, <span class="keyword">const</span> <span class="keywordtype">int</span> size)
+<a name="l03109"></a>03109 {
+<a name="l03110"></a>03110 
+<a name="l03111"></a>03111   cpl_vector* vo=NULL;
+<a name="l03112"></a>03112   <span class="keywordtype">double</span> min=0;
+<a name="l03113"></a>03113   <span class="keywordtype">int</span> start=size/2;
+<a name="l03114"></a>03114   <span class="keywordtype">int</span> end=0;
+<a name="l03115"></a>03115   <span class="keywordtype">int</span> length=0;
+<a name="l03116"></a>03116   <span class="keywordtype">int</span> i=0;
+<a name="l03117"></a>03117   <span class="keywordtype">int</span> j=0;
+<a name="l03118"></a>03118   <span class="keyword">const</span> <span class="keywordtype">double</span>* pi=NULL;
+<a name="l03119"></a>03119   <span class="keywordtype">double</span>* po=NULL;
+<a name="l03120"></a>03120   cknull(vi,<span class="stringliteral">"null input vector"</span>);
+<a name="l03121"></a>03121   pi=cpl_vector_get_data_const(vi);
+<a name="l03122"></a>03122   length=cpl_vector_get_size(vi);
+<a name="l03123"></a>03123   end=length-size/2;
+<a name="l03124"></a>03124   vo=cpl_vector_new(length);
+<a name="l03125"></a>03125   po=cpl_vector_get_data(vo);
+<a name="l03126"></a>03126 
+<a name="l03127"></a>03127   <span class="keywordflow">for</span>(i=start; i < end; i++) {
+<a name="l03128"></a>03128     min=pi[i-start];
+<a name="l03129"></a>03129     <span class="keywordflow">for</span>(j=i-start+1;j<i+start+1;j++) {
+<a name="l03130"></a>03130       <span class="keywordflow">if</span>(min> pi[j]) {
+<a name="l03131"></a>03131     min=pi[j];
+<a name="l03132"></a>03132       }
+<a name="l03133"></a>03133     }
+<a name="l03134"></a>03134     po[i]=min;
+<a name="l03135"></a>03135 
+<a name="l03136"></a>03136   }
+<a name="l03137"></a>03137 
+<a name="l03138"></a>03138   <span class="comment">// To prevent border effects:</span>
+<a name="l03139"></a>03139   <span class="keywordflow">for</span> (i = 0; i < start; i++) {
+<a name="l03140"></a>03140     po[i] = po[start];
+<a name="l03141"></a>03141   }
+<a name="l03142"></a>03142 
+<a name="l03143"></a>03143   <span class="keywordflow">for</span> (i = end; i < length; i++) {
+<a name="l03144"></a>03144     po[i] = po[end-1];
+<a name="l03145"></a>03145   }
+<a name="l03146"></a>03146   <span class="keywordflow">return</span> vo;
+<a name="l03147"></a>03147 
+<a name="l03148"></a>03148  cleanup:
+<a name="l03149"></a>03149   <span class="keywordflow">return</span> NULL;
+<a name="l03150"></a>03150 
+<a name="l03151"></a>03151 
+<a name="l03152"></a>03152 }
+<a name="l03153"></a>03153 
+<a name="l03154"></a>03154 
+<a name="l03166"></a>03166 <span class="keyword">static</span> cpl_vector*
+<a name="l03167"></a>03167 sinfo_filter_max(<span class="keyword">const</span> cpl_vector* vi, <span class="keyword">const</span> <span class="keywordtype">int</span> size)
+<a name="l03168"></a>03168 {
+<a name="l03169"></a>03169 
+<a name="l03170"></a>03170   cpl_vector* vo=NULL;
+<a name="l03171"></a>03171   <span class="keywordtype">double</span> max=0;
+<a name="l03172"></a>03172   <span class="keywordtype">int</span> start=size/2;
+<a name="l03173"></a>03173   <span class="keywordtype">int</span> end=0;
+<a name="l03174"></a>03174   <span class="keywordtype">int</span> length=0;
+<a name="l03175"></a>03175   <span class="keywordtype">int</span> i=0;
+<a name="l03176"></a>03176   <span class="keywordtype">int</span> j=0;
+<a name="l03177"></a>03177   <span class="keyword">const</span> <span class="keywordtype">double</span>* pi=NULL;
+<a name="l03178"></a>03178   <span class="keywordtype">double</span>* po=NULL;
+<a name="l03179"></a>03179 
+<a name="l03180"></a>03180   cknull(vi,<span class="stringliteral">"null input vector"</span>);
+<a name="l03181"></a>03181   pi=cpl_vector_get_data_const(vi);
+<a name="l03182"></a>03182   length=cpl_vector_get_size(vi);
+<a name="l03183"></a>03183   end=length-size/2;
+<a name="l03184"></a>03184   vo=cpl_vector_new(length);
+<a name="l03185"></a>03185   po=cpl_vector_get_data(vo);
+<a name="l03186"></a>03186 
+<a name="l03187"></a>03187   <span class="keywordflow">for</span>(i=start; i < end; i++) {
+<a name="l03188"></a>03188     max=pi[i-start];
+<a name="l03189"></a>03189     <span class="keywordflow">for</span>(j=i-start+1;j<i+start+1;j++) {
+<a name="l03190"></a>03190       <span class="keywordflow">if</span>(max< pi[j]) {
+<a name="l03191"></a>03191     max=pi[j];
+<a name="l03192"></a>03192       }
+<a name="l03193"></a>03193     }
+<a name="l03194"></a>03194     po[i]=max;
+<a name="l03195"></a>03195 
+<a name="l03196"></a>03196   }
+<a name="l03197"></a>03197 
+<a name="l03198"></a>03198   <span class="comment">// To prevent border effects:</span>
+<a name="l03199"></a>03199   <span class="keywordflow">for</span> (i = 0; i < start; i++) {
+<a name="l03200"></a>03200     po[i] = po[start];
+<a name="l03201"></a>03201   }
+<a name="l03202"></a>03202 
+<a name="l03203"></a>03203   <span class="keywordflow">for</span> (i = end; i < length; i++) {
+<a name="l03204"></a>03204     po[i] = po[end-1];
+<a name="l03205"></a>03205   }
+<a name="l03206"></a>03206   <span class="keywordflow">return</span> vo;
+<a name="l03207"></a>03207 
+<a name="l03208"></a>03208  cleanup:
+<a name="l03209"></a>03209   <span class="keywordflow">return</span> NULL;
+<a name="l03210"></a>03210 
+<a name="l03211"></a>03211 
+<a name="l03212"></a>03212 }
+<a name="l03213"></a>03213 
+<a name="l03214"></a>03214 
+<a name="l03215"></a>03215 
+<a name="l03227"></a>03227 <span class="keyword">static</span> cpl_vector*
+<a name="l03228"></a>03228 sinfo_filter_smo(<span class="keyword">const</span> cpl_vector* vi, <span class="keyword">const</span> <span class="keywordtype">int</span> size)
+<a name="l03229"></a>03229 {
+<a name="l03230"></a>03230 
+<a name="l03231"></a>03231 
+<a name="l03232"></a>03232   <span class="keywordtype">double</span> sum=0;
+<a name="l03233"></a>03233   <span class="keywordtype">int</span> start=size/2;
+<a name="l03234"></a>03234   <span class="keywordtype">int</span> end=0;
+<a name="l03235"></a>03235   <span class="keywordtype">int</span> length=0;
+<a name="l03236"></a>03236   <span class="keywordtype">int</span> i=0;
+<a name="l03237"></a>03237   <span class="keywordtype">int</span> j=0;
+<a name="l03238"></a>03238   <span class="keyword">const</span> <span class="keywordtype">double</span>* pi=NULL;
+<a name="l03239"></a>03239   <span class="keywordtype">double</span>* po=NULL;
+<a name="l03240"></a>03240   cpl_vector* vo=NULL;
+<a name="l03241"></a>03241 
+<a name="l03242"></a>03242   cknull(vi,<span class="stringliteral">"null input vector"</span>);
+<a name="l03243"></a>03243   length=cpl_vector_get_size(vi);
+<a name="l03244"></a>03244   end=length-size/2;
+<a name="l03245"></a>03245   vo=cpl_vector_new(length);
+<a name="l03246"></a>03246   pi=cpl_vector_get_data_const(vi);
+<a name="l03247"></a>03247   po=cpl_vector_get_data(vo);
+<a name="l03248"></a>03248 
+<a name="l03249"></a>03249   <span class="keywordflow">for</span>(i=start; i < end; i++) {
+<a name="l03250"></a>03250     sum=0;
+<a name="l03251"></a>03251     <span class="keywordflow">for</span>(j=i - start;j<i+start+1;j++) {
+<a name="l03252"></a>03252       sum += pi[j];
+<a name="l03253"></a>03253     }
+<a name="l03254"></a>03254     po[i]=sum/size;
+<a name="l03255"></a>03255 
+<a name="l03256"></a>03256   }
+<a name="l03257"></a>03257 
+<a name="l03258"></a>03258   <span class="comment">// To prevent border effects:</span>
+<a name="l03259"></a>03259   <span class="keywordflow">for</span> (i = 0; i < start; i++) {
+<a name="l03260"></a>03260     po[i] = po[start];
+<a name="l03261"></a>03261   }
+<a name="l03262"></a>03262 
+<a name="l03263"></a>03263   <span class="keywordflow">for</span> (i = end; i < length; i++) {
+<a name="l03264"></a>03264     po[i] = po[end-1];
+<a name="l03265"></a>03265   }
+<a name="l03266"></a>03266   <span class="keywordflow">return</span> vo;
+<a name="l03267"></a>03267 
+<a name="l03268"></a>03268  cleanup:
+<a name="l03269"></a>03269   <span class="keywordflow">return</span> NULL;
+<a name="l03270"></a>03270 
+<a name="l03271"></a>03271 }
+<a name="l03272"></a>03272 
+<a name="l03329"></a>03329 cpl_vector* sinfo_sky_background_estimate(cpl_vector *spectrum,
+<a name="l03330"></a>03330                                              <span class="keywordtype">int</span> msize,
+<a name="l03331"></a>03331                                              <span class="keywordtype">int</span> fsize)
+<a name="l03332"></a>03332 {
+<a name="l03333"></a>03333 
+<a name="l03334"></a>03334     cpl_vector  * minf=NULL;
+<a name="l03335"></a>03335     cpl_vector  * maxf=NULL;
+<a name="l03336"></a>03336     cpl_vector  * smof=NULL;
+<a name="l03337"></a>03337     cpl_vector  * back=NULL;
+<a name="l03338"></a>03338     <span class="keywordtype">double</span>* pb=NULL;
+<a name="l03339"></a>03339     <span class="keywordtype">double</span>* ps=NULL;
+<a name="l03340"></a>03340 
+<a name="l03341"></a>03341     <span class="keywordtype">int</span>     i=0;
+<a name="l03342"></a>03342     <span class="keywordtype">int</span> length=0;
+<a name="l03343"></a>03343 
+<a name="l03344"></a>03344 
+<a name="l03345"></a>03345     cknull(spectrum,<span class="stringliteral">"null input data"</span>);
+<a name="l03346"></a>03346 
+<a name="l03347"></a>03347     <span class="keywordflow">if</span> (msize % 2 == 0)
+<a name="l03348"></a>03348         msize++;
+<a name="l03349"></a>03349 
+<a name="l03350"></a>03350     <span class="keywordflow">if</span> (fsize % 2 == 0)
+<a name="l03351"></a>03351         fsize++;
+<a name="l03352"></a>03352     check_nomsg(length=cpl_vector_get_size(spectrum));
+<a name="l03353"></a>03353 
+<a name="l03354"></a>03354     <span class="keywordflow">if</span> (msize < 3 || fsize < msize || length < 2*fsize)
+<a name="l03355"></a>03355         <span class="keywordflow">return</span> NULL;
+<a name="l03356"></a>03356 
+<a name="l03357"></a>03357 
+<a name="l03358"></a>03358     cknull_nomsg(minf = sinfo_filter_min(spectrum, msize));
+<a name="l03359"></a>03359     cknull_nomsg(smof = sinfo_filter_smo(minf, fsize));
+<a name="l03360"></a>03360     cpl_vector_delete(minf);
+<a name="l03361"></a>03361     cknull_nomsg(maxf = sinfo_filter_max(smof,2*msize+1));
+<a name="l03362"></a>03362     cpl_vector_delete(smof);
+<a name="l03363"></a>03363     cknull_nomsg(smof = sinfo_filter_smo(maxf, 2*fsize+1));
+<a name="l03364"></a>03364     cpl_vector_delete(maxf);
+<a name="l03365"></a>03365     cknull_nomsg(minf = sinfo_filter_min(smof, 2*msize+1));
+<a name="l03366"></a>03366     cpl_vector_delete(smof);
+<a name="l03367"></a>03367     cknull_nomsg(smof = sinfo_filter_smo(minf, 2*fsize+1));
+<a name="l03368"></a>03368     cpl_vector_delete(minf);
+<a name="l03369"></a>03369     cknull_nomsg(back=cpl_vector_new(length));
+<a name="l03370"></a>03370     cknull_nomsg(pb=cpl_vector_get_data(back));
+<a name="l03371"></a>03371     cknull_nomsg(ps=cpl_vector_get_data(smof));
+<a name="l03372"></a>03372 
+<a name="l03373"></a>03373     <span class="keywordflow">for</span> (i = 0; i < length; i++) {
+<a name="l03374"></a>03374         pb[i] = ps[i];
+<a name="l03375"></a>03375      }
+<a name="l03376"></a>03376     cpl_vector_delete(smof);
+<a name="l03377"></a>03377 
+<a name="l03378"></a>03378     <span class="keywordflow">return</span> back;
+<a name="l03379"></a>03379  cleanup:
+<a name="l03380"></a>03380 
+<a name="l03381"></a>03381     <span class="keywordflow">return</span> NULL;
+<a name="l03382"></a>03382 
+<a name="l03383"></a>03383 }
+<a name="l03384"></a>03384 
+<a name="l03385"></a>03385 
+<a name="l03386"></a>03386 
+<a name="l03396"></a>03396 <span class="keyword">static</span> cpl_table*
+<a name="l03397"></a>03397 sinfo_slice_z(<span class="keyword">const</span> cpl_imagelist* cin,<span class="keyword">const</span> <span class="keywordtype">int</span> i,<span class="keyword">const</span> <span class="keywordtype">int</span> j)
+<a name="l03398"></a>03398 {
+<a name="l03399"></a>03399   <span class="keywordtype">int</span> sx=0;
+<a name="l03400"></a>03400   <span class="keywordtype">int</span> sy=0;
+<a name="l03401"></a>03401   <span class="keywordtype">int</span> sz=0;
+<a name="l03402"></a>03402   <span class="keywordtype">int</span> k=0;
+<a name="l03403"></a>03403   cpl_table* tout=NULL;
+<a name="l03404"></a>03404   <span class="keyword">const</span> cpl_image* img=NULL;
+<a name="l03405"></a>03405   <span class="keyword">const</span> <span class="keywordtype">double</span>* pim=NULL;
+<a name="l03406"></a>03406 
+<a name="l03407"></a>03407   cknull(cin,<span class="stringliteral">"null input imagelist"</span>);
+<a name="l03408"></a>03408   check_nomsg(sz=cpl_imagelist_get_size(cin));
+<a name="l03409"></a>03409   check_nomsg(img=cpl_imagelist_get_const(cin,0));
+<a name="l03410"></a>03410   check_nomsg(sx=cpl_image_get_size_x(img));
+<a name="l03411"></a>03411   check_nomsg(sy=cpl_image_get_size_y(img));
+<a name="l03412"></a>03412   check_nomsg(tout=cpl_table_new(sz));
+<a name="l03413"></a>03413   check_nomsg(cpl_table_new_column(tout,<span class="stringliteral">"VALUE"</span>,CPL_TYPE_DOUBLE));
+<a name="l03414"></a>03414   <span class="keywordflow">for</span>(k=0;k<sz;k++) {
+<a name="l03415"></a>03415     check_nomsg(img=cpl_imagelist_get_const(cin,k));
+<a name="l03416"></a>03416     check_nomsg(pim=cpl_image_get_data_double_const(img));
+<a name="l03417"></a>03417     check_nomsg(cpl_table_set(tout,<span class="stringliteral">"VALUE"</span>,k,pim[j*sx+i]));
+<a name="l03418"></a>03418   }
+<a name="l03419"></a>03419 
+<a name="l03420"></a>03420   <span class="keywordflow">return</span> tout;
+<a name="l03421"></a>03421  cleanup:
+<a name="l03422"></a>03422   sinfo_free_table(&tout);
+<a name="l03423"></a>03423 
+<a name="l03424"></a>03424   <span class="keywordflow">return</span> NULL;
+<a name="l03425"></a>03425 
+<a name="l03426"></a>03426 }
+<a name="l03427"></a>03427 
+<a name="l03438"></a>03438 <span class="keywordtype">double</span>
+<a name="l03439"></a>03439 sinfo_xcorr(cpl_table* int_obj,
+<a name="l03440"></a>03440             cpl_table* int_sky,
+<a name="l03441"></a>03441             cpl_table* lambda,
+<a name="l03442"></a>03442             <span class="keyword">const</span> <span class="keywordtype">double</span> dispersion,
+<a name="l03443"></a>03443             <span class="keyword">const</span> <span class="keywordtype">double</span> line_hw)
+<a name="l03444"></a>03444 {
+<a name="l03445"></a>03445 
+<a name="l03446"></a>03446   cpl_table* z=NULL;
+<a name="l03447"></a>03447   cpl_table* tmp_sky=NULL;
+<a name="l03448"></a>03448 
+<a name="l03449"></a>03449   cpl_table* z_diff=NULL;
+<a name="l03450"></a>03450   cpl_table* z_pos=NULL;
+<a name="l03451"></a>03451 
+<a name="l03452"></a>03452   <span class="keywordtype">int</span> z_ext=0;
+<a name="l03453"></a>03453   <span class="keywordtype">double</span> z_mean=0;
+<a name="l03454"></a>03454   <span class="keywordtype">double</span> z_sdv=0;
+<a name="l03455"></a>03455   <span class="keywordtype">int</span> nrow=0;
+<a name="l03456"></a>03456   <span class="keywordtype">int</span> i=0;
+<a name="l03457"></a>03457 
+<a name="l03458"></a>03458   <span class="keywordtype">double</span> g_lam=0;
+<a name="l03459"></a>03459   <span class="keywordtype">double</span> g_err=0;
+<a name="l03460"></a>03460 
+<a name="l03461"></a>03461   <span class="keywordtype">double</span> sky_max=0;
+<a name="l03462"></a>03462 
+<a name="l03463"></a>03463   <span class="keywordtype">double</span>* pint=NULL;
+<a name="l03464"></a>03464   <span class="keywordtype">int</span>* ppos=NULL;
+<a name="l03465"></a>03465   <span class="keywordtype">int</span> status=0;
+<a name="l03466"></a>03466   <span class="keywordtype">int</span> zsize=0;
+<a name="l03467"></a>03467   <span class="keywordtype">int</span> iq=0;
+<a name="l03468"></a>03468 
+<a name="l03469"></a>03469   <span class="keywordtype">double</span> g_diff=0;
+<a name="l03470"></a>03470   <span class="keywordtype">int</span> jz=0;
+<a name="l03471"></a>03471   <span class="keywordtype">int</span> z1=0;
+<a name="l03472"></a>03472   <span class="keywordtype">int</span> nfit=0;
+<a name="l03473"></a>03473   <span class="keywordtype">int</span> npos=0;
+<a name="l03474"></a>03474   cpl_table* z_good=NULL;
+<a name="l03475"></a>03475   cpl_table* w_tbl=NULL;
+<a name="l03476"></a>03476   cpl_table* o_tbl=NULL;
+<a name="l03477"></a>03477   cpl_table* s_tbl=NULL;
+<a name="l03478"></a>03478   cpl_vector* vw=NULL;
+<a name="l03479"></a>03479   cpl_vector* vs=NULL;
+<a name="l03480"></a>03480   cpl_vector* vo=NULL;
+<a name="l03481"></a>03481   cpl_vector* sx=NULL;
+<a name="l03482"></a>03482   cpl_vector* sy=NULL;
+<a name="l03483"></a>03483 
+<a name="l03484"></a>03484 
+<a name="l03485"></a>03485   <span class="keywordtype">double</span> o1=0;
+<a name="l03486"></a>03486   <span class="keywordtype">double</span> o2=0;
+<a name="l03487"></a>03487   <span class="keywordtype">double</span> oc=0;
+<a name="l03488"></a>03488   <span class="keywordtype">double</span> om=0;
+<a name="l03489"></a>03489 
+<a name="l03490"></a>03490 
+<a name="l03491"></a>03491 
+<a name="l03492"></a>03492   <span class="keywordtype">double</span> zfit=0;
+<a name="l03493"></a>03493 
+<a name="l03494"></a>03494 
+<a name="l03495"></a>03495   <span class="keywordtype">double</span> mse=0;
+<a name="l03496"></a>03496 
+<a name="l03497"></a>03497   <span class="keywordtype">double</span> ws=0;
+<a name="l03498"></a>03498   <span class="keywordtype">double</span> wc_s=0;
+<a name="l03499"></a>03499   <span class="keywordtype">double</span> sig_s=0;
+<a name="l03500"></a>03500   <span class="keywordtype">double</span> bkg_s=0;
+<a name="l03501"></a>03501   <span class="keywordtype">double</span> amp_s=0;
+<a name="l03502"></a>03502   <span class="keywordtype">double</span> area_s=0;
+<a name="l03503"></a>03503 
+<a name="l03504"></a>03504   <span class="keywordtype">double</span> wo=0;
+<a name="l03505"></a>03505   <span class="keywordtype">double</span> wc_o=0;
+<a name="l03506"></a>03506   <span class="keywordtype">double</span> sig_o=0;
+<a name="l03507"></a>03507   <span class="keywordtype">double</span> bkg_o=0;
+<a name="l03508"></a>03508   <span class="keywordtype">double</span> amp_o=0;
+<a name="l03509"></a>03509   <span class="keywordtype">double</span> area_o=0;
+<a name="l03510"></a>03510 
+<a name="l03511"></a>03511   cpl_polynomial* cfit=NULL;
+<a name="l03512"></a>03512   cpl_size pows[2];
+<a name="l03513"></a>03513   cpl_vector* vx=NULL;
+<a name="l03514"></a>03514   cpl_vector* vy=NULL;
+<a name="l03515"></a>03515 
+<a name="l03516"></a>03516 
+<a name="l03517"></a>03517   cpl_error_code error_code=CPL_ERROR_NONE;
+<a name="l03518"></a>03518 
+<a name="l03519"></a>03519   <span class="comment">// crosscorrelate obj & sky to check for lambda offset</span>
+<a name="l03520"></a>03520 
+<a name="l03521"></a>03521   <span class="comment">//if (mean(z[where(finite(z))]) < 0) z = z * (-1);</span>
+<a name="l03522"></a>03522   <span class="comment">//if sky mean is < 0 flip sky intensity</span>
+<a name="l03523"></a>03523   zsize=cpl_table_get_nrow(int_obj);
+<a name="l03524"></a>03524   check_nomsg(z = cpl_table_duplicate(int_sky));
+<a name="l03525"></a>03525   ck0_nomsg(sinfo_table_flag_nan(&z,<span class="stringliteral">"INT"</span>));
+<a name="l03526"></a>03526   <span class="comment">//check_nomsg(cpl_table_save(z,NULL,NULL,"out_z1.fits",CPL_IO_DEFAULT));</span>
+<a name="l03527"></a>03527   check_nomsg(z_mean=cpl_table_get_column_mean(z,<span class="stringliteral">"INT"</span>));
+<a name="l03528"></a>03528   <span class="keywordflow">if</span>(z_mean < 0) {
+<a name="l03529"></a>03529     check_nomsg(cpl_table_multiply_scalar(z,<span class="stringliteral">"INT"</span>,-1));
+<a name="l03530"></a>03530   }
+<a name="l03531"></a>03531   <span class="comment">//check_nomsg(cpl_table_save(z,NULL,NULL,"out_z2.fits",CPL_IO_DEFAULT));</span>
+<a name="l03532"></a>03532 
+<a name="l03533"></a>03533   <span class="comment">//z[where(int_sky < max(int_sky[where(finite(int_sky))])/4)] = 0;</span>
+<a name="l03534"></a>03534   <span class="comment">// take in consideration only strong sky lines (set else to 0)</span>
+<a name="l03535"></a>03535   check_nomsg(tmp_sky=cpl_table_duplicate(int_sky));
+<a name="l03536"></a>03536   ck0_nomsg(sinfo_table_flag_nan(&tmp_sky,<span class="stringliteral">"INT"</span>));
+<a name="l03537"></a>03537   check_nomsg(sky_max=cpl_table_get_column_max(tmp_sky,<span class="stringliteral">"INT"</span>));
+<a name="l03538"></a>03538   sinfo_free_table(&tmp_sky);
+<a name="l03539"></a>03539 
+<a name="l03540"></a>03540   <span class="comment">//flag too low values</span>
+<a name="l03541"></a>03541   check_nomsg(nrow=cpl_table_get_nrow(z));
+<a name="l03542"></a>03542   check_nomsg(pint=cpl_table_get_data_double(z,<span class="stringliteral">"INT"</span>));
+<a name="l03543"></a>03543   check_nomsg(sky_max=cpl_table_get_column_max(z,<span class="stringliteral">"INT"</span>));
+<a name="l03544"></a>03544   <span class="keywordflow">for</span>(i=0;i<nrow;i++) {
+<a name="l03545"></a>03545     <span class="keywordflow">if</span>(pint[i]<sky_max/SKY_LINE_MIN_CUT) {
+<a name="l03546"></a>03546       pint[i]=0;
+<a name="l03547"></a>03547     }
+<a name="l03548"></a>03548   }
+<a name="l03549"></a>03549 
+<a name="l03550"></a>03550 
+<a name="l03551"></a>03551   <span class="comment">//check_nomsg(cpl_table_save(z,NULL,NULL,"out_z4.fits",CPL_IO_DEFAULT));</span>
+<a name="l03552"></a>03552   <span class="comment">//computes gradient</span>
+<a name="l03553"></a>03553   <span class="comment">//z_diff = z[0:n_elements(z)-2] - z[1:n_elements(z)-1];</span>
+<a name="l03554"></a>03554   check_nomsg(z_diff=cpl_table_duplicate(z));
+<a name="l03555"></a>03555   check_nomsg(cpl_table_duplicate_column(z_diff,<span class="stringliteral">"INT1"</span>,z,<span class="stringliteral">"INT"</span>));
+<a name="l03556"></a>03556   check_nomsg(cpl_table_duplicate_column(z_diff,<span class="stringliteral">"INT2"</span>,z,<span class="stringliteral">"INT"</span>));
+<a name="l03557"></a>03557   check_nomsg(cpl_table_shift_column(z_diff,<span class="stringliteral">"INT1"</span>,-1));
+<a name="l03558"></a>03558   check_nomsg(cpl_table_duplicate_column(z_diff,<span class="stringliteral">"DIFF"</span>,z_diff,<span class="stringliteral">"INT2"</span>));
+<a name="l03559"></a>03559   check_nomsg(cpl_table_subtract_columns(z_diff,<span class="stringliteral">"DIFF"</span>,<span class="stringliteral">"INT1"</span>));
+<a name="l03560"></a>03560 
+<a name="l03561"></a>03561   check_nomsg(cpl_table_erase_window(z_diff,nrow-2,2));
+<a name="l03562"></a>03562   <span class="comment">//check_nomsg(cpl_table_save(z_diff,NULL,NULL,</span>
+<a name="l03563"></a>03563   <span class="comment">//                             "out_z_diff.fits",CPL_IO_DEFAULT));</span>
+<a name="l03564"></a>03564 
+<a name="l03565"></a>03565   <span class="comment">//identify points positions at which there is a line pick</span>
+<a name="l03566"></a>03566   check_nomsg(cpl_table_new_column(z_diff,<span class="stringliteral">"POS"</span>,CPL_TYPE_INT));
+<a name="l03567"></a>03567   check_nomsg(cpl_table_fill_column_window_int(z_diff,<span class="stringliteral">"POS"</span>,0,nrow,0));
+<a name="l03568"></a>03568 
+<a name="l03569"></a>03569   check_nomsg(pint=cpl_table_get_data_double(z_diff,<span class="stringliteral">"DIFF"</span>));
+<a name="l03570"></a>03570   check_nomsg(ppos=cpl_table_get_data_int(z_diff,<span class="stringliteral">"POS"</span>));
+<a name="l03571"></a>03571   check_nomsg(nrow=cpl_table_get_nrow(z_diff));
+<a name="l03572"></a>03572   <span class="keywordflow">for</span>(i=1;i<nrow;i++) {
+<a name="l03573"></a>03573     <span class="keywordflow">if</span>(!<a class="code" href="group__irplib__utils.html#ga804bfc739b5d55f9797ab881b1034ae4" title="portable isnan">irplib_isnan</a>(pint[i]) && (pint[i]>0 && pint[i-1]<0)) {
+<a name="l03574"></a>03574       ppos[i]=i;
+<a name="l03575"></a>03575     }
+<a name="l03576"></a>03576   }
+<a name="l03577"></a>03577 
+<a name="l03578"></a>03578   <span class="comment">//check_nomsg(cpl_table_save(z_diff,NULL,NULL,"out_z_diff.fits",</span>
+<a name="l03579"></a>03579   <span class="comment">//                             CPL_IO_DEFAULT));</span>
+<a name="l03580"></a>03580   check_nomsg(cpl_table_select_all(z_diff));
+<a name="l03581"></a>03581   check_nomsg(cpl_table_and_selected_int(z_diff,<span class="stringliteral">"POS"</span>,CPL_GREATER_THAN,0));
+<a name="l03582"></a>03582   check_nomsg(z_pos=cpl_table_extract_selected(z_diff));
+<a name="l03583"></a>03583   sinfo_free_table(&z_diff);
+<a name="l03584"></a>03584   <span class="comment">//check_nomsg(cpl_table_save(z_pos,NULL,NULL,</span>
+<a name="l03585"></a>03585   <span class="comment">//                             "out_z_pos.fits",CPL_IO_DEFAULT));</span>
+<a name="l03586"></a>03586   <span class="comment">//Do a gaussian fit in a range of size 2*zext centered at</span>
+<a name="l03587"></a>03587   <span class="comment">//each line maximum position (fit the line) to get in corresponding arrays:</span>
+<a name="l03588"></a>03588   <span class="comment">// 1) line lambda position of object and sky</span>
+<a name="l03589"></a>03589   <span class="comment">// 2) line object -sky intensity</span>
+<a name="l03590"></a>03590   <span class="comment">// 3) line object-sky intensity error</span>
+<a name="l03591"></a>03591 
+<a name="l03592"></a>03592 
+<a name="l03593"></a>03593   g_lam = 0.;
+<a name="l03594"></a>03594   g_diff = 0.;
+<a name="l03595"></a>03595   g_err = 0.;
+<a name="l03596"></a>03596   check_nomsg(npos=cpl_table_get_nrow(z_pos));
+<a name="l03597"></a>03597   z_ext = line_hw ;
+<a name="l03598"></a>03598   check_nomsg(cpl_table_new_column(z_pos,<span class="stringliteral">"STATUS_S"</span>,CPL_TYPE_INT));
+<a name="l03599"></a>03599   check_nomsg(cpl_table_new_column(z_pos,<span class="stringliteral">"STATUS_O"</span>,CPL_TYPE_INT));
+<a name="l03600"></a>03600   check_nomsg(cpl_table_fill_column_window_int(z_pos,<span class="stringliteral">"STATUS_S"</span>,0,npos,0));
+<a name="l03601"></a>03601   check_nomsg(cpl_table_fill_column_window_int(z_pos,<span class="stringliteral">"STATUS_O"</span>,0,npos,0));
+<a name="l03602"></a>03602   check_nomsg(cpl_table_new_column(z_pos,<span class="stringliteral">"SIGS"</span>,CPL_TYPE_DOUBLE));
+<a name="l03603"></a>03603   check_nomsg(cpl_table_new_column(z_pos,<span class="stringliteral">"WAVES"</span>,CPL_TYPE_DOUBLE));
+<a name="l03604"></a>03604   check_nomsg(cpl_table_new_column(z_pos,<span class="stringliteral">"BKGS"</span>,CPL_TYPE_DOUBLE));
+<a name="l03605"></a>03605   check_nomsg(cpl_table_new_column(z_pos,<span class="stringliteral">"AREAS"</span>,CPL_TYPE_DOUBLE));
+<a name="l03606"></a>03606   check_nomsg(cpl_table_new_column(z_pos,<span class="stringliteral">"AMPS"</span>,CPL_TYPE_DOUBLE));
+<a name="l03607"></a>03607 
+<a name="l03608"></a>03608 
+<a name="l03609"></a>03609   check_nomsg(cpl_table_new_column(z_pos,<span class="stringliteral">"SIGO"</span>,CPL_TYPE_DOUBLE));
+<a name="l03610"></a>03610   check_nomsg(cpl_table_new_column(z_pos,<span class="stringliteral">"WAVEO"</span>,CPL_TYPE_DOUBLE));
+<a name="l03611"></a>03611   check_nomsg(cpl_table_new_column(z_pos,<span class="stringliteral">"BKGO"</span>,CPL_TYPE_DOUBLE));
+<a name="l03612"></a>03612   check_nomsg(cpl_table_new_column(z_pos,<span class="stringliteral">"AREAO"</span>,CPL_TYPE_DOUBLE));
+<a name="l03613"></a>03613   check_nomsg(cpl_table_new_column(z_pos,<span class="stringliteral">"AMPO"</span>,CPL_TYPE_DOUBLE));
+<a name="l03614"></a>03614 
+<a name="l03615"></a>03615   check_nomsg(cpl_table_new_column(z_pos,<span class="stringliteral">"WAVEC"</span>,CPL_TYPE_DOUBLE));
+<a name="l03616"></a>03616   check_nomsg(cpl_table_new_column(z_pos,<span class="stringliteral">"WDIF"</span>,CPL_TYPE_DOUBLE));
+<a name="l03617"></a>03617   check_nomsg(cpl_table_new_column(z_pos,<span class="stringliteral">"ERR"</span>,CPL_TYPE_DOUBLE));
+<a name="l03618"></a>03618 
+<a name="l03619"></a>03619   nfit=2*z_ext+1;
+<a name="l03620"></a>03620   <span class="comment">//sinfo_msg("npos=%d z_ext=%d",npos,z_ext);</span>
+<a name="l03621"></a>03621   <span class="comment">//sinfo_table_column_dump(z_pos,"POS",CPL_TYPE_INT);</span>
+<a name="l03622"></a>03622   <span class="comment">//check_nomsg(cpl_table_save(z_pos,NULL,NULL,</span>
+<a name="l03623"></a>03623   <span class="comment">//                             "out_z_pos_0.fits",CPL_IO_DEFAULT));</span>
+<a name="l03624"></a>03624   <span class="comment">//check_nomsg(cpl_table_save(int_obj,NULL,NULL,</span>
+<a name="l03625"></a>03625   <span class="comment">//                             "out_int_obj_0.fits",CPL_IO_DEFAULT));</span>
+<a name="l03626"></a>03626   <span class="comment">//check_nomsg(cpl_table_save(int_sky,NULL,NULL,</span>
+<a name="l03627"></a>03627   <span class="comment">//                             "out_int_sky_0.fits",CPL_IO_DEFAULT));</span>
+<a name="l03628"></a>03628 
+<a name="l03629"></a>03629   <span class="keywordflow">for</span> (jz=0;jz<npos;jz++) {
+<a name="l03630"></a>03630     check_nomsg(z1 = cpl_table_get_int(z_pos,<span class="stringliteral">"POS"</span>,jz,&status));
+<a name="l03631"></a>03631     <span class="comment">//sinfo_msg("z1=%d",z1);</span>
+<a name="l03632"></a>03632     <span class="comment">// AMO added if check to prevent array explosion</span>
+<a name="l03633"></a>03633     <span class="keywordflow">if</span>((z1-z_ext) > 0 && (z1+z_ext) < zsize) {
+<a name="l03634"></a>03634       check_nomsg(cpl_table_select_all(int_sky));
+<a name="l03635"></a>03635       check_nomsg(cpl_table_select_all(int_obj));
+<a name="l03636"></a>03636       check_nomsg(cpl_table_select_all(lambda));
+<a name="l03637"></a>03637       check_nomsg(cpl_table_and_selected_window(int_sky,z1-z_ext,nfit));
+<a name="l03638"></a>03638       check_nomsg(s_tbl=cpl_table_extract_selected(int_sky));
+<a name="l03639"></a>03639       check_nomsg(cpl_table_and_selected_window(lambda,z1-z_ext,nfit));
+<a name="l03640"></a>03640       check_nomsg(w_tbl=cpl_table_extract_selected(lambda));
+<a name="l03641"></a>03641       check_nomsg(cpl_table_and_selected_window(int_obj,z1-z_ext,nfit));
+<a name="l03642"></a>03642       check_nomsg(o_tbl=cpl_table_extract_selected(int_obj));
+<a name="l03643"></a>03643 
+<a name="l03644"></a>03644 
+<a name="l03645"></a>03645       check_nomsg(vw=cpl_vector_wrap(nfit,
+<a name="l03646"></a>03646                      cpl_table_get_data_double(w_tbl,<span class="stringliteral">"WAVE"</span>)));
+<a name="l03647"></a>03647       check_nomsg(vs=cpl_vector_wrap(nfit,
+<a name="l03648"></a>03648                      cpl_table_get_data_double(s_tbl,<span class="stringliteral">"INT"</span>)));
+<a name="l03649"></a>03649       check_nomsg(vo=cpl_vector_wrap(nfit,
+<a name="l03650"></a>03650                      cpl_table_get_data_double(o_tbl,<span class="stringliteral">"INT"</span>)));
+<a name="l03651"></a>03651 
+<a name="l03652"></a>03652 
+<a name="l03653"></a>03653       check_nomsg(sx=cpl_vector_new(nfit));
+<a name="l03654"></a>03654       check_nomsg(cpl_vector_fill(sx,10.));
+<a name="l03655"></a>03655       check_nomsg(sy=cpl_vector_duplicate(sx));
+<a name="l03656"></a>03656 
+<a name="l03657"></a>03657 
+<a name="l03658"></a>03658       <span class="comment">// Check if the object line is in emission or absorbtion</span>
+<a name="l03659"></a>03659       o1=cpl_vector_get(vo,0);
+<a name="l03660"></a>03660       o2=cpl_vector_get(vo,nfit-1);
+<a name="l03661"></a>03661       oc=(o1+o2)*0.5;
+<a name="l03662"></a>03662       om=cpl_vector_get_median_const(vo);
+<a name="l03663"></a>03663       <span class="keywordflow">if</span>(om<oc) {
+<a name="l03664"></a>03664     cpl_vector_multiply_scalar(vo,-1.);
+<a name="l03665"></a>03665       }
+<a name="l03666"></a>03666       check_nomsg(ws=cpl_table_get_double(lambda,<span class="stringliteral">"WAVE"</span>,z1,&status));
+<a name="l03667"></a>03667       check_nomsg(amp_s=cpl_table_get_double(z_pos,<span class="stringliteral">"INT"</span>,jz,&status));
+<a name="l03668"></a>03668       wc_s=ws;
+<a name="l03669"></a>03669       sig_s=z_ext*dispersion;
+<a name="l03670"></a>03670       bkg_s=0;
+<a name="l03671"></a>03671       area_s=sinfo_gaussian_area(amp_s,sig_s,ws,wc_s,bkg_s);
+<a name="l03672"></a>03672       <span class="keywordflow">if</span>(wc_s < 2.35) {
+<a name="l03673"></a>03673         <span class="comment">//sinfo_msg("wc_s=%f",wc_s);</span>
+<a name="l03674"></a>03674         <span class="comment">//cpl_vector_dump(vw,stdout);</span>
+<a name="l03675"></a>03675         <span class="comment">//cpl_vector_dump(vs,stdout);</span>
+<a name="l03676"></a>03676 
+<a name="l03677"></a>03677         error_code=cpl_vector_fit_gaussian(vw,NULL,
+<a name="l03678"></a>03678                         vs,NULL,
+<a name="l03679"></a>03679                        CPL_FIT_ALL,
+<a name="l03680"></a>03680                        &wc_s,&sig_s,
+<a name="l03681"></a>03681                        &area_s,&bkg_s,
+<a name="l03682"></a>03682                        NULL,NULL,NULL);
+<a name="l03683"></a>03683         <span class="keywordflow">if</span>(error_code == CPL_ERROR_NONE) {
+<a name="l03684"></a>03684       amp_s=sinfo_gaussian_amp(area_s,sig_s,ws,wc_s,bkg_s);
+<a name="l03685"></a>03685           check_nomsg(cpl_table_set_double(z_pos,<span class="stringliteral">"WAVES"</span>,jz,wc_s));
+<a name="l03686"></a>03686           check_nomsg(cpl_table_set_double(z_pos,<span class="stringliteral">"SIGS"</span>,jz,sig_s));
+<a name="l03687"></a>03687           check_nomsg(cpl_table_set_double(z_pos,<span class="stringliteral">"AREAS"</span>,jz,area_s));
+<a name="l03688"></a>03688           check_nomsg(cpl_table_set_double(z_pos,<span class="stringliteral">"BKGS"</span>,jz,bkg_s));
+<a name="l03689"></a>03689           check_nomsg(cpl_table_set_double(z_pos,<span class="stringliteral">"AMPS"</span>,jz,amp_s));
+<a name="l03690"></a>03690       <span class="comment">/*</span>
+<a name="l03691"></a>03691 <span class="comment">          sinfo_msg("Gauss fit parameters:");</span>
+<a name="l03692"></a>03692 <span class="comment">          sinfo_msg("wc_s=%f sig_s=%f area_s=%f bkg_s=%f",</span>
+<a name="l03693"></a>03693 <span class="comment">                     wc_s,sig_s,area_s,bkg_s);</span>
+<a name="l03694"></a>03694 <span class="comment">          sinfo_msg("mse=%f chired=%f amp_s=%f",</span>
+<a name="l03695"></a>03695 <span class="comment">                     mse,chired,amp_s);</span>
+<a name="l03696"></a>03696 <span class="comment">      */</span>
+<a name="l03697"></a>03697 
+<a name="l03698"></a>03698     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (error_code == CPL_ERROR_CONTINUE) {
+<a name="l03699"></a>03699       cpl_error_reset();
+<a name="l03700"></a>03700       amp_s=sinfo_gaussian_amp(area_s,sig_s,ws,wc_s,bkg_s);
+<a name="l03701"></a>03701           check_nomsg(cpl_table_set_double(z_pos,<span class="stringliteral">"WAVES"</span>,jz,wc_s));
+<a name="l03702"></a>03702           check_nomsg(cpl_table_set_double(z_pos,<span class="stringliteral">"SIGS"</span>,jz,sig_s));
+<a name="l03703"></a>03703           check_nomsg(cpl_table_set_double(z_pos,<span class="stringliteral">"AREAS"</span>,jz,area_s));
+<a name="l03704"></a>03704           check_nomsg(cpl_table_set_double(z_pos,<span class="stringliteral">"BKGS"</span>,jz,bkg_s));
+<a name="l03705"></a>03705           check_nomsg(cpl_table_set_double(z_pos,<span class="stringliteral">"AMPS"</span>,jz,amp_s));
+<a name="l03706"></a>03706           check_nomsg(cpl_table_set_int(z_pos,<span class="stringliteral">"STATUS_S"</span>,jz,-1));
+<a name="l03707"></a>03707     } <span class="keywordflow">else</span> {
+<a name="l03708"></a>03708       cpl_error_reset();
+<a name="l03709"></a>03709           check_nomsg(cpl_table_set_double(z_pos,<span class="stringliteral">"WAVES"</span>,jz,wc_s));
+<a name="l03710"></a>03710           check_nomsg(cpl_table_set_double(z_pos,<span class="stringliteral">"SIGS"</span>,jz,sig_s));
+<a name="l03711"></a>03711           check_nomsg(cpl_table_set_double(z_pos,<span class="stringliteral">"AREAS"</span>,jz,area_s));
+<a name="l03712"></a>03712           check_nomsg(cpl_table_set_double(z_pos,<span class="stringliteral">"BKGS"</span>,jz,bkg_s));
+<a name="l03713"></a>03713           check_nomsg(cpl_table_set_double(z_pos,<span class="stringliteral">"AMPS"</span>,jz,amp_s));
+<a name="l03714"></a>03714           check_nomsg(cpl_table_set_int(z_pos,<span class="stringliteral">"STATUS_S"</span>,jz,-2));
+<a name="l03715"></a>03715     }
+<a name="l03716"></a>03716         check_nomsg(wo=cpl_table_get_double(lambda,<span class="stringliteral">"WAVE"</span>,z1,&status));
+<a name="l03717"></a>03717         check_nomsg(amp_o=cpl_table_get_double(z_pos,<span class="stringliteral">"INT"</span>,jz,&status));
+<a name="l03718"></a>03718         wc_o=wo;
+<a name="l03719"></a>03719         sig_o=z_ext*dispersion;
+<a name="l03720"></a>03720         bkg_o=0;
+<a name="l03721"></a>03721         area_o=sinfo_gaussian_area(amp_o,sig_o,wo,wc_o,bkg_o);
+<a name="l03722"></a>03722         error_code = cpl_vector_fit_gaussian(vw,NULL,
+<a name="l03723"></a>03723                       vo,sy,
+<a name="l03724"></a>03724                      CPL_FIT_ALL,
+<a name="l03725"></a>03725                      &wc_o,&sig_o,
+<a name="l03726"></a>03726                      &area_o,&bkg_o,
+<a name="l03727"></a>03727                      NULL,NULL,NULL);
+<a name="l03728"></a>03728 
+<a name="l03729"></a>03729         <span class="keywordflow">if</span>(error_code == CPL_ERROR_NONE) {
+<a name="l03730"></a>03730 
+<a name="l03731"></a>03731           amp_o=sinfo_gaussian_amp(area_o,sig_o,wo,wc_o,bkg_o);
+<a name="l03732"></a>03732           check_nomsg(cpl_table_set_double(z_pos,<span class="stringliteral">"WAVEO"</span>,jz,wc_o));
+<a name="l03733"></a>03733           check_nomsg(cpl_table_set_double(z_pos,<span class="stringliteral">"SIGO"</span>,jz,sig_o));
+<a name="l03734"></a>03734           check_nomsg(cpl_table_set_double(z_pos,<span class="stringliteral">"AREAO"</span>,jz,area_o));
+<a name="l03735"></a>03735           check_nomsg(cpl_table_set_double(z_pos,<span class="stringliteral">"BKGO"</span>,jz,bkg_o));
+<a name="l03736"></a>03736           check_nomsg(cpl_table_set_double(z_pos,<span class="stringliteral">"AMPO"</span>,jz,amp_o));
+<a name="l03737"></a>03737       <span class="comment">/*</span>
+<a name="l03738"></a>03738 <span class="comment">          sinfo_msg("Gauss fit parameters:");</span>
+<a name="l03739"></a>03739 <span class="comment">          sinfo_msg("wc_o=%f sig_o=%f area_o=%f bkg_o=%f",</span>
+<a name="l03740"></a>03740 <span class="comment">                     wc_o,sig_o,area_o,bkg_o);</span>
+<a name="l03741"></a>03741 <span class="comment">          sinfo_msg("mse=%f chired=%f amp_o=%f",</span>
+<a name="l03742"></a>03742 <span class="comment">                     mse,chired,amp_o);</span>
+<a name="l03743"></a>03743 <span class="comment">      */</span>
+<a name="l03744"></a>03744     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (error_code == CPL_ERROR_CONTINUE) {
+<a name="l03745"></a>03745 
+<a name="l03746"></a>03746       cpl_error_reset();
+<a name="l03747"></a>03747           amp_o=sinfo_gaussian_amp(area_o,sig_o,wo,wc_o,bkg_o);
+<a name="l03748"></a>03748           check_nomsg(cpl_table_set_double(z_pos,<span class="stringliteral">"WAVEO"</span>,jz,wc_o));
+<a name="l03749"></a>03749           check_nomsg(cpl_table_set_double(z_pos,<span class="stringliteral">"SIGO"</span>,jz,sig_o));
+<a name="l03750"></a>03750           check_nomsg(cpl_table_set_double(z_pos,<span class="stringliteral">"AREAO"</span>,jz,area_o));
+<a name="l03751"></a>03751           check_nomsg(cpl_table_set_double(z_pos,<span class="stringliteral">"BKGO"</span>,jz,bkg_o));
+<a name="l03752"></a>03752           check_nomsg(cpl_table_set_double(z_pos,<span class="stringliteral">"AMPO"</span>,jz,amp_o));
+<a name="l03753"></a>03753           check_nomsg(cpl_table_set_int(z_pos,<span class="stringliteral">"STATUS_O"</span>,jz,-1));
+<a name="l03754"></a>03754 
+<a name="l03755"></a>03755     } <span class="keywordflow">else</span> {
+<a name="l03756"></a>03756       cpl_error_reset();
+<a name="l03757"></a>03757           check_nomsg(cpl_table_set_double(z_pos,<span class="stringliteral">"WAVEO"</span>,jz,wc_o));
+<a name="l03758"></a>03758           check_nomsg(cpl_table_set_double(z_pos,<span class="stringliteral">"SIGO"</span>,jz,sig_o));
+<a name="l03759"></a>03759           check_nomsg(cpl_table_set_double(z_pos,<span class="stringliteral">"AREAO"</span>,jz,area_o));
+<a name="l03760"></a>03760           check_nomsg(cpl_table_set_double(z_pos,<span class="stringliteral">"BKGO"</span>,jz,bkg_o));
+<a name="l03761"></a>03761           check_nomsg(cpl_table_set_double(z_pos,<span class="stringliteral">"AMPO"</span>,jz,amp_o));
+<a name="l03762"></a>03762           check_nomsg(cpl_table_set_int(z_pos,<span class="stringliteral">"STATUS_O"</span>,jz,-2));
+<a name="l03763"></a>03763           <span class="comment">/*</span>
+<a name="l03764"></a>03764 <span class="comment">          if (lambda[z1] < 2.35 &&</span>
+<a name="l03765"></a>03765 <span class="comment">             total(finite([l1,s1,o1])) == n_elements([l1,s1,o1])) {</span>
+<a name="l03766"></a>03766 <span class="comment">            gs1 = float(gaussfit(l1,s1,as1,nterms=3));</span>
+<a name="l03767"></a>03767 <span class="comment">            go1 = float(gaussfit(l1,o1,ao1,nterms=3));</span>
+<a name="l03768"></a>03768 <span class="comment">            g_lam = [g_lam,(as1[1]+ao1[1])/2.];</span>
+<a name="l03769"></a>03769 <span class="comment">            g_diff = [g_diff,as1[1]-ao1[1]];</span>
+<a name="l03770"></a>03770 <span class="comment">            g_err = [g_err,sqrt(as1[2]^2+ao1[2]^2)];</span>
+<a name="l03771"></a>03771 <span class="comment">          }</span>
+<a name="l03772"></a>03772 <span class="comment">          */</span>
+<a name="l03773"></a>03773         }
+<a name="l03774"></a>03774         check_nomsg(cpl_table_set_double(z_pos,<span class="stringliteral">"ERR"</span>,
+<a name="l03775"></a>03775                                        jz,sqrt(sig_s*sig_s+sig_o*sig_o)));
+<a name="l03776"></a>03776         check_nomsg(cpl_table_set_double(z_pos,<span class="stringliteral">"WDIF"</span>,jz,wc_s-wc_o));
+<a name="l03777"></a>03777         check_nomsg(cpl_table_set_double(z_pos,<span class="stringliteral">"WAVEC"</span>,jz,(wc_o+wc_s)/2));
+<a name="l03778"></a>03778 
+<a name="l03779"></a>03779       } <span class="keywordflow">else</span> {
+<a name="l03780"></a>03780           check_nomsg(cpl_table_set_int(z_pos,<span class="stringliteral">"STATUS_S"</span>,jz,-3));
+<a name="l03781"></a>03781           check_nomsg(cpl_table_set_int(z_pos,<span class="stringliteral">"STATUS_O"</span>,jz,-3));
+<a name="l03782"></a>03782       }
+<a name="l03783"></a>03783       sinfo_unwrap_vector(&vw);
+<a name="l03784"></a>03784       sinfo_unwrap_vector(&vs);
+<a name="l03785"></a>03785       sinfo_unwrap_vector(&vo);
+<a name="l03786"></a>03786       sinfo_free_my_vector(&sx);
+<a name="l03787"></a>03787       sinfo_free_my_vector(&sy);
+<a name="l03788"></a>03788       sinfo_free_table(&w_tbl);
+<a name="l03789"></a>03789       sinfo_free_table(&s_tbl);
+<a name="l03790"></a>03790       sinfo_free_table(&o_tbl);
+<a name="l03791"></a>03791     }
+<a name="l03792"></a>03792   }
+<a name="l03793"></a>03793 
+<a name="l03794"></a>03794 
+<a name="l03795"></a>03795   check_nomsg(cpl_table_duplicate_column(z_pos,<span class="stringliteral">"YDIF"</span>,z_pos,<span class="stringliteral">"WDIF"</span>));
+<a name="l03796"></a>03796   check_nomsg(cpl_table_divide_scalar(z_pos,<span class="stringliteral">"YDIF"</span>,dispersion));
+<a name="l03797"></a>03797   <span class="comment">//sinfo_table_column_dump(z_pos,"WAVEC",CPL_TYPE_DOUBLE);</span>
+<a name="l03798"></a>03798   <span class="comment">//sinfo_table_column_dump(z_pos,"STATUS",CPL_TYPE_INT);</span>
+<a name="l03799"></a>03799   <span class="comment">//sinfo_table_column_dump(z_pos,"WDIF",CPL_TYPE_DOUBLE);</span>
+<a name="l03800"></a>03800 
+<a name="l03801"></a>03801   check_nomsg(cpl_table_and_selected_int(z_pos,<span class="stringliteral">"STATUS_S"</span>,CPL_GREATER_THAN,-2));
+<a name="l03802"></a>03802   check_nomsg(cpl_table_and_selected_int(z_pos,<span class="stringliteral">"STATUS_O"</span>,CPL_GREATER_THAN,-2));
+<a name="l03803"></a>03803 
+<a name="l03804"></a>03804   <span class="comment">//check_nomsg(cpl_table_save(z_pos,NULL,NULL,</span>
+<a name="l03805"></a>03805   <span class="comment">//                             "out_z_pos.fits",CPL_IO_DEFAULT));</span>
+<a name="l03806"></a>03806 
+<a name="l03807"></a>03807   <span class="comment">//goto cleanup;</span>
+<a name="l03808"></a>03808 
+<a name="l03809"></a>03809   check_nomsg(z_good=cpl_table_extract_selected(z_pos));
+<a name="l03810"></a>03810   check_nomsg(npos=cpl_table_get_nrow(z_good));
+<a name="l03811"></a>03811   sinfo_free_table(&z_pos);
+<a name="l03812"></a>03812   <span class="keywordflow">if</span>(npos == 0) {
+<a name="l03813"></a>03813     <span class="keywordflow">return</span> 0;
+<a name="l03814"></a>03814   }
+<a name="l03815"></a>03815   check_nomsg(z_pos=cpl_table_duplicate(z_good));
+<a name="l03816"></a>03816   check_nomsg(z_mean = cpl_table_get_column_median(z_pos,<span class="stringliteral">"WDIF"</span>));
+<a name="l03817"></a>03817   check_nomsg(z_sdv  = cpl_table_get_column_stdev(z_pos,<span class="stringliteral">"WDIF"</span>));
+<a name="l03818"></a>03818 
+<a name="l03819"></a>03819   <span class="comment">//check_nomsg(cpl_table_save(z_pos,NULL,NULL,</span>
+<a name="l03820"></a>03820   <span class="comment">//                             "out_z_pos.fits",CPL_IO_DEFAULT));</span>
+<a name="l03821"></a>03821 
+<a name="l03822"></a>03822   check_nomsg(cpl_table_duplicate_column(z_pos,<span class="stringliteral">"CHECK"</span>,
+<a name="l03823"></a>03823                                          z_pos,<span class="stringliteral">"WDIF"</span>));
+<a name="l03824"></a>03824 
+<a name="l03825"></a>03825 
+<a name="l03826"></a>03826   cpl_table_erase_column(z_pos,<span class="stringliteral">"AMPO"</span>);
+<a name="l03827"></a>03827   cpl_table_erase_column(z_pos,<span class="stringliteral">"SIGO"</span>);
+<a name="l03828"></a>03828   cpl_table_erase_column(z_pos,<span class="stringliteral">"AREAO"</span>);
+<a name="l03829"></a>03829   cpl_table_erase_column(z_pos,<span class="stringliteral">"BKGO"</span>);
+<a name="l03830"></a>03830   cpl_table_erase_column(z_pos,<span class="stringliteral">"WAVEO"</span>);
+<a name="l03831"></a>03831   cpl_table_erase_column(z_pos,<span class="stringliteral">"AMPS"</span>);
+<a name="l03832"></a>03832   cpl_table_erase_column(z_pos,<span class="stringliteral">"SIGS"</span>);
+<a name="l03833"></a>03833   cpl_table_erase_column(z_pos,<span class="stringliteral">"AREAS"</span>);
+<a name="l03834"></a>03834   cpl_table_erase_column(z_pos,<span class="stringliteral">"BKGS"</span>);
+<a name="l03835"></a>03835   cpl_table_erase_column(z_pos,<span class="stringliteral">"WAVES"</span>);
+<a name="l03836"></a>03836   cpl_table_erase_column(z_pos,<span class="stringliteral">"STATUS_S"</span>);
+<a name="l03837"></a>03837   cpl_table_erase_column(z_pos,<span class="stringliteral">"STATUS_O"</span>);
+<a name="l03838"></a>03838 
+<a name="l03839"></a>03839   cpl_table_erase_column(z_pos,<span class="stringliteral">"INT"</span>);
+<a name="l03840"></a>03840   cpl_table_erase_column(z_pos,<span class="stringliteral">"INT1"</span>);
+<a name="l03841"></a>03841   cpl_table_erase_column(z_pos,<span class="stringliteral">"INT2"</span>);
+<a name="l03842"></a>03842   cpl_table_erase_column(z_pos,<span class="stringliteral">"ERR"</span>);
+<a name="l03843"></a>03843   cpl_table_erase_column(z_pos,<span class="stringliteral">"POS"</span>);
+<a name="l03844"></a>03844   cpl_table_erase_column(z_pos,<span class="stringliteral">"DIFF"</span>);
+<a name="l03845"></a>03845 
+<a name="l03846"></a>03846   <span class="comment">//check_nomsg(cpl_table_save(z_good,NULL,NULL,</span>
+<a name="l03847"></a>03847   <span class="comment">//                             "out_z_good.fits",CPL_IO_DEFAULT));</span>
+<a name="l03848"></a>03848   <span class="comment">//Do a kappa-sigma clip of the differences of line positions</span>
+<a name="l03849"></a>03849   <span class="comment">//as determined in the object and in the sky spectrum</span>
+<a name="l03850"></a>03850 
+<a name="l03851"></a>03851   sinfo_msg(<span class="stringliteral">"ks-clip1"</span>);
+<a name="l03852"></a>03852   sinfo_msg(<span class="stringliteral">"iter mean (um) sdv (um) mean (pix) sdv (pix)"</span>);
+<a name="l03853"></a>03853   <span class="comment">//sinfo_table_column_dump(z_pos,"WAVEC",CPL_TYPE_DOUBLE);</span>
+<a name="l03854"></a>03854   <span class="comment">//sinfo_table_column_dump(z_pos,"WDIF",CPL_TYPE_DOUBLE);</span>
+<a name="l03855"></a>03855 
+<a name="l03856"></a>03856   <span class="keywordflow">for</span> (iq = 0;iq<XCOR_YSHIFT_KS_CLIP;iq++) {
+<a name="l03857"></a>03857     <span class="comment">//sinfo_msg("nval=%d",cpl_table_get_nrow(z_pos));</span>
+<a name="l03858"></a>03858     sinfo_msg(<span class="stringliteral">"  %d  %3.2g   %3.2g  %5.4g     %5.4g"</span>,
+<a name="l03859"></a>03859                iq,z_mean,z_sdv,z_mean/dispersion,z_sdv/dispersion);
+<a name="l03860"></a>03860     <span class="comment">//z_good = where(abs(g_diff-z_mean) <= 2*z_sdv);</span>
+<a name="l03861"></a>03861 
+<a name="l03862"></a>03862     check_nomsg(cpl_table_subtract_scalar(z_pos,<span class="stringliteral">"CHECK"</span>,z_mean));
+<a name="l03863"></a>03863     check_nomsg(cpl_table_duplicate_column(z_pos,<span class="stringliteral">"CHECKW"</span>,z_pos,<span class="stringliteral">"CHECK"</span>));
+<a name="l03864"></a>03864     check_nomsg(cpl_table_multiply_columns(z_pos,<span class="stringliteral">"CHECKW"</span>,<span class="stringliteral">"CHECK"</span>));
+<a name="l03865"></a>03865     check_nomsg(cpl_table_power_column(z_pos,<span class="stringliteral">"CHECKW"</span>,0.5));
+<a name="l03866"></a>03866     check_nomsg(cpl_table_add_scalar(z_pos,<span class="stringliteral">"CHECK"</span>,z_mean));
+<a name="l03867"></a>03867     check_nomsg(cpl_table_and_selected_double(z_pos,<span class="stringliteral">"CHECKW"</span>,
+<a name="l03868"></a>03868                                               CPL_NOT_GREATER_THAN,2*z_sdv));
+<a name="l03869"></a>03869     sinfo_free_table(&z_good);
+<a name="l03870"></a>03870     check_nomsg(z_good=cpl_table_extract_selected(z_pos));
+<a name="l03871"></a>03871     <span class="comment">//sinfo_msg("ngood=%d",cpl_table_get_nrow(z_good));</span>
+<a name="l03872"></a>03872     check_nomsg(cpl_table_select_all(z_pos));
+<a name="l03873"></a>03873     <span class="comment">//z_mean = median(g_diff[z_good]);</span>
+<a name="l03874"></a>03874     <span class="comment">//z_sdv = stddev(g_diff[z_good]);</span>
+<a name="l03875"></a>03875     check_nomsg(z_mean = cpl_table_get_column_median(z_good,<span class="stringliteral">"WDIF"</span>));
+<a name="l03876"></a>03876     <span class="keywordflow">if</span>(nfit>1) {
+<a name="l03877"></a>03877     check_nomsg(z_sdv  = cpl_table_get_column_stdev(z_good,<span class="stringliteral">"WDIF"</span>));
+<a name="l03878"></a>03878     } <span class="keywordflow">else</span> {
+<a name="l03879"></a>03879       z_sdv=0;
+<a name="l03880"></a>03880     }
+<a name="l03881"></a>03881     sinfo_free_table(&z_good);
+<a name="l03882"></a>03882     check_nomsg(cpl_table_erase_column(z_pos,<span class="stringliteral">"CHECKW"</span>));
+<a name="l03883"></a>03883 
+<a name="l03884"></a>03884   }
+<a name="l03885"></a>03885   <span class="comment">/* do a poly fit of wdif versus wave*/</span>
+<a name="l03886"></a>03886   <span class="comment">/*</span>
+<a name="l03887"></a>03887 <span class="comment">  for (iq = 0; iq<3; iq++) {</span>
+<a name="l03888"></a>03888 <span class="comment">    // sinfo_msg("%d %f %f",iq,mean(zfit),zsdv);</span>
+<a name="l03889"></a>03889 <span class="comment">    par1 = poly_fit(g_lam[z_good],g_diff[z_good],poly_n);</span>
+<a name="l03890"></a>03890 <span class="comment">    z_fit = g_diff*0.;</span>
+<a name="l03891"></a>03891 <span class="comment">    for (ii=0;ii<poly_n) z_fit = z_fit + par1[ii]*g_lam^ii;</span>
+<a name="l03892"></a>03892 <span class="comment">    z_res = g_diff-z_fit;</span>
+<a name="l03893"></a>03893 <span class="comment">    z_sdv = stddev(z_res[zgood]);</span>
+<a name="l03894"></a>03894 <span class="comment">    z_good = where(abs(z_res) le 3*z_sdv);</span>
+<a name="l03895"></a>03895 <span class="comment">  }</span>
+<a name="l03896"></a>03896 <span class="comment">  */</span>
+<a name="l03897"></a>03897   cpl_table_select_all(z_pos);
+<a name="l03898"></a>03898   check_nomsg(cpl_table_new_column(z_pos,<span class="stringliteral">"ZFIT"</span>,CPL_TYPE_DOUBLE));
+<a name="l03899"></a>03899   check_nomsg(nfit=cpl_table_get_nrow(z_pos));
+<a name="l03900"></a>03900   check_nomsg(cpl_table_fill_column_window(z_pos,<span class="stringliteral">"ZFIT"</span>,0,nfit,0));
+<a name="l03901"></a>03901   <span class="comment">//check_nomsg(cpl_table_save(z_pos,NULL,NULL,</span>
+<a name="l03902"></a>03902   <span class="comment">//                             "out_z_pos2.fits",CPL_IO_DEFAULT));</span>
+<a name="l03903"></a>03903   check_nomsg(z_good=cpl_table_duplicate(z_pos));
+<a name="l03904"></a>03904 
+<a name="l03905"></a>03905   <span class="comment">//Do a fit of a uniform function to the residuals line position differences</span>
+<a name="l03906"></a>03906   sinfo_msg(<span class="stringliteral">"ks-clip2"</span>);
+<a name="l03907"></a>03907   sinfo_msg(<span class="stringliteral">"iter mean (um) sdv (um) mean (pix) sdv (pix)"</span>);
+<a name="l03908"></a>03908   check_nomsg(cpl_table_select_all(z_good));
+<a name="l03909"></a>03909   <span class="comment">//sinfo_table_column_dump(z_pos,"WDIF",CPL_TYPE_DOUBLE);</span>
+<a name="l03910"></a>03910   <span class="keywordflow">for</span>(iq=0;iq<XCOR_YSHIFT_KS_CLIP;iq++) {
+<a name="l03911"></a>03911     <span class="comment">//cpl_table_dump(z_pos,0,cpl_table_get_nrow(z_pos),stdout);</span>
+<a name="l03912"></a>03912     check_nomsg(nfit=cpl_table_get_nrow(z_good));
+<a name="l03913"></a>03913     <span class="comment">//sinfo_msg("nfit=%d",nfit);</span>
+<a name="l03914"></a>03914     <span class="keywordflow">if</span>(nfit>0) {
+<a name="l03915"></a>03915     check_nomsg(vx=cpl_vector_wrap(nfit,
+<a name="l03916"></a>03916                    cpl_table_get_data_double(z_good,<span class="stringliteral">"WAVE"</span>)));
+<a name="l03917"></a>03917     check_nomsg(vy=cpl_vector_wrap(nfit,
+<a name="l03918"></a>03918                    cpl_table_get_data_double(z_good,<span class="stringliteral">"WDIF"</span>)));
+<a name="l03919"></a>03919     check_nomsg(cfit=sinfo_polynomial_fit_1d_create(vx,vy,0,&mse));
+<a name="l03920"></a>03920     pows[0]=0;
+<a name="l03921"></a>03921     pows[1]=0;
+<a name="l03922"></a>03922     check_nomsg(zfit=cpl_polynomial_get_coeff(cfit,pows));
+<a name="l03923"></a>03923     sinfo_free_polynomial(&cfit);
+<a name="l03924"></a>03924     <span class="comment">//sinfo_msg("coeff 0=%g um %g pix",zfit,zfit/dispersion);</span>
+<a name="l03925"></a>03925 
+<a name="l03926"></a>03926     <span class="comment">//computes residuals=difference-fit and their standard deviation</span>
+<a name="l03927"></a>03927     <span class="comment">//and then do a kappa-sigma clip of outliers (out of 3 sigma)</span>
+<a name="l03928"></a>03928     check_nomsg(cpl_table_fill_column_window(z_good,<span class="stringliteral">"ZFIT"</span>,0,nfit,zfit));
+<a name="l03929"></a>03929     check_nomsg(cpl_table_duplicate_column(z_good,<span class="stringliteral">"WRES"</span>,z_good,<span class="stringliteral">"WDIF"</span>));
+<a name="l03930"></a>03930     check_nomsg(cpl_table_subtract_columns(z_good,<span class="stringliteral">"WRES"</span>,<span class="stringliteral">"ZFIT"</span>));
+<a name="l03931"></a>03931     <span class="keywordflow">if</span>(nfit>1) {
+<a name="l03932"></a>03932       <span class="comment">//sinfo_msg("nfit=%d",nfit);</span>
+<a name="l03933"></a>03933       <span class="comment">//cpl_table_dump(z_good,0,nfit,stdout);</span>
+<a name="l03934"></a>03934       check_nomsg(z_sdv=cpl_table_get_column_stdev(z_good,<span class="stringliteral">"WRES"</span>));
+<a name="l03935"></a>03935       <span class="comment">//sinfo_msg("z_sdv=%f",z_sdv);</span>
+<a name="l03936"></a>03936     } <span class="keywordflow">else</span> {
+<a name="l03937"></a>03937       z_sdv=0;
+<a name="l03938"></a>03938     }
+<a name="l03939"></a>03939     check_nomsg(z_mean=cpl_table_get_column_mean(z_good,<span class="stringliteral">"WDIF"</span>));
+<a name="l03940"></a>03940 
+<a name="l03941"></a>03941     sinfo_msg(<span class="stringliteral">"  %d  %3.2g   %3.2g  %5.4g     %5.4g"</span>,
+<a name="l03942"></a>03942               iq,z_mean,z_sdv,z_mean/dispersion,z_sdv/dispersion);
+<a name="l03943"></a>03943 
+<a name="l03944"></a>03944     check_nomsg(nfit=cpl_table_get_nrow(z_pos));
+<a name="l03945"></a>03945     check_nomsg(cpl_table_fill_column_window(z_pos,<span class="stringliteral">"ZFIT"</span>,0,nfit,zfit));
+<a name="l03946"></a>03946     check_nomsg(cpl_table_duplicate_column(z_pos,<span class="stringliteral">"WRES"</span>,z_pos,<span class="stringliteral">"WDIF"</span>));
+<a name="l03947"></a>03947     check_nomsg(cpl_table_subtract_columns(z_pos,<span class="stringliteral">"WRES"</span>,<span class="stringliteral">"ZFIT"</span>));
+<a name="l03948"></a>03948 
+<a name="l03949"></a>03949     check_nomsg(cpl_table_multiply_columns(z_pos,<span class="stringliteral">"WRES"</span>,<span class="stringliteral">"WRES"</span>));
+<a name="l03950"></a>03950     check_nomsg(cpl_table_power_column(z_pos,<span class="stringliteral">"WRES"</span>,0.5));
+<a name="l03951"></a>03951     <span class="comment">//cpl_table_dump(z_pos,0,cpl_table_get_nrow(z_pos),stdout);</span>
+<a name="l03952"></a>03952     <span class="comment">/*</span>
+<a name="l03953"></a>03953 <span class="comment">    sinfo_msg("min=%g max=%g ndat=%d",</span>
+<a name="l03954"></a>03954 <span class="comment">              cpl_table_get_column_min(z_pos,"WRES"),</span>
+<a name="l03955"></a>03955 <span class="comment">              cpl_table_get_column_max(z_pos,"WRES"),</span>
+<a name="l03956"></a>03956 <span class="comment">              cpl_table_get_nrow(z_pos));</span>
+<a name="l03957"></a>03957 <span class="comment">    */</span>
+<a name="l03958"></a>03958     check_nomsg(cpl_table_and_selected_double(z_pos,<span class="stringliteral">"WRES"</span>,
+<a name="l03959"></a>03959                                               CPL_NOT_GREATER_THAN,3*z_sdv));
+<a name="l03960"></a>03960 
+<a name="l03961"></a>03961     check_nomsg(sinfo_free_table(&z_good));
+<a name="l03962"></a>03962     check_nomsg(z_good=cpl_table_extract_selected(z_pos));
+<a name="l03963"></a>03963 
+<a name="l03964"></a>03964 
+<a name="l03965"></a>03965     check_nomsg(cpl_table_select_all(z_pos));
+<a name="l03966"></a>03966     check_nomsg(cpl_table_select_all(z_good));
+<a name="l03967"></a>03967     check_nomsg(cpl_table_erase_column(z_good,<span class="stringliteral">"WRES"</span>));
+<a name="l03968"></a>03968     check_nomsg(cpl_table_erase_column(z_pos,<span class="stringliteral">"WRES"</span>));
+<a name="l03969"></a>03969 
+<a name="l03970"></a>03970     sinfo_unwrap_vector(&vx);
+<a name="l03971"></a>03971     sinfo_unwrap_vector(&vy);
+<a name="l03972"></a>03972 
+<a name="l03973"></a>03973     }
+<a name="l03974"></a>03974 
+<a name="l03975"></a>03975   }
+<a name="l03976"></a>03976   <span class="comment">//sinfo_msg(">>mean=%g",cpl_table_get_column_mean(z_good,"WDIF"));</span>
+<a name="l03977"></a>03977 
+<a name="l03978"></a>03978   <span class="comment">//check_nomsg(cpl_table_save(z_good,NULL,NULL,</span>
+<a name="l03979"></a>03979   <span class="comment">//                             "out_z_pos3.fits",CPL_IO_DEFAULT));</span>
+<a name="l03980"></a>03980   sinfo_unwrap_vector(&vx);
+<a name="l03981"></a>03981   sinfo_unwrap_vector(&vy);
+<a name="l03982"></a>03982   sinfo_free_polynomial(&cfit);
+<a name="l03983"></a>03983   sinfo_free_table(&z);
+<a name="l03984"></a>03984   sinfo_free_table(&z_pos);
+<a name="l03985"></a>03985   sinfo_free_table(&z_good);
+<a name="l03986"></a>03986 
+<a name="l03987"></a>03987 
+<a name="l03988"></a>03988   <span class="keywordflow">return</span> zfit;
+<a name="l03989"></a>03989  cleanup:
+<a name="l03990"></a>03990 
+<a name="l03991"></a>03991   sinfo_free_table(&z_good);
+<a name="l03992"></a>03992   sinfo_free_table(&z);
+<a name="l03993"></a>03993   sinfo_free_table(&z_diff);
+<a name="l03994"></a>03994   sinfo_free_table(&tmp_sky);
+<a name="l03995"></a>03995   sinfo_free_table(&z_pos);
+<a name="l03996"></a>03996   sinfo_unwrap_vector(&vw);
+<a name="l03997"></a>03997   sinfo_unwrap_vector(&vs);
+<a name="l03998"></a>03998   sinfo_unwrap_vector(&vo);
+<a name="l03999"></a>03999   sinfo_free_my_vector(&sx);
+<a name="l04000"></a>04000   sinfo_free_my_vector(&sy);
+<a name="l04001"></a>04001   sinfo_unwrap_vector(&vx);
+<a name="l04002"></a>04002   sinfo_unwrap_vector(&vy);
+<a name="l04003"></a>04003   sinfo_free_table(&w_tbl);
+<a name="l04004"></a>04004   sinfo_free_table(&s_tbl);
+<a name="l04005"></a>04005   sinfo_free_table(&o_tbl);
+<a name="l04006"></a>04006   sinfo_free_polynomial(&cfit);
+<a name="l04007"></a>04007 
+<a name="l04008"></a>04008   <span class="keywordflow">return</span> 0;
+<a name="l04009"></a>04009 
+<a name="l04010"></a>04010 
+<a name="l04011"></a>04011 }
+<a name="l04012"></a>04012 
+<a name="l04013"></a>04013 
+<a name="l04014"></a>04014 
+<a name="l04015"></a>04015 
+<a name="l04028"></a>04028 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l04029"></a>04029 sinfo_table_set_nan_out_min_max(cpl_table** t,
+<a name="l04030"></a>04030                                 <span class="keyword">const</span> <span class="keywordtype">char</span>* c,
+<a name="l04031"></a>04031                                 <span class="keyword">const</span> <span class="keywordtype">double</span> min,
+<a name="l04032"></a>04032                                 <span class="keyword">const</span> <span class="keywordtype">double</span> max)
+<a name="l04033"></a>04033 
+<a name="l04034"></a>04034 {
+<a name="l04035"></a>04035 
+<a name="l04036"></a>04036   <span class="keywordtype">int</span> sz=0;
+<a name="l04037"></a>04037   <span class="keywordtype">int</span> i=0;
+<a name="l04038"></a>04038   <span class="keywordtype">double</span>* pt=NULL;
+<a name="l04039"></a>04039 
+<a name="l04040"></a>04040   check_nomsg(sz=cpl_table_get_nrow(*t));
+<a name="l04041"></a>04041   check_nomsg(pt=cpl_table_get_data_double(*t,c));
+<a name="l04042"></a>04042   <span class="keywordflow">for</span>(i=0;i<sz;i++) {
+<a name="l04043"></a>04043     <span class="keywordflow">if</span>(pt[i] < min || pt[i] > max) {
+<a name="l04044"></a>04044       check_nomsg(cpl_table_set_invalid(*t ,c,i));
+<a name="l04045"></a>04045     }
+<a name="l04046"></a>04046   }
+<a name="l04047"></a>04047 
+<a name="l04048"></a>04048   <span class="keywordflow">return</span> 0;
+<a name="l04049"></a>04049 
+<a name="l04050"></a>04050  cleanup:
+<a name="l04051"></a>04051 
+<a name="l04052"></a>04052   <span class="keywordflow">return</span> -1;
+<a name="l04053"></a>04053 
+<a name="l04054"></a>04054 
+<a name="l04055"></a>04055 }
+<a name="l04056"></a>04056 
+<a name="l04066"></a>04066 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l04067"></a>04067 sinfo_table_flag_nan(cpl_table** t,<span class="keyword">const</span> <span class="keywordtype">char</span>* label)
+<a name="l04068"></a>04068 {
+<a name="l04069"></a>04069 
+<a name="l04070"></a>04070   <span class="keywordtype">int</span> sz=0;
+<a name="l04071"></a>04071   <span class="keywordtype">int</span> i=0;
+<a name="l04072"></a>04072   <span class="keywordtype">double</span>* pt=NULL;
+<a name="l04073"></a>04073 
+<a name="l04074"></a>04074   check_nomsg(sz=cpl_table_get_nrow(*t));
+<a name="l04075"></a>04075   check_nomsg(pt=cpl_table_get_data_double(*t,label));
+<a name="l04076"></a>04076   <span class="keywordflow">for</span>(i=0;i<sz;i++) {
+<a name="l04077"></a>04077     <span class="keywordflow">if</span>(<a class="code" href="group__irplib__utils.html#ga804bfc739b5d55f9797ab881b1034ae4" title="portable isnan">irplib_isnan</a>(pt[i])) {
+<a name="l04078"></a>04078       check_nomsg(cpl_table_set_invalid(*t ,label,i));
+<a name="l04079"></a>04079     }
+<a name="l04080"></a>04080   }
+<a name="l04081"></a>04081 
+<a name="l04082"></a>04082   <span class="keywordflow">return</span> 0;
+<a name="l04083"></a>04083 
+<a name="l04084"></a>04084  cleanup:
+<a name="l04085"></a>04085 
+<a name="l04086"></a>04086   <span class="keywordflow">return</span> -1;
+<a name="l04087"></a>04087 }
+<a name="l04088"></a>04088 
+<a name="l04098"></a>04098 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l04099"></a>04099 sinfo_table_sky_obj_flag_nan(cpl_table** s,cpl_table** o, cpl_table** w)
+<a name="l04100"></a>04100 {
+<a name="l04101"></a>04101 
+<a name="l04102"></a>04102   <span class="keywordtype">int</span> no=0;
+<a name="l04103"></a>04103   <span class="keywordtype">int</span> ns=0;
+<a name="l04104"></a>04104   <span class="keywordtype">int</span> nw=0;
+<a name="l04105"></a>04105   <span class="keywordtype">int</span> ni=0;
+<a name="l04106"></a>04106 
+<a name="l04107"></a>04107   <span class="keywordtype">int</span> i=0;
+<a name="l04108"></a>04108   <span class="keywordtype">double</span>* po=NULL;
+<a name="l04109"></a>04109   <span class="keywordtype">double</span>* ps=NULL;
+<a name="l04110"></a>04110   <span class="keywordtype">double</span>* pw=NULL;
+<a name="l04111"></a>04111 
+<a name="l04112"></a>04112   check_nomsg(no=cpl_table_get_nrow(*o));
+<a name="l04113"></a>04113   check_nomsg(ns=cpl_table_get_nrow(*s));
+<a name="l04114"></a>04114   check_nomsg(nw=cpl_table_get_nrow(*w));
+<a name="l04115"></a>04115   <span class="keywordflow">if</span>(no != ns || ns != nw || no != nw) {
+<a name="l04116"></a>04116     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"different input tables sizes"</span>);
+<a name="l04117"></a>04117     <span class="keywordflow">goto</span> cleanup;
+<a name="l04118"></a>04118   }
+<a name="l04119"></a>04119   check_nomsg(po=cpl_table_get_data_double(*o,<span class="stringliteral">"INT"</span>));
+<a name="l04120"></a>04120   check_nomsg(ps=cpl_table_get_data_double(*s,<span class="stringliteral">"INT"</span>));
+<a name="l04121"></a>04121   check_nomsg(pw=cpl_table_get_data_double(*w,<span class="stringliteral">"WAVE"</span>));
+<a name="l04122"></a>04122 
+<a name="l04123"></a>04123   <span class="keywordflow">for</span>(i=0;i<no;i++) {
+<a name="l04124"></a>04124     <span class="keywordflow">if</span>( (0==cpl_table_is_valid(*o,<span class="stringliteral">"INT"</span>,i)) ||
+<a name="l04125"></a>04125         <a class="code" href="group__irplib__utils.html#ga804bfc739b5d55f9797ab881b1034ae4" title="portable isnan">irplib_isnan</a>(po[i]) || <a class="code" href="group__irplib__utils.html#ga804bfc739b5d55f9797ab881b1034ae4" title="portable isnan">irplib_isnan</a>(ps[i]) || <a class="code" href="group__irplib__utils.html#ga804bfc739b5d55f9797ab881b1034ae4" title="portable isnan">irplib_isnan</a>(pw[i]) ) {
+<a name="l04126"></a>04126       check_nomsg(cpl_table_set_invalid(*o ,<span class="stringliteral">"INT"</span>,i));
+<a name="l04127"></a>04127       check_nomsg(cpl_table_set_invalid(*s ,<span class="stringliteral">"INT"</span>,i));
+<a name="l04128"></a>04128       check_nomsg(cpl_table_set_invalid(*w ,<span class="stringliteral">"WAVE"</span>,i));
+<a name="l04129"></a>04129       <span class="comment">//sinfo_msg_debug("Flagged raw %d",i);</span>
+<a name="l04130"></a>04130       ni++;
+<a name="l04131"></a>04131     }
+<a name="l04132"></a>04132   }
+<a name="l04133"></a>04133 
+<a name="l04134"></a>04134   <span class="keywordflow">return</span> no-ni;
+<a name="l04135"></a>04135 
+<a name="l04136"></a>04136  cleanup:
+<a name="l04137"></a>04137 
+<a name="l04138"></a>04138   <span class="keywordflow">return</span> -1;
+<a name="l04139"></a>04139 }
+<a name="l04140"></a>04140 
+<a name="l04141"></a>04141 <span class="comment">/*</span>
+<a name="l04142"></a>04142 <span class="comment">static void</span>
+<a name="l04143"></a>04143 <span class="comment">sinfo_shift_sky(const int x,const int y)</span>
+<a name="l04144"></a>04144 <span class="comment">{</span>
+<a name="l04145"></a>04145 <span class="comment"></span>
+<a name="l04146"></a>04146 <span class="comment">  //To remove compilation warnings</span>
+<a name="l04147"></a>04147 <span class="comment">  ck0_nomsg(x);</span>
+<a name="l04148"></a>04148 <span class="comment">  ck0_nomsg(y);</span>
+<a name="l04149"></a>04149 <span class="comment"></span>
+<a name="l04150"></a>04150 <span class="comment">  // shift sky spectrum of a given amount</span>
+<a name="l04151"></a>04151 <span class="comment">  if (max(abs(z_fit))/cdelts < 0.01) {</span>
+<a name="l04152"></a>04152 <span class="comment">    sinfo_msg("shift <0.01 pixels will not be applied");</span>
+<a name="l04153"></a>04153 <span class="comment">  } else {</span>
+<a name="l04154"></a>04154 <span class="comment">    sinfo_msg("shifting sky cube by mean of %f pix wrt object",</span>
+<a name="l04155"></a>04155 <span class="comment">             cpl_table_column_mean(z_fit,"VALUE")/cdelto);</span>
+<a name="l04156"></a>04156 <span class="comment">    sinfo_msg("this will take a couple of minutes...");</span>
+<a name="l04157"></a>04157 <span class="comment">    z_good = where(finite(int_sky));</span>
+<a name="l04158"></a>04158 <span class="comment">    new_sky = spline(lambda[z_good]-z_mean,int_sky[z_good],lambda);</span>
+<a name="l04159"></a>04159 <span class="comment">    int_sky = new_sky;</span>
+<a name="l04160"></a>04160 <span class="comment">    sky_out = dblarr(xsize,ysize,zsize) + !values.f_nan;</span>
+<a name="l04161"></a>04161 <span class="comment">    for (ix=0; ix<xsize;ix++) {</span>
+<a name="l04162"></a>04162 <span class="comment">      for (iy=0;iy<ysize;iy++) {</span>
+<a name="l04163"></a>04163 <span class="comment">    old_sky = reform(sky[ix,iy,*]);</span>
+<a name="l04164"></a>04164 <span class="comment">    z_good = where(finite(old_sky),z_good_i);</span>
+<a name="l04165"></a>04165 <span class="comment">    if (z_good_i > 0) {</span>
+<a name="l04166"></a>04166 <span class="comment">          new_sky= spline(lambda[z_good]-z_fit[z_good],old_sky[z_good],lambda);</span>
+<a name="l04167"></a>04167 <span class="comment">          new_fin= where(finite(new_sky,/infinity) ||</span>
+<a name="l04168"></a>04168 <span class="comment">                          finite(old_sky,/nan),newfin_i);</span>
+<a name="l04169"></a>04169 <span class="comment">      if (new_fin_i > 0) new_sky[new_fin] = !values.f_nan;</span>
+<a name="l04170"></a>04170 <span class="comment">      sky_out[ix,iy,*] = new_sky;</span>
+<a name="l04171"></a>04171 <span class="comment">    }</span>
+<a name="l04172"></a>04172 <span class="comment">      }</span>
+<a name="l04173"></a>04173 <span class="comment">    }</span>
+<a name="l04174"></a>04174 <span class="comment">    sky = sky_out;</span>
+<a name="l04175"></a>04175 <span class="comment">  }</span>
+<a name="l04176"></a>04176 <span class="comment"> cleanup:</span>
+<a name="l04177"></a>04177 <span class="comment">  return;</span>
+<a name="l04178"></a>04178 <span class="comment"></span>
+<a name="l04179"></a>04179 <span class="comment">}</span>
+<a name="l04180"></a>04180 <span class="comment">  */</span>
+<a name="l04207"></a>04207 <span class="keywordtype">void</span>
+<a name="l04208"></a>04208 sinfo_optimise_sky_sub(<span class="keyword">const</span> <span class="keywordtype">double</span> wtol,
+<a name="l04209"></a>04209                        <span class="keyword">const</span> <span class="keywordtype">double</span> line_hw,
+<a name="l04210"></a>04210                        <span class="keyword">const</span> <span class="keywordtype">int</span> method,
+<a name="l04211"></a>04211                        <span class="keyword">const</span> <span class="keywordtype">int</span> do_rot,
+<a name="l04212"></a>04212                        cpl_table* lrange,
+<a name="l04213"></a>04213                        cpl_table* lambda,
+<a name="l04214"></a>04214                        cpl_table* lr41,
+<a name="l04215"></a>04215                        cpl_table* lr52,
+<a name="l04216"></a>04216                        cpl_table* lr63,
+<a name="l04217"></a>04217                        cpl_table* lr74,
+<a name="l04218"></a>04218                        cpl_table* lr02,
+<a name="l04219"></a>04219                        cpl_table* lr85,
+<a name="l04220"></a>04220                        cpl_table* lr20,
+<a name="l04221"></a>04221                        cpl_table* lr31,
+<a name="l04222"></a>04222                        cpl_table* lr42,
+<a name="l04223"></a>04223                        cpl_table* lr53,
+<a name="l04224"></a>04224                        cpl_table* lr64,
+<a name="l04225"></a>04225                        cpl_table* lr75,
+<a name="l04226"></a>04226                        cpl_table* lr86,
+<a name="l04227"></a>04227                        cpl_table* lr97,
+<a name="l04228"></a>04228                        cpl_table* lr00,
+<a name="l04229"></a>04229                        cpl_table** int_obj,
+<a name="l04230"></a>04230                        cpl_table** int_sky,
+<a name="l04231"></a>04231                        cpl_table** rscale)
+<a name="l04232"></a>04232 
+<a name="l04233"></a>04233 {
+<a name="l04234"></a>04234 
+<a name="l04235"></a>04235   <span class="keywordtype">int</span> npixw=2*line_hw; <span class="comment">//full width in pixels of unresolved emission line</span>
+<a name="l04236"></a>04236   cpl_array* do_hk=NULL;
+<a name="l04237"></a>04237   cpl_array* rfit=NULL;
+<a name="l04238"></a>04238   <span class="keywordtype">int</span> i=0;
+<a name="l04239"></a>04239   cpl_table* sky_lr=NULL;
+<a name="l04240"></a>04240   cpl_table* obj_lr=NULL;
+<a name="l04241"></a>04241   cpl_table* wav_lr=NULL;
+<a name="l04242"></a>04242   <span class="keywordtype">double</span> sky_med=0;
+<a name="l04243"></a>04243   <span class="keywordtype">double</span> sky_sdv=0;
+<a name="l04244"></a>04244   <span class="keywordtype">int</span> lr41_i=0;
+<a name="l04245"></a>04245   <span class="keywordtype">int</span> lr52_i=0;
+<a name="l04246"></a>04246   <span class="keywordtype">int</span> lr63_i=0;
+<a name="l04247"></a>04247   <span class="keywordtype">int</span> lr74_i=0;
+<a name="l04248"></a>04248   <span class="keywordtype">int</span> lr02_i=0;
+<a name="l04249"></a>04249   <span class="keywordtype">int</span> lr85_i=0;
+<a name="l04250"></a>04250   <span class="keywordtype">int</span> lr20_i=0;
+<a name="l04251"></a>04251   <span class="keywordtype">int</span> lr31_i=0;
+<a name="l04252"></a>04252   <span class="keywordtype">int</span> lr42_i=0;
+<a name="l04253"></a>04253   <span class="keywordtype">int</span> lr53_i=0;
+<a name="l04254"></a>04254   <span class="keywordtype">int</span> lr64_i=0;
+<a name="l04255"></a>04255   <span class="keywordtype">int</span> lr75_i=0;
+<a name="l04256"></a>04256   <span class="keywordtype">int</span> lr86_i=0;
+<a name="l04257"></a>04257   <span class="keywordtype">int</span> lr97_i=0;
+<a name="l04258"></a>04258   <span class="keywordtype">int</span> lr00_i=0;
+<a name="l04259"></a>04259 
+<a name="l04260"></a>04260   <span class="keywordtype">int</span> xxx1_i=0;
+<a name="l04261"></a>04261   <span class="keywordtype">int</span> status=0;
+<a name="l04262"></a>04262   <span class="keywordtype">int</span> finite_pix_i=0;
+<a name="l04263"></a>04263   <span class="keywordtype">double</span> sky_thresh=0.;
+<a name="l04264"></a>04264 
+<a name="l04265"></a>04265   cpl_table* rat_sky=NULL;
+<a name="l04266"></a>04266 
+<a name="l04267"></a>04267   cpl_table* xxx1=NULL;
+<a name="l04268"></a>04268   cpl_table* xxx2=NULL;
+<a name="l04269"></a>04269   cpl_table* xxx1_sub=NULL;
+<a name="l04270"></a>04270   cpl_table* line_regions=NULL;
+<a name="l04271"></a>04271   cpl_table* cont_regions=NULL;
+<a name="l04272"></a>04272   <span class="keywordtype">int</span> line_i=0;
+<a name="l04273"></a>04273   <span class="keywordtype">int</span> cont_i=0;
+<a name="l04274"></a>04274   <span class="keywordtype">double</span> fmed=0;
+<a name="l04275"></a>04275   <span class="keywordtype">double</span> fsdv=0;
+<a name="l04276"></a>04276   cpl_table* fline_res=NULL;
+<a name="l04277"></a>04277   <span class="keywordtype">int</span> fclip_i=0;
+<a name="l04278"></a>04278   <span class="keywordtype">int</span> fline_i=0;
+<a name="l04279"></a>04279   cpl_table* rscale0=NULL;
+<a name="l04280"></a>04280   <span class="keywordtype">double</span> r=0;
+<a name="l04281"></a>04281   cpl_table* obj_cont=NULL;
+<a name="l04282"></a>04282   cpl_table* sky_cont=NULL;
+<a name="l04283"></a>04283   cpl_table* obj_line=NULL;
+<a name="l04284"></a>04284   cpl_table* sky_line=NULL;
+<a name="l04285"></a>04285 
+<a name="l04286"></a>04286 
+<a name="l04287"></a>04287   <span class="comment">//Rotational parameters</span>
+<a name="l04288"></a>04288   <span class="keywordtype">int</span> low_pos_i=0;
+<a name="l04289"></a>04289   <span class="keywordtype">int</span> med_pos_i=0;
+<a name="l04290"></a>04290   <span class="keywordtype">int</span> hi_pos_i=0;
+<a name="l04291"></a>04291 
+<a name="l04292"></a>04292   cpl_table* finite_pix=NULL;
+<a name="l04293"></a>04293   cpl_table* tmp_tbl=NULL;
+<a name="l04294"></a>04294 
+<a name="l04295"></a>04295   cpl_table* low_scale=NULL;
+<a name="l04296"></a>04296   cpl_table* med_scale=NULL;
+<a name="l04297"></a>04297   cpl_table* hi_regions=NULL;
+<a name="l04298"></a>04298 
+<a name="l04299"></a>04299   cpl_table* low_regions=NULL;
+<a name="l04300"></a>04300   cpl_table* med_regions=NULL;
+<a name="l04301"></a>04301 
+<a name="l04302"></a>04302 
+<a name="l04303"></a>04303   cpl_table* low_pos=NULL;
+<a name="l04304"></a>04304   cpl_table* med_pos=NULL;
+<a name="l04305"></a>04305   cpl_table* hi_pos=NULL;
+<a name="l04306"></a>04306   cpl_table* llr_xxx1=NULL;
+<a name="l04307"></a>04307 
+<a name="l04308"></a>04308   <span class="keywordtype">double</span> rhi=0;
+<a name="l04309"></a>04309   <span class="keywordtype">double</span> rmed=0;
+<a name="l04310"></a>04310   <span class="keywordtype">double</span> rlow=0;
+<a name="l04311"></a>04311 
+<a name="l04312"></a>04312   <span class="keywordtype">double</span> min_lrange=0;
+<a name="l04313"></a>04313   <span class="keywordtype">double</span> max_lrange=0;
+<a name="l04314"></a>04314 
+<a name="l04315"></a>04315   <span class="keywordtype">int</span> nrow=0;
+<a name="l04316"></a>04316 
+<a name="l04317"></a>04317 
+<a name="l04318"></a>04318   <span class="keywordtype">double</span> w_rot_low[NROT]={1.00852,1.03757,1.09264,1.15388,1.22293,
+<a name="l04319"></a>04319                           1.30216,1.45190,1.52410,1.60308,1.69037,
+<a name="l04320"></a>04320                           1.78803,2.02758,2.18023,1.02895,1.08343,
+<a name="l04321"></a>04321                           1.14399,1.21226,1.29057,1.43444,1.50555,
+<a name="l04322"></a>04322                           1.58333,1.66924,1.76532,2.00082,2.15073};
+<a name="l04323"></a>04323 
+<a name="l04324"></a>04324 
+<a name="l04325"></a>04325   <span class="keywordtype">double</span> w_rot_med[NROT]={1.00282,1.02139,1.04212,1.07539,1.09753,
+<a name="l04326"></a>04326                           1.13542,1.15917,1.20309,1.22870,1.28070,
+<a name="l04327"></a>04327                           1.30853,1.41861,1.46048,1.48877,1.53324,
+<a name="l04328"></a>04328                           1.56550,1.61286,1.65024,1.70088,1.74500,
+<a name="l04329"></a>04329                           1.79940,1.97719,2.04127,2.12496,2.19956};
+<a name="l04330"></a>04330 
+<a name="l04331"></a>04331 
+<a name="l04332"></a>04332 
+<a name="l04333"></a>04333   check_nomsg(do_hk = cpl_array_new(NBOUND+1,CPL_TYPE_INT));
+<a name="l04334"></a>04334   check_nomsg(rfit  = cpl_array_new(NBOUND+1,CPL_TYPE_DOUBLE));
+<a name="l04335"></a>04335 
+<a name="l04336"></a>04336   lr41_i=cpl_table_get_nrow(lr41);
+<a name="l04337"></a>04337   lr52_i=cpl_table_get_nrow(lr52);
+<a name="l04338"></a>04338   lr63_i=cpl_table_get_nrow(lr63);
+<a name="l04339"></a>04339   lr74_i=cpl_table_get_nrow(lr74);
+<a name="l04340"></a>04340   lr02_i=cpl_table_get_nrow(lr02);
+<a name="l04341"></a>04341   lr85_i=cpl_table_get_nrow(lr85);
+<a name="l04342"></a>04342   lr20_i=cpl_table_get_nrow(lr20);
+<a name="l04343"></a>04343   lr31_i=cpl_table_get_nrow(lr31);
+<a name="l04344"></a>04344   lr42_i=cpl_table_get_nrow(lr42);
+<a name="l04345"></a>04345   lr53_i=cpl_table_get_nrow(lr53);
+<a name="l04346"></a>04346   lr64_i=cpl_table_get_nrow(lr64);
+<a name="l04347"></a>04347   lr75_i=cpl_table_get_nrow(lr75);
+<a name="l04348"></a>04348   lr86_i=cpl_table_get_nrow(lr86);
+<a name="l04349"></a>04349   lr97_i=cpl_table_get_nrow(lr97);
+<a name="l04350"></a>04350   check_nomsg(lr00_i=cpl_table_get_nrow(lr00));
+<a name="l04351"></a>04351 
+<a name="l04352"></a>04352   cpl_array_set_int(do_hk,0,lr41_i);
+<a name="l04353"></a>04353   cpl_array_set_int(do_hk,1,lr52_i);
+<a name="l04354"></a>04354   cpl_array_set_int(do_hk,2,lr63_i);
+<a name="l04355"></a>04355   cpl_array_set_int(do_hk,3,lr74_i);
+<a name="l04356"></a>04356   cpl_array_set_int(do_hk,4,lr02_i);
+<a name="l04357"></a>04357   cpl_array_set_int(do_hk,5,lr85_i);
+<a name="l04358"></a>04358   cpl_array_set_int(do_hk,6,lr20_i);
+<a name="l04359"></a>04359   cpl_array_set_int(do_hk,7,lr31_i);
+<a name="l04360"></a>04360   cpl_array_set_int(do_hk,8,lr42_i);
+<a name="l04361"></a>04361   cpl_array_set_int(do_hk,9,lr53_i);
+<a name="l04362"></a>04362   cpl_array_set_int(do_hk,10,lr64_i);
+<a name="l04363"></a>04363   cpl_array_set_int(do_hk,11,lr75_i);
+<a name="l04364"></a>04364   cpl_array_set_int(do_hk,12,lr86_i);
+<a name="l04365"></a>04365   cpl_array_set_int(do_hk,13,lr97_i);
+<a name="l04366"></a>04366   check_nomsg(cpl_array_set_int(do_hk,14,lr00_i));
+<a name="l04367"></a>04367 
+<a name="l04368"></a>04368   check_nomsg(rscale0=cpl_table_duplicate(*int_sky));
+<a name="l04369"></a>04369   check_nomsg(cpl_table_new_column(rscale0,<span class="stringliteral">"RATIO"</span>,CPL_TYPE_DOUBLE));
+<a name="l04370"></a>04370   check_nomsg(nrow=cpl_table_get_nrow(rscale0));
+<a name="l04371"></a>04371   check_nomsg(cpl_table_fill_column_window(rscale0,<span class="stringliteral">"RATIO"</span>,0,nrow,0));
+<a name="l04372"></a>04372 
+<a name="l04373"></a>04373   <span class="comment">// For each range extract proper: obj, sky, wave spectra</span>
+<a name="l04374"></a>04374   <span class="keywordflow">for</span> (i=0;i<NBOUND+1;i++) {
+<a name="l04375"></a>04375     <span class="keywordflow">if</span> (cpl_array_get_int(do_hk,i,&status) > 0) {
+<a name="l04376"></a>04376 
+<a name="l04377"></a>04377 
+<a name="l04378"></a>04378       <span class="keywordflow">switch</span>(i) {
+<a name="l04379"></a>04379 
+<a name="l04380"></a>04380 
+<a name="l04381"></a>04381       <span class="keywordflow">case</span> 0:
+<a name="l04382"></a>04382         ck0_nomsg(sinfo_get_obj_sky_wav_sub(*int_obj,*int_sky,lambda,lr41,wtol,
+<a name="l04383"></a>04383                         &obj_lr,&sky_lr,&wav_lr));
+<a name="l04384"></a>04384     <span class="keywordflow">break</span>;
+<a name="l04385"></a>04385 
+<a name="l04386"></a>04386       <span class="keywordflow">case</span> 1:
+<a name="l04387"></a>04387         ck0_nomsg(sinfo_get_obj_sky_wav_sub(*int_obj,*int_sky,lambda,lr52,wtol,
+<a name="l04388"></a>04388                         &obj_lr,&sky_lr,&wav_lr));
+<a name="l04389"></a>04389     <span class="keywordflow">break</span>;
+<a name="l04390"></a>04390 
+<a name="l04391"></a>04391       <span class="keywordflow">case</span> 2:
+<a name="l04392"></a>04392         ck0_nomsg(sinfo_get_obj_sky_wav_sub(*int_obj,*int_sky,lambda,lr63,wtol,
+<a name="l04393"></a>04393                         &obj_lr,&sky_lr,&wav_lr));
+<a name="l04394"></a>04394     <span class="keywordflow">break</span>;
+<a name="l04395"></a>04395 
+<a name="l04396"></a>04396       <span class="keywordflow">case</span> 3:
+<a name="l04397"></a>04397         ck0_nomsg(sinfo_get_obj_sky_wav_sub(*int_obj,*int_sky,lambda,lr74,wtol,
+<a name="l04398"></a>04398                         &obj_lr,&sky_lr,&wav_lr));
+<a name="l04399"></a>04399     <span class="keywordflow">break</span>;
+<a name="l04400"></a>04400 
+<a name="l04401"></a>04401       <span class="keywordflow">case</span> 4:
+<a name="l04402"></a>04402         ck0_nomsg(sinfo_get_obj_sky_wav_sub(*int_obj,*int_sky,lambda,lr02,wtol,
+<a name="l04403"></a>04403                         &obj_lr,&sky_lr,&wav_lr));
+<a name="l04404"></a>04404     <span class="keywordflow">break</span>;
+<a name="l04405"></a>04405 
+<a name="l04406"></a>04406       <span class="keywordflow">case</span> 5:
+<a name="l04407"></a>04407         ck0_nomsg(sinfo_get_obj_sky_wav_sub(*int_obj,*int_sky,lambda,lr85,wtol,
+<a name="l04408"></a>04408                         &obj_lr,&sky_lr,&wav_lr));
+<a name="l04409"></a>04409     <span class="keywordflow">break</span>;
+<a name="l04410"></a>04410       <span class="keywordflow">case</span> 6:
+<a name="l04411"></a>04411         ck0_nomsg(sinfo_get_obj_sky_wav_sub(*int_obj,*int_sky,lambda,lr20,wtol,
+<a name="l04412"></a>04412                         &obj_lr,&sky_lr,&wav_lr));
+<a name="l04413"></a>04413     <span class="keywordflow">break</span>;
+<a name="l04414"></a>04414       <span class="keywordflow">case</span> 7:
+<a name="l04415"></a>04415         ck0_nomsg(sinfo_get_obj_sky_wav_sub(*int_obj,*int_sky,lambda,lr31,wtol,
+<a name="l04416"></a>04416                         &obj_lr,&sky_lr,&wav_lr));
+<a name="l04417"></a>04417     <span class="keywordflow">break</span>;
+<a name="l04418"></a>04418       <span class="keywordflow">case</span> 8:
+<a name="l04419"></a>04419         ck0_nomsg(sinfo_get_obj_sky_wav_sub(*int_obj,*int_sky,lambda,lr42,wtol,
+<a name="l04420"></a>04420                         &obj_lr,&sky_lr,&wav_lr));
+<a name="l04421"></a>04421     <span class="keywordflow">break</span>;
+<a name="l04422"></a>04422       <span class="keywordflow">case</span> 9:
+<a name="l04423"></a>04423         ck0_nomsg(sinfo_get_obj_sky_wav_sub(*int_obj,*int_sky,lambda,lr53,wtol,
+<a name="l04424"></a>04424                         &obj_lr,&sky_lr,&wav_lr));
+<a name="l04425"></a>04425     <span class="keywordflow">break</span>;
+<a name="l04426"></a>04426       <span class="keywordflow">case</span> 10:
+<a name="l04427"></a>04427         ck0_nomsg(sinfo_get_obj_sky_wav_sub(*int_obj,*int_sky,lambda,lr64,wtol,
+<a name="l04428"></a>04428                         &obj_lr,&sky_lr,&wav_lr));
+<a name="l04429"></a>04429     <span class="keywordflow">break</span>;
+<a name="l04430"></a>04430       <span class="keywordflow">case</span> 11:
+<a name="l04431"></a>04431         ck0_nomsg(sinfo_get_obj_sky_wav_sub(*int_obj,*int_sky,lambda,lr75,wtol,
+<a name="l04432"></a>04432                         &obj_lr,&sky_lr,&wav_lr));
+<a name="l04433"></a>04433     <span class="keywordflow">break</span>;
+<a name="l04434"></a>04434       <span class="keywordflow">case</span> 12:
+<a name="l04435"></a>04435         ck0_nomsg(sinfo_get_obj_sky_wav_sub(*int_obj,*int_sky,lambda,lr86,wtol,
+<a name="l04436"></a>04436                         &obj_lr,&sky_lr,&wav_lr));
+<a name="l04437"></a>04437     <span class="keywordflow">break</span>;
+<a name="l04438"></a>04438       <span class="keywordflow">case</span> 13:
+<a name="l04439"></a>04439         ck0_nomsg(sinfo_get_obj_sky_wav_sub(*int_obj,*int_sky,lambda,lr97,wtol,
+<a name="l04440"></a>04440                         &obj_lr,&sky_lr,&wav_lr));
+<a name="l04441"></a>04441     <span class="keywordflow">break</span>;
+<a name="l04442"></a>04442       <span class="keywordflow">case</span> 14:
+<a name="l04443"></a>04443          ck0_nomsg(sinfo_get_obj_sky_wav_sub(*int_obj,*int_sky,lambda,lr00,
+<a name="l04444"></a>04444                          wtol,&obj_lr,&sky_lr,&wav_lr));
+<a name="l04445"></a>04445      <span class="keywordflow">break</span>;
+<a name="l04446"></a>04446       <span class="keywordflow">default</span>:
+<a name="l04447"></a>04447         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"case not supported"</span>);
+<a name="l04448"></a>04448     <span class="keywordflow">goto</span> cleanup;
+<a name="l04449"></a>04449       }
+<a name="l04450"></a>04450       <span class="keywordflow">if</span>(sky_lr == NULL || obj_lr == NULL || wav_lr == NULL) {
+<a name="l04451"></a>04451     finite_pix_i=0;
+<a name="l04452"></a>04452         sinfo_msg(<span class="stringliteral">"no good pix left"</span>);
+<a name="l04453"></a>04453       } <span class="keywordflow">else</span> {
+<a name="l04454"></a>04454     <span class="comment">//AMO: the following 2 seems to be critical for robustness</span>
+<a name="l04455"></a>04455     <span class="comment">//check_nomsg(cpl_table_save(sky_lr,NULL,NULL,"out_skylr0.fits",</span>
+<a name="l04456"></a>04456     <span class="comment">//             CPL_IO_DEFAULT));</span>
+<a name="l04457"></a>04457     <span class="comment">//check_nomsg(cpl_table_save(obj_lr,NULL,NULL,"out_objlr0.fits",</span>
+<a name="l04458"></a>04458     <span class="comment">//             CPL_IO_DEFAULT));</span>
+<a name="l04459"></a>04459     <span class="comment">//check_nomsg(cpl_table_save(wav_lr,NULL,NULL,"out_wavlr0.fits",</span>
+<a name="l04460"></a>04460     <span class="comment">//             CPL_IO_DEFAULT));</span>
+<a name="l04461"></a>04461 
+<a name="l04462"></a>04462 
+<a name="l04463"></a>04463 
+<a name="l04464"></a>04464     check_nomsg(finite_pix_i=sinfo_table_sky_obj_flag_nan(&sky_lr,
+<a name="l04465"></a>04465                                                               &obj_lr,
+<a name="l04466"></a>04466                                                               &wav_lr));
+<a name="l04467"></a>04467 
+<a name="l04468"></a>04468 
+<a name="l04469"></a>04469       }
+<a name="l04470"></a>04470 
+<a name="l04471"></a>04471 
+<a name="l04472"></a>04472       <span class="keywordflow">if</span> (finite_pix_i > npixw) {
+<a name="l04473"></a>04473         <span class="comment">// identify sky lines</span>
+<a name="l04474"></a>04474         <span class="comment">//sinfo_msg("finite_pix_i=%d",finite_pix_i);</span>
+<a name="l04475"></a>04475         check_nomsg(cpl_table_erase_invalid(obj_lr));
+<a name="l04476"></a>04476     check_nomsg(cpl_table_erase_invalid(sky_lr));
+<a name="l04477"></a>04477     check_nomsg(cpl_table_erase_invalid(wav_lr));
+<a name="l04478"></a>04478 
+<a name="l04479"></a>04479 
+<a name="l04480"></a>04480     check_nomsg(sky_med=cpl_table_get_column_median(sky_lr,<span class="stringliteral">"INT"</span>));
+<a name="l04481"></a>04481     check_nomsg(sky_sdv=cpl_table_get_column_stdev(sky_lr,<span class="stringliteral">"INT"</span>));
+<a name="l04482"></a>04482         check_nomsg(cpl_table_select_all(sky_lr));
+<a name="l04483"></a>04483         sky_thresh=sky_med+sky_sdv;
+<a name="l04484"></a>04484         <span class="comment">//sinfo_msg("sky_thresh=%f",sky_thresh);</span>
+<a name="l04485"></a>04485         check_nomsg(xxx1_i=cpl_table_and_selected_double(sky_lr,<span class="stringliteral">"INT"</span>,
+<a name="l04486"></a>04486                            CPL_GREATER_THAN,sky_thresh));
+<a name="l04487"></a>04487     check_nomsg(xxx1 = cpl_table_extract_selected(sky_lr));
+<a name="l04488"></a>04488         check_nomsg(cpl_table_select_all(sky_lr));
+<a name="l04489"></a>04489 
+<a name="l04490"></a>04490     <span class="keywordflow">if</span> (xxx1_i > 0) {
+<a name="l04491"></a>04491       <span class="comment">//separate line and continuum regions</span>
+<a name="l04492"></a>04492           <span class="comment">//by convolving with a hat region of large as a line</span>
+<a name="l04493"></a>04493           <span class="comment">//sinfo_msg("xxx1_i=%d",xxx1_i);</span>
+<a name="l04494"></a>04494       check_nomsg(xxx2 = cpl_table_duplicate(sky_lr));
+<a name="l04495"></a>04495           <span class="comment">//check_nomsg(cpl_table_save(sky_lr,NULL,NULL,</span>
+<a name="l04496"></a>04496           <span class="comment">//                           "out_skylr.fits",CPL_IO_DEFAULT));</span>
+<a name="l04497"></a>04497           <span class="comment">//check_nomsg(cpl_table_save(obj_lr,NULL,NULL,</span>
+<a name="l04498"></a>04498           <span class="comment">//                             "out_objlr.fits",CPL_IO_DEFAULT));</span>
+<a name="l04499"></a>04499           <span class="comment">//check_nomsg(cpl_table_save(xxx2,NULL,NULL,</span>
+<a name="l04500"></a>04500           <span class="comment">//                             "out_xxx2_0.fits",CPL_IO_DEFAULT));</span>
+<a name="l04501"></a>04501           ck0_nomsg(sinfo_table_threshold(&xxx2,<span class="stringliteral">"INT"</span>,sky_thresh,
+<a name="l04502"></a>04502                                           sky_thresh,0.,10.));
+<a name="l04503"></a>04503           <span class="comment">//check_nomsg(cpl_table_save(xxx2,NULL,NULL,</span>
+<a name="l04504"></a>04504           <span class="comment">//                             "out_xxx2_1.fits",CPL_IO_DEFAULT));</span>
+<a name="l04505"></a>04505 
+<a name="l04506"></a>04506 
+<a name="l04507"></a>04507           <span class="comment">/* TODO</span>
+<a name="l04508"></a>04508 <span class="comment">      xxx2[xxx1] = 10.;</span>
+<a name="l04509"></a>04509 <span class="comment">      */</span>
+<a name="l04510"></a>04510           <span class="comment">//sinfo_msg("npixw/2=%d",npixw);</span>
+<a name="l04511"></a>04511       check_nomsg(sinfo_convolve_kernel(&xxx2,npixw/2));
+<a name="l04512"></a>04512           <span class="comment">//check_nomsg(cpl_table_save(xxx2,NULL,NULL,</span>
+<a name="l04513"></a>04513           <span class="comment">//                             "out_xxx2_2.fits",CPL_IO_DEFAULT));</span>
+<a name="l04514"></a>04514 
+<a name="l04515"></a>04515           <span class="comment">// get line_regions</span>
+<a name="l04516"></a>04516           check_nomsg(line_i=cpl_table_and_selected_double(xxx2,<span class="stringliteral">"CNV"</span>,
+<a name="l04517"></a>04517                                                          CPL_GREATER_THAN,0));
+<a name="l04518"></a>04518 
+<a name="l04519"></a>04519           check_nomsg(line_regions=cpl_table_extract_selected(xxx2));
+<a name="l04520"></a>04520 
+<a name="l04521"></a>04521           <span class="comment">//check_nomsg(cpl_table_save(line_regions,NULL,NULL,</span>
+<a name="l04522"></a>04522           <span class="comment">//"out_line_regions.fits",CPL_IO_DEFAULT));</span>
+<a name="l04523"></a>04523 
+<a name="l04524"></a>04524       check_nomsg(cpl_table_erase_column(line_regions,<span class="stringliteral">"INT"</span>));
+<a name="l04525"></a>04525       check_nomsg(cpl_table_erase_column(line_regions,<span class="stringliteral">"CNV"</span>));
+<a name="l04526"></a>04526 
+<a name="l04527"></a>04527           check_nomsg(cpl_table_select_all(xxx2));
+<a name="l04528"></a>04528 
+<a name="l04529"></a>04529           <span class="comment">// get cont_regions</span>
+<a name="l04530"></a>04530           check_nomsg(cont_i=cpl_table_and_selected_double(xxx2,<span class="stringliteral">"CNV"</span>,
+<a name="l04531"></a>04531                                                            CPL_EQUAL_TO,0));
+<a name="l04532"></a>04532           check_nomsg(cont_regions=cpl_table_extract_selected(xxx2));
+<a name="l04533"></a>04533 
+<a name="l04534"></a>04534           <span class="comment">//check_nomsg(cpl_table_save(line_regions,NULL,NULL,</span>
+<a name="l04535"></a>04535           <span class="comment">//"out_cont_regions.fits",CPL_IO_DEFAULT));</span>
+<a name="l04536"></a>04536 
+<a name="l04537"></a>04537       check_nomsg(cpl_table_erase_column(cont_regions,<span class="stringliteral">"INT"</span>));
+<a name="l04538"></a>04538       check_nomsg(cpl_table_erase_column(cont_regions,<span class="stringliteral">"CNV"</span>));
+<a name="l04539"></a>04539           check_nomsg(cpl_table_select_all(xxx2));
+<a name="l04540"></a>04540       sinfo_free_table(&xxx2);
+<a name="l04541"></a>04541 
+<a name="l04542"></a>04542 
+<a name="l04543"></a>04543       <span class="keywordflow">if</span> (line_i >= 3 && cont_i >= 3) {
+<a name="l04544"></a>04544             <span class="comment">//If we have enough line points and continuum points</span>
+<a name="l04545"></a>04545              <span class="comment">//sinfo_msg("line_i=%d cont_i=%d",line_i,cont_i);</span>
+<a name="l04546"></a>04546         <span class="keywordflow">if</span> (i == 0) sinfo_msg(<span class="stringliteral">"optimising 4-1 transitions"</span>);
+<a name="l04547"></a>04547             <span class="keywordflow">if</span> (i == 1) sinfo_msg(<span class="stringliteral">"optimising 5-2 transitions"</span>);
+<a name="l04548"></a>04548             <span class="keywordflow">if</span> (i == 2) sinfo_msg(<span class="stringliteral">"optimising 6-3 transitions"</span>);
+<a name="l04549"></a>04549             <span class="keywordflow">if</span> (i == 3) sinfo_msg(<span class="stringliteral">"optimising 7-4 transitions"</span>);
+<a name="l04550"></a>04550             <span class="keywordflow">if</span> (i == 4) sinfo_msg(<span class="stringliteral">"optimising 0-2 transitions"</span>);
+<a name="l04551"></a>04551             <span class="keywordflow">if</span> (i == 5) sinfo_msg(<span class="stringliteral">"optimising 8-5 transitions"</span>);
+<a name="l04552"></a>04552             <span class="keywordflow">if</span> (i == 6) sinfo_msg(<span class="stringliteral">"optimising 2-0 transitions"</span>);
+<a name="l04553"></a>04553             <span class="keywordflow">if</span> (i == 7) sinfo_msg(<span class="stringliteral">"optimising 3-1 transitions"</span>);
+<a name="l04554"></a>04554             <span class="keywordflow">if</span> (i == 8) sinfo_msg(<span class="stringliteral">"optimising 4-2 transitions"</span>);
+<a name="l04555"></a>04555             <span class="keywordflow">if</span> (i == 9) sinfo_msg(<span class="stringliteral">"optimising 5-3 transitions"</span>);
+<a name="l04556"></a>04556             <span class="keywordflow">if</span> (i == 10) sinfo_msg(<span class="stringliteral">"optimising 6-4 transitions"</span>);
+<a name="l04557"></a>04557             <span class="keywordflow">if</span> (i == 11) sinfo_msg(<span class="stringliteral">"optimising 7-5 transitions"</span>);
+<a name="l04558"></a>04558             <span class="keywordflow">if</span> (i == 12) sinfo_msg(<span class="stringliteral">"optimising 8-6 transitions"</span>);
+<a name="l04559"></a>04559             <span class="keywordflow">if</span> (i == 13) sinfo_msg(<span class="stringliteral">"optimising 9-7 transitions"</span>);
+<a name="l04560"></a>04560             <span class="keywordflow">if</span> (i == 14) sinfo_msg(<span class="stringliteral">"optimising final bit"</span>);
+<a name="l04561"></a>04561         <span class="comment">// Fit the object profile='fline_res' of the sky line residuals</span>
+<a name="l04562"></a>04562             <span class="comment">// left after proper scaled sky spectrum lines (and continua)</span>
+<a name="l04563"></a>04563             <span class="comment">// subtraction. Then determines median and stdev to flag outliers</span>
+<a name="l04564"></a>04564 
+<a name="l04565"></a>04565         <span class="comment">//Free memory for each loop</span>
+<a name="l04566"></a>04566             sinfo_free_table(&obj_cont);
+<a name="l04567"></a>04567             sinfo_free_table(&sky_cont);
+<a name="l04568"></a>04568             sinfo_free_table(&sky_line);
+<a name="l04569"></a>04569             sinfo_free_table(&obj_line);
+<a name="l04570"></a>04570         <span class="comment">//Identify obj lines and continuum, same for sky</span>
+<a name="l04571"></a>04571             cknull_nomsg(obj_line=sinfo_table_select_range(obj_lr,line_regions,
+<a name="l04572"></a>04572                                   wtol));
+<a name="l04573"></a>04573 
+<a name="l04574"></a>04574 
+<a name="l04575"></a>04575             cknull_nomsg(sky_line=sinfo_table_select_range(sky_lr,line_regions,
+<a name="l04576"></a>04576                                   wtol));
+<a name="l04577"></a>04577             cknull_nomsg(obj_cont=sinfo_table_select_range(obj_lr,cont_regions,
+<a name="l04578"></a>04578                                   wtol));
+<a name="l04579"></a>04579              cknull_nomsg(sky_cont=sinfo_table_select_range(sky_lr,cont_regions,
+<a name="l04580"></a>04580                                   wtol));
+<a name="l04581"></a>04581 
+<a name="l04582"></a>04582         <span class="comment">//Here was commented</span>
+<a name="l04583"></a>04583             <span class="comment">//check_nomsg(cpl_table_save(line_regions,NULL,NULL,</span>
+<a name="l04584"></a>04584             <span class="comment">//            "out_line.fits",CPL_IO_DEFAULT));</span>
+<a name="l04585"></a>04585             <span class="comment">//check_nomsg(cpl_table_save(cont_regions,NULL,NULL,</span>
+<a name="l04586"></a>04586             <span class="comment">//            "out_cont.fits",CPL_IO_DEFAULT));</span>
+<a name="l04587"></a>04587             <span class="comment">//check_nomsg(cpl_table_save(obj_cont,NULL,NULL,</span>
+<a name="l04588"></a>04588             <span class="comment">//            "out_obj_cont.fits",CPL_IO_DEFAULT));</span>
+<a name="l04589"></a>04589             <span class="comment">//check_nomsg(cpl_table_save(obj_line,NULL,NULL,</span>
+<a name="l04590"></a>04590             <span class="comment">//            "out_obj_line.fits",CPL_IO_DEFAULT));</span>
+<a name="l04591"></a>04591             <span class="comment">//check_nomsg(cpl_table_save(sky_line,NULL,NULL,</span>
+<a name="l04592"></a>04592             <span class="comment">//            "out_sky_line.fits",CPL_IO_DEFAULT));</span>
+<a name="l04593"></a>04593             <span class="comment">//check_nomsg(cpl_table_save(sky_cont,NULL,NULL,</span>
+<a name="l04594"></a>04594             <span class="comment">//            "out_sky_cont.fits",CPL_IO_DEFAULT));</span>
+<a name="l04595"></a>04595 
+<a name="l04596"></a>04596 
+<a name="l04597"></a>04597             sinfo_free_table(&fline_res);
+<a name="l04598"></a>04598             <span class="comment">//FIXME: in some cases obj_cont is empty</span>
+<a name="l04599"></a>04599             <span class="comment">//sinfo_msg("first line ratio determination");</span>
+<a name="l04600"></a>04600             ck0_nomsg(sinfo_get_line_ratio(obj_line,obj_cont,
+<a name="l04601"></a>04601                        sky_line,sky_cont,method,&r));
+<a name="l04602"></a>04602         sinfo_msg(<span class="stringliteral">"1st Line ratio %g"</span>,r);
+<a name="l04603"></a>04603 
+<a name="l04604"></a>04604 
+<a name="l04605"></a>04605             <span class="keywordflow">if</span>(cpl_table_get_nrow(obj_cont) > 0) {
+<a name="l04606"></a>04606                check_nomsg(fline_res=sinfo_table_interpol(obj_line,obj_cont,
+<a name="l04607"></a>04607                                                           sky_line,sky_cont,
+<a name="l04608"></a>04608                                                           r));
+<a name="l04609"></a>04609         } <span class="keywordflow">else</span> {
+<a name="l04610"></a>04610               check_nomsg(fline_res=cpl_table_duplicate(obj_line));
+<a name="l04611"></a>04611         }
+<a name="l04612"></a>04612 
+<a name="l04613"></a>04613             <span class="comment">// check if there are outliers</span>
+<a name="l04614"></a>04614             cpl_table_select_all(fline_res);
+<a name="l04615"></a>04615             check_nomsg(fmed = cpl_table_get_column_median(fline_res,<span class="stringliteral">"INT"</span>));
+<a name="l04616"></a>04616             check_nomsg(fsdv = cpl_table_get_column_stdev(fline_res,<span class="stringliteral">"INT"</span>));
+<a name="l04617"></a>04617 
+<a name="l04618"></a>04618             check_nomsg(cpl_table_duplicate_column(fline_res,<span class="stringliteral">"AINT"</span>,
+<a name="l04619"></a>04619                                                    fline_res,<span class="stringliteral">"INT"</span>));
+<a name="l04620"></a>04620             check_nomsg(cpl_table_multiply_columns(fline_res,<span class="stringliteral">"AINT"</span>,<span class="stringliteral">"INT"</span>));
+<a name="l04621"></a>04621             check_nomsg(cpl_table_power_column(fline_res,<span class="stringliteral">"AINT"</span>,0.5));
+<a name="l04622"></a>04622             check_nomsg(fclip_i=cpl_table_and_selected_double(fline_res,<span class="stringliteral">"AINT"</span>,
+<a name="l04623"></a>04623                                                   CPL_GREATER_THAN,
+<a name="l04624"></a>04624                                                   fmed+3*fsdv));
+<a name="l04625"></a>04625 
+<a name="l04626"></a>04626             check_nomsg(cpl_table_select_all(fline_res));
+<a name="l04627"></a>04627 
+<a name="l04628"></a>04628 
+<a name="l04629"></a>04629         <span class="keywordflow">if</span> (fclip_i > 0) {
+<a name="l04630"></a>04630               <span class="comment">// do a k-sigma clip to select a better line region</span>
+<a name="l04631"></a>04631               <span class="comment">//sinfo_msg("fclip_i=%d",fclip_i);</span>
+<a name="l04632"></a>04632               <span class="comment">//Find again line_regions</span>
+<a name="l04633"></a>04633               check_nomsg(line_i=cpl_table_and_selected_double(fline_res,
+<a name="l04634"></a>04634                                    <span class="stringliteral">"AINT"</span>,
+<a name="l04635"></a>04635                                    CPL_NOT_GREATER_THAN,
+<a name="l04636"></a>04636                                    fmed+3*fsdv));
+<a name="l04637"></a>04637           <span class="comment">// get new (better) line_regions</span>
+<a name="l04638"></a>04638           sinfo_free_table(&line_regions);
+<a name="l04639"></a>04639               <span class="comment">//sinfo_msg("line_i=%d",line_i);</span>
+<a name="l04640"></a>04640               check_nomsg(line_regions=cpl_table_extract_selected(fline_res));
+<a name="l04641"></a>04641               check_nomsg(cpl_table_erase_column(line_regions,<span class="stringliteral">"INT"</span>));
+<a name="l04642"></a>04642               check_nomsg(cpl_table_erase_column(line_regions,<span class="stringliteral">"AINT"</span>));
+<a name="l04643"></a>04643 
+<a name="l04644"></a>04644           sinfo_free_table(&obj_line);
+<a name="l04645"></a>04645           sinfo_free_table(&sky_line);
+<a name="l04646"></a>04646 
+<a name="l04647"></a>04647           <span class="comment">//check_nomsg(cpl_table_save(obj_lr,NULL,NULL,</span>
+<a name="l04648"></a>04648               <span class="comment">//                           "out_obj_lr.fits",CPL_IO_DEFAULT));</span>
+<a name="l04649"></a>04649           <span class="comment">//check_nomsg(cpl_table_save(line_regions,NULL,NULL,</span>
+<a name="l04650"></a>04650               <span class="comment">//                           "out_line_regions.fits",</span>
+<a name="l04651"></a>04651               <span class="comment">//                           CPL_IO_DEFAULT));</span>
+<a name="l04652"></a>04652 
+<a name="l04653"></a>04653 
+<a name="l04654"></a>04654 
+<a name="l04655"></a>04655 
+<a name="l04656"></a>04656           <span class="comment">// The following 2 may return an error so we do not check and</span>
+<a name="l04657"></a>04657           <span class="comment">// later we reset the error</span>
+<a name="l04658"></a>04658               obj_line=sinfo_table_select_range(obj_lr,line_regions,wtol);
+<a name="l04659"></a>04659               sky_line=sinfo_table_select_range(sky_lr,line_regions,wtol);
+<a name="l04660"></a>04660               fline_i=cpl_table_get_nrow(line_regions);
+<a name="l04661"></a>04661 
+<a name="l04662"></a>04662               <span class="comment">//sinfo_msg("fline_i=%d",fline_i);</span>
+<a name="l04663"></a>04663               <span class="keywordflow">if</span>(fline_i>=3) {
+<a name="l04664"></a>04664                 <span class="comment">// repeat the determination of the line ratio</span>
+<a name="l04665"></a>04665                 <span class="comment">//sinfo_msg("second line ratio determination");</span>
+<a name="l04666"></a>04666                 ck0_nomsg(sinfo_get_line_ratio(obj_line,obj_cont,
+<a name="l04667"></a>04667                                                 sky_line,sky_cont,method,&r));
+<a name="l04668"></a>04668 
+<a name="l04669"></a>04669         sinfo_msg(<span class="stringliteral">"2nd Line ratio %g"</span>,r);
+<a name="l04670"></a>04670 
+<a name="l04671"></a>04671           } <span class="keywordflow">else</span> {
+<a name="l04672"></a>04672                 cpl_error_reset();
+<a name="l04673"></a>04673           }
+<a name="l04674"></a>04674 
+<a name="l04675"></a>04675           sinfo_free_table(&sky_line);
+<a name="l04676"></a>04676           sinfo_free_table(&obj_line);
+<a name="l04677"></a>04677         }
+<a name="l04678"></a>04678 
+<a name="l04679"></a>04679             cpl_msg_info(cpl_func,<span class="stringliteral">"use %"</span> CPL_SIZE_FORMAT 
+<a name="l04680"></a>04680                          <span class="stringliteral">" pixels for line and %"</span> CPL_SIZE_FORMAT 
+<a name="l04681"></a>04681                          <span class="stringliteral">" for continuum estimation"</span>,
+<a name="l04682"></a>04682             cpl_table_get_nrow(line_regions),cpl_table_get_nrow(cont_regions));
+<a name="l04683"></a>04683 
+<a name="l04684"></a>04684         sinfo_msg(<span class="stringliteral">"OH spectrum scaling = %f "</span>,r);
+<a name="l04685"></a>04685             check_nomsg(cpl_array_set_double(rfit,i,r));
+<a name="l04686"></a>04686             ck0_nomsg(sinfo_table_set(&rscale0,wav_lr,r,wtol));
+<a name="l04687"></a>04687 
+<a name="l04688"></a>04688       } <span class="comment">/* end if line_i */</span>
+<a name="l04689"></a>04689         } <span class="comment">/* end if xxx1_i */</span>
+<a name="l04690"></a>04690      } <span class="comment">/* end finite_pix_i */</span>
+<a name="l04691"></a>04691 
+<a name="l04692"></a>04692     }
+<a name="l04693"></a>04693 
+<a name="l04694"></a>04694     sinfo_free_table(&xxx1);
+<a name="l04695"></a>04695     sinfo_free_table(&xxx2);
+<a name="l04696"></a>04696     sinfo_free_table(&sky_lr);
+<a name="l04697"></a>04697     sinfo_free_table(&obj_lr);
+<a name="l04698"></a>04698     sinfo_free_table(&wav_lr);
+<a name="l04699"></a>04699 
+<a name="l04700"></a>04700     sinfo_free_table(&line_regions);
+<a name="l04701"></a>04701     sinfo_free_table(&cont_regions);
+<a name="l04702"></a>04702 
+<a name="l04703"></a>04703   } <span class="comment">/* end for loop on i */</span>
+<a name="l04704"></a>04704 
+<a name="l04705"></a>04705   sinfo_free_array(&do_hk);
+<a name="l04706"></a>04706   sinfo_free_array(&rfit);
+<a name="l04707"></a>04707 
+<a name="l04708"></a>04708   <span class="comment">//sinfo_msg("n scale=%d",cpl_table_get_nrow(rscale0));</span>
+<a name="l04709"></a>04709   <span class="comment">//check_nomsg(cpl_table_save(rscale0,NULL,NULL,</span>
+<a name="l04710"></a>04710   <span class="comment">//                                   "out_rscale0.fits",CPL_IO_DEFAULT));</span>
+<a name="l04711"></a>04711 
+<a name="l04712"></a>04712   check_nomsg(cpl_table_select_all(rscale0));
+<a name="l04713"></a>04713  <span class="comment">/* TODO: here one has to implementa an interpol function</span>
+<a name="l04714"></a>04714 <span class="comment">  check_nomsg(range0_i=cpl_table_and_selected_double(rscale0,"RATIO",</span>
+<a name="l04715"></a>04715 <span class="comment">                                                     CPL_NOT_EQUAL_TO,0));</span>
+<a name="l04716"></a>04716 <span class="comment"> */</span>
+<a name="l04717"></a>04717   check_nomsg(*rscale = cpl_table_extract_selected(rscale0));
+<a name="l04718"></a>04718   sinfo_free_table(&rscale0);
+<a name="l04719"></a>04719 
+<a name="l04720"></a>04720 
+<a name="l04721"></a>04721   check_nomsg(rat_sky=cpl_table_duplicate(*int_sky));
+<a name="l04722"></a>04722   check_nomsg(cpl_table_duplicate_column(rat_sky,<span class="stringliteral">"RATIO"</span>,*rscale,<span class="stringliteral">"RATIO"</span>));
+<a name="l04723"></a>04723   check_nomsg(cpl_table_duplicate_column(*int_obj,<span class="stringliteral">"COR_FCT_VIB"</span>,
+<a name="l04724"></a>04724                      *rscale,<span class="stringliteral">"RATIO"</span>));
+<a name="l04725"></a>04725   <span class="comment">//check_nomsg(cpl_table_save(rat_sky,NULL,NULL,</span>
+<a name="l04726"></a>04726   <span class="comment">//                           "rat_sky0.fits",CPL_IO_DEFAULT));</span>
+<a name="l04727"></a>04727   check_nomsg(cpl_table_multiply_columns(rat_sky,<span class="stringliteral">"INT"</span>,<span class="stringliteral">"RATIO"</span>));
+<a name="l04728"></a>04728 
+<a name="l04729"></a>04729 
+<a name="l04730"></a>04730   <span class="comment">//check_nomsg(cpl_table_save(*int_obj,NULL,NULL,</span>
+<a name="l04731"></a>04731   <span class="comment">//                             "out_obj0.fits",CPL_IO_DEFAULT));</span>
+<a name="l04732"></a>04732   <span class="comment">//check_nomsg(cpl_table_save(*int_sky,NULL,NULL,</span>
+<a name="l04733"></a>04733   <span class="comment">//                             "out_sky0.fits",CPL_IO_DEFAULT));</span>
+<a name="l04734"></a>04734 
+<a name="l04735"></a>04735   <span class="comment">/*</span>
+<a name="l04736"></a>04736 <span class="comment">  check_nomsg(cpl_table_duplicate_column(*int_obj,"INTC",*int_obj,"INT"));</span>
+<a name="l04737"></a>04737 <span class="comment">  check_nomsg(cpl_table_duplicate_column(*int_obj,"SKYC",*int_sky,"INTC"));</span>
+<a name="l04738"></a>04738 <span class="comment">  check_nomsg(cpl_table_subtract_columns(*int_obj,"INTC","SKYC"));</span>
+<a name="l04739"></a>04739 <span class="comment">  */</span>
+<a name="l04740"></a>04740 
+<a name="l04741"></a>04741   <span class="comment">// do simple rotational correction</span>
+<a name="l04742"></a>04742   <span class="keywordflow">if</span> (do_rot == 1) {
+<a name="l04743"></a>04743 
+<a name="l04744"></a>04744     <span class="comment">//finite_pix = where(finite(int_sky) && finite(int_obj),finite_pix_i);</span>
+<a name="l04745"></a>04745     check_nomsg(min_lrange=cpl_table_get_column_min(lrange,<span class="stringliteral">"WAVE"</span>));
+<a name="l04746"></a>04746     check_nomsg(max_lrange=cpl_table_get_column_max(lrange,<span class="stringliteral">"WAVE"</span>));
+<a name="l04747"></a>04747     <span class="comment">//sinfo_msg("min_lrange=%g max_lrange=%g",min_lrange,max_lrange);</span>
+<a name="l04748"></a>04748     <span class="comment">//check_nomsg(finite_pix_i=sinfo_table_sky_obj_flag_nan(&rat_sky,</span>
+<a name="l04749"></a>04749     <span class="comment">//                                                      int_obj,</span>
+<a name="l04750"></a>04750     <span class="comment">//                                                      &lambda));</span>
+<a name="l04751"></a>04751     check_nomsg(finite_pix_i=sinfo_table_sky_obj_flag_nan(int_sky,
+<a name="l04752"></a>04752                                                           int_obj,
+<a name="l04753"></a>04753                                                           &lambda));
+<a name="l04754"></a>04754 
+<a name="l04755"></a>04755 
+<a name="l04756"></a>04756     check_nomsg(finite_pix=cpl_table_duplicate(lambda));
+<a name="l04757"></a>04757     <span class="comment">//TODO: lambda invalid values need to be reset to valid (?)</span>
+<a name="l04758"></a>04758 
+<a name="l04759"></a>04759     check_nomsg(cpl_table_erase_invalid(finite_pix));
+<a name="l04760"></a>04760 
+<a name="l04761"></a>04761 
+<a name="l04762"></a>04762     <span class="keywordflow">if</span> (finite_pix_i > npixw) {
+<a name="l04763"></a>04763 
+<a name="l04764"></a>04764       <span class="comment">//finite_pix = finite_pix[where(finite_pix > min(lrange) &&</span>
+<a name="l04765"></a>04765       <span class="comment">//                              finite_pix < max(lrange))];</span>
+<a name="l04766"></a>04766 
+<a name="l04767"></a>04767       check_nomsg(cpl_table_and_selected_double(finite_pix,<span class="stringliteral">"WAVE"</span>,
+<a name="l04768"></a>04768                                                 CPL_GREATER_THAN,
+<a name="l04769"></a>04769                                                 min_lrange));
+<a name="l04770"></a>04770 
+<a name="l04771"></a>04771       check_nomsg(cpl_table_and_selected_double(finite_pix,<span class="stringliteral">"WAVE"</span>,
+<a name="l04772"></a>04772                                                 CPL_LESS_THAN,
+<a name="l04773"></a>04773                                                 max_lrange));
+<a name="l04774"></a>04774 
+<a name="l04775"></a>04775 
+<a name="l04776"></a>04776 
+<a name="l04777"></a>04777       check_nomsg(tmp_tbl=cpl_table_extract_selected(finite_pix));
+<a name="l04778"></a>04778       sinfo_free_table(&finite_pix);
+<a name="l04779"></a>04779       check_nomsg(finite_pix=cpl_table_duplicate(tmp_tbl));
+<a name="l04780"></a>04780       sinfo_free_table(&tmp_tbl);
+<a name="l04781"></a>04781       sinfo_free_table(&sky_lr);
+<a name="l04782"></a>04782       sinfo_free_table(&obj_lr);
+<a name="l04783"></a>04783       sinfo_free_table(&wav_lr);
+<a name="l04784"></a>04784 
+<a name="l04785"></a>04785 
+<a name="l04786"></a>04786       cknull(sky_lr=sinfo_table_select_range(rat_sky,finite_pix,wtol),
+<a name="l04787"></a>04787          <span class="stringliteral">"extracting sky sub range"</span>);
+<a name="l04788"></a>04788       cknull(obj_lr=sinfo_table_select_range(*int_obj,finite_pix,wtol),
+<a name="l04789"></a>04789          <span class="stringliteral">"extracting obj sub range"</span>);
+<a name="l04790"></a>04790       cknull(wav_lr=sinfo_table_select_range(lambda,finite_pix,wtol),
+<a name="l04791"></a>04791          <span class="stringliteral">"extracting sky sub range"</span>);
+<a name="l04792"></a>04792 
+<a name="l04793"></a>04793 
+<a name="l04794"></a>04794       <span class="comment">//check_nomsg(cpl_table_save(rat_sky,NULL,NULL,</span>
+<a name="l04795"></a>04795       <span class="comment">//                             "out_rat_sky.fits",CPL_IO_DEFAULT));</span>
+<a name="l04796"></a>04796       <span class="comment">//check_nomsg(cpl_table_save(finite_pix,NULL,NULL,</span>
+<a name="l04797"></a>04797       <span class="comment">//                             "out_finite_pix.fits",CPL_IO_DEFAULT));</span>
+<a name="l04798"></a>04798       <span class="comment">//check_nomsg(cpl_table_save(sky_lr,NULL,NULL,</span>
+<a name="l04799"></a>04799       <span class="comment">//                             "out_sky_lr.fits",CPL_IO_DEFAULT));</span>
+<a name="l04800"></a>04800       <span class="comment">//check_nomsg(cpl_table_save(obj_lr,NULL,NULL,</span>
+<a name="l04801"></a>04801       <span class="comment">//                             "out_obj_lr.fits",CPL_IO_DEFAULT));</span>
+<a name="l04802"></a>04802       <span class="comment">//check_nomsg(cpl_table_save(wav_lr,NULL,NULL,</span>
+<a name="l04803"></a>04803       <span class="comment">//                             "out_wav_lr.fits",CPL_IO_DEFAULT));</span>
+<a name="l04804"></a>04804 
+<a name="l04805"></a>04805       <span class="comment">//The following may fail (sky_lr may be empty) so we do not check</span>
+<a name="l04806"></a>04806       <span class="keywordflow">if</span>(1 == cpl_table_has_valid(sky_lr,<span class="stringliteral">"INT"</span>)) {
+<a name="l04807"></a>04807     check_nomsg(sky_med=cpl_table_get_column_median(sky_lr,<span class="stringliteral">"INT"</span>));
+<a name="l04808"></a>04808     check_nomsg(sky_sdv=cpl_table_get_column_stdev(sky_lr,<span class="stringliteral">"INT"</span>));
+<a name="l04809"></a>04809     sky_thresh=sky_med+sky_sdv;
+<a name="l04810"></a>04810         <span class="comment">//xxx1 = where(sky_lr > median(sky_lr)+stddev(sky_lr),xxx1_i);</span>
+<a name="l04811"></a>04811         check_nomsg(xxx1_i=cpl_table_and_selected_double(sky_lr,<span class="stringliteral">"INT"</span>,
+<a name="l04812"></a>04812                            CPL_GREATER_THAN,sky_thresh));
+<a name="l04813"></a>04813         check_nomsg(xxx1=cpl_table_extract_selected(sky_lr));
+<a name="l04814"></a>04814         check_nomsg(cpl_table_select_all(sky_lr));
+<a name="l04815"></a>04815       } <span class="keywordflow">else</span> {
+<a name="l04816"></a>04816         xxx1_i=0;
+<a name="l04817"></a>04817       }
+<a name="l04818"></a>04818       <span class="keywordflow">if</span> (xxx1_i > 0) {
+<a name="l04819"></a>04819         sinfo_msg(<span class="stringliteral">"xxx1_i=%d"</span>,xxx1_i);
+<a name="l04820"></a>04820 
+<a name="l04821"></a>04821         sinfo_msg(<span class="stringliteral">"wav_lr wmin=%g wmax=%g"</span>,
+<a name="l04822"></a>04822           cpl_table_get_column_min(wav_lr,<span class="stringliteral">"WAVE"</span>),
+<a name="l04823"></a>04823           cpl_table_get_column_max(wav_lr,<span class="stringliteral">"WAVE"</span>));
+<a name="l04824"></a>04824 
+<a name="l04825"></a>04825         cknull_nomsg(llr_xxx1=sinfo_table_select_range(wav_lr,xxx1,wtol));
+<a name="l04826"></a>04826         <span class="comment">//check_nomsg(cpl_table_save(wav_lr,NULL,NULL,</span>
+<a name="l04827"></a>04827         <span class="comment">//                             "out_llr_xxx1.fits",CPL_IO_DEFAULT));</span>
+<a name="l04828"></a>04828 
+<a name="l04829"></a>04829         cknull(low_pos=sinfo_find_rot_waves(w_rot_low,npixw,wtol,llr_xxx1),
+<a name="l04830"></a>04830            <span class="stringliteral">"Determining low positions"</span>);
+<a name="l04831"></a>04831 
+<a name="l04832"></a>04832 
+<a name="l04833"></a>04833         check_nomsg(low_pos_i=cpl_table_get_nrow(low_pos));
+<a name="l04834"></a>04834         <span class="comment">//check_nomsg(cpl_table_dump(low_pos,0,low_pos_i,stdout));</span>
+<a name="l04835"></a>04835         cknull(med_pos=sinfo_find_rot_waves(w_rot_med,npixw,wtol,llr_xxx1),
+<a name="l04836"></a>04836                <span class="stringliteral">"Determining med positions"</span>);
+<a name="l04837"></a>04837         check_nomsg(med_pos_i=cpl_table_get_nrow(med_pos));
+<a name="l04838"></a>04838 
+<a name="l04839"></a>04839 
+<a name="l04840"></a>04840         <span class="comment">//check_nomsg(cpl_table_dump(med_pos,0,med_pos_i,stdout));</span>
+<a name="l04841"></a>04841 
+<a name="l04842"></a>04842         <span class="comment">//TODO:</span>
+<a name="l04843"></a>04843         <span class="comment">//hipos = [0]</span>
+<a name="l04844"></a>04844         <span class="comment">//for i=0,n_elements(xxx1)-1 do begin</span>
+<a name="l04845"></a>04845         <span class="comment">//    x1 = where(lowpos eq i,x1_i)</span>
+<a name="l04846"></a>04846         <span class="comment">//    x2 = where(medpos eq i,x2_i)</span>
+<a name="l04847"></a>04847         <span class="comment">//    if (x1_i eq 0 and x2_i eq 0) then hipos = [hipos,i]</span>
+<a name="l04848"></a>04848         <span class="comment">//endfor</span>
+<a name="l04849"></a>04849         <span class="comment">//hipos = hipos[1:n_elements(hipos)-1]</span>
+<a name="l04850"></a>04850         <span class="comment">//TODO: hi_pos=sinfo_find_rot_waves(w_rot_hi,npixw,wtol,wav_lr);</span>
+<a name="l04851"></a>04851 
+<a name="l04852"></a>04852 
+<a name="l04853"></a>04853         cknull(hi_pos=sinfo_table_extract_rest(xxx1,low_pos,med_pos,wtol),
+<a name="l04854"></a>04854            <span class="stringliteral">"determining hi position"</span>);
+<a name="l04855"></a>04855         check_nomsg(hi_pos_i=cpl_table_get_nrow(hi_pos));
+<a name="l04856"></a>04856         <span class="comment">//check_nomsg(cpl_table_dump(hi_pos,0,hi_pos_i,stdout));</span>
+<a name="l04857"></a>04857 
+<a name="l04858"></a>04858 
+<a name="l04859"></a>04859         <span class="comment">//xxx2[xxx1] = 10.;</span>
+<a name="l04860"></a>04860         check_nomsg(xxx2 = cpl_table_duplicate(sky_lr));
+<a name="l04861"></a>04861         check_nomsg(nrow=cpl_table_get_nrow(sky_lr));
+<a name="l04862"></a>04862         <span class="comment">//check_nomsg(cpl_table_save(xxx2,NULL,NULL,</span>
+<a name="l04863"></a>04863         <span class="comment">//                             "out_xxx1.fits",CPL_IO_DEFAULT));</span>
+<a name="l04864"></a>04864         <span class="comment">//check_nomsg(cpl_table_save(xxx2,NULL,NULL,</span>
+<a name="l04865"></a>04865         <span class="comment">//                             "out_xxx2_0.fits",CPL_IO_DEFAULT));</span>
+<a name="l04866"></a>04866 
+<a name="l04867"></a>04867         <span class="comment">// AMO: Why the following?</span>
+<a name="l04868"></a>04868         <span class="comment">//check_nomsg(cpl_table_fill_column_window(xxx2,"INT",0,nrow,0));</span>
+<a name="l04869"></a>04869 
+<a name="l04870"></a>04870         <span class="comment">//xxx2 = convol(xxx2,replicate(1,npixw),/edge_truncate,/center);</span>
+<a name="l04871"></a>04871         <span class="comment">//cont_regions = where(xxx2 == 0,cont_i);</span>
+<a name="l04872"></a>04872         ck0_nomsg(sinfo_table_threshold(&xxx2,<span class="stringliteral">"INT"</span>,sky_thresh,
+<a name="l04873"></a>04873                     sky_thresh,0.,10.));
+<a name="l04874"></a>04874         sinfo_msg(<span class="stringliteral">"sky_thresh=%g %g %f"</span>,sky_thresh,sky_med,sky_sdv);
+<a name="l04875"></a>04875         <span class="comment">//check_nomsg(cpl_table_save(xxx2,NULL,NULL,</span>
+<a name="l04876"></a>04876         <span class="comment">//                             "out_xxx2_1.fits",CPL_IO_DEFAULT));</span>
+<a name="l04877"></a>04877         check_nomsg(sinfo_convolve_kernel(&xxx2,npixw/2));
+<a name="l04878"></a>04878 
+<a name="l04879"></a>04879         <span class="comment">//check_nomsg(cpl_table_save(xxx2,NULL,NULL,</span>
+<a name="l04880"></a>04880         <span class="comment">//                             "out_xxx2_2.fits",CPL_IO_DEFAULT));</span>
+<a name="l04881"></a>04881         check_nomsg(cont_i=cpl_table_and_selected_double(xxx2,<span class="stringliteral">"CNV"</span>,
+<a name="l04882"></a>04882                              CPL_EQUAL_TO,0));
+<a name="l04883"></a>04883         check_nomsg(cont_regions=cpl_table_extract_selected(xxx2));
+<a name="l04884"></a>04884 
+<a name="l04885"></a>04885         sinfo_free_table(&xxx2);
+<a name="l04886"></a>04886         check_nomsg(cpl_table_erase_column(cont_regions,<span class="stringliteral">"INT"</span>));
+<a name="l04887"></a>04887         check_nomsg(cpl_table_erase_column(cont_regions,<span class="stringliteral">"CNV"</span>));
+<a name="l04888"></a>04888 
+<a name="l04889"></a>04889         check(low_pos_i=sinfo_get_sub_regions(sky_lr,xxx1,low_pos,wtol,
+<a name="l04890"></a>04890                          npixw,&low_regions),<span class="stringliteral">"failed determining low regions"</span>);
+<a name="l04891"></a>04891 
+<a name="l04892"></a>04892         check(med_pos_i=sinfo_get_sub_regions(sky_lr,xxx1,med_pos,wtol,
+<a name="l04893"></a>04893                          npixw,&med_regions),<span class="stringliteral">"failed determining med regions"</span>);
+<a name="l04894"></a>04894 
+<a name="l04895"></a>04895 
+<a name="l04896"></a>04896         check(hi_pos_i=sinfo_get_sub_regions(sky_lr,xxx1,hi_pos,wtol,
+<a name="l04897"></a>04897                         npixw,&hi_regions),<span class="stringliteral">"failed determining hi regions"</span>);
+<a name="l04898"></a>04898     <span class="comment">/*</span>
+<a name="l04899"></a>04899 <span class="comment">        sinfo_msg("xxx1: wmin=%g wmax=%g",</span>
+<a name="l04900"></a>04900 <span class="comment">                   cpl_table_get_column_min(xxx1,"WAVE"),</span>
+<a name="l04901"></a>04901 <span class="comment">                   cpl_table_get_column_max(xxx1,"WAVE"));</span>
+<a name="l04902"></a>04902 <span class="comment"></span>
+<a name="l04903"></a>04903 <span class="comment">        sinfo_msg("low_pos: wmin=%g wmax=%g",</span>
+<a name="l04904"></a>04904 <span class="comment">                   cpl_table_get_column_min(low_pos,"WAVE"),</span>
+<a name="l04905"></a>04905 <span class="comment">                   cpl_table_get_column_max(low_pos,"WAVE"));</span>
+<a name="l04906"></a>04906 <span class="comment">    */</span>
+<a name="l04907"></a>04907         sinfo_msg(<span class="stringliteral">"hi_pos_i : %d med_pos_i : %d low_pos_i : %d cont_i: %d"</span>,
+<a name="l04908"></a>04908                    hi_pos_i,     med_pos_i,     low_pos_i,     cont_i);
+<a name="l04909"></a>04909 
+<a name="l04910"></a>04910 
+<a name="l04911"></a>04911         <span class="keywordflow">if</span> (hi_pos_i >= 3 && med_pos_i >= 3 && low_pos_i >= 3 && cont_i >= 3) {
+<a name="l04912"></a>04912 
+<a name="l04913"></a>04913           <span class="comment">//compute line ratio for hi_regions</span>
+<a name="l04914"></a>04914           ck0_nomsg(sinfo_compute_line_ratio(obj_lr, sky_lr,wtol, method,
+<a name="l04915"></a>04915                                              hi_regions,cont_regions,&rhi));
+<a name="l04916"></a>04916           sinfo_msg(<span class="stringliteral">"high rotational OH scaling %g"</span>,rhi);
+<a name="l04917"></a>04917 
+<a name="l04918"></a>04918           <span class="comment">//compute line ratio for med_regions</span>
+<a name="l04919"></a>04919           ck0_nomsg(sinfo_compute_line_ratio(obj_lr, sky_lr,wtol, method,
+<a name="l04920"></a>04920                                              med_regions,cont_regions,&rmed));
+<a name="l04921"></a>04921 
+<a name="l04922"></a>04922           sinfo_msg(<span class="stringliteral">"P1(3.5) & R1(1.5) rotational OH scaling %g "</span>,rmed);
+<a name="l04923"></a>04923 
+<a name="l04924"></a>04924           <span class="comment">//compute line ratio for med_regions</span>
+<a name="l04925"></a>04925           ck0_nomsg(sinfo_compute_line_ratio(obj_lr, sky_lr,wtol, method,
+<a name="l04926"></a>04926                                              low_regions,cont_regions,&rlow));
+<a name="l04927"></a>04927           sinfo_msg(<span class="stringliteral">"P1(2.5) & Q1(1.5) rotational OH scaling %g"</span>,rlow);
+<a name="l04928"></a>04928 
+<a name="l04929"></a>04929           cknull(low_scale=sinfo_find_rot_waves(w_rot_low,npixw,wtol,lambda),
+<a name="l04930"></a>04930          <span class="stringliteral">"Determining low scale"</span>);
+<a name="l04931"></a>04931 
+<a name="l04932"></a>04932 
+<a name="l04933"></a>04933 
+<a name="l04934"></a>04934           cknull(med_scale=sinfo_find_rot_waves(w_rot_low,npixw,wtol,lambda),
+<a name="l04935"></a>04935          <span class="stringliteral">"Determining low scale"</span>);
+<a name="l04936"></a>04936           check_nomsg(cpl_table_multiply_scalar(*rscale,<span class="stringliteral">"RATIO"</span>,rhi));
+<a name="l04937"></a>04937           ck0_nomsg(sinfo_table_fill_column_over_range(rscale,med_scale,
+<a name="l04938"></a>04938                                                   <span class="stringliteral">"RATIO"</span>,rmed/rhi,wtol));
+<a name="l04939"></a>04939           ck0_nomsg(sinfo_table_fill_column_over_range(rscale,low_scale,
+<a name="l04940"></a>04940                                  <span class="stringliteral">"RATIO"</span>,rlow/rhi,wtol));
+<a name="l04941"></a>04941 
+<a name="l04942"></a>04942     }
+<a name="l04943"></a>04943       } <span class="comment">//xxx1_i > 0</span>
+<a name="l04944"></a>04944     }<span class="comment">//finitepix > npixw</span>
+<a name="l04945"></a>04945   }<span class="comment">//do_rot==1</span>
+<a name="l04946"></a>04946   <span class="comment">//end of new rotational bit</span>
+<a name="l04947"></a>04947   <span class="comment">//check_nomsg(cpl_table_save(*int_obj,NULL,NULL,</span>
+<a name="l04948"></a>04948   <span class="comment">//                             "out_obj.fits",CPL_IO_DEFAULT));</span>
+<a name="l04949"></a>04949   <span class="comment">//check_nomsg(cpl_table_save(*int_sky,NULL,NULL,</span>
+<a name="l04950"></a>04950   <span class="comment">//                             "out_sky.fits",CPL_IO_DEFAULT));</span>
+<a name="l04951"></a>04951 
+<a name="l04952"></a>04952 
+<a name="l04953"></a>04953   check_nomsg(cpl_table_duplicate_column(*int_sky,<span class="stringliteral">"INTC"</span>,*int_sky,<span class="stringliteral">"INT"</span>));
+<a name="l04954"></a>04954   <span class="comment">//sinfo_msg("n sky=%d",cpl_table_get_nrow(*int_sky));</span>
+<a name="l04955"></a>04955   <span class="comment">//sinfo_msg("n scale=%d",cpl_table_get_nrow(*rscale));</span>
+<a name="l04956"></a>04956 
+<a name="l04957"></a>04957   check_nomsg(cpl_table_duplicate_column(*int_obj,<span class="stringliteral">"COR_FCT_ALL"</span>,
+<a name="l04958"></a>04958                                          *rscale,<span class="stringliteral">"RATIO"</span>));
+<a name="l04959"></a>04959   check_nomsg(cpl_table_duplicate_column(*int_sky,<span class="stringliteral">"RATIO"</span>,*rscale,<span class="stringliteral">"RATIO"</span>));
+<a name="l04960"></a>04960   check_nomsg(cpl_table_multiply_columns(*int_sky,<span class="stringliteral">"INTC"</span>,<span class="stringliteral">"RATIO"</span>));
+<a name="l04961"></a>04961 
+<a name="l04962"></a>04962   check_nomsg(cpl_table_duplicate_column(*int_obj,<span class="stringliteral">"INTC"</span>,*int_obj,<span class="stringliteral">"INT"</span>));
+<a name="l04963"></a>04963   <span class="comment">//check_nomsg(cpl_table_save(*int_obj,NULL,NULL,</span>
+<a name="l04964"></a>04964   <span class="comment">//                             "out_obj1.fits",CPL_IO_DEFAULT));</span>
+<a name="l04965"></a>04965   <span class="comment">//check_nomsg(cpl_table_save(*int_sky,NULL,NULL,</span>
+<a name="l04966"></a>04966   <span class="comment">//                             "out_sky1.fits",CPL_IO_DEFAULT));</span>
+<a name="l04967"></a>04967 
+<a name="l04968"></a>04968   check_nomsg(cpl_table_duplicate_column(*int_obj,<span class="stringliteral">"SKYC"</span>,*int_sky,<span class="stringliteral">"INTC"</span>));
+<a name="l04969"></a>04969   check_nomsg(cpl_table_subtract_columns(*int_obj,<span class="stringliteral">"INTC"</span>,<span class="stringliteral">"SKYC"</span>));
+<a name="l04970"></a>04970 
+<a name="l04971"></a>04971 
+<a name="l04972"></a>04972   check_nomsg(cpl_table_erase_column(*int_sky,<span class="stringliteral">"INT"</span>));
+<a name="l04973"></a>04973   check_nomsg(cpl_table_name_column(*int_sky,<span class="stringliteral">"INTC"</span>,<span class="stringliteral">"INT"</span>));
+<a name="l04974"></a>04974 
+<a name="l04975"></a>04975 
+<a name="l04976"></a>04976 
+<a name="l04977"></a>04977  cleanup:
+<a name="l04978"></a>04978   sinfo_free_table(&llr_xxx1);
+<a name="l04979"></a>04979   sinfo_free_table(&hi_pos);
+<a name="l04980"></a>04980   sinfo_free_table(&low_pos);
+<a name="l04981"></a>04981   sinfo_free_table(&med_pos);
+<a name="l04982"></a>04982   sinfo_free_table(&low_regions);
+<a name="l04983"></a>04983   sinfo_free_table(&med_regions);
+<a name="l04984"></a>04984   sinfo_free_table(&hi_regions);
+<a name="l04985"></a>04985   sinfo_free_table(&low_scale);
+<a name="l04986"></a>04986   sinfo_free_table(&med_scale);
+<a name="l04987"></a>04987 
+<a name="l04988"></a>04988 
+<a name="l04989"></a>04989   sinfo_free_table(&finite_pix);
+<a name="l04990"></a>04990   sinfo_free_table(&xxx1_sub);
+<a name="l04991"></a>04991   sinfo_free_table(&tmp_tbl);
+<a name="l04992"></a>04992   sinfo_free_table(&rat_sky);
+<a name="l04993"></a>04993   sinfo_free_table(&fline_res);
+<a name="l04994"></a>04994   sinfo_free_table(&sky_cont);
+<a name="l04995"></a>04995   sinfo_free_table(&obj_cont);
+<a name="l04996"></a>04996   sinfo_free_table(&obj_line);
+<a name="l04997"></a>04997   sinfo_free_table(&sky_line);
+<a name="l04998"></a>04998   sinfo_free_table(&rscale0);
+<a name="l04999"></a>04999   sinfo_free_table(&xxx1);
+<a name="l05000"></a>05000   sinfo_free_table(&xxx2);
+<a name="l05001"></a>05001   sinfo_free_table(&line_regions);
+<a name="l05002"></a>05002   sinfo_free_table(&cont_regions);
+<a name="l05003"></a>05003   sinfo_free_table(&sky_lr);
+<a name="l05004"></a>05004   sinfo_free_table(&obj_lr);
+<a name="l05005"></a>05005   sinfo_free_table(&wav_lr);
+<a name="l05006"></a>05006   sinfo_free_array(&rfit);
+<a name="l05007"></a>05007   sinfo_free_array(&do_hk);
+<a name="l05008"></a>05008   <span class="keywordflow">return</span>;
+<a name="l05009"></a>05009 
+<a name="l05010"></a>05010 }
+<a name="l05019"></a>05019 <span class="keywordtype">int</span>
+<a name="l05020"></a>05020 sinfo_table_get_index_of_max(cpl_table* t,<span class="keyword">const</span> <span class="keywordtype">char</span>* name,cpl_type type)
+<a name="l05021"></a>05021 {
+<a name="l05022"></a>05022 
+<a name="l05023"></a>05023   <span class="keywordtype">int</span> i=0;
+<a name="l05024"></a>05024   <span class="keywordtype">int</span> result=0;
+<a name="l05025"></a>05025   <span class="keywordtype">int</span> nrow=0;
+<a name="l05026"></a>05026   <span class="keywordtype">int</span>* pi=NULL;
+<a name="l05027"></a>05027   <span class="keywordtype">float</span>* pf=NULL;
+<a name="l05028"></a>05028   <span class="keywordtype">double</span>* pd=NULL;
+<a name="l05029"></a>05029   <span class="keywordtype">double</span> max=0;
+<a name="l05030"></a>05030 
+<a name="l05031"></a>05031 
+<a name="l05032"></a>05032   <span class="keywordflow">if</span>(t == NULL) {
+<a name="l05033"></a>05033    cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT);
+<a name="l05034"></a>05034    <span class="keywordflow">return</span> result;
+<a name="l05035"></a>05035   }
+<a name="l05036"></a>05036   max=cpl_table_get_column_max(t,name);
+<a name="l05037"></a>05037   nrow=cpl_table_get_nrow(t);
+<a name="l05038"></a>05038   <span class="keywordflow">switch</span>(type) {
+<a name="l05039"></a>05039 
+<a name="l05040"></a>05040   <span class="keywordflow">case</span> CPL_TYPE_INT:
+<a name="l05041"></a>05041     pi=cpl_table_get_data_int(t,name);
+<a name="l05042"></a>05042     <span class="keywordflow">for</span>(i=0;i<nrow;i++) {
+<a name="l05043"></a>05043       <span class="keywordflow">if</span>(pi[i]==(<span class="keywordtype">int</span>)max) result=i;
+<a name="l05044"></a>05044     }
+<a name="l05045"></a>05045     <span class="keywordflow">break</span>;
+<a name="l05046"></a>05046   <span class="keywordflow">case</span> CPL_TYPE_FLOAT:
+<a name="l05047"></a>05047     pf=cpl_table_get_data_float(t,name);
+<a name="l05048"></a>05048     <span class="keywordflow">for</span>(i=0;i<nrow;i++) {
+<a name="l05049"></a>05049       <span class="keywordflow">if</span>(pf[i]==(<span class="keywordtype">float</span>)max) result=i;
+<a name="l05050"></a>05050     }
+<a name="l05051"></a>05051     <span class="keywordflow">break</span>;
+<a name="l05052"></a>05052   <span class="keywordflow">case</span> CPL_TYPE_DOUBLE:
+<a name="l05053"></a>05053     pd=cpl_table_get_data_double(t,name);
+<a name="l05054"></a>05054     <span class="keywordflow">for</span>(i=0;i<nrow;i++) {
+<a name="l05055"></a>05055       <span class="keywordflow">if</span>(pd[i]==max) result=i;
+<a name="l05056"></a>05056     }
+<a name="l05057"></a>05057     <span class="keywordflow">break</span>;
+<a name="l05058"></a>05058   <span class="keywordflow">default</span>:
+<a name="l05059"></a>05059     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Wrong column type"</span>);
+<a name="l05060"></a>05060    cpl_error_set(cpl_func, CPL_ERROR_TYPE_MISMATCH);
+<a name="l05061"></a>05061    <span class="keywordflow">return</span> result;
+<a name="l05062"></a>05062 
+<a name="l05063"></a>05063   }
+<a name="l05064"></a>05064   <span class="keywordflow">return</span> result;
+<a name="l05065"></a>05065 }
+<a name="l05066"></a>05066 
+<a name="l05067"></a>05067 
+<a name="l05068"></a>05068 
+<a name="l05078"></a>05078 <span class="keywordtype">int</span>
+<a name="l05079"></a>05079 sinfo_table_get_index_of_val(cpl_table* t,
+<a name="l05080"></a>05080                              <span class="keyword">const</span> <span class="keywordtype">char</span>* name,
+<a name="l05081"></a>05081                              <span class="keywordtype">double</span> val,
+<a name="l05082"></a>05082                              cpl_type type)
+<a name="l05083"></a>05083 {
+<a name="l05084"></a>05084 
+<a name="l05085"></a>05085   <span class="keywordtype">int</span> i=0;
+<a name="l05086"></a>05086   <span class="keywordtype">int</span> result=0;
+<a name="l05087"></a>05087   <span class="keywordtype">int</span> nrow=0;
+<a name="l05088"></a>05088   <span class="keywordtype">int</span>* pi=NULL;
+<a name="l05089"></a>05089   <span class="keywordtype">float</span>* pf=NULL;
+<a name="l05090"></a>05090   <span class="keywordtype">double</span>* pd=NULL;
+<a name="l05091"></a>05091 
+<a name="l05092"></a>05092   <span class="keywordflow">if</span>(t == NULL) {
+<a name="l05093"></a>05093    cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT);
+<a name="l05094"></a>05094    <span class="keywordflow">return</span> result;
+<a name="l05095"></a>05095   }
+<a name="l05096"></a>05096 
+<a name="l05097"></a>05097   nrow=cpl_table_get_nrow(t);
+<a name="l05098"></a>05098   <span class="keywordflow">switch</span>(type) {
+<a name="l05099"></a>05099 
+<a name="l05100"></a>05100   <span class="keywordflow">case</span> CPL_TYPE_INT:
+<a name="l05101"></a>05101     pi=cpl_table_get_data_int(t,name);
+<a name="l05102"></a>05102     <span class="keywordflow">for</span>(i=0;i<nrow;i++) {
+<a name="l05103"></a>05103       <span class="keywordflow">if</span>(pi[i]==(<span class="keywordtype">int</span>)val) result=i;
+<a name="l05104"></a>05104     }
+<a name="l05105"></a>05105     <span class="keywordflow">break</span>;
+<a name="l05106"></a>05106   <span class="keywordflow">case</span> CPL_TYPE_FLOAT:
+<a name="l05107"></a>05107     pf=cpl_table_get_data_float(t,name);
+<a name="l05108"></a>05108     <span class="keywordflow">for</span>(i=0;i<nrow;i++) {
+<a name="l05109"></a>05109       <span class="keywordflow">if</span>(pf[i]==(<span class="keywordtype">float</span>)val) result=i;
+<a name="l05110"></a>05110     }
+<a name="l05111"></a>05111     <span class="keywordflow">break</span>;
+<a name="l05112"></a>05112   <span class="keywordflow">case</span> CPL_TYPE_DOUBLE:
+<a name="l05113"></a>05113     pd=cpl_table_get_data_double(t,name);
+<a name="l05114"></a>05114     <span class="keywordflow">for</span>(i=0;i<nrow;i++) {
+<a name="l05115"></a>05115       <span class="keywordflow">if</span>(pd[i]==val) result=i;
+<a name="l05116"></a>05116     }
+<a name="l05117"></a>05117     <span class="keywordflow">break</span>;
+<a name="l05118"></a>05118   <span class="keywordflow">default</span>:
+<a name="l05119"></a>05119     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Wrong column type"</span>);
+<a name="l05120"></a>05120    cpl_error_set(cpl_func, CPL_ERROR_TYPE_MISMATCH);
+<a name="l05121"></a>05121    <span class="keywordflow">return</span> result;
+<a name="l05122"></a>05122 
+<a name="l05123"></a>05123   }
+<a name="l05124"></a>05124   <span class="keywordflow">return</span> result;
+<a name="l05125"></a>05125 }
+<a name="l05126"></a>05126 
+<a name="l05139"></a>05139 <span class="keywordtype">double</span>
+<a name="l05140"></a>05140 sinfo_table_column_interpolate(<span class="keyword">const</span> cpl_table* t,
+<a name="l05141"></a>05141                                <span class="keyword">const</span> <span class="keywordtype">char</span>* name,
+<a name="l05142"></a>05142                                <span class="keyword">const</span> <span class="keywordtype">double</span> x)
+<a name="l05143"></a>05143 {
+<a name="l05144"></a>05144 
+<a name="l05145"></a>05145   <span class="keywordtype">double</span> val1=0;
+<a name="l05146"></a>05146   <span class="keywordtype">double</span> val2=0;
+<a name="l05147"></a>05147   <span class="keywordtype">int</span> x1=0;
+<a name="l05148"></a>05148   <span class="keywordtype">int</span> x2=0;
+<a name="l05149"></a>05149   <span class="keywordtype">double</span> m=0;
+<a name="l05150"></a>05150   <span class="keywordtype">double</span> y=0;
+<a name="l05151"></a>05151   <span class="keywordtype">int</span> status=0;
+<a name="l05152"></a>05152   <span class="keywordtype">int</span> nrow=0;
+<a name="l05153"></a>05153   nrow=cpl_table_get_nrow(t);
+<a name="l05154"></a>05154   <span class="keywordflow">if</span> ((1<x) && (x<nrow-1)) {
+<a name="l05155"></a>05155     x1=x-1;
+<a name="l05156"></a>05156     x2=x+1;
+<a name="l05157"></a>05157   } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (x<2) {
+<a name="l05158"></a>05158     x1=0;
+<a name="l05159"></a>05159     x2=1;
+<a name="l05160"></a>05160   } <span class="keywordflow">else</span> {
+<a name="l05161"></a>05161     x1=nrow-2;
+<a name="l05162"></a>05162     x2=nrow-1;
+<a name="l05163"></a>05163   }
+<a name="l05164"></a>05164   check_nomsg(val1=cpl_table_get(t,name,x1,&status));
+<a name="l05165"></a>05165   check_nomsg(val2=cpl_table_get(t,name,x2,&status));
+<a name="l05166"></a>05166 
+<a name="l05167"></a>05167   m=(val2-val1)/(x2-x1);
+<a name="l05168"></a>05168   y=val1+m*(x-x1);
+<a name="l05169"></a>05169 
+<a name="l05170"></a>05170   <span class="keywordflow">return</span> y;
+<a name="l05171"></a>05171 
+<a name="l05172"></a>05172  cleanup:
+<a name="l05173"></a>05173 
+<a name="l05174"></a>05174   <span class="keywordflow">return</span> -1;
+<a name="l05175"></a>05175 
+<a name="l05176"></a>05176 
+<a name="l05177"></a>05177 }
+<a name="l05178"></a>05178 
+<a name="l05187"></a>05187 <span class="keyword">static</span> cpl_imagelist*
+<a name="l05188"></a>05188 sinfo_imagelist_select_range(<span class="keyword">const</span> cpl_imagelist* inp,
+<a name="l05189"></a>05189                                   <span class="keyword">const</span> cpl_table* full,
+<a name="l05190"></a>05190                                   <span class="keyword">const</span> cpl_table* good,
+<a name="l05191"></a>05191                                   <span class="keyword">const</span> <span class="keywordtype">double</span> tol)
+<a name="l05192"></a>05192 {
+<a name="l05193"></a>05193   cpl_imagelist* out=NULL;
+<a name="l05194"></a>05194   <span class="keywordtype">int</span> osz=0;
+<a name="l05195"></a>05195   <span class="keywordtype">int</span> isz=0;
+<a name="l05196"></a>05196   <span class="keywordtype">int</span> ksz=0;
+<a name="l05197"></a>05197   <span class="keywordtype">int</span> k=0;
+<a name="l05198"></a>05198   <span class="keywordtype">int</span> i=0;
+<a name="l05199"></a>05199   <span class="keywordtype">int</span> status=0;
+<a name="l05200"></a>05200 
+<a name="l05201"></a>05201   <span class="keywordtype">double</span> wave_chk=0;
+<a name="l05202"></a>05202   <span class="keywordtype">double</span> wave_sel=0;
+<a name="l05203"></a>05203 
+<a name="l05204"></a>05204   <span class="keyword">const</span> cpl_image* img=NULL;
+<a name="l05205"></a>05205 
+<a name="l05206"></a>05206 
+<a name="l05207"></a>05207   <span class="comment">/* Get Object relevant information */</span>
+<a name="l05208"></a>05208   <span class="comment">/* here one should scan the inp image constructing a wave range from it</span>
+<a name="l05209"></a>05209 <span class="comment">     and not from another table */</span>
+<a name="l05210"></a>05210   check_nomsg(osz=cpl_table_get_nrow(good));
+<a name="l05211"></a>05211   check_nomsg(ksz=cpl_imagelist_get_size(inp));
+<a name="l05212"></a>05212   check_nomsg(isz=cpl_table_get_nrow(good));
+<a name="l05213"></a>05213   check_nomsg(out=cpl_imagelist_new());
+<a name="l05214"></a>05214 
+<a name="l05215"></a>05215 
+<a name="l05216"></a>05216   <span class="keywordflow">for</span>(k=0;k<ksz;k++) {
+<a name="l05217"></a>05217     check_nomsg(img=cpl_imagelist_get_const(inp,k));
+<a name="l05218"></a>05218     check_nomsg(wave_chk=cpl_table_get(full,<span class="stringliteral">"WAVE"</span>,k,&status));
+<a name="l05219"></a>05219     <span class="keywordflow">if</span>(i<isz) {
+<a name="l05220"></a>05220       check_nomsg(wave_sel=cpl_table_get(good,<span class="stringliteral">"WAVE"</span>,i,&status));
+<a name="l05221"></a>05221     }
+<a name="l05222"></a>05222     <span class="comment">// insert cubes with wavelengths with appropriate values only</span>
+<a name="l05223"></a>05223     <span class="keywordflow">if</span>(fabs(wave_chk - wave_sel) < tol) {
+<a name="l05224"></a>05224       check_nomsg(cpl_imagelist_set(out,cpl_image_duplicate(img),i));
+<a name="l05225"></a>05225       i++;
+<a name="l05226"></a>05226     }
+<a name="l05227"></a>05227   }
+<a name="l05228"></a>05228   <span class="keywordflow">if</span>(i==0) {
+<a name="l05229"></a>05229     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"No lines selected"</span>);
+<a name="l05230"></a>05230     <span class="keywordflow">goto</span> cleanup;
+<a name="l05231"></a>05231   }
+<a name="l05232"></a>05232   <span class="keywordflow">return</span> out;
+<a name="l05233"></a>05233 
+<a name="l05234"></a>05234  cleanup:
+<a name="l05235"></a>05235 
+<a name="l05236"></a>05236   <span class="keywordflow">return</span> NULL;
+<a name="l05237"></a>05237 
+<a name="l05238"></a>05238 }
+<a name="l05239"></a>05239 
+<a name="l05249"></a>05249 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l05250"></a>05250 sinfo_table_extract_finite(<span class="keyword">const</span> cpl_table* in1,
+<a name="l05251"></a>05251                            <span class="keyword">const</span> cpl_table* in2,
+<a name="l05252"></a>05252                                  cpl_table** ou1,
+<a name="l05253"></a>05253                                  cpl_table** ou2)
+<a name="l05254"></a>05254 {
+<a name="l05255"></a>05255 
+<a name="l05256"></a>05256   <span class="keywordtype">int</span> size1=0;
+<a name="l05257"></a>05257   <span class="keywordtype">int</span> size2=0;
+<a name="l05258"></a>05258   <span class="keywordtype">int</span> i=0;
+<a name="l05259"></a>05259   <span class="keywordtype">int</span> ninv1=0;
+<a name="l05260"></a>05260   <span class="keywordtype">int</span> ninv2=0;
+<a name="l05261"></a>05261   <span class="keywordtype">double</span>* pout1=NULL;
+<a name="l05262"></a>05262   <span class="keywordtype">double</span>* pout2=NULL;
+<a name="l05263"></a>05263 
+<a name="l05264"></a>05264   cknull(in1,<span class="stringliteral">"null input image"</span>);
+<a name="l05265"></a>05265   cknull(in2,<span class="stringliteral">"null input image"</span>);
+<a name="l05266"></a>05266   cknull_nomsg(*ou1=cpl_table_duplicate(in1));
+<a name="l05267"></a>05267   cknull_nomsg(*ou2=cpl_table_duplicate(in2));
+<a name="l05268"></a>05268 
+<a name="l05269"></a>05269   check_nomsg(size1=cpl_table_get_nrow(*ou1));
+<a name="l05270"></a>05270   check_nomsg(size2=cpl_table_get_nrow(*ou2));
+<a name="l05271"></a>05271 
+<a name="l05272"></a>05272   check_nomsg(pout1=cpl_table_get_data_double(*ou1,<span class="stringliteral">"VALUE"</span>));
+<a name="l05273"></a>05273   check_nomsg(pout2=cpl_table_get_data_double(*ou2,<span class="stringliteral">"VALUE"</span>));
+<a name="l05274"></a>05274   <span class="keywordflow">for</span>(i=0;i<size1;i++) {
+<a name="l05275"></a>05275     <span class="keywordflow">if</span> (<a class="code" href="group__irplib__utils.html#ga804bfc739b5d55f9797ab881b1034ae4" title="portable isnan">irplib_isnan</a>(pout1[i])) {
+<a name="l05276"></a>05276       check_nomsg(cpl_table_set_invalid(*ou1,<span class="stringliteral">"VALUE"</span>,i));
+<a name="l05277"></a>05277       check_nomsg(cpl_table_set_invalid(*ou2,<span class="stringliteral">"VALUE"</span>,i));
+<a name="l05278"></a>05278     }
+<a name="l05279"></a>05279   }
+<a name="l05280"></a>05280   ninv1=cpl_table_count_invalid(*ou1,<span class="stringliteral">"VALUE"</span>);
+<a name="l05281"></a>05281   ninv2=cpl_table_count_invalid(*ou2,<span class="stringliteral">"VALUE"</span>);
+<a name="l05282"></a>05282   <span class="keywordflow">if</span>(ninv1==size1) {
+<a name="l05283"></a>05283     <span class="keywordflow">goto</span> cleanup;
+<a name="l05284"></a>05284   }
+<a name="l05285"></a>05285   <span class="keywordflow">if</span>(ninv2==size2) {
+<a name="l05286"></a>05286     <span class="keywordflow">goto</span> cleanup;
+<a name="l05287"></a>05287   }
+<a name="l05288"></a>05288   check_nomsg(cpl_table_erase_invalid(*ou1));
+<a name="l05289"></a>05289   check_nomsg(cpl_table_erase_invalid(*ou2));
+<a name="l05290"></a>05290   <span class="keywordflow">return</span> (size1-ninv1);
+<a name="l05291"></a>05291 
+<a name="l05292"></a>05292  cleanup:
+<a name="l05293"></a>05293   <span class="keywordflow">return</span> 0;
+<a name="l05294"></a>05294 
+<a name="l05295"></a>05295 }
+<a name="l05296"></a>05296 
+<a name="l05303"></a>05303 <span class="keyword">static</span> cpl_table*
+<a name="l05304"></a>05304 sinfo_image2table(<span class="keyword">const</span> cpl_image* im)
+<a name="l05305"></a>05305 {
+<a name="l05306"></a>05306   cpl_table* out=NULL;
+<a name="l05307"></a>05307   <span class="keywordtype">int</span> sx=0;
+<a name="l05308"></a>05308   <span class="keywordtype">int</span> sy=0;
+<a name="l05309"></a>05309   <span class="keyword">const</span> <span class="keywordtype">double</span>* pim=NULL;
+<a name="l05310"></a>05310   <span class="keywordtype">double</span>* pval=NULL;
+<a name="l05311"></a>05311   <span class="keywordtype">int</span> i=0;
+<a name="l05312"></a>05312   <span class="keywordtype">int</span> j=0;
+<a name="l05313"></a>05313   <span class="keywordtype">int</span> k=0;
+<a name="l05314"></a>05314 
+<a name="l05315"></a>05315   cknull(im,<span class="stringliteral">"input image is NULL"</span>);
+<a name="l05316"></a>05316 
+<a name="l05317"></a>05317   check_nomsg(sx=cpl_image_get_size_x(im));
+<a name="l05318"></a>05318   check_nomsg(sy=cpl_image_get_size_y(im));
+<a name="l05319"></a>05319   check_nomsg(pim=cpl_image_get_data_double_const(im));
+<a name="l05320"></a>05320   check_nomsg(out=cpl_table_new(sx*sy));
+<a name="l05321"></a>05321   check_nomsg(cpl_table_new_column(out,<span class="stringliteral">"VALUE"</span>,CPL_TYPE_DOUBLE));
+<a name="l05322"></a>05322   check_nomsg(pval=cpl_table_get_data_double(out,<span class="stringliteral">"VALUE"</span>));
+<a name="l05323"></a>05323 
+<a name="l05324"></a>05324   <span class="keywordflow">for</span>(j=0;j<sy;j++) {
+<a name="l05325"></a>05325     <span class="keywordflow">for</span>(i=0;i<sx;i++) {
+<a name="l05326"></a>05326       <span class="comment">/*</span>
+<a name="l05327"></a>05327 <span class="comment">      pval[k++]=pim[j*sx+i];</span>
+<a name="l05328"></a>05328 <span class="comment">      sinfo_msg("set tab %f",pim[j*sx+i]);</span>
+<a name="l05329"></a>05329 <span class="comment">      */</span>
+<a name="l05330"></a>05330       cpl_table_set_double(out,<span class="stringliteral">"VALUE"</span>,k++,pim[j*sx+i]);
+<a name="l05331"></a>05331     }
+<a name="l05332"></a>05332   }
+<a name="l05333"></a>05333 
+<a name="l05334"></a>05334   <span class="keywordflow">return</span> out;
+<a name="l05335"></a>05335  cleanup:
+<a name="l05336"></a>05336   sinfo_free_table(&out);
+<a name="l05337"></a>05337   <span class="keywordflow">return</span> NULL;
+<a name="l05338"></a>05338 
+<a name="l05339"></a>05339 }
+<a name="l05348"></a>05348 <span class="keywordtype">int</span>
+<a name="l05349"></a>05349 sinfo_check_screw_values(cpl_table** int_obj,
+<a name="l05350"></a>05350                          cpl_table** int_sky,
+<a name="l05351"></a>05351                          cpl_table* grange,
+<a name="l05352"></a>05352                          <span class="keyword">const</span> <span class="keywordtype">double</span> wtol)
+<a name="l05353"></a>05353 {
+<a name="l05354"></a>05354   <span class="comment">// check for screwy values at ends of spectrum</span>
+<a name="l05355"></a>05355   cpl_table* xsky=NULL;
+<a name="l05356"></a>05356   cpl_table* xobj=NULL;
+<a name="l05357"></a>05357 
+<a name="l05358"></a>05358   <span class="keywordtype">double</span> sky_min=0;
+<a name="l05359"></a>05359   <span class="keywordtype">double</span> sky_max=0;
+<a name="l05360"></a>05360   <span class="keywordtype">double</span> gsky_min=0;
+<a name="l05361"></a>05361   <span class="keywordtype">double</span> gsky_max=0;
+<a name="l05362"></a>05362   <span class="keywordtype">double</span> obj_min=0;
+<a name="l05363"></a>05363   <span class="keywordtype">double</span> obj_max=0;
+<a name="l05364"></a>05364   <span class="keywordtype">double</span> gobj_min=0;
+<a name="l05365"></a>05365   <span class="keywordtype">double</span> gobj_max=0;
+<a name="l05366"></a>05366 
+<a name="l05367"></a>05367   cknull(*int_sky,<span class="stringliteral">"Null input sky spectrum"</span>);
+<a name="l05368"></a>05368   cknull(*int_obj,<span class="stringliteral">"Null input obj spectrum"</span>);
+<a name="l05369"></a>05369   cknull(grange,<span class="stringliteral">"Null input wavelength range"</span>);
+<a name="l05370"></a>05370   <span class="comment">//check_nomsg(cpl_table_save(*int_sky,NULL,NULL,</span>
+<a name="l05371"></a>05371   <span class="comment">//                             "out_grange0.fits",CPL_IO_DEFAULT));</span>
+<a name="l05372"></a>05372   cknull_nomsg(xsky=sinfo_table_select_range(*int_sky,grange,wtol));
+<a name="l05373"></a>05373   <span class="comment">//check_nomsg(cpl_table_save(xsky,NULL,NULL,</span>
+<a name="l05374"></a>05374   <span class="comment">//                             "out_grange1.fits",CPL_IO_DEFAULT));</span>
+<a name="l05375"></a>05375   check_nomsg(sky_min=cpl_table_get_column_min(xsky,<span class="stringliteral">"INT"</span>));
+<a name="l05376"></a>05376   check_nomsg(sky_max=cpl_table_get_column_max(xsky,<span class="stringliteral">"INT"</span>));
+<a name="l05377"></a>05377   <span class="comment">//sinfo_msg("gskymax=%f gskymin=%f",sky_max,sky_min);</span>
+<a name="l05378"></a>05378 
+<a name="l05379"></a>05379   gsky_max = (sky_max>0) ? sky_max : 0;
+<a name="l05380"></a>05380   gsky_min = (sky_min<0) ? sky_min : 0;
+<a name="l05381"></a>05381   <span class="comment">//gsky_pos = where(int_sky > 1.*gsky_max || int_sky < 1.*gsky_min,gskypos_i);</span>
+<a name="l05382"></a>05382   check_nomsg(cpl_table_select_all(*int_sky));
+<a name="l05383"></a>05383   ck0_nomsg(sinfo_table_set_nan_out_min_max(int_sky,<span class="stringliteral">"INT"</span>,gsky_min,gsky_max));
+<a name="l05384"></a>05384   <span class="comment">//check_nomsg(cpl_table_save(*int_sky,NULL,NULL,</span>
+<a name="l05385"></a>05385   <span class="comment">//                             "out_gsky_pos.fits",CPL_IO_DEFAULT));</span>
+<a name="l05386"></a>05386 
+<a name="l05387"></a>05387   sinfo_free_table(&xsky);
+<a name="l05388"></a>05388   <span class="comment">//sinfo_msg("gsky_min=%f gsky_max=%f",gsky_min,gsky_max);</span>
+<a name="l05389"></a>05389 
+<a name="l05390"></a>05390   cknull_nomsg(xobj=sinfo_table_select_range(*int_obj,grange,wtol));
+<a name="l05391"></a>05391   check_nomsg(obj_min=cpl_table_get_column_min(xobj,<span class="stringliteral">"INT"</span>));
+<a name="l05392"></a>05392   check_nomsg(obj_max=cpl_table_get_column_max(xobj,<span class="stringliteral">"INT"</span>));
+<a name="l05393"></a>05393   <span class="comment">//check_nomsg(cpl_table_save(xobj,NULL,NULL,"out_xobj.fits",CPL_IO_DEFAULT));</span>
+<a name="l05394"></a>05394   gobj_max = (obj_max>0) ? obj_max : 0;
+<a name="l05395"></a>05395   gobj_min = (obj_min<0) ? obj_min : 0;
+<a name="l05396"></a>05396   <span class="comment">//gobj_pos=where(int_obj > 1.*gobj_max || int_obj < 1.*gobj_min,gobj_pos_i);</span>
+<a name="l05397"></a>05397   check_nomsg(cpl_table_select_all(*int_obj));
+<a name="l05398"></a>05398   ck0_nomsg(sinfo_table_set_nan_out_min_max(int_obj,<span class="stringliteral">"INT"</span>,gobj_min,gobj_max));
+<a name="l05399"></a>05399   <span class="comment">//check_nomsg(cpl_table_save(*int_obj,NULL,NULL,</span>
+<a name="l05400"></a>05400   <span class="comment">//              "out_gobj_pos.fits",CPL_IO_DEFAULT));</span>
+<a name="l05401"></a>05401   <span class="comment">//sinfo_msg("gobj_min=%f gobj_max=%f",gobj_min,gobj_max);</span>
+<a name="l05402"></a>05402   sinfo_free_table(&xobj);
+<a name="l05403"></a>05403 
+<a name="l05404"></a>05404   <span class="keywordflow">return</span> 0;
+<a name="l05405"></a>05405  cleanup:
+<a name="l05406"></a>05406   sinfo_free_table(&xsky);
+<a name="l05407"></a>05407   sinfo_free_table(&xobj);
+<a name="l05408"></a>05408 
+<a name="l05409"></a>05409   <span class="keywordflow">return</span> -1;
+<a name="l05410"></a>05410 
+<a name="l05411"></a>05411 
+<a name="l05412"></a>05412 }
+<a name="l05413"></a>05413 
+<a name="l05414"></a>05414 
+<a name="l05415"></a>05415 
+<a name="l05425"></a>05425 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l05426"></a>05426 sinfo_table_fill_column_over_range(cpl_table** inp,
+<a name="l05427"></a>05427                                    <span class="keyword">const</span> cpl_table* ref,
+<a name="l05428"></a>05428                                    <span class="keyword">const</span> <span class="keywordtype">char</span>* col,
+<a name="l05429"></a>05429                                    <span class="keyword">const</span> <span class="keywordtype">double</span> val,
+<a name="l05430"></a>05430                                    <span class="keyword">const</span> <span class="keywordtype">double</span> tol)
+<a name="l05431"></a>05431 {
+<a name="l05432"></a>05432 
+<a name="l05433"></a>05433   <span class="keywordtype">int</span> i=0;
+<a name="l05434"></a>05434   <span class="keywordtype">int</span> k=0;
+<a name="l05435"></a>05435   <span class="keywordtype">int</span> nref=0;
+<a name="l05436"></a>05436   <span class="keywordtype">int</span> ninp=0;
+<a name="l05437"></a>05437 
+<a name="l05438"></a>05438   <span class="keywordtype">double</span>* pwin=NULL;
+<a name="l05439"></a>05439   <span class="keywordtype">double</span>* pcin=NULL;
+<a name="l05440"></a>05440   <span class="keyword">const</span> <span class="keywordtype">double</span>* pwrf=NULL;
+<a name="l05441"></a>05441 
+<a name="l05442"></a>05442   cknull(inp,<span class="stringliteral">"null input table"</span>);
+<a name="l05443"></a>05443   cknull(ref,<span class="stringliteral">"null reference table"</span>);
+<a name="l05444"></a>05444 
+<a name="l05445"></a>05445   check_nomsg(ninp=cpl_table_get_nrow(*inp));
+<a name="l05446"></a>05446   check_nomsg(nref=cpl_table_get_nrow(ref));
+<a name="l05447"></a>05447   check_nomsg(pwin=cpl_table_get_data_double(*inp,<span class="stringliteral">"WAVE"</span>));
+<a name="l05448"></a>05448   check_nomsg(pcin=cpl_table_get_data_double(*inp,col));
+<a name="l05449"></a>05449   check_nomsg(pwrf=cpl_table_get_data_double_const(ref,<span class="stringliteral">"WAVE"</span>));
+<a name="l05450"></a>05450 
+<a name="l05451"></a>05451   k=0;
+<a name="l05452"></a>05452   i=0;
+<a name="l05453"></a>05453   <span class="comment">/*</span>
+<a name="l05454"></a>05454 <span class="comment">  sinfo_msg("ninp=%d nref=%d",ninp,nref);</span>
+<a name="l05455"></a>05455 <span class="comment">  sinfo_msg("winp(0)=%f wref(0)=%f tol=%f diff=%f",</span>
+<a name="l05456"></a>05456 <span class="comment">            pwin[0],pwrf[0],tol,fabs(pwin[0]-pwrf[0]));</span>
+<a name="l05457"></a>05457 <span class="comment">  */</span>
+<a name="l05458"></a>05458   <span class="keywordflow">if</span>(pwin[0]<=pwrf[0]) {
+<a name="l05459"></a>05459     <span class="comment">//sinfo_msg("case 1");</span>
+<a name="l05460"></a>05460     <span class="keywordflow">for</span>(i=0;i<ninp;i++) {
+<a name="l05461"></a>05461       <span class="keywordflow">if</span>(k<nref) {
+<a name="l05462"></a>05462     <span class="comment">/*</span>
+<a name="l05463"></a>05463 <span class="comment">        sinfo_msg("case1: %f %f %f %f %d %d",</span>
+<a name="l05464"></a>05464 <span class="comment">                  fabs(pwin[i] - pwrf[k]),tol,pwin[i],pwrf[k],i,k);</span>
+<a name="l05465"></a>05465 <span class="comment">    */</span>
+<a name="l05466"></a>05466     <span class="keywordflow">if</span>(fabs(pwin[i] - pwrf[k])< tol) {
+<a name="l05467"></a>05467       pcin[i]=val;
+<a name="l05468"></a>05468       k++;
+<a name="l05469"></a>05469     }
+<a name="l05470"></a>05470       }
+<a name="l05471"></a>05471     }
+<a name="l05472"></a>05472   } <span class="keywordflow">else</span> {
+<a name="l05473"></a>05473 
+<a name="l05474"></a>05474     <span class="comment">//pwin[0]>pwrf[0]</span>
+<a name="l05475"></a>05475     <span class="comment">//sinfo_msg("case 2");</span>
+<a name="l05476"></a>05476     <span class="keywordflow">for</span>(k=0;k<nref;k++) {
+<a name="l05477"></a>05477       <span class="keywordflow">if</span>(i<ninp) {
+<a name="l05478"></a>05478     <span class="comment">/*</span>
+<a name="l05479"></a>05479 <span class="comment">        sinfo_msg("case2: %f %f %f %f %d %d",</span>
+<a name="l05480"></a>05480 <span class="comment">                  fabs(pwin[i] - pwrf[k]),tol,pwin[i],pwrf[k],i,k);</span>
+<a name="l05481"></a>05481 <span class="comment">    */</span>
+<a name="l05482"></a>05482     <span class="keywordflow">if</span>(fabs(pwin[i] - pwrf[k])< tol) {
+<a name="l05483"></a>05483       pcin[i]=val;
+<a name="l05484"></a>05484       i++;
+<a name="l05485"></a>05485     }
+<a name="l05486"></a>05486       }
+<a name="l05487"></a>05487     }
+<a name="l05488"></a>05488   }
+<a name="l05489"></a>05489 
+<a name="l05490"></a>05490   <span class="keywordflow">return</span> 0;
+<a name="l05491"></a>05491 
+<a name="l05492"></a>05492  cleanup:
+<a name="l05493"></a>05493   <span class="keywordflow">return</span> -1;
+<a name="l05494"></a>05494 
+<a name="l05495"></a>05495 }
+<a name="l05496"></a>05496 
+<a name="l05497"></a>05497 
+<a name="l05506"></a>05506 <span class="keyword">static</span> cpl_table*
+<a name="l05507"></a>05507 sinfo_table_select_range(cpl_table* inp, cpl_table* ref,<span class="keyword">const</span> <span class="keywordtype">double</span> tol)
+<a name="l05508"></a>05508 {
+<a name="l05509"></a>05509 
+<a name="l05510"></a>05510   cpl_table* out=NULL;
+<a name="l05511"></a>05511   <span class="keywordtype">int</span> ninp=0;
+<a name="l05512"></a>05512   <span class="keywordtype">int</span> nref=0;
+<a name="l05513"></a>05513   <span class="keywordtype">int</span> nout=0;
+<a name="l05514"></a>05514 
+<a name="l05515"></a>05515   <span class="keywordtype">int</span> i=0;
+<a name="l05516"></a>05516   <span class="keywordtype">int</span> k=0;
+<a name="l05517"></a>05517   <span class="keywordtype">double</span>* pou;
+<a name="l05518"></a>05518   <span class="keywordtype">double</span>* prf;
+<a name="l05519"></a>05519   <span class="keywordtype">double</span> wmin=0;
+<a name="l05520"></a>05520   <span class="keywordtype">double</span> wmax=0;
+<a name="l05521"></a>05521   cpl_table* tmp=NULL;
+<a name="l05522"></a>05522   cknull(inp,<span class="stringliteral">"null input table"</span>);
+<a name="l05523"></a>05523   cknull(ref,<span class="stringliteral">"null reference table"</span>);
+<a name="l05524"></a>05524 
+<a name="l05525"></a>05525   check_nomsg(ninp=cpl_table_get_nrow(inp));
+<a name="l05526"></a>05526   check_nomsg(nref=cpl_table_get_nrow(ref));
+<a name="l05527"></a>05527   <span class="keywordflow">if</span>(ninp != nref) {
+<a name="l05528"></a>05528     <span class="comment">//sinfo_msg_warning("ninp != nref");</span>
+<a name="l05529"></a>05529     check_nomsg(wmin=cpl_table_get_column_min(ref,<span class="stringliteral">"WAVE"</span>));
+<a name="l05530"></a>05530     check_nomsg(wmax=cpl_table_get_column_max(ref,<span class="stringliteral">"WAVE"</span>));
+<a name="l05531"></a>05531     <span class="comment">//sinfo_msg_debug("wmin=%f wmax=%f",wmin,wmax);</span>
+<a name="l05532"></a>05532     cpl_table_select_all(inp);
+<a name="l05533"></a>05533     check_nomsg(ninp=cpl_table_and_selected_double(inp,<span class="stringliteral">"WAVE"</span>,
+<a name="l05534"></a>05534                                                    CPL_NOT_LESS_THAN,wmin));
+<a name="l05535"></a>05535     check_nomsg(tmp=cpl_table_extract_selected(inp));
+<a name="l05536"></a>05536     check_nomsg(ninp=cpl_table_and_selected_double(tmp,<span class="stringliteral">"WAVE"</span>,
+<a name="l05537"></a>05537                                                    CPL_NOT_GREATER_THAN,wmax));
+<a name="l05538"></a>05538     check_nomsg(out=cpl_table_extract_selected(tmp));
+<a name="l05539"></a>05539     sinfo_free_table(&tmp);
+<a name="l05540"></a>05540   } <span class="keywordflow">else</span> {
+<a name="l05541"></a>05541     check_nomsg(out=cpl_table_duplicate(inp));
+<a name="l05542"></a>05542   }
+<a name="l05543"></a>05543 
+<a name="l05544"></a>05544   check_nomsg(nout=cpl_table_get_nrow(out));
+<a name="l05545"></a>05545   <span class="keywordflow">if</span>(nout == 0) {
+<a name="l05546"></a>05546     <span class="comment">//sinfo_msg("nout=%d",nout);</span>
+<a name="l05547"></a>05547     <span class="keywordflow">goto</span> cleanup;
+<a name="l05548"></a>05548   }
+<a name="l05549"></a>05549   tmp=cpl_table_duplicate(out);
+<a name="l05550"></a>05550   sinfo_free_table(&out);
+<a name="l05551"></a>05551   check_nomsg(pou=cpl_table_get_data_double(tmp,<span class="stringliteral">"WAVE"</span>));
+<a name="l05552"></a>05552   check_nomsg(prf=cpl_table_get_data_double(ref,<span class="stringliteral">"WAVE"</span>));
+<a name="l05553"></a>05553 
+<a name="l05554"></a>05554   check_nomsg(cpl_table_new_column(tmp,<span class="stringliteral">"FLAG"</span>,CPL_TYPE_INT));
+<a name="l05555"></a>05555   check_nomsg(cpl_table_fill_column_window(tmp,<span class="stringliteral">"FLAG"</span>,0,nout,-1));
+<a name="l05556"></a>05556 
+<a name="l05557"></a>05557   k=0;
+<a name="l05558"></a>05558   i=0;
+<a name="l05559"></a>05559 
+<a name="l05560"></a>05560   <span class="comment">//sinfo_msg_debug("nout=%d nref=%d",nout,nref);</span>
+<a name="l05561"></a>05561   <span class="comment">//sinfo_msg_debug("wout(0)=%f wref(0)=%f tol=%f diff=%f",</span>
+<a name="l05562"></a>05562   <span class="comment">//          pou[0],prf[0],tol,fabs(pou[0]-prf[0]));</span>
+<a name="l05563"></a>05563 
+<a name="l05564"></a>05564   <span class="keywordflow">if</span>(pou[0]<=prf[0]) {
+<a name="l05565"></a>05565     <span class="comment">//sinfo_msg_debug("case 1");</span>
+<a name="l05566"></a>05566     <span class="keywordflow">for</span>(i=0;i<nout;i++) {
+<a name="l05567"></a>05567       <span class="keywordflow">if</span>(k<nref) {
+<a name="l05568"></a>05568     <span class="keywordflow">if</span>(fabs(pou[i] - prf[k])< tol) {
+<a name="l05569"></a>05569       check_nomsg(cpl_table_set_int(tmp,<span class="stringliteral">"FLAG"</span>,i,1));
+<a name="l05570"></a>05570       k++;
+<a name="l05571"></a>05571     }
+<a name="l05572"></a>05572       }
+<a name="l05573"></a>05573     }
+<a name="l05574"></a>05574   } <span class="keywordflow">else</span> {
+<a name="l05575"></a>05575 
+<a name="l05576"></a>05576     <span class="comment">//pou[0]>prf[0]</span>
+<a name="l05577"></a>05577     <span class="comment">//sinfo_msg_debug("case 2");</span>
+<a name="l05578"></a>05578     <span class="keywordflow">for</span>(k=0;k<nref;k++) {
+<a name="l05579"></a>05579       <span class="keywordflow">if</span>(i<nout) {
+<a name="l05580"></a>05580     <span class="comment">/*</span>
+<a name="l05581"></a>05581 <span class="comment">        sinfo_msg("check: %f %f %f %f",</span>
+<a name="l05582"></a>05582 <span class="comment">                  fabs(pou[i] - prf[k]),tol,pou[i],prf[k]);</span>
+<a name="l05583"></a>05583 <span class="comment">    */</span>
+<a name="l05584"></a>05584     <span class="keywordflow">if</span>(fabs(pou[i] - prf[k])< tol) {
+<a name="l05585"></a>05585       check_nomsg(cpl_table_set_int(tmp,<span class="stringliteral">"FLAG"</span>,i,1));
+<a name="l05586"></a>05586       i++;
+<a name="l05587"></a>05587     }
+<a name="l05588"></a>05588       }
+<a name="l05589"></a>05589     }
+<a name="l05590"></a>05590   }
+<a name="l05591"></a>05591   <span class="comment">//check_nomsg(cpl_table_save(tmp,NULL,NULL,"out_pre0.fits",CPL_IO_DEFAULT));</span>
+<a name="l05592"></a>05592   check_nomsg(nout=cpl_table_and_selected_int(tmp,<span class="stringliteral">"FLAG"</span>,CPL_GREATER_THAN,0));
+<a name="l05593"></a>05593   check_nomsg(out=cpl_table_extract_selected(tmp));
+<a name="l05594"></a>05594   sinfo_free_table(&tmp);
+<a name="l05595"></a>05595   check_nomsg(cpl_table_erase_column(out,<span class="stringliteral">"FLAG"</span>));
+<a name="l05596"></a>05596   <span class="keywordflow">if</span>(nout==0) {
+<a name="l05597"></a>05597     <span class="keywordflow">goto</span> cleanup;
+<a name="l05598"></a>05598   }
+<a name="l05599"></a>05599   <span class="comment">//check_nomsg(cpl_table_save(out,NULL,NULL,"out_post0.fits",CPL_IO_DEFAULT));</span>
+<a name="l05600"></a>05600   <span class="comment">/* sinfo_msg("nout=%d",nout); */</span>
+<a name="l05601"></a>05601   <span class="keywordflow">return</span> out;
+<a name="l05602"></a>05602 
+<a name="l05603"></a>05603  cleanup:
+<a name="l05604"></a>05604   sinfo_free_table(&tmp);
+<a name="l05605"></a>05605   sinfo_free_table(&out);
+<a name="l05606"></a>05606   <span class="keywordflow">return</span> NULL;
+<a name="l05607"></a>05607 
+<a name="l05608"></a>05608 }
+<a name="l05609"></a>05609 
+<a name="l05619"></a>05619 cpl_table*
+<a name="l05620"></a>05620 sinfo_interpolate_sky(<span class="keyword">const</span> cpl_table* inp,<span class="keyword">const</span> cpl_table* lambdas)
+<a name="l05621"></a>05621 {
+<a name="l05622"></a>05622   <span class="comment">//interpolate sky if necessary</span>
+<a name="l05623"></a>05623   cpl_table* <span class="keyword">new</span>=NULL;
+<a name="l05624"></a>05624   <span class="keyword">new</span> = sinfo_interpolate(inp,lambdas,<span class="stringliteral">"WAVE"</span>,<span class="stringliteral">"lsquadratic"</span>);;
+<a name="l05625"></a>05625 
+<a name="l05626"></a>05626   <span class="keywordflow">return</span> <span class="keyword">new</span>;
+<a name="l05627"></a>05627 }
+<a name="l05628"></a>05628 
+<a name="l05629"></a>05629 
+<a name="l05639"></a>05639 <span class="keyword">static</span> cpl_table*
+<a name="l05640"></a>05640 sinfo_interpolate(<span class="keyword">const</span> cpl_table* inp,
+<a name="l05641"></a>05641                   <span class="keyword">const</span> cpl_table* lambdas,
+<a name="l05642"></a>05642                   <span class="keyword">const</span> <span class="keywordtype">char</span>* name,
+<a name="l05643"></a>05643                   <span class="keyword">const</span> <span class="keywordtype">char</span>* method)
+<a name="l05644"></a>05644 {
+<a name="l05645"></a>05645   <span class="comment">//TODO</span>
+<a name="l05646"></a>05646   cpl_table* out=NULL;
+<a name="l05647"></a>05647 
+<a name="l05648"></a>05648   <span class="comment">//To remove compilation warnings</span>
+<a name="l05649"></a>05649   cknull_nomsg(lambdas);
+<a name="l05650"></a>05650   cknull_nomsg(name);
+<a name="l05651"></a>05651   cknull_nomsg(method);
+<a name="l05652"></a>05652 
+<a name="l05653"></a>05653   out=cpl_table_duplicate(inp);
+<a name="l05654"></a>05654   <span class="keywordflow">return</span> out;
+<a name="l05655"></a>05655 
+<a name="l05656"></a>05656  cleanup:
+<a name="l05657"></a>05657 
+<a name="l05658"></a>05658   <span class="keywordflow">return</span> NULL;
+<a name="l05659"></a>05659 
+<a name="l05660"></a>05660 }
+<a name="l05661"></a>05661 
+<a name="l05662"></a>05662 
+<a name="l05663"></a>05663 
+<a name="l05676"></a>05676 <span class="keyword">static</span> <span class="keywordtype">double</span>
+<a name="l05677"></a>05677 sinfo_gaussian_amp(<span class="keywordtype">double</span> area,<span class="keywordtype">double</span> sigma,<span class="keywordtype">double</span> x,<span class="keywordtype">double</span> x0,<span class="keywordtype">double</span> off)
+<a name="l05678"></a>05678 {
+<a name="l05679"></a>05679   <span class="keywordflow">return</span> area/sqrt(2*PI_NUMB*sigma*sigma)*
+<a name="l05680"></a>05680          exp(-(x-x0)*(x-x0)/(2*sigma*sigma))+off;
+<a name="l05681"></a>05681 }
+<a name="l05682"></a>05682 
+<a name="l05683"></a>05683 
+<a name="l05696"></a>05696 <span class="keyword">static</span> <span class="keywordtype">double</span>
+<a name="l05697"></a>05697 sinfo_gaussian_area(<span class="keywordtype">double</span> amp,<span class="keywordtype">double</span> sigma,<span class="keywordtype">double</span> x,<span class="keywordtype">double</span> x0,<span class="keywordtype">double</span> off)
+<a name="l05698"></a>05698 {
+<a name="l05699"></a>05699   <span class="keywordflow">return</span> sqrt(2*PI_NUMB*sigma*sigma)*exp((x-x0)*(x-x0)/(2*sigma*sigma))*
+<a name="l05700"></a>05700          (amp-off);
+<a name="l05701"></a>05701 }
+<a name="l05702"></a>05702 
+<a name="l05703"></a>05703 
+<a name="l05710"></a>05710 <span class="keywordtype">int</span>
+<a name="l05711"></a>05711 sinfo_table_smooth_column(cpl_table** t, <span class="keyword">const</span> <span class="keywordtype">char</span>* c, <span class="keyword">const</span> <span class="keywordtype">int</span> r)
+<a name="l05712"></a>05712 {
+<a name="l05713"></a>05713   <span class="keywordtype">int</span> nrow=0;
+<a name="l05714"></a>05714   <span class="keywordtype">int</span> i=0;
+<a name="l05715"></a>05715   <span class="keywordtype">int</span> j=0;
+<a name="l05716"></a>05716   <span class="keywordtype">double</span>* pval=NULL;
+<a name="l05717"></a>05717   <span class="keywordtype">double</span> sum;
+<a name="l05718"></a>05718   check_nomsg(nrow=cpl_table_get_nrow(*t));
+<a name="l05719"></a>05719   check_nomsg(pval=cpl_table_get_data_double(*t,c));
+<a name="l05720"></a>05720   <span class="keywordflow">for</span>(i=r;i<nrow;i++) {
+<a name="l05721"></a>05721     sum=0;
+<a name="l05722"></a>05722     <span class="keywordflow">for</span>(j=-r;j<=r;j++) {
+<a name="l05723"></a>05723       sum+=pval[i+j];
+<a name="l05724"></a>05724     }
+<a name="l05725"></a>05725     pval[i]=sum/(2*r+1);
+<a name="l05726"></a>05726   }
+<a name="l05727"></a>05727   <span class="keywordflow">return</span> 0;
+<a name="l05728"></a>05728  cleanup:
+<a name="l05729"></a>05729   <span class="keywordflow">return</span> -1;
+<a name="l05730"></a>05730 }
+<a name="l05731"></a>05731 
+<a name="l05740"></a>05740 <span class="keywordtype">void</span>
+<a name="l05741"></a>05741 sinfo_shift_sky(cpl_frame** sky_frm,
+<a name="l05742"></a>05742                 cpl_table** int_sky,
+<a name="l05743"></a>05743                 <span class="keyword">const</span> <span class="keywordtype">double</span> zshift)
+<a name="l05744"></a>05744 {
+<a name="l05745"></a>05745 
+<a name="l05746"></a>05746   <span class="keywordtype">int</span> xsz=0;
+<a name="l05747"></a>05747   <span class="keywordtype">int</span> ysz=0;
+<a name="l05748"></a>05748   <span class="keywordtype">int</span> zsz=0;
+<a name="l05749"></a>05749   cpl_propertylist* plist=NULL;
+<a name="l05750"></a>05750   cpl_imagelist* sky_cub=NULL;
+<a name="l05751"></a>05751   cpl_imagelist* sky_shift=NULL;
+<a name="l05752"></a>05752   cpl_table* int_sky_dup=NULL;
+<a name="l05753"></a>05753 
+<a name="l05754"></a>05754   <span class="keywordtype">double</span> min=0;
+<a name="l05755"></a>05755   <span class="keywordtype">double</span> max=0;
+<a name="l05756"></a>05756 
+<a name="l05757"></a>05757  <span class="comment">/* Get Object relevant information */</span>
+<a name="l05758"></a>05758   cknull_nomsg(plist=cpl_propertylist_load(
+<a name="l05759"></a>05759                      cpl_frame_get_filename(*sky_frm),0));
+<a name="l05760"></a>05760 
+<a name="l05761"></a>05761   check_nomsg(xsz=sinfo_pfits_get_naxis1(plist));
+<a name="l05762"></a>05762   check_nomsg(ysz=sinfo_pfits_get_naxis2(plist));
+<a name="l05763"></a>05763   check_nomsg(zsz=sinfo_pfits_get_naxis3(plist));
+<a name="l05764"></a>05764   sinfo_free_propertylist(&plist);
+<a name="l05765"></a>05765 
+<a name="l05766"></a>05766   cknull_nomsg(sky_cub=cpl_imagelist_load(cpl_frame_get_filename(*sky_frm),
+<a name="l05767"></a>05767                                             CPL_TYPE_FLOAT,0));
+<a name="l05768"></a>05768 
+<a name="l05769"></a>05769   check_nomsg(min=cpl_table_get_column_min(*int_sky,<span class="stringliteral">"INT"</span>));
+<a name="l05770"></a>05770   check_nomsg(max=cpl_table_get_column_max(*int_sky,<span class="stringliteral">"INT"</span>));
+<a name="l05771"></a>05771   int_sky_dup=cpl_table_duplicate(*int_sky);
+<a name="l05772"></a>05772   sinfo_free_table(&(*int_sky));
+<a name="l05773"></a>05773   <span class="comment">/*</span>
+<a name="l05774"></a>05774 <span class="comment">  cknull_nomsg(*int_sky=sinfo_table_shift_column_int(int_sky_dup,</span>
+<a name="l05775"></a>05775 <span class="comment">                                                     "INT", zshift,&zrest));</span>
+<a name="l05776"></a>05776 <span class="comment">  check_nomsg(cpl_table_save(*int_sky, NULL, NULL,</span>
+<a name="l05777"></a>05777 <span class="comment">                             "out_sky_shift1.fits", CPL_IO_DEFAULT));</span>
+<a name="l05778"></a>05778 <span class="comment">  sinfo_free_table(&(*int_sky));</span>
+<a name="l05779"></a>05779 <span class="comment"></span>
+<a name="l05780"></a>05780 <span class="comment">  sinfo_msg("min=%f max=%f",min,max);</span>
+<a name="l05781"></a>05781 <span class="comment">  check_nomsg(cpl_table_save(int_sky_dup, NULL, NULL,</span>
+<a name="l05782"></a>05782 <span class="comment">                             "out_sky_pre2.fits", CPL_IO_DEFAULT));</span>
+<a name="l05783"></a>05783 <span class="comment">  cknull_nomsg(*int_sky=sinfo_table_shift_column_poly(int_sky_dup,</span>
+<a name="l05784"></a>05784 <span class="comment">                                                      "INT", zshift,2));</span>
+<a name="l05785"></a>05785 <span class="comment">  check_nomsg(cpl_table_save(*int_sky, NULL, NULL,</span>
+<a name="l05786"></a>05786 <span class="comment">                             "out_sky_shift2.fits", CPL_IO_DEFAULT));</span>
+<a name="l05787"></a>05787 <span class="comment">  */</span>
+<a name="l05788"></a>05788   <span class="comment">//check_nomsg(cpl_table_save(int_sky_dup, NULL, NULL,</span>
+<a name="l05789"></a>05789   <span class="comment">//                             "out_sky_pre2.fits", CPL_IO_DEFAULT));</span>
+<a name="l05790"></a>05790   check_nomsg(*int_sky=sinfo_table_shift_simple(int_sky_dup,<span class="stringliteral">"INT"</span>,zshift));
+<a name="l05791"></a>05791   <span class="comment">/*</span>
+<a name="l05792"></a>05792 <span class="comment">  sinfo_free_table(&(*int_sky));</span>
+<a name="l05793"></a>05793 <span class="comment">  cknull_nomsg(*int_sky=sinfo_table_shift_column_spline3(int_sky_dup,</span>
+<a name="l05794"></a>05794 <span class="comment">                                                         "INT", zshift));</span>
+<a name="l05795"></a>05795 <span class="comment">  check_nomsg(cpl_table_save(*int_sky, NULL, NULL,</span>
+<a name="l05796"></a>05796 <span class="comment">                             "out_sky_shift3.fits", CPL_IO_DEFAULT));</span>
+<a name="l05797"></a>05797 <span class="comment">  */</span>
+<a name="l05798"></a>05798   sinfo_free_table(&int_sky_dup);
+<a name="l05799"></a>05799   <span class="comment">/*</span>
+<a name="l05800"></a>05800 <span class="comment">  check_nomsg(cpl_table_select_all(*int_sky));</span>
+<a name="l05801"></a>05801 <span class="comment">  check_nomsg(n=cpl_table_and_selected_double(*int_sky,"INT",</span>
+<a name="l05802"></a>05802 <span class="comment">                                              CPL_LESS_THAN,min));</span>
+<a name="l05803"></a>05803 <span class="comment">  ck0_nomsg(sinfo_table_set_column_invalid(int_sky,"INT"));</span>
+<a name="l05804"></a>05804 <span class="comment">  sinfo_msg("n=%d",n);</span>
+<a name="l05805"></a>05805 <span class="comment">  check_nomsg(cpl_table_select_all(*int_sky));</span>
+<a name="l05806"></a>05806 <span class="comment">  check_nomsg(n=cpl_table_and_selected_double(*int_sky,"INT",</span>
+<a name="l05807"></a>05807 <span class="comment">                CPL_GREATER_THAN,max));</span>
+<a name="l05808"></a>05808 <span class="comment">  sinfo_msg("n=%d",n);</span>
+<a name="l05809"></a>05809 <span class="comment">  ck0_nomsg(sinfo_table_set_column_invalid(int_sky,"INT"));</span>
+<a name="l05810"></a>05810 <span class="comment">  check_nomsg(cpl_table_select_all(*int_sky));</span>
+<a name="l05811"></a>05811 <span class="comment">  */</span>
+<a name="l05812"></a>05812   <span class="comment">//check_nomsg(cpl_table_save(*int_sky, NULL, NULL,</span>
+<a name="l05813"></a>05813   <span class="comment">//                           "out_sky_shift3.fits", CPL_IO_DEFAULT));</span>
+<a name="l05814"></a>05814 
+<a name="l05815"></a>05815 
+<a name="l05816"></a>05816 
+<a name="l05817"></a>05817   check_nomsg(sky_shift=sinfo_cube_zshift_simple(sky_cub,(<span class="keywordtype">float</span>)zshift));
+<a name="l05818"></a>05818 
+<a name="l05819"></a>05819   <span class="comment">//check_nomsg(sky_shift=sinfo_cube_zshift(sky_cub,zshift,&zrest));</span>
+<a name="l05820"></a>05820   <span class="comment">//check_nomsg(cpl_imagelist_save(sky_shift,"out_sky1.fits",</span>
+<a name="l05821"></a>05821   <span class="comment">//                 CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT));</span>
+<a name="l05822"></a>05822 
+<a name="l05823"></a>05823   sinfo_free_imagelist(&sky_shift);
+<a name="l05824"></a>05824   <span class="comment">//sinfo_free_imagelist(&sky_shift);</span>
+<a name="l05825"></a>05825   <span class="comment">//sinfo_msg("zrest=%f",zrest);</span>
+<a name="l05826"></a>05826 
+<a name="l05827"></a>05827   <span class="comment">//check_nomsg(sky_shift=sinfo_cube_zshift_poly(sky_cub,zshift,2));</span>
+<a name="l05828"></a>05828   <span class="comment">//check_nomsg(cpl_imagelist_save(sky_shift,"out_sky2.fits",</span>
+<a name="l05829"></a>05829   <span class="comment">//                               CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT));</span>
+<a name="l05830"></a>05830   <span class="comment">//sinfo_free_imagelist(&sky_shift);</span>
+<a name="l05831"></a>05831 
+<a name="l05832"></a>05832   <span class="comment">//check_nomsg(sky_shift=sinfo_cube_zshift_spline3(sky_cub,zshift));</span>
+<a name="l05833"></a>05833   <span class="comment">//check_nomsg(cpl_imagelist_save(sky_shift,"out_sky3.fits",</span>
+<a name="l05834"></a>05834   <span class="comment">//                               CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT));</span>
+<a name="l05835"></a>05835   <span class="comment">//sinfo_free_imagelist(&sky_shift);</span>
+<a name="l05836"></a>05836   sinfo_free_imagelist(&sky_cub);
+<a name="l05837"></a>05837 
+<a name="l05838"></a>05838   <span class="keywordflow">return</span>;
+<a name="l05839"></a>05839 
+<a name="l05840"></a>05840  cleanup:
+<a name="l05841"></a>05841   sinfo_free_table(&int_sky_dup);
+<a name="l05842"></a>05842   sinfo_free_propertylist(&plist);
+<a name="l05843"></a>05843   sinfo_free_imagelist(&sky_shift);
+<a name="l05844"></a>05844   sinfo_free_imagelist(&sky_cub);
+<a name="l05845"></a>05845   <span class="keywordflow">return</span>;
+<a name="l05846"></a>05846 }
+<a name="l05847"></a>05847 
+<a name="l05848"></a>05848 
+<a name="l05855"></a>05855 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l05856"></a>05856 sinfo_convolve_kernel(cpl_table** t, <span class="keyword">const</span> <span class="keywordtype">int</span> rad)
+<a name="l05857"></a>05857 {
+<a name="l05858"></a>05858   <span class="keywordtype">int</span> i=0;
+<a name="l05859"></a>05859   <span class="keywordtype">int</span> j=0;
+<a name="l05860"></a>05860   <span class="keywordtype">int</span> np=0;
+<a name="l05861"></a>05861   <span class="keywordtype">double</span> val=0;
+<a name="l05862"></a>05862   <span class="keywordtype">double</span>* pidata=NULL;
+<a name="l05863"></a>05863   <span class="keywordtype">double</span>* pcdata=NULL;
+<a name="l05864"></a>05864   <span class="keywordtype">double</span> dw=0;
+<a name="l05865"></a>05865   <span class="comment">//double dr=0;</span>
+<a name="l05866"></a>05866   <span class="keywordtype">double</span> ws=0;
+<a name="l05867"></a>05867   <span class="keywordtype">double</span> we=0;
+<a name="l05868"></a>05868   cknull(*t,<span class="stringliteral">"null input table"</span>);
+<a name="l05869"></a>05869   check_nomsg(cpl_table_new_column(*t,<span class="stringliteral">"CNV"</span>,CPL_TYPE_DOUBLE));
+<a name="l05870"></a>05870   check_nomsg(pidata=cpl_table_get_data_double(*t,<span class="stringliteral">"INT"</span>));
+<a name="l05871"></a>05871   check_nomsg(pcdata=cpl_table_get_data_double(*t,<span class="stringliteral">"CNV"</span>));
+<a name="l05872"></a>05872   check_nomsg(ws=cpl_table_get_column_min(*t,<span class="stringliteral">"WAVE"</span>));
+<a name="l05873"></a>05873   check_nomsg(we=cpl_table_get_column_max(*t,<span class="stringliteral">"WAVE"</span>));
+<a name="l05874"></a>05874   check_nomsg(np=cpl_table_get_nrow(*t));
+<a name="l05875"></a>05875   dw=(we-ws)/(np-1);
+<a name="l05876"></a>05876   <span class="comment">//dr=(we-ws)/(rad-1);</span>
+<a name="l05877"></a>05877   <span class="comment">/* set to 0 edges */</span>
+<a name="l05878"></a>05878   <span class="keywordflow">for</span>(i=0;i<rad;i++) {
+<a name="l05879"></a>05879     pcdata[i]=0.;
+<a name="l05880"></a>05880   }
+<a name="l05881"></a>05881   <span class="keywordflow">for</span>(i=np-rad;i<np;i++) {
+<a name="l05882"></a>05882     pcdata[i]=0.;
+<a name="l05883"></a>05883   }
+<a name="l05884"></a>05884   <span class="keywordflow">for</span>(i=rad;i<np-rad;i++) {
+<a name="l05885"></a>05885     val=0;
+<a name="l05886"></a>05886     <span class="keywordflow">for</span>(j=-rad;j<rad;j++) {
+<a name="l05887"></a>05887       val+=pidata[i+j];
+<a name="l05888"></a>05888     }
+<a name="l05889"></a>05889     <span class="comment">/*val*=dw; */</span>
+<a name="l05890"></a>05890     check_nomsg(cpl_table_set_double(*t,<span class="stringliteral">"CNV"</span>,i,val));
+<a name="l05891"></a>05891   }
+<a name="l05892"></a>05892   <span class="keywordflow">return</span> 0;
+<a name="l05893"></a>05893 
+<a name="l05894"></a>05894  cleanup:
+<a name="l05895"></a>05895   <span class="keywordflow">return</span> -1;
+<a name="l05896"></a>05896 
+<a name="l05897"></a>05897 }
+<a name="l05898"></a>05898 
+<a name="l05899"></a>05899 
+<a name="l05900"></a>05900 
+<a name="l05908"></a>05908 <span class="keywordtype">int</span>
+<a name="l05909"></a>05909 sinfo_convolve_kernel2(cpl_table** t, <span class="keyword">const</span> <span class="keywordtype">int</span> rad)
+<a name="l05910"></a>05910 {
+<a name="l05911"></a>05911   <span class="keywordtype">int</span> i=0;
+<a name="l05912"></a>05912   <span class="keywordtype">int</span> j=0;
+<a name="l05913"></a>05913   <span class="keywordtype">int</span> np=0;
+<a name="l05914"></a>05914   <span class="keywordtype">double</span> val=0;
+<a name="l05915"></a>05915   <span class="keywordtype">double</span>* pidata=NULL;
+<a name="l05916"></a>05916   <span class="keywordtype">double</span>* pcdata=NULL;
+<a name="l05917"></a>05917   <span class="keywordtype">double</span> dw=0;
+<a name="l05918"></a>05918   <span class="keywordtype">double</span> dr=0;
+<a name="l05919"></a>05919   <span class="keywordtype">double</span> ws=0;
+<a name="l05920"></a>05920   <span class="keywordtype">double</span> we=0;
+<a name="l05921"></a>05921   cknull(*t,<span class="stringliteral">"null input table"</span>);
+<a name="l05922"></a>05922   check_nomsg(cpl_table_new_column(*t,<span class="stringliteral">"CNV"</span>,CPL_TYPE_DOUBLE));
+<a name="l05923"></a>05923   check_nomsg(pidata=cpl_table_get_data_double(*t,<span class="stringliteral">"INT"</span>));
+<a name="l05924"></a>05924   check_nomsg(pcdata=cpl_table_get_data_double(*t,<span class="stringliteral">"CNV"</span>));
+<a name="l05925"></a>05925   check_nomsg(ws=cpl_table_get_column_min(*t,<span class="stringliteral">"WAVE"</span>));
+<a name="l05926"></a>05926   check_nomsg(we=cpl_table_get_column_max(*t,<span class="stringliteral">"WAVE"</span>));
+<a name="l05927"></a>05927   check_nomsg(np=cpl_table_get_nrow(*t));
+<a name="l05928"></a>05928   dw=(we-ws)/(np-1);
+<a name="l05929"></a>05929   dr=(we-ws)/(rad-1);
+<a name="l05930"></a>05930   <span class="comment">/* set to 0 edges */</span>
+<a name="l05931"></a>05931   <span class="keywordflow">for</span>(i=0;i<rad;i++) {
+<a name="l05932"></a>05932     pcdata[i]=0.;
+<a name="l05933"></a>05933   }
+<a name="l05934"></a>05934   <span class="keywordflow">for</span>(i=np-rad;i<np;i++) {
+<a name="l05935"></a>05935     pcdata[i]=0.;
+<a name="l05936"></a>05936   }
+<a name="l05937"></a>05937   <span class="keywordflow">for</span>(i=0;i<np-rad;i++) {
+<a name="l05938"></a>05938     val=0;
+<a name="l05939"></a>05939     <span class="keywordflow">for</span>(j=0;j<rad;j++) {
+<a name="l05940"></a>05940       val+=pidata[i+j];
+<a name="l05941"></a>05941     }
+<a name="l05942"></a>05942     <span class="comment">/*val*=dw; */</span>
+<a name="l05943"></a>05943     check_nomsg(cpl_table_set_double(*t,<span class="stringliteral">"CNV"</span>,i,val));
+<a name="l05944"></a>05944   }
+<a name="l05945"></a>05945   <span class="keywordflow">return</span> 0;
+<a name="l05946"></a>05946 
+<a name="l05947"></a>05947  cleanup:
+<a name="l05948"></a>05948   <span class="keywordflow">return</span> -1;
+<a name="l05949"></a>05949 
+<a name="l05950"></a>05950 }
+<a name="l05951"></a>05951 
+<a name="l05952"></a>05952 
+<a name="l05953"></a>05953 
+<a name="l05961"></a>05961 <span class="keywordtype">int</span>
+<a name="l05962"></a>05962 sinfo_convolve_exp(cpl_table** t, <span class="keyword">const</span> <span class="keywordtype">int</span> rad, <span class="keyword">const</span> <span class="keywordtype">double</span> fwhm)
+<a name="l05963"></a>05963 {
+<a name="l05964"></a>05964   <span class="keywordtype">int</span> i=0;
+<a name="l05965"></a>05965   <span class="keywordtype">int</span> j=0;
+<a name="l05966"></a>05966   <span class="keywordtype">int</span> np=0;
+<a name="l05967"></a>05967   <span class="keywordtype">double</span> ln2=0.693147180560;
+<a name="l05968"></a>05968   <span class="keywordtype">double</span> k=ln2/fwhm;
+<a name="l05969"></a>05969   <span class="keywordtype">double</span> val=0;
+<a name="l05970"></a>05970   <span class="keywordtype">double</span>* pidata=NULL;
+<a name="l05971"></a>05971   <span class="keywordtype">double</span>* pcdata=NULL;
+<a name="l05972"></a>05972   <span class="keywordtype">double</span> dw=0;
+<a name="l05973"></a>05973   <span class="comment">//double dr=0;</span>
+<a name="l05974"></a>05974   <span class="keywordtype">double</span> ws=0;
+<a name="l05975"></a>05975   <span class="keywordtype">double</span> we=0;
+<a name="l05976"></a>05976   cknull(*t,<span class="stringliteral">"null input table"</span>);
+<a name="l05977"></a>05977   check_nomsg(cpl_table_new_column(*t,<span class="stringliteral">"CNV"</span>,CPL_TYPE_DOUBLE));
+<a name="l05978"></a>05978   check_nomsg(pidata=cpl_table_get_data_double(*t,<span class="stringliteral">"INT"</span>));
+<a name="l05979"></a>05979   check_nomsg(pcdata=cpl_table_get_data_double(*t,<span class="stringliteral">"CNV"</span>));
+<a name="l05980"></a>05980   check_nomsg(ws=cpl_table_get_column_min(*t,<span class="stringliteral">"WAVE"</span>));
+<a name="l05981"></a>05981   check_nomsg(we=cpl_table_get_column_max(*t,<span class="stringliteral">"WAVE"</span>));
+<a name="l05982"></a>05982   check_nomsg(np=cpl_table_get_nrow(*t));
+<a name="l05983"></a>05983   dw=(we-ws)/(np-1);
+<a name="l05984"></a>05984   <span class="comment">//dr=(we-ws)/(rad-1);</span>
+<a name="l05985"></a>05985   <span class="comment">/* set to 0 edges */</span>
+<a name="l05986"></a>05986   <span class="keywordflow">for</span>(i=0;i<rad;i++) {
+<a name="l05987"></a>05987     pcdata[i]=0.;
+<a name="l05988"></a>05988   }
+<a name="l05989"></a>05989   <span class="keywordflow">for</span>(i=np-rad;i<np;i++) {
+<a name="l05990"></a>05990     pcdata[i]=0.;
+<a name="l05991"></a>05991   }
+<a name="l05992"></a>05992   <span class="keywordflow">for</span>(i=rad;i<np-rad;i++) {
+<a name="l05993"></a>05993     val=0;
+<a name="l05994"></a>05994     <span class="keywordflow">for</span>(j=-rad;j<rad;j++) {
+<a name="l05995"></a>05995       val+=pidata[i+j]*k*pow(2.0,-2.0*fabs(i-rad)/fwhm);
+<a name="l05996"></a>05996     }
+<a name="l05997"></a>05997     <span class="comment">/*val*=dw; */</span>
+<a name="l05998"></a>05998     check_nomsg(cpl_table_set_double(*t,<span class="stringliteral">"CNV"</span>,i,val));
+<a name="l05999"></a>05999   }
+<a name="l06000"></a>06000   <span class="keywordflow">return</span> 0;
+<a name="l06001"></a>06001 
+<a name="l06002"></a>06002  cleanup:
+<a name="l06003"></a>06003   <span class="keywordflow">return</span> -1;
+<a name="l06004"></a>06004 
+<a name="l06005"></a>06005 }
+<a name="l06006"></a>06006 
+<a name="l06007"></a>06007 
+<a name="l06016"></a>06016 <span class="keywordtype">int</span>
+<a name="l06017"></a>06017 sinfo_convolve_gauss(cpl_table** t, <span class="keyword">const</span> <span class="keywordtype">int</span> rad, <span class="keyword">const</span> <span class="keywordtype">double</span> fwhm)
+<a name="l06018"></a>06018 {
+<a name="l06019"></a>06019   <span class="keywordtype">int</span> i=0;
+<a name="l06020"></a>06020   <span class="keywordtype">int</span> j=0;
+<a name="l06021"></a>06021   <span class="keywordtype">int</span> np=0;
+<a name="l06022"></a>06022   <span class="keywordtype">double</span> val=0;
+<a name="l06023"></a>06023   <span class="keywordtype">double</span> sigma=fwhm/2.3548;
+<a name="l06024"></a>06024   <span class="keywordtype">double</span> sigma2=sigma*sigma;
+<a name="l06025"></a>06025   <span class="keywordtype">double</span>* pidata=NULL;
+<a name="l06026"></a>06026   <span class="keywordtype">double</span>* pcdata=NULL;
+<a name="l06027"></a>06027   <span class="keywordtype">double</span> dw=0;
+<a name="l06028"></a>06028   <span class="keywordtype">double</span> dr=0;
+<a name="l06029"></a>06029   <span class="keywordtype">double</span> ws=0;
+<a name="l06030"></a>06030   <span class="keywordtype">double</span> we=0;
+<a name="l06031"></a>06031   <span class="keywordtype">double</span> tx=0;
+<a name="l06032"></a>06032 
+<a name="l06033"></a>06033   cknull(*t,<span class="stringliteral">"null input table"</span>);
+<a name="l06034"></a>06034   check_nomsg(cpl_table_new_column(*t,<span class="stringliteral">"CNV"</span>,CPL_TYPE_DOUBLE));
+<a name="l06035"></a>06035   check_nomsg(pidata=cpl_table_get_data_double(*t,<span class="stringliteral">"INT"</span>));
+<a name="l06036"></a>06036   check_nomsg(pcdata=cpl_table_get_data_double(*t,<span class="stringliteral">"CNV"</span>));
+<a name="l06037"></a>06037   check_nomsg(ws=cpl_table_get_column_min(*t,<span class="stringliteral">"WAVE"</span>));
+<a name="l06038"></a>06038   check_nomsg(we=cpl_table_get_column_max(*t,<span class="stringliteral">"WAVE"</span>));
+<a name="l06039"></a>06039   check_nomsg(np=cpl_table_get_nrow(*t));
+<a name="l06040"></a>06040   dw=(we-ws)/(np-1);
+<a name="l06041"></a>06041   dr=(we-ws)/(rad-1);
+<a name="l06042"></a>06042   <span class="comment">/* set to 0 edges */</span>
+<a name="l06043"></a>06043   <span class="keywordflow">for</span>(i=0;i<rad;i++) {
+<a name="l06044"></a>06044     pcdata[i]=0.;
+<a name="l06045"></a>06045   }
+<a name="l06046"></a>06046   <span class="keywordflow">for</span>(i=np-rad;i<np;i++) {
+<a name="l06047"></a>06047     pcdata[i]=0.;
+<a name="l06048"></a>06048   }
+<a name="l06049"></a>06049   <span class="keywordflow">for</span>(i=rad;i<np-rad;i++) {
+<a name="l06050"></a>06050     val=0;
+<a name="l06051"></a>06051     <span class="keywordflow">for</span>(j=-rad;j<rad;j++) {
+<a name="l06052"></a>06052       tx=i-rad;
+<a name="l06053"></a>06053       val+=pidata[i+j]*exp(-tx*tx/2.0/sigma2)/(sigma*sqrt(2.0*PI_NUMB));
+<a name="l06054"></a>06054     }
+<a name="l06055"></a>06055     <span class="comment">/*val*=dw; */</span>
+<a name="l06056"></a>06056     check_nomsg(cpl_table_set_double(*t,<span class="stringliteral">"CNV"</span>,i,val));
+<a name="l06057"></a>06057   }
+<a name="l06058"></a>06058   <span class="keywordflow">return</span> 0;
+<a name="l06059"></a>06059 
+<a name="l06060"></a>06060  cleanup:
+<a name="l06061"></a>06061   <span class="keywordflow">return</span> -1;
+<a name="l06062"></a>06062 
+<a name="l06063"></a>06063 }
+<a name="l06064"></a>06064 
+<a name="l06065"></a>06065 
+<a name="l06066"></a>06066 
+<a name="l06078"></a>06078 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l06079"></a>06079 sinfo_scales_obj_sky_cubes(cpl_imagelist* obj_cub,
+<a name="l06080"></a>06080                             cpl_imagelist* sky_cub,
+<a name="l06081"></a>06081                             cpl_table* bkg,
+<a name="l06082"></a>06082                             cpl_table* rscale,
+<a name="l06083"></a>06083                             cpl_imagelist** obj_cor)
+<a name="l06084"></a>06084 {
+<a name="l06085"></a>06085 
+<a name="l06086"></a>06086 
+<a name="l06087"></a>06087   <span class="keywordtype">int</span> i=0;
+<a name="l06088"></a>06088   <span class="keywordtype">int</span> j=0;
+<a name="l06089"></a>06089   <span class="keywordtype">int</span> k=0;
+<a name="l06090"></a>06090   <span class="keywordtype">int</span> xsz=0;
+<a name="l06091"></a>06091   <span class="keywordtype">int</span> ysz=0;
+<a name="l06092"></a>06092   <span class="keywordtype">int</span> zsz=0;
+<a name="l06093"></a>06093 
+<a name="l06094"></a>06094   <span class="keywordtype">double</span>* podata=NULL;
+<a name="l06095"></a>06095   <span class="keywordtype">double</span>* psdata=NULL;
+<a name="l06096"></a>06096   <span class="keywordtype">double</span>* pbdata=NULL;
+<a name="l06097"></a>06097   <span class="keywordtype">double</span>* pcdata=NULL;
+<a name="l06098"></a>06098   <span class="keywordtype">double</span>* pscale=NULL;
+<a name="l06099"></a>06099 
+<a name="l06100"></a>06100 
+<a name="l06101"></a>06101   cpl_image* imgo=NULL;
+<a name="l06102"></a>06102   cpl_image* imgs=NULL;
+<a name="l06103"></a>06103   cpl_image* imgc=NULL;
+<a name="l06104"></a>06104 
+<a name="l06105"></a>06105 
+<a name="l06106"></a>06106   check_nomsg(imgo=cpl_imagelist_get(obj_cub,0));
+<a name="l06107"></a>06107   check_nomsg(xsz=cpl_image_get_size_x(imgo));
+<a name="l06108"></a>06108   check_nomsg(ysz=cpl_image_get_size_y(imgo));
+<a name="l06109"></a>06109   check_nomsg(zsz=cpl_imagelist_get_size(obj_cub));
+<a name="l06110"></a>06110 
+<a name="l06111"></a>06111   check_nomsg(*obj_cor=cpl_imagelist_duplicate(obj_cub));
+<a name="l06112"></a>06112 
+<a name="l06113"></a>06113   <span class="keywordflow">for</span>(k=0;k<zsz;k++) {
+<a name="l06114"></a>06114     check_nomsg(imgo=cpl_imagelist_get(obj_cub,k));
+<a name="l06115"></a>06115     check_nomsg(imgc=cpl_imagelist_get(*obj_cor,k));
+<a name="l06116"></a>06116     check_nomsg(imgs=cpl_imagelist_get(sky_cub,k));
+<a name="l06117"></a>06117 
+<a name="l06118"></a>06118     check_nomsg(podata=cpl_image_get_data_double(imgo));
+<a name="l06119"></a>06119     check_nomsg(pcdata=cpl_image_get_data_double(imgc));
+<a name="l06120"></a>06120     check_nomsg(psdata=cpl_image_get_data_double(imgs));
+<a name="l06121"></a>06121     check_nomsg(pbdata=cpl_table_get_data_double(bkg,<span class="stringliteral">"INT2"</span>));
+<a name="l06122"></a>06122     check_nomsg(pscale=cpl_table_get_data_double(rscale,<span class="stringliteral">"RATIO"</span>));
+<a name="l06123"></a>06123 
+<a name="l06124"></a>06124     <span class="keywordflow">for</span> (j=0;j<ysz; j++) {
+<a name="l06125"></a>06125       <span class="keywordflow">for</span> (i=0;i<xsz; i++) {
+<a name="l06126"></a>06126         <span class="keywordflow">if</span>(!<a class="code" href="group__irplib__utils.html#ga804bfc739b5d55f9797ab881b1034ae4" title="portable isnan">irplib_isnan</a>(podata[i+j*xsz]) &&
+<a name="l06127"></a>06127            !<a class="code" href="group__irplib__utils.html#ga804bfc739b5d55f9797ab881b1034ae4" title="portable isnan">irplib_isnan</a>(psdata[i+j*xsz]) &&
+<a name="l06128"></a>06128            !<a class="code" href="group__irplib__utils.html#ga804bfc739b5d55f9797ab881b1034ae4" title="portable isnan">irplib_isnan</a>(pbdata[k]) &&
+<a name="l06129"></a>06129            !<a class="code" href="group__irplib__utils.html#ga804bfc739b5d55f9797ab881b1034ae4" title="portable isnan">irplib_isnan</a>(pscale[k])) {
+<a name="l06130"></a>06130     pcdata[i+j*xsz] = podata[i+j*xsz]-
+<a name="l06131"></a>06131                           (psdata[i+j*xsz]-pbdata[k])*pscale[k];
+<a name="l06132"></a>06132     }
+<a name="l06133"></a>06133       }
+<a name="l06134"></a>06134     }
+<a name="l06135"></a>06135   }
+<a name="l06136"></a>06136 
+<a name="l06137"></a>06137 
+<a name="l06138"></a>06138   <span class="keywordflow">return</span> 0;
+<a name="l06139"></a>06139  cleanup:
+<a name="l06140"></a>06140 
+<a name="l06141"></a>06141   <span class="keywordflow">return</span> -1;
+<a name="l06142"></a>06142 }
+<a name="l06143"></a>06143 
+<a name="l06144"></a>06144 
+<a name="l06161"></a>06161 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l06162"></a>06162 sinfo_fitbkg(<span class="keyword">const</span> <span class="keywordtype">double</span> x[],
+<a name="l06163"></a>06163              <span class="keyword">const</span> <span class="keywordtype">double</span> a[],
+<a name="l06164"></a>06164              <span class="keywordtype">double</span> *result)
+<a name="l06165"></a>06165 {
+<a name="l06166"></a>06166 
+<a name="l06167"></a>06167 
+<a name="l06168"></a>06168   <span class="keywordtype">double</span> fac  = sinfo_fac(x[0],a[2]);
+<a name="l06169"></a>06169   <span class="comment">/*</span>
+<a name="l06170"></a>06170 <span class="comment">  int n=sizeof(x)/sizeof(double);</span>
+<a name="l06171"></a>06171 <span class="comment">  double fmin = sinfo_fac(x[0],a[2]);</span>
+<a name="l06172"></a>06172 <span class="comment">  double fmax = sinfo_fac(x[n-1],a[2]);</span>
+<a name="l06173"></a>06173 <span class="comment">  sinfo_msg("n=%d",n);</span>
+<a name="l06174"></a>06174 <span class="comment">  if(fmax < 0) sinfo_msg("fmax=%f",fmax);</span>
+<a name="l06175"></a>06175 <span class="comment">  */</span>
+<a name="l06176"></a>06176   <span class="comment">//*result = a[0]+a[1]*fac/sinfo_scale_fct;</span>
+<a name="l06177"></a>06177   *result = a[0]+a[1]*fac;
+<a name="l06178"></a>06178 
+<a name="l06179"></a>06179   <span class="keywordflow">return</span> 0;
+<a name="l06180"></a>06180 }
+<a name="l06181"></a>06181 
+<a name="l06205"></a>06205 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l06206"></a>06206 sinfo_fitbkg_derivative(<span class="keyword">const</span> <span class="keywordtype">double</span> x[],
+<a name="l06207"></a>06207                         <span class="keyword">const</span> <span class="keywordtype">double</span> a[],
+<a name="l06208"></a>06208                   <span class="keywordtype">double</span> d[])
+<a name="l06209"></a>06209 {
+<a name="l06210"></a>06210   <span class="keywordtype">double</span> c=14387.7;
+<a name="l06211"></a>06211   <span class="comment">/*</span>
+<a name="l06212"></a>06212 <span class="comment">  int n=sizeof(x)/sizeof(double);</span>
+<a name="l06213"></a>06213 <span class="comment">  double fmin = sinfo_fac(x[0],a[2]);</span>
+<a name="l06214"></a>06214 <span class="comment">  double fmax = sinfo_fac(x[n],a[2]);</span>
+<a name="l06215"></a>06215 <span class="comment">  */</span>
+<a name="l06216"></a>06216   <span class="keywordtype">double</span> fac  = sinfo_fac(x[0],a[2]);
+<a name="l06217"></a>06217   <span class="keywordtype">double</span> f2=0;
+<a name="l06218"></a>06218   <span class="comment">//double f1=0;</span>
+<a name="l06219"></a>06219   <span class="keywordtype">double</span> da=0.001;
+<a name="l06220"></a>06220   <span class="comment">//f1=a[0]+a[1]*fac;</span>
+<a name="l06221"></a>06221   <span class="comment">//f2=f1+da*a[0];</span>
+<a name="l06222"></a>06222   <span class="comment">//f2=a[0]+(a[1]+da*a[1])*fac;</span>
+<a name="l06223"></a>06223   f2=a[0]+a[1]*sinfo_fac(x[0],a[2]+da*a[2]);
+<a name="l06224"></a>06224   d[0]=1.;
+<a name="l06225"></a>06225   d[1]=fac;
+<a name="l06226"></a>06226   d[2]=a[1]*fac*fac*x[0]*x[0]*x[0]*x[0]*c/(a[2]*a[2])*exp(c/(x[0]*a[2]));
+<a name="l06227"></a>06227   <span class="comment">//sinfo_msg("d0=%g d1=%g d2=%g",d[0]*a[0]/f,d[1]*a[1]/f,d[2]*a[2]/f);</span>
+<a name="l06228"></a>06228   <span class="comment">//sinfo_msg("comp d1=%g",d[2]);</span>
+<a name="l06229"></a>06229   <span class="comment">//sinfo_msg("real d1=%g",(f2-f1)/(da*a[2]));</span>
+<a name="l06230"></a>06230 
+<a name="l06231"></a>06231   <span class="keywordflow">return</span> 0;
+<a name="l06232"></a>06232 }
+<a name="l06233"></a>06233 
+<a name="l06234"></a>06234 
+<a name="l06235"></a>06235 
+<a name="l06249"></a>06249 <span class="keyword">static</span> <span class="keywordtype">double</span>
+<a name="l06250"></a>06250 sinfo_fac(<span class="keyword">const</span> <span class="keywordtype">double</span> x, <span class="keyword">const</span> <span class="keywordtype">double</span> t)
+<a name="l06251"></a>06251 {
+<a name="l06252"></a>06252 
+<a name="l06253"></a>06253   <span class="keywordtype">double</span> c=14387.7;
+<a name="l06254"></a>06254 
+<a name="l06255"></a>06255   <span class="comment">//return pow(x,-5.)/(exp(c/(x*fabs(t)))-1.)/sinfo_scale_fct;</span>
+<a name="l06256"></a>06256   <span class="keywordflow">return</span> pow(x,-5.)/(exp(c/(x*fabs(t)))-1.);
+<a name="l06257"></a>06257 }
+<a name="l06258"></a>06258 
+<a name="l06268"></a>06268 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l06269"></a>06269 sinfo_table_threshold(cpl_table** t,
+<a name="l06270"></a>06270                       <span class="keyword">const</span> <span class="keywordtype">char</span>* column,
+<a name="l06271"></a>06271                       <span class="keyword">const</span> <span class="keywordtype">double</span> low_cut,
+<a name="l06272"></a>06272                       <span class="keyword">const</span> <span class="keywordtype">double</span> hig_cut,
+<a name="l06273"></a>06273                       <span class="keyword">const</span> <span class="keywordtype">double</span> low_ass,
+<a name="l06274"></a>06274                       <span class="keyword">const</span> <span class="keywordtype">double</span> hig_ass)
+<a name="l06275"></a>06275 {
+<a name="l06276"></a>06276 
+<a name="l06277"></a>06277   <span class="keywordtype">int</span> nrow=0;
+<a name="l06278"></a>06278   <span class="keywordtype">int</span> i=0;
+<a name="l06279"></a>06279   <span class="keywordtype">double</span>* pdata=NULL;
+<a name="l06280"></a>06280   cknull(*t,<span class="stringliteral">"null input table!"</span>);
+<a name="l06281"></a>06281 
+<a name="l06282"></a>06282   check_nomsg(nrow=cpl_table_get_nrow(*t));
+<a name="l06283"></a>06283   check_nomsg(pdata=cpl_table_get_data_double(*t,column));
+<a name="l06284"></a>06284 
+<a name="l06285"></a>06285   <span class="keywordflow">for</span>(i=0;i<nrow;i++) {
+<a name="l06286"></a>06286 
+<a name="l06287"></a>06287     <span class="keywordflow">if</span>(pdata[i]<low_cut) {
+<a name="l06288"></a>06288       pdata[i]=low_ass;
+<a name="l06289"></a>06289     }
+<a name="l06290"></a>06290     <span class="keywordflow">if</span> (pdata[i] >= hig_cut) {
+<a name="l06291"></a>06291       pdata[i]=hig_ass;
+<a name="l06292"></a>06292     }
+<a name="l06293"></a>06293 
+<a name="l06294"></a>06294   }
+<a name="l06295"></a>06295 
+<a name="l06296"></a>06296   <span class="keywordflow">return</span> 0;
+<a name="l06297"></a>06297 
+<a name="l06298"></a>06298  cleanup:
+<a name="l06299"></a>06299 
+<a name="l06300"></a>06300   <span class="keywordflow">return</span> -1;
+<a name="l06301"></a>06301 }
+<a name="l06302"></a>06302 
+<a name="l06331"></a>06331 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l06332"></a>06332 sinfo_table_set(cpl_table** inp,
+<a name="l06333"></a>06333                 <span class="keyword">const</span> cpl_table* ref,
+<a name="l06334"></a>06334                 <span class="keyword">const</span> <span class="keywordtype">double</span> val,
+<a name="l06335"></a>06335                 <span class="keyword">const</span> <span class="keywordtype">double</span> tol)
+<a name="l06336"></a>06336 {
+<a name="l06337"></a>06337 
+<a name="l06338"></a>06338   <span class="keywordtype">int</span> ninp=0;
+<a name="l06339"></a>06339   <span class="keywordtype">int</span> nref=0;
+<a name="l06340"></a>06340   <span class="keywordtype">double</span>* piw=NULL;
+<a name="l06341"></a>06341   <span class="keyword">const</span> <span class="keywordtype">double</span>* prw=NULL;
+<a name="l06342"></a>06342   <span class="keywordtype">double</span>* pir=NULL;
+<a name="l06343"></a>06343   <span class="keywordtype">int</span> i=0;
+<a name="l06344"></a>06344   <span class="keywordtype">int</span> k=0;
+<a name="l06345"></a>06345   cknull(*inp,<span class="stringliteral">"NULL input table"</span>);
+<a name="l06346"></a>06346   cknull(ref,<span class="stringliteral">"NULL reference table"</span>);
+<a name="l06347"></a>06347 
+<a name="l06348"></a>06348   check_nomsg(ninp=cpl_table_get_nrow(*inp));
+<a name="l06349"></a>06349   check_nomsg(nref=cpl_table_get_nrow(ref));
+<a name="l06350"></a>06350 
+<a name="l06351"></a>06351   check_nomsg(prw=cpl_table_get_data_double_const(ref,<span class="stringliteral">"WAVE"</span>));
+<a name="l06352"></a>06352   check_nomsg(piw=cpl_table_get_data_double(*inp,<span class="stringliteral">"WAVE"</span>));
+<a name="l06353"></a>06353   check_nomsg(pir=cpl_table_get_data_double(*inp,<span class="stringliteral">"RATIO"</span>));
+<a name="l06354"></a>06354 
+<a name="l06355"></a>06355 
+<a name="l06356"></a>06356   <span class="keywordflow">for</span>(i=0;i<ninp;i++) {
+<a name="l06357"></a>06357     <span class="comment">/*sinfo_msg("check =%g thresh=%g",fabs(piw[i]-prw[k]),tol); */</span>
+<a name="l06358"></a>06358     <span class="keywordflow">if</span>(fabs(piw[i]-prw[k]) < tol) {
+<a name="l06359"></a>06359       check_nomsg(cpl_table_set_double(*inp,<span class="stringliteral">"RATIO"</span>,i,val));
+<a name="l06360"></a>06360       k++;
+<a name="l06361"></a>06361     }
+<a name="l06362"></a>06362   }
+<a name="l06363"></a>06363   <span class="keywordflow">return</span> 0;
+<a name="l06364"></a>06364 
+<a name="l06365"></a>06365  cleanup:
+<a name="l06366"></a>06366 
+<a name="l06367"></a>06367   <span class="keywordflow">return</span> -1;
+<a name="l06368"></a>06368 
+<a name="l06369"></a>06369 }
+<a name="l06370"></a>06370 
+<a name="l06371"></a>06371 
+<a name="l06372"></a>06372 
+<a name="l06373"></a>06373 <span class="keyword">static</span> cpl_table*
+<a name="l06374"></a>06374 sinfo_table_shift_simple(cpl_table* inp,
+<a name="l06375"></a>06375                          <span class="keyword">const</span> <span class="keywordtype">char</span>* col,
+<a name="l06376"></a>06376                          <span class="keyword">const</span> <span class="keywordtype">double</span> shift)
+<a name="l06377"></a>06377 {
+<a name="l06378"></a>06378 
+<a name="l06379"></a>06379   <span class="keywordtype">int</span> nrow=0;
+<a name="l06380"></a>06380   cpl_table* out=NULL;
+<a name="l06381"></a>06381   <span class="keywordtype">int</span> is=(int)shift;
+<a name="l06382"></a>06382   <span class="keywordtype">double</span> ds=shift-is;
+<a name="l06383"></a>06383   <span class="keywordtype">double</span>* pi=NULL;
+<a name="l06384"></a>06384   <span class="keywordtype">double</span>* po=NULL;
+<a name="l06385"></a>06385   <span class="keywordtype">double</span> m=0;
+<a name="l06386"></a>06386   <span class="keywordtype">int</span> i=0;
+<a name="l06387"></a>06387   cknull(inp,<span class="stringliteral">"null input table"</span>);
+<a name="l06388"></a>06388 
+<a name="l06389"></a>06389   check_nomsg(nrow=cpl_table_get_nrow(inp));
+<a name="l06390"></a>06390   check_nomsg(out=cpl_table_duplicate(inp));
+<a name="l06391"></a>06391   check_nomsg(cpl_table_fill_column_window(out,col,0,nrow,0));
+<a name="l06392"></a>06392   check_nomsg(pi=cpl_table_get_data_double(inp,col));
+<a name="l06393"></a>06393   check_nomsg(po=cpl_table_get_data_double(out,col));
+<a name="l06394"></a>06394 
+<a name="l06395"></a>06395 
+<a name="l06396"></a>06396   <span class="keywordflow">for</span>(i=0;i<nrow;i++) {
+<a name="l06397"></a>06397     <span class="keywordflow">if</span>((i+is)>0 && (i+is+1) < nrow) {
+<a name="l06398"></a>06398       m=pi[i+is+1]-pi[i+is];
+<a name="l06399"></a>06399       po[i]=pi[i+is]+m*ds;
+<a name="l06400"></a>06400     }
+<a name="l06401"></a>06401   }
+<a name="l06402"></a>06402   <span class="keywordflow">return</span> out;
+<a name="l06403"></a>06403   cleanup:
+<a name="l06404"></a>06404   sinfo_free_table(&out);
+<a name="l06405"></a>06405   <span class="keywordflow">return</span> NULL;
+<a name="l06406"></a>06406 
+<a name="l06407"></a>06407 }
+<a name="l06408"></a>06408 
+<a name="l06409"></a>06409 
+<a name="l06410"></a>06410 
+<a name="l06411"></a>06411 
+<a name="l06412"></a>06412 <span class="keyword">static</span> cpl_imagelist*
+<a name="l06413"></a>06413 sinfo_cube_zshift_simple(cpl_imagelist* inp,
+<a name="l06414"></a>06414                         <span class="keyword">const</span> <span class="keywordtype">float</span> shift)
+<a name="l06415"></a>06415 {
+<a name="l06416"></a>06416 
+<a name="l06417"></a>06417   <span class="keywordtype">int</span> nx=0;
+<a name="l06418"></a>06418   <span class="keywordtype">int</span> ny=0;
+<a name="l06419"></a>06419   <span class="keywordtype">int</span> nz=0;
+<a name="l06420"></a>06420 
+<a name="l06421"></a>06421   <span class="keywordtype">int</span> i=0;
+<a name="l06422"></a>06422   <span class="keywordtype">int</span> j=0;
+<a name="l06423"></a>06423   <span class="keywordtype">int</span> k=0;
+<a name="l06424"></a>06424   <span class="keywordtype">int</span> ks=(int)shift;
+<a name="l06425"></a>06425 
+<a name="l06426"></a>06426   <span class="keywordtype">float</span> ds=shift-ks;
+<a name="l06427"></a>06427   <span class="keywordtype">float</span>* pu=NULL;
+<a name="l06428"></a>06428   <span class="keywordtype">float</span>* pl=NULL;
+<a name="l06429"></a>06429   <span class="keywordtype">float</span>* po=NULL;
+<a name="l06430"></a>06430 
+<a name="l06431"></a>06431   <span class="keywordtype">float</span>  int2=0;
+<a name="l06432"></a>06432   <span class="keywordtype">float</span>  int1=0;
+<a name="l06433"></a>06433   <span class="keywordtype">float</span> m=0;
+<a name="l06434"></a>06434 
+<a name="l06435"></a>06435   cpl_imagelist* out=NULL;
+<a name="l06436"></a>06436   cpl_image* imgu=NULL;
+<a name="l06437"></a>06437   cpl_image* imgl=NULL;
+<a name="l06438"></a>06438   cpl_image* imgo=NULL;
+<a name="l06439"></a>06439 
+<a name="l06440"></a>06440 
+<a name="l06441"></a>06441   cknull(inp,<span class="stringliteral">"null input cube"</span>);
+<a name="l06442"></a>06442 
+<a name="l06443"></a>06443   check_nomsg(nz=cpl_imagelist_get_size(inp));
+<a name="l06444"></a>06444   check_nomsg(out=cpl_imagelist_duplicate(inp));
+<a name="l06445"></a>06445   check_nomsg(imgo=cpl_imagelist_get(out,0));
+<a name="l06446"></a>06446   check_nomsg(nx=cpl_image_get_size_x(imgo));
+<a name="l06447"></a>06447   check_nomsg(ny=cpl_image_get_size_y(imgo));
+<a name="l06448"></a>06448 
+<a name="l06449"></a>06449   <span class="keywordflow">for</span>(k=0;k<nz;k++) {
+<a name="l06450"></a>06450     <span class="keywordflow">if</span>((k+ks)>0 && (k+ks+1) < nz) {
+<a name="l06451"></a>06451 
+<a name="l06452"></a>06452       check_nomsg(imgu=cpl_imagelist_get(inp,k+ks+1));
+<a name="l06453"></a>06453       check_nomsg(imgl=cpl_imagelist_get(inp,k+ks));
+<a name="l06454"></a>06454       check_nomsg(imgo=cpl_imagelist_get(out,k));
+<a name="l06455"></a>06455 
+<a name="l06456"></a>06456       check_nomsg(pu=cpl_image_get_data_float(imgu));
+<a name="l06457"></a>06457       check_nomsg(pl=cpl_image_get_data_float(imgl));
+<a name="l06458"></a>06458       check_nomsg(po=cpl_image_get_data_float(imgo));
+<a name="l06459"></a>06459 
+<a name="l06460"></a>06460 
+<a name="l06461"></a>06461       <span class="keywordflow">for</span>(j=0;j<ny;j++) {
+<a name="l06462"></a>06462     <span class="keywordflow">for</span>(i=0;i<nx;i++) {
+<a name="l06463"></a>06463           int2=pu[nx*j+i];
+<a name="l06464"></a>06464           int1=pl[nx*j+i];
+<a name="l06465"></a>06465       m=int2-int1;
+<a name="l06466"></a>06466       po[nx*j+i]=int1+m*ds;
+<a name="l06467"></a>06467     }
+<a name="l06468"></a>06468       }
+<a name="l06469"></a>06469     }
+<a name="l06470"></a>06470 
+<a name="l06471"></a>06471 
+<a name="l06472"></a>06472   }
+<a name="l06473"></a>06473   <span class="keywordflow">return</span> out;
+<a name="l06474"></a>06474   cleanup:
+<a name="l06475"></a>06475   sinfo_free_imagelist(&out);
+<a name="l06476"></a>06476   <span class="keywordflow">return</span> NULL;
+<a name="l06477"></a>06477 
+<a name="l06478"></a>06478 }
+<a name="l06479"></a>06479 
+<a name="l06480"></a>06480 
+<a name="l06491"></a>06491 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l06492"></a>06492 sinfo_get_line_ratio(cpl_table* obj_lin,
+<a name="l06493"></a>06493                       cpl_table* obj_cnt,
+<a name="l06494"></a>06494                       cpl_table* sky_lin,
+<a name="l06495"></a>06495                       cpl_table* sky_cnt,
+<a name="l06496"></a>06496                       <span class="keyword">const</span> <span class="keywordtype">int</span> method,
+<a name="l06497"></a>06497                       <span class="keywordtype">double</span>* r)
+<a name="l06498"></a>06498 {
+<a name="l06499"></a>06499 
+<a name="l06500"></a>06500   <span class="keywordtype">int</span> nobj;
+<a name="l06501"></a>06501   <span class="keywordtype">int</span> nsky;
+<a name="l06502"></a>06502   <span class="keywordtype">int</span> i=0;
+<a name="l06503"></a>06503 
+<a name="l06504"></a>06504   cpl_table* obj_dif=NULL;
+<a name="l06505"></a>06505   cpl_table* sky_dif=NULL;
+<a name="l06506"></a>06506 
+<a name="l06507"></a>06507   <span class="keywordtype">double</span>* poi=NULL;
+<a name="l06508"></a>06508   <span class="keywordtype">double</span>* psi=NULL;
+<a name="l06509"></a>06509   <span class="keywordtype">double</span>* pvd=NULL;
+<a name="l06510"></a>06510   <span class="keywordtype">double</span>* pvn=NULL;
+<a name="l06511"></a>06511   <span class="keywordtype">double</span>* pvr=NULL;
+<a name="l06512"></a>06512 
+<a name="l06513"></a>06513   cpl_vector* num=NULL;
+<a name="l06514"></a>06514   cpl_vector* den=NULL;
+<a name="l06515"></a>06515   cpl_vector* rat=NULL;
+<a name="l06516"></a>06516   cpl_vector* wav=NULL;
+<a name="l06517"></a>06517   <span class="keywordtype">double</span> mnum=0;
+<a name="l06518"></a>06518   <span class="keywordtype">double</span> mden=0;
+<a name="l06519"></a>06519   <span class="keywordtype">double</span> tnum=0;
+<a name="l06520"></a>06520   <span class="keywordtype">double</span> tden=0;
+<a name="l06521"></a>06521   cpl_size pows[2];
+<a name="l06522"></a>06522   cpl_polynomial* cfit=NULL;
+<a name="l06523"></a>06523   <span class="keywordtype">double</span> mse=0;
+<a name="l06524"></a>06524 
+<a name="l06525"></a>06525   cknull(obj_lin,<span class="stringliteral">"null obj line table"</span>);
+<a name="l06526"></a>06526   cknull(sky_lin,<span class="stringliteral">"null sky line table"</span>);
+<a name="l06527"></a>06527 
+<a name="l06528"></a>06528   cknull(obj_cnt,<span class="stringliteral">"null obj cont table"</span>);
+<a name="l06529"></a>06529   cknull(sky_cnt,<span class="stringliteral">"null sky cont table"</span>);
+<a name="l06530"></a>06530 
+<a name="l06531"></a>06531 
+<a name="l06532"></a>06532   cknull_nomsg(obj_dif=sinfo_table_subtract_continuum(obj_lin,obj_cnt));
+<a name="l06533"></a>06533   cknull_nomsg(sky_dif=sinfo_table_subtract_continuum(sky_lin,sky_cnt));
+<a name="l06534"></a>06534 
+<a name="l06535"></a>06535   check_nomsg(nobj=cpl_table_get_nrow(obj_dif));
+<a name="l06536"></a>06536   check_nomsg(nsky=cpl_table_get_nrow(sky_dif));
+<a name="l06537"></a>06537 
+<a name="l06538"></a>06538 
+<a name="l06539"></a>06539 
+<a name="l06540"></a>06540   <span class="keywordflow">if</span>(nobj != nsky) {
+<a name="l06541"></a>06541     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"obj and sky table must have the same no of rows!"</span>);
+<a name="l06542"></a>06542     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"nobj=%d nsky=%d"</span>,nobj,nsky);
+<a name="l06543"></a>06543     <span class="keywordflow">goto</span> cleanup;
+<a name="l06544"></a>06544   }
+<a name="l06545"></a>06545   <span class="comment">//sinfo_msg("Object sky residuals/Sky lines ratio determination method=%d",</span>
+<a name="l06546"></a>06546   <span class="comment">//          method);</span>
+<a name="l06547"></a>06547   <span class="keywordflow">if</span>(method == 0) {
+<a name="l06548"></a>06548     ck0_nomsg(sinfo_get_line_ratio_amoeba(obj_dif,sky_dif,r));
+<a name="l06549"></a>06549     sinfo_free_table(&obj_dif);
+<a name="l06550"></a>06550     sinfo_free_table(&sky_dif);
+<a name="l06551"></a>06551    <span class="keywordflow">return</span> 0;
+<a name="l06552"></a>06552   }
+<a name="l06553"></a>06553 
+<a name="l06554"></a>06554 
+<a name="l06555"></a>06555   check_nomsg(poi=cpl_table_get_data_double(obj_dif,<span class="stringliteral">"INT"</span>));
+<a name="l06556"></a>06556   check_nomsg(psi=cpl_table_get_data_double(sky_dif,<span class="stringliteral">"INT"</span>));
+<a name="l06557"></a>06557 
+<a name="l06558"></a>06558   check_nomsg(num=cpl_vector_new(nobj));
+<a name="l06559"></a>06559   check_nomsg(den=cpl_vector_new(nobj));
+<a name="l06560"></a>06560   check_nomsg(rat=cpl_vector_new(nobj));
+<a name="l06561"></a>06561   check_nomsg(cpl_vector_fill(num,0));
+<a name="l06562"></a>06562   check_nomsg(cpl_vector_fill(den,0));
+<a name="l06563"></a>06563   check_nomsg(cpl_vector_fill(rat,0));
+<a name="l06564"></a>06564   check_nomsg(pvd=cpl_vector_get_data(den));
+<a name="l06565"></a>06565   check_nomsg(pvn=cpl_vector_get_data(num));
+<a name="l06566"></a>06566   check_nomsg(pvr=cpl_vector_get_data(rat));
+<a name="l06567"></a>06567 
+<a name="l06568"></a>06568   <span class="keywordflow">for</span>(i=0;i<nobj;i++) {
+<a name="l06569"></a>06569     <span class="keywordflow">if</span>(!<a class="code" href="group__irplib__utils.html#ga804bfc739b5d55f9797ab881b1034ae4" title="portable isnan">irplib_isnan</a>(psi[i]) &&
+<a name="l06570"></a>06570        !<a class="code" href="group__irplib__utils.html#ga804bfc739b5d55f9797ab881b1034ae4" title="portable isnan">irplib_isnan</a>(poi[i]) &&
+<a name="l06571"></a>06571        !<a class="code" href="group__irplib__utils.html#ga09a11edf52efa78ddafce0bb4fa3b71f" title="portable isinf">irplib_isinf</a>(psi[i]) &&
+<a name="l06572"></a>06572        !<a class="code" href="group__irplib__utils.html#ga09a11edf52efa78ddafce0bb4fa3b71f" title="portable isinf">irplib_isinf</a>(poi[i]) ) {
+<a name="l06573"></a>06573       pvn[i]=psi[i]*poi[i];
+<a name="l06574"></a>06574       pvd[i]=psi[i]*psi[i];
+<a name="l06575"></a>06575       <span class="keywordflow">if</span>(psi[i] != 0) {
+<a name="l06576"></a>06576          pvr[i]=poi[i]/psi[i];
+<a name="l06577"></a>06577       }
+<a name="l06578"></a>06578     }
+<a name="l06579"></a>06579   }
+<a name="l06580"></a>06580   sinfo_free_table(&sky_dif);
+<a name="l06581"></a>06581 
+<a name="l06582"></a>06582   check_nomsg(mnum=cpl_vector_get_median_const(num));
+<a name="l06583"></a>06583   check_nomsg(mden=cpl_vector_get_median_const(den));
+<a name="l06584"></a>06584   check_nomsg(tnum=cpl_vector_get_mean(num)*nobj);
+<a name="l06585"></a>06585   check_nomsg(tden=cpl_vector_get_mean(den)*nobj);
+<a name="l06586"></a>06586 
+<a name="l06587"></a>06587   <span class="comment">//sinfo_msg("mden=%g tden=%g",mden,tden);</span>
+<a name="l06588"></a>06588   <span class="comment">//sinfo_msg("mnum=%g tnum=%g",mnum,tnum);</span>
+<a name="l06589"></a>06589   sinfo_free_my_vector(&num);
+<a name="l06590"></a>06590   sinfo_free_my_vector(&den);
+<a name="l06591"></a>06591   <span class="keywordflow">if</span>(method == 1) {
+<a name="l06592"></a>06592     *r=tnum/tden;
+<a name="l06593"></a>06593   } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (method == 2) {
+<a name="l06594"></a>06594     *r=mnum/mden;
+<a name="l06595"></a>06595   } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (method == 3) {
+<a name="l06596"></a>06596     *r=cpl_vector_get_median_const(rat);
+<a name="l06597"></a>06597   } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (method == 4) {
+<a name="l06598"></a>06598     *r=cpl_vector_get_mean(rat);
+<a name="l06599"></a>06599   } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (method == 5) {
+<a name="l06600"></a>06600 
+<a name="l06601"></a>06601     check_nomsg(wav=cpl_vector_wrap(nobj,
+<a name="l06602"></a>06602                     cpl_table_get_data_double(obj_dif,<span class="stringliteral">"WAVE"</span>)));
+<a name="l06603"></a>06603     check_nomsg(cfit=sinfo_polynomial_fit_1d_create(wav,rat,0,&mse));
+<a name="l06604"></a>06604     sinfo_unwrap_vector(&wav);
+<a name="l06605"></a>06605     pows[0]=0;
+<a name="l06606"></a>06606     pows[1]=0;
+<a name="l06607"></a>06607     check_nomsg(*r=cpl_polynomial_get_coeff(cfit,pows));
+<a name="l06608"></a>06608     sinfo_free_polynomial(&cfit);
+<a name="l06609"></a>06609 
+<a name="l06610"></a>06610   }
+<a name="l06611"></a>06611 
+<a name="l06612"></a>06612   sinfo_free_table(&obj_dif);
+<a name="l06613"></a>06613   sinfo_free_my_vector(&rat);
+<a name="l06614"></a>06614   <span class="keywordflow">return</span> 0;
+<a name="l06615"></a>06615  cleanup:
+<a name="l06616"></a>06616   sinfo_free_table(&obj_dif);
+<a name="l06617"></a>06617   sinfo_free_table(&sky_dif);
+<a name="l06618"></a>06618   sinfo_free_my_vector(&num);
+<a name="l06619"></a>06619   sinfo_free_my_vector(&den);
+<a name="l06620"></a>06620   sinfo_free_my_vector(&rat);
+<a name="l06621"></a>06621   sinfo_unwrap_vector(&wav);
+<a name="l06622"></a>06622 
+<a name="l06623"></a>06623   <span class="keywordflow">return</span> -1;
+<a name="l06624"></a>06624 }
+<a name="l06625"></a>06625 
+<a name="l06626"></a>06626 
+<a name="l06627"></a>06627 
+<a name="l06628"></a>06628 
+<a name="l06638"></a>06638 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l06639"></a>06639 sinfo_get_line_ratio_amoeba(cpl_table* obj,
+<a name="l06640"></a>06640                             cpl_table* sky,
+<a name="l06641"></a>06641                             <span class="keywordtype">double</span>* r)
+<a name="l06642"></a>06642 {
+<a name="l06643"></a>06643 
+<a name="l06644"></a>06644 
+<a name="l06645"></a>06645   <span class="keywordtype">int</span> i=0;
+<a name="l06646"></a>06646   <span class="keyword">const</span> <span class="keywordtype">int</span> MP=2;
+<a name="l06647"></a>06647   <span class="keyword">const</span> <span class="keywordtype">int</span> NP=1;
+<a name="l06648"></a>06648   <span class="keywordtype">double</span> y[MP];
+<a name="l06649"></a>06649   <span class="keywordtype">double</span> p0[NP];
+<a name="l06650"></a>06650   <span class="keywordtype">double</span>** ap=NULL;
+<a name="l06651"></a>06651   <span class="keywordtype">int</span> nfunc=0;
+<a name="l06652"></a>06652   <span class="keywordtype">int</span> np=0;
+<a name="l06653"></a>06653   check_nomsg(np=cpl_table_get_nrow(obj));
+<a name="l06654"></a>06654   check_nomsg(sa_ox=cpl_vector_wrap(np,cpl_table_get_data_double(obj,<span class="stringliteral">"WAVE"</span>)));
+<a name="l06655"></a>06655   check_nomsg(sa_oy=cpl_vector_wrap(np,cpl_table_get_data_double(obj,<span class="stringliteral">"INT"</span>)));
+<a name="l06656"></a>06656   check_nomsg(sa_sy=cpl_vector_wrap(np,cpl_table_get_data_double(sky,<span class="stringliteral">"INT"</span>)));
+<a name="l06657"></a>06657   <span class="comment">// Amoeba part</span>
+<a name="l06658"></a>06658 
+<a name="l06659"></a>06659 
+<a name="l06660"></a>06660   ap=(<span class="keywordtype">double</span>**) cpl_calloc(MP,<span class="keyword">sizeof</span>(<span class="keywordtype">double</span>*));
+<a name="l06661"></a>06661   <span class="keywordflow">for</span>(i=0;i<MP;i++) {
+<a name="l06662"></a>06662     ap[i]=cpl_calloc(NP,<span class="keyword">sizeof</span>(<span class="keywordtype">double</span>));
+<a name="l06663"></a>06663   }
+<a name="l06664"></a>06664 
+<a name="l06665"></a>06665   ap[0][0]=-1.;
+<a name="l06666"></a>06666   ap[1][0]=+1.;
+<a name="l06667"></a>06667 
+<a name="l06668"></a>06668   <span class="comment">//sinfo_msg("Before amoeba fit");</span>
+<a name="l06669"></a>06669   <span class="comment">//sinfo_msg("ap[0][0]=%g ap[0][1]=%g",ap[0][0],ap[1][0]);</span>
+<a name="l06670"></a>06670   <span class="keywordflow">for</span>(i=0;i<MP;i++) {
+<a name="l06671"></a>06671     p0[0]=ap[i][0];
+<a name="l06672"></a>06672     y[i]=sinfo_fit_sky(p0);
+<a name="l06673"></a>06673   }
+<a name="l06674"></a>06674 
+<a name="l06675"></a>06675 
+<a name="l06676"></a>06676   check_nomsg(sinfo_fit_amoeba(ap,y,NP,AMOEBA_FTOL,sinfo_fit_sky,&nfunc));
+<a name="l06677"></a>06677 
+<a name="l06678"></a>06678   sinfo_msg(<span class="stringliteral">"After amoeba fit"</span>);
+<a name="l06679"></a>06679   sinfo_msg(<span class="stringliteral">"ap[0][0]=%g ap[0][1]=%g"</span>,ap[0][0],ap[1][0]);
+<a name="l06680"></a>06680 
+<a name="l06681"></a>06681   *r=ap[0][0];
+<a name="l06682"></a>06682 
+<a name="l06683"></a>06683   sinfo_unwrap_vector(&sa_ox);
+<a name="l06684"></a>06684   sinfo_unwrap_vector(&sa_oy);
+<a name="l06685"></a>06685   sinfo_unwrap_vector(&sa_sy);
+<a name="l06686"></a>06686   sinfo_new_destroy_2Ddoublearray(&ap,MP);
+<a name="l06687"></a>06687 
+<a name="l06688"></a>06688 
+<a name="l06689"></a>06689   <span class="keywordflow">return</span> 0;
+<a name="l06690"></a>06690 
+<a name="l06691"></a>06691  cleanup:
+<a name="l06692"></a>06692   sinfo_unwrap_vector(&sa_ox);
+<a name="l06693"></a>06693   sinfo_unwrap_vector(&sa_oy);
+<a name="l06694"></a>06694   sinfo_unwrap_vector(&sa_sy);
+<a name="l06695"></a>06695   sinfo_new_destroy_2Ddoublearray(&ap,MP);
+<a name="l06696"></a>06696 
+<a name="l06697"></a>06697   <span class="keywordflow">return</span> -1;
+<a name="l06698"></a>06698 
+<a name="l06699"></a>06699 }
+<a name="l06700"></a>06700 
+<a name="l06701"></a>06701 
+<a name="l06702"></a>06702 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l06711"></a>06711 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l06712"></a>06712 
+<a name="l06713"></a>06713 <span class="keyword">static</span> <span class="keywordtype">double</span>
+<a name="l06714"></a>06714 sinfo_fit_sky(<span class="keywordtype">double</span> p[])
+<a name="l06715"></a>06715 
+<a name="l06716"></a>06716 {
+<a name="l06717"></a>06717   <span class="keywordtype">double</span>* ps=NULL;
+<a name="l06718"></a>06718   <span class="keywordtype">double</span>* po=NULL;
+<a name="l06719"></a>06719   <span class="keywordtype">double</span>* pv=NULL;
+<a name="l06720"></a>06720   cpl_vector* vtmp=NULL;
+<a name="l06721"></a>06721   <span class="keywordtype">int</span> i=0;
+<a name="l06722"></a>06722   <span class="keywordtype">int</span> np=0;
+<a name="l06723"></a>06723   cpl_size pows[2];
+<a name="l06724"></a>06724   <span class="keywordtype">double</span> mse=0;
+<a name="l06725"></a>06725   <span class="keywordtype">double</span> cont=0;
+<a name="l06726"></a>06726   cpl_polynomial* pfit=NULL;
+<a name="l06727"></a>06727 
+<a name="l06728"></a>06728   <span class="keywordtype">double</span> rms=0;
+<a name="l06729"></a>06729 
+<a name="l06730"></a>06730 
+<a name="l06731"></a>06731   <span class="comment">//fit residual obj continuum and subtract it</span>
+<a name="l06732"></a>06732   check_nomsg(pfit=sinfo_polynomial_fit_1d_create(sa_ox,sa_oy,0,&mse));
+<a name="l06733"></a>06733   pows[0]=0;
+<a name="l06734"></a>06734   pows[1]=0;
+<a name="l06735"></a>06735   check_nomsg(cont=cpl_polynomial_get_coeff(pfit,pows));
+<a name="l06736"></a>06736   check_nomsg(sinfo_free_polynomial(&pfit));
+<a name="l06737"></a>06737   check_nomsg(cpl_vector_subtract_scalar(sa_oy,cont));
+<a name="l06738"></a>06738 
+<a name="l06739"></a>06739 
+<a name="l06740"></a>06740   <span class="comment">//fit residual sky continuum and subtract it</span>
+<a name="l06741"></a>06741   check_nomsg(pfit=sinfo_polynomial_fit_1d_create(sa_ox,sa_sy,0,&mse));
+<a name="l06742"></a>06742   pows[0]=0;
+<a name="l06743"></a>06743   pows[1]=0;
+<a name="l06744"></a>06744   check_nomsg(cont=cpl_polynomial_get_coeff(pfit,pows));
+<a name="l06745"></a>06745   check_nomsg(sinfo_free_polynomial(&pfit));
+<a name="l06746"></a>06746   check_nomsg(cpl_vector_subtract_scalar(sa_sy,cont));
+<a name="l06747"></a>06747 
+<a name="l06748"></a>06748   <span class="comment">//computes diff=(obj-conto)-(sky-contsky)*p[0]</span>
+<a name="l06749"></a>06749   check_nomsg(po= cpl_vector_get_data(sa_oy));
+<a name="l06750"></a>06750   check_nomsg(ps= cpl_vector_get_data(sa_sy));
+<a name="l06751"></a>06751 
+<a name="l06752"></a>06752   check_nomsg(np=cpl_vector_get_size(sa_oy));
+<a name="l06753"></a>06753   check_nomsg(vtmp=cpl_vector_new(np));
+<a name="l06754"></a>06754   check_nomsg(pv= cpl_vector_get_data(vtmp));
+<a name="l06755"></a>06755 
+<a name="l06756"></a>06756 
+<a name="l06757"></a>06757   <span class="keywordflow">for</span>(i=0;i<np;i++) {
+<a name="l06758"></a>06758     pv[i]=po[i]-ps[i]*p[0];
+<a name="l06759"></a>06759   }
+<a name="l06760"></a>06760   <span class="comment">//computes rms diff</span>
+<a name="l06761"></a>06761   check_nomsg(rms=cpl_vector_get_stdev(vtmp));
+<a name="l06762"></a>06762   sinfo_free_my_vector(&vtmp);
+<a name="l06763"></a>06763   <span class="keywordflow">return</span> rms;
+<a name="l06764"></a>06764  cleanup:
+<a name="l06765"></a>06765   sinfo_free_my_vector(&vtmp);
+<a name="l06766"></a>06766   <span class="keywordflow">return</span> -1;
+<a name="l06767"></a>06767 
+<a name="l06768"></a>06768 }
+<a name="l06769"></a>06769 
+<a name="l06770"></a>06770 
+<a name="l06771"></a>06771 
+<a name="l06783"></a>06783 <span class="keyword">static</span> cpl_table*
+<a name="l06784"></a>06784 sinfo_table_interpol(cpl_table* obj_lin,
+<a name="l06785"></a>06785                      cpl_table* obj_cnt,
+<a name="l06786"></a>06786                      cpl_table* sky_lin,
+<a name="l06787"></a>06787                      cpl_table* sky_cnt,
+<a name="l06788"></a>06788                      <span class="keyword">const</span> <span class="keywordtype">double</span> r)
+<a name="l06789"></a>06789 {
+<a name="l06790"></a>06790 
+<a name="l06791"></a>06791   cpl_table* out=NULL;
+<a name="l06792"></a>06792   cpl_table* obj_dif=NULL;
+<a name="l06793"></a>06793   cpl_table* sky_dif=NULL;
+<a name="l06794"></a>06794   cknull(obj_lin,<span class="stringliteral">"null line table"</span>);
+<a name="l06795"></a>06795   cknull(obj_cnt,<span class="stringliteral">"null cont table"</span>);
+<a name="l06796"></a>06796 
+<a name="l06797"></a>06797   cknull_nomsg(obj_dif=sinfo_table_subtract_continuum(obj_lin,obj_cnt));
+<a name="l06798"></a>06798   cknull_nomsg(sky_dif=sinfo_table_subtract_continuum(sky_lin,sky_cnt));
+<a name="l06799"></a>06799 
+<a name="l06800"></a>06800   check_nomsg(out=cpl_table_duplicate(obj_dif));
+<a name="l06801"></a>06801   check_nomsg(cpl_table_duplicate_column(out,<span class="stringliteral">"CSKY"</span>,sky_dif,<span class="stringliteral">"INT"</span>));
+<a name="l06802"></a>06802   check_nomsg(cpl_table_multiply_scalar(out,<span class="stringliteral">"CSKY"</span>,r));
+<a name="l06803"></a>06803   check_nomsg(cpl_table_subtract_columns(out,<span class="stringliteral">"INT"</span>,<span class="stringliteral">"CSKY"</span>));
+<a name="l06804"></a>06804 
+<a name="l06805"></a>06805   sinfo_free_table(&obj_dif);
+<a name="l06806"></a>06806   sinfo_free_table(&sky_dif);
+<a name="l06807"></a>06807 
+<a name="l06808"></a>06808   <span class="keywordflow">return</span> out;
+<a name="l06809"></a>06809 
+<a name="l06810"></a>06810  cleanup:
+<a name="l06811"></a>06811   sinfo_free_table(&obj_dif);
+<a name="l06812"></a>06812   sinfo_free_table(&sky_dif);
+<a name="l06813"></a>06813   sinfo_free_table(&out);
+<a name="l06814"></a>06814   <span class="keywordflow">return</span> NULL;
+<a name="l06815"></a>06815 
+<a name="l06816"></a>06816 }
+<a name="l06817"></a>06817 
+<a name="l06818"></a>06818 
+<a name="l06819"></a>06819 
+<a name="l06820"></a>06820 
+<a name="l06821"></a>06821 
+<a name="l06822"></a>06822 
+<a name="l06831"></a>06831 <span class="keyword">static</span> cpl_table*
+<a name="l06832"></a>06832 sinfo_table_subtract_continuum(cpl_table* lin,
+<a name="l06833"></a>06833                                cpl_table* cnt)
+<a name="l06834"></a>06834 
+<a name="l06835"></a>06835 {
+<a name="l06836"></a>06836 
+<a name="l06837"></a>06837   cpl_table* out=NULL;
+<a name="l06838"></a>06838   <span class="keywordtype">int</span> nlin=0;
+<a name="l06839"></a>06839   <span class="keywordtype">int</span> ncnt=0;
+<a name="l06840"></a>06840   <span class="keywordtype">int</span> i=0;
+<a name="l06841"></a>06841   <span class="keywordtype">double</span>* poi=NULL;
+<a name="l06842"></a>06842   cpl_vector* vx=NULL;
+<a name="l06843"></a>06843   cpl_vector* vy=NULL;
+<a name="l06844"></a>06844   cpl_polynomial* cfit=NULL;
+<a name="l06845"></a>06845   cpl_size pows[2];
+<a name="l06846"></a>06846   <span class="keywordtype">double</span> mse=0;
+<a name="l06847"></a>06847   <span class="keywordtype">double</span> yfit=0;
+<a name="l06848"></a>06848 
+<a name="l06849"></a>06849   cknull(lin,<span class="stringliteral">"null line table"</span>);
+<a name="l06850"></a>06850   cknull(cnt,<span class="stringliteral">"null cont table"</span>);
+<a name="l06851"></a>06851   check_nomsg(out=cpl_table_duplicate(lin));
+<a name="l06852"></a>06852   check_nomsg(cpl_table_new_column(out,<span class="stringliteral">"CONT"</span>,CPL_TYPE_DOUBLE));
+<a name="l06853"></a>06853   check_nomsg(nlin=cpl_table_get_nrow(lin));
+<a name="l06854"></a>06854   check_nomsg(ncnt=cpl_table_get_nrow(cnt));
+<a name="l06855"></a>06855   <span class="comment">//sinfo_msg("nlin=%d",nlin);</span>
+<a name="l06856"></a>06856   check_nomsg(cpl_table_fill_column_window(out,<span class="stringliteral">"CONT"</span>,0,nlin,0));
+<a name="l06857"></a>06857 
+<a name="l06858"></a>06858   <span class="comment">//do a uniform fit</span>
+<a name="l06859"></a>06859   check_nomsg(vx=cpl_vector_wrap(ncnt,cpl_table_get_data_double(cnt,<span class="stringliteral">"WAVE"</span>)));
+<a name="l06860"></a>06860   check_nomsg(vy=cpl_vector_wrap(ncnt,cpl_table_get_data_double(cnt,<span class="stringliteral">"INT"</span>)));
+<a name="l06861"></a>06861   check_nomsg(cfit=sinfo_polynomial_fit_1d_create(vx,vy,0,&mse));
+<a name="l06862"></a>06862   sinfo_unwrap_vector(&vx);
+<a name="l06863"></a>06863   sinfo_unwrap_vector(&vy);
+<a name="l06864"></a>06864 
+<a name="l06865"></a>06865   pows[0]=0;
+<a name="l06866"></a>06866   pows[1]=0;
+<a name="l06867"></a>06867   check_nomsg(yfit=cpl_polynomial_get_coeff(cfit,pows));
+<a name="l06868"></a>06868   sinfo_free_polynomial(&cfit);
+<a name="l06869"></a>06869   <span class="comment">//sinfo_msg("coeff 0=%g",yfit);</span>
+<a name="l06870"></a>06870 
+<a name="l06871"></a>06871   check_nomsg(poi=cpl_table_get_data_double(out,<span class="stringliteral">"CONT"</span>));
+<a name="l06872"></a>06872   <span class="keywordflow">for</span>(i=0;i<nlin;i++) {
+<a name="l06873"></a>06873     poi[i]=yfit;
+<a name="l06874"></a>06874   }
+<a name="l06875"></a>06875 
+<a name="l06876"></a>06876   check_nomsg(cpl_table_subtract_columns(out,<span class="stringliteral">"INT"</span>,<span class="stringliteral">"CONT"</span>));
+<a name="l06877"></a>06877   check_nomsg(cpl_table_erase_column(out,<span class="stringliteral">"CONT"</span>));
+<a name="l06878"></a>06878 
+<a name="l06879"></a>06879 
+<a name="l06880"></a>06880 
+<a name="l06881"></a>06881   <span class="keywordflow">return</span> out;
+<a name="l06882"></a>06882 
+<a name="l06883"></a>06883  cleanup:
+<a name="l06884"></a>06884   sinfo_unwrap_vector(&vx);
+<a name="l06885"></a>06885   sinfo_unwrap_vector(&vy);
+<a name="l06886"></a>06886   sinfo_free_polynomial(&cfit);
+<a name="l06887"></a>06887   sinfo_free_table(&out);
+<a name="l06888"></a>06888   <span class="keywordflow">return</span> NULL;
+<a name="l06889"></a>06889 
+<a name="l06890"></a>06890 }
+<a name="l06891"></a>06891 
+<a name="l06892"></a>06892 
+<a name="l06893"></a>06893 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l06894"></a>06894 sinfo_compute_line_ratio(cpl_table* obj,
+<a name="l06895"></a>06895                          cpl_table* sky,
+<a name="l06896"></a>06896                          <span class="keyword">const</span> <span class="keywordtype">double</span> wtol,
+<a name="l06897"></a>06897                          <span class="keyword">const</span> <span class="keywordtype">int</span> meth,
+<a name="l06898"></a>06898                          <span class="keyword">const</span> cpl_table* sel_regions,
+<a name="l06899"></a>06899                          cpl_table* cont_regions,
+<a name="l06900"></a>06900                          <span class="keywordtype">double</span>* r)
+<a name="l06901"></a>06901 {
+<a name="l06902"></a>06902   cpl_table* line_regions=NULL;
+<a name="l06903"></a>06903   cpl_table* obj_cnt=NULL;
+<a name="l06904"></a>06904   cpl_table* sky_cnt=NULL;
+<a name="l06905"></a>06905   cpl_table* obj_lin=NULL;
+<a name="l06906"></a>06906   cpl_table* sky_lin=NULL;
+<a name="l06907"></a>06907   cpl_table* lres=NULL;
+<a name="l06908"></a>06908   <span class="keywordtype">double</span> fmed=0;
+<a name="l06909"></a>06909   <span class="keywordtype">double</span> fsdv=0;
+<a name="l06910"></a>06910   <span class="keywordtype">double</span> fthresh=0;
+<a name="l06911"></a>06911   <span class="keywordtype">int</span> fclip_i=0;
+<a name="l06912"></a>06912   <span class="keywordtype">int</span> line_i=0;
+<a name="l06913"></a>06913 
+<a name="l06914"></a>06914 
+<a name="l06915"></a>06915   <span class="comment">//line_regions = med_regions;</span>
+<a name="l06916"></a>06916   check_nomsg(line_regions = cpl_table_duplicate(sel_regions));
+<a name="l06917"></a>06917   <span class="comment">//r = amoeba(1.e-5,function_name='fitsky',p0=[1.],scale=[0.1]);</span>
+<a name="l06918"></a>06918   <span class="comment">//Identify obj lines and continuum, same for sky</span>
+<a name="l06919"></a>06919   check_nomsg(obj_lin=sinfo_table_select_range(obj,line_regions,wtol));
+<a name="l06920"></a>06920   check_nomsg(sky_lin=sinfo_table_select_range(sky,line_regions,wtol));
+<a name="l06921"></a>06921   check_nomsg(obj_cnt=sinfo_table_select_range(obj,cont_regions,wtol));
+<a name="l06922"></a>06922   check_nomsg(sky_cnt=sinfo_table_select_range(sky,cont_regions,wtol));
+<a name="l06923"></a>06923 
+<a name="l06924"></a>06924   ck0_nomsg(sinfo_get_line_ratio(obj_lin,obj_cnt,sky_lin,sky_cnt,meth,r));
+<a name="l06925"></a>06925 
+<a name="l06926"></a>06926 
+<a name="l06927"></a>06927   <span class="comment">//fline_res = (obj_lr[line_regions]-</span>
+<a name="l06928"></a>06928   <span class="comment">//             interpol(obj_lr[cont_regions],llr[cont_regions],</span>
+<a name="l06929"></a>06929   <span class="comment">//             llr[line_regions])) -</span>
+<a name="l06930"></a>06930   <span class="comment">//            (sky_lr[line_regions] -</span>
+<a name="l06931"></a>06931   <span class="comment">//             interpol(sky_lr[cont_regions],llr[cont_regions],</span>
+<a name="l06932"></a>06932   <span class="comment">//</span>
+<a name="l06933"></a>06933   <span class="comment">//            llr[line_regions]))*r[0];</span>
+<a name="l06934"></a>06934   check_nomsg(lres=sinfo_table_interpol(obj_lin,obj_cnt,sky_lin,sky_cnt,*r));
+<a name="l06935"></a>06935 
+<a name="l06936"></a>06936   check_nomsg(fmed = cpl_table_get_column_median(lres,<span class="stringliteral">"INT"</span>));
+<a name="l06937"></a>06937   check_nomsg(fsdv = cpl_table_get_column_stdev(lres,<span class="stringliteral">"INT"</span>));
+<a name="l06938"></a>06938   fthresh=fmed+3*fsdv;
+<a name="l06939"></a>06939   <span class="comment">//fclip = where(abs(fline_res) > fmed+3*fsdv,fclip_i);</span>
+<a name="l06940"></a>06940   check_nomsg(cpl_table_duplicate_column(lres,<span class="stringliteral">"AINT"</span>,lres,<span class="stringliteral">"INT"</span>));
+<a name="l06941"></a>06941   check_nomsg(cpl_table_multiply_columns(lres,<span class="stringliteral">"AINT"</span>,<span class="stringliteral">"INT"</span>));
+<a name="l06942"></a>06942   check_nomsg(cpl_table_power_column(lres,<span class="stringliteral">"AINT"</span>,0.5));
+<a name="l06943"></a>06943   check_nomsg(fclip_i=cpl_table_and_selected_double(lres,<span class="stringliteral">"AINT"</span>,
+<a name="l06944"></a>06944                                                     CPL_GREATER_THAN,
+<a name="l06945"></a>06945                                                     fthresh));
+<a name="l06946"></a>06946   check_nomsg(cpl_table_select_all(lres));
+<a name="l06947"></a>06947 
+<a name="l06948"></a>06948 
+<a name="l06949"></a>06949   <span class="keywordflow">if</span> (fclip_i > 0) {
+<a name="l06950"></a>06950     <span class="comment">//line_regions = line_regions[where(abs(fline_res) < fmed+3*fsdv)];</span>
+<a name="l06951"></a>06951     check_nomsg(line_i=cpl_table_and_selected_double(lres,<span class="stringliteral">"AINT"</span>,
+<a name="l06952"></a>06952                              CPL_LESS_THAN,
+<a name="l06953"></a>06953                              fthresh));
+<a name="l06954"></a>06954     sinfo_free_table(&line_regions);
+<a name="l06955"></a>06955     check_nomsg(line_regions=cpl_table_extract_selected(lres));
+<a name="l06956"></a>06956     sinfo_free_table(&lres);
+<a name="l06957"></a>06957 
+<a name="l06958"></a>06958     check_nomsg(cpl_table_erase_column(line_regions,<span class="stringliteral">"INT"</span>));
+<a name="l06959"></a>06959     check_nomsg(cpl_table_erase_column(line_regions,<span class="stringliteral">"AINT"</span>));
+<a name="l06960"></a>06960 
+<a name="l06961"></a>06961 
+<a name="l06962"></a>06962     <span class="keywordflow">if</span> (line_i >= 3) {
+<a name="l06963"></a>06963 
+<a name="l06964"></a>06964     sinfo_free_table(&obj_lin);
+<a name="l06965"></a>06965     sinfo_free_table(&sky_lin);
+<a name="l06966"></a>06966     check_nomsg(obj_lin=sinfo_table_select_range(obj,line_regions,wtol));
+<a name="l06967"></a>06967     check_nomsg(sky_lin=sinfo_table_select_range(sky,line_regions,wtol));
+<a name="l06968"></a>06968 
+<a name="l06969"></a>06969     sinfo_free_table(&line_regions);
+<a name="l06970"></a>06970 
+<a name="l06971"></a>06971 
+<a name="l06972"></a>06972      <span class="comment">//r = amoeba(1.e-5,function_name='fitsky',p0=[1.],scale=[0.1]);</span>
+<a name="l06973"></a>06973       ck0_nomsg(sinfo_get_line_ratio(obj_lin,obj_cnt,sky_lin,sky_cnt,meth,r));
+<a name="l06974"></a>06974     }
+<a name="l06975"></a>06975   }
+<a name="l06976"></a>06976   *r=fabs(*r);
+<a name="l06977"></a>06977   <span class="comment">//Free memory</span>
+<a name="l06978"></a>06978   sinfo_free_table(&obj_cnt);
+<a name="l06979"></a>06979   sinfo_free_table(&sky_cnt);
+<a name="l06980"></a>06980   sinfo_free_table(&sky_lin);
+<a name="l06981"></a>06981   sinfo_free_table(&obj_lin);
+<a name="l06982"></a>06982   sinfo_free_table(&lres);
+<a name="l06983"></a>06983   sinfo_free_table(&line_regions);
+<a name="l06984"></a>06984 
+<a name="l06985"></a>06985 
+<a name="l06986"></a>06986   <span class="keywordflow">return</span> 0;
+<a name="l06987"></a>06987 
+<a name="l06988"></a>06988 
+<a name="l06989"></a>06989  cleanup:
+<a name="l06990"></a>06990 
+<a name="l06991"></a>06991 
+<a name="l06992"></a>06992   sinfo_free_table(&obj_cnt);
+<a name="l06993"></a>06993   sinfo_free_table(&sky_cnt);
+<a name="l06994"></a>06994   sinfo_free_table(&sky_lin);
+<a name="l06995"></a>06995   sinfo_free_table(&obj_lin);
+<a name="l06996"></a>06996 
+<a name="l06997"></a>06997   sinfo_free_table(&lres);
+<a name="l06998"></a>06998   sinfo_free_table(&line_regions);
+<a name="l06999"></a>06999 
+<a name="l07000"></a>07000   <span class="keywordflow">return</span> -1;
+<a name="l07001"></a>07001 
+<a name="l07002"></a>07002 }
+<a name="l07014"></a>07014 <span class="keyword">static</span> cpl_table*
+<a name="l07015"></a>07015 sinfo_find_rot_waves(
+<a name="l07016"></a>07016              <span class="keyword">const</span> <span class="keywordtype">double</span>  w_rot[],
+<a name="l07017"></a>07017                      <span class="keyword">const</span> <span class="keywordtype">int</span> npix_w,
+<a name="l07018"></a>07018                      <span class="keyword">const</span> <span class="keywordtype">double</span> w_step,
+<a name="l07019"></a>07019                      cpl_table* range
+<a name="l07020"></a>07020              )
+<a name="l07021"></a>07021 {
+<a name="l07022"></a>07022   <span class="keywordtype">int</span> i=0;
+<a name="l07023"></a>07023   <span class="keywordtype">int</span> x_i=0;
+<a name="l07024"></a>07024   <span class="keywordtype">int</span> r_start=0;
+<a name="l07025"></a>07025   <span class="keywordtype">double</span> w_min=0;
+<a name="l07026"></a>07026   <span class="keywordtype">double</span> w_max=0;
+<a name="l07027"></a>07027 
+<a name="l07028"></a>07028   cpl_table* w_sel=NULL;
+<a name="l07029"></a>07029   cpl_table* res=NULL;
+<a name="l07030"></a>07030 
+<a name="l07031"></a>07031   check_nomsg(res = cpl_table_new(0));
+<a name="l07032"></a>07032 
+<a name="l07033"></a>07033   check_nomsg(cpl_table_copy_structure(res,range));
+<a name="l07034"></a>07034 
+<a name="l07035"></a>07035   <span class="keywordflow">for</span> (i=0; i< NROT; i++) {
+<a name="l07036"></a>07036 
+<a name="l07037"></a>07037     <span class="comment">//x = where(lambda > l_rot_low[i]-npixw*cdelto &&</span>
+<a name="l07038"></a>07038     <span class="comment">//          lambda < l_rot_low[i]+npixw*cdelto,x_i);</span>
+<a name="l07039"></a>07039 
+<a name="l07040"></a>07040     w_min=w_rot[i]-npix_w*w_step;
+<a name="l07041"></a>07041     w_max=w_rot[i]+npix_w*w_step;
+<a name="l07042"></a>07042 
+<a name="l07043"></a>07043     check_nomsg(cpl_table_and_selected_double(range,<span class="stringliteral">"WAVE"</span>,
+<a name="l07044"></a>07044                                               CPL_GREATER_THAN,w_min));
+<a name="l07045"></a>07045     check_nomsg(cpl_table_and_selected_double(range,<span class="stringliteral">"WAVE"</span>,
+<a name="l07046"></a>07046                                               CPL_LESS_THAN,w_max));
+<a name="l07047"></a>07047     sinfo_free_table(&w_sel);
+<a name="l07048"></a>07048     check_nomsg(w_sel=cpl_table_extract_selected(range));
+<a name="l07049"></a>07049     check_nomsg(x_i=cpl_table_get_nrow(w_sel));
+<a name="l07050"></a>07050 
+<a name="l07051"></a>07051     <span class="keywordflow">if</span> (x_i > 0) {
+<a name="l07052"></a>07052       check_nomsg(r_start=cpl_table_get_nrow(res));
+<a name="l07053"></a>07053       <span class="comment">//sinfo_msg("i=%d x_i=%d w_min=%g w_max=%g",i,x_i,w_min,w_max);</span>
+<a name="l07054"></a>07054       check_nomsg(cpl_table_insert(res,w_sel,r_start));
+<a name="l07055"></a>07055     }
+<a name="l07056"></a>07056     check_nomsg(cpl_table_select_all(range));
+<a name="l07057"></a>07057   }
+<a name="l07058"></a>07058 
+<a name="l07059"></a>07059   <span class="comment">//res = range[1:cpl_table_get_nrow(res)-1];</span>
+<a name="l07060"></a>07060   sinfo_free_table(&w_sel);
+<a name="l07061"></a>07061 
+<a name="l07062"></a>07062 
+<a name="l07063"></a>07063   <span class="keywordflow">return</span> res;
+<a name="l07064"></a>07064 
+<a name="l07065"></a>07065  cleanup:
+<a name="l07066"></a>07066   sinfo_free_table(&w_sel);
+<a name="l07067"></a>07067   sinfo_free_table(&res);
+<a name="l07068"></a>07068   <span class="keywordflow">return</span> NULL;
+<a name="l07069"></a>07069 
+<a name="l07070"></a>07070 }
+<a name="l07071"></a>07071 
+<a name="l07084"></a>07084 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l07085"></a>07085 sinfo_get_obj_sky_wav_sub(cpl_table* obj,
+<a name="l07086"></a>07086                           cpl_table* sky,
+<a name="l07087"></a>07087                           cpl_table* wav,
+<a name="l07088"></a>07088                           cpl_table* sel,
+<a name="l07089"></a>07089                           <span class="keyword">const</span> <span class="keywordtype">double</span> wtol,
+<a name="l07090"></a>07090                           cpl_table** sub_obj,
+<a name="l07091"></a>07091                           cpl_table** sub_sky,
+<a name="l07092"></a>07092                           cpl_table** sub_wav)
+<a name="l07093"></a>07093 
+<a name="l07094"></a>07094 {
+<a name="l07095"></a>07095   cknull_nomsg(*sub_obj = sinfo_table_select_range(obj,sel,wtol));
+<a name="l07096"></a>07096   cknull_nomsg(*sub_sky = sinfo_table_select_range(sky,sel,wtol));
+<a name="l07097"></a>07097   cknull_nomsg(*sub_wav = sinfo_table_select_range(wav,sel,wtol));
+<a name="l07098"></a>07098   <span class="keywordflow">return</span> 0;
+<a name="l07099"></a>07099 
+<a name="l07100"></a>07100  cleanup:
+<a name="l07101"></a>07101   sinfo_free_table(&(*sub_obj));
+<a name="l07102"></a>07102   sinfo_free_table(&(*sub_sky));
+<a name="l07103"></a>07103   sinfo_free_table(&(*sub_wav));
+<a name="l07104"></a>07104 
+<a name="l07105"></a>07105   <span class="keywordflow">return</span> -1;
+<a name="l07106"></a>07106 
+<a name="l07107"></a>07107 }
+<a name="l07108"></a>07108 
+<a name="l07109"></a>07109 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l07110"></a>07110 sinfo_get_sub_regions(cpl_table* sky,
+<a name="l07111"></a>07111                       cpl_table* x1,
+<a name="l07112"></a>07112                       cpl_table* pos,
+<a name="l07113"></a>07113                       <span class="keyword">const</span> <span class="keywordtype">double</span> wtol,
+<a name="l07114"></a>07114                       <span class="keyword">const</span> <span class="keywordtype">int</span> npixw,
+<a name="l07115"></a>07115                       cpl_table** res)
+<a name="l07116"></a>07116 {
+<a name="l07117"></a>07117 
+<a name="l07118"></a>07118   cpl_table* x1_sub=NULL;
+<a name="l07119"></a>07119   cpl_table* x2=NULL;
+<a name="l07120"></a>07120 
+<a name="l07121"></a>07121   <span class="keywordtype">int</span> nrow=0;
+<a name="l07122"></a>07122   <span class="keywordtype">int</span> np=0;
+<a name="l07123"></a>07123 
+<a name="l07124"></a>07124   cknull(sky,<span class="stringliteral">"Null input sky table"</span>);
+<a name="l07125"></a>07125   cknull(x1 ,<span class="stringliteral">"Null input x1 table"</span>);
+<a name="l07126"></a>07126   cknull(pos,<span class="stringliteral">"Null input pos table"</span>);
+<a name="l07127"></a>07127 
+<a name="l07128"></a>07128   check_nomsg(x2=cpl_table_duplicate(sky));
+<a name="l07129"></a>07129   check_nomsg(nrow=cpl_table_get_nrow(sky));
+<a name="l07130"></a>07130   check_nomsg(cpl_table_fill_column_window(x2,<span class="stringliteral">"INT"</span>,0,nrow,0));
+<a name="l07131"></a>07131 
+<a name="l07132"></a>07132   <span class="comment">//x2[x1[pos]] = 10.;</span>
+<a name="l07133"></a>07133   <span class="comment">//x2 = convol(x2,replicate(1,npixw),/edge_truncate,/center);</span>
+<a name="l07134"></a>07134   <span class="comment">//res = where(x2 > 0,hi_i);</span>
+<a name="l07135"></a>07135   <span class="comment">//cpl_table_save(x1, NULL, NULL, "out_x1.fits", CPL_IO_DEFAULT);</span>
+<a name="l07136"></a>07136 
+<a name="l07137"></a>07137   x1_sub=sinfo_table_select_range(x1,pos,wtol);
+<a name="l07138"></a>07138 
+<a name="l07139"></a>07139   <span class="keywordflow">if</span>(x1_sub != NULL) {
+<a name="l07140"></a>07140     ck0_nomsg(sinfo_table_fill_column_over_range(&x2,x1_sub,<span class="stringliteral">"INT"</span>,10.,wtol));
+<a name="l07141"></a>07141     sinfo_free_table(&x1_sub);
+<a name="l07142"></a>07142     check_nomsg(sinfo_convolve_kernel(&x2,npixw/2));
+<a name="l07143"></a>07143     check_nomsg(np=cpl_table_and_selected_double(x2,<span class="stringliteral">"CNV"</span>,CPL_GREATER_THAN,0));
+<a name="l07144"></a>07144     check_nomsg(*res=cpl_table_extract_selected(x2));
+<a name="l07145"></a>07145     sinfo_free_table(&x2);
+<a name="l07146"></a>07146     check_nomsg(cpl_table_erase_column(*res,<span class="stringliteral">"INT"</span>));
+<a name="l07147"></a>07147     check_nomsg(cpl_table_erase_column(*res,<span class="stringliteral">"CNV"</span>));
+<a name="l07148"></a>07148 
+<a name="l07149"></a>07149   } <span class="keywordflow">else</span> {
+<a name="l07150"></a>07150     cpl_error_reset();
+<a name="l07151"></a>07151     sinfo_free_table(&x1_sub);
+<a name="l07152"></a>07152     sinfo_free_table(&x2);
+<a name="l07153"></a>07153 
+<a name="l07154"></a>07154     <span class="keywordflow">return</span> np;
+<a name="l07155"></a>07155   }
+<a name="l07156"></a>07156 
+<a name="l07157"></a>07157   <span class="keywordflow">return</span> np;
+<a name="l07158"></a>07158  cleanup:
+<a name="l07159"></a>07159 
+<a name="l07160"></a>07160   sinfo_free_table(&x1_sub);
+<a name="l07161"></a>07161   sinfo_free_table(&x2);
+<a name="l07162"></a>07162   <span class="keywordflow">return</span> -1;
+<a name="l07163"></a>07163 
+<a name="l07164"></a>07164 }
+<a name="l07165"></a>07165 
+<a name="l07166"></a>07166 <span class="keyword">static</span> cpl_table*
+<a name="l07167"></a>07167 sinfo_table_extract_rest(cpl_table* inp,
+<a name="l07168"></a>07168                          cpl_table* low,
+<a name="l07169"></a>07169                          cpl_table* med,
+<a name="l07170"></a>07170                          <span class="keyword">const</span> <span class="keywordtype">double</span> wtol)
+<a name="l07171"></a>07171 {
+<a name="l07172"></a>07172 
+<a name="l07173"></a>07173   cpl_table* out=NULL;
+<a name="l07174"></a>07174   <span class="keywordtype">double</span>* pinp=NULL;
+<a name="l07175"></a>07175   <span class="keywordtype">double</span>* plow=NULL;
+<a name="l07176"></a>07176   <span class="keywordtype">double</span>* pmed=NULL;
+<a name="l07177"></a>07177   <span class="keywordtype">int</span> nlow=0;
+<a name="l07178"></a>07178   <span class="keywordtype">int</span> nmed=0;
+<a name="l07179"></a>07179 
+<a name="l07180"></a>07180   <span class="keywordtype">int</span> nrow=0;
+<a name="l07181"></a>07181   <span class="keywordtype">int</span> i=0;
+<a name="l07182"></a>07182   <span class="keywordtype">int</span> k=0;
+<a name="l07183"></a>07183   cpl_table* tmp=NULL;
+<a name="l07184"></a>07184 
+<a name="l07185"></a>07185   cknull(inp,<span class="stringliteral">"null input table"</span>);
+<a name="l07186"></a>07186 
+<a name="l07187"></a>07187 
+<a name="l07188"></a>07188   check_nomsg(tmp=cpl_table_duplicate(inp));
+<a name="l07189"></a>07189   check_nomsg(nrow=cpl_table_get_nrow(tmp));
+<a name="l07190"></a>07190   check_nomsg(cpl_table_new_column(tmp,<span class="stringliteral">"SEL"</span>,CPL_TYPE_INT));
+<a name="l07191"></a>07191   check_nomsg(cpl_table_fill_column_window_int(tmp,<span class="stringliteral">"SEL"</span>,0,nrow,0));
+<a name="l07192"></a>07192 
+<a name="l07193"></a>07193   check_nomsg(pinp=cpl_table_get_data_double(inp,<span class="stringliteral">"WAVE"</span>));
+<a name="l07194"></a>07194   check_nomsg(plow=cpl_table_get_data_double(low,<span class="stringliteral">"WAVE"</span>));
+<a name="l07195"></a>07195   check_nomsg(pmed=cpl_table_get_data_double(med,<span class="stringliteral">"WAVE"</span>));
+<a name="l07196"></a>07196   nlow=cpl_table_get_nrow(low);
+<a name="l07197"></a>07197 
+<a name="l07198"></a>07198 
+<a name="l07199"></a>07199   <span class="comment">//check_nomsg(cpl_table_save(low,NULL,NULL,"out_low.fits",CPL_IO_DEFAULT));</span>
+<a name="l07200"></a>07200   <span class="keywordflow">if</span>(nlow > 0) {
+<a name="l07201"></a>07201     k=0;
+<a name="l07202"></a>07202     <span class="keywordflow">for</span>(i=0;i<nrow;i++) {
+<a name="l07203"></a>07203       <span class="keywordflow">if</span>(fabs(pinp[i]-plow[k]) < wtol) {
+<a name="l07204"></a>07204     cpl_table_set_int(tmp,<span class="stringliteral">"SEL"</span>,k,-1);
+<a name="l07205"></a>07205     k++;
+<a name="l07206"></a>07206       }
+<a name="l07207"></a>07207     }
+<a name="l07208"></a>07208   }
+<a name="l07209"></a>07209   nmed=cpl_table_get_nrow(med);
+<a name="l07210"></a>07210 
+<a name="l07211"></a>07211   k=0;
+<a name="l07212"></a>07212   <span class="keywordflow">if</span>(nmed > 0) {
+<a name="l07213"></a>07213     <span class="keywordflow">for</span>(i=0;i<nrow;i++) {
+<a name="l07214"></a>07214       <span class="keywordflow">if</span>(fabs(pinp[i]-pmed[k]) < wtol) {
+<a name="l07215"></a>07215     cpl_table_set_int(tmp,<span class="stringliteral">"SEL"</span>,k,-1);
+<a name="l07216"></a>07216     k++;
+<a name="l07217"></a>07217       }
+<a name="l07218"></a>07218     }
+<a name="l07219"></a>07219   }
+<a name="l07220"></a>07220 
+<a name="l07221"></a>07221   check_nomsg(cpl_table_and_selected_int(tmp,<span class="stringliteral">"SEL"</span>,CPL_GREATER_THAN,-1));
+<a name="l07222"></a>07222   check_nomsg(out=cpl_table_extract_selected(tmp));
+<a name="l07223"></a>07223   sinfo_free_table(&tmp);
+<a name="l07224"></a>07224   check_nomsg(cpl_table_erase_column(out,<span class="stringliteral">"SEL"</span>));
+<a name="l07225"></a>07225 
+<a name="l07226"></a>07226   <span class="keywordflow">return</span> out;
+<a name="l07227"></a>07227 
+<a name="l07228"></a>07228  cleanup:
+<a name="l07229"></a>07229   sinfo_free_table(&tmp);
+<a name="l07230"></a>07230   <span class="keywordflow">return</span> NULL;
+<a name="l07231"></a>07231 
+<a name="l07232"></a>07232 }
+<a name="l07233"></a>07233 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__skycor_8h_source.html b/html/sinfo__skycor_8h_source.html
new file mode 100644
index 0000000..cdeb8f4
--- /dev/null
+++ b/html/sinfo__skycor_8h_source.html
@@ -0,0 +1,123 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_skycor.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_skycor.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_skycor.h,v 1.13 2007/03/05 07:21:54 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the SINFONI Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2007/03/05 07:21:54 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.13 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span>
+<a name="l00032"></a>00032 <span class="preprocessor">#ifndef SINFO_SKYCOR_H</span>
+<a name="l00033"></a>00033 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_SKYCOR_H</span>
+<a name="l00034"></a>00034 <span class="preprocessor"></span><span class="preprocessor">#include <cpl.h></span>
+<a name="l00035"></a>00035 
+<a name="l00036"></a>00036 <span class="preprocessor">#define SINFO_MASK_WAVE_MIN 1.4</span>
+<a name="l00037"></a>00037 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_MASK_WAVE_MAX 2.5</span>
+<a name="l00038"></a>00038 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_MIN_FRAC 0.8</span>
+<a name="l00039"></a>00039 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_LINE_HALF_WIDTH 4.0</span>
+<a name="l00040"></a>00040 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_SKY_BKG_FILTER_WIDTH 12</span>
+<a name="l00041"></a>00041 <span class="preprocessor"></span>
+<a name="l00042"></a>00042 
+<a name="l00043"></a>00043 
+<a name="l00044"></a>00044 <span class="preprocessor">#define HISTO_NBINS 100</span>
+<a name="l00045"></a>00045 <span class="preprocessor"></span><span class="preprocessor">#define HISTO_MIN_SIZE 10</span>
+<a name="l00046"></a>00046 <span class="preprocessor"></span><span class="preprocessor">#define HISTO_Y_CUT 10          </span><span class="comment">/* 50 is a better value this </span>
+<a name="l00047"></a>00047 <span class="comment">                                   affects histo right marging*/</span>
+<a name="l00048"></a>00048 <span class="preprocessor">#define HISTO_X_LEFT_CUT  1.0   </span><span class="comment">/* 0.2 is better */</span>
+<a name="l00049"></a>00049 <span class="preprocessor">#define HISTO_X_RIGHT_CUT  0.5  </span><span class="comment">/* 1.0 is better */</span>
+<a name="l00050"></a>00050 <span class="preprocessor">#define HISTO_DIST_TEMPC_MIN_FCT 5.   </span><span class="comment">/* 5.0 */</span>
+<a name="l00051"></a>00051 <span class="preprocessor">#define HISTO_DIST_TEMPC_MAX_FCT 0.25 </span><span class="comment">/* 0.25 */</span>
+<a name="l00052"></a>00052 
+<a name="l00053"></a>00053 <span class="keyword">struct </span>sinfo_skycor_qc_ {
+<a name="l00054"></a>00054   <span class="keywordtype">int</span>   th_fit;
+<a name="l00055"></a>00055 };
+<a name="l00056"></a>00056 <span class="keyword">typedef</span> <span class="keyword">struct </span>sinfo_skycor_qc_ sinfo_skycor_qc; 
+<a name="l00057"></a>00057 
+<a name="l00058"></a>00058 sinfo_skycor_qc* sinfo_skycor_qc_new(<span class="keywordtype">void</span>);
+<a name="l00059"></a>00059 <span class="keywordtype">void</span> sinfo_skycor_qc_delete(sinfo_skycor_qc** s);
+<a name="l00060"></a>00060 
+<a name="l00061"></a>00061 
+<a name="l00062"></a>00062 <span class="keywordtype">int</span> 
+<a name="l00063"></a>00063 sinfo_skycor(cpl_parameterlist * config, 
+<a name="l00064"></a>00064              cpl_frame* obj_frm, 
+<a name="l00065"></a>00065              cpl_frame* sky_frm,
+<a name="l00066"></a>00066              sinfo_skycor_qc* sqc,
+<a name="l00067"></a>00067              cpl_imagelist** obj_cor,
+<a name="l00068"></a>00068              cpl_table** int_obj);
+<a name="l00069"></a>00069 
+<a name="l00070"></a>00070 
+<a name="l00071"></a>00071 
+<a name="l00072"></a>00072 <span class="keywordtype">int</span>
+<a name="l00073"></a>00073 sinfo_histogram(<span class="keyword">const</span> cpl_table* data,
+<a name="l00074"></a>00074                 <span class="keyword">const</span> <span class="keywordtype">int</span> nbins, 
+<a name="l00075"></a>00075                 <span class="keyword">const</span> <span class="keywordtype">double</span> min, 
+<a name="l00076"></a>00076                 <span class="keyword">const</span> <span class="keywordtype">double</span> max,
+<a name="l00077"></a>00077                 cpl_table** histo);
+<a name="l00078"></a>00078 <span class="keywordtype">int</span>
+<a name="l00079"></a>00079 sinfo_table_get_index_of_val(cpl_table* t,
+<a name="l00080"></a>00080                              <span class="keyword">const</span> <span class="keywordtype">char</span>* name,
+<a name="l00081"></a>00081                              <span class="keywordtype">double</span> val,
+<a name="l00082"></a>00082                              cpl_type type);
+<a name="l00083"></a>00083 
+<a name="l00084"></a>00084 <span class="keywordtype">int</span>
+<a name="l00085"></a>00085 sinfo_table_get_index_of_max(cpl_table* t,
+<a name="l00086"></a>00086                              <span class="keyword">const</span> <span class="keywordtype">char</span>* name,
+<a name="l00087"></a>00087                              cpl_type type);
+<a name="l00088"></a>00088 
+<a name="l00089"></a>00089 
+<a name="l00090"></a>00090 <span class="keywordtype">double</span>
+<a name="l00091"></a>00091 sinfo_table_column_interpolate(<span class="keyword">const</span> cpl_table* t,
+<a name="l00092"></a>00092                                <span class="keyword">const</span> <span class="keywordtype">char</span>* name,
+<a name="l00093"></a>00093                                <span class="keyword">const</span> <span class="keywordtype">double</span> x);
+<a name="l00094"></a>00094 
+<a name="l00095"></a>00095 
+<a name="l00096"></a>00096 
+<a name="l00097"></a>00097 
+<a name="l00098"></a>00098 
+<a name="l00099"></a>00099 cpl_table* 
+<a name="l00100"></a>00100 sinfo_where_tab_min_max(cpl_table* t, 
+<a name="l00101"></a>00101                         <span class="keyword">const</span> <span class="keywordtype">char</span>* col, 
+<a name="l00102"></a>00102                         cpl_table_select_operator op1,  
+<a name="l00103"></a>00103                         <span class="keyword">const</span> <span class="keywordtype">double</span> v1, 
+<a name="l00104"></a>00104                         cpl_table_select_operator op2, 
+<a name="l00105"></a>00105                         <span class="keyword">const</span> <span class="keywordtype">double</span> v2);
+<a name="l00106"></a>00106 
+<a name="l00107"></a>00107 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__skycor__config_8c_source.html b/html/sinfo__skycor__config_8c_source.html
new file mode 100644
index 0000000..b8395b1
--- /dev/null
+++ b/html/sinfo__skycor__config_8c_source.html
@@ -0,0 +1,225 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_skycor_config.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_skycor_config.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_skycor_config.c,v 1.17 2012/03/03 10:18:26 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the CPL (Common Pipeline Library)</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
+<a name="l00007"></a>00007 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span>
+<a name="l00008"></a>00008 <span class="comment"> * License as published by the Free Software Foundation; either</span>
+<a name="l00009"></a>00009 <span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
+<a name="l00014"></a>00014 <span class="comment"> * Lesser General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
+<a name="l00017"></a>00017 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2012/03/03 10:18:26 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.17 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> */</span>
+<a name="l00026"></a>00026 
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span>
+<a name="l00032"></a>00032 <span class="preprocessor">#include "sinfo_skycor_config.h"</span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include "sinfo_skycor.h"</span>
+<a name="l00034"></a>00034 
+<a name="l00054"></a>00054   <span class="comment">/* General data reduction parameters */</span>
+<a name="l00055"></a>00055 
+<a name="l00056"></a>00056 <span class="keywordtype">void</span>
+<a name="l00057"></a>00057  sinfo_skycor_config_add(cpl_parameterlist *list)
+<a name="l00058"></a>00058 {
+<a name="l00059"></a>00059 
+<a name="l00060"></a>00060   cpl_parameter *p;
+<a name="l00061"></a>00061 
+<a name="l00062"></a>00062   <span class="keywordflow">if</span> (!list) {
+<a name="l00063"></a>00063     <span class="keywordflow">return</span>;
+<a name="l00064"></a>00064   }
+<a name="l00065"></a>00065 
+<a name="l00066"></a>00066 
+<a name="l00067"></a>00067    <span class="comment">/* Fill the parameters list */</span>
+<a name="l00068"></a>00068     <span class="comment">/* --stropt */</span>
+<a name="l00069"></a>00069   
+<a name="l00070"></a>00070     p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.sinfo_utl_skycor.mask_ws"</span>, 
+<a name="l00071"></a>00071                                 CPL_TYPE_DOUBLE, 
+<a name="l00072"></a>00072              <span class="stringliteral">"Starting wavelength for object-sky cross correlation"</span>, 
+<a name="l00073"></a>00073                                 <span class="stringliteral">"sinfoni.sinfo_utl_skycor"</span>,
+<a name="l00074"></a>00074                                 SINFO_MASK_WAVE_MIN) ;
+<a name="l00075"></a>00075     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"skycor-mask_ws"</span>) ;
+<a name="l00076"></a>00076     cpl_parameterlist_append(list, p) ;
+<a name="l00077"></a>00077 
+<a name="l00078"></a>00078 
+<a name="l00079"></a>00079     p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.sinfo_utl_skycor.mask_we"</span>, 
+<a name="l00080"></a>00080                                 CPL_TYPE_DOUBLE, 
+<a name="l00081"></a>00081              <span class="stringliteral">"End wavelength for object-sky cross correlation"</span>, 
+<a name="l00082"></a>00082                                 <span class="stringliteral">"sinfoni.sinfo_utl_skycor"</span>, 
+<a name="l00083"></a>00083                                 SINFO_MASK_WAVE_MAX) ;
+<a name="l00084"></a>00084     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"skycor-mask_we"</span>) ;
+<a name="l00085"></a>00085     cpl_parameterlist_append(list, p) ;
+<a name="l00086"></a>00086   
+<a name="l00087"></a>00087 
+<a name="l00088"></a>00088     p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.sinfo_utl_skycor.min_frac"</span>, 
+<a name="l00089"></a>00089                                 CPL_TYPE_DOUBLE, 
+<a name="l00090"></a>00090    <span class="stringliteral">"Threshold value for fraction of spatial pixels to be sky"</span>, 
+<a name="l00091"></a>00091                                 <span class="stringliteral">"sinfoni.sinfo_utl_skycor"</span>, 
+<a name="l00092"></a>00092                                 SINFO_MIN_FRAC) ;
+<a name="l00093"></a>00093     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"skycor-min_frac"</span>) ;
+<a name="l00094"></a>00094     cpl_parameterlist_append(list, p) ;
+<a name="l00095"></a>00095 
+<a name="l00096"></a>00096 
+<a name="l00097"></a>00097 
+<a name="l00098"></a>00098     p = cpl_parameter_new_range(
+<a name="l00099"></a>00099                       <span class="stringliteral">"sinfoni.sinfo_utl_skycor.sky_bkg_filter_width"</span>, 
+<a name="l00100"></a>00100                                 CPL_TYPE_INT, 
+<a name="l00101"></a>00101                                 <span class="stringliteral">"Width of sky-thermal background pre filter "</span>
+<a name="l00102"></a>00102                                 <span class="stringliteral">"(to remove emission lines before fitting a "</span>
+<a name="l00103"></a>00103                                 <span class="stringliteral">"Black Body)."</span>, 
+<a name="l00104"></a>00104                                 <span class="stringliteral">"sinfoni.sinfo_utl_skycor"</span>, 
+<a name="l00105"></a>00105                                 SINFO_SKY_BKG_FILTER_WIDTH,2,25) ;
+<a name="l00106"></a>00106     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, 
+<a name="l00107"></a>00107                               <span class="stringliteral">"skycor-sky_bkg_filter_width"</span>) ;
+<a name="l00108"></a>00108     cpl_parameterlist_append(list, p) ;
+<a name="l00109"></a>00109 
+<a name="l00110"></a>00110     p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.sinfo_utl_skycor.line_half_width"</span>, 
+<a name="l00111"></a>00111                                 CPL_TYPE_DOUBLE, 
+<a name="l00112"></a>00112                                 <span class="stringliteral">"Threshold value for full width in pixels "</span>
+<a name="l00113"></a>00113                                 <span class="stringliteral">"of unresolved emission line. Lines with FWHM "</span>
+<a name="l00114"></a>00114                                 <span class="stringliteral">"smaller than this value are not considered "</span> 
+<a name="l00115"></a>00115                                 <span class="stringliteral">"in the object-sky cross correlation and in "</span>
+<a name="l00116"></a>00116                                 <span class="stringliteral">"computation of the optimal sky lines scaling "</span>
+<a name="l00117"></a>00117                                 <span class="stringliteral">"factor"</span>, 
+<a name="l00118"></a>00118                                 <span class="stringliteral">"sinfoni.sinfo_utl_skycor"</span>, 
+<a name="l00119"></a>00119                                 SINFO_LINE_HALF_WIDTH) ;
+<a name="l00120"></a>00120     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"skycor-line_hw"</span>) ;
+<a name="l00121"></a>00121     cpl_parameterlist_append(list, p) ;
+<a name="l00122"></a>00122 
+<a name="l00123"></a>00123     p = cpl_parameter_new_enum(<span class="stringliteral">"sinfoni.sinfo_utl_skycor.scale_method"</span>, 
+<a name="l00124"></a>00124                    CPL_TYPE_INT, 
+<a name="l00125"></a>00125                                <span class="stringliteral">"Optimal sky lines scaling factor computation "</span>
+<a name="l00126"></a>00126                    <span class="stringliteral">"method: amoeba fit (0), "</span>
+<a name="l00127"></a>00127                                <span class="stringliteral">"maximum likelihood (1) "</span>,
+<a name="l00128"></a>00128                                <span class="stringliteral">"sinfoni.sinfo_utl_skycor"</span>, 
+<a name="l00129"></a>00129                                1,2,0,1) ;
+<a name="l00130"></a>00130     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, 
+<a name="l00131"></a>00131                             <span class="stringliteral">"skycor-scale_method"</span>) ;
+<a name="l00132"></a>00132     cpl_parameterlist_append(list, p) ;
+<a name="l00133"></a>00133 
+<a name="l00134"></a>00134 
+<a name="l00135"></a>00135     p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.sinfo_utl_skycor.rot_cor"</span>, 
+<a name="l00136"></a>00136                                 CPL_TYPE_BOOL, 
+<a name="l00137"></a>00137                                 <span class="stringliteral">"Computes scaling factor correction due to "</span>
+<a name="l00138"></a>00138                                 <span class="stringliteral">"rotational levels transitions"</span>,
+<a name="l00139"></a>00139                                 <span class="stringliteral">"sinfoni.sinfo_utl_skycor"</span>, 
+<a name="l00140"></a>00140                                 FALSE) ;
+<a name="l00141"></a>00141     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"skycor-rot_cor"</span>) ;
+<a name="l00142"></a>00142     cpl_parameterlist_append(list, p) ;
+<a name="l00143"></a>00143 
+<a name="l00144"></a>00144 
+<a name="l00145"></a>00145 
+<a name="l00146"></a>00146     p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.sinfo_utl_skycor.fit_obj_noise"</span>, 
+<a name="l00147"></a>00147                                 CPL_TYPE_BOOL, 
+<a name="l00148"></a>00148                                 <span class="stringliteral">"Do Gaussian fit of object noise"</span>,
+<a name="l00149"></a>00149                                 <span class="stringliteral">"sinfoni.sinfo_utl_skycor"</span>, 
+<a name="l00150"></a>00150                                 FALSE) ;
+<a name="l00151"></a>00151     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"skycor-fit_obj_noise"</span>);
+<a name="l00152"></a>00152     cpl_parameterlist_append(list, p) ;
+<a name="l00153"></a>00153 
+<a name="l00154"></a>00154 
+<a name="l00155"></a>00155     p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.sinfo_utl_skycor.niter"</span>, 
+<a name="l00156"></a>00156                                 CPL_TYPE_INT, 
+<a name="l00157"></a>00157                                 <span class="stringliteral">"Number of iterations of background "</span>
+<a name="l00158"></a>00158                                 <span class="stringliteral">"fit"</span>, 
+<a name="l00159"></a>00159                                 <span class="stringliteral">"sinfoni.sinfo_utl_skycor"</span>, 
+<a name="l00160"></a>00160                                 10) ;
+<a name="l00161"></a>00161     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"skycor-niter"</span>) ;
+<a name="l00162"></a>00162     cpl_parameterlist_append(list, p) ;
+<a name="l00163"></a>00163 
+<a name="l00164"></a>00164     p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.sinfo_utl_skycor.pshift"</span>, 
+<a name="l00165"></a>00165                                 CPL_TYPE_DOUBLE, 
+<a name="l00166"></a>00166                                 <span class="stringliteral">"Sky spectrum shift towar object"</span>, 
+<a name="l00167"></a>00167                                 <span class="stringliteral">"sinfoni.sinfo_utl_skycor"</span>, 
+<a name="l00168"></a>00168                                 0.) ;
+<a name="l00169"></a>00169     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"skycor-pshift"</span>) ;
+<a name="l00170"></a>00170     cpl_parameterlist_append(list, p) ;
+<a name="l00171"></a>00171 
+<a name="l00172"></a>00172     p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.sinfo_utl_skycor.llx"</span>, 
+<a name="l00173"></a>00173                                 CPL_TYPE_INT, 
+<a name="l00174"></a>00174                                 <span class="stringliteral">"Lower left X defining object "</span>
+<a name="l00175"></a>00175                                 <span class="stringliteral">"spectrum location"</span>, 
+<a name="l00176"></a>00176                                 <span class="stringliteral">"sinfoni.sinfo_utl_skycor"</span>, 
+<a name="l00177"></a>00177                                 1) ;
+<a name="l00178"></a>00178     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"skycor-llx"</span>) ;
+<a name="l00179"></a>00179     cpl_parameterlist_append(list, p) ;
+<a name="l00180"></a>00180 
+<a name="l00181"></a>00181     p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.sinfo_utl_skycor.lly"</span>, 
+<a name="l00182"></a>00182                                 CPL_TYPE_INT, 
+<a name="l00183"></a>00183                                 <span class="stringliteral">"Lower left Y defining object "</span>
+<a name="l00184"></a>00184                                 <span class="stringliteral">"spectrum location"</span>, 
+<a name="l00185"></a>00185                                 <span class="stringliteral">"sinfoni.sinfo_utl_skycor"</span>, 
+<a name="l00186"></a>00186                                 1) ;
+<a name="l00187"></a>00187     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"skycor-lly"</span>) ;
+<a name="l00188"></a>00188     cpl_parameterlist_append(list, p) ;
+<a name="l00189"></a>00189 
+<a name="l00190"></a>00190 
+<a name="l00191"></a>00191 
+<a name="l00192"></a>00192     p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.sinfo_utl_skycor.urx"</span>, 
+<a name="l00193"></a>00193                                 CPL_TYPE_INT, 
+<a name="l00194"></a>00194                                 <span class="stringliteral">"Upper right X defining object "</span>
+<a name="l00195"></a>00195                                 <span class="stringliteral">"spectrum location"</span>, 
+<a name="l00196"></a>00196                                 <span class="stringliteral">"sinfoni.sinfo_utl_skycor"</span>, 
+<a name="l00197"></a>00197                                 64) ;
+<a name="l00198"></a>00198     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"skycor-urx"</span>) ;
+<a name="l00199"></a>00199     cpl_parameterlist_append(list, p) ;
+<a name="l00200"></a>00200 
+<a name="l00201"></a>00201 
+<a name="l00202"></a>00202     p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.sinfo_utl_skycor.ury"</span>, 
+<a name="l00203"></a>00203                                 CPL_TYPE_INT, 
+<a name="l00204"></a>00204                                 <span class="stringliteral">"Upper right Y defining object "</span>
+<a name="l00205"></a>00205                                 <span class="stringliteral">"spectrum location"</span>, 
+<a name="l00206"></a>00206                                 <span class="stringliteral">"sinfoni.sinfo_utl_skycor"</span>, 
+<a name="l00207"></a>00207                                 64) ;
+<a name="l00208"></a>00208     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"skycor-ury"</span>) ;
+<a name="l00209"></a>00209     cpl_parameterlist_append(list, p) ;
+<a name="l00210"></a>00210 
+<a name="l00211"></a>00211 
+<a name="l00212"></a>00212 
+<a name="l00213"></a>00213     p = cpl_parameter_new_value(
+<a name="l00214"></a>00214      
+<a name="l00215"></a>00215                               <span class="stringliteral">"sinfoni.sinfo_utl_skycor.sub_thr_bkg_from_obj"</span>, 
+<a name="l00216"></a>00216                                 CPL_TYPE_BOOL, 
+<a name="l00217"></a>00217                                 <span class="stringliteral">"Subtract thermal background contribute from "</span>
+<a name="l00218"></a>00218                                 <span class="stringliteral">"object spectra. Set it to TRUE if "</span>
+<a name="l00219"></a>00219                                 <span class="stringliteral">"stack-sub_raw_sky is set to FALSE"</span>,
+<a name="l00220"></a>00220                                 <span class="stringliteral">"sinfoni.sinfo_utl_skycor"</span>, 
+<a name="l00221"></a>00221                                 FALSE) ;
+<a name="l00222"></a>00222 
+<a name="l00223"></a>00223     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, 
+<a name="l00224"></a>00224                 <span class="stringliteral">"skycor-sub_thr_bkg_from_obj"</span>) ;
+<a name="l00225"></a>00225     cpl_parameterlist_append(list, p) ;
+<a name="l00226"></a>00226 
+<a name="l00227"></a>00227 
+<a name="l00228"></a>00228 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__skycor__config_8h_source.html b/html/sinfo__skycor__config_8h_source.html
new file mode 100644
index 0000000..8d31bd0
--- /dev/null
+++ b/html/sinfo__skycor__config_8h_source.html
@@ -0,0 +1,53 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_skycor_config.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_skycor_config.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_skycor_config.h,v 1.1 2006/11/27 16:55:26 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the CPL (Common Pipeline Library)</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
+<a name="l00007"></a>00007 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span>
+<a name="l00008"></a>00008 <span class="comment"> * License as published by the Free Software Foundation; either</span>
+<a name="l00009"></a>00009 <span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
+<a name="l00014"></a>00014 <span class="comment"> * Lesser General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
+<a name="l00017"></a>00017 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2006/11/27 16:55:26 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.1 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> */</span>
+<a name="l00026"></a>00026 
+<a name="l00027"></a>00027  <span class="comment">/****************************************************************</span>
+<a name="l00028"></a>00028 <span class="comment">  *           Bad pixel search  (noise method)                  *</span>
+<a name="l00029"></a>00029 <span class="comment">  ****************************************************************/</span>
+<a name="l00030"></a>00030 <span class="preprocessor">#ifndef SINFO_SKYCOR_CONFIG_H</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_SKYCOR_CONFIG_H</span>
+<a name="l00032"></a>00032 <span class="preprocessor"></span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include <cpl.h></span>   
+<a name="l00034"></a>00034 
+<a name="l00035"></a>00035 <span class="keywordtype">void</span> sinfo_skycor_config_add(cpl_parameterlist *list);
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__solve__poly__root_8c_source.html b/html/sinfo__solve__poly__root_8c_source.html
new file mode 100644
index 0000000..4cf7868
--- /dev/null
+++ b/html/sinfo__solve__poly__root_8c_source.html
@@ -0,0 +1,137 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_solve_poly_root.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_solve_poly_root.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00020"></a>00020 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00021"></a>00021 <span class="preprocessor">#endif</span>
+<a name="l00022"></a>00022 <span class="preprocessor"></span><span class="comment">/*#include "companion.c"*/</span>
+<a name="l00023"></a>00023 <span class="comment">/*#include "balance.c"*/</span>
+<a name="l00024"></a>00024 <span class="comment">/*#include "qr.c"*/</span>
+<a name="l00025"></a>00025 <span class="preprocessor">#include "sinfo_solve_poly_root.h"</span>
+<a name="l00026"></a>00026 
+<a name="l00035"></a>00035 gsl_poly_complex_workspace *
+<a name="l00036"></a>00036 sinfo_gsl_poly_complex_workspace_alloc (<span class="keywordtype">size_t</span> n)
+<a name="l00037"></a>00037 {
+<a name="l00038"></a>00038   <span class="keywordtype">size_t</span> nc ;
+<a name="l00039"></a>00039 
+<a name="l00040"></a>00040   gsl_poly_complex_workspace * w ;
+<a name="l00041"></a>00041  
+<a name="l00042"></a>00042   <span class="keywordflow">if</span> (n == 0)
+<a name="l00043"></a>00043     {
+<a name="l00044"></a>00044       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"sinfo_matrix size n must be positive integer"</span>);
+<a name="l00045"></a>00045       <span class="keywordflow">return</span> NULL ;
+<a name="l00046"></a>00046     }
+<a name="l00047"></a>00047 
+<a name="l00048"></a>00048   w = (gsl_poly_complex_workspace *)
+<a name="l00049"></a>00049     cpl_malloc (<span class="keyword">sizeof</span>(gsl_poly_complex_workspace));
+<a name="l00050"></a>00050 
+<a name="l00051"></a>00051   <span class="keywordflow">if</span> (w == 0)
+<a name="l00052"></a>00052     {
+<a name="l00053"></a>00053       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"failed to allocate space for struct"</span>);
+<a name="l00054"></a>00054       <span class="keywordflow">return</span> NULL ;
+<a name="l00055"></a>00055     }
+<a name="l00056"></a>00056 
+<a name="l00057"></a>00057   nc = n - 1;
+<a name="l00058"></a>00058 
+<a name="l00059"></a>00059   w->nc = nc;
+<a name="l00060"></a>00060 
+<a name="l00061"></a>00061   w->sinfo_matrix = (<span class="keywordtype">double</span> *) cpl_malloc (nc * nc * <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>));
+<a name="l00062"></a>00062 
+<a name="l00063"></a>00063   <span class="keywordflow">if</span> (w->sinfo_matrix == 0)
+<a name="l00064"></a>00064     {
+<a name="l00065"></a>00065       cpl_free (w) ;       <span class="comment">/* error in constructor, avoid memory leak */</span>
+<a name="l00066"></a>00066       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"failed to allocate for workspace sinfo_matrix"</span>) ;
+<a name="l00067"></a>00067       <span class="keywordflow">return</span>  NULL ;
+<a name="l00068"></a>00068     }
+<a name="l00069"></a>00069 
+<a name="l00070"></a>00070   <span class="keywordflow">return</span> w ;
+<a name="l00071"></a>00071 }
+<a name="l00072"></a>00072 
+<a name="l00073"></a>00073 <span class="keywordtype">void</span>
+<a name="l00074"></a>00074 sinfo_gsl_poly_complex_workspace_free (gsl_poly_complex_workspace * w)
+<a name="l00075"></a>00075 {
+<a name="l00076"></a>00076   cpl_free(w->sinfo_matrix) ;
+<a name="l00077"></a>00077   cpl_free(w);
+<a name="l00078"></a>00078 }
+<a name="l00079"></a>00079 
+<a name="l00080"></a>00080 
+<a name="l00081"></a>00081 <span class="keywordtype">int</span>
+<a name="l00082"></a>00082 sinfo_gsl_poly_complex_solve (<span class="keyword">const</span> <span class="keywordtype">double</span> *a, <span class="keywordtype">size_t</span> n,
+<a name="l00083"></a>00083             gsl_poly_complex_workspace * w,
+<a name="l00084"></a>00084             gsl_complex_packed_ptr z)
+<a name="l00085"></a>00085 {
+<a name="l00086"></a>00086   <span class="keywordtype">int</span> status;
+<a name="l00087"></a>00087   <span class="keywordtype">double</span> *m;
+<a name="l00088"></a>00088 
+<a name="l00089"></a>00089   <span class="keywordflow">if</span> (n == 0)
+<a name="l00090"></a>00090     {
+<a name="l00091"></a>00091       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"number of terms must be a positive integer"</span>);
+<a name="l00092"></a>00092       <span class="keywordflow">return</span> -1 ;
+<a name="l00093"></a>00093     }
+<a name="l00094"></a>00094 
+<a name="l00095"></a>00095   <span class="keywordflow">if</span> (n == 1)
+<a name="l00096"></a>00096     {
+<a name="l00097"></a>00097       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"cannot solve for only one term"</span>);
+<a name="l00098"></a>00098       <span class="keywordflow">return</span> -1 ;
+<a name="l00099"></a>00099     }
+<a name="l00100"></a>00100 
+<a name="l00101"></a>00101   <span class="keywordflow">if</span> (a[n - 1] == 0)
+<a name="l00102"></a>00102     {
+<a name="l00103"></a>00103       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"leading term of polynomial must be non-zero"</span>) ;
+<a name="l00104"></a>00104       <span class="keywordflow">return</span> -1 ;
+<a name="l00105"></a>00105     }
+<a name="l00106"></a>00106 
+<a name="l00107"></a>00107   <span class="keywordflow">if</span> (w->nc != n - 1)
+<a name="l00108"></a>00108     {
+<a name="l00109"></a>00109       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"size of workspace does not match polynomial"</span>);
+<a name="l00110"></a>00110       <span class="keywordflow">return</span> -1 ;
+<a name="l00111"></a>00111     }
+<a name="l00112"></a>00112   
+<a name="l00113"></a>00113   m = w->sinfo_matrix;
+<a name="l00114"></a>00114 
+<a name="l00115"></a>00115   sinfo_set_companion_matrix (a, n - 1, m);
+<a name="l00116"></a>00116 
+<a name="l00117"></a>00117   sinfo_balance_companion_matrix (m, n - 1);
+<a name="l00118"></a>00118 
+<a name="l00119"></a>00119   status = sinfo_qr_companion (m, n - 1, z);
+<a name="l00120"></a>00120 
+<a name="l00121"></a>00121   <span class="keywordflow">if</span> (status == -1)
+<a name="l00122"></a>00122     {
+<a name="l00123"></a>00123       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"root solving qr method failed to converge"</span>);
+<a name="l00124"></a>00124       <span class="keywordflow">return</span> -1 ;
+<a name="l00125"></a>00125     }
+<a name="l00126"></a>00126 
+<a name="l00127"></a>00127   <span class="keywordflow">return</span> 1;
+<a name="l00128"></a>00128 }
+<a name="l00129"></a>00129 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__solve__poly__root_8h_source.html b/html/sinfo__solve__poly__root_8h_source.html
new file mode 100644
index 0000000..078a0a3
--- /dev/null
+++ b/html/sinfo__solve__poly__root_8h_source.html
@@ -0,0 +1,93 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_solve_poly_root.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_solve_poly_root.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#ifndef SINFO_SOLVE_POLY_ROOT_H</span>
+<a name="l00002"></a>00002 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_SOLVE_POLY_ROOT_H</span>
+<a name="l00003"></a>00003 <span class="preprocessor"></span><span class="comment">/*</span>
+<a name="l00004"></a>00004 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00005"></a>00005 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00006"></a>00006 <span class="comment"> *</span>
+<a name="l00007"></a>00007 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00008"></a>00008 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00009"></a>00009 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00010"></a>00010 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00011"></a>00011 <span class="comment"> *</span>
+<a name="l00012"></a>00012 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00013"></a>00013 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00014"></a>00014 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00015"></a>00015 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00016"></a>00016 <span class="comment"> *</span>
+<a name="l00017"></a>00017 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00018"></a>00018 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00019"></a>00019 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00020"></a>00020 <span class="comment"> */</span>
+<a name="l00021"></a>00021 
+<a name="l00022"></a>00022 <span class="comment">/*</span>
+<a name="l00023"></a>00023 <span class="comment">#include <stdio.h></span>
+<a name="l00024"></a>00024 <span class="comment">*/</span>
+<a name="l00025"></a>00025 <span class="preprocessor">#include <stdlib.h></span>
+<a name="l00026"></a>00026 <span class="preprocessor">#include <math.h></span>
+<a name="l00027"></a>00027 <span class="preprocessor">#include <stdlib.h></span>
+<a name="l00028"></a>00028 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00029"></a>00029 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00030"></a>00030 
+<a name="l00031"></a>00031 <span class="comment">/* C-style sinfo_matrix elements */</span>
+<a name="l00032"></a>00032 <span class="preprocessor">#define MAT(m,i,j,n) ((m)[(i)*(n) + (j)])</span>
+<a name="l00033"></a>00033 <span class="preprocessor"></span>
+<a name="l00034"></a>00034 <span class="comment">/* Fortran-style sinfo_matrix elements */</span>
+<a name="l00035"></a>00035 <span class="preprocessor">#define FMAT(m,i,j,n) ((m)[((i)-1)*(n) + ((j)-1)])</span>
+<a name="l00036"></a>00036 <span class="preprocessor"></span>
+<a name="l00037"></a>00037 
+<a name="l00038"></a>00038 <span class="preprocessor">#undef __BEGIN_DECLS</span>
+<a name="l00039"></a>00039 <span class="preprocessor"></span><span class="preprocessor">#undef __END_DECLS</span>
+<a name="l00040"></a>00040 <span class="preprocessor"></span><span class="preprocessor">#ifdef __cplusplus</span>
+<a name="l00041"></a>00041 <span class="preprocessor"></span><span class="preprocessor"># define __BEGIN_DECLS extern "C" {</span>
+<a name="l00042"></a>00042 <span class="preprocessor"></span><span class="preprocessor"># define __END_DECLS }</span>
+<a name="l00043"></a>00043 <span class="preprocessor"></span><span class="preprocessor">#else</span>
+<a name="l00044"></a>00044 <span class="preprocessor"></span><span class="preprocessor"># define __BEGIN_DECLS </span><span class="comment">/* empty */</span>
+<a name="l00045"></a>00045 <span class="preprocessor"># define __END_DECLS </span><span class="comment">/* empty */</span>
+<a name="l00046"></a>00046 <span class="preprocessor">#endif</span>
+<a name="l00047"></a>00047 <span class="preprocessor"></span>
+<a name="l00048"></a>00048 <span class="keyword">typedef</span> <span class="keywordtype">double</span> *       gsl_complex_packed_ptr ;
+<a name="l00049"></a>00049 
+<a name="l00050"></a>00050 <span class="keywordtype">void</span> sinfo_balance_companion_matrix (<span class="keywordtype">double</span> *m, <span class="keywordtype">size_t</span> nc);
+<a name="l00051"></a>00051 <span class="keywordtype">int</span> sinfo_qr_companion (<span class="keywordtype">double</span> *h, <span class="keywordtype">size_t</span> nc, gsl_complex_packed_ptr z);
+<a name="l00052"></a>00052 <span class="keywordtype">void</span> sinfo_set_companion_matrix (<span class="keyword">const</span> <span class="keywordtype">double</span> *a, <span class="keywordtype">size_t</span> n, <span class="keywordtype">double</span> *m);
+<a name="l00053"></a>00053 
+<a name="l00054"></a>00054 __BEGIN_DECLS
+<a name="l00055"></a>00055 
+<a name="l00056"></a>00056 <span class="comment">/* Solve for the complex roots of a general real polynomial */</span>
+<a name="l00057"></a>00057 
+<a name="l00058"></a>00058 <span class="keyword">typedef</span> <span class="keyword">struct </span>
+<a name="l00059"></a>00059 { 
+<a name="l00060"></a>00060   <span class="keywordtype">size_t</span> nc ;
+<a name="l00061"></a>00061   <span class="keywordtype">double</span> * sinfo_matrix ; 
+<a name="l00062"></a>00062 } 
+<a name="l00063"></a>00063 gsl_poly_complex_workspace ;
+<a name="l00064"></a>00064 
+<a name="l00065"></a>00065 gsl_poly_complex_workspace * sinfo_gsl_poly_complex_workspace_alloc (<span class="keywordtype">size_t</span> n);
+<a name="l00066"></a>00066 <span class="keywordtype">void</span> sinfo_gsl_poly_complex_workspace_free (gsl_poly_complex_workspace * w);
+<a name="l00067"></a>00067 
+<a name="l00068"></a>00068 <span class="keywordtype">int</span>
+<a name="l00069"></a>00069 sinfo_gsl_poly_complex_solve (<span class="keyword">const</span> <span class="keywordtype">double</span> * a, <span class="keywordtype">size_t</span> n, 
+<a name="l00070"></a>00070                         gsl_poly_complex_workspace * w,
+<a name="l00071"></a>00071                         gsl_complex_packed_ptr z);
+<a name="l00072"></a>00072             
+<a name="l00073"></a>00073             
+<a name="l00074"></a>00074 
+<a name="l00075"></a>00075 __END_DECLS
+<a name="l00076"></a>00076 
+<a name="l00077"></a>00077 <span class="preprocessor">#endif </span><span class="comment">/* SINFO_SOLVE_POLY_ROOT_H */</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__spectrum__ops_8c_source.html b/html/sinfo__spectrum__ops_8c_source.html
new file mode 100644
index 0000000..bde50cf
--- /dev/null
+++ b/html/sinfo__spectrum__ops_8c_source.html
@@ -0,0 +1,2420 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_spectrum_ops.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_spectrum_ops.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/***************************************************************************</span>
+<a name="l00020"></a>00020 <span class="comment">* E.S.O. - VLT project</span>
+<a name="l00021"></a>00021 <span class="comment">*</span>
+<a name="l00022"></a>00022 <span class="comment">*</span>
+<a name="l00023"></a>00023 <span class="comment">*</span>
+<a name="l00024"></a>00024 <span class="comment">* who       when      what</span>
+<a name="l00025"></a>00025 <span class="comment">* --------  --------  ----------------------------------------------</span>
+<a name="l00026"></a>00026 <span class="comment">* schreib  25/05/00  created</span>
+<a name="l00027"></a>00027 <span class="comment">*/</span>
+<a name="l00028"></a>00028 
+<a name="l00029"></a>00029 <span class="comment">/************************************************************************</span>
+<a name="l00030"></a>00030 <span class="comment">*   NAME</span>
+<a name="l00031"></a>00031 <span class="comment">*        sinfo_spectrum_ops.c -</span>
+<a name="l00032"></a>00032 <span class="comment">*        some sinfo_vector procedures to operate on spectra</span>
+<a name="l00033"></a>00033 <span class="comment">*</span>
+<a name="l00034"></a>00034 <span class="comment">*   SYNOPSIS</span>
+<a name="l00035"></a>00035 <span class="comment">*   #include "sinfo_spectrum_ops.h"</span>
+<a name="l00036"></a>00036 <span class="comment">*</span>
+<a name="l00037"></a>00037 <span class="comment">*   1) Vector * sinfo_new_vector( ulong32 n_elements )</span>
+<a name="l00038"></a>00038 <span class="comment">*   2) void * sinfo_new_destroy_vector( Vector *sinfo_vector )</span>
+<a name="l00039"></a>00039 <span class="comment">*   3) cpl_image * sinfo_new_vector_to_image( Vector * spectrum )</span>
+<a name="l00040"></a>00040 <span class="comment">*   4) Vector * sinfo_new_image_to_vector( cpl_image * spectrum )</span>
+<a name="l00041"></a>00041 <span class="comment">*   5) cpl_image * </span>
+<a name="l00042"></a>00042 <span class="comment">       sinfo_new_extract_spectrum_from_resampled_flat(cpl_image * resflat,</span>
+<a name="l00043"></a>00043 <span class="comment">*                                                   float      loreject,</span>
+<a name="l00044"></a>00044 <span class="comment">*                                                   float      hireject ) </span>
+<a name="l00045"></a>00045 <span class="comment">*   6) cpl_image * sinfo_new_multiply_image_with_spectrum(cpl_image * image, </span>
+<a name="l00046"></a>00046 <span class="comment">                                                          cpl_image * spectrum)</span>
+<a name="l00047"></a>00047 <span class="comment">*   7) cpl_image * sinfo_new_optimal_extraction_from_cube(cpl_imagelist * cube, </span>
+<a name="l00048"></a>00048 <span class="comment">*                                            int       halfbox_x, </span>
+<a name="l00049"></a>00049 <span class="comment">*                                            int       halfbox_y,</span>
+<a name="l00050"></a>00050 <span class="comment">*                                            float     fwhm_factor,</span>
+<a name="l00051"></a>00051 <span class="comment">*                                            float     backvariance,</span>
+<a name="l00052"></a>00052 <span class="comment">*                                            float     sky,</span>
+<a name="l00053"></a>00053 <span class="comment">*                                            float     gain,</span>
+<a name="l00054"></a>00054 <span class="comment">*                                            float     exptime)</span>
+<a name="l00055"></a>00055 <span class="comment">*   8) Vector * sinfo_new_extract_sky_from_cube( cpl_imagelist * cube,</span>
+<a name="l00056"></a>00056 <span class="comment">*                                   float     loReject,</span>
+<a name="l00057"></a>00057 <span class="comment">*                                   float     hiReject,</span>
+<a name="l00058"></a>00058 <span class="comment">*                                   int     * position,</span>
+<a name="l00059"></a>00059 <span class="comment">*                                   int       tolerance,</span>
+<a name="l00060"></a>00060 <span class="comment">*                                   int       posindicator )</span>
+<a name="l00061"></a>00061 <span class="comment">*    9) Vector * sinfo_new_sum_rectangle_of_cube_spectra( cpl_imagelist * cube,</span>
+<a name="l00062"></a>00062 <span class="comment">*                                     int llx,</span>
+<a name="l00063"></a>00063 <span class="comment">*                                     int lly,</span>
+<a name="l00064"></a>00064 <span class="comment">*                                     int urx,</span>
+<a name="l00065"></a>00065 <span class="comment">*                                     int ury )</span>
+<a name="l00066"></a>00066 <span class="comment">*   10) Vector * sinfo_new_sum_circle_of_cube_spectra( cpl_imagelist * cube,</span>
+<a name="l00067"></a>00067 <span class="comment">*                                        int       centerx,</span>
+<a name="l00068"></a>00068 <span class="comment">*                                        int       centery,</span>
+<a name="l00069"></a>00069 <span class="comment">*                                        int       radius )</span>
+<a name="l00070"></a>00070 <span class="comment">*   11) Vector * </span>
+<a name="l00071"></a>00071 <span class="comment">        sinfo_new_mean_rectangle_of_cube_spectra( cpl_imagelist * cube,</span>
+<a name="l00072"></a>00072 <span class="comment">*                                            int llx,</span>
+<a name="l00073"></a>00073 <span class="comment">*                                            int lly,</span>
+<a name="l00074"></a>00074 <span class="comment">*                                            int urx,</span>
+<a name="l00075"></a>00075 <span class="comment">*                                            int ury )</span>
+<a name="l00076"></a>00076 <span class="comment">*   12) Vector * sinfo_new_mean_circle_of_cube_spectra( cpl_imagelist * cube,</span>
+<a name="l00077"></a>00077 <span class="comment">*                                         int       centerx,</span>
+<a name="l00078"></a>00078 <span class="comment">*                                         int       centery,</span>
+<a name="l00079"></a>00079 <span class="comment">*                                         int       radius )</span>
+<a name="l00080"></a>00080 <span class="comment">*   13) Vector * </span>
+<a name="l00081"></a>00081 <span class="comment">        sinfo_new_blackbody_spectrum(char * templateSpec, double temp )</span>
+<a name="l00082"></a>00082 <span class="comment">*   14) Vector * </span>
+<a name="l00083"></a>00083 <span class="comment">        sinfo_new_median_rectangle_of_cube_spectra(cpl_imagelist * cube,</span>
+<a name="l00084"></a>00084 <span class="comment">*                                               int llx,</span>
+<a name="l00085"></a>00085 <span class="comment">*                                               int lly,</span>
+<a name="l00086"></a>00086 <span class="comment">*                                               int urx,</span>
+<a name="l00087"></a>00087 <span class="comment">*                                               int ury )</span>
+<a name="l00088"></a>00088 <span class="comment">*   15) Vector * sinfo_new_median_circle_of_cube_spectra( cpl_imagelist * cube,</span>
+<a name="l00089"></a>00089 <span class="comment">*                                           int       centerx,</span>
+<a name="l00090"></a>00090 <span class="comment">*                                           int       centery,</span>
+<a name="l00091"></a>00091 <span class="comment">*                                           int       radius )</span>
+<a name="l00092"></a>00092 <span class="comment">*   16) Vector * </span>
+<a name="l00093"></a>00093 <span class="comment">        sinfo_new_cleanmean_rectangle_of_cube_spectra(cpl_imagelist * cube,</span>
+<a name="l00094"></a>00094 <span class="comment">*                                                 int llx,</span>
+<a name="l00095"></a>00095 <span class="comment">*                                                 int lly,</span>
+<a name="l00096"></a>00096 <span class="comment">*                                                 int urx,</span>
+<a name="l00097"></a>00097 <span class="comment">*                                                 int ury,</span>
+<a name="l00098"></a>00098 <span class="comment">*                                                 float lo_reject,</span>
+<a name="l00099"></a>00099 <span class="comment">*                                                 float hi_reject )</span>
+<a name="l00100"></a>00100 <span class="comment">*   17) Vector * </span>
+<a name="l00101"></a>00101 <span class="comment">        sinfo_new_cleanmean_circle_of_cube_spectra( cpl_imagelist * cube,</span>
+<a name="l00102"></a>00102 <span class="comment">*                                              int       centerx,</span>
+<a name="l00103"></a>00103 <span class="comment">*                                              int       centery,</span>
+<a name="l00104"></a>00104 <span class="comment">*                                              int       radius,</span>
+<a name="l00105"></a>00105 <span class="comment">*                                              float     lo_reject,</span>
+<a name="l00106"></a>00106 <span class="comment">*                                              float     hi_reject )</span>
+<a name="l00107"></a>00107 <span class="comment">*   18) float * sinfo_new_shift_array ( float * input, </span>
+<a name="l00108"></a>00108 <span class="comment">                                        int n_elements, </span>
+<a name="l00109"></a>00109 <span class="comment">                                        float shift, </span>
+<a name="l00110"></a>00110 <span class="comment">                                        double * ker ) </span>
+<a name="l00111"></a>00111 <span class="comment">*</span>
+<a name="l00112"></a>00112 <span class="comment">*   DESCRIPTION</span>
+<a name="l00113"></a>00113 <span class="comment">*   1) allocates memory for a new sinfo_vector</span>
+<a name="l00114"></a>00114 <span class="comment">*   2) frees memory of a sinfo_vector</span>
+<a name="l00115"></a>00115 <span class="comment">*   3) converts a spectral sinfo_vector to a fits image</span>
+<a name="l00116"></a>00116 <span class="comment">*      remark: sinfo_vector object spectrum is destroyed</span>
+<a name="l00117"></a>00117 <span class="comment">*   4) converts a fits image to a spectral sinfo_vector</span>
+<a name="l00118"></a>00118 <span class="comment">*      remark: input image is destroyed</span>
+<a name="l00119"></a>00119 <span class="comment">*   5) builds one spectrum in a fits image out of a resampled</span>
+<a name="l00120"></a>00120 <span class="comment">*      flatfield frame by taking a clean mean along the spatial pixels</span>
+<a name="l00121"></a>00121 <span class="comment">*   6) multiplys a resampled image with a resampled spectrum</span>
+<a name="l00122"></a>00122 <span class="comment">*      (calibrated halogen lamp spectrum) in the same spectral range</span>
+<a name="l00123"></a>00123 <span class="comment">*      that means all image columns are multiplied with the same spectrum</span>
+<a name="l00124"></a>00124 <span class="comment">*   7) does the optimal extraction of a standard star spectrum</span>
+<a name="l00125"></a>00125 <span class="comment">*      according to the equation:</span>
+<a name="l00126"></a>00126 <span class="comment">*       S = sum { (P^2 / V) * (I - B) / P } / sum{ P^2 / V } </span>
+<a name="l00127"></a>00127 <span class="comment">*       S: spectral flux at a particular wavelength</span>
+<a name="l00128"></a>00128 <span class="comment">*       P: normalized PSF (determined by a 2D-Gaussian fit)</span>
+<a name="l00129"></a>00129 <span class="comment">*       I: pixel value</span>
+<a name="l00130"></a>00130 <span class="comment">*       B: background pixel value determined by the background parameter </span>
+<a name="l00131"></a>00131 <span class="comment">           of the 2D-Gaussian fit</span>
+<a name="l00132"></a>00132 <span class="comment">*       V: estimated variance of a pixel: </span>
+<a name="l00133"></a>00133 <span class="comment">           V = [R^2 + D + sky + I,c/exptime]/gain</span>
+<a name="l00134"></a>00134 <span class="comment">*          where R is the read noise, and D the sinfo_dark current variance.</span>
+<a name="l00135"></a>00135 <span class="comment">*          backvariance is R^2 + D in counts/sec. </span>
+<a name="l00136"></a>00136 <span class="comment">           I,c is the source intensity in counts</span>
+<a name="l00137"></a>00137 <span class="comment">*          Remember: sigma,e[e-] = gain[e/count] * sigma,c [counts] = </span>
+<a name="l00138"></a>00138 <span class="comment">                     sqrt(I,e) = sqrt(gain*I,c)</span>
+<a name="l00139"></a>00139 <span class="comment">*          => V,c = sigma,c^2 = sigma,e^2/gain^2 </span>
+<a name="l00140"></a>00140 <span class="comment">*          => sigma,c = sqrt(I,c/gain) => V,c = I,c/gain</span>
+<a name="l00141"></a>00141 <span class="comment">*   8) extracts a sky spectrum from a reduced sky spider observation, that</span>
+<a name="l00142"></a>00142 <span class="comment">*      means from a data cube. Therefore, the position of the sky within the</span>
+<a name="l00143"></a>00143 <span class="comment">*      field of view must be first read from the fits header.  </span>
+<a name="l00144"></a>00144 <span class="comment">       A pixel tolerance is subtracted.</span>
+<a name="l00145"></a>00145 <span class="comment">*      The found sky spectra are averaged by rejecting the extreme </span>
+<a name="l00146"></a>00146 <span class="comment">       high and low values.</span>
+<a name="l00147"></a>00147 <span class="comment">*   9) summing routine for a reduced data to get a better spectral S/N</span>
+<a name="l00148"></a>00148 <span class="comment">*      only for a rectangular aperture.</span>
+<a name="l00149"></a>00149 <span class="comment">*   10) summing routine for a reduced data to get a better spectral S/N</span>
+<a name="l00150"></a>00150 <span class="comment">*       only for a circular aperture.</span>
+<a name="l00151"></a>00151 <span class="comment">*   11) averaging routine for a reduced data to get a better spectral S/N</span>
+<a name="l00152"></a>00152 <span class="comment">*       only for a rectangular aperture.</span>
+<a name="l00153"></a>00153 <span class="comment">*   12) averaging routine for a reduced data to get a better spectral S/N</span>
+<a name="l00154"></a>00154 <span class="comment">*       only for a circular aperture.</span>
+<a name="l00155"></a>00155 <span class="comment">*   13) computes a blackbody spectral intensity distribution</span>
+<a name="l00156"></a>00156 <span class="comment">*       (W/(m^2 lambda ster)) </span>
+<a name="l00157"></a>00157 <span class="comment">*   14) sinfo_median routine for a reduced data to get a better spectral S/N</span>
+<a name="l00158"></a>00158 <span class="comment">*       only for a rectangular aperture.</span>
+<a name="l00159"></a>00159 <span class="comment">*   15) sinfo_median routine for a reduced data to get a better spectral S/N</span>
+<a name="l00160"></a>00160 <span class="comment">*       only for a circular aperture.</span>
+<a name="l00161"></a>00161 <span class="comment">*   16) clean averaging routine for a reduced data to get a better spectral S/N</span>
+<a name="l00162"></a>00162 <span class="comment">*       only for a rectangular aperture.</span>
+<a name="l00163"></a>00163 <span class="comment">*   17) clean averaging routine for a reduced data to get a better spectral S/N</span>
+<a name="l00164"></a>00164 <span class="comment">*       only for a circular aperture.</span>
+<a name="l00165"></a>00165 <span class="comment">*   18) shifts an array by a sub-pixel shift value using a tanh</span>
+<a name="l00166"></a>00166 <span class="comment">*       interpolation kernel</span>
+<a name="l00167"></a>00167 <span class="comment">*</span>
+<a name="l00168"></a>00168 <span class="comment">*   FILES</span>
+<a name="l00169"></a>00169 <span class="comment">*</span>
+<a name="l00170"></a>00170 <span class="comment">*   ENVIRONMENT</span>
+<a name="l00171"></a>00171 <span class="comment">*</span>
+<a name="l00172"></a>00172 <span class="comment">*   RETURN VALUES</span>
+<a name="l00173"></a>00173 <span class="comment">*</span>
+<a name="l00174"></a>00174 <span class="comment">*   CAUTIONS</span>
+<a name="l00175"></a>00175 <span class="comment">*</span>
+<a name="l00176"></a>00176 <span class="comment">*   EXAMPLES</span>
+<a name="l00177"></a>00177 <span class="comment">*</span>
+<a name="l00178"></a>00178 <span class="comment">*   SEE ALSO</span>
+<a name="l00179"></a>00179 <span class="comment">*</span>
+<a name="l00180"></a>00180 <span class="comment">*   BUGS</span>
+<a name="l00181"></a>00181 <span class="comment">*</span>
+<a name="l00182"></a>00182 <span class="comment">*------------------------------------------------------------------------</span>
+<a name="l00183"></a>00183 <span class="comment">*/</span>
+<a name="l00184"></a>00184 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00185"></a>00185 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00186"></a>00186 <span class="preprocessor">#endif</span>
+<a name="l00187"></a>00187 <span class="preprocessor"></span>
+<a name="l00188"></a>00188 <span class="preprocessor">#define POSIX_SOURCE 1</span>
+<a name="l00189"></a>00189 <span class="preprocessor"></span><span class="preprocessor">#include "sinfo_vltPort.h"</span>
+<a name="l00190"></a>00190 
+<a name="l00191"></a>00191 <span class="comment">/*</span>
+<a name="l00192"></a>00192 <span class="comment"> * System Headers</span>
+<a name="l00193"></a>00193 <span class="comment"> */</span>
+<a name="l00194"></a>00194 
+<a name="l00195"></a>00195 <span class="comment">/*</span>
+<a name="l00196"></a>00196 <span class="comment"> * Local Headers</span>
+<a name="l00197"></a>00197 <span class="comment"> */</span>
+<a name="l00198"></a>00198 <span class="preprocessor">#include "sinfo_pfits.h"</span>
+<a name="l00199"></a>00199 <span class="preprocessor">#include "sinfo_spectrum_ops.h"</span>
+<a name="l00200"></a>00200 <span class="preprocessor">#include "sinfo_resampling.h"</span>
+<a name="l00201"></a>00201 <span class="preprocessor">#include "sinfo_utilities.h"</span>
+<a name="l00202"></a>00202 <span class="preprocessor">#include "sinfo_utils_wrappers.h"</span>
+<a name="l00203"></a>00203 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00204"></a>00204 <span class="comment"> *                            Function codes</span>
+<a name="l00205"></a>00205 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00206"></a>00206 
+<a name="l00224"></a>00224 <span class="keywordtype">int</span> sinfo_stectrum_ima2table(
+<a name="l00225"></a>00225                  <span class="keyword">const</span> cpl_image* spc,
+<a name="l00226"></a>00226                  <span class="keyword">const</span> <span class="keywordtype">char</span>* filename,
+<a name="l00227"></a>00227                  cpl_table** tbl)
+<a name="l00228"></a>00228 {
+<a name="l00229"></a>00229   <span class="keyword">const</span> <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l00230"></a>00230   <span class="keywordtype">int</span> nx=0;
+<a name="l00231"></a>00231   <span class="keywordtype">int</span> ny=0;
+<a name="l00232"></a>00232   <span class="keywordtype">int</span> nraw=0;
+<a name="l00233"></a>00233   <span class="keywordtype">int</span> i=0;
+<a name="l00234"></a>00234   <span class="keywordtype">double</span> amp=0;
+<a name="l00235"></a>00235   <span class="keywordtype">double</span> wav=0;
+<a name="l00236"></a>00236  
+<a name="l00237"></a>00237   <span class="keywordtype">double</span> step=0;
+<a name="l00238"></a>00238   <span class="keywordtype">double</span> ws=0;
+<a name="l00239"></a>00239   <span class="keywordtype">double</span> we=0;
+<a name="l00240"></a>00240   <span class="keywordtype">double</span> wc=0;
+<a name="l00241"></a>00241   cpl_propertylist* plist=NULL;
+<a name="l00242"></a>00242 
+<a name="l00243"></a>00243   <span class="keywordflow">if</span>(spc == NULL){
+<a name="l00244"></a>00244     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Input image is null"</span>);
+<a name="l00245"></a>00245     <span class="keywordflow">return</span> -1;
+<a name="l00246"></a>00246   }
+<a name="l00247"></a>00247 
+<a name="l00248"></a>00248   pidata = cpl_image_get_data_const(spc);
+<a name="l00249"></a>00249   nx=cpl_image_get_size_x(spc);
+<a name="l00250"></a>00250   ny=cpl_image_get_size_y(spc);
+<a name="l00251"></a>00251 
+<a name="l00252"></a>00252   <span class="keywordflow">if</span>((nx == 0) || (ny == 0)) {
+<a name="l00253"></a>00253     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Input image has improper size: nx=%d ny=%d"</span>,nx,ny);
+<a name="l00254"></a>00254     <span class="keywordflow">return</span> -1;
+<a name="l00255"></a>00255   }
+<a name="l00256"></a>00256   <span class="keywordflow">if</span>((nx > 1) && (ny > 1)) {
+<a name="l00257"></a>00257     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Input image has improper size: nx=%d ny=%d"</span>,nx,ny);
+<a name="l00258"></a>00258     <span class="keywordflow">return</span> -1;
+<a name="l00259"></a>00259   }
+<a name="l00260"></a>00260 
+<a name="l00261"></a>00261 
+<a name="l00262"></a>00262   nraw=nx*ny;
+<a name="l00263"></a>00263   *tbl = cpl_table_new(nraw);
+<a name="l00264"></a>00264   cpl_table_new_column(*tbl,<span class="stringliteral">"WAVE"</span>,CPL_TYPE_DOUBLE);
+<a name="l00265"></a>00265   cpl_table_new_column(*tbl,<span class="stringliteral">"INT"</span>,CPL_TYPE_DOUBLE);
+<a name="l00266"></a>00266 
+<a name="l00267"></a>00267 
+<a name="l00268"></a>00268   <span class="keywordflow">if</span> ((cpl_error_code)((plist = cpl_propertylist_load(filename, 0)) == NULL)) {
+<a name="l00269"></a>00269       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>( <span class="stringliteral">"getting header from reference frame %s"</span>,filename);
+<a name="l00270"></a>00270       cpl_propertylist_delete(plist) ;
+<a name="l00271"></a>00271       <span class="keywordflow">return</span> -1 ;
+<a name="l00272"></a>00272   }
+<a name="l00273"></a>00273 
+<a name="l00274"></a>00274 
+<a name="l00275"></a>00275   <span class="keywordflow">if</span>(nx>1) {
+<a name="l00276"></a>00276     step=sinfo_pfits_get_cdelt1(plist);
+<a name="l00277"></a>00277     wc=sinfo_pfits_get_crval1(plist);
+<a name="l00278"></a>00278   } <span class="keywordflow">else</span> {
+<a name="l00279"></a>00279 
+<a name="l00280"></a>00280     step=sinfo_pfits_get_cdelt2(plist);
+<a name="l00281"></a>00281     wc=sinfo_pfits_get_crval2(plist);
+<a name="l00282"></a>00282   }
+<a name="l00283"></a>00283 
+<a name="l00284"></a>00284   ws=wc-nraw*step/2;
+<a name="l00285"></a>00285   we=wc+nraw*step/2;
+<a name="l00286"></a>00286   wav=ws;
+<a name="l00287"></a>00287   sinfo_msg(<span class="stringliteral">"ws=%f we=%f step=%f"</span>,ws,we,step);
+<a name="l00288"></a>00288   cpl_table_set_double(*tbl,<span class="stringliteral">"WAVE"</span>,0,wav);
+<a name="l00289"></a>00289   cpl_table_set_double(*tbl,<span class="stringliteral">"INT"</span>,0,pidata[i]);
+<a name="l00290"></a>00290 
+<a name="l00291"></a>00291   <span class="keywordflow">for</span>(i=1;i<nraw;i++) {
+<a name="l00292"></a>00292     wav+=step;
+<a name="l00293"></a>00293     amp=(double)pidata[i];
+<a name="l00294"></a>00294     cpl_table_set_double(*tbl,<span class="stringliteral">"WAVE"</span>,i,wav);
+<a name="l00295"></a>00295     cpl_table_set_double(*tbl,<span class="stringliteral">"INT"</span>,i,amp);
+<a name="l00296"></a>00296   }
+<a name="l00297"></a>00297   cpl_propertylist_delete(plist);
+<a name="l00298"></a>00298   <span class="keywordflow">return</span> 0;
+<a name="l00299"></a>00299 
+<a name="l00300"></a>00300 
+<a name="l00301"></a>00301 }
+<a name="l00302"></a>00302 
+<a name="l00303"></a>00303 
+<a name="l00304"></a>00304 
+<a name="l00314"></a>00314 Vector * sinfo_new_vector( ulong32 n_elements )
+<a name="l00315"></a>00315 {
+<a name="l00316"></a>00316     Vector * local_new_vector ;
+<a name="l00317"></a>00317 
+<a name="l00318"></a>00318     <span class="keywordflow">if</span> ( n_elements <= 0 )
+<a name="l00319"></a>00319     {
+<a name="l00320"></a>00320         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" wrong number of elements\n"</span>) ;
+<a name="l00321"></a>00321         <span class="keywordflow">return</span> NullVector ;
+<a name="l00322"></a>00322     }
+<a name="l00323"></a>00323     
+<a name="l00324"></a>00324     <span class="comment">/* allocate memory for a sinfo_vector with the given number of elements */</span>
+<a name="l00325"></a>00325     local_new_vector = (Vector *) cpl_malloc (<span class="keyword">sizeof</span> (Vector)) ; 
+<a name="l00326"></a>00326     local_new_vector -> n_elements = n_elements ;
+<a name="l00327"></a>00327     local_new_vector -> data = (pixelvalue *) cpl_calloc (n_elements, 
+<a name="l00328"></a>00328                                                   <span class="keyword">sizeof</span> (pixelvalue)) ;
+<a name="l00329"></a>00329 
+<a name="l00330"></a>00330     <span class="keywordflow">return</span> local_new_vector ;
+<a name="l00331"></a>00331 }
+<a name="l00332"></a>00332 
+<a name="l00340"></a>00340 <span class="keywordtype">void</span> sinfo_free_svector( Vector **svector )
+<a name="l00341"></a>00341 {
+<a name="l00342"></a>00342     <span class="keywordflow">if</span> ( *svector != NULL )   
+<a name="l00343"></a>00343     {
+<a name="l00344"></a>00344        
+<a name="l00345"></a>00345       <span class="keywordflow">if</span>((*svector) -> data != NULL) {
+<a name="l00346"></a>00346     cpl_free ( (*svector) -> data ) ;
+<a name="l00347"></a>00347     (*svector)->data = NULL;
+<a name="l00348"></a>00348       }
+<a name="l00349"></a>00349       cpl_free ( *svector ) ;
+<a name="l00350"></a>00350       *svector = NULL;
+<a name="l00351"></a>00351     }
+<a name="l00352"></a>00352     return ;
+<a name="l00353"></a>00353 }
+<a name="l00354"></a>00354 
+<a name="l00362"></a>00362 <span class="keywordtype">void</span> sinfo_new_destroy_vector( Vector *sinfo_vector )
+<a name="l00363"></a>00363 {
+<a name="l00364"></a>00364     <span class="keywordflow">if</span> ( sinfo_vector == NULL )   
+<a name="l00365"></a>00365     {
+<a name="l00366"></a>00366         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" NULL Vector given!\n"</span>) ;
+<a name="l00367"></a>00367         return ;
+<a name="l00368"></a>00368     }    
+<a name="l00369"></a>00369     
+<a name="l00370"></a>00370     cpl_free ( sinfo_vector -> data ) ;
+<a name="l00371"></a>00371     cpl_free ( sinfo_vector ) ;
+<a name="l00372"></a>00372 }
+<a name="l00373"></a>00373 
+<a name="l00382"></a>00382 cpl_image * sinfo_new_vector_to_image( Vector * spectrum )
+<a name="l00383"></a>00383 {
+<a name="l00384"></a>00384     cpl_image * returnIm ;
+<a name="l00385"></a>00385     <span class="keywordtype">int</span> i ;
+<a name="l00386"></a>00386    
+<a name="l00387"></a>00387     <span class="keywordtype">float</span>* podata=NULL;
+<a name="l00388"></a>00388 
+<a name="l00389"></a>00389 
+<a name="l00390"></a>00390     <span class="keywordflow">if</span> ( spectrum == NULL )
+<a name="l00391"></a>00391     {
+<a name="l00392"></a>00392         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" no spectrum given!\n"</span>) ;
+<a name="l00393"></a>00393         <span class="keywordflow">return</span> NULL ;
+<a name="l00394"></a>00394     }
+<a name="l00395"></a>00395  
+<a name="l00396"></a>00396     <span class="comment">/* allocate memory */</span>
+<a name="l00397"></a>00397     <span class="keywordflow">if</span> ( NULL == (returnIm = cpl_image_new(1, spectrum->n_elements,
+<a name="l00398"></a>00398                                            CPL_TYPE_FLOAT)) )
+<a name="l00399"></a>00399     {
+<a name="l00400"></a>00400         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" no spectrum given!\n"</span>) ;
+<a name="l00401"></a>00401         sinfo_new_destroy_vector(spectrum) ;
+<a name="l00402"></a>00402         <span class="keywordflow">return</span> NULL ;
+<a name="l00403"></a>00403     }
+<a name="l00404"></a>00404 
+<a name="l00405"></a>00405     podata=cpl_image_get_data_float(returnIm);
+<a name="l00406"></a>00406     <span class="keywordflow">for</span> ( i = 0 ; i < spectrum->n_elements ; i++ )
+<a name="l00407"></a>00407     {
+<a name="l00408"></a>00408         podata[i] = spectrum -> data[i] ;
+<a name="l00409"></a>00409     }
+<a name="l00410"></a>00410 
+<a name="l00411"></a>00411     sinfo_new_destroy_vector (spectrum) ;
+<a name="l00412"></a>00412     <span class="keywordflow">return</span> returnIm ;
+<a name="l00413"></a>00413 }
+<a name="l00414"></a>00414 
+<a name="l00423"></a>00423 Vector * sinfo_new_image_to_vector( cpl_image * spectrum )
+<a name="l00424"></a>00424 {
+<a name="l00425"></a>00425     Vector * returnVector ;
+<a name="l00426"></a>00426     <span class="keywordtype">int</span> i ;
+<a name="l00427"></a>00427     <span class="keywordtype">int</span> ilx=0;
+<a name="l00428"></a>00428     <span class="keywordtype">int</span> ily=0;
+<a name="l00429"></a>00429   
+<a name="l00430"></a>00430     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l00431"></a>00431 
+<a name="l00432"></a>00432     <span class="keywordflow">if</span> ( spectrum == NULL )
+<a name="l00433"></a>00433     {
+<a name="l00434"></a>00434         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" no spectrum given!"</span>) ;
+<a name="l00435"></a>00435         <span class="keywordflow">return</span> NULL ;
+<a name="l00436"></a>00436     }
+<a name="l00437"></a>00437     ilx=cpl_image_get_size_x(spectrum);
+<a name="l00438"></a>00438     ily=cpl_image_get_size_y(spectrum);
+<a name="l00439"></a>00439 
+<a name="l00440"></a>00440     <span class="comment">/* allocate memory */</span>
+<a name="l00441"></a>00441     <span class="keywordflow">if</span> ( NULL == (returnVector = sinfo_new_vector(ilx*ily)) )
+<a name="l00442"></a>00442     {
+<a name="l00443"></a>00443         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" cannot allocate memory!"</span>) ;
+<a name="l00444"></a>00444         cpl_image_delete(spectrum) ;
+<a name="l00445"></a>00445         <span class="keywordflow">return</span> NULL ;
+<a name="l00446"></a>00446     }
+<a name="l00447"></a>00447 
+<a name="l00448"></a>00448     pidata=cpl_image_get_data_float(spectrum);
+<a name="l00449"></a>00449     <span class="keywordflow">for</span> ( i = 0 ; i < (int) ilx*ily ; i++ )
+<a name="l00450"></a>00450     {
+<a name="l00451"></a>00451         returnVector -> data[i] = pidata[i] ;
+<a name="l00452"></a>00452     }
+<a name="l00453"></a>00453 
+<a name="l00454"></a>00454     cpl_image_delete (spectrum) ;
+<a name="l00455"></a>00455     <span class="keywordflow">return</span> returnVector ;
+<a name="l00456"></a>00456 }
+<a name="l00457"></a>00457 
+<a name="l00470"></a>00470 cpl_image * 
+<a name="l00471"></a>00471 sinfo_new_extract_spectrum_from_resampled_flat( cpl_image * resflat,
+<a name="l00472"></a>00472                                              <span class="keywordtype">float</span>      loreject,
+<a name="l00473"></a>00473                                              <span class="keywordtype">float</span>      hireject ) 
+<a name="l00474"></a>00474 {
+<a name="l00475"></a>00475     cpl_image * retIm ;
+<a name="l00476"></a>00476     <span class="keywordtype">int</span> col, row ;
+<a name="l00477"></a>00477     <span class="keywordtype">int</span> n ;
+<a name="l00478"></a>00478     <span class="keywordtype">float</span>* array=NULL ;
+<a name="l00479"></a>00479     <span class="keywordtype">float</span> cleanMean ;
+<a name="l00480"></a>00480     Vector * spectrum ;
+<a name="l00481"></a>00481 
+<a name="l00482"></a>00482     <span class="keywordtype">int</span> ilx=0;
+<a name="l00483"></a>00483     <span class="keywordtype">int</span> ily=0;
+<a name="l00484"></a>00484   
+<a name="l00485"></a>00485     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l00486"></a>00486   
+<a name="l00487"></a>00487     <span class="keywordflow">if</span> ( resflat == NULL )
+<a name="l00488"></a>00488     {
+<a name="l00489"></a>00489         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" no flatfield given!"</span>) ;
+<a name="l00490"></a>00490         <span class="keywordflow">return</span> NULL ;
+<a name="l00491"></a>00491     }
+<a name="l00492"></a>00492     ilx=cpl_image_get_size_x(resflat);
+<a name="l00493"></a>00493     ily=cpl_image_get_size_y(resflat);
+<a name="l00494"></a>00494 
+<a name="l00495"></a>00495     <span class="comment">/* allocate memory */</span>
+<a name="l00496"></a>00496     <span class="keywordflow">if</span> ( NullVector == (spectrum = sinfo_new_vector(ily) ) )
+<a name="l00497"></a>00497     {
+<a name="l00498"></a>00498         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" could not allocate memory!"</span>) ;
+<a name="l00499"></a>00499         <span class="keywordflow">return</span> NULL ;
+<a name="l00500"></a>00500     }
+<a name="l00501"></a>00501 
+<a name="l00502"></a>00502     array=cpl_calloc(ily,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l00503"></a>00503 
+<a name="l00504"></a>00504     pidata=cpl_image_get_data_float(resflat);
+<a name="l00505"></a>00505     <span class="keywordflow">for</span> ( row = 0 ; row < ily ; row++ )
+<a name="l00506"></a>00506     {
+<a name="l00507"></a>00507         n = 0 ;
+<a name="l00508"></a>00508         <span class="keywordflow">for</span> ( col = 0 ; col < ilx ; col++ )
+<a name="l00509"></a>00509         {
+<a name="l00510"></a>00510             <span class="keywordflow">if</span> ( !isnan(pidata[col + row*ilx]) )
+<a name="l00511"></a>00511             {
+<a name="l00512"></a>00512                 array[n] = pidata[col+row*ilx] ;
+<a name="l00513"></a>00513                 n++ ;
+<a name="l00514"></a>00514             }
+<a name="l00515"></a>00515         }
+<a name="l00516"></a>00516         <span class="keywordflow">if</span> ( n == 0 )
+<a name="l00517"></a>00517         {
+<a name="l00518"></a>00518             <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">" only bad pixels in row: %d!"</span>, row) ;
+<a name="l00519"></a>00519             cleanMean = ZERO ;
+<a name="l00520"></a>00520         }
+<a name="l00521"></a>00521         <span class="keywordflow">else</span>
+<a name="l00522"></a>00522         {
+<a name="l00523"></a>00523             <span class="keywordflow">if</span> ( FLT_MAX == (cleanMean = sinfo_new_clean_mean(array, n, 
+<a name="l00524"></a>00524                                                               loreject, 
+<a name="l00525"></a>00525                                                               hireject)) )
+<a name="l00526"></a>00526             {
+<a name="l00527"></a>00527                 <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" could not do sinfo_clean_mean!"</span>) ;
+<a name="l00528"></a>00528                 sinfo_new_destroy_vector(spectrum) ;
+<a name="l00529"></a>00529                 <span class="keywordflow">return</span> NULL ;
+<a name="l00530"></a>00530             }
+<a name="l00531"></a>00531         }
+<a name="l00532"></a>00532         spectrum->data[row] = cleanMean ; 
+<a name="l00533"></a>00533     }
+<a name="l00534"></a>00534     <span class="keywordflow">if</span> ( NULL == ( retIm = sinfo_new_vector_to_image( spectrum ) ) )
+<a name="l00535"></a>00535     {
+<a name="l00536"></a>00536         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" could not do sinfo_vectorToImage!"</span>) ;
+<a name="l00537"></a>00537         sinfo_new_destroy_vector(spectrum) ;
+<a name="l00538"></a>00538         <span class="keywordflow">return</span> NULL ;
+<a name="l00539"></a>00539     }
+<a name="l00540"></a>00540     cpl_free(array) ;
+<a name="l00541"></a>00541 
+<a name="l00542"></a>00542     <span class="keywordflow">return</span> retIm ;
+<a name="l00543"></a>00543 }
+<a name="l00544"></a>00544 
+<a name="l00558"></a>00558 cpl_image * 
+<a name="l00559"></a>00559 sinfo_new_multiply_image_with_spectrum( cpl_image * image, 
+<a name="l00560"></a>00560                                         cpl_image * spectrum )
+<a name="l00561"></a>00561 {
+<a name="l00562"></a>00562     <span class="keywordtype">int</span> col, row ;
+<a name="l00563"></a>00563     cpl_image * retImage ;
+<a name="l00564"></a>00564 
+<a name="l00565"></a>00565 
+<a name="l00566"></a>00566     <span class="keywordtype">int</span> ilx=0;
+<a name="l00567"></a>00567     <span class="keywordtype">int</span> ily=0;
+<a name="l00568"></a>00568     <span class="keywordtype">int</span> slx=0;
+<a name="l00569"></a>00569     <span class="keywordtype">int</span> sly=0;
+<a name="l00570"></a>00570 
+<a name="l00571"></a>00571     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l00572"></a>00572     <span class="keywordtype">float</span>* psdata=NULL;
+<a name="l00573"></a>00573     <span class="keywordtype">float</span>* podata=NULL;
+<a name="l00574"></a>00574 
+<a name="l00575"></a>00575 
+<a name="l00576"></a>00576     <span class="keywordflow">if</span> ( image == NULL )
+<a name="l00577"></a>00577     {
+<a name="l00578"></a>00578         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" no image given!"</span>) ;
+<a name="l00579"></a>00579         <span class="keywordflow">return</span> NULL ;
+<a name="l00580"></a>00580     }
+<a name="l00581"></a>00581     ilx=cpl_image_get_size_x(image);
+<a name="l00582"></a>00582     ily=cpl_image_get_size_y(image);
+<a name="l00583"></a>00583 
+<a name="l00584"></a>00584     <span class="keywordflow">if</span> ( spectrum == NULL )
+<a name="l00585"></a>00585     {
+<a name="l00586"></a>00586         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" no spectrum image given!"</span>) ;
+<a name="l00587"></a>00587         <span class="keywordflow">return</span> NULL ;
+<a name="l00588"></a>00588     }
+<a name="l00589"></a>00589     slx=cpl_image_get_size_x(spectrum);
+<a name="l00590"></a>00590     sly=cpl_image_get_size_y(spectrum);
+<a name="l00591"></a>00591 
+<a name="l00592"></a>00592     <span class="keywordflow">if</span> ( sly != ily )
+<a name="l00593"></a>00593     {
+<a name="l00594"></a>00594         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" images are not compatible in pixel length!"</span>) ;
+<a name="l00595"></a>00595         <span class="keywordflow">return</span> NULL ;
+<a name="l00596"></a>00596     }
+<a name="l00597"></a>00597 
+<a name="l00598"></a>00598     <span class="keywordflow">if</span> ( NULL == (retImage = cpl_image_duplicate(image)) )
+<a name="l00599"></a>00599     {
+<a name="l00600"></a>00600         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" could not copy original image!\n"</span>) ;
+<a name="l00601"></a>00601         <span class="keywordflow">return</span> NULL ;
+<a name="l00602"></a>00602     }
+<a name="l00603"></a>00603 
+<a name="l00604"></a>00604     pidata=cpl_image_get_data_float(image);
+<a name="l00605"></a>00605     psdata=cpl_image_get_data_float(spectrum);
+<a name="l00606"></a>00606     podata=cpl_image_get_data_float(retImage);
+<a name="l00607"></a>00607 
+<a name="l00608"></a>00608     <span class="keywordflow">for</span> ( col = 0 ; col < ilx ; col++ )
+<a name="l00609"></a>00609     {
+<a name="l00610"></a>00610         <span class="keywordflow">for</span> ( row = 0 ; row < ily ; row++ )
+<a name="l00611"></a>00611         {
+<a name="l00612"></a>00612             <span class="keywordflow">if</span> ( !isnan(pidata[col+row*ilx]) &&
+<a name="l00613"></a>00613                  !isnan(psdata[col+row*ilx]))
+<a name="l00614"></a>00614             {
+<a name="l00615"></a>00615                 podata[col+row*ilx] = pidata[col+row*ilx] * psdata[row] ;
+<a name="l00616"></a>00616                                                    
+<a name="l00617"></a>00617             }
+<a name="l00618"></a>00618         }
+<a name="l00619"></a>00619     }
+<a name="l00620"></a>00620     <span class="keywordflow">return</span> retImage ;
+<a name="l00621"></a>00621 }
+<a name="l00622"></a>00622 
+<a name="l00661"></a>00661 cpl_image * sinfo_new_optimal_extraction_from_cube( cpl_imagelist * cube, 
+<a name="l00662"></a>00662                                       <span class="keywordtype">int</span>       llx,
+<a name="l00663"></a>00663                                       <span class="keywordtype">int</span>       lly,
+<a name="l00664"></a>00664                                       <span class="keywordtype">int</span>       halfbox_x, 
+<a name="l00665"></a>00665                                       <span class="keywordtype">int</span>       halfbox_y,
+<a name="l00666"></a>00666                                       <span class="keywordtype">float</span>     fwhm_factor,
+<a name="l00667"></a>00667                                       <span class="keywordtype">float</span>     backvariance,
+<a name="l00668"></a>00668                                       <span class="keywordtype">float</span>     sky,
+<a name="l00669"></a>00669                                       <span class="keywordtype">float</span>     gain,
+<a name="l00670"></a>00670                                       <span class="keywordtype">float</span>     exptime,
+<a name="l00671"></a>00671                                       <span class="keyword">const</span> <span class="keywordtype">char</span>* name,
+<a name="l00672"></a>00672                                       cpl_table** spectrum,
+<a name="l00673"></a>00673                       <span class="keywordtype">int</span>       qc_info,
+<a name="l00674"></a>00674                                       <span class="keywordtype">int</span>*      check2)
+<a name="l00675"></a>00675 {
+<a name="l00676"></a>00676     <span class="keywordtype">int</span> col, row, z ;
+<a name="l00677"></a>00677     cpl_image * averagedIm ; 
+<a name="l00678"></a>00678     cpl_image * retIm ;
+<a name="l00679"></a>00679     <span class="keywordtype">double</span> fit_par[7] ;
+<a name="l00680"></a>00680     <span class="keywordtype">double</span> derv_par[7] ;
+<a name="l00681"></a>00681     <span class="keywordtype">int</span> mpar[7] ;
+<a name="l00682"></a>00682     <span class="keywordtype">double</span> gfit_par[7] ;
+<a name="l00683"></a>00683     <span class="keywordtype">double</span> gderv_par[7] ;
+<a name="l00684"></a>00684     <span class="keywordtype">int</span> gmpar[7] ;
+<a name="l00685"></a>00685     <span class="keywordtype">int</span> fitInd ;
+<a name="l00686"></a>00686     <span class="keywordtype">int</span> i ;
+<a name="l00687"></a>00687     <span class="keywordtype">double</span> sum ;
+<a name="l00688"></a>00688     <span class="keywordtype">double</span>** weight=NULL ;
+<a name="l00689"></a>00689     <span class="keywordtype">double</span>** sinfo_psf=NULL ;
+<a name="l00690"></a>00690 
+<a name="l00691"></a>00691     <span class="keywordtype">double</span> variance ;
+<a name="l00692"></a>00692     <span class="keywordtype">double</span> xdat[2] ;
+<a name="l00693"></a>00693     <span class="keywordtype">float</span> weighted_sum ;
+<a name="l00694"></a>00694     <span class="keywordtype">float</span> counts_tot ;
+<a name="l00695"></a>00695     <span class="keywordtype">float</span> counts_bkg ;
+<a name="l00696"></a>00696     <span class="keywordtype">float</span> bkg_tot ;
+<a name="l00697"></a>00697 
+<a name="l00698"></a>00698 
+<a name="l00699"></a>00699     <span class="keywordtype">int</span> first_col, last_col ;
+<a name="l00700"></a>00700     <span class="keywordtype">int</span> first_row, last_row ;
+<a name="l00701"></a>00701     <span class="keywordtype">float</span> norm ;
+<a name="l00702"></a>00702     <span class="keywordtype">float</span> sum_psf=0;
+<a name="l00703"></a>00703     <span class="keywordtype">float</span> sum_wgt=0;
+<a name="l00704"></a>00704     <span class="keywordtype">float</span> cenpix = 0;
+<a name="l00705"></a>00705     <span class="keywordtype">float</span> cenLambda = 0;
+<a name="l00706"></a>00706     <span class="keywordtype">float</span> dispersion = 0;
+<a name="l00707"></a>00707     <span class="keywordtype">float</span> lambda=0;
+<a name="l00708"></a>00708     <span class="keywordtype">float</span> lambda_start=0;
+<a name="l00709"></a>00709 
+<a name="l00710"></a>00710     <span class="keywordtype">int</span> ilx=0;
+<a name="l00711"></a>00711     <span class="keywordtype">int</span> ily=0;
+<a name="l00712"></a>00712     <span class="keywordtype">int</span> inp=0;
+<a name="l00713"></a>00713     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l00714"></a>00714     <span class="keywordtype">float</span>* padata=NULL;
+<a name="l00715"></a>00715     <span class="keywordtype">float</span>* podata=NULL;
+<a name="l00716"></a>00716     <span class="keywordtype">float</span> tmp_val=0;
+<a name="l00717"></a>00717     cpl_propertylist* plist=NULL;
+<a name="l00718"></a>00718     cpl_image* i_img=NULL;
+<a name="l00719"></a>00719 
+<a name="l00720"></a>00720 
+<a name="l00721"></a>00721     <span class="comment">/* TODO: the sky here is not really used. We remove compilation warning */</span>
+<a name="l00722"></a>00722     sky=0;
+<a name="l00723"></a>00723 
+<a name="l00724"></a>00724     <span class="keywordflow">if</span> ( NULL == cube )
+<a name="l00725"></a>00725     {
+<a name="l00726"></a>00726         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" no cube given!\n"</span>) ;
+<a name="l00727"></a>00727         <span class="keywordflow">return</span> NULL ;
+<a name="l00728"></a>00728     }
+<a name="l00729"></a>00729 
+<a name="l00730"></a>00730 
+<a name="l00731"></a>00731     ilx=cpl_image_get_size_x(cpl_imagelist_get(cube,0));
+<a name="l00732"></a>00732     ily=cpl_image_get_size_y(cpl_imagelist_get(cube,0));
+<a name="l00733"></a>00733     inp=cpl_imagelist_get_size(cube);
+<a name="l00734"></a>00734 
+<a name="l00735"></a>00735     <span class="keywordflow">if</span> ( llx < 0 || llx + 2*halfbox_x >= ilx || 
+<a name="l00736"></a>00736          lly < 0 || lly + 2*halfbox_y >= ily )
+<a name="l00737"></a>00737     {
+<a name="l00738"></a>00738       sinfo_msg(<span class="stringliteral">"llx=%d, lly=%d,  llx + 2*halfbox_x=%d, "</span>
+<a name="l00739"></a>00739                 <span class="stringliteral">"lly + 2*halfbox_y=%d"</span>,
+<a name="l00740"></a>00740                 llx,lly,llx + 2*halfbox_x,lly + 2*halfbox_y);
+<a name="l00741"></a>00741       sinfo_msg(<span class="stringliteral">"tresh_min_x=%d, tresh_min_y=%d, "</span>
+<a name="l00742"></a>00742                 <span class="stringliteral">"tresh_max_x=%d, tresh_max_y=%d"</span>,0,0,ilx,ily);
+<a name="l00743"></a>00743         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" lower left sinfo_edge points wrong position!"</span>) ;
+<a name="l00744"></a>00744         <span class="keywordflow">return</span> NULL ;
+<a name="l00745"></a>00745     }
+<a name="l00746"></a>00746     <span class="keywordflow">if</span> ( halfbox_x <= 0 || halfbox_y <= 0 || 
+<a name="l00747"></a>00747          2*halfbox_x > ilx || 2*halfbox_y > ily )
+<a name="l00748"></a>00748     {
+<a name="l00749"></a>00749         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" wrong halfbox width given!"</span>) ;
+<a name="l00750"></a>00750         <span class="keywordflow">return</span> NULL ;
+<a name="l00751"></a>00751     }
+<a name="l00752"></a>00752     <span class="keywordflow">if</span> ( fwhm_factor <= 0. )
+<a name="l00753"></a>00753     {
+<a name="l00754"></a>00754         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" wrong fwhm_factor given!"</span>) ;
+<a name="l00755"></a>00755         <span class="keywordflow">return</span> NULL ;
+<a name="l00756"></a>00756     }
+<a name="l00757"></a>00757     <span class="keywordflow">if</span> ( backvariance < 0. )
+<a name="l00758"></a>00758     {
+<a name="l00759"></a>00759         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" wrong backvariance given!"</span>) ;
+<a name="l00760"></a>00760         <span class="keywordflow">return</span> NULL ;
+<a name="l00761"></a>00761     }
+<a name="l00762"></a>00762     <span class="keywordflow">if</span> ( exptime <= 0. || exptime == FLAG )
+<a name="l00763"></a>00763     {
+<a name="l00764"></a>00764         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" wrong exposure time given!"</span>) ;
+<a name="l00765"></a>00765         <span class="keywordflow">return</span> NULL ;
+<a name="l00766"></a>00766     }
+<a name="l00767"></a>00767 
+<a name="l00768"></a>00768     <span class="comment">/* allocate memory for spectrum */</span>
+<a name="l00769"></a>00769     <span class="keywordflow">if</span> ( NULL == (retIm = cpl_image_new(1, inp,CPL_TYPE_FLOAT)) )
+<a name="l00770"></a>00770     {
+<a name="l00771"></a>00771         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" memory allocation failed!\n"</span>) ;
+<a name="l00772"></a>00772         <span class="keywordflow">return</span> NULL ;
+<a name="l00773"></a>00773     }
+<a name="l00774"></a>00774     <span class="comment">/* collapse the cube to be able to compute the weights </span>
+<a name="l00775"></a>00775 <span class="comment">       for optimal extraction */</span>
+<a name="l00776"></a>00776     <span class="keywordflow">if</span> ( NULL == (averagedIm = sinfo_new_average_cube_to_image(cube)) )
+<a name="l00777"></a>00777     {
+<a name="l00778"></a>00778         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" sinfo_averageCubeToImage failed!"</span>) ;
+<a name="l00779"></a>00779         cpl_image_delete(retIm) ;
+<a name="l00780"></a>00780         <span class="keywordflow">return</span> NULL ;
+<a name="l00781"></a>00781     }
+<a name="l00782"></a>00782 
+<a name="l00783"></a>00783     <span class="comment">/* call the 2D-Gaussian fit routine */</span>
+<a name="l00784"></a>00784     <span class="keywordflow">for</span> ( i = 0 ; i < 7 ; i++ )
+<a name="l00785"></a>00785     {
+<a name="l00786"></a>00786         mpar[i] = 1 ;
+<a name="l00787"></a>00787     }
+<a name="l00788"></a>00788 
+<a name="l00789"></a>00789     <span class="keywordflow">if</span> ( -1 == (fitInd = sinfo_new_fit_2d_gaussian(averagedIm,
+<a name="l00790"></a>00790                                                    fit_par,
+<a name="l00791"></a>00791                                                    derv_par,
+<a name="l00792"></a>00792                                                    mpar,
+<a name="l00793"></a>00793                                                    llx,
+<a name="l00794"></a>00794                                                    lly,
+<a name="l00795"></a>00795                                                    halfbox_x,
+<a name="l00796"></a>00796                                                    halfbox_y,
+<a name="l00797"></a>00797                                                    check2 )) )
+<a name="l00798"></a>00798     {
+<a name="l00799"></a>00799         <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"sinfo_fit2dGaussian failed!"</span>) ;
+<a name="l00800"></a>00800         cpl_image_delete(retIm) ;
+<a name="l00801"></a>00801         cpl_image_delete(averagedIm) ;
+<a name="l00802"></a>00802         <span class="keywordflow">return</span> NULL ;
+<a name="l00803"></a>00803     }
+<a name="l00804"></a>00804 
+<a name="l00805"></a>00805     <span class="comment">/* determine the PSF by using the found 2D-Gaussian */</span>
+<a name="l00806"></a>00806     sinfo_psf=sinfo_new_2Ddoublearray(ilx,ily) ;
+<a name="l00807"></a>00807     sum = 0 ;
+<a name="l00808"></a>00808     <span class="keywordflow">for</span> ( row = 0 ; row < ily ; row++ )
+<a name="l00809"></a>00809     {
+<a name="l00810"></a>00810         <span class="keywordflow">for</span> ( col = 0 ; col < ilx ; col++ )
+<a name="l00811"></a>00811         {
+<a name="l00812"></a>00812             xdat[0] = (double) col ;
+<a name="l00813"></a>00813             xdat[1] = (double) row ;
+<a name="l00814"></a>00814             sinfo_psf[col][row] = sinfo_new_gaussian_ellipse(xdat,fit_par) - 
+<a name="l00815"></a>00815                                   fit_par[3] ;
+<a name="l00816"></a>00816             sum += sinfo_psf[col][row] ;
+<a name="l00817"></a>00817         }
+<a name="l00818"></a>00818     }
+<a name="l00819"></a>00819     <span class="comment">/* Scale the PSF and determine the pixel variances and the </span>
+<a name="l00820"></a>00820 <span class="comment">       normalization factor */</span>
+<a name="l00821"></a>00821     norm = 0. ;
+<a name="l00822"></a>00822     variance = 0. ;
+<a name="l00823"></a>00823     sum_psf=0;
+<a name="l00824"></a>00824 
+<a name="l00825"></a>00825     weight=sinfo_new_2Ddoublearray(ilx,ily) ;
+<a name="l00826"></a>00826 
+<a name="l00827"></a>00827     padata=cpl_image_get_data_float(averagedIm);
+<a name="l00828"></a>00828     <span class="keywordflow">for</span> ( row = 0 ; row < ily ; row++ )
+<a name="l00829"></a>00829     {
+<a name="l00830"></a>00830         <span class="keywordflow">for</span> ( col = 0 ; col < ilx ; col++ )
+<a name="l00831"></a>00831         {
+<a name="l00832"></a>00832             sinfo_psf[col][row] /= sum ;
+<a name="l00833"></a>00833         sum_psf +=  sinfo_psf[col][row];
+<a name="l00834"></a>00834             <span class="keywordflow">if</span> ( !isnan(padata[col+row*ilx]) )
+<a name="l00835"></a>00835             {
+<a name="l00836"></a>00836           <span class="comment">/*</span>
+<a name="l00837"></a>00837 <span class="comment">                variance = (backvariance + sky + padata[col+row*ilx] / </span>
+<a name="l00838"></a>00838 <span class="comment">                            exptime) / gain ;</span>
+<a name="l00839"></a>00839 <span class="comment">          */</span>
+<a name="l00840"></a>00840                 variance = padata[col+row*ilx] / gain ;
+<a name="l00841"></a>00841 
+<a name="l00842"></a>00842             }
+<a name="l00843"></a>00843             <span class="keywordflow">else</span> 
+<a name="l00844"></a>00844             {
+<a name="l00845"></a>00845                 weight[col][row] = 0. ;
+<a name="l00846"></a>00846             }
+<a name="l00847"></a>00847             <span class="keywordflow">if</span> (variance == 0.)
+<a name="l00848"></a>00848             {
+<a name="l00849"></a>00849                 weight[col][row] = 0. ;
+<a name="l00850"></a>00850             }
+<a name="l00851"></a>00851             <span class="keywordflow">else</span>
+<a name="l00852"></a>00852             {
+<a name="l00853"></a>00853          
+<a name="l00854"></a>00854                 weight[col][row] = sinfo_psf[col][row]/variance ;
+<a name="l00855"></a>00855            
+<a name="l00856"></a>00856                 norm += weight[col][row] * weight[col][row] * variance ;
+<a name="l00857"></a>00857 
+<a name="l00858"></a>00858             }
+<a name="l00859"></a>00859         
+<a name="l00860"></a>00860         }
+<a name="l00861"></a>00861     }
+<a name="l00862"></a>00862 
+<a name="l00863"></a>00863     sum_wgt=0;
+<a name="l00864"></a>00864     <span class="keywordflow">for</span> ( row = 0 ; row < ily ; row++ )
+<a name="l00865"></a>00865     {
+<a name="l00866"></a>00866         <span class="keywordflow">for</span> ( col = 0 ; col < ilx ; col++ )
+<a name="l00867"></a>00867         {
+<a name="l00868"></a>00868       weight[col][row] /= norm;
+<a name="l00869"></a>00869           sum_wgt += weight[col][row]*sinfo_psf[col][row];
+<a name="l00870"></a>00870     }
+<a name="l00871"></a>00871     }
+<a name="l00872"></a>00872     <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"sum_psf=%f sum_wgt=%f norm=%f"</span>,sum_psf,sum_wgt,norm);
+<a name="l00873"></a>00873     cpl_image_delete(averagedIm) ;
+<a name="l00874"></a>00874     <span class="keywordflow">if</span> ( norm == 0. )
+<a name="l00875"></a>00875     {
+<a name="l00876"></a>00876         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" normalization sum is zero\n"</span>) ;
+<a name="l00877"></a>00877         cpl_image_delete(retIm) ;
+<a name="l00878"></a>00878         <span class="keywordflow">return</span> NULL ;
+<a name="l00879"></a>00879     }
+<a name="l00880"></a>00880 
+<a name="l00881"></a>00881     <span class="comment">/* limit the extraction region to the Gaussian, center +- fwhmx/y * </span>
+<a name="l00882"></a>00882 <span class="comment">                 cos(theta)  */</span>
+<a name="l00883"></a>00883     <span class="comment">/*</span>
+<a name="l00884"></a>00884 <span class="comment">    sinfo_msg("fit_par: %f %f %f %f %f %f %f", </span>
+<a name="l00885"></a>00885 <span class="comment">              fit_par[0],fit_par[1],fit_par[2],fit_par[3],</span>
+<a name="l00886"></a>00886 <span class="comment">              fit_par[4],fit_par[5],fit_par[6]);</span>
+<a name="l00887"></a>00887 <span class="comment">    sinfo_msg("fwhm_factor=%f",fwhm_factor);</span>
+<a name="l00888"></a>00888 <span class="comment">    */</span>
+<a name="l00889"></a>00889 
+<a name="l00890"></a>00890     <span class="keywordflow">if</span>(fabs(fit_par[6]) > PI_NUMB/4) {
+<a name="l00891"></a>00891       fit_par[6]=0;
+<a name="l00892"></a>00892     }
+<a name="l00893"></a>00893     first_col = (int) (fit_par[0] - 
+<a name="l00894"></a>00894                        fwhm_factor*fit_par[4]*cos((<span class="keywordtype">double</span>)fit_par[6])) ;
+<a name="l00895"></a>00895     first_col = (first_col > 2 ) ? first_col : 2;
+<a name="l00896"></a>00896 
+<a name="l00897"></a>00897     last_col =  (int) (fit_par[0] + 
+<a name="l00898"></a>00898                        fwhm_factor*fit_par[4]*cos((<span class="keywordtype">double</span>)fit_par[6])) ;
+<a name="l00899"></a>00899     last_col = (last_col < 63 ) ? last_col : 63;
+<a name="l00900"></a>00900 
+<a name="l00901"></a>00901     first_row = (int) (fit_par[1] - 
+<a name="l00902"></a>00902                        fwhm_factor*fit_par[5]*cos((<span class="keywordtype">double</span>)fit_par[6])) ;
+<a name="l00903"></a>00903     first_row = (first_row > 2 ) ? first_row : 2;
+<a name="l00904"></a>00904     last_row =  (int) (fit_par[1] + 
+<a name="l00905"></a>00905                        fwhm_factor*fit_par[5]*cos((<span class="keywordtype">double</span>)fit_par[6])) ;
+<a name="l00906"></a>00906     last_row = (last_row < 63 ) ? last_row : 63;
+<a name="l00907"></a>00907 
+<a name="l00908"></a>00908     
+<a name="l00909"></a>00909     <span class="keywordflow">if</span>(first_col > last_col) {
+<a name="l00910"></a>00910       tmp_val=last_col;
+<a name="l00911"></a>00911       last_col=first_col;
+<a name="l00912"></a>00912       first_col=tmp_val;
+<a name="l00913"></a>00913     }
+<a name="l00914"></a>00914 
+<a name="l00915"></a>00915     <span class="keywordflow">if</span>(first_row > last_row) {
+<a name="l00916"></a>00916       tmp_val=last_row;
+<a name="l00917"></a>00917       last_col=first_row;
+<a name="l00918"></a>00918       first_col=tmp_val;
+<a name="l00919"></a>00919     }
+<a name="l00920"></a>00920     <span class="keywordflow">if</span>(abs(first_col- last_col) < 1) {
+<a name="l00921"></a>00921       first_col -=1;
+<a name="l00922"></a>00922       last_col +=1;
+<a name="l00923"></a>00923     }
+<a name="l00924"></a>00924     <span class="keywordflow">if</span>(abs(first_row- last_row) < 1) {
+<a name="l00925"></a>00925       first_row -=1;
+<a name="l00926"></a>00926       last_row +=1;
+<a name="l00927"></a>00927     }
+<a name="l00928"></a>00928 
+<a name="l00929"></a>00929     <span class="keywordflow">if</span> ( first_col < 0 || first_row < 0 || last_col >= ilx || last_row >= ily )
+<a name="l00930"></a>00930     {
+<a name="l00931"></a>00931         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" star badly centered in FOV!"</span>) ;
+<a name="l00932"></a>00932         cpl_image_delete(retIm) ;
+<a name="l00933"></a>00933         <span class="keywordflow">return</span> NULL ;
+<a name="l00934"></a>00934     }
+<a name="l00935"></a>00935 
+<a name="l00936"></a>00936 
+<a name="l00937"></a>00937     cpl_table_new_column(*spectrum,<span class="stringliteral">"wavelength"</span>, CPL_TYPE_FLOAT);
+<a name="l00938"></a>00938     <span class="comment">/* cpl_table_new_column(*spectrum,"intensity" , CPL_TYPE_FLOAT); */</span>
+<a name="l00939"></a>00939     cpl_table_new_column(*spectrum,<span class="stringliteral">"counts_tot"</span> , CPL_TYPE_FLOAT);
+<a name="l00940"></a>00940     cpl_table_new_column(*spectrum,<span class="stringliteral">"counts_bkg"</span> , CPL_TYPE_FLOAT);
+<a name="l00941"></a>00941     cpl_table_new_column(*spectrum,<span class="stringliteral">"bkg_tot"</span> , CPL_TYPE_FLOAT);
+<a name="l00942"></a>00942 
+<a name="l00943"></a>00943     <span class="keywordflow">if</span>(qc_info==1) {
+<a name="l00944"></a>00944        cpl_table_new_column(*spectrum,<span class="stringliteral">"AMP"</span> , CPL_TYPE_FLOAT);
+<a name="l00945"></a>00945        cpl_table_new_column(*spectrum,<span class="stringliteral">"XC"</span> , CPL_TYPE_FLOAT);
+<a name="l00946"></a>00946        cpl_table_new_column(*spectrum,<span class="stringliteral">"YC"</span> , CPL_TYPE_FLOAT);
+<a name="l00947"></a>00947        cpl_table_new_column(*spectrum,<span class="stringliteral">"BKG"</span> , CPL_TYPE_FLOAT);
+<a name="l00948"></a>00948        cpl_table_new_column(*spectrum,<span class="stringliteral">"FWHMX"</span> , CPL_TYPE_FLOAT);
+<a name="l00949"></a>00949        cpl_table_new_column(*spectrum,<span class="stringliteral">"FWHMY"</span> , CPL_TYPE_FLOAT);
+<a name="l00950"></a>00950        cpl_table_new_column(*spectrum,<span class="stringliteral">"ANGLE"</span> , CPL_TYPE_FLOAT);
+<a name="l00951"></a>00951     }
+<a name="l00952"></a>00952     plist=cpl_propertylist_load(name,0);
+<a name="l00953"></a>00953     cenpix = sinfo_pfits_get_crpix3(plist);
+<a name="l00954"></a>00954     cenLambda = sinfo_pfits_get_crval3(plist);
+<a name="l00955"></a>00955     dispersion = sinfo_pfits_get_cdelt3(plist);
+<a name="l00956"></a>00956     cpl_propertylist_delete(plist);
+<a name="l00957"></a>00957     lambda_start=cenLambda-cenpix*dispersion;
+<a name="l00958"></a>00958 
+<a name="l00959"></a>00959     <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"frow %d lrow %d fcol %d lcol %d"</span>,
+<a name="l00960"></a>00960                      first_row, last_row, first_col, last_col);
+<a name="l00961"></a>00961     <span class="comment">/* go through the planes */</span>
+<a name="l00962"></a>00962     podata=cpl_image_get_data_float(retIm);
+<a name="l00963"></a>00963     <span class="keywordflow">for</span> ( z = 0 ; z < inp ; z++ )
+<a name="l00964"></a>00964     {
+<a name="l00965"></a>00965       i_img=cpl_imagelist_get(cube,z);
+<a name="l00966"></a>00966       pidata=cpl_image_get_data_float(i_img);
+<a name="l00967"></a>00967         weighted_sum = 0. ;
+<a name="l00968"></a>00968         counts_tot=0.;
+<a name="l00969"></a>00969         counts_bkg=0.;
+<a name="l00970"></a>00970 
+<a name="l00971"></a>00971         bkg_tot=0.;
+<a name="l00972"></a>00972 
+<a name="l00973"></a>00973         <span class="keywordflow">if</span>(qc_info==1) {
+<a name="l00974"></a>00974            sinfo_new_fit_2d_gaussian(i_img,gfit_par,
+<a name="l00975"></a>00975                                      gderv_par,gmpar,llx,lly,
+<a name="l00976"></a>00976                                      halfbox_x,halfbox_y,check2);
+<a name="l00977"></a>00977     }
+<a name="l00978"></a>00978 
+<a name="l00979"></a>00979         <span class="keywordflow">for</span> ( row = first_row ; row <= last_row ; row++ )
+<a name="l00980"></a>00980         {
+<a name="l00981"></a>00981             <span class="keywordflow">for</span> ( col = first_col ; col < last_col ; col++ )
+<a name="l00982"></a>00982             {
+<a name="l00983"></a>00983                 <span class="keywordflow">if</span> ( !isnan(pidata[col+row*ilx]) )
+<a name="l00984"></a>00984                 {
+<a name="l00985"></a>00985           
+<a name="l00986"></a>00986                     weighted_sum += weight[col][row] * (pidata[col+row*ilx] - 
+<a name="l00987"></a>00987                                     fit_par[3]);
+<a name="l00988"></a>00988             
+<a name="l00989"></a>00989                     counts_bkg += (pidata[col+row*ilx] - fit_par[3]);
+<a name="l00990"></a>00990                     counts_tot += (pidata[col+row*ilx]);
+<a name="l00991"></a>00991                     bkg_tot += fit_par[3];
+<a name="l00992"></a>00992             
+<a name="l00993"></a>00993                 } 
+<a name="l00994"></a>00994             }
+<a name="l00995"></a>00995         }    
+<a name="l00996"></a>00996 
+<a name="l00997"></a>00997         <span class="keywordflow">if</span> (weighted_sum == 0.)
+<a name="l00998"></a>00998         {
+<a name="l00999"></a>00999             weighted_sum = ZERO ;
+<a name="l01000"></a>01000             counts_tot = ZERO;
+<a name="l01001"></a>01001             counts_bkg = ZERO;
+<a name="l01002"></a>01002             bkg_tot = ZERO;
+<a name="l01003"></a>01003 
+<a name="l01004"></a>01004         }
+<a name="l01005"></a>01005         <span class="keywordflow">else</span>
+<a name="l01006"></a>01006         {
+<a name="l01007"></a>01007       <span class="comment">/*</span>
+<a name="l01008"></a>01008 <span class="comment">            weighted_sum /= norm ;</span>
+<a name="l01009"></a>01009 <span class="comment">      */</span>
+<a name="l01010"></a>01010       
+<a name="l01011"></a>01011       
+<a name="l01012"></a>01012         }
+<a name="l01013"></a>01013 
+<a name="l01014"></a>01014         podata[z] = weighted_sum ;
+<a name="l01015"></a>01015         lambda=lambda_start+z*dispersion;
+<a name="l01016"></a>01016         cpl_table_set_float(*spectrum,<span class="stringliteral">"wavelength"</span> ,z,lambda);
+<a name="l01017"></a>01017         <span class="comment">/* cpl_table_set_float(*spectrum,"intensity" ,z,weighted_sum); */</span>
+<a name="l01018"></a>01018         cpl_table_set_float(*spectrum,<span class="stringliteral">"counts_tot"</span> ,z,counts_tot);
+<a name="l01019"></a>01019         cpl_table_set_float(*spectrum,<span class="stringliteral">"counts_bkg"</span> ,z,counts_bkg);
+<a name="l01020"></a>01020         cpl_table_set_float(*spectrum,<span class="stringliteral">"bkg_tot"</span> ,z,bkg_tot);
+<a name="l01021"></a>01021         <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"w=%f I=%f b=%f a=%f"</span>,
+<a name="l01022"></a>01022                          lambda,counts_tot,counts_bkg,bkg_tot);
+<a name="l01023"></a>01023         <span class="keywordflow">if</span>(qc_info==1) {
+<a name="l01024"></a>01024            cpl_table_set_float(*spectrum,<span class="stringliteral">"AMP"</span> ,z,gfit_par[0]);
+<a name="l01025"></a>01025            cpl_table_set_float(*spectrum,<span class="stringliteral">"XC"</span> ,z,gfit_par[1]);
+<a name="l01026"></a>01026            cpl_table_set_float(*spectrum,<span class="stringliteral">"YC"</span> ,z,gfit_par[2]);
+<a name="l01027"></a>01027            cpl_table_set_float(*spectrum,<span class="stringliteral">"BKG"</span> ,z,gfit_par[3]);
+<a name="l01028"></a>01028            cpl_table_set_float(*spectrum,<span class="stringliteral">"FWHMX"</span> ,z,gfit_par[4]);
+<a name="l01029"></a>01029            cpl_table_set_float(*spectrum,<span class="stringliteral">"FWHMY"</span> ,z,gfit_par[5]);
+<a name="l01030"></a>01030            cpl_table_set_float(*spectrum,<span class="stringliteral">"ANGLE"</span> ,z,gfit_par[6]);
+<a name="l01031"></a>01031     }
+<a name="l01032"></a>01032 
+<a name="l01033"></a>01033     }
+<a name="l01034"></a>01034 
+<a name="l01035"></a>01035     sinfo_new_destroy_2Ddoublearray(&sinfo_psf,ilx) ;
+<a name="l01036"></a>01036     sinfo_new_destroy_2Ddoublearray(&weight,ilx) ;
+<a name="l01037"></a>01037 
+<a name="l01038"></a>01038     <span class="keywordflow">return</span> retIm ;
+<a name="l01039"></a>01039 }
+<a name="l01040"></a>01040 
+<a name="l01064"></a>01064 Vector * sinfo_new_extract_sky_from_cube( cpl_imagelist * cube,
+<a name="l01065"></a>01065                              <span class="keywordtype">float</span>     loReject,
+<a name="l01066"></a>01066                              <span class="keywordtype">float</span>     hiReject,
+<a name="l01067"></a>01067                              <span class="keywordtype">int</span>     * position,
+<a name="l01068"></a>01068                              <span class="keywordtype">int</span>       tolerance,
+<a name="l01069"></a>01069                              <span class="keywordtype">int</span>       posindicator )
+<a name="l01070"></a>01070 {
+<a name="l01071"></a>01071     Vector * spectrum ;
+<a name="l01072"></a>01072     <span class="keywordtype">int</span> x, y, z ;
+<a name="l01073"></a>01073     <span class="keywordtype">int</span> n ;
+<a name="l01074"></a>01074     <span class="keywordtype">int</span> n_sky ;
+<a name="l01075"></a>01075     <span class="keywordtype">int</span> x_low , x_high ;
+<a name="l01076"></a>01076     <span class="keywordtype">int</span> y_low , y_high ;
+<a name="l01077"></a>01077     <span class="keywordtype">int</span> hi_x, lo_x ;
+<a name="l01078"></a>01078     <span class="keywordtype">float</span> * to_average ;
+<a name="l01079"></a>01079     <span class="keywordtype">float</span>   cleanMean ;
+<a name="l01080"></a>01080 
+<a name="l01081"></a>01081     <span class="keywordtype">int</span> ilx=0;
+<a name="l01082"></a>01082     <span class="keywordtype">int</span> ily=0;
+<a name="l01083"></a>01083     <span class="keywordtype">int</span> inp=0;
+<a name="l01084"></a>01084     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l01085"></a>01085     cpl_image* i_img=NULL;
+<a name="l01086"></a>01086 
+<a name="l01087"></a>01087 
+<a name="l01088"></a>01088     ilx=cpl_image_get_size_x(cpl_imagelist_get(cube,0));
+<a name="l01089"></a>01089     ily=cpl_image_get_size_y(cpl_imagelist_get(cube,0));
+<a name="l01090"></a>01090     inp=cpl_imagelist_get_size(cube);
+<a name="l01091"></a>01091 
+<a name="l01092"></a>01092     <span class="keywordflow">if</span> ( NULL == cube )
+<a name="l01093"></a>01093     {
+<a name="l01094"></a>01094         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" no cube given!\n"</span>) ;
+<a name="l01095"></a>01095         <span class="keywordflow">return</span> NullVector ;
+<a name="l01096"></a>01096     }
+<a name="l01097"></a>01097     <span class="keywordflow">if</span> ( loReject < 0. || hiReject < 0. || loReject + hiReject >= 90. )
+<a name="l01098"></a>01098     {
+<a name="l01099"></a>01099         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"wrong or unrealistic loReject and hiReject values!"</span>) ;
+<a name="l01100"></a>01100         <span class="keywordflow">return</span> NullVector ;
+<a name="l01101"></a>01101     }
+<a name="l01102"></a>01102     <span class="keywordflow">if</span> ( position == NULL)
+<a name="l01103"></a>01103     {
+<a name="l01104"></a>01104         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" no position array given!"</span>) ;
+<a name="l01105"></a>01105         <span class="keywordflow">return</span> NullVector ;
+<a name="l01106"></a>01106     }
+<a name="l01107"></a>01107     <span class="keywordflow">if</span> ( position[0] < 0 || position[1] < 0 || 
+<a name="l01108"></a>01108          position[0] > ilx  || position[1] > ily )
+<a name="l01109"></a>01109     {
+<a name="l01110"></a>01110         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" wrong position of sky spider!"</span>) ;
+<a name="l01111"></a>01111         <span class="keywordflow">return</span> NullVector ;
+<a name="l01112"></a>01112     }
+<a name="l01113"></a>01113     <span class="keywordflow">if</span> ( tolerance < 0 || tolerance >= ilx )
+<a name="l01114"></a>01114     {
+<a name="l01115"></a>01115         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" wrong tolerance given!"</span>) ;
+<a name="l01116"></a>01116         <span class="keywordflow">return</span> NullVector ;
+<a name="l01117"></a>01117     }
+<a name="l01118"></a>01118     <span class="keywordflow">if</span> ( posindicator == 0 )
+<a name="l01119"></a>01119     {
+<a name="l01120"></a>01120         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" no sinfo_edge indicator given!"</span>) ;
+<a name="l01121"></a>01121         <span class="keywordflow">return</span> NullVector ;
+<a name="l01122"></a>01122     }
+<a name="l01123"></a>01123 
+<a name="l01124"></a>01124     <span class="comment">/* determine the edge of the image where the sky spectra are placed */</span>
+<a name="l01125"></a>01125     <span class="keywordflow">switch</span>(posindicator)
+<a name="l01126"></a>01126     {
+<a name="l01127"></a>01127         <span class="comment">/* lower right sinfo_edge */</span>
+<a name="l01128"></a>01128         <span class="keywordflow">case</span> 1:
+<a name="l01129"></a>01129             x_low  = position[0] + tolerance ;
+<a name="l01130"></a>01130             x_high = ilx ;
+<a name="l01131"></a>01131             y_low  = 0 ;
+<a name="l01132"></a>01132             y_high = position[1] - tolerance ;
+<a name="l01133"></a>01133             break ;
+<a name="l01134"></a>01134         <span class="comment">/* upper right sinfo_edge */</span>
+<a name="l01135"></a>01135         <span class="keywordflow">case</span> 2:
+<a name="l01136"></a>01136             x_low  = position[0] + tolerance ;
+<a name="l01137"></a>01137             x_high = ilx ;
+<a name="l01138"></a>01138             y_low  = position[1] + tolerance ;
+<a name="l01139"></a>01139             y_high = ily ;
+<a name="l01140"></a>01140             break ;
+<a name="l01141"></a>01141         <span class="comment">/* upper left sinfo_edge */</span>
+<a name="l01142"></a>01142         <span class="keywordflow">case</span> 3:
+<a name="l01143"></a>01143             x_low  = 0 ;
+<a name="l01144"></a>01144             x_high = position[0] - tolerance ;
+<a name="l01145"></a>01145             y_low  = position [1] + tolerance ;
+<a name="l01146"></a>01146             y_high = ily ;
+<a name="l01147"></a>01147             break ;
+<a name="l01148"></a>01148         <span class="keywordflow">default</span>:
+<a name="l01149"></a>01149             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" wrong position indicator index!"</span>) ;
+<a name="l01150"></a>01150             <span class="keywordflow">return</span> NullVector ;
+<a name="l01151"></a>01151             break ;
+<a name="l01152"></a>01152     }
+<a name="l01153"></a>01153     <span class="keywordflow">if</span> ( x_low >= ilx || x_high < 1 || y_low >= ily || y_high < 1 )
+<a name="l01154"></a>01154     {
+<a name="l01155"></a>01155         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" tolerance too high!"</span>) ;
+<a name="l01156"></a>01156         <span class="keywordflow">return</span> NullVector ;
+<a name="l01157"></a>01157     }
+<a name="l01158"></a>01158     <span class="keywordflow">if</span> ( x_high - x_low != y_high - y_low )
+<a name="l01159"></a>01159     {
+<a name="l01160"></a>01160         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" sky sinfo_edge is not a diagonal line!\n"</span>) ;
+<a name="l01161"></a>01161         <span class="keywordflow">return</span> NullVector ;
+<a name="l01162"></a>01162     }
+<a name="l01163"></a>01163 
+<a name="l01164"></a>01164     <span class="comment">/* determine the number of sky pixels in one image plane, take only </span>
+<a name="l01165"></a>01165 <span class="comment">       the full sky pixels which are not cut by the diagonal line */</span>
+<a name="l01166"></a>01166     n_sky = (x_high - x_low) * (x_high - x_low - 1) / 2 ;
+<a name="l01167"></a>01167     <span class="keywordflow">if</span> ( n_sky <= 0 )
+<a name="l01168"></a>01168     {
+<a name="l01169"></a>01169         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" no sky spectrum in found in cube!"</span>) ;
+<a name="l01170"></a>01170         <span class="keywordflow">return</span> NullVector ;
+<a name="l01171"></a>01171     }
+<a name="l01172"></a>01172     <span class="keywordflow">if</span> ( n_sky == 1 )
+<a name="l01173"></a>01173     {
+<a name="l01174"></a>01174         <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">" only one sky spectrum is taken, no averaging!"</span>) ;
+<a name="l01175"></a>01175     }
+<a name="l01176"></a>01176 
+<a name="l01177"></a>01177     <span class="comment">/* allocate memory for the output spectrum */</span>
+<a name="l01178"></a>01178     <span class="keywordflow">if</span> ( NullVector == (spectrum = sinfo_new_vector(inp)) )
+<a name="l01179"></a>01179     {
+<a name="l01180"></a>01180         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" could not allocate memory!"</span>) ;
+<a name="l01181"></a>01181         <span class="keywordflow">return</span> NullVector ;
+<a name="l01182"></a>01182     }
+<a name="l01183"></a>01183 
+<a name="l01184"></a>01184     <span class="comment">/* go through the image planes */</span>
+<a name="l01185"></a>01185     <span class="keywordflow">for</span> ( z = 0 ; z < inp ; z++ )
+<a name="l01186"></a>01186     {
+<a name="l01187"></a>01187       i_img=cpl_imagelist_get(cube,z);
+<a name="l01188"></a>01188       pidata=cpl_image_get_data_float(i_img);
+<a name="l01189"></a>01189         <span class="comment">/* allocate memory for the sky pixels in one image plane */</span>
+<a name="l01190"></a>01190         <span class="keywordflow">if</span> (NULL == (to_average = (<span class="keywordtype">float</span>*) cpl_calloc(n_sky, <span class="keyword">sizeof</span> (<span class="keywordtype">float</span>))))
+<a name="l01191"></a>01191         {
+<a name="l01192"></a>01192             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" could not allocate memory!"</span>) ;
+<a name="l01193"></a>01193             sinfo_new_destroy_vector(spectrum) ;
+<a name="l01194"></a>01194             <span class="keywordflow">return</span> NullVector ;
+<a name="l01195"></a>01195         }
+<a name="l01196"></a>01196         n = 0 ;
+<a name="l01197"></a>01197         <span class="keywordflow">switch</span>(posindicator)
+<a name="l01198"></a>01198         {
+<a name="l01199"></a>01199             <span class="comment">/* lower right sinfo_edge */</span>
+<a name="l01200"></a>01200             <span class="keywordflow">case</span> 1:
+<a name="l01201"></a>01201                 lo_x = x_low ;
+<a name="l01202"></a>01202                 <span class="keywordflow">for</span> ( y = y_low ; y < y_high - 1 ; y++ )
+<a name="l01203"></a>01203                 {
+<a name="l01204"></a>01204                     lo_x++ ;
+<a name="l01205"></a>01205                     <span class="keywordflow">for</span> ( x = lo_x ; x < x_high ; x++ )
+<a name="l01206"></a>01206                     {
+<a name="l01207"></a>01207                         to_average[n] = pidata[x+y*ilx] ;
+<a name="l01208"></a>01208                         n++ ;
+<a name="l01209"></a>01209                     }
+<a name="l01210"></a>01210                 }
+<a name="l01211"></a>01211                 break ;
+<a name="l01212"></a>01212             <span class="comment">/* lower left sinfo_edge */</span>
+<a name="l01213"></a>01213             <span class="keywordflow">case</span> 2:
+<a name="l01214"></a>01214                 hi_x = x_high ;
+<a name="l01215"></a>01215                 <span class="keywordflow">for</span> ( y = y_low ; y < y_high - 1 ; y++ )
+<a name="l01216"></a>01216                 {
+<a name="l01217"></a>01217                     hi_x-- ;
+<a name="l01218"></a>01218                     <span class="keywordflow">for</span> ( x = x_low ; x < hi_x ; x++ )
+<a name="l01219"></a>01219                     {
+<a name="l01220"></a>01220                         to_average[n] = pidata[x+y*ilx] ;
+<a name="l01221"></a>01221                         n++ ;
+<a name="l01222"></a>01222                     }
+<a name="l01223"></a>01223                 }
+<a name="l01224"></a>01224                 break ;
+<a name="l01225"></a>01225             <span class="comment">/* upper right sinfo_edge */</span>
+<a name="l01226"></a>01226             <span class="keywordflow">case</span> 3:
+<a name="l01227"></a>01227                 lo_x = x_high ;
+<a name="l01228"></a>01228                 <span class="keywordflow">for</span> ( y = y_low+1 ; y < y_high ; y++ )
+<a name="l01229"></a>01229                 {
+<a name="l01230"></a>01230                     lo_x-- ;
+<a name="l01231"></a>01231                     <span class="keywordflow">for</span> ( x = lo_x ; x < x_high ; x++ )
+<a name="l01232"></a>01232                     {
+<a name="l01233"></a>01233                         to_average[n] = pidata[x+y*ilx] ;
+<a name="l01234"></a>01234                         n++ ;
+<a name="l01235"></a>01235                     }
+<a name="l01236"></a>01236                 }
+<a name="l01237"></a>01237                 break ;
+<a name="l01238"></a>01238             <span class="comment">/* upper left sinfo_edge */</span>
+<a name="l01239"></a>01239             <span class="keywordflow">case</span> 4:
+<a name="l01240"></a>01240                 hi_x = x_low ;
+<a name="l01241"></a>01241                 <span class="keywordflow">for</span> ( y = y_low+1 ; y < y_high ; y++ )
+<a name="l01242"></a>01242                 {
+<a name="l01243"></a>01243                     hi_x++ ;
+<a name="l01244"></a>01244                     <span class="keywordflow">for</span> ( x = x_low ; x < hi_x ; x++ )
+<a name="l01245"></a>01245                     {
+<a name="l01246"></a>01246                         to_average[n] = pidata[x+y*ilx] ;
+<a name="l01247"></a>01247                         n++ ;
+<a name="l01248"></a>01248                     }
+<a name="l01249"></a>01249                 }
+<a name="l01250"></a>01250                 break ;
+<a name="l01251"></a>01251             <span class="keywordflow">default</span>:
+<a name="l01252"></a>01252                 <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" wrong position indicator index!\n"</span>) ;
+<a name="l01253"></a>01253                 <span class="keywordflow">return</span> NullVector ;
+<a name="l01254"></a>01254                 break ;
+<a name="l01255"></a>01255         }
+<a name="l01256"></a>01256         <span class="keywordflow">if</span> ( n != n_sky )
+<a name="l01257"></a>01257         {
+<a name="l01258"></a>01258             <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"number of stored sky image pixels does "</span>
+<a name="l01259"></a>01259                               <span class="stringliteral">"not equal number of computed sky pixels!"</span>) ;
+<a name="l01260"></a>01260         }
+<a name="l01261"></a>01261 
+<a name="l01262"></a>01262         <span class="comment">/* now take a clean mean of the sky "image" */</span>
+<a name="l01263"></a>01263         cleanMean = sinfo_new_clean_mean (to_average, n, loReject, hiReject) ;
+<a name="l01264"></a>01264         <span class="keywordflow">if</span> (cleanMean == FLT_MAX)
+<a name="l01265"></a>01265         {
+<a name="l01266"></a>01266             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" could not take a clean mean!\n"</span>) ;
+<a name="l01267"></a>01267             sinfo_new_destroy_vector(spectrum) ;
+<a name="l01268"></a>01268             cpl_free(to_average) ;
+<a name="l01269"></a>01269             <span class="keywordflow">return</span> NullVector ;
+<a name="l01270"></a>01270         }
+<a name="l01271"></a>01271         spectrum->data[z] = cleanMean ;
+<a name="l01272"></a>01272         cpl_free (to_average) ;
+<a name="l01273"></a>01273     }
+<a name="l01274"></a>01274      
+<a name="l01275"></a>01275     <span class="keywordflow">return</span> spectrum ;
+<a name="l01276"></a>01276 }
+<a name="l01277"></a>01277 
+<a name="l01291"></a>01291 Vector * sinfo_new_sum_rectangle_of_cube_spectra( cpl_imagelist * cube,
+<a name="l01292"></a>01292                                      <span class="keywordtype">int</span> llx,
+<a name="l01293"></a>01293                                      <span class="keywordtype">int</span> lly,
+<a name="l01294"></a>01294                                      <span class="keywordtype">int</span> urx,
+<a name="l01295"></a>01295                                      <span class="keywordtype">int</span> ury )
+<a name="l01296"></a>01296 {
+<a name="l01297"></a>01297     Vector          * sum ;
+<a name="l01298"></a>01298     pixelvalue      *local_rectangle ;
+<a name="l01299"></a>01299     <span class="keywordtype">int</span>             i, j, k, l, m ;
+<a name="l01300"></a>01300     <span class="keywordtype">int</span>             recsize ;
+<a name="l01301"></a>01301     <span class="keywordtype">int</span> ilx=0;
+<a name="l01302"></a>01302     <span class="keywordtype">int</span> ily=0;
+<a name="l01303"></a>01303     <span class="keywordtype">int</span> inp=0;
+<a name="l01304"></a>01304     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l01305"></a>01305     cpl_image* i_img=NULL;
+<a name="l01306"></a>01306 
+<a name="l01307"></a>01307 
+<a name="l01308"></a>01308     ilx=cpl_image_get_size_x(cpl_imagelist_get(cube,0));
+<a name="l01309"></a>01309     ily=cpl_image_get_size_y(cpl_imagelist_get(cube,0));
+<a name="l01310"></a>01310     inp=cpl_imagelist_get_size(cube);
+<a name="l01311"></a>01311 
+<a name="l01312"></a>01312     <span class="keywordflow">if</span> ( cube == NULL || inp < 1 )
+<a name="l01313"></a>01313     {
+<a name="l01314"></a>01314         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" no cube to take the mean of his spectra\n"</span>) ;
+<a name="l01315"></a>01315         <span class="keywordflow">return</span> NullVector ;
+<a name="l01316"></a>01316     }
+<a name="l01317"></a>01317 
+<a name="l01318"></a>01318     <span class="keywordflow">if</span> ((llx<0) || (llx>=ilx) ||
+<a name="l01319"></a>01319         (urx<0) || (urx>=ilx) ||
+<a name="l01320"></a>01320         (lly<0) || (lly>=ily) ||
+<a name="l01321"></a>01321         (ury<0) || (ury>=ily) ||
+<a name="l01322"></a>01322         (llx>=urx) || (lly>=ury))
+<a name="l01323"></a>01323     {
+<a name="l01324"></a>01324         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" invalid rectangle coordinates:"</span>) ;
+<a name="l01325"></a>01325         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"lower left is [%d %d] upper right is [%d %d]"</span>, 
+<a name="l01326"></a>01326                          llx, lly, urx, ury) ;
+<a name="l01327"></a>01327         <span class="keywordflow">return</span> NullVector ;
+<a name="l01328"></a>01328     }
+<a name="l01329"></a>01329 
+<a name="l01330"></a>01330     recsize = (urx - llx + 1) * (ury - lly + 1) ;
+<a name="l01331"></a>01331 
+<a name="l01332"></a>01332     <span class="comment">/* allocate a new sinfo_vector to store the average spectral values */</span>
+<a name="l01333"></a>01333     <span class="keywordflow">if</span> (NULL == (sum = sinfo_new_vector (inp)) )
+<a name="l01334"></a>01334     {
+<a name="l01335"></a>01335         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" cannot allocate a new sinfo_vector"</span>) ;
+<a name="l01336"></a>01336         <span class="keywordflow">return</span> NullVector ;
+<a name="l01337"></a>01337     }
+<a name="l01338"></a>01338 
+<a name="l01339"></a>01339     <span class="comment">/*------------------------------------------------------------------------</span>
+<a name="l01340"></a>01340 <span class="comment">     *  loop through the cube planes, through the x axis and the y-axis of the</span>
+<a name="l01341"></a>01341 <span class="comment">     *  plane rectangle and store pixel values in a buffer.</span>
+<a name="l01342"></a>01342 <span class="comment">     */</span>
+<a name="l01343"></a>01343     <span class="keywordflow">for</span> ( i = 0 ; i < inp ; i++ )
+<a name="l01344"></a>01344     {
+<a name="l01345"></a>01345       i_img=cpl_imagelist_get(cube,i);
+<a name="l01346"></a>01346       pidata=cpl_image_get_data_float(i_img);
+<a name="l01347"></a>01347         m = 0 ;
+<a name="l01348"></a>01348         local_rectangle = (pixelvalue *) cpl_calloc (recsize, 
+<a name="l01349"></a>01349                                          <span class="keyword">sizeof</span> (pixelvalue*));
+<a name="l01350"></a>01350 
+<a name="l01351"></a>01351         <span class="keywordflow">for</span> ( j = lly ; j <= ury ; j++ )
+<a name="l01352"></a>01352         {
+<a name="l01353"></a>01353             <span class="keywordflow">for</span> ( k = llx ; k <= urx ; k++ )
+<a name="l01354"></a>01354             {
+<a name="l01355"></a>01355                 local_rectangle[m] = pidata[k + j * ilx] ;
+<a name="l01356"></a>01356                 m ++ ;
+<a name="l01357"></a>01357             }
+<a name="l01358"></a>01358         }
+<a name="l01359"></a>01359         <span class="keywordflow">for</span> ( l = 0 ; l < recsize ; l++ )
+<a name="l01360"></a>01360         {
+<a name="l01361"></a>01361             <span class="keywordflow">if</span> ( isnan(local_rectangle[l]) )
+<a name="l01362"></a>01362             {
+<a name="l01363"></a>01363                 continue ;
+<a name="l01364"></a>01364             }
+<a name="l01365"></a>01365             sum -> data[i] += local_rectangle[l] ;
+<a name="l01366"></a>01366         }
+<a name="l01367"></a>01367         cpl_free ( local_rectangle ) ;
+<a name="l01368"></a>01368     }
+<a name="l01369"></a>01369     <span class="keywordflow">return</span> sum ;
+<a name="l01370"></a>01370 }
+<a name="l01371"></a>01371 
+<a name="l01383"></a>01383 Vector * sinfo_new_sum_circle_of_cube_spectra( cpl_imagelist * cube,
+<a name="l01384"></a>01384                                   <span class="keywordtype">int</span>       centerx,
+<a name="l01385"></a>01385                                   <span class="keywordtype">int</span>       centery,
+<a name="l01386"></a>01386                                   <span class="keywordtype">int</span>       radius )
+<a name="l01387"></a>01387 {
+<a name="l01388"></a>01388     Vector          * sum ;
+<a name="l01389"></a>01389     pixelvalue      * circle ;
+<a name="l01390"></a>01390     <span class="keywordtype">int</span>             i, j, k, l, m, n ;
+<a name="l01391"></a>01391     <span class="keywordtype">int</span>             circsize ;
+<a name="l01392"></a>01392     <span class="keywordtype">int</span> ilx=0;
+<a name="l01393"></a>01393     <span class="keywordtype">int</span> ily=0;
+<a name="l01394"></a>01394     <span class="keywordtype">int</span> inp=0;
+<a name="l01395"></a>01395     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l01396"></a>01396     cpl_image* i_img=NULL;
+<a name="l01397"></a>01397 
+<a name="l01398"></a>01398 
+<a name="l01399"></a>01399     ilx=cpl_image_get_size_x(cpl_imagelist_get(cube,0));
+<a name="l01400"></a>01400     ily=cpl_image_get_size_y(cpl_imagelist_get(cube,0));
+<a name="l01401"></a>01401     inp=cpl_imagelist_get_size(cube);
+<a name="l01402"></a>01402 
+<a name="l01403"></a>01403     <span class="keywordflow">if</span> ( cube == NULL || inp < 1 )
+<a name="l01404"></a>01404     {
+<a name="l01405"></a>01405         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" no cube to take the mean of his spectra\n"</span>) ;
+<a name="l01406"></a>01406         <span class="keywordflow">return</span> NullVector ;
+<a name="l01407"></a>01407     }
+<a name="l01408"></a>01408 
+<a name="l01409"></a>01409     <span class="keywordflow">if</span> ((centerx+radius>=ilx) ||
+<a name="l01410"></a>01410         (centery+radius>=ily) ||
+<a name="l01411"></a>01411         (centerx-radius<0) ||
+<a name="l01412"></a>01412         (centery-radius<0))
+<a name="l01413"></a>01413     {
+<a name="l01414"></a>01414         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" invalid circular coordinates"</span>) ;
+<a name="l01415"></a>01415         <span class="keywordflow">return</span> NullVector ;
+<a name="l01416"></a>01416     }
+<a name="l01417"></a>01417 
+<a name="l01418"></a>01418     n = 0 ;
+<a name="l01419"></a>01419     <span class="keywordflow">for</span> ( j = centery - radius ; j <= centery + radius ; j++ )
+<a name="l01420"></a>01420     {
+<a name="l01421"></a>01421         <span class="keywordflow">for</span> ( k = centerx - radius ; k <= centerx + radius ; k++ )
+<a name="l01422"></a>01422         {
+<a name="l01423"></a>01423             <span class="keywordflow">if</span> ( (k-centerx)*(k-centerx)+(j-centery)*(j-centery) <= 
+<a name="l01424"></a>01424                            radius*radius )
+<a name="l01425"></a>01425             {
+<a name="l01426"></a>01426                 n ++ ;
+<a name="l01427"></a>01427             }
+<a name="l01428"></a>01428         }
+<a name="l01429"></a>01429     }
+<a name="l01430"></a>01430     <span class="keywordflow">if</span> (n == 0)
+<a name="l01431"></a>01431     {
+<a name="l01432"></a>01432         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" no data points found!"</span>) ;
+<a name="l01433"></a>01433         <span class="keywordflow">return</span> NullVector ;
+<a name="l01434"></a>01434     }
+<a name="l01435"></a>01435     circsize = n ;
+<a name="l01436"></a>01436 
+<a name="l01437"></a>01437     <span class="comment">/* allocate a new sinfo_vector to store the average spectral values */</span>
+<a name="l01438"></a>01438     <span class="keywordflow">if</span> (NULL == (sum = sinfo_new_vector (inp)) )
+<a name="l01439"></a>01439     {
+<a name="l01440"></a>01440         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"  cannot allocate a new sinfo_vector"</span>) ;
+<a name="l01441"></a>01441         <span class="keywordflow">return</span> NullVector ;
+<a name="l01442"></a>01442     }
+<a name="l01443"></a>01443 
+<a name="l01444"></a>01444     <span class="comment">/*------------------------------------------------------------------------</span>
+<a name="l01445"></a>01445 <span class="comment">     *  loop through the cube planes, through the x axis and the y-axis of the</span>
+<a name="l01446"></a>01446 <span class="comment">     *  plane circle and store pixel values in a buffer.</span>
+<a name="l01447"></a>01447 <span class="comment">     */</span>
+<a name="l01448"></a>01448     <span class="keywordflow">for</span> ( i = 0 ; i < inp ; i++ )
+<a name="l01449"></a>01449     {
+<a name="l01450"></a>01450       i_img=cpl_imagelist_get(cube,i);
+<a name="l01451"></a>01451       pidata=cpl_image_get_data_float(i_img);
+<a name="l01452"></a>01452         m = 0 ;
+<a name="l01453"></a>01453         circle = (pixelvalue *) cpl_calloc (circsize, <span class="keyword">sizeof</span> (pixelvalue*));
+<a name="l01454"></a>01454 
+<a name="l01455"></a>01455         <span class="keywordflow">for</span> ( j = centery - radius ; j <= centery + radius ; j++ )
+<a name="l01456"></a>01456         {
+<a name="l01457"></a>01457             <span class="keywordflow">for</span> ( k = centerx - radius ; k <= centerx + radius ; k++ )
+<a name="l01458"></a>01458             {
+<a name="l01459"></a>01459                 <span class="keywordflow">if</span> ( (k-centerx)*(k-centerx)+(j-centery)*(j-centery) <= 
+<a name="l01460"></a>01460                      radius*radius )
+<a name="l01461"></a>01461                 {
+<a name="l01462"></a>01462                     circle[m] = pidata[k + j * ilx] ;
+<a name="l01463"></a>01463                     m ++ ;
+<a name="l01464"></a>01464                 }
+<a name="l01465"></a>01465             }
+<a name="l01466"></a>01466         }
+<a name="l01467"></a>01467 
+<a name="l01468"></a>01468         <span class="keywordflow">for</span> ( l = 0 ; l < circsize ; l++ )
+<a name="l01469"></a>01469         {
+<a name="l01470"></a>01470             <span class="keywordflow">if</span> ( isnan(circle[l]) )
+<a name="l01471"></a>01471             {
+<a name="l01472"></a>01472                 continue ;
+<a name="l01473"></a>01473             }
+<a name="l01474"></a>01474             sum -> data[i] += circle[l] ;
+<a name="l01475"></a>01475         }
+<a name="l01476"></a>01476         cpl_free (circle) ;
+<a name="l01477"></a>01477     }
+<a name="l01478"></a>01478     <span class="keywordflow">return</span> sum ;
+<a name="l01479"></a>01479 }
+<a name="l01480"></a>01480 
+<a name="l01494"></a>01494 Vector * sinfo_new_mean_rectangle_of_cube_spectra( cpl_imagelist * cube,
+<a name="l01495"></a>01495                                      <span class="keywordtype">int</span> llx,
+<a name="l01496"></a>01496                                      <span class="keywordtype">int</span> lly,
+<a name="l01497"></a>01497                                      <span class="keywordtype">int</span> urx,
+<a name="l01498"></a>01498                                      <span class="keywordtype">int</span> ury )
+<a name="l01499"></a>01499 {
+<a name="l01500"></a>01500     Vector          * mean ;
+<a name="l01501"></a>01501     pixelvalue      *local_rectangle ;
+<a name="l01502"></a>01502     <span class="keywordtype">int</span>             i, j, k, l, m ;
+<a name="l01503"></a>01503     <span class="keywordtype">int</span>             recsize, nv ;
+<a name="l01504"></a>01504     <span class="keywordtype">int</span> ilx=0;
+<a name="l01505"></a>01505     <span class="keywordtype">int</span> ily=0;
+<a name="l01506"></a>01506     <span class="keywordtype">int</span> inp=0;
+<a name="l01507"></a>01507     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l01508"></a>01508     cpl_image* i_img=NULL;
+<a name="l01509"></a>01509 
+<a name="l01510"></a>01510 
+<a name="l01511"></a>01511     ilx=cpl_image_get_size_x(cpl_imagelist_get(cube,0));
+<a name="l01512"></a>01512     ily=cpl_image_get_size_y(cpl_imagelist_get(cube,0));
+<a name="l01513"></a>01513     inp=cpl_imagelist_get_size(cube);
+<a name="l01514"></a>01514 
+<a name="l01515"></a>01515     <span class="keywordflow">if</span> ( cube == NULL || inp < 1 )
+<a name="l01516"></a>01516     {
+<a name="l01517"></a>01517         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"  no cube to take the mean of his spectra\n"</span>) ;
+<a name="l01518"></a>01518         <span class="keywordflow">return</span> NullVector ;
+<a name="l01519"></a>01519     }
+<a name="l01520"></a>01520 
+<a name="l01521"></a>01521     <span class="keywordflow">if</span> ((llx<0) || (llx>=ilx) ||
+<a name="l01522"></a>01522         (urx<0) || (urx>=ilx) ||
+<a name="l01523"></a>01523         (lly<0) || (lly>=ily) ||
+<a name="l01524"></a>01524         (ury<0) || (ury>=ily) ||
+<a name="l01525"></a>01525         (llx>=urx) || (lly>=ury))
+<a name="l01526"></a>01526     {
+<a name="l01527"></a>01527         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"  invalid rectangle coordinates:"</span>) ;
+<a name="l01528"></a>01528         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"lower left is [%d %d] upper right is [%d %d]"</span>,
+<a name="l01529"></a>01529                  llx, lly, urx, ury) ;
+<a name="l01530"></a>01530         <span class="keywordflow">return</span> NullVector ;
+<a name="l01531"></a>01531     }
+<a name="l01532"></a>01532 
+<a name="l01533"></a>01533     recsize = (urx - llx + 1) * (ury - lly + 1) ;
+<a name="l01534"></a>01534 
+<a name="l01535"></a>01535     <span class="comment">/* allocate a new sinfo_vector to store the average spectral values */</span>
+<a name="l01536"></a>01536     <span class="keywordflow">if</span> (NULL == (mean = sinfo_new_vector (inp)) )
+<a name="l01537"></a>01537     {
+<a name="l01538"></a>01538         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" cannot allocate a new sinfo_vector"</span>) ;
+<a name="l01539"></a>01539         <span class="keywordflow">return</span> NullVector ;
+<a name="l01540"></a>01540     }
+<a name="l01541"></a>01541 
+<a name="l01542"></a>01542     <span class="comment">/*------------------------------------------------------------------------</span>
+<a name="l01543"></a>01543 <span class="comment">     *  loop through the cube planes, through the x axis and the y-axis of the</span>
+<a name="l01544"></a>01544 <span class="comment">     *  plane rectangle and store pixel values in a buffer.</span>
+<a name="l01545"></a>01545 <span class="comment">     */</span>
+<a name="l01546"></a>01546     <span class="keywordflow">for</span> ( i = 0 ; i < inp ; i++ )
+<a name="l01547"></a>01547     {
+<a name="l01548"></a>01548       i_img=cpl_imagelist_get(cube,i);
+<a name="l01549"></a>01549       pidata=cpl_image_get_data_float(i_img);
+<a name="l01550"></a>01550         m = 0 ;
+<a name="l01551"></a>01551         local_rectangle = (pixelvalue *) cpl_calloc (recsize, 
+<a name="l01552"></a>01552                            <span class="keyword">sizeof</span> (pixelvalue*));
+<a name="l01553"></a>01553 
+<a name="l01554"></a>01554         <span class="keywordflow">for</span> ( j = lly ; j <= ury ; j++ )
+<a name="l01555"></a>01555         {
+<a name="l01556"></a>01556             <span class="keywordflow">for</span> ( k = llx ; k <= urx ; k++ )
+<a name="l01557"></a>01557             {
+<a name="l01558"></a>01558                 local_rectangle[m] = pidata[k + j * ilx] ;
+<a name="l01559"></a>01559                 m ++ ;
+<a name="l01560"></a>01560             }
+<a name="l01561"></a>01561         }
+<a name="l01562"></a>01562         nv = 0 ;
+<a name="l01563"></a>01563         <span class="keywordflow">for</span> ( l = 0 ; l < recsize ; l++ )
+<a name="l01564"></a>01564         {
+<a name="l01565"></a>01565             <span class="keywordflow">if</span> ( isnan(local_rectangle[l]) )
+<a name="l01566"></a>01566             {
+<a name="l01567"></a>01567                 continue ;
+<a name="l01568"></a>01568             }
+<a name="l01569"></a>01569             mean -> data[i] += local_rectangle[l] ;
+<a name="l01570"></a>01570             nv ++;
+<a name="l01571"></a>01571         }
+<a name="l01572"></a>01572         <span class="keywordflow">if</span> ( nv == 0 )
+<a name="l01573"></a>01573         {
+<a name="l01574"></a>01574             mean -> data[i] = ZERO ;
+<a name="l01575"></a>01575         }
+<a name="l01576"></a>01576         <span class="keywordflow">else</span>
+<a name="l01577"></a>01577         {
+<a name="l01578"></a>01578             mean -> data[i] /= nv ;
+<a name="l01579"></a>01579         }
+<a name="l01580"></a>01580         cpl_free ( local_rectangle ) ;
+<a name="l01581"></a>01581     }
+<a name="l01582"></a>01582     <span class="keywordflow">return</span> mean ;
+<a name="l01583"></a>01583 }
+<a name="l01584"></a>01584 
+<a name="l01596"></a>01596 Vector * 
+<a name="l01597"></a>01597 sinfo_new_mean_circle_of_cube_spectra( cpl_imagelist * cube,
+<a name="l01598"></a>01598                                   <span class="keywordtype">int</span>       centerx,
+<a name="l01599"></a>01599                                   <span class="keywordtype">int</span>       centery,
+<a name="l01600"></a>01600                                   <span class="keywordtype">int</span>       radius )
+<a name="l01601"></a>01601 {
+<a name="l01602"></a>01602     Vector          * mean ;
+<a name="l01603"></a>01603     pixelvalue      * circle ;
+<a name="l01604"></a>01604     <span class="keywordtype">int</span>             i, j, k, l, m, n ;
+<a name="l01605"></a>01605     <span class="keywordtype">int</span>             circsize, nv ;
+<a name="l01606"></a>01606     <span class="keywordtype">int</span> ilx=0;
+<a name="l01607"></a>01607     <span class="keywordtype">int</span> ily=0;
+<a name="l01608"></a>01608     <span class="keywordtype">int</span> inp=0;
+<a name="l01609"></a>01609     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l01610"></a>01610     cpl_image* i_img=NULL;
+<a name="l01611"></a>01611 
+<a name="l01612"></a>01612 
+<a name="l01613"></a>01613     ilx=cpl_image_get_size_x(cpl_imagelist_get(cube,0));
+<a name="l01614"></a>01614     ily=cpl_image_get_size_y(cpl_imagelist_get(cube,0));
+<a name="l01615"></a>01615     inp=cpl_imagelist_get_size(cube);
+<a name="l01616"></a>01616 
+<a name="l01617"></a>01617     <span class="keywordflow">if</span> ( cube == NULL || inp < 1 )
+<a name="l01618"></a>01618     {
+<a name="l01619"></a>01619         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"no cube to take the mean of his spectra"</span>) ;
+<a name="l01620"></a>01620         <span class="keywordflow">return</span> NullVector ;
+<a name="l01621"></a>01621     }
+<a name="l01622"></a>01622 
+<a name="l01623"></a>01623     <span class="keywordflow">if</span> ((centerx+radius>=ilx) ||
+<a name="l01624"></a>01624         (centery+radius>=ily) ||
+<a name="l01625"></a>01625         (centerx-radius<0) ||
+<a name="l01626"></a>01626         (centery-radius<0))
+<a name="l01627"></a>01627     {
+<a name="l01628"></a>01628         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" invalid circular coordinates"</span>) ;
+<a name="l01629"></a>01629         <span class="keywordflow">return</span> NullVector ;
+<a name="l01630"></a>01630     }
+<a name="l01631"></a>01631 
+<a name="l01632"></a>01632     n = 0 ;
+<a name="l01633"></a>01633     <span class="keywordflow">for</span> ( j = centery - radius ; j <= centery + radius ; j++ )
+<a name="l01634"></a>01634     {
+<a name="l01635"></a>01635         <span class="keywordflow">for</span> ( k = centerx - radius ; k <= centerx + radius ; k++ )
+<a name="l01636"></a>01636         {
+<a name="l01637"></a>01637             <span class="keywordflow">if</span> ( (k-centerx)*(k-centerx)+(j-centery)*(j-centery) <= 
+<a name="l01638"></a>01638                  radius*radius )
+<a name="l01639"></a>01639             {
+<a name="l01640"></a>01640                 n ++ ;
+<a name="l01641"></a>01641             }
+<a name="l01642"></a>01642         }
+<a name="l01643"></a>01643     }
+<a name="l01644"></a>01644     <span class="keywordflow">if</span> (n == 0)
+<a name="l01645"></a>01645     {
+<a name="l01646"></a>01646         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" no data points found!\n"</span>) ;
+<a name="l01647"></a>01647         <span class="keywordflow">return</span> NullVector ;
+<a name="l01648"></a>01648     }
+<a name="l01649"></a>01649     circsize = n ;
+<a name="l01650"></a>01650 
+<a name="l01651"></a>01651     <span class="comment">/* allocate a new sinfo_vector to store the average spectral values */</span>
+<a name="l01652"></a>01652     <span class="keywordflow">if</span> (NULL == (mean = sinfo_new_vector (inp)) )
+<a name="l01653"></a>01653     {
+<a name="l01654"></a>01654         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" cannot allocate a new sinfo_vector \n"</span>) ;
+<a name="l01655"></a>01655         <span class="keywordflow">return</span> NullVector ;
+<a name="l01656"></a>01656     }
+<a name="l01657"></a>01657 
+<a name="l01658"></a>01658     <span class="comment">/*------------------------------------------------------------------------</span>
+<a name="l01659"></a>01659 <span class="comment">     *  loop through the cube planes, through the x axis and the y-axis of the</span>
+<a name="l01660"></a>01660 <span class="comment">     *  plane circle and store pixel values in a buffer.</span>
+<a name="l01661"></a>01661 <span class="comment">     */</span>
+<a name="l01662"></a>01662     <span class="keywordflow">for</span> ( i = 0 ; i < inp ; i++ )
+<a name="l01663"></a>01663     {
+<a name="l01664"></a>01664       i_img=cpl_imagelist_get(cube,i);
+<a name="l01665"></a>01665       pidata=cpl_image_get_data_float(i_img);
+<a name="l01666"></a>01666         m = 0 ;
+<a name="l01667"></a>01667         circle = (pixelvalue *) cpl_calloc (circsize, <span class="keyword">sizeof</span> (pixelvalue*));
+<a name="l01668"></a>01668 
+<a name="l01669"></a>01669         <span class="keywordflow">for</span> ( j = centery - radius ; j <= centery + radius ; j++ )
+<a name="l01670"></a>01670         {
+<a name="l01671"></a>01671             <span class="keywordflow">for</span> ( k = centerx - radius ; k <= centerx + radius ; k++ )
+<a name="l01672"></a>01672             {
+<a name="l01673"></a>01673                 <span class="keywordflow">if</span> ( (k-centerx)*(k-centerx)+(j-centery)*(j-centery) <= 
+<a name="l01674"></a>01674                      radius*radius )
+<a name="l01675"></a>01675                 {
+<a name="l01676"></a>01676                     circle[m] = pidata[k + j * ilx] ;
+<a name="l01677"></a>01677                     m ++ ;
+<a name="l01678"></a>01678                 }
+<a name="l01679"></a>01679             }
+<a name="l01680"></a>01680         }
+<a name="l01681"></a>01681 
+<a name="l01682"></a>01682         nv = 0 ;
+<a name="l01683"></a>01683         <span class="keywordflow">for</span> ( l = 0 ; l < circsize ; l++ )
+<a name="l01684"></a>01684         {
+<a name="l01685"></a>01685             <span class="keywordflow">if</span> ( isnan(circle[l]) )
+<a name="l01686"></a>01686             {
+<a name="l01687"></a>01687                 continue ;
+<a name="l01688"></a>01688             }
+<a name="l01689"></a>01689             mean -> data[i] += circle[l] ;
+<a name="l01690"></a>01690             nv ++;
+<a name="l01691"></a>01691         }
+<a name="l01692"></a>01692         <span class="keywordflow">if</span> ( nv == 0 )
+<a name="l01693"></a>01693         {
+<a name="l01694"></a>01694             mean -> data[i] = ZERO ;
+<a name="l01695"></a>01695         }
+<a name="l01696"></a>01696         <span class="keywordflow">else</span>
+<a name="l01697"></a>01697         {
+<a name="l01698"></a>01698             mean -> data[i] /= nv ;
+<a name="l01699"></a>01699         }
+<a name="l01700"></a>01700 
+<a name="l01701"></a>01701         cpl_free (circle) ;
+<a name="l01702"></a>01702     }
+<a name="l01703"></a>01703     <span class="keywordflow">return</span> mean ;
+<a name="l01704"></a>01704 }
+<a name="l01705"></a>01705 
+<a name="l01715"></a>01715 Vector * sinfo_new_blackbody_spectrum( <span class="keywordtype">char</span> * templateSpec, <span class="keywordtype">double</span> temp )
+<a name="l01716"></a>01716 {
+<a name="l01717"></a>01717     Vector * retSpec ;
+<a name="l01718"></a>01718     <span class="keywordtype">int</span> n ;
+<a name="l01719"></a>01719     <span class="keywordtype">double</span> cenpix ;
+<a name="l01720"></a>01720     <span class="keywordtype">int</span> npix ;
+<a name="l01721"></a>01721     <span class="keywordtype">double</span> cenLambda ;
+<a name="l01722"></a>01722     <span class="keywordtype">double</span> firstLambda ;
+<a name="l01723"></a>01723     <span class="keywordtype">double</span> disp ;
+<a name="l01724"></a>01724     <span class="keywordtype">double</span> lambda ;
+<a name="l01725"></a>01725     <span class="keywordtype">double</span> intens ;
+<a name="l01726"></a>01726     <span class="keywordtype">double</span> denom ;
+<a name="l01727"></a>01727     <span class="keywordtype">double</span> norm ;
+<a name="l01728"></a>01728     cpl_propertylist* plist=NULL;
+<a name="l01729"></a>01729 
+<a name="l01730"></a>01730     <span class="keywordflow">if</span> ( NULL == templateSpec )
+<a name="l01731"></a>01731     {
+<a name="l01732"></a>01732         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" now input image given!\n"</span>) ;
+<a name="l01733"></a>01733         <span class="keywordflow">return</span> NULL ;
+<a name="l01734"></a>01734     }
+<a name="l01735"></a>01735     <span class="keywordflow">if</span> ( temp < 0. )
+<a name="l01736"></a>01736     {
+<a name="l01737"></a>01737         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" wrong temperature given!\n"</span>) ;
+<a name="l01738"></a>01738         <span class="keywordflow">return</span> NULL ;
+<a name="l01739"></a>01739     }
+<a name="l01740"></a>01740     <span class="comment">/* get the fits header information needed */</span>
+<a name="l01741"></a>01741     <span class="keywordflow">if</span> ((cpl_error_code)((plist=cpl_propertylist_load(templateSpec,0))==NULL)){
+<a name="l01742"></a>01742       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>( <span class="stringliteral">"getting header from frame %s"</span>,templateSpec);
+<a name="l01743"></a>01743       cpl_propertylist_delete(plist) ;
+<a name="l01744"></a>01744       <span class="keywordflow">return</span> NULL ;
+<a name="l01745"></a>01745     }
+<a name="l01746"></a>01746 
+<a name="l01747"></a>01747 
+<a name="l01748"></a>01748     cenpix = sinfo_pfits_get_crpix2(plist);
+<a name="l01749"></a>01749     <span class="keywordflow">if</span>(cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l01750"></a>01750         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" cannot get CRPIX2\n"</span>) ;
+<a name="l01751"></a>01751         sinfo_free_propertylist(&plist) ;
+<a name="l01752"></a>01752         <span class="keywordflow">return</span> NULL ;
+<a name="l01753"></a>01753     }
+<a name="l01754"></a>01754 
+<a name="l01755"></a>01755     cenLambda = sinfo_pfits_get_crval2(plist);
+<a name="l01756"></a>01756     <span class="keywordflow">if</span>(cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l01757"></a>01757         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" cannot get CRVAL2\n"</span>) ;
+<a name="l01758"></a>01758         sinfo_free_propertylist(&plist) ;
+<a name="l01759"></a>01759         <span class="keywordflow">return</span> NULL ;
+<a name="l01760"></a>01760     }
+<a name="l01761"></a>01761     disp = sinfo_pfits_get_cdelt2(plist);
+<a name="l01762"></a>01762     <span class="keywordflow">if</span>(cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l01763"></a>01763         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" cannot get CDELT2\n"</span>) ;
+<a name="l01764"></a>01764         sinfo_free_propertylist(&plist) ;
+<a name="l01765"></a>01765         <span class="keywordflow">return</span> NULL ;
+<a name="l01766"></a>01766     }
+<a name="l01767"></a>01767     npix = sinfo_pfits_get_naxis2(plist);
+<a name="l01768"></a>01768     <span class="keywordflow">if</span>(cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l01769"></a>01769         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" cannot get NAXIS2\n"</span>) ;
+<a name="l01770"></a>01770         sinfo_free_propertylist(&plist) ;
+<a name="l01771"></a>01771         <span class="keywordflow">return</span> NULL ;
+<a name="l01772"></a>01772     }
+<a name="l01773"></a>01773     sinfo_free_propertylist(&plist) ;
+<a name="l01774"></a>01774 
+<a name="l01775"></a>01775 
+<a name="l01776"></a>01776     <span class="keywordflow">if</span> (NULL == (retSpec = sinfo_new_vector (npix)))
+<a name="l01777"></a>01777     {
+<a name="l01778"></a>01778         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" could not allocate memory!\n"</span>) ;
+<a name="l01779"></a>01779         <span class="keywordflow">return</span> NULL ;
+<a name="l01780"></a>01780     }
+<a name="l01781"></a>01781     
+<a name="l01782"></a>01782     <span class="comment">/* shift from fits to image coordinates */</span>
+<a name="l01783"></a>01783     cenpix-- ;
+<a name="l01784"></a>01784   
+<a name="l01785"></a>01785     firstLambda = cenLambda - cenpix * disp ;
+<a name="l01786"></a>01786     <span class="keywordflow">for</span> ( n = 0 ; n < npix ; n++ )
+<a name="l01787"></a>01787     {
+<a name="l01788"></a>01788         lambda = firstLambda + disp * (double)n ;
+<a name="l01789"></a>01789         <span class="comment">/* convert from microns to m */</span>
+<a name="l01790"></a>01790 
+<a name="l01791"></a>01791         lambda /= 1.0e6 ;
+<a name="l01792"></a>01792         denom = 1./(exp(PLANCK*SPEED_OF_LIGHT/(lambda*BOLTZMANN*temp)) - 1.) ;
+<a name="l01793"></a>01793         intens = 2.*PI_NUMB*PLANCK*SPEED_OF_LIGHT*SPEED_OF_LIGHT / 
+<a name="l01794"></a>01794                  pow(lambda, 5) * denom ;
+<a name="l01795"></a>01795         retSpec->data[n] = intens ;   
+<a name="l01796"></a>01796     }
+<a name="l01797"></a>01797     norm = retSpec->data[npix/2] ;
+<a name="l01798"></a>01798     <span class="keywordflow">for</span> ( n = 0 ; n < npix ; n++ )
+<a name="l01799"></a>01799     {
+<a name="l01800"></a>01800         retSpec->data[n] /= norm ;
+<a name="l01801"></a>01801     }
+<a name="l01802"></a>01802     
+<a name="l01803"></a>01803     <span class="keywordflow">return</span> retSpec ;
+<a name="l01804"></a>01804 }
+<a name="l01805"></a>01805 
+<a name="l01806"></a>01806 
+<a name="l01820"></a>01820 Vector * sinfo_new_median_rectangle_of_cube_spectra( cpl_imagelist * cube,
+<a name="l01821"></a>01821                                              <span class="keywordtype">int</span> llx,
+<a name="l01822"></a>01822                                              <span class="keywordtype">int</span> lly,
+<a name="l01823"></a>01823                                              <span class="keywordtype">int</span> urx,
+<a name="l01824"></a>01824                                              <span class="keywordtype">int</span> ury )
+<a name="l01825"></a>01825 {
+<a name="l01826"></a>01826     Vector          * med ;
+<a name="l01827"></a>01827     pixelvalue      *local_rectangle ;
+<a name="l01828"></a>01828     <span class="keywordtype">int</span>             i, j, k, m ;
+<a name="l01829"></a>01829     <span class="keywordtype">int</span>             recsize ;
+<a name="l01830"></a>01830     <span class="keywordtype">int</span> ilx=0;
+<a name="l01831"></a>01831     <span class="keywordtype">int</span> ily=0;
+<a name="l01832"></a>01832     <span class="keywordtype">int</span> inp=0;
+<a name="l01833"></a>01833     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l01834"></a>01834     cpl_image* i_img=NULL;
+<a name="l01835"></a>01835 
+<a name="l01836"></a>01836 
+<a name="l01837"></a>01837     ilx=cpl_image_get_size_x(cpl_imagelist_get(cube,0));
+<a name="l01838"></a>01838     ily=cpl_image_get_size_y(cpl_imagelist_get(cube,0));
+<a name="l01839"></a>01839     inp=cpl_imagelist_get_size(cube);
+<a name="l01840"></a>01840 
+<a name="l01841"></a>01841     <span class="keywordflow">if</span> ( cube == NULL || inp < 1 )
+<a name="l01842"></a>01842     {
+<a name="l01843"></a>01843         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" no cube to take the mean of his spectra\n"</span>) ;
+<a name="l01844"></a>01844         <span class="keywordflow">return</span> NullVector ;
+<a name="l01845"></a>01845     }
+<a name="l01846"></a>01846 
+<a name="l01847"></a>01847     <span class="keywordflow">if</span> ((llx<0) || (llx>=ilx) ||
+<a name="l01848"></a>01848         (urx<0) || (urx>=ilx) ||
+<a name="l01849"></a>01849         (lly<0) || (lly>=ily) ||
+<a name="l01850"></a>01850         (ury<0) || (ury>=ily) ||
+<a name="l01851"></a>01851         (llx>=urx) || (lly>=ury))
+<a name="l01852"></a>01852     {
+<a name="l01853"></a>01853         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" invalid rectangle coordinates:"</span>) ;
+<a name="l01854"></a>01854         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"lower left is [%d %d] upper right is [%d %d]"</span>, 
+<a name="l01855"></a>01855                         llx, lly, urx, ury) ;
+<a name="l01856"></a>01856         <span class="keywordflow">return</span> NullVector ;
+<a name="l01857"></a>01857     }
+<a name="l01858"></a>01858 
+<a name="l01859"></a>01859     recsize = (urx - llx + 1) * (ury - lly + 1) ;
+<a name="l01860"></a>01860 
+<a name="l01861"></a>01861     <span class="comment">/* allocate a new sinfo_vector to store the average spectral values */</span>
+<a name="l01862"></a>01862     <span class="keywordflow">if</span> (NULL == (med = sinfo_new_vector (inp)) )
+<a name="l01863"></a>01863     {
+<a name="l01864"></a>01864         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" cannot allocate a new sinfo_vector \n"</span>) ;
+<a name="l01865"></a>01865         <span class="keywordflow">return</span> NullVector ;
+<a name="l01866"></a>01866     }
+<a name="l01867"></a>01867 
+<a name="l01868"></a>01868     <span class="comment">/*------------------------------------------------------------------------</span>
+<a name="l01869"></a>01869 <span class="comment">     *  loop through the cube planes, through the x axis and the y-axis of the</span>
+<a name="l01870"></a>01870 <span class="comment">     *  plane rectangle and store pixel values in a buffer.</span>
+<a name="l01871"></a>01871 <span class="comment">     */</span>
+<a name="l01872"></a>01872     <span class="keywordflow">for</span> ( i = 0 ; i < inp ; i++ )
+<a name="l01873"></a>01873     {
+<a name="l01874"></a>01874 
+<a name="l01875"></a>01875       i_img=cpl_imagelist_get(cube,i);
+<a name="l01876"></a>01876       pidata=cpl_image_get_data_float(i_img);
+<a name="l01877"></a>01877       m = 0 ;
+<a name="l01878"></a>01878       local_rectangle=(pixelvalue *)cpl_calloc(recsize, <span class="keyword">sizeof</span> (pixelvalue*));
+<a name="l01879"></a>01879 
+<a name="l01880"></a>01880         <span class="keywordflow">for</span> ( j = lly ; j <= ury ; j++ )
+<a name="l01881"></a>01881         {
+<a name="l01882"></a>01882             <span class="keywordflow">for</span> ( k = llx ; k <= urx ; k++ )
+<a name="l01883"></a>01883             {
+<a name="l01884"></a>01884                 <span class="keywordflow">if</span> ( isnan(pidata[k+j*ilx]) )
+<a name="l01885"></a>01885                 {
+<a name="l01886"></a>01886                     continue ;
+<a name="l01887"></a>01887                 }
+<a name="l01888"></a>01888                 <span class="keywordflow">else</span>
+<a name="l01889"></a>01889                 {
+<a name="l01890"></a>01890                     local_rectangle[m] = pidata[k + j * ilx] ;
+<a name="l01891"></a>01891                     m ++ ;
+<a name="l01892"></a>01892                 }
+<a name="l01893"></a>01893             }
+<a name="l01894"></a>01894         }
+<a name="l01895"></a>01895         <span class="keywordflow">if</span> ( m == 0 )
+<a name="l01896"></a>01896         {
+<a name="l01897"></a>01897             med->data[i] = 0. ;
+<a name="l01898"></a>01898         }
+<a name="l01899"></a>01899         <span class="keywordflow">else</span>
+<a name="l01900"></a>01900         {
+<a name="l01901"></a>01901             med->data[i] = sinfo_new_median(local_rectangle, m) ;
+<a name="l01902"></a>01902         }
+<a name="l01903"></a>01903         cpl_free ( local_rectangle ) ;
+<a name="l01904"></a>01904     }
+<a name="l01905"></a>01905     <span class="keywordflow">return</span> med ;
+<a name="l01906"></a>01906 }
+<a name="l01907"></a>01907 
+<a name="l01919"></a>01919 Vector * sinfo_new_median_circle_of_cube_spectra( cpl_imagelist * cube,
+<a name="l01920"></a>01920                                   <span class="keywordtype">int</span>       centerx,
+<a name="l01921"></a>01921                                   <span class="keywordtype">int</span>       centery,
+<a name="l01922"></a>01922                                   <span class="keywordtype">int</span>       radius )
+<a name="l01923"></a>01923 {
+<a name="l01924"></a>01924     Vector          * med ;
+<a name="l01925"></a>01925     pixelvalue      * circle ;
+<a name="l01926"></a>01926     <span class="keywordtype">int</span>             i, j, k, l, m, n ;
+<a name="l01927"></a>01927     <span class="keywordtype">int</span>             circsize, nv ;
+<a name="l01928"></a>01928     <span class="keywordtype">int</span> ilx=0;
+<a name="l01929"></a>01929     <span class="keywordtype">int</span> ily=0;
+<a name="l01930"></a>01930     <span class="keywordtype">int</span> inp=0;
+<a name="l01931"></a>01931     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l01932"></a>01932     cpl_image* i_img=NULL;
+<a name="l01933"></a>01933 
+<a name="l01934"></a>01934 
+<a name="l01935"></a>01935     ilx=cpl_image_get_size_x(cpl_imagelist_get(cube,0));
+<a name="l01936"></a>01936     ily=cpl_image_get_size_y(cpl_imagelist_get(cube,0));
+<a name="l01937"></a>01937     inp=cpl_imagelist_get_size(cube);
+<a name="l01938"></a>01938 
+<a name="l01939"></a>01939     <span class="keywordflow">if</span> ( cube == NULL || inp < 1 )
+<a name="l01940"></a>01940     {
+<a name="l01941"></a>01941         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" no cube to take the mean of his spectra\n"</span>) ;
+<a name="l01942"></a>01942         <span class="keywordflow">return</span> NullVector ;
+<a name="l01943"></a>01943     }
+<a name="l01944"></a>01944 
+<a name="l01945"></a>01945     <span class="keywordflow">if</span> ((centerx+radius>=ilx) ||
+<a name="l01946"></a>01946         (centery+radius>=ily) ||
+<a name="l01947"></a>01947         (centerx-radius<0) ||
+<a name="l01948"></a>01948         (centery-radius<0))
+<a name="l01949"></a>01949     {
+<a name="l01950"></a>01950         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" invalid circular coordinates"</span>) ;
+<a name="l01951"></a>01951         <span class="keywordflow">return</span> NullVector ;
+<a name="l01952"></a>01952     }
+<a name="l01953"></a>01953 
+<a name="l01954"></a>01954     n = 0 ;
+<a name="l01955"></a>01955     <span class="keywordflow">for</span> ( j = centery - radius ; j <= centery + radius ; j++ )
+<a name="l01956"></a>01956     {
+<a name="l01957"></a>01957         <span class="keywordflow">for</span> ( k = centerx - radius ; k <= centerx + radius ; k++ )
+<a name="l01958"></a>01958         {
+<a name="l01959"></a>01959             <span class="keywordflow">if</span> ( (k-centerx)*(k-centerx)+(j-centery)*(j-centery) <= 
+<a name="l01960"></a>01960                   radius*radius )
+<a name="l01961"></a>01961             {
+<a name="l01962"></a>01962                 n ++ ;
+<a name="l01963"></a>01963             }
+<a name="l01964"></a>01964         }
+<a name="l01965"></a>01965     }
+<a name="l01966"></a>01966     <span class="keywordflow">if</span> (n == 0)
+<a name="l01967"></a>01967     {
+<a name="l01968"></a>01968         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" no data points found!"</span>) ;
+<a name="l01969"></a>01969         <span class="keywordflow">return</span> NullVector ;
+<a name="l01970"></a>01970     }
+<a name="l01971"></a>01971     circsize = n ;
+<a name="l01972"></a>01972 
+<a name="l01973"></a>01973     <span class="comment">/* allocate a new sinfo_vector to store the average spectral values */</span>
+<a name="l01974"></a>01974     <span class="keywordflow">if</span> (NULL == (med = sinfo_new_vector (inp)) )
+<a name="l01975"></a>01975     {
+<a name="l01976"></a>01976         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" cannot allocate a new sinfo_vector"</span>) ;
+<a name="l01977"></a>01977         <span class="keywordflow">return</span> NullVector ;
+<a name="l01978"></a>01978     }
+<a name="l01979"></a>01979 
+<a name="l01980"></a>01980     <span class="comment">/*------------------------------------------------------------------------</span>
+<a name="l01981"></a>01981 <span class="comment">     *  loop through the cube planes, through the x axis and the y-axis of the</span>
+<a name="l01982"></a>01982 <span class="comment">     *  plane circle and store pixel values in a buffer.</span>
+<a name="l01983"></a>01983 <span class="comment">     */</span>
+<a name="l01984"></a>01984     <span class="keywordflow">for</span> ( i = 0 ; i < inp ; i++ )
+<a name="l01985"></a>01985     {
+<a name="l01986"></a>01986       i_img=cpl_imagelist_get(cube,i);
+<a name="l01987"></a>01987       pidata=cpl_image_get_data_float(i_img);
+<a name="l01988"></a>01988         m = 0 ;
+<a name="l01989"></a>01989         circle = (pixelvalue *) cpl_calloc (circsize, <span class="keyword">sizeof</span> (pixelvalue*));
+<a name="l01990"></a>01990 
+<a name="l01991"></a>01991         <span class="keywordflow">for</span> ( j = centery - radius ; j <= centery + radius ; j++ )
+<a name="l01992"></a>01992         {
+<a name="l01993"></a>01993             <span class="keywordflow">for</span> ( k = centerx - radius ; k <= centerx + radius ; k++ )
+<a name="l01994"></a>01994             {
+<a name="l01995"></a>01995                 <span class="keywordflow">if</span> ( (k-centerx)*(k-centerx)+(j-centery)*(j-centery) <= 
+<a name="l01996"></a>01996                       radius*radius )
+<a name="l01997"></a>01997                 {
+<a name="l01998"></a>01998                     circle[m] = pidata[k + j * ilx] ;
+<a name="l01999"></a>01999                     m ++ ;
+<a name="l02000"></a>02000                 }
+<a name="l02001"></a>02001             }
+<a name="l02002"></a>02002         }
+<a name="l02003"></a>02003 
+<a name="l02004"></a>02004         nv = 0 ;
+<a name="l02005"></a>02005         <span class="keywordflow">for</span> ( l = 0 ; l < circsize ; l++ )
+<a name="l02006"></a>02006         {
+<a name="l02007"></a>02007             <span class="keywordflow">if</span> ( isnan(circle[l]) )
+<a name="l02008"></a>02008             {
+<a name="l02009"></a>02009                 continue ;
+<a name="l02010"></a>02010             }
+<a name="l02011"></a>02011             med -> data[i] += circle[l] ;
+<a name="l02012"></a>02012             nv ++;
+<a name="l02013"></a>02013         }
+<a name="l02014"></a>02014         <span class="keywordflow">if</span> ( nv == 0 )
+<a name="l02015"></a>02015         {
+<a name="l02016"></a>02016             med->data[i] = 0. ;
+<a name="l02017"></a>02017         }
+<a name="l02018"></a>02018         <span class="keywordflow">else</span>
+<a name="l02019"></a>02019         {
+<a name="l02020"></a>02020             med->data[i] = sinfo_new_median(circle, nv) ; 
+<a name="l02021"></a>02021         }
+<a name="l02022"></a>02022         cpl_free (circle) ;
+<a name="l02023"></a>02023     }
+<a name="l02024"></a>02024     <span class="keywordflow">return</span> med ;
+<a name="l02025"></a>02025 }
+<a name="l02026"></a>02026 
+<a name="l02040"></a>02040 Vector * 
+<a name="l02041"></a>02041 sinfo_new_cleanmean_rectangle_of_cube_spectra( cpl_imagelist * cube,
+<a name="l02042"></a>02042                                           <span class="keywordtype">int</span> llx,
+<a name="l02043"></a>02043                                           <span class="keywordtype">int</span> lly,
+<a name="l02044"></a>02044                                           <span class="keywordtype">int</span> urx,
+<a name="l02045"></a>02045                                           <span class="keywordtype">int</span> ury,
+<a name="l02046"></a>02046                                           <span class="keywordtype">float</span> lo_reject,
+<a name="l02047"></a>02047                                           <span class="keywordtype">float</span> hi_reject )
+<a name="l02048"></a>02048 {
+<a name="l02049"></a>02049     Vector          * clean ;
+<a name="l02050"></a>02050     pixelvalue      *local_rectangle ;
+<a name="l02051"></a>02051     <span class="keywordtype">int</span>             i, j, k, m ;
+<a name="l02052"></a>02052     <span class="keywordtype">int</span>             recsize ;
+<a name="l02053"></a>02053     <span class="keywordtype">int</span> ilx=0;
+<a name="l02054"></a>02054     <span class="keywordtype">int</span> ily=0;
+<a name="l02055"></a>02055     <span class="keywordtype">int</span> inp=0;
+<a name="l02056"></a>02056     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l02057"></a>02057     cpl_image* i_img=NULL;
+<a name="l02058"></a>02058 
+<a name="l02059"></a>02059 
+<a name="l02060"></a>02060     ilx=cpl_image_get_size_x(cpl_imagelist_get(cube,0));
+<a name="l02061"></a>02061     ily=cpl_image_get_size_y(cpl_imagelist_get(cube,0));
+<a name="l02062"></a>02062     inp=cpl_imagelist_get_size(cube);
+<a name="l02063"></a>02063 
+<a name="l02064"></a>02064     <span class="keywordflow">if</span> ( cube == NULL || inp < 1 )
+<a name="l02065"></a>02065     {
+<a name="l02066"></a>02066         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" no cube to take the mean of his spectra\n"</span>) ;
+<a name="l02067"></a>02067         <span class="keywordflow">return</span> NullVector ;
+<a name="l02068"></a>02068     }
+<a name="l02069"></a>02069 
+<a name="l02070"></a>02070     <span class="keywordflow">if</span> ((llx<0) || (llx>=ilx) ||
+<a name="l02071"></a>02071         (urx<0) || (urx>=ilx) ||
+<a name="l02072"></a>02072         (lly<0) || (lly>=ily) ||
+<a name="l02073"></a>02073         (ury<0) || (ury>=ily) ||
+<a name="l02074"></a>02074         (llx>=urx) || (lly>=ury))
+<a name="l02075"></a>02075     {
+<a name="l02076"></a>02076         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" invalid rectangle coordinates:"</span>) ;
+<a name="l02077"></a>02077         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"lower left is [%d %d] upper right is [%d %d]"</span>,
+<a name="l02078"></a>02078                  llx, lly, urx, ury) ;
+<a name="l02079"></a>02079         <span class="keywordflow">return</span> NullVector ;
+<a name="l02080"></a>02080     }
+<a name="l02081"></a>02081 
+<a name="l02082"></a>02082     recsize = (urx - llx + 1) * (ury - lly + 1) ;
+<a name="l02083"></a>02083 
+<a name="l02084"></a>02084     <span class="comment">/* allocate a new sinfo_vector to store the average spectral values */</span>
+<a name="l02085"></a>02085     <span class="keywordflow">if</span> (NULL == (clean = sinfo_new_vector (inp)) )
+<a name="l02086"></a>02086     {
+<a name="l02087"></a>02087         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" cannot allocate a new sinfo_vector"</span>) ;
+<a name="l02088"></a>02088         <span class="keywordflow">return</span> NullVector ;
+<a name="l02089"></a>02089     }
+<a name="l02090"></a>02090 
+<a name="l02091"></a>02091     <span class="comment">/*------------------------------------------------------------------------</span>
+<a name="l02092"></a>02092 <span class="comment">     *  loop through the cube planes, through the x axis and the y-axis of the</span>
+<a name="l02093"></a>02093 <span class="comment">     *  plane rectangle and store pixel values in a buffer.</span>
+<a name="l02094"></a>02094 <span class="comment">     */</span>
+<a name="l02095"></a>02095     <span class="keywordflow">for</span> ( i = 0 ; i < inp ; i++ )
+<a name="l02096"></a>02096     {
+<a name="l02097"></a>02097       i_img=cpl_imagelist_get(cube,i);
+<a name="l02098"></a>02098       pidata=cpl_image_get_data_float(i_img);
+<a name="l02099"></a>02099       m = 0 ;
+<a name="l02100"></a>02100       local_rectangle=(pixelvalue *) cpl_calloc(recsize, <span class="keyword">sizeof</span> (pixelvalue*));
+<a name="l02101"></a>02101 
+<a name="l02102"></a>02102         <span class="keywordflow">for</span> ( j = lly ; j <= ury ; j++ )
+<a name="l02103"></a>02103         {
+<a name="l02104"></a>02104             <span class="keywordflow">for</span> ( k = llx ; k <= urx ; k++ )
+<a name="l02105"></a>02105             {
+<a name="l02106"></a>02106                 <span class="keywordflow">if</span> ( isnan(pidata[k+j*ilx]) )
+<a name="l02107"></a>02107                 {
+<a name="l02108"></a>02108                     continue ;
+<a name="l02109"></a>02109                 }
+<a name="l02110"></a>02110                 <span class="keywordflow">else</span>
+<a name="l02111"></a>02111                 {
+<a name="l02112"></a>02112                     local_rectangle[m] = pidata[k + j * ilx] ;
+<a name="l02113"></a>02113                     m ++ ;
+<a name="l02114"></a>02114                 }
+<a name="l02115"></a>02115             }
+<a name="l02116"></a>02116         }
+<a name="l02117"></a>02117         <span class="keywordflow">if</span> ( m == 0 )
+<a name="l02118"></a>02118         {
+<a name="l02119"></a>02119             clean->data[i] = 0. ;
+<a name="l02120"></a>02120         }
+<a name="l02121"></a>02121         <span class="keywordflow">else</span>
+<a name="l02122"></a>02122         {
+<a name="l02123"></a>02123             clean->data[i] = sinfo_new_clean_mean(local_rectangle, m, 
+<a name="l02124"></a>02124                                                   lo_reject, hi_reject) ;
+<a name="l02125"></a>02125         }
+<a name="l02126"></a>02126         cpl_free ( local_rectangle ) ;
+<a name="l02127"></a>02127     }
+<a name="l02128"></a>02128     <span class="keywordflow">return</span> clean ;
+<a name="l02129"></a>02129 }
+<a name="l02130"></a>02130 
+<a name="l02142"></a>02142 Vector * 
+<a name="l02143"></a>02143 sinfo_new_cleanmean_circle_of_cube_spectra( cpl_imagelist * cube,
+<a name="l02144"></a>02144                                   <span class="keywordtype">int</span>       centerx,
+<a name="l02145"></a>02145                                   <span class="keywordtype">int</span>       centery,
+<a name="l02146"></a>02146                                   <span class="keywordtype">int</span>       radius,
+<a name="l02147"></a>02147                                   <span class="keywordtype">float</span>     lo_reject,
+<a name="l02148"></a>02148                                   <span class="keywordtype">float</span>     hi_reject )
+<a name="l02149"></a>02149 {
+<a name="l02150"></a>02150     Vector          * clean ;
+<a name="l02151"></a>02151     pixelvalue      * circle ;
+<a name="l02152"></a>02152     <span class="keywordtype">int</span>             i, j, k, l, m, n ;
+<a name="l02153"></a>02153     <span class="keywordtype">int</span>             circsize, nv ;
+<a name="l02154"></a>02154     <span class="keywordtype">int</span> ilx=0;
+<a name="l02155"></a>02155     <span class="keywordtype">int</span> ily=0;
+<a name="l02156"></a>02156     <span class="keywordtype">int</span> inp=0;
+<a name="l02157"></a>02157     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l02158"></a>02158     cpl_image* i_img=NULL;
+<a name="l02159"></a>02159 
+<a name="l02160"></a>02160     ilx=cpl_image_get_size_x(cpl_imagelist_get(cube,0));
+<a name="l02161"></a>02161     ily=cpl_image_get_size_y(cpl_imagelist_get(cube,0));
+<a name="l02162"></a>02162     inp=cpl_imagelist_get_size(cube);
+<a name="l02163"></a>02163 
+<a name="l02164"></a>02164     <span class="keywordflow">if</span> ( cube == NULL || inp < 1 )
+<a name="l02165"></a>02165     {
+<a name="l02166"></a>02166         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" no cube to take the mean of his spectra\n"</span>) ;
+<a name="l02167"></a>02167         <span class="keywordflow">return</span> NullVector ;
+<a name="l02168"></a>02168     }
+<a name="l02169"></a>02169 
+<a name="l02170"></a>02170     <span class="keywordflow">if</span> ((centerx+radius>=ilx) ||
+<a name="l02171"></a>02171         (centery+radius>=ily) ||
+<a name="l02172"></a>02172         (centerx-radius<0) ||
+<a name="l02173"></a>02173         (centery-radius<0))
+<a name="l02174"></a>02174     {
+<a name="l02175"></a>02175         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" invalid circular coordinates"</span>) ;
+<a name="l02176"></a>02176         <span class="keywordflow">return</span> NullVector ;
+<a name="l02177"></a>02177     }
+<a name="l02178"></a>02178 
+<a name="l02179"></a>02179     n = 0 ;
+<a name="l02180"></a>02180     <span class="keywordflow">for</span> ( j = centery - radius ; j <= centery + radius ; j++ )
+<a name="l02181"></a>02181     {
+<a name="l02182"></a>02182         <span class="keywordflow">for</span> ( k = centerx - radius ; k <= centerx + radius ; k++ )
+<a name="l02183"></a>02183         {
+<a name="l02184"></a>02184             <span class="keywordflow">if</span> ( (k-centerx)*(k-centerx)+(j-centery)*(j-centery) <= 
+<a name="l02185"></a>02185                   radius*radius )
+<a name="l02186"></a>02186             {
+<a name="l02187"></a>02187                 n ++ ;
+<a name="l02188"></a>02188             }
+<a name="l02189"></a>02189         }
+<a name="l02190"></a>02190     }
+<a name="l02191"></a>02191     <span class="keywordflow">if</span> (n == 0)
+<a name="l02192"></a>02192     {
+<a name="l02193"></a>02193         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" no data points found!\n"</span>) ;
+<a name="l02194"></a>02194         <span class="keywordflow">return</span> NullVector ;
+<a name="l02195"></a>02195     }
+<a name="l02196"></a>02196     circsize = n ;
+<a name="l02197"></a>02197 
+<a name="l02198"></a>02198     <span class="comment">/* allocate a new sinfo_vector to store the average spectral values */</span>
+<a name="l02199"></a>02199     <span class="keywordflow">if</span> (NULL == (clean = sinfo_new_vector (inp)) )
+<a name="l02200"></a>02200     {
+<a name="l02201"></a>02201         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" cannot allocate a new sinfo_vector \n"</span>) ;
+<a name="l02202"></a>02202         <span class="keywordflow">return</span> NullVector ;
+<a name="l02203"></a>02203     }
+<a name="l02204"></a>02204 
+<a name="l02205"></a>02205     <span class="comment">/*------------------------------------------------------------------------</span>
+<a name="l02206"></a>02206 <span class="comment">     *  loop through the cube planes, through the x axis and the y-axis of the</span>
+<a name="l02207"></a>02207 <span class="comment">     *  plane circle and store pixel values in a buffer.</span>
+<a name="l02208"></a>02208 <span class="comment">     */</span>
+<a name="l02209"></a>02209     <span class="keywordflow">for</span> ( i = 0 ; i < inp ; i++ )
+<a name="l02210"></a>02210     {
+<a name="l02211"></a>02211       i_img=cpl_imagelist_get(cube,i);
+<a name="l02212"></a>02212       pidata=cpl_image_get_data_float(i_img);
+<a name="l02213"></a>02213         m = 0 ;
+<a name="l02214"></a>02214         circle = (pixelvalue *) cpl_calloc (circsize, <span class="keyword">sizeof</span> (pixelvalue*));
+<a name="l02215"></a>02215 
+<a name="l02216"></a>02216         <span class="keywordflow">for</span> ( j = centery - radius ; j <= centery + radius ; j++ )
+<a name="l02217"></a>02217         {
+<a name="l02218"></a>02218             <span class="keywordflow">for</span> ( k = centerx - radius ; k <= centerx + radius ; k++ )
+<a name="l02219"></a>02219             {
+<a name="l02220"></a>02220                 <span class="keywordflow">if</span> ( (k-centerx)*(k-centerx)+(j-centery)*(j-centery) <= 
+<a name="l02221"></a>02221                      radius*radius )
+<a name="l02222"></a>02222                 {
+<a name="l02223"></a>02223                     circle[m] = pidata[k + j * ilx] ;
+<a name="l02224"></a>02224                     m ++ ;
+<a name="l02225"></a>02225                 }
+<a name="l02226"></a>02226             }
+<a name="l02227"></a>02227         }
+<a name="l02228"></a>02228 
+<a name="l02229"></a>02229         nv = 0 ;
+<a name="l02230"></a>02230         <span class="keywordflow">for</span> ( l = 0 ; l < circsize ; l++ )
+<a name="l02231"></a>02231         {
+<a name="l02232"></a>02232             <span class="keywordflow">if</span> ( isnan(circle[l]) )
+<a name="l02233"></a>02233             {
+<a name="l02234"></a>02234                 continue ;
+<a name="l02235"></a>02235             }
+<a name="l02236"></a>02236             clean -> data[i] += circle[l] ;
+<a name="l02237"></a>02237             nv ++;
+<a name="l02238"></a>02238         }
+<a name="l02239"></a>02239         <span class="keywordflow">if</span> ( nv == 0 )
+<a name="l02240"></a>02240         {
+<a name="l02241"></a>02241             clean->data[i] = 0. ;
+<a name="l02242"></a>02242         }
+<a name="l02243"></a>02243         <span class="keywordflow">else</span>
+<a name="l02244"></a>02244         {
+<a name="l02245"></a>02245             clean->data[i] = sinfo_new_clean_mean(circle, nv, 
+<a name="l02246"></a>02246                                                   lo_reject, hi_reject) ; 
+<a name="l02247"></a>02247         }
+<a name="l02248"></a>02248         cpl_free (circle) ;
+<a name="l02249"></a>02249     }
+<a name="l02250"></a>02250     <span class="keywordflow">return</span> clean ;
+<a name="l02251"></a>02251 }
+<a name="l02252"></a>02252 
+<a name="l02264"></a>02264 <span class="keywordtype">float</span> * 
+<a name="l02265"></a>02265 sinfo_new_shift_array ( <span class="keywordtype">float</span> * input, <span class="keywordtype">int</span> n_elements, 
+<a name="l02266"></a>02266                         <span class="keywordtype">float</span> shift, <span class="keywordtype">double</span> * ker ) 
+<a name="l02267"></a>02267 {
+<a name="l02268"></a>02268     <span class="keywordtype">float</span>  *         shifted ;
+<a name="l02269"></a>02269     <span class="keywordtype">int</span>              samples = KERNEL_SAMPLES ;
+<a name="l02270"></a>02270     <span class="keywordtype">int</span>           i ;
+<a name="l02271"></a>02271     <span class="keywordtype">float</span>            fx ;
+<a name="l02272"></a>02272     <span class="keywordtype">float</span>            rx ;
+<a name="l02273"></a>02273     <span class="keywordtype">int</span>              px ;
+<a name="l02274"></a>02274     <span class="keywordtype">int</span>              tabx ;
+<a name="l02275"></a>02275     <span class="keywordtype">float</span>            value ;
+<a name="l02276"></a>02276     <span class="comment">/*size_t           pos ;*/</span>
+<a name="l02277"></a>02277     <span class="keyword">register</span> <span class="keywordtype">float</span> * pix ;
+<a name="l02278"></a>02278     <span class="keywordtype">int</span>              mid;
+<a name="l02279"></a>02279     <span class="keywordtype">float</span>            norm ;
+<a name="l02280"></a>02280 
+<a name="l02281"></a>02281     <span class="comment">/* error handling: test entries */</span>
+<a name="l02282"></a>02282     <span class="keywordflow">if</span> (input==NULL) 
+<a name="l02283"></a>02283     {
+<a name="l02284"></a>02284         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" no input array given!\n"</span>) ;
+<a name="l02285"></a>02285         <span class="keywordflow">return</span> NULL ;
+<a name="l02286"></a>02286     }
+<a name="l02287"></a>02287     <span class="keywordflow">if</span> (n_elements<=0) 
+<a name="l02288"></a>02288     {
+<a name="l02289"></a>02289         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" wrong number of elements in input array given!\n"</span>) ;
+<a name="l02290"></a>02290         <span class="keywordflow">return</span> NULL ;
+<a name="l02291"></a>02291     }
+<a name="l02292"></a>02292 
+<a name="l02293"></a>02293     shifted    = (<span class="keywordtype">float</span>*) cpl_calloc(n_elements, <span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l02294"></a>02294 
+<a name="l02295"></a>02295     <span class="comment">/* Shifting by a zero offset returns a copy of the input image */</span>
+<a name="l02296"></a>02296     <span class="keywordflow">if</span> ((fabs(shift)<1e-2))
+<a name="l02297"></a>02297     {
+<a name="l02298"></a>02298         <span class="keywordflow">for</span> (i = 0 ; i <  n_elements ; i++ )
+<a name="l02299"></a>02299         {
+<a name="l02300"></a>02300             shifted[i] = input[i] ;
+<a name="l02301"></a>02301         }
+<a name="l02302"></a>02302         <span class="keywordflow">return</span> shifted ;
+<a name="l02303"></a>02303     }
+<a name="l02304"></a>02304     
+<a name="l02305"></a>02305     mid = (int)samples/(<span class="keywordtype">int</span>)2 ;
+<a name="l02306"></a>02306 
+<a name="l02307"></a>02307     <span class="keywordflow">for</span> (i=1 ; i<  n_elements-2 ; i++) 
+<a name="l02308"></a>02308     {
+<a name="l02309"></a>02309         fx = (float)i+shift ;
+<a name="l02310"></a>02310         px = sinfo_new_nint(fx) ;
+<a name="l02311"></a>02311         rx = fx - (float)px ;
+<a name="l02312"></a>02312         pix = input ;
+<a name="l02313"></a>02313 
+<a name="l02314"></a>02314         <span class="keywordflow">if</span> ((px>=1) && (px<(n_elements-2))) 
+<a name="l02315"></a>02315         {
+<a name="l02316"></a>02316             tabx = (int)(fabs((<span class="keywordtype">float</span>)mid * rx)) ;
+<a name="l02317"></a>02317             <span class="comment">/* exclude blank (ZERO) pixels from interpolation */</span>
+<a name="l02318"></a>02318             <span class="keywordflow">if</span> (isnan(pix[i]))
+<a name="l02319"></a>02319             {
+<a name="l02320"></a>02320                 value = ZERO ;
+<a name="l02321"></a>02321             }
+<a name="l02322"></a>02322             <span class="keywordflow">else</span>
+<a name="l02323"></a>02323             {
+<a name="l02324"></a>02324                 <span class="keywordflow">if</span> (isnan(pix[i-1]))
+<a name="l02325"></a>02325                 {
+<a name="l02326"></a>02326                     pix[i-1] = 0. ;
+<a name="l02327"></a>02327                 }
+<a name="l02328"></a>02328                 <span class="keywordflow">if</span> (isnan(pix[i+1]))
+<a name="l02329"></a>02329                 {
+<a name="l02330"></a>02330                     pix[i+1] = 0. ;
+<a name="l02331"></a>02331                 }
+<a name="l02332"></a>02332                 <span class="keywordflow">if</span> (isnan(pix[i+2]))
+<a name="l02333"></a>02333                 {
+<a name="l02334"></a>02334                     pix[i+2] = 0. ;
+<a name="l02335"></a>02335                 }
+<a name="l02336"></a>02336 
+<a name="l02337"></a>02337                 <span class="comment">/*</span>
+<a name="l02338"></a>02338 <span class="comment">                 * Sum up over 4 closest pixel values,</span>
+<a name="l02339"></a>02339 <span class="comment">                 * weighted by interpolation kernel values</span>
+<a name="l02340"></a>02340 <span class="comment">                 */</span>
+<a name="l02341"></a>02341                 value =     pix[i-1] * ker[mid+tabx] +
+<a name="l02342"></a>02342                             pix[i] *   ker[tabx] +
+<a name="l02343"></a>02343                             pix[i+1] * ker[mid-tabx] +
+<a name="l02344"></a>02344                             pix[i+2] * ker[samples-tabx-1] ;
+<a name="l02345"></a>02345                 <span class="comment">/*</span>
+<a name="l02346"></a>02346 <span class="comment">                 * Also sum up interpolation kernel coefficients</span>
+<a name="l02347"></a>02347 <span class="comment">                 * for further normalization</span>
+<a name="l02348"></a>02348 <span class="comment">                 */</span>
+<a name="l02349"></a>02349                 norm =      ker[mid+tabx] +
+<a name="l02350"></a>02350                             ker[tabx] +
+<a name="l02351"></a>02351                             ker[mid-tabx] +
+<a name="l02352"></a>02352                             ker[samples-tabx-1] ;
+<a name="l02353"></a>02353                 <span class="keywordflow">if</span> (fabs(norm) > 1e-4) 
+<a name="l02354"></a>02354                 {
+<a name="l02355"></a>02355                     value /= norm ;
+<a name="l02356"></a>02356                 }
+<a name="l02357"></a>02357             }
+<a name="l02358"></a>02358         }   
+<a name="l02359"></a>02359         <span class="keywordflow">else</span> 
+<a name="l02360"></a>02360         {
+<a name="l02361"></a>02361             value = 0.0 ;
+<a name="l02362"></a>02362         }
+<a name="l02363"></a>02363         <span class="keywordflow">if</span> ( isnan(value) )
+<a name="l02364"></a>02364         {
+<a name="l02365"></a>02365             shifted[i] = ZERO ;
+<a name="l02366"></a>02366         }
+<a name="l02367"></a>02367         <span class="keywordflow">else</span>
+<a name="l02368"></a>02368         {
+<a name="l02369"></a>02369             shifted[i] = value ;
+<a name="l02370"></a>02370         }
+<a name="l02371"></a>02371     }  
+<a name="l02372"></a>02372     <span class="keywordflow">return</span> shifted ;
+<a name="l02373"></a>02373 }
+<a name="l02374"></a>02374 
+<a name="l02375"></a>02375 
+<a name="l02376"></a>02376 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l02377"></a>02377 
+<a name="l02389"></a>02389 cpl_image * 
+<a name="l02390"></a>02390 sinfo_new_div_image_by_spectrum( cpl_image * image, cpl_image * spectrum )
+<a name="l02391"></a>02391 {
+<a name="l02392"></a>02392     <span class="keywordtype">int</span> col, row ;
+<a name="l02393"></a>02393     cpl_image * retImage ;
+<a name="l02394"></a>02394     <span class="keywordtype">int</span> ilx=0;
+<a name="l02395"></a>02395     <span class="keywordtype">int</span> ily=0;
+<a name="l02396"></a>02396 
+<a name="l02397"></a>02397     <span class="keywordtype">int</span> slx=0;
+<a name="l02398"></a>02398     <span class="keywordtype">int</span> sly=0;
+<a name="l02399"></a>02399 
+<a name="l02400"></a>02400     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l02401"></a>02401     <span class="keywordtype">float</span>* psdata=NULL;
+<a name="l02402"></a>02402     <span class="keywordtype">float</span>* podata=NULL;
+<a name="l02403"></a>02403 
+<a name="l02404"></a>02404     <span class="keywordflow">if</span> ( image == NULL )
+<a name="l02405"></a>02405     {
+<a name="l02406"></a>02406         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no image given!"</span>) ;
+<a name="l02407"></a>02407         <span class="keywordflow">return</span> NULL ;
+<a name="l02408"></a>02408     }
+<a name="l02409"></a>02409     ilx=cpl_image_get_size_x(image);
+<a name="l02410"></a>02410     ily=cpl_image_get_size_y(image);
+<a name="l02411"></a>02411 
+<a name="l02412"></a>02412 
+<a name="l02413"></a>02413     <span class="keywordflow">if</span> ( spectrum == NULL )
+<a name="l02414"></a>02414     {
+<a name="l02415"></a>02415         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no spectrum image given!"</span>) ;
+<a name="l02416"></a>02416         <span class="keywordflow">return</span> NULL ;
+<a name="l02417"></a>02417     }
+<a name="l02418"></a>02418     slx=cpl_image_get_size_x(spectrum);
+<a name="l02419"></a>02419     sly=cpl_image_get_size_y(spectrum);
+<a name="l02420"></a>02420 
+<a name="l02421"></a>02421     <span class="keywordflow">if</span> ( sly != ily )
+<a name="l02422"></a>02422     {
+<a name="l02423"></a>02423         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"images are not compatible in pixel length!"</span>) ;
+<a name="l02424"></a>02424         <span class="keywordflow">return</span> NULL ;
+<a name="l02425"></a>02425     }
+<a name="l02426"></a>02426     <span class="keywordflow">if</span> ( NULL == (retImage = cpl_image_duplicate(image)) )
+<a name="l02427"></a>02427     {
+<a name="l02428"></a>02428         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"could not copy original image!"</span>) ;
+<a name="l02429"></a>02429         <span class="keywordflow">return</span> NULL ;
+<a name="l02430"></a>02430     }
+<a name="l02431"></a>02431     pidata=cpl_image_get_data_float(image);
+<a name="l02432"></a>02432     psdata=cpl_image_get_data_float(spectrum);
+<a name="l02433"></a>02433     podata=cpl_image_get_data_float(retImage);
+<a name="l02434"></a>02434 
+<a name="l02435"></a>02435     <span class="keywordflow">for</span> ( col = 0 ; col < ilx ; col++ )
+<a name="l02436"></a>02436     {
+<a name="l02437"></a>02437         <span class="keywordflow">for</span> ( row = 0 ; row < ily ; row++ )
+<a name="l02438"></a>02438         {
+<a name="l02439"></a>02439             <span class="keywordflow">if</span> ( !isnan(pidata[col+row*ilx]) &&
+<a name="l02440"></a>02440                  !isnan(psdata[col+row*ilx]))
+<a name="l02441"></a>02441             {
+<a name="l02442"></a>02442                 podata[col+row*ilx] = pidata[col+row*ilx] / psdata[row] ;
+<a name="l02443"></a>02443             }
+<a name="l02444"></a>02444          }
+<a name="l02445"></a>02445     }
+<a name="l02446"></a>02446     <span class="keywordflow">return</span> retImage ;
+<a name="l02447"></a>02447 }
+<a name="l02448"></a>02448 
+<a name="l02449"></a>02449 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l02450"></a>02450 <span class="comment">   Function     :       sinfo_new_clean_mean_circle_of_cube_spectra()</span>
+<a name="l02451"></a>02451 <span class="comment">   In           :       cube: 1 allocated cube, </span>
+<a name="l02452"></a>02452 <span class="comment">                        centerx, centery: center pixel of circular aperture </span>
+<a name="l02453"></a>02453 <span class="comment">                                          in image coordinates</span>
+<a name="l02454"></a>02454 <span class="comment">                        radius: integer radius of circular aperture</span>
+<a name="l02455"></a>02455 <span class="comment">   Out          :       result spectrum vector</span>
+<a name="l02456"></a>02456 <span class="comment">   Job          :       clean averaging routine for a reduced data to get </span>
+<a name="l02457"></a>02457 <span class="comment">                        a better spectral S/N only for a circular aperture.</span>
+<a name="l02458"></a>02458 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l02459"></a>02459 
+<a name="l02460"></a>02460 Vector * sinfo_new_clean_mean_circle_of_cube_spectra(cpl_imagelist * cube,
+<a name="l02461"></a>02461                                   <span class="keywordtype">int</span>       centerx,
+<a name="l02462"></a>02462                                   <span class="keywordtype">int</span>       centery,
+<a name="l02463"></a>02463                                   <span class="keywordtype">int</span>       radius,
+<a name="l02464"></a>02464                                   <span class="keywordtype">float</span>     lo_reject,
+<a name="l02465"></a>02465                                   <span class="keywordtype">float</span>     hi_reject )
+<a name="l02466"></a>02466 {
+<a name="l02467"></a>02467     Vector          * clean ;
+<a name="l02468"></a>02468     pixelvalue      * circle ;
+<a name="l02469"></a>02469     <span class="keywordtype">int</span>             i, j, k, l, m, n ;
+<a name="l02470"></a>02470     <span class="keywordtype">int</span>             circsize, nv ;
+<a name="l02471"></a>02471     <span class="keywordtype">int</span> lx=0;
+<a name="l02472"></a>02472     <span class="keywordtype">int</span> ly=0;
+<a name="l02473"></a>02473     <span class="keywordtype">int</span> lz=0;
+<a name="l02474"></a>02474     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l02475"></a>02475     cpl_image* img=NULL;
+<a name="l02476"></a>02476 
+<a name="l02477"></a>02477     lz=cpl_imagelist_get_size(cube);
+<a name="l02478"></a>02478 
+<a name="l02479"></a>02479     <span class="keywordflow">if</span> ( cube == NULL || lz < 1 )
+<a name="l02480"></a>02480     {
+<a name="l02481"></a>02481         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" no cube to take the mean of his spectra"</span>) ;
+<a name="l02482"></a>02482         <span class="keywordflow">return</span> NullVector ;
+<a name="l02483"></a>02483     }
+<a name="l02484"></a>02484     img=cpl_imagelist_get(cube,0);
+<a name="l02485"></a>02485     lx=cpl_image_get_size_x(img);
+<a name="l02486"></a>02486     ly=cpl_image_get_size_y(img);
+<a name="l02487"></a>02487 
+<a name="l02488"></a>02488     <span class="keywordflow">if</span> ((centerx+radius>=lx) ||
+<a name="l02489"></a>02489         (centery+radius>=ly) ||
+<a name="l02490"></a>02490         (centerx-radius<0) ||
+<a name="l02491"></a>02491         (centery-radius<0))
+<a name="l02492"></a>02492     {
+<a name="l02493"></a>02493         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" invalid circular coordinates"</span>) ;
+<a name="l02494"></a>02494         <span class="keywordflow">return</span> NullVector ;
+<a name="l02495"></a>02495     }
+<a name="l02496"></a>02496 
+<a name="l02497"></a>02497     n = 0 ;
+<a name="l02498"></a>02498     <span class="keywordflow">for</span> ( j = centery - radius ; j <= centery + radius ; j++ )
+<a name="l02499"></a>02499     {
+<a name="l02500"></a>02500         <span class="keywordflow">for</span> ( k = centerx - radius ; k <= centerx + radius ; k++ )
+<a name="l02501"></a>02501         {
+<a name="l02502"></a>02502             <span class="keywordflow">if</span> ( (k-centerx)*(k-centerx)+(j-centery)*(j-centery) <= 
+<a name="l02503"></a>02503                  radius*radius )
+<a name="l02504"></a>02504             {
+<a name="l02505"></a>02505                 n ++ ;
+<a name="l02506"></a>02506             }
+<a name="l02507"></a>02507         }
+<a name="l02508"></a>02508     }
+<a name="l02509"></a>02509     <span class="keywordflow">if</span> (n == 0)
+<a name="l02510"></a>02510     {
+<a name="l02511"></a>02511         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" no data points found!"</span>) ;
+<a name="l02512"></a>02512         <span class="keywordflow">return</span> NullVector ;
+<a name="l02513"></a>02513     }
+<a name="l02514"></a>02514     circsize = n ;
+<a name="l02515"></a>02515 
+<a name="l02516"></a>02516     <span class="comment">/* allocate a new vector to store the average spectral values */</span>
+<a name="l02517"></a>02517     <span class="keywordflow">if</span> (NULL == (clean = sinfo_new_vector (lz)) )
+<a name="l02518"></a>02518     {
+<a name="l02519"></a>02519         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" cannot allocate a new vector"</span>) ;
+<a name="l02520"></a>02520         <span class="keywordflow">return</span> NullVector ;
+<a name="l02521"></a>02521     }
+<a name="l02522"></a>02522 
+<a name="l02523"></a>02523     <span class="comment">/*------------------------------------------------------------------------</span>
+<a name="l02524"></a>02524 <span class="comment">     *  loop through the cube planes, through the x axis and the y-axis of the</span>
+<a name="l02525"></a>02525 <span class="comment">     *  plane circle and store pixel values in a buffer.</span>
+<a name="l02526"></a>02526 <span class="comment">     */</span>
+<a name="l02527"></a>02527     <span class="keywordflow">for</span> ( i = 0 ; i < lz ; i++ )
+<a name="l02528"></a>02528     {
+<a name="l02529"></a>02529       img=cpl_imagelist_get(cube,i);
+<a name="l02530"></a>02530       pidata=cpl_image_get_data(img);
+<a name="l02531"></a>02531       m = 0 ;
+<a name="l02532"></a>02532       circle = (pixelvalue *) cpl_calloc (circsize, <span class="keyword">sizeof</span> (pixelvalue*));
+<a name="l02533"></a>02533 
+<a name="l02534"></a>02534       <span class="keywordflow">for</span> ( j = centery - radius ; j <= centery + radius ; j++ )
+<a name="l02535"></a>02535         {
+<a name="l02536"></a>02536             <span class="keywordflow">for</span> ( k = centerx - radius ; k <= centerx + radius ; k++ )
+<a name="l02537"></a>02537             {
+<a name="l02538"></a>02538                 <span class="keywordflow">if</span> ( (k-centerx)*(k-centerx)+(j-centery)*(j-centery) <= 
+<a name="l02539"></a>02539                      radius*radius )
+<a name="l02540"></a>02540                 {
+<a name="l02541"></a>02541                      circle[m] = pidata[k + j * lx] ;
+<a name="l02542"></a>02542                     m ++ ;
+<a name="l02543"></a>02543                 }
+<a name="l02544"></a>02544             }
+<a name="l02545"></a>02545         }
+<a name="l02546"></a>02546 
+<a name="l02547"></a>02547         nv = 0 ;
+<a name="l02548"></a>02548         <span class="keywordflow">for</span> ( l = 0 ; l < circsize ; l++ )
+<a name="l02549"></a>02549         {
+<a name="l02550"></a>02550             <span class="keywordflow">if</span> ( isnan(circle[l]) )
+<a name="l02551"></a>02551             {
+<a name="l02552"></a>02552                 continue ;
+<a name="l02553"></a>02553             }
+<a name="l02554"></a>02554             clean -> data[i] += circle[l] ;
+<a name="l02555"></a>02555             nv ++;
+<a name="l02556"></a>02556         }
+<a name="l02557"></a>02557         <span class="keywordflow">if</span> ( nv == 0 )
+<a name="l02558"></a>02558         {
+<a name="l02559"></a>02559             clean->data[i] = 0. ;
+<a name="l02560"></a>02560         }
+<a name="l02561"></a>02561         <span class="keywordflow">else</span>
+<a name="l02562"></a>02562         {
+<a name="l02563"></a>02563             clean->data[i] = sinfo_new_clean_mean(circle, nv, 
+<a name="l02564"></a>02564                                                   lo_reject, hi_reject) ; 
+<a name="l02565"></a>02565         }
+<a name="l02566"></a>02566         cpl_free (circle) ;
+<a name="l02567"></a>02567     }
+<a name="l02568"></a>02568     <span class="keywordflow">return</span> clean ;
+<a name="l02569"></a>02569 }
+<a name="l02570"></a>02570 
+<a name="l02571"></a>02571 
+<a name="l02572"></a>02572 
+<a name="l02573"></a>02573 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l02574"></a>02574 <span class="comment">   Function     :       sinfo_new_clean_mean_rectangle_of_cube_spectra()</span>
+<a name="l02575"></a>02575 <span class="comment">   In           :       cube: 1 allocated cube, </span>
+<a name="l02576"></a>02576 <span class="comment">                        llx, lly, urx, ury: lower left and upper right</span>
+<a name="l02577"></a>02577 <span class="comment">                                            position of rectangle in x-y plane ,</span>
+<a name="l02578"></a>02578 <span class="comment">                                            image coordinates 0...</span>
+<a name="l02579"></a>02579 <span class="comment">   Out          :       result spectrum vector</span>
+<a name="l02580"></a>02580 <span class="comment">   Job          :       clean averaging routine for a reduced data to get a</span>
+<a name="l02581"></a>02581 <span class="comment">                        better spectral S/N only for a rectangular aperture.</span>
+<a name="l02582"></a>02582 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l02583"></a>02583 
+<a name="l02584"></a>02584 Vector * sinfo_new_clean_mean_rectangle_of_cube_spectra( cpl_imagelist * cube,
+<a name="l02585"></a>02585                                           <span class="keywordtype">int</span> llx,
+<a name="l02586"></a>02586                                           <span class="keywordtype">int</span> lly,
+<a name="l02587"></a>02587                                           <span class="keywordtype">int</span> urx,
+<a name="l02588"></a>02588                                           <span class="keywordtype">int</span> ury,
+<a name="l02589"></a>02589                                           <span class="keywordtype">float</span> lo_reject,
+<a name="l02590"></a>02590                                           <span class="keywordtype">float</span> hi_reject )
+<a name="l02591"></a>02591 {
+<a name="l02592"></a>02592     Vector          * clean ;
+<a name="l02593"></a>02593     pixelvalue      *rectangle ;
+<a name="l02594"></a>02594     <span class="keywordtype">int</span>             i, j, k, m ;
+<a name="l02595"></a>02595     <span class="keywordtype">int</span>             recsize ;
+<a name="l02596"></a>02596     <span class="keywordtype">int</span> lx=0;
+<a name="l02597"></a>02597     <span class="keywordtype">int</span> ly=0;
+<a name="l02598"></a>02598     <span class="keywordtype">int</span> lz=0;
+<a name="l02599"></a>02599     <span class="keywordtype">float</span>* pidata=0;
+<a name="l02600"></a>02600     cpl_image* img=NULL;
+<a name="l02601"></a>02601 
+<a name="l02602"></a>02602     lz=cpl_imagelist_get_size(cube);
+<a name="l02603"></a>02603 
+<a name="l02604"></a>02604     <span class="keywordflow">if</span> ( cube == NULL || lz < 1 )
+<a name="l02605"></a>02605     {
+<a name="l02606"></a>02606         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" no cube to take the mean of his spectra"</span>) ;
+<a name="l02607"></a>02607         <span class="keywordflow">return</span> NullVector ;
+<a name="l02608"></a>02608     }
+<a name="l02609"></a>02609     img=cpl_imagelist_get(cube,0);
+<a name="l02610"></a>02610     lx=cpl_image_get_size_x(img);
+<a name="l02611"></a>02611     ly=cpl_image_get_size_y(img);
+<a name="l02612"></a>02612 
+<a name="l02613"></a>02613     <span class="keywordflow">if</span> ((llx<0) || (llx>=lx) ||
+<a name="l02614"></a>02614         (urx<0) || (urx>=lx) ||
+<a name="l02615"></a>02615         (lly<0) || (lly>=ly) ||
+<a name="l02616"></a>02616         (ury<0) || (ury>=ly) ||
+<a name="l02617"></a>02617         (llx>=urx) || (lly>=ury))
+<a name="l02618"></a>02618     {
+<a name="l02619"></a>02619         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" invalid rectangle coordinates:"</span>) ;
+<a name="l02620"></a>02620         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"lower left is [%d %d] upper right is [%d %d]"</span>,
+<a name="l02621"></a>02621                  llx, lly, urx, ury) ;
+<a name="l02622"></a>02622         <span class="keywordflow">return</span> NullVector ;
+<a name="l02623"></a>02623     }
+<a name="l02624"></a>02624 
+<a name="l02625"></a>02625     recsize = (urx - llx + 1) * (ury - lly + 1) ;
+<a name="l02626"></a>02626 
+<a name="l02627"></a>02627     <span class="comment">/* allocate a new vector to store the average spectral values */</span>
+<a name="l02628"></a>02628     <span class="keywordflow">if</span> (NULL == (clean = sinfo_new_vector (lz)) )
+<a name="l02629"></a>02629     {
+<a name="l02630"></a>02630         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" cannot allocate a new vector"</span>) ;
+<a name="l02631"></a>02631         <span class="keywordflow">return</span> NullVector ;
+<a name="l02632"></a>02632     }
+<a name="l02633"></a>02633 
+<a name="l02634"></a>02634     <span class="comment">/*------------------------------------------------------------------------</span>
+<a name="l02635"></a>02635 <span class="comment">     *  loop through the cube planes, through the x axis and the y-axis of the</span>
+<a name="l02636"></a>02636 <span class="comment">     *  plane rectangle and store pixel values in a buffer.</span>
+<a name="l02637"></a>02637 <span class="comment">     */</span>
+<a name="l02638"></a>02638     <span class="keywordflow">for</span> ( i = 0 ; i < lz ; i++ )
+<a name="l02639"></a>02639     {
+<a name="l02640"></a>02640         m = 0 ;
+<a name="l02641"></a>02641         rectangle = (pixelvalue *) cpl_calloc (recsize, <span class="keyword">sizeof</span> (pixelvalue*));
+<a name="l02642"></a>02642         img=cpl_imagelist_get(cube,i);
+<a name="l02643"></a>02643         pidata=cpl_image_get_data(img);
+<a name="l02644"></a>02644         <span class="keywordflow">for</span> ( j = lly ; j <= ury ; j++ )
+<a name="l02645"></a>02645         {
+<a name="l02646"></a>02646             <span class="keywordflow">for</span> ( k = llx ; k <= urx ; k++ )
+<a name="l02647"></a>02647             {
+<a name="l02648"></a>02648                 <span class="keywordflow">if</span> ( isnan(pidata[k+j*lx]) )
+<a name="l02649"></a>02649                 {
+<a name="l02650"></a>02650                     continue ;
+<a name="l02651"></a>02651                 }
+<a name="l02652"></a>02652                 <span class="keywordflow">else</span>
+<a name="l02653"></a>02653                 {
+<a name="l02654"></a>02654                     rectangle[m] = pidata[k + j * lx] ;
+<a name="l02655"></a>02655                     m ++ ;
+<a name="l02656"></a>02656                 }
+<a name="l02657"></a>02657             }
+<a name="l02658"></a>02658         }
+<a name="l02659"></a>02659         <span class="keywordflow">if</span> ( m == 0 )
+<a name="l02660"></a>02660         {
+<a name="l02661"></a>02661             clean->data[i] = 0. ;
+<a name="l02662"></a>02662         }
+<a name="l02663"></a>02663         <span class="keywordflow">else</span>
+<a name="l02664"></a>02664         {
+<a name="l02665"></a>02665             clean->data[i] = sinfo_new_clean_mean(rectangle, m, 
+<a name="l02666"></a>02666                                                   lo_reject, hi_reject) ;
+<a name="l02667"></a>02667         }
+<a name="l02668"></a>02668         cpl_free ( rectangle ) ;
+<a name="l02669"></a>02669     }
+<a name="l02670"></a>02670     <span class="keywordflow">return</span> clean ;
+<a name="l02671"></a>02671 }
+<a name="l02672"></a>02672 
+<a name="l02673"></a>02673 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__spectrum__ops_8h_source.html b/html/sinfo__spectrum__ops_8h_source.html
new file mode 100644
index 0000000..0c047da
--- /dev/null
+++ b/html/sinfo__spectrum__ops_8h_source.html
@@ -0,0 +1,210 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_spectrum_ops.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_spectrum_ops.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#ifndef SINFO_SPECTRUM_OPS_H</span>
+<a name="l00002"></a>00002 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_SPECTRUM_OPS_H</span>
+<a name="l00003"></a>00003 <span class="preprocessor"></span><span class="comment">/*</span>
+<a name="l00004"></a>00004 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00005"></a>00005 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00006"></a>00006 <span class="comment"> *</span>
+<a name="l00007"></a>00007 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00008"></a>00008 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00009"></a>00009 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00010"></a>00010 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00011"></a>00011 <span class="comment"> *</span>
+<a name="l00012"></a>00012 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00013"></a>00013 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00014"></a>00014 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00015"></a>00015 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00016"></a>00016 <span class="comment"> *</span>
+<a name="l00017"></a>00017 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00018"></a>00018 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00019"></a>00019 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00020"></a>00020 <span class="comment"> */</span>
+<a name="l00021"></a>00021 
+<a name="l00022"></a>00022 <span class="comment">/************************************************************************</span>
+<a name="l00023"></a>00023 <span class="comment">* E.S.O. - VLT project</span>
+<a name="l00024"></a>00024 <span class="comment">*</span>
+<a name="l00025"></a>00025 <span class="comment">* "@(#) $Id: sinfo_spectrum_ops.h,v 1.4 2007/06/06 07:10:45 amodigli Exp $"</span>
+<a name="l00026"></a>00026 <span class="comment">*</span>
+<a name="l00027"></a>00027 <span class="comment">* who       when      what</span>
+<a name="l00028"></a>00028 <span class="comment">* --------  --------  ----------------------------------------------</span>
+<a name="l00029"></a>00029 <span class="comment">* schreib  25/05/00  created</span>
+<a name="l00030"></a>00030 <span class="comment">*/</span>
+<a name="l00031"></a>00031 
+<a name="l00032"></a>00032 <span class="comment">/************************************************************************</span>
+<a name="l00033"></a>00033 <span class="comment"> * sinfo_spectrum_ops.h</span>
+<a name="l00034"></a>00034 <span class="comment"> * spectral sinfo_vector routines</span>
+<a name="l00035"></a>00035 <span class="comment"> *----------------------------------------------------------------------</span>
+<a name="l00036"></a>00036 <span class="comment"> */</span>
+<a name="l00037"></a>00037 
+<a name="l00038"></a>00038 <span class="preprocessor">#define  SPEED_OF_LIGHT 2.99792458e8</span>
+<a name="l00039"></a>00039 <span class="preprocessor"></span><span class="preprocessor">#define  PLANCK            6.62606876e-34</span>
+<a name="l00040"></a>00040 <span class="preprocessor"></span><span class="preprocessor">#define  BOLTZMANN      1.3806503e-23</span>
+<a name="l00041"></a>00041 <span class="preprocessor"></span>
+<a name="l00042"></a>00042 <span class="comment">/*</span>
+<a name="l00043"></a>00043 <span class="comment"> * header files</span>
+<a name="l00044"></a>00044 <span class="comment"> */</span>
+<a name="l00045"></a>00045 
+<a name="l00046"></a>00046 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00047"></a>00047 <span class="preprocessor">#include "sinfo_focus.h"</span>
+<a name="l00048"></a>00048 <span class="preprocessor">#include "sinfo_recipes.h"</span>
+<a name="l00049"></a>00049 <span class="preprocessor">#include "sinfo_new_cube_ops.h"</span>
+<a name="l00050"></a>00050 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00051"></a>00051 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00052"></a>00052 <span class="comment"> *                        Function ANSI C prototypes</span>
+<a name="l00053"></a>00053 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00054"></a>00054 
+<a name="l00055"></a>00055 
+<a name="l00062"></a>00062 <span class="keywordtype">int</span> 
+<a name="l00063"></a>00063 sinfo_stectrum_ima2table(
+<a name="l00064"></a>00064                  <span class="keyword">const</span> cpl_image* spc,
+<a name="l00065"></a>00065                  <span class="keyword">const</span> <span class="keywordtype">char</span>* filename,
+<a name="l00066"></a>00066                  cpl_table** tbl);
+<a name="l00067"></a>00067 
+<a name="l00081"></a>00081 Vector * 
+<a name="l00082"></a>00082 sinfo_new_cleanmean_rectangle_of_cube_spectra( cpl_imagelist * cube,
+<a name="l00083"></a>00083                                           <span class="keywordtype">int</span> llx,
+<a name="l00084"></a>00084                                           <span class="keywordtype">int</span> lly,
+<a name="l00085"></a>00085                                           <span class="keywordtype">int</span> urx,
+<a name="l00086"></a>00086                                           <span class="keywordtype">int</span> ury,
+<a name="l00087"></a>00087                                           <span class="keywordtype">float</span> lo_reject,
+<a name="l00088"></a>00088                             <span class="keywordtype">float</span> hi_reject );
+<a name="l00100"></a>00100 Vector * 
+<a name="l00101"></a>00101 sinfo_new_cleanmean_circle_of_cube_spectra( cpl_imagelist * cube,
+<a name="l00102"></a>00102                                   <span class="keywordtype">int</span>       centerx,
+<a name="l00103"></a>00103                                   <span class="keywordtype">int</span>       centery,
+<a name="l00104"></a>00104                                   <span class="keywordtype">int</span>       radius,
+<a name="l00105"></a>00105                                   <span class="keywordtype">float</span>     lo_reject,
+<a name="l00106"></a>00106                              <span class="keywordtype">float</span>     hi_reject );
+<a name="l00117"></a>00117 cpl_image * 
+<a name="l00118"></a>00118 sinfo_new_div_image_by_spectrum( cpl_image * image, cpl_image * spectrum ) ;
+<a name="l00119"></a>00119 
+<a name="l00127"></a>00127 <span class="keywordtype">void</span> 
+<a name="l00128"></a>00128 sinfo_free_svector( Vector **svector );
+<a name="l00129"></a>00129 
+<a name="l00137"></a>00137 Vector * 
+<a name="l00138"></a>00138 sinfo_new_vector( ulong32 n_elements ) ;
+<a name="l00139"></a>00139 
+<a name="l00140"></a>00140 
+<a name="l00148"></a>00148 <span class="keywordtype">void</span> 
+<a name="l00149"></a>00149 sinfo_new_destroy_vector( Vector *sinfo_vector ) ;
+<a name="l00150"></a>00150 
+<a name="l00160"></a>00160 cpl_image * 
+<a name="l00161"></a>00161 sinfo_new_vector_to_image( Vector * spectrum ) ;
+<a name="l00162"></a>00162 
+<a name="l00172"></a>00172 Vector * 
+<a name="l00173"></a>00173 sinfo_new_image_to_vector( cpl_image * spectrum ) ;
+<a name="l00174"></a>00174 
+<a name="l00175"></a>00175 
+<a name="l00187"></a>00187 cpl_image * 
+<a name="l00188"></a>00188 sinfo_new_extract_spectrum_from_resampled_flat( cpl_image * resflat,
+<a name="l00189"></a>00189                                              <span class="keywordtype">float</span>      loreject,
+<a name="l00190"></a>00190                                              <span class="keywordtype">float</span>      hireject ) ;
+<a name="l00191"></a>00191 
+<a name="l00202"></a>00202 cpl_image * 
+<a name="l00203"></a>00203 sinfo_new_multiply_image_with_spectrum(cpl_image * image,
+<a name="l00204"></a>00204                                        cpl_image * spectrum ) ;
+<a name="l00205"></a>00205 
+<a name="l00246"></a>00246 cpl_image * 
+<a name="l00247"></a>00247 sinfo_new_optimal_extraction_from_cube( cpl_imagelist * cube,
+<a name="l00248"></a>00248                                       <span class="keywordtype">int</span> llx,
+<a name="l00249"></a>00249                                       <span class="keywordtype">int</span> lly,
+<a name="l00250"></a>00250                                       <span class="keywordtype">int</span> halfbox_x,
+<a name="l00251"></a>00251                                       <span class="keywordtype">int</span> halfbox_y,
+<a name="l00252"></a>00252                                       <span class="keywordtype">float</span> fwhm_factor,
+<a name="l00253"></a>00253                                       <span class="keywordtype">float</span> backvariance,
+<a name="l00254"></a>00254                                       <span class="keywordtype">float</span> sky,
+<a name="l00255"></a>00255                                       <span class="keywordtype">float</span> gain,
+<a name="l00256"></a>00256                                       <span class="keywordtype">float</span> exptime,
+<a name="l00257"></a>00257                                       <span class="keyword">const</span> <span class="keywordtype">char</span>* name,
+<a name="l00258"></a>00258                                       cpl_table** spectrum,
+<a name="l00259"></a>00259                                       <span class="keywordtype">int</span> qc_info,
+<a name="l00260"></a>00260                                       <span class="keywordtype">int</span>* check2) ;
+<a name="l00261"></a>00261 
+<a name="l00285"></a>00285 Vector * 
+<a name="l00286"></a>00286 sinfo_new_extract_sky_from_cube( cpl_imagelist * cube,
+<a name="l00287"></a>00287                              <span class="keywordtype">float</span>     loReject,
+<a name="l00288"></a>00288                              <span class="keywordtype">float</span>     hiReject,
+<a name="l00289"></a>00289                              <span class="keywordtype">int</span>     * position,
+<a name="l00290"></a>00290                              <span class="keywordtype">int</span>       tolerance,
+<a name="l00291"></a>00291                              <span class="keywordtype">int</span>       posindicator ) ;
+<a name="l00292"></a>00292 
+<a name="l00307"></a>00307 Vector * 
+<a name="l00308"></a>00308 sinfo_new_sum_rectangle_of_cube_spectra( cpl_imagelist * cube,
+<a name="l00309"></a>00309                                      <span class="keywordtype">int</span> llx,
+<a name="l00310"></a>00310                                      <span class="keywordtype">int</span> lly,
+<a name="l00311"></a>00311                                      <span class="keywordtype">int</span> urx,
+<a name="l00312"></a>00312                                      <span class="keywordtype">int</span> ury ) ;
+<a name="l00313"></a>00313 
+<a name="l00325"></a>00325 Vector * 
+<a name="l00326"></a>00326 sinfo_new_sum_circle_of_cube_spectra( cpl_imagelist * cube,
+<a name="l00327"></a>00327                                   <span class="keywordtype">int</span>       centerx,
+<a name="l00328"></a>00328                                   <span class="keywordtype">int</span>       centery,
+<a name="l00329"></a>00329                                   <span class="keywordtype">int</span>       radius ) ;
+<a name="l00330"></a>00330 
+<a name="l00331"></a>00331 
+<a name="l00345"></a>00345 Vector * 
+<a name="l00346"></a>00346 sinfo_new_mean_rectangle_of_cube_spectra( cpl_imagelist * cube,
+<a name="l00347"></a>00347                                      <span class="keywordtype">int</span> llx,
+<a name="l00348"></a>00348                                      <span class="keywordtype">int</span> lly,
+<a name="l00349"></a>00349                                      <span class="keywordtype">int</span> urx,
+<a name="l00350"></a>00350                                      <span class="keywordtype">int</span> ury ) ;
+<a name="l00351"></a>00351 
+<a name="l00363"></a>00363 Vector * 
+<a name="l00364"></a>00364 sinfo_new_mean_circle_of_cube_spectra( cpl_imagelist * cube,
+<a name="l00365"></a>00365                                   <span class="keywordtype">int</span>       centerx,
+<a name="l00366"></a>00366                                   <span class="keywordtype">int</span>       centery,
+<a name="l00367"></a>00367                                   <span class="keywordtype">int</span>       radius ) ;
+<a name="l00368"></a>00368 
+<a name="l00379"></a>00379 Vector * 
+<a name="l00380"></a>00380 sinfo_new_blackbody_spectrum( <span class="keywordtype">char</span> * templateSpec, <span class="keywordtype">double</span> temp ) ;
+<a name="l00381"></a>00381 
+<a name="l00395"></a>00395 Vector * 
+<a name="l00396"></a>00396 sinfo_new_median_rectangle_of_cube_spectra( cpl_imagelist * cube,
+<a name="l00397"></a>00397                                              <span class="keywordtype">int</span> llx,
+<a name="l00398"></a>00398                                              <span class="keywordtype">int</span> lly,
+<a name="l00399"></a>00399                                              <span class="keywordtype">int</span> urx,
+<a name="l00400"></a>00400                                              <span class="keywordtype">int</span> ury ) ;
+<a name="l00401"></a>00401 
+<a name="l00413"></a>00413 Vector * 
+<a name="l00414"></a>00414 sinfo_new_median_circle_of_cube_spectra( cpl_imagelist * cube,
+<a name="l00415"></a>00415                                   <span class="keywordtype">int</span>       centerx,
+<a name="l00416"></a>00416                                   <span class="keywordtype">int</span>       centery,
+<a name="l00417"></a>00417                                   <span class="keywordtype">int</span>       radius ) ;
+<a name="l00418"></a>00418 
+<a name="l00419"></a>00419 
+<a name="l00433"></a>00433 Vector * 
+<a name="l00434"></a>00434 sinfo_new_clean_mean_rectangle_of_cube_spectra( cpl_imagelist * cube,
+<a name="l00435"></a>00435                                              <span class="keywordtype">int</span> llx,
+<a name="l00436"></a>00436                                              <span class="keywordtype">int</span> lly,
+<a name="l00437"></a>00437                                              <span class="keywordtype">int</span> urx,
+<a name="l00438"></a>00438                                              <span class="keywordtype">int</span> ury,
+<a name="l00439"></a>00439                                              <span class="keywordtype">float</span> lo_reject,
+<a name="l00440"></a>00440                                              <span class="keywordtype">float</span> hi_reject ) ;
+<a name="l00441"></a>00441 
+<a name="l00453"></a>00453 Vector * 
+<a name="l00454"></a>00454 sinfo_new_clean_mean_circle_of_cube_spectra( cpl_imagelist * cube,
+<a name="l00455"></a>00455                                   <span class="keywordtype">int</span>       centerx,
+<a name="l00456"></a>00456                                   <span class="keywordtype">int</span>       centery,
+<a name="l00457"></a>00457                                   <span class="keywordtype">int</span>       radius,
+<a name="l00458"></a>00458                                   <span class="keywordtype">float</span>     lo_reject,
+<a name="l00459"></a>00459                                   <span class="keywordtype">float</span>     hi_reject ) ;
+<a name="l00460"></a>00460 
+<a name="l00472"></a>00472 <span class="keywordtype">float</span> * 
+<a name="l00473"></a>00473 sinfo_new_shift_array(<span class="keywordtype">float</span> * input,<span class="keywordtype">int</span> n_elements,<span class="keywordtype">float</span> shift,<span class="keywordtype">double</span> * ker ) ;
+<a name="l00474"></a>00474 
+<a name="l00475"></a>00475 <span class="preprocessor">#endif </span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__spiffi__types_8h_source.html b/html/sinfo__spiffi__types_8h_source.html
new file mode 100644
index 0000000..e2fcff3
--- /dev/null
+++ b/html/sinfo__spiffi__types_8h_source.html
@@ -0,0 +1,168 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_spiffi_types.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_spiffi_types.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#ifndef SINFO_SPIFFI_TYPES_H</span>
+<a name="l00002"></a>00002 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_SPIFFI_TYPES_H</span>
+<a name="l00003"></a>00003 <span class="preprocessor"></span><span class="comment">/*</span>
+<a name="l00004"></a>00004 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00005"></a>00005 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00006"></a>00006 <span class="comment"> *</span>
+<a name="l00007"></a>00007 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00008"></a>00008 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00009"></a>00009 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00010"></a>00010 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00011"></a>00011 <span class="comment"> *</span>
+<a name="l00012"></a>00012 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00013"></a>00013 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00014"></a>00014 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00015"></a>00015 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00016"></a>00016 <span class="comment"> *</span>
+<a name="l00017"></a>00017 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00018"></a>00018 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00019"></a>00019 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00020"></a>00020 <span class="comment"> */</span>
+<a name="l00021"></a>00021 <span class="comment">/*******************************************************************************</span>
+<a name="l00022"></a>00022 <span class="comment">* E.S.O. - VLT project</span>
+<a name="l00023"></a>00023 <span class="comment">*</span>
+<a name="l00024"></a>00024 <span class="comment">* "@(#) $Id: sinfo_spiffi_types.h,v 1.3 2007/06/06 07:10:45 amodigli Exp $"</span>
+<a name="l00025"></a>00025 <span class="comment">*</span>
+<a name="l00026"></a>00026 <span class="comment">* who       when      what</span>
+<a name="l00027"></a>00027 <span class="comment">* --------  --------  ----------------------------------------------</span>
+<a name="l00028"></a>00028 <span class="comment">* schreib  25/05/00  created</span>
+<a name="l00029"></a>00029 <span class="comment">*/</span>
+<a name="l00030"></a>00030 
+<a name="l00031"></a>00031 <span class="comment">/************************************************************************</span>
+<a name="l00032"></a>00032 <span class="comment"> * sinfo_spiffi_types.h</span>
+<a name="l00033"></a>00033 <span class="comment"> * all shared local new data types and defines for spiffi data reduction</span>
+<a name="l00034"></a>00034 <span class="comment"> *----------------------------------------------------------------------</span>
+<a name="l00035"></a>00035 <span class="comment"> */</span>
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="comment">/*</span>
+<a name="l00038"></a>00038 <span class="comment"> * header files</span>
+<a name="l00039"></a>00039 <span class="comment"> */</span>
+<a name="l00040"></a>00040 
+<a name="l00041"></a>00041 <span class="preprocessor">#include <sys/types.h></span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include <limits.h></span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include <stdlib.h></span>
+<a name="l00044"></a>00044 <span class="preprocessor">#include <stdio.h></span>
+<a name="l00045"></a>00045 <span class="preprocessor">#include <string.h></span>
+<a name="l00046"></a>00046 
+<a name="l00047"></a>00047 <span class="preprocessor">#include "sinfo_local_types.h"</span>
+<a name="l00048"></a>00048 
+<a name="l00049"></a>00049 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00050"></a>00050 <span class="comment">                                   Defines</span>
+<a name="l00051"></a>00051 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00052"></a>00052 
+<a name="l00053"></a>00053 <span class="preprocessor">#define NullVector   (Vector *) NULL</span>
+<a name="l00054"></a>00054 <span class="preprocessor"></span><span class="preprocessor">#define SLOPE        1000.  </span><span class="comment">/*slope limit of the linear fit*/</span>
+<a name="l00055"></a>00055 <span class="preprocessor">#define SATURATION   50000. </span><span class="comment">/*saturation level of the detector pixel values*/</span>
+<a name="l00056"></a>00056 <span class="preprocessor">#define ESTIMATE     200    </span><span class="comment">/*estimation of number of parameters stored in an</span>
+<a name="l00057"></a>00057 <span class="comment">                              ascii file*/</span>
+<a name="l00058"></a>00058 <span class="preprocessor">#define THRESH       100000. </span><span class="comment">/* Threshold for operation 1/pixelvalue of </span>
+<a name="l00059"></a>00059 <span class="comment">                                an image division*/</span>
+<a name="l00060"></a>00060 
+<a name="l00061"></a>00061 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00062"></a>00062 
+<a name="l00063"></a>00063 <span class="preprocessor">#define PIXEL_WIDTH  0.0185 </span><span class="comment">/* mm */</span>
+<a name="l00064"></a>00064 <span class="preprocessor">#define FOCAL_LENGTH 178.   </span><span class="comment">/* mm */</span>
+<a name="l00065"></a>00065  
+<a name="l00066"></a>00066 <span class="preprocessor">#define N_SLITLETS   32     </span><span class="comment">/* number of slitlets */</span>
+<a name="l00067"></a>00067 <span class="preprocessor">#define SLITLENGTH   64     </span><span class="comment">/* nominal pixel length of one slitlet */</span>
+<a name="l00068"></a>00068 <span class="preprocessor">#define SLIT_LEN_ERR  5     </span><span class="comment">/* error on SLITLENGTH */</span>
+<a name="l00069"></a>00069 <span class="preprocessor">#define SLIT_POS_ERR  5     </span><span class="comment">/* error on SLITLENGTH */</span>
+<a name="l00070"></a>00070 
+<a name="l00071"></a>00071 <span class="preprocessor">#define LOW_REJECT   0.1    </span><span class="comment">/* fraction of rejected extreme low values of fit </span>
+<a name="l00072"></a>00072 <span class="comment">                               coefficients in sinfo_coefsCrossFit() */</span>
+<a name="l00073"></a>00073 <span class="preprocessor">#define HIGH_REJECT  0.9    </span><span class="comment">/* fraction of rejected extreme high values of fit</span>
+<a name="l00074"></a>00074 <span class="comment">                               coefficients in sinfo_coefsCrossFit() */</span>
+<a name="l00075"></a>00075 <span class="preprocessor">#define PIXEL        25     </span><span class="comment">/* number of pixels for offsets in </span>
+<a name="l00076"></a>00076 <span class="comment">                               sinfo_coeffsCrossSlitFit() */</span>
+<a name="l00077"></a>00077 
+<a name="l00078"></a>00078 <span class="preprocessor">#define CENTRALLAMBDA_K 2.2 </span><span class="comment">/* defined central wavelengths and pixel </span>
+<a name="l00079"></a>00079 <span class="comment">                               dispersions for each grating for </span>
+<a name="l00080"></a>00080 <span class="comment">                               sinfo_definedResampling() */</span>
+<a name="l00081"></a>00081 <span class="preprocessor">#define CENTRALLAMBDA_H    1.65</span>
+<a name="l00082"></a>00082 <span class="preprocessor"></span><span class="preprocessor">#define CENTRALLAMBDA_J    1.25</span>
+<a name="l00083"></a>00083 <span class="preprocessor"></span><span class="preprocessor">#define CENTRALLAMBDA_HK   1.95</span>
+<a name="l00084"></a>00084 <span class="preprocessor"></span><span class="preprocessor">#define DISPERSION_K       0.00049</span>
+<a name="l00085"></a>00085 <span class="preprocessor"></span><span class="preprocessor">#define DISPERSION_K_DITH  0.000245</span>
+<a name="l00086"></a>00086 <span class="preprocessor"></span><span class="preprocessor">#define DISPERSION_H       0.00039</span>
+<a name="l00087"></a>00087 <span class="preprocessor"></span><span class="preprocessor">#define DISPERSION_H_DITH  0.000195</span>
+<a name="l00088"></a>00088 <span class="preprocessor"></span><span class="preprocessor">#define DISPERSION_J       0.00029</span>
+<a name="l00089"></a>00089 <span class="preprocessor"></span><span class="preprocessor">#define DISPERSION_J_DITH  0.000145</span>
+<a name="l00090"></a>00090 <span class="preprocessor"></span><span class="preprocessor">#define DISPERSION_HK      0.001</span>
+<a name="l00091"></a>00091 <span class="preprocessor"></span><span class="preprocessor">#define DISPERSION_HK_DITH 0.0005</span>
+<a name="l00092"></a>00092 <span class="preprocessor"></span>
+<a name="l00093"></a>00093 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00094"></a>00094 <span class="comment">                                   New types</span>
+<a name="l00095"></a>00095 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00096"></a>00096 
+<a name="l00097"></a>00097 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00098"></a>00098 <span class="comment">/* The following structure stores a sinfo_vector                           */</span>
+<a name="l00099"></a>00099 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00100"></a>00100 
+<a name="l00101"></a>00101 <span class="keyword">typedef</span> <span class="keyword">struct </span>_VECTOR_
+<a name="l00102"></a>00102 {
+<a name="l00103"></a>00103     <span class="keywordtype">int</span>           n_elements ;       <span class="comment">/* number of sinfo_vector elements */</span>
+<a name="l00104"></a>00104     pixelvalue    *       data ;         <span class="comment">/* array of sinfo_vector values */</span>
+<a name="l00105"></a>00105 } Vector ;   
+<a name="l00106"></a>00106 
+<a name="l00107"></a>00107 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00108"></a>00108 <span class="comment">/* The following structure stores the (gauss) fitting parameters of the     */</span>
+<a name="l00109"></a>00109 <span class="comment">/* emission lines of the calibration lamps                                  */</span>
+<a name="l00110"></a>00110 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00111"></a>00111 
+<a name="l00112"></a>00112 <span class="keyword">typedef</span> <span class="keyword">struct </span>_FIT_PARAMS_
+<a name="l00113"></a>00113 {
+<a name="l00114"></a>00114     <span class="keywordtype">int</span>      n_params ;        <span class="comment">/* total number of fits to allocate </span>
+<a name="l00115"></a>00115 <span class="comment">                                  FitParams array */</span>
+<a name="l00116"></a>00116     <span class="keywordtype">int</span>      column ;          <span class="comment">/* index of the column in image coordinates */</span>
+<a name="l00117"></a>00117     <span class="keywordtype">int</span>      line   ;          <span class="comment">/* index of fitted emission line </span>
+<a name="l00118"></a>00118 <span class="comment">                                  of the column */</span>            
+<a name="l00119"></a>00119     <span class="keywordtype">float</span>    wavelength ;      <span class="comment">/* associated wavelength of the calibration </span>
+<a name="l00120"></a>00120 <span class="comment">                                  lamp emission line taken from the </span>
+<a name="l00121"></a>00121 <span class="comment">                                  line center list file */</span>
+<a name="l00122"></a>00122     <span class="keywordtype">float</span>  * fit_par ;         <span class="comment">/* fit_par[0]: amplitude,</span>
+<a name="l00123"></a>00123 <span class="comment">                                  fit_par[1]: FWHM,</span>
+<a name="l00124"></a>00124 <span class="comment">                                  fit_par[2]: position of </span>
+<a name="l00125"></a>00125 <span class="comment">                                              center of gauss,</span>
+<a name="l00126"></a>00126 <span class="comment">                                  fit_par[3]: zero level offset */</span>
+<a name="l00127"></a>00127     <span class="keywordtype">float</span>  * derv_par ;        <span class="comment">/* corresponding derivatives of fit_par[] */</span>
+<a name="l00128"></a>00128 } FitParams ;   
+<a name="l00129"></a>00129 
+<a name="l00130"></a>00130 <span class="keyword">typedef</span> <span class="keyword">struct </span>_STATS_
+<a name="l00131"></a>00131 {
+<a name="l00132"></a>00132     <span class="keywordtype">float</span> cleanmean ;          <span class="comment">/* mean of pixel values without considering </span>
+<a name="l00133"></a>00133 <span class="comment">                                  the extreme values */</span>
+<a name="l00134"></a>00134     <span class="keywordtype">float</span> cleanstdev ;         <span class="comment">/* standard deviation of pixel values without </span>
+<a name="l00135"></a>00135 <span class="comment">                                  considering the extreme values */</span>
+<a name="l00136"></a>00136     <span class="keywordtype">int</span>   npix ;               <span class="comment">/* number of clean pixel values */</span>
+<a name="l00137"></a>00137 } Stats ;
+<a name="l00138"></a>00138 
+<a name="l00139"></a>00139 <span class="keyword">typedef</span> <span class="keyword">struct </span>_BCOEFFS_
+<a name="l00140"></a>00140 {
+<a name="l00141"></a>00141     <span class="keywordtype">int</span> slitlet ;              <span class="comment">/* current slitlet */</span>
+<a name="l00142"></a>00142     <span class="keywordtype">int</span> n_slitlets ;           <span class="comment">/* number of slitlets */</span>
+<a name="l00143"></a>00143     <span class="keywordtype">int</span> n_acoeffs ;            <span class="comment">/* number of a fit coefficients */</span>
+<a name="l00144"></a>00144     <span class="keywordtype">int</span> n_bcoeffs ;            <span class="comment">/* number of b fit coefficients */</span>
+<a name="l00145"></a>00145     <span class="keywordtype">float</span> ** b ;               <span class="comment">/* sinfo_matrix of fit coefficients: </span>
+<a name="l00146"></a>00146 <span class="comment">                                  b[index acoefs][index bcoefs] */</span>
+<a name="l00147"></a>00147 } Bcoeffs ;
+<a name="l00148"></a>00148 
+<a name="l00149"></a>00149 <span class="preprocessor">#endif </span>
+<a name="l00151"></a>00151 <span class="preprocessor"></span><span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00152"></a>00152 
+<a name="l00153"></a>00153 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__stack__cfg_8c_source.html b/html/sinfo__stack__cfg_8c_source.html
new file mode 100644
index 0000000..9ac3515
--- /dev/null
+++ b/html/sinfo__stack__cfg_8c_source.html
@@ -0,0 +1,75 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_stack_cfg.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_stack_cfg.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 
+<a name="l00020"></a>00020 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00021"></a>00021 <span class="comment">   </span>
+<a name="l00022"></a>00022 <span class="comment">   File name     :    stack_cfg.c</span>
+<a name="l00023"></a>00023 <span class="comment">   Author         : Juergen Schreiber</span>
+<a name="l00024"></a>00024 <span class="comment">   Created on    :    September 2001</span>
+<a name="l00025"></a>00025 <span class="comment">   Description    :    prepare stacked frames configuration handling tools</span>
+<a name="l00026"></a>00026 <span class="comment"></span>
+<a name="l00027"></a>00027 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span>
+<a name="l00032"></a>00032 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                                   Includes</span>
+<a name="l00034"></a>00034 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 
+<a name="l00036"></a>00036 <span class="preprocessor">#include "sinfo_stack_cfg.h"</span>
+<a name="l00044"></a>00044 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00045"></a>00045 <span class="comment">                              Function codes</span>
+<a name="l00046"></a>00046 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00047"></a>00047 
+<a name="l00056"></a>00056 stack_config_n * sinfo_stack_cfg_create_n(<span class="keywordtype">void</span>)
+<a name="l00057"></a>00057 {
+<a name="l00058"></a>00058     <span class="keywordflow">return</span> cpl_calloc(1, <span class="keyword">sizeof</span>(stack_config_n));
+<a name="l00059"></a>00059 }
+<a name="l00060"></a>00060 
+<a name="l00061"></a>00061 
+<a name="l00069"></a>00069 <span class="keywordtype">void</span> sinfo_stack_cfg_destroy_n(stack_config_n * sc)
+<a name="l00070"></a>00070 {
+<a name="l00071"></a>00071     <span class="keywordflow">if</span> (sc==NULL) return ;
+<a name="l00072"></a>00072 
+<a name="l00073"></a>00073     <span class="comment">/* Free list of frame types */</span>
+<a name="l00074"></a>00074     <span class="comment">/*cpl_free(sc->frametype);*/</span>
+<a name="l00075"></a>00075     <span class="comment">/* Free positions */</span>
+<a name="l00076"></a>00076     <span class="comment">/*cpl_free(sc->frameposition);*/</span>
+<a name="l00077"></a>00077     <span class="comment">/* Free main struct */</span>
+<a name="l00078"></a>00078     cpl_free(sc);
+<a name="l00079"></a>00079 
+<a name="l00080"></a>00080     return ;
+<a name="l00081"></a>00081 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__stack__cfg_8h_source.html b/html/sinfo__stack__cfg_8h_source.html
new file mode 100644
index 0000000..1ce9308
--- /dev/null
+++ b/html/sinfo__stack__cfg_8h_source.html
@@ -0,0 +1,179 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_stack_cfg.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_stack_cfg.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name     :    stack_cfg.h</span>
+<a name="l00022"></a>00022 <span class="comment">   Author         :    Juergen Schreiber</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on    :    September 2001</span>
+<a name="l00024"></a>00024 <span class="comment">   Description    :    stack_ini definitions + handling prototypes</span>
+<a name="l00025"></a>00025 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00026"></a>00026 <span class="preprocessor">#ifndef SINFO_STACK_CFG_H</span>
+<a name="l00027"></a>00027 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_STACK_CFG_H</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00029"></a>00029 <span class="comment">                                   Includes</span>
+<a name="l00030"></a>00030 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00031"></a>00031 <span class="preprocessor">#include <stdlib.h></span>
+<a name="l00032"></a>00032 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include "sinfo_globals.h"</span>
+<a name="l00034"></a>00034 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00035"></a>00035 <span class="comment">                                   Defines</span>
+<a name="l00036"></a>00036 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00037"></a>00037 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00038"></a>00038 <span class="comment">                                   New types</span>
+<a name="l00039"></a>00039 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00040"></a>00040 <span class="comment">/*</span>
+<a name="l00041"></a>00041 <span class="comment">  prepare stacked images blackboard container</span>
+<a name="l00042"></a>00042 <span class="comment"></span>
+<a name="l00043"></a>00043 <span class="comment">  This structure holds all information related to the stacked images handling</span>
+<a name="l00044"></a>00044 <span class="comment">  routine. It is used as a container for the flux of ancillary data,</span>
+<a name="l00045"></a>00045 <span class="comment">  computed values, and algorithm status. Pixel flux is separated from</span>
+<a name="l00046"></a>00046 <span class="comment">  the blackboard.</span>
+<a name="l00047"></a>00047 <span class="comment">  */</span>
+<a name="l00048"></a>00048 
+<a name="l00049"></a>00049 <span class="keyword">typedef</span> <span class="keyword">struct </span>stack_config_n {
+<a name="l00050"></a>00050 <span class="comment">/*-------General---------*/</span>
+<a name="l00051"></a>00051         <span class="keywordtype">char</span> inFile[FILE_NAME_SZ] ; <span class="comment">/* file name of the file containing </span>
+<a name="l00052"></a>00052 <span class="comment">                                       the list of all input frames */</span>
+<a name="l00053"></a>00053         <span class="keywordtype">char</span> outName[FILE_NAME_SZ] ; <span class="comment">/* output name of resulting fits </span>
+<a name="l00054"></a>00054 <span class="comment">                                        wavelength map */</span>
+<a name="l00055"></a>00055         <span class="keywordtype">char</span> sky_name[FILE_NAME_SZ] ; <span class="comment">/* output name of resulting fits </span>
+<a name="l00056"></a>00056 <span class="comment">                                         sky frame */</span>
+<a name="l00057"></a>00057         <span class="keywordtype">char</span> ** framelist ; <span class="comment">/* list of frames */</span>
+<a name="l00058"></a>00058         <span class="keywordtype">int</span>  * frametype ; <span class="comment">/* list of frame types on or off */</span>
+<a name="l00059"></a>00059         <span class="keywordtype">int</span>  * frameposition ; <span class="comment">/* list of grating positions */</span>  
+<a name="l00060"></a>00060         <span class="keywordtype">int</span>    contains_sky ; <span class="comment">/* indicates if off or sky frames were exposed */</span>
+<a name="l00061"></a>00061         <span class="keywordtype">int</span>    contains_ref ; <span class="comment">/* indicates if ref frames were exposed */</span>
+<a name="l00062"></a>00062         <span class="keywordtype">int</span>    contains_dither ; <span class="comment">/* indicates if spectral dithering </span>
+<a name="l00063"></a>00063 <span class="comment">                                    was applied */</span>
+<a name="l00064"></a>00064         <span class="keywordtype">int</span>    contains_dark ; <span class="comment">/* indicates if spectral </span>
+<a name="l00065"></a>00065 <span class="comment">                                  dithering was applied */</span>
+<a name="l00066"></a>00066         <span class="keywordtype">int</span>    nframes ; <span class="comment">/* number of frames in frame list */</span>
+<a name="l00067"></a>00067         <span class="keywordtype">int</span>    nobj ;  <span class="comment">/* number of object frames in frame list */</span>
+<a name="l00068"></a>00068         <span class="keywordtype">int</span>    noff ;  <span class="comment">/* number of off frames in frame list */</span>
+<a name="l00069"></a>00069         <span class="keywordtype">int</span>    ndark ;  <span class="comment">/* number of sinfo_dark frames in frame list */</span>
+<a name="l00070"></a>00070         <span class="keywordtype">int</span>    nditherobj ;  <span class="comment">/* number of dithered object </span>
+<a name="l00071"></a>00071 <span class="comment">                                frames in frame list */</span>
+<a name="l00072"></a>00072         <span class="keywordtype">int</span>    nditheroff ;  <span class="comment">/* number of dithered off frames in frame list */</span>
+<a name="l00073"></a>00073 
+<a name="l00074"></a>00074 <span class="comment">/*------ CleanMean ------*/</span>
+<a name="l00075"></a>00075         <span class="comment">/* percentage of rejected low intensity pixels */</span>
+<a name="l00076"></a>00076         <span class="keywordtype">float</span> loReject ;      
+<a name="l00077"></a>00077         <span class="comment">/* percentage of rejected high intensity pixels */</span>
+<a name="l00078"></a>00078         <span class="keywordtype">float</span> hiReject ;
+<a name="l00079"></a>00079 
+<a name="l00080"></a>00080 <span class="comment">/*------ Flatfielding ------*/</span>
+<a name="l00081"></a>00081         <span class="comment">/* indicator if a flatfielding is carried through or not */</span>
+<a name="l00082"></a>00082         <span class="keywordtype">int</span> flatInd ;
+<a name="l00083"></a>00083         <span class="keywordtype">char</span> flatfield1[FILE_NAME_SZ] ; <span class="comment">/* name of the flatfield fits file </span>
+<a name="l00084"></a>00084 <span class="comment">                                           for grating position 1 */</span>
+<a name="l00085"></a>00085         <span class="keywordtype">char</span> flatfield2[FILE_NAME_SZ] ; <span class="comment">/* name of the flatfield fits file </span>
+<a name="l00086"></a>00086 <span class="comment">                                           for grating position 2 */</span>
+<a name="l00087"></a>00087 
+<a name="l00088"></a>00088 <span class="comment">/*------ BadPixel ------*/</span>
+<a name="l00089"></a>00089         <span class="comment">/* indicates if the bad pixel mask should be applied or not */</span>
+<a name="l00090"></a>00090         <span class="keywordtype">int</span> maskInd ;
+<a name="l00091"></a>00091         <span class="comment">/* indicates if the pixels should be interpolated or indicated */</span>
+<a name="l00092"></a>00092         <span class="keywordtype">int</span> indind ;
+<a name="l00093"></a>00093         <span class="comment">/* file name of the bad pixel mask fits file */</span>
+<a name="l00094"></a>00094         <span class="keywordtype">char</span> mask[FILE_NAME_SZ] ;
+<a name="l00095"></a>00095         <span class="comment">/* maximal pixel distance from the bad pixel to which valid </span>
+<a name="l00096"></a>00096 <span class="comment">           pixels are searched for*/</span> 
+<a name="l00097"></a>00097         <span class="keywordtype">int</span> maxRad ;
+<a name="l00098"></a>00098         <span class="comment">/* file name of the slitlet sinfo_edge position list */</span>
+<a name="l00099"></a>00099         <span class="keywordtype">char</span> slitposList[FILE_NAME_SZ] ;
+<a name="l00100"></a>00100         <span class="comment">/* index file list*/</span>
+<a name="l00101"></a>00101         <span class="keywordtype">char</span> indexlist[FILE_NAME_SZ] ;
+<a name="l00102"></a>00102         <span class="comment">/* sigma factor for the additional bad pixel search </span>
+<a name="l00103"></a>00103 <span class="comment">           in method maskInd = 2 */</span>
+<a name="l00104"></a>00104         <span class="keywordtype">float</span> sigmaFactor ;
+<a name="l00105"></a>00105 
+<a name="l00106"></a>00106 <span class="comment">/*------ ColTilt ------*/</span>
+<a name="l00107"></a>00107         <span class="comment">/* indicator if the tilt correction should be carried through */</span>
+<a name="l00108"></a>00108         <span class="comment">/*int coltiltInd ;*/</span>
+<a name="l00109"></a>00109         <span class="comment">/* file name of the ASCII file containing the slope value */</span>
+<a name="l00110"></a>00110         <span class="comment">/*char slopeFile[FILE_NAME_SZ] ;*/</span>
+<a name="l00111"></a>00111         <span class="comment">/* order of polynomial used for polynomial interpolation </span>
+<a name="l00112"></a>00112 <span class="comment">           for the row shifting */</span>
+<a name="l00113"></a>00113         <span class="comment">/*int order ;*/</span>
+<a name="l00114"></a>00114 <span class="comment">/*------ WarpFix ------*/</span>
+<a name="l00115"></a>00115         <span class="comment">/* indicator if the warping should be carried through */</span>
+<a name="l00116"></a>00116         <span class="keywordtype">int</span> warpfixInd ;
+<a name="l00117"></a>00117         <span class="comment">/* file name of the ASCII file containing the polynomial values */</span>
+<a name="l00118"></a>00118         <span class="keywordtype">char</span> polyFile[FILE_NAME_SZ] ;
+<a name="l00119"></a>00119         <span class="comment">/* file name of MASTER DARK */</span>
+<a name="l00120"></a>00120         <span class="keywordtype">char</span> mdark[FILE_NAME_SZ] ;
+<a name="l00121"></a>00121   <span class="comment">/* swich to indicate if a mdark file has been found */</span>
+<a name="l00122"></a>00122         <span class="keywordtype">int</span> mdark_ind;  
+<a name="l00123"></a>00123       <span class="comment">/* kernel to be used for the interpolation */</span>
+<a name="l00124"></a>00124         <span class="keywordtype">char</span> kernel[FILE_NAME_SZ] ;
+<a name="l00125"></a>00125 
+<a name="l00126"></a>00126 <span class="comment">/*------ Interleaving ------*/</span>
+<a name="l00127"></a>00127         <span class="comment">/* indicator if the interleaving or Convolution with a </span>
+<a name="l00128"></a>00128 <span class="comment">           Gaussian or nothing should take place */</span>
+<a name="l00129"></a>00129         <span class="keywordtype">int</span> interInd ;
+<a name="l00130"></a>00130     <span class="comment">/* number of rows from which the general offset between </span>
+<a name="l00131"></a>00131 <span class="comment">           the frames is determined */</span>
+<a name="l00132"></a>00132     <span class="keywordtype">int</span> noRows ;
+<a name="l00133"></a>00133 
+<a name="l00134"></a>00134 <span class="comment">/*------ GaussConvolution ------*/</span>
+<a name="l00135"></a>00135     <span class="comment">/* indicator if Gaussian convolution is applied or not */</span>
+<a name="l00136"></a>00136         <span class="keywordtype">int</span> gaussInd ;
+<a name="l00137"></a>00137     <span class="comment">/* kernel half width of the Gaussian response function */</span>
+<a name="l00138"></a>00138     <span class="keywordtype">int</span> hw ;
+<a name="l00139"></a>00139 
+<a name="l00140"></a>00140 <span class="comment">/*------ ShifFrames ------*/</span>
+<a name="l00141"></a>00141     <span class="comment">/* indicator if shiftting frames is applied or not */</span>
+<a name="l00142"></a>00142         <span class="keywordtype">int</span> sfInd;
+<a name="l00143"></a>00143     <span class="comment">/* interpolation type*/</span>
+<a name="l00144"></a>00144     <span class="keywordtype">int</span> sfType;
+<a name="l00145"></a>00145     <span class="comment">/* interpolation order*/</span>
+<a name="l00146"></a>00146     <span class="keywordtype">int</span> sfOrder;
+<a name="l00147"></a>00147 
+<a name="l00148"></a>00148   <span class="comment">/* qc log */</span>
+<a name="l00149"></a>00149   <span class="keywordtype">int</span> qc_thresh_min;
+<a name="l00150"></a>00150   <span class="keywordtype">int</span> qc_thresh_max;
+<a name="l00151"></a>00151 
+<a name="l00152"></a>00152 } stack_config_n ;
+<a name="l00153"></a>00153 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00154"></a>00154 <span class="comment">                               Function prototypes</span>
+<a name="l00155"></a>00155 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00163"></a>00163 stack_config_n * 
+<a name="l00164"></a>00164 sinfo_stack_cfg_create_n(<span class="keywordtype">void</span>);
+<a name="l00165"></a>00165 
+<a name="l00166"></a>00166 
+<a name="l00173"></a>00173 <span class="keywordtype">void</span> 
+<a name="l00174"></a>00174 sinfo_stack_cfg_destroy_n(stack_config_n * sc);
+<a name="l00175"></a>00175 
+<a name="l00176"></a>00176 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__stack__ini_8h_source.html b/html/sinfo__stack__ini_8h_source.html
new file mode 100644
index 0000000..98188c6
--- /dev/null
+++ b/html/sinfo__stack__ini_8h_source.html
@@ -0,0 +1,87 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_stack_ini.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_stack_ini.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 
+<a name="l00020"></a>00020 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00021"></a>00021 <span class="comment">   </span>
+<a name="l00022"></a>00022 <span class="comment">   File name    :   sinfo_stack_ini.h</span>
+<a name="l00023"></a>00023 <span class="comment">   Author       :    Juergen Schreiber</span>
+<a name="l00024"></a>00024 <span class="comment">   Created on   :    Sept 25, 2001</span>
+<a name="l00025"></a>00025 <span class="comment">   Description  :    preparing stack of frames ini file handling for SPIFFI</span>
+<a name="l00026"></a>00026 <span class="comment"></span>
+<a name="l00027"></a>00027 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00028"></a>00028 
+<a name="l00029"></a>00029 
+<a name="l00030"></a>00030 <span class="preprocessor">#ifndef SINFO_STACK_INI_H</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_STACK_INI_H</span>
+<a name="l00032"></a>00032 <span class="preprocessor"></span>
+<a name="l00033"></a>00033 
+<a name="l00034"></a>00034 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00035"></a>00035 <span class="comment">                                Includes</span>
+<a name="l00036"></a>00036 <span class="comment">---------------------------------------------------------------------------*/</span>
+<a name="l00037"></a>00037 
+<a name="l00038"></a>00038 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00039"></a>00039 
+<a name="l00040"></a>00040 <span class="preprocessor">#include "sinfo_stack_cfg.h"</span>
+<a name="l00041"></a>00041 
+<a name="l00042"></a>00042  
+<a name="l00043"></a>00043 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00044"></a>00044 <span class="comment">                                Defines</span>
+<a name="l00045"></a>00045 <span class="comment">---------------------------------------------------------------------------*/</span>
+<a name="l00046"></a>00046 
+<a name="l00047"></a>00047 <span class="preprocessor">#define FRAME_ON     1  </span><span class="comment">/* object frames */</span>
+<a name="l00048"></a>00048 <span class="preprocessor">#define FRAME_OFF    0  </span><span class="comment">/* off frames, that means sky frames or calibration </span>
+<a name="l00049"></a>00049 <span class="comment">                           frames with lamp switched off */</span>
+<a name="l00050"></a>00050 <span class="preprocessor">#define FRAME_POS1   2  </span><span class="comment">/* frames exposed with grating position 1 */</span>
+<a name="l00051"></a>00051 <span class="preprocessor">#define FRAME_POS2   3  </span><span class="comment">/* frames exposed with dithered grating position 2 */</span>
+<a name="l00052"></a>00052  
+<a name="l00053"></a>00053 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00054"></a>00054 <span class="comment">                             Function prototypes </span>
+<a name="l00055"></a>00055 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00056"></a>00056 
+<a name="l00057"></a>00057 
+<a name="l00058"></a>00058 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l00073"></a>00073 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00074"></a>00074 <span class="keywordtype">int</span> generateStack_ini_file(
+<a name="l00075"></a>00075         <span class="keywordtype">char</span> * ini_name,
+<a name="l00076"></a>00076         <span class="keywordtype">char</span> * name_i,
+<a name="l00077"></a>00077         <span class="keywordtype">char</span> * name_o
+<a name="l00078"></a>00078 );
+<a name="l00079"></a>00079 
+<a name="l00080"></a>00080 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l00091"></a>00091 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00092"></a>00092 
+<a name="l00093"></a>00093 stack_config * parse_stack_ini_file(<span class="keywordtype">char</span> * ini_name) ;
+<a name="l00094"></a>00094 
+<a name="l00095"></a>00095 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__stack__ini__by__cpl_8c_source.html b/html/sinfo__stack__ini__by__cpl_8c_source.html
new file mode 100644
index 0000000..3ff2bf0
--- /dev/null
+++ b/html/sinfo__stack__ini__by__cpl_8c_source.html
@@ -0,0 +1,644 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_stack_ini_by_cpl.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_stack_ini_by_cpl.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name    :   stack_ini_by_cpl.c</span>
+<a name="l00022"></a>00022 <span class="comment">   Author       :   Andrea Modigliani</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on   :   May 23, 2004</span>
+<a name="l00024"></a>00024 <span class="comment">   Description  :   prepare stacked frames cpl input handling for SPIFFI</span>
+<a name="l00025"></a>00025 <span class="comment"></span>
+<a name="l00026"></a>00026 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span>
+<a name="l00032"></a>00032 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                                Includes</span>
+<a name="l00034"></a>00034 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 
+<a name="l00036"></a>00036 <span class="preprocessor">#include <string.h></span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include "sinfo_stack_ini_by_cpl.h"</span>
+<a name="l00038"></a>00038 <span class="preprocessor">#include "sinfo_error.h"</span>
+<a name="l00039"></a>00039 <span class="preprocessor">#include "sinfo_pro_types.h"</span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include "sinfo_raw_types.h"</span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include "sinfo_ref_types.h"</span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include "sinfo_functions.h"</span>
+<a name="l00043"></a>00043 
+<a name="l00044"></a>00044 <span class="preprocessor">#include "sinfo_file_handling.h"</span>
+<a name="l00045"></a>00045 
+<a name="l00046"></a>00046 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00047"></a>00047 <span class="comment">                    Functions private to this module</span>
+<a name="l00048"></a>00048 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00049"></a>00049 <span class="keyword">static</span> <span class="keywordtype">void</span> sinfo_stack_free_alloc(stack_config_n * cfg);  
+<a name="l00050"></a>00050 
+<a name="l00051"></a>00051 
+<a name="l00052"></a>00052 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00053"></a>00053 parse_section_frames(stack_config_n *, 
+<a name="l00054"></a>00054                      cpl_frameset* sof, 
+<a name="l00055"></a>00055                      cpl_frameset** raw,
+<a name="l00056"></a>00056                      <span class="keywordtype">int</span>* status,
+<a name="l00057"></a>00057                      fake* fk);
+<a name="l00058"></a>00058 
+<a name="l00059"></a>00059 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00060"></a>00060 parse_section_cleanmean(stack_config_n *, cpl_parameterlist* cpl_cfg);
+<a name="l00061"></a>00061 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00062"></a>00062 parse_section_flatfield(stack_config_n *, cpl_parameterlist* cpl_cfg);
+<a name="l00063"></a>00063 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00064"></a>00064 parse_section_badpixel(stack_config_n *, cpl_parameterlist* cpl_cfg);
+<a name="l00065"></a>00065 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00066"></a>00066 parse_section_interleaving(stack_config_n *);
+<a name="l00067"></a>00067 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00068"></a>00068 parse_section_gaussconvolution(stack_config_n *, cpl_parameterlist* cpl_cfg);
+<a name="l00069"></a>00069 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00070"></a>00070 parse_section_shiftframes(stack_config_n *);
+<a name="l00071"></a>00071 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00072"></a>00072 parse_section_warpfix(stack_config_n *,  cpl_parameterlist* cpl_cfg);
+<a name="l00073"></a>00073 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00074"></a>00074 parse_section_qclog(stack_config_n *,  cpl_parameterlist* cpl_cfg);
+<a name="l00082"></a>00082 <span class="comment">/* generateStack_ini_file */</span>
+<a name="l00083"></a>00083 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l00094"></a>00094 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00095"></a>00095 
+<a name="l00096"></a>00096 stack_config_n * sinfo_parse_cpl_input_stack(cpl_parameterlist* cpl_cfg, 
+<a name="l00097"></a>00097                                        cpl_frameset* sof, 
+<a name="l00098"></a>00098                                        cpl_frameset** raw,
+<a name="l00099"></a>00099                                        fake* fk)
+<a name="l00100"></a>00100 {
+<a name="l00101"></a>00101     stack_config_n   *       cfg =sinfo_stack_cfg_create_n();
+<a name="l00102"></a>00102     <span class="keywordtype">int</span> status=0;
+<a name="l00103"></a>00103    
+<a name="l00104"></a>00104 
+<a name="l00105"></a>00105 
+<a name="l00106"></a>00106     <span class="comment">/*</span>
+<a name="l00107"></a>00107 <span class="comment">     * Perform sanity checks, fill up the structure with what was</span>
+<a name="l00108"></a>00108 <span class="comment">     * found in the ini file</span>
+<a name="l00109"></a>00109 <span class="comment">     */</span>
+<a name="l00110"></a>00110 
+<a name="l00111"></a>00111     parse_section_cleanmean        (cfg, cpl_cfg);
+<a name="l00112"></a>00112     parse_section_flatfield        (cfg, cpl_cfg);
+<a name="l00113"></a>00113     parse_section_badpixel         (cfg, cpl_cfg); 
+<a name="l00114"></a>00114     parse_section_interleaving     (cfg); 
+<a name="l00115"></a>00115     parse_section_gaussconvolution (cfg, cpl_cfg); 
+<a name="l00116"></a>00116     parse_section_shiftframes      (cfg); 
+<a name="l00117"></a>00117     parse_section_warpfix          (cfg, cpl_cfg);
+<a name="l00118"></a>00118     parse_section_qclog            (cfg, cpl_cfg);
+<a name="l00119"></a>00119     parse_section_frames           (cfg, sof, raw, &status, fk);
+<a name="l00120"></a>00120           <span class="keywordflow">if</span> (status > 0) {
+<a name="l00121"></a>00121                 <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"parsing cpl input"</span>);
+<a name="l00122"></a>00122                 sinfo_stack_cfg_destroy_n(cfg);
+<a name="l00123"></a>00123                 cfg = NULL ;
+<a name="l00124"></a>00124                 <span class="keywordflow">return</span> NULL ;
+<a name="l00125"></a>00125         }
+<a name="l00126"></a>00126     <span class="keywordflow">return</span> cfg ;
+<a name="l00127"></a>00127 }
+<a name="l00137"></a>00137 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00138"></a>00138 parse_section_frames(stack_config_n * cfg, 
+<a name="l00139"></a>00139                      cpl_frameset* sof, cpl_frameset** raw_set,<span class="keywordtype">int</span>* status, 
+<a name="l00140"></a>00140                      fake* fk)
+<a name="l00141"></a>00141 {
+<a name="l00142"></a>00142 
+<a name="l00143"></a>00143    <span class="keywordtype">int</span>                     i;
+<a name="l00144"></a>00144    <span class="keyword">const</span> <span class="keywordtype">char</span>            *       name;
+<a name="l00145"></a>00145    <span class="keywordtype">char</span>                        file[FILE_NAME_SZ];
+<a name="l00146"></a>00146    <span class="keywordtype">int</span>                     nobj, noff, ndark ;
+<a name="l00147"></a>00147    <span class="keywordtype">int</span>                     nditherobj, nditheroff ;
+<a name="l00148"></a>00148    <span class="keywordtype">int</span>                     found_sky ;
+<a name="l00149"></a>00149    <span class="keywordtype">int</span>                     found_ref ;
+<a name="l00150"></a>00150    <span class="keywordtype">int</span>                     found_dither ;
+<a name="l00151"></a>00151    <span class="keywordtype">int</span>                     found_dark   ;
+<a name="l00152"></a>00152     <span class="keywordtype">int</span> nraw=0;
+<a name="l00153"></a>00153     <span class="keywordtype">int</span> nsof=0;
+<a name="l00154"></a>00154 
+<a name="l00155"></a>00155    cpl_frame* frame   = NULL;
+<a name="l00156"></a>00156 
+<a name="l00157"></a>00157     <span class="keywordtype">char</span> spat_res[FILE_NAME_SZ];
+<a name="l00158"></a>00158    <span class="keywordtype">char</span> lamp_status[FILE_NAME_SZ];
+<a name="l00159"></a>00159    <span class="keywordtype">char</span> band[FILE_NAME_SZ];
+<a name="l00160"></a>00160    <span class="keywordtype">int</span> ins_set=0;
+<a name="l00161"></a>00161    <span class="keywordtype">char</span>* tag=NULL;
+<a name="l00162"></a>00162    <span class="keywordtype">char</span>* do_class=NULL;
+<a name="l00163"></a>00163   
+<a name="l00164"></a>00164    nsof    = cpl_frameset_get_size(sof);
+<a name="l00165"></a>00165 
+<a name="l00166"></a>00166 
+<a name="l00167"></a>00167    do_class=fk->pro_class;
+<a name="l00168"></a>00168    <span class="comment">/* sinfo_msg("do_class=%s",do_class); */</span> 
+<a name="l00169"></a>00169    <span class="keywordflow">if</span>(strcmp(do_class,<span class="stringliteral">"DEFAULT"</span>) == 0) {
+<a name="l00170"></a>00170       sinfo_extract_raw_stack_frames(sof,raw_set);
+<a name="l00171"></a>00171    } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(do_class,PRO_FIBRE_NS_STACKED_DIST) == 0) {
+<a name="l00172"></a>00172       sinfo_is_fibres_on_off(sof,*raw_set);
+<a name="l00173"></a>00173    } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(do_class,PRO_FIBRE_NS_STACKED) == 0) {
+<a name="l00174"></a>00174       sinfo_contains_frames_kind(sof,*raw_set,(<span class="keywordtype">char</span>*)PRO_FIBRE_NS_STACKED);
+<a name="l00175"></a>00175    } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(do_class,RAW_STACKED_SLITPOS) == 0) {
+<a name="l00176"></a>00176       sinfo_extract_raw_stack_frames(sof,raw_set);
+<a name="l00177"></a>00177    } <span class="keywordflow">else</span> {
+<a name="l00178"></a>00178       sinfo_extract_raw_frames_type(sof,raw_set,do_class);
+<a name="l00179"></a>00179    }
+<a name="l00180"></a>00180    nraw    = cpl_frameset_get_size(*raw_set);
+<a name="l00181"></a>00181    <span class="keywordflow">if</span> (nraw < 1) {
+<a name="l00182"></a>00182       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Too few raw frames present in frameset!"</span>);
+<a name="l00183"></a>00183       (*status)++;
+<a name="l00184"></a>00184       <span class="keywordflow">return</span>;
+<a name="l00185"></a>00185    }
+<a name="l00186"></a>00186 
+<a name="l00187"></a>00187  
+<a name="l00188"></a>00188    <span class="comment">/* Allocate structures to go into the blackboard */</span>
+<a name="l00189"></a>00189    cfg->framelist     = cpl_malloc(nraw * <span class="keyword">sizeof</span>(<span class="keywordtype">char</span>*));
+<a name="l00190"></a>00190    cfg->frametype     = cpl_malloc(nraw * <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>));
+<a name="l00191"></a>00191    cfg->frameposition = cpl_malloc(nraw * <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>));
+<a name="l00192"></a>00192 
+<a name="l00193"></a>00193    <span class="keywordflow">for</span> (i=0;i<nraw;i++) {
+<a name="l00194"></a>00194      cfg->framelist[i]=NULL;
+<a name="l00195"></a>00195      cfg->frametype[i]=-1;
+<a name="l00196"></a>00196      cfg->frameposition[i]=-1;
+<a name="l00197"></a>00197    }
+<a name="l00198"></a>00198 
+<a name="l00199"></a>00199    found_sky     = 0 ;
+<a name="l00200"></a>00200    found_ref     = 0 ;
+<a name="l00201"></a>00201    found_dither  = 0 ;
+<a name="l00202"></a>00202    found_dark    = 0 ;
+<a name="l00203"></a>00203    nobj          = 0 ;
+<a name="l00204"></a>00204    noff          = 0 ;
+<a name="l00205"></a>00205    ndark         = 0 ;
+<a name="l00206"></a>00206    nditherobj    = 0 ;
+<a name="l00207"></a>00207    nditheroff    = 0 ;
+<a name="l00208"></a>00208 
+<a name="l00209"></a>00209 
+<a name="l00210"></a>00210 
+<a name="l00211"></a>00211    <span class="comment">/* Browse through the charmatrix to get names and file types */</span>
+<a name="l00212"></a>00212    <span class="comment">/*   for (i=0 ; i<nraw ; i++) { */</span>
+<a name="l00213"></a>00213    <span class="keywordflow">for</span> (i=0 ; i<nraw ; i++) {
+<a name="l00214"></a>00214       frame = cpl_frameset_get_frame(*raw_set,i);
+<a name="l00215"></a>00215       name=cpl_frame_get_filename(frame);
+<a name="l00216"></a>00216        <span class="keywordflow">if</span>(sinfo_file_exists((<span class="keywordtype">char</span>*)name)==1) {
+<a name="l00217"></a>00217     <span class="comment">/* to go on the file must exist */</span>
+<a name="l00218"></a>00218     <span class="keywordflow">if</span>(cpl_frame_get_tag(frame) != NULL) {
+<a name="l00219"></a>00219       <span class="comment">/* If the frame has a tag we process it. Else it is an object */</span> 
+<a name="l00220"></a>00220       tag= (<span class="keywordtype">char</span>*) cpl_frame_get_tag(frame);
+<a name="l00221"></a>00221           <span class="keywordflow">if</span>((sinfo_frame_is_on(frame)  == 0) || 
+<a name="l00222"></a>00222              (sinfo_frame_is_sky(frame)  == 1)) 
+<a name="l00223"></a>00223       {
+<a name="l00224"></a>00224              cfg->framelist[i]=cpl_strdup(cpl_frame_get_filename(frame));
+<a name="l00225"></a>00225              cfg->frametype[i] = FRAME_OFF ;
+<a name="l00226"></a>00226              found_sky = 1;
+<a name="l00227"></a>00227              <span class="keywordflow">if</span> (sinfo_frame_is_dither(frame)) 
+<a name="l00228"></a>00228            {
+<a name="l00229"></a>00229                 cfg->frameposition[i] = FRAME_POS2 ;
+<a name="l00230"></a>00230                 nditheroff++ ;
+<a name="l00231"></a>00231            }
+<a name="l00232"></a>00232              <span class="keywordflow">else</span> 
+<a name="l00233"></a>00233            {
+<a name="l00234"></a>00234                 cfg->frameposition[i] = FRAME_POS1 ;
+<a name="l00235"></a>00235                 noff++ ;
+<a name="l00236"></a>00236            }
+<a name="l00237"></a>00237       }
+<a name="l00238"></a>00238           <span class="keywordflow">else</span> <span class="keywordflow">if</span>(strstr(tag,RAW_REF)  != NULL) 
+<a name="l00239"></a>00239       {
+<a name="l00240"></a>00240           cfg->framelist[i]=cpl_strdup(cpl_frame_get_filename(frame));
+<a name="l00241"></a>00241           cfg->frametype[i] = FRAME_REF ;
+<a name="l00242"></a>00242               found_ref=1;
+<a name="l00243"></a>00243           <span class="keywordflow">if</span> (sinfo_frame_is_dither(frame))
+<a name="l00244"></a>00244         {
+<a name="l00245"></a>00245           cfg->frameposition[i] = FRAME_POS2 ;
+<a name="l00246"></a>00246         }
+<a name="l00247"></a>00247               <span class="keywordflow">else</span> 
+<a name="l00248"></a>00248         {
+<a name="l00249"></a>00249           cfg->frameposition[i] = FRAME_POS1 ;
+<a name="l00250"></a>00250         }
+<a name="l00251"></a>00251       }
+<a name="l00252"></a>00252           <span class="keywordflow">else</span> <span class="keywordflow">if</span>(sinfo_is_dark(tag)) 
+<a name="l00253"></a>00253         {
+<a name="l00254"></a>00254           cfg->framelist[i]=cpl_strdup(cpl_frame_get_filename(frame));
+<a name="l00255"></a>00255           cfg->frametype[i] = FRAME_DRK ;
+<a name="l00256"></a>00256           cfg->frameposition[i] = FRAME_POS1 ;
+<a name="l00257"></a>00257               found_dark=1;
+<a name="l00258"></a>00258               ndark++;
+<a name="l00259"></a>00259           sinfo_msg(<span class="stringliteral">"Frame is sinfo_dark on\n"</span>);
+<a name="l00260"></a>00260         }
+<a name="l00261"></a>00261           <span class="keywordflow">else</span> 
+<a name="l00262"></a>00262         {
+<a name="l00263"></a>00263 
+<a name="l00264"></a>00264           cfg->framelist[i]=cpl_strdup(cpl_frame_get_filename(frame));
+<a name="l00265"></a>00265           cfg->frametype[i] = FRAME_ON ;
+<a name="l00266"></a>00266               found_ref=1;
+<a name="l00267"></a>00267           <span class="keywordflow">if</span> (sinfo_frame_is_dither(frame))
+<a name="l00268"></a>00268         {
+<a name="l00269"></a>00269           cfg->frameposition[i] = FRAME_POS2 ;
+<a name="l00270"></a>00270                   found_dither=1;
+<a name="l00271"></a>00271                   nditherobj++;
+<a name="l00272"></a>00272         }
+<a name="l00273"></a>00273               <span class="keywordflow">else</span> 
+<a name="l00274"></a>00274         {
+<a name="l00275"></a>00275           cfg->frameposition[i] = FRAME_POS1 ;
+<a name="l00276"></a>00276                   nobj++;
+<a name="l00277"></a>00277         }
+<a name="l00278"></a>00278         }
+<a name="l00279"></a>00279     }
+<a name="l00280"></a>00280         <span class="keywordflow">else</span> 
+<a name="l00281"></a>00281       {
+<a name="l00282"></a>00282             <span class="comment">/* No type means an object */</span>
+<a name="l00283"></a>00283         cfg->frametype[i] = FRAME_ON ;
+<a name="l00284"></a>00284             <span class="comment">/* No type means position 1 */</span>
+<a name="l00285"></a>00285         cfg->frameposition[i] = FRAME_POS1 ;
+<a name="l00286"></a>00286             
+<a name="l00287"></a>00287         nobj ++ ;
+<a name="l00288"></a>00288       }
+<a name="l00289"></a>00289       }
+<a name="l00290"></a>00290       
+<a name="l00291"></a>00291       <span class="comment">/* Store file name into framelist */</span>
+<a name="l00292"></a>00292     }
+<a name="l00293"></a>00293    
+<a name="l00294"></a>00294    sinfo_msg(<span class="stringliteral">"Noff= %d Nobj= %d Nditheroff= %d Nditherobj= %d"</span>,
+<a name="l00295"></a>00295            noff,nobj,nditheroff,nditherobj);
+<a name="l00296"></a>00296    
+<a name="l00297"></a>00297 
+<a name="l00298"></a>00298 
+<a name="l00299"></a>00299    <span class="comment">/* Copy relevant information into the blackboard */</span>
+<a name="l00300"></a>00300    cfg->nframes         = nraw ;
+<a name="l00301"></a>00301    cfg->nobj            = nobj ;
+<a name="l00302"></a>00302    cfg->noff            = noff ;
+<a name="l00303"></a>00303    cfg->ndark           = ndark ;
+<a name="l00304"></a>00304    cfg->nditherobj      = nditherobj ;
+<a name="l00305"></a>00305    cfg->nditheroff      = nditheroff ;
+<a name="l00306"></a>00306    cfg->contains_sky    = found_sky ;
+<a name="l00307"></a>00307    cfg->contains_ref    = found_ref ;
+<a name="l00308"></a>00308    cfg->contains_dither = found_dither ;
+<a name="l00309"></a>00309    cfg->contains_dark   = found_dark ;
+<a name="l00310"></a>00310 
+<a name="l00311"></a>00311 
+<a name="l00312"></a>00312    frame = cpl_frameset_get_frame(*raw_set,0);
+<a name="l00313"></a>00313 
+<a name="l00314"></a>00314    ck0_nomsg(sinfo_get_spatial_res(frame,spat_res));
+<a name="l00315"></a>00315 
+<a name="l00316"></a>00316 
+<a name="l00317"></a>00317 
+<a name="l00318"></a>00318    <span class="keywordflow">if</span>(sinfo_frame_is_on(frame) == 1) {
+<a name="l00319"></a>00319      strcpy(lamp_status,<span class="stringliteral">"on"</span>);
+<a name="l00320"></a>00320    } <span class="keywordflow">else</span> {
+<a name="l00321"></a>00321      strcpy(lamp_status,<span class="stringliteral">"off"</span>);
+<a name="l00322"></a>00322    }
+<a name="l00323"></a>00323    <span class="keywordflow">switch</span>(sinfo_frame_is_on(frame)) 
+<a name="l00324"></a>00324      {
+<a name="l00325"></a>00325    <span class="keywordflow">case</span> 0: 
+<a name="l00326"></a>00326       strcpy(lamp_status,<span class="stringliteral">"on"</span>);
+<a name="l00327"></a>00327       <span class="keywordflow">break</span>;
+<a name="l00328"></a>00328     <span class="keywordflow">case</span> 1: 
+<a name="l00329"></a>00329       strcpy(lamp_status,<span class="stringliteral">"off"</span>);
+<a name="l00330"></a>00330       <span class="keywordflow">break</span>;
+<a name="l00331"></a>00331     <span class="keywordflow">case</span> -1:
+<a name="l00332"></a>00332       strcpy(lamp_status,<span class="stringliteral">"undefined"</span>);
+<a name="l00333"></a>00333       <span class="keywordflow">break</span>;
+<a name="l00334"></a>00334     <span class="keywordflow">default</span>: 
+<a name="l00335"></a>00335       strcpy(lamp_status,<span class="stringliteral">"undefined"</span>);
+<a name="l00336"></a>00336       <span class="keywordflow">break</span>;
+<a name="l00337"></a>00337 
+<a name="l00338"></a>00338 
+<a name="l00339"></a>00339      }
+<a name="l00340"></a>00340    sinfo_get_band(frame,band);
+<a name="l00341"></a>00341 
+<a name="l00342"></a>00342 
+<a name="l00343"></a>00343    sinfo_msg(<span class="stringliteral">"Spatial resolution: %s lamp status: %s band: %s"</span>,
+<a name="l00344"></a>00344                      spat_res,              lamp_status,    band);
+<a name="l00345"></a>00345 
+<a name="l00346"></a>00346    sinfo_get_ins_set(band,&ins_set);
+<a name="l00347"></a>00347    frame = cpl_frameset_get_frame(*raw_set,0);
+<a name="l00348"></a>00348    tag=(<span class="keywordtype">char</span>*)cpl_frame_get_tag(frame);
+<a name="l00349"></a>00349 
+<a name="l00350"></a>00350 
+<a name="l00351"></a>00351    <span class="comment">/* Update flatInd setting if we had changed the mflat switch */</span>
+<a name="l00352"></a>00352     <span class="comment">/* take care of NS test special case */</span>
+<a name="l00353"></a>00353     <span class="keywordflow">if</span>(fk->frm_switch==1) {
+<a name="l00354"></a>00354      <span class="comment">/* </span>
+<a name="l00355"></a>00355 <span class="comment">        In this case we force certain values indipendently from the </span>
+<a name="l00356"></a>00356 <span class="comment">        setting occurring during CPL parameters parsing </span>
+<a name="l00357"></a>00357 <span class="comment">      */</span>
+<a name="l00358"></a>00358 
+<a name="l00359"></a>00359     cfg->maskInd = fk->mask_index;
+<a name="l00360"></a>00360     cfg->indind = fk->ind_index;
+<a name="l00361"></a>00361     cfg->flatInd = fk->flat_index;
+<a name="l00362"></a>00362         cfg -> loReject = fk->low_rej;
+<a name="l00363"></a>00363         cfg -> hiReject = fk->hig_rej;
+<a name="l00364"></a>00364         cfg -> warpfixInd =  fk->wfix_index;
+<a name="l00365"></a>00365     <span class="comment">/*</span>
+<a name="l00366"></a>00366 <span class="comment">        sinfo_msg("Fake frame: reset parameter values: ");</span>
+<a name="l00367"></a>00367 <span class="comment">        sinfo_msg("maskInd:  %d", cfg->maskInd);</span>
+<a name="l00368"></a>00368 <span class="comment">        sinfo_msg("indind:   %d", cfg->indind);</span>
+<a name="l00369"></a>00369 <span class="comment">        sinfo_msg("flatInd:  %d", cfg->flatInd);</span>
+<a name="l00370"></a>00370 <span class="comment">        sinfo_msg("loReject: %f", cfg->loReject);</span>
+<a name="l00371"></a>00371 <span class="comment">        sinfo_msg("hiReject: %f", cfg->hiReject);</span>
+<a name="l00372"></a>00372 <span class="comment">    */</span>
+<a name="l00373"></a>00373    }
+<a name="l00374"></a>00374   
+<a name="l00375"></a>00375   
+<a name="l00376"></a>00376 
+<a name="l00377"></a>00377 
+<a name="l00378"></a>00378  
+<a name="l00379"></a>00379    <span class="keywordflow">if</span>(cfg -> flatInd) { 
+<a name="l00380"></a>00380       <span class="keywordflow">if</span>(NULL != cpl_frameset_find(sof,PRO_MASTER_FLAT_LAMP)) {
+<a name="l00381"></a>00381          frame = cpl_frameset_find(sof,PRO_MASTER_FLAT_LAMP);
+<a name="l00382"></a>00382          strcpy(file,cpl_frame_get_filename(frame));
+<a name="l00383"></a>00383          strcpy(cfg -> flatfield1, file);
+<a name="l00384"></a>00384       } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(NULL != cpl_frameset_find(sof,PRO_MASTER_FLAT_LAMP1)) {
+<a name="l00385"></a>00385          frame = cpl_frameset_find(sof,PRO_MASTER_FLAT_LAMP1);
+<a name="l00386"></a>00386          strcpy(file,cpl_frame_get_filename(frame));
+<a name="l00387"></a>00387          strcpy(cfg -> flatfield1, file);
+<a name="l00388"></a>00388       } <span class="keywordflow">else</span> {
+<a name="l00389"></a>00389          <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Frame %s not found!"</span>, PRO_MASTER_FLAT_LAMP);
+<a name="l00390"></a>00390          <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Frame %s not found!"</span>, PRO_MASTER_FLAT_LAMP1);
+<a name="l00391"></a>00391          sinfo_stack_free_alloc(cfg);  
+<a name="l00392"></a>00392          (*status)++;
+<a name="l00393"></a>00393          <span class="keywordflow">return</span>;
+<a name="l00394"></a>00394       }
+<a name="l00395"></a>00395 
+<a name="l00396"></a>00396       <span class="keywordflow">if</span>(found_dither) {
+<a name="l00397"></a>00397          <span class="keywordflow">if</span>(NULL != cpl_frameset_find(sof,PRO_MASTER_FLAT_LAMP2)) {
+<a name="l00398"></a>00398             frame = cpl_frameset_find(sof,PRO_MASTER_FLAT_LAMP2);
+<a name="l00399"></a>00399             strcpy(file,cpl_frame_get_filename(frame));
+<a name="l00400"></a>00400             strcpy(cfg -> flatfield2, file);
+<a name="l00401"></a>00401          } <span class="keywordflow">else</span> {
+<a name="l00402"></a>00402             sinfo_msg(<span class="stringliteral">"Frame %s not found!"</span>, PRO_MASTER_FLAT_LAMP2);
+<a name="l00403"></a>00403          }
+<a name="l00404"></a>00404       }
+<a name="l00405"></a>00405    }
+<a name="l00406"></a>00406 
+<a name="l00407"></a>00407    <span class="comment">/* bad pixel section */</span>
+<a name="l00408"></a>00408    <span class="keywordflow">if</span>(cfg->maskInd != 0) {
+<a name="l00409"></a>00409      <span class="keywordflow">if</span>(strstr(do_class,<span class="stringliteral">"FIBRE_NS"</span>) != NULL) {
+<a name="l00410"></a>00410         <span class="keywordflow">if</span>(NULL != cpl_frameset_find(sof,PRO_BP_MAP_DI)) {
+<a name="l00411"></a>00411            frame = cpl_frameset_find(sof,PRO_BP_MAP_DI);
+<a name="l00412"></a>00412            strcpy(file,cpl_frame_get_filename(frame));
+<a name="l00413"></a>00413            strcpy(cfg -> mask, file);
+<a name="l00414"></a>00414         } <span class="keywordflow">else</span> {
+<a name="l00415"></a>00415            <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Frame %s not found!"</span>, PRO_BP_MAP_DI);
+<a name="l00416"></a>00416            sinfo_stack_free_alloc(cfg);  
+<a name="l00417"></a>00417            (*status)++;
+<a name="l00418"></a>00418            <span class="keywordflow">return</span>;
+<a name="l00419"></a>00419         }
+<a name="l00420"></a>00420 
+<a name="l00421"></a>00421      } <span class="keywordflow">else</span> {
+<a name="l00422"></a>00422 
+<a name="l00423"></a>00423         <span class="keywordflow">if</span>(NULL != cpl_frameset_find(sof,PRO_MASTER_BP_MAP)) {
+<a name="l00424"></a>00424            frame = cpl_frameset_find(sof,PRO_MASTER_BP_MAP);
+<a name="l00425"></a>00425            strcpy(file,cpl_frame_get_filename(frame));
+<a name="l00426"></a>00426            strcpy(cfg -> mask, file);
+<a name="l00427"></a>00427         } <span class="keywordflow">else</span> {
+<a name="l00428"></a>00428            <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Frame %s not found!"</span>, PRO_MASTER_BP_MAP);
+<a name="l00429"></a>00429            sinfo_stack_free_alloc(cfg);  
+<a name="l00430"></a>00430            (*status)++;
+<a name="l00431"></a>00431            <span class="keywordflow">return</span>;
+<a name="l00432"></a>00432         }
+<a name="l00433"></a>00433 
+<a name="l00434"></a>00434      }
+<a name="l00435"></a>00435 
+<a name="l00436"></a>00436      <span class="keywordflow">if</span> (strcmp(do_class,RAW_STACKED_SLITPOS) == 0) {
+<a name="l00437"></a>00437        cfg -> indind = 1;
+<a name="l00438"></a>00438      }
+<a name="l00439"></a>00439 
+<a name="l00440"></a>00440       <span class="keywordflow">if</span>(cfg -> indind == 0) { 
+<a name="l00441"></a>00441           <span class="keywordflow">if</span>(NULL != cpl_frameset_find(sof,PRO_SLIT_POS)) {
+<a name="l00442"></a>00442             frame = cpl_frameset_find(sof,PRO_SLIT_POS);
+<a name="l00443"></a>00443             strcpy(file,cpl_frame_get_filename(frame));
+<a name="l00444"></a>00444             strcpy(cfg -> slitposList, file);
+<a name="l00445"></a>00445             sinfo_msg(<span class="stringliteral">"Using %s to interpolate bad pixels"</span>,
+<a name="l00446"></a>00446                              PRO_SLIT_POS);
+<a name="l00447"></a>00447             cpl_error_reset();
+<a name="l00448"></a>00448           } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(NULL != cpl_frameset_find(sof,PRO_SLIT_POS_GUESS)) {
+<a name="l00449"></a>00449             frame = cpl_frameset_find(sof,PRO_SLIT_POS_GUESS);
+<a name="l00450"></a>00450             strcpy(file,cpl_frame_get_filename(frame));
+<a name="l00451"></a>00451             strcpy(cfg -> slitposList, file);
+<a name="l00452"></a>00452             sinfo_msg(<span class="stringliteral">"Using %s to interpolated bad pixels"</span>,
+<a name="l00453"></a>00453                              PRO_SLIT_POS_GUESS);
+<a name="l00454"></a>00454             cpl_error_reset();
+<a name="l00455"></a>00455           } <span class="keywordflow">else</span> {
+<a name="l00456"></a>00456             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Frame %s nor %s found!"</span>, 
+<a name="l00457"></a>00457                               PRO_SLIT_POS,PRO_SLIT_POS_GUESS);
+<a name="l00458"></a>00458             sinfo_stack_free_alloc(cfg);  
+<a name="l00459"></a>00459             (*status)++;
+<a name="l00460"></a>00460             <span class="keywordflow">return</span>;
+<a name="l00461"></a>00461           }
+<a name="l00462"></a>00462 
+<a name="l00463"></a>00463      
+<a name="l00464"></a>00464       }
+<a name="l00465"></a>00465       <span class="keywordflow">if</span>(cfg -> maskInd == 2) {
+<a name="l00466"></a>00466          <span class="keywordflow">if</span>(NULL != cpl_frameset_find(sof,PRO_INDEX_LIST)) {
+<a name="l00467"></a>00467             frame = cpl_frameset_find(sof,PRO_INDEX_LIST);
+<a name="l00468"></a>00468             strcpy(file,cpl_frame_get_filename(frame));
+<a name="l00469"></a>00469             strcpy(cfg ->indexlist, file);
+<a name="l00470"></a>00470          } <span class="keywordflow">else</span> {
+<a name="l00471"></a>00471             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Frame %s not found!"</span>, PRO_INDEX_LIST);
+<a name="l00472"></a>00472             sinfo_stack_free_alloc(cfg);  
+<a name="l00473"></a>00473             (*status)++;
+<a name="l00474"></a>00474             <span class="keywordflow">return</span>;
+<a name="l00475"></a>00475          }
+<a name="l00476"></a>00476 
+<a name="l00477"></a>00477       }
+<a name="l00478"></a>00478    }
+<a name="l00479"></a>00479 
+<a name="l00480"></a>00480    cfg -> warpfixInd =  fk->wfix_index;
+<a name="l00481"></a>00481    <span class="keywordflow">if</span>(cfg->warpfixInd != 0) {
+<a name="l00482"></a>00482         <span class="keywordflow">if</span>(NULL != cpl_frameset_find(sof,PRO_DISTORTION)) {
+<a name="l00483"></a>00483             frame = cpl_frameset_find(sof,PRO_DISTORTION);
+<a name="l00484"></a>00484             strcpy(file,cpl_frame_get_filename(frame));
+<a name="l00485"></a>00485             strcpy(cfg -> polyFile, file);
+<a name="l00486"></a>00486          } <span class="keywordflow">else</span> {
+<a name="l00487"></a>00487             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Frame %s not found!"</span>, PRO_DISTORTION);
+<a name="l00488"></a>00488             sinfo_stack_free_alloc(cfg);  
+<a name="l00489"></a>00489             (*status)++;
+<a name="l00490"></a>00490             <span class="keywordflow">return</span>;
+<a name="l00491"></a>00491          }
+<a name="l00492"></a>00492    }
+<a name="l00493"></a>00493 
+<a name="l00494"></a>00494    <span class="keywordflow">if</span>(NULL != cpl_frameset_find(sof,PRO_MASTER_DARK)) {
+<a name="l00495"></a>00495      frame = cpl_frameset_find(sof,PRO_MASTER_DARK);
+<a name="l00496"></a>00496      strcpy(file,cpl_frame_get_filename(frame));
+<a name="l00497"></a>00497      strcpy(cfg -> mdark, file);
+<a name="l00498"></a>00498      cfg->mdark_ind=1;
+<a name="l00499"></a>00499 
+<a name="l00500"></a>00500    } <span class="keywordflow">else</span> {
+<a name="l00501"></a>00501      sinfo_msg(<span class="stringliteral">"Frame %s not found"</span>, PRO_MASTER_DARK);
+<a name="l00502"></a>00502      cfg->mdark_ind=0;
+<a name="l00503"></a>00503    }
+<a name="l00504"></a>00504 
+<a name="l00505"></a>00505   cleanup:
+<a name="l00506"></a>00506    return ;
+<a name="l00507"></a>00507 }
+<a name="l00508"></a>00508 
+<a name="l00516"></a>00516 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00517"></a>00517 parse_section_cleanmean(stack_config_n * cfg,cpl_parameterlist* cpl_cfg)
+<a name="l00518"></a>00518 {
+<a name="l00519"></a>00519 
+<a name="l00520"></a>00520    cpl_parameter* p;
+<a name="l00521"></a>00521    p = cpl_parameterlist_find(cpl_cfg,<span class="stringliteral">"sinfoni.stacked.low_rejection"</span>);
+<a name="l00522"></a>00522    cfg -> loReject = cpl_parameter_get_double(p);
+<a name="l00523"></a>00523 
+<a name="l00524"></a>00524    p = cpl_parameterlist_find(cpl_cfg,<span class="stringliteral">"sinfoni.stacked.high_rejection"</span>);
+<a name="l00525"></a>00525    cfg -> hiReject = cpl_parameter_get_double(p);
+<a name="l00526"></a>00526 
+<a name="l00527"></a>00527         return ;
+<a name="l00528"></a>00528 }
+<a name="l00535"></a>00535 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00536"></a>00536 parse_section_flatfield(stack_config_n * cfg,cpl_parameterlist* cpl_cfg)
+<a name="l00537"></a>00537 {
+<a name="l00538"></a>00538 
+<a name="l00539"></a>00539    cpl_parameter* p;
+<a name="l00540"></a>00540    p = cpl_parameterlist_find(cpl_cfg,<span class="stringliteral">"sinfoni.stacked.flat_index"</span>);
+<a name="l00541"></a>00541    cfg -> flatInd = cpl_parameter_get_bool(p);
+<a name="l00542"></a>00542 
+<a name="l00543"></a>00543 }
+<a name="l00550"></a>00550 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00551"></a>00551 parse_section_badpixel(stack_config_n * cfg,cpl_parameterlist* cpl_cfg)
+<a name="l00552"></a>00552 {
+<a name="l00553"></a>00553   cpl_parameter* p;
+<a name="l00554"></a>00554 
+<a name="l00555"></a>00555 
+<a name="l00556"></a>00556    p = cpl_parameterlist_find(cpl_cfg,<span class="stringliteral">"sinfoni.stacked.ind_index"</span>);
+<a name="l00557"></a>00557    cfg -> indind = cpl_parameter_get_bool(p);
+<a name="l00558"></a>00558 
+<a name="l00559"></a>00559    p = cpl_parameterlist_find(cpl_cfg,<span class="stringliteral">"sinfoni.stacked.mask_index"</span>);
+<a name="l00560"></a>00560    cfg -> maskInd = cpl_parameter_get_int(p);
+<a name="l00561"></a>00561 
+<a name="l00562"></a>00562    p = cpl_parameterlist_find(cpl_cfg,<span class="stringliteral">"sinfoni.stacked.mask_rad"</span>);
+<a name="l00563"></a>00563    cfg -> maxRad = cpl_parameter_get_int(p);
+<a name="l00564"></a>00564    <span class="comment">/*</span>
+<a name="l00565"></a>00565 <span class="comment">   p = cpl_parameterlist_find(cpl_cfg,"sinfoni.stacked.sigma_factor");</span>
+<a name="l00566"></a>00566 <span class="comment">   */</span>
+<a name="l00567"></a>00567    cfg -> sigmaFactor = 3.;
+<a name="l00568"></a>00568 
+<a name="l00569"></a>00569 }
+<a name="l00575"></a>00575 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00576"></a>00576 parse_section_interleaving(stack_config_n * cfg)
+<a name="l00577"></a>00577 {
+<a name="l00578"></a>00578    cfg -> interInd = 0;
+<a name="l00579"></a>00579    cfg -> noRows = 400;
+<a name="l00580"></a>00580 
+<a name="l00581"></a>00581 }
+<a name="l00588"></a>00588 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00589"></a>00589 parse_section_gaussconvolution(stack_config_n * cfg,cpl_parameterlist* cpl_cfg)
+<a name="l00590"></a>00590 {
+<a name="l00591"></a>00591 
+<a name="l00592"></a>00592    cpl_parameter* p;
+<a name="l00593"></a>00593    p = cpl_parameterlist_find(cpl_cfg,<span class="stringliteral">"sinfoni.stacked.gauss_index"</span>);
+<a name="l00594"></a>00594    cfg -> gaussInd = cpl_parameter_get_bool(p);
+<a name="l00595"></a>00595 
+<a name="l00596"></a>00596    p = cpl_parameterlist_find(cpl_cfg,<span class="stringliteral">"sinfoni.stacked.kernel_half_width"</span>);
+<a name="l00597"></a>00597    cfg -> hw = cpl_parameter_get_int(p);
+<a name="l00598"></a>00598 
+<a name="l00599"></a>00599 }
+<a name="l00605"></a>00605 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00606"></a>00606 parse_section_shiftframes(stack_config_n * cfg)
+<a name="l00607"></a>00607 {
+<a name="l00608"></a>00608   <span class="comment">/*</span>
+<a name="l00609"></a>00609 <span class="comment">   cpl_parameter* p;</span>
+<a name="l00610"></a>00610 <span class="comment">   p = cpl_parameterlist_find(cpl_cfg,"sinfoni.stacked.shift_frame_index");</span>
+<a name="l00611"></a>00611 <span class="comment">   cfg -> sfInd  = cpl_parameter_get_bool(p);</span>
+<a name="l00612"></a>00612 <span class="comment"></span>
+<a name="l00613"></a>00613 <span class="comment">   p = cpl_parameterlist_find(cpl_cfg,"sinfoni.stacked.shift_frame_type");</span>
+<a name="l00614"></a>00614 <span class="comment">   cfg -> sfType = cpl_parameter_get_int(p);</span>
+<a name="l00615"></a>00615 <span class="comment"></span>
+<a name="l00616"></a>00616 <span class="comment">   p = cpl_parameterlist_find(cpl_cfg,"sinfoni.stacked.shift_frame_order");</span>
+<a name="l00617"></a>00617 <span class="comment">   cfg -> sfOrder = cpl_parameter_get_int(p);</span>
+<a name="l00618"></a>00618 <span class="comment">  */</span>
+<a name="l00619"></a>00619 
+<a name="l00620"></a>00620    cfg -> sfInd  = 0;
+<a name="l00621"></a>00621    cfg -> sfType = 1;
+<a name="l00622"></a>00622    cfg -> sfOrder = 2;
+<a name="l00623"></a>00623 
+<a name="l00624"></a>00624 }
+<a name="l00631"></a>00631 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00632"></a>00632 parse_section_warpfix(stack_config_n * cfg,cpl_parameterlist * cpl_cfg)
+<a name="l00633"></a>00633 {
+<a name="l00634"></a>00634        
+<a name="l00635"></a>00635    cpl_parameter* p;
+<a name="l00636"></a>00636 
+<a name="l00637"></a>00637    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.stacked.warpfix_ind"</span>);
+<a name="l00638"></a>00638    cfg -> warpfixInd =  cpl_parameter_get_bool(p);
+<a name="l00639"></a>00639 
+<a name="l00640"></a>00640 
+<a name="l00641"></a>00641    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.stacked.warpfix_kernel"</span>);
+<a name="l00642"></a>00642    strcpy(cfg -> kernel, cpl_parameter_get_string(p));
+<a name="l00643"></a>00643 
+<a name="l00644"></a>00644    return ;
+<a name="l00645"></a>00645 }
+<a name="l00646"></a>00646 
+<a name="l00653"></a>00653 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00654"></a>00654 parse_section_qclog(stack_config_n * cfg,cpl_parameterlist * cpl_cfg)
+<a name="l00655"></a>00655 {
+<a name="l00656"></a>00656        
+<a name="l00657"></a>00657    cpl_parameter* p;
+<a name="l00658"></a>00658 
+<a name="l00659"></a>00659    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.stacked.qc_thresh_min"</span>);
+<a name="l00660"></a>00660    cfg -> qc_thresh_min =  cpl_parameter_get_int(p);
+<a name="l00661"></a>00661 
+<a name="l00662"></a>00662    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.stacked.qc_thresh_max"</span>);
+<a name="l00663"></a>00663    cfg -> qc_thresh_max =  cpl_parameter_get_int(p);
+<a name="l00664"></a>00664 
+<a name="l00665"></a>00665    return ;
+<a name="l00666"></a>00666 }
+<a name="l00672"></a>00672 <span class="keywordtype">void</span>
+<a name="l00673"></a>00673 sinfo_stack_free(stack_config_n ** cfg)
+<a name="l00674"></a>00674 {  
+<a name="l00675"></a>00675   <span class="keywordflow">if</span>(*cfg != NULL) {
+<a name="l00676"></a>00676     sinfo_stack_free_alloc(*cfg);
+<a name="l00677"></a>00677     sinfo_stack_cfg_destroy_n(*cfg);
+<a name="l00678"></a>00678     *cfg = NULL;
+<a name="l00679"></a>00679   }
+<a name="l00680"></a>00680   <span class="keywordflow">return</span>;
+<a name="l00681"></a>00681 
+<a name="l00682"></a>00682 }
+<a name="l00683"></a>00683 
+<a name="l00689"></a>00689 <span class="keyword">static</span> <span class="keywordtype">void</span>
+<a name="l00690"></a>00690 sinfo_stack_free_alloc(stack_config_n * cfg)
+<a name="l00691"></a>00691 {  
+<a name="l00692"></a>00692   <span class="keywordtype">int</span> i=0;
+<a name="l00693"></a>00693   <span class="keywordflow">for</span> (i=0; i< cfg->nframes; i++) {
+<a name="l00694"></a>00694     <span class="keywordflow">if</span>(cfg->framelist[i]  != NULL) {
+<a name="l00695"></a>00695         cpl_free(cfg->framelist[i]);
+<a name="l00696"></a>00696              cfg->framelist[i]=NULL;
+<a name="l00697"></a>00697     }
+<a name="l00698"></a>00698   }
+<a name="l00699"></a>00699   <span class="keywordflow">if</span>(cfg->frametype != NULL) {
+<a name="l00700"></a>00700     cpl_free(cfg->frametype); 
+<a name="l00701"></a>00701     cfg->frametype=NULL;
+<a name="l00702"></a>00702   }
+<a name="l00703"></a>00703   <span class="keywordflow">if</span>(cfg->framelist != NULL)   {
+<a name="l00704"></a>00704     cpl_free(cfg->framelist); 
+<a name="l00705"></a>00705     cfg->framelist=NULL;
+<a name="l00706"></a>00706   }
+<a name="l00707"></a>00707   <span class="keywordflow">if</span>(cfg->frameposition != NULL) {
+<a name="l00708"></a>00708     cpl_free(cfg->frameposition); 
+<a name="l00709"></a>00709     cfg->frameposition=NULL;
+<a name="l00710"></a>00710   }
+<a name="l00711"></a>00711 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__stack__ini__by__cpl_8h_source.html b/html/sinfo__stack__ini__by__cpl_8h_source.html
new file mode 100644
index 0000000..cdcda5a
--- /dev/null
+++ b/html/sinfo__stack__ini__by__cpl_8h_source.html
@@ -0,0 +1,73 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_stack_ini_by_cpl.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_stack_ini_by_cpl.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name    :   stack_ini_by_cpl.h</span>
+<a name="l00022"></a>00022 <span class="comment">   Author       :   Andrea Modigliani</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on   :   May 23, 2004</span>
+<a name="l00024"></a>00024 <span class="comment">   Description  :   preparing stack of frames cpl input handling for SPIFFI</span>
+<a name="l00025"></a>00025 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00026"></a>00026 <span class="preprocessor">#ifndef SINFO_STACK_INI_BY_CPL_H</span>
+<a name="l00027"></a>00027 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_STACK_INI_BY_CPL_H</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00029"></a>00029 <span class="comment">                                Includes</span>
+<a name="l00030"></a>00030 <span class="comment">---------------------------------------------------------------------------*/</span>
+<a name="l00031"></a>00031 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00032"></a>00032 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include "sinfo_globals.h"</span>
+<a name="l00034"></a>00034 <span class="preprocessor">#include "sinfo_stack_cfg.h"</span>
+<a name="l00035"></a>00035 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00036"></a>00036 <span class="comment">                                Defines</span>
+<a name="l00037"></a>00037 <span class="comment">---------------------------------------------------------------------------*/</span>
+<a name="l00038"></a>00038 <span class="preprocessor">#define FRAME_OFF    0  </span><span class="comment">/* off frames, that means sky frames </span>
+<a name="l00039"></a>00039 <span class="comment">                           or calibration frames with lamp switched off */</span>
+<a name="l00040"></a>00040 <span class="preprocessor">#define FRAME_ON     1  </span><span class="comment">/* object frames */</span>
+<a name="l00041"></a>00041 <span class="preprocessor">#define FRAME_POS1   2  </span><span class="comment">/* frames exposed with grating position 1 */</span>
+<a name="l00042"></a>00042 <span class="preprocessor">#define FRAME_POS2   3  </span><span class="comment">/* frames exposed with dithered grating position 2 */</span>
+<a name="l00043"></a>00043 <span class="preprocessor">#define FRAME_REF    4  </span><span class="comment">/* reference frames */</span>
+<a name="l00044"></a>00044 <span class="preprocessor">#define FRAME_DRK    5  </span><span class="comment">/* sinfo_dark frame*/</span>
+<a name="l00045"></a>00045 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00046"></a>00046 <span class="comment">                             Function prototypes </span>
+<a name="l00047"></a>00047 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00048"></a>00048 <span class="comment">/* generateStack_ini_file */</span>
+<a name="l00061"></a>00061 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00062"></a>00062 stack_config_n * 
+<a name="l00063"></a>00063 sinfo_parse_cpl_input_stack(cpl_parameterlist * cpl_cfg, 
+<a name="l00064"></a>00064                             cpl_frameset* sof, 
+<a name="l00065"></a>00065                             cpl_frameset** raw, 
+<a name="l00066"></a>00066                             fake* fk) ;
+<a name="l00067"></a>00067 <span class="keywordtype">void</span> sinfo_stack_free(stack_config_n ** cfg);
+<a name="l00068"></a>00068 
+<a name="l00069"></a>00069 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__stacked__hidden__config_8c_source.html b/html/sinfo__stacked__hidden__config_8c_source.html
new file mode 100644
index 0000000..436623d
--- /dev/null
+++ b/html/sinfo__stacked__hidden__config_8c_source.html
@@ -0,0 +1,86 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_stacked_hidden_config.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_stacked_hidden_config.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_stacked_hidden_config.c,v 1.5 2012/03/03 10:18:26 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the CPL (Common Pipeline Library)</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
+<a name="l00007"></a>00007 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span>
+<a name="l00008"></a>00008 <span class="comment"> * License as published by the Free Software Foundation; either</span>
+<a name="l00009"></a>00009 <span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
+<a name="l00014"></a>00014 <span class="comment"> * Lesser General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
+<a name="l00017"></a>00017 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2012/03/03 10:18:26 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.5 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> */</span>
+<a name="l00026"></a>00026 
+<a name="l00027"></a>00027  <span class="comment">/**************************************************************************</span>
+<a name="l00028"></a>00028 <span class="comment">  *  Prepare_Stacked_Frames Frames Data Reduction Parameter Initialization *</span>
+<a name="l00029"></a>00029 <span class="comment">  **************************************************************************/</span>
+<a name="l00030"></a>00030 
+<a name="l00031"></a>00031 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00032"></a>00032 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00033"></a>00033 <span class="preprocessor">#endif</span>
+<a name="l00034"></a>00034 <span class="preprocessor"></span>
+<a name="l00035"></a>00035 <span class="preprocessor">#include "sinfo_stacked_hidden_config.h"</span>
+<a name="l00049"></a>00049 <span class="keywordtype">void</span>
+<a name="l00050"></a>00050  sinfo_stacked_hidden_config_add(cpl_parameterlist *list)
+<a name="l00051"></a>00051 {
+<a name="l00052"></a>00052 
+<a name="l00053"></a>00053   cpl_parameter *p;
+<a name="l00054"></a>00054 
+<a name="l00055"></a>00055   <span class="keywordflow">if</span> (!list) {
+<a name="l00056"></a>00056     <span class="keywordflow">return</span>;
+<a name="l00057"></a>00057   }
+<a name="l00058"></a>00058 
+<a name="l00059"></a>00059 
+<a name="l00060"></a>00060 <span class="comment">/*</span>
+<a name="l00061"></a>00061 <span class="comment">  --------------------------------------------------------------------------</span>
+<a name="l00062"></a>00062 <span class="comment">  In/Out  </span>
+<a name="l00063"></a>00063 <span class="comment">  --------------------------------------------------------------------------</span>
+<a name="l00064"></a>00064 <span class="comment"> */</span>
+<a name="l00065"></a>00065 
+<a name="l00066"></a>00066 
+<a name="l00067"></a>00067 
+<a name="l00068"></a>00068   <span class="comment">/* Output file name */</span>
+<a name="l00069"></a>00069   <span class="comment">/* output name of resulting fits wavelength map */</span>
+<a name="l00070"></a>00070   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.stacked.output_filename"</span>,
+<a name="l00071"></a>00071                   CPL_TYPE_STRING,
+<a name="l00072"></a>00072                               <span class="stringliteral">"Output File Name: "</span>,
+<a name="l00073"></a>00073                               <span class="stringliteral">"sinfoni.stacked"</span>,
+<a name="l00074"></a>00074                               <span class="stringliteral">"out_stack.fits"</span>);
+<a name="l00075"></a>00075 
+<a name="l00076"></a>00076 
+<a name="l00077"></a>00077   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"out-stack_filename"</span>);
+<a name="l00078"></a>00078   cpl_parameterlist_append(list, p);
+<a name="l00079"></a>00079 
+<a name="l00080"></a>00080 
+<a name="l00081"></a>00081 
+<a name="l00082"></a>00082 
+<a name="l00083"></a>00083 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__stacked__hidden__config_8h_source.html b/html/sinfo__stacked__hidden__config_8h_source.html
new file mode 100644
index 0000000..b40e9cd
--- /dev/null
+++ b/html/sinfo__stacked__hidden__config_8h_source.html
@@ -0,0 +1,49 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_stacked_hidden_config.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_stacked_hidden_config.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_stacked_hidden_config.h,v 1.1 2006/10/20 08:06:33 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the CPL (Common Pipeline Library)</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
+<a name="l00007"></a>00007 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span>
+<a name="l00008"></a>00008 <span class="comment"> * License as published by the Free Software Foundation; either</span>
+<a name="l00009"></a>00009 <span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
+<a name="l00014"></a>00014 <span class="comment"> * Lesser General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
+<a name="l00017"></a>00017 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2006/10/20 08:06:33 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.1 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> */</span>
+<a name="l00026"></a>00026 
+<a name="l00027"></a>00027  <span class="comment">/****************************************************************</span>
+<a name="l00028"></a>00028 <span class="comment">  *   Prepare_Stacked_Frames Frames Data Reduction Parameter Initialization </span>
+<a name="l00029"></a>00029 <span class="comment">  ****************************************************************/</span>
+<a name="l00030"></a>00030 <span class="preprocessor">#include "cpl.h"</span>    <span class="comment">/* defines parlist structure */</span>
+<a name="l00031"></a>00031 
+<a name="l00032"></a>00032 <span class="keywordtype">void</span>
+<a name="l00033"></a>00033 sinfo_stacked_hidden_config_add(cpl_parameterlist *list);
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__standard__star__config_8c_source.html b/html/sinfo__standard__star__config_8c_source.html
new file mode 100644
index 0000000..150bd57
--- /dev/null
+++ b/html/sinfo__standard__star__config_8c_source.html
@@ -0,0 +1,156 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_standard_star_config.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_standard_star_config.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_standard_star_config.c,v 1.7 2012/03/03 10:18:26 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the CPL (Common Pipeline Library)</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
+<a name="l00007"></a>00007 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span>
+<a name="l00008"></a>00008 <span class="comment"> * License as published by the Free Software Foundation; either</span>
+<a name="l00009"></a>00009 <span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
+<a name="l00014"></a>00014 <span class="comment"> * Lesser General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
+<a name="l00017"></a>00017 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2012/03/03 10:18:26 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.7 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> */</span>
+<a name="l00026"></a>00026 
+<a name="l00027"></a>00027  <span class="comment">/****************************************************************</span>
+<a name="l00028"></a>00028 <span class="comment">  *   Standard_Star Frames Data Reduction Parameter Initialization        *</span>
+<a name="l00029"></a>00029 <span class="comment">  ****************************************************************/</span>
+<a name="l00030"></a>00030 
+<a name="l00031"></a>00031 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00032"></a>00032 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00033"></a>00033 <span class="preprocessor">#endif</span>
+<a name="l00034"></a>00034 <span class="preprocessor"></span>
+<a name="l00035"></a>00035 <span class="preprocessor">#include <string.h></span>
+<a name="l00036"></a>00036 <span class="preprocessor">#include "sinfo_standard_star_config.h"</span>
+<a name="l00050"></a>00050 <span class="keywordtype">void</span>
+<a name="l00051"></a>00051  sinfo_standard_star_config_add(cpl_parameterlist *list)
+<a name="l00052"></a>00052 {
+<a name="l00053"></a>00053 
+<a name="l00054"></a>00054   cpl_parameter *p;
+<a name="l00055"></a>00055 
+<a name="l00056"></a>00056   <span class="keywordflow">if</span> (!list) {
+<a name="l00057"></a>00057     <span class="keywordflow">return</span>;
+<a name="l00058"></a>00058   }
+<a name="l00059"></a>00059 
+<a name="l00060"></a>00060 
+<a name="l00061"></a>00061 <span class="comment">/*</span>
+<a name="l00062"></a>00062 <span class="comment">  --------------------------------------------------------------------------</span>
+<a name="l00063"></a>00063 <span class="comment">  In/Out  </span>
+<a name="l00064"></a>00064 <span class="comment">  --------------------------------------------------------------------------</span>
+<a name="l00065"></a>00065 <span class="comment"> */</span>
+<a name="l00066"></a>00066 
+<a name="l00067"></a>00067   <span class="comment">/* switch to generate the extracted spectrum */</span>
+<a name="l00068"></a>00068   <span class="comment">/*</span>
+<a name="l00069"></a>00069 <span class="comment">  p = cpl_parameter_new_value("sinfoni.std_star.qc_info",</span>
+<a name="l00070"></a>00070 <span class="comment">                  CPL_TYPE_BOOL,</span>
+<a name="l00071"></a>00071 <span class="comment">                              "Switch to activate extra QC information "</span>
+<a name="l00072"></a>00072 <span class="comment">                              "together with the spectrum",</span>
+<a name="l00073"></a>00073 <span class="comment">                              "sinfoni.std_star",</span>
+<a name="l00074"></a>00074 <span class="comment">                              FALSE);</span>
+<a name="l00075"></a>00075 <span class="comment"></span>
+<a name="l00076"></a>00076 <span class="comment">  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"std_star-qc_info");</span>
+<a name="l00077"></a>00077 <span class="comment">  cpl_parameterlist_append(list, p);</span>
+<a name="l00078"></a>00078 <span class="comment">  */</span>
+<a name="l00079"></a>00079 
+<a name="l00080"></a>00080   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.std_star.switch"</span>,
+<a name="l00081"></a>00081                   CPL_TYPE_BOOL,
+<a name="l00082"></a>00082                               <span class="stringliteral">"Switch to activate spectrum extraction"</span>,
+<a name="l00083"></a>00083                               <span class="stringliteral">"sinfoni.std_star"</span>,
+<a name="l00084"></a>00084                               TRUE);
+<a name="l00085"></a>00085 
+<a name="l00086"></a>00086   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"std_star-switch"</span>);
+<a name="l00087"></a>00087   cpl_parameterlist_append(list, p);
+<a name="l00088"></a>00088 
+<a name="l00089"></a>00089 <span class="comment">/* the fraction [0...1] of rejected low intensity pixels when taking </span>
+<a name="l00090"></a>00090 <span class="comment">the average of columns */</span>
+<a name="l00091"></a>00091   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.std_star.low_rejection"</span>,
+<a name="l00092"></a>00092                   CPL_TYPE_DOUBLE,
+<a name="l00093"></a>00093                               <span class="stringliteral">"lower rejection"</span>,
+<a name="l00094"></a>00094                               <span class="stringliteral">"sinfoni.std_star"</span>,
+<a name="l00095"></a>00095                               0.1);
+<a name="l00096"></a>00096 
+<a name="l00097"></a>00097   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"std_star-lo_rej"</span>);
+<a name="l00098"></a>00098   cpl_parameterlist_append(list, p);
+<a name="l00099"></a>00099 
+<a name="l00100"></a>00100  <span class="comment">/* the fraction [0...1] of rejected high intensity pixels when taking </span>
+<a name="l00101"></a>00101 <span class="comment">the average of columns */</span>
+<a name="l00102"></a>00102   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.std_star.high_rejection"</span>,
+<a name="l00103"></a>00103                   CPL_TYPE_DOUBLE,
+<a name="l00104"></a>00104                               <span class="stringliteral">"high rejection"</span>,
+<a name="l00105"></a>00105                               <span class="stringliteral">"sinfoni.std_star"</span>,
+<a name="l00106"></a>00106                               0.1);
+<a name="l00107"></a>00107 
+<a name="l00108"></a>00108   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"std_star-hi_rej"</span>);
+<a name="l00109"></a>00109   cpl_parameterlist_append(list, p);
+<a name="l00110"></a>00110 
+<a name="l00111"></a>00111 
+<a name="l00112"></a>00112 <span class="comment">/* factor applied to the found fwhms of a 2D-Gaussian fit, defines the radius </span>
+<a name="l00113"></a>00113 <span class="comment">   of the aperture inside which the spectral extraction is carried out.</span>
+<a name="l00114"></a>00114 <span class="comment"> */</span>
+<a name="l00115"></a>00115   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.std_star.fwhm_factor"</span>,
+<a name="l00116"></a>00116                   CPL_TYPE_DOUBLE,
+<a name="l00117"></a>00117                               <span class="stringliteral">"Factor to find 2D-Gauss FWHM. "</span>
+<a name="l00118"></a>00118                               <span class="stringliteral">"The extraction box is: "</span>
+<a name="l00119"></a>00119                               <span class="stringliteral">"halfbox_x=halfbox_y="</span>
+<a name="l00120"></a>00120                               <span class="stringliteral">"fwhm_factor*(fwhm_x+fwhm_y)*0.5"</span>,
+<a name="l00121"></a>00121                               <span class="stringliteral">"sinfoni.std_star"</span>,
+<a name="l00122"></a>00122                               5.0);
+<a name="l00123"></a>00123 
+<a name="l00124"></a>00124   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"std_star-fwhm_fct"</span>);
+<a name="l00125"></a>00125   cpl_parameterlist_append(list, p);
+<a name="l00126"></a>00126 
+<a name="l00127"></a>00127 
+<a name="l00128"></a>00128 <span class="comment">/* indicator if the intensity conversion factor should be determined or not</span>
+<a name="l00129"></a>00129 <span class="comment"> */</span>
+<a name="l00130"></a>00130 
+<a name="l00131"></a>00131 
+<a name="l00132"></a>00132   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.std_star.conversion_index"</span>,
+<a name="l00133"></a>00133                   CPL_TYPE_BOOL,
+<a name="l00134"></a>00134                               <span class="stringliteral">"Intensity Conversion Index: "</span>,
+<a name="l00135"></a>00135                               <span class="stringliteral">"sinfoni.std_star"</span>,
+<a name="l00136"></a>00136                               TRUE);
+<a name="l00137"></a>00137 
+<a name="l00138"></a>00138   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"std_star-conv_ind"</span>);
+<a name="l00139"></a>00139   cpl_parameterlist_append(list, p);
+<a name="l00140"></a>00140 
+<a name="l00141"></a>00141   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.std_star.compute_eff"</span>,
+<a name="l00142"></a>00142                   CPL_TYPE_BOOL,
+<a name="l00143"></a>00143                               <span class="stringliteral">"Compute efficiency: TRUE/FALSE"</span>,
+<a name="l00144"></a>00144                               <span class="stringliteral">"sinfoni.std_star"</span>,
+<a name="l00145"></a>00145                               TRUE);
+<a name="l00146"></a>00146 
+<a name="l00147"></a>00147   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"std_star-compute_eff"</span>);
+<a name="l00148"></a>00148   cpl_parameterlist_append(list, p);
+<a name="l00149"></a>00149 
+<a name="l00150"></a>00150 
+<a name="l00151"></a>00151 
+<a name="l00152"></a>00152 
+<a name="l00153"></a>00153 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__standard__star__config_8h_source.html b/html/sinfo__standard__star__config_8h_source.html
new file mode 100644
index 0000000..3b00a57
--- /dev/null
+++ b/html/sinfo__standard__star__config_8h_source.html
@@ -0,0 +1,49 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_standard_star_config.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_standard_star_config.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_standard_star_config.h,v 1.1 2006/10/20 08:06:33 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the CPL (Common Pipeline Library)</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
+<a name="l00007"></a>00007 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span>
+<a name="l00008"></a>00008 <span class="comment"> * License as published by the Free Software Foundation; either</span>
+<a name="l00009"></a>00009 <span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
+<a name="l00014"></a>00014 <span class="comment"> * Lesser General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
+<a name="l00017"></a>00017 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2006/10/20 08:06:33 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.1 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> */</span>
+<a name="l00026"></a>00026 
+<a name="l00027"></a>00027  <span class="comment">/****************************************************************</span>
+<a name="l00028"></a>00028 <span class="comment">  *   Standard_Star Frames Data Reduction Parameter Initialization        *</span>
+<a name="l00029"></a>00029 <span class="comment">  ****************************************************************/</span>
+<a name="l00030"></a>00030 <span class="preprocessor">#include "cpl.h"</span>    <span class="comment">/* defines parlist structure */</span>
+<a name="l00031"></a>00031 <span class="keywordtype">void</span>
+<a name="l00032"></a>00032 sinfo_standard_star_config_add(cpl_parameterlist *list);
+<a name="l00033"></a>00033 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__standstar__cfg_8c_source.html b/html/sinfo__standstar__cfg_8c_source.html
new file mode 100644
index 0000000..cd1f911
--- /dev/null
+++ b/html/sinfo__standstar__cfg_8c_source.html
@@ -0,0 +1,92 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_standstar_cfg.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_standstar_cfg.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 
+<a name="l00020"></a>00020 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00021"></a>00021 <span class="comment">   </span>
+<a name="l00022"></a>00022 <span class="comment">   File name     :    sinfo_standstar_cfg.c</span>
+<a name="l00023"></a>00023 <span class="comment">   Author     :       Juergen Schreiber</span>
+<a name="l00024"></a>00024 <span class="comment">   Created on    :    March 2002</span>
+<a name="l00025"></a>00025 <span class="comment">   Description    :    configuration handling tools for the </span>
+<a name="l00026"></a>00026 <span class="comment">                        standard star data reduction</span>
+<a name="l00027"></a>00027 <span class="comment"></span>
+<a name="l00028"></a>00028 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00029"></a>00029 
+<a name="l00030"></a>00030 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00032"></a>00032 <span class="preprocessor">#endif</span>
+<a name="l00033"></a>00033 <span class="preprocessor"></span>
+<a name="l00034"></a>00034 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00035"></a>00035 <span class="comment">                                   Includes</span>
+<a name="l00036"></a>00036 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00037"></a>00037 
+<a name="l00038"></a>00038 <span class="preprocessor">#include "sinfo_standstar_cfg.h"</span>
+<a name="l00039"></a>00039 
+<a name="l00047"></a>00047 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00048"></a>00048 <span class="comment">                              Function codes</span>
+<a name="l00049"></a>00049 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00050"></a>00050 
+<a name="l00051"></a>00051 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00052"></a>00052 <span class="comment">   @name   sinfo_standstar_cfg_create()</span>
+<a name="l00053"></a>00053 <span class="comment">   @param  void</span>
+<a name="l00054"></a>00054 <span class="comment">   @return pointer to allocated base standstar_config structure</span>
+<a name="l00055"></a>00055 <span class="comment">   @brief  allocate memory for a standstar_config struct</span>
+<a name="l00056"></a>00056 <span class="comment">   @note   only the main (base) structure is allocated</span>
+<a name="l00057"></a>00057 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00058"></a>00058 
+<a name="l00059"></a>00059 standstar_config * sinfo_standstar_cfg_create(<span class="keywordtype">void</span>)
+<a name="l00060"></a>00060 {
+<a name="l00061"></a>00061     <span class="keywordflow">return</span> cpl_calloc(1, <span class="keyword">sizeof</span>(standstar_config));
+<a name="l00062"></a>00062 }
+<a name="l00063"></a>00063 
+<a name="l00064"></a>00064 
+<a name="l00065"></a>00065 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00066"></a>00066 <span class="comment">   @name    sinfo_standstar_cfg_destroy()</span>
+<a name="l00067"></a>00067 <span class="comment">   @param   cc   standstar_config to deallocate</span>
+<a name="l00068"></a>00068 <span class="comment">   @return  void</span>
+<a name="l00069"></a>00069 <span class="comment">   @brief   deallocate all memory associated with a \</span>
+<a name="l00070"></a>00070 <span class="comment">            standstar_config data structure</span>
+<a name="l00071"></a>00071 <span class="comment">     </span>
+<a name="l00072"></a>00072 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00073"></a>00073 
+<a name="l00074"></a>00074 <span class="keywordtype">void</span> sinfo_standstar_cfg_destroy(standstar_config * cc)
+<a name="l00075"></a>00075 {
+<a name="l00076"></a>00076     <span class="keywordflow">if</span> (cc==NULL) return ;
+<a name="l00077"></a>00077 
+<a name="l00078"></a>00078     <span class="comment">/* Free main struct */</span>
+<a name="l00079"></a>00079     cpl_free(cc);
+<a name="l00080"></a>00080 
+<a name="l00081"></a>00081     return ;
+<a name="l00082"></a>00082 }
+<a name="l00083"></a>00083 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__standstar__cfg_8h_source.html b/html/sinfo__standstar__cfg_8h_source.html
new file mode 100644
index 0000000..2003fdc
--- /dev/null
+++ b/html/sinfo__standstar__cfg_8h_source.html
@@ -0,0 +1,151 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_standstar_cfg.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_standstar_cfg.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 
+<a name="l00020"></a>00020 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00021"></a>00021 <span class="comment">   </span>
+<a name="l00022"></a>00022 <span class="comment">   File name     :    sinfo_standstar_cfg.h</span>
+<a name="l00023"></a>00023 <span class="comment">   Author    :    Juergen Schreiber</span>
+<a name="l00024"></a>00024 <span class="comment">   Created on    :    March 2002</span>
+<a name="l00025"></a>00025 <span class="comment">   Description    :    standstar_ini definitions + handling prototypes</span>
+<a name="l00026"></a>00026 <span class="comment"></span>
+<a name="l00027"></a>00027 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00028"></a>00028 
+<a name="l00029"></a>00029 
+<a name="l00030"></a>00030 <span class="preprocessor">#ifndef SINFO_STANDSTAR_CFG_H</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_STANDSTAR_CFG_H</span>
+<a name="l00032"></a>00032 <span class="preprocessor"></span>
+<a name="l00033"></a>00033 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00034"></a>00034 <span class="comment">                                   Includes</span>
+<a name="l00035"></a>00035 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="preprocessor">#include <stdlib.h></span>
+<a name="l00038"></a>00038 <span class="preprocessor">#include "sinfo_globals.h"</span>
+<a name="l00039"></a>00039 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00040"></a>00040 
+<a name="l00041"></a>00041 
+<a name="l00042"></a>00042 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00043"></a>00043 <span class="comment">                                   Defines</span>
+<a name="l00044"></a>00044 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00045"></a>00045 
+<a name="l00046"></a>00046 
+<a name="l00047"></a>00047 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00048"></a>00048 <span class="comment">                                   New types</span>
+<a name="l00049"></a>00049 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00050"></a>00050 
+<a name="l00051"></a>00051 
+<a name="l00052"></a>00052 <span class="comment">/*</span>
+<a name="l00053"></a>00053 <span class="comment">  standard star data reduction blackboard container</span>
+<a name="l00054"></a>00054 <span class="comment"></span>
+<a name="l00055"></a>00055 <span class="comment">  This structure holds all information related to the standard </span>
+<a name="l00056"></a>00056 <span class="comment">  star data reduction</span>
+<a name="l00057"></a>00057 <span class="comment">  routine. It is used as a container for the flux of ancillary data,</span>
+<a name="l00058"></a>00058 <span class="comment">  computed values, and algorithm status. Pixel flux is separated from</span>
+<a name="l00059"></a>00059 <span class="comment">  the blackboard.</span>
+<a name="l00060"></a>00060 <span class="comment">  */</span>
+<a name="l00061"></a>00061 
+<a name="l00062"></a>00062 <span class="keyword">typedef</span> <span class="keyword">struct </span>standstar_config {
+<a name="l00063"></a>00063 <span class="comment">/*-------General---------*/</span>
+<a name="l00064"></a>00064         <span class="keywordtype">char</span> inFile[FILE_NAME_SZ]  ;<span class="comment">/* input file of reduced jittered </span>
+<a name="l00065"></a>00065 <span class="comment">                                       data cubes of a standard star */</span>
+<a name="l00066"></a>00066         <span class="keywordtype">char</span> ** inFrameList ; <span class="comment">/* input list of cubes */</span>
+<a name="l00067"></a>00067         <span class="keywordtype">int</span>     nframes ;         <span class="comment">/* number of input frames */</span>
+<a name="l00068"></a>00068         <span class="keywordtype">char</span> outName[FILE_NAME_SZ] ; <span class="comment">/* output name of resulting </span>
+<a name="l00069"></a>00069 <span class="comment">                                        extracted spectrum stored </span>
+<a name="l00070"></a>00070 <span class="comment">                                        as fits image */</span>
+<a name="l00071"></a>00071 
+<a name="l00072"></a>00072 <span class="comment">/*------ spectral extraction and determination of conversion factor ------*/</span>
+<a name="l00073"></a>00073         <span class="comment">/* the fraction [0...1] of rejected low intensity pixels when </span>
+<a name="l00074"></a>00074 <span class="comment">           taking the average of jittered spectra */</span>
+<a name="l00075"></a>00075         <span class="keywordtype">float</span> lo_reject ;
+<a name="l00076"></a>00076         <span class="comment">/* the fraction [0...1] of rejected high intensity pixels when </span>
+<a name="l00077"></a>00077 <span class="comment">           taking the average of jittered spectra */</span>
+<a name="l00078"></a>00078         <span class="keywordtype">float</span> hi_reject ;
+<a name="l00079"></a>00079         <span class="comment">/* lower left sinfo_edge coordinates of fitting box for </span>
+<a name="l00080"></a>00080 <span class="comment">           2d Gaussian fit */</span>
+<a name="l00081"></a>00081         <span class="keywordtype">int</span> llx ;
+<a name="l00082"></a>00082         <span class="keywordtype">int</span> lly ;
+<a name="l00083"></a>00083         <span class="comment">/* size of a box inside which the 2D-Gaussian fit is carried through */</span>
+<a name="l00084"></a>00084         <span class="keywordtype">int</span> halfbox_x ;
+<a name="l00085"></a>00085         <span class="keywordtype">int</span> halfbox_y ;
+<a name="l00086"></a>00086     
+<a name="l00087"></a>00087         <span class="comment">/* factor applied to the found fwhms of a 2D-Gaussian</span>
+<a name="l00088"></a>00088 <span class="comment">           fit, defines the radius of the aperture from which the</span>
+<a name="l00089"></a>00089 <span class="comment">           spectral extraction is carried out (default: 0.7). */</span>
+<a name="l00090"></a>00090         <span class="keywordtype">float</span> fwhm_factor ;
+<a name="l00091"></a>00091         <span class="comment">/* (readnoise^2 + sinfo_dark current) needed to determine the </span>
+<a name="l00092"></a>00092 <span class="comment">           noise variance of the background. Must be given in counts/sec. */</span>
+<a name="l00093"></a>00093         <span class="keywordtype">float</span> backvariance ;
+<a name="l00094"></a>00094         <span class="comment">/* estimated sky counts/sec */</span>
+<a name="l00095"></a>00095         <span class="keywordtype">float</span> sky ;
+<a name="l00096"></a>00096         <span class="comment">/* gain: counts per electron */</span>
+<a name="l00097"></a>00097         <span class="keywordtype">float</span> gain ;
+<a name="l00098"></a>00098         <span class="comment">/* indicator if an intensity conversion factor should be </span>
+<a name="l00099"></a>00099 <span class="comment">           determined or not */</span>
+<a name="l00100"></a>00100         <span class="keywordtype">int</span> convInd ;      
+<a name="l00101"></a>00101         <span class="comment">/* name of the ASCII file that stores the intensity conversion factor */</span>
+<a name="l00102"></a>00102         <span class="keywordtype">char</span> convName[FILE_NAME_SZ] ;      
+<a name="l00103"></a>00103         <span class="comment">/* magnitude of the standard star */</span>
+<a name="l00104"></a>00104         <span class="keywordtype">float</span> mag ;      
+<a name="l00105"></a>00105 } standstar_config ;
+<a name="l00106"></a>00106 
+<a name="l00107"></a>00107 
+<a name="l00108"></a>00108 
+<a name="l00109"></a>00109 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00110"></a>00110 <span class="comment">                               Function prototypes</span>
+<a name="l00111"></a>00111 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00112"></a>00112 
+<a name="l00113"></a>00113 
+<a name="l00114"></a>00114 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00115"></a>00115 <span class="comment">   Function :   sinfo_standstar_cfg_create()</span>
+<a name="l00116"></a>00116 <span class="comment">   In       :   void</span>
+<a name="l00117"></a>00117 <span class="comment">   Out      :   pointer to allocated base standstar_config structure</span>
+<a name="l00118"></a>00118 <span class="comment">   Job      :   allocate memory for a standstar_config struct</span>
+<a name="l00119"></a>00119 <span class="comment">   Notice   :   only the main (base) structure is allocated</span>
+<a name="l00120"></a>00120 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00121"></a>00121 
+<a name="l00122"></a>00122 standstar_config * sinfo_standstar_cfg_create(<span class="keywordtype">void</span>);
+<a name="l00123"></a>00123 
+<a name="l00124"></a>00124 
+<a name="l00125"></a>00125 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00126"></a>00126 <span class="comment">   Function :   sinfo_standstar_cfg_destroy()</span>
+<a name="l00127"></a>00127 <span class="comment">   In       :   standstar_config to deallocate</span>
+<a name="l00128"></a>00128 <span class="comment">   Out      :   void</span>
+<a name="l00129"></a>00129 <span class="comment">   Job      :   deallocate all memory associated with a </span>
+<a name="l00130"></a>00130 <span class="comment">                standstar_config data structure</span>
+<a name="l00131"></a>00131 <span class="comment">   Notice   :   </span>
+<a name="l00132"></a>00132 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00133"></a>00133 <span class="keywordtype">void</span> sinfo_standstar_cfg_destroy(standstar_config * cc);
+<a name="l00134"></a>00134 
+<a name="l00135"></a>00135 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__standstar__ini_8h_source.html b/html/sinfo__standstar__ini_8h_source.html
new file mode 100644
index 0000000..290a3a6
--- /dev/null
+++ b/html/sinfo__standstar__ini_8h_source.html
@@ -0,0 +1,78 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_standstar_ini.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_standstar_ini.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 
+<a name="l00020"></a>00020 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00021"></a>00021 <span class="comment">   </span>
+<a name="l00022"></a>00022 <span class="comment">   File name    :   sinfo_standstar_ini.h</span>
+<a name="l00023"></a>00023 <span class="comment">   Author       :    Juergen Schreiber</span>
+<a name="l00024"></a>00024 <span class="comment">   Created on   :    Mar 25, 2002</span>
+<a name="l00025"></a>00025 <span class="comment">   Description  :    ini file handling for SINFONI data reduction </span>
+<a name="l00026"></a>00026 <span class="comment">                        of a standard star</span>
+<a name="l00027"></a>00027 <span class="comment"></span>
+<a name="l00028"></a>00028 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00029"></a>00029 
+<a name="l00030"></a>00030 
+<a name="l00031"></a>00031 <span class="preprocessor">#ifndef SINFO_STANDSTAR_INI_H</span>
+<a name="l00032"></a>00032 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_STANDSTAR_INI_H</span>
+<a name="l00033"></a>00033 <span class="preprocessor"></span>
+<a name="l00034"></a>00034 
+<a name="l00035"></a>00035 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00036"></a>00036 <span class="comment">                                Includes</span>
+<a name="l00037"></a>00037 <span class="comment">---------------------------------------------------------------------------*/</span>
+<a name="l00038"></a>00038 
+<a name="l00039"></a>00039 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include "standstar_cfg.h"</span>
+<a name="l00041"></a>00041 
+<a name="l00042"></a>00042  
+<a name="l00043"></a>00043  
+<a name="l00044"></a>00044 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00045"></a>00045 <span class="comment">                             Function prototypes </span>
+<a name="l00046"></a>00046 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00047"></a>00047 
+<a name="l00048"></a>00048 
+<a name="l00049"></a>00049 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l00066"></a>00066 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00067"></a>00067 <span class="keywordtype">int</span> generateStandstar_ini_file(
+<a name="l00068"></a>00068         <span class="keywordtype">char</span> * ini_name,
+<a name="l00069"></a>00069         <span class="keywordtype">char</span> * name_i,
+<a name="l00070"></a>00070         <span class="keywordtype">char</span> * name_o
+<a name="l00071"></a>00071 );
+<a name="l00072"></a>00072 
+<a name="l00073"></a>00073 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l00084"></a>00084 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00085"></a>00085 
+<a name="l00086"></a>00086 standstar_config * parse_standstar_ini_file(<span class="keywordtype">char</span> * ini_name) ;
+<a name="l00087"></a>00087 
+<a name="l00088"></a>00088 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__standstar__ini__by__cpl_8c_source.html b/html/sinfo__standstar__ini__by__cpl_8c_source.html
new file mode 100644
index 0000000..5ff7ac1
--- /dev/null
+++ b/html/sinfo__standstar__ini__by__cpl_8c_source.html
@@ -0,0 +1,248 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_standstar_ini_by_cpl.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_standstar_ini_by_cpl.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 
+<a name="l00020"></a>00020 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00021"></a>00021 <span class="comment">   </span>
+<a name="l00022"></a>00022 <span class="comment">   File name    :   sinfo_standstar_ini_by_cpl.c</span>
+<a name="l00023"></a>00023 <span class="comment">   Author       :   Andrea Modigliani</span>
+<a name="l00024"></a>00024 <span class="comment">   Created on   :   May 23, 2004</span>
+<a name="l00025"></a>00025 <span class="comment">   Description  :   standard star reduction cpl input handling for SPIFFI</span>
+<a name="l00026"></a>00026 <span class="comment"></span>
+<a name="l00027"></a>00027 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00028"></a>00028 
+<a name="l00029"></a>00029 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00031"></a>00031 <span class="preprocessor">#endif</span>
+<a name="l00032"></a>00032 <span class="preprocessor"></span>
+<a name="l00033"></a>00033 
+<a name="l00034"></a>00034 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00035"></a>00035 <span class="comment">                                Includes</span>
+<a name="l00036"></a>00036 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include <string.h></span>
+<a name="l00038"></a>00038 <span class="preprocessor">#include "sinfo_standstar_ini_by_cpl.h"</span>
+<a name="l00039"></a>00039 <span class="preprocessor">#include "sinfo_pro_types.h"</span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include "sinfo_hidden.h"</span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include "sinfo_functions.h"</span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include "sinfo_file_handling.h"</span>
+<a name="l00043"></a>00043 
+<a name="l00044"></a>00044 
+<a name="l00045"></a>00045 
+<a name="l00046"></a>00046 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00047"></a>00047 <span class="comment">                    Functions private to this module</span>
+<a name="l00048"></a>00048 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00049"></a>00049 
+<a name="l00050"></a>00050 <span class="keyword">static</span> <span class="keywordtype">void</span> 
+<a name="l00051"></a>00051 parse_section_frames(standstar_config *,
+<a name="l00052"></a>00052                     cpl_frameset* sof, 
+<a name="l00053"></a>00053                     cpl_frameset** raw, 
+<a name="l00054"></a>00054                     <span class="keywordtype">int</span>* status);
+<a name="l00055"></a>00055 <span class="keyword">static</span> <span class="keywordtype">void</span> 
+<a name="l00056"></a>00056 parse_section_extraction(standstar_config *, cpl_parameterlist* cpl_cfg);
+<a name="l00066"></a>00066 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l00077"></a>00077 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00078"></a>00078 
+<a name="l00079"></a>00079 standstar_config * 
+<a name="l00080"></a>00080 sinfo_parse_cpl_input_standstar(cpl_parameterlist* cpl_cfg, 
+<a name="l00081"></a>00081                                 cpl_frameset* sof, 
+<a name="l00082"></a>00082                                 cpl_frameset** raw)
+<a name="l00083"></a>00083 {
+<a name="l00084"></a>00084 
+<a name="l00085"></a>00085         standstar_config   *  cfg = sinfo_standstar_cfg_create();
+<a name="l00086"></a>00086         <span class="keywordtype">int</span> status=0;
+<a name="l00087"></a>00087         <span class="comment">/*</span>
+<a name="l00088"></a>00088 <span class="comment">         * Perform sanity checks, fill up the structure with what was</span>
+<a name="l00089"></a>00089 <span class="comment">         * found in the ini file</span>
+<a name="l00090"></a>00090 <span class="comment">         */</span>
+<a name="l00091"></a>00091         parse_section_extraction   (cfg, cpl_cfg);
+<a name="l00092"></a>00092         parse_section_frames       (cfg, sof, raw,&status);
+<a name="l00093"></a>00093         <span class="keywordflow">if</span> (status > 0) {
+<a name="l00094"></a>00094                 <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"parsing cpl input"</span>);
+<a name="l00095"></a>00095                 sinfo_standstar_cfg_destroy(cfg);
+<a name="l00096"></a>00096                 cfg = NULL ;
+<a name="l00097"></a>00097                 <span class="keywordflow">return</span> NULL ;
+<a name="l00098"></a>00098         }
+<a name="l00099"></a>00099         <span class="keywordflow">return</span> cfg ;
+<a name="l00100"></a>00100 }
+<a name="l00101"></a>00101 
+<a name="l00102"></a>00102 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00103"></a>00103 parse_section_frames(standstar_config * cfg,
+<a name="l00104"></a>00104              cpl_frameset* sof,
+<a name="l00105"></a>00105              cpl_frameset** raw,
+<a name="l00106"></a>00106                      <span class="keywordtype">int</span>* status)
+<a name="l00107"></a>00107 {
+<a name="l00108"></a>00108     <span class="keywordtype">int</span>                     i;
+<a name="l00109"></a>00109     <span class="keywordtype">int</span>                     nval ;
+<a name="l00110"></a>00110     cpl_frame*      frame=NULL;
+<a name="l00111"></a>00111    <span class="keywordtype">char</span> spat_res[FILE_NAME_SZ];
+<a name="l00112"></a>00112    <span class="keywordtype">char</span> lamp_status[FILE_NAME_SZ];
+<a name="l00113"></a>00113    <span class="keywordtype">char</span> band[FILE_NAME_SZ];
+<a name="l00114"></a>00114    <span class="keywordtype">int</span> ins_set=0;
+<a name="l00115"></a>00115    cpl_frameset* tmp=NULL;
+<a name="l00116"></a>00116     <span class="comment">/* AMO BEWARE only STD frames should be here checked for */</span>
+<a name="l00117"></a>00117     sinfo_extract_frames_group_type(sof,&tmp,CPL_FRAME_GROUP_PRODUCT);
+<a name="l00118"></a>00118     sinfo_extract_raw_frames_type(tmp,raw,PRO_COADD_STD);
+<a name="l00119"></a>00119     cpl_frameset_delete(tmp);
+<a name="l00120"></a>00120     nval = cpl_frameset_get_size(*raw);
+<a name="l00121"></a>00121     <span class="keywordflow">if</span> (nval < 1) {
+<a name="l00122"></a>00122        sinfo_extract_raw_frames_type(sof,raw,PRO_OBS_STD);
+<a name="l00123"></a>00123     }
+<a name="l00124"></a>00124     nval = cpl_frameset_get_size(*raw);
+<a name="l00125"></a>00125     <span class="keywordflow">if</span> (nval < 1) {
+<a name="l00126"></a>00126        sinfo_extract_raw_frames_type(sof,raw,PRO_COADD_PSF);
+<a name="l00127"></a>00127     }
+<a name="l00128"></a>00128     nval = cpl_frameset_get_size(*raw);
+<a name="l00129"></a>00129     <span class="keywordflow">if</span> (nval < 1) {
+<a name="l00130"></a>00130        sinfo_extract_raw_frames_type(sof,raw,PRO_OBS_PSF);
+<a name="l00131"></a>00131     }
+<a name="l00132"></a>00132     nval = cpl_frameset_get_size(*raw);
+<a name="l00133"></a>00133     <span class="keywordflow">if</span> (nval < 1) {
+<a name="l00134"></a>00134        sinfo_extract_raw_frames_type(sof,raw,PRO_COADD_OBJ);
+<a name="l00135"></a>00135     }
+<a name="l00136"></a>00136     nval = cpl_frameset_get_size(*raw);
+<a name="l00137"></a>00137     <span class="keywordflow">if</span> (nval < 1) {
+<a name="l00138"></a>00138        sinfo_extract_raw_frames_type(sof,raw,PRO_OBS_OBJ);
+<a name="l00139"></a>00139     }
+<a name="l00140"></a>00140     nval = cpl_frameset_get_size(*raw);
+<a name="l00141"></a>00141     <span class="keywordflow">if</span> (nval < 1) {
+<a name="l00142"></a>00142       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Too few (%d) raw frames "</span>
+<a name="l00143"></a>00143                           <span class="stringliteral">"(%s or %s or %s or %s or %s or %s ) "</span>
+<a name="l00144"></a>00144               <span class="stringliteral">"present in frameset!Aborting..."</span>,nval,
+<a name="l00145"></a>00145               PRO_COADD_STD,PRO_OBS_STD,
+<a name="l00146"></a>00146               PRO_COADD_PSF,PRO_OBS_PSF,
+<a name="l00147"></a>00147               PRO_COADD_OBJ,PRO_OBS_OBJ);
+<a name="l00148"></a>00148           (*status)++;
+<a name="l00149"></a>00149           <span class="keywordflow">return</span>;
+<a name="l00150"></a>00150     } 
+<a name="l00151"></a>00151 
+<a name="l00152"></a>00152     <span class="comment">/* Allocate structures to go into the blackboard */</span>
+<a name="l00153"></a>00153     cfg->inFrameList     = cpl_malloc(nval * <span class="keyword">sizeof</span>(<span class="keywordtype">char</span>*));
+<a name="l00154"></a>00154     <span class="comment">/* Browse through the charmatrix to get names and file types */</span>
+<a name="l00155"></a>00155   <span class="comment">/* read input frames */</span>
+<a name="l00156"></a>00156    <span class="keywordflow">for</span> (i=0 ; i<nval ; i++) {
+<a name="l00157"></a>00157       frame = cpl_frameset_get_frame(*raw,i);
+<a name="l00158"></a>00158       <span class="keywordflow">if</span>(sinfo_file_exists((<span class="keywordtype">char</span>*) cpl_frame_get_filename(frame))==1) 
+<a name="l00159"></a>00159     {
+<a name="l00160"></a>00160          <span class="comment">/* Store file name into framelist */</span>
+<a name="l00161"></a>00161           cfg->inFrameList[i]=cpl_strdup(cpl_frame_get_filename(frame));
+<a name="l00162"></a>00162     }
+<a name="l00163"></a>00163    }
+<a name="l00164"></a>00164  
+<a name="l00165"></a>00165    <span class="comment">/* Copy relevant information into the blackboard */</span>
+<a name="l00166"></a>00166    cfg->nframes         = nval ;
+<a name="l00167"></a>00167 
+<a name="l00168"></a>00168    strcpy(cfg -> outName, STDSTAR_OUT_FILENAME);
+<a name="l00169"></a>00169    
+<a name="l00170"></a>00170 
+<a name="l00171"></a>00171 
+<a name="l00172"></a>00172 
+<a name="l00173"></a>00173 
+<a name="l00174"></a>00174    frame = cpl_frameset_get_frame(*raw,0);
+<a name="l00175"></a>00175 
+<a name="l00176"></a>00176    sinfo_get_spatial_res(frame,spat_res);
+<a name="l00177"></a>00177   <span class="keywordflow">switch</span>(sinfo_frame_is_on(frame)) 
+<a name="l00178"></a>00178     {
+<a name="l00179"></a>00179 
+<a name="l00180"></a>00180     <span class="keywordflow">case</span> 0: 
+<a name="l00181"></a>00181       strcpy(lamp_status,<span class="stringliteral">"on"</span>);
+<a name="l00182"></a>00182       <span class="keywordflow">break</span>;
+<a name="l00183"></a>00183     <span class="keywordflow">case</span> 1: 
+<a name="l00184"></a>00184       strcpy(lamp_status,<span class="stringliteral">"off"</span>);
+<a name="l00185"></a>00185       <span class="keywordflow">break</span>;
+<a name="l00186"></a>00186     <span class="keywordflow">case</span> -1:
+<a name="l00187"></a>00187       strcpy(lamp_status,<span class="stringliteral">"undefined"</span>);
+<a name="l00188"></a>00188       <span class="keywordflow">break</span>;
+<a name="l00189"></a>00189     <span class="keywordflow">default</span>: 
+<a name="l00190"></a>00190       strcpy(lamp_status,<span class="stringliteral">"undefined"</span>);
+<a name="l00191"></a>00191       <span class="keywordflow">break</span>;
+<a name="l00192"></a>00192     }
+<a name="l00193"></a>00193    sinfo_get_band(frame,band);
+<a name="l00194"></a>00194    sinfo_msg(<span class="stringliteral">"Spatial resolution: %s lamp_status: %s band: %s"</span>,
+<a name="l00195"></a>00195                      spat_res,    lamp_status,    band);
+<a name="l00196"></a>00196 
+<a name="l00197"></a>00197 
+<a name="l00198"></a>00198    sinfo_get_ins_set(band,&ins_set);
+<a name="l00199"></a>00199    return ;
+<a name="l00200"></a>00200 }
+<a name="l00201"></a>00201 
+<a name="l00202"></a>00202 <span class="keyword">static</span> <span class="keywordtype">void</span>     
+<a name="l00203"></a>00203 parse_section_extraction(standstar_config * cfg,cpl_parameterlist* cpl_cfg)
+<a name="l00204"></a>00204 {
+<a name="l00205"></a>00205    cpl_parameter* p;
+<a name="l00206"></a>00206    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.std_star.low_rejection"</span>);
+<a name="l00207"></a>00207    cfg -> lo_reject = cpl_parameter_get_double(p);
+<a name="l00208"></a>00208 
+<a name="l00209"></a>00209    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.std_star.high_rejection"</span>);
+<a name="l00210"></a>00210    cfg -> hi_reject =  cpl_parameter_get_double(p);
+<a name="l00211"></a>00211 
+<a name="l00212"></a>00212    cfg -> llx = 8;
+<a name="l00213"></a>00213    cfg -> lly = 8;
+<a name="l00214"></a>00214    cfg -> halfbox_x = 16;
+<a name="l00215"></a>00215    cfg -> halfbox_y = 16;
+<a name="l00216"></a>00216 
+<a name="l00217"></a>00217    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.std_star.fwhm_factor"</span>);
+<a name="l00218"></a>00218    cfg -> fwhm_factor =  cpl_parameter_get_double(p);
+<a name="l00219"></a>00219 
+<a name="l00220"></a>00220    cfg -> backvariance =  BKG_VARIANCE;
+<a name="l00221"></a>00221    cfg -> sky = SKY_FLUX;
+<a name="l00222"></a>00222    cfg -> gain = GAIN ;
+<a name="l00223"></a>00223 
+<a name="l00224"></a>00224    p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.std_star.conversion_index"</span>);
+<a name="l00225"></a>00225    cfg -> convInd = cpl_parameter_get_bool(p);
+<a name="l00226"></a>00226  
+<a name="l00227"></a>00227    strcpy(cfg -> convName, STDSTAR_CONV_OUT_FILENAME);
+<a name="l00228"></a>00228  
+<a name="l00229"></a>00229    cfg -> mag = 0;
+<a name="l00230"></a>00230 
+<a name="l00231"></a>00231  
+<a name="l00232"></a>00232    return ;
+<a name="l00233"></a>00233 }
+<a name="l00234"></a>00234 
+<a name="l00235"></a>00235 <span class="keywordtype">void</span>
+<a name="l00236"></a>00236 sinfo_stdstar_free(standstar_config  ** cfg)
+<a name="l00237"></a>00237 {
+<a name="l00238"></a>00238   <span class="keywordtype">int</span> i=0;
+<a name="l00239"></a>00239   <span class="keywordflow">if</span>((*cfg) != NULL) {
+<a name="l00240"></a>00240     <span class="keywordflow">for</span> (i=0 ; i<(*cfg)->nframes ; i++) {
+<a name="l00241"></a>00241       <span class="keywordflow">if</span>((*cfg)->inFrameList[i] != NULL) {
+<a name="l00242"></a>00242     cpl_free((*cfg)->inFrameList[i]);
+<a name="l00243"></a>00243     (*cfg)->inFrameList[i]= NULL;
+<a name="l00244"></a>00244       }
+<a name="l00245"></a>00245     }
+<a name="l00246"></a>00246     cpl_free((*cfg)->inFrameList);
+<a name="l00247"></a>00247     (*cfg)->inFrameList=NULL;
+<a name="l00248"></a>00248     sinfo_standstar_cfg_destroy (*cfg);
+<a name="l00249"></a>00249     (*cfg) = NULL;
+<a name="l00250"></a>00250   }
+<a name="l00251"></a>00251 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__standstar__ini__by__cpl_8h_source.html b/html/sinfo__standstar__ini__by__cpl_8h_source.html
new file mode 100644
index 0000000..1bb4811
--- /dev/null
+++ b/html/sinfo__standstar__ini__by__cpl_8h_source.html
@@ -0,0 +1,78 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_standstar_ini_by_cpl.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_standstar_ini_by_cpl.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 
+<a name="l00020"></a>00020 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00021"></a>00021 <span class="comment">   </span>
+<a name="l00022"></a>00022 <span class="comment">   File name    :   sinfo_standstar_ini_by_cpl.h</span>
+<a name="l00023"></a>00023 <span class="comment">   Author       :   Andrea Modigliani</span>
+<a name="l00024"></a>00024 <span class="comment">   Created on   :   May 23, 2004</span>
+<a name="l00025"></a>00025 <span class="comment">   Description  :   cpl input handling for SINFONI data reduction </span>
+<a name="l00026"></a>00026 <span class="comment">                    of a standard star</span>
+<a name="l00027"></a>00027 <span class="comment"></span>
+<a name="l00028"></a>00028 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00029"></a>00029 
+<a name="l00030"></a>00030 
+<a name="l00031"></a>00031 <span class="preprocessor">#ifndef SINFO_STANDSTAR_INI_BY_CPL_H</span>
+<a name="l00032"></a>00032 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_STANDSTAR_INI_BY_CPL_H</span>
+<a name="l00033"></a>00033 <span class="preprocessor"></span>
+<a name="l00034"></a>00034 
+<a name="l00035"></a>00035 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00036"></a>00036 <span class="comment">                                Includes</span>
+<a name="l00037"></a>00037 <span class="comment">---------------------------------------------------------------------------*/</span>
+<a name="l00038"></a>00038 
+<a name="l00039"></a>00039 <span class="preprocessor">#include <stdio.h></span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include "sinfo_standstar_cfg.h"</span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00043"></a>00043  
+<a name="l00044"></a>00044  
+<a name="l00045"></a>00045 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00046"></a>00046 <span class="comment">                             Function prototypes </span>
+<a name="l00047"></a>00047 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00048"></a>00048 
+<a name="l00049"></a>00049 
+<a name="l00050"></a>00050 <span class="comment">/* generateStandstar_ini_file */</span>
+<a name="l00051"></a>00051 
+<a name="l00052"></a>00052 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l00063"></a>00063 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00064"></a>00064 
+<a name="l00065"></a>00065 <span class="keywordtype">void</span>
+<a name="l00066"></a>00066 sinfo_stdstar_free(standstar_config  ** cfg);
+<a name="l00067"></a>00067 standstar_config * 
+<a name="l00068"></a>00068 sinfo_parse_cpl_input_standstar(cpl_parameterlist * cpl_cfg, 
+<a name="l00069"></a>00069                                 cpl_frameset* sof, 
+<a name="l00070"></a>00070                                 cpl_frameset** raw) ;
+<a name="l00071"></a>00071 
+<a name="l00072"></a>00072 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__star__index_8c_source.html b/html/sinfo__star__index_8c_source.html
new file mode 100644
index 0000000..2b0cf0e
--- /dev/null
+++ b/html/sinfo__star__index_8c_source.html
@@ -0,0 +1,338 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_star_index.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_star_index.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_star_index.c,v 1.9 2012/03/03 10:18:26 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the X-Shooter Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2012/03/03 10:18:26 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.9 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> */</span>
+<a name="l00026"></a>00026 
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 
+<a name="l00029"></a>00029 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>          <span class="comment">/* allows the program compilation */</span>
+<a name="l00031"></a>00031 <span class="preprocessor">#endif</span>
+<a name="l00032"></a>00032 <span class="preprocessor"></span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00034"></a>00034 <span class="preprocessor">#include <string.h></span>
+<a name="l00035"></a>00035 <span class="preprocessor">#include <math.h></span>
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 
+<a name="l00038"></a>00038 <span class="comment">//#include "sinfo_pro_save.h"</span>
+<a name="l00039"></a>00039 <span class="comment">//#include "sinfo_pfits.h"</span>
+<a name="l00040"></a>00040 <span class="comment">//#include "sinfo_utilities_scired.h"</span>
+<a name="l00041"></a>00041 <span class="comment">//#include "sinfo_hidden.h"</span>
+<a name="l00042"></a>00042 <span class="comment">//#include "sinfo_functions.h"</span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include "sinfo_error.h"</span>
+<a name="l00044"></a>00044 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00045"></a>00045 <span class="preprocessor">#include "sinfo_utils_wrappers.h"</span>
+<a name="l00046"></a>00046 <span class="comment">//#include "sinfo_globals.h"</span>
+<a name="l00047"></a>00047 <span class="preprocessor">#include "sinfo_star_index.h"</span>
+<a name="l00048"></a>00048 
+<a name="l00049"></a>00049 <span class="keyword">struct </span>_star_index_
+<a name="l00050"></a>00050 {
+<a name="l00051"></a>00051     cpl_table* index_table;
+<a name="l00052"></a>00052     <span class="keywordtype">char</span>* fits_file_name;
+<a name="l00053"></a>00053     <span class="keywordtype">int</span> index_size;
+<a name="l00054"></a>00054     cpl_table** cache;
+<a name="l00055"></a>00055     <span class="keywordtype">int</span> cache_size;
+<a name="l00056"></a>00056     <span class="keywordtype">int</span>* cache_index;
+<a name="l00057"></a>00057 };
+<a name="l00058"></a>00058 
+<a name="l00059"></a>00059 <span class="comment">//typedef struct _star_index_ star_index;</span>
+<a name="l00060"></a>00060 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span>* COL_NAME_EXTID   = <span class="stringliteral">"ext_id"</span>;
+<a name="l00061"></a>00061 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span>* COL_NAME_NAME    = <span class="stringliteral">"name"</span>;
+<a name="l00062"></a>00062 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span>* COL_NAME_RA  = <span class="stringliteral">"ra"</span>;
+<a name="l00063"></a>00063 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span>* COL_NAME_DEC     = <span class="stringliteral">"dec"</span>;
+<a name="l00064"></a>00064 
+<a name="l00065"></a>00065 <span class="keyword">static</span> star_index* star_index_construct(<span class="keyword">const</span> <span class="keywordtype">char</span>* fits_file);
+<a name="l00066"></a>00066 <span class="keyword">static</span> <span class="keywordtype">void</span> star_index_destruct(star_index* pindex);
+<a name="l00067"></a>00067 <span class="comment">// private functions</span>
+<a name="l00068"></a>00068 
+<a name="l00069"></a>00069 <span class="keyword">static</span> star_index* star_index_construct(<span class="keyword">const</span> <span class="keywordtype">char</span>* fits_file)
+<a name="l00070"></a>00070 {
+<a name="l00071"></a>00071     star_index* pret = cpl_malloc(<span class="keyword">sizeof</span>(star_index));
+<a name="l00072"></a>00072     pret->index_size = 0;
+<a name="l00073"></a>00073     pret->index_table = 0;
+<a name="l00074"></a>00074     pret->cache_size = 0;
+<a name="l00075"></a>00075     pret->cache = 0;
+<a name="l00076"></a>00076     pret->cache_index = 0;
+<a name="l00077"></a>00077     <span class="keywordflow">if</span> (fits_file)
+<a name="l00078"></a>00078     {
+<a name="l00079"></a>00079         <span class="keywordtype">size_t</span> bt = strlen(fits_file) * <span class="keyword">sizeof</span>(*fits_file)+1;
+<a name="l00080"></a>00080         pret->fits_file_name = cpl_malloc(bt);
+<a name="l00081"></a>00081         strcpy(pret->fits_file_name, fits_file);
+<a name="l00082"></a>00082     }
+<a name="l00083"></a>00083     <span class="keywordflow">else</span>
+<a name="l00084"></a>00084     {
+<a name="l00085"></a>00085         pret->fits_file_name = 0;
+<a name="l00086"></a>00086     }
+<a name="l00087"></a>00087     <span class="keywordflow">return</span> pret;
+<a name="l00088"></a>00088 }
+<a name="l00089"></a>00089 
+<a name="l00090"></a>00090 <span class="keyword">static</span> <span class="keywordtype">void</span> star_index_destruct(star_index* pindex)
+<a name="l00091"></a>00091 {
+<a name="l00092"></a>00092     <span class="keywordflow">if</span>(pindex)
+<a name="l00093"></a>00093     {
+<a name="l00094"></a>00094         <span class="keywordflow">if</span> (pindex->cache)
+<a name="l00095"></a>00095         {
+<a name="l00096"></a>00096             <span class="keywordtype">int</span> i = 0;
+<a name="l00097"></a>00097             <span class="keywordflow">for</span> ( i = 0; i < pindex->cache_size; i++)
+<a name="l00098"></a>00098             {
+<a name="l00099"></a>00099                 cpl_table_delete(pindex->cache[i]);
+<a name="l00100"></a>00100             }
+<a name="l00101"></a>00101             cpl_free(pindex->cache);
+<a name="l00102"></a>00102             pindex->cache = 0;
+<a name="l00103"></a>00103             pindex->cache_size = 0;
+<a name="l00104"></a>00104         }
+<a name="l00105"></a>00105         cpl_table_delete(pindex->index_table);
+<a name="l00106"></a>00106         <span class="keywordflow">if</span>(pindex->fits_file_name)
+<a name="l00107"></a>00107         {
+<a name="l00108"></a>00108             cpl_free(pindex->fits_file_name);
+<a name="l00109"></a>00109         }
+<a name="l00110"></a>00110         cpl_free(pindex->cache_index);
+<a name="l00111"></a>00111         cpl_free(pindex);
+<a name="l00112"></a>00112     }
+<a name="l00113"></a>00113 
+<a name="l00114"></a>00114 }
+<a name="l00115"></a>00115 
+<a name="l00118"></a>00118 star_index* star_index_create(<span class="keywordtype">void</span>)
+<a name="l00119"></a>00119 {
+<a name="l00120"></a>00120     star_index* pret = star_index_construct(0);
+<a name="l00121"></a>00121     <span class="comment">// initialize table</span>
+<a name="l00122"></a>00122     check_nomsg(pret->index_table = cpl_table_new(pret->index_size));
+<a name="l00123"></a>00123     <span class="comment">// create columns ext_id, name, ra, dec</span>
+<a name="l00124"></a>00124     cpl_table_new_column(pret->index_table, COL_NAME_EXTID, CPL_TYPE_INT);
+<a name="l00125"></a>00125     cpl_table_new_column(pret->index_table, COL_NAME_NAME, CPL_TYPE_STRING);
+<a name="l00126"></a>00126     cpl_table_new_column(pret->index_table, COL_NAME_RA, CPL_TYPE_DOUBLE);
+<a name="l00127"></a>00127     cpl_table_new_column(pret->index_table, COL_NAME_DEC, CPL_TYPE_DOUBLE);
+<a name="l00128"></a>00128 
+<a name="l00129"></a>00129     <span class="keywordflow">return</span> pret;
+<a name="l00130"></a>00130     cleanup:
+<a name="l00131"></a>00131     star_index_destruct(pret);
+<a name="l00132"></a>00132     <span class="keywordflow">return</span> 0;
+<a name="l00133"></a>00133 }
+<a name="l00134"></a>00134 star_index* star_index_load(<span class="keyword">const</span> <span class="keywordtype">char</span>* fits_file)
+<a name="l00135"></a>00135 {
+<a name="l00136"></a>00136     star_index* pret = star_index_construct(fits_file);
+<a name="l00137"></a>00137     <span class="comment">// load index table from the file</span>
+<a name="l00138"></a>00138     cpl_table* pindex = 0;
+<a name="l00139"></a>00139     check_nomsg(pindex = cpl_table_load(fits_file,1,0));
+<a name="l00140"></a>00140     <span class="comment">// TODO check_nomsg the structure of the table</span>
+<a name="l00141"></a>00141     pret->index_table = pindex;
+<a name="l00142"></a>00142     check_nomsg(pret->index_size = cpl_table_get_nrow(pindex));
+<a name="l00143"></a>00143     <span class="keywordflow">return</span> pret;
+<a name="l00144"></a>00144     cleanup:
+<a name="l00145"></a>00145     star_index_destruct(pret);
+<a name="l00146"></a>00146     cpl_error_reset();
+<a name="l00147"></a>00147     <span class="keywordflow">return</span> 0;
+<a name="l00148"></a>00148 }
+<a name="l00149"></a>00149 <span class="keywordtype">void</span> star_index_delete(star_index* pindex)
+<a name="l00150"></a>00150 {
+<a name="l00151"></a>00151     star_index_destruct(pindex);
+<a name="l00152"></a>00152 }
+<a name="l00153"></a>00153 <span class="keywordtype">int</span> star_index_add(star_index* pindex, <span class="keywordtype">double</span> RA, <span class="keywordtype">double</span> DEC, <span class="keyword">const</span> <span class="keywordtype">char</span>* star_name, cpl_table* ptable)
+<a name="l00154"></a>00154 {
+<a name="l00155"></a>00155     <span class="keywordtype">int</span> retval = 0;
+<a name="l00156"></a>00156     <span class="keywordflow">if</span> (pindex)
+<a name="l00157"></a>00157     {
+<a name="l00158"></a>00158         <span class="comment">// expand the index table</span>
+<a name="l00159"></a>00159         check_nomsg(cpl_table_insert_window(pindex->index_table, pindex->index_size++, 1));
+<a name="l00160"></a>00160         <span class="keywordflow">if</span> (!pindex->cache)
+<a name="l00161"></a>00161         {
+<a name="l00162"></a>00162             pindex->cache_size = 1;
+<a name="l00163"></a>00163             pindex->cache = cpl_malloc(<span class="keyword">sizeof</span>(cpl_table*) * pindex->cache_size);
+<a name="l00164"></a>00164             pindex->cache_index = cpl_malloc(<span class="keyword">sizeof</span>(pindex->cache_index[0]) * pindex->cache_size);
+<a name="l00165"></a>00165         }
+<a name="l00166"></a>00166         <span class="keywordflow">else</span>
+<a name="l00167"></a>00167         {
+<a name="l00168"></a>00168             <span class="comment">// add new entry</span>
+<a name="l00169"></a>00169             pindex->cache_size++;
+<a name="l00170"></a>00170             pindex->cache = cpl_realloc(pindex->cache, <span class="keyword">sizeof</span>(cpl_table*) * pindex->cache_size);
+<a name="l00171"></a>00171         }
+<a name="l00172"></a>00172         check_nomsg(pindex->cache[pindex->cache_size - 1] = cpl_table_duplicate(ptable));
+<a name="l00173"></a>00173         <span class="comment">// fill the index table with values</span>
+<a name="l00174"></a>00174         check_nomsg(cpl_table_set_string(pindex->index_table, COL_NAME_NAME, pindex->index_size - 1 ,star_name));
+<a name="l00175"></a>00175         check_nomsg(cpl_table_set(pindex->index_table, COL_NAME_RA, pindex->index_size - 1 ,RA));
+<a name="l00176"></a>00176         check_nomsg(cpl_table_set(pindex->index_table, COL_NAME_DEC, pindex->index_size - 1,DEC));
+<a name="l00177"></a>00177         check_nomsg(cpl_table_set_int(pindex->index_table, COL_NAME_EXTID, pindex->index_size - 1 ,pindex->index_size + 1));
+<a name="l00178"></a>00178         retval = pindex->index_size;
+<a name="l00179"></a>00179     }
+<a name="l00180"></a>00180     <span class="keywordflow">return</span> retval;
+<a name="l00181"></a>00181 
+<a name="l00182"></a>00182     cleanup:
+<a name="l00183"></a>00183     <span class="comment">//printf ("error: %s\n", cpl_error_get_message());</span>
+<a name="l00184"></a>00184     <span class="keywordflow">return</span> 0;
+<a name="l00185"></a>00185 }
+<a name="l00186"></a>00186 
+<a name="l00187"></a>00187 <span class="keywordtype">int</span> start_index_get_size(star_index* pindex)
+<a name="l00188"></a>00188 {
+<a name="l00189"></a>00189     <span class="keywordflow">return</span> pindex ? pindex->index_size : 0;
+<a name="l00190"></a>00190 }
+<a name="l00191"></a>00191 
+<a name="l00192"></a>00192 <span class="keywordtype">int</span> star_index_remove_by_name(star_index* pindex, <span class="keyword">const</span> <span class="keywordtype">char</span>* starname)
+<a name="l00193"></a>00193 {
+<a name="l00194"></a>00194     <span class="keywordtype">int</span> i = 0;
+<a name="l00195"></a>00195     <span class="keywordtype">int</span> index_pos = -1;
+<a name="l00196"></a>00196     <span class="keywordflow">for</span> (i = 0; i < pindex->index_size; i++)
+<a name="l00197"></a>00197     {
+<a name="l00198"></a>00198         <span class="keyword">const</span> <span class="keywordtype">char</span>* curr_star_name = 0;
+<a name="l00199"></a>00199         check_nomsg(curr_star_name = cpl_table_get_string(pindex->index_table, COL_NAME_NAME, i));
+<a name="l00200"></a>00200         <span class="keywordflow">if</span> (strcmp(curr_star_name, starname) == 0)
+<a name="l00201"></a>00201         {
+<a name="l00202"></a>00202             index_pos = i;
+<a name="l00203"></a>00203             <span class="keywordflow">break</span>;
+<a name="l00204"></a>00204         }
+<a name="l00205"></a>00205     }
+<a name="l00206"></a>00206     <span class="keywordflow">if</span> (index_pos >= 0)
+<a name="l00207"></a>00207     {
+<a name="l00208"></a>00208         <span class="comment">// star is found</span>
+<a name="l00209"></a>00209         <span class="comment">// clear only the index table, real data would be cleaned during save operation</span>
+<a name="l00210"></a>00210         cpl_table_set_int(pindex->index_table, COL_NAME_EXTID, index_pos, -1);
+<a name="l00211"></a>00211         <span class="keywordflow">if</span> (index_pos - pindex->index_size + pindex->cache_size  >= 0)
+<a name="l00212"></a>00212         {
+<a name="l00213"></a>00213             <span class="comment">// clear cache</span>
+<a name="l00214"></a>00214             <span class="keywordtype">int</span> cache_index = index_pos - pindex->index_size + pindex->cache_size;
+<a name="l00215"></a>00215             cpl_table_delete(pindex->cache[cache_index]);
+<a name="l00216"></a>00216             pindex->cache[cache_index] = 0;
+<a name="l00217"></a>00217         }
+<a name="l00218"></a>00218     }
+<a name="l00219"></a>00219     cleanup:
+<a name="l00220"></a>00220     <span class="keywordflow">return</span> index_pos;
+<a name="l00221"></a>00221 }
+<a name="l00222"></a>00222 
+<a name="l00223"></a>00223 <span class="keywordtype">int</span> star_index_save(star_index* pindex, <span class="keyword">const</span> <span class="keywordtype">char</span>* fits_file)
+<a name="l00224"></a>00224 {
+<a name="l00225"></a>00225     <span class="keywordtype">int</span> i  = 0;
+<a name="l00226"></a>00226     <span class="keywordtype">int</span> inull = 0;
+<a name="l00227"></a>00227     cpl_table* pnew_index = 0;
+<a name="l00228"></a>00228     <span class="keywordtype">int</span> nrows = 0;
+<a name="l00229"></a>00229     <span class="comment">// firstly save the index table - deleted entries should be removed firstly</span>
+<a name="l00230"></a>00230     check_nomsg(cpl_table_unselect_all(pindex->index_table));
+<a name="l00231"></a>00231     check_nomsg(cpl_table_or_selected_int(pindex->index_table, COL_NAME_EXTID, CPL_EQUAL_TO, -1));
+<a name="l00232"></a>00232     <span class="comment">// inverse selection</span>
+<a name="l00233"></a>00233     check_nomsg(cpl_table_not_selected(pindex->index_table));
+<a name="l00234"></a>00234     check_nomsg(pnew_index = cpl_table_extract_selected(pindex->index_table));
+<a name="l00235"></a>00235 
+<a name="l00236"></a>00236     nrows = cpl_table_get_nrow(pnew_index);
+<a name="l00237"></a>00237 <span class="comment">//  printf("rows to save[%d]\n", nrows);</span>
+<a name="l00238"></a>00238     <span class="keywordflow">for</span> (i = 0; i < nrows; i++)
+<a name="l00239"></a>00239     {
+<a name="l00240"></a>00240         cpl_table_set_int(pnew_index, COL_NAME_EXTID, i, i+2); <span class="comment">// ext in fits starts from 1, and another 1 is used by index_table</span>
+<a name="l00241"></a>00241     }
+<a name="l00242"></a>00242 <span class="comment">//  printf("writing index [%s]\n", fits_file);</span>
+<a name="l00243"></a>00243     check_nomsg(cpl_table_save(pnew_index, NULL, NULL, fits_file, CPL_IO_CREATE));
+<a name="l00244"></a>00244     cpl_table_delete(pnew_index);
+<a name="l00245"></a>00245     pnew_index = 0;
+<a name="l00246"></a>00246     <span class="comment">// save the data</span>
+<a name="l00247"></a>00247     <span class="keywordflow">for</span> (i = 0;i < pindex->index_size; i++)
+<a name="l00248"></a>00248     {
+<a name="l00249"></a>00249 <span class="comment">//      printf("saving ext [%d]\n", i);</span>
+<a name="l00250"></a>00250         <span class="comment">// 2. save cache</span>
+<a name="l00251"></a>00251         <span class="keywordtype">int</span> saved_ext = cpl_table_get_int(pindex->index_table, COL_NAME_EXTID, i, &inull);
+<a name="l00252"></a>00252 <span class="comment">//      printf("saving 1\n");</span>
+<a name="l00253"></a>00253         <span class="keywordflow">if</span> (saved_ext > 0) <span class="comment">// check_nomsg that was not removed</span>
+<a name="l00254"></a>00254         {
+<a name="l00255"></a>00255             cpl_table* ptable = 0;
+<a name="l00256"></a>00256 <span class="comment">//          printf("saving 2\n");</span>
+<a name="l00257"></a>00257             <span class="keywordflow">if</span> (i < pindex->index_size - pindex->cache_size)
+<a name="l00258"></a>00258             {
+<a name="l00259"></a>00259 <span class="comment">//              printf("saving 3\n");</span>
+<a name="l00260"></a>00260                 check_nomsg(ptable = cpl_table_load(pindex->fits_file_name, saved_ext, 0));
+<a name="l00261"></a>00261             }
+<a name="l00262"></a>00262             <span class="keywordflow">else</span>
+<a name="l00263"></a>00263             {
+<a name="l00264"></a>00264 <span class="comment">//              printf("saving 4\n");</span>
+<a name="l00265"></a>00265                 ptable = cpl_table_duplicate(pindex->cache[i - pindex->index_size + pindex->cache_size ]);
+<a name="l00266"></a>00266             }
+<a name="l00267"></a>00267 <span class="comment">//          printf("saving 5\n");</span>
+<a name="l00268"></a>00268             check_nomsg(cpl_table_save(ptable, NULL, NULL, fits_file, CPL_IO_EXTEND));
+<a name="l00269"></a>00269 <span class="comment">//          printf("saving 6\n");</span>
+<a name="l00270"></a>00270             cpl_table_delete(ptable);
+<a name="l00271"></a>00271 <span class="comment">//          printf("saving 7\n");</span>
+<a name="l00272"></a>00272         }
+<a name="l00273"></a>00273 <span class="comment">//      printf("saving 8\n");</span>
+<a name="l00274"></a>00274     }
+<a name="l00275"></a>00275 <span class="comment">//  printf("saving exit\n");</span>
+<a name="l00276"></a>00276     <span class="keywordflow">return</span> nrows;
+<a name="l00277"></a>00277     cleanup:
+<a name="l00278"></a>00278 <span class="comment">//  printf("error during save\n");</span>
+<a name="l00279"></a>00279     <span class="keywordflow">return</span> 0;
+<a name="l00280"></a>00280 }
+<a name="l00281"></a>00281 cpl_table* star_index_get(star_index* pindex, <span class="keywordtype">double</span> RA, <span class="keywordtype">double</span> DEC, <span class="keywordtype">double</span> RA_EPS, <span class="keywordtype">double</span> DEC_EPS, <span class="keyword">const</span> <span class="keywordtype">char</span>** pstar_name)
+<a name="l00282"></a>00282 {
+<a name="l00283"></a>00283     <span class="keywordtype">int</span> i = 0;
+<a name="l00284"></a>00284     cpl_table* pret = 0;
+<a name="l00285"></a>00285     <span class="keywordtype">int</span> inull = 0;
+<a name="l00286"></a>00286 
+<a name="l00287"></a>00287     <span class="keywordflow">for</span> (i = 0; i < pindex->index_size; i++)
+<a name="l00288"></a>00288     {
+<a name="l00289"></a>00289         <span class="keywordtype">double</span> curr_ra = 0;
+<a name="l00290"></a>00290         <span class="keywordtype">double</span> curr_dec = 0;
+<a name="l00291"></a>00291         <span class="keywordtype">int</span> ext_id = 0;
+<a name="l00292"></a>00292 
+<a name="l00293"></a>00293         check_nomsg(ext_id = cpl_table_get_int(pindex->index_table, COL_NAME_EXTID, i ,&inull));
+<a name="l00294"></a>00294         check_nomsg(curr_ra = cpl_table_get(pindex->index_table, COL_NAME_RA, i,&inull));
+<a name="l00295"></a>00295         check_nomsg(curr_dec = cpl_table_get(pindex->index_table, COL_NAME_DEC, i,&inull));
+<a name="l00296"></a>00296         <span class="keywordflow">if</span> ((ext_id > 0) && (fabs(curr_ra - RA) < RA_EPS) && (fabs(curr_dec - DEC) < DEC_EPS))
+<a name="l00297"></a>00297         {
+<a name="l00298"></a>00298             <span class="comment">// found</span>
+<a name="l00299"></a>00299             <span class="comment">// retrieve the data</span>
+<a name="l00300"></a>00300             <span class="keywordflow">if</span> (i - pindex->index_size + pindex->cache_size  >= 0)
+<a name="l00301"></a>00301             {
+<a name="l00302"></a>00302                 <span class="comment">// data is in cache</span>
+<a name="l00303"></a>00303                 pret = cpl_table_duplicate(pindex->cache[i - pindex->index_size + pindex->cache_size ]);
+<a name="l00304"></a>00304             }
+<a name="l00305"></a>00305             <span class="keywordflow">else</span>
+<a name="l00306"></a>00306             {
+<a name="l00307"></a>00307                 <span class="comment">// data is on disk</span>
+<a name="l00308"></a>00308                 pret = cpl_table_load(pindex->fits_file_name, ext_id, 0);
+<a name="l00309"></a>00309             }
+<a name="l00310"></a>00310             <span class="keywordflow">if</span> (pret && pstar_name)
+<a name="l00311"></a>00311             {
+<a name="l00312"></a>00312                 check_nomsg(*pstar_name = cpl_table_get_string(pindex->index_table, COL_NAME_NAME, i));
+<a name="l00313"></a>00313             }
+<a name="l00314"></a>00314             <span class="keywordflow">break</span>;
+<a name="l00315"></a>00315         }
+<a name="l00316"></a>00316     }
+<a name="l00317"></a>00317     cleanup:
+<a name="l00318"></a>00318     <span class="keywordflow">return</span> pret;
+<a name="l00319"></a>00319 }
+<a name="l00320"></a>00320 
+<a name="l00321"></a>00321 <span class="keywordtype">void</span> star_index_dump(star_index* pindex, FILE* pfile)
+<a name="l00322"></a>00322 {
+<a name="l00323"></a>00323     cpl_table_dump(pindex->index_table, 0,  cpl_table_get_nrow(pindex->index_table), pfile);
+<a name="l00324"></a>00324 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__star__index_8h_source.html b/html/sinfo__star__index_8h_source.html
new file mode 100644
index 0000000..de6d9d2
--- /dev/null
+++ b/html/sinfo__star__index_8h_source.html
@@ -0,0 +1,78 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_star_index.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_star_index.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004-2009 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*</span>
+<a name="l00020"></a>00020 <span class="comment"> * $Author: kmirny $</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Date: 2009/09/02 11:34:23 $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Revision: 1.4 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Log: sinfo_star_index.h,v $</span>
+<a name="l00024"></a>00024 <span class="comment"> * Revision 1.4  2009/09/02 11:34:23  kmirny</span>
+<a name="l00025"></a>00025 <span class="comment"> * fixing compiler warning</span>
+<a name="l00026"></a>00026 <span class="comment"> *</span>
+<a name="l00027"></a>00027 <span class="comment"> * Revision 1.3  2009/07/13 14:40:39  kmirny</span>
+<a name="l00028"></a>00028 <span class="comment"> * fixing unit test failure in star catalog</span>
+<a name="l00029"></a>00029 <span class="comment"> *</span>
+<a name="l00030"></a>00030 <span class="comment"> * Revision 1.2  2009/06/19 14:37:58  kmirny</span>
+<a name="l00031"></a>00031 <span class="comment"> * star index implementation</span>
+<a name="l00032"></a>00032 <span class="comment"> *</span>
+<a name="l00033"></a>00033 <span class="comment"> * Revision 1.1  2009/06/16 15:18:26  kmirny</span>
+<a name="l00034"></a>00034 <span class="comment"> * star catalog implementation for calculating efficiency</span>
+<a name="l00035"></a>00035 <span class="comment"> *</span>
+<a name="l00036"></a>00036 <span class="comment">*/</span>
+<a name="l00037"></a>00037 <span class="preprocessor">#ifndef _SINFONI_SINFO_STAR_INDEX_H_</span>
+<a name="l00038"></a>00038 <span class="preprocessor"></span><span class="preprocessor">#define _SINFONI_SINFO_STAR_INDEX_H_</span>
+<a name="l00039"></a>00039 <span class="preprocessor"></span>
+<a name="l00040"></a>00040 
+<a name="l00041"></a>00041 <span class="keyword">typedef</span> <span class="keyword">struct </span>_star_index_ star_index;
+<a name="l00042"></a>00042 
+<a name="l00043"></a>00043 <span class="comment">/* Loading the index from the fits file</span>
+<a name="l00044"></a>00044 <span class="comment"> * */</span>
+<a name="l00045"></a>00045 star_index* star_index_load(<span class="keyword">const</span> <span class="keywordtype">char</span>* fits_file);
+<a name="l00046"></a>00046 
+<a name="l00047"></a>00047 <span class="comment">/*Save the index to the fits file</span>
+<a name="l00048"></a>00048 <span class="comment"> * */</span>
+<a name="l00049"></a>00049 star_index* star_index_create(<span class="keywordtype">void</span>);
+<a name="l00050"></a>00050 <span class="comment">/* Add a new start to the index. To save the changed index to the file star_index_save() should be called</span>
+<a name="l00051"></a>00051 <span class="comment"> * */</span>
+<a name="l00052"></a>00052 <span class="keywordtype">int</span> star_index_add(star_index* pindex, <span class="keywordtype">double</span> RA, <span class="keywordtype">double</span> DEC, <span class="keyword">const</span> <span class="keywordtype">char</span>* star_name, cpl_table* ptable);
+<a name="l00053"></a>00053 <span class="keywordtype">int</span> star_index_remove_by_name(star_index* pindex, <span class="keyword">const</span> <span class="keywordtype">char</span>* starname);
+<a name="l00054"></a>00054 <span class="keywordtype">int</span> start_index_get_size(star_index* pindex);
+<a name="l00055"></a>00055 <span class="keywordtype">int</span> star_index_save(star_index* pindex, <span class="keyword">const</span> <span class="keywordtype">char</span>* fits_file_name);
+<a name="l00056"></a>00056 cpl_table* star_index_get(star_index* pindex, <span class="keywordtype">double</span> RA, <span class="keywordtype">double</span> DEC, <span class="keywordtype">double</span> RA_EPS, <span class="keywordtype">double</span> DEC_EPS, <span class="keyword">const</span> <span class="keywordtype">char</span>** pstar_name);
+<a name="l00057"></a>00057 <span class="keywordtype">void</span> star_index_delete(star_index* pindex);
+<a name="l00058"></a>00058 <span class="keywordtype">void</span> star_index_dump(star_index* pindex, FILE* pfile);
+<a name="l00059"></a>00059 
+<a name="l00060"></a>00060 
+<a name="l00061"></a>00061 
+<a name="l00062"></a>00062 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__step__distortion_8c_source.html b/html/sinfo__step__distortion_8c_source.html
new file mode 100644
index 0000000..538915b
--- /dev/null
+++ b/html/sinfo__step__distortion_8c_source.html
@@ -0,0 +1,318 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_step_distortion.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_step_distortion.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_step_distortion.c,v 1.20 2008/02/12 14:56:50 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the CPL (Common Pipeline Library)</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
+<a name="l00007"></a>00007 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span>
+<a name="l00008"></a>00008 <span class="comment"> * License as published by the Free Software Foundation; either</span>
+<a name="l00009"></a>00009 <span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
+<a name="l00014"></a>00014 <span class="comment"> * Lesser General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
+<a name="l00017"></a>00017 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2008/02/12 14:56:50 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.20 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028  <span class="comment">/****************************************************************</span>
+<a name="l00029"></a>00029 <span class="comment">  *          Distortion Frames Data Reduction                          *</span>
+<a name="l00030"></a>00030 <span class="comment">  ****************************************************************/</span>
+<a name="l00031"></a>00031 <span class="preprocessor">#include <strings.h></span>
+<a name="l00032"></a>00032 <span class="preprocessor">#include <string.h></span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include <irplib_utils.h></span>
+<a name="l00034"></a>00034 <span class="preprocessor">#include <stdio.h></span>
+<a name="l00035"></a>00035 
+<a name="l00036"></a>00036 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00037"></a>00037 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>          
+<a name="l00038"></a>00038 <span class="preprocessor">#endif</span>
+<a name="l00039"></a>00039 <span class="preprocessor"></span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include <cpl.h></span>      
+<a name="l00041"></a>00041 
+<a name="l00042"></a>00042 
+<a name="l00043"></a>00043 <span class="preprocessor">#include <sinfo_key_names.h></span>
+<a name="l00044"></a>00044 <span class="preprocessor">#include <sinfo_globals.h></span>
+<a name="l00045"></a>00045 <span class="preprocessor">#include <sinfo_pro_types.h></span>
+<a name="l00046"></a>00046 <span class="preprocessor">#include <sinfo_product_config.h></span>
+<a name="l00047"></a>00047 <span class="preprocessor">#include <sinfo_prepare_stacked_frames_config.h></span>
+<a name="l00048"></a>00048 <span class="preprocessor">#include <sinfo_north_south_test_config.h></span>
+<a name="l00049"></a>00049 
+<a name="l00050"></a>00050 <span class="preprocessor">#include <sinfo_new_prepare_stacked_frames.h></span>
+<a name="l00051"></a>00051 <span class="preprocessor">#include <sinfo_distortion_config.h></span>
+<a name="l00052"></a>00052 <span class="preprocessor">#include <sinfo_new_find_distortions.h></span>
+<a name="l00053"></a>00053 <span class="preprocessor">#include <sinfo_new_nst.h></span>
+<a name="l00054"></a>00054 <span class="preprocessor">#include <sinfo_hidden.h></span>
+<a name="l00055"></a>00055 <span class="preprocessor">#include <sinfo_tpl_dfs.h></span>
+<a name="l00056"></a>00056 <span class="preprocessor">#include <sinfo_globals.h></span>
+<a name="l00057"></a>00057 <span class="preprocessor">#include <sinfo_functions.h></span>
+<a name="l00058"></a>00058 <span class="preprocessor">#include <sinfo_tpl_utils.h></span>
+<a name="l00059"></a>00059 <span class="preprocessor">#include <sinfo_error.h></span>
+<a name="l00060"></a>00060 <span class="preprocessor">#include <sinfo_utils_wrappers.h></span>
+<a name="l00061"></a>00061 <span class="comment">//Only for sinfo_propertylist_has</span>
+<a name="l00062"></a>00062 <span class="preprocessor">#include <sinfo_dfs.h></span>
+<a name="l00063"></a>00063 
+<a name="l00064"></a>00064 <span class="keywordtype">int</span> sinfo_step_distortion_create(cpl_plugin *plugin);
+<a name="l00065"></a>00065 <span class="keywordtype">int</span> sinfo_step_distortion_exec(cpl_plugin *plugin);
+<a name="l00066"></a>00066 <span class="keywordtype">int</span> sinfo_step_distortion_destroy(cpl_plugin *plugin);
+<a name="l00067"></a>00067 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_step_distortion(cpl_parameterlist *config, cpl_frameset *<span class="keyword">set</span>);
+<a name="l00068"></a>00068 
+<a name="l00069"></a>00069 
+<a name="l00070"></a>00070 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00074"></a>00074 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00075"></a>00075 
+<a name="l00076"></a>00076 
+<a name="l00077"></a>00077 <span class="keywordtype">void</span> sinfo_find_distortion_config_add(cpl_parameterlist *); 
+<a name="l00078"></a>00078 
+<a name="l00079"></a>00079  <span class="comment">/*</span>
+<a name="l00080"></a>00080 <span class="comment">  *</span>
+<a name="l00081"></a>00081 <span class="comment">  * Create the recipe instance, i.e. setup the parameter list for this</span>
+<a name="l00082"></a>00082 <span class="comment">  * recipe and make it available to the application using the interface.</span>
+<a name="l00083"></a>00083 <span class="comment">  *</span>
+<a name="l00084"></a>00084 <span class="comment">  */</span>
+<a name="l00085"></a>00085 
+<a name="l00086"></a>00086 
+<a name="l00087"></a>00087 <span class="keywordtype">int</span>
+<a name="l00088"></a>00088 sinfo_step_distortion_create(cpl_plugin *plugin)
+<a name="l00089"></a>00089 {
+<a name="l00090"></a>00090 
+<a name="l00091"></a>00091   <span class="comment">/*</span>
+<a name="l00092"></a>00092 <span class="comment">   * We have to provide the option we accept to the application.</span>
+<a name="l00093"></a>00093 <span class="comment">   * We need to setup our parameter list and hook it into the recipe</span>
+<a name="l00094"></a>00094 <span class="comment">   * interface.</span>
+<a name="l00095"></a>00095 <span class="comment">   */</span>
+<a name="l00096"></a>00096   cpl_recipe *recipe = (cpl_recipe *)plugin;
+<a name="l00097"></a>00097   recipe->parameters = cpl_parameterlist_new();
+<a name="l00098"></a>00098   <span class="keywordflow">if</span>(recipe->parameters == NULL) {
+<a name="l00099"></a>00099     <span class="keywordflow">return</span> 1;
+<a name="l00100"></a>00100   }
+<a name="l00101"></a>00101   cpl_error_reset();
+<a name="l00102"></a>00102   <a class="code" href="group__irplib__utils.html#gaf9d392144014e2363054bc3f83c8e47e" title="Reset IRPLIB state.">irplib_reset</a>();
+<a name="l00103"></a>00103 
+<a name="l00104"></a>00104   <span class="comment">/*</span>
+<a name="l00105"></a>00105 <span class="comment">   * Fill the parameter list.</span>
+<a name="l00106"></a>00106 <span class="comment">   */</span>
+<a name="l00107"></a>00107   sinfo_product_config_add(recipe->parameters);
+<a name="l00108"></a>00108   sinfo_prepare_stacked_frames_config_add(recipe->parameters);
+<a name="l00109"></a>00109   sinfo_distortion_config_add(recipe->parameters);
+<a name="l00110"></a>00110   sinfo_north_south_test_config_add(recipe->parameters);
+<a name="l00111"></a>00111 
+<a name="l00112"></a>00112   <span class="keywordflow">return</span> 0;
+<a name="l00113"></a>00113 
+<a name="l00114"></a>00114 }
+<a name="l00115"></a>00115 
+<a name="l00116"></a>00116 <span class="keywordtype">int</span>
+<a name="l00117"></a>00117 sinfo_step_distortion_exec(cpl_plugin *plugin)
+<a name="l00118"></a>00118 {
+<a name="l00119"></a>00119 
+<a name="l00120"></a>00120   cpl_recipe *recipe = (cpl_recipe *) plugin;
+<a name="l00121"></a>00121   <span class="keywordflow">if</span>(recipe->parameters == NULL) {
+<a name="l00122"></a>00122     <span class="keywordflow">return</span> 1;
+<a name="l00123"></a>00123   }
+<a name="l00124"></a>00124   <span class="keywordflow">if</span>(recipe->frames == NULL) {
+<a name="l00125"></a>00125     <span class="keywordflow">return</span> 1;
+<a name="l00126"></a>00126   }
+<a name="l00127"></a>00127 
+<a name="l00128"></a>00128 
+<a name="l00129"></a>00129   <span class="keywordflow">return</span> sinfo_step_distortion(recipe->parameters, recipe->frames);
+<a name="l00130"></a>00130 
+<a name="l00131"></a>00131 }
+<a name="l00132"></a>00132 
+<a name="l00133"></a>00133 <span class="keywordtype">int</span>
+<a name="l00134"></a>00134 sinfo_step_distortion_destroy(cpl_plugin *plugin)
+<a name="l00135"></a>00135 {
+<a name="l00136"></a>00136 
+<a name="l00137"></a>00137   cpl_recipe *recipe = (cpl_recipe *) plugin;
+<a name="l00138"></a>00138   <span class="comment">/*</span>
+<a name="l00139"></a>00139 <span class="comment">   * We just destroy what was created during the plugin initializzation phase</span>
+<a name="l00140"></a>00140 <span class="comment">   * i.e. the parameter list. The frame set is managed by the application which</span>
+<a name="l00141"></a>00141 <span class="comment">   * called us, so that we must not touch it.</span>
+<a name="l00142"></a>00142 <span class="comment">   */</span>
+<a name="l00143"></a>00143 
+<a name="l00144"></a>00144   cpl_parameterlist_delete(recipe->parameters);
+<a name="l00145"></a>00145 
+<a name="l00146"></a>00146   <span class="keywordflow">return</span> 0;
+<a name="l00147"></a>00147 
+<a name="l00148"></a>00148 }
+<a name="l00149"></a>00149 
+<a name="l00150"></a>00150 <span class="keywordtype">int</span>
+<a name="l00151"></a>00151 <a class="code" href="group__sinfo__rec__detlin.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693" title="Build the list of available plugins, for this module.">cpl_plugin_get_info</a>(cpl_pluginlist *list)
+<a name="l00152"></a>00152 {
+<a name="l00153"></a>00153 
+<a name="l00154"></a>00154   cpl_recipe *recipe = cpl_calloc(1, <span class="keyword">sizeof</span> *recipe);
+<a name="l00155"></a>00155   cpl_plugin *plugin = &recipe->interface;
+<a name="l00156"></a>00156 
+<a name="l00157"></a>00157 
+<a name="l00158"></a>00158   cpl_plugin_init(plugin,
+<a name="l00159"></a>00159           CPL_PLUGIN_API,
+<a name="l00160"></a>00160           SINFONI_BINARY_VERSION,
+<a name="l00161"></a>00161           CPL_PLUGIN_TYPE_RECIPE,
+<a name="l00162"></a>00162           <span class="stringliteral">"sinfo_step_distortion"</span>,
+<a name="l00163"></a>00163           <span class="stringliteral">"Find Distortions in frames"</span>,
+<a name="l00164"></a>00164           <span class="stringliteral">"TBD"</span>,
+<a name="l00165"></a>00165           <span class="stringliteral">"A. Modigliani"</span>,
+<a name="l00166"></a>00166           <span class="stringliteral">"amodigli at eso.org"</span>,
+<a name="l00167"></a>00167           <span class="stringliteral">"No license"</span>,
+<a name="l00168"></a>00168           sinfo_step_distortion_create,
+<a name="l00169"></a>00169           sinfo_step_distortion_exec,
+<a name="l00170"></a>00170           sinfo_step_distortion_destroy);
+<a name="l00171"></a>00171 
+<a name="l00172"></a>00172   cpl_pluginlist_append(list, plugin);
+<a name="l00173"></a>00173 
+<a name="l00174"></a>00174   <span class="keywordflow">return</span> 0;
+<a name="l00175"></a>00175 
+<a name="l00176"></a>00176 }
+<a name="l00177"></a>00177 
+<a name="l00178"></a>00178 
+<a name="l00179"></a>00179 <span class="comment">/*</span>
+<a name="l00180"></a>00180 <span class="comment"> * The actual recipe actually start here.</span>
+<a name="l00181"></a>00181 <span class="comment"> */</span>
+<a name="l00182"></a>00182 
+<a name="l00183"></a>00183 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00184"></a>00184 sinfo_step_distortion(cpl_parameterlist *config, cpl_frameset *<span class="keyword">set</span>)
+<a name="l00185"></a>00185 {
+<a name="l00186"></a>00186  
+<a name="l00187"></a>00187  
+<a name="l00188"></a>00188   cpl_frame* frame=NULL;
+<a name="l00189"></a>00189   <span class="keywordtype">char</span> file_name[FILE_NAME_SZ];
+<a name="l00190"></a>00190   cpl_propertylist* plist=NULL;
+<a name="l00191"></a>00191 
+<a name="l00192"></a>00192   cpl_image* ima=NULL;
+<a name="l00193"></a>00193   fake* fk=NULL;
+<a name="l00194"></a>00194 
+<a name="l00195"></a>00195   ck0(sinfo_dfs_set_groups(<span class="keyword">set</span>),<span class="stringliteral">"Cannot indentify RAW and CALIB frames"</span>) ;
+<a name="l00196"></a>00196 
+<a name="l00197"></a>00197     <span class="comment">/* </span>
+<a name="l00198"></a>00198 <span class="comment">       ---------------------------------------------------------</span>
+<a name="l00199"></a>00199 <span class="comment">                DISTORTIONS </span>
+<a name="l00200"></a>00200 <span class="comment">       ---------------------------------------------------------</span>
+<a name="l00201"></a>00201 <span class="comment">     */</span>
+<a name="l00202"></a>00202    
+<a name="l00203"></a>00203          
+<a name="l00204"></a>00204   sinfo_msg(<span class="stringliteral">"COMPUTE DISTORTIONS"</span>) ; 
+<a name="l00205"></a>00205   ck0(sinfo_new_find_distortions(cpl_func,config,<span class="keyword">set</span>),
+<a name="l00206"></a>00206       <span class="stringliteral">"COMPUTE DISTORTION FAILED"</span>);
+<a name="l00207"></a>00207    
+<a name="l00208"></a>00208   <span class="keywordflow">if</span>(NULL != cpl_frameset_find(<span class="keyword">set</span>,PRO_FIBRE_NS_STACKED)) {
+<a name="l00209"></a>00209     frame = cpl_frameset_find(<span class="keyword">set</span>,PRO_FIBRE_NS_STACKED);
+<a name="l00210"></a>00210     strcpy(file_name,cpl_frame_get_filename(frame));
+<a name="l00211"></a>00211   } <span class="keywordflow">else</span> {
+<a name="l00212"></a>00212     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Frame %s not found!"</span>, PRO_FIBRE_NS_STACKED);
+<a name="l00213"></a>00213     <span class="keywordflow">goto</span> cleanup;
+<a name="l00214"></a>00214   }
+<a name="l00215"></a>00215   ima=cpl_image_load(file_name,CPL_TYPE_FLOAT,0,0);
+<a name="l00216"></a>00216 
+<a name="l00217"></a>00217   cknull(plist = cpl_propertylist_load(file_name, 0),
+<a name="l00218"></a>00218                 <span class="stringliteral">"getting header from reference ima frame %s"</span>,file_name);
+<a name="l00219"></a>00219 
+<a name="l00220"></a>00220 
+<a name="l00221"></a>00221   <span class="keywordflow">if</span> (sinfo_propertylist_has(plist, KEY_NAME_LAMP_HALO)) {
+<a name="l00222"></a>00222     cpl_propertylist_set_bool(plist, KEY_NAME_LAMP_HALO, LAMP_ON);
+<a name="l00223"></a>00223   } <span class="keywordflow">else</span> {
+<a name="l00224"></a>00224     cpl_propertylist_append_bool(plist, KEY_NAME_LAMP_HALO,LAMP_ON) ;
+<a name="l00225"></a>00225   }
+<a name="l00226"></a>00226      
+<a name="l00227"></a>00227   sinfo_free_image(&ima);
+<a name="l00228"></a>00228   sinfo_free_propertylist(&plist);
+<a name="l00229"></a>00229   sinfo_msg(<span class="stringliteral">"SUCCESS: COMPUTED DISTORTIONS"</span>) ; 
+<a name="l00230"></a>00230   
+<a name="l00231"></a>00231     <span class="comment">/* </span>
+<a name="l00232"></a>00232 <span class="comment">       ---------------------------------------------------------</span>
+<a name="l00233"></a>00233 <span class="comment">       4th iteration: distort fake frame</span>
+<a name="l00234"></a>00234 <span class="comment">       ---------------------------------------------------------</span>
+<a name="l00235"></a>00235 <span class="comment">     */</span>
+<a name="l00236"></a>00236   
+<a name="l00237"></a>00237   sinfo_msg(<span class="stringliteral">"DISTORT FAKE FRAME"</span>);
+<a name="l00238"></a>00238   fk=sinfo_fake_new();
+<a name="l00239"></a>00239 
+<a name="l00240"></a>00240   strcpy(fk->pro_class,PRO_FIBRE_NS_STACKED);
+<a name="l00241"></a>00241   fk->frm_switch=1;
+<a name="l00242"></a>00242   fk->mask_index=1;
+<a name="l00243"></a>00243   fk->ind_index=1;
+<a name="l00244"></a>00244   fk->flat_index=0;
+<a name="l00245"></a>00245   fk->wfix_index=1;
+<a name="l00246"></a>00246   fk->low_rej=0.0;
+<a name="l00247"></a>00247   fk->hig_rej=0.0;
+<a name="l00248"></a>00248   ck0(sinfo_new_prepare_stacked_frames(cpl_func,config, <span class="keyword">set</span>, 
+<a name="l00249"></a>00249                                        PRO_FIBRE_NS_STACKED_DIST, 0,fk),
+<a name="l00250"></a>00250                                        <span class="stringliteral">"FAILED STACKING FRAME"</span>) ;
+<a name="l00251"></a>00251 
+<a name="l00252"></a>00252   sinfo_msg(<span class="stringliteral">"SUCCESS: DISTORTED FAKE FRAME\n"</span>) ; 
+<a name="l00253"></a>00253   sinfo_fake_delete(&fk);
+<a name="l00254"></a>00254     
+<a name="l00255"></a>00255 
+<a name="l00256"></a>00256   <span class="keywordflow">if</span>(NULL != cpl_frameset_find(<span class="keyword">set</span>,PRO_FIBRE_NS_STACKED_DIST)) {
+<a name="l00257"></a>00257     frame = cpl_frameset_find(<span class="keyword">set</span>,PRO_FIBRE_NS_STACKED_DIST);
+<a name="l00258"></a>00258     strcpy(file_name,cpl_frame_get_filename(frame));
+<a name="l00259"></a>00259   } <span class="keywordflow">else</span> {
+<a name="l00260"></a>00260     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Frame %s not found!"</span>, PRO_FIBRE_NS_STACKED_DIST);
+<a name="l00261"></a>00261     <span class="keywordflow">goto</span> cleanup;
+<a name="l00262"></a>00262   }
+<a name="l00263"></a>00263   ima=cpl_image_load(file_name,CPL_TYPE_FLOAT,0,0);
+<a name="l00264"></a>00264     
+<a name="l00265"></a>00265   cknull(plist = cpl_propertylist_load(file_name, 0),
+<a name="l00266"></a>00266                   <span class="stringliteral">"getting header from reference ima frame %s"</span>,file_name);
+<a name="l00267"></a>00267 
+<a name="l00268"></a>00268 
+<a name="l00269"></a>00269   <span class="keywordflow">if</span> (sinfo_propertylist_has(plist, KEY_NAME_LAMP_HALO)) {
+<a name="l00270"></a>00270     cpl_propertylist_set_bool(plist, KEY_NAME_LAMP_HALO, LAMP_ON);
+<a name="l00271"></a>00271   } <span class="keywordflow">else</span> {
+<a name="l00272"></a>00272     cpl_propertylist_append_bool(plist, KEY_NAME_LAMP_HALO,LAMP_ON) ;
+<a name="l00273"></a>00273   }
+<a name="l00274"></a>00274   sinfo_free_propertylist(&plist);
+<a name="l00275"></a>00275   sinfo_free_image(&ima);
+<a name="l00276"></a>00276   sinfo_msg(<span class="stringliteral">"SUCCESS: COMPUTED DISTORTIONS\n"</span>) ; 
+<a name="l00277"></a>00277  
+<a name="l00278"></a>00278   
+<a name="l00279"></a>00279    
+<a name="l00280"></a>00280   
+<a name="l00281"></a>00281     <span class="comment">/* </span>
+<a name="l00282"></a>00282 <span class="comment">       ---------------------------------------------------------</span>
+<a name="l00283"></a>00283 <span class="comment">                               NST </span>
+<a name="l00284"></a>00284 <span class="comment">       ---------------------------------------------------------</span>
+<a name="l00285"></a>00285 <span class="comment">    */</span>
+<a name="l00286"></a>00286      
+<a name="l00287"></a>00287   sinfo_msg(<span class="stringliteral">"RUN NORD SUD TEST"</span>) ; 
+<a name="l00288"></a>00288   ck0(sinfo_new_nst(cpl_func,config, <span class="keyword">set</span> ),<span class="stringliteral">"NORTH SOUTH TEST FAILED"</span>) ;
+<a name="l00289"></a>00289   sinfo_msg(<span class="stringliteral">"SUCCESS: RUNNED NORD SUD TEST"</span>) ; 
+<a name="l00290"></a>00290   sinfo_msg(<span class="stringliteral">"SUCCESS: RECIPE\n"</span>) ;
+<a name="l00291"></a>00291 
+<a name="l00292"></a>00292 
+<a name="l00293"></a>00293  cleanup:
+<a name="l00294"></a>00294 
+<a name="l00295"></a>00295   sinfo_fake_delete(&fk);
+<a name="l00296"></a>00296   sinfo_free_propertylist(&plist) ;
+<a name="l00297"></a>00297   sinfo_free_image(&ima);
+<a name="l00298"></a>00298 
+<a name="l00299"></a>00299   <span class="keywordflow">if</span> (cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l00300"></a>00300     <span class="keywordflow">return</span> -1;
+<a name="l00301"></a>00301   } <span class="keywordflow">else</span> {
+<a name="l00302"></a>00302     <span class="keywordflow">return</span> 0;
+<a name="l00303"></a>00303   }
+<a name="l00304"></a>00304 }
+<a name="l00305"></a>00305 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__step__jitter_8c_source.html b/html/sinfo__step__jitter_8c_source.html
new file mode 100644
index 0000000..200241c
--- /dev/null
+++ b/html/sinfo__step__jitter_8c_source.html
@@ -0,0 +1,366 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_step_jitter.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_step_jitter.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_step_jitter.c,v 1.13 2007/10/08 13:26:50 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the SINFONI Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2007/10/08 13:26:50 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.13 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> */</span>
+<a name="l00026"></a>00026 
+<a name="l00027"></a>00027  <span class="comment">/****************************************************************</span>
+<a name="l00028"></a>00028 <span class="comment">  *           Object Data reduction                              *</span>
+<a name="l00029"></a>00029 <span class="comment">  ****************************************************************/</span>
+<a name="l00030"></a>00030 
+<a name="l00031"></a>00031 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00032"></a>00032 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>          <span class="comment">/* allows the program compilation */</span>
+<a name="l00033"></a>00033 <span class="preprocessor">#endif</span>
+<a name="l00034"></a>00034 <span class="preprocessor"></span>
+<a name="l00035"></a>00035 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00036"></a>00036 <span class="comment">                                Includes</span>
+<a name="l00037"></a>00037 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00038"></a>00038 
+<a name="l00039"></a>00039 <span class="comment">/* std */</span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include <strings.h></span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include <string.h></span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include <stdio.h></span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include <math.h></span>
+<a name="l00044"></a>00044 <span class="preprocessor">#include <libgen.h></span>
+<a name="l00045"></a>00045 
+<a name="l00046"></a>00046 
+<a name="l00047"></a>00047 <span class="comment">/* cpl */</span>
+<a name="l00048"></a>00048 <span class="preprocessor">#include <cpl.h></span>  
+<a name="l00049"></a>00049 
+<a name="l00050"></a>00050 <span class="comment">/* irplib */</span>
+<a name="l00051"></a>00051 <span class="preprocessor">#include <irplib_utils.h></span>
+<a name="l00052"></a>00052 
+<a name="l00053"></a>00053 <span class="comment">/* sinfoni */</span>
+<a name="l00054"></a>00054 <span class="preprocessor">#include <sinfo_pro_types.h></span>
+<a name="l00055"></a>00055 <span class="preprocessor">#include <sinfo_product_config.h></span>
+<a name="l00056"></a>00056 <span class="preprocessor">#include <sinfo_prepare_stacked_frames_config.h></span>
+<a name="l00057"></a>00057 <span class="preprocessor">#include <sinfo_objnod_config.h></span>
+<a name="l00058"></a>00058 <span class="preprocessor">#include <sinfo_standard_star_config.h></span>
+<a name="l00059"></a>00059 <span class="preprocessor">#include <sinfo_psf_config.h></span>
+<a name="l00060"></a>00060 <span class="preprocessor">#include <sinfo_skycor_config.h></span>
+<a name="l00061"></a>00061 <span class="preprocessor">#include <sinfo_new_objnod.h></span>
+<a name="l00062"></a>00062 <span class="preprocessor">#include <sinfo_new_stdstar.h></span>
+<a name="l00063"></a>00063 <span class="preprocessor">#include <sinfo_new_psf.h></span>
+<a name="l00064"></a>00064 <span class="preprocessor">#include <sinfo_new_prepare_stacked_frames.h></span>
+<a name="l00065"></a>00065 <span class="preprocessor">#include <sinfo_new_cubes_coadd.h></span>
+<a name="l00066"></a>00066 <span class="preprocessor">#include <sinfo_key_names.h></span>
+<a name="l00067"></a>00067 <span class="preprocessor">#include <sinfo_raw_types.h></span>
+<a name="l00068"></a>00068 <span class="preprocessor">#include <sinfo_functions.h></span>
+<a name="l00069"></a>00069 <span class="preprocessor">#include <sinfo_tpl_utils.h></span>
+<a name="l00070"></a>00070 <span class="preprocessor">#include <sinfo_tpl_dfs.h></span>
+<a name="l00071"></a>00071 <span class="preprocessor">#include <sinfo_hidden.h></span>
+<a name="l00072"></a>00072 <span class="preprocessor">#include <sinfo_globals.h></span>
+<a name="l00073"></a>00073 <span class="preprocessor">#include <sinfo_msg.h></span>
+<a name="l00074"></a>00074 <span class="preprocessor">#include <sinfo_rec_utils.h></span>
+<a name="l00075"></a>00075 <span class="preprocessor">#include <sinfo_error.h></span>
+<a name="l00076"></a>00076 <span class="preprocessor">#include <sinfo_utils_wrappers.h></span>
+<a name="l00077"></a>00077 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00078"></a>00078 <span class="comment">                            Functions prototypes</span>
+<a name="l00079"></a>00079 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00080"></a>00080 
+<a name="l00081"></a>00081 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_step_jitter_create(cpl_plugin *) ;
+<a name="l00082"></a>00082 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_step_jitter_exec(cpl_plugin *) ;
+<a name="l00083"></a>00083 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_step_jitter_destroy(cpl_plugin *) ;
+<a name="l00084"></a>00084 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_step_jitter(cpl_parameterlist *config, cpl_frameset *<span class="keyword">set</span>);
+<a name="l00085"></a>00085 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00086"></a>00086 <span class="comment">                            Static variables</span>
+<a name="l00087"></a>00087 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00088"></a>00088 
+<a name="l00089"></a>00089 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_step_jitter_description1[] =
+<a name="l00090"></a>00090 <span class="stringliteral">"This recipe performs science data reduction.\n"</span>
+<a name="l00091"></a>00091 <span class="stringliteral">"The input files are:\n"</span>
+<a name="l00092"></a>00092 <span class="stringliteral">"science object and sky frames with tags OBJECT_NODDING and SKY_NODDING or\n"</span>
+<a name="l00093"></a>00093 <span class="stringliteral">"Telluric standard star frames and sky frames with tags STD and SKY_STD or\n"</span>
+<a name="l00094"></a>00094 <span class="stringliteral">"PSF standard star and sky frames with tags \n"</span>
+<a name="l00095"></a>00095 <span class="stringliteral">"PSF_CALIBRATOR and SKY_PSF_CALIBRATOR\n"</span>
+<a name="l00096"></a>00096 <span class="stringliteral">"and Master calibration frames:\n"</span>;
+<a name="l00097"></a>00097 
+<a name="l00098"></a>00098 
+<a name="l00099"></a>00099 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_step_jitter_description2[] =
+<a name="l00100"></a>00100 <span class="stringliteral">"A corresponding (band,preoptics) wavelength map image with tag WAVE_MAP\n"</span>
+<a name="l00101"></a>00101 <span class="stringliteral">"A corresponding (band,preoptics) master flat field with tag MASTER_FLAT_LAMP\n"</span>
+<a name="l00102"></a>00102 <span class="stringliteral">"A corresponding (band,preoptics) master bad pixel map with tag MASTER_BP_MAP\n"</span>
+<a name="l00103"></a>00103 <span class="stringliteral">"A corresponding (band,preoptics) slitlets position frame with tag SLIT_POS\n"</span>
+<a name="l00104"></a>00104 <span class="stringliteral">"A corresponding (band) distortion table with tag DISTORTION\n"</span>
+<a name="l00105"></a>00105 <span class="stringliteral">"A corresponding (band) slitlet distance table with tag SLITLETS_DISTANCE\n"</span>;
+<a name="l00106"></a>00106 
+<a name="l00107"></a>00107 
+<a name="l00108"></a>00108 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_step_jitter_description3[] =
+<a name="l00109"></a>00109 <span class="stringliteral">"The output is an image resulting from the IMA1 op IMA2 where op indicates\n"</span>
+<a name="l00110"></a>00110 <span class="stringliteral">"A reference table with the position of the first "</span>
+<a name="l00111"></a>00111 <span class="stringliteral">"column with tag FIRST_COLUMN\n"</span>
+<a name="l00112"></a>00112 <span class="stringliteral">"Relevant outputs are:\n"</span>
+<a name="l00113"></a>00113 <span class="stringliteral">"combined cubes (PRO.CATG=x_OBS x=STD,OBJ,PSF)\n"</span>
+<a name="l00114"></a>00114 <span class="stringliteral">"reconstructed cube (PRO.CATG=COADD_x_OBS x=STD,OBJ,PSF)\n"</span>
+<a name="l00115"></a>00115 <span class="stringliteral">"An average along Z of the reconstructed cube \n"</span>
+<a name="l00116"></a>00116 <span class="stringliteral">"(PRO.CATG=MED_x_OBS x=STD,OBJ,PSF)\n"</span>
+<a name="l00117"></a>00117 <span class="stringliteral">"The bad pixel map associated to the cube \n"</span>
+<a name="l00118"></a>00118 <span class="stringliteral">"(PRO.CATG=BP_MAP_COADD_x_OBS x=STD,OBJ,PSF)\n"</span>;
+<a name="l00119"></a>00119 
+<a name="l00120"></a>00120 
+<a name="l00121"></a>00121 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_step_jitter_description4[] =
+<a name="l00122"></a>00122 <span class="stringliteral">"Information on relevant parameters can be found with\n"</span>
+<a name="l00123"></a>00123 <span class="stringliteral">"esorex --params sinfo_step_jitter\n"</span>
+<a name="l00124"></a>00124 <span class="stringliteral">"esorex --help sinfo_step_jitter\n"</span>
+<a name="l00125"></a>00125 <span class="stringliteral">"\n"</span>;
+<a name="l00126"></a>00126 
+<a name="l00127"></a>00127 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_step_jitter_description[1400];
+<a name="l00128"></a>00128 
+<a name="l00129"></a>00129 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00130"></a>00130 <span class="comment">                                Functions code</span>
+<a name="l00131"></a>00131 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00132"></a>00132 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00137"></a>00137 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00138"></a>00138 
+<a name="l00139"></a>00139 
+<a name="l00140"></a>00140 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00149"></a>00149 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00150"></a>00150 
+<a name="l00151"></a>00151 <span class="keywordtype">int</span>
+<a name="l00152"></a>00152 <a class="code" href="group__sinfo__rec__detlin.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693" title="Build the list of available plugins, for this module.">cpl_plugin_get_info</a>(cpl_pluginlist *list)
+<a name="l00153"></a>00153 {
+<a name="l00154"></a>00154 
+<a name="l00155"></a>00155   cpl_recipe *recipe = cpl_calloc(1, <span class="keyword">sizeof</span> *recipe);
+<a name="l00156"></a>00156   cpl_plugin *plugin = &recipe->interface;
+<a name="l00157"></a>00157 
+<a name="l00158"></a>00158   strcpy(sinfo_step_jitter_description,sinfo_step_jitter_description1);
+<a name="l00159"></a>00159   strcat(sinfo_step_jitter_description,sinfo_step_jitter_description2);
+<a name="l00160"></a>00160   strcat(sinfo_step_jitter_description,sinfo_step_jitter_description3);
+<a name="l00161"></a>00161   strcat(sinfo_step_jitter_description,sinfo_step_jitter_description4);
+<a name="l00162"></a>00162 
+<a name="l00163"></a>00163   cpl_plugin_init(plugin,
+<a name="l00164"></a>00164           CPL_PLUGIN_API,
+<a name="l00165"></a>00165           SINFONI_BINARY_VERSION,
+<a name="l00166"></a>00166           CPL_PLUGIN_TYPE_RECIPE,
+<a name="l00167"></a>00167           <span class="stringliteral">"sinfo_step_jitter"</span>,
+<a name="l00168"></a>00168           <span class="stringliteral">"Object or STD star or PSF star data reduction"</span>,
+<a name="l00169"></a>00169            sinfo_step_jitter_description,
+<a name="l00170"></a>00170           <span class="stringliteral">"Andrea Modigliani"</span>,
+<a name="l00171"></a>00171           <span class="stringliteral">"Andrea.Mdigliani at eso.org"</span>,
+<a name="l00172"></a>00172           sinfo_get_license(),
+<a name="l00173"></a>00173           sinfo_step_jitter_create,
+<a name="l00174"></a>00174           sinfo_step_jitter_exec,
+<a name="l00175"></a>00175           sinfo_step_jitter_destroy);
+<a name="l00176"></a>00176 
+<a name="l00177"></a>00177   cpl_pluginlist_append(list, plugin);
+<a name="l00178"></a>00178 
+<a name="l00179"></a>00179   <span class="keywordflow">return</span> 0;
+<a name="l00180"></a>00180 
+<a name="l00181"></a>00181 }
+<a name="l00182"></a>00182 
+<a name="l00183"></a>00183 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00191"></a>00191 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00192"></a>00192 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_step_jitter_create(cpl_plugin *plugin)
+<a name="l00193"></a>00193 {
+<a name="l00194"></a>00194     cpl_recipe      * recipe ;
+<a name="l00195"></a>00195 
+<a name="l00196"></a>00196     <span class="comment">/* Check that the plugin is part of a valid recipe */</span>
+<a name="l00197"></a>00197     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00198"></a>00198         recipe = (cpl_recipe *)plugin ;
+<a name="l00199"></a>00199     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00200"></a>00200 
+<a name="l00201"></a>00201     <span class="comment">/* Create the parameters list in the cpl_recipe object */</span>
+<a name="l00202"></a>00202     recipe->parameters = cpl_parameterlist_new() ; 
+<a name="l00203"></a>00203   cpl_error_reset();
+<a name="l00204"></a>00204   <a class="code" href="group__irplib__utils.html#gaf9d392144014e2363054bc3f83c8e47e" title="Reset IRPLIB state.">irplib_reset</a>();
+<a name="l00205"></a>00205 
+<a name="l00206"></a>00206 
+<a name="l00207"></a>00207   <span class="comment">/*</span>
+<a name="l00208"></a>00208 <span class="comment">   * Fill the parameter list.</span>
+<a name="l00209"></a>00209 <span class="comment">   */</span>
+<a name="l00210"></a>00210   sinfo_product_config_add(recipe->parameters);
+<a name="l00211"></a>00211   sinfo_prepare_stacked_frames_config_add(recipe->parameters);
+<a name="l00212"></a>00212   sinfo_objnod_config_add(recipe->parameters); 
+<a name="l00213"></a>00213   sinfo_skycor_config_add(recipe->parameters); 
+<a name="l00214"></a>00214   sinfo_standard_star_config_add(recipe->parameters);
+<a name="l00215"></a>00215   sinfo_psf_config_add(recipe->parameters);
+<a name="l00216"></a>00216 
+<a name="l00217"></a>00217   <span class="keywordflow">return</span> 0;
+<a name="l00218"></a>00218 
+<a name="l00219"></a>00219 }
+<a name="l00220"></a>00220 
+<a name="l00221"></a>00221 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00227"></a>00227 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00228"></a>00228 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_step_jitter_exec(cpl_plugin *plugin)
+<a name="l00229"></a>00229 {
+<a name="l00230"></a>00230  
+<a name="l00231"></a>00231   cpl_recipe *recipe = (cpl_recipe *) plugin;
+<a name="l00232"></a>00232 
+<a name="l00233"></a>00233   <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00234"></a>00234   <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00235"></a>00235       recipe = (cpl_recipe *)plugin ;
+<a name="l00236"></a>00236   <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00237"></a>00237 
+<a name="l00238"></a>00238   <span class="keywordflow">return</span> sinfo_step_jitter(recipe->parameters, recipe->frames);
+<a name="l00239"></a>00239 
+<a name="l00240"></a>00240 }
+<a name="l00241"></a>00241 
+<a name="l00242"></a>00242 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00248"></a>00248 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00249"></a>00249 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_step_jitter_destroy(cpl_plugin *plugin)
+<a name="l00250"></a>00250 {
+<a name="l00251"></a>00251 
+<a name="l00252"></a>00252    cpl_recipe  *   recipe ;
+<a name="l00253"></a>00253     
+<a name="l00254"></a>00254     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00255"></a>00255     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00256"></a>00256         recipe = (cpl_recipe *)plugin ;
+<a name="l00257"></a>00257     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00258"></a>00258 
+<a name="l00259"></a>00259   cpl_parameterlist_delete(recipe->parameters);
+<a name="l00260"></a>00260 
+<a name="l00261"></a>00261   <span class="keywordflow">return</span> 0;
+<a name="l00262"></a>00262 
+<a name="l00263"></a>00263 }
+<a name="l00264"></a>00264 
+<a name="l00265"></a>00265 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00272"></a>00272 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00273"></a>00273 
+<a name="l00274"></a>00274 <span class="comment">/*</span>
+<a name="l00275"></a>00275 <span class="comment"> * The actual recipe actually start here.</span>
+<a name="l00276"></a>00276 <span class="comment"> */</span>
+<a name="l00277"></a>00277 
+<a name="l00278"></a>00278 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_step_jitter(cpl_parameterlist *config, cpl_frameset *<span class="keyword">set</span>)
+<a name="l00279"></a>00279 {
+<a name="l00280"></a>00280   <span class="keyword">const</span> <span class="keywordtype">char</span>* pro_ctg_cube=NULL;
+<a name="l00281"></a>00281   <span class="keywordtype">int</span> ind=0;
+<a name="l00282"></a>00282   cpl_parameter* p=NULL;
+<a name="l00283"></a>00283   <span class="keywordtype">int</span> psf_sw=0;
+<a name="l00284"></a>00284   <span class="keywordtype">int</span> std_sw=0;
+<a name="l00285"></a>00285   cpl_frameset* obj_set=NULL;
+<a name="l00286"></a>00286   cpl_frame* obj_frm=NULL;
+<a name="l00287"></a>00287   <span class="keywordtype">char</span> tag[FILE_NAME_SZ];
+<a name="l00288"></a>00288   cpl_frameset* ref_set=NULL;
+<a name="l00289"></a>00289   sinfo_msg(<span class="stringliteral">"ok1"</span>);
+<a name="l00290"></a>00290   <span class="keywordflow">if</span>(sinfo_dfs_set_groups(<span class="keyword">set</span>)) {
+<a name="l00291"></a>00291     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Cannot indentify RAW and CALIB frames"</span>) ;
+<a name="l00292"></a>00292     <span class="keywordflow">return</span> -1;
+<a name="l00293"></a>00293   }
+<a name="l00294"></a>00294 
+<a name="l00295"></a>00295   sinfo_msg(<span class="stringliteral">"ok2"</span>);
+<a name="l00296"></a>00296   check_nomsg(ref_set=cpl_frameset_duplicate(<span class="keyword">set</span>));
+<a name="l00297"></a>00297   obj_set=cpl_frameset_new();
+<a name="l00298"></a>00298   sinfo_extract_obj_products(<span class="keyword">set</span>,obj_set);
+<a name="l00299"></a>00299   <span class="keywordflow">if</span>(NULL == (obj_frm = cpl_frameset_get_frame(obj_set,0))) {
+<a name="l00300"></a>00300     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"No object frames in input set."</span>);
+<a name="l00301"></a>00301     cpl_frameset_delete(obj_set);
+<a name="l00302"></a>00302     <span class="keywordflow">return</span> -1;
+<a name="l00303"></a>00303   }
+<a name="l00304"></a>00304 
+<a name="l00305"></a>00305   sinfo_msg(<span class="stringliteral">"ok3"</span>);
+<a name="l00306"></a>00306   strcpy(tag,cpl_frame_get_tag(obj_frm));
+<a name="l00307"></a>00307   <span class="keywordflow">if</span>(NULL!=sinfo_new_set_obj_procatg(tag)){
+<a name="l00308"></a>00308     pro_ctg_cube=sinfo_new_set_obj_procatg(tag);
+<a name="l00309"></a>00309   } <span class="keywordflow">else</span> {
+<a name="l00310"></a>00310     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Frame tag %s not supported."</span>,tag);
+<a name="l00311"></a>00311     cpl_frameset_delete(obj_set);
+<a name="l00312"></a>00312     <span class="keywordflow">return</span> -1;
+<a name="l00313"></a>00313   }
+<a name="l00314"></a>00314   cpl_frameset_delete(obj_set);
+<a name="l00315"></a>00315   sinfo_msg(<span class="stringliteral">"ok4"</span>);
+<a name="l00316"></a>00316   <span class="comment">/* =============================================================== </span>
+<a name="l00317"></a>00317 <span class="comment">     SCI OBJNOD </span>
+<a name="l00318"></a>00318 <span class="comment">     =============================================================== */</span>
+<a name="l00319"></a>00319   <span class="comment">/*</span>
+<a name="l00320"></a>00320 <span class="comment">    sinfo_msg("------------------------------") ; </span>
+<a name="l00321"></a>00321 <span class="comment">    sinfo_msg("COADDING CUBES");</span>
+<a name="l00322"></a>00322 <span class="comment">    sinfo_msg("------------------------------") ; </span>
+<a name="l00323"></a>00323 <span class="comment"></span>
+<a name="l00324"></a>00324 <span class="comment">    ck0(sinfo_new_cubes_coadd(cpl_func,config, set, pro_ctg_cube),</span>
+<a name="l00325"></a>00325 <span class="comment">    "COADDING CUBES") ;</span>
+<a name="l00326"></a>00326 <span class="comment">       </span>
+<a name="l00327"></a>00327 <span class="comment">    sinfo_msg("------------------------------") ; </span>
+<a name="l00328"></a>00328 <span class="comment">    sinfo_msg("COADDED CUBES");</span>
+<a name="l00329"></a>00329 <span class="comment">    sinfo_msg("------------------------------") ; </span>
+<a name="l00330"></a>00330 <span class="comment">  */</span>
+<a name="l00331"></a>00331 
+<a name="l00332"></a>00332 
+<a name="l00333"></a>00333   <span class="comment">/* =============================================================== </span>
+<a name="l00334"></a>00334 <span class="comment">     PSF</span>
+<a name="l00335"></a>00335 <span class="comment">     =============================================================== */</span>
+<a name="l00336"></a>00336   <span class="comment">/* </span>
+<a name="l00337"></a>00337 <span class="comment">  if((strcmp(pro_ctg_cube,PRO_COADD_OBJ) == 0) ||</span>
+<a name="l00338"></a>00338 <span class="comment">     (strcmp(pro_ctg_cube,PRO_COADD_PSF) == 0) ||</span>
+<a name="l00339"></a>00339 <span class="comment">     (strcmp(pro_ctg_cube,PRO_COADD_STD) == 0) ||</span>
+<a name="l00340"></a>00340 <span class="comment">     (strcmp(pro_ctg_cube,PRO_COADD_PUPIL) == 0) ) {</span>
+<a name="l00341"></a>00341 <span class="comment">  */</span>
+<a name="l00342"></a>00342       
+<a name="l00343"></a>00343   sinfo_msg(<span class="stringliteral">"ok5"</span>);
+<a name="l00344"></a>00344     p = cpl_parameterlist_find(config, <span class="stringliteral">"sinfoni.psf.switch"</span>);
+<a name="l00345"></a>00345     psf_sw = cpl_parameter_get_bool(p);
+<a name="l00346"></a>00346     sinfo_msg(<span class="stringliteral">"switch=%d"</span>,psf_sw);
+<a name="l00347"></a>00347     <span class="keywordflow">if</span>(psf_sw) {
+<a name="l00348"></a>00348       sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ;
+<a name="l00349"></a>00349       sinfo_msg(<span class="stringliteral">"REDUCE PSF STD STAR FRAMES"</span>);
+<a name="l00350"></a>00350       sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ; 
+<a name="l00351"></a>00351       <span class="keywordflow">if</span> ( -1 == (ind = sinfo_new_psf(cpl_func,config,<span class="keyword">set</span>,ref_set) ) )
+<a name="l00352"></a>00352     {
+<a name="l00353"></a>00353       sinfo_msg(<span class="stringliteral">"no: %d\n"</span>, ind) ;
+<a name="l00354"></a>00354       <span class="keywordflow">return</span> -1 ;
+<a name="l00355"></a>00355     }
+<a name="l00356"></a>00356       sinfo_msg(<span class="stringliteral">"SUCCESS REDUCE PSF STD STAR FRAMES"</span>) ;
+<a name="l00357"></a>00357     }
+<a name="l00358"></a>00358       
+<a name="l00359"></a>00359   sinfo_msg(<span class="stringliteral">"ok6"</span>);
+<a name="l00360"></a>00360     p = cpl_parameterlist_find(config, <span class="stringliteral">"sinfoni.std_star.switch"</span>);
+<a name="l00361"></a>00361     std_sw = cpl_parameter_get_bool(p);
+<a name="l00362"></a>00362     sinfo_msg(<span class="stringliteral">"switch=%d"</span>,std_sw);
+<a name="l00363"></a>00363     <span class="keywordflow">if</span>(std_sw) {
+<a name="l00364"></a>00364       sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ;
+<a name="l00365"></a>00365       sinfo_msg(<span class="stringliteral">"STD STAR DATA REDUCTION"</span>);
+<a name="l00366"></a>00366       sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ;
+<a name="l00367"></a>00367 
+<a name="l00368"></a>00368 
+<a name="l00369"></a>00369       <span class="keywordflow">if</span> ( -1 == (ind = sinfo_new_stdstar(cpl_func,config, <span class="keyword">set</span>,ref_set) ) )
+<a name="l00370"></a>00370     {
+<a name="l00371"></a>00371       sinfo_msg(<span class="stringliteral">"REDUCING STD STAR DATA No: %d"</span>,ind) ;
+<a name="l00372"></a>00372       <span class="keywordflow">return</span> -1 ;
+<a name="l00373"></a>00373     }
+<a name="l00374"></a>00374       sinfo_msg(<span class="stringliteral">"STD STAR DATA REDUCTION SUCCESS"</span>) ;
+<a name="l00375"></a>00375     }
+<a name="l00376"></a>00376   sinfo_msg(<span class="stringliteral">"ok7"</span>);
+<a name="l00377"></a>00377 
+<a name="l00378"></a>00378     <span class="comment">// }  </span>
+<a name="l00379"></a>00379       
+<a name="l00380"></a>00380  cleanup:
+<a name="l00381"></a>00381 
+<a name="l00382"></a>00382   <span class="keywordflow">return</span> 0 ;
+<a name="l00383"></a>00383 }
+<a name="l00384"></a>00384 
+<a name="l00385"></a>00385 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__step__objnod_8c_source.html b/html/sinfo__step__objnod_8c_source.html
new file mode 100644
index 0000000..5233ea9
--- /dev/null
+++ b/html/sinfo__step__objnod_8c_source.html
@@ -0,0 +1,183 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_step_objnod.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_step_objnod.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_step_objnod.c,v 1.9 2007/06/06 07:09:56 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the CPL (Common Pipeline Library)</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
+<a name="l00007"></a>00007 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span>
+<a name="l00008"></a>00008 <span class="comment"> * License as published by the Free Software Foundation; either</span>
+<a name="l00009"></a>00009 <span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
+<a name="l00014"></a>00014 <span class="comment"> * Lesser General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
+<a name="l00017"></a>00017 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2007/06/06 07:09:56 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.9 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> */</span>
+<a name="l00026"></a>00026 
+<a name="l00027"></a>00027  <span class="comment">/****************************************************************</span>
+<a name="l00028"></a>00028 <span class="comment">  *           Object Data reduction                              *</span>
+<a name="l00029"></a>00029 <span class="comment">  ****************************************************************/</span>
+<a name="l00030"></a>00030 <span class="preprocessor">#include <strings.h></span>
+<a name="l00031"></a>00031 <span class="preprocessor">#include <string.h></span>
+<a name="l00032"></a>00032 <span class="preprocessor">#include <stdio.h></span>
+<a name="l00033"></a>00033 
+<a name="l00034"></a>00034 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00035"></a>00035 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>          
+<a name="l00036"></a>00036 <span class="preprocessor">#endif</span>
+<a name="l00037"></a>00037 <span class="preprocessor"></span><span class="preprocessor">#include <cpl.h></span>      
+<a name="l00038"></a>00038 <span class="preprocessor">#include <irplib_utils.h></span>
+<a name="l00039"></a>00039 
+<a name="l00040"></a>00040 <span class="preprocessor">#include <sinfo_pro_types.h></span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include <sinfo_general_config.h></span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include <sinfo_objnod_config.h></span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include <sinfo_skycor_config.h></span>
+<a name="l00044"></a>00044 
+<a name="l00045"></a>00045 <span class="preprocessor">#include <sinfo_new_objnod.h></span>
+<a name="l00046"></a>00046 <span class="preprocessor">#include <sinfo_globals.h></span>
+<a name="l00047"></a>00047 <span class="preprocessor">#include <sinfo_tpl_utils.h></span>
+<a name="l00048"></a>00048 
+<a name="l00049"></a>00049 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_step_objnod(cpl_parameterlist *, cpl_frameset *);
+<a name="l00050"></a>00050 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00054"></a>00054 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00055"></a>00055 
+<a name="l00056"></a>00056 
+<a name="l00057"></a>00057 
+<a name="l00058"></a>00058 <span class="keywordtype">int</span>
+<a name="l00059"></a>00059 sinfo_step_objnod_create(cpl_plugin *plugin)
+<a name="l00060"></a>00060 {
+<a name="l00061"></a>00061 
+<a name="l00062"></a>00062   <span class="comment">/*</span>
+<a name="l00063"></a>00063 <span class="comment">   * We have to provide the option we accept to the application.</span>
+<a name="l00064"></a>00064 <span class="comment">   * We need to setup our parameter list and hook it into the recipe</span>
+<a name="l00065"></a>00065 <span class="comment">   * interface.</span>
+<a name="l00066"></a>00066 <span class="comment">   */</span>
+<a name="l00067"></a>00067   cpl_recipe *recipe = (cpl_recipe *)plugin;
+<a name="l00068"></a>00068   recipe->parameters = cpl_parameterlist_new();
+<a name="l00069"></a>00069   <span class="keywordflow">if</span>(recipe->parameters == NULL) {
+<a name="l00070"></a>00070     <span class="keywordflow">return</span> 1;
+<a name="l00071"></a>00071   }
+<a name="l00072"></a>00072   <a class="code" href="group__irplib__utils.html#gaf9d392144014e2363054bc3f83c8e47e" title="Reset IRPLIB state.">irplib_reset</a>();
+<a name="l00073"></a>00073   cpl_error_reset();
+<a name="l00074"></a>00074 
+<a name="l00075"></a>00075   <span class="comment">/*</span>
+<a name="l00076"></a>00076 <span class="comment">   * Fill the parameter list.</span>
+<a name="l00077"></a>00077 <span class="comment">   */</span>
+<a name="l00078"></a>00078 
+<a name="l00079"></a>00079   <span class="comment">/* General parameters */</span>
+<a name="l00080"></a>00080   sinfo_general_config_add(recipe->parameters); 
+<a name="l00081"></a>00081   sinfo_objnod_config_add(recipe->parameters); 
+<a name="l00082"></a>00082   sinfo_skycor_config_add(recipe->parameters); 
+<a name="l00083"></a>00083 
+<a name="l00084"></a>00084   <span class="keywordflow">return</span> 0;
+<a name="l00085"></a>00085 
+<a name="l00086"></a>00086 }
+<a name="l00087"></a>00087 
+<a name="l00088"></a>00088 <span class="keywordtype">int</span>
+<a name="l00089"></a>00089 sinfo_step_objnod_exec(cpl_plugin *plugin)
+<a name="l00090"></a>00090 {
+<a name="l00091"></a>00091  
+<a name="l00092"></a>00092   cpl_recipe *recipe = (cpl_recipe *) plugin;
+<a name="l00093"></a>00093   <span class="keywordflow">if</span>(recipe->parameters == NULL) {
+<a name="l00094"></a>00094     <span class="keywordflow">return</span> 1;
+<a name="l00095"></a>00095   }
+<a name="l00096"></a>00096   <span class="keywordflow">if</span>(recipe->frames == NULL) {
+<a name="l00097"></a>00097     <span class="keywordflow">return</span> 1;
+<a name="l00098"></a>00098   }
+<a name="l00099"></a>00099   <span class="keywordflow">return</span> sinfo_step_objnod(recipe->parameters, recipe->frames);
+<a name="l00100"></a>00100 
+<a name="l00101"></a>00101 }
+<a name="l00102"></a>00102 
+<a name="l00103"></a>00103 <span class="keywordtype">int</span>
+<a name="l00104"></a>00104 sinfo_step_objnod_destroy(cpl_plugin *plugin)
+<a name="l00105"></a>00105 {
+<a name="l00106"></a>00106   cpl_recipe *recipe = (cpl_recipe *) plugin;
+<a name="l00107"></a>00107   <span class="comment">/*</span>
+<a name="l00108"></a>00108 <span class="comment">   * We just destroy what was created during the plugin initializzation phase</span>
+<a name="l00109"></a>00109 <span class="comment">   * i.e. the parameter list. The frame set is managed by the application which</span>
+<a name="l00110"></a>00110 <span class="comment">   * called us, so that we must not touch it.</span>
+<a name="l00111"></a>00111 <span class="comment">   */</span>
+<a name="l00112"></a>00112 
+<a name="l00113"></a>00113   cpl_parameterlist_delete(recipe->parameters);
+<a name="l00114"></a>00114 
+<a name="l00115"></a>00115   <span class="keywordflow">return</span> 0;
+<a name="l00116"></a>00116 
+<a name="l00117"></a>00117 }
+<a name="l00118"></a>00118 
+<a name="l00119"></a>00119 <span class="keywordtype">int</span>
+<a name="l00120"></a>00120 <a class="code" href="group__sinfo__rec__detlin.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693" title="Build the list of available plugins, for this module.">cpl_plugin_get_info</a>(cpl_pluginlist *list)
+<a name="l00121"></a>00121 {
+<a name="l00122"></a>00122 
+<a name="l00123"></a>00123   cpl_recipe *recipe = cpl_calloc(1, <span class="keyword">sizeof</span> *recipe);
+<a name="l00124"></a>00124   cpl_plugin *plugin = &recipe->interface;
+<a name="l00125"></a>00125 
+<a name="l00126"></a>00126 
+<a name="l00127"></a>00127   cpl_plugin_init(plugin,
+<a name="l00128"></a>00128           CPL_PLUGIN_API,
+<a name="l00129"></a>00129           SINFONI_BINARY_VERSION,
+<a name="l00130"></a>00130           CPL_PLUGIN_TYPE_RECIPE,
+<a name="l00131"></a>00131           <span class="stringliteral">"sinfo_step_objnod"</span>,
+<a name="l00132"></a>00132           <span class="stringliteral">"Object data reduction"</span>,
+<a name="l00133"></a>00133           <span class="stringliteral">"TBD"</span>,
+<a name="l00134"></a>00134           <span class="stringliteral">"A. Modigliani"</span>,
+<a name="l00135"></a>00135           <span class="stringliteral">"amodigli at eso.org"</span>,
+<a name="l00136"></a>00136           <span class="stringliteral">"No license"</span>,
+<a name="l00137"></a>00137           sinfo_step_objnod_create,
+<a name="l00138"></a>00138           sinfo_step_objnod_exec,
+<a name="l00139"></a>00139           sinfo_step_objnod_destroy);
+<a name="l00140"></a>00140 
+<a name="l00141"></a>00141   cpl_pluginlist_append(list, plugin);
+<a name="l00142"></a>00142 
+<a name="l00143"></a>00143   <span class="keywordflow">return</span> 0;
+<a name="l00144"></a>00144 
+<a name="l00145"></a>00145 }
+<a name="l00146"></a>00146 
+<a name="l00147"></a>00147 
+<a name="l00148"></a>00148 
+<a name="l00149"></a>00149 <span class="comment">/*</span>
+<a name="l00150"></a>00150 <span class="comment"> * The actual recipe actually start here.</span>
+<a name="l00151"></a>00151 <span class="comment"> */</span>
+<a name="l00152"></a>00152 
+<a name="l00153"></a>00153 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00154"></a>00154 sinfo_step_objnod(cpl_parameterlist *config, cpl_frameset *<span class="keyword">set</span>)
+<a name="l00155"></a>00155 { 
+<a name="l00156"></a>00156   <span class="keywordtype">int</span>  ind =0;
+<a name="l00157"></a>00157 
+<a name="l00158"></a>00158   sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ;
+<a name="l00159"></a>00159   sinfo_msg(<span class="stringliteral">"NODDING SCIENCE FRAMES"</span>);
+<a name="l00160"></a>00160   sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ; 
+<a name="l00161"></a>00161   <span class="keywordflow">if</span> ( -1 == (ind = sinfo_new_objnod(cpl_func,config,<span class="keyword">set</span>,PRO_COADD_OBJ))) {
+<a name="l00162"></a>00162     sinfo_msg(<span class="stringliteral">"no: %d\n"</span>, ind) ;
+<a name="l00163"></a>00163     <span class="keywordflow">return</span> -1 ;
+<a name="l00164"></a>00164   } <span class="keywordflow">else</span> {
+<a name="l00165"></a>00165     sinfo_msg(<span class="stringliteral">"success"</span>);
+<a name="l00166"></a>00166   }
+<a name="l00167"></a>00167   <span class="keywordflow">return</span> 0 ;
+<a name="l00168"></a>00168 
+<a name="l00169"></a>00169 }
+<a name="l00170"></a>00170 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__step__psf_8c_source.html b/html/sinfo__step__psf_8c_source.html
new file mode 100644
index 0000000..6b2dec5
--- /dev/null
+++ b/html/sinfo__step__psf_8c_source.html
@@ -0,0 +1,197 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_step_psf.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_step_psf.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_step_psf.c,v 1.7 2007/06/06 07:09:56 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the CPL (Common Pipeline Library)</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
+<a name="l00007"></a>00007 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span>
+<a name="l00008"></a>00008 <span class="comment"> * License as published by the Free Software Foundation; either</span>
+<a name="l00009"></a>00009 <span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
+<a name="l00014"></a>00014 <span class="comment"> * Lesser General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
+<a name="l00017"></a>00017 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2007/06/06 07:09:56 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.7 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> */</span>
+<a name="l00026"></a>00026 
+<a name="l00027"></a>00027  <span class="comment">/****************************************************************</span>
+<a name="l00028"></a>00028 <span class="comment">  *          _Step_Psf Frames Data Reduction                          *</span>
+<a name="l00029"></a>00029 <span class="comment">  ****************************************************************/</span>
+<a name="l00030"></a>00030 
+<a name="l00031"></a>00031 <span class="preprocessor">#include <strings.h></span>
+<a name="l00032"></a>00032 <span class="preprocessor">#include <string.h></span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include <stdio.h></span>
+<a name="l00034"></a>00034 
+<a name="l00035"></a>00035 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00036"></a>00036 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>          <span class="comment">/* allows the program compilation */</span>
+<a name="l00037"></a>00037 <span class="preprocessor">#endif</span>
+<a name="l00038"></a>00038 <span class="preprocessor"></span><span class="preprocessor">#include <cpl.h></span> 
+<a name="l00039"></a>00039 <span class="preprocessor">#include <sinfo_pro_types.h></span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include <sinfo_psf_config.h></span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include <sinfo_new_psf.h></span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include <sinfo_tpl_utils.h></span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include <sinfo_msg.h></span>
+<a name="l00044"></a>00044 <span class="preprocessor">#include <irplib_utils.h></span>
+<a name="l00045"></a>00045 
+<a name="l00046"></a>00046 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00047"></a>00047 <span class="comment">                            Functions prototypes</span>
+<a name="l00048"></a>00048 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00049"></a>00049 
+<a name="l00050"></a>00050 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_step_psf(cpl_parameterlist *, cpl_frameset *);
+<a name="l00051"></a>00051 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_step_psf_create(cpl_plugin* plugin );
+<a name="l00052"></a>00052 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_step_psf_exec(cpl_plugin* plugin);
+<a name="l00053"></a>00053 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_step_psf_destroy(cpl_plugin* plugin);
+<a name="l00054"></a>00054 
+<a name="l00055"></a>00055 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00056"></a>00056 <span class="comment">                            Static variables</span>
+<a name="l00057"></a>00057 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00058"></a>00058 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_step_psf_description[] =<span class="stringliteral">"to debug\n"</span>;
+<a name="l00059"></a>00059 
+<a name="l00060"></a>00060 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00061"></a>00061 <span class="comment">                                Functions code</span>
+<a name="l00062"></a>00062 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00063"></a>00063 
+<a name="l00064"></a>00064 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00068"></a>00068 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00069"></a>00069 
+<a name="l00070"></a>00070 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00079"></a>00079 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00080"></a>00080 
+<a name="l00081"></a>00081 
+<a name="l00082"></a>00082 <span class="keywordtype">int</span>
+<a name="l00083"></a>00083 <a class="code" href="group__sinfo__rec__detlin.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693" title="Build the list of available plugins, for this module.">cpl_plugin_get_info</a>(cpl_pluginlist *list)
+<a name="l00084"></a>00084 {
+<a name="l00085"></a>00085 
+<a name="l00086"></a>00086   cpl_recipe *recipe = cpl_calloc(1, <span class="keyword">sizeof</span> *recipe);
+<a name="l00087"></a>00087   cpl_plugin *plugin = &recipe->interface;
+<a name="l00088"></a>00088 
+<a name="l00089"></a>00089 
+<a name="l00090"></a>00090   cpl_plugin_init(plugin,
+<a name="l00091"></a>00091           CPL_PLUGIN_API,
+<a name="l00092"></a>00092           SINFONI_BINARY_VERSION,
+<a name="l00093"></a>00093           CPL_PLUGIN_TYPE_RECIPE,
+<a name="l00094"></a>00094           <span class="stringliteral">"sinfo_step_psf"</span>,
+<a name="l00095"></a>00095           <span class="stringliteral">"PSF determination"</span>,
+<a name="l00096"></a>00096           sinfo_step_psf_description,
+<a name="l00097"></a>00097           <span class="stringliteral">"A. Modigliani"</span>,
+<a name="l00098"></a>00098           <span class="stringliteral">"amodigli at eso.org"</span>,
+<a name="l00099"></a>00099           <span class="stringliteral">"No license"</span>,
+<a name="l00100"></a>00100           sinfo_step_psf_create,
+<a name="l00101"></a>00101           sinfo_step_psf_exec,
+<a name="l00102"></a>00102           sinfo_step_psf_destroy);
+<a name="l00103"></a>00103 
+<a name="l00104"></a>00104   cpl_pluginlist_append(list, plugin);
+<a name="l00105"></a>00105 
+<a name="l00106"></a>00106   <span class="keywordflow">return</span> 0;
+<a name="l00107"></a>00107 
+<a name="l00108"></a>00108 }
+<a name="l00109"></a>00109 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00117"></a>00117 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00118"></a>00118 <span class="keywordtype">int</span>
+<a name="l00119"></a>00119 sinfo_step_psf_create(cpl_plugin *plugin)
+<a name="l00120"></a>00120 {
+<a name="l00121"></a>00121     cpl_recipe      * recipe ;
+<a name="l00122"></a>00122 
+<a name="l00123"></a>00123     <span class="comment">/* Check that the plugin is part of a valid recipe */</span>
+<a name="l00124"></a>00124     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00125"></a>00125         recipe = (cpl_recipe *)plugin ;
+<a name="l00126"></a>00126     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00127"></a>00127 
+<a name="l00128"></a>00128     <span class="comment">/* Create the parameters list in the cpl_recipe object */</span>
+<a name="l00129"></a>00129     recipe->parameters = cpl_parameterlist_new() ; 
+<a name="l00130"></a>00130 
+<a name="l00131"></a>00131   <span class="comment">/*</span>
+<a name="l00132"></a>00132 <span class="comment">   * Fill the parameter list.</span>
+<a name="l00133"></a>00133 <span class="comment">   */</span>
+<a name="l00134"></a>00134   <a class="code" href="group__irplib__utils.html#gaf9d392144014e2363054bc3f83c8e47e" title="Reset IRPLIB state.">irplib_reset</a>(); 
+<a name="l00135"></a>00135   sinfo_psf_config_add(recipe->parameters);
+<a name="l00136"></a>00136   
+<a name="l00137"></a>00137   <span class="keywordflow">return</span> 0;
+<a name="l00138"></a>00138 
+<a name="l00139"></a>00139 }
+<a name="l00140"></a>00140 
+<a name="l00141"></a>00141 
+<a name="l00142"></a>00142 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00148"></a>00148 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00149"></a>00149 <span class="keywordtype">int</span>
+<a name="l00150"></a>00150 sinfo_step_psf_exec(cpl_plugin *plugin)
+<a name="l00151"></a>00151 {
+<a name="l00152"></a>00152 
+<a name="l00153"></a>00153     cpl_recipe  *   recipe ;
+<a name="l00154"></a>00154     
+<a name="l00155"></a>00155     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00156"></a>00156     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00157"></a>00157         recipe = (cpl_recipe *)plugin ;
+<a name="l00158"></a>00158     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00159"></a>00159 
+<a name="l00160"></a>00160   <span class="keywordflow">return</span> sinfo_step_psf(recipe->parameters, recipe->frames);
+<a name="l00161"></a>00161 
+<a name="l00162"></a>00162 }
+<a name="l00163"></a>00163 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00169"></a>00169 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00170"></a>00170 
+<a name="l00171"></a>00171 <span class="keywordtype">int</span>
+<a name="l00172"></a>00172 sinfo_step_psf_destroy(cpl_plugin *plugin)
+<a name="l00173"></a>00173 {
+<a name="l00174"></a>00174     cpl_recipe  *   recipe ;
+<a name="l00175"></a>00175     
+<a name="l00176"></a>00176     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00177"></a>00177     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00178"></a>00178         recipe = (cpl_recipe *)plugin ;
+<a name="l00179"></a>00179     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00180"></a>00180 
+<a name="l00181"></a>00181   cpl_parameterlist_delete(recipe->parameters);
+<a name="l00182"></a>00182 
+<a name="l00183"></a>00183   <span class="keywordflow">return</span> 0;
+<a name="l00184"></a>00184 
+<a name="l00185"></a>00185 }
+<a name="l00186"></a>00186 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00193"></a>00193 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00194"></a>00194 
+<a name="l00195"></a>00195 <span class="comment">/*</span>
+<a name="l00196"></a>00196 <span class="comment"> * The actual recipe actually start here.</span>
+<a name="l00197"></a>00197 <span class="comment"> */</span>
+<a name="l00198"></a>00198 
+<a name="l00199"></a>00199 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00200"></a>00200 sinfo_step_psf(cpl_parameterlist *config, cpl_frameset *<span class="keyword">set</span>)
+<a name="l00201"></a>00201 {
+<a name="l00202"></a>00202 
+<a name="l00203"></a>00203   <span class="keywordtype">int</span>  ind =0;
+<a name="l00204"></a>00204 
+<a name="l00205"></a>00205     {
+<a name="l00206"></a>00206     sinfo_msg(<span class="stringliteral">"running"</span>) ; 
+<a name="l00207"></a>00207         <span class="keywordflow">if</span> ( -1 == (ind = sinfo_new_psf(cpl_func,config,<span class="keyword">set</span>) ) )
+<a name="l00208"></a>00208         {
+<a name="l00209"></a>00209         sinfo_msg(<span class="stringliteral">"no: %d\n"</span>, ind) ;
+<a name="l00210"></a>00210         <span class="keywordflow">return</span> -1 ;
+<a name="l00211"></a>00211     }
+<a name="l00212"></a>00212     sinfo_msg (<span class="stringliteral">"success\n"</span>) ; 
+<a name="l00213"></a>00213     }    
+<a name="l00214"></a>00214     <span class="keywordflow">return</span> 0 ;
+<a name="l00215"></a>00215 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__step__stdstar_8c_source.html b/html/sinfo__step__stdstar_8c_source.html
new file mode 100644
index 0000000..13a8094
--- /dev/null
+++ b/html/sinfo__step__stdstar_8c_source.html
@@ -0,0 +1,282 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_step_stdstar.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_step_stdstar.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_step_stdstar.c,v 1.8 2008/06/11 13:41:24 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the SINFONI Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2008/06/11 13:41:24 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.8 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028  <span class="comment">/****************************************************************</span>
+<a name="l00029"></a>00029 <span class="comment">  *          Standard_Star Frames Data Reduction                          *</span>
+<a name="l00030"></a>00030 <span class="comment">  ****************************************************************/</span>
+<a name="l00031"></a>00031 
+<a name="l00032"></a>00032 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                                Includes</span>
+<a name="l00034"></a>00034 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 
+<a name="l00036"></a>00036 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00037"></a>00037 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>          <span class="comment">/* allows the program compilation */</span>
+<a name="l00038"></a>00038 <span class="preprocessor">#endif</span>
+<a name="l00039"></a>00039 <span class="preprocessor"></span>
+<a name="l00040"></a>00040 <span class="comment">/* std */</span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include <strings.h></span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include <string.h></span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include <stdio.h></span>
+<a name="l00044"></a>00044 
+<a name="l00045"></a>00045 
+<a name="l00046"></a>00046 <span class="comment">/* cpl */</span>
+<a name="l00047"></a>00047 <span class="preprocessor">#include <cpl.h></span>      
+<a name="l00048"></a>00048 
+<a name="l00049"></a>00049 <span class="comment">/* irplib */</span>
+<a name="l00050"></a>00050 <span class="preprocessor">#include <irplib_utils.h></span>
+<a name="l00051"></a>00051 
+<a name="l00052"></a>00052 <span class="comment">/* sinfoni */</span>
+<a name="l00053"></a>00053 <span class="preprocessor">#include <sinfo_pro_types.h></span>
+<a name="l00054"></a>00054 <span class="preprocessor">#include <sinfo_prepare_stacked_frames_config.h></span>
+<a name="l00055"></a>00055 <span class="preprocessor">#include <sinfo_objnod_config.h></span>
+<a name="l00056"></a>00056 <span class="preprocessor">#include <sinfo_standard_star_config.h></span>
+<a name="l00057"></a>00057 <span class="preprocessor">#include <sinfo_skycor_config.h></span>
+<a name="l00058"></a>00058 <span class="preprocessor">#include <sinfo_new_prepare_stacked_frames.h></span>
+<a name="l00059"></a>00059 <span class="preprocessor">#include <sinfo_new_cubes_coadd.h></span>
+<a name="l00060"></a>00060 <span class="preprocessor">#include <sinfo_new_stdstar.h></span>
+<a name="l00061"></a>00061 <span class="preprocessor">#include <sinfo_functions.h></span>
+<a name="l00062"></a>00062 <span class="preprocessor">#include <sinfo_tpl_utils.h></span>
+<a name="l00063"></a>00063 <span class="preprocessor">#include <sinfo_tpl_dfs.h></span>
+<a name="l00064"></a>00064 <span class="preprocessor">#include <sinfo_hidden.h></span>
+<a name="l00065"></a>00065 <span class="preprocessor">#include <sinfo_globals.h></span>
+<a name="l00066"></a>00066 <span class="preprocessor">#include <sinfo_msg.h></span>
+<a name="l00067"></a>00067 <span class="preprocessor">#include <sinfo_rec_utils.h></span>
+<a name="l00068"></a>00068 <span class="preprocessor">#include <sinfo_error.h></span>
+<a name="l00069"></a>00069 <span class="preprocessor">#include <sinfo_utils_wrappers.h></span>
+<a name="l00070"></a>00070 
+<a name="l00071"></a>00071 
+<a name="l00072"></a>00072 
+<a name="l00073"></a>00073 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00074"></a>00074 <span class="comment">                            Functions prototypes</span>
+<a name="l00075"></a>00075 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00076"></a>00076 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_step_stdstar_create(cpl_plugin *) ;
+<a name="l00077"></a>00077 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_step_stdstar_exec(cpl_plugin *) ;
+<a name="l00078"></a>00078 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_step_stdstar_destroy(cpl_plugin *) ;
+<a name="l00079"></a>00079 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_step_stdstar(cpl_parameterlist *, cpl_frameset *);
+<a name="l00080"></a>00080 
+<a name="l00081"></a>00081 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00082"></a>00082 <span class="comment">                            Static variables</span>
+<a name="l00083"></a>00083 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00084"></a>00084 
+<a name="l00085"></a>00085 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_step_stdstar_description1[] =
+<a name="l00086"></a>00086 <span class="stringliteral">"This recipe performs science data reduction.\n"</span>
+<a name="l00087"></a>00087 <span class="stringliteral">"The input files are science object and sky frames with tags\n"</span>
+<a name="l00088"></a>00088 <span class="stringliteral">"STD_NODDING and SKY_STD_NODDING\n"</span>;
+<a name="l00089"></a>00089 
+<a name="l00090"></a>00090 
+<a name="l00091"></a>00091 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_step_stdstar_description2[] =
+<a name="l00092"></a>00092 <span class="stringliteral">"Master calibration frames:\n"</span>
+<a name="l00093"></a>00093 <span class="stringliteral">"A corresponding (band,preoptics) wavelength map image with tag WAVE_MAP\n"</span>
+<a name="l00094"></a>00094 <span class="stringliteral">"A corresponding (band,preoptics) master flat field with tag MASTER_FLAT_LAMP\n"</span>
+<a name="l00095"></a>00095 <span class="stringliteral">"A corresponding (band,preoptics) master bad pixel map with tag MASTER_BP_MAP\n"</span>
+<a name="l00096"></a>00096 <span class="stringliteral">"A corresponding (band,preoptics) slitlets position frame with tag SLIT_POS\n"</span>
+<a name="l00097"></a>00097 <span class="stringliteral">"A corresponding (band) distortion table with tag DISTORTION\n"</span>
+<a name="l00098"></a>00098 <span class="stringliteral">"A corresponding (band) slitlet distance table with tag SLITLETS_DISTANCE\n"</span>;
+<a name="l00099"></a>00099 
+<a name="l00100"></a>00100 
+<a name="l00101"></a>00101 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_step_stdstar_description3[] =
+<a name="l00102"></a>00102 <span class="stringliteral">"The output is an image resulting from the IMA1 op IMA2 where op indicates\n"</span>
+<a name="l00103"></a>00103 <span class="stringliteral">"A reference table with the position of the first  column\n"</span>
+<a name="l00104"></a>00104 <span class="stringliteral">" with tag FIRST_COLUMN\n"</span>
+<a name="l00105"></a>00105 <span class="stringliteral">"Relevant outputs are:\n"</span>
+<a name="l00106"></a>00106 <span class="stringliteral">"combined cubes (PRO.CATG=x_OBS x=STD,OBJ,PSF)\n"</span>
+<a name="l00107"></a>00107 <span class="stringliteral">"reconstructed cube (PRO.CATG=COADD_x_OBS x=STD,OBJ,PSF)\n"</span>;
+<a name="l00108"></a>00108 
+<a name="l00109"></a>00109 
+<a name="l00110"></a>00110 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_step_stdstar_description4[] =
+<a name="l00111"></a>00111 <span class="stringliteral">"An average along Z of the reconstructed cube \n"</span>
+<a name="l00112"></a>00112 <span class="stringliteral">"(PRO.CATG=MED_x_OBS x=STD,OBJ,PSF)\n"</span>
+<a name="l00113"></a>00113 <span class="stringliteral">"The bad pixel map associated to the cube \n"</span>
+<a name="l00114"></a>00114 <span class="stringliteral">"(PRO.CATG=BP_MAP_COADD_x_OBS x=STD,OBJ,PSF)\n"</span>
+<a name="l00115"></a>00115 <span class="stringliteral">"The std star spectrum image (PRO.CATG=STD_SPECTRUM)\n"</span>
+<a name="l00116"></a>00116 <span class="stringliteral">"The std start spectrum and efficiency spectrum table (PRO.CATG=STD_SPECTRA)\n"</span>
+<a name="l00117"></a>00117 <span class="stringliteral">"Information on relevant parameters can be found with\n"</span>
+<a name="l00118"></a>00118 <span class="stringliteral">"esorex --params sinfo_step_stdstar\n"</span>
+<a name="l00119"></a>00119 <span class="stringliteral">"esorex --help sinfo_step_stdstar\n"</span>
+<a name="l00120"></a>00120 <span class="stringliteral">"\n"</span>;
+<a name="l00121"></a>00121 
+<a name="l00122"></a>00122 
+<a name="l00123"></a>00123 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_step_stdstar_description[1300];
+<a name="l00124"></a>00124 
+<a name="l00125"></a>00125 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00126"></a>00126 <span class="comment">                                Functions code</span>
+<a name="l00127"></a>00127 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00128"></a>00128 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00132"></a>00132 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00133"></a>00133 
+<a name="l00134"></a>00134 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00143"></a>00143 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00144"></a>00144 
+<a name="l00145"></a>00145 
+<a name="l00146"></a>00146 <span class="keywordtype">int</span>
+<a name="l00147"></a>00147 <a class="code" href="group__sinfo__rec__detlin.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693" title="Build the list of available plugins, for this module.">cpl_plugin_get_info</a>(cpl_pluginlist *list)
+<a name="l00148"></a>00148 {
+<a name="l00149"></a>00149 
+<a name="l00150"></a>00150   cpl_recipe *recipe = cpl_calloc(1, <span class="keyword">sizeof</span> *recipe);
+<a name="l00151"></a>00151   cpl_plugin *plugin = &recipe->interface;
+<a name="l00152"></a>00152 
+<a name="l00153"></a>00153   strcpy(sinfo_step_stdstar_description,sinfo_step_stdstar_description1);
+<a name="l00154"></a>00154   strcat(sinfo_step_stdstar_description,sinfo_step_stdstar_description2);
+<a name="l00155"></a>00155   strcat(sinfo_step_stdstar_description,sinfo_step_stdstar_description3);
+<a name="l00156"></a>00156   strcat(sinfo_step_stdstar_description,sinfo_step_stdstar_description4);
+<a name="l00157"></a>00157 
+<a name="l00158"></a>00158 
+<a name="l00159"></a>00159   cpl_plugin_init(plugin,
+<a name="l00160"></a>00160           CPL_PLUGIN_API,
+<a name="l00161"></a>00161           SINFONI_BINARY_VERSION,
+<a name="l00162"></a>00162           CPL_PLUGIN_TYPE_RECIPE,
+<a name="l00163"></a>00163           <span class="stringliteral">"sinfo_step_stdstar"</span>,
+<a name="l00164"></a>00164           <span class="stringliteral">"Standard star data reduction"</span>,
+<a name="l00165"></a>00165           sinfo_step_stdstar_description,
+<a name="l00166"></a>00166           <span class="stringliteral">"Andrea Modigliani"</span>,
+<a name="l00167"></a>00167           <span class="stringliteral">"Andrea.Modigliani at eso.org"</span>,
+<a name="l00168"></a>00168           sinfo_get_license(),
+<a name="l00169"></a>00169           sinfo_step_stdstar_create,
+<a name="l00170"></a>00170           sinfo_step_stdstar_exec,
+<a name="l00171"></a>00171           sinfo_step_stdstar_destroy);
+<a name="l00172"></a>00172 
+<a name="l00173"></a>00173   cpl_pluginlist_append(list, plugin);
+<a name="l00174"></a>00174 
+<a name="l00175"></a>00175   <span class="keywordflow">return</span> 0;
+<a name="l00176"></a>00176 
+<a name="l00177"></a>00177 }
+<a name="l00178"></a>00178 
+<a name="l00179"></a>00179 
+<a name="l00180"></a>00180 
+<a name="l00181"></a>00181 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00189"></a>00189 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00190"></a>00190 
+<a name="l00191"></a>00191 
+<a name="l00192"></a>00192 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_step_stdstar_create(cpl_plugin *plugin)
+<a name="l00193"></a>00193 {
+<a name="l00194"></a>00194     cpl_recipe      * recipe ;
+<a name="l00195"></a>00195 
+<a name="l00196"></a>00196     <span class="comment">/* Check that the plugin is part of a valid recipe */</span>
+<a name="l00197"></a>00197     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00198"></a>00198         recipe = (cpl_recipe *)plugin ;
+<a name="l00199"></a>00199     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00200"></a>00200     cpl_error_reset();
+<a name="l00201"></a>00201     <a class="code" href="group__irplib__utils.html#gaf9d392144014e2363054bc3f83c8e47e" title="Reset IRPLIB state.">irplib_reset</a>();
+<a name="l00202"></a>00202 
+<a name="l00203"></a>00203     <span class="comment">/* Create the parameters list in the cpl_recipe object */</span>
+<a name="l00204"></a>00204     recipe->parameters = cpl_parameterlist_new() ; 
+<a name="l00205"></a>00205 
+<a name="l00206"></a>00206 
+<a name="l00207"></a>00207   <span class="comment">/*</span>
+<a name="l00208"></a>00208 <span class="comment">   * Fill the parameter list.</span>
+<a name="l00209"></a>00209 <span class="comment">   */</span>
+<a name="l00210"></a>00210   sinfo_prepare_stacked_frames_config_add(recipe->parameters);
+<a name="l00211"></a>00211   sinfo_objnod_config_add(recipe->parameters); 
+<a name="l00212"></a>00212   sinfo_skycor_config_add(recipe->parameters); 
+<a name="l00213"></a>00213   sinfo_standard_star_config_add(recipe->parameters);
+<a name="l00214"></a>00214   
+<a name="l00215"></a>00215   <span class="keywordflow">return</span> 0;
+<a name="l00216"></a>00216 
+<a name="l00217"></a>00217 }
+<a name="l00218"></a>00218 
+<a name="l00219"></a>00219 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00225"></a>00225 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00226"></a>00226 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_step_stdstar_exec(cpl_plugin *plugin)
+<a name="l00227"></a>00227 {
+<a name="l00228"></a>00228     cpl_recipe  *   recipe ;
+<a name="l00229"></a>00229     
+<a name="l00230"></a>00230     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00231"></a>00231     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00232"></a>00232         recipe = (cpl_recipe *)plugin ;
+<a name="l00233"></a>00233     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00234"></a>00234 
+<a name="l00235"></a>00235   <span class="keywordflow">return</span> sinfo_step_stdstar(recipe->parameters, recipe->frames);
+<a name="l00236"></a>00236 
+<a name="l00237"></a>00237 }
+<a name="l00238"></a>00238 
+<a name="l00239"></a>00239 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00245"></a>00245 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00246"></a>00246 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_step_stdstar_destroy(cpl_plugin *plugin)
+<a name="l00247"></a>00247 {
+<a name="l00248"></a>00248     cpl_recipe  *   recipe ;
+<a name="l00249"></a>00249     
+<a name="l00250"></a>00250     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00251"></a>00251     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00252"></a>00252         recipe = (cpl_recipe *)plugin ;
+<a name="l00253"></a>00253     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00254"></a>00254 
+<a name="l00255"></a>00255   cpl_parameterlist_delete(recipe->parameters);
+<a name="l00256"></a>00256   <span class="keywordflow">return</span> 0;
+<a name="l00257"></a>00257 
+<a name="l00258"></a>00258 }
+<a name="l00259"></a>00259 
+<a name="l00260"></a>00260 
+<a name="l00261"></a>00261 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00268"></a>00268 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00269"></a>00269 
+<a name="l00270"></a>00270 
+<a name="l00271"></a>00271 <span class="comment">/*</span>
+<a name="l00272"></a>00272 <span class="comment"> * The actual recipe actually start here.</span>
+<a name="l00273"></a>00273 <span class="comment"> */</span>
+<a name="l00274"></a>00274 
+<a name="l00275"></a>00275 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00276"></a>00276 sinfo_step_stdstar(cpl_parameterlist *config, cpl_frameset *<span class="keyword">set</span>)
+<a name="l00277"></a>00277 {
+<a name="l00278"></a>00278  
+<a name="l00279"></a>00279 
+<a name="l00280"></a>00280   <span class="keywordflow">if</span>(sinfo_dfs_set_groups(<span class="keyword">set</span>)) {
+<a name="l00281"></a>00281     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Cannot indentify RAW and CALIB frames"</span>) ;
+<a name="l00282"></a>00282     <span class="keywordflow">return</span> -1;
+<a name="l00283"></a>00283   }
+<a name="l00284"></a>00284 
+<a name="l00285"></a>00285   <span class="comment">/* =============================================================== </span>
+<a name="l00286"></a>00286 <span class="comment">     STDSTAR </span>
+<a name="l00287"></a>00287 <span class="comment">     =============================================================== */</span>
+<a name="l00288"></a>00288   sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ;
+<a name="l00289"></a>00289   sinfo_msg(<span class="stringliteral">"STD STAR DATA REDUCTION"</span>);
+<a name="l00290"></a>00290   sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ;
+<a name="l00291"></a>00291 
+<a name="l00292"></a>00292   ck0(sinfo_new_stdstar(cpl_func,config, <span class="keyword">set</span>, <span class="keyword">set</span> ),<span class="stringliteral">"REDUCING STD STAR DATA"</span>) ;
+<a name="l00293"></a>00293   sinfo_msg(<span class="stringliteral">"STD STAR DATA REDUCTION SUCCESS"</span>) ; 
+<a name="l00294"></a>00294 
+<a name="l00295"></a>00295   <span class="keywordflow">return</span> 0 ;
+<a name="l00296"></a>00296  cleanup:
+<a name="l00297"></a>00297   <span class="keywordflow">return</span> -1;
+<a name="l00298"></a>00298 
+<a name="l00299"></a>00299 }
+<a name="l00300"></a>00300 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__svd_8c_source.html b/html/sinfo__svd_8c_source.html
new file mode 100644
index 0000000..a6da77e
--- /dev/null
+++ b/html/sinfo__svd_8c_source.html
@@ -0,0 +1,441 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_svd.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_svd.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/**************************************************************************</span>
+<a name="l00020"></a>00020 <span class="comment">* E.S.O. - VLT project</span>
+<a name="l00021"></a>00021 <span class="comment">*</span>
+<a name="l00022"></a>00022 <span class="comment">*</span>
+<a name="l00023"></a>00023 <span class="comment">*</span>
+<a name="l00024"></a>00024 <span class="comment">* who       when      what</span>
+<a name="l00025"></a>00025 <span class="comment">* --------  --------  ----------------------------------------------</span>
+<a name="l00026"></a>00026 <span class="comment">* schreib  16/04/03  created</span>
+<a name="l00027"></a>00027 <span class="comment">*/</span>
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span>
+<a name="l00032"></a>00032 <span class="preprocessor">#include "sinfo_svd.h"</span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00041"></a>00041 <span class="keywordtype">void</span> sinfo_fpol(<span class="keywordtype">float</span> x, <span class="keywordtype">float</span> *p, <span class="keywordtype">int</span> np)
+<a name="l00042"></a>00042 {
+<a name="l00043"></a>00043     <span class="keywordtype">int</span> j ;
+<a name="l00044"></a>00044     
+<a name="l00045"></a>00045     p[1] = 1.0 ;
+<a name="l00046"></a>00046     <span class="keywordflow">for</span> ( j = 2 ; j <= np ; j++ )
+<a name="l00047"></a>00047     {
+<a name="l00048"></a>00048         p[j] = p[j-1]*x ;
+<a name="l00049"></a>00049     }
+<a name="l00050"></a>00050 }
+<a name="l00051"></a>00051 
+<a name="l00052"></a>00052 <span class="keywordtype">void</span> 
+<a name="l00053"></a>00053 sinfo_svb_kas(<span class="keywordtype">float</span> **u, <span class="keywordtype">float</span> w[], <span class="keywordtype">float</span> **v, <span class="keywordtype">int</span> m, 
+<a name="l00054"></a>00054               <span class="keywordtype">int</span> n, <span class="keywordtype">float</span> b[],<span class="keywordtype">float</span> x[])
+<a name="l00055"></a>00055 
+<a name="l00056"></a>00056 
+<a name="l00057"></a>00057 {
+<a name="l00058"></a>00058         <span class="keywordtype">int</span> jj,j,i;
+<a name="l00059"></a>00059         <span class="keywordtype">float</span> s,*tmp;
+<a name="l00060"></a>00060 
+<a name="l00061"></a>00061         tmp=sinfo_vector(1,n);
+<a name="l00062"></a>00062         <span class="keywordflow">for</span> (j=1;j<=n;j++) {
+<a name="l00063"></a>00063                 s=0.0;
+<a name="l00064"></a>00064                 <span class="keywordflow">if</span> (w[j]) {
+<a name="l00065"></a>00065                         <span class="keywordflow">for</span> (i=1;i<=m;i++) s += u[i][j]*b[i];
+<a name="l00066"></a>00066                         s /= w[j];
+<a name="l00067"></a>00067                 }
+<a name="l00068"></a>00068                 tmp[j]=s;
+<a name="l00069"></a>00069         }
+<a name="l00070"></a>00070         <span class="keywordflow">for</span> (j=1;j<=n;j++) {
+<a name="l00071"></a>00071                 s=0.0;
+<a name="l00072"></a>00072                 <span class="keywordflow">for</span> (jj=1;jj<=n;jj++) s += v[j][jj]*tmp[jj];
+<a name="l00073"></a>00073                 x[j]=s;
+<a name="l00074"></a>00074         }
+<a name="l00075"></a>00075         sinfo_free_vector(tmp,1<span class="comment">/*,n*/</span>);
+<a name="l00076"></a>00076 }
+<a name="l00077"></a>00077 
+<a name="l00078"></a>00078 <span class="keywordtype">void</span> sinfo_svd_variance(<span class="keywordtype">float</span> **v , <span class="keywordtype">int</span> ma , <span class="keywordtype">float</span> w[] , <span class="keywordtype">float</span> **cvm)
+<a name="l00079"></a>00079 {
+<a name="l00080"></a>00080         <span class="keywordtype">int</span> k,j,i;
+<a name="l00081"></a>00081         <span class="keywordtype">float</span> sum,*wti;
+<a name="l00082"></a>00082 
+<a name="l00083"></a>00083         wti=sinfo_vector(1,ma);
+<a name="l00084"></a>00084         <span class="keywordflow">for</span> (i=1;i<=ma;i++) {
+<a name="l00085"></a>00085                 wti[i]=0.0;
+<a name="l00086"></a>00086                 <span class="keywordflow">if</span> (w[i]) wti[i]=1.0/(w[i]*w[i]);
+<a name="l00087"></a>00087         }
+<a name="l00088"></a>00088         <span class="keywordflow">for</span> (i=1;i<=ma;i++) {
+<a name="l00089"></a>00089             <span class="keywordflow">for</span> (j=1;j<=i;j++) {
+<a name="l00090"></a>00090                <span class="keywordflow">for</span> (sum=0.0,k=1;k<=ma;k++) sum += (v[i][k]*v[j][k]*wti[k]);
+<a name="l00091"></a>00091                cvm[j][i]=cvm[i][j]=sum;
+<a name="l00092"></a>00092             }
+<a name="l00093"></a>00093         }
+<a name="l00094"></a>00094         sinfo_free_vector(wti,1<span class="comment">/*,ma*/</span>);
+<a name="l00095"></a>00095 }
+<a name="l00096"></a>00096 
+<a name="l00097"></a>00097 <span class="preprocessor">#define TOL 1.0e-5</span>
+<a name="l00098"></a>00098 <span class="preprocessor"></span>
+<a name="l00099"></a>00099 <span class="keywordtype">void</span> sinfo_svd_fitting ( <span class="keywordtype">float</span> *x,
+<a name="l00100"></a>00100                    <span class="keywordtype">float</span> *y,
+<a name="l00101"></a>00101                    <span class="keywordtype">float</span> *sig,
+<a name="l00102"></a>00102                    <span class="keywordtype">int</span>   ndata,
+<a name="l00103"></a>00103                    <span class="keywordtype">float</span> *a,
+<a name="l00104"></a>00104                    <span class="keywordtype">int</span>   ma,
+<a name="l00105"></a>00105                    <span class="keywordtype">float</span> **u,
+<a name="l00106"></a>00106                    <span class="keywordtype">float</span> **v,
+<a name="l00107"></a>00107                    <span class="keywordtype">float</span> *w,
+<a name="l00108"></a>00108                    <span class="keywordtype">float</span> **cvm,
+<a name="l00109"></a>00109                    <span class="keywordtype">float</span> *chisq,
+<a name="l00110"></a>00110                    <span class="keywordtype">void</span> (*funcs)(<span class="keywordtype">float</span>,<span class="keywordtype">float</span> *,<span class="keywordtype">int</span>) )
+<a name="l00111"></a>00111 {
+<a name="l00112"></a>00112         <span class="keywordtype">int</span> j,i;
+<a name="l00113"></a>00113         <span class="keywordtype">float</span> <span class="comment">/*sini,*/</span>wmax,tmp,thresh,sum,*b,*afunc;
+<a name="l00114"></a>00114 
+<a name="l00115"></a>00115 
+<a name="l00116"></a>00116         b=sinfo_vector(1,ndata);
+<a name="l00117"></a>00117         afunc=sinfo_vector(1,ma);
+<a name="l00118"></a>00118         <span class="keywordflow">for</span> (i=1;i<=ndata;i++) {
+<a name="l00119"></a>00119 
+<a name="l00120"></a>00120                 (*funcs)(x[i],afunc,ma);
+<a name="l00121"></a>00121                 tmp=1.0/sig[i];
+<a name="l00122"></a>00122                 <span class="keywordflow">for</span> (j=1;j<=ma;j++) {
+<a name="l00123"></a>00123                         u[i][j]=afunc[j]*tmp;
+<a name="l00124"></a>00124                 }
+<a name="l00125"></a>00125                 b[i]=y[i]*tmp;
+<a name="l00126"></a>00126         }
+<a name="l00127"></a>00127         sinfo_svd_compare(u,ndata,ma,w,v);
+<a name="l00128"></a>00128 
+<a name="l00129"></a>00129         wmax=0.0;
+<a name="l00130"></a>00130         <span class="keywordflow">for</span> (j=1;j<=ma;j++)
+<a name="l00131"></a>00131                 <span class="keywordflow">if</span> (w[j] > wmax) wmax=w[j];
+<a name="l00132"></a>00132         thresh=TOL*wmax;
+<a name="l00133"></a>00133         <span class="keywordflow">for</span> (j=1;j<=ma;j++) {
+<a name="l00134"></a>00134           <span class="keywordflow">if</span> (w[j] < thresh) {
+<a name="l00135"></a>00135             w[j]=0.0;
+<a name="l00136"></a>00136             <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"SVD_FITTING detected singular value in fit !"</span>);
+<a name="l00137"></a>00137           }
+<a name="l00138"></a>00138         }
+<a name="l00139"></a>00139         sinfo_svb_kas(u,w,v,ndata,ma,b,a);
+<a name="l00140"></a>00140         *chisq=0.0;
+<a name="l00141"></a>00141         <span class="keywordflow">for</span> (i=1;i<=ndata;i++) {
+<a name="l00142"></a>00142                 (*funcs)(x[i],afunc,ma);
+<a name="l00143"></a>00143                 <span class="keywordflow">for</span> (sum=0.0,j=1;j<=ma;j++) sum += a[j]*afunc[j];
+<a name="l00144"></a>00144                 *chisq += (tmp=(y[i]-sum)/sig[i],tmp*tmp);
+<a name="l00145"></a>00145         }
+<a name="l00146"></a>00146         sinfo_free_vector(afunc,1<span class="comment">/*,ma*/</span>);
+<a name="l00147"></a>00147         sinfo_free_vector(b,1<span class="comment">/*,ndata*/</span>);
+<a name="l00148"></a>00148         sinfo_svd_variance(v,ma,w,cvm);
+<a name="l00149"></a>00149 
+<a name="l00150"></a>00150 }
+<a name="l00151"></a>00151 
+<a name="l00152"></a>00152 <span class="preprocessor">#undef TOL</span>
+<a name="l00153"></a>00153 <span class="preprocessor"></span>
+<a name="l00154"></a>00154 
+<a name="l00155"></a>00155 
+<a name="l00156"></a>00156 <span class="keyword">static</span> <span class="keywordtype">float</span> at,bt,ct;
+<a name="l00157"></a>00157 <span class="preprocessor">#define SINFO_PYTHAG(a,b) ((at=fabs(a)) > (bt=fabs(b)) ? \</span>
+<a name="l00158"></a>00158 <span class="preprocessor">(ct=bt/at,at*sqrt(1.0+ct*ct)) : (bt ? (ct=at/bt,bt*sqrt(1.0+ct*ct)): 0.0))</span>
+<a name="l00159"></a>00159 <span class="preprocessor"></span>
+<a name="l00160"></a>00160 
+<a name="l00161"></a>00161 <span class="keyword">static</span> <span class="keywordtype">float</span> maxarg1,maxarg2;
+<a name="l00162"></a>00162 <span class="preprocessor">#define SINFO_MAX(a,b) (maxarg1=(a),maxarg2=(b),(maxarg1) > (maxarg2) ?\</span>
+<a name="l00163"></a>00163 <span class="preprocessor">        (maxarg1) : (maxarg2))</span>
+<a name="l00164"></a>00164 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_SIGN(a,b) ((b) >= 0.0 ? fabs(a) : -fabs(a))</span>
+<a name="l00165"></a>00165 <span class="preprocessor"></span>
+<a name="l00166"></a>00166 <span class="keywordtype">void</span> sinfo_svd_compare(<span class="keywordtype">float</span> **a,<span class="keywordtype">int</span> m,<span class="keywordtype">int</span> n,<span class="keywordtype">float</span> w[],<span class="keywordtype">float</span> **v)
+<a name="l00167"></a>00167 {
+<a name="l00168"></a>00168         <span class="keywordtype">int</span> flag,i,its,j,jj,k,l=0,nm=0;
+<a name="l00169"></a>00169         <span class="keywordtype">float</span> c,f,h,s,x,y,z;
+<a name="l00170"></a>00170         <span class="keywordtype">float</span> anorm=0.0,g=0.0,scale=0.0;
+<a name="l00171"></a>00171         <span class="keywordtype">float</span> *rv1;
+<a name="l00172"></a>00172 
+<a name="l00173"></a>00173         <span class="keywordflow">if</span> (m < n) {
+<a name="l00174"></a>00174            <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"SVDCMP: You must augment A with extra zero rows"</span>);
+<a name="l00175"></a>00175         }
+<a name="l00176"></a>00176         rv1=sinfo_vector(1,n);
+<a name="l00177"></a>00177         <span class="keywordflow">for</span> (i=1;i<=n;i++) {
+<a name="l00178"></a>00178                 l=i+1;
+<a name="l00179"></a>00179                 rv1[i]=scale*g;
+<a name="l00180"></a>00180                 g=s=scale=0.0;
+<a name="l00181"></a>00181                 <span class="keywordflow">if</span> (i <= m) {
+<a name="l00182"></a>00182                         <span class="keywordflow">for</span> (k=i;k<=m;k++) scale += fabs(a[k][i]);
+<a name="l00183"></a>00183                         <span class="keywordflow">if</span> (scale) {
+<a name="l00184"></a>00184                                 <span class="keywordflow">for</span> (k=i;k<=m;k++) {
+<a name="l00185"></a>00185                                         a[k][i] /= scale;
+<a name="l00186"></a>00186                                         s += a[k][i]*a[k][i];
+<a name="l00187"></a>00187                                 }
+<a name="l00188"></a>00188                                 f=a[i][i];
+<a name="l00189"></a>00189 
+<a name="l00190"></a>00190                                 g = -SINFO_SIGN(sqrt(s),f);
+<a name="l00191"></a>00191                                 h=f*g-s;
+<a name="l00192"></a>00192                                 a[i][i]=f-g;
+<a name="l00193"></a>00193                                 <span class="keywordflow">if</span> (i != n) {
+<a name="l00194"></a>00194                                         <span class="keywordflow">for</span> (j=l;j<=n;j++) {
+<a name="l00195"></a>00195                                                 <span class="keywordflow">for</span> (s=0.0,k=i;k<=m;k++) {
+<a name="l00196"></a>00196                                                   s += a[k][i]*a[k][j];
+<a name="l00197"></a>00197                                                 }
+<a name="l00198"></a>00198                                                 f=s/h;
+<a name="l00199"></a>00199                                                 <span class="keywordflow">for</span> (k=i;k<=m;k++) {
+<a name="l00200"></a>00200                                                   a[k][j] += f*a[k][i];
+<a name="l00201"></a>00201                                                 }
+<a name="l00202"></a>00202                                         }
+<a name="l00203"></a>00203                                 }
+<a name="l00204"></a>00204                                 <span class="keywordflow">for</span> (k=i;k<=m;k++) a[k][i] *= scale;
+<a name="l00205"></a>00205                         }
+<a name="l00206"></a>00206                 }
+<a name="l00207"></a>00207                 w[i]=scale*g;
+<a name="l00208"></a>00208                 g=s=scale=0.0;
+<a name="l00209"></a>00209                 <span class="keywordflow">if</span> (i <= m && i != n) {
+<a name="l00210"></a>00210                         <span class="keywordflow">for</span> (k=l;k<=n;k++) scale += fabs(a[i][k]);
+<a name="l00211"></a>00211                         <span class="keywordflow">if</span> (scale) {
+<a name="l00212"></a>00212                           <span class="keywordflow">for</span> (k=l;k<=n;k++) {
+<a name="l00213"></a>00213                                  a[i][k] /= scale;
+<a name="l00214"></a>00214                                  s += a[i][k]*a[i][k];
+<a name="l00215"></a>00215                           }
+<a name="l00216"></a>00216                           f=a[i][l];
+<a name="l00217"></a>00217 
+<a name="l00218"></a>00218                           g = -SINFO_SIGN(sqrt(s),f);
+<a name="l00219"></a>00219                           h=f*g-s;
+<a name="l00220"></a>00220                           a[i][l]=f-g;
+<a name="l00221"></a>00221                           <span class="keywordflow">for</span> (k=l;k<=n;k++) rv1[k]=a[i][k]/h;
+<a name="l00222"></a>00222                           <span class="keywordflow">if</span> (i != m) {
+<a name="l00223"></a>00223                             <span class="keywordflow">for</span> (j=l;j<=m;j++) {
+<a name="l00224"></a>00224                               <span class="keywordflow">for</span> (s=0.0,k=l;k<=n;k++) s += a[j][k]*a[i][k];
+<a name="l00225"></a>00225                               <span class="keywordflow">for</span> (k=l;k<=n;k++) a[j][k] += s*rv1[k];
+<a name="l00226"></a>00226                             }
+<a name="l00227"></a>00227                           }
+<a name="l00228"></a>00228                           <span class="keywordflow">for</span> (k=l;k<=n;k++) a[i][k] *= scale;
+<a name="l00229"></a>00229                         }
+<a name="l00230"></a>00230                 }
+<a name="l00231"></a>00231                 anorm=SINFO_MAX(anorm,(fabs(w[i])+fabs(rv1[i])));
+<a name="l00232"></a>00232         }
+<a name="l00233"></a>00233 
+<a name="l00234"></a>00234         <span class="keywordflow">for</span> (i=n;i>=1;i--) {
+<a name="l00235"></a>00235                 <span class="keywordflow">if</span> (i < n) {
+<a name="l00236"></a>00236                         <span class="keywordflow">if</span> (g) {
+<a name="l00237"></a>00237                           <span class="keywordflow">for</span> (j=l;j<=n;j++)
+<a name="l00238"></a>00238                               v[j][i]=(a[i][j]/a[i][l])/g;
+<a name="l00239"></a>00239                           <span class="keywordflow">for</span> (j=l;j<=n;j++) {
+<a name="l00240"></a>00240                               <span class="keywordflow">for</span> (s=0.0,k=l;k<=n;k++) s += a[i][k]*v[k][j];
+<a name="l00241"></a>00241                               <span class="keywordflow">for</span> (k=l;k<=n;k++) v[k][j] += s*v[k][i];
+<a name="l00242"></a>00242                           }
+<a name="l00243"></a>00243                         }
+<a name="l00244"></a>00244                         <span class="keywordflow">for</span> (j=l;j<=n;j++) v[i][j]=v[j][i]=0.0;
+<a name="l00245"></a>00245                 }
+<a name="l00246"></a>00246                 v[i][i]=1.0;
+<a name="l00247"></a>00247                 g=rv1[i];
+<a name="l00248"></a>00248                 l=i;
+<a name="l00249"></a>00249         }
+<a name="l00250"></a>00250         <span class="keywordflow">for</span> (i=n;i>=1;i--) {
+<a name="l00251"></a>00251                 l=i+1;
+<a name="l00252"></a>00252                 g=w[i];
+<a name="l00253"></a>00253                 <span class="keywordflow">if</span> (i < n)
+<a name="l00254"></a>00254                         <span class="keywordflow">for</span> (j=l;j<=n;j++) a[i][j]=0.0;
+<a name="l00255"></a>00255                 <span class="keywordflow">if</span> (g) {
+<a name="l00256"></a>00256                         g=1.0/g;
+<a name="l00257"></a>00257                         <span class="keywordflow">if</span> (i != n) {
+<a name="l00258"></a>00258                             <span class="keywordflow">for</span> (j=l;j<=n;j++) {
+<a name="l00259"></a>00259                               <span class="keywordflow">for</span> (s=0.0,k=l;k<=m;k++) s += a[k][i]*a[k][j];
+<a name="l00260"></a>00260                               f=(s/a[i][i])*g;
+<a name="l00261"></a>00261                               <span class="keywordflow">for</span> (k=i;k<=m;k++) a[k][j] += f*a[k][i];
+<a name="l00262"></a>00262                             }
+<a name="l00263"></a>00263                         }
+<a name="l00264"></a>00264                         <span class="keywordflow">for</span> (j=i;j<=m;j++) a[j][i] *= g;
+<a name="l00265"></a>00265                 } <span class="keywordflow">else</span> {
+<a name="l00266"></a>00266                         <span class="keywordflow">for</span> (j=i;j<=m;j++) a[j][i]=0.0;
+<a name="l00267"></a>00267                 }
+<a name="l00268"></a>00268                 ++a[i][i];
+<a name="l00269"></a>00269         }
+<a name="l00270"></a>00270         <span class="keywordflow">for</span> (k=n;k>=1;k--) {
+<a name="l00271"></a>00271                 <span class="keywordflow">for</span> (its=1;its<=30;its++) {
+<a name="l00272"></a>00272                         flag=1;
+<a name="l00273"></a>00273                         <span class="keywordflow">for</span> (l=k;l>=1;l--) {
+<a name="l00274"></a>00274                                 nm=l-1;
+<a name="l00275"></a>00275                                 <span class="keywordflow">if</span> (fabs(rv1[l])+anorm == anorm) {
+<a name="l00276"></a>00276                                         flag=0;
+<a name="l00277"></a>00277                                         <span class="keywordflow">break</span>;
+<a name="l00278"></a>00278                                 }
+<a name="l00279"></a>00279                                 <span class="keywordflow">if</span> (fabs(w[nm])+anorm == anorm) <span class="keywordflow">break</span>;
+<a name="l00280"></a>00280                         }
+<a name="l00281"></a>00281                         <span class="keywordflow">if</span> (flag) {
+<a name="l00282"></a>00282                                 c=0.0;
+<a name="l00283"></a>00283                                 s=1.0;
+<a name="l00284"></a>00284                                 <span class="keywordflow">for</span> (i=l;i<=k;i++) {
+<a name="l00285"></a>00285                                         f=s*rv1[i];
+<a name="l00286"></a>00286                                         <span class="keywordflow">if</span> (fabs(f)+anorm != anorm) {
+<a name="l00287"></a>00287                                                 g=w[i];
+<a name="l00288"></a>00288 
+<a name="l00289"></a>00289                                                 h=SINFO_PYTHAG(f,g);
+<a name="l00290"></a>00290                                                 w[i]=h;
+<a name="l00291"></a>00291                                                 h=1.0/h;
+<a name="l00292"></a>00292                                                 c=g*h;
+<a name="l00293"></a>00293                                                 s=(-f*h);
+<a name="l00294"></a>00294                                                 <span class="keywordflow">for</span> (j=1;j<=m;j++) {
+<a name="l00295"></a>00295                                                         y=a[j][nm];
+<a name="l00296"></a>00296                                                         z=a[j][i];
+<a name="l00297"></a>00297                                                         a[j][nm]=y*c+z*s;
+<a name="l00298"></a>00298                                                         a[j][i]=z*c-y*s;
+<a name="l00299"></a>00299                                                 }
+<a name="l00300"></a>00300                                         }
+<a name="l00301"></a>00301                                 }
+<a name="l00302"></a>00302                         }
+<a name="l00303"></a>00303                         z=w[k];
+<a name="l00304"></a>00304                         <span class="keywordflow">if</span> (l == k) {
+<a name="l00305"></a>00305                                 <span class="keywordflow">if</span> (z < 0.0) {
+<a name="l00306"></a>00306                                         w[k] = -z;
+<a name="l00307"></a>00307                                         <span class="keywordflow">for</span> (j=1;j<=n;j++) v[j][k]=(-v[j][k]);
+<a name="l00308"></a>00308                                 }
+<a name="l00309"></a>00309                                 <span class="keywordflow">break</span>;
+<a name="l00310"></a>00310                         }
+<a name="l00311"></a>00311                         <span class="keywordflow">if</span> (its == 30) {
+<a name="l00312"></a>00312                          <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"No convergence in 30 "</span>
+<a name="l00313"></a>00313                                          <span class="stringliteral">"SVDCMP iterations"</span>);
+<a name="l00314"></a>00314                         }
+<a name="l00315"></a>00315                         x=w[l];
+<a name="l00316"></a>00316                         nm=k-1;
+<a name="l00317"></a>00317                         y=w[nm];
+<a name="l00318"></a>00318                         g=rv1[nm];
+<a name="l00319"></a>00319                         h=rv1[k];
+<a name="l00320"></a>00320                         f=((y-z)*(y+z)+(g-h)*(g+h))/(2.0*h*y);
+<a name="l00321"></a>00321 
+<a name="l00322"></a>00322                         g=SINFO_PYTHAG(f,1.0);
+<a name="l00323"></a>00323                         f=((x-z)*(x+z)+h*((y/(f+SINFO_SIGN(g,f)))-h))/x;
+<a name="l00324"></a>00324                         c=s=1.0;
+<a name="l00325"></a>00325                         <span class="keywordflow">for</span> (j=l;j<=nm;j++) {
+<a name="l00326"></a>00326                                 i=j+1;
+<a name="l00327"></a>00327                                 g=rv1[i];
+<a name="l00328"></a>00328                                 y=w[i];
+<a name="l00329"></a>00329                                 h=s*g;
+<a name="l00330"></a>00330                                 g=c*g;
+<a name="l00331"></a>00331 
+<a name="l00332"></a>00332                                 z=SINFO_PYTHAG(f,h);
+<a name="l00333"></a>00333                                 rv1[j]=z;
+<a name="l00334"></a>00334                                 c=f/z;
+<a name="l00335"></a>00335                                 s=h/z;
+<a name="l00336"></a>00336                                 f=x*c+g*s;
+<a name="l00337"></a>00337                                 g=g*c-x*s;
+<a name="l00338"></a>00338                                 h=y*s;
+<a name="l00339"></a>00339                                 y=y*c;
+<a name="l00340"></a>00340                                 <span class="keywordflow">for</span> (jj=1;jj<=n;jj++) {
+<a name="l00341"></a>00341                                         x=v[jj][j];
+<a name="l00342"></a>00342                                         z=v[jj][i];
+<a name="l00343"></a>00343                                         v[jj][j]=x*c+z*s;
+<a name="l00344"></a>00344                                         v[jj][i]=z*c-x*s;
+<a name="l00345"></a>00345                                 }
+<a name="l00346"></a>00346 
+<a name="l00347"></a>00347                                 z=SINFO_PYTHAG(f,h);
+<a name="l00348"></a>00348                                 w[j]=z;
+<a name="l00349"></a>00349                                 <span class="keywordflow">if</span> (z) {
+<a name="l00350"></a>00350                                         z=1.0/z;
+<a name="l00351"></a>00351                                         c=f*z;
+<a name="l00352"></a>00352                                         s=h*z;
+<a name="l00353"></a>00353                                 }
+<a name="l00354"></a>00354                                 f=(c*g)+(s*y);
+<a name="l00355"></a>00355                                 x=(c*y)-(s*g);
+<a name="l00356"></a>00356                                 <span class="keywordflow">for</span> (jj=1;jj<=m;jj++) {
+<a name="l00357"></a>00357                                         y=a[jj][j];
+<a name="l00358"></a>00358                                         z=a[jj][i];
+<a name="l00359"></a>00359                                         a[jj][j]=y*c+z*s;
+<a name="l00360"></a>00360                                         a[jj][i]=z*c-y*s;
+<a name="l00361"></a>00361                                 }
+<a name="l00362"></a>00362                         }
+<a name="l00363"></a>00363                         rv1[l]=0.0;
+<a name="l00364"></a>00364                         rv1[k]=f;
+<a name="l00365"></a>00365                         w[k]=x;
+<a name="l00366"></a>00366                 }
+<a name="l00367"></a>00367         }
+<a name="l00368"></a>00368         sinfo_free_vector(rv1,1<span class="comment">/*,n*/</span>);
+<a name="l00369"></a>00369 }
+<a name="l00370"></a>00370 
+<a name="l00371"></a>00371 <span class="preprocessor">#undef SINFO_SIGN</span>
+<a name="l00372"></a>00372 <span class="preprocessor"></span><span class="preprocessor">#undef SINFO_MAX</span>
+<a name="l00373"></a>00373 <span class="preprocessor"></span><span class="preprocessor">#undef SINFO_PYTHAG</span>
+<a name="l00374"></a>00374 <span class="preprocessor"></span>
+<a name="l00375"></a>00375 <span class="preprocessor">#define NR_END 1</span>
+<a name="l00376"></a>00376 <span class="preprocessor"></span><span class="preprocessor">#define FREE_ARG char*</span>
+<a name="l00377"></a>00377 <span class="preprocessor"></span>
+<a name="l00378"></a>00378 <span class="keywordtype">void</span> sinfo_nerror(<span class="keyword">const</span> <span class="keywordtype">char</span> error_text[])
+<a name="l00379"></a>00379 {
+<a name="l00380"></a>00380         fprintf(stderr,<span class="stringliteral">"Runtime ERROR ...\n"</span>);
+<a name="l00381"></a>00381         fprintf(stderr,<span class="stringliteral">"%s\n"</span>,error_text);
+<a name="l00382"></a>00382         fprintf(stderr,<span class="stringliteral">"exiting system \n"</span>);
+<a name="l00383"></a>00383     <span class="keywordflow">return</span>;
+<a name="l00384"></a>00384 }
+<a name="l00385"></a>00385 
+<a name="l00386"></a>00386 <span class="keywordtype">float</span> *sinfo_vector(<span class="keywordtype">long</span> nl, <span class="keywordtype">long</span> nh)
+<a name="l00387"></a>00387 {
+<a name="l00388"></a>00388         <span class="keywordtype">float</span> *v;
+<a name="l00389"></a>00389 
+<a name="l00390"></a>00390         v=(<span class="keywordtype">float</span> *)cpl_malloc((<span class="keywordtype">size_t</span>) ((nh-nl+1+NR_END)*<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)));
+<a name="l00391"></a>00391         <span class="keywordflow">if</span> (!v) {
+<a name="l00392"></a>00392            <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"allocation failure in sinfo_vector()"</span>);
+<a name="l00393"></a>00393         }
+<a name="l00394"></a>00394         <span class="keywordflow">return</span> v-nl+NR_END;
+<a name="l00395"></a>00395 
+<a name="l00396"></a>00396 }
+<a name="l00397"></a>00397 
+<a name="l00398"></a>00398 <span class="keywordtype">void</span> sinfo_free_vector(<span class="keywordtype">float</span> *v, <span class="keywordtype">long</span> nl<span class="comment">/* , long nh*/</span>)
+<a name="l00399"></a>00399 
+<a name="l00400"></a>00400 {
+<a name="l00401"></a>00401         cpl_free((FREE_ARG) (v+nl-NR_END));
+<a name="l00402"></a>00402 }
+<a name="l00403"></a>00403 
+<a name="l00404"></a>00404 <span class="keywordtype">float</span> **sinfo_matrix(<span class="keywordtype">long</span> nrl, <span class="keywordtype">long</span> nrh, <span class="keywordtype">long</span> ncl, <span class="keywordtype">long</span> nch)
+<a name="l00405"></a>00405 {
+<a name="l00406"></a>00406         <span class="keywordtype">long</span> i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
+<a name="l00407"></a>00407         <span class="keywordtype">float</span> **m;
+<a name="l00408"></a>00408 
+<a name="l00409"></a>00409         m=(<span class="keywordtype">float</span> **) cpl_malloc((<span class="keywordtype">size_t</span>)((nrow+NR_END)*<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>*)));
+<a name="l00410"></a>00410         <span class="keywordflow">if</span> (!m) {
+<a name="l00411"></a>00411           <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"aloccation failure 1 in sinfo_matrix()"</span>);
+<a name="l00412"></a>00412         }
+<a name="l00413"></a>00413         m += NR_END;
+<a name="l00414"></a>00414         m -= nrl;
+<a name="l00415"></a>00415 
+<a name="l00416"></a>00416         m[nrl]=(<span class="keywordtype">float</span> *)cpl_malloc((<span class="keywordtype">size_t</span>)((nrow*ncol+NR_END)*<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)));
+<a name="l00417"></a>00417         <span class="keywordflow">if</span> (!m[nrl]) {
+<a name="l00418"></a>00418            <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"allocation failure 2 in sinfo_matrix()"</span>);
+<a name="l00419"></a>00419         }
+<a name="l00420"></a>00420         m[nrl] += NR_END;
+<a name="l00421"></a>00421         m[nrl] -= ncl;
+<a name="l00422"></a>00422 
+<a name="l00423"></a>00423         <span class="keywordflow">for</span>(i=nrl+1;i<=nrh;i++) m[i] = m[i-1]+ncol;
+<a name="l00424"></a>00424         <span class="keywordflow">return</span> m;
+<a name="l00425"></a>00425 }
+<a name="l00426"></a>00426 
+<a name="l00427"></a>00427 <span class="keywordtype">void</span> sinfo_free_matrix(<span class="keywordtype">float</span> **m,<span class="keywordtype">long</span> nrl<span class="comment">/*, long nrh*/</span>, <span class="keywordtype">long</span> ncl<span class="comment">/*, long nch*/</span>)
+<a name="l00428"></a>00428 {
+<a name="l00429"></a>00429         cpl_free((FREE_ARG)(m[nrl]+ncl-NR_END));
+<a name="l00430"></a>00430         cpl_free((FREE_ARG)(m+nrl-NR_END));
+<a name="l00431"></a>00431 }
+<a name="l00432"></a>00432 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__svd_8h_source.html b/html/sinfo__svd_8h_source.html
new file mode 100644
index 0000000..6baa86c
--- /dev/null
+++ b/html/sinfo__svd_8h_source.html
@@ -0,0 +1,100 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_svd.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_svd.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#ifndef SINFO_SVD_H</span>
+<a name="l00002"></a>00002 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_SVD_H</span>
+<a name="l00003"></a>00003 <span class="preprocessor"></span><span class="comment">/*</span>
+<a name="l00004"></a>00004 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00005"></a>00005 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00006"></a>00006 <span class="comment"> *</span>
+<a name="l00007"></a>00007 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00008"></a>00008 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00009"></a>00009 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00010"></a>00010 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00011"></a>00011 <span class="comment"> *</span>
+<a name="l00012"></a>00012 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00013"></a>00013 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00014"></a>00014 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00015"></a>00015 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00016"></a>00016 <span class="comment"> *</span>
+<a name="l00017"></a>00017 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00018"></a>00018 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00019"></a>00019 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00020"></a>00020 <span class="comment"> */</span>
+<a name="l00021"></a>00021 <span class="comment">/*******************************************************************************</span>
+<a name="l00022"></a>00022 <span class="comment">* E.S.O. - VLT project</span>
+<a name="l00023"></a>00023 <span class="comment">*</span>
+<a name="l00024"></a>00024 <span class="comment">* "@(#) $Id: sinfo_svd.h,v 1.4 2007/06/06 07:10:45 amodigli Exp $"</span>
+<a name="l00025"></a>00025 <span class="comment">*</span>
+<a name="l00026"></a>00026 <span class="comment">* who       when      what</span>
+<a name="l00027"></a>00027 <span class="comment">* --------  --------  ----------------------------------------------</span>
+<a name="l00028"></a>00028 <span class="comment">* schreib  16/04/03  created</span>
+<a name="l00029"></a>00029 <span class="comment">*/</span>
+<a name="l00030"></a>00030 
+<a name="l00031"></a>00031 <span class="comment">/************************************************************************</span>
+<a name="l00032"></a>00032 <span class="comment"> * sinfo_svd.h</span>
+<a name="l00033"></a>00033 <span class="comment"> * singular value decomposition fit routines</span>
+<a name="l00034"></a>00034 <span class="comment"> *----------------------------------------------------------------------</span>
+<a name="l00035"></a>00035 <span class="comment"> */</span>
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="comment">/*</span>
+<a name="l00038"></a>00038 <span class="comment"> * header files</span>
+<a name="l00039"></a>00039 <span class="comment"> */</span>
+<a name="l00040"></a>00040 
+<a name="l00041"></a>00041 <span class="preprocessor">#include <math.h></span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00043"></a>00043 
+<a name="l00044"></a>00044 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00045"></a>00045 <span class="comment"> *                        Function ANSI C prototypes</span>
+<a name="l00046"></a>00046 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00047"></a>00047 
+<a name="l00048"></a>00048 <span class="keywordtype">void</span> sinfo_fpol(<span class="keywordtype">float</span> x, <span class="keywordtype">float</span> *p, <span class="keywordtype">int</span> np) ;
+<a name="l00049"></a>00049 
+<a name="l00050"></a>00050 <span class="keywordtype">void</span> 
+<a name="l00051"></a>00051 sinfo_svb_kas(<span class="keywordtype">float</span> **u, <span class="keywordtype">float</span> w[], <span class="keywordtype">float</span> **v, <span class="keywordtype">int</span> m, 
+<a name="l00052"></a>00052               <span class="keywordtype">int</span> n, <span class="keywordtype">float</span> b[],<span class="keywordtype">float</span> x[]) ;
+<a name="l00053"></a>00053 
+<a name="l00054"></a>00054 <span class="keywordtype">void</span> sinfo_svd_variance(<span class="keywordtype">float</span> **v , <span class="keywordtype">int</span> ma , <span class="keywordtype">float</span> w[] , <span class="keywordtype">float</span> **cvm) ;
+<a name="l00055"></a>00055 
+<a name="l00056"></a>00056 <span class="keywordtype">void</span> sinfo_svd_fitting ( <span class="keywordtype">float</span> *x,
+<a name="l00057"></a>00057                    <span class="keywordtype">float</span> *y,
+<a name="l00058"></a>00058                    <span class="keywordtype">float</span> *sig,
+<a name="l00059"></a>00059                    <span class="keywordtype">int</span>   ndata,
+<a name="l00060"></a>00060                    <span class="keywordtype">float</span> *a,
+<a name="l00061"></a>00061                    <span class="keywordtype">int</span>   ma,
+<a name="l00062"></a>00062                    <span class="keywordtype">float</span> **u,
+<a name="l00063"></a>00063                    <span class="keywordtype">float</span> **v,
+<a name="l00064"></a>00064                    <span class="keywordtype">float</span> *w,
+<a name="l00065"></a>00065                    <span class="keywordtype">float</span> **cvm,
+<a name="l00066"></a>00066                    <span class="keywordtype">float</span> *chisq,
+<a name="l00067"></a>00067                    <span class="keywordtype">void</span> (*funcs)(<span class="keywordtype">float</span>,<span class="keywordtype">float</span> *,<span class="keywordtype">int</span>) ) ;
+<a name="l00068"></a>00068 
+<a name="l00069"></a>00069 <span class="keywordtype">void</span> sinfo_svd_compare(<span class="keywordtype">float</span> **a,<span class="keywordtype">int</span> m,<span class="keywordtype">int</span> n,<span class="keywordtype">float</span> w[],<span class="keywordtype">float</span> **v) ;
+<a name="l00070"></a>00070 
+<a name="l00071"></a>00071 <span class="keywordtype">void</span> sinfo_nerror(<span class="keyword">const</span> <span class="keywordtype">char</span> error_text[]) ;
+<a name="l00072"></a>00072 
+<a name="l00073"></a>00073 <span class="keywordtype">float</span> *sinfo_vector(<span class="keywordtype">long</span> nl, <span class="keywordtype">long</span> nh) ;
+<a name="l00074"></a>00074 
+<a name="l00075"></a>00075 <span class="keywordtype">void</span> sinfo_free_vector(<span class="keywordtype">float</span> *v, <span class="keywordtype">long</span> nl <span class="comment">/*, long nh*/</span>) ;
+<a name="l00076"></a>00076 
+<a name="l00077"></a>00077 <span class="keywordtype">float</span> **sinfo_matrix(<span class="keywordtype">long</span> nrl, <span class="keywordtype">long</span> nrh, <span class="keywordtype">long</span> ncl, <span class="keywordtype">long</span> nch) ;
+<a name="l00078"></a>00078 
+<a name="l00079"></a>00079 <span class="keywordtype">void</span> 
+<a name="l00080"></a>00080 sinfo_free_matrix(<span class="keywordtype">float</span> **m,<span class="keywordtype">long</span> nrl<span class="comment">/*, long nrh*/</span>, <span class="keywordtype">long</span> ncl<span class="comment">/*, long nch*/</span>) ;
+<a name="l00081"></a>00081 
+<a name="l00082"></a>00082 
+<a name="l00083"></a>00083 <span class="preprocessor">#endif </span>
+<a name="l00085"></a>00085 <span class="preprocessor"></span><span class="comment">/*--------------------------------------------------------------------------*/</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__tilt__cfg_8c_source.html b/html/sinfo__tilt__cfg_8c_source.html
new file mode 100644
index 0000000..80f2a4a
--- /dev/null
+++ b/html/sinfo__tilt__cfg_8c_source.html
@@ -0,0 +1,91 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_tilt_cfg.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_tilt_cfg.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 
+<a name="l00020"></a>00020 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00021"></a>00021 <span class="comment">   </span>
+<a name="l00022"></a>00022 <span class="comment">   File name     :    tilt_cfg.c</span>
+<a name="l00023"></a>00023 <span class="comment">   Autor    :       Juergen Schreiber</span>
+<a name="l00024"></a>00024 <span class="comment">   Created on    :    October 2001</span>
+<a name="l00025"></a>00025 <span class="comment">   Description    :    handles the data structure tilt_config</span>
+<a name="l00026"></a>00026 <span class="comment"></span>
+<a name="l00027"></a>00027 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span>
+<a name="l00032"></a>00032 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                                   Includes</span>
+<a name="l00034"></a>00034 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 
+<a name="l00036"></a>00036 <span class="preprocessor">#include "sinfo_tilt_cfg.h"</span>
+<a name="l00044"></a>00044 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00045"></a>00045 <span class="comment">                              Function codes</span>
+<a name="l00046"></a>00046 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00047"></a>00047 
+<a name="l00048"></a>00048 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00049"></a>00049 <span class="comment">   Function :   sinfo_tilt_cfg_create()</span>
+<a name="l00050"></a>00050 <span class="comment">   In       :   void</span>
+<a name="l00051"></a>00051 <span class="comment">   Out      :   pointer to allocated base tilt_config structure</span>
+<a name="l00052"></a>00052 <span class="comment">   Job      :   allocate memory for a tilt_config struct</span>
+<a name="l00053"></a>00053 <span class="comment">   Notice   :   only the main (base) structure is allocated</span>
+<a name="l00054"></a>00054 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00055"></a>00055 
+<a name="l00056"></a>00056 tilt_config * sinfo_tilt_cfg_create(<span class="keywordtype">void</span>)
+<a name="l00057"></a>00057 {
+<a name="l00058"></a>00058     <span class="keywordflow">return</span> cpl_calloc(1, <span class="keyword">sizeof</span>(tilt_config));
+<a name="l00059"></a>00059 }
+<a name="l00060"></a>00060 
+<a name="l00061"></a>00061 
+<a name="l00062"></a>00062 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00063"></a>00063 <span class="comment">   Function :   sinfo_tilt_cfg_destroy()</span>
+<a name="l00064"></a>00064 <span class="comment">   In       :   tilt_config to deallocate</span>
+<a name="l00065"></a>00065 <span class="comment">   Out      :   void</span>
+<a name="l00066"></a>00066 <span class="comment">   Job      :   deallocate all memory associated with a </span>
+<a name="l00067"></a>00067 <span class="comment">                tilt_config data structure</span>
+<a name="l00068"></a>00068 <span class="comment">   Notice   :   </span>
+<a name="l00069"></a>00069 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00070"></a>00070 
+<a name="l00071"></a>00071 <span class="keywordtype">void</span> sinfo_tilt_cfg_destroy(tilt_config * sc)
+<a name="l00072"></a>00072 {
+<a name="l00073"></a>00073     <span class="keywordflow">if</span> (sc==NULL) return ;
+<a name="l00074"></a>00074    <span class="comment">/* cpl_free(sc->frametype);*/</span>
+<a name="l00075"></a>00075     
+<a name="l00076"></a>00076     <span class="comment">/* Free main struct */</span>
+<a name="l00077"></a>00077     cpl_free(sc);
+<a name="l00078"></a>00078 
+<a name="l00079"></a>00079     return ;
+<a name="l00080"></a>00080 }
+<a name="l00081"></a>00081 
+<a name="l00082"></a>00082 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__tilt__cfg_8h_source.html b/html/sinfo__tilt__cfg_8h_source.html
new file mode 100644
index 0000000..72c3fe0
--- /dev/null
+++ b/html/sinfo__tilt__cfg_8h_source.html
@@ -0,0 +1,105 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_tilt_cfg.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_tilt_cfg.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   File name     :    sinfo_tilt_cfg.h</span>
+<a name="l00021"></a>00021 <span class="comment">   Author         :    Juergen Schreiber</span>
+<a name="l00022"></a>00022 <span class="comment">   Created on    :    October 2001</span>
+<a name="l00023"></a>00023 <span class="comment">   Description    :    tilt_ini definitions + handling prototypes</span>
+<a name="l00024"></a>00024 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00025"></a>00025 <span class="preprocessor">#ifndef SINFO_TILT_CFG_H</span>
+<a name="l00026"></a>00026 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_TILT_CFG_H</span>
+<a name="l00027"></a>00027 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00028"></a>00028 <span class="comment">                                   Includes</span>
+<a name="l00029"></a>00029 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00030"></a>00030 <span class="preprocessor">#include <stdlib.h></span>
+<a name="l00031"></a>00031 <span class="preprocessor">#include "sinfo_globals.h"</span>
+<a name="l00032"></a>00032 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00033"></a>00033 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00034"></a>00034 <span class="comment">                                   Defines</span>
+<a name="l00035"></a>00035 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00036"></a>00036 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00037"></a>00037 <span class="comment">                                   New types</span>
+<a name="l00038"></a>00038 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00039"></a>00039 <span class="comment">/*</span>
+<a name="l00040"></a>00040 <span class="comment">  determination of spectral tilt blackboard container</span>
+<a name="l00041"></a>00041 <span class="comment"></span>
+<a name="l00042"></a>00042 <span class="comment">  This structure holds all information related to the determination </span>
+<a name="l00043"></a>00043 <span class="comment">  of the spectral tilt routine. It is used as a container for the flux </span>
+<a name="l00044"></a>00044 <span class="comment">  of ancillary data, computed values, and algorithm status. Pixel flux </span>
+<a name="l00045"></a>00045 <span class="comment">  is separated from the blackboard.</span>
+<a name="l00046"></a>00046 <span class="comment">  */</span>
+<a name="l00047"></a>00047 
+<a name="l00048"></a>00048 <span class="keyword">typedef</span> <span class="keyword">struct </span>tilt_config {
+<a name="l00049"></a>00049 <span class="comment">/*-------General---------*/</span>
+<a name="l00050"></a>00050         <span class="keywordtype">char</span> inFile[FILE_NAME_SZ] ;    <span class="comment">/* file name of the file containing </span>
+<a name="l00051"></a>00051 <span class="comment">                                          the list of all input frames */</span>
+<a name="l00052"></a>00052         <span class="keywordtype">char</span> outName[FILE_NAME_SZ] ;   <span class="comment">/* output name of resulting fits </span>
+<a name="l00053"></a>00053 <span class="comment">                                          wavelength map */</span>
+<a name="l00054"></a>00054         <span class="keywordtype">char</span> ** framelist ; <span class="comment">/* list of frames */</span>
+<a name="l00055"></a>00055         <span class="keywordtype">int</span>  *  frametype ; <span class="comment">/* list of frame types on or off */</span>
+<a name="l00056"></a>00056         <span class="keywordtype">int</span>     nframes ;   <span class="comment">/* number of frames in frame list */</span>
+<a name="l00057"></a>00057         <span class="keywordtype">int</span>     nobj ;      <span class="comment">/* number of object frames in frame list */</span>
+<a name="l00058"></a>00058         <span class="keywordtype">int</span>     noff ;      <span class="comment">/* number of off frames in frame list */</span>
+<a name="l00059"></a>00059 
+<a name="l00060"></a>00060 <span class="comment">/*------ CleanMean ------*/</span>
+<a name="l00061"></a>00061         <span class="comment">/* percentage of rejected low intensity pixels */</span>
+<a name="l00062"></a>00062         <span class="keywordtype">float</span> loReject ;
+<a name="l00063"></a>00063         <span class="comment">/* percentage of rejected high intensity pixels */</span>
+<a name="l00064"></a>00064         <span class="keywordtype">float</span> hiReject ;
+<a name="l00065"></a>00065         <span class="comment">/* file name of the bad pixel mask fits file */</span>
+<a name="l00066"></a>00066         <span class="keywordtype">char</span> mask[FILE_NAME_SZ] ;
+<a name="l00067"></a>00067 
+<a name="l00068"></a>00068 <span class="comment">/*------ Slope ------*/</span>
+<a name="l00069"></a>00069         <span class="comment">/* width of a box along the slitlets within which the spectrum </span>
+<a name="l00070"></a>00070 <span class="comment">           is fitted by a Gaussian */</span>
+<a name="l00071"></a>00071         <span class="keywordtype">int</span> box_length ;
+<a name="l00072"></a>00072         <span class="comment">/* initial guess of the FWHM */</span>
+<a name="l00073"></a>00073         <span class="keywordtype">float</span> fwhm ;
+<a name="l00074"></a>00074         <span class="comment">/* amplitude below which the fit is not carried through */</span>
+<a name="l00075"></a>00075         <span class="keywordtype">float</span> minDiff ;
+<a name="l00076"></a>00076 
+<a name="l00077"></a>00077 } tilt_config ;
+<a name="l00078"></a>00078 
+<a name="l00079"></a>00079 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00080"></a>00080 <span class="comment">                               Function prototypes</span>
+<a name="l00081"></a>00081 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00089"></a>00089 tilt_config * 
+<a name="l00090"></a>00090 sinfo_tilt_cfg_create(<span class="keywordtype">void</span>);
+<a name="l00091"></a>00091 
+<a name="l00092"></a>00092 
+<a name="l00100"></a>00100 <span class="keywordtype">void</span> 
+<a name="l00101"></a>00101 sinfo_tilt_cfg_destroy(tilt_config * sc);
+<a name="l00102"></a>00102 
+<a name="l00103"></a>00103 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__tilt__ini_8h_source.html b/html/sinfo__tilt__ini_8h_source.html
new file mode 100644
index 0000000..6e40120
--- /dev/null
+++ b/html/sinfo__tilt__ini_8h_source.html
@@ -0,0 +1,68 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_tilt_ini.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_tilt_ini.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name    :   sinfo_tilt_ini.h</span>
+<a name="l00022"></a>00022 <span class="comment">   Author       :    Juergen Schreiber</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on   :    Oct 25, 2001</span>
+<a name="l00024"></a>00024 <span class="comment">   Description  :    prepare handling of .ini file for the determination</span>
+<a name="l00025"></a>00025 <span class="comment">                        of the spectral tilt</span>
+<a name="l00026"></a>00026 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00027"></a>00027 <span class="preprocessor">#ifndef SINFO_TILT_INI_H</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_TILT_INI_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00030"></a>00030 <span class="comment">                                Includes</span>
+<a name="l00031"></a>00031 <span class="comment">---------------------------------------------------------------------------*/</span>
+<a name="l00032"></a>00032 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include "sinfo_tilt_cfg.h"</span>
+<a name="l00034"></a>00034 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00035"></a>00035 <span class="comment">                                Defines</span>
+<a name="l00036"></a>00036 <span class="comment">---------------------------------------------------------------------------*/</span>
+<a name="l00037"></a>00037 <span class="preprocessor">#define FRAME_ON   1     </span><span class="comment">/* object frames */</span>
+<a name="l00038"></a>00038 <span class="preprocessor">#define FRAME_OFF  0     </span><span class="comment">/* off frames */</span>
+<a name="l00039"></a>00039 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00040"></a>00040 <span class="comment">                             Function prototypes </span>
+<a name="l00041"></a>00041 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00057"></a>00057 <span class="keywordtype">int</span> 
+<a name="l00058"></a>00058 generateTilt_ini_file(
+<a name="l00059"></a>00059         <span class="keywordtype">char</span> * ini_name,
+<a name="l00060"></a>00060         <span class="keywordtype">char</span> * name_i,
+<a name="l00061"></a>00061         <span class="keywordtype">char</span> * name_o
+<a name="l00062"></a>00062 );
+<a name="l00063"></a>00063 
+<a name="l00075"></a>00075 tilt_config * 
+<a name="l00076"></a>00076 parse_tilt_ini_file(<span class="keywordtype">char</span> * ini_name) ;
+<a name="l00077"></a>00077 
+<a name="l00078"></a>00078 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__time_8c_source.html b/html/sinfo__time_8c_source.html
new file mode 100644
index 0000000..5375d1e
--- /dev/null
+++ b/html/sinfo__time_8c_source.html
@@ -0,0 +1,201 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_time.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_time.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_time.c,v 1.5 2012/03/03 10:17:31 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the ESO QFITS Library</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2001-2004 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2012/03/03 10:17:31 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.5 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00029"></a>00029 <span class="preprocessor">#endif</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span><span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00031"></a>00031 <span class="comment">                                   Includes</span>
+<a name="l00032"></a>00032 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00033"></a>00033 
+<a name="l00034"></a>00034 <span class="preprocessor">#include <stdio.h></span>
+<a name="l00035"></a>00035 <span class="preprocessor">#include <stdlib.h></span>
+<a name="l00036"></a>00036 <span class="preprocessor">#include <string.h></span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include <time.h></span>
+<a name="l00038"></a>00038 <span class="preprocessor">#include <pwd.h></span>
+<a name="l00039"></a>00039 <span class="preprocessor">#include <unistd.h></span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include <sys/time.h></span>
+<a name="l00041"></a>00041 
+<a name="l00042"></a>00042 <span class="preprocessor">#include "sinfo_time.h"</span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include "sinfo_globals.h"</span>
+<a name="l00044"></a>00044 
+<a name="l00045"></a>00045 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00046"></a>00046 <span class="comment">                                   Macros</span>
+<a name="l00047"></a>00047 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00048"></a>00048 
+<a name="l00049"></a>00049 <span class="comment">/* Get century from a date in long format */</span>
+<a name="l00050"></a>00050 <span class="preprocessor">#define GET_CENTURY(d)      (int) ( (d) / 1000000L)</span>
+<a name="l00051"></a>00051 <span class="preprocessor"></span><span class="comment">/* Get century year from a date in long format */</span>
+<a name="l00052"></a>00052 <span class="preprocessor">#define GET_CCYEAR(d)       (int) ( (d) / 10000L)</span>
+<a name="l00053"></a>00053 <span class="preprocessor"></span><span class="comment">/* Get year from a date in long format */</span>
+<a name="l00054"></a>00054 <span class="preprocessor">#define GET_YEAR(d)         (int) (((d) % 1000000L) / 10000L)</span>
+<a name="l00055"></a>00055 <span class="preprocessor"></span><span class="comment">/* Get month from a date in long format */</span>
+<a name="l00056"></a>00056 <span class="preprocessor">#define GET_MONTH(d)        (int) (((d) % 10000L) / 100)</span>
+<a name="l00057"></a>00057 <span class="preprocessor"></span><span class="comment">/* Get day from a date in long format */</span>
+<a name="l00058"></a>00058 <span class="preprocessor">#define GET_DAY(d)          (int) ( (d) % 100)</span>
+<a name="l00059"></a>00059 <span class="preprocessor"></span>
+<a name="l00060"></a>00060 <span class="comment">/* Get hours from a date in long format */</span>
+<a name="l00061"></a>00061 <span class="preprocessor">#define GET_HOUR(t)         (int) ( (t) / 1000000L)</span>
+<a name="l00062"></a>00062 <span class="preprocessor"></span><span class="comment">/* Get minutes from a date in long format */</span>
+<a name="l00063"></a>00063 <span class="preprocessor">#define GET_MINUTE(t)       (int) (((t) % 1000000L) / 10000L)</span>
+<a name="l00064"></a>00064 <span class="preprocessor"></span><span class="comment">/* Get seconds from a date in long format */</span>
+<a name="l00065"></a>00065 <span class="preprocessor">#define GET_SECOND(t)       (int) (((t) % 10000L) / 100)</span>
+<a name="l00066"></a>00066 <span class="preprocessor"></span><span class="comment">/* Get centi-seconds from a date in long format */</span>
+<a name="l00067"></a>00067 <span class="preprocessor">#define GET_CENTI(t)        (int) ( (t) % 100)</span>
+<a name="l00068"></a>00068 <span class="preprocessor"></span>
+<a name="l00069"></a>00069 <span class="comment">/* Make date in long format from its components */</span>
+<a name="l00070"></a>00070 <span class="preprocessor">#define MAKE_DATE(c,y,m,d)  (long) (c) * 1000000L +                          \</span>
+<a name="l00071"></a>00071 <span class="preprocessor">                            (long) (y) * 10000L +                            \</span>
+<a name="l00072"></a>00072 <span class="preprocessor">                            (long) (m) * 100 + (d)</span>
+<a name="l00073"></a>00073 <span class="preprocessor"></span><span class="comment">/* Make time in long format from its components */</span>
+<a name="l00074"></a>00074 <span class="preprocessor">#define MAKE_TIME(h,m,s,c)  (long) (h) * 1000000L +                          \</span>
+<a name="l00075"></a>00075 <span class="preprocessor">                            (long) (m) * 10000L +                            \</span>
+<a name="l00076"></a>00076 <span class="preprocessor">                            (long) (s) * 100 + (c)</span>
+<a name="l00077"></a>00077 <span class="preprocessor"></span>
+<a name="l00078"></a>00078 <span class="comment">/*  Interval values, specified in centiseconds */</span>
+<a name="l00079"></a>00079 <span class="preprocessor">#define INTERVAL_CENTI      1</span>
+<a name="l00080"></a>00080 <span class="preprocessor"></span><span class="preprocessor">#define INTERVAL_SEC        100</span>
+<a name="l00081"></a>00081 <span class="preprocessor"></span><span class="preprocessor">#define INTERVAL_MIN        6000</span>
+<a name="l00082"></a>00082 <span class="preprocessor"></span><span class="preprocessor">#define INTERVAL_HOUR       360000L</span>
+<a name="l00083"></a>00083 <span class="preprocessor"></span><span class="preprocessor">#define INTERVAL_DAY        8640000L</span>
+<a name="l00084"></a>00084 <span class="preprocessor"></span>
+<a name="l00085"></a>00085 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00086"></a>00086 <span class="comment">                            Private to this module</span>
+<a name="l00087"></a>00087 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00088"></a>00088 
+<a name="l00089"></a>00089 <span class="keyword">static</span> <span class="keywordtype">long</span> timer_to_date(time_t time_secs) ;
+<a name="l00090"></a>00090 <span class="keyword">static</span> <span class="keywordtype">long</span> timer_to_time(time_t time_secs) ;
+<a name="l00091"></a>00091 <span class="keyword">static</span> <span class="keywordtype">long</span> sinfo_time_now(<span class="keywordtype">void</span>) ;
+<a name="l00092"></a>00092 <span class="keyword">static</span> <span class="keywordtype">long</span> sinfo_date_now (<span class="keywordtype">void</span>) ;
+<a name="l00093"></a>00093 
+<a name="l00095"></a>00095 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00102"></a>00102 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00103"></a>00103 
+<a name="l00104"></a>00104 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00105"></a>00105 <span class="comment">                              Function codes</span>
+<a name="l00106"></a>00106 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00107"></a>00107 
+<a name="l00108"></a>00108 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00117"></a>00117 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00118"></a>00118 <span class="keywordtype">char</span> * sinfo_get_datetime_iso8601(<span class="keywordtype">void</span>)
+<a name="l00119"></a>00119 {
+<a name="l00120"></a>00120     <span class="keyword">static</span> <span class="keywordtype">char</span> date_iso8601[MAX_NAME_SIZE] ;
+<a name="l00121"></a>00121     <span class="keywordtype">long</span>        curdate ;
+<a name="l00122"></a>00122     <span class="keywordtype">long</span>        curtime ;
+<a name="l00123"></a>00123 
+<a name="l00124"></a>00124     curdate  = sinfo_date_now() ;
+<a name="l00125"></a>00125     curtime  = sinfo_time_now() ;
+<a name="l00126"></a>00126 
+<a name="l00127"></a>00127     snprintf(date_iso8601, MAX_NAME_SIZE-1,
+<a name="l00128"></a>00128             <span class="stringliteral">"%04d-%02d-%02dT%02d:%02d:%02d"</span>,
+<a name="l00129"></a>00129             GET_CCYEAR(curdate),
+<a name="l00130"></a>00130             GET_MONTH(curdate),
+<a name="l00131"></a>00131             GET_DAY(curdate),
+<a name="l00132"></a>00132             GET_HOUR(curtime),
+<a name="l00133"></a>00133             GET_MINUTE(curtime),
+<a name="l00134"></a>00134             GET_SECOND(curtime));
+<a name="l00135"></a>00135     <span class="keywordflow">return</span> date_iso8601 ;
+<a name="l00136"></a>00136 }
+<a name="l00137"></a>00137 
+<a name="l00140"></a>00140 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00152"></a>00152 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00153"></a>00153 <span class="keyword">static</span> <span class="keywordtype">long</span> sinfo_date_now (<span class="keywordtype">void</span>)
+<a name="l00154"></a>00154 {
+<a name="l00155"></a>00155     <span class="keywordflow">return</span> (timer_to_date (time (NULL)));
+<a name="l00156"></a>00156 }
+<a name="l00157"></a>00157 
+<a name="l00158"></a>00158 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00168"></a>00168 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00169"></a>00169 <span class="keyword">static</span> <span class="keywordtype">long</span> sinfo_time_now(<span class="keywordtype">void</span>)
+<a name="l00170"></a>00170 {
+<a name="l00171"></a>00171     <span class="keyword">struct </span>timeval time_struct;
+<a name="l00172"></a>00172 
+<a name="l00173"></a>00173     gettimeofday (&time_struct, 0);
+<a name="l00174"></a>00174     <span class="keywordflow">return</span> (timer_to_time (time_struct.tv_sec)
+<a name="l00175"></a>00175                          + time_struct.tv_usec / 10000);
+<a name="l00176"></a>00176 }
+<a name="l00177"></a>00177 
+<a name="l00178"></a>00178 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00190"></a>00190 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00191"></a>00191 <span class="keyword">static</span> <span class="keywordtype">long</span> timer_to_date(time_t time_secs)
+<a name="l00192"></a>00192 {
+<a name="l00193"></a>00193     <span class="keyword">struct </span>tm *time_struct;
+<a name="l00194"></a>00194 
+<a name="l00195"></a>00195     <span class="keywordflow">if</span> (time_secs == 0) {
+<a name="l00196"></a>00196         <span class="keywordflow">return</span> 0;
+<a name="l00197"></a>00197     } <span class="keywordflow">else</span> {
+<a name="l00198"></a>00198         <span class="comment">/*  Convert into a long value CCYYMMDD */</span>
+<a name="l00199"></a>00199         time_struct = localtime (&time_secs);
+<a name="l00200"></a>00200         <span class="keywordflow">if</span> (time_struct) {
+<a name="l00201"></a>00201             time_struct-> tm_year += 1900;
+<a name="l00202"></a>00202             <span class="keywordflow">return</span> (MAKE_DATE (    time_struct-> tm_year / 100,
+<a name="l00203"></a>00203                                 time_struct-> tm_year % 100,
+<a name="l00204"></a>00204                                 time_struct-> tm_mon + 1,
+<a name="l00205"></a>00205                                 time_struct-> tm_mday));
+<a name="l00206"></a>00206         } <span class="keywordflow">else</span> {
+<a name="l00207"></a>00207             <span class="keywordflow">return</span> (19700101);
+<a name="l00208"></a>00208         }
+<a name="l00209"></a>00209     }
+<a name="l00210"></a>00210 }
+<a name="l00211"></a>00211 
+<a name="l00212"></a>00212 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00224"></a>00224 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00225"></a>00225 <span class="keyword">static</span> <span class="keywordtype">long</span> timer_to_time(time_t time_secs)
+<a name="l00226"></a>00226 {
+<a name="l00227"></a>00227     <span class="keyword">struct </span>tm *time_struct;
+<a name="l00228"></a>00228 
+<a name="l00229"></a>00229     <span class="keywordflow">if</span> (time_secs == 0) {
+<a name="l00230"></a>00230         <span class="keywordflow">return</span> 0;
+<a name="l00231"></a>00231     } <span class="keywordflow">else</span> {
+<a name="l00232"></a>00232         <span class="comment">/*  Convert into a long value HHMMSS00 */</span>
+<a name="l00233"></a>00233         time_struct = localtime (&time_secs);
+<a name="l00234"></a>00234         <span class="keywordflow">if</span> (time_struct) {
+<a name="l00235"></a>00235             <span class="keywordflow">return</span> (MAKE_TIME (time_struct-> tm_hour,
+<a name="l00236"></a>00236                                time_struct-> tm_min,
+<a name="l00237"></a>00237                                time_struct-> tm_sec,
+<a name="l00238"></a>00238                                0));
+<a name="l00239"></a>00239         } <span class="keywordflow">else</span> {
+<a name="l00240"></a>00240             <span class="keywordflow">return</span> 0;
+<a name="l00241"></a>00241         }
+<a name="l00242"></a>00242     }
+<a name="l00243"></a>00243 }
+<a name="l00244"></a>00244 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__time_8h_source.html b/html/sinfo__time_8h_source.html
new file mode 100644
index 0000000..3d3733e
--- /dev/null
+++ b/html/sinfo__time_8h_source.html
@@ -0,0 +1,53 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_time.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_time.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_time.h,v 1.1 2006/11/11 14:13:03 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the ESO QFITS Library</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2001-2004 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2006/11/11 14:13:03 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.1 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifndef SINFO_TIME_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_TIME_H</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span>
+<a name="l00031"></a>00031 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00032"></a>00032 <span class="comment">                        Function ANSI C prototypes</span>
+<a name="l00033"></a>00033 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00034"></a>00034 
+<a name="l00035"></a>00035 <span class="keywordtype">char</span> * sinfo_get_datetime_iso8601(<span class="keywordtype">void</span>) ;
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__tpl__dfs_8c_source.html b/html/sinfo__tpl__dfs_8c_source.html
new file mode 100644
index 0000000..e6c6977
--- /dev/null
+++ b/html/sinfo__tpl__dfs_8c_source.html
@@ -0,0 +1,242 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_tpl_dfs.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_tpl_dfs.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_tpl_dfs.c,v 1.13 2012/03/03 10:17:31 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the SINFONI Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2012/03/03 10:17:31 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.13 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span>
+<a name="l00032"></a>00032 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                                   Includes</span>
+<a name="l00034"></a>00034 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 
+<a name="l00036"></a>00036 <span class="preprocessor">#include <string.h></span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include <math.h></span>
+<a name="l00038"></a>00038 
+<a name="l00039"></a>00039 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include "sinfo_utilities.h"</span>
+<a name="l00041"></a>00041 
+<a name="l00042"></a>00042 <span class="preprocessor">#include "sinfo_tpl_dfs.h"</span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include "sinfo_pro_types.h"</span>
+<a name="l00044"></a>00044 <span class="preprocessor">#include "sinfo_raw_types.h"</span>
+<a name="l00045"></a>00045 <span class="preprocessor">#include "sinfo_ref_types.h"</span>
+<a name="l00046"></a>00046 <span class="preprocessor">#include "sinfo_error.h"</span>
+<a name="l00047"></a>00047 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00048"></a>00048 
+<a name="l00049"></a>00049 
+<a name="l00051"></a>00051 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00057"></a>00057 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00058"></a>00058 
+<a name="l00059"></a>00059 
+<a name="l00060"></a>00060 
+<a name="l00061"></a>00061 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00071"></a>00071 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00072"></a>00072 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00073"></a>00073 sinfo_dfs_files_dont_exist(cpl_frameset *frameset)
+<a name="l00074"></a>00074 {
+<a name="l00075"></a>00075     <span class="keyword">const</span> <span class="keywordtype">char</span> *func = <span class="stringliteral">"dfs_files_dont_exist"</span>;
+<a name="l00076"></a>00076     cpl_frame  *frame;
+<a name="l00077"></a>00077 
+<a name="l00078"></a>00078 
+<a name="l00079"></a>00079     <span class="keywordflow">if</span> (frameset == NULL) {
+<a name="l00080"></a>00080         cpl_error_set(func, CPL_ERROR_NULL_INPUT);
+<a name="l00081"></a>00081         <span class="keywordflow">return</span> 1;
+<a name="l00082"></a>00082     }
+<a name="l00083"></a>00083 
+<a name="l00084"></a>00084     <span class="keywordflow">if</span> (cpl_frameset_is_empty(frameset)) {
+<a name="l00085"></a>00085         <span class="keywordflow">return</span> 0;
+<a name="l00086"></a>00086     }
+<a name="l00087"></a>00087 
+<a name="l00088"></a>00088     frame = cpl_frameset_get_first(frameset);
+<a name="l00089"></a>00089 
+<a name="l00090"></a>00090     <span class="keywordflow">while</span> (frame) {
+<a name="l00091"></a>00091         <span class="keywordflow">if</span> (access(cpl_frame_get_filename(frame), F_OK)) {
+<a name="l00092"></a>00092             cpl_msg_error(func, <span class="stringliteral">"File %s (%s) was not found"</span>,
+<a name="l00093"></a>00093                           cpl_frame_get_filename(frame),
+<a name="l00094"></a>00094                           cpl_frame_get_tag(frame));
+<a name="l00095"></a>00095             cpl_error_set(func, CPL_ERROR_FILE_NOT_FOUND);
+<a name="l00096"></a>00096         }
+<a name="l00097"></a>00097 
+<a name="l00098"></a>00098         frame = cpl_frameset_get_next(frameset);
+<a name="l00099"></a>00099     }
+<a name="l00100"></a>00100 
+<a name="l00101"></a>00101     <span class="keywordflow">if</span> (cpl_error_get_code())
+<a name="l00102"></a>00102         <span class="keywordflow">return</span> 1;
+<a name="l00103"></a>00103 
+<a name="l00104"></a>00104     <span class="keywordflow">return</span> 0;
+<a name="l00105"></a>00105 }
+<a name="l00106"></a>00106 
+<a name="l00107"></a>00107 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00113"></a>00113 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00114"></a>00114 <span class="keywordtype">int</span> sinfo_dfs_set_groups(cpl_frameset * <span class="keyword">set</span>)
+<a name="l00115"></a>00115 {
+<a name="l00116"></a>00116     cpl_frame   *   cur_frame=NULL ;
+<a name="l00117"></a>00117     <span class="keyword">const</span> <span class="keywordtype">char</span>  *   tag=NULL ;
+<a name="l00118"></a>00118     <span class="keywordtype">int</span>             nframes=0 ;
+<a name="l00119"></a>00119     <span class="keywordtype">int</span>             i=0 ;
+<a name="l00120"></a>00120 
+<a name="l00121"></a>00121     sinfo_skip_if (cpl_error_get_code());
+<a name="l00122"></a>00122 
+<a name="l00123"></a>00123     <span class="comment">/* Check entries */</span>
+<a name="l00124"></a>00124     <span class="keywordflow">if</span> (<span class="keyword">set</span> == NULL) <span class="keywordflow">return</span> -1 ;
+<a name="l00125"></a>00125 
+<a name="l00126"></a>00126     <span class="comment">/* Initialize */</span>
+<a name="l00127"></a>00127     nframes = cpl_frameset_get_size(<span class="keyword">set</span>) ;
+<a name="l00128"></a>00128 
+<a name="l00129"></a>00129     <span class="comment">/* Loop on frames */</span>
+<a name="l00130"></a>00130     <span class="keywordflow">for</span> (i=0 ; i<nframes ; i++) {
+<a name="l00131"></a>00131         cur_frame = cpl_frameset_get_frame(<span class="keyword">set</span>, i) ;
+<a name="l00132"></a>00132         tag = cpl_frame_get_tag(cur_frame) ;
+<a name="l00133"></a>00133         <span class="keywordflow">if</span> (cpl_error_get_code()) <span class="keywordflow">break</span>;
+<a name="l00134"></a>00134         <span class="keywordflow">if</span> (tag == NULL) <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>( <span class="stringliteral">"Frame %d has no tag"</span>, i);
+<a name="l00135"></a>00135         <span class="comment">/* RAW frames */</span>
+<a name="l00136"></a>00136         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!strcmp(tag, RAW_LINEARITY_LAMP) ||
+<a name="l00137"></a>00137              !strcmp(tag, RAW_ON) ||
+<a name="l00138"></a>00138              !strcmp(tag, RAW_OFF) ||
+<a name="l00139"></a>00139              !strcmp(tag, RAW_DARK) ||
+<a name="l00140"></a>00140                  !strcmp(tag, RAW_FIBRE_NS) ||
+<a name="l00141"></a>00141                  !strcmp(tag, RAW_FIBRE_PSF) ||
+<a name="l00142"></a>00142                  !strcmp(tag, RAW_FIBRE_DARK) ||
+<a name="l00143"></a>00143                  !strcmp(tag, RAW_FLAT_NS) ||
+<a name="l00144"></a>00144                  !strcmp(tag, RAW_WAVE_NS) ||
+<a name="l00145"></a>00145                  !strcmp(tag, RAW_FLAT_LAMP) ||
+<a name="l00146"></a>00146                  !strcmp(tag, RAW_WAVE_LAMP) ||
+<a name="l00147"></a>00147                  !strcmp(tag, RAW_PSF_CALIBRATOR) ||
+<a name="l00148"></a>00148              !strcmp(tag, RAW_SKY_PSF_CALIBRATOR) ||
+<a name="l00149"></a>00149              !strcmp(tag, RAW_STD) ||
+<a name="l00150"></a>00150              !strcmp(tag, RAW_SKY) ||
+<a name="l00151"></a>00151                  !strcmp(tag, RAW_SKY_STD) ||
+<a name="l00152"></a>00152              !strcmp(tag, RAW_OBJECT_NODDING) ||
+<a name="l00153"></a>00153              !strcmp(tag, RAW_SKY_NODDING) ||
+<a name="l00154"></a>00154                  !strcmp(tag, RAW_OBJECT_JITTER) ||
+<a name="l00155"></a>00155                  !strcmp(tag, RAW_SKY_JITTER) ||
+<a name="l00156"></a>00156                  !strcmp(tag, RAW_PUPIL_LAMP) ||
+<a name="l00157"></a>00157                  !strcmp(tag, RAW_IMAGE_PRE_OBJECT) ||
+<a name="l00158"></a>00158                  !strcmp(tag, RAW_IMAGE_PRE_SKY) ||
+<a name="l00159"></a>00159                  !strcmp(tag, RAW_OBJECT_SKYSPIDER))
+<a name="l00160"></a>00160             cpl_frame_set_group(cur_frame, CPL_FRAME_GROUP_RAW) ;
+<a name="l00161"></a>00161         <span class="comment">/* CALIB frames */</span>
+<a name="l00162"></a>00162         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!strcmp(tag, PRO_BP_MAP_HP)  ||
+<a name="l00163"></a>00163          !strcmp(tag,SINFO_UTL_STDSTARS_RAW) ||
+<a name="l00164"></a>00164          !strcmp(tag,SINFO_CALIB_STDSTARS) ||
+<a name="l00165"></a>00165          !strcmp(tag,SINFO_CALIB_SED) ||
+<a name="l00166"></a>00166          !strcmp(tag,PRO_BP_MAP_NL) ||
+<a name="l00167"></a>00167          !strcmp(tag,PRO_BP_MAP_NO) ||
+<a name="l00168"></a>00168          !strcmp(tag,PRO_BP_MAP_DI) ||
+<a name="l00169"></a>00169          !strcmp(tag,PRO_BP_MAP_NL) ||
+<a name="l00170"></a>00170          !strcmp(tag,PRO_BP_MAP_NO) ||
+<a name="l00171"></a>00171          !strcmp(tag,PRO_BP_MAP) ||
+<a name="l00172"></a>00172          !strcmp(tag,PRO_ILL_COR) ||
+<a name="l00173"></a>00173          !strcmp(tag,PRO_MASTER_BP_MAP) ||
+<a name="l00174"></a>00174          !strcmp(tag,PRO_MASTER_DARK) ||
+<a name="l00175"></a>00175                  !strcmp(tag,PRO_DISTORTION) ||
+<a name="l00176"></a>00176          !strcmp(tag,PRO_SLITLETS_DISTANCE) ||
+<a name="l00177"></a>00177          !strcmp(tag,PRO_MASTER_FLAT_LAMP) ||
+<a name="l00178"></a>00178          !strcmp(tag,PRO_SLIT_POS) ||
+<a name="l00179"></a>00179          !strcmp(tag,PRO_SLIT_POS_GUESS) ||
+<a name="l00180"></a>00180          !strcmp(tag,PRO_FIRST_COL) ||
+<a name="l00181"></a>00181          !strcmp(tag,PRO_WAVE_MAP ) ||
+<a name="l00182"></a>00182          !strcmp(tag,REF_LINE_ARC ) ||
+<a name="l00183"></a>00183          !strcmp(tag,DRS_SETUP_WAVE ) ||
+<a name="l00184"></a>00184          !strcmp(tag,EXTCOEFF_TABLE ) ||
+<a name="l00185"></a>00185          !strcmp(tag,FLUX_STD_TABLE ) ||
+<a name="l00186"></a>00186          !strcmp(tag,FLUX_STD_CATALOG ) ||
+<a name="l00187"></a>00187          !strcmp(tag,PRO_IMA ) ||
+<a name="l00188"></a>00188          !strcmp(tag,PRO_CUBE ) ||
+<a name="l00189"></a>00189          !strcmp(tag,REF_BP_MAP ) ||
+<a name="l00190"></a>00190          !strcmp(tag,PRO_SKY_DUMMY ) ||
+<a name="l00191"></a>00191          !strcmp(tag,PRO_REF_ATM_REF_CORR) ||
+<a name="l00192"></a>00192          !strcmp(tag,PRO_SPECTRUM))
+<a name="l00193"></a>00193             cpl_frame_set_group(cur_frame, CPL_FRAME_GROUP_CALIB) ;
+<a name="l00194"></a>00194         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!strcmp(tag, PRO_OBS_OBJ)  ||
+<a name="l00195"></a>00195          !strcmp(tag,PRO_MED_OBS_OBJ) ||
+<a name="l00196"></a>00196          !strcmp(tag,PRO_OBS_STD) ||
+<a name="l00197"></a>00197          !strcmp(tag,PRO_MED_OBS_STD) ||
+<a name="l00198"></a>00198          !strcmp(tag,PRO_OBS_PSF) ||
+<a name="l00199"></a>00199          !strcmp(tag,PRO_MED_OBS_PSF) ||
+<a name="l00200"></a>00200          !strcmp(tag,PRO_COADD_OBJ) ||
+<a name="l00201"></a>00201          !strcmp(tag,PRO_COADD_STD) ||
+<a name="l00202"></a>00202          !strcmp(tag,PRO_COADD_PSF) ||
+<a name="l00203"></a>00203          !strcmp(tag,PRO_COADD_PUPIL) ||
+<a name="l00204"></a>00204          !strcmp(tag,PRO_MED_COADD_OBJ) ||
+<a name="l00205"></a>00205          !strcmp(tag,PRO_MED_COADD_STD) ||
+<a name="l00206"></a>00206          !strcmp(tag,PRO_MED_COADD_PSF) ||
+<a name="l00207"></a>00207          !strcmp(tag,PRO_MED_COADD_PUPIL) ||
+<a name="l00208"></a>00208          !strcmp(tag,PRO_MASK_COADD_OBJ) ||
+<a name="l00209"></a>00209          !strcmp(tag,PRO_MASK_COADD_STD) ||
+<a name="l00210"></a>00210          !strcmp(tag,PRO_MASK_COADD_PSF) ||
+<a name="l00211"></a>00211          !strcmp(tag,PRO_MASK_COADD_PUPIL) ||
+<a name="l00212"></a>00212          !strcmp(tag,PRO_PSF_CALIBRATOR_STACKED) ||
+<a name="l00213"></a>00213          !strcmp(tag,PRO_SKY_PSF_CALIBRATOR_STACKED) ||
+<a name="l00214"></a>00214          !strcmp(tag,PRO_AO_PERFORMANCE) ||
+<a name="l00215"></a>00215          !strcmp(tag,PRO_ENC_ENERGY) ||
+<a name="l00216"></a>00216          !strcmp(tag,PRO_PSF) ||
+<a name="l00217"></a>00217          !strcmp(tag,PRO_STD_STAR_SPECTRA) ||
+<a name="l00218"></a>00218          !strcmp(tag,PRO_STD_STAR_SPECTRUM) ||
+<a name="l00219"></a>00219          !strcmp(tag,PRO_MFLAT_CUBE) ||
+<a name="l00220"></a>00220          !strcmp(tag,PRO_MFLAT_AVG) ||
+<a name="l00221"></a>00221          !strcmp(tag,PRO_MFLAT_MED) ||
+<a name="l00222"></a>00222          !strcmp(tag,PRO_STACK_MFLAT_DIST) ||
+<a name="l00223"></a>00223          !strcmp(tag,PRO_WAVE_LAMP_STACKED ) ||
+<a name="l00224"></a>00224          !strcmp(tag,PRO_FIBRE_NS_STACKED_OFF) ||
+<a name="l00225"></a>00225          !strcmp(tag,PRO_FIBRE_NS_STACKED_ON) ||
+<a name="l00226"></a>00226          !strcmp(tag,PRO_FIBRE_NS_STACKED) ||
+<a name="l00227"></a>00227          !strcmp(tag,PRO_SLITLETS_POS_PREDIST) ||
+<a name="l00228"></a>00228          !strcmp(tag,PRO_OBS_SKY) ||
+<a name="l00229"></a>00229          !strcmp(tag,PRO_SKY_MED) ||
+<a name="l00230"></a>00230          !strcmp(tag,PRO_FIBRE_NS_STACKED_DIST))
+<a name="l00231"></a>00231             cpl_frame_set_group(cur_frame, CPL_FRAME_GROUP_PRODUCT) ;
+<a name="l00232"></a>00232         <span class="keywordflow">else</span> <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>( <span class="stringliteral">"Frame %d has unknown tag: %s"</span>, i, tag);
+<a name="l00233"></a>00233     }
+<a name="l00234"></a>00234     ck0_nomsg(sinfo_dfs_files_dont_exist(<span class="keyword">set</span>));
+<a name="l00235"></a>00235     sinfo_skip_if (i != nframes);
+<a name="l00236"></a>00236 
+<a name="l00237"></a>00237     sinfo_end_skip;
+<a name="l00238"></a>00238 
+<a name="l00239"></a>00239     <span class="keywordflow">if</span> (cpl_error_get_code())
+<a name="l00240"></a>00240         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>( <span class="stringliteral">"Could not identify RAW and CALIB frames (in "</span>
+<a name="l00241"></a>00241                       <span class="stringliteral">"frame set of size %d)"</span>, nframes);
+<a name="l00242"></a>00242 
+<a name="l00243"></a>00243 
+<a name="l00244"></a>00244     <span class="keywordflow">return</span> cpl_error_get_code();
+<a name="l00245"></a>00245 }
+<a name="l00246"></a>00246 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__tpl__dfs_8h_source.html b/html/sinfo__tpl__dfs_8h_source.html
new file mode 100644
index 0000000..c498417
--- /dev/null
+++ b/html/sinfo__tpl__dfs_8h_source.html
@@ -0,0 +1,90 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_tpl_dfs.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_tpl_dfs.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_tpl_dfs.h,v 1.3 2008/07/09 09:53:23 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the SINFONI Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2008/07/09 09:53:23 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.3 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifndef SINFO_TPL_DFS_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_TPL_DFS_H</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span>
+<a name="l00031"></a>00031 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00032"></a>00032 <span class="comment">                                   Define</span>
+<a name="l00033"></a>00033 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00034"></a>00034 
+<a name="l00035"></a>00035 <span class="comment">/* Define here the PRO.CATG keywords */</span>
+<a name="l00036"></a>00036 <span class="preprocessor">#define SI_UTL_IMA_ARITH_PROIMA               "PRO_IMA"</span>
+<a name="l00037"></a>00037 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_RAW                           "RAW"</span>
+<a name="l00038"></a>00038 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_CAL                           "CAL"</span>
+<a name="l00039"></a>00039 <span class="preprocessor"></span>
+<a name="l00040"></a>00040 <span class="comment">/* Define here the DO.CATG keywords */</span>
+<a name="l00041"></a>00041 <span class="preprocessor">#define SI_UTL_IMA_ARITH_IMA1                 "IMA1"</span>
+<a name="l00042"></a>00042 <span class="preprocessor"></span><span class="preprocessor">#define SI_UTL_IMA_ARITH_IMA2                 "IMA2"</span>
+<a name="l00043"></a>00043 <span class="preprocessor"></span><span class="preprocessor">#define SI_UTL_CUBE2IMA_CUBE                  "CUBE"</span>
+<a name="l00044"></a>00044 <span class="preprocessor"></span><span class="preprocessor">#define SI_UTL_CUBE2SPECTRUM_CUBE             "CUBE"</span>
+<a name="l00045"></a>00045 <span class="preprocessor"></span><span class="preprocessor">#define SI_UTL_CUBE_ARITH_CUBE                "CUBE"</span>
+<a name="l00046"></a>00046 <span class="preprocessor"></span><span class="preprocessor">#define SI_UTL_CUBE_ARITH_SPECTRUM            "SPECTRUM"</span>
+<a name="l00047"></a>00047 <span class="preprocessor"></span><span class="preprocessor">#define SI_UTL_CUBE2IMA_PROIMA                "PRO_IMA"</span>
+<a name="l00048"></a>00048 <span class="preprocessor"></span><span class="preprocessor">#define SI_UTL_CUBE2SPECTRUM_PROIMA           "PRO_IMA"</span>
+<a name="l00049"></a>00049 <span class="preprocessor"></span><span class="preprocessor">#define SI_UTL_CUBE_ARITH_PROCUBE             "PRO_CUBE_COADD"</span>
+<a name="l00050"></a>00050 <span class="preprocessor"></span><span class="preprocessor">#define SI_UTL_CUBE_COMBINE_PROCUBE           "PRO_CUBE"</span>
+<a name="l00051"></a>00051 <span class="preprocessor"></span><span class="preprocessor">#define SI_UTL_CUBE_COMBINE_PROMASK           "PRO_BP_MAP_CUBE_COADD"</span>
+<a name="l00052"></a>00052 <span class="preprocessor"></span><span class="preprocessor">#define SI_UTL_SPECTRUM_ARITH_PROSPECTRUM     "PRO_SPECTRUM"</span>
+<a name="l00053"></a>00053 <span class="preprocessor"></span><span class="preprocessor">#define SI_UTL_SPECTRUM_ARITH_SPECTRUM        "SPECTRUM"</span>
+<a name="l00054"></a>00054 <span class="preprocessor"></span><span class="preprocessor">#define SI_UTL_SPECTRUM_WAVELENGTH_SHIFT_PROSPECTRUM     "PRO_SPECTRUM"</span>
+<a name="l00055"></a>00055 <span class="preprocessor"></span><span class="preprocessor">#define SI_UTL_SPECTRUM_WAVELENGTH_SHIFT_SPECTRUM        "SPECTRUM"</span>
+<a name="l00056"></a>00056 <span class="preprocessor"></span><span class="preprocessor">#define SI_UTL_SPECTRUM_DIVIDE_BY_BLACKBODY_PROSPECTRUM     "PRO_SPECTRUM"</span>
+<a name="l00057"></a>00057 <span class="preprocessor"></span><span class="preprocessor">#define SI_UTL_SPECTRUM_DIVIDE_BY_BLACKBODY_SPECTRUM        "SPECTRUM"</span>
+<a name="l00058"></a>00058 <span class="preprocessor"></span><span class="preprocessor">#define SI_UTL_GENLOOKUP_CUBE1                "CUBE1"</span>
+<a name="l00059"></a>00059 <span class="preprocessor"></span><span class="preprocessor">#define SI_UTL_GENLOOKUP_CUBE2                "CUBE2"</span>
+<a name="l00060"></a>00060 <span class="preprocessor"></span><span class="preprocessor">#define SI_UTL_GENLOOKUP_PROIMA1              "PRO_IMA1"</span>
+<a name="l00061"></a>00061 <span class="preprocessor"></span><span class="preprocessor">#define SI_UTL_GENLOOKUP_PROIMA2              "PRO_IMA2"</span>
+<a name="l00062"></a>00062 <span class="preprocessor"></span><span class="preprocessor">#define SI_UTL_GENLOOKUP_PROIMA3              "PRO_IMA3"</span>
+<a name="l00063"></a>00063 <span class="preprocessor"></span><span class="preprocessor">#define SI_UTL_GENLOOKUP_PROIMA4              "PRO_IMA4"</span>
+<a name="l00064"></a>00064 <span class="preprocessor"></span><span class="preprocessor">#define SI_SKYMAP_CUBE                        "PRO_CUBE"</span>
+<a name="l00065"></a>00065 <span class="preprocessor"></span><span class="preprocessor">#define SI_SKYMAP_PROIMA                      "PRO_IMA"</span>
+<a name="l00066"></a>00066 <span class="preprocessor"></span>
+<a name="l00067"></a>00067 
+<a name="l00068"></a>00068 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00069"></a>00069 <span class="comment">                                Functions prototypes</span>
+<a name="l00070"></a>00070 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00071"></a>00071 
+<a name="l00072"></a>00072 <span class="keywordtype">int</span> sinfo_dfs_set_groups(cpl_frameset *) ;
+<a name="l00073"></a>00073 
+<a name="l00074"></a>00074 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__tpl__utils_8c_source.html b/html/sinfo__tpl__utils_8c_source.html
new file mode 100644
index 0000000..48686e4
--- /dev/null
+++ b/html/sinfo__tpl__utils_8c_source.html
@@ -0,0 +1,160 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_tpl_utils.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_tpl_utils.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_tpl_utils.c,v 1.3 2012/03/03 10:17:31 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the SINFONI Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2012/03/03 10:17:31 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.3 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span>
+<a name="l00032"></a>00032 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                                                                Includes</span>
+<a name="l00034"></a>00034 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 <span class="preprocessor">#include <string.h></span>
+<a name="l00036"></a>00036 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00037"></a>00037 
+<a name="l00038"></a>00038 <span class="preprocessor">#include "sinfo_tpl_utils.h"</span>
+<a name="l00039"></a>00039 
+<a name="l00041"></a>00041 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00045"></a>00045 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00046"></a>00046 
+<a name="l00047"></a>00047 
+<a name="l00048"></a>00048 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00056"></a>00056 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00057"></a>00057 <span class="keyword">const</span> <span class="keywordtype">char</span> * sinfo_get_license(<span class="keywordtype">void</span>)
+<a name="l00058"></a>00058 {
+<a name="l00059"></a>00059     <span class="keyword">const</span> <span class="keywordtype">char</span> *   sinfoni_license =
+<a name="l00060"></a>00060         <span class="stringliteral">"This file is part of the SINFONI Instrument Pipeline\n"</span>
+<a name="l00061"></a>00061         <span class="stringliteral">"Copyright (C) 2002,2003 European Southern Observatory\n"</span>
+<a name="l00062"></a>00062         <span class="stringliteral">"\n"</span>
+<a name="l00063"></a>00063         <span class="stringliteral">"This program is free software; you can redistribute it and/or modify\n"</span>
+<a name="l00064"></a>00064         <span class="stringliteral">"it under the terms of the GNU General Public License as published by\n"</span>
+<a name="l00065"></a>00065         <span class="stringliteral">"the Free Software Foundation; either version 2 of the License, or\n"</span>
+<a name="l00066"></a>00066         <span class="stringliteral">"(at your option) any later version.\n"</span>
+<a name="l00067"></a>00067         <span class="stringliteral">"\n"</span>
+<a name="l00068"></a>00068         <span class="stringliteral">"This program is distributed in the hope that it will be useful,\n"</span>
+<a name="l00069"></a>00069         <span class="stringliteral">"but WITHOUT ANY WARRANTY; without even the implied warranty of\n"</span>
+<a name="l00070"></a>00070         <span class="stringliteral">"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n"</span>
+<a name="l00071"></a>00071         <span class="stringliteral">"GNU General Public License for more details.\n"</span>
+<a name="l00072"></a>00072         <span class="stringliteral">"\n"</span>
+<a name="l00073"></a>00073         <span class="stringliteral">"You should have received a copy of the GNU General Public License\n"</span>
+<a name="l00074"></a>00074         <span class="stringliteral">"along with this program; if not, write to the Free Software\n"</span>
+<a name="l00075"></a>00075         <span class="stringliteral">"Foundation, Inc., 59 Temple Place, Suite 330, Boston, \n"</span>
+<a name="l00076"></a>00076         <span class="stringliteral">"MA  02111-1307  USA"</span> ;
+<a name="l00077"></a>00077 
+<a name="l00078"></a>00078     <span class="keywordflow">return</span> sinfoni_license ;
+<a name="l00079"></a>00079 }
+<a name="l00080"></a>00080 
+<a name="l00081"></a>00081 
+<a name="l00082"></a>00082 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00091"></a>00091 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00092"></a>00092 cpl_frameset * sinfo_extract_frameset(
+<a name="l00093"></a>00093         <span class="keyword">const</span> cpl_frameset  *   in,
+<a name="l00094"></a>00094         <span class="keyword">const</span> <span class="keywordtype">char</span>          *   tag)
+<a name="l00095"></a>00095 {
+<a name="l00096"></a>00096     cpl_frameset    *   out ;
+<a name="l00097"></a>00097     <span class="keyword">const</span> cpl_frame *   cur_frame ;
+<a name="l00098"></a>00098     cpl_frame       *   loc_frame ;
+<a name="l00099"></a>00099     <span class="keywordtype">int</span>                 nbframes, nbext ;
+<a name="l00100"></a>00100     <span class="keywordtype">int</span>                 i ;
+<a name="l00101"></a>00101 
+<a name="l00102"></a>00102     <span class="comment">/* Test entries */</span>
+<a name="l00103"></a>00103     <span class="keywordflow">if</span> (in == NULL) <span class="keywordflow">return</span> NULL ;
+<a name="l00104"></a>00104     <span class="keywordflow">if</span> (tag == NULL) <span class="keywordflow">return</span> NULL ;
+<a name="l00105"></a>00105 
+<a name="l00106"></a>00106     <span class="comment">/* Initialise */</span>
+<a name="l00107"></a>00107     nbframes = cpl_frameset_get_size(in) ;
+<a name="l00108"></a>00108 
+<a name="l00109"></a>00109     <span class="comment">/* Count the frames with the tag */</span>
+<a name="l00110"></a>00110     <span class="keywordflow">if</span> ((nbext = cpl_frameset_count_tags(in, tag)) == 0) <span class="keywordflow">return</span> NULL ;
+<a name="l00111"></a>00111 
+<a name="l00112"></a>00112     <span class="comment">/* Create the output frameset */</span>
+<a name="l00113"></a>00113     out = cpl_frameset_new() ;
+<a name="l00114"></a>00114 
+<a name="l00115"></a>00115     <span class="comment">/* Loop on the requested frames and store them in out */</span>
+<a name="l00116"></a>00116     nbext = 0 ;
+<a name="l00117"></a>00117     <span class="keywordflow">for</span> (i=0 ; i<nbframes ; i++) {
+<a name="l00118"></a>00118         cur_frame = cpl_frameset_get_frame_const(in, i) ;
+<a name="l00119"></a>00119         <span class="keywordflow">if</span> (!strcmp(cpl_frame_get_tag(cur_frame), tag)) {
+<a name="l00120"></a>00120             loc_frame = cpl_frame_duplicate(cur_frame) ;
+<a name="l00121"></a>00121             cpl_frameset_insert(out, loc_frame) ;
+<a name="l00122"></a>00122             nbext ++ ;
+<a name="l00123"></a>00123         }
+<a name="l00124"></a>00124     }
+<a name="l00125"></a>00125     <span class="keywordflow">return</span> out ;
+<a name="l00126"></a>00126 }
+<a name="l00127"></a>00127 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00134"></a>00134 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00135"></a>00135 <span class="keyword">const</span> <span class="keywordtype">char</span> * sinfo_extract_filename(
+<a name="l00136"></a>00136         <span class="keyword">const</span> cpl_frameset  *   in,
+<a name="l00137"></a>00137         <span class="keyword">const</span> <span class="keywordtype">char</span>          *   tag)
+<a name="l00138"></a>00138 {
+<a name="l00139"></a>00139     <span class="keyword">const</span> cpl_frame *   cur_frame ;
+<a name="l00140"></a>00140 
+<a name="l00141"></a>00141     <span class="comment">/* Get the frame  */</span>
+<a name="l00142"></a>00142     <span class="keywordflow">if</span> ((cur_frame = cpl_frameset_find_const(in, tag)) == NULL) <span class="keywordflow">return</span> NULL ;
+<a name="l00143"></a>00143     <span class="keywordflow">return</span> cpl_frame_get_filename(cur_frame) ;
+<a name="l00144"></a>00144 }
+<a name="l00145"></a>00145 
+<a name="l00146"></a>00146 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l00152"></a>00152 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00153"></a>00153 <span class="keyword">const</span> <span class="keywordtype">char</span> * sinfo_std_band_name(sinfo_band band)
+<a name="l00154"></a>00154 {
+<a name="l00155"></a>00155     <span class="keywordflow">switch</span> (band) {
+<a name="l00156"></a>00156         <span class="keywordflow">case</span> SINFO_BAND_J:        <span class="keywordflow">return</span> <span class="stringliteral">"J"</span> ;
+<a name="l00157"></a>00157         <span class="keywordflow">case</span> SINFO_BAND_JS:       <span class="keywordflow">return</span> <span class="stringliteral">"Js"</span> ;
+<a name="l00158"></a>00158         <span class="keywordflow">case</span> SINFO_BAND_JBLOCK:   <span class="keywordflow">return</span> <span class="stringliteral">"J+Block"</span> ;
+<a name="l00159"></a>00159         <span class="keywordflow">case</span> SINFO_BAND_H:        <span class="keywordflow">return</span> <span class="stringliteral">"H"</span> ;
+<a name="l00160"></a>00160         <span class="keywordflow">case</span> SINFO_BAND_K:        <span class="keywordflow">return</span> <span class="stringliteral">"K"</span> ;
+<a name="l00161"></a>00161         <span class="keywordflow">case</span> SINFO_BAND_KS:       <span class="keywordflow">return</span> <span class="stringliteral">"Ks"</span> ;
+<a name="l00162"></a>00162         <span class="keywordflow">case</span> SINFO_BAND_L:        <span class="keywordflow">return</span> <span class="stringliteral">"L"</span> ;
+<a name="l00163"></a>00163         <span class="keywordflow">case</span> SINFO_BAND_M:        <span class="keywordflow">return</span> <span class="stringliteral">"M"</span> ;
+<a name="l00164"></a>00164         <span class="keywordflow">case</span> SINFO_BAND_LP:       <span class="keywordflow">return</span> <span class="stringliteral">"Lp"</span> ;
+<a name="l00165"></a>00165         <span class="keywordflow">case</span> SINFO_BAND_MP:       <span class="keywordflow">return</span> <span class="stringliteral">"Mp"</span> ;
+<a name="l00166"></a>00166         <span class="keywordflow">case</span> SINFO_BAND_Z:        <span class="keywordflow">return</span> <span class="stringliteral">"Z"</span> ;
+<a name="l00167"></a>00167         <span class="keywordflow">case</span> SINFO_BAND_SZ:       <span class="keywordflow">return</span> <span class="stringliteral">"SZ"</span> ;
+<a name="l00168"></a>00168         <span class="keywordflow">case</span> SINFO_BAND_SH:       <span class="keywordflow">return</span> <span class="stringliteral">"SH"</span> ;
+<a name="l00169"></a>00169         <span class="keywordflow">case</span> SINFO_BAND_SK:       <span class="keywordflow">return</span> <span class="stringliteral">"SK"</span> ;
+<a name="l00170"></a>00170         <span class="keywordflow">case</span> SINFO_BAND_SL:       <span class="keywordflow">return</span> <span class="stringliteral">"SL"</span> ;
+<a name="l00171"></a>00171         <span class="keywordflow">default</span>:            <span class="keywordflow">return</span> <span class="stringliteral">"Unknown"</span> ;
+<a name="l00172"></a>00172     } 
+<a name="l00173"></a>00173 }
+<a name="l00174"></a>00174 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__tpl__utils_8h_source.html b/html/sinfo__tpl__utils_8h_source.html
new file mode 100644
index 0000000..c8bc957
--- /dev/null
+++ b/html/sinfo__tpl__utils_8h_source.html
@@ -0,0 +1,81 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_tpl_utils.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_tpl_utils.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_tpl_utils.h,v 1.2 2007/08/20 10:03:49 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the SINFONI Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2007/08/20 10:03:49 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifndef SINFO_TPL_UTILS_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_TPL_UTILS_H</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span>
+<a name="l00031"></a>00031 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00032"></a>00032 <span class="comment">                                                                Includes</span>
+<a name="l00033"></a>00033 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00034"></a>00034 
+<a name="l00035"></a>00035 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="keyword">typedef</span> <span class="keyword">enum</span> _SINFO_BAND_ {
+<a name="l00038"></a>00038     SINFO_BAND_J,
+<a name="l00039"></a>00039     SINFO_BAND_JS,
+<a name="l00040"></a>00040     SINFO_BAND_JBLOCK,
+<a name="l00041"></a>00041     SINFO_BAND_H,
+<a name="l00042"></a>00042     SINFO_BAND_K,
+<a name="l00043"></a>00043     SINFO_BAND_KS,
+<a name="l00044"></a>00044     SINFO_BAND_L,
+<a name="l00045"></a>00045     SINFO_BAND_M,
+<a name="l00046"></a>00046     SINFO_BAND_LP,
+<a name="l00047"></a>00047     SINFO_BAND_MP,
+<a name="l00048"></a>00048     SINFO_BAND_Z,
+<a name="l00049"></a>00049     SINFO_BAND_SZ,
+<a name="l00050"></a>00050     SINFO_BAND_SH,
+<a name="l00051"></a>00051     SINFO_BAND_SK,
+<a name="l00052"></a>00052     SINFO_BAND_SL,
+<a name="l00053"></a>00053     SINFO_BAND_UNKNOWN
+<a name="l00054"></a>00054 } sinfo_band ;
+<a name="l00055"></a>00055 
+<a name="l00056"></a>00056 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00057"></a>00057 <span class="comment">                                                                Prototypes</span>
+<a name="l00058"></a>00058 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00059"></a>00059 
+<a name="l00060"></a>00060 <span class="keyword">const</span> <span class="keywordtype">char</span> * sinfo_get_license(<span class="keywordtype">void</span>) ;
+<a name="l00061"></a>00061 cpl_frameset * sinfo_extract_frameset(<span class="keyword">const</span> cpl_frameset *, <span class="keyword">const</span> <span class="keywordtype">char</span> *) ;
+<a name="l00062"></a>00062 <span class="keyword">const</span> <span class="keywordtype">char</span> * sinfo_extract_filename(<span class="keyword">const</span> cpl_frameset *, <span class="keyword">const</span> <span class="keywordtype">char</span> *) ;
+<a name="l00063"></a>00063 
+<a name="l00064"></a>00064 <span class="keyword">const</span> <span class="keywordtype">char</span> * sinfo_std_band_name(sinfo_band) ;
+<a name="l00065"></a>00065 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__utilities_8c_source.html b/html/sinfo__utilities_8c_source.html
new file mode 100644
index 0000000..659d527
--- /dev/null
+++ b/html/sinfo__utilities_8c_source.html
@@ -0,0 +1,1075 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_utilities.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_utilities.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00020"></a>00020 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00021"></a>00021 <span class="preprocessor">#endif</span>
+<a name="l00022"></a>00022 <span class="preprocessor"></span><span class="preprocessor">#include "sinfo_utilities.h"</span>
+<a name="l00023"></a>00023 <span class="preprocessor">#include "sinfo_error.h"</span>
+<a name="l00024"></a>00024 <span class="preprocessor">#include "sinfo_dfs.h"</span>
+<a name="l00025"></a>00025 <span class="preprocessor">#include "sinfo_utils_wrappers.h"</span>
+<a name="l00026"></a>00026 <span class="preprocessor">#include "sinfo_function_1d.h"</span>
+<a name="l00035"></a>00035 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00045"></a>00045 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00046"></a>00046 
+<a name="l00047"></a>00047 cpl_image*
+<a name="l00048"></a>00048 sinfo_vector_to_image(<span class="keyword">const</span> cpl_vector* vector,cpl_type type)
+<a name="l00049"></a>00049 {
+<a name="l00050"></a>00050   <span class="keywordtype">int</span> i=0;
+<a name="l00051"></a>00051   cpl_image* image=NULL;
+<a name="l00052"></a>00052   <span class="keywordtype">int</span> size=0;
+<a name="l00053"></a>00053   <span class="keyword">const</span> <span class="keywordtype">double</span>* pv=NULL;
+<a name="l00054"></a>00054   <span class="keywordtype">int</span>* pi=NULL;
+<a name="l00055"></a>00055   <span class="keywordtype">float</span>* pf=NULL;
+<a name="l00056"></a>00056   <span class="keywordtype">double</span>* pd=NULL;
+<a name="l00057"></a>00057 
+<a name="l00058"></a>00058 
+<a name="l00059"></a>00059       size=cpl_vector_get_size(vector);
+<a name="l00060"></a>00060       image=cpl_image_new(size,1,type);
+<a name="l00061"></a>00061       pv=cpl_vector_get_data_const(vector);
+<a name="l00062"></a>00062       <span class="keywordflow">if</span>(type == CPL_TYPE_INT) {
+<a name="l00063"></a>00063         pi=cpl_image_get_data_int(image);
+<a name="l00064"></a>00064         <span class="keywordflow">for</span>(i=0;i<size;i++) {
+<a name="l00065"></a>00065       pi[i]=pv[i];
+<a name="l00066"></a>00066     }
+<a name="l00067"></a>00067       } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (type == CPL_TYPE_FLOAT) {
+<a name="l00068"></a>00068         pf=cpl_image_get_data_float(image);
+<a name="l00069"></a>00069         <span class="keywordflow">for</span>(i=0;i<size;i++) {
+<a name="l00070"></a>00070       pf[i]=pv[i];
+<a name="l00071"></a>00071     }
+<a name="l00072"></a>00072       } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (type == CPL_TYPE_DOUBLE) {
+<a name="l00073"></a>00073         pd=cpl_image_get_data_double(image);
+<a name="l00074"></a>00074         <span class="keywordflow">for</span>(i=0;i<size;i++) {
+<a name="l00075"></a>00075       pd[i]=pv[i];
+<a name="l00076"></a>00076     }
+<a name="l00077"></a>00077       } <span class="keywordflow">else</span> {
+<a name="l00078"></a>00078         assure( 0, CPL_ERROR_INVALID_TYPE,
+<a name="l00079"></a>00079             <span class="stringliteral">"No CPL type to represent BITPIX = %d"</span>, type);
+<a name="l00080"></a>00080       }
+<a name="l00081"></a>00081 
+<a name="l00082"></a>00082  cleanup:
+<a name="l00083"></a>00083     <span class="keywordflow">if</span> (cpl_error_get_code() != CPL_ERROR_NONE){
+<a name="l00084"></a>00084       sinfo_free_image(&image);
+<a name="l00085"></a>00085     }
+<a name="l00086"></a>00086 
+<a name="l00087"></a>00087     <span class="keywordflow">return</span> image;
+<a name="l00088"></a>00088 
+<a name="l00089"></a>00089 }
+<a name="l00090"></a>00090 
+<a name="l00091"></a>00091 
+<a name="l00092"></a>00092 cpl_error_code
+<a name="l00093"></a>00093 sinfo_ima_line_cor(cpl_parameterlist * parlist, cpl_frameset* in)
+<a name="l00094"></a>00094 {
+<a name="l00095"></a>00095   <span class="keywordtype">int</span> n=0;
+<a name="l00096"></a>00096   <span class="keywordtype">int</span> i=0;
+<a name="l00097"></a>00097   <span class="keywordtype">int</span> kappa=18;
+<a name="l00098"></a>00098   <span class="keywordtype">int</span> filt_rad=3;
+<a name="l00099"></a>00099   <span class="keywordtype">int</span> width=4;
+<a name="l00100"></a>00100 
+<a name="l00101"></a>00101   cpl_frame* frm=NULL;
+<a name="l00102"></a>00102   <span class="keyword">const</span> <span class="keywordtype">char</span>* name=NULL;
+<a name="l00103"></a>00103   <span class="keyword">const</span> <span class="keywordtype">char</span>* bname=NULL;
+<a name="l00104"></a>00104 
+<a name="l00105"></a>00105   cpl_image * ima=NULL ;
+<a name="l00106"></a>00106   cpl_image * ima_out=NULL ;
+<a name="l00107"></a>00107   cpl_parameter* p=NULL;
+<a name="l00108"></a>00108   cpl_propertylist* plist=NULL;
+<a name="l00109"></a>00109   <span class="keywordtype">char</span>* tag=NULL;
+<a name="l00110"></a>00110   <span class="keywordtype">char</span> name_deb[80];
+<a name="l00111"></a>00111 
+<a name="l00112"></a>00112 
+<a name="l00113"></a>00113   check_nomsg(p=cpl_parameterlist_find(parlist, <span class="stringliteral">"sinfoni.general.lc_kappa"</span>));
+<a name="l00114"></a>00114   check_nomsg(kappa=cpl_parameter_get_int(p));
+<a name="l00115"></a>00115   check_nomsg(p=cpl_parameterlist_find(parlist,
+<a name="l00116"></a>00116                        <span class="stringliteral">"sinfoni.general.lc_filt_rad"</span>));
+<a name="l00117"></a>00117   check_nomsg(filt_rad = cpl_parameter_get_int(p)) ;
+<a name="l00118"></a>00118 
+<a name="l00119"></a>00119   n=cpl_frameset_get_size(in);
+<a name="l00120"></a>00120 
+<a name="l00121"></a>00121   <span class="keywordflow">for</span>(i=0;i<n;i++) {
+<a name="l00122"></a>00122     check_nomsg(frm=cpl_frameset_get_frame(in,i));
+<a name="l00123"></a>00123     tag= (<span class="keywordtype">char</span>*) cpl_frame_get_tag(frm);
+<a name="l00124"></a>00124     <span class="keywordflow">if</span>(sinfo_frame_is_raw(tag) == 1) {
+<a name="l00125"></a>00125       check_nomsg(name=cpl_frame_get_filename(frm));
+<a name="l00126"></a>00126 
+<a name="l00127"></a>00127       bname=sinfo_new_get_basename(name);
+<a name="l00128"></a>00128       check_nomsg(ima=cpl_image_load(name,CPL_TYPE_FLOAT,0,0));
+<a name="l00129"></a>00129       check_nomsg(sinfo_image_line_corr(width,filt_rad,kappa,ima,&ima_out));
+<a name="l00130"></a>00130       check_nomsg(plist=cpl_propertylist_load(name,0));
+<a name="l00131"></a>00131       <span class="comment">//sprintf(name_deb,"dark_org_%d.fits",i);</span>
+<a name="l00132"></a>00132       sprintf(name_deb,<span class="stringliteral">"org_%2.2d_%s"</span>,i,bname);
+<a name="l00133"></a>00133 
+<a name="l00134"></a>00134       check(cpl_image_save(ima,
+<a name="l00135"></a>00135                name_deb,
+<a name="l00136"></a>00136                CPL_BPP_IEEE_FLOAT,
+<a name="l00137"></a>00137                plist,
+<a name="l00138"></a>00138                CPL_IO_DEFAULT),
+<a name="l00139"></a>00139         <span class="stringliteral">"Could not save product"</span>);
+<a name="l00140"></a>00140 
+<a name="l00141"></a>00141 
+<a name="l00142"></a>00142       check(cpl_image_save(ima_out,
+<a name="l00143"></a>00143                bname,
+<a name="l00144"></a>00144                CPL_BPP_IEEE_FLOAT,
+<a name="l00145"></a>00145                plist,
+<a name="l00146"></a>00146                CPL_IO_DEFAULT),
+<a name="l00147"></a>00147         <span class="stringliteral">"Could not save product"</span>);
+<a name="l00148"></a>00148 
+<a name="l00149"></a>00149       cpl_frame_set_filename(frm,bname);
+<a name="l00150"></a>00150       sinfo_free_image(&ima);
+<a name="l00151"></a>00151       sinfo_free_propertylist(&plist);
+<a name="l00152"></a>00152     }
+<a name="l00153"></a>00153 
+<a name="l00154"></a>00154   }
+<a name="l00155"></a>00155 
+<a name="l00156"></a>00156  cleanup:
+<a name="l00157"></a>00157   sinfo_free_image(&ima);
+<a name="l00158"></a>00158   sinfo_free_propertylist(&plist);
+<a name="l00159"></a>00159 
+<a name="l00160"></a>00160   <span class="keywordflow">return</span> cpl_error_get_code();
+<a name="l00161"></a>00161 
+<a name="l00162"></a>00162 }
+<a name="l00163"></a>00163 
+<a name="l00164"></a>00164 <span class="keywordtype">int</span>
+<a name="l00165"></a>00165 sinfo_table_column_dump(cpl_table* t, <span class="keyword">const</span> <span class="keywordtype">char</span>* name, cpl_type type)
+<a name="l00166"></a>00166 {
+<a name="l00167"></a>00167   <span class="keywordtype">int</span> nrow=0;
+<a name="l00168"></a>00168   <span class="keywordtype">int</span> i=0;
+<a name="l00169"></a>00169   <span class="keywordtype">int</span>* pi=NULL;
+<a name="l00170"></a>00170   <span class="keywordtype">float</span>* pf=NULL;
+<a name="l00171"></a>00171   <span class="keywordtype">double</span>* pd=NULL;
+<a name="l00172"></a>00172   <span class="keywordtype">char</span>** ps=NULL;
+<a name="l00173"></a>00173 
+<a name="l00174"></a>00174   nrow=cpl_table_get_nrow(t);
+<a name="l00175"></a>00175 
+<a name="l00176"></a>00176   <span class="keywordflow">switch</span>(type) {
+<a name="l00177"></a>00177 
+<a name="l00178"></a>00178   <span class="keywordflow">case</span> CPL_TYPE_INT:
+<a name="l00179"></a>00179     pi=cpl_table_get_data_int(t,name);
+<a name="l00180"></a>00180     <span class="keywordflow">for</span>(i=0;i<nrow;i++) {
+<a name="l00181"></a>00181       sinfo_msg(<span class="stringliteral">"val=%d"</span>,pi[i]);
+<a name="l00182"></a>00182     }
+<a name="l00183"></a>00183     <span class="keywordflow">break</span>;
+<a name="l00184"></a>00184   <span class="keywordflow">case</span> CPL_TYPE_FLOAT:
+<a name="l00185"></a>00185     pf=cpl_table_get_data_float(t,name);
+<a name="l00186"></a>00186     <span class="keywordflow">for</span>(i=0;i<nrow;i++) {
+<a name="l00187"></a>00187       sinfo_msg(<span class="stringliteral">"val=%g"</span>,pf[i]);
+<a name="l00188"></a>00188     }
+<a name="l00189"></a>00189     <span class="keywordflow">break</span>;
+<a name="l00190"></a>00190   <span class="keywordflow">case</span> CPL_TYPE_DOUBLE:
+<a name="l00191"></a>00191     pd=cpl_table_get_data_double(t,name);
+<a name="l00192"></a>00192     <span class="keywordflow">for</span>(i=0;i<nrow;i++) {
+<a name="l00193"></a>00193       sinfo_msg(<span class="stringliteral">"val=%g"</span>,pd[i]);
+<a name="l00194"></a>00194     }
+<a name="l00195"></a>00195     <span class="keywordflow">break</span>;
+<a name="l00196"></a>00196   <span class="keywordflow">case</span> CPL_TYPE_STRING:
+<a name="l00197"></a>00197     ps=cpl_table_get_data_string(t,name);
+<a name="l00198"></a>00198     <span class="keywordflow">for</span>(i=0;i<nrow;i++) {
+<a name="l00199"></a>00199       sinfo_msg(<span class="stringliteral">"val=%s"</span>,ps[i]);
+<a name="l00200"></a>00200     }
+<a name="l00201"></a>00201     <span class="keywordflow">break</span>;
+<a name="l00202"></a>00202   <span class="keywordflow">default</span>:
+<a name="l00203"></a>00203     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Wrong column type"</span>);
+<a name="l00204"></a>00204     cpl_error_set(cpl_func, CPL_ERROR_TYPE_MISMATCH);
+<a name="l00205"></a>00205     <span class="keywordflow">return</span> 0;
+<a name="l00206"></a>00206 
+<a name="l00207"></a>00207   }
+<a name="l00208"></a>00208   <span class="keywordflow">return</span> 0;
+<a name="l00209"></a>00209 }
+<a name="l00210"></a>00210 
+<a name="l00211"></a>00211 
+<a name="l00212"></a>00212 
+<a name="l00222"></a>00222 cpl_table*
+<a name="l00223"></a>00223 sinfo_table_shift_column_spline3(cpl_table* t,
+<a name="l00224"></a>00224                                  <span class="keyword">const</span> <span class="keywordtype">char</span>* col,
+<a name="l00225"></a>00225                                  <span class="keyword">const</span> <span class="keywordtype">double</span> shift)
+<a name="l00226"></a>00226 {
+<a name="l00227"></a>00227   cpl_table* out=NULL;
+<a name="l00228"></a>00228   <span class="keywordtype">int</span> nrow=0;
+<a name="l00229"></a>00229   <span class="keywordtype">int</span> i=0;
+<a name="l00230"></a>00230   <span class="keywordtype">int</span> z=0;
+<a name="l00231"></a>00231 
+<a name="l00232"></a>00232   <span class="keywordtype">float</span> sum=0;
+<a name="l00233"></a>00233   <span class="keywordtype">float</span> new_sum=0;
+<a name="l00234"></a>00234 
+<a name="l00235"></a>00235   <span class="keywordtype">float</span>* pi=NULL;
+<a name="l00236"></a>00236   <span class="keywordtype">float</span>* po=NULL;
+<a name="l00237"></a>00237   <span class="keywordtype">float</span>* eval=NULL;
+<a name="l00238"></a>00238   <span class="keywordtype">float</span>* xnum=NULL;
+<a name="l00239"></a>00239   <span class="keywordtype">float</span>* spec=NULL;
+<a name="l00240"></a>00240   <span class="keywordtype">float</span>* corrected_spec=NULL;
+<a name="l00241"></a>00241 
+<a name="l00242"></a>00242   cknull(t,<span class="stringliteral">"null input table"</span>);
+<a name="l00243"></a>00243   out=cpl_table_duplicate(t);
+<a name="l00244"></a>00244 
+<a name="l00245"></a>00245   nrow=cpl_table_get_nrow(t);
+<a name="l00246"></a>00246   check_nomsg(cpl_table_cast_column(t,col,<span class="stringliteral">"FINT"</span>,CPL_TYPE_FLOAT));
+<a name="l00247"></a>00247   check_nomsg(cpl_table_cast_column(out,col,<span class="stringliteral">"FINT"</span>,CPL_TYPE_FLOAT));
+<a name="l00248"></a>00248   pi=cpl_table_get_data_float(t,<span class="stringliteral">"FINT"</span>);
+<a name="l00249"></a>00249   po=cpl_table_get_data_float(out,<span class="stringliteral">"FINT"</span>);
+<a name="l00250"></a>00250 
+<a name="l00251"></a>00251 
+<a name="l00252"></a>00252 
+<a name="l00253"></a>00253   xnum=cpl_calloc(nrow,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l00254"></a>00254   <span class="comment">/* fill the xa[] array for the spline function */</span>
+<a name="l00255"></a>00255   <span class="keywordflow">for</span> ( i = 0 ; i < nrow ; i++ ) {
+<a name="l00256"></a>00256     xnum[i] = i ;
+<a name="l00257"></a>00257   }
+<a name="l00258"></a>00258 
+<a name="l00259"></a>00259   spec=cpl_calloc(nrow,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l00260"></a>00260   corrected_spec=cpl_calloc(nrow,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l00261"></a>00261   eval=cpl_calloc(nrow,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l00262"></a>00262 
+<a name="l00263"></a>00263   sum = 0. ;
+<a name="l00264"></a>00264   <span class="keywordflow">for</span> ( z = 0 ; z < nrow ; z++ ) {
+<a name="l00265"></a>00265     spec[z] = pi[z] ;
+<a name="l00266"></a>00266     <span class="keywordflow">if</span> (isnan(spec[z]) ) {
+<a name="l00267"></a>00267       <span class="keywordflow">for</span> ( i = z-1 ; i <= z+1 ; i++ ) {
+<a name="l00268"></a>00268     <span class="keywordflow">if</span> ( i < 0 ) continue ;
+<a name="l00269"></a>00269     <span class="keywordflow">if</span> ( i >= nrow) continue ;
+<a name="l00270"></a>00270     corrected_spec[i] = ZERO ;
+<a name="l00271"></a>00271       }
+<a name="l00272"></a>00272       spec[z] = 0. ;
+<a name="l00273"></a>00273     }
+<a name="l00274"></a>00274     sum += spec[z] ;
+<a name="l00275"></a>00275     eval[z] = (float)shift+(<span class="keywordtype">float</span>)z ;
+<a name="l00276"></a>00276   }
+<a name="l00277"></a>00277   <span class="comment">/* now we do the spline interpolation*/</span>
+<a name="l00278"></a>00278   <span class="keywordflow">if</span> ( -1 == sinfo_function1d_natural_spline(xnum,spec, nrow,
+<a name="l00279"></a>00279                                              eval,corrected_spec, nrow))
+<a name="l00280"></a>00280     {
+<a name="l00281"></a>00281       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"error in spline interpolation!"</span>) ;
+<a name="l00282"></a>00282       <span class="keywordflow">goto</span> cleanup;
+<a name="l00283"></a>00283     }
+<a name="l00284"></a>00284 
+<a name="l00285"></a>00285   new_sum = 0. ;
+<a name="l00286"></a>00286   <span class="keywordflow">for</span> ( z = 0 ; z < nrow ; z++ ) {
+<a name="l00287"></a>00287     <span class="keywordflow">if</span> ( isnan(corrected_spec[z]) ) {
+<a name="l00288"></a>00288       continue ;
+<a name="l00289"></a>00289     }
+<a name="l00290"></a>00290     new_sum += corrected_spec[z] ;
+<a name="l00291"></a>00291   }
+<a name="l00292"></a>00292   <span class="comment">/* fill output imagelist */</span>
+<a name="l00293"></a>00293   <span class="keywordflow">for</span> ( z = 0 ; z < nrow ; z++ ) {
+<a name="l00294"></a>00294     <span class="keywordflow">if</span> ( new_sum == 0. ) new_sum =1. ;
+<a name="l00295"></a>00295     {
+<a name="l00296"></a>00296       <span class="keywordflow">if</span> ( isnan(corrected_spec[z]) ) {
+<a name="l00297"></a>00297     po[z] = ZERO ;
+<a name="l00298"></a>00298       } <span class="keywordflow">else</span> {
+<a name="l00299"></a>00299     corrected_spec[z] *= sum / new_sum ;
+<a name="l00300"></a>00300     po[z] = corrected_spec[z] ;
+<a name="l00301"></a>00301       }
+<a name="l00302"></a>00302     }
+<a name="l00303"></a>00303   }
+<a name="l00304"></a>00304 
+<a name="l00305"></a>00305   sinfo_free_float(&xnum);
+<a name="l00306"></a>00306   sinfo_free_float(&spec) ;
+<a name="l00307"></a>00307   sinfo_free_float(&corrected_spec) ;
+<a name="l00308"></a>00308   sinfo_free_float(&eval) ;
+<a name="l00309"></a>00309 
+<a name="l00310"></a>00310   check_nomsg(cpl_table_erase_column(t,<span class="stringliteral">"FINT"</span>));
+<a name="l00311"></a>00311   check_nomsg(cpl_table_erase_column(out,col));
+<a name="l00312"></a>00312   check_nomsg(cpl_table_cast_column(out,<span class="stringliteral">"FINT"</span>,col,CPL_TYPE_DOUBLE));
+<a name="l00313"></a>00313   check_nomsg(cpl_table_erase_column(out,<span class="stringliteral">"FINT"</span>));
+<a name="l00314"></a>00314 
+<a name="l00315"></a>00315   <span class="keywordflow">return</span> out;
+<a name="l00316"></a>00316  cleanup:
+<a name="l00317"></a>00317 
+<a name="l00318"></a>00318   sinfo_free_float(&xnum);
+<a name="l00319"></a>00319   sinfo_free_float(&spec) ;
+<a name="l00320"></a>00320   sinfo_free_float(&corrected_spec) ;
+<a name="l00321"></a>00321   sinfo_free_float(&eval) ;
+<a name="l00322"></a>00322   sinfo_free_table(&out);
+<a name="l00323"></a>00323   <span class="keywordflow">return</span> NULL;
+<a name="l00324"></a>00324 
+<a name="l00325"></a>00325 
+<a name="l00326"></a>00326 }
+<a name="l00327"></a>00327 
+<a name="l00328"></a>00328 
+<a name="l00338"></a>00338 cpl_table*
+<a name="l00339"></a>00339 sinfo_table_shift_column_int(<span class="keyword">const</span> cpl_table* t,
+<a name="l00340"></a>00340                              <span class="keyword">const</span> <span class="keywordtype">char</span>* col,
+<a name="l00341"></a>00341                              <span class="keyword">const</span> <span class="keywordtype">double</span> s,
+<a name="l00342"></a>00342                                    <span class="keywordtype">double</span>* r)
+<a name="l00343"></a>00343 {
+<a name="l00344"></a>00344   cpl_table* out=NULL;
+<a name="l00345"></a>00345   <span class="keywordtype">int</span> is=(int)s;
+<a name="l00346"></a>00346   <span class="keywordtype">int</span> nrow=0;
+<a name="l00347"></a>00347   <span class="keywordtype">int</span> i=0;
+<a name="l00348"></a>00348 
+<a name="l00349"></a>00349   <span class="keyword">const</span> <span class="keywordtype">double</span>* pi=NULL;
+<a name="l00350"></a>00350   <span class="keywordtype">double</span>* po=NULL;
+<a name="l00351"></a>00351 
+<a name="l00352"></a>00352   cknull(t,<span class="stringliteral">"null input table"</span>);
+<a name="l00353"></a>00353   out=cpl_table_duplicate(t);
+<a name="l00354"></a>00354   *r=s-is;
+<a name="l00355"></a>00355   nrow=cpl_table_get_nrow(t);
+<a name="l00356"></a>00356   pi=cpl_table_get_data_double_const(t,col);
+<a name="l00357"></a>00357   po=cpl_table_get_data_double(out,col);
+<a name="l00358"></a>00358   <span class="keywordflow">for</span>(i=0;i<nrow;i++) {
+<a name="l00359"></a>00359     <span class="keywordflow">if</span>( ((i-is) >=0) && ((i-is) < nrow)) {
+<a name="l00360"></a>00360       po[i-is]=pi[i];
+<a name="l00361"></a>00361     }
+<a name="l00362"></a>00362   }
+<a name="l00363"></a>00363   <span class="keywordflow">return</span> out;
+<a name="l00364"></a>00364  cleanup:
+<a name="l00365"></a>00365   sinfo_free_table(&out);
+<a name="l00366"></a>00366   <span class="keywordflow">return</span> NULL;
+<a name="l00367"></a>00367 
+<a name="l00368"></a>00368 }
+<a name="l00369"></a>00369 
+<a name="l00370"></a>00370 
+<a name="l00381"></a>00381 cpl_table*
+<a name="l00382"></a>00382 sinfo_table_shift_column_poly(cpl_table* t,
+<a name="l00383"></a>00383                               <span class="keyword">const</span> <span class="keywordtype">char</span>* col,
+<a name="l00384"></a>00384                               <span class="keyword">const</span> <span class="keywordtype">double</span> shift,
+<a name="l00385"></a>00385                               <span class="keyword">const</span> <span class="keywordtype">int</span> order)
+<a name="l00386"></a>00386 {
+<a name="l00387"></a>00387   cpl_table* out=NULL;
+<a name="l00388"></a>00388   <span class="keywordtype">int</span> nrow=0;
+<a name="l00389"></a>00389   <span class="keywordtype">int</span> i=0;
+<a name="l00390"></a>00390   <span class="keywordtype">int</span> flag=0;
+<a name="l00391"></a>00391   <span class="keywordtype">int</span> n_points=0;
+<a name="l00392"></a>00392   <span class="keywordtype">int</span> firstpos=0;
+<a name="l00393"></a>00393   <span class="keywordtype">int</span> z=0;
+<a name="l00394"></a>00394   <span class="keywordtype">float</span> eval=0;
+<a name="l00395"></a>00395   <span class="keywordtype">float</span> sum=0;
+<a name="l00396"></a>00396   <span class="keywordtype">float</span> new_sum=0;
+<a name="l00397"></a>00397   <span class="keywordtype">float</span>* pi=NULL;
+<a name="l00398"></a>00398   <span class="keywordtype">float</span>* po=NULL;
+<a name="l00399"></a>00399   <span class="keywordtype">float</span>* spec=NULL ;
+<a name="l00400"></a>00400   <span class="keywordtype">float</span>* corrected_spec=NULL ;
+<a name="l00401"></a>00401   <span class="keywordtype">float</span>* xnum=NULL ;
+<a name="l00402"></a>00402   <span class="keywordtype">float</span>* tableptr=NULL;
+<a name="l00403"></a>00403 
+<a name="l00404"></a>00404   cknull(t,<span class="stringliteral">"null input table"</span>);
+<a name="l00405"></a>00405   <span class="keywordflow">if</span> ( order <= 0 ) {
+<a name="l00406"></a>00406     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"wrong order of interpolation polynom given!"</span>) ;
+<a name="l00407"></a>00407     <span class="keywordflow">goto</span> cleanup;
+<a name="l00408"></a>00408   }
+<a name="l00409"></a>00409 
+<a name="l00410"></a>00410   out=cpl_table_duplicate(t);
+<a name="l00411"></a>00411 
+<a name="l00412"></a>00412   nrow=cpl_table_get_nrow(t);
+<a name="l00413"></a>00413   cpl_table_cast_column(t,col,<span class="stringliteral">"FINT"</span>,CPL_TYPE_FLOAT);
+<a name="l00414"></a>00414   cpl_table_cast_column(out,col,<span class="stringliteral">"FINT"</span>,CPL_TYPE_FLOAT);
+<a name="l00415"></a>00415   pi=cpl_table_get_data_float(t,<span class="stringliteral">"FINT"</span>);
+<a name="l00416"></a>00416   po=cpl_table_get_data_float(out,<span class="stringliteral">"FINT"</span>);
+<a name="l00417"></a>00417 
+<a name="l00418"></a>00418   n_points = order + 1 ;
+<a name="l00419"></a>00419   <span class="keywordflow">if</span> ( n_points % 2 == 0 ) {
+<a name="l00420"></a>00420     firstpos = (int)(n_points/2) - 1 ;
+<a name="l00421"></a>00421   } <span class="keywordflow">else</span> {
+<a name="l00422"></a>00422     firstpos = (int)(n_points/2) ;
+<a name="l00423"></a>00423   }
+<a name="l00424"></a>00424   spec=cpl_calloc(nrow,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l00425"></a>00425   corrected_spec=cpl_calloc(nrow,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l00426"></a>00426   xnum=cpl_calloc(order+1,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l00427"></a>00427   <span class="comment">/* fill the xa[] array for the polint function */</span>
+<a name="l00428"></a>00428   <span class="keywordflow">for</span> ( i = 0 ; i < n_points ; i++ ) {
+<a name="l00429"></a>00429     xnum[i] = i ;
+<a name="l00430"></a>00430   }
+<a name="l00431"></a>00431 
+<a name="l00432"></a>00432 
+<a name="l00433"></a>00433   <span class="keywordflow">for</span>(i=0;i<nrow;i++) {
+<a name="l00434"></a>00434     corrected_spec[i] = 0. ;
+<a name="l00435"></a>00435   }
+<a name="l00436"></a>00436 
+<a name="l00437"></a>00437   sum = 0. ;
+<a name="l00438"></a>00438   <span class="keywordflow">for</span> ( z = 0 ; z < nrow ; z++ ) {
+<a name="l00439"></a>00439     spec[z] = pi[z] ;
+<a name="l00440"></a>00440     <span class="keywordflow">if</span> (isnan(spec[z]) ) {
+<a name="l00441"></a>00441       spec[z] = 0. ;
+<a name="l00442"></a>00442 
+<a name="l00443"></a>00443       <span class="keywordflow">for</span> ( i = z - firstpos ; i < z-firstpos+n_points ; i++ ) {
+<a name="l00444"></a>00444     <span class="keywordflow">if</span> ( i < 0 ) continue ;
+<a name="l00445"></a>00445     <span class="keywordflow">if</span> ( i >= nrow) continue  ;
+<a name="l00446"></a>00446     corrected_spec[i] = ZERO ;
+<a name="l00447"></a>00447       }
+<a name="l00448"></a>00448     }
+<a name="l00449"></a>00449     <span class="keywordflow">if</span> ( z != 0 && z != nrow - 1 ) {
+<a name="l00450"></a>00450       sum += spec[z] ;
+<a name="l00451"></a>00451     }
+<a name="l00452"></a>00452   }
+<a name="l00453"></a>00453 
+<a name="l00454"></a>00454   new_sum = 0. ;
+<a name="l00455"></a>00455   <span class="keywordflow">for</span> ( z = 0 ; z < nrow ; z++ ) {
+<a name="l00456"></a>00456     <span class="comment">/* ---------------------------------------------------------------</span>
+<a name="l00457"></a>00457 <span class="comment">     * now determine the arrays of size n_points with which the</span>
+<a name="l00458"></a>00458 <span class="comment">     * polynom is determined and determine the position eval</span>
+<a name="l00459"></a>00459 <span class="comment">     * where the polynom is evaluated in polynomial interpolation.</span>
+<a name="l00460"></a>00460 <span class="comment">     * Take care of the points near the row edges!</span>
+<a name="l00461"></a>00461 <span class="comment">     */</span>
+<a name="l00462"></a>00462     <span class="keywordflow">if</span> (isnan(corrected_spec[z])) continue ;
+<a name="l00463"></a>00463     <span class="keywordflow">if</span> ( z - firstpos < 0 ) {
+<a name="l00464"></a>00464       tableptr = &spec[0] ;
+<a name="l00465"></a>00465       eval     = shift + z ;
+<a name="l00466"></a>00466     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( z - firstpos + n_points >= nrow ) {
+<a name="l00467"></a>00467       tableptr = &spec[nrow - n_points] ;
+<a name="l00468"></a>00468       eval     = shift + z + n_points - nrow ;
+<a name="l00469"></a>00469     } <span class="keywordflow">else</span> {
+<a name="l00470"></a>00470       tableptr = &spec[z-firstpos] ;
+<a name="l00471"></a>00471       eval     = shift + firstpos ;
+<a name="l00472"></a>00472     }
+<a name="l00473"></a>00473 
+<a name="l00474"></a>00474     flag=0;
+<a name="l00475"></a>00475     corrected_spec[z]=sinfo_new_nev_ille(xnum,tableptr,order,eval,&flag);
+<a name="l00476"></a>00476     <span class="keywordflow">if</span> ( z != 0 && z != nrow - 1 ) {
+<a name="l00477"></a>00477       new_sum += corrected_spec[z] ;
+<a name="l00478"></a>00478     }
+<a name="l00479"></a>00479   }
+<a name="l00480"></a>00480 
+<a name="l00481"></a>00481   <span class="comment">/* fill the output spectrum */</span>
+<a name="l00482"></a>00482   <span class="keywordflow">for</span> (z = 0 ; z < nrow ; z++ ) {
+<a name="l00483"></a>00483     <span class="keywordflow">if</span> ( new_sum == 0. ) {
+<a name="l00484"></a>00484       new_sum = 1. ;
+<a name="l00485"></a>00485     }
+<a name="l00486"></a>00486     <span class="keywordflow">if</span> ( z == 0 ) {
+<a name="l00487"></a>00487       po[z] = ZERO ;
+<a name="l00488"></a>00488     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( z == nrow - 1 ) {
+<a name="l00489"></a>00489       po[z] = ZERO ;
+<a name="l00490"></a>00490     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( isnan(corrected_spec[z]) ) {
+<a name="l00491"></a>00491       po[z] = ZERO ;
+<a name="l00492"></a>00492     } <span class="keywordflow">else</span> {
+<a name="l00493"></a>00493       corrected_spec[z] *= sum / new_sum ;
+<a name="l00494"></a>00494       po[z] = corrected_spec[z] ;
+<a name="l00495"></a>00495     }
+<a name="l00496"></a>00496   }
+<a name="l00497"></a>00497   check_nomsg(cpl_table_erase_column(t,<span class="stringliteral">"FINT"</span>));
+<a name="l00498"></a>00498   check_nomsg(cpl_table_erase_column(out,col));
+<a name="l00499"></a>00499   check_nomsg(cpl_table_cast_column(out,<span class="stringliteral">"FINT"</span>,col,CPL_TYPE_DOUBLE));
+<a name="l00500"></a>00500   check_nomsg(cpl_table_erase_column(out,<span class="stringliteral">"FINT"</span>));
+<a name="l00501"></a>00501 
+<a name="l00502"></a>00502   sinfo_free_float(&spec) ;
+<a name="l00503"></a>00503   sinfo_free_float(&corrected_spec) ;
+<a name="l00504"></a>00504   sinfo_free_float(&xnum) ;
+<a name="l00505"></a>00505 
+<a name="l00506"></a>00506   <span class="keywordflow">return</span> out;
+<a name="l00507"></a>00507  cleanup:
+<a name="l00508"></a>00508 
+<a name="l00509"></a>00509 
+<a name="l00510"></a>00510   sinfo_free_float(&spec) ;
+<a name="l00511"></a>00511   sinfo_free_float(&corrected_spec) ;
+<a name="l00512"></a>00512   sinfo_free_float(&xnum) ;
+<a name="l00513"></a>00513   sinfo_free_table(&out);
+<a name="l00514"></a>00514   <span class="keywordflow">return</span> NULL;
+<a name="l00515"></a>00515 
+<a name="l00516"></a>00516 
+<a name="l00517"></a>00517 }
+<a name="l00518"></a>00518 
+<a name="l00519"></a>00519 
+<a name="l00520"></a>00520 
+<a name="l00521"></a>00521 
+<a name="l00522"></a>00522     <span class="keywordtype">void</span> sinfo_new_array_set_value( <span class="keywordtype">float</span> * array, <span class="keywordtype">float</span> value, <span class="keywordtype">int</span> i )
+<a name="l00523"></a>00523     {
+<a name="l00524"></a>00524         array[i] = value ;
+<a name="l00525"></a>00525     }
+<a name="l00526"></a>00526     <span class="keywordtype">float</span> sinfo_new_array_get_value( <span class="keywordtype">float</span> * array, <span class="keywordtype">int</span> i )
+<a name="l00527"></a>00527     {
+<a name="l00528"></a>00528         <span class="keywordflow">return</span> array[i] ;
+<a name="l00529"></a>00529     }
+<a name="l00530"></a>00530 
+<a name="l00531"></a>00531 
+<a name="l00532"></a>00532 
+<a name="l00533"></a>00533     <span class="keywordtype">void</span> sinfo_new_destroy_array(<span class="keywordtype">float</span> ** array)
+<a name="l00534"></a>00534     {
+<a name="l00535"></a>00535       <span class="keywordflow">if</span>(*array != NULL) {
+<a name="l00536"></a>00536         cpl_free( *array ) ;
+<a name="l00537"></a>00537         *array = NULL;
+<a name="l00538"></a>00538       }
+<a name="l00539"></a>00539     }
+<a name="l00540"></a>00540 
+<a name="l00541"></a>00541     <span class="keywordtype">void</span> sinfo_new_destroy_stringarray(<span class="keywordtype">char</span> ** array, <span class="keywordtype">int</span> size_x)
+<a name="l00542"></a>00542     {
+<a name="l00543"></a>00543         <span class="keywordtype">int</span> i ;
+<a name="l00544"></a>00544 
+<a name="l00545"></a>00545         <span class="keywordflow">for</span> ( i = 0 ; i < size_x ; i++ )
+<a name="l00546"></a>00546         {
+<a name="l00547"></a>00547             cpl_free( array[i] ) ;
+<a name="l00548"></a>00548         }
+<a name="l00549"></a>00549         cpl_free( array ) ;
+<a name="l00550"></a>00550     }
+<a name="l00551"></a>00551 
+<a name="l00552"></a>00552     <span class="keywordtype">void</span> sinfo_new_destroy_2Dintarray(<span class="keywordtype">int</span> *** array, <span class="keywordtype">int</span> size_x)
+<a name="l00553"></a>00553     {
+<a name="l00554"></a>00554         <span class="keywordtype">int</span> i ;
+<a name="l00555"></a>00555 
+<a name="l00556"></a>00556         <span class="keywordflow">if</span>((*array) != NULL) {
+<a name="l00557"></a>00557       <span class="keywordflow">for</span> ( i = 0 ; i < size_x ; i++ ) {
+<a name="l00558"></a>00558         <span class="keywordflow">if</span>((*array)[i] != NULL) {
+<a name="l00559"></a>00559           cpl_free( (*array)[i] );
+<a name="l00560"></a>00560           (*array)[i]=NULL;
+<a name="l00561"></a>00561         }
+<a name="l00562"></a>00562       }
+<a name="l00563"></a>00563       cpl_free( *array ) ;
+<a name="l00564"></a>00564       *array=NULL;
+<a name="l00565"></a>00565     }
+<a name="l00566"></a>00566 
+<a name="l00567"></a>00567     }
+<a name="l00568"></a>00568 
+<a name="l00569"></a>00569 
+<a name="l00570"></a>00570     <span class="keywordtype">void</span> sinfo_new_intarray_set_value( <span class="keywordtype">int</span> * array, <span class="keywordtype">int</span> value, <span class="keywordtype">int</span> i )
+<a name="l00571"></a>00571     {
+<a name="l00572"></a>00572         array[i] = value ;
+<a name="l00573"></a>00573     }
+<a name="l00574"></a>00574     <span class="keywordtype">float</span> sinfo_new_array2D_get_value( <span class="keywordtype">float</span> ** array, <span class="keywordtype">int</span> x, <span class="keywordtype">int</span> y )
+<a name="l00575"></a>00575     {
+<a name="l00576"></a>00576         <span class="keywordflow">return</span> array[x][y] ;
+<a name="l00577"></a>00577     }
+<a name="l00578"></a>00578     <span class="keywordtype">int</span> ** sinfo_new_2Dintarray( <span class="keywordtype">int</span> size_x, <span class="keywordtype">int</span> size_y)
+<a name="l00579"></a>00579     {
+<a name="l00580"></a>00580         <span class="keywordtype">int</span> ** retVal ;
+<a name="l00581"></a>00581         <span class="keywordtype">int</span> i ;
+<a name="l00582"></a>00582 
+<a name="l00583"></a>00583         retVal = (<span class="keywordtype">int</span> **) cpl_calloc( size_x, <span class="keyword">sizeof</span> (<span class="keywordtype">int</span>*) ) ;
+<a name="l00584"></a>00584         <span class="keywordflow">for</span> ( i = 0 ; i < size_x ; i++ )
+<a name="l00585"></a>00585         {
+<a name="l00586"></a>00586             retVal[i] = (<span class="keywordtype">int</span> *) cpl_calloc( size_y, <span class="keyword">sizeof</span> (<span class="keywordtype">int</span>)) ;
+<a name="l00587"></a>00587         }
+<a name="l00588"></a>00588         <span class="keywordflow">return</span> retVal ;
+<a name="l00589"></a>00589     }
+<a name="l00590"></a>00590 
+<a name="l00591"></a>00591     <span class="keywordtype">float</span> * sinfo_new_floatarray( <span class="keywordtype">int</span> size)
+<a name="l00592"></a>00592     {
+<a name="l00593"></a>00593         <span class="keywordflow">return</span> (<span class="keywordtype">float</span> *) cpl_calloc( size, <span class="keyword">sizeof</span> (<span class="keywordtype">float</span>) ) ;
+<a name="l00594"></a>00594     }
+<a name="l00595"></a>00595 
+<a name="l00596"></a>00596 
+<a name="l00597"></a>00597     <span class="keywordtype">void</span> sinfo_new_destroy_2Dfloatarray(<span class="keywordtype">float</span> *** array, <span class="keywordtype">int</span> size_x)
+<a name="l00598"></a>00598     {
+<a name="l00599"></a>00599         <span class="keywordtype">int</span> i ;
+<a name="l00600"></a>00600         <span class="keywordflow">if</span>((*array) != NULL) {
+<a name="l00601"></a>00601       <span class="keywordflow">for</span> ( i = 0 ; i < size_x ; i++ ) {
+<a name="l00602"></a>00602         <span class="keywordflow">if</span>((*array)[i] != NULL) {
+<a name="l00603"></a>00603           cpl_free( (*array)[i] );
+<a name="l00604"></a>00604           (*array)[i]=NULL;
+<a name="l00605"></a>00605         }
+<a name="l00606"></a>00606       }
+<a name="l00607"></a>00607       cpl_free( *array ) ;
+<a name="l00608"></a>00608       *array=NULL;
+<a name="l00609"></a>00609     }
+<a name="l00610"></a>00610     }
+<a name="l00611"></a>00611 
+<a name="l00612"></a>00612     <span class="keywordtype">void</span> sinfo_new_destroy_2Ddoublearray(<span class="keywordtype">double</span> *** array, <span class="keywordtype">int</span> size_x)
+<a name="l00613"></a>00613     {
+<a name="l00614"></a>00614         <span class="keywordtype">int</span> i ;
+<a name="l00615"></a>00615 
+<a name="l00616"></a>00616         <span class="keywordflow">if</span>((*array) != NULL) {
+<a name="l00617"></a>00617       <span class="keywordflow">for</span> ( i = 0 ; i < size_x ; i++ ) {
+<a name="l00618"></a>00618         <span class="keywordflow">if</span>((*array)[i] != NULL) {
+<a name="l00619"></a>00619           cpl_free( (*array)[i] );
+<a name="l00620"></a>00620           (*array)[i]=NULL;
+<a name="l00621"></a>00621         }
+<a name="l00622"></a>00622       }
+<a name="l00623"></a>00623       cpl_free( *array ) ;
+<a name="l00624"></a>00624       *array=NULL;
+<a name="l00625"></a>00625     }
+<a name="l00626"></a>00626 
+<a name="l00627"></a>00627     }
+<a name="l00628"></a>00628 
+<a name="l00629"></a>00629 
+<a name="l00630"></a>00630     <span class="keywordtype">void</span> sinfo_new_array2D_set_value(<span class="keywordtype">float</span> ** array,<span class="keywordtype">float</span> value,<span class="keywordtype">int</span> x,<span class="keywordtype">int</span> y)
+<a name="l00631"></a>00631     {
+<a name="l00632"></a>00632         array[x][y] = value ;
+<a name="l00633"></a>00633     }
+<a name="l00634"></a>00634 
+<a name="l00635"></a>00635     <span class="keywordtype">double</span> sinfo_new_doublearray_get_value( <span class="keywordtype">double</span> * array, <span class="keywordtype">int</span> i )
+<a name="l00636"></a>00636     {
+<a name="l00637"></a>00637         <span class="keywordflow">return</span> array[i] ;
+<a name="l00638"></a>00638     }
+<a name="l00639"></a>00639     <span class="keywordtype">void</span> sinfo_new_doublearray_set_value( <span class="keywordtype">double</span> * array, <span class="keywordtype">double</span> value, <span class="keywordtype">int</span> i )
+<a name="l00640"></a>00640     {
+<a name="l00641"></a>00641         array[i] = value ;
+<a name="l00642"></a>00642     }
+<a name="l00643"></a>00643 
+<a name="l00644"></a>00644    <span class="keywordtype">void</span> sinfo_new_destroy_doublearray(<span class="keywordtype">double</span> * array)
+<a name="l00645"></a>00645     {
+<a name="l00646"></a>00646         cpl_free( array ) ;
+<a name="l00647"></a>00647     }
+<a name="l00648"></a>00648     <span class="keywordtype">double</span> * sinfo_new_doublearray( <span class="keywordtype">int</span> size)
+<a name="l00649"></a>00649     {
+<a name="l00650"></a>00650         <span class="keywordflow">return</span> (<span class="keywordtype">double</span> *) cpl_calloc( size, <span class="keyword">sizeof</span> (<span class="keywordtype">double</span>) ) ;
+<a name="l00651"></a>00651     }
+<a name="l00652"></a>00652 
+<a name="l00653"></a>00653     <span class="keywordtype">double</span> ** sinfo_new_2Ddoublearray( <span class="keywordtype">int</span> size_x, <span class="keywordtype">int</span> size_y)
+<a name="l00654"></a>00654     {
+<a name="l00655"></a>00655         <span class="keywordtype">double</span> ** retVal ;
+<a name="l00656"></a>00656         <span class="keywordtype">int</span> i ;
+<a name="l00657"></a>00657 
+<a name="l00658"></a>00658         retVal = (<span class="keywordtype">double</span> **) cpl_calloc( size_x, <span class="keyword">sizeof</span> (<span class="keywordtype">double</span>*) ) ;
+<a name="l00659"></a>00659         <span class="keywordflow">for</span> ( i = 0 ; i < size_x ; i++ )
+<a name="l00660"></a>00660         {
+<a name="l00661"></a>00661             retVal[i] = (<span class="keywordtype">double</span> *) cpl_calloc( size_y, <span class="keyword">sizeof</span> (<span class="keywordtype">double</span>)) ;
+<a name="l00662"></a>00662         }
+<a name="l00663"></a>00663         <span class="keywordflow">return</span> retVal ;
+<a name="l00664"></a>00664     }
+<a name="l00665"></a>00665 
+<a name="l00666"></a>00666     <span class="keywordtype">float</span> ** sinfo_new_2Dfloatarray( <span class="keywordtype">int</span> size_x, <span class="keywordtype">int</span> size_y)
+<a name="l00667"></a>00667     {
+<a name="l00668"></a>00668         <span class="keywordtype">float</span> ** retVal ;
+<a name="l00669"></a>00669         <span class="keywordtype">int</span> i ;
+<a name="l00670"></a>00670 
+<a name="l00671"></a>00671         retVal = (<span class="keywordtype">float</span> **) cpl_calloc( size_x, <span class="keyword">sizeof</span> (<span class="keywordtype">float</span>*) ) ;
+<a name="l00672"></a>00672         <span class="keywordflow">for</span> ( i = 0 ; i < size_x ; i++ )
+<a name="l00673"></a>00673         {
+<a name="l00674"></a>00674             retVal[i] = (<span class="keywordtype">float</span> *) cpl_calloc( size_y, <span class="keyword">sizeof</span> (<span class="keywordtype">float</span>)) ;
+<a name="l00675"></a>00675         }
+<a name="l00676"></a>00676         <span class="keywordflow">return</span> retVal ;
+<a name="l00677"></a>00677     }
+<a name="l00678"></a>00678 
+<a name="l00679"></a>00679 
+<a name="l00680"></a>00680     <span class="keywordtype">int</span> * sinfo_new_intarray( <span class="keywordtype">int</span> size)
+<a name="l00681"></a>00681     {
+<a name="l00682"></a>00682         <span class="keywordflow">return</span> (<span class="keywordtype">int</span> *) cpl_calloc( size, <span class="keyword">sizeof</span> (<span class="keywordtype">int</span>) ) ;
+<a name="l00683"></a>00683     }
+<a name="l00684"></a>00684     <span class="keywordtype">void</span> sinfo_new_destroy_intarray(<span class="keywordtype">int</span> ** array)
+<a name="l00685"></a>00685     {
+<a name="l00686"></a>00686         cpl_free( *array ) ;
+<a name="l00687"></a>00687         *array=NULL;
+<a name="l00688"></a>00688     }
+<a name="l00689"></a>00689 
+<a name="l00690"></a>00690     <span class="keywordtype">int</span> sinfo_new_intarray_get_value( <span class="keywordtype">int</span> * array, <span class="keywordtype">int</span> i )
+<a name="l00691"></a>00691     {
+<a name="l00692"></a>00692         <span class="keywordflow">return</span> array[i] ;
+<a name="l00693"></a>00693     }
+<a name="l00694"></a>00694 
+<a name="l00695"></a>00695     <span class="keywordtype">float</span> sinfo_new_Stats_get_cleanstdev(Stats * stats)
+<a name="l00696"></a>00696     {
+<a name="l00697"></a>00697         <span class="keywordflow">return</span> stats -> cleanstdev ;
+<a name="l00698"></a>00698     }
+<a name="l00699"></a>00699     <span class="keywordtype">float</span> sinfo_new_Stats_get_cleanmean(Stats * stats)
+<a name="l00700"></a>00700     {
+<a name="l00701"></a>00701         <span class="keywordflow">return</span> stats -> cleanmean ;
+<a name="l00702"></a>00702     }
+<a name="l00703"></a>00703 
+<a name="l00704"></a>00704 <span class="keywordtype">char</span> * sinfo_new_get_basename(<span class="keyword">const</span> <span class="keywordtype">char</span> *filename)
+<a name="l00705"></a>00705 {
+<a name="l00706"></a>00706   <span class="keywordtype">char</span> *p ;
+<a name="l00707"></a>00707   p = strrchr (filename, <span class="charliteral">'/'</span>);
+<a name="l00708"></a>00708   <span class="keywordflow">return</span> p ? p + 1 : (<span class="keywordtype">char</span> *) filename;
+<a name="l00709"></a>00709 }
+<a name="l00710"></a>00710 
+<a name="l00711"></a>00711 
+<a name="l00712"></a>00712 
+<a name="l00713"></a>00713 <span class="keywordtype">char</span> * sinfo_new_get_rootname(<span class="keyword">const</span> <span class="keywordtype">char</span> * filename)
+<a name="l00714"></a>00714 {
+<a name="l00715"></a>00715     <span class="keyword">static</span> <span class="keywordtype">char</span> path[MAX_NAME_SIZE+1];
+<a name="l00716"></a>00716     <span class="keywordtype">char</span> * lastdot ;
+<a name="l00717"></a>00717 
+<a name="l00718"></a>00718     <span class="keywordflow">if</span> (strlen(filename)>MAX_NAME_SIZE) <span class="keywordflow">return</span> NULL ;
+<a name="l00719"></a>00719     memset(path, MAX_NAME_SIZE, 0);
+<a name="l00720"></a>00720     strcpy(path, filename);
+<a name="l00721"></a>00721     lastdot = strrchr(path, <span class="charliteral">'.'</span>);
+<a name="l00722"></a>00722     <span class="keywordflow">if</span> (lastdot == NULL) <span class="keywordflow">return</span> path ;
+<a name="l00723"></a>00723     <span class="keywordflow">if</span> ((!strcmp(lastdot, <span class="stringliteral">".fits"</span>)) || (!strcmp(lastdot, <span class="stringliteral">".FITS"</span>)) ||
+<a name="l00724"></a>00724         (!strcmp(lastdot, <span class="stringliteral">".paf"</span>)) || (!strcmp(lastdot, <span class="stringliteral">".PAF"</span>)) ||
+<a name="l00725"></a>00725         (!strcmp(lastdot, <span class="stringliteral">".dat"</span>)) || (!strcmp(lastdot, <span class="stringliteral">".DAT"</span>)) ||
+<a name="l00726"></a>00726         (!strcmp(lastdot, <span class="stringliteral">".fits"</span>)) || (!strcmp(lastdot, <span class="stringliteral">".TFITS"</span>)) ||
+<a name="l00727"></a>00727         (!strcmp(lastdot, <span class="stringliteral">".ascii"</span>)) || (!strcmp(lastdot, <span class="stringliteral">".ASCII"</span>)))
+<a name="l00728"></a>00728     {
+<a name="l00729"></a>00729         lastdot[0] = (char)0;
+<a name="l00730"></a>00730     }
+<a name="l00731"></a>00731     <span class="keywordflow">return</span> path ;
+<a name="l00732"></a>00732 }
+<a name="l00733"></a>00733 
+<a name="l00734"></a>00734 
+<a name="l00735"></a>00735 
+<a name="l00736"></a>00736 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00744"></a>00744 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00745"></a>00745 cpl_imagelist * sinfo_new_frameset_to_iset(cpl_frameset * fset)
+<a name="l00746"></a>00746 {
+<a name="l00747"></a>00747     cpl_imagelist   *   iset=NULL ;
+<a name="l00748"></a>00748     <span class="keywordtype">char</span>        **  filenames ;
+<a name="l00749"></a>00749     <span class="keywordtype">int</span>             nfiles=0 ;
+<a name="l00750"></a>00750 
+<a name="l00751"></a>00751     <span class="comment">/* Test entries */</span>
+<a name="l00752"></a>00752     <span class="keywordflow">if</span> (fset == NULL) <span class="keywordflow">return</span> NULL ;
+<a name="l00753"></a>00753 
+<a name="l00754"></a>00754     <span class="comment">/* Get the filenames */</span>
+<a name="l00755"></a>00755     <span class="keywordflow">if</span> ((filenames = sinfo_new_frameset_to_filenames(fset, &nfiles)) == NULL) {
+<a name="l00756"></a>00756         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>( <span class="stringliteral">"Cannot get the files names"</span>) ;
+<a name="l00757"></a>00757         <span class="keywordflow">return</span> NULL ;
+<a name="l00758"></a>00758     }
+<a name="l00759"></a>00759     <span class="comment">/* Load image set */</span>
+<a name="l00760"></a>00760     <span class="keywordflow">if</span> ((iset = sinfo_new_imagelist_load_frameset(fset,
+<a name="l00761"></a>00761                                          CPL_TYPE_FLOAT, 0, 0)) == NULL) {
+<a name="l00762"></a>00762         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>( <span class="stringliteral">"Cannot load *** the image set"</span>) ;
+<a name="l00763"></a>00763         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>((<span class="keywordtype">char</span>* ) cpl_error_get_message());
+<a name="l00764"></a>00764 
+<a name="l00765"></a>00765         cpl_free(filenames) ;
+<a name="l00766"></a>00766         <span class="keywordflow">return</span> NULL ;
+<a name="l00767"></a>00767     }
+<a name="l00768"></a>00768 
+<a name="l00769"></a>00769     <span class="comment">/* Free and Return  */</span>
+<a name="l00770"></a>00770     cpl_free(filenames) ;
+<a name="l00771"></a>00771     <span class="keywordflow">return</span> iset ;
+<a name="l00772"></a>00772 }
+<a name="l00773"></a>00773 <span class="preprocessor">#include "cpl_imagelist_io.h"</span>
+<a name="l00774"></a>00774 
+<a name="l00775"></a>00775 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00786"></a>00786 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00787"></a>00787 cpl_imagelist *
+<a name="l00788"></a>00788 sinfo_new_imagelist_load_frameset(<span class="keyword">const</span> cpl_frameset * frameset,
+<a name="l00789"></a>00789                                   cpl_type type,
+<a name="l00790"></a>00790                                   <span class="keywordtype">int</span> pnum,
+<a name="l00791"></a>00791                                   <span class="keywordtype">int</span> extnum)
+<a name="l00792"></a>00792 {
+<a name="l00793"></a>00793     cpl_image  * image     = NULL;
+<a name="l00794"></a>00794     cpl_imagelist  * imagelist = NULL;
+<a name="l00795"></a>00795     <span class="keyword">const</span> cpl_frame  * frame     = cpl_frameset_get_first_const(frameset);
+<a name="l00796"></a>00796     <span class="keyword">const</span> <span class="keywordtype">int</span> nz = cpl_frameset_get_size(frameset);
+<a name="l00797"></a>00797     <span class="keywordtype">int</span>       i;
+<a name="l00798"></a>00798 
+<a name="l00799"></a>00799     <span class="comment">/* Require imagelist to contain at least one image */</span>
+<a name="l00800"></a>00800     cpl_ensure(nz > 0, CPL_ERROR_DATA_NOT_FOUND, NULL);
+<a name="l00801"></a>00801 
+<a name="l00802"></a>00802     <span class="keywordflow">for</span> (i = 0; frame != NULL;
+<a name="l00803"></a>00803          i++, frame = cpl_frameset_get_next_const(frameset)) {
+<a name="l00804"></a>00804 
+<a name="l00805"></a>00805         <span class="keyword">const</span> <span class="keywordtype">char</span> * name = cpl_frame_get_filename(frame);
+<a name="l00806"></a>00806         <span class="keywordflow">if</span> (name == NULL) <span class="keywordflow">break</span>; <span class="comment">/* Error check */</span>
+<a name="l00807"></a>00807 
+<a name="l00808"></a>00808 
+<a name="l00809"></a>00809         image = cpl_image_load(name, type, pnum, extnum);
+<a name="l00810"></a>00810 
+<a name="l00811"></a>00811         <span class="keywordflow">if</span> (image == NULL) <span class="keywordflow">break</span>; <span class="comment">/* Error check */</span>
+<a name="l00812"></a>00812 
+<a name="l00813"></a>00813         <span class="keywordflow">if</span> (i == 0) {
+<a name="l00814"></a>00814             <span class="keyword">const</span> <span class="keywordtype">int</span> nx = cpl_image_get_size_x(image);
+<a name="l00815"></a>00815             <span class="keyword">const</span> <span class="keywordtype">int</span> ny = cpl_image_get_size_y(image);
+<a name="l00816"></a>00816 
+<a name="l00817"></a>00817             <span class="keywordflow">if</span> (nx < 1 || ny < 1) <span class="keywordflow">break</span>; <span class="comment">/* Error check */</span>
+<a name="l00818"></a>00818             imagelist = cpl_imagelist_new();
+<a name="l00819"></a>00819         <span class="keywordflow">if</span> (imagelist == NULL) <span class="keywordflow">break</span>; <span class="comment">/* Error check */</span>
+<a name="l00820"></a>00820         }
+<a name="l00821"></a>00821 
+<a name="l00822"></a>00822         <span class="keywordflow">if</span> (cpl_imagelist_set(imagelist, image, i)) <span class="keywordflow">break</span>;
+<a name="l00823"></a>00823         image = NULL; <span class="comment">/* Image is now part of the imagelist */</span>
+<a name="l00824"></a>00824 
+<a name="l00825"></a>00825     }
+<a name="l00826"></a>00826 
+<a name="l00827"></a>00827     <span class="keywordflow">if</span> (i != nz) {
+<a name="l00828"></a>00828         <span class="comment">/* Error handling */</span>
+<a name="l00829"></a>00829         cpl_image_delete(image);
+<a name="l00830"></a>00830         cpl_imagelist_delete(imagelist);
+<a name="l00831"></a>00831         imagelist = NULL;
+<a name="l00832"></a>00832     }
+<a name="l00833"></a>00833     <span class="keywordflow">return</span> imagelist;
+<a name="l00834"></a>00834 
+<a name="l00835"></a>00835 }
+<a name="l00836"></a>00836 
+<a name="l00847"></a>00847 <span class="keywordtype">char</span> ** sinfo_new_frameset_to_filenames(cpl_frameset *<span class="keyword">set</span>, <span class="keywordtype">int</span> *nfiles)
+<a name="l00848"></a>00848 {
+<a name="l00849"></a>00849     <span class="keywordtype">char</span> **filenames=NULL;
+<a name="l00850"></a>00850 
+<a name="l00851"></a>00851     <span class="keywordtype">int</span> nbframes=0;
+<a name="l00852"></a>00852     <span class="keywordtype">int</span> i=0;
+<a name="l00853"></a>00853 
+<a name="l00854"></a>00854     cpl_frame *curr_frame;
+<a name="l00855"></a>00855 
+<a name="l00856"></a>00856     <span class="keywordflow">if</span> (<span class="keyword">set</span> == NULL) {
+<a name="l00857"></a>00857         <span class="keywordflow">return</span> NULL;
+<a name="l00858"></a>00858     }
+<a name="l00859"></a>00859 
+<a name="l00860"></a>00860     nbframes = cpl_frameset_get_size(<span class="keyword">set</span>);
+<a name="l00861"></a>00861 
+<a name="l00862"></a>00862     <span class="keywordflow">if</span> (nbframes < 1) {
+<a name="l00863"></a>00863         <span class="keywordflow">return</span> NULL;
+<a name="l00864"></a>00864     }
+<a name="l00865"></a>00865     <span class="comment">/*</span>
+<a name="l00866"></a>00866 <span class="comment">     * Create the list of filenames and fill it</span>
+<a name="l00867"></a>00867 <span class="comment">     */</span>
+<a name="l00868"></a>00868     filenames = cpl_malloc(nbframes * <span class="keyword">sizeof</span>(<span class="keywordtype">char</span> *));
+<a name="l00869"></a>00869 
+<a name="l00870"></a>00870     curr_frame = cpl_frameset_get_first(<span class="keyword">set</span>);
+<a name="l00871"></a>00871     <span class="keywordflow">for</span> (i = 0; i < nbframes; i++) {
+<a name="l00872"></a>00872        filenames[i]=(<span class="keywordtype">char</span>*) cpl_frame_get_filename(curr_frame);
+<a name="l00873"></a>00873         curr_frame = cpl_frameset_get_next(<span class="keyword">set</span>);
+<a name="l00874"></a>00874     }
+<a name="l00875"></a>00875 
+<a name="l00876"></a>00876 
+<a name="l00877"></a>00877     <span class="comment">/*</span>
+<a name="l00878"></a>00878 <span class="comment">     * Set the number of files found</span>
+<a name="l00879"></a>00879 <span class="comment">     */</span>
+<a name="l00880"></a>00880     *nfiles = nbframes;
+<a name="l00881"></a>00881 
+<a name="l00882"></a>00882     <span class="keywordflow">return</span> filenames;
+<a name="l00883"></a>00883 
+<a name="l00884"></a>00884 }
+<a name="l00885"></a>00885 
+<a name="l00886"></a>00886 
+<a name="l00887"></a>00887 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00903"></a>00903 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00904"></a>00904 <span class="keywordtype">double</span> sinfo_spline_hermite(<span class="keywordtype">double</span> xp,
+<a name="l00905"></a>00905                             <span class="keyword">const</span> <span class="keywordtype">double</span> *x,
+<a name="l00906"></a>00906                             <span class="keyword">const</span> <span class="keywordtype">double</span> *y,
+<a name="l00907"></a>00907                               <span class="keywordtype">int</span> n,
+<a name="l00908"></a>00908                               <span class="keywordtype">int</span> *istart )
+<a name="l00909"></a>00909 {
+<a name="l00910"></a>00910     <span class="keywordtype">double</span> yp1, yp2, yp = 0;
+<a name="l00911"></a>00911     <span class="keywordtype">double</span> xpi, xpi1, l1, l2, lp1, lp2;
+<a name="l00912"></a>00912     <span class="keywordtype">int</span> i;
+<a name="l00913"></a>00913 
+<a name="l00914"></a>00914     <span class="keywordflow">if</span> ( x[0] <= x[n-1] && (xp < x[0] || xp > x[n-1]) )    <span class="keywordflow">return</span> 0.0;
+<a name="l00915"></a>00915     <span class="keywordflow">if</span> ( x[0] >  x[n-1] && (xp > x[0] || xp < x[n-1]) )    <span class="keywordflow">return</span> 0.0;
+<a name="l00916"></a>00916 
+<a name="l00917"></a>00917     <span class="keywordflow">if</span> ( x[0] <= x[n-1] )
+<a name="l00918"></a>00918     {
+<a name="l00919"></a>00919         <span class="keywordflow">for</span> ( i = (*istart)+1; i <= n && xp >= x[i-1]; i++ )
+<a name="l00920"></a>00920         ;
+<a name="l00921"></a>00921     }
+<a name="l00922"></a>00922     <span class="keywordflow">else</span>
+<a name="l00923"></a>00923     {
+<a name="l00924"></a>00924         <span class="keywordflow">for</span> ( i = (*istart)+1; i <= n && xp <= x[i-1]; i++ )
+<a name="l00925"></a>00925         ;
+<a name="l00926"></a>00926     }
+<a name="l00927"></a>00927 
+<a name="l00928"></a>00928     *istart = i;
+<a name="l00929"></a>00929     i--;
+<a name="l00930"></a>00930 
+<a name="l00931"></a>00931     lp1 = 1.0 / (x[i-1] - x[i]);
+<a name="l00932"></a>00932     lp2 = -lp1;
+<a name="l00933"></a>00933 
+<a name="l00934"></a>00934     <span class="keywordflow">if</span> ( i == 1 )
+<a name="l00935"></a>00935     {
+<a name="l00936"></a>00936         yp1 = (y[1] - y[0]) / (x[1] - x[0]);
+<a name="l00937"></a>00937     }
+<a name="l00938"></a>00938     <span class="keywordflow">else</span>
+<a name="l00939"></a>00939     {
+<a name="l00940"></a>00940         yp1 = (y[i] - y[i-2]) / (x[i] - x[i-2]);
+<a name="l00941"></a>00941     }
+<a name="l00942"></a>00942 
+<a name="l00943"></a>00943     <span class="keywordflow">if</span> ( i >= n - 1 )
+<a name="l00944"></a>00944     {
+<a name="l00945"></a>00945         yp2 = (y[n-1] - y[n-2]) / (x[n-1] - x[n-2]);
+<a name="l00946"></a>00946     }
+<a name="l00947"></a>00947     <span class="keywordflow">else</span>
+<a name="l00948"></a>00948     {
+<a name="l00949"></a>00949         yp2 = (y[i+1] - y[i-1]) / (x[i+1] - x[i-1]);
+<a name="l00950"></a>00950     }
+<a name="l00951"></a>00951 
+<a name="l00952"></a>00952     xpi1 = xp - x[i];
+<a name="l00953"></a>00953     xpi  = xp - x[i-1];
+<a name="l00954"></a>00954     l1   = xpi1*lp1;
+<a name="l00955"></a>00955     l2   = xpi*lp2;
+<a name="l00956"></a>00956 
+<a name="l00957"></a>00957     yp = y[i-1]*(1 - 2.0*lp1*xpi)*l1*l1 +
+<a name="l00958"></a>00958          y[i]*(1 - 2.0*lp2*xpi1)*l2*l2 +
+<a name="l00959"></a>00959          yp1*xpi*l1*l1 + yp2*xpi1*l2*l2;
+<a name="l00960"></a>00960 
+<a name="l00961"></a>00961     <span class="keywordflow">return</span> yp;
+<a name="l00962"></a>00962 }
+<a name="l00963"></a>00963 
+<a name="l00969"></a>00969 cpl_error_code update_bad_pixel_map(cpl_image* im)
+<a name="l00970"></a>00970 {
+<a name="l00971"></a>00971     <span class="keywordtype">int</span> szx = cpl_image_get_size_x(im);
+<a name="l00972"></a>00972     <span class="keywordtype">int</span> szy = cpl_image_get_size_y(im);
+<a name="l00973"></a>00973     <span class="keywordtype">int</span> x = 0;
+<a name="l00974"></a>00974     cpl_mask* bpm = cpl_image_get_bpm(im);
+<a name="l00975"></a>00975 
+<a name="l00976"></a>00976     <span class="keywordflow">for</span> (x = 1; x <=szx; x++)
+<a name="l00977"></a>00977     {
+<a name="l00978"></a>00978         <span class="keywordtype">int</span> y = 0;
+<a name="l00979"></a>00979         <span class="keywordflow">for</span>(y = 1; y <= szy; y++)
+<a name="l00980"></a>00980         {
+<a name="l00981"></a>00981             <span class="keywordtype">int</span> isnull = 0;
+<a name="l00982"></a>00982             <span class="keywordtype">double</span> value = cpl_image_get(im, x, y, &isnull);
+<a name="l00983"></a>00983             <span class="keywordflow">if</span> (isnan(value))
+<a name="l00984"></a>00984             {
+<a name="l00985"></a>00985                 cpl_mask_set(bpm, x, y, CPL_BINARY_1);
+<a name="l00986"></a>00986             }
+<a name="l00987"></a>00987         }
+<a name="l00988"></a>00988     }
+<a name="l00989"></a>00989     <span class="keywordflow">return</span> cpl_error_get_code();
+<a name="l00990"></a>00990 }
+<a name="l00991"></a>00991 cpl_polynomial * sinfo_polynomial_fit_2d_create(cpl_bivector     *  xy_pos,
+<a name="l00992"></a>00992                                               cpl_vector       *  values,
+<a name="l00993"></a>00993                                               cpl_size                 degree,
+<a name="l00994"></a>00994                                               <span class="keywordtype">double</span>           *  mse)
+<a name="l00995"></a>00995 {
+<a name="l00996"></a>00996     <span class="keyword">typedef</span> <span class="keywordtype">double</span>* (*get_data)(cpl_bivector*);
+<a name="l00997"></a>00997     get_data data_extractor[2] = { &cpl_bivector_get_x_data, &cpl_bivector_get_y_data};
+<a name="l00998"></a>00998     <span class="comment">//samppos matrix must</span>
+<a name="l00999"></a>00999     <span class="comment">// have two rows with copies of the two vectors in the x_pos bivector.</span>
+<a name="l01000"></a>01000 
+<a name="l01001"></a>01001     <span class="keywordtype">double</span> rechisq = 0;
+<a name="l01002"></a>01002     <span class="keywordtype">int</span> i, j;
+<a name="l01003"></a>01003     cpl_vector     * fitresidual = 0;
+<a name="l01004"></a>01004     cpl_matrix     * samppos2d = 0;
+<a name="l01005"></a>01005     cpl_polynomial * fit2d = cpl_polynomial_new(2);
+<a name="l01006"></a>01006     <span class="keywordtype">int</span> xy_size = cpl_bivector_get_size(xy_pos);
+<a name="l01007"></a>01007 
+<a name="l01008"></a>01008     samppos2d = cpl_matrix_new(2, xy_size);
+<a name="l01009"></a>01009     <span class="keywordflow">for</span> (i = 0; i < 2; i++)
+<a name="l01010"></a>01010     {
+<a name="l01011"></a>01011         <span class="keywordflow">for</span> (j = 0; j < xy_size; j++)
+<a name="l01012"></a>01012         {
+<a name="l01013"></a>01013             <span class="keywordtype">double</span> value = data_extractor[i](xy_pos)[j];
+<a name="l01014"></a>01014             cpl_matrix_set(samppos2d, i, j, value);
+<a name="l01015"></a>01015         }
+<a name="l01016"></a>01016     }
+<a name="l01017"></a>01017 
+<a name="l01018"></a>01018    cpl_polynomial_fit(fit2d, samppos2d, NULL, values, NULL, CPL_FALSE,
+<a name="l01019"></a>01019                              NULL, &degree);
+<a name="l01020"></a>01020 
+<a name="l01021"></a>01021     fitresidual = cpl_vector_new(xy_size);
+<a name="l01022"></a>01022     cpl_vector_fill_polynomial_fit_residual(fitresidual, values, NULL, fit2d,
+<a name="l01023"></a>01023                                             samppos2d, &rechisq);
+<a name="l01024"></a>01024     <span class="keywordflow">if</span> (mse)
+<a name="l01025"></a>01025     {
+<a name="l01026"></a>01026         *mse = cpl_vector_product(fitresidual, fitresidual)
+<a name="l01027"></a>01027             / cpl_vector_get_size(fitresidual);
+<a name="l01028"></a>01028     }
+<a name="l01029"></a>01029     cpl_matrix_delete(samppos2d);
+<a name="l01030"></a>01030     cpl_vector_delete(fitresidual);
+<a name="l01031"></a>01031     <span class="keywordflow">return</span> fit2d;
+<a name="l01032"></a>01032 }
+<a name="l01033"></a>01033 
+<a name="l01034"></a>01034 cpl_polynomial * sinfo_polynomial_fit_1d_create(
+<a name="l01035"></a>01035         <span class="keyword">const</span> cpl_vector    *   x_pos,
+<a name="l01036"></a>01036         <span class="keyword">const</span> cpl_vector    *   values,
+<a name="l01037"></a>01037         <span class="keywordtype">int</span>                     degree,
+<a name="l01038"></a>01038         <span class="keywordtype">double</span>              *   mse
+<a name="l01039"></a>01039         )
+<a name="l01040"></a>01040 {
+<a name="l01041"></a>01041     cpl_polynomial * fit1d = cpl_polynomial_new(1);
+<a name="l01042"></a>01042 <span class="comment">//    cpl_vector* x_copy = cpl_vector_duplicate(x_pos);</span>
+<a name="l01043"></a>01043 <span class="comment">//    cpl_vector* values_copy = cpl_vector_duplicate(values);</span>
+<a name="l01044"></a>01044     <span class="keywordtype">int</span> x_size = cpl_vector_get_size(x_pos);
+<a name="l01045"></a>01045     <span class="keywordtype">double</span> rechisq = 0;
+<a name="l01046"></a>01046     cpl_size loc_deg=(cpl_size)degree;
+<a name="l01047"></a>01047     cpl_matrix     * samppos = cpl_matrix_wrap(1, x_size,
+<a name="l01048"></a>01048                                                (<span class="keywordtype">double</span>*)cpl_vector_get_data_const(x_pos));
+<a name="l01049"></a>01049     cpl_vector     * fitresidual = cpl_vector_new(x_size);
+<a name="l01050"></a>01050 
+<a name="l01051"></a>01051     cpl_polynomial_fit(fit1d, samppos, NULL, values, NULL,
+<a name="l01052"></a>01052                        CPL_FALSE, NULL, &loc_deg);
+<a name="l01053"></a>01053     cpl_ensure(!cpl_error_get_code(), cpl_error_get_code(), NULL);
+<a name="l01054"></a>01054     cpl_vector_fill_polynomial_fit_residual(fitresidual, values, NULL, fit1d,
+<a name="l01055"></a>01055                                             samppos, &rechisq);
+<a name="l01056"></a>01056     cpl_ensure(!cpl_error_get_code(), cpl_error_get_code(), NULL);
+<a name="l01057"></a>01057     <span class="keywordflow">if</span> (mse)
+<a name="l01058"></a>01058     {
+<a name="l01059"></a>01059         *mse = cpl_vector_product(fitresidual, fitresidual)
+<a name="l01060"></a>01060             / cpl_vector_get_size(fitresidual);
+<a name="l01061"></a>01061     }
+<a name="l01062"></a>01062     cpl_matrix_unwrap(samppos);
+<a name="l01063"></a>01063     cpl_vector_delete(fitresidual);
+<a name="l01064"></a>01064     <span class="keywordflow">return</span> fit1d;
+<a name="l01065"></a>01065 }
+<a name="l01066"></a>01066 
+<a name="l01067"></a>01067 <span class="comment">//cpl_image * sinfo_image_filter_</span>
+<a name="l01068"></a>01068 <span class="keyword">static</span> cpl_image * sinfo_image_filter_wrapper(<span class="keyword">const</span> cpl_image *b, <span class="keyword">const</span> cpl_matrix *k, cpl_filter_mode mode)
+<a name="l01069"></a>01069 {
+<a name="l01070"></a>01070     <span class="keyword">const</span> <span class="keywordtype">double</span> EPSILON = 1E-5;
+<a name="l01071"></a>01071     <span class="keywordtype">int</span> nx   = cpl_image_get_size_x(b);
+<a name="l01072"></a>01072     <span class="keywordtype">int</span> ny   = cpl_image_get_size_y(b);
+<a name="l01073"></a>01073     <span class="keywordtype">int</span> nrow = cpl_matrix_get_nrow(k);
+<a name="l01074"></a>01074     <span class="keywordtype">int</span> ncol = cpl_matrix_get_ncol(k);
+<a name="l01075"></a>01075     <span class="keywordtype">int</span> i, j;
+<a name="l01076"></a>01076     cpl_type type = cpl_image_get_type(b);
+<a name="l01077"></a>01077     cpl_image * a = cpl_image_new(nx, ny, type);
+<a name="l01078"></a>01078     <span class="comment">// where m is a cpl_mask with a CPL_BINARY_1 whereever k has a 1.0.</span>
+<a name="l01079"></a>01079     cpl_mask* m = cpl_mask_new(ncol, nrow);
+<a name="l01080"></a>01080     cpl_msg_warning(cpl_func, <span class="stringliteral">"nx[%d], ny[%d], ncol[%d], nrow[%d]"</span>, nx, ny, ncol, nrow);
+<a name="l01081"></a>01081     <span class="keywordflow">for</span> (i = 0; i < ncol ; i++)
+<a name="l01082"></a>01082     {
+<a name="l01083"></a>01083         <span class="keywordflow">for</span> (j = 0; j < nrow ; j++)
+<a name="l01084"></a>01084         {
+<a name="l01085"></a>01085             <span class="keywordtype">double</span> value = cpl_matrix_get(k, j, i);
+<a name="l01086"></a>01086             <span class="keywordflow">if</span> (fabs(value - 1.0) < EPSILON)
+<a name="l01087"></a>01087             {
+<a name="l01088"></a>01088                 cpl_mask_set(m, i + 1, j + 1, CPL_BINARY_1);
+<a name="l01089"></a>01089             }
+<a name="l01090"></a>01090         }
+<a name="l01091"></a>01091     }
+<a name="l01092"></a>01092 
+<a name="l01093"></a>01093     cpl_image_filter_mask(a, b, m, mode, CPL_BORDER_FILTER);
+<a name="l01094"></a>01094     cpl_mask_delete(m);
+<a name="l01095"></a>01095     <span class="keywordflow">return</span> a;
+<a name="l01096"></a>01096  }
+<a name="l01097"></a>01097 
+<a name="l01098"></a>01098 
+<a name="l01099"></a>01099 <span class="keyword">static</span> cpl_image*
+<a name="l01100"></a>01100 sinfo_image_filter_mode(<span class="keyword">const</span> cpl_image* b,
+<a name="l01101"></a>01101                       <span class="keyword">const</span> cpl_matrix * ker,
+<a name="l01102"></a>01102                       cpl_filter_mode filter)
+<a name="l01103"></a>01103 {
+<a name="l01104"></a>01104   <span class="keywordtype">int</span> nx   = cpl_image_get_size_x(b);
+<a name="l01105"></a>01105   <span class="keywordtype">int</span> ny   = cpl_image_get_size_y(b);
+<a name="l01106"></a>01106   <span class="keywordtype">int</span> type = cpl_image_get_type(b);
+<a name="l01107"></a>01107   cpl_image * a = cpl_image_new(nx, ny, type);
+<a name="l01108"></a>01108 
+<a name="l01109"></a>01109   <span class="keywordflow">switch</span>(filter) {
+<a name="l01110"></a>01110   <span class="keywordflow">case</span> CPL_FILTER_MEDIAN:
+<a name="l01111"></a>01111     check_nomsg(cpl_image_filter(a, b, ker, CPL_FILTER_MEDIAN, CPL_BORDER_FILTER));
+<a name="l01112"></a>01112     <span class="keywordflow">break</span>;
+<a name="l01113"></a>01113   <span class="keywordflow">case</span> CPL_FILTER_LINEAR:
+<a name="l01114"></a>01114     check_nomsg(cpl_image_filter(a, b, ker, CPL_FILTER_LINEAR, CPL_BORDER_FILTER));
+<a name="l01115"></a>01115     <span class="keywordflow">break</span>;
+<a name="l01116"></a>01116   <span class="keywordflow">case</span> CPL_FILTER_STDEV:
+<a name="l01117"></a>01117     cpl_image_filter(a, b, ker, CPL_FILTER_STDEV, CPL_BORDER_FILTER);
+<a name="l01118"></a>01118     <span class="keywordflow">break</span>;
+<a name="l01119"></a>01119   <span class="keywordflow">case</span> CPL_FILTER_MORPHO:
+<a name="l01120"></a>01120     cpl_image_filter(a, b, ker, CPL_FILTER_MORPHO, CPL_BORDER_FILTER);
+<a name="l01121"></a>01121     <span class="keywordflow">break</span>;
+<a name="l01122"></a>01122   <span class="keywordflow">default</span>:
+<a name="l01123"></a>01123     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Filter type not supported"</span>);
+<a name="l01124"></a>01124     <span class="keywordflow">return</span> NULL;
+<a name="l01125"></a>01125   }
+<a name="l01126"></a>01126  cleanup:
+<a name="l01127"></a>01127 
+<a name="l01128"></a>01128   <span class="keywordflow">return</span> a;
+<a name="l01129"></a>01129 
+<a name="l01130"></a>01130 }
+<a name="l01131"></a>01131 
+<a name="l01132"></a>01132 cpl_image * 
+<a name="l01133"></a>01133 sinfo_image_filter_linear(<span class="keyword">const</span> cpl_image *img, <span class="keyword">const</span> cpl_matrix * mx)
+<a name="l01134"></a>01134 {
+<a name="l01135"></a>01135     <span class="keywordflow">return</span> sinfo_image_filter_mode(img, mx, CPL_FILTER_LINEAR);
+<a name="l01136"></a>01136 
+<a name="l01137"></a>01137 }
+<a name="l01138"></a>01138 
+<a name="l01139"></a>01139 cpl_image * sinfo_image_filter_linear2(<span class="keyword">const</span> cpl_image *img, <span class="keyword">const</span> cpl_matrix * mx)
+<a name="l01140"></a>01140 {
+<a name="l01141"></a>01141     <span class="keywordflow">return</span> sinfo_image_filter_wrapper(img, mx, CPL_FILTER_LINEAR);
+<a name="l01142"></a>01142 
+<a name="l01143"></a>01143 }
+<a name="l01144"></a>01144 
+<a name="l01145"></a>01145 
+<a name="l01146"></a>01146 cpl_image * sinfo_image_filter_median(<span class="keyword">const</span> cpl_image * img, <span class="keyword">const</span> cpl_matrix * mx)
+<a name="l01147"></a>01147 {
+<a name="l01148"></a>01148     <span class="keywordflow">return</span> sinfo_image_filter_wrapper(img, mx, CPL_FILTER_MEDIAN);
+<a name="l01149"></a>01149 }
+<a name="l01150"></a>01150 
+<a name="l01151"></a>01151 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__utilities_8h_source.html b/html/sinfo__utilities_8h_source.html
new file mode 100644
index 0000000..ce60daf
--- /dev/null
+++ b/html/sinfo__utilities_8h_source.html
@@ -0,0 +1,230 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_utilities.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_utilities.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_utilities.h,v 1.13 2011/12/09 07:47:42 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the SINFONI Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2011/12/09 07:47:42 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.13 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 <span class="preprocessor">#ifndef SINFO_UTILITIES_H</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_UTILITIES_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00032"></a>00032 <span class="preprocessor">#endif</span>
+<a name="l00033"></a>00033 <span class="preprocessor"></span><span class="preprocessor">#include <sinfo_cpl_size.h></span>
+<a name="l00034"></a>00034 
+<a name="l00035"></a>00035 <span class="comment">/*</span>
+<a name="l00036"></a>00036 <span class="comment">  This recipe implements error handling cleanly using a pair of macros called</span>
+<a name="l00037"></a>00037 <span class="comment">  sinfo_skip_if() and sinfo_end_skip.</span>
+<a name="l00038"></a>00038 <span class="comment"></span>
+<a name="l00039"></a>00039 <span class="comment">  sinfo_skip_if() takes one argument, which is a logical expression.</span>
+<a name="l00040"></a>00040 <span class="comment">  If the logical expression is false sinfo_skip_if() takes no action and</span>
+<a name="l00041"></a>00041 <span class="comment">  program execution continues.</span>
+<a name="l00042"></a>00042 <span class="comment">  If the logical expression is true this indicates an error. In this case</span>
+<a name="l00043"></a>00043 <span class="comment">  sinfo_skip_if() will set the location of the error to the point where it</span>
+<a name="l00044"></a>00044 <span class="comment">  was invoked in the recipe code (unless the error location is already in the</span>
+<a name="l00045"></a>00045 <span class="comment">  recipe code). If no error code had been set, then sinfo_skip_if() will set</span>
+<a name="l00046"></a>00046 <span class="comment">  one. Finally, sinfo_skip_if() causes program execution to skip to the</span>
+<a name="l00047"></a>00047 <span class="comment">  macro 'sinfo_end_skip'.</span>
+<a name="l00048"></a>00048 <span class="comment">  The macro sinfo_end_skip is located towards the end of the function, after</span>
+<a name="l00049"></a>00049 <span class="comment">  which all resource deallocation and the function return is located.</span>
+<a name="l00050"></a>00050 <span class="comment"></span>
+<a name="l00051"></a>00051 <span class="comment">  The use of sinfo_skip_if() assumes the following coding practice:</span>
+<a name="l00052"></a>00052 <span class="comment">  1) Pointers used for dynamically allocated memory that they "own" shall</span>
+<a name="l00053"></a>00053 <span class="comment">     always</span>
+<a name="l00054"></a>00054 <span class="comment">     point to either NULL or to allocated memory (including CPL-objects).</span>
+<a name="l00055"></a>00055 <span class="comment">  2) Such pointers may not be reused to point to memory whose deallocation</span>
+<a name="l00056"></a>00056 <span class="comment">     requires calls to different functions.</span>
+<a name="l00057"></a>00057 <span class="comment">  3) Pointers of type FILE should be set NULL when not pointing to an open</span>
+<a name="l00058"></a>00058 <span class="comment">     stream and their closing calls (fclose(), freopen(), etc.) following the</span>
+<a name="l00059"></a>00059 <span class="comment">     'sinfo_end_skip' should be guarded against such NULL pointers.</span>
+<a name="l00060"></a>00060 <span class="comment"></span>
+<a name="l00061"></a>00061 <span class="comment">  Error checking with sinfo_skip_if() is encouraged due to the following</span>
+<a name="l00062"></a>00062 <span class="comment">  advantages:</span>
+<a name="l00063"></a>00063 <span class="comment">  1) It ensures that a CPL-error code is set.</span>
+<a name="l00064"></a>00064 <span class="comment">  2) It ensures that the location of the error in the _recipe_ code is noted.</span>
+<a name="l00065"></a>00065 <span class="comment">  3) The error checking may be confined to a single concise line.</span>
+<a name="l00066"></a>00066 <span class="comment">  4) It is not necessary to replicate memory deallocation for every error</span>
+<a name="l00067"></a>00067 <span class="comment">     condition.</span>
+<a name="l00068"></a>00068 <span class="comment">  5) If more extensive error reporting/handling is required it is not precluded</span>
+<a name="l00069"></a>00069 <span class="comment">     by the use of sinfo_skip_if().</span>
+<a name="l00070"></a>00070 <span class="comment">  6) It allows for a single point of function return.</span>
+<a name="l00071"></a>00071 <span class="comment">  7) It allows for optional, uniformly formatted debugging/tracing information</span>
+<a name="l00072"></a>00072 <span class="comment">     at each macro invocation.</span>
+<a name="l00073"></a>00073 <span class="comment"></span>
+<a name="l00074"></a>00074 <span class="comment">  The implementation of sinfo_skip_if() uses a goto/label construction.</span>
+<a name="l00075"></a>00075 <span class="comment">  According to Kerningham & Ritchie, The C Programming Language, 2nd edition,</span>
+<a name="l00076"></a>00076 <span class="comment">  Section 3.8:</span>
+<a name="l00077"></a>00077 <span class="comment">  "This organization is handy if the error-handling code is non-trivial,</span>
+<a name="l00078"></a>00078 <span class="comment">  and if errors can occur in several places."</span>
+<a name="l00079"></a>00079 <span class="comment"></span>
+<a name="l00080"></a>00080 <span class="comment">  The use of goto for any other purpose should be avoided.</span>
+<a name="l00081"></a>00081 <span class="comment"></span>
+<a name="l00082"></a>00082 <span class="comment">*/</span>
+<a name="l00083"></a>00083 
+<a name="l00084"></a>00084 <span class="preprocessor">#define sinfo_skip_if(CONDITION) \</span>
+<a name="l00085"></a>00085 <span class="preprocessor">  do if (CONDITION) { \</span>
+<a name="l00086"></a>00086 <span class="preprocessor">    if (cpl_error_get_code()) { \</span>
+<a name="l00087"></a>00087 <span class="preprocessor">        cpl_msg_debug("", "Skip in %s line %d due to '%s' with error '%s' " \</span>
+<a name="l00088"></a>00088 <span class="preprocessor">                      "at %s", __FILE__, __LINE__, #CONDITION, \</span>
+<a name="l00089"></a>00089 <span class="preprocessor">                      cpl_error_get_message(), cpl_error_get_where());  \</span>
+<a name="l00090"></a>00090 <span class="preprocessor">        if (strstr(cpl_error_get_where(), "visir") == NULL) \</span>
+<a name="l00091"></a>00091 <span class="preprocessor">            cpl_error_set_where(""); \</span>
+<a name="l00092"></a>00092 <span class="preprocessor">    } else { \</span>
+<a name="l00093"></a>00093 <span class="preprocessor">        cpl_msg_debug("", "Skip in %s line %d due to '%s'", \</span>
+<a name="l00094"></a>00094 <span class="preprocessor">                        __FILE__, __LINE__, #CONDITION);  \</span>
+<a name="l00095"></a>00095 <span class="preprocessor">        cpl_error_set("", CPL_ERROR_UNSPECIFIED); \</span>
+<a name="l00096"></a>00096 <span class="preprocessor">    } \</span>
+<a name="l00097"></a>00097 <span class="preprocessor">    goto cleanup; \</span>
+<a name="l00098"></a>00098 <span class="preprocessor">  } else { \</span>
+<a name="l00099"></a>00099 <span class="preprocessor">    if (cpl_error_get_code()) \</span>
+<a name="l00100"></a>00100 <span class="preprocessor">        cpl_msg_debug("", "No skip in %s line %d due to '%s' with error '%s' " \</span>
+<a name="l00101"></a>00101 <span class="preprocessor">                      "at %s", __FILE__, __LINE__, #CONDITION, \</span>
+<a name="l00102"></a>00102 <span class="preprocessor">                      cpl_error_get_message(), cpl_error_get_where()); \</span>
+<a name="l00103"></a>00103 <span class="preprocessor">    else \</span>
+<a name="l00104"></a>00104 <span class="preprocessor">        cpl_msg_debug("", "No skip in %s line %d due to '%s'", \</span>
+<a name="l00105"></a>00105 <span class="preprocessor">                      __FILE__, __LINE__, #CONDITION);  \</span>
+<a name="l00106"></a>00106 <span class="preprocessor">  } while (0)</span>
+<a name="l00107"></a>00107 <span class="preprocessor"></span>
+<a name="l00108"></a>00108 
+<a name="l00109"></a>00109 <span class="preprocessor">#define sinfo_end_skip \</span>
+<a name="l00110"></a>00110 <span class="preprocessor">    do { \</span>
+<a name="l00111"></a>00111 <span class="preprocessor">        cleanup: \</span>
+<a name="l00112"></a>00112 <span class="preprocessor">        if (cpl_error_get_code()) \</span>
+<a name="l00113"></a>00113 <span class="preprocessor">            cpl_msg_debug("", "Cleanup in %s line %d with error '%s' at %s", \</span>
+<a name="l00114"></a>00114 <span class="preprocessor">                           __FILE__, __LINE__, \</span>
+<a name="l00115"></a>00115 <span class="preprocessor">                          cpl_error_get_message(), cpl_error_get_where()); \</span>
+<a name="l00116"></a>00116 <span class="preprocessor">        else \</span>
+<a name="l00117"></a>00117 <span class="preprocessor">            cpl_msg_debug("", "Cleanup in %s line %d", \</span>
+<a name="l00118"></a>00118 <span class="preprocessor">                          __FILE__, __LINE__);  \</span>
+<a name="l00119"></a>00119 <span class="preprocessor">    } while (0)</span>
+<a name="l00120"></a>00120 <span class="preprocessor"></span>
+<a name="l00121"></a>00121 
+<a name="l00122"></a>00122 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00123"></a>00123 <span class="preprocessor">#include <sinfo_image_ops.h></span>
+<a name="l00124"></a>00124 <span class="preprocessor">#include "sinfo_globals.h"</span>
+<a name="l00125"></a>00125 CPL_BEGIN_DECLS
+<a name="l00126"></a>00126 
+<a name="l00127"></a>00127 
+<a name="l00128"></a>00128 cpl_image*
+<a name="l00129"></a>00129 sinfo_vector_to_image(<span class="keyword">const</span> cpl_vector* vector,cpl_type type);
+<a name="l00130"></a>00130 
+<a name="l00131"></a>00131 <span class="keywordtype">int</span>
+<a name="l00132"></a>00132 sinfo_table_column_dump(cpl_table* t, <span class="keyword">const</span> <span class="keywordtype">char</span>* name, cpl_type type);
+<a name="l00133"></a>00133 
+<a name="l00134"></a>00134 cpl_table*
+<a name="l00135"></a>00135 sinfo_table_shift_column_spline3(cpl_table* t,
+<a name="l00136"></a>00136                                  <span class="keyword">const</span> <span class="keywordtype">char</span>* col,
+<a name="l00137"></a>00137                                  <span class="keyword">const</span> <span class="keywordtype">double</span> s);
+<a name="l00138"></a>00138 
+<a name="l00139"></a>00139 cpl_table*
+<a name="l00140"></a>00140 sinfo_table_shift_column_poly(cpl_table* t,
+<a name="l00141"></a>00141                               <span class="keyword">const</span> <span class="keywordtype">char</span>* col,
+<a name="l00142"></a>00142                               <span class="keyword">const</span> <span class="keywordtype">double</span> s,
+<a name="l00143"></a>00143                               <span class="keyword">const</span> <span class="keywordtype">int</span> order);
+<a name="l00144"></a>00144 
+<a name="l00145"></a>00145 cpl_table*
+<a name="l00146"></a>00146 sinfo_table_shift_column_int(<span class="keyword">const</span> cpl_table* t,
+<a name="l00147"></a>00147                              <span class="keyword">const</span> <span class="keywordtype">char</span>* col,
+<a name="l00148"></a>00148                              <span class="keyword">const</span> <span class="keywordtype">double</span> s,
+<a name="l00149"></a>00149                                    <span class="keywordtype">double</span>* r);
+<a name="l00150"></a>00150 
+<a name="l00151"></a>00151 cpl_error_code
+<a name="l00152"></a>00152 sinfo_ima_line_cor(cpl_parameterlist * parlist, cpl_frameset* in);
+<a name="l00153"></a>00153 
+<a name="l00154"></a>00154 
+<a name="l00155"></a>00155 <span class="keywordtype">void</span> sinfo_new_array_set_value( <span class="keywordtype">float</span> * array, <span class="keywordtype">float</span> value, <span class="keywordtype">int</span> i );
+<a name="l00156"></a>00156 <span class="keywordtype">float</span> sinfo_new_array_get_value( <span class="keywordtype">float</span> * array, <span class="keywordtype">int</span> i );
+<a name="l00157"></a>00157 <span class="keywordtype">void</span> sinfo_new_destroy_array(<span class="keywordtype">float</span> ** array);
+<a name="l00158"></a>00158 <span class="keywordtype">void</span> sinfo_new_destroy_stringarray(<span class="keywordtype">char</span> ** array, <span class="keywordtype">int</span> size_x);
+<a name="l00159"></a>00159 <span class="keywordtype">void</span> sinfo_new_intarray_set_value( <span class="keywordtype">int</span> * array, <span class="keywordtype">int</span> value, <span class="keywordtype">int</span> i );
+<a name="l00160"></a>00160 <span class="keywordtype">void</span> sinfo_new_array2D_set_value( <span class="keywordtype">float</span> ** array, <span class="keywordtype">float</span> value, <span class="keywordtype">int</span> x, <span class="keywordtype">int</span> y );
+<a name="l00161"></a>00161 <span class="keywordtype">void</span> sinfo_new_destroy_2Dintarray(<span class="keywordtype">int</span> *** array, <span class="keywordtype">int</span> size_x);
+<a name="l00162"></a>00162 <span class="keywordtype">void</span> sinfo_new_destroy_2Dfloatarray(<span class="keywordtype">float</span> *** array, <span class="keywordtype">int</span> size_x);
+<a name="l00163"></a>00163 <span class="keywordtype">void</span> sinfo_new_destroy_2Ddoublearray(<span class="keywordtype">double</span> *** array, <span class="keywordtype">int</span> size_x);
+<a name="l00164"></a>00164 <span class="keywordtype">void</span> sinfo_new_destroy_intarray(<span class="keywordtype">int</span> ** array);
+<a name="l00165"></a>00165 <span class="keywordtype">void</span> sinfo_new_destroy_doublearray(<span class="keywordtype">double</span> * array);
+<a name="l00166"></a>00166 <span class="keywordtype">void</span> sinfo_new_doublearray_set_value( <span class="keywordtype">double</span> * array, <span class="keywordtype">double</span> value, <span class="keywordtype">int</span> i );
+<a name="l00167"></a>00167 <span class="keywordtype">int</span> sinfo_new_intarray_get_value( <span class="keywordtype">int</span> * array, <span class="keywordtype">int</span> i );
+<a name="l00168"></a>00168 <span class="keywordtype">int</span> * sinfo_new_intarray( <span class="keywordtype">int</span> size);
+<a name="l00169"></a>00169 <span class="keywordtype">int</span> ** sinfo_new_2Dintarray( <span class="keywordtype">int</span> size_x, <span class="keywordtype">int</span> size_y);
+<a name="l00170"></a>00170 <span class="keywordtype">double</span> ** sinfo_new_2Ddoublearray( <span class="keywordtype">int</span> size_x, <span class="keywordtype">int</span> size_y);
+<a name="l00171"></a>00171 <span class="keywordtype">char</span> * sinfo_new_get_rootname(<span class="keyword">const</span> <span class="keywordtype">char</span> * filename);
+<a name="l00172"></a>00172 <span class="keywordtype">char</span> * sinfo_new_get_basename(<span class="keyword">const</span> <span class="keywordtype">char</span> *filename);
+<a name="l00173"></a>00173 <span class="keywordtype">float</span> sinfo_new_Stats_get_cleanstdev(Stats * stats);
+<a name="l00174"></a>00174 <span class="keywordtype">float</span> sinfo_new_Stats_get_cleanmean(Stats * stats);
+<a name="l00175"></a>00175 <span class="keywordtype">float</span> sinfo_new_array2D_get_value( <span class="keywordtype">float</span> ** array, <span class="keywordtype">int</span> x, <span class="keywordtype">int</span> y );
+<a name="l00176"></a>00176 <span class="keywordtype">float</span> * sinfo_new_floatarray( <span class="keywordtype">int</span> size);
+<a name="l00177"></a>00177 <span class="keywordtype">float</span> ** sinfo_new_2Dfloatarray( <span class="keywordtype">int</span> size_x, <span class="keywordtype">int</span> size_y);
+<a name="l00178"></a>00178 <span class="keywordtype">double</span>   sinfo_new_doublearray_get_value( <span class="keywordtype">double</span> * array, <span class="keywordtype">int</span> i );
+<a name="l00179"></a>00179 
+<a name="l00180"></a>00180 <span class="keywordtype">double</span> * sinfo_new_doublearray( <span class="keywordtype">int</span> size);
+<a name="l00181"></a>00181 <span class="comment">/*</span>
+<a name="l00182"></a>00182 <span class="comment">FitParams ** sinfo_new_fit_params( int n_params ) ;</span>
+<a name="l00183"></a>00183 <span class="comment">*/</span>
+<a name="l00184"></a>00184 cpl_imagelist * sinfo_new_frameset_to_iset(cpl_frameset *) ;
+<a name="l00185"></a>00185 cpl_imagelist *
+<a name="l00186"></a>00186 sinfo_new_imagelist_load_frameset(<span class="keyword">const</span> cpl_frameset * frameset,cpl_type type,
+<a name="l00187"></a>00187                                             <span class="keywordtype">int</span> pnum,<span class="keywordtype">int</span> extnum);
+<a name="l00188"></a>00188 
+<a name="l00189"></a>00189 <span class="keywordtype">char</span> ** sinfo_new_frameset_to_filenames(cpl_frameset *<span class="keyword">set</span>, <span class="keywordtype">int</span> *nfiles);
+<a name="l00190"></a>00190 <span class="keywordtype">char</span> ** new_frameset_to_tags(cpl_frameset *<span class="keyword">set</span>, <span class="keywordtype">int</span> *ntags);
+<a name="l00191"></a>00191 <span class="keywordtype">double</span> sinfo_spline_hermite(<span class="keywordtype">double</span> xp,
+<a name="l00192"></a>00192                             <span class="keyword">const</span> <span class="keywordtype">double</span> *x,
+<a name="l00193"></a>00193                             <span class="keyword">const</span> <span class="keywordtype">double</span> *y,
+<a name="l00194"></a>00194                                   <span class="keywordtype">int</span> n,
+<a name="l00195"></a>00195                                   <span class="keywordtype">int</span> *istart );
+<a name="l00196"></a>00196 
+<a name="l00197"></a>00197 cpl_error_code update_bad_pixel_map(cpl_image* im);
+<a name="l00198"></a>00198 <span class="comment">/* replacement of deprecated functions */</span>
+<a name="l00199"></a>00199 cpl_polynomial * sinfo_polynomial_fit_2d_create(cpl_bivector     *  xy_pos,
+<a name="l00200"></a>00200                                               cpl_vector       *  values,
+<a name="l00201"></a>00201                                               cpl_size                 degree,
+<a name="l00202"></a>00202                                               <span class="keywordtype">double</span>           *  mse);
+<a name="l00203"></a>00203 cpl_polynomial * sinfo_polynomial_fit_1d_create(
+<a name="l00204"></a>00204         <span class="keyword">const</span> cpl_vector    *   x_pos,
+<a name="l00205"></a>00205         <span class="keyword">const</span> cpl_vector    *   values,
+<a name="l00206"></a>00206         <span class="keywordtype">int</span>                     degree,
+<a name="l00207"></a>00207         <span class="keywordtype">double</span>              *   mse
+<a name="l00208"></a>00208         );
+<a name="l00209"></a>00209 cpl_image * sinfo_image_filter_median(<span class="keyword">const</span> cpl_image *, <span class="keyword">const</span> cpl_matrix *);
+<a name="l00210"></a>00210 cpl_image * sinfo_image_filter_linear(<span class="keyword">const</span> cpl_image *, <span class="keyword">const</span> cpl_matrix *);
+<a name="l00211"></a>00211 cpl_image * sinfo_image_filter_linear2(<span class="keyword">const</span> cpl_image *, <span class="keyword">const</span> cpl_matrix *);
+<a name="l00212"></a>00212 CPL_END_DECLS
+<a name="l00213"></a>00213 
+<a name="l00214"></a>00214 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__utilities__scired_8c_source.html b/html/sinfo__utilities__scired_8c_source.html
new file mode 100644
index 0000000..6151bc3
--- /dev/null
+++ b/html/sinfo__utilities__scired_8c_source.html
@@ -0,0 +1,1869 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_utilities_scired.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_utilities_scired.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00020"></a>00020 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00021"></a>00021 <span class="preprocessor">#endif</span>
+<a name="l00022"></a>00022 <span class="preprocessor"></span><span class="preprocessor">#include <irplib_stdstar.h></span>
+<a name="l00023"></a>00023 
+<a name="l00024"></a>00024 <span class="comment">//Used only for sinfo_propertylist_has</span>
+<a name="l00025"></a>00025 <span class="preprocessor">#include "sinfo_dfs.h"</span>
+<a name="l00026"></a>00026 
+<a name="l00027"></a>00027 <span class="comment">//Used only for sinfo_band</span>
+<a name="l00028"></a>00028 <span class="preprocessor">#include "sinfo_tpl_utils.h"</span>
+<a name="l00029"></a>00029 
+<a name="l00030"></a>00030 <span class="preprocessor">#include "sinfo_utilities_scired.h"</span>
+<a name="l00031"></a>00031 <span class="preprocessor">#include "sinfo_functions.h"</span>
+<a name="l00032"></a>00032 <span class="preprocessor">#include "sinfo_pfits.h"</span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include "sinfo_spiffi_types.h"</span>
+<a name="l00034"></a>00034 <span class="preprocessor">#include "sinfo_utils_wrappers.h"</span>
+<a name="l00035"></a>00035 <span class="preprocessor">#include "sinfo_error.h"</span>
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="keyword">static</span> <span class="keywordtype">double</span>
+<a name="l00038"></a>00038 sinfo_sess2deg(<span class="keyword">const</span> <span class="keywordtype">double</span> sess);
+<a name="l00039"></a>00039 
+<a name="l00040"></a>00040 <span class="keyword">static</span> <span class="keywordtype">void</span>
+<a name="l00041"></a>00041 sinfo_set_spect_coord1(cpl_propertylist** plist,
+<a name="l00042"></a>00042                <span class="keyword">const</span> <span class="keywordtype">int</span> crpix1,
+<a name="l00043"></a>00043                <span class="keyword">const</span> <span class="keywordtype">double</span> crval1,
+<a name="l00044"></a>00044                <span class="keyword">const</span> <span class="keywordtype">double</span> cdelt1);
+<a name="l00045"></a>00045 
+<a name="l00046"></a>00046 <span class="keyword">static</span> <span class="keywordtype">void</span>
+<a name="l00047"></a>00047 sinfo_set_spect_coord2(cpl_propertylist** plist,
+<a name="l00048"></a>00048                <span class="keyword">const</span> <span class="keywordtype">int</span> crpix2,
+<a name="l00049"></a>00049                <span class="keyword">const</span> <span class="keywordtype">double</span> crval2,
+<a name="l00050"></a>00050                <span class="keyword">const</span> <span class="keywordtype">double</span> cdelt2);
+<a name="l00051"></a>00051 
+<a name="l00052"></a>00052 
+<a name="l00053"></a>00053 <span class="keyword">static</span> <span class="keywordtype">void</span>
+<a name="l00054"></a>00054 sinfo_set_coord1(cpl_propertylist** plist,
+<a name="l00055"></a>00055                  <span class="keyword">const</span> <span class="keywordtype">double</span> crpix1,
+<a name="l00056"></a>00056                  <span class="keyword">const</span> <span class="keywordtype">double</span> crval1,
+<a name="l00057"></a>00057                  <span class="keyword">const</span> <span class="keywordtype">double</span> cdelt1);
+<a name="l00058"></a>00058 <span class="keyword">static</span> <span class="keywordtype">void</span>
+<a name="l00059"></a>00059 sinfo_set_coord2(cpl_propertylist** plist,
+<a name="l00060"></a>00060                  <span class="keyword">const</span> <span class="keywordtype">double</span> crpix2,
+<a name="l00061"></a>00061                  <span class="keyword">const</span> <span class="keywordtype">double</span> crval2,
+<a name="l00062"></a>00062                  <span class="keyword">const</span> <span class="keywordtype">double</span> cdelt2);
+<a name="l00063"></a>00063 <span class="keyword">static</span> <span class="keywordtype">void</span>
+<a name="l00064"></a>00064 sinfo_set_coord3(cpl_propertylist** plist,
+<a name="l00065"></a>00065                  <span class="keyword">const</span> <span class="keywordtype">int</span> crpix3,
+<a name="l00066"></a>00066                  <span class="keyword">const</span> <span class="keywordtype">double</span> crval3,
+<a name="l00067"></a>00067                  <span class="keyword">const</span> <span class="keywordtype">double</span> cdelt3);
+<a name="l00068"></a>00068 
+<a name="l00069"></a>00069 
+<a name="l00070"></a>00070 <span class="keyword">static</span> <span class="keywordtype">void</span>
+<a name="l00071"></a>00071 sinfo_set_cd_matrix2(cpl_propertylist** plist,
+<a name="l00072"></a>00072             <span class="keyword">const</span> <span class="keywordtype">double</span> cd1_1,
+<a name="l00073"></a>00073             <span class="keyword">const</span> <span class="keywordtype">double</span> cd1_2,
+<a name="l00074"></a>00074             <span class="keyword">const</span> <span class="keywordtype">double</span> cd2_1,
+<a name="l00075"></a>00075             <span class="keyword">const</span> <span class="keywordtype">double</span> cd2_2);
+<a name="l00076"></a>00076 
+<a name="l00077"></a>00077 
+<a name="l00078"></a>00078 <span class="keyword">static</span> <span class="keywordtype">void</span>
+<a name="l00079"></a>00079 sinfo_set_cd_matrix3(cpl_propertylist** plist,
+<a name="l00080"></a>00080                      <span class="keyword">const</span> <span class="keywordtype">double</span> cd1_3,
+<a name="l00081"></a>00081                      <span class="keyword">const</span> <span class="keywordtype">double</span> cd2_3,
+<a name="l00082"></a>00082                      <span class="keyword">const</span> <span class="keywordtype">double</span> cd3_1,
+<a name="l00083"></a>00083                      <span class="keyword">const</span> <span class="keywordtype">double</span> cd3_2,
+<a name="l00084"></a>00084                      <span class="keyword">const</span> <span class="keywordtype">double</span> cd3_3);
+<a name="l00085"></a>00085 
+<a name="l00086"></a>00086 
+<a name="l00087"></a>00087 <span class="keyword">static</span> <span class="keywordtype">void</span>
+<a name="l00088"></a>00088 sinfo_new_change_plist_cube (cpl_propertylist * plist,
+<a name="l00089"></a>00089                              <span class="keywordtype">float</span> cenLambda,
+<a name="l00090"></a>00090                              <span class="keywordtype">float</span> dispersion,
+<a name="l00091"></a>00091                              <span class="keywordtype">int</span>   center_z,
+<a name="l00092"></a>00092                              <span class="keywordtype">float</span> center_x,
+<a name="l00093"></a>00093                  <span class="keywordtype">float</span> center_y );
+<a name="l00094"></a>00094 
+<a name="l00095"></a>00095 
+<a name="l00096"></a>00096 <span class="keyword">static</span> <span class="keywordtype">void</span>
+<a name="l00097"></a>00097 sinfo_new_change_plist_image (cpl_propertylist * plist,
+<a name="l00098"></a>00098                               <span class="keywordtype">float</span> center_x,
+<a name="l00099"></a>00099                   <span class="keywordtype">float</span> center_y );
+<a name="l00100"></a>00100 
+<a name="l00101"></a>00101 
+<a name="l00102"></a>00102 <span class="keyword">static</span> <span class="keywordtype">void</span>
+<a name="l00103"></a>00103 sinfo_new_change_plist_spectrum (cpl_propertylist * plist,
+<a name="l00104"></a>00104                  <span class="keywordtype">double</span> cenLambda,
+<a name="l00105"></a>00105                  <span class="keywordtype">double</span> dispersion,
+<a name="l00106"></a>00106                  <span class="keywordtype">int</span>   cenpix);
+<a name="l00107"></a>00107 
+<a name="l00108"></a>00108 <span class="keyword">static</span> cpl_image *
+<a name="l00109"></a>00109 sinfo_new_image_getvig(
+<a name="l00110"></a>00110         cpl_image    *   image_in,
+<a name="l00111"></a>00111         <span class="keywordtype">int</span>             loleft_x,
+<a name="l00112"></a>00112         <span class="keywordtype">int</span>             loleft_y,
+<a name="l00113"></a>00113         <span class="keywordtype">int</span>             upright_x,
+<a name="l00114"></a>00114         <span class="keywordtype">int</span>             upright_y);
+<a name="l00115"></a>00115 
+<a name="l00116"></a>00116 
+<a name="l00117"></a>00117 
+<a name="l00130"></a>00130 <span class="keywordtype">int</span>
+<a name="l00131"></a>00131 sinfo_check_input_data(object_config* cfg)
+<a name="l00132"></a>00132 {
+<a name="l00133"></a>00133 
+<a name="l00134"></a>00134 
+<a name="l00135"></a>00135     <span class="keywordflow">if</span> (cfg == NULL)
+<a name="l00136"></a>00136     {
+<a name="l00137"></a>00137         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" could not parse cpl input!\n"</span>) ;
+<a name="l00138"></a>00138         <span class="keywordflow">return</span> -1 ;
+<a name="l00139"></a>00139     }
+<a name="l00140"></a>00140 
+<a name="l00141"></a>00141 
+<a name="l00142"></a>00142     <span class="keywordflow">if</span>(sinfo_is_fits_file(cfg->wavemap) != 1) {
+<a name="l00143"></a>00143       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Input file wavemap %s is not FITS"</span>,cfg->wavemap);
+<a name="l00144"></a>00144       <span class="keywordflow">return</span> -1;
+<a name="l00145"></a>00145     }
+<a name="l00146"></a>00146 
+<a name="l00147"></a>00147 
+<a name="l00148"></a>00148     <span class="keywordflow">if</span> (cfg->halocorrectInd == 1)
+<a name="l00149"></a>00149     {
+<a name="l00150"></a>00150        <span class="keywordflow">if</span>(sinfo_is_fits_file(cfg->halospectrum) != 1) {
+<a name="l00151"></a>00151           <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Input file %s is not FITS"</span>,cfg->halospectrum);
+<a name="l00152"></a>00152           <span class="keywordflow">return</span> -1;
+<a name="l00153"></a>00153        }
+<a name="l00154"></a>00154 
+<a name="l00155"></a>00155     }
+<a name="l00156"></a>00156 
+<a name="l00157"></a>00157     <span class="keywordflow">if</span> (cfg->northsouthInd == 0) {
+<a name="l00158"></a>00158       <span class="keywordflow">if</span> (sinfo_is_fits_file(cfg->poslist) != 1)
+<a name="l00159"></a>00159     {
+<a name="l00160"></a>00160       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"File %s with tag %s is not FITS!"</span>,
+<a name="l00161"></a>00161                           cfg->poslist,PRO_SLIT_POS);
+<a name="l00162"></a>00162       <span class="keywordflow">return</span> -1 ;
+<a name="l00163"></a>00163     }
+<a name="l00164"></a>00164     } <span class="keywordflow">else</span> {
+<a name="l00165"></a>00165 
+<a name="l00166"></a>00166       <span class="keywordflow">if</span> (sinfo_is_fits_file(cfg->distlist) != 1)
+<a name="l00167"></a>00167     {
+<a name="l00168"></a>00168       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"File %s with tag %s is not FITS!"</span>,
+<a name="l00169"></a>00169                            cfg->distlist,PRO_SLITLETS_DISTANCE);
+<a name="l00170"></a>00170       <span class="keywordflow">return</span> -1;
+<a name="l00171"></a>00171     }
+<a name="l00172"></a>00172     }
+<a name="l00173"></a>00173 
+<a name="l00174"></a>00174 
+<a name="l00175"></a>00175     <span class="keywordflow">return</span> 0;
+<a name="l00176"></a>00176 
+<a name="l00177"></a>00177 
+<a name="l00178"></a>00178 }
+<a name="l00186"></a>00186 <span class="keyword">static</span> <span class="keywordtype">double</span>
+<a name="l00187"></a>00187 sinfo_hms2deg(<span class="keyword">const</span> <span class="keywordtype">double</span> hms)
+<a name="l00188"></a>00188 {
+<a name="l00189"></a>00189   <span class="keywordtype">int</span> hrs=0;
+<a name="l00190"></a>00190   <span class="keywordtype">int</span> min=0;
+<a name="l00191"></a>00191   <span class="keywordtype">double</span> sec=0;
+<a name="l00192"></a>00192   <span class="keywordtype">double</span> deg=0;
+<a name="l00193"></a>00193   <span class="keywordtype">double</span> rest=hms;
+<a name="l00194"></a>00194   <span class="keywordtype">int</span> sign=1;
+<a name="l00195"></a>00195 
+<a name="l00196"></a>00196   <span class="comment">//sinfo_msg("hms=%f",hms);</span>
+<a name="l00197"></a>00197 
+<a name="l00198"></a>00198   <span class="keywordflow">if</span>(hms<0) {
+<a name="l00199"></a>00199     sign=-1;
+<a name="l00200"></a>00200     rest=-hms;
+<a name="l00201"></a>00201   }
+<a name="l00202"></a>00202   <span class="comment">//sinfo_msg("rest=%f",rest);</span>
+<a name="l00203"></a>00203   <span class="comment">//sinfo_msg("sign=%d",sign);</span>
+<a name="l00204"></a>00204 
+<a name="l00205"></a>00205   hrs=(int)(rest/10000.);
+<a name="l00206"></a>00206   <span class="comment">//sinfo_msg("hrs=%d",hrs);</span>
+<a name="l00207"></a>00207 
+<a name="l00208"></a>00208   rest=rest-(double)(hrs*10000.);
+<a name="l00209"></a>00209   min=(int)(rest/100.);
+<a name="l00210"></a>00210   <span class="comment">//sinfo_msg("min=%d",min);</span>
+<a name="l00211"></a>00211 
+<a name="l00212"></a>00212   sec=rest-(double)(min*100.);
+<a name="l00213"></a>00213   <span class="comment">//sinfo_msg("sec=%f",sec);</span>
+<a name="l00214"></a>00214 
+<a name="l00215"></a>00215   deg=hrs*15+(double)(min/4.)+(double)(sec/240.);
+<a name="l00216"></a>00216   <span class="comment">//sinfo_msg("deg=%f",deg);</span>
+<a name="l00217"></a>00217 
+<a name="l00218"></a>00218   deg=sign*deg;
+<a name="l00219"></a>00219   <span class="comment">//sinfo_msg("deg=%f",deg);</span>
+<a name="l00220"></a>00220 
+<a name="l00221"></a>00221   <span class="keywordflow">return</span> deg;
+<a name="l00222"></a>00222 
+<a name="l00223"></a>00223 }
+<a name="l00224"></a>00224 
+<a name="l00232"></a>00232 <span class="keyword">static</span> <span class="keywordtype">double</span>
+<a name="l00233"></a>00233 sinfo_sess2deg(<span class="keyword">const</span> <span class="keywordtype">double</span> sess)
+<a name="l00234"></a>00234 {
+<a name="l00235"></a>00235   <span class="keywordtype">int</span> grad=0;
+<a name="l00236"></a>00236   <span class="keywordtype">int</span> min=0;
+<a name="l00237"></a>00237   <span class="keywordtype">double</span> sec=0;
+<a name="l00238"></a>00238   <span class="keywordtype">double</span> deg=0;
+<a name="l00239"></a>00239   <span class="keywordtype">double</span> rest=sess;
+<a name="l00240"></a>00240   <span class="keywordtype">int</span> sign=1;
+<a name="l00241"></a>00241 
+<a name="l00242"></a>00242   <span class="comment">//sinfo_msg("sess=%f",sess);</span>
+<a name="l00243"></a>00243 
+<a name="l00244"></a>00244   <span class="keywordflow">if</span>(sess<0) {
+<a name="l00245"></a>00245     sign=-1;
+<a name="l00246"></a>00246     rest=-sess;
+<a name="l00247"></a>00247   }
+<a name="l00248"></a>00248   <span class="comment">//sinfo_msg("rest=%f",rest);</span>
+<a name="l00249"></a>00249   <span class="comment">//sinfo_msg("sign=%d",sign);</span>
+<a name="l00250"></a>00250 
+<a name="l00251"></a>00251   grad=(int)(rest/10000.);
+<a name="l00252"></a>00252   <span class="comment">//sinfo_msg("grad=%d",grad);</span>
+<a name="l00253"></a>00253 
+<a name="l00254"></a>00254   rest=rest-(double)(grad*10000.);
+<a name="l00255"></a>00255   min=(int)(rest/100.);
+<a name="l00256"></a>00256   <span class="comment">//sinfo_msg("min=%d",min);</span>
+<a name="l00257"></a>00257 
+<a name="l00258"></a>00258   sec=rest-(double)(min*100.);
+<a name="l00259"></a>00259   <span class="comment">//sinfo_msg("sec=%f",sec);</span>
+<a name="l00260"></a>00260 
+<a name="l00261"></a>00261   deg=grad+(double)(min/60.)+(double)(sec/3600.);
+<a name="l00262"></a>00262   <span class="comment">//sinfo_msg("deg=%f",deg);</span>
+<a name="l00263"></a>00263 
+<a name="l00264"></a>00264   deg=sign*deg;
+<a name="l00265"></a>00265   <span class="comment">//sinfo_msg("deg=%f",deg);</span>
+<a name="l00266"></a>00266 
+<a name="l00267"></a>00267   <span class="keywordflow">return</span> deg;
+<a name="l00268"></a>00268 
+<a name="l00269"></a>00269 }
+<a name="l00270"></a>00270 
+<a name="l00271"></a>00271 
+<a name="l00284"></a>00284 <span class="keywordtype">int</span>
+<a name="l00285"></a>00285 sinfo_auto_size_cube(<span class="keywordtype">float</span>* offsetx,
+<a name="l00286"></a>00286                       <span class="keywordtype">float</span>* offsety,
+<a name="l00287"></a>00287               <span class="keyword">const</span> <span class="keywordtype">int</span> nframes,
+<a name="l00288"></a>00288                     <span class="keywordtype">float</span>* ref_offx,
+<a name="l00289"></a>00289                     <span class="keywordtype">float</span>* ref_offy,
+<a name="l00290"></a>00290                     <span class="keywordtype">int</span>* size_x,
+<a name="l00291"></a>00291                     <span class="keywordtype">int</span>* size_y)
+<a name="l00292"></a>00292 {
+<a name="l00293"></a>00293 
+<a name="l00294"></a>00294   <span class="keywordtype">int</span> n=0;
+<a name="l00295"></a>00295   <span class="keywordtype">float</span> offx=0;
+<a name="l00296"></a>00296   <span class="keywordtype">float</span> offy=0;
+<a name="l00297"></a>00297   <span class="keywordtype">float</span> min_offx=0;
+<a name="l00298"></a>00298   <span class="keywordtype">float</span> max_offx=0;
+<a name="l00299"></a>00299   <span class="keywordtype">float</span> min_offy=0;
+<a name="l00300"></a>00300   <span class="keywordtype">float</span> max_offy=0;
+<a name="l00301"></a>00301 
+<a name="l00302"></a>00302   sinfo_msg (<span class="stringliteral">"Computation of output cube size"</span>) ;
+<a name="l00303"></a>00303   <span class="keywordflow">for</span> ( n = 0 ; n < nframes ; n++ ) {
+<a name="l00304"></a>00304     offx = offsetx[n];  <span class="comment">/* was - */</span>
+<a name="l00305"></a>00305     offy = offsety[n];  <span class="comment">/* was - */</span>
+<a name="l00306"></a>00306     <span class="comment">/* sinfo_msg("frame %d offx=%f offy=%f",n,offx,offy); */</span>
+<a name="l00307"></a>00307     <span class="keywordflow">if</span>(n==0) {
+<a name="l00308"></a>00308       min_offx=offx;
+<a name="l00309"></a>00309       min_offy=offy;
+<a name="l00310"></a>00310       max_offx=offx;
+<a name="l00311"></a>00311       max_offy=offy;
+<a name="l00312"></a>00312     } <span class="keywordflow">else</span> {
+<a name="l00313"></a>00313       <span class="keywordflow">if</span>(offx > max_offx) max_offx=offx;
+<a name="l00314"></a>00314       <span class="keywordflow">if</span>(offy > max_offy) max_offy=offy;
+<a name="l00315"></a>00315       <span class="keywordflow">if</span>(offx < min_offx) min_offx=offx;
+<a name="l00316"></a>00316       <span class="keywordflow">if</span>(offy < min_offy) min_offy=offy;
+<a name="l00317"></a>00317     }
+<a name="l00318"></a>00318   }
+<a name="l00319"></a>00319   <span class="comment">/*</span>
+<a name="l00320"></a>00320 <span class="comment">  sinfo_msg("max_offx=%f max_offy=%f",max_offx,max_offy);</span>
+<a name="l00321"></a>00321 <span class="comment">  sinfo_msg("min_offx=%f min_offy=%f",min_offx,min_offy);</span>
+<a name="l00322"></a>00322 <span class="comment">  */</span>
+<a name="l00323"></a>00323   *ref_offx=(min_offx+max_offx)/2;
+<a name="l00324"></a>00324   *ref_offy=(min_offy+max_offy)/2;
+<a name="l00325"></a>00325   *size_x+=2*floor(max_offx-min_offx+0.5);
+<a name="l00326"></a>00326   *size_y+=2*floor(max_offy-min_offy+0.5);
+<a name="l00327"></a>00327   sinfo_msg(<span class="stringliteral">"Output cube size: %d x %d"</span>,*size_x,*size_y);
+<a name="l00328"></a>00328   sinfo_msg(<span class="stringliteral">"Ref offset. x: %f y: %f"</span>,*ref_offx,*ref_offy);
+<a name="l00329"></a>00329   <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"Max offset. x: %f y: %f"</span>,max_offx,max_offy);
+<a name="l00330"></a>00330   <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"Min offset. x: %f y: %f"</span>,min_offx,min_offy);
+<a name="l00331"></a>00331   <span class="keywordflow">return</span> 0;
+<a name="l00332"></a>00332 
+<a name="l00333"></a>00333 }
+<a name="l00334"></a>00334 
+<a name="l00342"></a>00342 <span class="keywordtype">int</span>
+<a name="l00343"></a>00343 sinfo_auto_size_cube5(object_config * cfg,
+<a name="l00344"></a>00344                     <span class="keywordtype">float</span>* ref_offx, <span class="keywordtype">float</span>* ref_offy,
+<a name="l00345"></a>00345                     <span class="keywordtype">float</span>* min_offx, <span class="keywordtype">float</span>* min_offy,
+<a name="l00346"></a>00346                     <span class="keywordtype">float</span>* max_offx, <span class="keywordtype">float</span>* max_offy)
+<a name="l00347"></a>00347 {
+<a name="l00348"></a>00348 
+<a name="l00349"></a>00349   <span class="keywordtype">char</span>* name =NULL;
+<a name="l00350"></a>00350   <span class="keywordtype">int</span> n=0;
+<a name="l00351"></a>00351   <span class="keywordtype">float</span> offx=0;
+<a name="l00352"></a>00352   <span class="keywordtype">float</span> offy=0;
+<a name="l00353"></a>00353 
+<a name="l00354"></a>00354   cpl_propertylist * plist=NULL;
+<a name="l00355"></a>00355   sinfo_msg (<span class="stringliteral">"Automatic computation of output cube size"</span>) ;
+<a name="l00356"></a>00356   <span class="keywordflow">for</span> ( n = 0 ; n < cfg->nframes ; n++ ) {
+<a name="l00357"></a>00357     name = cfg->framelist[n] ;
+<a name="l00358"></a>00358     plist=cpl_propertylist_load(name,0);
+<a name="l00359"></a>00359     offx = sinfo_pfits_get_cumoffsetx(plist);  <span class="comment">/* was - */</span>
+<a name="l00360"></a>00360     <span class="keywordflow">if</span>(cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l00361"></a>00361       <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">" could not read fits header keyword cummoffsetx!"</span>);
+<a name="l00362"></a>00362       <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">" set it to  0"</span>);
+<a name="l00363"></a>00363       offx = 0;
+<a name="l00364"></a>00364       cpl_error_reset();
+<a name="l00365"></a>00365       <span class="comment">/* return -1 ; */</span>
+<a name="l00366"></a>00366     }
+<a name="l00367"></a>00367 
+<a name="l00368"></a>00368     offy = sinfo_pfits_get_cumoffsety(plist); <span class="comment">/* was - */</span>
+<a name="l00369"></a>00369     sinfo_free_propertylist(&plist);
+<a name="l00370"></a>00370     <span class="keywordflow">if</span>(cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l00371"></a>00371       <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">" could not read fits header keyword! cumoffsety"</span>) ;
+<a name="l00372"></a>00372       <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">" set it to 0"</span>);
+<a name="l00373"></a>00373       offy = 0;
+<a name="l00374"></a>00374       cpl_error_reset();
+<a name="l00375"></a>00375       <span class="comment">/* return -1 ; */</span>
+<a name="l00376"></a>00376     }
+<a name="l00377"></a>00377     <span class="comment">//sinfo_msg("n=%d offx=%f offy=%f",n,offx,offy);</span>
+<a name="l00378"></a>00378 
+<a name="l00379"></a>00379     <span class="keywordflow">if</span>(n==0) {
+<a name="l00380"></a>00380       *min_offx=offx;
+<a name="l00381"></a>00381       *min_offy=offy;
+<a name="l00382"></a>00382       *max_offx=offx;
+<a name="l00383"></a>00383       *max_offy=offy;
+<a name="l00384"></a>00384     } <span class="keywordflow">else</span> {
+<a name="l00385"></a>00385       <span class="keywordflow">if</span>(offx > *max_offx) *max_offx=offx;
+<a name="l00386"></a>00386       <span class="keywordflow">if</span>(offy > *max_offy) *max_offy=offy;
+<a name="l00387"></a>00387       <span class="keywordflow">if</span>(offx < *min_offx) *min_offx=offx;
+<a name="l00388"></a>00388       <span class="keywordflow">if</span>(offy < *min_offy) *min_offy=offy;
+<a name="l00389"></a>00389     }
+<a name="l00390"></a>00390   }
+<a name="l00391"></a>00391   *ref_offx=(*min_offx+*max_offx)/2;
+<a name="l00392"></a>00392   *ref_offy=(*min_offy+*max_offy)/2;
+<a name="l00393"></a>00393 
+<a name="l00394"></a>00394   <span class="keywordflow">if</span>(cfg->size_x == 0) cfg->size_x=2*floor(*max_offx-*min_offx+0.5)+64 ;
+<a name="l00395"></a>00395 <span class="comment">/* The formula above doesn't give always the right result (DSF07663)</span>
+<a name="l00396"></a>00396 <span class="comment"> * for example, if diff in offset is 35.5, the formula gives 72 but 71 would be</span>
+<a name="l00397"></a>00397 <span class="comment"> * enough, the following candidate is working fine:</span>
+<a name="l00398"></a>00398 <span class="comment"> *   if(cfg->size_x == 0)</span>
+<a name="l00399"></a>00399 <span class="comment">      cfg->size_x=floor(2.0*(*max_offx-*min_offx + 0.5 - 0.00001))+64 ;</span>
+<a name="l00400"></a>00400 <span class="comment">      Currently the ticket is suspended, because the formula above</span>
+<a name="l00401"></a>00401 <span class="comment">      would change the scientific results for the previous data.</span>
+<a name="l00402"></a>00402 <span class="comment">      The same is actual for Y axis.</span>
+<a name="l00403"></a>00403 <span class="comment">*/</span>
+<a name="l00404"></a>00404   <span class="keywordflow">if</span>(cfg->size_y == 0) cfg->size_y=2*floor(*max_offy-*min_offy+0.5)+64 ;
+<a name="l00405"></a>00405 
+<a name="l00406"></a>00406   sinfo_msg(<span class="stringliteral">"Output cube size: %d x %d"</span>,cfg->size_x,cfg->size_y);
+<a name="l00407"></a>00407   sinfo_msg(<span class="stringliteral">"Ref offset. x: %f y: %f"</span>,*ref_offx,*ref_offy);
+<a name="l00408"></a>00408   sinfo_msg(<span class="stringliteral">"Max offset. x: %f y: %f"</span>,*max_offx,*max_offy);
+<a name="l00409"></a>00409   sinfo_msg(<span class="stringliteral">"Min offset. x: %f y: %f"</span>,*min_offx,*min_offy);
+<a name="l00410"></a>00410   <span class="keywordflow">return</span> 0;
+<a name="l00411"></a>00411 
+<a name="l00412"></a>00412 
+<a name="l00413"></a>00413 }
+<a name="l00414"></a>00414 
+<a name="l00424"></a>00424 <span class="keywordtype">float</span>*
+<a name="l00425"></a>00425 sinfo_read_distances(<span class="keyword">const</span> <span class="keywordtype">int</span> nslits, <span class="keyword">const</span> <span class="keywordtype">char</span>* distlist)
+<a name="l00426"></a>00426 {
+<a name="l00427"></a>00427   <span class="keywordtype">int</span> i=0;
+<a name="l00428"></a>00428   <span class="keywordtype">int</span>* status=NULL;
+<a name="l00429"></a>00429   <span class="keywordtype">float</span> * distances = NULL;
+<a name="l00430"></a>00430   <span class="keywordtype">float</span> tmp_float=0;
+<a name="l00431"></a>00431   <span class="keywordtype">char</span> tbl_distances_name[FILE_NAME_SZ];
+<a name="l00432"></a>00432   cpl_table* tbl_distances = NULL;
+<a name="l00433"></a>00433 
+<a name="l00434"></a>00434   sinfo_msg(<span class="stringliteral">"Read distances"</span>);
+<a name="l00435"></a>00435   distances = (<span class="keywordtype">float</span>*) cpl_calloc (nslits - 1, <span class="keyword">sizeof</span> (<span class="keywordtype">float</span>));
+<a name="l00436"></a>00436 
+<a name="l00437"></a>00437   <span class="keywordflow">if</span> ( NULL == distances )
+<a name="l00438"></a>00438     {
+<a name="l00439"></a>00439       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"could allocate memory!"</span>) ;
+<a name="l00440"></a>00440       <span class="keywordflow">return</span> NULL ;
+<a name="l00441"></a>00441     }
+<a name="l00442"></a>00442 
+<a name="l00443"></a>00443             <span class="comment">/*READ TFITS TABLE*/</span>
+<a name="l00444"></a>00444   <span class="keywordflow">if</span>(cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l00445"></a>00445     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Before loading input table"</span>);
+<a name="l00446"></a>00446     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>((<span class="keywordtype">char</span>* ) cpl_error_get_message());
+<a name="l00447"></a>00447     <span class="keywordflow">return</span> NULL;
+<a name="l00448"></a>00448   }
+<a name="l00449"></a>00449   strcpy(tbl_distances_name,distlist);
+<a name="l00450"></a>00450   tbl_distances = cpl_table_load(tbl_distances_name,1,0);
+<a name="l00451"></a>00451   <span class="keywordflow">if</span>(cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l00452"></a>00452     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"loading input table %s"</span>,tbl_distances_name);
+<a name="l00453"></a>00453     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>((<span class="keywordtype">char</span>* ) cpl_error_get_message());
+<a name="l00454"></a>00454     <span class="keywordflow">return</span> NULL;
+<a name="l00455"></a>00455   }
+<a name="l00456"></a>00456 
+<a name="l00457"></a>00457   <span class="keywordflow">for</span> (i =0 ; i< nslits-1; i++){
+<a name="l00458"></a>00458     tmp_float=cpl_table_get_float(tbl_distances,<span class="stringliteral">"slitlet_distance"</span>,i,status);
+<a name="l00459"></a>00459     <span class="keywordflow">if</span>(cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l00460"></a>00460       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"reading col %s from table %s"</span>,<span class="stringliteral">"slitlet_distance"</span>,
+<a name="l00461"></a>00461                        tbl_distances_name);
+<a name="l00462"></a>00462       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>((<span class="keywordtype">char</span>* ) cpl_error_get_message());
+<a name="l00463"></a>00463       <span class="keywordflow">return</span> NULL;
+<a name="l00464"></a>00464     }
+<a name="l00465"></a>00465     sinfo_new_array_set_value(distances,tmp_float,i);
+<a name="l00466"></a>00466   }
+<a name="l00467"></a>00467   cpl_table_delete(tbl_distances);
+<a name="l00468"></a>00468   <span class="keywordflow">return</span> distances;
+<a name="l00469"></a>00469 
+<a name="l00470"></a>00470 }
+<a name="l00471"></a>00471 
+<a name="l00472"></a>00472 
+<a name="l00473"></a>00473 
+<a name="l00481"></a>00481 <span class="keywordtype">float</span>**
+<a name="l00482"></a>00482 sinfo_read_slitlets_edges(<span class="keyword">const</span> <span class="keywordtype">int</span> nslits, <span class="keyword">const</span> <span class="keywordtype">char</span>* poslist)
+<a name="l00483"></a>00483 {
+<a name="l00484"></a>00484 
+<a name="l00485"></a>00485 
+<a name="l00486"></a>00486   <span class="keywordtype">char</span> tbl_slitpos_name[FILE_NAME_SZ];
+<a name="l00487"></a>00487   cpl_table* tbl_slitpos=NULL;
+<a name="l00488"></a>00488   <span class="keywordtype">int</span> n=0;
+<a name="l00489"></a>00489   <span class="keywordtype">int</span> i=0;
+<a name="l00490"></a>00490   <span class="keywordtype">int</span>* status=NULL;
+<a name="l00491"></a>00491   <span class="keywordtype">float</span> edge_x=0;
+<a name="l00492"></a>00492   <span class="keywordtype">float</span> edge_y=0;
+<a name="l00493"></a>00493   <span class="keywordtype">float</span> ** slit_edges = NULL;
+<a name="l00494"></a>00494 
+<a name="l00495"></a>00495   slit_edges = sinfo_new_2Dfloatarray(nslits, 2) ;
+<a name="l00496"></a>00496 
+<a name="l00497"></a>00497   strcpy(tbl_slitpos_name,poslist);
+<a name="l00498"></a>00498   tbl_slitpos = cpl_table_load(tbl_slitpos_name,1,0);
+<a name="l00499"></a>00499   <span class="keywordflow">if</span>(cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l00500"></a>00500     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"error loading tbl %s"</span>,tbl_slitpos_name);
+<a name="l00501"></a>00501     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>((<span class="keywordtype">char</span>* ) cpl_error_get_message());
+<a name="l00502"></a>00502     <span class="keywordflow">return</span> NULL;
+<a name="l00503"></a>00503   }
+<a name="l00504"></a>00504   n = cpl_table_get_nrow(tbl_slitpos);
+<a name="l00505"></a>00505   <span class="keywordflow">if</span> (n != nslits) {
+<a name="l00506"></a>00506     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"No of slitlets in table is n = %d != %d !"</span>,n,nslits);
+<a name="l00507"></a>00507     <span class="keywordflow">return</span> NULL;
+<a name="l00508"></a>00508   }
+<a name="l00509"></a>00509 
+<a name="l00510"></a>00510   <span class="keywordflow">for</span> (i =0 ; i< nslits; i++){
+<a name="l00511"></a>00511     edge_x=cpl_table_get_double(tbl_slitpos,<span class="stringliteral">"pos1"</span>,i,status);
+<a name="l00512"></a>00512     edge_y=cpl_table_get_double(tbl_slitpos,<span class="stringliteral">"pos2"</span>,i,status);
+<a name="l00513"></a>00513     <span class="keywordflow">if</span>(cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l00514"></a>00514       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"error reading tbl %s row %d"</span>,tbl_slitpos_name,i);
+<a name="l00515"></a>00515       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>((<span class="keywordtype">char</span>* ) cpl_error_get_message());
+<a name="l00516"></a>00516       <span class="keywordflow">return</span> NULL;
+<a name="l00517"></a>00517     }
+<a name="l00518"></a>00518     sinfo_new_array2D_set_value(slit_edges,edge_x,i,0);
+<a name="l00519"></a>00519     sinfo_new_array2D_set_value(slit_edges,edge_y,i,1);
+<a name="l00520"></a>00520   }
+<a name="l00521"></a>00521   cpl_table_delete(tbl_slitpos);
+<a name="l00522"></a>00522   <span class="keywordflow">if</span>(cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l00523"></a>00523     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"error reading tbl %s"</span>,tbl_slitpos_name);
+<a name="l00524"></a>00524     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>((<span class="keywordtype">char</span>* ) cpl_error_get_message());
+<a name="l00525"></a>00525     <span class="keywordflow">return</span> NULL;
+<a name="l00526"></a>00526   }
+<a name="l00527"></a>00527 
+<a name="l00528"></a>00528   <span class="keywordflow">return</span> slit_edges;
+<a name="l00529"></a>00529 
+<a name="l00530"></a>00530 }
+<a name="l00531"></a>00531 
+<a name="l00532"></a>00532 
+<a name="l00533"></a>00533 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00556"></a>00556 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00557"></a>00557 cpl_imagelist * sinfo_new_cube_getvig(
+<a name="l00558"></a>00558         cpl_imagelist *        cube_in,
+<a name="l00559"></a>00559         <span class="keywordtype">int</span>             loleft_x,
+<a name="l00560"></a>00560         <span class="keywordtype">int</span>             loleft_y,
+<a name="l00561"></a>00561         <span class="keywordtype">int</span>             upright_x,
+<a name="l00562"></a>00562         <span class="keywordtype">int</span>             upright_y)
+<a name="l00563"></a>00563 {
+<a name="l00564"></a>00564     cpl_imagelist     *        cube_out ;
+<a name="l00565"></a>00565     <span class="keywordtype">int</span>                 i ;
+<a name="l00566"></a>00566     <span class="keywordtype">int</span>                 outlx,
+<a name="l00567"></a>00567                                         outly ;
+<a name="l00568"></a>00568 
+<a name="l00569"></a>00569     <span class="keywordtype">int</span> ilx=0;
+<a name="l00570"></a>00570     <span class="keywordtype">int</span> ily=0;
+<a name="l00571"></a>00571     <span class="keywordtype">int</span> inp=0;
+<a name="l00572"></a>00572     cpl_image* i_img=NULL;
+<a name="l00573"></a>00573     cpl_image* o_img=NULL;
+<a name="l00574"></a>00574 
+<a name="l00575"></a>00575     <span class="keywordflow">if</span> (cube_in==NULL) <span class="keywordflow">return</span> NULL ;
+<a name="l00576"></a>00576 
+<a name="l00577"></a>00577     ilx=cpl_image_get_size_x(cpl_imagelist_get(cube_in,0));
+<a name="l00578"></a>00578     ily=cpl_image_get_size_y(cpl_imagelist_get(cube_in,0));
+<a name="l00579"></a>00579     inp=cpl_imagelist_get_size(cube_in);
+<a name="l00580"></a>00580 
+<a name="l00581"></a>00581         <span class="keywordflow">if</span> ((loleft_x>upright_x) ||
+<a name="l00582"></a>00582             (loleft_y>upright_y)) {
+<a name="l00583"></a>00583             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"ill-defined slit for extraction: aborting"</span>);
+<a name="l00584"></a>00584             <span class="keywordflow">return</span> NULL ;
+<a name="l00585"></a>00585         }
+<a name="l00586"></a>00586 
+<a name="l00587"></a>00587     <span class="comment">/* Extraction coordinates include rectangular zone  */</span>
+<a name="l00588"></a>00588     outlx = upright_x - loleft_x + 1 ;
+<a name="l00589"></a>00589     outly = upright_y - loleft_y + 1 ;
+<a name="l00590"></a>00590     <span class="comment">/*</span>
+<a name="l00591"></a>00591 <span class="comment">    cube_out = sinfo_new_cube(outlx, outly, cube_in->np) ;</span>
+<a name="l00592"></a>00592 <span class="comment">    */</span>
+<a name="l00593"></a>00593     cube_out = cpl_imagelist_new() ;
+<a name="l00594"></a>00594     <span class="comment">/* Loop on all input planes */</span>
+<a name="l00595"></a>00595     <span class="keywordflow">for</span> (i=0 ; i<cpl_imagelist_get_size(cube_in) ; i++) {
+<a name="l00596"></a>00596 
+<a name="l00597"></a>00597       i_img=cpl_imagelist_get(cube_in,i);
+<a name="l00598"></a>00598         <span class="comment">/* Extract a slit from this plane   */</span>
+<a name="l00599"></a>00599                 o_img = sinfo_new_image_getvig(i_img,
+<a name="l00600"></a>00600                         loleft_x, loleft_y,
+<a name="l00601"></a>00601                         upright_x, upright_y) ;
+<a name="l00602"></a>00602         cpl_imagelist_set(cube_out,o_img,i);
+<a name="l00603"></a>00603     }
+<a name="l00604"></a>00604     <span class="keywordflow">return</span> cube_out ;
+<a name="l00605"></a>00605 }
+<a name="l00606"></a>00606 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00623"></a>00623 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00624"></a>00624 
+<a name="l00625"></a>00625 <span class="keyword">static</span> cpl_image *
+<a name="l00626"></a>00626 sinfo_new_image_getvig(
+<a name="l00627"></a>00627         cpl_image    *    image_in,
+<a name="l00628"></a>00628         <span class="keywordtype">int</span>             loleft_x,
+<a name="l00629"></a>00629         <span class="keywordtype">int</span>             loleft_y,
+<a name="l00630"></a>00630         <span class="keywordtype">int</span>             upright_x,
+<a name="l00631"></a>00631         <span class="keywordtype">int</span>             upright_y)
+<a name="l00632"></a>00632 {
+<a name="l00633"></a>00633     cpl_image    *        slit_img ;
+<a name="l00634"></a>00634     <span class="keywordtype">int</span>                 i, j ;
+<a name="l00635"></a>00635     <span class="keyword">register</span>
+<a name="l00636"></a>00636     pixelvalue  *       inpt,
+<a name="l00637"></a>00637                                 *       outpt ;
+<a name="l00638"></a>00638     <span class="keywordtype">int</span>         outlx, outly ;
+<a name="l00639"></a>00639     <span class="keywordtype">int</span> ilx=0;
+<a name="l00640"></a>00640     <span class="keywordtype">int</span> ily=0;
+<a name="l00641"></a>00641 
+<a name="l00642"></a>00642     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l00643"></a>00643     <span class="keywordtype">float</span>* podata=NULL;
+<a name="l00644"></a>00644 
+<a name="l00645"></a>00645     <span class="keywordflow">if</span> (image_in==NULL) <span class="keywordflow">return</span> NULL ;
+<a name="l00646"></a>00646 
+<a name="l00647"></a>00647     ilx=cpl_image_get_size_x(image_in);
+<a name="l00648"></a>00648     ily=cpl_image_get_size_y(image_in);
+<a name="l00649"></a>00649     pidata=cpl_image_get_data_float(image_in);
+<a name="l00650"></a>00650 
+<a name="l00651"></a>00651     <span class="keywordflow">if</span> ((loleft_x<1) || (loleft_x>ilx) ||
+<a name="l00652"></a>00652         (loleft_y<1) || (loleft_y>ily) ||
+<a name="l00653"></a>00653         (upright_x<1) || (upright_x>ilx) ||
+<a name="l00654"></a>00654         (upright_y<1) || (upright_y>ily) ||
+<a name="l00655"></a>00655         (loleft_x>upright_x) || (loleft_y>upright_y)) {
+<a name="l00656"></a>00656         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"extraction zone is [%d %d] [%d %d]\n"</span>
+<a name="l00657"></a>00657                         <span class="stringliteral">"cannot extract such zone: aborting slit extraction"</span>,
+<a name="l00658"></a>00658                 loleft_x, loleft_y, upright_x, upright_y) ;
+<a name="l00659"></a>00659         <span class="keywordflow">return</span> NULL ;
+<a name="l00660"></a>00660     }
+<a name="l00661"></a>00661 
+<a name="l00662"></a>00662     outlx = upright_x - loleft_x + 1 ;
+<a name="l00663"></a>00663     outly = upright_y - loleft_y + 1 ;
+<a name="l00664"></a>00664     slit_img = cpl_image_new(outlx, outly,CPL_TYPE_FLOAT) ;
+<a name="l00665"></a>00665     podata=cpl_image_get_data_float(slit_img);
+<a name="l00666"></a>00666 
+<a name="l00667"></a>00667     <span class="keywordflow">for</span> (j=0 ; j<outly ; j++) {
+<a name="l00668"></a>00668         inpt = pidata+loleft_x-1 + (j+loleft_y-1)*ilx ;
+<a name="l00669"></a>00669         outpt = podata + j*outlx ;
+<a name="l00670"></a>00670         <span class="keywordflow">for</span> (i=0 ; i<outlx ; i++) {
+<a name="l00671"></a>00671             *outpt++ = *inpt++ ;
+<a name="l00672"></a>00672         }
+<a name="l00673"></a>00673     }
+<a name="l00674"></a>00674     <span class="keywordflow">return</span> slit_img ;
+<a name="l00675"></a>00675 }
+<a name="l00676"></a>00676 
+<a name="l00688"></a>00688 <span class="keywordtype">int</span>
+<a name="l00689"></a>00689 sinfo_new_set_wcs_cube(cpl_imagelist* cub, <span class="keyword">const</span> <span class="keywordtype">char</span>* name, <span class="keywordtype">double</span> clambda,
+<a name="l00690"></a>00690          <span class="keywordtype">double</span> dis, <span class="keywordtype">double</span> cpix, <span class="keywordtype">double</span> cx, <span class="keywordtype">double</span> cy)
+<a name="l00691"></a>00691 {
+<a name="l00692"></a>00692   cpl_propertylist* plist=NULL;
+<a name="l00693"></a>00693 
+<a name="l00694"></a>00694   <span class="keywordflow">if</span> ((cpl_error_code)((plist = cpl_propertylist_load(name, 0)) == NULL)) {
+<a name="l00695"></a>00695     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>( <span class="stringliteral">"getting header from frame %s"</span>,name);
+<a name="l00696"></a>00696     cpl_propertylist_delete(plist) ;
+<a name="l00697"></a>00697     <span class="keywordflow">return</span> -1 ;
+<a name="l00698"></a>00698   }
+<a name="l00699"></a>00699 
+<a name="l00700"></a>00700   sinfo_new_change_plist_cube(plist, clambda, dis, cpix, cx, cy) ;
+<a name="l00701"></a>00701   sinfo_plist_set_extra_keys(plist,<span class="stringliteral">"IMAGE"</span>,<span class="stringliteral">"DATA"</span>,<span class="stringliteral">"RMSE"</span>,
+<a name="l00702"></a>00702                  <span class="stringliteral">"DATA"</span>,<span class="stringliteral">"ERRS"</span>,<span class="stringliteral">"QUAL"</span>,0);
+<a name="l00703"></a>00703   <span class="keywordflow">if</span> (cpl_imagelist_save(cub, name, CPL_BPP_IEEE_FLOAT,
+<a name="l00704"></a>00704                          plist,CPL_IO_DEFAULT)!=CPL_ERROR_NONE) {
+<a name="l00705"></a>00705     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>( <span class="stringliteral">"Cannot save the product %s"</span>,name);
+<a name="l00706"></a>00706     cpl_propertylist_delete(plist) ;
+<a name="l00707"></a>00707     <span class="keywordflow">return</span> -1 ;
+<a name="l00708"></a>00708   }
+<a name="l00709"></a>00709   cpl_propertylist_delete(plist) ;
+<a name="l00710"></a>00710   <span class="keywordflow">return</span> 0;
+<a name="l00711"></a>00711 
+<a name="l00712"></a>00712 }
+<a name="l00721"></a>00721 <span class="keywordtype">int</span>
+<a name="l00722"></a>00722 sinfo_new_set_wcs_image(cpl_image* img,
+<a name="l00723"></a>00723                         <span class="keyword">const</span> <span class="keywordtype">char</span>* name,
+<a name="l00724"></a>00724                         <span class="keywordtype">double</span> cx,
+<a name="l00725"></a>00725                         <span class="keywordtype">double</span> cy)
+<a name="l00726"></a>00726 {
+<a name="l00727"></a>00727   cpl_propertylist* plist=NULL;
+<a name="l00728"></a>00728 
+<a name="l00729"></a>00729   <span class="keywordflow">if</span> ((cpl_error_code)((plist = cpl_propertylist_load(name, 0)) == NULL)) {
+<a name="l00730"></a>00730     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>( <span class="stringliteral">"getting header from frame %s"</span>,name);
+<a name="l00731"></a>00731     cpl_propertylist_delete(plist) ;
+<a name="l00732"></a>00732     <span class="keywordflow">return</span> -1 ;
+<a name="l00733"></a>00733   }
+<a name="l00734"></a>00734   sinfo_new_change_plist_image(plist, cx, cy) ;
+<a name="l00735"></a>00735 
+<a name="l00736"></a>00736   <span class="keywordflow">if</span> (cpl_image_save(img, name, CPL_BPP_IEEE_FLOAT,
+<a name="l00737"></a>00737                      plist,CPL_IO_DEFAULT)!=CPL_ERROR_NONE) {
+<a name="l00738"></a>00738     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>( <span class="stringliteral">"Cannot save the product %s"</span>,name);
+<a name="l00739"></a>00739     cpl_propertylist_delete(plist) ;
+<a name="l00740"></a>00740     <span class="keywordflow">return</span> -1 ;
+<a name="l00741"></a>00741   }
+<a name="l00742"></a>00742   cpl_propertylist_delete(plist) ;
+<a name="l00743"></a>00743   <span class="keywordflow">return</span> 0;
+<a name="l00744"></a>00744 
+<a name="l00745"></a>00745 }
+<a name="l00746"></a>00746 
+<a name="l00747"></a>00747 
+<a name="l00757"></a>00757 <span class="keywordtype">int</span>
+<a name="l00758"></a>00758 sinfo_new_set_wcs_spectrum(cpl_image* img, <span class="keyword">const</span> <span class="keywordtype">char</span>* name, <span class="keywordtype">double</span> clambda,
+<a name="l00759"></a>00759              <span class="keywordtype">double</span> dis, <span class="keywordtype">double</span> cpix)
+<a name="l00760"></a>00760 {
+<a name="l00761"></a>00761   cpl_propertylist* plist=NULL;
+<a name="l00762"></a>00762 
+<a name="l00763"></a>00763   <span class="keywordflow">if</span> ((cpl_error_code)((plist = cpl_propertylist_load(name, 0)) == NULL)) {
+<a name="l00764"></a>00764     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>( <span class="stringliteral">"getting header from frame %s"</span>,name);
+<a name="l00765"></a>00765     cpl_propertylist_delete(plist) ;
+<a name="l00766"></a>00766     <span class="keywordflow">return</span> -1 ;
+<a name="l00767"></a>00767   }
+<a name="l00768"></a>00768   sinfo_new_change_plist_spectrum(plist, clambda, dis,cpix) ;
+<a name="l00769"></a>00769 
+<a name="l00770"></a>00770   <span class="keywordflow">if</span> (cpl_image_save(img, name, CPL_BPP_IEEE_FLOAT,
+<a name="l00771"></a>00771                      plist,CPL_IO_DEFAULT)!=CPL_ERROR_NONE) {
+<a name="l00772"></a>00772     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>( <span class="stringliteral">"Cannot save the product %s"</span>,name);
+<a name="l00773"></a>00773     cpl_propertylist_delete(plist) ;
+<a name="l00774"></a>00774     <span class="keywordflow">return</span> -1 ;
+<a name="l00775"></a>00775   }
+<a name="l00776"></a>00776   cpl_propertylist_delete(plist) ;
+<a name="l00777"></a>00777   <span class="keywordflow">return</span> 0;
+<a name="l00778"></a>00778 
+<a name="l00779"></a>00779 }
+<a name="l00791"></a>00791 <span class="keyword">static</span> <span class="keywordtype">void</span>
+<a name="l00792"></a>00792 sinfo_new_change_plist_cube (cpl_propertylist * plist,
+<a name="l00793"></a>00793             <span class="keywordtype">float</span> cenLambda,
+<a name="l00794"></a>00794             <span class="keywordtype">float</span> dispersion,
+<a name="l00795"></a>00795             <span class="keywordtype">int</span>   center_z,
+<a name="l00796"></a>00796             <span class="keywordtype">float</span> center_x,
+<a name="l00797"></a>00797             <span class="keywordtype">float</span> center_y )
+<a name="l00798"></a>00798 {
+<a name="l00799"></a>00799 
+<a name="l00800"></a>00800     <span class="keywordtype">float</span> pixelscale ;
+<a name="l00801"></a>00801     <span class="keywordtype">double</span> ra ;
+<a name="l00802"></a>00802     <span class="keywordtype">double</span> dec ;
+<a name="l00803"></a>00803     <span class="keywordtype">double</span> angle ;
+<a name="l00804"></a>00804     <span class="keywordtype">float</span> radangle ;
+<a name="l00805"></a>00805     <span class="keywordtype">double</span> cd1_1, cd1_2, cd2_1, cd2_2 ;
+<a name="l00806"></a>00806     <span class="keywordtype">int</span> sign_swap = -1;
+<a name="l00807"></a>00807     <span class="keywordtype">char</span> firsttext[2*FILE_NAME_SZ] ;
+<a name="l00808"></a>00808 
+<a name="l00809"></a>00809     <span class="keywordtype">double</span> cdelt1=0;
+<a name="l00810"></a>00810     <span class="keywordtype">double</span> cdelt2=0;
+<a name="l00811"></a>00811     <span class="keywordtype">double</span> cdelt3=dispersion;
+<a name="l00812"></a>00812 
+<a name="l00813"></a>00813     <span class="keywordtype">double</span> crpix1=center_x;
+<a name="l00814"></a>00814     <span class="keywordtype">double</span> crpix2=center_y;
+<a name="l00815"></a>00815     <span class="keywordtype">int</span> crpix3=center_z;
+<a name="l00816"></a>00816 
+<a name="l00817"></a>00817     <span class="keywordtype">double</span> crval1=0;
+<a name="l00818"></a>00818     <span class="keywordtype">double</span> crval2=0;
+<a name="l00819"></a>00819     <span class="keywordtype">double</span> crval3=cenLambda;
+<a name="l00820"></a>00820 
+<a name="l00821"></a>00821 
+<a name="l00822"></a>00822     strcpy(firsttext, <span class="stringliteral">"sinfo_rec_objnod -f \0"</span>) ;
+<a name="l00823"></a>00823 
+<a name="l00824"></a>00824     pixelscale = sinfo_pfits_get_pixscale(plist)/2. ;
+<a name="l00825"></a>00825     ra = sinfo_pfits_get_ra(plist) ;
+<a name="l00826"></a>00826     dec = sinfo_pfits_get_DEC(plist) ;
+<a name="l00827"></a>00827 
+<a name="l00828"></a>00828     <span class="comment">//get better coordinate values</span>
+<a name="l00829"></a>00829     ra=sinfo_pfits_get_targ_alpha(plist);
+<a name="l00830"></a>00830     dec=sinfo_pfits_get_targ_delta(plist);
+<a name="l00831"></a>00831     <span class="comment">//sinfo_msg("ra=%f",ra);</span>
+<a name="l00832"></a>00832     <span class="comment">//sinfo_msg("dec=%f",dec);</span>
+<a name="l00833"></a>00833     ra=sinfo_hms2deg(ra);
+<a name="l00834"></a>00834     dec=sinfo_sess2deg(dec);
+<a name="l00835"></a>00835     <span class="comment">//sinfo_msg("ra=%f",ra);</span>
+<a name="l00836"></a>00836     <span class="comment">//sinfo_msg("dec=%f",dec);</span>
+<a name="l00837"></a>00837 
+<a name="l00838"></a>00838     crval1=ra;
+<a name="l00839"></a>00839     crval2=dec;
+<a name="l00840"></a>00840 
+<a name="l00841"></a>00841     angle = sinfo_pfits_get_posangle(plist) ;
+<a name="l00842"></a>00842     <span class="comment">/* in PUPIL data there is not posangle info: we reset the error */</span>
+<a name="l00843"></a>00843     <span class="keywordflow">if</span>(cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l00844"></a>00844        cpl_error_reset();
+<a name="l00845"></a>00845     }
+<a name="l00846"></a>00846     cdelt1=sign_swap*pixelscale / 3600.;
+<a name="l00847"></a>00847     cdelt2=         +pixelscale / 3600.;
+<a name="l00848"></a>00848 
+<a name="l00849"></a>00849 
+<a name="l00850"></a>00850     radangle = angle * PI_NUMB / 180. ;
+<a name="l00851"></a>00851     cd1_1 = +cdelt1*cos(radangle);
+<a name="l00852"></a>00852     cd1_2 = -cdelt2*sin(radangle);
+<a name="l00853"></a>00853     cd2_1 = +cdelt1*sin(radangle);
+<a name="l00854"></a>00854     cd2_2 = +cdelt2*cos(radangle);
+<a name="l00855"></a>00855 
+<a name="l00856"></a>00856 
+<a name="l00857"></a>00857     sinfo_set_coord1(&plist,crpix1,crval1,cdelt1);
+<a name="l00858"></a>00858     sinfo_set_coord2(&plist,crpix2,crval2,cdelt2);
+<a name="l00859"></a>00859     sinfo_set_coord3(&plist,crpix3,crval3,cdelt3);
+<a name="l00860"></a>00860     sinfo_set_cd_matrix2(&plist,cd1_1,cd1_2,cd2_1,cd2_2);
+<a name="l00861"></a>00861     sinfo_set_cd_matrix3(&plist,0,0,0,0,dispersion);
+<a name="l00862"></a>00862 
+<a name="l00863"></a>00863 
+<a name="l00864"></a>00864     }
+<a name="l00865"></a>00865 
+<a name="l00866"></a>00866 
+<a name="l00867"></a>00867 
+<a name="l00868"></a>00868 
+<a name="l00877"></a>00877 <span class="keyword">static</span> <span class="keywordtype">void</span>
+<a name="l00878"></a>00878 sinfo_set_coord1(cpl_propertylist** plist,
+<a name="l00879"></a>00879                  <span class="keyword">const</span> <span class="keywordtype">double</span> crpix1,
+<a name="l00880"></a>00880                  <span class="keyword">const</span> <span class="keywordtype">double</span> crval1,
+<a name="l00881"></a>00881                  <span class="keyword">const</span> <span class="keywordtype">double</span> cdelt1)
+<a name="l00882"></a>00882 {
+<a name="l00883"></a>00883    cpl_propertylist_erase_regexp(*plist, <span class="stringliteral">"^CTYPE1"</span>,0);
+<a name="l00884"></a>00884     cpl_propertylist_insert_after_string(*plist,<span class="stringliteral">"EXPTIME"</span>,<span class="stringliteral">"CTYPE1"</span>,<span class="stringliteral">"RA---TAN"</span>);
+<a name="l00885"></a>00885     cpl_propertylist_set_comment(*plist, <span class="stringliteral">"CTYPE1"</span>, <span class="stringliteral">"Projected Rectascension"</span>);
+<a name="l00886"></a>00886     cpl_propertylist_erase_regexp(*plist, <span class="stringliteral">"^CRPIX1"</span>,0);
+<a name="l00887"></a>00887     cpl_propertylist_insert_after_double(*plist,<span class="stringliteral">"CTYPE1"</span>,<span class="stringliteral">"CRPIX1"</span>, crpix1) ;
+<a name="l00888"></a>00888     cpl_propertylist_set_comment(*plist, <span class="stringliteral">"CRPIX1"</span>,<span class="stringliteral">"Reference pixel in RA"</span> ) ;
+<a name="l00889"></a>00889 
+<a name="l00890"></a>00890     cpl_propertylist_erase_regexp(*plist, <span class="stringliteral">"^CRVAL1"</span>,0);
+<a name="l00891"></a>00891     cpl_propertylist_insert_after_double(*plist, <span class="stringliteral">"CRPIX1"</span>, <span class="stringliteral">"CRVAL1"</span>, crval1 ) ;
+<a name="l00892"></a>00892     cpl_propertylist_set_comment(*plist, <span class="stringliteral">"CRVAL1"</span>,<span class="stringliteral">"Reference RA"</span> ) ;
+<a name="l00893"></a>00893 
+<a name="l00894"></a>00894     cpl_propertylist_erase_regexp(*plist, <span class="stringliteral">"^CDELT1"</span>,0);
+<a name="l00895"></a>00895     cpl_propertylist_insert_after_double(*plist,<span class="stringliteral">"CRVAL1"</span>,<span class="stringliteral">"CDELT1"</span>,cdelt1 ) ;
+<a name="l00896"></a>00896     cpl_propertylist_set_comment(*plist, <span class="stringliteral">"CDELT1"</span>,<span class="stringliteral">"pixel scale"</span> ) ;
+<a name="l00897"></a>00897 
+<a name="l00898"></a>00898     cpl_propertylist_erase_regexp(*plist, <span class="stringliteral">"^CUNIT1"</span>,0);
+<a name="l00899"></a>00899     cpl_propertylist_insert_after_string(*plist, <span class="stringliteral">"CDELT1"</span>,  <span class="stringliteral">"CUNIT1"</span>, <span class="stringliteral">"deg"</span> ) ;
+<a name="l00900"></a>00900     cpl_propertylist_set_comment(*plist, <span class="stringliteral">"CUNIT1"</span>,<span class="stringliteral">"RA-UNIT"</span> ) ;
+<a name="l00901"></a>00901 
+<a name="l00902"></a>00902     <span class="keywordflow">return</span>;
+<a name="l00903"></a>00903 }
+<a name="l00904"></a>00904 
+<a name="l00905"></a>00905 
+<a name="l00914"></a>00914 <span class="keyword">static</span> <span class="keywordtype">void</span>
+<a name="l00915"></a>00915 sinfo_set_coord2(cpl_propertylist** plist,
+<a name="l00916"></a>00916                  <span class="keyword">const</span> <span class="keywordtype">double</span> crpix2,
+<a name="l00917"></a>00917                  <span class="keyword">const</span> <span class="keywordtype">double</span> crval2,
+<a name="l00918"></a>00918                  <span class="keyword">const</span> <span class="keywordtype">double</span> cdelt2)
+<a name="l00919"></a>00919 {
+<a name="l00920"></a>00920     cpl_propertylist_erase_regexp(*plist, <span class="stringliteral">"^CTYPE2"</span>,0);
+<a name="l00921"></a>00921     cpl_propertylist_insert_after_string(*plist,<span class="stringliteral">"CUNIT1"</span>,<span class="stringliteral">"CTYPE2"</span>,<span class="stringliteral">"DEC--TAN"</span>);
+<a name="l00922"></a>00922     cpl_propertylist_set_comment(*plist, <span class="stringliteral">"CTYPE2"</span>, <span class="stringliteral">"Projected Declination"</span>) ;
+<a name="l00923"></a>00923 
+<a name="l00924"></a>00924     cpl_propertylist_erase_regexp(*plist, <span class="stringliteral">"^CRPIX2"</span>,0);
+<a name="l00925"></a>00925     cpl_propertylist_insert_after_double(*plist,<span class="stringliteral">"CTYPE2"</span>,<span class="stringliteral">"CRPIX2"</span>,crpix2 ) ;
+<a name="l00926"></a>00926     cpl_propertylist_set_comment(*plist, <span class="stringliteral">"CRPIX2"</span>, <span class="stringliteral">"Reference pixel in DEC"</span>) ;
+<a name="l00927"></a>00927 
+<a name="l00928"></a>00928     cpl_propertylist_erase_regexp(*plist,<span class="stringliteral">"^CRVAL2"</span>,0);
+<a name="l00929"></a>00929     cpl_propertylist_insert_after_double(*plist,<span class="stringliteral">"CRPIX2"</span>,<span class="stringliteral">"CRVAL2"</span>,crval2) ;
+<a name="l00930"></a>00930     cpl_propertylist_set_comment(*plist,<span class="stringliteral">"CRVAL2"</span>,<span class="stringliteral">"Reference DEC"</span>) ;
+<a name="l00931"></a>00931 
+<a name="l00932"></a>00932     cpl_propertylist_erase_regexp(*plist,<span class="stringliteral">"^CDELT2"</span>,0);
+<a name="l00933"></a>00933     cpl_propertylist_insert_after_double(*plist,<span class="stringliteral">"CRVAL2"</span>,<span class="stringliteral">"CDELT2"</span>,cdelt2 ) ;
+<a name="l00934"></a>00934     cpl_propertylist_set_comment(*plist,<span class="stringliteral">"CDELT2"</span>,<span class="stringliteral">"pixel scale"</span>) ;
+<a name="l00935"></a>00935 
+<a name="l00936"></a>00936     cpl_propertylist_erase_regexp(*plist,<span class="stringliteral">"^CUNIT2"</span>,0);
+<a name="l00937"></a>00937     cpl_propertylist_insert_after_string(*plist,<span class="stringliteral">"CDELT2"</span>,<span class="stringliteral">"CUNIT2"</span>, <span class="stringliteral">"deg"</span> ) ;
+<a name="l00938"></a>00938     cpl_propertylist_set_comment(*plist,<span class="stringliteral">"CUNIT2"</span>,<span class="stringliteral">"DEC-UNIT"</span>) ;
+<a name="l00939"></a>00939 
+<a name="l00940"></a>00940 
+<a name="l00941"></a>00941 }
+<a name="l00942"></a>00942 
+<a name="l00943"></a>00943 
+<a name="l00944"></a>00944 
+<a name="l00953"></a>00953 <span class="keyword">static</span> <span class="keywordtype">void</span>
+<a name="l00954"></a>00954 sinfo_set_coord3(cpl_propertylist** plist,
+<a name="l00955"></a>00955                  <span class="keyword">const</span> <span class="keywordtype">int</span> crpix3,
+<a name="l00956"></a>00956                  <span class="keyword">const</span> <span class="keywordtype">double</span> crval3,
+<a name="l00957"></a>00957                  <span class="keyword">const</span> <span class="keywordtype">double</span> cdelt3)
+<a name="l00958"></a>00958 {
+<a name="l00959"></a>00959     cpl_propertylist_erase_regexp(*plist, <span class="stringliteral">"^CTYPE3"</span>,0);
+<a name="l00960"></a>00960     cpl_propertylist_insert_after_string(*plist,<span class="stringliteral">"EXPTIME"</span>, <span class="stringliteral">"CTYPE3"</span>, <span class="stringliteral">"WAVE"</span> ) ;
+<a name="l00961"></a>00961     cpl_propertylist_set_comment(*plist,<span class="stringliteral">"CTYPE3"</span>,<span class="stringliteral">"wavelength axis in microns"</span>) ;
+<a name="l00962"></a>00962 
+<a name="l00963"></a>00963     cpl_propertylist_erase_regexp(*plist, <span class="stringliteral">"^CRPIX3"</span>,0);
+<a name="l00964"></a>00964     cpl_propertylist_insert_after_double(*plist,<span class="stringliteral">"CTYPE3"</span>,<span class="stringliteral">"CRPIX3"</span>, (<span class="keywordtype">double</span>)crpix3 ) ;
+<a name="l00965"></a>00965     cpl_propertylist_set_comment(*plist, <span class="stringliteral">"CRPIX3"</span>, <span class="stringliteral">"Reference pixel in z"</span>) ;
+<a name="l00966"></a>00966 
+<a name="l00967"></a>00967     cpl_propertylist_erase_regexp(*plist, <span class="stringliteral">"^CRVAL3"</span>,0);
+<a name="l00968"></a>00968     cpl_propertylist_insert_after_double(*plist,<span class="stringliteral">"CRPIX3"</span>, <span class="stringliteral">"CRVAL3"</span>, crval3) ;
+<a name="l00969"></a>00969     cpl_propertylist_set_comment(*plist, <span class="stringliteral">"CRVAL3"</span>, <span class="stringliteral">"central wavelength"</span>) ;
+<a name="l00970"></a>00970 
+<a name="l00971"></a>00971     cpl_propertylist_erase_regexp(*plist, <span class="stringliteral">"^CDELT3"</span>,0);
+<a name="l00972"></a>00972 
+<a name="l00973"></a>00973     cpl_propertylist_insert_after_double(*plist,<span class="stringliteral">"CRVAL3"</span>,<span class="stringliteral">"CDELT3"</span>,cdelt3) ;
+<a name="l00974"></a>00974     cpl_propertylist_set_comment(*plist, <span class="stringliteral">"CDELT3"</span>, <span class="stringliteral">"microns per pixel"</span>) ;
+<a name="l00975"></a>00975 
+<a name="l00976"></a>00976     cpl_propertylist_erase_regexp(*plist, <span class="stringliteral">"^CUNIT3"</span>,0);
+<a name="l00977"></a>00977     cpl_propertylist_insert_after_string(*plist,<span class="stringliteral">"CDELT3"</span>, <span class="stringliteral">"CUNIT3"</span>, <span class="stringliteral">"um"</span> ) ;
+<a name="l00978"></a>00978     cpl_propertylist_set_comment(*plist, <span class="stringliteral">"CUNIT3"</span>,  <span class="stringliteral">"spectral unit"</span> ) ;
+<a name="l00979"></a>00979 
+<a name="l00980"></a>00980     cpl_propertylist_erase_regexp(*plist, <span class="stringliteral">"^SPECSYS"</span>,0);
+<a name="l00981"></a>00981     cpl_propertylist_insert_after_string(*plist,<span class="stringliteral">"CUNIT3"</span>, <span class="stringliteral">"SPECSYS"</span>, <span class="stringliteral">"TOPOCENT"</span> ) ;
+<a name="l00982"></a>00982     cpl_propertylist_set_comment(*plist, <span class="stringliteral">"SPECSYS"</span>,  <span class="stringliteral">"Coordinate reference frame"</span> ) ;
+<a name="l00983"></a>00983 }
+<a name="l00984"></a>00984 
+<a name="l00985"></a>00985 
+<a name="l00996"></a>00996 <span class="keyword">static</span> <span class="keywordtype">void</span>
+<a name="l00997"></a>00997 sinfo_set_cd_matrix2(cpl_propertylist** plist,
+<a name="l00998"></a>00998             <span class="keyword">const</span> <span class="keywordtype">double</span> cd1_1,
+<a name="l00999"></a>00999             <span class="keyword">const</span> <span class="keywordtype">double</span> cd1_2,
+<a name="l01000"></a>01000             <span class="keyword">const</span> <span class="keywordtype">double</span> cd2_1,
+<a name="l01001"></a>01001             <span class="keyword">const</span> <span class="keywordtype">double</span> cd2_2)
+<a name="l01002"></a>01002 {
+<a name="l01003"></a>01003 
+<a name="l01004"></a>01004     check_nomsg(cpl_propertylist_erase_regexp(*plist, <span class="stringliteral">"^CD1_1"</span>,0));
+<a name="l01005"></a>01005     check_nomsg(cpl_propertylist_insert_after_double(*plist,<span class="stringliteral">"EXPTIME"</span>,
+<a name="l01006"></a>01006                              <span class="stringliteral">"CD1_1"</span>, cd1_1 )) ;
+<a name="l01007"></a>01007     check_nomsg(cpl_propertylist_set_comment(*plist, <span class="stringliteral">"CD1_1"</span>,
+<a name="l01008"></a>01008                          <span class="stringliteral">"CD rotation matrix"</span> )) ;
+<a name="l01009"></a>01009 
+<a name="l01010"></a>01010     check_nomsg(cpl_propertylist_erase_regexp(*plist, <span class="stringliteral">"^CD1_2"</span>,0));
+<a name="l01011"></a>01011     check_nomsg(cpl_propertylist_insert_after_double(*plist, <span class="stringliteral">"CD1_1"</span>,
+<a name="l01012"></a>01012                              <span class="stringliteral">"CD1_2"</span>, cd1_2 )) ;
+<a name="l01013"></a>01013     check_nomsg(cpl_propertylist_set_comment(*plist, <span class="stringliteral">"CD1_2"</span>,
+<a name="l01014"></a>01014                          <span class="stringliteral">"CD rotation matrix"</span> )) ;
+<a name="l01015"></a>01015 
+<a name="l01016"></a>01016     check_nomsg(cpl_propertylist_erase_regexp(*plist, <span class="stringliteral">"^CD2_1"</span>,0));
+<a name="l01017"></a>01017     check_nomsg(cpl_propertylist_insert_after_double(*plist, <span class="stringliteral">"CD1_2"</span>,
+<a name="l01018"></a>01018                              <span class="stringliteral">"CD2_1"</span>, cd2_1 )) ;
+<a name="l01019"></a>01019     check_nomsg(cpl_propertylist_set_comment(*plist, <span class="stringliteral">"CD2_1"</span>,
+<a name="l01020"></a>01020                          <span class="stringliteral">"CD rotation matrix"</span> )) ;
+<a name="l01021"></a>01021 
+<a name="l01022"></a>01022     check_nomsg(cpl_propertylist_erase_regexp(*plist, <span class="stringliteral">"^CD2_2"</span>,0));
+<a name="l01023"></a>01023     check_nomsg(cpl_propertylist_insert_after_double(*plist, <span class="stringliteral">"CD2_1"</span>,
+<a name="l01024"></a>01024                              <span class="stringliteral">"CD2_2"</span>, cd2_2 )) ;
+<a name="l01025"></a>01025     check_nomsg(cpl_propertylist_set_comment(*plist, <span class="stringliteral">"CD2_2"</span>,
+<a name="l01026"></a>01026                          <span class="stringliteral">"CD rotation matrix"</span> )) ;
+<a name="l01027"></a>01027 
+<a name="l01028"></a>01028  cleanup:
+<a name="l01029"></a>01029     <span class="keywordflow">return</span>;
+<a name="l01030"></a>01030 
+<a name="l01031"></a>01031 
+<a name="l01032"></a>01032 }
+<a name="l01033"></a>01033 
+<a name="l01034"></a>01034 
+<a name="l01047"></a>01047 <span class="keyword">static</span> <span class="keywordtype">void</span>
+<a name="l01048"></a>01048 sinfo_set_cd_matrix3(cpl_propertylist** plist,
+<a name="l01049"></a>01049                      <span class="keyword">const</span> <span class="keywordtype">double</span> cd1_3,
+<a name="l01050"></a>01050                      <span class="keyword">const</span> <span class="keywordtype">double</span> cd2_3,
+<a name="l01051"></a>01051                      <span class="keyword">const</span> <span class="keywordtype">double</span> cd3_1,
+<a name="l01052"></a>01052                      <span class="keyword">const</span> <span class="keywordtype">double</span> cd3_2,
+<a name="l01053"></a>01053                      <span class="keyword">const</span> <span class="keywordtype">double</span> cd3_3)
+<a name="l01054"></a>01054 {
+<a name="l01055"></a>01055 
+<a name="l01056"></a>01056 
+<a name="l01057"></a>01057     check_nomsg(cpl_propertylist_erase_regexp(*plist, <span class="stringliteral">"^CD1_3"</span>,0));
+<a name="l01058"></a>01058     check_nomsg(cpl_propertylist_insert_after_double(*plist,<span class="stringliteral">"EXPTIME"</span>,
+<a name="l01059"></a>01059                              <span class="stringliteral">"CD1_3"</span>, cd1_3 )) ;
+<a name="l01060"></a>01060     check_nomsg(cpl_propertylist_set_comment(*plist, <span class="stringliteral">"CD1_3"</span>,
+<a name="l01061"></a>01061                          <span class="stringliteral">"CD rotation matrix"</span> )) ;
+<a name="l01062"></a>01062 
+<a name="l01063"></a>01063 
+<a name="l01064"></a>01064     check_nomsg(cpl_propertylist_erase_regexp(*plist, <span class="stringliteral">"^CD2_3"</span>,0));
+<a name="l01065"></a>01065     check_nomsg(cpl_propertylist_insert_after_double(*plist,<span class="stringliteral">"CD1_3"</span>,
+<a name="l01066"></a>01066                              <span class="stringliteral">"CD2_3"</span>, cd2_3 )) ;
+<a name="l01067"></a>01067     check_nomsg(cpl_propertylist_set_comment(*plist, <span class="stringliteral">"CD2_3"</span>,
+<a name="l01068"></a>01068                          <span class="stringliteral">"CD rotation matrix"</span> )) ;
+<a name="l01069"></a>01069 
+<a name="l01070"></a>01070 
+<a name="l01071"></a>01071 
+<a name="l01072"></a>01072     check_nomsg(cpl_propertylist_erase_regexp(*plist, <span class="stringliteral">"^CD3_1"</span>,0));
+<a name="l01073"></a>01073     check_nomsg(cpl_propertylist_insert_after_double(*plist,<span class="stringliteral">"CD2_3"</span>,
+<a name="l01074"></a>01074                              <span class="stringliteral">"CD3_1"</span>, cd3_1 )) ;
+<a name="l01075"></a>01075     check_nomsg(cpl_propertylist_set_comment(*plist, <span class="stringliteral">"CD3_1"</span>,
+<a name="l01076"></a>01076                          <span class="stringliteral">"CD rotation matrix"</span> )) ;
+<a name="l01077"></a>01077 
+<a name="l01078"></a>01078     check_nomsg(cpl_propertylist_erase_regexp(*plist, <span class="stringliteral">"^CD3_2"</span>,0));
+<a name="l01079"></a>01079     check_nomsg(cpl_propertylist_insert_after_double(*plist, <span class="stringliteral">"CD3_1"</span>,
+<a name="l01080"></a>01080                              <span class="stringliteral">"CD3_2"</span>, cd3_2 )) ;
+<a name="l01081"></a>01081     check_nomsg(cpl_propertylist_set_comment(*plist, <span class="stringliteral">"CD3_2"</span>,
+<a name="l01082"></a>01082                          <span class="stringliteral">"CD rotation matrix"</span> )) ;
+<a name="l01083"></a>01083 
+<a name="l01084"></a>01084     check_nomsg(cpl_propertylist_erase_regexp(*plist, <span class="stringliteral">"^CD3_3"</span>,0));
+<a name="l01085"></a>01085     check_nomsg(cpl_propertylist_insert_after_double(*plist, <span class="stringliteral">"CD3_2"</span>,
+<a name="l01086"></a>01086                              <span class="stringliteral">"CD3_3"</span>, cd3_3 )) ;
+<a name="l01087"></a>01087     check_nomsg(cpl_propertylist_set_comment(*plist, <span class="stringliteral">"CD3_3"</span>,
+<a name="l01088"></a>01088                          <span class="stringliteral">"CD rotation matrix"</span> )) ;
+<a name="l01089"></a>01089 
+<a name="l01090"></a>01090  cleanup:
+<a name="l01091"></a>01091     <span class="keywordflow">return</span>;
+<a name="l01092"></a>01092 
+<a name="l01093"></a>01093 
+<a name="l01094"></a>01094 }
+<a name="l01095"></a>01095 
+<a name="l01096"></a>01096 
+<a name="l01105"></a>01105 <span class="keyword">static</span> <span class="keywordtype">void</span>
+<a name="l01106"></a>01106 sinfo_set_spect_coord1(cpl_propertylist** plist,
+<a name="l01107"></a>01107                  <span class="keyword">const</span> <span class="keywordtype">int</span> crpix1,
+<a name="l01108"></a>01108                  <span class="keyword">const</span> <span class="keywordtype">double</span> crval1,
+<a name="l01109"></a>01109                  <span class="keyword">const</span> <span class="keywordtype">double</span> cdelt1)
+<a name="l01110"></a>01110 {
+<a name="l01111"></a>01111 
+<a name="l01112"></a>01112     cpl_propertylist_erase_regexp(*plist, <span class="stringliteral">"^CTYPE1"</span>,0);
+<a name="l01113"></a>01113     cpl_propertylist_insert_after_string(*plist,<span class="stringliteral">"EXPTIME"</span>,  <span class="stringliteral">"CTYPE1"</span>, <span class="stringliteral">"PIXEL"</span>);
+<a name="l01114"></a>01114     cpl_propertylist_set_comment(*plist, <span class="stringliteral">"CTYPE1"</span>, <span class="stringliteral">"Pixel coordinate system."</span>);
+<a name="l01115"></a>01115 
+<a name="l01116"></a>01116     cpl_propertylist_erase_regexp(*plist, <span class="stringliteral">"^CRPIX1"</span>,0);
+<a name="l01117"></a>01117     cpl_propertylist_insert_after_double(*plist, <span class="stringliteral">"CTYPE1"</span>,  <span class="stringliteral">"CRPIX1"</span>, (<span class="keywordtype">double</span>)crpix1 ) ;
+<a name="l01118"></a>01118     cpl_propertylist_set_comment(*plist, <span class="stringliteral">"CRPIX1"</span>, <span class="stringliteral">"Reference pixel in x"</span>) ;
+<a name="l01119"></a>01119 
+<a name="l01120"></a>01120     cpl_propertylist_erase_regexp(*plist, <span class="stringliteral">"^CRVAL1"</span>,0);
+<a name="l01121"></a>01121     cpl_propertylist_insert_after_double(*plist,<span class="stringliteral">"CRPIX1"</span>,  <span class="stringliteral">"CRVAL1"</span>, crval1 ) ;
+<a name="l01122"></a>01122     cpl_propertylist_set_comment(*plist, <span class="stringliteral">"CRVAL1"</span>, <span class="stringliteral">"value of ref pixel."</span>) ;
+<a name="l01123"></a>01123 
+<a name="l01124"></a>01124     cpl_propertylist_erase_regexp(*plist, <span class="stringliteral">"^CDELT1"</span>,0);
+<a name="l01125"></a>01125     cpl_propertylist_insert_after_double(*plist,<span class="stringliteral">"CRVAL1"</span>,  <span class="stringliteral">"CDELT1"</span>, cdelt1 ) ;
+<a name="l01126"></a>01126     cpl_propertylist_set_comment(*plist,<span class="stringliteral">"CDELT1"</span>, <span class="stringliteral">"pixel scale"</span>) ;
+<a name="l01127"></a>01127 
+<a name="l01128"></a>01128 
+<a name="l01129"></a>01129     cpl_propertylist_erase_regexp(*plist, <span class="stringliteral">"^CUNIT1"</span>,0);
+<a name="l01130"></a>01130     cpl_propertylist_insert_after_string(*plist,<span class="stringliteral">"CDELT1"</span>,  <span class="stringliteral">"CUNIT1"</span>, <span class="stringliteral">"Pixel"</span> );
+<a name="l01131"></a>01131     cpl_propertylist_set_comment(*plist, <span class="stringliteral">"CUNIT1"</span>,  <span class="stringliteral">"spectral unit"</span> );
+<a name="l01132"></a>01132 
+<a name="l01133"></a>01133 }
+<a name="l01134"></a>01134 
+<a name="l01135"></a>01135 
+<a name="l01136"></a>01136 
+<a name="l01137"></a>01137 
+<a name="l01138"></a>01138 
+<a name="l01147"></a>01147 <span class="keyword">static</span> <span class="keywordtype">void</span>
+<a name="l01148"></a>01148 sinfo_set_spect_coord2(cpl_propertylist** plist,
+<a name="l01149"></a>01149                  <span class="keyword">const</span> <span class="keywordtype">int</span> crpix2,
+<a name="l01150"></a>01150                  <span class="keyword">const</span> <span class="keywordtype">double</span> crval2,
+<a name="l01151"></a>01151                  <span class="keyword">const</span> <span class="keywordtype">double</span> cdelt2)
+<a name="l01152"></a>01152 {
+<a name="l01153"></a>01153 
+<a name="l01154"></a>01154     cpl_propertylist_erase_regexp(*plist, <span class="stringliteral">"^CTYPE2"</span>,0);
+<a name="l01155"></a>01155     cpl_propertylist_insert_after_string(*plist, <span class="stringliteral">"EXPTIME"</span>,<span class="stringliteral">"CTYPE2"</span>,<span class="stringliteral">"WAVE"</span> );
+<a name="l01156"></a>01156     cpl_propertylist_set_comment(*plist,<span class="stringliteral">"CTYPE2"</span>,<span class="stringliteral">"wavelength axis in microns"</span>);
+<a name="l01157"></a>01157 
+<a name="l01158"></a>01158     cpl_propertylist_erase_regexp(*plist, <span class="stringliteral">"^CRPIX2"</span>,0);
+<a name="l01159"></a>01159     cpl_propertylist_insert_after_double(*plist, <span class="stringliteral">"CTYPE2"</span>,  <span class="stringliteral">"CRPIX2"</span>,(<span class="keywordtype">double</span>)crpix2 ) ;
+<a name="l01160"></a>01160     cpl_propertylist_set_comment(*plist, <span class="stringliteral">"CRPIX2"</span>, <span class="stringliteral">"Reference pixel in x"</span>) ;
+<a name="l01161"></a>01161 
+<a name="l01162"></a>01162     cpl_propertylist_erase_regexp(*plist, <span class="stringliteral">"^CRVAL2"</span>,0);
+<a name="l01163"></a>01163     cpl_propertylist_insert_after_double(*plist, <span class="stringliteral">"CRPIX2"</span>,<span class="stringliteral">"CRVAL2"</span>,crval2 ) ;
+<a name="l01164"></a>01164     cpl_propertylist_set_comment(*plist,<span class="stringliteral">"CRVAL2"</span>, <span class="stringliteral">"central wavelength"</span>) ;
+<a name="l01165"></a>01165 
+<a name="l01166"></a>01166     cpl_propertylist_erase_regexp(*plist, <span class="stringliteral">"^CDELT2"</span>,0);
+<a name="l01167"></a>01167     cpl_propertylist_insert_after_double(*plist, <span class="stringliteral">"CRVAL2"</span>, <span class="stringliteral">"CDELT2"</span>,cdelt2);
+<a name="l01168"></a>01168     cpl_propertylist_set_comment(*plist,<span class="stringliteral">"CDELT2"</span>, <span class="stringliteral">"microns per pixel"</span>);
+<a name="l01169"></a>01169 
+<a name="l01170"></a>01170     cpl_propertylist_erase_regexp(*plist, <span class="stringliteral">"^CUNIT2"</span>,0);
+<a name="l01171"></a>01171     cpl_propertylist_insert_after_string(*plist,<span class="stringliteral">"CDELT2"</span>,  <span class="stringliteral">"CUNIT2"</span>, <span class="stringliteral">"um"</span>);
+<a name="l01172"></a>01172     cpl_propertylist_set_comment(*plist, <span class="stringliteral">"CUNIT2"</span>,  <span class="stringliteral">"spectral unit"</span> );
+<a name="l01173"></a>01173 
+<a name="l01174"></a>01174 
+<a name="l01175"></a>01175 }
+<a name="l01185"></a>01185 <span class="keyword">static</span> <span class="keywordtype">void</span>
+<a name="l01186"></a>01186 sinfo_new_change_plist_spectrum (cpl_propertylist * plist,
+<a name="l01187"></a>01187                 <span class="keywordtype">double</span> cenLambda,
+<a name="l01188"></a>01188                 <span class="keywordtype">double</span> dispersion,
+<a name="l01189"></a>01189                 <span class="keywordtype">int</span>   cenpix)
+<a name="l01190"></a>01190 {
+<a name="l01191"></a>01191 
+<a name="l01192"></a>01192   <span class="keywordtype">int</span> crpix1=1;
+<a name="l01193"></a>01193   <span class="keywordtype">double</span> crval1=1;
+<a name="l01194"></a>01194   <span class="keywordtype">double</span> cdelt1=1;
+<a name="l01195"></a>01195 
+<a name="l01196"></a>01196   <span class="keywordtype">int</span> crpix2=cenpix;
+<a name="l01197"></a>01197   <span class="keywordtype">double</span> crval2=cenLambda;
+<a name="l01198"></a>01198   <span class="keywordtype">double</span> cdelt2=dispersion;
+<a name="l01199"></a>01199 
+<a name="l01200"></a>01200 
+<a name="l01201"></a>01201 
+<a name="l01202"></a>01202   cpl_propertylist_erase_regexp(plist, <span class="stringliteral">"^CTYPE3"</span>,0);
+<a name="l01203"></a>01203   cpl_propertylist_erase_regexp(plist, <span class="stringliteral">"^CRPIX3"</span>,0);
+<a name="l01204"></a>01204   cpl_propertylist_erase_regexp(plist, <span class="stringliteral">"^CRVAL3"</span>,0);
+<a name="l01205"></a>01205   cpl_propertylist_erase_regexp(plist, <span class="stringliteral">"^CDELT3"</span>,0);
+<a name="l01206"></a>01206   cpl_propertylist_erase_regexp(plist, <span class="stringliteral">"^CUNIT3"</span>,0);
+<a name="l01207"></a>01207 
+<a name="l01208"></a>01208   cpl_propertylist_erase_regexp(plist, <span class="stringliteral">"^CTYPE2"</span>,0);
+<a name="l01209"></a>01209   cpl_propertylist_erase_regexp(plist, <span class="stringliteral">"^CRPIX2"</span>,0);
+<a name="l01210"></a>01210   cpl_propertylist_erase_regexp(plist, <span class="stringliteral">"^CRVAL2"</span>,0);
+<a name="l01211"></a>01211   cpl_propertylist_erase_regexp(plist, <span class="stringliteral">"^CDELT2"</span>,0);
+<a name="l01212"></a>01212   cpl_propertylist_erase_regexp(plist, <span class="stringliteral">"^CUNIT2"</span>,0);
+<a name="l01213"></a>01213 
+<a name="l01214"></a>01214 
+<a name="l01215"></a>01215   cpl_propertylist_erase_regexp(plist, <span class="stringliteral">"^CD1_1"</span>,0);
+<a name="l01216"></a>01216   cpl_propertylist_erase_regexp(plist, <span class="stringliteral">"^CD1_2"</span>,0);
+<a name="l01217"></a>01217   cpl_propertylist_erase_regexp(plist, <span class="stringliteral">"^CD2_1"</span>,0);
+<a name="l01218"></a>01218   cpl_propertylist_erase_regexp(plist, <span class="stringliteral">"^CD2_2"</span>,0);
+<a name="l01219"></a>01219 
+<a name="l01220"></a>01220 
+<a name="l01221"></a>01221 
+<a name="l01222"></a>01222 
+<a name="l01223"></a>01223   sinfo_set_spect_coord1(&plist,crpix1,crval1,cdelt1);
+<a name="l01224"></a>01224   sinfo_set_spect_coord2(&plist,crpix2,crval2,cdelt2);
+<a name="l01225"></a>01225 
+<a name="l01226"></a>01226 
+<a name="l01227"></a>01227 
+<a name="l01228"></a>01228 }
+<a name="l01238"></a>01238 <span class="keyword">static</span> <span class="keywordtype">void</span>
+<a name="l01239"></a>01239 sinfo_new_change_plist_image (cpl_propertylist * plist,
+<a name="l01240"></a>01240             <span class="keywordtype">float</span> center_x,
+<a name="l01241"></a>01241             <span class="keywordtype">float</span> center_y )
+<a name="l01242"></a>01242 {
+<a name="l01243"></a>01243 
+<a name="l01244"></a>01244     <span class="keywordtype">float</span> pixelscale ;
+<a name="l01245"></a>01245     <span class="keywordtype">double</span> ra ;
+<a name="l01246"></a>01246     <span class="keywordtype">double</span> dec ;
+<a name="l01247"></a>01247     <span class="keywordtype">double</span> angle ;
+<a name="l01248"></a>01248     <span class="keywordtype">float</span> radangle ;
+<a name="l01249"></a>01249     <span class="keywordtype">float</span> cd1_1, cd1_2, cd2_1, cd2_2 ;
+<a name="l01250"></a>01250     <span class="keywordtype">char</span> firsttext[2*FILE_NAME_SZ] ;
+<a name="l01251"></a>01251     <span class="keywordtype">int</span> sign_swap = -1;
+<a name="l01252"></a>01252 
+<a name="l01253"></a>01253 
+<a name="l01254"></a>01254     <span class="keywordtype">double</span> cdelt1=0;
+<a name="l01255"></a>01255     <span class="keywordtype">double</span> cdelt2=0;
+<a name="l01256"></a>01256 
+<a name="l01257"></a>01257     <span class="keywordtype">double</span> crpix1=center_x;
+<a name="l01258"></a>01258     <span class="keywordtype">double</span> crpix2=center_y;
+<a name="l01259"></a>01259 
+<a name="l01260"></a>01260     <span class="keywordtype">double</span> crval1=0;
+<a name="l01261"></a>01261     <span class="keywordtype">double</span> crval2=0;
+<a name="l01262"></a>01262 
+<a name="l01263"></a>01263 
+<a name="l01264"></a>01264 
+<a name="l01265"></a>01265 
+<a name="l01266"></a>01266     strcpy(firsttext, <span class="stringliteral">"sinfo_rec_objnod -f \0"</span>) ;
+<a name="l01267"></a>01267 
+<a name="l01268"></a>01268     pixelscale = sinfo_pfits_get_pixscale(plist)/2. ;
+<a name="l01269"></a>01269     ra = sinfo_pfits_get_ra(plist) ;
+<a name="l01270"></a>01270     dec = sinfo_pfits_get_DEC(plist) ;
+<a name="l01271"></a>01271 
+<a name="l01272"></a>01272 
+<a name="l01273"></a>01273 
+<a name="l01274"></a>01274     <span class="comment">//get better coordinate values</span>
+<a name="l01275"></a>01275     ra=sinfo_pfits_get_targ_alpha(plist);
+<a name="l01276"></a>01276     dec=sinfo_pfits_get_targ_delta(plist);
+<a name="l01277"></a>01277     ra=sinfo_hms2deg(ra);
+<a name="l01278"></a>01278     dec=sinfo_sess2deg(dec);
+<a name="l01279"></a>01279 
+<a name="l01280"></a>01280 
+<a name="l01281"></a>01281 
+<a name="l01282"></a>01282     crval1=ra;
+<a name="l01283"></a>01283     crval2=dec;
+<a name="l01284"></a>01284 
+<a name="l01285"></a>01285     angle = sinfo_pfits_get_posangle(plist) ;
+<a name="l01286"></a>01286     <span class="comment">/* in PUPIL data there is not posangle info: we reset the error */</span>
+<a name="l01287"></a>01287     <span class="keywordflow">if</span>(cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l01288"></a>01288        cpl_error_reset();
+<a name="l01289"></a>01289     }
+<a name="l01290"></a>01290 
+<a name="l01291"></a>01291     radangle = angle * PI_NUMB / 180. ;
+<a name="l01292"></a>01292 
+<a name="l01293"></a>01293     cdelt1=sign_swap * pixelscale / 3600. ;
+<a name="l01294"></a>01294     cdelt2=            pixelscale / 3600. ;
+<a name="l01295"></a>01295 
+<a name="l01296"></a>01296 
+<a name="l01297"></a>01297     cd1_1 = +cdelt1*cos(radangle) ;
+<a name="l01298"></a>01298     cd1_2 = -cdelt2*sin(radangle) ;
+<a name="l01299"></a>01299     cd2_1 = +cdelt1*sin(radangle) ;
+<a name="l01300"></a>01300     cd2_2 = +cdelt2*cos(radangle) ;
+<a name="l01301"></a>01301 
+<a name="l01302"></a>01302 
+<a name="l01303"></a>01303 
+<a name="l01304"></a>01304 
+<a name="l01305"></a>01305 
+<a name="l01306"></a>01306     check_nomsg(sinfo_set_coord1(&plist,crpix1,crval1,cdelt1));
+<a name="l01307"></a>01307     check_nomsg(sinfo_set_coord2(&plist,crpix2,crval2,cdelt2));
+<a name="l01308"></a>01308     check_nomsg(sinfo_set_cd_matrix2(&plist,cd1_1,cd1_2,cd2_1,cd2_2));
+<a name="l01309"></a>01309 
+<a name="l01310"></a>01310 
+<a name="l01311"></a>01311  cleanup:
+<a name="l01312"></a>01312     <span class="keywordflow">return</span>;
+<a name="l01313"></a>01313 }
+<a name="l01314"></a>01314 
+<a name="l01322"></a>01322 cpl_imagelist**
+<a name="l01323"></a>01323 sinfo_new_sinfoni_correct_median(cpl_imagelist** cubes, <span class="keyword">const</span> <span class="keywordtype">int</span> n_cubes)
+<a name="l01324"></a>01324 {
+<a name="l01325"></a>01325   <span class="keywordtype">int</span> i=0;
+<a name="l01326"></a>01326   cpl_imagelist** cubes_cor=NULL;
+<a name="l01327"></a>01327   <span class="keywordtype">double</span> local_median=0;
+<a name="l01328"></a>01328   <span class="keywordtype">int</span> z=0;
+<a name="l01329"></a>01329   cpl_image* i_img=NULL;
+<a name="l01330"></a>01330   cpl_image* o_img=NULL;
+<a name="l01331"></a>01331 
+<a name="l01332"></a>01332 
+<a name="l01333"></a>01333   <span class="keywordflow">if</span> ( cubes == NULL ) {
+<a name="l01334"></a>01334     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"no cube list given!"</span>) ;
+<a name="l01335"></a>01335     <span class="keywordflow">return</span> NULL ;
+<a name="l01336"></a>01336   }
+<a name="l01337"></a>01337   <span class="keywordflow">if</span> ( n_cubes <= 0 ) {
+<a name="l01338"></a>01338     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"wrong number of data cubes in list!"</span>) ;
+<a name="l01339"></a>01339     <span class="keywordflow">return</span> NULL ;
+<a name="l01340"></a>01340   }
+<a name="l01341"></a>01341 
+<a name="l01342"></a>01342   cubes_cor = (cpl_imagelist**) cpl_calloc (n_cubes, <span class="keyword">sizeof</span> (cpl_imagelist*)) ;
+<a name="l01343"></a>01343 
+<a name="l01344"></a>01344   <span class="keywordflow">for</span> ( i = 0 ; i < n_cubes ; i++ ) {
+<a name="l01345"></a>01345     cubes_cor[i] = cpl_imagelist_new();
+<a name="l01346"></a>01346     <span class="keywordflow">for</span>(z=0;z< cpl_imagelist_get_size(cubes[i]); z++) {
+<a name="l01347"></a>01347       i_img=cpl_imagelist_get(cubes[i],z);
+<a name="l01348"></a>01348       local_median=cpl_image_get_median(i_img);;
+<a name="l01349"></a>01349       o_img=cpl_image_duplicate(i_img);
+<a name="l01350"></a>01350       <span class="keywordflow">if</span>(!isnan(local_median)) {
+<a name="l01351"></a>01351         cpl_image_subtract_scalar(o_img,local_median);
+<a name="l01352"></a>01352        }
+<a name="l01353"></a>01353       cpl_imagelist_set(cubes_cor[i],o_img,z);
+<a name="l01354"></a>01354     }
+<a name="l01355"></a>01355   }
+<a name="l01356"></a>01356 
+<a name="l01357"></a>01357   <span class="keywordflow">return</span> cubes_cor;
+<a name="l01358"></a>01358 }
+<a name="l01359"></a>01359 
+<a name="l01366"></a>01366 <span class="keywordtype">int</span> sinfo_new_sinfoni_correct_median_it(cpl_imagelist** inp)
+<a name="l01367"></a>01367 {
+<a name="l01368"></a>01368 
+<a name="l01369"></a>01369   <span class="keywordtype">double</span> local_median=0;
+<a name="l01370"></a>01370   <span class="keywordtype">int</span> z=0;
+<a name="l01371"></a>01371   cpl_image* img=NULL;
+<a name="l01372"></a>01372 
+<a name="l01373"></a>01373   <span class="keywordflow">for</span>(z=0;z< cpl_imagelist_get_size((*inp)); z++) {
+<a name="l01374"></a>01374     img=cpl_imagelist_get((*inp),z);
+<a name="l01375"></a>01375     local_median=sinfo_new_my_median_image(img);
+<a name="l01376"></a>01376     <span class="keywordflow">if</span>(!isnan(local_median)) {
+<a name="l01377"></a>01377       cpl_image_subtract_scalar(img,local_median);
+<a name="l01378"></a>01378     }  <span class="keywordflow">else</span> {
+<a name="l01379"></a>01379       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"local_median is NAN"</span>);
+<a name="l01380"></a>01380     }
+<a name="l01381"></a>01381     cpl_imagelist_set((*inp),img,z);
+<a name="l01382"></a>01382   }
+<a name="l01383"></a>01383 
+<a name="l01384"></a>01384   <span class="keywordflow">return</span> 0;
+<a name="l01385"></a>01385 }
+<a name="l01386"></a>01386 
+<a name="l01396"></a>01396 cpl_imagelist** sinfo_new_sinfoni_correct_sky(cpl_imagelist** cubes,
+<a name="l01397"></a>01397                   <span class="keyword">const</span> <span class="keywordtype">int</span> nc,
+<a name="l01398"></a>01398                   cpl_imagelist* sky_cube)
+<a name="l01399"></a>01399 
+<a name="l01400"></a>01400 {
+<a name="l01401"></a>01401   cpl_imagelist** cubes_sky=NULL;
+<a name="l01402"></a>01402   <span class="keywordtype">int</span> x=0;
+<a name="l01403"></a>01403   <span class="keywordtype">int</span> y=0;
+<a name="l01404"></a>01404   <span class="keywordtype">int</span> z=0;
+<a name="l01405"></a>01405   <span class="keywordtype">int</span> i=0;
+<a name="l01406"></a>01406   <span class="keywordtype">float</span> k=0.5;
+<a name="l01407"></a>01407   <span class="keywordtype">int</span> ovr=0;
+<a name="l01408"></a>01408   <span class="keywordtype">int</span> ks=0;
+<a name="l01409"></a>01409   <span class="keywordtype">int</span> nclip=0;
+<a name="l01410"></a>01410   <span class="keywordtype">double</span> med=0;
+<a name="l01411"></a>01411   <span class="keywordtype">double</span> avg=0;
+<a name="l01412"></a>01412   <span class="keywordtype">double</span> sig=0;
+<a name="l01413"></a>01413   <span class="keywordtype">int</span> msk_sum=0;
+<a name="l01414"></a>01414   <span class="keywordtype">double</span> val_msk_sum=0;
+<a name="l01415"></a>01415   cpl_vector* val=NULL;
+<a name="l01416"></a>01416   cpl_vector* msk=NULL;
+<a name="l01417"></a>01417   <span class="keywordtype">int</span> ilx=0;
+<a name="l01418"></a>01418   <span class="keywordtype">int</span> ily=0;
+<a name="l01419"></a>01419   <span class="keywordtype">int</span> inp=0;
+<a name="l01420"></a>01420 
+<a name="l01421"></a>01421 
+<a name="l01422"></a>01422   <span class="keywordtype">int</span> sky_lx=0;
+<a name="l01423"></a>01423   <span class="keywordtype">int</span> sky_ly=0;
+<a name="l01424"></a>01424 
+<a name="l01425"></a>01425   <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l01426"></a>01426   <span class="keywordtype">float</span>* p_sky_data=NULL;
+<a name="l01427"></a>01427   cpl_image* i_img=NULL;
+<a name="l01428"></a>01428   cpl_image* sky_img=NULL;
+<a name="l01429"></a>01429 
+<a name="l01430"></a>01430 
+<a name="l01431"></a>01431   <span class="keywordflow">if</span> ( cubes == NULL ) {
+<a name="l01432"></a>01432     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"no cube list given!"</span>) ;
+<a name="l01433"></a>01433     <span class="keywordflow">return</span> NULL ;
+<a name="l01434"></a>01434   }
+<a name="l01435"></a>01435   ilx=cpl_image_get_size_x(cpl_imagelist_get(cubes[0],0));
+<a name="l01436"></a>01436   ily=cpl_image_get_size_y(cpl_imagelist_get(cubes[0],0));
+<a name="l01437"></a>01437   inp=cpl_imagelist_get_size(cubes[0]);
+<a name="l01438"></a>01438 
+<a name="l01439"></a>01439 
+<a name="l01440"></a>01440   sky_lx=cpl_image_get_size_x(cpl_imagelist_get(sky_cube,0));
+<a name="l01441"></a>01441   sky_ly=cpl_image_get_size_y(cpl_imagelist_get(sky_cube,0));
+<a name="l01442"></a>01442   <span class="keywordflow">if</span> ( nc <= 0 ) {
+<a name="l01443"></a>01443     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"wrong number of data cubes in list!"</span>) ;
+<a name="l01444"></a>01444     <span class="keywordflow">return</span> NULL ;
+<a name="l01445"></a>01445   }
+<a name="l01446"></a>01446 
+<a name="l01447"></a>01447   cubes_sky = (cpl_imagelist**) cpl_calloc (nc, <span class="keyword">sizeof</span> (cpl_imagelist*)) ;
+<a name="l01448"></a>01448   <span class="keywordflow">for</span>(z=0;z< inp; z++) {
+<a name="l01449"></a>01449     sky_img=cpl_imagelist_get(sky_cube,z);
+<a name="l01450"></a>01450     p_sky_data=cpl_image_get_data_float(sky_img);
+<a name="l01451"></a>01451     <span class="keywordflow">for</span>(y=0;y< ily; y++) {
+<a name="l01452"></a>01452       <span class="keywordflow">for</span>(x=0;x< ilx; x++) {
+<a name="l01453"></a>01453         <span class="comment">/* here we start to do a k-s clipping */</span>
+<a name="l01454"></a>01454     msk=cpl_vector_new(nc);
+<a name="l01455"></a>01455     <span class="keywordflow">for</span> (i=0;i<nc;i++) {
+<a name="l01456"></a>01456       cpl_vector_set(msk,i,1);
+<a name="l01457"></a>01457     }
+<a name="l01458"></a>01458         nclip=0;
+<a name="l01459"></a>01459         <span class="keywordflow">for</span> (ks=0;ks<nc;ks++) {
+<a name="l01460"></a>01460       sig=0;
+<a name="l01461"></a>01461       med=0;
+<a name="l01462"></a>01462       ovr=0;
+<a name="l01463"></a>01463       val=cpl_vector_new(nc-nclip);
+<a name="l01464"></a>01464 
+<a name="l01465"></a>01465       <span class="keywordflow">for</span> ( i = 0 ; i < nc ; i++ ) {
+<a name="l01466"></a>01466             i_img=cpl_imagelist_get(cubes[i],z);
+<a name="l01467"></a>01467             pidata=cpl_image_get_data_float(i_img);
+<a name="l01468"></a>01468         <span class="keywordflow">if</span> ((!isnan(pidata[x+y*ilx])) &&
+<a name="l01469"></a>01469                  (cpl_vector_get(msk,i) != 0) ) {
+<a name="l01470"></a>01470           cpl_vector_set(val,ovr,(<span class="keywordtype">double</span>)pidata[x+y*ilx]);
+<a name="l01471"></a>01471           ovr++;
+<a name="l01472"></a>01472         }
+<a name="l01473"></a>01473       }
+<a name="l01474"></a>01474 
+<a name="l01475"></a>01475       <span class="keywordflow">if</span>(ovr>0) {
+<a name="l01476"></a>01476         avg=cpl_vector_get_mean(val);
+<a name="l01477"></a>01477         med=cpl_vector_get_median_const(val);
+<a name="l01478"></a>01478         <span class="keywordflow">if</span>(ovr>1) {
+<a name="l01479"></a>01479           sig=cpl_vector_get_stdev(val);
+<a name="l01480"></a>01480         } <span class="keywordflow">else</span> {
+<a name="l01481"></a>01481               sig=0;
+<a name="l01482"></a>01482         }
+<a name="l01483"></a>01483       } <span class="keywordflow">else</span> {
+<a name="l01484"></a>01484         avg=cpl_vector_get(val,0);
+<a name="l01485"></a>01485         med=avg;
+<a name="l01486"></a>01486         sig=0;
+<a name="l01487"></a>01487       }
+<a name="l01488"></a>01488 
+<a name="l01489"></a>01489       cpl_vector_delete(val);
+<a name="l01490"></a>01490       <span class="keywordflow">for</span> ( i = 0 ; i < nc ; i++ ) {
+<a name="l01491"></a>01491             i_img=cpl_imagelist_get(cubes[i],z);
+<a name="l01492"></a>01492             pidata=cpl_image_get_data_float(i_img);
+<a name="l01493"></a>01493       <span class="comment">/* Do k-s clipping at each pixel */</span>
+<a name="l01494"></a>01494         <span class="keywordflow">if</span> ((!isnan(pidata[x+y*ilx])) &&
+<a name="l01495"></a>01495                 (cpl_vector_get(msk,i) != 0)) {
+<a name="l01496"></a>01496           <span class="keywordflow">if</span>(abs((pidata[x+y*ilx]-med))> k*sig) {
+<a name="l01497"></a>01497         cpl_vector_set(msk,i,0);
+<a name="l01498"></a>01498                 nclip++;
+<a name="l01499"></a>01499           }
+<a name="l01500"></a>01500         }
+<a name="l01501"></a>01501       }
+<a name="l01502"></a>01502     }<span class="comment">/* end of k-s clipping */</span>
+<a name="l01503"></a>01503     msk_sum=0;
+<a name="l01504"></a>01504     val_msk_sum=0;
+<a name="l01505"></a>01505     <span class="keywordflow">for</span> ( i = 0 ; i < nc ; i++ ) {
+<a name="l01506"></a>01506       <span class="comment">/* computes sky at each point */</span>
+<a name="l01507"></a>01507       <span class="keywordflow">if</span> (!isnan(pidata[x+y*ilx])) {
+<a name="l01508"></a>01508         msk_sum+=cpl_vector_get(msk,i);
+<a name="l01509"></a>01509                 val_msk_sum+=pidata[x+y*ilx]*
+<a name="l01510"></a>01510           cpl_vector_get(msk,i);
+<a name="l01511"></a>01511       }
+<a name="l01512"></a>01512     }
+<a name="l01513"></a>01513     p_sky_data[x+y*sky_lx]=val_msk_sum/msk_sum;
+<a name="l01514"></a>01514     cpl_vector_delete(msk);
+<a name="l01515"></a>01515       } <span class="comment">/* end loop over x */</span>
+<a name="l01516"></a>01516     } <span class="comment">/* end loop over y */</span>
+<a name="l01517"></a>01517   } <span class="comment">/* end loop over z */</span>
+<a name="l01518"></a>01518   <span class="keywordflow">for</span> ( i = 0 ; i < nc ; i++ ) {
+<a name="l01519"></a>01519     cubes_sky[i]=cpl_imagelist_duplicate(cubes[i]);
+<a name="l01520"></a>01520     <span class="comment">/* subtract the variable clean sky */</span>
+<a name="l01521"></a>01521     cpl_imagelist_subtract(cubes_sky[i],sky_cube);
+<a name="l01522"></a>01522 
+<a name="l01523"></a>01523   }
+<a name="l01524"></a>01524 
+<a name="l01525"></a>01525 
+<a name="l01526"></a>01526   <span class="keywordflow">return</span> cubes_sky;
+<a name="l01527"></a>01527 }
+<a name="l01528"></a>01528 
+<a name="l01543"></a>01543 cpl_imagelist** sinfo_new_sinfoni_correct_sky2(cpl_imagelist** cubes,
+<a name="l01544"></a>01544                   <span class="keyword">const</span> <span class="keywordtype">int</span> nc,
+<a name="l01545"></a>01545                   cpl_imagelist* sky_cube,
+<a name="l01546"></a>01546                               cpl_imagelist* med_cube,
+<a name="l01547"></a>01547                               cpl_imagelist* msk_cube,
+<a name="l01548"></a>01548                               cpl_imagelist* avg_cube,
+<a name="l01549"></a>01549                               cpl_imagelist* sig_cube,
+<a name="l01550"></a>01550                               cpl_imagelist* ovr_cube)
+<a name="l01551"></a>01551 {
+<a name="l01552"></a>01552   cpl_imagelist** cubes_sky=NULL;
+<a name="l01553"></a>01553   <span class="keywordtype">int</span> x=0;
+<a name="l01554"></a>01554   <span class="keywordtype">int</span> y=0;
+<a name="l01555"></a>01555   <span class="keywordtype">int</span> z=0;
+<a name="l01556"></a>01556   <span class="keywordtype">int</span> i=0;
+<a name="l01557"></a>01557   <span class="keywordtype">float</span> k=0.5;
+<a name="l01558"></a>01558   <span class="keywordtype">int</span> ovr=0;
+<a name="l01559"></a>01559   <span class="keywordtype">int</span> ks=0;
+<a name="l01560"></a>01560   <span class="keywordtype">int</span> nclip=0;
+<a name="l01561"></a>01561   <span class="keywordtype">double</span> med=0;
+<a name="l01562"></a>01562   <span class="keywordtype">double</span> avg=0;
+<a name="l01563"></a>01563   <span class="keywordtype">double</span> sig=0;
+<a name="l01564"></a>01564   <span class="keywordtype">int</span> msk_sum=0;
+<a name="l01565"></a>01565   <span class="keywordtype">double</span> val_msk_sum=0;
+<a name="l01566"></a>01566   cpl_vector* val=NULL;
+<a name="l01567"></a>01567   cpl_vector* msk=NULL;
+<a name="l01568"></a>01568 
+<a name="l01569"></a>01569   <span class="keywordtype">int</span> ilx=0;
+<a name="l01570"></a>01570   <span class="keywordtype">int</span> ily=0;
+<a name="l01571"></a>01571   <span class="keywordtype">int</span> inp=0;
+<a name="l01572"></a>01572 
+<a name="l01573"></a>01573   <span class="keywordtype">int</span> ovr_lx=0;
+<a name="l01574"></a>01574   <span class="keywordtype">int</span> msk_lx=0;
+<a name="l01575"></a>01575   <span class="keywordtype">int</span> avg_lx=0;
+<a name="l01576"></a>01576   <span class="keywordtype">int</span> sig_lx=0;
+<a name="l01577"></a>01577   <span class="keywordtype">int</span> sky_lx=0;
+<a name="l01578"></a>01578   <span class="keywordtype">int</span> med_lx=0;
+<a name="l01579"></a>01579 
+<a name="l01580"></a>01580 
+<a name="l01581"></a>01581   <span class="keywordtype">float</span>* p_ovr_data=NULL;
+<a name="l01582"></a>01582   <span class="keywordtype">float</span>* p_msk_data=NULL;
+<a name="l01583"></a>01583   <span class="keywordtype">float</span>* p_avg_data=NULL;
+<a name="l01584"></a>01584   <span class="keywordtype">float</span>* p_sig_data=NULL;
+<a name="l01585"></a>01585   <span class="keywordtype">float</span>* p_sky_data=NULL;
+<a name="l01586"></a>01586   <span class="keywordtype">float</span>* p_med_data=NULL;
+<a name="l01587"></a>01587 
+<a name="l01588"></a>01588   <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l01589"></a>01589 
+<a name="l01590"></a>01590   <span class="keywordflow">if</span> ( cubes == NULL ) {
+<a name="l01591"></a>01591     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"no cube list given!"</span>) ;
+<a name="l01592"></a>01592     <span class="keywordflow">return</span> NULL ;
+<a name="l01593"></a>01593   }
+<a name="l01594"></a>01594 
+<a name="l01595"></a>01595   ilx=cpl_image_get_size_x(cpl_imagelist_get(cubes[0],0));
+<a name="l01596"></a>01596   ily=cpl_image_get_size_y(cpl_imagelist_get(cubes[0],0));
+<a name="l01597"></a>01597   inp=cpl_imagelist_get_size(cubes[0]);
+<a name="l01598"></a>01598 
+<a name="l01599"></a>01599   <span class="keywordflow">if</span> ( nc <= 0 ) {
+<a name="l01600"></a>01600     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"wrong number of data cubes in list!"</span>) ;
+<a name="l01601"></a>01601     <span class="keywordflow">return</span> NULL ;
+<a name="l01602"></a>01602   }
+<a name="l01603"></a>01603 
+<a name="l01604"></a>01604   cubes_sky = (cpl_imagelist**) cpl_calloc (nc, <span class="keyword">sizeof</span> (cpl_imagelist*)) ;
+<a name="l01605"></a>01605 
+<a name="l01606"></a>01606   ovr_lx=ilx;
+<a name="l01607"></a>01607   msk_lx=ilx;
+<a name="l01608"></a>01608   avg_lx=ilx;
+<a name="l01609"></a>01609   sig_lx=ilx;
+<a name="l01610"></a>01610   sky_lx=ilx;
+<a name="l01611"></a>01611   med_lx=ilx;
+<a name="l01612"></a>01612 
+<a name="l01613"></a>01613   <span class="keywordflow">for</span>(z=0;z< inp; z++) {
+<a name="l01614"></a>01614     p_ovr_data=cpl_image_get_data_float(cpl_imagelist_get(ovr_cube,z));
+<a name="l01615"></a>01615     p_msk_data=cpl_image_get_data_float(cpl_imagelist_get(msk_cube,z));
+<a name="l01616"></a>01616     p_avg_data=cpl_image_get_data_float(cpl_imagelist_get(avg_cube,z));
+<a name="l01617"></a>01617     p_sig_data=cpl_image_get_data_float(cpl_imagelist_get(sig_cube,z));
+<a name="l01618"></a>01618     p_sky_data=cpl_image_get_data_float(cpl_imagelist_get(sky_cube,z));
+<a name="l01619"></a>01619     p_med_data=cpl_image_get_data_float(cpl_imagelist_get(med_cube,z));
+<a name="l01620"></a>01620 
+<a name="l01621"></a>01621 
+<a name="l01622"></a>01622     <span class="keywordflow">for</span>(y=0;y< ily; y++) {
+<a name="l01623"></a>01623       <span class="keywordflow">for</span>(x=0;x< ilx; x++) {
+<a name="l01624"></a>01624         <span class="comment">/* here we start to do a k-s clipping */</span>
+<a name="l01625"></a>01625     msk=cpl_vector_new(nc);
+<a name="l01626"></a>01626     <span class="keywordflow">for</span> (i=0;i<nc;i++) {
+<a name="l01627"></a>01627       cpl_vector_set(msk,i,1);
+<a name="l01628"></a>01628     }
+<a name="l01629"></a>01629     p_ovr_data[x+y*ovr_lx]=nc;
+<a name="l01630"></a>01630     p_msk_data[x+y*msk_lx]=nc;
+<a name="l01631"></a>01631         nclip=0;
+<a name="l01632"></a>01632         <span class="keywordflow">for</span> (ks=0;ks<nc;ks++) {
+<a name="l01633"></a>01633       sig=0;
+<a name="l01634"></a>01634       med=0;
+<a name="l01635"></a>01635       ovr=0;
+<a name="l01636"></a>01636       val=cpl_vector_new(nc-nclip);
+<a name="l01637"></a>01637 
+<a name="l01638"></a>01638       <span class="keywordflow">for</span> ( i = 0 ; i < nc ; i++ ) {
+<a name="l01639"></a>01639             pidata=cpl_image_get_data_float(cpl_imagelist_get(cubes[i],z));
+<a name="l01640"></a>01640         <span class="keywordflow">if</span> ((!isnan(pidata[x+y*ilx])) &&
+<a name="l01641"></a>01641                  (cpl_vector_get(msk,i) != 0) ) {
+<a name="l01642"></a>01642           cpl_vector_set(val,ovr,(<span class="keywordtype">double</span>)pidata[x+y*ilx]);
+<a name="l01643"></a>01643           ovr++;
+<a name="l01644"></a>01644         }
+<a name="l01645"></a>01645       }
+<a name="l01646"></a>01646 
+<a name="l01647"></a>01647       <span class="keywordflow">if</span>(ovr>1) {
+<a name="l01648"></a>01648         avg=cpl_vector_get_mean(val);
+<a name="l01649"></a>01649         med=cpl_vector_get_median_const(val);
+<a name="l01650"></a>01650         sig=cpl_vector_get_stdev(val);
+<a name="l01651"></a>01651       } <span class="keywordflow">else</span> {
+<a name="l01652"></a>01652         avg=cpl_vector_get(val,0);
+<a name="l01653"></a>01653         med=avg;
+<a name="l01654"></a>01654         sig=0;
+<a name="l01655"></a>01655       }
+<a name="l01656"></a>01656 
+<a name="l01657"></a>01657       p_med_data[x+y*med_lx]=med;
+<a name="l01658"></a>01658       p_avg_data[x+y*avg_lx]=avg;
+<a name="l01659"></a>01659       p_sig_data[x+y*sig_lx]=sig;
+<a name="l01660"></a>01660       cpl_vector_delete(val);
+<a name="l01661"></a>01661       <span class="keywordflow">for</span> ( i = 0 ; i < nc ; i++ ) {
+<a name="l01662"></a>01662            pidata=cpl_image_get_data_float(cpl_imagelist_get(cubes[i],z));
+<a name="l01663"></a>01663       <span class="comment">/* Do k-s clipping at each pixel */</span>
+<a name="l01664"></a>01664         <span class="keywordflow">if</span> ((!isnan(pidata[x+y*ilx])) &&
+<a name="l01665"></a>01665                 (cpl_vector_get(msk,i) != 0)) {
+<a name="l01666"></a>01666           <span class="keywordflow">if</span>(abs((pidata[x+y*ilx]-med))> k*sig) {
+<a name="l01667"></a>01667         <span class="comment">/* pidata[x+y*ilx]=0; */</span>
+<a name="l01668"></a>01668         p_msk_data[x+y*msk_lx]-=1;
+<a name="l01669"></a>01669         cpl_vector_set(msk,i,0);
+<a name="l01670"></a>01670                 nclip++;
+<a name="l01671"></a>01671           }
+<a name="l01672"></a>01672         }
+<a name="l01673"></a>01673       }
+<a name="l01674"></a>01674     }<span class="comment">/* end of k-s clipping */</span>
+<a name="l01675"></a>01675     msk_sum=0;
+<a name="l01676"></a>01676     val_msk_sum=0;
+<a name="l01677"></a>01677     <span class="keywordflow">for</span> ( i = 0 ; i < nc ; i++ ) {
+<a name="l01678"></a>01678            pidata=cpl_image_get_data_float(cpl_imagelist_get(cubes[i],z));
+<a name="l01679"></a>01679       <span class="comment">/* computes sky at each point */</span>
+<a name="l01680"></a>01680       <span class="keywordflow">if</span> (!isnan(pidata[x+y*ilx])) {
+<a name="l01681"></a>01681         <span class="comment">/*</span>
+<a name="l01682"></a>01682 <span class="comment">        msk_sum+=p_msk_data[x+y*msk_lx];</span>
+<a name="l01683"></a>01683 <span class="comment">                val_msk_sum+=pidata[x+y*cubes[i]->lx]*</span>
+<a name="l01684"></a>01684 <span class="comment">          p_msk_data[x+y*msk_lx];</span>
+<a name="l01685"></a>01685 <span class="comment">        */</span>
+<a name="l01686"></a>01686         msk_sum+=cpl_vector_get(msk,i);
+<a name="l01687"></a>01687                 val_msk_sum+=pidata[x+y*ilx]*
+<a name="l01688"></a>01688           cpl_vector_get(msk,i);
+<a name="l01689"></a>01689       }
+<a name="l01690"></a>01690     }
+<a name="l01691"></a>01691     p_sky_data[x+y*sky_lx]=val_msk_sum/msk_sum;
+<a name="l01692"></a>01692     cpl_vector_delete(msk);
+<a name="l01693"></a>01693       } <span class="comment">/* end loop over x */</span>
+<a name="l01694"></a>01694     } <span class="comment">/* end loop over y */</span>
+<a name="l01695"></a>01695   } <span class="comment">/* end loop over z */</span>
+<a name="l01696"></a>01696   <span class="keywordflow">for</span> ( i = 0 ; i < nc ; i++ ) {
+<a name="l01697"></a>01697     cubes_sky[i]=cpl_imagelist_duplicate(cubes[i]);
+<a name="l01698"></a>01698     <span class="comment">/* subtract the variable clean sky */</span>
+<a name="l01699"></a>01699     cpl_imagelist_subtract(cubes_sky[i],sky_cube);
+<a name="l01700"></a>01700   }
+<a name="l01701"></a>01701 
+<a name="l01702"></a>01702 
+<a name="l01703"></a>01703   <span class="keywordflow">return</span> cubes_sky;
+<a name="l01704"></a>01704 }
+<a name="l01705"></a>01705 
+<a name="l01706"></a>01706 
+<a name="l01719"></a>01719 <span class="keywordtype">int</span>
+<a name="l01720"></a>01720 sinfo_new_assign_offset(<span class="keyword">const</span> <span class="keywordtype">int</span> n,
+<a name="l01721"></a>01721                         <span class="keyword">const</span> <span class="keywordtype">char</span>* name,
+<a name="l01722"></a>01722                         <span class="keywordtype">float</span>* offsetx,
+<a name="l01723"></a>01723                         <span class="keywordtype">float</span>* offsety,
+<a name="l01724"></a>01724                         <span class="keyword">const</span> <span class="keywordtype">float</span> ref_offx,
+<a name="l01725"></a>01725                         <span class="keyword">const</span> <span class="keywordtype">float</span> ref_offy)
+<a name="l01726"></a>01726 {
+<a name="l01727"></a>01727 
+<a name="l01728"></a>01728   <span class="keywordtype">float</span> offx=0;
+<a name="l01729"></a>01729   <span class="keywordtype">float</span> offy=0;
+<a name="l01730"></a>01730   <span class="keywordtype">double</span> mjd_obs=0;
+<a name="l01731"></a>01731   <span class="comment">/*</span>
+<a name="l01732"></a>01732 <span class="comment">  double pixelscale=0;</span>
+<a name="l01733"></a>01733 <span class="comment">  double angle=0;</span>
+<a name="l01734"></a>01734 <span class="comment">  double radangle=0;</span>
+<a name="l01735"></a>01735 <span class="comment">  double cd1_1=0;</span>
+<a name="l01736"></a>01736 <span class="comment">  double cd1_2=0;</span>
+<a name="l01737"></a>01737 <span class="comment">  double cd2_1=0;</span>
+<a name="l01738"></a>01738 <span class="comment">  double cd2_2=0;</span>
+<a name="l01739"></a>01739 <span class="comment">  double ra=0;</span>
+<a name="l01740"></a>01740 <span class="comment">  double dec=0;</span>
+<a name="l01741"></a>01741 <span class="comment">  */</span>
+<a name="l01742"></a>01742 
+<a name="l01743"></a>01743   cpl_propertylist * plist=NULL;
+<a name="l01744"></a>01744   <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"Assign offsets"</span>);
+<a name="l01745"></a>01745 
+<a name="l01746"></a>01746   <span class="keywordflow">if</span> ((cpl_error_code)((plist = cpl_propertylist_load(name, 0)) == NULL)) {
+<a name="l01747"></a>01747     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>( <span class="stringliteral">"getting header from reference frame %s"</span>,name);
+<a name="l01748"></a>01748     cpl_propertylist_delete(plist) ;
+<a name="l01749"></a>01749     <span class="keywordflow">return</span> -1 ;
+<a name="l01750"></a>01750   }
+<a name="l01751"></a>01751 
+<a name="l01752"></a>01752   offx = sinfo_pfits_get_cumoffsetx(plist) - ref_offx ;  <span class="comment">/* was - */</span>
+<a name="l01753"></a>01753   <span class="keywordflow">if</span>(cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l01754"></a>01754     <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">" could not read fits header keyword cummoffsetx!"</span>) ;
+<a name="l01755"></a>01755     <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">" Set relative offset to 0 - %f!"</span>,ref_offx) ;
+<a name="l01756"></a>01756     offx =  - ref_offx;
+<a name="l01757"></a>01757     cpl_error_reset();
+<a name="l01758"></a>01758     <span class="comment">/* return -1 ; */</span>
+<a name="l01759"></a>01759   }
+<a name="l01760"></a>01760 
+<a name="l01761"></a>01761   offy = sinfo_pfits_get_cumoffsety(plist) - ref_offy ; <span class="comment">/* was - */</span>
+<a name="l01762"></a>01762   <span class="keywordflow">if</span>(cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l01763"></a>01763     <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">" could not read fits header keyword! cumoffsety"</span>) ;
+<a name="l01764"></a>01764     <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">" Set relative offset to 0 - %f!"</span>,ref_offx) ;
+<a name="l01765"></a>01765     offy =  - ref_offy;
+<a name="l01766"></a>01766     cpl_error_reset();
+<a name="l01767"></a>01767     <span class="comment">/* return -1 ; */</span>
+<a name="l01768"></a>01768   }
+<a name="l01769"></a>01769   <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"offx=%f offy=%f"</span>,offx,offy);
+<a name="l01770"></a>01770 
+<a name="l01771"></a>01771   <span class="keywordflow">if</span> (sinfo_propertylist_has(plist, KEY_NAME_MJD_OBS)) {
+<a name="l01772"></a>01772     mjd_obs=cpl_propertylist_get_double(plist, KEY_NAME_MJD_OBS);
+<a name="l01773"></a>01773   } <span class="keywordflow">else</span> {
+<a name="l01774"></a>01774     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"keyword %s does not exist"</span>,KEY_NAME_MJD_OBS);
+<a name="l01775"></a>01775     cpl_propertylist_delete(plist) ;
+<a name="l01776"></a>01776     <span class="keywordflow">return</span> -1;
+<a name="l01777"></a>01777   }
+<a name="l01778"></a>01778 
+<a name="l01779"></a>01779   cpl_propertylist_delete(plist) ;
+<a name="l01780"></a>01780 
+<a name="l01781"></a>01781   <span class="keywordflow">if</span> (mjd_obs > 53825. ) {
+<a name="l01782"></a>01782     <span class="comment">/* April 1st 2006 */</span>
+<a name="l01783"></a>01783     <span class="comment">//sinfo_msg("New cumoffset setting convention");</span>
+<a name="l01784"></a>01784     sinfo_new_array_set_value(offsetx,2*offx,n);
+<a name="l01785"></a>01785     sinfo_new_array_set_value(offsety,2*offy,n);
+<a name="l01786"></a>01786   } <span class="keywordflow">else</span> <span class="keywordflow">if</span> ((mjd_obs > 53421.58210082 ) && (mjd_obs <= 53825.)){
+<a name="l01787"></a>01787     <span class="comment">/* after detector's upgrade */</span>
+<a name="l01788"></a>01788     <span class="comment">/*</span>
+<a name="l01789"></a>01789 <span class="comment">    sinfo_new_array_set_value(offsetx,-offx*2,n);</span>
+<a name="l01790"></a>01790 <span class="comment">    sinfo_new_array_set_value(offsety,+offy*2,n);</span>
+<a name="l01791"></a>01791 <span class="comment">    */</span>
+<a name="l01792"></a>01792     sinfo_new_array_set_value(offsetx,-2*offx,n);
+<a name="l01793"></a>01793     sinfo_new_array_set_value(offsety,2*offy,n);
+<a name="l01794"></a>01794   } <span class="keywordflow">else</span> {
+<a name="l01795"></a>01795     <span class="comment">/* before detector's upgrade */</span>
+<a name="l01796"></a>01796     <span class="comment">/*</span>
+<a name="l01797"></a>01797 <span class="comment">    sinfo_new_array_set_value(offsetx,+offx*2,n);</span>
+<a name="l01798"></a>01798 <span class="comment">    sinfo_new_array_set_value(offsety,-offy*2,n);</span>
+<a name="l01799"></a>01799 <span class="comment">    */</span>
+<a name="l01800"></a>01800     sinfo_new_array_set_value(offsetx,2*offx,n);
+<a name="l01801"></a>01801     sinfo_new_array_set_value(offsety,-2*offy,n);
+<a name="l01802"></a>01802   }
+<a name="l01803"></a>01803 
+<a name="l01804"></a>01804   <span class="keywordflow">return</span> 0;
+<a name="l01805"></a>01805 
+<a name="l01806"></a>01806 
+<a name="l01807"></a>01807 }
+<a name="l01808"></a>01808 
+<a name="l01809"></a>01809 
+<a name="l01810"></a>01810 
+<a name="l01811"></a>01811 
+<a name="l01812"></a>01812 
+<a name="l01825"></a>01825 <span class="keywordtype">int</span>
+<a name="l01826"></a>01826 sinfo_new_assign_offset2(<span class="keyword">const</span> <span class="keywordtype">int</span> n,
+<a name="l01827"></a>01827                         <span class="keyword">const</span> <span class="keywordtype">char</span>* name,
+<a name="l01828"></a>01828                         <span class="keywordtype">float</span>* offsetx,
+<a name="l01829"></a>01829                         <span class="keywordtype">float</span>* offsety,
+<a name="l01830"></a>01830                         <span class="keyword">const</span> <span class="keywordtype">float</span> ref_offx,
+<a name="l01831"></a>01831                         <span class="keyword">const</span> <span class="keywordtype">float</span> ref_offy)
+<a name="l01832"></a>01832 {
+<a name="l01833"></a>01833 
+<a name="l01834"></a>01834   <span class="keywordtype">float</span> offx=0;
+<a name="l01835"></a>01835   <span class="keywordtype">float</span> offy=0;
+<a name="l01836"></a>01836   <span class="keywordtype">double</span> mjd_obs=0;
+<a name="l01837"></a>01837 
+<a name="l01838"></a>01838   cpl_propertylist * plist=NULL;
+<a name="l01839"></a>01839   <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"Assign offsets as set by user"</span>);
+<a name="l01840"></a>01840   offx = offsetx[n] - ref_offx ;  <span class="comment">/* was - */</span>
+<a name="l01841"></a>01841   offy = offsety[n] - ref_offy ;  <span class="comment">/* was - */</span>
+<a name="l01842"></a>01842   <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"offx=%f offy=%f"</span>,offx,offy);
+<a name="l01843"></a>01843 
+<a name="l01844"></a>01844   <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"Assign offsets"</span>);
+<a name="l01845"></a>01845 
+<a name="l01846"></a>01846   <span class="keywordflow">if</span> ((cpl_error_code)((plist = cpl_propertylist_load(name, 0)) == NULL)) {
+<a name="l01847"></a>01847     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>( <span class="stringliteral">"getting header from reference frame %s"</span>,name);
+<a name="l01848"></a>01848     cpl_propertylist_delete(plist) ;
+<a name="l01849"></a>01849     <span class="keywordflow">return</span> -1 ;
+<a name="l01850"></a>01850   }
+<a name="l01851"></a>01851 
+<a name="l01852"></a>01852   <span class="keywordflow">if</span> (sinfo_propertylist_has(plist, KEY_NAME_MJD_OBS)) {
+<a name="l01853"></a>01853     mjd_obs=cpl_propertylist_get_double(plist, KEY_NAME_MJD_OBS);
+<a name="l01854"></a>01854   } <span class="keywordflow">else</span> {
+<a name="l01855"></a>01855     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"keyword %s does not exist"</span>,KEY_NAME_MJD_OBS);
+<a name="l01856"></a>01856     cpl_propertylist_delete(plist) ;
+<a name="l01857"></a>01857     <span class="keywordflow">return</span> -1;
+<a name="l01858"></a>01858   }
+<a name="l01859"></a>01859   cpl_propertylist_delete(plist) ;
+<a name="l01860"></a>01860 
+<a name="l01861"></a>01861   <span class="comment">//sinfo_new_array_set_value(offsetx,-2*offx,n);</span>
+<a name="l01862"></a>01862   <span class="comment">//sinfo_new_array_set_value(offsety,2*offy,n);</span>
+<a name="l01863"></a>01863 
+<a name="l01864"></a>01864   <span class="keywordflow">if</span> (mjd_obs > 53825. ) {
+<a name="l01865"></a>01865     <span class="comment">/* April 1st 2006 */</span>
+<a name="l01866"></a>01866     <span class="comment">//sinfo_msg("New cumoffset setting convention");</span>
+<a name="l01867"></a>01867     sinfo_new_array_set_value(offsetx,2*offx,n);
+<a name="l01868"></a>01868     sinfo_new_array_set_value(offsety,2*offy,n);
+<a name="l01869"></a>01869   } <span class="keywordflow">else</span> <span class="keywordflow">if</span> ((mjd_obs > 53421.58210082 ) && (mjd_obs <= 53825.)){
+<a name="l01870"></a>01870     <span class="comment">/* after detector's upgrade */</span>
+<a name="l01871"></a>01871     <span class="comment">/*</span>
+<a name="l01872"></a>01872 <span class="comment">    sinfo_new_array_set_value(offsetx,-offx*2,n);</span>
+<a name="l01873"></a>01873 <span class="comment">    sinfo_new_array_set_value(offsety,+offy*2,n);</span>
+<a name="l01874"></a>01874 <span class="comment">    */</span>
+<a name="l01875"></a>01875     sinfo_new_array_set_value(offsetx,-2*offx,n);
+<a name="l01876"></a>01876     sinfo_new_array_set_value(offsety,2*offy,n);
+<a name="l01877"></a>01877   } <span class="keywordflow">else</span> {
+<a name="l01878"></a>01878     <span class="comment">/* before detector's upgrade */</span>
+<a name="l01879"></a>01879     <span class="comment">/*</span>
+<a name="l01880"></a>01880 <span class="comment">    sinfo_new_array_set_value(offsetx,+offx*2,n);</span>
+<a name="l01881"></a>01881 <span class="comment">    sinfo_new_array_set_value(offsety,-offy*2,n);</span>
+<a name="l01882"></a>01882 <span class="comment">    */</span>
+<a name="l01883"></a>01883     sinfo_new_array_set_value(offsetx,2*offx,n);
+<a name="l01884"></a>01884     sinfo_new_array_set_value(offsety,-2*offy,n);
+<a name="l01885"></a>01885   }
+<a name="l01886"></a>01886 
+<a name="l01887"></a>01887 
+<a name="l01888"></a>01888   <span class="keywordflow">return</span> 0;
+<a name="l01889"></a>01889 
+<a name="l01890"></a>01890 
+<a name="l01891"></a>01891 }
+<a name="l01892"></a>01892 
+<a name="l01893"></a>01893 
+<a name="l01906"></a>01906 <span class="keywordtype">int</span>
+<a name="l01907"></a>01907 sinfo_new_object_assign_offset(<span class="keyword">const</span> <span class="keywordtype">char</span>* name,
+<a name="l01908"></a>01908                                <span class="keyword">const</span> <span class="keywordtype">int</span> n,
+<a name="l01909"></a>01909                                <span class="keywordtype">double</span>* ref_offx,
+<a name="l01910"></a>01910                                <span class="keywordtype">double</span>* ref_offy,
+<a name="l01911"></a>01911                                <span class="keywordtype">float</span>** offsetx,
+<a name="l01912"></a>01912                                <span class="keywordtype">float</span>** offsety)
+<a name="l01913"></a>01913 {
+<a name="l01914"></a>01914 
+<a name="l01915"></a>01915   <span class="keywordtype">float</span> offx=0;
+<a name="l01916"></a>01916   <span class="keywordtype">float</span> offy=0;
+<a name="l01917"></a>01917   <span class="keywordtype">double</span> mjd_obs=0;
+<a name="l01918"></a>01918   cpl_propertylist * plist=NULL;
+<a name="l01919"></a>01919   <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"Assign offsets"</span>);
+<a name="l01920"></a>01920 
+<a name="l01921"></a>01921   <span class="keywordflow">if</span> ((cpl_error_code)((plist = cpl_propertylist_load(name, 0)) == NULL)) {
+<a name="l01922"></a>01922     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>( <span class="stringliteral">"getting header from reference frame %s"</span>,name);
+<a name="l01923"></a>01923     cpl_propertylist_delete(plist) ;
+<a name="l01924"></a>01924     <span class="keywordflow">return</span> -1 ;
+<a name="l01925"></a>01925   }
+<a name="l01926"></a>01926   <span class="keywordflow">if</span> ( n == 0 ) {
+<a name="l01927"></a>01927 
+<a name="l01928"></a>01928     *ref_offx = sinfo_pfits_get_cumoffsetx(plist) ;
+<a name="l01929"></a>01929     <span class="keywordflow">if</span>(cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l01930"></a>01930       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" could not read fits header keyword cummoffsetx!"</span>) ;
+<a name="l01931"></a>01931       <span class="comment">/* return -1 ; */</span>
+<a name="l01932"></a>01932       cpl_error_reset();
+<a name="l01933"></a>01933     }
+<a name="l01934"></a>01934 
+<a name="l01935"></a>01935     *ref_offy = sinfo_pfits_get_cumoffsety(plist) ;
+<a name="l01936"></a>01936     <span class="keywordflow">if</span>(cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l01937"></a>01937       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" could not read fits header keyword! cumoffsety"</span>) ;
+<a name="l01938"></a>01938       cpl_error_reset();
+<a name="l01939"></a>01939        <span class="comment">/* return -1 ; */</span>
+<a name="l01940"></a>01940     }
+<a name="l01941"></a>01941     <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"Reference offx=%f offy=%f"</span>,*ref_offx,*ref_offy);
+<a name="l01942"></a>01942 
+<a name="l01943"></a>01943     offx = 0. ;
+<a name="l01944"></a>01944     offy = 0. ;
+<a name="l01945"></a>01945 
+<a name="l01946"></a>01946   } <span class="keywordflow">else</span> {
+<a name="l01947"></a>01947 
+<a name="l01948"></a>01948     offx = sinfo_pfits_get_cumoffsetx(plist) - *ref_offx ;  <span class="comment">/* was - */</span>
+<a name="l01949"></a>01949     <span class="keywordflow">if</span>(cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l01950"></a>01950       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" could not read fits header keyword cummoffsetx!"</span>) ;
+<a name="l01951"></a>01951       cpl_error_reset();
+<a name="l01952"></a>01952       <span class="comment">/* return -1 ; */</span>
+<a name="l01953"></a>01953     }
+<a name="l01954"></a>01954 
+<a name="l01955"></a>01955     offy = sinfo_pfits_get_cumoffsety(plist) - *ref_offy ; <span class="comment">/* was - */</span>
+<a name="l01956"></a>01956     <span class="keywordflow">if</span>(cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l01957"></a>01957       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" could not read fits header keyword! cumoffsety"</span>) ;
+<a name="l01958"></a>01958       <span class="comment">/* return -1 ; */</span>
+<a name="l01959"></a>01959       cpl_error_reset();
+<a name="l01960"></a>01960     }
+<a name="l01961"></a>01961     <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"offx=%f offy=%f"</span>,offx,offy);
+<a name="l01962"></a>01962   }
+<a name="l01963"></a>01963 
+<a name="l01964"></a>01964 
+<a name="l01965"></a>01965     <span class="comment">/* rotate the coordinates</span>
+<a name="l01966"></a>01966 <span class="comment">       offx_rot = cd1_1 * offx + cd2_1 * offy ;</span>
+<a name="l01967"></a>01967 <span class="comment">       offy_rot = cd1_2 * offx + cd2_2 * offy ;</span>
+<a name="l01968"></a>01968 <span class="comment">        convert the coordinates to pixel units</span>
+<a name="l01969"></a>01969 <span class="comment">       offx_rot_pix = offx_rot / pixelscale ;</span>
+<a name="l01970"></a>01970 <span class="comment">       offy_rot_pix = offy_rot / pixelscale ;</span>
+<a name="l01971"></a>01971 <span class="comment">       offsetx[i] = offx_rot_pix ;</span>
+<a name="l01972"></a>01972 <span class="comment">       offsety[i] = offy_rot_pix ;</span>
+<a name="l01973"></a>01973 <span class="comment">    */</span>
+<a name="l01974"></a>01974 
+<a name="l01975"></a>01975 
+<a name="l01976"></a>01976   <span class="keywordflow">if</span> (sinfo_propertylist_has(plist, KEY_NAME_MJD_OBS)) {
+<a name="l01977"></a>01977     mjd_obs=cpl_propertylist_get_double(plist, KEY_NAME_MJD_OBS);
+<a name="l01978"></a>01978   } <span class="keywordflow">else</span> {
+<a name="l01979"></a>01979     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"keyword %s does not exist"</span>,KEY_NAME_MJD_OBS);
+<a name="l01980"></a>01980     cpl_propertylist_delete(plist) ;
+<a name="l01981"></a>01981     <span class="keywordflow">return</span> -1;
+<a name="l01982"></a>01982   }
+<a name="l01983"></a>01983 
+<a name="l01984"></a>01984   cpl_propertylist_delete(plist) ;
+<a name="l01985"></a>01985 
+<a name="l01986"></a>01986   <span class="keywordflow">if</span> (mjd_obs > 53825. ) {
+<a name="l01987"></a>01987     <span class="comment">/* April 1st 2006 */</span>
+<a name="l01988"></a>01988     <span class="comment">//sinfo_msg("New cumoffset setting convention");</span>
+<a name="l01989"></a>01989     sinfo_new_array_set_value(*offsetx,2*offx,n);
+<a name="l01990"></a>01990     sinfo_new_array_set_value(*offsety,2*offy,n);
+<a name="l01991"></a>01991   } <span class="keywordflow">else</span> <span class="keywordflow">if</span> ((mjd_obs > 53421.58210082 ) && (mjd_obs <= 53825.)){
+<a name="l01992"></a>01992     <span class="comment">/* after detector's upgrade */</span>
+<a name="l01993"></a>01993     sinfo_new_array_set_value(*offsetx,-offx*2,n);
+<a name="l01994"></a>01994     sinfo_new_array_set_value(*offsety,+offy*2,n);
+<a name="l01995"></a>01995   } <span class="keywordflow">else</span> {
+<a name="l01996"></a>01996     <span class="comment">/* before detector's upgrade */</span>
+<a name="l01997"></a>01997     sinfo_new_array_set_value(*offsetx,+offx*2,n);
+<a name="l01998"></a>01998     sinfo_new_array_set_value(*offsety,-offy*2,n);
+<a name="l01999"></a>01999   }
+<a name="l02000"></a>02000 
+<a name="l02001"></a>02001   <span class="keywordflow">return</span> 0;
+<a name="l02002"></a>02002 }
+<a name="l02003"></a>02003 
+<a name="l02015"></a>02015 cpl_imagelist*
+<a name="l02016"></a>02016 sinfo_new_fine_tune(cpl_imagelist* cube,
+<a name="l02017"></a>02017               <span class="keywordtype">float</span>* correct_dist,
+<a name="l02018"></a>02018               <span class="keyword">const</span> <span class="keywordtype">char</span>* method,
+<a name="l02019"></a>02019               <span class="keyword">const</span> <span class="keywordtype">int</span> order,
+<a name="l02020"></a>02020               <span class="keyword">const</span> <span class="keywordtype">int</span> nslits) {
+<a name="l02021"></a>02021   <span class="keywordtype">int</span> i =0;
+<a name="l02022"></a>02022   cpl_imagelist* outcube2=NULL;
+<a name="l02023"></a>02023   <span class="keywordtype">float</span>* neg_dist=NULL;
+<a name="l02024"></a>02024   sinfo_msg(<span class="stringliteral">"Finetuning, method=%s"</span>,method);
+<a name="l02025"></a>02025 
+<a name="l02026"></a>02026   <span class="keywordflow">if</span> (strcmp(method,<span class="stringliteral">"P"</span>)==0)
+<a name="l02027"></a>02027     {
+<a name="l02028"></a>02028       outcube2 = sinfo_new_fine_tune_cube( cube, correct_dist, order ) ;
+<a name="l02029"></a>02029       <span class="keywordflow">if</span> (outcube2 == NULL)
+<a name="l02030"></a>02030     {
+<a name="l02031"></a>02031       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" could not fine tune the data cube\n"</span>) ;
+<a name="l02032"></a>02032       <span class="keywordflow">return</span> NULL ;
+<a name="l02033"></a>02033     }
+<a name="l02034"></a>02034     }
+<a name="l02035"></a>02035   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(method,<span class="stringliteral">"F"</span>)==0)
+<a name="l02036"></a>02036     {
+<a name="l02037"></a>02037       neg_dist=cpl_calloc(nslits,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>));
+<a name="l02038"></a>02038       <span class="keywordflow">for</span> ( i = 0 ; i < nslits ; i++ )
+<a name="l02039"></a>02039     {
+<a name="l02040"></a>02040       neg_dist[i] = -correct_dist[i] ;
+<a name="l02041"></a>02041     }
+<a name="l02042"></a>02042       outcube2 = sinfo_new_fine_tune_cube_by_FFT( cube, neg_dist ) ;
+<a name="l02043"></a>02043      cpl_free(neg_dist);
+<a name="l02044"></a>02044       <span class="keywordflow">if</span> ( outcube2 == NULL )
+<a name="l02045"></a>02045     {
+<a name="l02046"></a>02046       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" could not fine tune the data cube\n"</span>) ;
+<a name="l02047"></a>02047       <span class="keywordflow">return</span> NULL ;
+<a name="l02048"></a>02048     }
+<a name="l02049"></a>02049     }
+<a name="l02050"></a>02050   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(method,<span class="stringliteral">"S"</span>)==0)
+<a name="l02051"></a>02051     {
+<a name="l02052"></a>02052       outcube2 = sinfo_new_fine_tune_cube_by_spline( cube, correct_dist ) ;
+<a name="l02053"></a>02053       <span class="keywordflow">if</span> ( outcube2 == NULL )
+<a name="l02054"></a>02054     {
+<a name="l02055"></a>02055       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" could not fine tune the data cube\n"</span>) ;
+<a name="l02056"></a>02056       <span class="keywordflow">return</span> NULL ;
+<a name="l02057"></a>02057     }
+<a name="l02058"></a>02058     }
+<a name="l02059"></a>02059   <span class="keywordflow">else</span>
+<a name="l02060"></a>02060     {
+<a name="l02061"></a>02061       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" wrong method indicator given!"</span>) ;
+<a name="l02062"></a>02062       <span class="keywordflow">return</span> NULL ;
+<a name="l02063"></a>02063     }
+<a name="l02064"></a>02064 
+<a name="l02065"></a>02065 
+<a name="l02066"></a>02066 
+<a name="l02067"></a>02067 <span class="keywordflow">return</span> outcube2;
+<a name="l02068"></a>02068 
+<a name="l02069"></a>02069 }
+<a name="l02070"></a>02070 
+<a name="l02071"></a>02071 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l02077"></a>02077 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l02078"></a>02078 sinfo_band sinfo_get_associated_filter(<span class="keyword">const</span> <span class="keywordtype">char</span> * f)
+<a name="l02079"></a>02079 {
+<a name="l02080"></a>02080     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"J"</span>))            <span class="keywordflow">return</span> SINFO_BAND_J ;
+<a name="l02081"></a>02081     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"Js"</span>))           <span class="keywordflow">return</span> SINFO_BAND_JS ;
+<a name="l02082"></a>02082     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"Z"</span>))            <span class="keywordflow">return</span> SINFO_BAND_Z ;
+<a name="l02083"></a>02083     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"SZ"</span>))           <span class="keywordflow">return</span> SINFO_BAND_SZ ;
+<a name="l02084"></a>02084     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"SH"</span>))           <span class="keywordflow">return</span> SINFO_BAND_SH ;
+<a name="l02085"></a>02085     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"H"</span>))            <span class="keywordflow">return</span> SINFO_BAND_H ;
+<a name="l02086"></a>02086     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"Ks"</span>))           <span class="keywordflow">return</span> SINFO_BAND_KS ;
+<a name="l02087"></a>02087     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"K"</span>))            <span class="keywordflow">return</span> SINFO_BAND_K ;
+<a name="l02088"></a>02088     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"SK"</span>))           <span class="keywordflow">return</span> SINFO_BAND_SK ;
+<a name="l02089"></a>02089     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"L"</span>))            <span class="keywordflow">return</span> SINFO_BAND_L ;
+<a name="l02090"></a>02090     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"SL"</span>))           <span class="keywordflow">return</span> SINFO_BAND_SL ;
+<a name="l02091"></a>02091     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"M"</span>))            <span class="keywordflow">return</span> SINFO_BAND_M ;
+<a name="l02092"></a>02092     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"M_NB"</span>))         <span class="keywordflow">return</span> SINFO_BAND_M ;
+<a name="l02093"></a>02093     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"NB_1.06"</span>))      <span class="keywordflow">return</span> SINFO_BAND_J ;
+<a name="l02094"></a>02094     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"NB_1.08"</span>))      <span class="keywordflow">return</span> SINFO_BAND_J ;
+<a name="l02095"></a>02095     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"NB_1.19"</span>))      <span class="keywordflow">return</span> SINFO_BAND_J ;
+<a name="l02096"></a>02096     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"NB_1.21"</span>))      <span class="keywordflow">return</span> SINFO_BAND_J ;
+<a name="l02097"></a>02097     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"NB_1.26"</span>))      <span class="keywordflow">return</span> SINFO_BAND_J ;
+<a name="l02098"></a>02098     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"NB_1.28"</span>))      <span class="keywordflow">return</span> SINFO_BAND_J ;
+<a name="l02099"></a>02099     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"NB_1.64"</span>))      <span class="keywordflow">return</span> SINFO_BAND_H ;
+<a name="l02100"></a>02100     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"NB_1.71"</span>))      <span class="keywordflow">return</span> SINFO_BAND_H ;
+<a name="l02101"></a>02101     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"NB_2.07"</span>))      <span class="keywordflow">return</span> SINFO_BAND_KS ;
+<a name="l02102"></a>02102     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"NB_2.09"</span>))      <span class="keywordflow">return</span> SINFO_BAND_KS ;
+<a name="l02103"></a>02103     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"NB_2.13"</span>))      <span class="keywordflow">return</span> SINFO_BAND_KS ;
+<a name="l02104"></a>02104     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"NB_2.17"</span>))      <span class="keywordflow">return</span> SINFO_BAND_KS ;
+<a name="l02105"></a>02105     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"NB_2.19"</span>))      <span class="keywordflow">return</span> SINFO_BAND_KS ;
+<a name="l02106"></a>02106     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"NB_2.25"</span>))      <span class="keywordflow">return</span> SINFO_BAND_KS ;
+<a name="l02107"></a>02107     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"NB_2.29"</span>))      <span class="keywordflow">return</span> SINFO_BAND_KS ;
+<a name="l02108"></a>02108     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"NB_2.34"</span>))      <span class="keywordflow">return</span> SINFO_BAND_KS ;
+<a name="l02109"></a>02109     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"NB_3.21"</span>))      <span class="keywordflow">return</span> SINFO_BAND_L ;
+<a name="l02110"></a>02110     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"NB_3.28"</span>))      <span class="keywordflow">return</span> SINFO_BAND_L ;
+<a name="l02111"></a>02111     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"NB_3.80"</span>))      <span class="keywordflow">return</span> SINFO_BAND_L ;
+<a name="l02112"></a>02112     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"NB_4.07"</span>))      <span class="keywordflow">return</span> SINFO_BAND_L ;
+<a name="l02113"></a>02113     <span class="keywordflow">return</span> SINFO_BAND_UNKNOWN ;
+<a name="l02114"></a>02114 }
+<a name="l02115"></a>02115 
+<a name="l02116"></a>02116 
+<a name="l02117"></a>02117 
+<a name="l02118"></a>02118 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l02124"></a>02124 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l02125"></a>02125 sinfo_band sinfo_get_bbfilter(<span class="keyword">const</span> <span class="keywordtype">char</span> * f)
+<a name="l02126"></a>02126 {
+<a name="l02127"></a>02127     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"J"</span>))            <span class="keywordflow">return</span> SINFO_BAND_J ;
+<a name="l02128"></a>02128     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"J+Block"</span>))      <span class="keywordflow">return</span> SINFO_BAND_J ;
+<a name="l02129"></a>02129     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"Js"</span>))           <span class="keywordflow">return</span> SINFO_BAND_J ;
+<a name="l02130"></a>02130     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"Z"</span>))            <span class="keywordflow">return</span> SINFO_BAND_J ;
+<a name="l02131"></a>02131     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"SZ"</span>))           <span class="keywordflow">return</span> SINFO_BAND_J ;
+<a name="l02132"></a>02132     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"SH"</span>))           <span class="keywordflow">return</span> SINFO_BAND_H ;
+<a name="l02133"></a>02133     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"H"</span>))            <span class="keywordflow">return</span> SINFO_BAND_H ;
+<a name="l02134"></a>02134     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"Ks"</span>))           <span class="keywordflow">return</span> SINFO_BAND_KS ;
+<a name="l02135"></a>02135     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"K"</span>))            <span class="keywordflow">return</span> SINFO_BAND_K ;
+<a name="l02136"></a>02136     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"SK"</span>))           <span class="keywordflow">return</span> SINFO_BAND_K ;
+<a name="l02137"></a>02137     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"L"</span>))            <span class="keywordflow">return</span> SINFO_BAND_L ;
+<a name="l02138"></a>02138     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"SL"</span>))           <span class="keywordflow">return</span> SINFO_BAND_L ;
+<a name="l02139"></a>02139     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"M"</span>))            <span class="keywordflow">return</span> SINFO_BAND_M ;
+<a name="l02140"></a>02140     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"M_NB"</span>))         <span class="keywordflow">return</span> SINFO_BAND_M ;
+<a name="l02141"></a>02141     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"NB_1.06"</span>))      <span class="keywordflow">return</span> SINFO_BAND_J ;
+<a name="l02142"></a>02142     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"NB_1.08"</span>))      <span class="keywordflow">return</span> SINFO_BAND_J ;
+<a name="l02143"></a>02143     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"NB_1.19"</span>))      <span class="keywordflow">return</span> SINFO_BAND_J ;
+<a name="l02144"></a>02144     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"NB_1.21"</span>))      <span class="keywordflow">return</span> SINFO_BAND_J ;
+<a name="l02145"></a>02145     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"NB_1.26"</span>))      <span class="keywordflow">return</span> SINFO_BAND_J ;
+<a name="l02146"></a>02146     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"NB_1.28"</span>))      <span class="keywordflow">return</span> SINFO_BAND_J ;
+<a name="l02147"></a>02147     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"NB_1.64"</span>))      <span class="keywordflow">return</span> SINFO_BAND_H ;
+<a name="l02148"></a>02148     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"NB_1.71"</span>))      <span class="keywordflow">return</span> SINFO_BAND_H ;
+<a name="l02149"></a>02149     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"NB_2.07"</span>))      <span class="keywordflow">return</span> SINFO_BAND_KS ;
+<a name="l02150"></a>02150     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"NB_2.09"</span>))      <span class="keywordflow">return</span> SINFO_BAND_KS ;
+<a name="l02151"></a>02151     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"NB_2.13"</span>))      <span class="keywordflow">return</span> SINFO_BAND_KS ;
+<a name="l02152"></a>02152     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"NB_2.17"</span>))      <span class="keywordflow">return</span> SINFO_BAND_KS ;
+<a name="l02153"></a>02153     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"NB_2.19"</span>))      <span class="keywordflow">return</span> SINFO_BAND_KS ;
+<a name="l02154"></a>02154     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"NB_2.25"</span>))      <span class="keywordflow">return</span> SINFO_BAND_KS ;
+<a name="l02155"></a>02155     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"NB_2.29"</span>))      <span class="keywordflow">return</span> SINFO_BAND_KS ;
+<a name="l02156"></a>02156     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"NB_2.34"</span>))      <span class="keywordflow">return</span> SINFO_BAND_KS ;
+<a name="l02157"></a>02157     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"NB_3.21"</span>))      <span class="keywordflow">return</span> SINFO_BAND_L ;
+<a name="l02158"></a>02158     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"NB_3.28"</span>))      <span class="keywordflow">return</span> SINFO_BAND_L ;
+<a name="l02159"></a>02159     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"NB_3.80"</span>))      <span class="keywordflow">return</span> SINFO_BAND_L ;
+<a name="l02160"></a>02160     <span class="keywordflow">if</span> (!strcmp(f, <span class="stringliteral">"NB_4.07"</span>))      <span class="keywordflow">return</span> SINFO_BAND_L ;
+<a name="l02161"></a>02161     <span class="keywordflow">return</span> SINFO_BAND_UNKNOWN ;
+<a name="l02162"></a>02162 }
+<a name="l02163"></a>02163 
+<a name="l02164"></a>02164 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__utilities__scired_8h_source.html b/html/sinfo__utilities__scired_8h_source.html
new file mode 100644
index 0000000..ffd77e4
--- /dev/null
+++ b/html/sinfo__utilities__scired_8h_source.html
@@ -0,0 +1,162 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_utilities_scired.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_utilities_scired.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#ifndef SINFO_UTILITIES_SCIRED_H</span>
+<a name="l00002"></a>00002 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_UTILITIES_SCIRED_H</span>
+<a name="l00003"></a>00003 <span class="preprocessor"></span><span class="comment">/*</span>
+<a name="l00004"></a>00004 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00005"></a>00005 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00006"></a>00006 <span class="comment"> *</span>
+<a name="l00007"></a>00007 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00008"></a>00008 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00009"></a>00009 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00010"></a>00010 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00011"></a>00011 <span class="comment"> *</span>
+<a name="l00012"></a>00012 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00013"></a>00013 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00014"></a>00014 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00015"></a>00015 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00016"></a>00016 <span class="comment"> *</span>
+<a name="l00017"></a>00017 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00018"></a>00018 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00019"></a>00019 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00020"></a>00020 <span class="comment"> */</span>
+<a name="l00021"></a>00021 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00022"></a>00022 <span class="preprocessor">#include "sinfo_tpl_utils.h"</span>
+<a name="l00023"></a>00023 <span class="preprocessor">#include "sinfo_key_names.h"</span>
+<a name="l00024"></a>00024 <span class="preprocessor">#include "sinfo_pro_types.h"</span>
+<a name="l00025"></a>00025 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00026"></a>00026 <span class="preprocessor">#include "sinfo_cube_construct.h"</span>
+<a name="l00027"></a>00027 <span class="preprocessor">#include "sinfo_utilities.h"</span>
+<a name="l00028"></a>00028 <span class="preprocessor">#include "sinfo_object_cfg.h"</span>
+<a name="l00029"></a>00029 
+<a name="l00030"></a>00030 <span class="keywordtype">float</span>*
+<a name="l00031"></a>00031 sinfo_read_distances(<span class="keyword">const</span> <span class="keywordtype">int</span> nslits, <span class="keyword">const</span> <span class="keywordtype">char</span>* distlist);
+<a name="l00032"></a>00032 
+<a name="l00033"></a>00033 <span class="keywordtype">float</span>** 
+<a name="l00034"></a>00034 sinfo_read_slitlets_edges(<span class="keyword">const</span> <span class="keywordtype">int</span> nslits, <span class="keyword">const</span> <span class="keywordtype">char</span>* poslist);
+<a name="l00035"></a>00035 
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="keywordtype">int</span> 
+<a name="l00038"></a>00038 sinfo_check_input_data(object_config* cfg);  
+<a name="l00039"></a>00039 
+<a name="l00040"></a>00040 <span class="keywordtype">int</span>
+<a name="l00041"></a>00041 sinfo_auto_size_cube(<span class="keywordtype">float</span>* offsetx, 
+<a name="l00042"></a>00042                       <span class="keywordtype">float</span>* offsety,
+<a name="l00043"></a>00043               <span class="keyword">const</span> <span class="keywordtype">int</span> nframes, 
+<a name="l00044"></a>00044                     <span class="keywordtype">float</span>* ref_offx, 
+<a name="l00045"></a>00045                     <span class="keywordtype">float</span>* ref_offy,
+<a name="l00046"></a>00046                     <span class="keywordtype">int</span>* size_x,
+<a name="l00047"></a>00047              <span class="keywordtype">int</span>* size_y);
+<a name="l00048"></a>00048 
+<a name="l00049"></a>00049 <span class="keywordtype">int</span>
+<a name="l00050"></a>00050 sinfo_auto_size_cube4(<span class="keywordtype">float</span>* offsetx, 
+<a name="l00051"></a>00051                       <span class="keywordtype">float</span>* offsety,
+<a name="l00052"></a>00052               <span class="keyword">const</span> <span class="keywordtype">int</span> nframes, 
+<a name="l00053"></a>00053                     <span class="keywordtype">float</span>* ref_offx, 
+<a name="l00054"></a>00054                     <span class="keywordtype">float</span>* ref_offy,
+<a name="l00055"></a>00055                     <span class="keywordtype">int</span>* size_x,
+<a name="l00056"></a>00056               <span class="keywordtype">int</span>* size_y);
+<a name="l00057"></a>00057 
+<a name="l00058"></a>00058 
+<a name="l00059"></a>00059 
+<a name="l00060"></a>00060 <span class="keywordtype">int</span>
+<a name="l00061"></a>00061 sinfo_auto_size_cube5(object_config * cfg, 
+<a name="l00062"></a>00062                     <span class="keywordtype">float</span>* ref_offx, <span class="keywordtype">float</span>* ref_offy,
+<a name="l00063"></a>00063                     <span class="keywordtype">float</span>* min_offx, <span class="keywordtype">float</span>* min_offy,
+<a name="l00064"></a>00064               <span class="keywordtype">float</span>* max_offx, <span class="keywordtype">float</span>* max_offy);
+<a name="l00065"></a>00065 
+<a name="l00066"></a>00066 cpl_imagelist * 
+<a name="l00067"></a>00067 sinfo_new_cube_getvig(
+<a name="l00068"></a>00068         cpl_imagelist *       cube_in,
+<a name="l00069"></a>00069         <span class="keywordtype">int</span>             loleft_x,
+<a name="l00070"></a>00070         <span class="keywordtype">int</span>             loleft_y,
+<a name="l00071"></a>00071         <span class="keywordtype">int</span>             upright_x,
+<a name="l00072"></a>00072         <span class="keywordtype">int</span>             upright_y);
+<a name="l00073"></a>00073 
+<a name="l00074"></a>00074 
+<a name="l00075"></a>00075 <span class="keywordtype">int</span>
+<a name="l00076"></a>00076 sinfo_new_set_wcs_cube(cpl_imagelist* cub, <span class="keyword">const</span> <span class="keywordtype">char</span>* name, <span class="keywordtype">double</span> clambda, 
+<a name="l00077"></a>00077          <span class="keywordtype">double</span> dis, <span class="keywordtype">double</span> cpix, <span class="keywordtype">double</span> cx, <span class="keywordtype">double</span> cy);
+<a name="l00078"></a>00078 
+<a name="l00079"></a>00079 <span class="keywordtype">int</span>
+<a name="l00080"></a>00080 sinfo_new_set_wcs_image(cpl_image* img, <span class="keyword">const</span> <span class="keywordtype">char</span>* name,  
+<a name="l00081"></a>00081                         <span class="keywordtype">double</span> cx, <span class="keywordtype">double</span> cy);
+<a name="l00082"></a>00082 
+<a name="l00083"></a>00083 <span class="keywordtype">int</span>
+<a name="l00084"></a>00084 sinfo_new_set_wcs_spectrum(cpl_image* img, <span class="keyword">const</span> <span class="keywordtype">char</span>* name,   
+<a name="l00085"></a>00085                            <span class="keywordtype">double</span> clambda, <span class="keywordtype">double</span> dis, <span class="keywordtype">double</span> cpix);
+<a name="l00086"></a>00086 
+<a name="l00087"></a>00087 
+<a name="l00088"></a>00088 
+<a name="l00089"></a>00089 cpl_imagelist* 
+<a name="l00090"></a>00090 sinfo_new_fine_tune(cpl_imagelist* cube,<span class="keywordtype">float</span>* correct_dist, 
+<a name="l00091"></a>00091                     <span class="keyword">const</span> <span class="keywordtype">char</span>* method, <span class="keyword">const</span> <span class="keywordtype">int</span> order, <span class="keyword">const</span> <span class="keywordtype">int</span> nslits) ;
+<a name="l00092"></a>00092 
+<a name="l00093"></a>00093 <span class="keywordtype">int</span>
+<a name="l00094"></a>00094 sinfo_new_object_assign_offset(<span class="keyword">const</span> <span class="keywordtype">char</span>* name, <span class="keyword">const</span> <span class="keywordtype">int</span> n, <span class="keywordtype">double</span>* ref_offx, 
+<a name="l00095"></a>00095                                <span class="keywordtype">double</span>* ref_offy, <span class="keywordtype">float</span>** offsetx, 
+<a name="l00096"></a>00096                                <span class="keywordtype">float</span>** offsety);
+<a name="l00097"></a>00097 
+<a name="l00098"></a>00098 <span class="keywordtype">int</span>
+<a name="l00099"></a>00099 sinfo_new_assign_offset2(<span class="keyword">const</span> <span class="keywordtype">int</span> n,
+<a name="l00100"></a>00100                         <span class="keyword">const</span> <span class="keywordtype">char</span>* name,
+<a name="l00101"></a>00101                         <span class="keywordtype">float</span>* offsetx,
+<a name="l00102"></a>00102                         <span class="keywordtype">float</span>* offsety,
+<a name="l00103"></a>00103                         <span class="keyword">const</span> <span class="keywordtype">float</span> ref_offx,
+<a name="l00104"></a>00104              <span class="keyword">const</span> <span class="keywordtype">float</span> ref_offy);
+<a name="l00105"></a>00105 
+<a name="l00106"></a>00106 <span class="keywordtype">int</span>
+<a name="l00107"></a>00107 sinfo_new_assign_offset(<span class="keyword">const</span> <span class="keywordtype">int</span> n,<span class="keyword">const</span> <span class="keywordtype">char</span>* name,<span class="keywordtype">float</span>* offsetx,
+<a name="l00108"></a>00108                         <span class="keywordtype">float</span>* offsety,<span class="keyword">const</span> <span class="keywordtype">float</span> ref_offx,
+<a name="l00109"></a>00109                         <span class="keyword">const</span> <span class="keywordtype">float</span> ref_offy);
+<a name="l00110"></a>00110 
+<a name="l00111"></a>00111 
+<a name="l00112"></a>00112 cpl_imagelist** 
+<a name="l00113"></a>00113 sinfo_new_sinfoni_correct_median(cpl_imagelist** cubeobject, <span class="keyword">const</span> <span class="keywordtype">int</span> n_cubes);
+<a name="l00114"></a>00114 
+<a name="l00115"></a>00115 cpl_imagelist** 
+<a name="l00116"></a>00116 sinfo_new_sinfoni_correct_sky2(cpl_imagelist** cubes,
+<a name="l00117"></a>00117                   <span class="keyword">const</span> <span class="keywordtype">int</span> nc,
+<a name="l00118"></a>00118                   cpl_imagelist* sky_cube,
+<a name="l00119"></a>00119                               cpl_imagelist* med_cube,
+<a name="l00120"></a>00120                               cpl_imagelist* msk_cube,
+<a name="l00121"></a>00121                               cpl_imagelist* avg_cube,
+<a name="l00122"></a>00122                               cpl_imagelist* sig_cube,
+<a name="l00123"></a>00123                               cpl_imagelist* ovr_cube);
+<a name="l00124"></a>00124 
+<a name="l00125"></a>00125 cpl_imagelist** 
+<a name="l00126"></a>00126 sinfo_new_sinfoni_correct_sky(cpl_imagelist** cubes,
+<a name="l00127"></a>00127                   <span class="keyword">const</span> <span class="keywordtype">int</span> nc,
+<a name="l00128"></a>00128                   cpl_imagelist* sky_cube);
+<a name="l00129"></a>00129 
+<a name="l00130"></a>00130 <span class="keywordtype">int</span> 
+<a name="l00131"></a>00131 sinfo_new_sinfoni_correct_median_it(cpl_imagelist** inp);
+<a name="l00132"></a>00132 
+<a name="l00133"></a>00133 
+<a name="l00134"></a>00134 <span class="keywordtype">int</span> sinfo_calib_flux_std(
+<a name="l00135"></a>00135         <span class="keyword">const</span> <span class="keywordtype">char</span>  *   seds_file,
+<a name="l00136"></a>00136         <span class="keyword">const</span> <span class="keywordtype">char</span>  *   stdstars,
+<a name="l00137"></a>00137         <span class="keyword">const</span> <span class="keywordtype">char</span>  *   filter,
+<a name="l00138"></a>00138         cpl_frame   *   frame,
+<a name="l00139"></a>00139         cpl_table   *   tab,
+<a name="l00140"></a>00140         <span class="keywordtype">double</span>          mag);
+<a name="l00141"></a>00141 
+<a name="l00142"></a>00142 
+<a name="l00143"></a>00143 sinfo_band sinfo_get_associated_filter(<span class="keyword">const</span> <span class="keywordtype">char</span> * f);
+<a name="l00144"></a>00144 sinfo_band sinfo_get_bbfilter(<span class="keyword">const</span> <span class="keywordtype">char</span> * f);
+<a name="l00145"></a>00145 
+<a name="l00146"></a>00146 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__utils_8c_source.html b/html/sinfo__utils_8c_source.html
new file mode 100644
index 0000000..399fc0f
--- /dev/null
+++ b/html/sinfo__utils_8c_source.html
@@ -0,0 +1,128 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_utils.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_utils.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*                                                                           *</span>
+<a name="l00002"></a>00002 <span class="comment"> *   This file is part of the ESO SINFONI Pipeline                           *</span>
+<a name="l00003"></a>00003 <span class="comment"> *   Copyright (C) 2004,2005 European Southern Observatory                   *</span>
+<a name="l00004"></a>00004 <span class="comment"> *                                                                           *</span>
+<a name="l00005"></a>00005 <span class="comment"> *   This library is free software; you can redistribute it and/or modify    *</span>
+<a name="l00006"></a>00006 <span class="comment"> *   it under the terms of the GNU General Public License as published by    *</span>
+<a name="l00007"></a>00007 <span class="comment"> *   the Free Software Foundation; either version 2 of the License, or       *</span>
+<a name="l00008"></a>00008 <span class="comment"> *   (at your option) any later version.                                     *</span>
+<a name="l00009"></a>00009 <span class="comment"> *                                                                           *</span>
+<a name="l00010"></a>00010 <span class="comment"> *   This program is distributed in the hope that it will be useful,         *</span>
+<a name="l00011"></a>00011 <span class="comment"> *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *</span>
+<a name="l00012"></a>00012 <span class="comment"> *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *</span>
+<a name="l00013"></a>00013 <span class="comment"> *   GNU General Public License for more details.                            *</span>
+<a name="l00014"></a>00014 <span class="comment"> *                                                                           *</span>
+<a name="l00015"></a>00015 <span class="comment"> *   You should have received a copy of the GNU General Public License       *</span>
+<a name="l00016"></a>00016 <span class="comment"> *   along with this program; if not, write to the Free Software             *</span>
+<a name="l00017"></a>00017 <span class="comment"> *   Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA    *</span>
+<a name="l00018"></a>00018 <span class="comment"> *                                                                           */</span>
+<a name="l00019"></a>00019 <span class="comment">/*</span>
+<a name="l00020"></a>00020 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Date: 2012/03/03 10:17:31 $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Revision: 1.7 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Log: sinfo_utils.c,v $</span>
+<a name="l00025"></a>00025 <span class="comment"> * Revision 1.7  2012/03/03 10:17:31  amodigli</span>
+<a name="l00026"></a>00026 <span class="comment"> * fixed some doxygen warnings</span>
+<a name="l00027"></a>00027 <span class="comment"> *</span>
+<a name="l00028"></a>00028 <span class="comment"> * Revision 1.6  2010/09/30 14:00:03  kmirny</span>
+<a name="l00029"></a>00029 <span class="comment"> * moving function from wavecal to utils</span>
+<a name="l00030"></a>00030 <span class="comment"> *</span>
+<a name="l00031"></a>00031 <span class="comment"> * Revision 1.5  2007/05/25 06:28:35  amodigli</span>
+<a name="l00032"></a>00032 <span class="comment"> * fixed plugintest warnings</span>
+<a name="l00033"></a>00033 <span class="comment"> *</span>
+<a name="l00034"></a>00034 <span class="comment"> * Revision 1.4  2006/11/07 07:13:25  amodigli</span>
+<a name="l00035"></a>00035 <span class="comment"> * added doxygen</span>
+<a name="l00036"></a>00036 <span class="comment"> *</span>
+<a name="l00037"></a>00037 <span class="comment"> * Revision 1.3  2006/11/04 15:28:36  amodigli</span>
+<a name="l00038"></a>00038 <span class="comment"> * doxygen</span>
+<a name="l00039"></a>00039 <span class="comment"> *</span>
+<a name="l00040"></a>00040 <span class="comment"> * Revision 1.2  2006/10/17 07:02:24  amodigli</span>
+<a name="l00041"></a>00041 <span class="comment"> * shorten line length</span>
+<a name="l00042"></a>00042 <span class="comment"> *</span>
+<a name="l00043"></a>00043 <span class="comment"> * Revision 1.1  2006/08/09 12:26:36  amodigli</span>
+<a name="l00044"></a>00044 <span class="comment"> * added sinfo_utils.h sinfo_utils.c</span>
+<a name="l00045"></a>00045 <span class="comment"> *</span>
+<a name="l00046"></a>00046 <span class="comment"></span>
+<a name="l00047"></a>00047 <span class="comment"> */</span>
+<a name="l00048"></a>00048 
+<a name="l00049"></a>00049 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00050"></a>00050 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00051"></a>00051 <span class="preprocessor">#endif</span>
+<a name="l00052"></a>00052 <span class="preprocessor"></span>
+<a name="l00054"></a>00054 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00061"></a>00061 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00062"></a>00062 
+<a name="l00063"></a>00063 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00064"></a>00064 <span class="comment">                            Includes</span>
+<a name="l00065"></a>00065 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00066"></a>00066 
+<a name="l00067"></a>00067 <span class="preprocessor">#include <sinfo_utils.h></span>
+<a name="l00074"></a>00074 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00075"></a>00075 <span class="comment">                            Functions prototypes</span>
+<a name="l00076"></a>00076 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00077"></a>00077 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00078"></a>00078 <span class="comment">                            Implementation</span>
+<a name="l00079"></a>00079 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00080"></a>00080 
+<a name="l00081"></a>00081 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00090"></a>00090 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00091"></a>00091 <span class="keywordtype">long</span>
+<a name="l00092"></a>00092 sinfo_round_double(<span class="keywordtype">double</span> x)
+<a name="l00093"></a>00093 {
+<a name="l00094"></a>00094     <span class="keywordflow">return</span> (x >=0) ? (long)(x+0.5) : (long)(x-0.5);
+<a name="l00095"></a>00095 }
+<a name="l00101"></a>00101 <span class="keywordtype">int</span>
+<a name="l00102"></a>00102 sinfo_parameter_get_default_flag ( <span class="keyword">const</span> cpl_parameter* p )
+<a name="l00103"></a>00103 {
+<a name="l00104"></a>00104    <span class="keywordtype">int</span> flag_gasgano=0;
+<a name="l00105"></a>00105    <span class="keywordtype">int</span> flag_norm=0;
+<a name="l00106"></a>00106    <span class="keywordtype">int</span> flag=0;
+<a name="l00107"></a>00107    cpl_type type =0;
+<a name="l00108"></a>00108 
+<a name="l00109"></a>00109    flag_norm = ( cpl_parameter_get_default_flag ( p ) == 0 ) ? 1 : 0;
+<a name="l00110"></a>00110    type=cpl_parameter_get_type ( p );
+<a name="l00111"></a>00111 
+<a name="l00112"></a>00112    <span class="keywordflow">switch</span> ( type )
+<a name="l00113"></a>00113    {
+<a name="l00114"></a>00114       <span class="keywordflow">case</span> CPL_TYPE_BOOL:
+<a name="l00115"></a>00115          flag_gasgano = ( cpl_parameter_get_default_bool ( p ) ==
+<a name="l00116"></a>00116                           cpl_parameter_get_bool ( p ) ) ? 1:0;
+<a name="l00117"></a>00117          <span class="keywordflow">break</span>;
+<a name="l00118"></a>00118       <span class="keywordflow">case</span> CPL_TYPE_INT:
+<a name="l00119"></a>00119          flag_gasgano = ( cpl_parameter_get_default_int ( p ) ==
+<a name="l00120"></a>00120                           cpl_parameter_get_int ( p ) ) ? 1:0;
+<a name="l00121"></a>00121          <span class="keywordflow">break</span>;
+<a name="l00122"></a>00122       <span class="keywordflow">case</span> CPL_TYPE_DOUBLE:
+<a name="l00123"></a>00123          flag_gasgano = ( cpl_parameter_get_default_double ( p ) ==
+<a name="l00124"></a>00124                           cpl_parameter_get_double ( p ) ) ? 1:0;
+<a name="l00125"></a>00125          <span class="keywordflow">break</span>;
+<a name="l00126"></a>00126       <span class="keywordflow">case</span> CPL_TYPE_STRING:
+<a name="l00127"></a>00127          flag_gasgano = ( cpl_parameter_get_default_string ( p ) ==
+<a name="l00128"></a>00128                           cpl_parameter_get_string ( p ) ) ? 1:0;
+<a name="l00129"></a>00129          <span class="keywordflow">break</span>;
+<a name="l00130"></a>00130 
+<a name="l00131"></a>00131       <span class="keywordflow">default</span>:
+<a name="l00132"></a>00132          cpl_msg_error (cpl_func, <span class="stringliteral">"type not supported"</span> );
+<a name="l00133"></a>00133    }
+<a name="l00134"></a>00134 
+<a name="l00135"></a>00135    flag = ( flag_gasgano && flag_norm ) ? 0 : 1;
+<a name="l00136"></a>00136 
+<a name="l00137"></a>00137    <span class="keywordflow">return</span> flag;
+<a name="l00138"></a>00138 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__utils_8h_source.html b/html/sinfo__utils_8h_source.html
new file mode 100644
index 0000000..a2bb6fe
--- /dev/null
+++ b/html/sinfo__utils_8h_source.html
@@ -0,0 +1,115 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_utils.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_utils.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFO Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: kmirny $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2010/09/30 14:00:03 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.5 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> *</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 <span class="preprocessor">#ifndef SINFO_UTILS_H</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_UTILS_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span>
+<a name="l00030"></a>00030 
+<a name="l00031"></a>00031 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00032"></a>00032 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00033"></a>00033 <span class="preprocessor">#endif</span>
+<a name="l00034"></a>00034 <span class="preprocessor"></span><span class="preprocessor">#include <math.h></span>
+<a name="l00035"></a>00035 <span class="preprocessor">#include <sinfo_msg.h></span>
+<a name="l00036"></a>00036 <span class="preprocessor">#include <sinfo_error.h></span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00038"></a>00038 <span class="comment">/*</span>
+<a name="l00039"></a>00039 <span class="comment"> * The purpose of this target is to</span>
+<a name="l00040"></a>00040 <span class="comment"> * decrease the amount of messages</span>
+<a name="l00041"></a>00041 <span class="comment"> * printed at the debug level.</span>
+<a name="l00042"></a>00042 <span class="comment"> *</span>
+<a name="l00043"></a>00043 <span class="comment"> * If set to non-zero, even more messages</span>
+<a name="l00044"></a>00044 <span class="comment"> * are printed at the debug level</span>
+<a name="l00045"></a>00045 <span class="comment"> * (sometimes 50 - 100 MB)</span>
+<a name="l00046"></a>00046 <span class="comment"> *</span>
+<a name="l00047"></a>00047 <span class="comment"> */</span>
+<a name="l00048"></a>00048 <span class="preprocessor">#ifndef WANT_BIG_LOGFILE</span>
+<a name="l00049"></a>00049 <span class="preprocessor"></span><span class="preprocessor">#define WANT_BIG_LOGFILE 0</span>
+<a name="l00050"></a>00050 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
+<a name="l00051"></a>00051 <span class="preprocessor"></span>
+<a name="l00052"></a>00052 <span class="comment">/*</span>
+<a name="l00053"></a>00053 <span class="comment"> * Set to 1 to show timing</span>
+<a name="l00054"></a>00054 <span class="comment"> * information on msg-level = info</span>
+<a name="l00055"></a>00055 <span class="comment"> */</span>
+<a name="l00056"></a>00056 <span class="preprocessor">#ifndef WANT_TIME_MEASURE</span>
+<a name="l00057"></a>00057 <span class="preprocessor"></span><span class="preprocessor">#define WANT_TIME_MEASURE 0</span>
+<a name="l00058"></a>00058 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
+<a name="l00059"></a>00059 <span class="preprocessor"></span>
+<a name="l00060"></a>00060 
+<a name="l00061"></a>00061 <span class="preprocessor">#if WANT_TIME_MEASURE</span>
+<a name="l00062"></a>00062 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_TIME_START(what) sinfo_msg("Timing (%s, l%d) %s start", \</span>
+<a name="l00063"></a>00063 <span class="preprocessor">                                       __FILE__, __LINE__, what)</span>
+<a name="l00064"></a>00064 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_TIME_END         sinfo_msg("Timing (%s, l%d) end", \</span>
+<a name="l00065"></a>00065 <span class="preprocessor">                                       __FILE__, __LINE__)</span>
+<a name="l00066"></a>00066 <span class="preprocessor"></span><span class="preprocessor">#else</span>
+<a name="l00067"></a>00067 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_TIME_START(what) sinfo_msg_debug("Timing (%s, l%d) %s start", \</span>
+<a name="l00068"></a>00068 <span class="preprocessor">                                             __FILE__, __LINE__, what)</span>
+<a name="l00069"></a>00069 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_TIME_END         sinfo_msg_debug("Timing (%s, l%d) end", \</span>
+<a name="l00070"></a>00070 <span class="preprocessor">                                             __FILE__, __LINE__)</span>
+<a name="l00071"></a>00071 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
+<a name="l00072"></a>00072 <span class="preprocessor"></span>
+<a name="l00073"></a>00073 
+<a name="l00074"></a>00074 
+<a name="l00075"></a>00075 
+<a name="l00076"></a>00076 <span class="preprocessor">#ifndef stringify</span>
+<a name="l00077"></a>00077 <span class="preprocessor"></span><span class="preprocessor">#ifndef make_str</span>
+<a name="l00078"></a>00078 <span class="preprocessor"></span><span class="preprocessor">#define stringify(X) #X</span>
+<a name="l00079"></a>00079 <span class="preprocessor"></span><span class="preprocessor">#define make_str(X) stringify(X)</span>
+<a name="l00080"></a>00080 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
+<a name="l00081"></a>00081 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
+<a name="l00082"></a>00082 <span class="preprocessor"></span>
+<a name="l00083"></a>00083 <span class="preprocessor">#define TWOSQRT2LN2 2.35482004503095</span>
+<a name="l00084"></a>00084 <span class="preprocessor"></span>
+<a name="l00085"></a>00085 <span class="preprocessor">#ifndef M_PI</span>
+<a name="l00086"></a>00086 <span class="preprocessor"></span><span class="preprocessor">#define M_PI 3.1415926535897932384626433832795</span>
+<a name="l00087"></a>00087 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
+<a name="l00088"></a>00088 <span class="preprocessor"></span>
+<a name="l00089"></a>00089 <span class="preprocessor">#define COS_DEG(x) cos(((x)/180)*M_PI)</span>
+<a name="l00090"></a>00090 <span class="preprocessor"></span><span class="preprocessor">#define SIN_DEG(x) sin(((x)/180)*M_PI)</span>
+<a name="l00091"></a>00091 <span class="preprocessor"></span><span class="preprocessor">#define ACOS_DEG(x) (acos(x)*180/M_PI)</span>
+<a name="l00092"></a>00092 <span class="preprocessor"></span>
+<a name="l00093"></a>00093 
+<a name="l00094"></a>00094 
+<a name="l00095"></a>00095 <span class="keywordtype">long</span> sinfo_round_double(<span class="keywordtype">double</span> x);
+<a name="l00096"></a>00096 <span class="keywordtype">int</span>
+<a name="l00097"></a>00097 sinfo_parameter_get_default_flag ( <span class="keyword">const</span> cpl_parameter* p );
+<a name="l00098"></a>00098 
+<a name="l00099"></a>00099 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__utils__wrappers_8c_source.html b/html/sinfo__utils__wrappers_8c_source.html
new file mode 100644
index 0000000..1ae6a25
--- /dev/null
+++ b/html/sinfo__utils__wrappers_8c_source.html
@@ -0,0 +1,335 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_utils_wrappers.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_utils_wrappers.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 
+<a name="l00002"></a>00002 <span class="comment">/*                                                                           *</span>
+<a name="l00003"></a>00003 <span class="comment"> *   This file is part of the ESO SINFO Pipeline                             *</span>
+<a name="l00004"></a>00004 <span class="comment"> *   Copyright (C) 2004,2005 European Southern Observatory                   *</span>
+<a name="l00005"></a>00005 <span class="comment"> *                                                                           *</span>
+<a name="l00006"></a>00006 <span class="comment"> *   This library is free software; you can redistribute it and/or modify    *</span>
+<a name="l00007"></a>00007 <span class="comment"> *   it under the terms of the GNU General Public License as published by    *</span>
+<a name="l00008"></a>00008 <span class="comment"> *   the Free Software Foundation; either version 2 of the License, or       *</span>
+<a name="l00009"></a>00009 <span class="comment"> *   (at your option) any later version.                                     *</span>
+<a name="l00010"></a>00010 <span class="comment"> *                                                                           *</span>
+<a name="l00011"></a>00011 <span class="comment"> *   This program is distributed in the hope that it will be useful,         *</span>
+<a name="l00012"></a>00012 <span class="comment"> *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *</span>
+<a name="l00013"></a>00013 <span class="comment"> *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *</span>
+<a name="l00014"></a>00014 <span class="comment"> *   GNU General Public License for more details.                            *</span>
+<a name="l00015"></a>00015 <span class="comment"> *                                                                           *</span>
+<a name="l00016"></a>00016 <span class="comment"> *   You should have received a copy of the GNU General Public License       *</span>
+<a name="l00017"></a>00017 <span class="comment"> *   along with this program; if not, write to the Free Software             *</span>
+<a name="l00018"></a>00018 <span class="comment"> *   Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA    *</span>
+<a name="l00019"></a>00019 <span class="comment"> *                                                                           */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 
+<a name="l00022"></a>00022 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00023"></a>00023 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00024"></a>00024 <span class="preprocessor">#endif</span>
+<a name="l00025"></a>00025 <span class="preprocessor"></span>
+<a name="l00027"></a>00027 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 
+<a name="l00038"></a>00038 <span class="preprocessor">#include <sinfo_utils_wrappers.h></span>
+<a name="l00039"></a>00039 <span class="preprocessor">#include <sinfo_functions.h></span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include <sinfo_dump.h></span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include <sinfo_utils.h></span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include <sinfo_error.h></span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00044"></a>00044 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00045"></a>00045 
+<a name="l00046"></a>00046 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00058"></a>00058 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00059"></a>00059 cpl_error_code
+<a name="l00060"></a>00060 sinfo_sort_table_1(cpl_table *t, <span class="keyword">const</span> <span class="keywordtype">char</span> *column, cpl_boolean reverse)
+<a name="l00061"></a>00061 {
+<a name="l00062"></a>00062     cpl_propertylist *plist = NULL;
+<a name="l00063"></a>00063     
+<a name="l00064"></a>00064     assure(t != NULL, CPL_ERROR_NULL_INPUT, <span class="stringliteral">"Null table"</span>);
+<a name="l00065"></a>00065     assure(cpl_table_has_column(t, column), CPL_ERROR_ILLEGAL_INPUT, 
+<a name="l00066"></a>00066        <span class="stringliteral">"No column '%s'"</span>, column);
+<a name="l00067"></a>00067 
+<a name="l00068"></a>00068     check(( plist = cpl_propertylist_new(),
+<a name="l00069"></a>00069         cpl_propertylist_append_bool(plist, column, reverse)),
+<a name="l00070"></a>00070        <span class="stringliteral">"Could not create property list for sorting"</span>);
+<a name="l00071"></a>00071 
+<a name="l00072"></a>00072     check( cpl_table_sort(t, plist), <span class="stringliteral">"Could not sort table"</span>);
+<a name="l00073"></a>00073 
+<a name="l00074"></a>00074   cleanup:
+<a name="l00075"></a>00075     sinfo_free_propertylist(&plist);
+<a name="l00076"></a>00076     <span class="keywordflow">return</span> cpl_error_get_code();
+<a name="l00077"></a>00077 }
+<a name="l00078"></a>00078 
+<a name="l00079"></a>00079 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00095"></a>00095 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00096"></a>00096 cpl_error_code
+<a name="l00097"></a>00097 sinfo_sort_table_2(cpl_table *t, <span class="keyword">const</span> <span class="keywordtype">char</span> *column1, <span class="keyword">const</span> <span class="keywordtype">char</span> *column2, 
+<a name="l00098"></a>00098           cpl_boolean reverse1, cpl_boolean reverse2)
+<a name="l00099"></a>00099 {
+<a name="l00100"></a>00100     cpl_propertylist *plist = NULL;
+<a name="l00101"></a>00101     
+<a name="l00102"></a>00102     assure(t != NULL, CPL_ERROR_NULL_INPUT, <span class="stringliteral">"Null table"</span>);
+<a name="l00103"></a>00103     assure(cpl_table_has_column(t, column1), CPL_ERROR_ILLEGAL_INPUT, 
+<a name="l00104"></a>00104        <span class="stringliteral">"No column '%s'"</span>, column1);
+<a name="l00105"></a>00105     assure(cpl_table_has_column(t, column2), CPL_ERROR_ILLEGAL_INPUT,
+<a name="l00106"></a>00106        <span class="stringliteral">"No column '%s'"</span>, column2);
+<a name="l00107"></a>00107 
+<a name="l00108"></a>00108     check(( plist = cpl_propertylist_new(),
+<a name="l00109"></a>00109         cpl_propertylist_append_bool(plist, column1, reverse1),
+<a name="l00110"></a>00110         cpl_propertylist_append_bool(plist, column2, reverse2)),
+<a name="l00111"></a>00111        <span class="stringliteral">"Could not create property list for sorting"</span>);
+<a name="l00112"></a>00112     check( cpl_table_sort(t, plist), <span class="stringliteral">"Could not sort table"</span>);
+<a name="l00113"></a>00113     
+<a name="l00114"></a>00114   cleanup:
+<a name="l00115"></a>00115     sinfo_free_propertylist(&plist);
+<a name="l00116"></a>00116     <span class="keywordflow">return</span> cpl_error_get_code();
+<a name="l00117"></a>00117 }
+<a name="l00118"></a>00118 
+<a name="l00119"></a>00119 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00136"></a>00136 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00137"></a>00137 cpl_table *
+<a name="l00138"></a>00138 sinfo_extract_table_rows(<span class="keyword">const</span> cpl_table *t, <span class="keyword">const</span> <span class="keywordtype">char</span> *column,
+<a name="l00139"></a>00139             cpl_table_select_operator <span class="keyword">operator</span>, <span class="keywordtype">double</span> value)
+<a name="l00140"></a>00140 {
+<a name="l00141"></a>00141     cpl_table *result = NULL;
+<a name="l00142"></a>00142     assure( t != NULL, CPL_ERROR_NULL_INPUT, <span class="stringliteral">"Null table"</span>);
+<a name="l00143"></a>00143     assure( cpl_table_has_column(t, column), CPL_ERROR_INCOMPATIBLE_INPUT,
+<a name="l00144"></a>00144         <span class="stringliteral">"No such column: %s"</span>, column);
+<a name="l00145"></a>00145     
+<a name="l00146"></a>00146     <span class="comment">/* 1. Extract (duplicate) the entire table</span>
+<a name="l00147"></a>00147 <span class="comment">       2. remove rows *not* satisfying the criterion */</span>
+<a name="l00148"></a>00148 
+<a name="l00149"></a>00149     check(result = cpl_table_duplicate(t),<span class="stringliteral">"selecting"</span>);
+<a name="l00150"></a>00150     check(sinfo_select_table_rows(result, column, <span class="keyword">operator</span>, value),<span class="stringliteral">"select"</span>);
+<a name="l00151"></a>00151     check(cpl_table_not_selected(result),<span class="stringliteral">"Inverses selection"</span>);
+<a name="l00152"></a>00152     check(cpl_table_erase_selected(result),<span class="stringliteral">"erase selection"</span>);<span class="comment">//problems</span>
+<a name="l00153"></a>00153 
+<a name="l00154"></a>00154     <span class="comment">/*</span>
+<a name="l00155"></a>00155 <span class="comment">    check(( result = cpl_table_duplicate(t),</span>
+<a name="l00156"></a>00156 <span class="comment">        sinfo_select_table_rows(result, column, operator, value),</span>
+<a name="l00157"></a>00157 <span class="comment">        cpl_table_not_selected(result),  // Inverses selection </span>
+<a name="l00158"></a>00158 <span class="comment">        cpl_table_erase_selected(result)),</span>
+<a name="l00159"></a>00159 <span class="comment">       "Error extracting rows");</span>
+<a name="l00160"></a>00160 <span class="comment">    */</span>
+<a name="l00161"></a>00161     
+<a name="l00162"></a>00162   cleanup:
+<a name="l00163"></a>00163     <span class="keywordflow">if</span> (cpl_error_get_code() != CPL_ERROR_NONE)
+<a name="l00164"></a>00164     {
+<a name="l00165"></a>00165         sinfo_free_table(&result);
+<a name="l00166"></a>00166     }
+<a name="l00167"></a>00167     <span class="keywordflow">return</span> result;
+<a name="l00168"></a>00168 }
+<a name="l00169"></a>00169 
+<a name="l00170"></a>00170 
+<a name="l00171"></a>00171 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00188"></a>00188 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00189"></a>00189 
+<a name="l00190"></a>00190 <span class="keywordtype">int</span>
+<a name="l00191"></a>00191 sinfo_select_table_rows(cpl_table *t,  <span class="keyword">const</span> <span class="keywordtype">char</span> *column, 
+<a name="l00192"></a>00192                cpl_table_select_operator <span class="keyword">operator</span>, <span class="keywordtype">double</span> value)
+<a name="l00193"></a>00193 {
+<a name="l00194"></a>00194     <span class="keywordtype">int</span> result = 0;
+<a name="l00195"></a>00195     cpl_type type;
+<a name="l00196"></a>00196     assure( t != NULL, CPL_ERROR_NULL_INPUT, <span class="stringliteral">"Null table"</span>);
+<a name="l00197"></a>00197     assure( cpl_table_has_column(t, column), CPL_ERROR_INCOMPATIBLE_INPUT, 
+<a name="l00198"></a>00198         <span class="stringliteral">"No such column: %s"</span>, column);
+<a name="l00199"></a>00199 
+<a name="l00200"></a>00200     type = cpl_table_get_column_type(t, column);
+<a name="l00201"></a>00201 
+<a name="l00202"></a>00202     assure( type == CPL_TYPE_DOUBLE ||
+<a name="l00203"></a>00203         type == CPL_TYPE_INT, CPL_ERROR_INVALID_TYPE,
+<a name="l00204"></a>00204         <span class="stringliteral">"Column '%s' must be double or int. %s found"</span>, column, 
+<a name="l00205"></a>00205         sinfo_tostring_cpl_type(type));
+<a name="l00206"></a>00206 
+<a name="l00207"></a>00207     check( cpl_table_select_all(t), <span class="stringliteral">"Error selecting rows"</span>);
+<a name="l00208"></a>00208     
+<a name="l00209"></a>00209     <span class="keywordflow">if</span>      (type == CPL_TYPE_DOUBLE)
+<a name="l00210"></a>00210     {
+<a name="l00211"></a>00211         result = cpl_table_and_selected_double(t, column, <span class="keyword">operator</span>, value);
+<a name="l00212"></a>00212     }
+<a name="l00213"></a>00213     <span class="keywordflow">else</span> <span class="keywordflow">if</span> (type == CPL_TYPE_INT)
+<a name="l00214"></a>00214     {
+<a name="l00215"></a>00215         result = cpl_table_and_selected_int   (t, column, <span class="keyword">operator</span>, 
+<a name="l00216"></a>00216                              sinfo_round_double(value));
+<a name="l00217"></a>00217     }
+<a name="l00218"></a>00218     <span class="keywordflow">else</span> { <span class="comment">/*impossible*/</span> passure(CPL_FALSE, <span class="stringliteral">""</span>); }
+<a name="l00219"></a>00219     
+<a name="l00220"></a>00220   cleanup:
+<a name="l00221"></a>00221     <span class="keywordflow">return</span> result;
+<a name="l00222"></a>00222 
+<a name="l00223"></a>00223 }
+<a name="l00224"></a>00224 
+<a name="l00229"></a>00229 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00230"></a>00230 <span class="keywordtype">void</span> sinfo_free_parameter(cpl_parameter **p) 
+<a name="l00231"></a>00231 {<span class="keywordflow">if</span>(p){cpl_parameter_delete(*p);            *p = NULL;}}
+<a name="l00232"></a>00232 
+<a name="l00233"></a>00233 
+<a name="l00234"></a>00234 
+<a name="l00239"></a>00239 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00240"></a>00240 <span class="keywordtype">void</span> sinfo_free_apertures(cpl_apertures **a) 
+<a name="l00241"></a>00241 {<span class="keywordflow">if</span>(a){cpl_apertures_delete(*a);            *a = NULL;}}
+<a name="l00242"></a>00242 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00243"></a>00243 
+<a name="l00244"></a>00244 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00249"></a>00249 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00250"></a>00250 <span class="keywordtype">void</span> sinfo_free_image(cpl_image **i)  {<span class="keywordflow">if</span>(i){cpl_image_delete(*i); *i = NULL;}}
+<a name="l00251"></a>00251 
+<a name="l00252"></a>00252 
+<a name="l00253"></a>00253 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00258"></a>00258 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00259"></a>00259 <span class="keywordtype">void</span> sinfoni_free_vector(cpl_vector **v)  {<span class="keywordflow">if</span>(v){cpl_vector_delete(*v); *v = NULL;}}
+<a name="l00260"></a>00260 
+<a name="l00261"></a>00261 
+<a name="l00262"></a>00262 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00267"></a>00267 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00268"></a>00268 <span class="keywordtype">void</span> sinfo_free_array(cpl_array **i)  {<span class="keywordflow">if</span>(i){cpl_array_delete(*i); *i = NULL;}}
+<a name="l00269"></a>00269 
+<a name="l00270"></a>00270 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00275"></a>00275 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00276"></a>00276 <span class="keywordtype">void</span> sinfo_free_mask(cpl_mask **m)  {<span class="keywordflow">if</span>(m){cpl_mask_delete(*m); *m = NULL;}}
+<a name="l00277"></a>00277 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00282"></a>00282 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00283"></a>00283 <span class="keywordtype">void</span> sinfo_free_imagelist(cpl_imagelist **i) 
+<a name="l00284"></a>00284 {<span class="keywordflow">if</span>(i){cpl_imagelist_delete(*i);        *i = NULL;}}
+<a name="l00285"></a>00285 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00290"></a>00290 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00291"></a>00291 <span class="keywordtype">void</span> sinfo_free_table(cpl_table **t) {<span class="keywordflow">if</span>(t){cpl_table_delete(*t); *t = NULL;}}
+<a name="l00292"></a>00292 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00297"></a>00297 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00298"></a>00298 <span class="keywordtype">void</span> sinfo_free_propertylist(cpl_propertylist **p)   
+<a name="l00299"></a>00299 {<span class="keywordflow">if</span>(p){cpl_propertylist_delete(*p);     *p = NULL;}}
+<a name="l00300"></a>00300 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00305"></a>00305 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00306"></a>00306 <span class="keywordtype">void</span> sinfo_free_polynomial(cpl_polynomial **p)       
+<a name="l00307"></a>00307 {<span class="keywordflow">if</span>(p){cpl_polynomial_delete(*p);       *p = NULL;}}
+<a name="l00308"></a>00308 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00313"></a>00313 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00314"></a>00314 <span class="comment">/* similar also present in svd.c */</span>
+<a name="l00315"></a>00315 <span class="keywordtype">void</span> sinfoni_free_matrix(cpl_matrix **m) 
+<a name="l00316"></a>00316 {<span class="keywordflow">if</span>(m){cpl_matrix_delete(*m); *m = NULL;}}
+<a name="l00317"></a>00317 
+<a name="l00318"></a>00318 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00323"></a>00323 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00324"></a>00324 <span class="keywordtype">void</span> sinfo_free_parameterlist(cpl_parameterlist **p) 
+<a name="l00325"></a>00325 {<span class="keywordflow">if</span>(p){cpl_parameterlist_delete(*p);    *p = NULL;}}
+<a name="l00326"></a>00326 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00331"></a>00331 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00332"></a>00332 <span class="keywordtype">void</span> sinfo_free_frameset(cpl_frameset **f) 
+<a name="l00333"></a>00333 {<span class="keywordflow">if</span>(f){cpl_frameset_delete(*f);    *f = NULL;}}
+<a name="l00334"></a>00334 
+<a name="l00335"></a>00335 
+<a name="l00336"></a>00336 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00341"></a>00341 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00342"></a>00342 <span class="keywordtype">void</span> sinfo_free_frame(cpl_frame **f) 
+<a name="l00343"></a>00343 {<span class="keywordflow">if</span>(f){cpl_frame_delete(*f);    *f = NULL;}}
+<a name="l00344"></a>00344 
+<a name="l00345"></a>00345 
+<a name="l00346"></a>00346 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00351"></a>00351 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00352"></a>00352 <span class="keywordtype">void</span> sinfo_free_int(<span class="keywordtype">int</span> **i) {<span class="keywordflow">if</span>(i){cpl_free(*i);    *i = NULL;}}
+<a name="l00353"></a>00353 
+<a name="l00354"></a>00354 
+<a name="l00355"></a>00355 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00360"></a>00360 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00361"></a>00361 <span class="keywordtype">void</span> sinfo_free_float(<span class="keywordtype">float</span> **f) {<span class="keywordflow">if</span>(f){cpl_free(*f);    *f = NULL;}}
+<a name="l00362"></a>00362 
+<a name="l00363"></a>00363 
+<a name="l00364"></a>00364 
+<a name="l00365"></a>00365 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00370"></a>00370 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00371"></a>00371 <span class="keywordtype">void</span> sinfo_free_double(<span class="keywordtype">double</span> **d) {<span class="keywordflow">if</span>(d){cpl_free(*d);    *d = NULL;}}
+<a name="l00372"></a>00372 
+<a name="l00373"></a>00373 
+<a name="l00374"></a>00374 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00379"></a>00379 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00380"></a>00380 <span class="keywordtype">void</span> sinfo_free_array_imagelist(cpl_imagelist ***a) 
+<a name="l00381"></a>00381 {<span class="keywordflow">if</span>(*a){cpl_free(*a); *a = NULL;}}
+<a name="l00382"></a>00382 
+<a name="l00383"></a>00383 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00388"></a>00388 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00389"></a>00389 <span class="keywordtype">void</span> sinfo_free_array_image(cpl_image ***a) {<span class="keywordflow">if</span>(*a){cpl_free(*a); *a = NULL;}}
+<a name="l00390"></a>00390 
+<a name="l00391"></a>00391 
+<a name="l00392"></a>00392 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00398"></a>00398 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00399"></a>00399 <span class="keywordtype">void</span> sinfo_free_image_array(cpl_image ***a, <span class="keyword">const</span> <span class="keywordtype">int</span> n) 
+<a name="l00400"></a>00400 {
+<a name="l00401"></a>00401   <span class="keywordtype">int</span> i=0;
+<a name="l00402"></a>00402   <span class="keywordflow">if</span>((*a) != NULL) {
+<a name="l00403"></a>00403     <span class="keywordflow">for</span> (i=0; i < n; i++) {
+<a name="l00404"></a>00404       <span class="keywordflow">if</span>((*a)[i] != NULL) {
+<a name="l00405"></a>00405     sinfo_free_image(&(*a)[i]);
+<a name="l00406"></a>00406     (*a)[i]=NULL;
+<a name="l00407"></a>00407       }
+<a name="l00408"></a>00408     }
+<a name="l00409"></a>00409     sinfo_free_array_image(&(*a));
+<a name="l00410"></a>00410     *a=NULL;
+<a name="l00411"></a>00411   }
+<a name="l00412"></a>00412 }
+<a name="l00413"></a>00413 
+<a name="l00414"></a>00414 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00420"></a>00420 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00421"></a>00421 <span class="keywordtype">void</span> sinfo_free_float_array(<span class="keywordtype">float</span> ***a, <span class="keyword">const</span> <span class="keywordtype">int</span> n) 
+<a name="l00422"></a>00422 {
+<a name="l00423"></a>00423   <span class="keywordtype">int</span> i=0;
+<a name="l00424"></a>00424   <span class="keywordflow">if</span>((*a) != NULL) {
+<a name="l00425"></a>00425     <span class="keywordflow">for</span> (i=0; i < n; i++) {
+<a name="l00426"></a>00426       <span class="keywordflow">if</span>((*a)[i] != NULL) {
+<a name="l00427"></a>00427     sinfo_free_float(&(*a)[i]);
+<a name="l00428"></a>00428     (*a)[i]=NULL;
+<a name="l00429"></a>00429       }
+<a name="l00430"></a>00430     }
+<a name="l00431"></a>00431     cpl_free(*a);
+<a name="l00432"></a>00432     *a=NULL;
+<a name="l00433"></a>00433   }
+<a name="l00434"></a>00434 }
+<a name="l00435"></a>00435 
+<a name="l00436"></a>00436 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00441"></a>00441 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00442"></a>00442 
+<a name="l00443"></a>00443 <span class="keywordtype">void</span> 
+<a name="l00444"></a>00444 sinfo_free_my_vector(cpl_vector **v) {<span class="keywordflow">if</span>(v){cpl_vector_delete(*v);*v = NULL;}}
+<a name="l00445"></a>00445 
+<a name="l00446"></a>00446 
+<a name="l00447"></a>00447 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00452"></a>00452 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00453"></a>00453 
+<a name="l00454"></a>00454 <span class="keywordtype">void</span> 
+<a name="l00455"></a>00455 sinfo_free_bivector(cpl_bivector **bv) {
+<a name="l00456"></a>00456   <span class="keywordflow">if</span>(bv){
+<a name="l00457"></a>00457      cpl_bivector_delete(*bv);
+<a name="l00458"></a>00458      *bv = NULL;
+<a name="l00459"></a>00459   }
+<a name="l00460"></a>00460 }
+<a name="l00461"></a>00461 
+<a name="l00462"></a>00462 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00467"></a>00467 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00468"></a>00468 <span class="keywordtype">void</span> sinfo_free_stats(cpl_stats **s) {<span class="keywordflow">if</span>(s){cpl_stats_delete(*s); *s = NULL;}}
+<a name="l00469"></a>00469 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00474"></a>00474 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00475"></a>00475 <span class="keywordtype">void</span> 
+<a name="l00476"></a>00476 sinfo_unwrap_vector(cpl_vector **v) {<span class="keywordflow">if</span>(v){cpl_vector_unwrap(*v); *v = NULL;}}
+<a name="l00477"></a>00477 
+<a name="l00478"></a>00478 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00483"></a>00483 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00484"></a>00484 <span class="keywordtype">void</span> sinfo_unwrap_matrix(cpl_matrix **m) 
+<a name="l00485"></a>00485 {<span class="keywordflow">if</span>(m){cpl_matrix_unwrap(*m); *m = NULL;}}
+<a name="l00486"></a>00486 
+<a name="l00487"></a>00487 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00492"></a>00492 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00493"></a>00493 <span class="keywordtype">void</span> sinfo_unwrap_bivector_vectors(cpl_bivector **b) 
+<a name="l00494"></a>00494 {<span class="keywordflow">if</span>(b){cpl_bivector_unwrap_vectors(*b); *b = NULL;}}
+<a name="l00495"></a>00495 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__utils__wrappers_8h_source.html b/html/sinfo__utils__wrappers_8h_source.html
new file mode 100644
index 0000000..4a76cea
--- /dev/null
+++ b/html/sinfo__utils__wrappers_8h_source.html
@@ -0,0 +1,100 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_utils_wrappers.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_utils_wrappers.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 
+<a name="l00020"></a>00020 <span class="preprocessor">#ifndef SINFO_UTILS_WRAPPERS_H</span>
+<a name="l00021"></a>00021 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_UTILS_WRAPPERS_H</span>
+<a name="l00022"></a>00022 <span class="preprocessor"></span>
+<a name="l00023"></a>00023 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00024"></a>00024 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00025"></a>00025 <span class="preprocessor">#endif</span>
+<a name="l00026"></a>00026 <span class="preprocessor"></span><span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00027"></a>00027 <span class="comment">                    Includes</span>
+<a name="l00028"></a>00028 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00029"></a>00029 
+<a name="l00030"></a>00030 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00031"></a>00031 
+<a name="l00032"></a>00032 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                             Defines</span>
+<a name="l00034"></a>00034 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00038"></a>00038 <span class="comment">                                   Prototypes</span>
+<a name="l00039"></a>00039 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00040"></a>00040 <span class="keywordtype">void</span> sinfo_free_float_array(<span class="keywordtype">float</span> ***a, <span class="keyword">const</span> <span class="keywordtype">int</span> n) ;
+<a name="l00041"></a>00041 
+<a name="l00042"></a>00042 cpl_table *
+<a name="l00043"></a>00043 sinfo_extract_table_rows(<span class="keyword">const</span> cpl_table *t, <span class="keyword">const</span> <span class="keywordtype">char</span> *column,
+<a name="l00044"></a>00044              cpl_table_select_operator <span class="keyword">operator</span>, <span class="keywordtype">double</span> value);
+<a name="l00045"></a>00045 <span class="keywordtype">int</span>
+<a name="l00046"></a>00046 sinfo_select_table_rows(cpl_table *t,  <span class="keyword">const</span> <span class="keywordtype">char</span> *column, 
+<a name="l00047"></a>00047             cpl_table_select_operator <span class="keyword">operator</span>, <span class="keywordtype">double</span> value);
+<a name="l00048"></a>00048 
+<a name="l00049"></a>00049 cpl_error_code sinfo_sort_table_1(cpl_table *t, <span class="keyword">const</span> <span class="keywordtype">char</span> *column1,
+<a name="l00050"></a>00050                  cpl_boolean reverse1);
+<a name="l00051"></a>00051 cpl_error_code sinfo_sort_table_2(cpl_table *t, <span class="keyword">const</span> <span class="keywordtype">char</span> *column1, 
+<a name="l00052"></a>00052                  <span class="keyword">const</span> <span class="keywordtype">char</span> *column2, cpl_boolean reverse1, 
+<a name="l00053"></a>00053                  cpl_boolean reverse2);
+<a name="l00054"></a>00054 
+<a name="l00055"></a>00055 <span class="keywordtype">void</span> sinfoni_free_vector(cpl_vector **v);
+<a name="l00056"></a>00056 <span class="keywordtype">void</span> sinfo_free_array(cpl_array **i);
+<a name="l00057"></a>00057 <span class="keywordtype">void</span> sinfo_free_apertures(cpl_apertures **a);
+<a name="l00058"></a>00058 <span class="keywordtype">void</span> sinfo_free_parameter(cpl_parameter **p);
+<a name="l00059"></a>00059 <span class="keywordtype">void</span> sinfo_free_image(cpl_image **i);
+<a name="l00060"></a>00060 <span class="keywordtype">void</span> sinfo_free_mask(cpl_mask **m);
+<a name="l00061"></a>00061 <span class="keywordtype">void</span> sinfo_free_imagelist(cpl_imagelist **i);
+<a name="l00062"></a>00062 <span class="keywordtype">void</span> sinfo_free_table(cpl_table **t);
+<a name="l00063"></a>00063 <span class="keywordtype">void</span> sinfo_free_propertylist(cpl_propertylist **p);
+<a name="l00064"></a>00064 <span class="keywordtype">void</span> sinfo_free_polynomial(cpl_polynomial **p);
+<a name="l00065"></a>00065 <span class="keywordtype">void</span> sinfo_free_stats(cpl_stats **s);
+<a name="l00066"></a>00066 <span class="keywordtype">void</span> sinfo_unwrap_matrix(cpl_matrix **m);
+<a name="l00067"></a>00067 <span class="keywordtype">void</span> sinfo_unwrap_vector(cpl_vector **v);
+<a name="l00068"></a>00068 <span class="keywordtype">void</span> sinfo_unwrap_bivector_vectors(cpl_bivector **b);
+<a name="l00069"></a>00069 <span class="keywordtype">void</span> sinfo_free_parameterlist(cpl_parameterlist **p);
+<a name="l00070"></a>00070 <span class="keywordtype">void</span> sinfo_free_frameset(cpl_frameset **f);
+<a name="l00071"></a>00071 <span class="keywordtype">void</span> sinfo_free_frame(cpl_frame **f);
+<a name="l00072"></a>00072 <span class="keywordtype">void</span> sinfo_free_int(<span class="keywordtype">int</span> **i);
+<a name="l00073"></a>00073 <span class="keywordtype">void</span> sinfo_free_float(<span class="keywordtype">float</span> **i);
+<a name="l00074"></a>00074 <span class="keywordtype">void</span> sinfo_free_double(<span class="keywordtype">double</span> **i);
+<a name="l00075"></a>00075 <span class="keywordtype">void</span> sinfo_free_array_imagelist(cpl_imagelist ***a);
+<a name="l00076"></a>00076 <span class="keywordtype">void</span> sinfo_free_array_image(cpl_image ***a);
+<a name="l00077"></a>00077 <span class="keywordtype">void</span> sinfo_free_image_array(cpl_image ***a,<span class="keyword">const</span> <span class="keywordtype">int</span> n);
+<a name="l00078"></a>00078 <span class="comment">/* similar are also defined with same name in svd.h */</span>
+<a name="l00079"></a>00079 <span class="keywordtype">void</span> sinfoni_free_matrix(cpl_matrix **m);
+<a name="l00080"></a>00080 <span class="keywordtype">void</span> sinfo_free_my_vector(cpl_vector **v);
+<a name="l00081"></a>00081 <span class="keywordtype">void</span> sinfo_free_bivector(cpl_bivector **bv);
+<a name="l00082"></a>00082 
+<a name="l00083"></a>00083 
+<a name="l00084"></a>00084 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__utl__bp__mask__add_8c_source.html b/html/sinfo__utl__bp__mask__add_8c_source.html
new file mode 100644
index 0000000..91b65b9
--- /dev/null
+++ b/html/sinfo__utl__bp__mask__add_8c_source.html
@@ -0,0 +1,252 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_utl_bp_mask_add.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_utl_bp_mask_add.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_utl_bp_mask_add.c,v 1.18 2008/08/21 09:46:47 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the CPL (Common Pipeline Library)</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
+<a name="l00007"></a>00007 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span>
+<a name="l00008"></a>00008 <span class="comment"> * License as published by the Free Software Foundation; either</span>
+<a name="l00009"></a>00009 <span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
+<a name="l00014"></a>00014 <span class="comment"> * Lesser General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
+<a name="l00017"></a>00017 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2008/08/21 09:46:47 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.18 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> */</span>
+<a name="l00026"></a>00026 
+<a name="l00027"></a>00027  <span class="comment">/****************************************************************</span>
+<a name="l00028"></a>00028 <span class="comment">  *           Bad pixel search  (normal method)                  *</span>
+<a name="l00029"></a>00029 <span class="comment">  ****************************************************************/</span>
+<a name="l00030"></a>00030 
+<a name="l00031"></a>00031 <span class="comment">/* --------------------------------------------------------------- </span>
+<a name="l00032"></a>00032 <span class="comment">                         INCLUDES</span>
+<a name="l00033"></a>00033 <span class="comment">   --------------------------------------------------------------- */</span>
+<a name="l00034"></a>00034 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00035"></a>00035 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>
+<a name="l00036"></a>00036 <span class="preprocessor">#endif</span>
+<a name="l00037"></a>00037 <span class="preprocessor"></span>
+<a name="l00038"></a>00038 <span class="comment">/* std libraries */</span>
+<a name="l00039"></a>00039 <span class="preprocessor">#include <strings.h></span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include <string.h></span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include <stdio.h></span>
+<a name="l00042"></a>00042 
+<a name="l00043"></a>00043 <span class="comment">/* cpl */</span>
+<a name="l00044"></a>00044 <span class="preprocessor">#include <cpl.h></span>     
+<a name="l00045"></a>00045 <span class="comment">/* irplib */</span>
+<a name="l00046"></a>00046 <span class="preprocessor">#include <irplib_utils.h></span>
+<a name="l00047"></a>00047 
+<a name="l00048"></a>00048 <span class="comment">/* sinfoni */</span>
+<a name="l00049"></a>00049 <span class="preprocessor">#include <sinfo_general_config.h></span>
+<a name="l00050"></a>00050 <span class="preprocessor">#include <sinfo_bp_norm_config.h></span>
+<a name="l00051"></a>00051 <span class="preprocessor">#include <sinfo_bp_lin_config.h></span>
+<a name="l00052"></a>00052 <span class="preprocessor">#include <sinfo_bp_noise_config.h></span>
+<a name="l00053"></a>00053 <span class="preprocessor">#include <sinfo_new_add_bp_map.h></span>
+<a name="l00054"></a>00054 <span class="preprocessor">#include <sinfo_tpl_utils.h></span>
+<a name="l00055"></a>00055 <span class="preprocessor">#include <sinfo_tpl_dfs.h></span>
+<a name="l00056"></a>00056 <span class="preprocessor">#include <sinfo_msg.h></span>
+<a name="l00057"></a>00057 <span class="preprocessor">#include <sinfo_error.h></span>
+<a name="l00058"></a>00058 <span class="preprocessor">#include <sinfo_utils_wrappers.h></span>
+<a name="l00059"></a>00059 
+<a name="l00060"></a>00060 <span class="comment">/* --------------------------------------------------------------- </span>
+<a name="l00061"></a>00061 <span class="comment">                         DEFINES</span>
+<a name="l00062"></a>00062 <span class="comment">   --------------------------------------------------------------- */</span>
+<a name="l00063"></a>00063 <span class="comment">/* --------------------------------------------------------------- </span>
+<a name="l00064"></a>00064 <span class="comment">                         FUNCTIONS PROTOTYPES</span>
+<a name="l00065"></a>00065 <span class="comment">   --------------------------------------------------------------- */</span>
+<a name="l00066"></a>00066 
+<a name="l00067"></a>00067 <span class="keyword">const</span> <span class="keywordtype">char</span> * sinfoni_get_licence(<span class="keywordtype">void</span>);
+<a name="l00068"></a>00068 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_bp_mask_add_create(cpl_plugin *plugin);
+<a name="l00069"></a>00069 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_bp_mask_add_exec(cpl_plugin *plugin);
+<a name="l00070"></a>00070 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_bp_mask_add_destroy(cpl_plugin *plugin);
+<a name="l00071"></a>00071 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_bp_mask_add(cpl_parameterlist *, cpl_frameset *);
+<a name="l00072"></a>00072 
+<a name="l00073"></a>00073 <span class="comment">/* --------------------------------------------------------------- </span>
+<a name="l00074"></a>00074 <span class="comment">                         STATIC VARIABLES</span>
+<a name="l00075"></a>00075 <span class="comment">   --------------------------------------------------------------- */</span>
+<a name="l00076"></a>00076 
+<a name="l00077"></a>00077 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_utl_bp_mask_add_description[] =
+<a name="l00078"></a>00078 <span class="stringliteral">"This recipe performs bad pixel map coaddition.\n"</span>
+<a name="l00079"></a>00079 <span class="stringliteral">"The input files are several (at least 2)  bad pixel masks in the sof file\n"</span>
+<a name="l00080"></a>00080 <span class="stringliteral">"Their tab should contain the string BP_MAP.\n"</span>
+<a name="l00081"></a>00081 <span class="stringliteral">"The output is an image resulting from the logical operator OR \n"</span>
+<a name="l00082"></a>00082 <span class="stringliteral">"applied to all the masks.\n"</span>
+<a name="l00083"></a>00083 <span class="stringliteral">"Information on relevant parameters can be found with\n"</span>
+<a name="l00084"></a>00084 <span class="stringliteral">"esorex --params sinfo_utl_bp_mask_add\n"</span>
+<a name="l00085"></a>00085 <span class="stringliteral">"esorex --help sinfo_utl_bp_mask_add\n"</span>
+<a name="l00086"></a>00086 <span class="stringliteral">"\n"</span>;
+<a name="l00087"></a>00087 
+<a name="l00088"></a>00088 
+<a name="l00089"></a>00089 <span class="comment">/* --------------------------------------------------------------- </span>
+<a name="l00090"></a>00090 <span class="comment">                         FUNCTIONS CODE</span>
+<a name="l00091"></a>00091 <span class="comment">   --------------------------------------------------------------- */</span>
+<a name="l00092"></a>00092 
+<a name="l00093"></a>00093 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00097"></a>00097 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00099"></a>00099 <span class="comment">/* --------------------------------------------------------------- */</span>
+<a name="l00100"></a>00100 
+<a name="l00101"></a>00101 <span class="keywordtype">int</span>
+<a name="l00102"></a>00102 <a class="code" href="group__sinfo__rec__detlin.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693" title="Build the list of available plugins, for this module.">cpl_plugin_get_info</a>(cpl_pluginlist *list)
+<a name="l00103"></a>00103 {
+<a name="l00104"></a>00104 
+<a name="l00105"></a>00105   cpl_recipe *recipe = cpl_calloc(1, <span class="keyword">sizeof</span> *recipe);
+<a name="l00106"></a>00106   cpl_plugin *plugin = &recipe->interface;
+<a name="l00107"></a>00107 
+<a name="l00108"></a>00108 
+<a name="l00109"></a>00109   cpl_plugin_init(plugin,
+<a name="l00110"></a>00110           CPL_PLUGIN_API,
+<a name="l00111"></a>00111           SINFONI_BINARY_VERSION,
+<a name="l00112"></a>00112           CPL_PLUGIN_TYPE_RECIPE,
+<a name="l00113"></a>00113           <span class="stringliteral">"sinfo_utl_bp_mask_add"</span>,
+<a name="l00114"></a>00114           <span class="stringliteral">"Add bad pixels masks"</span>,
+<a name="l00115"></a>00115           sinfo_utl_bp_mask_add_description,
+<a name="l00116"></a>00116           <span class="stringliteral">"Andrea Modigliani"</span>,
+<a name="l00117"></a>00117           <span class="stringliteral">"Andrea.Modigliani at eso.org"</span>,
+<a name="l00118"></a>00118           sinfo_get_license(),
+<a name="l00119"></a>00119           sinfo_utl_bp_mask_add_create,
+<a name="l00120"></a>00120           sinfo_utl_bp_mask_add_exec,
+<a name="l00121"></a>00121           sinfo_utl_bp_mask_add_destroy);
+<a name="l00122"></a>00122 
+<a name="l00123"></a>00123   cpl_pluginlist_append(list, plugin);
+<a name="l00124"></a>00124 
+<a name="l00125"></a>00125   <span class="keywordflow">return</span> 0;
+<a name="l00126"></a>00126 
+<a name="l00127"></a>00127 }
+<a name="l00128"></a>00128 
+<a name="l00129"></a>00129 <span class="comment">/* --------------------------------------------------------------- */</span>
+<a name="l00136"></a>00136 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00137"></a>00137 sinfo_utl_bp_mask_add_create(cpl_plugin *plugin)
+<a name="l00138"></a>00138 {
+<a name="l00139"></a>00139 
+<a name="l00140"></a>00140   <span class="comment">/*</span>
+<a name="l00141"></a>00141 <span class="comment">   * We have to provide the option we accept to the application.</span>
+<a name="l00142"></a>00142 <span class="comment">   * We need to setup our parameter list and hook it into the recipe</span>
+<a name="l00143"></a>00143 <span class="comment">   * interface.</span>
+<a name="l00144"></a>00144 <span class="comment">   */</span>
+<a name="l00145"></a>00145   cpl_recipe *recipe = (cpl_recipe *)plugin;
+<a name="l00146"></a>00146   recipe->parameters = cpl_parameterlist_new();
+<a name="l00147"></a>00147   <span class="keywordflow">if</span>(recipe->parameters == NULL) {
+<a name="l00148"></a>00148     <span class="keywordflow">return</span> 1;
+<a name="l00149"></a>00149   }
+<a name="l00150"></a>00150   cpl_error_reset();
+<a name="l00151"></a>00151   <a class="code" href="group__irplib__utils.html#gaf9d392144014e2363054bc3f83c8e47e" title="Reset IRPLIB state.">irplib_reset</a>();
+<a name="l00152"></a>00152 
+<a name="l00153"></a>00153   <span class="comment">/*</span>
+<a name="l00154"></a>00154 <span class="comment">   * Fill the parameter list.</span>
+<a name="l00155"></a>00155 <span class="comment">   */</span>
+<a name="l00156"></a>00156 
+<a name="l00157"></a>00157 
+<a name="l00158"></a>00158   <span class="keywordflow">return</span> 0;
+<a name="l00159"></a>00159 
+<a name="l00160"></a>00160 }
+<a name="l00161"></a>00161 
+<a name="l00162"></a>00162 <span class="comment">/* --------------------------------------------------------------- */</span>
+<a name="l00168"></a>00168 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00169"></a>00169 sinfo_utl_bp_mask_add_exec(cpl_plugin *plugin)
+<a name="l00170"></a>00170 {
+<a name="l00171"></a>00171  
+<a name="l00172"></a>00172 
+<a name="l00173"></a>00173   cpl_recipe *recipe = (cpl_recipe *) plugin;
+<a name="l00174"></a>00174   cpl_errorstate initial_errorstate = cpl_errorstate_get();
+<a name="l00175"></a>00175   <span class="keywordtype">int</span> code=0;
+<a name="l00176"></a>00176   
+<a name="l00177"></a>00177   <span class="keywordflow">if</span>(recipe->parameters == NULL ) {
+<a name="l00178"></a>00178     <span class="keywordflow">return</span> 1;
+<a name="l00179"></a>00179   }
+<a name="l00180"></a>00180   <span class="keywordflow">if</span>(recipe->frames == NULL) {
+<a name="l00181"></a>00181     <span class="keywordflow">return</span> 1;
+<a name="l00182"></a>00182   }
+<a name="l00183"></a>00183 
+<a name="l00184"></a>00184   check_nomsg(code=sinfo_utl_bp_mask_add(recipe->parameters, recipe->frames));
+<a name="l00185"></a>00185 
+<a name="l00186"></a>00186   <span class="keywordflow">if</span> (!cpl_errorstate_is_equal(initial_errorstate)) {                      
+<a name="l00187"></a>00187     <span class="comment">/* Dump the error history since recipe execution start.                </span>
+<a name="l00188"></a>00188 <span class="comment">       At this point the recipe cannot recover from the error */</span>           
+<a name="l00189"></a>00189     cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);              
+<a name="l00190"></a>00190   } 
+<a name="l00191"></a>00191   cleanup:
+<a name="l00192"></a>00192 
+<a name="l00193"></a>00193   <span class="keywordflow">return</span> code;
+<a name="l00194"></a>00194 
+<a name="l00195"></a>00195 }
+<a name="l00196"></a>00196 
+<a name="l00197"></a>00197 <span class="comment">/* --------------------------------------------------------------- */</span>
+<a name="l00204"></a>00204 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00205"></a>00205 sinfo_utl_bp_mask_add_destroy(cpl_plugin *plugin)
+<a name="l00206"></a>00206 {
+<a name="l00207"></a>00207   cpl_recipe *recipe = (cpl_recipe *) plugin;
+<a name="l00208"></a>00208   <span class="comment">/*</span>
+<a name="l00209"></a>00209 <span class="comment">   * We just destroy what was created during the plugin initializzation phase</span>
+<a name="l00210"></a>00210 <span class="comment">   * i.e. the parameter list. The frame set is managed by the application which</span>
+<a name="l00211"></a>00211 <span class="comment">   * called us, so that we must not touch it.</span>
+<a name="l00212"></a>00212 <span class="comment">   */</span>
+<a name="l00213"></a>00213 
+<a name="l00214"></a>00214   cpl_parameterlist_delete(recipe->parameters);
+<a name="l00215"></a>00215   <span class="keywordflow">return</span> 0;
+<a name="l00216"></a>00216 
+<a name="l00217"></a>00217 }
+<a name="l00218"></a>00218 
+<a name="l00219"></a>00219 <span class="comment">/*</span>
+<a name="l00220"></a>00220 <span class="comment"> * The actual recipe actually start here.</span>
+<a name="l00221"></a>00221 <span class="comment"> */</span>
+<a name="l00222"></a>00222 
+<a name="l00223"></a>00223 
+<a name="l00224"></a>00224 <span class="comment">/* --------------------------------------------------------------- */</span>
+<a name="l00238"></a>00238 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00239"></a>00239 sinfo_utl_bp_mask_add(cpl_parameterlist *config, cpl_frameset *sof)
+<a name="l00240"></a>00240 {
+<a name="l00241"></a>00241   cpl_frameset* ref_set=NULL;
+<a name="l00242"></a>00242   <span class="keywordtype">int</span> n=0;
+<a name="l00243"></a>00243   
+<a name="l00244"></a>00244   sinfo_msg(<span class="stringliteral">"Welcome to SINFONI Pipeline release %d.%d.%d"</span>,
+<a name="l00245"></a>00245         SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
+<a name="l00246"></a>00246 
+<a name="l00247"></a>00247    <span class="keywordflow">if</span>(sinfo_dfs_set_groups(sof)) {
+<a name="l00248"></a>00248        <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Cannot indentify RAW and CALIB frames"</span>) ;
+<a name="l00249"></a>00249    }
+<a name="l00250"></a>00250 
+<a name="l00251"></a>00251     n=cpl_frameset_get_size(sof);
+<a name="l00252"></a>00252     <span class="keywordflow">if</span>(n<1) {
+<a name="l00253"></a>00253       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Empty input frame list!"</span>);
+<a name="l00254"></a>00254       <span class="keywordflow">goto</span> cleanup ;
+<a name="l00255"></a>00255     }
+<a name="l00256"></a>00256 
+<a name="l00257"></a>00257    check_nomsg(ref_set=cpl_frameset_duplicate(sof));
+<a name="l00258"></a>00258    ck0_nomsg(sinfo_new_add_bp_map(cpl_func,config,sof,ref_set));
+<a name="l00259"></a>00259 
+<a name="l00260"></a>00260  cleanup:
+<a name="l00261"></a>00261    sinfo_free_frameset(&ref_set);
+<a name="l00262"></a>00262   <span class="keywordflow">if</span> (cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l00263"></a>00263     <span class="keywordflow">return</span> -1;
+<a name="l00264"></a>00264   } <span class="keywordflow">else</span> {
+<a name="l00265"></a>00265     <span class="keywordflow">return</span> 0;
+<a name="l00266"></a>00266   }
+<a name="l00267"></a>00267 
+<a name="l00268"></a>00268 
+<a name="l00269"></a>00269 
+<a name="l00270"></a>00270 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__utl__cube2ima_8h_source.html b/html/sinfo__utl__cube2ima_8h_source.html
new file mode 100644
index 0000000..73413ed
--- /dev/null
+++ b/html/sinfo__utl__cube2ima_8h_source.html
@@ -0,0 +1,58 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_utl_cube2ima.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_utl_cube2ima.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_utl_cube2ima.h,v 1.1 2006/10/22 14:12:28 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the IIINSTRUMENT Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2006/10/22 14:12:28 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.1 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00028"></a>00028 <span class="comment">                                Includes</span>
+<a name="l00029"></a>00029 <span class="comment">-----------------------------------------------------------------------------*/</span>
+<a name="l00030"></a>00030 <span class="preprocessor">#ifndef SINFO_UTL_CUBE2IMA_H</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_UTL_CUBE2IMA_H</span>
+<a name="l00032"></a>00032 <span class="preprocessor"></span><span class="preprocessor">#include <cpl.h></span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include "sinfo_tpl_utils.h"</span>
+<a name="l00034"></a>00034 <span class="preprocessor">#include "sinfo_pfits.h"</span>
+<a name="l00035"></a>00035 <span class="preprocessor">#include "sinfo_tpl_dfs.h"</span>
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00038"></a>00038 <span class="comment">                            Functions prototypes</span>
+<a name="l00039"></a>00039 <span class="comment">-----------------------------------------------------------------------------*/</span>
+<a name="l00040"></a>00040 <span class="keywordtype">int</span> sinfo_utl_cube2ima(cpl_parameterlist *, cpl_frameset *) ;
+<a name="l00041"></a>00041 
+<a name="l00042"></a>00042 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__utl__cube2spectrum_8h_source.html b/html/sinfo__utl__cube2spectrum_8h_source.html
new file mode 100644
index 0000000..69a4bc8
--- /dev/null
+++ b/html/sinfo__utl__cube2spectrum_8h_source.html
@@ -0,0 +1,60 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_utl_cube2spectrum.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_utl_cube2spectrum.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_utl_cube2spectrum.h,v 1.1 2006/10/22 14:12:28 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the IIINSTRUMENT Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2006/10/22 14:12:28 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.1 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00028"></a>00028 <span class="comment">                                Includes</span>
+<a name="l00029"></a>00029 <span class="comment">-----------------------------------------------------------------------------*/</span>
+<a name="l00030"></a>00030 <span class="preprocessor">#ifndef SINFO_UTL_CUBE2SPECTRUM_H</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_UTL_CUBE2SPECTRUM_H</span>
+<a name="l00032"></a>00032 <span class="preprocessor"></span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00034"></a>00034 <span class="preprocessor">#include "sinfo_tpl_utils.h"</span>
+<a name="l00035"></a>00035 <span class="preprocessor">#include "sinfo_pfits.h"</span>
+<a name="l00036"></a>00036 <span class="preprocessor">#include "sinfo_tpl_dfs.h"</span>
+<a name="l00037"></a>00037 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00038"></a>00038 <span class="comment">                            Functions prototypes</span>
+<a name="l00039"></a>00039 <span class="comment">-----------------------------------------------------------------------------*/</span>
+<a name="l00040"></a>00040 
+<a name="l00041"></a>00041 <span class="keywordtype">int</span> sinfo_utl_cube2spectrum(cpl_parameterlist *, cpl_frameset *, <span class="keyword">const</span> <span class="keywordtype">char</span>*) ;
+<a name="l00042"></a>00042 
+<a name="l00043"></a>00043 <span class="preprocessor">#endif</span>
+<a name="l00044"></a>00044 <span class="preprocessor"></span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__utl__cube__arith_8h_source.html b/html/sinfo__utl__cube__arith_8h_source.html
new file mode 100644
index 0000000..75155ac
--- /dev/null
+++ b/html/sinfo__utl__cube__arith_8h_source.html
@@ -0,0 +1,59 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_utl_cube_arith.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_utl_cube_arith.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_utl_cube_arith.h,v 1.1 2006/10/22 14:12:28 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the IIINSTRUMENT Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2006/10/22 14:12:28 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.1 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00028"></a>00028 <span class="comment">                                Includes</span>
+<a name="l00029"></a>00029 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00030"></a>00030 <span class="preprocessor">#ifndef SINFO_UTL_CUBE_ARITH_H</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_UTL_CUBE_ARITH_H</span>
+<a name="l00032"></a>00032 <span class="preprocessor"></span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00034"></a>00034 <span class="preprocessor">#include "sinfo_tpl_utils.h"</span>
+<a name="l00035"></a>00035 <span class="preprocessor">#include "sinfo_pfits.h"</span>
+<a name="l00036"></a>00036 <span class="preprocessor">#include "sinfo_tpl_dfs.h"</span>
+<a name="l00037"></a>00037 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00038"></a>00038 <span class="comment">                            Functions prototypes</span>
+<a name="l00039"></a>00039 <span class="comment">-----------------------------------------------------------------------------*/</span>
+<a name="l00040"></a>00040 
+<a name="l00041"></a>00041 <span class="keywordtype">int</span> sinfo_utl_cube_arith(cpl_parameterlist *, cpl_frameset *) ;
+<a name="l00042"></a>00042 
+<a name="l00043"></a>00043 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__utl__cube__combine_8h_source.html b/html/sinfo__utl__cube__combine_8h_source.html
new file mode 100644
index 0000000..6ebf1bb
--- /dev/null
+++ b/html/sinfo__utl__cube__combine_8h_source.html
@@ -0,0 +1,59 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_utl_cube_combine.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_utl_cube_combine.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_utl_cube_combine.h,v 1.1 2006/10/22 14:12:28 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the IIINSTRUMENT Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2006/10/22 14:12:28 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.1 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00028"></a>00028 <span class="comment">                                Includes</span>
+<a name="l00029"></a>00029 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00030"></a>00030 <span class="preprocessor">#ifndef SINFO_UTL_CUBE_COMBINE_H</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_UTL_CUBE_COMBINE_H</span>
+<a name="l00032"></a>00032 <span class="preprocessor"></span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00034"></a>00034 <span class="preprocessor">#include "sinfo_tpl_utils.h"</span>
+<a name="l00035"></a>00035 <span class="preprocessor">#include "sinfo_pfits.h"</span>
+<a name="l00036"></a>00036 <span class="preprocessor">#include "sinfo_tpl_dfs.h"</span>
+<a name="l00037"></a>00037 
+<a name="l00038"></a>00038 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00039"></a>00039 <span class="comment">                            Functions prototypes</span>
+<a name="l00040"></a>00040 <span class="comment">-----------------------------------------------------------------------------*/</span>
+<a name="l00041"></a>00041 <span class="keywordtype">int</span> sinfo_utl_cube_combine(cpl_parameterlist *, cpl_frameset *) ;
+<a name="l00042"></a>00042 
+<a name="l00043"></a>00043 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__utl__cube__create_8c_source.html b/html/sinfo__utl__cube__create_8c_source.html
new file mode 100644
index 0000000..0423208
--- /dev/null
+++ b/html/sinfo__utl__cube__create_8c_source.html
@@ -0,0 +1,656 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_utl_cube_create.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_utl_cube_create.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_utl_cube_create.c,v 1.5 2008/08/29 11:34:03 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the SINFONI Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2008/08/29 11:34:03 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.5 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span>
+<a name="l00032"></a>00032 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                                Includes</span>
+<a name="l00034"></a>00034 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="comment">/* cpl */</span>
+<a name="l00038"></a>00038 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00039"></a>00039 
+<a name="l00040"></a>00040 <span class="comment">/* irplib */</span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include <irplib_utils.h></span>
+<a name="l00042"></a>00042 
+<a name="l00043"></a>00043 <span class="preprocessor">#include <sinfo_tpl_utils.h></span>
+<a name="l00044"></a>00044 <span class="preprocessor">#include <sinfo_pfits.h></span>
+<a name="l00045"></a>00045 <span class="preprocessor">#include <sinfo_tpl_dfs.h></span>
+<a name="l00046"></a>00046 <span class="preprocessor">#include <sinfo_msg.h></span>
+<a name="l00047"></a>00047 <span class="preprocessor">#include <sinfo_error.h></span>
+<a name="l00048"></a>00048 <span class="preprocessor">#include <sinfo_utils_wrappers.h></span>
+<a name="l00049"></a>00049 <span class="preprocessor">#include <sinfo_image_ops.h></span>
+<a name="l00050"></a>00050 <span class="preprocessor">#include <sinfo_wave_calibration.h></span>
+<a name="l00051"></a>00051 <span class="preprocessor">#include <sinfo_pro_save.h></span>
+<a name="l00052"></a>00052 <span class="preprocessor">#include <sinfo_raw_types.h></span>
+<a name="l00053"></a>00053 <span class="preprocessor">#include <sinfo_pro_types.h></span>
+<a name="l00054"></a>00054 <span class="preprocessor">#include <sinfo_coltilt.h></span>
+<a name="l00055"></a>00055 <span class="preprocessor">#include <sinfo_utilities_scired.h></span>
+<a name="l00056"></a>00056 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00057"></a>00057 <span class="comment">                            Functions prototypes</span>
+<a name="l00058"></a>00058 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00059"></a>00059 
+<a name="l00060"></a>00060 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_cube_create_create(cpl_plugin *) ;
+<a name="l00061"></a>00061 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_cube_create_exec(cpl_plugin *) ;
+<a name="l00062"></a>00062 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_cube_create_destroy(cpl_plugin *) ;
+<a name="l00063"></a>00063 
+<a name="l00064"></a>00064 <span class="keyword">static</span> <span class="keywordtype">int</span> 
+<a name="l00065"></a>00065 sinfo_cube_create(cpl_parameterlist * parameters, cpl_frameset * frames);
+<a name="l00066"></a>00066 
+<a name="l00067"></a>00067 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00068"></a>00068 <span class="comment">                            Static variables</span>
+<a name="l00069"></a>00069 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00070"></a>00070 
+<a name="l00071"></a>00071 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_utl_cube_create_description[] =
+<a name="l00072"></a>00072 <span class="stringliteral">"This recipe perform cubes creation.\n"</span>
+<a name="l00073"></a>00073 <span class="stringliteral">"The input files are:\n"</span>
+<a name="l00074"></a>00074 <span class="stringliteral">"A raw frame on tagged as RAW_ON\n"</span>
+<a name="l00075"></a>00075 <span class="stringliteral">"[optional] A raw frame off RAW_OFF\n"</span>
+<a name="l00076"></a>00076 <span class="stringliteral">"A wavelength map, tagged as WAVE_MAP\n"</span>
+<a name="l00077"></a>00077 <span class="stringliteral">"A wavelength map, tagged as WAVE_MAP\n"</span>
+<a name="l00078"></a>00078 <span class="stringliteral">"A distortion table, tagged as DISTORTION\n"</span>
+<a name="l00079"></a>00079 <span class="stringliteral">"A slitlets position table, tagged as SLIT_POS\n"</span>
+<a name="l00080"></a>00080 <span class="stringliteral">"Information on relevant parameters can be found with\n"</span>
+<a name="l00081"></a>00081 <span class="stringliteral">"esorex --params sinfo_utl_cube_create\n"</span>
+<a name="l00082"></a>00082 <span class="stringliteral">"esorex --help sinfo_utl_cube_create\n"</span>
+<a name="l00083"></a>00083 <span class="stringliteral">"\n"</span>;
+<a name="l00084"></a>00084 
+<a name="l00085"></a>00085 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00086"></a>00086 <span class="comment">                                Functions code</span>
+<a name="l00087"></a>00087 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00088"></a>00088 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00092"></a>00092 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00093"></a>00093 
+<a name="l00095"></a>00095 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00103"></a>00103 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00104"></a><a class="code" href="group__sinfo__utl__cube__create.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693">00104</a> <span class="keywordtype">int</span> <a class="code" href="group__sinfo__rec__detlin.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693" title="Build the list of available plugins, for this module.">cpl_plugin_get_info</a>(cpl_pluginlist * list)
+<a name="l00105"></a>00105 {
+<a name="l00106"></a>00106     cpl_recipe  *   recipe = cpl_calloc(1, <span class="keyword">sizeof</span> *recipe ) ;
+<a name="l00107"></a>00107     cpl_plugin  *   plugin = &recipe->interface ;
+<a name="l00108"></a>00108 
+<a name="l00109"></a>00109     cpl_plugin_init(plugin,
+<a name="l00110"></a>00110                     CPL_PLUGIN_API,
+<a name="l00111"></a>00111                     SINFONI_BINARY_VERSION,
+<a name="l00112"></a>00112                     CPL_PLUGIN_TYPE_RECIPE,
+<a name="l00113"></a>00113                     <span class="stringliteral">"sinfo_utl_cube_create"</span>,
+<a name="l00114"></a>00114                     <span class="stringliteral">"Generate a cube"</span>,
+<a name="l00115"></a>00115                     sinfo_utl_cube_create_description,
+<a name="l00116"></a>00116                     <span class="stringliteral">"Andrea Modigliani"</span>,
+<a name="l00117"></a>00117                     <span class="stringliteral">"Andrea.Modigliani at eso.org"</span>,
+<a name="l00118"></a>00118                     sinfo_get_license(),
+<a name="l00119"></a>00119                     sinfo_utl_cube_create_create,
+<a name="l00120"></a>00120                     sinfo_utl_cube_create_exec,
+<a name="l00121"></a>00121                     sinfo_utl_cube_create_destroy) ;
+<a name="l00122"></a>00122 
+<a name="l00123"></a>00123     cpl_pluginlist_append(list, plugin) ;
+<a name="l00124"></a>00124     
+<a name="l00125"></a>00125     <span class="keywordflow">return</span> 0;
+<a name="l00126"></a>00126 }
+<a name="l00127"></a>00127 
+<a name="l00128"></a>00128 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00137"></a>00137 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00138"></a>00138 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_cube_create_create(cpl_plugin * plugin)
+<a name="l00139"></a>00139 {
+<a name="l00140"></a>00140     cpl_recipe      * recipe ;
+<a name="l00141"></a>00141     cpl_parameter   * p ;
+<a name="l00142"></a>00142     cpl_parameterlist   * list ;
+<a name="l00143"></a>00143 
+<a name="l00144"></a>00144     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00145"></a>00145     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00146"></a>00146         recipe = (cpl_recipe *)plugin ;
+<a name="l00147"></a>00147     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00148"></a>00148     cpl_error_reset();
+<a name="l00149"></a>00149     <a class="code" href="group__irplib__utils.html#gaf9d392144014e2363054bc3f83c8e47e" title="Reset IRPLIB state.">irplib_reset</a>();
+<a name="l00150"></a>00150 
+<a name="l00151"></a>00151     <span class="comment">/* Create the parameters list in the cpl_recipe object */</span>
+<a name="l00152"></a>00152     recipe->parameters = cpl_parameterlist_new() ; 
+<a name="l00153"></a>00153 
+<a name="l00154"></a>00154     list=recipe->parameters;
+<a name="l00155"></a>00155   <span class="comment">/* jitter mode indicator: yes: Auto-Jitter, no: user defined jitter</span>
+<a name="l00156"></a>00156 <span class="comment">     The next three parameters are only used if jitterInd is set to yes, </span>
+<a name="l00157"></a>00157 <span class="comment">     that means in auto-jittering mode!</span>
+<a name="l00158"></a>00158 <span class="comment">  */</span>
+<a name="l00159"></a>00159   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.objnod.jitter_index"</span>,
+<a name="l00160"></a>00160                   CPL_TYPE_BOOL,
+<a name="l00161"></a>00161                               <span class="stringliteral">"jitter mode indicator: "</span>
+<a name="l00162"></a>00162                               <span class="stringliteral">"TRUE: Auto-Jitter, "</span>
+<a name="l00163"></a>00163                               <span class="stringliteral">"FALSE: user defined jitter. "</span>
+<a name="l00164"></a>00164                               <span class="stringliteral">"The size_x size_y kernel_type parameters "</span>
+<a name="l00165"></a>00165                               <span class="stringliteral">"are only used if jitterInd is set to yes, "</span>
+<a name="l00166"></a>00166                               <span class="stringliteral">"that means in auto-jittering mode."</span>,
+<a name="l00167"></a>00167                               <span class="stringliteral">"sinfoni.objnod"</span>,
+<a name="l00168"></a>00168                               TRUE);
+<a name="l00169"></a>00169 
+<a name="l00170"></a>00170   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"objnod-jit_ind"</span>);
+<a name="l00171"></a>00171   cpl_parameterlist_append(list, p);
+<a name="l00172"></a>00172 
+<a name="l00173"></a>00173 
+<a name="l00174"></a>00174   <span class="comment">/* Kernel Type */</span>
+<a name="l00175"></a>00175   <span class="comment">/* the name of the interpolation kernel to shift the single cubes  to the </span>
+<a name="l00176"></a>00176 <span class="comment">     correct places inside the big combined cube. That you want to generate </span>
+<a name="l00177"></a>00177 <span class="comment">     using the eclipse routine sinfo_generate_interpolation_kernel()</span>
+<a name="l00178"></a>00178 <span class="comment">     Supported kernels are:</span>
+<a name="l00179"></a>00179 <span class="comment"></span>
+<a name="l00180"></a>00180 <span class="comment">                                     NULL:      default kernel, currently tanh</span>
+<a name="l00181"></a>00181 <span class="comment">                                     default: dito</span>
+<a name="l00182"></a>00182 <span class="comment">                                     tanh:    Hyperbolic tangent</span>
+<a name="l00183"></a>00183 <span class="comment">                                     sinc2:   Square sinc</span>
+<a name="l00184"></a>00184 <span class="comment">                                     lanczos: Lanczos2 kernel</span>
+<a name="l00185"></a>00185 <span class="comment">                                     hamming: Hamming kernel</span>
+<a name="l00186"></a>00186 <span class="comment">                                     hann:    Hann kernel</span>
+<a name="l00187"></a>00187 <span class="comment">  */</span>
+<a name="l00188"></a>00188   p = cpl_parameter_new_enum(<span class="stringliteral">"sinfoni.objnod.kernel_type"</span>,
+<a name="l00189"></a>00189                   CPL_TYPE_STRING,
+<a name="l00190"></a>00190                               <span class="stringliteral">"Kernel Type:"</span>
+<a name="l00191"></a>00191                               <span class="stringliteral">"the name of the interpolation kernel to shift "</span>
+<a name="l00192"></a>00192                               <span class="stringliteral">"the single cubes  to the correct places inside "</span>
+<a name="l00193"></a>00193                              <span class="stringliteral">"the big combined cube"</span>,
+<a name="l00194"></a>00194                               <span class="stringliteral">"sinfoni.objnod"</span>,
+<a name="l00195"></a>00195                               <span class="stringliteral">"tanh"</span>,
+<a name="l00196"></a>00196                                7,
+<a name="l00197"></a>00197                               <span class="stringliteral">"NULL"</span>,<span class="stringliteral">"default"</span>,<span class="stringliteral">"tanh"</span>,<span class="stringliteral">"sinc2"</span>,
+<a name="l00198"></a>00198                               <span class="stringliteral">"lanczos"</span>,<span class="stringliteral">"hamming"</span>,<span class="stringliteral">"hann"</span>);
+<a name="l00199"></a>00199 
+<a name="l00200"></a>00200   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"objnod-kernel_typ"</span>);
+<a name="l00201"></a>00201   cpl_parameterlist_append(list, p);
+<a name="l00202"></a>00202 
+<a name="l00203"></a>00203   <span class="comment">/*Resampling */</span>
+<a name="l00204"></a>00204  <span class="comment">/* number of coefficients for the polynomial interpolation */</span>
+<a name="l00205"></a>00205   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.objnod.n_coeffs"</span>,
+<a name="l00206"></a>00206                   CPL_TYPE_INT,
+<a name="l00207"></a>00207                               <span class="stringliteral">"number of coefficients for the polynomial "</span>
+<a name="l00208"></a>00208                               <span class="stringliteral">"interpolation "</span>,
+<a name="l00209"></a>00209                               <span class="stringliteral">"sinfoni.objnod"</span>,
+<a name="l00210"></a>00210                                3);
+<a name="l00211"></a>00211 
+<a name="l00212"></a>00212   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"objnod-no_coeffs"</span>);
+<a name="l00213"></a>00213   cpl_parameterlist_append(list, p);
+<a name="l00214"></a>00214 
+<a name="l00215"></a>00215   <span class="comment">/* Cube Creation */</span>
+<a name="l00216"></a>00216   <span class="comment">/*indicates if the slitlet distances are determined by a north-south-test </span>
+<a name="l00217"></a>00217 <span class="comment">     (yes) or slitlet edge fits (no)</span>
+<a name="l00218"></a>00218 <span class="comment">  */</span>
+<a name="l00219"></a>00219   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.objnod.nord_south_index"</span>,
+<a name="l00220"></a>00220                   CPL_TYPE_BOOL,
+<a name="l00221"></a>00221                               <span class="stringliteral">"Nord South Index Switch: "</span>
+<a name="l00222"></a>00222                               <span class="stringliteral">"indicates if the slitlet distances are "</span>
+<a name="l00223"></a>00223                               <span class="stringliteral">"determined by a north-south-test (TRUE) "</span>
+<a name="l00224"></a>00224                               <span class="stringliteral">"or slitlet edge fits (FALSE)"</span>,
+<a name="l00225"></a>00225                               <span class="stringliteral">"sinfoni.objnod"</span>,
+<a name="l00226"></a>00226                               TRUE);
+<a name="l00227"></a>00227 
+<a name="l00228"></a>00228 
+<a name="l00229"></a>00229   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"objnod-ns_ind"</span>);
+<a name="l00230"></a>00230   cpl_parameterlist_append(list, p);
+<a name="l00231"></a>00231 
+<a name="l00232"></a>00232 
+<a name="l00233"></a>00233   <span class="comment">/* Cube Creation */</span>
+<a name="l00234"></a>00234   <span class="comment">/*indicates if the slitlet distances are determined by a north-south-test </span>
+<a name="l00235"></a>00235 <span class="comment">     (yes) or slitlet edge fits (no)</span>
+<a name="l00236"></a>00236 <span class="comment">  */</span>
+<a name="l00237"></a>00237   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.objnod.flux_cor"</span>,
+<a name="l00238"></a>00238                               CPL_TYPE_BOOL,
+<a name="l00239"></a>00239                               <span class="stringliteral">"Flux correction: "</span>,
+<a name="l00240"></a>00240                               <span class="stringliteral">"sinfoni.objnod"</span>,
+<a name="l00241"></a>00241                               FALSE);
+<a name="l00242"></a>00242 
+<a name="l00243"></a>00243 
+<a name="l00244"></a>00244   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"objnod-flux_cor"</span>);
+<a name="l00245"></a>00245   cpl_parameterlist_append(list, p);
+<a name="l00246"></a>00246 
+<a name="l00247"></a>00247 
+<a name="l00248"></a>00248 
+<a name="l00249"></a>00249 
+<a name="l00250"></a>00250  <span class="comment">/* Fine tuning */</span>
+<a name="l00251"></a>00251   <span class="comment">/* Method */</span>
+<a name="l00252"></a>00252   p = cpl_parameter_new_enum(<span class="stringliteral">"sinfoni.objnod.fine_tuning_method"</span>,
+<a name="l00253"></a>00253                   CPL_TYPE_STRING,
+<a name="l00254"></a>00254                               <span class="stringliteral">"Fine Tuning Method: "</span>
+<a name="l00255"></a>00255                               <span class="stringliteral">"indicator for the shifting method to use "</span>
+<a name="l00256"></a>00256                               <span class="stringliteral">"(P: polynomial interpolation, "</span>
+<a name="l00257"></a>00257                  <span class="comment">/* " F: FFT, " */</span>
+<a name="l00258"></a>00258                               <span class="stringliteral">" S: cubic spline interpolation)"</span>,
+<a name="l00259"></a>00259                               <span class="stringliteral">"sinfoni.objnod"</span>,
+<a name="l00260"></a>00260                               <span class="stringliteral">"P"</span>,
+<a name="l00261"></a>00261                                2,
+<a name="l00262"></a>00262                               <span class="stringliteral">"P"</span>,<span class="stringliteral">"S"</span>);
+<a name="l00263"></a>00263 
+<a name="l00264"></a>00264   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"objnod-fine_tune_mtd"</span>);
+<a name="l00265"></a>00265   cpl_parameterlist_append(list, p);
+<a name="l00266"></a>00266 
+<a name="l00267"></a>00267   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.objnod.order"</span>,
+<a name="l00268"></a>00268                   CPL_TYPE_INT,
+<a name="l00269"></a>00269                               <span class="stringliteral">"Fine Tuning polynomial order: "</span> 
+<a name="l00270"></a>00270                               <span class="stringliteral">"order of the polynomial if the polynomial "</span>
+<a name="l00271"></a>00271                               <span class="stringliteral">"interpolation shifting method is used."</span>,
+<a name="l00272"></a>00272                               <span class="stringliteral">"sinfoni.objnod"</span>,
+<a name="l00273"></a>00273                               2);
+<a name="l00274"></a>00274 
+<a name="l00275"></a>00275   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"objnod-order"</span>);
+<a name="l00276"></a>00276   cpl_parameterlist_append(list, p);
+<a name="l00277"></a>00277 
+<a name="l00278"></a>00278     <span class="comment">/* Fill the parameters list */</span>
+<a name="l00279"></a>00279     <span class="comment">/* --stropt */</span>
+<a name="l00280"></a>00280 
+<a name="l00281"></a>00281   
+<a name="l00282"></a>00282     <span class="comment">/* Return */</span>
+<a name="l00283"></a>00283     <span class="keywordflow">return</span> 0;
+<a name="l00284"></a>00284 }
+<a name="l00285"></a>00285 
+<a name="l00286"></a>00286 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00292"></a>00292 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00293"></a>00293 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_cube_create_exec(cpl_plugin * plugin)
+<a name="l00294"></a>00294 {
+<a name="l00295"></a>00295     cpl_recipe  *   recipe ;
+<a name="l00296"></a>00296     <span class="keywordtype">int</span> result=0;    
+<a name="l00297"></a>00297     cpl_errorstate initial_errorstate = cpl_errorstate_get();
+<a name="l00298"></a>00298 
+<a name="l00299"></a>00299     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00300"></a>00300     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00301"></a>00301         recipe = (cpl_recipe *)plugin ;
+<a name="l00302"></a>00302     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00303"></a>00303        sinfo_msg(<span class="stringliteral">"Welcome to SINFONI Pipeline release %d.%d.%d"</span>,
+<a name="l00304"></a>00304         SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
+<a name="l00305"></a>00305 
+<a name="l00306"></a>00306     result=sinfo_cube_create(recipe->parameters, recipe->frames) ;
+<a name="l00307"></a>00307     <span class="keywordflow">if</span> (!cpl_errorstate_is_equal(initial_errorstate)) {                      
+<a name="l00308"></a>00308         <span class="comment">/* Dump the error history since recipe execution start.                </span>
+<a name="l00309"></a>00309 <span class="comment">           At this point the recipe cannot recover from the error */</span>           
+<a name="l00310"></a>00310         cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);              
+<a name="l00311"></a>00311     } 
+<a name="l00312"></a>00312     <span class="keywordflow">return</span> result;
+<a name="l00313"></a>00313 }
+<a name="l00314"></a>00314 
+<a name="l00315"></a>00315 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00321"></a>00321 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00322"></a>00322 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_cube_create_destroy(cpl_plugin * plugin)
+<a name="l00323"></a>00323 {
+<a name="l00324"></a>00324     cpl_recipe  *   recipe ;
+<a name="l00325"></a>00325     
+<a name="l00326"></a>00326     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00327"></a>00327     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00328"></a>00328         recipe = (cpl_recipe *)plugin ;
+<a name="l00329"></a>00329     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00330"></a>00330 
+<a name="l00331"></a>00331     cpl_parameterlist_delete(recipe->parameters) ; 
+<a name="l00332"></a>00332     <span class="keywordflow">return</span> 0 ;
+<a name="l00333"></a>00333 }
+<a name="l00334"></a>00334 
+<a name="l00335"></a>00335 
+<a name="l00336"></a>00336 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00343"></a>00343 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00344"></a>00344 <span class="keyword">static</span> <span class="keywordtype">int</span> 
+<a name="l00345"></a>00345 sinfo_cube_create(cpl_parameterlist * parameters, cpl_frameset * frames)
+<a name="l00346"></a>00346 {
+<a name="l00347"></a>00347 
+<a name="l00348"></a>00348    cpl_frame* frm_raw_on=NULL;
+<a name="l00349"></a>00349    cpl_frame* frm_raw_off=NULL;
+<a name="l00350"></a>00350    cpl_frame* frm_wav_map=NULL;
+<a name="l00351"></a>00351    cpl_frame* frm_mflat=NULL;
+<a name="l00352"></a>00352    cpl_frame* frm_distortion=NULL;
+<a name="l00353"></a>00353    cpl_frame* frm_slit_pos=NULL;
+<a name="l00354"></a>00354    cpl_frame* frm_slitlets_distance=NULL;
+<a name="l00355"></a>00355 
+<a name="l00356"></a>00356    cpl_image* ima_raw_on=NULL;
+<a name="l00357"></a>00357    cpl_image* ima_raw_off=NULL;
+<a name="l00358"></a>00358    cpl_image* ima_wav_map=NULL;
+<a name="l00359"></a>00359    cpl_image* ima_mflat=NULL;
+<a name="l00360"></a>00360    cpl_image* ima_mflat_dist=NULL;
+<a name="l00361"></a>00361    cpl_image* ima_obj_mflat=NULL;
+<a name="l00362"></a>00362    cpl_image* ima_obj_dist=NULL;
+<a name="l00363"></a>00363    cpl_image* ima_obj_res=NULL;
+<a name="l00364"></a>00364    cpl_image* ima_wav_res=NULL;
+<a name="l00365"></a>00365    cpl_image* ima_wav_dif=NULL;
+<a name="l00366"></a>00366 
+<a name="l00367"></a>00367    cpl_imagelist* cube=NULL;
+<a name="l00368"></a>00368    cpl_imagelist* outcube=NULL;
+<a name="l00369"></a>00369    cpl_imagelist* outcube2=NULL;
+<a name="l00370"></a>00370 
+<a name="l00371"></a>00371    <span class="comment">//cpl_table* tab_distortion=NULL;</span>
+<a name="l00372"></a>00372    <span class="comment">//cpl_table* tab_slit_pos=NULL;</span>
+<a name="l00373"></a>00373 
+<a name="l00374"></a>00374    <span class="keywordtype">float</span> mi=0;
+<a name="l00375"></a>00375    <span class="keywordtype">float</span> ma=0;
+<a name="l00376"></a>00376    <span class="keywordtype">double</span> dis=0 ;
+<a name="l00377"></a>00377    <span class="keywordtype">double</span> cwav=0 ;
+<a name="l00378"></a>00378    <span class="keywordtype">int</span> cpix=0 ;
+<a name="l00379"></a>00379    <span class="keywordtype">int</span> nx=0;
+<a name="l00380"></a>00380    <span class="keywordtype">int</span> ny=0;
+<a name="l00381"></a>00381     <span class="keywordtype">float</span> fcol=0;
+<a name="l00382"></a>00382    <span class="keywordtype">float</span>* pd=NULL;
+<a name="l00383"></a>00383    <span class="keywordtype">float</span>* pw=NULL;
+<a name="l00384"></a>00384    <span class="keywordtype">int</span> i=0;
+<a name="l00385"></a>00385    <span class="keywordtype">int</span> j=0;
+<a name="l00386"></a>00386    <span class="keywordtype">float</span>** slit_edges=NULL;
+<a name="l00387"></a>00387    <span class="keywordtype">float</span>* distances=NULL;
+<a name="l00388"></a>00388    <span class="keywordtype">float</span>* correct_dist=NULL;
+<a name="l00389"></a>00389    <span class="keywordtype">char</span> kernel[80];
+<a name="l00390"></a>00390    <span class="keywordtype">char</span> poly_file[80];
+<a name="l00391"></a>00391    <span class="keywordtype">char</span> pos_list[80];
+<a name="l00392"></a>00392    <span class="keywordtype">char</span> dist_list[80];
+<a name="l00393"></a>00393 
+<a name="l00394"></a>00394 
+<a name="l00395"></a>00395     <span class="keywordtype">int</span> jit_ind=0;
+<a name="l00396"></a>00396    <span class="keywordtype">int</span> ns_index=0;
+<a name="l00397"></a>00397    <span class="keywordtype">int</span> n_coeffs=0;
+<a name="l00398"></a>00398    <span class="keywordtype">int</span> nrows=0;
+<a name="l00399"></a>00399    cpl_parameter* p=NULL;
+<a name="l00400"></a>00400    <span class="keywordtype">int</span> nslits=32;
+<a name="l00401"></a>00401    <span class="keywordtype">int</span> flux_cor=0;
+<a name="l00402"></a>00402    <span class="keyword">const</span> <span class="keywordtype">char</span>* fine_tuning_method=NULL;
+<a name="l00403"></a>00403    <span class="keywordtype">int</span> fine_tuning_pol_order=0;
+<a name="l00404"></a>00404    <span class="keywordtype">float</span> center_x=0;
+<a name="l00405"></a>00405    <span class="keywordtype">float</span> center_y=0;
+<a name="l00406"></a>00406 
+<a name="l00407"></a>00407    <span class="comment">/* Identify the RAW and CALIB frames in the input frameset */</span>
+<a name="l00408"></a>00408     check(sinfo_dfs_set_groups(frames),
+<a name="l00409"></a>00409          <span class="stringliteral">"Cannot identify RAW and CALIB frames"</span>) ;
+<a name="l00410"></a>00410 
+<a name="l00411"></a>00411    check_nomsg(p=cpl_parameterlist_find(parameters,
+<a name="l00412"></a>00412                                         <span class="stringliteral">"sinfoni.objnod.flux_cor"</span>));
+<a name="l00413"></a>00413    check_nomsg(flux_cor=cpl_parameter_get_bool(p));
+<a name="l00414"></a>00414 
+<a name="l00415"></a>00415    check_nomsg(p=cpl_parameterlist_find(parameters,
+<a name="l00416"></a>00416                                         <span class="stringliteral">"sinfoni.objnod.jitter_index"</span>));
+<a name="l00417"></a>00417    check_nomsg(jit_ind=cpl_parameter_get_bool(p));
+<a name="l00418"></a>00418 
+<a name="l00419"></a>00419    check_nomsg(p=cpl_parameterlist_find(parameters,
+<a name="l00420"></a>00420                                         <span class="stringliteral">"sinfoni.objnod.kernel_type"</span>));
+<a name="l00421"></a>00421    check_nomsg(strcpy(kernel,cpl_parameter_get_string(p)));
+<a name="l00422"></a>00422 
+<a name="l00423"></a>00423    check_nomsg(p=cpl_parameterlist_find(parameters,<span class="stringliteral">"sinfoni.objnod.n_coeffs"</span>));
+<a name="l00424"></a>00424    check_nomsg(n_coeffs=cpl_parameter_get_int(p));
+<a name="l00425"></a>00425 
+<a name="l00426"></a>00426 
+<a name="l00427"></a>00427    check_nomsg(p=cpl_parameterlist_find(parameters,
+<a name="l00428"></a>00428                                         <span class="stringliteral">"sinfoni.objnod.nord_south_index"</span>));
+<a name="l00429"></a>00429    check_nomsg(ns_index=cpl_parameter_get_bool(p));
+<a name="l00430"></a>00430 
+<a name="l00431"></a>00431 
+<a name="l00432"></a>00432    check_nomsg(p=cpl_parameterlist_find(parameters,
+<a name="l00433"></a>00433                                         <span class="stringliteral">"sinfoni.objnod.fine_tuning_method"</span>));
+<a name="l00434"></a>00434    check_nomsg(fine_tuning_method=cpl_parameter_get_string(p));
+<a name="l00435"></a>00435 
+<a name="l00436"></a>00436    check_nomsg(p=cpl_parameterlist_find(parameters,
+<a name="l00437"></a>00437                                         <span class="stringliteral">"sinfoni.objnod.order"</span>));
+<a name="l00438"></a>00438    check_nomsg(fine_tuning_pol_order=cpl_parameter_get_int(p));
+<a name="l00439"></a>00439 
+<a name="l00440"></a>00440  
+<a name="l00441"></a>00441    cknull(frm_raw_on=cpl_frameset_find(frames,RAW_ON),
+<a name="l00442"></a>00442           <span class="stringliteral">"Missing required input %s"</span>,RAW_ON);
+<a name="l00443"></a>00443    cknull(frm_raw_off=cpl_frameset_find(frames,RAW_OFF),
+<a name="l00444"></a>00444           <span class="stringliteral">"Missing required input %s"</span>,RAW_OFF);
+<a name="l00445"></a>00445    cknull(frm_wav_map=cpl_frameset_find(frames,PRO_WAVE_MAP),
+<a name="l00446"></a>00446                 <span class="stringliteral">"Missing required input %s"</span>,PRO_WAVE_MAP);
+<a name="l00447"></a>00447    cknull(frm_mflat=cpl_frameset_find(frames,PRO_MASTER_FLAT_LAMP),
+<a name="l00448"></a>00448                 <span class="stringliteral">"Missing required input %s"</span>,PRO_WAVE_MAP);
+<a name="l00449"></a>00449 
+<a name="l00450"></a>00450    check_nomsg(frm_distortion=cpl_frameset_find(frames,PRO_DISTORTION));
+<a name="l00451"></a>00451    check_nomsg(frm_slit_pos=cpl_frameset_find(frames,PRO_SLIT_POS));
+<a name="l00452"></a>00452    check_nomsg(frm_slitlets_distance=
+<a name="l00453"></a>00453                cpl_frameset_find(frames,PRO_SLITLETS_DISTANCE));
+<a name="l00454"></a>00454 
+<a name="l00455"></a>00455    strcpy(pos_list,cpl_frame_get_filename(frm_slit_pos));
+<a name="l00456"></a>00456    strcpy(dist_list,cpl_frame_get_filename(frm_slitlets_distance));
+<a name="l00457"></a>00457    strcpy(poly_file,cpl_frame_get_filename(frm_distortion));
+<a name="l00458"></a>00458 
+<a name="l00459"></a>00459  
+<a name="l00460"></a>00460    check_nomsg(ima_raw_on=cpl_image_load(cpl_frame_get_filename(frm_raw_on),
+<a name="l00461"></a>00461                                          CPL_TYPE_FLOAT,0,0));
+<a name="l00462"></a>00462  
+<a name="l00463"></a>00463    check_nomsg(ima_raw_off=cpl_image_load(cpl_frame_get_filename(frm_raw_off),
+<a name="l00464"></a>00464                                           CPL_TYPE_FLOAT,0,0));
+<a name="l00465"></a>00465 
+<a name="l00466"></a>00466  
+<a name="l00467"></a>00467    check_nomsg(ima_wav_map=cpl_image_load(cpl_frame_get_filename(frm_wav_map),
+<a name="l00468"></a>00468                                           CPL_TYPE_FLOAT,0,0));
+<a name="l00469"></a>00469  
+<a name="l00470"></a>00470    check_nomsg(ima_mflat=cpl_image_load(cpl_frame_get_filename(frm_mflat),
+<a name="l00471"></a>00471                                           CPL_TYPE_FLOAT,0,0));
+<a name="l00472"></a>00472 
+<a name="l00473"></a>00473  
+<a name="l00474"></a>00474 
+<a name="l00475"></a>00475    check_nomsg(cpl_image_subtract(ima_raw_on,ima_raw_off));
+<a name="l00476"></a>00476    cpl_image_save(ima_raw_on,<span class="stringliteral">"ima_sub.fits"</span>, CPL_BPP_IEEE_FLOAT, 
+<a name="l00477"></a>00477                   NULL,CPL_IO_DEFAULT);
+<a name="l00478"></a>00478 
+<a name="l00479"></a>00479    cknull_nomsg(ima_obj_mflat=sinfo_new_div_images_robust(ima_raw_on,
+<a name="l00480"></a>00480                                                          ima_mflat));
+<a name="l00481"></a>00481    cpl_image_save(ima_obj_mflat,<span class="stringliteral">"ima_obj_mflat.fits"</span>, CPL_BPP_IEEE_FLOAT, 
+<a name="l00482"></a>00482                   NULL,CPL_IO_DEFAULT);
+<a name="l00483"></a>00483  
+<a name="l00484"></a>00484 
+<a name="l00485"></a>00485 <span class="comment">//The following is not needed</span>
+<a name="l00486"></a>00486    cknull_nomsg(ima_mflat_dist=sinfo_new_image_warp_fits(ima_mflat,kernel,
+<a name="l00487"></a>00487                                                          poly_file));
+<a name="l00488"></a>00488 
+<a name="l00489"></a>00489    cpl_image_save(ima_mflat_dist,<span class="stringliteral">"ima_mflat_dist.fits"</span>, CPL_BPP_IEEE_FLOAT, 
+<a name="l00490"></a>00490                   NULL,CPL_IO_DEFAULT);
+<a name="l00491"></a>00491 
+<a name="l00492"></a>00492    cknull_nomsg(ima_obj_dist=sinfo_new_image_warp_fits(ima_obj_mflat, 
+<a name="l00493"></a>00493                                                        kernel, 
+<a name="l00494"></a>00494                                                        poly_file));
+<a name="l00495"></a>00495 
+<a name="l00496"></a>00496    cpl_image_save(ima_obj_dist,<span class="stringliteral">"ima_obj_dist.fits"</span>, CPL_BPP_IEEE_FLOAT, 
+<a name="l00497"></a>00497                   NULL,CPL_IO_DEFAULT);
+<a name="l00498"></a>00498  
+<a name="l00499"></a>00499    cknull(ima_obj_res = sinfo_new_defined_resampling(ima_obj_dist, 
+<a name="l00500"></a>00500                             ima_wav_map, 
+<a name="l00501"></a>00501                             n_coeffs,
+<a name="l00502"></a>00502                             &nrows,
+<a name="l00503"></a>00503                             &dis,
+<a name="l00504"></a>00504                             &mi,
+<a name="l00505"></a>00505                             &ma,
+<a name="l00506"></a>00506                             &cwav,
+<a name="l00507"></a>00507                             &cpix),
+<a name="l00508"></a>00508          <span class="stringliteral">" sinfo_definedResampling() failed"</span> ) ;
+<a name="l00509"></a>00509 
+<a name="l00510"></a>00510 
+<a name="l00511"></a>00511 
+<a name="l00512"></a>00512   cpl_image_save(ima_obj_res,<span class="stringliteral">"ima_obj_res.fits"</span>, CPL_BPP_IEEE_FLOAT, 
+<a name="l00513"></a>00513                   NULL,CPL_IO_DEFAULT);
+<a name="l00514"></a>00514 
+<a name="l00515"></a>00515 
+<a name="l00516"></a>00516     <span class="comment">//We create an image with the derivatives</span>
+<a name="l00517"></a>00517   nx=cpl_image_get_size_x(ima_wav_map);
+<a name="l00518"></a>00518   ny=cpl_image_get_size_y(ima_wav_map);
+<a name="l00519"></a>00519 
+<a name="l00520"></a>00520       check_nomsg(ima_wav_dif=cpl_image_new(nx,ny,CPL_TYPE_FLOAT));
+<a name="l00521"></a>00521       pw=cpl_image_get_data(ima_wav_map);
+<a name="l00522"></a>00522       pd=cpl_image_get_data(ima_wav_dif);
+<a name="l00523"></a>00523 
+<a name="l00524"></a>00524     
+<a name="l00525"></a>00525       <span class="keywordflow">for</span>(i=1;i<nx-1;i++) {
+<a name="l00526"></a>00526     <span class="keywordflow">for</span>(j=1;j<ny-1;j++) {
+<a name="l00527"></a>00527       <span class="keywordflow">if</span>(!isnan(pd[nx*j+i])) {
+<a name="l00528"></a>00528         pd[nx*j+i]=2.0*dis/(pw[nx*(j+1)+i]-pw[nx*(j-1)+i]);
+<a name="l00529"></a>00529       }
+<a name="l00530"></a>00530     }
+<a name="l00531"></a>00531     <span class="keywordflow">if</span>(!isnan(pd[i])) {
+<a name="l00532"></a>00532       pd[i]=dis/(pw[nx+i]-pw[i]);
+<a name="l00533"></a>00533     }
+<a name="l00534"></a>00534     <span class="keywordflow">if</span>(!isnan(pd[nx*(ny-1)+i])) {
+<a name="l00535"></a>00535       pd[nx*(ny-1)+i]=dis/(pw[nx*(ny-1)+i]-pw[nx*(ny-2)+i]);
+<a name="l00536"></a>00536     }
+<a name="l00537"></a>00537       }
+<a name="l00538"></a>00538     
+<a name="l00539"></a>00539 
+<a name="l00540"></a>00540       <span class="comment">//cpl_image_save(ima_wav_dif,"diff.fits", </span>
+<a name="l00541"></a>00541       <span class="comment">//CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT);</span>
+<a name="l00542"></a>00542 
+<a name="l00543"></a>00543 
+<a name="l00544"></a>00544 
+<a name="l00545"></a>00545       cknull(ima_wav_res = sinfo_new_defined_resampling(ima_wav_dif, 
+<a name="l00546"></a>00546                             ima_wav_map, 
+<a name="l00547"></a>00547                             n_coeffs,
+<a name="l00548"></a>00548                             &nrows,
+<a name="l00549"></a>00549                             &dis,
+<a name="l00550"></a>00550                             &mi,
+<a name="l00551"></a>00551                             &ma,
+<a name="l00552"></a>00552                             &cwav,
+<a name="l00553"></a>00553                             &cpix),
+<a name="l00554"></a>00554          <span class="stringliteral">" sinfo_definedResampling() failed"</span> ) ;
+<a name="l00555"></a>00555 
+<a name="l00556"></a>00556       <span class="keywordflow">if</span>(flux_cor) {
+<a name="l00557"></a>00557     sinfo_msg(<span class="stringliteral">"Apply flux correction"</span>);
+<a name="l00558"></a>00558     cpl_image_divide(ima_obj_res,ima_wav_res);
+<a name="l00559"></a>00559       }
+<a name="l00560"></a>00560 
+<a name="l00561"></a>00561 
+<a name="l00562"></a>00562       <span class="comment">//cpl_image_save(ima_wav_res,"res_diff.fits", </span>
+<a name="l00563"></a>00563       <span class="comment">//CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT);</span>
+<a name="l00564"></a>00564 
+<a name="l00565"></a>00565 
+<a name="l00566"></a>00566 
+<a name="l00567"></a>00567   cpl_image_save(ima_wav_res,<span class="stringliteral">"ima_wav_res.fits"</span>, CPL_BPP_IEEE_FLOAT, 
+<a name="l00568"></a>00568                   NULL,CPL_IO_DEFAULT);
+<a name="l00569"></a>00569 
+<a name="l00570"></a>00570 
+<a name="l00571"></a>00571       <span class="comment">//To rescale in flux we divide the resampled image and </span>
+<a name="l00572"></a>00572       <span class="comment">//the resampled derivatives. At this point ima_obj_res should have same </span>
+<a name="l00573"></a>00573       <span class="comment">//flux as input image (im.diff)</span>
+<a name="l00574"></a>00574 
+<a name="l00575"></a>00575       <span class="comment">//ima_obj_res=cpl_image_duplicate(ima_wav_res);</span>
+<a name="l00576"></a>00576       <span class="comment">//sinfo_free_image(&ima_wav_res);</span>
+<a name="l00577"></a>00577       <span class="keywordflow">if</span>(flux_cor) {
+<a name="l00578"></a>00578     sinfo_msg(<span class="stringliteral">"Apply flux correction"</span>);
+<a name="l00579"></a>00579     cpl_image_divide(ima_obj_res,ima_wav_res);
+<a name="l00580"></a>00580       }
+<a name="l00581"></a>00581 
+<a name="l00582"></a>00582 
+<a name="l00583"></a>00583 
+<a name="l00584"></a>00584 
+<a name="l00585"></a>00585       <span class="comment">/*---select north-south-test or fitting of slitlet edges--*/</span>
+<a name="l00586"></a>00586       <span class="keywordflow">if</span> (ns_index == 0) {
+<a name="l00587"></a>00587     sinfo_msg(<span class="stringliteral">"cfg->northsouthInd == 0"</span>);
+<a name="l00588"></a>00588     cknull(slit_edges=sinfo_read_slitlets_edges(nslits,pos_list),
+<a name="l00589"></a>00589            <span class="stringliteral">"error reading slitlets edges"</span>);
+<a name="l00590"></a>00590       } <span class="keywordflow">else</span> {
+<a name="l00591"></a>00591     sinfo_msg(<span class="stringliteral">"cfg->northsouthInd != 0"</span>);
+<a name="l00592"></a>00592     cknull(distances = sinfo_read_distances(nslits,dist_list),
+<a name="l00593"></a>00593            <span class="stringliteral">"error reading distances"</span>);
+<a name="l00594"></a>00594       }
+<a name="l00595"></a>00595  
+<a name="l00596"></a>00596       cknull(correct_dist = (<span class="keywordtype">float</span>*) cpl_calloc(nslits, <span class="keyword">sizeof</span> (<span class="keywordtype">float</span>)),
+<a name="l00597"></a>00597          <span class="stringliteral">" could not allocate memory!"</span>) ;
+<a name="l00598"></a>00598 
+<a name="l00599"></a>00599       sinfo_msg(<span class="stringliteral">"Create cube object"</span>);
+<a name="l00600"></a>00600       <span class="keywordflow">if</span> (ns_index ==0 ) {
+<a name="l00601"></a>00601 
+<a name="l00602"></a>00602         cknull(cube = sinfo_new_make_cube_spi(ima_obj_res,slit_edges,
+<a name="l00603"></a>00603                           correct_dist),
+<a name="l00604"></a>00604            <span class="stringliteral">"could not construct data cube!"</span>) ;
+<a name="l00605"></a>00605 
+<a name="l00606"></a>00606       }  <span class="keywordflow">else</span> {
+<a name="l00607"></a>00607     cknull(cube = sinfo_new_make_cube_dist(ima_obj_res,fcol,distances,
+<a name="l00608"></a>00608                            correct_dist),
+<a name="l00609"></a>00609            <span class="stringliteral">"could not construct a data cube!"</span>) ;
+<a name="l00610"></a>00610       }
+<a name="l00611"></a>00611       sinfo_free_image(&ima_obj_res);
+<a name="l00612"></a>00612 
+<a name="l00613"></a>00613 
+<a name="l00614"></a>00614      cknull(outcube2=sinfo_new_fine_tune(cube,
+<a name="l00615"></a>00615                       correct_dist,
+<a name="l00616"></a>00616                       fine_tuning_method,
+<a name="l00617"></a>00617                       fine_tuning_pol_order,
+<a name="l00618"></a>00618                       nslits),
+<a name="l00619"></a>00619          <span class="stringliteral">" could not fine tune the data cube"</span>) ;
+<a name="l00620"></a>00620 
+<a name="l00621"></a>00621       sinfo_msg(<span class="stringliteral">"Stretch output cube along Y direction"</span>);
+<a name="l00622"></a>00622       cknull(outcube = sinfo_new_bin_cube(outcube2,1,2,0,63,0,63),
+<a name="l00623"></a>00623          <span class="stringliteral">"Error binning cube"</span>);
+<a name="l00624"></a>00624       sinfo_free_imagelist(&cube);
+<a name="l00625"></a>00625 
+<a name="l00626"></a>00626       ck0(sinfo_pro_save_ims(outcube,frames,frames,<span class="stringliteral">"out_cube.fits"</span>,<span class="stringliteral">"CUBE"</span>,NULL,
+<a name="l00627"></a>00627                              <span class="stringliteral">"sinfo_utl_cube_create"</span>,parameters),
+<a name="l00628"></a>00628           <span class="stringliteral">"cannot save cube %s"</span>, <span class="stringliteral">"out_cube.fits"</span>);
+<a name="l00629"></a>00629 
+<a name="l00630"></a>00630 
+<a name="l00631"></a>00631       check_nomsg(center_x = cpl_image_get_size_x(
+<a name="l00632"></a>00632                           cpl_imagelist_get(outcube,0))/2.+0.5) ;
+<a name="l00633"></a>00633       check_nomsg(center_y = cpl_image_get_size_y(
+<a name="l00634"></a>00634                           cpl_imagelist_get(outcube,0))/2.+0.5 );
+<a name="l00635"></a>00635 
+<a name="l00636"></a>00636      sinfo_new_set_wcs_cube(outcube,<span class="stringliteral">"out_cube.fits"</span>, cwav, dis, 
+<a name="l00637"></a>00637                  cpix, center_x, center_y);
+<a name="l00638"></a>00638 
+<a name="l00639"></a>00639 
+<a name="l00640"></a>00640   cleanup:      
+<a name="l00641"></a>00641 
+<a name="l00642"></a>00642     <span class="keywordflow">if</span> (ns_index ==0 ) {
+<a name="l00643"></a>00643       <span class="keywordflow">if</span>(slit_edges != NULL) {
+<a name="l00644"></a>00644     sinfo_new_destroy_2Dfloatarray(&slit_edges,nslits);
+<a name="l00645"></a>00645       }
+<a name="l00646"></a>00646     } <span class="keywordflow">else</span> {
+<a name="l00647"></a>00647       <span class="keywordflow">if</span> (distances != NULL ) {
+<a name="l00648"></a>00648     sinfo_new_destroy_array(&distances);
+<a name="l00649"></a>00649       }
+<a name="l00650"></a>00650     }
+<a name="l00651"></a>00651 
+<a name="l00652"></a>00652 
+<a name="l00653"></a>00653 
+<a name="l00654"></a>00654    
+<a name="l00655"></a>00655       sinfo_free_float(&correct_dist) ;
+<a name="l00656"></a>00656       sinfo_free_imagelist(&cube);
+<a name="l00657"></a>00657       sinfo_free_imagelist(&outcube);
+<a name="l00658"></a>00658       sinfo_free_imagelist(&outcube2);
+<a name="l00659"></a>00659       sinfo_free_image(&ima_raw_on);
+<a name="l00660"></a>00660       sinfo_free_image(&ima_raw_off);
+<a name="l00661"></a>00661       sinfo_free_image(&ima_wav_map);
+<a name="l00662"></a>00662       sinfo_free_image(&ima_mflat);
+<a name="l00663"></a>00663       sinfo_free_image(&ima_mflat_dist);
+<a name="l00664"></a>00664       sinfo_free_image(&ima_obj_res);
+<a name="l00665"></a>00665       sinfo_free_image(&ima_obj_mflat);
+<a name="l00666"></a>00666       sinfo_free_image(&ima_obj_dist);
+<a name="l00667"></a>00667       sinfo_free_image(&ima_obj_res);
+<a name="l00668"></a>00668       sinfo_free_image(&ima_wav_res);
+<a name="l00669"></a>00669       sinfo_free_image(&ima_wav_dif);
+<a name="l00670"></a>00670     
+<a name="l00671"></a>00671       <span class="keywordflow">return</span> 0 ;
+<a name="l00672"></a>00672 
+<a name="l00673"></a>00673 }
+<a name="l00674"></a>00674 
+<a name="l00675"></a>00675 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__utl__cube__test_8c_source.html b/html/sinfo__utl__cube__test_8c_source.html
new file mode 100644
index 0000000..8c72022
--- /dev/null
+++ b/html/sinfo__utl__cube__test_8c_source.html
@@ -0,0 +1,257 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_utl_cube_test.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_utl_cube_test.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_utl_cube_test.c,v 1.8 2008/02/12 09:11:10 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the SINFONI Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2008/02/12 09:11:10 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.8 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span>
+<a name="l00032"></a>00032 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                                Includes</span>
+<a name="l00034"></a>00034 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 
+<a name="l00036"></a>00036 <span class="comment">/* cpl */</span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00038"></a>00038 <span class="comment">/* irplib */</span>
+<a name="l00039"></a>00039 <span class="preprocessor">#include <irplib_utils.h></span>
+<a name="l00040"></a>00040 
+<a name="l00041"></a>00041 <span class="preprocessor">#include <sinfo_tpl_utils.h></span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include <sinfo_pfits.h></span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include <sinfo_tpl_dfs.h></span>
+<a name="l00044"></a>00044 <span class="preprocessor">#include <sinfo_utl_cube_test.h></span>
+<a name="l00045"></a>00045 
+<a name="l00046"></a>00046 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00047"></a>00047 <span class="comment">                            Functions prototypes</span>
+<a name="l00048"></a>00048 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00049"></a>00049 
+<a name="l00050"></a>00050 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_cube_test_create(cpl_plugin *) ;
+<a name="l00051"></a>00051 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_cube_test_exec(cpl_plugin *) ;
+<a name="l00052"></a>00052 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_cube_test_destroy(cpl_plugin *) ;
+<a name="l00053"></a>00053 
+<a name="l00054"></a>00054 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00055"></a>00055 <span class="comment">                            Static variables</span>
+<a name="l00056"></a>00056 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00057"></a>00057 
+<a name="l00058"></a>00058 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_utl_cube_test_description[] =
+<a name="l00059"></a>00059 <span class="stringliteral">"This recipe perform cubes combination.\n"</span>
+<a name="l00060"></a>00060 <span class="stringliteral">"The input files are several cubeses\n"</span>
+<a name="l00061"></a>00061 <span class="stringliteral">"their associated tags should be CUBE.\n"</span>
+<a name="l00062"></a>00062 <span class="stringliteral">"The output is a cube PRO_CUBE resulting from the input cubes\n"</span>
+<a name="l00063"></a>00063 <span class="stringliteral">"accurding to the value of op where op indicates the operation to be \n"</span>
+<a name="l00064"></a>00064 <span class="stringliteral">"performed specified by the parameter sinfoni.sinfo_utl_cube_test.op\n"</span>
+<a name="l00065"></a>00065 <span class="stringliteral">"Information on relevant parameters can be found with\n"</span>
+<a name="l00066"></a>00066 <span class="stringliteral">"esorex --params sinfo_utl_cube_test\n"</span>
+<a name="l00067"></a>00067 <span class="stringliteral">"esorex --help sinfo_utl_cube_test\n"</span>
+<a name="l00068"></a>00068 <span class="stringliteral">"\n"</span>;
+<a name="l00069"></a>00069 
+<a name="l00070"></a>00070 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00071"></a>00071 <span class="comment">                                Functions code</span>
+<a name="l00072"></a>00072 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00073"></a>00073 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00077"></a>00077 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00079"></a>00079 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00087"></a>00087 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00088"></a><a class="code" href="group__sinfo__utl__cube__test.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693">00088</a> <span class="keywordtype">int</span> <a class="code" href="group__sinfo__rec__detlin.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693" title="Build the list of available plugins, for this module.">cpl_plugin_get_info</a>(cpl_pluginlist * list)
+<a name="l00089"></a>00089 {
+<a name="l00090"></a>00090     cpl_recipe  *   recipe = cpl_calloc(1, <span class="keyword">sizeof</span> *recipe ) ;
+<a name="l00091"></a>00091     cpl_plugin  *   plugin = &recipe->interface ;
+<a name="l00092"></a>00092 
+<a name="l00093"></a>00093     cpl_plugin_init(plugin,
+<a name="l00094"></a>00094                     CPL_PLUGIN_API,
+<a name="l00095"></a>00095                     SINFONI_BINARY_VERSION,
+<a name="l00096"></a>00096                     CPL_PLUGIN_TYPE_RECIPE,
+<a name="l00097"></a>00097                     <span class="stringliteral">"sinfo_utl_cube_test"</span>,
+<a name="l00098"></a>00098                     <span class="stringliteral">"Combines a cube list in an output cube"</span>,
+<a name="l00099"></a>00099                     sinfo_utl_cube_test_description,
+<a name="l00100"></a>00100                     <span class="stringliteral">"Andrea Modigliani"</span>,
+<a name="l00101"></a>00101                     <span class="stringliteral">"Andrea.Modigliani at eso.org"</span>,
+<a name="l00102"></a>00102                     sinfo_get_license(),
+<a name="l00103"></a>00103                     sinfo_utl_cube_test_create,
+<a name="l00104"></a>00104                     sinfo_utl_cube_test_exec,
+<a name="l00105"></a>00105                     sinfo_utl_cube_test_destroy) ;
+<a name="l00106"></a>00106 
+<a name="l00107"></a>00107     cpl_pluginlist_append(list, plugin) ;
+<a name="l00108"></a>00108     
+<a name="l00109"></a>00109     <span class="keywordflow">return</span> 0;
+<a name="l00110"></a>00110 }
+<a name="l00111"></a>00111 
+<a name="l00112"></a>00112 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00121"></a>00121 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00122"></a>00122 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_cube_test_create(cpl_plugin * plugin)
+<a name="l00123"></a>00123 {
+<a name="l00124"></a>00124     cpl_recipe      * recipe ;
+<a name="l00125"></a>00125     cpl_parameter   * p ;
+<a name="l00126"></a>00126 
+<a name="l00127"></a>00127     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00128"></a>00128     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00129"></a>00129         recipe = (cpl_recipe *)plugin ;
+<a name="l00130"></a>00130     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00131"></a>00131     cpl_error_reset();
+<a name="l00132"></a>00132     <a class="code" href="group__irplib__utils.html#gaf9d392144014e2363054bc3f83c8e47e" title="Reset IRPLIB state.">irplib_reset</a>();
+<a name="l00133"></a>00133 
+<a name="l00134"></a>00134     <span class="comment">/* Create the parameters list in the cpl_recipe object */</span>
+<a name="l00135"></a>00135     recipe->parameters = cpl_parameterlist_new() ; 
+<a name="l00136"></a>00136 
+<a name="l00137"></a>00137     <span class="comment">/* Fill the parameters list */</span>
+<a name="l00138"></a>00138     <span class="comment">/* --stropt */</span>
+<a name="l00139"></a>00139     p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.sinfo_utl_cube_test.name_i"</span>, 
+<a name="l00140"></a>00140                                 CPL_TYPE_STRING, 
+<a name="l00141"></a>00141                                 <span class="stringliteral">"Output filename"</span>, 
+<a name="l00142"></a>00142                                 <span class="stringliteral">"sinfoni.sinfo_utl_cube_test"</span>,
+<a name="l00143"></a>00143                                 <span class="stringliteral">"input.list"</span>);
+<a name="l00144"></a>00144     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"name_i"</span>) ;
+<a name="l00145"></a>00145     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00146"></a>00146 
+<a name="l00147"></a>00147 
+<a name="l00148"></a>00148     p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.sinfo_utl_cube_test.method"</span>, 
+<a name="l00149"></a>00149                                 CPL_TYPE_STRING, 
+<a name="l00150"></a>00150                                 <span class="stringliteral">"Output filename"</span>, 
+<a name="l00151"></a>00151                                 <span class="stringliteral">"sinfoni.sinfo_utl_cube_test"</span>,
+<a name="l00152"></a>00152                                 <span class="stringliteral">"sinfo_clean_mean"</span>);
+<a name="l00153"></a>00153     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"method"</span>) ;
+<a name="l00154"></a>00154     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00155"></a>00155 
+<a name="l00156"></a>00156     p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.sinfo_utl_cube_test.op"</span>, 
+<a name="l00157"></a>00157                                 CPL_TYPE_STRING, 
+<a name="l00158"></a>00158                                 <span class="stringliteral">"A possible operation"</span>, 
+<a name="l00159"></a>00159                                 <span class="stringliteral">"sinfoni.sinfo_utl_cube_test"</span>,
+<a name="l00160"></a>00160                                 <span class="stringliteral">"+"</span>);
+<a name="l00161"></a>00161     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"op"</span>) ;
+<a name="l00162"></a>00162     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00163"></a>00163 
+<a name="l00164"></a>00164 
+<a name="l00165"></a>00165     p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.sinfo_utl_cube_test.name_o"</span>, 
+<a name="l00166"></a>00166                                 CPL_TYPE_STRING, 
+<a name="l00167"></a>00167                                 <span class="stringliteral">"Output filename"</span>, 
+<a name="l00168"></a>00168                                 <span class="stringliteral">"sinfoni.sinfo_utl_cube_test"</span>,
+<a name="l00169"></a>00169                                 <span class="stringliteral">"out_cube.fits"</span>);
+<a name="l00170"></a>00170     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"name_o"</span>) ;
+<a name="l00171"></a>00171     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00172"></a>00172 
+<a name="l00173"></a>00173     p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.sinfo_utl_cube_test.name_m"</span>, 
+<a name="l00174"></a>00174                                 CPL_TYPE_STRING, 
+<a name="l00175"></a>00175                                 <span class="stringliteral">"Output filename"</span>, 
+<a name="l00176"></a>00176                                 <span class="stringliteral">"sinfoni.sinfo_utl_cube_test"</span>,
+<a name="l00177"></a>00177                                 <span class="stringliteral">"out_maskcube.fits"</span>);
+<a name="l00178"></a>00178     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"name_m"</span>) ;
+<a name="l00179"></a>00179     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00180"></a>00180 
+<a name="l00181"></a>00181     <span class="comment">/* --doubleopt */</span>
+<a name="l00182"></a>00182     p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.sinfo_utl_cube_test.xsize"</span>, 
+<a name="l00183"></a>00183                                 CPL_TYPE_INT, 
+<a name="l00184"></a>00184                                 <span class="stringliteral">"Output cube X size"</span>, 
+<a name="l00185"></a>00185                                 <span class="stringliteral">"sinfoni.sinfo_utl_cube_test"</span>, 
+<a name="l00186"></a>00186                                 80) ;
+<a name="l00187"></a>00187     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"xsize"</span>) ;
+<a name="l00188"></a>00188     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00189"></a>00189 
+<a name="l00190"></a>00190 
+<a name="l00191"></a>00191     p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.sinfo_utl_cube_test.ysize"</span>, 
+<a name="l00192"></a>00192                                 CPL_TYPE_INT, 
+<a name="l00193"></a>00193                                 <span class="stringliteral">"Output cube Y size"</span>, 
+<a name="l00194"></a>00194                                 <span class="stringliteral">"sinfoni.sinfo_utl_cube_test"</span>, 
+<a name="l00195"></a>00195                                 80) ;
+<a name="l00196"></a>00196     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"ysize"</span>) ;
+<a name="l00197"></a>00197     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00198"></a>00198 
+<a name="l00199"></a>00199 
+<a name="l00200"></a>00200     p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.sinfo_utl_cube_test.sigma"</span>, 
+<a name="l00201"></a>00201                                 CPL_TYPE_DOUBLE, 
+<a name="l00202"></a>00202                                 <span class="stringliteral">"Output cube Y size"</span>, 
+<a name="l00203"></a>00203                                 <span class="stringliteral">"sinfoni.sinfo_utl_cube_test"</span>, 
+<a name="l00204"></a>00204                                 5.) ;
+<a name="l00205"></a>00205     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"sigma"</span>) ;
+<a name="l00206"></a>00206     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00207"></a>00207  
+<a name="l00208"></a>00208 
+<a name="l00209"></a>00209   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.objnod.kappa"</span>,
+<a name="l00210"></a>00210                   CPL_TYPE_DOUBLE,
+<a name="l00211"></a>00211                               <span class="stringliteral">"kappa value for kappa-sigma clipping "</span>
+<a name="l00212"></a>00212                               <span class="stringliteral">"of coadded cube"</span>,
+<a name="l00213"></a>00213                               <span class="stringliteral">"sinfoni.objnod"</span>,
+<a name="l00214"></a>00214                               2.0);
+<a name="l00215"></a>00215 
+<a name="l00216"></a>00216   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"sinfo_objnod-kappa"</span>);
+<a name="l00217"></a>00217   cpl_parameterlist_append(recipe->parameters, p);
+<a name="l00218"></a>00218 
+<a name="l00219"></a>00219 
+<a name="l00220"></a>00220     <span class="comment">/* Return */</span>
+<a name="l00221"></a>00221     <span class="keywordflow">return</span> 0;
+<a name="l00222"></a>00222 }
+<a name="l00223"></a>00223 
+<a name="l00224"></a>00224 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00230"></a>00230 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00231"></a>00231 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_cube_test_exec(cpl_plugin * plugin)
+<a name="l00232"></a>00232 {
+<a name="l00233"></a>00233     cpl_recipe  *   recipe ;
+<a name="l00234"></a>00234     cpl_errorstate initial_errorstate = cpl_errorstate_get();
+<a name="l00235"></a>00235     <span class="keywordtype">int</span> code=0;
+<a name="l00236"></a>00236     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00237"></a>00237     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00238"></a>00238         recipe = (cpl_recipe *)plugin ;
+<a name="l00239"></a>00239     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00240"></a>00240 
+<a name="l00241"></a>00241     code=sinfo_utl_cube_test(recipe->parameters, recipe->frames) ;
+<a name="l00242"></a>00242     <span class="keywordflow">if</span> (!cpl_errorstate_is_equal(initial_errorstate)) {                      
+<a name="l00243"></a>00243         <span class="comment">/* Dump the error history since recipe execution start.                </span>
+<a name="l00244"></a>00244 <span class="comment">           At this point the recipe cannot recover from the error */</span>           
+<a name="l00245"></a>00245         cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);              
+<a name="l00246"></a>00246     } 
+<a name="l00247"></a>00247 
+<a name="l00248"></a>00248     <span class="keywordflow">return</span> code;
+<a name="l00249"></a>00249 }
+<a name="l00250"></a>00250 
+<a name="l00251"></a>00251 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00257"></a>00257 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00258"></a>00258 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_cube_test_destroy(cpl_plugin * plugin)
+<a name="l00259"></a>00259 {
+<a name="l00260"></a>00260     cpl_recipe  *   recipe ;
+<a name="l00261"></a>00261     
+<a name="l00262"></a>00262     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00263"></a>00263     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00264"></a>00264         recipe = (cpl_recipe *)plugin ;
+<a name="l00265"></a>00265     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00266"></a>00266 
+<a name="l00267"></a>00267     cpl_parameterlist_delete(recipe->parameters) ; 
+<a name="l00268"></a>00268     <span class="keywordflow">return</span> 0 ;
+<a name="l00269"></a>00269 }
+<a name="l00270"></a>00270 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__utl__eff_8c_source.html b/html/sinfo__utl__eff_8c_source.html
new file mode 100644
index 0000000..4363504
--- /dev/null
+++ b/html/sinfo__utl__eff_8c_source.html
@@ -0,0 +1,279 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_utl_eff.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_utl_eff.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_utl_eff.c,v 1.7 2010/02/18 19:14:41 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the SINFONI Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2010/02/18 19:14:41 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.7 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Log: sinfo_utl_eff.c,v $</span>
+<a name="l00026"></a>00026 <span class="comment"> * Revision 1.7  2010/02/18 19:14:41  amodigli</span>
+<a name="l00027"></a>00027 <span class="comment"> * some bug fixes</span>
+<a name="l00028"></a>00028 <span class="comment"> *</span>
+<a name="l00029"></a>00029 <span class="comment"> * Revision 1.6  2010/02/08 07:14:34  amodigli</span>
+<a name="l00030"></a>00030 <span class="comment"> * changed sinfo_utl_efficiency API</span>
+<a name="l00031"></a>00031 <span class="comment"> *</span>
+<a name="l00032"></a>00032 <span class="comment"> * Revision 1.5  2009/12/15 15:07:32  kmirny</span>
+<a name="l00033"></a>00033 <span class="comment"> * efficiency update</span>
+<a name="l00034"></a>00034 <span class="comment"> *</span>
+<a name="l00035"></a>00035 <span class="comment"> * Revision 1.4  2009/07/27 12:37:43  amodigli</span>
+<a name="l00036"></a>00036 <span class="comment"> * removed parlist from sinfo_utl_efficiency() API as not used</span>
+<a name="l00037"></a>00037 <span class="comment"> *</span>
+<a name="l00038"></a>00038 <span class="comment"> * Revision 1.3  2009/07/14 14:45:03  kmirny</span>
+<a name="l00039"></a>00039 <span class="comment"> * new recipe parameters</span>
+<a name="l00040"></a>00040 <span class="comment"> *</span>
+<a name="l00041"></a>00041 <span class="comment"> * Revision 1.2  2009/06/12 14:20:20  kmirny</span>
+<a name="l00042"></a>00042 <span class="comment"> * updating SINFONI efficiency calculation</span>
+<a name="l00043"></a>00043 <span class="comment"> *</span>
+<a name="l00044"></a>00044 <span class="comment"> * Revision 1.1  2009/06/10 14:57:14  kmirny</span>
+<a name="l00045"></a>00045 <span class="comment"> * sinfoni efficiency utility recipe</span>
+<a name="l00046"></a>00046 <span class="comment"> *</span>
+<a name="l00047"></a>00047 <span class="comment"> */</span>
+<a name="l00048"></a>00048 
+<a name="l00049"></a>00049 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00050"></a>00050 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>
+<a name="l00051"></a>00051 <span class="preprocessor">#endif</span>
+<a name="l00052"></a>00052 <span class="preprocessor"></span>
+<a name="l00053"></a>00053 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00054"></a>00054 <span class="comment">                                Includes</span>
+<a name="l00055"></a>00055 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00056"></a>00056 <span class="preprocessor">#include <string.h></span>
+<a name="l00057"></a>00057 
+<a name="l00058"></a>00058 <span class="comment">/* cpl */</span>
+<a name="l00059"></a>00059 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00060"></a>00060 
+<a name="l00061"></a>00061 <span class="comment">/* irplib */</span>
+<a name="l00062"></a>00062 <span class="preprocessor">#include <irplib_utils.h></span>
+<a name="l00063"></a>00063 
+<a name="l00064"></a>00064 <span class="preprocessor">#include <sinfo_tpl_utils.h></span>
+<a name="l00065"></a>00065 <span class="preprocessor">#include <sinfo_pfits.h></span>
+<a name="l00066"></a>00066 <span class="preprocessor">#include <sinfo_tpl_dfs.h></span>
+<a name="l00067"></a>00067 <span class="preprocessor">#include <sinfo_key_names.h></span>
+<a name="l00068"></a>00068 <span class="preprocessor">#include <sinfo_pro_types.h></span>
+<a name="l00069"></a>00069 <span class="preprocessor">#include <sinfo_ref_types.h></span>
+<a name="l00070"></a>00070 <span class="preprocessor">#include <sinfo_functions.h></span>
+<a name="l00071"></a>00071 <span class="preprocessor">#include <sinfo_msg.h></span>
+<a name="l00072"></a>00072 <span class="preprocessor">#include <sinfo_error.h></span>
+<a name="l00073"></a>00073 <span class="preprocessor">#include <sinfo_utils_wrappers.h></span>
+<a name="l00074"></a>00074 <span class="preprocessor">#include <sinfo_utl_efficiency.h></span>
+<a name="l00075"></a>00075 
+<a name="l00076"></a>00076 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00077"></a>00077 <span class="comment">                            Functions prototypes</span>
+<a name="l00078"></a>00078 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00079"></a>00079 
+<a name="l00080"></a>00080 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_eff_create(cpl_plugin *) ;
+<a name="l00081"></a>00081 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_eff_exec(cpl_plugin *) ;
+<a name="l00082"></a>00082 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_eff_destroy(cpl_plugin *) ;
+<a name="l00083"></a>00083 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_eff(cpl_parameterlist *, cpl_frameset *) ;
+<a name="l00084"></a>00084 
+<a name="l00085"></a>00085 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00086"></a>00086 <span class="comment">                            Static variables</span>
+<a name="l00087"></a>00087 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00088"></a>00088 
+<a name="l00089"></a>00089 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_utl_eff_description[] =
+<a name="l00090"></a>00090 <span class="stringliteral">"This recipe calculate a efficiency\n"</span>
+<a name="l00091"></a>00091 <span class="stringliteral">"esorex --params sinfo_utl_eff\n"</span>
+<a name="l00092"></a>00092 <span class="stringliteral">"esorex --help sinfo_utl_eff\n"</span>
+<a name="l00093"></a>00093 <span class="stringliteral">"\n"</span>;
+<a name="l00094"></a>00094 
+<a name="l00095"></a>00095 
+<a name="l00096"></a>00096 
+<a name="l00097"></a>00097 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00098"></a>00098 <span class="comment">                                Functions code</span>
+<a name="l00099"></a>00099 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00100"></a>00100 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00104"></a>00104 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00105"></a>00105 
+<a name="l00107"></a>00107 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00115"></a>00115 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00116"></a><a class="code" href="group__sinfo__utl__eff.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693">00116</a> <span class="keywordtype">int</span> <a class="code" href="group__sinfo__rec__detlin.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693" title="Build the list of available plugins, for this module.">cpl_plugin_get_info</a>(cpl_pluginlist * list)
+<a name="l00117"></a>00117 {
+<a name="l00118"></a>00118     cpl_recipe  *   recipe = cpl_calloc(1, <span class="keyword">sizeof</span> *recipe ) ;
+<a name="l00119"></a>00119     cpl_plugin  *   plugin = &recipe->interface ;
+<a name="l00120"></a>00120 
+<a name="l00121"></a>00121     cpl_plugin_init(plugin,
+<a name="l00122"></a>00122                     CPL_PLUGIN_API,
+<a name="l00123"></a>00123                     SINFONI_BINARY_VERSION,
+<a name="l00124"></a>00124                     CPL_PLUGIN_TYPE_RECIPE,
+<a name="l00125"></a>00125                     <span class="stringliteral">"sinfo_utl_eff"</span>,
+<a name="l00126"></a>00126                     <span class="stringliteral">"Produce a table with efficiency"</span>,
+<a name="l00127"></a>00127                     sinfo_utl_eff_description,
+<a name="l00128"></a>00128                     <span class="stringliteral">"Konstantin Mirny"</span>,
+<a name="l00129"></a>00129                     <span class="stringliteral">"kmirny at eso.org"</span>,
+<a name="l00130"></a>00130                     sinfo_get_license(),
+<a name="l00131"></a>00131                     sinfo_utl_eff_create,
+<a name="l00132"></a>00132                     sinfo_utl_eff_exec,
+<a name="l00133"></a>00133                     sinfo_utl_eff_destroy) ;
+<a name="l00134"></a>00134 
+<a name="l00135"></a>00135     cpl_pluginlist_append(list, plugin) ;
+<a name="l00136"></a>00136 
+<a name="l00137"></a>00137     <span class="keywordflow">return</span> 0;
+<a name="l00138"></a>00138 }
+<a name="l00139"></a>00139 
+<a name="l00140"></a>00140 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00149"></a>00149 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00150"></a>00150 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_eff_create(cpl_plugin * plugin)
+<a name="l00151"></a>00151 {
+<a name="l00152"></a>00152     cpl_recipe      * recipe ;
+<a name="l00153"></a>00153 
+<a name="l00154"></a>00154     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00155"></a>00155     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
+<a name="l00156"></a>00156         recipe = (cpl_recipe *)plugin ;
+<a name="l00157"></a>00157     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00158"></a>00158     cpl_error_reset();
+<a name="l00159"></a>00159     <a class="code" href="group__irplib__utils.html#gaf9d392144014e2363054bc3f83c8e47e" title="Reset IRPLIB state.">irplib_reset</a>();
+<a name="l00160"></a>00160 
+<a name="l00161"></a>00161     <span class="comment">/* Create the parameters list in the cpl_recipe object */</span>
+<a name="l00162"></a>00162     recipe->parameters = cpl_parameterlist_new() ;
+<a name="l00163"></a>00163 
+<a name="l00164"></a>00164     <span class="comment">/* Fill the parameters list */</span>
+<a name="l00165"></a>00165 
+<a name="l00166"></a>00166 
+<a name="l00167"></a>00167         <span class="comment">/* Return */</span>
+<a name="l00168"></a>00168     <span class="keywordflow">return</span> 0;
+<a name="l00169"></a>00169 }
+<a name="l00170"></a>00170 
+<a name="l00171"></a>00171 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00177"></a>00177 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00178"></a>00178 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_eff_exec(cpl_plugin * plugin)
+<a name="l00179"></a>00179 {
+<a name="l00180"></a>00180     cpl_recipe  *   recipe ;
+<a name="l00181"></a>00181      <span class="keywordtype">int</span> code=0;
+<a name="l00182"></a>00182      cpl_errorstate initial_errorstate = cpl_errorstate_get();
+<a name="l00183"></a>00183 
+<a name="l00184"></a>00184     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00185"></a>00185     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
+<a name="l00186"></a>00186         recipe = (cpl_recipe *)plugin ;
+<a name="l00187"></a>00187     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00188"></a>00188     cpl_error_reset();
+<a name="l00189"></a>00189     <a class="code" href="group__irplib__utils.html#gaf9d392144014e2363054bc3f83c8e47e" title="Reset IRPLIB state.">irplib_reset</a>();
+<a name="l00190"></a>00190     code = sinfo_utl_eff(recipe->parameters, recipe->frames) ;
+<a name="l00191"></a>00191 
+<a name="l00192"></a>00192 
+<a name="l00193"></a>00193     <span class="keywordflow">if</span> (!cpl_errorstate_is_equal(initial_errorstate)) {
+<a name="l00194"></a>00194         <span class="comment">/* Dump the error history since recipe execution start.</span>
+<a name="l00195"></a>00195 <span class="comment">           At this point the recipe cannot recover from the error */</span>
+<a name="l00196"></a>00196         cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
+<a name="l00197"></a>00197     }
+<a name="l00198"></a>00198 
+<a name="l00199"></a>00199     <span class="keywordflow">return</span> code ;
+<a name="l00200"></a>00200 }
+<a name="l00201"></a>00201 
+<a name="l00202"></a>00202 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00208"></a>00208 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00209"></a>00209 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_eff_destroy(cpl_plugin * plugin)
+<a name="l00210"></a>00210 {
+<a name="l00211"></a>00211     cpl_recipe  *   recipe ;
+<a name="l00212"></a>00212 
+<a name="l00213"></a>00213     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00214"></a>00214     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
+<a name="l00215"></a>00215         recipe = (cpl_recipe *)plugin ;
+<a name="l00216"></a>00216     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00217"></a>00217 
+<a name="l00218"></a>00218     cpl_parameterlist_delete(recipe->parameters) ;
+<a name="l00219"></a>00219     <span class="keywordflow">return</span> 0 ;
+<a name="l00220"></a>00220 }
+<a name="l00221"></a>00221 
+<a name="l00222"></a>00222 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00229"></a>00229 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00230"></a>00230 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00231"></a>00231 sinfo_utl_eff( cpl_parameterlist   *   parlist,
+<a name="l00232"></a>00232                cpl_frameset        *   framelist)
+<a name="l00233"></a>00233 {
+<a name="l00234"></a>00234 
+<a name="l00235"></a>00235    <span class="keyword">const</span> <span class="keywordtype">char</span>          *   name_o = NULL ;
+<a name="l00236"></a>00236 
+<a name="l00237"></a>00237    cpl_frame*               product_frame = 0;
+<a name="l00238"></a>00238    cpl_propertylist    *   plist = NULL ;
+<a name="l00239"></a>00239    <span class="keywordtype">int</span> pos = 0;
+<a name="l00240"></a>00240    <span class="keywordtype">int</span> npos = 0;
+<a name="l00241"></a>00241    cpl_frame* frm_sci=NULL;
+<a name="l00242"></a>00242    cpl_frame* frm_atm_ext=NULL;
+<a name="l00243"></a>00243    cpl_frame* frm_std_cat=NULL;
+<a name="l00244"></a>00244    cpl_table* eff_tbl=NULL;
+<a name="l00245"></a>00245 
+<a name="l00246"></a>00246    sinfo_msg(<span class="stringliteral">"Welcome to SINFONI Pipeline release %d.%d.%d"</span>,
+<a name="l00247"></a>00247              SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
+<a name="l00248"></a>00248    ck0(sinfo_dfs_set_groups(framelist),<span class="stringliteral">"Cannot indentify RAW and CALIB frames"</span>);
+<a name="l00249"></a>00249 
+<a name="l00250"></a>00250    <span class="comment">/* HOW TO GET THE VALUE OF A FITS KEYWORD */</span>
+<a name="l00251"></a>00251    check(plist=cpl_propertylist_new(),<span class="stringliteral">"Cannot create a Property List"</span>);
+<a name="l00252"></a>00252 
+<a name="l00253"></a>00253 
+<a name="l00254"></a>00254    <span class="comment">/* Now performing the data reduction */</span>
+<a name="l00255"></a>00255    name_o = <span class="stringliteral">"eff_res.fits"</span> ;
+<a name="l00256"></a>00256 
+<a name="l00257"></a>00257    check_nomsg(frm_sci=cpl_frameset_find (framelist, PRO_STD_STAR_SPECTRA));
+<a name="l00258"></a>00258    check_nomsg(frm_std_cat=cpl_frameset_find (framelist, FLUX_STD_CATALOG));
+<a name="l00259"></a>00259    check_nomsg(frm_atm_ext=cpl_frameset_find (framelist, EXTCOEFF_TABLE));
+<a name="l00260"></a>00260    sinfo_msg(<span class="stringliteral">"frm_sci=%p frm_std=%p frm_atm_ext=%p"</span>,frm_sci,frm_std_cat,frm_atm_ext);
+<a name="l00261"></a>00261    check_nomsg(eff_tbl=sinfo_efficiency_compute(frm_sci,frm_std_cat,frm_atm_ext));
+<a name="l00262"></a>00262    npos = cpl_frameset_get_size(framelist);
+<a name="l00263"></a>00263    <span class="keywordflow">for</span> (pos = 0; pos < npos; pos++)
+<a name="l00264"></a>00264    {
+<a name="l00265"></a>00265       cpl_frame* pframe = cpl_frameset_get_frame(framelist, pos);
+<a name="l00266"></a>00266       cpl_frame_group group = cpl_frame_get_group(pframe);
+<a name="l00267"></a>00267       <span class="keywordflow">if</span> (CPL_FRAME_GROUP_PRODUCT == group)
+<a name="l00268"></a>00268       {
+<a name="l00269"></a>00269          check_nomsg(cpl_frame_set_group (pframe, CPL_FRAME_GROUP_CALIB));
+<a name="l00270"></a>00270       }
+<a name="l00271"></a>00271    }
+<a name="l00272"></a>00272    <span class="comment">/* Create product frame */</span>
+<a name="l00273"></a>00273    check_nomsg(product_frame = cpl_frame_new());
+<a name="l00274"></a>00274    check_nomsg(cpl_frame_set_filename(product_frame, name_o)) ;
+<a name="l00275"></a>00275    check_nomsg(cpl_frame_set_tag(product_frame,<span class="stringliteral">"sinfo_efficiency"</span> )) ;
+<a name="l00276"></a>00276    check_nomsg(cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_TABLE)) ;
+<a name="l00277"></a>00277    check_nomsg(cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT)) ;
+<a name="l00278"></a>00278    check(cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL),
+<a name="l00279"></a>00279          <span class="stringliteral">"Error while initialising the product frame"</span>) ;
+<a name="l00280"></a>00280 
+<a name="l00281"></a>00281    <span class="comment">/* Add DataFlow keywords */</span>
+<a name="l00282"></a>00282    check_nomsg(cpl_propertylist_erase_regexp(plist, <span class="stringliteral">"^ESO PRO CATG"</span>,0));
+<a name="l00283"></a>00283    <span class="comment">/* Log the saved file in the input frameset */</span>
+<a name="l00284"></a>00284    check_nomsg(cpl_frameset_insert(framelist, product_frame)) ;
+<a name="l00285"></a>00285    check(cpl_dfs_setup_product_header(plist,
+<a name="l00286"></a>00286                                       product_frame,
+<a name="l00287"></a>00287                                       framelist,
+<a name="l00288"></a>00288                                       parlist,
+<a name="l00289"></a>00289                                       <span class="stringliteral">"sinfo_utl_eff"</span>,
+<a name="l00290"></a>00290                                       <span class="stringliteral">"SINFONI"</span>,
+<a name="l00291"></a>00291                                       KEY_VALUE_HPRO_DID,NULL),
+<a name="l00292"></a>00292          <span class="stringliteral">"Problem in the product DFS-compliance"</span>) ;
+<a name="l00293"></a>00293    sinfo_free_propertylist(&plist) ;
+<a name="l00294"></a>00294 
+<a name="l00295"></a>00295   cleanup:
+<a name="l00296"></a>00296    sinfo_free_propertylist(&plist) ;
+<a name="l00297"></a>00297    <span class="keywordflow">return</span> (cpl_error_get_code()) ? -1 : 0;
+<a name="l00298"></a>00298 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__utl__efficiency_8c_source.html b/html/sinfo__utl__efficiency_8c_source.html
new file mode 100644
index 0000000..8131941
--- /dev/null
+++ b/html/sinfo__utl__efficiency_8c_source.html
@@ -0,0 +1,675 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_utl_efficiency.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_utl_efficiency.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004-2009 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*</span>
+<a name="l00020"></a>00020 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Date: 2012/03/03 10:17:31 $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Revision: 1.17 $</span>
+<a name="l00023"></a>00023 <span class="comment"> *</span>
+<a name="l00024"></a>00024 <span class="comment"> */</span>
+<a name="l00025"></a>00025 
+<a name="l00026"></a>00026 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00027"></a>00027 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>
+<a name="l00028"></a>00028 <span class="preprocessor">#endif</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#include <string.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#include <math.h></span>
+<a name="l00031"></a>00031 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00032"></a>00032 <span class="comment">/* irplib */</span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include <irplib_utils.h></span>
+<a name="l00034"></a>00034 
+<a name="l00035"></a>00035 <span class="preprocessor">#include <sinfo_pfits.h></span>
+<a name="l00036"></a>00036 <span class="preprocessor">#include <sinfo_msg.h></span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include <sinfo_dfs.h></span>
+<a name="l00038"></a>00038 <span class="preprocessor">#include <sinfo_error.h></span>
+<a name="l00039"></a>00039 <span class="preprocessor">#include <sinfo_utils_wrappers.h></span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include "sinfo_utl_efficiency.h"</span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include <sinfo_star_index.h></span>
+<a name="l00042"></a>00042 
+<a name="l00043"></a>00043 <span class="preprocessor">#define PRO_STD_STAR_SPECTRA "STD_STAR_SPECTRA"</span>
+<a name="l00044"></a>00044 <span class="preprocessor"></span><span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> COL_NAME_WAVELENGTH[] = <span class="stringliteral">"WAVELENGTH"</span>;
+<a name="l00045"></a>00045 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> COL_NAME_WAVELENGTH_C[] = <span class="stringliteral">"WAVELENGTH"</span>;
+<a name="l00046"></a>00046 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> COL_NAME_LAMBDA[]     = <span class="stringliteral">"LAMBDA"</span>;
+<a name="l00047"></a>00047 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> COL_NAME_LA_SILLA[]   = <span class="stringliteral">"LA_SILLA"</span>;
+<a name="l00048"></a>00048 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> COL_NAME_REF[]        = <span class="stringliteral">"REF"</span>;
+<a name="l00049"></a>00049 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> COL_NAME_COR[]        = <span class="stringliteral">"COR"</span>;
+<a name="l00050"></a>00050 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> COL_NAME_SRC_COR[]    = <span class="stringliteral">"SRC_COR"</span>;
+<a name="l00051"></a>00051 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> COL_NAME_COUNTS_BKG[] = <span class="stringliteral">"INT_OBJ"</span>;<span class="comment">//"counts_tot";</span>
+<a name="l00052"></a>00052 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> COL_NAME_FLUX[]       = <span class="stringliteral">"FLUX"</span>;
+<a name="l00053"></a>00053 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> COL_NAME_EPHOT[]      = <span class="stringliteral">"EPHOT"</span>;
+<a name="l00054"></a>00054 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> COL_NAME_EXT[]        = <span class="stringliteral">"EXT"</span>;
+<a name="l00055"></a>00055 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> COL_NAME_SRC_EFF[]    = <span class="stringliteral">"EFF"</span>;
+<a name="l00056"></a>00056 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> PAR_NAME_DIT[]        = <span class="stringliteral">"ESO DET DIT"</span>;
+<a name="l00057"></a>00057 
+<a name="l00058"></a>00058 <span class="keyword">static</span> <span class="keywordtype">char</span> FRM_RAW_IMA_SLIT[]  = PRO_STD_STAR_SPECTRA;
+<a name="l00059"></a>00059 <span class="keyword">static</span> <span class="keywordtype">char</span> FRM_FLUX_STD_TAB[]  = FLUX_STD_TABLE;
+<a name="l00060"></a>00060 <span class="keyword">static</span> <span class="keywordtype">char</span> FRM_FLUX_STD_CAT[]  = FLUX_STD_CATALOG;
+<a name="l00061"></a>00061 <span class="keyword">static</span> <span class="keywordtype">char</span> FRM_EXTCOEFF_TAB[]  = EXTCOEFF_TABLE;
+<a name="l00062"></a>00062 
+<a name="l00063"></a>00063 <span class="keyword">static</span> <span class="keywordtype">int</span> 
+<a name="l00064"></a>00064 sinfo_column_to_double(cpl_table* ptable, <span class="keyword">const</span> <span class="keywordtype">char</span>* column);
+<a name="l00065"></a>00065 
+<a name="l00066"></a>00066 <span class="keyword">static</span> <span class="keywordtype">double</span> 
+<a name="l00067"></a>00067 sinfo_table_interpolate(cpl_table* tbl,
+<a name="l00068"></a>00068           <span class="keywordtype">double</span> wav,
+<a name="l00069"></a>00069           <span class="keyword">const</span> <span class="keywordtype">char</span>* colx,
+<a name="l00070"></a>00070           <span class="keyword">const</span> <span class="keywordtype">char</span>* coly);
+<a name="l00071"></a>00071 <span class="keyword">static</span> <span class="keywordtype">double</span>* 
+<a name="l00072"></a>00072 sinfo_create_column_double(cpl_table* tbl, <span class="keyword">const</span> <span class="keywordtype">char</span>* col_name, <span class="keywordtype">int</span> nrow);
+<a name="l00073"></a>00073 
+<a name="l00074"></a>00074 
+<a name="l00075"></a>00075 
+<a name="l00076"></a>00076 cpl_error_code
+<a name="l00077"></a>00077 sinfo_get_std_obs_values(cpl_propertylist* plist,
+<a name="l00078"></a>00078                        <span class="keywordtype">double</span>* exptime,
+<a name="l00079"></a>00079                        <span class="keywordtype">double</span>* airmass,
+<a name="l00080"></a>00080                        <span class="keywordtype">double</span>* dRA,
+<a name="l00081"></a>00081                        <span class="keywordtype">double</span>* dDEC);
+<a name="l00082"></a>00082 
+<a name="l00083"></a>00083 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00084"></a>00084 
+<a name="l00086"></a>00086 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00097"></a>00097 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00098"></a>00098 
+<a name="l00099"></a>00099 <span class="keywordtype">void</span> 
+<a name="l00100"></a>00100 sinfo_load_ref_table(cpl_frameset* frames, 
+<a name="l00101"></a>00101                    <span class="keywordtype">double</span> dRA, 
+<a name="l00102"></a>00102                    <span class="keywordtype">double</span> dDEC, 
+<a name="l00103"></a>00103                    <span class="keywordtype">double</span> EPSILON, 
+<a name="l00104"></a>00104                    cpl_table** pptable)
+<a name="l00105"></a>00105 {
+<a name="l00106"></a>00106   <span class="keyword">const</span> <span class="keywordtype">char</span>* name = NULL;
+<a name="l00107"></a>00107   cpl_frame* frm_ref = NULL;
+<a name="l00108"></a>00108 
+<a name="l00109"></a>00109   <span class="comment">/* REF STD frame */</span>
+<a name="l00110"></a>00110   frm_ref=cpl_frameset_find(frames,FRM_FLUX_STD_TAB);
+<a name="l00111"></a>00111   <span class="keywordflow">if</span> (!frm_ref)
+<a name="l00112"></a>00112     {
+<a name="l00113"></a>00113       sinfo_msg(<span class="stringliteral">"REF frame is not found, trying to get REF from the catalog"</span>);
+<a name="l00114"></a>00114      <span class="comment">/* REF STD catalog frame */</span>
+<a name="l00115"></a>00115       <span class="comment">// get from catalog</span>
+<a name="l00116"></a>00116       check_nomsg(frm_ref=cpl_frameset_find(frames,FRM_FLUX_STD_CAT));
+<a name="l00117"></a>00117       <span class="keywordflow">if</span> (frm_ref)
+<a name="l00118"></a>00118     {
+<a name="l00119"></a>00119       check_nomsg(name=cpl_frame_get_filename(frm_ref));
+<a name="l00120"></a>00120       <span class="keywordflow">if</span> (name)
+<a name="l00121"></a>00121         {
+<a name="l00122"></a>00122           star_index* pstarindex = star_index_load(name);
+<a name="l00123"></a>00123           <span class="keywordflow">if</span> (pstarindex)
+<a name="l00124"></a>00124         {
+<a name="l00125"></a>00125           <span class="keyword">const</span> <span class="keywordtype">char</span>* star_name = 0;
+<a name="l00126"></a>00126           sinfo_msg(<span class="stringliteral">"The catalog is loaded, looking for star in RA[%f] DEC[%f] tolerance[%f]"</span>, dRA, dDEC, EPSILON);
+<a name="l00127"></a>00127           *pptable = star_index_get(pstarindex, dRA, dDEC, EPSILON, EPSILON, &star_name);
+<a name="l00128"></a>00128           <span class="keywordflow">if</span> (*pptable && star_name)
+<a name="l00129"></a>00129             {
+<a name="l00130"></a>00130               sinfo_msg(<span class="stringliteral">"REF table is found in the catalog, star name is [%s]"</span>, star_name);
+<a name="l00131"></a>00131             }
+<a name="l00132"></a>00132           <span class="keywordflow">else</span>
+<a name="l00133"></a>00133             {
+<a name="l00134"></a>00134               sinfo_msg(<span class="stringliteral">"ERROR - REF table could not be found in the catalog"</span>);
+<a name="l00135"></a>00135             }
+<a name="l00136"></a>00136         }
+<a name="l00137"></a>00137           <span class="keywordflow">else</span>
+<a name="l00138"></a>00138         {
+<a name="l00139"></a>00139           sinfo_msg(<span class="stringliteral">"ERROR - could not load the catalog"</span>);
+<a name="l00140"></a>00140         }
+<a name="l00141"></a>00141         }
+<a name="l00142"></a>00142     }
+<a name="l00143"></a>00143     }
+<a name="l00144"></a>00144   <span class="keywordflow">else</span>
+<a name="l00145"></a>00145     {
+<a name="l00146"></a>00146       sinfo_msg(<span class="stringliteral">"REF frame is found"</span>);
+<a name="l00147"></a>00147       check_nomsg(name=cpl_frame_get_filename(frm_ref));
+<a name="l00148"></a>00148       check_nomsg(*pptable=cpl_table_load(name,1,0));
+<a name="l00149"></a>00149     }
+<a name="l00150"></a>00150   <span class="keywordflow">return</span>;
+<a name="l00151"></a>00151  cleanup:
+<a name="l00152"></a>00152   <span class="keywordflow">return</span>;
+<a name="l00153"></a>00153 }
+<a name="l00154"></a>00154 
+<a name="l00155"></a>00155 
+<a name="l00156"></a>00156 
+<a name="l00157"></a>00157 
+<a name="l00158"></a>00158 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00169"></a>00169 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00170"></a>00170 
+<a name="l00171"></a>00171 <span class="keyword">static</span> <span class="keywordtype">void</span> 
+<a name="l00172"></a>00172 sinfo_parse_catalog_std_stars(cpl_frame* cat, 
+<a name="l00173"></a>00173                 <span class="keywordtype">double</span> dRA, 
+<a name="l00174"></a>00174                 <span class="keywordtype">double</span> dDEC, 
+<a name="l00175"></a>00175                 <span class="keywordtype">double</span> EPSILON, 
+<a name="l00176"></a>00176                 cpl_table** pptable)
+<a name="l00177"></a>00177 {
+<a name="l00178"></a>00178   <span class="keyword">const</span> <span class="keywordtype">char</span>* name = NULL;
+<a name="l00179"></a>00179 
+<a name="l00180"></a>00180   <span class="keywordflow">if</span> (cat) {
+<a name="l00181"></a>00181     check_nomsg(name=cpl_frame_get_filename(cat));
+<a name="l00182"></a>00182     <span class="keywordflow">if</span> (name) {
+<a name="l00183"></a>00183       star_index* pstarindex = star_index_load(name);
+<a name="l00184"></a>00184       <span class="keywordflow">if</span> (pstarindex) {
+<a name="l00185"></a>00185     <span class="keyword">const</span> <span class="keywordtype">char</span>* star_name = 0;
+<a name="l00186"></a>00186     sinfo_msg(<span class="stringliteral">"The catalog is loaded, looking for star in RA[%f] DEC[%f] tolerance[%f]"</span>, dRA, dDEC, EPSILON);
+<a name="l00187"></a>00187     *pptable = star_index_get(pstarindex, dRA, dDEC, EPSILON, EPSILON, &star_name);
+<a name="l00188"></a>00188     <span class="keywordflow">if</span> (*pptable && star_name) {
+<a name="l00189"></a>00189       sinfo_msg(<span class="stringliteral">"REF table is found in the catalog, star name is [%s]"</span>, star_name);
+<a name="l00190"></a>00190     }
+<a name="l00191"></a>00191     <span class="keywordflow">else</span> {
+<a name="l00192"></a>00192       sinfo_msg(<span class="stringliteral">"ERROR - REF table could not be found in the catalog"</span>);
+<a name="l00193"></a>00193     }
+<a name="l00194"></a>00194       }
+<a name="l00195"></a>00195       <span class="keywordflow">else</span> {
+<a name="l00196"></a>00196     sinfo_msg(<span class="stringliteral">"ERROR - could not load the catalog"</span>);
+<a name="l00197"></a>00197       }
+<a name="l00198"></a>00198 
+<a name="l00199"></a>00199     }
+<a name="l00200"></a>00200   }
+<a name="l00201"></a>00201 
+<a name="l00202"></a>00202  cleanup:
+<a name="l00203"></a>00203   <span class="keywordflow">return</span>;
+<a name="l00204"></a>00204 }
+<a name="l00205"></a>00205 
+<a name="l00206"></a>00206 
+<a name="l00207"></a>00207 
+<a name="l00208"></a>00208 
+<a name="l00209"></a>00209 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00218"></a>00218 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00219"></a>00219 
+<a name="l00220"></a>00220 
+<a name="l00221"></a>00221 <span class="keywordtype">double</span>
+<a name="l00222"></a>00222 sinfo_data_interpolate(
+<a name="l00223"></a>00223              <span class="keywordtype">double</span> wav,
+<a name="l00224"></a>00224              <span class="keywordtype">int</span> nrow,
+<a name="l00225"></a>00225              <span class="keywordtype">double</span>* pw,
+<a name="l00226"></a>00226              <span class="keywordtype">double</span>* pe
+<a name="l00227"></a>00227              )
+<a name="l00228"></a>00228 {
+<a name="l00229"></a>00229   <span class="keywordtype">double</span> y = 0;
+<a name="l00230"></a>00230   <span class="keywordtype">double</span> w1=pw[0];
+<a name="l00231"></a>00231   <span class="keywordtype">double</span> w2=pw[nrow-1];
+<a name="l00232"></a>00232   <span class="keywordtype">double</span> y1_=pe[0]; <span class="comment">/*was changed from y1 to y1_ due a warning from compiler - shadowed variable*/</span>
+<a name="l00233"></a>00233   <span class="keywordtype">double</span> y2=pe[nrow-1];
+<a name="l00234"></a>00234   <span class="keywordflow">if</span>(wav < pw[0])
+<a name="l00235"></a>00235     {
+<a name="l00236"></a>00236       w1=pw[0];
+<a name="l00237"></a>00237       w2=pw[1];
+<a name="l00238"></a>00238       y1_=pe[0];
+<a name="l00239"></a>00239       y2=pe[1];
+<a name="l00240"></a>00240     }
+<a name="l00241"></a>00241   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (wav > pw[nrow - 1])
+<a name="l00242"></a>00242     {
+<a name="l00243"></a>00243       w1=pw[nrow - 2];
+<a name="l00244"></a>00244       w2=pw[nrow - 1];
+<a name="l00245"></a>00245       y1_=pe[nrow - 2];
+<a name="l00246"></a>00246       y2=pe[nrow - 1];
+<a name="l00247"></a>00247     }
+<a name="l00248"></a>00248   <span class="keywordflow">else</span>
+<a name="l00249"></a>00249     {
+<a name="l00250"></a>00250       <span class="keywordtype">int</span> l = 0;
+<a name="l00251"></a>00251       <span class="keywordtype">int</span> h = nrow - 1;
+<a name="l00252"></a>00252       <span class="keywordtype">int</span> curr_row = 0;
+<a name="l00253"></a>00253       curr_row = (h-l) / 2;
+<a name="l00254"></a>00254       <span class="keywordflow">while</span>( h-l >1 )
+<a name="l00255"></a>00255     {
+<a name="l00256"></a>00256       <span class="keywordflow">if</span>(wav < pw[curr_row])
+<a name="l00257"></a>00257         {
+<a name="l00258"></a>00258           h = curr_row;
+<a name="l00259"></a>00259         }
+<a name="l00260"></a>00260       <span class="keywordflow">else</span>
+<a name="l00261"></a>00261         {
+<a name="l00262"></a>00262           l = curr_row;
+<a name="l00263"></a>00263         }
+<a name="l00264"></a>00264       curr_row = (h-l) / 2 + l;
+<a name="l00265"></a>00265     }
+<a name="l00266"></a>00266       w1=pw[curr_row];
+<a name="l00267"></a>00267       w2=pw[curr_row + 1];
+<a name="l00268"></a>00268       y1_=pe[curr_row];
+<a name="l00269"></a>00269       y2=pe[curr_row + 1];
+<a name="l00270"></a>00270     }
+<a name="l00271"></a>00271   y=y1_+(y2-y1_)/(w2-w1)*(wav-w1);
+<a name="l00272"></a>00272   <span class="keywordflow">return</span> y;
+<a name="l00273"></a>00273 }
+<a name="l00274"></a>00274 <span class="keyword">static</span> <span class="keywordtype">double</span>
+<a name="l00275"></a>00275 sinfo_table_interpolate(cpl_table* tbl,
+<a name="l00276"></a>00276           <span class="keywordtype">double</span> wav,
+<a name="l00277"></a>00277           <span class="keyword">const</span> <span class="keywordtype">char</span>* colx,
+<a name="l00278"></a>00278           <span class="keyword">const</span> <span class="keywordtype">char</span>* coly)
+<a name="l00279"></a>00279 {
+<a name="l00280"></a>00280 
+<a name="l00281"></a>00281   <span class="keywordtype">double</span> y=0;
+<a name="l00282"></a>00282   <span class="keywordtype">double</span>* pe=NULL;
+<a name="l00283"></a>00283   <span class="keywordtype">double</span>* pw=NULL;
+<a name="l00284"></a>00284   <span class="keywordtype">int</span> nrow=0;
+<a name="l00285"></a>00285 
+<a name="l00286"></a>00286   check_nomsg(pw=cpl_table_get_data_double(tbl,colx));
+<a name="l00287"></a>00287   check_nomsg(pe=cpl_table_get_data_double(tbl,coly));
+<a name="l00288"></a>00288   check_nomsg(nrow=cpl_table_get_nrow(tbl));
+<a name="l00289"></a>00289 
+<a name="l00290"></a>00290   y = sinfo_data_interpolate(wav, nrow, pw, pe);
+<a name="l00291"></a>00291  cleanup:
+<a name="l00292"></a>00292   <span class="keywordflow">return</span> y;
+<a name="l00293"></a>00293 
+<a name="l00294"></a>00294 }
+<a name="l00295"></a>00295 
+<a name="l00296"></a>00296 <span class="keyword">static</span> <span class="keywordtype">double</span>* 
+<a name="l00297"></a>00297 sinfo_create_column_double(cpl_table* tbl, <span class="keyword">const</span> <span class="keywordtype">char</span>* col_name, <span class="keywordtype">int</span> nrow)
+<a name="l00298"></a>00298 {
+<a name="l00299"></a>00299   <span class="keywordtype">double</span>* retval = 0;
+<a name="l00300"></a>00300   check_nomsg(cpl_table_new_column(tbl, col_name, CPL_TYPE_DOUBLE));
+<a name="l00301"></a>00301   check_nomsg(cpl_table_fill_column_window_double(tbl, col_name, 0, nrow, -1));
+<a name="l00302"></a>00302   check_nomsg(retval = cpl_table_get_data_double(tbl,col_name));
+<a name="l00303"></a>00303   <span class="keywordflow">return</span> retval;
+<a name="l00304"></a>00304  cleanup:
+<a name="l00305"></a>00305   <span class="keywordflow">return</span> retval;
+<a name="l00306"></a>00306 }
+<a name="l00307"></a>00307 
+<a name="l00308"></a>00308 
+<a name="l00309"></a>00309 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00319"></a>00319 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00320"></a>00320 
+<a name="l00321"></a>00321 cpl_error_code
+<a name="l00322"></a>00322 sinfo_get_std_obs_values(cpl_propertylist* plist,
+<a name="l00323"></a>00323                        <span class="keywordtype">double</span>* exptime,
+<a name="l00324"></a>00324                        <span class="keywordtype">double</span>* airmass,
+<a name="l00325"></a>00325                        <span class="keywordtype">double</span>* dRA,
+<a name="l00326"></a>00326                        <span class="keywordtype">double</span>* dDEC)
+<a name="l00327"></a>00327 {
+<a name="l00328"></a>00328    <span class="keywordtype">double</span> airmass_start=0;
+<a name="l00329"></a>00329    <span class="keywordtype">double</span> airmass_end=0;
+<a name="l00330"></a>00330 
+<a name="l00331"></a>00331    check_nomsg(*exptime=sinfo_pfits_get_exp_time(plist));
+<a name="l00332"></a>00332    airmass_start=sinfo_pfits_get_airmass_start(plist);
+<a name="l00333"></a>00333    airmass_end=sinfo_pfits_get_airmass_end(plist);
+<a name="l00334"></a>00334    *dRA=sinfo_pfits_get_ra(plist);
+<a name="l00335"></a>00335    *dDEC=sinfo_pfits_get_dec(plist);
+<a name="l00336"></a>00336    *airmass=0.5*(airmass_start+airmass_end);
+<a name="l00337"></a>00337 
+<a name="l00338"></a>00338  cleanup:
+<a name="l00339"></a>00339    <span class="keywordflow">return</span> cpl_error_get_code();
+<a name="l00340"></a>00340 
+<a name="l00341"></a>00341 }
+<a name="l00342"></a>00342 
+<a name="l00343"></a>00343 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00360"></a>00360 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00361"></a>00361 
+<a name="l00362"></a>00362 cpl_table*
+<a name="l00363"></a>00363 sinfo_utl_efficiency(
+<a name="l00364"></a>00364              cpl_frameset * frames,
+<a name="l00365"></a>00365              <span class="keywordtype">double</span> dGain,
+<a name="l00366"></a>00366              <span class="keywordtype">double</span> dEpsilon,
+<a name="l00367"></a>00367              <span class="keywordtype">double</span> aimprim,
+<a name="l00368"></a>00368                      <span class="keyword">const</span> <span class="keywordtype">char</span>* col_name_atm_wave,
+<a name="l00369"></a>00369              <span class="keyword">const</span> <span class="keywordtype">char</span>* col_name_atm_abs,
+<a name="l00370"></a>00370                      <span class="keyword">const</span> <span class="keywordtype">char</span>* col_name_ref_wave,
+<a name="l00371"></a>00371                      <span class="keyword">const</span> <span class="keywordtype">char</span>* col_name_ref_flux,
+<a name="l00372"></a>00372                      <span class="keyword">const</span> <span class="keywordtype">char</span>* col_name_ref_bin,
+<a name="l00373"></a>00373                      <span class="keyword">const</span> <span class="keywordtype">char</span>* col_name_obj_wave,
+<a name="l00374"></a>00374                      <span class="keyword">const</span> <span class="keywordtype">char</span>* col_name_obj_flux
+<a name="l00375"></a>00375              )
+<a name="l00376"></a>00376 {
+<a name="l00377"></a>00377   cpl_frame* frm_sci = NULL;
+<a name="l00378"></a>00378   cpl_frame* frm_atmext = NULL;
+<a name="l00379"></a>00379   cpl_table* tbl_obj_spectrum = NULL; <span class="comment">// input table with spectrum</span>
+<a name="l00380"></a>00380   cpl_table* tbl_atmext = NULL;
+<a name="l00381"></a>00381   <span class="keywordtype">double</span> exptime = 600;
+<a name="l00382"></a>00382 
+<a name="l00383"></a>00383   cpl_propertylist* plist = NULL;
+<a name="l00384"></a>00384   cpl_table* tbl_ref = NULL;
+<a name="l00385"></a>00385   cpl_table* tbl_result=NULL;
+<a name="l00386"></a>00386 
+<a name="l00387"></a>00387   <span class="keyword">const</span> <span class="keywordtype">char</span>* name=NULL;
+<a name="l00388"></a>00388   <span class="keywordtype">double</span> dRA = 0;
+<a name="l00389"></a>00389   <span class="keywordtype">double</span> dDEC = 0;
+<a name="l00390"></a>00390 
+<a name="l00391"></a>00391   <span class="keywordtype">double</span> airmass=0;
+<a name="l00392"></a>00392   <span class="keyword">const</span> <span class="keywordtype">double</span> mk2AA=1E4; <span class="comment">/* mkm/AA */</span>
+<a name="l00393"></a>00393 
+<a name="l00394"></a>00394 
+<a name="l00395"></a>00395   <span class="comment">// read all input data and call the internal function</span>
+<a name="l00396"></a>00396   <span class="comment">// read the input tables</span>
+<a name="l00397"></a>00397   <span class="comment">// 1. observation</span>
+<a name="l00398"></a>00398   check_nomsg(frm_sci=cpl_frameset_find(frames, FRM_RAW_IMA_SLIT));
+<a name="l00399"></a>00399   check_nomsg(name=cpl_frame_get_filename(frm_sci));
+<a name="l00400"></a>00400   sinfo_msg(<span class="stringliteral">"name=%s"</span>,name);
+<a name="l00401"></a>00401   check_nomsg(tbl_obj_spectrum=cpl_table_load(name,1,0));
+<a name="l00402"></a>00402   check_nomsg(plist=cpl_propertylist_load(name,0));
+<a name="l00403"></a>00403 
+<a name="l00404"></a>00404   sinfo_get_std_obs_values(plist,&exptime,&airmass,&dRA,&dDEC);
+<a name="l00405"></a>00405 
+<a name="l00406"></a>00406   <span class="comment">// 2. reference table</span>
+<a name="l00407"></a>00407   sinfo_load_ref_table(frames, dRA, dDEC, dEpsilon, &tbl_ref);
+<a name="l00408"></a>00408   <span class="keywordflow">if</span> (tbl_ref)
+<a name="l00409"></a>00409     {
+<a name="l00410"></a>00410       <span class="comment">// 3. atmext</span>
+<a name="l00411"></a>00411       check_nomsg(frm_atmext=cpl_frameset_find(frames,FRM_EXTCOEFF_TAB));
+<a name="l00412"></a>00412       check_nomsg(name=cpl_frame_get_filename(frm_atmext));
+<a name="l00413"></a>00413       check_nomsg(tbl_atmext=cpl_table_load(name,1,0));
+<a name="l00414"></a>00414 
+<a name="l00415"></a>00415       tbl_result = sinfo_utl_efficiency_internal(
+<a name="l00416"></a>00416                          tbl_obj_spectrum,
+<a name="l00417"></a>00417                          tbl_atmext,
+<a name="l00418"></a>00418                          tbl_ref,
+<a name="l00419"></a>00419                          exptime,
+<a name="l00420"></a>00420                          airmass,
+<a name="l00421"></a>00421                          aimprim,
+<a name="l00422"></a>00422                          dGain,
+<a name="l00423"></a>00423                                                  1,
+<a name="l00424"></a>00424                                                  mk2AA,<span class="comment">//valid only for SINFONI</span>
+<a name="l00425"></a>00425                                                  col_name_atm_wave,
+<a name="l00426"></a>00426                                                  col_name_atm_abs,
+<a name="l00427"></a>00427                                                  col_name_ref_wave,
+<a name="l00428"></a>00428                                                  col_name_ref_flux,
+<a name="l00429"></a>00429                                                  col_name_ref_bin,
+<a name="l00430"></a>00430                                                  col_name_obj_wave,
+<a name="l00431"></a>00431                                                  col_name_obj_flux
+<a name="l00432"></a>00432          );
+<a name="l00433"></a>00433      }
+<a name="l00434"></a>00434 
+<a name="l00435"></a>00435  cleanup:
+<a name="l00436"></a>00436   sinfo_free_propertylist(&plist);
+<a name="l00437"></a>00437   sinfo_free_table(&tbl_atmext);
+<a name="l00438"></a>00438   sinfo_free_table(&tbl_obj_spectrum);
+<a name="l00439"></a>00439   sinfo_free_table(&tbl_ref);
+<a name="l00440"></a>00440   <span class="keywordflow">return</span> tbl_result;
+<a name="l00441"></a>00441 }
+<a name="l00442"></a>00442 <span class="keyword">static</span> <span class="keywordtype">int</span> 
+<a name="l00443"></a>00443 sinfo_column_to_double(cpl_table* ptable, <span class="keyword">const</span> <span class="keywordtype">char</span>* column)
+<a name="l00444"></a>00444 {
+<a name="l00445"></a>00445   <span class="keyword">const</span> <span class="keywordtype">char</span>* TEMP = <span class="stringliteral">"_temp_"</span>;
+<a name="l00446"></a>00446   check_nomsg(cpl_table_duplicate_column(ptable, TEMP, ptable, column));
+<a name="l00447"></a>00447   check_nomsg(cpl_table_erase_column(ptable, column));
+<a name="l00448"></a>00448   check_nomsg(cpl_table_cast_column(ptable, TEMP, column, CPL_TYPE_DOUBLE));
+<a name="l00449"></a>00449   check_nomsg(cpl_table_erase_column(ptable, TEMP ));
+<a name="l00450"></a>00450   <span class="keywordflow">return</span> 0;
+<a name="l00451"></a>00451  cleanup:
+<a name="l00452"></a>00452   sinfo_msg(<span class="stringliteral">" error column to double [%s]"</span>, column);
+<a name="l00453"></a>00453   <span class="keywordflow">return</span> -1;
+<a name="l00454"></a>00454 }
+<a name="l00455"></a>00455 
+<a name="l00456"></a>00456 
+<a name="l00457"></a>00457 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00478"></a>00478 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00479"></a>00479 
+<a name="l00480"></a>00480 cpl_table* 
+<a name="l00481"></a>00481 sinfo_utl_efficiency_internal(
+<a name="l00482"></a>00482                   cpl_table* tbl_obj_spectrum,
+<a name="l00483"></a>00483                   cpl_table* tbl_atmext,
+<a name="l00484"></a>00484                   cpl_table* tbl_ref,
+<a name="l00485"></a>00485                   <span class="keywordtype">double</span> exptime,
+<a name="l00486"></a>00486                   <span class="keywordtype">double</span> airmass,
+<a name="l00487"></a>00487                   <span class="keywordtype">double</span> aimprim,
+<a name="l00488"></a>00488                   <span class="keywordtype">double</span> gain,
+<a name="l00489"></a>00489                   <span class="keywordtype">int</span>    biny,
+<a name="l00490"></a>00490                               <span class="keywordtype">double</span> src2ref_wave_sampling,
+<a name="l00491"></a>00491                               <span class="keyword">const</span> <span class="keywordtype">char</span>* col_name_atm_wave,
+<a name="l00492"></a>00492                               <span class="keyword">const</span> <span class="keywordtype">char</span>* col_name_atm_abs,
+<a name="l00493"></a>00493                               <span class="keyword">const</span> <span class="keywordtype">char</span>* col_name_ref_wave,
+<a name="l00494"></a>00494                               <span class="keyword">const</span> <span class="keywordtype">char</span>* col_name_ref_flux,
+<a name="l00495"></a>00495                               <span class="keyword">const</span> <span class="keywordtype">char</span>* col_name_ref_bin,
+<a name="l00496"></a>00496                               <span class="keyword">const</span> <span class="keywordtype">char</span>* col_name_obj_wave,
+<a name="l00497"></a>00497                               <span class="keyword">const</span> <span class="keywordtype">char</span>* col_name_obj_flux
+<a name="l00498"></a>00498                   )
+<a name="l00499"></a>00499 {
+<a name="l00500"></a>00500 
+<a name="l00501"></a>00501   <span class="keyword">const</span> <span class="keywordtype">double</span> TEL_AREA     = 51.2e4; <span class="comment">/* collecting area in cm2 */</span>
+<a name="l00502"></a>00502   <span class="keywordtype">double</span> cdelta1 = 0;
+<a name="l00503"></a>00503   <span class="keywordtype">int</span> i = 0;
+<a name="l00504"></a>00504   cpl_table* tbl_sel = NULL;
+<a name="l00505"></a>00505 
+<a name="l00506"></a>00506   <span class="comment">/* structure of the input table</span>
+<a name="l00507"></a>00507 <span class="comment">   * col            type    description</span>
+<a name="l00508"></a>00508 <span class="comment">   * wavelength double</span>
+<a name="l00509"></a>00509 <span class="comment">   * flux           double</span>
+<a name="l00510"></a>00510 <span class="comment">   * */</span>
+<a name="l00511"></a>00511   cpl_table* tbl_result = NULL; <span class="comment">// output table</span>
+<a name="l00512"></a>00512 
+<a name="l00513"></a>00513   <span class="comment">/*</span>
+<a name="l00514"></a>00514 <span class="comment">   * structure of the output table</span>
+<a name="l00515"></a>00515 <span class="comment">   * col            type    description</span>
+<a name="l00516"></a>00516 <span class="comment">   * wavelength double</span>
+<a name="l00517"></a>00517 <span class="comment">   * EFF            double  efficiency in range 0-1</span>
+<a name="l00518"></a>00518 <span class="comment">   * */</span>
+<a name="l00519"></a>00519 
+<a name="l00520"></a>00520   <span class="keywordtype">double</span>* pref = NULL;
+<a name="l00521"></a>00521   <span class="keywordtype">double</span>* pext = NULL;
+<a name="l00522"></a>00522   <span class="keywordtype">double</span>* pcor = NULL;
+<a name="l00523"></a>00523   <span class="keywordtype">double</span>* peph = NULL;
+<a name="l00524"></a>00524 
+<a name="l00525"></a>00525   <span class="keywordtype">double</span>* pw = NULL; <span class="comment">// wavelength of the input table</span>
+<a name="l00526"></a>00526   <span class="keywordtype">double</span>* pf = NULL; <span class="comment">// flux of the input table</span>
+<a name="l00527"></a>00527   <span class="keywordtype">int</span> nrow = 0;
+<a name="l00528"></a>00528   <span class="keywordtype">double</span> ref_bin_size=0;
+<a name="l00529"></a>00529 
+<a name="l00530"></a>00530   nrow = cpl_table_get_nrow(tbl_obj_spectrum);
+<a name="l00531"></a>00531   sinfo_msg(<span class="stringliteral">"Starting efficiency calculation: exptime[%f] airmass[%f] nrow[%d]"</span>, 
+<a name="l00532"></a>00532       exptime, airmass, nrow);
+<a name="l00533"></a>00533 
+<a name="l00534"></a>00534   <span class="comment">//cpl_table_dump(tbl_obj_spectrum,0,3,stdout);</span>
+<a name="l00535"></a>00535   <span class="comment">//sinfo_msg("col wave=%s col_flux=%s",col_name_obj_wave,col_name_obj_flux);</span>
+<a name="l00536"></a>00536 
+<a name="l00537"></a>00537   <span class="comment">/* convert to double */</span>
+<a name="l00538"></a>00538   sinfo_column_to_double(tbl_obj_spectrum,col_name_obj_wave);
+<a name="l00539"></a>00539   sinfo_column_to_double(tbl_obj_spectrum,col_name_obj_flux);
+<a name="l00540"></a>00540 
+<a name="l00541"></a>00541   check_nomsg(sinfo_column_to_double(tbl_atmext,col_name_atm_wave ));
+<a name="l00542"></a>00542   check_nomsg(sinfo_column_to_double(tbl_atmext,col_name_atm_abs ));
+<a name="l00543"></a>00543   check_nomsg(sinfo_column_to_double(tbl_ref,col_name_ref_wave ));
+<a name="l00544"></a>00544   check_nomsg(sinfo_column_to_double(tbl_ref,col_name_ref_flux ));
+<a name="l00545"></a>00545   check_nomsg(sinfo_column_to_double(tbl_ref,col_name_ref_bin ));
+<a name="l00546"></a>00546 
+<a name="l00547"></a>00547   <span class="comment">/* get bin size of ref STD star spectrum */</span>
+<a name="l00548"></a>00548   ref_bin_size=cpl_table_get_double(tbl_ref,col_name_ref_bin,0,NULL);
+<a name="l00549"></a>00549   sinfo_msg(<span class="stringliteral">"ref_bin_size[AA]=%g"</span>,ref_bin_size);
+<a name="l00550"></a>00550   <span class="comment">/*</span>
+<a name="l00551"></a>00551 <span class="comment">  sinfo_msg("Unit conversion factor src/ref STD spectrum=%g",</span>
+<a name="l00552"></a>00552 <span class="comment">          src2ref_wave_sampling);</span>
+<a name="l00553"></a>00553 <span class="comment">  */</span>
+<a name="l00554"></a>00554 
+<a name="l00555"></a>00555   <span class="comment">/* convert obj spectrum wave unit to the same of the reference one */</span>
+<a name="l00556"></a>00556   check_nomsg(cpl_table_multiply_scalar(tbl_obj_spectrum,col_name_obj_wave,
+<a name="l00557"></a>00557                                  src2ref_wave_sampling));
+<a name="l00558"></a>00558 
+<a name="l00559"></a>00559   check_nomsg(cpl_table_save(tbl_ref,NULL,NULL,<span class="stringliteral">"ref2.fits"</span>,CPL_IO_DEFAULT));
+<a name="l00560"></a>00560   check_nomsg(cpl_table_save(tbl_atmext,NULL,NULL,<span class="stringliteral">"atm2.fits"</span>,CPL_IO_DEFAULT));
+<a name="l00561"></a>00561   check_nomsg(cpl_table_save(tbl_obj_spectrum,NULL,NULL,<span class="stringliteral">"sci2.fits"</span>,CPL_IO_DEFAULT));
+<a name="l00562"></a>00562   sinfo_msg(<span class="stringliteral">"object 2 src std %g"</span>,src2ref_wave_sampling);
+<a name="l00563"></a>00563   check_nomsg(pw=cpl_table_get_data_double(tbl_obj_spectrum,col_name_obj_wave));
+<a name="l00564"></a>00564   check_nomsg(pf=cpl_table_get_data_double(tbl_obj_spectrum,col_name_obj_flux));
+<a name="l00565"></a>00565 
+<a name="l00566"></a>00566   <span class="comment">// prepare columns for the output data</span>
+<a name="l00567"></a>00567   check_nomsg(tbl_result=cpl_table_new(nrow));
+<a name="l00568"></a>00568   check_nomsg(pref=sinfo_create_column_double(tbl_result, COL_NAME_REF, nrow));
+<a name="l00569"></a>00569   check_nomsg(pext=sinfo_create_column_double(tbl_result, COL_NAME_EXT, nrow));
+<a name="l00570"></a>00570   check_nomsg(pcor=sinfo_create_column_double(tbl_result, COL_NAME_COR, nrow));
+<a name="l00571"></a>00571   check_nomsg(peph=sinfo_create_column_double(tbl_result, COL_NAME_EPHOT, nrow));
+<a name="l00572"></a>00572   sinfo_msg(<span class="stringliteral">"wave range: [%g,%g]"</span>,pw[0],pw[nrow-1]); 
+<a name="l00573"></a>00573   sinfo_msg(<span class="stringliteral">"src_bin_size[AA]=%g"</span>,pw[1] - pw[0]);
+<a name="l00574"></a>00574   
+<a name="l00575"></a>00575   cdelta1 = (pw[1] - pw[0]) / src2ref_wave_sampling ; <span class="comment">/* we want the delta in original units. As we rescaled to AA we need to correct for this */</span>
+<a name="l00576"></a>00576   <span class="comment">//sinfo_msg("nrow=%d cdelta1=%g",nrow,cdelta1);</span>
+<a name="l00577"></a>00577   <span class="keywordflow">for</span> (i = 0; i < nrow; i++)
+<a name="l00578"></a>00578     {
+<a name="l00579"></a>00579       check_nomsg(pext[i] = sinfo_table_interpolate(tbl_atmext, pw[i],col_name_atm_wave, col_name_atm_abs));
+<a name="l00580"></a>00580       check_nomsg(pref[i] = sinfo_table_interpolate(tbl_ref, pw[i], col_name_ref_wave,col_name_ref_flux));
+<a name="l00581"></a>00581       pcor[i] = pow(10,(0.4*pext[i] * (aimprim - airmass)));
+<a name="l00582"></a>00582       peph[i] = 1.e7*1.986e-19/(pw[i]*1e-4);
+<a name="l00583"></a>00583       <span class="comment">/* ph energy: 1.986*10^-19(J.ph^-1)/lam(um) ==> </span>
+<a name="l00584"></a>00584 <span class="comment">         in as pw is expressed in Angstrom units we need to multiply by 10-4 </span>
+<a name="l00585"></a>00585 <span class="comment">       */</span>
+<a name="l00586"></a>00586       <span class="comment">/*</span>
+<a name="l00587"></a>00587 <span class="comment">      if(i< 2) {</span>
+<a name="l00588"></a>00588 <span class="comment">         sinfo_msg("pw[i]=%g,pcor=%g peph=%g",pw[i],pcor[i],peph[i]);</span>
+<a name="l00589"></a>00589 <span class="comment">      }</span>
+<a name="l00590"></a>00590 <span class="comment">      */</span>
+<a name="l00591"></a>00591     }
+<a name="l00592"></a>00592 
+<a name="l00593"></a>00593 
+<a name="l00594"></a>00594   <span class="comment">/*</span>
+<a name="l00595"></a>00595 <span class="comment">  sinfo_msg("atm: %s, %s ref: %s, %s obj: %s, %s",</span>
+<a name="l00596"></a>00596 <span class="comment">          col_name_atm_wave,col_name_atm_abs,</span>
+<a name="l00597"></a>00597 <span class="comment">          col_name_ref_wave,col_name_ref_flux,</span>
+<a name="l00598"></a>00598 <span class="comment">          col_name_obj_wave,col_name_obj_flux);</span>
+<a name="l00599"></a>00599 <span class="comment">  */</span>
+<a name="l00600"></a>00600   check_nomsg(cpl_table_duplicate_column(tbl_result,COL_NAME_SRC_COR,
+<a name="l00601"></a>00601                    tbl_obj_spectrum, col_name_obj_flux));
+<a name="l00602"></a>00602   check_nomsg(cpl_table_duplicate_column(tbl_result,col_name_obj_wave,
+<a name="l00603"></a>00603                    tbl_obj_spectrum,col_name_obj_wave));
+<a name="l00604"></a>00604   <span class="comment">/* correct for atmospheric extintion */</span>
+<a name="l00605"></a>00605   check_nomsg(cpl_table_multiply_columns(tbl_result,COL_NAME_SRC_COR,COL_NAME_COR));
+<a name="l00606"></a>00606 
+<a name="l00607"></a>00607   <span class="comment">/* correct object flux by binning: </span>
+<a name="l00608"></a>00608 <span class="comment">      divides by binsize in ref_wave_sampling (usually AA): </span>
+<a name="l00609"></a>00609 <span class="comment">     cdelt1[src_sampling]*src2ref_wave_sampling */</span>
+<a name="l00610"></a>00610   cpl_table_divide_scalar(tbl_result, COL_NAME_SRC_COR, src2ref_wave_sampling);
+<a name="l00611"></a>00611 
+<a name="l00612"></a>00612   cpl_table_divide_scalar(tbl_result, COL_NAME_SRC_COR, cdelta1);
+<a name="l00613"></a>00613   <span class="comment">/* correct for spatial bin size */</span>
+<a name="l00614"></a>00614 
+<a name="l00615"></a>00615   cpl_table_divide_scalar(tbl_result,COL_NAME_SRC_COR,biny); 
+<a name="l00616"></a>00616 
+<a name="l00617"></a>00617 
+<a name="l00618"></a>00618   <span class="comment">/*correct ref std star flux by binning: </span>
+<a name="l00619"></a>00619 <span class="comment">    divides by the bin size in ref_wave_sampling (usually AA) */</span>
+<a name="l00620"></a>00620   check_nomsg(cpl_table_divide_scalar(tbl_result,COL_NAME_REF,ref_bin_size));
+<a name="l00621"></a>00621 
+<a name="l00622"></a>00622   check_nomsg(cpl_table_duplicate_column(tbl_result,COL_NAME_SRC_EFF,
+<a name="l00623"></a>00623                    tbl_result,COL_NAME_SRC_COR));
+<a name="l00624"></a>00624 
+<a name="l00625"></a>00625 
+<a name="l00626"></a>00626   <span class="comment">/* correct for detector gain, exposure time, telescope area */</span>
+<a name="l00627"></a>00627   check_nomsg(cpl_table_multiply_scalar(tbl_result,COL_NAME_SRC_EFF,
+<a name="l00628"></a>00628                   gain / (exptime * TEL_AREA)));
+<a name="l00629"></a>00629 
+<a name="l00630"></a>00630   <span class="comment">/* correct for photon energy */</span>
+<a name="l00631"></a>00631   check_nomsg(cpl_table_multiply_columns(tbl_result,COL_NAME_SRC_EFF,
+<a name="l00632"></a>00632                    COL_NAME_EPHOT));
+<a name="l00633"></a>00633 
+<a name="l00634"></a>00634 
+<a name="l00635"></a>00635   check_nomsg(cpl_table_divide_columns(tbl_result,COL_NAME_SRC_EFF,COL_NAME_REF));
+<a name="l00636"></a>00636   <span class="comment">/* apply factor 1.e16 as reference catalog has fluxes in units of 1e-16 */</span>
+<a name="l00637"></a>00637   check_nomsg(cpl_table_multiply_scalar(tbl_result,COL_NAME_SRC_EFF,1.e16));
+<a name="l00638"></a>00638   <span class="comment">//check_nomsg(cpl_table_save(tbl_result,NULL,NULL,"pippo.fits", CPL_IO_DEFAULT));</span>
+<a name="l00639"></a>00639   <span class="comment">/* clean from outliers */</span>
+<a name="l00640"></a>00640   cpl_table_and_selected_double(tbl_result,COL_NAME_SRC_EFF,
+<a name="l00641"></a>00641                 CPL_GREATER_THAN,1.e-5);
+<a name="l00642"></a>00642   cpl_table_and_selected_double(tbl_result,COL_NAME_SRC_EFF,
+<a name="l00643"></a>00643                 CPL_LESS_THAN,100.);
+<a name="l00644"></a>00644   tbl_sel=cpl_table_extract_selected(tbl_result);
+<a name="l00645"></a>00645   check_nomsg(cpl_table_save(tbl_result,NULL,NULL,<span class="stringliteral">"result9.fits"</span>,CPL_IO_DEFAULT));
+<a name="l00646"></a>00646 
+<a name="l00647"></a>00647  cleanup:
+<a name="l00648"></a>00648   sinfo_free_table(&tbl_result);
+<a name="l00649"></a>00649   <span class="keywordflow">return</span> tbl_sel;
+<a name="l00650"></a>00650 }
+<a name="l00651"></a>00651 
+<a name="l00652"></a>00652 
+<a name="l00653"></a>00653 cpl_table*
+<a name="l00654"></a>00654 sinfo_efficiency_compute(cpl_frame* frm_sci, 
+<a name="l00655"></a>00655                        cpl_frame* frm_cat,
+<a name="l00656"></a>00656                        cpl_frame* frm_atmext)
+<a name="l00657"></a>00657 
+<a name="l00658"></a>00658 {
+<a name="l00659"></a>00659 
+<a name="l00660"></a>00660   cpl_propertylist* plist=NULL;
+<a name="l00661"></a>00661 
+<a name="l00662"></a>00662   cpl_table* tbl_eff=NULL;
+<a name="l00663"></a>00663   cpl_table* tbl_ref=NULL;
+<a name="l00664"></a>00664   cpl_table* tbl_atmext=NULL;
+<a name="l00665"></a>00665   cpl_table* tbl_sci=NULL;
+<a name="l00666"></a>00666 
+<a name="l00667"></a>00667   <span class="keywordtype">double</span> exptime=600;
+<a name="l00668"></a>00668   <span class="keywordtype">double</span> airmass=0;
+<a name="l00669"></a>00669   <span class="keywordtype">double</span> airmass_start=0;
+<a name="l00670"></a>00670   <span class="keywordtype">double</span> airmass_end=0;
+<a name="l00671"></a>00671   <span class="keywordtype">double</span> dRA=0;
+<a name="l00672"></a>00672   <span class="keywordtype">double</span> dDEC=0;
+<a name="l00673"></a>00673   <span class="keywordtype">double</span> gain=0;
+<a name="l00674"></a>00674   <span class="keywordtype">double</span> aimprim=0;
+<a name="l00675"></a>00675   <span class="keywordtype">double</span> dEpsilon=0.1;
+<a name="l00676"></a>00676   <span class="keywordtype">double</span> um2AA=1.e4;
+<a name="l00677"></a>00677 
+<a name="l00678"></a>00678   <span class="keywordtype">int</span> nrow=0;
+<a name="l00679"></a>00679   <span class="keywordtype">int</span> biny=1;
+<a name="l00680"></a>00680 
+<a name="l00681"></a>00681   <span class="keyword">const</span> <span class="keywordtype">char</span>* name_sci=NULL;
+<a name="l00682"></a>00682   <span class="keyword">const</span> <span class="keywordtype">char</span>* name_atm=NULL;
+<a name="l00683"></a>00683 
+<a name="l00684"></a>00684   name_sci=cpl_frame_get_filename(frm_sci);
+<a name="l00685"></a>00685   sinfo_msg(<span class="stringliteral">"name_sci=%s"</span>,name_sci);     
+<a name="l00686"></a>00686   check_nomsg(plist=cpl_propertylist_load(name_sci,0));
+<a name="l00687"></a>00687   check_nomsg(tbl_sci=cpl_table_load(name_sci,1,0));
+<a name="l00688"></a>00688   check_nomsg(dRA=sinfo_pfits_get_ra(plist));
+<a name="l00689"></a>00689   dDEC=sinfo_pfits_get_dec(plist);
+<a name="l00690"></a>00690   airmass_start=sinfo_pfits_get_airmass_end(plist);
+<a name="l00691"></a>00691   airmass_end=sinfo_pfits_get_airmass_end(plist);
+<a name="l00692"></a>00692   airmass=0.5*(airmass_start+airmass_end);
+<a name="l00693"></a>00693   gain=2.42;
+<a name="l00694"></a>00694   biny=1;
+<a name="l00695"></a>00695   check_nomsg(exptime=sinfo_pfits_get_dit(plist));
+<a name="l00696"></a>00696   sinfo_free_propertylist(&plist);
+<a name="l00697"></a>00697   sinfo_msg(<span class="stringliteral">"gain=%g airm=%g exptime=%g airmass=%g ra=%g dec=%g"</span>,
+<a name="l00698"></a>00698           gain,airmass,exptime,airmass,dRA,dDEC);
+<a name="l00699"></a>00699 
+<a name="l00700"></a>00700   sinfo_msg(<span class="stringliteral">"table sci spectra=%s"</span>,name_sci);
+<a name="l00701"></a>00701   nrow=cpl_table_get_nrow(tbl_sci);
+<a name="l00702"></a>00702 
+<a name="l00703"></a>00703   check_nomsg(name_atm=cpl_frame_get_filename(frm_atmext));
+<a name="l00704"></a>00704   check_nomsg(tbl_atmext=cpl_table_load(name_atm,1,0));
+<a name="l00705"></a>00705  
+<a name="l00706"></a>00706   check_nomsg(sinfo_parse_catalog_std_stars(frm_cat,dRA,dDEC,dEpsilon,&tbl_ref));
+<a name="l00707"></a>00707  
+<a name="l00708"></a>00708   <span class="keywordflow">if</span>(tbl_ref == NULL) {
+<a name="l00709"></a>00709     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Provide std sar catalog frame"</span>);
+<a name="l00710"></a>00710     <span class="keywordflow">return</span> NULL;
+<a name="l00711"></a>00711   <span class="comment">//cpl_table_dump(tbl_ref,0,3,stdout);</span>
+<a name="l00712"></a>00712   }
+<a name="l00713"></a>00713 
+<a name="l00714"></a>00714   check_nomsg(cpl_table_save(tbl_sci,NULL,NULL,<span class="stringliteral">"sci.fits"</span>,CPL_IO_DEFAULT));
+<a name="l00715"></a>00715   check_nomsg(tbl_eff=sinfo_utl_efficiency_internal(tbl_sci,tbl_atmext,tbl_ref,
+<a name="l00716"></a>00716                                                  exptime,airmass,aimprim,gain,
+<a name="l00717"></a>00717                                                  biny,um2AA,
+<a name="l00718"></a>00718                                                  <span class="stringliteral">"LAMBDA"</span>,
+<a name="l00719"></a>00719                                                  <span class="stringliteral">"LA_SILLA"</span>,
+<a name="l00720"></a>00720                                                  <span class="stringliteral">"LAMBDA"</span>,
+<a name="l00721"></a>00721                                                  <span class="stringliteral">"F_LAMBDA"</span>,
+<a name="l00722"></a>00722                                                  <span class="stringliteral">"BIN_WIDTH"</span>,
+<a name="l00723"></a>00723                                                  <span class="stringliteral">"wavelength"</span>,
+<a name="l00724"></a>00724                                                  <span class="stringliteral">"counts_bkg"</span>));
+<a name="l00725"></a>00725 
+<a name="l00726"></a>00726   cleanup:
+<a name="l00727"></a>00727   sinfo_free_table(&tbl_ref);
+<a name="l00728"></a>00728   sinfo_free_table(&tbl_atmext);
+<a name="l00729"></a>00729   sinfo_free_propertylist(&plist);
+<a name="l00730"></a>00730  
+<a name="l00731"></a>00731   <span class="keywordflow">return</span> tbl_eff;
+<a name="l00732"></a>00732 
+<a name="l00733"></a>00733 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__utl__efficiency_8h_source.html b/html/sinfo__utl__efficiency_8h_source.html
new file mode 100644
index 0000000..0f664fe
--- /dev/null
+++ b/html/sinfo__utl__efficiency_8h_source.html
@@ -0,0 +1,107 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_utl_efficiency.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_utl_efficiency.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004-2009 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*</span>
+<a name="l00020"></a>00020 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Date: 2010/02/08 07:18:21 $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Revision: 1.9 $</span>
+<a name="l00023"></a>00023 <span class="comment"> *</span>
+<a name="l00024"></a>00024 <span class="comment"> */</span>
+<a name="l00025"></a>00025 
+<a name="l00026"></a>00026 <span class="preprocessor">#ifndef SINFO_UTL_EFFICIENCY_H_</span>
+<a name="l00027"></a>00027 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_UTL_EFFICIENCY_H_</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="preprocessor">#include <cpl.h></span>
+<a name="l00029"></a>00029 
+<a name="l00030"></a>00030 
+<a name="l00031"></a>00031 <span class="keywordtype">void</span> 
+<a name="l00032"></a>00032 sinfo_load_ref_table(cpl_frameset* frames, 
+<a name="l00033"></a>00033                    <span class="keywordtype">double</span> dRA, 
+<a name="l00034"></a>00034                    <span class="keywordtype">double</span> dDEC, 
+<a name="l00035"></a>00035                    <span class="keywordtype">double</span> EPSILON, 
+<a name="l00036"></a>00036                    cpl_table** pptable);
+<a name="l00037"></a>00037 
+<a name="l00038"></a>00038 
+<a name="l00039"></a>00039 
+<a name="l00040"></a>00040 cpl_table*
+<a name="l00041"></a>00041 sinfo_utl_efficiency(
+<a name="l00042"></a>00042              cpl_frameset * frames,
+<a name="l00043"></a>00043              <span class="keywordtype">double</span> dGain,
+<a name="l00044"></a>00044              <span class="keywordtype">double</span> dEpsilon,
+<a name="l00045"></a>00045              <span class="keywordtype">double</span> aimprim,
+<a name="l00046"></a>00046                      <span class="keyword">const</span> <span class="keywordtype">char</span>* col_name_atm_wave,
+<a name="l00047"></a>00047                      <span class="keyword">const</span> <span class="keywordtype">char</span>* col_name_atm_abs,
+<a name="l00048"></a>00048                      <span class="keyword">const</span> <span class="keywordtype">char</span>* col_name_ref_wave,
+<a name="l00049"></a>00049                      <span class="keyword">const</span> <span class="keywordtype">char</span>* col_name_ref_flux,
+<a name="l00050"></a>00050                      <span class="keyword">const</span> <span class="keywordtype">char</span>* col_name_ref_bin,
+<a name="l00051"></a>00051                      <span class="keyword">const</span> <span class="keywordtype">char</span>* col_name_obj_wave,
+<a name="l00052"></a>00052                      <span class="keyword">const</span> <span class="keywordtype">char</span>* col_name_obj_flux
+<a name="l00053"></a>00053    );
+<a name="l00054"></a>00054 
+<a name="l00055"></a>00055 cpl_table* 
+<a name="l00056"></a>00056 sinfo_utl_efficiency_internal(
+<a name="l00057"></a>00057                   cpl_table* tbl_obj_spectrum,
+<a name="l00058"></a>00058                   cpl_table* tbl_atmext,
+<a name="l00059"></a>00059                   cpl_table* tbl_ref,
+<a name="l00060"></a>00060                   <span class="keywordtype">double</span> exptime,
+<a name="l00061"></a>00061                   <span class="keywordtype">double</span> airmass,
+<a name="l00062"></a>00062                   <span class="keywordtype">double</span> aimprim,
+<a name="l00063"></a>00063                   <span class="keywordtype">double</span> gain,
+<a name="l00064"></a>00064                   <span class="keywordtype">int</span>    biny,
+<a name="l00065"></a>00065                               <span class="keywordtype">double</span> src2ref_wave_sampling,
+<a name="l00066"></a>00066                               <span class="keyword">const</span> <span class="keywordtype">char</span>* col_name_atm_wave,
+<a name="l00067"></a>00067                               <span class="keyword">const</span> <span class="keywordtype">char</span>* col_name_atm_abs,
+<a name="l00068"></a>00068                               <span class="keyword">const</span> <span class="keywordtype">char</span>* col_name_ref_wave,
+<a name="l00069"></a>00069                               <span class="keyword">const</span> <span class="keywordtype">char</span>* col_name_ref_flux,
+<a name="l00070"></a>00070                               <span class="keyword">const</span> <span class="keywordtype">char</span>* col_name_ref_bin,
+<a name="l00071"></a>00071                               <span class="keyword">const</span> <span class="keywordtype">char</span>* col_name_obj_wave,
+<a name="l00072"></a>00072                               <span class="keyword">const</span> <span class="keywordtype">char</span>* col_name_obj_flux
+<a name="l00073"></a>00073    );
+<a name="l00074"></a>00074 
+<a name="l00075"></a>00075 <span class="keywordtype">double</span>
+<a name="l00076"></a>00076 sinfo_data_interpolate(
+<a name="l00077"></a>00077              <span class="keywordtype">double</span> wav,
+<a name="l00078"></a>00078              <span class="keywordtype">int</span> nrow,
+<a name="l00079"></a>00079              <span class="keywordtype">double</span>* pw,
+<a name="l00080"></a>00080              <span class="keywordtype">double</span>* pe
+<a name="l00081"></a>00081              );
+<a name="l00082"></a>00082 
+<a name="l00083"></a>00083 
+<a name="l00084"></a>00084 
+<a name="l00085"></a>00085 cpl_table*
+<a name="l00086"></a>00086 sinfo_efficiency_compute(cpl_frame* frm_sci, 
+<a name="l00087"></a>00087                        cpl_frame* frm_cat,
+<a name="l00088"></a>00088                        cpl_frame* frm_atmext);
+<a name="l00089"></a>00089 
+<a name="l00090"></a>00090 
+<a name="l00091"></a>00091 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__utl__illumcorr_8c_source.html b/html/sinfo__utl__illumcorr_8c_source.html
new file mode 100644
index 0000000..20e90b9
--- /dev/null
+++ b/html/sinfo__utl__illumcorr_8c_source.html
@@ -0,0 +1,1945 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_utl_illumcorr.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_utl_illumcorr.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_utl_illumcorr.c,v 1.18 2012/03/03 10:38:03 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the CPL (Common Pipeline Library)</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
+<a name="l00007"></a>00007 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span>
+<a name="l00008"></a>00008 <span class="comment"> * License as published by the Free Software Foundation; either</span>
+<a name="l00009"></a>00009 <span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
+<a name="l00014"></a>00014 <span class="comment"> * Lesser General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
+<a name="l00017"></a>00017 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2012/03/03 10:38:03 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.18 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> */</span>
+<a name="l00026"></a>00026 
+<a name="l00027"></a>00027  <span class="comment">/****************************************************************</span>
+<a name="l00028"></a>00028 <span class="comment">  *           Object Data reduction                              *</span>
+<a name="l00029"></a>00029 <span class="comment">  ****************************************************************/</span>
+<a name="l00030"></a>00030 
+<a name="l00031"></a>00031 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00032"></a>00032 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>          <span class="comment">/* allows the program compilation */</span>
+<a name="l00033"></a>00033 <span class="preprocessor">#endif</span>
+<a name="l00034"></a>00034 <span class="preprocessor"></span>
+<a name="l00035"></a>00035 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00036"></a>00036 <span class="comment">                                Includes</span>
+<a name="l00037"></a>00037 <span class="comment">-----------------------------------------------------------------------------*/</span>
+<a name="l00038"></a>00038 
+<a name="l00039"></a>00039 <span class="comment">/* std */</span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include <strings.h></span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include <string.h></span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include <stdio.h></span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include <math.h></span>
+<a name="l00044"></a>00044 <span class="preprocessor">#include <libgen.h></span>
+<a name="l00045"></a>00045 
+<a name="l00046"></a>00046 
+<a name="l00047"></a>00047 <span class="comment">/* cpl */</span>
+<a name="l00048"></a>00048 <span class="preprocessor">#include <cpl.h></span>  
+<a name="l00049"></a>00049 
+<a name="l00050"></a>00050 <span class="comment">/* irplib */</span>
+<a name="l00051"></a>00051 <span class="preprocessor">#include <irplib_utils.h></span>
+<a name="l00052"></a>00052 
+<a name="l00053"></a>00053 <span class="comment">/* sinfoni */</span>
+<a name="l00054"></a>00054 <span class="preprocessor">#include <sinfo_pro_types.h></span>
+<a name="l00055"></a>00055 <span class="preprocessor">#include <sinfo_product_config.h></span>
+<a name="l00056"></a>00056 <span class="preprocessor">#include <sinfo_prepare_stacked_frames_config.h></span>
+<a name="l00057"></a>00057 <span class="preprocessor">#include <sinfo_objnod_config.h></span>
+<a name="l00058"></a>00058 <span class="preprocessor">#include <sinfo_new_objnod.h></span>
+<a name="l00059"></a>00059 <span class="preprocessor">#include <sinfo_new_prepare_stacked_frames.h></span>
+<a name="l00060"></a>00060 <span class="preprocessor">#include <sinfo_pro_save.h></span>
+<a name="l00061"></a>00061 <span class="preprocessor">#include <sinfo_raw_types.h></span>
+<a name="l00062"></a>00062 <span class="preprocessor">#include <sinfo_functions.h></span>
+<a name="l00063"></a>00063 <span class="preprocessor">#include <sinfo_tpl_utils.h></span>
+<a name="l00064"></a>00064 <span class="preprocessor">#include <sinfo_tpl_dfs.h></span>
+<a name="l00065"></a>00065 <span class="preprocessor">#include <sinfo_hidden.h></span>
+<a name="l00066"></a>00066 <span class="preprocessor">#include <sinfo_globals.h></span>
+<a name="l00067"></a>00067 <span class="preprocessor">#include <sinfo_rec_utils.h></span>
+<a name="l00068"></a>00068 <span class="comment">//Only for sinfo_propertylist_has</span>
+<a name="l00069"></a>00069 <span class="preprocessor">#include <sinfo_dfs.h></span>
+<a name="l00070"></a>00070 
+<a name="l00071"></a>00071 
+<a name="l00072"></a>00072 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00073"></a>00073 <span class="comment">                            Function prototypes</span>
+<a name="l00074"></a>00074 <span class="comment">-----------------------------------------------------------------------------*/</span>
+<a name="l00075"></a>00075 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_illumcorr_create(cpl_plugin *plugin);
+<a name="l00076"></a>00076 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_illumcorr_exec(cpl_plugin *plugin);
+<a name="l00077"></a>00077 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_illumcorr_destroy(cpl_plugin *plugin);
+<a name="l00078"></a>00078 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_illumcorr(cpl_parameterlist *config, cpl_frameset *<span class="keyword">set</span>);
+<a name="l00079"></a>00079 
+<a name="l00080"></a>00080 
+<a name="l00081"></a>00081 <span class="preprocessor">#define SINFO_DOUBLE_SWAP(a,b) { register double t=(a);(a)=(b);(b)=t; }</span>
+<a name="l00082"></a>00082 <span class="preprocessor"></span>
+<a name="l00083"></a>00083 <span class="keyword">static</span> cpl_error_code 
+<a name="l00084"></a>00084 sinfo_tools_sort_double(
+<a name="l00085"></a>00085         <span class="keywordtype">double</span>  *   pix_arr,
+<a name="l00086"></a>00086         <span class="keywordtype">int</span>         n);
+<a name="l00087"></a>00087 
+<a name="l00088"></a>00088 <span class="keyword">static</span> cpl_frame* 
+<a name="l00089"></a>00089 sinfo_get_dummy_object(cpl_frameset* obj_set);
+<a name="l00090"></a>00090 
+<a name="l00091"></a>00091 <span class="keyword">static</span> <span class="keywordtype">void</span> 
+<a name="l00092"></a>00092 sinfo_illumcorr_config_add (cpl_parameterlist *list);
+<a name="l00093"></a>00093 
+<a name="l00094"></a>00094 <span class="keyword">static</span> <span class="keywordtype">int</span> 
+<a name="l00095"></a>00095 create_illumcorr (<span class="keyword">const</span> <span class="keywordtype">char</span>* plugin_id, 
+<a name="l00096"></a>00096                  cpl_parameterlist *cpl_cfg, 
+<a name="l00097"></a>00097                  cpl_frameset* sof,
+<a name="l00098"></a>00098                  <span class="keyword">const</span> <span class="keywordtype">char</span> *name_i);
+<a name="l00099"></a>00099 <span class="keyword">static</span> <span class="keywordtype">int</span> 
+<a name="l00100"></a>00100 sinfo_illumcorr_create_bins (cpl_imagelist *sky, 
+<a name="l00101"></a>00101                  <span class="keywordtype">int</span> llx, <span class="keywordtype">int</span> lly, <span class="keywordtype">int</span> urx, <span class="keywordtype">int</span> ury,
+<a name="l00102"></a>00102                  <span class="keywordtype">int</span> spec_bin, 
+<a name="l00103"></a>00103                  <span class="keywordtype">double</span> min_flux,
+<a name="l00104"></a>00104                  <span class="keywordtype">int</span> ** start,
+<a name="l00105"></a>00105                  <span class="keywordtype">int</span> ** end,
+<a name="l00106"></a>00106                  <span class="keywordtype">int</span> z1, <span class="keywordtype">int</span> z2);
+<a name="l00107"></a>00107 
+<a name="l00108"></a>00108 <span class="keyword">static</span> <span class="keywordtype">int</span> 
+<a name="l00109"></a>00109 sinfo_juha_function1d_natural_spline(<span class="keywordtype">double</span> *, <span class="keywordtype">double</span> *, <span class="keywordtype">int</span>, <span class="keywordtype">double</span> *, 
+<a name="l00110"></a>00110                                      <span class="keywordtype">double</span> *, <span class="keywordtype">int</span>);
+<a name="l00111"></a>00111 
+<a name="l00112"></a>00112 <span class="keyword">static</span> <span class="keywordtype">int</span> 
+<a name="l00113"></a>00113 sinfo_function1d_search_value(<span class="keywordtype">double</span> *, <span class="keywordtype">int</span>, <span class="keywordtype">double</span>, <span class="keywordtype">int</span> *) ;
+<a name="l00114"></a>00114 
+<a name="l00115"></a>00115 <span class="keyword">static</span> cpl_vector * 
+<a name="l00116"></a>00116 sinfo_vector_filter_median_create(<span class="keyword">const</span> cpl_vector * v, <span class="keywordtype">int</span>  hw);
+<a name="l00117"></a>00117 
+<a name="l00118"></a>00118 <span class="keyword">static</span> cpl_vector * 
+<a name="l00119"></a>00119 sinfo_juha_vector_filter_median_create(<span class="keyword">const</span> cpl_vector * v, <span class="keywordtype">int</span>  hw);
+<a name="l00120"></a>00120 
+<a name="l00121"></a>00121 <span class="keyword">static</span> <span class="keywordtype">double</span> 
+<a name="l00122"></a>00122 sinfo_image_get_median_window  (<span class="keyword">const</span> cpl_image *image, 
+<a name="l00123"></a>00123                 <span class="keywordtype">int</span> llx, <span class="keywordtype">int</span> lly, <span class="keywordtype">int</span> urx, <span class="keywordtype">int</span> ury);
+<a name="l00124"></a>00124 
+<a name="l00125"></a>00125 
+<a name="l00126"></a>00126 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00127"></a>00127 <span class="comment">                            Static variables</span>
+<a name="l00128"></a>00128 <span class="comment">-----------------------------------------------------------------------------*/</span>
+<a name="l00129"></a>00129 
+<a name="l00130"></a>00130 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_utl_illumcorr_description1[] =
+<a name="l00131"></a>00131 <span class="stringliteral">"This recipe calculates illumination correction based on sky emission.\n"</span>
+<a name="l00132"></a>00132 <span class="stringliteral">"The input files are sky (or object) frames tagged\n"</span>
+<a name="l00133"></a>00133 <span class="stringliteral">" SKY_NODDING (OBJECT_NODDING)\n"</span>
+<a name="l00134"></a>00134 <span class="stringliteral">"Master calibration frames:\n"</span>;
+<a name="l00135"></a>00135 
+<a name="l00136"></a>00136 
+<a name="l00137"></a>00137 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_utl_illumcorr_description2[] =
+<a name="l00138"></a>00138 <span class="stringliteral">"A corresponding (DIT) dark frame (tag=MASTER_DARK)"</span>
+<a name="l00139"></a>00139 <span class="stringliteral">"A corresponding (band,preoptics) wavelength map image (tag=WAVE_MAP)\n"</span>
+<a name="l00140"></a>00140 <span class="stringliteral">"A corresponding (band,preoptics) master flat field (tag=MASTER_FLAT_LAMP)\n"</span>
+<a name="l00141"></a>00141 <span class="stringliteral">"A corresponding (band,preoptics) master bad pixel map (tag=MASTER_BP_MAP)\n"</span>
+<a name="l00142"></a>00142 <span class="stringliteral">"A corresponding (band,preoptics) slitlets position frame (tag=SLIT_POS)\n"</span>
+<a name="l00143"></a>00143 <span class="stringliteral">"A corresponding (band) distortion table (tag=DISTORTION)\n"</span>
+<a name="l00144"></a>00144 <span class="stringliteral">"A corresponding (band) slitlet distance table (tag=SLITLETS_DISTANCE)\n"</span>;
+<a name="l00145"></a>00145 
+<a name="l00146"></a>00146 
+<a name="l00147"></a>00147 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_utl_illumcorr_description3[] =
+<a name="l00148"></a>00148 <span class="stringliteral">"The output is a cube resulting from the analysis of sky emission\n"</span>;
+<a name="l00149"></a>00149 
+<a name="l00150"></a>00150 
+<a name="l00151"></a>00151 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_utl_illumcorr_description4[] =
+<a name="l00152"></a>00152 <span class="stringliteral">"Information on relevant parameters can be found with\n"</span>
+<a name="l00153"></a>00153 <span class="stringliteral">"esorex --params sinfo_utl_illumcorr\n"</span>
+<a name="l00154"></a>00154 <span class="stringliteral">"esorex --help sinfo_utl_illumcorr\n"</span>
+<a name="l00155"></a>00155 <span class="stringliteral">"\n"</span>;
+<a name="l00156"></a>00156 
+<a name="l00157"></a>00157 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_utl_illumcorr_description[1300];
+<a name="l00158"></a>00158 
+<a name="l00159"></a>00159 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00160"></a>00160 <span class="comment">                                Functions code</span>
+<a name="l00161"></a>00161 <span class="comment">-----------------------------------------------------------------------------*/</span>
+<a name="l00162"></a>00162 
+<a name="l00164"></a>00164 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00169"></a>00169 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00170"></a>00170 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00171"></a>00171 sinfo_utl_illumcorr_create(cpl_plugin *plugin)
+<a name="l00172"></a>00172 {
+<a name="l00173"></a>00173 
+<a name="l00174"></a>00174   <span class="comment">/*</span>
+<a name="l00175"></a>00175 <span class="comment">   * We have to provide the option we accept to the application.</span>
+<a name="l00176"></a>00176 <span class="comment">   * We need to setup our parameter list and hook it into the recipe</span>
+<a name="l00177"></a>00177 <span class="comment">   * interface.</span>
+<a name="l00178"></a>00178 <span class="comment">   */</span>
+<a name="l00179"></a>00179   cpl_recipe *recipe = (cpl_recipe *)plugin;
+<a name="l00180"></a>00180   recipe->parameters = cpl_parameterlist_new();
+<a name="l00181"></a>00181   <span class="keywordflow">if</span>(recipe->parameters == NULL) {
+<a name="l00182"></a>00182     <span class="keywordflow">return</span> 1;
+<a name="l00183"></a>00183   }
+<a name="l00184"></a>00184   cpl_error_reset();
+<a name="l00185"></a>00185   <a class="code" href="group__irplib__utils.html#gaf9d392144014e2363054bc3f83c8e47e" title="Reset IRPLIB state.">irplib_reset</a>();
+<a name="l00186"></a>00186 
+<a name="l00187"></a>00187   <span class="comment">/*</span>
+<a name="l00188"></a>00188 <span class="comment">   * Fill the parameter list.</span>
+<a name="l00189"></a>00189 <span class="comment">   */</span>
+<a name="l00190"></a>00190   sinfo_product_config_add (recipe->parameters);
+<a name="l00191"></a>00191   sinfo_prepare_stacked_frames_config_add(recipe->parameters);
+<a name="l00192"></a>00192   sinfo_objnod_config_add(recipe->parameters); 
+<a name="l00193"></a>00193   sinfo_illumcorr_config_add (recipe->parameters);
+<a name="l00194"></a>00194  
+<a name="l00195"></a>00195   <span class="keywordflow">return</span> 0;
+<a name="l00196"></a>00196 
+<a name="l00197"></a>00197 }
+<a name="l00198"></a>00198 
+<a name="l00199"></a>00199 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00205"></a>00205 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00206"></a>00206 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00207"></a>00207 sinfo_utl_illumcorr_exec(cpl_plugin *plugin)
+<a name="l00208"></a>00208 {
+<a name="l00209"></a>00209  
+<a name="l00210"></a>00210   cpl_recipe *recipe = (cpl_recipe *) plugin;
+<a name="l00211"></a>00211   <span class="keywordtype">int</span> code=0;
+<a name="l00212"></a>00212   cpl_errorstate initial_errorstate = cpl_errorstate_get();
+<a name="l00213"></a>00213 
+<a name="l00214"></a>00214   <span class="keywordflow">if</span>(recipe->parameters == NULL) {
+<a name="l00215"></a>00215     <span class="keywordflow">return</span> 1;
+<a name="l00216"></a>00216   }
+<a name="l00217"></a>00217   <span class="keywordflow">if</span>(recipe->frames == NULL) {
+<a name="l00218"></a>00218     <span class="keywordflow">return</span> 1;
+<a name="l00219"></a>00219   }
+<a name="l00220"></a>00220   code=sinfo_utl_illumcorr(recipe->parameters, recipe->frames);
+<a name="l00221"></a>00221 
+<a name="l00222"></a>00222   <span class="keywordflow">if</span> (!cpl_errorstate_is_equal(initial_errorstate)) {                      
+<a name="l00223"></a>00223     <span class="comment">/* Dump the error history since recipe execution start.                </span>
+<a name="l00224"></a>00224 <span class="comment">       At this point the recipe cannot recover from the error */</span>           
+<a name="l00225"></a>00225     cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);              
+<a name="l00226"></a>00226   } 
+<a name="l00227"></a>00227   <span class="keywordflow">return</span> code;
+<a name="l00228"></a>00228 
+<a name="l00229"></a>00229 
+<a name="l00230"></a>00230 }
+<a name="l00231"></a>00231 
+<a name="l00232"></a>00232 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00238"></a>00238 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00239"></a>00239 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00240"></a>00240 sinfo_utl_illumcorr_destroy(cpl_plugin *plugin)
+<a name="l00241"></a>00241 {
+<a name="l00242"></a>00242   cpl_recipe *recipe = (cpl_recipe *) plugin;
+<a name="l00243"></a>00243   <span class="comment">/*</span>
+<a name="l00244"></a>00244 <span class="comment">   * We just destroy what was created during the plugin initializzation phase</span>
+<a name="l00245"></a>00245 <span class="comment">   * i.e. the parameter list. The frame set is managed by the application which</span>
+<a name="l00246"></a>00246 <span class="comment">   * called us, so that we must not touch it.</span>
+<a name="l00247"></a>00247 <span class="comment">   */</span>
+<a name="l00248"></a>00248 
+<a name="l00249"></a>00249   cpl_parameterlist_delete(recipe->parameters);
+<a name="l00250"></a>00250 
+<a name="l00251"></a>00251   <span class="keywordflow">return</span> 0;
+<a name="l00252"></a>00252 
+<a name="l00253"></a>00253 }
+<a name="l00254"></a>00254 
+<a name="l00255"></a>00255 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00263"></a>00263 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00264"></a>00264 <span class="keywordtype">int</span>
+<a name="l00265"></a>00265 <a class="code" href="group__sinfo__rec__detlin.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693" title="Build the list of available plugins, for this module.">cpl_plugin_get_info</a>(cpl_pluginlist *list)
+<a name="l00266"></a>00266 {
+<a name="l00267"></a>00267 
+<a name="l00268"></a>00268   cpl_recipe *recipe = cpl_calloc(1, <span class="keyword">sizeof</span> *recipe);
+<a name="l00269"></a>00269   cpl_plugin *plugin = &recipe->interface;
+<a name="l00270"></a>00270 
+<a name="l00271"></a>00271   strcpy(sinfo_utl_illumcorr_description,sinfo_utl_illumcorr_description1);
+<a name="l00272"></a>00272   strcat(sinfo_utl_illumcorr_description,sinfo_utl_illumcorr_description2);
+<a name="l00273"></a>00273   strcat(sinfo_utl_illumcorr_description,sinfo_utl_illumcorr_description3);
+<a name="l00274"></a>00274   strcat(sinfo_utl_illumcorr_description,sinfo_utl_illumcorr_description4);
+<a name="l00275"></a>00275 
+<a name="l00276"></a>00276   cpl_plugin_init(plugin,
+<a name="l00277"></a>00277           CPL_PLUGIN_API,
+<a name="l00278"></a>00278           SINFONI_BINARY_VERSION,
+<a name="l00279"></a>00279           CPL_PLUGIN_TYPE_RECIPE,
+<a name="l00280"></a>00280           <span class="stringliteral">"sinfo_utl_illumcorr"</span>,
+<a name="l00281"></a>00281           <span class="stringliteral">"Object data reduction"</span>,
+<a name="l00282"></a>00282            sinfo_utl_illumcorr_description,
+<a name="l00283"></a>00283           <span class="stringliteral">"Juha Reunanen"</span>,
+<a name="l00284"></a>00284           <span class="stringliteral">"reunanen at strw.leidenuniv.nl"</span>,
+<a name="l00285"></a>00285           sinfo_get_license(),
+<a name="l00286"></a>00286           sinfo_utl_illumcorr_create,
+<a name="l00287"></a>00287           sinfo_utl_illumcorr_exec,
+<a name="l00288"></a>00288           sinfo_utl_illumcorr_destroy);
+<a name="l00289"></a>00289 
+<a name="l00290"></a>00290   cpl_pluginlist_append(list, plugin);
+<a name="l00291"></a>00291 
+<a name="l00292"></a>00292   <span class="keywordflow">return</span> 0;
+<a name="l00293"></a>00293 
+<a name="l00294"></a>00294 }
+<a name="l00295"></a>00295 
+<a name="l00296"></a>00296 <span class="comment">/*</span>
+<a name="l00297"></a>00297 <span class="comment"> * The actual recipe actually start here.</span>
+<a name="l00298"></a>00298 <span class="comment"> */</span>
+<a name="l00299"></a>00299 
+<a name="l00300"></a>00300 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00301"></a>00301 sinfo_utl_illumcorr(cpl_parameterlist *config, cpl_frameset *<span class="keyword">set</span>)
+<a name="l00302"></a>00302 {
+<a name="l00303"></a>00303   <span class="keywordtype">char</span> outname[FILE_NAME_SZ];
+<a name="l00304"></a>00304 
+<a name="l00305"></a>00305   <span class="keywordtype">int</span> i=0;
+<a name="l00306"></a>00306   <span class="keywordtype">int</span> k=0;
+<a name="l00307"></a>00307 
+<a name="l00308"></a>00308   <span class="keywordtype">int</span> ind=0;
+<a name="l00309"></a>00309   <span class="keywordtype">int</span> nsky=0;
+<a name="l00310"></a>00310   <span class="keywordtype">int</span> nobj=0;
+<a name="l00311"></a>00311   <span class="keywordtype">int</span> ncdb=0;
+<a name="l00312"></a>00312   <span class="keywordtype">int</span> nstk=0;
+<a name="l00313"></a>00313 
+<a name="l00314"></a>00314   cpl_frameset  * obj_set=NULL;
+<a name="l00315"></a>00315   cpl_frameset  * sky_set=NULL;
+<a name="l00316"></a>00316   cpl_frameset  * cdb_set=NULL;
+<a name="l00317"></a>00317   cpl_frameset  * wrk_set=NULL;
+<a name="l00318"></a>00318   cpl_frameset  * stk_set=NULL;
+<a name="l00319"></a>00319   cpl_frame     * sky_frm=NULL;
+<a name="l00320"></a>00320 
+<a name="l00321"></a>00321   cpl_frame     * dup_frm=NULL; 
+<a name="l00322"></a>00322   cpl_frame     * cdb_frm=NULL;
+<a name="l00323"></a>00323   cpl_frame     * wrk_frm=NULL;
+<a name="l00324"></a>00324   cpl_frameset  * ref_set=NULL;
+<a name="l00325"></a>00325 
+<a name="l00326"></a>00326   cpl_frame     * dark_frm=NULL;
+<a name="l00327"></a>00327 
+<a name="l00328"></a>00328   fake* fk;
+<a name="l00329"></a>00329 
+<a name="l00330"></a>00330 
+<a name="l00331"></a>00331   cpl_image           *   ima1=NULL ;
+<a name="l00332"></a>00332   cpl_image           *   ima2=NULL ;
+<a name="l00333"></a>00333   cpl_image           *   resima=NULL ;
+<a name="l00334"></a>00334   cpl_propertylist    *   plist=NULL ;
+<a name="l00335"></a>00335   cpl_frame           *   product_frame=NULL;
+<a name="l00336"></a>00336   <span class="keyword">const</span> <span class="keywordtype">char</span> *name_i=NULL;
+<a name="l00337"></a>00337 
+<a name="l00338"></a>00338   <span class="comment">/* cpl_parameterlist_dump(config); */</span>
+<a name="l00339"></a>00339         sinfo_msg(<span class="stringliteral">"Welcome to SINFONI Pipeline release %d.%d.%d"</span>,
+<a name="l00340"></a>00340         SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
+<a name="l00341"></a>00341 
+<a name="l00342"></a>00342   <span class="keywordflow">if</span>(sinfo_dfs_set_groups(<span class="keyword">set</span>)) {
+<a name="l00343"></a>00343     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Cannot identify RAW and CALIB frames"</span>) ;
+<a name="l00344"></a>00344     <span class="keywordflow">return</span> -1;
+<a name="l00345"></a>00345   }
+<a name="l00346"></a>00346 
+<a name="l00347"></a>00347   dark_frm = cpl_frameset_find(<span class="keyword">set</span>,PRO_MASTER_DARK);
+<a name="l00348"></a>00348   <span class="keywordflow">if</span> (dark_frm == NULL) {
+<a name="l00349"></a>00349     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Cannot find dark frame"</span>) ;
+<a name="l00350"></a>00350     <span class="keywordflow">return</span> (-1);
+<a name="l00351"></a>00351   }
+<a name="l00352"></a>00352 
+<a name="l00353"></a>00353   ref_set=cpl_frameset_duplicate(<span class="keyword">set</span>);
+<a name="l00354"></a>00354 
+<a name="l00355"></a>00355   obj_set=cpl_frameset_new();
+<a name="l00356"></a>00356   sky_set=cpl_frameset_new();
+<a name="l00357"></a>00357   cdb_set=cpl_frameset_new();
+<a name="l00358"></a>00358   fk = sinfo_fake_new();
+<a name="l00359"></a>00359 
+<a name="l00360"></a>00360   sinfo_extract_obj_frames(<span class="keyword">set</span>,obj_set);
+<a name="l00361"></a>00361   sinfo_extract_sky_frames(<span class="keyword">set</span>,sky_set);
+<a name="l00362"></a>00362   sinfo_extract_mst_frames(<span class="keyword">set</span>,cdb_set);
+<a name="l00363"></a>00363 
+<a name="l00364"></a>00364   nobj=cpl_frameset_get_size(obj_set);
+<a name="l00365"></a>00365   nsky=cpl_frameset_get_size(sky_set);
+<a name="l00366"></a>00366   ncdb=cpl_frameset_get_size(cdb_set);
+<a name="l00367"></a>00367 
+<a name="l00368"></a>00368   <span class="keywordflow">if</span> ((nobj==0) && (nsky==0)) {
+<a name="l00369"></a>00369     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Empty input set"</span>);
+<a name="l00370"></a>00370     cpl_frameset_delete(obj_set);
+<a name="l00371"></a>00371     cpl_frameset_delete(sky_set);
+<a name="l00372"></a>00372     cpl_frameset_delete(cdb_set);
+<a name="l00373"></a>00373     cpl_frameset_delete(ref_set);
+<a name="l00374"></a>00374     sinfo_fake_delete(&fk);
+<a name="l00375"></a>00375     <span class="keywordflow">return</span> (-1);
+<a name="l00376"></a>00376   }
+<a name="l00377"></a>00377 
+<a name="l00378"></a>00378 
+<a name="l00379"></a>00379   <span class="comment">/*</span>
+<a name="l00380"></a>00380 <span class="comment">   *  Create median collapsed sky frame either from real SKY frames, </span>
+<a name="l00381"></a>00381 <span class="comment">   *  or from jittered OBJECT frames</span>
+<a name="l00382"></a>00382 <span class="comment">   */</span>
+<a name="l00383"></a>00383   <span class="keywordflow">if</span> ( nsky != 0) {
+<a name="l00384"></a>00384     <span class="keywordflow">if</span>( (sky_frm = sinfo_get_dummy_object(sky_set)) == NULL) {
+<a name="l00385"></a>00385       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Problem to get dummy frame"</span>);
+<a name="l00386"></a>00386       cpl_frameset_delete(obj_set);
+<a name="l00387"></a>00387       cpl_frameset_delete(sky_set);
+<a name="l00388"></a>00388       cpl_frameset_delete(cdb_set);
+<a name="l00389"></a>00389       cpl_frameset_delete(ref_set);
+<a name="l00390"></a>00390       sinfo_fake_delete(&fk);
+<a name="l00391"></a>00391       <span class="keywordflow">return</span> (-1);
+<a name="l00392"></a>00392     }
+<a name="l00393"></a>00393   }
+<a name="l00394"></a>00394   <span class="keywordflow">else</span> {
+<a name="l00395"></a>00395     <span class="keywordflow">if</span>( (sky_frm = sinfo_get_dummy_object(obj_set)) == NULL) {
+<a name="l00396"></a>00396       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Problem to get dummy frame"</span>);
+<a name="l00397"></a>00397       cpl_frameset_delete(obj_set);
+<a name="l00398"></a>00398       cpl_frameset_delete(sky_set);
+<a name="l00399"></a>00399       cpl_frameset_delete(cdb_set);
+<a name="l00400"></a>00400       cpl_frameset_delete(ref_set);
+<a name="l00401"></a>00401       sinfo_fake_delete(&fk);
+<a name="l00402"></a>00402       <span class="keywordflow">return</span> (-1);
+<a name="l00403"></a>00403     }
+<a name="l00404"></a>00404   }
+<a name="l00405"></a>00405   
+<a name="l00406"></a>00406   <span class="comment">/* </span>
+<a name="l00407"></a>00407 <span class="comment">   *  Seems it's not possible to use draks as sky (due to INS.GRAT1.ENC)</span>
+<a name="l00408"></a>00408 <span class="comment">   *  and stacking phase subtracts dark only in special circumstances...</span>
+<a name="l00409"></a>00409 <span class="comment">   */</span>
+<a name="l00410"></a>00410   ima1 = cpl_image_load(cpl_frame_get_filename(sky_frm),CPL_TYPE_FLOAT,0,0);
+<a name="l00411"></a>00411   ima2 = cpl_image_load(cpl_frame_get_filename(dark_frm),CPL_TYPE_FLOAT,0,0);
+<a name="l00412"></a>00412   resima = cpl_image_subtract_create(ima1, ima2);
+<a name="l00413"></a>00413   plist=cpl_propertylist_load(cpl_frame_get_filename(sky_frm), 0);
+<a name="l00414"></a>00414   cpl_image_delete(ima1);
+<a name="l00415"></a>00415   cpl_image_delete(ima2);
+<a name="l00416"></a>00416 
+<a name="l00417"></a>00417   product_frame = cpl_frame_new();
+<a name="l00418"></a>00418   cpl_frame_set_filename(product_frame, <span class="stringliteral">"out_fake_object2.fits"</span>) ;
+<a name="l00419"></a>00419   cpl_frame_set_tag(product_frame, <span class="stringliteral">"OBJECT_NODDING"</span>) ;
+<a name="l00420"></a>00420   cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_IMAGE) ;
+<a name="l00421"></a>00421   cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_RAW) ;
+<a name="l00422"></a>00422   <span class="comment">//cpl_frame_set_level(product_frame, CPL_FR) ;</span>
+<a name="l00423"></a>00423   cpl_propertylist_erase_regexp(plist, <span class="stringliteral">"^ESO PRO CATG"</span>,0);
+<a name="l00424"></a>00424 
+<a name="l00425"></a>00425   cpl_image_save(resima, <span class="stringliteral">"out_fake_object2.fits"</span>, CPL_BPP_IEEE_FLOAT, plist,
+<a name="l00426"></a>00426          CPL_IO_DEFAULT) ;
+<a name="l00427"></a>00427   cpl_propertylist_delete(plist) ;
+<a name="l00428"></a>00428   cpl_image_delete(resima) ;
+<a name="l00429"></a>00429 
+<a name="l00430"></a>00430 
+<a name="l00431"></a>00431   <span class="comment">/*</span>
+<a name="l00432"></a>00432 <span class="comment">   *  Stack it - with some trickery...</span>
+<a name="l00433"></a>00433 <span class="comment">   */</span> 
+<a name="l00434"></a>00434   wrk_set=cpl_frameset_new();
+<a name="l00435"></a>00435 
+<a name="l00436"></a>00436   dup_frm=cpl_frame_duplicate(product_frame);
+<a name="l00437"></a>00437   cpl_frame_set_tag   (dup_frm, <span class="stringliteral">"OBJECT_NODDING"</span>);
+<a name="l00438"></a>00438   cpl_frame_set_group (dup_frm ,CPL_FRAME_GROUP_RAW);
+<a name="l00439"></a>00439   cpl_frameset_insert(wrk_set,dup_frm);
+<a name="l00440"></a>00440 
+<a name="l00441"></a>00441   <span class="comment">/* merge CDB frames to work set */</span>
+<a name="l00442"></a>00442   <span class="keywordflow">for</span>(k=0;k<ncdb;k++) {
+<a name="l00443"></a>00443     cdb_frm=cpl_frameset_get_frame(cdb_set,k);
+<a name="l00444"></a>00444     dup_frm=cpl_frame_duplicate(cdb_frm);
+<a name="l00445"></a>00445     cpl_frameset_insert(wrk_set,dup_frm);
+<a name="l00446"></a>00446   }
+<a name="l00447"></a>00447   
+<a name="l00448"></a>00448   
+<a name="l00449"></a>00449   <span class="comment">/* defines a new name for the output stacked frame */</span> 
+<a name="l00450"></a>00450   sprintf(outname,<span class="stringliteral">"%s%d%s"</span>,<span class="stringliteral">"out_stack"</span>,i,<span class="stringliteral">".fits"</span>);
+<a name="l00451"></a>00451   <span class="keywordflow">if</span>(-1 == sinfo_new_stack_frames(config,wrk_set,
+<a name="l00452"></a>00452             PRO_OBJECT_NODDING_STACKED,i,fk,cpl_func)) {
+<a name="l00453"></a>00453     
+<a name="l00454"></a>00454     cpl_frameset_delete(wrk_set);
+<a name="l00455"></a>00455     <span class="comment">//cpl_frameset_delete(tot_set);</span>
+<a name="l00456"></a>00456     cpl_frameset_delete(obj_set);
+<a name="l00457"></a>00457     cpl_frameset_delete(sky_set);
+<a name="l00458"></a>00458     cpl_frameset_delete(cdb_set);
+<a name="l00459"></a>00459     cpl_frameset_delete(ref_set);
+<a name="l00460"></a>00460     sinfo_fake_delete(&fk);
+<a name="l00461"></a>00461     <span class="keywordflow">return</span> -1;
+<a name="l00462"></a>00462   }
+<a name="l00463"></a>00463 
+<a name="l00464"></a>00464   stk_set=cpl_frameset_new();
+<a name="l00465"></a>00465   sinfo_contains_frames_kind(wrk_set,stk_set,PRO_STACKED);
+<a name="l00466"></a>00466   nstk=cpl_frameset_get_size(stk_set);
+<a name="l00467"></a>00467 
+<a name="l00468"></a>00468   <span class="keywordflow">for</span>(k=0;k<nstk;k++) {
+<a name="l00469"></a>00469     wrk_frm=cpl_frameset_get_frame(stk_set,k);
+<a name="l00470"></a>00470     dup_frm = cpl_frame_duplicate(wrk_frm);
+<a name="l00471"></a>00471     cpl_frameset_insert(<span class="keyword">set</span>,dup_frm);
+<a name="l00472"></a>00472   }
+<a name="l00473"></a>00473   cpl_frameset_delete(stk_set);
+<a name="l00474"></a>00474   cpl_frameset_delete(wrk_set);
+<a name="l00475"></a>00475 
+<a name="l00476"></a>00476   sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ; 
+<a name="l00477"></a>00477   sinfo_msg(<span class="stringliteral">"CREATING SKY CUBE"</span>);
+<a name="l00478"></a>00478   sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ; 
+<a name="l00479"></a>00479   
+<a name="l00480"></a>00480 
+<a name="l00481"></a>00481   <span class="keywordflow">if</span> ( -1 == (ind=sinfo_new_objnod(cpl_func,config, <span class="keyword">set</span>, PRO_COADD_OBJ ) ) ) {
+<a name="l00482"></a>00482     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"NODDING SCIENCE FRAMES no. %d\n"</span>, ind) ;
+<a name="l00483"></a>00483     cpl_frameset_delete(obj_set);
+<a name="l00484"></a>00484     cpl_frameset_delete(sky_set);
+<a name="l00485"></a>00485     cpl_frameset_delete(cdb_set);
+<a name="l00486"></a>00486     cpl_frameset_delete(ref_set);
+<a name="l00487"></a>00487     sinfo_fake_delete(&fk);
+<a name="l00488"></a>00488     
+<a name="l00489"></a>00489     <span class="keywordflow">return</span> (-1);
+<a name="l00490"></a>00490   }
+<a name="l00491"></a>00491   sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ; 
+<a name="l00492"></a>00492   sinfo_msg(<span class="stringliteral">"CREATED SKY CUBE"</span>);
+<a name="l00493"></a>00493   sinfo_msg(<span class="stringliteral">"------------------------------"</span>) ; 
+<a name="l00494"></a>00494   
+<a name="l00495"></a>00495 
+<a name="l00496"></a>00496   stk_set=cpl_frameset_new();
+<a name="l00497"></a>00497   sinfo_contains_frames_kind(<span class="keyword">set</span>, stk_set, PRO_OBS_OBJ);
+<a name="l00498"></a>00498   nstk=cpl_frameset_get_size(stk_set);
+<a name="l00499"></a>00499 
+<a name="l00500"></a>00500   wrk_frm=cpl_frameset_get_frame(stk_set,0);  
+<a name="l00501"></a>00501   name_i = cpl_frame_get_filename(wrk_frm);
+<a name="l00502"></a>00502   
+<a name="l00503"></a>00503 
+<a name="l00504"></a>00504   <span class="comment">//cpl_frameset_delete(wrk_set);</span>
+<a name="l00505"></a>00505   cpl_frameset_delete(obj_set);
+<a name="l00506"></a>00506   cpl_frameset_delete(sky_set);
+<a name="l00507"></a>00507   cpl_frameset_delete(cdb_set);
+<a name="l00508"></a>00508   cpl_frameset_delete(ref_set);
+<a name="l00509"></a>00509   sinfo_fake_delete(&fk);
+<a name="l00510"></a>00510   cpl_frame_delete(sky_frm);
+<a name="l00511"></a>00511   create_illumcorr (cpl_func, config, <span class="keyword">set</span>, name_i);
+<a name="l00512"></a>00512 
+<a name="l00513"></a>00513   <span class="keywordflow">return</span> (0);
+<a name="l00514"></a>00514 
+<a name="l00515"></a>00515 }
+<a name="l00516"></a>00516 
+<a name="l00517"></a>00517 
+<a name="l00518"></a>00518 <span class="keyword">static</span> cpl_frame*
+<a name="l00519"></a>00519 sinfo_get_dummy_object(cpl_frameset* obj_set)
+<a name="l00520"></a>00520 {
+<a name="l00521"></a>00521 
+<a name="l00522"></a>00522   cpl_imagelist* obj_list=NULL;
+<a name="l00523"></a>00523   cpl_image* fake_object=NULL;
+<a name="l00524"></a>00524   <span class="keywordtype">char</span> filename[FILE_NAME_SZ];
+<a name="l00525"></a>00525   cpl_frame* frame=NULL;
+<a name="l00526"></a>00526   cpl_frame* object_frame=NULL;
+<a name="l00527"></a>00527 
+<a name="l00528"></a>00528   cpl_propertylist* plist=NULL;
+<a name="l00529"></a>00529  
+<a name="l00530"></a>00530   obj_list = cpl_imagelist_load_frameset(obj_set,CPL_TYPE_FLOAT,0,0);
+<a name="l00531"></a>00531   fake_object = cpl_imagelist_collapse_median_create(obj_list);
+<a name="l00532"></a>00532 
+<a name="l00533"></a>00533   frame = cpl_frameset_get_frame(obj_set,0);
+<a name="l00534"></a>00534   strcpy(filename,cpl_frame_get_filename(frame));
+<a name="l00535"></a>00535  
+<a name="l00536"></a>00536   <span class="keywordflow">if</span> ((cpl_error_code)((plist = cpl_propertylist_load(filename, 0)) == NULL)) {
+<a name="l00537"></a>00537     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"getting header from reference ima frame %s"</span>,filename);
+<a name="l00538"></a>00538     cpl_propertylist_delete(plist) ;
+<a name="l00539"></a>00539     <span class="keywordflow">return</span> NULL ;
+<a name="l00540"></a>00540   }
+<a name="l00541"></a>00541 
+<a name="l00542"></a>00542   <span class="keywordflow">if</span> (sinfo_propertylist_has(plist, KEY_NAME_DPR_TYPE)) {
+<a name="l00543"></a>00543     cpl_propertylist_set_string(plist, KEY_NAME_DPR_TYPE, <span class="stringliteral">"OBJECT"</span>);
+<a name="l00544"></a>00544   } <span class="keywordflow">else</span> {
+<a name="l00545"></a>00545     cpl_propertylist_append_string(plist, KEY_NAME_DPR_TYPE,<span class="stringliteral">"OBJECT"</span>) ;
+<a name="l00546"></a>00546   }
+<a name="l00547"></a>00547        
+<a name="l00548"></a>00548   <span class="keywordflow">if</span> (cpl_image_save(fake_object, <span class="stringliteral">"out_fake_object.fits"</span>, CPL_BPP_IEEE_FLOAT, 
+<a name="l00549"></a>00549                    plist,CPL_IO_DEFAULT)!=CPL_ERROR_NONE) {
+<a name="l00550"></a>00550     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Cannot save the product %s"</span>,<span class="stringliteral">"out_fake_object.fits"</span>);
+<a name="l00551"></a>00551     cpl_propertylist_delete(plist) ;
+<a name="l00552"></a>00552     <span class="keywordflow">return</span> NULL ;
+<a name="l00553"></a>00553   }
+<a name="l00554"></a>00554   cpl_propertylist_delete(plist);
+<a name="l00555"></a>00555        
+<a name="l00556"></a>00556   object_frame = cpl_frame_new() ;
+<a name="l00557"></a>00557   cpl_frame_set_filename(object_frame, <span class="stringliteral">"out_fake_object.fits"</span>) ;
+<a name="l00558"></a>00558   cpl_frame_set_tag(object_frame, <span class="stringliteral">"OBJECT"</span>) ;
+<a name="l00559"></a>00559   cpl_frame_set_type(object_frame, CPL_FRAME_TYPE_IMAGE);
+<a name="l00560"></a>00560   <span class="comment">/*</span>
+<a name="l00561"></a>00561 <span class="comment">  cpl_frame_set_group(object_frame, CPL_FRAME_GROUP_PRODUCT);</span>
+<a name="l00562"></a>00562 <span class="comment">  */</span>
+<a name="l00563"></a>00563   cpl_frame_set_level(object_frame, CPL_FRAME_LEVEL_FINAL);
+<a name="l00564"></a>00564   cpl_image_delete(fake_object);
+<a name="l00565"></a>00565   cpl_imagelist_delete(obj_list);
+<a name="l00566"></a>00566 
+<a name="l00567"></a>00567   <span class="keywordflow">return</span> object_frame;
+<a name="l00568"></a>00568 }
+<a name="l00569"></a>00569 
+<a name="l00570"></a>00570 <span class="keyword">static</span> <span class="keywordtype">void</span> 
+<a name="l00571"></a>00571 sinfo_illumcorr_config_add (cpl_parameterlist *list) 
+<a name="l00572"></a>00572 {
+<a name="l00573"></a>00573   cpl_parameter *p;
+<a name="l00574"></a>00574 
+<a name="l00575"></a>00575   <span class="keywordflow">if</span> (!list) {
+<a name="l00576"></a>00576     <span class="keywordflow">return</span>;
+<a name="l00577"></a>00577   }
+<a name="l00578"></a>00578 
+<a name="l00579"></a>00579   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.illumcorr.spec_bin"</span>,
+<a name="l00580"></a>00580                               CPL_TYPE_INT,
+<a name="l00581"></a>00581                               <span class="stringliteral">"Number of spectral planes to be combined "</span>,
+<a name="l00582"></a>00582                               <span class="stringliteral">"sinfoni.illumcorr"</span>,
+<a name="l00583"></a>00583                               100, 1, 200);
+<a name="l00584"></a>00584   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"illumcorr-spec_bin"</span>);
+<a name="l00585"></a>00585   cpl_parameterlist_append(list, p);
+<a name="l00586"></a>00586 
+<a name="l00587"></a>00587   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.illumcorr.min_flux"</span>,
+<a name="l00588"></a>00588                               CPL_TYPE_DOUBLE,
+<a name="l00589"></a>00589                               <span class="stringliteral">"Minimum flux in each spectral bin "</span>,
+<a name="l00590"></a>00590                               <span class="stringliteral">"sinfoni.illumcorr"</span>,
+<a name="l00591"></a>00591                               0.0);
+<a name="l00592"></a>00592   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"illumcorr-min_flux"</span>);
+<a name="l00593"></a>00593   cpl_parameterlist_append(list, p);
+<a name="l00594"></a>00594 
+<a name="l00595"></a>00595   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.illumcorr.center_bins"</span>,
+<a name="l00596"></a>00596                               CPL_TYPE_BOOL,
+<a name="l00597"></a>00597                               <span class="stringliteral">"Center the spectral bins at prominent "</span>
+<a name="l00598"></a>00598                               <span class="stringliteral">"emission features "</span>,
+<a name="l00599"></a>00599                               <span class="stringliteral">"sinfoni.illumcorr"</span>,
+<a name="l00600"></a>00600                               FALSE);
+<a name="l00601"></a>00601   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"illumcorr-center_bins"</span>);
+<a name="l00602"></a>00602   cpl_parameterlist_append(list, p);
+<a name="l00603"></a>00603 
+<a name="l00604"></a>00604   p = cpl_parameter_new_enum(<span class="stringliteral">"sinfoni.illumcorr.order"</span>,
+<a name="l00605"></a>00605                  CPL_TYPE_INT,
+<a name="l00606"></a>00606                  <span class="stringliteral">"The order of the polynomial to be fitted "</span>
+<a name="l00607"></a>00607                              <span class="stringliteral">"for each slitlet"</span>,
+<a name="l00608"></a>00608                  <span class="stringliteral">"sinfoni.illumcorr"</span>,
+<a name="l00609"></a>00609                  0,
+<a name="l00610"></a>00610                  2,0,1);
+<a name="l00611"></a>00611   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"illumcorr-order"</span>);
+<a name="l00612"></a>00612   cpl_parameterlist_append(list, p);
+<a name="l00613"></a>00613   
+<a name="l00614"></a>00614   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.illumcorr.sigma"</span>,
+<a name="l00615"></a>00615                               CPL_TYPE_DOUBLE,
+<a name="l00616"></a>00616                               <span class="stringliteral">"Reject n-sigma deviant pixels on each slitlet "</span>,
+<a name="l00617"></a>00617                               <span class="stringliteral">"sinfoni.illumcorr"</span>,
+<a name="l00618"></a>00618                               3.0);
+<a name="l00619"></a>00619   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"illumcorr-sigma"</span>);
+<a name="l00620"></a>00620   cpl_parameterlist_append(list, p);
+<a name="l00621"></a>00621 
+<a name="l00622"></a>00622   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.illumcorr.iterations"</span>,
+<a name="l00623"></a>00623                               CPL_TYPE_INT,
+<a name="l00624"></a>00624                               <span class="stringliteral">"Number of sigma rejection iterations to run "</span>,
+<a name="l00625"></a>00625                               <span class="stringliteral">"sinfoni.illumcorr"</span>,
+<a name="l00626"></a>00626                               3);
+<a name="l00627"></a>00627   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"illumcorr-iter"</span>);
+<a name="l00628"></a>00628   cpl_parameterlist_append(list, p);
+<a name="l00629"></a>00629 
+<a name="l00630"></a>00630   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.illumcorr.llx"</span>,
+<a name="l00631"></a>00631                               CPL_TYPE_INT,
+<a name="l00632"></a>00632                               <span class="stringliteral">"Reference region coordinates "</span>,
+<a name="l00633"></a>00633                               <span class="stringliteral">"sinfoni.illumcorr"</span>,
+<a name="l00634"></a>00634                               8, 0, 63);
+<a name="l00635"></a>00635   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"illumcorr-llx"</span>);
+<a name="l00636"></a>00636   cpl_parameterlist_append(list, p);
+<a name="l00637"></a>00637 
+<a name="l00638"></a>00638   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.illumcorr.lly"</span>,
+<a name="l00639"></a>00639                               CPL_TYPE_INT,
+<a name="l00640"></a>00640                               <span class="stringliteral">"Reference region coordinates "</span>,
+<a name="l00641"></a>00641                               <span class="stringliteral">"sinfoni.illumcorr"</span>,
+<a name="l00642"></a>00642                               33, 0, 63);
+<a name="l00643"></a>00643   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"illumcorr-lly"</span>);
+<a name="l00644"></a>00644   cpl_parameterlist_append(list, p);
+<a name="l00645"></a>00645 
+<a name="l00646"></a>00646   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.illumcorr.urx"</span>,
+<a name="l00647"></a>00647                               CPL_TYPE_INT,
+<a name="l00648"></a>00648                               <span class="stringliteral">"Reference region coordinates "</span>,
+<a name="l00649"></a>00649                               <span class="stringliteral">"sinfoni.illumcorr"</span>,
+<a name="l00650"></a>00650                               60, 0, 63);
+<a name="l00651"></a>00651   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"illumcorr-urx"</span>);
+<a name="l00652"></a>00652   cpl_parameterlist_append(list, p);
+<a name="l00653"></a>00653 
+<a name="l00654"></a>00654   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.illumcorr.ury"</span>,
+<a name="l00655"></a>00655                               CPL_TYPE_INT,
+<a name="l00656"></a>00656                               <span class="stringliteral">"Reference region coordinates "</span>,
+<a name="l00657"></a>00657                               <span class="stringliteral">"sinfoni.illumcorr"</span>,
+<a name="l00658"></a>00658                               36, 0, 63);
+<a name="l00659"></a>00659   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"illumcorr-ury"</span>);
+<a name="l00660"></a>00660   cpl_parameterlist_append(list, p);
+<a name="l00661"></a>00661 
+<a name="l00662"></a>00662   p = cpl_parameter_new_enum(<span class="stringliteral">"sinfoni.illumcorr.smooth0"</span>,
+<a name="l00663"></a>00663                  CPL_TYPE_INT,
+<a name="l00664"></a>00664                  <span class="stringliteral">"Smooth zeroth order terms by fitting "</span>
+<a name="l00665"></a>00665                              <span class="stringliteral">"with polynomial (1),"</span>
+<a name="l00666"></a>00666                  <span class="stringliteral">"with median filter (2) or not (0) "</span>,
+<a name="l00667"></a>00667                  <span class="stringliteral">"sinfoni.illumcorr"</span>,
+<a name="l00668"></a>00668                  0, 
+<a name="l00669"></a>00669                  3, 0, 1, 2);
+<a name="l00670"></a>00670   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"illumcorr-smooth0"</span>);
+<a name="l00671"></a>00671   cpl_parameterlist_append(list, p);
+<a name="l00672"></a>00672 
+<a name="l00673"></a>00673   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.illumcorr.smooth0_order"</span>,
+<a name="l00674"></a>00674                               CPL_TYPE_INT,
+<a name="l00675"></a>00675                               <span class="stringliteral">"Order of the smoothing polynomial for 0th term"</span>,
+<a name="l00676"></a>00676                               <span class="stringliteral">"sinfoni.illumcorr"</span>,
+<a name="l00677"></a>00677                               2);
+<a name="l00678"></a>00678   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"illumcorr-smooth_order0"</span>);
+<a name="l00679"></a>00679   cpl_parameterlist_append(list, p);
+<a name="l00680"></a>00680 
+<a name="l00681"></a>00681   p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.illumcorr.smooth0_size"</span>,
+<a name="l00682"></a>00682                               CPL_TYPE_INT,
+<a name="l00683"></a>00683                               <span class="stringliteral">"Size of the median filter for 0th "</span>
+<a name="l00684"></a>00684                               <span class="stringliteral">"order smoothing "</span>,
+<a name="l00685"></a>00685                               <span class="stringliteral">"sinfoni.illumcorr"</span>,
+<a name="l00686"></a>00686                               51,3, 301);
+<a name="l00687"></a>00687   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"illumcorr-smooth0_size"</span>);
+<a name="l00688"></a>00688   cpl_parameterlist_append(list, p);
+<a name="l00689"></a>00689 
+<a name="l00690"></a>00690   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.illumcorr.smooth1"</span>,
+<a name="l00691"></a>00691                               CPL_TYPE_BOOL,
+<a name="l00692"></a>00692                               <span class="stringliteral">"Smooth higher (>0) order polynomials "</span>,
+<a name="l00693"></a>00693                               <span class="stringliteral">"sinfoni.illumcorr"</span>,
+<a name="l00694"></a>00694                               TRUE);
+<a name="l00695"></a>00695   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"illumcorr-smooth"</span>);
+<a name="l00696"></a>00696   cpl_parameterlist_append(list, p);
+<a name="l00697"></a>00697 
+<a name="l00698"></a>00698   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.illumcorr.smooth1_order"</span>,
+<a name="l00699"></a>00699                               CPL_TYPE_INT,
+<a name="l00700"></a>00700                               <span class="stringliteral">"Smoothing order for higher terms "</span>,
+<a name="l00701"></a>00701                               <span class="stringliteral">"sinfoni.illumcorr"</span>,
+<a name="l00702"></a>00702                               2);
+<a name="l00703"></a>00703   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"illumcorr-smooth_order"</span>);
+<a name="l00704"></a>00704   cpl_parameterlist_append(list, p);
+<a name="l00705"></a>00705 
+<a name="l00706"></a>00706   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.illumcorr.illumcorr_sigma"</span>,
+<a name="l00707"></a>00707                               CPL_TYPE_DOUBLE,
+<a name="l00708"></a>00708                               <span class="stringliteral">"Reject all fits for which the rms is "</span>
+<a name="l00709"></a>00709                               <span class="stringliteral">"illumcorr-sigma times bigger than the "</span>
+<a name="l00710"></a>00710                               <span class="stringliteral">"median rms in each spectral bin"</span> ,
+<a name="l00711"></a>00711                               <span class="stringliteral">"sinfoni.illumcorr"</span>,
+<a name="l00712"></a>00712                               5.0);
+<a name="l00713"></a>00713   cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI,
+<a name="l00714"></a>00714                             <span class="stringliteral">"illumcorr-illumcorr_sigma"</span>);
+<a name="l00715"></a>00715   cpl_parameterlist_append(list, p);
+<a name="l00716"></a>00716 
+<a name="l00717"></a>00717 }
+<a name="l00718"></a>00718 
+<a name="l00719"></a>00719 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00720"></a>00720 create_illumcorr (<span class="keyword">const</span> <span class="keywordtype">char</span>* plugin_id,
+<a name="l00721"></a>00721           cpl_parameterlist *cpl_cfg,
+<a name="l00722"></a>00722           cpl_frameset* sof,
+<a name="l00723"></a>00723           <span class="keyword">const</span> <span class="keywordtype">char</span> *name_i)
+<a name="l00724"></a>00724 {
+<a name="l00725"></a>00725   cpl_parameter *p=NULL;
+<a name="l00726"></a>00726   <span class="keywordtype">double</span>        min_flux=0;
+<a name="l00727"></a>00727   <span class="keywordtype">double</span>        sigma=0;
+<a name="l00728"></a>00728   <span class="keywordtype">double</span>        il_sigma=0;
+<a name="l00729"></a>00729   <span class="keywordtype">int</span>           spec_bin=0;
+<a name="l00730"></a>00730   <span class="keywordtype">int</span>           _order=0;
+<a name="l00731"></a>00731   cpl_imagelist *sky=NULL;
+<a name="l00732"></a>00732   cpl_imagelist *binnedsky=NULL;
+<a name="l00733"></a>00733   cpl_imagelist *result=NULL;
+<a name="l00734"></a>00734   cpl_image     *temp_image=NULL;
+<a name="l00735"></a>00735   cpl_image     *temp_image2=NULL;
+<a name="l00736"></a>00736   <span class="keywordtype">int</span>            nplanes=0;
+<a name="l00737"></a>00737   <span class="keywordtype">int</span>            i=0;
+<a name="l00738"></a>00738   <span class="keywordtype">int</span>            j=0;
+<a name="l00739"></a>00739   <span class="keywordtype">int</span>            k=0;
+<a name="l00740"></a>00740   <span class="keywordtype">int</span>            kk=0;
+<a name="l00741"></a>00741   <span class="keywordtype">int</span>            n=0;
+<a name="l00742"></a>00742   <span class="keywordtype">int</span>            slitlet=0;
+<a name="l00743"></a>00743   <span class="keywordtype">int</span>            bin=0;
+<a name="l00744"></a>00744   <span class="keywordtype">double</span>        *median=NULL;
+<a name="l00745"></a>00745   <span class="keywordtype">double</span>        *pos=NULL;
+<a name="l00746"></a>00746   <span class="keywordtype">double</span>         temp=0;
+<a name="l00747"></a>00747   <span class="keywordtype">double</span>         temp2=0;
+<a name="l00748"></a>00748   <span class="keywordtype">double</span>        *inter_pos=NULL;
+<a name="l00749"></a>00749   <span class="keywordtype">double</span>        *inter_val=NULL;
+<a name="l00750"></a>00750   <span class="keywordtype">double</span>        *plane_pos=NULL;
+<a name="l00751"></a>00751   <span class="keywordtype">double</span>        *plane_val=NULL;
+<a name="l00752"></a>00752   <span class="keywordtype">int</span>            llx=0;
+<a name="l00753"></a>00753   <span class="keywordtype">int</span>            lly=0;
+<a name="l00754"></a>00754   <span class="keywordtype">int</span>            urx=0;
+<a name="l00755"></a>00755   <span class="keywordtype">int</span>            ury=0;
+<a name="l00756"></a>00756   <span class="keywordtype">int</span>            smooth_order=0;
+<a name="l00757"></a>00757   <span class="keywordtype">int</span>            iter=0;
+<a name="l00758"></a>00758   cpl_vector    *row=NULL;
+<a name="l00759"></a>00759   cpl_vector    *model=NULL;
+<a name="l00760"></a>00760   cpl_vector    *xpos=NULL;
+<a name="l00761"></a>00761   cpl_vector    *tempvector=NULL;
+<a name="l00762"></a>00762   cpl_vector *tempvector2=NULL;
+<a name="l00763"></a>00763   <span class="keywordtype">double</span>         mse=0.0;
+<a name="l00764"></a>00764   <span class="keywordtype">double</span>         stddev=0.0;
+<a name="l00765"></a>00765   cpl_polynomial*poly=NULL;
+<a name="l00766"></a>00766   cpl_polynomial *poly2=NULL;
+<a name="l00767"></a>00767   <span class="keywordtype">double</span>        *temparray=NULL;
+<a name="l00768"></a>00768   <span class="keywordtype">double</span>  *tempxarray=NULL;
+<a name="l00769"></a>00769   <span class="keywordtype">double</span>  * tempsarray=NULL;
+<a name="l00770"></a>00770   cpl_polynomial**coeffs=NULL;
+<a name="l00771"></a>00771   <span class="keywordtype">float</span>         *data=NULL;
+<a name="l00772"></a>00772   <span class="keywordtype">double</span>        *rms_values=NULL;
+<a name="l00773"></a>00773   <span class="keywordtype">double</span>         rms_array[32];
+<a name="l00774"></a>00774   <span class="keywordtype">int</span> smooth=0;
+<a name="l00775"></a>00775   <span class="keywordtype">int</span> smooth0=0;
+<a name="l00776"></a>00776   <span class="keywordtype">int</span> smooth_order0=0;
+<a name="l00777"></a>00777   <span class="keywordtype">int</span> smooth_size0=0;
+<a name="l00778"></a>00778   <span class="keywordtype">int</span> center_bins = 0;
+<a name="l00779"></a>00779 
+<a name="l00780"></a>00780   <span class="keywordtype">int</span> *bin_start=NULL;
+<a name="l00781"></a>00781   <span class="keywordtype">int</span> *bin_end=NULL;
+<a name="l00782"></a>00782   <span class="keywordtype">int</span> z1=0;
+<a name="l00783"></a>00783   <span class="keywordtype">int</span> z2=0;
+<a name="l00784"></a>00784   <span class="keywordtype">int</span> nbins=0;
+<a name="l00785"></a>00785 
+<a name="l00786"></a>00786   FILE          *dumpfile=NULL;
+<a name="l00787"></a>00787 
+<a name="l00788"></a>00788   <span class="keywordtype">int</span> order[32];
+<a name="l00789"></a>00789   <span class="keywordtype">int</span> ok[64];
+<a name="l00790"></a>00790   <span class="keywordtype">int</span> nbad=0;
+<a name="l00791"></a>00791 
+<a name="l00792"></a>00792 
+<a name="l00793"></a>00793   <span class="comment">/*</span>
+<a name="l00794"></a>00794 <span class="comment">   *  Get parameters</span>
+<a name="l00795"></a>00795 <span class="comment">   */</span>
+<a name="l00796"></a>00796   p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.illumcorr.spec_bin"</span>);
+<a name="l00797"></a>00797   spec_bin = cpl_parameter_get_int(p);
+<a name="l00798"></a>00798   p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.illumcorr.min_flux"</span>);
+<a name="l00799"></a>00799   min_flux =  cpl_parameter_get_double(p);
+<a name="l00800"></a>00800   p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.illumcorr.order"</span>);
+<a name="l00801"></a>00801   _order = cpl_parameter_get_int(p);
+<a name="l00802"></a>00802   p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.illumcorr.sigma"</span>);
+<a name="l00803"></a>00803   sigma = cpl_parameter_get_double(p);
+<a name="l00804"></a>00804   p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.illumcorr.llx"</span>);
+<a name="l00805"></a>00805   llx = cpl_parameter_get_int(p);
+<a name="l00806"></a>00806   p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.illumcorr.lly"</span>);
+<a name="l00807"></a>00807   lly = cpl_parameter_get_int(p);
+<a name="l00808"></a>00808   p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.illumcorr.urx"</span>);
+<a name="l00809"></a>00809   urx = cpl_parameter_get_int(p);
+<a name="l00810"></a>00810   p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.illumcorr.ury"</span>);
+<a name="l00811"></a>00811   ury = cpl_parameter_get_int(p);
+<a name="l00812"></a>00812   p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.illumcorr.illumcorr_sigma"</span>);
+<a name="l00813"></a>00813   il_sigma = cpl_parameter_get_double(p);
+<a name="l00814"></a>00814 
+<a name="l00815"></a>00815   p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.illumcorr.smooth0"</span>);
+<a name="l00816"></a>00816   smooth0 = cpl_parameter_get_int (p);
+<a name="l00817"></a>00817   p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.illumcorr.smooth0_order"</span>);
+<a name="l00818"></a>00818   smooth_order0 = cpl_parameter_get_int (p);
+<a name="l00819"></a>00819   p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.illumcorr.smooth0_size"</span>);
+<a name="l00820"></a>00820   smooth_size0 = cpl_parameter_get_int (p);
+<a name="l00821"></a>00821 
+<a name="l00822"></a>00822   p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.illumcorr.smooth1"</span>);
+<a name="l00823"></a>00823   smooth = cpl_parameter_get_bool (p);
+<a name="l00824"></a>00824   p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.illumcorr.smooth1_order"</span>);
+<a name="l00825"></a>00825   smooth_order = cpl_parameter_get_int (p);
+<a name="l00826"></a>00826 
+<a name="l00827"></a>00827   p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.illumcorr.iterations"</span>);
+<a name="l00828"></a>00828   iter = cpl_parameter_get_int (p);
+<a name="l00829"></a>00829 
+<a name="l00830"></a>00830   p = cpl_parameterlist_find(cpl_cfg, <span class="stringliteral">"sinfoni.illumcorr.center_bins"</span>);
+<a name="l00831"></a>00831   center_bins = cpl_parameter_get_bool (p);
+<a name="l00832"></a>00832 
+<a name="l00833"></a>00833 <span class="comment">/*   cpl_msg_set_level(CPL_MSG_DEBUG); */</span>
+<a name="l00834"></a>00834 
+<a name="l00835"></a>00835   <span class="comment">/*</span>
+<a name="l00836"></a>00836 <span class="comment">   *  Allocate resources</span>
+<a name="l00837"></a>00837 <span class="comment">   */</span>
+<a name="l00838"></a>00838   sky       = cpl_imagelist_load(name_i, CPL_TYPE_FLOAT, 0);
+<a name="l00839"></a>00839   nplanes   = cpl_imagelist_get_size(sky);
+<a name="l00840"></a>00840 
+<a name="l00841"></a>00841   <span class="comment">/*  Determine the start and end points of data within the </span>
+<a name="l00842"></a>00842 <span class="comment">   *  reference region  */</span>     
+<a name="l00843"></a>00843   z1 = 0;
+<a name="l00844"></a>00844   z2=nplanes -1;
+<a name="l00845"></a>00845   <span class="keywordflow">while</span> (z1<nplanes 
+<a name="l00846"></a>00846      && isnan(cpl_image_get_mean_window(cpl_imagelist_get(sky, z1),
+<a name="l00847"></a>00847                         llx, lly, urx, ury)))
+<a name="l00848"></a>00848     z1++;
+<a name="l00849"></a>00849   <span class="keywordflow">while</span> (z2>=0
+<a name="l00850"></a>00850      && isnan(cpl_image_get_mean_window(cpl_imagelist_get(sky, z2),
+<a name="l00851"></a>00851                         llx, lly, urx, ury)))
+<a name="l00852"></a>00852     z2--;
+<a name="l00853"></a>00853   z1 += 2;
+<a name="l00854"></a>00854   z2 -= 2;
+<a name="l00855"></a>00855   <span class="keywordflow">if</span> (z1>=nplanes || z2 <0 || z2<=z1) {
+<a name="l00856"></a>00856     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"Start z = %d, end z = %d"</span>, z1, z2);
+<a name="l00857"></a>00857     cpl_imagelist_delete (sky);
+<a name="l00858"></a>00858     <span class="keywordflow">return</span> (-1);
+<a name="l00859"></a>00859   }
+<a name="l00860"></a>00860   sinfo_msg (<span class="stringliteral">"Start z = %d, end z = %d"</span>, z1, z2);
+<a name="l00861"></a>00861 
+<a name="l00862"></a>00862   binnedsky = cpl_imagelist_new ();
+<a name="l00863"></a>00863   median    = (<span class="keywordtype">double</span>*) cpl_calloc(nplanes/spec_bin, <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>));
+<a name="l00864"></a>00864   pos       = (<span class="keywordtype">double</span>*) cpl_calloc(nplanes/spec_bin, <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>));
+<a name="l00865"></a>00865   temparray = (<span class="keywordtype">double</span>*) cpl_calloc(64, <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>));
+<a name="l00866"></a>00866   tempxarray= (<span class="keywordtype">double</span>*) cpl_calloc(64, <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>));
+<a name="l00867"></a>00867   tempsarray= (<span class="keywordtype">double</span>*) cpl_calloc (nplanes/spec_bin, <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>));
+<a name="l00868"></a>00868   plane_pos = (<span class="keywordtype">double</span>*) cpl_calloc (nplanes/spec_bin, <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>));
+<a name="l00869"></a>00869   plane_val = (<span class="keywordtype">double</span>*) cpl_calloc (nplanes/spec_bin, <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>));
+<a name="l00870"></a>00870   coeffs    = (cpl_polynomial**) cpl_calloc(32*(nplanes/spec_bin), 
+<a name="l00871"></a>00871                         <span class="keyword">sizeof</span>(cpl_polynomial*));
+<a name="l00872"></a>00872   rms_values= (<span class="keywordtype">double</span>*) cpl_calloc (32*(nplanes/spec_bin), <span class="keyword">sizeof</span> (double));
+<a name="l00873"></a>00873   inter_pos = (<span class="keywordtype">double</span>*) cpl_calloc (nplanes, <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>));
+<a name="l00874"></a>00874   inter_val = (<span class="keywordtype">double</span>*) cpl_calloc (nplanes, <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>));
+<a name="l00875"></a>00875 
+<a name="l00876"></a>00876   model     = cpl_vector_new(64);
+<a name="l00877"></a>00877   xpos      = cpl_vector_new(64);
+<a name="l00878"></a>00878 
+<a name="l00879"></a>00879   <span class="keywordflow">for</span> (i=0; i<64; i++)
+<a name="l00880"></a>00880     cpl_vector_set(xpos, i, (<span class="keywordtype">double</span>)(i)-((<span class="keywordtype">double</span>)urx-(<span class="keywordtype">double</span>)llx)/2.0);
+<a name="l00881"></a>00881   <span class="keywordflow">for</span> (i=0; i<nplanes; i++)
+<a name="l00882"></a>00882     inter_pos[i] = (<span class="keywordtype">double</span>)i;
+<a name="l00883"></a>00883 
+<a name="l00884"></a>00884   <span class="comment">/*</span>
+<a name="l00885"></a>00885 <span class="comment">   *  This array could be given as input file for the recipe.</span>
+<a name="l00886"></a>00886 <span class="comment">   *  Generally, 0th order fitting is sufficient (and of course</span>
+<a name="l00887"></a>00887 <span class="comment">   *  more robust), but few slitlets might require 1st order.</span>
+<a name="l00888"></a>00888 <span class="comment">   */</span>
+<a name="l00889"></a>00889   <span class="keywordflow">for</span> (i=0; i<32; i++)
+<a name="l00890"></a>00890     order[i] = _order;
+<a name="l00891"></a>00891 
+<a name="l00892"></a>00892 
+<a name="l00893"></a>00893   <span class="keywordflow">if</span> (center_bins == 1) {
+<a name="l00894"></a>00894     sinfo_msg(<span class="stringliteral">"Using centering on emission features\n"</span>);
+<a name="l00895"></a>00895     nbins = sinfo_illumcorr_create_bins (sky,llx, lly, urx, ury,
+<a name="l00896"></a>00896                      spec_bin, min_flux,
+<a name="l00897"></a>00897                      &bin_start, &bin_end,
+<a name="l00898"></a>00898                      z1, z2);
+<a name="l00899"></a>00899   }
+<a name="l00900"></a>00900   <span class="keywordflow">else</span> {
+<a name="l00901"></a>00901     sinfo_msg(<span class="stringliteral">"Using simple spectral binning - "</span>
+<a name="l00902"></a>00902           <span class="stringliteral">"not centering on emission features\n"</span>);
+<a name="l00903"></a>00903     nbins = (z2-z1)/spec_bin;
+<a name="l00904"></a>00904     bin_start = (<span class="keywordtype">int</span>*)cpl_calloc(nbins+1, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>));
+<a name="l00905"></a>00905     bin_end =  (<span class="keywordtype">int</span>*)cpl_calloc(nbins+1, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>));
+<a name="l00906"></a>00906     <span class="keywordflow">for</span> (i = 0; i<nbins; i++) {
+<a name="l00907"></a>00907       bin_start[i] = z1+i*spec_bin;
+<a name="l00908"></a>00908       bin_end[i]   = z1+(i+1)*spec_bin - 1;
+<a name="l00909"></a>00909     }
+<a name="l00910"></a>00910     <span class="keywordflow">if</span> (bin_end[nbins-1]<z2-spec_bin/10) {
+<a name="l00911"></a>00911       bin_start[nbins] = bin_end[nbins-1]+1;
+<a name="l00912"></a>00912       bin_end[nbins] = z2;
+<a name="l00913"></a>00913       nbins++;
+<a name="l00914"></a>00914     }
+<a name="l00915"></a>00915   }
+<a name="l00916"></a>00916   
+<a name="l00917"></a>00917   <span class="comment">/*</span>
+<a name="l00918"></a>00918 <span class="comment">   *  - bin the cube in spectral direction</span>
+<a name="l00919"></a>00919 <span class="comment">   *  - calculate the median (=reference value) in region </span>
+<a name="l00920"></a>00920 <span class="comment">   *    (llx,lly) - (urx,ury)</span>
+<a name="l00921"></a>00921 <span class="comment">   *  - calculate the weighted position of the each spectral bin</span>
+<a name="l00922"></a>00922 <span class="comment">   */</span>
+<a name="l00923"></a>00923   sinfo_msg(<span class="stringliteral">"Binning the cube and calculating statistics\n"</span>);
+<a name="l00924"></a>00924   <span class="keywordflow">for</span> (i=0; i<nbins; i++) {
+<a name="l00925"></a>00925     temp_image = cpl_image_duplicate(cpl_imagelist_get(sky, bin_start[i]));
+<a name="l00926"></a>00926     median[i] = sinfo_image_get_median_window (temp_image, llx, lly, urx, ury);
+<a name="l00927"></a>00927     pos[i] = median[i] * (double)bin_start[i];
+<a name="l00928"></a>00928     cpl_imagelist_set (binnedsky, temp_image, i);
+<a name="l00929"></a>00929     <span class="keywordflow">for</span> (j=bin_start[i]+1; j<bin_end[i]; j++) {
+<a name="l00930"></a>00930       temp_image2 = cpl_imagelist_get (sky, j);
+<a name="l00931"></a>00931       cpl_image_add (temp_image, temp_image2);
+<a name="l00932"></a>00932       temp = sinfo_image_get_median_window (temp_image2, llx, lly, urx, ury);
+<a name="l00933"></a>00933       median[i] = median[i] + temp;
+<a name="l00934"></a>00934       pos[i] = pos[i] + temp*(double)j;
+<a name="l00935"></a>00935     }
+<a name="l00936"></a>00936     temp2 =(double)(bin_end[i]-bin_start[i]+1);
+<a name="l00937"></a>00937     cpl_image_divide_scalar (temp_image, temp2);
+<a name="l00938"></a>00938     pos[i] = pos[i]/median[i];
+<a name="l00939"></a>00939     median[i] = median[i] / temp2;
+<a name="l00940"></a>00940     <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"median image=%g at %g"</span>,median[i], pos[i]); 
+<a name="l00941"></a>00941   }
+<a name="l00942"></a>00942   
+<a name="l00943"></a>00943   sinfo_msg(<span class="stringliteral">"Fitting slitlets between x=%d - x=%d\n"</span>, llx, urx);
+<a name="l00944"></a>00944   sinfo_msg(<span class="stringliteral">"Fitting order %d\n"</span>, _order); 
+<a name="l00945"></a>00945   <span class="keywordflow">for</span> (k=0;k<nbins; k++) {
+<a name="l00946"></a>00946     <span class="keywordflow">if</span> (median[k]>min_flux) {
+<a name="l00947"></a>00947       <span class="keywordflow">for</span> (j=0; j<32; j++) {
+<a name="l00948"></a>00948     row=cpl_vector_new_from_image_row(cpl_imagelist_get(binnedsky,k),2*j+1);
+<a name="l00949"></a>00949     n = 0;
+<a name="l00950"></a>00950     <span class="keywordflow">for</span> (i=llx; i<=urx; i++) {
+<a name="l00951"></a>00951       <span class="keywordflow">if</span> (!isnan(cpl_vector_get(row, i))) {
+<a name="l00952"></a>00952         ok[i] = 1;
+<a name="l00953"></a>00953         temparray[n]  = cpl_vector_get(row, i);
+<a name="l00954"></a>00954         tempxarray[n] = cpl_vector_get(xpos, i);
+<a name="l00955"></a>00955         n++;
+<a name="l00956"></a>00956       }
+<a name="l00957"></a>00957       <span class="keywordflow">else</span>
+<a name="l00958"></a>00958         ok[i] = 0;
+<a name="l00959"></a>00959     }
+<a name="l00960"></a>00960 
+<a name="l00961"></a>00961     <span class="comment">/* The ends of cube are always filled with NaNs => n==0*/</span>
+<a name="l00962"></a>00962     <span class="keywordflow">if</span> (n>20) {
+<a name="l00963"></a>00963       tempvector = cpl_vector_wrap (n, temparray);
+<a name="l00964"></a>00964       tempvector2= cpl_vector_wrap (n, tempxarray);
+<a name="l00965"></a>00965       poly = cpl_polynomial_fit_1d_create (tempvector2, tempvector, 
+<a name="l00966"></a>00966                                                order[j], &mse);
+<a name="l00967"></a>00967       
+<a name="l00968"></a>00968       <span class="keywordflow">if</span> (poly == NULL)
+<a name="l00969"></a>00969         sinfo_msg(<span class="stringliteral">"Fitting failed (plane %d, row %d): %s"</span>,
+<a name="l00970"></a>00970                  k, j, (<span class="keywordtype">char</span>* ) cpl_error_get_message());
+<a name="l00971"></a>00971       <span class="keywordflow">else</span> {
+<a name="l00972"></a>00972         <span class="keywordflow">if</span> (sigma>0 && iter>0) {
+<a name="l00973"></a>00973           <span class="keywordflow">for</span> (kk = 0; kk<iter; kk++) {
+<a name="l00974"></a>00974         cpl_vector_fill_polynomial (model, poly, 0.0, 1.0);
+<a name="l00975"></a>00975         cpl_vector_subtract (model, row);
+<a name="l00976"></a>00976         
+<a name="l00977"></a>00977         <span class="comment">/* Calculate stdev NaN-correctly */</span>
+<a name="l00978"></a>00978         n = 0;
+<a name="l00979"></a>00979         <span class="keywordflow">for</span> (i=llx; i<=urx; i++) 
+<a name="l00980"></a>00980           <span class="keywordflow">if</span> (ok[i] == 1) 
+<a name="l00981"></a>00981             temparray[n++]  = cpl_vector_get(model, i);
+<a name="l00982"></a>00982         stddev = cpl_vector_get_stdev(tempvector);
+<a name="l00983"></a>00983         
+<a name="l00984"></a>00984         <span class="keywordflow">for</span> (i=llx; i<=urx; i++) 
+<a name="l00985"></a>00985           <span class="keywordflow">if</span> (ok[i] == 1) 
+<a name="l00986"></a>00986             <span class="keywordflow">if</span> (fabs(cpl_vector_get(model, i))>(stddev*sigma))
+<a name="l00987"></a>00987               ok[i] = 0;
+<a name="l00988"></a>00988         
+<a name="l00989"></a>00989         
+<a name="l00990"></a>00990         n = 0;
+<a name="l00991"></a>00991         <span class="keywordflow">for</span> (i=llx; i<=urx; i++) {
+<a name="l00992"></a>00992           <span class="keywordflow">if</span> (ok[i] == 1) {
+<a name="l00993"></a>00993             temparray[n]  = cpl_vector_get(row, i);
+<a name="l00994"></a>00994             tempxarray[n] = cpl_vector_get(xpos, i);
+<a name="l00995"></a>00995             n++;
+<a name="l00996"></a>00996           }
+<a name="l00997"></a>00997         }
+<a name="l00998"></a>00998         cpl_polynomial_delete(poly);
+<a name="l00999"></a>00999         <span class="keywordflow">if</span> (n>20) {
+<a name="l01000"></a>01000           cpl_vector_unwrap (tempvector);
+<a name="l01001"></a>01001           cpl_vector_unwrap (tempvector2);
+<a name="l01002"></a>01002           tempvector = cpl_vector_wrap (n, temparray);
+<a name="l01003"></a>01003           tempvector2= cpl_vector_wrap (n, tempxarray);
+<a name="l01004"></a>01004           stddev = cpl_vector_get_stdev(tempvector);
+<a name="l01005"></a>01005           
+<a name="l01006"></a>01006           poly = cpl_polynomial_fit_1d_create (tempvector2, 
+<a name="l01007"></a>01007                                                        tempvector, 
+<a name="l01008"></a>01008                                                        order[j], &mse);
+<a name="l01009"></a>01009           <span class="keywordflow">if</span> (poly == NULL)
+<a name="l01010"></a>01010             <span class="keywordflow">break</span>;
+<a name="l01011"></a>01011         }
+<a name="l01012"></a>01012         <span class="keywordflow">else</span> {
+<a name="l01013"></a>01013           poly = NULL;
+<a name="l01014"></a>01014           <span class="keywordflow">break</span>;
+<a name="l01015"></a>01015         }
+<a name="l01016"></a>01016 <span class="comment">/*           printf ("%d %e ", n, stddev); */</span>
+<a name="l01017"></a>01017           }
+<a name="l01018"></a>01018         }
+<a name="l01019"></a>01019 
+<a name="l01020"></a>01020         <span class="keywordflow">if</span> (poly!=NULL) {
+<a name="l01021"></a>01021           coeffs[j*nbins+k] = poly;
+<a name="l01022"></a>01022           rms_values[j*nbins+k] = sqrt(mse);
+<a name="l01023"></a>01023         }
+<a name="l01024"></a>01024         <span class="keywordflow">else</span>
+<a name="l01025"></a>01025           coeffs[j*nbins+k] = NULL;
+<a name="l01026"></a>01026       }
+<a name="l01027"></a>01027       cpl_vector_unwrap (tempvector);
+<a name="l01028"></a>01028       cpl_vector_unwrap (tempvector2);
+<a name="l01029"></a>01029     }
+<a name="l01030"></a>01030     cpl_vector_delete(row);
+<a name="l01031"></a>01031       }
+<a name="l01032"></a>01032     }
+<a name="l01033"></a>01033   }
+<a name="l01034"></a>01034 
+<a name="l01035"></a>01035   <span class="comment">/*</span>
+<a name="l01036"></a>01036 <span class="comment">   *   These should (probably) be saved in a fits file...</span>
+<a name="l01037"></a>01037 <span class="comment">   */</span>
+<a name="l01038"></a>01038   sinfo_msg(<span class="stringliteral">"Writing dat out_illum.dat\n"</span>);
+<a name="l01039"></a>01039   dumpfile = fopen (<span class="stringliteral">"out_illum.dat"</span>,<span class="stringliteral">"w"</span>);
+<a name="l01040"></a>01040   fprintf (dumpfile, <span class="stringliteral">"# slitlet, pos, median, rms, coeff0, coeff1...\n"</span>);
+<a name="l01041"></a>01041   <span class="keywordflow">for</span> (slitlet = 0; slitlet<32; slitlet++)
+<a name="l01042"></a>01042     <span class="keywordflow">for</span> (bin=0; bin<nbins; bin++) {
+<a name="l01043"></a>01043       poly = coeffs[slitlet*nbins+bin];
+<a name="l01044"></a>01044       <span class="keywordflow">if</span> (poly != NULL) {
+<a name="l01045"></a>01045     fprintf (dumpfile, <span class="stringliteral">"%d %f %f %f "</span>,slitlet, pos[bin],
+<a name="l01046"></a>01046          median[bin],
+<a name="l01047"></a>01047          rms_values[slitlet*nbins+bin]);
+<a name="l01048"></a>01048     <span class="keywordflow">for</span> (i=0; i<(cpl_polynomial_get_degree(poly)+1); i++) {
+<a name="l01049"></a>01049       temp = cpl_polynomial_get_coeff (poly, &i);
+<a name="l01050"></a>01050       fprintf (dumpfile, <span class="stringliteral">"%f "</span>, temp);
+<a name="l01051"></a>01051     }
+<a name="l01052"></a>01052     fprintf (dumpfile, <span class="stringliteral">"\n"</span>);
+<a name="l01053"></a>01053       }
+<a name="l01054"></a>01054     }
+<a name="l01055"></a>01055   fclose (dumpfile);
+<a name="l01056"></a>01056 
+<a name="l01057"></a>01057   <span class="comment">/*</span>
+<a name="l01058"></a>01058 <span class="comment">   *    Remove poor fits:</span>
+<a name="l01059"></a>01059 <span class="comment">   *      - calculate the median rms of all fits</span>
+<a name="l01060"></a>01060 <span class="comment">   *      - throw away the fits whose rms is il_sigma*median_rms</span>
+<a name="l01061"></a>01061 <span class="comment">   */</span>
+<a name="l01062"></a>01062   sinfo_msg(<span class="stringliteral">"Removing poor fits - factor %f"</span>, il_sigma);
+<a name="l01063"></a>01063   n = 0;
+<a name="l01064"></a>01064   i = 0;
+<a name="l01065"></a>01065   nbad=0;
+<a name="l01066"></a>01066   sinfo_msg(<span class="stringliteral">"max loop over bin =%d"</span>,nbins);
+<a name="l01067"></a>01067   <span class="keywordflow">for</span> (bin=0; bin<nbins; bin++) {
+<a name="l01068"></a>01068     k = 0;
+<a name="l01069"></a>01069     <span class="keywordflow">for</span> (slitlet=0; slitlet<32; slitlet++)
+<a name="l01070"></a>01070       <span class="keywordflow">if</span> (coeffs[slitlet*nbins+bin] != NULL)
+<a name="l01071"></a>01071     rms_array[k++] = rms_values[slitlet*nbins+bin];
+<a name="l01072"></a>01072     <span class="keywordflow">if</span> (k>0) {
+<a name="l01073"></a>01073       <span class="comment">/* For some bizarre reason, cpl_tools_get_median_double returns </span>
+<a name="l01074"></a>01074 <span class="comment">       *  -1076245448.000000 (is that NaN?). On closer inspection,</span>
+<a name="l01075"></a>01075 <span class="comment">       * it seems to have replaced one of the numbers in array with NaN...*/</span>
+<a name="l01076"></a>01076       tempvector = cpl_vector_wrap (k, &rms_array[0]);
+<a name="l01077"></a>01077       temp = cpl_vector_get_median (tempvector);
+<a name="l01078"></a>01078       sinfo_msg(<span class="stringliteral">"median temp=%g"</span>,temp);
+<a name="l01079"></a>01079       cpl_vector_unwrap (tempvector);
+<a name="l01080"></a>01080       <span class="keywordflow">for</span> (slitlet=0; slitlet<32; slitlet++) 
+<a name="l01081"></a>01081     <span class="keywordflow">if</span> (coeffs[slitlet*nbins+bin] != NULL) {
+<a name="l01082"></a>01082       i++;
+<a name="l01083"></a>01083       <span class="keywordflow">if</span> (rms_values[slitlet*nbins+bin]>(il_sigma*temp)) {
+<a name="l01084"></a>01084         cpl_polynomial_delete(coeffs[slitlet*nbins+bin]);
+<a name="l01085"></a>01085         coeffs[slitlet*nbins+bin] = NULL;
+<a name="l01086"></a>01086         n++;
+<a name="l01087"></a>01087       }
+<a name="l01088"></a>01088     } <span class="keywordflow">else</span> {
+<a name="l01089"></a>01089           nbad++;
+<a name="l01090"></a>01090     }
+<a name="l01091"></a>01091         
+<a name="l01092"></a>01092     }
+<a name="l01093"></a>01093   }
+<a name="l01094"></a>01094   sinfo_msg(<span class="stringliteral">"Removed %d poor fits out of %d. Bad coeffs=%d"</span>, n,i,nbad);
+<a name="l01095"></a>01095 
+<a name="l01096"></a>01096   <span class="keywordflow">if</span>(smooth0 == 1) {
+<a name="l01097"></a>01097     sinfo_msg(<span class="stringliteral">"Smoothing zeroth terms (order %d)"</span>, smooth_order0);
+<a name="l01098"></a>01098     <span class="comment">/*</span>
+<a name="l01099"></a>01099 <span class="comment">     *  Since the new centering scheme will pro</span>
+<a name="l01100"></a>01100 <span class="comment">     */</span> 
+<a name="l01101"></a>01101     <span class="keywordflow">for</span> (slitlet = 0; slitlet<32; slitlet++) {
+<a name="l01102"></a>01102       k = 0;
+<a name="l01103"></a>01103       <span class="keywordflow">for</span> (bin=0; bin<nbins; bin++) {
+<a name="l01104"></a>01104     <span class="keywordflow">if</span> (coeffs[slitlet*nbins+bin] != NULL) {
+<a name="l01105"></a>01105       poly = coeffs[slitlet*nbins+bin];
+<a name="l01106"></a>01106       i = 0;
+<a name="l01107"></a>01107       temp = cpl_polynomial_get_coeff (poly, &i);
+<a name="l01108"></a>01108       plane_pos[k] = pos[bin];
+<a name="l01109"></a>01109       plane_val[k] = temp/median[bin];
+<a name="l01110"></a>01110       k++;
+<a name="l01111"></a>01111     }
+<a name="l01112"></a>01112       }
+<a name="l01113"></a>01113       <span class="keywordflow">if</span> (k>0) {
+<a name="l01114"></a>01114     tempvector = cpl_vector_wrap (k, plane_pos);
+<a name="l01115"></a>01115     tempvector2= cpl_vector_wrap (k, plane_val);
+<a name="l01116"></a>01116     poly2 = cpl_polynomial_fit_1d_create (tempvector, tempvector2, 
+<a name="l01117"></a>01117                                               smooth_order0, &mse);
+<a name="l01118"></a>01118     cpl_vector_unwrap (tempvector);
+<a name="l01119"></a>01119     cpl_vector_unwrap (tempvector2);
+<a name="l01120"></a>01120     <span class="keywordflow">for</span> (bin=0; bin<nbins; bin++) {
+<a name="l01121"></a>01121       <span class="keywordflow">if</span> (coeffs[slitlet*nbins+bin] != NULL) {
+<a name="l01122"></a>01122         poly = coeffs[slitlet*nbins+bin];
+<a name="l01123"></a>01123         i = 0;
+<a name="l01124"></a>01124         temp2 = cpl_polynomial_eval_1d (poly2, pos[bin], NULL);
+<a name="l01125"></a>01125         cpl_polynomial_set_coeff (poly, &i, temp2*median[bin]);
+<a name="l01126"></a>01126       }
+<a name="l01127"></a>01127     }
+<a name="l01128"></a>01128     cpl_polynomial_delete(poly2); 
+<a name="l01129"></a>01129       }
+<a name="l01130"></a>01130       <span class="keywordflow">else</span> 
+<a name="l01131"></a>01131     <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a> (<span class="stringliteral">"Not enough data points in slitlet %d"</span>, slitlet);
+<a name="l01132"></a>01132     }
+<a name="l01133"></a>01133   }
+<a name="l01134"></a>01134   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (smooth0 == 2) {
+<a name="l01135"></a>01135     sinfo_msg(<span class="stringliteral">"Smoothing zeroth terms (median filter size %d)"</span>, smooth_size0);
+<a name="l01136"></a>01136     smooth_size0 = smooth_size0/2;
+<a name="l01137"></a>01137     <span class="keywordflow">if</span> (smooth_size0 <= 0) smooth_size0 = 1;
+<a name="l01138"></a>01138     <span class="keywordflow">for</span> (slitlet = 0; slitlet<32; slitlet++) {
+<a name="l01139"></a>01139       k = 0;
+<a name="l01140"></a>01140       <span class="keywordflow">for</span> (bin=0; bin<nbins; bin++) {
+<a name="l01141"></a>01141     <span class="keywordflow">if</span> (coeffs[slitlet*nbins+bin] != NULL) {
+<a name="l01142"></a>01142       poly = coeffs[slitlet*nbins+bin];
+<a name="l01143"></a>01143       i = 0;
+<a name="l01144"></a>01144       temp = cpl_polynomial_get_coeff (poly, &i);
+<a name="l01145"></a>01145       <span class="comment">//plane_pos[k] = pos[bin];</span>
+<a name="l01146"></a>01146       plane_val[k] = temp/median[bin];
+<a name="l01147"></a>01147       k++;
+<a name="l01148"></a>01148     }
+<a name="l01149"></a>01149       }
+<a name="l01150"></a>01150       <span class="keywordflow">if</span> (k>0) {
+<a name="l01151"></a>01151     tempvector = cpl_vector_wrap (k, plane_val);
+<a name="l01152"></a>01152     tempvector2= sinfo_juha_vector_filter_median_create (tempvector, 
+<a name="l01153"></a>01153                                                              smooth_size0);
+<a name="l01154"></a>01154     cpl_vector_unwrap (tempvector);
+<a name="l01155"></a>01155     kk = 0;
+<a name="l01156"></a>01156     <span class="keywordflow">for</span> (bin=0; bin<nbins; bin++) {
+<a name="l01157"></a>01157       <span class="keywordflow">if</span> (coeffs[slitlet*nbins+bin] != NULL) {
+<a name="l01158"></a>01158         poly = coeffs[slitlet*nbins+bin];
+<a name="l01159"></a>01159         i = 0;
+<a name="l01160"></a>01160         cpl_polynomial_set_coeff(poly, &i, cpl_vector_get(tempvector2, kk++)
+<a name="l01161"></a>01161                       *median[bin]);
+<a name="l01162"></a>01162       }
+<a name="l01163"></a>01163     }
+<a name="l01164"></a>01164     cpl_vector_delete (tempvector2);
+<a name="l01165"></a>01165       }
+<a name="l01166"></a>01166     }
+<a name="l01167"></a>01167   }
+<a name="l01168"></a>01168 
+<a name="l01169"></a>01169   <span class="keywordflow">if</span>(smooth == 1) {
+<a name="l01170"></a>01170     sinfo_msg(<span class="stringliteral">"Smoothing higher terms (with order %d)"</span>, smooth_order);
+<a name="l01171"></a>01171     <span class="keywordflow">for</span> (slitlet = 0; slitlet<32; slitlet++) {
+<a name="l01172"></a>01172       <span class="keywordflow">if</span> (order[slitlet]>0) {
+<a name="l01173"></a>01173     <span class="keywordflow">for</span> (j=1; j<=order[slitlet]; j++) {
+<a name="l01174"></a>01174       k = 0;
+<a name="l01175"></a>01175       <span class="keywordflow">for</span> (bin=0; bin<nbins; bin++) {
+<a name="l01176"></a>01176         <span class="keywordflow">if</span> (coeffs[slitlet*nbins+bin] != NULL) {
+<a name="l01177"></a>01177           poly = coeffs[slitlet*nbins+bin];
+<a name="l01178"></a>01178           i = 0;
+<a name="l01179"></a>01179 <span class="comment">/*           temp = cpl_polynomial_get_coeff (poly, &i); */</span>
+<a name="l01180"></a>01180           temp2 = cpl_polynomial_get_coeff (poly, &j);
+<a name="l01181"></a>01181           plane_pos[k] = pos[bin];
+<a name="l01182"></a>01182           plane_val[k] = temp2/median[bin];
+<a name="l01183"></a>01183           k++;
+<a name="l01184"></a>01184         }
+<a name="l01185"></a>01185       }
+<a name="l01186"></a>01186       <span class="keywordflow">if</span> (k>0) {
+<a name="l01187"></a>01187         tempvector = cpl_vector_wrap (k, plane_pos);
+<a name="l01188"></a>01188         tempvector2= cpl_vector_wrap (k, plane_val);
+<a name="l01189"></a>01189         poly2 = cpl_polynomial_fit_1d_create (tempvector, tempvector2, 
+<a name="l01190"></a>01190                                                   smooth_order, &mse);
+<a name="l01191"></a>01191         cpl_vector_unwrap (tempvector);
+<a name="l01192"></a>01192         cpl_vector_unwrap (tempvector2);
+<a name="l01193"></a>01193         <span class="keywordflow">for</span> (bin=0; bin<nbins; bin++) {
+<a name="l01194"></a>01194           <span class="keywordflow">if</span> (coeffs[slitlet*nbins+bin] != NULL) {
+<a name="l01195"></a>01195         poly = coeffs[slitlet*nbins+bin];
+<a name="l01196"></a>01196           i = 0;
+<a name="l01197"></a>01197           <span class="comment">/*           temp = cpl_polynomial_get_coeff (poly, &i); */</span>
+<a name="l01198"></a>01198           temp2 = cpl_polynomial_eval_1d (poly2, pos[bin], NULL);
+<a name="l01199"></a>01199           cpl_polynomial_set_coeff (poly, &j, temp2*median[bin]);
+<a name="l01200"></a>01200           }
+<a name="l01201"></a>01201         }
+<a name="l01202"></a>01202         cpl_polynomial_delete(poly2); 
+<a name="l01203"></a>01203       }
+<a name="l01204"></a>01204       <span class="keywordflow">else</span> 
+<a name="l01205"></a>01205         <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a> (<span class="stringliteral">"Not enough data points in slitlet %d\n"</span>, 
+<a name="l01206"></a>01206                                slitlet);
+<a name="l01207"></a>01207     }
+<a name="l01208"></a>01208       }
+<a name="l01209"></a>01209     }
+<a name="l01210"></a>01210   }
+<a name="l01211"></a>01211 
+<a name="l01212"></a>01212   sinfo_msg(<span class="stringliteral">"Creating cube for illumination correction\n"</span>);
+<a name="l01213"></a>01213   result = cpl_imagelist_new ();
+<a name="l01214"></a>01214   <span class="keywordflow">for</span> (i=0; i<nplanes; i++) {
+<a name="l01215"></a>01215     temp_image = cpl_image_new (64, 64, CPL_TYPE_FLOAT);
+<a name="l01216"></a>01216     cpl_imagelist_set (result, temp_image, i);
+<a name="l01217"></a>01217   }
+<a name="l01218"></a>01218     
+<a name="l01219"></a>01219   sinfo_msg(<span class="stringliteral">"nplanes=%d spec_bin=%d"</span>,nplanes,spec_bin);
+<a name="l01220"></a>01220   <span class="keywordflow">if</span> ( nbins>5) {
+<a name="l01221"></a>01221     sinfo_msg(<span class="stringliteral">"Interpolating\n"</span>);
+<a name="l01222"></a>01222     <span class="keywordflow">for</span> (slitlet = 0; slitlet<32; slitlet++) {
+<a name="l01223"></a>01223       <span class="keywordflow">for</span> (i=0; i<64; i++) {
+<a name="l01224"></a>01224     k = 0;
+<a name="l01225"></a>01225     <span class="keywordflow">for</span> (bin=0; bin<nbins; bin++) {
+<a name="l01226"></a>01226       <span class="keywordflow">if</span> (coeffs[slitlet*nbins+bin] != NULL) {
+<a name="l01227"></a>01227         plane_pos[k] = pos[bin];
+<a name="l01228"></a>01228         plane_val[k] = cpl_polynomial_eval_1d(coeffs[slitlet*nbins+bin], 
+<a name="l01229"></a>01229                           cpl_vector_get(xpos, i),NULL)/
+<a name="l01230"></a>01230                                                   median[bin];
+<a name="l01231"></a>01231         k++;
+<a name="l01232"></a>01232       }
+<a name="l01233"></a>01233     }
+<a name="l01234"></a>01234         
+<a name="l01235"></a>01235     <span class="keywordflow">if</span> (k>3) {
+<a name="l01236"></a>01236       sinfo_juha_function1d_natural_spline (plane_pos, plane_val, k,
+<a name="l01237"></a>01237                          &inter_pos[(<span class="keywordtype">int</span>)plane_pos[0]],
+<a name="l01238"></a>01238                          &inter_val[(<span class="keywordtype">int</span>)plane_pos[0]],
+<a name="l01239"></a>01239                          (<span class="keywordtype">int</span>)(plane_pos[k-1]-plane_pos[0]));
+<a name="l01240"></a>01240       <span class="keywordflow">for</span> (j=0; j<=(int)plane_pos[0]; j++)
+<a name="l01241"></a>01241         inter_val[j] = inter_val[(<span class="keywordtype">int</span>)plane_pos[0]+1];
+<a name="l01242"></a>01242       <span class="keywordflow">for</span> (j=(<span class="keywordtype">int</span>)plane_pos[k-1]-1; j<nplanes; j++)
+<a name="l01243"></a>01243         inter_val[j] = inter_val[(<span class="keywordtype">int</span>)plane_pos[k-1]-2];
+<a name="l01244"></a>01244       <span class="keywordflow">for</span> (k=0; k<nplanes; k++) {
+<a name="l01245"></a>01245         data = cpl_image_get_data_float(cpl_imagelist_get(result, k));
+<a name="l01246"></a>01246         data[i + (2*slitlet)*64] = inter_val[k];
+<a name="l01247"></a>01247         data[i + (2*slitlet+1)*64] = inter_val[k];
+<a name="l01248"></a>01248             <span class="comment">/*sinfo_msg("inter_val=%g",inter_val[k]);*/</span>
+<a name="l01249"></a>01249       }
+<a name="l01250"></a>01250     }
+<a name="l01251"></a>01251     <span class="keywordflow">else</span>
+<a name="l01252"></a>01252     <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a> (<span class="stringliteral">"Too few points %d\n"</span>, slitlet);
+<a name="l01253"></a>01253       }
+<a name="l01254"></a>01254     }
+<a name="l01255"></a>01255   }
+<a name="l01256"></a>01256   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (nbins==1) {
+<a name="l01257"></a>01257     sinfo_msg(<span class="stringliteral">"Filling the illumination cube\n"</span>);
+<a name="l01258"></a>01258     <span class="keywordflow">for</span> (slitlet = 0; slitlet<32; slitlet++) {
+<a name="l01259"></a>01259       <span class="keywordflow">for</span> (i=0; i<64; i++) {
+<a name="l01260"></a>01260     <span class="keywordflow">if</span> (coeffs[slitlet] != NULL) {
+<a name="l01261"></a>01261       temp = cpl_polynomial_eval_1d(coeffs[slitlet], 
+<a name="l01262"></a>01262                     cpl_vector_get(xpos, i),NULL)/median[0];
+<a name="l01263"></a>01263       <span class="keywordflow">for</span> (k=0; k<nplanes; k++) {
+<a name="l01264"></a>01264         data = cpl_image_get_data_float(cpl_imagelist_get(result, k));
+<a name="l01265"></a>01265         data[i + (2*slitlet)*64] = temp;
+<a name="l01266"></a>01266         data[i + (2*slitlet+1)*64] = temp;
+<a name="l01267"></a>01267             sinfo_msg(<span class="stringliteral">"temp=%g"</span>,temp);
+<a name="l01268"></a>01268       }
+<a name="l01269"></a>01269     }
+<a name="l01270"></a>01270       }
+<a name="l01271"></a>01271     }
+<a name="l01272"></a>01272   } <span class="keywordflow">else</span> {
+<a name="l01273"></a>01273 
+<a name="l01274"></a>01274   }
+<a name="l01275"></a>01275 
+<a name="l01276"></a>01276 
+<a name="l01277"></a>01277   sinfo_msg(<span class="stringliteral">"Writing ima out_illum.fits\n"</span>);
+<a name="l01278"></a>01278 <span class="comment">/*   pl = cpl_propertylist_load (name_i, 0); */</span>
+<a name="l01279"></a>01279 <span class="comment">/*   if (sinfo_propertylist_has(pl, KEY_NAME_PRO_CATG)) */</span>
+<a name="l01280"></a>01280 <span class="comment">/*     cpl_propertylist_set_string (pl, KEY_NAME_PRO_CATG, PRO_ILL_COR); */</span>
+<a name="l01281"></a>01281 <span class="comment">/*   else */</span>
+<a name="l01282"></a>01282 <span class="comment">/*     cpl_propertylist_append_string (pl, KEY_NAME_PRO_CATG, PRO_ILL_COR); */</span>
+<a name="l01283"></a>01283 
+<a name="l01284"></a>01284 <span class="comment">/*  cpl_imagelist_save(result, "out_illum.fits", CPL_BPP_IEEE_FLOAT, pl, 0); */</span>
+<a name="l01285"></a>01285 
+<a name="l01286"></a>01286   sinfo_pro_save_ims(result,sof,sof,<span class="stringliteral">"out_illum.fits"</span>, 
+<a name="l01287"></a>01287               PRO_ILL_COR,NULL,plugin_id, cpl_cfg); 
+<a name="l01288"></a>01288 
+<a name="l01289"></a>01289   <span class="comment">/*</span>
+<a name="l01290"></a>01290 <span class="comment">   *   These should (probably) be saved in a fits file...</span>
+<a name="l01291"></a>01291 <span class="comment">   */</span>
+<a name="l01292"></a>01292   sinfo_msg(<span class="stringliteral">"Writing dat out_illum2.dat\n"</span>);
+<a name="l01293"></a>01293   dumpfile = fopen (<span class="stringliteral">"out_illum2.dat"</span>,<span class="stringliteral">"w"</span>);
+<a name="l01294"></a>01294   fprintf (dumpfile, <span class="stringliteral">"# slitlet, pos, median, rms, coeff0, coeff1...\n"</span>);
+<a name="l01295"></a>01295   <span class="keywordflow">for</span> (slitlet = 0; slitlet<32; slitlet++)
+<a name="l01296"></a>01296     <span class="keywordflow">for</span> (bin=0; bin<nbins; bin++) {
+<a name="l01297"></a>01297       poly = coeffs[slitlet*nbins+bin];
+<a name="l01298"></a>01298       <span class="keywordflow">if</span> (poly != NULL) {
+<a name="l01299"></a>01299     fprintf (dumpfile, <span class="stringliteral">"%d %f %f %f "</span>,slitlet, pos[bin],
+<a name="l01300"></a>01300          median[bin],
+<a name="l01301"></a>01301          rms_values[slitlet*nbins+bin]);
+<a name="l01302"></a>01302     <span class="keywordflow">for</span> (i=0; i<(cpl_polynomial_get_degree(poly)+1); i++) {
+<a name="l01303"></a>01303       temp = cpl_polynomial_get_coeff (poly, &i);
+<a name="l01304"></a>01304       fprintf (dumpfile, <span class="stringliteral">"%f "</span>, temp);
+<a name="l01305"></a>01305     }
+<a name="l01306"></a>01306     fprintf (dumpfile, <span class="stringliteral">"\n"</span>);
+<a name="l01307"></a>01307       }
+<a name="l01308"></a>01308     }
+<a name="l01309"></a>01309   fclose (dumpfile);
+<a name="l01310"></a>01310 
+<a name="l01311"></a>01311   <span class="comment">/*</span>
+<a name="l01312"></a>01312 <span class="comment">   *  Clean up...</span>
+<a name="l01313"></a>01313 <span class="comment">   */</span>
+<a name="l01314"></a>01314   <span class="keywordflow">for</span> (i = 0; i<32*nbins; i++)
+<a name="l01315"></a>01315     <span class="keywordflow">if</span> (coeffs[i] != NULL)
+<a name="l01316"></a>01316       cpl_polynomial_delete(coeffs[i]);
+<a name="l01317"></a>01317   cpl_imagelist_delete (sky);
+<a name="l01318"></a>01318   cpl_imagelist_delete (binnedsky);
+<a name="l01319"></a>01319   cpl_imagelist_delete (result);
+<a name="l01320"></a>01320   cpl_free (pos);
+<a name="l01321"></a>01321   cpl_free (median);
+<a name="l01322"></a>01322   cpl_free (temparray);
+<a name="l01323"></a>01323   cpl_free (tempxarray);
+<a name="l01324"></a>01324   cpl_free (tempsarray);
+<a name="l01325"></a>01325   cpl_free (coeffs);
+<a name="l01326"></a>01326   cpl_free (inter_pos);
+<a name="l01327"></a>01327   cpl_free (inter_val);
+<a name="l01328"></a>01328   cpl_free (plane_pos);
+<a name="l01329"></a>01329   cpl_free (plane_val);
+<a name="l01330"></a>01330   cpl_free (rms_values);
+<a name="l01331"></a>01331   cpl_vector_delete (xpos);
+<a name="l01332"></a>01332   cpl_vector_delete (model);
+<a name="l01333"></a>01333 
+<a name="l01334"></a>01334   cpl_free (bin_start);
+<a name="l01335"></a>01335   cpl_free (bin_end);
+<a name="l01336"></a>01336 
+<a name="l01337"></a>01337   <span class="keywordflow">return</span> (1);
+<a name="l01338"></a>01338 }
+<a name="l01339"></a>01339 
+<a name="l01340"></a>01340 <span class="comment">/*</span>
+<a name="l01341"></a>01341 <span class="comment"> *  sinfo_illumcorr_create_bins:</span>
+<a name="l01342"></a>01342 <span class="comment"> *    - searches for the sky emission lines</span>
+<a name="l01343"></a>01343 <span class="comment"> *    - increases the size of the bin to include two or more emission</span>
+<a name="l01344"></a>01344 <span class="comment"> *      lines if they are too close to each other</span>
+<a name="l01345"></a>01345 <span class="comment"> *    - fills the space between emission lines with bins if</span>
+<a name="l01346"></a>01346 <span class="comment"> *      thermal background has enough flux</span>
+<a name="l01347"></a>01347 <span class="comment"> *    - copies the start and end points of bins to two arrays</span>
+<a name="l01348"></a>01348 <span class="comment"> *      (returned in **start and **end)</span>
+<a name="l01349"></a>01349 <span class="comment"> *</span>
+<a name="l01350"></a>01350 <span class="comment"> *  Returns: the number bins created</span>
+<a name="l01351"></a>01351 <span class="comment"> *</span>
+<a name="l01352"></a>01352 <span class="comment"> *  The arrays start and end must be deallocated with cpl_free()</span>
+<a name="l01353"></a>01353 <span class="comment"> */</span>
+<a name="l01354"></a>01354 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l01355"></a>01355 sinfo_illumcorr_create_bins (cpl_imagelist *sky, 
+<a name="l01356"></a>01356                  <span class="keywordtype">int</span> llx, <span class="keywordtype">int</span> lly, <span class="keywordtype">int</span> urx, <span class="keywordtype">int</span> ury,
+<a name="l01357"></a>01357                  <span class="keywordtype">int</span> spec_bin, 
+<a name="l01358"></a>01358                  <span class="keywordtype">double</span> min_flux,
+<a name="l01359"></a>01359                  <span class="keywordtype">int</span> ** start,
+<a name="l01360"></a>01360                  <span class="keywordtype">int</span> ** end,
+<a name="l01361"></a>01361                  <span class="keywordtype">int</span> z1, <span class="keywordtype">int</span> z2)
+<a name="l01362"></a>01362 {
+<a name="l01363"></a>01363   <span class="keywordtype">int</span> temp_i=0;
+<a name="l01364"></a>01364   <span class="keywordtype">double</span> testarray3[15];
+<a name="l01365"></a>01365   <span class="keywordtype">double</span> temp_double=0;
+<a name="l01366"></a>01366   <span class="keywordtype">int</span>  i=0, j=0, k=0,kk=0,nplanes=0; 
+<a name="l01367"></a>01367 
+<a name="l01368"></a>01368   <span class="keywordtype">int</span> norig = 0, nmerged = 0, ncont = 0, nline=0;
+<a name="l01369"></a>01369 
+<a name="l01370"></a>01370   <span class="keywordtype">int</span> *pos=NULL;
+<a name="l01371"></a>01371   <span class="keywordtype">int</span> *x1=NULL;
+<a name="l01372"></a>01372   <span class="keywordtype">int</span> *x2=NULL;
+<a name="l01373"></a>01373   <span class="keywordtype">int</span> *x1b=NULL;
+<a name="l01374"></a>01374   <span class="keywordtype">int</span> *x2b=NULL;
+<a name="l01375"></a>01375   <span class="keywordtype">int</span> *s1=NULL;
+<a name="l01376"></a>01376   <span class="keywordtype">int</span> *s2=NULL;
+<a name="l01377"></a>01377   <span class="keywordtype">double</span> *flux=NULL;
+<a name="l01378"></a>01378   <span class="keywordtype">double</span> *spec=NULL;
+<a name="l01379"></a>01379   <span class="keywordtype">double</span>  *spec_cont=NULL;
+<a name="l01380"></a>01380   <span class="keywordtype">double</span> *spec_line=NULL;
+<a name="l01381"></a>01381 
+<a name="l01382"></a>01382 
+<a name="l01383"></a>01383   cpl_image     *temp_image=NULL;
+<a name="l01384"></a>01384 
+<a name="l01385"></a>01385   nplanes   = cpl_imagelist_get_size(sky);
+<a name="l01386"></a>01386 
+<a name="l01387"></a>01387   spec = (<span class="keywordtype">double</span>*) cpl_calloc(nplanes, <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>));
+<a name="l01388"></a>01388   spec_line = (<span class="keywordtype">double</span>*) cpl_calloc(nplanes, <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>));
+<a name="l01389"></a>01389   spec_cont = (<span class="keywordtype">double</span>*) cpl_calloc(nplanes, <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>));
+<a name="l01390"></a>01390 
+<a name="l01391"></a>01391   <span class="comment">/*  there should be no way of actually needing this large arrays*/</span>
+<a name="l01392"></a>01392   pos = (<span class="keywordtype">int</span>*) cpl_calloc(nplanes, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>));
+<a name="l01393"></a>01393   flux = (<span class="keywordtype">double</span>*) cpl_calloc(nplanes, <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>));
+<a name="l01394"></a>01394   x1 = (<span class="keywordtype">int</span>*) cpl_calloc(nplanes, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>));
+<a name="l01395"></a>01395   x2 = (<span class="keywordtype">int</span>*) cpl_calloc(nplanes, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>));
+<a name="l01396"></a>01396   x1b = (<span class="keywordtype">int</span>*) cpl_calloc(nplanes, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>));
+<a name="l01397"></a>01397   x2b = (<span class="keywordtype">int</span>*) cpl_calloc(nplanes, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>));
+<a name="l01398"></a>01398 
+<a name="l01399"></a>01399   <span class="keywordflow">for</span> (i=z1; i<=z2; i++) {
+<a name="l01400"></a>01400     temp_image =  cpl_imagelist_get(sky, i);
+<a name="l01401"></a>01401     spec[i] = sinfo_image_get_median_window (temp_image, llx, lly, urx, ury);
+<a name="l01402"></a>01402   }
+<a name="l01403"></a>01403   <span class="keywordflow">for</span> (i=z1+7; i<=z2-7; i++) {
+<a name="l01404"></a>01404     k = 0;
+<a name="l01405"></a>01405     <span class="keywordflow">for</span> (j=-7; j<=7; j++)
+<a name="l01406"></a>01406       <span class="keywordflow">if</span> (!isnan(spec[i+j]))
+<a name="l01407"></a>01407     testarray3[k++] = spec[i+j];
+<a name="l01408"></a>01408     <span class="keywordflow">if</span> (k>0) {
+<a name="l01409"></a>01409       sinfo_tools_sort_double (&testarray3[0], k);
+<a name="l01410"></a>01410       spec_cont[i] =  testarray3[1];
+<a name="l01411"></a>01411     }
+<a name="l01412"></a>01412     <span class="keywordflow">else</span>
+<a name="l01413"></a>01413       spec_cont[i] =  0./0.;
+<a name="l01414"></a>01414   }
+<a name="l01415"></a>01415 
+<a name="l01416"></a>01416   <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"Calculating pure line flux at pos: "</span>
+<a name="l01417"></a>01417                   <span class="stringliteral">"original, continuum, line"</span>);
+<a name="l01418"></a>01418   <span class="keywordflow">for</span> (i=z1; i<=z2; i++) {
+<a name="l01419"></a>01419     spec_line[i] = spec[i] - spec_cont[i];
+<a name="l01420"></a>01420     <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a>(<span class="stringliteral">"Flux at %i = %g %g %g"</span>,
+<a name="l01421"></a>01421                      i,spec[i],spec_cont[i], spec_line[i]);   
+<a name="l01422"></a>01422   }
+<a name="l01423"></a>01423 
+<a name="l01424"></a>01424 
+<a name="l01425"></a>01425   <span class="comment">/*</span>
+<a name="l01426"></a>01426 <span class="comment">   *  Search for peaks</span>
+<a name="l01427"></a>01427 <span class="comment">   */</span>  
+<a name="l01428"></a>01428   sinfo_msg (<span class="stringliteral">"Searching for peaks"</span>);
+<a name="l01429"></a>01429   temp_double = -10000.0;
+<a name="l01430"></a>01430   i = z1+2; 
+<a name="l01431"></a>01431   <span class="keywordflow">while</span> (i<=z2-2) {
+<a name="l01432"></a>01432     <span class="keywordflow">if</span> (!isnan (spec_line[i])) {
+<a name="l01433"></a>01433       <span class="keywordflow">if</span> (temp_double<spec_line[i]) {
+<a name="l01434"></a>01434         temp_i = i;
+<a name="l01435"></a>01435         temp_double = spec_line[i];
+<a name="l01436"></a>01436       }
+<a name="l01437"></a>01437       <span class="keywordflow">else</span> {
+<a name="l01438"></a>01438         <span class="comment">/*  Found a peak! */</span> 
+<a name="l01439"></a>01439         <span class="keywordflow">if</span> (temp_i == i-1 && spec_line[temp_i]>min_flux) {
+<a name="l01440"></a>01440       k = 0;
+<a name="l01441"></a>01441       <span class="keywordflow">for</span> (j=-spec_bin/2; j<=spec_bin/2; j++) 
+<a name="l01442"></a>01442         <span class="keywordflow">if</span> (j+i>=0 && i+j<nplanes && isnan(spec[i+j])) {
+<a name="l01443"></a>01443           k = 1;
+<a name="l01444"></a>01444           <span class="keywordflow">break</span>;
+<a name="l01445"></a>01445         }
+<a name="l01446"></a>01446       <span class="keywordflow">if</span> (k==0) {
+<a name="l01447"></a>01447         pos[norig] = temp_i; <span class="comment">// - spec_bin/2;</span>
+<a name="l01448"></a>01448         flux[norig]   = temp_double;
+<a name="l01449"></a>01449         x1[norig] = temp_i;
+<a name="l01450"></a>01450         x2[norig] = temp_i;
+<a name="l01451"></a>01451         temp_double = -10000.0; 
+<a name="l01452"></a>01452         <span class="keywordflow">while</span> (spec_line[i]<spec_line[i-1])
+<a name="l01453"></a>01453           i++;
+<a name="l01454"></a>01454         i--;
+<a name="l01455"></a>01455         norig++;
+<a name="l01456"></a>01456       }
+<a name="l01457"></a>01457         }
+<a name="l01458"></a>01458       }
+<a name="l01459"></a>01459     }      
+<a name="l01460"></a>01460     i++;
+<a name="l01461"></a>01461   }
+<a name="l01462"></a>01462 
+<a name="l01463"></a>01463   <span class="comment">/*</span>
+<a name="l01464"></a>01464 <span class="comment">   *   Merge the features which are too close to each other</span>
+<a name="l01465"></a>01465 <span class="comment">   */</span>
+<a name="l01466"></a>01466   sinfo_msg (<span class="stringliteral">"Merging emission features too close to each other"</span>);
+<a name="l01467"></a>01467   i = 0;
+<a name="l01468"></a>01468   <span class="keywordflow">while</span> (i<norig) {
+<a name="l01469"></a>01469     <span class="keywordflow">if</span> (flux[i] > 0.0) {
+<a name="l01470"></a>01470       j = i+1;
+<a name="l01471"></a>01471       <span class="keywordflow">while</span> (j<norig 
+<a name="l01472"></a>01472          && (x1[j]-x2[i]) <=spec_bin 
+<a name="l01473"></a>01473          && flux[j]>0.0) {
+<a name="l01474"></a>01474     flux[j] = -100.0;
+<a name="l01475"></a>01475     x2[i] = x1[j];
+<a name="l01476"></a>01476     j++;
+<a name="l01477"></a>01477     nmerged++;
+<a name="l01478"></a>01478       }
+<a name="l01479"></a>01479     }
+<a name="l01480"></a>01480     i++;
+<a name="l01481"></a>01481   }
+<a name="l01482"></a>01482 
+<a name="l01483"></a>01483   nline = norig - nmerged;
+<a name="l01484"></a>01484 
+<a name="l01485"></a>01485   j = 0;
+<a name="l01486"></a>01486   <span class="keywordflow">for</span> (i=0; i<norig; i++)
+<a name="l01487"></a>01487     <span class="keywordflow">if</span> (flux[i]>0.0) {
+<a name="l01488"></a>01488       x1b[j] = x1[i] - spec_bin/2;
+<a name="l01489"></a>01489       x2b[j] = x2[i] + spec_bin/2;
+<a name="l01490"></a>01490       j++;
+<a name="l01491"></a>01491       <span class="comment">/* sinfo_msg ("Bin start: %i end %i", x1[i], x2[i]); */</span>
+<a name="l01492"></a>01492     }
+<a name="l01493"></a>01493 
+<a name="l01494"></a>01494   x1b[j] = nplanes+1;
+<a name="l01495"></a>01495 
+<a name="l01496"></a>01496   <span class="comment">/*</span>
+<a name="l01497"></a>01497 <span class="comment">   *  Check whether there is enough continuum (thermal background)</span>
+<a name="l01498"></a>01498 <span class="comment">   *  for binning</span>
+<a name="l01499"></a>01499 <span class="comment">   */</span>
+<a name="l01500"></a>01500   j=0;
+<a name="l01501"></a>01501   i=z1;
+<a name="l01502"></a>01502   <span class="keywordflow">while</span> (i<=z2) {
+<a name="l01503"></a>01503     <span class="keywordflow">if</span> (!isnan (spec[i])) {
+<a name="l01504"></a>01504       <span class="keywordflow">if</span> (x1b[j]-i < spec_bin) {
+<a name="l01505"></a>01505     i = x2b[j]+1;
+<a name="l01506"></a>01506     j++;
+<a name="l01507"></a>01507       }
+<a name="l01508"></a>01508       <span class="keywordflow">else</span> {
+<a name="l01509"></a>01509     kk = 0;
+<a name="l01510"></a>01510     <span class="keywordflow">for</span> (k=0; k<spec_bin; k++) 
+<a name="l01511"></a>01511       <span class="keywordflow">if</span> (spec[i+k]>min_flux)
+<a name="l01512"></a>01512         kk++;
+<a name="l01513"></a>01513     <span class="keywordflow">if</span> (kk==spec_bin) {
+<a name="l01514"></a>01514       x1[ncont] = i;
+<a name="l01515"></a>01515       x2[ncont] = i+spec_bin-1;
+<a name="l01516"></a>01516       ncont++;
+<a name="l01517"></a>01517       i = i+spec_bin;
+<a name="l01518"></a>01518     }
+<a name="l01519"></a>01519     <span class="keywordflow">else</span>
+<a name="l01520"></a>01520       i++;
+<a name="l01521"></a>01521       }
+<a name="l01522"></a>01522     }
+<a name="l01523"></a>01523     <span class="keywordflow">else</span> 
+<a name="l01524"></a>01524       i++;
+<a name="l01525"></a>01525   }
+<a name="l01526"></a>01526 
+<a name="l01527"></a>01527   sinfo_msg (<span class="stringliteral">"Number of bins centered on emission features:"</span>);
+<a name="l01528"></a>01528   sinfo_msg (<span class="stringliteral">"  %i - %i (merged) = %i"</span>, norig, nmerged, nline);
+<a name="l01529"></a>01529   sinfo_msg (<span class="stringliteral">"  %i continuum bins"</span>, ncont);
+<a name="l01530"></a>01530 
+<a name="l01531"></a>01531   s1 = (<span class="keywordtype">int</span>*)cpl_calloc(norig-nmerged+ncont, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>));
+<a name="l01532"></a>01532   s2 = (<span class="keywordtype">int</span>*)cpl_calloc(norig-nmerged+ncont, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>));
+<a name="l01533"></a>01533 
+<a name="l01534"></a>01534 
+<a name="l01535"></a>01535   <span class="comment">/* </span>
+<a name="l01536"></a>01536 <span class="comment">   *  Merge arrays sorted </span>
+<a name="l01537"></a>01537 <span class="comment">   */</span>
+<a name="l01538"></a>01538   i=0;
+<a name="l01539"></a>01539   j=0;
+<a name="l01540"></a>01540   k=0;
+<a name="l01541"></a>01541   <span class="keywordflow">while</span> (k<norig-nmerged+ncont) {
+<a name="l01542"></a>01542     <span class="keywordflow">if</span> (i<norig && j<ncont && x1b[i]<x1[j]) {
+<a name="l01543"></a>01543       s1[k] = x1b[i];
+<a name="l01544"></a>01544       s2[k] = x2b[i];
+<a name="l01545"></a>01545       k++;
+<a name="l01546"></a>01546       i++;
+<a name="l01547"></a>01547     }
+<a name="l01548"></a>01548     <span class="keywordflow">else</span> <span class="keywordflow">if</span> (i<norig && j<ncont && x1b[i]>x1[j]) {
+<a name="l01549"></a>01549       s1[k] = x1[j];
+<a name="l01550"></a>01550       s2[k] = x2[j];
+<a name="l01551"></a>01551       k++;
+<a name="l01552"></a>01552       j++;
+<a name="l01553"></a>01553     }
+<a name="l01554"></a>01554     <span class="keywordflow">else</span> <span class="keywordflow">if</span> (i == norig) {
+<a name="l01555"></a>01555       s1[k] = x1[j];
+<a name="l01556"></a>01556       s2[k] = x2[j];
+<a name="l01557"></a>01557       k++;
+<a name="l01558"></a>01558       j++;
+<a name="l01559"></a>01559     }
+<a name="l01560"></a>01560     <span class="keywordflow">else</span> <span class="keywordflow">if</span> (j == ncont) {
+<a name="l01561"></a>01561       s1[k] = x1b[i];
+<a name="l01562"></a>01562       s2[k] = x2b[i];
+<a name="l01563"></a>01563       k++;
+<a name="l01564"></a>01564       i++;
+<a name="l01565"></a>01565     }
+<a name="l01566"></a>01566     <span class="keywordflow">else</span> {
+<a name="l01567"></a>01567       <span class="comment">/* Should never happen */</span>
+<a name="l01568"></a>01568       <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"Something went wrong when combining "</span>
+<a name="l01569"></a>01569                         <span class="stringliteral">"the bins %i and %i"</span>, i,j);
+<a name="l01570"></a>01570       <span class="keywordflow">break</span>;
+<a name="l01571"></a>01571     }
+<a name="l01572"></a>01572   }
+<a name="l01573"></a>01573 
+<a name="l01574"></a>01574   <span class="keywordflow">for</span> (i=0; i<nline+ncont; i++)
+<a name="l01575"></a>01575     <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a> (<span class="stringliteral">"Bin start: %i end %i"</span>, s1[i], s2[i]);
+<a name="l01576"></a>01576 
+<a name="l01577"></a>01577   *start = s1;
+<a name="l01578"></a>01578   *end   = s2;
+<a name="l01579"></a>01579 
+<a name="l01580"></a>01580   cpl_free (pos);
+<a name="l01581"></a>01581   cpl_free (x1);
+<a name="l01582"></a>01582   cpl_free (x2);
+<a name="l01583"></a>01583   cpl_free (x1b);
+<a name="l01584"></a>01584   cpl_free (x2b);
+<a name="l01585"></a>01585   cpl_free (flux);
+<a name="l01586"></a>01586   cpl_free (spec);
+<a name="l01587"></a>01587   cpl_free (spec_line);
+<a name="l01588"></a>01588   cpl_free (spec_cont);
+<a name="l01589"></a>01589 
+<a name="l01590"></a>01590   <span class="keywordflow">return</span> (nline+ncont);
+<a name="l01591"></a>01591 }
+<a name="l01592"></a>01592 
+<a name="l01593"></a>01593 
+<a name="l01594"></a>01594 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l01621"></a>01621 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l01622"></a>01622 
+<a name="l01623"></a>01623 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l01624"></a>01624 sinfo_juha_function1d_natural_spline(
+<a name="l01625"></a>01625     <span class="keywordtype">double</span>  *      x,
+<a name="l01626"></a>01626     <span class="keywordtype">double</span>  *      y,
+<a name="l01627"></a>01627     <span class="keywordtype">int</span>            len,
+<a name="l01628"></a>01628     <span class="keywordtype">double</span>  *      splX,
+<a name="l01629"></a>01629     <span class="keywordtype">double</span>  *      splY,
+<a name="l01630"></a>01630     <span class="keywordtype">int</span>            splLen
+<a name="l01631"></a>01631 )
+<a name="l01632"></a>01632 {
+<a name="l01633"></a>01633   <span class="keywordtype">int</span>                         end;
+<a name="l01634"></a>01634   <span class="keywordtype">int</span>                         loc, found;
+<a name="l01635"></a>01635   <span class="keyword">register</span> <span class="keywordtype">int</span>        i, j, n;
+<a name="l01636"></a>01636   <span class="keywordtype">double</span>              *       h;      <span class="comment">/* vector of deltas in x */</span>
+<a name="l01637"></a>01637   <span class="keywordtype">double</span>              *       alpha;
+<a name="l01638"></a>01638   <span class="keywordtype">double</span>              *       l,
+<a name="l01639"></a>01639     *       mu,
+<a name="l01640"></a>01640     *       z,
+<a name="l01641"></a>01641     *       a,
+<a name="l01642"></a>01642     *       b,
+<a name="l01643"></a>01643     *       c,
+<a name="l01644"></a>01644     *       d,
+<a name="l01645"></a>01645     v;
+<a name="l01646"></a>01646 
+<a name="l01647"></a>01647   end = len - 1;
+<a name="l01648"></a>01648   
+<a name="l01649"></a>01649   a = cpl_malloc(<span class="keyword">sizeof</span>(<span class="keywordtype">double</span>) * splLen * 9) ;
+<a name="l01650"></a>01650   b = a + len;
+<a name="l01651"></a>01651   c = b + len;
+<a name="l01652"></a>01652   d = c + len;
+<a name="l01653"></a>01653   h = d + len;
+<a name="l01654"></a>01654   l = h + len;
+<a name="l01655"></a>01655   z = l + len;
+<a name="l01656"></a>01656   mu = z + len;
+<a name="l01657"></a>01657   alpha = mu + len;
+<a name="l01658"></a>01658   
+<a name="l01659"></a>01659   <span class="keywordflow">for</span> (i = 0; i < len; i++) {
+<a name="l01660"></a>01660     a[i] = (double)y[i];
+<a name="l01661"></a>01661   }
+<a name="l01662"></a>01662   
+<a name="l01663"></a>01663   <span class="comment">/* Calculate vector of differences */</span>
+<a name="l01664"></a>01664   <span class="keywordflow">for</span> (i = 0; i < end; i++) {
+<a name="l01665"></a>01665     h[i] = (double)x[i + 1] - (<span class="keywordtype">double</span>)x[i];
+<a name="l01666"></a>01666     <span class="keywordflow">if</span> (h[i] < 0.0) {
+<a name="l01667"></a>01667       cpl_free(a) ;
+<a name="l01668"></a>01668       <span class="keywordflow">return</span> -1;
+<a name="l01669"></a>01669     }
+<a name="l01670"></a>01670   }
+<a name="l01671"></a>01671   
+<a name="l01672"></a>01672   <span class="comment">/* Calculate alpha vector */</span>
+<a name="l01673"></a>01673   <span class="keywordflow">for</span> (n = 0, i = 1; i < end; i++, n++) {
+<a name="l01674"></a>01674     <span class="comment">/* n = i - 1 */</span>
+<a name="l01675"></a>01675     alpha[i] = 3.0 * ((a[i+1] / h[i]) - (a[i] / h[n]) - (a[i] / h[i]) +
+<a name="l01676"></a>01676               (a[n] / h[n]));
+<a name="l01677"></a>01677   }
+<a name="l01678"></a>01678   
+<a name="l01679"></a>01679   <span class="comment">/* Vectors to solve the tridiagonal matrix */</span>
+<a name="l01680"></a>01680   l[0] = l[end] = 1.0;
+<a name="l01681"></a>01681   mu[0] = mu[end] = 0.0;
+<a name="l01682"></a>01682   z[0] = z[end] = 0.0;
+<a name="l01683"></a>01683   c[0] = c[end] = 0.0;
+<a name="l01684"></a>01684   
+<a name="l01685"></a>01685   <span class="comment">/* Calculate the intermediate results */</span>
+<a name="l01686"></a>01686   <span class="keywordflow">for</span> (n = 0, i = 1; i < end; i++, n++) {
+<a name="l01687"></a>01687     <span class="comment">/* n = i-1 */</span>
+<a name="l01688"></a>01688     l[i] = 2 * (h[i] + h[n]) - h[n] * mu[n];
+<a name="l01689"></a>01689     mu[i] = h[i] / l[i];
+<a name="l01690"></a>01690     z[i] = (alpha[i] - h[n] * z[n]) / l[i];
+<a name="l01691"></a>01691   }
+<a name="l01692"></a>01692   <span class="keywordflow">for</span> (n = end, j = end - 1; j >= 0; j--, n--) {
+<a name="l01693"></a>01693     <span class="comment">/* n = j + 1 */</span>
+<a name="l01694"></a>01694     c[j] = z[j] - mu[j] * c[n];
+<a name="l01695"></a>01695     b[j] = (a[n] - a[j]) / h[j] - h[j] * (c[n] + 2.0 * c[j]) / 3.0;
+<a name="l01696"></a>01696     d[j] = (c[n] - c[j]) / (3.0 * h[j]);
+<a name="l01697"></a>01697   }
+<a name="l01698"></a>01698   
+<a name="l01699"></a>01699   <span class="comment">/* Now calculate the new values */</span>
+<a name="l01700"></a>01700   <span class="keywordflow">for</span> (j = 0; j < splLen; j++) {
+<a name="l01701"></a>01701     v = (double)splX[j];
+<a name="l01702"></a>01702     splY[j] = (float)0;
+<a name="l01703"></a>01703     
+<a name="l01704"></a>01704     <span class="comment">/* Is it outside the interval? */</span>
+<a name="l01705"></a>01705     <span class="keywordflow">if</span> ((v < (<span class="keywordtype">double</span>)x[0]) || (v > (<span class="keywordtype">double</span>)x[end])) {
+<a name="l01706"></a>01706       <span class="keywordflow">continue</span>;
+<a name="l01707"></a>01707     }
+<a name="l01708"></a>01708     <span class="comment">/* Search for the interval containing v in the x vector */</span>
+<a name="l01709"></a>01709     loc = sinfo_function1d_search_value(x, len, (<span class="keywordtype">double</span>)v, &found);
+<a name="l01710"></a>01710     <span class="keywordflow">if</span> (found) {
+<a name="l01711"></a>01711       splY[j] = y[loc];
+<a name="l01712"></a>01712     } <span class="keywordflow">else</span> {
+<a name="l01713"></a>01713       loc--;
+<a name="l01714"></a>01714       v -= (double)x[loc];
+<a name="l01715"></a>01715       splY[j] = (float)( a[loc] + v * (b[loc] + v * (c[loc] + v * d[loc])));
+<a name="l01716"></a>01716     }
+<a name="l01717"></a>01717   }
+<a name="l01718"></a>01718   cpl_free(a) ;
+<a name="l01719"></a>01719   <span class="keywordflow">return</span> 0;
+<a name="l01720"></a>01720 }
+<a name="l01721"></a>01721 
+<a name="l01722"></a>01722 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l01738"></a>01738 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l01739"></a>01739 
+<a name="l01740"></a>01740 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l01741"></a>01741 sinfo_function1d_search_value(
+<a name="l01742"></a>01742     <span class="keywordtype">double</span>  *       x,
+<a name="l01743"></a>01743     <span class="keywordtype">int</span>             len,
+<a name="l01744"></a>01744     <span class="keywordtype">double</span>          key,
+<a name="l01745"></a>01745     <span class="keywordtype">int</span>     *       foundPtr
+<a name="l01746"></a>01746 )
+<a name="l01747"></a>01747 {
+<a name="l01748"></a>01748     <span class="keywordtype">int</span> high,
+<a name="l01749"></a>01749                 low,
+<a name="l01750"></a>01750                 middle;
+<a name="l01751"></a>01751 
+<a name="l01752"></a>01752     low  = 0;
+<a name="l01753"></a>01753     high = len - 1;
+<a name="l01754"></a>01754 
+<a name="l01755"></a>01755     <span class="keywordflow">while</span> (high >= low) {
+<a name="l01756"></a>01756       middle = (high + low) / 2;
+<a name="l01757"></a>01757       <span class="keywordflow">if</span> (key > x[middle]) {
+<a name="l01758"></a>01758     low = middle + 1;
+<a name="l01759"></a>01759       } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (key < x[middle]) {
+<a name="l01760"></a>01760     high = middle - 1;
+<a name="l01761"></a>01761       } <span class="keywordflow">else</span> {
+<a name="l01762"></a>01762     *foundPtr = 1;
+<a name="l01763"></a>01763     <span class="keywordflow">return</span> (middle);
+<a name="l01764"></a>01764       }
+<a name="l01765"></a>01765     }
+<a name="l01766"></a>01766     *foundPtr = 0;
+<a name="l01767"></a>01767     <span class="keywordflow">return</span> (low);
+<a name="l01768"></a>01768 }
+<a name="l01769"></a>01769 
+<a name="l01770"></a>01770 
+<a name="l01771"></a>01771 <span class="comment">/*</span>
+<a name="l01772"></a>01772 <span class="comment">cpl_vector * sinfo_vector_filter_median_create(</span>
+<a name="l01773"></a>01773 <span class="comment">        const cpl_vector * v, </span>
+<a name="l01774"></a>01774 <span class="comment">        int                hw)</span>
+<a name="l01775"></a>01775 <span class="comment">{</span>
+<a name="l01776"></a>01776 <span class="comment">    cpl_vector * filtered;</span>
+<a name="l01777"></a>01777 <span class="comment">    double     * row;</span>
+<a name="l01778"></a>01778 <span class="comment">    int          i, j, k, size;</span>
+<a name="l01779"></a>01779 <span class="comment">    double temp;</span>
+<a name="l01780"></a>01780 <span class="comment">    </span>
+<a name="l01781"></a>01781 <span class="comment">    size = cpl_vector_get_size(v);</span>
+<a name="l01782"></a>01782 <span class="comment">    filtered = cpl_vector_new(size);</span>
+<a name="l01783"></a>01783 <span class="comment"></span>
+<a name="l01784"></a>01784 <span class="comment">    row = cpl_malloc((2*hw+1) * sizeof(double));</span>
+<a name="l01785"></a>01785 <span class="comment">    for (i=0; i<size; i++) {</span>
+<a name="l01786"></a>01786 <span class="comment">      k = 0;</span>
+<a name="l01787"></a>01787 <span class="comment">      for (j=-hw; j<=hw; j++) </span>
+<a name="l01788"></a>01788 <span class="comment">    if ( (i+j) >= 0 && (i+j) < size) {</span>
+<a name="l01789"></a>01789 <span class="comment">      temp = cpl_vector_get (v, i+j);</span>
+<a name="l01790"></a>01790 <span class="comment">      row[k] = temp;</span>
+<a name="l01791"></a>01791 <span class="comment">      k++;</span>
+<a name="l01792"></a>01792 <span class="comment">    }</span>
+<a name="l01793"></a>01793 <span class="comment">      cpl_tools_sort_double (row, k);</span>
+<a name="l01794"></a>01794 <span class="comment">      if (k%2 == 1)</span>
+<a name="l01795"></a>01795 <span class="comment">    temp = row[k/2];</span>
+<a name="l01796"></a>01796 <span class="comment">      else</span>
+<a name="l01797"></a>01797 <span class="comment">    temp = row[k/2-1];</span>
+<a name="l01798"></a>01798 <span class="comment">      cpl_vector_set (filtered, i, temp);</span>
+<a name="l01799"></a>01799 <span class="comment">    }</span>
+<a name="l01800"></a>01800 <span class="comment">    cpl_free(row);</span>
+<a name="l01801"></a>01801 <span class="comment">    return filtered;</span>
+<a name="l01802"></a>01802 <span class="comment">}</span>
+<a name="l01803"></a>01803 <span class="comment">*/</span>
+<a name="l01804"></a>01804 
+<a name="l01805"></a>01805 <span class="keyword">static</span> cpl_vector * 
+<a name="l01806"></a>01806 sinfo_juha_vector_filter_median_create(
+<a name="l01807"></a>01807         <span class="keyword">const</span> cpl_vector * v, 
+<a name="l01808"></a>01808         <span class="keywordtype">int</span>                hw)
+<a name="l01809"></a>01809 {
+<a name="l01810"></a>01810     cpl_vector * filtered=NULL;
+<a name="l01811"></a>01811     <span class="keywordtype">double</span>     * row=NULL;
+<a name="l01812"></a>01812     <span class="keywordtype">int</span>          i, j, k,  size;
+<a name="l01813"></a>01813     <span class="keywordtype">double</span> temp;
+<a name="l01814"></a>01814     
+<a name="l01815"></a>01815     size = cpl_vector_get_size(v);
+<a name="l01816"></a>01816     filtered = cpl_vector_new(size);
+<a name="l01817"></a>01817 
+<a name="l01818"></a>01818     row = cpl_malloc((2*hw+1) * <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>));
+<a name="l01819"></a>01819     <span class="keywordflow">for</span> (i=0; i<size; i++) {
+<a name="l01820"></a>01820       k = 0;
+<a name="l01821"></a>01821       <span class="keywordflow">for</span> (j=-hw; j<=hw; j++) 
+<a name="l01822"></a>01822     <span class="keywordflow">if</span> ( (i+j) >= 0 && (i+j) < size) {
+<a name="l01823"></a>01823       temp = cpl_vector_get (v, i+j);
+<a name="l01824"></a>01824       row[k] = temp;
+<a name="l01825"></a>01825       k++;
+<a name="l01826"></a>01826     }
+<a name="l01827"></a>01827       sinfo_tools_sort_double (row, k);
+<a name="l01828"></a>01828 
+<a name="l01829"></a>01829       <span class="keywordflow">if</span> (k%2 == 1)
+<a name="l01830"></a>01830     temp = row[k/2];
+<a name="l01831"></a>01831       <span class="keywordflow">else</span>
+<a name="l01832"></a>01832     temp = row[k/2-1];
+<a name="l01833"></a>01833       cpl_vector_set (filtered, i, temp);
+<a name="l01834"></a>01834     }
+<a name="l01835"></a>01835     cpl_free(row);
+<a name="l01836"></a>01836     <span class="keywordflow">return</span> filtered;
+<a name="l01837"></a>01837 }
+<a name="l01838"></a>01838 
+<a name="l01839"></a>01839 <span class="preprocessor">#define CPL_PIX_STACK_SIZE 50</span>
+<a name="l01840"></a>01840 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l01851"></a>01851 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l01852"></a>01852 <span class="keyword">static</span> cpl_error_code sinfo_tools_sort_double(
+<a name="l01853"></a>01853         <span class="keywordtype">double</span>  *   pix_arr,
+<a name="l01854"></a>01854         <span class="keywordtype">int</span>         n)
+<a name="l01855"></a>01855 {
+<a name="l01856"></a>01856     <span class="keywordtype">int</span>         i, ir, j, k, l;
+<a name="l01857"></a>01857     <span class="keywordtype">int</span>     *   i_stack ;
+<a name="l01858"></a>01858     <span class="keywordtype">int</span>         j_stack ;
+<a name="l01859"></a>01859     <span class="keywordtype">double</span>      a ;
+<a name="l01860"></a>01860     
+<a name="l01861"></a>01861     <span class="comment">/* Check entries */</span>
+<a name="l01862"></a>01862     cpl_ensure(pix_arr, CPL_ERROR_NULL_INPUT, CPL_ERROR_NULL_INPUT) ;
+<a name="l01863"></a>01863 
+<a name="l01864"></a>01864     ir = n ;
+<a name="l01865"></a>01865     l = 1 ;
+<a name="l01866"></a>01866     j_stack = 0 ;
+<a name="l01867"></a>01867     i_stack = malloc(CPL_PIX_STACK_SIZE * <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>)) ;
+<a name="l01868"></a>01868     <span class="keywordflow">for</span> (;;) {
+<a name="l01869"></a>01869         <span class="keywordflow">if</span> (ir-l < 7) {
+<a name="l01870"></a>01870             <span class="keywordflow">for</span> (j=l+1 ; j<=ir ; j++) {
+<a name="l01871"></a>01871                 a = pix_arr[j-1];
+<a name="l01872"></a>01872                 <span class="keywordflow">for</span> (i=j-1 ; i>=1 ; i--) {
+<a name="l01873"></a>01873                     <span class="keywordflow">if</span> (pix_arr[i-1] <= a) <span class="keywordflow">break</span>;
+<a name="l01874"></a>01874                     pix_arr[i] = pix_arr[i-1];
+<a name="l01875"></a>01875                 }
+<a name="l01876"></a>01876                 pix_arr[i] = a;
+<a name="l01877"></a>01877             }
+<a name="l01878"></a>01878             <span class="keywordflow">if</span> (j_stack == 0) <span class="keywordflow">break</span>;
+<a name="l01879"></a>01879             ir = i_stack[j_stack-- -1];
+<a name="l01880"></a>01880             l  = i_stack[j_stack-- -1];
+<a name="l01881"></a>01881         } <span class="keywordflow">else</span> {
+<a name="l01882"></a>01882             k = (l+ir) >> 1;
+<a name="l01883"></a>01883             SINFO_DOUBLE_SWAP(pix_arr[k-1], pix_arr[l])
+<a name="l01884"></a>01884             <span class="keywordflow">if</span> (pix_arr[l] > pix_arr[ir-1]) {
+<a name="l01885"></a>01885                 SINFO_DOUBLE_SWAP(pix_arr[l], pix_arr[ir-1])
+<a name="l01886"></a>01886             }
+<a name="l01887"></a>01887             <span class="keywordflow">if</span> (pix_arr[l-1] > pix_arr[ir-1]) {
+<a name="l01888"></a>01888                 SINFO_DOUBLE_SWAP(pix_arr[l-1], pix_arr[ir-1])
+<a name="l01889"></a>01889             }
+<a name="l01890"></a>01890             <span class="keywordflow">if</span> (pix_arr[l] > pix_arr[l-1]) {
+<a name="l01891"></a>01891                 SINFO_DOUBLE_SWAP(pix_arr[l], pix_arr[l-1])
+<a name="l01892"></a>01892             }
+<a name="l01893"></a>01893             i = l+1;
+<a name="l01894"></a>01894             j = ir;
+<a name="l01895"></a>01895             a = pix_arr[l-1];
+<a name="l01896"></a>01896             <span class="keywordflow">for</span> (;;) {
+<a name="l01897"></a>01897                 <span class="keywordflow">do</span> i++; <span class="keywordflow">while</span> (pix_arr[i-1] < a);
+<a name="l01898"></a>01898                 <span class="keywordflow">do</span> j--; <span class="keywordflow">while</span> (pix_arr[j-1] > a);
+<a name="l01899"></a>01899                 <span class="keywordflow">if</span> (j < i) <span class="keywordflow">break</span>;
+<a name="l01900"></a>01900                 SINFO_DOUBLE_SWAP(pix_arr[i-1], pix_arr[j-1]);
+<a name="l01901"></a>01901             } 
+<a name="l01902"></a>01902             pix_arr[l-1] = pix_arr[j-1];
+<a name="l01903"></a>01903             pix_arr[j-1] = a; 
+<a name="l01904"></a>01904             j_stack += 2; 
+<a name="l01905"></a>01905             <span class="keywordflow">if</span> (j_stack > CPL_PIX_STACK_SIZE) {
+<a name="l01906"></a>01906                 <span class="comment">/* Should never reach here */</span>
+<a name="l01907"></a>01907                 free(i_stack);
+<a name="l01908"></a>01908                 <span class="keywordflow">return</span> CPL_ERROR_ILLEGAL_INPUT ; 
+<a name="l01909"></a>01909             } 
+<a name="l01910"></a>01910             <span class="keywordflow">if</span> (ir-i+1 >= j-l) {
+<a name="l01911"></a>01911                 i_stack[j_stack-1] = ir;
+<a name="l01912"></a>01912                 i_stack[j_stack-2] = i;
+<a name="l01913"></a>01913                 ir = j-1;
+<a name="l01914"></a>01914             } <span class="keywordflow">else</span> {
+<a name="l01915"></a>01915                 i_stack[j_stack-1] = j-1;
+<a name="l01916"></a>01916                 i_stack[j_stack-2] = l;
+<a name="l01917"></a>01917                 l = i;
+<a name="l01918"></a>01918             }
+<a name="l01919"></a>01919         }
+<a name="l01920"></a>01920     }
+<a name="l01921"></a>01921     free(i_stack) ;
+<a name="l01922"></a>01922     <span class="keywordflow">return</span> CPL_ERROR_NONE ;
+<a name="l01923"></a>01923 }
+<a name="l01924"></a>01924 
+<a name="l01925"></a>01925 <span class="keyword">static</span> cpl_vector * 
+<a name="l01926"></a>01926 sinfo_vector_filter_median_create(
+<a name="l01927"></a>01927         <span class="keyword">const</span> cpl_vector * v, 
+<a name="l01928"></a>01928         <span class="keywordtype">int</span>                hw)
+<a name="l01929"></a>01929 {
+<a name="l01930"></a>01930     cpl_vector * filtered;
+<a name="l01931"></a>01931     cpl_vector * row;
+<a name="l01932"></a>01932     <span class="keywordtype">int</span>          i, j, k, size;
+<a name="l01933"></a>01933     <span class="keywordtype">double</span> temp;
+<a name="l01934"></a>01934     
+<a name="l01935"></a>01935     <span class="comment">/* Create the filtered vector */</span>
+<a name="l01936"></a>01936     size = cpl_vector_get_size(v);
+<a name="l01937"></a>01937     filtered = cpl_vector_new(size);
+<a name="l01938"></a>01938 
+<a name="l01939"></a>01939     <span class="comment">/* median filter on all central items */</span>
+<a name="l01940"></a>01940     row = cpl_vector_new((2*hw+1));
+<a name="l01941"></a>01941     <span class="keywordflow">for</span> (i=0; i<size; i++) {
+<a name="l01942"></a>01942       k = 0;
+<a name="l01943"></a>01943       <span class="keywordflow">for</span> (j=-hw; j<=hw; j++) 
+<a name="l01944"></a>01944     <span class="keywordflow">if</span> ( (i+j) >= 0 && (i+j) < size) {
+<a name="l01945"></a>01945       temp = cpl_vector_get (v, i+j);
+<a name="l01946"></a>01946       cpl_vector_set(row,k,temp);
+<a name="l01947"></a>01947       k++;
+<a name="l01948"></a>01948     }
+<a name="l01949"></a>01949       <span class="comment">/*  this returns ~2e8 when all the values are 1.0....*/</span>
+<a name="l01950"></a>01950 <span class="comment">/*       temp = cpl_tools_get_median_double(row, k); */</span>
+<a name="l01951"></a>01951       cpl_vector_sort(row, +1);
+<a name="l01952"></a>01952       <span class="keywordflow">if</span> (k%2 == 1) {
+<a name="l01953"></a>01953     temp = cpl_vector_get(row,k/2);
+<a name="l01954"></a>01954       }
+<a name="l01955"></a>01955       <span class="keywordflow">else</span> {
+<a name="l01956"></a>01956     temp = cpl_vector_get(row,k/2-1);
+<a name="l01957"></a>01957       }
+<a name="l01958"></a>01958 
+<a name="l01959"></a>01959       sinfo_msg(<span class="stringliteral">"value = %g "</span>, temp);
+<a name="l01960"></a>01960       cpl_vector_set (filtered, i, temp);
+<a name="l01961"></a>01961     }
+<a name="l01962"></a>01962     cpl_vector_delete(row);
+<a name="l01963"></a>01963     <span class="keywordflow">return</span> filtered;
+<a name="l01964"></a>01964 }
+<a name="l01965"></a>01965 
+<a name="l01966"></a>01966 <span class="comment">/*</span>
+<a name="l01967"></a>01967 <span class="comment"> *  A NaN safe version of cpl_image_get_median_window</span>
+<a name="l01968"></a>01968 <span class="comment"> */</span>
+<a name="l01969"></a>01969 <span class="keyword">static</span> <span class="keywordtype">double</span> 
+<a name="l01970"></a>01970 sinfo_image_get_median_window  (<span class="keyword">const</span> cpl_image *image, 
+<a name="l01971"></a>01971                        <span class="keywordtype">int</span> llx, <span class="keywordtype">int</span> lly, <span class="keywordtype">int</span> urx, <span class="keywordtype">int</span> ury)
+<a name="l01972"></a>01972 {
+<a name="l01973"></a>01973   cpl_image *window;
+<a name="l01974"></a>01974   <span class="keywordtype">float</span> *data;
+<a name="l01975"></a>01975   <span class="keywordtype">double</span> *array, median;
+<a name="l01976"></a>01976   <span class="keywordtype">int</span> size, i,j;
+<a name="l01977"></a>01977 
+<a name="l01978"></a>01978   window = cpl_image_extract (image, llx, lly, urx, ury);
+<a name="l01979"></a>01979   size = (urx-llx+1)*(ury-lly+1);
+<a name="l01980"></a>01980   data = cpl_image_get_data_float(window);
+<a name="l01981"></a>01981 
+<a name="l01982"></a>01982   array = (<span class="keywordtype">double</span>*)cpl_calloc ( size, <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>));
+<a name="l01983"></a>01983   j = 0;
+<a name="l01984"></a>01984   <span class="keywordflow">for</span> (i=0; i<size; i++)
+<a name="l01985"></a>01985     <span class="keywordflow">if</span> (!isnan(data[i]))
+<a name="l01986"></a>01986       array[j++] = data[i];
+<a name="l01987"></a>01987   
+<a name="l01988"></a>01988   <span class="keywordflow">if</span> (j>0)
+<a name="l01989"></a>01989     sinfo_tools_sort_double (array, j);
+<a name="l01990"></a>01990   
+<a name="l01991"></a>01991   <span class="keywordflow">if</span> (j == 0 || 2*j<size)
+<a name="l01992"></a>01992     median = 0./0.;
+<a name="l01993"></a>01993   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (j%2 == 1) 
+<a name="l01994"></a>01994     median = array[j/2];
+<a name="l01995"></a>01995   <span class="keywordflow">else</span> 
+<a name="l01996"></a>01996     median = array[j/2-1];
+<a name="l01997"></a>01997 
+<a name="l01998"></a>01998   cpl_image_delete (window);
+<a name="l01999"></a>01999   cpl_free (array);
+<a name="l02000"></a>02000   
+<a name="l02001"></a>02001   <span class="keywordflow">return</span> (median);
+<a name="l02002"></a>02002 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__utl__ima__arith_8c_source.html b/html/sinfo__utl__ima__arith_8c_source.html
new file mode 100644
index 0000000..d56cb8f
--- /dev/null
+++ b/html/sinfo__utl__ima__arith_8c_source.html
@@ -0,0 +1,403 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_utl_ima_arith.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_utl_ima_arith.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_utl_ima_arith.c,v 1.14 2009/01/30 14:56:12 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the SINFONI Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2009/01/30 14:56:12 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.14 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span>
+<a name="l00032"></a>00032 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                                Includes</span>
+<a name="l00034"></a>00034 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 <span class="preprocessor">#include <string.h></span>
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="comment">/* cpl */</span>
+<a name="l00038"></a>00038 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00039"></a>00039 
+<a name="l00040"></a>00040 <span class="comment">/* irplib */</span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include <irplib_utils.h></span>
+<a name="l00042"></a>00042 
+<a name="l00043"></a>00043 <span class="preprocessor">#include <sinfo_tpl_utils.h></span>
+<a name="l00044"></a>00044 <span class="preprocessor">#include <sinfo_pfits.h></span>
+<a name="l00045"></a>00045 <span class="preprocessor">#include <sinfo_tpl_dfs.h></span>
+<a name="l00046"></a>00046 <span class="preprocessor">#include <sinfo_key_names.h></span>
+<a name="l00047"></a>00047 <span class="preprocessor">#include <sinfo_pro_types.h></span>
+<a name="l00048"></a>00048 <span class="preprocessor">#include <sinfo_functions.h></span>
+<a name="l00049"></a>00049 <span class="preprocessor">#include <sinfo_msg.h></span>
+<a name="l00050"></a>00050 <span class="preprocessor">#include <sinfo_error.h></span>
+<a name="l00051"></a>00051 <span class="preprocessor">#include <sinfo_utils_wrappers.h></span>
+<a name="l00052"></a>00052 
+<a name="l00053"></a>00053 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00054"></a>00054 <span class="comment">                            Functions prototypes</span>
+<a name="l00055"></a>00055 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00056"></a>00056 
+<a name="l00057"></a>00057 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_ima_arith_create(cpl_plugin *) ;
+<a name="l00058"></a>00058 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_ima_arith_exec(cpl_plugin *) ;
+<a name="l00059"></a>00059 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_ima_arith_destroy(cpl_plugin *) ;
+<a name="l00060"></a>00060 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_ima_arith(cpl_parameterlist *, cpl_frameset *) ;
+<a name="l00061"></a>00061 
+<a name="l00062"></a>00062 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00063"></a>00063 <span class="comment">                            Static variables</span>
+<a name="l00064"></a>00064 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00065"></a>00065 
+<a name="l00066"></a>00066 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_utl_ima_arith_description[] =
+<a name="l00067"></a>00067 <span class="stringliteral">"This recipe performs image computation.\n"</span>
+<a name="l00068"></a>00068 <span class="stringliteral">"The input files are 2 images\n"</span>
+<a name="l00069"></a>00069 <span class="stringliteral">"their associated tags should be IMA.\n"</span>
+<a name="l00070"></a>00070 <span class="stringliteral">"The output is an image resulting from the IMA op IMA where op indicates\n"</span>
+<a name="l00071"></a>00071 <span class="stringliteral">"the operation to be performed specified by the parameter \n"</span>
+<a name="l00072"></a>00072 <span class="stringliteral">"sinfoni.sinfo_utl_ima_arith.op having alias 'op'\n"</span>
+<a name="l00073"></a>00073 <span class="stringliteral">"Information on relevant parameters can be found with\n"</span>
+<a name="l00074"></a>00074 <span class="stringliteral">"esorex --params sinfo_utl_ima_arith\n"</span>
+<a name="l00075"></a>00075 <span class="stringliteral">"esorex --help sinfo_utl_ima_arith\n"</span>
+<a name="l00076"></a>00076 <span class="stringliteral">"\n"</span>;
+<a name="l00077"></a>00077 
+<a name="l00078"></a>00078 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00079"></a>00079 <span class="comment">                                Functions code</span>
+<a name="l00080"></a>00080 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00081"></a>00081 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00085"></a>00085 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00086"></a>00086 
+<a name="l00088"></a>00088 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00096"></a>00096 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00097"></a><a class="code" href="group__sinfo__utl__ima__arith.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693">00097</a> <span class="keywordtype">int</span> <a class="code" href="group__sinfo__rec__detlin.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693" title="Build the list of available plugins, for this module.">cpl_plugin_get_info</a>(cpl_pluginlist * list)
+<a name="l00098"></a>00098 {
+<a name="l00099"></a>00099     cpl_recipe  *   recipe = cpl_calloc(1, <span class="keyword">sizeof</span> *recipe ) ;
+<a name="l00100"></a>00100     cpl_plugin  *   plugin = &recipe->interface ;
+<a name="l00101"></a>00101 
+<a name="l00102"></a>00102     cpl_plugin_init(plugin,
+<a name="l00103"></a>00103                     CPL_PLUGIN_API,
+<a name="l00104"></a>00104                     SINFONI_BINARY_VERSION,
+<a name="l00105"></a>00105                     CPL_PLUGIN_TYPE_RECIPE,
+<a name="l00106"></a>00106                     <span class="stringliteral">"sinfo_utl_ima_arith"</span>,
+<a name="l00107"></a>00107                     <span class="stringliteral">"Computes result of ima1 op ima2"</span>,
+<a name="l00108"></a>00108                     sinfo_utl_ima_arith_description,
+<a name="l00109"></a>00109                     <span class="stringliteral">"Andrea Modigliani"</span>,
+<a name="l00110"></a>00110                     <span class="stringliteral">"Andrea.Modigliani at eso.org"</span>,
+<a name="l00111"></a>00111                     sinfo_get_license(),
+<a name="l00112"></a>00112                     sinfo_utl_ima_arith_create,
+<a name="l00113"></a>00113                     sinfo_utl_ima_arith_exec,
+<a name="l00114"></a>00114                     sinfo_utl_ima_arith_destroy) ;
+<a name="l00115"></a>00115 
+<a name="l00116"></a>00116     cpl_pluginlist_append(list, plugin) ;
+<a name="l00117"></a>00117     
+<a name="l00118"></a>00118     <span class="keywordflow">return</span> 0;
+<a name="l00119"></a>00119 }
+<a name="l00120"></a>00120 
+<a name="l00121"></a>00121 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00130"></a>00130 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00131"></a>00131 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_ima_arith_create(cpl_plugin * plugin)
+<a name="l00132"></a>00132 {
+<a name="l00133"></a>00133     cpl_recipe      * recipe ;
+<a name="l00134"></a>00134     cpl_parameter   * p ;
+<a name="l00135"></a>00135 
+<a name="l00136"></a>00136     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00137"></a>00137     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00138"></a>00138         recipe = (cpl_recipe *)plugin ;
+<a name="l00139"></a>00139     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00140"></a>00140     cpl_error_reset();
+<a name="l00141"></a>00141     <a class="code" href="group__irplib__utils.html#gaf9d392144014e2363054bc3f83c8e47e" title="Reset IRPLIB state.">irplib_reset</a>();
+<a name="l00142"></a>00142 
+<a name="l00143"></a>00143     <span class="comment">/* Create the parameters list in the cpl_recipe object */</span>
+<a name="l00144"></a>00144     recipe->parameters = cpl_parameterlist_new() ; 
+<a name="l00145"></a>00145 
+<a name="l00146"></a>00146     <span class="comment">/* Fill the parameters list */</span>
+<a name="l00147"></a>00147     <span class="comment">/* --stropt */</span>
+<a name="l00148"></a>00148     p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.sinfo_utl_ima_arith.op"</span>, 
+<a name="l00149"></a>00149                                 CPL_TYPE_STRING, 
+<a name="l00150"></a>00150                                 <span class="stringliteral">"A possible operation"</span>, 
+<a name="l00151"></a>00151                                 <span class="stringliteral">"sinfoni.sinfo_utl_ima_arith"</span>,<span class="stringliteral">"+"</span>);
+<a name="l00152"></a>00152     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"op"</span>) ;
+<a name="l00153"></a>00153     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00154"></a>00154 
+<a name="l00155"></a>00155     <span class="comment">/* --doubleopt */</span>
+<a name="l00156"></a>00156     p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.sinfo_utl_ima_arith.value"</span>, 
+<a name="l00157"></a>00157             CPL_TYPE_DOUBLE, <span class="stringliteral">"a value"</span>, <span class="stringliteral">"sinfoni.sinfo_utl_ima_arith"</span>, 9999.) ;
+<a name="l00158"></a>00158     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"value"</span>) ;
+<a name="l00159"></a>00159     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00160"></a>00160  
+<a name="l00161"></a>00161     <span class="comment">/* Return */</span>
+<a name="l00162"></a>00162     <span class="keywordflow">return</span> 0;
+<a name="l00163"></a>00163 }
+<a name="l00164"></a>00164 
+<a name="l00165"></a>00165 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00171"></a>00171 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00172"></a>00172 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_ima_arith_exec(cpl_plugin * plugin)
+<a name="l00173"></a>00173 {
+<a name="l00174"></a>00174     cpl_recipe  *   recipe ;
+<a name="l00175"></a>00175      <span class="keywordtype">int</span> code=0;
+<a name="l00176"></a>00176      cpl_errorstate initial_errorstate = cpl_errorstate_get();
+<a name="l00177"></a>00177 
+<a name="l00178"></a>00178     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00179"></a>00179     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00180"></a>00180         recipe = (cpl_recipe *)plugin ;
+<a name="l00181"></a>00181     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00182"></a>00182     cpl_error_reset();
+<a name="l00183"></a>00183     <a class="code" href="group__irplib__utils.html#gaf9d392144014e2363054bc3f83c8e47e" title="Reset IRPLIB state.">irplib_reset</a>();
+<a name="l00184"></a>00184     code = sinfo_utl_ima_arith(recipe->parameters, recipe->frames) ;
+<a name="l00185"></a>00185 
+<a name="l00186"></a>00186 
+<a name="l00187"></a>00187     <span class="keywordflow">if</span> (!cpl_errorstate_is_equal(initial_errorstate)) {                      
+<a name="l00188"></a>00188         <span class="comment">/* Dump the error history since recipe execution start.                </span>
+<a name="l00189"></a>00189 <span class="comment">           At this point the recipe cannot recover from the error */</span>           
+<a name="l00190"></a>00190         cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);              
+<a name="l00191"></a>00191     } 
+<a name="l00192"></a>00192 
+<a name="l00193"></a>00193     <span class="keywordflow">return</span> code ;
+<a name="l00194"></a>00194 }
+<a name="l00195"></a>00195 
+<a name="l00196"></a>00196 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00202"></a>00202 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00203"></a>00203 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_ima_arith_destroy(cpl_plugin * plugin)
+<a name="l00204"></a>00204 {
+<a name="l00205"></a>00205     cpl_recipe  *   recipe ;
+<a name="l00206"></a>00206     
+<a name="l00207"></a>00207     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00208"></a>00208     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00209"></a>00209         recipe = (cpl_recipe *)plugin ;
+<a name="l00210"></a>00210     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00211"></a>00211 
+<a name="l00212"></a>00212     cpl_parameterlist_delete(recipe->parameters) ; 
+<a name="l00213"></a>00213     <span class="keywordflow">return</span> 0 ;
+<a name="l00214"></a>00214 }
+<a name="l00215"></a>00215 
+<a name="l00216"></a>00216 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00223"></a>00223 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00224"></a>00224 <span class="keyword">static</span> <span class="keywordtype">int</span> 
+<a name="l00225"></a>00225 sinfo_utl_ima_arith( cpl_parameterlist   *   parlist, 
+<a name="l00226"></a>00226         cpl_frameset        *   framelist)
+<a name="l00227"></a>00227 {
+<a name="l00228"></a>00228     cpl_parameter       *   param= NULL ;
+<a name="l00229"></a>00229     <span class="keyword">const</span> <span class="keywordtype">char</span>          *   operation=NULL;
+<a name="l00230"></a>00230     <span class="keywordtype">double</span>                     value=1 ;
+<a name="l00231"></a>00231     cpl_frame           *   frm_ima1=NULL ;
+<a name="l00232"></a>00232     cpl_frame           *   frm_ima2=NULL ;
+<a name="l00233"></a>00233     cpl_image           *   ima1=NULL ;
+<a name="l00234"></a>00234     cpl_image           *   ima2=NULL ;
+<a name="l00235"></a>00235     <span class="keywordtype">int</span> switch_ima2     = 0;
+<a name="l00236"></a>00236     <span class="keyword">const</span> <span class="keywordtype">char</span>                *   name_o=NULL ;
+<a name="l00237"></a>00237     cpl_propertylist    *   plist=NULL ;
+<a name="l00238"></a>00238     cpl_image           *   image=NULL ;
+<a name="l00239"></a>00239     cpl_frame           *   product_frame=NULL;
+<a name="l00240"></a>00240     cpl_frameset * raw_set=NULL;
+<a name="l00241"></a>00241     <span class="keywordtype">int</span> nraw=0;
+<a name="l00242"></a>00242     <span class="keywordtype">int</span> n=0;
+<a name="l00243"></a>00243           sinfo_msg(<span class="stringliteral">"Welcome to SINFONI Pipeline release %d.%d.%d"</span>,
+<a name="l00244"></a>00244         SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
+<a name="l00245"></a>00245 
+<a name="l00246"></a>00246     <span class="comment">/* HOW TO RETRIEVE INPUT PARAMETERS */</span>
+<a name="l00247"></a>00247     <span class="comment">/* --stropt */</span>
+<a name="l00248"></a>00248     check_nomsg(param=cpl_parameterlist_find(parlist, 
+<a name="l00249"></a>00249                                              <span class="stringliteral">"sinfoni.sinfo_utl_ima_arith.op"</span>));
+<a name="l00250"></a>00250     check_nomsg(operation=cpl_parameter_get_string(param));
+<a name="l00251"></a>00251 
+<a name="l00252"></a>00252     <span class="comment">/* --boolopt */</span>
+<a name="l00253"></a>00253     check_nomsg(param=cpl_parameterlist_find(parlist,
+<a name="l00254"></a>00254                                              <span class="stringliteral">"sinfoni.sinfo_utl_ima_arith.value"</span>));
+<a name="l00255"></a>00255     check_nomsg(value = cpl_parameter_get_double(param)) ;
+<a name="l00256"></a>00256   
+<a name="l00257"></a>00257     <span class="comment">/* Identify the RAW and CALIB frames in the input frameset */</span>
+<a name="l00258"></a>00258     check(sinfo_dfs_set_groups(framelist),
+<a name="l00259"></a>00259          <span class="stringliteral">"Cannot identify RAW and CALIB frames"</span>) ;
+<a name="l00260"></a>00260  
+<a name="l00261"></a>00261     <span class="comment">/* HOW TO ACCESS INPUT DATA */</span>
+<a name="l00262"></a>00262     n=cpl_frameset_get_size(framelist);
+<a name="l00263"></a>00263     <span class="keywordflow">if</span>(n<1) {
+<a name="l00264"></a>00264       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Empty input frame list!"</span>);
+<a name="l00265"></a>00265       <span class="keywordflow">goto</span> cleanup ;
+<a name="l00266"></a>00266     }
+<a name="l00267"></a>00267 
+<a name="l00268"></a>00268     <span class="comment">/* HOW TO ACCESS INPUT DATA */</span>
+<a name="l00269"></a>00269     check_nomsg(raw_set=cpl_frameset_new());
+<a name="l00270"></a>00270 
+<a name="l00271"></a>00271     check(sinfo_contains_frames_kind(framelist,raw_set,PRO_IMA),
+<a name="l00272"></a>00272      <span class="stringliteral">"Found no input frames with tag %s"</span>,PRO_IMA);
+<a name="l00273"></a>00273     check_nomsg(nraw=cpl_frameset_get_size(raw_set));
+<a name="l00274"></a>00274     <span class="keywordflow">if</span> (nraw<1) {
+<a name="l00275"></a>00275       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Found no input frames with tag %s"</span>,PRO_IMA);
+<a name="l00276"></a>00276       <span class="keywordflow">goto</span> cleanup;
+<a name="l00277"></a>00277     } <span class="keywordflow">else</span> {
+<a name="l00278"></a>00278          check_nomsg(frm_ima1=cpl_frameset_get_frame(framelist,0));
+<a name="l00279"></a>00279          check_nomsg(ima1=cpl_image_load(cpl_frame_get_filename(frm_ima1),
+<a name="l00280"></a>00280                                          CPL_TYPE_FLOAT,0,0));
+<a name="l00281"></a>00281      <span class="keywordflow">if</span> (nraw>1) {
+<a name="l00282"></a>00282          check_nomsg(frm_ima2=cpl_frameset_get_frame(framelist,1));
+<a name="l00283"></a>00283          check_nomsg(ima2 = cpl_image_load(cpl_frame_get_filename(frm_ima2),
+<a name="l00284"></a>00284                                            CPL_TYPE_FLOAT,0,0));
+<a name="l00285"></a>00285          switch_ima2=1;
+<a name="l00286"></a>00286       } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (value == 9999.) {
+<a name="l00287"></a>00287         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Found only one input frames with tag %s"</span>,PRO_IMA);
+<a name="l00288"></a>00288         <span class="keywordflow">goto</span> cleanup; 
+<a name="l00289"></a>00289       } <span class="keywordflow">else</span> {
+<a name="l00290"></a>00290         sinfo_msg(<span class="stringliteral">"Perform image arithmetics on frame %s"</span>,PRO_IMA);
+<a name="l00291"></a>00291       }
+<a name="l00292"></a>00292     }
+<a name="l00293"></a>00293 
+<a name="l00294"></a>00294     sinfo_free_frameset(&raw_set);
+<a name="l00295"></a>00295 
+<a name="l00296"></a>00296     <span class="comment">/* HOW TO GET THE VALUE OF A FITS KEYWORD */</span>
+<a name="l00297"></a>00297     check(plist=cpl_propertylist_load(cpl_frame_get_filename(frm_ima1),0),
+<a name="l00298"></a>00298           <span class="stringliteral">"Cannot read the FITS header"</span>) ;
+<a name="l00299"></a>00299 
+<a name="l00300"></a>00300     <span class="comment">/* Now performing the data reduction */</span>
+<a name="l00301"></a>00301     <span class="comment">/* Let's generate one image for the example */</span>
+<a name="l00302"></a>00302     <span class="keywordflow">if</span> (value == 9999.) {
+<a name="l00303"></a>00303 
+<a name="l00304"></a>00304       <span class="keywordflow">if</span>(ima1 != NULL && ima2 != NULL) {
+<a name="l00305"></a>00305     sinfo_msg(<span class="stringliteral">"ima1 %s ima2"</span>,operation);
+<a name="l00306"></a>00306     <span class="keywordflow">if</span> (strcmp(operation,<span class="stringliteral">"+"</span>) == 0 ) {
+<a name="l00307"></a>00307           check(image = cpl_image_add_create(ima1, ima2),
+<a name="l00308"></a>00308                 <span class="stringliteral">"Cannot generate the %s image"</span>,operation) ;
+<a name="l00309"></a>00309     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(operation,<span class="stringliteral">"-"</span>) == 0 ) {
+<a name="l00310"></a>00310           check(image = cpl_image_subtract_create(ima1, ima2),               
+<a name="l00311"></a>00311         <span class="stringliteral">"Cannot generate the %s image"</span>,operation) ;
+<a name="l00312"></a>00312     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(operation,<span class="stringliteral">"*"</span>) == 0 ) {
+<a name="l00313"></a>00313           check(image = cpl_image_multiply_create(ima1, ima2),
+<a name="l00314"></a>00314         <span class="stringliteral">"Cannot generate the %s image"</span>,operation) ;
+<a name="l00315"></a>00315     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(operation,<span class="stringliteral">"/"</span>) == 0 ) {
+<a name="l00316"></a>00316       check(image = cpl_image_divide_create(ima1, ima2),
+<a name="l00317"></a>00317         <span class="stringliteral">"Cannot generate the %s image"</span>,operation) ;
+<a name="l00318"></a>00318     } <span class="keywordflow">else</span> {
+<a name="l00319"></a>00319           <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Operation %s not supported"</span>,operation);
+<a name="l00320"></a>00320           <span class="keywordflow">goto</span> cleanup;
+<a name="l00321"></a>00321     }
+<a name="l00322"></a>00322       sinfo_free_image(&ima1);
+<a name="l00323"></a>00323       sinfo_free_image(&ima2);
+<a name="l00324"></a>00324 
+<a name="l00325"></a>00325       }
+<a name="l00326"></a>00326     
+<a name="l00327"></a>00327     } <span class="keywordflow">else</span> {
+<a name="l00328"></a>00328       sinfo_msg(<span class="stringliteral">"ima1 %s %f"</span>,operation,value);
+<a name="l00329"></a>00329        
+<a name="l00330"></a>00330       <span class="keywordflow">if</span>(switch_ima2 == 1) {
+<a name="l00331"></a>00331       sinfo_free_image(&ima2);
+<a name="l00332"></a>00332       }
+<a name="l00333"></a>00333        
+<a name="l00334"></a>00334       <span class="keywordflow">if</span> (strcmp(operation,<span class="stringliteral">"+"</span>) == 0 ) {
+<a name="l00335"></a>00335     check(image = cpl_image_add_scalar_create(ima1, value),
+<a name="l00336"></a>00336           <span class="stringliteral">"Cannot apply the %s operator"</span>,operation) ;
+<a name="l00337"></a>00337       } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(operation,<span class="stringliteral">"-"</span>) == 0 ) {
+<a name="l00338"></a>00338     check(image = cpl_image_subtract_scalar_create(ima1, value),
+<a name="l00339"></a>00339           <span class="stringliteral">"Cannot apply the %s operator"</span>,operation) ;
+<a name="l00340"></a>00340       } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(operation,<span class="stringliteral">"*"</span>) == 0 ) {
+<a name="l00341"></a>00341     check(image = cpl_image_multiply_scalar_create(ima1, value),
+<a name="l00342"></a>00342           <span class="stringliteral">"Cannot apply the %s operator"</span>,operation) ;
+<a name="l00343"></a>00343       } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(operation,<span class="stringliteral">"/"</span>) == 0 ) {
+<a name="l00344"></a>00344     check(image = cpl_image_divide_scalar_create(ima1, value),
+<a name="l00345"></a>00345           <span class="stringliteral">"Cannot apply the %s operator"</span>,operation) ;
+<a name="l00346"></a>00346       } <span class="keywordflow">else</span> {
+<a name="l00347"></a>00347     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Operation %s not supported"</span>,operation);
+<a name="l00348"></a>00348     <span class="keywordflow">goto</span> cleanup;
+<a name="l00349"></a>00349       }
+<a name="l00350"></a>00350     
+<a name="l00351"></a>00351       sinfo_free_image(&ima1);
+<a name="l00352"></a>00352 
+<a name="l00353"></a>00353     }
+<a name="l00354"></a>00354 
+<a name="l00355"></a>00355 
+<a name="l00356"></a>00356     <span class="comment">/* HOW TO SAVE A PRODUCT ON DISK  */</span>
+<a name="l00357"></a>00357     <span class="comment">/* Set the file name */</span>
+<a name="l00358"></a>00358     name_o = <span class="stringliteral">"ima_res.fits"</span> ;
+<a name="l00359"></a>00359 
+<a name="l00360"></a>00360     <span class="comment">/* Create product frame */</span>
+<a name="l00361"></a>00361     check_nomsg(product_frame = cpl_frame_new());
+<a name="l00362"></a>00362     check_nomsg(cpl_frame_set_filename(product_frame, name_o)) ;
+<a name="l00363"></a>00363     check_nomsg(cpl_frame_set_tag(product_frame, SI_UTL_IMA_ARITH_PROIMA)) ;
+<a name="l00364"></a>00364     check_nomsg(cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_IMAGE)) ;
+<a name="l00365"></a>00365     check_nomsg(cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT)) ;
+<a name="l00366"></a>00366     check(cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL),
+<a name="l00367"></a>00367       <span class="stringliteral">"Error while initialising the product frame"</span>) ;
+<a name="l00368"></a>00368     
+<a name="l00369"></a>00369     <span class="comment">/* Add DataFlow keywords */</span>
+<a name="l00370"></a>00370     check_nomsg(cpl_propertylist_erase_regexp(plist, <span class="stringliteral">"^ESO PRO CATG"</span>,0));
+<a name="l00371"></a>00371 <span class="preprocessor">#if defined CPL_VERSION_CODE && CPL_VERSION_CODE >= CPL_VERSION(4, 8, 0)  </span>
+<a name="l00372"></a>00372 <span class="preprocessor"></span>    check(cpl_dfs_setup_product_header(plist, 
+<a name="l00373"></a>00373                                        product_frame, 
+<a name="l00374"></a>00374                                        framelist, 
+<a name="l00375"></a>00375                                        parlist,
+<a name="l00376"></a>00376                                        <span class="stringliteral">"sinfo_utl_ima_arith"</span>, 
+<a name="l00377"></a>00377                                        <span class="stringliteral">"SINFONI"</span>, 
+<a name="l00378"></a>00378                                        KEY_VALUE_HPRO_DID,NULL),
+<a name="l00379"></a>00379       <span class="stringliteral">"Problem in the product DFS-compliance"</span>) ;
+<a name="l00380"></a>00380 <span class="preprocessor">#else</span>
+<a name="l00381"></a>00381 <span class="preprocessor"></span>    check(cpl_dfs_setup_product_header(plist, 
+<a name="l00382"></a>00382                                        product_frame, 
+<a name="l00383"></a>00383                                        framelist, 
+<a name="l00384"></a>00384                                        parlist,
+<a name="l00385"></a>00385                                        <span class="stringliteral">"sinfo_utl_ima_arith"</span>, 
+<a name="l00386"></a>00386                                        <span class="stringliteral">"SINFONI"</span>, 
+<a name="l00387"></a>00387                                        KEY_VALUE_HPRO_DID),
+<a name="l00388"></a>00388       <span class="stringliteral">"Problem in the product DFS-compliance"</span>) ;
+<a name="l00389"></a>00389 <span class="preprocessor">#endif</span>
+<a name="l00390"></a>00390 <span class="preprocessor"></span>
+<a name="l00391"></a>00391     <span class="comment">/* Save the file */</span>
+<a name="l00392"></a>00392     check(cpl_image_save(image, 
+<a name="l00393"></a>00393                          name_o, 
+<a name="l00394"></a>00394                          CPL_BPP_IEEE_FLOAT, 
+<a name="l00395"></a>00395                          plist,
+<a name="l00396"></a>00396                          CPL_IO_DEFAULT),
+<a name="l00397"></a>00397       <span class="stringliteral">"Could not save product"</span>);
+<a name="l00398"></a>00398     sinfo_free_propertylist(&plist) ;
+<a name="l00399"></a>00399     sinfo_free_image(&image);
+<a name="l00400"></a>00400 
+<a name="l00401"></a>00401     <span class="comment">/* Log the saved file in the input frameset */</span>
+<a name="l00402"></a>00402     check_nomsg(cpl_frameset_insert(framelist, product_frame)) ;
+<a name="l00403"></a>00403 
+<a name="l00404"></a>00404 
+<a name="l00405"></a>00405  cleanup:
+<a name="l00406"></a>00406    
+<a name="l00407"></a>00407     sinfo_free_image(&ima1);
+<a name="l00408"></a>00408     sinfo_free_image(&ima2);
+<a name="l00409"></a>00409     sinfo_free_frameset(&raw_set);
+<a name="l00410"></a>00410     sinfo_free_propertylist(&plist) ;
+<a name="l00411"></a>00411     <span class="comment">/* This is usually freed by esorex: but what about if errors occurs?</span>
+<a name="l00412"></a>00412 <span class="comment">    sinfo_free_frame(&product_frame) ;</span>
+<a name="l00413"></a>00413 <span class="comment">    */</span>
+<a name="l00414"></a>00414     sinfo_free_image(&image) ;
+<a name="l00415"></a>00415 
+<a name="l00416"></a>00416     <span class="keywordflow">if</span> (cpl_error_get_code()) {
+<a name="l00417"></a>00417         <span class="keywordflow">return</span> -1 ;
+<a name="l00418"></a>00418     } <span class="keywordflow">else</span> {
+<a name="l00419"></a>00419         <span class="keywordflow">return</span> 0 ;
+<a name="l00420"></a>00420     }
+<a name="l00421"></a>00421 
+<a name="l00422"></a>00422 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__utl__ima__cube__ks__test_8c_source.html b/html/sinfo__utl__ima__cube__ks__test_8c_source.html
new file mode 100644
index 0000000..e1eb966
--- /dev/null
+++ b/html/sinfo__utl__ima__cube__ks__test_8c_source.html
@@ -0,0 +1,875 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_utl_ima_cube_ks_test.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_utl_ima_cube_ks_test.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_utl_ima_cube_ks_test.c,v 1.12 2012/05/04 08:11:55 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the SINFONI Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2012/05/04 08:11:55 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.12 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> * $Log: sinfo_utl_ima_cube_ks_test.c,v $</span>
+<a name="l00027"></a>00027 <span class="comment"> * Revision 1.12  2012/05/04 08:11:55  amodigli</span>
+<a name="l00028"></a>00028 <span class="comment"> * fixed errors fromn cpptest</span>
+<a name="l00029"></a>00029 <span class="comment"> *</span>
+<a name="l00030"></a>00030 <span class="comment"> * Revision 1.11  2009/11/12 14:49:38  kmirny</span>
+<a name="l00031"></a>00031 <span class="comment"> * changing output message</span>
+<a name="l00032"></a>00032 <span class="comment"> *</span>
+<a name="l00033"></a>00033 <span class="comment"> * Revision 1.10  2009/07/27 10:34:54  amodigli</span>
+<a name="l00034"></a>00034 <span class="comment"> * fixed typo in short description</span>
+<a name="l00035"></a>00035 <span class="comment"> *</span>
+<a name="l00036"></a>00036 <span class="comment"> * Revision 1.9  2009/06/03 14:59:31  kmirny</span>
+<a name="l00037"></a>00037 <span class="comment"> * rollback</span>
+<a name="l00038"></a>00038 <span class="comment"> *</span>
+<a name="l00039"></a>00039 <span class="comment"> */</span>
+<a name="l00040"></a>00040 
+<a name="l00041"></a>00041 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00042"></a>00042 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>
+<a name="l00043"></a>00043 <span class="preprocessor">#endif</span>
+<a name="l00044"></a>00044 <span class="preprocessor"></span>
+<a name="l00045"></a>00045 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00046"></a>00046 <span class="comment">                                Includes</span>
+<a name="l00047"></a>00047 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00048"></a>00048 <span class="preprocessor">#include <string.h></span>
+<a name="l00049"></a>00049 
+<a name="l00050"></a>00050 <span class="comment">/* cpl */</span>
+<a name="l00051"></a>00051 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00052"></a>00052 <span class="preprocessor">#include <math.h></span>
+<a name="l00053"></a>00053 <span class="comment">/* irplib */</span>
+<a name="l00054"></a>00054 <span class="preprocessor">#include <irplib_utils.h></span>
+<a name="l00055"></a>00055 <span class="preprocessor">#include <sinfo_globals.h></span>
+<a name="l00056"></a>00056 <span class="preprocessor">#include <sinfo_tpl_utils.h></span>
+<a name="l00057"></a>00057 <span class="preprocessor">#include <sinfo_pfits.h></span>
+<a name="l00058"></a>00058 <span class="preprocessor">#include <sinfo_tpl_dfs.h></span>
+<a name="l00059"></a>00059 <span class="preprocessor">#include <sinfo_key_names.h></span>
+<a name="l00060"></a>00060 <span class="preprocessor">#include <sinfo_pro_types.h></span>
+<a name="l00061"></a>00061 <span class="preprocessor">#include <sinfo_pro_save.h></span>
+<a name="l00062"></a>00062 <span class="preprocessor">#include <sinfo_functions.h></span>
+<a name="l00063"></a>00063 <span class="preprocessor">#include <sinfo_msg.h></span>
+<a name="l00064"></a>00064 <span class="preprocessor">#include <sinfo_error.h></span>
+<a name="l00065"></a>00065 <span class="preprocessor">#include <sinfo_utils_wrappers.h></span>
+<a name="l00066"></a>00066 <span class="preprocessor">#include <sinfo_new_cube_ops.h></span>
+<a name="l00067"></a>00067 
+<a name="l00068"></a>00068 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00069"></a>00069 <span class="comment">                            Functions prototypes</span>
+<a name="l00070"></a>00070 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00071"></a>00071 
+<a name="l00072"></a>00072 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_ima_cube_ks_test_create(cpl_plugin *) ;
+<a name="l00073"></a>00073 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_ima_cube_ks_test_exec(cpl_plugin *) ;
+<a name="l00074"></a>00074 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_ima_cube_ks_test_destroy(cpl_plugin *) ;
+<a name="l00075"></a>00075 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_ima_cube_ks_test(cpl_parameterlist *, cpl_frameset *) ;
+<a name="l00076"></a>00076 
+<a name="l00077"></a>00077 
+<a name="l00078"></a>00078 <span class="keyword">static</span> cpl_imagelist* create_cube_shift(
+<a name="l00079"></a>00079                 <span class="keywordtype">int</span> iSizeX,
+<a name="l00080"></a>00080                 <span class="keywordtype">int</span> iSizeY,
+<a name="l00081"></a>00081                 <span class="keywordtype">int</span> iPlanesNumber,
+<a name="l00082"></a>00082                 <span class="keywordtype">int</span> iFWHMX,
+<a name="l00083"></a>00083                 <span class="keywordtype">int</span> iFWHMY,
+<a name="l00084"></a>00084                 <span class="keywordtype">int</span> shiftX,
+<a name="l00085"></a>00085                 <span class="keywordtype">int</span> shiftY,
+<a name="l00086"></a>00086                 <span class="keywordtype">double</span> dSignal,
+<a name="l00087"></a>00087                 <span class="keywordtype">double</span> dBkgSignal,
+<a name="l00088"></a>00088                 <span class="keywordtype">double</span> dNoiseLvl,
+<a name="l00089"></a>00089                 <span class="keywordtype">double</span> dSignalDelta,
+<a name="l00090"></a>00090                 <span class="keywordtype">int</span> iDefectX,
+<a name="l00091"></a>00091                 <span class="keywordtype">int</span> iDefectY,
+<a name="l00092"></a>00092                 <span class="keywordtype">double</span> dDefectValue,
+<a name="l00093"></a>00093                 <span class="keywordtype">int</span> type
+<a name="l00094"></a>00094         );
+<a name="l00095"></a>00095 
+<a name="l00096"></a>00096 <span class="keyword">static</span> cpl_image* create_plane(
+<a name="l00097"></a>00097                 <span class="keywordtype">int</span> iSizeX,
+<a name="l00098"></a>00098                 <span class="keywordtype">int</span> iSizeY,
+<a name="l00099"></a>00099                 <span class="keywordtype">int</span> iFWHMX,
+<a name="l00100"></a>00100                 <span class="keywordtype">int</span> iFWHMY,
+<a name="l00101"></a>00101                 <span class="keywordtype">int</span> shiftX,
+<a name="l00102"></a>00102                 <span class="keywordtype">int</span> shiftY,
+<a name="l00103"></a>00103                 <span class="keywordtype">double</span> dSignal,
+<a name="l00104"></a>00104                 <span class="keywordtype">double</span> dBkgSignal,
+<a name="l00105"></a>00105                 <span class="keywordtype">double</span> dNoiseLvl
+<a name="l00106"></a>00106         );
+<a name="l00107"></a>00107 <span class="keyword">static</span> cpl_image* create_square_plane(
+<a name="l00108"></a>00108                 <span class="keywordtype">int</span> iSizeX,
+<a name="l00109"></a>00109                 <span class="keywordtype">int</span> iSizeY,
+<a name="l00110"></a>00110                 <span class="keywordtype">int</span> iHoleX,
+<a name="l00111"></a>00111                 <span class="keywordtype">int</span> iHoleY,
+<a name="l00112"></a>00112                 <span class="keywordtype">int</span> shiftX,
+<a name="l00113"></a>00113                 <span class="keywordtype">int</span> shiftY,
+<a name="l00114"></a>00114                 <span class="keywordtype">double</span> dSignal,
+<a name="l00115"></a>00115                 <span class="keywordtype">double</span> dBkgSignal,
+<a name="l00116"></a>00116                 <span class="keywordtype">double</span> dNoiseLvl);
+<a name="l00117"></a>00117 
+<a name="l00118"></a>00118 <span class="keyword">static</span> <span class="keywordtype">int</span> put_defect(cpl_image *pPlane, <span class="keywordtype">int</span> iDefectX, <span class="keywordtype">int</span> iDefectY, <span class="keywordtype">double</span> dDefectValue);
+<a name="l00119"></a>00119 <span class="keywordtype">void</span> putNAN(cpl_image *pPlane, <span class="keywordtype">int</span> iDefectX, <span class="keywordtype">int</span> iDefectY);
+<a name="l00120"></a>00120 
+<a name="l00121"></a>00121 
+<a name="l00122"></a>00122 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00123"></a>00123 <span class="comment">                            Static variables</span>
+<a name="l00124"></a>00124 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00125"></a>00125 
+<a name="l00126"></a>00126 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_utl_ima_cube_ks_test_description[] =
+<a name="l00127"></a>00127 <span class="stringliteral">"This recipe produces a test for kappa-sigma clipping\n"</span>
+<a name="l00128"></a>00128 <span class="stringliteral">"Information on relevant parameters can be found with\n"</span>
+<a name="l00129"></a>00129 <span class="stringliteral">"esorex --params sinfo_utl_ima_cube_ks_test\n"</span>
+<a name="l00130"></a>00130 <span class="stringliteral">"esorex --help sinfo_utl_ima_cube_ks_test\n"</span>
+<a name="l00131"></a>00131 <span class="stringliteral">"\n"</span>;
+<a name="l00132"></a>00132 
+<a name="l00133"></a>00133 <span class="keyword">static</span> <span class="keywordtype">char</span> PARAM_NAME_SIZE_X[] = <span class="stringliteral">"sinfoni.sinfo_utl_ima_cube_ks_test.size_x"</span>;
+<a name="l00134"></a>00134 <span class="keyword">static</span> <span class="keywordtype">char</span> PARAM_NAME_SIZE_Y[] = <span class="stringliteral">"sinfoni.sinfo_utl_ima_cube_ks_test.size_y"</span>;
+<a name="l00135"></a>00135 <span class="keyword">static</span> <span class="keywordtype">char</span> PARAM_NAME_FWHM_X[] = <span class="stringliteral">"sinfoni.sinfo_utl_ima_cube_ks_test.fwhm_x"</span>;
+<a name="l00136"></a>00136 <span class="keyword">static</span> <span class="keywordtype">char</span> PARAM_NAME_FWHM_Y[] = <span class="stringliteral">"sinfoni.sinfo_utl_ima_cube_ks_test.fwhm_y"</span>;
+<a name="l00137"></a>00137 <span class="keyword">static</span> <span class="keywordtype">char</span> PARAM_NAME_SIGNAL[] = <span class="stringliteral">"sinfoni.sinfo_utl_ima_cube_ks_test.total_signal"</span>;
+<a name="l00138"></a>00138 <span class="keyword">static</span> <span class="keywordtype">char</span> PARAM_NAME_SIGNAL_DELTA[] = <span class="stringliteral">"sinfoni.sinfo_utl_ima_cube_ks_test.total_signal_delta"</span>;
+<a name="l00139"></a>00139 <span class="keyword">static</span> <span class="keywordtype">char</span> PARAM_NAME_BKGSIG[] = <span class="stringliteral">"sinfoni.sinfo_utl_ima_cube_ks_test.bkg_signal"</span>;
+<a name="l00140"></a>00140 <span class="keyword">static</span> <span class="keywordtype">char</span> PARAM_NAME_NOISEL[] = <span class="stringliteral">"sinfoni.sinfo_utl_ima_cube_ks_test.noise_level"</span>;
+<a name="l00141"></a>00141 <span class="keyword">static</span> <span class="keywordtype">char</span> PARAM_NAME_DEFECT_X[] = <span class="stringliteral">"sinfoni.sinfo_utl_ima_cube_ks_test.defect_x"</span>;
+<a name="l00142"></a>00142 <span class="keyword">static</span> <span class="keywordtype">char</span> PARAM_NAME_DEFECT_Y[] = <span class="stringliteral">"sinfoni.sinfo_utl_ima_cube_ks_test.defect_y"</span>;
+<a name="l00143"></a>00143 <span class="keyword">static</span> <span class="keywordtype">char</span> PARAM_NAME_DEFECT_SIGNAL[] = <span class="stringliteral">"sinfoni.sinfo_utl_ima_cube_ks_test.defect_signal"</span>;
+<a name="l00144"></a>00144 <span class="keyword">static</span> <span class="keywordtype">char</span> PARAM_NAME_DEFECT_NUMBER[] = <span class="stringliteral">"sinfoni.sinfo_utl_ima_cube_ks_test.defect_number"</span>;
+<a name="l00145"></a>00145 <span class="keyword">static</span> <span class="keywordtype">char</span> PARAM_NAME_CUBES_NUMBER[] = <span class="stringliteral">"sinfoni.sinfo_utl_ima_cube_ks_test.cubes_number"</span>;
+<a name="l00146"></a>00146 <span class="keyword">static</span> <span class="keywordtype">char</span> PARAM_NAME_PLANES_NUMBER[] = <span class="stringliteral">"sinfoni.sinfo_utl_ima_cube_ks_test.planes_number"</span>;
+<a name="l00147"></a>00147 
+<a name="l00148"></a>00148 
+<a name="l00149"></a>00149 <span class="keyword">static</span> <span class="keywordtype">char</span> RECIPE_NAME[] = <span class="stringliteral">"sinfoni.sinfo_utl_ima_cube_ks_test"</span>;
+<a name="l00150"></a>00150 
+<a name="l00151"></a>00151 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00152"></a>00152 <span class="comment">                                Functions code</span>
+<a name="l00153"></a>00153 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00154"></a>00154 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00158"></a>00158 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00159"></a>00159 
+<a name="l00161"></a>00161 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00169"></a>00169 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00170"></a><a class="code" href="group__sinfo__utl__ima__cube__ks__test.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693">00170</a> <span class="keywordtype">int</span> <a class="code" href="group__sinfo__rec__detlin.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693" title="Build the list of available plugins, for this module.">cpl_plugin_get_info</a>(cpl_pluginlist * list)
+<a name="l00171"></a>00171 {
+<a name="l00172"></a>00172     cpl_recipe  *   recipe = cpl_calloc(1, <span class="keyword">sizeof</span> *recipe ) ;
+<a name="l00173"></a>00173     cpl_plugin  *   plugin = &recipe->interface ;
+<a name="l00174"></a>00174 
+<a name="l00175"></a>00175     cpl_plugin_init(plugin,
+<a name="l00176"></a>00176                     CPL_PLUGIN_API,
+<a name="l00177"></a>00177                     SINFONI_BINARY_VERSION,
+<a name="l00178"></a>00178                     CPL_PLUGIN_TYPE_RECIPE,
+<a name="l00179"></a>00179                     <span class="stringliteral">"sinfo_utl_ima_cube_ks_test"</span>,
+<a name="l00180"></a>00180                     <span class="stringliteral">"Test cube coaddition with kappa-sigma clip of ouliers"</span>,
+<a name="l00181"></a>00181                     sinfo_utl_ima_cube_ks_test_description,
+<a name="l00182"></a>00182                     <span class="stringliteral">"Konstantin Mirny"</span>,
+<a name="l00183"></a>00183                     <span class="stringliteral">"kmirny at eso.org"</span>,
+<a name="l00184"></a>00184                     sinfo_get_license(),
+<a name="l00185"></a>00185                     sinfo_utl_ima_cube_ks_test_create,
+<a name="l00186"></a>00186                     sinfo_utl_ima_cube_ks_test_exec,
+<a name="l00187"></a>00187                     sinfo_utl_ima_cube_ks_test_destroy) ;
+<a name="l00188"></a>00188 
+<a name="l00189"></a>00189     cpl_pluginlist_append(list, plugin) ;
+<a name="l00190"></a>00190 
+<a name="l00191"></a>00191     <span class="keywordflow">return</span> 0;
+<a name="l00192"></a>00192 }
+<a name="l00193"></a>00193 
+<a name="l00194"></a>00194 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00203"></a>00203 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00204"></a>00204 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_ima_cube_ks_test_create(cpl_plugin * plugin)
+<a name="l00205"></a>00205 {
+<a name="l00206"></a>00206     <span class="keyword">const</span> <span class="keywordtype">int</span> CUBES_NUMBER      = 5;
+<a name="l00207"></a>00207     <span class="keyword">const</span> <span class="keywordtype">int</span> PLANES_NUMBER     = 10;
+<a name="l00208"></a>00208     <span class="keyword">const</span> <span class="keywordtype">int</span> SIZE_X_DEFAULT    = 64;
+<a name="l00209"></a>00209     <span class="keyword">const</span> <span class="keywordtype">int</span> SIZE_Y_DEFAULT    = 64;
+<a name="l00210"></a>00210     <span class="keyword">const</span> <span class="keywordtype">int</span> FWHM_X            = 24;
+<a name="l00211"></a>00211     <span class="keyword">const</span> <span class="keywordtype">int</span> FWHM_Y            = 24;
+<a name="l00212"></a>00212     <span class="keyword">const</span> <span class="keywordtype">double</span> TOTAL_SIGNAL   = 1E6;
+<a name="l00213"></a>00213     <span class="keyword">const</span> <span class="keywordtype">double</span> SIGNAL_DELTA   = 1E5;
+<a name="l00214"></a>00214     <span class="keyword">const</span> <span class="keywordtype">double</span> BKG_SIGNAL     = 250.; <span class="comment">// 250</span>
+<a name="l00215"></a>00215     <span class="keyword">const</span> <span class="keywordtype">double</span> NOISE_VALUE    = 100;
+<a name="l00216"></a>00216     <span class="keyword">const</span> <span class="keywordtype">int</span> DEFECT_X          = 42;
+<a name="l00217"></a>00217     <span class="keyword">const</span> <span class="keywordtype">int</span> DEFECT_Y          = 42;
+<a name="l00218"></a>00218     <span class="keyword">const</span> <span class="keywordtype">double</span> DEFECT_SIGNAL  = 400;
+<a name="l00219"></a>00219     <span class="keyword">const</span> <span class="keywordtype">int</span> DEFECT_NUMBER     = 1;
+<a name="l00220"></a>00220 
+<a name="l00221"></a>00221     cpl_recipe      * recipe ;
+<a name="l00222"></a>00222     cpl_parameter   * p ;
+<a name="l00223"></a>00223 
+<a name="l00224"></a>00224     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00225"></a>00225     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
+<a name="l00226"></a>00226         recipe = (cpl_recipe *)plugin ;
+<a name="l00227"></a>00227     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00228"></a>00228     cpl_error_reset();
+<a name="l00229"></a>00229     <a class="code" href="group__irplib__utils.html#gaf9d392144014e2363054bc3f83c8e47e" title="Reset IRPLIB state.">irplib_reset</a>();
+<a name="l00230"></a>00230 
+<a name="l00231"></a>00231     <span class="comment">/* Create the parameters list in the cpl_recipe object */</span>
+<a name="l00232"></a>00232     recipe->parameters = cpl_parameterlist_new() ;
+<a name="l00233"></a>00233 
+<a name="l00234"></a>00234     <span class="comment">/* Fill the parameters list */</span>
+<a name="l00235"></a>00235     <span class="comment">/* --stropt */</span>
+<a name="l00236"></a>00236 <span class="comment">/*    p = cpl_parameter_new_value("sinfoni.sinfo_utl_ima_cube_ks_test.op",</span>
+<a name="l00237"></a>00237 <span class="comment">                                CPL_TYPE_STRING,</span>
+<a name="l00238"></a>00238 <span class="comment">                                "A possible operation",</span>
+<a name="l00239"></a>00239 <span class="comment">                                "sinfoni.sinfo_utl_ima_cube_ks_test","+");</span>
+<a name="l00240"></a>00240 <span class="comment">    cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "op") ;</span>
+<a name="l00241"></a>00241 <span class="comment">    cpl_parameterlist_append(recipe->parameters, p) ;*/</span>
+<a name="l00242"></a>00242 
+<a name="l00243"></a>00243     <span class="comment">/* --size_x */</span>
+<a name="l00244"></a>00244     p = cpl_parameter_new_value(PARAM_NAME_SIZE_X,
+<a name="l00245"></a>00245             CPL_TYPE_INT, <span class="stringliteral">"size X axis"</span>, RECIPE_NAME, SIZE_X_DEFAULT) ;
+<a name="l00246"></a>00246     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"size_x"</span>) ;
+<a name="l00247"></a>00247     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00248"></a>00248 
+<a name="l00249"></a>00249     <span class="comment">/* --size_y */</span>
+<a name="l00250"></a>00250     p = cpl_parameter_new_value(PARAM_NAME_SIZE_Y,
+<a name="l00251"></a>00251             CPL_TYPE_INT, <span class="stringliteral">"size Y axis"</span>, RECIPE_NAME, SIZE_Y_DEFAULT) ;
+<a name="l00252"></a>00252     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"size_y"</span>) ;
+<a name="l00253"></a>00253     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00254"></a>00254 
+<a name="l00255"></a>00255     <span class="comment">/* --fwhm_x */</span>
+<a name="l00256"></a>00256     p = cpl_parameter_new_value(PARAM_NAME_FWHM_X,
+<a name="l00257"></a>00257             CPL_TYPE_INT, <span class="stringliteral">"FWHM X axis"</span>, RECIPE_NAME, FWHM_X) ;
+<a name="l00258"></a>00258     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"fwhm_x"</span>) ;
+<a name="l00259"></a>00259     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00260"></a>00260 
+<a name="l00261"></a>00261     <span class="comment">/* --fwhm_y */</span>
+<a name="l00262"></a>00262     p = cpl_parameter_new_value(PARAM_NAME_FWHM_Y,
+<a name="l00263"></a>00263             CPL_TYPE_INT, <span class="stringliteral">"FWHM Y axis"</span>, RECIPE_NAME, FWHM_Y) ;
+<a name="l00264"></a>00264     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"fwhm_y"</span>) ;
+<a name="l00265"></a>00265     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00266"></a>00266 
+<a name="l00267"></a>00267     <span class="comment">/* --total_signal */</span>
+<a name="l00268"></a>00268     p = cpl_parameter_new_value(PARAM_NAME_SIGNAL,
+<a name="l00269"></a>00269             CPL_TYPE_DOUBLE, <span class="stringliteral">"Total signal value"</span>, RECIPE_NAME, TOTAL_SIGNAL) ;
+<a name="l00270"></a>00270     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"total_signal"</span>) ;
+<a name="l00271"></a>00271     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00272"></a>00272 
+<a name="l00273"></a>00273     <span class="comment">/* --bkg_signal */</span>
+<a name="l00274"></a>00274     p = cpl_parameter_new_value(PARAM_NAME_BKGSIG,
+<a name="l00275"></a>00275             CPL_TYPE_DOUBLE, <span class="stringliteral">"background signal level"</span>, RECIPE_NAME, BKG_SIGNAL) ;
+<a name="l00276"></a>00276     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"bkg_signal"</span>) ;
+<a name="l00277"></a>00277     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00278"></a>00278 
+<a name="l00279"></a>00279     <span class="comment">/* --noise_level */</span>
+<a name="l00280"></a>00280     p = cpl_parameter_new_value(PARAM_NAME_NOISEL,
+<a name="l00281"></a>00281             CPL_TYPE_DOUBLE, <span class="stringliteral">"Noise level"</span>, RECIPE_NAME, NOISE_VALUE) ;
+<a name="l00282"></a>00282     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"noise_level"</span>) ;
+<a name="l00283"></a>00283     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00284"></a>00284 
+<a name="l00285"></a>00285     <span class="comment">/* --cubes_number */</span>
+<a name="l00286"></a>00286     p = cpl_parameter_new_value(PARAM_NAME_CUBES_NUMBER,
+<a name="l00287"></a>00287             CPL_TYPE_INT, <span class="stringliteral">"Number of cubes"</span>, RECIPE_NAME, CUBES_NUMBER) ;
+<a name="l00288"></a>00288     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"cubes_number"</span>) ;
+<a name="l00289"></a>00289     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00290"></a>00290 
+<a name="l00291"></a>00291     <span class="comment">/* --planes_number */</span>
+<a name="l00292"></a>00292     p = cpl_parameter_new_value(PARAM_NAME_PLANES_NUMBER,
+<a name="l00293"></a>00293             CPL_TYPE_INT, <span class="stringliteral">"Number of images for each cube"</span>, RECIPE_NAME, PLANES_NUMBER) ;
+<a name="l00294"></a>00294     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"planes_number"</span>) ;
+<a name="l00295"></a>00295     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00296"></a>00296 
+<a name="l00297"></a>00297     <span class="comment">/* --signal_delta */</span>
+<a name="l00298"></a>00298         p = cpl_parameter_new_value(PARAM_NAME_SIGNAL_DELTA,
+<a name="l00299"></a>00299                 CPL_TYPE_DOUBLE, <span class="stringliteral">"Change of the signal for the next plane inside a cube"</span>, RECIPE_NAME, SIGNAL_DELTA) ;
+<a name="l00300"></a>00300         cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"total_signal_delta"</span>) ;
+<a name="l00301"></a>00301         cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00302"></a>00302 
+<a name="l00303"></a>00303     <span class="comment">/* --defect_x */</span>
+<a name="l00304"></a>00304         p = cpl_parameter_new_value(PARAM_NAME_DEFECT_X,
+<a name="l00305"></a>00305                 CPL_TYPE_INT, <span class="stringliteral">"X position of the bad pixel"</span>, RECIPE_NAME, DEFECT_X) ;
+<a name="l00306"></a>00306         cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"defect_x"</span>) ;
+<a name="l00307"></a>00307         cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00308"></a>00308 
+<a name="l00309"></a>00309     <span class="comment">/* --defect_x */</span>
+<a name="l00310"></a>00310         p = cpl_parameter_new_value(PARAM_NAME_DEFECT_Y,
+<a name="l00311"></a>00311                 CPL_TYPE_INT, <span class="stringliteral">"Y position of the bad pixel"</span>, RECIPE_NAME, DEFECT_Y) ;
+<a name="l00312"></a>00312         cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"defect_y"</span>) ;
+<a name="l00313"></a>00313         cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00314"></a>00314 
+<a name="l00315"></a>00315     <span class="comment">/* --defect_signal */</span>
+<a name="l00316"></a>00316         p = cpl_parameter_new_value(PARAM_NAME_DEFECT_SIGNAL,
+<a name="l00317"></a>00317                 CPL_TYPE_DOUBLE, <span class="stringliteral">"signal value of the bad pixel"</span>, RECIPE_NAME, DEFECT_SIGNAL) ;
+<a name="l00318"></a>00318         cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"defect_signal"</span>) ;
+<a name="l00319"></a>00319         cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00320"></a>00320 
+<a name="l00321"></a>00321     <span class="comment">/* --defect_number */</span>
+<a name="l00322"></a>00322         p = cpl_parameter_new_value(PARAM_NAME_DEFECT_NUMBER,
+<a name="l00323"></a>00323                 CPL_TYPE_INT, <span class="stringliteral">"Number of planes in a cube with a bad pixel"</span>, RECIPE_NAME, DEFECT_NUMBER) ;
+<a name="l00324"></a>00324         cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"defect_number"</span>) ;
+<a name="l00325"></a>00325         cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00326"></a>00326 
+<a name="l00327"></a>00327     <span class="comment">/* Return */</span>
+<a name="l00328"></a>00328     <span class="keywordflow">return</span> 0;
+<a name="l00329"></a>00329 }
+<a name="l00330"></a>00330 
+<a name="l00331"></a>00331 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00337"></a>00337 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00338"></a>00338 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_ima_cube_ks_test_exec(cpl_plugin * plugin)
+<a name="l00339"></a>00339 {
+<a name="l00340"></a>00340     cpl_recipe  *   recipe ;
+<a name="l00341"></a>00341      <span class="keywordtype">int</span> code=0;
+<a name="l00342"></a>00342      cpl_errorstate initial_errorstate = cpl_errorstate_get();
+<a name="l00343"></a>00343 
+<a name="l00344"></a>00344     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00345"></a>00345     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
+<a name="l00346"></a>00346         recipe = (cpl_recipe *)plugin ;
+<a name="l00347"></a>00347     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00348"></a>00348     cpl_error_reset();
+<a name="l00349"></a>00349     <a class="code" href="group__irplib__utils.html#gaf9d392144014e2363054bc3f83c8e47e" title="Reset IRPLIB state.">irplib_reset</a>();
+<a name="l00350"></a>00350     code = sinfo_utl_ima_cube_ks_test(recipe->parameters, recipe->frames) ;
+<a name="l00351"></a>00351 
+<a name="l00352"></a>00352 
+<a name="l00353"></a>00353     <span class="keywordflow">if</span> (!cpl_errorstate_is_equal(initial_errorstate)) {
+<a name="l00354"></a>00354         <span class="comment">/* Dump the error history since recipe execution start.</span>
+<a name="l00355"></a>00355 <span class="comment">           At this point the recipe cannot recover from the error */</span>
+<a name="l00356"></a>00356         cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
+<a name="l00357"></a>00357     }
+<a name="l00358"></a>00358 
+<a name="l00359"></a>00359     <span class="keywordflow">return</span> code ;
+<a name="l00360"></a>00360 }
+<a name="l00361"></a>00361 
+<a name="l00362"></a>00362 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00368"></a>00368 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00369"></a>00369 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_ima_cube_ks_test_destroy(cpl_plugin * plugin)
+<a name="l00370"></a>00370 {
+<a name="l00371"></a>00371     cpl_recipe  *   recipe ;
+<a name="l00372"></a>00372 
+<a name="l00373"></a>00373     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00374"></a>00374     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
+<a name="l00375"></a>00375         recipe = (cpl_recipe *)plugin ;
+<a name="l00376"></a>00376     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00377"></a>00377 
+<a name="l00378"></a>00378     cpl_parameterlist_delete(recipe->parameters) ;
+<a name="l00379"></a>00379     <span class="keywordflow">return</span> 0 ;
+<a name="l00380"></a>00380 }
+<a name="l00381"></a>00381 
+<a name="l00382"></a>00382 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00389"></a>00389 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00390"></a>00390 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00391"></a>00391 sinfo_utl_ima_cube_ks_test( cpl_parameterlist   *   parlist,
+<a name="l00392"></a>00392         cpl_frameset        *   framelist)
+<a name="l00393"></a>00393 {
+<a name="l00394"></a>00394     <span class="comment">// parameters</span>
+<a name="l00395"></a>00395     <span class="keywordtype">int</span>     iSizeX = 0;
+<a name="l00396"></a>00396     <span class="keywordtype">int</span>     iSizeY = 0;
+<a name="l00397"></a>00397     <span class="keywordtype">int</span>     iFWHMX = 0;
+<a name="l00398"></a>00398     <span class="keywordtype">int</span>     iFWHMY = 0;
+<a name="l00399"></a>00399     <span class="keywordtype">int</span>     iGlobalSizeX = 0;
+<a name="l00400"></a>00400     <span class="keywordtype">int</span>     iGlobalSizeY = 0;
+<a name="l00401"></a>00401     <span class="keywordtype">int</span>     shiftMultX = 2;
+<a name="l00402"></a>00402     <span class="keywordtype">int</span>     shiftMultY = 2;
+<a name="l00403"></a>00403     <span class="keywordtype">int</span>*    pOffsetX = 0;
+<a name="l00404"></a>00404     <span class="keywordtype">int</span>*    pOffsetY = 0;
+<a name="l00405"></a>00405     <span class="keywordtype">double</span> dSignal = 0;
+<a name="l00406"></a>00406     <span class="keywordtype">double</span> dBkgSignal = 0;
+<a name="l00407"></a>00407     <span class="keywordtype">double</span> dNoiseLvl = 0;
+<a name="l00408"></a>00408 
+<a name="l00409"></a>00409     <span class="keywordtype">double</span> dSignalDelta = 0;
+<a name="l00410"></a>00410     <span class="keywordtype">int</span> iDefectX = 0;
+<a name="l00411"></a>00411     <span class="keywordtype">int</span> iDefectY = 0;
+<a name="l00412"></a>00412     <span class="keywordtype">double</span> dDefectValue = 0;
+<a name="l00413"></a>00413     <span class="keywordtype">int</span> iDefectNumber = 0;
+<a name="l00414"></a>00414     <span class="keywordtype">int</span> iCubesNumber = 0;
+<a name="l00415"></a>00415     <span class="keywordtype">int</span> iPlanesNumber = 0;
+<a name="l00417"></a>00417     <span class="keywordtype">int</span> z = 0;
+<a name="l00418"></a>00418     <span class="keywordtype">int</span> x = 0;
+<a name="l00419"></a>00419     <span class="keywordtype">int</span> y = 0;
+<a name="l00420"></a>00420     <span class="keyword">const</span> <span class="keywordtype">double</span> kappa = 3;
+<a name="l00421"></a>00421     <span class="keyword">const</span> <span class="keywordtype">char</span>          *   name_o = NULL ;
+<a name="l00422"></a>00422     cpl_parameter       *   param = NULL ;
+<a name="l00423"></a>00423     cpl_propertylist    *   plist = NULL ;
+<a name="l00424"></a>00424     cpl_frame           *   product_frame = NULL;
+<a name="l00425"></a>00425     cpl_imagelist       ** ppCubes = NULL;
+<a name="l00426"></a>00426     cpl_imagelist       *  pResult = NULL;
+<a name="l00427"></a>00427     <span class="keywordtype">double</span>          *   exptimes = NULL;
+<a name="l00428"></a>00428     cpl_imagelist       *   mask = NULL;
+<a name="l00429"></a>00429     sinfo_msg(<span class="stringliteral">"Welcome to SINFONI Pipeline release %d.%d.%d"</span>,
+<a name="l00430"></a>00430     SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
+<a name="l00431"></a>00431     ck0(sinfo_dfs_set_groups(framelist),<span class="stringliteral">"Cannot indentify RAW and CALIB frames"</span>);
+<a name="l00432"></a>00432 
+<a name="l00433"></a>00433 
+<a name="l00434"></a>00434 <span class="comment">/* HOW TO RETRIEVE INPUT PARAMETERS */</span>
+<a name="l00435"></a>00435       <span class="comment">/* --size_x */</span>
+<a name="l00436"></a>00436       check_nomsg(param=cpl_parameterlist_find(parlist,
+<a name="l00437"></a>00437                                                PARAM_NAME_SIZE_X));
+<a name="l00438"></a>00438       check_nomsg(iSizeX=cpl_parameter_get_int(param));
+<a name="l00439"></a>00439 
+<a name="l00440"></a>00440       <span class="comment">/* --size_y */</span>
+<a name="l00441"></a>00441       check_nomsg(param=cpl_parameterlist_find(parlist,
+<a name="l00442"></a>00442                                                PARAM_NAME_SIZE_Y));
+<a name="l00443"></a>00443       check_nomsg(iSizeY=cpl_parameter_get_int(param));
+<a name="l00444"></a>00444 
+<a name="l00445"></a>00445       <span class="comment">/* --fwhm_x */</span>
+<a name="l00446"></a>00446       check_nomsg(param=cpl_parameterlist_find(parlist,
+<a name="l00447"></a>00447                                                PARAM_NAME_FWHM_X));
+<a name="l00448"></a>00448       check_nomsg(iFWHMX=cpl_parameter_get_int(param));
+<a name="l00449"></a>00449 
+<a name="l00450"></a>00450       <span class="comment">/* --fwhm_y */</span>
+<a name="l00451"></a>00451       check_nomsg(param=cpl_parameterlist_find(parlist,
+<a name="l00452"></a>00452                                                PARAM_NAME_FWHM_Y));
+<a name="l00453"></a>00453       check_nomsg(iFWHMY=cpl_parameter_get_int(param));
+<a name="l00454"></a>00454 
+<a name="l00455"></a>00455       <span class="comment">/* --total_signal */</span>
+<a name="l00456"></a>00456       check_nomsg(param=cpl_parameterlist_find(parlist,
+<a name="l00457"></a>00457                                                PARAM_NAME_SIGNAL));
+<a name="l00458"></a>00458       check_nomsg(dSignal=cpl_parameter_get_double(param));
+<a name="l00459"></a>00459 
+<a name="l00460"></a>00460       <span class="comment">/* --bkg_signal */</span>
+<a name="l00461"></a>00461       check_nomsg(param=cpl_parameterlist_find(parlist,
+<a name="l00462"></a>00462                                                PARAM_NAME_BKGSIG));
+<a name="l00463"></a>00463       check_nomsg(dBkgSignal=cpl_parameter_get_double(param));
+<a name="l00464"></a>00464 
+<a name="l00465"></a>00465       <span class="comment">/* --noise_level */</span>
+<a name="l00466"></a>00466       check_nomsg(param=cpl_parameterlist_find(parlist,
+<a name="l00467"></a>00467                                                PARAM_NAME_NOISEL));
+<a name="l00468"></a>00468       check_nomsg(dNoiseLvl=cpl_parameter_get_double(param));
+<a name="l00469"></a>00469 
+<a name="l00470"></a>00470       <span class="comment">/* --cubes_number */</span>
+<a name="l00471"></a>00471       check_nomsg(param=cpl_parameterlist_find(parlist,
+<a name="l00472"></a>00472                                                PARAM_NAME_CUBES_NUMBER));
+<a name="l00473"></a>00473       check_nomsg(iCubesNumber=cpl_parameter_get_int(param));
+<a name="l00474"></a>00474 
+<a name="l00475"></a>00475       <span class="comment">/* --planes_number */</span>
+<a name="l00476"></a>00476       check_nomsg(param=cpl_parameterlist_find(parlist,
+<a name="l00477"></a>00477                                                PARAM_NAME_PLANES_NUMBER));
+<a name="l00478"></a>00478       check_nomsg(iPlanesNumber=cpl_parameter_get_int(param));
+<a name="l00479"></a>00479 
+<a name="l00480"></a>00480       <span class="comment">/* -signal_delta */</span>
+<a name="l00481"></a>00481       check_nomsg(param=cpl_parameterlist_find(parlist,
+<a name="l00482"></a>00482                                                PARAM_NAME_SIGNAL_DELTA));
+<a name="l00483"></a>00483       check_nomsg(dSignalDelta=cpl_parameter_get_double(param));
+<a name="l00484"></a>00484 
+<a name="l00485"></a>00485       <span class="comment">/* --defect_x */</span>
+<a name="l00486"></a>00486       check_nomsg(param=cpl_parameterlist_find(parlist,
+<a name="l00487"></a>00487                                                PARAM_NAME_DEFECT_X));
+<a name="l00488"></a>00488       check_nomsg(iDefectX=cpl_parameter_get_int(param));
+<a name="l00489"></a>00489 
+<a name="l00490"></a>00490       <span class="comment">/* --defect_y */</span>
+<a name="l00491"></a>00491       check_nomsg(param=cpl_parameterlist_find(parlist,
+<a name="l00492"></a>00492                                                PARAM_NAME_DEFECT_Y));
+<a name="l00493"></a>00493       check_nomsg(iDefectY=cpl_parameter_get_int(param));
+<a name="l00494"></a>00494 
+<a name="l00495"></a>00495       <span class="comment">/* --defect_value */</span>
+<a name="l00496"></a>00496       check_nomsg(param=cpl_parameterlist_find(parlist,
+<a name="l00497"></a>00497                                                PARAM_NAME_DEFECT_SIGNAL));
+<a name="l00498"></a>00498       check_nomsg(dDefectValue=cpl_parameter_get_double(param));
+<a name="l00499"></a>00499 
+<a name="l00500"></a>00500       <span class="comment">/* --defect_number */</span>
+<a name="l00501"></a>00501       check_nomsg(param=cpl_parameterlist_find(parlist,
+<a name="l00502"></a>00502                                                PARAM_NAME_DEFECT_NUMBER));
+<a name="l00503"></a>00503       check_nomsg(iDefectNumber=cpl_parameter_get_int(param));
+<a name="l00504"></a>00504 
+<a name="l00505"></a>00505 
+<a name="l00506"></a>00506     <span class="comment">/* HOW TO GET THE VALUE OF A FITS KEYWORD */</span>
+<a name="l00507"></a>00507     check(plist=cpl_propertylist_new(),<span class="stringliteral">"Cannot create a Property List"</span>);
+<a name="l00508"></a>00508 
+<a name="l00509"></a>00509     <span class="comment">/* Now performing the data reduction */</span>
+<a name="l00510"></a>00510     <span class="comment">/* Let's generate one image for the example */</span>
+<a name="l00511"></a>00511 
+<a name="l00512"></a>00512     <span class="comment">// 1. Create cubes</span>
+<a name="l00513"></a>00513     ppCubes = (cpl_imagelist**)cpl_malloc(<span class="keyword">sizeof</span>(cpl_imagelist*) * (iCubesNumber + 2)); <span class="comment">// +1 for the result, +1 for the mask</span>
+<a name="l00514"></a>00514     pOffsetX = cpl_malloc(<span class="keyword">sizeof</span>(<span class="keywordtype">int</span>) * iCubesNumber);
+<a name="l00515"></a>00515     pOffsetY = cpl_malloc(<span class="keyword">sizeof</span>(<span class="keywordtype">int</span>) * iCubesNumber);
+<a name="l00516"></a>00516 <span class="comment">//    iGlobalSizeX = iSizeX + (iCubesNumber-1) * shiftMultX;// it's not a fair calculation - only for test</span>
+<a name="l00517"></a>00517 <span class="comment">//    iGlobalSizeY = iSizeY + (iCubesNumber-1) * shiftMultY;</span>
+<a name="l00518"></a>00518     sinfo_msg(<span class="stringliteral">"Creating cubes...."</span>);
+<a name="l00519"></a>00519     <span class="keywordflow">for</span> (z = 0; z < iCubesNumber; z++)
+<a name="l00520"></a>00520     {
+<a name="l00521"></a>00521         pOffsetX[z] = shiftMultX*z;<span class="comment">// + ((z%3) - 3) * shiftMultX ;</span>
+<a name="l00522"></a>00522         pOffsetY[z] = shiftMultY*z;<span class="comment">// + (((z-2)%3) - 1) * shiftMultY / 2;</span>
+<a name="l00523"></a>00523         cpl_msg_warning(cpl_func, <span class="stringliteral">"cube [%d] offset[%d:%d]"</span>, z,pOffsetX[z], pOffsetY[z] );
+<a name="l00524"></a>00524         cpl_imagelist* pCube =
+<a name="l00525"></a>00525         create_cube_shift(
+<a name="l00526"></a>00526                 iSizeX,
+<a name="l00527"></a>00527                 iSizeY,
+<a name="l00528"></a>00528                 iPlanesNumber,
+<a name="l00529"></a>00529                 iFWHMX,
+<a name="l00530"></a>00530                 iFWHMY,
+<a name="l00531"></a>00531                 -pOffsetX[z],
+<a name="l00532"></a>00532                 -pOffsetY[z],
+<a name="l00533"></a>00533                 dSignal,
+<a name="l00534"></a>00534                 dBkgSignal,
+<a name="l00535"></a>00535                 dNoiseLvl,
+<a name="l00536"></a>00536                 dSignalDelta,
+<a name="l00537"></a>00537                 iDefectX,
+<a name="l00538"></a>00538                 iDefectY,
+<a name="l00539"></a>00539                 (z < iDefectNumber) ? dDefectValue : 0,
+<a name="l00540"></a>00540                 0
+<a name="l00541"></a>00541         );
+<a name="l00542"></a>00542         ppCubes[z] = pCube;
+<a name="l00543"></a>00543 
+<a name="l00544"></a>00544         <span class="comment">// fill NAN areas</span>
+<a name="l00545"></a>00545 <span class="comment">/*      cpl_image* pImage = cpl_imagelist_get(pCube, 0);</span>
+<a name="l00546"></a>00546 <span class="comment">        switch(z)</span>
+<a name="l00547"></a>00547 <span class="comment">        {</span>
+<a name="l00548"></a>00548 <span class="comment">        case 0:</span>
+<a name="l00549"></a>00549 <span class="comment">            {</span>
+<a name="l00550"></a>00550 <span class="comment">                for (x = 1; x <=iSizeX; x++)</span>
+<a name="l00551"></a>00551 <span class="comment">                {</span>
+<a name="l00552"></a>00552 <span class="comment">                    for (y = 1; y <= 16; y++)</span>
+<a name="l00553"></a>00553 <span class="comment">                    {</span>
+<a name="l00554"></a>00554 <span class="comment">                        check_nomsg(cpl_image_set(pImage, x, y, sqrt(-1)));</span>
+<a name="l00555"></a>00555 <span class="comment">                        check_nomsg(cpl_image_set(pImage, x, y+48, sqrt(-1)));</span>
+<a name="l00556"></a>00556 <span class="comment">                    }</span>
+<a name="l00557"></a>00557 <span class="comment">                }</span>
+<a name="l00558"></a>00558 <span class="comment">            }</span>
+<a name="l00559"></a>00559 <span class="comment">            break;</span>
+<a name="l00560"></a>00560 <span class="comment">        case 1:</span>
+<a name="l00561"></a>00561 <span class="comment">            {</span>
+<a name="l00562"></a>00562 <span class="comment">                for (x = 1; x <=iSizeX; x++)</span>
+<a name="l00563"></a>00563 <span class="comment">                {</span>
+<a name="l00564"></a>00564 <span class="comment">                    for (y = 1; y <= 8; y++)</span>
+<a name="l00565"></a>00565 <span class="comment">                    {</span>
+<a name="l00566"></a>00566 <span class="comment">                        check_nomsg(cpl_image_set(pImage, x, y, sqrt(-1)));</span>
+<a name="l00567"></a>00567 <span class="comment">                    }</span>
+<a name="l00568"></a>00568 <span class="comment">                    for (y = 24; y <= iSizeY; y++)</span>
+<a name="l00569"></a>00569 <span class="comment">                    {</span>
+<a name="l00570"></a>00570 <span class="comment">                        check_nomsg(cpl_image_set(pImage, x, y, sqrt(-1)));</span>
+<a name="l00571"></a>00571 <span class="comment"></span>
+<a name="l00572"></a>00572 <span class="comment">                    }</span>
+<a name="l00573"></a>00573 <span class="comment">                }</span>
+<a name="l00574"></a>00574 <span class="comment">            }</span>
+<a name="l00575"></a>00575 <span class="comment">            break;</span>
+<a name="l00576"></a>00576 <span class="comment">        }</span>
+<a name="l00577"></a>00577 <span class="comment">*/</span>
+<a name="l00578"></a>00578     }
+<a name="l00579"></a>00579     <span class="comment">// 2. make a kappa-sigma clipping</span>
+<a name="l00580"></a>00580 <span class="comment">/*    pResult =  kappa_sigma(</span>
+<a name="l00581"></a>00581 <span class="comment">            iSizeX,</span>
+<a name="l00582"></a>00582 <span class="comment">            iSizeY,</span>
+<a name="l00583"></a>00583 <span class="comment">            iCubesNumber,</span>
+<a name="l00584"></a>00584 <span class="comment">            iPlanesNumber,</span>
+<a name="l00585"></a>00585 <span class="comment">            kappa,</span>
+<a name="l00586"></a>00586 <span class="comment">            NULL,</span>
+<a name="l00587"></a>00587 <span class="comment">            ppCubes);*/</span>
+<a name="l00588"></a>00588 
+<a name="l00589"></a>00589     <span class="comment">// prepare offset arrays</span>
+<a name="l00590"></a>00590     sinfo_msg(<span class="stringliteral">"Kappa-sigma...."</span>);
+<a name="l00591"></a>00591 
+<a name="l00592"></a>00592     <span class="comment">// determine size of the coadded cube</span>
+<a name="l00593"></a>00593     <span class="keyword">const</span> <span class="keywordtype">int</span> BIG_ENOUGH_INT = 65535;
+<a name="l00594"></a>00594     <span class="keywordtype">int</span> xmax = -BIG_ENOUGH_INT;
+<a name="l00595"></a>00595     <span class="keywordtype">int</span> ymax = -BIG_ENOUGH_INT;
+<a name="l00596"></a>00596     <span class="keywordtype">int</span> xmin = BIG_ENOUGH_INT;
+<a name="l00597"></a>00597     <span class="keywordtype">int</span> ymin = BIG_ENOUGH_INT;
+<a name="l00598"></a>00598     <span class="keywordflow">for</span> (z = 0; z < iCubesNumber; z++)
+<a name="l00599"></a>00599     {
+<a name="l00600"></a>00600 
+<a name="l00601"></a>00601         <span class="keywordtype">int</span> localMaxX = iSizeX + pOffsetX[z];
+<a name="l00602"></a>00602         <span class="keywordtype">int</span> localMaxY = iSizeY + pOffsetY[z];
+<a name="l00603"></a>00603         <span class="keywordtype">int</span> localMinX = pOffsetX[z];
+<a name="l00604"></a>00604         <span class="keywordtype">int</span> localMinY = pOffsetY[z];
+<a name="l00605"></a>00605 
+<a name="l00606"></a>00606         <span class="keywordflow">if</span>(localMaxX > xmax) xmax = localMaxX;
+<a name="l00607"></a>00607         <span class="keywordflow">if</span>(localMaxY > ymax) ymax = localMaxY;
+<a name="l00608"></a>00608 
+<a name="l00609"></a>00609         <span class="keywordflow">if</span>(localMinX < xmin) xmin = localMinX;
+<a name="l00610"></a>00610         <span class="keywordflow">if</span>(localMinY < ymin) ymin = localMinY;
+<a name="l00611"></a>00611     }
+<a name="l00612"></a>00612 
+<a name="l00613"></a>00613     iGlobalSizeX = xmax - xmin;
+<a name="l00614"></a>00614     iGlobalSizeY = ymax - ymin;
+<a name="l00615"></a>00615     cpl_msg_warning(cpl_func, <span class="stringliteral">"iGlobalSize[%d:%d] xmaxmin[%d:%d] ymaxmin[%d:%d]"</span>, iGlobalSizeX, iGlobalSizeY, xmin, xmax, ymin, ymax);
+<a name="l00616"></a>00616     pResult = cpl_imagelist_new();
+<a name="l00617"></a>00617     exptimes = cpl_malloc(<span class="keyword">sizeof</span>(<span class="keywordtype">double</span>) * iCubesNumber);
+<a name="l00618"></a>00618     <span class="keywordflow">for</span> (z = 0; z < iCubesNumber; z++)
+<a name="l00619"></a>00619     {
+<a name="l00620"></a>00620         exptimes[z] = 10.;
+<a name="l00621"></a>00621     }
+<a name="l00622"></a>00622     mask= cpl_imagelist_new();
+<a name="l00623"></a>00623     <span class="keywordflow">for</span> (z = 0; z < iPlanesNumber; z++)
+<a name="l00624"></a>00624     {
+<a name="l00625"></a>00625         cpl_image* imMask = cpl_image_new(iGlobalSizeX, iGlobalSizeY, CPL_TYPE_FLOAT);
+<a name="l00626"></a>00626         cpl_image* imResult = cpl_image_new(iGlobalSizeX, iGlobalSizeY, CPL_TYPE_FLOAT);
+<a name="l00627"></a>00627         <span class="keywordflow">for</span> (x = 1; x <= iGlobalSizeX; x++)
+<a name="l00628"></a>00628         {
+<a name="l00629"></a>00629             <span class="keywordflow">for</span> (y = 1; y <= iGlobalSizeY; y++)
+<a name="l00630"></a>00630             {
+<a name="l00631"></a>00631                 cpl_image_set(imMask, x, y, 100);
+<a name="l00632"></a>00632             }
+<a name="l00633"></a>00633         }
+<a name="l00634"></a>00634         cpl_imagelist_set(mask, imMask, z);
+<a name="l00635"></a>00635         cpl_imagelist_set(pResult, imResult, z);
+<a name="l00636"></a>00636     }
+<a name="l00637"></a>00637 
+<a name="l00638"></a>00638     sinfo_coadd_with_ks_clip_optimized(
+<a name="l00639"></a>00639                 0,
+<a name="l00640"></a>00640                 iPlanesNumber,
+<a name="l00641"></a>00641                 iSizeX,
+<a name="l00642"></a>00642                 iSizeY,
+<a name="l00643"></a>00643                 iCubesNumber,
+<a name="l00644"></a>00644                 kappa,
+<a name="l00645"></a>00645                 pOffsetX,
+<a name="l00646"></a>00646                 pOffsetY,
+<a name="l00647"></a>00647                 exptimes,
+<a name="l00648"></a>00648                 mask,
+<a name="l00649"></a>00649                 pResult,
+<a name="l00650"></a>00650                 ppCubes);
+<a name="l00651"></a>00651 <span class="comment">//    pResult = kappa_sigma_offset(iGlobalSizeX, iGlobalSizeY, iCubesNumber, ppCubes, iCubesNumber, pOffsetY, kappa);</span>
+<a name="l00652"></a>00652 
+<a name="l00653"></a>00653 
+<a name="l00654"></a>00654 
+<a name="l00655"></a>00655     sinfo_msg(<span class="stringliteral">"Saving results"</span>);
+<a name="l00656"></a>00656     ppCubes[iCubesNumber] = pResult;
+<a name="l00657"></a>00657     ppCubes[iCubesNumber + 1] = mask;
+<a name="l00658"></a>00658 
+<a name="l00659"></a>00659     <span class="comment">/* HOW TO SAVE A PRODUCT ON DISK  */</span>
+<a name="l00660"></a>00660     <span class="comment">/* Set the file name */</span>
+<a name="l00661"></a>00661     name_o = <span class="stringliteral">"ima_res_0000.fits"</span> ;
+<a name="l00662"></a>00662 
+<a name="l00663"></a>00663     <span class="comment">/* Create product frame */</span>
+<a name="l00664"></a>00664     check_nomsg(product_frame = cpl_frame_new());
+<a name="l00665"></a>00665     check_nomsg(cpl_frame_set_filename(product_frame, name_o)) ;
+<a name="l00666"></a>00666     check_nomsg(cpl_frame_set_tag(product_frame,<span class="stringliteral">"image_gauss"</span> )) ;
+<a name="l00667"></a>00667     check_nomsg(cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_IMAGE)) ;
+<a name="l00668"></a>00668     check_nomsg(cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT)) ;
+<a name="l00669"></a>00669     check(cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL),
+<a name="l00670"></a>00670       <span class="stringliteral">"Error while initialising the product frame"</span>) ;
+<a name="l00671"></a>00671 
+<a name="l00672"></a>00672     <span class="comment">/* Add DataFlow keywords */</span>
+<a name="l00673"></a>00673     check_nomsg(cpl_propertylist_erase_regexp(plist, <span class="stringliteral">"^ESO PRO CATG"</span>,0));
+<a name="l00674"></a>00674 <span class="comment">//    cpl_frameset_dump(framelist, stdout);</span>
+<a name="l00675"></a>00675     check(cpl_dfs_setup_product_header(plist,
+<a name="l00676"></a>00676                                        product_frame,
+<a name="l00677"></a>00677                                        framelist,
+<a name="l00678"></a>00678                                        parlist,
+<a name="l00679"></a>00679                                        <span class="stringliteral">"sinfo_utl_ima_cube_ks_test"</span>,
+<a name="l00680"></a>00680                                        <span class="stringliteral">"SINFONI"</span>,
+<a name="l00681"></a>00681                                        KEY_VALUE_HPRO_DID,NULL),
+<a name="l00682"></a>00682       <span class="stringliteral">"Problem in the product DFS-compliance"</span>) ;
+<a name="l00683"></a>00683 
+<a name="l00684"></a>00684     <span class="comment">/* Save the input images file */</span>
+<a name="l00685"></a>00685 
+<a name="l00686"></a>00686     <span class="keywordflow">for</span> (z = 0; z <= iCubesNumber + 1; z++) <span class="comment">// the last imagelist is result after kappa-sigma, the very last is the mask</span>
+<a name="l00687"></a>00687     {
+<a name="l00688"></a>00688         <span class="keywordtype">char</span> BUF[256];
+<a name="l00689"></a>00689         sprintf(BUF,<span class="stringliteral">"out_cube_%d.fits"</span>,z);
+<a name="l00690"></a>00690         sinfo_msg(<span class="stringliteral">"Saving results cube[%d]"</span>,z);
+<a name="l00691"></a>00691         check(cpl_imagelist_save(ppCubes[z],
+<a name="l00692"></a>00692                 BUF,
+<a name="l00693"></a>00693                        CPL_BPP_IEEE_FLOAT,
+<a name="l00694"></a>00694                        plist,
+<a name="l00695"></a>00695                        CPL_IO_DEFAULT),
+<a name="l00696"></a>00696             <span class="stringliteral">"Could not save product"</span>);
+<a name="l00697"></a>00697 
+<a name="l00698"></a>00698         ck0(sinfo_pro_save_ims(ppCubes[z],framelist,framelist,BUF,<span class="stringliteral">"CUBE"</span>,NULL,
+<a name="l00699"></a>00699                         <span class="stringliteral">"sinfo_utl_ima_cube_ks_ex"</span>,parlist),
+<a name="l00700"></a>00700             <span class="stringliteral">"cannot save cube %s"</span>, BUF);
+<a name="l00701"></a>00701     }
+<a name="l00702"></a>00702 
+<a name="l00703"></a>00703     sinfo_free_propertylist(&plist) ;
+<a name="l00704"></a>00704     <span class="comment">/* Log the saved file in the input frameset */</span>
+<a name="l00705"></a>00705     check_nomsg(cpl_frameset_insert(framelist, product_frame)) ;
+<a name="l00706"></a>00706 
+<a name="l00707"></a>00707 
+<a name="l00708"></a>00708  cleanup:
+<a name="l00709"></a>00709 
+<a name="l00710"></a>00710 <span class="comment">//    sinfo_free_frameset(&raw_set);</span>
+<a name="l00711"></a>00711     sinfo_free_propertylist(&plist) ;
+<a name="l00712"></a>00712     <span class="keywordflow">for</span> (z = 0; z <= iCubesNumber + 1; z++) <span class="comment">// the last imagelist is result after kappa-sigma, the very last is the mask</span>
+<a name="l00713"></a>00713     {
+<a name="l00714"></a>00714         cpl_imagelist_delete(ppCubes[z]);
+<a name="l00715"></a>00715     }
+<a name="l00716"></a>00716     cpl_free(ppCubes);
+<a name="l00717"></a>00717     <span class="comment">/* This is usually freed by esorex: but what about if errors occurs?</span>
+<a name="l00718"></a>00718 <span class="comment">    sinfo_free_frame(&product_frame) ;</span>
+<a name="l00719"></a>00719 <span class="comment">    */</span>
+<a name="l00720"></a>00720 
+<a name="l00721"></a>00721     <span class="keywordflow">return</span> cpl_error_get_code() ? -1 : 0;
+<a name="l00722"></a>00722 
+<a name="l00723"></a>00723 }
+<a name="l00724"></a>00724 cpl_imagelist* create_cube_shift(
+<a name="l00725"></a>00725                 <span class="keywordtype">int</span> iSizeX,
+<a name="l00726"></a>00726                 <span class="keywordtype">int</span> iSizeY,
+<a name="l00727"></a>00727                 <span class="keywordtype">int</span> iPlanesNumber,
+<a name="l00728"></a>00728                 <span class="keywordtype">int</span> iFWHMX,
+<a name="l00729"></a>00729                 <span class="keywordtype">int</span> iFWHMY,
+<a name="l00730"></a>00730                 <span class="keywordtype">int</span> shiftX,
+<a name="l00731"></a>00731                 <span class="keywordtype">int</span> shiftY,
+<a name="l00732"></a>00732                 <span class="keywordtype">double</span> dSignal,
+<a name="l00733"></a>00733                 <span class="keywordtype">double</span> dBkgSignal,
+<a name="l00734"></a>00734                 <span class="keywordtype">double</span> dNoiseLvl,
+<a name="l00735"></a>00735                 <span class="keywordtype">double</span> dSignalDelta,
+<a name="l00736"></a>00736                 <span class="keywordtype">int</span> iDefectX,
+<a name="l00737"></a>00737                 <span class="keywordtype">int</span> iDefectY,
+<a name="l00738"></a>00738                 <span class="keywordtype">double</span> dDefectValue,
+<a name="l00739"></a>00739                 <span class="keywordtype">int</span> type
+<a name="l00740"></a>00740 )
+<a name="l00741"></a>00741 {
+<a name="l00742"></a>00742     <span class="keywordtype">int</span> z = 0;
+<a name="l00743"></a>00743     cpl_image* pPlane = NULL;
+<a name="l00744"></a>00744     cpl_imagelist* pRetval = NULL;
+<a name="l00745"></a>00745     pRetval = cpl_imagelist_new();
+<a name="l00746"></a>00746 
+<a name="l00747"></a>00747     <span class="keywordflow">for</span> (z = 0; z < iPlanesNumber; z++)
+<a name="l00748"></a>00748     {
+<a name="l00749"></a>00749         <span class="keywordtype">double</span> dSignalValue = dSignal + z * dSignalDelta;
+<a name="l00750"></a>00750         <span class="keywordflow">switch</span> (type)
+<a name="l00751"></a>00751         {
+<a name="l00752"></a>00752         <span class="keywordflow">case</span> 0:
+<a name="l00753"></a>00753             pPlane = create_plane(
+<a name="l00754"></a>00754                             iSizeX,
+<a name="l00755"></a>00755                             iSizeY,
+<a name="l00756"></a>00756                             iFWHMX,
+<a name="l00757"></a>00757                             iFWHMY,
+<a name="l00758"></a>00758                             shiftX,
+<a name="l00759"></a>00759                             shiftY,
+<a name="l00760"></a>00760                             dSignalValue,
+<a name="l00761"></a>00761                             dBkgSignal,
+<a name="l00762"></a>00762                             dNoiseLvl
+<a name="l00763"></a>00763                         );
+<a name="l00764"></a>00764             <span class="keywordflow">break</span>;
+<a name="l00765"></a>00765         <span class="keywordflow">case</span> 1:
+<a name="l00766"></a>00766             pPlane = create_square_plane(
+<a name="l00767"></a>00767                             iSizeX,
+<a name="l00768"></a>00768                             iSizeY,
+<a name="l00769"></a>00769                             iFWHMX,
+<a name="l00770"></a>00770                             iFWHMY,
+<a name="l00771"></a>00771                             shiftX,
+<a name="l00772"></a>00772                             shiftY,
+<a name="l00773"></a>00773                             dSignalValue,
+<a name="l00774"></a>00774                             dBkgSignal,
+<a name="l00775"></a>00775                             dNoiseLvl
+<a name="l00776"></a>00776                         );
+<a name="l00777"></a>00777             <span class="keywordflow">break</span>;
+<a name="l00778"></a>00778         }
+<a name="l00779"></a>00779 
+<a name="l00780"></a>00780 
+<a name="l00781"></a>00781         <span class="keywordflow">if</span> (dDefectValue)
+<a name="l00782"></a>00782         {
+<a name="l00783"></a>00783             put_defect(pPlane, iDefectX, iDefectY, dDefectValue);
+<a name="l00784"></a>00784         }
+<a name="l00785"></a>00785         putNAN(pPlane, iDefectX + shiftX, iDefectY + shiftY);
+<a name="l00786"></a>00786         cpl_imagelist_set(pRetval, pPlane, z);
+<a name="l00787"></a>00787     }
+<a name="l00788"></a>00788     <span class="keywordflow">return</span> pRetval;
+<a name="l00789"></a>00789 }
+<a name="l00790"></a>00790 cpl_image* create_plane(
+<a name="l00791"></a>00791                 <span class="keywordtype">int</span> iSizeX,
+<a name="l00792"></a>00792                 <span class="keywordtype">int</span> iSizeY,
+<a name="l00793"></a>00793                 <span class="keywordtype">int</span> iFWHMX,
+<a name="l00794"></a>00794                 <span class="keywordtype">int</span> iFWHMY,
+<a name="l00795"></a>00795                 <span class="keywordtype">int</span> shiftX,
+<a name="l00796"></a>00796                 <span class="keywordtype">int</span> shiftY,
+<a name="l00797"></a>00797                 <span class="keywordtype">double</span> dSignal,
+<a name="l00798"></a>00798                 <span class="keywordtype">double</span> dBkgSignal,
+<a name="l00799"></a>00799                 <span class="keywordtype">double</span> dNoiseLvl
+<a name="l00800"></a>00800 )
+<a name="l00801"></a>00801 {
+<a name="l00802"></a>00802     cpl_image* imNoise = NULL;
+<a name="l00803"></a>00803     cpl_image* imGauss = NULL;
+<a name="l00804"></a>00804     cpl_image* imResult = NULL;
+<a name="l00805"></a>00805     <span class="keyword">const</span> <span class="keywordtype">double</span> K = 2.35482;<span class="comment">//1. / (2. * sqrt(2.* ln(2.)));</span>
+<a name="l00806"></a>00806 
+<a name="l00807"></a>00807     imNoise = cpl_image_new(iSizeX, iSizeY, CPL_TYPE_FLOAT);
+<a name="l00808"></a>00808     cpl_image_fill_noise_uniform(imNoise, dBkgSignal - dNoiseLvl, dBkgSignal + dNoiseLvl);
+<a name="l00809"></a>00809     imGauss = cpl_image_new(iSizeX, iSizeY, CPL_TYPE_FLOAT);
+<a name="l00810"></a>00810     sinfo_msg(<span class="stringliteral">"Generate Gaussian center[%d:%d] signal[%f], sigma[%f:%f]"</span>, iSizeX/2 + shiftX, iSizeY/2 + shiftY, dSignal, iFWHMX / K, iFWHMY / K);
+<a name="l00811"></a>00811     cpl_image_fill_gaussian(imGauss, iSizeX/2 + shiftX, iSizeY/2 + shiftY, dSignal, iFWHMX / K, iFWHMY / K);
+<a name="l00812"></a>00812     imResult = cpl_image_add_create(imGauss, imNoise);
+<a name="l00813"></a>00813 
+<a name="l00814"></a>00814     <span class="comment">// cleanup</span>
+<a name="l00815"></a>00815     <span class="keywordflow">if</span> (imNoise)
+<a name="l00816"></a>00816     {
+<a name="l00817"></a>00817         cpl_image_delete(imNoise);
+<a name="l00818"></a>00818         imNoise = 0;
+<a name="l00819"></a>00819     }
+<a name="l00820"></a>00820     <span class="keywordflow">if</span> (imGauss)
+<a name="l00821"></a>00821     {
+<a name="l00822"></a>00822         cpl_image_delete(imGauss);
+<a name="l00823"></a>00823         imGauss = 0;
+<a name="l00824"></a>00824     }
+<a name="l00825"></a>00825     <span class="keywordflow">return</span> imResult;
+<a name="l00826"></a>00826 }
+<a name="l00827"></a>00827 cpl_image* create_square_plane(
+<a name="l00828"></a>00828                 <span class="keywordtype">int</span> iSizeX,
+<a name="l00829"></a>00829                 <span class="keywordtype">int</span> iSizeY,
+<a name="l00830"></a>00830                 <span class="keywordtype">int</span> iHoleX,
+<a name="l00831"></a>00831                 <span class="keywordtype">int</span> iHoleY,
+<a name="l00832"></a>00832                 <span class="keywordtype">int</span> shiftX,
+<a name="l00833"></a>00833                 <span class="keywordtype">int</span> shiftY,
+<a name="l00834"></a>00834                 <span class="keywordtype">double</span> dSignal,
+<a name="l00835"></a>00835                 <span class="keywordtype">double</span> dBkgSignal,
+<a name="l00836"></a>00836                 <span class="keywordtype">double</span> dNoiseLvl
+<a name="l00837"></a>00837 )
+<a name="l00838"></a>00838 {
+<a name="l00839"></a>00839     cpl_image* imNoise = NULL;
+<a name="l00840"></a>00840     cpl_image* imHole = NULL;
+<a name="l00841"></a>00841     cpl_image* imResult = NULL;
+<a name="l00842"></a>00842     <span class="keywordtype">int</span> x = 0;
+<a name="l00843"></a>00843     <span class="keywordtype">int</span> y = 0;
+<a name="l00844"></a>00844     <span class="keywordtype">int</span> xHoleInitial = 0;
+<a name="l00845"></a>00845     <span class="keywordtype">int</span> yHoleInitial = 0;
+<a name="l00846"></a>00846     imNoise = cpl_image_new(iSizeX, iSizeY, CPL_TYPE_FLOAT);
+<a name="l00847"></a>00847     cpl_image_fill_noise_uniform(imNoise, dBkgSignal - dNoiseLvl, dBkgSignal + dNoiseLvl);
+<a name="l00848"></a>00848     imHole = cpl_image_new(iSizeX, iSizeY, CPL_TYPE_FLOAT);
+<a name="l00849"></a>00849     xHoleInitial = iSizeX / 2 - iHoleX / 2;
+<a name="l00850"></a>00850     yHoleInitial = iSizeY / 2 - iHoleY / 2;
+<a name="l00851"></a>00851     <span class="keywordflow">for</span> (x = 0; x <= iHoleX; x++)
+<a name="l00852"></a>00852     {
+<a name="l00853"></a>00853         <span class="keywordflow">for</span> (y = 0; y <= iHoleY; y++)
+<a name="l00854"></a>00854         {
+<a name="l00855"></a>00855             <span class="keywordtype">int</span> pX = x + xHoleInitial + shiftX ;
+<a name="l00856"></a>00856             <span class="keywordtype">int</span> pY = y + yHoleInitial + shiftY;
+<a name="l00857"></a>00857             <span class="keywordflow">if</span> ((pX <= iSizeX) &&(pY <= iSizeY))
+<a name="l00858"></a>00858             cpl_image_set(imHole, pX,pY, dSignal);
+<a name="l00859"></a>00859         }
+<a name="l00860"></a>00860     }
+<a name="l00861"></a>00861     <span class="comment">//cpl_image_fill_gaussian(imGauss, iSizeX/2 + shiftX, iSizeY/2 + shiftY, dSignal, iFWHMX / K, iFWHMY / K);</span>
+<a name="l00862"></a>00862     imResult = cpl_image_add_create(imHole, imNoise);
+<a name="l00863"></a>00863 
+<a name="l00864"></a>00864     <span class="comment">// cleanup</span>
+<a name="l00865"></a>00865     <span class="keywordflow">if</span> (imNoise)
+<a name="l00866"></a>00866     {
+<a name="l00867"></a>00867         cpl_image_delete(imNoise);
+<a name="l00868"></a>00868         imNoise = 0;
+<a name="l00869"></a>00869     }
+<a name="l00870"></a>00870     <span class="keywordflow">if</span> (imHole)
+<a name="l00871"></a>00871     {
+<a name="l00872"></a>00872         cpl_image_delete(imHole);
+<a name="l00873"></a>00873         imHole = 0;
+<a name="l00874"></a>00874     }
+<a name="l00875"></a>00875     <span class="keywordflow">return</span> imResult;
+<a name="l00876"></a>00876 }
+<a name="l00877"></a>00877 <span class="keywordtype">int</span> put_defect(cpl_image *pPlane, <span class="keywordtype">int</span> iDefectX, <span class="keywordtype">int</span> iDefectY, <span class="keywordtype">double</span> dDefectValue)
+<a name="l00878"></a>00878 {
+<a name="l00879"></a>00879     sinfo_msg(<span class="stringliteral">"Set bad pixel x[%d] y[%d] value[%f]"</span>, iDefectX, iDefectY, dDefectValue);
+<a name="l00880"></a>00880     <span class="keywordflow">if</span> (pPlane)
+<a name="l00881"></a>00881     {
+<a name="l00882"></a>00882         cpl_image_set(pPlane, iDefectX, iDefectY, dDefectValue);
+<a name="l00883"></a>00883         cpl_image_set(pPlane, iDefectX+1, iDefectY+1, dDefectValue);
+<a name="l00884"></a>00884         cpl_image_set(pPlane, iDefectX-1, iDefectY-1, dDefectValue);
+<a name="l00885"></a>00885         cpl_image_set(pPlane, iDefectX+1, iDefectY-1, dDefectValue);
+<a name="l00886"></a>00886         cpl_image_set(pPlane, iDefectX-1, iDefectY+1, dDefectValue);
+<a name="l00887"></a>00887     }
+<a name="l00888"></a>00888     <span class="keywordflow">return</span> 0;
+<a name="l00889"></a>00889 }
+<a name="l00890"></a>00890 
+<a name="l00891"></a>00891 <span class="keywordtype">void</span> putNAN(cpl_image *pPlane, <span class="keywordtype">int</span> iDefectX, <span class="keywordtype">int</span> iDefectY)
+<a name="l00892"></a>00892 {
+<a name="l00893"></a>00893     cpl_image_set(pPlane, iDefectX, iDefectY, ZERO);
+<a name="l00894"></a>00894 }
+<a name="l00895"></a>00895 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__utl__ima__gauss_8c_source.html b/html/sinfo__utl__ima__gauss_8c_source.html
new file mode 100644
index 0000000..3fa6afa
--- /dev/null
+++ b/html/sinfo__utl__ima__gauss_8c_source.html
@@ -0,0 +1,435 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_utl_ima_gauss.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_utl_ima_gauss.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_utl_ima_gauss.c,v 1.1 2009/05/20 15:22:42 kmirny Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the SINFONI Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: kmirny $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2009/05/20 15:22:42 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.1 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span>
+<a name="l00032"></a>00032 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                                Includes</span>
+<a name="l00034"></a>00034 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 <span class="preprocessor">#include <string.h></span>
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="comment">/* cpl */</span>
+<a name="l00038"></a>00038 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00039"></a>00039 
+<a name="l00040"></a>00040 <span class="comment">/* irplib */</span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include <irplib_utils.h></span>
+<a name="l00042"></a>00042 
+<a name="l00043"></a>00043 <span class="preprocessor">#include <sinfo_tpl_utils.h></span>
+<a name="l00044"></a>00044 <span class="preprocessor">#include <sinfo_pfits.h></span>
+<a name="l00045"></a>00045 <span class="preprocessor">#include <sinfo_tpl_dfs.h></span>
+<a name="l00046"></a>00046 <span class="preprocessor">#include <sinfo_key_names.h></span>
+<a name="l00047"></a>00047 <span class="preprocessor">#include <sinfo_pro_types.h></span>
+<a name="l00048"></a>00048 <span class="preprocessor">#include <sinfo_functions.h></span>
+<a name="l00049"></a>00049 <span class="preprocessor">#include <sinfo_msg.h></span>
+<a name="l00050"></a>00050 <span class="preprocessor">#include <sinfo_error.h></span>
+<a name="l00051"></a>00051 <span class="preprocessor">#include <sinfo_utils_wrappers.h></span>
+<a name="l00052"></a>00052 
+<a name="l00053"></a>00053 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00054"></a>00054 <span class="comment">                            Functions prototypes</span>
+<a name="l00055"></a>00055 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00056"></a>00056 
+<a name="l00057"></a>00057 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_ima_gauss_create(cpl_plugin *) ;
+<a name="l00058"></a>00058 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_ima_gauss_exec(cpl_plugin *) ;
+<a name="l00059"></a>00059 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_ima_gauss_destroy(cpl_plugin *) ;
+<a name="l00060"></a>00060 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_ima_gauss(cpl_parameterlist *, cpl_frameset *) ;
+<a name="l00061"></a>00061 
+<a name="l00062"></a>00062 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00063"></a>00063 <span class="comment">                            Static variables</span>
+<a name="l00064"></a>00064 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00065"></a>00065 
+<a name="l00066"></a>00066 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_utl_ima_gauss_description[] =
+<a name="l00067"></a>00067 <span class="stringliteral">"This recipe produce an image,\n"</span>
+<a name="l00068"></a>00068 <span class="stringliteral">"containing a 2D Gaussian.\n"</span>
+<a name="l00069"></a>00069 <span class="stringliteral">"Information on relevant parameters can be found with\n"</span>
+<a name="l00070"></a>00070 <span class="stringliteral">"esorex --params sinfo_utl_ima_gauss\n"</span>
+<a name="l00071"></a>00071 <span class="stringliteral">"esorex --help sinfo_utl_ima_gauss\n"</span>
+<a name="l00072"></a>00072 <span class="stringliteral">"\n"</span>;
+<a name="l00073"></a>00073 
+<a name="l00074"></a>00074 <span class="keyword">static</span> <span class="keywordtype">char</span> PARAM_NAME_SIZE_X[] = <span class="stringliteral">"sinfoni.sinfo_utl_ima_gauss.size_x"</span>;
+<a name="l00075"></a>00075 <span class="keyword">static</span> <span class="keywordtype">char</span> PARAM_NAME_SIZE_Y[] = <span class="stringliteral">"sinfoni.sinfo_utl_ima_gauss.size_y"</span>;
+<a name="l00076"></a>00076 <span class="keyword">static</span> <span class="keywordtype">char</span> PARAM_NAME_FWHM_X[] = <span class="stringliteral">"sinfoni.sinfo_utl_ima_gauss.fwhm_x"</span>;
+<a name="l00077"></a>00077 <span class="keyword">static</span> <span class="keywordtype">char</span> PARAM_NAME_FWHM_Y[] = <span class="stringliteral">"sinfoni.sinfo_utl_ima_gauss.fwhm_y"</span>;
+<a name="l00078"></a>00078 <span class="keyword">static</span> <span class="keywordtype">char</span> PARAM_NAME_SIGNAL[] = <span class="stringliteral">"sinfoni.sinfo_utl_ima_gauss.total_signal"</span>;
+<a name="l00079"></a>00079 <span class="keyword">static</span> <span class="keywordtype">char</span> PARAM_NAME_BKGSIG[] = <span class="stringliteral">"sinfoni.sinfo_utl_ima_gauss.bkg_signal"</span>;
+<a name="l00080"></a>00080 <span class="keyword">static</span> <span class="keywordtype">char</span> PARAM_NAME_NOISEL[] = <span class="stringliteral">"sinfoni.sinfo_utl_ima_gauss.noise_level"</span>;
+<a name="l00081"></a>00081 
+<a name="l00082"></a>00082 <span class="keyword">static</span> <span class="keywordtype">char</span> RECIPE_NAME[] = <span class="stringliteral">"sinfoni.sinfo_utl_ima_gauss"</span>;
+<a name="l00083"></a>00083 
+<a name="l00084"></a>00084 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00085"></a>00085 <span class="comment">                                Functions code</span>
+<a name="l00086"></a>00086 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00087"></a>00087 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00091"></a>00091 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00092"></a>00092 
+<a name="l00094"></a>00094 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00102"></a>00102 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00103"></a><a class="code" href="group__sinfo__utl__ima__gauss.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693">00103</a> <span class="keywordtype">int</span> <a class="code" href="group__sinfo__rec__detlin.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693" title="Build the list of available plugins, for this module.">cpl_plugin_get_info</a>(cpl_pluginlist * list)
+<a name="l00104"></a>00104 {
+<a name="l00105"></a>00105     cpl_recipe  *   recipe = cpl_calloc(1, <span class="keyword">sizeof</span> *recipe ) ;
+<a name="l00106"></a>00106     cpl_plugin  *   plugin = &recipe->interface ;
+<a name="l00107"></a>00107 
+<a name="l00108"></a>00108     cpl_plugin_init(plugin,
+<a name="l00109"></a>00109                     CPL_PLUGIN_API,
+<a name="l00110"></a>00110                     SINFONI_BINARY_VERSION,
+<a name="l00111"></a>00111                     CPL_PLUGIN_TYPE_RECIPE,
+<a name="l00112"></a>00112                     <span class="stringliteral">"sinfo_utl_ima_gauss"</span>,
+<a name="l00113"></a>00113                     <span class="stringliteral">"Produce an image containing 2D Gaussian"</span>,
+<a name="l00114"></a>00114                     sinfo_utl_ima_gauss_description,
+<a name="l00115"></a>00115                     <span class="stringliteral">"Konstantin Mirny"</span>,
+<a name="l00116"></a>00116                     <span class="stringliteral">"kmirny at eso.org"</span>,
+<a name="l00117"></a>00117                     sinfo_get_license(),
+<a name="l00118"></a>00118                     sinfo_utl_ima_gauss_create,
+<a name="l00119"></a>00119                     sinfo_utl_ima_gauss_exec,
+<a name="l00120"></a>00120                     sinfo_utl_ima_gauss_destroy) ;
+<a name="l00121"></a>00121 
+<a name="l00122"></a>00122     cpl_pluginlist_append(list, plugin) ;
+<a name="l00123"></a>00123 
+<a name="l00124"></a>00124     <span class="keywordflow">return</span> 0;
+<a name="l00125"></a>00125 }
+<a name="l00126"></a>00126 
+<a name="l00127"></a>00127 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00136"></a>00136 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00137"></a>00137 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_ima_gauss_create(cpl_plugin * plugin)
+<a name="l00138"></a>00138 {
+<a name="l00139"></a>00139     <span class="keyword">const</span> <span class="keywordtype">int</span> SIZE_X_DEFAULT    = 1024;
+<a name="l00140"></a>00140     <span class="keyword">const</span> <span class="keywordtype">int</span> SIZE_Y_DEFAULT    = 1024;
+<a name="l00141"></a>00141     <span class="keyword">const</span> <span class="keywordtype">int</span> FWHM_X            = 100;
+<a name="l00142"></a>00142     <span class="keyword">const</span> <span class="keywordtype">int</span> FWHM_Y            = 100;
+<a name="l00143"></a>00143     <span class="keyword">const</span> <span class="keywordtype">double</span> TOTAL_SIGNAL   = 10E5;
+<a name="l00144"></a>00144     <span class="keyword">const</span> <span class="keywordtype">double</span> BKG_SIGNAL     = 400.;
+<a name="l00145"></a>00145     <span class="keyword">const</span> <span class="keywordtype">double</span> NOISE_VALUE    = 20.;
+<a name="l00146"></a>00146 
+<a name="l00147"></a>00147     cpl_recipe      * recipe ;
+<a name="l00148"></a>00148     cpl_parameter   * p ;
+<a name="l00149"></a>00149 
+<a name="l00150"></a>00150     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00151"></a>00151     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
+<a name="l00152"></a>00152         recipe = (cpl_recipe *)plugin ;
+<a name="l00153"></a>00153     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00154"></a>00154     cpl_error_reset();
+<a name="l00155"></a>00155     <a class="code" href="group__irplib__utils.html#gaf9d392144014e2363054bc3f83c8e47e" title="Reset IRPLIB state.">irplib_reset</a>();
+<a name="l00156"></a>00156 
+<a name="l00157"></a>00157     <span class="comment">/* Create the parameters list in the cpl_recipe object */</span>
+<a name="l00158"></a>00158     recipe->parameters = cpl_parameterlist_new() ;
+<a name="l00159"></a>00159 
+<a name="l00160"></a>00160     <span class="comment">/* Fill the parameters list */</span>
+<a name="l00161"></a>00161     <span class="comment">/* --stropt */</span>
+<a name="l00162"></a>00162 <span class="comment">/*    p = cpl_parameter_new_value("sinfoni.sinfo_utl_ima_gauss.op",</span>
+<a name="l00163"></a>00163 <span class="comment">                                CPL_TYPE_STRING,</span>
+<a name="l00164"></a>00164 <span class="comment">                                "A possible operation",</span>
+<a name="l00165"></a>00165 <span class="comment">                                "sinfoni.sinfo_utl_ima_gauss","+");</span>
+<a name="l00166"></a>00166 <span class="comment">    cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "op") ;</span>
+<a name="l00167"></a>00167 <span class="comment">    cpl_parameterlist_append(recipe->parameters, p) ;*/</span>
+<a name="l00168"></a>00168 
+<a name="l00169"></a>00169     <span class="comment">/* --size_x */</span>
+<a name="l00170"></a>00170     p = cpl_parameter_new_value(PARAM_NAME_SIZE_X,
+<a name="l00171"></a>00171             CPL_TYPE_INT, <span class="stringliteral">"size X axis"</span>, RECIPE_NAME, SIZE_X_DEFAULT) ;
+<a name="l00172"></a>00172     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"size_x"</span>) ;
+<a name="l00173"></a>00173     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00174"></a>00174 
+<a name="l00175"></a>00175     <span class="comment">/* --size_y */</span>
+<a name="l00176"></a>00176     p = cpl_parameter_new_value(PARAM_NAME_SIZE_Y,
+<a name="l00177"></a>00177             CPL_TYPE_INT, <span class="stringliteral">"size Y axis"</span>, RECIPE_NAME, SIZE_Y_DEFAULT) ;
+<a name="l00178"></a>00178     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"size_y"</span>) ;
+<a name="l00179"></a>00179     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00180"></a>00180 
+<a name="l00181"></a>00181     <span class="comment">/* --fwhm_x */</span>
+<a name="l00182"></a>00182     p = cpl_parameter_new_value(PARAM_NAME_FWHM_X,
+<a name="l00183"></a>00183             CPL_TYPE_INT, <span class="stringliteral">"FWHM X axis"</span>, RECIPE_NAME, FWHM_X) ;
+<a name="l00184"></a>00184     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"fwhm_x"</span>) ;
+<a name="l00185"></a>00185     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00186"></a>00186 
+<a name="l00187"></a>00187     <span class="comment">/* --fwhm_y */</span>
+<a name="l00188"></a>00188     p = cpl_parameter_new_value(PARAM_NAME_FWHM_Y,
+<a name="l00189"></a>00189             CPL_TYPE_INT, <span class="stringliteral">"FWHM Y axis"</span>, RECIPE_NAME, FWHM_Y) ;
+<a name="l00190"></a>00190     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"fwhm_y"</span>) ;
+<a name="l00191"></a>00191     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00192"></a>00192 
+<a name="l00193"></a>00193     <span class="comment">/* --total_signal */</span>
+<a name="l00194"></a>00194     p = cpl_parameter_new_value(PARAM_NAME_SIGNAL,
+<a name="l00195"></a>00195             CPL_TYPE_DOUBLE, <span class="stringliteral">"Total signal value"</span>, RECIPE_NAME, TOTAL_SIGNAL) ;
+<a name="l00196"></a>00196     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"total_signal"</span>) ;
+<a name="l00197"></a>00197     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00198"></a>00198 
+<a name="l00199"></a>00199     <span class="comment">/* --bkg_signal */</span>
+<a name="l00200"></a>00200     p = cpl_parameter_new_value(PARAM_NAME_BKGSIG,
+<a name="l00201"></a>00201             CPL_TYPE_DOUBLE, <span class="stringliteral">"background signal level"</span>, RECIPE_NAME, BKG_SIGNAL) ;
+<a name="l00202"></a>00202     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"bkg_signal"</span>) ;
+<a name="l00203"></a>00203     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00204"></a>00204 
+<a name="l00205"></a>00205     <span class="comment">/* --noise_level */</span>
+<a name="l00206"></a>00206     p = cpl_parameter_new_value(PARAM_NAME_NOISEL,
+<a name="l00207"></a>00207             CPL_TYPE_DOUBLE, <span class="stringliteral">"Noise level"</span>, RECIPE_NAME, NOISE_VALUE) ;
+<a name="l00208"></a>00208     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"noise_level"</span>) ;
+<a name="l00209"></a>00209     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00210"></a>00210     <span class="comment">/* Return */</span>
+<a name="l00211"></a>00211     <span class="keywordflow">return</span> 0;
+<a name="l00212"></a>00212 }
+<a name="l00213"></a>00213 
+<a name="l00214"></a>00214 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00220"></a>00220 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00221"></a>00221 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_ima_gauss_exec(cpl_plugin * plugin)
+<a name="l00222"></a>00222 {
+<a name="l00223"></a>00223     cpl_recipe  *   recipe ;
+<a name="l00224"></a>00224      <span class="keywordtype">int</span> code=0;
+<a name="l00225"></a>00225      cpl_errorstate initial_errorstate = cpl_errorstate_get();
+<a name="l00226"></a>00226 
+<a name="l00227"></a>00227     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00228"></a>00228     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
+<a name="l00229"></a>00229         recipe = (cpl_recipe *)plugin ;
+<a name="l00230"></a>00230     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00231"></a>00231     cpl_error_reset();
+<a name="l00232"></a>00232     <a class="code" href="group__irplib__utils.html#gaf9d392144014e2363054bc3f83c8e47e" title="Reset IRPLIB state.">irplib_reset</a>();
+<a name="l00233"></a>00233     code = sinfo_utl_ima_gauss(recipe->parameters, recipe->frames) ;
+<a name="l00234"></a>00234 
+<a name="l00235"></a>00235 
+<a name="l00236"></a>00236     <span class="keywordflow">if</span> (!cpl_errorstate_is_equal(initial_errorstate)) {
+<a name="l00237"></a>00237         <span class="comment">/* Dump the error history since recipe execution start.</span>
+<a name="l00238"></a>00238 <span class="comment">           At this point the recipe cannot recover from the error */</span>
+<a name="l00239"></a>00239         cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
+<a name="l00240"></a>00240     }
+<a name="l00241"></a>00241 
+<a name="l00242"></a>00242     <span class="keywordflow">return</span> code ;
+<a name="l00243"></a>00243 }
+<a name="l00244"></a>00244 
+<a name="l00245"></a>00245 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00251"></a>00251 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00252"></a>00252 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_ima_gauss_destroy(cpl_plugin * plugin)
+<a name="l00253"></a>00253 {
+<a name="l00254"></a>00254     cpl_recipe  *   recipe ;
+<a name="l00255"></a>00255 
+<a name="l00256"></a>00256     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00257"></a>00257     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
+<a name="l00258"></a>00258         recipe = (cpl_recipe *)plugin ;
+<a name="l00259"></a>00259     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00260"></a>00260 
+<a name="l00261"></a>00261     cpl_parameterlist_delete(recipe->parameters) ;
+<a name="l00262"></a>00262     <span class="keywordflow">return</span> 0 ;
+<a name="l00263"></a>00263 }
+<a name="l00264"></a>00264 
+<a name="l00265"></a>00265 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00272"></a>00272 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00273"></a>00273 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00274"></a>00274 sinfo_utl_ima_gauss( cpl_parameterlist   *   parlist,
+<a name="l00275"></a>00275         cpl_frameset        *   framelist)
+<a name="l00276"></a>00276 {
+<a name="l00277"></a>00277     <span class="comment">// parameters</span>
+<a name="l00278"></a>00278     <span class="keywordtype">int</span>     iSizeX = 0;
+<a name="l00279"></a>00279     <span class="keywordtype">int</span>     iSizeY = 0;
+<a name="l00280"></a>00280     <span class="keywordtype">int</span>     iFWHMX = 0;
+<a name="l00281"></a>00281     <span class="keywordtype">int</span>     iFWHMY = 0;
+<a name="l00282"></a>00282     <span class="keywordtype">double</span> dSignal = 0;
+<a name="l00283"></a>00283     <span class="keywordtype">double</span> dBkgSignal = 0;
+<a name="l00284"></a>00284     <span class="keywordtype">double</span> dNoiseLvl = 0;
+<a name="l00286"></a>00286 
+<a name="l00287"></a>00287     <span class="keyword">const</span> <span class="keywordtype">char</span>          *   name_o = NULL ;
+<a name="l00288"></a>00288     cpl_parameter       *   param = NULL ;
+<a name="l00289"></a>00289 
+<a name="l00290"></a>00290     cpl_propertylist    *   plist = NULL ;
+<a name="l00291"></a>00291     cpl_image           *   imNoise = NULL ;
+<a name="l00292"></a>00292     cpl_image           *   imGauss = NULL ;
+<a name="l00293"></a>00293     cpl_image           *   imResult = NULL;
+<a name="l00294"></a>00294     cpl_frame           *   product_frame = NULL;
+<a name="l00295"></a>00295     <span class="keyword">const</span> <span class="keywordtype">double</span> K = 2.35482;<span class="comment">//1. / (2. * sqrt(2.* ln(2.)));</span>
+<a name="l00296"></a>00296 
+<a name="l00297"></a>00297     sinfo_msg(<span class="stringliteral">"Welcome to SINFONI Pipeline release %d.%d.%d"</span>,
+<a name="l00298"></a>00298     SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
+<a name="l00299"></a>00299     ck0(sinfo_dfs_set_groups(framelist),<span class="stringliteral">"Cannot indentify RAW and CALIB frames"</span>);
+<a name="l00300"></a>00300 
+<a name="l00301"></a>00301 <span class="comment">/* HOW TO RETRIEVE INPUT PARAMETERS */</span>
+<a name="l00302"></a>00302       <span class="comment">/* --size_x */</span>
+<a name="l00303"></a>00303       check_nomsg(param=cpl_parameterlist_find(parlist,
+<a name="l00304"></a>00304                                                PARAM_NAME_SIZE_X));
+<a name="l00305"></a>00305       check_nomsg(iSizeX=cpl_parameter_get_int(param));
+<a name="l00306"></a>00306 
+<a name="l00307"></a>00307       <span class="comment">/* --size_y */</span>
+<a name="l00308"></a>00308       check_nomsg(param=cpl_parameterlist_find(parlist,
+<a name="l00309"></a>00309                                                PARAM_NAME_SIZE_Y));
+<a name="l00310"></a>00310       check_nomsg(iSizeY=cpl_parameter_get_int(param));
+<a name="l00311"></a>00311 
+<a name="l00312"></a>00312       <span class="comment">/* --fwhm_x */</span>
+<a name="l00313"></a>00313       check_nomsg(param=cpl_parameterlist_find(parlist,
+<a name="l00314"></a>00314                                                PARAM_NAME_FWHM_X));
+<a name="l00315"></a>00315       check_nomsg(iFWHMX=cpl_parameter_get_int(param));
+<a name="l00316"></a>00316 
+<a name="l00317"></a>00317       <span class="comment">/* --fwhm_y */</span>
+<a name="l00318"></a>00318       check_nomsg(param=cpl_parameterlist_find(parlist,
+<a name="l00319"></a>00319                                                PARAM_NAME_FWHM_Y));
+<a name="l00320"></a>00320       check_nomsg(iFWHMY=cpl_parameter_get_int(param));
+<a name="l00321"></a>00321 
+<a name="l00322"></a>00322       <span class="comment">/* --total_signal */</span>
+<a name="l00323"></a>00323       check_nomsg(param=cpl_parameterlist_find(parlist,
+<a name="l00324"></a>00324                                                PARAM_NAME_SIGNAL));
+<a name="l00325"></a>00325       check_nomsg(dSignal=cpl_parameter_get_double(param));
+<a name="l00326"></a>00326 
+<a name="l00327"></a>00327       <span class="comment">/* --bkg_signal */</span>
+<a name="l00328"></a>00328       check_nomsg(param=cpl_parameterlist_find(parlist,
+<a name="l00329"></a>00329                                                PARAM_NAME_BKGSIG));
+<a name="l00330"></a>00330       check_nomsg(dBkgSignal=cpl_parameter_get_double(param));
+<a name="l00331"></a>00331 
+<a name="l00332"></a>00332       <span class="comment">/* --noise_level */</span>
+<a name="l00333"></a>00333       check_nomsg(param=cpl_parameterlist_find(parlist,
+<a name="l00334"></a>00334                                                PARAM_NAME_NOISEL));
+<a name="l00335"></a>00335       check_nomsg(dNoiseLvl=cpl_parameter_get_double(param));
+<a name="l00336"></a>00336 
+<a name="l00337"></a>00337     <span class="comment">/* Identify the RAW and CALIB frames in the input frameset */</span>
+<a name="l00338"></a>00338 <span class="comment">//    check(sinfo_dfs_set_groups(framelist),</span>
+<a name="l00339"></a>00339 <span class="comment">//         "Cannot identify RAW and CALIB frames") ;</span>
+<a name="l00340"></a>00340 
+<a name="l00341"></a>00341     <span class="comment">/* HOW TO ACCESS INPUT DATA */</span>
+<a name="l00342"></a>00342 <span class="comment">/*    n=cpl_frameset_get_size(framelist);</span>
+<a name="l00343"></a>00343 <span class="comment">    if(n<1) {</span>
+<a name="l00344"></a>00344 <span class="comment">      sinfo_msg_error("Empty input frame list!");</span>
+<a name="l00345"></a>00345 <span class="comment">      goto cleanup ;</span>
+<a name="l00346"></a>00346 <span class="comment">    }</span>
+<a name="l00347"></a>00347 <span class="comment">*/</span>
+<a name="l00348"></a>00348     <span class="comment">/* HOW TO ACCESS INPUT DATA */</span>
+<a name="l00349"></a>00349 <span class="comment">//    check_nomsg(raw_set=cpl_frameset_new());</span>
+<a name="l00350"></a>00350 <span class="comment">/*</span>
+<a name="l00351"></a>00351 <span class="comment">    check(sinfo_contains_frames_kind(framelist,raw_set,PRO_IMA),</span>
+<a name="l00352"></a>00352 <span class="comment">     "Found no input frames with tag %s",PRO_IMA);</span>
+<a name="l00353"></a>00353 <span class="comment">    check_nomsg(nraw=cpl_frameset_get_size(raw_set));</span>
+<a name="l00354"></a>00354 <span class="comment">    if (nraw<1) {</span>
+<a name="l00355"></a>00355 <span class="comment">      sinfo_msg_error("Found no input frames with tag %s",PRO_IMA);</span>
+<a name="l00356"></a>00356 <span class="comment">      goto cleanup;</span>
+<a name="l00357"></a>00357 <span class="comment">    } else {</span>
+<a name="l00358"></a>00358 <span class="comment">         check_nomsg(frm_ima1=cpl_frameset_get_frame(framelist,0));</span>
+<a name="l00359"></a>00359 <span class="comment">         check_nomsg(ima1=cpl_image_load(cpl_frame_get_filename(frm_ima1),</span>
+<a name="l00360"></a>00360 <span class="comment">                                         CPL_TYPE_FLOAT,0,0));</span>
+<a name="l00361"></a>00361 <span class="comment">     if (nraw>1) {</span>
+<a name="l00362"></a>00362 <span class="comment">         check_nomsg(frm_ima2=cpl_frameset_get_frame(framelist,1));</span>
+<a name="l00363"></a>00363 <span class="comment">         check_nomsg(ima2 = cpl_image_load(cpl_frame_get_filename(frm_ima2),</span>
+<a name="l00364"></a>00364 <span class="comment">                                           CPL_TYPE_FLOAT,0,0));</span>
+<a name="l00365"></a>00365 <span class="comment">         switch_ima2=1;</span>
+<a name="l00366"></a>00366 <span class="comment">      } else if (value == 9999.) {</span>
+<a name="l00367"></a>00367 <span class="comment">        sinfo_msg_error("Found only one input frames with tag %s",PRO_IMA);</span>
+<a name="l00368"></a>00368 <span class="comment">        goto cleanup;</span>
+<a name="l00369"></a>00369 <span class="comment">      } else {</span>
+<a name="l00370"></a>00370 <span class="comment">        sinfo_msg("Produce an image %s",PRO_IMA);</span>
+<a name="l00371"></a>00371 <span class="comment">      }</span>
+<a name="l00372"></a>00372 <span class="comment">    }</span>
+<a name="l00373"></a>00373 <span class="comment"></span>
+<a name="l00374"></a>00374 <span class="comment">    sinfo_free_frameset(&raw_set);</span>
+<a name="l00375"></a>00375 <span class="comment">*/</span>
+<a name="l00376"></a>00376     <span class="comment">/* HOW TO GET THE VALUE OF A FITS KEYWORD */</span>
+<a name="l00377"></a>00377     check(plist=cpl_propertylist_new(),<span class="stringliteral">"Cannot create a Property List"</span>);
+<a name="l00378"></a>00378 
+<a name="l00379"></a>00379     <span class="comment">/* Now performing the data reduction */</span>
+<a name="l00380"></a>00380     <span class="comment">/* Let's generate one image for the example */</span>
+<a name="l00381"></a>00381 
+<a name="l00382"></a>00382 
+<a name="l00383"></a>00383   check(imNoise = cpl_image_fill_test_create(iSizeX, iSizeY),
+<a name="l00384"></a>00384                 <span class="stringliteral">"Cannot generate the image"</span>) ;
+<a name="l00385"></a>00385   check_nomsg(cpl_image_fill_noise_uniform(imNoise, dBkgSignal - dNoiseLvl, dBkgSignal + dNoiseLvl));
+<a name="l00386"></a>00386   check(imGauss = cpl_image_fill_test_create(iSizeX, iSizeY),
+<a name="l00387"></a>00387                 <span class="stringliteral">"Cannot generate the image"</span>) ;
+<a name="l00388"></a>00388 <span class="comment">//  double dfwhm_x = iFWHMX;</span>
+<a name="l00389"></a>00389 <span class="comment">//  double dfwhm_y = iFWHMY;</span>
+<a name="l00390"></a>00390 <span class="comment">//  double xcen = 0;</span>
+<a name="l00391"></a>00391 <span class="comment">//  double ycen = 0;</span>
+<a name="l00392"></a>00392 <span class="comment">//  check_nomsg(cpl_image_fit_gaussian(imNoise, iSizeX/2, iSizeY/2, 5, &dSignal, &xcen, &ycen, 0, 0, &dfwhm_y, &dfwhm_y));</span>
+<a name="l00393"></a>00393   check(imResult = cpl_image_fill_test_create(iSizeX, iSizeY),
+<a name="l00394"></a>00394                 <span class="stringliteral">"Cannot generate the image"</span>) ;
+<a name="l00395"></a>00395   check_nomsg(cpl_image_fill_gaussian(imGauss, iSizeX/2, iSizeY/2, dSignal, iFWHMX / K, iFWHMY / K));
+<a name="l00396"></a>00396   check(imResult = cpl_image_add_create(imGauss, imNoise), <span class="stringliteral">"Cannot generate the image"</span>);
+<a name="l00397"></a>00397     <span class="comment">/* HOW TO SAVE A PRODUCT ON DISK  */</span>
+<a name="l00398"></a>00398     <span class="comment">/* Set the file name */</span>
+<a name="l00399"></a>00399     name_o = <span class="stringliteral">"ima_res.fits"</span> ;
+<a name="l00400"></a>00400 
+<a name="l00401"></a>00401     <span class="comment">/* Create product frame */</span>
+<a name="l00402"></a>00402     check_nomsg(product_frame = cpl_frame_new());
+<a name="l00403"></a>00403     check_nomsg(cpl_frame_set_filename(product_frame, name_o)) ;
+<a name="l00404"></a>00404     check_nomsg(cpl_frame_set_tag(product_frame,<span class="stringliteral">"image_gauss"</span> )) ;
+<a name="l00405"></a>00405     check_nomsg(cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_IMAGE)) ;
+<a name="l00406"></a>00406     check_nomsg(cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT)) ;
+<a name="l00407"></a>00407     check(cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL),
+<a name="l00408"></a>00408       <span class="stringliteral">"Error while initialising the product frame"</span>) ;
+<a name="l00409"></a>00409 
+<a name="l00410"></a>00410     <span class="comment">/* Add DataFlow keywords */</span>
+<a name="l00411"></a>00411     check_nomsg(cpl_propertylist_erase_regexp(plist, <span class="stringliteral">"^ESO PRO CATG"</span>,0));
+<a name="l00412"></a>00412 <span class="comment">//    cpl_frameset_dump(framelist, stdout);</span>
+<a name="l00413"></a>00413     check(cpl_dfs_setup_product_header(plist,
+<a name="l00414"></a>00414                                        product_frame,
+<a name="l00415"></a>00415                                        framelist,
+<a name="l00416"></a>00416                                        parlist,
+<a name="l00417"></a>00417                                        <span class="stringliteral">"sinfo_utl_ima_gauss"</span>,
+<a name="l00418"></a>00418                                        <span class="stringliteral">"SINFONI"</span>,
+<a name="l00419"></a>00419                                        KEY_VALUE_HPRO_DID,NULL),
+<a name="l00420"></a>00420       <span class="stringliteral">"Problem in the product DFS-compliance"</span>) ;
+<a name="l00421"></a>00421 
+<a name="l00422"></a>00422 
+<a name="l00423"></a>00423     <span class="comment">/* Save the file */</span>
+<a name="l00424"></a>00424     check(cpl_image_save(imResult,
+<a name="l00425"></a>00425                          name_o,
+<a name="l00426"></a>00426                          CPL_BPP_IEEE_FLOAT,
+<a name="l00427"></a>00427                          plist,
+<a name="l00428"></a>00428                          CPL_IO_DEFAULT),
+<a name="l00429"></a>00429                          <span class="stringliteral">"Could not save product"</span>);
+<a name="l00430"></a>00430 
+<a name="l00431"></a>00431 
+<a name="l00432"></a>00432     sinfo_free_propertylist(&plist) ;
+<a name="l00433"></a>00433     sinfo_free_image(&imNoise);
+<a name="l00434"></a>00434     sinfo_free_image(&imGauss);
+<a name="l00435"></a>00435     sinfo_free_image(&imResult);
+<a name="l00436"></a>00436     <span class="comment">/* Log the saved file in the input frameset */</span>
+<a name="l00437"></a>00437     check_nomsg(cpl_frameset_insert(framelist, product_frame)) ;
+<a name="l00438"></a>00438 
+<a name="l00439"></a>00439 
+<a name="l00440"></a>00440  cleanup:
+<a name="l00441"></a>00441 
+<a name="l00442"></a>00442 <span class="comment">//    sinfo_free_frameset(&raw_set);</span>
+<a name="l00443"></a>00443     sinfo_free_propertylist(&plist) ;
+<a name="l00444"></a>00444     <span class="comment">/* This is usually freed by esorex: but what about if errors occurs?</span>
+<a name="l00445"></a>00445 <span class="comment">    sinfo_free_frame(&product_frame) ;</span>
+<a name="l00446"></a>00446 <span class="comment">    */</span>
+<a name="l00447"></a>00447     sinfo_free_image(&imNoise) ;
+<a name="l00448"></a>00448 
+<a name="l00449"></a>00449     <span class="keywordflow">if</span> (cpl_error_get_code()) {
+<a name="l00450"></a>00450         <span class="keywordflow">return</span> -1 ;
+<a name="l00451"></a>00451     } <span class="keywordflow">else</span> {
+<a name="l00452"></a>00452         <span class="keywordflow">return</span> 0 ;
+<a name="l00453"></a>00453     }
+<a name="l00454"></a>00454 
+<a name="l00455"></a>00455 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__utl__ima__line__corr_8c_source.html b/html/sinfo__utl__ima__line__corr_8c_source.html
new file mode 100644
index 0000000..d56e7e8
--- /dev/null
+++ b/html/sinfo__utl__ima__line__corr_8c_source.html
@@ -0,0 +1,321 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_utl_ima_line_corr.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_utl_ima_line_corr.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_utl_ima_line_corr.c,v 1.3 2009/06/05 08:18:55 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the SINFONI Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2009/06/05 08:18:55 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.3 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span>
+<a name="l00032"></a>00032 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                                Includes</span>
+<a name="l00034"></a>00034 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 <span class="preprocessor">#include <string.h></span>
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="comment">/* cpl */</span>
+<a name="l00038"></a>00038 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00039"></a>00039 
+<a name="l00040"></a>00040 <span class="comment">/* irplib */</span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include <irplib_utils.h></span>
+<a name="l00042"></a>00042 
+<a name="l00043"></a>00043 <span class="preprocessor">#include <sinfo_tpl_utils.h></span>
+<a name="l00044"></a>00044 <span class="preprocessor">#include <sinfo_pfits.h></span>
+<a name="l00045"></a>00045 <span class="preprocessor">#include <sinfo_tpl_dfs.h></span>
+<a name="l00046"></a>00046 <span class="preprocessor">#include <sinfo_key_names.h></span>
+<a name="l00047"></a>00047 <span class="preprocessor">#include <sinfo_pro_types.h></span>
+<a name="l00048"></a>00048 <span class="preprocessor">#include <sinfo_functions.h></span>
+<a name="l00049"></a>00049 <span class="preprocessor">#include <sinfo_image_ops.h></span>
+<a name="l00050"></a>00050 <span class="preprocessor">#include <sinfo_msg.h></span>
+<a name="l00051"></a>00051 <span class="preprocessor">#include <sinfo_error.h></span>
+<a name="l00052"></a>00052 <span class="preprocessor">#include <sinfo_utils_wrappers.h></span>
+<a name="l00053"></a>00053 
+<a name="l00054"></a>00054 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00055"></a>00055 <span class="comment">                            Functions prototypes</span>
+<a name="l00056"></a>00056 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00057"></a>00057 
+<a name="l00058"></a>00058 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_ima_line_corr_create(cpl_plugin *) ;
+<a name="l00059"></a>00059 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_ima_line_corr_exec(cpl_plugin *) ;
+<a name="l00060"></a>00060 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_ima_line_corr_destroy(cpl_plugin *) ;
+<a name="l00061"></a>00061 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_ima_line_corr(cpl_parameterlist *, cpl_frameset *) ;
+<a name="l00062"></a>00062 
+<a name="l00063"></a>00063 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00064"></a>00064 <span class="comment">                            Static variables</span>
+<a name="l00065"></a>00065 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00066"></a>00066 
+<a name="l00067"></a>00067 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_utl_ima_line_corr_description[] =
+<a name="l00068"></a>00068 <span class="stringliteral">"This recipe performs image computation.\n"</span>
+<a name="l00069"></a>00069 <span class="stringliteral">"The input files are images\n"</span>
+<a name="l00070"></a>00070 <span class="stringliteral">"their associated tags should be IMA.\n"</span>
+<a name="l00071"></a>00071 <span class="stringliteral">"The output are the images cleaned by the defect introduced by SINFONI sw\n"</span>
+<a name="l00072"></a>00072 <span class="stringliteral">"Information on relevant parameters can be found with\n"</span>
+<a name="l00073"></a>00073 <span class="stringliteral">"esorex --params sinfo_utl_ima_line_corr\n"</span>
+<a name="l00074"></a>00074 <span class="stringliteral">"esorex --help sinfo_utl_ima_line_corr\n"</span>
+<a name="l00075"></a>00075 <span class="stringliteral">"\n"</span>;
+<a name="l00076"></a>00076 
+<a name="l00077"></a>00077 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00078"></a>00078 <span class="comment">                                Functions code</span>
+<a name="l00079"></a>00079 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00080"></a>00080 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00084"></a>00084 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00085"></a>00085 
+<a name="l00087"></a>00087 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00095"></a>00095 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00096"></a><a class="code" href="group__sinfo__utl__ima__line__corr.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693">00096</a> <span class="keywordtype">int</span> <a class="code" href="group__sinfo__rec__detlin.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693" title="Build the list of available plugins, for this module.">cpl_plugin_get_info</a>(cpl_pluginlist * list)
+<a name="l00097"></a>00097 {
+<a name="l00098"></a>00098     cpl_recipe  *   recipe = cpl_calloc(1, <span class="keyword">sizeof</span> *recipe ) ;
+<a name="l00099"></a>00099     cpl_plugin  *   plugin = &recipe->interface ;
+<a name="l00100"></a>00100 
+<a name="l00101"></a>00101     cpl_plugin_init(plugin,
+<a name="l00102"></a>00102                     CPL_PLUGIN_API,
+<a name="l00103"></a>00103                     SINFONI_BINARY_VERSION,
+<a name="l00104"></a>00104                     CPL_PLUGIN_TYPE_RECIPE,
+<a name="l00105"></a>00105                     <span class="stringliteral">"sinfo_utl_ima_line_corr"</span>,
+<a name="l00106"></a>00106                     <span class="stringliteral">"Computes result of ima1 op ima2"</span>,
+<a name="l00107"></a>00107                     sinfo_utl_ima_line_corr_description,
+<a name="l00108"></a>00108                     <span class="stringliteral">"Andrea Modigliani"</span>,
+<a name="l00109"></a>00109                     <span class="stringliteral">"Andrea.Modigliani at eso.org"</span>,
+<a name="l00110"></a>00110                     sinfo_get_license(),
+<a name="l00111"></a>00111                     sinfo_utl_ima_line_corr_create,
+<a name="l00112"></a>00112                     sinfo_utl_ima_line_corr_exec,
+<a name="l00113"></a>00113                     sinfo_utl_ima_line_corr_destroy) ;
+<a name="l00114"></a>00114 
+<a name="l00115"></a>00115     cpl_pluginlist_append(list, plugin) ;
+<a name="l00116"></a>00116     
+<a name="l00117"></a>00117     <span class="keywordflow">return</span> 0;
+<a name="l00118"></a>00118 }
+<a name="l00119"></a>00119 
+<a name="l00120"></a>00120 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00129"></a>00129 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00130"></a>00130 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_ima_line_corr_create(cpl_plugin * plugin)
+<a name="l00131"></a>00131 {
+<a name="l00132"></a>00132     cpl_recipe      * recipe ;
+<a name="l00133"></a>00133     cpl_parameter   * p ;
+<a name="l00134"></a>00134 
+<a name="l00135"></a>00135     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00136"></a>00136     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00137"></a>00137         recipe = (cpl_recipe *)plugin ;
+<a name="l00138"></a>00138     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00139"></a>00139     cpl_error_reset();
+<a name="l00140"></a>00140     <a class="code" href="group__irplib__utils.html#gaf9d392144014e2363054bc3f83c8e47e" title="Reset IRPLIB state.">irplib_reset</a>();
+<a name="l00141"></a>00141 
+<a name="l00142"></a>00142     <span class="comment">/* Create the parameters list in the cpl_recipe object */</span>
+<a name="l00143"></a>00143     recipe->parameters = cpl_parameterlist_new() ; 
+<a name="l00144"></a>00144 
+<a name="l00145"></a>00145     <span class="comment">/* Fill the parameters list */</span>
+<a name="l00146"></a>00146     p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.sinfo_utl_ima_line_corr.kappa"</span>, 
+<a name="l00147"></a>00147                                 CPL_TYPE_INT, 
+<a name="l00148"></a>00148                                 <span class="stringliteral">"Kappa sigma value"</span>, 
+<a name="l00149"></a>00149                                 <span class="stringliteral">"sinfoni.sinfo_utl_ima_line_corr"</span>,18);
+<a name="l00150"></a>00150     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"kappa"</span>) ;
+<a name="l00151"></a>00151     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00152"></a>00152 
+<a name="l00153"></a>00153      p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.sinfo_utl_ima_line_corr.filt_rad"</span>, 
+<a name="l00154"></a>00154                 CPL_TYPE_INT,
+<a name="l00155"></a>00155                 <span class="stringliteral">"Filtering radii applied during median filter."</span>
+<a name="l00156"></a>00156                                 <span class="stringliteral">" Should be small"</span>, 
+<a name="l00157"></a>00157                 <span class="stringliteral">"sinfoni.sinfo_utl_ima_line_corr"</span>,3) ;;
+<a name="l00158"></a>00158     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"filt_rad"</span>) ;
+<a name="l00159"></a>00159     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00160"></a>00160  
+<a name="l00161"></a>00161     <span class="comment">/* Return */</span>
+<a name="l00162"></a>00162     <span class="keywordflow">return</span> 0;
+<a name="l00163"></a>00163 }
+<a name="l00164"></a>00164 
+<a name="l00165"></a>00165 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00171"></a>00171 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00172"></a>00172 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_ima_line_corr_exec(cpl_plugin * plugin)
+<a name="l00173"></a>00173 {
+<a name="l00174"></a>00174     cpl_recipe  *   recipe ;
+<a name="l00175"></a>00175      <span class="keywordtype">int</span> code=0;
+<a name="l00176"></a>00176      cpl_errorstate initial_errorstate = cpl_errorstate_get();
+<a name="l00177"></a>00177 
+<a name="l00178"></a>00178     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00179"></a>00179     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00180"></a>00180         recipe = (cpl_recipe *)plugin ;
+<a name="l00181"></a>00181     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00182"></a>00182     cpl_error_reset();
+<a name="l00183"></a>00183     <a class="code" href="group__irplib__utils.html#gaf9d392144014e2363054bc3f83c8e47e" title="Reset IRPLIB state.">irplib_reset</a>();
+<a name="l00184"></a>00184     code = sinfo_utl_ima_line_corr(recipe->parameters, recipe->frames) ;
+<a name="l00185"></a>00185 
+<a name="l00186"></a>00186 
+<a name="l00187"></a>00187     <span class="keywordflow">if</span> (!cpl_errorstate_is_equal(initial_errorstate)) {                      
+<a name="l00188"></a>00188         <span class="comment">/* Dump the error history since recipe execution start.                </span>
+<a name="l00189"></a>00189 <span class="comment">           At this point the recipe cannot recover from the error */</span>           
+<a name="l00190"></a>00190         cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);              
+<a name="l00191"></a>00191     } 
+<a name="l00192"></a>00192 
+<a name="l00193"></a>00193     <span class="keywordflow">return</span> code ;
+<a name="l00194"></a>00194 }
+<a name="l00195"></a>00195 
+<a name="l00196"></a>00196 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00202"></a>00202 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00203"></a>00203 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_ima_line_corr_destroy(cpl_plugin * plugin)
+<a name="l00204"></a>00204 {
+<a name="l00205"></a>00205     cpl_recipe  *   recipe ;
+<a name="l00206"></a>00206     
+<a name="l00207"></a>00207     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00208"></a>00208     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00209"></a>00209         recipe = (cpl_recipe *)plugin ;
+<a name="l00210"></a>00210     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00211"></a>00211 
+<a name="l00212"></a>00212     cpl_parameterlist_delete(recipe->parameters) ; 
+<a name="l00213"></a>00213     <span class="keywordflow">return</span> 0 ;
+<a name="l00214"></a>00214 }
+<a name="l00215"></a>00215 
+<a name="l00216"></a>00216 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00223"></a>00223 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00224"></a>00224 <span class="keyword">static</span> <span class="keywordtype">int</span> 
+<a name="l00225"></a>00225 sinfo_utl_ima_line_corr( cpl_parameterlist   *   parlist, 
+<a name="l00226"></a>00226              cpl_frameset        *   framelist)
+<a name="l00227"></a>00227 {
+<a name="l00228"></a>00228     cpl_parameter       *   p= NULL ;
+<a name="l00229"></a>00229     <span class="keywordtype">int</span>                     kappa=18;
+<a name="l00230"></a>00230     <span class="keywordtype">int</span>                     filt_rad=3;
+<a name="l00231"></a>00231     <span class="keywordtype">int</span> width=4;
+<a name="l00232"></a>00232 
+<a name="l00233"></a>00233     cpl_image           *   ima=NULL ;
+<a name="l00234"></a>00234     cpl_image           *   ima_out=NULL ;
+<a name="l00235"></a>00235     cpl_propertylist    *   plist=NULL ;
+<a name="l00236"></a>00236     cpl_frame           *   product_frame=NULL;
+<a name="l00237"></a>00237     cpl_frameset * raw_set=NULL;
+<a name="l00238"></a>00238     <span class="keywordtype">int</span> i=0;
+<a name="l00239"></a>00239     cpl_frame * frm=NULL;
+<a name="l00240"></a>00240     <span class="keywordtype">char</span> name_o[MAX_NAME_SIZE];
+<a name="l00241"></a>00241     <span class="keyword">const</span> <span class="keywordtype">char</span>* name=NULL;
+<a name="l00242"></a>00242 
+<a name="l00243"></a>00243     <span class="keywordtype">int</span> n=0;
+<a name="l00244"></a>00244     sinfo_msg(<span class="stringliteral">"Welcome to SINFONI Pipeline release %d.%d.%d"</span>,
+<a name="l00245"></a>00245         SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
+<a name="l00246"></a>00246 
+<a name="l00247"></a>00247     <span class="comment">/* HOW TO RETRIEVE INPUT PARAMETERS */</span>
+<a name="l00248"></a>00248     <span class="comment">/* --stropt */</span>
+<a name="l00249"></a>00249     check_nomsg(p=cpl_parameterlist_find(parlist, 
+<a name="l00250"></a>00250                                          <span class="stringliteral">"sinfoni.sinfo_utl_ima_line_corr.kappa"</span>));
+<a name="l00251"></a>00251     check_nomsg(kappa=cpl_parameter_get_int(p));
+<a name="l00252"></a>00252 
+<a name="l00253"></a>00253     <span class="comment">/* --boolopt */</span>
+<a name="l00254"></a>00254     check_nomsg(p=cpl_parameterlist_find(parlist,
+<a name="l00255"></a>00255                                          <span class="stringliteral">"sinfoni.sinfo_utl_ima_line_corr.filt_rad"</span>));
+<a name="l00256"></a>00256     check_nomsg(filt_rad = cpl_parameter_get_int(p)) ;
+<a name="l00257"></a>00257   
+<a name="l00258"></a>00258     <span class="comment">/* Identify the RAW and CALIB frames in the input frameset */</span>
+<a name="l00259"></a>00259     check(sinfo_dfs_set_groups(framelist),
+<a name="l00260"></a>00260          <span class="stringliteral">"Cannot identify RAW and CALIB frames"</span>) ;
+<a name="l00261"></a>00261  
+<a name="l00262"></a>00262     <span class="comment">/* HOW TO ACCESS INPUT DATA */</span>
+<a name="l00263"></a>00263     n=cpl_frameset_get_size(framelist);
+<a name="l00264"></a>00264     <span class="keywordflow">if</span>(n<1) {
+<a name="l00265"></a>00265       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Empty input frame list!"</span>);
+<a name="l00266"></a>00266       <span class="keywordflow">goto</span> cleanup ;
+<a name="l00267"></a>00267     }
+<a name="l00268"></a>00268     raw_set=cpl_frameset_new();
+<a name="l00269"></a>00269     ck0_nomsg(sinfo_extract_raw_frames(framelist, &raw_set));
+<a name="l00270"></a>00270     n=cpl_frameset_get_size(raw_set);
+<a name="l00271"></a>00271     <span class="keywordflow">if</span>(n<1) {
+<a name="l00272"></a>00272       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"No raw data found in frame list!"</span>);
+<a name="l00273"></a>00273       <span class="keywordflow">goto</span> cleanup ;
+<a name="l00274"></a>00274     }
+<a name="l00275"></a>00275 
+<a name="l00276"></a>00276 
+<a name="l00277"></a>00277     <span class="keywordflow">for</span>(i=0;i<n;i++) {
+<a name="l00278"></a>00278       check_nomsg(frm=cpl_frameset_get_frame(raw_set,0));
+<a name="l00279"></a>00279       check_nomsg(name=cpl_frame_get_filename(frm));
+<a name="l00280"></a>00280       check_nomsg(ima=cpl_image_load(name,CPL_TYPE_FLOAT,0,0));
+<a name="l00281"></a>00281 
+<a name="l00282"></a>00282       check_nomsg(sinfo_image_line_corr(width,filt_rad,kappa,ima,&ima_out));
+<a name="l00283"></a>00283 
+<a name="l00284"></a>00284       sprintf(name_o,<span class="stringliteral">"%s%d%s"</span>,<span class="stringliteral">"ima_cor"</span>,i,<span class="stringliteral">".fits"</span>) ;
+<a name="l00285"></a>00285 
+<a name="l00286"></a>00286       <span class="comment">/* Create product frame */</span>
+<a name="l00287"></a>00287       check_nomsg(product_frame = cpl_frame_new());
+<a name="l00288"></a>00288       check_nomsg(cpl_frame_set_filename(product_frame, name_o));
+<a name="l00289"></a>00289       check_nomsg(cpl_frame_set_tag(product_frame, <span class="stringliteral">"IMA_COR"</span>));
+<a name="l00290"></a>00290       check_nomsg(cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_IMAGE));
+<a name="l00291"></a>00291       check_nomsg(cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT));
+<a name="l00292"></a>00292       check(cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL),
+<a name="l00293"></a>00293         <span class="stringliteral">"Error while initialising the product frame"</span>) ;
+<a name="l00294"></a>00294     
+<a name="l00295"></a>00295       <span class="comment">/* Add DataFlow keywords */</span>
+<a name="l00296"></a>00296       <span class="comment">/*</span>
+<a name="l00297"></a>00297 <span class="comment">      check(cpl_dfs_setup_product_header(plist, </span>
+<a name="l00298"></a>00298 <span class="comment">                     product_frame, </span>
+<a name="l00299"></a>00299 <span class="comment">                     framelist, </span>
+<a name="l00300"></a>00300 <span class="comment">                     parlist,</span>
+<a name="l00301"></a>00301 <span class="comment">                     "sinfo_utl_ima_line_corr", </span>
+<a name="l00302"></a>00302 <span class="comment">                     "SINFONI", </span>
+<a name="l00303"></a>00303 <span class="comment">                     KEY_VALUE_HPRO_DID),</span>
+<a name="l00304"></a>00304 <span class="comment">        "Problem in the product DFS-compliance") ;</span>
+<a name="l00305"></a>00305 <span class="comment">      */</span>
+<a name="l00306"></a>00306 
+<a name="l00307"></a>00307       <span class="comment">/* Save the file */</span>
+<a name="l00308"></a>00308       check(cpl_image_save(ima_out, 
+<a name="l00309"></a>00309                name_o, 
+<a name="l00310"></a>00310                CPL_BPP_IEEE_FLOAT, 
+<a name="l00311"></a>00311                plist,
+<a name="l00312"></a>00312                CPL_IO_DEFAULT),
+<a name="l00313"></a>00313         <span class="stringliteral">"Could not save product"</span>);
+<a name="l00314"></a>00314       sinfo_free_propertylist(&plist) ;
+<a name="l00315"></a>00315       sinfo_free_image(&ima_out);
+<a name="l00316"></a>00316       sinfo_free_image(&ima);
+<a name="l00317"></a>00317 
+<a name="l00318"></a>00318       <span class="comment">/* Log the saved file in the input frameset */</span>
+<a name="l00319"></a>00319       check_nomsg(cpl_frameset_insert(framelist, product_frame)) ;
+<a name="l00320"></a>00320 
+<a name="l00321"></a>00321     }
+<a name="l00322"></a>00322 
+<a name="l00323"></a>00323  cleanup:
+<a name="l00324"></a>00324     sinfo_free_image(&ima);
+<a name="l00325"></a>00325     sinfo_free_image(&ima_out);
+<a name="l00326"></a>00326       <span class="comment">//sinfo_free_frameset(&raw_set);</span>
+<a name="l00327"></a>00327 
+<a name="l00328"></a>00328 
+<a name="l00329"></a>00329     <span class="comment">/* This is usually freed by esorex: but what about if errors occurs?</span>
+<a name="l00330"></a>00330 <span class="comment">    sinfo_free_frame(&product_frame) ;</span>
+<a name="l00331"></a>00331 <span class="comment">    */</span>
+<a name="l00332"></a>00332 
+<a name="l00333"></a>00333 
+<a name="l00334"></a>00334     <span class="keywordflow">if</span> (cpl_error_get_code()) {
+<a name="l00335"></a>00335         <span class="keywordflow">return</span> -1 ;
+<a name="l00336"></a>00336     } <span class="keywordflow">else</span> {
+<a name="l00337"></a>00337         <span class="keywordflow">return</span> 0 ;
+<a name="l00338"></a>00338     }
+<a name="l00339"></a>00339 
+<a name="l00340"></a>00340 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__utl__remove__crh__single_8c_source.html b/html/sinfo__utl__remove__crh__single_8c_source.html
new file mode 100644
index 0000000..398ec22
--- /dev/null
+++ b/html/sinfo__utl__remove__crh__single_8c_source.html
@@ -0,0 +1,431 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_utl_remove_crh_single.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_utl_remove_crh_single.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_utl_remove_crh_single.c,v 1.2 2009/01/30 14:56:12 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the SINFONI Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2009/01/30 14:56:12 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span>
+<a name="l00032"></a>00032 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                                Includes</span>
+<a name="l00034"></a>00034 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 <span class="preprocessor">#include <string.h></span>
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="comment">/* cpl */</span>
+<a name="l00038"></a>00038 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00039"></a>00039 
+<a name="l00040"></a>00040 <span class="comment">/* irplib */</span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include <irplib_utils.h></span>
+<a name="l00042"></a>00042 
+<a name="l00043"></a>00043 <span class="preprocessor">#include <sinfo_tpl_utils.h></span>
+<a name="l00044"></a>00044 <span class="preprocessor">#include <sinfo_pfits.h></span>
+<a name="l00045"></a>00045 <span class="preprocessor">#include <sinfo_tpl_dfs.h></span>
+<a name="l00046"></a>00046 <span class="preprocessor">#include <sinfo_key_names.h></span>
+<a name="l00047"></a>00047 <span class="preprocessor">#include <sinfo_raw_types.h></span>
+<a name="l00048"></a>00048 <span class="preprocessor">#include <sinfo_pro_types.h></span>
+<a name="l00049"></a>00049 <span class="preprocessor">#include <sinfo_functions.h></span>
+<a name="l00050"></a>00050 <span class="preprocessor">#include <sinfo_msg.h></span>
+<a name="l00051"></a>00051 <span class="preprocessor">#include <sinfo_error.h></span>
+<a name="l00052"></a>00052 <span class="preprocessor">#include <sinfo_utils_wrappers.h></span>
+<a name="l00053"></a>00053 <span class="preprocessor">#include <sinfo_remove_crh_single.h></span>
+<a name="l00054"></a>00054 
+<a name="l00055"></a>00055 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00056"></a>00056 <span class="comment">                            Functions prototypes</span>
+<a name="l00057"></a>00057 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00058"></a>00058 
+<a name="l00059"></a>00059 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_remove_crh_single_create(cpl_plugin *) ;
+<a name="l00060"></a>00060 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_remove_crh_single_exec(cpl_plugin *) ;
+<a name="l00061"></a>00061 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_remove_crh_single_destroy(cpl_plugin *) ;
+<a name="l00062"></a>00062 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_remove_crh_single(cpl_parameterlist *, cpl_frameset *) ;
+<a name="l00063"></a>00063 
+<a name="l00064"></a>00064 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00065"></a>00065 <span class="comment">                            Static variables</span>
+<a name="l00066"></a>00066 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00067"></a>00067 
+<a name="l00068"></a>00068 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_utl_remove_crh_single_description[] =
+<a name="l00069"></a>00069 <span class="stringliteral">"This recipe performs image computation.\n"</span>
+<a name="l00070"></a>00070 <span class="stringliteral">"The input files is one image\n"</span>
+<a name="l00071"></a>00071 <span class="stringliteral">"their associated tags should be IMA.\n"</span>
+<a name="l00072"></a>00072 <span class="stringliteral">"The output is the image cleaned from CRHs\n"</span>
+<a name="l00073"></a>00073 <span class="stringliteral">"Information on relevant parameters can be found with\n"</span>
+<a name="l00074"></a>00074 <span class="stringliteral">"esorex --params sinfo_utl_remove_crh_single\n"</span>
+<a name="l00075"></a>00075 <span class="stringliteral">"esorex --help sinfo_utl_remove_crh_single\n"</span>
+<a name="l00076"></a>00076 <span class="stringliteral">"\n"</span>;
+<a name="l00077"></a>00077 
+<a name="l00078"></a>00078 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00079"></a>00079 <span class="comment">                                Functions code</span>
+<a name="l00080"></a>00080 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00081"></a>00081 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00085"></a>00085 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00086"></a>00086 
+<a name="l00088"></a>00088 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00096"></a>00096 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00097"></a><a class="code" href="group__sinfo__utl__remove__crh__single.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693">00097</a> <span class="keywordtype">int</span> <a class="code" href="group__sinfo__rec__detlin.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693" title="Build the list of available plugins, for this module.">cpl_plugin_get_info</a>(cpl_pluginlist * list)
+<a name="l00098"></a>00098 {
+<a name="l00099"></a>00099     cpl_recipe  *   recipe = cpl_calloc(1, <span class="keyword">sizeof</span> *recipe ) ;
+<a name="l00100"></a>00100     cpl_plugin  *   plugin = &recipe->interface ;
+<a name="l00101"></a>00101 
+<a name="l00102"></a>00102     cpl_plugin_init(plugin,
+<a name="l00103"></a>00103                     CPL_PLUGIN_API,
+<a name="l00104"></a>00104                     SINFONI_BINARY_VERSION,
+<a name="l00105"></a>00105                     CPL_PLUGIN_TYPE_RECIPE,
+<a name="l00106"></a>00106                     <span class="stringliteral">"sinfo_utl_remove_crh_single"</span>,
+<a name="l00107"></a>00107                     <span class="stringliteral">"Remove CRHs from an image"</span>,
+<a name="l00108"></a>00108                     sinfo_utl_remove_crh_single_description,
+<a name="l00109"></a>00109                     <span class="stringliteral">"Andrea Modigliani"</span>,
+<a name="l00110"></a>00110                     <span class="stringliteral">"Andrea.Modigliani at eso.org"</span>,
+<a name="l00111"></a>00111                     sinfo_get_license(),
+<a name="l00112"></a>00112                     sinfo_utl_remove_crh_single_create,
+<a name="l00113"></a>00113                     sinfo_utl_remove_crh_single_exec,
+<a name="l00114"></a>00114                     sinfo_utl_remove_crh_single_destroy) ;
+<a name="l00115"></a>00115 
+<a name="l00116"></a>00116     cpl_pluginlist_append(list, plugin) ;
+<a name="l00117"></a>00117     
+<a name="l00118"></a>00118     <span class="keywordflow">return</span> 0;
+<a name="l00119"></a>00119 }
+<a name="l00120"></a>00120 
+<a name="l00121"></a>00121 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00130"></a>00130 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00131"></a>00131 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_remove_crh_single_create(cpl_plugin * plugin)
+<a name="l00132"></a>00132 {
+<a name="l00133"></a>00133     cpl_recipe      * recipe ;
+<a name="l00134"></a>00134     cpl_parameter   * p ;
+<a name="l00135"></a>00135 
+<a name="l00136"></a>00136     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00137"></a>00137     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00138"></a>00138         recipe = (cpl_recipe *)plugin ;
+<a name="l00139"></a>00139     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00140"></a>00140     cpl_error_reset();
+<a name="l00141"></a>00141     <a class="code" href="group__irplib__utils.html#gaf9d392144014e2363054bc3f83c8e47e" title="Reset IRPLIB state.">irplib_reset</a>();
+<a name="l00142"></a>00142 
+<a name="l00143"></a>00143     <span class="comment">/* Create the parameters list in the cpl_recipe object */</span>
+<a name="l00144"></a>00144     recipe->parameters = cpl_parameterlist_new() ; 
+<a name="l00145"></a>00145 
+<a name="l00146"></a>00146     <span class="comment">/* Fill the parameters list */</span>
+<a name="l00147"></a>00147     <span class="comment">/* --stropt */</span>
+<a name="l00148"></a>00148     p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.sinfo_utl_remove_crh_single.crh_frac_max"</span>, 
+<a name="l00149"></a>00149                                 CPL_TYPE_DOUBLE, 
+<a name="l00150"></a>00150                                 <span class="stringliteral">"Maximum fraction of allowed CRHs"</span>, 
+<a name="l00151"></a>00151                                 <span class="stringliteral">"sinfoni.sinfo_utl_remove_crh_single"</span>,0.7);
+<a name="l00152"></a>00152     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"crh_frac_max"</span>) ;
+<a name="l00153"></a>00153     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00154"></a>00154 
+<a name="l00155"></a>00155     <span class="comment">/* --doubleopt */</span>
+<a name="l00156"></a>00156     p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.sinfo_utl_remove_crh_single.sigma_lim"</span>, 
+<a name="l00157"></a>00157                 CPL_TYPE_DOUBLE, 
+<a name="l00158"></a>00158                 <span class="stringliteral">"Maximum sigma in kappa-sigma clip"</span>,
+<a name="l00159"></a>00159                 <span class="stringliteral">"sinfoni.sinfo_utl_remove_crh_single"</span>, 25.) ;
+<a name="l00160"></a>00160     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"sigma_lim"</span>) ;
+<a name="l00161"></a>00161     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00162"></a>00162 
+<a name="l00163"></a>00163 
+<a name="l00164"></a>00164 
+<a name="l00165"></a>00165     p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.sinfo_utl_remove_crh_single.f_lim"</span>, 
+<a name="l00166"></a>00166                 CPL_TYPE_DOUBLE, 
+<a name="l00167"></a>00167                 <span class="stringliteral">"Max fraction of bad pixels allowed"</span>,
+<a name="l00168"></a>00168                 <span class="stringliteral">"sinfoni.sinfo_utl_remove_crh_single"</span>, 0.7) ;
+<a name="l00169"></a>00169     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"f_lim"</span>) ;
+<a name="l00170"></a>00170     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00171"></a>00171 
+<a name="l00172"></a>00172 
+<a name="l00173"></a>00173     p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.sinfo_utl_remove_crh_single.max_iter"</span>,
+<a name="l00174"></a>00174                 CPL_TYPE_INT, 
+<a name="l00175"></a>00175                 <span class="stringliteral">"Max fraction of bad pixels allowed"</span>,
+<a name="l00176"></a>00176                 <span class="stringliteral">"sinfoni.sinfo_utl_remove_crh_single"</span>,5) ;
+<a name="l00177"></a>00177     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"max_iter"</span>) ;
+<a name="l00178"></a>00178     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00179"></a>00179 
+<a name="l00180"></a>00180 
+<a name="l00181"></a>00181 
+<a name="l00182"></a>00182     p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.sinfo_utl_remove_crh_single.gain"</span>,
+<a name="l00183"></a>00183                 CPL_TYPE_DOUBLE, 
+<a name="l00184"></a>00184                 <span class="stringliteral">"Detector's gain"</span>,
+<a name="l00185"></a>00185                 <span class="stringliteral">"sinfoni.sinfo_utl_remove_crh_single"</span>,2.42) ;
+<a name="l00186"></a>00186     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"gain"</span>) ;
+<a name="l00187"></a>00187     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00188"></a>00188 
+<a name="l00189"></a>00189 
+<a name="l00190"></a>00190     p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.sinfo_utl_remove_crh_single.ron"</span>,
+<a name="l00191"></a>00191                 CPL_TYPE_DOUBLE, 
+<a name="l00192"></a>00192                 <span class="stringliteral">"Detector's ron"</span>,
+<a name="l00193"></a>00193                 <span class="stringliteral">"sinfoni.sinfo_utl_remove_crh_single"</span>,1.) ;
+<a name="l00194"></a>00194     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"ron"</span>) ;
+<a name="l00195"></a>00195     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00196"></a>00196 
+<a name="l00197"></a>00197 
+<a name="l00198"></a>00198 
+<a name="l00199"></a>00199  
+<a name="l00200"></a>00200     <span class="comment">/* Return */</span>
+<a name="l00201"></a>00201     <span class="keywordflow">return</span> 0;
+<a name="l00202"></a>00202 }
+<a name="l00203"></a>00203 
+<a name="l00204"></a>00204 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00210"></a>00210 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00211"></a>00211 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_remove_crh_single_exec(cpl_plugin * plugin)
+<a name="l00212"></a>00212 {
+<a name="l00213"></a>00213     cpl_recipe  *   recipe ;
+<a name="l00214"></a>00214      <span class="keywordtype">int</span> code=0;
+<a name="l00215"></a>00215      cpl_errorstate initial_errorstate = cpl_errorstate_get();
+<a name="l00216"></a>00216 
+<a name="l00217"></a>00217     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00218"></a>00218     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00219"></a>00219         recipe = (cpl_recipe *)plugin ;
+<a name="l00220"></a>00220     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00221"></a>00221     cpl_error_reset();
+<a name="l00222"></a>00222     <a class="code" href="group__irplib__utils.html#gaf9d392144014e2363054bc3f83c8e47e" title="Reset IRPLIB state.">irplib_reset</a>();
+<a name="l00223"></a>00223     code = sinfo_utl_remove_crh_single(recipe->parameters, recipe->frames) ;
+<a name="l00224"></a>00224 
+<a name="l00225"></a>00225 
+<a name="l00226"></a>00226     <span class="keywordflow">if</span> (!cpl_errorstate_is_equal(initial_errorstate)) {                      
+<a name="l00227"></a>00227         <span class="comment">/* Dump the error history since recipe execution start.                </span>
+<a name="l00228"></a>00228 <span class="comment">           At this point the recipe cannot recover from the error */</span>           
+<a name="l00229"></a>00229         cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);              
+<a name="l00230"></a>00230     } 
+<a name="l00231"></a>00231 
+<a name="l00232"></a>00232     <span class="keywordflow">return</span> code ;
+<a name="l00233"></a>00233 }
+<a name="l00234"></a>00234 
+<a name="l00235"></a>00235 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00241"></a>00241 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00242"></a>00242 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_remove_crh_single_destroy(cpl_plugin * plugin)
+<a name="l00243"></a>00243 {
+<a name="l00244"></a>00244     cpl_recipe  *   recipe ;
+<a name="l00245"></a>00245     
+<a name="l00246"></a>00246     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00247"></a>00247     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00248"></a>00248         recipe = (cpl_recipe *)plugin ;
+<a name="l00249"></a>00249     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00250"></a>00250 
+<a name="l00251"></a>00251     cpl_parameterlist_delete(recipe->parameters) ; 
+<a name="l00252"></a>00252     <span class="keywordflow">return</span> 0 ;
+<a name="l00253"></a>00253 }
+<a name="l00254"></a>00254 
+<a name="l00255"></a>00255 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00262"></a>00262 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00263"></a>00263 <span class="keyword">static</span> <span class="keywordtype">int</span> 
+<a name="l00264"></a>00264 sinfo_utl_remove_crh_single( cpl_parameterlist   *   parlist, 
+<a name="l00265"></a>00265         cpl_frameset        *   framelist)
+<a name="l00266"></a>00266 {
+<a name="l00267"></a>00267     cpl_parameter       *   param= NULL ;
+<a name="l00268"></a>00268     cpl_frameset * raw_on=NULL;
+<a name="l00269"></a>00269     cpl_frameset * raw_off=NULL;
+<a name="l00270"></a>00270     <span class="keywordtype">double</span> crh_frac_max=0;
+<a name="l00271"></a>00271     <span class="keywordtype">double</span> sigma_lim=0;
+<a name="l00272"></a>00272     <span class="keywordtype">double</span> f_lim=0;
+<a name="l00273"></a>00273     <span class="keywordtype">int</span> max_iter=0;
+<a name="l00274"></a>00274     <span class="keywordtype">double</span> gain=0;
+<a name="l00275"></a>00275     <span class="keywordtype">double</span> ron=0;
+<a name="l00276"></a>00276     <span class="keywordtype">int</span> nraw=0;
+<a name="l00277"></a>00277     <span class="keywordtype">int</span> n=0;
+<a name="l00278"></a>00278     cpl_image* ima_res=NULL;
+<a name="l00279"></a>00279     <span class="keywordtype">char</span> name[256];
+<a name="l00280"></a>00280     cpl_image* image=NULL;
+<a name="l00281"></a>00281     cpl_image* img_on=NULL;
+<a name="l00282"></a>00282     cpl_image* img_off=NULL;
+<a name="l00283"></a>00283     cpl_propertylist* plist=NULL;
+<a name="l00284"></a>00284     <span class="keyword">const</span> <span class="keywordtype">char</span>* name_o=NULL;
+<a name="l00285"></a>00285     cpl_frame* product_frame=NULL;
+<a name="l00286"></a>00286     cpl_frame* frame_on=NULL;
+<a name="l00287"></a>00287     cpl_frame* frame_off=NULL;
+<a name="l00288"></a>00288 
+<a name="l00289"></a>00289           sinfo_msg(<span class="stringliteral">"Welcome to SINFONI Pipeline release %d.%d.%d"</span>,
+<a name="l00290"></a>00290         SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
+<a name="l00291"></a>00291 
+<a name="l00292"></a>00292     <span class="comment">/* HOW TO RETRIEVE INPUT PARAMETERS */</span>
+<a name="l00293"></a>00293     check_nomsg(param=cpl_parameterlist_find(parlist, 
+<a name="l00294"></a>00294                                              <span class="stringliteral">"sinfoni.sinfo_utl_remove_crh_single.crh_frac_max"</span>));
+<a name="l00295"></a>00295     check_nomsg(crh_frac_max=cpl_parameter_get_double(param));
+<a name="l00296"></a>00296 
+<a name="l00297"></a>00297     check_nomsg(param=cpl_parameterlist_find(parlist,
+<a name="l00298"></a>00298                                              <span class="stringliteral">"sinfoni.sinfo_utl_remove_crh_single.sigma_lim"</span>));
+<a name="l00299"></a>00299     check_nomsg(sigma_lim = cpl_parameter_get_double(param)) ;
+<a name="l00300"></a>00300 
+<a name="l00301"></a>00301 
+<a name="l00302"></a>00302     check_nomsg(param=cpl_parameterlist_find(parlist,
+<a name="l00303"></a>00303                                              <span class="stringliteral">"sinfoni.sinfo_utl_remove_crh_single.f_lim"</span>));
+<a name="l00304"></a>00304     check_nomsg(f_lim = cpl_parameter_get_double(param)) ;
+<a name="l00305"></a>00305 
+<a name="l00306"></a>00306     check_nomsg(param=cpl_parameterlist_find(parlist,
+<a name="l00307"></a>00307                                              <span class="stringliteral">"sinfoni.sinfo_utl_remove_crh_single.max_iter"</span>));
+<a name="l00308"></a>00308     check_nomsg(max_iter = cpl_parameter_get_int(param)) ;
+<a name="l00309"></a>00309 
+<a name="l00310"></a>00310     check_nomsg(param=cpl_parameterlist_find(parlist,
+<a name="l00311"></a>00311                                              <span class="stringliteral">"sinfoni.sinfo_utl_remove_crh_single.gain"</span>));
+<a name="l00312"></a>00312     check_nomsg(gain = cpl_parameter_get_double(param)) ;
+<a name="l00313"></a>00313 
+<a name="l00314"></a>00314 
+<a name="l00315"></a>00315     check_nomsg(param=cpl_parameterlist_find(parlist,
+<a name="l00316"></a>00316                                              <span class="stringliteral">"sinfoni.sinfo_utl_remove_crh_single.ron"</span>));
+<a name="l00317"></a>00317     check_nomsg(ron = cpl_parameter_get_double(param)) ;
+<a name="l00318"></a>00318   
+<a name="l00319"></a>00319     <span class="comment">/* Identify the RAW and CALIB frames in the input frameset */</span>
+<a name="l00320"></a>00320     check(sinfo_dfs_set_groups(framelist),
+<a name="l00321"></a>00321          <span class="stringliteral">"Cannot identify RAW and CALIB frames"</span>) ;
+<a name="l00322"></a>00322     <span class="comment">//cpl_frameset_dump(framelist,stdout);</span>
+<a name="l00323"></a>00323 
+<a name="l00324"></a>00324     <span class="comment">/* HOW TO ACCESS INPUT DATA */</span>
+<a name="l00325"></a>00325     n=cpl_frameset_get_size(framelist);
+<a name="l00326"></a>00326     <span class="keywordflow">if</span>(n<1) {
+<a name="l00327"></a>00327       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Empty input frame list!"</span>);
+<a name="l00328"></a>00328       <span class="keywordflow">goto</span> cleanup ;
+<a name="l00329"></a>00329     }
+<a name="l00330"></a>00330 
+<a name="l00331"></a>00331     <span class="comment">/* HOW TO ACCESS INPUT DATA */</span>
+<a name="l00332"></a>00332     check_nomsg(raw_on=cpl_frameset_new());
+<a name="l00333"></a>00333 
+<a name="l00334"></a>00334     check(sinfo_contains_frames_kind(framelist,raw_on,RAW_ON),
+<a name="l00335"></a>00335      <span class="stringliteral">"Found no input frames with tag %s"</span>,RAW_ON);
+<a name="l00336"></a>00336     check_nomsg(nraw=cpl_frameset_get_size(raw_on));
+<a name="l00337"></a>00337     <span class="keywordflow">if</span> (nraw<1) {
+<a name="l00338"></a>00338       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Found no input frames with tag %s"</span>,RAW_ON);
+<a name="l00339"></a>00339       <span class="keywordflow">goto</span> cleanup;
+<a name="l00340"></a>00340     }
+<a name="l00341"></a>00341 
+<a name="l00342"></a>00342 
+<a name="l00343"></a>00343     check_nomsg(raw_off=cpl_frameset_new());
+<a name="l00344"></a>00344 
+<a name="l00345"></a>00345     check(sinfo_contains_frames_kind(framelist,raw_off,RAW_OFF),
+<a name="l00346"></a>00346      <span class="stringliteral">"Found no input frames with tag %s"</span>,RAW_OFF);
+<a name="l00347"></a>00347     check_nomsg(nraw=cpl_frameset_get_size(raw_off));
+<a name="l00348"></a>00348     <span class="keywordflow">if</span> (nraw<1) {
+<a name="l00349"></a>00349       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Found no input frames with tag %s"</span>,RAW_OFF);
+<a name="l00350"></a>00350       <span class="keywordflow">goto</span> cleanup;
+<a name="l00351"></a>00351     }
+<a name="l00352"></a>00352 
+<a name="l00353"></a>00353 
+<a name="l00354"></a>00354     check_nomsg(frame_on=cpl_frameset_get_first(raw_on));
+<a name="l00355"></a>00355     check_nomsg(strcpy(name,cpl_frame_get_filename(frame_on)));
+<a name="l00356"></a>00356     check_nomsg(sinfo_free_frameset(&raw_on));
+<a name="l00357"></a>00357     sinfo_msg(<span class="stringliteral">"name=%s"</span>,name);
+<a name="l00358"></a>00358     check_nomsg(img_on=cpl_image_load(name,CPL_TYPE_FLOAT,0,0));
+<a name="l00359"></a>00359     check(plist=cpl_propertylist_load(name,0),
+<a name="l00360"></a>00360           <span class="stringliteral">"Cannot read the FITS header"</span>) ;
+<a name="l00361"></a>00361 
+<a name="l00362"></a>00362 
+<a name="l00363"></a>00363     frame_off=cpl_frameset_get_first(raw_off);
+<a name="l00364"></a>00364     strcpy(name,cpl_frame_get_filename(frame_off));
+<a name="l00365"></a>00365     sinfo_free_frameset(&raw_off);
+<a name="l00366"></a>00366 
+<a name="l00367"></a>00367     img_off=cpl_image_load(name,CPL_TYPE_FLOAT,0,0);
+<a name="l00368"></a>00368 
+<a name="l00369"></a>00369     image=cpl_image_duplicate(img_on);
+<a name="l00370"></a>00370     sinfo_free_image(&img_on);
+<a name="l00371"></a>00371 
+<a name="l00372"></a>00372     cpl_image_subtract(image,img_off);
+<a name="l00373"></a>00373     cpl_image_save(image,<span class="stringliteral">"image_with_crh.fits"</span>,CPL_BPP_IEEE_FLOAT,NULL,
+<a name="l00374"></a>00374            CPL_IO_DEFAULT);
+<a name="l00375"></a>00375 
+<a name="l00376"></a>00376     check(ima_res=sinfo_remove_crh_single(image,crh_frac_max,sigma_lim,f_lim,
+<a name="l00377"></a>00377                       max_iter,gain,ron),
+<a name="l00378"></a>00378       <span class="stringliteral">"fail to remove CRHs"</span>);
+<a name="l00379"></a>00379 
+<a name="l00380"></a>00380     sinfo_free_image(&image); 
+<a name="l00381"></a>00381 
+<a name="l00382"></a>00382 
+<a name="l00383"></a>00383 
+<a name="l00384"></a>00384     <span class="comment">/* HOW TO SAVE A PRODUCT ON DISK  */</span>
+<a name="l00385"></a>00385     <span class="comment">/* Set the file name */</span>
+<a name="l00386"></a>00386     name_o = <span class="stringliteral">"ima_res.fits"</span> ;
+<a name="l00387"></a>00387 
+<a name="l00388"></a>00388     <span class="comment">/* Create product frame */</span>
+<a name="l00389"></a>00389     check_nomsg(product_frame = cpl_frame_new());
+<a name="l00390"></a>00390     check_nomsg(cpl_frame_set_filename(product_frame, name_o)) ;
+<a name="l00391"></a>00391     check_nomsg(cpl_frame_set_tag(product_frame, SI_UTL_IMA_ARITH_PROIMA)) ;
+<a name="l00392"></a>00392     check_nomsg(cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_IMAGE)) ;
+<a name="l00393"></a>00393     check_nomsg(cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT)) ;
+<a name="l00394"></a>00394     check(cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL),
+<a name="l00395"></a>00395       <span class="stringliteral">"Error while initialising the product frame"</span>) ;
+<a name="l00396"></a>00396     
+<a name="l00397"></a>00397     <span class="comment">/* Add DataFlow keywords */</span>
+<a name="l00398"></a>00398     check_nomsg(cpl_propertylist_erase_regexp(plist, <span class="stringliteral">"^ESO PRO CATG"</span>,0));
+<a name="l00399"></a>00399 <span class="preprocessor">#if defined CPL_VERSION_CODE && CPL_VERSION_CODE >= CPL_VERSION(4, 8, 0) </span>
+<a name="l00400"></a>00400 <span class="preprocessor"></span>    check(cpl_dfs_setup_product_header(plist, 
+<a name="l00401"></a>00401                                        product_frame, 
+<a name="l00402"></a>00402                                        framelist, 
+<a name="l00403"></a>00403                                        parlist,
+<a name="l00404"></a>00404                                        <span class="stringliteral">"sinfo_utl_remove_crh_single"</span>, 
+<a name="l00405"></a>00405                                        <span class="stringliteral">"SINFONI"</span>, 
+<a name="l00406"></a>00406                                        KEY_VALUE_HPRO_DID,NULL),
+<a name="l00407"></a>00407       <span class="stringliteral">"Problem in the product DFS-compliance"</span>) ;
+<a name="l00408"></a>00408 <span class="preprocessor">#else</span>
+<a name="l00409"></a>00409 <span class="preprocessor"></span>    check(cpl_dfs_setup_product_header(plist, 
+<a name="l00410"></a>00410                                        product_frame, 
+<a name="l00411"></a>00411                                        framelist, 
+<a name="l00412"></a>00412                                        parlist,
+<a name="l00413"></a>00413                                        <span class="stringliteral">"sinfo_utl_remove_crh_single"</span>, 
+<a name="l00414"></a>00414                                        <span class="stringliteral">"SINFONI"</span>, 
+<a name="l00415"></a>00415                                        KEY_VALUE_HPRO_DID),
+<a name="l00416"></a>00416       <span class="stringliteral">"Problem in the product DFS-compliance"</span>) ;
+<a name="l00417"></a>00417 <span class="preprocessor">#endif</span>
+<a name="l00418"></a>00418 <span class="preprocessor"></span>    <span class="comment">/* Save the file */</span>
+<a name="l00419"></a>00419     check(cpl_image_save(ima_res, 
+<a name="l00420"></a>00420                          name_o, 
+<a name="l00421"></a>00421                          CPL_BPP_IEEE_FLOAT, 
+<a name="l00422"></a>00422                          plist,
+<a name="l00423"></a>00423                          CPL_IO_DEFAULT),
+<a name="l00424"></a>00424       <span class="stringliteral">"Could not save product"</span>);
+<a name="l00425"></a>00425     sinfo_free_propertylist(&plist) ;
+<a name="l00426"></a>00426 
+<a name="l00427"></a>00427 
+<a name="l00428"></a>00428     <span class="comment">/* Log the saved file in the input frameset */</span>
+<a name="l00429"></a>00429     check_nomsg(cpl_frameset_insert(framelist, product_frame)) ;
+<a name="l00430"></a>00430 
+<a name="l00431"></a>00431 
+<a name="l00432"></a>00432  cleanup:
+<a name="l00433"></a>00433    
+<a name="l00434"></a>00434     sinfo_free_frameset(&raw_on);
+<a name="l00435"></a>00435     sinfo_free_frameset(&raw_off);
+<a name="l00436"></a>00436     sinfo_free_image(&img_on);
+<a name="l00437"></a>00437     sinfo_free_image(&img_off);
+<a name="l00438"></a>00438     sinfo_free_propertylist(&plist) ;
+<a name="l00439"></a>00439     <span class="comment">/* This is usually freed by esorex: but what about if errors occurs?</span>
+<a name="l00440"></a>00440 <span class="comment">    sinfo_free_frame(&product_frame) ;</span>
+<a name="l00441"></a>00441 <span class="comment">    */</span>
+<a name="l00442"></a>00442     sinfo_free_image(&image) ;
+<a name="l00443"></a>00443 
+<a name="l00444"></a>00444     <span class="keywordflow">if</span> (cpl_error_get_code()) {
+<a name="l00445"></a>00445         <span class="keywordflow">return</span> -1 ;
+<a name="l00446"></a>00446     } <span class="keywordflow">else</span> {
+<a name="l00447"></a>00447         <span class="keywordflow">return</span> 0 ;
+<a name="l00448"></a>00448     }
+<a name="l00449"></a>00449 
+<a name="l00450"></a>00450 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__utl__seds_8c_source.html b/html/sinfo__utl__seds_8c_source.html
new file mode 100644
index 0000000..412c552
--- /dev/null
+++ b/html/sinfo__utl__seds_8c_source.html
@@ -0,0 +1,284 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_utl_seds.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_utl_seds.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_utl_seds.c,v 1.1 2008/06/11 13:42:20 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the SINFONI Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2008/06/11 13:42:20 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.1 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span>
+<a name="l00032"></a>00032 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                                Includes</span>
+<a name="l00034"></a>00034 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 
+<a name="l00036"></a>00036 <span class="preprocessor">#include <math.h></span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00038"></a>00038 
+<a name="l00039"></a>00039 <span class="preprocessor">#include "irplib_utils.h"</span>
+<a name="l00040"></a>00040 
+<a name="l00041"></a>00041 
+<a name="l00042"></a>00042 <span class="preprocessor">#include "sinfo_raw_types.h"</span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include "sinfo_pro_types.h"</span>
+<a name="l00044"></a>00044 <span class="preprocessor">#include "sinfo_tpl_utils.h"</span>
+<a name="l00045"></a>00045 <span class="preprocessor">#include "sinfo_tpl_dfs.h"</span>
+<a name="l00046"></a>00046 
+<a name="l00047"></a>00047 <span class="comment">/*</span>
+<a name="l00048"></a>00048 <span class="comment">#include "isaac_utils.h"</span>
+<a name="l00049"></a>00049 <span class="comment">#include "isaac_pfits.h"</span>
+<a name="l00050"></a>00050 <span class="comment">#include "isaac_dfs.h"</span>
+<a name="l00051"></a>00051 <span class="comment">*/</span>
+<a name="l00052"></a>00052 
+<a name="l00053"></a>00053 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00054"></a>00054 <span class="comment">                            Functions prototypes</span>
+<a name="l00055"></a>00055 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00056"></a>00056 
+<a name="l00057"></a>00057 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_seds_create(cpl_plugin *) ;
+<a name="l00058"></a>00058 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_seds_exec(cpl_plugin *) ;
+<a name="l00059"></a>00059 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_seds_destroy(cpl_plugin *) ;
+<a name="l00060"></a>00060 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_seds(cpl_parameterlist *, cpl_frameset *) ;
+<a name="l00061"></a>00061 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_seds_save(cpl_table *, cpl_parameterlist *, 
+<a name="l00062"></a>00062         cpl_frameset *) ;
+<a name="l00063"></a>00063 
+<a name="l00064"></a>00064 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00065"></a>00065 <span class="comment">                            Static variables</span>
+<a name="l00066"></a>00066 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00067"></a>00067 
+<a name="l00068"></a>00068 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_utl_seds_description[] = 
+<a name="l00069"></a>00069 <span class="stringliteral">"sinfo_utl_seds -- SINFONI SEDS table creation.\n"</span>
+<a name="l00070"></a>00070 <span class="stringliteral">"The files listed in the Set Of Frames (sof-file) must be tagged:\n"</span>
+<a name="l00071"></a>00071 <span class="stringliteral">"raw-file.fits "</span>SINFO_UTL_SEDS_RAW<span class="stringliteral">"\n"</span> ;
+<a name="l00072"></a>00072 
+<a name="l00073"></a>00073 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00074"></a>00074 <span class="comment">                                Functions code</span>
+<a name="l00075"></a>00075 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00076"></a>00076 
+<a name="l00077"></a>00077 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00085"></a>00085 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00086"></a>00086 <span class="keywordtype">int</span> <a class="code" href="group__sinfo__rec__detlin.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693" title="Build the list of available plugins, for this module.">cpl_plugin_get_info</a>(cpl_pluginlist * list)
+<a name="l00087"></a>00087 {
+<a name="l00088"></a>00088     cpl_recipe  *   recipe = cpl_calloc(1, <span class="keyword">sizeof</span>(*recipe)) ;
+<a name="l00089"></a>00089     cpl_plugin  *   plugin = &recipe->interface ;
+<a name="l00090"></a>00090 
+<a name="l00091"></a>00091     cpl_plugin_init(plugin,
+<a name="l00092"></a>00092                     CPL_PLUGIN_API,
+<a name="l00093"></a>00093                     SINFONI_BINARY_VERSION,
+<a name="l00094"></a>00094                     CPL_PLUGIN_TYPE_RECIPE,
+<a name="l00095"></a>00095                     <span class="stringliteral">"sinfo_utl_seds"</span>,
+<a name="l00096"></a>00096                     <span class="stringliteral">"SEDS table creation"</span>,
+<a name="l00097"></a>00097                     sinfo_utl_seds_description,
+<a name="l00098"></a>00098                     <span class="stringliteral">"Yves Jung"</span>,
+<a name="l00099"></a>00099                     <span class="stringliteral">"yjung at eso.org"</span>,
+<a name="l00100"></a>00100                     sinfo_get_license(),
+<a name="l00101"></a>00101                     sinfo_utl_seds_create,
+<a name="l00102"></a>00102                     sinfo_utl_seds_exec,
+<a name="l00103"></a>00103                     sinfo_utl_seds_destroy) ;
+<a name="l00104"></a>00104 
+<a name="l00105"></a>00105     cpl_pluginlist_append(list, plugin) ;
+<a name="l00106"></a>00106     
+<a name="l00107"></a>00107     <span class="keywordflow">return</span> 0;
+<a name="l00108"></a>00108 }
+<a name="l00109"></a>00109 
+<a name="l00110"></a>00110 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00119"></a>00119 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00120"></a>00120 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_seds_create(cpl_plugin * plugin)
+<a name="l00121"></a>00121 {
+<a name="l00122"></a>00122     cpl_recipe      * recipe ;
+<a name="l00123"></a>00123 
+<a name="l00124"></a>00124     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00125"></a>00125     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
+<a name="l00126"></a>00126         recipe = (cpl_recipe *)plugin ;
+<a name="l00127"></a>00127     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00128"></a>00128 
+<a name="l00129"></a>00129     <span class="comment">/* Create the parameters list in the cpl_recipe object */</span>
+<a name="l00130"></a>00130     recipe->parameters = cpl_parameterlist_new() ;
+<a name="l00131"></a>00131 
+<a name="l00132"></a>00132     <span class="comment">/* Return */</span>
+<a name="l00133"></a>00133     <span class="keywordflow">return</span> 0;
+<a name="l00134"></a>00134 }
+<a name="l00135"></a>00135 
+<a name="l00136"></a>00136 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00142"></a>00142 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00143"></a>00143 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_seds_exec(cpl_plugin * plugin)
+<a name="l00144"></a>00144 {
+<a name="l00145"></a>00145     cpl_recipe  *   recipe ;
+<a name="l00146"></a>00146 
+<a name="l00147"></a>00147     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00148"></a>00148     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
+<a name="l00149"></a>00149         recipe = (cpl_recipe *)plugin ;
+<a name="l00150"></a>00150     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00151"></a>00151 
+<a name="l00152"></a>00152     <span class="keywordflow">return</span> sinfo_utl_seds(recipe->parameters, recipe->frames) ;
+<a name="l00153"></a>00153 }
+<a name="l00154"></a>00154 
+<a name="l00155"></a>00155 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00161"></a>00161 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00162"></a>00162 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_seds_destroy(cpl_plugin * plugin)
+<a name="l00163"></a>00163 {
+<a name="l00164"></a>00164     cpl_recipe  *   recipe ;
+<a name="l00165"></a>00165 
+<a name="l00166"></a>00166     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00167"></a>00167     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
+<a name="l00168"></a>00168         recipe = (cpl_recipe *)plugin ;
+<a name="l00169"></a>00169     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00170"></a>00170 
+<a name="l00171"></a>00171     cpl_parameterlist_delete(recipe->parameters) ;
+<a name="l00172"></a>00172     <span class="keywordflow">return</span> 0 ;
+<a name="l00173"></a>00173 }
+<a name="l00174"></a>00174 
+<a name="l00175"></a>00175 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00182"></a>00182 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00183"></a>00183 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_seds(
+<a name="l00184"></a>00184         cpl_parameterlist   *   parlist, 
+<a name="l00185"></a>00185         cpl_frameset        *   framelist)
+<a name="l00186"></a>00186 {
+<a name="l00187"></a>00187     cpl_frame       *   cur_frame ;
+<a name="l00188"></a>00188     cpl_frameset    *   rawframes ;
+<a name="l00189"></a>00189     <span class="keywordtype">int</span>                 nframes, nlines ;
+<a name="l00190"></a>00190     cpl_table       *   out ;
+<a name="l00191"></a>00191     cpl_bivector    **  seds ;
+<a name="l00192"></a>00192     <span class="keywordtype">char</span>            *   name ;
+<a name="l00193"></a>00193     cpl_vector      *   tmp_vec ;
+<a name="l00194"></a>00194     <span class="keywordtype">int</span>                 i, j ;
+<a name="l00195"></a>00195     
+<a name="l00196"></a>00196     <span class="comment">/* Identify the RAW and CALIB frames in the input frameset */</span>
+<a name="l00197"></a>00197     <span class="keywordflow">if</span> (sinfo_dfs_set_groups(framelist)) {
+<a name="l00198"></a>00198         cpl_msg_error(__func__, <span class="stringliteral">"Cannot identify RAW and CALIB frames"</span>) ;
+<a name="l00199"></a>00199         <span class="keywordflow">return</span> -1 ;
+<a name="l00200"></a>00200     }
+<a name="l00201"></a>00201 
+<a name="l00202"></a>00202     <span class="comment">/* Retrieve raw frames */</span>
+<a name="l00203"></a>00203     <span class="keywordflow">if</span> ((rawframes = sinfo_extract_frameset(framelist,
+<a name="l00204"></a>00204                     SINFO_UTL_SEDS_RAW)) == NULL) {
+<a name="l00205"></a>00205         cpl_msg_error(__func__, <span class="stringliteral">"Cannot find raw frames in the input list"</span>) ;
+<a name="l00206"></a>00206         <span class="keywordflow">return</span> -1 ;
+<a name="l00207"></a>00207     }
+<a name="l00208"></a>00208     nframes = cpl_frameset_get_size(rawframes) ;
+<a name="l00209"></a>00209  
+<a name="l00210"></a>00210     <span class="comment">/* Load */</span>
+<a name="l00211"></a>00211     seds = cpl_malloc(nframes * <span class="keyword">sizeof</span>(cpl_bivector*)) ;
+<a name="l00212"></a>00212     <span class="keywordflow">for</span> (i=0 ; i<nframes ; i++) {
+<a name="l00213"></a>00213         cur_frame = cpl_frameset_get_frame(rawframes, i) ;
+<a name="l00214"></a>00214         <span class="keywordflow">if</span> ((seds[i] = cpl_bivector_read(cpl_frame_get_filename(cur_frame))) 
+<a name="l00215"></a>00215                 == NULL) {
+<a name="l00216"></a>00216             cpl_msg_error(__func__, <span class="stringliteral">"Cannot load the sed %d"</span>, i+1) ;
+<a name="l00217"></a>00217             <span class="keywordflow">for</span> (j=0 ; j<i ; j++) cpl_bivector_delete(seds[j]) ;
+<a name="l00218"></a>00218             cpl_free(seds) ;
+<a name="l00219"></a>00219             cpl_frameset_delete(rawframes) ;
+<a name="l00220"></a>00220             <span class="keywordflow">return</span> -1 ;
+<a name="l00221"></a>00221         }
+<a name="l00222"></a>00222     }
+<a name="l00223"></a>00223 
+<a name="l00224"></a>00224     <span class="comment">/* Verify the length */</span>
+<a name="l00225"></a>00225     nlines = cpl_bivector_get_size(seds[0]) ;
+<a name="l00226"></a>00226     <span class="keywordflow">for</span> (i=1 ; i<nframes ; i++) {
+<a name="l00227"></a>00227         <span class="keywordflow">if</span> (cpl_bivector_get_size(seds[i]) != nlines) {
+<a name="l00228"></a>00228             cpl_msg_error(__func__, <span class="stringliteral">"Wrong SED size abort"</span>) ;
+<a name="l00229"></a>00229             <span class="keywordflow">for</span> (j=0 ; j<nframes ; j++) cpl_bivector_delete(seds[j]) ;
+<a name="l00230"></a>00230             cpl_free(seds) ;
+<a name="l00231"></a>00231             cpl_frameset_delete(rawframes) ;
+<a name="l00232"></a>00232             <span class="keywordflow">return</span> -1 ;
+<a name="l00233"></a>00233         }
+<a name="l00234"></a>00234     }
+<a name="l00235"></a>00235     
+<a name="l00236"></a>00236     <span class="comment">/* Create the out table */</span>
+<a name="l00237"></a>00237     out = cpl_table_new(nlines) ;
+<a name="l00238"></a>00238     tmp_vec = cpl_vector_duplicate(cpl_bivector_get_x(seds[0])) ;
+<a name="l00239"></a>00239     cpl_table_wrap_double(out, cpl_vector_get_data(tmp_vec), <span class="stringliteral">"Wavelength"</span>) ;
+<a name="l00240"></a>00240     cpl_vector_unwrap(tmp_vec) ;
+<a name="l00241"></a>00241     
+<a name="l00242"></a>00242     <span class="comment">/* Fill the table */</span>
+<a name="l00243"></a>00243     <span class="keywordflow">for</span> (i=0 ; i<nframes ; i++) {
+<a name="l00244"></a>00244         <span class="comment">/* Create the column */</span>
+<a name="l00245"></a>00245         cur_frame = cpl_frameset_get_frame(rawframes, i) ;
+<a name="l00246"></a>00246         name = cpl_strdup(cpl_frame_get_filename(cur_frame)) ;
+<a name="l00247"></a>00247         name[3] = (char)0 ;
+<a name="l00248"></a>00248         tmp_vec = cpl_vector_duplicate(cpl_bivector_get_y(seds[i])) ;
+<a name="l00249"></a>00249         cpl_table_wrap_double(out, cpl_vector_get_data(tmp_vec), name) ;
+<a name="l00250"></a>00250         cpl_vector_unwrap(tmp_vec) ;
+<a name="l00251"></a>00251         cpl_free(name) ;
+<a name="l00252"></a>00252     }
+<a name="l00253"></a>00253     cpl_frameset_delete(rawframes) ;
+<a name="l00254"></a>00254     cpl_free(seds) ;
+<a name="l00255"></a>00255 
+<a name="l00256"></a>00256     <span class="comment">/* Save the table */</span>
+<a name="l00257"></a>00257     <span class="keywordflow">if</span> (sinfo_utl_seds_save(out, parlist, framelist) != 0) {
+<a name="l00258"></a>00258         cpl_msg_error(__func__, <span class="stringliteral">"Cannot create product"</span>) ;
+<a name="l00259"></a>00259         cpl_table_delete(out) ;
+<a name="l00260"></a>00260         <span class="keywordflow">return</span> -1 ;
+<a name="l00261"></a>00261     }
+<a name="l00262"></a>00262     
+<a name="l00263"></a>00263     <span class="comment">/* Free and return */</span>
+<a name="l00264"></a>00264     cpl_table_delete(out) ;
+<a name="l00265"></a>00265     <span class="keywordflow">return</span> 0 ;
+<a name="l00266"></a>00266 }
+<a name="l00267"></a>00267 
+<a name="l00268"></a>00268 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00276"></a>00276 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00277"></a>00277 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_seds_save(
+<a name="l00278"></a>00278         cpl_table           *   sed,
+<a name="l00279"></a>00279         cpl_parameterlist   *   parlist,
+<a name="l00280"></a>00280         cpl_frameset        *   <span class="keyword">set</span>)
+<a name="l00281"></a>00281 {
+<a name="l00282"></a>00282     cpl_propertylist    *   plist ;
+<a name="l00283"></a>00283 
+<a name="l00284"></a>00284     <span class="comment">/* Some keywords  */</span>
+<a name="l00285"></a>00285     plist = cpl_propertylist_new() ;
+<a name="l00286"></a>00286     cpl_propertylist_append_string(plist, <span class="stringliteral">"INSTRUME"</span>, <span class="stringliteral">"SINFO"</span>) ;
+<a name="l00287"></a>00287  
+<a name="l00288"></a>00288     <span class="comment">/* Write the table */</span>
+<a name="l00289"></a>00289     cpl_dfs_save_table(<span class="keyword">set</span>,
+<a name="l00290"></a>00290             parlist,
+<a name="l00291"></a>00291             <span class="keyword">set</span>,
+<a name="l00292"></a>00292             sed,
+<a name="l00293"></a>00293             NULL,
+<a name="l00294"></a>00294             <span class="stringliteral">"sinfo_utl_seds"</span>,
+<a name="l00295"></a>00295             SINFO_UTL_SEDS_RES,
+<a name="l00296"></a>00296             plist,
+<a name="l00297"></a>00297             NULL,
+<a name="l00298"></a>00298             PACKAGE <span class="stringliteral">"/"</span> PACKAGE_VERSION,
+<a name="l00299"></a>00299             <span class="stringliteral">"sinfo_utl_seds.fits"</span>) ;
+<a name="l00300"></a>00300 
+<a name="l00301"></a>00301     cpl_propertylist_delete(plist) ;
+<a name="l00302"></a>00302 
+<a name="l00303"></a>00303     <span class="keywordflow">return</span> 0 ;
+<a name="l00304"></a>00304 }
+<a name="l00305"></a>00305 
+<a name="l00306"></a>00306 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__utl__skycor_8c_source.html b/html/sinfo__utl__skycor_8c_source.html
new file mode 100644
index 0000000..390426f
--- /dev/null
+++ b/html/sinfo__utl__skycor_8c_source.html
@@ -0,0 +1,339 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_utl_skycor.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_utl_skycor.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_utl_skycor.c,v 1.13 2007/10/26 09:40:28 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the SINFONI Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2007/10/26 09:40:28 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.13 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span>
+<a name="l00032"></a>00032 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                                Includes</span>
+<a name="l00034"></a>00034 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 <span class="preprocessor">#include <string.h></span>
+<a name="l00036"></a>00036 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include <irplib_utils.h></span>
+<a name="l00038"></a>00038 <span class="preprocessor">#include <sinfo_skycor.h></span>
+<a name="l00039"></a>00039 <span class="preprocessor">#include <sinfo_skycor_config.h></span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include <sinfo_tpl_utils.h></span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include <sinfo_tpl_dfs.h></span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include <sinfo_pro_types.h></span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include <sinfo_utils_wrappers.h></span>
+<a name="l00044"></a>00044 <span class="preprocessor">#include <sinfo_error.h></span>
+<a name="l00045"></a>00045 <span class="preprocessor">#include <sinfo_msg.h></span>
+<a name="l00046"></a>00046 <span class="preprocessor">#include <sinfo_pro_save.h></span>
+<a name="l00047"></a>00047 <span class="preprocessor">#include <sinfo_globals.h></span>
+<a name="l00048"></a>00048 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00049"></a>00049 <span class="comment">                                Defines</span>
+<a name="l00050"></a>00050 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00051"></a>00051 
+<a name="l00052"></a>00052 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00053"></a>00053 <span class="comment">                            Functions prototypes</span>
+<a name="l00054"></a>00054 <span class="comment">-----------------------------------------------------------------------------*/</span>
+<a name="l00055"></a>00055 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_skycor_create(cpl_plugin *) ;
+<a name="l00056"></a>00056 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_skycor_exec(cpl_plugin *) ;
+<a name="l00057"></a>00057 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_skycor_destroy(cpl_plugin *) ;
+<a name="l00058"></a>00058 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_skycor(cpl_parameterlist * config, cpl_frameset* <span class="keyword">set</span>);
+<a name="l00059"></a>00059 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00060"></a>00060 <span class="comment">                            Static variables</span>
+<a name="l00061"></a>00061 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00062"></a>00062 
+<a name="l00063"></a>00063 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_utl_skycor_description[] =
+<a name="l00064"></a>00064 <span class="stringliteral">"This recipe perform a correction of possible sky line residuals in the \n"</span>
+<a name="l00065"></a>00065 <span class="stringliteral">"object cube after standard data reduction.\n"</span>
+<a name="l00066"></a>00066 <span class="stringliteral">"Input frames are cubes with target and sky observations.\n"</span>
+<a name="l00067"></a>00067 <span class="stringliteral">"Their tags can be respectively OBS_OBJ (or OBS_PSF or OBS_STD) and OBS_SKY.\n"</span>
+<a name="l00068"></a>00068 <span class="stringliteral">"The output is a cube with same tag as the corresponding input target frame.\n"</span>
+<a name="l00069"></a>00069 <span class="stringliteral">"\n"</span>;
+<a name="l00070"></a>00070 
+<a name="l00071"></a>00071 
+<a name="l00072"></a>00072 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00073"></a>00073 <span class="comment">                                Functions code</span>
+<a name="l00074"></a>00074 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00075"></a>00075 
+<a name="l00076"></a>00076 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00080"></a>00080 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00082"></a>00082 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00090"></a>00090 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00091"></a><a class="code" href="group__sinfo__utl__skycor.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693">00091</a> <span class="keywordtype">int</span> <a class="code" href="group__sinfo__rec__detlin.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693" title="Build the list of available plugins, for this module.">cpl_plugin_get_info</a>(cpl_pluginlist * list)
+<a name="l00092"></a>00092 {
+<a name="l00093"></a>00093     cpl_recipe  *   recipe = cpl_calloc(1, <span class="keyword">sizeof</span> *recipe ) ;
+<a name="l00094"></a>00094     cpl_plugin  *   plugin = &recipe->interface ;
+<a name="l00095"></a>00095 
+<a name="l00096"></a>00096     cpl_plugin_init(plugin,
+<a name="l00097"></a>00097                     CPL_PLUGIN_API,
+<a name="l00098"></a>00098                     SINFONI_BINARY_VERSION,
+<a name="l00099"></a>00099                     CPL_PLUGIN_TYPE_RECIPE,
+<a name="l00100"></a>00100                     <span class="stringliteral">"sinfo_utl_skycor"</span>,
+<a name="l00101"></a>00101                     <span class="stringliteral">"Sky lines residuals correction"</span>,
+<a name="l00102"></a>00102                     sinfo_utl_skycor_description,
+<a name="l00103"></a>00103                     <span class="stringliteral">"Andrea Modigliani"</span>,
+<a name="l00104"></a>00104                     <span class="stringliteral">"Andrea.Modigliani at eso.org"</span>,
+<a name="l00105"></a>00105                     sinfo_get_license(),
+<a name="l00106"></a>00106                     sinfo_utl_skycor_create,
+<a name="l00107"></a>00107                     sinfo_utl_skycor_exec,
+<a name="l00108"></a>00108                     sinfo_utl_skycor_destroy) ;
+<a name="l00109"></a>00109 
+<a name="l00110"></a>00110     cpl_pluginlist_append(list, plugin) ;
+<a name="l00111"></a>00111     <span class="keywordflow">return</span> 0;
+<a name="l00112"></a>00112 }
+<a name="l00113"></a>00113 
+<a name="l00114"></a>00114 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00123"></a>00123 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00124"></a>00124 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_skycor_create(cpl_plugin * plugin)
+<a name="l00125"></a>00125 {
+<a name="l00126"></a>00126     cpl_recipe      * recipe ;
+<a name="l00127"></a>00127 
+<a name="l00128"></a>00128     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00129"></a>00129     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00130"></a>00130         recipe = (cpl_recipe *)plugin ;
+<a name="l00131"></a>00131     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00132"></a>00132 
+<a name="l00133"></a>00133     <span class="comment">/* reset error handling */</span>
+<a name="l00134"></a>00134     <a class="code" href="group__irplib__utils.html#gaf9d392144014e2363054bc3f83c8e47e" title="Reset IRPLIB state.">irplib_reset</a>();
+<a name="l00135"></a>00135     <span class="comment">/* Create the parameters list in the cpl_recipe object */</span>
+<a name="l00136"></a>00136     recipe->parameters = cpl_parameterlist_new() ; 
+<a name="l00137"></a>00137     sinfo_skycor_config_add(recipe->parameters);
+<a name="l00138"></a>00138   
+<a name="l00139"></a>00139     <span class="comment">/* Return */</span>
+<a name="l00140"></a>00140     <span class="keywordflow">return</span> 0;
+<a name="l00141"></a>00141 }
+<a name="l00142"></a>00142 
+<a name="l00143"></a>00143 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00149"></a>00149 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00150"></a>00150 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_skycor_exec(cpl_plugin * plugin)
+<a name="l00151"></a>00151 {
+<a name="l00152"></a>00152     cpl_recipe  *   recipe ;
+<a name="l00153"></a>00153     <span class="keywordtype">int</span> code=0;
+<a name="l00154"></a>00154     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00155"></a>00155     cpl_errorstate initial_errorstate = cpl_errorstate_get();
+<a name="l00156"></a>00156 
+<a name="l00157"></a>00157     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00158"></a>00158         recipe = (cpl_recipe *)plugin ;
+<a name="l00159"></a>00159     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00160"></a>00160 
+<a name="l00161"></a>00161 
+<a name="l00162"></a>00162     code = sinfo_utl_skycor(recipe->parameters, recipe->frames) ;
+<a name="l00163"></a>00163 
+<a name="l00164"></a>00164     <span class="keywordflow">if</span> (!cpl_errorstate_is_equal(initial_errorstate)) {                      
+<a name="l00165"></a>00165         <span class="comment">/* Dump the error history since recipe execution start.                </span>
+<a name="l00166"></a>00166 <span class="comment">           At this point the recipe cannot recover from the error */</span>           
+<a name="l00167"></a>00167         cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);              
+<a name="l00168"></a>00168     } 
+<a name="l00169"></a>00169     <span class="keywordflow">return</span> code;
+<a name="l00170"></a>00170 }
+<a name="l00171"></a>00171 
+<a name="l00172"></a>00172 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00178"></a>00178 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00179"></a>00179 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_skycor_destroy(cpl_plugin * plugin)
+<a name="l00180"></a>00180 {
+<a name="l00181"></a>00181     cpl_recipe  *   recipe ;
+<a name="l00182"></a>00182     
+<a name="l00183"></a>00183     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00184"></a>00184     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00185"></a>00185         recipe = (cpl_recipe *)plugin ;
+<a name="l00186"></a>00186     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00187"></a>00187 
+<a name="l00188"></a>00188     cpl_parameterlist_delete(recipe->parameters) ; 
+<a name="l00189"></a>00189     <span class="keywordflow">return</span> 0 ;
+<a name="l00190"></a>00190 }
+<a name="l00191"></a>00191 
+<a name="l00192"></a>00192 
+<a name="l00199"></a>00199 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00200"></a>00200 <span class="keyword">static</span> <span class="keywordtype">int</span> 
+<a name="l00201"></a>00201 sinfo_utl_skycor(cpl_parameterlist * config, cpl_frameset* <span class="keyword">set</span>)
+<a name="l00202"></a>00202 {
+<a name="l00203"></a>00203  
+<a name="l00204"></a>00204   cpl_frame* obj_frm=NULL;
+<a name="l00205"></a>00205   cpl_frame* sky_frm=NULL;
+<a name="l00206"></a>00206   cpl_imagelist* obj_cor=NULL;
+<a name="l00207"></a>00207   <span class="keyword">const</span> <span class="keywordtype">char</span> *   name_o=NULL ;
+<a name="l00208"></a>00208   cpl_frame* product_frame=NULL;
+<a name="l00209"></a>00209 
+<a name="l00210"></a>00210   cpl_propertylist* plist=NULL;
+<a name="l00211"></a>00211   sinfo_skycor_qc* sqc=NULL;
+<a name="l00212"></a>00212   <span class="keywordtype">char</span> obj_tag[MAX_NAME_SIZE];
+<a name="l00213"></a>00213   cpl_table* int_obj=NULL;
+<a name="l00214"></a>00214 
+<a name="l00215"></a>00215       sinfo_msg(<span class="stringliteral">"Welcome to SINFONI Pipeline release %d.%d.%d"</span>,
+<a name="l00216"></a>00216         SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
+<a name="l00217"></a>00217 
+<a name="l00218"></a>00218 
+<a name="l00219"></a>00219   ck0(sinfo_dfs_set_groups(<span class="keyword">set</span>),<span class="stringliteral">"Cannot indentify RAW and CALIB frames"</span>) ;
+<a name="l00220"></a>00220 
+<a name="l00221"></a>00221 
+<a name="l00222"></a>00222   <span class="comment">// get input data </span>
+<a name="l00223"></a>00223     obj_frm=cpl_frameset_find(<span class="keyword">set</span>,PRO_OBS_OBJ);
+<a name="l00224"></a>00224   <span class="keywordflow">if</span>(obj_frm == NULL) {
+<a name="l00225"></a>00225     obj_frm=cpl_frameset_find(<span class="keyword">set</span>,PRO_OBS_PSF);
+<a name="l00226"></a>00226     strcpy(obj_tag,PRO_OBS_PSF);
+<a name="l00227"></a>00227   } <span class="keywordflow">else</span> {
+<a name="l00228"></a>00228     strcpy(obj_tag,PRO_OBS_OBJ);
+<a name="l00229"></a>00229   }
+<a name="l00230"></a>00230 
+<a name="l00231"></a>00231 
+<a name="l00232"></a>00232   <span class="keywordflow">if</span>(obj_frm == NULL) {
+<a name="l00233"></a>00233     obj_frm=cpl_frameset_find(<span class="keyword">set</span>,PRO_OBS_STD);
+<a name="l00234"></a>00234     strcpy(obj_tag,PRO_OBS_STD);
+<a name="l00235"></a>00235   }
+<a name="l00236"></a>00236   cknull(obj_frm,<span class="stringliteral">"No %s or %s or %s frame found"</span>,
+<a name="l00237"></a>00237      PRO_OBS_OBJ,PRO_OBS_PSF,PRO_OBS_STD);
+<a name="l00238"></a>00238   check(sky_frm=cpl_frameset_find(<span class="keyword">set</span>,PRO_OBS_SKY),
+<a name="l00239"></a>00239         <span class="stringliteral">"No %s found"</span>,PRO_OBS_SKY);
+<a name="l00240"></a>00240   sqc=sinfo_skycor_qc_new();
+<a name="l00241"></a>00241 
+<a name="l00242"></a>00242   check(plist=cpl_propertylist_load(cpl_frame_get_filename(obj_frm),0),
+<a name="l00243"></a>00243           <span class="stringliteral">"Cannot read the FITS header"</span>) ;
+<a name="l00244"></a>00244  
+<a name="l00245"></a>00245   ck0(sinfo_skycor(config, obj_frm,sky_frm,sqc,&obj_cor,&int_obj),
+<a name="l00246"></a>00246      <span class="stringliteral">"determining sky residuals corrected object"</span>);
+<a name="l00247"></a>00247   sinfo_msg(<span class="stringliteral">"Write out adjusted cube"</span>);
+<a name="l00248"></a>00248   <span class="comment">/* Set the file name */</span>
+<a name="l00249"></a>00249 
+<a name="l00250"></a>00250   cpl_frameset_erase(<span class="keyword">set</span>,obj_tag);
+<a name="l00251"></a>00251   cpl_frameset_erase(<span class="keyword">set</span>,PRO_OBS_SKY);
+<a name="l00252"></a>00252   name_o = <span class="stringliteral">"out_obj_cor.fits"</span> ;
+<a name="l00253"></a>00253 
+<a name="l00254"></a>00254 
+<a name="l00255"></a>00255   <span class="comment">/* Create product frame */</span>
+<a name="l00256"></a>00256   check_nomsg(product_frame = cpl_frame_new());
+<a name="l00257"></a>00257   check_nomsg(cpl_frame_set_filename(product_frame, name_o)) ;
+<a name="l00258"></a>00258   check_nomsg(cpl_frame_set_tag(product_frame, obj_tag)) ;
+<a name="l00259"></a>00259   check_nomsg(cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_IMAGE)) ;
+<a name="l00260"></a>00260   check_nomsg(cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT)) ;
+<a name="l00261"></a>00261   check(cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL),
+<a name="l00262"></a>00262         <span class="stringliteral">"Error while initialising the product frame"</span>) ;
+<a name="l00263"></a>00263   <span class="comment">// Add DataFlow keywords </span>
+<a name="l00264"></a>00264 
+<a name="l00265"></a>00265     <span class="comment">/*</span>
+<a name="l00266"></a>00266 <span class="comment">    check(plist=cpl_propertylist_load(name_o,0),</span>
+<a name="l00267"></a>00267 <span class="comment">          "Cannot read the FITS header") ;</span>
+<a name="l00268"></a>00268 <span class="comment">    check_nomsg(cpl_propertylist_erase_regexp(plist, "^ESO PRO CATG",0));</span>
+<a name="l00269"></a>00269 <span class="comment">    check(cpl_dfs_setup_product_header(plist, </span>
+<a name="l00270"></a>00270 <span class="comment">                                       product_frame, </span>
+<a name="l00271"></a>00271 <span class="comment">                                       set, </span>
+<a name="l00272"></a>00272 <span class="comment">                                       parlist,</span>
+<a name="l00273"></a>00273 <span class="comment">                                       "sinfo_utl_skycor", </span>
+<a name="l00274"></a>00274 <span class="comment">                                       "SINFONI", </span>
+<a name="l00275"></a>00275 <span class="comment">                                       KEY_VALUE_HPRO_DID),</span>
+<a name="l00276"></a>00276 <span class="comment">        "Problem in the product DFS-compliance") ;</span>
+<a name="l00277"></a>00277 <span class="comment">    */</span>
+<a name="l00278"></a>00278 
+<a name="l00279"></a>00279   <span class="comment">//save the file </span>
+<a name="l00280"></a>00280 
+<a name="l00281"></a>00281   check(cpl_imagelist_save(obj_cor, 
+<a name="l00282"></a>00282                name_o,
+<a name="l00283"></a>00283                CPL_BPP_IEEE_FLOAT, 
+<a name="l00284"></a>00284                plist,
+<a name="l00285"></a>00285                CPL_IO_DEFAULT),
+<a name="l00286"></a>00286     <span class="stringliteral">"Could not save product"</span>);
+<a name="l00287"></a>00287   <span class="comment">// Log the saved file in the input frameset </span>
+<a name="l00288"></a>00288   check_nomsg(cpl_frameset_insert(<span class="keyword">set</span>,cpl_frame_duplicate(product_frame))) ;
+<a name="l00289"></a>00289   sinfo_free_frame(&product_frame);
+<a name="l00290"></a>00290   <span class="comment">/*</span>
+<a name="l00291"></a>00291 <span class="comment">  ck0(sinfo_pro_save_ims(obj_cor,set,set,"out_obj_cor.fits",</span>
+<a name="l00292"></a>00292 <span class="comment">             PRO_OBS_OBJ,NULL,cpl_func,config),</span>
+<a name="l00293"></a>00293 <span class="comment">      "cannot dump cube %s", "obj_cub.fits");</span>
+<a name="l00294"></a>00294 <span class="comment">  */</span>
+<a name="l00295"></a>00295     
+<a name="l00296"></a>00296 
+<a name="l00297"></a>00297 
+<a name="l00298"></a>00298 
+<a name="l00299"></a>00299   sinfo_free_imagelist(&obj_cor);
+<a name="l00300"></a>00300 
+<a name="l00301"></a>00301 
+<a name="l00302"></a>00302 
+<a name="l00303"></a>00303   name_o = <span class="stringliteral">"out_obj_int.fits"</span> ;
+<a name="l00304"></a>00304 
+<a name="l00305"></a>00305   <span class="comment">/* Create product frame */</span>
+<a name="l00306"></a>00306   check_nomsg(product_frame = cpl_frame_new());
+<a name="l00307"></a>00307   check_nomsg(cpl_frame_set_filename(product_frame, name_o)) ;
+<a name="l00308"></a>00308   check_nomsg(cpl_frame_set_tag(product_frame, PRO_SPECTRA_QC)) ;
+<a name="l00309"></a>00309   check_nomsg(cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_TABLE)) ;
+<a name="l00310"></a>00310   check_nomsg(cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT)) ;
+<a name="l00311"></a>00311   check(cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL),
+<a name="l00312"></a>00312       <span class="stringliteral">"Error while initialising the product frame"</span>) ;
+<a name="l00313"></a>00313   check_nomsg(cpl_propertylist_update_string(plist, <span class="stringliteral">"ESO PRO CATG"</span>,
+<a name="l00314"></a>00314               PRO_SPECTRA_QC));
+<a name="l00315"></a>00315 
+<a name="l00316"></a>00316 
+<a name="l00317"></a>00317     <span class="comment">/* Add DataFlow keywords */</span>
+<a name="l00318"></a>00318     <span class="comment">/*    </span>
+<a name="l00319"></a>00319 <span class="comment">    check(plist=cpl_propertylist_load(name_o,0),</span>
+<a name="l00320"></a>00320 <span class="comment">          "Cannot read the FITS header") ;</span>
+<a name="l00321"></a>00321 <span class="comment"></span>
+<a name="l00322"></a>00322 <span class="comment">    check_nomsg(cpl_propertylist_erase_regexp(plist, "^ESO PRO CATG",0));</span>
+<a name="l00323"></a>00323 <span class="comment">    check(cpl_dfs_setup_product_header(plist, </span>
+<a name="l00324"></a>00324 <span class="comment">                                       product_frame, </span>
+<a name="l00325"></a>00325 <span class="comment">                                       set, </span>
+<a name="l00326"></a>00326 <span class="comment">                                       parlist,</span>
+<a name="l00327"></a>00327 <span class="comment">                                       "sinfo_utl_skycor", </span>
+<a name="l00328"></a>00328 <span class="comment">                                       "SINFONI", </span>
+<a name="l00329"></a>00329 <span class="comment">                                       KEY_VALUE_HPRO_DID),</span>
+<a name="l00330"></a>00330 <span class="comment">      "Problem in the product DFS-compliance") ;</span>
+<a name="l00331"></a>00331 <span class="comment">    */</span>
+<a name="l00332"></a>00332 
+<a name="l00333"></a>00333     <span class="comment">/* Save the file */</span>
+<a name="l00334"></a>00334     check(cpl_table_save(int_obj, plist, NULL, name_o, 0),
+<a name="l00335"></a>00335       <span class="stringliteral">"Could not save product"</span>);
+<a name="l00336"></a>00336     sinfo_free_propertylist(&plist) ;
+<a name="l00337"></a>00337  
+<a name="l00338"></a>00338     <span class="comment">/* Log the saved file in the input frameset */</span>
+<a name="l00339"></a>00339     check_nomsg(cpl_frameset_insert(<span class="keyword">set</span>, cpl_frame_duplicate(product_frame))) ;
+<a name="l00340"></a>00340   sinfo_free_frame(&product_frame);
+<a name="l00341"></a>00341 
+<a name="l00342"></a>00342 
+<a name="l00343"></a>00343 
+<a name="l00344"></a>00344 
+<a name="l00345"></a>00345  cleanup:
+<a name="l00346"></a>00346   sinfo_free_imagelist(&obj_cor);
+<a name="l00347"></a>00347   sinfo_free_table(&int_obj);
+<a name="l00348"></a>00348   sinfo_skycor_qc_delete(&sqc);
+<a name="l00349"></a>00349   sinfo_free_propertylist(&plist);
+<a name="l00350"></a>00350   sinfo_free_frame(&product_frame);
+<a name="l00351"></a>00351   <span class="keywordflow">if</span> (cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l00352"></a>00352     <span class="keywordflow">return</span> -1;
+<a name="l00353"></a>00353   } <span class="keywordflow">else</span> {
+<a name="l00354"></a>00354     <span class="keywordflow">return</span> 0;
+<a name="l00355"></a>00355   }
+<a name="l00356"></a>00356 
+<a name="l00357"></a>00357 
+<a name="l00358"></a>00358 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__utl__skymap_8c_source.html b/html/sinfo__utl__skymap_8c_source.html
new file mode 100644
index 0000000..801afa4
--- /dev/null
+++ b/html/sinfo__utl__skymap_8c_source.html
@@ -0,0 +1,421 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_utl_skymap.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_utl_skymap.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_utl_skymap.c,v 1.13 2009/01/30 14:56:12 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the SINFONI Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2009/01/30 14:56:12 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.13 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span>
+<a name="l00032"></a>00032 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                                Includes</span>
+<a name="l00034"></a>00034 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 
+<a name="l00036"></a>00036 <span class="comment">/* cpl */</span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00038"></a>00038 <span class="comment">/* irplib */</span>
+<a name="l00039"></a>00039 <span class="preprocessor">#include <irplib_utils.h></span>
+<a name="l00040"></a>00040 
+<a name="l00041"></a>00041 <span class="comment">/* sinfoni */</span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include <sinfo_tpl_utils.h></span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include <sinfo_pfits.h></span>
+<a name="l00044"></a>00044 <span class="preprocessor">#include <sinfo_tpl_dfs.h></span>
+<a name="l00045"></a>00045 <span class="preprocessor">#include <sinfo_raw_types.h></span>
+<a name="l00046"></a>00046 <span class="preprocessor">#include <sinfo_pro_types.h></span>
+<a name="l00047"></a>00047 <span class="preprocessor">#include <sinfo_functions.h></span>
+<a name="l00048"></a>00048 <span class="preprocessor">#include <sinfo_key_names.h></span>
+<a name="l00049"></a>00049 <span class="preprocessor">#include <sinfo_msg.h></span>
+<a name="l00050"></a>00050 <span class="preprocessor">#include <sinfo_error.h></span>
+<a name="l00051"></a>00051 <span class="preprocessor">#include <sinfo_utils_wrappers.h></span>
+<a name="l00052"></a>00052 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00053"></a>00053 <span class="comment">                            Functions prototypes</span>
+<a name="l00054"></a>00054 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00055"></a>00055 
+<a name="l00056"></a>00056 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_skymap_create(cpl_plugin *) ;
+<a name="l00057"></a>00057 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_skymap_exec(cpl_plugin *) ;
+<a name="l00058"></a>00058 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_skymap_destroy(cpl_plugin *) ;
+<a name="l00059"></a>00059 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_skymap(cpl_parameterlist *, cpl_frameset *) ;
+<a name="l00060"></a>00060 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00061"></a>00061 <span class="comment">                            Static variables</span>
+<a name="l00062"></a>00062 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00063"></a>00063 
+<a name="l00064"></a>00064 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_utl_skymap_description[] =
+<a name="l00065"></a>00065 <span class="stringliteral">"This recipe flags as bad pixels sky lines.\n"</span>
+<a name="l00066"></a>00066 <span class="stringliteral">"Input are sky frames with tag SKY\n"</span>
+<a name="l00067"></a>00067 <span class="stringliteral">"Output image is called out_skymap.fits\n"</span>
+<a name="l00068"></a>00068 <span class="stringliteral">"Information on relevant parameters can be found with\n"</span>
+<a name="l00069"></a>00069 <span class="stringliteral">"esorex --params sinfo_utl_skymap\n"</span>
+<a name="l00070"></a>00070 <span class="stringliteral">"esorex --help sinfo_utl_skymap\n"</span>
+<a name="l00071"></a>00071 <span class="stringliteral">"\n"</span>;
+<a name="l00072"></a>00072 
+<a name="l00073"></a>00073 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00074"></a>00074 <span class="comment">                                Functions code</span>
+<a name="l00075"></a>00075 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00076"></a>00076 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00080"></a>00080 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00081"></a>00081 
+<a name="l00083"></a>00083 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00091"></a>00091 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00092"></a><a class="code" href="group__sinfo__utl__skymap.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693">00092</a> <span class="keywordtype">int</span> <a class="code" href="group__sinfo__rec__detlin.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693" title="Build the list of available plugins, for this module.">cpl_plugin_get_info</a>(cpl_pluginlist * list)
+<a name="l00093"></a>00093 {
+<a name="l00094"></a>00094     cpl_recipe  *   recipe = cpl_calloc(1, <span class="keyword">sizeof</span> *recipe ) ;
+<a name="l00095"></a>00095     cpl_plugin  *   plugin = &recipe->interface ;
+<a name="l00096"></a>00096 
+<a name="l00097"></a>00097     cpl_plugin_init(plugin,
+<a name="l00098"></a>00098                     CPL_PLUGIN_API,
+<a name="l00099"></a>00099                     SINFONI_BINARY_VERSION,
+<a name="l00100"></a>00100                     CPL_PLUGIN_TYPE_RECIPE,
+<a name="l00101"></a>00101                     <span class="stringliteral">"sinfo_utl_skymap"</span>,
+<a name="l00102"></a>00102                     <span class="stringliteral">"Flags sky lines as bad pixels, with map generation"</span>,
+<a name="l00103"></a>00103                     sinfo_utl_skymap_description,
+<a name="l00104"></a>00104                     <span class="stringliteral">"Andrea Modigliani"</span>,
+<a name="l00105"></a>00105                     <span class="stringliteral">"Andrea.Modigliani at eso.org"</span>,
+<a name="l00106"></a>00106                     sinfo_get_license(),
+<a name="l00107"></a>00107                     sinfo_utl_skymap_create,
+<a name="l00108"></a>00108                     sinfo_utl_skymap_exec,
+<a name="l00109"></a>00109                     sinfo_utl_skymap_destroy) ;
+<a name="l00110"></a>00110 
+<a name="l00111"></a>00111     cpl_pluginlist_append(list, plugin) ;
+<a name="l00112"></a>00112     
+<a name="l00113"></a>00113     <span class="keywordflow">return</span> 0;
+<a name="l00114"></a>00114 }
+<a name="l00115"></a>00115 
+<a name="l00116"></a>00116 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00125"></a>00125 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00126"></a>00126 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_skymap_create(cpl_plugin * plugin)
+<a name="l00127"></a>00127 {
+<a name="l00128"></a>00128     cpl_recipe      * recipe ;
+<a name="l00129"></a>00129     cpl_parameter   * p ;
+<a name="l00130"></a>00130 
+<a name="l00131"></a>00131     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00132"></a>00132     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00133"></a>00133         recipe = (cpl_recipe *)plugin ;
+<a name="l00134"></a>00134     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00135"></a>00135 
+<a name="l00136"></a>00136     <span class="comment">/* Create the parameters list in the cpl_recipe object */</span>
+<a name="l00137"></a>00137     recipe->parameters = cpl_parameterlist_new() ; 
+<a name="l00138"></a>00138 
+<a name="l00139"></a>00139     <span class="comment">/* Fill the parameters list */</span>
+<a name="l00140"></a>00140 
+<a name="l00141"></a>00141 
+<a name="l00142"></a>00142     <span class="comment">/* --doubleopt */</span>
+<a name="l00143"></a>00143     p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.sinfo_utl_skymap.xsize"</span>, 
+<a name="l00144"></a>00144             CPL_TYPE_INT, <span class="stringliteral">"X box size"</span>, <span class="stringliteral">"sinfoni.sinfo_utl_skymap"</span>, 1,1,2047) ;
+<a name="l00145"></a>00145     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"xsize"</span>) ;
+<a name="l00146"></a>00146     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00147"></a>00147 
+<a name="l00148"></a>00148     <span class="comment">/* --doubleopt */</span>
+<a name="l00149"></a>00149     p = cpl_parameter_new_range(<span class="stringliteral">"sinfoni.sinfo_utl_skymap.ysize"</span>, 
+<a name="l00150"></a>00150             CPL_TYPE_INT, <span class="stringliteral">"Y box size"</span>, <span class="stringliteral">"sinfoni.sinfo_utl_skymap"</span>, 30,1,2047) ;
+<a name="l00151"></a>00151     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"ysize"</span>) ;
+<a name="l00152"></a>00152     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00153"></a>00153 
+<a name="l00154"></a>00154 
+<a name="l00155"></a>00155 
+<a name="l00156"></a>00156     <span class="comment">/* --doubleopt */</span>
+<a name="l00157"></a>00157     p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.sinfo_utl_skymap.threshold"</span>, 
+<a name="l00158"></a>00158             CPL_TYPE_DOUBLE, <span class="stringliteral">"Threshold"</span>, <span class="stringliteral">"sinfoni.sinfo_utl_skymap"</span>, 30.) ;
+<a name="l00159"></a>00159     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"thresh"</span>) ;
+<a name="l00160"></a>00160     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00161"></a>00161 
+<a name="l00162"></a>00162     <span class="comment">/* Return */</span>
+<a name="l00163"></a>00163     <span class="keywordflow">return</span> 0;
+<a name="l00164"></a>00164 }
+<a name="l00165"></a>00165 
+<a name="l00166"></a>00166 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00172"></a>00172 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00173"></a>00173 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_skymap_exec(cpl_plugin * plugin)
+<a name="l00174"></a>00174 {
+<a name="l00175"></a>00175     cpl_recipe  *   recipe ;
+<a name="l00176"></a>00176     <span class="keywordtype">int</span> code=0;
+<a name="l00177"></a>00177     cpl_errorstate initial_errorstate = cpl_errorstate_get();
+<a name="l00178"></a>00178 
+<a name="l00179"></a>00179     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00180"></a>00180     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00181"></a>00181         recipe = (cpl_recipe *)plugin ;
+<a name="l00182"></a>00182     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00183"></a>00183     cpl_error_reset();
+<a name="l00184"></a>00184     <span class="comment">//irplib_reset();</span>
+<a name="l00185"></a>00185     check_nomsg(code = sinfo_utl_skymap(recipe->parameters, recipe->frames)) ;
+<a name="l00186"></a>00186     <span class="keywordflow">if</span> (!cpl_errorstate_is_equal(initial_errorstate)) {                      
+<a name="l00187"></a>00187         <span class="comment">/* Dump the error history since recipe execution start.                </span>
+<a name="l00188"></a>00188 <span class="comment">           At this point the recipe cannot recover from the error */</span>           
+<a name="l00189"></a>00189         cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);              
+<a name="l00190"></a>00190     } 
+<a name="l00191"></a>00191   cleanup:
+<a name="l00192"></a>00192     <span class="keywordflow">return</span> code ;
+<a name="l00193"></a>00193 }
+<a name="l00194"></a>00194 
+<a name="l00195"></a>00195 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00201"></a>00201 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00202"></a>00202 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_skymap_destroy(cpl_plugin * plugin)
+<a name="l00203"></a>00203 {
+<a name="l00204"></a>00204     cpl_recipe  *   recipe ;
+<a name="l00205"></a>00205     
+<a name="l00206"></a>00206     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00207"></a>00207     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00208"></a>00208         recipe = (cpl_recipe *)plugin ;
+<a name="l00209"></a>00209     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00210"></a>00210 
+<a name="l00211"></a>00211     cpl_parameterlist_delete(recipe->parameters) ; 
+<a name="l00212"></a>00212     <span class="keywordflow">return</span> 0 ;
+<a name="l00213"></a>00213 }
+<a name="l00214"></a>00214 
+<a name="l00215"></a>00215 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_skymap(
+<a name="l00216"></a>00216         cpl_parameterlist   *   parlist, 
+<a name="l00217"></a>00217         cpl_frameset        *   framelist)
+<a name="l00218"></a>00218 {
+<a name="l00219"></a>00219     cpl_parameter       *   param =NULL;
+<a name="l00220"></a>00220     <span class="keyword">const</span> <span class="keywordtype">char</span> *            name_i=NULL;
+<a name="l00221"></a>00221     <span class="keywordtype">int</span>                    xsize=0;
+<a name="l00222"></a>00222     <span class="keywordtype">int</span>                    ysize=0;
+<a name="l00223"></a>00223 
+<a name="l00224"></a>00224     cpl_frame           *   sky_frm=NULL;
+<a name="l00225"></a>00225 
+<a name="l00226"></a>00226     <span class="keyword">const</span> <span class="keywordtype">char</span>          *   name_o=NULL ;
+<a name="l00227"></a>00227     cpl_propertylist    *   plist =NULL;
+<a name="l00228"></a>00228     cpl_frame           *   product_frame=NULL;
+<a name="l00229"></a>00229     cpl_frameset        *   sky_set=NULL;
+<a name="l00230"></a>00230     cpl_image           *   sky_ima=NULL;
+<a name="l00231"></a>00231     cpl_image           *   sky_map=NULL;
+<a name="l00232"></a>00232     <span class="keywordtype">double</span> threshold=0;
+<a name="l00233"></a>00233     <span class="keywordtype">int</span> i=0;
+<a name="l00234"></a>00234     <span class="keywordtype">int</span> j=0;
+<a name="l00235"></a>00235     <span class="keywordtype">double</span> sinfo_median=0;
+<a name="l00236"></a>00236     <span class="keywordtype">float</span>* sky_ima_pix=NULL;
+<a name="l00237"></a>00237     <span class="keywordtype">float</span>* sky_map_pix=NULL;
+<a name="l00238"></a>00238     <span class="keywordtype">int</span> nx=0;
+<a name="l00239"></a>00239     <span class="keywordtype">int</span> ny=0;
+<a name="l00240"></a>00240     <span class="keywordtype">int</span> n=0;
+<a name="l00241"></a>00241   
+<a name="l00242"></a>00242     <span class="comment">/* HOW TO RETRIEVE INPUT PARAMETERS */</span>
+<a name="l00243"></a>00243     <span class="comment">/* --stropt */</span>
+<a name="l00244"></a>00244 
+<a name="l00245"></a>00245       sinfo_msg(<span class="stringliteral">"Welcome to SINFONI Pipeline release %d.%d.%d"</span>,
+<a name="l00246"></a>00246         SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
+<a name="l00247"></a>00247 
+<a name="l00248"></a>00248     param = cpl_parameterlist_find(parlist, 
+<a name="l00249"></a>00249                                    <span class="stringliteral">"sinfoni.sinfo_utl_skymap.out_filename"</span>);
+<a name="l00250"></a>00250     name_o = <span class="stringliteral">"out_skymap.fits"</span>;
+<a name="l00251"></a>00251 
+<a name="l00252"></a>00252     <span class="comment">/* --intopt */</span>
+<a name="l00253"></a>00253     param = cpl_parameterlist_find(parlist,<span class="stringliteral">"sinfoni.sinfo_utl_skymap.xsize"</span>);
+<a name="l00254"></a>00254     xsize = cpl_parameter_get_int(param) ;
+<a name="l00255"></a>00255 
+<a name="l00256"></a>00256     <span class="comment">/* --intopt */</span>
+<a name="l00257"></a>00257     param = cpl_parameterlist_find(parlist,<span class="stringliteral">"sinfoni.sinfo_utl_skymap.ysize"</span>);
+<a name="l00258"></a>00258     ysize = cpl_parameter_get_int(param) ;
+<a name="l00259"></a>00259   
+<a name="l00260"></a>00260     param = cpl_parameterlist_find(parlist,
+<a name="l00261"></a>00261                    <span class="stringliteral">"sinfoni.sinfo_utl_skymap.threshold"</span>);
+<a name="l00262"></a>00262     threshold = cpl_parameter_get_double(param) ;
+<a name="l00263"></a>00263  
+<a name="l00264"></a>00264     <span class="comment">/* Identify the RAW and CALIB frames in the input frameset */</span>
+<a name="l00265"></a>00265     <span class="keywordflow">if</span> (sinfo_dfs_set_groups(framelist)) {
+<a name="l00266"></a>00266         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Cannot identify RAW and CALIB frames"</span>) ;
+<a name="l00267"></a>00267         <span class="keywordflow">return</span> -1 ;
+<a name="l00268"></a>00268     }
+<a name="l00269"></a>00269     
+<a name="l00270"></a>00270     <span class="comment">/* HOW TO ACCESS INPUT DATA */</span>
+<a name="l00271"></a>00271     n=cpl_frameset_get_size(framelist);
+<a name="l00272"></a>00272     <span class="keywordflow">if</span>(n<1) {
+<a name="l00273"></a>00273       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Empty input frame list!"</span>);
+<a name="l00274"></a>00274       <span class="keywordflow">return</span> -1;
+<a name="l00275"></a>00275     }
+<a name="l00276"></a>00276     sky_set=cpl_frameset_new();
+<a name="l00277"></a>00277     sinfo_extract_frames_type(framelist,sky_set,RAW_SKY);
+<a name="l00278"></a>00278 
+<a name="l00279"></a>00279     n=cpl_frameset_get_size(framelist);
+<a name="l00280"></a>00280     <span class="keywordflow">if</span>(n<1) {
+<a name="l00281"></a>00281       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"No sky frames in input list!"</span>);
+<a name="l00282"></a>00282       sinfo_free_frameset(&sky_set);
+<a name="l00283"></a>00283       <span class="keywordflow">return</span> -1;
+<a name="l00284"></a>00284     }
+<a name="l00285"></a>00285 
+<a name="l00286"></a>00286 
+<a name="l00287"></a>00287     check_nomsg(sky_frm = cpl_frameset_get_frame(sky_set,0));
+<a name="l00288"></a>00288 
+<a name="l00289"></a>00289    <span class="keywordflow">if</span> ((plist=cpl_propertylist_load(cpl_frame_get_filename(sky_frm), 
+<a name="l00290"></a>00290                     0)) == NULL) {
+<a name="l00291"></a>00291         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Cannot read the FITS header"</span>) ;
+<a name="l00292"></a>00292         <span class="keywordflow">return</span> -1 ;
+<a name="l00293"></a>00293     }
+<a name="l00294"></a>00294   
+<a name="l00295"></a>00295 
+<a name="l00296"></a>00296     name_i=cpl_frame_get_filename(sky_frm);
+<a name="l00297"></a>00297     sky_ima = cpl_image_load(name_i,CPL_TYPE_FLOAT,0,0);
+<a name="l00298"></a>00298     sky_map=cpl_image_duplicate(sky_ima);
+<a name="l00299"></a>00299     sky_ima_pix=cpl_image_get_data(sky_ima);
+<a name="l00300"></a>00300     sky_map_pix=cpl_image_get_data(sky_map);
+<a name="l00301"></a>00301     nx = cpl_image_get_size_x(sky_ima);
+<a name="l00302"></a>00302     ny = cpl_image_get_size_y(sky_ima);
+<a name="l00303"></a>00303     <span class="keywordflow">if</span> (nx != SIZEX || ny != SIZEY) {
+<a name="l00304"></a>00304        <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"nx=%d ny=%d, expected nx=%d ny=%d"</span>,nx,ny,SIZEX,SIZEY);
+<a name="l00305"></a>00305        <span class="keywordflow">goto</span> cleanup;
+<a name="l00306"></a>00306 
+<a name="l00307"></a>00307     }
+<a name="l00308"></a>00308     <span class="keywordflow">for</span>(i=1;i<nx;i++) {
+<a name="l00309"></a>00309 
+<a name="l00310"></a>00310        <span class="keywordflow">for</span>(j=ysize+1;j<ny-ysize;j++) {
+<a name="l00311"></a>00311 
+<a name="l00312"></a>00312           sinfo_median=cpl_image_get_median_window(sky_ima,i,j-ysize,i,j+xsize);
+<a name="l00313"></a>00313           <span class="keywordflow">if</span>(cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l00314"></a>00314              <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Exit"</span>);
+<a name="l00315"></a>00315              sinfo_free_image(&sky_ima);
+<a name="l00316"></a>00316              sinfo_free_image(&sky_map);
+<a name="l00317"></a>00317              sinfo_free_propertylist(&plist);
+<a name="l00318"></a>00318              sinfo_free_frameset(&sky_set);
+<a name="l00319"></a>00319              <span class="keywordflow">return</span> -1;
+<a name="l00320"></a>00320       }
+<a name="l00321"></a>00321       <span class="keywordflow">if</span>(sky_ima_pix[i+j*nx] > sinfo_median+threshold) {
+<a name="l00322"></a>00322         sky_map_pix[i+j*nx]=0.;
+<a name="l00323"></a>00323       } <span class="keywordflow">else</span> {
+<a name="l00324"></a>00324         sky_map_pix[i+j*nx]=1.;
+<a name="l00325"></a>00325       }
+<a name="l00326"></a>00326        }
+<a name="l00327"></a>00327 
+<a name="l00328"></a>00328     }
+<a name="l00329"></a>00329 
+<a name="l00330"></a>00330 
+<a name="l00331"></a>00331 
+<a name="l00332"></a>00332     <span class="keywordflow">for</span>(i=1;i<nx;i++) {
+<a name="l00333"></a>00333 
+<a name="l00334"></a>00334        <span class="keywordflow">for</span>(j=0;j<ysize+1;j++) {
+<a name="l00335"></a>00335 
+<a name="l00336"></a>00336              sky_map_pix[i+j*nx]=0.;
+<a name="l00337"></a>00337 
+<a name="l00338"></a>00338        }
+<a name="l00339"></a>00339 
+<a name="l00340"></a>00340        <span class="keywordflow">for</span>(j=ny-ysize+1;j<ny;j++) {
+<a name="l00341"></a>00341 
+<a name="l00342"></a>00342              sky_map_pix[i+j*nx]=0.;
+<a name="l00343"></a>00343 
+<a name="l00344"></a>00344        }
+<a name="l00345"></a>00345 
+<a name="l00346"></a>00346     }
+<a name="l00347"></a>00347 
+<a name="l00348"></a>00348 
+<a name="l00349"></a>00349 
+<a name="l00350"></a>00350     <span class="comment">/* Now performing the data reduction */</span>
+<a name="l00351"></a>00351     <span class="comment">/* Let's generate one image for the example */</span>
+<a name="l00352"></a>00352 
+<a name="l00353"></a>00353 
+<a name="l00354"></a>00354     
+<a name="l00355"></a>00355     <span class="comment">/* HOW TO SAVE A PRODUCT ON DISK  */</span>
+<a name="l00356"></a>00356     <span class="comment">/* Set the file name */</span>
+<a name="l00357"></a>00357     name_o = <span class="stringliteral">"sky_map.fits"</span> ;
+<a name="l00358"></a>00358 
+<a name="l00359"></a>00359     <span class="comment">/* Create product frame */</span>
+<a name="l00360"></a>00360     product_frame = cpl_frame_new();
+<a name="l00361"></a>00361     cpl_frame_set_filename(product_frame, name_o) ;
+<a name="l00362"></a>00362     cpl_frame_set_tag(product_frame, PRO_SKY_DUMMY) ;
+<a name="l00363"></a>00363     cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_IMAGE) ;
+<a name="l00364"></a>00364     cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT) ;
+<a name="l00365"></a>00365     cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL) ;
+<a name="l00366"></a>00366 
+<a name="l00367"></a>00367     <span class="keywordflow">if</span> (cpl_error_get_code()) {
+<a name="l00368"></a>00368         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Error while initialising the product frame"</span>) ;
+<a name="l00369"></a>00369         sinfo_free_propertylist(&plist) ;
+<a name="l00370"></a>00370         sinfo_free_frame(&product_frame) ;
+<a name="l00371"></a>00371         <span class="keywordflow">return</span> -1 ;
+<a name="l00372"></a>00372     }
+<a name="l00373"></a>00373 
+<a name="l00374"></a>00374     <span class="comment">/* Add DataFlow keywords */</span>
+<a name="l00375"></a>00375 <span class="preprocessor">#if defined CPL_VERSION_CODE && CPL_VERSION_CODE >= CPL_VERSION(4, 8, 0)     </span>
+<a name="l00376"></a>00376 <span class="preprocessor"></span>    <span class="keywordflow">if</span> (cpl_dfs_setup_product_header(plist, product_frame, framelist, parlist,
+<a name="l00377"></a>00377                      <span class="stringliteral">"sinfo_utl_skymap"</span>, 
+<a name="l00378"></a>00378                      <span class="stringliteral">"SINFONI"</span>, KEY_VALUE_HPRO_DID,NULL) 
+<a name="l00379"></a>00379     != CPL_ERROR_NONE) {
+<a name="l00380"></a>00380         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Problem in the product DFS-compliance"</span>) ;
+<a name="l00381"></a>00381         sinfo_free_propertylist(&plist) ;
+<a name="l00382"></a>00382         sinfo_free_frame(&product_frame) ;
+<a name="l00383"></a>00383         sinfo_free_image(&sky_ima);
+<a name="l00384"></a>00384         sinfo_free_image(&sky_map);
+<a name="l00385"></a>00385         sinfo_free_frameset(&sky_set);
+<a name="l00386"></a>00386         <span class="keywordflow">return</span> -1 ;
+<a name="l00387"></a>00387     }
+<a name="l00388"></a>00388 <span class="preprocessor">#else</span>
+<a name="l00389"></a>00389 <span class="preprocessor"></span>    <span class="keywordflow">if</span> (cpl_dfs_setup_product_header(plist, product_frame, framelist, parlist,
+<a name="l00390"></a>00390                      <span class="stringliteral">"sinfo_utl_skymap"</span>, 
+<a name="l00391"></a>00391                      <span class="stringliteral">"SINFONI"</span>, KEY_VALUE_HPRO_DID) 
+<a name="l00392"></a>00392     != CPL_ERROR_NONE) {
+<a name="l00393"></a>00393         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Problem in the product DFS-compliance"</span>) ;
+<a name="l00394"></a>00394         sinfo_free_propertylist(&plist) ;
+<a name="l00395"></a>00395         sinfo_free_frame(&product_frame) ;
+<a name="l00396"></a>00396         sinfo_free_image(&sky_ima);
+<a name="l00397"></a>00397         sinfo_free_image(&sky_map);
+<a name="l00398"></a>00398         sinfo_free_frameset(&sky_set);
+<a name="l00399"></a>00399         <span class="keywordflow">return</span> -1 ;
+<a name="l00400"></a>00400     }
+<a name="l00401"></a>00401 <span class="preprocessor">#endif    </span>
+<a name="l00402"></a>00402 <span class="preprocessor"></span>
+<a name="l00403"></a>00403 
+<a name="l00404"></a>00404     <span class="comment">/* Save the file */</span>
+<a name="l00405"></a>00405     <span class="keywordflow">if</span> (cpl_image_save(sky_map, name_o, CPL_BPP_IEEE_FLOAT, plist,
+<a name="l00406"></a>00406                        CPL_IO_DEFAULT) != CPL_ERROR_NONE) {
+<a name="l00407"></a>00407         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Could not save product"</span>);
+<a name="l00408"></a>00408         sinfo_free_propertylist(&plist) ;
+<a name="l00409"></a>00409         sinfo_free_frame(&product_frame) ;
+<a name="l00410"></a>00410         sinfo_free_image(&sky_map) ;
+<a name="l00411"></a>00411         <span class="keywordflow">return</span> -1 ;
+<a name="l00412"></a>00412     }
+<a name="l00413"></a>00413     sinfo_free_propertylist(&plist) ;
+<a name="l00414"></a>00414     sinfo_free_image(&sky_map) ;
+<a name="l00415"></a>00415     sinfo_free_image(&sky_ima) ;
+<a name="l00416"></a>00416 
+<a name="l00417"></a>00417     <span class="comment">/* Log the saved file in the input frameset */</span>
+<a name="l00418"></a>00418     cpl_frameset_insert(framelist, product_frame) ;
+<a name="l00419"></a>00419     sinfo_free_frameset(&sky_set);
+<a name="l00420"></a>00420    
+<a name="l00421"></a>00421 
+<a name="l00422"></a>00422 
+<a name="l00423"></a>00423   cleanup:
+<a name="l00424"></a>00424     sinfo_free_image(&sky_ima);
+<a name="l00425"></a>00425     sinfo_free_image(&sky_map);
+<a name="l00426"></a>00426     sinfo_free_propertylist(&plist);
+<a name="l00427"></a>00427     sinfo_free_frameset(&sky_set);
+<a name="l00428"></a>00428 
+<a name="l00429"></a>00429     <span class="keywordflow">if</span>(  cpl_error_get_code()!=CPL_ERROR_NONE) {
+<a name="l00430"></a>00430         <span class="keywordflow">return</span> -1 ;
+<a name="l00431"></a>00431     } <span class="keywordflow">else</span> {
+<a name="l00432"></a>00432         <span class="keywordflow">return</span> 0 ;
+<a name="l00433"></a>00433     }
+<a name="l00434"></a>00434 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__utl__spectrum__divide__by__blackbody_8h_source.html b/html/sinfo__utl__spectrum__divide__by__blackbody_8h_source.html
new file mode 100644
index 0000000..4a5617a
--- /dev/null
+++ b/html/sinfo__utl__spectrum__divide__by__blackbody_8h_source.html
@@ -0,0 +1,62 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_utl_spectrum_divide_by_blackbody.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_utl_spectrum_divide_by_blackbody.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_utl_spectrum_divide_by_blackbody.h,v 1.1 2006/10/22 14:12:28 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the IIINSTRUMENT Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2006/10/22 14:12:28 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.1 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00028"></a>00028 <span class="comment">                                Includes</span>
+<a name="l00029"></a>00029 <span class="comment">-----------------------------------------------------------------------------*/</span>
+<a name="l00030"></a>00030 <span class="preprocessor">#ifndef SINFO_UTL_SPECTRUM_DIVIDE_BY_BLACKBODY_H</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_UTL_SPECTRUM_DIVIDE_BY_BLACKBODY_H</span>
+<a name="l00032"></a>00032 <span class="preprocessor"></span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00034"></a>00034 <span class="preprocessor">#include "sinfo_tpl_utils.h"</span>
+<a name="l00035"></a>00035 <span class="preprocessor">#include "sinfo_pfits.h"</span>
+<a name="l00036"></a>00036 <span class="preprocessor">#include "sinfo_tpl_dfs.h"</span>
+<a name="l00037"></a>00037 
+<a name="l00038"></a>00038 
+<a name="l00039"></a>00039 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00040"></a>00040 <span class="comment">                            Functions prototypes</span>
+<a name="l00041"></a>00041 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00042"></a>00042 
+<a name="l00043"></a>00043 <span class="keywordtype">int</span> 
+<a name="l00044"></a>00044 sinfo_utl_spectrum_divide_by_blackbody(cpl_parameterlist *, cpl_frameset *) ;
+<a name="l00045"></a>00045 
+<a name="l00046"></a>00046 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__utl__spectrum__wavelength__shift_8h_source.html b/html/sinfo__utl__spectrum__wavelength__shift_8h_source.html
new file mode 100644
index 0000000..ba09481
--- /dev/null
+++ b/html/sinfo__utl__spectrum__wavelength__shift_8h_source.html
@@ -0,0 +1,61 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_utl_spectrum_wavelength_shift.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_utl_spectrum_wavelength_shift.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_utl_spectrum_wavelength_shift.h,v 1.1 2006/10/22 14:12:28 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the IIINSTRUMENT Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2006/10/22 14:12:28 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.1 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00028"></a>00028 <span class="comment">                                Includes</span>
+<a name="l00029"></a>00029 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00030"></a>00030 
+<a name="l00031"></a>00031 <span class="preprocessor">#ifndef SINFO_UTL_SPECTRUM_WAVELENGTH_SHIFT_H</span>
+<a name="l00032"></a>00032 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_UTL_SPECTRUM_WAVELENGTH_SHIFT_H</span>
+<a name="l00033"></a>00033 <span class="preprocessor"></span>
+<a name="l00034"></a>00034 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00035"></a>00035 <span class="preprocessor">#include "sinfo_tpl_utils.h"</span>
+<a name="l00036"></a>00036 <span class="preprocessor">#include "sinfo_pfits.h"</span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include "sinfo_tpl_dfs.h"</span>
+<a name="l00038"></a>00038 
+<a name="l00039"></a>00039 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00040"></a>00040 <span class="comment">                            Functions prototypes</span>
+<a name="l00041"></a>00041 <span class="comment">-----------------------------------------------------------------------------*/</span>
+<a name="l00042"></a>00042 
+<a name="l00043"></a>00043 <span class="keywordtype">int</span> sinfo_utl_spectrum_wavelength_shift(cpl_parameterlist *, cpl_frameset *) ;
+<a name="l00044"></a>00044 
+<a name="l00045"></a>00045 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__utl__stdstars_8c_source.html b/html/sinfo__utl__stdstars_8c_source.html
new file mode 100644
index 0000000..e023459
--- /dev/null
+++ b/html/sinfo__utl__stdstars_8c_source.html
@@ -0,0 +1,283 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_utl_stdstars.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_utl_stdstars.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_utl_stdstars.c,v 1.5 2012/05/04 08:12:07 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the ISAAC Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2012/05/04 08:12:07 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.5 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span>
+<a name="l00032"></a>00032 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                                Includes</span>
+<a name="l00034"></a>00034 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 
+<a name="l00036"></a>00036 <span class="preprocessor">#include <math.h></span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00038"></a>00038 
+<a name="l00039"></a>00039 <span class="preprocessor">#include "irplib_utils.h"</span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include "irplib_stdstar.h"</span>
+<a name="l00041"></a>00041 
+<a name="l00042"></a>00042 <span class="preprocessor">#include "sinfo_raw_types.h"</span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include "sinfo_pro_types.h"</span>
+<a name="l00044"></a>00044 <span class="preprocessor">#include "sinfo_tpl_utils.h"</span>
+<a name="l00045"></a>00045 <span class="preprocessor">#include "sinfo_tpl_dfs.h"</span>
+<a name="l00046"></a>00046 
+<a name="l00047"></a>00047 <span class="comment">/*</span>
+<a name="l00048"></a>00048 <span class="comment">#include "isaac_utils.h"</span>
+<a name="l00049"></a>00049 <span class="comment">#include "isaac_pfits.h"</span>
+<a name="l00050"></a>00050 <span class="comment">#include "isaac_dfs.h"</span>
+<a name="l00051"></a>00051 <span class="comment">*/</span>
+<a name="l00052"></a>00052 
+<a name="l00053"></a>00053 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00054"></a>00054 <span class="comment">                            Functions prototypes</span>
+<a name="l00055"></a>00055 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00056"></a>00056 
+<a name="l00057"></a>00057 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_stdstars_create(cpl_plugin *) ;
+<a name="l00058"></a>00058 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_stdstars_exec(cpl_plugin *) ;
+<a name="l00059"></a>00059 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_stdstars_destroy(cpl_plugin *) ;
+<a name="l00060"></a>00060 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_stdstars(cpl_frameset *) ;
+<a name="l00061"></a>00061 <span class="keyword">static</span> cpl_table * sinfo_utl_stdstars_convert(<span class="keyword">const</span> <span class="keywordtype">char</span> *) ; 
+<a name="l00062"></a>00062 
+<a name="l00063"></a>00063 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00064"></a>00064 <span class="comment">                            Static variables</span>
+<a name="l00065"></a>00065 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00066"></a>00066 
+<a name="l00067"></a>00067 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_utl_stdstars_description[] = 
+<a name="l00068"></a>00068 <span class="stringliteral">"sinfo_utl_stdstars -- SINFONI standard stars catalog creation.\n"</span>
+<a name="l00069"></a>00069 <span class="stringliteral">"The files listed in the Set Of Frames (sof-file) must be tagged:\n"</span>
+<a name="l00070"></a>00070 <span class="stringliteral">"raw-file.fits "</span>SINFO_UTL_STDSTARS_RAW<span class="stringliteral">"\n"</span> ;
+<a name="l00071"></a>00071 
+<a name="l00072"></a>00072 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00073"></a>00073 <span class="comment">                                Functions code</span>
+<a name="l00074"></a>00074 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00075"></a>00075 
+<a name="l00076"></a>00076 
+<a name="l00077"></a>00077 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00081"></a>00081 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00082"></a>00082 
+<a name="l00083"></a>00083 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00091"></a>00091 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00092"></a>00092 <span class="keywordtype">int</span> <a class="code" href="group__sinfo__rec__detlin.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693" title="Build the list of available plugins, for this module.">cpl_plugin_get_info</a>(cpl_pluginlist * list)
+<a name="l00093"></a>00093 {
+<a name="l00094"></a>00094     cpl_recipe  *   recipe = cpl_calloc(1, <span class="keyword">sizeof</span>(*recipe)) ;
+<a name="l00095"></a>00095     cpl_plugin  *   plugin = &recipe->interface ;
+<a name="l00096"></a>00096 
+<a name="l00097"></a>00097     cpl_plugin_init(plugin,
+<a name="l00098"></a>00098                     CPL_PLUGIN_API,
+<a name="l00099"></a>00099                     SINFONI_BINARY_VERSION,
+<a name="l00100"></a>00100                     CPL_PLUGIN_TYPE_RECIPE,
+<a name="l00101"></a>00101                     <span class="stringliteral">"sinfo_utl_stdstars"</span>,
+<a name="l00102"></a>00102                     <span class="stringliteral">"Standard stars catalog creation"</span>,
+<a name="l00103"></a>00103                     sinfo_utl_stdstars_description,
+<a name="l00104"></a>00104                     <span class="stringliteral">"Andrea Modigliani"</span>,
+<a name="l00105"></a>00105                     <span class="stringliteral">"amodigli at eso.org"</span>,
+<a name="l00106"></a>00106                     sinfo_get_license(),
+<a name="l00107"></a>00107                     sinfo_utl_stdstars_create,
+<a name="l00108"></a>00108                     sinfo_utl_stdstars_exec,
+<a name="l00109"></a>00109                     sinfo_utl_stdstars_destroy) ;
+<a name="l00110"></a>00110 
+<a name="l00111"></a>00111     cpl_pluginlist_append(list, plugin) ;
+<a name="l00112"></a>00112     
+<a name="l00113"></a>00113     <span class="keywordflow">return</span> 0;
+<a name="l00114"></a>00114 }
+<a name="l00115"></a>00115 
+<a name="l00116"></a>00116 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00125"></a>00125 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00126"></a>00126 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_stdstars_create(cpl_plugin * plugin)
+<a name="l00127"></a>00127 {
+<a name="l00128"></a>00128     cpl_recipe      * recipe ;
+<a name="l00129"></a>00129 
+<a name="l00130"></a>00130     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00131"></a>00131     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
+<a name="l00132"></a>00132         recipe = (cpl_recipe *)plugin ;
+<a name="l00133"></a>00133     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00134"></a>00134 
+<a name="l00135"></a>00135     <span class="comment">/* Create the parameters list in the cpl_recipe object */</span>
+<a name="l00136"></a>00136     recipe->parameters = cpl_parameterlist_new() ;
+<a name="l00137"></a>00137 
+<a name="l00138"></a>00138     <span class="comment">/* Return */</span>
+<a name="l00139"></a>00139     <span class="keywordflow">return</span> 0;
+<a name="l00140"></a>00140 }
+<a name="l00141"></a>00141 
+<a name="l00142"></a>00142 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00148"></a>00148 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00149"></a>00149 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_stdstars_exec(cpl_plugin * plugin)
+<a name="l00150"></a>00150 {
+<a name="l00151"></a>00151     cpl_recipe  *   recipe ;
+<a name="l00152"></a>00152 
+<a name="l00153"></a>00153     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00154"></a>00154     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
+<a name="l00155"></a>00155         recipe = (cpl_recipe *)plugin ;
+<a name="l00156"></a>00156     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00157"></a>00157 
+<a name="l00158"></a>00158     <span class="keywordflow">return</span> sinfo_utl_stdstars(recipe->frames) ;
+<a name="l00159"></a>00159 }
+<a name="l00160"></a>00160 
+<a name="l00161"></a>00161 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00167"></a>00167 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00168"></a>00168 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_stdstars_destroy(cpl_plugin * plugin)
+<a name="l00169"></a>00169 {
+<a name="l00170"></a>00170     cpl_recipe  *   recipe ;
+<a name="l00171"></a>00171 
+<a name="l00172"></a>00172     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00173"></a>00173     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
+<a name="l00174"></a>00174         recipe = (cpl_recipe *)plugin ;
+<a name="l00175"></a>00175     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00176"></a>00176 
+<a name="l00177"></a>00177     cpl_parameterlist_delete(recipe->parameters) ;
+<a name="l00178"></a>00178     <span class="keywordflow">return</span> 0 ;
+<a name="l00179"></a>00179 }
+<a name="l00180"></a>00180 
+<a name="l00181"></a>00181 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00187"></a>00187 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00188"></a>00188 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_stdstars(
+<a name="l00189"></a>00189         cpl_frameset        *   framelist)
+<a name="l00190"></a>00190 {
+<a name="l00191"></a>00191     cpl_frameset    *   rawframes ;
+<a name="l00192"></a>00192     
+<a name="l00193"></a>00193     <span class="comment">/* Identify the RAW and CALIB frames in the input frameset */</span>
+<a name="l00194"></a>00194     <span class="keywordflow">if</span> (sinfo_dfs_set_groups(framelist)) {
+<a name="l00195"></a>00195         cpl_msg_error(__func__, <span class="stringliteral">"Cannot identify RAW and CALIB frames"</span>) ;
+<a name="l00196"></a>00196         <span class="keywordflow">return</span> -1 ;
+<a name="l00197"></a>00197     }
+<a name="l00198"></a>00198 
+<a name="l00199"></a>00199     <span class="comment">/* Retrieve raw frames */</span>
+<a name="l00200"></a>00200     <span class="keywordflow">if</span> ((rawframes = sinfo_extract_frameset(framelist,
+<a name="l00201"></a>00201                     SINFO_UTL_STDSTARS_RAW)) == NULL) {
+<a name="l00202"></a>00202         cpl_msg_error(__func__, <span class="stringliteral">"Cannot find raw frames in the input list"</span>) ;
+<a name="l00203"></a>00203         <span class="keywordflow">return</span> -1 ;
+<a name="l00204"></a>00204     }
+<a name="l00205"></a>00205 
+<a name="l00206"></a>00206     <span class="comment">/* Write the catalog */</span>
+<a name="l00207"></a>00207     <span class="keywordflow">if</span> (<a class="code" href="group__irplib__stdstar.html#ga1d798cc23ce72891460133af03ee21ba" title="Write the ASCII catalogs as FITS files.">irplib_stdstar_write_catalogs</a>(framelist,
+<a name="l00208"></a>00208                 rawframes, 
+<a name="l00209"></a>00209                 <span class="stringliteral">"sinfo_utl_stdstars"</span>,
+<a name="l00210"></a>00210                 SINFO_UTL_STDSTARS_RES, NULL,
+<a name="l00211"></a>00211                 PACKAGE <span class="stringliteral">"/"</span> PACKAGE_VERSION,
+<a name="l00212"></a>00212                 <span class="stringliteral">"SINFONI"</span>,
+<a name="l00213"></a>00213                 sinfo_utl_stdstars_convert) == -1) {
+<a name="l00214"></a>00214         cpl_msg_error(__func__, <span class="stringliteral">"Cannot write the catalogs"</span>) ;
+<a name="l00215"></a>00215         cpl_frameset_delete(rawframes) ;
+<a name="l00216"></a>00216         <span class="keywordflow">return</span> -1 ;
+<a name="l00217"></a>00217     }
+<a name="l00218"></a>00218     cpl_frameset_delete(rawframes) ;
+<a name="l00219"></a>00219     <span class="keywordflow">return</span> 0 ;
+<a name="l00220"></a>00220 }
+<a name="l00221"></a>00221 
+<a name="l00222"></a>00222 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00243"></a>00243 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00244"></a>00244 <span class="keyword">static</span> cpl_table * sinfo_utl_stdstars_convert(<span class="keyword">const</span> <span class="keywordtype">char</span> * filename) 
+<a name="l00245"></a>00245 {
+<a name="l00246"></a>00246     cpl_table   *   out ;
+<a name="l00247"></a>00247     <span class="keywordtype">int</span>             nfilters ;
+<a name="l00248"></a>00248     <span class="keyword">const</span> <span class="keywordtype">char</span>  *   filters[8];
+<a name="l00249"></a>00249     <span class="keywordtype">double</span>          mags[8] ;
+<a name="l00250"></a>00250     <span class="keywordtype">int</span>             nbentries ;
+<a name="l00251"></a>00251     FILE        *   in ;
+<a name="l00252"></a>00252     <span class="keywordtype">char</span>            line[1024];
+<a name="l00253"></a>00253     <span class="keywordtype">double</span>          ra, dec ;
+<a name="l00254"></a>00254     <span class="keywordtype">char</span>            sname[512];
+<a name="l00255"></a>00255     <span class="keywordtype">char</span>            stype[512];
+<a name="l00256"></a>00256     <span class="keywordtype">int</span>             i ;
+<a name="l00257"></a>00257     
+<a name="l00258"></a>00258     <span class="comment">/* Check entries */</span>
+<a name="l00259"></a>00259     <span class="keywordflow">if</span> (filename == NULL) <span class="keywordflow">return</span> NULL ;
+<a name="l00260"></a>00260 
+<a name="l00261"></a>00261     <span class="comment">/* Initialise */</span>
+<a name="l00262"></a>00262     nfilters = 8 ;
+<a name="l00263"></a>00263     filters[0] = <span class="stringliteral">"J"</span> ;
+<a name="l00264"></a>00264     filters[1] = <span class="stringliteral">"H"</span> ;
+<a name="l00265"></a>00265     filters[2] = <span class="stringliteral">"K"</span> ;
+<a name="l00266"></a>00266     filters[3] = <span class="stringliteral">"Ks"</span> ;
+<a name="l00267"></a>00267     filters[4] = <span class="stringliteral">"L"</span> ;
+<a name="l00268"></a>00268     filters[5] = <span class="stringliteral">"M"</span> ;
+<a name="l00269"></a>00269     filters[6] = <span class="stringliteral">"Lp"</span> ;
+<a name="l00270"></a>00270     filters[7] = <span class="stringliteral">"Mp"</span> ;
+<a name="l00271"></a>00271    
+<a name="l00272"></a>00272     <span class="comment">/* Get the number of lines */</span>
+<a name="l00273"></a>00273     nbentries = 0 ;
+<a name="l00274"></a>00274     <span class="keywordflow">if</span> ((in = fopen(filename, <span class="stringliteral">"r"</span>)) == NULL) {
+<a name="l00275"></a>00275         <span class="keywordflow">return</span> NULL ;
+<a name="l00276"></a>00276     }
+<a name="l00277"></a>00277     <span class="keywordflow">while</span> (fgets(line, 1024, in) != NULL) {
+<a name="l00278"></a>00278         <span class="keywordflow">if</span> (line[0] != <span class="charliteral">'#'</span>) nbentries ++ ;
+<a name="l00279"></a>00279     }
+<a name="l00280"></a>00280     fclose(in) ;
+<a name="l00281"></a>00281     
+<a name="l00282"></a>00282    <span class="comment">/* Create the table */</span>
+<a name="l00283"></a>00283     out = cpl_table_new(nbentries);
+<a name="l00284"></a>00284     cpl_table_new_column(out, IRPLIB_STDSTAR_STAR_COL, CPL_TYPE_STRING);
+<a name="l00285"></a>00285     cpl_table_new_column(out, IRPLIB_STDSTAR_TYPE_COL, CPL_TYPE_STRING);
+<a name="l00286"></a>00286     cpl_table_new_column(out, IRPLIB_STDSTAR_RA_COL, CPL_TYPE_DOUBLE);
+<a name="l00287"></a>00287     cpl_table_new_column(out, IRPLIB_STDSTAR_DEC_COL, CPL_TYPE_DOUBLE);
+<a name="l00288"></a>00288     <span class="keywordflow">for</span> (i=0 ; i<nfilters ; i++)
+<a name="l00289"></a>00289         cpl_table_new_column(out, filters[i], CPL_TYPE_DOUBLE);
+<a name="l00290"></a>00290 
+<a name="l00291"></a>00291     <span class="comment">/* Parse the file */</span>
+<a name="l00292"></a>00292     <span class="keywordflow">if</span> ((in = fopen(filename, <span class="stringliteral">"r"</span>)) == NULL) {
+<a name="l00293"></a>00293         cpl_table_delete(out) ;
+<a name="l00294"></a>00294         <span class="keywordflow">return</span> NULL ;
+<a name="l00295"></a>00295     }
+<a name="l00296"></a>00296     nbentries = 0 ;
+<a name="l00297"></a>00297     <span class="keywordflow">while</span> (fgets(line, 1024, in) != NULL) {
+<a name="l00298"></a>00298         <span class="keywordflow">if</span> (line[0] != <span class="charliteral">'#'</span>) {
+<a name="l00299"></a>00299             <span class="keywordflow">if</span> (sscanf(line, <span class="stringliteral">"%s %lg %lg %s %lg %lg %lg %lg %lg %lg %lg %lg"</span>, 
+<a name="l00300"></a>00300                         sname, &ra, &dec, stype, &(mags[0]), &(mags[1]), 
+<a name="l00301"></a>00301                         &(mags[2]), &(mags[3]), &(mags[4]), &(mags[5]), 
+<a name="l00302"></a>00302                         &(mags[6]), &(mags[7])) != 12) {
+<a name="l00303"></a>00303                 cpl_table_delete(out) ;
+<a name="l00304"></a>00304                 fclose(in) ;
+<a name="l00305"></a>00305                 <span class="keywordflow">return</span> NULL ;
+<a name="l00306"></a>00306             }
+<a name="l00307"></a>00307             cpl_table_set_string(out, IRPLIB_STDSTAR_STAR_COL,nbentries, sname);
+<a name="l00308"></a>00308             cpl_table_set_string(out, IRPLIB_STDSTAR_TYPE_COL,nbentries, stype);
+<a name="l00309"></a>00309             cpl_table_set_double(out, IRPLIB_STDSTAR_RA_COL, nbentries, ra);
+<a name="l00310"></a>00310             cpl_table_set_double(out, IRPLIB_STDSTAR_DEC_COL, nbentries, dec);
+<a name="l00311"></a>00311             <span class="keywordflow">for</span> (i=0 ; i<nfilters ; i++)
+<a name="l00312"></a>00312                 cpl_table_set_double(out, filters[i], nbentries, mags[i]);
+<a name="l00313"></a>00313             nbentries ++ ;
+<a name="l00314"></a>00314         }
+<a name="l00315"></a>00315     }
+<a name="l00316"></a>00316     fclose(in) ;
+<a name="l00317"></a>00317                 
+<a name="l00318"></a>00318     <span class="keywordflow">return</span> out ;
+<a name="l00319"></a>00319 }
+<a name="l00320"></a>00320 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__utl__table__ex_8c_source.html b/html/sinfo__utl__table__ex_8c_source.html
new file mode 100644
index 0000000..701bc9a
--- /dev/null
+++ b/html/sinfo__utl__table__ex_8c_source.html
@@ -0,0 +1,331 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_utl_table_ex.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_utl_table_ex.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_utl_table_ex.c,v 1.1 2009/05/20 15:22:42 kmirny Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the SINFONI Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: kmirny $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2009/05/20 15:22:42 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.1 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span>
+<a name="l00032"></a>00032 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                                Includes</span>
+<a name="l00034"></a>00034 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 <span class="preprocessor">#include <string.h></span>
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="comment">/* cpl */</span>
+<a name="l00038"></a>00038 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00039"></a>00039 
+<a name="l00040"></a>00040 <span class="comment">/* irplib */</span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include <irplib_utils.h></span>
+<a name="l00042"></a>00042 
+<a name="l00043"></a>00043 <span class="preprocessor">#include <sinfo_tpl_utils.h></span>
+<a name="l00044"></a>00044 <span class="preprocessor">#include <sinfo_pfits.h></span>
+<a name="l00045"></a>00045 <span class="preprocessor">#include <sinfo_tpl_dfs.h></span>
+<a name="l00046"></a>00046 <span class="preprocessor">#include <sinfo_key_names.h></span>
+<a name="l00047"></a>00047 <span class="preprocessor">#include <sinfo_pro_types.h></span>
+<a name="l00048"></a>00048 <span class="preprocessor">#include <sinfo_functions.h></span>
+<a name="l00049"></a>00049 <span class="preprocessor">#include <sinfo_msg.h></span>
+<a name="l00050"></a>00050 <span class="preprocessor">#include <sinfo_error.h></span>
+<a name="l00051"></a>00051 <span class="preprocessor">#include <sinfo_utils_wrappers.h></span>
+<a name="l00052"></a>00052 
+<a name="l00053"></a>00053 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00054"></a>00054 <span class="comment">                            Functions prototypes</span>
+<a name="l00055"></a>00055 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00056"></a>00056 
+<a name="l00057"></a>00057 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_table_ex_create(cpl_plugin *) ;
+<a name="l00058"></a>00058 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_table_ex_exec(cpl_plugin *) ;
+<a name="l00059"></a>00059 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_table_ex_destroy(cpl_plugin *) ;
+<a name="l00060"></a>00060 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_table_ex(cpl_parameterlist *, cpl_frameset *) ;
+<a name="l00061"></a>00061 
+<a name="l00062"></a>00062 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00063"></a>00063 <span class="comment">                            Static variables</span>
+<a name="l00064"></a>00064 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00065"></a>00065 
+<a name="l00066"></a>00066 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_utl_table_ex_description[] =
+<a name="l00067"></a>00067 <span class="stringliteral">"This recipe produce a table,\n"</span>;
+<a name="l00068"></a>00068 
+<a name="l00069"></a>00069 <span class="comment">/*static char PARAM_NAME_SIZE_X[] = "sinfoni.sinfo_utl_table_ex.size_x";</span>
+<a name="l00070"></a>00070 <span class="comment">static char PARAM_NAME_SIZE_Y[] = "sinfoni.sinfo_utl_table_ex.size_y";</span>
+<a name="l00071"></a>00071 <span class="comment">static char PARAM_NAME_FWHM_X[] = "sinfoni.sinfo_utl_table_ex.fwhm_x";</span>
+<a name="l00072"></a>00072 <span class="comment">static char PARAM_NAME_FWHM_Y[] = "sinfoni.sinfo_utl_table_ex.fwhm_y";</span>
+<a name="l00073"></a>00073 <span class="comment">static char PARAM_NAME_SIGNAL[] = "sinfoni.sinfo_utl_table_ex.total_signal";</span>
+<a name="l00074"></a>00074 <span class="comment">static char PARAM_NAME_BKGSIG[] = "sinfoni.sinfo_utl_table_ex.bkg_signal";</span>
+<a name="l00075"></a>00075 <span class="comment">static char PARAM_NAME_NOISEL[] = "sinfoni.sinfo_utl_table_ex.noise_level";</span>
+<a name="l00076"></a>00076 <span class="comment">*/</span>
+<a name="l00077"></a>00077 <span class="keyword">static</span> <span class="keywordtype">char</span> RECIPE_NAME[] = <span class="stringliteral">"sinfoni.sinfo_utl_table_ex"</span>;
+<a name="l00078"></a>00078 <span class="keyword">static</span> <span class="keywordtype">char</span> CLMN_NAME_SPECTRUM[] = <span class="stringliteral">"spectrum"</span>;
+<a name="l00079"></a>00079 <span class="keyword">static</span> <span class="keywordtype">char</span> CLMN_NAME_WAVELENGTH[] = <span class="stringliteral">"wavelength"</span>;
+<a name="l00080"></a>00080 <span class="keyword">static</span> <span class="keywordtype">char</span> CLMN_NAME_BKG_TOT[] = <span class="stringliteral">"bkg_tot"</span>;
+<a name="l00081"></a>00081 <span class="keyword">static</span> <span class="keywordtype">char</span> CLMN_NAME_COUNTS_BKG[] = <span class="stringliteral">"counts_bkg"</span>;
+<a name="l00082"></a>00082 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00083"></a>00083 <span class="comment">                                Functions code</span>
+<a name="l00084"></a>00084 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00085"></a>00085 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00089"></a>00089 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00090"></a>00090 
+<a name="l00092"></a>00092 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00100"></a>00100 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00101"></a><a class="code" href="group__sinfo__utl__table__ex.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693">00101</a> <span class="keywordtype">int</span> <a class="code" href="group__sinfo__rec__detlin.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693" title="Build the list of available plugins, for this module.">cpl_plugin_get_info</a>(cpl_pluginlist * list)
+<a name="l00102"></a>00102 {
+<a name="l00103"></a>00103     cpl_recipe  *   recipe = cpl_calloc(1, <span class="keyword">sizeof</span> *recipe ) ;
+<a name="l00104"></a>00104     cpl_plugin  *   plugin = &recipe->interface ;
+<a name="l00105"></a>00105 
+<a name="l00106"></a>00106     cpl_plugin_init(plugin,
+<a name="l00107"></a>00107                     CPL_PLUGIN_API,
+<a name="l00108"></a>00108                     SINFONI_BINARY_VERSION,
+<a name="l00109"></a>00109                     CPL_PLUGIN_TYPE_RECIPE,
+<a name="l00110"></a>00110                     <span class="stringliteral">"sinfo_utl_table_ex"</span>,
+<a name="l00111"></a>00111                     <span class="stringliteral">"Test example shows table manipulating utilities"</span>,
+<a name="l00112"></a>00112                     sinfo_utl_table_ex_description,
+<a name="l00113"></a>00113                     <span class="stringliteral">"Konstantin Mirny"</span>,
+<a name="l00114"></a>00114                     <span class="stringliteral">"kmirny at eso.org"</span>,
+<a name="l00115"></a>00115                     sinfo_get_license(),
+<a name="l00116"></a>00116                     sinfo_utl_table_ex_create,
+<a name="l00117"></a>00117                     sinfo_utl_table_ex_exec,
+<a name="l00118"></a>00118                     sinfo_utl_table_ex_destroy) ;
+<a name="l00119"></a>00119 
+<a name="l00120"></a>00120     cpl_pluginlist_append(list, plugin) ;
+<a name="l00121"></a>00121 
+<a name="l00122"></a>00122     <span class="keywordflow">return</span> 0;
+<a name="l00123"></a>00123 }
+<a name="l00124"></a>00124 
+<a name="l00125"></a>00125 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00134"></a>00134 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00135"></a>00135 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_table_ex_create(cpl_plugin * plugin)
+<a name="l00136"></a>00136 {
+<a name="l00137"></a>00137     cpl_recipe      * recipe ;
+<a name="l00138"></a>00138 <span class="comment">//    cpl_parameter   * p ;</span>
+<a name="l00139"></a>00139 
+<a name="l00140"></a>00140     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00141"></a>00141     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
+<a name="l00142"></a>00142         recipe = (cpl_recipe *)plugin ;
+<a name="l00143"></a>00143     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00144"></a>00144     cpl_error_reset();
+<a name="l00145"></a>00145     <a class="code" href="group__irplib__utils.html#gaf9d392144014e2363054bc3f83c8e47e" title="Reset IRPLIB state.">irplib_reset</a>();
+<a name="l00146"></a>00146 
+<a name="l00147"></a>00147     <span class="comment">/* Create the parameters list in the cpl_recipe object */</span>
+<a name="l00148"></a>00148     recipe->parameters = cpl_parameterlist_new() ;
+<a name="l00149"></a>00149 
+<a name="l00150"></a>00150     <span class="comment">/* Fill the parameters list */</span>
+<a name="l00151"></a>00151     <span class="comment">/* --stropt */</span>
+<a name="l00152"></a>00152 <span class="comment">/*    p = cpl_parameter_new_value("sinfoni.sinfo_utl_table_ex.op",</span>
+<a name="l00153"></a>00153 <span class="comment">                                CPL_TYPE_STRING,</span>
+<a name="l00154"></a>00154 <span class="comment">                                "A possible operation",</span>
+<a name="l00155"></a>00155 <span class="comment">                                "sinfoni.sinfo_utl_table_ex","+");</span>
+<a name="l00156"></a>00156 <span class="comment">    cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "op") ;</span>
+<a name="l00157"></a>00157 <span class="comment">    cpl_parameterlist_append(recipe->parameters, p) ;*/</span>
+<a name="l00158"></a>00158 
+<a name="l00159"></a>00159     <span class="comment">/* --size_x */</span>
+<a name="l00160"></a>00160 <span class="comment">/*    p = cpl_parameter_new_value(PARAM_NAME_SIZE_X,</span>
+<a name="l00161"></a>00161 <span class="comment">            CPL_TYPE_INT, "size X axis", RECIPE_NAME, SIZE_X_DEFAULT) ;</span>
+<a name="l00162"></a>00162 <span class="comment">    cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "size_x") ;</span>
+<a name="l00163"></a>00163 <span class="comment">    cpl_parameterlist_append(recipe->parameters, p) ;</span>
+<a name="l00164"></a>00164 <span class="comment">*/</span>
+<a name="l00165"></a>00165     <span class="comment">/* Return */</span>
+<a name="l00166"></a>00166     <span class="keywordflow">return</span> 0;
+<a name="l00167"></a>00167 }
+<a name="l00168"></a>00168 
+<a name="l00169"></a>00169 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00175"></a>00175 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00176"></a>00176 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_table_ex_exec(cpl_plugin * plugin)
+<a name="l00177"></a>00177 {
+<a name="l00178"></a>00178     cpl_recipe  *   recipe ;
+<a name="l00179"></a>00179      <span class="keywordtype">int</span> code=0;
+<a name="l00180"></a>00180      cpl_errorstate initial_errorstate = cpl_errorstate_get();
+<a name="l00181"></a>00181 
+<a name="l00182"></a>00182     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00183"></a>00183     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
+<a name="l00184"></a>00184         recipe = (cpl_recipe *)plugin ;
+<a name="l00185"></a>00185     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00186"></a>00186     cpl_error_reset();
+<a name="l00187"></a>00187     <a class="code" href="group__irplib__utils.html#gaf9d392144014e2363054bc3f83c8e47e" title="Reset IRPLIB state.">irplib_reset</a>();
+<a name="l00188"></a>00188     code = sinfo_utl_table_ex(recipe->parameters, recipe->frames) ;
+<a name="l00189"></a>00189 
+<a name="l00190"></a>00190 
+<a name="l00191"></a>00191     <span class="keywordflow">if</span> (!cpl_errorstate_is_equal(initial_errorstate)) {
+<a name="l00192"></a>00192         <span class="comment">/* Dump the error history since recipe execution start.</span>
+<a name="l00193"></a>00193 <span class="comment">           At this point the recipe cannot recover from the error */</span>
+<a name="l00194"></a>00194         cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
+<a name="l00195"></a>00195     }
+<a name="l00196"></a>00196 
+<a name="l00197"></a>00197     <span class="keywordflow">return</span> code ;
+<a name="l00198"></a>00198 }
+<a name="l00199"></a>00199 
+<a name="l00200"></a>00200 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00206"></a>00206 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00207"></a>00207 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_table_ex_destroy(cpl_plugin * plugin)
+<a name="l00208"></a>00208 {
+<a name="l00209"></a>00209     cpl_recipe  *   recipe ;
+<a name="l00210"></a>00210 
+<a name="l00211"></a>00211     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00212"></a>00212     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
+<a name="l00213"></a>00213         recipe = (cpl_recipe *)plugin ;
+<a name="l00214"></a>00214     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00215"></a>00215 
+<a name="l00216"></a>00216     cpl_parameterlist_delete(recipe->parameters) ;
+<a name="l00217"></a>00217     <span class="keywordflow">return</span> 0 ;
+<a name="l00218"></a>00218 }
+<a name="l00219"></a>00219 
+<a name="l00220"></a>00220 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00227"></a>00227 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00228"></a>00228 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00229"></a>00229 sinfo_utl_table_ex( cpl_parameterlist   *   parlist,
+<a name="l00230"></a>00230         cpl_frameset        *   framelist)
+<a name="l00231"></a>00231 {
+<a name="l00232"></a>00232     <span class="comment">// parameters</span>
+<a name="l00233"></a>00233     <span class="keywordtype">double</span> range_min = 1.9;
+<a name="l00234"></a>00234     <span class="keywordtype">double</span> range_max = 2.;
+<a name="l00236"></a>00236 
+<a name="l00237"></a>00237     <span class="keyword">const</span> <span class="keywordtype">char</span>          *   name_o = NULL ;
+<a name="l00238"></a>00238     <span class="keyword">const</span> <span class="keywordtype">char</span>          *   sourceTableName = NULL;
+<a name="l00239"></a>00239 <span class="comment">//    cpl_parameter       *   param = NULL ;</span>
+<a name="l00240"></a>00240 
+<a name="l00241"></a>00241     cpl_propertylist    *   plist = NULL ;
+<a name="l00242"></a>00242     cpl_frame           *   product_frame = NULL;
+<a name="l00243"></a>00243     <span class="keywordtype">int</span>                     nrow = 0; <span class="comment">// number of rows in the table</span>
+<a name="l00244"></a>00244     cpl_table           *   tblSource = NULL; <span class="comment">// source table</span>
+<a name="l00245"></a>00245     cpl_table           *   tblResult = NULL; <span class="comment">// result table</span>
+<a name="l00246"></a>00246     <span class="keywordtype">float</span>               *   pValues   = NULL; <span class="comment">// source column</span>
+<a name="l00247"></a>00247 
+<a name="l00248"></a>00248     sinfo_msg(<span class="stringliteral">"Welcome to SINFONI Pipeline release %d.%d.%d"</span>,
+<a name="l00249"></a>00249     SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
+<a name="l00250"></a>00250     ck0(sinfo_dfs_set_groups(framelist),<span class="stringliteral">"Cannot indentify RAW and CALIB frames"</span>);
+<a name="l00251"></a>00251 
+<a name="l00252"></a>00252 <span class="comment">/* HOW TO RETRIEVE INPUT PARAMETERS */</span>
+<a name="l00253"></a>00253       <span class="comment">/* --size_x */</span>
+<a name="l00254"></a>00254 <span class="comment">//    check_nomsg(param=cpl_parameterlist_find(parlist,</span>
+<a name="l00255"></a>00255 <span class="comment">//                                             PARAM_NAME_SIZE_X));</span>
+<a name="l00256"></a>00256 <span class="comment">//    check_nomsg(iSizeX=cpl_parameter_get_int(param));</span>
+<a name="l00257"></a>00257 
+<a name="l00258"></a>00258 
+<a name="l00259"></a>00259 
+<a name="l00260"></a>00260 
+<a name="l00261"></a>00261     <span class="comment">/* HOW TO GET THE VALUE OF A FITS KEYWORD */</span>
+<a name="l00262"></a>00262     check(plist=cpl_propertylist_new(),<span class="stringliteral">"Cannot create a Property List"</span>);
+<a name="l00263"></a>00263 
+<a name="l00264"></a>00264     <span class="comment">/* Now performing the data reduction */</span>
+<a name="l00265"></a>00265     <span class="comment">/* Let's generate one image for the example */</span>
+<a name="l00266"></a>00266 
+<a name="l00267"></a>00267     <span class="comment">// get the source table</span>
+<a name="l00268"></a>00268     check(product_frame = cpl_frameset_get_first(framelist),<span class="stringliteral">"Cannot get product frame"</span>);
+<a name="l00269"></a>00269     check(sourceTableName = cpl_frame_get_filename(product_frame),<span class="stringliteral">"Cannot get source table name"</span>);
+<a name="l00270"></a>00270     check_nomsg(tblSource = cpl_table_load(sourceTableName, 1, 0));
+<a name="l00271"></a>00271     <span class="comment">// generate result table</span>
+<a name="l00272"></a>00272     <span class="comment">// 1. duplicate the table</span>
+<a name="l00273"></a>00273     check(tblResult = cpl_table_duplicate(tblSource), <span class="stringliteral">"cannot duplicate table"</span>);
+<a name="l00274"></a>00274     <span class="comment">// 2. Cycle through the table - select only predefined interval</span>
+<a name="l00275"></a>00275     check_nomsg(nrow = cpl_table_get_nrow(tblResult));
+<a name="l00276"></a>00276     sinfo_msg(<span class="stringliteral">"%d rows in the source table"</span>, nrow);
+<a name="l00277"></a>00277     <span class="keywordflow">if</span> (nrow)
+<a name="l00278"></a>00278     {
+<a name="l00279"></a>00279         <span class="keywordtype">int</span> i = 0;
+<a name="l00280"></a>00280         <span class="keywordtype">int</span> m = 0;
+<a name="l00281"></a>00281         check_nomsg(pValues = cpl_table_get_data_float(tblResult, CLMN_NAME_WAVELENGTH));
+<a name="l00282"></a>00282         sinfo_msg(<span class="stringliteral">"checking wavelenghts..."</span>);
+<a name="l00283"></a>00283         check(cpl_table_unselect_all(tblResult),<span class="stringliteral">"cannot unselect all"</span>);
+<a name="l00284"></a>00284         <span class="keywordflow">for</span> (i = 0; i < nrow; ++i)
+<a name="l00285"></a>00285         {
+<a name="l00286"></a>00286             <span class="keywordflow">if</span> ((*(pValues + i) < range_min) || (*(pValues + i) > range_max))
+<a name="l00287"></a>00287             {
+<a name="l00288"></a>00288                 <span class="comment">// mark for removing</span>
+<a name="l00289"></a>00289                 check(cpl_table_select_row(tblResult, i), <span class="stringliteral">"Cannot select a row in a table"</span>);
+<a name="l00290"></a>00290                 ++m;
+<a name="l00291"></a>00291             }
+<a name="l00292"></a>00292         }
+<a name="l00293"></a>00293         sinfo_msg(<span class="stringliteral">"%d row(s) would be removed from the result"</span>, m);
+<a name="l00294"></a>00294         <span class="comment">// delete select rows from the table</span>
+<a name="l00295"></a>00295         check(cpl_table_erase_selected(tblResult),<span class="stringliteral">"Cannot delete selected rows from a table"</span>);
+<a name="l00296"></a>00296     }
+<a name="l00297"></a>00297     <span class="comment">// 3. create a new column for the result table</span>
+<a name="l00298"></a>00298     <span class="comment">// 4. Fill in the new column with values</span>
+<a name="l00299"></a>00299     check(cpl_table_duplicate_column(tblResult,CLMN_NAME_SPECTRUM, tblResult, CLMN_NAME_BKG_TOT),<span class="stringliteral">"Unable to create new column in the table"</span>);
+<a name="l00300"></a>00300     check(cpl_table_add_columns(tblResult, CLMN_NAME_SPECTRUM, CLMN_NAME_COUNTS_BKG), <span class="stringliteral">"Error during sum the columns"</span>);
+<a name="l00301"></a>00301 
+<a name="l00302"></a>00302     <span class="comment">/* Set the file name */</span>
+<a name="l00303"></a>00303     name_o = <span class="stringliteral">"ima_res.fits"</span> ;
+<a name="l00304"></a>00304     <span class="comment">/* Create product frame */</span>
+<a name="l00305"></a>00305 
+<a name="l00306"></a>00306     check_nomsg(product_frame = cpl_frame_new());
+<a name="l00307"></a>00307     check_nomsg(cpl_frame_set_filename(product_frame, name_o)) ;
+<a name="l00308"></a>00308     check_nomsg(cpl_frame_set_tag(product_frame,<span class="stringliteral">"table_example"</span> )) ;
+<a name="l00309"></a>00309     check_nomsg(cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_TABLE)) ;
+<a name="l00310"></a>00310     check_nomsg(cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT)) ;
+<a name="l00311"></a>00311     check(cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL),
+<a name="l00312"></a>00312       <span class="stringliteral">"Error while initialising the product frame"</span>) ;
+<a name="l00313"></a>00313 
+<a name="l00314"></a>00314     <span class="comment">/* Add DataFlow keywords */</span>
+<a name="l00315"></a>00315     check_nomsg(cpl_propertylist_erase_regexp(plist, <span class="stringliteral">"^ESO PRO CATG"</span>,0));
+<a name="l00316"></a>00316 <span class="comment">//    cpl_frameset_dump(framelist, stdout);</span>
+<a name="l00317"></a>00317     check(cpl_dfs_setup_product_header(plist,
+<a name="l00318"></a>00318                                        product_frame,
+<a name="l00319"></a>00319                                        framelist,
+<a name="l00320"></a>00320                                        parlist,
+<a name="l00321"></a>00321                                        <span class="stringliteral">"sinfo_utl_table_ex"</span>,
+<a name="l00322"></a>00322                                        <span class="stringliteral">"SINFONI"</span>,
+<a name="l00323"></a>00323                                        KEY_VALUE_HPRO_DID,NULL),
+<a name="l00324"></a>00324       <span class="stringliteral">"Problem in the product DFS-compliance"</span>) ;
+<a name="l00325"></a>00325 
+<a name="l00326"></a>00326 
+<a name="l00327"></a>00327     <span class="comment">/* Save the file */</span>
+<a name="l00328"></a>00328     cpl_table_dump(tblResult, 0, 3, stdout);
+<a name="l00329"></a>00329     check(cpl_table_save(tblResult,
+<a name="l00330"></a>00330                         NULL, NULL,
+<a name="l00331"></a>00331                          name_o,
+<a name="l00332"></a>00332                          CPL_IO_DEFAULT), <span class="stringliteral">"Cannot save table"</span>);
+<a name="l00333"></a>00333 
+<a name="l00334"></a>00334     sinfo_free_propertylist(&plist) ;
+<a name="l00335"></a>00335     <span class="comment">/* Log the saved file in the input frameset */</span>
+<a name="l00336"></a>00336     check_nomsg(cpl_frameset_insert(framelist, product_frame)) ;
+<a name="l00337"></a>00337 
+<a name="l00338"></a>00338 
+<a name="l00339"></a>00339  cleanup:
+<a name="l00340"></a>00340 
+<a name="l00341"></a>00341     sinfo_free_propertylist(&plist) ;
+<a name="l00342"></a>00342     cpl_table_delete(tblSource);
+<a name="l00343"></a>00343     cpl_table_delete(tblResult);
+<a name="l00344"></a>00344     <span class="comment">/* This is usually freed by esorex: but what about if errors occurs?</span>
+<a name="l00345"></a>00345 <span class="comment">    sinfo_free_frame(&product_frame) ;</span>
+<a name="l00346"></a>00346 <span class="comment">    */</span>
+<a name="l00347"></a>00347 
+<a name="l00348"></a>00348 
+<a name="l00349"></a>00349     <span class="keywordflow">return</span> ((cpl_error_get_code()) ? -1 : 0 );
+<a name="l00350"></a>00350 
+<a name="l00351"></a>00351 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__utl__table__test_8c_source.html b/html/sinfo__utl__table__test_8c_source.html
new file mode 100644
index 0000000..840e430
--- /dev/null
+++ b/html/sinfo__utl__table__test_8c_source.html
@@ -0,0 +1,1133 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_utl_table_test.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_utl_table_test.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_utl_table_test.c,v 1.6 2012/03/03 10:38:03 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the SINFONI Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2012/03/03 10:38:03 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.6 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span><span class="preprocessor">#include <math.h></span>
+<a name="l00032"></a>00032 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                                Includes</span>
+<a name="l00034"></a>00034 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 <span class="preprocessor">#include <stdlib.h></span>
+<a name="l00036"></a>00036 <span class="comment">/* cpl */</span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00038"></a>00038 <span class="comment">/* irplib */</span>
+<a name="l00039"></a>00039 <span class="preprocessor">#include <irplib_utils.h></span>
+<a name="l00040"></a>00040 
+<a name="l00041"></a>00041 <span class="preprocessor">#include <sinfo_tpl_utils.h></span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include <sinfo_pfits.h></span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include <sinfo_tpl_dfs.h></span>
+<a name="l00044"></a>00044 <span class="preprocessor">#include <sinfo_msg.h></span>
+<a name="l00045"></a>00045 <span class="preprocessor">#include <sinfo_error.h></span>
+<a name="l00046"></a>00046 <span class="preprocessor">#include <sinfo_utils_wrappers.h></span>
+<a name="l00047"></a>00047 <span class="preprocessor">#include <sinfo_globals.h></span>
+<a name="l00048"></a>00048 <span class="preprocessor">#include <sinfo_recipes.h></span>
+<a name="l00049"></a>00049 <span class="preprocessor">#include <sinfo_function_1d.h></span>
+<a name="l00050"></a>00050 <span class="preprocessor">#include <sinfo_functions.h></span>
+<a name="l00051"></a>00051 <span class="preprocessor">#include <sinfo_fit.h></span>
+<a name="l00052"></a>00052 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00053"></a>00053 <span class="comment">                            Functions prototypes</span>
+<a name="l00054"></a>00054 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00055"></a>00055 
+<a name="l00056"></a>00056 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_table_test_create(cpl_plugin *) ;
+<a name="l00057"></a>00057 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_table_test_exec(cpl_plugin *) ;
+<a name="l00058"></a>00058 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_table_test_destroy(cpl_plugin *) ;
+<a name="l00059"></a>00059 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_table_test_shift(cpl_parameterlist *, cpl_frameset *) ;
+<a name="l00060"></a>00060 
+<a name="l00061"></a>00061 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00062"></a>00062 sinfo_utl_table_test_amoeba_poly(cpl_parameterlist   *   parlist, 
+<a name="l00063"></a>00063              cpl_frameset        *   framelist);
+<a name="l00064"></a>00064 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00065"></a>00065 sinfo_utl_table_test_amoeba_boltzmann(cpl_parameterlist   *   parlist, 
+<a name="l00066"></a>00066              cpl_frameset        *   framelist);
+<a name="l00067"></a>00067 
+<a name="l00068"></a>00068 <span class="keyword">static</span> cpl_vector* sa_vx=NULL;
+<a name="l00069"></a>00069 <span class="keyword">static</span> cpl_vector* sa_vy=NULL;
+<a name="l00070"></a>00070 
+<a name="l00071"></a>00071 <span class="keyword">static</span> <span class="keywordtype">double</span>
+<a name="l00072"></a>00072 sinfo_fit_boltzmann(<span class="keywordtype">double</span> p[]);
+<a name="l00073"></a>00073 
+<a name="l00074"></a>00074 
+<a name="l00075"></a>00075 <span class="keyword">static</span> <span class="keywordtype">int</span> 
+<a name="l00076"></a>00076 sinfo_fitbkg(<span class="keyword">const</span> <span class="keywordtype">double</span> x[], 
+<a name="l00077"></a>00077              <span class="keyword">const</span> <span class="keywordtype">double</span> a[], 
+<a name="l00078"></a>00078              <span class="keywordtype">double</span> *result);
+<a name="l00079"></a>00079 
+<a name="l00080"></a>00080 <span class="keyword">static</span> <span class="keywordtype">double</span>
+<a name="l00081"></a>00081 sinfo_fac(<span class="keyword">const</span> <span class="keywordtype">double</span> x, <span class="keyword">const</span> <span class="keywordtype">double</span> t);
+<a name="l00082"></a>00082 
+<a name="l00083"></a>00083 <span class="keyword">static</span> <span class="keywordtype">double</span>
+<a name="l00084"></a>00084 sinfo_fit_poly(<span class="keywordtype">double</span> p[]);;
+<a name="l00085"></a>00085 
+<a name="l00086"></a>00086 <span class="keyword">static</span> cpl_table*
+<a name="l00087"></a>00087 sinfo_table_shift_column_spline3(cpl_table* t, 
+<a name="l00088"></a>00088                                  <span class="keyword">const</span> <span class="keywordtype">char</span>* col, 
+<a name="l00089"></a>00089                                  <span class="keyword">const</span> <span class="keywordtype">double</span> s);
+<a name="l00090"></a>00090 
+<a name="l00091"></a>00091 <span class="keyword">static</span> cpl_table*
+<a name="l00092"></a>00092 sinfo_table_shift_column_poly(cpl_table* t, 
+<a name="l00093"></a>00093                               <span class="keyword">const</span> <span class="keywordtype">char</span>* col, 
+<a name="l00094"></a>00094                               <span class="keyword">const</span> <span class="keywordtype">double</span> s,
+<a name="l00095"></a>00095                               <span class="keyword">const</span> <span class="keywordtype">int</span> order);
+<a name="l00096"></a>00096 
+<a name="l00097"></a>00097 <span class="keyword">static</span> cpl_table*
+<a name="l00098"></a>00098 sinfo_table_shift_column_int(<span class="keyword">const</span> cpl_table* t, 
+<a name="l00099"></a>00099                              <span class="keyword">const</span> <span class="keywordtype">char</span>* col, 
+<a name="l00100"></a>00100                              <span class="keyword">const</span> <span class="keywordtype">double</span> s,
+<a name="l00101"></a>00101                                    <span class="keywordtype">double</span>* r);
+<a name="l00102"></a>00102 
+<a name="l00103"></a>00103 <span class="keyword">static</span> cpl_table*
+<a name="l00104"></a>00104 sinfo_table_shift_simple(cpl_table* inp, 
+<a name="l00105"></a>00105                          <span class="keyword">const</span> <span class="keywordtype">char</span>* col, 
+<a name="l00106"></a>00106                          <span class="keyword">const</span> <span class="keywordtype">double</span> shift);
+<a name="l00107"></a>00107 
+<a name="l00108"></a>00108 <span class="preprocessor">#define NPOINT 1000</span>
+<a name="l00109"></a>00109 <span class="preprocessor"></span><span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00110"></a>00110 <span class="comment">                            Static variables</span>
+<a name="l00111"></a>00111 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00112"></a>00112 
+<a name="l00113"></a>00113 <span class="keyword">static</span> <span class="keywordtype">char</span> sinfo_utl_table_test_description[] =
+<a name="l00114"></a>00114 <span class="stringliteral">"This recipe perform cubes combination.\n"</span>
+<a name="l00115"></a>00115 <span class="stringliteral">"The input files are several cubeses\n"</span>
+<a name="l00116"></a>00116 <span class="stringliteral">"their associated tags should be CUBE.\n"</span>
+<a name="l00117"></a>00117 <span class="stringliteral">"The output is a cube PRO_CUBE resulting from the input cubes\n"</span>
+<a name="l00118"></a>00118 <span class="stringliteral">"accurding to the value of op where op indicates the operation to be \n"</span>
+<a name="l00119"></a>00119 <span class="stringliteral">"performed specified by the parameter sinfoni.sinfo_utl_table_test.op\n"</span>
+<a name="l00120"></a>00120 <span class="stringliteral">"Information on relevant parameters can be found with\n"</span>
+<a name="l00121"></a>00121 <span class="stringliteral">"esorex --params sinfo_utl_table_test\n"</span>
+<a name="l00122"></a>00122 <span class="stringliteral">"esorex --help sinfo_utl_table_test\n"</span>
+<a name="l00123"></a>00123 <span class="stringliteral">"\n"</span>;
+<a name="l00124"></a>00124 
+<a name="l00125"></a>00125 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00126"></a>00126 <span class="comment">                                Functions code</span>
+<a name="l00127"></a>00127 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00129"></a>00129 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00133"></a>00133 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00134"></a>00134 
+<a name="l00135"></a>00135 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00143"></a>00143 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00144"></a>00144 <span class="keywordtype">int</span> <a class="code" href="group__sinfo__rec__detlin.html#ga31d1fccd4cd15b1c1f3c5edc8cb18693" title="Build the list of available plugins, for this module.">cpl_plugin_get_info</a>(cpl_pluginlist * list)
+<a name="l00145"></a>00145 {
+<a name="l00146"></a>00146     cpl_recipe  *   recipe = cpl_calloc(1, <span class="keyword">sizeof</span> *recipe ) ;
+<a name="l00147"></a>00147     cpl_plugin  *   plugin = &recipe->interface ;
+<a name="l00148"></a>00148 
+<a name="l00149"></a>00149     cpl_plugin_init(plugin,
+<a name="l00150"></a>00150                     CPL_PLUGIN_API,
+<a name="l00151"></a>00151                     SINFONI_BINARY_VERSION,
+<a name="l00152"></a>00152                     CPL_PLUGIN_TYPE_RECIPE,
+<a name="l00153"></a>00153                     <span class="stringliteral">"sinfo_utl_table_test"</span>,
+<a name="l00154"></a>00154                     <span class="stringliteral">"Combines a cube list in an output cube"</span>,
+<a name="l00155"></a>00155                     sinfo_utl_table_test_description,
+<a name="l00156"></a>00156                     <span class="stringliteral">"Andrea Modigliani"</span>,
+<a name="l00157"></a>00157                     <span class="stringliteral">"Andrea.Modigliani at eso.org"</span>,
+<a name="l00158"></a>00158                     sinfo_get_license(),
+<a name="l00159"></a>00159                     sinfo_utl_table_test_create,
+<a name="l00160"></a>00160                     sinfo_utl_table_test_exec,
+<a name="l00161"></a>00161                     sinfo_utl_table_test_destroy) ;
+<a name="l00162"></a>00162 
+<a name="l00163"></a>00163     cpl_pluginlist_append(list, plugin) ;
+<a name="l00164"></a>00164     
+<a name="l00165"></a>00165     <span class="keywordflow">return</span> 0;
+<a name="l00166"></a>00166 }
+<a name="l00167"></a>00167 
+<a name="l00168"></a>00168 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00177"></a>00177 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00178"></a>00178 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_table_test_create(cpl_plugin * plugin)
+<a name="l00179"></a>00179 {
+<a name="l00180"></a>00180     cpl_recipe      * recipe ;
+<a name="l00181"></a>00181     cpl_parameter   * p ;
+<a name="l00182"></a>00182 
+<a name="l00183"></a>00183     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00184"></a>00184     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00185"></a>00185         recipe = (cpl_recipe *)plugin ;
+<a name="l00186"></a>00186     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00187"></a>00187     cpl_error_reset();
+<a name="l00188"></a>00188     <a class="code" href="group__irplib__utils.html#gaf9d392144014e2363054bc3f83c8e47e" title="Reset IRPLIB state.">irplib_reset</a>();
+<a name="l00189"></a>00189 
+<a name="l00190"></a>00190     <span class="comment">/* Create the parameters list in the cpl_recipe object */</span>
+<a name="l00191"></a>00191     recipe->parameters = cpl_parameterlist_new() ; 
+<a name="l00192"></a>00192 
+<a name="l00193"></a>00193     <span class="comment">/* Fill the parameters list */</span>
+<a name="l00194"></a>00194     <span class="comment">/* --stropt */</span>
+<a name="l00195"></a>00195     p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.sinfo_utl_table_test.method"</span>, 
+<a name="l00196"></a>00196                                 CPL_TYPE_STRING, 
+<a name="l00197"></a>00197                                 <span class="stringliteral">"Output filename"</span>, 
+<a name="l00198"></a>00198                                 <span class="stringliteral">"sinfoni.sinfo_utl_table_test"</span>,
+<a name="l00199"></a>00199                                 <span class="stringliteral">"sinfo_clean_mean"</span>);
+<a name="l00200"></a>00200     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"method"</span>) ;
+<a name="l00201"></a>00201     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00202"></a>00202 
+<a name="l00203"></a>00203     <span class="comment">/* --doubleopt */</span>
+<a name="l00204"></a>00204     p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.sinfo_utl_table_test.wshift"</span>, 
+<a name="l00205"></a>00205                                 CPL_TYPE_DOUBLE, 
+<a name="l00206"></a>00206                                 <span class="stringliteral">"Shift"</span>, 
+<a name="l00207"></a>00207                                 <span class="stringliteral">"sinfoni.sinfo_utl_table_test"</span>, 
+<a name="l00208"></a>00208                                 0.01) ;
+<a name="l00209"></a>00209 
+<a name="l00210"></a>00210     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"wshift"</span>) ;
+<a name="l00211"></a>00211     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00212"></a>00212 
+<a name="l00213"></a>00213     <span class="comment">/* --doubleopt */</span>
+<a name="l00214"></a>00214     p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.sinfo_utl_table_test.wstart"</span>, 
+<a name="l00215"></a>00215                                 CPL_TYPE_DOUBLE, 
+<a name="l00216"></a>00216                                 <span class="stringliteral">"Shift"</span>, 
+<a name="l00217"></a>00217                                 <span class="stringliteral">"sinfoni.sinfo_utl_table_test"</span>, 
+<a name="l00218"></a>00218                                 1.45) ;
+<a name="l00219"></a>00219 
+<a name="l00220"></a>00220 
+<a name="l00221"></a>00221     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"wstart"</span>) ;
+<a name="l00222"></a>00222     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00223"></a>00223 
+<a name="l00224"></a>00224 
+<a name="l00225"></a>00225     <span class="comment">/* --doubleopt */</span>
+<a name="l00226"></a>00226     p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.sinfo_utl_table_test.wend"</span>, 
+<a name="l00227"></a>00227                                 CPL_TYPE_DOUBLE, 
+<a name="l00228"></a>00228                                 <span class="stringliteral">"End Wavelength"</span>, 
+<a name="l00229"></a>00229                                 <span class="stringliteral">"sinfoni.sinfo_utl_table_test"</span>, 
+<a name="l00230"></a>00230                                 2.45) ;
+<a name="l00231"></a>00231 
+<a name="l00232"></a>00232 
+<a name="l00233"></a>00233     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, <span class="stringliteral">"wend"</span>) ;
+<a name="l00234"></a>00234     cpl_parameterlist_append(recipe->parameters, p) ;
+<a name="l00235"></a>00235 
+<a name="l00236"></a>00236 
+<a name="l00237"></a>00237     <span class="comment">/* Return */</span>
+<a name="l00238"></a>00238     <span class="keywordflow">return</span> 0;
+<a name="l00239"></a>00239 }
+<a name="l00240"></a>00240 
+<a name="l00241"></a>00241 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00247"></a>00247 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00248"></a>00248 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_table_test_exec(cpl_plugin * plugin)
+<a name="l00249"></a>00249 {
+<a name="l00250"></a>00250     cpl_recipe  *   recipe ;
+<a name="l00251"></a>00251     <span class="keywordtype">int</span> status=0;
+<a name="l00252"></a>00252     cpl_errorstate initial_errorstate = cpl_errorstate_get();
+<a name="l00253"></a>00253 
+<a name="l00254"></a>00254     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00255"></a>00255     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00256"></a>00256         recipe = (cpl_recipe *)plugin ;
+<a name="l00257"></a>00257     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00258"></a>00258     status+=sinfo_utl_table_test_shift(recipe->parameters, recipe->frames);
+<a name="l00259"></a>00259     status+=sinfo_utl_table_test_amoeba_poly(recipe->parameters, 
+<a name="l00260"></a>00260                                              recipe->frames);
+<a name="l00261"></a>00261     status+=sinfo_utl_table_test_amoeba_boltzmann(recipe->parameters, 
+<a name="l00262"></a>00262                                                   recipe->frames);
+<a name="l00263"></a>00263    <span class="keywordflow">if</span> (!cpl_errorstate_is_equal(initial_errorstate)) {                      
+<a name="l00264"></a>00264         <span class="comment">/* Dump the error history since recipe execution start.                </span>
+<a name="l00265"></a>00265 <span class="comment">           At this point the recipe cannot recover from the error */</span>           
+<a name="l00266"></a>00266         cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);              
+<a name="l00267"></a>00267     } 
+<a name="l00268"></a>00268     <span class="keywordflow">return</span> status ;
+<a name="l00269"></a>00269 }
+<a name="l00270"></a>00270 
+<a name="l00271"></a>00271 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00277"></a>00277 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00278"></a>00278 <span class="keyword">static</span> <span class="keywordtype">int</span> sinfo_utl_table_test_destroy(cpl_plugin * plugin)
+<a name="l00279"></a>00279 {
+<a name="l00280"></a>00280     cpl_recipe  *   recipe ;
+<a name="l00281"></a>00281     
+<a name="l00282"></a>00282     <span class="comment">/* Get the recipe out of the plugin */</span>
+<a name="l00283"></a>00283     <span class="keywordflow">if</span> (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+<a name="l00284"></a>00284         recipe = (cpl_recipe *)plugin ;
+<a name="l00285"></a>00285     <span class="keywordflow">else</span> <span class="keywordflow">return</span> -1 ;
+<a name="l00286"></a>00286 
+<a name="l00287"></a>00287     cpl_parameterlist_delete(recipe->parameters) ; 
+<a name="l00288"></a>00288     <span class="keywordflow">return</span> 0 ;
+<a name="l00289"></a>00289 }
+<a name="l00290"></a>00290 
+<a name="l00291"></a>00291 
+<a name="l00292"></a>00292 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00299"></a>00299 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00300"></a>00300 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00301"></a>00301 sinfo_utl_table_test_shift(cpl_parameterlist   *   parlist, 
+<a name="l00302"></a>00302             cpl_frameset        *   framelist)
+<a name="l00303"></a>00303 {
+<a name="l00304"></a>00304 
+<a name="l00305"></a>00305   cpl_table* t=NULL;
+<a name="l00306"></a>00306   cpl_table* t_shift=NULL;
+<a name="l00307"></a>00307   <span class="keywordtype">int</span> np=NPOINT;
+<a name="l00308"></a>00308   cpl_parameter* p=NULL;
+<a name="l00309"></a>00309   <span class="keyword">const</span> <span class="keywordtype">char</span>* op=NULL;
+<a name="l00310"></a>00310   <span class="keywordtype">double</span> ws=0;
+<a name="l00311"></a>00311   <span class="keywordtype">double</span> we=0;
+<a name="l00312"></a>00312   <span class="keywordtype">double</span> wd=0;
+<a name="l00313"></a>00313   <span class="keywordtype">double</span> wshift=0;
+<a name="l00314"></a>00314   <span class="keywordtype">double</span> pshift=0;
+<a name="l00315"></a>00315 
+<a name="l00316"></a>00316   <span class="keywordtype">double</span>* pw=NULL;
+<a name="l00317"></a>00317   <span class="keywordtype">double</span>* pi=NULL;
+<a name="l00318"></a>00318 
+<a name="l00319"></a>00319   <span class="keywordtype">int</span> i=0;
+<a name="l00320"></a>00320 
+<a name="l00321"></a>00321   <span class="keywordtype">double</span> ra=0;
+<a name="l00322"></a>00322   <span class="keyword">const</span> <span class="keywordtype">double</span> pg=3.1415926535897932384626433832795;
+<a name="l00323"></a>00323   
+<a name="l00324"></a>00324 
+<a name="l00325"></a>00325   check(sinfo_dfs_set_groups(framelist),
+<a name="l00326"></a>00326          <span class="stringliteral">"Cannot identify RAW and CALIB frames"</span>) ;
+<a name="l00327"></a>00327 
+<a name="l00328"></a>00328   <span class="comment">// read input parameters</span>
+<a name="l00329"></a>00329   check_nomsg(p=cpl_parameterlist_find(parlist, 
+<a name="l00330"></a>00330                 <span class="stringliteral">"sinfoni.sinfo_utl_table_test.method"</span>));
+<a name="l00331"></a>00331   check_nomsg(op=cpl_parameter_get_string(p));
+<a name="l00332"></a>00332 
+<a name="l00333"></a>00333 
+<a name="l00334"></a>00334   check_nomsg(p=cpl_parameterlist_find(parlist,
+<a name="l00335"></a>00335                 <span class="stringliteral">"sinfoni.sinfo_utl_table_test.wstart"</span>));
+<a name="l00336"></a>00336   check_nomsg(ws=cpl_parameter_get_double(p)) ;
+<a name="l00337"></a>00337 
+<a name="l00338"></a>00338 
+<a name="l00339"></a>00339   wd=(we-ws)/np;
+<a name="l00340"></a>00340   check_nomsg(p=cpl_parameterlist_find(parlist,
+<a name="l00341"></a>00341                 <span class="stringliteral">"sinfoni.sinfo_utl_table_test.wend"</span>));
+<a name="l00342"></a>00342   check_nomsg(we=cpl_parameter_get_double(p)) ;
+<a name="l00343"></a>00343 
+<a name="l00344"></a>00344   check_nomsg(p=cpl_parameterlist_find(parlist,
+<a name="l00345"></a>00345                 <span class="stringliteral">"sinfoni.sinfo_utl_table_test.wshift"</span>));
+<a name="l00346"></a>00346   check_nomsg(wshift=cpl_parameter_get_double(p)) ;
+<a name="l00347"></a>00347   
+<a name="l00348"></a>00348 
+<a name="l00349"></a>00349 
+<a name="l00350"></a>00350   <span class="comment">// create the table</span>
+<a name="l00351"></a>00351   check_nomsg(t=cpl_table_new(np));
+<a name="l00352"></a>00352   check_nomsg(cpl_table_new_column(t,<span class="stringliteral">"WAVE"</span>,CPL_TYPE_DOUBLE));
+<a name="l00353"></a>00353   check_nomsg(cpl_table_new_column(t,<span class="stringliteral">"INT"</span>,CPL_TYPE_DOUBLE));
+<a name="l00354"></a>00354   check_nomsg(cpl_table_fill_column_window(t,<span class="stringliteral">"WAVE"</span>,0,np,0));
+<a name="l00355"></a>00355   check_nomsg(cpl_table_fill_column_window(t,<span class="stringliteral">"INT"</span>,0,np,0));
+<a name="l00356"></a>00356 
+<a name="l00357"></a>00357   check_nomsg(pw=cpl_table_get_data_double(t,<span class="stringliteral">"WAVE"</span>));
+<a name="l00358"></a>00358   check_nomsg(pi=cpl_table_get_data_double(t,<span class="stringliteral">"INT"</span>));
+<a name="l00359"></a>00359 
+<a name="l00360"></a>00360 
+<a name="l00361"></a>00361 
+<a name="l00362"></a>00362   <span class="keywordflow">for</span>(i=0;i<np;i++) {
+<a name="l00363"></a>00363     pw[i]=ws+i*wd;
+<a name="l00364"></a>00364     ra=(double)i/(<span class="keywordtype">double</span>)np*6.*pg;
+<a name="l00365"></a>00365     pi[i]=cos(ra);
+<a name="l00366"></a>00366   }
+<a name="l00367"></a>00367   pshift=wshift/wd;
+<a name="l00368"></a>00368   check_nomsg(cpl_table_save(t, NULL, NULL, <span class="stringliteral">"out_cosine.fits"</span>, 0));
+<a name="l00369"></a>00369   <span class="comment">/*</span>
+<a name="l00370"></a>00370 <span class="comment">  sinfo_msg("shift1");</span>
+<a name="l00371"></a>00371 <span class="comment">  cknull_nomsg(t_shift=sinfo_table_shift_column_int(t, "INT", pshift,&wrest));</span>
+<a name="l00372"></a>00372 <span class="comment">  check_nomsg(cpl_table_save(t_shift,NULL,NULL,"out_cosine_shift1.fits", 0));</span>
+<a name="l00373"></a>00373 <span class="comment">  sinfo_msg("shift2");</span>
+<a name="l00374"></a>00374 <span class="comment">  sinfo_free_table(&t_shift);</span>
+<a name="l00375"></a>00375 <span class="comment">  cknull_nomsg(t_shift=sinfo_table_shift_column_poly(t,"INT", pshift,2));</span>
+<a name="l00376"></a>00376 <span class="comment">  check_nomsg(cpl_table_save(t_shift,NULL,NULL,"out_cosine_shift2.fits", 0));</span>
+<a name="l00377"></a>00377 <span class="comment">  sinfo_msg("shift3");</span>
+<a name="l00378"></a>00378 <span class="comment">  sinfo_free_table(&t_shift);</span>
+<a name="l00379"></a>00379 <span class="comment">  cknull_nomsg(t_shift=sinfo_table_shift_column_spline3(t_shift,"INT",pshift));</span>
+<a name="l00380"></a>00380 <span class="comment"></span>
+<a name="l00381"></a>00381 <span class="comment">  */</span>
+<a name="l00382"></a>00382 
+<a name="l00383"></a>00383   check_nomsg(t_shift=sinfo_table_shift_simple(t,<span class="stringliteral">"INT"</span>,pshift));
+<a name="l00384"></a>00384   check_nomsg(cpl_table_save(t_shift,NULL,NULL, <span class="stringliteral">"out_cosine_shift3.fits"</span>, 0));
+<a name="l00385"></a>00385   sinfo_free_table(&t);
+<a name="l00386"></a>00386 
+<a name="l00387"></a>00387   <span class="keywordflow">return</span> -1;
+<a name="l00388"></a>00388  cleanup:
+<a name="l00389"></a>00389 
+<a name="l00390"></a>00390   sinfo_free_table(&t);
+<a name="l00391"></a>00391   <span class="keywordflow">return</span> -1;
+<a name="l00392"></a>00392 
+<a name="l00393"></a>00393 
+<a name="l00394"></a>00394 }
+<a name="l00395"></a>00395 
+<a name="l00396"></a>00396 
+<a name="l00397"></a>00397 
+<a name="l00398"></a>00398 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00405"></a>00405 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00406"></a>00406 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00407"></a>00407 sinfo_utl_table_test_amoeba_poly(cpl_parameterlist   *   parlist, 
+<a name="l00408"></a>00408             cpl_frameset        *   framelist)
+<a name="l00409"></a>00409 {
+<a name="l00410"></a>00410 
+<a name="l00411"></a>00411   cpl_table* t=NULL;
+<a name="l00412"></a>00412   <span class="keywordtype">int</span> np=NPOINT;
+<a name="l00413"></a>00413   cpl_parameter* p=NULL;
+<a name="l00414"></a>00414   <span class="keyword">const</span> <span class="keywordtype">char</span>* op=NULL;
+<a name="l00415"></a>00415   <span class="keywordtype">double</span> ws=0;
+<a name="l00416"></a>00416   <span class="keywordtype">double</span> we=0;
+<a name="l00417"></a>00417   <span class="keywordtype">double</span> wd=0;
+<a name="l00418"></a>00418   <span class="keywordtype">double</span> wshift=0;
+<a name="l00419"></a>00419 
+<a name="l00420"></a>00420   <span class="keywordtype">double</span>* pw=NULL;
+<a name="l00421"></a>00421   <span class="keywordtype">double</span>* pi=NULL;
+<a name="l00422"></a>00422   <span class="keywordtype">double</span>* pf=NULL;
+<a name="l00423"></a>00423   <span class="keywordtype">int</span> i=0;
+<a name="l00424"></a>00424   <span class="keywordtype">int</span> j=0;
+<a name="l00425"></a>00425   <span class="keywordtype">double</span> a[3];
+<a name="l00426"></a>00426   <span class="keywordtype">double</span> p0[3];
+<a name="l00427"></a>00427 
+<a name="l00428"></a>00428   
+<a name="l00429"></a>00429   <span class="comment">// Amoeba fit:</span>
+<a name="l00430"></a>00430   <span class="keyword">const</span> <span class="keywordtype">int</span> MP=4;
+<a name="l00431"></a>00431   <span class="keyword">const</span> <span class="keywordtype">int</span> NP=3;
+<a name="l00432"></a>00432   <span class="keywordtype">double</span> y[MP];
+<a name="l00433"></a>00433   <span class="keywordtype">double</span>** ap=NULL;
+<a name="l00434"></a>00434   <span class="keywordtype">double</span> FTOL=2e-6;
+<a name="l00435"></a>00435   <span class="keywordtype">int</span> nfunc=0;
+<a name="l00436"></a>00436 
+<a name="l00437"></a>00437   check(sinfo_dfs_set_groups(framelist),
+<a name="l00438"></a>00438          <span class="stringliteral">"Cannot identify RAW and CALIB frames"</span>) ;
+<a name="l00439"></a>00439 
+<a name="l00440"></a>00440   <span class="comment">// read input parameters</span>
+<a name="l00441"></a>00441   check_nomsg(p=cpl_parameterlist_find(parlist, 
+<a name="l00442"></a>00442                 <span class="stringliteral">"sinfoni.sinfo_utl_table_test.method"</span>));
+<a name="l00443"></a>00443   check_nomsg(op=cpl_parameter_get_string(p));
+<a name="l00444"></a>00444 
+<a name="l00445"></a>00445 
+<a name="l00446"></a>00446   check_nomsg(p=cpl_parameterlist_find(parlist,
+<a name="l00447"></a>00447                 <span class="stringliteral">"sinfoni.sinfo_utl_table_test.wstart"</span>));
+<a name="l00448"></a>00448   check_nomsg(ws=cpl_parameter_get_double(p)) ;
+<a name="l00449"></a>00449 
+<a name="l00450"></a>00450 
+<a name="l00451"></a>00451   wd=(we-ws)/np;
+<a name="l00452"></a>00452   check_nomsg(p=cpl_parameterlist_find(parlist,
+<a name="l00453"></a>00453                 <span class="stringliteral">"sinfoni.sinfo_utl_table_test.wend"</span>));
+<a name="l00454"></a>00454   check_nomsg(we=cpl_parameter_get_double(p)) ;
+<a name="l00455"></a>00455 
+<a name="l00456"></a>00456   check_nomsg(p=cpl_parameterlist_find(parlist,
+<a name="l00457"></a>00457                 <span class="stringliteral">"sinfoni.sinfo_utl_table_test.wshift"</span>));
+<a name="l00458"></a>00458   check_nomsg(wshift=cpl_parameter_get_double(p)) ;
+<a name="l00459"></a>00459   
+<a name="l00460"></a>00460 
+<a name="l00461"></a>00461   <span class="comment">//Prepare a template function (polynomial)</span>
+<a name="l00462"></a>00462   check_nomsg(t=cpl_table_new(np));
+<a name="l00463"></a>00463   check_nomsg(cpl_table_new_column(t,<span class="stringliteral">"WAVE"</span>,CPL_TYPE_DOUBLE));
+<a name="l00464"></a>00464   check_nomsg(cpl_table_new_column(t,<span class="stringliteral">"INT"</span>,CPL_TYPE_DOUBLE));
+<a name="l00465"></a>00465   check_nomsg(cpl_table_fill_column_window(t,<span class="stringliteral">"WAVE"</span>,0,np,0));
+<a name="l00466"></a>00466   check_nomsg(cpl_table_fill_column_window(t,<span class="stringliteral">"INT"</span>,0,np,0));
+<a name="l00467"></a>00467 
+<a name="l00468"></a>00468   check_nomsg(pw=cpl_table_get_data_double(t,<span class="stringliteral">"WAVE"</span>));
+<a name="l00469"></a>00469   check_nomsg(pi=cpl_table_get_data_double(t,<span class="stringliteral">"INT"</span>));
+<a name="l00470"></a>00470   ws=-2.;
+<a name="l00471"></a>00471   we=+4.;
+<a name="l00472"></a>00472   a[0]=+1.;
+<a name="l00473"></a>00473   a[1]=-2.;
+<a name="l00474"></a>00474   a[2]=1.;
+<a name="l00475"></a>00475   wd=(we-ws)/np;
+<a name="l00476"></a>00476   <span class="keywordflow">for</span>(i=0;i<np;i++) {
+<a name="l00477"></a>00477     pw[i]=ws+i*wd;
+<a name="l00478"></a>00478     <span class="comment">//pi[i]=(pw[i]-a[0])*(pw[i]-a[0])+1.*rand()/RAND_MAX;</span>
+<a name="l00479"></a>00479     pi[i]=a[0]+a[1]*pw[i]+a[2]*pw[i]*pw[i]+1.*rand()/RAND_MAX;
+<a name="l00480"></a>00480   }
+<a name="l00481"></a>00481 
+<a name="l00482"></a>00482 
+<a name="l00483"></a>00483   sa_vx=cpl_vector_wrap(np,cpl_table_get_data_double(t,<span class="stringliteral">"WAVE"</span>));
+<a name="l00484"></a>00484   sa_vy=cpl_vector_wrap(np,cpl_table_get_data_double(t,<span class="stringliteral">"INT"</span>));
+<a name="l00485"></a>00485   <span class="comment">// Amoeba part</span>
+<a name="l00486"></a>00486   ap=(<span class="keywordtype">double</span>**) cpl_calloc(MP,<span class="keyword">sizeof</span>(<span class="keywordtype">double</span>*));
+<a name="l00487"></a>00487   <span class="keywordflow">for</span>(i=0;i<MP;i++) {
+<a name="l00488"></a>00488     ap[i]=cpl_calloc(NP,<span class="keyword">sizeof</span>(<span class="keywordtype">double</span>));
+<a name="l00489"></a>00489   }
+<a name="l00490"></a>00490 
+<a name="l00491"></a>00491   <span class="keywordflow">for</span>(i=0;i<MP;i++) {
+<a name="l00492"></a>00492     <span class="keywordflow">for</span>(j=0;j<NP;j++) {
+<a name="l00493"></a>00493       ap[i][j]=0;
+<a name="l00494"></a>00494     }
+<a name="l00495"></a>00495   }
+<a name="l00496"></a>00496   <span class="comment">//ap[0][0]=-5;</span>
+<a name="l00497"></a>00497   <span class="comment">//ap[1][0]=-2;</span>
+<a name="l00498"></a>00498 
+<a name="l00499"></a>00499   ap[0][0]=-3; ap[0][1]=-3; ap[0][2]=-3;
+<a name="l00500"></a>00500   ap[1][0]=+3; ap[1][1]=-3; ap[1][2]=-3;
+<a name="l00501"></a>00501   ap[2][0]=+3; ap[2][1]=+3; ap[2][2]=-3;
+<a name="l00502"></a>00502   ap[3][0]=+3; ap[3][1]=-3; ap[3][2]=+3;
+<a name="l00503"></a>00503 
+<a name="l00504"></a>00504   sinfo_msg(<span class="stringliteral">"Before amoeba fit"</span>);
+<a name="l00505"></a>00505   <span class="keywordflow">for</span>(i=0;i<MP;i++) {
+<a name="l00506"></a>00506     <span class="keywordflow">for</span>(j=0;j<NP;j++) {
+<a name="l00507"></a>00507       sinfo_msg(<span class="stringliteral">"ap[%d][%d]=%g"</span>,i,j,ap[i][j]);
+<a name="l00508"></a>00508     }
+<a name="l00509"></a>00509   }
+<a name="l00510"></a>00510 
+<a name="l00511"></a>00511   <span class="keywordflow">for</span>(i=0;i<MP;i++) {
+<a name="l00512"></a>00512     p0[0]=ap[i][0]; 
+<a name="l00513"></a>00513     p0[1]=ap[i][1]; 
+<a name="l00514"></a>00514     p0[2]=ap[i][2];
+<a name="l00515"></a>00515     y[i]=sinfo_fit_poly(p0);
+<a name="l00516"></a>00516   }
+<a name="l00517"></a>00517 
+<a name="l00518"></a>00518   sinfo_fit_amoeba(ap,y,NP,FTOL,sinfo_fit_poly,&nfunc);
+<a name="l00519"></a>00519 
+<a name="l00520"></a>00520   sinfo_msg(<span class="stringliteral">"After amoeba fit"</span>);
+<a name="l00521"></a>00521   <span class="keywordflow">for</span>(i=0;i<MP;i++) {
+<a name="l00522"></a>00522     <span class="keywordflow">for</span>(j=0;j<NP;j++) {
+<a name="l00523"></a>00523       sinfo_msg(<span class="stringliteral">"ap[%d][%d]=%g"</span>,i,j,ap[i][j]);
+<a name="l00524"></a>00524     }
+<a name="l00525"></a>00525   }
+<a name="l00526"></a>00526 
+<a name="l00527"></a>00527   check_nomsg(cpl_table_new_column(t,<span class="stringliteral">"FIT"</span>,CPL_TYPE_DOUBLE));
+<a name="l00528"></a>00528   check_nomsg(cpl_table_fill_column_window(t,<span class="stringliteral">"FIT"</span>,0,np,0));
+<a name="l00529"></a>00529   check_nomsg(pf=cpl_table_get_data_double(t,<span class="stringliteral">"FIT"</span>));
+<a name="l00530"></a>00530 
+<a name="l00531"></a>00531   wd=(we-ws)/np;
+<a name="l00532"></a>00532   <span class="keywordflow">for</span>(i=0;i<np;i++) {
+<a name="l00533"></a>00533     pw[i]=ws+i*wd;
+<a name="l00534"></a>00534     pf[i]=ap[0][0]+ap[0][1]*pw[i]+ap[0][2]*pw[i]*pw[i];
+<a name="l00535"></a>00535   }
+<a name="l00536"></a>00536 
+<a name="l00537"></a>00537   check_nomsg(cpl_table_save(t,NULL,NULL, <span class="stringliteral">"out_amoeba_poly.fits"</span>, 0));
+<a name="l00538"></a>00538   cpl_vector_unwrap(sa_vx);
+<a name="l00539"></a>00539   cpl_vector_unwrap(sa_vy);
+<a name="l00540"></a>00540 
+<a name="l00541"></a>00541   sinfo_free_table(&t);
+<a name="l00542"></a>00542   <span class="keywordflow">return</span> -1;
+<a name="l00543"></a>00543  cleanup:
+<a name="l00544"></a>00544   cpl_vector_unwrap(sa_vx);
+<a name="l00545"></a>00545   cpl_vector_unwrap(sa_vy);
+<a name="l00546"></a>00546 
+<a name="l00547"></a>00547   sinfo_free_table(&t);
+<a name="l00548"></a>00548   <span class="keywordflow">return</span> -1;
+<a name="l00549"></a>00549 
+<a name="l00550"></a>00550 
+<a name="l00551"></a>00551 }
+<a name="l00552"></a>00552 
+<a name="l00553"></a>00553 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00560"></a>00560 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00561"></a>00561 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00562"></a>00562 sinfo_utl_table_test_amoeba_boltzmann(cpl_parameterlist   *   parlist, 
+<a name="l00563"></a>00563                        cpl_frameset        *   framelist)
+<a name="l00564"></a>00564 {
+<a name="l00565"></a>00565 
+<a name="l00566"></a>00566   cpl_table* t=NULL;
+<a name="l00567"></a>00567   <span class="keywordtype">int</span> np=NPOINT;
+<a name="l00568"></a>00568   cpl_parameter* p=NULL;
+<a name="l00569"></a>00569   <span class="keyword">const</span> <span class="keywordtype">char</span>* op=NULL;
+<a name="l00570"></a>00570   <span class="keywordtype">double</span> ws=0;
+<a name="l00571"></a>00571   <span class="keywordtype">double</span> we=0;
+<a name="l00572"></a>00572   <span class="keywordtype">double</span> wd=0;
+<a name="l00573"></a>00573   <span class="keywordtype">double</span> wshift=0;
+<a name="l00574"></a>00574 
+<a name="l00575"></a>00575   <span class="keywordtype">double</span>* pw=NULL;
+<a name="l00576"></a>00576   <span class="keywordtype">double</span>* pi=NULL;
+<a name="l00577"></a>00577   <span class="keywordtype">double</span>* pf=NULL;
+<a name="l00578"></a>00578   <span class="keywordtype">int</span> i=0;
+<a name="l00579"></a>00579   <span class="keywordtype">int</span> j=0;
+<a name="l00580"></a>00580   <span class="keywordtype">double</span> a[3];
+<a name="l00581"></a>00581   <span class="keywordtype">double</span> p0[3];
+<a name="l00582"></a>00582 
+<a name="l00583"></a>00583   
+<a name="l00584"></a>00584   <span class="comment">// Amoeba fit:</span>
+<a name="l00585"></a>00585   <span class="keyword">const</span> <span class="keywordtype">int</span> MP=4;
+<a name="l00586"></a>00586   <span class="keyword">const</span> <span class="keywordtype">int</span> NP=3;
+<a name="l00587"></a>00587   <span class="keywordtype">double</span> y[MP];
+<a name="l00588"></a>00588   <span class="keywordtype">double</span>** ap=NULL;
+<a name="l00589"></a>00589   <span class="keywordtype">double</span> FTOL=2e-6;
+<a name="l00590"></a>00590   <span class="keywordtype">int</span> nfunc=0;
+<a name="l00591"></a>00591   <span class="keywordtype">double</span> max=0;
+<a name="l00592"></a>00592 
+<a name="l00593"></a>00593   <span class="keywordtype">double</span> bkg_min=0;
+<a name="l00594"></a>00594   <span class="keywordtype">double</span> bkg_max=0;
+<a name="l00595"></a>00595   <span class="keywordtype">double</span> p0_min=0;
+<a name="l00596"></a>00596   <span class="keywordtype">double</span> p0_max=0;
+<a name="l00597"></a>00597   <span class="keywordtype">double</span> p1_min=0;
+<a name="l00598"></a>00598   <span class="keywordtype">double</span> p1_max=0;
+<a name="l00599"></a>00599   <span class="keywordtype">double</span> p2_min=0;
+<a name="l00600"></a>00600   <span class="keywordtype">double</span> p2_max=0;
+<a name="l00601"></a>00601 
+<a name="l00602"></a>00602 
+<a name="l00603"></a>00603   check(sinfo_dfs_set_groups(framelist),
+<a name="l00604"></a>00604          <span class="stringliteral">"Cannot identify RAW and CALIB frames"</span>) ;
+<a name="l00605"></a>00605 
+<a name="l00606"></a>00606   <span class="comment">// read input parameters</span>
+<a name="l00607"></a>00607   check_nomsg(p=cpl_parameterlist_find(parlist, 
+<a name="l00608"></a>00608                 <span class="stringliteral">"sinfoni.sinfo_utl_table_test.method"</span>));
+<a name="l00609"></a>00609   check_nomsg(op=cpl_parameter_get_string(p));
+<a name="l00610"></a>00610 
+<a name="l00611"></a>00611 
+<a name="l00612"></a>00612   check_nomsg(p=cpl_parameterlist_find(parlist,
+<a name="l00613"></a>00613                 <span class="stringliteral">"sinfoni.sinfo_utl_table_test.wstart"</span>));
+<a name="l00614"></a>00614   check_nomsg(ws=cpl_parameter_get_double(p)) ;
+<a name="l00615"></a>00615 
+<a name="l00616"></a>00616 
+<a name="l00617"></a>00617   wd=(we-ws)/np;
+<a name="l00618"></a>00618   check_nomsg(p=cpl_parameterlist_find(parlist,
+<a name="l00619"></a>00619                 <span class="stringliteral">"sinfoni.sinfo_utl_table_test.wend"</span>));
+<a name="l00620"></a>00620   check_nomsg(we=cpl_parameter_get_double(p)) ;
+<a name="l00621"></a>00621 
+<a name="l00622"></a>00622   check_nomsg(p=cpl_parameterlist_find(parlist,
+<a name="l00623"></a>00623                 <span class="stringliteral">"sinfoni.sinfo_utl_table_test.wshift"</span>));
+<a name="l00624"></a>00624   check_nomsg(wshift=cpl_parameter_get_double(p)) ;
+<a name="l00625"></a>00625   
+<a name="l00626"></a>00626 
+<a name="l00627"></a>00627   <span class="comment">//Prepare a template function (polynomial)</span>
+<a name="l00628"></a>00628   check_nomsg(t=cpl_table_new(np));
+<a name="l00629"></a>00629   check_nomsg(cpl_table_new_column(t,<span class="stringliteral">"WAVE"</span>,CPL_TYPE_DOUBLE));
+<a name="l00630"></a>00630   check_nomsg(cpl_table_new_column(t,<span class="stringliteral">"INT"</span>,CPL_TYPE_DOUBLE));
+<a name="l00631"></a>00631   check_nomsg(cpl_table_fill_column_window(t,<span class="stringliteral">"WAVE"</span>,0,np,0));
+<a name="l00632"></a>00632   check_nomsg(cpl_table_fill_column_window(t,<span class="stringliteral">"INT"</span>,0,np,0));
+<a name="l00633"></a>00633 
+<a name="l00634"></a>00634   check_nomsg(pw=cpl_table_get_data_double(t,<span class="stringliteral">"WAVE"</span>));
+<a name="l00635"></a>00635   check_nomsg(pi=cpl_table_get_data_double(t,<span class="stringliteral">"INT"</span>));
+<a name="l00636"></a>00636   ws=1.4;
+<a name="l00637"></a>00637   we=2.5;
+<a name="l00638"></a>00638   wd=(we-ws)/np;
+<a name="l00639"></a>00639   a[2]=280;
+<a name="l00640"></a>00640   a[1]=55.817665;
+<a name="l00641"></a>00641   a[0]=548.77802;
+<a name="l00642"></a>00642   <span class="keywordflow">for</span>(i=0;i<np;i++) {
+<a name="l00643"></a>00643     pw[i]=ws+i*wd;
+<a name="l00644"></a>00644     pi[i]=sinfo_fac(pw[i],a[2])*(1.+0.1*rand()/RAND_MAX);
+<a name="l00645"></a>00645   }
+<a name="l00646"></a>00646   check_nomsg(max=cpl_table_get_column_max(t,<span class="stringliteral">"INT"</span>));
+<a name="l00647"></a>00647   check_nomsg(cpl_table_duplicate_column(t,<span class="stringliteral">"THERMAL"</span>,t,<span class="stringliteral">"INT"</span>));
+<a name="l00648"></a>00648   check_nomsg(cpl_table_divide_scalar(t,<span class="stringliteral">"THERMAL"</span>,max));
+<a name="l00649"></a>00649   check_nomsg(cpl_table_multiply_scalar(t,<span class="stringliteral">"THERMAL"</span>,a[1]));
+<a name="l00650"></a>00650   check_nomsg(cpl_table_add_scalar(t,<span class="stringliteral">"THERMAL"</span>,a[0]));
+<a name="l00651"></a>00651 
+<a name="l00652"></a>00652   check_nomsg(sa_vx=cpl_vector_wrap(np,cpl_table_get_data_double(t,<span class="stringliteral">"WAVE"</span>)));
+<a name="l00653"></a>00653   check_nomsg(sa_vy=cpl_vector_wrap(np,cpl_table_get_data_double(t,<span class="stringliteral">"THERMAL"</span>)));
+<a name="l00654"></a>00654   <span class="comment">// Amoeba part</span>
+<a name="l00655"></a>00655   ap=(<span class="keywordtype">double</span>**) cpl_calloc(MP,<span class="keyword">sizeof</span>(<span class="keywordtype">double</span>*));
+<a name="l00656"></a>00656   <span class="keywordflow">for</span>(i=0;i<MP;i++) {
+<a name="l00657"></a>00657     ap[i]=cpl_calloc(NP,<span class="keyword">sizeof</span>(<span class="keywordtype">double</span>));
+<a name="l00658"></a>00658   }
+<a name="l00659"></a>00659 
+<a name="l00660"></a>00660   <span class="keywordflow">for</span>(i=0;i<MP;i++) {
+<a name="l00661"></a>00661     <span class="keywordflow">for</span>(j=0;j<NP;j++) {
+<a name="l00662"></a>00662       ap[i][j]=0;
+<a name="l00663"></a>00663     }
+<a name="l00664"></a>00664   }
+<a name="l00665"></a>00665   <span class="comment">//ap[0][0]=-5;</span>
+<a name="l00666"></a>00666   <span class="comment">//ap[1][0]=-2;</span>
+<a name="l00667"></a>00667   bkg_min=cpl_table_get_column_min(t,<span class="stringliteral">"THERMAL"</span>);
+<a name="l00668"></a>00668   bkg_max=cpl_table_get_column_max(t,<span class="stringliteral">"THERMAL"</span>);
+<a name="l00669"></a>00669 
+<a name="l00670"></a>00670   p0_min=bkg_min/2;
+<a name="l00671"></a>00671   p0_max=bkg_min*2;
+<a name="l00672"></a>00672   p1_min=bkg_min/2.;
+<a name="l00673"></a>00673   p1_max=bkg_max*2;
+<a name="l00674"></a>00674   p1_min=200;
+<a name="l00675"></a>00675   p2_max=300;
+<a name="l00676"></a>00676 
+<a name="l00677"></a>00677   ap[0][0]=p0_min; ap[0][1]=p1_min; ap[0][2]=p2_min;
+<a name="l00678"></a>00678   ap[1][0]=p0_max; ap[1][1]=p1_min; ap[1][2]=p2_min;
+<a name="l00679"></a>00679   ap[2][0]=p0_min; ap[2][1]=p1_max; ap[2][2]=p2_min;
+<a name="l00680"></a>00680   ap[3][0]=p0_min; ap[3][1]=p1_min; ap[3][2]=p2_max;
+<a name="l00681"></a>00681 
+<a name="l00682"></a>00682   sinfo_msg(<span class="stringliteral">"Before amoeba fit"</span>);
+<a name="l00683"></a>00683   <span class="keywordflow">for</span>(i=0;i<MP;i++) {
+<a name="l00684"></a>00684     <span class="keywordflow">for</span>(j=0;j<NP;j++) {
+<a name="l00685"></a>00685       sinfo_msg(<span class="stringliteral">"ap[%d][%d]=%g"</span>,i,j,ap[i][j]);
+<a name="l00686"></a>00686     }
+<a name="l00687"></a>00687   }
+<a name="l00688"></a>00688 
+<a name="l00689"></a>00689   <span class="keywordflow">for</span>(i=0;i<MP;i++) {
+<a name="l00690"></a>00690     p0[0]=ap[i][0]; 
+<a name="l00691"></a>00691     p0[1]=ap[i][1]; 
+<a name="l00692"></a>00692     p0[2]=ap[i][2];
+<a name="l00693"></a>00693     y[i]=sinfo_fit_boltzmann(p0);
+<a name="l00694"></a>00694   }
+<a name="l00695"></a>00695 
+<a name="l00696"></a>00696   sinfo_fit_amoeba(ap,y,NP,FTOL,sinfo_fit_boltzmann,&nfunc);
+<a name="l00697"></a>00697 
+<a name="l00698"></a>00698   sinfo_msg(<span class="stringliteral">"After amoeba fit"</span>);
+<a name="l00699"></a>00699   <span class="keywordflow">for</span>(i=0;i<MP;i++) {
+<a name="l00700"></a>00700     <span class="keywordflow">for</span>(j=0;j<NP;j++) {
+<a name="l00701"></a>00701       sinfo_msg(<span class="stringliteral">"ap[%d][%d]=%g"</span>,i,j,ap[i][j]);
+<a name="l00702"></a>00702     }
+<a name="l00703"></a>00703   }
+<a name="l00704"></a>00704 
+<a name="l00705"></a>00705   check_nomsg(cpl_table_new_column(t,<span class="stringliteral">"FIT"</span>,CPL_TYPE_DOUBLE));
+<a name="l00706"></a>00706   check_nomsg(cpl_table_fill_column_window(t,<span class="stringliteral">"FIT"</span>,0,np,0));
+<a name="l00707"></a>00707   check_nomsg(pf=cpl_table_get_data_double(t,<span class="stringliteral">"FIT"</span>));
+<a name="l00708"></a>00708 
+<a name="l00709"></a>00709   wd=(we-ws)/np;
+<a name="l00710"></a>00710   <span class="keywordflow">for</span>(i=0;i<np;i++) {
+<a name="l00711"></a>00711     pw[i]=ws+i*wd;
+<a name="l00712"></a>00712     pf[i]=sinfo_fac(pw[i],ap[0][2]);
+<a name="l00713"></a>00713   }
+<a name="l00714"></a>00714   check_nomsg(max=cpl_table_get_column_max(t,<span class="stringliteral">"FIT"</span>));
+<a name="l00715"></a>00715   check_nomsg(cpl_table_divide_scalar(t,<span class="stringliteral">"FIT"</span>,max));
+<a name="l00716"></a>00716   check_nomsg(cpl_table_multiply_scalar(t,<span class="stringliteral">"FIT"</span>,ap[0][1]));
+<a name="l00717"></a>00717   check_nomsg(cpl_table_add_scalar(t,<span class="stringliteral">"FIT"</span>,ap[0][0]));
+<a name="l00718"></a>00718 
+<a name="l00719"></a>00719   check_nomsg(cpl_table_save(t,NULL,NULL, <span class="stringliteral">"out_amoeba_boltzmann.fits"</span>, 0));
+<a name="l00720"></a>00720 
+<a name="l00721"></a>00721 
+<a name="l00722"></a>00722  cleanup:
+<a name="l00723"></a>00723 
+<a name="l00724"></a>00724   cpl_vector_unwrap(sa_vx);
+<a name="l00725"></a>00725   cpl_vector_unwrap(sa_vy);
+<a name="l00726"></a>00726   sinfo_free_table(&t);
+<a name="l00727"></a>00727 
+<a name="l00728"></a>00728   <span class="keywordflow">if</span> (cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l00729"></a>00729     <span class="keywordflow">return</span> -1;
+<a name="l00730"></a>00730   } <span class="keywordflow">else</span> {
+<a name="l00731"></a>00731     <span class="keywordflow">return</span> 0;
+<a name="l00732"></a>00732   }
+<a name="l00733"></a>00733 
+<a name="l00734"></a>00734 
+<a name="l00735"></a>00735 
+<a name="l00736"></a>00736 }
+<a name="l00737"></a>00737 
+<a name="l00738"></a>00738 
+<a name="l00739"></a>00739 <span class="keyword">static</span> cpl_table*
+<a name="l00740"></a>00740 sinfo_table_shift_column_int(<span class="keyword">const</span> cpl_table* t, 
+<a name="l00741"></a>00741                              <span class="keyword">const</span> <span class="keywordtype">char</span>* col, 
+<a name="l00742"></a>00742                              <span class="keyword">const</span> <span class="keywordtype">double</span> s, 
+<a name="l00743"></a>00743                                    <span class="keywordtype">double</span>* r)
+<a name="l00744"></a>00744 {
+<a name="l00745"></a>00745   cpl_table* out=NULL;
+<a name="l00746"></a>00746   <span class="keywordtype">int</span> is=(int)s;
+<a name="l00747"></a>00747   <span class="keywordtype">int</span> nrow=0;
+<a name="l00748"></a>00748   <span class="keywordtype">int</span> i=0;
+<a name="l00749"></a>00749 
+<a name="l00750"></a>00750   <span class="keywordtype">double</span>* pi=NULL;
+<a name="l00751"></a>00751   <span class="keywordtype">double</span>* po=NULL;
+<a name="l00752"></a>00752 
+<a name="l00753"></a>00753   cknull(t,<span class="stringliteral">"null input table"</span>);
+<a name="l00754"></a>00754   out=cpl_table_duplicate(t);
+<a name="l00755"></a>00755   *r=s-is;
+<a name="l00756"></a>00756   nrow=cpl_table_get_nrow(t);
+<a name="l00757"></a>00757   pi=cpl_table_get_data_double(t,col);
+<a name="l00758"></a>00758   po=cpl_table_get_data_double(out,col);
+<a name="l00759"></a>00759   sinfo_msg(<span class="stringliteral">"shifting of  %d pixels"</span>,is);
+<a name="l00760"></a>00760   <span class="keywordflow">if</span>(is > 0 ) {
+<a name="l00761"></a>00761     <span class="keywordflow">for</span>(i=0;i<nrow;i++) {
+<a name="l00762"></a>00762       <span class="keywordflow">if</span>( ((i-is) >=0) && ((i-is) < nrow)) {
+<a name="l00763"></a>00763     po[i-is]=pi[i];
+<a name="l00764"></a>00764       }
+<a name="l00765"></a>00765     }
+<a name="l00766"></a>00766   } <span class="keywordflow">else</span> {
+<a name="l00767"></a>00767     <span class="keywordflow">for</span>(i=nrow-1;i>-1;i--) {
+<a name="l00768"></a>00768       <span class="keywordflow">if</span>( ((i-is) >=0) && ((i-is) < nrow)) {
+<a name="l00769"></a>00769     po[i-is]=pi[i];
+<a name="l00770"></a>00770       }
+<a name="l00771"></a>00771     }
+<a name="l00772"></a>00772   }
+<a name="l00773"></a>00773   <span class="keywordflow">return</span> out;
+<a name="l00774"></a>00774  cleanup:
+<a name="l00775"></a>00775   sinfo_free_table(&out);
+<a name="l00776"></a>00776   <span class="keywordflow">return</span> NULL;
+<a name="l00777"></a>00777 
+<a name="l00778"></a>00778 }
+<a name="l00779"></a>00779 
+<a name="l00780"></a>00780 
+<a name="l00781"></a>00781 
+<a name="l00782"></a>00782 <span class="keyword">static</span> cpl_table*
+<a name="l00783"></a>00783 sinfo_table_shift_column_poly(cpl_table* t, 
+<a name="l00784"></a>00784                               <span class="keyword">const</span> <span class="keywordtype">char</span>* col, 
+<a name="l00785"></a>00785                               <span class="keyword">const</span> <span class="keywordtype">double</span> shift,
+<a name="l00786"></a>00786                               <span class="keyword">const</span> <span class="keywordtype">int</span> order)
+<a name="l00787"></a>00787 {
+<a name="l00788"></a>00788   cpl_table* out=NULL;
+<a name="l00789"></a>00789   <span class="keywordtype">int</span> nrow=0;
+<a name="l00790"></a>00790   <span class="keywordtype">int</span> i=0;
+<a name="l00791"></a>00791   <span class="keywordtype">int</span> flag=0;
+<a name="l00792"></a>00792   <span class="keywordtype">int</span> n_points=0;
+<a name="l00793"></a>00793   <span class="keywordtype">int</span> firstpos=0;
+<a name="l00794"></a>00794   <span class="keywordtype">int</span> z=0;
+<a name="l00795"></a>00795   <span class="keywordtype">float</span> eval=0;
+<a name="l00796"></a>00796   <span class="keywordtype">float</span> sum=0;
+<a name="l00797"></a>00797   <span class="keywordtype">float</span> new_sum=0;
+<a name="l00798"></a>00798   <span class="keywordtype">float</span>* pi=NULL;
+<a name="l00799"></a>00799   <span class="keywordtype">float</span>* po=NULL;
+<a name="l00800"></a>00800   <span class="keywordtype">float</span>* spec=NULL ;
+<a name="l00801"></a>00801   <span class="keywordtype">float</span>* corrected_spec=NULL ;
+<a name="l00802"></a>00802   <span class="keywordtype">float</span>* xnum=NULL ;
+<a name="l00803"></a>00803   <span class="keywordtype">float</span>* tableptr=NULL;
+<a name="l00804"></a>00804 
+<a name="l00805"></a>00805   cknull(t,<span class="stringliteral">"null input table"</span>);
+<a name="l00806"></a>00806   <span class="keywordflow">if</span> ( order <= 0 ) {
+<a name="l00807"></a>00807     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"wrong order of interpolation polynom given!"</span>) ;
+<a name="l00808"></a>00808     <span class="keywordflow">goto</span> cleanup;
+<a name="l00809"></a>00809   }
+<a name="l00810"></a>00810 
+<a name="l00811"></a>00811   out=cpl_table_duplicate(t);
+<a name="l00812"></a>00812 
+<a name="l00813"></a>00813   nrow=cpl_table_get_nrow(t);
+<a name="l00814"></a>00814   cpl_table_cast_column(t,col,<span class="stringliteral">"FINT"</span>,CPL_TYPE_FLOAT);
+<a name="l00815"></a>00815   cpl_table_cast_column(out,col,<span class="stringliteral">"FINT"</span>,CPL_TYPE_FLOAT);
+<a name="l00816"></a>00816   pi=cpl_table_get_data_float(t,<span class="stringliteral">"FINT"</span>);
+<a name="l00817"></a>00817   po=cpl_table_get_data_float(out,<span class="stringliteral">"FINT"</span>);
+<a name="l00818"></a>00818 
+<a name="l00819"></a>00819   n_points = order + 1 ;
+<a name="l00820"></a>00820   <span class="keywordflow">if</span> ( n_points % 2 == 0 ) {
+<a name="l00821"></a>00821     firstpos = (int)(n_points/2) - 1 ;
+<a name="l00822"></a>00822   } <span class="keywordflow">else</span> {
+<a name="l00823"></a>00823     firstpos = (int)(n_points/2) ;
+<a name="l00824"></a>00824   }
+<a name="l00825"></a>00825   spec=cpl_calloc(nrow,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l00826"></a>00826   corrected_spec=cpl_calloc(nrow,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l00827"></a>00827   xnum=cpl_calloc(order+1,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l00828"></a>00828   <span class="comment">/* fill the xa[] array for the polint function */</span>
+<a name="l00829"></a>00829   <span class="keywordflow">for</span> ( i = 0 ; i < n_points ; i++ ) {
+<a name="l00830"></a>00830     xnum[i] = i ;
+<a name="l00831"></a>00831   }
+<a name="l00832"></a>00832 
+<a name="l00833"></a>00833 
+<a name="l00834"></a>00834   <span class="keywordflow">for</span>(i=0;i<nrow;i++) {
+<a name="l00835"></a>00835     corrected_spec[i] = 0. ;
+<a name="l00836"></a>00836   }
+<a name="l00837"></a>00837 
+<a name="l00838"></a>00838   sum = 0. ;
+<a name="l00839"></a>00839   <span class="keywordflow">for</span> ( z = 0 ; z < nrow ; z++ ) {
+<a name="l00840"></a>00840     spec[z] = pi[z] ;
+<a name="l00841"></a>00841     <span class="keywordflow">if</span> (isnan(spec[z]) ) {
+<a name="l00842"></a>00842       spec[z] = 0. ;
+<a name="l00843"></a>00843                   
+<a name="l00844"></a>00844       <span class="keywordflow">for</span> ( i = z - firstpos ; i < z-firstpos+n_points ; i++ ) {
+<a name="l00845"></a>00845     <span class="keywordflow">if</span> ( i < 0 ) continue ;
+<a name="l00846"></a>00846     <span class="keywordflow">if</span> ( i >= nrow) continue  ;
+<a name="l00847"></a>00847     corrected_spec[i] = ZERO ;
+<a name="l00848"></a>00848       }
+<a name="l00849"></a>00849     }
+<a name="l00850"></a>00850     <span class="keywordflow">if</span> ( z != 0 && z != nrow - 1 ) {
+<a name="l00851"></a>00851       sum += spec[z] ;
+<a name="l00852"></a>00852     }
+<a name="l00853"></a>00853   }
+<a name="l00854"></a>00854 
+<a name="l00855"></a>00855   new_sum = 0. ;
+<a name="l00856"></a>00856   <span class="keywordflow">for</span> ( z = 0 ; z < nrow ; z++ ) {
+<a name="l00857"></a>00857     <span class="comment">/* ---------------------------------------------------------------</span>
+<a name="l00858"></a>00858 <span class="comment">     * now determine the arrays of size n_points with which the</span>
+<a name="l00859"></a>00859 <span class="comment">     * polynom is determined and determine the position eval</span>
+<a name="l00860"></a>00860 <span class="comment">     * where the polynom is evaluated in polynomial interpolation.</span>
+<a name="l00861"></a>00861 <span class="comment">     * Take care of the points near the row edges!</span>
+<a name="l00862"></a>00862 <span class="comment">     */</span>
+<a name="l00863"></a>00863     <span class="keywordflow">if</span> (isnan(corrected_spec[z])) continue ;
+<a name="l00864"></a>00864     <span class="keywordflow">if</span> ( z - firstpos < 0 ) {
+<a name="l00865"></a>00865       tableptr = &spec[0] ;
+<a name="l00866"></a>00866       eval     = shift + z ;
+<a name="l00867"></a>00867     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( z - firstpos + n_points >= nrow ) {
+<a name="l00868"></a>00868       tableptr = &spec[nrow - n_points] ;
+<a name="l00869"></a>00869       eval     = shift + z + n_points - nrow ;
+<a name="l00870"></a>00870     } <span class="keywordflow">else</span> {
+<a name="l00871"></a>00871       tableptr = &spec[z-firstpos] ;
+<a name="l00872"></a>00872       eval     = shift + firstpos ;
+<a name="l00873"></a>00873     }
+<a name="l00874"></a>00874 
+<a name="l00875"></a>00875     flag=0;
+<a name="l00876"></a>00876     corrected_spec[z]=sinfo_new_nev_ille(xnum,tableptr,order,eval,&flag);
+<a name="l00877"></a>00877     <span class="keywordflow">if</span> ( z != 0 && z != nrow - 1 ) {
+<a name="l00878"></a>00878       new_sum += corrected_spec[z] ;
+<a name="l00879"></a>00879     }
+<a name="l00880"></a>00880   }
+<a name="l00881"></a>00881 
+<a name="l00882"></a>00882   <span class="comment">/* fill the output spectrum */</span>
+<a name="l00883"></a>00883   <span class="keywordflow">for</span> (z = 0 ; z < nrow ; z++ ) {
+<a name="l00884"></a>00884     <span class="keywordflow">if</span> ( new_sum == 0. ) {
+<a name="l00885"></a>00885       new_sum = 1. ;
+<a name="l00886"></a>00886     }
+<a name="l00887"></a>00887     <span class="keywordflow">if</span> ( z == 0 ) {
+<a name="l00888"></a>00888       po[z] = ZERO ;
+<a name="l00889"></a>00889     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( z == nrow - 1 ) {
+<a name="l00890"></a>00890       po[z] = ZERO ;
+<a name="l00891"></a>00891     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( isnan(corrected_spec[z]) ) {
+<a name="l00892"></a>00892       po[z] = ZERO ;
+<a name="l00893"></a>00893     } <span class="keywordflow">else</span> {
+<a name="l00894"></a>00894       corrected_spec[z] *= sum / new_sum ;
+<a name="l00895"></a>00895       po[z] = corrected_spec[z] ;
+<a name="l00896"></a>00896     }
+<a name="l00897"></a>00897   }
+<a name="l00898"></a>00898   check_nomsg(cpl_table_erase_column(t,<span class="stringliteral">"FINT"</span>));
+<a name="l00899"></a>00899   check_nomsg(cpl_table_erase_column(out,col));
+<a name="l00900"></a>00900   check_nomsg(cpl_table_cast_column(out,<span class="stringliteral">"FINT"</span>,col,CPL_TYPE_DOUBLE));
+<a name="l00901"></a>00901   check_nomsg(cpl_table_erase_column(out,<span class="stringliteral">"FINT"</span>));
+<a name="l00902"></a>00902 
+<a name="l00903"></a>00903   sinfo_free_float(&spec) ;
+<a name="l00904"></a>00904   sinfo_free_float(&corrected_spec) ;
+<a name="l00905"></a>00905   sinfo_free_float(&xnum) ;
+<a name="l00906"></a>00906 
+<a name="l00907"></a>00907   <span class="keywordflow">return</span> out;
+<a name="l00908"></a>00908  cleanup:
+<a name="l00909"></a>00909 
+<a name="l00910"></a>00910 
+<a name="l00911"></a>00911   sinfo_free_float(&spec) ;
+<a name="l00912"></a>00912   sinfo_free_float(&corrected_spec) ;
+<a name="l00913"></a>00913   sinfo_free_float(&xnum) ;
+<a name="l00914"></a>00914   sinfo_free_table(&out);
+<a name="l00915"></a>00915   <span class="keywordflow">return</span> NULL;
+<a name="l00916"></a>00916 
+<a name="l00917"></a>00917 
+<a name="l00918"></a>00918 }
+<a name="l00919"></a>00919 
+<a name="l00920"></a>00920 
+<a name="l00921"></a>00921 
+<a name="l00922"></a>00922 
+<a name="l00923"></a>00923 <span class="keyword">static</span> cpl_table*
+<a name="l00924"></a>00924 sinfo_table_shift_column_spline3(cpl_table* t, 
+<a name="l00925"></a>00925                                  <span class="keyword">const</span> <span class="keywordtype">char</span>* col, 
+<a name="l00926"></a>00926                                  <span class="keyword">const</span> <span class="keywordtype">double</span> shift)
+<a name="l00927"></a>00927 {
+<a name="l00928"></a>00928   cpl_table* out=NULL;
+<a name="l00929"></a>00929   <span class="keywordtype">int</span> nrow=0;
+<a name="l00930"></a>00930   <span class="keywordtype">int</span> i=0;
+<a name="l00931"></a>00931   <span class="keywordtype">int</span> z=0;
+<a name="l00932"></a>00932 
+<a name="l00933"></a>00933   <span class="keywordtype">float</span> sum=0;
+<a name="l00934"></a>00934   <span class="keywordtype">float</span> new_sum=0;
+<a name="l00935"></a>00935 
+<a name="l00936"></a>00936   <span class="keywordtype">float</span>* pi=NULL;
+<a name="l00937"></a>00937   <span class="keywordtype">float</span>* po=NULL;
+<a name="l00938"></a>00938   <span class="keywordtype">float</span>* eval=NULL;
+<a name="l00939"></a>00939   <span class="keywordtype">float</span>* xnum=NULL;
+<a name="l00940"></a>00940   <span class="keywordtype">float</span>* spec=NULL;
+<a name="l00941"></a>00941   <span class="keywordtype">float</span>* corrected_spec=NULL;
+<a name="l00942"></a>00942 
+<a name="l00943"></a>00943   cknull(t,<span class="stringliteral">"null input table"</span>);
+<a name="l00944"></a>00944   out=cpl_table_duplicate(t);
+<a name="l00945"></a>00945 
+<a name="l00946"></a>00946   nrow=cpl_table_get_nrow(t);
+<a name="l00947"></a>00947   check_nomsg(cpl_table_cast_column(t,col,<span class="stringliteral">"FINT"</span>,CPL_TYPE_FLOAT));
+<a name="l00948"></a>00948   check_nomsg(cpl_table_cast_column(out,col,<span class="stringliteral">"FINT"</span>,CPL_TYPE_FLOAT));
+<a name="l00949"></a>00949   pi=cpl_table_get_data_float(t,<span class="stringliteral">"FINT"</span>);
+<a name="l00950"></a>00950   po=cpl_table_get_data_float(out,<span class="stringliteral">"FINT"</span>);
+<a name="l00951"></a>00951   
+<a name="l00952"></a>00952 
+<a name="l00953"></a>00953 
+<a name="l00954"></a>00954   xnum=cpl_calloc(nrow,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l00955"></a>00955   <span class="comment">/* fill the xa[] array for the spline function */</span>
+<a name="l00956"></a>00956   <span class="keywordflow">for</span> ( i = 0 ; i < nrow ; i++ ) {
+<a name="l00957"></a>00957     xnum[i] = i ;
+<a name="l00958"></a>00958   }
+<a name="l00959"></a>00959 
+<a name="l00960"></a>00960   spec=cpl_calloc(nrow,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l00961"></a>00961   corrected_spec=cpl_calloc(nrow,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l00962"></a>00962   eval=cpl_calloc(nrow,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l00963"></a>00963 
+<a name="l00964"></a>00964   sum = 0. ;
+<a name="l00965"></a>00965   <span class="keywordflow">for</span> ( z = 0 ; z < nrow ; z++ ) {
+<a name="l00966"></a>00966     spec[z] = pi[z] ;
+<a name="l00967"></a>00967     <span class="keywordflow">if</span> (isnan(spec[z]) ) {
+<a name="l00968"></a>00968       <span class="keywordflow">for</span> ( i = z-1 ; i <= z+1 ; i++ ) {
+<a name="l00969"></a>00969     <span class="keywordflow">if</span> ( i < 0 ) continue ;
+<a name="l00970"></a>00970     <span class="keywordflow">if</span> ( i >= nrow) continue ;
+<a name="l00971"></a>00971     corrected_spec[i] = ZERO ;
+<a name="l00972"></a>00972       }
+<a name="l00973"></a>00973       spec[z] = 0. ;
+<a name="l00974"></a>00974     }
+<a name="l00975"></a>00975     sum += spec[z] ;
+<a name="l00976"></a>00976     eval[z] = (float)shift+(<span class="keywordtype">float</span>)z ;
+<a name="l00977"></a>00977   }
+<a name="l00978"></a>00978   <span class="comment">/* now we do the spline interpolation*/</span>
+<a name="l00979"></a>00979   <span class="keywordflow">if</span> ( -1 == sinfo_function1d_natural_spline(xnum,spec, nrow, 
+<a name="l00980"></a>00980                                              eval,corrected_spec, nrow))
+<a name="l00981"></a>00981     {
+<a name="l00982"></a>00982       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"error in spline interpolation!"</span>) ;
+<a name="l00983"></a>00983       <span class="keywordflow">goto</span> cleanup;
+<a name="l00984"></a>00984     }
+<a name="l00985"></a>00985         
+<a name="l00986"></a>00986   new_sum = 0. ;
+<a name="l00987"></a>00987   <span class="keywordflow">for</span> ( z = 0 ; z < nrow ; z++ ) {
+<a name="l00988"></a>00988     <span class="keywordflow">if</span> ( isnan(corrected_spec[z]) ) {
+<a name="l00989"></a>00989       continue ;
+<a name="l00990"></a>00990     }
+<a name="l00991"></a>00991     new_sum += corrected_spec[z] ;
+<a name="l00992"></a>00992   }
+<a name="l00993"></a>00993   <span class="comment">/* fill output imagelist */</span>
+<a name="l00994"></a>00994   <span class="keywordflow">for</span> ( z = 0 ; z < nrow ; z++ ) {
+<a name="l00995"></a>00995     <span class="keywordflow">if</span> ( new_sum == 0. ) new_sum =1. ; 
+<a name="l00996"></a>00996     {
+<a name="l00997"></a>00997       <span class="keywordflow">if</span> ( isnan(corrected_spec[z]) ) {
+<a name="l00998"></a>00998     po[z] = ZERO ;
+<a name="l00999"></a>00999       } <span class="keywordflow">else</span> {
+<a name="l01000"></a>01000     corrected_spec[z] *= sum / new_sum ;
+<a name="l01001"></a>01001     po[z] = corrected_spec[z] ;
+<a name="l01002"></a>01002       }
+<a name="l01003"></a>01003     }
+<a name="l01004"></a>01004   }
+<a name="l01005"></a>01005 
+<a name="l01006"></a>01006   sinfo_free_float(&xnum);
+<a name="l01007"></a>01007   sinfo_free_float(&spec) ;
+<a name="l01008"></a>01008   sinfo_free_float(&corrected_spec) ;
+<a name="l01009"></a>01009   sinfo_free_float(&eval) ;
+<a name="l01010"></a>01010 
+<a name="l01011"></a>01011   check_nomsg(cpl_table_erase_column(t,<span class="stringliteral">"FINT"</span>));
+<a name="l01012"></a>01012   check_nomsg(cpl_table_erase_column(out,col));
+<a name="l01013"></a>01013   check_nomsg(cpl_table_cast_column(out,<span class="stringliteral">"FINT"</span>,col,CPL_TYPE_DOUBLE));
+<a name="l01014"></a>01014   check_nomsg(cpl_table_erase_column(out,<span class="stringliteral">"FINT"</span>));
+<a name="l01015"></a>01015 
+<a name="l01016"></a>01016   <span class="keywordflow">return</span> out;
+<a name="l01017"></a>01017  cleanup:
+<a name="l01018"></a>01018 
+<a name="l01019"></a>01019   sinfo_free_float(&xnum);
+<a name="l01020"></a>01020   sinfo_free_float(&spec) ;
+<a name="l01021"></a>01021   sinfo_free_float(&corrected_spec) ;
+<a name="l01022"></a>01022   sinfo_free_float(&eval) ;
+<a name="l01023"></a>01023   sinfo_free_table(&out);
+<a name="l01024"></a>01024   <span class="keywordflow">return</span> NULL;
+<a name="l01025"></a>01025 
+<a name="l01026"></a>01026 
+<a name="l01027"></a>01027 }
+<a name="l01028"></a>01028 
+<a name="l01029"></a>01029 
+<a name="l01030"></a>01030 <span class="keyword">static</span> cpl_table*
+<a name="l01031"></a>01031 sinfo_table_shift_simple(cpl_table* inp, 
+<a name="l01032"></a>01032                          <span class="keyword">const</span> <span class="keywordtype">char</span>* col, 
+<a name="l01033"></a>01033                          <span class="keyword">const</span> <span class="keywordtype">double</span> shift)
+<a name="l01034"></a>01034 {
+<a name="l01035"></a>01035 
+<a name="l01036"></a>01036   <span class="keywordtype">int</span> nrow=0;
+<a name="l01037"></a>01037   cpl_table* out=NULL;
+<a name="l01038"></a>01038   <span class="keywordtype">int</span> is=(int)shift;
+<a name="l01039"></a>01039   <span class="keywordtype">double</span> ds=shift-is;
+<a name="l01040"></a>01040   <span class="keywordtype">double</span>* pi=NULL;
+<a name="l01041"></a>01041   <span class="keywordtype">double</span>* po=NULL;
+<a name="l01042"></a>01042   <span class="keywordtype">double</span> m=0;
+<a name="l01043"></a>01043   <span class="keywordtype">int</span> i=0;
+<a name="l01044"></a>01044   cknull(inp,<span class="stringliteral">"null input table"</span>);
+<a name="l01045"></a>01045 
+<a name="l01046"></a>01046   check_nomsg(nrow=cpl_table_get_nrow(inp));
+<a name="l01047"></a>01047   check_nomsg(out=cpl_table_duplicate(inp));
+<a name="l01048"></a>01048   check_nomsg(cpl_table_fill_column_window(out,col,0,nrow,0));
+<a name="l01049"></a>01049   check_nomsg(pi=cpl_table_get_data_double(inp,col));
+<a name="l01050"></a>01050   check_nomsg(po=cpl_table_get_data_double(out,col));
+<a name="l01051"></a>01051 
+<a name="l01052"></a>01052 
+<a name="l01053"></a>01053   <span class="keywordflow">for</span>(i=0;i<nrow;i++) {
+<a name="l01054"></a>01054     <span class="keywordflow">if</span>((i+is)>0 && (i+is+1) < nrow) {
+<a name="l01055"></a>01055       m=pi[i+is+1]-pi[i+is];
+<a name="l01056"></a>01056       po[i]=pi[i+is]+m*ds;
+<a name="l01057"></a>01057     }
+<a name="l01058"></a>01058   }
+<a name="l01059"></a>01059   <span class="keywordflow">return</span> out;
+<a name="l01060"></a>01060   cleanup:
+<a name="l01061"></a>01061   sinfo_free_table(&out);
+<a name="l01062"></a>01062   <span class="keywordflow">return</span> NULL;
+<a name="l01063"></a>01063 
+<a name="l01064"></a>01064 }
+<a name="l01065"></a>01065 
+<a name="l01066"></a>01066 
+<a name="l01067"></a>01067 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l01074"></a>01074 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l01075"></a>01075 
+<a name="l01076"></a>01076 <span class="keyword">static</span> <span class="keywordtype">double</span>
+<a name="l01077"></a>01077 sinfo_fit_poly(<span class="keywordtype">double</span> p[])
+<a name="l01078"></a>01078 
+<a name="l01079"></a>01079 {
+<a name="l01080"></a>01080 
+<a name="l01081"></a>01081   <span class="keywordtype">double</span>* px=NULL;
+<a name="l01082"></a>01082   <span class="keywordtype">double</span>* py=NULL; 
+<a name="l01083"></a>01083 
+<a name="l01084"></a>01084   <span class="keywordtype">int</span> i=0;
+<a name="l01085"></a>01085   <span class="keywordtype">int</span> np=0;
+<a name="l01086"></a>01086  
+<a name="l01087"></a>01087   <span class="keywordtype">double</span> fy=0;  
+<a name="l01088"></a>01088   <span class="keywordtype">double</span> chi2=0;
+<a name="l01089"></a>01089 
+<a name="l01090"></a>01090   check_nomsg(px= cpl_vector_get_data(sa_vx));
+<a name="l01091"></a>01091   check_nomsg(py= cpl_vector_get_data(sa_vy));
+<a name="l01092"></a>01092   check_nomsg(np= cpl_vector_get_size(sa_vx));
+<a name="l01093"></a>01093 
+<a name="l01094"></a>01094   <span class="keywordflow">for</span>(i=0;i<np;i++) {
+<a name="l01095"></a>01095     <span class="comment">//fy=(px[i]-p[0])*(px[i]-p[0]);</span>
+<a name="l01096"></a>01096     fy=p[0]+p[1]*px[i]+p[2]*px[i]*px[i];
+<a name="l01097"></a>01097     chi2+=(py[i]-fy)*(py[i]-fy);
+<a name="l01098"></a>01098   } 
+<a name="l01099"></a>01099   
+<a name="l01100"></a>01100   <span class="keywordflow">return</span> chi2;
+<a name="l01101"></a>01101  cleanup:
+<a name="l01102"></a>01102   <span class="keywordflow">return</span> -1;
+<a name="l01103"></a>01103 
+<a name="l01104"></a>01104 }
+<a name="l01105"></a>01105 
+<a name="l01106"></a>01106 <span class="keyword">static</span> <span class="keywordtype">double</span>
+<a name="l01107"></a>01107 sinfo_fit_boltzmann(<span class="keywordtype">double</span> p[])
+<a name="l01108"></a>01108 
+<a name="l01109"></a>01109 {
+<a name="l01110"></a>01110 
+<a name="l01111"></a>01111   <span class="keywordtype">double</span>* px=NULL;
+<a name="l01112"></a>01112   <span class="keywordtype">double</span>* py=NULL; 
+<a name="l01113"></a>01113   <span class="keywordtype">double</span>* pv=NULL; 
+<a name="l01114"></a>01114   cpl_vector* vtmp=NULL;
+<a name="l01115"></a>01115   <span class="keywordtype">double</span> max=0;
+<a name="l01116"></a>01116   <span class="keywordtype">int</span> i=0;
+<a name="l01117"></a>01117   <span class="keywordtype">int</span> np=0;
+<a name="l01118"></a>01118  
+<a name="l01119"></a>01119   <span class="keywordtype">double</span> chi2=0;
+<a name="l01120"></a>01120 
+<a name="l01121"></a>01121   check_nomsg(px= cpl_vector_get_data(sa_vx));
+<a name="l01122"></a>01122   check_nomsg(py= cpl_vector_get_data(sa_vy));
+<a name="l01123"></a>01123   check_nomsg(np= cpl_vector_get_size(sa_vx));
+<a name="l01124"></a>01124   check_nomsg(vtmp=cpl_vector_duplicate(sa_vy));
+<a name="l01125"></a>01125   check_nomsg(pv=cpl_vector_get_data(vtmp));
+<a name="l01126"></a>01126    
+<a name="l01127"></a>01127   <span class="keywordflow">for</span>(i=0;i<np;i++) {
+<a name="l01128"></a>01128     pv[i]=sinfo_fac(px[i],p[2]);
+<a name="l01129"></a>01129     <span class="comment">//sinfo_msg("x=%g p=%g",px[i],pv[i]);</span>
+<a name="l01130"></a>01130   }
+<a name="l01131"></a>01131   check_nomsg(max=cpl_vector_get_max(vtmp));
+<a name="l01132"></a>01132   <span class="keywordflow">if</span>(max> 0) {
+<a name="l01133"></a>01133     check_nomsg(cpl_vector_divide_scalar(vtmp,max));
+<a name="l01134"></a>01134     check_nomsg(cpl_vector_multiply_scalar(vtmp,p[1]));
+<a name="l01135"></a>01135     check_nomsg(cpl_vector_add_scalar(vtmp,p[0]));
+<a name="l01136"></a>01136   }
+<a name="l01137"></a>01137 
+<a name="l01138"></a>01138 
+<a name="l01139"></a>01139   <span class="keywordflow">for</span>(i=0;i<np;i++) {
+<a name="l01140"></a>01140     chi2+=(py[i]-pv[i])*(py[i]-pv[i]);
+<a name="l01141"></a>01141   } 
+<a name="l01142"></a>01142   
+<a name="l01143"></a>01143   <span class="keywordflow">return</span> chi2;
+<a name="l01144"></a>01144  cleanup:
+<a name="l01145"></a>01145   <span class="keywordflow">return</span> -1;
+<a name="l01146"></a>01146 
+<a name="l01147"></a>01147 }
+<a name="l01148"></a>01148 
+<a name="l01149"></a>01149 <span class="keyword">static</span> <span class="keywordtype">int</span> 
+<a name="l01150"></a>01150 sinfo_fitbkg(<span class="keyword">const</span> <span class="keywordtype">double</span> x[], 
+<a name="l01151"></a>01151              <span class="keyword">const</span> <span class="keywordtype">double</span> a[], 
+<a name="l01152"></a>01152              <span class="keywordtype">double</span> *result)
+<a name="l01153"></a>01153 {
+<a name="l01154"></a>01154 
+<a name="l01155"></a>01155   <span class="keywordtype">double</span> fac  = sinfo_fac(x[0],a[2]);
+<a name="l01156"></a>01156   *result = a[0]+a[1]*fac;
+<a name="l01157"></a>01157 
+<a name="l01158"></a>01158   <span class="keywordflow">return</span> 0;
+<a name="l01159"></a>01159 }
+<a name="l01160"></a>01160 
+<a name="l01161"></a>01161 <span class="keyword">static</span> <span class="keywordtype">double</span>
+<a name="l01162"></a>01162 sinfo_fac(<span class="keyword">const</span> <span class="keywordtype">double</span> x, <span class="keyword">const</span> <span class="keywordtype">double</span> t)
+<a name="l01163"></a>01163 {
+<a name="l01164"></a>01164   
+<a name="l01165"></a>01165   <span class="keywordtype">double</span> c=14387.7;
+<a name="l01166"></a>01166 
+<a name="l01167"></a>01167   <span class="keywordflow">return</span> pow(x,-5.)/(exp(c/(x*fabs(t)))-1.);
+<a name="l01168"></a>01168 }
+<a name="l01169"></a>01169 
+<a name="l01170"></a>01170 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__vltPort_8h_source.html b/html/sinfo__vltPort_8h_source.html
new file mode 100644
index 0000000..667af44
--- /dev/null
+++ b/html/sinfo__vltPort_8h_source.html
@@ -0,0 +1,117 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_vltPort.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_vltPort.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*************************************************************************</span>
+<a name="l00020"></a>00020 <span class="comment">* E.S.O. - VLT project</span>
+<a name="l00021"></a>00021 <span class="comment">*</span>
+<a name="l00022"></a>00022 <span class="comment">* "@(#) $Id: sinfo_vltPort.h,v 1.3 2006/10/25 06:46:09 amodigli Exp $" </span>
+<a name="l00023"></a>00023 <span class="comment">*</span>
+<a name="l00024"></a>00024 <span class="comment">* vltPort.h for Sun Solaris 2</span>
+<a name="l00025"></a>00025 <span class="comment">*</span>
+<a name="l00026"></a>00026 <span class="comment">* who        when      what</span>
+<a name="l00027"></a>00027 <span class="comment">* --------  --------  ----------------------------------------------</span>
+<a name="l00028"></a>00028 <span class="comment">* gfilippi  22/05/96  created form vltPort.h</span>
+<a name="l00029"></a>00029 <span class="comment">* gfilippi  23/05/96  define SUN_COMP added</span>
+<a name="l00030"></a>00030 <span class="comment">*</span>
+<a name="l00031"></a>00031 <span class="comment">*/</span>
+<a name="l00032"></a>00032 
+<a name="l00033"></a>00033 <span class="comment">/************************************************************************</span>
+<a name="l00034"></a>00034 <span class="comment">*  vltPort.h - Include file to mask differences between platforms.</span>
+<a name="l00035"></a>00035 <span class="comment">*              This file should be included in all source files.</span>
+<a name="l00036"></a>00036 <span class="comment">*              It relies on macro definitions preceeding the</span>
+<a name="l00037"></a>00037 <span class="comment">*              inclusion of this file.</span>
+<a name="l00038"></a>00038 <span class="comment">*                </span>
+<a name="l00039"></a>00039 <span class="comment">*  REMARK: This file belongs to the "vltMake" module.</span>
+<a name="l00040"></a>00040 <span class="comment">*------------------------------------------------------------------------</span>
+<a name="l00041"></a>00041 <span class="comment">*/</span>
+<a name="l00042"></a>00042 
+<a name="l00043"></a>00043 <span class="preprocessor">#ifndef SINFO_VLTPORT_H</span>
+<a name="l00044"></a>00044 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_VLTPORT_H</span>
+<a name="l00045"></a>00045 <span class="preprocessor"></span>
+<a name="l00046"></a>00046 <span class="comment">/*</span>
+<a name="l00047"></a>00047 <span class="comment">* When it is used, vltPort.h MUST be the very first file included</span>
+<a name="l00048"></a>00048 <span class="comment">* in ANSI ".c" files.</span>
+<a name="l00049"></a>00049 <span class="comment">* Cause a syntax error if we detect that any other include file has been</span>
+<a name="l00050"></a>00050 <span class="comment">* included before vltPort.h in an ANSI ".c" file.</span>
+<a name="l00051"></a>00051 <span class="comment">*/</span>
+<a name="l00052"></a>00052 <span class="preprocessor">#if defined(__STDC__) && \</span>
+<a name="l00053"></a>00053 <span class="preprocessor">                         (defined(_H_STANDARDS) || \</span>
+<a name="l00054"></a>00054 <span class="preprocessor">                          defined(_SYS_STDSYMS_INCLUDED) || \</span>
+<a name="l00055"></a>00055 <span class="preprocessor">                          defined(_STANDARDS_H_))</span>
+<a name="l00056"></a>00056 <span class="preprocessor"></span><span class="preprocessor">#    error "vltPort.h MUST BE THE VERY FIRST FILE INCLUDED IN ANSI '.c' FILES"</span>
+<a name="l00057"></a>00057 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
+<a name="l00058"></a>00058 <span class="preprocessor"></span>
+<a name="l00059"></a>00059 <span class="comment">/*</span>
+<a name="l00060"></a>00060 <span class="comment"> * This file is used also by some VxWorks code.</span>
+<a name="l00061"></a>00061 <span class="comment"> * To be compatible with existing code, SUN_COMP is defined for both</span>
+<a name="l00062"></a>00062 <span class="comment"> * gcc and cc68k, but the following definitiond do not influence cc68k</span>
+<a name="l00063"></a>00063 <span class="comment"> */</span>
+<a name="l00064"></a>00064  
+<a name="l00065"></a>00065 <span class="preprocessor">#define SUN_COMP</span>
+<a name="l00066"></a>00066 <span class="preprocessor"></span>
+<a name="l00067"></a>00067 <span class="comment">/* </span>
+<a name="l00068"></a>00068 <span class="comment"> * at present, SELECT is defined in the code using it. It should be done here</span>
+<a name="l00069"></a>00069 <span class="comment"> * for all. May be in the next release.</span>
+<a name="l00070"></a>00070 <span class="comment"> */</span>
+<a name="l00071"></a>00071 
+<a name="l00072"></a>00072 <span class="comment">/*</span>
+<a name="l00073"></a>00073 <span class="comment"> * Adjust name-space information.</span>
+<a name="l00074"></a>00074 <span class="comment"> */</span>
+<a name="l00075"></a>00075 <span class="preprocessor">#if defined(_ALL_SOURCE)</span>
+<a name="l00076"></a>00076 <span class="preprocessor"></span><span class="preprocessor">#    undef _POSIX_C_SOURCE</span>
+<a name="l00077"></a>00077 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
+<a name="l00078"></a>00078 <span class="preprocessor"></span>
+<a name="l00079"></a>00079 <span class="preprocessor">#if defined(_XOPEN_SOURCE)</span>
+<a name="l00080"></a>00080 <span class="preprocessor"></span><span class="preprocessor">#    undef _POSIX_C_SOURCE</span>
+<a name="l00081"></a>00081 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
+<a name="l00082"></a>00082 <span class="preprocessor"></span>
+<a name="l00083"></a>00083 <span class="preprocessor">#ifndef MAKE_VXWORKS</span>
+<a name="l00084"></a>00084 <span class="preprocessor"></span><span class="preprocessor">#include <stddef.h></span>
+<a name="l00085"></a>00085 <span class="preprocessor">#include <sys/types.h></span>
+<a name="l00086"></a>00086 <span class="preprocessor">#include <sys/time.h></span>
+<a name="l00087"></a>00087 
+<a name="l00088"></a>00088 <span class="preprocessor">#if !defined(timercmp)</span>
+<a name="l00089"></a>00089 <span class="preprocessor"></span><span class="comment">/*</span>
+<a name="l00090"></a>00090 <span class="comment">AMO: 03/09/03 commented out for Linux</span>
+<a name="l00091"></a>00091 <span class="comment">    struct timeval</span>
+<a name="l00092"></a>00092 <span class="comment">        {</span>
+<a name="l00093"></a>00093 <span class="comment">        long      tv_sec;         </span>
+<a name="l00094"></a>00094 <span class="comment">        long      tv_usec;        </span>
+<a name="l00095"></a>00095 <span class="comment">        };</span>
+<a name="l00096"></a>00096 <span class="comment">*/</span>
+<a name="l00097"></a>00097 <span class="preprocessor">#define crTIMEVAL_TIMEZONE_DEFINED</span>
+<a name="l00098"></a>00098 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
+<a name="l00099"></a>00099 <span class="preprocessor"></span><span class="preprocessor">#endif </span><span class="comment">/* MAKE_VXWORKS */</span>
+<a name="l00100"></a>00100 
+<a name="l00101"></a>00101 <span class="preprocessor">#endif </span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__wave__calibration_8c_source.html b/html/sinfo__wave__calibration_8c_source.html
new file mode 100644
index 0000000..1af6eb5
--- /dev/null
+++ b/html/sinfo__wave__calibration_8c_source.html
@@ -0,0 +1,2638 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_wave_calibration.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_wave_calibration.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*************************************************************************</span>
+<a name="l00020"></a>00020 <span class="comment">* E.S.O. - VLT project</span>
+<a name="l00021"></a>00021 <span class="comment">*</span>
+<a name="l00022"></a>00022 <span class="comment">* </span>
+<a name="l00023"></a>00023 <span class="comment">*</span>
+<a name="l00024"></a>00024 <span class="comment">* who       when      what</span>
+<a name="l00025"></a>00025 <span class="comment">* --------  --------  ----------------------------------------------</span>
+<a name="l00026"></a>00026 <span class="comment">* schreib  13/07/00  created</span>
+<a name="l00027"></a>00027 <span class="comment">*/</span>
+<a name="l00028"></a>00028 
+<a name="l00029"></a>00029 <span class="comment">/************************************************************************</span>
+<a name="l00030"></a>00030 <span class="comment">*   NAME</span>
+<a name="l00031"></a>00031 <span class="comment">*     sinfo_wave_calibration.c -</span>
+<a name="l00032"></a>00032 <span class="comment">*     routines needed for wavelength calibration</span>
+<a name="l00033"></a>00033 <span class="comment">*</span>
+<a name="l00034"></a>00034 <span class="comment">*   SYNOPSIS</span>
+<a name="l00035"></a>00035 <span class="comment">* </span>
+<a name="l00036"></a>00036 <span class="comment">*   1) FitParams ** sinfo_new_fit_params( int n_params )</span>
+<a name="l00037"></a>00037 <span class="comment">*</span>
+<a name="l00038"></a>00038 <span class="comment">*   2) void sinfo_new_destroy_fit_params ( FitParams ** params )</span>
+<a name="l00039"></a>00039 <span class="comment">*</span>
+<a name="l00040"></a>00040 <span class="comment">*   3) void sinfo_new_dump_fit_params_to_ascii(FitParams ** params,</span>
+<a name="l00041"></a>00041 <span class="comment">                                               const char * filename )</span>
+<a name="l00042"></a>00042 <span class="comment">*</span>
+<a name="l00043"></a>00043 <span class="comment">*   4) void sinfo_new_dump_ascii_to_fit_params ( FitParams ** params, </span>
+<a name="l00044"></a>00044 <span class="comment">                                                 char * filename )</span>
+<a name="l00045"></a>00045 <span class="comment">*</span>
+<a name="l00046"></a>00046 <span class="comment">*   5) int sinfo_new_find_lines(cpl_image * lineImage, </span>
+<a name="l00047"></a>00047 <span class="comment">*                     float    * wave_position, </span>
+<a name="l00048"></a>00048 <span class="comment">*                     float    * wave_intensity,</span>
+<a name="l00049"></a>00049 <span class="comment">*                     int        n_lines, </span>
+<a name="l00050"></a>00050 <span class="comment">*                     int     ** row_clean,</span>
+<a name="l00051"></a>00051 <span class="comment">*                     float   ** wavelength_clean,</span>
+<a name="l00052"></a>00052 <span class="comment">*                     float      beginWave, </span>
+<a name="l00053"></a>00053 <span class="comment">*                     float      dispersion,</span>
+<a name="l00054"></a>00054 <span class="comment">*                     float      mindiff, </span>
+<a name="l00055"></a>00055 <span class="comment">*                     int        halfWidth,</span>
+<a name="l00056"></a>00056 <span class="comment">*                     int      * n_found_lines,</span>
+<a name="l00057"></a>00057 <span class="comment">*                     float      sigma,</span>
+<a name="l00058"></a>00058 <span class="comment">*                     int      * sum_lines )</span>
+<a name="l00059"></a>00059 <span class="comment">*</span>
+<a name="l00060"></a>00060 <span class="comment">*   6) int sinfo_new_read_list( char * listname, </span>
+<a name="l00061"></a>00061 <span class="comment">                                float * lineCenter, </span>
+<a name="l00062"></a>00062 <span class="comment">                                float * lineIntensity )</span>
+<a name="l00063"></a>00063 <span class="comment">*</span>
+<a name="l00064"></a>00064 <span class="comment">*</span>
+<a name="l00065"></a>00065 <span class="comment">*   7) int sinfo_new_line_fit ( cpl_image  *  mergedImage, </span>
+<a name="l00066"></a>00066 <span class="comment">*                    FitParams *  par,</span>
+<a name="l00067"></a>00067 <span class="comment">*                    float        fwhm,</span>
+<a name="l00068"></a>00068 <span class="comment">*                    int          lineInd,</span>
+<a name="l00069"></a>00069 <span class="comment">*                    int          column, </span>
+<a name="l00070"></a>00070 <span class="comment">*                    int          halfWidth, </span>
+<a name="l00071"></a>00071 <span class="comment">*                    int          lineRow,</span>
+<a name="l00072"></a>00072 <span class="comment">*                    float        min_amplitude )</span>
+<a name="l00073"></a>00073 <span class="comment">*</span>
+<a name="l00074"></a>00074 <span class="comment">*   8) int sinfo_new_fit_lines ( cpl_image  *  line_image, </span>
+<a name="l00075"></a>00075 <span class="comment">*                     FitParams ** allParams,</span>
+<a name="l00076"></a>00076 <span class="comment">*                     float        fwhm,</span>
+<a name="l00077"></a>00077 <span class="comment">*                     int       *  n_lines, </span>
+<a name="l00078"></a>00078 <span class="comment">*                     int       ** row,</span>
+<a name="l00079"></a>00079 <span class="comment">*                     float     ** wavelength, </span>
+<a name="l00080"></a>00080 <span class="comment">*                     int          width,</span>
+<a name="l00081"></a>00081 <span class="comment">*                     float        min_amplitude ) </span>
+<a name="l00082"></a>00082 <span class="comment">*</span>
+<a name="l00083"></a>00083 <span class="comment">*   9) float sinfo_new_polyfit( FitParams ** par, </span>
+<a name="l00084"></a>00084 <span class="comment">*                     int          column,</span>
+<a name="l00085"></a>00085 <span class="comment">*                     int          n_lines,</span>
+<a name="l00086"></a>00086 <span class="comment">*                     int          n_rows,</span>
+<a name="l00087"></a>00087 <span class="comment">*                     float        dispersion,</span>
+<a name="l00088"></a>00088 <span class="comment">*                     float        max_residual,</span>
+<a name="l00089"></a>00089 <span class="comment">*                     float *      acoefs, </span>
+<a name="l00090"></a>00090 <span class="comment">*                     float *      dacoefs, </span>
+<a name="l00091"></a>00091 <span class="comment">*                     int   *      n_reject,</span>
+<a name="l00092"></a>00092 <span class="comment">*                     int          n_fitcoefs )</span>
+<a name="l00093"></a>00093 <span class="comment">*</span>
+<a name="l00094"></a>00094 <span class="comment">*   10) float sinfo_new_coefs_cross_fit ( int      n_columns,</span>
+<a name="l00095"></a>00095 <span class="comment">*                            float *  acoefs,</span>
+<a name="l00096"></a>00096 <span class="comment">*                            float *  dacoefs, </span>
+<a name="l00097"></a>00097 <span class="comment">*                            float *  bcoefs,</span>
+<a name="l00098"></a>00098 <span class="comment">*                            int      n_fitcoefs,</span>
+<a name="l00099"></a>00099 <span class="comment">*                            float    sigma_factor )</span>
+<a name="l00100"></a>00100 <span class="comment">*</span>
+<a name="l00101"></a>00101 <span class="comment">*</span>
+<a name="l00102"></a>00102 <span class="comment">*  11) cpl_image * sinfo_new_wave_map( cpl_image * lineImage,</span>
+<a name="l00103"></a>00103 <span class="comment">*                          float   ** bcoefs,</span>
+<a name="l00104"></a>00104 <span class="comment">*                          int        n_a_fitcoefs,</span>
+<a name="l00105"></a>00105 <span class="comment">*                          int        n_b_fitcoefs,</span>
+<a name="l00106"></a>00106 <span class="comment">*                          float    * wavelength,</span>
+<a name="l00107"></a>00107 <span class="comment">*                          float    * intensity,</span>
+<a name="l00108"></a>00108 <span class="comment">*                          int        n_lines,</span>
+<a name="l00109"></a>00109 <span class="comment">*                          int        magFactor,</span>
+<a name="l00110"></a>00110 <span class="comment">*                          int      * bad_column_mask,</span>
+<a name="l00111"></a>00111 <span class="comment">*                          int        n_bad_columns )</span>
+<a name="l00112"></a>00112 <span class="comment">*</span>
+<a name="l00113"></a>00113 <span class="comment">*  12) int sinfo_new_wavelength_calibration( cpl_image   * image, </span>
+<a name="l00114"></a>00114 <span class="comment">*                                 FitParams ** par ,</span>
+<a name="l00115"></a>00115 <span class="comment">*                                 float     ** bcoefs,</span>
+<a name="l00116"></a>00116 <span class="comment">*                                 float      * wave,</span>
+<a name="l00117"></a>00117 <span class="comment">*                                 int          n_lines,</span>
+<a name="l00118"></a>00118 <span class="comment">*                                 int       ** row_clean,</span>
+<a name="l00119"></a>00119 <span class="comment">*                                 float     ** wavelength_clean,</span>
+<a name="l00120"></a>00120 <span class="comment">*                                 int        * n_found_lines,</span>
+<a name="l00121"></a>00121 <span class="comment">*                                 float        dispersion,</span>
+<a name="l00122"></a>00122 <span class="comment">*                                 int          halfWidth,</span>
+<a name="l00123"></a>00123 <span class="comment">*                                 float        minAmplitude,</span>
+<a name="l00124"></a>00124 <span class="comment">*                                 float        max_residual,</span>
+<a name="l00125"></a>00125 <span class="comment">*                                 float        fwhm,</span>
+<a name="l00126"></a>00126 <span class="comment">*                                 int          n_a_fitcoefs,</span>
+<a name="l00127"></a>00127 <span class="comment">*                                 int          n_b_fitcoefs,</span>
+<a name="l00128"></a>00128 <span class="comment">*                                 float        sigmaFactor )</span>
+<a name="l00129"></a>00129 <span class="comment">*</span>
+<a name="l00130"></a>00130 <span class="comment">*  13) cpl_image * sinfo_new_convolve_image_by_gauss( cpl_image * lineImage,</span>
+<a name="l00131"></a>00131 <span class="comment">*                                       int        hw )</span>
+<a name="l00132"></a>00132 <span class="comment">*</span>
+<a name="l00133"></a>00133 <span class="comment">*  14) cpl_image * sinfo_new_defined_resampling( cpl_image * image,</span>
+<a name="l00134"></a>00134 <span class="comment">*                                    cpl_image * calimage,</span>
+<a name="l00135"></a>00135 <span class="comment">*                                    int        n_params,</span>
+<a name="l00136"></a>00136 <span class="comment">*                                    int        n_rows,</span>
+<a name="l00137"></a>00137 <span class="comment">*                                    double   * dispersion,</span>
+<a name="l00138"></a>00138 <span class="comment">*                                    float    * minval,</span>
+<a name="l00139"></a>00139 <span class="comment">*                                    float    * maxval,</span>
+<a name="l00140"></a>00140 <span class="comment">*                                    double   * centralLambda,</span>
+<a name="l00141"></a>00141 <span class="comment">*                                    int      * centralpix )</span>
+<a name="l00142"></a>00142 <span class="comment">*</span>
+<a name="l00143"></a>00143 <span class="comment">*   DESCRIPTION</span>
+<a name="l00144"></a>00144 <span class="comment">*</span>
+<a name="l00145"></a>00145 <span class="comment">*   1) allocates memory for a new sinfo_vector of </span>
+<a name="l00146"></a>00146 <span class="comment">*      FitParams data structures</span>
+<a name="l00147"></a>00147 <span class="comment">*   2) frees memory of a sinfo_vector of FitParams data structures</span>
+<a name="l00148"></a>00148 <span class="comment">*   3) dumps the fit parameters to an ASCII file</span>
+<a name="l00149"></a>00149 <span class="comment">*   4) dumps ASCII information to an allocated FitParams data structure</span>
+<a name="l00150"></a>00150 <span class="comment">*   5) determines the pixel shift between the line list </span>
+<a name="l00151"></a>00151 <span class="comment">*      and the real image by using the beginning wavelength</span>
+<a name="l00152"></a>00152 <span class="comment">*      on the detector and the dispersion estimate.</span>
+<a name="l00153"></a>00153 <span class="comment">*   6) reads the line data of the calibration lamps</span>
+<a name="l00154"></a>00154 <span class="comment">*   7) fits a sinfo_gaussian to a 1-dimensional slice of an image, </span>
+<a name="l00155"></a>00155 <span class="comment">*      this routine uses the routine sinfo_new_lsqfit_c as a non-linear</span>
+<a name="l00156"></a>00156 <span class="comment">*      least square fit method (Levenberg-Marquardt).               </span>
+<a name="l00157"></a>00157 <span class="comment">*   8) calculates and stores the fit parameters of the neon </span>
+<a name="l00158"></a>00158 <span class="comment">*      emission lines of a neon frame by using the sinfo_linefit </span>
+<a name="l00159"></a>00159 <span class="comment">*      routine.</span>
+<a name="l00160"></a>00160 <span class="comment">*   9) fits a second order polynom </span>
+<a name="l00161"></a>00161 <span class="comment">*      lambda[i] = a1 + a2*pos[i] + a3*pos[i]^2</span>
+<a name="l00162"></a>00162 <span class="comment">*      to determine the connection between the listed wave-</span>
+<a name="l00163"></a>00163 <span class="comment">*      length values and the gauss-fitted positions for each</span>
+<a name="l00164"></a>00164 <span class="comment">*      image column using the singular value decomposition </span>
+<a name="l00165"></a>00165 <span class="comment">*      method. </span>
+<a name="l00166"></a>00166 <span class="comment">*  10) Fits the each single parameter of the three fit parameters </span>
+<a name="l00167"></a>00167 <span class="comment">*      acoefs from sinfo_polyfit through the image columns</span>
+<a name="l00168"></a>00168 <span class="comment">*  11) this routine determines a wavelength calibration map </span>
+<a name="l00169"></a>00169 <span class="comment">*      frame associating a wavelength value to each pixel</span>
+<a name="l00170"></a>00170 <span class="comment">*      by using the fit coefficients determined before.</span>
+<a name="l00171"></a>00171 <span class="comment">*  12) this routine takes an image from a calibration</span>
+<a name="l00172"></a>00172 <span class="comment">*      emission lamp and delivers the fit coefficients of  </span>
+<a name="l00173"></a>00173 <span class="comment">*      a polynomial fit across the columns </span>
+<a name="l00174"></a>00174 <span class="comment">*      of the coefficients of the polynomial line position</span>
+<a name="l00175"></a>00175 <span class="comment">*      fits as output. Furthermore it delivers an array of the fit parameters</span>
+<a name="l00176"></a>00176 <span class="comment">*      as output. This routine expects Nyquist sampled spectra </span>
+<a name="l00177"></a>00177 <span class="comment">*     (either an interleaved image or an image convolved with an </span>
+<a name="l00178"></a>00178 <span class="comment">*      appropriate function in spectral direction)</span>
+<a name="l00179"></a>00179 <span class="comment">*  13) convolves an emission line image with a sinfo_gaussian</span>
+<a name="l00180"></a>00180 <span class="comment">*      with user given integer half width by using the eclipse </span>
+<a name="l00181"></a>00181 <span class="comment">*      routine sinfo_function1d_filter_lowpass().</span>
+<a name="l00182"></a>00182 <span class="comment">*  14) Given a source image and a corresponding wavelength</span>
+<a name="l00183"></a>00183 <span class="comment">*      calibration file this routine produces an image</span>
+<a name="l00184"></a>00184 <span class="comment">*      in which elements in a given row are associated</span>
+<a name="l00185"></a>00185 <span class="comment">*      with a single wavelength. It thus corrects for </span>
+<a name="l00186"></a>00186 <span class="comment">*      the wavelength shifts between adjacent elements</span>
+<a name="l00187"></a>00187 <span class="comment">*      in the rows of the input image. The output image</span>
+<a name="l00188"></a>00188 <span class="comment">*      is larger in the wavelength domain than the input</span>
+<a name="l00189"></a>00189 <span class="comment">*      image with pixels in each column corresponding to </span>
+<a name="l00190"></a>00190 <span class="comment">*      undefined (blank, ZERO) values. The distribution</span>
+<a name="l00191"></a>00191 <span class="comment">*      of these undefined values varies from column to</span>
+<a name="l00192"></a>00192 <span class="comment">*      column. The input image is resampled at discrete</span>
+<a name="l00193"></a>00193 <span class="comment">*      wavelength intervals using a polynomial interpolation</span>
+<a name="l00194"></a>00194 <span class="comment">*      routine. </span>
+<a name="l00195"></a>00195 <span class="comment">*      The wavelength intervals (dispersion) and the </span>
+<a name="l00196"></a>00196 <span class="comment">*      central wavelength are defined and stable for each</span>
+<a name="l00197"></a>00197 <span class="comment">*      used grating. Thus, each row has a defined wavelength</span>
+<a name="l00198"></a>00198 <span class="comment">*      for each grating. Only the number of rows can be </span>
+<a name="l00199"></a>00199 <span class="comment">*      changed by the user. </span>
+<a name="l00200"></a>00200 <span class="comment">*</span>
+<a name="l00201"></a>00201 <span class="comment">*   FILES</span>
+<a name="l00202"></a>00202 <span class="comment">*</span>
+<a name="l00203"></a>00203 <span class="comment">*   ENVIRONMENT</span>
+<a name="l00204"></a>00204 <span class="comment">*</span>
+<a name="l00205"></a>00205 <span class="comment">*   RETURN VALUES </span>
+<a name="l00206"></a>00206 <span class="comment">*</span>
+<a name="l00207"></a>00207 <span class="comment">*   CAUTIONS </span>
+<a name="l00208"></a>00208 <span class="comment">*</span>
+<a name="l00209"></a>00209 <span class="comment">*   EXAMPLES</span>
+<a name="l00210"></a>00210 <span class="comment">*</span>
+<a name="l00211"></a>00211 <span class="comment">*   SEE ALSO</span>
+<a name="l00212"></a>00212 <span class="comment">*</span>
+<a name="l00213"></a>00213 <span class="comment">*   BUGS   </span>
+<a name="l00214"></a>00214 <span class="comment">*</span>
+<a name="l00215"></a>00215 <span class="comment">*------------------------------------------------------------------------</span>
+<a name="l00216"></a>00216 <span class="comment">*/</span>
+<a name="l00217"></a>00217 
+<a name="l00218"></a>00218 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00219"></a>00219 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00220"></a>00220 <span class="preprocessor">#endif</span>
+<a name="l00221"></a>00221 <span class="preprocessor"></span><span class="preprocessor">#include "sinfo_vltPort.h"</span>
+<a name="l00222"></a>00222 
+<a name="l00223"></a>00223 <span class="comment">/* </span>
+<a name="l00224"></a>00224 <span class="comment"> * System Headers</span>
+<a name="l00225"></a>00225 <span class="comment"> */</span>
+<a name="l00226"></a>00226 
+<a name="l00227"></a>00227 <span class="comment">/* </span>
+<a name="l00228"></a>00228 <span class="comment"> * Local Headers</span>
+<a name="l00229"></a>00229 <span class="comment"> */</span>
+<a name="l00230"></a>00230 
+<a name="l00231"></a>00231 <span class="preprocessor">#include "sinfo_function_1d.h"</span>
+<a name="l00232"></a>00232 <span class="preprocessor">#include "sinfo_wave_calibration.h"</span>
+<a name="l00233"></a>00233 <span class="preprocessor">#include "sinfo_solve_poly_root.h"</span>
+<a name="l00234"></a>00234 <span class="preprocessor">#include "sinfo_recipes.h"</span>
+<a name="l00235"></a>00235 <span class="preprocessor">#include "sinfo_globals.h"</span>
+<a name="l00236"></a>00236 <span class="preprocessor">#include "sinfo_svd.h"</span>
+<a name="l00237"></a>00237 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00238"></a>00238 
+<a name="l00239"></a>00239 
+<a name="l00255"></a>00255 FitParams ** sinfo_new_fit_params( <span class="keywordtype">int</span> n_params )
+<a name="l00256"></a>00256 {
+<a name="l00257"></a>00257     FitParams ** new_params =NULL;
+<a name="l00258"></a>00258     FitParams  * temp_params =NULL;
+<a name="l00259"></a>00259     <span class="keywordtype">float</span> * temp_fit_mem =NULL;
+<a name="l00260"></a>00260     <span class="keywordtype">float</span> * temp_derv_mem=NULL;
+<a name="l00261"></a>00261     <span class="keywordtype">int</span> i ;
+<a name="l00262"></a>00262 
+<a name="l00263"></a>00263     
+<a name="l00264"></a>00264     <span class="keywordflow">if</span> ( n_params <= 0 )
+<a name="l00265"></a>00265     {
+<a name="l00266"></a>00266         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" wrong number of lines to fit\n"</span>) ;
+<a name="l00267"></a>00267         <span class="keywordflow">return</span> NULL ;
+<a name="l00268"></a>00268     }
+<a name="l00269"></a>00269 
+<a name="l00270"></a>00270     <span class="keywordflow">if</span> (NULL==(new_params=(FitParams **) cpl_calloc ( n_params , 
+<a name="l00271"></a>00271                                          <span class="keyword">sizeof</span> (FitParams*) ) ) )
+<a name="l00272"></a>00272     {
+<a name="l00273"></a>00273         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" could not allocate memory\n"</span>) ;
+<a name="l00274"></a>00274         <span class="keywordflow">return</span> NULL ;
+<a name="l00275"></a>00275     }
+<a name="l00276"></a>00276     <span class="keywordflow">if</span> ( NULL == (temp_params = cpl_calloc ( n_params , <span class="keyword">sizeof</span> (FitParams) ) ) )
+<a name="l00277"></a>00277     {
+<a name="l00278"></a>00278         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" could not allocate memory\n"</span>) ;
+<a name="l00279"></a>00279         <span class="keywordflow">return</span> NULL ;
+<a name="l00280"></a>00280     }
+<a name="l00281"></a>00281     <span class="keywordflow">if</span> ( NULL == (temp_fit_mem = (<span class="keywordtype">float</span> *) cpl_calloc( n_params*MAXPAR, 
+<a name="l00282"></a>00282                                      <span class="keyword">sizeof</span> (<span class="keywordtype">float</span>) ) ) )
+<a name="l00283"></a>00283     {
+<a name="l00284"></a>00284         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" could not allocate memory\n"</span>) ;
+<a name="l00285"></a>00285         <span class="keywordflow">return</span> NULL ;
+<a name="l00286"></a>00286     }
+<a name="l00287"></a>00287 
+<a name="l00288"></a>00288 
+<a name="l00289"></a>00289     <span class="keywordflow">if</span> ( NULL == (temp_derv_mem   = 
+<a name="l00290"></a>00290              (<span class="keywordtype">float</span> *) cpl_calloc( n_params*MAXPAR, <span class="keyword">sizeof</span> (<span class="keywordtype">float</span>) ) ) )
+<a name="l00291"></a>00291     {
+<a name="l00292"></a>00292         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" could not allocate memory\n"</span>) ;
+<a name="l00293"></a>00293         <span class="keywordflow">return</span> NULL ;
+<a name="l00294"></a>00294     }
+<a name="l00295"></a>00295 
+<a name="l00296"></a>00296     <span class="keywordflow">for</span> ( i = 0 ; i < n_params ; i ++ )
+<a name="l00297"></a>00297     {
+<a name="l00298"></a>00298         new_params[i] = temp_params+i;
+<a name="l00299"></a>00299         new_params[i] -> fit_par    = temp_fit_mem+i*MAXPAR;
+<a name="l00300"></a>00300         new_params[i] -> derv_par   = temp_derv_mem+i*MAXPAR;
+<a name="l00301"></a>00301         new_params[i] -> column     = 0 ;
+<a name="l00302"></a>00302         new_params[i] -> line       = 0 ;
+<a name="l00303"></a>00303         new_params[i] -> wavelength = 0. ;
+<a name="l00304"></a>00304         new_params[i] -> n_params   = n_params ;
+<a name="l00305"></a>00305     }
+<a name="l00306"></a>00306 
+<a name="l00307"></a>00307     <span class="keywordflow">return</span> new_params ;
+<a name="l00308"></a>00308 }
+<a name="l00309"></a>00309 
+<a name="l00317"></a>00317 <span class="keywordtype">void</span> sinfo_new_destroy_fit_params ( FitParams *** params )
+<a name="l00318"></a>00318 { 
+<a name="l00319"></a>00319     
+<a name="l00320"></a>00320     <span class="keywordflow">if</span> ( *params == NULL )
+<a name="l00321"></a>00321     {
+<a name="l00322"></a>00322         return ;
+<a name="l00323"></a>00323     }
+<a name="l00324"></a>00324 
+<a name="l00325"></a>00325     cpl_free ( (*params)[0] -> fit_par ) ;
+<a name="l00326"></a>00326     (*params)[0] -> fit_par=NULL;
+<a name="l00327"></a>00327     cpl_free ( (*params)[0] -> derv_par ) ;
+<a name="l00328"></a>00328     (*params)[0] -> derv_par=NULL;
+<a name="l00329"></a>00329     cpl_free ( (*params)[0] ) ;
+<a name="l00330"></a>00330     (*params)[0]=NULL;
+<a name="l00331"></a>00331     cpl_free ( (*params) ) ;
+<a name="l00332"></a>00332     (*params)=NULL;
+<a name="l00333"></a>00333 }
+<a name="l00334"></a>00334 
+<a name="l00343"></a>00343 <span class="keywordtype">void</span> sinfo_new_dump_fit_params_to_ascii ( FitParams ** params, <span class="keyword">const</span> <span class="keywordtype">char</span> * filename )
+<a name="l00344"></a>00344 {
+<a name="l00345"></a>00345     FILE * fp ;
+<a name="l00346"></a>00346     <span class="keywordtype">int</span>    i ;
+<a name="l00347"></a>00347 
+<a name="l00348"></a>00348     <span class="keywordflow">if</span> ( NULL == params )
+<a name="l00349"></a>00349     {
+<a name="l00350"></a>00350         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" no fit parameters available!\n"</span>) ;
+<a name="l00351"></a>00351         return ;
+<a name="l00352"></a>00352     }
+<a name="l00353"></a>00353 
+<a name="l00354"></a>00354     <span class="keywordflow">if</span> ( NULL == filename )
+<a name="l00355"></a>00355     {
+<a name="l00356"></a>00356         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" no filename available!\n"</span>) ;
+<a name="l00357"></a>00357         return ;
+<a name="l00358"></a>00358     }
+<a name="l00359"></a>00359 
+<a name="l00360"></a>00360     <span class="keywordflow">if</span> ( NULL == (fp = fopen ( filename, <span class="stringliteral">"w"</span> ) ) )
+<a name="l00361"></a>00361     {
+<a name="l00362"></a>00362         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" cannot open %s\n"</span>, filename) ;
+<a name="l00363"></a>00363         return ;
+<a name="l00364"></a>00364     }
+<a name="l00365"></a>00365 
+<a name="l00366"></a>00366     <span class="keywordflow">for</span> ( i = 0 ; i < params[0] -> n_params ; i++ )
+<a name="l00367"></a>00367     {
+<a name="l00368"></a>00368         fprintf(fp, <span class="stringliteral">"%d %d %d %f %f %f %f %f %f %f %f %f\n"</span>, 
+<a name="l00369"></a>00369                      params[i]->n_params, 
+<a name="l00370"></a>00370                      params[i]->column, 
+<a name="l00371"></a>00371                      params[i]->line, 
+<a name="l00372"></a>00372                      params[i]->wavelength, 
+<a name="l00373"></a>00373                      params[i]->fit_par[0], 
+<a name="l00374"></a>00374                      params[i]->fit_par[1], 
+<a name="l00375"></a>00375                      params[i]->fit_par[2], 
+<a name="l00376"></a>00376                      params[i]->fit_par[3],
+<a name="l00377"></a>00377                      params[i]->derv_par[0], 
+<a name="l00378"></a>00378                      params[i]->derv_par[1], 
+<a name="l00379"></a>00379                      params[i]->derv_par[2], 
+<a name="l00380"></a>00380                      params[i]->derv_par[3] ) ; 
+<a name="l00381"></a>00381     }
+<a name="l00382"></a>00382     fclose(fp) ;
+<a name="l00383"></a>00383 }
+<a name="l00384"></a>00384 
+<a name="l00393"></a>00393 <span class="keywordtype">void</span> 
+<a name="l00394"></a>00394 sinfo_new_dump_ascii_to_fit_params ( FitParams ** params, <span class="keywordtype">char</span> * filename )
+<a name="l00395"></a>00395 {
+<a name="l00396"></a>00396     FILE * fp ;
+<a name="l00397"></a>00397     <span class="keywordtype">int</span> i ;
+<a name="l00398"></a>00398 
+<a name="l00399"></a>00399     <span class="keywordflow">if</span> ( NULL == params )
+<a name="l00400"></a>00400     {
+<a name="l00401"></a>00401         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" no fit parameters available!\n"</span>) ;
+<a name="l00402"></a>00402         return ;
+<a name="l00403"></a>00403     }
+<a name="l00404"></a>00404 
+<a name="l00405"></a>00405     <span class="keywordflow">if</span> ( NULL == filename )
+<a name="l00406"></a>00406     {
+<a name="l00407"></a>00407         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" no filename available!\n"</span>) ;
+<a name="l00408"></a>00408         return ;
+<a name="l00409"></a>00409     }
+<a name="l00410"></a>00410 
+<a name="l00411"></a>00411     <span class="keywordflow">if</span> ( NULL == (fp = fopen ( filename, <span class="stringliteral">"r"</span> ) ) )
+<a name="l00412"></a>00412     {
+<a name="l00413"></a>00413         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" cannot open %s\n"</span>, filename) ;
+<a name="l00414"></a>00414         return ;
+<a name="l00415"></a>00415     }
+<a name="l00416"></a>00416     
+<a name="l00417"></a>00417     <span class="keywordflow">for</span> ( i = 0 ; i < params[0]->n_params ; i++ )
+<a name="l00418"></a>00418     {
+<a name="l00419"></a>00419         fscanf(fp, <span class="stringliteral">"%d %d %d %f %f %f %f %f %f %f %f %f\n"</span>, 
+<a name="l00420"></a>00420                     &params[i]->n_params, 
+<a name="l00421"></a>00421                     &params[i]->column, 
+<a name="l00422"></a>00422                     &params[i]->line, 
+<a name="l00423"></a>00423                     &params[i]->wavelength, 
+<a name="l00424"></a>00424                     &params[i]->fit_par[0], 
+<a name="l00425"></a>00425                     &params[i]->fit_par[1], 
+<a name="l00426"></a>00426                     &params[i]->fit_par[2], 
+<a name="l00427"></a>00427                     &params[i]->fit_par[3],
+<a name="l00428"></a>00428                     &params[i]->derv_par[0], 
+<a name="l00429"></a>00429                     &params[i]->derv_par[1], 
+<a name="l00430"></a>00430                     &params[i]->derv_par[2], 
+<a name="l00431"></a>00431                     &params[i]->derv_par[3] ) ; 
+<a name="l00432"></a>00432     }
+<a name="l00433"></a>00433     fclose(fp) ;
+<a name="l00434"></a>00434 }
+<a name="l00435"></a>00435 
+<a name="l00474"></a>00474 <span class="keywordtype">int</span> sinfo_new_find_lines(cpl_image * lineImage, 
+<a name="l00475"></a>00475                <span class="keywordtype">float</span>    * wave_position, 
+<a name="l00476"></a>00476                <span class="keywordtype">float</span>    * wave_intensity,
+<a name="l00477"></a>00477                <span class="keywordtype">int</span>        n_lines, 
+<a name="l00478"></a>00478                <span class="keywordtype">int</span>     ** row_clean,
+<a name="l00479"></a>00479                <span class="keywordtype">float</span>   ** wavelength_clean,
+<a name="l00480"></a>00480                <span class="keywordtype">float</span>      beginWave, 
+<a name="l00481"></a>00481                <span class="keywordtype">float</span>      dispersion1,
+<a name="l00482"></a>00482                <span class="keywordtype">float</span>      dispersion2,
+<a name="l00483"></a>00483                <span class="keywordtype">float</span>      mindiff, 
+<a name="l00484"></a>00484                <span class="keywordtype">int</span>        halfWidth,
+<a name="l00485"></a>00485                <span class="keywordtype">int</span>      * n_found_lines,
+<a name="l00486"></a>00486                <span class="keywordtype">float</span>      sigma,
+<a name="l00487"></a>00487                <span class="keywordtype">int</span>      * sum_lines )
+<a name="l00488"></a>00488 {
+<a name="l00489"></a>00489     <span class="keywordtype">int</span>     ** row ;
+<a name="l00490"></a>00490     <span class="keywordtype">float</span>   ** wavelength ;
+<a name="l00491"></a>00491     <span class="keywordtype">float</span> buf1, buf2 ;
+<a name="l00492"></a>00492     <span class="keywordtype">float</span> meanval ;
+<a name="l00493"></a>00493     <span class="keywordtype">float</span> colmedian ;
+<a name="l00494"></a>00494     <span class="keywordtype">float</span> * column, * tempcol ;
+<a name="l00495"></a>00495     <span class="keywordtype">float</span> * lines ;
+<a name="l00496"></a>00496     <span class="keywordtype">float</span> * conv_lines ;
+<a name="l00497"></a>00497     <span class="keywordtype">float</span> * wave_buffer ;
+<a name="l00498"></a>00498     <span class="keywordtype">float</span> * wave_mem;
+<a name="l00499"></a>00499     <span class="keywordtype">int</span>   * dummy_row ;
+<a name="l00500"></a>00500     <span class="keywordtype">int</span> i, j, k, m ;
+<a name="l00501"></a>00501     <span class="keywordtype">int</span> position ;
+<a name="l00502"></a>00502     <span class="keywordtype">int</span> gmax, gmin ;
+<a name="l00503"></a>00503     <span class="keywordtype">int</span> col ;
+<a name="l00504"></a>00504     <span class="keywordtype">int</span> * row_mem;
+<a name="l00505"></a>00505     <span class="keywordtype">float</span> sum ;
+<a name="l00506"></a>00506     <span class="keywordtype">float</span> angst ;
+<a name="l00507"></a>00507 
+<a name="l00508"></a>00508     <span class="keywordtype">int</span> lx=0;
+<a name="l00509"></a>00509     <span class="keywordtype">int</span> ly=0;
+<a name="l00510"></a>00510     <span class="keywordtype">float</span>* pdata=NULL;
+<a name="l00511"></a>00511 
+<a name="l00512"></a>00512     <span class="keywordflow">if</span> ( NULL == lineImage )
+<a name="l00513"></a>00513     {
+<a name="l00514"></a>00514         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" no image given\n"</span>) ;
+<a name="l00515"></a>00515         <span class="keywordflow">return</span> -1 ;
+<a name="l00516"></a>00516     }
+<a name="l00517"></a>00517 
+<a name="l00518"></a>00518     lx=cpl_image_get_size_x(lineImage);
+<a name="l00519"></a>00519     ly=cpl_image_get_size_y(lineImage);
+<a name="l00520"></a>00520     pdata=cpl_image_get_data_float(lineImage);
+<a name="l00521"></a>00521 
+<a name="l00522"></a>00522     <span class="keywordflow">if</span> ( n_lines <= 0 || NULL == wave_position ) 
+<a name="l00523"></a>00523     {
+<a name="l00524"></a>00524         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" no line list given\n"</span>) ;
+<a name="l00525"></a>00525         <span class="keywordflow">return</span> -1 ;
+<a name="l00526"></a>00526     }
+<a name="l00527"></a>00527     <span class="keywordflow">if</span> ( NULL == wave_intensity ) 
+<a name="l00528"></a>00528     {
+<a name="l00529"></a>00529         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" no intensity list given\n"</span>) ;
+<a name="l00530"></a>00530         <span class="keywordflow">return</span> -1 ;
+<a name="l00531"></a>00531     }
+<a name="l00532"></a>00532      
+<a name="l00533"></a>00533     <span class="keywordflow">if</span> ( dispersion1 == 0. )
+<a name="l00534"></a>00534     {
+<a name="l00535"></a>00535         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" wrong dispersion given\n"</span>) ;
+<a name="l00536"></a>00536         <span class="keywordflow">return</span> -1 ;
+<a name="l00537"></a>00537     }
+<a name="l00538"></a>00538    
+<a name="l00539"></a>00539     <span class="keywordflow">if</span> ( row_clean == NULL )
+<a name="l00540"></a>00540     {
+<a name="l00541"></a>00541         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" row_clean array is not allocated\n"</span>) ;
+<a name="l00542"></a>00542         <span class="keywordflow">return</span> -1 ;
+<a name="l00543"></a>00543     }
+<a name="l00544"></a>00544 
+<a name="l00545"></a>00545     <span class="keywordflow">if</span> ( wavelength_clean == NULL )
+<a name="l00546"></a>00546     {
+<a name="l00547"></a>00547         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" wavelength_clean array is not allocated\n"</span>) ;
+<a name="l00548"></a>00548         <span class="keywordflow">return</span> -1 ;
+<a name="l00549"></a>00549     }
+<a name="l00550"></a>00550 
+<a name="l00551"></a>00551     <span class="keywordflow">if</span> ( beginWave <= 0. )
+<a name="l00552"></a>00552     {
+<a name="l00553"></a>00553         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" impossible beginWave given\n"</span>) ;
+<a name="l00554"></a>00554         <span class="keywordflow">return</span> -1 ;
+<a name="l00555"></a>00555     }
+<a name="l00556"></a>00556     <span class="keywordflow">if</span> ( mindiff < -100. )
+<a name="l00557"></a>00557     {
+<a name="l00558"></a>00558         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" wrong mindiff value\n"</span>) ;
+<a name="l00559"></a>00559         <span class="keywordflow">return</span> -1 ;
+<a name="l00560"></a>00560     }
+<a name="l00561"></a>00561 
+<a name="l00562"></a>00562     <span class="keywordflow">if</span> ( halfWidth <= 0 )
+<a name="l00563"></a>00563     {
+<a name="l00564"></a>00564         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" wrong half width of fit box given\n"</span>) ;
+<a name="l00565"></a>00565         <span class="keywordflow">return</span> -1 ;
+<a name="l00566"></a>00566     }
+<a name="l00567"></a>00567 
+<a name="l00568"></a>00568     <span class="keywordflow">if</span> ( n_found_lines == NULL )
+<a name="l00569"></a>00569     {
+<a name="l00570"></a>00570         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" n_found_lines not allocated\n"</span>) ;
+<a name="l00571"></a>00571         <span class="keywordflow">return</span> -1 ;
+<a name="l00572"></a>00572     }
+<a name="l00573"></a>00573 
+<a name="l00574"></a>00574     <span class="keywordflow">if</span> ( sigma <= 0. || sigma >= ly / 2)
+<a name="l00575"></a>00575     {
+<a name="l00576"></a>00576         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" wrong sigma given\n"</span>) ;
+<a name="l00577"></a>00577         <span class="keywordflow">return</span> -1 ;
+<a name="l00578"></a>00578     }
+<a name="l00579"></a>00579     
+<a name="l00580"></a>00580     <span class="comment">/* allocate memory */</span>
+<a name="l00581"></a>00581     row        = (<span class="keywordtype">int</span>**) cpl_calloc( lx, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>*)) ;
+<a name="l00582"></a>00582     wavelength = (<span class="keywordtype">float</span>**) cpl_calloc( lx, <span class="keyword">sizeof</span>(<span class="keywordtype">float</span>*)) ;
+<a name="l00583"></a>00583     row_mem = cpl_calloc( n_lines*lx, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>) ) ;
+<a name="l00584"></a>00584     wave_mem = cpl_calloc( n_lines*lx, <span class="keyword">sizeof</span>(<span class="keywordtype">float</span>) ) ;
+<a name="l00585"></a>00585     <span class="keywordflow">for</span> ( i = 0 ; i <lx ; i++ )
+<a name="l00586"></a>00586     {
+<a name="l00587"></a>00587         row[i] = row_mem + i*n_lines;
+<a name="l00588"></a>00588         wavelength[i] = wave_mem + i*n_lines;
+<a name="l00589"></a>00589     }
+<a name="l00590"></a>00590 
+<a name="l00591"></a>00591     <span class="comment">/* find if the wavelength is given in microns, nanometers or Angstroem */</span>
+<a name="l00592"></a>00592     <span class="keywordflow">if</span> ( wave_position[0] > 10000. )
+<a name="l00593"></a>00593     {
+<a name="l00594"></a>00594     <span class="comment">/* Angstroem */</span>
+<a name="l00595"></a>00595         angst = 10000. ;
+<a name="l00596"></a>00596     }
+<a name="l00597"></a>00597     <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( wave_position[0] > 1000. && wave_position[0] < 10000. )
+<a name="l00598"></a>00598     {
+<a name="l00599"></a>00599     <span class="comment">/* nanometers */</span>
+<a name="l00600"></a>00600     angst = 1000. ;
+<a name="l00601"></a>00601     }
+<a name="l00602"></a>00602     <span class="keywordflow">else</span>
+<a name="l00603"></a>00603     {
+<a name="l00604"></a>00604     <span class="comment">/* microns */</span>
+<a name="l00605"></a>00605     angst = 1. ;
+<a name="l00606"></a>00606     }
+<a name="l00607"></a>00607 
+<a name="l00608"></a>00608     <span class="comment">/*----------------------------------------------------------------------</span>
+<a name="l00609"></a>00609 <span class="comment">     * compute the mean and median intensity value in the given </span>
+<a name="l00610"></a>00610 <span class="comment">       column and determine if there is enough intensity in the column to </span>
+<a name="l00611"></a>00611 <span class="comment">       do the correlation</span>
+<a name="l00612"></a>00612 <span class="comment">     */</span>
+<a name="l00613"></a>00613     tempcol = (<span class="keywordtype">float</span>*) cpl_calloc(ly, <span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l00614"></a>00614     *sum_lines = 0 ;
+<a name="l00615"></a>00615     buf1 = 0. ;
+<a name="l00616"></a>00616     buf2 = 0. ;
+<a name="l00617"></a>00617     <span class="comment">/* allocate memory */</span>
+<a name="l00618"></a>00618     column      = (<span class="keywordtype">float</span>*) cpl_calloc(ly, <span class="keyword">sizeof</span> (<span class="keywordtype">float</span>)) ;
+<a name="l00619"></a>00619     lines       = (<span class="keywordtype">float</span>*) cpl_calloc(ly, <span class="keyword">sizeof</span> (<span class="keywordtype">float</span>)) ;
+<a name="l00620"></a>00620     conv_lines  = (<span class="keywordtype">float</span>*) cpl_calloc(ly, <span class="keyword">sizeof</span> (<span class="keywordtype">float</span>)) ;
+<a name="l00621"></a>00621     wave_buffer = (<span class="keywordtype">float</span>*) cpl_calloc(ly, <span class="keyword">sizeof</span> (<span class="keywordtype">float</span>)) ;
+<a name="l00622"></a>00622     dummy_row   = (<span class="keywordtype">int</span>*)   cpl_calloc(n_lines, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>)) ;
+<a name="l00623"></a>00623 
+<a name="l00624"></a>00624     <span class="keywordflow">for</span> ( col = 0 ; col < lx ; col++ )
+<a name="l00625"></a>00625     {
+<a name="l00626"></a>00626         n_found_lines[col] = 0 ;
+<a name="l00627"></a>00627         sum = 0. ;
+<a name="l00628"></a>00628         <span class="keywordflow">for</span> ( i = 0 ; i < ly ; i++ )
+<a name="l00629"></a>00629         {
+<a name="l00630"></a>00630             <span class="keywordflow">if</span> (isnan(pdata[col + i*lx]) )
+<a name="l00631"></a>00631             {
+<a name="l00632"></a>00632                 tempcol[i] = 0. ;
+<a name="l00633"></a>00633                 continue ;
+<a name="l00634"></a>00634             }
+<a name="l00635"></a>00635 
+<a name="l00636"></a>00636         sum = sum + pdata[col + i*lx] ;
+<a name="l00637"></a>00637         tempcol[i] = pdata[col + i*lx];
+<a name="l00638"></a>00638         }
+<a name="l00639"></a>00639         meanval = sum / ly ;
+<a name="l00640"></a>00640         <span class="comment">/* lets assume the sinfo_new_median is the background */</span>
+<a name="l00641"></a>00641         colmedian =  sinfo_new_median ( tempcol, ly);
+<a name="l00642"></a>00642 
+<a name="l00643"></a>00643         <span class="keywordflow">if</span> ( meanval - colmedian < mindiff )
+<a name="l00644"></a>00644         {
+<a name="l00645"></a>00645         <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">" sorry, not enough intensity "</span>
+<a name="l00646"></a>00646                               <span class="stringliteral">"(mean: %f, diff: %f) in image column: "</span>
+<a name="l00647"></a>00647                                <span class="stringliteral">"%d to correlate emission lines\n"</span>, 
+<a name="l00648"></a>00648                                 meanval, meanval - colmedian,col) ;
+<a name="l00649"></a>00649         continue ;
+<a name="l00650"></a>00650     }
+<a name="l00651"></a>00651 
+<a name="l00652"></a>00652         <span class="keywordflow">for</span> ( i = 0 ; i < ly ; i++ )
+<a name="l00653"></a>00653           {
+<a name="l00654"></a>00654       conv_lines[i]=0;
+<a name="l00655"></a>00655       wave_buffer[i]=0;
+<a name="l00656"></a>00656     }
+<a name="l00657"></a>00657     <span class="keywordflow">for</span> ( i = 0 ; i < n_lines ; i++ )
+<a name="l00658"></a>00658     {
+<a name="l00659"></a>00659       dummy_row[i] = 0;
+<a name="l00660"></a>00660     }
+<a name="l00661"></a>00661 
+<a name="l00662"></a>00662         <span class="comment">/* go through the column with index col */</span>
+<a name="l00663"></a>00663         <span class="keywordflow">for</span> ( i = 0 ; i < ly ; i++ )
+<a name="l00664"></a>00664         {
+<a name="l00665"></a>00665             <span class="keywordflow">if</span> ( isnan(pdata[col+i*lx]) )
+<a name="l00666"></a>00666             {
+<a name="l00667"></a>00667                 column[i] = 0. ;
+<a name="l00668"></a>00668             }
+<a name="l00669"></a>00669             <span class="keywordflow">else</span>
+<a name="l00670"></a>00670             {
+<a name="l00671"></a>00671                 column[i] = pdata[col + i*lx] ;
+<a name="l00672"></a>00672             }
+<a name="l00673"></a>00673 
+<a name="l00674"></a>00674             <span class="comment">/* determine the line position on the pixels */</span>
+<a name="l00675"></a>00675             <span class="comment">/*lines[i] = (dispersion * (float) i + beginWave) * angst ;*/</span> 
+<a name="l00676"></a>00676             lines[i] = (dispersion1 * (float) (i-ly/2) + 
+<a name="l00677"></a>00677                         dispersion2 * (float) (i-ly/2) * 
+<a name="l00678"></a>00678                                       (float) (i-ly/2) + 
+<a name="l00679"></a>00679                                               beginWave) * angst ; 
+<a name="l00680"></a>00680 
+<a name="l00681"></a>00681             <span class="comment">/* ---------------------------------------------------------------</span>
+<a name="l00682"></a>00682 <span class="comment">             * find the nearest line position for each wavelength in the list </span>
+<a name="l00683"></a>00683 <span class="comment">             * and set this position to the given line intensity as weight </span>
+<a name="l00684"></a>00684 <span class="comment">             */</span>
+<a name="l00685"></a>00685             <span class="keywordflow">for</span> ( j = 0 ; j < n_lines ; j ++ )
+<a name="l00686"></a>00686             {
+<a name="l00687"></a>00687                 buf1 = 0. ;
+<a name="l00688"></a>00688                 buf2 = 0. ;
+<a name="l00689"></a>00689                 <span class="keywordflow">if</span> ( (wave_position[j] >= (lines[i] - 
+<a name="l00690"></a>00690                       fabs(dispersion1)/2.*angst)) && 
+<a name="l00691"></a>00691                      (wave_position[j] <= (lines[i] + 
+<a name="l00692"></a>00692                       fabs(dispersion1)/2.*angst)) ) 
+<a name="l00693"></a>00693                 {
+<a name="l00694"></a>00694                     buf1 = wave_intensity[j] ; <span class="comment">/* set the given line intensity </span>
+<a name="l00695"></a>00695 <span class="comment">                                                  as weight */</span>
+<a name="l00696"></a>00696                     buf2 = wave_position[j] ;
+<a name="l00697"></a>00697                     break ;
+<a name="l00698"></a>00698                 }
+<a name="l00699"></a>00699             }
+<a name="l00700"></a>00700             lines[i] = buf1 ;
+<a name="l00701"></a>00701             wave_buffer[i] = buf2 ; <span class="comment">/* get the wavelength associated </span>
+<a name="l00702"></a>00702 <span class="comment">                                       with the corresponding </span>
+<a name="l00703"></a>00703 <span class="comment">                                           found emission line */</span>
+<a name="l00704"></a>00704     
+<a name="l00705"></a>00705             <span class="comment">/* convolve the artificial spectrum by a Gaussian </span>
+<a name="l00706"></a>00706 <span class="comment">               with given sigma value */</span>
+<a name="l00707"></a>00707             <span class="keywordflow">if</span> ( lines[i] != 0. )
+<a name="l00708"></a>00708             {
+<a name="l00709"></a>00709                 <span class="comment">/* consider only +- 2 sigma */</span>
+<a name="l00710"></a>00710                 gmin = sinfo_new_nint((<span class="keywordtype">float</span>) i - 2. * sigma) ;
+<a name="l00711"></a>00711                 gmax = sinfo_new_nint((<span class="keywordtype">float</span>) i + 2. * sigma) ;
+<a name="l00712"></a>00712 
+<a name="l00713"></a>00713                 <span class="comment">/* be aware of image margins */</span>
+<a name="l00714"></a>00714                 <span class="keywordflow">if</span> ( gmin < 0 )
+<a name="l00715"></a>00715                 {
+<a name="l00716"></a>00716                     gmin = 0 ;
+<a name="l00717"></a>00717                 }
+<a name="l00718"></a>00718                 <span class="keywordflow">if</span> ( gmax >= ly )
+<a name="l00719"></a>00719                 {
+<a name="l00720"></a>00720                     gmax = ly - 1 ;
+<a name="l00721"></a>00721                 } 
+<a name="l00722"></a>00722                 <span class="keywordflow">for</span> ( j = gmin ; j <= gmax ; j++ )
+<a name="l00723"></a>00723                 {
+<a name="l00724"></a>00724                     conv_lines[j] += 
+<a name="l00725"></a>00725                         lines[i] * exp( (<span class="keywordtype">double</span>)( -0.5*((j - i)*(j - i)))/
+<a name="l00726"></a>00726                                         (<span class="keywordtype">double</span>) (sigma*sigma) ) ; 
+<a name="l00727"></a>00727                 }
+<a name="l00728"></a>00728             }
+<a name="l00729"></a>00729         }
+<a name="l00730"></a>00730 
+<a name="l00731"></a>00731         <span class="comment">/* do the cross sinfo_new_correlitioation */</span>
+<a name="l00732"></a>00732         position = INT32_MAX ;
+<a name="l00733"></a>00733         position = sinfo_new_correlation(column+5, conv_lines+5, ly-10 ) ; 
+<a name="l00734"></a>00734         <span class="keywordflow">if</span> ( abs (position) > ly / 4 )
+<a name="l00735"></a>00735         {
+<a name="l00736"></a>00736             <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">" sorry, shift of artificial data relative to"</span>
+<a name="l00737"></a>00737                               <span class="stringliteral">" image (%d) seems to be too high in column: %d"</span>,
+<a name="l00738"></a>00738                               position, col) ;
+<a name="l00739"></a>00739             continue ;
+<a name="l00740"></a>00740         }
+<a name="l00741"></a>00741 
+<a name="l00742"></a>00742         <span class="comment">//AMO we initialize this to -999 and later check that it is not</span>
+<a name="l00743"></a>00743         <span class="comment">//-999 to prevent an invalid read out due to the fact that not</span>
+<a name="l00744"></a>00744         <span class="comment">//all elements of row are filled by the the loop below</span>
+<a name="l00745"></a>00745         <span class="keywordflow">for</span> ( j = 0 ; j < n_lines ; j ++ ) {
+<a name="l00746"></a>00746           row[col][j] = -999;
+<a name="l00747"></a>00747     }
+<a name="l00748"></a>00748 
+<a name="l00749"></a>00749         <span class="comment">//The following loop does not fill all elements</span>
+<a name="l00750"></a>00750         j = 0 ;
+<a name="l00751"></a>00751         <span class="keywordflow">for</span> ( i = 0 ; i < ly ; i ++ )
+<a name="l00752"></a>00752         {
+<a name="l00753"></a>00753             <span class="keywordflow">if</span> ( lines[i] != 0.0 )
+<a name="l00754"></a>00754             {
+<a name="l00755"></a>00755                 <span class="keywordflow">if</span> ( (i - position) >= 0 && (i - position) < ly )
+<a name="l00756"></a>00756                 {
+<a name="l00757"></a>00757                     row[col][j] = i - position ;
+<a name="l00758"></a>00758                     <span class="comment">/* get the wavelength corresponding to </span>
+<a name="l00759"></a>00759 <span class="comment">                       found line row index */</span>
+<a name="l00760"></a>00760                     wavelength[col][j] = wave_buffer[i] / angst ;
+<a name="l00761"></a>00761                     j++ ;
+<a name="l00762"></a>00762                 }
+<a name="l00763"></a>00763             }
+<a name="l00764"></a>00764         }
+<a name="l00765"></a>00765 
+<a name="l00766"></a>00766 
+<a name="l00767"></a>00767         <span class="comment">/* ------------------------------------------------------------------</span>
+<a name="l00768"></a>00768 <span class="comment">         *  determine the row_clean array, that means, take only the row </span>
+<a name="l00769"></a>00769 <span class="comment">            values if the distance between adjacent lines is large enough </span>
+<a name="l00770"></a>00770 <span class="comment">            for the fit</span>
+<a name="l00771"></a>00771 <span class="comment">         */</span>
+<a name="l00772"></a>00772         <span class="comment">//sinfo_msg("lx=%d",lx);</span>
+<a name="l00773"></a>00773         <span class="keywordflow">for</span> ( k = 1 ; k <= j && k<(lx-1); k ++ )
+<a name="l00774"></a>00774         {
+<a name="l00775"></a>00775             <span class="keywordflow">if</span> (dummy_row[k-1] != -1)
+<a name="l00776"></a>00776             {
+<a name="l00777"></a>00777                 dummy_row[k-1] = row[col][k-1] ;
+<a name="l00778"></a>00778             }
+<a name="l00779"></a>00779             <span class="keywordflow">if</span> ( (row[col][k] - row[col][k-1]) <= 2*halfWidth )
+<a name="l00780"></a>00780             {
+<a name="l00781"></a>00781                 dummy_row[k-1] = -1 ;
+<a name="l00782"></a>00782         <span class="keywordflow">if</span> (k<n_lines) {
+<a name="l00783"></a>00783                   dummy_row[k]   = -1 ;
+<a name="l00784"></a>00784         }
+<a name="l00785"></a>00785             }
+<a name="l00786"></a>00786             <span class="comment">/* the following gives invalid read size 4: check that k+1<lx */</span>
+<a name="l00787"></a>00787             
+<a name="l00788"></a>00788             <span class="comment">//sinfo_msg("col=%d k=%d row1=%d row2=%d",</span>
+<a name="l00789"></a>00789             <span class="comment">//           col,k,row[col][k+1],row[col][k]);</span>
+<a name="l00790"></a>00790             <span class="keywordflow">if</span> ( (row[col][j] != -999) && 
+<a name="l00791"></a>00791                  (row[col][k+1] - row[col][k]) <= 2*halfWidth)
+<a name="l00792"></a>00792             {
+<a name="l00793"></a>00793           <span class="keywordflow">if</span> (k<n_lines) {
+<a name="l00794"></a>00794                   dummy_row[k]   = -1 ;
+<a name="l00795"></a>00795           }
+<a name="l00796"></a>00796           <span class="keywordflow">if</span> (k+1<n_lines) {
+<a name="l00797"></a>00797                   dummy_row[k+1] = -1 ;
+<a name="l00798"></a>00798           }
+<a name="l00799"></a>00799             }
+<a name="l00800"></a>00800         }
+<a name="l00801"></a>00801 
+<a name="l00802"></a>00802         m = 0 ;
+<a name="l00803"></a>00803         <span class="keywordflow">for</span> ( k = 0 ; k < j ; k ++ )
+<a name="l00804"></a>00804         {
+<a name="l00805"></a>00805             <span class="keywordflow">if</span> ( dummy_row[k] != -1 && dummy_row[k] != 0 )
+<a name="l00806"></a>00806             {
+<a name="l00807"></a>00807                 row_clean[col][m] = dummy_row[k] ;
+<a name="l00808"></a>00808                 wavelength_clean[col][m] = wavelength[col][k] ;
+<a name="l00809"></a>00809                 m ++ ;
+<a name="l00810"></a>00810             }
+<a name="l00811"></a>00811         }
+<a name="l00812"></a>00812 
+<a name="l00813"></a>00813         n_found_lines[col] = m ;
+<a name="l00814"></a>00814 
+<a name="l00815"></a>00815         *sum_lines += n_found_lines[col] ;
+<a name="l00816"></a>00816     }
+<a name="l00817"></a>00817     cpl_free (column) ;
+<a name="l00818"></a>00818     cpl_free (lines) ;
+<a name="l00819"></a>00819     cpl_free (conv_lines) ;
+<a name="l00820"></a>00820     cpl_free (dummy_row) ;
+<a name="l00821"></a>00821     cpl_free (wave_buffer) ;
+<a name="l00822"></a>00822     cpl_free (row_mem) ;
+<a name="l00823"></a>00823     cpl_free (wave_mem) ;
+<a name="l00824"></a>00824     cpl_free (tempcol) ;
+<a name="l00825"></a>00825     cpl_free (row) ;
+<a name="l00826"></a>00826     cpl_free (wavelength) ;
+<a name="l00827"></a>00827 
+<a name="l00828"></a>00828     <span class="keywordflow">return</span> 0 ;
+<a name="l00829"></a>00829 }
+<a name="l00830"></a>00830 
+<a name="l00840"></a>00840 <span class="keywordtype">int</span> 
+<a name="l00841"></a>00841 sinfo_new_read_list( <span class="keywordtype">char</span> * listname, 
+<a name="l00842"></a>00842                      <span class="keywordtype">float</span> * lineCenter, 
+<a name="l00843"></a>00843                      <span class="keywordtype">float</span> * lineIntensity )
+<a name="l00844"></a>00844 {
+<a name="l00845"></a>00845     FILE * fp ;
+<a name="l00846"></a>00846     <span class="keywordtype">int</span> i, n_lines ;
+<a name="l00847"></a>00847     
+<a name="l00848"></a>00848     <span class="keywordflow">if</span> ( NULL == lineCenter )
+<a name="l00849"></a>00849     {
+<a name="l00850"></a>00850         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" lineCenter array is not allocated\n"</span>) ;
+<a name="l00851"></a>00851         <span class="keywordflow">return</span> -1 ;
+<a name="l00852"></a>00852     }
+<a name="l00853"></a>00853 
+<a name="l00854"></a>00854     <span class="keywordflow">if</span> ( NULL == lineIntensity )
+<a name="l00855"></a>00855     {
+<a name="l00856"></a>00856         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" lineIntensity array is not allocated\n"</span>) ;
+<a name="l00857"></a>00857         <span class="keywordflow">return</span> -1 ;
+<a name="l00858"></a>00858     }
+<a name="l00859"></a>00859 
+<a name="l00860"></a>00860     <span class="keywordflow">if</span> ( NULL == (fp = fopen ( listname, <span class="stringliteral">"r"</span> ) ) )
+<a name="l00861"></a>00861     {
+<a name="l00862"></a>00862         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" cannot open %s\n"</span>, listname) ;
+<a name="l00863"></a>00863         <span class="keywordflow">return</span> -1 ;
+<a name="l00864"></a>00864     }
+<a name="l00865"></a>00865 
+<a name="l00866"></a>00866     i = 0 ;
+<a name="l00867"></a>00867     <span class="keywordflow">while</span> ( fscanf( fp, <span class="stringliteral">"%f %f"</span>, &lineCenter[i], &lineIntensity[i] ) != EOF )
+<a name="l00868"></a>00868     {
+<a name="l00869"></a>00869         i ++ ;
+<a name="l00870"></a>00870     }
+<a name="l00871"></a>00871     n_lines = i ;
+<a name="l00872"></a>00872     fclose(fp) ;
+<a name="l00873"></a>00873            
+<a name="l00874"></a>00874     <span class="keywordflow">return</span> n_lines ;
+<a name="l00875"></a>00875 }
+<a name="l00876"></a>00876 
+<a name="l00877"></a>00877 
+<a name="l00909"></a>00909 <span class="keywordtype">int</span> sinfo_new_line_fit ( cpl_image  *  mergedImage, 
+<a name="l00910"></a>00910               FitParams *  par,
+<a name="l00911"></a>00911               <span class="keywordtype">float</span>        fwhm,
+<a name="l00912"></a>00912               <span class="keywordtype">int</span>          lineInd,
+<a name="l00913"></a>00913               <span class="keywordtype">int</span>          column, 
+<a name="l00914"></a>00914               <span class="keywordtype">int</span>          halfWidth, 
+<a name="l00915"></a>00915               <span class="keywordtype">int</span>          lineRow,
+<a name="l00916"></a>00916               <span class="keywordtype">float</span>        min_amplitude,
+<a name="l00917"></a>00917           Vector    *  line,
+<a name="l00918"></a>00918           <span class="keywordtype">int</span>       *  mpar,
+<a name="l00919"></a>00919           <span class="keywordtype">float</span>     *  xdat,
+<a name="l00920"></a>00920           <span class="keywordtype">float</span>     *  wdat )
+<a name="l00921"></a>00921 {
+<a name="l00922"></a>00922     <span class="keywordtype">int</span> i, j ;
+<a name="l00923"></a>00923     <span class="keywordtype">int</span> iters, xdim, ndat ;
+<a name="l00924"></a>00924     <span class="keywordtype">int</span> numpar, its ;
+<a name="l00925"></a>00925     <span class="keywordtype">int</span> position ;
+<a name="l00926"></a>00926     <span class="keywordtype">float</span> maxval, tol, lab ;
+<a name="l00927"></a>00927     <span class="keywordtype">int</span> lx=0;
+<a name="l00928"></a>00928     <span class="keywordtype">int</span> ly=0;
+<a name="l00929"></a>00929     <span class="keywordtype">float</span>* pdata=NULL;
+<a name="l00930"></a>00930 
+<a name="l00931"></a>00931     <span class="keywordflow">if</span> ( mergedImage == NULL )
+<a name="l00932"></a>00932     {
+<a name="l00933"></a>00933         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" no image given as input\n"</span>) ;
+<a name="l00934"></a>00934         <span class="keywordflow">return</span> -8 ;
+<a name="l00935"></a>00935     }
+<a name="l00936"></a>00936     lx=cpl_image_get_size_x(mergedImage);
+<a name="l00937"></a>00937     ly=cpl_image_get_size_y(mergedImage);
+<a name="l00938"></a>00938     pdata=cpl_image_get_data_float(mergedImage);
+<a name="l00939"></a>00939 
+<a name="l00940"></a>00940 
+<a name="l00941"></a>00941     <span class="keywordflow">if</span> ( par == NULL )
+<a name="l00942"></a>00942     {
+<a name="l00943"></a>00943         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" fit parameters not given\n"</span>) ;
+<a name="l00944"></a>00944         <span class="keywordflow">return</span> -9 ;
+<a name="l00945"></a>00945     }
+<a name="l00946"></a>00946     <span class="keywordflow">if</span> ( column < 0 || column > lx )
+<a name="l00947"></a>00947     {
+<a name="l00948"></a>00948         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" wrong column number\n"</span>) ;
+<a name="l00949"></a>00949         <span class="keywordflow">return</span> -10 ;
+<a name="l00950"></a>00950     }
+<a name="l00951"></a>00951     <span class="keywordflow">if</span> ( halfWidth < 0 || halfWidth > ly )
+<a name="l00952"></a>00952     {
+<a name="l00953"></a>00953         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" wrong width given\n"</span>) ;
+<a name="l00954"></a>00954         <span class="keywordflow">return</span> -11 ;
+<a name="l00955"></a>00955     }
+<a name="l00956"></a>00956     <span class="keywordflow">if</span> ( lineRow < 0 || lineRow > ly )
+<a name="l00957"></a>00957     {
+<a name="l00958"></a>00958         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" wrong number of row of the line given\n"</span>) ;
+<a name="l00959"></a>00959         <span class="keywordflow">return</span> -12 ;
+<a name="l00960"></a>00960     }
+<a name="l00961"></a>00961     <span class="keywordflow">if</span> ( min_amplitude < 1. )
+<a name="l00962"></a>00962     {
+<a name="l00963"></a>00963         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" wrong minimum amplitude\n"</span>) ;
+<a name="l00964"></a>00964         <span class="keywordflow">return</span> -13 ;
+<a name="l00965"></a>00965     }
+<a name="l00966"></a>00966     
+<a name="l00967"></a>00967     <span class="comment">/* initialise the Vector */</span>
+<a name="l00968"></a>00968     <span class="keywordflow">for</span> ( i = 0 ; i < line -> n_elements ; i++) 
+<a name="l00969"></a>00969     {
+<a name="l00970"></a>00970         line->data[i] = 0;
+<a name="l00971"></a>00971     }
+<a name="l00972"></a>00972     
+<a name="l00973"></a>00973     par -> column = column  ;
+<a name="l00974"></a>00974     par -> line   = lineInd ;
+<a name="l00975"></a>00975 
+<a name="l00976"></a>00976     <span class="comment">/* determine the values of the spectral sinfo_vector given as input */</span>
+<a name="l00977"></a>00977     <span class="comment">/* go through the chosen column */</span>
+<a name="l00978"></a>00978 
+<a name="l00979"></a>00979     j = 0 ;
+<a name="l00980"></a>00980     <span class="keywordflow">for</span> ( i = lineRow-halfWidth ; i <= lineRow+halfWidth ; i++ ) 
+<a name="l00981"></a>00981     {
+<a name="l00982"></a>00982         <span class="keywordflow">if</span> ( i < 0 || i >= ly )
+<a name="l00983"></a>00983         {
+<a name="l00984"></a>00984             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" wrong line position or width given\n"</span>) ;
+<a name="l00985"></a>00985             <span class="keywordflow">return</span> -15 ;
+<a name="l00986"></a>00986         }
+<a name="l00987"></a>00987         <span class="keywordflow">else</span>
+<a name="l00988"></a>00988         {
+<a name="l00989"></a>00989             line -> data[j] = pdata[column + i*lx] ;
+<a name="l00990"></a>00990             j ++ ;
+<a name="l00991"></a>00991         }
+<a name="l00992"></a>00992     } 
+<a name="l00993"></a>00993 
+<a name="l00994"></a>00994     <span class="comment">/*-------------------------------------------------------------------- </span>
+<a name="l00995"></a>00995 <span class="comment">     * go through the spectral sinfo_vector </span>
+<a name="l00996"></a>00996 <span class="comment">     * determine the maximum pixel value in the spectral sinfo_vector </span>
+<a name="l00997"></a>00997 <span class="comment">     */</span>
+<a name="l00998"></a>00998     maxval = -FLT_MAX ;
+<a name="l00999"></a>00999     position = -INT32_MAX ;
+<a name="l01000"></a>01000     <span class="keywordflow">for</span> ( i = 0 ; i < line -> n_elements ; i++ )
+<a name="l01001"></a>01001     {
+<a name="l01002"></a>01002         xdat[i] = i ;
+<a name="l01003"></a>01003         wdat[i] = 1.0 ;
+<a name="l01004"></a>01004         <span class="keywordflow">if</span> ( line -> data[i] >= maxval )
+<a name="l01005"></a>01005         {
+<a name="l01006"></a>01006             maxval = line -> data[i] ;
+<a name="l01007"></a>01007             position = i ;
+<a name="l01008"></a>01008         }
+<a name="l01009"></a>01009     }
+<a name="l01010"></a>01010 
+<a name="l01011"></a>01011     <span class="comment">/* set initial values for the fitting routine */</span>
+<a name="l01012"></a>01012     xdim     = XDIM ;
+<a name="l01013"></a>01013     ndat     = line -> n_elements ;
+<a name="l01014"></a>01014     numpar   = MAXPAR ;
+<a name="l01015"></a>01015     tol      = TOL ;
+<a name="l01016"></a>01016     lab      = LAB ;
+<a name="l01017"></a>01017     its      = ITS ;
+<a name="l01018"></a>01018     par -> fit_par[1] = fwhm ;
+<a name="l01019"></a>01019     par -> fit_par[2] = (float) position ;
+<a name="l01020"></a>01020     par -> fit_par[3] = (float) (line -> data[0] + 
+<a name="l01021"></a>01021                                  line -> data[line->n_elements - 1]) / 2.0 ;
+<a name="l01022"></a>01022     par -> fit_par[0]  = maxval - (par -> fit_par[3]) ;
+<a name="l01023"></a>01023 
+<a name="l01024"></a>01024     <span class="comment">/* exclude low signal cases */</span>
+<a name="l01025"></a>01025     <span class="keywordflow">if</span> ( par->fit_par[0] < min_amplitude )
+<a name="l01026"></a>01026     {
+<a name="l01027"></a>01027         cpl_msg_debug (<span class="stringliteral">"sinfo_linefit:"</span>,
+<a name="l01028"></a>01028                        <span class="stringliteral">" sorry, amplitude of line too low to fit: %f"</span>,
+<a name="l01029"></a>01029                        par->fit_par[0] ) ;
+<a name="l01030"></a>01030         <span class="keywordflow">return</span> -16 ;
+<a name="l01031"></a>01031     }
+<a name="l01032"></a>01032 
+<a name="l01033"></a>01033     <span class="keywordflow">for</span> ( i = 0 ; i < MAXPAR ; i++ )
+<a name="l01034"></a>01034     {
+<a name="l01035"></a>01035         par -> derv_par[i] = 0.0 ;
+<a name="l01036"></a>01036         mpar[i] = 1 ;
+<a name="l01037"></a>01037     }
+<a name="l01038"></a>01038 
+<a name="l01039"></a>01039     <span class="comment">/* finally, do the least square fit using a sinfo_gaussian */</span>
+<a name="l01040"></a>01040     <span class="keywordflow">if</span> ( 0 > ( iters = sinfo_new_lsqfit_c( xdat, &xdim, 
+<a name="l01041"></a>01041                                            line -> data, wdat, 
+<a name="l01042"></a>01042                                            &ndat, par -> fit_par,  
+<a name="l01043"></a>01043                                            par -> derv_par, mpar, 
+<a name="l01044"></a>01044                                            &numpar, &tol, &its, &lab )) )  
+<a name="l01045"></a>01045     {
+<a name="l01046"></a>01046         cpl_msg_debug (<span class="stringliteral">"sinfo_linefit:"</span>,
+<a name="l01047"></a>01047                        <span class="stringliteral">" sinfo_new_lsqfit_c: least squares fit failed,"</span>
+<a name="l01048"></a>01048                        <span class="stringliteral">" error no.: %d\n"</span>, iters) ; 
+<a name="l01049"></a>01049         <span class="keywordflow">return</span> -17 ;
+<a name="l01050"></a>01050     }
+<a name="l01051"></a>01051 
+<a name="l01052"></a>01052     <span class="comment">/* correct the fitted position for the given row of the </span>
+<a name="l01053"></a>01053 <span class="comment">       line in image coordinates */</span>
+<a name="l01054"></a>01054     par -> fit_par[2] =  (float) (lineRow - halfWidth) + par -> fit_par[2] ;
+<a name="l01055"></a>01055 
+<a name="l01056"></a>01056     <span class="comment">/* all was o.k. */</span>
+<a name="l01057"></a>01057     <span class="keywordflow">return</span> iters ;
+<a name="l01058"></a>01058 }
+<a name="l01059"></a>01059 
+<a name="l01084"></a>01084 <span class="keywordtype">int</span> sinfo_new_fit_lines ( cpl_image  *  line_image, 
+<a name="l01085"></a>01085                FitParams ** allParams,
+<a name="l01086"></a>01086                <span class="keywordtype">float</span>        fwhm,
+<a name="l01087"></a>01087                <span class="keywordtype">int</span>       *  n_lines, 
+<a name="l01088"></a>01088                <span class="keywordtype">int</span>       ** row,
+<a name="l01089"></a>01089                <span class="keywordtype">float</span>     ** wavelength, 
+<a name="l01090"></a>01090                <span class="keywordtype">int</span>          width,
+<a name="l01091"></a>01091                <span class="keywordtype">float</span>        min_amplitude ) 
+<a name="l01092"></a>01092 {
+<a name="l01093"></a>01093     <span class="keywordtype">int</span> i, k, l ;
+<a name="l01094"></a>01094     <span class="keywordtype">int</span> result ;
+<a name="l01095"></a>01095     Vector * line;
+<a name="l01096"></a>01096     <span class="keywordtype">int</span>    * mpar;
+<a name="l01097"></a>01097     <span class="keywordtype">float</span>  * xdat, * wdat;
+<a name="l01098"></a>01098     <span class="keywordtype">int</span> lx=0;
+<a name="l01099"></a>01099     <span class="keywordtype">int</span> ly=0;
+<a name="l01100"></a>01100     <span class="keywordtype">float</span>* pdata=NULL;
+<a name="l01101"></a>01101 
+<a name="l01102"></a>01102     <span class="keywordflow">if</span> ( line_image == NULL )
+<a name="l01103"></a>01103     {
+<a name="l01104"></a>01104         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" no image given\n"</span>) ;
+<a name="l01105"></a>01105         <span class="keywordflow">return</span> -18 ;
+<a name="l01106"></a>01106     }
+<a name="l01107"></a>01107     lx=cpl_image_get_size_x(line_image);
+<a name="l01108"></a>01108     ly=cpl_image_get_size_y(line_image);
+<a name="l01109"></a>01109     pdata=cpl_image_get_data_float(line_image);
+<a name="l01110"></a>01110 
+<a name="l01111"></a>01111     <span class="keywordflow">if</span> ( n_lines == NULL )
+<a name="l01112"></a>01112     {
+<a name="l01113"></a>01113         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" no counter of emission lines\n"</span>) ;
+<a name="l01114"></a>01114         <span class="keywordflow">return</span> -19 ;
+<a name="l01115"></a>01115     } 
+<a name="l01116"></a>01116     <span class="keywordflow">if</span> ( row == NULL || width <= 0 )
+<a name="l01117"></a>01117     {
+<a name="l01118"></a>01118         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" row or width vectors are empty\n"</span>) ;
+<a name="l01119"></a>01119         <span class="keywordflow">return</span> -20 ;
+<a name="l01120"></a>01120     }
+<a name="l01121"></a>01121     <span class="keywordflow">if</span> ( wavelength == NULL )
+<a name="l01122"></a>01122     {
+<a name="l01123"></a>01123         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" no wavelength array given\n"</span>) ;
+<a name="l01124"></a>01124         <span class="keywordflow">return</span> -21 ;
+<a name="l01125"></a>01125     }
+<a name="l01126"></a>01126 
+<a name="l01127"></a>01127     k = 0 ;
+<a name="l01128"></a>01128 
+<a name="l01129"></a>01129     <span class="comment">/* allocate memory for the spectral sinfo_vector */</span>
+<a name="l01130"></a>01130     line = sinfo_new_vector (2*width + 1) ;
+<a name="l01131"></a>01131     <span class="comment">/* allocate memory */</span>
+<a name="l01132"></a>01132     xdat = (<span class="keywordtype">float</span> *) cpl_calloc( line -> n_elements, <span class="keyword">sizeof</span> (<span class="keywordtype">float</span>) ) ;
+<a name="l01133"></a>01133     wdat = (<span class="keywordtype">float</span> *) cpl_calloc( line -> n_elements, <span class="keyword">sizeof</span> (<span class="keywordtype">float</span>) ) ;
+<a name="l01134"></a>01134     mpar = (<span class="keywordtype">int</span> *)   cpl_calloc( MAXPAR, <span class="keyword">sizeof</span> (<span class="keywordtype">int</span>) ) ;
+<a name="l01135"></a>01135     
+<a name="l01136"></a>01136     <span class="comment">/* go through the columns */</span>
+<a name="l01137"></a>01137     <span class="keywordflow">for</span> ( i = 0 ; i < lx ; i++ )
+<a name="l01138"></a>01138     {
+<a name="l01139"></a>01139         <span class="keywordflow">if</span> ( n_lines[i] == 0 )
+<a name="l01140"></a>01140         {
+<a name="l01141"></a>01141             continue ;
+<a name="l01142"></a>01142         }
+<a name="l01143"></a>01143         <span class="comment">/* go through the emission lines in a column */</span>
+<a name="l01144"></a>01144         <span class="keywordflow">for</span> ( l = 0 ; l < n_lines[i] ; l++ )
+<a name="l01145"></a>01145         {
+<a name="l01146"></a>01146             <span class="keywordflow">if</span> ( row[i][l] <= 0 )
+<a name="l01147"></a>01147             {
+<a name="l01148"></a>01148                 continue ;
+<a name="l01149"></a>01149             }
+<a name="l01150"></a>01150 
+<a name="l01151"></a>01151             <span class="comment">/* --------------------------------------------------------------</span>
+<a name="l01152"></a>01152 <span class="comment">             * fit the single lines using sinfo_linefit and store the </span>
+<a name="l01153"></a>01153 <span class="comment">               parameters in</span>
+<a name="l01154"></a>01154 <span class="comment">             * an array of the FitParams data structure allParams[].</span>
+<a name="l01155"></a>01155 <span class="comment">             */</span> 
+<a name="l01156"></a>01156             <span class="keywordflow">if</span> ( (result = sinfo_new_line_fit ( line_image, 
+<a name="l01157"></a>01157                                                 allParams[k], fwhm, l, i, 
+<a name="l01158"></a>01158                                                 width, row[i][l], 
+<a name="l01159"></a>01159                                                 min_amplitude,line,mpar,
+<a name="l01160"></a>01160                                                 xdat,wdat ) ) < 0 )
+<a name="l01161"></a>01161             {
+<a name="l01162"></a>01162                 cpl_msg_debug (<span class="stringliteral">"sinfo_fitLines:"</span>,
+<a name="l01163"></a>01163                                <span class="stringliteral">" sinfo_linefit failed, error no.: %d,"</span>
+<a name="l01164"></a>01164                                <span class="stringliteral">" column: %d, row: %d, line: %d\n"</span>, 
+<a name="l01165"></a>01165                                result, i, row[i][l], l) ;
+<a name="l01166"></a>01166                 continue ;
+<a name="l01167"></a>01167             }
+<a name="l01168"></a>01168             <span class="keywordflow">if</span> ( (allParams[k] -> fit_par[0] <= 0.) || 
+<a name="l01169"></a>01169                  (allParams[k] -> fit_par[1] <= 0.)
+<a name="l01170"></a>01170                   || (allParams[k] -> fit_par[2] <= 0.) )
+<a name="l01171"></a>01171             {
+<a name="l01172"></a>01172                 <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a> (<span class="stringliteral">" negative fit parameters in column: %d,"</span>
+<a name="l01173"></a>01173                                    <span class="stringliteral">" line: %d\n"</span>, i, l) ;
+<a name="l01174"></a>01174                 continue ;
+<a name="l01175"></a>01175             }
+<a name="l01176"></a>01176             allParams[k] -> wavelength = wavelength[i][l] ;
+<a name="l01177"></a>01177             k++ ;
+<a name="l01178"></a>01178         }
+<a name="l01179"></a>01179     }
+<a name="l01180"></a>01180 
+<a name="l01181"></a>01181     <span class="comment">/* free memory */</span>
+<a name="l01182"></a>01182     sinfo_new_destroy_vector(line);
+<a name="l01183"></a>01183     cpl_free(xdat);
+<a name="l01184"></a>01184     cpl_free(wdat);
+<a name="l01185"></a>01185     cpl_free(mpar);
+<a name="l01186"></a>01186     
+<a name="l01187"></a>01187     <span class="comment">/* all is o.k. */</span>
+<a name="l01188"></a>01188     <span class="keywordflow">return</span> k ;
+<a name="l01189"></a>01189 }    
+<a name="l01190"></a>01190 
+<a name="l01218"></a>01218 <span class="keywordtype">float</span> sinfo_new_polyfit( FitParams ** par,
+<a name="l01219"></a>01219                <span class="keywordtype">int</span>          column,
+<a name="l01220"></a>01220                <span class="keywordtype">int</span>          n_lines,
+<a name="l01221"></a>01221                <span class="keywordtype">int</span>          n_rows,
+<a name="l01222"></a>01222                <span class="keywordtype">float</span>        dispersion,
+<a name="l01223"></a>01223                <span class="keywordtype">float</span>        max_residual,
+<a name="l01224"></a>01224                <span class="keywordtype">float</span> *      acoefs,
+<a name="l01225"></a>01225                <span class="keywordtype">float</span> *      dacoefs,
+<a name="l01226"></a>01226                <span class="keywordtype">int</span>   *      n_reject,
+<a name="l01227"></a>01227                <span class="keywordtype">int</span>          n_fitcoefs )
+<a name="l01228"></a>01228 {
+<a name="l01229"></a>01229     <span class="keywordtype">float</span> ** ucoefs, ** vcoefs, ** covar ;
+<a name="l01230"></a>01230     <span class="keywordtype">float</span> *mem;
+<a name="l01231"></a>01231     <span class="keywordtype">float</span> * lambda, * posit ;
+<a name="l01232"></a>01232     <span class="keywordtype">float</span> * weight, * resid ;
+<a name="l01233"></a>01233     <span class="keywordtype">float</span> * newlam, * newpos, * newwet ;
+<a name="l01234"></a>01234     <span class="keywordtype">float</span> * wcoefs=NULL ;
+<a name="l01235"></a>01235     <span class="keywordtype">float</span> chisq, result ;
+<a name="l01236"></a>01236     <span class="keywordtype">float</span> offset ;
+<a name="l01237"></a>01237     <span class="keywordtype">int</span> num, found ;
+<a name="l01238"></a>01238     <span class="keywordtype">int</span> i, j, k, n ;
+<a name="l01239"></a>01239 
+<a name="l01240"></a>01240     <span class="comment">/* reset the fit coefficients and their errors */</span>
+<a name="l01241"></a>01241     <span class="keywordflow">for</span> ( i = 0 ; i < n_fitcoefs ; i++ )
+<a name="l01242"></a>01242     {
+<a name="l01243"></a>01243         acoefs[i]  = 0. ;
+<a name="l01244"></a>01244         dacoefs[i] = 0. ;
+<a name="l01245"></a>01245     }
+<a name="l01246"></a>01246     <span class="keywordflow">if</span> ( NULL == par )
+<a name="l01247"></a>01247     {
+<a name="l01248"></a>01248         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" no fit params given\n"</span>);
+<a name="l01249"></a>01249         <span class="keywordflow">return</span> FLT_MAX ;
+<a name="l01250"></a>01250     }
+<a name="l01251"></a>01251 
+<a name="l01252"></a>01252     <span class="keywordflow">if</span> ( 0 >= n_lines )
+<a name="l01253"></a>01253     {
+<a name="l01254"></a>01254       <span class="comment">/*</span>
+<a name="l01255"></a>01255 <span class="comment">        sinfo_msg_warning (" sorry, number of lines is wrong") ;</span>
+<a name="l01256"></a>01256 <span class="comment">      */</span>
+<a name="l01257"></a>01257         <span class="keywordflow">return</span> FLT_MAX ;
+<a name="l01258"></a>01258     }
+<a name="l01259"></a>01259     <span class="keywordflow">if</span> ( 0 >= n_rows )
+<a name="l01260"></a>01260     {
+<a name="l01261"></a>01261         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" sorry, number of rows is wrong"</span>) ;
+<a name="l01262"></a>01262         <span class="keywordflow">return</span> FLT_MAX ;
+<a name="l01263"></a>01263     }
+<a name="l01264"></a>01264     <span class="keywordflow">if</span> ( dispersion == 0. )
+<a name="l01265"></a>01265     {
+<a name="l01266"></a>01266         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" sorry, wrong dispersion given"</span>) ;
+<a name="l01267"></a>01267         <span class="keywordflow">return</span> FLT_MAX ;
+<a name="l01268"></a>01268     }
+<a name="l01269"></a>01269 
+<a name="l01270"></a>01270     offset = (float)(n_rows - 1)/2. ;
+<a name="l01271"></a>01271 
+<a name="l01272"></a>01272     <span class="comment">/* allocate memory */</span>
+<a name="l01273"></a>01273     
+<a name="l01274"></a>01274     mem = (<span class="keywordtype">float</span>*) cpl_calloc( n_lines*7, <span class="keyword">sizeof</span> (<span class="keywordtype">float</span>) ) ;
+<a name="l01275"></a>01275     lambda = mem;
+<a name="l01276"></a>01276     posit  = mem + n_lines;
+<a name="l01277"></a>01277     weight = mem + n_lines*2;
+<a name="l01278"></a>01278     resid  = mem + n_lines*3;
+<a name="l01279"></a>01279     newlam = mem + n_lines*4;
+<a name="l01280"></a>01280     newpos = mem + n_lines*5;
+<a name="l01281"></a>01281     newwet = mem + n_lines*6;
+<a name="l01282"></a>01282     
+<a name="l01283"></a>01283     <span class="comment">/*lambda = (float*) cpl_calloc( n_lines, sizeof (float) ) ;</span>
+<a name="l01284"></a>01284 <span class="comment">    posit  = (float*) cpl_calloc( n_lines, sizeof (float) ) ;</span>
+<a name="l01285"></a>01285 <span class="comment">    weight = (float*) cpl_calloc( n_lines, sizeof (float) ) ;</span>
+<a name="l01286"></a>01286 <span class="comment">    resid  = (float*) cpl_calloc( n_lines, sizeof (float) ) ;</span>
+<a name="l01287"></a>01287 <span class="comment">    newlam = (float*) cpl_calloc( n_lines, sizeof (float) ) ;</span>
+<a name="l01288"></a>01288 <span class="comment">    newpos = (float*) cpl_calloc( n_lines, sizeof (float) ) ;</span>
+<a name="l01289"></a>01289 <span class="comment">    newwet = (float*) cpl_calloc( n_lines, sizeof (float) ) ;*/</span>
+<a name="l01290"></a>01290 
+<a name="l01291"></a>01291     <span class="comment">/* allocate coefficient matrices*/</span>
+<a name="l01292"></a>01292     ucoefs = sinfo_matrix ( 1, n_lines, 1, n_fitcoefs ) ;
+<a name="l01293"></a>01293     vcoefs = sinfo_matrix ( 1, n_lines, 1, n_fitcoefs ) ;
+<a name="l01294"></a>01294     covar  = sinfo_matrix ( 1, n_fitcoefs, 1, n_fitcoefs ) ;
+<a name="l01295"></a>01295     wcoefs=cpl_calloc(n_fitcoefs,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l01296"></a>01296 
+<a name="l01297"></a>01297     <span class="comment">/* go through all fit parameters */</span>
+<a name="l01298"></a>01298     n = 0 ;
+<a name="l01299"></a>01299     <span class="keywordflow">for</span> ( i = 0 ; i < (par[0] -> n_params) ; i ++ )
+<a name="l01300"></a>01300     {
+<a name="l01301"></a>01301         found = -1 ;
+<a name="l01302"></a>01302         <span class="comment">/* find the given column and go through the lines in that column */</span>
+<a name="l01303"></a>01303         <span class="keywordflow">for</span> ( j = 0 ; j < n_lines ; j ++ )
+<a name="l01304"></a>01304         {
+<a name="l01305"></a>01305             <span class="keywordflow">if</span> ( (par[i] -> column == column) && (par[i] -> line == j) )
+<a name="l01306"></a>01306             {
+<a name="l01307"></a>01307                 found = i ;
+<a name="l01308"></a>01308             }
+<a name="l01309"></a>01309             <span class="keywordflow">else</span>
+<a name="l01310"></a>01310             {
+<a name="l01311"></a>01311                 continue ;
+<a name="l01312"></a>01312             }
+<a name="l01313"></a>01313 
+<a name="l01314"></a>01314             <span class="comment">/* store only fit params with reasonable values */</span>
+<a name="l01315"></a>01315             <span class="keywordflow">if</span> ( par[found] -> derv_par[2] != 0. && 
+<a name="l01316"></a>01316                  par[found] -> fit_par[2] > 0. &&
+<a name="l01317"></a>01317                  par[found] -> wavelength > 0. && 
+<a name="l01318"></a>01318                  par[found] -> fit_par[1] > 0. &&
+<a name="l01319"></a>01319                  par[found] -> fit_par[0] > 0. )
+<a name="l01320"></a>01320             {
+<a name="l01321"></a>01321                 <span class="comment">/* ----------------------------------------------------------</span>
+<a name="l01322"></a>01322 <span class="comment">                 * store the found position, error of the position as </span>
+<a name="l01323"></a>01323 <span class="comment">                   weight and the associated</span>
+<a name="l01324"></a>01324 <span class="comment">                 * wavelength values of the fitted lines</span>
+<a name="l01325"></a>01325 <span class="comment">                 */</span>
+<a name="l01326"></a>01326                 posit[n]  = par[found] -> fit_par[2] ;
+<a name="l01327"></a>01327                 weight[n] = par[found] -> derv_par[2] ;
+<a name="l01328"></a>01328                 lambda[n] = par[found] -> wavelength ;
+<a name="l01329"></a>01329                 n ++ ;
+<a name="l01330"></a>01330             }
+<a name="l01331"></a>01331             <span class="keywordflow">else</span>
+<a name="l01332"></a>01332             {
+<a name="l01333"></a>01333                 continue ;
+<a name="l01334"></a>01334             }
+<a name="l01335"></a>01335         }
+<a name="l01336"></a>01336 
+<a name="l01337"></a>01337     }
+<a name="l01338"></a>01338 
+<a name="l01339"></a>01339     num = n ;
+<a name="l01340"></a>01340     <span class="keywordflow">if</span> ( num < n_fitcoefs )
+<a name="l01341"></a>01341     {
+<a name="l01342"></a>01342         <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"not enough lines found in column %d to "</span>
+<a name="l01343"></a>01343                           <span class="stringliteral">"determine the three coefficients.\n"</span>, column) ;
+<a name="l01344"></a>01344         <span class="keywordflow">for</span> ( i = 0 ; i < n_fitcoefs ; i++ )
+<a name="l01345"></a>01345         {
+<a name="l01346"></a>01346             acoefs[i]  = ZERO ;
+<a name="l01347"></a>01347             dacoefs[i] = ZERO ;
+<a name="l01348"></a>01348         }
+<a name="l01349"></a>01349         sinfo_free_matrix ( ucoefs, 1<span class="comment">/*, n_lines*/</span>,    1<span class="comment">/*, n_fitcoefs*/</span> ) ;
+<a name="l01350"></a>01350         sinfo_free_matrix ( vcoefs, 1<span class="comment">/*, n_lines*/</span>,    1<span class="comment">/*, n_fitcoefs*/</span> ) ;
+<a name="l01351"></a>01351         sinfo_free_matrix ( covar,  1<span class="comment">/*, n_fitcoefs*/</span>, 1<span class="comment">/*, n_fitcoefs*/</span> ) ;
+<a name="l01352"></a>01352         <span class="comment">/*cpl_free (lambda) ;</span>
+<a name="l01353"></a>01353 <span class="comment">        cpl_free (posit) ;</span>
+<a name="l01354"></a>01354 <span class="comment">        cpl_free (weight) ;</span>
+<a name="l01355"></a>01355 <span class="comment">        cpl_free (resid) ;</span>
+<a name="l01356"></a>01356 <span class="comment">        cpl_free (newlam) ;</span>
+<a name="l01357"></a>01357 <span class="comment">        cpl_free (newpos) ;</span>
+<a name="l01358"></a>01358 <span class="comment">        cpl_free (newwet) ;*/</span>
+<a name="l01359"></a>01359     cpl_free (mem);
+<a name="l01360"></a>01360         <span class="keywordflow">return</span> FLT_MAX ;
+<a name="l01361"></a>01361     }
+<a name="l01362"></a>01362 
+<a name="l01363"></a>01363     <span class="comment">/*-------------------------------------------------------------------------</span>
+<a name="l01364"></a>01364 <span class="comment">     * scale the pixel position values to smaller than 1 and transform </span>
+<a name="l01365"></a>01365 <span class="comment">       the weights to wavelength units </span>
+<a name="l01366"></a>01366 <span class="comment">     */</span>
+<a name="l01367"></a>01367 
+<a name="l01368"></a>01368     <span class="keywordflow">for</span> ( i = 0 ; i < num ; i ++ )
+<a name="l01369"></a>01369     {
+<a name="l01370"></a>01370         posit[i] = (posit[i] - offset)/offset ;
+<a name="l01371"></a>01371         weight[i] *= fabs(dispersion) ;
+<a name="l01372"></a>01372     }
+<a name="l01373"></a>01373 
+<a name="l01374"></a>01374     <span class="comment">/* do the fit using the singular value decomposition method */</span>
+<a name="l01375"></a>01375     sinfo_svd_fitting( posit - 1, lambda - 1, 
+<a name="l01376"></a>01376                       weight - 1, num, acoefs-1, n_fitcoefs,
+<a name="l01377"></a>01377             ucoefs, vcoefs, wcoefs-1, covar, &chisq, sinfo_fpol ) ;
+<a name="l01378"></a>01378 
+<a name="l01379"></a>01379     <span class="comment">/* scale the linear and the quadratic coefficient */</span>
+<a name="l01380"></a>01380     <span class="keywordflow">for</span> ( i = 1 ; i < n_fitcoefs ; i++ )
+<a name="l01381"></a>01381     {
+<a name="l01382"></a>01382         acoefs[i] /= pow(offset, i) ;
+<a name="l01383"></a>01383     }
+<a name="l01384"></a>01384 
+<a name="l01385"></a>01385     <span class="comment">/* now that we have determined the fit coefficients, find the residuals */</span>
+<a name="l01386"></a>01386     *n_reject = 0 ;
+<a name="l01387"></a>01387 
+<a name="l01388"></a>01388     j = 0 ;
+<a name="l01389"></a>01389     <span class="keywordflow">for</span> ( i = 0 ; i < num ; i++ )
+<a name="l01390"></a>01390     {
+<a name="l01391"></a>01391         result = 0. ;
+<a name="l01392"></a>01392         <span class="keywordflow">for</span> ( k = 0 ; k < n_fitcoefs ; k++ )
+<a name="l01393"></a>01393         {
+<a name="l01394"></a>01394             result += acoefs[k] * pow(posit[i], k) ;
+<a name="l01395"></a>01395         }
+<a name="l01396"></a>01396 
+<a name="l01397"></a>01397         resid[i] = lambda[i] - result ;
+<a name="l01398"></a>01398 
+<a name="l01399"></a>01399         <span class="keywordflow">if</span> ( fabs( resid[i] ) > max_residual)
+<a name="l01400"></a>01400         {
+<a name="l01401"></a>01401             (*n_reject) ++ ;
+<a name="l01402"></a>01402         }
+<a name="l01403"></a>01403         <span class="keywordflow">else</span>
+<a name="l01404"></a>01404         {
+<a name="l01405"></a>01405             newlam[j] = lambda[i] ;
+<a name="l01406"></a>01406             newpos[j] = posit[i] ;
+<a name="l01407"></a>01407             newwet[j] = weight[i] ;
+<a name="l01408"></a>01408             j++ ;
+<a name="l01409"></a>01409         }
+<a name="l01410"></a>01410     }
+<a name="l01411"></a>01411 
+<a name="l01412"></a>01412     num = j ;
+<a name="l01413"></a>01413     <span class="keywordflow">if</span> ( num >= n_fitcoefs )
+<a name="l01414"></a>01414     {
+<a name="l01415"></a>01415         sinfo_svd_fitting( newpos - 1, newlam - 1, 
+<a name="l01416"></a>01416                            newwet - 1, num, acoefs-1, n_fitcoefs, ucoefs,
+<a name="l01417"></a>01417                 vcoefs, wcoefs-1, covar, &chisq, sinfo_fpol ) ;
+<a name="l01418"></a>01418 
+<a name="l01419"></a>01419         <span class="comment">/* scale the resulting coefficients */</span>
+<a name="l01420"></a>01420         <span class="keywordflow">for</span> ( i = 0 ; i < n_fitcoefs ; i++ )
+<a name="l01421"></a>01421         {
+<a name="l01422"></a>01422             acoefs[i] /= pow(offset, i) ;
+<a name="l01423"></a>01423             dacoefs[i] = sqrt( (<span class="keywordtype">double</span>) covar[i+1][i+1] ) / pow(offset, i) ;
+<a name="l01424"></a>01424         }
+<a name="l01425"></a>01425     }
+<a name="l01426"></a>01426     <span class="keywordflow">else</span>
+<a name="l01427"></a>01427     {
+<a name="l01428"></a>01428         <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a> (<span class="stringliteral">" too many lines rejected (number: %d) "</span>
+<a name="l01429"></a>01429                            <span class="stringliteral">"due to high residuals, fit coefficients are set "</span>
+<a name="l01430"></a>01430                            <span class="stringliteral">"zero, in column: %d\n"</span>, *n_reject, column) ;
+<a name="l01431"></a>01431         <span class="keywordflow">for</span> ( i = 0 ; i < n_fitcoefs ; i++ )
+<a name="l01432"></a>01432         {
+<a name="l01433"></a>01433             acoefs[i]  = ZERO ;
+<a name="l01434"></a>01434             dacoefs[i] = ZERO ;
+<a name="l01435"></a>01435         }
+<a name="l01436"></a>01436     }
+<a name="l01437"></a>01437 
+<a name="l01438"></a>01438     sinfo_free_matrix ( ucoefs, 1<span class="comment">/*, n_lines*/</span>,    1<span class="comment">/*, n_fitcoefs*/</span> ) ;
+<a name="l01439"></a>01439     sinfo_free_matrix ( vcoefs, 1<span class="comment">/*, n_lines*/</span>,    1<span class="comment">/*, n_fitcoefs*/</span> ) ;
+<a name="l01440"></a>01440     sinfo_free_matrix ( covar,  1<span class="comment">/*, n_fitcoefs*/</span>, 1<span class="comment">/*, n_fitcoefs*/</span> ) ;
+<a name="l01441"></a>01441     <span class="comment">/*cpl_free (lambda) ;</span>
+<a name="l01442"></a>01442 <span class="comment">    cpl_free (posit) ;</span>
+<a name="l01443"></a>01443 <span class="comment">    cpl_free (weight) ;</span>
+<a name="l01444"></a>01444 <span class="comment">    cpl_free (resid) ;</span>
+<a name="l01445"></a>01445 <span class="comment">    cpl_free (newlam) ;</span>
+<a name="l01446"></a>01446 <span class="comment">    cpl_free (newpos) ;</span>
+<a name="l01447"></a>01447 <span class="comment">    cpl_free (newwet) ;*/</span>
+<a name="l01448"></a>01448     cpl_free (mem);
+<a name="l01449"></a>01449     cpl_free(wcoefs) ;
+<a name="l01450"></a>01450 
+<a name="l01451"></a>01451     <span class="keywordflow">return</span> chisq ;
+<a name="l01452"></a>01452 }
+<a name="l01453"></a>01453 
+<a name="l01470"></a>01470 <span class="keywordtype">float</span> sinfo_new_coefs_cross_fit ( <span class="keywordtype">int</span>      n_columns,
+<a name="l01471"></a>01471                       <span class="keywordtype">float</span> *  acoefs,
+<a name="l01472"></a>01472                       <span class="keywordtype">float</span> *  dacoefs,
+<a name="l01473"></a>01473                       <span class="keywordtype">float</span> *  bcoefs,
+<a name="l01474"></a>01474                       <span class="keywordtype">int</span>      n_fitcoefs,
+<a name="l01475"></a>01475                       <span class="keywordtype">float</span>    sigma_factor )
+<a name="l01476"></a>01476 {
+<a name="l01477"></a>01477     <span class="keywordtype">float</span> col_index;
+<a name="l01478"></a>01478     <span class="keywordtype">float</span>* sub_col_index=NULL ;
+<a name="l01479"></a>01479     <span class="keywordtype">float</span>* sub_acoefs=NULL ;
+<a name="l01480"></a>01480     <span class="keywordtype">float</span>* sub_dacoefs=NULL ;
+<a name="l01481"></a>01481     <span class="keywordtype">float</span>* wcoefs=NULL ;
+<a name="l01482"></a>01482     <span class="keywordtype">float</span> ** ucoefs, **vcoefs, **covar ;
+<a name="l01483"></a>01483     <span class="keywordtype">float</span> chisq ;
+<a name="l01484"></a>01484     <span class="keywordtype">float</span> * acoefsclean ;
+<a name="l01485"></a>01485     <span class="keywordtype">double</span> sum, sumq, mean ;
+<a name="l01486"></a>01486     <span class="keywordtype">double</span> sigma ;
+<a name="l01487"></a>01487     <span class="keywordtype">double</span> cliphi, cliplo ;
+<a name="l01488"></a>01488     <span class="keywordtype">float</span> offset ;
+<a name="l01489"></a>01489     <span class="keywordtype">int</span> i, n, num, ndata ;
+<a name="l01490"></a>01490     <span class="keywordtype">int</span> nc ;
+<a name="l01491"></a>01491 
+<a name="l01492"></a>01492 
+<a name="l01493"></a>01493     <span class="keywordflow">if</span> ( n_columns < 1 )
+<a name="l01494"></a>01494     {
+<a name="l01495"></a>01495         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" wrong number of image columns given\n"</span>) ;
+<a name="l01496"></a>01496         <span class="keywordflow">return</span> FLT_MAX ;
+<a name="l01497"></a>01497     }
+<a name="l01498"></a>01498     <span class="keywordflow">if</span> ( acoefs == NULL || dacoefs == NULL )
+<a name="l01499"></a>01499     {
+<a name="l01500"></a>01500         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" coeffs or errors of coefficients are not given\n"</span>) ;
+<a name="l01501"></a>01501         <span class="keywordflow">return</span> FLT_MAX ;
+<a name="l01502"></a>01502     }
+<a name="l01503"></a>01503     <span class="keywordflow">if</span> ( bcoefs == NULL )
+<a name="l01504"></a>01504     {
+<a name="l01505"></a>01505         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" coeffs are not allocated\n"</span>) ;
+<a name="l01506"></a>01506         <span class="keywordflow">return</span> FLT_MAX ;
+<a name="l01507"></a>01507     }
+<a name="l01508"></a>01508 
+<a name="l01509"></a>01509     <span class="keywordflow">if</span> ( n_fitcoefs < 1 )
+<a name="l01510"></a>01510     {
+<a name="l01511"></a>01511         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" wrong number of fit coefficients\n"</span>) ;
+<a name="l01512"></a>01512         <span class="keywordflow">return</span> FLT_MAX ;
+<a name="l01513"></a>01513     }
+<a name="l01514"></a>01514     <span class="keywordflow">if</span> ( sigma_factor <= 0. )
+<a name="l01515"></a>01515     {
+<a name="l01516"></a>01516         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" impossible sigma_factor given!\n"</span>) ;
+<a name="l01517"></a>01517         <span class="keywordflow">return</span> FLT_MAX ;
+<a name="l01518"></a>01518     }
+<a name="l01519"></a>01519 
+<a name="l01520"></a>01520     offset = (float)(n_columns - 1) / 2. ;
+<a name="l01521"></a>01521 
+<a name="l01522"></a>01522     <span class="comment">/* ----------------------------------------------------------</span>
+<a name="l01523"></a>01523 <span class="comment">     * determine the clean mean and sigma value of the coefficients,</span>
+<a name="l01524"></a>01524 <span class="comment">     * that means reject 10 % of the extreme low and high values</span>
+<a name="l01525"></a>01525 <span class="comment">     */</span>
+<a name="l01526"></a>01526 
+<a name="l01527"></a>01527     wcoefs=cpl_calloc(n_fitcoefs,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l01528"></a>01528 
+<a name="l01529"></a>01529     nc = 0 ;
+<a name="l01530"></a>01530     <span class="keywordflow">for</span> ( i = 0 ; i < n_columns ; i++ )
+<a name="l01531"></a>01531     {
+<a name="l01532"></a>01532         <span class="keywordflow">if</span> ( isnan(acoefs[i]) || acoefs[i] == 0. || dacoefs[i] == 0. )
+<a name="l01533"></a>01533         {
+<a name="l01534"></a>01534             continue ;
+<a name="l01535"></a>01535         }
+<a name="l01536"></a>01536         <span class="keywordflow">else</span>
+<a name="l01537"></a>01537         {
+<a name="l01538"></a>01538             nc++ ;
+<a name="l01539"></a>01539         }
+<a name="l01540"></a>01540     }
+<a name="l01541"></a>01541     acoefsclean = (<span class="keywordtype">float</span>*) cpl_calloc(nc , <span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l01542"></a>01542     nc = 0 ;
+<a name="l01543"></a>01543     <span class="keywordflow">for</span> ( i = 0 ; i < n_columns ; i++ )
+<a name="l01544"></a>01544     {
+<a name="l01545"></a>01545         <span class="keywordflow">if</span> ( isnan(acoefs[i]) || acoefs[i] == 0. || dacoefs[i] == 0. )
+<a name="l01546"></a>01546         {
+<a name="l01547"></a>01547             continue ;
+<a name="l01548"></a>01548         }
+<a name="l01549"></a>01549         <span class="keywordflow">else</span>
+<a name="l01550"></a>01550         {
+<a name="l01551"></a>01551             acoefsclean[nc] = acoefs[i] ;
+<a name="l01552"></a>01552             nc++ ;
+<a name="l01553"></a>01553         }
+<a name="l01554"></a>01554     }
+<a name="l01555"></a>01555     sinfo_pixel_qsort(acoefsclean, nc) ;
+<a name="l01556"></a>01556     sum   = 0. ;
+<a name="l01557"></a>01557     sumq  = 0. ;
+<a name="l01558"></a>01558     mean  = 0. ;
+<a name="l01559"></a>01559     sigma = 0. ;
+<a name="l01560"></a>01560     n     = 0 ;
+<a name="l01561"></a>01561     <span class="keywordflow">for</span> ( i = (<span class="keywordtype">int</span>)((<span class="keywordtype">float</span>)nc*LOW_REJECT) ; 
+<a name="l01562"></a>01562           i < (int)((<span class="keywordtype">float</span>)nc*HIGH_REJECT) ; i++ )
+<a name="l01563"></a>01563     {
+<a name="l01564"></a>01564         sum  += (double)acoefsclean[i] ;
+<a name="l01565"></a>01565         sumq += ((double)acoefsclean[i] * (<span class="keywordtype">double</span>)acoefsclean[i]) ;
+<a name="l01566"></a>01566         n ++ ;
+<a name="l01567"></a>01567     }
+<a name="l01568"></a>01568     mean          = sum/(double)n ;
+<a name="l01569"></a>01569     sigma         = sqrt( sumq/(<span class="keywordtype">double</span>)n - (mean * mean) ) ;
+<a name="l01570"></a>01570     cliphi        = mean + sigma * (double)sigma_factor ;
+<a name="l01571"></a>01571     cliplo        = mean - sigma * (double)sigma_factor ;
+<a name="l01572"></a>01572 
+<a name="l01573"></a>01573     sub_col_index=cpl_calloc(n_columns,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l01574"></a>01574     sub_acoefs=cpl_calloc(n_columns,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>));
+<a name="l01575"></a>01575     sub_dacoefs=cpl_calloc(n_columns,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l01576"></a>01576 
+<a name="l01577"></a>01577     <span class="comment">/* fit only the reasonnable values */</span>
+<a name="l01578"></a>01578     num = 0 ;
+<a name="l01579"></a>01579     <span class="keywordflow">for</span> ( i = 0 ; i < n_columns ; i++ )
+<a name="l01580"></a>01580     {
+<a name="l01581"></a>01581         <span class="comment">/* associate the column indices to the corresponding array */</span>
+<a name="l01582"></a>01582         col_index = (float) i ;
+<a name="l01583"></a>01583 
+<a name="l01584"></a>01584         <span class="comment">/* take only the reasonnable coefficients */</span>
+<a name="l01585"></a>01585         <span class="keywordflow">if</span> ( !isnan(acoefs[i]) && 
+<a name="l01586"></a>01586              (acoefs[i] <= cliphi) && (acoefs[i] >= cliplo) &&
+<a name="l01587"></a>01587              (dacoefs[i] != 0. ) && (acoefs[i] != 0.) )
+<a name="l01588"></a>01588         {
+<a name="l01589"></a>01589             sub_acoefs[num]    = acoefs[i] ;
+<a name="l01590"></a>01590             sub_dacoefs[num]   = dacoefs[i] ;
+<a name="l01591"></a>01591             sub_col_index[num] = col_index ;
+<a name="l01592"></a>01592             num ++ ;
+<a name="l01593"></a>01593         }
+<a name="l01594"></a>01594     }
+<a name="l01595"></a>01595     ndata = num ;
+<a name="l01596"></a>01596 
+<a name="l01597"></a>01597     <span class="keywordflow">if</span> ( ndata < n_fitcoefs )
+<a name="l01598"></a>01598     {
+<a name="l01599"></a>01599         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"not enough data found to determine "</span>
+<a name="l01600"></a>01600                         <span class="stringliteral">"the fit coefficients.\n"</span>) ;
+<a name="l01601"></a>01601 
+<a name="l01602"></a>01602         <span class="keywordflow">return</span> FLT_MAX ;
+<a name="l01603"></a>01603     }
+<a name="l01604"></a>01604 
+<a name="l01605"></a>01605     <span class="comment">/* allocate coefficient matrices */</span>
+<a name="l01606"></a>01606     ucoefs = sinfo_matrix(1, ndata, 1, n_fitcoefs) ;
+<a name="l01607"></a>01607     vcoefs = sinfo_matrix(1, ndata, 1, n_fitcoefs) ;
+<a name="l01608"></a>01608     covar  = sinfo_matrix ( 1, n_fitcoefs, 1, n_fitcoefs ) ;
+<a name="l01609"></a>01609 
+<a name="l01610"></a>01610     <span class="comment">/* scale the x-values for the fit */</span>
+<a name="l01611"></a>01611     <span class="keywordflow">for</span> ( i = 0 ; i < ndata ; i++ )
+<a name="l01612"></a>01612     {
+<a name="l01613"></a>01613         sub_col_index[i] = (sub_col_index[i] - offset) / offset ;
+<a name="l01614"></a>01614     }
+<a name="l01615"></a>01615 
+<a name="l01616"></a>01616     <span class="comment">/* finally, do the singular value decomposition fit */</span>
+<a name="l01617"></a>01617     sinfo_svd_fitting ( sub_col_index-1, sub_acoefs-1, 
+<a name="l01618"></a>01618                         sub_dacoefs-1, ndata, bcoefs-1,
+<a name="l01619"></a>01619                         n_fitcoefs, ucoefs, vcoefs, 
+<a name="l01620"></a>01620                         wcoefs-1, covar, &chisq, sinfo_fpol ) ;
+<a name="l01621"></a>01621 
+<a name="l01622"></a>01622     <span class="comment">/* scale the found coefficients */</span>
+<a name="l01623"></a>01623     <span class="keywordflow">for</span> ( i = 0 ; i < n_fitcoefs ; i ++ )
+<a name="l01624"></a>01624     {
+<a name="l01625"></a>01625         bcoefs[i] /= pow(offset, i) ;
+<a name="l01626"></a>01626     }
+<a name="l01627"></a>01627 
+<a name="l01628"></a>01628     <span class="comment">/* free memory */</span>
+<a name="l01629"></a>01629     cpl_free (acoefsclean) ;
+<a name="l01630"></a>01630     sinfo_free_matrix( ucoefs, 1<span class="comment">/*, ndata*/</span>, 1<span class="comment">/*, n_fitcoefs */</span>) ;
+<a name="l01631"></a>01631     sinfo_free_matrix( vcoefs, 1<span class="comment">/*, ndata*/</span>, 1<span class="comment">/*, n_fitcoefs */</span>) ;
+<a name="l01632"></a>01632     sinfo_free_matrix ( covar, 1<span class="comment">/*, n_fitcoefs*/</span>, 1<span class="comment">/*, n_fitcoefs*/</span> ) ;
+<a name="l01633"></a>01633 
+<a name="l01634"></a>01634     cpl_free(sub_col_index) ;
+<a name="l01635"></a>01635     cpl_free(sub_acoefs) ;
+<a name="l01636"></a>01636     cpl_free(sub_dacoefs) ;
+<a name="l01637"></a>01637     cpl_free(wcoefs) ;
+<a name="l01638"></a>01638 
+<a name="l01639"></a>01639     <span class="keywordflow">return</span> chisq ;
+<a name="l01640"></a>01640 }
+<a name="l01641"></a>01641 
+<a name="l01642"></a>01642 
+<a name="l01662"></a>01662 cpl_image * sinfo_new_wave_map( cpl_image * lineImage,
+<a name="l01663"></a>01663                     <span class="keywordtype">float</span>   ** bcoefs,
+<a name="l01664"></a>01664                     <span class="keywordtype">int</span>        n_a_fitcoefs,
+<a name="l01665"></a>01665                     <span class="keywordtype">int</span>        n_b_fitcoefs,
+<a name="l01666"></a>01666                     <span class="keywordtype">float</span>    * wavelength,
+<a name="l01667"></a>01667                     <span class="keywordtype">float</span>    * intensity,
+<a name="l01668"></a>01668                     <span class="keywordtype">int</span>        n_lines,
+<a name="l01669"></a>01669                     <span class="keywordtype">int</span>        magFactor)
+<a name="l01670"></a>01670 {
+<a name="l01671"></a>01671     cpl_image * retImage ;
+<a name="l01672"></a>01672     <span class="keywordtype">float</span> cenpos, cenpix ;
+<a name="l01673"></a>01673     <span class="keywordtype">float</span> centreval, centrepix, wavelag ;
+<a name="l01674"></a>01674     <span class="keywordtype">float</span>  pixvalue ;
+<a name="l01675"></a>01675     <span class="keywordtype">float</span> a_initial ;
+<a name="l01676"></a>01676     <span class="keywordtype">int</span> i, j, k, l<span class="comment">/*, m*/</span>, line, col, row, found, sign ;
+<a name="l01677"></a>01677     <span class="keywordtype">int</span> var, maxlag, cmin, cmax, offset ;
+<a name="l01678"></a>01678     <span class="keywordtype">double</span> * result ;
+<a name="l01679"></a>01679     <span class="keywordtype">float</span> col_off ;
+<a name="l01680"></a>01680     <span class="keywordtype">float</span> angst ;
+<a name="l01681"></a>01681     <span class="keywordtype">double</span> xcorr_max ;
+<a name="l01682"></a>01682     <span class="keywordtype">int</span> delta ;
+<a name="l01683"></a>01683 
+<a name="l01684"></a>01684     <span class="keywordtype">double</span>* z=NULL ;
+<a name="l01685"></a>01685     <span class="keywordtype">double</span>* a=NULL ;
+<a name="l01686"></a>01686     <span class="keywordtype">double</span>*  wave=NULL ;
+<a name="l01687"></a>01687     <span class="keywordtype">float</span>* emline=NULL ;
+<a name="l01688"></a>01688     <span class="keywordtype">float</span>* spec=NULL ;
+<a name="l01689"></a>01689     <span class="keywordtype">int</span> ilx=0;
+<a name="l01690"></a>01690     <span class="keywordtype">int</span> ily=0;
+<a name="l01691"></a>01691     <span class="keywordtype">int</span> olx=0;
+<a name="l01692"></a>01692     <span class="keywordtype">int</span> oly=0;
+<a name="l01693"></a>01693     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l01694"></a>01694     <span class="keywordtype">float</span>* podata=NULL;
+<a name="l01695"></a>01695 
+<a name="l01696"></a>01696 
+<a name="l01697"></a>01697     gsl_poly_complex_workspace * w ;
+<a name="l01698"></a>01698     
+<a name="l01699"></a>01699     <span class="keywordflow">if</span> ( NULL == lineImage )
+<a name="l01700"></a>01700     {
+<a name="l01701"></a>01701         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no image given\n"</span>) ;
+<a name="l01702"></a>01702         <span class="keywordflow">return</span> NULL ;
+<a name="l01703"></a>01703     }
+<a name="l01704"></a>01704     ilx=cpl_image_get_size_x(lineImage);
+<a name="l01705"></a>01705     ily=cpl_image_get_size_y(lineImage);
+<a name="l01706"></a>01706     pidata=cpl_image_get_data_float(lineImage);
+<a name="l01707"></a>01707 
+<a name="l01708"></a>01708     <span class="keywordflow">if</span> ( NULL == wavelength || n_lines <= 0 )
+<a name="l01709"></a>01709     {
+<a name="l01710"></a>01710         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no wavelength list given\n"</span>) ;
+<a name="l01711"></a>01711         <span class="keywordflow">return</span> NULL ;
+<a name="l01712"></a>01712     }
+<a name="l01713"></a>01713 
+<a name="l01714"></a>01714     <span class="keywordflow">if</span> ( NULL == intensity )
+<a name="l01715"></a>01715     {
+<a name="l01716"></a>01716         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no intensity list given\n"</span>) ;
+<a name="l01717"></a>01717         <span class="keywordflow">return</span> NULL ;
+<a name="l01718"></a>01718     }
+<a name="l01719"></a>01719 
+<a name="l01720"></a>01720     <span class="keywordflow">if</span> ( NULL == bcoefs )
+<a name="l01721"></a>01721     {
+<a name="l01722"></a>01722         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no coefficients given\n"</span>) ;
+<a name="l01723"></a>01723         <span class="keywordflow">return</span> NULL ;
+<a name="l01724"></a>01724     }
+<a name="l01725"></a>01725 
+<a name="l01726"></a>01726     <span class="keywordflow">if</span> ( magFactor <= 1 )
+<a name="l01727"></a>01727     {
+<a name="l01728"></a>01728         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"wrong magnifying factor given\n"</span>) ;
+<a name="l01729"></a>01729         <span class="keywordflow">return</span> NULL ;
+<a name="l01730"></a>01730     }
+<a name="l01731"></a>01731     
+<a name="l01732"></a>01732     <span class="comment">/* allocate memory */</span>
+<a name="l01733"></a>01733     <span class="keywordflow">if</span> ( NULL == ( retImage = cpl_image_new( ilx, ily,CPL_TYPE_FLOAT ) ))
+<a name="l01734"></a>01734     {
+<a name="l01735"></a>01735         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"cannot allocate a new image\n"</span>);
+<a name="l01736"></a>01736         <span class="keywordflow">return</span> NULL ;
+<a name="l01737"></a>01737     }
+<a name="l01738"></a>01738     olx=cpl_image_get_size_x(retImage);
+<a name="l01739"></a>01739     oly=cpl_image_get_size_y(retImage);
+<a name="l01740"></a>01740     podata=cpl_image_get_data_float(retImage);
+<a name="l01741"></a>01741 
+<a name="l01742"></a>01742 
+<a name="l01743"></a>01743     var    = (magFactor - 1)*(magFactor - 1) ;
+<a name="l01744"></a>01744     offset = ily * (magFactor/4 + 1) ;
+<a name="l01745"></a>01745 
+<a name="l01746"></a>01746     <span class="comment">/* find out if Angstroem or microns are used */</span>
+<a name="l01747"></a>01747     <span class="keywordflow">if</span> ( wavelength[0] > 10000. )
+<a name="l01748"></a>01748     {
+<a name="l01749"></a>01749     <span class="comment">/* Angstroem */</span>
+<a name="l01750"></a>01750         angst = 10000. ;
+<a name="l01751"></a>01751     }
+<a name="l01752"></a>01752     <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( wavelength[0] > 1000. && wavelength[0] < 10000. )
+<a name="l01753"></a>01753     {
+<a name="l01754"></a>01754     <span class="comment">/* nanometers */</span>
+<a name="l01755"></a>01755     angst = 1000. ;
+<a name="l01756"></a>01756     }
+<a name="l01757"></a>01757     <span class="keywordflow">else</span>
+<a name="l01758"></a>01758     {
+<a name="l01759"></a>01759     <span class="comment">/* microns */</span>
+<a name="l01760"></a>01760     angst = 1. ;
+<a name="l01761"></a>01761     }
+<a name="l01762"></a>01762 
+<a name="l01763"></a>01763     z=cpl_calloc(2*(n_a_fitcoefs - 1),<span class="keyword">sizeof</span>(<span class="keywordtype">double</span>)) ;
+<a name="l01764"></a>01764     a=cpl_calloc(n_a_fitcoefs,<span class="keyword">sizeof</span>(<span class="keywordtype">double</span>));
+<a name="l01765"></a>01765     wave=cpl_calloc(n_lines,<span class="keyword">sizeof</span>(<span class="keywordtype">double</span>)) ;
+<a name="l01766"></a>01766     emline=cpl_calloc(2*magFactor*ily,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>));
+<a name="l01767"></a>01767     spec=cpl_calloc(2*magFactor*ily,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l01768"></a>01768 
+<a name="l01769"></a>01769     <span class="comment">/* go through the image columns */</span>
+<a name="l01770"></a>01770     <span class="keywordflow">for</span> ( col = 0 ; col < ilx ; col++ )
+<a name="l01771"></a>01771     {
+<a name="l01772"></a>01772         <span class="comment">/* initialize the emline array for each column */</span>
+<a name="l01773"></a>01773         <span class="keywordflow">for</span> ( i = 0 ; i < 2*magFactor*ily ; i++ )
+<a name="l01774"></a>01774         {
+<a name="l01775"></a>01775             emline[i] = 0. ;
+<a name="l01776"></a>01776         }
+<a name="l01777"></a>01777         col_off = (float)col - (<span class="keywordtype">float</span>)(ilx-1)/2. ;
+<a name="l01778"></a>01778 
+<a name="l01779"></a>01779         <span class="comment">/* determine the coefficients by using the given bcoefs */</span>
+<a name="l01780"></a>01780         <span class="keywordflow">for</span> ( i = 0 ; i < n_a_fitcoefs ; i++ ) 
+<a name="l01781"></a>01781         {
+<a name="l01782"></a>01782             <span class="comment">/* initialize coefficients and solution */</span>
+<a name="l01783"></a>01783             a[i] = 0. ;
+<a name="l01784"></a>01784             <span class="keywordflow">if</span> (i < n_a_fitcoefs-1)
+<a name="l01785"></a>01785             {
+<a name="l01786"></a>01786                 z[2*i] = 0. ;
+<a name="l01787"></a>01787                 z[2*i+1] = 0. ;
+<a name="l01788"></a>01788             }
+<a name="l01789"></a>01789             <span class="keywordflow">for</span> ( j = 0 ; j < n_b_fitcoefs ; j++ )
+<a name="l01790"></a>01790             {
+<a name="l01791"></a>01791                 a[i] += bcoefs[i][j] * pow(col_off, j) ;
+<a name="l01792"></a>01792             }
+<a name="l01793"></a>01793         }
+<a name="l01794"></a>01794         a_initial = a[0] ;
+<a name="l01795"></a>01795         
+<a name="l01796"></a>01796         <span class="comment">/* go through the lines and generate an artificial spectrum */</span>
+<a name="l01797"></a>01797         <span class="keywordflow">for</span> ( line = 0 ; line < n_lines ; line++ )
+<a name="l01798"></a>01798         {
+<a name="l01799"></a>01799             <span class="comment">/* go from Angstroem to micron */</span>
+<a name="l01800"></a>01800             wave[line] = wavelength[line]/angst ;
+<a name="l01801"></a>01801 
+<a name="l01802"></a>01802             <span class="comment">/* ---------------------------------------------------------------</span>
+<a name="l01803"></a>01803 <span class="comment">             * solve the polynomial for the exact offset of the line that means</span>
+<a name="l01804"></a>01804 <span class="comment">             * find the root of the polynomial of order n_fitcoefs - 1</span>
+<a name="l01805"></a>01805 <span class="comment">             */</span>
+<a name="l01806"></a>01806             a[0] = a_initial - wave[line] ;
+<a name="l01807"></a>01807 
+<a name="l01808"></a>01808             <span class="keywordflow">if</span>(NULL==(w=sinfo_gsl_poly_complex_workspace_alloc(n_a_fitcoefs)))
+<a name="l01809"></a>01809             {
+<a name="l01810"></a>01810                 <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"could not allocate complex workspace!"</span>) ;
+<a name="l01811"></a>01811                 cpl_image_delete(retImage) ;
+<a name="l01812"></a>01812                 <span class="keywordflow">return</span> NULL ;
+<a name="l01813"></a>01813             }
+<a name="l01814"></a>01814             <span class="keywordflow">if</span> (-1 == sinfo_gsl_poly_complex_solve(a, n_a_fitcoefs, w, z))
+<a name="l01815"></a>01815             {
+<a name="l01816"></a>01816                 <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"sinfo_gsl_poly_complex_solve did not work!"</span>) ;
+<a name="l01817"></a>01817                 cpl_image_delete(retImage) ;
+<a name="l01818"></a>01818                 <span class="keywordflow">return</span> NULL ;
+<a name="l01819"></a>01819             }
+<a name="l01820"></a>01820             sinfo_gsl_poly_complex_workspace_free(w) ;
+<a name="l01821"></a>01821 
+<a name="l01822"></a>01822             
+<a name="l01823"></a>01823             j = 0 ;
+<a name="l01824"></a>01824             found = -1 ;
+<a name="l01825"></a>01825             <span class="keywordflow">for</span> ( i = 0 ; i < n_a_fitcoefs - 1  ; i++ )
+<a name="l01826"></a>01826             {
+<a name="l01827"></a>01827                 <span class="comment">/* test for appropriate solution */</span>
+<a name="l01828"></a>01828                 <span class="keywordflow">if</span>( z[2*i] > (-1.)*(<span class="keywordtype">float</span>) ily/2. && 
+<a name="l01829"></a>01829                     z[2*i] < (<span class="keywordtype">float</span>)ily/2. && z[2*i+1] == 0. )
+<a name="l01830"></a>01830                 {
+<a name="l01831"></a>01831                     found = 2*i ;
+<a name="l01832"></a>01832                     j ++ ;
+<a name="l01833"></a>01833                 }
+<a name="l01834"></a>01834                 <span class="keywordflow">else</span>
+<a name="l01835"></a>01835                 {
+<a name="l01836"></a>01836                     continue ;
+<a name="l01837"></a>01837                 } 
+<a name="l01838"></a>01838             }
+<a name="l01839"></a>01839             <span class="keywordflow">if</span> ( j == 0 )
+<a name="l01840"></a>01840             {
+<a name="l01841"></a>01841                 <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"no offset solution found "</span>
+<a name="l01842"></a>01842                                   <span class="stringliteral">"for line %d in column %d\n"</span>, line, col) ;
+<a name="l01843"></a>01843                 continue ;
+<a name="l01844"></a>01844             } 
+<a name="l01845"></a>01845             <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( j == 1 )
+<a name="l01846"></a>01846             {
+<a name="l01847"></a>01847                 cenpos = z[found] + (float) ily /2. ;
+<a name="l01848"></a>01848             }
+<a name="l01849"></a>01849             <span class="keywordflow">else</span>
+<a name="l01850"></a>01850             {
+<a name="l01851"></a>01851                 <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"two or more offset solutions found "</span>
+<a name="l01852"></a>01852                                   <span class="stringliteral">"for line %d in column %d\n"</span>, line, col) ;
+<a name="l01853"></a>01853                 continue ;
+<a name="l01854"></a>01854             }
+<a name="l01855"></a>01855              
+<a name="l01856"></a>01856             <span class="comment">/*---------------------------------------------------------------</span>
+<a name="l01857"></a>01857 <span class="comment">             * magnify image by the given factor add an additional offset </span>
+<a name="l01858"></a>01858 <span class="comment">             */</span>
+<a name="l01859"></a>01859             cenpix = cenpos * (float) magFactor + (<span class="keywordtype">float</span>) offset ;  
+<a name="l01860"></a>01860             
+<a name="l01861"></a>01861             <span class="comment">/* determine max and min pixel limits over </span>
+<a name="l01862"></a>01862 <span class="comment">               which line should be convolved */</span>
+<a name="l01863"></a>01863             cmin = (sinfo_new_nint(cenpix) - (var-1)) > 0 ? 
+<a name="l01864"></a>01864                     sinfo_new_nint(cenpix) - (var-1) : 0 ;
+<a name="l01865"></a>01865             cmax = (sinfo_new_nint(cenpix) + (var-1)) < 2*magFactor * ily ? 
+<a name="l01866"></a>01866                     sinfo_new_nint(cenpix) + (var-1) :  2*magFactor * ily ;
+<a name="l01867"></a>01867 
+<a name="l01868"></a>01868             <span class="comment">/* convolve neon lines with Gaussian function */</span>
+<a name="l01869"></a>01869             for ( j = cmin ; j < cmax ; j++ )
+<a name="l01870"></a>01870             {
+<a name="l01871"></a>01871                 emline[j] += intensity[line] * 
+<a name="l01872"></a>01872                 exp((<span class="keywordtype">double</span>)(-0.5*(j-cenpix)*(j-cenpix))/(<span class="keywordtype">double</span>)var) ;
+<a name="l01873"></a>01873             }
+<a name="l01874"></a>01874         }
+<a name="l01875"></a>01875                 
+<a name="l01876"></a>01876         <span class="comment">/*--------------------------------------------------------------------- </span>
+<a name="l01877"></a>01877 <span class="comment">         * for each column, map the image data points onto an magFactor times </span>
+<a name="l01878"></a>01878 <span class="comment">           bigger element grid for FFT in the cross sinfo_new_correlation, </span>
+<a name="l01879"></a>01879 <span class="comment">           first initialize the two helping arrays for each new column.</span>
+<a name="l01880"></a>01880 <span class="comment">         */</span>
+<a name="l01881"></a>01881         <span class="keywordflow">for</span> ( k = 0 ; k < 2*magFactor * ily ; k++ )
+<a name="l01882"></a>01882         {
+<a name="l01883"></a>01883             spec[k] =  0. ;
+<a name="l01884"></a>01884         }
+<a name="l01885"></a>01885    
+<a name="l01886"></a>01886         <span class="comment">/* now take the image data points of the column and put them </span>
+<a name="l01887"></a>01887 <span class="comment">           into the spec array */</span>
+<a name="l01888"></a>01888         <span class="keywordflow">for</span> ( row = 0 ; row < ily ; row++ ) <span class="comment">/* go through the column */</span>
+<a name="l01889"></a>01889         {
+<a name="l01890"></a>01890             <span class="comment">/* insert 8 values for each image row (magnification) and </span>
+<a name="l01891"></a>01891 <span class="comment">               add same offset as for emline array */</span>
+<a name="l01892"></a>01892             <span class="keywordflow">for</span> ( l = 0 ; l < magFactor ; l++ )   
+<a name="l01893"></a>01893         {
+<a name="l01894"></a>01894             <span class="comment">/* set bad pixels or negative values to zero */</span>
+<a name="l01895"></a>01895                 <span class="keywordflow">if</span> (!isnan(pidata[col + row * ilx]) &&
+<a name="l01896"></a>01896                                 (pidata[col + row * ilx] > 0.))
+<a name="l01897"></a>01897                 {
+<a name="l01898"></a>01898                     spec[offset + l + (row * magFactor)] = 
+<a name="l01899"></a>01899                 pidata[col + row * ilx] ;     
+<a name="l01900"></a>01900                 }
+<a name="l01901"></a>01901                 <span class="keywordflow">else</span>
+<a name="l01902"></a>01902                 {
+<a name="l01903"></a>01903                     spec[offset + l + (row * magFactor)] = 0. ;
+<a name="l01904"></a>01904                 }
+<a name="l01905"></a>01905             }
+<a name="l01906"></a>01906     }
+<a name="l01907"></a>01907  
+<a name="l01908"></a>01908         <span class="comment">/* now call the cross sinfo_new_correlation routine */</span>
+<a name="l01909"></a>01909         <span class="keywordflow">if</span> (NULL == (result = sinfo_new_xcorrel(spec, 2*magFactor * ily, 
+<a name="l01910"></a>01910                                                 emline, 2*magFactor * ily, 
+<a name="l01911"></a>01911                                                 magFactor * ily, &delta, 
+<a name="l01912"></a>01912                                                 &maxlag, &xcorr_max)) ) 
+<a name="l01913"></a>01913         {
+<a name="l01914"></a>01914         <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a> (<span class="stringliteral">"cross sinfo_new_correlation did not work,"</span>
+<a name="l01915"></a>01915                                <span class="stringliteral">" col: %d is set ZERO\n"</span>, col) ;
+<a name="l01916"></a>01916             <span class="keywordflow">for</span> ( row = 0 ; row < ily ; row++ )
+<a name="l01917"></a>01917             {
+<a name="l01918"></a>01918                 podata[col + row * ilx] = ZERO ;
+<a name="l01919"></a>01919             }
+<a name="l01920"></a>01920             continue ;
+<a name="l01921"></a>01921         }
+<a name="l01922"></a>01922     
+<a name="l01923"></a>01923         <span class="keywordflow">if</span> ( xcorr_max <= 0. )
+<a name="l01924"></a>01924         {
+<a name="l01925"></a>01925             <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a> (<span class="stringliteral">"cross sinfo_new_correlation sum is negative,"</span>
+<a name="l01926"></a>01926                                <span class="stringliteral">" col: %d is set ZERO\n"</span>, col) ;
+<a name="l01927"></a>01927             <span class="keywordflow">for</span> ( row = 0 ; row < ily ; row++ )
+<a name="l01928"></a>01928             {
+<a name="l01929"></a>01929                 podata[col + row * ilx] = ZERO ;
+<a name="l01930"></a>01930             }
+<a name="l01931"></a>01931             cpl_free(result) ;
+<a name="l01932"></a>01932             continue ;
+<a name="l01933"></a>01933         }
+<a name="l01934"></a>01934 
+<a name="l01935"></a>01935         wavelag = (float) -delta / (<span class="keywordtype">float</span>) magFactor ;
+<a name="l01936"></a>01936         <span class="keywordflow">if</span> ( fabs(wavelag) > (float)ily/20. )
+<a name="l01937"></a>01937         {
+<a name="l01938"></a>01938             <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"wave lag too big, col: %d is set ZERO\n"</span>, col) ;
+<a name="l01939"></a>01939             <span class="keywordflow">for</span> ( row = 0 ; row < ily ; row++ )
+<a name="l01940"></a>01940             {
+<a name="l01941"></a>01941                 podata[col + row * ilx] = ZERO ;
+<a name="l01942"></a>01942             }
+<a name="l01943"></a>01943             cpl_free(result) ;
+<a name="l01944"></a>01944         continue ;
+<a name="l01945"></a>01945         }
+<a name="l01946"></a>01946 
+<a name="l01947"></a>01947         <span class="comment">/*-------------------------------------------------------------------- </span>
+<a name="l01948"></a>01948 <span class="comment">         * determine new zero order coefficient centreval, of which the </span>
+<a name="l01949"></a>01949 <span class="comment">           formula is determined by setting equal a polynomial shifted by </span>
+<a name="l01950"></a>01950 <span class="comment">           wavelag with the same higher order coefficients and set the new </span>
+<a name="l01951"></a>01951 <span class="comment">           zero order coefficient to get both sides of the equation </span>
+<a name="l01952"></a>01952 <span class="comment">           approximately equal.</span>
+<a name="l01953"></a>01953 <span class="comment">         */</span> 
+<a name="l01954"></a>01954         centreval = a_initial ;
+<a name="l01955"></a>01955         <span class="keywordflow">for</span> ( i = 1 ; i < n_a_fitcoefs ; i++ )
+<a name="l01956"></a>01956         {
+<a name="l01957"></a>01957             <span class="keywordflow">if</span> ( i%2 == 0 )
+<a name="l01958"></a>01958             {
+<a name="l01959"></a>01959                 sign = -1 ;
+<a name="l01960"></a>01960             }
+<a name="l01961"></a>01961             <span class="keywordflow">else</span>
+<a name="l01962"></a>01962             {
+<a name="l01963"></a>01963                 sign = 1 ;
+<a name="l01964"></a>01964             }
+<a name="l01965"></a>01965             centreval += (float)sign * a[i]*pow(wavelag, i) ;
+<a name="l01966"></a>01966         }
+<a name="l01967"></a>01967 
+<a name="l01968"></a>01968         <span class="comment">/* prepare to write out wavelength as pixel values */</span>
+<a name="l01969"></a>01969         <span class="keywordflow">for</span> ( row = 0 ; row < ily ; row++ )
+<a name="l01970"></a>01970         {
+<a name="l01971"></a>01971             centrepix = (float)row - ((<span class="keywordtype">float</span>)ily - 1.)/2. ;
+<a name="l01972"></a>01972             pixvalue = 0. ;
+<a name="l01973"></a>01973             <span class="keywordflow">for</span> ( i = 1 ; i < n_a_fitcoefs ; i++ )
+<a name="l01974"></a>01974             {
+<a name="l01975"></a>01975                 pixvalue += a[i]*pow(centrepix, i) ; 
+<a name="l01976"></a>01976             }
+<a name="l01977"></a>01977             podata[col + row * ilx] = centreval + pixvalue ; 
+<a name="l01978"></a>01978         }
+<a name="l01979"></a>01979         cpl_free(result) ;   
+<a name="l01980"></a>01980     }
+<a name="l01981"></a>01981 
+<a name="l01982"></a>01982 
+<a name="l01983"></a>01983 
+<a name="l01984"></a>01984     cpl_free(z) ;
+<a name="l01985"></a>01985     cpl_free(a) ;
+<a name="l01986"></a>01986     cpl_free(wave) ;
+<a name="l01987"></a>01987     cpl_free(emline) ;
+<a name="l01988"></a>01988     cpl_free(spec) ;
+<a name="l01989"></a>01989 
+<a name="l01990"></a>01990     <span class="keywordflow">return</span> retImage ;
+<a name="l01991"></a>01991 }                    
+<a name="l01992"></a>01992 
+<a name="l02037"></a>02037 <span class="keywordtype">int</span> sinfo_new_wavelength_calibration( cpl_image   * image,
+<a name="l02038"></a>02038                            FitParams ** par ,
+<a name="l02039"></a>02039                            <span class="keywordtype">float</span>     ** bcoefs,
+<a name="l02040"></a>02040                            <span class="keywordtype">float</span>      * wave,
+<a name="l02041"></a>02041                            <span class="keywordtype">int</span>          n_lines,
+<a name="l02042"></a>02042                            <span class="keywordtype">int</span>       ** row_clean,
+<a name="l02043"></a>02043                            <span class="keywordtype">float</span>     ** wavelength_clean,
+<a name="l02044"></a>02044                            <span class="keywordtype">int</span>        * n_found_lines,
+<a name="l02045"></a>02045                            <span class="keywordtype">float</span>        dispersion,
+<a name="l02046"></a>02046                            <span class="keywordtype">int</span>          halfWidth,
+<a name="l02047"></a>02047                            <span class="keywordtype">float</span>        minAmplitude,
+<a name="l02048"></a>02048                            <span class="keywordtype">float</span>        max_residual,
+<a name="l02049"></a>02049                            <span class="keywordtype">float</span>        fwhm,
+<a name="l02050"></a>02050                            <span class="keywordtype">int</span>          n_a_fitcoefs,
+<a name="l02051"></a>02051                            <span class="keywordtype">int</span>          n_b_fitcoefs,
+<a name="l02052"></a>02052                            <span class="keywordtype">float</span>        sigmaFactor,
+<a name="l02053"></a>02053                            <span class="keywordtype">float</span>        pixel_tolerance )
+<a name="l02054"></a>02054 
+<a name="l02055"></a>02055 {
+<a name="l02056"></a>02056     <span class="keywordtype">int</span>          i, j, k ;
+<a name="l02057"></a>02057     <span class="keywordtype">int</span>          n_fit ;
+<a name="l02058"></a>02058     <span class="keywordtype">int</span>          n_reject ;
+<a name="l02059"></a>02059     <span class="keywordtype">float</span>     *  acoefs ;
+<a name="l02060"></a>02060     <span class="keywordtype">float</span>     *  dacoefs ;
+<a name="l02061"></a>02061     <span class="keywordtype">float</span>     ** abuf ;
+<a name="l02062"></a>02062     <span class="keywordtype">float</span>     ** dabuf ;
+<a name="l02063"></a>02063     <span class="keywordtype">float</span>        chisq_poly, chisq_cross ;
+<a name="l02064"></a>02064     <span class="keywordtype">int</span>          zeroind ;
+<a name="l02065"></a>02065     <span class="comment">/*float     *  mem ;*/</span>
+<a name="l02066"></a>02066     <span class="keywordtype">int</span> lx=0;
+<a name="l02067"></a>02067     <span class="keywordtype">int</span> ly=0;
+<a name="l02068"></a>02068     <span class="keywordtype">float</span>* pdata=NULL;
+<a name="l02069"></a>02069 
+<a name="l02070"></a>02070     <span class="keywordflow">if</span> (  NULL == image )
+<a name="l02071"></a>02071     {
+<a name="l02072"></a>02072         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no image given\n"</span>) ;
+<a name="l02073"></a>02073         <span class="keywordflow">return</span> -1 ;
+<a name="l02074"></a>02074     }
+<a name="l02075"></a>02075     lx=cpl_image_get_size_x(image);
+<a name="l02076"></a>02076     ly=cpl_image_get_size_y(image);
+<a name="l02077"></a>02077     pdata=cpl_image_get_data_float(image);
+<a name="l02078"></a>02078 
+<a name="l02079"></a>02079     <span class="keywordflow">if</span> ( par == NULL )
+<a name="l02080"></a>02080     {
+<a name="l02081"></a>02081         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no fit parameter data structure given\n"</span>) ;
+<a name="l02082"></a>02082         <span class="keywordflow">return</span> -1 ;
+<a name="l02083"></a>02083     }
+<a name="l02084"></a>02084     <span class="keywordflow">if</span> ( wave == NULL )
+<a name="l02085"></a>02085     {
+<a name="l02086"></a>02086         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no wavelength list given\n"</span>) ;
+<a name="l02087"></a>02087         <span class="keywordflow">return</span> -1 ;
+<a name="l02088"></a>02088     }
+<a name="l02089"></a>02089     <span class="keywordflow">if</span> ( n_lines <= 0 )
+<a name="l02090"></a>02090     {
+<a name="l02091"></a>02091         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"impossible number of lines in line list given\n"</span>) ;
+<a name="l02092"></a>02092         <span class="keywordflow">return</span> -1 ;
+<a name="l02093"></a>02093     }
+<a name="l02094"></a>02094     <span class="keywordflow">if</span> ( row_clean == NULL )
+<a name="l02095"></a>02095     {
+<a name="l02096"></a>02096         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no row_clean array given\n"</span>) ;
+<a name="l02097"></a>02097         <span class="keywordflow">return</span> -1 ;
+<a name="l02098"></a>02098     }
+<a name="l02099"></a>02099     <span class="keywordflow">if</span> ( wavelength_clean == NULL )
+<a name="l02100"></a>02100     {
+<a name="l02101"></a>02101         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no wavelength_clean array given\n"</span>) ;
+<a name="l02102"></a>02102         <span class="keywordflow">return</span> -1 ;
+<a name="l02103"></a>02103     }
+<a name="l02104"></a>02104 
+<a name="l02105"></a>02105     <span class="keywordflow">if</span> ( dispersion == 0. )
+<a name="l02106"></a>02106     {
+<a name="l02107"></a>02107         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"impossible dispersion given\n"</span>) ;
+<a name="l02108"></a>02108         <span class="keywordflow">return</span> -1 ;
+<a name="l02109"></a>02109     }
+<a name="l02110"></a>02110 
+<a name="l02111"></a>02111     <span class="keywordflow">if</span> ( halfWidth <= 0 || halfWidth > ly/2 )
+<a name="l02112"></a>02112     {
+<a name="l02113"></a>02113         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"impossible half width of the fitting box given\n"</span>) ;
+<a name="l02114"></a>02114         <span class="keywordflow">return</span> -1 ;
+<a name="l02115"></a>02115     }
+<a name="l02116"></a>02116     <span class="keywordflow">if</span> ( minAmplitude < 1. )
+<a name="l02117"></a>02117     {
+<a name="l02118"></a>02118         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"impossible minimal amplitude\n"</span>) ;
+<a name="l02119"></a>02119         <span class="keywordflow">return</span> -1 ;
+<a name="l02120"></a>02120     }
+<a name="l02121"></a>02121 
+<a name="l02122"></a>02122     <span class="keywordflow">if</span> ( max_residual <= 0. || max_residual > 1. )
+<a name="l02123"></a>02123     {
+<a name="l02124"></a>02124         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"impossible max_residual given\n"</span>) ;
+<a name="l02125"></a>02125         <span class="keywordflow">return</span> -1 ;
+<a name="l02126"></a>02126     }
+<a name="l02127"></a>02127 
+<a name="l02128"></a>02128     <span class="keywordflow">if</span> ( fwhm <= 0. || fwhm > 10. )
+<a name="l02129"></a>02129     {
+<a name="l02130"></a>02130         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"impossible fwhm given\n"</span>) ;
+<a name="l02131"></a>02131 
+<a name="l02132"></a>02132         <span class="keywordflow">return</span> -1 ;
+<a name="l02133"></a>02133     }
+<a name="l02134"></a>02134 
+<a name="l02135"></a>02135     <span class="keywordflow">if</span> ( n_a_fitcoefs <= 0 || n_a_fitcoefs > 9 )
+<a name="l02136"></a>02136     {
+<a name="l02137"></a>02137         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"unrealistic n_a_fitcoefs given\n"</span>) ;
+<a name="l02138"></a>02138         <span class="keywordflow">return</span> -1 ;
+<a name="l02139"></a>02139     }
+<a name="l02140"></a>02140 
+<a name="l02141"></a>02141     <span class="keywordflow">if</span> ( n_b_fitcoefs <= 0 || n_b_fitcoefs > 9 )
+<a name="l02142"></a>02142     {
+<a name="l02143"></a>02143         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" unrealistic n_b_fitcoefs given\n"</span>) ;
+<a name="l02144"></a>02144         <span class="keywordflow">return</span> -1 ;
+<a name="l02145"></a>02145     }
+<a name="l02146"></a>02146     <span class="keywordflow">if</span> ( sigmaFactor <= 0. )
+<a name="l02147"></a>02147     {
+<a name="l02148"></a>02148         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" impossible sigmaFactor given\n"</span>) ;
+<a name="l02149"></a>02149         <span class="keywordflow">return</span> -1 ;
+<a name="l02150"></a>02150     }
+<a name="l02151"></a>02151 
+<a name="l02152"></a>02152     <span class="comment">/* initialize the variables */</span>
+<a name="l02153"></a>02153     n_reject = 0 ;
+<a name="l02154"></a>02154     n_fit = 0 ;
+<a name="l02155"></a>02155 
+<a name="l02156"></a>02156     <span class="comment">/* fit each found line by using a Gaussian function and determine the </span>
+<a name="l02157"></a>02157 <span class="comment">       exact position */</span>
+<a name="l02158"></a>02158     <span class="keywordflow">if</span> ( 0 > (n_fit = sinfo_new_fit_lines( image , par, fwhm, 
+<a name="l02159"></a>02159                                            n_found_lines, row_clean, 
+<a name="l02160"></a>02160                                            wavelength_clean,
+<a name="l02161"></a>02161                                 halfWidth, minAmplitude )) )
+<a name="l02162"></a>02162     {
+<a name="l02163"></a>02163         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" cannot fit the lines, "</span>
+<a name="l02164"></a>02164                         <span class="stringliteral">"error code of sinfo_fitLines: %d\n"</span>, n_fit) ;
+<a name="l02165"></a>02165         <span class="keywordflow">return</span> -1 ;
+<a name="l02166"></a>02166     }
+<a name="l02167"></a>02167 
+<a name="l02168"></a>02168     <span class="comment">/* first check for faked lines like bad pixels */</span>
+<a name="l02169"></a>02169     <span class="keywordflow">if</span> ( -1 == sinfo_new_check_for_fake_lines (par, dispersion, 
+<a name="l02170"></a>02170                                                wavelength_clean, row_clean, 
+<a name="l02171"></a>02171                                                n_found_lines,
+<a name="l02172"></a>02172                                                lx, pixel_tolerance) )
+<a name="l02173"></a>02173     {
+<a name="l02174"></a>02174         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"cannot fit the lines, "</span>
+<a name="l02175"></a>02175                         <span class="stringliteral">"error code of sinfo_fitLines: %d"</span>, n_fit) ;
+<a name="l02176"></a>02176         <span class="keywordflow">return</span> -1 ;
+<a name="l02177"></a>02177     }
+<a name="l02178"></a>02178 
+<a name="l02179"></a>02179     <span class="comment">/* allocate memory */</span>
+<a name="l02180"></a>02180     <span class="keywordflow">if</span> (NULL == (acoefs = (<span class="keywordtype">float</span>*) cpl_calloc (n_a_fitcoefs, <span class="keyword">sizeof</span>(<span class="keywordtype">float</span>*))) ||
+<a name="l02181"></a>02181         NULL == (dacoefs = (<span class="keywordtype">float</span>*)cpl_calloc (n_a_fitcoefs, <span class="keyword">sizeof</span>(<span class="keywordtype">float</span>*))) ||
+<a name="l02182"></a>02182         NULL == (abuf = (<span class="keywordtype">float</span>**) cpl_calloc (n_a_fitcoefs, <span class="keyword">sizeof</span>(<span class="keywordtype">float</span>*))) ||
+<a name="l02183"></a>02183         NULL == (dabuf = (<span class="keywordtype">float</span>**) cpl_calloc (n_a_fitcoefs, <span class="keyword">sizeof</span>(<span class="keywordtype">float</span>*))) )
+<a name="l02184"></a>02184     {
+<a name="l02185"></a>02185         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" cannot allocate memory\n"</span>) ;
+<a name="l02186"></a>02186         <span class="keywordflow">return</span> -1 ;
+<a name="l02187"></a>02187     }
+<a name="l02188"></a>02188 
+<a name="l02189"></a>02189     <span class="keywordflow">for</span> ( i = 0 ; i < n_a_fitcoefs ; i++ )
+<a name="l02190"></a>02190     {
+<a name="l02191"></a>02191         <span class="keywordflow">if</span> ( NULL == (abuf[i] = (<span class="keywordtype">float</span>*) cpl_calloc(lx, <span class="keyword">sizeof</span>(<span class="keywordtype">float</span>))) ||
+<a name="l02192"></a>02192              NULL == (dabuf[i] = (<span class="keywordtype">float</span>*) cpl_calloc(lx, <span class="keyword">sizeof</span>(<span class="keywordtype">float</span>))) )
+<a name="l02193"></a>02193         {
+<a name="l02194"></a>02194             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" cannot allocate memory\n"</span>) ;
+<a name="l02195"></a>02195             cpl_free(abuf) ;
+<a name="l02196"></a>02196             cpl_free(dabuf) ;
+<a name="l02197"></a>02197             <span class="keywordflow">return</span> -1 ;
+<a name="l02198"></a>02198         }
+<a name="l02199"></a>02199     }
+<a name="l02200"></a>02200 
+<a name="l02201"></a>02201     <span class="comment">/* fit wavelengths to the corresponding found positions for each column */</span>
+<a name="l02202"></a>02202     k = 0 ;
+<a name="l02203"></a>02203     
+<a name="l02204"></a>02204     <span class="keywordflow">for</span> ( i = 0 ; i < lx ; i++ )
+<a name="l02205"></a>02205     {
+<a name="l02206"></a>02206         zeroind = 0 ;
+<a name="l02207"></a>02207         <span class="keywordflow">if</span> ( FLT_MAX == (chisq_poly = sinfo_new_polyfit( par, i, 
+<a name="l02208"></a>02208                                                          n_found_lines[i], 
+<a name="l02209"></a>02209                                                          ly, dispersion,
+<a name="l02210"></a>02210                                                          max_residual, acoefs, 
+<a name="l02211"></a>02211                                                          dacoefs, &n_reject, 
+<a name="l02212"></a>02212                                                          n_a_fitcoefs)) )
+<a name="l02213"></a>02213         {
+<a name="l02214"></a>02214       <span class="comment">/* </span>
+<a name="l02215"></a>02215 <span class="comment">           sinfo_msg_warning (" error in polyfitt in column: %d\n", i) ;</span>
+<a name="l02216"></a>02216 <span class="comment">       */</span>
+<a name="l02217"></a>02217             <span class="keywordflow">for</span> ( j = 0 ; j < n_a_fitcoefs ; j++ )
+<a name="l02218"></a>02218             {
+<a name="l02219"></a>02219                 acoefs[j] = ZERO ;
+<a name="l02220"></a>02220                 dacoefs[j] = ZERO ;
+<a name="l02221"></a>02221             }
+<a name="l02222"></a>02222         }
+<a name="l02223"></a>02223 
+<a name="l02224"></a>02224         <span class="keywordflow">for</span> ( j = 0 ; j < n_a_fitcoefs ; j++ )
+<a name="l02225"></a>02225         {
+<a name="l02226"></a>02226             <span class="keywordflow">if</span> ( acoefs[0] <= 0. || acoefs[1] ==0. ||
+<a name="l02227"></a>02227                  dacoefs[j] == 0. || isnan(acoefs[j]) )
+<a name="l02228"></a>02228             {
+<a name="l02229"></a>02229                 zeroind = 1 ;
+<a name="l02230"></a>02230 
+<a name="l02231"></a>02231             }
+<a name="l02232"></a>02232         }
+<a name="l02233"></a>02233         <span class="keywordflow">for</span> ( j = 0 ; j < n_a_fitcoefs ; j++ )
+<a name="l02234"></a>02234         {
+<a name="l02235"></a>02235             <span class="keywordflow">if</span> ( zeroind == 0 )
+<a name="l02236"></a>02236             {
+<a name="l02237"></a>02237                 abuf[j][i]  = acoefs[j] ;
+<a name="l02238"></a>02238                 dabuf[j][i] = dacoefs[j] ;
+<a name="l02239"></a>02239             }
+<a name="l02240"></a>02240             <span class="keywordflow">else</span>
+<a name="l02241"></a>02241             {
+<a name="l02242"></a>02242                 abuf[j][i]  = ZERO ;
+<a name="l02243"></a>02243                 dabuf[j][i] = ZERO ;
+<a name="l02244"></a>02244             }
+<a name="l02245"></a>02245         }
+<a name="l02246"></a>02246     }
+<a name="l02247"></a>02247 
+<a name="l02248"></a>02248     <span class="comment">/* fit each acoefs across the columns to smooth the result */</span>
+<a name="l02249"></a>02249     <span class="keywordflow">for</span> ( i = 0 ; i < n_a_fitcoefs ; i++ )
+<a name="l02250"></a>02250     {
+<a name="l02251"></a>02251         <span class="keywordflow">if</span> ( FLT_MAX == (chisq_cross = sinfo_new_coefs_cross_fit(lx, 
+<a name="l02252"></a>02252                                                                  abuf[i], 
+<a name="l02253"></a>02253                                                                  dabuf[i],
+<a name="l02254"></a>02254                                                                  bcoefs[i],
+<a name="l02255"></a>02255                                                                  n_b_fitcoefs,
+<a name="l02256"></a>02256                                                                  sigmaFactor)))
+<a name="l02257"></a>02257         {
+<a name="l02258"></a>02258             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" cannot carry out the fitting of coefficients"</span>
+<a name="l02259"></a>02259                              <span class="stringliteral">" across the columns, for the coefficient with"</span>
+<a name="l02260"></a>02260                              <span class="stringliteral">" index: %d\n"</span>, i) ;
+<a name="l02261"></a>02261             <span class="keywordflow">for</span> ( i = 0 ; i < n_a_fitcoefs ; i++ )
+<a name="l02262"></a>02262             {
+<a name="l02263"></a>02263                 cpl_free (abuf[i]) ;
+<a name="l02264"></a>02264                 cpl_free (dabuf[i]) ;
+<a name="l02265"></a>02265             }
+<a name="l02266"></a>02266             cpl_free ( acoefs ) ;
+<a name="l02267"></a>02267             cpl_free ( dacoefs ) ;
+<a name="l02268"></a>02268             cpl_free ( abuf ) ;
+<a name="l02269"></a>02269             cpl_free ( dabuf ) ;
+<a name="l02270"></a>02270             <span class="keywordflow">return</span> -1 ;
+<a name="l02271"></a>02271         }
+<a name="l02272"></a>02272     }
+<a name="l02273"></a>02273 
+<a name="l02274"></a>02274     <span class="comment">/* free all allocated memory */</span>
+<a name="l02275"></a>02275     <span class="keywordflow">for</span> ( i = 0 ; i < n_a_fitcoefs ; i++ )
+<a name="l02276"></a>02276     {
+<a name="l02277"></a>02277         cpl_free (abuf[i]) ;
+<a name="l02278"></a>02278         cpl_free (dabuf[i]) ;
+<a name="l02279"></a>02279     }
+<a name="l02280"></a>02280     cpl_free ( acoefs ) ;
+<a name="l02281"></a>02281     cpl_free ( dacoefs ) ;
+<a name="l02282"></a>02282     cpl_free ( abuf ) ;
+<a name="l02283"></a>02283     cpl_free ( dabuf ) ;
+<a name="l02284"></a>02284 
+<a name="l02285"></a>02285     <span class="keywordflow">return</span> 0 ;   
+<a name="l02286"></a>02286 }
+<a name="l02287"></a>02287 
+<a name="l02288"></a>02288                            
+<a name="l02300"></a>02300 cpl_image * sinfo_new_convolve_image_by_gauss( cpl_image * lineImage,
+<a name="l02301"></a>02301                                  <span class="keywordtype">int</span>        hw )
+<a name="l02302"></a>02302 {
+<a name="l02303"></a>02303     cpl_image * returnImage ;
+<a name="l02304"></a>02304     <span class="keywordtype">float</span>* column_buffer=NULL ;
+<a name="l02305"></a>02305     <span class="keywordtype">float</span> * filter ;
+<a name="l02306"></a>02306     <span class="keywordtype">int</span> col, row ;
+<a name="l02307"></a>02307     <span class="keywordtype">int</span> ilx=0;
+<a name="l02308"></a>02308     <span class="keywordtype">int</span> ily=0;
+<a name="l02309"></a>02309     <span class="keywordtype">int</span> olx=0;
+<a name="l02310"></a>02310     <span class="keywordtype">int</span> oly=0;
+<a name="l02311"></a>02311     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l02312"></a>02312     <span class="keywordtype">float</span>* podata=NULL;
+<a name="l02313"></a>02313 
+<a name="l02314"></a>02314     <span class="keywordflow">if</span> ( lineImage == NULL )
+<a name="l02315"></a>02315     {
+<a name="l02316"></a>02316         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" no input image given!\n"</span>) ;
+<a name="l02317"></a>02317         <span class="keywordflow">return</span> NULL ;
+<a name="l02318"></a>02318     }
+<a name="l02319"></a>02319     ilx=cpl_image_get_size_x(lineImage);
+<a name="l02320"></a>02320     ily=cpl_image_get_size_y(lineImage);
+<a name="l02321"></a>02321     pidata=cpl_image_get_data_float(lineImage);
+<a name="l02322"></a>02322 
+<a name="l02323"></a>02323     <span class="keywordflow">if</span> ( hw < 1 )
+<a name="l02324"></a>02324     {
+<a name="l02325"></a>02325         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" wrong half width given!\n"</span>) ;
+<a name="l02326"></a>02326         <span class="keywordflow">return</span> NULL ;
+<a name="l02327"></a>02327     }
+<a name="l02328"></a>02328 
+<a name="l02329"></a>02329     <span class="comment">/* allocate memory for returned image */</span>
+<a name="l02330"></a>02330     <span class="keywordflow">if</span> ( NULL == ( returnImage = cpl_image_new(ilx,ily,CPL_TYPE_FLOAT ) ))
+<a name="l02331"></a>02331     {
+<a name="l02332"></a>02332         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" cannot allocate a new image\n"</span>);
+<a name="l02333"></a>02333         <span class="keywordflow">return</span> NULL ;
+<a name="l02334"></a>02334     }
+<a name="l02335"></a>02335     olx=cpl_image_get_size_x(returnImage);
+<a name="l02336"></a>02336     oly=cpl_image_get_size_y(returnImage);
+<a name="l02337"></a>02337     podata=cpl_image_get_data_float(returnImage);
+<a name="l02338"></a>02338 
+<a name="l02339"></a>02339     column_buffer=cpl_calloc(ily,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l02340"></a>02340 
+<a name="l02341"></a>02341     <span class="comment">/* go through the image columns and save them in a buffer */</span>
+<a name="l02342"></a>02342     <span class="keywordflow">for</span> ( col = 0 ; col < ilx ; col++ )
+<a name="l02343"></a>02343     { 
+<a name="l02344"></a>02344         <span class="keywordflow">for</span> ( row = 0 ; row < ily ; row++ )
+<a name="l02345"></a>02345         {
+<a name="l02346"></a>02346             column_buffer[row] = pidata[col + row*ilx] ;
+<a name="l02347"></a>02347         }
+<a name="l02348"></a>02348          
+<a name="l02349"></a>02349         <span class="comment">/*--------------------------------------------------------------------- </span>
+<a name="l02350"></a>02350 <span class="comment">         * now low pass filter the columns by the sinfo_gaussian and fill </span>
+<a name="l02351"></a>02351 <span class="comment">           the return image.</span>
+<a name="l02352"></a>02352 <span class="comment">         */</span>  
+<a name="l02353"></a>02353         filter = sinfo_function1d_filter_lowpass( column_buffer,
+<a name="l02354"></a>02354                                             ily,
+<a name="l02355"></a>02355                                             LOW_PASS_GAUSSIAN,
+<a name="l02356"></a>02356                                             hw ) ;
+<a name="l02357"></a>02357         <span class="keywordflow">for</span> ( row = 0 ; row < ily ; row++ )
+<a name="l02358"></a>02358         {
+<a name="l02359"></a>02359             podata[col + row*ilx] = filter[row] ;
+<a name="l02360"></a>02360         }
+<a name="l02361"></a>02361         sinfo_function1d_del(filter) ;
+<a name="l02362"></a>02362     }
+<a name="l02363"></a>02363                         
+<a name="l02364"></a>02364     cpl_free(column_buffer);
+<a name="l02365"></a>02365     <span class="keywordflow">return</span> returnImage ;
+<a name="l02366"></a>02366 }
+<a name="l02367"></a>02367 
+<a name="l02407"></a>02407 cpl_image * sinfo_new_defined_resampling( cpl_image * image,
+<a name="l02408"></a>02408                               cpl_image * calimage,
+<a name="l02409"></a>02409                               <span class="keywordtype">int</span>        n_params,
+<a name="l02410"></a>02410                               <span class="keywordtype">int</span>*       n_rows,
+<a name="l02411"></a>02411                               <span class="keywordtype">double</span>   * dispersion,
+<a name="l02412"></a>02412                               <span class="keywordtype">float</span>    * minval,
+<a name="l02413"></a>02413                               <span class="keywordtype">float</span>    * maxval,
+<a name="l02414"></a>02414                               <span class="keywordtype">double</span>   * centralLambda,
+<a name="l02415"></a>02415                               <span class="keywordtype">int</span>    * centralpix )
+<a name="l02416"></a>02416 {
+<a name="l02417"></a>02417     cpl_image * retImage ;
+<a name="l02418"></a>02418     cpl_image * tempCalImage ;
+<a name="l02419"></a>02419     cpl_image * tempImage ;
+<a name="l02420"></a>02420     <span class="keywordtype">float</span> lambda ;
+<a name="l02421"></a>02421     <span class="keywordtype">float</span> dif, lambda_renorm ;
+<a name="l02422"></a>02422     <span class="keywordtype">float</span> * retimagecol = NULL;<span class="comment">//[2560] ; /* retimagecol[n_rows] ; */</span>
+<a name="l02423"></a>02423 
+<a name="l02424"></a>02424     <span class="keywordtype">float</span>* imagecol=NULL ;
+<a name="l02425"></a>02425     <span class="keywordtype">float</span>* calcol=NULL ;
+<a name="l02426"></a>02426     <span class="keywordtype">float</span>* x_renorm=NULL ;
+<a name="l02427"></a>02427 
+<a name="l02428"></a>02428     <span class="keywordtype">float</span> * imageptr ;
+<a name="l02429"></a>02429     <span class="keywordtype">float</span> sum, new_sum ;
+<a name="l02430"></a>02430     <span class="keywordtype">float</span> disp, mindisp ;
+<a name="l02431"></a>02431     <span class="keywordtype">int</span> *calcolpos=NULL;<span class="comment">//[2560];</span>
+<a name="l02432"></a>02432     <span class="keywordtype">int</span> i<span class="comment">/*, j*/</span>, col, row, testrow ;
+<a name="l02433"></a>02433     <span class="keywordtype">int</span> half_width, firstpos ;
+<a name="l02434"></a>02434     <span class="keywordtype">int</span> dispInd ;
+<a name="l02435"></a>02435     <span class="keywordtype">int</span> n ;
+<a name="l02436"></a>02436     <span class="keywordtype">int</span> flag;
+<a name="l02437"></a>02437     <span class="keywordtype">float</span> temprow;
+<a name="l02438"></a>02438     <span class="keywordtype">float</span> minLambda = 0. ;
+<a name="l02439"></a>02439     <span class="comment">/*dpoint list[n_params] ;*/</span>
+<a name="l02440"></a>02440     <span class="comment">/*double * polycoeffs ;*/</span>
+<a name="l02441"></a>02441     <span class="keywordtype">double</span> poly ;
+<a name="l02442"></a>02442     <span class="comment">/*float error;*/</span>
+<a name="l02443"></a>02443     <span class="keywordtype">int</span> zeroind ;
+<a name="l02444"></a>02444     <span class="keywordtype">int</span> ilx=0;
+<a name="l02445"></a>02445     <span class="keywordtype">int</span> ily=0;
+<a name="l02446"></a>02446     <span class="keywordtype">int</span> clx=0;
+<a name="l02447"></a>02447     <span class="keywordtype">int</span> cly=0;
+<a name="l02448"></a>02448     <span class="keywordtype">int</span> olx=0;
+<a name="l02449"></a>02449     <span class="keywordtype">int</span> oly=0;
+<a name="l02450"></a>02450 
+<a name="l02451"></a>02451     <span class="keywordtype">float</span>* podata=NULL;
+<a name="l02452"></a>02452     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l02453"></a>02453     <span class="keywordtype">float</span>* pcdata=NULL;
+<a name="l02454"></a>02454     <span class="keywordtype">float</span>* ptidata=NULL;
+<a name="l02455"></a>02455     <span class="keywordtype">float</span>* ptcdata=NULL;
+<a name="l02456"></a>02456 
+<a name="l02457"></a>02457     <span class="keywordflow">if</span> ( NULL == image )
+<a name="l02458"></a>02458     {
+<a name="l02459"></a>02459         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" source image not given\n"</span>) ;
+<a name="l02460"></a>02460         <span class="keywordflow">return</span> NULL ;
+<a name="l02461"></a>02461     }
+<a name="l02462"></a>02462     ilx=cpl_image_get_size_x(image);
+<a name="l02463"></a>02463     ily=cpl_image_get_size_y(image);
+<a name="l02464"></a>02464     pidata=cpl_image_get_data_float(image);
+<a name="l02465"></a>02465 
+<a name="l02466"></a>02466 
+<a name="l02467"></a>02467     <span class="keywordflow">if</span> ( NULL == calimage )
+<a name="l02468"></a>02468     {
+<a name="l02469"></a>02469         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" wavelength map image not given\n"</span>) ;
+<a name="l02470"></a>02470         <span class="keywordflow">return</span> NULL ;
+<a name="l02471"></a>02471     }
+<a name="l02472"></a>02472     clx=cpl_image_get_size_x(calimage);
+<a name="l02473"></a>02473     cly=cpl_image_get_size_y(calimage);
+<a name="l02474"></a>02474     pcdata=cpl_image_get_data_float(calimage);
+<a name="l02475"></a>02475     <span class="keywordflow">if</span> ( ilx != clx ||
+<a name="l02476"></a>02476          ily != cly )
+<a name="l02477"></a>02477     {
+<a name="l02478"></a>02478         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"source image and wavelength map image "</span>
+<a name="l02479"></a>02479                         <span class="stringliteral">"are not compatible in size\n"</span>) ;
+<a name="l02480"></a>02480         <span class="keywordflow">return</span> NULL ;
+<a name="l02481"></a>02481     }                              
+<a name="l02482"></a>02482   
+<a name="l02483"></a>02483     <span class="keywordflow">if</span> ( n_params < 1 )
+<a name="l02484"></a>02484     {
+<a name="l02485"></a>02485         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" wrong number of fit parameters given\n"</span>) ;
+<a name="l02486"></a>02486         <span class="keywordflow">return</span> NULL ;
+<a name="l02487"></a>02487     }
+<a name="l02488"></a>02488 
+<a name="l02489"></a>02489     <span class="keywordflow">if</span> ( n_params > 4 )
+<a name="l02490"></a>02490     {
+<a name="l02491"></a>02491         <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">" attention: very high number of fit "</span>
+<a name="l02492"></a>02492                           <span class="stringliteral">"parameters given, not tested !!!\n"</span>) ;
+<a name="l02493"></a>02493     }
+<a name="l02494"></a>02494 
+<a name="l02495"></a>02495     imagecol=cpl_calloc(ily,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l02496"></a>02496     calcol=cpl_calloc(cly,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l02497"></a>02497     x_renorm=cpl_calloc(n_params,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l02498"></a>02498 
+<a name="l02499"></a>02499 
+<a name="l02500"></a>02500     <span class="comment">/*if ( n_rows <= cly)</span>
+<a name="l02501"></a>02501 <span class="comment">    {</span>
+<a name="l02502"></a>02502 <span class="comment">        sinfo_msg_error (" number of rows of resampled image will be "</span>
+<a name="l02503"></a>02503 <span class="comment">                         " smaller than in wavelength calibration map,"</span>
+<a name="l02504"></a>02504 <span class="comment">                         " information would get lost!") ;</span>
+<a name="l02505"></a>02505 <span class="comment">        return NULL ;</span>
+<a name="l02506"></a>02506 <span class="comment">    }*/</span>
+<a name="l02507"></a>02507    
+<a name="l02508"></a>02508     dispInd = 0 ;
+<a name="l02509"></a>02509 
+<a name="l02510"></a>02510     <span class="comment">/* first determine the dispersion direction */</span>
+<a name="l02511"></a>02511     <span class="keywordflow">for</span> ( col = 0 ; col < clx ; col++ )
+<a name="l02512"></a>02512     {
+<a name="l02513"></a>02513         <span class="keywordflow">if</span> ( isnan(pcdata[col]) || pcdata[col] <= 0. )
+<a name="l02514"></a>02514         {
+<a name="l02515"></a>02515             continue ;
+<a name="l02516"></a>02516         }
+<a name="l02517"></a>02517         <span class="keywordflow">if</span> ((pcdata[col] - pcdata[col+(clx)*(cly-1)]) > 0. )
+<a name="l02518"></a>02518         {
+<a name="l02519"></a>02519            dispInd--  ;
+<a name="l02520"></a>02520         }
+<a name="l02521"></a>02521         <span class="keywordflow">else</span> <span class="keywordflow">if</span> ((pcdata[col] - pcdata[col+(clx)*(cly-1)]) < 0. )
+<a name="l02522"></a>02522         {
+<a name="l02523"></a>02523            dispInd++ ;
+<a name="l02524"></a>02524         }
+<a name="l02525"></a>02525         <span class="keywordflow">else</span>
+<a name="l02526"></a>02526         {
+<a name="l02527"></a>02527             continue ;
+<a name="l02528"></a>02528         }
+<a name="l02529"></a>02529     }
+<a name="l02530"></a>02530 
+<a name="l02531"></a>02531     <span class="keywordflow">if</span> ( dispInd == 0 )
+<a name="l02532"></a>02532     {
+<a name="l02533"></a>02533         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" zero dispersion?\n"</span>);
+<a name="l02534"></a>02534         <span class="keywordflow">return</span> NULL ;
+<a name="l02535"></a>02535     }
+<a name="l02536"></a>02536    
+<a name="l02537"></a>02537     <span class="comment">/* mirror the wavelength map and the raw image if </span>
+<a name="l02538"></a>02538 <span class="comment">       the dispersion is negative */</span>
+<a name="l02539"></a>02539     <span class="keywordflow">if</span> ( dispInd < 0 )
+<a name="l02540"></a>02540     {
+<a name="l02541"></a>02541 
+<a name="l02542"></a>02542         <span class="comment">/* allocate a temp image */</span>
+<a name="l02543"></a>02543         <span class="keywordflow">if</span> ( NULL == ( tempCalImage = cpl_image_new(clx,cly,CPL_TYPE_FLOAT)))
+<a name="l02544"></a>02544         {
+<a name="l02545"></a>02545             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" cannot allocate a new image\n"</span>);
+<a name="l02546"></a>02546             <span class="keywordflow">return</span> NULL ;
+<a name="l02547"></a>02547         }
+<a name="l02548"></a>02548         ptcdata=cpl_image_get_data_float(tempCalImage);
+<a name="l02549"></a>02549         <span class="keywordflow">if</span> ( NULL == ( tempImage = cpl_image_new( ilx, ily,CPL_TYPE_FLOAT)))
+<a name="l02550"></a>02550         {
+<a name="l02551"></a>02551             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" cannot allocate a new image\n"</span>);
+<a name="l02552"></a>02552             cpl_image_delete(tempCalImage) ;
+<a name="l02553"></a>02553             <span class="keywordflow">return</span> NULL ;
+<a name="l02554"></a>02554         }
+<a name="l02555"></a>02555         ptidata=cpl_image_get_data_float(tempImage);
+<a name="l02556"></a>02556 
+<a name="l02557"></a>02557         <span class="keywordflow">for</span> ( col = 0 ; col < clx ; col++ )
+<a name="l02558"></a>02558         {
+<a name="l02559"></a>02559             n = cly - 1 ;
+<a name="l02560"></a>02560             <span class="keywordflow">for</span> ( row = 0 ; row < cly ; row++ )
+<a name="l02561"></a>02561             {
+<a name="l02562"></a>02562                 ptcdata[col+row*clx] = pcdata[col+n*clx] ;
+<a name="l02563"></a>02563                 ptidata[col+row*clx] = pidata[col+n*clx] ;
+<a name="l02564"></a>02564                 n-- ;
+<a name="l02565"></a>02565             }
+<a name="l02566"></a>02566         }
+<a name="l02567"></a>02567 
+<a name="l02568"></a>02568         <span class="keywordflow">for</span> ( i = 0 ; i < (int) ilx*ily ; i++ )
+<a name="l02569"></a>02569         {
+<a name="l02570"></a>02570             pidata[i] = ptidata[i] ;
+<a name="l02571"></a>02571             pcdata[i] = ptcdata[i] ;
+<a name="l02572"></a>02572         }
+<a name="l02573"></a>02573         cpl_image_delete(tempCalImage) ;
+<a name="l02574"></a>02574         cpl_image_delete(tempImage) ;
+<a name="l02575"></a>02575     }
+<a name="l02576"></a>02576 
+<a name="l02577"></a>02577     <span class="comment">/* determine the max and min pixel value in the first and the last row */</span>
+<a name="l02578"></a>02578     *maxval = -FLT_MAX ;
+<a name="l02579"></a>02579     *minval =  FLT_MAX ;
+<a name="l02580"></a>02580     mindisp = FLT_MAX ;
+<a name="l02581"></a>02581     <span class="keywordflow">for</span> ( col = 0 ; col < clx ; col++ )
+<a name="l02582"></a>02582     {
+<a name="l02583"></a>02583         <span class="keywordflow">if</span> ( isnan(pcdata[col]) || pcdata[col] <= 0. )
+<a name="l02584"></a>02584         {
+<a name="l02585"></a>02585            continue ;
+<a name="l02586"></a>02586         }
+<a name="l02587"></a>02587         disp = (pcdata[col+(clx)*((cly)-1)]
+<a name="l02588"></a>02588                - pcdata[col]) / (float)cly ;
+<a name="l02589"></a>02589         <span class="keywordflow">if</span> ( mindisp > disp )
+<a name="l02590"></a>02590         {
+<a name="l02591"></a>02591             mindisp = disp ;
+<a name="l02592"></a>02592         }
+<a name="l02593"></a>02593         <span class="keywordflow">if</span> ( *minval >= pcdata[col] )
+<a name="l02594"></a>02594         {
+<a name="l02595"></a>02595             *minval = pcdata[col] ;
+<a name="l02596"></a>02596         }
+<a name="l02597"></a>02597         <span class="keywordflow">if</span> ( *maxval <= pcdata[col + (clx)*((cly)-1)] )
+<a name="l02598"></a>02598         {
+<a name="l02599"></a>02599             *maxval = pcdata[col + (clx)*((cly)-1)] ;
+<a name="l02600"></a>02600         }
+<a name="l02601"></a>02601     }
+<a name="l02602"></a>02602 
+<a name="l02603"></a>02603     <span class="comment">/* find the used grating and set the dispersion to the defined value */</span>
+<a name="l02604"></a>02604     <span class="keywordflow">if</span> (*minval > 1.9 )
+<a name="l02605"></a>02605     {
+<a name="l02606"></a>02606         <span class="keywordflow">if</span> ( cly > 1024 && cly < 3000)
+<a name="l02607"></a>02607         {
+<a name="l02608"></a>02608             *dispersion = DISPERSION_K_DITH ;
+<a name="l02609"></a>02609             *centralLambda = CENTRALLAMBDA_K ;
+<a name="l02610"></a>02610         }
+<a name="l02611"></a>02611         <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( cly < 2000)
+<a name="l02612"></a>02612         {
+<a name="l02613"></a>02613             *dispersion = DISPERSION_K ;
+<a name="l02614"></a>02614             *centralLambda = CENTRALLAMBDA_K ;
+<a name="l02615"></a>02615         }
+<a name="l02616"></a>02616         <span class="keywordflow">else</span>
+<a name="l02617"></a>02617         {
+<a name="l02618"></a>02618             *dispersion = DISPERSION_K_DITH/2 ;
+<a name="l02619"></a>02619             *centralLambda = CENTRALLAMBDA_K ;
+<a name="l02620"></a>02620         }
+<a name="l02621"></a>02621     }
+<a name="l02622"></a>02622     <span class="keywordflow">else</span> <span class="keywordflow">if</span> (*minval < 1.2 )
+<a name="l02623"></a>02623     {
+<a name="l02624"></a>02624         <span class="keywordflow">if</span> ( cly > 1024 )
+<a name="l02625"></a>02625         {
+<a name="l02626"></a>02626             *dispersion = DISPERSION_J_DITH ;
+<a name="l02627"></a>02627             *centralLambda = CENTRALLAMBDA_J ;
+<a name="l02628"></a>02628         }
+<a name="l02629"></a>02629         <span class="keywordflow">else</span>
+<a name="l02630"></a>02630         {
+<a name="l02631"></a>02631             *dispersion = DISPERSION_J ;
+<a name="l02632"></a>02632             *centralLambda = CENTRALLAMBDA_J ;
+<a name="l02633"></a>02633         }
+<a name="l02634"></a>02634     }
+<a name="l02635"></a>02635     <span class="keywordflow">else</span> 
+<a name="l02636"></a>02636     {
+<a name="l02637"></a>02637         <span class="keywordflow">if</span> ( *maxval > 2.3 )
+<a name="l02638"></a>02638         {
+<a name="l02639"></a>02639             <span class="keywordflow">if</span> ( cly > 1024 )
+<a name="l02640"></a>02640             {
+<a name="l02641"></a>02641                 *dispersion = DISPERSION_HK_DITH ;
+<a name="l02642"></a>02642                 *centralLambda = CENTRALLAMBDA_HK ;
+<a name="l02643"></a>02643             }
+<a name="l02644"></a>02644             <span class="keywordflow">else</span>
+<a name="l02645"></a>02645             {
+<a name="l02646"></a>02646                 *dispersion = DISPERSION_HK ;
+<a name="l02647"></a>02647                 *centralLambda = CENTRALLAMBDA_HK ;
+<a name="l02648"></a>02648             }
+<a name="l02649"></a>02649         }
+<a name="l02650"></a>02650         <span class="keywordflow">else</span> 
+<a name="l02651"></a>02651         {
+<a name="l02652"></a>02652             <span class="keywordflow">if</span> ( cly > 1024 )
+<a name="l02653"></a>02653             {
+<a name="l02654"></a>02654                 *dispersion = DISPERSION_H_DITH ;
+<a name="l02655"></a>02655                 *centralLambda = CENTRALLAMBDA_H ;
+<a name="l02656"></a>02656             }
+<a name="l02657"></a>02657             <span class="keywordflow">else</span>
+<a name="l02658"></a>02658             {
+<a name="l02659"></a>02659                 *dispersion = DISPERSION_H ;
+<a name="l02660"></a>02660                 *centralLambda = CENTRALLAMBDA_H ;
+<a name="l02661"></a>02661             }
+<a name="l02662"></a>02662         }
+<a name="l02663"></a>02663     }
+<a name="l02664"></a>02664 
+<a name="l02665"></a>02665     <span class="comment">/*if ( *minval + (float)n_rows * *dispersion < *maxval ) </span>
+<a name="l02666"></a>02666 <span class="comment">    {</span>
+<a name="l02667"></a>02667 <span class="comment">        sinfo_msg_error(" given number of rows too small!\n");</span>
+<a name="l02668"></a>02668 <span class="comment">        return NULL ;</span>
+<a name="l02669"></a>02669 <span class="comment">    }*/</span>
+<a name="l02670"></a>02670     <span class="keywordflow">if</span> ( (*maxval - *minval) / *dispersion < (float)cly ) 
+<a name="l02671"></a>02671     {
+<a name="l02672"></a>02672         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" must be something wrong with the wavelength map!\n"</span>);
+<a name="l02673"></a>02673         <span class="keywordflow">return</span> NULL ;
+<a name="l02674"></a>02674     }
+<a name="l02675"></a>02675    
+<a name="l02676"></a>02676     <span class="comment">/* determine the central pixel and the lambda in the first image row */</span>
+<a name="l02677"></a>02677     *n_rows = floor(floor(0.5+(*maxval - *minval) / *dispersion)/2+0.5)*2;
+<a name="l02678"></a>02678     *centralpix = *n_rows / 2 ; 
+<a name="l02679"></a>02679     minLambda  = *centralLambda - *dispersion * (float)*centralpix ;
+<a name="l02680"></a>02680     <span class="comment">/*if ( (minLambda + *dispersion * n_rows) < *maxval ) </span>
+<a name="l02681"></a>02681 <span class="comment">    {</span>
+<a name="l02682"></a>02682 <span class="comment">        sinfo_msg_error(" not enough rows defined \n");</span>
+<a name="l02683"></a>02683 <span class="comment">        return NULL ;</span>
+<a name="l02684"></a>02684 <span class="comment">    }</span>
+<a name="l02685"></a>02685 <span class="comment">    if ( minLambda  > *minval ) </span>
+<a name="l02686"></a>02686 <span class="comment">    {</span>
+<a name="l02687"></a>02687 <span class="comment">        sinfo_msg_error(" not enough rows defined \n");</span>
+<a name="l02688"></a>02688 <span class="comment">        return NULL ;</span>
+<a name="l02689"></a>02689 <span class="comment">    }*/</span>
+<a name="l02690"></a>02690 
+<a name="l02691"></a>02691     <span class="comment">/* allocate memory */</span>
+<a name="l02692"></a>02692     <span class="keywordflow">if</span> ( NULL == ( retImage = cpl_image_new( ilx, *n_rows,CPL_TYPE_FLOAT ) ))
+<a name="l02693"></a>02693     {
+<a name="l02694"></a>02694         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" cannot allocate a new image\n"</span>);
+<a name="l02695"></a>02695         <span class="keywordflow">return</span> NULL ;
+<a name="l02696"></a>02696     }
+<a name="l02697"></a>02697     podata=cpl_image_get_data_float(retImage);
+<a name="l02698"></a>02698     olx=cpl_image_get_size_x(retImage);
+<a name="l02699"></a>02699     oly=cpl_image_get_size_y(retImage);
+<a name="l02700"></a>02700     <span class="comment">/* now go through the columns */</span>
+<a name="l02701"></a>02701     retimagecol = cpl_malloc(*n_rows * <span class="keyword">sizeof</span>(retimagecol[0]));
+<a name="l02702"></a>02702     calcolpos = cpl_malloc(*n_rows * <span class="keyword">sizeof</span>(calcolpos[0]));    
+<a name="l02703"></a>02703     <span class="keywordflow">for</span> ( col = 0 ; col < olx ; col++ )
+<a name="l02704"></a>02704     {
+<a name="l02705"></a>02705         <span class="comment">/*------------------------------------------------------------------ </span>
+<a name="l02706"></a>02706 <span class="comment">         * copy the columns of the source image and the wavemap image into</span>
+<a name="l02707"></a>02707 <span class="comment">         * buffer arrays to speed things up</span>
+<a name="l02708"></a>02708 <span class="comment">         */</span>
+<a name="l02709"></a>02709         sum = 0. ;
+<a name="l02710"></a>02710         <span class="keywordflow">for</span> ( row = 0 ; row < ily ; row++ )
+<a name="l02711"></a>02711         {
+<a name="l02712"></a>02712             imagecol[row] = pidata[col + row*ilx] ; 
+<a name="l02713"></a>02713             <span class="keywordflow">if</span> (!isnan(imagecol[row]))
+<a name="l02714"></a>02714             {
+<a name="l02715"></a>02715                 sum += imagecol[row] ;
+<a name="l02716"></a>02716             }
+<a name="l02717"></a>02717             calcol[row]   = pcdata[col + row*clx] ; 
+<a name="l02718"></a>02718         }
+<a name="l02719"></a>02719 
+<a name="l02720"></a>02720         <span class="keywordflow">for</span> ( row = 0 ; row < oly ; row++ )
+<a name="l02721"></a>02721         {
+<a name="l02722"></a>02722             retimagecol[row] = 0. ;
+<a name="l02723"></a>02723             calcolpos[row] = -1;
+<a name="l02724"></a>02724         }
+<a name="l02725"></a>02725 
+<a name="l02726"></a>02726     <span class="keywordflow">for</span> ( row=0 ; row < cly ; row++)
+<a name="l02727"></a>02727     {
+<a name="l02728"></a>02728         temprow = (calcol[row]- minLambda)/ *dispersion;
+<a name="l02729"></a>02729         <span class="keywordflow">if</span> (temprow >= 0 && temprow < oly)
+<a name="l02730"></a>02730             calcolpos[(int) temprow]  = row;
+<a name="l02731"></a>02731     }
+<a name="l02732"></a>02732         
+<a name="l02733"></a>02733     zeroind = 0 ;
+<a name="l02734"></a>02734        
+<a name="l02735"></a>02735 
+<a name="l02736"></a>02736         <span class="keywordflow">for</span> ( row = 0 ; row < oly ; row++ )
+<a name="l02737"></a>02737         {
+<a name="l02738"></a>02738             lambda = minLambda + *dispersion * (float) row ;
+<a name="l02739"></a>02739       
+<a name="l02740"></a>02740             <span class="comment">/*--------------------------------------------------------------- </span>
+<a name="l02741"></a>02741 <span class="comment">             * lambda must lie between the two available wavelength extremes</span>
+<a name="l02742"></a>02742 <span class="comment">             * otherwise the image pixels are set to ZERO </span>
+<a name="l02743"></a>02743 <span class="comment">             */</span>
+<a name="l02744"></a>02744             <span class="keywordflow">if</span> ( row < cly )
+<a name="l02745"></a>02745             {
+<a name="l02746"></a>02746                 <span class="keywordflow">if</span> ( isnan(calcol[row]) )
+<a name="l02747"></a>02747                 {
+<a name="l02748"></a>02748                     zeroind = 1 ;
+<a name="l02749"></a>02749                 } 
+<a name="l02750"></a>02750             }
+<a name="l02751"></a>02751 
+<a name="l02752"></a>02752             <span class="keywordflow">if</span> ( (lambda < calcol[0]) || 
+<a name="l02753"></a>02753                  (lambda > calcol[(cly)-1]) || zeroind == 1 )
+<a name="l02754"></a>02754             {
+<a name="l02755"></a>02755                 retimagecol[row] = ZERO ;
+<a name="l02756"></a>02756                 continue ;
+<a name="l02757"></a>02757             }
+<a name="l02758"></a>02758             <span class="comment">/*testrow = 0 ; </span>
+<a name="l02759"></a>02759 <span class="comment">            while ( lambda > calcol[testrow] )</span>
+<a name="l02760"></a>02760 <span class="comment">            {</span>
+<a name="l02761"></a>02761 <span class="comment">                testrow++ ;</span>
+<a name="l02762"></a>02762 <span class="comment">            }*/</span>
+<a name="l02763"></a>02763         <span class="keywordflow">if</span> (calcolpos[row]==-1) {
+<a name="l02764"></a>02764                 <span class="keywordflow">if</span>(row>= (*n_rows-1)) calcolpos[row] = calcolpos[row-1];
+<a name="l02765"></a>02765                 <span class="keywordflow">if</span>(row<  (*n_rows-1)) calcolpos[row] = calcolpos[row+1];
+<a name="l02766"></a>02766         }
+<a name="l02767"></a>02767         <span class="keywordflow">if</span>(calcolpos[row]>0) {
+<a name="l02768"></a>02768           <span class="keywordflow">if</span> (lambda-calcol[calcolpos[row]-1]==0.) {
+<a name="l02769"></a>02769         calcolpos[row]=calcolpos[row]-1;
+<a name="l02770"></a>02770           }
+<a name="l02771"></a>02771         }
+<a name="l02772"></a>02772         testrow = calcolpos[row];
+<a name="l02773"></a>02773 
+<a name="l02774"></a>02774             <span class="comment">/*-----------------------------------------------------------------</span>
+<a name="l02775"></a>02775 <span class="comment">             * at this point calcol[testrow-1] < lambda <= calcol[testrow] </span>
+<a name="l02776"></a>02776 <span class="comment">             * now determine the box position in which the polint fit is </span>
+<a name="l02777"></a>02777 <span class="comment">               carried through.</span>
+<a name="l02778"></a>02778 <span class="comment">             * the half width of the box is half the number of fit parameters.</span>
+<a name="l02779"></a>02779 <span class="comment">             * Now we determine the start position of the fitting box and treat</span>
+<a name="l02780"></a>02780 <span class="comment">             * the special case of being near the sinfo_edge.</span>
+<a name="l02781"></a>02781 <span class="comment">             */</span>
+<a name="l02782"></a>02782 
+<a name="l02783"></a>02783             <span class="keywordflow">if</span> ( n_params % 2 == 0 )
+<a name="l02784"></a>02784             {
+<a name="l02785"></a>02785                 half_width = (int)(n_params/2) - 1 ;
+<a name="l02786"></a>02786             }
+<a name="l02787"></a>02787             <span class="keywordflow">else</span>
+<a name="l02788"></a>02788             {
+<a name="l02789"></a>02789                 half_width = (int)(n_params/2) ;
+<a name="l02790"></a>02790             }
+<a name="l02791"></a>02791 
+<a name="l02792"></a>02792 
+<a name="l02793"></a>02793             <span class="keywordflow">if</span> ( isnan(imagecol[testrow]) )
+<a name="l02794"></a>02794             {
+<a name="l02795"></a>02795                 <span class="keywordflow">for</span> ( i = row-half_width ; i < row-half_width+n_params ; i++ )
+<a name="l02796"></a>02796                 { 
+<a name="l02797"></a>02797                     <span class="keywordflow">if</span> (i < 0) continue ;
+<a name="l02798"></a>02798                     <span class="keywordflow">if</span> ( i >= oly ) continue  ;
+<a name="l02799"></a>02799                     retimagecol[i] = ZERO ;
+<a name="l02800"></a>02800                 }
+<a name="l02801"></a>02801                 imagecol[testrow] = 0. ;
+<a name="l02802"></a>02802             }
+<a name="l02803"></a>02803 
+<a name="l02804"></a>02804         }
+<a name="l02805"></a>02805 
+<a name="l02806"></a>02806         <span class="comment">/* now loop over the rows and establish the lambda for each row */</span>
+<a name="l02807"></a>02807         new_sum = 0. ;
+<a name="l02808"></a>02808         <span class="keywordflow">for</span> ( row = 0 ; row < oly ; row++ )
+<a name="l02809"></a>02809         {
+<a name="l02810"></a>02810             <span class="keywordflow">if</span> ( isnan(retimagecol[row]) )
+<a name="l02811"></a>02811             {
+<a name="l02812"></a>02812                 continue ;
+<a name="l02813"></a>02813             }
+<a name="l02814"></a>02814         lambda = minLambda + *dispersion * (float) row ;
+<a name="l02815"></a>02815       
+<a name="l02816"></a>02816             <span class="comment">/*--------------------------------------------------------------- </span>
+<a name="l02817"></a>02817 <span class="comment">             * lambda must lie between the two available wavelength extremes</span>
+<a name="l02818"></a>02818 <span class="comment">             * otherwise the image pixels are set to ZERO </span>
+<a name="l02819"></a>02819 <span class="comment">             */</span>
+<a name="l02820"></a>02820             <span class="keywordflow">if</span> ( (lambda < calcol[0]) || (lambda > calcol[(cly)-1]) ) 
+<a name="l02821"></a>02821             {
+<a name="l02822"></a>02822                 retimagecol[row] = ZERO ;
+<a name="l02823"></a>02823                 continue ;
+<a name="l02824"></a>02824             }
+<a name="l02825"></a>02825             <span class="comment">/*testrow = 0 ; </span>
+<a name="l02826"></a>02826 <span class="comment">            while ( lambda > calcol[testrow] )</span>
+<a name="l02827"></a>02827 <span class="comment">            {</span>
+<a name="l02828"></a>02828 <span class="comment">                testrow++ ;</span>
+<a name="l02829"></a>02829 <span class="comment">            }*/</span>
+<a name="l02830"></a>02830         <span class="keywordflow">if</span> (calcolpos[row]==-1) {
+<a name="l02831"></a>02831                <span class="keywordflow">if</span>(row >= (*n_rows-1)) calcolpos[row] = calcolpos[row-1];
+<a name="l02832"></a>02832                <span class="keywordflow">if</span>(row <  (*n_rows-1)) calcolpos[row] = calcolpos[row+1];
+<a name="l02833"></a>02833         }
+<a name="l02834"></a>02834 
+<a name="l02835"></a>02835         testrow = calcolpos[row];
+<a name="l02836"></a>02836 
+<a name="l02837"></a>02837             <span class="comment">/*--------------------------------------------------------------</span>
+<a name="l02838"></a>02838 <span class="comment">             * at this point calcol[testrow-1] < lambda <= calcol[testrow] </span>
+<a name="l02839"></a>02839 <span class="comment">             * now determine the box position in which the polynomial </span>
+<a name="l02840"></a>02840 <span class="comment">               interpolation is carried through.</span>
+<a name="l02841"></a>02841 <span class="comment">             * the half width of the box is half the number of fit parameters.</span>
+<a name="l02842"></a>02842 <span class="comment">             * Now we determine the start position of the fitting box and treat</span>
+<a name="l02843"></a>02843 <span class="comment">             * the special case of being near the sinfo_edge.</span>
+<a name="l02844"></a>02844 <span class="comment">             */</span>
+<a name="l02845"></a>02845 
+<a name="l02846"></a>02846             <span class="keywordflow">if</span> ( n_params % 2 == 0 )
+<a name="l02847"></a>02847             {
+<a name="l02848"></a>02848                 half_width = (int)(n_params/2) - 1 ;
+<a name="l02849"></a>02849             }
+<a name="l02850"></a>02850             <span class="keywordflow">else</span>
+<a name="l02851"></a>02851             {
+<a name="l02852"></a>02852                 half_width = (int)(n_params/2) ;
+<a name="l02853"></a>02853             }
+<a name="l02854"></a>02854 
+<a name="l02855"></a>02855             firstpos   = testrow - half_width ;
+<a name="l02856"></a>02856             <span class="keywordflow">if</span> ( firstpos < 0 )
+<a name="l02857"></a>02857             {
+<a name="l02858"></a>02858                 firstpos = 0 ;
+<a name="l02859"></a>02859             }
+<a name="l02860"></a>02860             <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( firstpos > ((cly)-n_params) )
+<a name="l02861"></a>02861             {
+<a name="l02862"></a>02862                firstpos = cly - n_params ;
+<a name="l02863"></a>02863             }
+<a name="l02864"></a>02864             <span class="keywordflow">if</span> ( isnan(imagecol[firstpos]) )
+<a name="l02865"></a>02865             {
+<a name="l02866"></a>02866                 retimagecol[row] = ZERO ;
+<a name="l02867"></a>02867                 continue ;
+<a name="l02868"></a>02868             }
+<a name="l02869"></a>02869             
+<a name="l02870"></a>02870 
+<a name="l02871"></a>02871             <span class="comment">/* we must rescale the x-values (smaller than 1) </span>
+<a name="l02872"></a>02872 <span class="comment">               for the fitting routine */</span>
+<a name="l02873"></a>02873             dif = calcol[firstpos+n_params-1] - calcol[firstpos] ;
+<a name="l02874"></a>02874             <span class="keywordflow">for</span> ( i = 0 ; i < n_params ; i++ )
+<a name="l02875"></a>02875             {
+<a name="l02876"></a>02876             x_renorm[i] = (calcol[firstpos + i] - calcol[firstpos]) / dif ;
+<a name="l02877"></a>02877         }
+<a name="l02878"></a>02878         
+<a name="l02879"></a>02879            
+<a name="l02880"></a>02880             lambda_renorm = ( lambda - calcol[firstpos] ) / dif ; 
+<a name="l02881"></a>02881         
+<a name="l02882"></a>02882         imageptr = &imagecol[firstpos] ;
+<a name="l02883"></a>02883         
+<a name="l02884"></a>02884         flag = 0;
+<a name="l02885"></a>02885         poly=sinfo_new_nev_ille(x_renorm, imageptr, 
+<a name="l02886"></a>02886                                     n_params-1, lambda_renorm, &flag);
+<a name="l02887"></a>02887         
+<a name="l02888"></a>02888             new_sum += poly ;
+<a name="l02889"></a>02889             retimagecol[row] = poly ; 
+<a name="l02890"></a>02890     }
+<a name="l02891"></a>02891     
+<a name="l02892"></a>02892         <span class="comment">/* now renorm the total flux */</span>
+<a name="l02893"></a>02893         <span class="keywordflow">for</span> ( row = 0 ; row < oly ; row++ )
+<a name="l02894"></a>02894         {
+<a name="l02895"></a>02895             <span class="keywordflow">if</span> ( new_sum == 0. ) new_sum = 1. ;
+<a name="l02896"></a>02896             <span class="keywordflow">if</span> ( isnan(retimagecol[row]) )
+<a name="l02897"></a>02897             {
+<a name="l02898"></a>02898                 podata[col+row*olx] = ZERO ;
+<a name="l02899"></a>02899             }
+<a name="l02900"></a>02900             <span class="keywordflow">else</span>
+<a name="l02901"></a>02901             {
+<a name="l02902"></a>02902                 <span class="comment">/* rescaling is commented out because it delivers wrong results</span>
+<a name="l02903"></a>02903 <span class="comment">                   in case of appearance of blanks or bad pixels */</span>
+<a name="l02904"></a>02904                 podata[col+row*olx] = retimagecol[row] <span class="comment">/* * sum/new_sum*/</span> ;
+<a name="l02905"></a>02905             }
+<a name="l02906"></a>02906         }
+<a name="l02907"></a>02907 
+<a name="l02908"></a>02908     }
+<a name="l02909"></a>02909     cpl_free(retimagecol);
+<a name="l02910"></a>02910     cpl_free(calcolpos);
+<a name="l02911"></a>02911     cpl_free(imagecol) ;
+<a name="l02912"></a>02912     cpl_free(calcol) ;
+<a name="l02913"></a>02913     cpl_free(x_renorm) ;
+<a name="l02914"></a>02914     
+<a name="l02915"></a>02915     <span class="keywordflow">return</span> retImage ;
+<a name="l02916"></a>02916 }
+<a name="l02917"></a>02917 
+<a name="l02919"></a>02919 <span class="comment">/*___oOo___*/</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__wave__calibration_8h_source.html b/html/sinfo__wave__calibration_8h_source.html
new file mode 100644
index 0000000..75fafaa
--- /dev/null
+++ b/html/sinfo__wave__calibration_8h_source.html
@@ -0,0 +1,185 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_wave_calibration.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_wave_calibration.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#ifndef SINFO_WAVE_CALIBRATION_H</span>
+<a name="l00002"></a>00002 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_WAVE_CALIBRATION_H</span>
+<a name="l00003"></a>00003 <span class="preprocessor"></span><span class="comment">/*</span>
+<a name="l00004"></a>00004 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00005"></a>00005 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00006"></a>00006 <span class="comment"> *</span>
+<a name="l00007"></a>00007 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00008"></a>00008 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00009"></a>00009 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00010"></a>00010 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00011"></a>00011 <span class="comment"> *</span>
+<a name="l00012"></a>00012 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00013"></a>00013 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00014"></a>00014 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00015"></a>00015 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00016"></a>00016 <span class="comment"> *</span>
+<a name="l00017"></a>00017 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00018"></a>00018 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00019"></a>00019 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00020"></a>00020 <span class="comment"> */</span>
+<a name="l00021"></a>00021 <span class="comment">/*******************************************************************************</span>
+<a name="l00022"></a>00022 <span class="comment">* E.S.O. - VLT project</span>
+<a name="l00023"></a>00023 <span class="comment">*</span>
+<a name="l00024"></a>00024 <span class="comment">* "@(#) $Id: sinfo_wave_calibration.h,v 1.5 2008/03/25 08:20:43 amodigli Exp $"</span>
+<a name="l00025"></a>00025 <span class="comment">*</span>
+<a name="l00026"></a>00026 <span class="comment">* who       when      what</span>
+<a name="l00027"></a>00027 <span class="comment">* --------  --------  ----------------------------------------------</span>
+<a name="l00028"></a>00028 <span class="comment">* schreib  13/07/00  created</span>
+<a name="l00029"></a>00029 <span class="comment">*/</span>
+<a name="l00030"></a>00030 
+<a name="l00031"></a>00031 <span class="comment">/************************************************************************</span>
+<a name="l00032"></a>00032 <span class="comment"> * wave_calibration.h</span>
+<a name="l00033"></a>00033 <span class="comment"> * routines needed for wavelength calibration</span>
+<a name="l00034"></a>00034 <span class="comment"> *----------------------------------------------------------------------</span>
+<a name="l00035"></a>00035 <span class="comment"> */</span>
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="comment">/*</span>
+<a name="l00038"></a>00038 <span class="comment"> * header files</span>
+<a name="l00039"></a>00039 <span class="comment"> */</span>
+<a name="l00040"></a>00040 
+<a name="l00041"></a>00041 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include "sinfo_wavecal.h"</span>
+<a name="l00043"></a>00043 <span class="comment">/*</span>
+<a name="l00044"></a>00044 <span class="comment"> * function prototypes</span>
+<a name="l00045"></a>00045 <span class="comment"> */</span>
+<a name="l00046"></a>00046 
+<a name="l00054"></a>00054 FitParams ** 
+<a name="l00055"></a>00055 sinfo_new_fit_params( <span class="keywordtype">int</span> n_params ) ;
+<a name="l00056"></a>00056 
+<a name="l00064"></a>00064 <span class="keywordtype">void</span> 
+<a name="l00065"></a>00065 sinfo_new_destroy_fit_params ( FitParams *** params ) ;
+<a name="l00066"></a>00066 
+<a name="l00075"></a>00075 <span class="keywordtype">void</span> 
+<a name="l00076"></a>00076 sinfo_new_dump_fit_params_to_ascii ( FitParams ** params, <span class="keyword">const</span> <span class="keywordtype">char</span> * filename ) ;
+<a name="l00077"></a>00077 
+<a name="l00086"></a>00086 <span class="keywordtype">void</span> 
+<a name="l00087"></a>00087 sinfo_new_dump_ascii_to_fit_params ( FitParams ** params, <span class="keywordtype">char</span> * filename ) ;
+<a name="l00088"></a>00088 
+<a name="l00129"></a>00129 <span class="keywordtype">int</span> 
+<a name="l00130"></a>00130 sinfo_new_find_lines(cpl_image * lineImage,
+<a name="l00131"></a>00131                <span class="keywordtype">float</span>    * wave_position,
+<a name="l00132"></a>00132                <span class="keywordtype">float</span>    * wave_intensity,
+<a name="l00133"></a>00133                <span class="keywordtype">int</span>        n_lines,
+<a name="l00134"></a>00134                <span class="keywordtype">int</span>     ** row_clean,
+<a name="l00135"></a>00135                <span class="keywordtype">float</span>   ** wavelength_clean,
+<a name="l00136"></a>00136                <span class="keywordtype">float</span>      beginWave,
+<a name="l00137"></a>00137                <span class="keywordtype">float</span>      dispersion1,
+<a name="l00138"></a>00138                <span class="keywordtype">float</span>      dispersion2,
+<a name="l00139"></a>00139                <span class="keywordtype">float</span>      mindiff,
+<a name="l00140"></a>00140                <span class="keywordtype">int</span>        halfWidth,
+<a name="l00141"></a>00141                <span class="keywordtype">int</span>      * n_found_lines,
+<a name="l00142"></a>00142                <span class="keywordtype">float</span>      sigma,
+<a name="l00143"></a>00143                <span class="keywordtype">int</span>      * sum_lines ) ;
+<a name="l00144"></a>00144 
+<a name="l00153"></a>00153 <span class="keywordtype">int</span> 
+<a name="l00154"></a>00154 sinfo_new_read_list( <span class="keywordtype">char</span> * listname, 
+<a name="l00155"></a>00155                      <span class="keywordtype">float</span> * lineCenter, 
+<a name="l00156"></a>00156                      <span class="keywordtype">float</span> * lineIntensity ) ;
+<a name="l00157"></a>00157 
+<a name="l00187"></a>00187 <span class="keywordtype">int</span> 
+<a name="l00188"></a>00188 sinfo_new_line_fit (cpl_image  * mergedImage,
+<a name="l00189"></a>00189               FitParams * par,
+<a name="l00190"></a>00190               <span class="keywordtype">float</span>       fwhm,
+<a name="l00191"></a>00191               <span class="keywordtype">int</span>         lineInd,
+<a name="l00192"></a>00192               <span class="keywordtype">int</span>         column,
+<a name="l00193"></a>00193               <span class="keywordtype">int</span>         halfWidth,
+<a name="l00194"></a>00194               <span class="keywordtype">int</span>         lineRow,
+<a name="l00195"></a>00195               <span class="keywordtype">float</span>       min_amplitude,
+<a name="l00196"></a>00196           Vector    *  line,
+<a name="l00197"></a>00197           <span class="keywordtype">int</span>       *  mpar,
+<a name="l00198"></a>00198           <span class="keywordtype">float</span>     *  xdat,
+<a name="l00199"></a>00199           <span class="keywordtype">float</span>     *  wdat ) ;
+<a name="l00200"></a>00200 
+<a name="l00225"></a>00225 <span class="keywordtype">int</span> 
+<a name="l00226"></a>00226 sinfo_new_fit_lines (cpl_image  *  line_image,
+<a name="l00227"></a>00227                FitParams ** allParams,
+<a name="l00228"></a>00228                <span class="keywordtype">float</span>        fwhm,
+<a name="l00229"></a>00229                <span class="keywordtype">int</span>       *  n_lines,
+<a name="l00230"></a>00230                <span class="keywordtype">int</span>       ** row,
+<a name="l00231"></a>00231                <span class="keywordtype">float</span>     ** wavelength,
+<a name="l00232"></a>00232                <span class="keywordtype">int</span>          width,
+<a name="l00233"></a>00233                <span class="keywordtype">float</span>        min_amplitude ) ;
+<a name="l00234"></a>00234 
+<a name="l00257"></a>00257 <span class="keywordtype">float</span> 
+<a name="l00258"></a>00258 sinfo_new_polyfit( FitParams ** par,
+<a name="l00259"></a>00259                <span class="keywordtype">int</span>          column,
+<a name="l00260"></a>00260                <span class="keywordtype">int</span>          n_lines,
+<a name="l00261"></a>00261                <span class="keywordtype">int</span>          n_rows,
+<a name="l00262"></a>00262                <span class="keywordtype">float</span>        dispersion,
+<a name="l00263"></a>00263                <span class="keywordtype">float</span>        max_residual,
+<a name="l00264"></a>00264                <span class="keywordtype">float</span> *      acoefs,
+<a name="l00265"></a>00265                <span class="keywordtype">float</span> *      dacoefs,
+<a name="l00266"></a>00266                <span class="keywordtype">int</span>   *      n_reject,
+<a name="l00267"></a>00267                <span class="keywordtype">int</span>          n_fitcoefs ) ;
+<a name="l00268"></a>00268 
+<a name="l00285"></a>00285 <span class="keywordtype">float</span> 
+<a name="l00286"></a>00286 sinfo_new_coefs_cross_fit ( <span class="keywordtype">int</span>      n_columns,
+<a name="l00287"></a>00287                       <span class="keywordtype">float</span> *  acoefs,
+<a name="l00288"></a>00288                       <span class="keywordtype">float</span> *  dacoefs,
+<a name="l00289"></a>00289                       <span class="keywordtype">float</span> *  bcoefs,
+<a name="l00290"></a>00290                       <span class="keywordtype">int</span>      n_fitcoefs,
+<a name="l00291"></a>00291                       <span class="keywordtype">float</span>    sigma_factor ) ;
+<a name="l00292"></a>00292 
+<a name="l00311"></a>00311 cpl_image * 
+<a name="l00312"></a>00312 sinfo_new_wave_map(cpl_image * lineImage,
+<a name="l00313"></a>00313                     <span class="keywordtype">float</span>   ** bcoefs,
+<a name="l00314"></a>00314                     <span class="keywordtype">int</span>        n_a_fitcoefs,
+<a name="l00315"></a>00315                     <span class="keywordtype">int</span>        n_b_fitcoefs,
+<a name="l00316"></a>00316                     <span class="keywordtype">float</span>    * wavelength,
+<a name="l00317"></a>00317                     <span class="keywordtype">float</span>    * intensity,
+<a name="l00318"></a>00318                     <span class="keywordtype">int</span>        n_lines,
+<a name="l00319"></a>00319                     <span class="keywordtype">int</span>        magFactor) ;
+<a name="l00320"></a>00320 
+<a name="l00365"></a>00365 <span class="keywordtype">int</span> 
+<a name="l00366"></a>00366 sinfo_new_wavelength_calibration(cpl_image   * image,
+<a name="l00367"></a>00367                            FitParams ** par ,
+<a name="l00368"></a>00368                            <span class="keywordtype">float</span>     ** bcoefs,
+<a name="l00369"></a>00369                            <span class="keywordtype">float</span>      * wave,
+<a name="l00370"></a>00370                            <span class="keywordtype">int</span>          n_lines,
+<a name="l00371"></a>00371                            <span class="keywordtype">int</span>       ** row_clean,
+<a name="l00372"></a>00372                            <span class="keywordtype">float</span>     ** wavelength_clean,
+<a name="l00373"></a>00373                            <span class="keywordtype">int</span>        * n_found_lines,
+<a name="l00374"></a>00374                            <span class="keywordtype">float</span>        dispersion,
+<a name="l00375"></a>00375                            <span class="keywordtype">int</span>          halfWidth,
+<a name="l00376"></a>00376                            <span class="keywordtype">float</span>        minAmplitude,
+<a name="l00377"></a>00377                            <span class="keywordtype">float</span>        max_residual,
+<a name="l00378"></a>00378                            <span class="keywordtype">float</span>        fwhm,
+<a name="l00379"></a>00379                            <span class="keywordtype">int</span>          n_a_fitcoefs,
+<a name="l00380"></a>00380                            <span class="keywordtype">int</span>          n_b_fitcoefs,
+<a name="l00381"></a>00381                            <span class="keywordtype">float</span>        sigmaFactor,
+<a name="l00382"></a>00382                <span class="keywordtype">float</span>        pixel_tolerance ) ;
+<a name="l00383"></a>00383 
+<a name="l00395"></a>00395 cpl_image * 
+<a name="l00396"></a>00396 sinfo_new_convolve_image_by_gauss(cpl_image * lineImage,
+<a name="l00397"></a>00397                                  <span class="keywordtype">int</span>        hw ) ;
+<a name="l00398"></a>00398 
+<a name="l00438"></a>00438 cpl_image * 
+<a name="l00439"></a>00439 sinfo_new_defined_resampling(cpl_image * image,
+<a name="l00440"></a>00440                               cpl_image * calimage,
+<a name="l00441"></a>00441                               <span class="keywordtype">int</span>        n_params,
+<a name="l00442"></a>00442                               <span class="keywordtype">int</span>*        n_rows,
+<a name="l00443"></a>00443                               <span class="keywordtype">double</span>   * dispersion,
+<a name="l00444"></a>00444                               <span class="keywordtype">float</span>    * minval,
+<a name="l00445"></a>00445                               <span class="keywordtype">float</span>    * maxval,
+<a name="l00446"></a>00446                               <span class="keywordtype">double</span>   * centralLambda,
+<a name="l00447"></a>00447                               <span class="keywordtype">int</span>    * centralpix ) ;
+<a name="l00448"></a>00448 
+<a name="l00449"></a>00449 
+<a name="l00450"></a>00450 <span class="preprocessor">#endif </span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__wavecal_8c_source.html b/html/sinfo__wavecal_8c_source.html
new file mode 100644
index 0000000..5169074
--- /dev/null
+++ b/html/sinfo__wavecal_8c_source.html
@@ -0,0 +1,3590 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_wavecal.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_wavecal.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*************************************************************************</span>
+<a name="l00020"></a>00020 <span class="comment">* E.S.O. - VLT project</span>
+<a name="l00021"></a>00021 <span class="comment">*</span>
+<a name="l00022"></a>00022 <span class="comment">* </span>
+<a name="l00023"></a>00023 <span class="comment">*</span>
+<a name="l00024"></a>00024 <span class="comment">* who       when      what</span>
+<a name="l00025"></a>00025 <span class="comment">* --------  --------  ----------------------------------------------</span>
+<a name="l00026"></a>00026 <span class="comment">* schreib  22/01/02  created</span>
+<a name="l00027"></a>00027 <span class="comment">*/</span>
+<a name="l00028"></a>00028 
+<a name="l00029"></a>00029 <span class="comment">/************************************************************************</span>
+<a name="l00030"></a>00030 <span class="comment">*   NAME</span>
+<a name="l00031"></a>00031 <span class="comment">*     sinfo_wavecal.c -</span>
+<a name="l00032"></a>00032 <span class="comment">*     routines needed for wavelength calibration with smoothing only</span>
+<a name="l00033"></a>00033 <span class="comment">*     within the slitlets</span>
+<a name="l00034"></a>00034 <span class="comment">*</span>
+<a name="l00035"></a>00035 <span class="comment">*   SYNOPSIS</span>
+<a name="l00036"></a>00036 <span class="comment">*  1) Bcoeffs * sinfo_new_b_coeffs( int n_slitlets,</span>
+<a name="l00037"></a>00037 <span class="comment">*                           int n_acoeffs,</span>
+<a name="l00038"></a>00038 <span class="comment">*                           int n_bcoeffs )</span>
+<a name="l00039"></a>00039 <span class="comment">*  2) void sinfo_new_destroy_b_coeffs ( Bcoeffs * bco )</span>
+<a name="l00040"></a>00040 <span class="comment">*  3) int   sinfo_new_coeffs_cross_slit_fit ( int      n_columns,</span>
+<a name="l00041"></a>00041 <span class="comment">*                                float ** acoefs,</span>
+<a name="l00042"></a>00042 <span class="comment">*                                float ** dacoefs,</span>
+<a name="l00043"></a>00043 <span class="comment">*                                Bcoeffs* bco,</span>
+<a name="l00044"></a>00044 <span class="comment">*                                float    sigma_factor,</span>
+<a name="l00045"></a>00045 <span class="comment">*                                float    dispersion,</span>
+<a name="l00046"></a>00046 <span class="comment">*                                float    pixel_dist,</span>
+<a name="l00047"></a>00047 <span class="comment">*                                float  * chisq )</span>
+<a name="l00048"></a>00048 <span class="comment">*  4) cpl_image * sinfo_new_wave_map_slit ( float ** acoefs,</span>
+<a name="l00049"></a>00049 <span class="comment">*                              int      n_acoefs,</span>
+<a name="l00050"></a>00050 <span class="comment">*                              int      n_rows,</span>
+<a name="l00051"></a>00051 <span class="comment">*                              int      n_columns )</span>
+<a name="l00052"></a>00052 <span class="comment">*  5) cpl_image * sinfo_new_wave_cal( cpl_image   * image, </span>
+<a name="l00053"></a>00053 <span class="comment">*                         FitParams ** par ,</span>
+<a name="l00054"></a>00054 <span class="comment">*                         float     ** abuf,</span>
+<a name="l00055"></a>00055 <span class="comment">*                         int          n_slitlets,</span>
+<a name="l00056"></a>00056 <span class="comment">*                         int       ** row_clean,</span>
+<a name="l00057"></a>00057 <span class="comment">*                         float     ** wavelength_clean,</span>
+<a name="l00058"></a>00058 <span class="comment">*                         int        * n_found_lines,</span>
+<a name="l00059"></a>00059 <span class="comment">*                         float        dispersion,</span>
+<a name="l00060"></a>00060 <span class="comment">*                         int          halfWidth,</span>
+<a name="l00061"></a>00061 <span class="comment">*                         float        minAmplitude,</span>
+<a name="l00062"></a>00062 <span class="comment">*                         float        max_residual,</span>
+<a name="l00063"></a>00063 <span class="comment">*                         float        fwhm,</span>
+<a name="l00064"></a>00064 <span class="comment">*                         int          n_a_fitcoefs,</span>
+<a name="l00065"></a>00065 <span class="comment">*                         int          n_b_fitcoefs,</span>
+<a name="l00066"></a>00066 <span class="comment">*                         float        sigmaFactor,</span>
+<a name="l00067"></a>00067 <span class="comment">*                         float        pixel_dist )</span>
+<a name="l00068"></a>00068 <span class="comment">*  6) int sinfo_new_check_for_fake_lines ( FitParams ** par,</span>
+<a name="l00069"></a>00069 <span class="comment">*                             float        dispersion,</span>
+<a name="l00070"></a>00070 <span class="comment">*                             float     ** wavelength_clean,</span>
+<a name="l00071"></a>00071 <span class="comment">*                             int       ** row_clean,</span>
+<a name="l00072"></a>00072 <span class="comment">*                             int        * n_found_lines,</span>
+<a name="l00073"></a>00073 <span class="comment">*                             int          n_columns,</span>
+<a name="l00074"></a>00074 <span class="comment">*                             float        pixel_tolerance )</span>
+<a name="l00075"></a>00075 <span class="comment">*  7) cpl_image * sinfo_new_create_shifted_slit_wavemap ( cpl_image * lineIm,</span>
+<a name="l00076"></a>00076 <span class="comment">*                                           float    ** coeffs,</span>
+<a name="l00077"></a>00077 <span class="comment">*                                           int      n_fitcoeffs,</span>
+<a name="l00078"></a>00078 <span class="comment">*                                           float  * wavelength,</span>
+<a name="l00079"></a>00079 <span class="comment">*                                           float  * intensity,</span>
+<a name="l00080"></a>00080 <span class="comment">*                                           int      n_lines,</span>
+<a name="l00081"></a>00081 <span class="comment">*                                           int      magFactor )</span>
+<a name="l00082"></a>00082 <span class="comment">*   </span>
+<a name="l00083"></a>00083 <span class="comment">*   DESCRIPTION</span>
+<a name="l00084"></a>00084 <span class="comment">*  1) allocates memory for a new array of </span>
+<a name="l00085"></a>00085 <span class="comment">*     Bcoeffs data structures</span>
+<a name="l00086"></a>00086 <span class="comment">*  2) frees memory of an array of Bcoeffs data structures</span>
+<a name="l00087"></a>00087 <span class="comment">*  3) Fits each single polynomial coefficient acoefs resulting from </span>
+<a name="l00088"></a>00088 <span class="comment">      sinfo_polyfit </span>
+<a name="l00089"></a>00089 <span class="comment">*     across the columns of each slitlet and use the result of this fit to</span>
+<a name="l00090"></a>00090 <span class="comment">*     smooth the acoefs.</span>
+<a name="l00091"></a>00091 <span class="comment">*  4) builds a new wavelength calibration map as fits image</span>
+<a name="l00092"></a>00092 <span class="comment">*     by using the fit coeficients.</span>
+<a name="l00093"></a>00093 <span class="comment">*  5) this routine takes an image from a calibration</span>
+<a name="l00094"></a>00094 <span class="comment">*     emission lamp and delivers the smoothed fit coefficients of  </span>
+<a name="l00095"></a>00095 <span class="comment">*     a polynomial fit along the columns of the line positions as output. </span>
+<a name="l00096"></a>00096 <span class="comment">*     This routine expects Nyquist sampled spectra </span>
+<a name="l00097"></a>00097 <span class="comment">*     (either an interleaved image or an image convolved with an </span>
+<a name="l00098"></a>00098 <span class="comment">*      appropriate function in spectral direction)</span>
+<a name="l00099"></a>00099 <span class="comment">*  6) this routine searches for successfully fitted fake lines like</span>
+<a name="l00100"></a>00100 <span class="comment">*     bad pixels by comparing the found line positons with </span>
+<a name="l00101"></a>00101 <span class="comment">*     estimated template positions. This routine should be</span>
+<a name="l00102"></a>00102 <span class="comment">*     inserted in the wavelength calibration routine just after</span>
+<a name="l00103"></a>00103 <span class="comment">*     the sinfo_fitLines() routine.</span>
+<a name="l00104"></a>00104 <span class="comment">*  7) This routine cross-correlates a shifted emission line frames </span>
+<a name="l00105"></a>00105 <span class="comment">*     and determines the shift to the old one which is given by</span>
+<a name="l00106"></a>00106 <span class="comment">*     its polynomial coefficients.</span>
+<a name="l00107"></a>00107 <span class="comment">*     Then the a0 coefficients is recalculated and afterwards</span>
+<a name="l00108"></a>00108 <span class="comment">*     a new wavelength calibration map is generated using the </span>
+<a name="l00109"></a>00109 <span class="comment">*     already calculated smoothed polynomial coefficients.</span>
+<a name="l00110"></a>00110 <span class="comment">*</span>
+<a name="l00111"></a>00111 <span class="comment">*   FILES</span>
+<a name="l00112"></a>00112 <span class="comment">*</span>
+<a name="l00113"></a>00113 <span class="comment">*   ENVIRONMENT</span>
+<a name="l00114"></a>00114 <span class="comment">*</span>
+<a name="l00115"></a>00115 <span class="comment">*   RETURN VALUES </span>
+<a name="l00116"></a>00116 <span class="comment">*</span>
+<a name="l00117"></a>00117 <span class="comment">*   CAUTIONS </span>
+<a name="l00118"></a>00118 <span class="comment">*</span>
+<a name="l00119"></a>00119 <span class="comment">*   EXAMPLES</span>
+<a name="l00120"></a>00120 <span class="comment">*</span>
+<a name="l00121"></a>00121 <span class="comment">*   SEE ALSO</span>
+<a name="l00122"></a>00122 <span class="comment">*</span>
+<a name="l00123"></a>00123 <span class="comment">*   BUGS   </span>
+<a name="l00124"></a>00124 <span class="comment">*</span>
+<a name="l00125"></a>00125 <span class="comment">*------------------------------------------------------------------------</span>
+<a name="l00126"></a>00126 <span class="comment">*/</span>
+<a name="l00127"></a>00127 
+<a name="l00128"></a>00128 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00129"></a>00129 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00130"></a>00130 <span class="preprocessor">#endif</span>
+<a name="l00131"></a>00131 <span class="preprocessor"></span><span class="preprocessor">#include "sinfo_vltPort.h"</span>
+<a name="l00132"></a>00132 <span class="preprocessor">#include <math.h></span>
+<a name="l00133"></a>00133 
+<a name="l00134"></a>00134 <span class="comment">/* </span>
+<a name="l00135"></a>00135 <span class="comment"> * System Headers</span>
+<a name="l00136"></a>00136 <span class="comment"> */</span>
+<a name="l00137"></a>00137 <span class="comment">/* </span>
+<a name="l00138"></a>00138 <span class="comment"> * Local Headers</span>
+<a name="l00139"></a>00139 <span class="comment"> */</span>
+<a name="l00140"></a>00140 
+<a name="l00141"></a>00141 <span class="preprocessor">#include "sinfo_function_1d.h"</span>
+<a name="l00142"></a>00142 <span class="preprocessor">#include "sinfo_recipes.h"</span>
+<a name="l00143"></a>00143 <span class="preprocessor">#include "sinfo_wavecal.h"</span>
+<a name="l00144"></a>00144 <span class="preprocessor">#include "sinfo_wave_calibration.h"</span>
+<a name="l00145"></a>00145 <span class="preprocessor">#include "sinfo_solve_poly_root.h"</span>
+<a name="l00146"></a>00146 <span class="preprocessor">#include "sinfo_utils_wrappers.h"</span>
+<a name="l00147"></a>00147 <span class="preprocessor">#include "sinfo_error.h"</span>
+<a name="l00148"></a>00148 
+<a name="l00149"></a>00149 <span class="preprocessor">#include "sinfo_svd.h"</span>
+<a name="l00150"></a>00150 <span class="comment">/*</span>
+<a name="l00151"></a>00151 <span class="comment"> * Private functions prototype</span>
+<a name="l00152"></a>00152 <span class="comment"> */</span>
+<a name="l00153"></a>00153 <span class="keyword">static</span> Bcoeffs * 
+<a name="l00154"></a>00154 sinfo_new_b_coeffs( <span class="keywordtype">int</span> n_slitlets,
+<a name="l00155"></a>00155                       <span class="keywordtype">int</span> n_acoeffs,
+<a name="l00156"></a>00156                       <span class="keywordtype">int</span> n_bcoeffs ) ;
+<a name="l00157"></a>00157 
+<a name="l00158"></a>00158 <span class="keyword">static</span> <span class="keywordtype">void</span> 
+<a name="l00159"></a>00159 sinfo_new_destroy_b_coeffs ( Bcoeffs * bco ) ;
+<a name="l00160"></a>00160 
+<a name="l00161"></a>00161 <span class="keyword">static</span> <span class="keywordtype">int</span>   
+<a name="l00162"></a>00162 sinfo_new_coeffs_cross_slit_fit ( <span class="keywordtype">int</span>      n_columns,
+<a name="l00163"></a>00163                            <span class="keywordtype">float</span> ** acoefs,
+<a name="l00164"></a>00164                            <span class="keywordtype">float</span> ** dacoefs,
+<a name="l00165"></a>00165                            Bcoeffs* bco,
+<a name="l00166"></a>00166                            <span class="keywordtype">float</span>    sigma_factor,
+<a name="l00167"></a>00167                            <span class="keywordtype">float</span>    dispersion,
+<a name="l00168"></a>00168                            <span class="keywordtype">float</span>    pixel_dist,
+<a name="l00169"></a>00169                            <span class="keywordtype">float</span>  * chisq ) ;
+<a name="l00170"></a>00170 
+<a name="l00171"></a>00171 
+<a name="l00172"></a>00172 <span class="keyword">static</span> <span class="keywordtype">int</span>   
+<a name="l00173"></a>00173 sinfo_new_spred_coeffs_cross_slit_fit ( <span class="keywordtype">int</span>      n_columns,
+<a name="l00174"></a>00174                             <span class="keywordtype">float</span> ** acoefs,
+<a name="l00175"></a>00175                             <span class="keywordtype">float</span> ** dacoefs,
+<a name="l00176"></a>00176                             Bcoeffs* bco,
+<a name="l00177"></a>00177                             <span class="keywordtype">float</span>    sigma_factor,
+<a name="l00178"></a>00178                             <span class="keywordtype">float</span>    dispersion,
+<a name="l00179"></a>00179                             <span class="keywordtype">float</span>    pixel_dist,
+<a name="l00180"></a>00180                             <span class="keywordtype">float</span>  * chisq,
+<a name="l00181"></a>00181                           <span class="keywordtype">float</span> ** sinfo_slit_pos) ;
+<a name="l00182"></a>00182 <span class="comment">/*</span>
+<a name="l00183"></a>00183 <span class="comment"> * function definitions</span>
+<a name="l00184"></a>00184 <span class="comment"> */</span>
+<a name="l00200"></a>00200 <span class="keyword">static</span> Bcoeffs * 
+<a name="l00201"></a>00201 sinfo_new_b_coeffs( <span class="keywordtype">int</span> n_slitlets,
+<a name="l00202"></a>00202                       <span class="keywordtype">int</span> n_acoeffs,
+<a name="l00203"></a>00203                       <span class="keywordtype">int</span> n_bcoeffs )
+<a name="l00204"></a>00204 {
+<a name="l00205"></a>00205     <span class="keywordtype">int</span> i, n ;
+<a name="l00206"></a>00206     Bcoeffs * returnbco ;
+<a name="l00207"></a>00207 
+<a name="l00208"></a>00208     <span class="keywordflow">if</span>(NULL == (returnbco=(Bcoeffs*) cpl_calloc(n_slitlets, <span class="keyword">sizeof</span>(Bcoeffs))) )
+<a name="l00209"></a>00209     {
+<a name="l00210"></a>00210         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"could not allocate memory"</span>) ;
+<a name="l00211"></a>00211         <span class="keywordflow">return</span> NULL ;
+<a name="l00212"></a>00212     }
+<a name="l00213"></a>00213     returnbco -> n_slitlets = n_slitlets ;
+<a name="l00214"></a>00214     returnbco -> n_acoeffs  = n_acoeffs ;
+<a name="l00215"></a>00215     returnbco -> n_bcoeffs  = n_bcoeffs ;
+<a name="l00216"></a>00216     <span class="keywordflow">for</span> ( i = 0 ; i < n_slitlets ; i++ )
+<a name="l00217"></a>00217     {
+<a name="l00218"></a>00218         returnbco[i].slitlet = i ;
+<a name="l00219"></a>00219         <span class="keywordflow">if</span> ( NULL == (returnbco[i].b = (<span class="keywordtype">float</span>**)cpl_calloc(n_acoeffs, 
+<a name="l00220"></a>00220                                                 <span class="keyword">sizeof</span>(<span class="keywordtype">float</span>*)) ) ) 
+<a name="l00221"></a>00221         {
+<a name="l00222"></a>00222             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"could not allocate memory"</span>) ;
+<a name="l00223"></a>00223             <span class="keywordflow">return</span> NULL ;
+<a name="l00224"></a>00224         }
+<a name="l00225"></a>00225         <span class="keywordflow">for</span> ( n = 0 ; n < n_acoeffs ; n++ )
+<a name="l00226"></a>00226         {
+<a name="l00227"></a>00227             <span class="keywordflow">if</span> ( NULL == (returnbco[i].b[n] = (<span class="keywordtype">float</span>*)cpl_calloc(n_bcoeffs, 
+<a name="l00228"></a>00228                                                <span class="keyword">sizeof</span>(<span class="keywordtype">float</span>))) )
+<a name="l00229"></a>00229             {
+<a name="l00230"></a>00230                 <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"could not allocate memory"</span>) ;
+<a name="l00231"></a>00231                 <span class="keywordflow">return</span> NULL ;
+<a name="l00232"></a>00232             }
+<a name="l00233"></a>00233         }  
+<a name="l00234"></a>00234     }
+<a name="l00235"></a>00235     <span class="keywordflow">return</span> returnbco ;
+<a name="l00236"></a>00236 }
+<a name="l00237"></a>00237 
+<a name="l00245"></a>00245 <span class="keyword">static</span> <span class="keywordtype">void</span> 
+<a name="l00246"></a>00246 sinfo_new_destroy_b_coeffs ( Bcoeffs * bco )
+<a name="l00247"></a>00247 {
+<a name="l00248"></a>00248     <span class="keywordtype">int</span> i, n ;
+<a name="l00249"></a>00249   
+<a name="l00250"></a>00250     <span class="keywordflow">for</span> ( i = 0 ; i < bco->n_slitlets ; i++ )
+<a name="l00251"></a>00251     {
+<a name="l00252"></a>00252         <span class="keywordflow">for</span> ( n = 0 ; n < bco->n_acoeffs ; n++ )
+<a name="l00253"></a>00253         {
+<a name="l00254"></a>00254             cpl_free (bco[i].b[n]) ;
+<a name="l00255"></a>00255         }
+<a name="l00256"></a>00256         cpl_free(bco[i].b) ;
+<a name="l00257"></a>00257     }
+<a name="l00258"></a>00258     
+<a name="l00259"></a>00259     cpl_free (bco) ;  
+<a name="l00260"></a>00260 }
+<a name="l00261"></a>00261 
+<a name="l00287"></a>00287 <span class="keyword">static</span> <span class="keywordtype">int</span>   
+<a name="l00288"></a>00288 sinfo_new_coeffs_cross_slit_fit ( <span class="keywordtype">int</span>      n_columns,
+<a name="l00289"></a>00289                            <span class="keywordtype">float</span> ** acoefs,
+<a name="l00290"></a>00290                            <span class="keywordtype">float</span> ** dacoefs,
+<a name="l00291"></a>00291                            Bcoeffs* bco,
+<a name="l00292"></a>00292                            <span class="keywordtype">float</span>    sigma_factor,
+<a name="l00293"></a>00293                            <span class="keywordtype">float</span>    dispersion,
+<a name="l00294"></a>00294                            <span class="keywordtype">float</span>    pixel_dist,
+<a name="l00295"></a>00295                            <span class="keywordtype">float</span>  * chisq )
+<a name="l00296"></a>00296 {
+<a name="l00297"></a>00297     <span class="keywordtype">float</span> col_index;
+<a name="l00298"></a>00298     <span class="keywordtype">float</span> ** ucoefs, **vcoefs, **covar ;
+<a name="l00299"></a>00299     <span class="keywordtype">float</span> * acoefsclean ;
+<a name="l00300"></a>00300     <span class="keywordtype">double</span> sum, sumq, mean ;
+<a name="l00301"></a>00301     <span class="keywordtype">double</span> sigma ;
+<a name="l00302"></a>00302     <span class="keywordtype">double</span> cliphi, cliplo ;
+<a name="l00303"></a>00303     <span class="keywordtype">float</span> offset ;
+<a name="l00304"></a>00304     <span class="keywordtype">float</span> threshold ;
+<a name="l00305"></a>00305     <span class="keywordtype">float</span>* sub_col_index=NULL ;
+<a name="l00306"></a>00306     <span class="keywordtype">float</span>* sub_acoefs=NULL;
+<a name="l00307"></a>00307     <span class="keywordtype">float</span>* sub_dacoefs=NULL ;
+<a name="l00308"></a>00308     <span class="keywordtype">float</span>* wcoefs=NULL ;
+<a name="l00309"></a>00309     <span class="keywordtype">int</span>* edge=NULL ;
+<a name="l00310"></a>00310 
+<a name="l00311"></a>00311     <span class="keywordtype">int</span> ed1, ed2 ;
+<a name="l00312"></a>00312     <span class="keywordtype">int</span> i, n, num, ndata ;
+<a name="l00313"></a>00313     <span class="keywordtype">int</span> nc, ns ;
+<a name="l00314"></a>00314     <span class="keywordtype">int</span> loc_index ;
+<a name="l00315"></a>00315     <span class="keywordtype">int</span> last_i=PIXEL;
+<a name="l00316"></a>00316     
+<a name="l00317"></a>00317     <span class="keywordflow">if</span> ( n_columns < 1 )
+<a name="l00318"></a>00318     {
+<a name="l00319"></a>00319         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"wrong number of image columns given"</span>) ;
+<a name="l00320"></a>00320         <span class="keywordflow">return</span> -1 ;
+<a name="l00321"></a>00321     }
+<a name="l00322"></a>00322     <span class="keywordflow">if</span> ( acoefs == NULL || dacoefs == NULL )
+<a name="l00323"></a>00323     {
+<a name="l00324"></a>00324         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"acoeffs or errors of coefficients are not given"</span>) ;
+<a name="l00325"></a>00325         <span class="keywordflow">return</span> -1 ;
+<a name="l00326"></a>00326     }
+<a name="l00327"></a>00327     <span class="keywordflow">if</span> ( bco == NULL )
+<a name="l00328"></a>00328     {
+<a name="l00329"></a>00329         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"bcoeffs are not allocated"</span>) ;
+<a name="l00330"></a>00330         <span class="keywordflow">return</span> -1 ;
+<a name="l00331"></a>00331     }
+<a name="l00332"></a>00332     <span class="keywordflow">if</span> ( sigma_factor <= 0. )
+<a name="l00333"></a>00333     {
+<a name="l00334"></a>00334         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"impossible sigma_factor given!"</span>) ;
+<a name="l00335"></a>00335         <span class="keywordflow">return</span> -1 ;
+<a name="l00336"></a>00336     }
+<a name="l00337"></a>00337     <span class="keywordflow">if</span> ( dispersion == 0. )
+<a name="l00338"></a>00338     {
+<a name="l00339"></a>00339         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"impossible dispersion given!"</span>) ;
+<a name="l00340"></a>00340         <span class="keywordflow">return</span> -1 ;
+<a name="l00341"></a>00341     }
+<a name="l00342"></a>00342 
+<a name="l00343"></a>00343     <span class="comment">/*-------------------------------------------------------------------------</span>
+<a name="l00344"></a>00344 <span class="comment">     * search for the slitlet edges by comparing the a0 coefficients along </span>
+<a name="l00345"></a>00345 <span class="comment">       the columns if a bigger deviation occurrs it is assumed that there </span>
+<a name="l00346"></a>00346 <span class="comment">       is an edge.</span>
+<a name="l00347"></a>00347 <span class="comment">     */</span>
+<a name="l00348"></a>00348 
+<a name="l00349"></a>00349     edge=cpl_calloc(bco->n_slitlets,<span class="keyword">sizeof</span>(<span class="keywordtype">int</span>)) ;
+<a name="l00350"></a>00350     wcoefs=cpl_calloc(bco->n_bcoeffs,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l00351"></a>00351 
+<a name="l00352"></a>00352     n = 0 ;
+<a name="l00353"></a>00353     threshold = pixel_dist * fabs(dispersion) ;
+<a name="l00354"></a>00354     <span class="keywordflow">for</span> ( i = PIXEL ; i < n_columns - PIXEL ; )
+<a name="l00355"></a>00355     {
+<a name="l00356"></a>00356         <span class="keywordflow">if</span> ( !isnan(acoefs[0][i+1]) && 
+<a name="l00357"></a>00357                     acoefs[0][i+1] != 0. && 
+<a name="l00358"></a>00358                     acoefs[0][i] != 0.  &&
+<a name="l00359"></a>00359                     dacoefs[0][i+1] != 0.)
+<a name="l00360"></a>00360         {
+<a name="l00361"></a>00361             <span class="keywordflow">if</span> ( isnan(acoefs[0][i]) || acoefs[0][i] == 0. )
+<a name="l00362"></a>00362             {
+<a name="l00363"></a>00363                 <span class="keywordflow">if</span> (fabs(acoefs[0][i+1] - acoefs[0][i-1]) >= threshold )
+<a name="l00364"></a>00364                 {
+<a name="l00365"></a>00365            <span class="keywordflow">if</span>( (i-last_i) < 60 && (i > 80) ) {
+<a name="l00366"></a>00366              <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"skip1 i=%d diff=%d\n"</span>,i,i-last_i);
+<a name="l00367"></a>00367              <span class="keywordflow">goto</span> skip;
+<a name="l00368"></a>00368                    } <span class="keywordflow">else</span> {  
+<a name="l00369"></a>00369              <span class="comment">/*</span>
+<a name="l00370"></a>00370 <span class="comment">                 sinfo_msg("diff1=%f i=%d threshold-%f size=%d\n", </span>
+<a name="l00371"></a>00371 <span class="comment">                               fabs(acoefs[0][i+1] - acoefs[0][i-1]),i,</span>
+<a name="l00372"></a>00372 <span class="comment">                               threshold,i-last_i);</span>
+<a name="l00373"></a>00373 <span class="comment">             */</span>
+<a name="l00374"></a>00374                      edge[n] = i+1 ;
+<a name="l00375"></a>00375              <span class="comment">//sinfo_msg("1found edge: %d",edge[n]);</span>
+<a name="l00376"></a>00376                      n++ ;
+<a name="l00377"></a>00377                      last_i = i;
+<a name="l00378"></a>00378                      i += PIXEL ;
+<a name="l00379"></a>00379            }
+<a name="l00380"></a>00380                 }
+<a name="l00381"></a>00381             }
+<a name="l00382"></a>00382             <span class="keywordflow">else</span>
+<a name="l00383"></a>00383             {
+<a name="l00384"></a>00384                 <span class="keywordflow">if</span> ((fabs(acoefs[0][i+1] - acoefs[0][i]) >= threshold) || 
+<a name="l00385"></a>00385                     (i-last_i) > 63 )
+<a name="l00386"></a>00386                 {
+<a name="l00387"></a>00387            <span class="keywordflow">if</span>( (i-last_i) < 60 && ((i> 80) || (i<PIXEL+2))) {
+<a name="l00388"></a>00388              <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"skip2 i=%d diff=%d\n"</span>,i,i-last_i);
+<a name="l00389"></a>00389              <span class="keywordflow">goto</span> skip;
+<a name="l00390"></a>00390                    } <span class="keywordflow">else</span> {  
+<a name="l00391"></a>00391                       
+<a name="l00392"></a>00392              <span class="comment">/*</span>
+<a name="l00393"></a>00393 <span class="comment">                      sinfo_msg_warning("diff2=%f i=%d threshold-%f size=%d",</span>
+<a name="l00394"></a>00394 <span class="comment">                      fabs(acoefs[0][i+1] - acoefs[0][i]),</span>
+<a name="l00395"></a>00395 <span class="comment">                      i,threshold,i-last_i);                      </span>
+<a name="l00396"></a>00396 <span class="comment">                      */</span>
+<a name="l00397"></a>00397               
+<a name="l00398"></a>00398  
+<a name="l00399"></a>00399                   
+<a name="l00400"></a>00400                       edge[n] = i+1 ;
+<a name="l00401"></a>00401                 <span class="comment">//sinfo_msg("2found edge: %d",edge[n]);</span>
+<a name="l00402"></a>00402                       n++ ;
+<a name="l00403"></a>00403                       last_i = i;
+<a name="l00404"></a>00404                       i += PIXEL ;
+<a name="l00405"></a>00405            }
+<a name="l00406"></a>00406                 }
+<a name="l00407"></a>00407             }
+<a name="l00408"></a>00408         <span class="comment">/* sometimes a slitlet may be lost due to divergences in acoeffs[0]</span>
+<a name="l00409"></a>00409 <span class="comment">               we try to recover it */</span>
+<a name="l00410"></a>00410             <span class="keywordflow">if</span>( ( (i-last_i) > 63 ) && 
+<a name="l00411"></a>00411                 ( isnan(fabs(acoefs[0][i+1] - acoefs[0][i])) ||
+<a name="l00412"></a>00412                   isnan(fabs(acoefs[0][i+1] - acoefs[0][i-1])) ) ) 
+<a name="l00413"></a>00413           {
+<a name="l00414"></a>00414         edge[n] = i+1 ;
+<a name="l00415"></a>00415         <span class="comment">//sinfo_msg("3found edge: %d",edge[n]);</span>
+<a name="l00416"></a>00416         n++ ;
+<a name="l00417"></a>00417         last_i = i;
+<a name="l00418"></a>00418                 <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"recovered slitlet edge i=%d"</span>,i);
+<a name="l00419"></a>00419         i += PIXEL ;
+<a name="l00420"></a>00420 
+<a name="l00421"></a>00421           }
+<a name="l00422"></a>00422     }
+<a name="l00423"></a>00423       skip:
+<a name="l00424"></a>00424         i++ ;
+<a name="l00425"></a>00425     }
+<a name="l00426"></a>00426     <span class="comment">/*</span>
+<a name="l00427"></a>00427 <span class="comment">    printf("X min %d max %d last %d\n", PIXEL, n_columns - PIXEL, i);</span>
+<a name="l00428"></a>00428 <span class="comment">    printf("n=%d check=%d\n",n,bco->n_slitlets - 1);</span>
+<a name="l00429"></a>00429 <span class="comment">    */</span>
+<a name="l00430"></a>00430     <span class="keywordflow">if</span> ( n != bco->n_slitlets - 1 )
+<a name="l00431"></a>00431     {
+<a name="l00432"></a>00432         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"could not find the right number "</span>
+<a name="l00433"></a>00433                         <span class="stringliteral">"of slitlets, found: %d"</span>,n+1) ;
+<a name="l00434"></a>00434         <span class="keywordflow">return</span> -1 ;
+<a name="l00435"></a>00435     }
+<a name="l00436"></a>00436  
+<a name="l00437"></a>00437     sub_col_index=cpl_calloc(n_columns,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l00438"></a>00438     sub_acoefs=cpl_calloc(n_columns,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>));
+<a name="l00439"></a>00439     sub_dacoefs=cpl_calloc(n_columns,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l00440"></a>00440 
+<a name="l00441"></a>00441     <span class="comment">/* go through the coefficents indices */</span>
+<a name="l00442"></a>00442     <span class="keywordflow">for</span> ( loc_index = 0 ; loc_index < bco->n_acoeffs ; loc_index++ )
+<a name="l00443"></a>00443     {
+<a name="l00444"></a>00444         <span class="comment">/* go through the single slitlets */</span>
+<a name="l00445"></a>00445         <span class="keywordflow">for</span> ( ns = 0 ; ns < bco->n_slitlets ; ns++ )
+<a name="l00446"></a>00446         {
+<a name="l00447"></a>00447             <span class="comment">/* determine the slitlet edges */</span>
+<a name="l00448"></a>00448             <span class="keywordflow">if</span> ( ns == 0 )
+<a name="l00449"></a>00449             {
+<a name="l00450"></a>00450                 ed1 = 0 ;
+<a name="l00451"></a>00451                 ed2 = edge[0] ;
+<a name="l00452"></a>00452             }
+<a name="l00453"></a>00453             <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( ns == bco->n_slitlets - 1 )
+<a name="l00454"></a>00454             {
+<a name="l00455"></a>00455                 ed1 = edge[bco->n_slitlets - 2] ;
+<a name="l00456"></a>00456                 ed2 = n_columns ;
+<a name="l00457"></a>00457             }
+<a name="l00458"></a>00458             <span class="keywordflow">else</span>
+<a name="l00459"></a>00459             {
+<a name="l00460"></a>00460                 ed1 = edge[ns-1] ;
+<a name="l00461"></a>00461                 ed2 = edge[ns] ;
+<a name="l00462"></a>00462             }
+<a name="l00463"></a>00463 
+<a name="l00464"></a>00464             nc = 0 ;
+<a name="l00465"></a>00465             <span class="keywordflow">for</span> ( i = ed1 ; i < ed2 ; i++ )
+<a name="l00466"></a>00466             {
+<a name="l00467"></a>00467                 <span class="keywordflow">if</span> ( isnan(acoefs[loc_index][i]) || 
+<a name="l00468"></a>00468                            acoefs[loc_index][i] == 0. || 
+<a name="l00469"></a>00469                           dacoefs[loc_index][i] == 0. )
+<a name="l00470"></a>00470                 {
+<a name="l00471"></a>00471                     continue ;
+<a name="l00472"></a>00472                 }
+<a name="l00473"></a>00473                 <span class="keywordflow">else</span>
+<a name="l00474"></a>00474                 {
+<a name="l00475"></a>00475                     nc++ ;
+<a name="l00476"></a>00476                 }
+<a name="l00477"></a>00477             }
+<a name="l00478"></a>00478             <span class="keywordflow">if</span> (NULL==(acoefsclean = (<span class="keywordtype">float</span>*) cpl_calloc(nc , <span class="keyword">sizeof</span>(<span class="keywordtype">float</span>))) )
+<a name="l00479"></a>00479             {
+<a name="l00480"></a>00480                 <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"could not allocate memory for acoefsclean!"</span>) ;
+<a name="l00481"></a>00481                 <span class="keywordflow">return</span> -1 ;
+<a name="l00482"></a>00482             }
+<a name="l00483"></a>00483             nc = 0 ;
+<a name="l00484"></a>00484             <span class="keywordflow">for</span> ( i = ed1 ; i < ed2 ; i++ )
+<a name="l00485"></a>00485             {
+<a name="l00486"></a>00486                 <span class="keywordflow">if</span> ( isnan(acoefs[loc_index][i]) || 
+<a name="l00487"></a>00487                       acoefs[loc_index][i] == 0. || 
+<a name="l00488"></a>00488                      dacoefs[loc_index][i] == 0. )
+<a name="l00489"></a>00489                 {
+<a name="l00490"></a>00490                     continue ;
+<a name="l00491"></a>00491                 }
+<a name="l00492"></a>00492                 <span class="keywordflow">else</span>
+<a name="l00493"></a>00493                 {
+<a name="l00494"></a>00494                     acoefsclean[nc] = acoefs[loc_index][i] ;
+<a name="l00495"></a>00495                     nc++ ;
+<a name="l00496"></a>00496                 }
+<a name="l00497"></a>00497             }
+<a name="l00498"></a>00498 
+<a name="l00499"></a>00499             <span class="comment">/* ----------------------------------------------------------</span>
+<a name="l00500"></a>00500 <span class="comment">             * determine the clean mean and sigma value of the coefficients,</span>
+<a name="l00501"></a>00501 <span class="comment">             * that means reject 10 % of the extreme low and high values</span>
+<a name="l00502"></a>00502 <span class="comment">             */</span>
+<a name="l00503"></a>00503             sinfo_pixel_qsort(acoefsclean, nc) ;
+<a name="l00504"></a>00504 
+<a name="l00505"></a>00505             sum   = 0. ;
+<a name="l00506"></a>00506             sumq  = 0. ;
+<a name="l00507"></a>00507             mean  = 0. ;
+<a name="l00508"></a>00508             sigma = 0. ;
+<a name="l00509"></a>00509             n     = 0 ;
+<a name="l00510"></a>00510             <span class="keywordflow">for</span> ( i = (<span class="keywordtype">int</span>)((<span class="keywordtype">float</span>)nc*LOW_REJECT) ; 
+<a name="l00511"></a>00511                   i < (int)((<span class="keywordtype">float</span>)nc*HIGH_REJECT) ; i++ )
+<a name="l00512"></a>00512             {
+<a name="l00513"></a>00513                 sum  += (double)acoefsclean[i] ;
+<a name="l00514"></a>00514                 sumq += ((double)acoefsclean[i] * (<span class="keywordtype">double</span>)acoefsclean[i]) ;
+<a name="l00515"></a>00515                 n ++ ;
+<a name="l00516"></a>00516             }
+<a name="l00517"></a>00517             mean          = sum/(double)n ;
+<a name="l00518"></a>00518             sigma         = sqrt( sumq/(<span class="keywordtype">double</span>)n - (mean * mean) ) ;
+<a name="l00519"></a>00519             cliphi        = mean + sigma * (double)sigma_factor ;
+<a name="l00520"></a>00520             cliplo        = mean - sigma * (double)sigma_factor ;
+<a name="l00521"></a>00521             <span class="comment">/* fit only the reasonnable values */</span>
+<a name="l00522"></a>00522             num = 0 ;
+<a name="l00523"></a>00523             col_index = 0 ;
+<a name="l00524"></a>00524             <span class="comment">/*</span>
+<a name="l00525"></a>00525 <span class="comment">            printf("ed1=%d ed2=%d\n",ed1,ed2);</span>
+<a name="l00526"></a>00526 <span class="comment">        */</span>
+<a name="l00527"></a>00527             <span class="keywordflow">for</span> ( i = ed1 ; i < ed2 ; i++ )
+<a name="l00528"></a>00528             {
+<a name="l00529"></a>00529                 <span class="comment">/* take only the reasonnable coefficients */</span>
+<a name="l00530"></a>00530                  <span class="comment">/*</span>
+<a name="l00531"></a>00531 <span class="comment">        printf("acoeffs=%f dacoefs=%f cliphi=%f cliplo=%f\n",</span>
+<a name="l00532"></a>00532 <span class="comment">                   acoefs[loc_index][i],dacoefs[loc_index][i],cliphi,cliplo);</span>
+<a name="l00533"></a>00533 <span class="comment">         */</span>
+<a name="l00534"></a>00534                 <span class="keywordflow">if</span> ( !isnan(acoefs[loc_index][i])     && 
+<a name="l00535"></a>00535                      (acoefs[loc_index][i] <= cliphi) && 
+<a name="l00536"></a>00536                      (acoefs[loc_index][i] >= cliplo) &&
+<a name="l00537"></a>00537                      (dacoefs[loc_index][i] != 0. )   && 
+<a name="l00538"></a>00538                      (acoefs[loc_index][i] != 0.)     )
+<a name="l00539"></a>00539                 {
+<a name="l00540"></a>00540                     sub_acoefs[num]    = acoefs[loc_index][i] ;
+<a name="l00541"></a>00541                     sub_dacoefs[num]   = dacoefs[loc_index][i] ;
+<a name="l00542"></a>00542                     sub_col_index[num] = col_index ;
+<a name="l00543"></a>00543                     num ++ ;
+<a name="l00544"></a>00544                 }
+<a name="l00545"></a>00545                 col_index++ ;
+<a name="l00546"></a>00546             }
+<a name="l00547"></a>00547             ndata = num ;
+<a name="l00548"></a>00548             offset = (float)(col_index-1) / 2. ;
+<a name="l00549"></a>00549             <span class="comment">/* printf("ndata=%d bco->n_bcoeffs=%d\n",ndata,bco->n_bcoeffs); */</span>
+<a name="l00550"></a>00550 
+<a name="l00551"></a>00551             <span class="keywordflow">if</span> ( ndata < bco->n_bcoeffs )
+<a name="l00552"></a>00552             {
+<a name="l00553"></a>00553                 <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"not enough data found in slitlet %d to "</span>
+<a name="l00554"></a>00554                                 <span class="stringliteral">"determine the fit coefficients."</span>, ns) ;
+<a name="l00555"></a>00555                 cpl_free(acoefsclean) ;
+<a name="l00556"></a>00556                 <span class="keywordflow">return</span> -1 ;
+<a name="l00557"></a>00557             }
+<a name="l00558"></a>00558 
+<a name="l00559"></a>00559             <span class="comment">/* allocate coefficient matrices */</span>
+<a name="l00560"></a>00560             ucoefs = sinfo_matrix(1, ndata, 1, bco->n_bcoeffs) ;
+<a name="l00561"></a>00561             vcoefs = sinfo_matrix(1, ndata, 1, bco->n_bcoeffs) ;
+<a name="l00562"></a>00562             covar  = sinfo_matrix(1, bco->n_bcoeffs, 1, bco->n_bcoeffs) ;
+<a name="l00563"></a>00563 
+<a name="l00564"></a>00564             <span class="comment">/* scale the x-values for the fit */</span>
+<a name="l00565"></a>00565             <span class="keywordflow">for</span> ( i = 0 ; i < ndata ; i++ )
+<a name="l00566"></a>00566             {
+<a name="l00567"></a>00567                 sub_col_index[i] = (sub_col_index[i] - offset) / offset ;
+<a name="l00568"></a>00568             }
+<a name="l00569"></a>00569 
+<a name="l00570"></a>00570             <span class="comment">/* finally, do the singular value decomposition fit */</span>
+<a name="l00571"></a>00571             sinfo_svd_fitting ( sub_col_index-1, sub_acoefs-1, 
+<a name="l00572"></a>00572                                 sub_dacoefs-1, ndata, bco[ns].b[loc_index]-1,
+<a name="l00573"></a>00573                                 bco->n_bcoeffs, ucoefs, vcoefs, 
+<a name="l00574"></a>00574                                 wcoefs-1, covar, &chisq[ns], sinfo_fpol ) ;
+<a name="l00575"></a>00575 
+<a name="l00576"></a>00576             <span class="comment">/* scale the found coefficients */</span>
+<a name="l00577"></a>00577             <span class="keywordflow">for</span> ( i = 0 ; i < bco->n_bcoeffs ; i ++ )
+<a name="l00578"></a>00578             {
+<a name="l00579"></a>00579                 bco[ns].b[loc_index][i] /= pow( offset, i ) ;
+<a name="l00580"></a>00580             }
+<a name="l00581"></a>00581 
+<a name="l00582"></a>00582             <span class="comment">/* free memory */</span>
+<a name="l00583"></a>00583             cpl_free (acoefsclean) ;
+<a name="l00584"></a>00584             sinfo_free_matrix( ucoefs, 1<span class="comment">/*, ndata*/</span>, 1<span class="comment">/*, bco->n_bcoeffs */</span>) ;
+<a name="l00585"></a>00585             sinfo_free_matrix( vcoefs, 1<span class="comment">/*, ndata*/</span>, 1<span class="comment">/*, bco->n_bcoeffs */</span>) ;
+<a name="l00586"></a>00586             sinfo_free_matrix( covar, 1<span class="comment">/*, bco->n_bcoeffs*/</span>, 
+<a name="l00587"></a>00587                                 1<span class="comment">/*, bco->n_bcoeffs */</span>) ;
+<a name="l00588"></a>00588 
+<a name="l00589"></a>00589             <span class="comment">/* now calculate the smoothed acoefs for each column */</span>
+<a name="l00590"></a>00590             col_index = 0 ;
+<a name="l00591"></a>00591             <span class="keywordflow">for</span> ( i = ed1 ; i < ed2  ; i++ )
+<a name="l00592"></a>00592             {
+<a name="l00593"></a>00593                 acoefs[loc_index][i] = 0. ;
+<a name="l00594"></a>00594                 <span class="keywordflow">for</span> ( n = 0 ; n < bco->n_bcoeffs ; n++ )
+<a name="l00595"></a>00595                 {
+<a name="l00596"></a>00596                     acoefs[loc_index][i] += bco[ns].b[loc_index][n] * 
+<a name="l00597"></a>00597                                         pow(col_index - offset, n) ;
+<a name="l00598"></a>00598                 }
+<a name="l00599"></a>00599                 col_index++ ;
+<a name="l00600"></a>00600             }
+<a name="l00601"></a>00601 
+<a name="l00602"></a>00602         }
+<a name="l00603"></a>00603     }
+<a name="l00604"></a>00604 
+<a name="l00605"></a>00605     cpl_free(sub_col_index) ;
+<a name="l00606"></a>00606     cpl_free(sub_acoefs) ;
+<a name="l00607"></a>00607     cpl_free(sub_dacoefs) ;
+<a name="l00608"></a>00608 
+<a name="l00609"></a>00609 
+<a name="l00610"></a>00610     cpl_free(edge) ;
+<a name="l00611"></a>00611     cpl_free(wcoefs) ;
+<a name="l00612"></a>00612 
+<a name="l00613"></a>00613     <span class="keywordflow">return</span> 0 ;
+<a name="l00614"></a>00614 }
+<a name="l00615"></a>00615 
+<a name="l00616"></a>00616 
+<a name="l00629"></a>00629 cpl_image * sinfo_new_wave_map_slit ( <span class="keywordtype">float</span> ** acoefs,
+<a name="l00630"></a>00630                          <span class="keywordtype">int</span>      n_acoefs,
+<a name="l00631"></a>00631                          <span class="keywordtype">int</span>      n_rows,
+<a name="l00632"></a>00632                          <span class="keywordtype">int</span>      n_columns )
+<a name="l00633"></a>00633 {
+<a name="l00634"></a>00634     cpl_image * newIm=NULL ;
+<a name="l00635"></a>00635     <span class="keywordtype">float</span> lambda=0 ;
+<a name="l00636"></a>00636     <span class="keywordtype">float</span> offset=0 ;
+<a name="l00637"></a>00637     <span class="keywordtype">int</span> col=0;
+<a name="l00638"></a>00638     <span class="keywordtype">int</span> row=0 ;
+<a name="l00639"></a>00639     <span class="keywordtype">int</span> i=0 ;
+<a name="l00640"></a>00640     <span class="keywordtype">float</span> row_index=0 ;
+<a name="l00641"></a>00641     <span class="keywordtype">float</span>* podata=NULL;
+<a name="l00642"></a>00642     <span class="keywordflow">if</span> ( NULL == acoefs )
+<a name="l00643"></a>00643     {
+<a name="l00644"></a>00644         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" no coefficient sinfo_matrix given!"</span>) ;
+<a name="l00645"></a>00645         <span class="keywordflow">return</span> NULL ;
+<a name="l00646"></a>00646     }
+<a name="l00647"></a>00647 
+<a name="l00648"></a>00648     <span class="comment">/* allocate new image */</span>
+<a name="l00649"></a>00649     <span class="keywordflow">if</span> ( NULL == (newIm = cpl_image_new(n_columns , n_rows,CPL_TYPE_FLOAT)) )
+<a name="l00650"></a>00650     {
+<a name="l00651"></a>00651         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"could not allocate new image!"</span>) ;
+<a name="l00652"></a>00652         <span class="keywordflow">return</span> NULL ;
+<a name="l00653"></a>00653     }
+<a name="l00654"></a>00654     podata=cpl_image_get_data_float(newIm);
+<a name="l00655"></a>00655 
+<a name="l00656"></a>00656     <span class="comment">/* make the parabola symmetric to the image */</span>
+<a name="l00657"></a>00657     offset = (float)(n_rows - 1) / 2. ; 
+<a name="l00658"></a>00658 
+<a name="l00659"></a>00659     <span class="comment">/* go through the rows */</span>
+<a name="l00660"></a>00660     <span class="keywordflow">for</span> ( col = 0 ; col < n_columns ; col++ )
+<a name="l00661"></a>00661     {
+<a name="l00662"></a>00662         <span class="comment">/* go through the columns */</span>
+<a name="l00663"></a>00663         <span class="keywordflow">for</span> ( row = 0 ; row < n_rows ; row++ )
+<a name="l00664"></a>00664         {
+<a name="l00665"></a>00665             lambda = 0. ;
+<a name="l00666"></a>00666             row_index = (float)row - offset ;
+<a name="l00667"></a>00667             <span class="keywordflow">for</span> ( i = 0 ; i < n_acoefs ; i++ )
+<a name="l00668"></a>00668             {
+<a name="l00669"></a>00669                 lambda += acoefs[i][col] * pow(row_index, i) ;
+<a name="l00670"></a>00670             }
+<a name="l00671"></a>00671             podata[col+row*n_columns] = lambda ;
+<a name="l00672"></a>00672         }
+<a name="l00673"></a>00673     }
+<a name="l00674"></a>00674     <span class="keywordflow">return</span> newIm ;
+<a name="l00675"></a>00675 }
+<a name="l00676"></a>00676 
+<a name="l00677"></a>00677 
+<a name="l00724"></a>00724 cpl_image * sinfo_new_wave_cal( cpl_image   * image,
+<a name="l00725"></a>00725                     FitParams ** par ,
+<a name="l00726"></a>00726                     <span class="keywordtype">float</span>     ** abuf,
+<a name="l00727"></a>00727                     <span class="keywordtype">int</span>          n_slitlets,
+<a name="l00728"></a>00728                     <span class="keywordtype">int</span>       ** row_clean,
+<a name="l00729"></a>00729                     <span class="keywordtype">float</span>     ** wavelength_clean,
+<a name="l00730"></a>00730                     <span class="keywordtype">int</span>        * n_found_lines,
+<a name="l00731"></a>00731                     <span class="keywordtype">float</span>        dispersion,
+<a name="l00732"></a>00732                     <span class="keywordtype">int</span>          halfWidth,
+<a name="l00733"></a>00733                     <span class="keywordtype">float</span>        minAmplitude,
+<a name="l00734"></a>00734                     <span class="keywordtype">float</span>        max_residual,
+<a name="l00735"></a>00735                     <span class="keywordtype">float</span>        fwhm,
+<a name="l00736"></a>00736                     <span class="keywordtype">int</span>          n_a_fitcoefs,
+<a name="l00737"></a>00737                     <span class="keywordtype">int</span>          n_b_fitcoefs,
+<a name="l00738"></a>00738                     <span class="keywordtype">float</span>        sigmaFactor,
+<a name="l00739"></a>00739                     <span class="keywordtype">float</span>        pixel_dist,
+<a name="l00740"></a>00740                     <span class="keywordtype">float</span>        pixel_tolerance )
+<a name="l00741"></a>00741 
+<a name="l00742"></a>00742 {
+<a name="l00743"></a>00743     <span class="keywordtype">int</span>          i=0, j=0, k=0 ;
+<a name="l00744"></a>00744     <span class="keywordtype">int</span>          n_fit=0 ;
+<a name="l00745"></a>00745     <span class="keywordtype">int</span>          n_reject=0 ;
+<a name="l00746"></a>00746     <span class="keywordtype">float</span>     *  acoefs=NULL ;
+<a name="l00747"></a>00747     <span class="keywordtype">float</span>     *  dacoefs=NULL ;
+<a name="l00748"></a>00748     <span class="keywordtype">float</span>     ** dabuf=NULL ;
+<a name="l00749"></a>00749     <span class="keywordtype">float</span>        chisq_poly=0 ;
+<a name="l00750"></a>00750     <span class="keywordtype">float</span>     *  chisq_cross=NULL ;
+<a name="l00751"></a>00751     <span class="keywordtype">int</span>          zeroind=0 ;
+<a name="l00752"></a>00752     <span class="keywordtype">int</span>          crossInd=0 ;
+<a name="l00753"></a>00753     Bcoeffs   *  bco=NULL ;
+<a name="l00754"></a>00754     cpl_image  *  wavemap=NULL ;
+<a name="l00755"></a>00755     <span class="keywordtype">int</span> ilx=0;
+<a name="l00756"></a>00756     <span class="keywordtype">int</span> ily=0;
+<a name="l00757"></a>00757     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l00758"></a>00758 
+<a name="l00759"></a>00759 
+<a name="l00760"></a>00760     <span class="keywordflow">if</span> (  NULL == image )
+<a name="l00761"></a>00761     {
+<a name="l00762"></a>00762         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no image given"</span>) ;
+<a name="l00763"></a>00763         <span class="keywordflow">return</span> NULL ;
+<a name="l00764"></a>00764     }
+<a name="l00765"></a>00765     check_nomsg(ilx=cpl_image_get_size_x(image));
+<a name="l00766"></a>00766     check_nomsg(ily=cpl_image_get_size_y(image));
+<a name="l00767"></a>00767     check_nomsg(pidata=cpl_image_get_data_float(image));
+<a name="l00768"></a>00768 
+<a name="l00769"></a>00769     <span class="keywordflow">if</span> ( par == NULL )
+<a name="l00770"></a>00770     {
+<a name="l00771"></a>00771         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no fit parameter data structure given"</span>) ;
+<a name="l00772"></a>00772         <span class="keywordflow">return</span> NULL ;
+<a name="l00773"></a>00773     }
+<a name="l00774"></a>00774     <span class="keywordflow">if</span> ( abuf == NULL )
+<a name="l00775"></a>00775     {
+<a name="l00776"></a>00776         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no buffer for fit coefficients given"</span>) ;
+<a name="l00777"></a>00777         <span class="keywordflow">return</span> NULL ;
+<a name="l00778"></a>00778     }
+<a name="l00779"></a>00779     <span class="keywordflow">if</span> ( n_slitlets <= 0 )
+<a name="l00780"></a>00780     {
+<a name="l00781"></a>00781         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"impossible number of slitlets given"</span>) ;
+<a name="l00782"></a>00782         <span class="keywordflow">return</span> NULL ;
+<a name="l00783"></a>00783     }
+<a name="l00784"></a>00784     <span class="keywordflow">if</span> ( row_clean == NULL )
+<a name="l00785"></a>00785     {
+<a name="l00786"></a>00786         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no row_clean array given"</span>) ;
+<a name="l00787"></a>00787         <span class="keywordflow">return</span> NULL ;
+<a name="l00788"></a>00788     }
+<a name="l00789"></a>00789     <span class="keywordflow">if</span> ( wavelength_clean == NULL )
+<a name="l00790"></a>00790     {
+<a name="l00791"></a>00791         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no wavelength_clean array given"</span>) ;
+<a name="l00792"></a>00792         <span class="keywordflow">return</span> NULL ;
+<a name="l00793"></a>00793     }
+<a name="l00794"></a>00794 
+<a name="l00795"></a>00795     <span class="keywordflow">if</span> ( dispersion == 0. )
+<a name="l00796"></a>00796     {
+<a name="l00797"></a>00797         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"impossible dispersion given"</span>) ;
+<a name="l00798"></a>00798         <span class="keywordflow">return</span> NULL ;
+<a name="l00799"></a>00799     }
+<a name="l00800"></a>00800 
+<a name="l00801"></a>00801     <span class="keywordflow">if</span> ( halfWidth <= 0 || halfWidth > ily/2 )
+<a name="l00802"></a>00802     {
+<a name="l00803"></a>00803         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"impossible half width of the fitting box given"</span>) ;
+<a name="l00804"></a>00804         <span class="keywordflow">return</span> NULL ;
+<a name="l00805"></a>00805     }
+<a name="l00806"></a>00806     <span class="keywordflow">if</span> ( minAmplitude < 1. )
+<a name="l00807"></a>00807     {
+<a name="l00808"></a>00808         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"impossible minimal amplitude"</span>) ;
+<a name="l00809"></a>00809         <span class="keywordflow">return</span> NULL ;
+<a name="l00810"></a>00810     }
+<a name="l00811"></a>00811 
+<a name="l00812"></a>00812     <span class="keywordflow">if</span> ( max_residual <= 0. || max_residual > 1. )
+<a name="l00813"></a>00813     {
+<a name="l00814"></a>00814         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"impossible max_residual given"</span>) ;
+<a name="l00815"></a>00815         <span class="keywordflow">return</span> NULL ;
+<a name="l00816"></a>00816     }
+<a name="l00817"></a>00817     <span class="keywordflow">if</span> ( fwhm <= 0. || fwhm > 10. )
+<a name="l00818"></a>00818     {
+<a name="l00819"></a>00819         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"impossible fwhm given"</span>) ;
+<a name="l00820"></a>00820         <span class="keywordflow">return</span> NULL ;
+<a name="l00821"></a>00821     }
+<a name="l00822"></a>00822 
+<a name="l00823"></a>00823     <span class="keywordflow">if</span> ( n_a_fitcoefs <= 0 || n_a_fitcoefs > 9 )
+<a name="l00824"></a>00824     {
+<a name="l00825"></a>00825         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"unrealistic n_a_fitcoefs given"</span>) ;
+<a name="l00826"></a>00826         <span class="keywordflow">return</span> NULL ;
+<a name="l00827"></a>00827     }
+<a name="l00828"></a>00828 
+<a name="l00829"></a>00829     <span class="keywordflow">if</span> ( n_b_fitcoefs <= 0 || n_b_fitcoefs > 9 )
+<a name="l00830"></a>00830     {
+<a name="l00831"></a>00831         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"unrealistic n_b_fitcoefs given"</span>) ;
+<a name="l00832"></a>00832         <span class="keywordflow">return</span> NULL ;
+<a name="l00833"></a>00833     }
+<a name="l00834"></a>00834     <span class="keywordflow">if</span> ( sigmaFactor <= 0. )
+<a name="l00835"></a>00835     {
+<a name="l00836"></a>00836         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"impossible sigmaFactor given"</span>) ;
+<a name="l00837"></a>00837         <span class="keywordflow">return</span> NULL ;
+<a name="l00838"></a>00838     }
+<a name="l00839"></a>00839 
+<a name="l00840"></a>00840     <span class="comment">/* initialize the variables */</span>
+<a name="l00841"></a>00841     n_reject = 0 ;
+<a name="l00842"></a>00842     n_fit = 0 ;
+<a name="l00843"></a>00843 
+<a name="l00844"></a>00844 
+<a name="l00845"></a>00845     <span class="comment">/* fit each found line by using a Gaussian function and determine </span>
+<a name="l00846"></a>00846 <span class="comment">       the exact position */</span>
+<a name="l00847"></a>00847     <span class="keywordflow">if</span> ( 0 > (n_fit = sinfo_new_fit_lines( image , par, fwhm, n_found_lines, 
+<a name="l00848"></a>00848                                      row_clean, wavelength_clean,
+<a name="l00849"></a>00849                                      halfWidth, minAmplitude )) )
+<a name="l00850"></a>00850     {
+<a name="l00851"></a>00851         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"cannot fit the lines, error code of "</span>
+<a name="l00852"></a>00852                         <span class="stringliteral">"sinfo_fitLines: %d"</span>, n_fit) ;
+<a name="l00853"></a>00853         <span class="keywordflow">return</span> NULL ;
+<a name="l00854"></a>00854     }
+<a name="l00855"></a>00855 
+<a name="l00856"></a>00856     <span class="comment">/* first check for faked lines like bad pixels */</span>
+<a name="l00857"></a>00857     <span class="keywordflow">if</span> ( -1 == sinfo_new_check_for_fake_lines (par, dispersion, 
+<a name="l00858"></a>00858                                                wavelength_clean, 
+<a name="l00859"></a>00859                                          row_clean, n_found_lines,
+<a name="l00860"></a>00860                                          ilx, pixel_tolerance) )
+<a name="l00861"></a>00861     {
+<a name="l00862"></a>00862         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"cannot fit the lines, error code of "</span>
+<a name="l00863"></a>00863                         <span class="stringliteral">"sinfo_fitLines: %d"</span>, n_fit) ;
+<a name="l00864"></a>00864         <span class="keywordflow">return</span> NULL ;
+<a name="l00865"></a>00865     }
+<a name="l00866"></a>00866 
+<a name="l00867"></a>00867     <span class="comment">/* allocate memory */</span>
+<a name="l00868"></a>00868     <span class="keywordflow">if</span> (NULL == (acoefs = (<span class="keywordtype">float</span>*) cpl_calloc(n_a_fitcoefs, <span class="keyword">sizeof</span>(<span class="keywordtype">float</span>))) ||
+<a name="l00869"></a>00869         NULL == (dacoefs = (<span class="keywordtype">float</span>*) cpl_calloc(n_a_fitcoefs, <span class="keyword">sizeof</span>(<span class="keywordtype">float</span>))) ||
+<a name="l00870"></a>00870         NULL == (dabuf = (<span class="keywordtype">float</span>**) cpl_calloc(n_a_fitcoefs, <span class="keyword">sizeof</span>(<span class="keywordtype">float</span>*))) ||
+<a name="l00871"></a>00871         NULL == (chisq_cross = (<span class="keywordtype">float</span>*) cpl_calloc(n_slitlets, <span class="keyword">sizeof</span>(<span class="keywordtype">float</span>))))
+<a name="l00872"></a>00872     {
+<a name="l00873"></a>00873         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"cannot allocate memory\n"</span>) ;
+<a name="l00874"></a>00874         <span class="keywordflow">return</span> NULL ;
+<a name="l00875"></a>00875     }
+<a name="l00876"></a>00876     <span class="keywordflow">for</span> ( i = 0 ; i < n_a_fitcoefs ; i++ )
+<a name="l00877"></a>00877     {
+<a name="l00878"></a>00878         <span class="keywordflow">if</span> (  NULL == (dabuf[i] = (<span class="keywordtype">float</span>*) cpl_calloc(ilx, <span class="keyword">sizeof</span>(<span class="keywordtype">float</span>))) )
+<a name="l00879"></a>00879         {
+<a name="l00880"></a>00880             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"cannot allocate memory"</span>) ;
+<a name="l00881"></a>00881             sinfo_free_float (&acoefs ) ;
+<a name="l00882"></a>00882             sinfo_free_float ( &dacoefs ) ;
+<a name="l00883"></a>00883             sinfo_free_float ( &chisq_cross ) ;
+<a name="l00884"></a>00884             sinfo_free_float_array(&dabuf,n_a_fitcoefs) ;
+<a name="l00885"></a>00885             <span class="keywordflow">return</span> NULL ;
+<a name="l00886"></a>00886         }
+<a name="l00887"></a>00887     }
+<a name="l00888"></a>00888 
+<a name="l00889"></a>00889 
+<a name="l00890"></a>00890     <span class="comment">/* fit wavelengths to the corresponding found positions for each column */</span>
+<a name="l00891"></a>00891     k = 0 ;
+<a name="l00892"></a>00892     <span class="keywordflow">for</span> ( i = 0 ; i < ilx ; i++ )
+<a name="l00893"></a>00893     {
+<a name="l00894"></a>00894         zeroind = 0 ;
+<a name="l00895"></a>00895         <span class="keywordflow">if</span> ( FLT_MAX == (chisq_poly = sinfo_new_polyfit( par, i, 
+<a name="l00896"></a>00896                                                          n_found_lines[i], 
+<a name="l00897"></a>00897                                                    ily, dispersion,
+<a name="l00898"></a>00898                                                    max_residual, acoefs, 
+<a name="l00899"></a>00899                                                    dacoefs, &n_reject, 
+<a name="l00900"></a>00900                                                    n_a_fitcoefs)) )
+<a name="l00901"></a>00901         {
+<a name="l00902"></a>00902       <span class="comment">/*</span>
+<a name="l00903"></a>00903 <span class="comment">            sinfo_msg_warning ("error in sinfo_polyfit in column: %d\n", i) ;</span>
+<a name="l00904"></a>00904 <span class="comment">      */</span>
+<a name="l00905"></a>00905             <span class="keywordflow">for</span> ( j = 0 ; j < n_a_fitcoefs ; j++ )
+<a name="l00906"></a>00906             {
+<a name="l00907"></a>00907                 acoefs[j] = ZERO ;
+<a name="l00908"></a>00908                 dacoefs[j] = ZERO ;
+<a name="l00909"></a>00909             }
+<a name="l00910"></a>00910         }
+<a name="l00911"></a>00911 
+<a name="l00912"></a>00912         <span class="keywordflow">for</span> ( j = 0 ; j < n_a_fitcoefs ; j++ )
+<a name="l00913"></a>00913         {
+<a name="l00914"></a>00914 
+<a name="l00915"></a>00915             <span class="keywordflow">if</span> ( acoefs[0] <= 0. || acoefs[1] ==0. ||
+<a name="l00916"></a>00916                  dacoefs[j] == 0. || isnan(acoefs[j]) )
+<a name="l00917"></a>00917             {
+<a name="l00918"></a>00918                 zeroind = 1 ;
+<a name="l00919"></a>00919             }
+<a name="l00920"></a>00920         }
+<a name="l00921"></a>00921         <span class="keywordflow">for</span> ( j = 0 ; j < n_a_fitcoefs ; j++ )
+<a name="l00922"></a>00922         {
+<a name="l00923"></a>00923             <span class="keywordflow">if</span> ( zeroind == 0 )
+<a name="l00924"></a>00924             {
+<a name="l00925"></a>00925                 abuf[j][i]  = acoefs[j] ;
+<a name="l00926"></a>00926                 dabuf[j][i] = dacoefs[j] ;
+<a name="l00927"></a>00927             }
+<a name="l00928"></a>00928             <span class="keywordflow">else</span>
+<a name="l00929"></a>00929             {
+<a name="l00930"></a>00930                 abuf[j][i]  = ZERO ;
+<a name="l00931"></a>00931                 dabuf[j][i] = ZERO ;
+<a name="l00932"></a>00932             }
+<a name="l00933"></a>00933         }
+<a name="l00934"></a>00934     }
+<a name="l00935"></a>00935  
+<a name="l00936"></a>00936     <span class="comment">/* allocate memory for the fitting coefficients */</span>
+<a name="l00937"></a>00937     <span class="keywordflow">if</span> ( NULL == ( bco = sinfo_new_b_coeffs( n_slitlets, 
+<a name="l00938"></a>00938                                              n_a_fitcoefs, n_b_fitcoefs)) )
+<a name="l00939"></a>00939     {
+<a name="l00940"></a>00940         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"cannot allocate memory for the bcoeffs"</span>) ;
+<a name="l00941"></a>00941         sinfo_free_float_array(&dabuf,n_a_fitcoefs) ;
+<a name="l00942"></a>00942         sinfo_free_float (&acoefs ) ;
+<a name="l00943"></a>00943         sinfo_free_float (&dacoefs ) ;
+<a name="l00944"></a>00944         sinfo_free_float (&chisq_cross ) ;
+<a name="l00945"></a>00945         <span class="keywordflow">return</span> NULL ;
+<a name="l00946"></a>00946     }
+<a name="l00947"></a>00947 
+<a name="l00948"></a>00948     <span class="comment">/* fit each acoefs across the slitlets to smooth the result */</span>
+<a name="l00949"></a>00949     <span class="keywordflow">if</span> ( -1 == ( crossInd = sinfo_new_coeffs_cross_slit_fit( ilx, 
+<a name="l00950"></a>00950                                                 abuf, 
+<a name="l00951"></a>00951                                                 dabuf,
+<a name="l00952"></a>00952                                                 bco, 
+<a name="l00953"></a>00953                                                 sigmaFactor, 
+<a name="l00954"></a>00954                                                 dispersion, 
+<a name="l00955"></a>00955                                                 pixel_dist, 
+<a name="l00956"></a>00956                                                 chisq_cross )) )
+<a name="l00957"></a>00957     {
+<a name="l00958"></a>00958         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"cannot carry out the fitting of "</span>
+<a name="l00959"></a>00959                          <span class="stringliteral">"coefficients across the columns"</span>) ;
+<a name="l00960"></a>00960         sinfo_free_float_array(&dabuf,n_a_fitcoefs) ;
+<a name="l00961"></a>00961         sinfo_free_float (&acoefs ) ;
+<a name="l00962"></a>00962         sinfo_free_float (&dacoefs ) ;
+<a name="l00963"></a>00963         sinfo_free_float (&chisq_cross ) ;
+<a name="l00964"></a>00964         <span class="keywordflow">return</span> NULL ;
+<a name="l00965"></a>00965     }
+<a name="l00966"></a>00966   
+<a name="l00967"></a>00967 
+<a name="l00968"></a>00968     <span class="keywordflow">if</span> ( NULL == (wavemap = sinfo_new_wave_map_slit (abuf, n_a_fitcoefs, 
+<a name="l00969"></a>00969                                                      ily, ilx)) )
+<a name="l00970"></a>00970     {
+<a name="l00971"></a>00971         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"cannot carry out wavemap creation"</span>) ;
+<a name="l00972"></a>00972         sinfo_free_float_array(&dabuf,n_a_fitcoefs) ;
+<a name="l00973"></a>00973         sinfo_free_float (&acoefs ) ;
+<a name="l00974"></a>00974         sinfo_free_float (&dacoefs ) ;
+<a name="l00975"></a>00975         sinfo_free_float (&chisq_cross ) ;
+<a name="l00976"></a>00976         sinfo_new_destroy_b_coeffs(bco) ;
+<a name="l00977"></a>00977         <span class="keywordflow">return</span> NULL ;
+<a name="l00978"></a>00978     }
+<a name="l00979"></a>00979 
+<a name="l00980"></a>00980     <span class="comment">/* free all allocated memory */</span>
+<a name="l00981"></a>00981     sinfo_free_float_array(&dabuf,n_a_fitcoefs) ;
+<a name="l00982"></a>00982     sinfo_free_float (&acoefs ) ;
+<a name="l00983"></a>00983     sinfo_free_float (&dacoefs ) ;
+<a name="l00984"></a>00984     sinfo_free_float (&chisq_cross ) ;
+<a name="l00985"></a>00985     sinfo_new_destroy_b_coeffs(bco) ;
+<a name="l00986"></a>00986 
+<a name="l00987"></a>00987     <span class="keywordflow">return</span> wavemap ;
+<a name="l00988"></a>00988  cleanup:
+<a name="l00989"></a>00989     sinfo_free_float (&acoefs ) ;
+<a name="l00990"></a>00990     sinfo_free_float ( &dacoefs ) ;
+<a name="l00991"></a>00991     sinfo_free_float ( &chisq_cross ) ;
+<a name="l00992"></a>00992     sinfo_free_float_array(&dabuf,n_a_fitcoefs) ;
+<a name="l00993"></a>00993     sinfo_new_destroy_b_coeffs(bco) ;
+<a name="l00994"></a>00994     <span class="keywordflow">return</span> NULL;
+<a name="l00995"></a>00995 }
+<a name="l00996"></a>00996 
+<a name="l00997"></a>00997 
+<a name="l00998"></a>00998 
+<a name="l01021"></a>01021 <span class="keywordtype">int</span> sinfo_new_check_for_fake_lines ( FitParams ** par,
+<a name="l01022"></a>01022                         <span class="keywordtype">float</span>        dispersion,
+<a name="l01023"></a>01023             <span class="keywordtype">float</span>     ** wavelength_clean,
+<a name="l01024"></a>01024             <span class="keywordtype">int</span>       ** row_clean,
+<a name="l01025"></a>01025             <span class="keywordtype">int</span>        * n_found_lines,
+<a name="l01026"></a>01026             <span class="keywordtype">int</span>          n_columns,
+<a name="l01027"></a>01027             <span class="keywordtype">float</span>        pixel_tolerance )
+<a name="l01028"></a>01028 {
+<a name="l01029"></a>01029     <span class="keywordtype">int</span> i,  k ;
+<a name="l01030"></a>01030     <span class="keywordtype">int</span> col ;
+<a name="l01031"></a>01031     <span class="keywordtype">int</span> found ;
+<a name="l01032"></a>01032     <span class="keywordtype">float</span> row ;
+<a name="l01033"></a>01033     <span class="keywordtype">float</span> * beginWave ;
+<a name="l01034"></a>01034     <span class="keywordtype">float</span> firstWave ;
+<a name="l01035"></a>01035 
+<a name="l01036"></a>01036     <span class="keywordflow">if</span> ( par == NULL )
+<a name="l01037"></a>01037     {
+<a name="l01038"></a>01038         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no fit parameter data structure given"</span>) ;
+<a name="l01039"></a>01039         <span class="keywordflow">return</span> -1 ;
+<a name="l01040"></a>01040     }
+<a name="l01041"></a>01041     <span class="keywordflow">if</span> ( dispersion == 0. )
+<a name="l01042"></a>01042     {
+<a name="l01043"></a>01043         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"dispersion zero given!"</span>) ;
+<a name="l01044"></a>01044         <span class="keywordflow">return</span> -1 ;
+<a name="l01045"></a>01045     }
+<a name="l01046"></a>01046     <span class="keywordflow">if</span> ( wavelength_clean == NULL )
+<a name="l01047"></a>01047     {
+<a name="l01048"></a>01048         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no wavelength array given!"</span>) ;
+<a name="l01049"></a>01049         <span class="keywordflow">return</span> -1 ;
+<a name="l01050"></a>01050     }
+<a name="l01051"></a>01051     <span class="keywordflow">if</span> ( row_clean == NULL )
+<a name="l01052"></a>01052     {
+<a name="l01053"></a>01053         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no row array given!"</span>) ;
+<a name="l01054"></a>01054         <span class="keywordflow">return</span> -1 ;
+<a name="l01055"></a>01055     }
+<a name="l01056"></a>01056     <span class="keywordflow">if</span> ( n_found_lines == NULL )
+<a name="l01057"></a>01057     {
+<a name="l01058"></a>01058         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"no number of lines given!"</span>) ;
+<a name="l01059"></a>01059         <span class="keywordflow">return</span> -1 ;
+<a name="l01060"></a>01060     }
+<a name="l01061"></a>01061     <span class="keywordflow">if</span> ( n_columns < 200 )
+<a name="l01062"></a>01062     {
+<a name="l01063"></a>01063         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"wrong number of columns given!"</span>) ;
+<a name="l01064"></a>01064         <span class="keywordflow">return</span> -1 ;
+<a name="l01065"></a>01065     }
+<a name="l01066"></a>01066 
+<a name="l01067"></a>01067     <span class="comment">/* first determine the estimated beginning wavelength of the first row */</span>
+<a name="l01068"></a>01068     <span class="keywordflow">for</span> ( col = 0 ; col < n_columns ; col++ )
+<a name="l01069"></a>01069     {
+<a name="l01070"></a>01070         <span class="keywordflow">if</span> ( n_found_lines[col] == 0 )
+<a name="l01071"></a>01071         {
+<a name="l01072"></a>01072         continue ;
+<a name="l01073"></a>01073         } 
+<a name="l01074"></a>01074         <span class="keywordflow">if</span> ( NULL == (beginWave = (<span class="keywordtype">float</span>*) cpl_calloc( n_found_lines[col], 
+<a name="l01075"></a>01075                                                        <span class="keyword">sizeof</span>(<span class="keywordtype">float</span>) ) ) )
+<a name="l01076"></a>01076         {
+<a name="l01077"></a>01077             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"could not allocate memory!"</span>) ;
+<a name="l01078"></a>01078             <span class="keywordflow">return</span> -1 ;
+<a name="l01079"></a>01079     }
+<a name="l01080"></a>01080     <span class="keywordflow">for</span> ( k = 0 ; k < n_found_lines[col] ; k++ ) 
+<a name="l01081"></a>01081     {
+<a name="l01082"></a>01082         beginWave[k] = wavelength_clean[col][k] - 
+<a name="l01083"></a>01083                            (float)row_clean[col][k] * dispersion ;
+<a name="l01084"></a>01084         }
+<a name="l01085"></a>01085     <span class="comment">/* determine the clean mean of the estimated </span>
+<a name="l01086"></a>01086 <span class="comment">           beginning wavelengths of one column */</span>
+<a name="l01087"></a>01087     <span class="keywordflow">if</span> ( FLT_MAX == (firstWave = sinfo_new_clean_mean (beginWave, 
+<a name="l01088"></a>01088                                                            n_found_lines[col], 
+<a name="l01089"></a>01089                                                            10., 10.) ) )
+<a name="l01090"></a>01090     {
+<a name="l01091"></a>01091             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"clean mean did not work!"</span>) ;
+<a name="l01092"></a>01092             <span class="keywordflow">return</span> -1 ;
+<a name="l01093"></a>01093     }
+<a name="l01094"></a>01094 
+<a name="l01095"></a>01095         cpl_free (beginWave) ;
+<a name="l01096"></a>01096         <span class="comment">/* go through the lines in that column and select the </span>
+<a name="l01097"></a>01097 <span class="comment">           correct FitParam structure */</span>
+<a name="l01098"></a>01098         <span class="keywordflow">for</span> ( k = 0 ; k < n_found_lines[col] ; k++ ) 
+<a name="l01099"></a>01099         {    
+<a name="l01100"></a>01100         <span class="comment">/* compute the estimated line position */</span>
+<a name="l01101"></a>01101         row = ( wavelength_clean[col][k] - firstWave ) / dispersion ;
+<a name="l01102"></a>01102 
+<a name="l01103"></a>01103             <span class="comment">/* go through all fit parameters and find the corresponding one */</span>
+<a name="l01104"></a>01104         found = -1 ;
+<a name="l01105"></a>01105             <span class="keywordflow">for</span> ( i = 0 ; i < (par[0] -> n_params) ; i ++ )
+<a name="l01106"></a>01106             {    
+<a name="l01107"></a>01107             <span class="comment">/* find the given column and go through the </span>
+<a name="l01108"></a>01108 <span class="comment">                   lines in that column */</span>
+<a name="l01109"></a>01109         <span class="keywordflow">if</span> ( (par[i] -> column == col) && (par[i] -> line == k) && 
+<a name="l01110"></a>01110              (par[i] -> wavelength == wavelength_clean[col][k]) )
+<a name="l01111"></a>01111         {
+<a name="l01112"></a>01112                 found = i ;
+<a name="l01113"></a>01113             break ;
+<a name="l01114"></a>01114                 }
+<a name="l01115"></a>01115             }
+<a name="l01116"></a>01116         <span class="keywordflow">if</span> ( found != -1 )
+<a name="l01117"></a>01117         {
+<a name="l01118"></a>01118             <span class="comment">/* set fit params to zero where the fitted row </span>
+<a name="l01119"></a>01119 <span class="comment">                   position and the estimated </span>
+<a name="l01120"></a>01120 <span class="comment">            row positions are outside the tolerance */</span>
+<a name="l01121"></a>01121                 <span class="keywordflow">if</span> ( fabs(row - par[found]->fit_par[2]) > pixel_tolerance ) 
+<a name="l01122"></a>01122             {
+<a name="l01123"></a>01123                 <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"found bad line in col: "</span>
+<a name="l01124"></a>01124                                       <span class="stringliteral">"%d line: %d in row: %f difference: %f"</span>, 
+<a name="l01125"></a>01125                                       col, k, par[found]->fit_par[2],
+<a name="l01126"></a>01126                                       row - par[found]->fit_par[2])  ;
+<a name="l01127"></a>01127                 par[found]->fit_par[2] = 0. ;
+<a name="l01128"></a>01128                 }
+<a name="l01129"></a>01129             }
+<a name="l01130"></a>01130         <span class="keywordflow">else</span>
+<a name="l01131"></a>01131         {
+<a name="l01132"></a>01132         <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"fit parameter of col %d and line "</span>
+<a name="l01133"></a>01133                                   <span class="stringliteral">"no %d not found!\n"</span>, col, k ) ;
+<a name="l01134"></a>01134         }
+<a name="l01135"></a>01135         }
+<a name="l01136"></a>01136     }
+<a name="l01137"></a>01137 
+<a name="l01138"></a>01138     <span class="keywordflow">return</span> 0 ;
+<a name="l01139"></a>01139 }
+<a name="l01140"></a>01140 
+<a name="l01159"></a>01159 cpl_image * 
+<a name="l01160"></a>01160 sinfo_new_create_shifted_slit_wavemap ( cpl_image * lineIm,
+<a name="l01161"></a>01161                               <span class="keywordtype">float</span>    ** coeffs,
+<a name="l01162"></a>01162                           <span class="keywordtype">int</span>      n_fitcoeffs,
+<a name="l01163"></a>01163                                       <span class="keywordtype">float</span>  * wavelength,
+<a name="l01164"></a>01164                                       <span class="keywordtype">float</span>  * intensity,
+<a name="l01165"></a>01165                                       <span class="keywordtype">int</span>      n_lines,
+<a name="l01166"></a>01166                                       <span class="keywordtype">int</span>      magFactor )
+<a name="l01167"></a>01167 {
+<a name="l01168"></a>01168     cpl_image * wavemap ;
+<a name="l01169"></a>01169     <span class="keywordtype">float</span>* emline=NULL ;
+<a name="l01170"></a>01170     <span class="keywordtype">float</span>* spec=NULL ;
+<a name="l01171"></a>01171     <span class="keywordtype">float</span>* wave=NULL ;
+<a name="l01172"></a>01172     <span class="keywordtype">double</span>* a=NULL ;
+<a name="l01173"></a>01173     <span class="keywordtype">float</span>* par=NULL ;
+<a name="l01174"></a>01174     <span class="keywordtype">float</span>* derv_par=NULL ;
+<a name="l01175"></a>01175     <span class="keywordtype">double</span>* z=NULL ;
+<a name="l01176"></a>01176 
+<a name="l01177"></a>01177     <span class="keywordtype">double</span>  * result ;
+<a name="l01178"></a>01178     <span class="keywordtype">float</span> * filter_spec ;
+<a name="l01179"></a>01179     <span class="keywordtype">float</span> centreval ;
+<a name="l01180"></a>01180     <span class="keywordtype">float</span> centrepix ;
+<a name="l01181"></a>01181     <span class="keywordtype">float</span> cenpos, cenpix ;
+<a name="l01182"></a>01182     <span class="keywordtype">float</span> pixvalue ;
+<a name="l01183"></a>01183     <span class="keywordtype">float</span> wavelag ;
+<a name="l01184"></a>01184     <span class="keywordtype">float</span> angst ;
+<a name="l01185"></a>01185     <span class="keywordtype">float</span> a_initial ;
+<a name="l01186"></a>01186     <span class="keywordtype">int</span>        numpar, its ;
+<a name="l01187"></a>01187     <span class="keywordtype">int</span>        * mpar ;
+<a name="l01188"></a>01188     <span class="keywordtype">float</span>      tol, lab ;
+<a name="l01189"></a>01189     <span class="keywordtype">float</span>      * xdat, * wdat ;
+<a name="l01190"></a>01190     Vector     * peak;
+<a name="l01191"></a>01191     <span class="keywordtype">int</span>   iters, xdim, ndat ;
+<a name="l01192"></a>01192     <span class="keywordtype">int</span>   row , col ;
+<a name="l01193"></a>01193     <span class="keywordtype">int</span>   i, j, k<span class="comment">/*, l, m*/</span> ;
+<a name="l01194"></a>01194     <span class="keywordtype">int</span>   sign, found, line, width ;
+<a name="l01195"></a>01195     <span class="keywordtype">int</span> var, maxlag, cmin, cmax ;
+<a name="l01196"></a>01196     gsl_poly_complex_workspace * w ;
+<a name="l01197"></a>01197     <span class="keywordtype">double</span> xcorr_max ;
+<a name="l01198"></a>01198     <span class="keywordtype">int</span> delta ;
+<a name="l01199"></a>01199     <span class="keywordtype">int</span> ilx=0;
+<a name="l01200"></a>01200     <span class="keywordtype">int</span> ily=0;
+<a name="l01201"></a>01201     <span class="keywordtype">int</span> olx=0;
+<a name="l01202"></a>01202     <span class="keywordtype">int</span> oly=0;
+<a name="l01203"></a>01203     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l01204"></a>01204     <span class="keywordtype">float</span>* podata=NULL;
+<a name="l01205"></a>01205 
+<a name="l01206"></a>01206 
+<a name="l01207"></a>01207     <span class="keywordflow">if</span> ( lineIm == NULL )
+<a name="l01208"></a>01208     {
+<a name="l01209"></a>01209         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"no input image given!"</span>) ;
+<a name="l01210"></a>01210         <span class="keywordflow">return</span> NULL ;
+<a name="l01211"></a>01211     }
+<a name="l01212"></a>01212     ilx=cpl_image_get_size_x(lineIm);
+<a name="l01213"></a>01213     ily=cpl_image_get_size_y(lineIm);
+<a name="l01214"></a>01214     pidata=cpl_image_get_data_float(lineIm);
+<a name="l01215"></a>01215 
+<a name="l01216"></a>01216     <span class="keywordflow">if</span> ( coeffs == NULL )
+<a name="l01217"></a>01217     {
+<a name="l01218"></a>01218         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"no coefficient sinfo_matrix given!"</span>) ;
+<a name="l01219"></a>01219         <span class="keywordflow">return</span> NULL ;
+<a name="l01220"></a>01220     }
+<a name="l01221"></a>01221     <span class="keywordflow">if</span> ( n_fitcoeffs < 2 )
+<a name="l01222"></a>01222     {
+<a name="l01223"></a>01223         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"wrong number of polynomial coefficients given!"</span>) ;
+<a name="l01224"></a>01224         <span class="keywordflow">return</span> NULL ;
+<a name="l01225"></a>01225     }
+<a name="l01226"></a>01226     <span class="keywordflow">if</span> ( wavelength == NULL || intensity == NULL )
+<a name="l01227"></a>01227     {
+<a name="l01228"></a>01228         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"no input image given!"</span>) ;
+<a name="l01229"></a>01229         <span class="keywordflow">return</span> NULL ;
+<a name="l01230"></a>01230     }
+<a name="l01231"></a>01231     <span class="keywordflow">if</span> ( n_lines < 1 )
+<a name="l01232"></a>01232     {
+<a name="l01233"></a>01233         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"no input image given!"</span>) ;
+<a name="l01234"></a>01234         <span class="keywordflow">return</span> NULL ;
+<a name="l01235"></a>01235     }
+<a name="l01236"></a>01236 
+<a name="l01237"></a>01237     <span class="comment">/* find out if Angstroem or microns are used */</span>
+<a name="l01238"></a>01238     <span class="keywordflow">if</span> ( wavelength[0] > 10000. )
+<a name="l01239"></a>01239     {
+<a name="l01240"></a>01240         <span class="comment">/* Angstroem */</span>
+<a name="l01241"></a>01241         angst = 10000. ;
+<a name="l01242"></a>01242     }
+<a name="l01243"></a>01243     <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( wavelength[0] > 1000. && wavelength[0] < 10000. )
+<a name="l01244"></a>01244     {
+<a name="l01245"></a>01245         <span class="comment">/* nanometers */</span>
+<a name="l01246"></a>01246         angst = 1000. ;
+<a name="l01247"></a>01247     }
+<a name="l01248"></a>01248     <span class="keywordflow">else</span>
+<a name="l01249"></a>01249     {
+<a name="l01250"></a>01250         <span class="comment">/* microns */</span>
+<a name="l01251"></a>01251         angst = 1. ;
+<a name="l01252"></a>01252     }
+<a name="l01253"></a>01253 
+<a name="l01254"></a>01254     <span class="comment">/* allocate memory */</span>
+<a name="l01255"></a>01255     <span class="keywordflow">if</span> ( NULL == (wavemap = cpl_image_new ( ilx, ily, CPL_TYPE_FLOAT)) )
+<a name="l01256"></a>01256     {
+<a name="l01257"></a>01257         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"could not allocate memory!"</span>) ;
+<a name="l01258"></a>01258         <span class="keywordflow">return</span> NULL ;
+<a name="l01259"></a>01259     }
+<a name="l01260"></a>01260     olx=cpl_image_get_size_x(wavemap);
+<a name="l01261"></a>01261     oly=cpl_image_get_size_y(wavemap);
+<a name="l01262"></a>01262     podata=cpl_image_get_data_float(wavemap);
+<a name="l01263"></a>01263 
+<a name="l01264"></a>01264     var = (magFactor-1)*(magFactor-1) ;
+<a name="l01265"></a>01265 
+<a name="l01266"></a>01266 
+<a name="l01267"></a>01267  
+<a name="l01268"></a>01268     emline=cpl_calloc(ily,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l01269"></a>01269     spec=cpl_calloc(ily,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l01270"></a>01270     wave=cpl_calloc(n_lines,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l01271"></a>01271     par=cpl_calloc(MAXPAR,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l01272"></a>01272     derv_par=cpl_calloc(MAXPAR,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l01273"></a>01273 
+<a name="l01274"></a>01274     a=cpl_calloc(n_fitcoeffs,<span class="keyword">sizeof</span>(<span class="keywordtype">double</span>)) ;
+<a name="l01275"></a>01275     z=cpl_calloc(2*(n_fitcoeffs - 1),<span class="keyword">sizeof</span>(<span class="keywordtype">double</span>)) ;
+<a name="l01276"></a>01276 
+<a name="l01277"></a>01277    
+<a name="l01278"></a>01278     <span class="comment">/* first store each spectrum in a buffer */</span>
+<a name="l01279"></a>01279     <span class="keywordflow">for</span> ( col = 0 ; col < ilx ; col++ )
+<a name="l01280"></a>01280     {
+<a name="l01281"></a>01281         <span class="comment">/* initialize the emline array for each column */</span>
+<a name="l01282"></a>01282         <span class="keywordflow">for</span> ( i = 0 ; i < ily ; i++ )
+<a name="l01283"></a>01283         {
+<a name="l01284"></a>01284             emline[i] = 0. ;
+<a name="l01285"></a>01285         }
+<a name="l01286"></a>01286         <span class="comment">/* determine the coefficients by using the given bcoefs */</span>
+<a name="l01287"></a>01287         <span class="keywordflow">for</span> ( i = 0 ; i < n_fitcoeffs ; i++ )
+<a name="l01288"></a>01288         {
+<a name="l01289"></a>01289             <span class="comment">/* initialize coefficients and solution */</span>
+<a name="l01290"></a>01290             <span class="keywordflow">if</span> (i < n_fitcoeffs-1)
+<a name="l01291"></a>01291             {
+<a name="l01292"></a>01292                 z[2*i] = 0. ;
+<a name="l01293"></a>01293                 z[2*i+1] = 0. ;
+<a name="l01294"></a>01294             }
+<a name="l01295"></a>01295             a[i] = coeffs[i][col] ;
+<a name="l01296"></a>01296         }
+<a name="l01297"></a>01297          
+<a name="l01298"></a>01298         a_initial = coeffs[0][col] ;
+<a name="l01299"></a>01299         <span class="comment">/* go through the lines and generate an artificial spectrum */</span>
+<a name="l01300"></a>01300         <span class="keywordflow">for</span> ( line = 0 ; line < n_lines ; line++ )
+<a name="l01301"></a>01301         {
+<a name="l01302"></a>01302             <span class="comment">/* go from Angstroem to micron */</span>
+<a name="l01303"></a>01303             wave[line] = wavelength[line]/angst ;
+<a name="l01304"></a>01304 
+<a name="l01305"></a>01305             <span class="comment">/* -----------------------------------------------------------</span>
+<a name="l01306"></a>01306 <span class="comment">             * solve the polynomial for the exact offset of the line that means</span>
+<a name="l01307"></a>01307 <span class="comment">             * find the root of the polynomial of order n_fitcoefs - 1</span>
+<a name="l01308"></a>01308 <span class="comment">             */</span>
+<a name="l01309"></a>01309             a[0] = a_initial - wave[line] ;
+<a name="l01310"></a>01310 
+<a name="l01311"></a>01311             <span class="keywordflow">if</span>(NULL==(w=sinfo_gsl_poly_complex_workspace_alloc(n_fitcoeffs))) 
+<a name="l01312"></a>01312             {
+<a name="l01313"></a>01313                 <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"could not allocate complex workspace!"</span>) ;
+<a name="l01314"></a>01314                 cpl_image_delete(wavemap) ;
+<a name="l01315"></a>01315                 <span class="keywordflow">return</span> NULL ;
+<a name="l01316"></a>01316             }
+<a name="l01317"></a>01317             <span class="keywordflow">if</span> (-1 == sinfo_gsl_poly_complex_solve(a, n_fitcoeffs, w, z)) 
+<a name="l01318"></a>01318             {
+<a name="l01319"></a>01319                 <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"sinfo_gsl_poly_complex_solve did not work!"</span>) ;
+<a name="l01320"></a>01320                 cpl_image_delete(wavemap) ;
+<a name="l01321"></a>01321                 <span class="keywordflow">return</span> NULL ;
+<a name="l01322"></a>01322             }
+<a name="l01323"></a>01323             sinfo_gsl_poly_complex_workspace_free(w) ;           
+<a name="l01324"></a>01324 
+<a name="l01325"></a>01325             j = 0 ;
+<a name="l01326"></a>01326             found = -1 ;
+<a name="l01327"></a>01327             <span class="keywordflow">for</span> ( i = 0 ; i < n_fitcoeffs - 1 ; i++ )
+<a name="l01328"></a>01328             {
+<a name="l01329"></a>01329                 <span class="comment">/* test for appropriate solution */</span>
+<a name="l01330"></a>01330                 <span class="keywordflow">if</span>( (z[2*i] > (-1.)*(<span class="keywordtype">float</span>) ily/2. &&
+<a name="l01331"></a>01331                      z[2*i] < (<span class="keywordtype">float</span>)ily/2.) && z[2*i+1] == 0. )
+<a name="l01332"></a>01332                 {
+<a name="l01333"></a>01333                     found = 2*i ;
+<a name="l01334"></a>01334                     j ++ ;
+<a name="l01335"></a>01335                 }
+<a name="l01336"></a>01336                 <span class="keywordflow">else</span>
+<a name="l01337"></a>01337                 {
+<a name="l01338"></a>01338                     continue ;
+<a name="l01339"></a>01339                 }
+<a name="l01340"></a>01340             }
+<a name="l01341"></a>01341             <span class="keywordflow">if</span> ( j == 0 )
+<a name="l01342"></a>01342             {
+<a name="l01343"></a>01343                 <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"no offset solution found for line %d in "</span>
+<a name="l01344"></a>01344                                   <span class="stringliteral">"column %d"</span>, line, col) ;
+<a name="l01345"></a>01345                 continue ;
+<a name="l01346"></a>01346             }
+<a name="l01347"></a>01347             <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( j == 1 )
+<a name="l01348"></a>01348             {
+<a name="l01349"></a>01349                 cenpos = z[found] + (float) ily /2. ;
+<a name="l01350"></a>01350             }
+<a name="l01351"></a>01351             <span class="keywordflow">else</span>
+<a name="l01352"></a>01352             {
+<a name="l01353"></a>01353                 <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"two or more offset solutions found for "</span>
+<a name="l01354"></a>01354                                   <span class="stringliteral">"line %d in column %d"</span>, line, col) ;
+<a name="l01355"></a>01355                 continue ;
+<a name="l01356"></a>01356             }
+<a name="l01357"></a>01357 
+<a name="l01358"></a>01358             <span class="comment">/*-----------------------------------------------------------------</span>
+<a name="l01359"></a>01359 <span class="comment">             * magnify image by the given factor add an additional offset</span>
+<a name="l01360"></a>01360 <span class="comment">             */</span>
+<a name="l01361"></a>01361             cenpix = cenpos ;
+<a name="l01362"></a>01362 
+<a name="l01363"></a>01363             <span class="comment">/* determine max and min pixel limits over </span>
+<a name="l01364"></a>01364 <span class="comment">               which line should be convolved */</span>
+<a name="l01365"></a>01365             cmin = (sinfo_new_nint(cenpix) - (var-1)) > 0 ? 
+<a name="l01366"></a>01366                     sinfo_new_nint(cenpix) - (var-1) : 0 ;
+<a name="l01367"></a>01367             cmax = (sinfo_new_nint(cenpix) + (var-1)) < ily ?
+<a name="l01368"></a>01368                     sinfo_new_nint(cenpix) + (var-1) : ily ;
+<a name="l01369"></a>01369 
+<a name="l01370"></a>01370             <span class="comment">/* convolve neon lines with Gaussian function */</span>
+<a name="l01371"></a>01371             <span class="keywordflow">for</span> ( j = cmin ; j < cmax ; j++ )
+<a name="l01372"></a>01372             {
+<a name="l01373"></a>01373                 emline[j] += intensity[line] * 
+<a name="l01374"></a>01374                      exp((<span class="keywordtype">double</span>)(-0.5*(j-cenpix)*(j-cenpix))/(<span class="keywordtype">double</span>)var) ;
+<a name="l01375"></a>01375             }
+<a name="l01376"></a>01376         }
+<a name="l01377"></a>01377 
+<a name="l01378"></a>01378         <span class="comment">/*-------------------------------------------------------------------</span>
+<a name="l01379"></a>01379 <span class="comment">         * for each column, map the image data points onto an magFactor times </span>
+<a name="l01380"></a>01380 <span class="comment">           bigger element grid for FFT in the cross sinfo_correlation, first </span>
+<a name="l01381"></a>01381 <span class="comment">           initialize the two helping arrays for each new column.</span>
+<a name="l01382"></a>01382 <span class="comment">         */</span>
+<a name="l01383"></a>01383         <span class="keywordflow">for</span> ( k = 0 ; k < ily ; k++ )
+<a name="l01384"></a>01384         {
+<a name="l01385"></a>01385             spec[k] = 0. ;
+<a name="l01386"></a>01386         }
+<a name="l01387"></a>01387 
+<a name="l01388"></a>01388         <span class="comment">/* now take the image data points of the column and put </span>
+<a name="l01389"></a>01389 <span class="comment">           them into the spec array */</span>
+<a name="l01390"></a>01390         <span class="keywordflow">for</span> ( row = 0 ; row < ily ; row++ ) <span class="comment">/* go through the column */</span>
+<a name="l01391"></a>01391         {
+<a name="l01392"></a>01392             <span class="comment">/* set bad pixels or negative values to zero */</span>
+<a name="l01393"></a>01393             <span class="keywordflow">if</span> (!isnan(pidata[col + row*ilx]) &&
+<a name="l01394"></a>01394                 (pidata[col + row*ilx] > 0.))
+<a name="l01395"></a>01395             {
+<a name="l01396"></a>01396                 spec[row] = pidata[col + row*ilx] ;
+<a name="l01397"></a>01397             }
+<a name="l01398"></a>01398             <span class="keywordflow">else</span>
+<a name="l01399"></a>01399             {
+<a name="l01400"></a>01400                 spec[row] = 0. ;
+<a name="l01401"></a>01401             }
+<a name="l01402"></a>01402         }
+<a name="l01403"></a>01403         <span class="comment">/* convolve the spectrum by Gaussian */</span>
+<a name="l01404"></a>01404         filter_spec = sinfo_function1d_filter_lowpass(spec, ily, 
+<a name="l01405"></a>01405                                                       LOW_PASS_GAUSSIAN, 
+<a name="l01406"></a>01406                                                       magFactor) ; 
+<a name="l01407"></a>01407 
+<a name="l01408"></a>01408         <span class="comment">/* now call the cross sinfo_correlation routine */</span>
+<a name="l01409"></a>01409         result = sinfo_new_xcorrel( filter_spec, ily, emline, ily,
+<a name="l01410"></a>01410                           ily/2, &delta, &maxlag, &xcorr_max) ;
+<a name="l01411"></a>01411 
+<a name="l01412"></a>01412         <span class="keywordflow">if</span> ( xcorr_max <= 0. )
+<a name="l01413"></a>01413         {
+<a name="l01414"></a>01414             <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"no positive cross correlation sum , "</span>
+<a name="l01415"></a>01415                               <span class="stringliteral">"col %d set to ZERO \n"</span>, col) ;
+<a name="l01416"></a>01416             <span class="keywordflow">for</span> ( row = 0 ; row < ily ; row++ )
+<a name="l01417"></a>01417             {
+<a name="l01418"></a>01418                 podata[col + row*ilx] = ZERO ;
+<a name="l01419"></a>01419             }
+<a name="l01420"></a>01420             sinfo_function1d_del(filter_spec) ;
+<a name="l01421"></a>01421             cpl_free(result) ;
+<a name="l01422"></a>01422             continue ;
+<a name="l01423"></a>01423         }
+<a name="l01424"></a>01424 
+<a name="l01425"></a>01425        <span class="comment">/* in this section, we fit the correlation function with a gauss, </span>
+<a name="l01426"></a>01426 <span class="comment">          and find its peak, thus getting subpixel-accuracy */</span>
+<a name="l01427"></a>01427 
+<a name="l01428"></a>01428         i = maxlag; j = i+1;
+<a name="l01429"></a>01429         <span class="keywordflow">while</span> (result[j] < result[i])
+<a name="l01430"></a>01430         {
+<a name="l01431"></a>01431             i++; j++;
+<a name="l01432"></a>01432         }
+<a name="l01433"></a>01433         i = maxlag; k = i-1;
+<a name="l01434"></a>01434         <span class="keywordflow">while</span> (result[k] < result[i])
+<a name="l01435"></a>01435         {
+<a name="l01436"></a>01436             i--; k--;
+<a name="l01437"></a>01437         }
+<a name="l01438"></a>01438         width = j-k+1;
+<a name="l01439"></a>01439         <span class="comment">/* allocate memory for the spectral sinfo_vector */</span>
+<a name="l01440"></a>01440         <span class="keywordflow">if</span> ( NULL == (peak = sinfo_new_vector (width)) )
+<a name="l01441"></a>01441         {
+<a name="l01442"></a>01442             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"cannot allocate new Vector \n"</span>) ;
+<a name="l01443"></a>01443             sinfo_function1d_del(filter_spec) ;
+<a name="l01444"></a>01444             cpl_free(result) ;
+<a name="l01445"></a>01445             <span class="keywordflow">return</span> NULL ;
+<a name="l01446"></a>01446         }
+<a name="l01447"></a>01447 
+<a name="l01448"></a>01448 
+<a name="l01449"></a>01449         <span class="comment">/* allocate memory */</span>
+<a name="l01450"></a>01450         xdat = (<span class="keywordtype">float</span> *) cpl_calloc( peak -> n_elements, <span class="keyword">sizeof</span> (<span class="keywordtype">float</span>) ) ;
+<a name="l01451"></a>01451         wdat = (<span class="keywordtype">float</span> *) cpl_calloc( peak -> n_elements, <span class="keyword">sizeof</span> (<span class="keywordtype">float</span>) ) ;
+<a name="l01452"></a>01452         mpar = (<span class="keywordtype">int</span> *)   cpl_calloc( MAXPAR, <span class="keyword">sizeof</span> (<span class="keywordtype">int</span>) ) ;
+<a name="l01453"></a>01453 
+<a name="l01454"></a>01454         <span class="comment">/* determine the values of the spectral sinfo_vector given as input */</span>
+<a name="l01455"></a>01455         <span class="comment">/* go through the chosen column */</span>
+<a name="l01456"></a>01456 
+<a name="l01457"></a>01457         <span class="keywordflow">for</span> ( i = 0 ; i < width ; i++ )
+<a name="l01458"></a>01458         {
+<a name="l01459"></a>01459             peak -> data[i] = result[k+i]/xcorr_max * 100. ;
+<a name="l01460"></a>01460             xdat[i] = i;
+<a name="l01461"></a>01461             wdat[i] = 1.0;
+<a name="l01462"></a>01462         }
+<a name="l01463"></a>01463 
+<a name="l01464"></a>01464         <span class="comment">/* set initial values for the fitting routine */</span>
+<a name="l01465"></a>01465         xdim     = XDIM;
+<a name="l01466"></a>01466         ndat     = peak -> n_elements ;
+<a name="l01467"></a>01467         numpar   = MAXPAR ;
+<a name="l01468"></a>01468         tol      = TOL ;
+<a name="l01469"></a>01469         lab      = LAB ;
+<a name="l01470"></a>01470         its      = ITS ;
+<a name="l01471"></a>01471         par[1] = width/2.0 ;
+<a name="l01472"></a>01472         par[2] = (float) (maxlag - k) ;
+<a name="l01473"></a>01473         par[3] = (peak -> data[0] + peak -> data[peak->n_elements - 1]) / 2.0 ;
+<a name="l01474"></a>01474         par[0]  = result[maxlag]/xcorr_max * 100. - (par[3]) ;
+<a name="l01475"></a>01475 
+<a name="l01476"></a>01476         <span class="keywordflow">for</span> ( i = 0 ; i < MAXPAR ; i++ )
+<a name="l01477"></a>01477         {
+<a name="l01478"></a>01478             derv_par[i] = 0.0 ;
+<a name="l01479"></a>01479             mpar[i] = 1 ;
+<a name="l01480"></a>01480         }
+<a name="l01481"></a>01481 
+<a name="l01482"></a>01482         <span class="comment">/* finally, do the least square fit using a sinfo_gaussian */</span>
+<a name="l01483"></a>01483         <span class="keywordflow">if</span> ( 0 > ( iters = sinfo_new_lsqfit_c( xdat, &xdim, 
+<a name="l01484"></a>01484                                                peak -> data, wdat, 
+<a name="l01485"></a>01485                                                &ndat, par, derv_par, mpar,
+<a name="l01486"></a>01486                                                &numpar, &tol, &its, &lab )) )
+<a name="l01487"></a>01487         {
+<a name="l01488"></a>01488             <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a> (<span class="stringliteral">"sinfo_new_lsqfit_c: least squares fit failed "</span>
+<a name="l01489"></a>01489                                <span class="stringliteral">"in col: %d, error no.: %d"</span>, col, iters) ;
+<a name="l01490"></a>01490             sinfo_new_destroy_vector ( peak ) ;
+<a name="l01491"></a>01491             cpl_free ( xdat ) ;
+<a name="l01492"></a>01492             cpl_free ( wdat ) ;
+<a name="l01493"></a>01493             cpl_free ( mpar ) ;
+<a name="l01494"></a>01494             sinfo_function1d_del(filter_spec) ;
+<a name="l01495"></a>01495             cpl_free(result) ;
+<a name="l01496"></a>01496             continue ;
+<a name="l01497"></a>01497         }
+<a name="l01498"></a>01498 
+<a name="l01499"></a>01499         sinfo_new_destroy_vector ( peak ) ;
+<a name="l01500"></a>01500         cpl_free (xdat) ;
+<a name="l01501"></a>01501         cpl_free (wdat) ;
+<a name="l01502"></a>01502         cpl_free (mpar) ;
+<a name="l01503"></a>01503         sinfo_function1d_del(filter_spec) ;
+<a name="l01504"></a>01504         cpl_free(result) ;
+<a name="l01505"></a>01505 
+<a name="l01506"></a>01506         wavelag =((float)ily/2 - (<span class="keywordtype">float</span>)k - par[2]) ;
+<a name="l01507"></a>01507 
+<a name="l01508"></a>01508         <span class="keywordflow">if</span> ( fabs(wavelag) > (float)ily/20. )
+<a name="l01509"></a>01509         {
+<a name="l01510"></a>01510             <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"wavelag very big , col %d set to ZERO"</span>, col) ;
+<a name="l01511"></a>01511             <span class="keywordflow">for</span> ( row = 0 ; row < ily ; row++ )
+<a name="l01512"></a>01512             {
+<a name="l01513"></a>01513                 podata[col + row*ilx] = ZERO ;
+<a name="l01514"></a>01514             }
+<a name="l01515"></a>01515             continue ;
+<a name="l01516"></a>01516         }
+<a name="l01517"></a>01517 
+<a name="l01518"></a>01518         <span class="comment">/*--------------------------------------------------------------------</span>
+<a name="l01519"></a>01519 <span class="comment">         * determine new zero order coefficient centreval, of which the </span>
+<a name="l01520"></a>01520 <span class="comment">         * formula is determined by setting equal a polynomial shifted by </span>
+<a name="l01521"></a>01521 <span class="comment">         * wavelag with the same higher order coefficients and set the new </span>
+<a name="l01522"></a>01522 <span class="comment">         * zero order coefficient to</span>
+<a name="l01523"></a>01523 <span class="comment">         * get both sides of the equation approximately equal.</span>
+<a name="l01524"></a>01524 <span class="comment">         */</span>
+<a name="l01525"></a>01525         centreval = a_initial ;
+<a name="l01526"></a>01526         <span class="keywordflow">for</span> ( i = 1 ; i < n_fitcoeffs ; i++ )
+<a name="l01527"></a>01527         {
+<a name="l01528"></a>01528             <span class="keywordflow">if</span> ( i%2 == 0 ) 
+<a name="l01529"></a>01529             {
+<a name="l01530"></a>01530                 sign = -1 ;
+<a name="l01531"></a>01531             }
+<a name="l01532"></a>01532             <span class="keywordflow">else</span>
+<a name="l01533"></a>01533             {
+<a name="l01534"></a>01534                 sign = 1 ;
+<a name="l01535"></a>01535             }
+<a name="l01536"></a>01536             centreval += (float)sign * coeffs[i][col]*pow(wavelag, i) ;
+<a name="l01537"></a>01537         }
+<a name="l01538"></a>01538 
+<a name="l01539"></a>01539         <span class="comment">/* prepare to write out wavelength as pixel values */</span>
+<a name="l01540"></a>01540         <span class="keywordflow">for</span> ( row = 0 ; row < oly ; row++ )
+<a name="l01541"></a>01541         {
+<a name="l01542"></a>01542             centrepix = (float)row - ((<span class="keywordtype">float</span>)oly - 1.)/2. ;
+<a name="l01543"></a>01543             pixvalue = 0. ;
+<a name="l01544"></a>01544             <span class="keywordflow">for</span> ( i = 1 ; i < n_fitcoeffs ; i++ )
+<a name="l01545"></a>01545             {
+<a name="l01546"></a>01546                 pixvalue += coeffs[i][col]*pow(centrepix, i) ;
+<a name="l01547"></a>01547             }
+<a name="l01548"></a>01548             podata[col+row*olx] = centreval + pixvalue ;
+<a name="l01549"></a>01549         }
+<a name="l01550"></a>01550     }
+<a name="l01551"></a>01551 
+<a name="l01552"></a>01552 
+<a name="l01553"></a>01553     cpl_free(emline) ;
+<a name="l01554"></a>01554     cpl_free(spec) ;
+<a name="l01555"></a>01555     cpl_free(wave) ;
+<a name="l01556"></a>01556     cpl_free(par) ;
+<a name="l01557"></a>01557     cpl_free(derv_par) ;
+<a name="l01558"></a>01558 
+<a name="l01559"></a>01559     cpl_free(a) ;
+<a name="l01560"></a>01560     cpl_free(z) ;
+<a name="l01561"></a>01561 
+<a name="l01562"></a>01562 
+<a name="l01563"></a>01563 
+<a name="l01564"></a>01564     <span class="keywordflow">return</span> wavemap ;
+<a name="l01565"></a>01565 }
+<a name="l01566"></a>01566 
+<a name="l01591"></a>01591 cpl_image * sinfo_new_create_shifted_slit_wavemap2 ( cpl_image * lineIm,
+<a name="l01592"></a>01592                                       <span class="keywordtype">float</span>    ** coeffs,
+<a name="l01593"></a>01593                                       <span class="keywordtype">int</span>      n_fitcoeffs,
+<a name="l01594"></a>01594                                       <span class="keywordtype">float</span>  * wavelength,
+<a name="l01595"></a>01595                                       <span class="keywordtype">float</span>  * intensity,
+<a name="l01596"></a>01596                                       <span class="keywordtype">int</span>      n_lines,
+<a name="l01597"></a>01597                                       <span class="keywordtype">int</span>      magFactor,
+<a name="l01598"></a>01598                                       <span class="keywordtype">float</span>    dispersion,
+<a name="l01599"></a>01599                                       <span class="keywordtype">float</span>    pixel_dist )
+<a name="l01600"></a>01600 {
+<a name="l01601"></a>01601     cpl_image * wavemap ;
+<a name="l01602"></a>01602     <span class="keywordtype">double</span> * result ;
+<a name="l01603"></a>01603     <span class="keywordtype">float</span> * filter_spec ;
+<a name="l01604"></a>01604     <span class="keywordtype">float</span> centreval ;
+<a name="l01605"></a>01605     <span class="keywordtype">float</span> centrepix ;
+<a name="l01606"></a>01606     <span class="keywordtype">float</span> cenpos, cenpix ;
+<a name="l01607"></a>01607     <span class="keywordtype">float</span> pixvalue ;
+<a name="l01608"></a>01608     <span class="keywordtype">float</span> wavelag ;
+<a name="l01609"></a>01609     <span class="comment">/*float maxres ;*/</span>
+<a name="l01610"></a>01610     <span class="keywordtype">float</span> angst ;
+<a name="l01611"></a>01611     <span class="comment">/*float temp ;*/</span>
+<a name="l01612"></a>01612     <span class="keywordtype">float</span> a_initial ;
+<a name="l01613"></a>01613     <span class="keywordtype">int</span>        numpar, its ;
+<a name="l01614"></a>01614     <span class="keywordtype">int</span>        * mpar ;
+<a name="l01615"></a>01615     <span class="keywordtype">float</span>      tol, lab ;
+<a name="l01616"></a>01616     <span class="keywordtype">float</span>      * xdat, * wdat ;
+<a name="l01617"></a>01617     Vector     * peak;
+<a name="l01618"></a>01618     <span class="keywordtype">int</span>   iters, xdim, ndat ;
+<a name="l01619"></a>01619     <span class="keywordtype">int</span>   row , col ;
+<a name="l01620"></a>01620     <span class="keywordtype">int</span>   i, j, k<span class="comment">/*, l, m*/</span>, n ;
+<a name="l01621"></a>01621     <span class="keywordtype">int</span>   sign, found, line, width ;
+<a name="l01622"></a>01622     <span class="keywordtype">int</span> var, maxlag, cmin, cmax ;
+<a name="l01623"></a>01623     <span class="keywordtype">float</span> offset2 ;
+<a name="l01624"></a>01624     <span class="keywordtype">float</span> threshold ;
+<a name="l01625"></a>01625     <span class="keywordtype">int</span> ed1, ed2 ;
+<a name="l01626"></a>01626 
+<a name="l01627"></a>01627     <span class="keywordtype">int</span> edge[N_SLITLETS] ;
+<a name="l01628"></a>01628     <span class="keywordtype">float</span> par[MAXPAR] ;
+<a name="l01629"></a>01629     <span class="keywordtype">float</span> derv_par[MAXPAR] ;
+<a name="l01630"></a>01630 
+<a name="l01631"></a>01631     <span class="keywordtype">float</span>* emline=NULL ;
+<a name="l01632"></a>01632     <span class="keywordtype">float</span>* spec=NULL ;
+<a name="l01633"></a>01633     <span class="keywordtype">float</span>* wave=NULL ;
+<a name="l01634"></a>01634     <span class="keywordtype">float</span>* a0=NULL ;
+<a name="l01635"></a>01635     <span class="keywordtype">float</span>* a0_clean=NULL ;
+<a name="l01636"></a>01636 
+<a name="l01637"></a>01637 
+<a name="l01638"></a>01638     <span class="keywordtype">float</span>* sub_col_index=NULL ;
+<a name="l01639"></a>01639     <span class="keywordtype">float</span>* sub_acoefs=NULL;
+<a name="l01640"></a>01640     <span class="keywordtype">float</span>* sub_dacoefs=NULL ;
+<a name="l01641"></a>01641     <span class="keywordtype">double</span>* z=NULL ;
+<a name="l01642"></a>01642     <span class="keywordtype">double</span>* a=NULL ;
+<a name="l01643"></a>01643 
+<a name="l01644"></a>01644     <span class="keywordtype">float</span>** bcoef=NULL ;
+<a name="l01645"></a>01645     <span class="keywordtype">float</span>* wcoefs=NULL ;
+<a name="l01646"></a>01646 
+<a name="l01647"></a>01647 
+<a name="l01648"></a>01648     <span class="keywordtype">int</span> ns, nc ;
+<a name="l01649"></a>01649     <span class="keywordtype">float</span> * acoefsclean ;
+<a name="l01650"></a>01650     <span class="keywordtype">float</span> col_index;
+<a name="l01651"></a>01651 
+<a name="l01652"></a>01652     <span class="keywordtype">float</span> ** ucoefs, **vcoefs, **covar ;
+<a name="l01653"></a>01653     <span class="keywordtype">double</span> sum, sumq, mean ;
+<a name="l01654"></a>01654     <span class="keywordtype">double</span> sigma ;
+<a name="l01655"></a>01655     <span class="keywordtype">double</span> cliphi, cliplo ;
+<a name="l01656"></a>01656     <span class="keywordtype">float</span> chisq ;
+<a name="l01657"></a>01657     <span class="keywordtype">int</span> num, ndata ;
+<a name="l01658"></a>01658     gsl_poly_complex_workspace * w ;
+<a name="l01659"></a>01659     <span class="keywordtype">double</span> xcorr_max ;
+<a name="l01660"></a>01660     <span class="keywordtype">int</span> delta ;
+<a name="l01661"></a>01661     <span class="keywordtype">int</span> ilx=0;
+<a name="l01662"></a>01662     <span class="keywordtype">int</span> ily=0;
+<a name="l01663"></a>01663     <span class="keywordtype">int</span> olx=0;
+<a name="l01664"></a>01664     <span class="keywordtype">int</span> oly=0;
+<a name="l01665"></a>01665     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l01666"></a>01666     <span class="keywordtype">float</span>* podata=NULL;
+<a name="l01667"></a>01667 
+<a name="l01668"></a>01668 
+<a name="l01669"></a>01669     <span class="keywordflow">if</span> ( lineIm == NULL )
+<a name="l01670"></a>01670     {
+<a name="l01671"></a>01671         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" no input image given!\n"</span>) ;
+<a name="l01672"></a>01672         <span class="keywordflow">return</span> NULL ;
+<a name="l01673"></a>01673     }
+<a name="l01674"></a>01674 
+<a name="l01675"></a>01675     ilx=cpl_image_get_size_x(lineIm);
+<a name="l01676"></a>01676     ily=cpl_image_get_size_y(lineIm);
+<a name="l01677"></a>01677     pidata=cpl_image_get_data_float(lineIm);
+<a name="l01678"></a>01678 
+<a name="l01679"></a>01679     <span class="keywordflow">if</span> ( coeffs == NULL )
+<a name="l01680"></a>01680     {
+<a name="l01681"></a>01681         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" no coefficient sinfo_matrix given!\n"</span>) ;
+<a name="l01682"></a>01682         <span class="keywordflow">return</span> NULL ;
+<a name="l01683"></a>01683     }
+<a name="l01684"></a>01684     <span class="keywordflow">if</span> ( n_fitcoeffs < 2 )
+<a name="l01685"></a>01685     {
+<a name="l01686"></a>01686         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" wrong number of polynomial coefficients given!\n"</span>) ;
+<a name="l01687"></a>01687         <span class="keywordflow">return</span> NULL ;
+<a name="l01688"></a>01688     }
+<a name="l01689"></a>01689     <span class="keywordflow">if</span> ( wavelength == NULL || intensity == NULL )
+<a name="l01690"></a>01690     {
+<a name="l01691"></a>01691         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" no input image given!\n"</span>) ;
+<a name="l01692"></a>01692         <span class="keywordflow">return</span> NULL ;
+<a name="l01693"></a>01693     }
+<a name="l01694"></a>01694     <span class="keywordflow">if</span> ( n_lines < 1 || magFactor < 1 )
+<a name="l01695"></a>01695     {
+<a name="l01696"></a>01696         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" no input image given!\n"</span>) ;
+<a name="l01697"></a>01697         <span class="keywordflow">return</span> NULL ;
+<a name="l01698"></a>01698     }
+<a name="l01699"></a>01699     var    = (magFactor - 1)*(magFactor - 1) ;
+<a name="l01700"></a>01700     <span class="comment">/* find out if Angstroem or microns are used */</span>
+<a name="l01701"></a>01701     <span class="keywordflow">if</span> ( wavelength[0] > 10000. )
+<a name="l01702"></a>01702     {
+<a name="l01703"></a>01703         <span class="comment">/* Angstroem */</span>
+<a name="l01704"></a>01704         angst = 10000. ;
+<a name="l01705"></a>01705     }
+<a name="l01706"></a>01706     <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( wavelength[0] > 1000. && wavelength[0] < 10000. )
+<a name="l01707"></a>01707     {
+<a name="l01708"></a>01708         <span class="comment">/* nanometers */</span>
+<a name="l01709"></a>01709         angst = 1000. ;
+<a name="l01710"></a>01710     }
+<a name="l01711"></a>01711     <span class="keywordflow">else</span>
+<a name="l01712"></a>01712     {
+<a name="l01713"></a>01713         <span class="comment">/* microns */</span>
+<a name="l01714"></a>01714         angst = 1. ;
+<a name="l01715"></a>01715     }
+<a name="l01716"></a>01716 
+<a name="l01717"></a>01717     bcoef=sinfo_new_2Dfloatarray(N_SLITLETS,n_fitcoeffs) ;
+<a name="l01718"></a>01718     wcoefs=cpl_calloc(n_fitcoeffs,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l01719"></a>01719 
+<a name="l01720"></a>01720     emline=cpl_calloc(ily,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l01721"></a>01721     spec=cpl_calloc(ily,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l01722"></a>01722     wave=cpl_calloc(n_lines,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l01723"></a>01723     a0=cpl_calloc(ilx,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l01724"></a>01724     a0_clean=cpl_calloc(ilx,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l01725"></a>01725 
+<a name="l01726"></a>01726 
+<a name="l01727"></a>01727 
+<a name="l01728"></a>01728     sub_col_index=cpl_calloc(ilx,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l01729"></a>01729     sub_acoefs=cpl_calloc(ilx,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>));
+<a name="l01730"></a>01730     sub_dacoefs=cpl_calloc(ilx,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l01731"></a>01731 
+<a name="l01732"></a>01732     a=cpl_calloc(n_fitcoeffs,<span class="keyword">sizeof</span>(<span class="keywordtype">double</span>)) ;
+<a name="l01733"></a>01733     z=cpl_calloc(2*(n_fitcoeffs - 1),<span class="keyword">sizeof</span>(<span class="keywordtype">double</span>)) ;
+<a name="l01734"></a>01734 
+<a name="l01735"></a>01735     <span class="comment">/* find the slitlet edges from the a0 coefficient */</span>
+<a name="l01736"></a>01736     n = 0 ;
+<a name="l01737"></a>01737     threshold = pixel_dist * fabs(dispersion) ;
+<a name="l01738"></a>01738     <span class="keywordflow">for</span> ( i = PIXEL ; i < ilx - PIXEL ; )
+<a name="l01739"></a>01739     {
+<a name="l01740"></a>01740         <span class="keywordflow">if</span> (fabs(coeffs[0][i+1] - coeffs[0][i]) >= threshold )
+<a name="l01741"></a>01741         {
+<a name="l01742"></a>01742             edge[n] = i+1 ;
+<a name="l01743"></a>01743             n++ ;
+<a name="l01744"></a>01744             i += PIXEL ;
+<a name="l01745"></a>01745         }
+<a name="l01746"></a>01746         i++ ;
+<a name="l01747"></a>01747     }
+<a name="l01748"></a>01748 
+<a name="l01749"></a>01749 
+<a name="l01750"></a>01750     <span class="comment">/* allocate memory */</span>
+<a name="l01751"></a>01751     <span class="keywordflow">if</span> ( NULL == (wavemap = cpl_image_new ( ilx, ily, CPL_TYPE_FLOAT)) )
+<a name="l01752"></a>01752     {
+<a name="l01753"></a>01753         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" could not allocate memory!\n"</span>) ;
+<a name="l01754"></a>01754         <span class="keywordflow">return</span> NULL ;
+<a name="l01755"></a>01755     }
+<a name="l01756"></a>01756     olx=cpl_image_get_size_x(wavemap);
+<a name="l01757"></a>01757     oly=cpl_image_get_size_y(wavemap);
+<a name="l01758"></a>01758     podata=cpl_image_get_data_float(wavemap);
+<a name="l01759"></a>01759 
+<a name="l01760"></a>01760     <span class="comment">/* first store each spectrum in a buffer */</span>
+<a name="l01761"></a>01761     <span class="keywordflow">for</span> ( col = 0 ; col < ilx ; col++ )
+<a name="l01762"></a>01762     {
+<a name="l01763"></a>01763         <span class="comment">/* initialize the emline array for each column */</span>
+<a name="l01764"></a>01764         <span class="keywordflow">for</span> ( i = 0 ; i < ily ; i++ )
+<a name="l01765"></a>01765         {
+<a name="l01766"></a>01766             emline[i] = 0. ;
+<a name="l01767"></a>01767         }
+<a name="l01768"></a>01768         <span class="comment">/* determine the coefficients by using the given bcoefs */</span>
+<a name="l01769"></a>01769         <span class="keywordflow">for</span> ( i = 0 ; i < n_fitcoeffs ; i++ )
+<a name="l01770"></a>01770         {
+<a name="l01771"></a>01771             <span class="comment">/* initialize coefficients and solution */</span>
+<a name="l01772"></a>01772             <span class="keywordflow">if</span> (i < n_fitcoeffs-1)
+<a name="l01773"></a>01773             {
+<a name="l01774"></a>01774                 z[2*i] = 0. ;
+<a name="l01775"></a>01775                 z[2*i+1] = 0. ;
+<a name="l01776"></a>01776             }
+<a name="l01777"></a>01777             a[i] = coeffs[i][col] ;
+<a name="l01778"></a>01778         }
+<a name="l01779"></a>01779          
+<a name="l01780"></a>01780         a_initial = coeffs[0][col] ;
+<a name="l01781"></a>01781         <span class="comment">/* go through the lines and generate an artificial spectrum */</span>
+<a name="l01782"></a>01782         <span class="keywordflow">for</span> ( line = 0 ; line < n_lines ; line++ )
+<a name="l01783"></a>01783         {
+<a name="l01784"></a>01784             <span class="comment">/* go from Angstroem to micron */</span>
+<a name="l01785"></a>01785             wave[line] = wavelength[line]/angst ;
+<a name="l01786"></a>01786 
+<a name="l01787"></a>01787             <span class="comment">/* ------------------------------------------------------------</span>
+<a name="l01788"></a>01788 <span class="comment">             * solve the polynomial for the exact offset of the line that means</span>
+<a name="l01789"></a>01789 <span class="comment">             * find the root of the polynomial of order n_fitcoefs - 1</span>
+<a name="l01790"></a>01790 <span class="comment">             */</span>
+<a name="l01791"></a>01791             a[0] = a_initial - wave[line] ;
+<a name="l01792"></a>01792 
+<a name="l01793"></a>01793             <span class="keywordflow">if</span> (NULL==(w=sinfo_gsl_poly_complex_workspace_alloc(n_fitcoeffs))) 
+<a name="l01794"></a>01794             {
+<a name="l01795"></a>01795                 <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" could not allocate complex workspace!"</span>) ;
+<a name="l01796"></a>01796                 cpl_image_delete(wavemap) ;
+<a name="l01797"></a>01797                 <span class="keywordflow">return</span> NULL ;
+<a name="l01798"></a>01798             }
+<a name="l01799"></a>01799             <span class="keywordflow">if</span> (-1 == sinfo_gsl_poly_complex_solve(a, n_fitcoeffs, w, z)) 
+<a name="l01800"></a>01800             {
+<a name="l01801"></a>01801                 <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" sinfo_gsl_poly_complex_solve did not work!"</span>) ;
+<a name="l01802"></a>01802                 cpl_image_delete(wavemap) ;
+<a name="l01803"></a>01803                 <span class="keywordflow">return</span> NULL ;
+<a name="l01804"></a>01804             }
+<a name="l01805"></a>01805             sinfo_gsl_poly_complex_workspace_free(w) ;           
+<a name="l01806"></a>01806 
+<a name="l01807"></a>01807             j = 0 ;
+<a name="l01808"></a>01808             found = -1 ;
+<a name="l01809"></a>01809             <span class="keywordflow">for</span> ( i = 0 ; i < n_fitcoeffs - 1 ; i++ )
+<a name="l01810"></a>01810             {
+<a name="l01811"></a>01811                 <span class="comment">/* test for appropriate solution */</span>
+<a name="l01812"></a>01812                 <span class="keywordflow">if</span>( (z[2*i] > (-1.)*(<span class="keywordtype">float</span>) ily/2. &&
+<a name="l01813"></a>01813                      z[2*i] < (<span class="keywordtype">float</span>)ily/2.) && z[2*i+1] == 0. )
+<a name="l01814"></a>01814                 {
+<a name="l01815"></a>01815                     found = 2*i ;
+<a name="l01816"></a>01816                     j ++ ;
+<a name="l01817"></a>01817                 }
+<a name="l01818"></a>01818                 <span class="keywordflow">else</span>
+<a name="l01819"></a>01819                 {
+<a name="l01820"></a>01820                     continue ;
+<a name="l01821"></a>01821                 }
+<a name="l01822"></a>01822             }
+<a name="l01823"></a>01823             <span class="keywordflow">if</span> ( j == 0 )
+<a name="l01824"></a>01824             {
+<a name="l01825"></a>01825                 <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">" no offset solution found for "</span>
+<a name="l01826"></a>01826                                   <span class="stringliteral">"line %d in column %d\n"</span>, line, col) ;
+<a name="l01827"></a>01827                 continue ;
+<a name="l01828"></a>01828             }
+<a name="l01829"></a>01829             <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( j == 1 )
+<a name="l01830"></a>01830             {
+<a name="l01831"></a>01831                 cenpos = z[found] + (float) ily/2. ;
+<a name="l01832"></a>01832             }
+<a name="l01833"></a>01833             <span class="keywordflow">else</span>
+<a name="l01834"></a>01834             {
+<a name="l01835"></a>01835                 <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">" two or more offset solutions found "</span>
+<a name="l01836"></a>01836                                   <span class="stringliteral">"for line %d in column %d"</span>, line, col) ;
+<a name="l01837"></a>01837                 continue ;
+<a name="l01838"></a>01838             }
+<a name="l01839"></a>01839 
+<a name="l01840"></a>01840             <span class="comment">/*----------------------------------------------------------------</span>
+<a name="l01841"></a>01841 <span class="comment">             * magnify image by the given factor add an additional offset</span>
+<a name="l01842"></a>01842 <span class="comment">             */</span>
+<a name="l01843"></a>01843             cenpix = cenpos ;
+<a name="l01844"></a>01844 
+<a name="l01845"></a>01845             <span class="comment">/* determine max and min pixel limits over which line should </span>
+<a name="l01846"></a>01846 <span class="comment">               be convolved */</span>
+<a name="l01847"></a>01847             cmin = (sinfo_new_nint(cenpix) - (var-1)) > 0 ? 
+<a name="l01848"></a>01848                     sinfo_new_nint(cenpix) - (var-1) : 0 ;
+<a name="l01849"></a>01849             cmax = (sinfo_new_nint(cenpix) + (var-1)) < ily ?
+<a name="l01850"></a>01850                     sinfo_new_nint(cenpix) + (var-1)  : ily ;
+<a name="l01851"></a>01851 
+<a name="l01852"></a>01852             <span class="comment">/* convolve neon lines with Gaussian function */</span>
+<a name="l01853"></a>01853             <span class="keywordflow">for</span> ( j = cmin ; j < cmax ; j++ )
+<a name="l01854"></a>01854             {
+<a name="l01855"></a>01855                 emline[j] += intensity[line] * 
+<a name="l01856"></a>01856                        exp((<span class="keywordtype">double</span>)(-0.5*(j-cenpix)*(j-cenpix))/(<span class="keywordtype">double</span>)var) ;
+<a name="l01857"></a>01857             }
+<a name="l01858"></a>01858         }
+<a name="l01859"></a>01859 
+<a name="l01860"></a>01860         <span class="comment">/*--------------------------------------------------------------------</span>
+<a name="l01861"></a>01861 <span class="comment">         * for each column, map the image data points onto an magFactor times </span>
+<a name="l01862"></a>01862 <span class="comment">           bigger element grid for FFT  in the cross sinfo_correlation, first </span>
+<a name="l01863"></a>01863 <span class="comment">           initialize the two helping arrays for each new column.</span>
+<a name="l01864"></a>01864 <span class="comment">         */</span>
+<a name="l01865"></a>01865         <span class="keywordflow">for</span> ( k = 0 ; k < ily ; k++ )
+<a name="l01866"></a>01866         {
+<a name="l01867"></a>01867             spec[k] = 0. ;
+<a name="l01868"></a>01868         }
+<a name="l01869"></a>01869 
+<a name="l01870"></a>01870         <span class="comment">/* now take the image data points of the column and put them into </span>
+<a name="l01871"></a>01871 <span class="comment">           the spec array */</span>
+<a name="l01872"></a>01872         <span class="keywordflow">for</span> ( row = 0 ; row < ily ; row++ ) <span class="comment">/* go through the column */</span>
+<a name="l01873"></a>01873         {
+<a name="l01874"></a>01874             <span class="comment">/* set bad pixels or negative values to zero */</span>
+<a name="l01875"></a>01875             <span class="keywordflow">if</span> (!isnan(pidata[col + row*ilx]) &&
+<a name="l01876"></a>01876                 (pidata[col + row*ilx] > 0.))
+<a name="l01877"></a>01877             {
+<a name="l01878"></a>01878                 spec[row] = pidata[col + row*ilx] ;
+<a name="l01879"></a>01879             }
+<a name="l01880"></a>01880             <span class="keywordflow">else</span>
+<a name="l01881"></a>01881             {
+<a name="l01882"></a>01882                 spec[row] = 0. ;
+<a name="l01883"></a>01883             }
+<a name="l01884"></a>01884         }
+<a name="l01885"></a>01885         <span class="comment">/* convolve the spectrum by Gaussian */</span>
+<a name="l01886"></a>01886         filter_spec = sinfo_function1d_filter_lowpass(spec,ily, 
+<a name="l01887"></a>01887                                                       LOW_PASS_GAUSSIAN, 
+<a name="l01888"></a>01888                                                       magFactor) ; 
+<a name="l01889"></a>01889 
+<a name="l01890"></a>01890         <span class="comment">/* now call the cross sinfo_correlation routine */</span>
+<a name="l01891"></a>01891         result = sinfo_new_xcorrel( filter_spec, ily, emline, ily,
+<a name="l01892"></a>01892                           ily/2, &delta, &maxlag, &xcorr_max) ;
+<a name="l01893"></a>01893 
+<a name="l01894"></a>01894         <span class="keywordflow">if</span> ( xcorr_max <= 0. )
+<a name="l01895"></a>01895         {
+<a name="l01896"></a>01896             <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"no positive cross sinfo_correlation "</span>
+<a name="l01897"></a>01897                               <span class="stringliteral">"sum , col %d set to ZERO \n"</span>, col) ;
+<a name="l01898"></a>01898             <span class="keywordflow">for</span> ( row = 0 ; row < ily ; row++ )
+<a name="l01899"></a>01899             {
+<a name="l01900"></a>01900                 podata[col + row*ilx] = ZERO ;
+<a name="l01901"></a>01901             }
+<a name="l01902"></a>01902             sinfo_function1d_del(filter_spec) ;
+<a name="l01903"></a>01903             cpl_free(result) ;
+<a name="l01904"></a>01904             continue ;
+<a name="l01905"></a>01905         }
+<a name="l01906"></a>01906 
+<a name="l01907"></a>01907        <span class="comment">/* in this section, we fit the sinfo_correlation function with a gauss, </span>
+<a name="l01908"></a>01908 <span class="comment">          and find its peak, thus getting subpixel-accuracy */</span>
+<a name="l01909"></a>01909 
+<a name="l01910"></a>01910         i = maxlag; j = i+1;
+<a name="l01911"></a>01911         <span class="keywordflow">while</span> (result[j] < result[i])
+<a name="l01912"></a>01912         {
+<a name="l01913"></a>01913             i++; j++;
+<a name="l01914"></a>01914         }
+<a name="l01915"></a>01915         i = maxlag; k = i-1;
+<a name="l01916"></a>01916         <span class="keywordflow">while</span> (result[k] < result[i])
+<a name="l01917"></a>01917         {
+<a name="l01918"></a>01918             i--; k--;
+<a name="l01919"></a>01919         }
+<a name="l01920"></a>01920         width = j-k+1;
+<a name="l01921"></a>01921         <span class="comment">/* allocate memory for the spectral sinfo_vector */</span>
+<a name="l01922"></a>01922         <span class="keywordflow">if</span> ( NULL == (peak = sinfo_new_vector (width)) )
+<a name="l01923"></a>01923         {
+<a name="l01924"></a>01924             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" cannot allocate new Vector \n"</span>) ;
+<a name="l01925"></a>01925             sinfo_function1d_del(filter_spec) ;
+<a name="l01926"></a>01926             cpl_free(result) ;
+<a name="l01927"></a>01927             <span class="keywordflow">return</span> NULL ;
+<a name="l01928"></a>01928         }
+<a name="l01929"></a>01929 
+<a name="l01930"></a>01930 
+<a name="l01931"></a>01931         <span class="comment">/* allocate memory */</span>
+<a name="l01932"></a>01932         xdat = (<span class="keywordtype">float</span> *) cpl_calloc( peak -> n_elements, <span class="keyword">sizeof</span> (<span class="keywordtype">float</span>) ) ;
+<a name="l01933"></a>01933         wdat = (<span class="keywordtype">float</span> *) cpl_calloc( peak -> n_elements, <span class="keyword">sizeof</span> (<span class="keywordtype">float</span>) ) ;
+<a name="l01934"></a>01934         mpar = (<span class="keywordtype">int</span> *)   cpl_calloc( MAXPAR, <span class="keyword">sizeof</span> (<span class="keywordtype">int</span>) ) ;
+<a name="l01935"></a>01935 
+<a name="l01936"></a>01936         <span class="comment">/* determine the values of the spectral sinfo_vector given as input */</span>
+<a name="l01937"></a>01937         <span class="comment">/* go through the chosen column */</span>
+<a name="l01938"></a>01938 
+<a name="l01939"></a>01939         <span class="keywordflow">for</span> ( i = 0 ; i < width ; i++ )
+<a name="l01940"></a>01940         {
+<a name="l01941"></a>01941             peak -> data[i] = result[k+i]/xcorr_max * 100. ;
+<a name="l01942"></a>01942             xdat[i] = i;
+<a name="l01943"></a>01943             wdat[i] = 1.0;
+<a name="l01944"></a>01944         }
+<a name="l01945"></a>01945 
+<a name="l01946"></a>01946         <span class="comment">/* set initial values for the fitting routine */</span>
+<a name="l01947"></a>01947         xdim     = XDIM;
+<a name="l01948"></a>01948         ndat     = peak -> n_elements ;
+<a name="l01949"></a>01949         numpar   = MAXPAR ;
+<a name="l01950"></a>01950         tol      = TOL ;
+<a name="l01951"></a>01951         lab      = LAB ;
+<a name="l01952"></a>01952         its      = ITS ;
+<a name="l01953"></a>01953         par[1] = width/2.0 ;
+<a name="l01954"></a>01954         par[2] = (float) (maxlag - k) ;
+<a name="l01955"></a>01955         par[3] = (peak -> data[0] + peak -> data[peak->n_elements - 1]) / 2.0 ;
+<a name="l01956"></a>01956         par[0]  = result[maxlag]/xcorr_max * 100. - (par[3]) ;
+<a name="l01957"></a>01957 
+<a name="l01958"></a>01958         <span class="keywordflow">for</span> ( i = 0 ; i < MAXPAR ; i++ )
+<a name="l01959"></a>01959         {
+<a name="l01960"></a>01960             derv_par[i] = 0.0 ;
+<a name="l01961"></a>01961             mpar[i] = 1 ;
+<a name="l01962"></a>01962         }
+<a name="l01963"></a>01963 
+<a name="l01964"></a>01964         <span class="comment">/* finally, do the least square fit using a sinfo_gaussian */</span>
+<a name="l01965"></a>01965         <span class="keywordflow">if</span> ( 0 > ( iters = sinfo_new_lsqfit_c( xdat, &xdim, peak -> data, 
+<a name="l01966"></a>01966                                                wdat, &ndat, par, 
+<a name="l01967"></a>01967                                                derv_par, mpar,
+<a name="l01968"></a>01968                                                &numpar, &tol, &its, &lab )) )
+<a name="l01969"></a>01969         {
+<a name="l01970"></a>01970             <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a> (<span class="stringliteral">" sinfo_new_lsqfit_c: least squares fit "</span>
+<a name="l01971"></a>01971                                <span class="stringliteral">"failed in col: %d, error no.: %d"</span>, col, iters);
+<a name="l01972"></a>01972             sinfo_new_destroy_vector ( peak ) ;
+<a name="l01973"></a>01973             cpl_free ( xdat ) ;
+<a name="l01974"></a>01974             cpl_free ( wdat ) ;
+<a name="l01975"></a>01975             cpl_free ( mpar ) ;
+<a name="l01976"></a>01976             sinfo_function1d_del(filter_spec) ;
+<a name="l01977"></a>01977             cpl_free(result) ;
+<a name="l01978"></a>01978             continue ;
+<a name="l01979"></a>01979         }
+<a name="l01980"></a>01980 
+<a name="l01981"></a>01981         sinfo_new_destroy_vector ( peak ) ;
+<a name="l01982"></a>01982         cpl_free (xdat) ;
+<a name="l01983"></a>01983         cpl_free (wdat) ;
+<a name="l01984"></a>01984         cpl_free (mpar) ;
+<a name="l01985"></a>01985         sinfo_function1d_del(filter_spec) ;
+<a name="l01986"></a>01986         cpl_free(result) ;
+<a name="l01987"></a>01987 
+<a name="l01988"></a>01988         wavelag =((float)ily/2 - (<span class="keywordtype">float</span>)k - par[2]) ;
+<a name="l01989"></a>01989 
+<a name="l01990"></a>01990         <span class="keywordflow">if</span> ( fabs(wavelag) > (float)ily/20. )
+<a name="l01991"></a>01991         {
+<a name="l01992"></a>01992             <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"wavelag very big , col %d set to ZERO "</span>, col) ;
+<a name="l01993"></a>01993             <span class="keywordflow">for</span> ( row = 0 ; row < ily ; row++ )
+<a name="l01994"></a>01994             {
+<a name="l01995"></a>01995                 podata[col + row*ilx] = ZERO ;
+<a name="l01996"></a>01996             }
+<a name="l01997"></a>01997             continue ;
+<a name="l01998"></a>01998         }
+<a name="l01999"></a>01999 
+<a name="l02000"></a>02000         <span class="comment">/*--------------------------------------------------------------------</span>
+<a name="l02001"></a>02001 <span class="comment">         * determine new zero order coefficient centreval, of which the </span>
+<a name="l02002"></a>02002 <span class="comment">         * formula is determined by setting equal a polynomial shifted by </span>
+<a name="l02003"></a>02003 <span class="comment">         * wavelag with the same higher order coefficients and set the new </span>
+<a name="l02004"></a>02004 <span class="comment">         * zero order coefficient to get both sides of the equation </span>
+<a name="l02005"></a>02005 <span class="comment">         * approximately equal.</span>
+<a name="l02006"></a>02006 <span class="comment">         */</span>
+<a name="l02007"></a>02007         centreval = a_initial ;
+<a name="l02008"></a>02008         <span class="keywordflow">for</span> ( i = 1 ; i < n_fitcoeffs ; i++ )
+<a name="l02009"></a>02009         {
+<a name="l02010"></a>02010             <span class="keywordflow">if</span> ( i%2 == 0 )
+<a name="l02011"></a>02011             {
+<a name="l02012"></a>02012                 sign = -1 ;
+<a name="l02013"></a>02013             }
+<a name="l02014"></a>02014             <span class="keywordflow">else</span>
+<a name="l02015"></a>02015             {
+<a name="l02016"></a>02016                 sign = 1 ;
+<a name="l02017"></a>02017             }
+<a name="l02018"></a>02018             centreval += (float)sign * coeffs[i][col]*pow(wavelag, i) ;
+<a name="l02019"></a>02019         }
+<a name="l02020"></a>02020         a0[col] = centreval ;
+<a name="l02021"></a>02021     }
+<a name="l02022"></a>02022 
+<a name="l02023"></a>02023     <span class="comment">/* go through the single slitlets */</span>
+<a name="l02024"></a>02024     <span class="keywordflow">for</span> ( ns = 0 ; ns < N_SLITLETS ; ns++ )
+<a name="l02025"></a>02025     {
+<a name="l02026"></a>02026         <span class="comment">/* determine the slitlet edges */</span>
+<a name="l02027"></a>02027         <span class="keywordflow">if</span> ( ns == 0 )
+<a name="l02028"></a>02028         {
+<a name="l02029"></a>02029             ed1 = 0 ;
+<a name="l02030"></a>02030             ed2 = edge[0] ;
+<a name="l02031"></a>02031         }
+<a name="l02032"></a>02032         <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( ns == N_SLITLETS - 1 )
+<a name="l02033"></a>02033         {
+<a name="l02034"></a>02034             ed1 = edge[N_SLITLETS - 2] ;
+<a name="l02035"></a>02035             ed2 = ilx ;
+<a name="l02036"></a>02036         }
+<a name="l02037"></a>02037         <span class="keywordflow">else</span>
+<a name="l02038"></a>02038         {
+<a name="l02039"></a>02039             ed1 = edge[ns-1] ;
+<a name="l02040"></a>02040             ed2 = edge[ns] ;
+<a name="l02041"></a>02041         }
+<a name="l02042"></a>02042 
+<a name="l02043"></a>02043         nc = 0 ;
+<a name="l02044"></a>02044         <span class="keywordflow">for</span> ( i = ed1 ; i < ed2 ; i++ )
+<a name="l02045"></a>02045         {
+<a name="l02046"></a>02046             <span class="keywordflow">if</span> ( isnan(a0[i]) || a0[i] == 0. )
+<a name="l02047"></a>02047             {
+<a name="l02048"></a>02048                 continue ;
+<a name="l02049"></a>02049             }
+<a name="l02050"></a>02050             <span class="keywordflow">else</span>
+<a name="l02051"></a>02051             {
+<a name="l02052"></a>02052                 nc++ ;
+<a name="l02053"></a>02053             }
+<a name="l02054"></a>02054         }
+<a name="l02055"></a>02055         <span class="keywordflow">if</span> ( NULL == (acoefsclean = (<span class="keywordtype">float</span>*) cpl_calloc(nc , <span class="keyword">sizeof</span>(<span class="keywordtype">float</span>))) )
+<a name="l02056"></a>02056         {
+<a name="l02057"></a>02057             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"could not allocate memory for acoefsclean!\n"</span>) ;
+<a name="l02058"></a>02058             <span class="keywordflow">return</span> NULL ;
+<a name="l02059"></a>02059         }
+<a name="l02060"></a>02060         nc = 0 ;
+<a name="l02061"></a>02061         <span class="keywordflow">for</span> ( i = ed1 ; i < ed2 ; i++ )
+<a name="l02062"></a>02062         {
+<a name="l02063"></a>02063             <span class="keywordflow">if</span> ( isnan(a0[i]) || a0[i] == 0. )
+<a name="l02064"></a>02064             {
+<a name="l02065"></a>02065                 continue ;
+<a name="l02066"></a>02066             }
+<a name="l02067"></a>02067             <span class="keywordflow">else</span>
+<a name="l02068"></a>02068             {
+<a name="l02069"></a>02069                 acoefsclean[nc] = a0[i] ;
+<a name="l02070"></a>02070                 nc++ ;
+<a name="l02071"></a>02071             }
+<a name="l02072"></a>02072         }
+<a name="l02073"></a>02073 
+<a name="l02074"></a>02074         <span class="comment">/* ----------------------------------------------------------</span>
+<a name="l02075"></a>02075 <span class="comment">         * determine the clean mean and sigma value of the coefficients,</span>
+<a name="l02076"></a>02076 <span class="comment">         * that means reject 10 % of the extreme low and high values</span>
+<a name="l02077"></a>02077 <span class="comment">         */</span>
+<a name="l02078"></a>02078         sinfo_pixel_qsort(acoefsclean, nc) ;
+<a name="l02079"></a>02079         sum   = 0. ;
+<a name="l02080"></a>02080         sumq  = 0. ;
+<a name="l02081"></a>02081         mean  = 0. ;
+<a name="l02082"></a>02082         sigma = 0. ;
+<a name="l02083"></a>02083         n     = 0 ;
+<a name="l02084"></a>02084         <span class="keywordflow">for</span> ( i = (<span class="keywordtype">int</span>)((<span class="keywordtype">float</span>)nc*LOW_REJECT) ; 
+<a name="l02085"></a>02085               i < (int)((<span class="keywordtype">float</span>)nc*HIGH_REJECT) ; i++ )
+<a name="l02086"></a>02086         {
+<a name="l02087"></a>02087             sum  += (double)acoefsclean[i] ;
+<a name="l02088"></a>02088             sumq += ((double)acoefsclean[i] * (<span class="keywordtype">double</span>)acoefsclean[i]) ;
+<a name="l02089"></a>02089             n ++ ;
+<a name="l02090"></a>02090         }
+<a name="l02091"></a>02091         mean          = sum/(double)n ;
+<a name="l02092"></a>02092         sigma         = sqrt( sumq/(<span class="keywordtype">double</span>)n - (mean * mean) ) ;
+<a name="l02093"></a>02093         cliphi        = mean + sigma * (double)3. ;
+<a name="l02094"></a>02094         cliplo        = mean - sigma * (double)3. ;
+<a name="l02095"></a>02095         <span class="comment">/* fit only the reasonnable values */</span>
+<a name="l02096"></a>02096         num = 0 ;
+<a name="l02097"></a>02097         col_index = 0 ;
+<a name="l02098"></a>02098         <span class="keywordflow">for</span> ( i = ed1 ; i < ed2 ; i++ )
+<a name="l02099"></a>02099         {
+<a name="l02100"></a>02100             <span class="comment">/* take only the reasonnable coefficients */</span>
+<a name="l02101"></a>02101             <span class="keywordflow">if</span> ( !isnan(a0[i]) && (a0[i] <= cliphi) && (a0[i] >= cliplo) &&
+<a name="l02102"></a>02102                  (a0[i] != 0.) )
+<a name="l02103"></a>02103             {
+<a name="l02104"></a>02104                 sub_acoefs[num]    = a0[i] ;
+<a name="l02105"></a>02105                 sub_dacoefs[num]   = 0.0000005 ;
+<a name="l02106"></a>02106                 sub_col_index[num] = col_index ;
+<a name="l02107"></a>02107                 num ++ ;
+<a name="l02108"></a>02108             }
+<a name="l02109"></a>02109             col_index++ ;
+<a name="l02110"></a>02110         }
+<a name="l02111"></a>02111         ndata = num ;
+<a name="l02112"></a>02112         offset2 = (float)(col_index-1) / 2. ;
+<a name="l02113"></a>02113 
+<a name="l02114"></a>02114         <span class="keywordflow">if</span> ( ndata < n_fitcoeffs )
+<a name="l02115"></a>02115         {
+<a name="l02116"></a>02116             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" not enough data found in slitlet %d\</span>
+<a name="l02117"></a>02117 <span class="stringliteral">                    to determine the fit coefficients.\n"</span>, ns) ;
+<a name="l02118"></a>02118             cpl_free(acoefsclean) ;
+<a name="l02119"></a>02119             <span class="keywordflow">return</span> NULL ;
+<a name="l02120"></a>02120         }
+<a name="l02121"></a>02121 
+<a name="l02122"></a>02122         <span class="comment">/* allocate coefficient matrices, see numerical recipe function </span>
+<a name="l02123"></a>02123 <span class="comment">           sinfo_matrix */</span>
+<a name="l02124"></a>02124         ucoefs = sinfo_matrix(1, ndata, 1, n_fitcoeffs) ;
+<a name="l02125"></a>02125         vcoefs = sinfo_matrix(1, ndata, 1, n_fitcoeffs) ;
+<a name="l02126"></a>02126         covar  = sinfo_matrix(1, n_fitcoeffs, 1, n_fitcoeffs) ;
+<a name="l02127"></a>02127 
+<a name="l02128"></a>02128         <span class="comment">/* scale the x-values for the fit */</span>
+<a name="l02129"></a>02129         <span class="keywordflow">for</span> ( i = 0 ; i < ndata ; i++ )
+<a name="l02130"></a>02130         {
+<a name="l02131"></a>02131             sub_col_index[i] = (sub_col_index[i] - offset2) / offset2 ;
+<a name="l02132"></a>02132         }
+<a name="l02133"></a>02133 
+<a name="l02134"></a>02134         <span class="comment">/* finally, do the singular value decomposition fit */</span>
+<a name="l02135"></a>02135         sinfo_svd_fitting ( sub_col_index-1, sub_acoefs-1, 
+<a name="l02136"></a>02136                             sub_dacoefs-1, ndata, bcoef[ns]-1,
+<a name="l02137"></a>02137                             n_fitcoeffs, ucoefs, vcoefs, wcoefs-1, 
+<a name="l02138"></a>02138                             covar, &chisq, sinfo_fpol ) ;
+<a name="l02139"></a>02139 
+<a name="l02140"></a>02140         <span class="comment">/* scale the found coefficients */</span>
+<a name="l02141"></a>02141         <span class="keywordflow">for</span> ( i = 0 ; i < n_fitcoeffs ; i ++ )
+<a name="l02142"></a>02142         {
+<a name="l02143"></a>02143             bcoef[ns][i] /= pow( offset2, i ) ;
+<a name="l02144"></a>02144         }
+<a name="l02145"></a>02145 
+<a name="l02146"></a>02146         <span class="comment">/* free memory */</span>
+<a name="l02147"></a>02147         cpl_free (acoefsclean) ;
+<a name="l02148"></a>02148         sinfo_free_matrix( ucoefs, 1<span class="comment">/*, ndata*/</span>, 1<span class="comment">/*, n_fitcoeffs */</span>) ;
+<a name="l02149"></a>02149         sinfo_free_matrix( vcoefs, 1<span class="comment">/*, ndata*/</span>, 1<span class="comment">/*, n_fitcoeffs */</span>) ;
+<a name="l02150"></a>02150         sinfo_free_matrix( covar, 1<span class="comment">/*, n_fitcoeffs*/</span>, 1<span class="comment">/*, n_fitcoeffs*/</span>) ;
+<a name="l02151"></a>02151 
+<a name="l02152"></a>02152         <span class="comment">/* now calculate the smoothed acoefs for each column */</span>
+<a name="l02153"></a>02153         col_index = 0 ;
+<a name="l02154"></a>02154         <span class="keywordflow">for</span> ( i = ed1 ; i < ed2 ; i++ )
+<a name="l02155"></a>02155         {
+<a name="l02156"></a>02156             a0_clean[i] = 0. ;
+<a name="l02157"></a>02157             <span class="keywordflow">for</span> ( n = 0 ; n < n_fitcoeffs ; n++ )
+<a name="l02158"></a>02158             {
+<a name="l02159"></a>02159               a0_clean[i] += bcoef[ns][n] * 
+<a name="l02160"></a>02160                              pow((<span class="keywordtype">float</span>)col_index - offset2, n) ;
+<a name="l02161"></a>02161             }
+<a name="l02162"></a>02162             col_index++ ;
+<a name="l02163"></a>02163         }
+<a name="l02164"></a>02164 
+<a name="l02165"></a>02165     }
+<a name="l02166"></a>02166 
+<a name="l02167"></a>02167     <span class="keywordflow">for</span> ( col = 0 ; col < ilx ; col++ )
+<a name="l02168"></a>02168     {
+<a name="l02169"></a>02169         <span class="comment">/* prepare to write out wavelength as pixel values */</span>
+<a name="l02170"></a>02170         <span class="keywordflow">for</span> ( row = 0 ; row < oly ; row++ )
+<a name="l02171"></a>02171         {
+<a name="l02172"></a>02172             centrepix = (float)row - ((<span class="keywordtype">float</span>)oly - 1.)/2. ;
+<a name="l02173"></a>02173             pixvalue = 0. ;
+<a name="l02174"></a>02174             <span class="keywordflow">for</span> ( i = 1 ; i < n_fitcoeffs ; i++ )
+<a name="l02175"></a>02175             {
+<a name="l02176"></a>02176                 pixvalue += coeffs[i][col]*pow(centrepix, i) ;
+<a name="l02177"></a>02177             }
+<a name="l02178"></a>02178             podata[col+row*olx] = a0_clean[col] + pixvalue ;
+<a name="l02179"></a>02179         }
+<a name="l02180"></a>02180     }
+<a name="l02181"></a>02181 
+<a name="l02182"></a>02182 
+<a name="l02183"></a>02183     cpl_free(emline) ;
+<a name="l02184"></a>02184     cpl_free(spec) ;
+<a name="l02185"></a>02185     cpl_free(wave) ;
+<a name="l02186"></a>02186     cpl_free(a0) ;
+<a name="l02187"></a>02187     cpl_free(a0_clean) ;
+<a name="l02188"></a>02188 
+<a name="l02189"></a>02189 
+<a name="l02190"></a>02190     cpl_free(sub_col_index) ;
+<a name="l02191"></a>02191     cpl_free(sub_acoefs);
+<a name="l02192"></a>02192     cpl_free(sub_dacoefs) ;
+<a name="l02193"></a>02193 
+<a name="l02194"></a>02194     cpl_free(a) ;
+<a name="l02195"></a>02195     cpl_free(z) ;
+<a name="l02196"></a>02196 
+<a name="l02197"></a>02197     sinfo_new_destroy_2Dfloatarray(&bcoef,n_fitcoeffs) ;
+<a name="l02198"></a>02198     cpl_free(wcoefs) ;
+<a name="l02199"></a>02199 
+<a name="l02200"></a>02200     <span class="keywordflow">return</span> wavemap ;
+<a name="l02201"></a>02201 }
+<a name="l02202"></a>02202 
+<a name="l02226"></a>02226 cpl_image * sinfo_new_create_shifted_slit_wavemap3 ( cpl_image * lineIm,
+<a name="l02227"></a>02227                               <span class="keywordtype">float</span>    ** coeffs,
+<a name="l02228"></a>02228                           <span class="keywordtype">int</span>      n_fitcoeffs,
+<a name="l02229"></a>02229                                       <span class="keywordtype">float</span>  * wavelength,
+<a name="l02230"></a>02230                                       <span class="keywordtype">float</span>  * intensity,
+<a name="l02231"></a>02231                                       <span class="keywordtype">int</span>      n_lines,
+<a name="l02232"></a>02232                                       <span class="keywordtype">int</span>      magFactor )
+<a name="l02233"></a>02233 {
+<a name="l02234"></a>02234 
+<a name="l02235"></a>02235     cpl_image * wavemap ;
+<a name="l02236"></a>02236     <span class="keywordtype">double</span> * result ;
+<a name="l02237"></a>02237     <span class="keywordtype">float</span> * filter_spec ;
+<a name="l02238"></a>02238     <span class="keywordtype">float</span> centreval ;
+<a name="l02239"></a>02239     <span class="keywordtype">float</span> centrepix ;
+<a name="l02240"></a>02240     <span class="keywordtype">float</span> cenpos, cenpix ;
+<a name="l02241"></a>02241     <span class="keywordtype">float</span> pixvalue ;
+<a name="l02242"></a>02242     <span class="keywordtype">float</span> wavelag_mean ;
+<a name="l02243"></a>02243     <span class="comment">/*float maxres ;*/</span>
+<a name="l02244"></a>02244     <span class="keywordtype">float</span> angst ;
+<a name="l02245"></a>02245     <span class="comment">/*float temp ;*/</span>
+<a name="l02246"></a>02246     <span class="keywordtype">float</span> a_initial ;
+<a name="l02247"></a>02247     <span class="comment">/*float solution[n_fitcoeffs-1], im_solution[n_fitcoeffs-1] ;*/</span>
+<a name="l02248"></a>02248 
+<a name="l02249"></a>02249     <span class="keywordtype">float</span> par[MAXPAR] ;
+<a name="l02250"></a>02250     <span class="keywordtype">float</span> derv_par[MAXPAR] ;
+<a name="l02251"></a>02251     <span class="keywordtype">int</span>        numpar, its ;
+<a name="l02252"></a>02252     <span class="keywordtype">int</span>        * mpar ;
+<a name="l02253"></a>02253     <span class="keywordtype">float</span>      tol, lab ;
+<a name="l02254"></a>02254     <span class="keywordtype">float</span>      * xdat, * wdat ;
+<a name="l02255"></a>02255     Vector     * peak;
+<a name="l02256"></a>02256     <span class="keywordtype">int</span>   iters, xdim, ndat ;
+<a name="l02257"></a>02257     <span class="keywordtype">int</span>   row , col ;
+<a name="l02258"></a>02258     <span class="keywordtype">int</span>   i, j, k<span class="comment">/*, l, m, n*/</span> ;
+<a name="l02259"></a>02259     <span class="keywordtype">int</span>   sign, found, line, width ;
+<a name="l02260"></a>02260     <span class="keywordtype">int</span> var, maxlag, cmin, cmax ;
+<a name="l02261"></a>02261 
+<a name="l02262"></a>02262     <span class="keywordtype">float</span>* emline=NULL ;
+<a name="l02263"></a>02263     <span class="keywordtype">float</span>* spec=NULL ;
+<a name="l02264"></a>02264     <span class="keywordtype">float</span>* wavelag=NULL ;
+<a name="l02265"></a>02265     <span class="keywordtype">float</span>* wave=NULL ;
+<a name="l02266"></a>02266     <span class="keywordtype">double</span>* a=NULL ;
+<a name="l02267"></a>02267     <span class="keywordtype">double</span>* z=NULL ;
+<a name="l02268"></a>02268 
+<a name="l02269"></a>02269     gsl_poly_complex_workspace * w ;
+<a name="l02270"></a>02270     <span class="keywordtype">double</span> xcorr_max ;
+<a name="l02271"></a>02271     <span class="keywordtype">int</span> delta ;
+<a name="l02272"></a>02272     
+<a name="l02273"></a>02273     <span class="keywordtype">int</span> ilx=0;
+<a name="l02274"></a>02274     <span class="keywordtype">int</span> ily=0;
+<a name="l02275"></a>02275     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l02276"></a>02276     <span class="keywordtype">int</span> olx=0;
+<a name="l02277"></a>02277     <span class="keywordtype">int</span> oly=0;
+<a name="l02278"></a>02278     <span class="keywordtype">float</span>* podata=NULL;
+<a name="l02279"></a>02279 
+<a name="l02280"></a>02280 
+<a name="l02281"></a>02281 
+<a name="l02282"></a>02282     <span class="keywordflow">if</span> ( lineIm == NULL )
+<a name="l02283"></a>02283     {
+<a name="l02284"></a>02284         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" no input image given!\n"</span>) ;
+<a name="l02285"></a>02285         <span class="keywordflow">return</span> NULL ;
+<a name="l02286"></a>02286     }
+<a name="l02287"></a>02287     ilx=cpl_image_get_size_x(lineIm);
+<a name="l02288"></a>02288     ily=cpl_image_get_size_y(lineIm);
+<a name="l02289"></a>02289     pidata=cpl_image_get_data_float(lineIm);
+<a name="l02290"></a>02290 
+<a name="l02291"></a>02291     <span class="keywordflow">if</span> ( coeffs == NULL )
+<a name="l02292"></a>02292     {
+<a name="l02293"></a>02293         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" no coefficient sinfo_matrix given!\n"</span>) ;
+<a name="l02294"></a>02294         <span class="keywordflow">return</span> NULL ;
+<a name="l02295"></a>02295     }
+<a name="l02296"></a>02296     <span class="keywordflow">if</span> ( n_fitcoeffs < 2 )
+<a name="l02297"></a>02297     {
+<a name="l02298"></a>02298         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" wrong number of polynomial coefficients given!\n"</span>) ;
+<a name="l02299"></a>02299         <span class="keywordflow">return</span> NULL ;
+<a name="l02300"></a>02300     }
+<a name="l02301"></a>02301 
+<a name="l02302"></a>02302     <span class="keywordflow">if</span> ( wavelength == NULL || intensity == NULL )
+<a name="l02303"></a>02303     {
+<a name="l02304"></a>02304         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" no wavelength list given!\n"</span>) ;
+<a name="l02305"></a>02305         <span class="keywordflow">return</span> NULL ;
+<a name="l02306"></a>02306     }
+<a name="l02307"></a>02307     <span class="keywordflow">if</span> ( n_lines < 1 || magFactor < 1 )
+<a name="l02308"></a>02308     {
+<a name="l02309"></a>02309         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" wrong n_lines or magFactor given!\n"</span>) ;
+<a name="l02310"></a>02310         <span class="keywordflow">return</span> NULL ;
+<a name="l02311"></a>02311     }
+<a name="l02312"></a>02312     
+<a name="l02313"></a>02313     var    = (magFactor - 1)*(magFactor - 1) ;
+<a name="l02314"></a>02314     <span class="comment">/* find out if Angstroem or microns are used */</span>
+<a name="l02315"></a>02315     <span class="keywordflow">if</span> ( wavelength[0] > 10000. )
+<a name="l02316"></a>02316     {
+<a name="l02317"></a>02317         <span class="comment">/* Angstroem */</span>
+<a name="l02318"></a>02318         angst = 10000. ;
+<a name="l02319"></a>02319     }
+<a name="l02320"></a>02320     <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( wavelength[0] > 1000. && wavelength[0] < 10000. )
+<a name="l02321"></a>02321     {
+<a name="l02322"></a>02322         <span class="comment">/* nanometers */</span>
+<a name="l02323"></a>02323         angst = 1000. ;
+<a name="l02324"></a>02324     }
+<a name="l02325"></a>02325     <span class="keywordflow">else</span>
+<a name="l02326"></a>02326     {
+<a name="l02327"></a>02327         <span class="comment">/* microns */</span>
+<a name="l02328"></a>02328         angst = 1. ;
+<a name="l02329"></a>02329     }
+<a name="l02330"></a>02330 
+<a name="l02331"></a>02331 
+<a name="l02332"></a>02332 
+<a name="l02333"></a>02333     <span class="comment">/* allocate memory */</span>
+<a name="l02334"></a>02334     <span class="keywordflow">if</span> ( NULL == (wavemap = cpl_image_new ( ilx, ily,CPL_TYPE_FLOAT)) )
+<a name="l02335"></a>02335     {
+<a name="l02336"></a>02336         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" could not allocate memory!\n"</span>) ;
+<a name="l02337"></a>02337         <span class="keywordflow">return</span> NULL ;
+<a name="l02338"></a>02338     }
+<a name="l02339"></a>02339     podata=cpl_image_get_data_float(lineIm);
+<a name="l02340"></a>02340     olx=ilx;
+<a name="l02341"></a>02341     oly=ily;
+<a name="l02342"></a>02342 
+<a name="l02343"></a>02343     emline=cpl_calloc(ily,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l02344"></a>02344     spec=cpl_calloc(ily,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l02345"></a>02345     wavelag=cpl_calloc(ilx,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l02346"></a>02346     wave=cpl_calloc(n_lines,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l02347"></a>02347     a=cpl_calloc(n_fitcoeffs,<span class="keyword">sizeof</span>(<span class="keywordtype">double</span>)) ;
+<a name="l02348"></a>02348     z=cpl_calloc(2*(n_fitcoeffs - 1),<span class="keyword">sizeof</span>(<span class="keywordtype">double</span>)) ;
+<a name="l02349"></a>02349 
+<a name="l02350"></a>02350     
+<a name="l02351"></a>02351     <span class="comment">/* first store each spectrum in a buffer */</span>
+<a name="l02352"></a>02352     <span class="keywordflow">for</span> ( col = 0 ; col < ilx ; col++ )
+<a name="l02353"></a>02353     {
+<a name="l02354"></a>02354         <span class="comment">/* initialize the emline array for each column */</span>
+<a name="l02355"></a>02355         <span class="keywordflow">for</span> ( i = 0 ; i < ily ; i++ )
+<a name="l02356"></a>02356         {
+<a name="l02357"></a>02357             emline[i] = 0. ;
+<a name="l02358"></a>02358         }
+<a name="l02359"></a>02359         <span class="comment">/* determine the coefficients by using the given bcoefs */</span>
+<a name="l02360"></a>02360         <span class="keywordflow">for</span> ( i = 0 ; i < n_fitcoeffs ; i++ )
+<a name="l02361"></a>02361         {
+<a name="l02362"></a>02362             <span class="comment">/* initialize coefficients and solution */</span>
+<a name="l02363"></a>02363             <span class="keywordflow">if</span> (i < n_fitcoeffs-1)
+<a name="l02364"></a>02364             {
+<a name="l02365"></a>02365                 z[2*i] = 0. ;
+<a name="l02366"></a>02366                 z[2*i+1] = 0. ;
+<a name="l02367"></a>02367             }
+<a name="l02368"></a>02368             a[i] = coeffs[i][col] ;
+<a name="l02369"></a>02369         }
+<a name="l02370"></a>02370          
+<a name="l02371"></a>02371         a_initial = coeffs[0][col] ;
+<a name="l02372"></a>02372         <span class="comment">/* go through the lines and generate an artificial spectrum */</span>
+<a name="l02373"></a>02373         <span class="keywordflow">for</span> ( line = 0 ; line < n_lines ; line++ )
+<a name="l02374"></a>02374         {
+<a name="l02375"></a>02375             <span class="comment">/* go from Angstroem to micron */</span>
+<a name="l02376"></a>02376             wave[line] = wavelength[line]/angst ;
+<a name="l02377"></a>02377 
+<a name="l02378"></a>02378             <span class="comment">/* ----------------------------------------------------------------</span>
+<a name="l02379"></a>02379 <span class="comment">             * solve the polynomial for the exact offset of the line that means</span>
+<a name="l02380"></a>02380 <span class="comment">             * find the root of the polynomial of order n_fitcoefs - 1</span>
+<a name="l02381"></a>02381 <span class="comment">             */</span>
+<a name="l02382"></a>02382             a[0] = a_initial - wave[line] ;
+<a name="l02383"></a>02383 
+<a name="l02384"></a>02384             <span class="keywordflow">if</span> (NULL==(w=sinfo_gsl_poly_complex_workspace_alloc(n_fitcoeffs))) 
+<a name="l02385"></a>02385             {
+<a name="l02386"></a>02386                 <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" could not allocate complex workspace!"</span>) ;
+<a name="l02387"></a>02387                 cpl_image_delete(wavemap) ;
+<a name="l02388"></a>02388                 <span class="keywordflow">return</span> NULL ;
+<a name="l02389"></a>02389             }
+<a name="l02390"></a>02390             <span class="keywordflow">if</span> (-1 == sinfo_gsl_poly_complex_solve(a, n_fitcoeffs, w, z)) 
+<a name="l02391"></a>02391             {
+<a name="l02392"></a>02392                 <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"sinfo_gsl_poly_complex_solve did not work!"</span>) ;
+<a name="l02393"></a>02393                 cpl_image_delete(wavemap) ;
+<a name="l02394"></a>02394                 <span class="keywordflow">return</span> NULL ;
+<a name="l02395"></a>02395             }
+<a name="l02396"></a>02396             sinfo_gsl_poly_complex_workspace_free(w) ;           
+<a name="l02397"></a>02397 
+<a name="l02398"></a>02398             j = 0 ;
+<a name="l02399"></a>02399             found = -1 ;
+<a name="l02400"></a>02400             <span class="keywordflow">for</span> ( i = 0 ; i < n_fitcoeffs - 1 ; i++ )
+<a name="l02401"></a>02401             {
+<a name="l02402"></a>02402                 <span class="comment">/* test for appropriate solution */</span>
+<a name="l02403"></a>02403                 <span class="keywordflow">if</span>( (z[2*i] > (-1.)*(<span class="keywordtype">float</span>) ily/2. &&
+<a name="l02404"></a>02404                      z[2*i] < (<span class="keywordtype">float</span>)ily/2.) && z[2*i+1] == 0. )
+<a name="l02405"></a>02405                 {
+<a name="l02406"></a>02406                     found = 2*i ;
+<a name="l02407"></a>02407                     j ++ ;
+<a name="l02408"></a>02408                 }
+<a name="l02409"></a>02409                 <span class="keywordflow">else</span>
+<a name="l02410"></a>02410                 {
+<a name="l02411"></a>02411                     continue ;
+<a name="l02412"></a>02412                 }
+<a name="l02413"></a>02413             }
+<a name="l02414"></a>02414             <span class="keywordflow">if</span> ( j == 0 )
+<a name="l02415"></a>02415             {
+<a name="l02416"></a>02416                 <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"no offset solution found for line %d "</span>
+<a name="l02417"></a>02417                                   <span class="stringliteral">"in column %d\n"</span>, line, col) ;
+<a name="l02418"></a>02418                 continue ;
+<a name="l02419"></a>02419             }
+<a name="l02420"></a>02420             <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( j == 1 )
+<a name="l02421"></a>02421             {
+<a name="l02422"></a>02422                 cenpos = z[found] + (float) ily /2. ;
+<a name="l02423"></a>02423             }
+<a name="l02424"></a>02424             <span class="keywordflow">else</span>
+<a name="l02425"></a>02425             {
+<a name="l02426"></a>02426                 <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"two or more offset solutions found for "</span>
+<a name="l02427"></a>02427                                   <span class="stringliteral">"line %d in column %d\n"</span>, line, col) ;
+<a name="l02428"></a>02428                 continue ;
+<a name="l02429"></a>02429             }
+<a name="l02430"></a>02430 
+<a name="l02431"></a>02431             <span class="comment">/*-----------------------------------------------------------------</span>
+<a name="l02432"></a>02432 <span class="comment">             * magnify image by the given factor add an additional offset</span>
+<a name="l02433"></a>02433 <span class="comment">             */</span>
+<a name="l02434"></a>02434             cenpix = cenpos ;
+<a name="l02435"></a>02435 
+<a name="l02436"></a>02436             <span class="comment">/* determine max and min pixel limits over which </span>
+<a name="l02437"></a>02437 <span class="comment">               line should be convolved */</span>
+<a name="l02438"></a>02438             cmin = (sinfo_new_nint(cenpix) - (var-1)) > 0 ? 
+<a name="l02439"></a>02439                     sinfo_new_nint(cenpix) - (var-1) : 0 ;
+<a name="l02440"></a>02440             cmax = (sinfo_new_nint(cenpix) + (var-1)) < ily ?
+<a name="l02441"></a>02441                     sinfo_new_nint(cenpix) + (var-1)  : ily ;
+<a name="l02442"></a>02442 
+<a name="l02443"></a>02443             <span class="comment">/* convolve neon lines with Gaussian function */</span>
+<a name="l02444"></a>02444             <span class="keywordflow">for</span> ( j = cmin ; j < cmax ; j++ )
+<a name="l02445"></a>02445             {
+<a name="l02446"></a>02446                 emline[j] += intensity[line] * 
+<a name="l02447"></a>02447                         exp((<span class="keywordtype">double</span>)(-0.5*(j-cenpix)*(j-cenpix))/(<span class="keywordtype">double</span>)var) ;
+<a name="l02448"></a>02448             }
+<a name="l02449"></a>02449         }
+<a name="l02450"></a>02450 
+<a name="l02451"></a>02451         <span class="comment">/*--------------------------------------------------------------------</span>
+<a name="l02452"></a>02452 <span class="comment">         * for each column, map the image data points onto an magFactor times </span>
+<a name="l02453"></a>02453 <span class="comment">           bigger element grid for FFT in the cross sinfo_correlation, first </span>
+<a name="l02454"></a>02454 <span class="comment">           initialize the two helping arrays for each new column.</span>
+<a name="l02455"></a>02455 <span class="comment">         */</span>
+<a name="l02456"></a>02456         <span class="keywordflow">for</span> ( k = 0 ; k < ily ; k++ )
+<a name="l02457"></a>02457         {
+<a name="l02458"></a>02458             spec[k] = 0. ;
+<a name="l02459"></a>02459         }
+<a name="l02460"></a>02460 
+<a name="l02461"></a>02461         <span class="comment">/* now take the image data points of the column and put them into </span>
+<a name="l02462"></a>02462 <span class="comment">           the spec array */</span>
+<a name="l02463"></a>02463         <span class="keywordflow">for</span> ( row = 0 ; row < ily ; row++ ) <span class="comment">/* go through the column */</span>
+<a name="l02464"></a>02464         {
+<a name="l02465"></a>02465             <span class="comment">/* set bad pixels or negative values to zero */</span>
+<a name="l02466"></a>02466             <span class="keywordflow">if</span> (!isnan(pidata[col + row*ilx]) &&
+<a name="l02467"></a>02467                             (pidata[col + row*ilx] > 0.))
+<a name="l02468"></a>02468             {
+<a name="l02469"></a>02469                 spec[row] = pidata[col + row*ilx] ;
+<a name="l02470"></a>02470             }
+<a name="l02471"></a>02471             <span class="keywordflow">else</span>
+<a name="l02472"></a>02472             {
+<a name="l02473"></a>02473                 spec[row] = 0. ;
+<a name="l02474"></a>02474             }
+<a name="l02475"></a>02475         }
+<a name="l02476"></a>02476         <span class="comment">/* convolve the spectrum by Gaussian */</span>
+<a name="l02477"></a>02477         filter_spec = sinfo_function1d_filter_lowpass(spec, ily, 
+<a name="l02478"></a>02478                                                       LOW_PASS_GAUSSIAN, 
+<a name="l02479"></a>02479                                                       magFactor) ; 
+<a name="l02480"></a>02480 
+<a name="l02481"></a>02481         <span class="comment">/* now call the cross sinfo_correlation routine */</span>
+<a name="l02482"></a>02482         result = sinfo_new_xcorrel( filter_spec, ily, emline, ily,
+<a name="l02483"></a>02483                           ily/2, &delta, &maxlag, &xcorr_max) ;
+<a name="l02484"></a>02484 
+<a name="l02485"></a>02485         <span class="keywordflow">if</span> ( xcorr_max <= 0. )
+<a name="l02486"></a>02486         {
+<a name="l02487"></a>02487             <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"no positive cross correlation sum , "</span>
+<a name="l02488"></a>02488                               <span class="stringliteral">"col %d set to ZERO \n"</span>, col) ;
+<a name="l02489"></a>02489             <span class="keywordflow">for</span> ( row = 0 ; row < ily ; row++ )
+<a name="l02490"></a>02490             {
+<a name="l02491"></a>02491                 podata[col + row*ilx] = ZERO ;
+<a name="l02492"></a>02492             }
+<a name="l02493"></a>02493             sinfo_function1d_del(filter_spec) ;
+<a name="l02494"></a>02494             cpl_free(result) ;
+<a name="l02495"></a>02495             continue ;
+<a name="l02496"></a>02496         }
+<a name="l02497"></a>02497 
+<a name="l02498"></a>02498        <span class="comment">/* in this section, we fit the sinfo_correlation function with a </span>
+<a name="l02499"></a>02499 <span class="comment">           gauss, and find its peak, thus getting subpixel-accuracy */</span>
+<a name="l02500"></a>02500 
+<a name="l02501"></a>02501         i = maxlag; j = i+1;
+<a name="l02502"></a>02502         <span class="keywordflow">while</span> (result[j] < result[i])
+<a name="l02503"></a>02503         {
+<a name="l02504"></a>02504             i++; j++;
+<a name="l02505"></a>02505         }
+<a name="l02506"></a>02506         i = maxlag; k = i-1;
+<a name="l02507"></a>02507         <span class="keywordflow">while</span> (result[k] < result[i])
+<a name="l02508"></a>02508         {
+<a name="l02509"></a>02509             i--; k--;
+<a name="l02510"></a>02510         }
+<a name="l02511"></a>02511         width = j-k+1;
+<a name="l02512"></a>02512         <span class="comment">/* allocate memory for the spectral sinfo_vector */</span>
+<a name="l02513"></a>02513         <span class="keywordflow">if</span> ( NULL == (peak = sinfo_new_vector (width)) )
+<a name="l02514"></a>02514         {
+<a name="l02515"></a>02515             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" cannot allocate new Vector \n"</span>) ;
+<a name="l02516"></a>02516             sinfo_function1d_del(filter_spec) ;
+<a name="l02517"></a>02517             cpl_free(result) ;
+<a name="l02518"></a>02518             <span class="keywordflow">return</span> NULL ;
+<a name="l02519"></a>02519         }
+<a name="l02520"></a>02520 
+<a name="l02521"></a>02521 
+<a name="l02522"></a>02522         <span class="comment">/* allocate memory */</span>
+<a name="l02523"></a>02523         xdat = (<span class="keywordtype">float</span> *) cpl_calloc( peak -> n_elements, <span class="keyword">sizeof</span> (<span class="keywordtype">float</span>) ) ;
+<a name="l02524"></a>02524         wdat = (<span class="keywordtype">float</span> *) cpl_calloc( peak -> n_elements, <span class="keyword">sizeof</span> (<span class="keywordtype">float</span>) ) ;
+<a name="l02525"></a>02525         mpar = (<span class="keywordtype">int</span> *)   cpl_calloc( MAXPAR, <span class="keyword">sizeof</span> (<span class="keywordtype">int</span>) ) ;
+<a name="l02526"></a>02526 
+<a name="l02527"></a>02527         <span class="comment">/* determine the values of the spectral sinfo_vector given as input */</span>
+<a name="l02528"></a>02528         <span class="comment">/* go through the chosen column */</span>
+<a name="l02529"></a>02529 
+<a name="l02530"></a>02530         <span class="keywordflow">for</span> ( i = 0 ; i < width ; i++ )
+<a name="l02531"></a>02531         {
+<a name="l02532"></a>02532             peak -> data[i] = result[k+i]/xcorr_max * 100. ;
+<a name="l02533"></a>02533             xdat[i] = i;
+<a name="l02534"></a>02534             wdat[i] = 1.0;
+<a name="l02535"></a>02535         }
+<a name="l02536"></a>02536 
+<a name="l02537"></a>02537         <span class="comment">/* set initial values for the fitting routine */</span>
+<a name="l02538"></a>02538         xdim     = XDIM;
+<a name="l02539"></a>02539         ndat     = peak -> n_elements ;
+<a name="l02540"></a>02540         numpar   = MAXPAR ;
+<a name="l02541"></a>02541         tol      = TOL ;
+<a name="l02542"></a>02542         lab      = LAB ;
+<a name="l02543"></a>02543         its      = ITS ;
+<a name="l02544"></a>02544         par[1] = width/2.0 ;
+<a name="l02545"></a>02545         par[2] = (float) (maxlag - k) ;
+<a name="l02546"></a>02546         par[3] = (peak -> data[0] + peak -> data[peak->n_elements - 1]) / 2.0 ;
+<a name="l02547"></a>02547         par[0]  = result[maxlag]/xcorr_max * 100. - (par[3]) ;
+<a name="l02548"></a>02548 
+<a name="l02549"></a>02549         <span class="keywordflow">for</span> ( i = 0 ; i < MAXPAR ; i++ )
+<a name="l02550"></a>02550         {
+<a name="l02551"></a>02551             derv_par[i] = 0.0 ;
+<a name="l02552"></a>02552             mpar[i] = 1 ;
+<a name="l02553"></a>02553         }
+<a name="l02554"></a>02554 
+<a name="l02555"></a>02555         <span class="comment">/* finally, do the least square fit using a sinfo_gaussian */</span>
+<a name="l02556"></a>02556         <span class="keywordflow">if</span> ( 0 > ( iters = sinfo_new_lsqfit_c( xdat, &xdim, 
+<a name="l02557"></a>02557                                                peak -> data, wdat, 
+<a name="l02558"></a>02558                                                &ndat, par, derv_par, mpar,
+<a name="l02559"></a>02559                                                &numpar, &tol, &its, &lab )) )
+<a name="l02560"></a>02560         {
+<a name="l02561"></a>02561             <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a> (<span class="stringliteral">" sinfo_new_lsqfit_c: least squares fit"</span>
+<a name="l02562"></a>02562                                <span class="stringliteral">" failed in col: %d, error no.: %d\n"</span>, 
+<a name="l02563"></a>02563                                col, iters) ;
+<a name="l02564"></a>02564             sinfo_new_destroy_vector ( peak ) ;
+<a name="l02565"></a>02565             cpl_free ( xdat ) ;
+<a name="l02566"></a>02566             cpl_free ( wdat ) ;
+<a name="l02567"></a>02567             cpl_free ( mpar ) ;
+<a name="l02568"></a>02568             sinfo_function1d_del(filter_spec) ;
+<a name="l02569"></a>02569             cpl_free(result) ;
+<a name="l02570"></a>02570             continue ;
+<a name="l02571"></a>02571         }
+<a name="l02572"></a>02572 
+<a name="l02573"></a>02573         sinfo_new_destroy_vector ( peak ) ;
+<a name="l02574"></a>02574         cpl_free (xdat) ;
+<a name="l02575"></a>02575         cpl_free (wdat) ;
+<a name="l02576"></a>02576         cpl_free (mpar) ;
+<a name="l02577"></a>02577         sinfo_function1d_del(filter_spec) ;
+<a name="l02578"></a>02578         cpl_free(result) ;
+<a name="l02579"></a>02579 
+<a name="l02580"></a>02580         wavelag[col] =((float)ily/2 - (<span class="keywordtype">float</span>)k - par[2]) ;
+<a name="l02581"></a>02581 
+<a name="l02582"></a>02582     }
+<a name="l02583"></a>02583     
+<a name="l02584"></a>02584     <span class="keywordflow">if</span> (FLT_MAX==(wavelag_mean=sinfo_new_clean_mean(wavelag, ilx, 10., 10.)) )
+<a name="l02585"></a>02585     {
+<a name="l02586"></a>02586         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" could not determine a mean offset\n"</span>) ;
+<a name="l02587"></a>02587         <span class="keywordflow">return</span> NULL ;
+<a name="l02588"></a>02588     }
+<a name="l02589"></a>02589 
+<a name="l02590"></a>02590     <span class="keywordflow">if</span> ( fabs(wavelag_mean) > (<span class="keywordtype">float</span>)ily/20. )
+<a name="l02591"></a>02591     {
+<a name="l02592"></a>02592         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" wavelag too big \n"</span>) ;
+<a name="l02593"></a>02593         <span class="keywordflow">return</span> NULL ;
+<a name="l02594"></a>02594     }
+<a name="l02595"></a>02595 
+<a name="l02596"></a>02596     
+<a name="l02597"></a>02597 
+<a name="l02598"></a>02598     <span class="keywordflow">for</span> ( col = 0 ; col < ilx ; col++ )
+<a name="l02599"></a>02599     {
+<a name="l02600"></a>02600         <span class="comment">/*--------------------------------------------------------------------</span>
+<a name="l02601"></a>02601 <span class="comment">         * determine new zero order coefficient centreval, of which the </span>
+<a name="l02602"></a>02602 <span class="comment">         * formula is determined by setting equal a polynomial shifted by </span>
+<a name="l02603"></a>02603 <span class="comment">         * wavelag with the same higher order coefficients and set the new </span>
+<a name="l02604"></a>02604 <span class="comment">         * zero order coefficient to get both sides of the equation </span>
+<a name="l02605"></a>02605 <span class="comment">         * approximately equal.</span>
+<a name="l02606"></a>02606 <span class="comment">         */</span>
+<a name="l02607"></a>02607         a_initial = coeffs[0][col] ;
+<a name="l02608"></a>02608     centreval = a_initial ;
+<a name="l02609"></a>02609     <span class="keywordflow">for</span> ( i = 1 ; i < n_fitcoeffs ; i++ )
+<a name="l02610"></a>02610         {
+<a name="l02611"></a>02611             <span class="keywordflow">if</span> ( i%2 == 0 )
+<a name="l02612"></a>02612             {
+<a name="l02613"></a>02613                 sign = -1 ;
+<a name="l02614"></a>02614             }
+<a name="l02615"></a>02615             <span class="keywordflow">else</span>
+<a name="l02616"></a>02616             {
+<a name="l02617"></a>02617                 sign = 1 ;
+<a name="l02618"></a>02618             }
+<a name="l02619"></a>02619             centreval += (float)sign * coeffs[i][col]*pow(wavelag_mean, i) ;
+<a name="l02620"></a>02620         }
+<a name="l02621"></a>02621 
+<a name="l02622"></a>02622     
+<a name="l02623"></a>02623         <span class="comment">/* prepare to write out wavelength as pixel values */</span>
+<a name="l02624"></a>02624         <span class="keywordflow">for</span> ( row = 0 ; row < oly ; row++ )
+<a name="l02625"></a>02625         {
+<a name="l02626"></a>02626             centrepix = (float)row - ((<span class="keywordtype">float</span>)oly - 1.)/2. ;
+<a name="l02627"></a>02627             pixvalue = 0. ;
+<a name="l02628"></a>02628             <span class="keywordflow">for</span> ( i = 1 ; i < n_fitcoeffs ; i++ )
+<a name="l02629"></a>02629             {
+<a name="l02630"></a>02630                 pixvalue += coeffs[i][col]*pow(centrepix, i) ;
+<a name="l02631"></a>02631             }
+<a name="l02632"></a>02632             podata[col+row*olx] = centreval + pixvalue ;
+<a name="l02633"></a>02633         }
+<a name="l02634"></a>02634     }
+<a name="l02635"></a>02635 
+<a name="l02636"></a>02636 
+<a name="l02637"></a>02637 
+<a name="l02638"></a>02638     cpl_free(emline) ;
+<a name="l02639"></a>02639     cpl_free(spec) ;
+<a name="l02640"></a>02640     cpl_free(wavelag) ;
+<a name="l02641"></a>02641     cpl_free(wave) ;
+<a name="l02642"></a>02642     cpl_free(a) ;
+<a name="l02643"></a>02643     cpl_free(z) ;
+<a name="l02644"></a>02644 
+<a name="l02645"></a>02645 
+<a name="l02646"></a>02646     <span class="keywordflow">return</span> wavemap ;
+<a name="l02647"></a>02647 }
+<a name="l02648"></a>02648 
+<a name="l02671"></a>02671 <span class="keywordtype">float</span> sinfo_new_check_line_positions ( cpl_image     * lineIm,
+<a name="l02672"></a>02672                        <span class="keywordtype">float</span>       ** coeffs,
+<a name="l02673"></a>02673                        <span class="keywordtype">int</span>            n_fitcoeffs,
+<a name="l02674"></a>02674                        <span class="keywordtype">float</span>            gdisp1,
+<a name="l02675"></a>02675                        FitParams   ** par )
+<a name="l02676"></a>02676 {
+<a name="l02677"></a>02677     <span class="keywordtype">float</span> wave_shift=0 ;
+<a name="l02678"></a>02678     <span class="keywordtype">float</span> amp[100] ;
+<a name="l02679"></a>02679     <span class="keywordtype">float</span> sort_amp[100] ;
+<a name="l02680"></a>02680     <span class="keywordtype">float</span> offset=0 ;
+<a name="l02681"></a>02681     <span class="keywordtype">float</span> shift=0 ;
+<a name="l02682"></a>02682     <span class="keywordtype">float</span> position=0;
+<a name="l02683"></a>02683     <span class="keywordtype">float</span> lambda=0;
+<a name="l02684"></a>02684     <span class="keywordtype">float</span> wave=0 ;
+<a name="l02685"></a>02685     <span class="keywordtype">int</span> i=0;
+<a name="l02686"></a>02686     <span class="keywordtype">int</span> j=0;
+<a name="l02687"></a>02687     <span class="keywordtype">int</span> k=0;
+<a name="l02688"></a>02688     <span class="keywordtype">int</span> l=0;
+<a name="l02689"></a>02689     <span class="keywordtype">int</span> m=0;
+<a name="l02690"></a>02690     <span class="keywordtype">int</span> n=0;
+<a name="l02691"></a>02691     <span class="keywordtype">int</span> col=0;
+<a name="l02692"></a>02692     <span class="keywordtype">int</span> firstj=0;
+<a name="l02693"></a>02693     <span class="keywordtype">float</span>* shift_col=NULL ;
+<a name="l02694"></a>02694     <span class="keywordtype">int</span>* foundit=NULL ;
+<a name="l02695"></a>02695     <span class="keywordtype">int</span> n_lines=0;
+<a name="l02696"></a>02696     <span class="keywordtype">int</span> lin, found=0 ;
+<a name="l02697"></a>02697     <span class="keywordtype">int</span> lx=0;
+<a name="l02698"></a>02698     <span class="keywordtype">int</span> ly=0;
+<a name="l02699"></a>02699     <span class="keywordtype">float</span>* pdata=NULL;
+<a name="l02700"></a>02700 
+<a name="l02701"></a>02701     <span class="keywordflow">if</span> ( lineIm == NULL )
+<a name="l02702"></a>02702     {
+<a name="l02703"></a>02703         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" no input image given!\n"</span>) ;
+<a name="l02704"></a>02704         <span class="keywordflow">return</span> FLAG ;
+<a name="l02705"></a>02705     }
+<a name="l02706"></a>02706     lx=cpl_image_get_size_x(lineIm);
+<a name="l02707"></a>02707     ly=cpl_image_get_size_y(lineIm);
+<a name="l02708"></a>02708     pdata=cpl_image_get_data_float(lineIm);
+<a name="l02709"></a>02709 
+<a name="l02710"></a>02710     <span class="keywordflow">if</span> ( coeffs == NULL )
+<a name="l02711"></a>02711     {
+<a name="l02712"></a>02712         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" no coefficient sinfo_matrix given!\n"</span>) ;
+<a name="l02713"></a>02713         <span class="keywordflow">return</span> FLAG ;
+<a name="l02714"></a>02714     }
+<a name="l02715"></a>02715     <span class="keywordflow">if</span> ( par == NULL )
+<a name="l02716"></a>02716     {
+<a name="l02717"></a>02717         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" no fit parameters given!\n"</span>) ;
+<a name="l02718"></a>02718         <span class="keywordflow">return</span> FLAG ;
+<a name="l02719"></a>02719     }
+<a name="l02720"></a>02720     <span class="keywordflow">if</span> ( n_fitcoeffs < 2 )
+<a name="l02721"></a>02721     {
+<a name="l02722"></a>02722         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" wrong number of polynomial coefficients given!\n"</span>) ;
+<a name="l02723"></a>02723         <span class="keywordflow">return</span> FLAG ;
+<a name="l02724"></a>02724     }
+<a name="l02725"></a>02725 
+<a name="l02726"></a>02726     offset = (float) (ly -1.) / 2. ;
+<a name="l02727"></a>02727     n_lines = par[0]->n_params/lx ;
+<a name="l02728"></a>02728 
+<a name="l02729"></a>02729     shift_col=cpl_calloc(lx,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l02730"></a>02730     foundit=cpl_calloc(par[0]->n_params,<span class="keyword">sizeof</span>(<span class="keywordtype">int</span>)) ;
+<a name="l02731"></a>02731     
+<a name="l02732"></a>02732     <span class="comment">/*search for the brightest 5 lines in each column and compute the </span>
+<a name="l02733"></a>02733 <span class="comment">      wavelength difference*/</span>
+<a name="l02734"></a>02734     <span class="keywordflow">for</span> ( col = 0 ; col < lx ; col++ )
+<a name="l02735"></a>02735     {
+<a name="l02736"></a>02736         n = 0 ;
+<a name="l02737"></a>02737         <span class="keywordflow">for</span> ( i = 0 ; i < par[0]->n_params ; i++ )
+<a name="l02738"></a>02738         {
+<a name="l02739"></a>02739             <span class="keywordflow">if</span> (par[i]->column == col && par[i]->fit_par[2] != 0. && 
+<a name="l02740"></a>02740                 par[i]->fit_par[1] > 1. && par[i]->fit_par[1] < 7. )
+<a name="l02741"></a>02741             {
+<a name="l02742"></a>02742                 foundit[n] = i ;
+<a name="l02743"></a>02743                 amp[n] = par[i]->fit_par[0] ;
+<a name="l02744"></a>02744                 sort_amp[n] = amp[n] ;
+<a name="l02745"></a>02745                 n++ ;
+<a name="l02746"></a>02746             }
+<a name="l02747"></a>02747         }
+<a name="l02748"></a>02748         sinfo_pixel_qsort(sort_amp, n) ;
+<a name="l02749"></a>02749 
+<a name="l02750"></a>02750         <span class="keywordflow">if</span> ( n > 5 )
+<a name="l02751"></a>02751         {
+<a name="l02752"></a>02752             firstj = n - 5 ;
+<a name="l02753"></a>02753         }
+<a name="l02754"></a>02754         <span class="keywordflow">else</span>
+<a name="l02755"></a>02755         {
+<a name="l02756"></a>02756             firstj = 0 ;
+<a name="l02757"></a>02757         }
+<a name="l02758"></a>02758         l = 0 ; 
+<a name="l02759"></a>02759         shift = 0 ;
+<a name="l02760"></a>02760         <span class="keywordflow">for</span> ( j = firstj ; j < n ; j++ )
+<a name="l02761"></a>02761         {
+<a name="l02762"></a>02762             <span class="keywordflow">for</span> ( m = 0 ; m < n ; m++ )
+<a name="l02763"></a>02763             {
+<a name="l02764"></a>02764                 <span class="keywordflow">if</span> ( sort_amp[j] == amp[m] )
+<a name="l02765"></a>02765                 {
+<a name="l02766"></a>02766                     position = par[foundit[m]]->fit_par[2] ; 
+<a name="l02767"></a>02767                     lambda   = par[foundit[m]]->wavelength ;
+<a name="l02768"></a>02768                     wave = 0 ;
+<a name="l02769"></a>02769                     <span class="keywordflow">for</span> ( k = 0 ; k < n_fitcoeffs ; k++ ) 
+<a name="l02770"></a>02770                     {
+<a name="l02771"></a>02771                         wave += coeffs[k][col]*pow(position-offset, k) ;
+<a name="l02772"></a>02772                     }
+<a name="l02773"></a>02773                     shift += lambda - wave ;
+<a name="l02774"></a>02774                     l++ ;
+<a name="l02775"></a>02775                 }
+<a name="l02776"></a>02776             }
+<a name="l02777"></a>02777         }
+<a name="l02778"></a>02778         <span class="keywordflow">if</span> ( l == 0 ) continue ;
+<a name="l02779"></a>02779         shift_col[col] = shift/(float)l ; 
+<a name="l02780"></a>02780     }
+<a name="l02781"></a>02781     wave_shift = sinfo_new_clean_mean(shift_col, lx, 10., 10.) ;
+<a name="l02782"></a>02782     sinfo_msg(<span class="stringliteral">"Overall positioning error: %3.2g [um] %3.2g [pix]"</span>, 
+<a name="l02783"></a>02783                wave_shift,wave_shift/fabs(gdisp1)) ;
+<a name="l02784"></a>02784 
+<a name="l02785"></a>02785 
+<a name="l02786"></a>02786     <span class="comment">/* determine positioning error for each found line */</span>
+<a name="l02787"></a>02787     <span class="keywordflow">for</span> ( lin = 0 ; lin < n_lines ; lin++ )
+<a name="l02788"></a>02788     {
+<a name="l02789"></a>02789         <span class="keywordflow">for</span> ( col = 0 ; col < lx ; col++ )
+<a name="l02790"></a>02790         {
+<a name="l02791"></a>02791             shift_col[col] = 0. ;
+<a name="l02792"></a>02792             found = -1 ;
+<a name="l02793"></a>02793             <span class="keywordflow">for</span> ( i = 0 ; i < par[0]->n_params ; i++ )
+<a name="l02794"></a>02794             {
+<a name="l02795"></a>02795                 <span class="keywordflow">if</span> (par[i]->column == col && par[i]->fit_par[2] != 0. && 
+<a name="l02796"></a>02796                     par[i]->fit_par[1] > 1. && par[i]->fit_par[1] < 7. && 
+<a name="l02797"></a>02797                     par[i]->line == lin )
+<a name="l02798"></a>02798                 {
+<a name="l02799"></a>02799                     found = i ;
+<a name="l02800"></a>02800                 }
+<a name="l02801"></a>02801             }
+<a name="l02802"></a>02802             <span class="keywordflow">if</span> (found == -1) break ;
+<a name="l02803"></a>02803 
+<a name="l02804"></a>02804             position = par[found]->fit_par[2] ; 
+<a name="l02805"></a>02805             lambda  = par[found]->wavelength ;
+<a name="l02806"></a>02806             wave = 0 ;
+<a name="l02807"></a>02807             <span class="keywordflow">for</span> ( k = 0 ; k < n_fitcoeffs ; k++ ) 
+<a name="l02808"></a>02808             {
+<a name="l02809"></a>02809                 wave += coeffs[k][col]*pow(position-offset, k) ;
+<a name="l02810"></a>02810             }
+<a name="l02811"></a>02811             shift_col[col] = lambda - wave ;
+<a name="l02812"></a>02812         }
+<a name="l02813"></a>02813         <span class="keywordflow">if</span> (found != -1 )
+<a name="l02814"></a>02814         {
+<a name="l02815"></a>02815       sinfo_msg(<span class="stringliteral">"shift: %3.2g [um] %3.2g (pix) at: %4.3f [um]"</span>,
+<a name="l02816"></a>02816             sinfo_new_clean_mean(shift_col,lx, 10., 10.),
+<a name="l02817"></a>02817                     sinfo_new_clean_mean(shift_col,lx, 10., 10.)/fabs(gdisp1),
+<a name="l02818"></a>02818                     lambda) ;
+<a name="l02819"></a>02819         }
+<a name="l02820"></a>02820     }
+<a name="l02821"></a>02821     cpl_free(shift_col) ;
+<a name="l02822"></a>02822     cpl_free(foundit) ;
+<a name="l02823"></a>02823 
+<a name="l02824"></a>02824     <span class="keywordflow">return</span> wave_shift ;
+<a name="l02825"></a>02825 }
+<a name="l02826"></a>02826 
+<a name="l02827"></a>02827 
+<a name="l02856"></a>02856 <span class="keywordtype">float</span> sinfo_new_check_correlated_line_positions ( cpl_image     * lineIm,
+<a name="l02857"></a>02857                                      <span class="keywordtype">float</span>       ** coeffs,
+<a name="l02858"></a>02858                                      <span class="keywordtype">int</span>            n_fitcoeffs,
+<a name="l02859"></a>02859                                      <span class="keywordtype">float</span>        * wavelength,
+<a name="l02860"></a>02860                                      <span class="keywordtype">float</span>        * intensity,
+<a name="l02861"></a>02861                                      <span class="keywordtype">int</span>            n_lines,
+<a name="l02862"></a>02862                                      <span class="keywordtype">float</span>          fwhm, 
+<a name="l02863"></a>02863                                      <span class="keywordtype">float</span>          width,
+<a name="l02864"></a>02864                                      <span class="keywordtype">float</span>          min_amplitude,
+<a name="l02865"></a>02865                                      <span class="keywordtype">float</span>          dispersion,
+<a name="l02866"></a>02866                                      FitParams   ** par )
+<a name="l02867"></a>02867 {
+<a name="l02868"></a>02868     <span class="keywordtype">float</span> wave_shift=0 ;
+<a name="l02869"></a>02869     <span class="keywordtype">float</span> offset=0;
+<a name="l02870"></a>02870     <span class="keywordtype">float</span> shift=0;
+<a name="l02871"></a>02871     <span class="keywordtype">float</span> position=0;
+<a name="l02872"></a>02872     <span class="keywordtype">float</span> lambda=0;
+<a name="l02873"></a>02873     <span class="keywordtype">float</span> wave=0;
+<a name="l02874"></a>02874     <span class="keywordtype">int</span> i=0;
+<a name="l02875"></a>02875     <span class="keywordtype">int</span> j=0;
+<a name="l02876"></a>02876     <span class="keywordtype">int</span> k=0;  <span class="comment">/*, l, m*/</span>
+<a name="l02877"></a>02877     <span class="keywordtype">int</span> n=0;
+<a name="l02878"></a>02878     <span class="keywordtype">int</span> c=0;
+<a name="l02879"></a>02879     <span class="keywordtype">int</span> z=0;
+<a name="l02880"></a>02880     <span class="keywordtype">int</span> col=0;<span class="comment">/*, firstj*/</span>
+<a name="l02881"></a>02881     <span class="keywordtype">int</span> found=0;<span class="comment">/*lin,*/</span>
+<a name="l02882"></a>02882     <span class="keywordtype">int</span> line=0;
+<a name="l02883"></a>02883     <span class="keywordtype">int</span> result=0;
+<a name="l02884"></a>02884     <span class="keywordtype">float</span> cenpos=0;
+<a name="l02885"></a>02885     <span class="keywordtype">float</span> angst=0;
+<a name="l02886"></a>02886     <span class="keywordtype">float</span> a_initial=0;
+<a name="l02887"></a>02887 
+<a name="l02888"></a>02888     <span class="keywordtype">int</span>* foundit=NULL ;
+<a name="l02889"></a>02889     <span class="keywordtype">float</span>* shift_col=NULL ;
+<a name="l02890"></a>02890     <span class="keywordtype">float</span>* wave_cor=NULL ;
+<a name="l02891"></a>02891     <span class="keywordtype">double</span>* a=NULL ;
+<a name="l02892"></a>02892     <span class="keywordtype">double</span>* zroot=NULL ;
+<a name="l02893"></a>02893 
+<a name="l02894"></a>02894     gsl_poly_complex_workspace * w=NULL ;
+<a name="l02895"></a>02895     Vector * vline=NULL;
+<a name="l02896"></a>02896     <span class="keywordtype">int</span>    * mpar=NULL;
+<a name="l02897"></a>02897     <span class="keywordtype">float</span>  * xdat=NULL;
+<a name="l02898"></a>02898     <span class="keywordtype">float</span>  * wdat=NULL;
+<a name="l02899"></a>02899     <span class="keywordtype">int</span> lx=0;
+<a name="l02900"></a>02900     <span class="keywordtype">int</span> ly=0;
+<a name="l02901"></a>02901     <span class="keywordtype">float</span>* pdata=NULL;
+<a name="l02902"></a>02902 
+<a name="l02903"></a>02903     <span class="keywordflow">if</span> ( lineIm == NULL )
+<a name="l02904"></a>02904     {
+<a name="l02905"></a>02905         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" no input image given!\n"</span>) ;
+<a name="l02906"></a>02906         <span class="keywordflow">return</span> FLAG ;
+<a name="l02907"></a>02907     }
+<a name="l02908"></a>02908     lx=cpl_image_get_size_x(lineIm);
+<a name="l02909"></a>02909     ly=cpl_image_get_size_y(lineIm);
+<a name="l02910"></a>02910     pdata=cpl_image_get_data_float(lineIm);
+<a name="l02911"></a>02911 
+<a name="l02912"></a>02912 
+<a name="l02913"></a>02913     <span class="keywordflow">if</span> ( coeffs == NULL )
+<a name="l02914"></a>02914     {
+<a name="l02915"></a>02915         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" no coefficient sinfo_matrix given!\n"</span>) ;
+<a name="l02916"></a>02916         <span class="keywordflow">return</span> FLAG ;
+<a name="l02917"></a>02917     }
+<a name="l02918"></a>02918     <span class="keywordflow">if</span> ( par == NULL )
+<a name="l02919"></a>02919     {
+<a name="l02920"></a>02920         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" no fit parameters given!\n"</span>) ;
+<a name="l02921"></a>02921         <span class="keywordflow">return</span> FLAG ;
+<a name="l02922"></a>02922     }
+<a name="l02923"></a>02923     <span class="keywordflow">if</span> ( n_fitcoeffs < 2 )
+<a name="l02924"></a>02924     {
+<a name="l02925"></a>02925         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" wrong number of polynomial coefficients given!\n"</span>) ;
+<a name="l02926"></a>02926         <span class="keywordflow">return</span> FLAG ;
+<a name="l02927"></a>02927     }
+<a name="l02928"></a>02928     <span class="keywordflow">if</span> ( wavelength == NULL || intensity == NULL )
+<a name="l02929"></a>02929     {
+<a name="l02930"></a>02930         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" no line list given!\n"</span>) ;
+<a name="l02931"></a>02931         <span class="keywordflow">return</span> FLAG ;
+<a name="l02932"></a>02932     }
+<a name="l02933"></a>02933     <span class="keywordflow">if</span> ( fwhm <= 0 )
+<a name="l02934"></a>02934     {
+<a name="l02935"></a>02935         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" wrong guess fwhm given!\n"</span>) ;
+<a name="l02936"></a>02936         <span class="keywordflow">return</span> FLAG ;
+<a name="l02937"></a>02937     }
+<a name="l02938"></a>02938     <span class="keywordflow">if</span> ( width <= 0 )
+<a name="l02939"></a>02939     {
+<a name="l02940"></a>02940         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" wrong half width given!\n"</span>) ;
+<a name="l02941"></a>02941         <span class="keywordflow">return</span> FLAG ;
+<a name="l02942"></a>02942     } 
+<a name="l02943"></a>02943     <span class="keywordflow">if</span> ( min_amplitude <= 0 )
+<a name="l02944"></a>02944     {
+<a name="l02945"></a>02945         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" wrong guess amplitude given!\n"</span>) ;
+<a name="l02946"></a>02946         <span class="keywordflow">return</span> FLAG ;
+<a name="l02947"></a>02947     } 
+<a name="l02948"></a>02948 
+<a name="l02949"></a>02949     <span class="comment">/* allocate memory for the spectral sinfo_vector */</span>
+<a name="l02950"></a>02950     <span class="keywordflow">if</span> ( NULL == (vline = sinfo_new_vector (2*width + 1)) )
+<a name="l02951"></a>02951     {
+<a name="l02952"></a>02952         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" cannot allocate new Vector \n"</span>) ;
+<a name="l02953"></a>02953         <span class="keywordflow">return</span> -14 ;
+<a name="l02954"></a>02954     }
+<a name="l02955"></a>02955     <span class="comment">/* allocate memory */</span>
+<a name="l02956"></a>02956     xdat = (<span class="keywordtype">float</span> *) cpl_calloc( vline -> n_elements, <span class="keyword">sizeof</span> (<span class="keywordtype">float</span>) ) ;
+<a name="l02957"></a>02957     wdat = (<span class="keywordtype">float</span> *) cpl_calloc( vline -> n_elements, <span class="keyword">sizeof</span> (<span class="keywordtype">float</span>) ) ;
+<a name="l02958"></a>02958     mpar = (<span class="keywordtype">int</span> *)   cpl_calloc( MAXPAR, <span class="keyword">sizeof</span> (<span class="keywordtype">int</span>) ) ;
+<a name="l02959"></a>02959 
+<a name="l02960"></a>02960 
+<a name="l02961"></a>02961     foundit=cpl_calloc(par[0]->n_params,<span class="keyword">sizeof</span>(<span class="keywordtype">int</span>)) ;
+<a name="l02962"></a>02962     shift_col=cpl_calloc(lx,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l02963"></a>02963     wave_cor=cpl_calloc(n_lines,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l02964"></a>02964     a=cpl_calloc(n_fitcoeffs,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l02965"></a>02965     zroot=cpl_calloc(2*(n_fitcoeffs - 1),<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l02966"></a>02966 
+<a name="l02967"></a>02967 
+<a name="l02968"></a>02968 
+<a name="l02969"></a>02969     <span class="comment">/* determine the approximate line positions using the line list and the </span>
+<a name="l02970"></a>02970 <span class="comment">       coefficients */</span>
+<a name="l02971"></a>02971     <span class="comment">/* find out if Angstroem or microns are used */</span>
+<a name="l02972"></a>02972     <span class="keywordflow">if</span> ( wavelength[0] > 10000. )
+<a name="l02973"></a>02973     {
+<a name="l02974"></a>02974         <span class="comment">/* Angstroem */</span>
+<a name="l02975"></a>02975         angst = 10000. ;
+<a name="l02976"></a>02976     }
+<a name="l02977"></a>02977     <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( wavelength[0] > 1000. && wavelength[0] < 10000. )
+<a name="l02978"></a>02978     {
+<a name="l02979"></a>02979         <span class="comment">/* nanometers */</span>
+<a name="l02980"></a>02980         angst = 1000. ;
+<a name="l02981"></a>02981     }
+<a name="l02982"></a>02982     <span class="keywordflow">else</span>
+<a name="l02983"></a>02983     {
+<a name="l02984"></a>02984         <span class="comment">/* microns */</span>
+<a name="l02985"></a>02985         angst = 1. ;
+<a name="l02986"></a>02986     }
+<a name="l02987"></a>02987     offset = ((float) ly -1.) / 2. ;
+<a name="l02988"></a>02988 
+<a name="l02989"></a>02989     k = 0 ;
+<a name="l02990"></a>02990     <span class="keywordflow">for</span> ( col = 10 ; col < 25 ; col++ )
+<a name="l02991"></a>02991     {
+<a name="l02992"></a>02992         <span class="comment">/* determine the coefficients by using the given bcoefs */</span>
+<a name="l02993"></a>02993         <span class="keywordflow">for</span> ( i = 0 ; i < n_fitcoeffs ; i++ )
+<a name="l02994"></a>02994         {
+<a name="l02995"></a>02995             <span class="comment">/* initialize coefficients and solution */</span>
+<a name="l02996"></a>02996             <span class="keywordflow">if</span> (i < n_fitcoeffs-1)
+<a name="l02997"></a>02997             {
+<a name="l02998"></a>02998                 zroot[2*i] = 0. ;
+<a name="l02999"></a>02999                 zroot[2*i+1] = 0. ;
+<a name="l03000"></a>03000             }
+<a name="l03001"></a>03001             a[i] = coeffs[i][col] ;
+<a name="l03002"></a>03002         }
+<a name="l03003"></a>03003         a_initial = a[0] ;
+<a name="l03004"></a>03004 
+<a name="l03005"></a>03005         <span class="comment">/* go through the lines */</span>
+<a name="l03006"></a>03006         <span class="keywordflow">for</span> ( line = 0 ; line < n_lines ; line++ )
+<a name="l03007"></a>03007         {
+<a name="l03008"></a>03008             <span class="comment">/* go from Angstroem to micron */</span>
+<a name="l03009"></a>03009             wave_cor[line] = wavelength[line]/angst ;
+<a name="l03010"></a>03010             <span class="keywordflow">if</span> (line > 0 && line < n_lines-1)
+<a name="l03011"></a>03011             {
+<a name="l03012"></a>03012                 <span class="keywordflow">if</span> (fabs((wave_cor[line] - wave_cor[line-1]) / 
+<a name="l03013"></a>03013                          dispersion ) < 2*width ||
+<a name="l03014"></a>03014                     fabs((wave_cor[line] - wave_cor[line+1]) / 
+<a name="l03015"></a>03015                          dispersion ) < 2*width )
+<a name="l03016"></a>03016                 {
+<a name="l03017"></a>03017                     continue ;
+<a name="l03018"></a>03018                 }
+<a name="l03019"></a>03019             }
+<a name="l03020"></a>03020 
+<a name="l03021"></a>03021             a[0] = a_initial - wave_cor[line] ;
+<a name="l03022"></a>03022 
+<a name="l03023"></a>03023             <span class="keywordflow">if</span> (NULL==(w=sinfo_gsl_poly_complex_workspace_alloc(n_fitcoeffs)))
+<a name="l03024"></a>03024             {
+<a name="l03025"></a>03025                 <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" could not allocate complex workspace!"</span>) ;
+<a name="l03026"></a>03026                 <span class="keywordflow">return</span> FLAG ;
+<a name="l03027"></a>03027             }
+<a name="l03028"></a>03028             <span class="keywordflow">if</span> (-1 == sinfo_gsl_poly_complex_solve(a, n_fitcoeffs, w, zroot))
+<a name="l03029"></a>03029             {
+<a name="l03030"></a>03030                 <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" sinfo_gsl_poly_complex_solve did not work!"</span>) ;
+<a name="l03031"></a>03031                 <span class="keywordflow">return</span> FLAG ;
+<a name="l03032"></a>03032             }
+<a name="l03033"></a>03033             sinfo_gsl_poly_complex_workspace_free(w) ;
+<a name="l03034"></a>03034 
+<a name="l03035"></a>03035             j = 0 ;
+<a name="l03036"></a>03036             found = -1 ;
+<a name="l03037"></a>03037             <span class="keywordflow">for</span> ( i = 0 ; i < n_fitcoeffs - 1 ; i++ )
+<a name="l03038"></a>03038             {
+<a name="l03039"></a>03039                 <span class="comment">/* test for appropriate solution */</span>
+<a name="l03040"></a>03040                 <span class="keywordflow">if</span>( (zroot[2*i] > (-1.)*(<span class="keywordtype">float</span>) ly/2. &&
+<a name="l03041"></a>03041                      zroot[2*i] < (<span class="keywordtype">float</span>)ly/2.) && zroot[2*i+1] == 0. )
+<a name="l03042"></a>03042                 {
+<a name="l03043"></a>03043                     found = 2*i ;
+<a name="l03044"></a>03044                     j ++ ;
+<a name="l03045"></a>03045                 }
+<a name="l03046"></a>03046                 <span class="keywordflow">else</span>
+<a name="l03047"></a>03047                 {
+<a name="l03048"></a>03048                     continue ;
+<a name="l03049"></a>03049                 }
+<a name="l03050"></a>03050             }
+<a name="l03051"></a>03051 
+<a name="l03052"></a>03052             <span class="keywordflow">if</span> ( j == 0 )
+<a name="l03053"></a>03053             {
+<a name="l03054"></a>03054                 <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">" no offset solution found for line %d "</span>
+<a name="l03055"></a>03055                                   <span class="stringliteral">"in column %d\n"</span>, line, col) ;
+<a name="l03056"></a>03056                 continue ;
+<a name="l03057"></a>03057             }
+<a name="l03058"></a>03058             <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( j == 1 )
+<a name="l03059"></a>03059             {
+<a name="l03060"></a>03060                 cenpos = zroot[found] + (float)ly / 2. ; ;
+<a name="l03061"></a>03061             }
+<a name="l03062"></a>03062             <span class="keywordflow">else</span>
+<a name="l03063"></a>03063             {
+<a name="l03064"></a>03064                 <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">" two or more offset solutions found for \</span>
+<a name="l03065"></a>03065 <span class="stringliteral">                       line %d in column %d\n"</span>, line, col) ;
+<a name="l03066"></a>03066                 continue ;
+<a name="l03067"></a>03067             }
+<a name="l03068"></a>03068 
+<a name="l03069"></a>03069             <span class="keywordflow">if</span> ( cenpos <= 0 )
+<a name="l03070"></a>03070             {
+<a name="l03071"></a>03071                 continue ;
+<a name="l03072"></a>03072             }
+<a name="l03073"></a>03073 
+<a name="l03074"></a>03074             <span class="comment">/* --------------------------------------------------------------</span>
+<a name="l03075"></a>03075 <span class="comment">             * fit the single lines using sinfo_linefit and store the </span>
+<a name="l03076"></a>03076 <span class="comment">             * parameters in</span>
+<a name="l03077"></a>03077 <span class="comment">             * an array of the FitParams data structure allParams[].</span>
+<a name="l03078"></a>03078 <span class="comment">             */</span>
+<a name="l03079"></a>03079             <span class="keywordflow">if</span> ( (result = sinfo_new_line_fit ( lineIm, par[k], 
+<a name="l03080"></a>03080                                                 fwhm, line, col,
+<a name="l03081"></a>03081                                          width, cenpos, min_amplitude, vline,
+<a name="l03082"></a>03082                                          mpar, xdat, wdat ) ) < 0 )
+<a name="l03083"></a>03083             {
+<a name="l03084"></a>03084              <a class="code" href="group__sinfo__msg.html#ga5011f548e1cbc15d52154469a63343c8" title="Print a debug message.">sinfo_msg_debug</a> (<span class="stringliteral">"sinfo_linefit failed, error no.: %d, "</span>
+<a name="l03085"></a>03085                               <span class="stringliteral">"column: %d, row: %f, line: %d\n"</span>, 
+<a name="l03086"></a>03086                               result, col, cenpos, line) ;
+<a name="l03087"></a>03087                 continue ;
+<a name="l03088"></a>03088             }
+<a name="l03089"></a>03089             <span class="keywordflow">if</span> ( (par[k] -> fit_par[0] <= 0.) || (par[k] -> fit_par[1] <= 0.)
+<a name="l03090"></a>03090                   || (par[k] -> fit_par[2] <= 0.) )
+<a name="l03091"></a>03091             {
+<a name="l03092"></a>03092                 <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a> (<span class="stringliteral">"negative fit parameters in column: %d, "</span>
+<a name="l03093"></a>03093                                    <span class="stringliteral">"line: %d\n"</span>, col, line) ;
+<a name="l03094"></a>03094                 continue ;
+<a name="l03095"></a>03095             }
+<a name="l03096"></a>03096             par[k] -> wavelength = wavelength[line] ;
+<a name="l03097"></a>03097             k++ ;
+<a name="l03098"></a>03098         }
+<a name="l03099"></a>03099 
+<a name="l03100"></a>03100     }
+<a name="l03101"></a>03101     
+<a name="l03102"></a>03102     <span class="comment">/* free memory */</span>
+<a name="l03103"></a>03103     sinfo_new_destroy_vector(vline);
+<a name="l03104"></a>03104     cpl_free(xdat);
+<a name="l03105"></a>03105     cpl_free(wdat);
+<a name="l03106"></a>03106     cpl_free(mpar);
+<a name="l03107"></a>03107 
+<a name="l03108"></a>03108     
+<a name="l03109"></a>03109     c = 0 ;
+<a name="l03110"></a>03110     <span class="keywordflow">for</span> ( col = 10 ; col < 25 ; col++ )
+<a name="l03111"></a>03111     {
+<a name="l03112"></a>03112         n = 0 ;
+<a name="l03113"></a>03113         <span class="keywordflow">for</span> ( i = 0 ; i < k ; i++ )
+<a name="l03114"></a>03114         {
+<a name="l03115"></a>03115             <span class="keywordflow">if</span> (par[i]->column == col && par[i]->fit_par[2] != 0. && 
+<a name="l03116"></a>03116                 par[i]->fit_par[1] > 1. && par[i]->fit_par[1] < 7. )
+<a name="l03117"></a>03117             {
+<a name="l03118"></a>03118                 foundit[n] = i ;
+<a name="l03119"></a>03119                 n++ ;
+<a name="l03120"></a>03120             }
+<a name="l03121"></a>03121         }
+<a name="l03122"></a>03122         <span class="keywordflow">if</span> ( n == 0 ) continue ;
+<a name="l03123"></a>03123 
+<a name="l03124"></a>03124         shift = 0 ;
+<a name="l03125"></a>03125         z = 0 ;
+<a name="l03126"></a>03126         <span class="keywordflow">for</span> ( j = 0 ; j < n ; j++ )
+<a name="l03127"></a>03127         {
+<a name="l03128"></a>03128             position = par[foundit[j]]->fit_par[2] ; 
+<a name="l03129"></a>03129             lambda   = par[foundit[j]]->wavelength ;
+<a name="l03130"></a>03130             line     = par[foundit[j]]->line ;
+<a name="l03131"></a>03131             <span class="keywordflow">if</span> (line > 0 && line < n_lines-1)
+<a name="l03132"></a>03132             {
+<a name="l03133"></a>03133                 <span class="keywordflow">if</span> (fabs((wave_cor[line] - wave_cor[line-1]) / 
+<a name="l03134"></a>03134                           dispersion ) < 2*width ||
+<a name="l03135"></a>03135                     fabs((wave_cor[line] - wave_cor[line+1]) / 
+<a name="l03136"></a>03136                           dispersion ) < 2*width )
+<a name="l03137"></a>03137                 {
+<a name="l03138"></a>03138                     continue ;
+<a name="l03139"></a>03139                 }
+<a name="l03140"></a>03140             }
+<a name="l03141"></a>03141             wave = 0 ;
+<a name="l03142"></a>03142             <span class="keywordflow">for</span> ( i = 0 ; i < n_fitcoeffs ; i++ ) 
+<a name="l03143"></a>03143             {
+<a name="l03144"></a>03144                 wave += coeffs[i][col]*pow(position-offset, i) ;
+<a name="l03145"></a>03145             }
+<a name="l03146"></a>03146             shift += lambda - wave ;
+<a name="l03147"></a>03147             z++ ;
+<a name="l03148"></a>03148         }
+<a name="l03149"></a>03149         shift_col[c] = shift/(float)z ; 
+<a name="l03150"></a>03150         c++ ;
+<a name="l03151"></a>03151     }
+<a name="l03152"></a>03152     <span class="keywordflow">if</span> ( c > 0 )
+<a name="l03153"></a>03153     {
+<a name="l03154"></a>03154         wave_shift = sinfo_new_clean_mean(shift_col, c, 10., 10.) ;
+<a name="l03155"></a>03155         sinfo_msg(<span class="stringliteral">"overall positioning error in microns: %g"</span>, wave_shift) ;
+<a name="l03156"></a>03156     }
+<a name="l03157"></a>03157 
+<a name="l03158"></a>03158     <span class="comment">/* determine positioning error for each found line */</span>
+<a name="l03159"></a>03159     <span class="keywordflow">for</span> ( line = 0 ; line < n_lines ; line++ )
+<a name="l03160"></a>03160     {
+<a name="l03161"></a>03161         <span class="keywordflow">if</span> (line > 0 && line < n_lines-1)
+<a name="l03162"></a>03162         {
+<a name="l03163"></a>03163             <span class="keywordflow">if</span> (fabs((wave_cor[line] - wave_cor[line-1]) / dispersion ) < 
+<a name="l03164"></a>03164                                          2*width ||
+<a name="l03165"></a>03165                 fabs((wave_cor[line] - wave_cor[line+1]) / dispersion ) < 
+<a name="l03166"></a>03166                                          2*width )
+<a name="l03167"></a>03167             {
+<a name="l03168"></a>03168                 continue ;
+<a name="l03169"></a>03169             }
+<a name="l03170"></a>03170         }
+<a name="l03171"></a>03171 
+<a name="l03172"></a>03172         c = 0 ;
+<a name="l03173"></a>03173         <span class="keywordflow">for</span> ( col = 10 ; col < 25 ; col++ )
+<a name="l03174"></a>03174         {
+<a name="l03175"></a>03175             shift_col[c] = 0. ;
+<a name="l03176"></a>03176             found = -1 ;
+<a name="l03177"></a>03177             <span class="keywordflow">for</span> ( i = 0 ; i < k ; i++ )
+<a name="l03178"></a>03178             {
+<a name="l03179"></a>03179                 <span class="keywordflow">if</span> (par[i]->column == col && par[i]->fit_par[2] != 0. && 
+<a name="l03180"></a>03180                     par[i]->fit_par[1] > 1. && par[i]->fit_par[1] < 7. && 
+<a name="l03181"></a>03181                     par[i]->line == line )
+<a name="l03182"></a>03182                 {
+<a name="l03183"></a>03183                     found = i ;
+<a name="l03184"></a>03184                 }
+<a name="l03185"></a>03185             }
+<a name="l03186"></a>03186             <span class="keywordflow">if</span> (found == -1) break ;
+<a name="l03187"></a>03187 
+<a name="l03188"></a>03188             position = par[found]->fit_par[2] ; 
+<a name="l03189"></a>03189             lambda  = par[found]->wavelength ;
+<a name="l03190"></a>03190             wave = 0 ;
+<a name="l03191"></a>03191             <span class="keywordflow">for</span> ( i = 0 ; i < n_fitcoeffs ; i++ ) 
+<a name="l03192"></a>03192             {
+<a name="l03193"></a>03193                 wave += coeffs[i][col]*pow(position-offset, i) ;
+<a name="l03194"></a>03194             }
+<a name="l03195"></a>03195             shift_col[c] = lambda - wave ;
+<a name="l03196"></a>03196             c++ ;
+<a name="l03197"></a>03197         }
+<a name="l03198"></a>03198         <span class="keywordflow">if</span> (found != -1 && c > 0 )
+<a name="l03199"></a>03199         {
+<a name="l03200"></a>03200             sinfo_msg(<span class="stringliteral">"shift in microns: %g at wavelength: %f\n"</span>, 
+<a name="l03201"></a>03201             sinfo_new_clean_mean(shift_col, c, 20., 20.), lambda) ;
+<a name="l03202"></a>03202         }
+<a name="l03203"></a>03203     }
+<a name="l03204"></a>03204 
+<a name="l03205"></a>03205 
+<a name="l03206"></a>03206 
+<a name="l03207"></a>03207     cpl_free(foundit) ;
+<a name="l03208"></a>03208     cpl_free(shift_col) ;
+<a name="l03209"></a>03209     cpl_free(wave_cor) ;
+<a name="l03210"></a>03210     cpl_free(a) ;
+<a name="l03211"></a>03211     cpl_free(zroot) ;
+<a name="l03212"></a>03212 
+<a name="l03213"></a>03213     <span class="keywordflow">return</span> wave_shift ;
+<a name="l03214"></a>03214 }
+<a name="l03215"></a>03215 
+<a name="l03216"></a>03216 
+<a name="l03217"></a>03217 
+<a name="l03242"></a>03242  <span class="keyword">static</span> <span class="keywordtype">int</span>   
+<a name="l03243"></a>03243 sinfo_new_spred_coeffs_cross_slit_fit ( <span class="keywordtype">int</span>      n_columns,
+<a name="l03244"></a>03244                             <span class="keywordtype">float</span> ** acoefs,
+<a name="l03245"></a>03245                             <span class="keywordtype">float</span> ** dacoefs,
+<a name="l03246"></a>03246                             Bcoeffs* bco,
+<a name="l03247"></a>03247                             <span class="keywordtype">float</span>    sigma_factor,
+<a name="l03248"></a>03248                             <span class="keywordtype">float</span>    dispersion,
+<a name="l03249"></a>03249                             <span class="keywordtype">float</span>    pixel_dist,
+<a name="l03250"></a>03250                             <span class="keywordtype">float</span>  * chisq,
+<a name="l03251"></a>03251                           <span class="keywordtype">float</span> ** sinfo_slit_pos )
+<a name="l03252"></a>03252  {
+<a name="l03253"></a>03253      <span class="keywordtype">float</span> col_index;
+<a name="l03254"></a>03254 
+<a name="l03255"></a>03255 
+<a name="l03256"></a>03256      <span class="keywordtype">float</span> ** ucoefs, **vcoefs, **covar ;
+<a name="l03257"></a>03257      <span class="keywordtype">float</span> * acoefsclean ;
+<a name="l03258"></a>03258      <span class="keywordtype">double</span> sum, sumq, mean ;
+<a name="l03259"></a>03259      <span class="keywordtype">double</span> sigma ;
+<a name="l03260"></a>03260      <span class="keywordtype">double</span> cliphi, cliplo ;
+<a name="l03261"></a>03261      <span class="keywordtype">float</span> offset ;
+<a name="l03262"></a>03262      <span class="keywordtype">float</span> threshold ;
+<a name="l03263"></a>03263 
+<a name="l03264"></a>03264      <span class="keywordtype">int</span>* edge=NULL ;
+<a name="l03265"></a>03265      <span class="keywordtype">float</span>* sub_col_index=NULL ;
+<a name="l03266"></a>03266      <span class="keywordtype">float</span>* sub_acoefs=NULL;
+<a name="l03267"></a>03267      <span class="keywordtype">float</span>* sub_dacoefs=NULL ;
+<a name="l03268"></a>03268      <span class="keywordtype">float</span>* wcoefs=NULL ;
+<a name="l03269"></a>03269 
+<a name="l03270"></a>03270 
+<a name="l03271"></a>03271      <span class="keywordtype">int</span> ed1, ed2 ;
+<a name="l03272"></a>03272      <span class="keywordtype">int</span> i, n, num, ndata ;
+<a name="l03273"></a>03273      <span class="keywordtype">int</span> nc, ns ;
+<a name="l03274"></a>03274      <span class="keywordtype">int</span> loc_index ;
+<a name="l03275"></a>03275      <span class="keywordtype">int</span> sl_index;
+<a name="l03276"></a>03276      <span class="keywordtype">int</span> last_i=PIXEL;
+<a name="l03277"></a>03277  
+<a name="l03278"></a>03278      <span class="keywordflow">if</span> ( n_columns < 1 )
+<a name="l03279"></a>03279      {
+<a name="l03280"></a>03280          <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" wrong number of image columns given\n"</span>) ;
+<a name="l03281"></a>03281          <span class="keywordflow">return</span> -1 ;
+<a name="l03282"></a>03282      }
+<a name="l03283"></a>03283      <span class="keywordflow">if</span> ( acoefs == NULL || dacoefs == NULL )
+<a name="l03284"></a>03284      {
+<a name="l03285"></a>03285          <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" acoeffs or errors of coefficients are not given"</span>) ;
+<a name="l03286"></a>03286          <span class="keywordflow">return</span> -1 ;
+<a name="l03287"></a>03287      }
+<a name="l03288"></a>03288      <span class="keywordflow">if</span> ( bco == NULL )
+<a name="l03289"></a>03289      {
+<a name="l03290"></a>03290          <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" bcoeffs are not allocated\n"</span>) ;
+<a name="l03291"></a>03291          <span class="keywordflow">return</span> -1 ;
+<a name="l03292"></a>03292      }
+<a name="l03293"></a>03293      <span class="keywordflow">if</span> ( sigma_factor <= 0. )
+<a name="l03294"></a>03294      {
+<a name="l03295"></a>03295          <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" impossible sigma_factor given!\n"</span>) ;
+<a name="l03296"></a>03296          <span class="keywordflow">return</span> -1 ;
+<a name="l03297"></a>03297      }
+<a name="l03298"></a>03298      <span class="keywordflow">if</span> ( dispersion == 0. )
+<a name="l03299"></a>03299      {
+<a name="l03300"></a>03300          <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" impossible dispersion given!\n"</span>) ;
+<a name="l03301"></a>03301          <span class="keywordflow">return</span> -1 ;
+<a name="l03302"></a>03302      }
+<a name="l03303"></a>03303 
+<a name="l03304"></a>03304 
+<a name="l03305"></a>03305      edge=cpl_calloc(bco->n_slitlets,<span class="keyword">sizeof</span>(<span class="keywordtype">int</span>)) ;
+<a name="l03306"></a>03306      sub_col_index=cpl_calloc(n_columns,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l03307"></a>03307      sub_acoefs=cpl_calloc(n_columns,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>));
+<a name="l03308"></a>03308      sub_dacoefs=cpl_calloc(n_columns,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l03309"></a>03309 
+<a name="l03310"></a>03310      wcoefs=cpl_calloc(bco->n_bcoeffs,<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)) ;
+<a name="l03311"></a>03311 
+<a name="l03312"></a>03312      <span class="comment">/*------------------------------------------------------------------------</span>
+<a name="l03313"></a>03313 <span class="comment">      * search for the slitlet edges by comparing the a0 coefficients along i</span>
+<a name="l03314"></a>03314 <span class="comment">      * the columns</span>
+<a name="l03315"></a>03315 <span class="comment">      * if a bigger deviation occurrs it is assumed that there is an edge.</span>
+<a name="l03316"></a>03316 <span class="comment">      */</span>
+<a name="l03317"></a>03317      n = 0 ;
+<a name="l03318"></a>03318      threshold = pixel_dist * fabs(dispersion) ;
+<a name="l03319"></a>03319      sinfo_slit_pos[0][0]=0 ;
+<a name="l03320"></a>03320      sl_index  = 0;
+<a name="l03321"></a>03321      <span class="comment">/* it was for ( i = PIXEL ; i  < n_columns - PIXEL ; ) */</span>
+<a name="l03322"></a>03322      <span class="keywordflow">for</span> ( i = 0 ; i  < n_columns - PIXEL ; )
+<a name="l03323"></a>03323      {
+<a name="l03324"></a>03324          <span class="keywordflow">if</span> ( !isnan(acoefs[0][i+1]) && 
+<a name="l03325"></a>03325                      acoefs[0][i+1] != 0. && 
+<a name="l03326"></a>03326                      acoefs[0][i] != 0.
+<a name="l03327"></a>03327                    && dacoefs[0][i+1] != 0.)
+<a name="l03328"></a>03328          {
+<a name="l03329"></a>03329              <span class="keywordflow">if</span> ( isnan(acoefs[0][i]) || acoefs[0][i] == 0. )
+<a name="l03330"></a>03330              {
+<a name="l03331"></a>03331                  <span class="keywordflow">if</span> (fabs(acoefs[0][i+1] - acoefs[0][i-1]) >= threshold )
+<a name="l03332"></a>03332              {
+<a name="l03333"></a>03333              <span class="comment">/* printf("case a pos1 %d pos2 %d \n",i,i+1); */</span>
+<a name="l03334"></a>03334                      edge[n] = i+1 ;
+<a name="l03335"></a>03335              sinfo_slit_pos[sl_index][1] = i ;
+<a name="l03336"></a>03336              sinfo_slit_pos[sl_index+1][0] = i + 1 ;
+<a name="l03337"></a>03337              sl_index++;
+<a name="l03338"></a>03338                      n++ ;
+<a name="l03339"></a>03339              last_i = i;
+<a name="l03340"></a>03340                      i += PIXEL ;
+<a name="l03341"></a>03341                  }
+<a name="l03342"></a>03342              }
+<a name="l03343"></a>03343              <span class="keywordflow">else</span>
+<a name="l03344"></a>03344              {
+<a name="l03345"></a>03345                  <span class="keywordflow">if</span> (fabs(acoefs[0][i+1] - acoefs[0][i]) >= threshold )
+<a name="l03346"></a>03346              {
+<a name="l03347"></a>03347              <span class="comment">/* printf("case b pos1 %d pos2 %d \n",i,i+1); */</span>
+<a name="l03348"></a>03348                      edge[n] = i+1 ;
+<a name="l03349"></a>03349              sinfo_slit_pos[sl_index][1] = i ;
+<a name="l03350"></a>03350              sinfo_slit_pos[sl_index+1][0] = i + 1 ;
+<a name="l03351"></a>03351              sl_index++;
+<a name="l03352"></a>03352                      n++ ;
+<a name="l03353"></a>03353              last_i = i;
+<a name="l03354"></a>03354                      i += PIXEL ;
+<a name="l03355"></a>03355                  }
+<a name="l03356"></a>03356              }
+<a name="l03357"></a>03357 
+<a name="l03358"></a>03358 
+<a name="l03359"></a>03359             <span class="comment">/* sometimes a slitlet may be lost due to divergences in </span>
+<a name="l03360"></a>03360 <span class="comment">                acoeffs[0] we try to recover it */</span>
+<a name="l03361"></a>03361              <span class="keywordflow">if</span>( ( (i-last_i) > 63 ) && 
+<a name="l03362"></a>03362                 ( isnan(fabs(acoefs[0][i+1] - acoefs[0][i])) ||
+<a name="l03363"></a>03363                   isnan(fabs(acoefs[0][i+1] - acoefs[0][i-1])) ) ) 
+<a name="l03364"></a>03364          {
+<a name="l03365"></a>03365                      edge[n] = i+1 ;
+<a name="l03366"></a>03366                      sinfo_slit_pos[sl_index][1] = i ;
+<a name="l03367"></a>03367                      sinfo_slit_pos[sl_index+1][0] = i + 1 ;
+<a name="l03368"></a>03368                      sl_index++;
+<a name="l03369"></a>03369                      n++ ;
+<a name="l03370"></a>03370 
+<a name="l03371"></a>03371                      last_i = i;
+<a name="l03372"></a>03372                      <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"2 recovered slitlet edge i=%d"</span>,i);
+<a name="l03373"></a>03373                      i += PIXEL ;
+<a name="l03374"></a>03374 
+<a name="l03375"></a>03375          }
+<a name="l03376"></a>03376          }
+<a name="l03377"></a>03377          i++ ;
+<a name="l03378"></a>03378      }
+<a name="l03379"></a>03379      sinfo_slit_pos[sl_index][1]  = 2047;
+<a name="l03380"></a>03380      <span class="comment">/* printf("2 Found n slitlest: %d check %d\n", n,bco->n_slitlets - 1); */</span>
+<a name="l03381"></a>03381      <span class="keywordflow">if</span> ( n != bco->n_slitlets - 1 )
+<a name="l03382"></a>03382      {
+<a name="l03383"></a>03383          <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"could not find the right number of "</span>
+<a name="l03384"></a>03384                          <span class="stringliteral">"slitlets, found: %d\n"</span>,n+1) ;
+<a name="l03385"></a>03385          <span class="keywordflow">return</span> -1 ;
+<a name="l03386"></a>03386      }
+<a name="l03387"></a>03387 
+<a name="l03388"></a>03388      <span class="comment">/* go through the coefficents indices */</span>
+<a name="l03389"></a>03389      <span class="keywordflow">for</span> ( loc_index = 0 ; loc_index < bco->n_acoeffs ; loc_index++ )
+<a name="l03390"></a>03390      {
+<a name="l03391"></a>03391          <span class="comment">/* go through the single slitlets */</span>
+<a name="l03392"></a>03392          <span class="keywordflow">for</span> ( ns = 0 ; ns < bco->n_slitlets ; ns++ )
+<a name="l03393"></a>03393          {
+<a name="l03394"></a>03394              <span class="comment">/* determine the slitlet edges */</span>
+<a name="l03395"></a>03395              <span class="keywordflow">if</span> ( ns == 0 )
+<a name="l03396"></a>03396              {
+<a name="l03397"></a>03397                  ed1 = 0 ;
+<a name="l03398"></a>03398                  ed2 = edge[0] ;
+<a name="l03399"></a>03399              }
+<a name="l03400"></a>03400              <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( ns == bco->n_slitlets - 1 )
+<a name="l03401"></a>03401              {
+<a name="l03402"></a>03402                  ed1 = edge[bco->n_slitlets - 2] ;
+<a name="l03403"></a>03403                  ed2 = n_columns ;
+<a name="l03404"></a>03404              }
+<a name="l03405"></a>03405              <span class="keywordflow">else</span>
+<a name="l03406"></a>03406              {
+<a name="l03407"></a>03407                  ed1 = edge[ns-1] ;
+<a name="l03408"></a>03408                  ed2 = edge[ns] ;
+<a name="l03409"></a>03409              }
+<a name="l03410"></a>03410 
+<a name="l03411"></a>03411              nc = 0 ;
+<a name="l03412"></a>03412              <span class="keywordflow">for</span> ( i = ed1 ; i < ed2 ; i++ )
+<a name="l03413"></a>03413              {
+<a name="l03414"></a>03414                  <span class="keywordflow">if</span> ( isnan(acoefs[loc_index][i]) || 
+<a name="l03415"></a>03415                             acoefs[loc_index][i] == 0. || 
+<a name="l03416"></a>03416                            dacoefs[loc_index][i] == 0. )
+<a name="l03417"></a>03417                  {
+<a name="l03418"></a>03418                      continue ;
+<a name="l03419"></a>03419                  }
+<a name="l03420"></a>03420                  <span class="keywordflow">else</span>
+<a name="l03421"></a>03421                  {
+<a name="l03422"></a>03422                      nc++ ;
+<a name="l03423"></a>03423                  }
+<a name="l03424"></a>03424              }
+<a name="l03425"></a>03425              <span class="keywordflow">if</span> (NULL==(acoefsclean=(<span class="keywordtype">float</span>*) cpl_calloc(nc , <span class="keyword">sizeof</span>(<span class="keywordtype">float</span>))) )
+<a name="l03426"></a>03426              {
+<a name="l03427"></a>03427                  <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"could not allocate memory for acoefsclean!"</span>);
+<a name="l03428"></a>03428                  <span class="keywordflow">return</span> -1 ;
+<a name="l03429"></a>03429              }
+<a name="l03430"></a>03430              nc = 0 ;
+<a name="l03431"></a>03431              <span class="keywordflow">for</span> ( i = ed1 ; i  < ed2 ; i++ )
+<a name="l03432"></a>03432             {
+<a name="l03433"></a>03433                 <span class="keywordflow">if</span> ( isnan(acoefs[loc_index][i]) || 
+<a name="l03434"></a>03434                            acoefs[loc_index][i] == 0. || 
+<a name="l03435"></a>03435                           dacoefs[loc_index][i] == 0. )
+<a name="l03436"></a>03436                 {
+<a name="l03437"></a>03437                     continue ;
+<a name="l03438"></a>03438                 }
+<a name="l03439"></a>03439                 <span class="keywordflow">else</span>
+<a name="l03440"></a>03440                 {
+<a name="l03441"></a>03441                     acoefsclean[nc] = acoefs[loc_index][i] ;
+<a name="l03442"></a>03442                     nc++ ;
+<a name="l03443"></a>03443                 }
+<a name="l03444"></a>03444             }
+<a name="l03445"></a>03445 
+<a name="l03446"></a>03446             <span class="comment">/* ----------------------------------------------------------</span>
+<a name="l03447"></a>03447 <span class="comment">             * determine the clean mean and sigma value of the coefficients,</span>
+<a name="l03448"></a>03448 <span class="comment">             * that means reject 10 % of the extreme low and high values</span>
+<a name="l03449"></a>03449 <span class="comment">             */</span>
+<a name="l03450"></a>03450             sinfo_pixel_qsort(acoefsclean, nc) ;
+<a name="l03451"></a>03451 
+<a name="l03452"></a>03452             sum   = 0. ;
+<a name="l03453"></a>03453             sumq  = 0. ;
+<a name="l03454"></a>03454             mean  = 0. ;
+<a name="l03455"></a>03455             sigma = 0. ;
+<a name="l03456"></a>03456             n     = 0 ;
+<a name="l03457"></a>03457             <span class="keywordflow">for</span> ( i = (<span class="keywordtype">int</span>)((<span class="keywordtype">float</span>)nc*LOW_REJECT) ; 
+<a name="l03458"></a>03458                   i < (int)((<span class="keywordtype">float</span>)nc*HIGH_REJECT) ; i++ )
+<a name="l03459"></a>03459             {
+<a name="l03460"></a>03460                 sum  += (double)acoefsclean[i] ;
+<a name="l03461"></a>03461                 sumq += ((double)acoefsclean[i] * (<span class="keywordtype">double</span>)acoefsclean[i]) ;
+<a name="l03462"></a>03462                 n ++ ;
+<a name="l03463"></a>03463             }
+<a name="l03464"></a>03464             mean          = sum/(double)n ;
+<a name="l03465"></a>03465             sigma         = sqrt( sumq/(<span class="keywordtype">double</span>)n - (mean * mean) ) ;
+<a name="l03466"></a>03466             cliphi        = mean + sigma * (double)sigma_factor ;
+<a name="l03467"></a>03467             cliplo        = mean - sigma * (double)sigma_factor ;
+<a name="l03468"></a>03468             <span class="comment">/* fit only the reasonnable values */</span>
+<a name="l03469"></a>03469             num = 0 ;
+<a name="l03470"></a>03470             col_index = 0 ;
+<a name="l03471"></a>03471             <span class="keywordflow">for</span> ( i = ed1 ; i < ed2 ; i++ )
+<a name="l03472"></a>03472             {
+<a name="l03473"></a>03473                 <span class="comment">/* take only the reasonnable coefficients */</span>
+<a name="l03474"></a>03474                 <span class="keywordflow">if</span> ( !isnan(acoefs[loc_index][i]) && 
+<a name="l03475"></a>03475                            (acoefs[loc_index][i] <= cliphi) && 
+<a name="l03476"></a>03476                            (acoefs[loc_index][i] >= cliplo) &&
+<a name="l03477"></a>03477                      (dacoefs[loc_index][i] != 0. ) && 
+<a name="l03478"></a>03478              (acoefs[loc_index][i] != 0.) )
+<a name="l03479"></a>03479                 {
+<a name="l03480"></a>03480                     sub_acoefs[num]    = acoefs[loc_index][i] ;
+<a name="l03481"></a>03481                     sub_dacoefs[num]   = dacoefs[loc_index][i] ;
+<a name="l03482"></a>03482                     sub_col_index[num] = col_index ;
+<a name="l03483"></a>03483                     num ++ ;
+<a name="l03484"></a>03484                 }
+<a name="l03485"></a>03485                 col_index++ ;
+<a name="l03486"></a>03486             }
+<a name="l03487"></a>03487             ndata = num ;
+<a name="l03488"></a>03488             offset = (float)(col_index-1) / 2. ;
+<a name="l03489"></a>03489 
+<a name="l03490"></a>03490             <span class="keywordflow">if</span> ( ndata < bco->n_bcoeffs )
+<a name="l03491"></a>03491             {
+<a name="l03492"></a>03492                 <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" not enough data found in slitlet %da"</span>
+<a name="l03493"></a>03493                                 <span class="stringliteral">" to determine the fit coefficients.\n"</span>, ns) ;
+<a name="l03494"></a>03494                 cpl_free(acoefsclean) ;
+<a name="l03495"></a>03495                 <span class="keywordflow">return</span> -1 ;
+<a name="l03496"></a>03496             }
+<a name="l03497"></a>03497 
+<a name="l03498"></a>03498             <span class="comment">/* allocate coefficient matrices */</span>
+<a name="l03499"></a>03499             ucoefs = sinfo_matrix(1, ndata, 1, bco->n_bcoeffs) ;
+<a name="l03500"></a>03500             vcoefs = sinfo_matrix(1, ndata, 1, bco->n_bcoeffs) ;
+<a name="l03501"></a>03501             covar  = sinfo_matrix(1, bco->n_bcoeffs, 1, bco->n_bcoeffs) ;
+<a name="l03502"></a>03502 
+<a name="l03503"></a>03503             <span class="comment">/* scale the x-values for the fit */</span>
+<a name="l03504"></a>03504             <span class="keywordflow">for</span> ( i = 0 ; i < ndata ; i++ )
+<a name="l03505"></a>03505             {
+<a name="l03506"></a>03506                 sub_col_index[i] = (sub_col_index[i] - offset) / offset ;
+<a name="l03507"></a>03507             }
+<a name="l03508"></a>03508 
+<a name="l03509"></a>03509             <span class="comment">/* finally, do the singular value decomposition fit */</span>
+<a name="l03510"></a>03510             sinfo_svd_fitting ( sub_col_index-1, sub_acoefs-1, 
+<a name="l03511"></a>03511                                 sub_dacoefs-1, ndata, bco[ns].b[loc_index]-1,
+<a name="l03512"></a>03512                                 bco->n_bcoeffs, ucoefs, vcoefs, wcoefs-1, 
+<a name="l03513"></a>03513                                 covar, &chisq[ns], sinfo_fpol ) ;
+<a name="l03514"></a>03514 
+<a name="l03515"></a>03515             <span class="comment">/* scale the found coefficients */</span>
+<a name="l03516"></a>03516             <span class="keywordflow">for</span> ( i = 0 ; i < bco->n_bcoeffs ; i ++ )
+<a name="l03517"></a>03517             {
+<a name="l03518"></a>03518                 bco[ns].b[loc_index][i] /= pow( offset, i ) ;
+<a name="l03519"></a>03519             }
+<a name="l03520"></a>03520 
+<a name="l03521"></a>03521             <span class="comment">/* free memory */</span>
+<a name="l03522"></a>03522             cpl_free (acoefsclean) ;
+<a name="l03523"></a>03523             sinfo_free_matrix( ucoefs, 1<span class="comment">/*, ndata*/</span>, 1<span class="comment">/*, bco->n_bcoeffs */</span>) ;
+<a name="l03524"></a>03524             sinfo_free_matrix( vcoefs, 1<span class="comment">/*, ndata*/</span>, 1<span class="comment">/*, bco->n_bcoeffs */</span>) ;
+<a name="l03525"></a>03525             sinfo_free_matrix( covar, 1<span class="comment">/*, bco->n_bcoeffs*/</span>, 
+<a name="l03526"></a>03526                                1<span class="comment">/*, bco->n_bcoeffs */</span>) ;
+<a name="l03527"></a>03527 
+<a name="l03528"></a>03528             <span class="comment">/* now calculate the smoothed acoefs for each column */</span>
+<a name="l03529"></a>03529             col_index = 0 ;
+<a name="l03530"></a>03530             <span class="keywordflow">for</span> ( i = ed1 ; i < ed2  ; i++ )
+<a name="l03531"></a>03531             {
+<a name="l03532"></a>03532                 acoefs[loc_index][i] = 0. ;
+<a name="l03533"></a>03533                 <span class="keywordflow">for</span> ( n = 0 ; n < bco->n_bcoeffs ; n++ )
+<a name="l03534"></a>03534                 {
+<a name="l03535"></a>03535                     acoefs[loc_index][i] += bco[ns].b[loc_index][n] * 
+<a name="l03536"></a>03536                                         pow(col_index - offset, n) ;
+<a name="l03537"></a>03537                 }
+<a name="l03538"></a>03538                 col_index++ ;
+<a name="l03539"></a>03539             }
+<a name="l03540"></a>03540 
+<a name="l03541"></a>03541         }
+<a name="l03542"></a>03542     }
+<a name="l03543"></a>03543 
+<a name="l03544"></a>03544 
+<a name="l03545"></a>03545     cpl_free(edge) ;
+<a name="l03546"></a>03546     cpl_free(sub_col_index) ;
+<a name="l03547"></a>03547     cpl_free(sub_acoefs);
+<a name="l03548"></a>03548     cpl_free(sub_dacoefs) ;
+<a name="l03549"></a>03549     cpl_free(wcoefs) ;
+<a name="l03550"></a>03550 
+<a name="l03551"></a>03551     <span class="keywordflow">return</span> 0 ;
+<a name="l03552"></a>03552 }
+<a name="l03553"></a>03553 
+<a name="l03554"></a>03554 
+<a name="l03603"></a>03603 cpl_image * sinfo_new_spred_wave_cal( cpl_image   * image,
+<a name="l03604"></a>03604                     FitParams ** par ,
+<a name="l03605"></a>03605                     <span class="keywordtype">float</span>     ** abuf,
+<a name="l03606"></a>03606                     <span class="keywordtype">int</span>          n_slitlets,
+<a name="l03607"></a>03607                     <span class="keywordtype">int</span>       ** row_clean,
+<a name="l03608"></a>03608                     <span class="keywordtype">float</span>     ** wavelength_clean,
+<a name="l03609"></a>03609                     <span class="keywordtype">int</span>        * n_found_lines,
+<a name="l03610"></a>03610                     <span class="keywordtype">float</span>        dispersion,
+<a name="l03611"></a>03611                     <span class="keywordtype">int</span>          halfWidth,
+<a name="l03612"></a>03612                     <span class="keywordtype">float</span>        minAmplitude,
+<a name="l03613"></a>03613                     <span class="keywordtype">float</span>        max_residual,
+<a name="l03614"></a>03614                     <span class="keywordtype">float</span>        fwhm,
+<a name="l03615"></a>03615                     <span class="keywordtype">int</span>          n_a_fitcoefs,
+<a name="l03616"></a>03616                     <span class="keywordtype">int</span>          n_b_fitcoefs,
+<a name="l03617"></a>03617                     <span class="keywordtype">float</span>        sigmaFactor,
+<a name="l03618"></a>03618                     <span class="keywordtype">float</span>        pixel_dist,
+<a name="l03619"></a>03619                     <span class="keywordtype">float</span>        pixel_tolerance,
+<a name="l03620"></a>03620                   <span class="keywordtype">float</span> ** sinfo_slit_pos)
+<a name="l03621"></a>03621 
+<a name="l03622"></a>03622 
+<a name="l03623"></a>03623 {
+<a name="l03624"></a>03624     <span class="keywordtype">int</span>          i, j, k ;
+<a name="l03625"></a>03625     <span class="keywordtype">int</span>          n_fit ;
+<a name="l03626"></a>03626     <span class="keywordtype">int</span>          n_reject ;
+<a name="l03627"></a>03627     <span class="keywordtype">float</span>     *  acoefs ;
+<a name="l03628"></a>03628     <span class="keywordtype">float</span>     *  dacoefs ;
+<a name="l03629"></a>03629     <span class="keywordtype">float</span>     ** dabuf ;
+<a name="l03630"></a>03630     <span class="keywordtype">float</span>        chisq_poly ;
+<a name="l03631"></a>03631     <span class="keywordtype">float</span>     *  chisq_cross ;
+<a name="l03632"></a>03632     <span class="keywordtype">int</span>          zeroind ;
+<a name="l03633"></a>03633     <span class="keywordtype">int</span>          crossInd ;
+<a name="l03634"></a>03634     Bcoeffs   *  bco ;
+<a name="l03635"></a>03635     cpl_image  *  wavemap ;
+<a name="l03636"></a>03636     <span class="keywordtype">int</span> ilx=0;
+<a name="l03637"></a>03637     <span class="keywordtype">int</span> ily=0;
+<a name="l03638"></a>03638     <span class="keywordtype">float</span>* pidata=NULL;
+<a name="l03639"></a>03639 
+<a name="l03640"></a>03640 
+<a name="l03641"></a>03641     <span class="keywordflow">if</span> (  NULL == image )
+<a name="l03642"></a>03642     {
+<a name="l03643"></a>03643         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" no image given\n"</span>) ;
+<a name="l03644"></a>03644         <span class="keywordflow">return</span> NULL ;
+<a name="l03645"></a>03645     }
+<a name="l03646"></a>03646     ilx=cpl_image_get_size_x(image);
+<a name="l03647"></a>03647     ily=cpl_image_get_size_y(image);
+<a name="l03648"></a>03648     pidata=cpl_image_get_data_float(image);
+<a name="l03649"></a>03649 
+<a name="l03650"></a>03650     <span class="keywordflow">if</span> ( par == NULL )
+<a name="l03651"></a>03651     {
+<a name="l03652"></a>03652         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" no fit parameter data structure given\n"</span>) ;
+<a name="l03653"></a>03653         <span class="keywordflow">return</span> NULL ;
+<a name="l03654"></a>03654     }
+<a name="l03655"></a>03655     <span class="keywordflow">if</span> ( abuf == NULL )
+<a name="l03656"></a>03656     {
+<a name="l03657"></a>03657         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" no buffer for fit coefficients given\n"</span>) ;
+<a name="l03658"></a>03658         <span class="keywordflow">return</span> NULL ;
+<a name="l03659"></a>03659     }
+<a name="l03660"></a>03660     <span class="keywordflow">if</span> ( n_slitlets <= 0 )
+<a name="l03661"></a>03661     {
+<a name="l03662"></a>03662         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" impossible number of slitlets given\n"</span>) ;
+<a name="l03663"></a>03663         <span class="keywordflow">return</span> NULL ;
+<a name="l03664"></a>03664     }
+<a name="l03665"></a>03665     <span class="keywordflow">if</span> ( row_clean == NULL )
+<a name="l03666"></a>03666     {
+<a name="l03667"></a>03667         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" no row_clean array given\n"</span>) ;
+<a name="l03668"></a>03668         <span class="keywordflow">return</span> NULL ;
+<a name="l03669"></a>03669     }
+<a name="l03670"></a>03670     <span class="keywordflow">if</span> ( wavelength_clean == NULL )
+<a name="l03671"></a>03671     {
+<a name="l03672"></a>03672         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" no wavelength_clean array given\n"</span>) ;
+<a name="l03673"></a>03673         <span class="keywordflow">return</span> NULL ;
+<a name="l03674"></a>03674     }
+<a name="l03675"></a>03675 
+<a name="l03676"></a>03676     <span class="keywordflow">if</span> ( dispersion == 0. )
+<a name="l03677"></a>03677     {
+<a name="l03678"></a>03678         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" impossible dispersion given\n"</span>) ;
+<a name="l03679"></a>03679         <span class="keywordflow">return</span> NULL ;
+<a name="l03680"></a>03680     }
+<a name="l03681"></a>03681 
+<a name="l03682"></a>03682     <span class="keywordflow">if</span> ( halfWidth <= 0 || halfWidth > ily/2 )
+<a name="l03683"></a>03683     {
+<a name="l03684"></a>03684         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" impossible half width of the fitting box given\n"</span>) ;
+<a name="l03685"></a>03685         <span class="keywordflow">return</span> NULL ;
+<a name="l03686"></a>03686     }
+<a name="l03687"></a>03687     <span class="keywordflow">if</span> ( minAmplitude < 1. )
+<a name="l03688"></a>03688      {
+<a name="l03689"></a>03689          <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" impossible minimal amplitude\n"</span>) ;
+<a name="l03690"></a>03690          <span class="keywordflow">return</span> NULL ;
+<a name="l03691"></a>03691      }
+<a name="l03692"></a>03692 
+<a name="l03693"></a>03693      <span class="keywordflow">if</span> ( max_residual <= 0. || max_residual > 1. )
+<a name="l03694"></a>03694      {
+<a name="l03695"></a>03695          <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" impossible max_residual given\n"</span>) ;
+<a name="l03696"></a>03696          <span class="keywordflow">return</span> NULL ;
+<a name="l03697"></a>03697      }
+<a name="l03698"></a>03698      <span class="keywordflow">if</span> ( fwhm <= 0. || fwhm > 10. )
+<a name="l03699"></a>03699      {
+<a name="l03700"></a>03700          <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" impossible fwhm given\n"</span>) ;
+<a name="l03701"></a>03701          <span class="keywordflow">return</span> NULL ;
+<a name="l03702"></a>03702      }
+<a name="l03703"></a>03703 
+<a name="l03704"></a>03704      <span class="keywordflow">if</span> ( n_a_fitcoefs <= 0 || n_a_fitcoefs > 9 )
+<a name="l03705"></a>03705      {
+<a name="l03706"></a>03706          <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" unrealistic n_a_fitcoefs given\n"</span>) ;
+<a name="l03707"></a>03707          <span class="keywordflow">return</span> NULL ;
+<a name="l03708"></a>03708      }
+<a name="l03709"></a>03709 
+<a name="l03710"></a>03710      <span class="keywordflow">if</span> ( n_b_fitcoefs <= 0 || n_b_fitcoefs > 9 )
+<a name="l03711"></a>03711      {
+<a name="l03712"></a>03712          <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" unrealistic n_b_fitcoefs given\n"</span>) ;
+<a name="l03713"></a>03713          <span class="keywordflow">return</span> NULL ;
+<a name="l03714"></a>03714      }
+<a name="l03715"></a>03715      <span class="keywordflow">if</span> ( sigmaFactor <= 0. )
+<a name="l03716"></a>03716      {
+<a name="l03717"></a>03717          <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" impossible sigmaFactor given\n"</span>) ;
+<a name="l03718"></a>03718          <span class="keywordflow">return</span> NULL ;
+<a name="l03719"></a>03719      }
+<a name="l03720"></a>03720 
+<a name="l03721"></a>03721      <span class="comment">/* initialize the variables */</span>
+<a name="l03722"></a>03722      n_reject = 0 ;
+<a name="l03723"></a>03723      n_fit = 0 ;
+<a name="l03724"></a>03724 
+<a name="l03725"></a>03725      <span class="comment">/* fit each found line by using a sinfo_gaussian function and </span>
+<a name="l03726"></a>03726 <span class="comment">        determine the exact position */</span>
+<a name="l03727"></a>03727      <span class="keywordflow">if</span> ( 0 > (n_fit = sinfo_new_fit_lines( image , par, fwhm, n_found_lines, 
+<a name="l03728"></a>03728                                       row_clean, wavelength_clean,
+<a name="l03729"></a>03729                                       halfWidth, minAmplitude )) )
+<a name="l03730"></a>03730      {
+<a name="l03731"></a>03731          <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" cannot fit the lines, error code of "</span>
+<a name="l03732"></a>03732                          <span class="stringliteral">"sinfo_fitLines: %d"</span>, n_fit) ;
+<a name="l03733"></a>03733          <span class="keywordflow">return</span> NULL ;
+<a name="l03734"></a>03734      }
+<a name="l03735"></a>03735 
+<a name="l03736"></a>03736      <span class="comment">/* first check for faked lines like bad pixels */</span>
+<a name="l03737"></a>03737      <span class="keywordflow">if</span> ( -1 == sinfo_new_check_for_fake_lines (par, 
+<a name="l03738"></a>03738                                                 dispersion, 
+<a name="l03739"></a>03739                                                 wavelength_clean, 
+<a name="l03740"></a>03740                                                 row_clean, 
+<a name="l03741"></a>03741                                                 n_found_lines,
+<a name="l03742"></a>03742                                                 ilx, 
+<a name="l03743"></a>03743                                                 pixel_tolerance) )
+<a name="l03744"></a>03744      {
+<a name="l03745"></a>03745          <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" cannot fit the lines, error code of "</span>
+<a name="l03746"></a>03746                          <span class="stringliteral">" sinfo_fitLines: %d\n"</span>, n_fit) ;
+<a name="l03747"></a>03747          <span class="keywordflow">return</span> NULL ;
+<a name="l03748"></a>03748      }
+<a name="l03749"></a>03749 
+<a name="l03750"></a>03750 
+<a name="l03751"></a>03751      <span class="comment">/* allocate memory */</span>
+<a name="l03752"></a>03752      <span class="keywordflow">if</span> (NULL==(acoefs = (<span class="keywordtype">float</span>*) cpl_calloc (n_a_fitcoefs, <span class="keyword">sizeof</span>(<span class="keywordtype">float</span>))) ||
+<a name="l03753"></a>03753          NULL==(dacoefs = (<span class="keywordtype">float</span>*) cpl_calloc (n_a_fitcoefs, <span class="keyword">sizeof</span>(<span class="keywordtype">float</span>))) ||
+<a name="l03754"></a>03754          NULL==(dabuf = (<span class="keywordtype">float</span>**) cpl_calloc (n_a_fitcoefs, <span class="keyword">sizeof</span>(<span class="keywordtype">float</span>*))) ||
+<a name="l03755"></a>03755          NULL==(chisq_cross = (<span class="keywordtype">float</span>*) cpl_calloc(n_slitlets, <span class="keyword">sizeof</span>(<span class="keywordtype">float</span>))) )
+<a name="l03756"></a>03756      {
+<a name="l03757"></a>03757          <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" cannot allocate memory\n"</span>) ;
+<a name="l03758"></a>03758          <span class="keywordflow">return</span> NULL ;
+<a name="l03759"></a>03759      }
+<a name="l03760"></a>03760      <span class="keywordflow">for</span> ( i = 0 ; i < n_a_fitcoefs ; i++ )
+<a name="l03761"></a>03761      {
+<a name="l03762"></a>03762          <span class="keywordflow">if</span> (  NULL == (dabuf[i] = (<span class="keywordtype">float</span>*) cpl_calloc(ilx, <span class="keyword">sizeof</span>(<span class="keywordtype">float</span>))) )
+<a name="l03763"></a>03763          {
+<a name="l03764"></a>03764              <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">" cannot allocate memory\n"</span>) ;
+<a name="l03765"></a>03765              cpl_free ( acoefs ) ;
+<a name="l03766"></a>03766              cpl_free ( dacoefs ) ;
+<a name="l03767"></a>03767              cpl_free ( chisq_cross ) ;
+<a name="l03768"></a>03768              cpl_free(dabuf) ;
+<a name="l03769"></a>03769              <span class="keywordflow">return</span> NULL ;
+<a name="l03770"></a>03770          }
+<a name="l03771"></a>03771      }
+<a name="l03772"></a>03772 
+<a name="l03773"></a>03773      <span class="comment">/* fit wavelengths to the corresponding found positions for each column */</span>
+<a name="l03774"></a>03774      k = 0 ;
+<a name="l03775"></a>03775      <span class="keywordflow">for</span> ( i = 0 ; i < ilx ; i++ )
+<a name="l03776"></a>03776      {
+<a name="l03777"></a>03777          zeroind = 0 ;
+<a name="l03778"></a>03778          <span class="keywordflow">if</span> ( FLT_MAX == (chisq_poly = sinfo_new_polyfit( par, i, 
+<a name="l03779"></a>03779                                                          n_found_lines[i], 
+<a name="l03780"></a>03780                                                          ily, dispersion,
+<a name="l03781"></a>03781                                                          max_residual, acoefs,
+<a name="l03782"></a>03782                                                          dacoefs, &n_reject, 
+<a name="l03783"></a>03783                                                          n_a_fitcoefs)) )
+<a name="l03784"></a>03784          {
+<a name="l03785"></a>03785              <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a> (<span class="stringliteral">" error in sinfo_polyfit in column: %d\n"</span>, i) ;
+<a name="l03786"></a>03786              <span class="keywordflow">for</span> ( j = 0 ; j < n_a_fitcoefs ; j++ )
+<a name="l03787"></a>03787              {
+<a name="l03788"></a>03788                  acoefs[j] = ZERO ;
+<a name="l03789"></a>03789                  dacoefs[j] = ZERO ;
+<a name="l03790"></a>03790              }
+<a name="l03791"></a>03791          }
+<a name="l03792"></a>03792 
+<a name="l03793"></a>03793          <span class="keywordflow">for</span> ( j = 0 ; j < n_a_fitcoefs ; j++ )
+<a name="l03794"></a>03794          {
+<a name="l03795"></a>03795 
+<a name="l03796"></a>03796              <span class="keywordflow">if</span> ( acoefs[0] <= 0. || acoefs[1] ==0. ||
+<a name="l03797"></a>03797                   dacoefs[j] == 0. || isnan(acoefs[j]) )
+<a name="l03798"></a>03798              {
+<a name="l03799"></a>03799                  zeroind = 1 ;
+<a name="l03800"></a>03800              }
+<a name="l03801"></a>03801          }
+<a name="l03802"></a>03802          <span class="keywordflow">for</span> ( j = 0 ; j < n_a_fitcoefs ; j++ )
+<a name="l03803"></a>03803          {
+<a name="l03804"></a>03804              <span class="keywordflow">if</span> ( zeroind == 0 )
+<a name="l03805"></a>03805              {
+<a name="l03806"></a>03806                  abuf[j][i]  = acoefs[j] ;
+<a name="l03807"></a>03807                  dabuf[j][i] = dacoefs[j] ;
+<a name="l03808"></a>03808              }
+<a name="l03809"></a>03809              <span class="keywordflow">else</span>
+<a name="l03810"></a>03810              {
+<a name="l03811"></a>03811                  abuf[j][i]  = ZERO ;
+<a name="l03812"></a>03812                  dabuf[j][i] = ZERO ;
+<a name="l03813"></a>03813              }
+<a name="l03814"></a>03814          }
+<a name="l03815"></a>03815      }
+<a name="l03816"></a>03816 
+<a name="l03817"></a>03817      <span class="comment">/* allocate memory for the fitting coefficients */</span>
+<a name="l03818"></a>03818      <span class="keywordflow">if</span> ( NULL == ( bco = sinfo_new_b_coeffs( n_slitlets, 
+<a name="l03819"></a>03819                                               n_a_fitcoefs, n_b_fitcoefs)) )
+<a name="l03820"></a>03820      {
+<a name="l03821"></a>03821          <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" cannot allocate memory for the bcoeffs\n"</span>) ;
+<a name="l03822"></a>03822          <span class="keywordflow">for</span> ( i = 0 ; i < n_a_fitcoefs ; i++ )
+<a name="l03823"></a>03823          {
+<a name="l03824"></a>03824              cpl_free (dabuf[i]) ;
+<a name="l03825"></a>03825          }
+<a name="l03826"></a>03826          cpl_free (dabuf) ;
+<a name="l03827"></a>03827          cpl_free ( acoefs ) ;
+<a name="l03828"></a>03828          cpl_free ( dacoefs ) ;
+<a name="l03829"></a>03829          cpl_free ( chisq_cross ) ;
+<a name="l03830"></a>03830          <span class="keywordflow">return</span> NULL ;
+<a name="l03831"></a>03831      }
+<a name="l03832"></a>03832 
+<a name="l03833"></a>03833      <span class="comment">/* fit each acoefs across the slitlets to smooth the result */</span>
+<a name="l03834"></a>03834      <span class="keywordflow">if</span> ( -1 == ( crossInd = sinfo_new_spred_coeffs_cross_slit_fit( ilx, abuf, 
+<a name="l03835"></a>03835                                                                     dabuf,
+<a name="l03836"></a>03836                                                              bco, sigmaFactor,
+<a name="l03837"></a>03837                                                              dispersion, 
+<a name="l03838"></a>03838                                                              pixel_dist, 
+<a name="l03839"></a>03839                                                              chisq_cross,
+<a name="l03840"></a>03840                                                              sinfo_slit_pos )) )
+<a name="l03841"></a>03841      {
+<a name="l03842"></a>03842          <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" cannot carry out the fitting of "</span>
+<a name="l03843"></a>03843                           <span class="stringliteral">"coefficients across the columns\n"</span>) ;
+<a name="l03844"></a>03844          <span class="keywordflow">for</span> ( i = 0 ; i < n_a_fitcoefs ; i++ )
+<a name="l03845"></a>03845          {
+<a name="l03846"></a>03846              cpl_free (dabuf[i]) ;
+<a name="l03847"></a>03847          }
+<a name="l03848"></a>03848 
+<a name="l03849"></a>03849          cpl_free (dabuf) ;
+<a name="l03850"></a>03850          cpl_free ( acoefs ) ;
+<a name="l03851"></a>03851          cpl_free ( dacoefs ) ;
+<a name="l03852"></a>03852          sinfo_new_destroy_b_coeffs(bco) ;
+<a name="l03853"></a>03853          cpl_free ( chisq_cross ) ;
+<a name="l03854"></a>03854          <span class="keywordflow">return</span> NULL ;
+<a name="l03855"></a>03855      }
+<a name="l03856"></a>03856 
+<a name="l03857"></a>03857      <span class="keywordflow">if</span> ( NULL == (wavemap = sinfo_new_wave_map_slit (abuf, n_a_fitcoefs, 
+<a name="l03858"></a>03858                                                       ily, ilx)))
+<a name="l03859"></a>03859      {
+<a name="l03860"></a>03860          <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">" cannot carry out wavemap creation\n"</span>) ;
+<a name="l03861"></a>03861          <span class="keywordflow">for</span> ( i = 0 ; i < n_a_fitcoefs ; i++ )
+<a name="l03862"></a>03862          {
+<a name="l03863"></a>03863              cpl_free (dabuf[i]) ;
+<a name="l03864"></a>03864          }
+<a name="l03865"></a>03865 
+<a name="l03866"></a>03866          cpl_free (dabuf) ;
+<a name="l03867"></a>03867          cpl_free ( acoefs ) ;
+<a name="l03868"></a>03868          cpl_free ( dacoefs ) ;
+<a name="l03869"></a>03869          sinfo_new_destroy_b_coeffs(bco) ;
+<a name="l03870"></a>03870          cpl_free ( chisq_cross ) ;
+<a name="l03871"></a>03871          <span class="keywordflow">return</span> NULL ;
+<a name="l03872"></a>03872      }
+<a name="l03873"></a>03873 
+<a name="l03874"></a>03874      <span class="comment">/* free all allocated memory */</span>
+<a name="l03875"></a>03875      <span class="keywordflow">for</span> ( i = 0 ; i < n_a_fitcoefs ; i++ )
+<a name="l03876"></a>03876      {
+<a name="l03877"></a>03877          cpl_free (dabuf[i]) ;
+<a name="l03878"></a>03878      }
+<a name="l03879"></a>03879      cpl_free (dabuf) ;
+<a name="l03880"></a>03880      cpl_free ( acoefs ) ;
+<a name="l03881"></a>03881      cpl_free ( dacoefs ) ;
+<a name="l03882"></a>03882      sinfo_new_destroy_b_coeffs(bco) ;
+<a name="l03883"></a>03883      cpl_free ( chisq_cross ) ;
+<a name="l03884"></a>03884 
+<a name="l03885"></a>03885      <span class="keywordflow">return</span> wavemap ;
+<a name="l03886"></a>03886  }
+<a name="l03887"></a>03887 
+<a name="l03889"></a>03889 <span class="comment">/*___oOo___*/</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__wavecal_8h_source.html b/html/sinfo__wavecal_8h_source.html
new file mode 100644
index 0000000..1d0450b
--- /dev/null
+++ b/html/sinfo__wavecal_8h_source.html
@@ -0,0 +1,170 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_wavecal.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_wavecal.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#ifndef SINFO_WAVECAL_H</span>
+<a name="l00002"></a>00002 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_WAVECAL_H</span>
+<a name="l00003"></a>00003 <span class="preprocessor"></span><span class="comment">/*</span>
+<a name="l00004"></a>00004 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00005"></a>00005 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00006"></a>00006 <span class="comment"> *</span>
+<a name="l00007"></a>00007 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00008"></a>00008 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00009"></a>00009 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00010"></a>00010 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00011"></a>00011 <span class="comment"> *</span>
+<a name="l00012"></a>00012 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00013"></a>00013 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00014"></a>00014 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00015"></a>00015 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00016"></a>00016 <span class="comment"> *</span>
+<a name="l00017"></a>00017 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00018"></a>00018 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00019"></a>00019 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00020"></a>00020 <span class="comment"> */</span>
+<a name="l00021"></a>00021 <span class="comment">/************************************************************************</span>
+<a name="l00022"></a>00022 <span class="comment">* E.S.O. - VLT project</span>
+<a name="l00023"></a>00023 <span class="comment">*</span>
+<a name="l00024"></a>00024 <span class="comment">* "@(#) $Id: sinfo_wavecal.h,v 1.5 2007/06/06 07:10:46 amodigli Exp $"</span>
+<a name="l00025"></a>00025 <span class="comment">*</span>
+<a name="l00026"></a>00026 <span class="comment">* who       when      what</span>
+<a name="l00027"></a>00027 <span class="comment">* --------  --------  ----------------------------------------------</span>
+<a name="l00028"></a>00028 <span class="comment">* schreib  13/07/00  created</span>
+<a name="l00029"></a>00029 <span class="comment">*/</span>
+<a name="l00030"></a>00030 
+<a name="l00031"></a>00031 <span class="comment">/************************************************************************</span>
+<a name="l00032"></a>00032 <span class="comment"> * sinfo_wavecal.h</span>
+<a name="l00033"></a>00033 <span class="comment"> * routines needed for wavelength calibration</span>
+<a name="l00034"></a>00034 <span class="comment"> *----------------------------------------------------------------------</span>
+<a name="l00035"></a>00035 <span class="comment"> */</span>
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="comment">/*</span>
+<a name="l00038"></a>00038 <span class="comment"> * header files</span>
+<a name="l00039"></a>00039 <span class="comment"> */</span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include "sinfo_spectrum_ops.h"</span>
+<a name="l00042"></a>00042 
+<a name="l00043"></a>00043 <span class="comment">/*</span>
+<a name="l00044"></a>00044 <span class="comment"> * function prototypes</span>
+<a name="l00045"></a>00045 <span class="comment"> */</span>
+<a name="l00046"></a>00046 
+<a name="l00057"></a>00057 cpl_image * 
+<a name="l00058"></a>00058 sinfo_new_wave_map_slit ( <span class="keywordtype">float</span> ** acoefs,
+<a name="l00059"></a>00059                          <span class="keywordtype">int</span>      n_acoefs,
+<a name="l00060"></a>00060                          <span class="keywordtype">int</span>      n_rows,
+<a name="l00061"></a>00061                          <span class="keywordtype">int</span>      n_columns ) ;
+<a name="l00062"></a>00062 
+<a name="l00107"></a>00107 cpl_image * 
+<a name="l00108"></a>00108 sinfo_new_wave_cal(cpl_image   * image,
+<a name="l00109"></a>00109                     FitParams ** par ,
+<a name="l00110"></a>00110                     <span class="keywordtype">float</span>     ** abuf,
+<a name="l00111"></a>00111                     <span class="keywordtype">int</span>          n_slitlets,
+<a name="l00112"></a>00112                     <span class="keywordtype">int</span>       ** row_clean,
+<a name="l00113"></a>00113                     <span class="keywordtype">float</span>     ** wavelength_clean,
+<a name="l00114"></a>00114                     <span class="keywordtype">int</span>        * n_found_lines,
+<a name="l00115"></a>00115                     <span class="keywordtype">float</span>        dispersion,
+<a name="l00116"></a>00116                     <span class="keywordtype">int</span>          halfWidth,
+<a name="l00117"></a>00117                     <span class="keywordtype">float</span>        minAmplitude,
+<a name="l00118"></a>00118                     <span class="keywordtype">float</span>        max_residual,
+<a name="l00119"></a>00119                     <span class="keywordtype">float</span>        fwhm,
+<a name="l00120"></a>00120                     <span class="keywordtype">int</span>          n_a_fitcoefs,
+<a name="l00121"></a>00121                     <span class="keywordtype">int</span>          n_b_fitcoefs,
+<a name="l00122"></a>00122                     <span class="keywordtype">float</span>        sigmaFactor,
+<a name="l00123"></a>00123                     <span class="keywordtype">float</span>        pixel_dist,
+<a name="l00124"></a>00124             <span class="keywordtype">float</span>        pixel_tolerance ) ;
+<a name="l00125"></a>00125 
+<a name="l00126"></a>00126 
+<a name="l00170"></a>00170  cpl_image * sinfo_new_spred_wave_cal(cpl_image   * image,
+<a name="l00171"></a>00171                      FitParams ** par ,
+<a name="l00172"></a>00172                      <span class="keywordtype">float</span>     ** abuf,
+<a name="l00173"></a>00173                      <span class="keywordtype">int</span>          n_slitlets,
+<a name="l00174"></a>00174                      <span class="keywordtype">int</span>       ** row_clean,
+<a name="l00175"></a>00175                      <span class="keywordtype">float</span>     ** wavelength_clean,
+<a name="l00176"></a>00176                      <span class="keywordtype">int</span>        * n_found_lines,
+<a name="l00177"></a>00177                      <span class="keywordtype">float</span>        dispersion,
+<a name="l00178"></a>00178                      <span class="keywordtype">int</span>          halfWidth,
+<a name="l00179"></a>00179                      <span class="keywordtype">float</span>        minAmplitude,
+<a name="l00180"></a>00180                      <span class="keywordtype">float</span>        max_residual,
+<a name="l00181"></a>00181                      <span class="keywordtype">float</span>        fwhm,
+<a name="l00182"></a>00182                      <span class="keywordtype">int</span>          n_a_fitcoefs,
+<a name="l00183"></a>00183                      <span class="keywordtype">int</span>          n_b_fitcoefs,
+<a name="l00184"></a>00184                      <span class="keywordtype">float</span>        sigmaFactor,
+<a name="l00185"></a>00185                      <span class="keywordtype">float</span>        pixel_dist,
+<a name="l00186"></a>00186                      <span class="keywordtype">float</span>        pixel_tolerance,
+<a name="l00187"></a>00187                      <span class="keywordtype">float</span> **sinfo_slit_pos ) ;
+<a name="l00188"></a>00188 
+<a name="l00189"></a>00189 
+<a name="l00207"></a>00207 <span class="keywordtype">int</span> 
+<a name="l00208"></a>00208 sinfo_new_check_for_fake_lines ( FitParams ** par,
+<a name="l00209"></a>00209                        <span class="keywordtype">float</span>        dispersion,
+<a name="l00210"></a>00210                         <span class="keywordtype">float</span>     ** wavelength_clean,
+<a name="l00211"></a>00211             <span class="keywordtype">int</span>       ** row_clean,
+<a name="l00212"></a>00212             <span class="keywordtype">int</span>        * n_found_lines,
+<a name="l00213"></a>00213             <span class="keywordtype">int</span>          n_columns,
+<a name="l00214"></a>00214             <span class="keywordtype">float</span>        pixel_tolerance ) ;
+<a name="l00215"></a>00215 
+<a name="l00216"></a>00216 
+<a name="l00235"></a>00235 cpl_image * 
+<a name="l00236"></a>00236 sinfo_new_create_shifted_slit_wavemap (cpl_image * lineIm,
+<a name="l00237"></a>00237                                       <span class="keywordtype">float</span>    ** coeffs,
+<a name="l00238"></a>00238                                       <span class="keywordtype">int</span>      n_fitcoeffs,
+<a name="l00239"></a>00239                                       <span class="keywordtype">float</span>  * wavelength,
+<a name="l00240"></a>00240                                       <span class="keywordtype">float</span>  * intensity,
+<a name="l00241"></a>00241                                       <span class="keywordtype">int</span>      n_lines,
+<a name="l00242"></a>00242                                       <span class="keywordtype">int</span>      magFactor ) ;
+<a name="l00266"></a>00266 cpl_image * 
+<a name="l00267"></a>00267 sinfo_new_create_shifted_slit_wavemap2 (cpl_image * lineIm,
+<a name="l00268"></a>00268                                       <span class="keywordtype">float</span>    ** coeffs,
+<a name="l00269"></a>00269                                       <span class="keywordtype">int</span>      n_fitcoeffs,
+<a name="l00270"></a>00270                                       <span class="keywordtype">float</span>  * wavelength,
+<a name="l00271"></a>00271                                       <span class="keywordtype">float</span>  * intensity,
+<a name="l00272"></a>00272                                       <span class="keywordtype">int</span>      n_lines,
+<a name="l00273"></a>00273                                       <span class="keywordtype">int</span>      magFactor,
+<a name="l00274"></a>00274                                       <span class="keywordtype">float</span>    dispersion,
+<a name="l00275"></a>00275                                       <span class="keywordtype">float</span>    pixel_dist ) ;
+<a name="l00276"></a>00276 
+<a name="l00277"></a>00277 
+<a name="l00299"></a>00299 cpl_image * 
+<a name="l00300"></a>00300 sinfo_new_create_shifted_slit_wavemap3 (cpl_image * lineIm,
+<a name="l00301"></a>00301                                       <span class="keywordtype">float</span>    ** coeffs,
+<a name="l00302"></a>00302                                       <span class="keywordtype">int</span>      n_fitcoeffs,
+<a name="l00303"></a>00303                                       <span class="keywordtype">float</span>  * wavelength,
+<a name="l00304"></a>00304                                       <span class="keywordtype">float</span>  * intensity,
+<a name="l00305"></a>00305                                       <span class="keywordtype">int</span>      n_lines,
+<a name="l00306"></a>00306                                       <span class="keywordtype">int</span>      magFactor ) ;
+<a name="l00307"></a>00307 
+<a name="l00308"></a>00308 
+<a name="l00329"></a>00329 <span class="keywordtype">float</span> sinfo_new_check_line_positions ( cpl_image     * lineIm,
+<a name="l00330"></a>00330                        <span class="keywordtype">float</span>       ** coeffs,
+<a name="l00331"></a>00331                        <span class="keywordtype">int</span>            n_fitcoeffs,
+<a name="l00332"></a>00332                        <span class="keywordtype">float</span>           guess_disp1,
+<a name="l00333"></a>00333                        FitParams   ** par );
+<a name="l00334"></a>00334 
+<a name="l00360"></a>00360 <span class="keywordtype">float</span> 
+<a name="l00361"></a>00361 sinfo_new_check_correlated_line_positions (cpl_image     * lineIm,
+<a name="l00362"></a>00362                                      <span class="keywordtype">float</span>       ** coeffs,
+<a name="l00363"></a>00363                                      <span class="keywordtype">int</span>            n_fitcoeffs,
+<a name="l00364"></a>00364                                      <span class="keywordtype">float</span>        * wavelength,
+<a name="l00365"></a>00365                                      <span class="keywordtype">float</span>        * intensity,
+<a name="l00366"></a>00366                                      <span class="keywordtype">int</span>            n_lines,
+<a name="l00367"></a>00367                                      <span class="keywordtype">float</span>          fwhm,
+<a name="l00368"></a>00368                                      <span class="keywordtype">float</span>          width,
+<a name="l00369"></a>00369                                      <span class="keywordtype">float</span>          min_amplitude,
+<a name="l00370"></a>00370                                      <span class="keywordtype">float</span>          dispersion,
+<a name="l00371"></a>00371                                      FitParams   ** par ) ;
+<a name="l00372"></a>00372 
+<a name="l00373"></a>00373 
+<a name="l00374"></a>00374 
+<a name="l00375"></a>00375 <span class="preprocessor">#endif </span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__wavecal__cfg_8c_source.html b/html/sinfo__wavecal__cfg_8c_source.html
new file mode 100644
index 0000000..f75a5eb
--- /dev/null
+++ b/html/sinfo__wavecal__cfg_8c_source.html
@@ -0,0 +1,89 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_wavecal_cfg.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_wavecal_cfg.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 
+<a name="l00020"></a>00020 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00021"></a>00021 <span class="comment">   </span>
+<a name="l00022"></a>00022 <span class="comment">   File name     :    sinfo_wavecal_cfg.c</span>
+<a name="l00023"></a>00023 <span class="comment">   Author         : Juergen Schreiber</span>
+<a name="l00024"></a>00024 <span class="comment">   Created on    :    September 2001</span>
+<a name="l00025"></a>00025 <span class="comment">   Description    :    wavelength calibration configuration handling tools</span>
+<a name="l00026"></a>00026 <span class="comment"></span>
+<a name="l00027"></a>00027 <span class="comment"> *--------------------------------------------------------------------------*/</span>
+<a name="l00028"></a>00028 
+<a name="l00029"></a>00029 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00031"></a>00031 <span class="preprocessor">#endif</span>
+<a name="l00032"></a>00032 <span class="preprocessor"></span>
+<a name="l00033"></a>00033 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00034"></a>00034 <span class="comment">                                   Includes</span>
+<a name="l00035"></a>00035 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="preprocessor">#include "sinfo_wavecal_cfg.h"</span>
+<a name="l00038"></a>00038 
+<a name="l00046"></a>00046 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00047"></a>00047 <span class="comment">                              Function codes</span>
+<a name="l00048"></a>00048 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00049"></a>00049 
+<a name="l00050"></a>00050 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00051"></a>00051 <span class="comment">   Function :   sinfo_wave_cfg_create()</span>
+<a name="l00052"></a>00052 <span class="comment">   In       :   void</span>
+<a name="l00053"></a>00053 <span class="comment">   Out      :   pointer to allocated base wave_config structure</span>
+<a name="l00054"></a>00054 <span class="comment">   Job      :   allocate memory for a wave_config struct</span>
+<a name="l00055"></a>00055 <span class="comment">   Notice   :   only the main (base) structure is allocated</span>
+<a name="l00056"></a>00056 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00057"></a>00057 
+<a name="l00058"></a>00058 wave_config * sinfo_wave_cfg_create(<span class="keywordtype">void</span>)
+<a name="l00059"></a>00059 {
+<a name="l00060"></a>00060     <span class="keywordflow">return</span> cpl_calloc(1, <span class="keyword">sizeof</span>(wave_config));
+<a name="l00061"></a>00061 }
+<a name="l00062"></a>00062 
+<a name="l00063"></a>00063 
+<a name="l00064"></a>00064 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00065"></a>00065 <span class="comment">   Function :   sinfo_wave_cfg_destroy()</span>
+<a name="l00066"></a>00066 <span class="comment">   In       :   wave_config to deallocate</span>
+<a name="l00067"></a>00067 <span class="comment">   Out      :   void</span>
+<a name="l00068"></a>00068 <span class="comment">   Job      :   deallocate all memory associated with a wave_config</span>
+<a name="l00069"></a>00069 <span class="comment">   Notice   :   </span>
+<a name="l00070"></a>00070 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00071"></a>00071 
+<a name="l00072"></a>00072 <span class="keywordtype">void</span> sinfo_wave_cfg_destroy(wave_config * wc)
+<a name="l00073"></a>00073 {
+<a name="l00074"></a>00074     <span class="keywordflow">if</span> (wc==NULL) return ;
+<a name="l00075"></a>00075 
+<a name="l00076"></a>00076     <span class="comment">/* Free main struct */</span>
+<a name="l00077"></a>00077     cpl_free(wc);
+<a name="l00078"></a>00078 
+<a name="l00079"></a>00079     return ;
+<a name="l00080"></a>00080 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__wavecal__cfg_8h_source.html b/html/sinfo__wavecal__cfg_8h_source.html
new file mode 100644
index 0000000..6caa63d
--- /dev/null
+++ b/html/sinfo__wavecal__cfg_8h_source.html
@@ -0,0 +1,173 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_wavecal_cfg.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_wavecal_cfg.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name     :    sinfo_wavecal_cfg.h</span>
+<a name="l00022"></a>00022 <span class="comment">   Author         :    Juergen Schreiber</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on    :    September 2001</span>
+<a name="l00024"></a>00024 <span class="comment">   Description    :    wavecal_ini definitions + handling prototypes</span>
+<a name="l00025"></a>00025 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00026"></a>00026 <span class="preprocessor">#ifndef SINFO_WAVECAL_CFG_H</span>
+<a name="l00027"></a>00027 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_WAVECAL_CFG_H</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00029"></a>00029 <span class="comment">                                   Includes</span>
+<a name="l00030"></a>00030 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00031"></a>00031 <span class="preprocessor">#include <stdlib.h></span>
+<a name="l00032"></a>00032 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include "sinfo_globals.h"</span>
+<a name="l00034"></a>00034 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00035"></a>00035 <span class="comment">                                   Defines</span>
+<a name="l00036"></a>00036 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00037"></a>00037 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00038"></a>00038 <span class="comment">                                   New types</span>
+<a name="l00039"></a>00039 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00040"></a>00040 <span class="comment">/*</span>
+<a name="l00041"></a>00041 <span class="comment">  Wavelength calibration blackboard container</span>
+<a name="l00042"></a>00042 <span class="comment"></span>
+<a name="l00043"></a>00043 <span class="comment">  This structure holds all information related to the wavelength calibration</span>
+<a name="l00044"></a>00044 <span class="comment">  routine. It is used as a container for the flux of ancillary data,</span>
+<a name="l00045"></a>00045 <span class="comment">  computed values, and algorithm status. Pixel flux is separated from</span>
+<a name="l00046"></a>00046 <span class="comment">  the blackboard.</span>
+<a name="l00047"></a>00047 <span class="comment">  */</span>
+<a name="l00048"></a>00048 
+<a name="l00049"></a>00049 <span class="keyword">typedef</span> <span class="keyword">struct </span>wave_config {
+<a name="l00050"></a>00050 <span class="comment">/*-------General---------*/</span>
+<a name="l00051"></a>00051         <span class="keywordtype">char</span> inFrame[FILE_NAME_SZ] ; <span class="comment">/* input emission line frame */</span>
+<a name="l00052"></a>00052         <span class="keywordtype">char</span> lineList[FILE_NAME_SZ] ; <span class="comment">/* input wavelength and intensity </span>
+<a name="l00053"></a>00053 <span class="comment">                                         line list */</span>
+<a name="l00054"></a>00054         <span class="keywordtype">char</span> outName[FILE_NAME_SZ] ;  <span class="comment">/* output name of resulting </span>
+<a name="l00055"></a>00055 <span class="comment">                                         fits wavelength map */</span>
+<a name="l00056"></a>00056         <span class="keywordtype">char</span> drs_setup[FILE_NAME_SZ] ; <span class="comment">/* DRS setup table */</span>
+<a name="l00057"></a>00057 
+<a name="l00058"></a>00058 <span class="comment">/*------ FindLines ------*/</span>
+<a name="l00059"></a>00059         <span class="comment">/* indicates if the dispersion relation is already determined or not */</span>
+<a name="l00060"></a>00060         <span class="keywordtype">int</span> calibIndicator ;      
+<a name="l00061"></a>00061         <span class="comment">/* estimated central wavelength of the image */</span>
+<a name="l00062"></a>00062         <span class="keywordtype">float</span> guessBeginWavelength ;
+<a name="l00063"></a>00063         <span class="comment">/* estimated linear dispersion of emission line frame */</span>
+<a name="l00064"></a>00064         <span class="keywordtype">float</span> guessDispersion1 ;
+<a name="l00065"></a>00065         <span class="comment">/* estimated square dispersion of emission line frame */</span>
+<a name="l00066"></a>00066         <span class="keywordtype">float</span> guessDispersion2 ;
+<a name="l00067"></a>00067         <span class="comment">/* minimal difference of mean and sinfo_median column intensity */</span>
+<a name="l00068"></a>00068         <span class="keywordtype">float</span> mindiff ;
+<a name="l00069"></a>00069         <span class="comment">/* half width of a box within which the line must sit */</span>
+<a name="l00070"></a>00070         <span class="keywordtype">int</span> halfWidth ;
+<a name="l00071"></a>00071         <span class="comment">/* sigma of Gaussian of artificial model spectra */</span>
+<a name="l00072"></a>00072         <span class="keywordtype">float</span> sigma ; 
+<a name="l00073"></a>00073 
+<a name="l00074"></a>00074 <span class="comment">/*------ WaveCalib ------*/</span>
+<a name="l00075"></a>00075         <span class="comment">/* guess value for fwhm of emission lines */</span> 
+<a name="l00076"></a>00076         <span class="keywordtype">float</span> fwhm ;
+<a name="l00077"></a>00077         <span class="comment">/* minimum amplitude of a line to be fitted */</span>
+<a name="l00078"></a>00078         <span class="keywordtype">float</span> minAmplitude ;
+<a name="l00079"></a>00079         <span class="comment">/* maximal residual value for a valid fit */</span>
+<a name="l00080"></a>00080         <span class="keywordtype">float</span> maxResidual ;
+<a name="l00081"></a>00081         <span class="comment">/* # of polynomial coefficients used for the dispersion relation */</span>
+<a name="l00082"></a>00082         <span class="keywordtype">int</span> nrDispCoefficients ;
+<a name="l00083"></a>00083         <span class="comment">/* # of polynomial coefficients used for the fit of </span>
+<a name="l00084"></a>00084 <span class="comment">             the dispersion coefficients */</span>
+<a name="l00085"></a>00085         <span class="keywordtype">int</span> nrCoefCoefficients ;
+<a name="l00086"></a>00086         <span class="comment">/* minimal factor of the standard deviation of the fit coefficients */</span>
+<a name="l00087"></a>00087         <span class="keywordtype">float</span> sigmaFactor ;
+<a name="l00088"></a>00088         <span class="comment">/* indicates if the parameterized dispersion relation coefficients </span>
+<a name="l00089"></a>00089 <span class="comment">       should be written into an ASCII file */</span>
+<a name="l00090"></a>00090         <span class="keywordtype">int</span> writeCoeffsInd ;
+<a name="l00091"></a>00091         <span class="comment">/* indicates if the fit parameters should be written </span>
+<a name="l00092"></a>00092 <span class="comment">           into an ASCII file */</span>
+<a name="l00093"></a>00093         <span class="keywordtype">int</span> writeParInd ;
+<a name="l00094"></a>00094         <span class="comment">/* name of the ASCII file containing the fit parameters */</span>
+<a name="l00095"></a>00095         <span class="keywordtype">char</span> paramsList[FILE_NAME_SZ] ;
+<a name="l00096"></a>00096         <span class="comment">/* name of the ASCII file containing the coefficients </span>
+<a name="l00097"></a>00097 <span class="comment">           of the parameterized dispersion relation */</span>
+<a name="l00098"></a>00098         <span class="keywordtype">char</span> coeffsName[FILE_NAME_SZ] ;
+<a name="l00099"></a>00099         <span class="comment">/* number of slitlets */</span>
+<a name="l00100"></a>00100         <span class="keywordtype">int</span>    nslitlets ;
+<a name="l00101"></a>00101         <span class="comment">/* minimal pixel distance of slitlets in spectral direction */</span>
+<a name="l00102"></a>00102         <span class="keywordtype">int</span>    pixeldist ;
+<a name="l00103"></a>00103         <span class="comment">/* allowed pixel position tolerance between estimated </span>
+<a name="l00104"></a>00104 <span class="comment">           and fitted line position */</span>
+<a name="l00105"></a>00105         <span class="keywordtype">float</span>  pixel_tolerance  ;
+<a name="l00106"></a>00106 
+<a name="l00107"></a>00107 <span class="comment">/*------ WaveMap ------*/</span>
+<a name="l00108"></a>00108         <span class="comment">/* indicator if wavelength map should be generated or not */</span>
+<a name="l00109"></a>00109         <span class="keywordtype">int</span> wavemapInd ;
+<a name="l00110"></a>00110     <span class="comment">/* magnifying factor for FFT */</span>
+<a name="l00111"></a>00111     <span class="keywordtype">int</span> magFactor ;
+<a name="l00112"></a>00112 
+<a name="l00113"></a>00113 <span class="comment">/*------ FitSlits ------*/</span>
+<a name="l00114"></a>00114         <span class="comment">/* indicator if the fit of the slit edge positions is carried </span>
+<a name="l00115"></a>00115 <span class="comment">           through or not */</span>
+<a name="l00116"></a>00116         <span class="keywordtype">int</span> slitposIndicator ;
+<a name="l00117"></a>00117         <span class="comment">/* indicator if the fit model function is a Boltzmann </span>
+<a name="l00118"></a>00118 <span class="comment">           function or not */</span>
+<a name="l00119"></a>00119         <span class="keywordtype">int</span> fitBoltzIndicator ;
+<a name="l00120"></a>00120         <span class="comment">/* indicator if the fit model function is a simple edge </span>
+<a name="l00121"></a>00121 <span class="comment">           function or not */</span>
+<a name="l00122"></a>00122         <span class="keywordtype">int</span> fitEdgeIndicator ;
+<a name="l00123"></a>00123         <span class="comment">/* indicator if the fit guess position are user given or </span>
+<a name="l00124"></a>00124 <span class="comment">           calculated automatically */</span>
+<a name="l00125"></a>00125         <span class="keywordtype">int</span> estimateIndicator ;
+<a name="l00126"></a>00126     <span class="comment">/* pixel length of the row box within which the fit of the </span>
+<a name="l00127"></a>00127 <span class="comment">           slitlet positions is carried out*/</span>
+<a name="l00128"></a>00128     <span class="keywordtype">int</span> boxLength ;
+<a name="l00129"></a>00129         <span class="comment">/* lower row position for the estimate fit */</span>
+<a name="l00130"></a>00130     <span class="keywordtype">int</span> loPos ;
+<a name="l00131"></a>00131         <span class="comment">/* upper row position for the estimate fit */</span>
+<a name="l00132"></a>00132     <span class="keywordtype">int</span> hiPos ;
+<a name="l00133"></a>00133     <span class="comment">/* float box half width in spectral direction */</span>
+<a name="l00134"></a>00134         <span class="keywordtype">float</span> yBox ;
+<a name="l00135"></a>00135         <span class="comment">/* maximal tolerable difference to the expected slitlet positions */</span>
+<a name="l00136"></a>00136         <span class="keywordtype">float</span> diffTol ;
+<a name="l00137"></a>00137         <span class="comment">/* name of the ASCII file containing the slitlet edge positions */</span>
+<a name="l00138"></a>00138         <span class="keywordtype">char</span> slitposName[FILE_NAME_SZ] ;
+<a name="l00139"></a>00139         <span class="comment">/* name of the ASCII file containing the estimated slitlet </span>
+<a name="l00140"></a>00140 <span class="comment">           edge positions */</span>
+<a name="l00141"></a>00141         <span class="keywordtype">char</span> slitposGuessName[FILE_NAME_SZ] ;
+<a name="l00142"></a>00142 
+<a name="l00143"></a>00143 
+<a name="l00144"></a>00144   <span class="keywordtype">int</span> qc_thresh_min;
+<a name="l00145"></a>00145   <span class="keywordtype">int</span> qc_thresh_max;
+<a name="l00146"></a>00146 
+<a name="l00147"></a>00147 } wave_config ;
+<a name="l00148"></a>00148 
+<a name="l00149"></a>00149 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00150"></a>00150 <span class="comment">                               Function prototypes</span>
+<a name="l00151"></a>00151 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00159"></a>00159 wave_config * 
+<a name="l00160"></a>00160 sinfo_wave_cfg_create(<span class="keywordtype">void</span>);
+<a name="l00168"></a>00168 <span class="keywordtype">void</span> 
+<a name="l00169"></a>00169 sinfo_wave_cfg_destroy(wave_config * jc);
+<a name="l00170"></a>00170 
+<a name="l00171"></a>00171 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__wavecal__config_8c_source.html b/html/sinfo__wavecal__config_8c_source.html
new file mode 100644
index 0000000..1658d4d
--- /dev/null
+++ b/html/sinfo__wavecal__config_8c_source.html
@@ -0,0 +1,434 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_wavecal_config.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_wavecal_config.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_wavecal_config.c,v 1.6 2012/03/03 10:35:14 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the CPL (Common Pipeline Library)</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
+<a name="l00007"></a>00007 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span>
+<a name="l00008"></a>00008 <span class="comment"> * License as published by the Free Software Foundation; either</span>
+<a name="l00009"></a>00009 <span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
+<a name="l00014"></a>00014 <span class="comment"> * Lesser General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
+<a name="l00017"></a>00017 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2012/03/03 10:35:14 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.6 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> */</span>
+<a name="l00026"></a>00026 
+<a name="l00027"></a>00027  <span class="comment">/****************************************************************</span>
+<a name="l00028"></a>00028 <span class="comment">  *   Wavecal Frames Data Reduction Parameter Initialization        *</span>
+<a name="l00029"></a>00029 <span class="comment">  ****************************************************************/</span>
+<a name="l00030"></a>00030 
+<a name="l00031"></a>00031 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00032"></a>00032 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00033"></a>00033 <span class="preprocessor">#endif</span>
+<a name="l00034"></a>00034 <span class="preprocessor"></span>
+<a name="l00035"></a>00035 <span class="preprocessor">#include "sinfo_wavecal_config.h"</span>
+<a name="l00045"></a>00045 <span class="keywordtype">void</span>
+<a name="l00046"></a>00046  sinfo_wavecal_config_add(cpl_parameterlist *list)
+<a name="l00047"></a>00047 {
+<a name="l00048"></a>00048 
+<a name="l00049"></a>00049   cpl_parameter *p;
+<a name="l00050"></a>00050 
+<a name="l00051"></a>00051   <span class="keywordflow">if</span> (!list) {
+<a name="l00052"></a>00052     <span class="keywordflow">return</span>;
+<a name="l00053"></a>00053   }
+<a name="l00054"></a>00054 
+<a name="l00055"></a>00055   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.wavecal.slitpos_boostrap"</span>,
+<a name="l00056"></a>00056                   CPL_TYPE_BOOL,
+<a name="l00057"></a>00057                            <span class="stringliteral">"Switch to get a new slitpos without a reference: "</span>,
+<a name="l00058"></a>00058                               <span class="stringliteral">"sinfoni.wavecal"</span>,
+<a name="l00059"></a>00059                               FALSE);
+<a name="l00060"></a>00060 
+<a name="l00061"></a>00061   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"wcal-slitpos_bootstrap"</span>);
+<a name="l00062"></a>00062   cpl_parameterlist_append(list, p);
+<a name="l00063"></a>00063 
+<a name="l00064"></a>00064   <span class="comment">/*</span>
+<a name="l00065"></a>00065 <span class="comment">  p = cpl_parameter_new_value("sinfoni.wavecal.mflat_frm_switch",</span>
+<a name="l00066"></a>00066 <span class="comment">                  CPL_TYPE_BOOL,</span>
+<a name="l00067"></a>00067 <span class="comment">                              "Switch for master lampflat input: ",</span>
+<a name="l00068"></a>00068 <span class="comment">                              "sinfoni.wavecal",</span>
+<a name="l00069"></a>00069 <span class="comment">                              TRUE);</span>
+<a name="l00070"></a>00070 <span class="comment"></span>
+<a name="l00071"></a>00071 <span class="comment"></span>
+<a name="l00072"></a>00072 <span class="comment">  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"wcal-mflat_frm_switch");</span>
+<a name="l00073"></a>00073 <span class="comment">  cpl_parameterlist_append(list, p);</span>
+<a name="l00074"></a>00074 <span class="comment">  */</span>
+<a name="l00075"></a>00075 
+<a name="l00076"></a>00076 
+<a name="l00077"></a>00077 <span class="comment">/* Find Lines */</span>
+<a name="l00078"></a>00078 <span class="comment">/* indicates if the dispersion relation is already determined or not */</span>
+<a name="l00079"></a>00079   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.wavecal.calib_indicator"</span>,
+<a name="l00080"></a>00080                   CPL_TYPE_BOOL,
+<a name="l00081"></a>00081                               <span class="stringliteral">"Calib Indicator: "</span>
+<a name="l00082"></a>00082                               <span class="stringliteral">"FALSE: if the dispersion relation is already "</span>
+<a name="l00083"></a>00083                             <span class="stringliteral">"known, the routine can jump to the sinfo_waveMap "</span>
+<a name="l00084"></a>00084                               <span class="stringliteral">"section "</span>
+<a name="l00085"></a>00085                               <span class="stringliteral">"TRUE: if the dispersion relation "</span>
+<a name="l00086"></a>00086                               <span class="stringliteral">"must first be determined"</span>,
+<a name="l00087"></a>00087                               <span class="stringliteral">"sinfoni.wavecal"</span>,
+<a name="l00088"></a>00088                               TRUE);
+<a name="l00089"></a>00089 
+<a name="l00090"></a>00090   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"wcal-calib_indicator"</span>);
+<a name="l00091"></a>00091   cpl_parameterlist_append(list, p);
+<a name="l00092"></a>00092 
+<a name="l00093"></a>00093 
+<a name="l00094"></a>00094 <span class="comment">/* minimal difference of mean and sinfo_median column intensity */</span>
+<a name="l00095"></a>00095   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.wavecal.min_diff"</span>,
+<a name="l00096"></a>00096                   CPL_TYPE_DOUBLE,
+<a name="l00097"></a>00097                               <span class="stringliteral">"Minimum Of Difference: "</span>
+<a name="l00098"></a>00098                           <span class="stringliteral">"minimum difference of mean and sinfo_median column "</span>
+<a name="l00099"></a>00099                           <span class="stringliteral">"intensity to carry out the cross sinfo_correlation"</span>,
+<a name="l00100"></a>00100                               <span class="stringliteral">"sinfoni.wavecal"</span>,
+<a name="l00101"></a>00101                               1.);
+<a name="l00102"></a>00102 
+<a name="l00103"></a>00103   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"wcal-min_diff"</span>);
+<a name="l00104"></a>00104   cpl_parameterlist_append(list, p);
+<a name="l00105"></a>00105 
+<a name="l00106"></a>00106 <span class="comment">/* half width of a box within which the line must sit */</span>
+<a name="l00107"></a>00107   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.wavecal.half_width"</span>,
+<a name="l00108"></a>00108                   CPL_TYPE_INT,
+<a name="l00109"></a>00109                               <span class="stringliteral">"Half Width: "</span>
+<a name="l00110"></a>00110                               <span class="stringliteral">"half width of a box within which the line "</span>
+<a name="l00111"></a>00111                               <span class="stringliteral">"must be placed"</span>,
+<a name="l00112"></a>00112                               <span class="stringliteral">"sinfoni.wavecal"</span>,
+<a name="l00113"></a>00113                               7);
+<a name="l00114"></a>00114 
+<a name="l00115"></a>00115   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"wcal-hw"</span>);
+<a name="l00116"></a>00116   cpl_parameterlist_append(list, p);
+<a name="l00117"></a>00117 
+<a name="l00118"></a>00118 <span class="comment">/* sigma of Gaussian of artificial model spectra */</span>
+<a name="l00119"></a>00119   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.wavecal.sigma"</span>,
+<a name="l00120"></a>00120                   CPL_TYPE_DOUBLE,
+<a name="l00121"></a>00121                               <span class="stringliteral">"Sigma: sigma of Gaussian which is convolved "</span>
+<a name="l00122"></a>00122                               <span class="stringliteral">"with the artificial spectrum generated using "</span>
+<a name="l00123"></a>00123                               <span class="stringliteral">"the line list"</span>,
+<a name="l00124"></a>00124                               <span class="stringliteral">"sinfoni.wavecal"</span>,
+<a name="l00125"></a>00125                                2.);
+<a name="l00126"></a>00126 
+<a name="l00127"></a>00127   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"wcal-sigma"</span>);
+<a name="l00128"></a>00128   cpl_parameterlist_append(list, p);
+<a name="l00129"></a>00129 
+<a name="l00130"></a>00130   <span class="comment">/* Wavelength Calibration */</span>
+<a name="l00131"></a>00131 <span class="comment">/* guess value for fwhm of emission lines */</span>
+<a name="l00132"></a>00132   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.wavecal.fwhm"</span>,
+<a name="l00133"></a>00133                   CPL_TYPE_DOUBLE,
+<a name="l00134"></a>00134                               <span class="stringliteral">"FWHM: initial guess value for the fwhm of "</span>
+<a name="l00135"></a>00135                               <span class="stringliteral">"the Gaussian used for the line fit"</span>,
+<a name="l00136"></a>00136                               <span class="stringliteral">"sinfoni.wavecal"</span>,
+<a name="l00137"></a>00137                                2.83);
+<a name="l00138"></a>00138 
+<a name="l00139"></a>00139   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"wcal-fwhm"</span>);
+<a name="l00140"></a>00140   cpl_parameterlist_append(list, p);
+<a name="l00141"></a>00141 
+<a name="l00142"></a>00142 <span class="comment">/* minimum amplitude of a line to be fitted */</span>
+<a name="l00143"></a>00143   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.wavecal.min_amplitude"</span>,
+<a name="l00144"></a>00144                   CPL_TYPE_DOUBLE,
+<a name="l00145"></a>00145                               <span class="stringliteral">"Minimum Of Amplitude: "</span>
+<a name="l00146"></a>00146                               <span class="stringliteral">"of the Gaussian to do the fit"</span>,
+<a name="l00147"></a>00147                               <span class="stringliteral">"sinfoni.wavecal"</span>,
+<a name="l00148"></a>00148                               5.);
+<a name="l00149"></a>00149 
+<a name="l00150"></a>00150   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"wcal-min_amplitude"</span>);
+<a name="l00151"></a>00151   cpl_parameterlist_append(list, p);
+<a name="l00152"></a>00152 
+<a name="l00153"></a>00153 <span class="comment">/* maximal residual value for a valid fit */</span>
+<a name="l00154"></a>00154   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.wavecal.max_residual"</span>,
+<a name="l00155"></a>00155                   CPL_TYPE_DOUBLE,
+<a name="l00156"></a>00156                               <span class="stringliteral">"Maximum Residuals value: "</span>
+<a name="l00157"></a>00157                               <span class="stringliteral">"beyond this value the fit is rejected"</span>,
+<a name="l00158"></a>00158                               <span class="stringliteral">"sinfoni.wavecal"</span>,
+<a name="l00159"></a>00159                               0.5);
+<a name="l00160"></a>00160 
+<a name="l00161"></a>00161   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"wcal-max_residual"</span>);
+<a name="l00162"></a>00162   cpl_parameterlist_append(list, p);
+<a name="l00163"></a>00163 
+<a name="l00164"></a>00164 <span class="comment">/* # of polynomial coefficients used for the dispersion relation */</span>
+<a name="l00165"></a>00165   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.wavecal.n_a_coefficients"</span>,
+<a name="l00166"></a>00166                   CPL_TYPE_INT,
+<a name="l00167"></a>00167                               <span class="stringliteral">"Number of A coefficients: number of "</span>
+<a name="l00168"></a>00168                               <span class="stringliteral">"polynomial coefficients for the "</span>
+<a name="l00169"></a>00169                               <span class="stringliteral">"dispersion relation"</span>,
+<a name="l00170"></a>00170                               <span class="stringliteral">"sinfoni.wavecal"</span>,
+<a name="l00171"></a>00171                               4);
+<a name="l00172"></a>00172 
+<a name="l00173"></a>00173   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"wcal-n_a_coeffs"</span>);
+<a name="l00174"></a>00174   cpl_parameterlist_append(list, p);
+<a name="l00175"></a>00175 
+<a name="l00176"></a>00176  <span class="comment">/* # of polynomial coefficients used for the fit of </span>
+<a name="l00177"></a>00177 <span class="comment">    the dispersion coefficients */</span>
+<a name="l00178"></a>00178   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.wavecal.n_b_coefficients"</span>,
+<a name="l00179"></a>00179                   CPL_TYPE_INT,
+<a name="l00180"></a>00180                               <span class="stringliteral">"Number of B coefficients: "</span>
+<a name="l00181"></a>00181                               <span class="stringliteral">"number of polynomial coefficients for the "</span>
+<a name="l00182"></a>00182                               <span class="stringliteral">"polynomial fit of the dispersion coefficients"</span>,
+<a name="l00183"></a>00183                               <span class="stringliteral">"sinfoni.wavecal"</span>,
+<a name="l00184"></a>00184                               2);
+<a name="l00185"></a>00185 
+<a name="l00186"></a>00186   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"wcal-n_b_coeffs"</span>);
+<a name="l00187"></a>00187   cpl_parameterlist_append(list, p);
+<a name="l00188"></a>00188 
+<a name="l00189"></a>00189  <span class="comment">/* minimal factor of the standard deviation of the fit coefficients */</span>
+<a name="l00190"></a>00190   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.wavecal.sigma_factor"</span>,
+<a name="l00191"></a>00191                   CPL_TYPE_DOUBLE,
+<a name="l00192"></a>00192                               <span class="stringliteral">"Sigma Factor: "</span>
+<a name="l00193"></a>00193                               <span class="stringliteral">"Factor of the standard deviation of the "</span>
+<a name="l00194"></a>00194                               <span class="stringliteral">"polynomial coefficients of the dispersion "</span>
+<a name="l00195"></a>00195                               <span class="stringliteral">"relation beyond which the coefficients are "</span>
+<a name="l00196"></a>00196                               <span class="stringliteral">"not used for the fit"</span>,
+<a name="l00197"></a>00197                               <span class="stringliteral">"sinfoni.wavecal"</span>,
+<a name="l00198"></a>00198                               1.5);
+<a name="l00199"></a>00199 
+<a name="l00200"></a>00200   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"wcal-sigma_factor"</span>);
+<a name="l00201"></a>00201   cpl_parameterlist_append(list, p);
+<a name="l00202"></a>00202 
+<a name="l00203"></a>00203   <span class="comment">/* indicates if the parameterized dispersion relation coefficients </span>
+<a name="l00204"></a>00204 <span class="comment">       should be written into an ASCII file */</span>
+<a name="l00205"></a>00205   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.wavecal.write_coeffs_ind"</span>,
+<a name="l00206"></a>00206                   CPL_TYPE_BOOL,
+<a name="l00207"></a>00207                               <span class="stringliteral">"Write Coefficients Index: "</span>
+<a name="l00208"></a>00208                               <span class="stringliteral">"indicates if the coefficients should "</span>
+<a name="l00209"></a>00209                               <span class="stringliteral">"be written into a file or not"</span>,
+<a name="l00210"></a>00210                               <span class="stringliteral">"sinfoni.wavecal"</span>,
+<a name="l00211"></a>00211                               TRUE);
+<a name="l00212"></a>00212 
+<a name="l00213"></a>00213   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"wcal-wcoeff_ind"</span>);
+<a name="l00214"></a>00214   cpl_parameterlist_append(list, p);
+<a name="l00215"></a>00215 
+<a name="l00216"></a>00216   <span class="comment">/* indicates if the fit parameters should be written into an ASCII file */</span>
+<a name="l00217"></a>00217   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.wavecal.write_par_ind"</span>,
+<a name="l00218"></a>00218                   CPL_TYPE_BOOL,
+<a name="l00219"></a>00219                               <span class="stringliteral">"Write Parameter Index: "</span>
+<a name="l00220"></a>00220                               <span class="stringliteral">"indicates if the fit parameters should "</span>
+<a name="l00221"></a>00221                               <span class="stringliteral">"be written into a file or not "</span>,
+<a name="l00222"></a>00222                               <span class="stringliteral">"sinfoni.wavecal"</span>,
+<a name="l00223"></a>00223                               TRUE);
+<a name="l00224"></a>00224 
+<a name="l00225"></a>00225   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"wcal-par_ind"</span>);
+<a name="l00226"></a>00226   cpl_parameterlist_append(list, p);
+<a name="l00227"></a>00227 
+<a name="l00228"></a>00228 
+<a name="l00229"></a>00229 
+<a name="l00230"></a>00230 
+<a name="l00231"></a>00231 
+<a name="l00232"></a>00232 
+<a name="l00233"></a>00233 
+<a name="l00234"></a>00234 
+<a name="l00235"></a>00235 
+<a name="l00236"></a>00236   <span class="comment">/* dispersion relation */</span>
+<a name="l00237"></a>00237 
+<a name="l00238"></a>00238 
+<a name="l00239"></a>00239 
+<a name="l00240"></a>00240   <span class="comment">/* minimal distance of the slitlets in spectral direction */</span>
+<a name="l00241"></a>00241   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.wavecal.pixel_dist"</span>,
+<a name="l00242"></a>00242                   CPL_TYPE_INT,
+<a name="l00243"></a>00243                          <span class="stringliteral">"Minimal Slitlets's Distance in spectral direction"</span>,
+<a name="l00244"></a>00244                               <span class="stringliteral">"sinfoni.wavecal"</span>,
+<a name="l00245"></a>00245                               15);
+<a name="l00246"></a>00246 
+<a name="l00247"></a>00247   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"wcal-pixel_dist"</span>);
+<a name="l00248"></a>00248   cpl_parameterlist_append(list, p);
+<a name="l00249"></a>00249 
+<a name="l00250"></a>00250 
+<a name="l00251"></a>00251 
+<a name="l00252"></a>00252   <span class="comment">/* allowed pixel position tolerance between estimated and fitted line </span>
+<a name="l00253"></a>00253 <span class="comment">     position</span>
+<a name="l00254"></a>00254 <span class="comment">  */</span>
+<a name="l00255"></a>00255 
+<a name="l00256"></a>00256   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.wavecal.pixel_tol"</span>,
+<a name="l00257"></a>00257                   CPL_TYPE_DOUBLE,
+<a name="l00258"></a>00258                               <span class="stringliteral">"Pixel Tolerance: allowed pixel position "</span>
+<a name="l00259"></a>00259                               <span class="stringliteral">"tolerance between estimated and fitted "</span>
+<a name="l00260"></a>00260                   <span class="stringliteral">"line position"</span>,
+<a name="l00261"></a>00261                               <span class="stringliteral">"sinfoni.wavecal"</span>,
+<a name="l00262"></a>00262                               5.0);
+<a name="l00263"></a>00263 
+<a name="l00264"></a>00264   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"wcal-pixel_tol"</span>);
+<a name="l00265"></a>00265   cpl_parameterlist_append(list, p);
+<a name="l00266"></a>00266 
+<a name="l00267"></a>00267   <span class="comment">/* Wavelength Map */</span>
+<a name="l00268"></a>00268 <span class="comment">/* indicator if wavelength map should be generated or not */</span>
+<a name="l00269"></a>00269   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.wavecal.wave_map_ind"</span>,
+<a name="l00270"></a>00270                   CPL_TYPE_BOOL,
+<a name="l00271"></a>00271                               <span class="stringliteral">"Wavelength Map Indicator: "</span>
+<a name="l00272"></a>00272                               <span class="stringliteral">"indicates if the wavelength calibration map "</span>
+<a name="l00273"></a>00273                               <span class="stringliteral">"should be generated (TRUE) or not (FALSE)"</span>,
+<a name="l00274"></a>00274                               <span class="stringliteral">"sinfoni.wavecal"</span>,
+<a name="l00275"></a>00275                               FALSE);
+<a name="l00276"></a>00276 
+<a name="l00277"></a>00277   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"wcal-wave_map_ind"</span>);
+<a name="l00278"></a>00278   cpl_parameterlist_append(list, p);
+<a name="l00279"></a>00279 
+<a name="l00280"></a>00280   <span class="comment">/* magnifying factor for FFT */</span>
+<a name="l00281"></a>00281   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.wavecal.mag_factor"</span>,
+<a name="l00282"></a>00282                   CPL_TYPE_INT,
+<a name="l00283"></a>00283                               <span class="stringliteral">"Magnificator Factor: "</span>
+<a name="l00284"></a>00284                               <span class="stringliteral">"magnifying factor for the number of pixels "</span>
+<a name="l00285"></a>00285                               <span class="stringliteral">"in the columns needed for FFT"</span>,
+<a name="l00286"></a>00286                               <span class="stringliteral">"sinfoni.wavecal"</span>,
+<a name="l00287"></a>00287                               8);
+<a name="l00288"></a>00288 
+<a name="l00289"></a>00289   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"wcal-mag_factor"</span>);
+<a name="l00290"></a>00290   cpl_parameterlist_append(list, p);
+<a name="l00291"></a>00291 
+<a name="l00292"></a>00292 <span class="comment">/* Fits Slits */</span>
+<a name="l00293"></a>00293 <span class="comment">/* indicator if the fit of the slit edge positions is carried through or not */</span>
+<a name="l00294"></a>00294   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.wavecal.slit_pos_indicator"</span>,
+<a name="l00295"></a>00295                   CPL_TYPE_BOOL,
+<a name="l00296"></a>00296                               <span class="stringliteral">"Slit Position Indicator: "</span>
+<a name="l00297"></a>00297                               <span class="stringliteral">"indicates if the fits of the slitlet "</span>
+<a name="l00298"></a>00298                               <span class="stringliteral">"edge positions should be carried "</span>
+<a name="l00299"></a>00299                               <span class="stringliteral">"through or not"</span>,
+<a name="l00300"></a>00300                               <span class="stringliteral">"sinfoni.wavecal"</span>,
+<a name="l00301"></a>00301                               TRUE);
+<a name="l00302"></a>00302 
+<a name="l00303"></a>00303   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"wcal-slit_pos_ind"</span>);
+<a name="l00304"></a>00304   cpl_parameterlist_append(list, p);
+<a name="l00305"></a>00305 
+<a name="l00306"></a>00306 <span class="comment">/* indicator if the fit model function is a Boltzmann function or not */</span>
+<a name="l00307"></a>00307   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.wavecal.fit_boltz_indicator"</span>,
+<a name="l00308"></a>00308                   CPL_TYPE_BOOL ,
+<a name="l00309"></a>00309                               <span class="stringliteral">"Fit Boltzmann Indicator: "</span>
+<a name="l00310"></a>00310                               <span class="stringliteral">"indicates if the fits of the slitlet edge "</span>
+<a name="l00311"></a>00311                               <span class="stringliteral">"positions is carried trough by using a "</span>
+<a name="l00312"></a>00312                               <span class="stringliteral">"Boltzmann function as model function"</span>,
+<a name="l00313"></a>00313                               <span class="stringliteral">"sinfoni.wavecal"</span>,
+<a name="l00314"></a>00314                               TRUE);
+<a name="l00315"></a>00315 
+<a name="l00316"></a>00316   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"wcal-fit_boltz_ind"</span>);
+<a name="l00317"></a>00317   cpl_parameterlist_append(list, p);
+<a name="l00318"></a>00318 
+<a name="l00319"></a>00319 <span class="comment">/* indicator if the fit model function </span>
+<a name="l00320"></a>00320 <span class="comment">   is a simple edge function or not */</span>
+<a name="l00321"></a>00321   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.wavecal.fit_edge_indicator"</span>,
+<a name="l00322"></a>00322                   CPL_TYPE_BOOL,
+<a name="l00323"></a>00323                               <span class="stringliteral">"Fit Edge Indicator: "</span>
+<a name="l00324"></a>00324                               <span class="stringliteral">"indicates if the fits of the slitlet edge "</span>
+<a name="l00325"></a>00325                               <span class="stringliteral">"positions is carried through by using a "</span>
+<a name="l00326"></a>00326                               <span class="stringliteral">"simple edge function as model function"</span>,
+<a name="l00327"></a>00327                               <span class="stringliteral">"sinfoni.wavecal"</span>,
+<a name="l00328"></a>00328                               FALSE);
+<a name="l00329"></a>00329 
+<a name="l00330"></a>00330   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"wcal-fit_edge_ind"</span>);
+<a name="l00331"></a>00331   cpl_parameterlist_append(list, p);
+<a name="l00332"></a>00332 
+<a name="l00333"></a>00333  <span class="comment">/* indicator if the fit guess position are </span>
+<a name="l00334"></a>00334 <span class="comment">    user given or calculated automatically */</span>
+<a name="l00335"></a>00335 
+<a name="l00336"></a>00336   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.wavecal.estimate_indicator"</span>,
+<a name="l00337"></a>00337                   CPL_TYPE_BOOL,
+<a name="l00338"></a>00338                               <span class="stringliteral">"Estimate Indicator: "</span>
+<a name="l00339"></a>00339                               <span class="stringliteral">"indicates if the fits of the slitlet edge "</span>
+<a name="l00340"></a>00340                               <span class="stringliteral">"positions is carried through by using a list "</span>
+<a name="l00341"></a>00341                               <span class="stringliteral">"of estimated guess positions in a file (TRUE)"</span>
+<a name="l00342"></a>00342                               <span class="stringliteral">"or if the initial positions are calculated "</span>
+<a name="l00343"></a>00343                               <span class="stringliteral">"automatically (FALSE). The estimation case "</span>
+<a name="l00344"></a>00344                               <span class="stringliteral">"is more stable"</span>,
+<a name="l00345"></a>00345                               <span class="stringliteral">"sinfoni.wavecal"</span>,
+<a name="l00346"></a>00346                               FALSE);
+<a name="l00347"></a>00347 
+<a name="l00348"></a>00348   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"wcal-estimate_ind"</span>);
+<a name="l00349"></a>00349   cpl_parameterlist_append(list, p);
+<a name="l00350"></a>00350 
+<a name="l00351"></a>00351 <span class="comment">/* pixel length of the row box within which the fit of the </span>
+<a name="l00352"></a>00352 <span class="comment">   slitlet positions is carried out*/</span>
+<a name="l00353"></a>00353 
+<a name="l00354"></a>00354   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.wavecal.box_length"</span>,
+<a name="l00355"></a>00355                   CPL_TYPE_INT,
+<a name="l00356"></a>00356                               <span class="stringliteral">"Box Length: "</span>
+<a name="l00357"></a>00357                               <span class="stringliteral">"pixel length of the row box within "</span>
+<a name="l00358"></a>00358                               <span class="stringliteral">"which the fit is carried out"</span>,
+<a name="l00359"></a>00359                               <span class="stringliteral">"sinfoni.wavecal"</span>,
+<a name="l00360"></a>00360                               32);
+<a name="l00361"></a>00361 
+<a name="l00362"></a>00362   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"wcal-box_len"</span>);
+<a name="l00363"></a>00363   cpl_parameterlist_append(list, p);
+<a name="l00364"></a>00364 
+<a name="l00365"></a>00365 <span class="comment">/* float box half width in spectral direction */</span>
+<a name="l00366"></a>00366   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.wavecal.y_box"</span>,
+<a name="l00367"></a>00367                   CPL_TYPE_DOUBLE,
+<a name="l00368"></a>00368                               <span class="stringliteral">"Y Box: half width of a small box in "</span>
+<a name="l00369"></a>00369                               <span class="stringliteral">"spectral direction within which the "</span>
+<a name="l00370"></a>00370                               <span class="stringliteral">"maximal intensity pixel is searched"</span>,
+<a name="l00371"></a>00371                               <span class="stringliteral">"sinfoni.wavecal"</span>,
+<a name="l00372"></a>00372                               5.);
+<a name="l00373"></a>00373 
+<a name="l00374"></a>00374  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"wcal-y_box"</span>);
+<a name="l00375"></a>00375   cpl_parameterlist_append(list, p);
+<a name="l00376"></a>00376 
+<a name="l00377"></a>00377 
+<a name="l00378"></a>00378 <span class="comment">/* maximal tolerable difference to the expected slitlet positions */</span>
+<a name="l00379"></a>00379   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.wavecal.diff_tol"</span>,
+<a name="l00380"></a>00380                   CPL_TYPE_DOUBLE,
+<a name="l00381"></a>00381                               <span class="stringliteral">"Difference Tolearance: "</span>
+<a name="l00382"></a>00382                               <span class="stringliteral">"maximal tolerable difference of the "</span>
+<a name="l00383"></a>00383                               <span class="stringliteral">"resulting fit positions of the slitlet "</span>
+<a name="l00384"></a>00384                               <span class="stringliteral">"edges with respect to the expected positions"</span>,
+<a name="l00385"></a>00385                               <span class="stringliteral">"sinfoni.wavecal"</span>,
+<a name="l00386"></a>00386                               2.);
+<a name="l00387"></a>00387 
+<a name="l00388"></a>00388   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"wcal-diff_toll"</span>);
+<a name="l00389"></a>00389   cpl_parameterlist_append(list, p);
+<a name="l00390"></a>00390 
+<a name="l00391"></a>00391 
+<a name="l00392"></a>00392 
+<a name="l00393"></a>00393  p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.wavecal.qc_thresh_min"</span>,
+<a name="l00394"></a>00394                   CPL_TYPE_INT,
+<a name="l00395"></a>00395                               <span class="stringliteral">"qc_thresh_min"</span>,
+<a name="l00396"></a>00396                               <span class="stringliteral">"sinfoni.wavecal"</span>,
+<a name="l00397"></a>00397                               0);
+<a name="l00398"></a>00398 
+<a name="l00399"></a>00399   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"wcal-qc_thresh_min"</span>);
+<a name="l00400"></a>00400   cpl_parameterlist_append(list, p);
+<a name="l00401"></a>00401 
+<a name="l00402"></a>00402 
+<a name="l00403"></a>00403   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.wavecal.qc_thresh_max"</span>,
+<a name="l00404"></a>00404                   CPL_TYPE_INT,
+<a name="l00405"></a>00405                               <span class="stringliteral">"qc_thresh_max"</span>,
+<a name="l00406"></a>00406                               <span class="stringliteral">"sinfoni.wavecal"</span>,
+<a name="l00407"></a>00407                               49000);
+<a name="l00408"></a>00408 
+<a name="l00409"></a>00409   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"wcal-qc_thresh_max"</span>);
+<a name="l00410"></a>00410   cpl_parameterlist_append(list, p);
+<a name="l00411"></a>00411 
+<a name="l00412"></a>00412 
+<a name="l00413"></a>00413   <span class="comment">/*Resampling */</span>
+<a name="l00414"></a>00414  <span class="comment">/* number of coefficients for the polynomial interpolation */</span>
+<a name="l00415"></a>00415   p = cpl_parameter_new_value(<span class="stringliteral">"sinfoni.wavecal.n_coeffs"</span>,
+<a name="l00416"></a>00416                   CPL_TYPE_INT,
+<a name="l00417"></a>00417                               <span class="stringliteral">"number of coefficients for the polynomial "</span>
+<a name="l00418"></a>00418                               <span class="stringliteral">"interpolation "</span>,
+<a name="l00419"></a>00419                               <span class="stringliteral">"sinfoni.wavecal"</span>,
+<a name="l00420"></a>00420                                3);
+<a name="l00421"></a>00421 
+<a name="l00422"></a>00422   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,<span class="stringliteral">"wcal-no_coeffs"</span>);
+<a name="l00423"></a>00423   cpl_parameterlist_append(list, p);
+<a name="l00424"></a>00424 
+<a name="l00425"></a>00425 
+<a name="l00426"></a>00426 
+<a name="l00427"></a>00427 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__wavecal__config_8h_source.html b/html/sinfo__wavecal__config_8h_source.html
new file mode 100644
index 0000000..f52e51a
--- /dev/null
+++ b/html/sinfo__wavecal__config_8h_source.html
@@ -0,0 +1,48 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_wavecal_config.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_wavecal_config.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_wavecal_config.h,v 1.1 2006/10/20 08:06:33 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the CPL (Common Pipeline Library)</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
+<a name="l00007"></a>00007 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span>
+<a name="l00008"></a>00008 <span class="comment"> * License as published by the Free Software Foundation; either</span>
+<a name="l00009"></a>00009 <span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
+<a name="l00014"></a>00014 <span class="comment"> * Lesser General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
+<a name="l00017"></a>00017 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 <span class="comment">/*</span>
+<a name="l00021"></a>00021 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Date: 2006/10/20 08:06:33 $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Revision: 1.1 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> */</span>
+<a name="l00026"></a>00026 
+<a name="l00027"></a>00027  <span class="comment">/****************************************************************</span>
+<a name="l00028"></a>00028 <span class="comment">  *   Wavecal Frames Data Reduction Parameter Initialization        *</span>
+<a name="l00029"></a>00029 <span class="comment">  ****************************************************************/</span>
+<a name="l00030"></a>00030 <span class="preprocessor">#include <cpl.h></span>    <span class="comment">/* defines parlist structure */</span>
+<a name="l00031"></a>00031 <span class="keywordtype">void</span>
+<a name="l00032"></a>00032 sinfo_wavecal_config_add(cpl_parameterlist *list);
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__wavecal__ini_8h_source.html b/html/sinfo__wavecal__ini_8h_source.html
new file mode 100644
index 0000000..bf43fc9
--- /dev/null
+++ b/html/sinfo__wavecal__ini_8h_source.html
@@ -0,0 +1,65 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_wavecal_ini.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_wavecal_ini.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   File name    :   sinfo_wavecal_ini.h</span>
+<a name="l00021"></a>00021 <span class="comment">   Author       :    Juergen Schreiber</span>
+<a name="l00022"></a>00022 <span class="comment">   Created on   :    Sept 14, 2001</span>
+<a name="l00023"></a>00023 <span class="comment">   Description  :    wavelength calibration ini file handling for SPIFFI</span>
+<a name="l00024"></a>00024 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00025"></a>00025 <span class="preprocessor">#ifndef SINFO_WAVECAL_INI_H</span>
+<a name="l00026"></a>00026 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_WAVECAL_INI_H</span>
+<a name="l00027"></a>00027 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00028"></a>00028 <span class="comment">                                Includes</span>
+<a name="l00029"></a>00029 <span class="comment">---------------------------------------------------------------------------*/</span>
+<a name="l00030"></a>00030 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00031"></a>00031 <span class="preprocessor">#include "sinfo_wavecal_cfg.h"</span>
+<a name="l00032"></a>00032 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                             Function prototypes </span>
+<a name="l00034"></a>00034 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 
+<a name="l00054"></a>00054 <span class="keywordtype">int</span> 
+<a name="l00055"></a>00055 generateWave_ini_file(
+<a name="l00056"></a>00056         <span class="keywordtype">char</span> * ini_name,
+<a name="l00057"></a>00057         <span class="keywordtype">char</span> * name_i,
+<a name="l00058"></a>00058         <span class="keywordtype">char</span> * name_o,
+<a name="l00059"></a>00059         <span class="keywordtype">char</span> * name_c
+<a name="l00060"></a>00060 );
+<a name="l00061"></a>00061  
+<a name="l00062"></a>00062 
+<a name="l00074"></a>00074 wave_config * 
+<a name="l00075"></a>00075 parse_wave_ini_file(<span class="keywordtype">char</span> * ini_name) ;
+<a name="l00076"></a>00076  
+<a name="l00077"></a>00077 
+<a name="l00078"></a>00078 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__wavecal__ini__by__cpl_8c_source.html b/html/sinfo__wavecal__ini__by__cpl_8c_source.html
new file mode 100644
index 0000000..b96192b
--- /dev/null
+++ b/html/sinfo__wavecal__ini__by__cpl_8c_source.html
@@ -0,0 +1,540 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_wavecal_ini_by_cpl.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_wavecal_ini_by_cpl.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment"></span>
+<a name="l00021"></a>00021 <span class="comment">   File name    :   sinfo_wavecal_ini_by_cpl.c</span>
+<a name="l00022"></a>00022 <span class="comment">   Author       :   Andrea Modigliani</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on   :   May 21, 2004</span>
+<a name="l00024"></a>00024 <span class="comment">   Description  :   wavelength calibration cpl input handling for SPIFFI</span>
+<a name="l00025"></a>00025 <span class="comment"></span>
+<a name="l00026"></a>00026 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span>
+<a name="l00032"></a>00032 
+<a name="l00033"></a>00033 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00034"></a>00034 <span class="comment">                                Includes</span>
+<a name="l00035"></a>00035 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="preprocessor">#include <string.h></span>
+<a name="l00038"></a>00038 <span class="preprocessor">#include "sinfo_wavecal_ini_by_cpl.h"</span>
+<a name="l00039"></a>00039 <span class="preprocessor">#include "sinfo_raw_types.h"</span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include "sinfo_pro_types.h"</span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include "sinfo_ref_types.h"</span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include "sinfo_hidden.h"</span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include "sinfo_functions.h"</span>
+<a name="l00044"></a>00044 <span class="preprocessor">#include "sinfo_utils.h"</span>
+<a name="l00045"></a>00045 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00046"></a>00046 <span class="comment">                    Functions private to this module</span>
+<a name="l00047"></a>00047 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00048"></a>00048 
+<a name="l00049"></a>00049 <span class="keyword">static</span> <span class="keywordtype">void</span>
+<a name="l00050"></a>00050 parse_section_frames ( wave_config *, cpl_parameterlist* cpl_cfg, cpl_frameset* sof,
+<a name="l00051"></a>00051                        cpl_frameset** raw, <span class="keywordtype">int</span>* status );
+<a name="l00052"></a>00052 
+<a name="l00053"></a>00053 <span class="keyword">static</span> <span class="keywordtype">void</span>
+<a name="l00054"></a>00054 parse_section_findlines ( wave_config *, cpl_parameterlist* cpl_cfg );
+<a name="l00055"></a>00055 <span class="keyword">static</span> <span class="keywordtype">void</span>
+<a name="l00056"></a>00056 parse_section_wavecalib ( wave_config *, cpl_parameterlist* cpl_cfg );
+<a name="l00057"></a>00057 <span class="keyword">static</span> <span class="keywordtype">void</span>
+<a name="l00058"></a>00058 parse_section_wavemap ( wave_config *, cpl_parameterlist* cpl_cfg );
+<a name="l00059"></a>00059 <span class="keyword">static</span> <span class="keywordtype">void</span>
+<a name="l00060"></a>00060 parse_section_qclog ( wave_config *, cpl_parameterlist* cpl_cfg );
+<a name="l00061"></a>00061 <span class="keyword">static</span> <span class="keywordtype">void</span>
+<a name="l00062"></a>00062 parse_section_fitslits ( wave_config *, cpl_parameterlist* cpl_cfg );
+<a name="l00063"></a>00063 
+<a name="l00064"></a>00064 
+<a name="l00065"></a>00065 
+<a name="l00074"></a>00074 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l00092"></a>00092 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00093"></a>00093 
+<a name="l00094"></a>00094 <span class="comment">/* Removed  generateWave_ini_file */</span>
+<a name="l00095"></a>00095 
+<a name="l00096"></a>00096 <span class="comment">/*-------------------------------------------------------------------------*/</span>
+<a name="l00107"></a>00107 <span class="comment">/*--------------------------------------------------------------------------*/</span>
+<a name="l00108"></a>00108 
+<a name="l00109"></a>00109 wave_config *
+<a name="l00110"></a>00110 sinfo_parse_cpl_input_wave ( cpl_parameterlist* cpl_cfg,
+<a name="l00111"></a>00111                              cpl_frameset* sof, cpl_frameset** raw )
+<a name="l00112"></a>00112 {
+<a name="l00113"></a>00113 
+<a name="l00114"></a>00114     <span class="keywordtype">int</span>  status=0;
+<a name="l00115"></a>00115     wave_config   * cfg= sinfo_wave_cfg_create();
+<a name="l00116"></a>00116     <span class="comment">/*</span>
+<a name="l00117"></a>00117 <span class="comment">     * Perform sanity checks, fill up the structure with what was</span>
+<a name="l00118"></a>00118 <span class="comment">     * found in the ini file</span>
+<a name="l00119"></a>00119 <span class="comment">     */</span>
+<a name="l00120"></a>00120 
+<a name="l00121"></a>00121     parse_section_findlines ( cfg, cpl_cfg );
+<a name="l00122"></a>00122     parse_section_wavecalib ( cfg, cpl_cfg );
+<a name="l00123"></a>00123     parse_section_wavemap ( cfg, cpl_cfg );
+<a name="l00124"></a>00124     parse_section_fitslits ( cfg, cpl_cfg );
+<a name="l00125"></a>00125     parse_section_qclog ( cfg, cpl_cfg );
+<a name="l00126"></a>00126     parse_section_frames ( cfg, cpl_cfg, sof, raw, &status );
+<a name="l00127"></a>00127 
+<a name="l00128"></a>00128     <span class="keywordflow">if</span> ( status > 0 )
+<a name="l00129"></a>00129     {
+<a name="l00130"></a>00130         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> ( <span class="stringliteral">"parsing cpl input"</span> );
+<a name="l00131"></a>00131         sinfo_wave_cfg_destroy ( cfg );
+<a name="l00132"></a>00132         cfg = NULL ;
+<a name="l00133"></a>00133         <span class="keywordflow">return</span> NULL ;
+<a name="l00134"></a>00134     }
+<a name="l00135"></a>00135     <span class="keywordflow">return</span> cfg ;
+<a name="l00136"></a>00136 }
+<a name="l00137"></a>00137 
+<a name="l00138"></a>00138 
+<a name="l00139"></a>00139 <span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00140"></a>00140 <span class="comment">   Functions:   parse_section_xxx()</span>
+<a name="l00141"></a>00141 <span class="comment">   In           :       symbolic table read from ini file</span>
+<a name="l00142"></a>00142 <span class="comment">   Out          :       void</span>
+<a name="l00143"></a>00143 <span class="comment">   Job          :       update a wave_config structure from what can be</span>
+<a name="l00144"></a>00144 <span class="comment">                            found in the ini file.</span>
+<a name="l00145"></a>00145 <span class="comment">   Notice       :       all of these functions update a status integer to</span>
+<a name="l00146"></a>00146 <span class="comment">                        indicate if an error occurred, or leave it as it is if</span>
+<a name="l00147"></a>00147 <span class="comment">                        everything went Ok.</span>
+<a name="l00148"></a>00148 <span class="comment"></span>
+<a name="l00149"></a>00149 <span class="comment">        parse_section_general()</span>
+<a name="l00150"></a>00150 <span class="comment">        parse_section_findlines()</span>
+<a name="l00151"></a>00151 <span class="comment">        parse_section_wavecalib()</span>
+<a name="l00152"></a>00152 <span class="comment">        parse_section_wavemap()</span>
+<a name="l00153"></a>00153 <span class="comment">        parse_section_fitslits()</span>
+<a name="l00154"></a>00154 <span class="comment"></span>
+<a name="l00155"></a>00155 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00156"></a>00156 
+<a name="l00157"></a>00157 
+<a name="l00158"></a>00158 
+<a name="l00159"></a>00159 <span class="keyword">static</span> <span class="keywordtype">void</span>
+<a name="l00160"></a>00160 parse_section_frames ( wave_config * cfg,cpl_parameterlist* cpl_cfg, cpl_frameset* sof,
+<a name="l00161"></a>00161                        cpl_frameset** raw, <span class="keywordtype">int</span>* status )
+<a name="l00162"></a>00162 {
+<a name="l00163"></a>00163     cpl_frame* frame   = NULL;
+<a name="l00164"></a>00164     <span class="keywordtype">char</span> spat_res[FILE_NAME_SZ];
+<a name="l00165"></a>00165     <span class="keywordtype">char</span> lamp_status[FILE_NAME_SZ];
+<a name="l00166"></a>00166     <span class="keywordtype">char</span> band[FILE_NAME_SZ];
+<a name="l00167"></a>00167     <span class="keywordtype">int</span> ins_set=0;
+<a name="l00168"></a>00168     <span class="keywordtype">int</span> nraw=0;
+<a name="l00169"></a>00169     cpl_parameter* p=NULL;
+<a name="l00170"></a>00170     cpl_table* drs_tab=NULL;
+<a name="l00171"></a>00171     wcal* w=sinfo_wcal_new();
+<a name="l00172"></a>00172     <span class="keywordtype">int</span> check=0;
+<a name="l00173"></a>00173 
+<a name="l00174"></a>00174     sinfo_extract_raw_frames_type ( sof,raw,PRO_WAVE_LAMP_STACKED );
+<a name="l00175"></a>00175     nraw=cpl_frameset_get_size ( *raw );
+<a name="l00176"></a>00176     <span class="keywordflow">if</span> ( nraw==0 )
+<a name="l00177"></a>00177     {
+<a name="l00178"></a>00178         sinfo_extract_raw_frames_type ( sof,raw,PRO_WAVE_NS_STACKED );
+<a name="l00179"></a>00179     }
+<a name="l00180"></a>00180     nraw=cpl_frameset_get_size ( *raw );
+<a name="l00181"></a>00181     <span class="keywordflow">if</span> ( nraw==0 )
+<a name="l00182"></a>00182     {
+<a name="l00183"></a>00183         sinfo_extract_raw_frames_type ( sof,raw,PRO_WAVE_SLITPOS_STACKED );
+<a name="l00184"></a>00184     }
+<a name="l00185"></a>00185 
+<a name="l00186"></a>00186     nraw=cpl_frameset_get_size ( *raw );
+<a name="l00187"></a>00187     <span class="keywordflow">if</span> ( nraw==0 )
+<a name="l00188"></a>00188     {
+<a name="l00189"></a>00189         sinfo_msg ( <span class="stringliteral">"Frame %s or %s or %s not found!"</span>,
+<a name="l00190"></a>00190                     PRO_WAVE_LAMP_STACKED,PRO_WAVE_NS_STACKED,PRO_WAVE_SLITPOS_STACKED );
+<a name="l00191"></a>00191         ( *status ) ++;
+<a name="l00192"></a>00192         return   ;
+<a name="l00193"></a>00193     }
+<a name="l00194"></a>00194 
+<a name="l00195"></a>00195     frame = cpl_frameset_get_frame ( *raw,0 );
+<a name="l00196"></a>00196     sinfo_get_spatial_res ( frame,spat_res );
+<a name="l00197"></a>00197 
+<a name="l00198"></a>00198     <span class="keywordflow">switch</span> ( sinfo_frame_is_on ( frame ) )
+<a name="l00199"></a>00199     {
+<a name="l00200"></a>00200         <span class="keywordflow">case</span> 0:
+<a name="l00201"></a>00201             strcpy ( lamp_status,<span class="stringliteral">"on"</span> );
+<a name="l00202"></a>00202             <span class="keywordflow">break</span>;
+<a name="l00203"></a>00203         <span class="keywordflow">case</span> 1:
+<a name="l00204"></a>00204             strcpy ( lamp_status,<span class="stringliteral">"off"</span> );
+<a name="l00205"></a>00205             <span class="keywordflow">break</span>;
+<a name="l00206"></a>00206         <span class="keywordflow">case</span> -1:
+<a name="l00207"></a>00207             strcpy ( lamp_status,<span class="stringliteral">"undefined"</span> );
+<a name="l00208"></a>00208             <span class="keywordflow">break</span>;
+<a name="l00209"></a>00209         <span class="keywordflow">default</span>:
+<a name="l00210"></a>00210             strcpy ( lamp_status,<span class="stringliteral">"undefined"</span> );
+<a name="l00211"></a>00211             <span class="keywordflow">break</span>;
+<a name="l00212"></a>00212 
+<a name="l00213"></a>00213 
+<a name="l00214"></a>00214     }
+<a name="l00215"></a>00215 
+<a name="l00216"></a>00216     sinfo_get_band ( frame,band );
+<a name="l00217"></a>00217     sinfo_msg ( <span class="stringliteral">"Spatial resolution: %s lamp status: %s band: %s \n"</span>,
+<a name="l00218"></a>00218                 spat_res,              lamp_status,    band );
+<a name="l00219"></a>00219 
+<a name="l00220"></a>00220 
+<a name="l00221"></a>00221     sinfo_get_ins_set ( band,&ins_set );
+<a name="l00222"></a>00222     <span class="keywordflow">if</span> ( NULL != cpl_frameset_find ( sof,PRO_WAVE_LAMP_STACKED ) )
+<a name="l00223"></a>00223     {
+<a name="l00224"></a>00224         frame = cpl_frameset_find ( sof,PRO_WAVE_LAMP_STACKED );
+<a name="l00225"></a>00225         strcpy ( cfg -> inFrame,cpl_frame_get_filename ( frame ) );
+<a name="l00226"></a>00226     }
+<a name="l00227"></a>00227     <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( NULL != cpl_frameset_find ( sof,PRO_WAVE_NS_STACKED ) )
+<a name="l00228"></a>00228     {
+<a name="l00229"></a>00229         frame = cpl_frameset_find ( sof,PRO_WAVE_NS_STACKED );
+<a name="l00230"></a>00230         strcpy ( cfg -> inFrame,cpl_frame_get_filename ( frame ) );
+<a name="l00231"></a>00231     }
+<a name="l00232"></a>00232     <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( NULL != cpl_frameset_find ( sof,PRO_WAVE_SLITPOS_STACKED ) )
+<a name="l00233"></a>00233     {
+<a name="l00234"></a>00234         frame = cpl_frameset_find ( sof,PRO_WAVE_SLITPOS_STACKED );
+<a name="l00235"></a>00235         strcpy ( cfg -> inFrame,cpl_frame_get_filename ( frame ) );
+<a name="l00236"></a>00236     }
+<a name="l00237"></a>00237     <span class="keywordflow">else</span>
+<a name="l00238"></a>00238     {
+<a name="l00239"></a>00239         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> ( <span class="stringliteral">"Frame %s or %s not found! Exit!"</span>,
+<a name="l00240"></a>00240                           PRO_WAVE_LAMP_STACKED,PRO_WAVE_NS_STACKED );
+<a name="l00241"></a>00241         ( *status ) ++;
+<a name="l00242"></a>00242         <span class="keywordflow">return</span>;
+<a name="l00243"></a>00243     }
+<a name="l00244"></a>00244 
+<a name="l00245"></a>00245 
+<a name="l00246"></a>00246     <span class="keywordflow">if</span> ( NULL != cpl_frameset_find ( sof,DRS_SETUP_WAVE ) )
+<a name="l00247"></a>00247     {
+<a name="l00248"></a>00248         frame = cpl_frameset_find ( sof,DRS_SETUP_WAVE );
+<a name="l00249"></a>00249         strcpy ( cfg -> drs_setup,cpl_frame_get_filename ( frame ) );
+<a name="l00250"></a>00250         drs_tab = cpl_table_load ( cfg->drs_setup,1,0 );
+<a name="l00251"></a>00251         w->wstart=cpl_table_get_double ( drs_tab,<span class="stringliteral">"W_START"</span>,ins_set,&check );
+<a name="l00252"></a>00252         w->wgdisp1=cpl_table_get_double ( drs_tab,<span class="stringliteral">"W_DISP1"</span>,ins_set,&check );
+<a name="l00253"></a>00253         w->wgdisp2=cpl_table_get_double ( drs_tab,<span class="stringliteral">"W_DISP2"</span>,ins_set,&check );
+<a name="l00254"></a>00254         w->hw=cpl_table_get_int ( drs_tab,<span class="stringliteral">"W_HW"</span>,ins_set,&check );
+<a name="l00255"></a>00255         w->fwhm=cpl_table_get_double ( drs_tab,<span class="stringliteral">"W_FWHM"</span>,ins_set,&check );
+<a name="l00256"></a>00256         w->min_amp=cpl_table_get_double ( drs_tab,<span class="stringliteral">"W_MIN_AMP"</span>,ins_set,&check );
+<a name="l00257"></a>00257         <span class="comment">/*</span>
+<a name="l00258"></a>00258 <span class="comment">            w->min_dif=cpl_table_get_double(drs_tab,"W_MIN_DIF",ins_set,&check);</span>
+<a name="l00259"></a>00259 <span class="comment">            w->na_coef=cpl_table_get_int(drs_tab,"W_NA_COEFF",ins_set,&check);</span>
+<a name="l00260"></a>00260 <span class="comment">            w->nb_coef=cpl_table_get_int(drs_tab,"W_NB_COEFF",ins_set,&check);</span>
+<a name="l00261"></a>00261 <span class="comment">            w->pixel_tol=cpl_table_get_double(drs_tab,"W_PIX_TOL",ins_set,&check);</span>
+<a name="l00262"></a>00262 <span class="comment">            w->y_box=cpl_table_get_double(drs_tab,"W_Y_BOX",ins_set,&check);</span>
+<a name="l00263"></a>00263 <span class="comment">            */</span>
+<a name="l00264"></a>00264         w->low_pos=cpl_table_get_int ( drs_tab,<span class="stringliteral">"W_LOW_POS"</span>,ins_set,&check );
+<a name="l00265"></a>00265         w->hig_pos=cpl_table_get_int ( drs_tab,<span class="stringliteral">"W_HI_POS"</span>,ins_set,&check );
+<a name="l00266"></a>00266 
+<a name="l00267"></a>00267         cfg -> guessBeginWavelength = w->wstart;
+<a name="l00268"></a>00268         cfg -> guessDispersion1 =  w->wgdisp1;
+<a name="l00269"></a>00269         cfg -> guessDispersion2 =  w->wgdisp2;
+<a name="l00270"></a>00270         p = cpl_parameterlist_find ( cpl_cfg, <span class="stringliteral">"sinfoni.wavecal.half_width"</span> );
+<a name="l00271"></a>00271         <span class="keywordflow">if</span> ( sinfo_parameter_get_default_flag ( p ) == 0 )
+<a name="l00272"></a>00272         {
+<a name="l00273"></a>00273 <span class="comment">/*         cpl_msg_info(cpl_func, "param sinfoni.wavecal.half_width - using value from DRS [%i]", w->hw);*/</span>
+<a name="l00274"></a>00274             cfg -> halfWidth =         w->hw;
+<a name="l00275"></a>00275         }
+<a name="l00276"></a>00276    <span class="keywordflow">else</span>
+<a name="l00277"></a>00277    {
+<a name="l00278"></a>00278 <span class="comment">/*         cpl_msg_info(cpl_func, "param sinfoni.wavecal.half_width - using value from command line [%g]", cfg -> halfWidth);   */</span>
+<a name="l00279"></a>00279    }
+<a name="l00280"></a>00280        
+<a name="l00281"></a>00281         p = cpl_parameterlist_find ( cpl_cfg, <span class="stringliteral">"sinfoni.wavecal.fwhm"</span> );
+<a name="l00282"></a>00282         <span class="keywordflow">if</span> ( sinfo_parameter_get_default_flag ( p ) == 0 )
+<a name="l00283"></a>00283         {
+<a name="l00284"></a>00284             cfg -> fwhm =              w->fwhm;
+<a name="l00285"></a>00285 <span class="comment">/*         cpl_msg_info(cpl_func, "param sinfoni.wavecal.fwhm - using value from DRS [%g]", cfg -> fwhm);  */</span>
+<a name="l00286"></a>00286         }
+<a name="l00287"></a>00287       <span class="keywordflow">else</span>
+<a name="l00288"></a>00288       {
+<a name="l00289"></a>00289 <span class="comment">/*         cpl_msg_info(cpl_func, "param sinfoni.wavecal.fwhm - using value from command line [%g]", cfg -> fwhm);     */</span>
+<a name="l00290"></a>00290       }
+<a name="l00291"></a>00291         p = cpl_parameterlist_find ( cpl_cfg, <span class="stringliteral">"sinfoni.wavecal.min_amplitude"</span> );
+<a name="l00292"></a>00292         <span class="keywordflow">if</span> ( sinfo_parameter_get_default_flag ( p ) == 0 )
+<a name="l00293"></a>00293         {
+<a name="l00294"></a>00294             cfg -> minAmplitude =      w->min_amp;
+<a name="l00295"></a>00295 <span class="comment">/*         cpl_msg_info(cpl_func, "param sinfoni.wavecal.min_amplitude - using value from DRS [%g]", cfg -> minAmplitude);         */</span>
+<a name="l00296"></a>00296         }
+<a name="l00297"></a>00297       <span class="keywordflow">else</span>
+<a name="l00298"></a>00298       {
+<a name="l00299"></a>00299 <span class="comment">/*         cpl_msg_info(cpl_func, "param sinfoni.wavecal.min_amplitude - using value from command line [%g]", cfg -> minAmplitude);     */</span>
+<a name="l00300"></a>00300       }      
+<a name="l00301"></a>00301         <span class="comment">/*</span>
+<a name="l00302"></a>00302 <span class="comment">        cfg -> mindiff =           w->min_dif;</span>
+<a name="l00303"></a>00303 <span class="comment">        cfg -> nrDispCoefficients = w->na_coef;</span>
+<a name="l00304"></a>00304 <span class="comment">        cfg -> nrCoefCoefficients = w->nb_coef;</span>
+<a name="l00305"></a>00305 <span class="comment">        cfg -> pixel_tolerance =    w->pixel_tol;</span>
+<a name="l00306"></a>00306 <span class="comment">        cfg -> yBox =               w->y_box;</span>
+<a name="l00307"></a>00307 <span class="comment">        */</span>
+<a name="l00308"></a>00308         cfg -> loPos =              w->low_pos;
+<a name="l00309"></a>00309         cfg -> hiPos =              w->hig_pos;
+<a name="l00310"></a>00310         <span class="comment">/* cfg -> pixel_tolerance =    w->pixel_tol; */</span>
+<a name="l00311"></a>00311         <span class="comment">/*</span>
+<a name="l00312"></a>00312 <span class="comment">            sinfo_msg("cfg->guessBeginWavelength %g",cfg -> guessBeginWavelength);</span>
+<a name="l00313"></a>00313 <span class="comment">            sinfo_msg("cfg->guessDispersion1 %g",cfg -> guessDispersion1);</span>
+<a name="l00314"></a>00314 <span class="comment">            sinfo_msg("cfg->guessDispersion2 %g",cfg -> guessDispersion2);</span>
+<a name="l00315"></a>00315 <span class="comment">            sinfo_msg("cfg->mindiff %g",cfg -> mindiff);</span>
+<a name="l00316"></a>00316 <span class="comment">            sinfo_msg("cfg->halfWidth %d",cfg ->  halfWidth);</span>
+<a name="l00317"></a>00317 <span class="comment">            sinfo_msg("cfg->fwhm %g",cfg -> fwhm);</span>
+<a name="l00318"></a>00318 <span class="comment">            sinfo_msg("cfg->minAmplitude %g",cfg -> minAmplitude);</span>
+<a name="l00319"></a>00319 <span class="comment">            sinfo_msg("cfg->nrDispCoefficients %d",cfg -> nrDispCoefficients); </span>
+<a name="l00320"></a>00320 <span class="comment">            sinfo_msg("cfg->nrCoefCoefficients %d",cfg -> nrCoefCoefficients);</span>
+<a name="l00321"></a>00321 <span class="comment">            sinfo_msg("cfg->pixel_tolerance  %g",cfg -> pixel_tolerance);</span>
+<a name="l00322"></a>00322 <span class="comment">            sinfo_msg("cfg->loPos %d",cfg -> loPos);</span>
+<a name="l00323"></a>00323 <span class="comment">            sinfo_msg("cfg->hiPos %d",cfg -> hiPos);</span>
+<a name="l00324"></a>00324 <span class="comment">            sinfo_msg("cfg->yBox  %f",cfg -> yBox);</span>
+<a name="l00325"></a>00325 <span class="comment">        */</span>
+<a name="l00326"></a>00326 
+<a name="l00327"></a>00327         sinfo_wcal_delete ( w );
+<a name="l00328"></a>00328         cpl_table_delete ( drs_tab );
+<a name="l00329"></a>00329         <span class="keywordflow">if</span> ( -1 == sinfo_check_rec_status ( 0 ) )
+<a name="l00330"></a>00330         {
+<a name="l00331"></a>00331             ( *status ) ++;
+<a name="l00332"></a>00332             <span class="keywordflow">return</span>;
+<a name="l00333"></a>00333         }
+<a name="l00334"></a>00334 
+<a name="l00335"></a>00335     }
+<a name="l00336"></a>00336     <span class="keywordflow">else</span>
+<a name="l00337"></a>00337     {
+<a name="l00338"></a>00338         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> ( <span class="stringliteral">"Frame %s not found! Exit!"</span>, DRS_SETUP_WAVE );
+<a name="l00339"></a>00339         ( *status ) ++;
+<a name="l00340"></a>00340         <span class="keywordflow">return</span>;
+<a name="l00341"></a>00341     }
+<a name="l00342"></a>00342 
+<a name="l00343"></a>00343 
+<a name="l00344"></a>00344     <span class="keywordflow">if</span> ( NULL != cpl_frameset_find ( sof,REF_LINE_ARC ) )
+<a name="l00345"></a>00345     {
+<a name="l00346"></a>00346         frame = cpl_frameset_find ( sof,REF_LINE_ARC );
+<a name="l00347"></a>00347         strcpy ( cfg -> lineList,cpl_frame_get_filename ( frame ) );
+<a name="l00348"></a>00348     }
+<a name="l00349"></a>00349     <span class="keywordflow">else</span>
+<a name="l00350"></a>00350     {
+<a name="l00351"></a>00351         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> ( <span class="stringliteral">"Frame %s not found! Exit!"</span>, REF_LINE_ARC );
+<a name="l00352"></a>00352         ( *status ) ++;
+<a name="l00353"></a>00353         <span class="keywordflow">return</span>;
+<a name="l00354"></a>00354     }
+<a name="l00355"></a>00355 
+<a name="l00356"></a>00356 
+<a name="l00357"></a>00357     <span class="keywordflow">if</span> ( NULL != cpl_frameset_find ( sof,PRO_SLIT_POS_GUESS ) )
+<a name="l00358"></a>00358     {
+<a name="l00359"></a>00359         frame = cpl_frameset_find ( sof,PRO_SLIT_POS_GUESS );
+<a name="l00360"></a>00360         strcpy ( cfg -> slitposGuessName,cpl_frame_get_filename ( frame ) );
+<a name="l00361"></a>00361     }
+<a name="l00362"></a>00362     <span class="keywordflow">else</span>
+<a name="l00363"></a>00363     {
+<a name="l00364"></a>00364         sinfo_msg ( <span class="stringliteral">"Frame %s not found!"</span>, PRO_SLIT_POS_GUESS );
+<a name="l00365"></a>00365     }
+<a name="l00366"></a>00366 
+<a name="l00367"></a>00367     <span class="keywordflow">if</span> ( cfg -> writeParInd ==0 )
+<a name="l00368"></a>00368     {
+<a name="l00369"></a>00369         <span class="keywordflow">if</span> ( NULL != cpl_frameset_find ( sof,PRO_WAVE_PAR_LIST ) )
+<a name="l00370"></a>00370         {
+<a name="l00371"></a>00371             frame = cpl_frameset_find ( sof,PRO_WAVE_PAR_LIST );
+<a name="l00372"></a>00372             strcpy ( cfg ->  paramsList,cpl_frame_get_filename ( frame ) );
+<a name="l00373"></a>00373         }
+<a name="l00374"></a>00374         <span class="keywordflow">else</span>
+<a name="l00375"></a>00375         {
+<a name="l00376"></a>00376             sinfo_msg ( <span class="stringliteral">"Frame %s not found!"</span>, PRO_WAVE_PAR_LIST );
+<a name="l00377"></a>00377             ( *status ) ++;
+<a name="l00378"></a>00378             return   ;
+<a name="l00379"></a>00379         }
+<a name="l00380"></a>00380 
+<a name="l00381"></a>00381     }
+<a name="l00382"></a>00382     <span class="keywordflow">else</span>
+<a name="l00383"></a>00383     {
+<a name="l00384"></a>00384 
+<a name="l00385"></a>00385         strcpy ( cfg -> paramsList, WAVECAL_FIT_PARAMS_OUT_FILENAME );
+<a name="l00386"></a>00386         sinfo_msg ( <span class="stringliteral">"cfg -> paramsList %s not given\n"</span>,cfg -> paramsList );
+<a name="l00387"></a>00387 
+<a name="l00388"></a>00388     }
+<a name="l00389"></a>00389 
+<a name="l00390"></a>00390 
+<a name="l00391"></a>00391 
+<a name="l00392"></a>00392     <span class="keywordflow">if</span> ( cfg -> calibIndicator ==  0 )
+<a name="l00393"></a>00393     {
+<a name="l00394"></a>00394         <span class="keywordflow">if</span> ( NULL != cpl_frameset_find ( sof,PRO_WAVE_COEF_SLIT ) )
+<a name="l00395"></a>00395         {
+<a name="l00396"></a>00396             frame = cpl_frameset_find ( sof,PRO_WAVE_COEF_SLIT );
+<a name="l00397"></a>00397             strcpy ( cfg -> coeffsName,cpl_frame_get_filename ( frame ) );
+<a name="l00398"></a>00398         }
+<a name="l00399"></a>00399         <span class="keywordflow">else</span>
+<a name="l00400"></a>00400         {
+<a name="l00401"></a>00401             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> ( <span class="stringliteral">"Frame %s not found! Exit!"</span>, PRO_WAVE_COEF_SLIT );
+<a name="l00402"></a>00402             ( *status ) ++;
+<a name="l00403"></a>00403             <span class="keywordflow">return</span>;
+<a name="l00404"></a>00404         }
+<a name="l00405"></a>00405     }
+<a name="l00406"></a>00406     <span class="keywordflow">else</span>
+<a name="l00407"></a>00407     {
+<a name="l00408"></a>00408 
+<a name="l00409"></a>00409         strcpy ( cfg -> coeffsName, WAVECAL_COEFF_SLIT_OUT_FILENAME );
+<a name="l00410"></a>00410         sinfo_msg ( <span class="stringliteral">"cfg -> coeffsName %s not given\n"</span>,cfg -> coeffsName );
+<a name="l00411"></a>00411 
+<a name="l00412"></a>00412     }
+<a name="l00413"></a>00413 
+<a name="l00414"></a>00414     strcpy ( cfg -> outName, WAVECAL_OUT_FILENAME );
+<a name="l00415"></a>00415     strcpy ( cfg -> slitposName, WAVECAL_SLIT_POS_OUT_FILENAME );
+<a name="l00416"></a>00416 
+<a name="l00417"></a>00417     <span class="keywordflow">return</span>;
+<a name="l00418"></a>00418 }
+<a name="l00419"></a>00419 
+<a name="l00420"></a>00420 
+<a name="l00421"></a>00421 <span class="keyword">static</span> <span class="keywordtype">void</span>
+<a name="l00422"></a>00422 parse_section_findlines ( wave_config * cfg,cpl_parameterlist* cpl_cfg )
+<a name="l00423"></a>00423 {
+<a name="l00424"></a>00424 
+<a name="l00425"></a>00425     cpl_parameter* p;
+<a name="l00426"></a>00426 
+<a name="l00427"></a>00427     p = cpl_parameterlist_find ( cpl_cfg, <span class="stringliteral">"sinfoni.wavecal.calib_indicator"</span> );
+<a name="l00428"></a>00428     cfg -> calibIndicator = cpl_parameter_get_bool ( p );
+<a name="l00429"></a>00429 
+<a name="l00430"></a>00430     p = cpl_parameterlist_find ( cpl_cfg, <span class="stringliteral">"sinfoni.wavecal.min_diff"</span> );
+<a name="l00431"></a>00431     cfg -> mindiff =  cpl_parameter_get_double ( p );
+<a name="l00432"></a>00432 
+<a name="l00433"></a>00433     p = cpl_parameterlist_find ( cpl_cfg, <span class="stringliteral">"sinfoni.wavecal.half_width"</span> );
+<a name="l00434"></a>00434     cfg -> halfWidth = cpl_parameter_get_int ( p );
+<a name="l00435"></a>00435 
+<a name="l00436"></a>00436     p = cpl_parameterlist_find ( cpl_cfg, <span class="stringliteral">"sinfoni.wavecal.sigma"</span> );
+<a name="l00437"></a>00437     cfg -> sigma =  cpl_parameter_get_double ( p );
+<a name="l00438"></a>00438 
+<a name="l00439"></a>00439     return ;
+<a name="l00440"></a>00440 }
+<a name="l00441"></a>00441 
+<a name="l00442"></a>00442 <span class="keyword">static</span> <span class="keywordtype">void</span>
+<a name="l00443"></a>00443 parse_section_wavecalib ( wave_config * cfg,cpl_parameterlist* cpl_cfg )
+<a name="l00444"></a>00444 {
+<a name="l00445"></a>00445     cpl_parameter* p;
+<a name="l00446"></a>00446 
+<a name="l00447"></a>00447     p = cpl_parameterlist_find ( cpl_cfg, <span class="stringliteral">"sinfoni.wavecal.fwhm"</span> );
+<a name="l00448"></a>00448     cfg -> fwhm =  cpl_parameter_get_double ( p );
+<a name="l00449"></a>00449 
+<a name="l00450"></a>00450     p = cpl_parameterlist_find ( cpl_cfg, <span class="stringliteral">"sinfoni.wavecal.min_amplitude"</span> );
+<a name="l00451"></a>00451     cfg -> minAmplitude =  cpl_parameter_get_double ( p );
+<a name="l00452"></a>00452 
+<a name="l00453"></a>00453     p = cpl_parameterlist_find ( cpl_cfg, <span class="stringliteral">"sinfoni.wavecal.max_residual"</span> );
+<a name="l00454"></a>00454     cfg -> maxResidual =  cpl_parameter_get_double ( p );
+<a name="l00455"></a>00455 
+<a name="l00456"></a>00456     p = cpl_parameterlist_find ( cpl_cfg, <span class="stringliteral">"sinfoni.wavecal.n_a_coefficients"</span> );
+<a name="l00457"></a>00457     cfg -> nrDispCoefficients = cpl_parameter_get_int ( p );
+<a name="l00458"></a>00458 
+<a name="l00459"></a>00459     p = cpl_parameterlist_find ( cpl_cfg, <span class="stringliteral">"sinfoni.wavecal.n_b_coefficients"</span> );
+<a name="l00460"></a>00460     cfg -> nrCoefCoefficients = cpl_parameter_get_int ( p );
+<a name="l00461"></a>00461 
+<a name="l00462"></a>00462     p = cpl_parameterlist_find ( cpl_cfg, <span class="stringliteral">"sinfoni.wavecal.sigma_factor"</span> );
+<a name="l00463"></a>00463     cfg -> sigmaFactor =  cpl_parameter_get_double ( p );
+<a name="l00464"></a>00464 
+<a name="l00465"></a>00465     p = cpl_parameterlist_find ( cpl_cfg, <span class="stringliteral">"sinfoni.wavecal.write_coeffs_ind"</span> );
+<a name="l00466"></a>00466     cfg -> writeCoeffsInd = cpl_parameter_get_bool ( p );
+<a name="l00467"></a>00467 
+<a name="l00468"></a>00468     p = cpl_parameterlist_find ( cpl_cfg, <span class="stringliteral">"sinfoni.wavecal.write_par_ind"</span> );
+<a name="l00469"></a>00469     cfg -> writeParInd = cpl_parameter_get_bool ( p );
+<a name="l00470"></a>00470 
+<a name="l00471"></a>00471     cfg -> nslitlets = NSLITLETS;
+<a name="l00472"></a>00472 
+<a name="l00473"></a>00473     p = cpl_parameterlist_find ( cpl_cfg, <span class="stringliteral">"sinfoni.wavecal.pixel_dist"</span> );
+<a name="l00474"></a>00474     cfg -> pixeldist = cpl_parameter_get_int ( p );
+<a name="l00475"></a>00475 
+<a name="l00476"></a>00476     p = cpl_parameterlist_find ( cpl_cfg, <span class="stringliteral">"sinfoni.wavecal.pixel_tol"</span> );
+<a name="l00477"></a>00477     cfg -> pixel_tolerance = cpl_parameter_get_double ( p );
+<a name="l00478"></a>00478 
+<a name="l00479"></a>00479 }
+<a name="l00480"></a>00480 
+<a name="l00481"></a>00481 <span class="keyword">static</span> <span class="keywordtype">void</span>
+<a name="l00482"></a>00482 parse_section_wavemap ( wave_config * cfg,cpl_parameterlist* cpl_cfg )
+<a name="l00483"></a>00483 {
+<a name="l00484"></a>00484     cpl_parameter* p;
+<a name="l00485"></a>00485 
+<a name="l00486"></a>00486     p = cpl_parameterlist_find ( cpl_cfg, <span class="stringliteral">"sinfoni.wavecal.wave_map_ind"</span> );
+<a name="l00487"></a>00487     cfg -> wavemapInd = cpl_parameter_get_bool ( p );
+<a name="l00488"></a>00488 
+<a name="l00489"></a>00489     p = cpl_parameterlist_find ( cpl_cfg, <span class="stringliteral">"sinfoni.wavecal.mag_factor"</span> );
+<a name="l00490"></a>00490     cfg -> magFactor = cpl_parameter_get_int ( p );
+<a name="l00491"></a>00491 
+<a name="l00492"></a>00492 
+<a name="l00493"></a>00493 }
+<a name="l00494"></a>00494 
+<a name="l00495"></a>00495 <span class="keyword">static</span> <span class="keywordtype">void</span>
+<a name="l00496"></a>00496 parse_section_fitslits ( wave_config * cfg,cpl_parameterlist* cpl_cfg )
+<a name="l00497"></a>00497 {
+<a name="l00498"></a>00498 
+<a name="l00499"></a>00499     cpl_parameter* p;
+<a name="l00500"></a>00500 
+<a name="l00501"></a>00501     p = cpl_parameterlist_find ( cpl_cfg, <span class="stringliteral">"sinfoni.wavecal.slit_pos_indicator"</span> );
+<a name="l00502"></a>00502     cfg -> slitposIndicator = cpl_parameter_get_bool ( p );
+<a name="l00503"></a>00503 
+<a name="l00504"></a>00504     p = cpl_parameterlist_find ( cpl_cfg, <span class="stringliteral">"sinfoni.wavecal.fit_boltz_indicator"</span> );
+<a name="l00505"></a>00505     cfg -> fitBoltzIndicator = cpl_parameter_get_bool ( p );
+<a name="l00506"></a>00506 
+<a name="l00507"></a>00507     p = cpl_parameterlist_find ( cpl_cfg, <span class="stringliteral">"sinfoni.wavecal.fit_edge_indicator"</span> );
+<a name="l00508"></a>00508     cfg -> fitEdgeIndicator = cpl_parameter_get_bool ( p );
+<a name="l00509"></a>00509 
+<a name="l00510"></a>00510     p = cpl_parameterlist_find ( cpl_cfg, <span class="stringliteral">"sinfoni.wavecal.estimate_indicator"</span> );
+<a name="l00511"></a>00511     cfg -> estimateIndicator = cpl_parameter_get_bool ( p );
+<a name="l00512"></a>00512 
+<a name="l00513"></a>00513     cfg -> loPos =  750;
+<a name="l00514"></a>00514     cfg -> hiPos =  1000;
+<a name="l00515"></a>00515 
+<a name="l00516"></a>00516     p = cpl_parameterlist_find ( cpl_cfg, <span class="stringliteral">"sinfoni.wavecal.box_length"</span> );
+<a name="l00517"></a>00517     cfg -> boxLength = cpl_parameter_get_int ( p );
+<a name="l00518"></a>00518 
+<a name="l00519"></a>00519     p = cpl_parameterlist_find ( cpl_cfg, <span class="stringliteral">"sinfoni.wavecal.y_box"</span> );
+<a name="l00520"></a>00520     cfg -> yBox = cpl_parameter_get_double ( p );
+<a name="l00521"></a>00521 
+<a name="l00522"></a>00522     p = cpl_parameterlist_find ( cpl_cfg, <span class="stringliteral">"sinfoni.wavecal.diff_tol"</span> );
+<a name="l00523"></a>00523     cfg -> diffTol =  cpl_parameter_get_double ( p );
+<a name="l00524"></a>00524 
+<a name="l00525"></a>00525     <span class="comment">/* input CDB</span>
+<a name="l00526"></a>00526 <span class="comment">    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.wavecal.slit_pos_guess_name");</span>
+<a name="l00527"></a>00527 <span class="comment">    strcpy(cfg -> slitposGuessName, cpl_parameter_get_default_string(p));</span>
+<a name="l00528"></a>00528 <span class="comment">    */</span>
+<a name="l00529"></a>00529 
+<a name="l00530"></a>00530 }
+<a name="l00531"></a>00531 
+<a name="l00532"></a>00532 <span class="keyword">static</span> <span class="keywordtype">void</span>
+<a name="l00533"></a>00533 parse_section_qclog ( wave_config * cfg, cpl_parameterlist* cpl_cfg )
+<a name="l00534"></a>00534 {
+<a name="l00535"></a>00535     cpl_parameter* p;
+<a name="l00536"></a>00536 
+<a name="l00537"></a>00537     p = cpl_parameterlist_find ( cpl_cfg, <span class="stringliteral">"sinfoni.wavecal.qc_thresh_min"</span> );
+<a name="l00538"></a>00538     cfg ->  qc_thresh_min = cpl_parameter_get_int ( p );
+<a name="l00539"></a>00539 
+<a name="l00540"></a>00540 
+<a name="l00541"></a>00541     p = cpl_parameterlist_find ( cpl_cfg, <span class="stringliteral">"sinfoni.wavecal.qc_thresh_max"</span> );
+<a name="l00542"></a>00542     cfg ->  qc_thresh_max = cpl_parameter_get_int ( p );
+<a name="l00543"></a>00543 
+<a name="l00544"></a>00544 
+<a name="l00545"></a>00545 }
+<a name="l00546"></a>00546 
+<a name="l00547"></a>00547 <span class="keywordtype">void</span>
+<a name="l00548"></a>00548 sinfo_wavecal_free ( wave_config ** cfg )
+<a name="l00549"></a>00549 {
+<a name="l00550"></a>00550     <span class="keywordflow">if</span> ( *cfg != NULL )
+<a name="l00551"></a>00551     {
+<a name="l00552"></a>00552         sinfo_wave_cfg_destroy ( *cfg );
+<a name="l00553"></a>00553         *cfg=NULL;
+<a name="l00554"></a>00554     }
+<a name="l00555"></a>00555     <span class="keywordflow">return</span>;
+<a name="l00556"></a>00556 
+<a name="l00557"></a>00557 }
+<a name="l00558"></a>00558 
+<a name="l00559"></a>00559 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__wavecal__ini__by__cpl_8h_source.html b/html/sinfo__wavecal__ini__by__cpl_8h_source.html
new file mode 100644
index 0000000..f8ee3a0
--- /dev/null
+++ b/html/sinfo__wavecal__ini__by__cpl_8h_source.html
@@ -0,0 +1,61 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_wavecal_ini_by_cpl.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_wavecal_ini_by_cpl.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
+<a name="l00002"></a>00002 <span class="comment"> * This file is part of the ESO SINFONI Pipeline</span>
+<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2004,2005 European Southern Observatory</span>
+<a name="l00004"></a>00004 <span class="comment"> *</span>
+<a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00009"></a>00009 <span class="comment"> *</span>
+<a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00014"></a>00014 <span class="comment"> *</span>
+<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00016"></a>00016 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00017"></a>00017 <span class="comment"> * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA</span>
+<a name="l00018"></a>00018 <span class="comment"> */</span>
+<a name="l00019"></a>00019 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00020"></a>00020 <span class="comment">   </span>
+<a name="l00021"></a>00021 <span class="comment">   File name    :   sinfo_wavecal_ini_by_cpl.h</span>
+<a name="l00022"></a>00022 <span class="comment">   Author       :   Andrea Modigliani</span>
+<a name="l00023"></a>00023 <span class="comment">   Created on   :   May 21, 2004</span>
+<a name="l00024"></a>00024 <span class="comment">   Description  :   wavelength calibration cpl input handling for SPIFFI</span>
+<a name="l00025"></a>00025 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00026"></a>00026 <span class="preprocessor">#ifndef SINFO_WAVECAL_INI_BY_CPL_H</span>
+<a name="l00027"></a>00027 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_WAVECAL_INI_BY_CPL_H</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------</span>
+<a name="l00029"></a>00029 <span class="comment">                                Includes</span>
+<a name="l00030"></a>00030 <span class="comment">---------------------------------------------------------------------------*/</span>
+<a name="l00031"></a>00031 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00032"></a>00032 <span class="preprocessor">#include "sinfo_wavecal_cfg.h"</span>
+<a name="l00033"></a>00033 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00034"></a>00034 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00035"></a>00035 <span class="comment">                             Function prototypes </span>
+<a name="l00036"></a>00036 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00050"></a>00050 wave_config * 
+<a name="l00051"></a>00051 sinfo_parse_cpl_input_wave(cpl_parameterlist * cpl_cfg, 
+<a name="l00052"></a>00052                            cpl_frameset* sof, 
+<a name="l00053"></a>00053                cpl_frameset** raw) ;
+<a name="l00054"></a>00054 
+<a name="l00061"></a>00061 <span class="keywordtype">void</span> 
+<a name="l00062"></a>00062 sinfo_wavecal_free(wave_config ** cfg);
+<a name="l00063"></a>00063 
+<a name="l00064"></a>00064 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__wcal__functions_8c_source.html b/html/sinfo__wcal__functions_8c_source.html
new file mode 100644
index 0000000..8d85c0e
--- /dev/null
+++ b/html/sinfo__wcal__functions_8c_source.html
@@ -0,0 +1,422 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_wcal_functions.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_wcal_functions.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_wcal_functions.c,v 1.9 2012/03/03 10:35:14 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the SINFONI Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2012/03/03 10:35:14 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.9 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 
+<a name="l00029"></a>00029 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00031"></a>00031 <span class="preprocessor">#endif</span>
+<a name="l00032"></a>00032 <span class="preprocessor"></span><span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                                   Includes</span>
+<a name="l00034"></a>00034 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 
+<a name="l00036"></a>00036 <span class="preprocessor">#include "sinfo_wcal_functions.h"</span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include "sinfo_globals.h"</span>
+<a name="l00038"></a>00038 <span class="preprocessor">#include "sinfo_error.h"</span>
+<a name="l00039"></a>00039 <span class="preprocessor">#include "sinfo_utils_wrappers.h"</span>
+<a name="l00040"></a>00040 
+<a name="l00041"></a>00041 <span class="comment">/* struct qc_wcal qc_wcal_par; */</span>
+<a name="l00049"></a>00049 qc_wcal* sinfo_qc_wcal_new(<span class="keywordtype">void</span>)
+<a name="l00050"></a>00050 {  
+<a name="l00051"></a>00051 
+<a name="l00052"></a>00052   qc_wcal * qc;
+<a name="l00053"></a>00053   qc= cpl_malloc(<span class="keyword">sizeof</span>(qc_wcal));
+<a name="l00054"></a>00054 
+<a name="l00055"></a>00055   qc->avg_on=0; 
+<a name="l00056"></a>00056   qc->std_on=0;
+<a name="l00057"></a>00057   qc->avg_of=0; 
+<a name="l00058"></a>00058   qc->std_of=0;
+<a name="l00059"></a>00059   qc->avg_di=0; 
+<a name="l00060"></a>00060   qc->std_di=0;
+<a name="l00061"></a>00061   qc->max_on=0;
+<a name="l00062"></a>00062   qc->max_of=0;
+<a name="l00063"></a>00063   qc->max_di=0;
+<a name="l00064"></a>00064   qc->nsat_on=0;
+<a name="l00065"></a>00065   qc->noise_on=0;
+<a name="l00066"></a>00066   qc->noise_of=0;
+<a name="l00067"></a>00067   qc->flux_on=0;
+<a name="l00068"></a>00068   qc->nsat=0;
+<a name="l00069"></a>00069   <span class="keywordflow">return</span> qc;
+<a name="l00070"></a>00070 }
+<a name="l00071"></a>00071 
+<a name="l00072"></a>00072 <span class="keywordtype">void</span> sinfo_qc_wcal_delete(qc_wcal** qc)
+<a name="l00073"></a>00073 {
+<a name="l00074"></a>00074   cpl_free(*qc);
+<a name="l00075"></a>00075   *qc = NULL;
+<a name="l00076"></a>00076 }
+<a name="l00077"></a>00077 
+<a name="l00078"></a>00078 <span class="keywordtype">int</span> sinfo_dumpTblToFitParams ( FitParams ** params, <span class="keywordtype">char</span> * filename )
+<a name="l00079"></a>00079 {
+<a name="l00080"></a>00080     cpl_table * fp =NULL;
+<a name="l00081"></a>00081     <span class="keywordtype">char</span>* col=NULL;
+<a name="l00082"></a>00082     <span class="keywordtype">int</span> i =0;
+<a name="l00083"></a>00083     <span class="keywordtype">int</span> j =0;
+<a name="l00084"></a>00084     <span class="keywordtype">int</span> status=0;
+<a name="l00085"></a>00085 
+<a name="l00086"></a>00086 
+<a name="l00087"></a>00087     <span class="keywordflow">if</span> ( NULL == params )
+<a name="l00088"></a>00088     {
+<a name="l00089"></a>00089         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"no fit parameters available!"</span>) ;
+<a name="l00090"></a>00090         <span class="keywordflow">return</span> -1;
+<a name="l00091"></a>00091     }
+<a name="l00092"></a>00092 
+<a name="l00093"></a>00093     <span class="keywordflow">if</span> ( NULL == filename )
+<a name="l00094"></a>00094     {
+<a name="l00095"></a>00095         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a> (<span class="stringliteral">"no filename available!"</span>) ;
+<a name="l00096"></a>00096         <span class="keywordflow">return</span> -1;
+<a name="l00097"></a>00097     }
+<a name="l00098"></a>00098    
+<a name="l00099"></a>00099 
+<a name="l00100"></a>00100     fp=cpl_table_load(filename,1,0);
+<a name="l00101"></a>00101     <span class="keywordflow">if</span>(cpl_error_get_code() != CPL_ERROR_NONE) {
+<a name="l00102"></a>00102       sinfo_msg(<span class="stringliteral">"cannot load table %s"</span>,filename);
+<a name="l00103"></a>00103       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>((<span class="keywordtype">char</span>* ) cpl_error_get_message());
+<a name="l00104"></a>00104       <span class="keywordflow">return</span> -1;
+<a name="l00105"></a>00105     }
+<a name="l00106"></a>00106 
+<a name="l00107"></a>00107     col = (<span class="keywordtype">char</span>*) cpl_calloc(MAX_NAME_SIZE,<span class="keyword">sizeof</span>(<span class="keywordtype">char</span>*));
+<a name="l00108"></a>00108     <span class="keywordflow">for</span> ( i = 0 ; i < params[0]->n_params ; i++ )
+<a name="l00109"></a>00109     {
+<a name="l00110"></a>00110        params[i]->n_params=cpl_table_get_int(fp,<span class="stringliteral">"n_params"</span>,i,&status);
+<a name="l00111"></a>00111        params[i]->column  =cpl_table_get_int(fp,<span class="stringliteral">"column"</span>,i,&status);
+<a name="l00112"></a>00112        params[i]->line    =cpl_table_get_int(fp,<span class="stringliteral">"line"</span>,i,&status);
+<a name="l00113"></a>00113        <span class="keywordflow">for</span> (j=0 ; j < 4; j++) {
+<a name="l00114"></a>00114      snprintf(col,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%d"</span>,<span class="stringliteral">"fpar"</span>,j);
+<a name="l00115"></a>00115          params[i]->fit_par[j]=cpl_table_get_double(fp,col,i,&status);
+<a name="l00116"></a>00116      snprintf(col,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%d"</span>,<span class="stringliteral">"dpar"</span>,j);
+<a name="l00117"></a>00117          params[i]->derv_par[j]=cpl_table_get_double(fp,col,i,&status);
+<a name="l00118"></a>00118        }
+<a name="l00119"></a>00119     }
+<a name="l00120"></a>00120     cpl_free(col);
+<a name="l00121"></a>00121     cpl_table_delete(fp) ;
+<a name="l00122"></a>00122     <span class="keywordflow">return</span> 0;
+<a name="l00123"></a>00123 }
+<a name="l00124"></a>00124 
+<a name="l00125"></a>00125 
+<a name="l00126"></a>00126 
+<a name="l00127"></a>00127 
+<a name="l00128"></a>00128 <span class="keywordtype">int</span> sinfo_det_ncounts(cpl_frameset* raw, <span class="keywordtype">int</span> thresh_max, qc_wcal* qc)
+<a name="l00129"></a>00129 {
+<a name="l00130"></a>00130  <span class="keywordtype">int</span> i=0;
+<a name="l00131"></a>00131  <span class="keywordtype">int</span> j=0;
+<a name="l00132"></a>00132 
+<a name="l00133"></a>00133  <span class="keywordtype">long</span> nraw=0;
+<a name="l00134"></a>00134  <span class="keywordtype">int</span> non=0;
+<a name="l00135"></a>00135  <span class="keywordtype">int</span> noff=0;
+<a name="l00136"></a>00136  <span class="keywordtype">int</span> nsat=0;
+<a name="l00137"></a>00137 
+<a name="l00138"></a>00138  <span class="keywordtype">double</span> mean=0;
+<a name="l00139"></a>00139  <span class="keywordtype">double</span> max=0;
+<a name="l00140"></a>00140 
+<a name="l00141"></a>00141  <span class="keywordtype">double</span> mjd_on=0;
+<a name="l00142"></a>00142  <span class="keywordtype">double</span> mjd_of=0;
+<a name="l00143"></a>00143  <span class="keywordtype">double</span> mjd_of_frm=0;
+<a name="l00144"></a>00144 
+<a name="l00145"></a>00145  <span class="keywordtype">char</span> name[FILE_NAME_SZ];
+<a name="l00146"></a>00146  <span class="keywordtype">char</span> filename[FILE_NAME_SZ];
+<a name="l00147"></a>00147 
+<a name="l00148"></a>00148 
+<a name="l00149"></a>00149  cpl_vector* avg_on=NULL;
+<a name="l00150"></a>00150  cpl_vector* avg_of=NULL;
+<a name="l00151"></a>00151  cpl_vector* avg_di=NULL;
+<a name="l00152"></a>00152 
+<a name="l00153"></a>00153 
+<a name="l00154"></a>00154  cpl_vector* max_on=NULL;
+<a name="l00155"></a>00155  cpl_vector* max_of=NULL;
+<a name="l00156"></a>00156  cpl_vector* max_di=NULL;
+<a name="l00157"></a>00157 
+<a name="l00158"></a>00158  cpl_vector* vec_nsat=NULL;
+<a name="l00159"></a>00159 
+<a name="l00160"></a>00160  cpl_frame* frm=NULL;
+<a name="l00161"></a>00161  cpl_frame* frm_dup=NULL;
+<a name="l00162"></a>00162  cpl_frame* on_frm=NULL;
+<a name="l00163"></a>00163  cpl_frame* of_frm=NULL;
+<a name="l00164"></a>00164  cpl_frame* tmp_of_frm=NULL;
+<a name="l00165"></a>00165 
+<a name="l00166"></a>00166  cpl_image* dif_ima=NULL;
+<a name="l00167"></a>00167  cpl_image* on_ima=NULL;
+<a name="l00168"></a>00168  cpl_image* of_ima=NULL;
+<a name="l00169"></a>00169  cpl_image* tmp_ima=NULL;
+<a name="l00170"></a>00170 
+<a name="l00171"></a>00171  cpl_frameset* on_set=NULL;
+<a name="l00172"></a>00172  cpl_frameset* of_set=NULL;
+<a name="l00173"></a>00173  
+<a name="l00174"></a>00174  on_set=cpl_frameset_new();
+<a name="l00175"></a>00175  of_set=cpl_frameset_new();
+<a name="l00176"></a>00176  nraw = cpl_frameset_get_size(raw);
+<a name="l00177"></a>00177 
+<a name="l00178"></a>00178 
+<a name="l00179"></a>00179  <span class="keywordflow">for</span> (i=0; i< nraw; i++) {
+<a name="l00180"></a>00180    check_nomsg(frm = cpl_frameset_get_frame(raw,i));
+<a name="l00181"></a>00181    check_nomsg(frm_dup = cpl_frame_duplicate(frm));
+<a name="l00182"></a>00182    <span class="keywordflow">if</span>(sinfo_frame_is_on(frm) == 1) {
+<a name="l00183"></a>00183      cpl_frameset_insert(on_set,frm_dup);
+<a name="l00184"></a>00184      non++;
+<a name="l00185"></a>00185    } <span class="keywordflow">else</span> {
+<a name="l00186"></a>00186      cpl_frameset_insert(of_set,frm_dup);
+<a name="l00187"></a>00187      noff++;
+<a name="l00188"></a>00188    }
+<a name="l00189"></a>00189  }
+<a name="l00190"></a>00190 
+<a name="l00191"></a>00191 
+<a name="l00192"></a>00192  <span class="keywordflow">if</span> (non == noff) {   
+<a name="l00193"></a>00193      sinfo_msg(<span class="stringliteral">"Monitor counts: case Non==Noff"</span>);
+<a name="l00194"></a>00194 
+<a name="l00195"></a>00195 
+<a name="l00196"></a>00196     avg_on = cpl_vector_new(non);
+<a name="l00197"></a>00197     avg_of = cpl_vector_new(non);
+<a name="l00198"></a>00198     avg_di = cpl_vector_new(non);
+<a name="l00199"></a>00199 
+<a name="l00200"></a>00200     max_on = cpl_vector_new(non);
+<a name="l00201"></a>00201     max_of = cpl_vector_new(non);
+<a name="l00202"></a>00202     max_di = cpl_vector_new(non);
+<a name="l00203"></a>00203 
+<a name="l00204"></a>00204 
+<a name="l00205"></a>00205 
+<a name="l00206"></a>00206     vec_nsat = cpl_vector_new(non);
+<a name="l00207"></a>00207     <span class="keywordflow">for</span> (i=0; i< non; i++) {
+<a name="l00208"></a>00208       check_nomsg(on_frm = cpl_frameset_get_frame(on_set,i));
+<a name="l00209"></a>00209       strcpy(name,cpl_frame_get_filename(on_frm));
+<a name="l00210"></a>00210       check_nomsg(on_ima = cpl_image_load(name,CPL_TYPE_FLOAT,0,0));
+<a name="l00211"></a>00211 
+<a name="l00212"></a>00212       check_nomsg(mean= cpl_image_get_mean(on_ima));
+<a name="l00213"></a>00213       check_nomsg(cpl_vector_set(avg_on,i,mean));
+<a name="l00214"></a>00214       check_nomsg(max= cpl_image_get_max(on_ima));
+<a name="l00215"></a>00215       check_nomsg(cpl_vector_set(max_on,i,max));
+<a name="l00216"></a>00216       check_nomsg(tmp_ima = cpl_image_duplicate(on_ima));
+<a name="l00217"></a>00217       check_nomsg(cpl_image_threshold(tmp_ima,thresh_max,thresh_max,0,1));
+<a name="l00218"></a>00218       check_nomsg(nsat=cpl_image_get_flux(tmp_ima));
+<a name="l00219"></a>00219       check_nomsg(cpl_vector_set(vec_nsat,i,nsat));
+<a name="l00220"></a>00220 
+<a name="l00221"></a>00221 
+<a name="l00222"></a>00222       check_nomsg(of_frm = cpl_frameset_get_frame(of_set,i));
+<a name="l00223"></a>00223       strcpy(name,cpl_frame_get_filename(of_frm));
+<a name="l00224"></a>00224       check_nomsg(of_ima = cpl_image_load(name,CPL_TYPE_FLOAT,0,0));
+<a name="l00225"></a>00225       check_nomsg(mean= cpl_image_get_mean(of_ima));
+<a name="l00226"></a>00226       check_nomsg(cpl_vector_set(avg_of,i,mean));
+<a name="l00227"></a>00227       check_nomsg(max= cpl_image_get_max(of_ima));
+<a name="l00228"></a>00228       check_nomsg(cpl_vector_set(max_of,i,max));
+<a name="l00229"></a>00229      
+<a name="l00230"></a>00230       check_nomsg(dif_ima = cpl_image_subtract_create(on_ima,of_ima));
+<a name="l00231"></a>00231       check_nomsg(mean= cpl_image_get_mean(dif_ima));
+<a name="l00232"></a>00232       check_nomsg(cpl_vector_set(avg_di,i,mean));
+<a name="l00233"></a>00233       check_nomsg(max= cpl_image_get_max(dif_ima));
+<a name="l00234"></a>00234       check_nomsg(cpl_vector_set(max_di,i,max));
+<a name="l00235"></a>00235 
+<a name="l00236"></a>00236       sinfo_free_image(&on_ima);
+<a name="l00237"></a>00237       sinfo_free_image(&of_ima);
+<a name="l00238"></a>00238       sinfo_free_image(&dif_ima);
+<a name="l00239"></a>00239       sinfo_free_image(&tmp_ima);
+<a name="l00240"></a>00240 
+<a name="l00241"></a>00241     }
+<a name="l00242"></a>00242 
+<a name="l00243"></a>00243     check_nomsg(qc->avg_on=cpl_vector_get_mean(avg_on));
+<a name="l00244"></a>00244     check_nomsg(qc->avg_of=cpl_vector_get_mean(avg_of));
+<a name="l00245"></a>00245     check_nomsg(qc->avg_di=cpl_vector_get_mean(avg_di));
+<a name="l00246"></a>00246 
+<a name="l00247"></a>00247     check_nomsg(qc->max_on=cpl_vector_get_max(max_on));
+<a name="l00248"></a>00248     check_nomsg(qc->max_of=cpl_vector_get_max(max_of));
+<a name="l00249"></a>00249     check_nomsg(qc->max_di=cpl_vector_get_max(max_di));
+<a name="l00250"></a>00250 
+<a name="l00251"></a>00251     check_nomsg(qc->nsat=cpl_vector_get_mean(vec_nsat));
+<a name="l00252"></a>00252 
+<a name="l00253"></a>00253     <span class="keywordflow">if</span> (non > 1) {
+<a name="l00254"></a>00254       check_nomsg(qc->std_on=cpl_vector_get_stdev(avg_on));
+<a name="l00255"></a>00255       check_nomsg(qc->std_of=cpl_vector_get_stdev(avg_of));
+<a name="l00256"></a>00256       check_nomsg(qc->std_di=cpl_vector_get_stdev(avg_di));
+<a name="l00257"></a>00257     }
+<a name="l00258"></a>00258 
+<a name="l00259"></a>00259     sinfo_free_my_vector(&avg_on);
+<a name="l00260"></a>00260     sinfo_free_my_vector(&avg_of);
+<a name="l00261"></a>00261     sinfo_free_my_vector(&avg_di);    
+<a name="l00262"></a>00262 
+<a name="l00263"></a>00263     sinfo_free_my_vector(&max_on);
+<a name="l00264"></a>00264     sinfo_free_my_vector(&max_of);
+<a name="l00265"></a>00265     sinfo_free_my_vector(&max_di);
+<a name="l00266"></a>00266 
+<a name="l00267"></a>00267     sinfo_free_my_vector(&vec_nsat);
+<a name="l00268"></a>00268 
+<a name="l00269"></a>00269 
+<a name="l00270"></a>00270  } <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( ((non ==0) | (noff == 0)) && (nraw > 0 ) ) {
+<a name="l00271"></a>00271     sinfo_msg(<span class="stringliteral">"Monitor counts: case Nraw == 1"</span>);
+<a name="l00272"></a>00272     check_nomsg(avg_di = cpl_vector_new(nraw));
+<a name="l00273"></a>00273     check_nomsg(max_di = cpl_vector_new(nraw));
+<a name="l00274"></a>00274     check_nomsg(vec_nsat = cpl_vector_new(nraw));
+<a name="l00275"></a>00275 
+<a name="l00276"></a>00276     <span class="keywordflow">for</span> (i=0; i< nraw; i++) {
+<a name="l00277"></a>00277       check_nomsg(frm = cpl_frameset_get_frame(raw,i));
+<a name="l00278"></a>00278       strcpy(name,cpl_frame_get_filename(frm));
+<a name="l00279"></a>00279       check_nomsg(dif_ima = cpl_image_load(name,CPL_TYPE_FLOAT,0,0));
+<a name="l00280"></a>00280 
+<a name="l00281"></a>00281       check_nomsg(mean= cpl_image_get_mean(dif_ima));
+<a name="l00282"></a>00282       check_nomsg(tmp_ima=cpl_image_duplicate(dif_ima));
+<a name="l00283"></a>00283       sinfo_clean_nan(&tmp_ima);
+<a name="l00284"></a>00284       check_nomsg(mean= cpl_image_get_mean(tmp_ima));
+<a name="l00285"></a>00285       check_nomsg(cpl_vector_set(avg_di,i,mean));
+<a name="l00286"></a>00286       check_nomsg(max= cpl_image_get_max(tmp_ima));
+<a name="l00287"></a>00287       check_nomsg(cpl_vector_set(max_di,i,max));
+<a name="l00288"></a>00288       check_nomsg(cpl_image_threshold(tmp_ima,thresh_max,thresh_max,0,1));
+<a name="l00289"></a>00289       check_nomsg(nsat=cpl_image_get_flux(tmp_ima));
+<a name="l00290"></a>00290       check_nomsg(cpl_vector_set(vec_nsat,i,nsat));
+<a name="l00291"></a>00291 
+<a name="l00292"></a>00292       sinfo_free_image(&tmp_ima);
+<a name="l00293"></a>00293       sinfo_free_image(&dif_ima);
+<a name="l00294"></a>00294 
+<a name="l00295"></a>00295     }
+<a name="l00296"></a>00296 
+<a name="l00297"></a>00297     qc->avg_di=cpl_vector_get_mean(avg_di);
+<a name="l00298"></a>00298     <span class="keywordflow">if</span> (nraw > 1) {
+<a name="l00299"></a>00299       check_nomsg(qc->std_di=cpl_vector_get_stdev(avg_di));
+<a name="l00300"></a>00300     }
+<a name="l00301"></a>00301     check_nomsg(qc->max_di=cpl_vector_get_max(max_di));
+<a name="l00302"></a>00302     check_nomsg(qc->nsat=cpl_vector_get_mean(vec_nsat));
+<a name="l00303"></a>00303 
+<a name="l00304"></a>00304     sinfo_free_my_vector(&avg_di);
+<a name="l00305"></a>00305     sinfo_free_my_vector(&max_di);
+<a name="l00306"></a>00306     sinfo_free_my_vector(&vec_nsat);
+<a name="l00307"></a>00307 
+<a name="l00308"></a>00308  } <span class="keywordflow">else</span> {
+<a name="l00309"></a>00309    sinfo_msg(<span class="stringliteral">"Monitor counts: else case"</span>);
+<a name="l00310"></a>00310 
+<a name="l00311"></a>00311     avg_on = cpl_vector_new(non);
+<a name="l00312"></a>00312     avg_of = cpl_vector_new(non);
+<a name="l00313"></a>00313     avg_di = cpl_vector_new(non);
+<a name="l00314"></a>00314 
+<a name="l00315"></a>00315     max_on = cpl_vector_new(non);
+<a name="l00316"></a>00316     max_of = cpl_vector_new(non);
+<a name="l00317"></a>00317     max_di = cpl_vector_new(non);
+<a name="l00318"></a>00318 
+<a name="l00319"></a>00319     vec_nsat = cpl_vector_new(non);
+<a name="l00320"></a>00320 
+<a name="l00321"></a>00321     <span class="keywordflow">for</span> (i=0;i<non;i++) {
+<a name="l00322"></a>00322       check_nomsg(on_frm=cpl_frameset_get_frame(on_set,i));
+<a name="l00323"></a>00323       check_nomsg(mjd_on=sinfo_get_mjd_obs(on_frm));
+<a name="l00324"></a>00324       check_nomsg(of_frm=cpl_frameset_get_frame(of_set,0));
+<a name="l00325"></a>00325       check_nomsg(mjd_of=sinfo_get_mjd_obs(of_frm));
+<a name="l00326"></a>00326       strcpy(filename,cpl_frame_get_filename(of_frm));
+<a name="l00327"></a>00327 
+<a name="l00328"></a>00328       <span class="keywordflow">for</span> (j=1;j<noff;j++) {
+<a name="l00329"></a>00329     check_nomsg(tmp_of_frm = cpl_frameset_get_frame(of_set,j));
+<a name="l00330"></a>00330         check_nomsg(mjd_of_frm = sinfo_get_mjd_obs(tmp_of_frm));
+<a name="l00331"></a>00331 
+<a name="l00332"></a>00332           <span class="keywordflow">if</span>(1000.*(mjd_of_frm-mjd_on)*(mjd_of_frm-mjd_on) <
+<a name="l00333"></a>00333              1000.*(mjd_of-    mjd_on)*(mjd_of-    mjd_on) ) {
+<a name="l00334"></a>00334             mjd_of=mjd_of_frm;
+<a name="l00335"></a>00335              of_frm=tmp_of_frm;
+<a name="l00336"></a>00336       }
+<a name="l00337"></a>00337       }
+<a name="l00338"></a>00338 
+<a name="l00339"></a>00339        strcpy(filename,cpl_frame_get_filename(of_frm));
+<a name="l00340"></a>00340        check_nomsg(of_ima = cpl_image_load(filename,CPL_TYPE_FLOAT,0,0));
+<a name="l00341"></a>00341        check_nomsg(mean= cpl_image_get_mean(of_ima));
+<a name="l00342"></a>00342        check_nomsg(cpl_vector_set(avg_of,i,mean));
+<a name="l00343"></a>00343        check_nomsg(max= cpl_image_get_max(of_ima));
+<a name="l00344"></a>00344        check_nomsg(cpl_vector_set(max_of,i,max));
+<a name="l00345"></a>00345 
+<a name="l00346"></a>00346        strcpy(filename,cpl_frame_get_filename(on_frm));
+<a name="l00347"></a>00347        check_nomsg(on_ima = cpl_image_load(filename,CPL_TYPE_FLOAT,0,0));
+<a name="l00348"></a>00348        check_nomsg(mean= cpl_image_get_mean(on_ima)); 
+<a name="l00349"></a>00349        check_nomsg(cpl_vector_set(avg_on,i,mean));
+<a name="l00350"></a>00350        check_nomsg(max= cpl_image_get_mean(on_ima)); 
+<a name="l00351"></a>00351        check_nomsg(cpl_vector_set(max_on,i,max));
+<a name="l00352"></a>00352 
+<a name="l00353"></a>00353        check_nomsg(tmp_ima = cpl_image_duplicate(on_ima));     
+<a name="l00354"></a>00354        check_nomsg(cpl_image_threshold(tmp_ima,thresh_max,thresh_max,0,1));
+<a name="l00355"></a>00355        check_nomsg(nsat=cpl_image_get_flux(tmp_ima));
+<a name="l00356"></a>00356        check_nomsg(cpl_vector_set(vec_nsat,i,nsat));
+<a name="l00357"></a>00357 
+<a name="l00358"></a>00358        check_nomsg(dif_ima = cpl_image_subtract_create(on_ima,of_ima));
+<a name="l00359"></a>00359        check_nomsg(mean= cpl_image_get_mean(dif_ima));
+<a name="l00360"></a>00360        check_nomsg(cpl_vector_set(avg_di,i,mean));
+<a name="l00361"></a>00361        check_nomsg(max= cpl_image_get_max(dif_ima));
+<a name="l00362"></a>00362        check_nomsg(cpl_vector_set(max_di,i,max));
+<a name="l00363"></a>00363 
+<a name="l00364"></a>00364        sinfo_free_image(&on_ima);
+<a name="l00365"></a>00365        sinfo_free_image(&of_ima);
+<a name="l00366"></a>00366        sinfo_free_image(&dif_ima);
+<a name="l00367"></a>00367        sinfo_free_image(&tmp_ima);
+<a name="l00368"></a>00368 
+<a name="l00369"></a>00369    }
+<a name="l00370"></a>00370 
+<a name="l00371"></a>00371     sinfo_free_my_vector(&avg_on);
+<a name="l00372"></a>00372     sinfo_free_my_vector(&avg_of);
+<a name="l00373"></a>00373     sinfo_free_my_vector(&avg_di);
+<a name="l00374"></a>00374 
+<a name="l00375"></a>00375     sinfo_free_my_vector(&max_on);
+<a name="l00376"></a>00376     sinfo_free_my_vector(&max_of);
+<a name="l00377"></a>00377     sinfo_free_my_vector(&max_di);
+<a name="l00378"></a>00378 
+<a name="l00379"></a>00379     sinfo_free_my_vector(&vec_nsat);
+<a name="l00380"></a>00380 
+<a name="l00381"></a>00381  }
+<a name="l00382"></a>00382 
+<a name="l00383"></a>00383  <span class="comment">/*</span>
+<a name="l00384"></a>00384 <span class="comment"> sinfo_msg("avg_on=%g std_on=%g ",qc->avg_on,qc_wcal.std_on);</span>
+<a name="l00385"></a>00385 <span class="comment"> sinfo_msg("avg_of=%g std_of=%g ",qc->avg_of,qc_wcal.std_of);</span>
+<a name="l00386"></a>00386 <span class="comment"> sinfo_msg("avg_di=%g std_di=%g ",qc->avg_di,qc_wcal.std_di);</span>
+<a name="l00387"></a>00387 <span class="comment"> sinfo_msg("max_fl=%g nsat_on=%g ",qc->max_di,qc_wcal.nsat);</span>
+<a name="l00388"></a>00388 <span class="comment"> */</span>
+<a name="l00389"></a>00389  cleanup:
+<a name="l00390"></a>00390  
+<a name="l00391"></a>00391  sinfo_free_image(&on_ima);
+<a name="l00392"></a>00392  sinfo_free_image(&of_ima);
+<a name="l00393"></a>00393  sinfo_free_image(&dif_ima);
+<a name="l00394"></a>00394  sinfo_free_image(&tmp_ima);
+<a name="l00395"></a>00395 
+<a name="l00396"></a>00396  sinfo_free_my_vector(&avg_on);
+<a name="l00397"></a>00397  sinfo_free_my_vector(&avg_of);
+<a name="l00398"></a>00398  sinfo_free_my_vector(&avg_di);
+<a name="l00399"></a>00399 
+<a name="l00400"></a>00400  sinfo_free_my_vector(&max_on);
+<a name="l00401"></a>00401  sinfo_free_my_vector(&max_of);
+<a name="l00402"></a>00402  sinfo_free_my_vector(&max_di);
+<a name="l00403"></a>00403 
+<a name="l00404"></a>00404  sinfo_free_my_vector(&vec_nsat);
+<a name="l00405"></a>00405 
+<a name="l00406"></a>00406  sinfo_free_frameset(&on_set);
+<a name="l00407"></a>00407  sinfo_free_frameset(&of_set);
+<a name="l00408"></a>00408 
+<a name="l00409"></a>00409  <span class="keywordflow">return</span> 0;
+<a name="l00410"></a>00410 
+<a name="l00411"></a>00411 }
+<a name="l00412"></a>00412 
+<a name="l00413"></a>00413 
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfo__wcal__functions_8h_source.html b/html/sinfo__wcal__functions_8h_source.html
new file mode 100644
index 0000000..0ee676d
--- /dev/null
+++ b/html/sinfo__wcal__functions_8h_source.html
@@ -0,0 +1,84 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_wcal_functions.h Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_wcal_functions.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_wcal_functions.h,v 1.2 2006/10/22 14:12:28 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the SINFONI Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This proram is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2006/10/22 14:12:28 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.2 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 <span class="preprocessor">#ifndef SINFO_WCAL_FUNCTIONS_H</span>
+<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="preprocessor">#define SINFO_WCAL_FUNCTIONS_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="keyword">struct </span>qc_wcal_ {
+<a name="l00030"></a>00030 
+<a name="l00031"></a>00031   <span class="keywordtype">double</span> avg_on; 
+<a name="l00032"></a>00032   <span class="keywordtype">double</span> std_on;
+<a name="l00033"></a>00033   <span class="keywordtype">double</span> avg_of; 
+<a name="l00034"></a>00034   <span class="keywordtype">double</span> std_of;
+<a name="l00035"></a>00035   <span class="keywordtype">double</span> avg_di; 
+<a name="l00036"></a>00036   <span class="keywordtype">double</span> std_di;
+<a name="l00037"></a>00037   <span class="keywordtype">double</span> max_on;
+<a name="l00038"></a>00038   <span class="keywordtype">double</span> max_of;
+<a name="l00039"></a>00039   <span class="keywordtype">double</span> max_di;
+<a name="l00040"></a>00040   <span class="keywordtype">double</span> nsat_on;
+<a name="l00041"></a>00041   <span class="keywordtype">double</span> noise_on;
+<a name="l00042"></a>00042   <span class="keywordtype">double</span> noise_of;
+<a name="l00043"></a>00043   <span class="keywordtype">double</span> flux_on;
+<a name="l00044"></a>00044   <span class="keywordtype">double</span>    nsat;
+<a name="l00045"></a>00045 
+<a name="l00046"></a>00046 };
+<a name="l00047"></a>00047  
+<a name="l00048"></a>00048 
+<a name="l00049"></a>00049 
+<a name="l00050"></a>00050 <span class="keyword">typedef</span> <span class="keyword">struct </span>qc_wcal_ qc_wcal;
+<a name="l00051"></a>00051 
+<a name="l00052"></a>00052 <span class="comment">/* extern struct qc_wcal qc_wcal_par; */</span>
+<a name="l00053"></a>00053 <span class="preprocessor">#include "sinfo_functions.h"</span>
+<a name="l00054"></a>00054 <span class="preprocessor">#include <cpl.h></span>
+<a name="l00055"></a>00055 <span class="preprocessor">#include <sinfo_globals.h></span>
+<a name="l00056"></a>00056 <span class="preprocessor">#include <sinfo_spiffi_types.h></span>
+<a name="l00057"></a>00057 <span class="preprocessor">#include <sinfo_wavecal_cfg.h></span>
+<a name="l00058"></a>00058 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00059"></a>00059 <span class="comment">/* ---------------------------------------------------------------------- </span>
+<a name="l00060"></a>00060 <span class="comment">   group of frames</span>
+<a name="l00061"></a>00061 <span class="comment">---------------------------------------------------------------------- */</span>
+<a name="l00062"></a>00062 <span class="keywordtype">int</span> sinfo_dumpTblToFitParams ( FitParams ** params, <span class="keywordtype">char</span> * filename );
+<a name="l00063"></a>00063 <span class="keywordtype">int</span> sinfo_det_ncounts(cpl_frameset* raw, <span class="keywordtype">int</span> thresh_max, qc_wcal* qc);
+<a name="l00064"></a>00064 qc_wcal* sinfo_qc_wcal_new(<span class="keywordtype">void</span>);
+<a name="l00065"></a>00065 <span class="keywordtype">void</span> sinfo_qc_wcal_delete(qc_wcal** qc);
+<a name="l00066"></a>00066 CPL_END_DECLS
+<a name="l00067"></a>00067 
+<a name="l00068"></a>00068 <span class="preprocessor">#endif</span>
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfoni_2sinfo__utl__cube2ima_8c_source.html b/html/sinfoni_2sinfo__utl__cube2ima_8c_source.html
new file mode 100644
index 0000000..e453a8e
--- /dev/null
+++ b/html/sinfoni_2sinfo__utl__cube2ima_8c_source.html
@@ -0,0 +1,246 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_utl_cube2ima.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_utl_cube2ima.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_utl_cube2ima.c,v 1.8 2012/03/03 10:17:31 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the IIINSTRUMENT Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2012/03/03 10:17:31 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.8 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span>
+<a name="l00032"></a>00032 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                                Includes</span>
+<a name="l00034"></a>00034 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 
+<a name="l00036"></a>00036 <span class="preprocessor">#include "sinfo_functions.h"</span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include "sinfo_new_cube_ops.h"</span>
+<a name="l00038"></a>00038 <span class="preprocessor">#include "sinfo_utl_cube2ima.h"</span>
+<a name="l00039"></a>00039 <span class="preprocessor">#include "sinfo_key_names.h"</span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include <sinfo_error.h></span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include <sinfo_utils_wrappers.h></span>
+<a name="l00042"></a>00042 
+<a name="l00043"></a>00043 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00044"></a>00044 <span class="comment">                            Functions prototypes</span>
+<a name="l00045"></a>00045 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00046"></a>00046 
+<a name="l00047"></a>00047 
+<a name="l00048"></a>00048 
+<a name="l00049"></a>00049 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00050"></a>00050 <span class="comment">                            Static variables</span>
+<a name="l00051"></a>00051 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00052"></a>00052 
+<a name="l00053"></a>00053 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00054"></a>00054 <span class="comment">                                Functions code</span>
+<a name="l00055"></a>00055 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00056"></a>00056 
+<a name="l00064"></a>00064 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00071"></a>00071 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00072"></a>00072 <span class="keywordtype">int</span> sinfo_utl_cube2ima(
+<a name="l00073"></a>00073         cpl_parameterlist   *   parlist, 
+<a name="l00074"></a>00074         cpl_frameset        *   framelist)
+<a name="l00075"></a>00075 {
+<a name="l00076"></a>00076     cpl_parameter       *   param =NULL ;
+<a name="l00077"></a>00077     <span class="keyword">const</span> <span class="keywordtype">char</span>          *   name_i =NULL;
+<a name="l00078"></a>00078     <span class="keyword">const</span> <span class="keywordtype">char</span>          *   name_o =NULL;
+<a name="l00079"></a>00079 
+<a name="l00080"></a>00080     <span class="keywordtype">double</span>                  ws=0 ;
+<a name="l00081"></a>00081     <span class="keywordtype">double</span>                  we=0 ;
+<a name="l00082"></a>00082     <span class="keywordtype">double</span>                  wc=0 ;
+<a name="l00083"></a>00083     <span class="keywordtype">double</span>                  wd=0 ;
+<a name="l00084"></a>00084 
+<a name="l00085"></a>00085 
+<a name="l00086"></a>00086     <span class="keywordtype">int</span> naxis3=0;
+<a name="l00087"></a>00087     <span class="keywordtype">double</span> lams=0;
+<a name="l00088"></a>00088     <span class="keywordtype">double</span> lame=0;
+<a name="l00089"></a>00089 
+<a name="l00090"></a>00090     cpl_frame           *   frm_cub=NULL ;
+<a name="l00091"></a>00091  
+<a name="l00092"></a>00092     cpl_propertylist    *   plist=NULL ;
+<a name="l00093"></a>00093     cpl_frame           *   product_frame=NULL;
+<a name="l00094"></a>00094 
+<a name="l00095"></a>00095     cpl_imagelist * cube=NULL;
+<a name="l00096"></a>00096     cpl_image * img=NULL;
+<a name="l00097"></a>00097 
+<a name="l00098"></a>00098    
+<a name="l00099"></a>00099     <span class="comment">/* HOW TO RETRIEVE INPUT PARAMETERS */</span>
+<a name="l00100"></a>00100     <span class="comment">/* --stropt */</span>
+<a name="l00101"></a>00101     name_o =<span class="stringliteral">"out_ima.fits"</span>;
+<a name="l00102"></a>00102  
+<a name="l00103"></a>00103     <span class="comment">/* --doubleopt */</span>
+<a name="l00104"></a>00104     check_nomsg(param = cpl_parameterlist_find(parlist,
+<a name="l00105"></a>00105                                             <span class="stringliteral">"sinfoni.sinfo_utl_cube2ima.ws"</span>));
+<a name="l00106"></a>00106     check_nomsg(ws = cpl_parameter_get_double(param)) ;
+<a name="l00107"></a>00107 
+<a name="l00108"></a>00108     <span class="comment">/* --doubleopt */</span>
+<a name="l00109"></a>00109     check_nomsg(param = cpl_parameterlist_find(parlist,
+<a name="l00110"></a>00110                                             <span class="stringliteral">"sinfoni.sinfo_utl_cube2ima.we"</span>));
+<a name="l00111"></a>00111     check_nomsg(we = cpl_parameter_get_double(param)) ;
+<a name="l00112"></a>00112 
+<a name="l00113"></a>00113     <span class="comment">/* Identify the RAW and CALIB frames in the input frameset */</span>
+<a name="l00114"></a>00114     check(sinfo_dfs_set_groups(framelist),
+<a name="l00115"></a>00115         <span class="stringliteral">"Cannot identify RAW and CALIB frames"</span>);
+<a name="l00116"></a>00116  
+<a name="l00117"></a>00117     <span class="comment">/* HOW TO ACCESS INPUT DATA */</span>
+<a name="l00118"></a>00118     check(frm_cub = cpl_frameset_find(framelist, SI_UTL_CUBE2IMA_CUBE),
+<a name="l00119"></a>00119         <span class="stringliteral">"SOF does not have a file tagged as %s"</span>,SI_UTL_CUBE2IMA_CUBE);
+<a name="l00120"></a>00120 
+<a name="l00121"></a>00121     check_nomsg(name_i = cpl_frame_get_filename(frm_cub));
+<a name="l00122"></a>00122 
+<a name="l00123"></a>00123     plist=cpl_propertylist_load(name_i,0);
+<a name="l00124"></a>00124     naxis3=sinfo_pfits_get_naxis3(plist);
+<a name="l00125"></a>00125     wd=sinfo_pfits_get_cdelt3(plist);
+<a name="l00126"></a>00126     wc=sinfo_pfits_get_crval3(plist);
+<a name="l00127"></a>00127     sinfo_free_propertylist(&plist);
+<a name="l00128"></a>00128 
+<a name="l00129"></a>00129     lams=wc-naxis3*wd/2+wd;
+<a name="l00130"></a>00130     lame=lams+(naxis3-2)*wd;
+<a name="l00131"></a>00131 
+<a name="l00132"></a>00132     check_nomsg(param = cpl_parameterlist_find(parlist,
+<a name="l00133"></a>00133                                             <span class="stringliteral">"sinfoni.sinfo_utl_cube2ima.ws"</span>));
+<a name="l00134"></a>00134 
+<a name="l00135"></a>00135     <span class="keywordflow">if</span>(ws != cpl_parameter_get_default_double(param)) {
+<a name="l00136"></a>00136       <span class="keywordflow">if</span> (ws < lams) {
+<a name="l00137"></a>00137         <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"ws =%f too low set it to %f"</span>,ws,lams);
+<a name="l00138"></a>00138         ws=lams;
+<a name="l00139"></a>00139       }
+<a name="l00140"></a>00140       <span class="keywordflow">else</span> <span class="keywordflow">if</span> (ws >= lame) {
+<a name="l00141"></a>00141         <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"ws =%f too high set it to %f"</span>,ws,lams);
+<a name="l00142"></a>00142         ws=lams;
+<a name="l00143"></a>00143       }
+<a name="l00144"></a>00144     } <span class="keywordflow">else</span> {
+<a name="l00145"></a>00145       ws=lams;
+<a name="l00146"></a>00146     }
+<a name="l00147"></a>00147 
+<a name="l00148"></a>00148     check_nomsg(param = cpl_parameterlist_find(parlist,
+<a name="l00149"></a>00149                                              <span class="stringliteral">"sinfoni.sinfo_utl_cube2ima.we"</span>));
+<a name="l00150"></a>00150     <span class="keywordflow">if</span>(we != cpl_parameter_get_default_double(param)) {
+<a name="l00151"></a>00151       <span class="keywordflow">if</span> (we > lame) {
+<a name="l00152"></a>00152         <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"we =%f too low set it to %f"</span>,we,lame);
+<a name="l00153"></a>00153         we=lame;
+<a name="l00154"></a>00154       }
+<a name="l00155"></a>00155       <span class="keywordflow">else</span> <span class="keywordflow">if</span> (we <= lams) {
+<a name="l00156"></a>00156         <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"we =%f too low set it to %f"</span>,we,lame);
+<a name="l00157"></a>00157         we=lame;
+<a name="l00158"></a>00158       }
+<a name="l00159"></a>00159     } <span class="keywordflow">else</span> {
+<a name="l00160"></a>00160       we=lame;
+<a name="l00161"></a>00161     }
+<a name="l00162"></a>00162 
+<a name="l00163"></a>00163     check(plist=cpl_propertylist_load(cpl_frame_get_filename(frm_cub),0),
+<a name="l00164"></a>00164           <span class="stringliteral">"Cannot read the FITS header"</span>) ;
+<a name="l00165"></a>00165 
+<a name="l00166"></a>00166     <span class="comment">/* recipe's algorithm */</span>
+<a name="l00167"></a>00167     check_nomsg(cube = cpl_imagelist_load((<span class="keywordtype">char</span>*)name_i,CPL_TYPE_FLOAT,0));
+<a name="l00168"></a>00168     <span class="keywordflow">if</span>(NULL==(img=sinfo_new_average_cube_to_image_between_waves(cube,wd,wc,
+<a name="l00169"></a>00169                                                                 ws,we))) {
+<a name="l00170"></a>00170      <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Cannot average cube to image in wavelength "</span>
+<a name="l00171"></a>00171                      <span class="stringliteral">"range [%f,%f] um"</span>,ws,we) ;
+<a name="l00172"></a>00172 
+<a name="l00173"></a>00173        sinfo_free_imagelist(&cube);
+<a name="l00174"></a>00174        sinfo_free_propertylist(&plist);    
+<a name="l00175"></a>00175 
+<a name="l00176"></a>00176     }
+<a name="l00177"></a>00177     sinfo_free_imagelist(&cube);
+<a name="l00178"></a>00178 
+<a name="l00179"></a>00179     <span class="comment">/* HOW TO SAVE A PRODUCT ON DISK  */</span>
+<a name="l00180"></a>00180     <span class="comment">/* Create product frame */</span>
+<a name="l00181"></a>00181     check_nomsg(product_frame = cpl_frame_new());
+<a name="l00182"></a>00182     check_nomsg(cpl_frame_set_filename(product_frame, name_o)) ;
+<a name="l00183"></a>00183     check_nomsg(cpl_frame_set_tag(product_frame, SI_UTL_CUBE2IMA_PROIMA)) ;
+<a name="l00184"></a>00184     check_nomsg(cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_IMAGE)) ;
+<a name="l00185"></a>00185     check_nomsg(cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT)) ;
+<a name="l00186"></a>00186     check(cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL), 
+<a name="l00187"></a>00187      <span class="stringliteral">"Error while initialising the product frame"</span>) ;
+<a name="l00188"></a>00188 
+<a name="l00189"></a>00189 
+<a name="l00190"></a>00190     <span class="comment">/* Add DataFlow keywords */</span>
+<a name="l00191"></a>00191     check_nomsg(cpl_propertylist_erase_regexp(plist, <span class="stringliteral">"^ESO PRO CATG"</span>,0));
+<a name="l00192"></a>00192 <span class="preprocessor">#if defined CPL_VERSION_CODE && CPL_VERSION_CODE >= CPL_VERSION(4, 8, 0) </span>
+<a name="l00193"></a>00193 <span class="preprocessor"></span>    check(cpl_dfs_setup_product_header(plist, 
+<a name="l00194"></a>00194                                        product_frame, 
+<a name="l00195"></a>00195                                        framelist, 
+<a name="l00196"></a>00196                                        parlist,
+<a name="l00197"></a>00197                                        <span class="stringliteral">"si_sinfo_utl_cube2ima"</span>, 
+<a name="l00198"></a>00198                                        <span class="stringliteral">"SINFONI"</span>, 
+<a name="l00199"></a>00199                                        KEY_VALUE_HPRO_DID,NULL),
+<a name="l00200"></a>00200       <span class="stringliteral">"Problem in the product DFS-compliance"</span>) ;
+<a name="l00201"></a>00201 <span class="preprocessor">#else</span>
+<a name="l00202"></a>00202 <span class="preprocessor"></span>    check(cpl_dfs_setup_product_header(plist, 
+<a name="l00203"></a>00203                                        product_frame, 
+<a name="l00204"></a>00204                                        framelist, 
+<a name="l00205"></a>00205                                        parlist,
+<a name="l00206"></a>00206                                        <span class="stringliteral">"si_sinfo_utl_cube2ima"</span>, 
+<a name="l00207"></a>00207                                        <span class="stringliteral">"SINFONI"</span>, 
+<a name="l00208"></a>00208                                        KEY_VALUE_HPRO_DID),
+<a name="l00209"></a>00209       <span class="stringliteral">"Problem in the product DFS-compliance"</span>) ;
+<a name="l00210"></a>00210 <span class="preprocessor">#endif</span>
+<a name="l00211"></a>00211 <span class="preprocessor"></span>   
+<a name="l00212"></a>00212     <span class="comment">/* Save the file */</span>
+<a name="l00213"></a>00213     check_nomsg(cpl_propertylist_erase_regexp(plist, <span class="stringliteral">"^CTYPE3"</span>,0));
+<a name="l00214"></a>00214     check_nomsg(cpl_propertylist_erase_regexp(plist, <span class="stringliteral">"^CRPIX3"</span>,0));
+<a name="l00215"></a>00215     check_nomsg(cpl_propertylist_erase_regexp(plist, <span class="stringliteral">"^CRVAL3"</span>,0));
+<a name="l00216"></a>00216     check_nomsg(cpl_propertylist_erase_regexp(plist, <span class="stringliteral">"^CDELT3"</span>,0));
+<a name="l00217"></a>00217     check_nomsg(cpl_propertylist_erase_regexp(plist, <span class="stringliteral">"^CUNIT3"</span>,0));
+<a name="l00218"></a>00218 
+<a name="l00219"></a>00219     check(cpl_image_save(img, 
+<a name="l00220"></a>00220                          name_o, 
+<a name="l00221"></a>00221                          CPL_BPP_IEEE_FLOAT, 
+<a name="l00222"></a>00222                          plist,
+<a name="l00223"></a>00223                          CPL_IO_DEFAULT),
+<a name="l00224"></a>00224       <span class="stringliteral">"Could not save product"</span>);
+<a name="l00225"></a>00225 
+<a name="l00226"></a>00226     check_nomsg(sinfo_free_propertylist(&plist)) ;
+<a name="l00227"></a>00227   
+<a name="l00228"></a>00228     <span class="comment">/* Log the saved file in the input frameset */</span>
+<a name="l00229"></a>00229     check_nomsg(cpl_frameset_insert(framelist, product_frame)) ;
+<a name="l00230"></a>00230     check_nomsg(sinfo_free_image(&img)) ;
+<a name="l00231"></a>00231  
+<a name="l00232"></a>00232     <span class="comment">/* Return */</span>
+<a name="l00233"></a>00233 
+<a name="l00234"></a>00234  cleanup:
+<a name="l00235"></a>00235        sinfo_free_imagelist(&cube);
+<a name="l00236"></a>00236        sinfo_free_propertylist(&plist);    
+<a name="l00237"></a>00237        sinfo_free_image(&img);
+<a name="l00238"></a>00238 
+<a name="l00239"></a>00239     <span class="keywordflow">if</span> (cpl_error_get_code()) 
+<a name="l00240"></a>00240         <span class="keywordflow">return</span> -1 ;
+<a name="l00241"></a>00241     <span class="keywordflow">else</span> 
+<a name="l00242"></a>00242         <span class="keywordflow">return</span> 0 ;
+<a name="l00243"></a>00243 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfoni_2sinfo__utl__cube2spectrum_8c_source.html b/html/sinfoni_2sinfo__utl__cube2spectrum_8c_source.html
new file mode 100644
index 0000000..aeaa2b1
--- /dev/null
+++ b/html/sinfoni_2sinfo__utl__cube2spectrum_8c_source.html
@@ -0,0 +1,489 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_utl_cube2spectrum.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_utl_cube2spectrum.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_utl_cube2spectrum.c,v 1.11 2012/03/03 10:17:31 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the IIINSTRUMENT Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2012/03/03 10:17:31 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.11 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span>
+<a name="l00032"></a>00032 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                                Includes</span>
+<a name="l00034"></a>00034 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 
+<a name="l00036"></a>00036 
+<a name="l00037"></a>00037 <span class="preprocessor">#include "sinfo_utl_cube2spectrum.h"</span>
+<a name="l00038"></a>00038 <span class="preprocessor">#include "sinfo_functions.h"</span>
+<a name="l00039"></a>00039 <span class="preprocessor">#include "sinfo_spectrum_ops.h"</span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include "sinfo_key_names.h"</span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include "sinfo_pro_save.h"</span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include "sinfo_utilities_scired.h"</span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include "sinfo_globals.h"</span>
+<a name="l00044"></a>00044 <span class="preprocessor">#include "sinfo_error.h"</span>
+<a name="l00045"></a>00045 <span class="preprocessor">#include "sinfo_utils_wrappers.h"</span>
+<a name="l00046"></a>00046 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00047"></a>00047 <span class="comment">                            Functions prototypes</span>
+<a name="l00048"></a>00048 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00049"></a>00049 
+<a name="l00050"></a>00050 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00051"></a>00051 <span class="comment">                            Static variables</span>
+<a name="l00052"></a>00052 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00053"></a>00053 
+<a name="l00054"></a>00054 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00055"></a>00055 sinfo_change_header(<span class="keyword">const</span> <span class="keywordtype">char</span> * name);
+<a name="l00063"></a>00063 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00064"></a>00064 <span class="comment">                            Function implementation</span>
+<a name="l00065"></a>00065 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00066"></a>00066 
+<a name="l00067"></a>00067 <span class="keyword">static</span> <span class="keywordtype">int</span>
+<a name="l00068"></a>00068 sinfo_change_header(<span class="keyword">const</span> <span class="keywordtype">char</span> * name) {
+<a name="l00069"></a>00069   <span class="keywordtype">int</span> cenpix=0;
+<a name="l00070"></a>00070   <span class="keywordtype">double</span> cenLambda=0;
+<a name="l00071"></a>00071   <span class="keywordtype">double</span> dispersion=0;
+<a name="l00072"></a>00072   cpl_propertylist* plist=NULL;
+<a name="l00073"></a>00073 
+<a name="l00074"></a>00074   plist=cpl_propertylist_load(name,0);
+<a name="l00075"></a>00075   cenpix = sinfo_pfits_get_crpix3(plist);
+<a name="l00076"></a>00076   cenLambda = sinfo_pfits_get_crval3(plist);
+<a name="l00077"></a>00077   dispersion = sinfo_pfits_get_cdelt3(plist);
+<a name="l00078"></a>00078 
+<a name="l00079"></a>00079   
+<a name="l00080"></a>00080   check(cpl_propertylist_set_string(plist,<span class="stringliteral">"CTYPE2"</span>,<span class="stringliteral">"WAVE"</span>),<span class="stringliteral">"Setting CTYPE2"</span>);
+<a name="l00081"></a>00081   check_nomsg(cpl_propertylist_set_comment(plist,<span class="stringliteral">"CTYPE2"</span>,
+<a name="l00082"></a>00082                        <span class="stringliteral">"wavelength axis in microns"</span>));
+<a name="l00083"></a>00083 
+<a name="l00084"></a>00084   check(cpl_propertylist_set_double(plist,<span class="stringliteral">"CRPIX2"</span>,(<span class="keywordtype">double</span>)cenpix),
+<a name="l00085"></a>00085     <span class="stringliteral">"Setting CRPIX2"</span>);
+<a name="l00086"></a>00086   check_nomsg(cpl_propertylist_set_comment(plist,<span class="stringliteral">"CRPIX2"</span>,<span class="stringliteral">"Reference pixel"</span>));
+<a name="l00087"></a>00087  
+<a name="l00088"></a>00088   check(cpl_propertylist_set_double(plist,<span class="stringliteral">"CRVAL2"</span>,cenLambda),
+<a name="l00089"></a>00089     <span class="stringliteral">"Setting CRVAL2"</span>);
+<a name="l00090"></a>00090   check_nomsg(cpl_propertylist_set_comment(plist,<span class="stringliteral">"CRVAL2"</span>,
+<a name="l00091"></a>00091                        <span class="stringliteral">"central wavelength"</span>));
+<a name="l00092"></a>00092 
+<a name="l00093"></a>00093   check(cpl_propertylist_set_double(plist,<span class="stringliteral">"CDELT2"</span>,dispersion),
+<a name="l00094"></a>00094     <span class="stringliteral">"Setting CDELT2"</span>);
+<a name="l00095"></a>00095   check_nomsg(cpl_propertylist_set_comment(plist,<span class="stringliteral">"CDELT2"</span>,
+<a name="l00096"></a>00096                        <span class="stringliteral">"microns per pixel"</span>));
+<a name="l00097"></a>00097 
+<a name="l00098"></a>00098   check(cpl_propertylist_set_string(plist,<span class="stringliteral">"CUNIT2"</span>,<span class="stringliteral">"um"</span>),<span class="stringliteral">"Setting CUNIT2"</span>); 
+<a name="l00099"></a>00099   check_nomsg(cpl_propertylist_set_comment(plist,<span class="stringliteral">"CUNIT2"</span>,<span class="stringliteral">"spectral unit"</span>)); 
+<a name="l00100"></a>00100 
+<a name="l00101"></a>00101   check(cpl_propertylist_set_string(plist,<span class="stringliteral">"CTYPE1"</span>,<span class="stringliteral">"ONESPEC"</span>),
+<a name="l00102"></a>00102     <span class="stringliteral">"Setting CTYPE1"</span>);
+<a name="l00103"></a>00103   check_nomsg(cpl_propertylist_set_comment(plist,<span class="stringliteral">"CTYPE1"</span>,
+<a name="l00104"></a>00104                        <span class="stringliteral">"one spectrum in y-direction"</span>));
+<a name="l00105"></a>00105 
+<a name="l00106"></a>00106   <span class="keywordflow">if</span>(cpl_propertylist_has(plist,<span class="stringliteral">"CRPIX1"</span>)==1) {
+<a name="l00107"></a>00107     check(cpl_propertylist_erase_regexp(plist, <span class="stringliteral">"CRPIX1"</span>,0),<span class="stringliteral">"Erasing CRPIX1"</span>);
+<a name="l00108"></a>00108   }
+<a name="l00109"></a>00109 
+<a name="l00110"></a>00110   <span class="keywordflow">if</span>(cpl_propertylist_has(plist,<span class="stringliteral">"CRVAL1"</span>)==1) {
+<a name="l00111"></a>00111     check(cpl_propertylist_erase_regexp(plist, <span class="stringliteral">"CRVAL1"</span>,0),<span class="stringliteral">"Erasing CRVAL1"</span>);
+<a name="l00112"></a>00112   }
+<a name="l00113"></a>00113 
+<a name="l00114"></a>00114   <span class="keywordflow">if</span>(cpl_propertylist_has(plist,<span class="stringliteral">"CDELT1"</span>)==1) {
+<a name="l00115"></a>00115     check(cpl_propertylist_erase_regexp(plist, <span class="stringliteral">"CDELT1"</span>,0),<span class="stringliteral">"Erasing CDELT1"</span>);
+<a name="l00116"></a>00116   }
+<a name="l00117"></a>00117 
+<a name="l00118"></a>00118 
+<a name="l00119"></a>00119   <span class="keywordflow">if</span>(cpl_propertylist_has(plist,<span class="stringliteral">"CUNIT1"</span>)==1) {
+<a name="l00120"></a>00120     check(cpl_propertylist_erase_regexp(plist, <span class="stringliteral">"CUNIT1"</span>,0),<span class="stringliteral">"Erasing CUNIT1"</span>);
+<a name="l00121"></a>00121   }
+<a name="l00122"></a>00122 
+<a name="l00123"></a>00123 
+<a name="l00124"></a>00124   <span class="keywordflow">if</span>(cpl_propertylist_has(plist,<span class="stringliteral">"CTYPE3"</span>)==1) {
+<a name="l00125"></a>00125     check(cpl_propertylist_erase_regexp(plist, <span class="stringliteral">"CTYPE3"</span>,0),<span class="stringliteral">"Erasing CTYPE3"</span>);
+<a name="l00126"></a>00126   }
+<a name="l00127"></a>00127 
+<a name="l00128"></a>00128 
+<a name="l00129"></a>00129   <span class="keywordflow">if</span>(cpl_propertylist_has(plist,<span class="stringliteral">"CRPIX3"</span>)==1) {
+<a name="l00130"></a>00130     check(cpl_propertylist_erase_regexp(plist, <span class="stringliteral">"CRPIX3"</span>,0),<span class="stringliteral">"Erasing CRPIX3"</span>);
+<a name="l00131"></a>00131   }
+<a name="l00132"></a>00132 
+<a name="l00133"></a>00133   <span class="keywordflow">if</span>(cpl_propertylist_has(plist,<span class="stringliteral">"CRVAL3"</span>)==1) {
+<a name="l00134"></a>00134     check(cpl_propertylist_erase_regexp(plist, <span class="stringliteral">"CRVAL3"</span>,0),<span class="stringliteral">"Erasing CRVAL3"</span>);
+<a name="l00135"></a>00135   }
+<a name="l00136"></a>00136 
+<a name="l00137"></a>00137   <span class="keywordflow">if</span>(cpl_propertylist_has(plist,<span class="stringliteral">"CDELT3"</span>)==1) {
+<a name="l00138"></a>00138     check(cpl_propertylist_erase_regexp(plist, <span class="stringliteral">"CDELT3"</span>,0),<span class="stringliteral">"Erasing CDELT3"</span>);
+<a name="l00139"></a>00139   }
+<a name="l00140"></a>00140 
+<a name="l00141"></a>00141   <span class="keywordflow">if</span>(cpl_propertylist_has(plist,<span class="stringliteral">"CUNIT3"</span>)==1) {
+<a name="l00142"></a>00142     check(cpl_propertylist_erase_regexp(plist, <span class="stringliteral">"CUNIT3"</span>,0),<span class="stringliteral">"Erasing CUNIT3"</span>);
+<a name="l00143"></a>00143   }
+<a name="l00144"></a>00144 
+<a name="l00145"></a>00145 
+<a name="l00146"></a>00146   <span class="keywordflow">if</span>(cpl_propertylist_has(plist,<span class="stringliteral">"CD1_1"</span>)==1) {
+<a name="l00147"></a>00147     check(cpl_propertylist_erase_regexp(plist, <span class="stringliteral">"CD1_1"</span>,0),<span class="stringliteral">"Erasing CD1_1"</span>);
+<a name="l00148"></a>00148   }
+<a name="l00149"></a>00149 
+<a name="l00150"></a>00150 
+<a name="l00151"></a>00151   <span class="keywordflow">if</span>(cpl_propertylist_has(plist,<span class="stringliteral">"CD1_2"</span>)==1) {
+<a name="l00152"></a>00152     check(cpl_propertylist_erase_regexp(plist, <span class="stringliteral">"CD1_2"</span>,0),<span class="stringliteral">"Erasing CD1_2"</span>);
+<a name="l00153"></a>00153   }
+<a name="l00154"></a>00154 
+<a name="l00155"></a>00155   <span class="keywordflow">if</span>(cpl_propertylist_has(plist,<span class="stringliteral">"CD2_1"</span>)==1) {
+<a name="l00156"></a>00156     check(cpl_propertylist_erase_regexp(plist, <span class="stringliteral">"CD2_1"</span>,0),<span class="stringliteral">"Erasing CD2_1"</span>);
+<a name="l00157"></a>00157   }
+<a name="l00158"></a>00158 
+<a name="l00159"></a>00159   <span class="keywordflow">if</span>(cpl_propertylist_has(plist,<span class="stringliteral">"CD2_2"</span>)==1) {
+<a name="l00160"></a>00160     check(cpl_propertylist_erase_regexp(plist, <span class="stringliteral">"CD2_2"</span>,0),<span class="stringliteral">"Erasing CD2_2"</span>);
+<a name="l00161"></a>00161   }
+<a name="l00162"></a>00162 
+<a name="l00163"></a>00163  cleanup:
+<a name="l00164"></a>00164   sinfo_free_propertylist(&plist);
+<a name="l00165"></a>00165 
+<a name="l00166"></a>00166    <span class="comment">/* Return */</span>
+<a name="l00167"></a>00167     <span class="keywordflow">if</span> (cpl_error_get_code()) 
+<a name="l00168"></a>00168         <span class="keywordflow">return</span> -1 ;
+<a name="l00169"></a>00169     <span class="keywordflow">else</span> 
+<a name="l00170"></a>00170         <span class="keywordflow">return</span> 0 ;
+<a name="l00171"></a>00171 
+<a name="l00172"></a>00172 }
+<a name="l00173"></a>00173 
+<a name="l00174"></a>00174 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00182"></a>00182 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00183"></a>00183 <span class="keywordtype">int</span> sinfo_utl_cube2spectrum(
+<a name="l00184"></a>00184         cpl_parameterlist   *   parlist, 
+<a name="l00185"></a>00185         cpl_frameset        *   framelist,
+<a name="l00186"></a>00186          <span class="keyword">const</span> <span class="keywordtype">char</span>* tag)
+<a name="l00187"></a>00187 {
+<a name="l00188"></a>00188     cpl_parameter       *   param =NULL;
+<a name="l00189"></a>00189     <span class="keyword">const</span> <span class="keywordtype">char</span>          *   operation =NULL;
+<a name="l00190"></a>00190     <span class="keyword">const</span> <span class="keywordtype">char</span>          *   aperture =NULL;
+<a name="l00191"></a>00191     <span class="keywordtype">char</span>  name_i [MAX_NAME_SIZE];
+<a name="l00192"></a>00192     <span class="keywordtype">int</span>                    llx=0;
+<a name="l00193"></a>00193     <span class="keywordtype">int</span>                    urx=0;
+<a name="l00194"></a>00194     <span class="keywordtype">int</span>                    lly=0;
+<a name="l00195"></a>00195     <span class="keywordtype">int</span>                    ury=0;
+<a name="l00196"></a>00196     <span class="keywordtype">int</span>                    lo_rej=0;
+<a name="l00197"></a>00197     <span class="keywordtype">int</span>                    hi_rej=0;
+<a name="l00198"></a>00198     <span class="keywordtype">int</span>                    centerx=0;
+<a name="l00199"></a>00199     <span class="keywordtype">int</span>                    centery=0;
+<a name="l00200"></a>00200     <span class="keywordtype">int</span>                    radius=0;
+<a name="l00201"></a>00201     <span class="keywordtype">int</span>                    clx=0;
+<a name="l00202"></a>00202     <span class="keywordtype">int</span>                    cly=0;
+<a name="l00203"></a>00203     
+<a name="l00204"></a>00204     <span class="keywordtype">double</span>                 disp=0;
+<a name="l00205"></a>00205     <span class="keywordtype">double</span>                 cpix=0;
+<a name="l00206"></a>00206     <span class="keywordtype">double</span>                 clam=0;
+<a name="l00207"></a>00207 
+<a name="l00208"></a>00208     cpl_frame           *   frm_cub=NULL;
+<a name="l00209"></a>00209 
+<a name="l00210"></a>00210     <span class="keywordtype">char</span> ima_o[MAX_NAME_SIZE];
+<a name="l00211"></a>00211     <span class="keywordtype">char</span> tbl_o[MAX_NAME_SIZE];
+<a name="l00212"></a>00212     <span class="keywordtype">char</span> tag_i[MAX_NAME_SIZE];
+<a name="l00213"></a>00213     <span class="keywordtype">char</span> tag_o[MAX_NAME_SIZE];
+<a name="l00214"></a>00214     cpl_propertylist    *   plist =NULL;
+<a name="l00215"></a>00215     cpl_image           *   image =NULL;
+<a name="l00216"></a>00216     cpl_frame           *   product_frame=NULL;
+<a name="l00217"></a>00217 
+<a name="l00218"></a>00218     cpl_image * im_spec=NULL;
+<a name="l00219"></a>00219     cpl_table * tbl_spec=NULL;
+<a name="l00220"></a>00220     cpl_image * img=NULL;
+<a name="l00221"></a>00221     cpl_imagelist  * cube=NULL;
+<a name="l00222"></a>00222     Vector * spec=NULL;
+<a name="l00223"></a>00223     <span class="comment">/*fits_header* head=NULL; */</span>
+<a name="l00224"></a>00224 
+<a name="l00225"></a>00225      <span class="comment">/* HOW TO RETRIEVE INPUT PARAMETERS */</span>
+<a name="l00226"></a>00226     <span class="comment">/* --stropt */</span>
+<a name="l00227"></a>00227     check_nomsg(param=cpl_parameterlist_find(parlist, 
+<a name="l00228"></a>00228                                          <span class="stringliteral">"sinfoni.sinfo_utl_cube2spectrum.op"</span>));
+<a name="l00229"></a>00229     check_nomsg(operation=cpl_parameter_get_string(param));
+<a name="l00230"></a>00230  
+<a name="l00231"></a>00231     <span class="comment">/* --stropt */</span>
+<a name="l00232"></a>00232     check_nomsg(param=cpl_parameterlist_find(parlist, 
+<a name="l00233"></a>00233                                          <span class="stringliteral">"sinfoni.sinfo_utl_cube2spectrum.ap"</span>));
+<a name="l00234"></a>00234     check_nomsg(aperture=cpl_parameter_get_string(param));
+<a name="l00235"></a>00235      <span class="comment">/* --stropt */</span>
+<a name="l00236"></a>00236 
+<a name="l00237"></a>00237  
+<a name="l00238"></a>00238     <span class="keywordflow">if</span> (tag == NULL) {
+<a name="l00239"></a>00239       strcpy(ima_o,<span class="stringliteral">"out_spec_ima.fits"</span>);
+<a name="l00240"></a>00240       strcpy(tbl_o,<span class="stringliteral">"out_spec_tbl.fits"</span>);
+<a name="l00241"></a>00241       strcpy(tag_i,SI_UTL_CUBE2SPECTRUM_CUBE);
+<a name="l00242"></a>00242       strcpy(tag_o,SI_UTL_CUBE2SPECTRUM_PROIMA);
+<a name="l00243"></a>00243     } <span class="keywordflow">else</span> {
+<a name="l00244"></a>00244       snprintf(ima_o,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%s"</span>,tag,<span class="stringliteral">"_spec_ima.fits"</span>);
+<a name="l00245"></a>00245       snprintf(tbl_o,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%s"</span>,tag,<span class="stringliteral">"_spec_tbl.fits"</span>);
+<a name="l00246"></a>00246       snprintf(tag_o,MAX_NAME_SIZE-1,<span class="stringliteral">"%s%s"</span>,tag,<span class="stringliteral">"_SPCT"</span>);
+<a name="l00247"></a>00247       strcpy(tag_i,  tag);
+<a name="l00248"></a>00248     }
+<a name="l00249"></a>00249  
+<a name="l00250"></a>00250 
+<a name="l00251"></a>00251     <span class="comment">/* --intopt */</span>
+<a name="l00252"></a>00252     check_nomsg(param=cpl_parameterlist_find(parlist,
+<a name="l00253"></a>00253                                     <span class="stringliteral">"sinfoni.sinfo_utl_cube2spectrum.llx"</span>));
+<a name="l00254"></a>00254     check_nomsg(llx=cpl_parameter_get_int(param));
+<a name="l00255"></a>00255 
+<a name="l00256"></a>00256     <span class="comment">/* --intopt */</span>
+<a name="l00257"></a>00257     check_nomsg(param=cpl_parameterlist_find(parlist,
+<a name="l00258"></a>00258                                     <span class="stringliteral">"sinfoni.sinfo_utl_cube2spectrum.lly"</span>));
+<a name="l00259"></a>00259     check_nomsg(lly=cpl_parameter_get_int(param));
+<a name="l00260"></a>00260 
+<a name="l00261"></a>00261     <span class="comment">/* --intopt */</span>
+<a name="l00262"></a>00262     check_nomsg(param=cpl_parameterlist_find(parlist,
+<a name="l00263"></a>00263                                     <span class="stringliteral">"sinfoni.sinfo_utl_cube2spectrum.urx"</span>));
+<a name="l00264"></a>00264     check_nomsg(urx=cpl_parameter_get_int(param));
+<a name="l00265"></a>00265 
+<a name="l00266"></a>00266     <span class="comment">/* --intopt */</span>
+<a name="l00267"></a>00267     check_nomsg(param=cpl_parameterlist_find(parlist,
+<a name="l00268"></a>00268                                     <span class="stringliteral">"sinfoni.sinfo_utl_cube2spectrum.ury"</span>));
+<a name="l00269"></a>00269     check_nomsg(ury=cpl_parameter_get_int(param));
+<a name="l00270"></a>00270 
+<a name="l00271"></a>00271     <span class="comment">/* --intopt */</span>
+<a name="l00272"></a>00272     check_nomsg(param=cpl_parameterlist_find(parlist,
+<a name="l00273"></a>00273                                   <span class="stringliteral">"sinfoni.sinfo_utl_cube2spectrum.lo_rej"</span>));
+<a name="l00274"></a>00274     check_nomsg(lo_rej=cpl_parameter_get_int(param));
+<a name="l00275"></a>00275 
+<a name="l00276"></a>00276     <span class="comment">/* --intopt */</span>
+<a name="l00277"></a>00277     check_nomsg(param=cpl_parameterlist_find(parlist,
+<a name="l00278"></a>00278                                   <span class="stringliteral">"sinfoni.sinfo_utl_cube2spectrum.hi_rej"</span>));
+<a name="l00279"></a>00279     check_nomsg(hi_rej=cpl_parameter_get_int(param));
+<a name="l00280"></a>00280 
+<a name="l00281"></a>00281     <span class="comment">/* --intopt */</span>
+<a name="l00282"></a>00282     check_nomsg(param=cpl_parameterlist_find(parlist,
+<a name="l00283"></a>00283                                   <span class="stringliteral">"sinfoni.sinfo_utl_cube2spectrum.centerx"</span>));
+<a name="l00284"></a>00284     check_nomsg(centerx=cpl_parameter_get_int(param));
+<a name="l00285"></a>00285 
+<a name="l00286"></a>00286     <span class="comment">/* --intopt */</span>
+<a name="l00287"></a>00287     check_nomsg(param=cpl_parameterlist_find(parlist,
+<a name="l00288"></a>00288                                   <span class="stringliteral">"sinfoni.sinfo_utl_cube2spectrum.centery"</span>));
+<a name="l00289"></a>00289     check_nomsg(centery=cpl_parameter_get_int(param));
+<a name="l00290"></a>00290 
+<a name="l00291"></a>00291     <span class="comment">/* --intopt */</span>
+<a name="l00292"></a>00292     check_nomsg(param=cpl_parameterlist_find(parlist,
+<a name="l00293"></a>00293                                   <span class="stringliteral">"sinfoni.sinfo_utl_cube2spectrum.radius"</span>));
+<a name="l00294"></a>00294     check_nomsg(radius=cpl_parameter_get_int(param));
+<a name="l00295"></a>00295   
+<a name="l00296"></a>00296     <span class="comment">/* Identify the RAW and CALIB frames in the input frameset */</span>
+<a name="l00297"></a>00297     <span class="keywordflow">if</span> (sinfo_dfs_set_groups(framelist)) {
+<a name="l00298"></a>00298         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>( <span class="stringliteral">"Cannot identify RAW and CALIB frames"</span>) ;
+<a name="l00299"></a>00299         <span class="keywordflow">goto</span> cleanup;
+<a name="l00300"></a>00300     }
+<a name="l00301"></a>00301 
+<a name="l00302"></a>00302     <span class="comment">/* HOW TO ACCESS INPUT DATA */</span>
+<a name="l00303"></a>00303     cknull(frm_cub=cpl_frameset_find(framelist,tag_i),
+<a name="l00304"></a>00304       <span class="stringliteral">"SOF does not have a file tagged as %s"</span>,tag_i);
+<a name="l00305"></a>00305    
+<a name="l00306"></a>00306     <span class="comment">/* Now performing the data reduction */</span>
+<a name="l00307"></a>00307     <span class="comment">/* Let's generate one image for the example */</span>
+<a name="l00308"></a>00308     check_nomsg(strcpy(name_i,cpl_frame_get_filename(frm_cub)));
+<a name="l00309"></a>00309     check_nomsg(cube = cpl_imagelist_load((<span class="keywordtype">char</span>*)name_i,CPL_TYPE_FLOAT,0));
+<a name="l00310"></a>00310 
+<a name="l00311"></a>00311     check_nomsg(img=cpl_imagelist_get(cube,0));
+<a name="l00312"></a>00312     check_nomsg(clx=cpl_image_get_size_x(img));
+<a name="l00313"></a>00313     check_nomsg(cly=cpl_image_get_size_y(img));
+<a name="l00314"></a>00314     check(plist=cpl_propertylist_load(name_i,0),
+<a name="l00315"></a>00315       <span class="stringliteral">"Cannot read the FITS header"</span>) ;
+<a name="l00316"></a>00316 
+<a name="l00317"></a>00317     cpix = (double) sinfo_pfits_get_crpix3(plist);
+<a name="l00318"></a>00318     clam = (double) sinfo_pfits_get_crval3(plist);
+<a name="l00319"></a>00319     disp = (double) sinfo_pfits_get_cdelt3(plist);
+<a name="l00320"></a>00320     sinfo_free_propertylist(&plist);
+<a name="l00321"></a>00321     <span class="keywordflow">if</span>(strcmp(aperture,<span class="stringliteral">"rectangle"</span>) ==0) {
+<a name="l00322"></a>00322       <span class="keywordflow">if</span> (llx<0) {
+<a name="l00323"></a>00323         <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"llx=%d too low set it to 0"</span>,llx);
+<a name="l00324"></a>00324         llx=0;
+<a name="l00325"></a>00325       }   
+<a name="l00326"></a>00326       <span class="keywordflow">if</span> (lly<0) {
+<a name="l00327"></a>00327         <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"lly=%d too low set it to 0"</span>,lly);
+<a name="l00328"></a>00328         lly=0;
+<a name="l00329"></a>00329       }   
+<a name="l00330"></a>00330       <span class="keywordflow">if</span> (urx>clx-1) {
+<a name="l00331"></a>00331         <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"urx=%d too large set it to %d"</span>,urx,clx-1);
+<a name="l00332"></a>00332         urx=clx-1;
+<a name="l00333"></a>00333       }   
+<a name="l00334"></a>00334       <span class="keywordflow">if</span> (ury>cly-1) {
+<a name="l00335"></a>00335         <a class="code" href="group__sinfo__msg.html#ga885dfc1c23dbdf3ea2051b42341a52a6" title="Print an warning message.">sinfo_msg_warning</a>(<span class="stringliteral">"ury=%d too large set it to %d"</span>,ury,cly-1);
+<a name="l00336"></a>00336         ury=cly-1;
+<a name="l00337"></a>00337       }   
+<a name="l00338"></a>00338       <span class="keywordflow">if</span>(llx>=urx) {
+<a name="l00339"></a>00339         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"llx>=urx!"</span>);
+<a name="l00340"></a>00340         <span class="keywordflow">goto</span> cleanup;
+<a name="l00341"></a>00341       }
+<a name="l00342"></a>00342       <span class="keywordflow">if</span>(lly>=ury) {
+<a name="l00343"></a>00343         <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"lly>=ury!"</span>);
+<a name="l00344"></a>00344         <span class="keywordflow">goto</span> cleanup;
+<a name="l00345"></a>00345       }
+<a name="l00346"></a>00346 
+<a name="l00347"></a>00347     } 
+<a name="l00348"></a>00348 
+<a name="l00349"></a>00349     <span class="keywordflow">if</span>(strcmp(aperture,<span class="stringliteral">"circle"</span>) ==0) {
+<a name="l00350"></a>00350       <span class="keywordflow">if</span>((centerx-radius) < 0) {
+<a name="l00351"></a>00351     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"It is not possible to set centerx-radius<0."</span>);
+<a name="l00352"></a>00352         <span class="keywordflow">goto</span> cleanup;
+<a name="l00353"></a>00353       }
+<a name="l00354"></a>00354 
+<a name="l00355"></a>00355       <span class="keywordflow">if</span>((centery-radius) < 0) {
+<a name="l00356"></a>00356     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"It is not possible to set centery-radius<0."</span>);
+<a name="l00357"></a>00357         <span class="keywordflow">goto</span> cleanup;
+<a name="l00358"></a>00358       }
+<a name="l00359"></a>00359 
+<a name="l00360"></a>00360       <span class="keywordflow">if</span>((centerx+radius) >= clx) {
+<a name="l00361"></a>00361     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"It is not possible to set centerx+radius >= cube x sixe"</span>);
+<a name="l00362"></a>00362         <span class="keywordflow">goto</span> cleanup;
+<a name="l00363"></a>00363       }
+<a name="l00364"></a>00364 
+<a name="l00365"></a>00365       <span class="keywordflow">if</span>((centery+radius) >= cly) {
+<a name="l00366"></a>00366     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"It is not possible to set centery+radius >= cube y size."</span>);
+<a name="l00367"></a>00367         <span class="keywordflow">goto</span> cleanup;
+<a name="l00368"></a>00368       }
+<a name="l00369"></a>00369 
+<a name="l00370"></a>00370       <span class="keywordflow">if</span>((radius) < 0) {
+<a name="l00371"></a>00371     <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"It is not possible to set radius<0."</span>);
+<a name="l00372"></a>00372         <span class="keywordflow">goto</span> cleanup;
+<a name="l00373"></a>00373       }
+<a name="l00374"></a>00374 
+<a name="l00375"></a>00375     }
+<a name="l00376"></a>00376 
+<a name="l00377"></a>00377     <span class="keywordflow">if</span>(strcmp(operation,<span class="stringliteral">"average"</span>) ==0) {
+<a name="l00378"></a>00378        <span class="keywordflow">if</span> (strcmp(aperture,<span class="stringliteral">"rectangle"</span>) ==0) {
+<a name="l00379"></a>00379           spec = sinfo_new_mean_rectangle_of_cube_spectra(cube,llx,lly,urx,ury);
+<a name="l00380"></a>00380        } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(aperture,<span class="stringliteral">"circle"</span>)==0) {
+<a name="l00381"></a>00381           spec = sinfo_new_mean_circle_of_cube_spectra(cube,centerx,
+<a name="l00382"></a>00382                                                        centery,radius);
+<a name="l00383"></a>00383        } <span class="keywordflow">else</span> {
+<a name="l00384"></a>00384           <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Aperture not supported"</span>);
+<a name="l00385"></a>00385           sinfo_msg(<span class="stringliteral">"Supported apertures are only:"</span>);
+<a name="l00386"></a>00386           sinfo_msg(<span class="stringliteral">"rectangle, circle:"</span>);
+<a name="l00387"></a>00387         <span class="keywordflow">goto</span> cleanup;
+<a name="l00388"></a>00388        }
+<a name="l00389"></a>00389     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(operation,<span class="stringliteral">"clean_mean"</span>) ==0) {
+<a name="l00390"></a>00390       <span class="keywordflow">if</span> (strcmp(aperture,<span class="stringliteral">"rectangle"</span>) == 0) {
+<a name="l00391"></a>00391           spec = sinfo_new_clean_mean_rectangle_of_cube_spectra(cube,llx,lly,
+<a name="l00392"></a>00392                                                                 urx,ury,
+<a name="l00393"></a>00393                                                                 lo_rej,hi_rej);
+<a name="l00394"></a>00394       } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(aperture,<span class="stringliteral">"circle"</span>)==0) {
+<a name="l00395"></a>00395           spec = sinfo_new_clean_mean_circle_of_cube_spectra(cube,centerx,
+<a name="l00396"></a>00396                                                              centery,radius,
+<a name="l00397"></a>00397                                                              lo_rej,hi_rej); 
+<a name="l00398"></a>00398       } <span class="keywordflow">else</span> {
+<a name="l00399"></a>00399           <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Aperture not supported"</span>);
+<a name="l00400"></a>00400           sinfo_msg(<span class="stringliteral">"Supported apertures are only:"</span>);
+<a name="l00401"></a>00401           sinfo_msg(<span class="stringliteral">"rectangle, circle:"</span>);
+<a name="l00402"></a>00402           <span class="keywordflow">goto</span> cleanup;
+<a name="l00403"></a>00403       }
+<a name="l00404"></a>00404     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(operation,<span class="stringliteral">"median"</span>) ==0) {
+<a name="l00405"></a>00405        <span class="keywordflow">if</span> (strcmp(aperture,<span class="stringliteral">"rectangle"</span>)==0) {
+<a name="l00406"></a>00406           spec = sinfo_new_median_rectangle_of_cube_spectra(cube,llx,lly,
+<a name="l00407"></a>00407                                                             urx,ury);
+<a name="l00408"></a>00408        } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(aperture,<span class="stringliteral">"circle"</span>)==0) {
+<a name="l00409"></a>00409           spec = sinfo_new_median_circle_of_cube_spectra(cube,centerx,
+<a name="l00410"></a>00410                                                          centery,radius);
+<a name="l00411"></a>00411        } <span class="keywordflow">else</span> {
+<a name="l00412"></a>00412           <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Aperture not supported"</span>);
+<a name="l00413"></a>00413           sinfo_msg(<span class="stringliteral">"Supported apertures are only:"</span>);
+<a name="l00414"></a>00414           sinfo_msg(<span class="stringliteral">"rectangle, circle:"</span>);
+<a name="l00415"></a>00415           <span class="keywordflow">goto</span> cleanup;
+<a name="l00416"></a>00416        }
+<a name="l00417"></a>00417     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(operation,<span class="stringliteral">"sum"</span>) ==0) {
+<a name="l00418"></a>00418        <span class="keywordflow">if</span> (strcmp(aperture,<span class="stringliteral">"rectangle"</span>)==0) {
+<a name="l00419"></a>00419           spec = sinfo_new_sum_rectangle_of_cube_spectra(cube,llx,lly,urx,ury);
+<a name="l00420"></a>00420        } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(aperture,<span class="stringliteral">"circle"</span>)==0) {
+<a name="l00421"></a>00421           spec = sinfo_new_sum_circle_of_cube_spectra(cube,centerx,
+<a name="l00422"></a>00422                                                       centery,radius);
+<a name="l00423"></a>00423        } <span class="keywordflow">else</span> {
+<a name="l00424"></a>00424           <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Aperture not supported"</span>);
+<a name="l00425"></a>00425           sinfo_msg(<span class="stringliteral">"Supported apertures are only:"</span>);
+<a name="l00426"></a>00426           sinfo_msg(<span class="stringliteral">"rectangle, circle:"</span>);
+<a name="l00427"></a>00427           <span class="keywordflow">goto</span> cleanup;
+<a name="l00428"></a>00428        }
+<a name="l00429"></a>00429     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(operation,<span class="stringliteral">"extract"</span>) == 0) {
+<a name="l00430"></a>00430        <span class="keywordflow">if</span> (strcmp(aperture,<span class="stringliteral">"rectangle"</span>)==0) {
+<a name="l00431"></a>00431       spec = sinfo_new_median_rectangle_of_cube_spectra(cube,llx,lly,
+<a name="l00432"></a>00432                                                             urx,ury); 
+<a name="l00433"></a>00433        } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(aperture,<span class="stringliteral">"circle"</span>)==0) {
+<a name="l00434"></a>00434      spec = sinfo_new_median_circle_of_cube_spectra(cube,centerx,
+<a name="l00435"></a>00435                                                         centery,radius);
+<a name="l00436"></a>00436        } <span class="keywordflow">else</span> {
+<a name="l00437"></a>00437           <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Aperture not supported"</span>);
+<a name="l00438"></a>00438           sinfo_msg(<span class="stringliteral">"Supported apertures are only:"</span>);
+<a name="l00439"></a>00439           sinfo_msg(<span class="stringliteral">"rectangle, circle:"</span>);
+<a name="l00440"></a>00440           <span class="keywordflow">goto</span> cleanup;
+<a name="l00441"></a>00441        }
+<a name="l00442"></a>00442     } <span class="keywordflow">else</span> {
+<a name="l00443"></a>00443       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Operation not supported"</span>);
+<a name="l00444"></a>00444       sinfo_msg(<span class="stringliteral">"Supported operations are only:"</span>);
+<a name="l00445"></a>00445       sinfo_msg(<span class="stringliteral">"average, clean_mean, median, sum, extract :"</span>);
+<a name="l00446"></a>00446       <span class="keywordflow">goto</span> cleanup;
+<a name="l00447"></a>00447     }
+<a name="l00448"></a>00448     im_spec = sinfo_new_vector_to_image(spec);
+<a name="l00449"></a>00449     <span class="comment">/* head = sinfo_fits_read_header((char*)name_i); */</span>
+<a name="l00450"></a>00450     sinfo_msg(<span class="stringliteral">"name_i=%s"</span>,name_i);
+<a name="l00451"></a>00451     ck0_nomsg(sinfo_change_header(name_i));
+<a name="l00452"></a>00452 
+<a name="l00453"></a>00453     <span class="comment">/* HOW TO SAVE A PRODUCT ON DISK  */</span>
+<a name="l00454"></a>00454     <span class="comment">/* Set the file name */</span>
+<a name="l00455"></a>00455  
+<a name="l00456"></a>00456     <span class="comment">/* Create product frame */</span>
+<a name="l00457"></a>00457     ck0(sinfo_pro_save_ima(im_spec,framelist,framelist,ima_o,
+<a name="l00458"></a>00458                tag_o,NULL,cpl_func,parlist),<span class="stringliteral">"failed to save ima"</span>);
+<a name="l00459"></a>00459 
+<a name="l00460"></a>00460 
+<a name="l00461"></a>00461     sinfo_new_set_wcs_spectrum (im_spec,ima_o,clam, disp, cpix);
+<a name="l00462"></a>00462 
+<a name="l00463"></a>00463     sinfo_stectrum_ima2table(im_spec,ima_o,&tbl_spec);
+<a name="l00464"></a>00464      ck0(sinfo_pro_save_tbl(tbl_spec,framelist,framelist,tbl_o,
+<a name="l00465"></a>00465                tag_o,NULL,cpl_func,parlist),
+<a name="l00466"></a>00466                            <span class="stringliteral">"failed to save spectrum"</span>);
+<a name="l00467"></a>00467 
+<a name="l00468"></a>00468  cleanup:
+<a name="l00469"></a>00469     sinfo_free_propertylist(&plist) ;
+<a name="l00470"></a>00470     sinfo_free_frame(&product_frame) ;
+<a name="l00471"></a>00471     sinfo_free_image(&image) ;
+<a name="l00472"></a>00472     sinfo_free_imagelist(&cube);
+<a name="l00473"></a>00473     sinfo_free_image(&im_spec);
+<a name="l00474"></a>00474     <span class="comment">/* This generate seg fault</span>
+<a name="l00475"></a>00475 <span class="comment">    if(spec != NULL) sinfo_free_svector(&spec);</span>
+<a name="l00476"></a>00476 <span class="comment">    */</span>
+<a name="l00477"></a>00477     sinfo_free_table(&tbl_spec);
+<a name="l00478"></a>00478     <span class="comment">/*if(head != NULL) sinfo_fits_header_destroy(head); */</span>
+<a name="l00479"></a>00479  
+<a name="l00480"></a>00480     <span class="comment">/* Return */</span>
+<a name="l00481"></a>00481     <span class="keywordflow">if</span> (cpl_error_get_code()) 
+<a name="l00482"></a>00482         <span class="keywordflow">return</span> -1 ;
+<a name="l00483"></a>00483     <span class="keywordflow">else</span> 
+<a name="l00484"></a>00484         <span class="keywordflow">return</span> 0 ;
+<a name="l00485"></a>00485 
+<a name="l00486"></a>00486 
+<a name="l00487"></a>00487 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfoni_2sinfo__utl__cube__arith_8c_source.html b/html/sinfoni_2sinfo__utl__cube__arith_8c_source.html
new file mode 100644
index 0000000..657c9d4
--- /dev/null
+++ b/html/sinfoni_2sinfo__utl__cube__arith_8c_source.html
@@ -0,0 +1,333 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_utl_cube_arith.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_utl_cube_arith.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_utl_cube_arith.c,v 1.14 2012/03/03 10:17:31 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the IIINSTRUMENT Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2012/03/03 10:17:31 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.14 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 
+<a name="l00029"></a>00029 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00031"></a>00031 <span class="preprocessor">#endif</span>
+<a name="l00032"></a>00032 <span class="preprocessor"></span><span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                                Includes</span>
+<a name="l00034"></a>00034 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 
+<a name="l00036"></a>00036 <span class="preprocessor">#include "sinfo_utl_cube_arith.h"</span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include <sinfo_spectrum_ops.h></span>
+<a name="l00038"></a>00038 <span class="preprocessor">#include <sinfo_new_cube_ops.h></span>
+<a name="l00039"></a>00039 <span class="preprocessor">#include "sinfo_key_names.h"</span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include "sinfo_pro_types.h"</span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include <sinfo_error.h></span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include <sinfo_utilities.h></span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include <sinfo_utils_wrappers.h></span>
+<a name="l00044"></a>00044 
+<a name="l00045"></a>00045 
+<a name="l00046"></a>00046 
+<a name="l00047"></a>00047 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00048"></a>00048 <span class="comment">                            Functions prototypes</span>
+<a name="l00049"></a>00049 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00050"></a>00050 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00051"></a>00051 <span class="comment">                            Static variables</span>
+<a name="l00052"></a>00052 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00053"></a>00053 
+<a name="l00061"></a>00061 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00062"></a>00062 <span class="comment">                                Functions code</span>
+<a name="l00063"></a>00063 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00064"></a>00064 
+<a name="l00065"></a>00065 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00072"></a>00072 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00073"></a>00073 <span class="keywordtype">int</span> sinfo_utl_cube_arith(
+<a name="l00074"></a>00074    cpl_parameterlist   *   parlist, 
+<a name="l00075"></a>00075    cpl_frameset        *   framelist)
+<a name="l00076"></a>00076 {
+<a name="l00077"></a>00077    cpl_parameter       *   param =NULL;
+<a name="l00078"></a>00078    <span class="keyword">const</span> <span class="keywordtype">char</span>          *   operation =NULL;
+<a name="l00079"></a>00079    <span class="keyword">const</span> <span class="keywordtype">char</span>          *   name_c =NULL;
+<a name="l00080"></a>00080    <span class="keyword">const</span> <span class="keywordtype">char</span>          *   name_s =NULL;
+<a name="l00081"></a>00081    <span class="keyword">const</span> <span class="keywordtype">char</span>          *   name_o =NULL;
+<a name="l00082"></a>00082    <span class="keyword">const</span> <span class="keywordtype">char</span>          *   name_d =<span class="stringliteral">"start"</span>;
+<a name="l00083"></a>00083 
+<a name="l00084"></a>00084    <span class="comment">/* double                  temp=0 ; */</span>
+<a name="l00085"></a>00085    <span class="keywordtype">double</span>                  value=0 ;
+<a name="l00086"></a>00086    <span class="keywordtype">double</span>                  def_value=0 ;
+<a name="l00087"></a>00087 
+<a name="l00088"></a>00088    cpl_parameter *         p=NULL;
+<a name="l00089"></a>00089    cpl_frame           *   frm_cube=NULL ;
+<a name="l00090"></a>00090    cpl_frame           *   frm_spct=NULL ;
+<a name="l00091"></a>00091 
+<a name="l00092"></a>00092    cpl_propertylist    *   plist=NULL ;
+<a name="l00093"></a>00093    cpl_image           *   image=NULL ;
+<a name="l00094"></a>00094    cpl_frame           *   product_frame=NULL;
+<a name="l00095"></a>00095    cpl_imagelist       *   cub_ims=NULL;
+<a name="l00096"></a>00096    cpl_imagelist * cube_i=NULL;
+<a name="l00097"></a>00097    cpl_imagelist * cube_o=NULL;
+<a name="l00098"></a>00098    cpl_imagelist * cube_d=NULL;
+<a name="l00099"></a>00099    cpl_image * std_star=NULL;
+<a name="l00100"></a>00100    Vector * bb=NULL;
+<a name="l00101"></a>00101    Vector*   spectrum=NULL;
+<a name="l00102"></a>00102    cpl_vector* vec=NULL;
+<a name="l00103"></a>00103    <span class="comment">/* Identify the RAW and CALIB frames in the input frameset */</span>
+<a name="l00104"></a>00104    check(sinfo_dfs_set_groups(framelist),
+<a name="l00105"></a>00105          <span class="stringliteral">"Cannot identify RAW and CALIB frames"</span>) ;
+<a name="l00106"></a>00106 
+<a name="l00107"></a>00107  
+<a name="l00108"></a>00108    <span class="comment">/* HOW TO RETRIEVE INPUT PARAMETERS */</span>
+<a name="l00109"></a>00109    <span class="comment">/* --stropt */</span>
+<a name="l00110"></a>00110    check_nomsg(param = cpl_parameterlist_find(parlist, 
+<a name="l00111"></a>00111                                               <span class="stringliteral">"sinfoni.sinfo_utl_cube_arith.op"</span>));
+<a name="l00112"></a>00112    check_nomsg(operation = cpl_parameter_get_string(param));
+<a name="l00113"></a>00113    name_o = <span class="stringliteral">"out_cube.fits"</span>;
+<a name="l00114"></a>00114 
+<a name="l00115"></a>00115 
+<a name="l00116"></a>00116    <span class="comment">/* --doubleopt */</span>
+<a name="l00117"></a>00117    check_nomsg(param = cpl_parameterlist_find(parlist,
+<a name="l00118"></a>00118                                               <span class="stringliteral">"sinfoni.sinfo_utl_cube_arith.value"</span>));
+<a name="l00119"></a>00119    check_nomsg(value = cpl_parameter_get_double(param));
+<a name="l00120"></a>00120 
+<a name="l00121"></a>00121    <span class="comment">/* HOW TO ACCESS INPUT DATA */</span>
+<a name="l00122"></a>00122    check(frm_cube = cpl_frameset_find(framelist, SI_UTL_CUBE_ARITH_CUBE),
+<a name="l00123"></a>00123          <span class="stringliteral">"SOF does not have a file tagged as %s"</span>,SI_UTL_CUBE_ARITH_CUBE);
+<a name="l00124"></a>00124     
+<a name="l00125"></a>00125    check_nomsg(name_c = cpl_frame_get_filename(frm_cube));
+<a name="l00126"></a>00126    check_nomsg(p = cpl_parameterlist_find(parlist, 
+<a name="l00127"></a>00127                                           <span class="stringliteral">"sinfoni.sinfo_utl_cube_arith.value"</span>));
+<a name="l00128"></a>00128    check_nomsg(def_value = cpl_parameter_get_default_double(p));
+<a name="l00129"></a>00129    <span class="keywordflow">if</span> (value == def_value) {
+<a name="l00130"></a>00130       <span class="keywordflow">if</span> ((frm_spct = cpl_frameset_find(framelist, 
+<a name="l00131"></a>00131                                         SI_UTL_CUBE_ARITH_SPECTRUM))==NULL) {
+<a name="l00132"></a>00132          sinfo_msg( <span class="stringliteral">"SOF does not have a file tagged as %s"</span>,
+<a name="l00133"></a>00133                     SI_UTL_CUBE_ARITH_SPECTRUM);
+<a name="l00134"></a>00134          cpl_error_reset();
+<a name="l00135"></a>00135       } <span class="keywordflow">else</span> {
+<a name="l00136"></a>00136          sinfo_msg( <span class="stringliteral">"SOF contains a file tagged as %s"</span>,
+<a name="l00137"></a>00137                     SI_UTL_CUBE_ARITH_SPECTRUM);
+<a name="l00138"></a>00138          name_s = cpl_frame_get_filename(frm_spct);
+<a name="l00139"></a>00139          name_d = <span class="stringliteral">"spectrum"</span>;
+<a name="l00140"></a>00140       }
+<a name="l00141"></a>00141    }
+<a name="l00142"></a>00142 
+<a name="l00143"></a>00143    <span class="keywordflow">if</span> (value == def_value) {
+<a name="l00144"></a>00144       <span class="keywordflow">if</span> ((frm_spct = cpl_frameset_find(framelist, PRO_SPECTRUM))!=NULL) {
+<a name="l00145"></a>00145          sinfo_msg( <span class="stringliteral">"SOF contains a file tagged as %s"</span>,PRO_SPECTRUM);
+<a name="l00146"></a>00146          name_s = cpl_frame_get_filename(frm_spct);
+<a name="l00147"></a>00147          name_d = <span class="stringliteral">"spectrum"</span>;
+<a name="l00148"></a>00148       } <span class="keywordflow">else</span> <span class="keywordflow">if</span> ((frm_spct = cpl_frameset_find(framelist, PRO_IMA))!=NULL) {
+<a name="l00149"></a>00149          sinfo_msg( <span class="stringliteral">"SOF contains a file tagged as %s"</span>,PRO_IMA);
+<a name="l00150"></a>00150          name_s = cpl_frame_get_filename(frm_spct);
+<a name="l00151"></a>00151          name_d = <span class="stringliteral">"image"</span>;
+<a name="l00152"></a>00152       } <span class="keywordflow">else</span> {
+<a name="l00153"></a>00153          sinfo_msg( <span class="stringliteral">"SOF does not contains a file tagged as %s nor as %s"</span>,
+<a name="l00154"></a>00154             PRO_SPECTRUM,PRO_IMA);
+<a name="l00155"></a>00155          sinfo_msg( <span class="stringliteral">"Assume operation by a constant"</span>);
+<a name="l00156"></a>00156          cpl_error_reset();
+<a name="l00157"></a>00157       }
+<a name="l00158"></a>00158    }
+<a name="l00159"></a>00159    check(plist=cpl_propertylist_load(cpl_frame_get_filename(frm_cube),0),
+<a name="l00160"></a>00160          <span class="stringliteral">"Cannot read the FITS header"</span>) ;
+<a name="l00161"></a>00161      
+<a name="l00162"></a>00162 
+<a name="l00163"></a>00163    <span class="comment">/* Now performing the data reduction */</span>
+<a name="l00164"></a>00164    <span class="comment">/* Let's generate one image for the example */</span>
+<a name="l00165"></a>00165    check_nomsg(cube_i= cpl_imagelist_load((<span class="keywordtype">char</span>*)name_c,CPL_TYPE_FLOAT,0));
+<a name="l00166"></a>00166    <span class="keywordflow">if</span> (value == def_value) {
+<a name="l00167"></a>00167       sinfo_msg(<span class="stringliteral">"value equal to default"</span>);
+<a name="l00168"></a>00168       <span class="keywordflow">if</span>( strcmp(name_d,<span class="stringliteral">"spectrum"</span>) == 0 ) {
+<a name="l00169"></a>00169          sinfo_msg(<span class="stringliteral">"Operation by spectrum"</span>);
+<a name="l00170"></a>00170          sinfo_msg(<span class="stringliteral">"loading spectrum image file %s"</span>,name_s);
+<a name="l00171"></a>00171          check_nomsg(std_star=cpl_image_load((<span class="keywordtype">char</span>*)name_s,CPL_TYPE_FLOAT,0,0));
+<a name="l00172"></a>00172 
+<a name="l00173"></a>00173          <span class="comment">//check_nomsg(std_star=sinfo_vector_to_image(vec,CPL_TYPE_FLOAT));</span>
+<a name="l00174"></a>00174          check_nomsg(spectrum  = sinfo_new_image_to_vector(std_star));
+<a name="l00175"></a>00175          <span class="keywordflow">if</span> (strcmp(operation,<span class="stringliteral">"/"</span>) == 0) {
+<a name="l00176"></a>00176             cube_o = sinfo_new_div_cube_by_spectrum (cube_i, spectrum);
+<a name="l00177"></a>00177          } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(operation,<span class="stringliteral">"-"</span>) == 0) {
+<a name="l00178"></a>00178             cube_o = sinfo_new_sub_spectrum_from_cube(cube_i, spectrum);
+<a name="l00179"></a>00179          } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(operation,<span class="stringliteral">"+"</span>) == 0) {
+<a name="l00180"></a>00180             cube_o = sinfo_new_add_spectrum_to_cube(cube_i, spectrum);
+<a name="l00181"></a>00181          } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(operation,<span class="stringliteral">"*"</span>) == 0) {
+<a name="l00182"></a>00182             cube_o = sinfo_new_mul_spectrum_to_cube(cube_i, spectrum);
+<a name="l00183"></a>00183             <span class="comment">/*</span>
+<a name="l00184"></a>00184 <span class="comment">              } else if (strcmp(operation,"calib") == 0) {</span>
+<a name="l00185"></a>00185 <span class="comment">              bb = sinfo_new_blackbody_spectrum ((char*)name_s, temp); </span>
+<a name="l00186"></a>00186 <span class="comment">              cube_d   = sinfo_new_div_cube_by_Spectrum (cube_i, spectrum);</span>
+<a name="l00187"></a>00187 <span class="comment">              cube_o = sinfo_new_mul_spectrum_to_cube(cube_d, bb); </span>
+<a name="l00188"></a>00188 <span class="comment">            */</span>
+<a name="l00189"></a>00189       
+<a name="l00190"></a>00190          } <span class="keywordflow">else</span> {
+<a name="l00191"></a>00191             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"operation %s not supported"</span>,operation);
+<a name="l00192"></a>00192             sinfo_msg(<span class="stringliteral">"If an input spectrum is given and no value is set"</span>);
+<a name="l00193"></a>00193             sinfo_msg(<span class="stringliteral">"operations supported are: `/`,`-`,`+`,'*'"</span>);
+<a name="l00194"></a>00194             <span class="keywordflow">goto</span> cleanup;
+<a name="l00195"></a>00195          }
+<a name="l00196"></a>00196          <span class="keywordflow">if</span> (strcmp(operation,<span class="stringliteral">"calib"</span>) == 0) {
+<a name="l00197"></a>00197             <span class="keywordflow">goto</span> cleanup;
+<a name="l00198"></a>00198          }
+<a name="l00199"></a>00199       } <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( strcmp(name_d,<span class="stringliteral">"image"</span>) == 0) {
+<a name="l00200"></a>00200          sinfo_msg(<span class="stringliteral">"Operation by image"</span>);
+<a name="l00201"></a>00201          check_nomsg(std_star=cpl_image_load ((<span class="keywordtype">char</span>*)name_s,
+<a name="l00202"></a>00202                                               CPL_TYPE_FLOAT,0,0));
+<a name="l00203"></a>00203          <span class="keywordflow">if</span>(strcmp(operation,<span class="stringliteral">"+"</span>) == 0) {
+<a name="l00204"></a>00204             cknull(cube_o = sinfo_new_add_image_to_cube(cube_i,std_star),
+<a name="l00205"></a>00205                    <span class="stringliteral">"operation %s failed"</span>,operation);
+<a name="l00206"></a>00206          } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(operation,<span class="stringliteral">"-"</span>) == 0) {
+<a name="l00207"></a>00207             cknull(cube_o = sinfo_new_sub_image_from_cube(cube_i,std_star),
+<a name="l00208"></a>00208                    <span class="stringliteral">"operation %s failed"</span>,operation);
+<a name="l00209"></a>00209          } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(operation,<span class="stringliteral">"*"</span>) == 0) {
+<a name="l00210"></a>00210             cknull(cube_o = sinfo_new_mul_image_to_cube(cube_i,std_star),
+<a name="l00211"></a>00211                    <span class="stringliteral">"operation %s failed"</span>,operation);
+<a name="l00212"></a>00212          } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(operation,<span class="stringliteral">"/"</span>) == 0) {
+<a name="l00213"></a>00213             cknull(cube_o = sinfo_new_div_cube_by_image(cube_i,std_star),
+<a name="l00214"></a>00214                    <span class="stringliteral">"operation %s failed"</span>,operation);
+<a name="l00215"></a>00215          } <span class="keywordflow">else</span> {
+<a name="l00216"></a>00216             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"operation %s not supported"</span>,operation);
+<a name="l00217"></a>00217             sinfo_msg(<span class="stringliteral">"If an input image is set"</span>);
+<a name="l00218"></a>00218             sinfo_msg(<span class="stringliteral">"operations supported are: `-`, `+`, `*`, `/`"</span>);
+<a name="l00219"></a>00219             <span class="keywordflow">goto</span> cleanup;
+<a name="l00220"></a>00220          }
+<a name="l00221"></a>00221       } <span class="keywordflow">else</span> {
+<a name="l00222"></a>00222          sinfo_msg(<span class="stringliteral">"Operation %s by constant"</span>,operation);
+<a name="l00223"></a>00223 
+<a name="l00224"></a>00224          check_nomsg(cube_o = cpl_imagelist_duplicate(cube_i));
+<a name="l00225"></a>00225 
+<a name="l00226"></a>00226          <span class="keywordflow">if</span>(strcmp(operation,<span class="stringliteral">"+"</span>) == 0) {
+<a name="l00227"></a>00227             check(cpl_imagelist_add_scalar(cube_o,value),
+<a name="l00228"></a>00228                   <span class="stringliteral">"operation %s failed"</span>,operation);
+<a name="l00229"></a>00229          } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(operation,<span class="stringliteral">"-"</span>) == 0) {
+<a name="l00230"></a>00230             check(cpl_imagelist_subtract_scalar(cube_o,value),
+<a name="l00231"></a>00231                   <span class="stringliteral">"operation %s failed"</span>,operation);
+<a name="l00232"></a>00232          } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(operation,<span class="stringliteral">"*"</span>) == 0) {
+<a name="l00233"></a>00233             check(cpl_imagelist_multiply_scalar(cube_o,value),
+<a name="l00234"></a>00234                   <span class="stringliteral">"operation %s failed"</span>,operation);
+<a name="l00235"></a>00235          } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(operation,<span class="stringliteral">"/"</span>) == 0) {
+<a name="l00236"></a>00236             check(cpl_imagelist_divide_scalar(cube_o,value),
+<a name="l00237"></a>00237                   <span class="stringliteral">"operation %s failed"</span>,operation);
+<a name="l00238"></a>00238          } <span class="keywordflow">else</span> {
+<a name="l00239"></a>00239             <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"operation %s not supported"</span>,operation);
+<a name="l00240"></a>00240             sinfo_msg(<span class="stringliteral">"If an input value is set"</span>);
+<a name="l00241"></a>00241             sinfo_msg(<span class="stringliteral">"operations supported are: `-`, `+`, `*`, `/`"</span>);
+<a name="l00242"></a>00242             <span class="keywordflow">goto</span> cleanup;
+<a name="l00243"></a>00243          }
+<a name="l00244"></a>00244 
+<a name="l00245"></a>00245       } <span class="comment">/* env case op by constant && value == default */</span>
+<a name="l00246"></a>00246 
+<a name="l00247"></a>00247    } <span class="keywordflow">else</span> {
+<a name="l00248"></a>00248 
+<a name="l00249"></a>00249       sinfo_msg(<span class="stringliteral">"Operation %s by constant"</span>,operation);
+<a name="l00250"></a>00250 
+<a name="l00251"></a>00251       check_nomsg(cube_o = cpl_imagelist_duplicate(cube_i));
+<a name="l00252"></a>00252 
+<a name="l00253"></a>00253       <span class="keywordflow">if</span>(strcmp(operation,<span class="stringliteral">"+"</span>) == 0) {
+<a name="l00254"></a>00254          check(cpl_imagelist_add_scalar(cube_o,value),
+<a name="l00255"></a>00255                <span class="stringliteral">"operation %s failed"</span>,operation);
+<a name="l00256"></a>00256       } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(operation,<span class="stringliteral">"-"</span>) == 0) {
+<a name="l00257"></a>00257          check(cpl_imagelist_subtract_scalar(cube_o,value),
+<a name="l00258"></a>00258                <span class="stringliteral">"operation %s failed"</span>,operation);
+<a name="l00259"></a>00259       } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(operation,<span class="stringliteral">"*"</span>) == 0) {
+<a name="l00260"></a>00260          check(cpl_imagelist_multiply_scalar(cube_o,value),
+<a name="l00261"></a>00261                <span class="stringliteral">"operation %s failed"</span>,operation);
+<a name="l00262"></a>00262       } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(operation,<span class="stringliteral">"/"</span>) == 0) {
+<a name="l00263"></a>00263          check(cpl_imagelist_divide_scalar(cube_o,value),
+<a name="l00264"></a>00264                <span class="stringliteral">"operation %s failed"</span>,operation);
+<a name="l00265"></a>00265       } <span class="keywordflow">else</span> {
+<a name="l00266"></a>00266          <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"operation %s not supported"</span>,operation);
+<a name="l00267"></a>00267          sinfo_msg(<span class="stringliteral">"If an input value is set"</span>);
+<a name="l00268"></a>00268          sinfo_msg(<span class="stringliteral">"operations supported are: `-`, `+`, `*`, `/`"</span>);
+<a name="l00269"></a>00269          <span class="keywordflow">goto</span> cleanup;
+<a name="l00270"></a>00270       }
+<a name="l00271"></a>00271 
+<a name="l00272"></a>00272    }
+<a name="l00273"></a>00273    <span class="comment">/* HOW TO SAVE A PRODUCT ON DISK  */</span>
+<a name="l00274"></a>00274    <span class="comment">/* Set the file name */</span>
+<a name="l00275"></a>00275    <span class="comment">/* Create product frame */</span>
+<a name="l00276"></a>00276    check_nomsg(product_frame = cpl_frame_new());
+<a name="l00277"></a>00277    check_nomsg(cpl_frame_set_filename(product_frame, name_o)) ;
+<a name="l00278"></a>00278    check_nomsg(cpl_frame_set_tag(product_frame, SI_UTL_CUBE_ARITH_PROCUBE)) ;
+<a name="l00279"></a>00279    check_nomsg(cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_IMAGE)) ;
+<a name="l00280"></a>00280    check_nomsg(cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT)) ;
+<a name="l00281"></a>00281    check(cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL),
+<a name="l00282"></a>00282            <span class="stringliteral">"Error while initialising the product frame"</span>) ;
+<a name="l00283"></a>00283  <span class="comment">/* Add DataFlow keywords */</span>
+<a name="l00284"></a>00284    check_nomsg(cpl_propertylist_erase_regexp(plist, <span class="stringliteral">"^ESO PRO CATG"</span>,0));
+<a name="l00285"></a>00285 
+<a name="l00286"></a>00286 <span class="preprocessor">#if defined CPL_VERSION_CODE && CPL_VERSION_CODE >= CPL_VERSION(4, 8, 0)  </span>
+<a name="l00287"></a>00287 <span class="preprocessor"></span>   check(cpl_dfs_setup_product_header(plist, product_frame, framelist, 
+<a name="l00288"></a>00288                                       parlist,
+<a name="l00289"></a>00289                                       <span class="stringliteral">"si_sinfo_utl_cube_arith"</span>, 
+<a name="l00290"></a>00290                                       <span class="stringliteral">"SINFONI"</span>, KEY_VALUE_HPRO_DID,NULL),
+<a name="l00291"></a>00291          <span class="stringliteral">"Problem in the product DFS-compliance"</span>) ;
+<a name="l00292"></a>00292 <span class="preprocessor">#else</span>
+<a name="l00293"></a>00293 <span class="preprocessor"></span>   check(cpl_dfs_setup_product_header(plist, product_frame, framelist, 
+<a name="l00294"></a>00294                                       parlist,
+<a name="l00295"></a>00295                                       <span class="stringliteral">"si_sinfo_utl_cube_arith"</span>, 
+<a name="l00296"></a>00296                                       <span class="stringliteral">"SINFONI"</span>, KEY_VALUE_HPRO_DID),
+<a name="l00297"></a>00297          <span class="stringliteral">"Problem in the product DFS-compliance"</span>) ;
+<a name="l00298"></a>00298 <span class="preprocessor">#endif</span>
+<a name="l00299"></a>00299 <span class="preprocessor"></span>
+<a name="l00300"></a>00300   <span class="comment">/* Save the file */</span>
+<a name="l00301"></a>00301    check(cpl_imagelist_save(cube_o, name_o, CPL_BPP_IEEE_FLOAT, plist,
+<a name="l00302"></a>00302                             CPL_IO_DEFAULT),
+<a name="l00303"></a>00303          <span class="stringliteral">"Could not save product"</span>);
+<a name="l00304"></a>00304  
+<a name="l00305"></a>00305 
+<a name="l00306"></a>00306    <span class="comment">/* Log the saved file in the input frameset */</span>
+<a name="l00307"></a>00307    check_nomsg(cpl_frameset_insert(framelist, product_frame)) ;
+<a name="l00308"></a>00308 
+<a name="l00309"></a>00309 
+<a name="l00310"></a>00310 
+<a name="l00311"></a>00311   cleanup:
+<a name="l00312"></a>00312    sinfoni_free_vector(&vec);
+<a name="l00313"></a>00313    sinfo_free_svector(&spectrum);
+<a name="l00314"></a>00314    sinfo_free_svector(&bb);
+<a name="l00315"></a>00315 
+<a name="l00316"></a>00316    sinfo_free_imagelist(&cube_d);
+<a name="l00317"></a>00317    sinfo_free_imagelist(&cube_i);
+<a name="l00318"></a>00318    sinfo_free_imagelist(&cube_o);
+<a name="l00319"></a>00319    <span class="comment">//If I free the next image I get core dump!</span>
+<a name="l00320"></a>00320    <span class="comment">//sinfo_free_image(&std_star);</span>
+<a name="l00321"></a>00321    sinfo_free_image(&image);
+<a name="l00322"></a>00322    sinfo_free_imagelist(&cub_ims);
+<a name="l00323"></a>00323    sinfo_free_propertylist(&plist);
+<a name="l00324"></a>00324     
+<a name="l00325"></a>00325     <span class="comment">/* Return */</span>
+<a name="l00326"></a>00326    <span class="keywordflow">if</span> (cpl_error_get_code()) 
+<a name="l00327"></a>00327       <span class="keywordflow">return</span> -1 ;
+<a name="l00328"></a>00328    <span class="keywordflow">else</span> 
+<a name="l00329"></a>00329       <span class="keywordflow">return</span> 0 ;
+<a name="l00330"></a>00330 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfoni_2sinfo__utl__cube__combine_8c_source.html b/html/sinfoni_2sinfo__utl__cube__combine_8c_source.html
new file mode 100644
index 0000000..78c4e8e
--- /dev/null
+++ b/html/sinfoni_2sinfo__utl__cube__combine_8c_source.html
@@ -0,0 +1,381 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_utl_cube_combine.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_utl_cube_combine.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_utl_cube_combine.c,v 1.20 2012/03/03 10:17:31 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the IIINSTRUMENT Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2012/03/03 10:17:31 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.20 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span>
+<a name="l00032"></a>00032 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                                Includes</span>
+<a name="l00034"></a>00034 <span class="comment"> ---------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 
+<a name="l00036"></a>00036 <span class="preprocessor">#include "sinfo_utl_cube_combine.h"</span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include "sinfo_utilities.h"</span>
+<a name="l00038"></a>00038 <span class="preprocessor">#include "sinfo_utilities_scired.h"</span>
+<a name="l00039"></a>00039 <span class="preprocessor">#include <stdio.h></span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include "sinfo_key_names.h"</span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include "sinfo_error.h"</span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include "sinfo_utils_wrappers.h"</span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include "sinfo_pro_save.h"</span>
+<a name="l00044"></a>00044 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00045"></a>00045 <span class="comment">                            Functions prototypes</span>
+<a name="l00046"></a>00046 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00047"></a>00047 
+<a name="l00048"></a>00048 
+<a name="l00049"></a>00049 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00050"></a>00050 <span class="comment">                            Static variables</span>
+<a name="l00051"></a>00051 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00052"></a>00052 
+<a name="l00053"></a>00053 
+<a name="l00054"></a>00054 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00055"></a>00055 <span class="comment">                                Functions code</span>
+<a name="l00056"></a>00056 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00066"></a>00066 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00073"></a>00073 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00074"></a>00074 <span class="keywordtype">int</span> sinfo_utl_cube_combine(
+<a name="l00075"></a>00075         cpl_parameterlist   *   parlist, 
+<a name="l00076"></a>00076         cpl_frameset        *   framelist)
+<a name="l00077"></a>00077 {
+<a name="l00078"></a>00078     cpl_parameter       *   param=NULL ;
+<a name="l00079"></a>00079     <span class="keyword">const</span> <span class="keywordtype">char</span>                *   name_o=NULL ;
+<a name="l00080"></a>00080     <span class="keyword">const</span> <span class="keywordtype">char</span>                *   name_i=NULL ;
+<a name="l00081"></a>00081     <span class="keyword">const</span> <span class="keywordtype">char</span>                *   name_m=NULL ;
+<a name="l00082"></a>00082    
+<a name="l00083"></a>00083     cpl_propertylist    *   plist=NULL ;
+<a name="l00084"></a>00084     cpl_image           *   image=NULL ;
+<a name="l00085"></a>00085     cpl_frame           *   product_frame=NULL;
+<a name="l00086"></a>00086     cpl_frame           *   prod_frm=NULL;
+<a name="l00087"></a>00087     cpl_frame           *   frame=NULL;
+<a name="l00088"></a>00088   
+<a name="l00089"></a>00089     <span class="keywordtype">int</span> z=0;
+<a name="l00090"></a>00090     <span class="keywordtype">int</span> z_min=0;
+<a name="l00091"></a>00091     <span class="keywordtype">int</span> z_max=0;
+<a name="l00092"></a>00092     <span class="keywordtype">int</span> z_siz=0;
+<a name="l00093"></a>00093     <span class="keywordtype">int</span> z_stp=100;
+<a name="l00094"></a>00094     <span class="keywordtype">int</span> xsize=0;
+<a name="l00095"></a>00095     <span class="keywordtype">int</span> ysize=0;
+<a name="l00096"></a>00096     <span class="keywordtype">int</span> scales_sky=0;
+<a name="l00097"></a>00097 
+<a name="l00098"></a>00098     <span class="keywordtype">int</span> i=0;
+<a name="l00099"></a>00099     <span class="keywordtype">int</span> j=0;
+<a name="l00100"></a>00100     <span class="keywordtype">int</span> n=0;
+<a name="l00101"></a>00101 
+<a name="l00102"></a>00102     <span class="keywordtype">int</span> size_x=0;
+<a name="l00103"></a>00103     <span class="keywordtype">int</span> size_y=0;
+<a name="l00104"></a>00104     cpl_image* j_img=NULL;
+<a name="l00105"></a>00105     cpl_image* m_img=NULL;
+<a name="l00106"></a>00106  
+<a name="l00107"></a>00107     cpl_imagelist ** cube_object=NULL;
+<a name="l00108"></a>00108     cpl_imagelist * cube_jitter=NULL;
+<a name="l00109"></a>00109     cpl_imagelist * cube_mask=NULL;
+<a name="l00110"></a>00110  
+<a name="l00111"></a>00111     <span class="keyword">const</span> <span class="keywordtype">char</span>**    files=NULL;
+<a name="l00112"></a>00112     <span class="keywordtype">int</span> nframes=0;
+<a name="l00113"></a>00113 
+<a name="l00114"></a>00114     <span class="keywordtype">double</span> * times=NULL;
+<a name="l00115"></a>00115     <span class="keywordtype">float</span> * offsetx=NULL;
+<a name="l00116"></a>00116     <span class="keywordtype">float</span> * offsety=NULL;
+<a name="l00117"></a>00117     <span class="keywordtype">float</span>  ref_offx=0;
+<a name="l00118"></a>00118     <span class="keywordtype">float</span>  ref_offy=0;
+<a name="l00119"></a>00119     <span class="keywordtype">float</span> tmpoffx=0;
+<a name="l00120"></a>00120     <span class="keywordtype">float</span> tmpoffy=0;
+<a name="l00121"></a>00121     <span class="keywordtype">double</span> kappa=2;
+<a name="l00122"></a>00122     <span class="keywordtype">int</span> ks_clip=0;
+<a name="l00123"></a>00123     <span class="keywordtype">int</span> min_size_x=9999;
+<a name="l00124"></a>00124     <span class="keywordtype">int</span> min_size_y=9999;
+<a name="l00125"></a>00125     <span class="keyword">const</span> <span class="keywordtype">char</span>* name=NULL;
+<a name="l00126"></a>00126 
+<a name="l00127"></a>00127  
+<a name="l00128"></a>00128     FILE* file_list=NULL;
+<a name="l00129"></a>00129     <span class="keywordtype">int</span> cnt=0;
+<a name="l00130"></a>00130     <span class="keywordtype">int</span> onp=0;
+<a name="l00131"></a>00131   
+<a name="l00132"></a>00132     <span class="comment">/* HOW TO RETRIEVE INPUT PARAMETERS */</span>
+<a name="l00133"></a>00133     <span class="comment">/* --stropt */</span>
+<a name="l00134"></a>00134     check_nomsg(param = cpl_parameterlist_find(parlist, 
+<a name="l00135"></a>00135                         <span class="stringliteral">"sinfoni.sinfo_utl_cube_combine.ks_clip"</span>));
+<a name="l00136"></a>00136     check_nomsg(ks_clip = cpl_parameter_get_bool(param));
+<a name="l00137"></a>00137 
+<a name="l00138"></a>00138     check_nomsg(param = cpl_parameterlist_find(parlist, 
+<a name="l00139"></a>00139                         <span class="stringliteral">"sinfoni.sinfo_utl_cube_combine.scale_sky"</span>));
+<a name="l00140"></a>00140     check_nomsg(scales_sky = cpl_parameter_get_bool(param));
+<a name="l00141"></a>00141 
+<a name="l00142"></a>00142 
+<a name="l00143"></a>00143     check_nomsg(param = cpl_parameterlist_find(parlist, 
+<a name="l00144"></a>00144                         <span class="stringliteral">"sinfoni.sinfo_utl_cube_combine.kappa"</span>));
+<a name="l00145"></a>00145     check_nomsg(kappa = cpl_parameter_get_double(param));
+<a name="l00146"></a>00146 
+<a name="l00147"></a>00147     check_nomsg(param = cpl_parameterlist_find(parlist, 
+<a name="l00148"></a>00148                         <span class="stringliteral">"sinfoni.sinfo_utl_cube_combine.name_i"</span>));
+<a name="l00149"></a>00149     check_nomsg(name_i = cpl_parameter_get_string(param));
+<a name="l00150"></a>00150 
+<a name="l00151"></a>00151     check_nomsg(param = cpl_parameterlist_find(parlist, 
+<a name="l00152"></a>00152                         <span class="stringliteral">"sinfoni.sinfo_utl_cube_combine.name_o"</span>));
+<a name="l00153"></a>00153     check_nomsg(name_o = cpl_parameter_get_string(param));
+<a name="l00154"></a>00154 
+<a name="l00155"></a>00155 
+<a name="l00156"></a>00156     <span class="comment">/* --doubleopt */</span>
+<a name="l00157"></a>00157     check_nomsg(param = cpl_parameterlist_find(parlist,
+<a name="l00158"></a>00158                         <span class="stringliteral">"sinfoni.sinfo_utl_cube_combine.xsize"</span>));
+<a name="l00159"></a>00159     check_nomsg(xsize = cpl_parameter_get_int(param));
+<a name="l00160"></a>00160 
+<a name="l00161"></a>00161     check_nomsg(param = cpl_parameterlist_find(parlist,
+<a name="l00162"></a>00162                         <span class="stringliteral">"sinfoni.sinfo_utl_cube_combine.ysize"</span>));
+<a name="l00163"></a>00163     check_nomsg(ysize = cpl_parameter_get_int(param));
+<a name="l00164"></a>00164 
+<a name="l00165"></a>00165   
+<a name="l00166"></a>00166   <span class="comment">/* Identify the RAW and CALIB frames in the input frameset */</span>
+<a name="l00167"></a>00167     check(sinfo_dfs_set_groups(framelist),
+<a name="l00168"></a>00168          <span class="stringliteral">"Cannot identify RAW and CALIB frames"</span>) ;
+<a name="l00169"></a>00169  
+<a name="l00170"></a>00170 
+<a name="l00171"></a>00171     <span class="comment">/* HOW TO ACCESS INPUT DATA */</span>
+<a name="l00172"></a>00172     n=cpl_frameset_get_size(framelist);
+<a name="l00173"></a>00173     <span class="keywordflow">if</span>(n<1) {
+<a name="l00174"></a>00174       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"Empty input frame list!"</span>);
+<a name="l00175"></a>00175       <span class="keywordflow">goto</span> cleanup ;
+<a name="l00176"></a>00176     }
+<a name="l00177"></a>00177     <span class="keywordflow">for</span> (i=0;i<n;i++) {
+<a name="l00178"></a>00178        frame=cpl_frameset_get_frame(framelist,i);
+<a name="l00179"></a>00179        cpl_frame_set_group(frame,CPL_FRAME_GROUP_RAW);
+<a name="l00180"></a>00180     }
+<a name="l00181"></a>00181 
+<a name="l00182"></a>00182    
+<a name="l00183"></a>00183 
+<a name="l00184"></a>00184     <span class="comment">/* Now performing the data reduction */</span>
+<a name="l00185"></a>00185     <span class="comment">/* Let's generate one image for the example */</span>
+<a name="l00186"></a>00186     
+<a name="l00187"></a>00187     <span class="keywordflow">if</span> ( NULL == (file_list = fopen (name_i, <span class="stringliteral">"r"</span> ) ) )
+<a name="l00188"></a>00188     {      
+<a name="l00189"></a>00189       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"cannot open %s\n"</span>, name_i) ;
+<a name="l00190"></a>00190       <span class="keywordflow">goto</span> cleanup ;
+<a name="l00191"></a>00191     }
+<a name="l00192"></a>00192  
+<a name="l00193"></a>00193     cnt = 0 ;
+<a name="l00194"></a>00194     <span class="keywordflow">while</span> ( fscanf( file_list, <span class="stringliteral">"%f %f"</span>,&tmpoffx, &tmpoffy) != EOF )
+<a name="l00195"></a>00195     {
+<a name="l00196"></a>00196       cnt ++ ;
+<a name="l00197"></a>00197     }
+<a name="l00198"></a>00198     fclose(file_list);
+<a name="l00199"></a>00199    
+<a name="l00200"></a>00200     nframes= cnt ;
+<a name="l00201"></a>00201     cknull(times = (<span class="keywordtype">double</span>*) cpl_calloc (nframes, <span class="keyword">sizeof</span> (<span class="keywordtype">double</span>)), 
+<a name="l00202"></a>00202            <span class="stringliteral">" could not allocate memory!"</span>) ;
+<a name="l00203"></a>00203  
+<a name="l00204"></a>00204     cknull(offsetx = (<span class="keywordtype">float</span>*) cpl_calloc (nframes, <span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)),
+<a name="l00205"></a>00205            <span class="stringliteral">" could not allocate memory!"</span>) ;
+<a name="l00206"></a>00206 
+<a name="l00207"></a>00207     cknull(offsety = (<span class="keywordtype">float</span>*) cpl_calloc (nframes, <span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)),
+<a name="l00208"></a>00208            <span class="stringliteral">" could not allocate memory!"</span>) ;
+<a name="l00209"></a>00209   
+<a name="l00210"></a>00210     files = (<span class="keyword">const</span> <span class="keywordtype">char</span>**) cpl_calloc(MAX_NAME_SIZE,<span class="keyword">sizeof</span>(<span class="keyword">const</span> <span class="keywordtype">char</span>*));
+<a name="l00211"></a>00211     <span class="keywordflow">if</span> ( NULL == (file_list = fopen (name_i, <span class="stringliteral">"r"</span> ) ) )
+<a name="l00212"></a>00212     {
+<a name="l00213"></a>00213       <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"cannot open %s\n"</span>, name_i) ;
+<a name="l00214"></a>00214       <span class="keywordflow">return</span> -1 ;
+<a name="l00215"></a>00215     }
+<a name="l00216"></a>00216 
+<a name="l00217"></a>00217 
+<a name="l00218"></a>00218     cnt=0;   
+<a name="l00219"></a>00219     <span class="keywordflow">while</span> ( fscanf( file_list, <span class="stringliteral">"%f %f"</span>,&tmpoffx,&tmpoffy ) != EOF ) {
+<a name="l00220"></a>00220       frame=cpl_frameset_get_frame(framelist,cnt);
+<a name="l00221"></a>00221       files[cnt]= cpl_frame_get_filename(frame);
+<a name="l00222"></a>00222       times[cnt]=sinfo_pfits_get_exptime(files[cnt]);
+<a name="l00223"></a>00223       offsetx[cnt]=tmpoffx;
+<a name="l00224"></a>00224       offsety[cnt]=tmpoffy;
+<a name="l00225"></a>00225       plist=cpl_propertylist_load(files[cnt],0);
+<a name="l00226"></a>00226       size_x=sinfo_pfits_get_naxis1(plist);
+<a name="l00227"></a>00227       size_y=sinfo_pfits_get_naxis2(plist);
+<a name="l00228"></a>00228       sinfo_free_propertylist(&plist);
+<a name="l00229"></a>00229       <span class="keywordflow">if</span>(size_x < min_size_x) min_size_x=size_x;
+<a name="l00230"></a>00230       <span class="keywordflow">if</span>(size_y < min_size_y) min_size_y=size_y;
+<a name="l00231"></a>00231       cnt ++ ;
+<a name="l00232"></a>00232     }
+<a name="l00233"></a>00233     sinfo_msg(<span class="stringliteral">"Min input cube size x=%d y=%d"</span>,min_size_x,min_size_y);
+<a name="l00234"></a>00234  
+<a name="l00235"></a>00235     nframes=cnt;
+<a name="l00236"></a>00236     fclose(file_list);
+<a name="l00237"></a>00237  
+<a name="l00238"></a>00238     ck0(sinfo_auto_size_cube(offsetx,offsety,nframes,
+<a name="l00239"></a>00239                               &ref_offx,&ref_offy,&size_x,&size_y),
+<a name="l00240"></a>00240          <span class="stringliteral">"Error resizing cube"</span>);
+<a name="l00241"></a>00241     sinfo_msg(<span class="stringliteral">"output ima size=%dx%d"</span>,size_x,size_y); 
+<a name="l00242"></a>00242     cknull(cube_object = cpl_calloc(nframes,<span class="keyword">sizeof</span>(cpl_imagelist*)),
+<a name="l00243"></a>00243        <span class="stringliteral">"could not allocate memory"</span>) ;
+<a name="l00244"></a>00244  
+<a name="l00245"></a>00245     <span class="keywordflow">for</span> (i=0;i<nframes;i++) {
+<a name="l00246"></a>00246       frame=cpl_frameset_get_frame(framelist,i);
+<a name="l00247"></a>00247       name=cpl_frame_get_filename(frame);
+<a name="l00248"></a>00248       check_nomsg(cube_object[i]=cpl_imagelist_load(name,CPL_TYPE_FLOAT,0));
+<a name="l00249"></a>00249       ck0(sinfo_new_assign_offset2(i,name,offsetx,offsety,
+<a name="l00250"></a>00250                                   ref_offx,ref_offy),
+<a name="l00251"></a>00251                                   <span class="stringliteral">"Error assigning offsets"</span>);
+<a name="l00252"></a>00252     }
+<a name="l00253"></a>00253     onp = cpl_imagelist_get_size(cube_object[0]);
+<a name="l00254"></a>00254 
+<a name="l00255"></a>00255 
+<a name="l00256"></a>00256     check(cube_jitter = cpl_imagelist_new(),<span class="stringliteral">"allocating new data cube object"</span>);
+<a name="l00257"></a>00257     check(cube_mask = cpl_imagelist_new(),<span class="stringliteral">"allocating new data cube mask"</span>);
+<a name="l00258"></a>00258 
+<a name="l00259"></a>00259     check(plist=cpl_propertylist_load(files[0],0),
+<a name="l00260"></a>00260       <span class="stringliteral">"Cannot read the FITS header"</span>) ;
+<a name="l00261"></a>00261 
+<a name="l00262"></a>00262    <span class="keywordflow">if</span>(scales_sky == 1) {
+<a name="l00263"></a>00263       sinfo_msg(<span class="stringliteral">"Subtract spatial sinfo_median to each cube plane"</span>);
+<a name="l00264"></a>00264       <span class="keywordflow">for</span>(n=0;n<nframes;n++) {
+<a name="l00265"></a>00265     sinfo_msg(<span class="stringliteral">"process cube %d\n"</span>,n);
+<a name="l00266"></a>00266     sinfo_new_sinfoni_correct_median_it(&(cube_object[n]));
+<a name="l00267"></a>00267       }
+<a name="l00268"></a>00268     }
+<a name="l00269"></a>00269 
+<a name="l00270"></a>00270    <span class="keywordflow">for</span>(z=0;z<onp;z+=z_stp) {
+<a name="l00271"></a>00271      z_siz=(z_stp < (onp-z)) ? z_stp : (onp-z);
+<a name="l00272"></a>00272      z_min=z;
+<a name="l00273"></a>00273      z_max=z_min+z_siz;
+<a name="l00274"></a>00274      sinfo_msg(<span class="stringliteral">"Coadding cubes: range [%4.4d,%4.4d) of 0-%d\n"</span>,
+<a name="l00275"></a>00275            z_min,z_max,onp);
+<a name="l00276"></a>00276 
+<a name="l00277"></a>00277      <span class="keywordflow">for</span>(j=z_min;j<z_max;j++) {
+<a name="l00278"></a>00278 
+<a name="l00279"></a>00279        check_nomsg(j_img=cpl_image_new(size_x,size_y,CPL_TYPE_FLOAT));
+<a name="l00280"></a>00280        check_nomsg(cpl_imagelist_set(cube_jitter,j_img,j));
+<a name="l00281"></a>00281        check_nomsg(m_img = cpl_image_new(size_x,size_y,CPL_TYPE_FLOAT));
+<a name="l00282"></a>00282        check_nomsg(cpl_imagelist_set(cube_mask,m_img,j));
+<a name="l00283"></a>00283      }
+<a name="l00284"></a>00284      <span class="keywordflow">if</span>(ks_clip == 1){
+<a name="l00285"></a>00285        sinfo_new_combine_jittered_cubes_thomas_range(cube_object,
+<a name="l00286"></a>00286                              cube_jitter,
+<a name="l00287"></a>00287                              cube_mask,
+<a name="l00288"></a>00288                              nframes,
+<a name="l00289"></a>00289                              offsetx,offsety,
+<a name="l00290"></a>00290                              times,
+<a name="l00291"></a>00291                              (<span class="keywordtype">char</span>*) <span class="stringliteral">"tanh"</span>,
+<a name="l00292"></a>00292                              z_min,
+<a name="l00293"></a>00293                              z_max,
+<a name="l00294"></a>00294                              kappa);
+<a name="l00295"></a>00295      } <span class="keywordflow">else</span> {
+<a name="l00296"></a>00296        sinfo_new_combine_jittered_cubes_range(cube_object, 
+<a name="l00297"></a>00297                           cube_jitter,
+<a name="l00298"></a>00298                           cube_mask,
+<a name="l00299"></a>00299                           nframes,
+<a name="l00300"></a>00300                           offsetx,
+<a name="l00301"></a>00301                           offsety,
+<a name="l00302"></a>00302                           times,
+<a name="l00303"></a>00303                           (<span class="keywordtype">char</span>*) <span class="stringliteral">"tanh"</span>,
+<a name="l00304"></a>00304                           z_min,
+<a name="l00305"></a>00305                           z_max) ;
+<a name="l00306"></a>00306      }
+<a name="l00307"></a>00307       
+<a name="l00308"></a>00308    }
+<a name="l00309"></a>00309    sinfo_new_convert_0_to_ZERO_for_cubes(cube_jitter) ; 
+<a name="l00310"></a>00310  
+<a name="l00311"></a>00311     name_m=<span class="stringliteral">"out_cube_mask.fits"</span>;
+<a name="l00312"></a>00312      <span class="comment">/* HOW TO SAVE A PRODUCT ON DISK  */</span>
+<a name="l00313"></a>00313 
+<a name="l00314"></a>00314     <span class="comment">/* Create product frame */</span>
+<a name="l00315"></a>00315     check_nomsg(product_frame = cpl_frame_new());
+<a name="l00316"></a>00316     check_nomsg(cpl_frame_set_filename(product_frame, name_o)) ;
+<a name="l00317"></a>00317     check_nomsg(cpl_frame_set_tag(product_frame, SI_UTL_CUBE_COMBINE_PROCUBE));
+<a name="l00318"></a>00318     check_nomsg(cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_IMAGE)) ;
+<a name="l00319"></a>00319     check_nomsg(cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT)) ;
+<a name="l00320"></a>00320     check_nomsg(cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL)) ;
+<a name="l00321"></a>00321       
+<a name="l00322"></a>00322     <span class="comment">/* Add DataFlow keywords */</span>
+<a name="l00323"></a>00323 <span class="preprocessor">#if defined CPL_VERSION_CODE && CPL_VERSION_CODE >= CPL_VERSION(4, 8, 0)  </span>
+<a name="l00324"></a>00324 <span class="preprocessor"></span>    check(cpl_dfs_setup_product_header(plist, product_frame, 
+<a name="l00325"></a>00325                                        framelist, parlist,
+<a name="l00326"></a>00326                                        <span class="stringliteral">"sinfo_utl_cube_combine"</span>, 
+<a name="l00327"></a>00327                                        <span class="stringliteral">"SINFONI"</span>, KEY_VALUE_HPRO_DID,NULL),
+<a name="l00328"></a>00328       <span class="stringliteral">"Problem in the product DFS-compliance"</span>) ;
+<a name="l00329"></a>00329 <span class="preprocessor">#else</span>
+<a name="l00330"></a>00330 <span class="preprocessor"></span>    check(cpl_dfs_setup_product_header(plist, product_frame, 
+<a name="l00331"></a>00331                                        framelist, parlist,
+<a name="l00332"></a>00332                                        <span class="stringliteral">"sinfo_utl_cube_combine"</span>,
+<a name="l00333"></a>00333                                        <span class="stringliteral">"SINFONI"</span>, KEY_VALUE_HPRO_DID),
+<a name="l00334"></a>00334       <span class="stringliteral">"Problem in the product DFS-compliance"</span>) ;
+<a name="l00335"></a>00335 <span class="preprocessor">#endif    </span>
+<a name="l00336"></a>00336 <span class="preprocessor"></span>    check(cpl_imagelist_save(cube_jitter, name_o, CPL_BPP_IEEE_FLOAT, plist,
+<a name="l00337"></a>00337                  CPL_IO_DEFAULT),<span class="stringliteral">"Could not save product"</span>);
+<a name="l00338"></a>00338     check_nomsg(cpl_frameset_insert(framelist, product_frame));
+<a name="l00339"></a>00339     
+<a name="l00340"></a>00340    
+<a name="l00341"></a>00341     check_nomsg(prod_frm = cpl_frame_new());
+<a name="l00342"></a>00342     check_nomsg(cpl_frame_set_filename(prod_frm, name_m)) ;
+<a name="l00343"></a>00343     check_nomsg(cpl_frame_set_tag(prod_frm, SI_UTL_CUBE_COMBINE_PROMASK)) ;
+<a name="l00344"></a>00344     check_nomsg(cpl_frame_set_type(prod_frm, CPL_FRAME_TYPE_IMAGE)) ;
+<a name="l00345"></a>00345     check_nomsg(cpl_frame_set_group(prod_frm, CPL_FRAME_GROUP_PRODUCT)) ;
+<a name="l00346"></a>00346     check_nomsg(cpl_frame_set_level(prod_frm, CPL_FRAME_LEVEL_FINAL)) ;
+<a name="l00347"></a>00347 
+<a name="l00348"></a>00348     check(cpl_imagelist_save(cube_mask, name_m, CPL_BPP_IEEE_FLOAT, plist,
+<a name="l00349"></a>00349                  CPL_IO_DEFAULT),<span class="stringliteral">"Could not save product"</span>);
+<a name="l00350"></a>00350     check_nomsg(cpl_frameset_insert(framelist, prod_frm));
+<a name="l00351"></a>00351     
+<a name="l00352"></a>00352  cleanup:
+<a name="l00353"></a>00353     sinfo_free_imagelist(&cube_jitter) ;
+<a name="l00354"></a>00354     sinfo_free_image(&image) ;
+<a name="l00355"></a>00355     sinfo_free_imagelist(&cube_mask) ;
+<a name="l00356"></a>00356 
+<a name="l00357"></a>00357 
+<a name="l00358"></a>00358     <span class="keywordflow">if</span>(cube_object != NULL) {
+<a name="l00359"></a>00359       <span class="keywordflow">for</span> (i=0;i< nframes;i++){
+<a name="l00360"></a>00360     sinfo_free_imagelist(&(cube_object[i]));      
+<a name="l00361"></a>00361       }
+<a name="l00362"></a>00362       sinfo_free_array_imagelist(&cube_object);
+<a name="l00363"></a>00363     }
+<a name="l00364"></a>00364     sinfo_free_propertylist(&plist);
+<a name="l00365"></a>00365     <span class="keywordflow">if</span>(files != NULL) {
+<a name="l00366"></a>00366       cpl_free(files);
+<a name="l00367"></a>00367       files=NULL;
+<a name="l00368"></a>00368     }
+<a name="l00369"></a>00369     sinfo_free_double(&times);
+<a name="l00370"></a>00370     sinfo_free_float(&offsetx);
+<a name="l00371"></a>00371     sinfo_free_float(&offsety);
+<a name="l00372"></a>00372  
+<a name="l00373"></a>00373     <span class="comment">/* Return */</span>
+<a name="l00374"></a>00374     <span class="keywordflow">if</span> (cpl_error_get_code()) {
+<a name="l00375"></a>00375         <span class="keywordflow">return</span> -1 ;
+<a name="l00376"></a>00376     }
+<a name="l00377"></a>00377     <span class="keywordflow">else</span> { 
+<a name="l00378"></a>00378         <span class="keywordflow">return</span> 0 ;
+<a name="l00379"></a>00379     }
+<a name="l00380"></a>00380 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfoni_2sinfo__utl__spectrum__divide__by__blackbody_8c_source.html b/html/sinfoni_2sinfo__utl__spectrum__divide__by__blackbody_8c_source.html
new file mode 100644
index 0000000..b6bb976
--- /dev/null
+++ b/html/sinfoni_2sinfo__utl__spectrum__divide__by__blackbody_8c_source.html
@@ -0,0 +1,162 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_utl_spectrum_divide_by_blackbody.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_utl_spectrum_divide_by_blackbody.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_utl_spectrum_divide_by_blackbody.c,v 1.8 2012/03/03 10:17:31 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the IIINSTRUMENT Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2012/03/03 10:17:31 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.8 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 
+<a name="l00029"></a>00029 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00030"></a>00030 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00031"></a>00031 <span class="preprocessor">#endif</span>
+<a name="l00032"></a>00032 <span class="preprocessor"></span><span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                                Includes</span>
+<a name="l00034"></a>00034 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 
+<a name="l00036"></a>00036 <span class="preprocessor">#include <string.h></span>
+<a name="l00037"></a>00037 <span class="preprocessor">#include "sinfo_utl_spectrum_divide_by_blackbody.h"</span>
+<a name="l00038"></a>00038 <span class="preprocessor">#include <sinfo_spectrum_ops.h></span>
+<a name="l00039"></a>00039 <span class="preprocessor">#include "sinfo_key_names.h"</span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include "sinfo_error.h"</span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include "sinfo_utils_wrappers.h"</span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00043"></a>00043 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00044"></a>00044 <span class="comment">                            Functions prototypes</span>
+<a name="l00045"></a>00045 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00046"></a>00046 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00047"></a>00047 <span class="comment">                            Static variables</span>
+<a name="l00048"></a>00048 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00049"></a>00049 
+<a name="l00058"></a>00058 <span class="comment">/*----------------------------------------------------------------------------</span>
+<a name="l00059"></a>00059 <span class="comment">                                Functions code</span>
+<a name="l00060"></a>00060 <span class="comment"> ----------------------------------------------------------------------------*/</span>
+<a name="l00061"></a>00061 
+<a name="l00062"></a>00062 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00069"></a>00069 <span class="comment">/*---------------------------------------------------------------------------*/</span>
+<a name="l00070"></a>00070 <span class="keywordtype">int</span> sinfo_utl_spectrum_divide_by_blackbody(
+<a name="l00071"></a>00071         cpl_parameterlist   *   parlist, 
+<a name="l00072"></a>00072         cpl_frameset        *   framelist)
+<a name="l00073"></a>00073 {
+<a name="l00074"></a>00074     cpl_parameter       *   param =NULL;
+<a name="l00075"></a>00075     <span class="keyword">const</span> <span class="keywordtype">char</span>          *   name_i =NULL;
+<a name="l00076"></a>00076     <span class="keyword">const</span> <span class="keywordtype">char</span>          *   name_o =NULL;
+<a name="l00077"></a>00077 
+<a name="l00078"></a>00078     <span class="keywordtype">double</span>                  temp=0 ;
+<a name="l00079"></a>00079 
+<a name="l00080"></a>00080     cpl_frame           *   frm_spct=NULL ;
+<a name="l00081"></a>00081 
+<a name="l00082"></a>00082     cpl_propertylist    *   plist=NULL ;
+<a name="l00083"></a>00083 
+<a name="l00084"></a>00084 
+<a name="l00085"></a>00085     cpl_frame           *   product_frame=NULL;
+<a name="l00086"></a>00086     cpl_image * bb_img=NULL;
+<a name="l00087"></a>00087     cpl_image * image_o=NULL;
+<a name="l00088"></a>00088     cpl_image * image_i=NULL;
+<a name="l00089"></a>00089 
+<a name="l00090"></a>00090     Vector*   bb=NULL;
+<a name="l00091"></a>00091     <span class="comment">/* double * ker=NULL; */</span>
+<a name="l00092"></a>00092 
+<a name="l00093"></a>00093     <span class="comment">/* HOW TO RETRIEVE INPUT PARAMETERS */</span>
+<a name="l00094"></a>00094     <span class="comment">/* --stropt */</span>
+<a name="l00095"></a>00095     name_o = <span class="stringliteral">"out_ima.fits"</span>;
+<a name="l00096"></a>00096 
+<a name="l00097"></a>00097     <span class="comment">/* --doubleopt */</span>
+<a name="l00098"></a>00098 
+<a name="l00099"></a>00099     check_nomsg(param = cpl_parameterlist_find(parlist,
+<a name="l00100"></a>00100                 <span class="stringliteral">"sinfoni.sinfo_utl_spectrum_divide_by_blackbody.temperature"</span>));
+<a name="l00101"></a>00101     check_nomsg(temp = cpl_parameter_get_double(param));
+<a name="l00102"></a>00102    
+<a name="l00103"></a>00103     <span class="comment">/* HOW TO ACCESS INPUT DATA */</span>
+<a name="l00104"></a>00104     check(frm_spct = cpl_frameset_find(framelist, 
+<a name="l00105"></a>00105                     SI_UTL_SPECTRUM_DIVIDE_BY_BLACKBODY_SPECTRUM),
+<a name="l00106"></a>00106                     <span class="stringliteral">"SOF does not have a file tagged as %s"</span>,
+<a name="l00107"></a>00107                     SI_UTL_SPECTRUM_DIVIDE_BY_BLACKBODY_SPECTRUM);
+<a name="l00108"></a>00108 
+<a name="l00109"></a>00109     check(plist=cpl_propertylist_load(cpl_frame_get_filename(frm_spct), 
+<a name="l00110"></a>00110                         0),<span class="stringliteral">"Cannot read the FITS header"</span>) ;
+<a name="l00111"></a>00111 
+<a name="l00112"></a>00112     <span class="comment">/* Now performing the data reduction */</span>
+<a name="l00113"></a>00113     <span class="comment">/* Let's generate one image for the example */</span>
+<a name="l00114"></a>00114     check_nomsg(name_i = cpl_frame_get_filename(frm_spct));
+<a name="l00115"></a>00115     check_nomsg(image_i= cpl_image_load((<span class="keywordtype">char</span>*)name_i, CPL_TYPE_FLOAT,0,0));  
+<a name="l00116"></a>00116     cknull_nomsg(bb= sinfo_new_blackbody_spectrum ((<span class="keywordtype">char</span>*)name_i, temp));
+<a name="l00117"></a>00117     cknull_nomsg(bb_img = sinfo_new_vector_to_image(bb));
+<a name="l00118"></a>00118     cknull_nomsg(image_o = sinfo_new_div_image_by_spectrum (image_i,bb_img));
+<a name="l00119"></a>00119     
+<a name="l00120"></a>00120     <span class="comment">/* HOW TO SAVE A PRODUCT ON DISK  */</span>
+<a name="l00121"></a>00121     <span class="comment">/* Set the file name */</span>
+<a name="l00122"></a>00122 
+<a name="l00123"></a>00123     <span class="comment">/* Create product frame */</span>
+<a name="l00124"></a>00124     check_nomsg(product_frame = cpl_frame_new());
+<a name="l00125"></a>00125     check_nomsg(cpl_frame_set_filename(product_frame, name_o)) ;
+<a name="l00126"></a>00126     check_nomsg(cpl_frame_set_tag(product_frame, 
+<a name="l00127"></a>00127                         SI_UTL_SPECTRUM_DIVIDE_BY_BLACKBODY_PROSPECTRUM));
+<a name="l00128"></a>00128     check_nomsg(cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_IMAGE));
+<a name="l00129"></a>00129     check_nomsg(cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT));
+<a name="l00130"></a>00130     check_nomsg(cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL));
+<a name="l00131"></a>00131 
+<a name="l00132"></a>00132     <span class="comment">/* Add DataFlow keywords */</span>
+<a name="l00133"></a>00133        <span class="comment">/*</span>
+<a name="l00134"></a>00134 <span class="comment">    check(cpl_dfs_setup_product_header(plist, product_frame, </span>
+<a name="l00135"></a>00135 <span class="comment">                                             framelist, parlist,</span>
+<a name="l00136"></a>00136 <span class="comment">            "sinfo_utl_spectrum_divide_by_blackbody", "SINFONI", </span>
+<a name="l00137"></a>00137 <span class="comment">                KEY_VALUE_HPRO_DID),"Problem in the product DFS-compliance") ;</span>
+<a name="l00138"></a>00138 <span class="comment">       */</span>
+<a name="l00139"></a>00139  
+<a name="l00140"></a>00140     <span class="comment">/* Save the file */</span>
+<a name="l00141"></a>00141     check(cpl_image_save(image_o, name_o, CPL_BPP_IEEE_FLOAT, plist,
+<a name="l00142"></a>00142                    CPL_IO_DEFAULT),<span class="stringliteral">"Could not save product"</span>);
+<a name="l00143"></a>00143 
+<a name="l00144"></a>00144     <span class="comment">/* Log the saved file in the input frameset */</span>
+<a name="l00145"></a>00145     check_nomsg(cpl_frameset_insert(framelist, product_frame));
+<a name="l00146"></a>00146 
+<a name="l00147"></a>00147  cleanup:
+<a name="l00148"></a>00148 
+<a name="l00149"></a>00149        sinfo_free_propertylist(&plist) ;
+<a name="l00150"></a>00150        sinfo_free_image(&image_i);
+<a name="l00151"></a>00151        sinfo_free_image(&image_o);
+<a name="l00152"></a>00152        sinfo_free_image(&bb_img);
+<a name="l00153"></a>00153      
+<a name="l00154"></a>00154 
+<a name="l00155"></a>00155     <span class="comment">/* Return */</span>
+<a name="l00156"></a>00156     <span class="keywordflow">if</span> (cpl_error_get_code()) 
+<a name="l00157"></a>00157         <span class="keywordflow">return</span> -1 ;
+<a name="l00158"></a>00158     <span class="keywordflow">else</span> 
+<a name="l00159"></a>00159         <span class="keywordflow">return</span> 0 ;
+<a name="l00160"></a>00160 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/sinfoni_2sinfo__utl__spectrum__wavelength__shift_8c_source.html b/html/sinfoni_2sinfo__utl__spectrum__wavelength__shift_8c_source.html
new file mode 100644
index 0000000..2ba38f8
--- /dev/null
+++ b/html/sinfoni_2sinfo__utl__spectrum__wavelength__shift_8c_source.html
@@ -0,0 +1,190 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>SINFONI Pipeline Reference Manual: sinfo_utl_spectrum_wavelength_shift.c Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.1 -->
+<h1>sinfo_utl_spectrum_wavelength_shift.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* $Id: sinfo_utl_spectrum_wavelength_shift.c,v 1.8 2012/03/03 10:17:31 amodigli Exp $</span>
+<a name="l00002"></a>00002 <span class="comment"> *</span>
+<a name="l00003"></a>00003 <span class="comment"> * This file is part of the IIINSTRUMENT Pipeline</span>
+<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002,2003 European Southern Observatory</span>
+<a name="l00005"></a>00005 <span class="comment"> *</span>
+<a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
+<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
+<a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span>
+<a name="l00010"></a>00010 <span class="comment"> *</span>
+<a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
+<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
+<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
+<a name="l00015"></a>00015 <span class="comment"> *</span>
+<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+<a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span>
+<a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
+<a name="l00019"></a>00019 <span class="comment"> */</span>
+<a name="l00020"></a>00020 
+<a name="l00021"></a>00021 <span class="comment">/*</span>
+<a name="l00022"></a>00022 <span class="comment"> * $Author: amodigli $</span>
+<a name="l00023"></a>00023 <span class="comment"> * $Date: 2012/03/03 10:17:31 $</span>
+<a name="l00024"></a>00024 <span class="comment"> * $Revision: 1.8 $</span>
+<a name="l00025"></a>00025 <span class="comment"> * $Name: sinfo-2_3_2 $</span>
+<a name="l00026"></a>00026 <span class="comment"> */</span>
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
+<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#  include <config.h></span>
+<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
+<a name="l00031"></a>00031 <span class="preprocessor"></span>
+<a name="l00032"></a>00032 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00033"></a>00033 <span class="comment">                                Includes</span>
+<a name="l00034"></a>00034 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00035"></a>00035 
+<a name="l00036"></a>00036 <span class="preprocessor">#include <string.h></span>
+<a name="l00037"></a>00037 
+<a name="l00038"></a>00038 <span class="preprocessor">#include "sinfo_utl_spectrum_wavelength_shift.h"</span>
+<a name="l00039"></a>00039 <span class="preprocessor">#include "sinfo_spectrum_ops.h"</span>
+<a name="l00040"></a>00040 <span class="preprocessor">#include "sinfo_shift_images.h"</span>
+<a name="l00041"></a>00041 <span class="preprocessor">#include "sinfo_key_names.h"</span>
+<a name="l00042"></a>00042 <span class="preprocessor">#include "sinfo_error.h"</span>
+<a name="l00043"></a>00043 <span class="preprocessor">#include "sinfo_utils_wrappers.h"</span>
+<a name="l00044"></a>00044 <span class="preprocessor">#include "sinfo_msg.h"</span>
+<a name="l00045"></a>00045 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00046"></a>00046 <span class="comment">                            Functions prototypes</span>
+<a name="l00047"></a>00047 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00048"></a>00048 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00049"></a>00049 <span class="comment">                            Static variables</span>
+<a name="l00050"></a>00050 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00051"></a>00051 
+<a name="l00060"></a>00060 <span class="comment">/*-----------------------------------------------------------------------------</span>
+<a name="l00061"></a>00061 <span class="comment">                                Functions code</span>
+<a name="l00062"></a>00062 <span class="comment"> -----------------------------------------------------------------------------*/</span>
+<a name="l00063"></a>00063 
+<a name="l00064"></a>00064 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00071"></a>00071 <span class="comment">/*----------------------------------------------------------------------------*/</span>
+<a name="l00072"></a>00072 <span class="keywordtype">int</span> sinfo_utl_spectrum_wavelength_shift(
+<a name="l00073"></a>00073         cpl_parameterlist   *   parlist, 
+<a name="l00074"></a>00074         cpl_frameset        *   framelist)
+<a name="l00075"></a>00075 {
+<a name="l00076"></a>00076     cpl_parameter       *   param =NULL;
+<a name="l00077"></a>00077     <span class="keyword">const</span> <span class="keywordtype">char</span>          *   method =NULL;
+<a name="l00078"></a>00078     <span class="keyword">const</span> <span class="keywordtype">char</span>          *   name_i =NULL;
+<a name="l00079"></a>00079     <span class="keyword">const</span> <span class="keywordtype">char</span>          *   name_o =NULL;
+<a name="l00080"></a>00080 
+<a name="l00081"></a>00081     <span class="keywordtype">double</span>                  shift=0 ;
+<a name="l00082"></a>00082 
+<a name="l00083"></a>00083     cpl_frame           *   frm_spct=NULL ;
+<a name="l00084"></a>00084 
+<a name="l00085"></a>00085     cpl_propertylist    *   plist=NULL ;
+<a name="l00086"></a>00086 
+<a name="l00087"></a>00087     cpl_frame           *   product_frame=NULL;
+<a name="l00088"></a>00088     cpl_image * image_o=NULL;
+<a name="l00089"></a>00089     cpl_image * image_i=NULL;
+<a name="l00090"></a>00090     cpl_image * image_s=NULL;
+<a name="l00091"></a>00091 
+<a name="l00092"></a>00092     <span class="keywordtype">double</span>* sub_shift=NULL;
+<a name="l00093"></a>00093     <span class="comment">/* double * ker=NULL; */</span>
+<a name="l00094"></a>00094 
+<a name="l00095"></a>00095     <span class="comment">/* HOW TO RETRIEVE INPUT PARAMETERS */</span>
+<a name="l00096"></a>00096     <span class="comment">/* --stropt */</span>
+<a name="l00097"></a>00097     name_o = <span class="stringliteral">"out_ima.fits"</span>;
+<a name="l00098"></a>00098  
+<a name="l00099"></a>00099     <span class="comment">/* --doubleopt */</span>
+<a name="l00100"></a>00100     check_nomsg(param = cpl_parameterlist_find(parlist, 
+<a name="l00101"></a>00101                                   <span class="stringliteral">"sinfoni.sinfo_utl_spectrum_arith.method"</span>));
+<a name="l00102"></a>00102     check_nomsg(method = cpl_parameter_get_string(param));
+<a name="l00103"></a>00103 
+<a name="l00104"></a>00104 
+<a name="l00105"></a>00105     check_nomsg(param = cpl_parameterlist_find(parlist,
+<a name="l00106"></a>00106                          <span class="stringliteral">"sinfoni.sinfo_utl_spectrum_wavelength_shift.shift"</span>));
+<a name="l00107"></a>00107     check_nomsg(shift = cpl_parameter_get_double(param));
+<a name="l00108"></a>00108   
+<a name="l00109"></a>00109    
+<a name="l00110"></a>00110     <span class="comment">/* HOW TO ACCESS INPUT DATA */</span>
+<a name="l00111"></a>00111     check(frm_spct = cpl_frameset_find(framelist, 
+<a name="l00112"></a>00112                                    SI_UTL_SPECTRUM_WAVELENGTH_SHIFT_SPECTRUM),
+<a name="l00113"></a>00113                                    <span class="stringliteral">"SOF does not have a file tagged as %s"</span>,
+<a name="l00114"></a>00114                                    SI_UTL_SPECTRUM_WAVELENGTH_SHIFT_SPECTRUM);
+<a name="l00115"></a>00115 
+<a name="l00116"></a>00116     check(plist=cpl_propertylist_load(cpl_frame_get_filename(frm_spct), 
+<a name="l00117"></a>00117                         0),<span class="stringliteral">"Cannot read the FITS header"</span>) ;
+<a name="l00118"></a>00118    <span class="comment">/* Now performing the data reduction */</span>
+<a name="l00119"></a>00119     <span class="comment">/* Let's generate one image for the example */</span>
+<a name="l00120"></a>00120     check_nomsg(name_i = cpl_frame_get_filename(frm_spct));
+<a name="l00121"></a>00121     check_nomsg(image_i= cpl_image_load ((<span class="keywordtype">char</span>*)name_i,CPL_TYPE_FLOAT,0,0));  
+<a name="l00122"></a>00122     sub_shift = sinfo_new_doublearray(1);
+<a name="l00123"></a>00123     sinfo_new_doublearray_set_value(sub_shift, 0., 0);
+<a name="l00124"></a>00124     cknull(image_s = sinfo_new_shift_image_in_spec (image_i, shift, sub_shift),
+<a name="l00125"></a>00125          <span class="stringliteral">"error in sinfo_new_shift_image_in_spec()"</span>);
+<a name="l00126"></a>00126 
+<a name="l00127"></a>00127     shift = sinfo_new_doublearray_get_value(sub_shift, 0);
+<a name="l00128"></a>00128  
+<a name="l00129"></a>00129     <span class="keywordflow">if</span> (strcmp(method,<span class="stringliteral">"S"</span>)==0) {
+<a name="l00130"></a>00130 
+<a name="l00131"></a>00131        cknull(image_o = sinfo_new_fine_shift_image_in_spec_cubic_spline (
+<a name="l00132"></a>00132                        image_s, shift ),
+<a name="l00133"></a>00133                        <span class="stringliteral">"error in fine_shift_image_in_spec_cubic_spline()"</span>);
+<a name="l00134"></a>00134 
+<a name="l00135"></a>00135        } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(method,<span class="stringliteral">"P"</span>)==0) {
+<a name="l00136"></a>00136      cknull(image_o = sinfo_new_fine_shift_image_in_spec_poly(
+<a name="l00137"></a>00137                             image_s,shift,2),
+<a name="l00138"></a>00138                             <span class="stringliteral">"error in sinfo_fineShiftImageInSpecPoly()"</span>);
+<a name="l00139"></a>00139       <span class="comment">/*</span>
+<a name="l00140"></a>00140 <span class="comment">       } else if (strcmp (method, "T")==0) {</span>
+<a name="l00141"></a>00141 <span class="comment">      ker = sinfo_new_generate_interpolation_kernel("tanh");</span>
+<a name="l00142"></a>00142 <span class="comment">          cknull(image_o = sinfo_new_shift_image ( image_s, 0, shift, ker ),</span>
+<a name="l00143"></a>00143 <span class="comment">              "error in sinfo_new_fine_shift_image_in_spec_poly()");</span>
+<a name="l00144"></a>00144 <span class="comment">      */</span>
+<a name="l00145"></a>00145           <span class="comment">/* sinfo_new_destroy_doublearray(ker); */</span>
+<a name="l00146"></a>00146        }  <span class="keywordflow">else</span> {
+<a name="l00147"></a>00147           <a class="code" href="group__sinfo__msg.html#ga207c781e45c0904f20faa13fdf08c789" title="Print an error message.">sinfo_msg_error</a>(<span class="stringliteral">"wrong method %s"</span>,method);
+<a name="l00148"></a>00148           <span class="keywordflow">goto</span> cleanup;
+<a name="l00149"></a>00149        }
+<a name="l00150"></a>00150     
+<a name="l00151"></a>00151     <span class="comment">/* HOW TO SAVE A PRODUCT ON DISK  */</span>
+<a name="l00152"></a>00152     <span class="comment">/* Set the file name */</span>
+<a name="l00153"></a>00153 
+<a name="l00154"></a>00154     <span class="comment">/* Create product frame */</span>
+<a name="l00155"></a>00155     check_nomsg(product_frame = cpl_frame_new());
+<a name="l00156"></a>00156     check_nomsg(cpl_frame_set_filename(product_frame, name_o)) ;
+<a name="l00157"></a>00157     check_nomsg(cpl_frame_set_tag(product_frame, 
+<a name="l00158"></a>00158                                 SI_UTL_SPECTRUM_WAVELENGTH_SHIFT_PROSPECTRUM)) ;
+<a name="l00159"></a>00159     check_nomsg(cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_IMAGE));
+<a name="l00160"></a>00160     check_nomsg(cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT)) ;
+<a name="l00161"></a>00161     check_nomsg(cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL)) ;
+<a name="l00162"></a>00162 
+<a name="l00163"></a>00163     <span class="comment">/* Add DataFlow keywords */</span>
+<a name="l00164"></a>00164     <span class="comment">/*</span>
+<a name="l00165"></a>00165 <span class="comment">    check(cpl_dfs_setup_product_header(plist, product_frame, </span>
+<a name="l00166"></a>00166 <span class="comment">                                      framelist, parlist,</span>
+<a name="l00167"></a>00167 <span class="comment">                                      "si_sinfo_utl_spectrum_wavelength_shift", </span>
+<a name="l00168"></a>00168 <span class="comment">                                      "SINFONI", KEY_VALUE_HPRO_DID),</span>
+<a name="l00169"></a>00169 <span class="comment">        "Problem in the product DFS-compliance") ;</span>
+<a name="l00170"></a>00170 <span class="comment">    */</span>
+<a name="l00171"></a>00171    
+<a name="l00172"></a>00172    
+<a name="l00173"></a>00173     <span class="comment">/* Save the file */</span>
+<a name="l00174"></a>00174     check(cpl_image_save(image_o, name_o, CPL_BPP_IEEE_FLOAT, plist,
+<a name="l00175"></a>00175              CPL_IO_DEFAULT),<span class="stringliteral">"Could not save product"</span>);
+<a name="l00176"></a>00176     check_nomsg(cpl_frameset_insert(framelist, product_frame));
+<a name="l00177"></a>00177  cleanup:
+<a name="l00178"></a>00178     sinfo_free_image(&image_i);
+<a name="l00179"></a>00179     sinfo_free_image(&image_o);
+<a name="l00180"></a>00180     sinfo_free_image(&image_s);
+<a name="l00181"></a>00181     <span class="keywordflow">if</span>(sub_shift != NULL) sinfo_new_destroy_doublearray(sub_shift);
+<a name="l00182"></a>00182     sinfo_free_propertylist(&plist);
+<a name="l00183"></a>00183 
+<a name="l00184"></a>00184     <span class="keywordflow">if</span> (cpl_error_get_code()) 
+<a name="l00185"></a>00185         <span class="keywordflow">return</span> -1 ;
+<a name="l00186"></a>00186     <span class="keywordflow">else</span> 
+<a name="l00187"></a>00187         <span class="keywordflow">return</span> 0 ;
+<a name="l00188"></a>00188 }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated on 22 May 2012 for SINFONI Pipeline Reference Manual by 
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
+</body>
+</html>
diff --git a/html/tab_b.gif b/html/tab_b.gif
new file mode 100644
index 0000000..0d62348
Binary files /dev/null and b/html/tab_b.gif differ
diff --git a/html/tab_l.gif b/html/tab_l.gif
new file mode 100644
index 0000000..9b1e633
Binary files /dev/null and b/html/tab_l.gif differ
diff --git a/html/tab_r.gif b/html/tab_r.gif
new file mode 100644
index 0000000..ce9dd9f
Binary files /dev/null and b/html/tab_r.gif differ
diff --git a/html/tabs.css b/html/tabs.css
new file mode 100644
index 0000000..a444163
--- /dev/null
+++ b/html/tabs.css
@@ -0,0 +1,105 @@
+/* tabs styles, based on http://www.alistapart.com/articles/slidingdoors */
+
+DIV.tabs
+{
+   float            : left;
+   width            : 100%;
+   background       : url("tab_b.gif") repeat-x bottom;
+   margin-bottom    : 4px;
+}
+
+DIV.tabs UL
+{
+   margin           : 0px;
+   padding-left     : 10px;
+   list-style       : none;
+}
+
+DIV.tabs LI, DIV.tabs FORM
+{
+   display          : inline;
+   margin           : 0px;
+   padding          : 0px;
+}
+
+DIV.tabs FORM
+{
+   float            : right;
+}
+
+DIV.tabs A
+{
+   float            : left;
+   background       : url("tab_r.gif") no-repeat right top;
+   border-bottom    : 1px solid #84B0C7;
+   font-size        : 80%;
+   font-weight      : bold;
+   text-decoration  : none;
+}
+
+DIV.tabs A:hover
+{
+   background-position: 100% -150px;
+}
+
+DIV.tabs A:link, DIV.tabs A:visited,
+DIV.tabs A:active, DIV.tabs A:hover
+{
+       color: #1A419D;
+}
+
+DIV.tabs SPAN
+{
+   float            : left;
+   display          : block;
+   background       : url("tab_l.gif") no-repeat left top;
+   padding          : 5px 9px;
+   white-space      : nowrap;
+}
+
+DIV.tabs #MSearchBox
+{
+   float            : right;
+   display          : inline;
+   font-size        : 1em;
+}
+
+DIV.tabs TD
+{
+   font-size        : 80%;
+   font-weight      : bold;
+   text-decoration  : none;
+}
+
+
+
+/* Commented Backslash Hack hides rule from IE5-Mac \*/
+DIV.tabs SPAN {float : none;}
+/* End IE5-Mac hack */
+
+DIV.tabs A:hover SPAN
+{
+   background-position: 0% -150px;
+}
+
+DIV.tabs LI.current A
+{
+   background-position: 100% -150px;
+   border-width     : 0px;
+}
+
+DIV.tabs LI.current SPAN
+{
+   background-position: 0% -150px;
+   padding-bottom   : 6px;
+}
+
+DIV.navpath
+{
+   background       : none;
+   border           : none;
+   border-bottom    : 1px solid #84B0C7;
+   text-align       : center;
+   margin           : 2px;
+   padding          : 2px;
+}
diff --git a/irplib/Makefile.am b/irplib/Makefile.am
new file mode 100644
index 0000000..2a5e64e
--- /dev/null
+++ b/irplib/Makefile.am
@@ -0,0 +1,87 @@
+## Process this file with automake to produce Makefile.in
+
+##   This file is part of the irplib package
+##   Copyright (C) 2002,2003 European Southern Observatory
+
+##   This library is free software; you can redistribute it and/or modify
+##   it under the terms of the GNU General Public License as published by
+##   the Free Software Foundation; either version 2 of the License, or
+##   (at your option) any later version.
+
+##   This program is distributed in the hope that it will be useful,
+##   but WITHOUT ANY WARRANTY; without even the implied warranty of
+##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+##   GNU General Public License for more details.
+
+##   You should have received a copy of the GNU General Public License
+##   along with this program; if not, write to the Free Software
+##   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+
+AUTOMAKE_OPTIONS = 1.8 foreign
+
+DISTCLEANFILES = *~
+
+SUBDIRS = . tests
+
+
+if MAINTAINER_MODE
+
+MAINTAINERCLEANFILES = Makefile.in
+
+endif
+
+INCLUDES = $(all_includes)
+
+noinst_HEADERS =    irplib_flat.h \
+                    irplib_calib.h \
+                    irplib_cat.h \
+                    irplib_distortion.h \
+                    irplib_framelist.h \
+                    irplib_utils.h \
+                    irplib_oddeven.h \
+                    irplib_slitpos.h \
+                    irplib_strehl.h \
+                    irplib_stdstar.h \
+                    irplib_plugin.h \
+                    irplib_polynomial.h \
+                    irplib_ppm.h \
+                    irplib_spectrum.h \
+                    irplib_match_cats.h \
+                    irplib_hist.h \
+                    irplib_wavecal.h \
+                    irplib_wavecal_impl.h \
+                    irplib_wcs.h \
+                    irplib_wlxcorr.h \
+                    irplib_mkmaster.h \
+                    irplib_ksigma_clip.h \
+                    irplib_ksigma_clip_body.h
+
+pkginclude_HEADERS = 
+
+noinst_LTLIBRARIES = libirplib.la
+
+libirplib_la_SOURCES =  irplib_flat.c \
+                        irplib_calib.c \
+                        irplib_cat.c \
+                        irplib_distortion.c \
+                        irplib_framelist.c \
+                        irplib_match_cats.c \
+                        irplib_utils.c \
+                        irplib_oddeven.c \
+                        irplib_slitpos.c \
+                        irplib_stdstar.c \
+                        irplib_plugin.c \
+                        irplib_polynomial.c \
+                        irplib_ppm.c \
+                        irplib_spectrum.c \
+                        irplib_strehl.c \
+                        irplib_hist.c \
+                        irplib_wavecal.c \
+                        irplib_wcs.c \
+                        irplib_wlxcorr.c \
+                        irplib_mkmaster.c \
+                        irplib_ksigma_clip.c 
+
+libirplib_la_LDFLAGS = $(CPL_LDFLAGS)
+libirplib_la_LIBADD = $(LIBCPLDFS) $(LIBCPLUI) $(LIBCPLDRS) $(LIBCPLCORE) 
+libirplib_la_DEPENDENCIES =
diff --git a/irplib/Makefile.in b/irplib/Makefile.in
new file mode 100644
index 0000000..19cb9dc
--- /dev/null
+++ b/irplib/Makefile.in
@@ -0,0 +1,799 @@
+# Makefile.in generated by automake 1.11 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009  Free Software Foundation,
+# Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+ at SET_MAKE@
+
+
+VPATH = @srcdir@
+pkgdatadir = $(datadir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkglibexecdir = $(libexecdir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
+target_triplet = @target@
+subdir = irplib
+DIST_COMMON = $(noinst_HEADERS) $(pkginclude_HEADERS) \
+	$(srcdir)/Makefile.am $(srcdir)/Makefile.in
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/m4macros/cpl.m4 \
+	$(top_srcdir)/m4macros/eso.m4 \
+	$(top_srcdir)/m4macros/libtool.m4 \
+	$(top_srcdir)/m4macros/ltoptions.m4 \
+	$(top_srcdir)/m4macros/ltsugar.m4 \
+	$(top_srcdir)/m4macros/ltversion.m4 \
+	$(top_srcdir)/m4macros/lt~obsolete.m4 \
+	$(top_srcdir)/m4macros/purify.m4 $(top_srcdir)/acinclude.m4 \
+	$(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+	$(ACLOCAL_M4)
+mkinstalldirs = $(install_sh) -d
+CONFIG_HEADER = $(top_builddir)/config.h
+CONFIG_CLEAN_FILES =
+CONFIG_CLEAN_VPATH_FILES =
+LTLIBRARIES = $(noinst_LTLIBRARIES)
+am__DEPENDENCIES_1 =
+am_libirplib_la_OBJECTS = irplib_flat.lo irplib_calib.lo irplib_cat.lo \
+	irplib_distortion.lo irplib_framelist.lo irplib_match_cats.lo \
+	irplib_utils.lo irplib_oddeven.lo irplib_slitpos.lo \
+	irplib_stdstar.lo irplib_plugin.lo irplib_polynomial.lo \
+	irplib_ppm.lo irplib_spectrum.lo irplib_strehl.lo \
+	irplib_hist.lo irplib_wavecal.lo irplib_wcs.lo \
+	irplib_wlxcorr.lo irplib_mkmaster.lo irplib_ksigma_clip.lo
+libirplib_la_OBJECTS = $(am_libirplib_la_OBJECTS)
+libirplib_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
+	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+	$(libirplib_la_LDFLAGS) $(LDFLAGS) -o $@
+DEFAULT_INCLUDES = -I. at am__isrc@ -I$(top_builddir)
+depcomp = $(SHELL) $(top_srcdir)/admin/depcomp
+am__depfiles_maybe = depfiles
+am__mv = mv -f
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+	--mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
+	$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+CCLD = $(CC)
+LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+	--mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
+	$(LDFLAGS) -o $@
+SOURCES = $(libirplib_la_SOURCES)
+DIST_SOURCES = $(libirplib_la_SOURCES)
+RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \
+	html-recursive info-recursive install-data-recursive \
+	install-dvi-recursive install-exec-recursive \
+	install-html-recursive install-info-recursive \
+	install-pdf-recursive install-ps-recursive install-recursive \
+	installcheck-recursive installdirs-recursive pdf-recursive \
+	ps-recursive uninstall-recursive
+am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
+am__vpath_adj = case $$p in \
+    $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
+    *) f=$$p;; \
+  esac;
+am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`;
+am__install_max = 40
+am__nobase_strip_setup = \
+  srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'`
+am__nobase_strip = \
+  for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||"
+am__nobase_list = $(am__nobase_strip_setup); \
+  for p in $$list; do echo "$$p $$p"; done | \
+  sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \
+  $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \
+    if (++n[$$2] == $(am__install_max)) \
+      { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \
+    END { for (dir in files) print dir, files[dir] }'
+am__base_list = \
+  sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
+  sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
+am__installdirs = "$(DESTDIR)$(pkgincludedir)"
+HEADERS = $(noinst_HEADERS) $(pkginclude_HEADERS)
+RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive	\
+  distclean-recursive maintainer-clean-recursive
+AM_RECURSIVE_TARGETS = $(RECURSIVE_TARGETS:-recursive=) \
+	$(RECURSIVE_CLEAN_TARGETS:-recursive=) tags TAGS ctags CTAGS \
+	distdir
+ETAGS = etags
+CTAGS = ctags
+DIST_SUBDIRS = $(SUBDIRS)
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+am__relativize = \
+  dir0=`pwd`; \
+  sed_first='s,^\([^/]*\)/.*$$,\1,'; \
+  sed_rest='s,^[^/]*/*,,'; \
+  sed_last='s,^.*/\([^/]*\)$$,\1,'; \
+  sed_butlast='s,/*[^/]*$$,,'; \
+  while test -n "$$dir1"; do \
+    first=`echo "$$dir1" | sed -e "$$sed_first"`; \
+    if test "$$first" != "."; then \
+      if test "$$first" = ".."; then \
+        dir2=`echo "$$dir0" | sed -e "$$sed_last"`/"$$dir2"; \
+        dir0=`echo "$$dir0" | sed -e "$$sed_butlast"`; \
+      else \
+        first2=`echo "$$dir2" | sed -e "$$sed_first"`; \
+        if test "$$first2" = "$$first"; then \
+          dir2=`echo "$$dir2" | sed -e "$$sed_rest"`; \
+        else \
+          dir2="../$$dir2"; \
+        fi; \
+        dir0="$$dir0"/"$$first"; \
+      fi; \
+    fi; \
+    dir1=`echo "$$dir1" | sed -e "$$sed_rest"`; \
+  done; \
+  reldir="$$dir2"
+ACLOCAL = @ACLOCAL@
+AMTAR = @AMTAR@
+AR = @AR@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CPL_INCLUDES = @CPL_INCLUDES@
+CPL_LDFLAGS = @CPL_LDFLAGS@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CX_INCLUDES = @CX_INCLUDES@
+CX_LDFLAGS = @CX_LDFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+DOXYGEN = @DOXYGEN@
+DSYMUTIL = @DSYMUTIL@
+DUMPBIN = @DUMPBIN@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+ESO_DEBUG_FLAGS = @ESO_DEBUG_FLAGS@
+EXEEXT = @EXEEXT@
+FGREP = @FGREP@
+GREP = @GREP@
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+IRPLIB_INCLUDES = @IRPLIB_INCLUDES@
+IRPLIB_LDFLAGS = @IRPLIB_LDFLAGS@
+LATEX = @LATEX@
+LD = @LD@
+LDFLAGS = @LDFLAGS@
+LIBCEXT = @LIBCEXT@
+LIBCPLCORE = @LIBCPLCORE@
+LIBCPLDFS = @LIBCPLDFS@
+LIBCPLDRS = @LIBCPLDRS@
+LIBCPLUI = @LIBCPLUI@
+LIBIRPLIB = @LIBIRPLIB@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LIBSINFONI = @LIBSINFONI@
+LIBTOOL = @LIBTOOL@
+LIBTOOL_DEPS = @LIBTOOL_DEPS@
+LIPO = @LIPO@
+LN_S = @LN_S@
+LTLIBOBJS = @LTLIBOBJS@
+LT_AGE = @LT_AGE@
+LT_CURRENT = @LT_CURRENT@
+LT_REVISION = @LT_REVISION@
+MAINT = @MAINT@
+MAKEINFO = @MAKEINFO@
+MKDIR_P = @MKDIR_P@
+NM = @NM@
+NMEDIT = @NMEDIT@
+OBJDUMP = @OBJDUMP@
+OBJEXT = @OBJEXT@
+OTOOL = @OTOOL@
+OTOOL64 = @OTOOL64@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+PURIFY_CMD = @PURIFY_CMD@
+RANLIB = @RANLIB@
+SED = @SED@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+SINFONI_BINARY_AGE = @SINFONI_BINARY_AGE@
+SINFONI_BINARY_VERSION = @SINFONI_BINARY_VERSION@
+SINFONI_INCLUDES = @SINFONI_INCLUDES@
+SINFONI_INTERFACE_AGE = @SINFONI_INTERFACE_AGE@
+SINFONI_LDFLAGS = @SINFONI_LDFLAGS@
+SINFONI_MAJOR_VERSION = @SINFONI_MAJOR_VERSION@
+SINFONI_MICRO_VERSION = @SINFONI_MICRO_VERSION@
+SINFONI_MINOR_VERSION = @SINFONI_MINOR_VERSION@
+SINFONI_VERSION = @SINFONI_VERSION@
+STRIP = @STRIP@
+VERSION = @VERSION@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
+all_includes = @all_includes@
+all_ldflags = @all_ldflags@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build = @build@
+build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
+builddir = @builddir@
+configdir = @configdir@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
+exec_prefix = @exec_prefix@
+host = @host@
+host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localedir = @localedir@
+localstatedir = @localstatedir@
+lt_ECHO = @lt_ECHO@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+pipedocsdir = @pipedocsdir@
+plugindir = @plugindir@
+prefix = @prefix@
+privatelibdir = @privatelibdir@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
+sysconfdir = @sysconfdir@
+target = @target@
+target_alias = @target_alias@
+target_cpu = @target_cpu@
+target_os = @target_os@
+target_vendor = @target_vendor@
+top_build_prefix = @top_build_prefix@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+AUTOMAKE_OPTIONS = 1.8 foreign
+DISTCLEANFILES = *~
+SUBDIRS = . tests
+ at MAINTAINER_MODE_TRUE@MAINTAINERCLEANFILES = Makefile.in
+INCLUDES = $(all_includes)
+noinst_HEADERS = irplib_flat.h \
+                    irplib_calib.h \
+                    irplib_cat.h \
+                    irplib_distortion.h \
+                    irplib_framelist.h \
+                    irplib_utils.h \
+                    irplib_oddeven.h \
+                    irplib_slitpos.h \
+                    irplib_strehl.h \
+                    irplib_stdstar.h \
+                    irplib_plugin.h \
+                    irplib_polynomial.h \
+                    irplib_ppm.h \
+                    irplib_spectrum.h \
+                    irplib_match_cats.h \
+                    irplib_hist.h \
+                    irplib_wavecal.h \
+                    irplib_wavecal_impl.h \
+                    irplib_wcs.h \
+                    irplib_wlxcorr.h \
+                    irplib_mkmaster.h \
+                    irplib_ksigma_clip.h \
+                    irplib_ksigma_clip_body.h
+
+pkginclude_HEADERS = 
+noinst_LTLIBRARIES = libirplib.la
+libirplib_la_SOURCES = irplib_flat.c \
+                        irplib_calib.c \
+                        irplib_cat.c \
+                        irplib_distortion.c \
+                        irplib_framelist.c \
+                        irplib_match_cats.c \
+                        irplib_utils.c \
+                        irplib_oddeven.c \
+                        irplib_slitpos.c \
+                        irplib_stdstar.c \
+                        irplib_plugin.c \
+                        irplib_polynomial.c \
+                        irplib_ppm.c \
+                        irplib_spectrum.c \
+                        irplib_strehl.c \
+                        irplib_hist.c \
+                        irplib_wavecal.c \
+                        irplib_wcs.c \
+                        irplib_wlxcorr.c \
+                        irplib_mkmaster.c \
+                        irplib_ksigma_clip.c 
+
+libirplib_la_LDFLAGS = $(CPL_LDFLAGS)
+libirplib_la_LIBADD = $(LIBCPLDFS) $(LIBCPLUI) $(LIBCPLDRS) $(LIBCPLCORE) 
+libirplib_la_DEPENDENCIES = 
+all: all-recursive
+
+.SUFFIXES:
+.SUFFIXES: .c .lo .o .obj
+$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am  $(am__configure_deps)
+	@for dep in $?; do \
+	  case '$(am__configure_deps)' in \
+	    *$$dep*) \
+	      ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+	        && { if test -f $@; then exit 0; else break; fi; }; \
+	      exit 1;; \
+	  esac; \
+	done; \
+	echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign irplib/Makefile'; \
+	$(am__cd) $(top_srcdir) && \
+	  $(AUTOMAKE) --foreign irplib/Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+	@case '$?' in \
+	  *config.status*) \
+	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+	  *) \
+	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
+	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+	esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(am__aclocal_m4_deps):
+
+clean-noinstLTLIBRARIES:
+	-test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES)
+	@list='$(noinst_LTLIBRARIES)'; for p in $$list; do \
+	  dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \
+	  test "$$dir" != "$$p" || dir=.; \
+	  echo "rm -f \"$${dir}/so_locations\""; \
+	  rm -f "$${dir}/so_locations"; \
+	done
+libirplib.la: $(libirplib_la_OBJECTS) $(libirplib_la_DEPENDENCIES) 
+	$(libirplib_la_LINK)  $(libirplib_la_OBJECTS) $(libirplib_la_LIBADD) $(LIBS)
+
+mostlyclean-compile:
+	-rm -f *.$(OBJEXT)
+
+distclean-compile:
+	-rm -f *.tab.c
+
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/irplib_calib.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/irplib_cat.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/irplib_distortion.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/irplib_flat.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/irplib_framelist.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/irplib_hist.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/irplib_ksigma_clip.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/irplib_match_cats.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/irplib_mkmaster.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/irplib_oddeven.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/irplib_plugin.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/irplib_polynomial.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/irplib_ppm.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/irplib_slitpos.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/irplib_spectrum.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/irplib_stdstar.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/irplib_strehl.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/irplib_utils.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/irplib_wavecal.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/irplib_wcs.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/irplib_wlxcorr.Plo at am__quote@
+
+.c.o:
+ at am__fastdepCC_TRUE@	$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+ at am__fastdepCC_TRUE@	$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCC_FALSE@	$(COMPILE) -c $<
+
+.c.obj:
+ at am__fastdepCC_TRUE@	$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
+ at am__fastdepCC_TRUE@	$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCC_FALSE@	$(COMPILE) -c `$(CYGPATH_W) '$<'`
+
+.c.lo:
+ at am__fastdepCC_TRUE@	$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+ at am__fastdepCC_TRUE@	$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCC_FALSE@	$(LTCOMPILE) -c -o $@ $<
+
+mostlyclean-libtool:
+	-rm -f *.lo
+
+clean-libtool:
+	-rm -rf .libs _libs
+install-pkgincludeHEADERS: $(pkginclude_HEADERS)
+	@$(NORMAL_INSTALL)
+	test -z "$(pkgincludedir)" || $(MKDIR_P) "$(DESTDIR)$(pkgincludedir)"
+	@list='$(pkginclude_HEADERS)'; test -n "$(pkgincludedir)" || list=; \
+	for p in $$list; do \
+	  if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
+	  echo "$$d$$p"; \
+	done | $(am__base_list) | \
+	while read files; do \
+	  echo " $(INSTALL_HEADER) $$files '$(DESTDIR)$(pkgincludedir)'"; \
+	  $(INSTALL_HEADER) $$files "$(DESTDIR)$(pkgincludedir)" || exit $$?; \
+	done
+
+uninstall-pkgincludeHEADERS:
+	@$(NORMAL_UNINSTALL)
+	@list='$(pkginclude_HEADERS)'; test -n "$(pkgincludedir)" || list=; \
+	files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
+	test -n "$$files" || exit 0; \
+	echo " ( cd '$(DESTDIR)$(pkgincludedir)' && rm -f" $$files ")"; \
+	cd "$(DESTDIR)$(pkgincludedir)" && rm -f $$files
+
+# This directory's subdirectories are mostly independent; you can cd
+# into them and run `make' without going through this Makefile.
+# To change the values of `make' variables: instead of editing Makefiles,
+# (1) if the variable is set in `config.status', edit `config.status'
+#     (which will cause the Makefiles to be regenerated when you run `make');
+# (2) otherwise, pass the desired values on the `make' command line.
+$(RECURSIVE_TARGETS):
+	@failcom='exit 1'; \
+	for f in x $$MAKEFLAGS; do \
+	  case $$f in \
+	    *=* | --[!k]*);; \
+	    *k*) failcom='fail=yes';; \
+	  esac; \
+	done; \
+	dot_seen=no; \
+	target=`echo $@ | sed s/-recursive//`; \
+	list='$(SUBDIRS)'; for subdir in $$list; do \
+	  echo "Making $$target in $$subdir"; \
+	  if test "$$subdir" = "."; then \
+	    dot_seen=yes; \
+	    local_target="$$target-am"; \
+	  else \
+	    local_target="$$target"; \
+	  fi; \
+	  ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
+	  || eval $$failcom; \
+	done; \
+	if test "$$dot_seen" = "no"; then \
+	  $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \
+	fi; test -z "$$fail"
+
+$(RECURSIVE_CLEAN_TARGETS):
+	@failcom='exit 1'; \
+	for f in x $$MAKEFLAGS; do \
+	  case $$f in \
+	    *=* | --[!k]*);; \
+	    *k*) failcom='fail=yes';; \
+	  esac; \
+	done; \
+	dot_seen=no; \
+	case "$@" in \
+	  distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \
+	  *) list='$(SUBDIRS)' ;; \
+	esac; \
+	rev=''; for subdir in $$list; do \
+	  if test "$$subdir" = "."; then :; else \
+	    rev="$$subdir $$rev"; \
+	  fi; \
+	done; \
+	rev="$$rev ."; \
+	target=`echo $@ | sed s/-recursive//`; \
+	for subdir in $$rev; do \
+	  echo "Making $$target in $$subdir"; \
+	  if test "$$subdir" = "."; then \
+	    local_target="$$target-am"; \
+	  else \
+	    local_target="$$target"; \
+	  fi; \
+	  ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
+	  || eval $$failcom; \
+	done && test -z "$$fail"
+tags-recursive:
+	list='$(SUBDIRS)'; for subdir in $$list; do \
+	  test "$$subdir" = . || ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) tags); \
+	done
+ctags-recursive:
+	list='$(SUBDIRS)'; for subdir in $$list; do \
+	  test "$$subdir" = . || ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) ctags); \
+	done
+
+ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
+	list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	mkid -fID $$unique
+tags: TAGS
+
+TAGS: tags-recursive $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
+		$(TAGS_FILES) $(LISP)
+	set x; \
+	here=`pwd`; \
+	if ($(ETAGS) --etags-include --version) >/dev/null 2>&1; then \
+	  include_option=--etags-include; \
+	  empty_fix=.; \
+	else \
+	  include_option=--include; \
+	  empty_fix=; \
+	fi; \
+	list='$(SUBDIRS)'; for subdir in $$list; do \
+	  if test "$$subdir" = .; then :; else \
+	    test ! -f $$subdir/TAGS || \
+	      set "$$@" "$$include_option=$$here/$$subdir/TAGS"; \
+	  fi; \
+	done; \
+	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	shift; \
+	if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
+	  test -n "$$unique" || unique=$$empty_fix; \
+	  if test $$# -gt 0; then \
+	    $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+	      "$$@" $$unique; \
+	  else \
+	    $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+	      $$unique; \
+	  fi; \
+	fi
+ctags: CTAGS
+CTAGS: ctags-recursive $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
+		$(TAGS_FILES) $(LISP)
+	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	test -z "$(CTAGS_ARGS)$$unique" \
+	  || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+	     $$unique
+
+GTAGS:
+	here=`$(am__cd) $(top_builddir) && pwd` \
+	  && $(am__cd) $(top_srcdir) \
+	  && gtags -i $(GTAGS_ARGS) "$$here"
+
+distclean-tags:
+	-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+
+distdir: $(DISTFILES)
+	@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+	topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+	list='$(DISTFILES)'; \
+	  dist_files=`for file in $$list; do echo $$file; done | \
+	  sed -e "s|^$$srcdirstrip/||;t" \
+	      -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+	case $$dist_files in \
+	  */*) $(MKDIR_P) `echo "$$dist_files" | \
+			   sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+			   sort -u` ;; \
+	esac; \
+	for file in $$dist_files; do \
+	  if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+	  if test -d $$d/$$file; then \
+	    dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+	    if test -d "$(distdir)/$$file"; then \
+	      find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+	    fi; \
+	    if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+	      cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
+	      find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+	    fi; \
+	    cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
+	  else \
+	    test -f "$(distdir)/$$file" \
+	    || cp -p $$d/$$file "$(distdir)/$$file" \
+	    || exit 1; \
+	  fi; \
+	done
+	@list='$(DIST_SUBDIRS)'; for subdir in $$list; do \
+	  if test "$$subdir" = .; then :; else \
+	    test -d "$(distdir)/$$subdir" \
+	    || $(MKDIR_P) "$(distdir)/$$subdir" \
+	    || exit 1; \
+	  fi; \
+	done
+	@list='$(DIST_SUBDIRS)'; for subdir in $$list; do \
+	  if test "$$subdir" = .; then :; else \
+	    dir1=$$subdir; dir2="$(distdir)/$$subdir"; \
+	    $(am__relativize); \
+	    new_distdir=$$reldir; \
+	    dir1=$$subdir; dir2="$(top_distdir)"; \
+	    $(am__relativize); \
+	    new_top_distdir=$$reldir; \
+	    echo " (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) top_distdir="$$new_top_distdir" distdir="$$new_distdir" \\"; \
+	    echo "     am__remove_distdir=: am__skip_length_check=: am__skip_mode_fix=: distdir)"; \
+	    ($(am__cd) $$subdir && \
+	      $(MAKE) $(AM_MAKEFLAGS) \
+	        top_distdir="$$new_top_distdir" \
+	        distdir="$$new_distdir" \
+		am__remove_distdir=: \
+		am__skip_length_check=: \
+		am__skip_mode_fix=: \
+	        distdir) \
+	      || exit 1; \
+	  fi; \
+	done
+check-am: all-am
+check: check-recursive
+all-am: Makefile $(LTLIBRARIES) $(HEADERS)
+installdirs: installdirs-recursive
+installdirs-am:
+	for dir in "$(DESTDIR)$(pkgincludedir)"; do \
+	  test -z "$$dir" || $(MKDIR_P) "$$dir"; \
+	done
+install: install-recursive
+install-exec: install-exec-recursive
+install-data: install-data-recursive
+uninstall: uninstall-recursive
+
+install-am: all-am
+	@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-recursive
+install-strip:
+	$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+	  install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+	  `test -z '$(STRIP)' || \
+	    echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+	-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+	-test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
+	-test -z "$(DISTCLEANFILES)" || rm -f $(DISTCLEANFILES)
+
+maintainer-clean-generic:
+	@echo "This command is intended for maintainers to use"
+	@echo "it deletes files that may require special tools to rebuild."
+	-test -z "$(MAINTAINERCLEANFILES)" || rm -f $(MAINTAINERCLEANFILES)
+clean: clean-recursive
+
+clean-am: clean-generic clean-libtool clean-noinstLTLIBRARIES \
+	mostlyclean-am
+
+distclean: distclean-recursive
+	-rm -rf ./$(DEPDIR)
+	-rm -f Makefile
+distclean-am: clean-am distclean-compile distclean-generic \
+	distclean-tags
+
+dvi: dvi-recursive
+
+dvi-am:
+
+html: html-recursive
+
+html-am:
+
+info: info-recursive
+
+info-am:
+
+install-data-am: install-pkgincludeHEADERS
+
+install-dvi: install-dvi-recursive
+
+install-dvi-am:
+
+install-exec-am:
+
+install-html: install-html-recursive
+
+install-html-am:
+
+install-info: install-info-recursive
+
+install-info-am:
+
+install-man:
+
+install-pdf: install-pdf-recursive
+
+install-pdf-am:
+
+install-ps: install-ps-recursive
+
+install-ps-am:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-recursive
+	-rm -rf ./$(DEPDIR)
+	-rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-recursive
+
+mostlyclean-am: mostlyclean-compile mostlyclean-generic \
+	mostlyclean-libtool
+
+pdf: pdf-recursive
+
+pdf-am:
+
+ps: ps-recursive
+
+ps-am:
+
+uninstall-am: uninstall-pkgincludeHEADERS
+
+.MAKE: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) ctags-recursive \
+	install-am install-strip tags-recursive
+
+.PHONY: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) CTAGS GTAGS \
+	all all-am check check-am clean clean-generic clean-libtool \
+	clean-noinstLTLIBRARIES ctags ctags-recursive distclean \
+	distclean-compile distclean-generic distclean-libtool \
+	distclean-tags distdir dvi dvi-am html html-am info info-am \
+	install install-am install-data install-data-am install-dvi \
+	install-dvi-am install-exec install-exec-am install-html \
+	install-html-am install-info install-info-am install-man \
+	install-pdf install-pdf-am install-pkgincludeHEADERS \
+	install-ps install-ps-am install-strip installcheck \
+	installcheck-am installdirs installdirs-am maintainer-clean \
+	maintainer-clean-generic mostlyclean mostlyclean-compile \
+	mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
+	tags tags-recursive uninstall uninstall-am \
+	uninstall-pkgincludeHEADERS
+
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/irplib/irplib_calib.c b/irplib/irplib_calib.c
new file mode 100644
index 0000000..35aef8c
--- /dev/null
+++ b/irplib/irplib_calib.c
@@ -0,0 +1,646 @@
+/* $Id: irplib_calib.c,v 1.17 2009/02/17 08:05:25 amodigli Exp $
+ *
+ * This file is part of the irplib package
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2009/02/17 08:05:25 $
+ * $Revision: 1.17 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+/*-----------------------------------------------------------------------------
+                                   Includes
+ -----------------------------------------------------------------------------*/
+
+#include <math.h>
+#include <cpl.h>
+
+#include "irplib_calib.h"
+
+static int  
+irplib_get_clean_mean_window(cpl_image* img, 
+                             const int llx, 
+                             const int lly, 
+                             const int urx, int ury, 
+                             const int kappa, 
+                             const int nclip, 
+                             double* clean_mean, 
+                             double* clean_stdev);
+
+static double irplib_pfits_get_dit(const cpl_propertylist * plist);
+static double irplib_pfits_get_exp_time(const cpl_propertylist* plist);
+/*----------------------------------------------------------------------------*/
+/**
+ * @defgroup irplib_calib   Functions for calibrations
+ */
+/*----------------------------------------------------------------------------*/
+
+/**@{*/
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    find out the character string associated to the DIT keyword
+            in a propertylist
+  @param    plist propertylist 
+  @return   dit value
+ */
+/*---------------------------------------------------------------------------*/
+static double irplib_pfits_get_dit(const cpl_propertylist * plist)
+{
+    return cpl_propertylist_get_double(plist,"ESO DET DIT");
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    find out the character string associated to the EXPTIME keyword
+  @param    plist propertylist
+  @return   keyword value
+ */
+/*---------------------------------------------------------------------------*/
+static double irplib_pfits_get_exp_time(const cpl_propertylist* plist)
+{
+  
+    return cpl_propertylist_get_double(plist,"EXPTIME");
+
+}
+
+
+/**
+  @brief    Get clean mean and stdev of an image over a window
+  @param    img input image
+  @param    llx input lower left x image's window coordinate
+  @param    lly input lower left y image's window coordinate
+  @param    urx input upper right y image's window coordinate
+  @param    ury input upper right y image's window coordinate
+  @param    kappa  input kappa of kappa-sigma clip
+  @param    nclip input max no of kappa-sigma clip iterations
+  @param    clean_mean output upper right y image's window coordinate
+  @param    clean_stdev output upper right y image's window coordinate
+  @return   pixel scale
+ */
+
+
+static int  
+irplib_get_clean_mean_window(cpl_image* img, 
+                             const int llx, 
+                             const int lly, 
+                             const int urx, int ury, 
+                             const int kappa, 
+                             const int nclip, 
+                             double* clean_mean, 
+                             double* clean_stdev)
+{
+
+
+  double mean=0;
+  double stdev=0;
+  double threshold=0;
+  double lo_cut=0;
+  double hi_cut=0;
+  cpl_mask* mask=NULL;
+  cpl_image* tmp=NULL;
+  cpl_stats* stats=NULL;
+  int i=0;
+  
+  tmp=cpl_image_extract(img,llx,lly,urx,ury);
+  cpl_image_accept_all(tmp);
+  for(i=0;i<nclip;i++) {
+   
+
+    cpl_stats_delete(stats);
+    stats = cpl_stats_new_from_image(tmp, CPL_STATS_MEAN | CPL_STATS_STDEV);
+    mean = cpl_stats_get_mean(stats);
+    stdev = cpl_stats_get_stdev(stats);
+
+    threshold=kappa*stdev;
+    lo_cut=mean-threshold;
+    hi_cut=mean+threshold;
+
+    cpl_image_accept_all(tmp);
+    mask=cpl_mask_threshold_image_create(tmp,lo_cut,hi_cut);
+
+    cpl_mask_not(mask);
+    cpl_image_reject_from_mask(tmp,mask);
+    cpl_mask_delete(mask);
+
+
+  }
+  *clean_mean=mean;
+  *clean_stdev=stdev;
+  cpl_image_delete(tmp);
+  cpl_stats_delete(stats);
+ 
+  return 0;
+
+
+}
+
+
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Computes the detector's gain
+  @param    son   the input frameset of linearity on-flat fields 
+  @param    sof   the input frameset of linearity off-flat fields 
+  @param    zone  pointer to an integer array with locations (llx,lly,urx,ury)
+                   of region where a clean mean and noise are computed 
+  @param    kappa  value of kappa in kappa-sigma clipping 
+  @param    nclip  number of kappa-sigma clipping iterations
+
+  @return   pointer to a table containing single gain evaluations
+  @note: 
+  #1 input frames need to have defined FITS keyword EXPTIME
+  #2 input frames need to have defined FITS keyword DIT
+ */
+/*---------------------------------------------------------------------------*/
+
+
+cpl_table* 
+irplib_compute_gain(
+                cpl_frameset* son, 
+                cpl_frameset* sof, 
+                int* zone,   
+                const int kappa,
+                const int nclip)
+{
+
+  cpl_frame*    frm=NULL;
+
+  cpl_image* img_on1=NULL;
+  cpl_image* img_on2=NULL;
+  cpl_image* img_on_dif=NULL;
+
+  cpl_image* img_of1=NULL;
+  cpl_image* img_of2=NULL;
+  cpl_image* img_of_dif=NULL;
+
+  cpl_table* res_tbl=NULL;
+  cpl_vector* dit_on=NULL;
+  cpl_vector* dit_of=NULL;
+  cpl_vector* exptime_on=NULL;
+  cpl_vector* exptime_of=NULL;
+  cpl_propertylist* plist=NULL;
+
+  int non=0;
+  int nof=0;
+  int nfr=0;
+  int llx;
+  int lly;
+  int urx;
+  int ury;
+
+  double avg_on1=0;
+  double avg_on2=0;
+  double avg_of1=0;
+  double avg_of2=0;
+  double avg_on_dif=0;
+  double avg_of_dif=0;
+  double std=0;
+
+  double sig_on_dif=0;
+  double sig_of_dif=0;
+  char* name=NULL;
+  int i=0;
+  int m=0;
+
+  double gain=0;
+  double dit_ref=0;
+  double dit_tmp=0;
+  double exptime_ref=0;
+  double exptime_tmp=0;
+
+ 
+  non = cpl_frameset_get_size(son);
+  nof = cpl_frameset_get_size(sof);
+  nfr = (non <= nof) ? non : nof;
+
+  dit_on=cpl_vector_new(nfr);
+  dit_of=cpl_vector_new(nfr);  
+  exptime_on=cpl_vector_new(nfr);
+  exptime_of=cpl_vector_new(nfr);
+
+  for(i=0;i<nfr;i++) {
+
+    frm=cpl_frameset_get_frame(son,i);
+    name=(char*)cpl_frame_get_filename(frm);
+    plist=cpl_propertylist_load(name,0);
+    dit_ref=irplib_pfits_get_dit(plist);
+    exptime_ref=(double)irplib_pfits_get_exp_time(plist);
+    cpl_propertylist_delete(plist);
+    cpl_vector_set(dit_on,i,dit_ref);
+    cpl_vector_set(exptime_on,i,exptime_ref);
+
+    frm=cpl_frameset_get_frame(sof,i);
+    name=(char*)cpl_frame_get_filename(frm);
+    plist=cpl_propertylist_load(name,0);
+    dit_ref=irplib_pfits_get_dit(plist);
+    exptime_ref=(double)irplib_pfits_get_exp_time(plist);
+    cpl_propertylist_delete(plist);
+    cpl_vector_set(dit_of,i,dit_ref);
+    cpl_vector_set(exptime_of,i,exptime_ref);
+
+  }
+
+
+  llx=zone[0];
+  lly=zone[1];
+  urx=zone[2];
+  ury=zone[3];
+
+
+
+  res_tbl=cpl_table_new(nfr);
+  cpl_table_new_column(res_tbl,"adu", CPL_TYPE_DOUBLE);
+  cpl_table_new_column(res_tbl,"gain", CPL_TYPE_DOUBLE);
+ 
+  for(i=0;i<nfr;i++) {
+    frm=cpl_frameset_get_frame(son,i);
+    name=(char*)cpl_frame_get_filename(frm);
+    img_on1=cpl_image_load(name,CPL_TYPE_FLOAT,0,0);
+
+    frm=cpl_frameset_get_frame(sof,i);
+    name=(char*)cpl_frame_get_filename(frm);
+    img_of1=cpl_image_load(name,CPL_TYPE_FLOAT,0,0);
+
+
+    dit_ref=cpl_vector_get(dit_on,i);
+    exptime_ref=cpl_vector_get(exptime_on,i);
+
+   
+    for(m=0;m<nfr; m++) {
+      if(m != i) {
+	frm=cpl_frameset_get_frame(son,m);
+	name=(char*)cpl_frame_get_filename(frm);
+	dit_tmp=cpl_vector_get(dit_on,m);
+	exptime_tmp=cpl_vector_get(exptime_on,m);
+	if(dit_tmp == dit_ref && exptime_tmp == exptime_ref) {
+	  img_on2=cpl_image_load(name,CPL_TYPE_FLOAT,0,0);
+	  frm=cpl_frameset_get_frame(sof,m);
+	  name=(char*)cpl_frame_get_filename(frm);
+	  img_of2=cpl_image_load(name,CPL_TYPE_FLOAT,0,0);
+
+	  img_on_dif=cpl_image_subtract_create(img_on1,img_on2);
+	  img_of_dif=cpl_image_subtract_create(img_of1,img_of2);
+	  
+	  irplib_get_clean_mean_window(img_on1,llx,lly,urx,ury,kappa,
+                                      nclip,&avg_on1,&std);
+	  irplib_get_clean_mean_window(img_on2,llx,lly,urx,ury,kappa,
+                                      nclip,&avg_on2,&std);
+	  irplib_get_clean_mean_window(img_of1,llx,lly,urx,ury,kappa,
+                                      nclip,&avg_of1,&std);
+	  irplib_get_clean_mean_window(img_of2,llx,lly,urx,ury,kappa,
+                                      nclip,&avg_of2,&std);
+	  irplib_get_clean_mean_window(img_on_dif,llx,lly,urx,ury,kappa,
+                                      nclip,&avg_on_dif,&sig_on_dif);
+	  irplib_get_clean_mean_window(img_of_dif,llx,lly,urx,ury,kappa,
+                                      nclip,&avg_of_dif,&sig_of_dif);
+
+	  cpl_image_delete(img_on2);
+	  cpl_image_delete(img_of2);
+	  cpl_image_delete(img_on_dif);
+	  cpl_image_delete(img_of_dif);
+
+          gain=((avg_on1+avg_on2)-(avg_of1+avg_of2))/
+               ((sig_on_dif*sig_on_dif)-(sig_of_dif*sig_of_dif));
+
+          cpl_table_set_double(res_tbl,"gain",m,gain);
+          cpl_table_set_double(res_tbl,"adu",m,
+                               ((avg_on1+avg_on2)/2-(avg_of1+avg_of2)/2));
+
+	}
+      }
+    }
+    cpl_image_delete(img_on1);
+    cpl_image_delete(img_of1);
+  }
+  
+
+  cpl_vector_delete(dit_on);
+  cpl_vector_delete(dit_of);
+  cpl_vector_delete(exptime_on);
+  cpl_vector_delete(exptime_of);
+
+  return res_tbl;
+
+}
+
+/* --------------------------------------------------------------------------*/
+/**
+  @brief    Computes the detector's linearity
+  @param    son    the input frameset of linearity on flat fields 
+  @param    sof    the input frameset of linearity off flat fields 
+  @return   pointer to a table containing linearity evaluations
+  @note: 
+  #2 input frames need to have defined FITS keyword EXPTIME
+  #3 input frames need to have defined FITS keyword DIT
+ */
+/*---------------------------------------------------------------------------*/
+
+
+cpl_table* irplib_compute_linearity(cpl_frameset* son, cpl_frameset* sof)
+{
+
+
+  cpl_frame*    frm=NULL;
+
+  int* status=0;
+  int non=0;
+  int nof=0;
+  int nfr=0;
+  int i=0;
+  double med_on=0;
+  double avg_on=0;
+  double med_of=0;
+  double avg_of=0;
+  double med_dit=0;
+  double avg_dit=0;
+
+  double med=0;
+  double avg=0;
+
+  char* name=NULL;
+  cpl_image* img=NULL;
+  cpl_vector* vec_adl=NULL;
+  cpl_vector* vec_dit=NULL;
+  cpl_vector* vec_avg=NULL;
+  cpl_vector* vec_med=NULL;
+  cpl_vector* vec_avg_dit=NULL;
+  cpl_vector* vec_med_dit=NULL;
+  cpl_propertylist* plist=NULL;
+
+  double dit=0;
+  cpl_table* lin_tbl=NULL;
+
+ 
+  non = cpl_frameset_get_size(son);
+  nof = cpl_frameset_get_size(sof);
+  nfr = (non <= nof) ? non : nof;
+
+  lin_tbl=cpl_table_new(nfr);
+  cpl_table_new_column(lin_tbl,"med", CPL_TYPE_DOUBLE);
+  cpl_table_new_column(lin_tbl,"avg", CPL_TYPE_DOUBLE);
+  cpl_table_new_column(lin_tbl,"med_dit", CPL_TYPE_DOUBLE);
+  cpl_table_new_column(lin_tbl,"avg_dit", CPL_TYPE_DOUBLE);
+  cpl_table_new_column(lin_tbl,"dit", CPL_TYPE_DOUBLE);
+  vec_med=cpl_vector_new(nfr);
+  vec_avg=cpl_vector_new(nfr);
+  vec_med_dit=cpl_vector_new(nfr);
+  vec_avg_dit=cpl_vector_new(nfr);
+  vec_dit=cpl_vector_new(nfr);
+  vec_adl=cpl_vector_new(nfr);
+  for(i=0;i<nfr;i++) {
+    frm=cpl_frameset_get_frame(son,i);
+    name=(char*)cpl_frame_get_filename(frm);
+    img=cpl_image_load(name,CPL_TYPE_FLOAT,0,0);
+    med_on=cpl_image_get_median(img);
+    avg_on=cpl_image_get_mean(img);
+    cpl_image_delete(img);
+
+    frm=cpl_frameset_get_frame(sof,i);
+    name=(char*)cpl_frame_get_filename(frm);
+    img=cpl_image_load(name,CPL_TYPE_FLOAT,0,0);
+    med_of=cpl_image_get_median(img);
+    avg_of=cpl_image_get_mean(img);
+    cpl_image_delete(img);
+    med=med_on-med_of;
+    avg=avg_on-avg_of;
+    plist=cpl_propertylist_load(name,0);
+    dit=(double)irplib_pfits_get_dit(plist);
+    cpl_propertylist_delete(plist);
+    avg_dit=avg/dit;
+    med_dit=med/dit;
+
+    cpl_vector_set(vec_dit,i,dit);
+    cpl_vector_set(vec_avg,i,avg);
+    cpl_vector_set(vec_med,i,med);
+    cpl_vector_set(vec_avg_dit,i,avg_dit);
+    cpl_vector_set(vec_med_dit,i,med_dit);
+
+
+    cpl_table_set_double(lin_tbl,"dit",i,dit);
+    cpl_table_set_double(lin_tbl,"med",i,med);
+    cpl_table_set_double(lin_tbl,"avg",i,avg);
+    cpl_table_set_double(lin_tbl,"med_dit",i,med_dit);
+    cpl_table_set_double(lin_tbl,"avg_dit",i,avg_dit);
+
+  }
+  cpl_table_new_column(lin_tbl,"adl", CPL_TYPE_DOUBLE);
+  med_dit=cpl_vector_get_mean(vec_med_dit);
+  avg_dit=cpl_vector_get_mean(vec_avg_dit);
+
+  for(i=0;i<nfr;i++) {
+    dit = cpl_table_get_double(lin_tbl,"dit",i,status);
+    cpl_vector_set(vec_adl,i,dit*med_dit);
+    cpl_table_set_double(lin_tbl,"adl",i,dit*med_dit);
+  }
+ 
+  
+  cpl_vector_delete(vec_dit);
+  cpl_vector_delete(vec_adl);
+  cpl_vector_delete(vec_avg);
+  cpl_vector_delete(vec_med);
+  cpl_vector_delete(vec_avg_dit);
+  cpl_vector_delete(vec_med_dit);
+
+
+  return lin_tbl;
+
+}
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Apply the detector linearity correction
+  @param    ilist   the input image list
+  @param    detlin_a    the a coeffs
+  @param    detlin_b    the b coeffs
+  @param    detlin_c    the c coeffs
+  @return   0 if everything is ok, -1 otherwise
+ */
+/*----------------------------------------------------------------------------*/
+int irplib_detlin_correct(
+        cpl_imagelist       *   ilist,
+        const char          *   detlin_a,
+        const char          *   detlin_b,
+        const char          *   detlin_c)
+{
+    cpl_image       *   ima ;
+    cpl_image       *   imb ;
+    cpl_image       *   imc ;
+    float           *   pima ;
+    float           *   pimb ;
+    float           *   pimc ;
+    float           *   pdata ;
+    int                 nx, ny, ni ; 
+    double              coeff_1, coeff_2, val ;
+    int                 i, j ;
+
+    /* Test entries */
+    if (!ilist || !detlin_a || !detlin_b || !detlin_c) return -1 ;
+    
+    /* Load the 3 coeffs images */
+    ima = cpl_image_load(detlin_a, CPL_TYPE_FLOAT, 0, 0) ;
+    imb = cpl_image_load(detlin_b, CPL_TYPE_FLOAT, 0, 0) ;
+    imc = cpl_image_load(detlin_c, CPL_TYPE_FLOAT, 0, 0) ;
+    if (!ima || !imb || !imc) {
+        cpl_msg_error(cpl_func, "Cannot load the detlin images") ;
+        if (ima) cpl_image_delete(ima) ;
+        if (imb) cpl_image_delete(imb) ;
+        if (imc) cpl_image_delete(imc) ;
+        return -1 ;
+    }
+    pima = cpl_image_get_data_float(ima) ;
+    pimb = cpl_image_get_data_float(imb) ;
+    pimc = cpl_image_get_data_float(imc) ;
+    
+    /* Test sizes */
+    nx = cpl_image_get_size_x(cpl_imagelist_get(ilist, 0)) ;
+    ny = cpl_image_get_size_y(cpl_imagelist_get(ilist, 0)) ;
+    ni = cpl_imagelist_get_size(ilist) ;
+    if ((cpl_image_get_size_x(ima) != nx) ||
+            (cpl_image_get_size_x(imb) != nx) ||
+            (cpl_image_get_size_x(imc) != nx) ||
+            (cpl_image_get_size_y(ima) != ny) ||
+            (cpl_image_get_size_y(imb) != ny) ||
+            (cpl_image_get_size_y(imc) != ny)) {
+        cpl_msg_error(cpl_func, "Incompatible sizes") ;
+        cpl_image_delete(ima) ;
+        cpl_image_delete(imb) ;
+        cpl_image_delete(imc) ;
+        return -1 ;
+    }
+    
+    /* Loop on pixels */
+    for (i=0 ; i<nx*ny ; i++) {
+        /* Compute the coefficients */
+        if (fabs(pima[i]) < 1e-30) {
+            coeff_1 = coeff_2 = (double)0.0 ;
+        } else {
+            coeff_1 = (double)pimb[i] / (double)pima[i] ;
+            coeff_2 = (double)pimc[i] / (double)pima[i] ;
+        }
+        /* Correct this pixel in each plane */
+        for (j=0 ; j<ni ; j++) {
+            pdata = cpl_image_get_data_float(cpl_imagelist_get(ilist, j)) ;
+            val = (double)pdata[i] ;
+            pdata[i]=(float)(val+coeff_1*val*val+coeff_2*val*val*val) ;
+        }
+    }
+    /* Free and return */
+    cpl_image_delete(ima) ;
+    cpl_image_delete(imb) ;
+    cpl_image_delete(imc) ;
+    return 0 ;
+}
+ 
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Apply the calibration to the frames
+  @param    ilist   the input image list
+  @param    flat    the flat field
+  @param    dark    the dark
+  @param    bpm     the bad pixels map
+  @return   0 if everything is ok, -1 otherwise
+ */
+/*----------------------------------------------------------------------------*/
+int irplib_flat_dark_bpm_calib(
+        cpl_imagelist       *   ilist,
+        const char          *   flat,
+        const char          *   dark,
+        const char          *   bpm)
+{
+    cpl_image       *   dark_image ;
+    cpl_image       *   flat_image ;
+    cpl_mask        *   bpm_im_bin ;
+    cpl_image       *   bpm_im_int ;
+    int                 i ;
+
+    /* Test entries */
+    if (ilist == NULL) return -1 ;
+
+    /* Dark correction */
+    if (dark != NULL) {
+        cpl_msg_info(cpl_func, "Subtract the dark to the images") ;
+        /* Load the dark image */
+        if ((dark_image = cpl_image_load(dark, CPL_TYPE_FLOAT, 0, 0)) == NULL) {
+            cpl_msg_error(cpl_func, "Cannot load the dark %s", dark) ;
+            return -1 ;
+        }
+        /* Apply the dark correction to the images */
+        if (cpl_imagelist_subtract_image(ilist, dark_image)!=CPL_ERROR_NONE) {
+            cpl_msg_error(cpl_func, "Cannot apply the dark to the images") ;
+            cpl_image_delete(dark_image) ;
+            return -1 ;
+        }
+        cpl_image_delete(dark_image) ;
+    }
+
+    /* Flat-field correction */
+    if (flat != NULL) {
+        cpl_msg_info(cpl_func, "Divide the images by the flatfield") ;
+        /* Load the flat image */
+        if ((flat_image = cpl_image_load(flat, CPL_TYPE_FLOAT, 0, 0)) == NULL) {
+            cpl_msg_error(cpl_func, "Cannot load the flat field %s", flat) ;
+            return -1 ;
+        }
+        /* Apply the flatfield correction to the images */
+        if (cpl_imagelist_divide_image(ilist, flat_image)!=CPL_ERROR_NONE) {
+            cpl_msg_error(cpl_func, "Cannot apply the flatfield to the images") ;
+            cpl_image_delete(flat_image) ;
+            return -1 ;
+        }
+        cpl_image_delete(flat_image) ;
+    }
+
+    /* Correct the bad pixels if requested */
+    if (bpm != NULL) {
+        cpl_msg_info(cpl_func, "Correct the bad pixels in the images") ;
+         /* Load the bad pixels image */
+        if ((bpm_im_int = cpl_image_load(bpm, CPL_TYPE_INT, 0, 0)) == NULL) {
+            cpl_msg_error(cpl_func, "Cannot load the bad pixel map %s", bpm) ;
+            return -1 ;
+        }
+        /* Convert the map from integer to binary */
+        bpm_im_bin = cpl_mask_threshold_image_create(bpm_im_int, -0.5, 0.5) ;
+        cpl_mask_not(bpm_im_bin) ;
+        cpl_image_delete(bpm_im_int) ;
+        /* Apply the bad pixels cleaning */
+        for (i=0 ; i<cpl_imagelist_get_size(ilist) ; i++) {
+            cpl_image_reject_from_mask(cpl_imagelist_get(ilist, i), bpm_im_bin);
+            if (cpl_detector_interpolate_rejected(
+                        cpl_imagelist_get(ilist, i)) != CPL_ERROR_NONE) {
+                cpl_msg_error(cpl_func, "Cannot clean the bad pixels in obj %d",
+                        i+1);
+                cpl_mask_delete(bpm_im_bin) ;
+                return -1 ;
+            }
+        }
+        cpl_mask_delete(bpm_im_bin) ;
+    }
+
+    /* Return */
+    return 0 ;
+}
+
+/**@}*/
+
diff --git a/irplib/irplib_calib.h b/irplib/irplib_calib.h
new file mode 100644
index 0000000..a05d5e9
--- /dev/null
+++ b/irplib/irplib_calib.h
@@ -0,0 +1,49 @@
+/* $Id: irplib_calib.h,v 1.8 2007/02/12 10:34:51 amodigli Exp $
+ *
+ * This file is part of the irplib package
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2007/02/12 10:34:51 $
+ * $Revision: 1.8 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifndef IRPLIB_CALIB_H
+#define IRPLIB_CALIB_H
+
+/*-----------------------------------------------------------------------------
+                                   Includes
+ -----------------------------------------------------------------------------*/
+
+#include <cpl.h>
+cpl_table*
+irplib_compute_gain(
+                cpl_frameset* son, 
+                cpl_frameset* sof, 
+                int* zone1, 
+                const int kappa1,
+                const int nclip1);
+cpl_table* irplib_compute_linearity(cpl_frameset* son, cpl_frameset* sof);
+int irplib_flat_dark_bpm_calib(cpl_imagelist *, const char *, const char *,
+                               const char *);
+int irplib_detlin_correct(cpl_imagelist *, const char *, const char *,
+                          const char *);
+
+#endif
diff --git a/irplib/irplib_cat.c b/irplib/irplib_cat.c
new file mode 100644
index 0000000..39300a2
--- /dev/null
+++ b/irplib/irplib_cat.c
@@ -0,0 +1,469 @@
+/* $Id: irplib_cat.c,v 1.10 2009/12/01 12:34:25 cgarcia Exp $
+ *
+ * This file is part of the irplib package
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: cgarcia $
+ * $Date: 2009/12/01 12:34:25 $
+ * $Revision: 1.10 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+/*-----------------------------------------------------------------------------
+                                   Includes
+ -----------------------------------------------------------------------------*/
+
+#include <libgen.h>
+#include <math.h>
+#include <cpl.h>
+
+#include "irplib_cat.h"
+#include "irplib_wcs.h"
+
+#define FILENAME_SZBUF 1024
+
+/*----------------------------------------------------------------------------*/
+/**
+ * @defgroup irplib_cat   Functions for accessing catalogues
+ */
+/*----------------------------------------------------------------------------*/
+
+/**@{*/
+
+/*---------------------------------------------------------------------------*/
+/**
+ * @brief
+ *       Find the name of the standard catalogue being used and its location
+ * @param index
+ *       The frame for the index FITS file
+ * @param catpath
+ *       The full path to the catalgoue FITS files
+ * @param catname
+ *       The name of the catalogue
+ * @return
+ *   CPL_ERROR_NONE if sucess
+ *   CPL_ERROR_FILE_IO if the file does not exist or the header cannot be read.
+ *
+ *   Find the name of the standard catalogue being used and its location.
+ *   The former should be in a header keyword in the specified FITS
+ *   file. The latter is the full path of the FITS file. Both values
+ *   need to be deallocated when you're finished with them.
+*/
+/*---------------------------------------------------------------------------*/
+
+int irplib_2mass_get_catpars
+(const cpl_frame *  master_index,
+ char            ** catpath,
+ char            ** catname)
+{
+    cpl_propertylist * p;
+    const char       * unk = "unknown";
+    char             * fname;
+    int                status = CPL_ERROR_NONE;
+
+    /* Initialise a few things */
+    *catpath = NULL;
+    *catname = NULL;
+
+    /* First get the full path to the index file and make sure it exists */
+    fname = cpl_strdup(cpl_frame_get_filename(master_index));
+    if (access((const char *)fname,R_OK) != 0)
+    {
+         cpl_msg_error(__func__,"Can't access index file %s",fname);
+         cpl_free(fname);
+         return CPL_ERROR_FILE_IO;
+    }
+    *catpath = cpl_strdup(dirname(fname));
+
+    /* Try to load the propertylist. If it is not possible signal a fatal
+       error since this probably means the whole file is messed up */
+    if ((p = cpl_propertylist_load(cpl_frame_get_filename(master_index),0)) == NULL)
+    {
+        cpl_msg_error(__func__,"Can't load index file header %s",fname);
+        cpl_free(*catpath);
+        cpl_free(fname);
+        return CPL_ERROR_FILE_IO;
+    }
+
+    /* If there is a catalogue name in the header then send it back. If there
+       isn't then give a default name and send a warning */
+    if (cpl_propertylist_has(p,"CATNAME"))
+    {
+        *catname = cpl_strdup(cpl_propertylist_get_string(p,"CATNAME"));
+        status = CPL_ERROR_NONE;
+    } else {
+        *catname = cpl_strdup(unk);
+        cpl_msg_warning(__func__,"Property CATNAME not in index file header %s",
+                        fname);
+    }
+
+    /* Free and return */
+    cpl_free(fname);
+    cpl_propertylist_delete(p);
+    return(status);
+}
+
+
+
+/*---------------------------------------------------------------------------*/
+/**
+ *  @brief
+ *       Get coverage in ra, dec of a frame
+ *  @param plist
+ *      Input property list
+ *  @param ext_search
+ *      Factor for an extra box search.
+ *  @param ra1
+ *       Lower RA
+ *  @param ra2
+ *       Upper RA
+ *  @param dec1
+ *       Lower Dec
+ *  @param dec2
+ *       Upper Dec
+ *  @return
+ *      CPL_ERROR_NONE if sucess.
+ *      CPL_ERROR_DATA_NOT_FOUND if wcs is not valid
+ *
+ *      Given a WCS solution this routine works out the min and max equatorial
+ *      coordinates covered by the image.
+ */
+/*---------------------------------------------------------------------------*/
+
+cpl_error_code irplib_cat_get_image_limits
+(const cpl_wcs    * wcs,
+ float              ext_search,
+ double           * ra1,
+ double           * ra2,
+ double           * dec1,
+ double           * dec2)
+{
+    double            ra;
+    double            dec;
+    double            x;
+    double            y;
+    double            dra;
+    double            ddec;
+    double            min_4q;
+    double            max_1q;
+    int               first_quad;
+    int               fourth_quad;
+    const int       * naxes;
+    long              i;
+    long              j;
+    const cpl_array * a;
+
+    /* Initialise these in case of failure later*/
+    *ra1 = 0.0;
+    *ra2 = 0.0;
+    *dec1 = 0.0;
+    *dec2 = 0.0;
+
+    /* Grab the WCS info from the property list */
+    if (wcs == NULL)
+        return CPL_ERROR_DATA_NOT_FOUND;
+
+    /* Get the size of the data array */
+
+    a = cpl_wcs_get_image_dims(wcs);
+    if(a == NULL)
+        return CPL_ERROR_ILLEGAL_INPUT;
+    naxes = cpl_array_get_data_int_const(a);
+
+    /* Find the RA and Dec limits of the image */
+
+    *ra1 = 370.0;
+    *ra2 = -370.0;
+    *dec1 = 95.0;
+    *dec2 = -95.0;
+    first_quad = 0;
+    fourth_quad = 0;
+    min_4q = 370.0;
+    max_1q = 0.0;
+    for (j = 1; j < naxes[1]; j += 10) {
+        y = (double)j;
+        for (i = 1; i < naxes[0]; i += 10) {
+            x = (double)i;
+            irplib_wcs_xytoradec(wcs,x,y,&ra,&dec);
+            if (ra >= 0.0 && ra <= 90.0) {
+                first_quad = 1;
+                if(ra > max_1q)
+                    max_1q = ra;
+            } else if (ra >= 270.0 && ra <= 360.0) {
+                fourth_quad = 1;
+                if(ra - 360.0 < min_4q)
+                    min_4q = ra - 360.0;
+            }
+            if(ra < *ra1)
+                *ra1 = ra;
+            if(ra > *ra2)
+                *ra2 = ra;
+            if(dec < *dec1)
+                *dec1 = dec;
+            if(dec > *dec2)
+                *dec2 = dec;
+        }
+    }
+
+    /* Now have a look to see if you had RA values in both the first and
+       fourth quadrants.  If you have, then make the minimum RA a negative
+       value.  This will be the signal to the caller that you have the
+       wraparound... */
+
+    if (first_quad && fourth_quad) {
+        *ra1 = min_4q;
+        *ra2 = max_1q;
+    }
+
+    /* Pad out search a bit */
+    if (ext_search)
+    {
+        dra = 0.5*ext_search*(*ra2 - *ra1);
+        *ra1 -= dra;
+        *ra2 += dra;
+        ddec = 0.5*ext_search*(*dec2 - *dec1);
+        *dec1 -= ddec;
+        *dec2 += ddec;
+    }
+
+    /* Exit */
+    return CPL_ERROR_NONE;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+ *
+ *  @brief
+ *       Extract standards from the 2mass catalogue
+ *  @param path
+ *    The full path to the catalogue FITS files and index.
+ *  @param ramin1
+ *    The minimum RA, this can be negative in the case the area wraps around
+ *    the equinox.
+ *  @param ramax1
+ *    The maximum RA
+ *  @param decmin
+ *    The minimum Declination
+ *  @param decmax
+ *    The maximum Declination
+ *  @return
+ *    A table structure with the extracted catalogue objects
+ *
+ *
+ *       The FITS tables containing the 2mass psc catalogue are searched
+ *       to find all of the objects within an input equatorial area. Deals
+ *   with the sigularity at the equinox, but not at the poles.
+ */
+/*---------------------------------------------------------------------------*/
+
+cpl_table *  irplib_2mass_extract
+(char *path,
+ float ramin,
+ float ramax,
+ float decmin,
+ float decmax)
+{
+    cpl_table *t,*s;
+    cpl_table *out;
+    int i,nrows,start,finish,first_index,last_index,irow,init,j;
+    int first_index_ra,last_index_ra,wrap,iwrap;
+    float dectest,ratest,ramin_wrap,ramax_wrap;
+    char fullname[FILENAME_SZBUF];
+    cpl_array *a;
+    const char *deccol[] = {"Dec"};
+    cpl_propertylist *p;
+
+    /* Create an output table */
+
+    out = cpl_table_new(0);
+    init = 1;
+
+    /* Create a cpl array */
+
+    /* deccol will NOT be modified */
+    a = cpl_array_wrap_string((char **)deccol,1);
+
+    /* Is there a wrap around problem? */
+
+    wrap = (ramin < 0.0 && ramax > 0.0) ? 2 : 1;
+
+    /* Loop for each query. If there is a wrap around problem then we need 2
+       queries. If not, then we only need 1 */
+
+    for (iwrap = 0; iwrap < wrap; iwrap++) {
+        if (wrap == 2) {
+            if (iwrap == 0) {
+                ramin_wrap = ramin + 360.0;
+                ramax_wrap = 360.0;
+            } else {
+                ramin_wrap = 0.000001;
+                ramax_wrap = ramax;
+            }
+        } else {
+            ramin_wrap = ramin;
+            ramax_wrap = ramax;
+        }
+
+        /* Find out where in the index to look */
+
+        first_index_ra = (int)ramin_wrap;
+        last_index_ra = (int)ramax_wrap;
+        if(last_index_ra > 359)
+            last_index_ra = 359;
+
+        /* Look at the min and max RA and decide which files need to be
+           opened. */
+
+        for (i = first_index_ra; i <= last_index_ra; i++)
+        {
+
+            /* Ok, we've found one that needs opening. Read the file with
+               the relevant CPL call */
+
+            (void)snprintf(fullname,FILENAME_SZBUF,"%s/npsc%03d.fits",path,i);
+
+            /* Read the propertylist so that you know how many rows there
+               are in the table */
+
+            p = cpl_propertylist_load(fullname,1);
+            if (p == NULL)
+            {
+                cpl_error_set_message_macro(__func__,CPL_ERROR_DATA_NOT_FOUND,
+                        __FILE__, __LINE__, "2mass file %s missing",fullname);
+                cpl_table_delete(out);
+                cpl_array_unwrap(a);
+                return(NULL);
+            }
+            nrows = cpl_propertylist_get_int(p, "NAXIS2");
+            cpl_propertylist_delete(p);
+
+            /* Load various rows until you find the Dec range that you
+             have specified. First the minimum Dec */
+
+            start = 0;
+            finish = nrows;
+            first_index = nrows/2;
+            while (finish - start >= 2)
+            {
+                t = cpl_table_load_window(fullname, 1, 0, a, first_index, 1);
+                dectest = cpl_table_get_float(t, "Dec", 0, NULL);
+                cpl_table_delete(t);
+                if (dectest < decmin)
+                {
+                    start = first_index;
+                    first_index = (first_index + finish)/2;
+                }
+                else
+                {
+                    finish = first_index;
+                    first_index = (first_index + start)/2;
+                }
+            }
+
+            /* Load various rows until you find the Dec range that you
+             have specified. Now the maximum Dec */
+
+            start = first_index;
+            finish = nrows;
+            last_index = start + (finish - start)/2;
+            while (finish - start >= 2)
+            {
+                t = cpl_table_load_window(fullname, 1, 0, a, last_index, 1);
+                dectest = cpl_table_get_float(t, "Dec", 0, NULL);
+                cpl_table_delete(t);
+                if (dectest < decmax)
+                {
+                    start = last_index;
+                    last_index = (last_index + finish)/2;
+                }
+                else
+                {
+                    finish = last_index;
+                    last_index = (last_index + start)/2;
+                }
+            }
+            if (last_index < first_index)
+                last_index = first_index;
+
+            /* Ok now now load all the rows in the relevant dec limits */
+
+            nrows = last_index - first_index + 1;
+            if ((t = cpl_table_load_window(fullname, 1, 0, NULL, first_index,
+                                           nrows)) == NULL)
+            {
+                cpl_error_set_message_macro(__func__,CPL_ERROR_DATA_NOT_FOUND,
+                        __FILE__, __LINE__, "Error in subset of 2mass file %s ",
+                        fullname);
+                cpl_table_delete(out);
+                cpl_array_unwrap(a);
+                return (NULL);
+            }
+            cpl_table_unselect_all(t);
+
+            /* Right, we now know what range of rows to search. Go through
+             these and pick the ones that are in the correct range of RA.
+             If a row qualifies, then 'select' it. */
+
+            for (j = 0; j < nrows; j++)
+            {
+                ratest = cpl_table_get_float(t, "RA", j, NULL);
+                if (cpl_error_get_code() != CPL_ERROR_NONE)
+                {
+                    cpl_error_set_message_macro(__func__,CPL_ERROR_DATA_NOT_FOUND,
+                            __FILE__, __LINE__, "No RA column in 2mass file %s",
+                            fullname);
+                    cpl_table_delete(t);
+                    cpl_array_unwrap(a);
+                    cpl_table_delete(out);
+                    return (NULL);
+                }
+                if (ratest >= ramin_wrap && ratest <= ramax_wrap)
+                    cpl_table_select_row(t, j);
+            }
+
+            /* Extract the rows that have been selected now and append them
+             onto the output table */
+
+            s = cpl_table_extract_selected(t);
+            if (init == 1)
+            {
+                cpl_table_copy_structure(out, t);
+                init = 0;
+            }
+            irow = cpl_table_get_nrow(out) + 1;
+            cpl_table_insert(out, s, irow);
+
+            /* Tidy up */
+
+            cpl_table_delete(t);
+            cpl_table_delete(s);
+        }
+    }
+
+    /* Ok, now just return the table and get out of here */
+
+    cpl_array_unwrap(a);
+    return(out);
+}
+/**@}*/
+
diff --git a/irplib/irplib_cat.h b/irplib/irplib_cat.h
new file mode 100644
index 0000000..7d9fe46
--- /dev/null
+++ b/irplib/irplib_cat.h
@@ -0,0 +1,57 @@
+/* $Id: irplib_cat.h,v 1.5 2009/12/16 14:49:52 cgarcia Exp $
+ *
+ * This file is part of the irplib package
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: cgarcia $
+ * $Date: 2009/12/16 14:49:52 $
+ * $Revision: 1.5 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifndef IRPLIB_CAT_H
+#define IRPLIB_CAT_H
+
+/*-----------------------------------------------------------------------------
+                                   Includes
+ -----------------------------------------------------------------------------*/
+
+#include <cpl.h>
+
+int irplib_2mass_get_catpars
+(const cpl_frame *master_index,
+ char            **catpath,
+ char            **catname);
+
+cpl_table *  irplib_2mass_extract
+(char *path,
+ float ramin,
+ float ramax,
+ float decmin,
+ float decmax);
+
+cpl_error_code irplib_cat_get_image_limits
+(const cpl_wcs    * wcs,
+ float              ext_search,
+ double           * ra1,
+ double           * ra2,
+ double           * dec1,
+ double           * dec2);
+
+#endif
diff --git a/irplib/irplib_distortion.c b/irplib/irplib_distortion.c
new file mode 100644
index 0000000..16938ce
--- /dev/null
+++ b/irplib/irplib_distortion.c
@@ -0,0 +1,1398 @@
+/* $Id: irplib_distortion.c,v 1.51 2012/02/03 15:08:14 llundin Exp $
+ *
+ * This file is part of the irplib package
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: llundin $
+ * $Date: 2012/02/03 15:08:14 $
+ * $Revision: 1.51 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+/*-----------------------------------------------------------------------------
+                                   Includes
+ -----------------------------------------------------------------------------*/
+
+/* TEMPORARY SUPPORT OF CPL 5.x */
+#include <cpl.h>
+
+#ifndef CPL_SIZE_FORMAT
+#define CPL_SIZE_FORMAT "d"
+#define cpl_size int
+#endif
+
+#if defined CPL_VERSION_CODE && CPL_VERSION_CODE <= CPL_VERSION(5, 92, 0)
+#define cpl_apertures_get_pos_x cpl_apertures_get_max_x
+#endif
+
+/* END TEMPORARY SUPPORT OF CPL 5.x */
+
+#include "irplib_distortion.h"
+
+#include "irplib_flat.h"
+#include "irplib_utils.h"
+#include "irplib_polynomial.h"
+
+#include <math.h>
+#include <float.h>
+
+/*-----------------------------------------------------------------------------
+                                   Define
+ -----------------------------------------------------------------------------*/
+
+#define IRPLIB_MAX(A,B) ((A) > (B) ? (A) : (B))
+#define IRPLIB_MIN(A,B) ((A) < (B) ? (A) : (B))
+
+#define ARC_MINGOODPIX      100
+#define ARC_MINARCLENFACT   2.0
+#define ARC_MINNBARCS       4
+#define ARC_RANGE_FACT      3.0
+#define ARC_WINDOWSIZE      32
+
+#define TRESH_MEDIAN_MIN    0.0
+#define TRESH_SIGMA_MAX     200.0
+
+/*----------------------------------------------------------------------------*/
+/**
+ * @defgroup irplib_distortion       Distortion correction functions
+ */
+/*----------------------------------------------------------------------------*/
+
+/*-----------------------------------------------------------------------------
+                                Functions prototypes
+ -----------------------------------------------------------------------------*/
+
+static cpl_apertures * irplib_distortion_detect_arcs(cpl_image *,
+        cpl_image **, int, int, double, int, int, int, int);
+static cpl_error_code irplib_distortion_fill_border(cpl_image *, int, int,
+                                                    int, int, double);
+static int irplib_distortion_threshold1d(cpl_image *, double, cpl_image *, 
+        double);
+static cpl_error_code irplib_distortion_purge_arcs(cpl_apertures **, cpl_image *,
+                                                   const cpl_image *, int, int,
+                                                   double);
+static cpl_error_code irplib_distortion_fill_arc_positions(cpl_bivector *,
+                                                          cpl_vector *,
+                                                          const cpl_image *,
+                                                          const cpl_image *,
+                                                          const cpl_apertures *);
+
+static double irplib_distortion_get_row_centroid(const cpl_image *,
+                                                 const cpl_image *, int, int);
+
+static int irplib_distortion_sub_hor_lowpass(cpl_image *, int);
+static cpl_image * irplib_distortion_remove_ramp(const cpl_image *);
+
+static cpl_error_code irplib_image_filter_background_line(cpl_image *,
+        const cpl_image *, int, cpl_boolean) ;
+
+static cpl_error_code irplib_polynomial_fit_2d(cpl_polynomial *,
+                                               const cpl_bivector *,
+                                               const cpl_vector *, int,
+                                               double, double *);
+
+static cpl_matrix * irplib_matrix_product_normal_create(const cpl_matrix *);
+
+/*-----------------------------------------------------------------------------
+                                Functions code
+ -----------------------------------------------------------------------------*/
+
+/**@{*/
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Estimate the distortion using vertical curved arc lines
+  @param    org     the input image
+  @param    xmin
+  @param    ymin    Define the zone to take into account
+  @param    xmax
+  @param    ymax
+  @param    auto_ramp_sub   To automatically clean the image before detection
+  @param    arc_sat Saturation threshold for the arc lines
+  @param    max_arc_width   Maximum arc width allowed in pixels
+  @param    kappa   Kappa for arc detection (0.33 = good default)
+  @param    degree  The positive degree of the fitted polynomial
+  @param    arcs    The found arc lines, *arcs is NULL on error
+  @return   The 2d polynomial describing the distortion or NULL in error case
+  @see cpl_image_warp_polynomial()
+  @note The arc lines are expected to be vertical.
+
+  If (Xi, yi) define positions on the curved arc lines, and (xi, yi) the
+  associated positions on the straight arc lines, the created polynomial is
+  Xi = P(xi, yi).
+
+  The polynomial has the property for all xi that xi = P(xi, (Ny+1)/2),
+  where Ny is the Y-size, i.e. the polynomial transformation does not move
+  the points on the detector center line, y = (Ny+1)/2.
+
+  The returned polynomial can passed to cpl_image_warp_polynomial() to correct 
+  the image.
+ */
+/*----------------------------------------------------------------------------*/
+cpl_polynomial * irplib_distortion_estimate(
+        const cpl_image *   org,
+        int                 xmin,
+        int                 ymin,
+        int                 xmax,
+        int                 ymax,
+        int                 auto_ramp_sub,
+        int                 arc_sat,
+        int                 max_arc_width,
+        double              kappa,
+        int                 degree,
+        cpl_apertures   **  arcs)
+{
+    cpl_image      * local_im;
+    cpl_image      * filtered;
+    cpl_image      * label_image;
+    double           rightmost, leftmost;
+    cpl_bivector   * grid;
+    cpl_vector     * values_to_fit;
+    int              n_arcs;
+    cpl_polynomial * poly2d;
+    double           mse = 0.0;
+    const int        nx = cpl_image_get_size_x(org);
+    const int        ny = cpl_image_get_size_y(org);
+    const int        min_arc_range = (int)(nx / ARC_RANGE_FACT);
+    int              i;
+
+    /* Check entries */
+    cpl_ensure(org           != NULL, CPL_ERROR_NULL_INPUT,    NULL);
+    cpl_ensure(kappa         >= 0.0,  CPL_ERROR_ILLEGAL_INPUT, NULL);
+    cpl_ensure(max_arc_width > 0,     CPL_ERROR_ILLEGAL_INPUT, NULL);
+
+    /* The background may vary strongly along the vertical line. */
+    /* Detect and rm background with a 1+2*max_arc_width x 1 median filter */
+
+    filtered = cpl_image_new(nx, ny, cpl_image_get_type(org));
+
+    irplib_image_filter_background_line(filtered, org, max_arc_width, CPL_TRUE);
+
+    if (auto_ramp_sub) {
+        local_im = irplib_distortion_remove_ramp(filtered);
+        cpl_image_delete(filtered);
+    } else {
+        local_im = filtered;
+    }
+
+    cpl_error_ensure(local_im != NULL, cpl_error_get_code(),
+                     return(NULL), "Cannot clean the image");
+
+    /* Detect the arcs in the input image */
+    *arcs = irplib_distortion_detect_arcs(local_im, &label_image, arc_sat,
+                                          max_arc_width, kappa, xmin, ymin,
+                                          xmax, ymax);
+    if (*arcs == NULL) {
+        cpl_image_delete(local_im);
+        cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
+                              "Cannot detect the arcs");
+        return NULL;
+    }
+    n_arcs = cpl_apertures_get_size(*arcs);
+    cpl_msg_info(cpl_func, "%d detected arcs", n_arcs);
+
+    /* Check that the arcs are not concentrated in the same zone */
+    rightmost = leftmost = cpl_apertures_get_pos_x(*arcs, 1);
+    for (i=1; i<n_arcs; i++) {
+        if (cpl_apertures_get_pos_x(*arcs, i+1) < leftmost)
+            leftmost = cpl_apertures_get_pos_x(*arcs, i+1);
+        if (cpl_apertures_get_pos_x(*arcs, i+1) > rightmost)
+            rightmost = cpl_apertures_get_pos_x(*arcs, i+1);
+    }
+    if ((int)(rightmost-leftmost) < min_arc_range) {
+#if defined CPL_HAVE_VA_ARGS && CPL_HAVE_VA_ARGS != 0
+        cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
+                              "too narrow range (%g-%g)<%d",
+                              rightmost, leftmost, min_arc_range);
+#else
+        cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
+                              "too narrow range");
+#endif
+        cpl_apertures_delete(*arcs);
+        cpl_image_delete(local_im);
+        cpl_image_delete(label_image);
+        *arcs = NULL;
+        return NULL;
+    }
+
+    /* Create a 2-D deformation grid with detected arcs */
+    cpl_msg_info(cpl_func, "Create deformation grid");
+    grid = cpl_bivector_new(n_arcs * ny);
+    values_to_fit = cpl_vector_new(n_arcs * ny);
+
+    if (irplib_distortion_fill_arc_positions(grid, values_to_fit, local_im,
+                                            label_image, *arcs)){
+        cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
+                              "cannot get arcs positions");
+        cpl_apertures_delete(*arcs);
+        cpl_image_delete(local_im);
+        cpl_image_delete(label_image);
+        *arcs = NULL;
+        return NULL;
+    }
+    cpl_image_delete(label_image);
+    cpl_image_delete(local_im);
+
+    /* Apply the fitting */
+    poly2d = cpl_polynomial_new(2);
+    if (irplib_polynomial_fit_2d(poly2d, grid, values_to_fit, degree,
+                                 0.5*(ny+1), &mse)) {
+        cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
+                              "cannot apply the 2d fit");
+        cpl_bivector_delete(grid);
+        cpl_vector_delete(values_to_fit);
+        cpl_apertures_delete(*arcs);
+        *arcs = NULL;
+        return NULL;
+    }
+
+    cpl_msg_info(cpl_func, 
+            "Fitted a %d. degree 2D-polynomial to %"CPL_SIZE_FORMAT" points "
+            "with mean-square error: %g", degree,
+            cpl_vector_get_size(values_to_fit), mse);
+
+    /* Free and return */
+    cpl_bivector_delete(grid);
+    cpl_vector_delete(values_to_fit);
+    return poly2d;
+}
+
+/**@}*/
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Detect the vertical arcs in an image
+  @param    im          the input image
+  @param    label_im    the output label image
+  @param    arc_sat     Saturation threshold for the arcs
+  @param    max_arc_width   Maximum arc width allowed
+  @param    kappa           For arcs detection (0.33 is a good default)
+  @param    xmin
+  @param    ymin        Define the zone to take into account
+  @param    xmax
+  @param    ymax
+  @return   The arcs or NULL in error case
+  
+  The arcs are expected to be vertical.
+ */
+/*----------------------------------------------------------------------------*/
+static cpl_apertures * irplib_distortion_detect_arcs(
+        cpl_image *   im,
+        cpl_image **  label_im,
+        int             arc_sat,
+        int             max_arc_width,
+        double          kappa,
+        int             xmin,
+        int             ymin,
+        int             xmax,
+        int             ymax)
+{
+    const int           ny = cpl_image_get_size_y(im);
+    /* Set min_arclen */
+    const int           min_arclen = (int)(ny / ARC_MINARCLENFACT);
+    cpl_image       *   filt_im;
+    cpl_mask        *   filter;
+    cpl_image       *   collapsed;
+    cpl_mask        *   bin_im;
+    double              threshold, fillval, median_val, sigma;
+    cpl_apertures   *   det;
+    cpl_size            nobj;
+    int                 ngoodpix;
+    
+    /* Default values for output parameters */
+    *label_im = NULL;
+
+    /* Clear zones to be ignored (to avoid false detections) */
+    median_val = cpl_image_get_median_dev(im, &sigma);
+    fillval = median_val-sigma/2.0;
+    if (irplib_distortion_fill_border(im, xmin, ymin, xmax, ymax, fillval)) {
+        cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
+                              "cannot fill bad zones");
+        return NULL;
+    }
+
+    /* Subtract a low-pass */
+    filt_im = cpl_image_duplicate(im);
+    if (irplib_distortion_sub_hor_lowpass(filt_im, ARC_WINDOWSIZE) == -1) {
+        cpl_image_delete(filt_im);
+        return NULL;
+    }
+    
+    /* Get relevant stats for thresholding */
+    median_val = cpl_image_get_median_dev(filt_im, &sigma);
+
+    /* Correct median_val and sigma if necessary */
+    if (median_val < TRESH_MEDIAN_MIN) median_val = TRESH_MEDIAN_MIN;
+    if (sigma > TRESH_SIGMA_MAX) sigma = TRESH_SIGMA_MAX;
+
+    /* Set the threshold */
+    threshold = median_val + sigma * kappa;
+
+    /* Collapse the image */
+    collapsed = cpl_image_collapse_median_create(filt_im, 0, 0, 0);
+
+    /* Threshold to keep only the arcs - use of the collapsed image */
+    if (irplib_distortion_threshold1d(filt_im, median_val, collapsed, 0.0)==-1) {
+        cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
+                              "cannot threshold the filtered image");
+        cpl_image_delete(filt_im);
+        cpl_image_delete(collapsed);
+        return NULL;
+    }
+    cpl_image_delete(collapsed);
+
+    /* Binarize the image */
+    bin_im = cpl_mask_threshold_image_create(filt_im, threshold, 
+            DBL_MAX);
+    cpl_image_delete(filt_im);
+    if (bin_im == NULL) {
+        cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
+                              "cannot binarise the image");
+        return NULL;
+    }
+
+    /* Test if there are enough good pixels */
+    ngoodpix = cpl_mask_count(bin_im);
+    if (ngoodpix < ARC_MINGOODPIX) {
+#if defined CPL_HAVE_VA_ARGS && CPL_HAVE_VA_ARGS != 0
+        cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
+                              "Too few (%d) white pixels", ngoodpix);
+#else
+        cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
+                              "Too few white pixels");
+#endif
+        cpl_mask_delete(bin_im);
+        return NULL;
+    }
+
+    /* Apply a morphological opening to clean the isolated pixels */
+    filter = cpl_mask_new(3, 3);
+    cpl_mask_not(filter);
+    cpl_mask_filter(bin_im, bin_im, filter, CPL_FILTER_OPENING,
+                    CPL_BORDER_ZERO);
+    cpl_mask_delete(filter);
+
+    /* Labelize pixel map to a label image */
+    *label_im = cpl_image_labelise_mask_create(bin_im, &nobj);
+    cpl_mask_delete(bin_im);
+
+    /* Compute statistics on objects */
+    if ((det = cpl_apertures_new_from_image(im, *label_im)) == NULL) {
+        cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
+                              "Cannot compute arcs stats");
+        cpl_image_delete(*label_im);
+        *label_im = NULL;
+        return NULL;
+    }
+
+    /* Purge non-relevant arcs */
+    if (irplib_distortion_purge_arcs(&det, *label_im, im, min_arclen,
+                                     max_arc_width, arc_sat)) {
+        cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
+                              "Cannot purge the arcs");
+        cpl_image_delete(*label_im);
+        *label_im = NULL;
+        cpl_apertures_delete(det);
+        return NULL;
+    }
+    if (cpl_apertures_get_size(det) < ARC_MINNBARCS) {
+#if defined CPL_HAVE_VA_ARGS && CPL_HAVE_VA_ARGS != 0
+        cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
+                "Not enough valid arcs (%"CPL_SIZE_FORMAT" < %d)", 
+                cpl_apertures_get_size(det), ARC_MINNBARCS);
+#else
+        cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
+                              "Not enough valid arcs, min="
+                              IRPLIB_STRINGIFY(ARC_MINNBARCS));
+#endif
+        cpl_image_delete(*label_im);
+        *label_im = NULL;
+        cpl_apertures_delete(det);
+        return NULL;
+    }
+
+    /* Return  */
+    return det;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Fill the image border with the given constant
+  @param    self  Image of pixel-type float to be modified
+  @param    xmin  Fill xmin-1  leftmost  column(s) (No fill for xmin <= 1)
+  @param    ymin  Fill ymin-1  first     row(s)    (No fill for ymin <= 1)
+  @param    xmax  Fill nx-xmax rightmost column(s) (No fill for xmax >= nx)
+  @param    ymax  Fill ny-ymax last      row(s)    (No fill for ymax >= ny)
+  @return   CPL_ERROR_NONE on success, otherwise the relevant CPL error code
+ */
+/*----------------------------------------------------------------------------*/
+static cpl_error_code irplib_distortion_fill_border(cpl_image * self,
+                                                    int         xmin,
+                                                    int         ymin,
+                                                    int         xmax,
+                                                    int         ymax,
+                                                    double      fillval)
+{
+    const int   nx     = cpl_image_get_size_x(self);
+    const int   ny     = cpl_image_get_size_y(self);
+    float     * pfi    = cpl_image_get_data_float(self);
+    const float fvalue = (float)fillval;
+    int         i, j;
+
+
+    cpl_ensure_code(pfi != NULL, cpl_error_get_code());
+
+    /* Ensure validity of pixel buffer access */
+    xmin = IRPLIB_MIN(xmin, nx+1);
+    ymax = IRPLIB_MIN(ymax, ny);
+
+    /* - and avoid double access */
+    xmax = IRPLIB_MAX(xmax, xmin - 1);
+    ymin = IRPLIB_MIN(ymin, ymax + 1);
+
+    /* Fill the zone */
+
+    for (j = 0; j < ymin-1; j++) {
+        for (i = 0; i < nx; i++) {
+            pfi[i+j*nx] = fvalue;
+        }
+    }
+    /* assert( j == IRPLIB_MAX(0, ymin-1) ); */
+
+    for (; j < ymax; j++) {
+        for (i = 0; i < xmin-1; i++) {
+            pfi[i+j*nx] = fvalue;
+        }
+        for (i = xmax; i < nx; i++) {
+            pfi[i+j*nx] = fvalue;
+        }
+    }
+    /* assert( j == IRPLIB_MAX(0, ymax) ); */
+
+    for (; j < ny; j++) {
+        for (i = 0; i < nx; i++) {
+            pfi[i+j*nx] = fvalue;
+        }
+    }
+
+    return CPL_ERROR_NONE;
+}
+
+static int irplib_distortion_threshold1d(
+        cpl_image   *   im,
+        double          threshold,
+        cpl_image   *   im1d,
+        double          newval)
+{
+    float       *   pim;
+    float       *   pim1d;
+    int             nx, ny;
+    int             i, j;
+
+    /* Check entries */
+    if (im == NULL) return -1;
+    if (im1d == NULL) return -1;
+    if (cpl_image_get_type(im) != CPL_TYPE_FLOAT) return -1;
+    if (cpl_image_get_type(im1d) != CPL_TYPE_FLOAT) return -1;
+
+    /* Get access to the im / im1d data */
+    pim = cpl_image_get_data_float(im);
+    pim1d = cpl_image_get_data_float(im1d);
+    nx = cpl_image_get_size_x(im);
+    ny = cpl_image_get_size_y(im);
+
+    /* Apply the thresholding */
+    for (i=0; i<nx; i++)
+        if (pim1d[i] < threshold) {
+            for (j=0; j<ny; j++) pim[i+j*nx] = (float)newval;
+        }
+
+    /* Return */
+    return 0;
+}
+
+static int irplib_distortion_sub_hor_lowpass(
+        cpl_image   *   im, 
+        int             filt_size)
+{
+    cpl_vector  *   linehi;
+    cpl_vector  *   linelo;
+    cpl_vector  *   avglinehi;
+    cpl_vector  *   avglinelo;
+    double      *   pavglinehi;
+    float       *   pim;
+    int             lopos, hipos, nx, ny;
+    int             i, j;
+
+    /* Test entries */
+    if (im == NULL) return -1;
+    if (filt_size <= 0) return -1;
+    
+    /* Initialise */
+    nx = cpl_image_get_size_x(im);
+    ny = cpl_image_get_size_y(im);
+    lopos = (int)(ny/4);
+    hipos = (int)(3*ny/4);
+
+    /* Get the vectors out of the image */
+    if ((linehi = cpl_vector_new_from_image_row(im, hipos)) == NULL) {
+        return -1;
+    }
+    if ((linelo = cpl_vector_new_from_image_row(im, lopos)) == NULL) {
+        cpl_vector_delete(linehi);
+        return -1;
+    }
+    
+    /* Filter the vectors */
+    if ((avglinehi = cpl_vector_filter_median_create(linehi, 
+                    filt_size)) == NULL) {
+        cpl_vector_delete(linehi);
+        cpl_vector_delete(linelo);
+        return -1;
+    }
+    cpl_vector_delete(linehi);
+    
+    if ((avglinelo = cpl_vector_filter_median_create(linelo, 
+                    filt_size)) == NULL) {
+        cpl_vector_delete(linelo);
+        cpl_vector_delete(avglinehi);
+        return -1;
+    }
+    cpl_vector_delete(linelo);
+
+    /* Average the filtered vectors to get the low freq signal */
+    cpl_vector_add(avglinehi, avglinelo);
+    cpl_vector_delete(avglinelo);
+    cpl_vector_divide_scalar(avglinehi, 2.0);
+
+    /* Subtract the low frequency signal */
+    pavglinehi = cpl_vector_get_data(avglinehi);
+    pim = cpl_image_get_data_float(im);
+    for (i=0; i<nx; i++) {
+        for (j=0; j<ny; j++) {
+            pim[i+j*nx] -= pavglinehi[i];
+        }
+    }
+    cpl_vector_delete(avglinehi);
+
+    return 0;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Purge apertures that don't look like arc lines
+  @param    self         Aperture object pointer
+  @param    lab_im       Label image, to be relabelled
+  @param    arc_im       Image with arc lines
+  @param    min_arclen   Arc line criterion
+  @param    max_arcwidth Arc line criterion
+  @param    arc_sat      Arc line criterion
+  @return   a newly allocated clean image
+ */
+/*----------------------------------------------------------------------------*/
+static
+cpl_error_code irplib_distortion_purge_arcs(cpl_apertures  ** self,
+                                            cpl_image       * lab_im,
+                                            const cpl_image * arc_im,
+                                            int               min_arclen,
+                                            int               max_arcwidth,
+                                            double            arc_sat)
+{
+    const double ycenter = 0.5 * (1 + cpl_image_get_size_y(arc_im));
+    int   narcs;
+    int   nkeep  = 0;
+    int   ifirst = 1;
+    int * relabel;
+    int   i;
+
+    /* Check entries */
+    cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT);
+
+    /* Get number of arcs */
+    narcs = cpl_apertures_get_size(*self);
+
+    cpl_ensure_code(narcs  > 0,     CPL_ERROR_DATA_NOT_FOUND);
+    cpl_ensure_code(cpl_image_get_type(lab_im) == CPL_TYPE_INT,
+                    CPL_ERROR_ILLEGAL_INPUT);
+
+    /* Allocate relabel array with default relabelling to zero */
+    relabel = cpl_calloc(narcs, sizeof(int));
+
+    /* Loop on the different arcs candidates */
+    for (i = 0; i < narcs; i++) {
+        /* Test if the current object is a valid arc */
+        const int arclen = 1
+            + cpl_apertures_get_top(*self, i+1)
+            - cpl_apertures_get_bottom(*self, i+1);
+
+        if (cpl_apertures_get_top(*self,    i+1) < ycenter) continue;
+        if (cpl_apertures_get_bottom(*self, i+1) > ycenter) continue;
+
+        if (arclen > min_arclen) {
+            const int arcwidth = 1
+                + cpl_apertures_get_right(*self, i+1)
+                - cpl_apertures_get_left(*self, i+1);
+            if (arcwidth < max_arcwidth) {
+                const int edge = cpl_apertures_get_left_y(*self, i+1);
+                if (edge > 0) {
+                    const double mean = cpl_apertures_get_mean(*self, i+1);
+                    if (mean < arc_sat) {
+                        relabel[i] = ++nkeep;
+                        /* Relabeling, if any, starts with ifirst */
+                        if (nkeep == i+1) ifirst = nkeep;
+                    }
+                }
+            }
+        }
+    }
+
+    if (nkeep < narcs) {
+        /* Update the labelised image by erasing non valid arcs */
+        int     * plabim = cpl_image_get_data_int(lab_im);
+        const int npix   = cpl_image_get_size_x(lab_im)
+            * cpl_image_get_size_y(lab_im);
+
+        if (nkeep == 0) {
+            cpl_free(relabel);
+#if defined CPL_HAVE_VA_ARGS && CPL_HAVE_VA_ARGS != 0
+            return cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
+                                         "All %d arc(s) are invalid", narcs);
+#else
+            return cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
+                                         "All arcs are invalid");
+#endif
+        }
+
+        for (i = 0; i < npix; i++) {
+            const int label = plabim[i];
+
+            if (label < 0 || label > narcs) break;
+            if (label >= ifirst) plabim[i] = relabel[label-1];
+        }
+
+        if (i < npix) {
+            /* lab_im is not a valid label image */
+            cpl_free(relabel);
+            return cpl_error_set(cpl_func, plabim[i] < 0
+                                         ? CPL_ERROR_ILLEGAL_INPUT
+                                         : CPL_ERROR_INCOMPATIBLE_INPUT);
+        }
+
+        /* Purge the bad arcs */
+        cpl_apertures_delete(*self);
+        *self = cpl_apertures_new_from_image(arc_im, lab_im);
+
+    }
+
+    cpl_free(relabel);
+
+    cpl_msg_info(cpl_func, "Purged %d of %d arcs (1st purged=%d)", narcs - nkeep,
+                 narcs, ifirst);
+
+    /* arc_im may be invalid */
+    cpl_ensure_code(*self != NULL, cpl_error_get_code());
+
+    return CPL_ERROR_NONE;
+}
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Find the fitting points for the 2D-polynomial
+  @param    grid      Positions in the image (may be shortened), (1,1) for first
+  @param    fitvalues Fitting values in the image (may be shortened)
+  @param    in        2D-spectrum with curvature
+  @param    label_im  Corresponding label image 
+  @param    det       Corresponding apertures
+  @return   CPL_ERROR_NONE on success, otherwise the relevant CPL error code
+
+  Sample arcs along all rows.
+  Fit to centroid of center row, i.e. center row is fix-points of transform.
+
+ */
+/*----------------------------------------------------------------------------*/
+static cpl_error_code
+irplib_distortion_fill_arc_positions(cpl_bivector        * grid,
+                                     cpl_vector          * fitvalues,
+                                     const cpl_image     * in,
+                                     const cpl_image     * label_im,
+                                     const cpl_apertures * det)
+{
+    const int    narcs = cpl_apertures_get_size(det);
+    int          nfitvals = cpl_vector_get_size(fitvalues);
+    const int    nx = cpl_image_get_size_x(label_im);
+    const int    ny = cpl_image_get_size_y(label_im);
+    cpl_image  * filt_img;
+    cpl_mask   * kernel;
+    cpl_vector * gridx = cpl_bivector_get_x(grid);
+    cpl_vector * gridy = cpl_bivector_get_y(grid);
+    cpl_polynomial* dist1d;
+    cpl_matrix * dist1dx = NULL;
+    cpl_vector * dist1dy = NULL;
+    double     * dgridx;
+    double     * dgridy;
+    double     * dfitv;
+    int          ndone = 0;
+    int          i, obj;
+
+    cpl_ensure_code(nfitvals > 0,      CPL_ERROR_DATA_NOT_FOUND);
+    cpl_ensure_code(narcs    > 0,      CPL_ERROR_DATA_NOT_FOUND);
+    cpl_ensure_code(cpl_image_get_type(label_im) == CPL_TYPE_INT,
+                    CPL_ERROR_TYPE_MISMATCH);
+
+    /* Ensure space for output */
+    if (nfitvals < narcs * ny) {
+        nfitvals = narcs * ny;
+        cpl_vector_set_size(fitvalues, nfitvals);
+    }
+    if (cpl_vector_get_size(gridx) < nfitvals ||
+        cpl_vector_get_size(gridy) < nfitvals) {
+        cpl_vector_set_size(gridx, nfitvals);
+        cpl_vector_set_size(gridy, nfitvals);
+    }
+
+    /* Get data after resizing */
+    dgridx = cpl_vector_get_data(gridx);
+    dgridy = cpl_vector_get_data(gridy);
+    dfitv  = cpl_vector_get_data(fitvalues);
+
+    /* Median filter on input image */
+    kernel = cpl_mask_new(3, 3);
+    cpl_mask_not(kernel);
+    filt_img = cpl_image_new(nx, ny, cpl_image_get_type(in));
+    cpl_image_filter_mask(filt_img, in, kernel, CPL_FILTER_MEDIAN,
+                                                CPL_BORDER_FILTER);
+    cpl_mask_delete(kernel);
+
+    dist1d = cpl_polynomial_new(1);
+
+    for (obj = 0; obj < narcs; obj++) {
+        /* Find the reference X-coordinate for the arc */
+        const int  * plabel_im = cpl_image_get_data_int_const(label_im);
+        const int    ndist1d = cpl_apertures_get_top(det, obj+1)
+            - cpl_apertures_get_bottom(det, obj+1) + 1;
+        cpl_boolean sampsym = CPL_TRUE;
+        int         j, prevj = 0;
+        int         k = 0;
+
+        (void)cpl_matrix_unwrap(dist1dx);
+        (void)cpl_vector_unwrap(dist1dy);
+        dist1dx = cpl_matrix_wrap(1, ndist1d, dgridy + ndone);
+        dist1dy = cpl_vector_wrap(ndist1d, dfitv  + ndone);
+
+        /* Find out the X coord. at all Y positions on the arc */
+
+        for (j = cpl_apertures_get_bottom(det, obj+1)-1;
+             j < cpl_apertures_get_top(det, obj+1); j++) {
+
+            for (i = 0; i < nx; i++) {
+                if (plabel_im[i + j * nx] == obj + 1) break;
+            }
+            if (i < nx) {
+                /* Found 1st pixel of aperture obj+1 in row j+1 */
+                cpl_errorstate prestate = cpl_errorstate_get();
+
+                const double x_finepos
+                    = irplib_distortion_get_row_centroid(filt_img, label_im,
+                                                         i, j);
+                if (!cpl_errorstate_is_equal(prestate)) {
+                    irplib_error_recover(prestate, "Could not find X-position "
+                                         "for line %d at y=%d (x=%d)",
+                                         obj+1, j+1, i+1);
+                } else if (x_finepos >= 0.0) {
+                    cpl_matrix_set(dist1dx, 0, k, 1.0 + j);
+                    cpl_vector_set(dist1dy, k, 1.0 + x_finepos);
+                    if (k > 0 && j != 1 + prevj) sampsym = CPL_FALSE;
+                    prevj = j;
+                    k++;
+                }
+            }
+        }
+        if (k > 0) {
+            double ref_xpos, grad;
+            cpl_error_code error;
+            const cpl_boolean did_drop = k != ndist1d;
+            const cpl_size mindeg = 0;
+            const cpl_size maxdeg = 2;
+
+            if (did_drop) {
+                /* Set correct size */
+                dist1dx = cpl_matrix_wrap(1, k, cpl_matrix_unwrap(dist1dx));
+                dist1dy = cpl_vector_wrap(k, cpl_vector_unwrap(dist1dy));
+            }
+
+            error = cpl_polynomial_fit(dist1d, dist1dx, &sampsym, dist1dy, NULL,
+                             CPL_FALSE, &mindeg, &maxdeg);
+            if (error) {
+                cpl_msg_error(cpl_func, "1D-fit failed");
+                break;
+            }
+
+            ref_xpos = cpl_polynomial_eval_1d(dist1d, 0.5 * (ny + 1), &grad);
+
+            for (j = cpl_apertures_get_bottom(det, obj+1)-1;
+                 j < cpl_apertures_get_top(det, obj+1); j++) {
+                const double xpos = cpl_polynomial_eval_1d(dist1d, j+1.0, NULL);
+
+                dfitv [ndone] = xpos;
+                dgridx[ndone] = ref_xpos;
+                /* Wrapping dist1dx does _not_ take care of dgridy,
+                   in case of "Could not find X-position " */
+                if (did_drop)
+                    dgridy[ndone] = 1.0 + j;
+                ndone++;
+            }
+            cpl_msg_info(cpl_func, "Line %d has center gradient %g", obj+1,
+                         grad);
+        }
+    }
+
+    cpl_image_delete(filt_img);
+    cpl_polynomial_delete(dist1d);
+    (void)cpl_matrix_unwrap(dist1dx);
+    (void)cpl_vector_unwrap(dist1dy);
+
+    cpl_msg_info(cpl_func, "Found %d fitting points ("
+                 "expected up to %d points)", ndone, nfitvals);
+
+    cpl_ensure_code(obj == narcs, cpl_error_get_code());
+
+    cpl_ensure_code(ndone > 0, CPL_ERROR_DATA_NOT_FOUND);
+
+    cpl_vector_set_size(fitvalues, ndone);
+    cpl_vector_set_size(gridx, ndone);
+    cpl_vector_set_size(gridy, ndone);
+
+    return CPL_ERROR_NONE;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Get the X-centroid of the row y (y=0 for first)
+  @param    im        Input image 
+  @param    label_im  Label image 
+  @param    x         Start column of the line profile (0 for first)
+  @param    y         Start row (0 for first)
+  @return   a newly allocated clean image
+  @note All object pixels must have column positions of at least x
+ */
+/*----------------------------------------------------------------------------*/
+static double irplib_distortion_get_row_centroid(const cpl_image * im,
+                                                 const cpl_image * label_im,
+                                                 int               x,
+                                                 int               y)
+{
+    const int     nx        = cpl_image_get_size_x(im);
+    const int     ny        = cpl_image_get_size_y(im);
+    const int     ynx       = y * nx;
+    const float * pim       = cpl_image_get_data_float_const(im);
+    const int   * plabel_im = cpl_image_get_data_int_const(label_im);
+    int           firstpos = -1;
+    int           lastpos  = -1;
+    int           maxpos   = x;
+    int           objnum;
+    double        wsum = 0.0;
+    double        sum  = 0.0;
+    double        max  = 0.0;
+
+    cpl_ensure(pim       != NULL, cpl_error_get_code(),    -1.0);
+    cpl_ensure(plabel_im != NULL, cpl_error_get_code(),    -2.0);
+    cpl_ensure(x         >= 0,    CPL_ERROR_ILLEGAL_INPUT, -3.0);
+    cpl_ensure(y         >= 0,    CPL_ERROR_ILLEGAL_INPUT, -4.0);
+    cpl_ensure(x         <  nx,   CPL_ERROR_ILLEGAL_INPUT, -5.0);
+    cpl_ensure(y         <  ny,   CPL_ERROR_ILLEGAL_INPUT, -6.0);
+
+    max    = (double)pim[x + ynx];
+    objnum = plabel_im[x + ynx];
+
+    /* While we stay in the same object... */
+    do {
+        const double val = (double)pim[x + ynx];
+
+        if (val > 0.0) { /* FIXME: Handle this exception better */
+            wsum += x * val;
+            sum += val;
+
+            if (firstpos < 0) firstpos = x;
+            lastpos = x;
+
+            if (val > max) {
+                max = val;
+                maxpos = x;
+            }
+        }
+
+
+        /* Next point */
+        x++;
+
+    } while (x < nx && objnum == plabel_im[x + ynx]);
+
+    cpl_ensure(sum > 0.0, CPL_ERROR_DATA_NOT_FOUND, -7.0);
+
+    /*
+       assert( 0 <= maxpos && maxpos < nx );
+       assert( objnum == plabel_im[maxpos + ynx] );
+       assert( wsum >= 0.0 );
+    */
+
+    return (wsum < sum * firstpos || wsum > sum * lastpos)
+        ? maxpos : wsum / sum;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Detect and remove a dark ramp in an image
+  @param    in  input image 
+  @return   a newly allocated clean image
+ */
+/*----------------------------------------------------------------------------*/
+#define IS_NB_TESTPOINTS    8
+#define IS_MIN_SLOPE        0.01
+#define IS_MAX_SLOPE_DIF    0.075
+#define IS_MAX_FIT_EDGE_DIF 0.05
+#define IS_MIN_RAMP         10.0
+#define IS_MAX_MNERR        13.0
+#define IS_MAX_MNERR_DIF    8.0
+#define IS_MAX_INTER_DIF    20.0
+#define IS_SKIPZONE         2.5
+#define SQR(x) ((x)*(x))
+static cpl_image * irplib_distortion_remove_ramp(const cpl_image * in) 
+{
+    int                 ramp_present;
+    const int           nx = cpl_image_get_size_x(in);
+    const int           ny = cpl_image_get_size_y(in);
+    const int           yhi = (int)(ny/2);
+    const int           ylo = yhi - 1;
+    int                 y;
+    cpl_vector      *   tmp_vector;
+    cpl_bivector    *   testpointlo;
+    double          *   testpointlo_x;
+    double          *   testpointlo_y;
+    cpl_bivector    *   testpointhi;
+    double          *   testpointhi_x;
+    double          *   testpointhi_y;
+    const int           spacing = ny / (IS_SKIPZONE*IS_NB_TESTPOINTS);
+    double              rampdif, fitslope;
+    double          *   pol_coefhi,
+                    *   pol_coeflo;
+    cpl_vector      *   median;
+    double          *   median_data;
+    double              medianerrlo, medianerrhi;
+    double              slope;
+    cpl_image       *   out;
+    float           *   pout;
+    float               val;
+    int                 i, j;
+
+    cpl_ensure(cpl_image_get_type(in) == CPL_TYPE_FLOAT,
+               CPL_ERROR_UNSUPPORTED_MODE, NULL);
+                    
+    if (ny < IS_SKIPZONE * IS_NB_TESTPOINTS){
+#if defined CPL_HAVE_VA_ARGS && CPL_HAVE_VA_ARGS != 0
+        cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
+                              "image has %d lines, min="
+                              IRPLIB_STRINGIFY(IS_SKIPZONE) "*"
+                              IRPLIB_STRINGIFY(IS_NB_TESTPOINTS), ny);
+#else
+        cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
+                              "image has too few lines, min="
+                              IRPLIB_STRINGIFY(IS_SKIPZONE) "*"
+                              IRPLIB_STRINGIFY(IS_NB_TESTPOINTS));
+#endif
+        return NULL;
+    }
+    
+    /* Fill the vectors */
+    testpointhi = cpl_bivector_new(IS_NB_TESTPOINTS);
+    testpointhi_x = cpl_bivector_get_x_data(testpointhi);
+    testpointhi_y = cpl_bivector_get_y_data(testpointhi);
+    testpointlo = cpl_bivector_new(IS_NB_TESTPOINTS);
+    testpointlo_x = cpl_bivector_get_x_data(testpointlo);
+    testpointlo_y = cpl_bivector_get_y_data(testpointlo);
+    for (i=0; i<IS_NB_TESTPOINTS; i++) {
+        y = yhi + i * spacing;
+        tmp_vector = cpl_vector_new_from_image_row(in, y+1);
+        testpointhi_x[i] = y - ny / 2;
+        testpointhi_y[i] = cpl_vector_get_median_const(tmp_vector);
+        cpl_vector_delete(tmp_vector);
+        y = ylo - i * spacing;
+        tmp_vector = cpl_vector_new_from_image_row(in, y+1);
+        testpointlo_x[IS_NB_TESTPOINTS-i-1] = y;
+        testpointlo_y[IS_NB_TESTPOINTS-i-1]=cpl_vector_get_median_const(tmp_vector);
+        cpl_vector_delete(tmp_vector);
+    }
+
+    /* Apply the fit */
+    pol_coefhi = irplib_flat_fit_slope_robust(testpointhi_x,
+            testpointhi_y, IS_NB_TESTPOINTS);
+    pol_coeflo = irplib_flat_fit_slope_robust(testpointlo_x, 
+            testpointlo_y, IS_NB_TESTPOINTS);
+
+    /* Compute the errors */
+    median = cpl_vector_new(IS_NB_TESTPOINTS);
+    median_data = cpl_vector_get_data(median);
+    for (i=0; i<IS_NB_TESTPOINTS; i++) {
+        median_data[i]=SQR(testpointhi_y[i]
+                - pol_coefhi[0] - pol_coefhi[1] * testpointhi_x[i]);
+    }
+    medianerrhi = cpl_vector_get_median(median);
+    for (i=0; i<IS_NB_TESTPOINTS; i++) {
+        median_data[i]=SQR(testpointlo_y[i]
+                - pol_coeflo[0] - pol_coeflo[1] * testpointlo_x[i]);
+    }
+    medianerrlo = cpl_vector_get_median(median);
+    cpl_vector_delete(median);
+    rampdif = testpointlo_y[IS_NB_TESTPOINTS-1] - testpointhi_y[0];
+    slope = rampdif / (ny/2.0);
+    fitslope = (pol_coefhi[1] + pol_coeflo[1]) / 2.0;
+
+    cpl_bivector_delete(testpointlo);
+    cpl_bivector_delete(testpointhi);
+
+    /* Decide if there is a ramp or not  */
+    if (fabs(rampdif)<IS_MIN_RAMP ||
+            fabs(pol_coefhi[1]) < IS_MIN_SLOPE ||
+            fabs(pol_coeflo[1]) < IS_MIN_SLOPE ||
+            pol_coefhi[1]/pol_coeflo[1]<0.5 ||
+            pol_coefhi[1]/pol_coeflo[1]>2.0 ||
+            fabs(pol_coefhi[1]-pol_coeflo[1])>IS_MAX_SLOPE_DIF ||
+            fabs(pol_coefhi[0]-pol_coeflo[0]) > IS_MAX_INTER_DIF ||
+            medianerrlo> IS_MAX_MNERR ||
+            medianerrhi> IS_MAX_MNERR ||
+            fabs(medianerrlo-medianerrhi) >IS_MAX_MNERR_DIF ||
+            fabs(slope-fitslope) > IS_MAX_FIT_EDGE_DIF ||
+            slope/fitslope<0.5 ||
+            slope/fitslope>2.0) ramp_present = 0;
+    else ramp_present = 1;
+
+    cpl_free(pol_coeflo);
+    cpl_free(pol_coefhi);
+
+    /* Correct the ramp if it is there */
+    out = cpl_image_duplicate(in);
+    pout = cpl_image_get_data_float(out);
+    if (ramp_present == 1) {
+        for (j=0; j<ny/2; j++) {
+            val = slope * (j-ny/2);
+            for (i=0; i<nx; i++)
+                pout[i+j*nx] -= val;
+        }
+        for (j=ny/2; j<ny; j++) {
+            val = slope * (j-ny);
+            for (i=0; i<nx; i++)
+                pout[i+j*nx] -= val;
+        }
+
+    }
+
+    return out;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief  Filter the background of an image with horizontal or vertical lines
+  @param  self    Filtered image
+  @param  other   Image to filter, use NULL for in-place filtering
+  @param  hsize   Filtering half-size, total size is 1 + 2 * hsize
+  @param  vertical True iff the lines are vertical
+  @return CPL_ERROR_NONE or the relevant CPL error code
+
+  If the background varies strongly along the line, it can be detected
+  and removed with a unit width 1+2*hsize median filter, where hsize is an
+  upper bound on the line width.
+
+ */
+/*----------------------------------------------------------------------------*/
+static cpl_error_code irplib_image_filter_background_line(cpl_image * self,
+                                                   const cpl_image * other,
+                                                   int hsize,
+                                                   cpl_boolean vertical)
+{
+    const int      nx = cpl_image_get_size_x(self);
+    const int      ny = cpl_image_get_size_y(self);
+    const int      msize = 1 + 2 * hsize;
+    cpl_mask     * mask;
+    cpl_image    * background;
+    cpl_error_code error = CPL_ERROR_NONE;
+
+    cpl_ensure_code(self  != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(hsize >= 0,    CPL_ERROR_ILLEGAL_INPUT);
+
+    if (other == NULL) other = self;
+
+    mask = vertical ? cpl_mask_new(msize, 1) : cpl_mask_new(1, msize);
+
+    error |= cpl_mask_not(mask);
+
+    background = cpl_image_new(nx, ny, cpl_image_get_type(other));
+
+    error |= cpl_image_filter_mask(background, other, mask, CPL_FILTER_MEDIAN,
+                                   CPL_BORDER_FILTER);
+    cpl_mask_delete(mask);
+
+    if (self != other) {
+        error |= cpl_image_copy(self, other, 1, 1);
+    }
+
+    error |= cpl_image_subtract(self, background);
+    cpl_image_delete(background);
+
+    return error ? cpl_error_set_where(cpl_func) : CPL_ERROR_NONE;
+}
+
+
+
+/**
+ * @internal
+ * @brief Create and compute A = B * transpose(B)
+ *
+ * @param self     M x N Matrix
+ * @return Pointer to created M x M product matrix, or @c NULL on error.
+ * @note Only the upper triangle of A is computed, while the elements
+ *       below the main diagonal have undefined values.
+ * @see cpl_matrix_product_normal_create()
+ *
+ * @error
+ *   <table class="ec" align="center">
+ *     <tr>
+ *       <td class="ecl">CPL_ERROR_NULL_INPUT</td>
+ *       <td class="ecr">
+ *         Any input matrix is a <tt>NULL</tt> pointer.
+ *       </td>
+ *     </tr>
+ *   </table>
+ * @enderror
+ *
+ * To destroy the new matrix the function @c cpl_matrix_delete() should
+ * be used.
+ */
+
+static cpl_matrix * irplib_matrix_product_normal_create(const cpl_matrix * self)
+{
+
+    double         sum;
+    cpl_matrix   * product;
+    const double * ai = cpl_matrix_get_data_const(self);
+    const double * aj;
+    double       * bwrite;
+    const int      m = cpl_matrix_get_nrow(self);
+    const int      n = cpl_matrix_get_ncol(self);
+    int            i, j, k;
+
+
+    cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL);
+
+#if 0
+    /* Initialize all values to zero.
+       This is done to avoid access of uninitilized memory,  in case
+       someone passes the matrix to for example cpl_matrix_dump(). */
+    product = cpl_matrix_new(m, m);
+    bwrite = cpl_matrix_get_data(product);
+#else
+    bwrite = (double *) cpl_malloc(m * m * sizeof(double));
+    product = cpl_matrix_wrap(m, m, bwrite);
+#endif
+
+    /* The result at (i,j) is the dot-product of i'th and j'th row */
+    for (i = 0; i < m; i++, bwrite += m, ai += n) {
+        aj = ai; /* aj points to first entry in j'th row */
+        for (j = i; j < m; j++, aj += n) {
+            sum = 0.0;
+            for (k = 0; k < n; k++) {
+                sum += ai[k] * aj[k];
+            }
+            bwrite[j] = sum;
+        }
+    }
+
+    return product;
+
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @internal
+  @brief    Fit a 2D-polynomial to a 2D-surface in a least squares sense
+  @param    xy_pos  Bivector  positions of the surface to fit.
+  @param    values  Vector of values of the surface to fit.
+  @param    degree  Positive polynomial degree
+  @param    fixy    Fix-point in Y
+  @param    mse     Iff mse is not null, the mean squared error on success
+  @return   The fitted polynomial or NULL on error
+  @see cpl_polynomial_fit_2d_createe
+  @note The fix-point is not supported by cpl_polynomial_fit_2d_create()
+
+ */
+/*----------------------------------------------------------------------------*/
+static cpl_error_code irplib_polynomial_fit_2d(cpl_polynomial * self,
+                                               const cpl_bivector * xy_pos,
+                                               const cpl_vector * values,
+                                               int degree, double fixy,
+                                               double * mse)
+{
+
+    const int        np = cpl_bivector_get_size(xy_pos);
+    /* Number of unknowns to determine in one dimension */
+    const int        nc1 = 1+degree;
+    /* Number of unknowns to determine */
+    /* P_{i,0} = 0, except P_{1,0} = 1 */
+    const int        nc = nc1 * (1 + nc1) / 2 - nc1;
+    cpl_matrix     * mv;   /* The transpose of the Vandermonde matrix */
+    cpl_matrix     * mh;   /* Block-Hankel matrix, V'*V */
+    cpl_matrix     * mb;
+    cpl_matrix     * mx;
+#ifdef IRPLIB_DISTORTION_ASSERT
+    const double   * coeffs1d;
+#endif
+    double         * dmv;
+    cpl_vector     * xhat;
+    cpl_vector     * yhat;
+    cpl_vector     * zhat;
+    cpl_size         powers[2];
+    int              degx, degy;
+    int              i, j;
+    cpl_error_code   error;
+   
+
+    cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(cpl_polynomial_get_dimension(self) == 2,
+                    CPL_ERROR_INVALID_TYPE);
+    cpl_ensure_code(np > 0,         cpl_error_get_code());
+    cpl_ensure_code(values != NULL, CPL_ERROR_NULL_INPUT);
+
+    cpl_ensure_code(cpl_vector_get_size(values) == np,
+                    CPL_ERROR_INCOMPATIBLE_INPUT);
+
+    cpl_ensure_code(degree > 0, CPL_ERROR_ILLEGAL_INPUT);
+    cpl_ensure_code(np >= nc,   CPL_ERROR_DATA_NOT_FOUND);
+
+    /* transform zero-point to fixy */
+    yhat = cpl_vector_duplicate(cpl_bivector_get_y_const(xy_pos));
+    cpl_vector_subtract_scalar(yhat, fixy);
+
+    /* - and ensure P(y) = y on center line */
+    xhat = cpl_vector_duplicate(cpl_bivector_get_x_const(xy_pos));
+    zhat = cpl_vector_duplicate(values);
+    cpl_vector_subtract(zhat, xhat);
+
+    /* Initialize matrices */
+    /* mv contains the polynomial terms in the order described */
+    /* above in each row, for each input point. */
+    dmv = (double*)cpl_malloc(nc*np*sizeof(double));
+    mv = cpl_matrix_wrap(nc, np, dmv);
+
+    /* Has redundant FLOPs, appears to improve accuracy */
+    for (i=0; i < np; i++) {
+        const double x = cpl_vector_get(xhat, i);
+        const double y = cpl_vector_get(yhat, i);
+        double xvalue;
+        double yvalue = y;
+        j = 0;
+        for (degy = 1; degy <= degree; degy++) {
+            xvalue = 1;
+            for (degx = 0; degx <= degree-degy; degx++, j++) {
+                dmv[np * j + i] = xvalue * yvalue;
+                xvalue *= x;
+            }
+            yvalue *= y;
+        }
+        /* cx_assert( j == nc ); */
+    }
+    cpl_vector_delete(xhat);
+    cpl_vector_delete(yhat);
+
+    /* mb contains the values, it is not modified */
+    mb = cpl_matrix_wrap(np, 1, cpl_vector_get_data(zhat));
+
+    /* Form the right hand side of the normal equations */
+    mx = cpl_matrix_product_create(mv, mb);
+
+    cpl_matrix_unwrap(mb);
+    cpl_vector_delete(zhat);
+
+    /* Form the matrix of the normal equations */
+    mh = irplib_matrix_product_normal_create(mv);
+    cpl_matrix_delete(mv);
+
+    /* Solve XA=B by a least-square solution (aka pseudo-inverse). */
+    error = cpl_matrix_decomp_chol(mh) || cpl_matrix_solve_chol(mh, mx);
+
+    cpl_matrix_delete(mh);
+
+    if (error) {
+        cpl_matrix_delete(mx);
+        cpl_ensure_code(0, error);
+    }
+
+    /* Store coefficients for output */
+
+#ifdef IRPLIB_DISTORTION_ASSERT
+    coeffs1d = cpl_matrix_get_data(mx);
+#endif
+
+    j = 0;
+    for (degy = 1; degy <= degree; degy++) {
+        powers[1] = degy;
+        for (degx = 0; degx <= degree-degy; degx++, j++) {
+            powers[0] = degx;
+            /* cx_assert( coeffs1d[j] == cpl_matrix_get(mx, j, 0) ); */
+            cpl_polynomial_set_coeff(self, powers, cpl_matrix_get(mx, j, 0));
+        }
+    }
+    /* cx_assert( j == nc ); */
+
+    cpl_matrix_delete(mx);
+
+    /* P_{1,0} = 1 */
+    powers[0] = 1;
+    powers[1] = 0;
+    cpl_polynomial_set_coeff(self, powers, 1.0);
+
+    /* Transform the polynomial back in Y */
+    cpl_polynomial_shift_1d(self, 1, -fixy);
+
+    /* If requested, compute mean squared error */
+    if (mse != NULL) {
+        const cpl_vector * x_pos = cpl_bivector_get_x_const(xy_pos);
+        const cpl_vector * y_pos = cpl_bivector_get_y_const(xy_pos);
+        cpl_vector * x_val = cpl_vector_new(2);
+        double residue;
+
+        *mse = 0;
+        for (i=0; i<np; i++) {
+            cpl_vector_set(x_val, 0, cpl_vector_get(x_pos, i));
+            cpl_vector_set(x_val, 1, cpl_vector_get(y_pos, i));
+            /* Subtract from the true value, square, accumulate */
+            residue = cpl_vector_get(values, i)
+                - cpl_polynomial_eval(self, x_val);
+            *mse += residue * residue;
+        }
+        cpl_vector_delete(x_val);
+        /* Average the error term */
+        *mse /= np;
+    }
+
+    return CPL_ERROR_NONE;
+}
+
diff --git a/irplib/irplib_distortion.h b/irplib/irplib_distortion.h
new file mode 100644
index 0000000..54bdee0
--- /dev/null
+++ b/irplib/irplib_distortion.h
@@ -0,0 +1,44 @@
+/* $Id: irplib_distortion.h,v 1.5 2006/07/26 14:47:34 yjung Exp $
+ *
+ * This file is part of the irplib package
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: yjung $
+ * $Date: 2006/07/26 14:47:34 $
+ * $Revision: 1.5 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifndef IRPLIB_DISTORTION_H
+#define IRPLIB_DISTORTION_H
+
+/*-----------------------------------------------------------------------------
+   								Includes
+ -----------------------------------------------------------------------------*/
+
+#include <cpl.h>
+
+/*-----------------------------------------------------------------------------
+   							        Prototypes
+ -----------------------------------------------------------------------------*/
+
+cpl_polynomial * irplib_distortion_estimate(const cpl_image *, int, int, int, 
+        int, int, int, int, double, int, cpl_apertures **) ;
+
+#endif
diff --git a/irplib/irplib_flat.c b/irplib/irplib_flat.c
new file mode 100644
index 0000000..3ea57c7
--- /dev/null
+++ b/irplib/irplib_flat.c
@@ -0,0 +1,402 @@
+/* $Id: irplib_flat.c,v 1.15 2007/08/07 12:15:41 llundin Exp $
+ *
+ * This file is part of the irplib package
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: llundin $
+ * $Date: 2007/08/07 12:15:41 $
+ * $Revision: 1.15 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+/*-----------------------------------------------------------------------------
+                                   Includes
+ -----------------------------------------------------------------------------*/
+
+#include <math.h>
+#include <cpl.h>
+
+#include "irplib_flat.h"
+
+/*-----------------------------------------------------------------------------
+                            Functions prototypes
+ -----------------------------------------------------------------------------*/
+
+static double * irplib_flat_fit_proportional(double *, double *, int) ;
+
+/*----------------------------------------------------------------------------*/
+/**
+ * @defgroup irplib_flat    Functions for flatfielding 
+ */
+/*----------------------------------------------------------------------------*/
+
+/**@{*/
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Compute a flat-field out of a set of exposures.
+  @param    raw     Input image set 
+  @param    mode    0 for proportional, 1 for robust fit
+  @return   1 newly allocated set of 2 or 3 images 
+
+  The input is assumed to be a cube containing planes of different intensities 
+  (usually increasing or decreasing). Typical inputs are: twilight data sets, 
+  halogen lamp, or skies of different airmasses in the thermal regime.
+
+  The input image list must be of type float.
+  
+  In robust mode, the output is a set of 3 images. 
+  The first image contains a regression map, i.e. for each pixel position on 
+  the detector, a curve is plotted of the pixel intensity in each plane 
+  against the median intensity of the plane. A slope is fit, and the gain 
+  factor is stored into this first image.
+
+  The second image contains the y-intercepts of the slope fit. It is usually 
+  good to check it out in case of failures.
+
+  The third image contains the sum of squared errors for each fit.
+  The fit is using a robust least-squares criterion rejecting outliers. This 
+  is the algorithm to use with big telescopes like the VLT, which collect so 
+  much light that objects are actually seen in the twilight sky.  
+
+  In proportional mode, the output is a set of 2 images.
+  The first image contains a regression map.
+  The second image contains the sum of squared errors for each fit.
+ */
+/*----------------------------------------------------------------------------*/
+cpl_imagelist * irplib_flat_fit_set(
+        cpl_imagelist   *   raw,
+        int                 mode)
+{
+    double          *   plane_med    = NULL ;
+    double          *   slope        = NULL ;
+    cpl_image       *   gain         = NULL ;
+    double          *   pgain        = NULL ;
+    cpl_image       *   intercept    = NULL ;
+    double          *   pintercept   = NULL ;
+    cpl_image       *   sq_err       = NULL ;
+    double          *   psq_err      = NULL ;
+    double          *   timeline     = NULL ;
+    float           *   raw_im_data  = NULL ;
+    cpl_imagelist   *   result       = NULL ;
+    const int           nx = cpl_image_get_size_x(cpl_imagelist_get(raw, 0));
+    const int           ny = cpl_image_get_size_y(cpl_imagelist_get(raw, 0));
+    const int           ni = cpl_imagelist_get_size(raw);
+    int                 i, j ;
+
+    /* Check entries */
+    if (raw==NULL) return NULL ;
+    if ((mode != 0) && (mode != 1)) return NULL ;
+    if (cpl_image_get_type(cpl_imagelist_get(raw, 0)) != CPL_TYPE_FLOAT)
+        return NULL ;
+    if (cpl_imagelist_get_size(raw) <= 1) return NULL ;
+
+    /* Compute median for all planes */
+    plane_med = cpl_malloc(ni * sizeof(double)) ;
+    for (i=0 ; i<ni ; i++)
+        plane_med[i] = cpl_image_get_median(cpl_imagelist_get(raw, i));
+
+    /* Create result images */
+    gain = cpl_image_new(nx, ny, CPL_TYPE_DOUBLE) ;
+    pgain = cpl_image_get_data_double(gain) ;
+    if (mode == 1) {
+        intercept = cpl_image_new(nx, ny, CPL_TYPE_DOUBLE) ;
+        pintercept = cpl_image_get_data_double(intercept) ;
+    }
+    sq_err = cpl_image_new(nx, ny, CPL_TYPE_DOUBLE) ;
+    psq_err = cpl_image_get_data_double(sq_err) ;
+    timeline = cpl_malloc(ni * sizeof(double)) ;
+
+    /* Loop on all pixel positions */
+    cpl_msg_info(cpl_func, "Computing gains for all positions (long)...") ;
+    for (i=0 ; i<nx * ny ; i++) {
+        /* extract time line */
+        for (j=0 ; j<ni ; j++) {
+            raw_im_data = cpl_image_get_data_float(cpl_imagelist_get(raw, j)) ;
+            timeline[j] = (double)raw_im_data[i] ;
+        }
+        /* Fit slope to this time line */
+        if (mode == 1) {
+            slope = irplib_flat_fit_slope_robust(plane_med, timeline, ni) ;
+            pintercept[i] = slope[0] ;
+            pgain[i]      = slope[1] ;
+            psq_err[i]    = slope[2] ;
+            /* Set results in output images */
+        } else {
+            slope = irplib_flat_fit_proportional(plane_med, timeline, ni) ;
+            /* Set results in output images */
+            pgain[i]      = slope[0] ;
+            psq_err[i]    = slope[1] ;
+        }
+        cpl_free(slope);
+    }
+    cpl_free(plane_med) ;
+    cpl_free(timeline) ;
+
+    /* Return */
+    result = cpl_imagelist_new() ;
+    if (mode == 1) {
+        cpl_imagelist_set(result, gain, 0) ;
+        cpl_imagelist_set(result, intercept, 1) ;
+        cpl_imagelist_set(result, sq_err, 2) ;
+    } else {
+        cpl_imagelist_set(result, gain, 0) ;
+        cpl_imagelist_set(result, sq_err, 1) ;
+    }
+    return result ;
+}
+
+/* @cond */
+#define SIGN(a,b) ((b) >= 0.0 ? fabs(a) : -fabs(a))
+#define MAX_ITERATE     30
+/* @endcond */
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Fit a slope to a list of points (robust fit).
+  @param    x   x coordinates 
+  @param    y   y coordinates 
+  @param    np  number of points 
+  @return   Pointer to newly allocated array of 3 doubles.
+
+  The slope to fit has the following kind of equation:
+  y = c[0] + c[1] * x
+
+  The returned coefficients are defined as:
+  c[0] is the y-intercept.
+  c[1] is the slope.
+  c[2] is the median squared error of the fit.
+  This is a very robust slope fit. It tolerates up to 50% of outliers in input.
+ */
+/*----------------------------------------------------------------------------*/
+double * irplib_flat_fit_slope_robust(
+        double  *   x,
+        double  *   y,
+        int         np)
+{
+    double      *   c ;
+    double          aa, bb, bcomp, b1, b2, del, abdevt, f, f1, f2, sigb, temp,
+                    d, sum ;
+    double          sx, sy, sxy, sxx, chisq ;
+    cpl_vector  *   arr ;
+    double      *   parr ;
+    double          aa_ls, bb_ls ;
+    int             iter ;
+    int             i ;
+
+    /* Check entries */
+    if (x==NULL || y==NULL) return NULL ;
+
+    c = cpl_malloc(3 * sizeof(double)) ;
+
+    sx = sy = sxx = sxy = 0.00 ;
+    for (i=0 ; i<np ; i++) {
+        sx  += x[i];
+        sy  += y[i];
+        sxy += x[i] * y[i];
+        sxx += x[i] * x[i];
+    }
+
+    del = np * sxx - sx * sx;
+    aa_ls = aa  = (sxx * sy - sx * sxy) / del;
+    bb_ls = bb  = (np * sxy - sx * sy) / del;
+
+    chisq = 0.00 ;
+    for (i=0;i<np;i++) {
+        temp = y[i] - (aa+bb*x[i]) ;
+        temp *= temp ;
+        chisq += temp ;
+    }
+
+    arr = cpl_vector_new(np) ;
+    parr = cpl_vector_get_data(arr) ;
+    sigb = sqrt(chisq/del);
+    b1   = bb ;
+
+    bcomp = b1 ;
+    sum = 0.00 ;
+    for (i=0 ; i<np ; i++) {
+            parr[i] = y[i] - bcomp * x[i];
+        }
+    aa = cpl_vector_get_median(arr); /* arr permuted */
+    abdevt = 0.0;
+    for (i=0 ; i<np ; i++) {
+        d = y[i] - (bcomp * x[i] + aa);
+        abdevt += fabs(d);
+        if (fabs(y[i]) > 1e-7) d /= fabs(y[i]);
+        if (fabs(d) > 1e-7) sum += (d >= 0.0 ? x[i] : -x[i]);
+    }
+    f1 = sum ;
+    b2   = bb + SIGN(3.0 * sigb, f1);
+    bcomp = b2 ;
+    sum = 0.00 ;
+    for (i=0 ; i<np ; i++) parr[i] = y[i] - bcomp * x[i];
+    aa = cpl_vector_get_median(arr);  /* arr permuted */
+    abdevt = 0.0;
+    for (i=0 ; i<np ; i++) {
+        d = y[i] - (bcomp * x[i] + aa);
+        abdevt += fabs(d);
+        if (fabs(y[i]) > 1e-7) d /= fabs(y[i]);
+        if (fabs(d) > 1e-7) sum += (d >= 0.0 ? x[i] : -x[i]);
+    }
+    f2 = sum ;
+
+    if (fabs(b2-b1)<1e-7) {
+        c[0] = aa ;
+        c[1] = bb ;
+        c[2] = abdevt / (double)np;
+        cpl_vector_delete(arr);
+        return c ;
+    }
+
+    iter = 0 ;
+    while (f1*f2 > 0.0) {
+        bb = 2.0*b2-b1;
+        b1 = b2;
+        f1 = f2;
+        b2 = bb;
+
+        bcomp = b2 ;
+        sum = 0.00 ;
+        for (i=0 ; i<np ; i++) parr[i] = y[i] - bcomp * x[i];
+        aa = cpl_vector_get_median(arr); /* arr permuted */
+        abdevt = 0.0;
+        for (i=0 ; i<np ; i++) {
+            d = y[i] - (bcomp * x[i] + aa);
+            abdevt += fabs(d);
+            if (fabs(y[i]) > 1e-7) d /= fabs(y[i]);
+            if (fabs(d) > 1e-7) sum += (d >= 0.0 ? x[i] : -x[i]);
+        }
+        f2 = sum ;
+        iter++;
+        if (iter>=MAX_ITERATE) break ;
+    }
+    if (iter>=MAX_ITERATE) {
+        c[0] = aa_ls ;
+        c[1] = bb_ls ;
+        c[2] = -1.0 ;
+        cpl_vector_delete(arr);
+        return c ;
+    }
+
+    sigb = 0.01 * sigb;
+    while (fabs(b2-b1) > sigb) {
+        bb = 0.5 * (b1 + b2) ;
+        if ((fabs(bb-b1)<1e-7) || (fabs(bb-b2)<1e-7)) break;
+        bcomp = bb ;
+        sum = 0.00 ;
+        for (i=0 ; i<np ; i++) parr[i] = y[i] - bcomp * x[i];
+        aa = cpl_vector_get_median(arr); /* arr permuted */
+        abdevt = 0.0;
+        for (i=0 ; i<np ; i++) {
+            d = y[i] - (bcomp * x[i] + aa);
+            abdevt += fabs(d);
+            if (fabs(y[i]) > 1e-7) d /= fabs(y[i]);
+            if (fabs(d) > 1e-7) sum += (d >= 0.0 ? x[i] : -x[i]);
+        }
+        f = sum ;
+
+        if (f*f1 >= 0.0) {
+            f1=f;
+            b1=bb;
+        } else {
+            f2=f;
+            b2=bb;
+        }
+    }
+    cpl_vector_delete(arr) ;
+    c[0]=aa;
+    c[1]=bb;
+    c[2]=abdevt/np;
+    return c ;
+}
+#undef MAX_ITERATE
+#undef SIGN
+
+
+/**@}*/
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Compute a=y/x for all given points
+  @param    x   x coordinates 
+  @param    y   y coordinates 
+  @param    np  number of points 
+  @return   Pointer to newly allocated array of two doubles.
+
+  This function takes in input a list of points supposed all aligned
+  on a slope going through the origin (of equation y=ax). It computes
+  the slope a = y/x for all points, and returns a pointer to two
+  doubles:
+
+  \begin{itemize}
+  \item The median slope.
+  \item The mean squared error.
+  \end{itemize}
+
+  Returning the median of all slopes makes it very robust to outliers.
+  A more precise method would be to make a histogram of all slopes and
+  take the maximum (i.e. the mode of the distribution). It can be
+  shown that the median approximates the mode quite well for a large
+  number of points.
+ */
+/*----------------------------------------------------------------------------*/
+#define FITPROP_BIG_SLOPE   1e30
+static double * irplib_flat_fit_proportional(
+        double  *   x,
+        double  *   y,
+        int         np)
+{
+    cpl_vector  *   slopes ;
+    double      *   pslopes ;
+    double      *   med_slope ;
+    double          val ;
+    double          sq_err ;
+    int             i ;
+
+    /* Check entries */
+    if (x==NULL || y==NULL) return NULL ;
+
+    slopes = cpl_vector_new(np) ;
+    pslopes = cpl_vector_get_data(slopes) ;
+    for (i=0 ; i<np ; i++) {
+        if (fabs(x[i])>1e-30)  pslopes[i] = y[i] / x[i] ;
+        else                   pslopes[i] = FITPROP_BIG_SLOPE ;
+    }
+    med_slope = cpl_malloc(2 * sizeof(double));
+    med_slope[0] = cpl_vector_get_median(slopes); /* slopes permuted */
+    cpl_vector_delete(slopes);
+
+    sq_err = 0.00 ;
+    for (i=0 ; i<np ; i++) {
+        val = med_slope[0] * x[i] ;
+        sq_err += (val-y[i])*(val-y[i]) ;
+    }
+    sq_err /= (double)np ;
+    med_slope[1] = sq_err ;
+
+    return med_slope ;
+#undef FITPROP_BIG_SLOPE
+}
+
+
+
diff --git a/irplib/irplib_flat.h b/irplib/irplib_flat.h
new file mode 100644
index 0000000..62d855a
--- /dev/null
+++ b/irplib/irplib_flat.h
@@ -0,0 +1,40 @@
+/* $Id: irplib_flat.h,v 1.4 2005/09/15 11:47:16 llundin Exp $
+ *
+ * This file is part of the irplib package
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: llundin $
+ * $Date: 2005/09/15 11:47:16 $
+ * $Revision: 1.4 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifndef IRPLIB_FLAT_H
+#define IRPLIB_FLAT_H
+
+/*-----------------------------------------------------------------------------
+                                   Includes
+ -----------------------------------------------------------------------------*/
+
+#include <cpl.h>
+
+cpl_imagelist * irplib_flat_fit_set(cpl_imagelist *, int) ;
+double * irplib_flat_fit_slope_robust(double *, double *, int) ;
+
+#endif
diff --git a/irplib/irplib_framelist.c b/irplib/irplib_framelist.c
new file mode 100644
index 0000000..d3ac8d6
--- /dev/null
+++ b/irplib/irplib_framelist.c
@@ -0,0 +1,1289 @@
+/* $Id: irplib_framelist.c,v 1.29 2012/02/03 13:55:14 llundin Exp $
+ *
+ * This file is part of the irplib package 
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: llundin $
+ * $Date: 2012/02/03 13:55:14 $
+ * $Revision: 1.29 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+
+/*-----------------------------------------------------------------------------
+                                 Includes
+ -----------------------------------------------------------------------------*/
+
+#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+#include <regex.h>
+#include <math.h>
+#include <assert.h>
+
+#include <cpl.h>
+
+#include "irplib_framelist.h"
+
+
+/*-----------------------------------------------------------------------------
+                                 New types
+ -----------------------------------------------------------------------------*/
+
+/* @cond */
+struct _irplib_framelist_ {
+    int size;
+    cpl_frame        ** frame;
+    cpl_propertylist ** propertylist;
+
+};
+/* @endcond */
+
+/*-----------------------------------------------------------------------------
+                                 Private funcions
+ -----------------------------------------------------------------------------*/
+
+static void irplib_framelist_set_size(irplib_framelist *)
+#if defined __GNUC__ &&  __GNUC__ >= 4
+    __attribute__((nonnull))
+#endif
+;
+
+static cpl_boolean irplib_property_equal(const cpl_propertylist *,
+                                         const cpl_propertylist *,
+                                         const char *, cpl_type, double,
+                                         char **, char **)
+#if defined __GNUC__ &&  __GNUC__ >= 4
+    __attribute__((nonnull))
+#endif
+;
+
+/*----------------------------------------------------------------------------*/
+/**
+ * @defgroup irplib_framelist  Lists of frames with properties.
+
+   This module implements a container type for frames and their propertylists.
+   It differs from the cpl_frameset in these ways:
+   1) A propertylist can be associated to each frame
+   2) Access by index is a O(1)-operation
+   3) It can not be corrupted due to caching bugs (e.g. DFS02731).
+
+   @par Synopsis:
+   @code
+     #include <irplib_framelist.h>
+   @endcode
+
+   @par Example:
+   @code
+
+   static int rrecipe(cpl_frameset * frameset)
+   {
+      // Error handling omitted for brevity
+
+      irplib_framelist * allframes = irplib_framelist_cast(frameset);
+
+      // Get raw frames of either type
+      irplib_framelist * rawframes = irplib_framelist_extract_regexp(allframes,
+                                                                   "^("
+                                                                   RAW_TYPE1 "|"
+                                                                   RAW_TYPE2 ")$",
+                                                                   CPL_FALSE);
+
+      // Load the list of images
+      cpl_imagelist * ilist = irplib_imagelist_load_framelist(rawframes,
+                                                              CPL_TYPE_FLOAT,
+                                                              0, 0);
+
+      const cpl_propertylist * plist;
+
+      // A regular expression of the FITS cards needed by this recipe
+      const char cards[] = "^(RA|DEC|EXPTIME)$";
+      double ra, dec;
+
+
+      // Load the specified FITS cards for all raw frames
+      irplib_framelist_load_propertylist_all(rawframes, 0, cards, CPL_FALSE));
+
+
+      // Verify the presence and uniformity of the FITS cards
+      if (irplib_framelist_contains(rawframes, "RA",
+                                     CPL_TYPE_DOUBLE, CPL_TRUE, 1e-5)) {
+         // RA is missing in one or more headers
+         //  - or it varies by more than 1e-5
+      }
+
+       if (irplib_framelist_contains(rawframes, "DEC",
+                                     CPL_TYPE_DOUBLE, CPL_TRUE, 1e-5)) {
+         // DEC is missing in one or more headers
+         //  - or it varies by more than 1e-5
+      }
+
+      // Process the FITS cards 
+      plist = irplib_framelist_get_propertylist_const(rawframes, 0);
+
+      ra  = cpl_propertylist_get_double(plist, "RA");
+      dec = cpl_propertylist_get_double(plist, "DEC");
+
+      // Object deallocation
+      irplib_framelist_delete(allframes);
+      irplib_framelist_delete(rawframes);
+      cpl_imagelist_delete(ilist);
+
+      return 0;
+
+   }
+
+   @endcode
+
+
+ */
+/*----------------------------------------------------------------------------*/
+
+/**@{*/
+
+/*-----------------------------------------------------------------------------
+                            Function codes
+ -----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Create an empty framelist
+  @return   1 newly allocated irplib_framelist
+  @note The returned irplib_framelist must be deallocated using
+        irplib_framelist_delete()
+
+ */
+/*----------------------------------------------------------------------------*/
+irplib_framelist * irplib_framelist_new(void)
+{
+
+    return (irplib_framelist *) cpl_calloc(1, sizeof(irplib_framelist));
+
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Deallocate an irplib_framelist with its frames and properties
+  @param    self  the framelist
+ */
+/*----------------------------------------------------------------------------*/
+void irplib_framelist_delete(irplib_framelist * self)
+{
+
+    irplib_framelist_empty(self);
+    cpl_free(self);
+}
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Create an irplib_framelist from a cpl_framelist
+  @param    frameset The cpl_frameset
+  @return   1 newly allocated irplib_framelist or NULL on error
+  @note The returned irplib_framelist must be deallocated using
+        irplib_framelist_delete()
+
+ */
+/*----------------------------------------------------------------------------*/
+irplib_framelist * irplib_framelist_cast(const cpl_frameset * frameset)
+{
+
+    irplib_framelist * self;
+    const cpl_frame * frame;
+    int i;
+
+
+    cpl_ensure(frameset != NULL, CPL_ERROR_NULL_INPUT, NULL);
+
+    /* The function cannot fail now */
+    self = irplib_framelist_new();
+
+    for (i = 0, frame = cpl_frameset_get_first_const(frameset);
+         frame != NULL;
+         i++, frame = cpl_frameset_get_next_const(frameset)) {
+
+        cpl_frame * copy = cpl_frame_duplicate(frame);
+
+        const cpl_error_code error = irplib_framelist_set(self, copy, i);
+
+        assert(error == CPL_ERROR_NONE);
+
+    }
+
+    assert(self->size == cpl_frameset_get_size(frameset));
+
+    return self;
+
+}
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Create a CPL frameset from an irplib_framelist
+  @param    self    The framelist
+  @return   1 newly allocated cpl_frameset or NULL on error
+  @note The returned cpl_frameset must be deallocated using
+        cpl_frameset_delete()
+
+ */
+/*----------------------------------------------------------------------------*/
+cpl_frameset * irplib_frameset_cast(const irplib_framelist * self)
+{
+
+    cpl_frameset * new;
+    int i;
+
+    cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL);
+
+    /* The function cannot fail now */
+    new = cpl_frameset_new();
+
+    for (i = 0; i < self->size; i++) {
+        cpl_frame * frame = cpl_frame_duplicate(self->frame[i]);
+        const cpl_error_code error = cpl_frameset_insert(new, frame);
+
+        assert(error == CPL_ERROR_NONE);
+
+    }
+
+    assert(self->size == cpl_frameset_get_size(new));
+
+    return new;
+
+}
+
+
+/*----------------------------------------------------------------------------*/
+/**
+   @brief Extract the frames with the given tag from a framelist
+   @param self  A non-empty framelist
+   @param tag   The frame tag to search for.
+   @return      The newly created framelist or NULL on error
+   @see         cpl_frameset_find
+   @note Any propertylists of the extracted frames are also extracted.
+         It is an error if no matching frames are found, in which case
+         an error is set.
+
+ */
+/*----------------------------------------------------------------------------*/
+irplib_framelist * irplib_framelist_extract(const irplib_framelist * self,
+                                            const char * tag)
+{
+
+    irplib_framelist * new;
+    int i, newsize;
+
+
+    cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL);
+    cpl_ensure(tag  != NULL, CPL_ERROR_NULL_INPUT, NULL);
+
+    new = irplib_framelist_new();
+    newsize = 0;
+
+    for (i = 0; i < self->size; i++) {
+        const cpl_frame * frame = self->frame[i];
+        const char * ftag = cpl_frame_get_tag(frame);
+        cpl_frame * copy;
+        cpl_error_code error;
+
+        if (ftag == NULL) {
+            /* The frame is ill-formed */
+            irplib_framelist_delete(new);
+            cpl_ensure(0, CPL_ERROR_ILLEGAL_INPUT, NULL);
+        }
+
+        if (strcmp(tag, ftag)) continue;
+
+        copy = cpl_frame_duplicate(frame);
+
+        error = irplib_framelist_set(new, copy, newsize);
+        assert(error == CPL_ERROR_NONE);
+
+        if (self->propertylist[i] != NULL) new->propertylist[newsize]
+            = cpl_propertylist_duplicate(self->propertylist[i]);
+
+        newsize++;
+    }
+
+    assert( newsize == new->size );
+
+    if (newsize == 0) {
+#if defined CPL_HAVE_VA_ARGS && CPL_HAVE_VA_ARGS != 0
+        cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
+                              "The list of %d frame(s) has no frames "
+                              "with tag: %s", self->size, tag);
+#else
+        cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
+                              "The list of frame(s) has no frames "
+                              "with the given tag");
+#endif
+        irplib_framelist_delete(new);
+        new = NULL;
+    }
+
+    return new;
+
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+   @brief Extract the frames with the given tag from a framelist
+   @param self   A non-empty framelist
+   @param regexp The regular expression of frame tag(s) to search for.
+   @param invert Boolean to invert the sense of the pattern matching.
+   @return       The newly created framelist or NULL on error
+   @see irplib_framelist_extract
+
+ */
+/*----------------------------------------------------------------------------*/
+irplib_framelist * irplib_framelist_extract_regexp(const irplib_framelist* self,
+                                                   const char * regexp,
+                                                   cpl_boolean invert)
+{
+
+    irplib_framelist * new;
+    int error;
+    int i, newsize;
+    const int xor = invert == CPL_FALSE ? 0 : 1;
+    regex_t re;
+
+
+    cpl_ensure(self   != NULL, CPL_ERROR_NULL_INPUT, NULL);
+    cpl_ensure(regexp != NULL, CPL_ERROR_NULL_INPUT, NULL);
+
+    error = regcomp(&re, regexp, REG_EXTENDED | REG_NOSUB);
+    cpl_ensure(!error, CPL_ERROR_ILLEGAL_INPUT, NULL);
+
+    new = irplib_framelist_new();
+    newsize = 0;
+
+    for (i = 0; i < self->size; i++) {
+        const cpl_frame * frame = self->frame[i];
+        const char * tag = cpl_frame_get_tag(frame);
+        cpl_frame * copy;
+
+        if (tag == NULL) {
+            /* The frame is ill-formed */
+            irplib_framelist_delete(new);
+            regfree(&re);
+            cpl_ensure(0, CPL_ERROR_ILLEGAL_INPUT, NULL);
+        }
+
+        if ((regexec(&re, tag, (size_t)0, NULL, 0) == REG_NOMATCH ? 1 : 0)
+            ^ xor) continue;
+
+        copy = cpl_frame_duplicate(frame);
+
+        error = (int)irplib_framelist_set(new, copy, newsize);
+        assert(error == CPL_ERROR_NONE);
+
+        if (self->propertylist[i] != NULL) new->propertylist[newsize]
+            = cpl_propertylist_duplicate(self->propertylist[i]);
+
+        newsize++;
+
+    }
+
+    regfree(&re);
+
+    assert( newsize == new->size );
+
+    if (newsize == 0) {
+#if defined CPL_HAVE_VA_ARGS && CPL_HAVE_VA_ARGS != 0
+        cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
+                              "The list of %d frame(s) has no frames "
+                              "that match: %s", self->size, regexp);
+#else
+        cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
+                              "The list of frames has no frames "
+                              "that match the regular expression");
+#endif
+        irplib_framelist_delete(new);
+        new = NULL;
+    }
+
+    return new;
+}
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Get the size of a framelist
+  @param    self  The framelist
+  @return   The size or a negative number on error
+
+ */
+/*----------------------------------------------------------------------------*/
+int irplib_framelist_get_size(const irplib_framelist * self)
+{
+
+    cpl_ensure(self != NULL,  CPL_ERROR_NULL_INPUT, -1);
+
+    return self->size;
+
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Get the specified frame from the framelist
+  @param    self  The framelist
+  @param    pos   position (0 for first)
+  @return   The frame or NULL on error
+
+ */
+/*----------------------------------------------------------------------------*/
+cpl_frame * irplib_framelist_get(irplib_framelist * self, int pos)
+{
+    return (cpl_frame *)irplib_framelist_get_const(self, pos);
+
+}
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Get the specified frame from the framelist
+  @param    self  The framelist
+  @param    pos   position (0 for first)
+  @return   The frame or NULL on error
+
+ */
+/*----------------------------------------------------------------------------*/
+const cpl_frame * irplib_framelist_get_const(const irplib_framelist * self,
+                                             int pos)
+{
+
+    cpl_ensure(self != NULL,      CPL_ERROR_NULL_INPUT,          NULL);
+    cpl_ensure(pos >= 0,          CPL_ERROR_ILLEGAL_INPUT,       NULL);
+    cpl_ensure(pos  < self->size, CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL);
+
+    return self->frame[pos];
+
+}
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Duplicate a propertylist to the specified position in the framelist
+  @param    self   The framelist to modify
+  @param    pos    position (0 for first).
+  @param    list   The propertylist to copy
+  @return   CPL_ERROR_NONE or the relevant CPL error code
+
+ */
+/*----------------------------------------------------------------------------*/
+cpl_error_code irplib_framelist_set_propertylist(irplib_framelist * self,
+                                                 int pos,
+                                                 const cpl_propertylist * list)
+{
+
+    cpl_ensure_code(self != NULL,      CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(list != NULL,      CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(pos  >= 0,         CPL_ERROR_ILLEGAL_INPUT);
+    cpl_ensure_code(pos  < self->size, CPL_ERROR_ACCESS_OUT_OF_RANGE);
+
+    cpl_propertylist_delete(self->propertylist[pos]);
+
+    self->propertylist[pos] = cpl_propertylist_duplicate(list);
+
+    cpl_ensure_code(self->propertylist[pos] != NULL, cpl_error_get_code());
+
+    return CPL_ERROR_NONE;
+
+}
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Get the propertylist of the specified frame in the framelist
+  @param    self  The framelist
+  @param    pos   position (0 for first)
+  @return   The propertylist or NULL on error
+  @note The propertylist must first be created, for example with
+        irplib_framelist_load_propertylist(self, pos, ...), otherwise
+        an error occurs.
+
+ */
+/*----------------------------------------------------------------------------*/
+cpl_propertylist * irplib_framelist_get_propertylist(irplib_framelist * self,
+                                                     int pos)
+{
+
+    return (cpl_propertylist *)irplib_framelist_get_propertylist_const(self,
+                                                                       pos);
+
+}
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Get the propertylist of the specified frame in the framelist
+  @param    self  The framelist
+  @param    pos   position (0 for first)
+  @return   The propertylist or NULL on error
+  @note The propertylist must first be created, for example with
+        irplib_framelist_load_propertylist(self, pos, ...), otherwise
+        an error occurs.
+
+ */
+/*----------------------------------------------------------------------------*/
+const cpl_propertylist * irplib_framelist_get_propertylist_const(
+                                                  const irplib_framelist * self,
+                                                  int pos)
+{
+    cpl_ensure(self != NULL,      CPL_ERROR_NULL_INPUT,          NULL);
+    cpl_ensure(pos  >= 0,         CPL_ERROR_ILLEGAL_INPUT,       NULL);
+    cpl_ensure(pos  < self->size, CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL);
+
+    cpl_ensure(self->propertylist[pos] != NULL,
+                  CPL_ERROR_DATA_NOT_FOUND, NULL);
+
+    return self->propertylist[pos];
+
+}
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Load the propertylist of the specified frame in the framelist
+  @param    self   The framelist to modify
+  @param    pos    position (0 for first).
+  @param    ind    The index of the date set to read
+  @param    regexp The regular expression of properties to load
+  @param    invert Boolean to invert the sense of the pattern matching.
+  @return   CPL_ERROR_NONE or the relevant CPL error code
+  @see      cpl_propertylist_load_regexp()
+  @note     Use a regexp of ".?" to load all properties. If a propertylist
+            already exists it is deleted and replaced by the new one.
+
+ */
+/*----------------------------------------------------------------------------*/
+cpl_error_code irplib_framelist_load_propertylist(irplib_framelist * self,
+                                                  int pos, int ind,
+                                                  const char * regexp,
+                                                  cpl_boolean invert)
+{
+
+    const char * filename;
+
+
+    cpl_ensure_code(self   != NULL,    CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(regexp != NULL,    CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(pos >= 0,          CPL_ERROR_ILLEGAL_INPUT);
+    cpl_ensure_code(pos <  self->size, CPL_ERROR_ACCESS_OUT_OF_RANGE);
+
+    filename = cpl_frame_get_filename(self->frame[pos]);
+
+    cpl_ensure_code(filename != NULL, cpl_error_get_code());
+
+    cpl_propertylist_delete(self->propertylist[pos]);
+
+    self->propertylist[pos] = cpl_propertylist_load_regexp(filename, ind,
+                                                           regexp,
+                                                           invert ? 1 : 0);
+
+    if (self->propertylist[pos] == NULL) {
+#if defined CPL_HAVE_VA_ARGS && CPL_HAVE_VA_ARGS != 0
+        return cpl_error_set_message(cpl_func, cpl_error_get_code(), "Could "
+                                     "not load FITS header from '%s' using "
+                                     "regexp '%s'", filename, regexp);
+#else
+        return cpl_error_set_message(cpl_func, cpl_error_get_code(),
+                                     "Could not load FITS header");
+#endif
+    }
+
+    return CPL_ERROR_NONE;
+
+}
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Load the propertylists of all frames in the framelist
+  @param    self   The framelist to modify
+  @param    ind    The index of the date set to read
+  @param    regexp The regular expression of properties to load
+  @param    invert Boolean to invert the sense of the pattern matching.
+  @return   CPL_ERROR_NONE or the relevant CPL error code
+  @see      irplib_framelist_load_propertylist()
+  @note     Use a regexp of "" to load all properties. If a frame already has
+            a propertylist, it is not modified (and no propertylist is loaded
+            for that frame).
+
+ */
+/*----------------------------------------------------------------------------*/
+cpl_error_code irplib_framelist_load_propertylist_all(irplib_framelist * self,
+                                                      int ind,
+                                                      const char * regexp,
+                                                      cpl_boolean invert)
+{
+
+    int nprops = 0;
+    int nfiles = 0;
+    int i;
+
+    cpl_ensure_code(self   != NULL,    CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(regexp != NULL,    CPL_ERROR_NULL_INPUT);
+
+    for (i=0; i < self->size; i++) {
+        if (self->propertylist[i] == NULL)
+            cpl_ensure_code(!irplib_framelist_load_propertylist(self, i,
+                                                                ind,
+                                                                regexp,
+                                                                invert),
+                               cpl_error_get_code());
+        /* Counting just for diagnostics - this actually causes
+           the whole list to be reiterated :-( */
+        nprops += cpl_propertylist_get_size(self->propertylist[i]);
+        nfiles++;
+    }
+
+    cpl_msg_info(cpl_func, "List of %d frames has %d properties", nfiles,
+                 nprops);
+
+    return CPL_ERROR_NONE;
+
+}
+
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Set the tag of all frames in the list
+  @param    self   The framelist to modify
+  @param    tag    The new tag of the frames
+  @return   CPL_ERROR_NONE or the relevant _cpl_error_code_
+
+ */
+/*----------------------------------------------------------------------------*/
+cpl_error_code irplib_framelist_set_tag_all(irplib_framelist * self,
+                                            const char * tag)
+{
+
+    int i;
+
+    cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(tag  != NULL, CPL_ERROR_NULL_INPUT);
+
+    for (i=0; i < self->size; i++)
+        cpl_ensure_code(!cpl_frame_set_tag(self->frame[i], tag),
+                           cpl_error_get_code());
+
+    return CPL_ERROR_NONE;
+}
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Add a frame to a framelist
+  @param    self  The framelist to modify
+  @param    frame The frame to insert into the framelist
+  @param    pos   position (0 for first).
+  @return   CPL_ERROR_NONE or the relevant CPL error code
+  @note It is an error to call cpl_frame_delete() on a frame that is inserted
+  in a framelist.
+
+  It is allowed to specify the position equal to the size of the list.
+  This will increment the size of the list.
+
+ */
+/*----------------------------------------------------------------------------*/
+cpl_error_code irplib_framelist_set(irplib_framelist * self, cpl_frame * frame,
+                                    int pos)
+{
+
+    cpl_ensure_code(self  != NULL,     CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(frame != NULL,     CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(pos >= 0,          CPL_ERROR_ILLEGAL_INPUT);
+
+    if (pos == self->size) {
+
+        self->size++;
+
+        irplib_framelist_set_size(self);
+
+    } else {
+
+        cpl_ensure_code(pos < self->size, CPL_ERROR_ACCESS_OUT_OF_RANGE);
+
+        cpl_frame_delete(self->frame[pos]);
+        cpl_propertylist_delete(self->propertylist[pos]);
+    }
+
+    self->frame[pos] = frame;
+    self->propertylist[pos] = NULL;
+
+    return CPL_ERROR_NONE;
+
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Erase a frame from a framelist and delete it and its propertylist
+  @param    self  The non-empty framelist to modify
+  @param    pos   position of frame to delete (0 for first).
+  @return   CPL_ERROR_NONE or the relevant CPL error code
+
+
+ */
+/*----------------------------------------------------------------------------*/
+cpl_error_code irplib_framelist_erase(irplib_framelist * self, int pos)
+{
+
+    int i;
+
+    cpl_ensure_code(self  != NULL,    CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(pos >= 0,         CPL_ERROR_ILLEGAL_INPUT);
+    cpl_ensure_code(pos < self->size, CPL_ERROR_ACCESS_OUT_OF_RANGE);
+
+
+    /* Delete the specified frame and its propertylist */
+    cpl_frame_delete(self->frame[pos]);
+    cpl_propertylist_delete(self->propertylist[pos]);
+
+    /* Move following frames down one position */
+    for (i = pos+1; i < self->size; i++) {
+
+        self->frame[i-1] = self->frame[i];
+
+        self->propertylist[i-1] = self->propertylist[i];
+
+    }
+
+    self->size--;
+
+    irplib_framelist_set_size(self);
+
+    return CPL_ERROR_NONE;
+
+}
+
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Erase a frame from a framelist and return it to the caller
+  @param    self  The non-empty framelist to modify
+  @param    pos   position of frame to delete (0 for first).
+  @param    plist Pointer to a propertylist or NULL
+  @return   CPL_ERROR_NONE or the relevant CPL error code
+
+  The specified frame is removed from the framelist and its size is decreased
+  by one. The frame is returned to the caller. The caller may also retrieve
+  the propertylist of the frame by passing a non-NULL pointer. On success
+  this may point to NULL, if a propertylist was not created for the
+  frame. If the caller passes a NULL-pointer for the propertylist, the
+  propertylist is deallocated.
+
+ */
+/*----------------------------------------------------------------------------*/
+cpl_frame * irplib_framelist_unset(irplib_framelist * self, int pos,
+                                   cpl_propertylist ** plist)
+
+{
+    cpl_frame * frame;
+    int i;
+
+
+    cpl_ensure(self  != NULL,    CPL_ERROR_NULL_INPUT, NULL);
+    cpl_ensure(pos >= 0,         CPL_ERROR_ILLEGAL_INPUT, NULL);
+    cpl_ensure(pos < self->size, CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL);
+
+    /* Get the specified frame and its propertylist */
+    frame = self->frame[pos];
+
+    if (plist != NULL)
+        *plist = self->propertylist[pos];
+    else
+        cpl_propertylist_delete(self->propertylist[pos]);
+
+
+    /* Move following frames down one position */
+    for (i = pos+1; i < self->size; i++) {
+
+        self->frame[i-1] = self->frame[i];
+
+        self->propertylist[i-1] = self->propertylist[i];
+
+    }
+
+    self->size--;
+
+    irplib_framelist_set_size(self);
+
+    return frame;
+
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Erase all frames from a framelist
+  @param    self  The framelist to modify, or NULL
+  @return   CPL_ERROR_NONE or the relevant CPL error code
+
+ */
+/*----------------------------------------------------------------------------*/
+void irplib_framelist_empty(irplib_framelist * self)
+{
+
+    if (self != NULL) {
+
+        /* Deallocate all frames and their propertylists */
+        while (self->size > 0) {
+            self->size--;
+            cpl_frame_delete(self->frame[self->size]);
+            cpl_propertylist_delete(self->propertylist[self->size]);
+
+        }
+        
+        /* Deallocate the arrays */
+        irplib_framelist_set_size(self);
+
+    }
+}
+
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Verify that a property is present for all frames
+  @param    self     The framelist to verify
+  @param    key      Property that must be present for all the frames
+  @param    type     The type the property must have, or CPL_TYPE_INVALID
+  @param    is_equal If true, the value must be identical for all keys
+  @param    fp_tol   The non-negative tolerance for floating point comparison
+  @return   CPL_ERROR_NONE or the relevant CPL error code
+  @note It is allowed for a frame to have a NULL propertylist,
+        in which case no check is performed.
+        If type is CPL_TYPE_INVALID the check for a specific type is disabled.
+        However, with is_equal true, all properties must nevertheless have the
+        same type.
+        fp_tol is used only when is_equal is true and the type is 
+        (explicitly or implicitly) CPL_TYPE_FLOAT or CPL_TYPE_DOUBLE.
+
+   To verify the presence of the MJD-OBS keyword:
+   @code
+       irplib_framelist_contains(myframes, "MJD-OBS", CPL_TYPE_INVALID,
+                                 CPL_FALSE, 0.0);
+   @endcode
+  
+   To verify that the EXPTIME is identical to within 0.1 millisecond:
+   @code
+       irplib_framelist_contains(myframes, "EXPTIME", CPL_TYPE_INVALID,
+                                 CPL_TRUE, 0.0001);
+   @endcode
+  
+   To verify that the keyword "ESO INS LAMP ST" is of type boolean and that
+   it has the same value for all frames:
+   @code
+       irplib_framelist_contains(myframes, "ESO INS LAMP ST", CPL_TYPE_BOOL,
+                                 CPL_TRUE, 0.0);
+   @endcode
+
+
+ */
+/*----------------------------------------------------------------------------*/
+cpl_error_code irplib_framelist_contains(const irplib_framelist * self,
+                                         const char * key, cpl_type type,
+                                         cpl_boolean is_equal, double fp_tol)
+{
+
+    char * value_0;
+    char * value_i;
+    cpl_type type_0 = CPL_TYPE_INVALID;
+    int i, ifirst = -1;  /* First non-NULL propertylist */
+
+
+    cpl_ensure_code(self  != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(key   != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(fp_tol >= 0.0, CPL_ERROR_ILLEGAL_INPUT);
+
+    for (i=0; i < self->size; i++) {
+        cpl_type type_i;
+
+
+        if (self->propertylist[i] == NULL) continue;
+        if (ifirst < 0) ifirst = i;
+
+        type_i = cpl_propertylist_get_type(self->propertylist[i], key);
+
+        if (type_i == CPL_TYPE_INVALID) {
+            if (type == CPL_TYPE_INVALID)
+#if defined CPL_HAVE_VA_ARGS && CPL_HAVE_VA_ARGS != 0
+                cpl_error_set_message(cpl_func, cpl_error_get_code(), "FITS "
+                                      "key '%s' is missing from file %s", key,
+                                      cpl_frame_get_filename(self->frame[i]));
+            else
+                cpl_error_set_message(cpl_func, cpl_error_get_code(),
+                                      "FITS key '%s' [%s] is missing from file "
+                                      "%s", key, cpl_type_get_name(type),
+                                      cpl_frame_get_filename(self->frame[i]));
+#else
+                cpl_error_set_message(cpl_func, cpl_error_get_code(),
+                                      "A FITS key is missing from a file");
+            else
+                cpl_error_set_message(cpl_func, cpl_error_get_code(),
+                                      "A FITS key is missing from a file");
+#endif
+            return cpl_error_get_code();
+        }
+
+        if (type != CPL_TYPE_INVALID && type_i != type) {
+#if defined CPL_HAVE_VA_ARGS && CPL_HAVE_VA_ARGS != 0
+            return cpl_error_set_message(cpl_func, CPL_ERROR_INVALID_TYPE,
+                                         "FITS key '%s' has type %s instead of "
+                                         "%s in file %s", key,
+                                         cpl_type_get_name(type_i),
+                                         cpl_type_get_name(type),
+                                         cpl_frame_get_filename(self->frame[i]));
+#else
+            return cpl_error_set_message(cpl_func, CPL_ERROR_INVALID_TYPE,
+                                         "A FITS key had an unexpected type");
+#endif
+
+        }
+
+        if (!is_equal) continue;
+
+        if (type_0 == CPL_TYPE_INVALID) {
+            type_0 = type_i;
+            continue;
+        }
+
+        if (type_i != type_0) {
+            assert( type == CPL_TYPE_INVALID );
+#if defined CPL_HAVE_VA_ARGS && CPL_HAVE_VA_ARGS != 0
+            return cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH,
+                                         "FITS key '%s' has different types "
+                                         "(%s <=> %s) in files %s and %s", key,
+                                         cpl_type_get_name(type_0),
+                                         cpl_type_get_name(type_i),
+                                         cpl_frame_get_filename(self->frame[0]),
+                                         cpl_frame_get_filename(self->frame[i]));
+#else
+            return cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH,
+                                         "A FITS key has different types in "
+                                         "two files");
+#endif
+        }
+
+        if (irplib_property_equal(self->propertylist[ifirst],
+                                  self->propertylist[i],
+                                  key, type_0, fp_tol, &value_0, &value_i))
+            continue;
+
+        if ((type_0 == CPL_TYPE_FLOAT || type_0 == CPL_TYPE_DOUBLE)
+            && fp_tol > 0.0) {
+#if defined CPL_HAVE_VA_ARGS && CPL_HAVE_VA_ARGS != 0
+            cpl_error_set_message(cpl_func, CPL_ERROR_INCOMPATIBLE_INPUT, "FITS"
+                                  " key '%s' [%s] has values that differ by "
+                                  "more than %g (%s <=> %s) in files %s and %s",
+                                  key, cpl_type_get_name(type_0), fp_tol,
+                                  value_0, value_i,
+                                  cpl_frame_get_filename(self->frame[0]),
+                                  cpl_frame_get_filename(self->frame[i]));
+#else
+            cpl_error_set_message(cpl_func, CPL_ERROR_INCOMPATIBLE_INPUT, "A "
+                                  "FITS key has values that differ by more "
+                                  "than the allowed tolerance in two file");
+#endif
+        } else {
+#if defined CPL_HAVE_VA_ARGS && CPL_HAVE_VA_ARGS != 0
+            cpl_error_set_message(cpl_func, CPL_ERROR_INCOMPATIBLE_INPUT,
+                                  "FITS key '%s' [%s] has different values "
+                                  "(%s <=> %s) in files %s and %s", key,
+                                  cpl_type_get_name(type_0),
+                                  value_0, value_i,
+                                  cpl_frame_get_filename(self->frame[0]),
+                                  cpl_frame_get_filename(self->frame[i]));
+#else
+            cpl_error_set_message(cpl_func, CPL_ERROR_INCOMPATIBLE_INPUT, "A "
+                                  "FITS key has different values in two files");
+#endif
+        }
+        cpl_free(value_0);
+        cpl_free(value_i);
+
+        return cpl_error_get_code();
+    }        
+
+    return CPL_ERROR_NONE;
+
+}
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Load an imagelist from a framelist
+  @param    self        The framelist
+  @param    pixeltype   The required type of the pixels in the images
+  @param    planenum    The (non-negative ) plane number 
+  @param    extnum      The non-negative extension (0 for primary data unit)
+  @return   The loaded list of images or NULL on error.
+  @see      cpl_image_load()
+  @note The returned cpl_imagelist must be deallocated using
+        cpl_imagelist_delete()
+
+ */
+/*----------------------------------------------------------------------------*/
+cpl_imagelist * irplib_imagelist_load_framelist(const irplib_framelist * self,
+                                                cpl_type pixeltype,
+                                                int planenum,
+                                                int extnum)
+{
+
+    cpl_imagelist * list = NULL;
+    cpl_image     * image = NULL;
+    int i;
+
+
+    cpl_ensure(self != NULL,  CPL_ERROR_NULL_INPUT,          NULL);
+    cpl_ensure(extnum >= 0,   CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL);
+    cpl_ensure(planenum >= 0, CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL);
+
+    list = cpl_imagelist_new();
+
+    for (i=0; i < self->size; i++, image = NULL) {
+        const char * filename = cpl_frame_get_filename(self->frame[i]);
+        cpl_error_code error;
+
+        if (filename == NULL) break;
+
+        image = cpl_image_load(filename, pixeltype, planenum, extnum);
+        if (image == NULL) {
+#if defined CPL_HAVE_VA_ARGS && CPL_HAVE_VA_ARGS != 0
+            (void)cpl_error_set_message(cpl_func, cpl_error_get_code(),
+                                        "Could not load FITS-image from plane "
+                                        "%d in extension %d in file %s",
+                                        planenum, extnum, filename);
+#else
+            (void)cpl_error_set_message(cpl_func, cpl_error_get_code(),
+                                        "Could not load FITS-image");
+#endif
+            break;
+        }
+
+        error = cpl_imagelist_set(list, image, i);
+        assert(error == CPL_ERROR_NONE);
+    }
+
+    cpl_image_delete(image);
+    
+    if (cpl_imagelist_get_size(list) != self->size) {
+        cpl_imagelist_delete(list);
+        list = NULL;
+        assert(cpl_error_get_code() != CPL_ERROR_NONE);
+    }
+
+    return list;
+
+}
+
+
+/**@}*/
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Set the size of the framelist - without handling any frames
+  @param    self  The framelist to modify
+  @return   void
+  @note This private function should be used by all morphological functions;
+        it will assert() on NULL input.
+
+  This function updates the arrays used to hold the frames and propertylists
+  to the size specified by the size member.
+
+ */
+/*----------------------------------------------------------------------------*/
+static void irplib_framelist_set_size(irplib_framelist * self)
+{
+
+
+    assert( self != NULL);
+
+    if (self->size == 0) {
+        /* The list has been emptied */
+        cpl_free(self->frame);
+        cpl_free(self->propertylist);
+        self->frame = NULL;
+        self->propertylist = NULL;
+    } else {
+        /* Update the size of the arrays */
+
+        self->frame = cpl_realloc(self->frame, self->size * sizeof(cpl_frame*));
+        self->propertylist =
+            cpl_realloc(self->propertylist,
+                        self->size * sizeof(cpl_propertylist*));
+    }
+
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Compare the value of two properties
+  @param    self     The first property
+  @param    other    The other property of the same type
+  @param    fp_tol   The non-negative tolerance for floating point comparison
+  @param    sstring  The string value of the first property (if they differ)
+  @param    ostring  The string value of the other property (if they differ)
+  @return   CPL_TRUE if equal, CPL_FALSE if not.
+  @note This private function will assert() on illegal input.
+        The names of the two properties are not compared.
+
+  Iff the function returns CPL_FALSE *sstring and *ostring must be deallocated
+  with cpl_free().
+
+  The original content of *sstring and *ostring is not accessed.        
+
+  FIXME: This function should really take two properties (and no key + type),
+  but the cpl_propertylist module is flawed: It does not have
+  an accessor by name... :-(
+  The penalty for this is multiple propertylist searches by key
+  (and loss of commutativity) :-(((
+
+ */
+/*----------------------------------------------------------------------------*/
+static cpl_boolean irplib_property_equal(const cpl_propertylist * self,
+                                         const cpl_propertylist * other,
+                                         const char * key, cpl_type type,
+                                         double fp_tol,
+                                         char ** sstring, char ** ostring)
+{
+
+    cpl_boolean equal;
+
+
+    assert(self    != NULL);
+    assert(other   != NULL);
+    assert(key     != NULL);
+    assert(sstring != NULL);
+    assert(ostring != NULL);
+
+    /* FIXME: disable for better performance also with debugging */
+    assert(cpl_propertylist_get_type(other, key) == type);
+    assert(fp_tol >= 0.0);
+
+    if (self == other) return CPL_TRUE;
+
+    switch (type) {
+
+    case CPL_TYPE_CHAR: {
+        const char svalue = cpl_propertylist_get_char(self, key);
+        const char ovalue = cpl_propertylist_get_char(other, key);
+
+        equal = svalue == ovalue ? CPL_TRUE : CPL_FALSE;
+        if (!equal) {
+            *sstring = cpl_sprintf("%c", svalue);
+            *ostring = cpl_sprintf("%c", ovalue);
+        }
+        break;
+    }
+
+    case CPL_TYPE_BOOL: {
+        const int svalue = cpl_propertylist_get_bool(self, key);
+        const int ovalue = cpl_propertylist_get_bool(other, key);
+
+        equal = svalue == ovalue ? CPL_TRUE : CPL_FALSE;
+        if (!equal) {
+            *sstring = cpl_strdup(svalue == 0 ? "F" : "T");
+            *ostring = cpl_strdup(ovalue == 0 ? "F" : "T");
+        }
+        break;
+    }
+
+    case CPL_TYPE_INT: {
+        const int svalue = cpl_propertylist_get_int(self, key);
+        const int ovalue = cpl_propertylist_get_int(other, key);
+
+        equal = svalue == ovalue ? CPL_TRUE : CPL_FALSE;
+        if (!equal) {
+            *sstring = cpl_sprintf("%d", svalue);
+            *ostring = cpl_sprintf("%d", ovalue);
+        }
+        break;
+    }
+
+    case CPL_TYPE_LONG: {
+        const long svalue = cpl_propertylist_get_long(self, key);
+        const long ovalue = cpl_propertylist_get_long(other, key);
+
+        equal = svalue == ovalue ? CPL_TRUE : CPL_FALSE;
+        if (!equal) {
+            *sstring = cpl_sprintf("%ld", svalue);
+            *ostring = cpl_sprintf("%ld", ovalue);
+        }
+        break;
+    }
+
+    case CPL_TYPE_FLOAT: {
+        const double svalue = (double)cpl_propertylist_get_float(self, key);
+        const double ovalue = (double)cpl_propertylist_get_float(other, key);
+
+        equal = (fabs(svalue - ovalue) <= fp_tol) ? CPL_TRUE : CPL_FALSE;
+        if (!equal) {
+            *sstring = cpl_sprintf("%f", svalue);
+            *ostring = cpl_sprintf("%f", ovalue);
+        }
+        break;
+    }
+
+    case CPL_TYPE_DOUBLE: {
+        const double svalue = cpl_propertylist_get_double(self, key);
+        const double ovalue = cpl_propertylist_get_double(other, key);
+
+        equal = (fabs(svalue - ovalue) <= fp_tol) ? CPL_TRUE : CPL_FALSE;
+        if (!equal) {
+            *sstring = cpl_sprintf("%g", svalue);
+            *ostring = cpl_sprintf("%g", ovalue);
+        }
+        break;
+    }
+    case CPL_TYPE_STRING: {
+        const char * svalue = cpl_propertylist_get_string(self, key);
+        const char * ovalue = cpl_propertylist_get_string(other, key);
+
+        equal = strcmp(svalue, ovalue) == 0 ? CPL_TRUE : CPL_FALSE;
+        if (!equal) {
+            *sstring = cpl_strdup(svalue);
+            *ostring = cpl_strdup(ovalue);
+        }
+        break;
+    }
+    default:
+        /* Unknown property type */
+        assert( 0 );
+
+        equal = CPL_FALSE; /* In case of -DNDEBUG */
+
+    }
+
+    if (!equal) {
+        assert( *sstring != NULL );
+        assert( *ostring != NULL );
+    }
+
+    return equal;
+
+}
diff --git a/irplib/irplib_framelist.h b/irplib/irplib_framelist.h
new file mode 100644
index 0000000..69ce19c
--- /dev/null
+++ b/irplib/irplib_framelist.h
@@ -0,0 +1,107 @@
+/* $Id: irplib_framelist.h,v 1.8 2008/11/20 10:24:47 llundin Exp $
+ *
+ * This file is part of the irplib package 
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: llundin $
+ * $Date: 2008/11/20 10:24:47 $
+ * $Revision: 1.8 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifndef IRPLIB_FRAMELIST_H
+#define IRPLIB_FRAMELIST_H
+
+/*-----------------------------------------------------------------------------
+                                   Includes
+ -----------------------------------------------------------------------------*/
+
+#include <cpl.h>
+
+/*-----------------------------------------------------------------------------
+                                   New type
+ -----------------------------------------------------------------------------*/
+
+typedef struct _irplib_framelist_ irplib_framelist;
+
+/*-----------------------------------------------------------------------------
+                                   Function prototypes
+ -----------------------------------------------------------------------------*/
+
+/* Constructors and destructor */
+
+irplib_framelist * irplib_framelist_new(void);
+
+void irplib_framelist_delete(irplib_framelist *);
+
+irplib_framelist * irplib_framelist_cast(const cpl_frameset *);
+
+irplib_framelist * irplib_framelist_extract(const irplib_framelist *,
+                                            const char *);
+irplib_framelist * irplib_framelist_extract_regexp(const irplib_framelist *,
+                                                   const char *, cpl_boolean);
+
+/* Accessors and element modifiers */
+
+int irplib_framelist_get_size(const irplib_framelist *);
+
+const cpl_frame * irplib_framelist_get_const(const irplib_framelist *, int);
+
+cpl_frame * irplib_framelist_get(irplib_framelist *, int);
+
+const cpl_propertylist * irplib_framelist_get_propertylist_const(
+                                                       const irplib_framelist *,
+                                                       int);
+
+cpl_propertylist * irplib_framelist_get_propertylist(irplib_framelist *, int);
+
+cpl_error_code irplib_framelist_set_propertylist(irplib_framelist *, int,
+                                                 const cpl_propertylist *);
+
+cpl_error_code irplib_framelist_load_propertylist(irplib_framelist *, int,
+                                                  int, const char *,
+                                                  cpl_boolean);
+
+cpl_error_code irplib_framelist_load_propertylist_all(irplib_framelist *, int,
+                                                      const char *,
+                                                      cpl_boolean);
+
+cpl_error_code irplib_framelist_set_tag_all(irplib_framelist *, const char *);
+
+
+/* Inserting and removing elements */
+
+cpl_error_code irplib_framelist_set(irplib_framelist *, cpl_frame *, int);
+
+cpl_error_code irplib_framelist_erase(irplib_framelist *, int);
+
+cpl_frame * irplib_framelist_unset(irplib_framelist *, int, cpl_propertylist **);
+
+void irplib_framelist_empty(irplib_framelist *);
+
+/* Others */
+cpl_error_code irplib_framelist_contains(const irplib_framelist *, const char *,
+                                         cpl_type, cpl_boolean, double);
+
+cpl_imagelist * irplib_imagelist_load_framelist(const irplib_framelist *,
+                                                cpl_type, int, int);
+
+cpl_frameset * irplib_frameset_cast(const irplib_framelist *);
+
+#endif
diff --git a/irplib/irplib_hist.c b/irplib/irplib_hist.c
new file mode 100644
index 0000000..90f96ff
--- /dev/null
+++ b/irplib/irplib_hist.c
@@ -0,0 +1,350 @@
+
+
+/*
+ * This file is part of the irplib package
+ * Copyright (C) 2002, 2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA
+ */
+
+/*
+ * $Author: kmirny $
+ * $Id: irplib_hist.c,v 1.7 2009/10/15 14:02:18 kmirny Exp $
+ * $Date: 2009/10/15 14:02:18 $
+ * $Revision: 1.7 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include <math.h>
+
+#include "irplib_hist.h"
+
+struct _irplib_hist_
+{
+    unsigned long * bins;
+    unsigned long   nbins;
+    double          start;
+    double          range;
+};
+
+/*
+ * Create a new empty histogram
+ */
+
+irplib_hist *
+irplib_hist_new(void)
+{
+    return (irplib_hist *) cpl_calloc(1, sizeof(irplib_hist));
+}
+
+/*
+ * Delete a histogram
+ */
+
+void
+irplib_hist_delete(irplib_hist * d)
+{
+    if (d == NULL)
+	return;
+
+    if (d -> bins)
+	cpl_free(d -> bins);
+
+    cpl_free(d);
+}
+
+/*
+ * Initialise a histogram with user-defined values
+ */
+
+cpl_error_code
+irplib_hist_init(irplib_hist   * hist,
+                 unsigned long   nbins,
+                 double          start,
+                 double          range)
+{
+    /* Test the entries */
+    cpl_ensure_code(hist         != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(nbins        >  0,    CPL_ERROR_ILLEGAL_INPUT);
+    cpl_ensure_code(range        >  0,    CPL_ERROR_ILLEGAL_INPUT);
+    cpl_ensure_code(hist -> bins == NULL, CPL_ERROR_ILLEGAL_INPUT);
+
+    /* Initialise the histogram structure */
+    hist -> bins  = (unsigned long *) cpl_calloc(nbins, sizeof(unsigned long));
+    hist -> nbins = nbins;
+    hist -> start = start;
+    hist -> range = range;
+
+    return cpl_error_get_code();
+}
+
+/*
+ * Return the value of a histogram bin.
+ * An uninitialised histogram is considered an illegal input.
+ */
+
+unsigned long
+irplib_hist_get_value(const irplib_hist * hist,
+                      const unsigned long binpos)
+{
+    cpl_ensure(hist         != NULL,          CPL_ERROR_NULL_INPUT, 0);
+    cpl_ensure(hist -> bins != NULL,          CPL_ERROR_ILLEGAL_INPUT, 0);
+    cpl_ensure(binpos       <  hist -> nbins, CPL_ERROR_ILLEGAL_INPUT, 0);
+
+    return hist -> bins[binpos];
+}
+
+/*
+ * Return the number of bins in the histogram.
+ */
+
+unsigned long
+irplib_hist_get_nbins(const irplib_hist * hist)
+{
+    cpl_ensure(hist != NULL, CPL_ERROR_NULL_INPUT, 0);
+
+    return hist -> nbins;
+}
+
+/*
+ * Return the binwidth of the histogram.
+ */
+
+double
+irplib_hist_get_bin_size(const irplib_hist * hist)
+{
+    cpl_ensure(hist         != NULL, CPL_ERROR_NULL_INPUT, 0);
+    cpl_ensure(hist -> bins != NULL, CPL_ERROR_ILLEGAL_INPUT, 0);
+
+    return hist -> range / (double)(hist -> nbins - 2);
+}
+
+/*
+ * Return the range covered by the histogram.
+ */
+
+double
+irplib_hist_get_range(const irplib_hist * hist)
+{
+    cpl_ensure(hist != NULL, CPL_ERROR_NULL_INPUT, 0);
+
+    return hist -> range;
+}
+
+/*
+ * Return the real value corresponding
+ * to the inferior limit of the histogram..
+ */
+
+double
+irplib_hist_get_start(const irplib_hist * hist)
+{
+    cpl_ensure(hist         != NULL, CPL_ERROR_NULL_INPUT, 0);
+    cpl_ensure(hist -> bins != NULL, CPL_ERROR_ILLEGAL_INPUT, 0);
+
+    return hist -> start;
+}
+
+/*
+ * Fill a histogram for an image.
+ * If the histogram is uninitialised,
+ * the function initialises it with default values.
+ */
+
+cpl_error_code
+irplib_hist_fill(irplib_hist     * hist,
+                 const cpl_image * image)
+{
+    double           binwidth = 1.0;
+    int              nsamples;
+    int              i;
+    const float    * data = 0;
+    const cpl_binary*  bpm_data = 0;
+    const cpl_mask* bpm = 0;
+    cpl_error_code   error;
+
+    /* Test the entries */
+    cpl_ensure_code(hist  != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(image != NULL, CPL_ERROR_NULL_INPUT);
+
+    if (hist -> bins == NULL) {
+	const double        hstart = cpl_image_get_min(image);
+	const double        hrange = cpl_image_get_max(image) - hstart;
+
+	/*
+         * Whichever function that computes an optimal binwidth
+         * should be introduced inside this if-statement, here.
+         */
+
+	/* 2 extra-bins for possible out-of-range values */
+	const unsigned long nbins  = (unsigned long) (hrange / binwidth) + 2;
+
+	error = irplib_hist_init(hist, nbins, hstart, hrange);
+	cpl_ensure_code(!error, error);
+    } else {
+	cpl_ensure_code(hist -> range > 0, CPL_ERROR_ILLEGAL_INPUT);
+
+	/* 2 bins reserved for possible out-of-range values */
+        binwidth = hist -> range / (double)(hist -> nbins - 2);
+    }
+
+    nsamples = cpl_image_get_size_x(image) * cpl_image_get_size_y(image);
+    data     = cpl_image_get_data_float_const(image);
+    bpm 	 = cpl_image_get_bpm_const(image);
+    if (bpm)
+    {
+    	bpm_data 	 = cpl_mask_get_data_const(bpm); // bad pixel mask
+    }
+
+    for (i = 0; i < nsamples; i++)
+    {
+    	int pos = 0;
+    	if(bpm_data && bpm_data[i] == CPL_BINARY_1)
+    	{
+    		continue;
+    	}
+		pos = (int)((data[i] - hist -> start) / binwidth);
+		if (pos <  0)
+		{
+			hist -> bins[0]++;
+		} else if ((unsigned long) pos >= (hist -> nbins - 2))
+		{
+			hist -> bins[hist -> nbins - 1]++;
+		} else
+		{
+			hist -> bins[pos + 1]++;
+		}
+    }
+
+    return cpl_error_get_code();
+}
+
+/*
+ * Compute the maximum of a histogram.
+ * Return: the maximum value.
+ * The parameter max_where is a pointer to the position
+ * of the maximum in the histogram.
+ */
+
+unsigned long
+irplib_hist_get_max(const irplib_hist * hist,
+                    unsigned long     * maxpos)
+{
+    unsigned long max = 0;
+    unsigned long ui;
+
+    cpl_ensure(hist         != NULL, CPL_ERROR_NULL_INPUT, 0);
+    cpl_ensure(maxpos       != NULL, CPL_ERROR_NULL_INPUT, 0);
+    cpl_ensure(hist -> bins != NULL, CPL_ERROR_ILLEGAL_INPUT, 0);
+
+    for(ui = 0; ui < hist -> nbins; ui++) {
+	double c_value = irplib_hist_get_value(hist, ui);
+	if(c_value > max) {
+	    max     = c_value;
+	    *maxpos = ui;
+	}
+    }
+
+    return max;
+}
+
+/*
+ * Cast a histogram into a table with a single column named "HIST"
+ */
+
+cpl_table *
+irplib_hist_cast_table(const irplib_hist * hist)
+{
+    cpl_table      * table;
+    cpl_error_code   error;
+
+    cpl_ensure(hist         != NULL, CPL_ERROR_NULL_INPUT, NULL);
+    cpl_ensure(hist -> bins != NULL, CPL_ERROR_ILLEGAL_INPUT, NULL);
+
+    table = cpl_table_new(hist -> nbins);
+
+    error = cpl_table_new_column(table, "HIST", CPL_TYPE_INT);
+    cpl_ensure(!error, error, NULL);
+
+    error = cpl_table_copy_data_int(table, "HIST", (int *)(hist -> bins));
+    cpl_ensure(!error, error, NULL);
+
+    return table;
+}
+
+/*
+ * Collapse the histogram: add the values of all bins.
+ * Used now only for debugging purposes.
+ */
+
+cpl_error_code
+irplib_hist_collapse(irplib_hist * hist,
+                     unsigned long new_nbins)
+{
+    unsigned long   ui, nuj;
+    unsigned long * old_bins;
+    unsigned long   old_nbins;
+    double          collapse_rate;
+    cpl_error_code  error;
+    unsigned long   rest;
+
+    cpl_ensure_code(hist         != NULL,          CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(hist -> bins != NULL,          CPL_ERROR_ILLEGAL_INPUT);
+    cpl_ensure_code(new_nbins    >  0,             CPL_ERROR_ILLEGAL_INPUT);
+    cpl_ensure_code(new_nbins    <= hist -> nbins, CPL_ERROR_ILLEGAL_INPUT);
+
+    old_bins  = hist -> bins;
+    old_nbins = hist -> nbins;
+
+    hist -> bins = NULL;
+    error = irplib_hist_init(hist, new_nbins, hist -> start, hist -> range);
+    cpl_ensure_code(!error, error);
+
+    collapse_rate = (double) (old_nbins - 2) / (double) (new_nbins - 2);
+
+    /* The out-of-range values are not affected by the collapsing operation */
+    hist -> bins[0]             = old_bins[0];
+    hist -> bins[new_nbins - 1] = old_bins[old_nbins - 1];
+
+    rest = 0;
+    nuj  = 1;
+
+    for (ui = 1; ui < new_nbins - 1; ui++) {
+	unsigned long uj;
+	const double  up  = collapse_rate *  ui;
+
+	hist -> bins[ui] += rest;
+
+	for (uj = nuj; uj < (unsigned long) up + 1; uj++)
+	    hist -> bins[ui] +=  old_bins[uj];
+
+	rest = (unsigned long)(up - (unsigned long) up) * old_bins[uj];
+	hist -> bins[ui] += rest;
+
+	rest = old_bins[uj] - rest;
+	nuj = uj + 1;
+    }
+
+    cpl_free(old_bins);
+
+    return cpl_error_get_code();
+}
diff --git a/irplib/irplib_hist.h b/irplib/irplib_hist.h
new file mode 100644
index 0000000..0a8ccf3
--- /dev/null
+++ b/irplib/irplib_hist.h
@@ -0,0 +1,93 @@
+/* $Id: irplib_hist.h,v 1.3 2007/09/07 14:23:50 lbilbao Exp $
+ *
+ * This file is part of the irplib package
+ * Copyright (C) 2002, 2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA
+ */
+
+/*
+ * $Author: lbilbao $
+ * $Date: 2007/09/07 14:23:50 $
+ * $Revision: 1.3 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifndef IRPLIB_HIST_H
+#define IRPLIB_HIST_H
+
+#include <cpl.h>
+
+typedef struct _irplib_hist_ irplib_hist;
+
+/* Creation/Destruction functions */
+
+irplib_hist *
+irplib_hist_new(void);
+
+void
+irplib_hist_delete(irplib_hist *);
+
+/* Initialisation function */
+
+cpl_error_code
+irplib_hist_init(irplib_hist   *,
+                 unsigned long  ,
+                 double         ,
+                 double         );
+
+/* Accessor functions */
+
+unsigned long
+irplib_hist_get_value(const irplib_hist *,
+                      const unsigned long);
+
+unsigned long
+irplib_hist_get_nbins(const irplib_hist *);
+
+double
+irplib_hist_get_bin_size(const irplib_hist *);
+
+double
+irplib_hist_get_range(const irplib_hist *);
+
+double
+irplib_hist_get_start(const irplib_hist *);
+
+/* Histogram computing function */
+
+cpl_error_code
+irplib_hist_fill(irplib_hist     *,
+                 const cpl_image *);
+
+/* Statistics functions */
+
+unsigned long
+irplib_hist_get_max(const irplib_hist *,
+                    unsigned long     *);
+
+/* Casting function */
+
+cpl_table *
+irplib_hist_cast_table(const irplib_hist *);
+
+/* Functions for operations on histograms */
+
+cpl_error_code
+irplib_hist_collapse(irplib_hist *,
+                     unsigned long);
+
+#endif /* IRPLIB_HIST_H */
+
diff --git a/irplib/irplib_ksigma_clip.c b/irplib/irplib_ksigma_clip.c
new file mode 100644
index 0000000..c84874b
--- /dev/null
+++ b/irplib/irplib_ksigma_clip.c
@@ -0,0 +1,258 @@
+/* $Id: irplib_ksigma_clip.c,v 1.1 2011/11/02 13:18:28 amodigli Exp $
+ *
+ * This file is part of the irplib package
+ * Copyright (C) 2002, 2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2011/11/02 13:18:28 $
+ * $Revision: 1.1 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <complex.h>
+
+/*---------------------------------------------------------------------------
+                                  Includes
+ ---------------------------------------------------------------------------*/
+
+#include <math.h>
+#include <string.h>
+#include <assert.h>
+#include <float.h>
+
+#include <cpl.h>
+
+#include "irplib_ksigma_clip.h"
+
+#include "irplib_hist.h"
+#include "irplib_utils.h"
+
+/*--------------------------------------------------------------------------*/
+
+/*
+ * @defgroup ksigmaclip        kappa sigma clip functions
+ */
+
+/*--------------------------------------------------------------------------*/
+
+/*---------------------------------------------------------------------------
+                                  Defines
+ ---------------------------------------------------------------------------*/
+
+/*---------------------------------------------------------------------------
+                                  Private function prototypes
+ ---------------------------------------------------------------------------*/
+
+static cpl_error_code
+irplib_ksigma_clip_double(const double  * pi,
+			  int               llx,
+			  int               lly,
+			  int               urx,
+			  int               ury,
+			  int               nx,
+			  double            var_sum,
+			  int               npixs,
+			  double            kappa,
+			  int               nclip,
+			  double            tolerance,
+			  double          * mean,
+			  double          * stdev);
+
+static cpl_error_code
+irplib_ksigma_clip_float(const float     * pi,
+			 int               llx,
+			 int               lly,
+			 int               urx,
+			 int               ury,
+			 int               nx,
+			 double            var_sum,
+			 int               npixs,
+			 double            kappa,
+			 int               nclip,
+			 double            tolerance,
+			 double          * mean,
+			 double          * stdev);
+
+static cpl_error_code
+irplib_ksigma_clip_int(const int       * pi,
+		       int               llx,
+		       int               lly,
+		       int               urx,
+		       int               ury,
+		       int               nx,
+		       double            var_sum,
+		       int               npixs,
+		       double            kappa,
+		       int               nclip,
+		       double            tolerance,
+		       double          * mean,
+		       double          * stdev);
+
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Apply kappa-sigma clipping on input image
+  @param    img      Input image
+  @param    llx      Lower left x position (FITS convention)
+  @param    lly      Lower left y position (FITS convention)
+  @param    urx      Upper right x position (FITS convention)
+  @param    ury      Upper right y position (FITS convention)
+  @param    kappa    Kappa value for the clipping
+  @param    nclip    Number of clipping iterations
+  @param    tolerance tolerance on range between two successive clip iterations
+  @param    kmean    Mean after clipping (output)
+  @param    kstdev   Stdev after clipping (output)
+  @return   CPL_ERROR_NONE or the relevant #_cpl_error_code_ on error
+
+  This function applies an iterative kappa-sigma clipping on the image and
+  returns mean and stdev after the clipping.
+
+  The function takes as a starting point the "standard" values of mean and
+  stdev from cpl_stats.
+
+  On each iteration, the contribution of pixels outside the range
+  [mean - kappa * stdev, mean + kappa * stdev] is removed, the values of
+  mean and stdev are updated, and so are the limits of the range to be used
+  in the next iteration as well.
+
+  The algorithm stops after nclip iterations or when the variation of the
+  range between two consecutive iterations is smaller (absolute value) than
+  the tolerance.
+
+  The effectiveness of this function resides on the way the update of the
+  values of mean and stdev is done.
+
+  The contribution of a single pixel in variance can be removed as follows:
+
+  \sum_{i=1}^{N-1} (x_i - \overline{x}_{n-1})^2 =
+  \sum_{i=1}^ N    (x_i - \overline{x}_n    )^2 -
+  \frac{N}{N-1} \,( \, \overline{x}_n - x_{n} )^2
+
+  For further details on the mathematical aspects, please refer to DFS05126.
+
+  Possible #_cpl_error_code_ set in this function:
+   - CPL_ERROR_NULL_INPUT if img or kmean is NULL
+   - CPL_ERROR_ILLEGAL_INPUT if
+       a) the window specification is illegal (llx > urx or lly > ury)
+       b) the window specification is outside the image
+       c) the tolerance is negative
+       d) kappa is <= 1.0
+       e) nclip is <= 0.
+
+  The values of kmean and kstdev is undefined on error.
+*/
+/*---------------------------------------------------------------------------*/
+cpl_error_code
+irplib_ksigma_clip(const cpl_image * img,
+		   int               llx,
+		   int               lly,
+		   int               urx,
+		   int               ury,
+		   double            kappa,
+		   int               nclip,
+		   double            tolerance,
+		   double          * kmean,
+		   double          * kstdev)
+{
+    cpl_errorstate inistate = cpl_errorstate_get();
+
+    int nx, ny;
+
+    cpl_stats * stats;
+    double      mean, stdev, var_sum;
+    int         npixs;
+
+    cpl_ensure_code(img != NULL, CPL_ERROR_NULL_INPUT);
+
+    nx = cpl_image_get_size_x(img);
+    ny = cpl_image_get_size_y(img);
+
+    cpl_ensure_code(llx > 0 && urx > llx && urx <= nx &&
+		    lly > 0 && ury > lly && ury <= ny,
+		    CPL_ERROR_ILLEGAL_INPUT);
+
+    cpl_ensure_code(tolerance >= 0.0, CPL_ERROR_ILLEGAL_INPUT);
+    cpl_ensure_code(kappa     >  1.0, CPL_ERROR_ILLEGAL_INPUT);
+    cpl_ensure_code(nclip     >    0, CPL_ERROR_ILLEGAL_INPUT);
+
+    stats = cpl_stats_new_from_image_window(img,
+					    CPL_STATS_MEAN | CPL_STATS_STDEV,
+					    llx, lly, urx, ury);
+
+    npixs   = cpl_stats_get_npix(stats); /* Non-bad pixels in window */
+    mean    = cpl_stats_get_mean(stats);
+    stdev   = cpl_stats_get_stdev(stats);
+    var_sum = stdev * stdev * (npixs - 1);
+
+    cpl_stats_delete(stats);
+
+    /* img, llx etc. may cause errors: Check and propagate */
+    cpl_ensure_code(cpl_errorstate_is_equal(inistate), cpl_error_get_code());
+
+    switch (cpl_image_get_type(img)) {
+    case CPL_TYPE_DOUBLE:
+	skip_if(irplib_ksigma_clip_double(cpl_image_get_data_double_const(img),
+					  llx, lly, urx, ury, nx, var_sum,
+					  npixs, kappa, nclip, tolerance,
+					  &mean, &stdev));
+	break;
+    case CPL_TYPE_FLOAT:
+	skip_if(irplib_ksigma_clip_float(cpl_image_get_data_float_const(img),
+					 llx, lly, urx, ury, nx, var_sum,
+					 npixs, kappa, nclip, tolerance,
+					 &mean, &stdev));
+	break;
+    case CPL_TYPE_INT:
+	skip_if(irplib_ksigma_clip_int(cpl_image_get_data_int_const(img),
+				       llx, lly, urx, ury, nx, var_sum,
+				       npixs, kappa, nclip, tolerance,
+				       &mean, &stdev));
+	break;
+    default:
+	/* It is an error in CPL to reach this point */
+	assert( 0 );
+    }
+
+    *kmean = mean;
+    if (kstdev != NULL) *kstdev = stdev; /* Optional */
+
+    end_skip;
+
+    return cpl_error_get_code();
+}
+
+#define CONCAT(a,b) a ## _ ## b
+#define CONCAT2X(a,b) CONCAT(a,b)
+
+#define CPL_TYPE double
+#include "irplib_ksigma_clip_body.h"
+#undef CPL_TYPE
+
+#define CPL_TYPE float
+#include "irplib_ksigma_clip_body.h"
+#undef CPL_TYPE
+
+#define CPL_TYPE int
+#include "irplib_ksigma_clip_body.h"
+#undef CPL_TYPE
+
diff --git a/irplib/irplib_ksigma_clip.h b/irplib/irplib_ksigma_clip.h
new file mode 100644
index 0000000..58bf567
--- /dev/null
+++ b/irplib/irplib_ksigma_clip.h
@@ -0,0 +1,52 @@
+/* $Id: irplib_ksigma_clip.h,v 1.1 2011/11/02 13:18:28 amodigli Exp $
+ *
+ * This file is part of the irplib package
+ * Copyright (C) 2002, 2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2011/11/02 13:18:28 $
+ * $Revision: 1.1 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifndef IRPLIB_KSIGMA_CLIP_H
+#define IRPLIB_KSIGMA_CLIP_H
+
+/*----------------------------------------------------------------------------
+                                   Includes
+ ----------------------------------------------------------------------------*/
+
+#include <cpl.h>
+
+/*----------------------------------------------------------------------------
+                                   Prototypes
+ ----------------------------------------------------------------------------*/
+cpl_error_code
+irplib_ksigma_clip(const cpl_image *,
+		   const int,
+		   const int,
+		   const int,
+		   const int,
+		   const double,
+		   const int,
+		   const double,
+		   double *,
+		   double *);
+
+#endif
diff --git a/irplib/irplib_ksigma_clip_body.h b/irplib/irplib_ksigma_clip_body.h
new file mode 100644
index 0000000..033c835
--- /dev/null
+++ b/irplib/irplib_ksigma_clip_body.h
@@ -0,0 +1,107 @@
+/* $Id: irplib_ksigma_clip_body.h,v 1.1 2011/11/02 13:18:28 amodigli Exp $
+ *
+ * This file is part of the irplib package 
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2011/11/02 13:18:28 $
+ * $Revision: 1.1 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#define TYPE_ADD(a) CONCAT2X(a, CPL_TYPE)
+
+static cpl_error_code
+TYPE_ADD(irplib_ksigma_clip)(const CPL_TYPE  * pi,
+			     int               llx,
+			     int               lly,
+			     int               urx,
+			     int               ury,
+			     int               nx,
+			     double            var_sum,
+			     int               npixs,
+			     double            kappa,
+			     int               nclip,
+			     double            tolerance,
+			     double          * mean,
+			     double          * stdev)
+{
+    int    pos0 = (llx - 1) + (lly - 1) * nx; /* 1st pixel to process */
+    double nb   = (double) npixs;             /* Non-bad pixels in window */
+
+    double lo_cut    = *mean - kappa * (*stdev);
+    double hi_cut    = *mean + kappa * (*stdev);
+    
+    double lo_cut_p  = lo_cut;
+    double hi_cut_p  = hi_cut;
+
+    double c_var_sum;
+    double c_mean = 0; /* Avoid false uninit warning */
+    double c_stdev = 0; /* Avoid false uninit warning */
+
+    int    iclip;
+
+    for (iclip = 0; iclip < nclip; iclip++) {
+        int pos = pos0;
+        int i, j;
+
+	c_var_sum = var_sum;
+	c_mean    = *mean;
+	c_stdev   = *stdev;
+	nb        = npixs;
+	
+        for (j = lly - 1; j < ury; j++, pos += (nx - urx + llx - 1)) {
+            for (i = llx - 1; i < urx; i++, pos++) {
+                if (pi[pos] > hi_cut || pi[pos] < lo_cut) {
+                    const double delta = (double)pi[pos] - c_mean;
+
+                    c_var_sum  -= nb * delta * delta / (nb - 1.0);
+                    c_mean     -= delta / (nb - 1.0);
+                    nb          = nb - 1.0;
+                }
+            }
+        }
+
+	if (nb == 1.0 || c_var_sum < 0.0) {
+	    cpl_msg_error(cpl_func, "Iteration %d: Too many pixels were "
+			  "removed. This may cause unexpected behaviour. "
+			  "Please set a lower number of iterations "
+                          "or increase the value of kappa\n", iclip);
+	    cpl_error_set(cpl_func, CPL_ERROR_DIVISION_BY_ZERO);
+	} else {
+	    c_stdev = sqrt(c_var_sum / (nb - 1.0));
+	}
+
+	lo_cut = c_mean - kappa * c_stdev;
+	hi_cut = c_mean + kappa * c_stdev;
+	
+        if(fabs(lo_cut - lo_cut_p) < tolerance &&
+           fabs(hi_cut - hi_cut_p) < tolerance) {
+            break;
+	} else {
+	    lo_cut_p = lo_cut;
+	    hi_cut_p = hi_cut;
+	}
+    }
+
+    *mean  = c_mean;
+    *stdev = c_stdev;
+
+    return cpl_error_get_code();
+}
diff --git a/irplib/irplib_match_cats.c b/irplib/irplib_match_cats.c
new file mode 100644
index 0000000..c37c750
--- /dev/null
+++ b/irplib/irplib_match_cats.c
@@ -0,0 +1,211 @@
+/* $Id: irplib_match_cats.c,v 1.10 2009/12/18 10:44:48 cgarcia Exp $
+ *
+ * This file is part of the irplib package
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: cgarcia $
+ * $Date: 2009/12/18 10:44:48 $
+ * $Revision: 1.10 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+/*-----------------------------------------------------------------------------
+                                   Includes
+ -----------------------------------------------------------------------------*/
+
+
+#include <math.h>
+#include <cpl.h>
+#include <cpl_table.h>
+
+#include "irplib_match_cats.h"
+
+#define FILENAME_SZBUF 1024
+
+
+/*----------------------------------------------------------------------------*/
+/* Private functions
+ */
+/*----------------------------------------------------------------------------*/
+
+cpl_error_code irplib_match_cats_get_all_matching_pairs
+(cpl_table ** catalogues,
+ int          ncats,
+ cpl_table  * matching_sets,
+ int (*binary_match_condition)
+   (cpl_table * catalogue1,
+    cpl_table * catalogue2,
+    int         iobj1,
+    int         iobj2)  );
+
+cpl_error_code irplib_match_cats_get_all_matches_cresc
+(cpl_table ** catalogues,
+ cpl_array  * cat_index_begin,
+ cpl_array  * cats_idx_set,
+ int          mincat_match,
+ cpl_table * matching_sets);
+
+cpl_error_code irplib_match_cats_iterate_on_cat
+(cpl_table ** catalogues,
+ cpl_array  * cats_idx_set,
+ int          icat_iterate,
+ cpl_array  * valid_iobjs,
+ int          mincat_match,
+ cpl_table  * matching_sets,
+ cpl_table  * less_minmatch_sets);
+
+cpl_error_code irplib_match_cats_filter_obj_to_iter
+(cpl_array * cats_idx_set,
+ int         order_begin,
+ cpl_table * matches_set,
+ cpl_array * excluded_objs,
+ int         itercat_nobj);
+
+int irplib_match_cats_match_condition
+(cpl_table ** catalogues,
+ int       *  cats_idx_set_ptr,
+ int          ncats);
+
+int irplib_match_count_nonmatched
+(int * cats_idx_set_ptr,
+ int   ncats);
+
+int nCombinations;
+int nFilter;
+
+/*----------------------------------------------------------------------------*/
+/**
+ * @defgroup irplib_cat   Functions for matching of catalogues
+ */
+/*----------------------------------------------------------------------------*/
+
+/**@{*/
+
+/*---------------------------------------------------------------------------*/
+/**
+ * @brief
+ *       Finds all the objects that appear at least in some of the catalogues
+ * @param catalogues
+ *       All the catalogues
+ * @param ncats
+ *       Number of catalogues
+ * @return
+ *   The matching table if sucess, NULL otherwise.
+ *
+ *
+ *   Implementation notes:
+ *
+ *   cat_indexing_order tells you in which order the catalogues are being
+ *   iterated. For example cat_indexing_order[2] gives the index of the
+ *   catalogue that is being iterated in the 3rd postion.
+ *
+ *
+*/
+/*---------------------------------------------------------------------------*/
+cpl_table * irplib_match_cat_pairs
+(cpl_table ** catalogues,
+ int          ncats,
+ int (*binary_match_condition)
+   (cpl_table * catalogue1,
+    cpl_table * catalogue2,
+    int         iobj1,
+    int         iobj2)  )
+{
+    cpl_table *  matching_sets;
+
+    //Initialize the solution
+    matching_sets = cpl_table_new(0);
+    cpl_table_new_column_array(matching_sets, "MATCHING_SETS",
+                               CPL_TYPE_INT, ncats);
+
+    irplib_match_cats_get_all_matching_pairs
+        (catalogues, ncats, matching_sets, binary_match_condition);
+    
+    return matching_sets;
+}
+
+cpl_error_code irplib_match_cats_get_all_matching_pairs
+(cpl_table ** catalogues,
+ int          ncats,
+ cpl_table  * matching_sets,
+ int (*binary_match_condition)
+   (cpl_table * catalogue1,
+    cpl_table * catalogue2,
+    int         iobj1,
+    int         iobj2)  )
+{
+    int icat1;
+    int icat2;
+    
+    nCombinations = 0;
+    nFilter = 0;
+
+    for(icat1 = 0; icat1 < ncats ; ++icat1)
+        for(icat2 = icat1 + 1 ; icat2 < ncats ; ++icat2)
+        {
+            int iobj1;
+            int iobj2;
+            int nobj1;
+            int nobj2;
+            
+            nobj1 = cpl_table_get_nrow(catalogues[icat1]);
+            nobj2 = cpl_table_get_nrow(catalogues[icat2]);
+
+            for(iobj1 = 0; iobj1 < nobj1 ; ++iobj1)
+                for(iobj2 = 0 ; iobj2 < nobj2 ; ++iobj2)
+                {
+                    ++nCombinations;
+                    if(binary_match_condition(catalogues[icat1],
+                                              catalogues[icat2],
+                                              iobj1, iobj2))
+                    {
+                        cpl_array  * cats_idx_set;
+                        int          icat;
+                        
+                        ++nFilter;
+                        cats_idx_set = cpl_array_new(ncats, CPL_TYPE_INT);
+                        for(icat = 0; icat < ncats; ++icat)
+                        {
+                            if(icat == icat1)
+                                cpl_array_set_int(cats_idx_set, icat, iobj1);
+                            else if(icat == icat2)
+                                cpl_array_set_int(cats_idx_set, icat, iobj2);
+                            else
+                                cpl_array_set_int(cats_idx_set, icat, -1);
+                        }
+                        
+                        cpl_table_set_size(matching_sets,
+                                           cpl_table_get_nrow(matching_sets)+1);
+                        cpl_table_set_array(matching_sets,"MATCHING_SETS",
+                                            cpl_table_get_nrow(matching_sets)-1,
+                                            cats_idx_set);
+                        cpl_array_delete(cats_idx_set);
+                    }
+                }
+        }
+    
+    return CPL_ERROR_NONE;
+}
+
+/**@}*/
+
diff --git a/irplib/irplib_match_cats.h b/irplib/irplib_match_cats.h
new file mode 100644
index 0000000..99ed5ce
--- /dev/null
+++ b/irplib/irplib_match_cats.h
@@ -0,0 +1,46 @@
+/* $Id: irplib_match_cats.h,v 1.5 2009/12/18 10:44:48 cgarcia Exp $
+ *
+ * This file is part of the irplib package
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: cgarcia $
+ * $Date: 2009/12/18 10:44:48 $
+ * $Revision: 1.5 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifndef IRPLIB_MATCH_CATS_H
+#define IRPLIB_MATCH_CATS_H
+
+/*-----------------------------------------------------------------------------
+                                   Includes
+ -----------------------------------------------------------------------------*/
+
+#include <cpl.h>
+
+cpl_table * irplib_match_cat_pairs
+(cpl_table ** catalogues,
+ int          nCats,
+ int (*binary_match_condition)
+   (cpl_table * catalogue1,
+    cpl_table * catalogue2,
+    int         iobj1,
+    int         iobj2)  );
+
+#endif
diff --git a/irplib/irplib_mkmaster.c b/irplib/irplib_mkmaster.c
new file mode 100644
index 0000000..dbb26bf
--- /dev/null
+++ b/irplib/irplib_mkmaster.c
@@ -0,0 +1,565 @@
+/* $Id: irplib_mkmaster.c,v 1.5 2012/01/12 14:29:41 amodigli Exp $
+ *
+ * This file is part of the irplib package
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2012/01/12 14:29:41 $
+ * $Revision: 1.5 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+/*-----------------------------------------------------------------------------
+                                   Includes
+ -----------------------------------------------------------------------------*/
+
+#include <math.h>
+#include <string.h>
+#include "irplib_mkmaster.h"
+
+/*----------------------------------------------------------------------------*/
+/**
+ * @defgroup irplib_calib   Functions for calibrations
+ */
+/*----------------------------------------------------------------------------*/
+
+/**@{*/
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    find out the character string associated to the DIT keyword
+            in a propertylist
+  @param    plist propertylist 
+  @return   dit value
+ */
+/*---------------------------------------------------------------------------*/
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief	Computes kappa-sigma clean mean (free bad pixels) for each input image of the input imagelist.
+  @param	iml      input imagelist
+  @param	kappa    value for kappa-sigma clip
+  @param	nclip    Number of clipping iterations
+  @param	tolerance tolerance on range between two successive clip iterations
+
+  @return	vector with computed values for each image of the list
+
+  The returned vector must be deallocated.
+ */
+/*--------------------------------------------------------------------------*/
+static cpl_vector * 
+irplib_imagelist_get_clean_mean_levels(const cpl_imagelist* iml, 
+                                       const double kappa, 
+                                       const int nclip,
+                                       const double tolerance)
+{
+
+   const cpl_image* img=NULL;
+   int size=0;
+   int i=0;
+   cpl_vector* levels=NULL;
+   double* pval=NULL;
+   double mean=0;
+   double stdev=0;
+
+
+   cpl_error_ensure(iml != NULL, CPL_ERROR_NULL_INPUT, return(levels),
+                    "Null input image list");
+   cpl_error_ensure(kappa >= 0, CPL_ERROR_ILLEGAL_INPUT, return(levels), 
+                    "Must be kappa>0");
+
+   size=cpl_imagelist_get_size(iml);
+   levels=cpl_vector_new(size);
+   pval=cpl_vector_get_data(levels);
+
+   for(i=0;i<size;i++) {
+      img=cpl_imagelist_get_const(iml,i);
+      irplib_ksigma_clip(img,1,1,
+                         cpl_image_get_size_x(img),
+                         cpl_image_get_size_y(img),
+                         nclip,kappa,tolerance,&mean,&stdev);
+      cpl_msg_info(cpl_func,"Ima %d mean level: %g",i+1,mean);
+      pval[i]=mean;
+   }
+
+
+   return levels;
+}
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief  Subtract from input imagelist values specified in input vector.
+  @param  iml      input imagelist
+  @param  values   value to be subtracted
+  @return corrected imagelist
+
+ */
+/*--------------------------------------------------------------------------*/
+static cpl_error_code
+irplib_imagelist_subtract_values(cpl_imagelist** iml, cpl_vector* values)
+{
+
+   cpl_image* img=NULL;
+   int size=0;
+   int i=0;
+   double* pval=NULL;
+  
+   size=cpl_imagelist_get_size(*iml);
+   pval=cpl_vector_get_data(values);
+
+   for(i=0;i<size;i++) {
+      img=cpl_imagelist_get(*iml,i);
+      cpl_image_subtract_scalar(img,pval[i]);
+      cpl_imagelist_set(*iml,img,i);
+   }
+
+   return cpl_error_get_code();
+}
+
+/*---------------------------------------------------------------------------*/
+/** 
+ * @brief  Perform kappa-sigma clip.
+   @author C. Izzo
+   @param  values values to be checked
+   @param  klow   kappa to clip too low level values
+   @param  khigh  kappa to clip too high values
+   @param  kiter  number of iterations
+
+   @note   In first iteration a median is the reference value for robustness
+
+ * @return 
+ */
+/*---------------------------------------------------------------------------*/
+static double 
+irplib_vector_ksigma(cpl_vector *values,
+                     const double klow, const double khigh, int kiter)
+{
+   cpl_vector *accepted;
+   double  mean  = 0.0;
+   double  sigma = 0.0;
+   double *data  = cpl_vector_get_data(values);
+   int     n     = cpl_vector_get_size(values);
+   int     ngood = n;
+   int     count = 0;
+   int     i;
+ 
+   /*
+    * At first iteration the mean is taken as the median, and the
+    * standard deviation relative to this value is computed.
+    */
+
+   mean = cpl_vector_get_median(values);
+
+   for (i = 0; i < n; i++) {
+      sigma += (mean - data[i]) * (mean - data[i]);
+   }
+   sigma = sqrt(sigma / (n - 1));
+
+   while (kiter) {
+      count = 0;
+      for (i = 0; i < ngood; i++) {
+         if (data[i]-mean < khigh*sigma && mean-data[i] < klow*sigma) {
+            data[count] = data[i];
+            ++count;
+         }
+      }
+
+      if (count == 0) // This cannot happen at first iteration.
+         break;      // So we can break: we have already computed a mean.
+
+      /*
+       * The mean must be computed even if no element was rejected
+       * (count == ngood), because at first iteration median instead
+       * of mean was computed.
+       */
+
+      accepted = cpl_vector_wrap(count, data);
+      mean = cpl_vector_get_mean(accepted);
+      if(count>1) {
+         sigma = cpl_vector_get_stdev(accepted);
+      }
+      cpl_vector_unwrap(accepted);
+
+      if (count == ngood) {
+         break;
+      }
+      ngood = count;
+      --kiter;
+   }
+
+   return mean;
+}
+
+
+/**
+ * @brief
+ *   Stack images using k-sigma clipping
+ *
+ * @param imlist      List of images to stack
+ * @param klow        Number of sigmas for rejection of lowest values
+ * @param khigh       Number of sigmas for rejection of highest values
+ * @param kiter       Max number of iterations
+ *
+ * @return Stacked image.
+ *
+ * At the first iteration the value of sigma is computed relatively to
+ * the median value of all pixels at a given image position. For the
+ * next iterations the sigma is computed in the standard way. If
+ * at some iteration all points would be rejected, the mean computed
+ * at the previous iteration is returned.
+ */
+
+static cpl_image *
+irplib_imagelist_ksigma_stack(const cpl_imagelist *imlist, 
+                              double klow, double khigh, int kiter)
+{
+   int         ni, nx, ny, npix;
+   cpl_image  *out_ima=NULL;
+   cpl_imagelist  *loc_iml=NULL;
+   double      *pout_ima=NULL;
+   cpl_image  *image=NULL;
+   const double     **data=NULL;
+   double     *med=NULL;
+   cpl_vector *time_line=NULL;
+  
+   double     *ptime_line=NULL;
+   int         i, j;
+   double mean_of_medians=0;
+
+   cpl_error_ensure(imlist != NULL, CPL_ERROR_NULL_INPUT, return(out_ima),
+                    "Null input image list");
+
+   ni         = cpl_imagelist_get_size(imlist);
+   loc_iml        = cpl_imagelist_duplicate(imlist);
+   image      = cpl_imagelist_get(loc_iml, 0);
+   nx         = cpl_image_get_size_x(image);
+   ny         = cpl_image_get_size_y(image);
+   npix       = nx * ny;
+
+   out_ima    = cpl_image_new(nx, ny, CPL_TYPE_DOUBLE);
+   pout_ima   = cpl_image_get_data_double(out_ima);
+
+   time_line  = cpl_vector_new(ni);
+   
+   ptime_line = cpl_vector_get_data(time_line);
+
+   data = cpl_calloc(sizeof(double *), ni);
+   med  = cpl_calloc(sizeof(double), ni);
+
+   for (i = 0; i < ni; i++) {
+      image = cpl_imagelist_get(loc_iml, i);
+      med[i]=cpl_image_get_median(image);
+      cpl_image_subtract_scalar(image,med[i]);
+      data[i] = cpl_image_get_data_double(image);
+      mean_of_medians+=med[i];
+   }
+   mean_of_medians/=ni;
+
+   for (i = 0; i < npix; i++) {
+      for (j = 0; j < ni; j++) {
+         ptime_line[j] = data[j][i];
+      }
+      pout_ima[i] = irplib_vector_ksigma(time_line, klow, khigh, kiter); 
+   }
+ 
+   cpl_image_add_scalar(out_ima,mean_of_medians);
+
+ 
+   cpl_free(data);
+   cpl_free(med);
+   cpl_vector_delete(time_line);
+   cpl_imagelist_delete(loc_iml);
+
+   return out_ima;
+
+} 
+
+
+
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief  Computes master frame by clean stack mean of the input imagelist.
+  @param  images   input imagelist
+  @param  kappa    value for kappa-sigma clip
+  @param  nclip    Number of clipping iterations
+  @param  tolerance tolerance on range between two successive clip iterations
+
+  @return master image 
+
+  The returned image must be deallocated.
+ */
+/*--------------------------------------------------------------------------*/
+cpl_image*
+irplib_mkmaster_mean(cpl_imagelist* images,const double kappa, const int nclip, const double tolerance,const double klow,const double khigh,const int niter)
+{
+
+   cpl_image* master=NULL;
+   cpl_vector* levels=NULL;
+   double mean=0;
+   cpl_imagelist* iml=NULL;
+
+   cpl_msg_info(cpl_func,"method mean");
+   iml=cpl_imagelist_duplicate(images);
+   levels=irplib_imagelist_get_clean_mean_levels(iml,kappa,nclip,tolerance);
+   mean=cpl_vector_get_mean(levels);
+   cpl_msg_info(cpl_func,"Master mean level: %g",mean);
+
+   irplib_imagelist_subtract_values(&iml,levels);
+
+   master = irplib_imagelist_ksigma_stack(iml,klow,khigh,niter);
+   cpl_image_add_scalar(master,mean);
+
+   cpl_vector_delete(levels);
+   cpl_imagelist_delete(iml);
+   return master;
+
+}
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief  Computes master frame by clean stack median of the input imagelist.
+  @param  images   input imagelist
+  @param  kappa    value for kappa-sigma clip
+  @param  nclip    Number of clipping iterations
+  @param  tolerance tolerance on range between two successive clip iterations
+
+  @return master image 
+
+  The returned image must be deallocated.
+ */
+/*--------------------------------------------------------------------------*/
+cpl_image* 
+irplib_mkmaster_median(cpl_imagelist* images,const double kappa, const int nclip, const double tolerance)
+{
+
+   cpl_image* master=NULL;
+   cpl_vector* levels=NULL;
+   double mean=0;
+   cpl_imagelist* iml=NULL;
+
+   cpl_msg_info(cpl_func,"method median");
+   iml=cpl_imagelist_duplicate(images);
+   levels=irplib_imagelist_get_clean_mean_levels(iml,kappa,nclip,tolerance);
+
+   mean=cpl_vector_get_mean(levels);
+   cpl_msg_info(cpl_func,"Master mean level: %g",mean);
+   irplib_imagelist_subtract_values(&iml,levels);
+       
+   master = cpl_imagelist_collapse_median_create(iml);
+
+   cpl_image_add_scalar(master,mean);
+
+   cpl_vector_delete(levels);
+   cpl_imagelist_delete(iml);
+
+   return master;
+
+}
+
+/* Work in progress */
+static cpl_error_code
+irplib_mkmaster_dark_qc(const cpl_imagelist* raw_images,
+    cpl_imagelist* preproc_images,
+    const cpl_parameterlist* parameters,
+     const int pr_num_x, const int pr_num_y,
+    const int pr_box_sx, const int pr_box_sy, const char* recipe_id,
+    cpl_table* qclog) {
+
+   cpl_ensure_code(qclog !=NULL, CPL_ERROR_NULL_INPUT);
+   cpl_ensure_code(recipe_id !=NULL, CPL_ERROR_NULL_INPUT);
+   cpl_ensure_code(parameters !=NULL, CPL_ERROR_NULL_INPUT);
+
+  int i = 0;
+  cpl_image* current_dark = 0;
+  if (pr_num_x != 0 && pr_num_y != 0 && pr_box_sx != 0 && pr_box_sy != 0) {
+    for (i = 0; i < cpl_imagelist_get_size(raw_images); i++) {
+      current_dark = cpl_image_duplicate(
+          cpl_imagelist_get_const(preproc_images, i));
+      cpl_msg_info(cpl_func, "Calculating QC parameters on raw dark frame %d",
+          i);
+      /* Here To be defined more general way to qc-log */
+       /* UVES specific stuff: may be this function should not be put in irplib
+      irplib_mdark_region_qc(current_dark, parameters, raw_images, recipe_id,qclog);
+       */    
+    }
+  }
+  return cpl_error_get_code();
+}
+
+/*-------------------------------------------------------------------------*/
+/**
+ @brief    Find out the exposure time in seconds
+ @param    plist       Header to read from
+
+ @return   The requested value, or undefined on error
+
+ An error is set if the exposure time is negative. In that case this negative
+ value is returned.
+ */
+/*-------------------------------------------------------------------------*/
+static double
+irplib_head_get_exptime(const cpl_propertylist * plist) {
+  double result = 0; /* Conversion from electrons to ADUs */
+
+  result=cpl_propertylist_get_double(plist, "EXPTIME");
+  cpl_ensure_code(result >= 0, CPL_ERROR_ILLEGAL_OUTPUT);
+
+  return result;
+}
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Write the exposure time
+  @param    plist        Property list to write to
+  @param    exptime      The value to write
+
+  @return   CPL_ERROR_NONE iff okay.
+ */
+/*-------------------------------------------------------------------------*/
+static cpl_error_code
+irplib_head_set_exptime(cpl_propertylist *plist, double exptime)
+{
+   cpl_propertylist_update_double(plist, "EXPTIME", exptime);
+   cpl_propertylist_set_comment(plist, "EXPTIME", "Total integration time");
+
+    return cpl_error_get_code();
+}
+
+static cpl_imagelist*
+irplib_mkmaster_dark_fill_imagelist(const cpl_imagelist* raw_images,
+    cpl_propertylist** raw_headers, const cpl_image* master_bias,
+    double* mean_exptime) {
+  /* First process each input image and store the results in a
+   new image list */
+
+  cpl_imagelist* preproc_images = NULL;
+  int i = 0;
+  cpl_image* current_dark = NULL;
+  double min_exptime = 0;
+  double max_exptime = 0;
+
+  preproc_images = cpl_imagelist_new();
+  for (i = 0; i < cpl_imagelist_get_size(raw_images); i++) {
+    double exposure_time = 0.0;
+    const cpl_propertylist *current_header;
+
+    current_dark = cpl_image_duplicate(cpl_imagelist_get_const(raw_images, i));
+    current_header = raw_headers[i];
+
+    /* Subtract master bias */
+    if (master_bias != NULL) {
+      cpl_msg_info(cpl_func, "Subtracting master bias");
+      cpl_image_subtract(current_dark, master_bias);
+    } else {
+      cpl_msg_info(cpl_func, "Skipping bias subtraction");
+    }
+
+    exposure_time = irplib_head_get_exptime(current_header);
+
+    /* Initialize/update min/max exposure time*/
+    if (i == 0 || exposure_time < min_exptime) {
+      min_exptime = exposure_time;
+    }
+    if (i == 0 || exposure_time > max_exptime) {
+      max_exptime = exposure_time;
+    }
+
+    /* Do not normalize to unit exposure time */
+    /*        If this is uncommented, then remember to also calculate the
+     correct master dark exposure time below.
+     irplib_msg("Normalizing from %f s to unit exposure time", exposure_time);
+     check( cpl_image_divide_scalar(current_dark, exposure_time),
+     "Error normalizing dark frame");   */
+
+    /* Append to imagelist */
+    cpl_imagelist_set(preproc_images, current_dark, i);
+
+    /* Don't deallocate the image. It will be deallocated when
+     the image list is deallocated */
+    current_dark = NULL;
+  }
+
+
+  /* Check exposure times */
+   cpl_msg_info(cpl_func,
+       "Exposure times range from %e s to %e s (%e %% variation)", min_exptime,
+       max_exptime, 100 * (max_exptime - min_exptime) / min_exptime);
+
+   if ((max_exptime - min_exptime) / min_exptime > .001) {
+     cpl_msg_warning(cpl_func, "Exposure times differ by %e %%",
+         100 * (max_exptime - min_exptime) / min_exptime);
+   }
+
+   /* compute correct exposure time */
+   *mean_exptime=0.5 * (max_exptime + min_exptime);
+  return preproc_images;
+}
+
+
+cpl_image *
+irplib_mdark_process_chip(const cpl_imagelist *raw_images,
+    cpl_propertylist **raw_headers, const cpl_image *master_bias,
+    cpl_propertylist *mdark_header, const cpl_parameterlist *parameters,
+    const char* recipe_id, cpl_table* qclog, const int do_qc,
+    const char* STACK_METHOD, const double STACK_KLOW, const double STACK_KHIGH,
+    const int STACK_NITER,
+    const int pr_num_x, const int pr_num_y,
+    const int pr_box_sx, const int pr_box_sy) {
+  cpl_image *master_dark = NULL; /* Result */
+  cpl_image *current_dark = NULL;
+  cpl_imagelist *preproc_images = NULL;
+  double mean_exptime = 0;
+
+  /* First process each input image and store the results in a
+   new image list */
+  preproc_images = irplib_mkmaster_dark_fill_imagelist(raw_images, raw_headers,
+      master_bias, &mean_exptime);
+  if (do_qc) {
+     /* Here we should compute QC but a a better way to log it is TBD  */
+    irplib_mkmaster_dark_qc(raw_images, preproc_images, parameters, pr_num_x,
+        pr_num_y, pr_box_sx, pr_box_sy, recipe_id, qclog);
+     
+  }
+  /* Get median stack of input darks */
+  if (strcmp(STACK_METHOD, "MEDIAN") == 0) {
+    cpl_msg_info(cpl_func, "Calculating stack median");
+    master_dark = cpl_imagelist_collapse_median_create(preproc_images);
+  } else {
+    cpl_msg_info(cpl_func, "Calculating stack mean");
+    master_dark = irplib_imagelist_ksigma_stack(preproc_images, STACK_KLOW,
+        STACK_KHIGH, STACK_NITER);
+
+  }
+  irplib_head_set_exptime(mdark_header, mean_exptime );
+
+  cpl_image_delete(current_dark);
+  cpl_imagelist_delete(preproc_images);
+  if (cpl_error_get_code() != CPL_ERROR_NONE) {
+    cpl_image_delete(master_dark);
+  }
+
+  return master_dark;
+}
+
+/**@}*/
+
diff --git a/irplib/irplib_mkmaster.h b/irplib/irplib_mkmaster.h
new file mode 100644
index 0000000..27f35dd
--- /dev/null
+++ b/irplib/irplib_mkmaster.h
@@ -0,0 +1,53 @@
+/* $Id: irplib_mkmaster.h,v 1.3 2011/11/02 13:17:25 amodigli Exp $
+ *
+ * This file is part of the irplib package
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2011/11/02 13:17:25 $
+ * $Revision: 1.3 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifndef IRPLIB_MKMASTER_H
+#define IRPLIB_MKMASTER_H
+
+/*-----------------------------------------------------------------------------
+                                   Includes
+ -----------------------------------------------------------------------------*/
+
+#include <cpl.h>
+#include <irplib_ksigma_clip.h>
+
+cpl_image*
+irplib_mkmaster_mean(cpl_imagelist* images,const double kappa, const int nclip, const double tolerance,const double klow,const double khigh,const int niter);
+
+cpl_image* 
+irplib_mkmaster_median(cpl_imagelist* images,const double kappa, const int nclip, const double tolerance);
+
+cpl_image *
+irplib_mdark_process_chip(const cpl_imagelist *raw_images,
+    cpl_propertylist **raw_headers, const cpl_image *master_bias,
+    cpl_propertylist *mdark_header, const cpl_parameterlist *parameters,
+    const char* recipe_id, cpl_table* qclog, const int do_qc,
+    const char* STACK_METHOD, const double STACK_KLOW, const double STACK_KHIGH,
+    const int STACK_NITER,
+    const int pr_num_x, const int pr_num_y,
+    const int pr_box_sx, const int pr_box_sy);
+#endif
diff --git a/irplib/irplib_oddeven.c b/irplib/irplib_oddeven.c
new file mode 100644
index 0000000..f19b293
--- /dev/null
+++ b/irplib/irplib_oddeven.c
@@ -0,0 +1,338 @@
+/* $Id: irplib_oddeven.c,v 1.9 2012/01/12 11:50:41 llundin Exp $
+ *
+ * This file is part of the irplib package
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: llundin $
+ * $Date: 2012/01/12 11:50:41 $
+ * $Revision: 1.9 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+/*-----------------------------------------------------------------------------
+                                   Includes
+ -----------------------------------------------------------------------------*/
+
+#include <math.h>
+#include <cpl.h>
+
+#include "irplib_oddeven.h"
+
+/*-----------------------------------------------------------------------------
+                            Functions prototypes
+ -----------------------------------------------------------------------------*/
+
+static cpl_imagelist * irplib_oddeven_cube_conv_xy_rtheta(cpl_imagelist *) ;
+static cpl_imagelist * irplib_oddeven_cube_conv_rtheta_xy(cpl_imagelist *) ;
+ 
+/*----------------------------------------------------------------------------*/
+/**
+ * @defgroup irplib_oddeven     Odd/Even column effect correction
+ */
+/*----------------------------------------------------------------------------*/
+
+/**@{*/
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Estimate the odd/even rate in an image quadrant
+  @param    in      the inpute image
+  @param    iquad    the quadrant (ll=1, lr=2, ul=3, ur=4, all=0)  
+  @param    r_even  the median of even columns / median of all columns
+  @return   0 if ok, -1 otherwise
+*/
+/*----------------------------------------------------------------------------*/
+int irplib_oddeven_monitor(
+        const cpl_image     *   in,
+        int                     iquad,
+        double              *   r_even) 
+{
+    cpl_image       *   extracted ;        
+    cpl_image       *   labels ;        
+    int             *   plabels ;
+    int                 llx, lly, urx, ury ;
+    int                 nx, ny ;
+    double              f_even, f_tot ;
+    cpl_apertures   *   aperts ;
+    int                 i, j ;
+
+    /* Test entries */
+    if (in == NULL || r_even == NULL) return -1 ;
+    nx = cpl_image_get_size_x(in) ;
+    ny = cpl_image_get_size_y(in) ;
+    
+    switch (iquad){
+        case 1:
+            llx = 1 ; lly = 1 ; urx = nx/2 ; ury = ny/2 ; break ;
+        case 2:
+            llx = (nx/2)+1 ; lly = 1 ; urx = nx ; ury = ny/2 ; break ;
+        case 3:
+            llx = 1 ; lly = (ny/2)+1 ; urx = nx/2 ; ury = ny ; break ;
+        case 4:
+            llx = (nx/2)+1 ; lly = (ny/2)+1 ; urx = nx ; ury = ny ; break ;
+        case 0:
+            llx = 1 ; lly = 1 ; urx = nx ; ury = ny ; break ;
+        default:
+            cpl_msg_error(cpl_func, "Unsupported mode") ;
+            *r_even = 0.0 ;
+            return -1 ;
+    }
+   
+    /* Extract quadrant */
+    if ((extracted = cpl_image_extract(in, llx, lly, urx, ury)) == NULL) {
+        cpl_msg_error(cpl_func, "Cannot extract quadrant") ;
+        *r_even = 0.0 ;
+        return -1 ;
+    }
+    nx = cpl_image_get_size_x(extracted) ;
+    ny = cpl_image_get_size_y(extracted) ;
+            
+    /* Get f_tot */
+    f_tot = cpl_image_get_median(extracted) ;
+    if (fabs(f_tot) < 1e-6) {
+        cpl_msg_warning(cpl_func, "Quadrant median is 0.0") ;
+        cpl_image_delete(extracted) ;
+        *r_even = 0.0 ;
+        return -1 ;
+    }
+
+    /* Create the label image to define the even columns */
+    labels = cpl_image_new(nx, ny, CPL_TYPE_INT) ;
+    plabels = cpl_image_get_data_int(labels) ;
+    for (i=0 ; i<nx ; i++) {
+        if (i % 2) for (j=0 ; j<ny ; j++) plabels[i+j*nx] = 0 ;
+        else for (j=0 ; j<ny ; j++) plabels[i+j*nx] = 1 ;
+    }
+    
+    /* Get the median of even columns */
+    if ((aperts = cpl_apertures_new_from_image(extracted, labels)) == NULL) {
+        cpl_msg_error(cpl_func, "Cannot compute the even columns median") ;
+        cpl_image_delete(extracted) ;
+        cpl_image_delete(labels) ;
+        *r_even = 0.0 ;
+        return -1 ;
+    }
+    cpl_image_delete(extracted) ;
+    cpl_image_delete(labels) ;
+    f_even = cpl_apertures_get_median(aperts, 1) ;
+    cpl_apertures_delete(aperts) ;
+    
+    /* Compute the even rate and return */
+    *r_even = f_even / f_tot ;
+    return 0 ;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Correct the odd/even in an image 
+  @param    in      the inpute image
+  @return   the corrected image or NULL on error case
+*/
+/*----------------------------------------------------------------------------*/
+cpl_image * irplib_oddeven_correct(const cpl_image * in)
+{
+    cpl_image       *   in_real ;
+    cpl_image       *   in_imag ;
+    cpl_imagelist   *   freq_i ;
+    cpl_imagelist   *   freq_i_amp ;
+    cpl_image       *   cur_im ;
+    double          *   pcur_im ;
+    cpl_image       *   cleaned ;
+    int                 nx ;
+    cpl_vector      *   hf_med ;
+
+    /* Test entries */
+    if (in==NULL) return NULL ;
+
+    nx = cpl_image_get_size_x(in) ;
+
+    /* Local copy of the input image in DOUBLE */
+    in_real = cpl_image_cast(in, CPL_TYPE_DOUBLE) ;
+    in_imag = cpl_image_duplicate(in_real) ;
+    cpl_image_multiply_scalar(in_imag, 0.0) ;
+    
+    /* Apply FFT to input image */
+    cpl_image_fft(in_real, in_imag, CPL_FFT_DEFAULT) ;
+
+    /* Put the result in an image list */
+    freq_i = cpl_imagelist_new() ;
+    cpl_imagelist_set(freq_i, in_real, 0) ;
+    cpl_imagelist_set(freq_i, in_imag, 1) ;
+    
+    /* Convert to amplitude/phase */
+    freq_i_amp = irplib_oddeven_cube_conv_xy_rtheta(freq_i);
+    cpl_imagelist_delete(freq_i) ;
+
+    /* Correct the odd-even frequency */
+    cur_im = cpl_imagelist_get(freq_i_amp, 0) ;
+    pcur_im = cpl_image_get_data_double(cur_im) ;
+    /* Odd-even frequency will be replaced by 
+       the median of the 5 values around */
+    hf_med = cpl_vector_new(5); 
+
+    cpl_vector_set(hf_med, 0, pcur_im[nx/2 + 1]); 
+    cpl_vector_set(hf_med, 1, pcur_im[nx/2 + 2]);
+    cpl_vector_set(hf_med, 2, pcur_im[nx/2 + 3]);
+    cpl_vector_set(hf_med, 3, pcur_im[nx/2    ]);
+    cpl_vector_set(hf_med, 4, pcur_im[nx/2  -1]);
+
+    pcur_im[nx / 2 + 1] = cpl_vector_get_median(hf_med);
+    cpl_vector_delete(hf_med);
+
+    /* Convert to X/Y */
+    freq_i = irplib_oddeven_cube_conv_rtheta_xy(freq_i_amp) ;
+    cpl_imagelist_delete(freq_i_amp) ;
+    /* FFT back to image space */
+    cpl_image_fft(cpl_imagelist_get(freq_i, 0), cpl_imagelist_get(freq_i, 1), 
+            CPL_FFT_INVERSE) ;
+    cleaned = cpl_image_cast(cpl_imagelist_get(freq_i, 0), CPL_TYPE_FLOAT) ;
+    cpl_imagelist_delete(freq_i) ;
+    return cleaned ;
+}
+
+/**@}*/
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Convert a 2-plane cube from (real,imag) to (ampl,phase).
+  @param    cube_in        Input cube (containing 2 planes)
+  @return    1 newly allocated cube containing 2 planes.
+
+  The input cube is expected to contain two planes: first one is the real part 
+  of a complex image, second one is the imaginary part of the same image. The 
+  returned cube contains two planes: first one is the complex amplitude of the 
+  image, second one is the phase.
+ */
+/*----------------------------------------------------------------------------*/
+static cpl_imagelist * irplib_oddeven_cube_conv_xy_rtheta(
+        cpl_imagelist   *   cube_in)
+{
+    cpl_imagelist       *   cube_out ;
+    double                  re, im ;
+    double                  mod, phase ;
+    int                     nx, ny, np ;
+    cpl_image           *   tmp_im ;
+    double              *   pim1 ;
+    double              *   pim2 ;
+    double              *   pim3 ;
+    double              *   pim4 ;
+    int                     i, j ;
+
+    /* Error handling : test entries    */
+    if (cube_in == NULL) return NULL ;
+    np = cpl_imagelist_get_size(cube_in) ;
+    if (np != 2) return NULL ;
+
+    /* Initialise */
+    tmp_im = cpl_imagelist_get(cube_in, 0) ;
+    pim1 = cpl_image_get_data_double(tmp_im) ;
+    nx = cpl_image_get_size_x(tmp_im) ;
+    ny = cpl_image_get_size_y(tmp_im) ;
+    tmp_im = cpl_imagelist_get(cube_in, 1) ;
+    pim2 = cpl_image_get_data_double(tmp_im) ;
+
+    /* Allocate cube_out */
+    cube_out = cpl_imagelist_duplicate(cube_in) ;
+
+    tmp_im = cpl_imagelist_get(cube_out, 0) ;
+    pim3 = cpl_image_get_data_double(tmp_im) ;
+    tmp_im = cpl_imagelist_get(cube_out, 1) ;
+    pim4 = cpl_image_get_data_double(tmp_im) ;
+    /* Convert */
+    for (j=0 ; j<ny ; j++) {
+        for (i=0 ; i<nx ; i++) {
+            re = (double)pim1[i+j*nx] ;
+            im = (double)pim2[i+j*nx] ;
+            mod = (double)(sqrt(re*re + im*im)) ;
+            if (re != 0.0)
+                phase = (double)atan2(im, re) ;
+            else 
+                phase = 0.0 ;
+            pim3[i+j*nx] = mod ; 
+            pim4[i+j*nx] = phase ; 
+        }
+    }
+    return cube_out ;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Convert a 2-plane cube from (ampl,phase) to (real,imag).
+  @param    cube_in        Input cube (containing 2 planes)
+  @return    1 newly allocated cube containing 2 planes.
+
+  The input cube is expected to contain two planes: first one is the
+  amplitude of a complex image, second one is the phase. The returned cube
+  contains two planes: first one is the real part of the image, second one
+  is the imaginary part.
+
+  The returned cube must be deallocated using cube_del().
+ */
+/*----------------------------------------------------------------------------*/
+static cpl_imagelist * irplib_oddeven_cube_conv_rtheta_xy(
+        cpl_imagelist   *   cube_in)
+{
+    cpl_imagelist       *   cube_out ;
+    double                  re, im ;
+    double                  mod, phase ;
+    int                     nx, ny, np ;
+    cpl_image           *   tmp_im ;
+    double              *   pim1 ;
+    double              *   pim2 ;
+    double              *   pim3 ;
+    double              *   pim4 ;
+    int                     i, j ;
+
+    /* Error handling : test entries    */
+    if (cube_in == NULL) return NULL ;
+    np = cpl_imagelist_get_size(cube_in) ;
+    if (np != 2) return NULL ;
+
+    /* Initialise */
+    tmp_im = cpl_imagelist_get(cube_in, 0) ;
+    pim1 = cpl_image_get_data_double(tmp_im) ;
+    nx = cpl_image_get_size_x(tmp_im) ;
+    ny = cpl_image_get_size_y(tmp_im) ;
+    tmp_im = cpl_imagelist_get(cube_in, 1) ;
+    pim2 = cpl_image_get_data_double(tmp_im) ;
+
+    /* Allocate cube_out */
+    cube_out = cpl_imagelist_duplicate(cube_in) ;
+
+    tmp_im = cpl_imagelist_get(cube_out, 0) ;
+    pim3 = cpl_image_get_data_double(tmp_im) ;
+    tmp_im = cpl_imagelist_get(cube_out, 1) ;
+    pim4 = cpl_image_get_data_double(tmp_im) ;
+    /* Convert */
+    for (j=0 ; j<ny ; j++) {
+        for (i=0 ; i<nx ; i++) {
+            mod = (double)pim1[i+j*nx] ;
+            phase = (double)pim2[i+j*nx] ;
+            re = (double)(mod * cos(phase));
+            im = (double)(mod * sin(phase));
+            pim3[i+j*nx] = re ; 
+            pim4[i+j*nx] = im ; 
+        }
+    }
+    return cube_out ;
+}
diff --git a/irplib/irplib_oddeven.h b/irplib/irplib_oddeven.h
new file mode 100644
index 0000000..70fc11f
--- /dev/null
+++ b/irplib/irplib_oddeven.h
@@ -0,0 +1,40 @@
+/* $Id: irplib_oddeven.h,v 1.4 2006/10/06 20:46:04 yjung Exp $
+ *
+ * This file is part of the irplib package
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: yjung $
+ * $Date: 2006/10/06 20:46:04 $
+ * $Revision: 1.4 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifndef IRPLIB_ODDEVEN_H
+#define IRPLIB_ODDEVEN_H
+
+/*-----------------------------------------------------------------------------
+                                   Includes
+ -----------------------------------------------------------------------------*/
+
+#include <cpl.h>
+
+int irplib_oddeven_monitor(const cpl_image *, int, double *) ;
+cpl_image * irplib_oddeven_correct(const cpl_image *) ;
+
+#endif
diff --git a/irplib/irplib_plugin.c b/irplib/irplib_plugin.c
new file mode 100644
index 0000000..feba345
--- /dev/null
+++ b/irplib/irplib_plugin.c
@@ -0,0 +1,1267 @@
+/* $Id: irplib_plugin.c,v 1.39 2012/02/03 14:19:06 llundin Exp $
+ *
+ * This file is part of the irplib package 
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: llundin $
+ * $Date: 2012/02/03 14:19:06 $
+ * $Revision: 1.39 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+/*-----------------------------------------------------------------------------
+                                Includes
+ -----------------------------------------------------------------------------*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <string.h>
+#include <stdlib.h>
+#include <assert.h>
+
+#include <cpl.h>
+
+
+#include "irplib_plugin.h"
+
+/*----------------------------------------------------------------------------*/
+/**
+ * @defgroup irplib_plugin Irplib plugin functionality
+ *
+ * This module provides a macro and a unit test function for @em irplib_plugin.
+ *
+ * @code
+ *   #include "irplib_plugin.h"
+ * @endcode
+ */
+/*----------------------------------------------------------------------------*/
+
+/*-----------------------------------------------------------------------------
+                                Defines
+ -----------------------------------------------------------------------------*/
+
+/* Maximum line length in SOF-file */
+#ifndef LINE_LEN_MAX
+#define LINE_LEN_MAX 1024
+#endif
+
+/* This device provides quite-random data */
+#define DEV_RANDOM "/dev/urandom"
+
+/* Copied from cpl_tools.h */
+#define recipe_assert(bool) \
+  ((bool) ? (cpl_msg_debug(cpl_func, \
+     "OK in " __FILE__ " line %d (CPL-error state: '%s' in %s): %s",__LINE__, \
+       cpl_error_get_message(), cpl_error_get_where(), #bool), 0) \
+          : (cpl_msg_error(cpl_func, \
+     "Failure in " __FILE__ " line %d (CPL-error state: '%s' in %s): %s", \
+      __LINE__, cpl_error_get_message(), cpl_error_get_where(), #bool), 1))
+
+
+
+/*-----------------------------------------------------------------------------
+                            Private Function prototypes
+ -----------------------------------------------------------------------------*/
+
+static const cpl_parameter * irplib_parameterlist_get(const cpl_parameterlist *,
+                                                      const char *,
+                                                      const char *,
+                                                      const char *);
+
+static void recipe_parameterlist_set(cpl_parameterlist *);
+static cpl_boolean irplib_plugin_has_sof_from_env(const cpl_plugin *,
+                                                  const char *);
+
+static void recipe_frameset_load(cpl_frameset *, const char *);
+
+static void recipe_sof_test_devfile(cpl_plugin *, const char *, size_t,
+                                   const char *[]);
+static void recipe_sof_test_image_empty(cpl_plugin *, size_t, const char *[]);
+static void recipe_sof_test_local(cpl_plugin *);
+static void recipe_sof_test_from_env(cpl_plugin *);
+static void recipe_frameset_empty(cpl_frameset *);
+static void recipe_frameset_test_frame(const cpl_frame *);
+static void recipe_frameset_test_frameset_diff(const cpl_frameset *,
+                                               const cpl_frameset *);
+
+static cpl_errorstate inistate;
+
+/**@{*/
+
+/*-----------------------------------------------------------------------------
+                            Function definitions
+ -----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Retrieve the value of a plugin parameter of type string
+  @param    self      The parameterlist to get from
+  @param    instrume  The recipe name, e.g. PACKAGE from config.h
+  @param    recipe    The recipe name, e.g. "rrrecipe"
+  @param    parameter The parameter name, e.g. "stropt"
+  @return   The string, or NULL on error
+
+ */
+/*----------------------------------------------------------------------------*/
+const char * irplib_parameterlist_get_string(const cpl_parameterlist * self,
+                                             const char * instrume,
+                                             const char * recipe,
+                                             const char * parameter)
+{
+
+    const cpl_parameter * par = irplib_parameterlist_get(self, instrume,
+                                                         recipe, parameter);
+    const char * value;
+
+    cpl_ensure(par != NULL, cpl_error_get_code(), NULL);
+
+    value = cpl_parameter_get_string(par);
+
+    if (value == NULL) (void)cpl_error_set_where(cpl_func);
+
+    return value;
+
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Retrieve the value of a plugin parameter of type int
+  @param    self      The parameterlist to get from
+  @param    instrume  The recipe name, e.g. PACKAGE from config.h
+  @param    recipe    The recipe name, e.g. "rrrecipe"
+  @param    parameter The parameter name, e.g. "boolopt"
+  @return   The cpl_boolean (CPL_FALSE or CPL_TRUE), or undefined on error
+
+ */
+/*----------------------------------------------------------------------------*/
+cpl_boolean irplib_parameterlist_get_bool(const cpl_parameterlist * self,
+                                          const char * instrume,
+                                          const char * recipe,
+                                          const char * parameter)
+{
+
+    const cpl_parameter * par = irplib_parameterlist_get(self, instrume,
+                                                         recipe, parameter);
+    cpl_errorstate        prestate = cpl_errorstate_get();
+    cpl_boolean           value;
+
+
+    cpl_ensure(par != NULL, cpl_error_get_code(), CPL_FALSE);
+
+    value = cpl_parameter_get_bool(par);
+
+    if (!cpl_errorstate_is_equal(prestate)) (void)cpl_error_set_where(cpl_func);
+
+    return value;
+
+}
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Retrieve the value of a plugin parameter of type int
+  @param    self      The parameterlist to get from
+  @param    instrume  The recipe name, e.g. PACKAGE from config.h
+  @param    recipe    The recipe name, e.g. "rrrecipe"
+  @param    parameter The parameter name
+  @return   The int, or undefined on error
+
+ */
+/*----------------------------------------------------------------------------*/
+int irplib_parameterlist_get_int(const cpl_parameterlist * self,
+                                 const char * instrume,
+                                 const char * recipe,
+                                 const char * parameter)
+{
+
+    const cpl_parameter * par = irplib_parameterlist_get(self, instrume,
+                                                         recipe, parameter);
+    cpl_errorstate        prestate = cpl_errorstate_get();
+    int                   value;
+
+
+    cpl_ensure(par != NULL, cpl_error_get_code(), 0);
+
+    value = cpl_parameter_get_int(par);
+
+    if (!cpl_errorstate_is_equal(prestate)) (void)cpl_error_set_where(cpl_func);
+
+    return value;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Retrieve the value of a plugin parameter of type double
+  @param    self      The parameterlist to get from
+  @param    instrume  The recipe name, e.g. PACKAGE from config.h
+  @param    recipe    The recipe name, e.g. "rrrecipe"
+  @param    parameter The parameter name
+  @return   The double, or undefined on error
+
+ */
+/*----------------------------------------------------------------------------*/
+double irplib_parameterlist_get_double(const cpl_parameterlist * self,
+                                       const char * instrume,
+                                       const char * recipe,
+                                       const char * parameter)
+{
+
+    const cpl_parameter * par = irplib_parameterlist_get(self, instrume,
+                                                         recipe, parameter);
+    cpl_errorstate        prestate = cpl_errorstate_get();
+    double                value;
+
+
+    cpl_ensure(par != NULL, cpl_error_get_code(), 0.0);
+
+    value = cpl_parameter_get_double(par);
+
+    if (!cpl_errorstate_is_equal(prestate)) (void)cpl_error_set_where(cpl_func);
+
+    return value;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Add a parameter of type string to a plugin parameterlist
+  @param    self      The parameterlist to set
+  @param    instrume  The recipe name, e.g. PACKAGE from config.h
+  @param    recipe    The recipe name, e.g. "rrrecipe"
+  @param    parameter The parameter name
+  @param    defvalue  The default value of the parameter
+  @param    alias     The alias of the parameter or NULL to alias to parameter
+  @param    context   The parameter context
+  @param    man       The man-page of the parameter
+  @return   CPL_ERROR_NONE or the relevant CPL error code
+
+ */
+/*----------------------------------------------------------------------------*/
+cpl_error_code irplib_parameterlist_set_string(cpl_parameterlist * self,
+                                               const char * instrume,
+                                               const char * recipe,
+                                               const char * parameter,
+                                               const char * defvalue,
+                                               const char * alias,
+                                               const char * context,
+                                               const char * man)
+{
+
+    cpl_error_code  error;
+    cpl_parameter * par;
+    char          * paramname = cpl_sprintf("%s.%s.%s", instrume, recipe,
+                                            parameter);
+
+    cpl_ensure_code(paramname != NULL, cpl_error_get_code());
+    
+    par = cpl_parameter_new_value(paramname, CPL_TYPE_STRING, man, context,
+                                  defvalue);
+    cpl_free(paramname);
+
+    cpl_ensure_code(par != NULL, cpl_error_get_code());
+    
+    error = cpl_parameter_set_alias(par, CPL_PARAMETER_MODE_CLI,
+                                    alias ? alias : parameter);
+    cpl_ensure_code(!error, error);
+
+    error = cpl_parameter_disable(par, CPL_PARAMETER_MODE_ENV);
+    cpl_ensure_code(!error, error);
+
+    error = cpl_parameterlist_append(self, par);
+    cpl_ensure_code(!error, error);
+    
+    return CPL_ERROR_NONE;
+}
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Add a parameter of type cpl_boolean to a plugin parameterlist
+  @param    self      The parameterlist to set
+  @param    instrume  The recipe name, e.g. PACKAGE from config.h
+  @param    recipe    The recipe name, e.g. "rrrecipe"
+  @param    parameter The parameter name
+  @param    defvalue  The default value of the parameter
+  @param    alias     The alias of the parameter or NULL to alias to parameter
+  @param    context   The parameter context
+  @param    man       The man-page of the parameter
+  @return   CPL_ERROR_NONE or the relevant CPL error code
+
+ */
+/*----------------------------------------------------------------------------*/
+cpl_error_code irplib_parameterlist_set_bool(cpl_parameterlist * self,
+                                             const char * instrume,
+                                             const char * recipe,
+                                             const char * parameter,
+                                             cpl_boolean  defvalue,
+                                             const char * alias,
+                                             const char * context,
+                                             const char * man)
+{
+
+    cpl_error_code  error;
+    cpl_parameter * par;
+    char          * paramname = cpl_sprintf("%s.%s.%s", instrume, recipe,
+                                            parameter);
+
+    cpl_ensure_code(paramname != NULL, cpl_error_get_code());
+    
+    par = cpl_parameter_new_value(paramname, CPL_TYPE_BOOL, man, context,
+                                  defvalue);
+    cpl_free(paramname);
+
+    cpl_ensure_code(par != NULL, cpl_error_get_code());
+    
+    error = cpl_parameter_set_alias(par, CPL_PARAMETER_MODE_CLI,
+                                    alias ? alias : parameter);
+    cpl_ensure_code(!error, error);
+    
+    error = cpl_parameter_disable(par, CPL_PARAMETER_MODE_ENV);
+    cpl_ensure_code(!error, error);
+
+    error = cpl_parameterlist_append(self, par);
+    cpl_ensure_code(!error, error);
+    
+    return CPL_ERROR_NONE;
+}
+
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Add a parameter of type int to a plugin parameterlist
+  @param    self      The parameterlist to set
+  @param    instrume  The recipe name, e.g. PACKAGE from config.h
+  @param    recipe    The recipe name, e.g. "rrrecipe"
+  @param    parameter The parameter name
+  @param    defvalue  The default value of the parameter
+  @param    alias     The alias of the parameter or NULL to alias to parameter
+  @param    context   The parameter context
+  @param    man       The man-page of the parameter
+  @return   CPL_ERROR_NONE or the relevant CPL error code
+
+ */
+/*----------------------------------------------------------------------------*/
+cpl_error_code irplib_parameterlist_set_int(cpl_parameterlist * self,
+                                            const char * instrume,
+                                            const char * recipe,
+                                            const char * parameter,
+                                            int         defvalue,
+                                            const char * alias,
+                                            const char * context,
+                                            const char * man)
+{
+
+    cpl_error_code  error;
+    cpl_parameter * par;
+    char          * paramname = cpl_sprintf("%s.%s.%s", instrume, recipe,
+                                            parameter);
+
+    cpl_ensure_code(paramname != NULL, cpl_error_get_code());
+    
+    par = cpl_parameter_new_value(paramname, CPL_TYPE_INT, man, context,
+                                  defvalue);
+    cpl_free(paramname);
+
+    cpl_ensure_code(par != NULL, cpl_error_get_code());
+    
+    error = cpl_parameter_set_alias(par, CPL_PARAMETER_MODE_CLI,
+                                    alias ? alias : parameter);
+    cpl_ensure_code(!error, error);
+    
+    error = cpl_parameter_disable(par, CPL_PARAMETER_MODE_ENV);
+    cpl_ensure_code(!error, error);
+
+    error = cpl_parameterlist_append(self, par);
+    cpl_ensure_code(!error, error);
+    
+    return CPL_ERROR_NONE;
+}
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Add a parameter of type double to a plugin parameterlist
+  @param    self      The parameterlist to set
+  @param    instrume  The recipe name, e.g. PACKAGE from config.h
+  @param    recipe    The recipe name, e.g. "rrrecipe"
+  @param    parameter The parameter name
+  @param    defvalue  The default value of the parameter
+  @param    alias     The alias of the parameter or NULL to alias to parameter
+  @param    context   The parameter context
+  @param    man       The man-page of the parameter
+  @return   CPL_ERROR_NONE or the relevant CPL error code
+
+ */
+/*----------------------------------------------------------------------------*/
+cpl_error_code irplib_parameterlist_set_double(cpl_parameterlist * self,
+                                               const char * instrume,
+                                               const char * recipe,
+                                               const char * parameter,
+                                               double       defvalue,
+                                               const char * alias,
+                                               const char * context,
+                                               const char * man)
+{
+
+    cpl_error_code  error;
+    cpl_parameter * par;
+    char          * paramname = cpl_sprintf("%s.%s.%s", instrume, recipe,
+                                            parameter);
+
+    cpl_ensure_code(paramname != NULL, cpl_error_get_code());
+    
+    par = cpl_parameter_new_value(paramname, CPL_TYPE_DOUBLE, man, context,
+                                  defvalue);
+    cpl_free(paramname);
+
+    cpl_ensure_code(par != NULL, cpl_error_get_code());
+    
+    error = cpl_parameter_set_alias(par, CPL_PARAMETER_MODE_CLI,
+                                    alias ? alias : parameter);
+    cpl_ensure_code(!error, error);
+    
+    error = cpl_parameter_disable(par, CPL_PARAMETER_MODE_ENV);
+    cpl_ensure_code(!error, error);
+
+    error = cpl_parameterlist_append(self, par);
+    cpl_ensure_code(!error, error);
+    
+    return CPL_ERROR_NONE;
+}
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Find a plugin and submit it to some tests
+  @param    self   A non-empty pluginlist
+  @param    nstr   The counter of parameter strings, may be zero
+  @param    astr   The array of nstr parameter strings, may be NULL
+  @return   0
+  @note astr may be NULL iff nstr is zero.
+        If nstr is non-zero, the strings are used as tags in SOFs
+        created to test the plugin.
+
+  FIXME: Redeclare to void
+
+ */
+/*----------------------------------------------------------------------------*/
+int irplib_plugin_test(cpl_pluginlist * self, size_t nstr, const char *astr[]) {
+
+    cpl_plugin     * plugin;
+    cpl_recipe     * recipe;
+    int            (*recipe_create) (cpl_plugin *);
+    int            (*recipe_exec  ) (cpl_plugin *);
+    int            (*recipe_deinit) (cpl_plugin *);
+    cpl_error_code error;
+    FILE         * stream;
+    cpl_boolean    is_debug;
+
+
+    is_debug = cpl_msg_get_level() <= CPL_MSG_DEBUG ? CPL_TRUE : CPL_FALSE;
+
+    /* Modified from CPL unit tests */
+    stream = is_debug ? stdout : fopen("/dev/null", "a");
+
+    inistate = cpl_errorstate_get();
+
+    assert( nstr == 0 || astr != NULL );
+
+    plugin = cpl_pluginlist_get_first(self);
+
+    if (plugin == NULL) {
+        cpl_msg_warning(cpl_func, "With an empty pluginlist, "
+                        "no tests can be made");
+        return 0;
+    }
+
+    cpl_plugin_dump(plugin, stream);
+
+    recipe_create = cpl_plugin_get_init(plugin);
+    cpl_test( recipe_create != NULL);
+
+    recipe_exec   = cpl_plugin_get_exec(plugin);
+    cpl_test( recipe_exec != NULL);
+
+    recipe_deinit = cpl_plugin_get_deinit(plugin);
+    cpl_test( recipe_deinit != NULL);
+
+    /* Only plugins of type recipe are tested (further)  */
+    if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
+        cpl_msg_warning(cpl_func, "This plugin is not of type recipe, "
+                      "cannot test further");
+        return 0;
+    }
+
+    if (recipe_create != NULL && recipe_exec != NULL && recipe_deinit != NULL) {
+
+        cpl_test_zero(recipe_create(plugin));
+
+        recipe = (cpl_recipe *) plugin;
+
+        cpl_test_nonnull( recipe->parameters );
+
+        recipe_parameterlist_set(recipe->parameters);
+
+        cpl_parameterlist_dump(recipe->parameters, stream);
+
+        recipe->frames = cpl_frameset_new();
+
+        if (irplib_plugin_has_sof_from_env(plugin, "RECIPE_SOF_PATH")) {
+
+            recipe_sof_test_from_env(plugin);
+
+        } else {
+
+            const cpl_msg_severity msg_level = cpl_msg_get_level();
+
+            /* Unless the CPL_MSG_LEVEL has been explicitly set, turn off
+               terminal messaging completely while inside this function */
+            if (getenv("CPL_MSG_LEVEL") == NULL) cpl_msg_set_level(CPL_MSG_OFF);
+
+            cpl_msg_info(cpl_func,"Checking handling of pre-existing CPL error "
+                         "state - may produce warning(s)/error(s):");
+            cpl_error_set(cpl_func, CPL_ERROR_EOL);
+            /* Call recipe and expect non-zero return code */
+            cpl_test( recipe_exec(plugin) );
+            /* Expect also the CPL error code to be preserved */
+            cpl_test_error( CPL_ERROR_EOL );
+
+            cpl_msg_info(cpl_func,"Checking handling of empty frameset - "
+                         "may produce warning(s)/error(s):");
+            /* Call recipe and expect non-zero return code */
+            cpl_test( recipe_exec(plugin) );
+            error = cpl_error_get_code();
+            /* Expect also the CPL error code to be set */
+            cpl_test_error( error );
+            cpl_test( error );
+
+            cpl_msg_info(cpl_func,"Checking handling of dummy frameset - "
+                         "may produce warning(s)/error(s):");
+            do {
+                cpl_frame * f = cpl_frame_new();
+                error = cpl_frame_set_filename(f, "/dev/null");
+                cpl_test_eq_error(error, CPL_ERROR_NONE);
+                error = cpl_frame_set_tag(f, "RECIPE_DUMMY_TAG");
+                cpl_test_eq_error(error, CPL_ERROR_NONE);
+                error = cpl_frameset_insert(recipe->frames, f);
+                cpl_test_eq_error(error, CPL_ERROR_NONE);
+
+                /* Call recipe and expect non-zero return code */
+                cpl_test( recipe_exec(plugin) );
+                error = cpl_error_get_code();
+                /* Expect also the CPL error code to be set */
+                cpl_test_error( error );
+                cpl_test( error );
+
+                error = cpl_frameset_erase_frame(recipe->frames, f);
+                cpl_test_eq_error(error, CPL_ERROR_NONE);
+
+            } while (0);
+
+#ifdef IRPLIB_TEST_RANDOM_SOF
+            recipe_sof_test_devfile(plugin, DEV_RANDOM, nstr, astr);
+#endif
+
+            recipe_sof_test_devfile(plugin, "/dev/null", nstr, astr);
+
+            recipe_sof_test_devfile(plugin, ".", nstr, astr);
+
+            recipe_sof_test_image_empty(plugin, nstr, astr);
+
+            recipe_sof_test_local(plugin);
+
+            cpl_msg_set_level(msg_level);
+
+        }
+
+        cpl_frameset_delete(recipe->frames);
+
+        error = recipe_deinit(plugin);
+        cpl_test_eq_error(error, CPL_ERROR_NONE);
+    }
+
+    if (stream != stdout) fclose(stream);
+
+    return 0;
+}
+
+/**@}*/
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Set unset parameters to default value or via the env
+  @param    self    The parameter list
+  @return   void
+  @note This is a modification of params_parse_config_postprocess() from esorex
+
+  The function initializes the provided parameter list by setting the current
+  parameter values to the default parameter values.
+ */
+/*----------------------------------------------------------------------------*/
+static void recipe_parameterlist_set(cpl_parameterlist * self)
+{
+
+    cpl_parameter * p = cpl_parameterlist_get_first(self);
+
+    for (; p != NULL; p = cpl_parameterlist_get_next(self)) {
+
+        const char * envvar;
+        const char * svalue;
+
+        /* FIXME: Needed ? */
+        if (cpl_parameter_get_default_flag(p)) continue;
+
+        cpl_msg_debug(cpl_func, __FILE__ " line %u: OK", __LINE__);
+
+        envvar = cpl_parameter_get_alias(p, CPL_PARAMETER_MODE_ENV);
+        svalue = envvar ? getenv(envvar) : NULL;
+
+        switch (cpl_parameter_get_type(p)) {
+        case CPL_TYPE_BOOL: {
+            const int value
+                = svalue ? atoi(svalue) : cpl_parameter_get_default_bool(p);
+            cpl_parameter_set_bool(p, value);
+            break;
+        }
+        case CPL_TYPE_INT: {
+            const int value
+                = svalue ? atoi(svalue) : cpl_parameter_get_default_int(p);
+            cpl_parameter_set_int(p, value);
+            break;
+        }
+        case CPL_TYPE_DOUBLE: {
+            const double value
+                = svalue ? atof(svalue) : cpl_parameter_get_default_double(p);
+            cpl_parameter_set_double(p, value);
+            break;
+        }
+        case CPL_TYPE_STRING:
+            {
+                const char * s_default = cpl_parameter_get_default_string(p);
+                /* Replace NULL with "" */
+                const char * value
+                    = svalue ? svalue : (s_default ? s_default : "");
+                cpl_parameter_set_string(p, value);
+                break;
+            }
+
+        default:
+            assert( 0 ); /* It is a testing error to reach this point */
+        }
+    }
+}
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Invoke the recipe with the supplied TAGS using the supplied file
+  @param    plugin   The plugin
+  @param    filename The filename to use
+  @param    nstr   The number of strings
+  @param    astr   The array of tags
+  @return   void
+
+ */
+/*----------------------------------------------------------------------------*/
+static void recipe_sof_test_devfile(cpl_plugin * plugin, const char * filename,
+                                    size_t nstr, const char *astr[])
+{
+    cpl_recipe * recipe  = (cpl_recipe*)plugin;
+    int       (*recipe_exec) (cpl_plugin *);
+    cpl_frameset * copy;
+    cpl_error_code error;
+    size_t i;
+
+
+    if (nstr < 1) return;
+    if (filename == NULL) return;
+
+    cpl_msg_info(cpl_func, "Testing recipe with %u %s as input ",
+                 (unsigned)nstr, filename);
+
+    for (i = 0; i < nstr; i++) {
+        cpl_frame * f = cpl_frame_new();
+
+        error = cpl_frame_set_filename(f, filename);
+        cpl_test_eq_error(error, CPL_ERROR_NONE);
+
+        error = cpl_frame_set_tag(f, astr[i]);
+        cpl_test_eq_error(error, CPL_ERROR_NONE);
+
+        error = cpl_frameset_insert(recipe->frames, f);
+        cpl_test_eq_error(error, CPL_ERROR_NONE);
+    }
+
+    copy = cpl_frameset_duplicate(recipe->frames);
+
+    recipe_exec = cpl_plugin_get_exec(plugin);
+    cpl_test( recipe_exec != NULL);
+
+    if (recipe_exec != NULL) {
+
+        /* Call recipe and expect non-zero return code */
+        cpl_test( recipe_exec(plugin) );
+        error = cpl_error_get_code();
+        /* Expect also the CPL error code to be set */
+        cpl_test_error( error );
+        cpl_test( error );
+
+        recipe_frameset_test_frameset_diff(recipe->frames, copy);
+
+        recipe_frameset_empty(recipe->frames);
+    }
+
+    cpl_frameset_delete(copy);
+
+    return;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Invoke the recipe with the supplied TAGS using empty images
+  @param    plugin The plugin
+  @return   void
+
+ */
+/*----------------------------------------------------------------------------*/
+static void recipe_sof_test_image_empty(cpl_plugin * plugin, size_t nstr,
+                                        const char *astr[])
+{
+    cpl_recipe * recipe  = (cpl_recipe*)plugin;
+    int       (*recipe_exec) (cpl_plugin *);
+    cpl_frameset * copy;
+    cpl_error_code error;
+    size_t i;
+    cpl_frame * frame;
+    cpl_image * iempty;
+    int retstat;
+
+
+    if (nstr < 1) return;
+
+    cpl_msg_info(cpl_func, "Testing recipe with %u empty images as input ",
+                 (unsigned)nstr);
+
+    iempty = cpl_image_new(13, 17, CPL_TYPE_FLOAT);
+    cpl_test_nonnull(iempty);
+
+    for (i = 0; i < nstr; i++) {
+        cpl_frame * f = cpl_frame_new();
+        char * rawname = cpl_sprintf("raw%05u.fits", (unsigned)(i+1));
+
+        error = cpl_image_save(iempty, rawname,CPL_BPP_IEEE_FLOAT, NULL,
+                               CPL_IO_DEFAULT);
+        cpl_test_eq_error(error, CPL_ERROR_NONE);
+
+        error = cpl_frame_set_filename(f, rawname);
+        cpl_test_eq_error(error, CPL_ERROR_NONE);
+
+        error = cpl_frame_set_tag(f, astr[i]);
+        cpl_test_eq_error(error, CPL_ERROR_NONE);
+
+        error = cpl_frameset_insert(recipe->frames, f);
+        cpl_test_eq_error(error, CPL_ERROR_NONE);
+
+        cpl_free(rawname);
+    }
+    cpl_image_delete(iempty);
+
+    copy = cpl_frameset_duplicate(recipe->frames);
+
+    recipe_exec = cpl_plugin_get_exec(plugin);
+    cpl_test(recipe_exec != NULL);
+
+    if (recipe_exec != NULL) {
+
+        /* Call recipe and expect consistency between return code and
+           CPL error */
+
+        retstat = recipe_exec(plugin);
+        error = cpl_error_get_code();
+        /* Expect also the CPL error code to be set */
+        if (error == 0) {
+            cpl_test_zero(retstat);
+        } else {
+            cpl_test(retstat);
+        }
+        cpl_test_error( error );
+
+        recipe_frameset_test_frameset_diff(recipe->frames, copy);
+
+        for (frame = cpl_frameset_get_first(recipe->frames); frame != NULL;
+             frame = cpl_frameset_get_next(recipe->frames))
+            {
+                cpl_test_zero( remove(cpl_frame_get_filename(frame)) );
+            }
+
+        recipe_frameset_empty(recipe->frames);
+    }
+
+    cpl_frameset_delete(copy);
+
+    return;
+}
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief  Check if the the env-variable has an SOF from the plugin
+  @param  plugin   The plugin
+  @param  envname  The environment variable with the directory to load from
+  @return True iff there is an SOF in the directory of the env
+
+ */
+/*----------------------------------------------------------------------------*/
+cpl_boolean irplib_plugin_has_sof_from_env(const cpl_plugin * plugin,
+                                           const char * envname)
+{
+    const char      * recipename = cpl_plugin_get_name(plugin);
+    const char      * sof_path   = envname ? getenv(envname) : NULL;
+    cpl_frameset    * frames;
+    char            * sof_name;
+    const cpl_frame * ffirst;
+
+    cpl_ensure(plugin  != NULL, CPL_ERROR_NULL_INPUT, CPL_FALSE);
+    cpl_ensure(envname != NULL, CPL_ERROR_NULL_INPUT, CPL_FALSE);
+    cpl_ensure(recipename != NULL, CPL_ERROR_DATA_NOT_FOUND, CPL_FALSE);
+    cpl_ensure(!cpl_error_get_code(), cpl_error_get_code(), CPL_FALSE);
+
+    if (sof_path == NULL) return CPL_FALSE;
+
+    sof_name = cpl_sprintf("%s/%s.sof", sof_path, recipename);
+
+    frames = cpl_frameset_new();
+    recipe_frameset_load(frames, sof_name);
+
+    ffirst = cpl_frameset_get_first_const(frames);
+
+    cpl_free(sof_name);
+    cpl_frameset_delete(frames);
+
+    cpl_ensure(!cpl_error_get_code(), cpl_error_get_code(), CPL_FALSE);
+
+    return ffirst ? CPL_TRUE : CPL_FALSE;
+
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Use getenv() to look for SOFs
+  @param    plugin The plugin
+  @return   void
+
+ */
+/*----------------------------------------------------------------------------*/
+static void recipe_sof_test_from_env(cpl_plugin * plugin)
+{
+    cpl_recipe * recipe  = (cpl_recipe*)plugin;
+    const char * recipename = cpl_plugin_get_name(plugin);
+    const char * var_name = "RECIPE_SOF_PATH";
+    const char * sof_path = getenv(var_name);
+    cpl_error_code error;
+
+    char * sof_name;
+
+    if (sof_path == NULL) {
+        cpl_msg_warning(cpl_func, "Environment variable %s is unset: "
+                        "No SOFs to check", var_name);
+        return;
+    }
+
+    cpl_msg_debug(cpl_func, "Checking for SOFs in %s", sof_path);
+
+    cpl_test_nonnull( recipename );
+    if (recipename == NULL) return;
+
+    sof_name = cpl_sprintf("%s/%s.sof", sof_path, recipename);
+
+    cpl_msg_debug(cpl_func, "Checking for SOF %s", sof_name);
+    
+    recipe_frameset_load(recipe->frames, sof_name);
+
+    if (!cpl_frameset_is_empty(recipe->frames)) {
+
+        int          (*recipe_exec  ) (cpl_plugin *);
+        cpl_frameset * copy = cpl_frameset_duplicate(recipe->frames);
+
+        recipe_exec   = cpl_plugin_get_exec(plugin);
+        cpl_test(recipe_exec != NULL);
+
+        if (recipe_exec != NULL) {
+            cpl_msg_info(cpl_func,"Checking handling of SOF: %s", sof_name);
+
+            /* Call recipe and expect zero return code */
+            cpl_test_zero( recipe_exec(plugin) );
+            /* Expect also the CPL error code to be clear */
+            cpl_test_error(CPL_ERROR_NONE);
+
+            error = cpl_dfs_update_product_header(recipe->frames);
+            cpl_test_eq_error(error, CPL_ERROR_NONE);
+
+            recipe_frameset_test_frameset_diff(recipe->frames, copy);
+
+            recipe_frameset_empty(recipe->frames);
+        }
+
+        cpl_frameset_delete(copy);
+
+    }
+
+    cpl_free(sof_name);
+
+    return;
+}
+
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Look for SOF an SOF in ./<recipename>.sof
+  @param    plugin The plugin
+  @return   void
+
+ */
+/*----------------------------------------------------------------------------*/
+static void recipe_sof_test_local(cpl_plugin * plugin)
+{
+    cpl_recipe * recipe  = (cpl_recipe*)plugin;
+    const char * recipename = cpl_plugin_get_name(plugin);
+    cpl_error_code error;
+    char * sof_name = cpl_sprintf("%s.sof", recipename);
+
+    cpl_msg_debug(cpl_func, "Checking for SOF %s", sof_name);
+    
+    recipe_frameset_load(recipe->frames, sof_name);
+
+    if (!cpl_frameset_is_empty(recipe->frames)) {
+
+        int          (*recipe_exec  ) (cpl_plugin *);
+        cpl_frameset * copy = cpl_frameset_duplicate(recipe->frames);
+
+        recipe_exec   = cpl_plugin_get_exec(plugin);
+        cpl_test(recipe_exec != NULL);
+
+        if (recipe_exec != NULL) {
+
+            cpl_msg_info(cpl_func,"Checking handling of SOF: %s", sof_name);
+
+            /* Call recipe and expect zero return code */
+            cpl_test_zero( recipe_exec(plugin) );
+            /* Expect also the CPL error code to be clear */
+            cpl_test_error(CPL_ERROR_NONE);
+
+            error = cpl_dfs_update_product_header(recipe->frames);
+            cpl_test_eq_error( error, CPL_ERROR_NONE );
+
+            recipe_frameset_test_frameset_diff(recipe->frames, copy);
+
+            recipe_frameset_empty(recipe->frames);
+        }
+
+        cpl_frameset_delete(copy);
+    }
+
+    cpl_free(sof_name);
+
+    return;
+}
+
+
+
+
+/**********************************************************************/
+/**  
+ * @brief
+ *   Create a new frame set from a @em set @em of @em frames file.
+ * 
+ * @param set   Frame set to be updated with the contents of @em name.
+ * @param name  Input file path.
+ * 
+ * @return Pointer to the newly created frame set if @em set was @c NULL,
+ *   or the updated set @em set. In case an error occurred the return value
+ *   is @c NULL.
+ *
+ * @note This is a simplification of er_frameset_load() from esorex
+ */   
+/**********************************************************************/
+
+static void recipe_frameset_load(cpl_frameset * set, const char *name)
+{
+
+    FILE *fp;
+    char line[LINE_LEN_MAX];
+    char path[LINE_LEN_MAX], group[LINE_LEN_MAX], tag[LINE_LEN_MAX];
+    int line_number;
+
+    assert( set != NULL );
+    assert( name != NULL );
+
+    fp = fopen(name, "r");
+    if (fp == NULL) {
+        cpl_msg_debug(cpl_func, "Unable to open SOF file '%s'", name);
+        return;
+    }
+
+    /* Loop over all the lines in the set-of-frames file */
+    for (line_number = 0; fgets(line, LINE_LEN_MAX - 1, fp); line_number++) {
+
+        cpl_frame_group grp;
+        cpl_frame * frame;
+        int n;
+
+        if (line[0] == '#') continue;
+
+        n = sscanf(line, "%s %s %s", path, tag, group);
+
+        if (n < 1) {
+            cpl_msg_warning(cpl_func, "Spurious line no. %d in %s: %s",
+                            line_number, name, line);
+            break;
+        }
+
+        /* Allocate a new frame */
+        frame = cpl_frame_new();
+
+        /* Set the filename component of the frame */
+        cpl_frame_set_filename(frame, path);
+
+        /* Set the tag component of the frame (or set a default) */
+        cpl_frame_set_tag(frame, n == 1 ? "" : tag);
+
+        cpl_frameset_insert(set, frame);
+
+        /* Set the group component of the frame (or set a default) */
+        if (n < 3) continue;
+
+        if (!strcmp(group, CPL_FRAME_GROUP_RAW_ID))
+            grp = CPL_FRAME_GROUP_RAW;
+        else if (!strcmp(group, CPL_FRAME_GROUP_CALIB_ID))
+            grp = CPL_FRAME_GROUP_CALIB;
+        else if (!strcmp(group, CPL_FRAME_GROUP_PRODUCT_ID))
+            grp = CPL_FRAME_GROUP_PRODUCT;
+        else
+            grp = CPL_FRAME_GROUP_NONE;
+
+        cpl_frame_set_group(frame, grp);
+    }
+
+    fclose(fp);
+
+    return;
+
+}
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Retrieve a parameter from a plugin parameterlist
+  @param    self      The parameterlist to get from
+  @param    instrume  The recipe name, e.g. PACKAGE from config.h
+  @param    recipe    The recipe name, e.g. "rrrecipe"
+  @param    parameter The parameter name, e.g. "stropt"
+  @return   The parameter, or NULL on error
+
+ */
+/*----------------------------------------------------------------------------*/
+static
+const cpl_parameter * irplib_parameterlist_get(const cpl_parameterlist * self,
+                                               const char * instrume,
+                                               const char * recipe,
+                                               const char * parameter)
+{
+
+    char                * paramname;
+    const cpl_parameter * par;
+
+
+    cpl_ensure(instrume  != NULL, CPL_ERROR_NULL_INPUT, NULL);
+    cpl_ensure(recipe    != NULL, CPL_ERROR_NULL_INPUT, NULL);
+    cpl_ensure(parameter != NULL, CPL_ERROR_NULL_INPUT, NULL);
+
+    paramname = cpl_sprintf("%s.%s.%s", instrume, recipe, parameter);
+
+    par = cpl_parameterlist_find_const(self, paramname);
+
+    if (par == NULL) (void)cpl_error_set_message(cpl_func,
+                                                 cpl_error_get_code()
+                                                 ? cpl_error_get_code()
+                                                 : CPL_ERROR_DATA_NOT_FOUND,
+                                                 "%s", paramname);
+
+    cpl_free(paramname);
+    
+    return par;
+
+}
+
+
+/*----------------------------------------------------------------------------*/
+/**
+ * @brief
+ *   Remove all frames from a frameset
+ *
+ * @param self  A frameset.
+ *
+ * @return Nothing.
+ *
+ * @note FIXME: Move to CPL
+ *
+ * @error
+ *   <table class="ec" align="center">
+ *     <tr>
+ *       <td class="ecl">CPL_ERROR_NULL_INPUT</td>
+ *       <td class="ecr">
+ *         The parameter <i>self</i> is a <tt>NULL</tt> pointer.
+ *       </td>
+ *     </tr>
+ *   </table>
+ * @enderror
+ *
+ * The function removes all frames from @em self. Each frame
+ * is properly deallocated. After calling this function @em self is
+ * empty.
+*/
+/*----------------------------------------------------------------------------*/
+static void recipe_frameset_empty(cpl_frameset * self)
+{
+    cpl_frame * f;
+
+    if (self == NULL) {
+        cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT);
+        return;
+    }
+
+    for (f = cpl_frameset_get_first(self); f != NULL;
+         f = cpl_frameset_get_first(self))
+        {
+            cpl_frameset_erase_frame(self, f);
+        }
+}
+
+
+/*----------------------------------------------------------------------------*/
+/**
+ * @brief
+ *   Test a frame for product conformance
+ * @param self  A frame.
+ * @return Nothing.
+ * @note FIXME: Move to CPL test module
+ *
+ * @error
+ *   <table class="ec" align="center">
+ *     <tr>
+ *       <td class="ecl">CPL_ERROR_NULL_INPUT</td>
+ *       <td class="ecr">
+ *         The parameter <i>self</i> is a <tt>NULL</tt> pointer.
+ *       </td>
+ *     </tr>
+ *   </table>
+ * @enderror
+ *
+*/
+/*----------------------------------------------------------------------------*/
+static void recipe_frameset_test_frame(const cpl_frame * self)
+{
+
+    cpl_msg_info(cpl_func, "Validating new frame: %s",
+                 cpl_frame_get_filename(self));
+
+    cpl_test_nonnull(self);
+
+    /* Frame must be tagged */
+    cpl_test_nonnull(cpl_frame_get_tag(self));
+
+    /* New frames must be products */
+    cpl_test_eq(cpl_frame_get_group(self), CPL_FRAME_GROUP_PRODUCT);
+
+    if (cpl_frame_get_type(self) != CPL_FRAME_TYPE_PAF) {
+        /* All but PAF (?) must be FITS */
+        cpl_test_fits(cpl_frame_get_filename(self));
+    } else {
+        /* Frame must at least have a filename */
+        cpl_test_nonnull(cpl_frame_get_filename(self));
+    }
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+ * @brief
+ *   Test the new frames for product conformance
+ * @param self  The frameset in which to test
+ * @param other The reference frameset (with recipe input frames)
+ * @return Nothing.
+ * @note FIXME: Move to CPL test module ?
+ *
+ * @error
+ *   <table class="ec" align="center">
+ *     <tr>
+ *       <td class="ecl">CPL_ERROR_NULL_INPUT</td>
+ *       <td class="ecr">
+ *         The parameter <i>self</i> is a <tt>NULL</tt> pointer.
+ *       </td>
+ *     </tr>
+ *   </table>
+ * @enderror
+ *
+*/
+/*----------------------------------------------------------------------------*/
+static void recipe_frameset_test_frameset_diff(const cpl_frameset * self,
+                                               const cpl_frameset * other)
+{
+
+    const cpl_frame * frame = cpl_frameset_get_first_const(other);
+
+    /* First verify that filenames in other are non-NULL */
+    for (;frame != NULL; frame = cpl_frameset_get_next_const(other)) {
+        const char * file = cpl_frame_get_filename(frame);
+
+        if (file == NULL) {
+            cpl_test_nonnull(cpl_frame_get_filename(frame));
+            break;
+        }
+    }
+    if (frame != NULL) return;
+
+    frame = cpl_frameset_get_first_const(self);
+
+    for (;frame != NULL; frame = cpl_frameset_get_next_const(self)) {
+        const cpl_frame * cmp  = cpl_frameset_get_first_const(other);
+        const char * file = cpl_frame_get_filename(frame);
+
+        if (file == NULL) {
+            cpl_test_nonnull(cpl_frame_get_filename(frame));
+            continue;
+        }
+
+        for (;cmp != NULL; cmp = cpl_frameset_get_next_const(other)) {
+            const char * cfile = cpl_frame_get_filename(cmp);
+
+            if (!strcmp(file, cfile)) break;
+
+        }
+        if (cmp == NULL) {
+            /* frame is new */
+
+            cpl_test_eq(cpl_frame_get_group(frame), CPL_FRAME_GROUP_PRODUCT);
+            recipe_frameset_test_frame(frame);
+        }
+    }
+}
diff --git a/irplib/irplib_plugin.h b/irplib/irplib_plugin.h
new file mode 100644
index 0000000..434d905
--- /dev/null
+++ b/irplib/irplib_plugin.h
@@ -0,0 +1,93 @@
+/* $Id: irplib_plugin.h,v 1.23 2012/01/11 08:03:37 llundin Exp $
+ *
+ * This file is part of the irplib package 
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: llundin $
+ * $Date: 2012/01/11 08:03:37 $
+ * $Revision: 1.23 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifndef IRPLIB_PLUGIN_H
+#define IRPLIB_PLUGIN_H
+
+/*-----------------------------------------------------------------------------
+                                   Includes
+ -----------------------------------------------------------------------------*/
+
+#include <irplib_utils.h>  /* irplib_reset() */
+
+#include <cpl.h>
+
+/*-----------------------------------------------------------------------------
+                                   Define
+ -----------------------------------------------------------------------------*/
+
+/* Needed (by uves) to concatenate two macro arguments */
+#define IRPLIB_CONCAT(a,b) a ## _ ## b
+#define IRPLIB_CONCAT2X(a,b) IRPLIB_CONCAT(a,b)
+
+/*-----------------------------------------------------------------------------
+                                   Function prototypes
+ -----------------------------------------------------------------------------*/
+
+int irplib_plugin_test(cpl_pluginlist *, size_t, const char *[]);
+
+cpl_error_code irplib_parameterlist_set_string(cpl_parameterlist *,
+                                               const char *, const char *,
+                                               const char *, const char *, 
+                                               const char *, const char *,
+                                               const char *);
+
+cpl_error_code irplib_parameterlist_set_bool(cpl_parameterlist *,
+                                             const char *, const char *,
+                                             const char *, cpl_boolean,
+                                             const char *, const char *,
+                                             const char *);
+
+cpl_error_code irplib_parameterlist_set_int(cpl_parameterlist *,
+                                            const char *, const char *,
+                                            const char *, int,
+                                            const char *, const char *,
+                                            const char *);
+
+cpl_error_code irplib_parameterlist_set_double(cpl_parameterlist *,
+                                               const char *, const char *,
+                                               const char *, double, 
+                                               const char *, const char *,
+                                               const char *);
+
+const char * irplib_parameterlist_get_string(const cpl_parameterlist *,
+                                             const char *, const char *,
+                                             const char *);
+
+cpl_boolean irplib_parameterlist_get_bool(const cpl_parameterlist *,
+                                          const char *, const char *,
+                                          const char *);
+
+int irplib_parameterlist_get_int(const cpl_parameterlist *,
+                                 const char *, const char *,
+                                 const char *);
+
+double irplib_parameterlist_get_double(const cpl_parameterlist *,
+                                       const char *, const char *,
+                                       const char *);
+
+#endif
diff --git a/irplib/irplib_polynomial.c b/irplib/irplib_polynomial.c
new file mode 100644
index 0000000..ecd0abf
--- /dev/null
+++ b/irplib/irplib_polynomial.c
@@ -0,0 +1,1486 @@
+/* $Id: irplib_polynomial.c,v 1.34 2012/02/03 14:54:06 llundin Exp $
+ *
+ * This file is part of the ESO Common Pipeline Library
+ * Copyright (C) 2001-2004 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: llundin $
+ * $Date: 2012/02/03 14:54:06 $
+ * $Revision: 1.34 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+/*-----------------------------------------------------------------------------
+                                   Includes
+ -----------------------------------------------------------------------------*/
+
+#include "irplib_polynomial.h"
+#include <assert.h>
+#include <math.h>
+/* DBL_MAX: */
+#include <float.h>
+
+/*----------------------------------------------------------------------------*/
+/**
+ * @defgroup irplib_polynomial 1D-Polynomial roots 
+ *
+ *
+ */
+/*----------------------------------------------------------------------------*/
+/**@{*/
+
+/*-----------------------------------------------------------------------------
+                                   Macro definitions
+ -----------------------------------------------------------------------------*/
+
+#define IRPLIB_SWAP(a,b) { const double t=(a);(a)=(b);(b)=t; }
+
+#if 0
+#define irplib_trace() cpl_msg_info(cpl_func, "%d: Trace", __LINE__)
+#else
+#define irplib_trace() /* Trace */
+#endif
+
+/*-----------------------------------------------------------------------------
+                                   Static functions
+ -----------------------------------------------------------------------------*/
+
+static double irplib_polynomial_eval_2_max(double, double, double, cpl_boolean,
+                                           double, double);
+
+static double irplib_polynomial_eval_3_max(double, double, double, double,
+                                           cpl_boolean, double, double, double);
+
+
+static cpl_boolean irplib_polynomial_solve_1d_2(double, double, double,
+                                                double *, double *);
+static cpl_boolean irplib_polynomial_solve_1d_3(double, double, double, double,
+                                                double *, double *, double *,
+                                                cpl_boolean *,
+                                                cpl_boolean *);
+
+static void irplib_polynomial_solve_1d_31(double, double, double *, double *,
+                                          double *, cpl_boolean *);
+
+static void irplib_polynomial_solve_1d_32(double, double, double, double *,
+                                          double *, double *, cpl_boolean *);
+
+static void irplib_polynomial_solve_1d_3r(double, double, double, double,
+                                          double *, double *, double *);
+
+static void irplib_polynomial_solve_1d_3c(double, double, double,
+                                          double, double, double,
+                                          double *, double *, double *,
+                                          cpl_boolean *, cpl_boolean *);
+
+static cpl_error_code irplib_polynomial_solve_1d_4(double, double, double,
+                                                   double, double, cpl_size *,
+                                                   double *, double *,
+                                                   double *, double *);
+
+static cpl_error_code irplib_polynomial_solve_1d_nonzero(cpl_polynomial *,
+                                                         cpl_vector *,
+                                                         cpl_size *);
+
+static cpl_error_code irplib_polynomial_divide_1d_root(cpl_polynomial *, double,
+                                                       double *);
+
+#ifdef IPRLIB_POLYNOMIAL_USE_MONOMIAL_ROOT
+static double irplib_polynomial_depress_1d(cpl_polynomial *);
+#endif
+
+/*-----------------------------------------------------------------------------
+                              Function codes
+ -----------------------------------------------------------------------------*/
+
+#if defined CPL_VERSION_CODE && CPL_VERSION_CODE > CPL_VERSION(5, 92, 0)
+#else
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Add two polynomials of the same dimension
+  @param    self      The polynomial to hold the result
+  @param    first     The 1st polynomial to add
+  @param    second    The 2nd polynomial to add
+  @return   CPL_ERROR_NONE or the relevant CPL error code
+  @note self may be passed also as first and/or second
+
+  Possible CPL error code set in this function:
+  - CPL_ERROR_NULL_INPUT if an input pointer is NULL
+  - CPL_ERROR_INCOMPATIBLE_INPUT if the polynomials do not have identical
+    dimensions
+  - CPL_ERROR_UNSUPPORTED_MODE if the dimension is not 1 (FIXME)
+ */
+/*----------------------------------------------------------------------------*/
+cpl_error_code irplib_polynomial_add(cpl_polynomial * self,
+                                     const cpl_polynomial * first,
+                                     const cpl_polynomial * second)
+{
+    cpl_size       degree0 = cpl_polynomial_get_degree(self);
+    const cpl_size degree1 = cpl_polynomial_get_degree(first);
+    const cpl_size degree2 = cpl_polynomial_get_degree(second);
+    const cpl_size maxdeg  = degree1 > degree2 ? degree1 : degree2;
+
+
+    cpl_ensure_code(self   != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(first  != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(second != NULL, CPL_ERROR_NULL_INPUT);
+
+    cpl_ensure_code(cpl_polynomial_get_dimension(self) ==
+                    cpl_polynomial_get_dimension(first),
+                    CPL_ERROR_INCOMPATIBLE_INPUT);
+    cpl_ensure_code(cpl_polynomial_get_dimension(self) ==
+                    cpl_polynomial_get_dimension(second),
+                    CPL_ERROR_INCOMPATIBLE_INPUT);
+
+    /* FIXME: */
+    cpl_ensure_code(cpl_polynomial_get_dimension(self) == 1,
+                    CPL_ERROR_UNSUPPORTED_MODE);
+
+    if (degree0 < maxdeg) {
+        degree0 = maxdeg;
+    } else {
+        /* Reset coefficients in self as needed */
+        for (; degree0 > maxdeg; degree0--) {
+            cpl_polynomial_set_coeff(self, &degree0, 0.0);
+        }
+    }
+
+    /* assert( degree0 == maxdeg ); */
+
+    for (; degree0 >= 0; degree0--) {
+        const double val1 = cpl_polynomial_get_coeff(first, &degree0);
+        const double val2 = cpl_polynomial_get_coeff(second, &degree0);
+        cpl_polynomial_set_coeff(self, &degree0, val1 + val2);
+    }
+
+    return CPL_ERROR_NONE;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Subtract two polynomials of the same dimension
+  @param    self      The polynomial to hold the result
+  @param    first     The polynomial to subtract from
+  @param    second    The polynomial to subtract
+  @return   CPL_ERROR_NONE or the relevant CPL error code
+  @note self may be passed also as first and/or second
+
+  Possible CPL error code set in this function:
+  - CPL_ERROR_NULL_INPUT if an input pointer is NULL
+  - CPL_ERROR_INCOMPATIBLE_INPUT if the polynomials do not have identical
+    dimensions
+  - CPL_ERROR_UNSUPPORTED_MODE if the dimension is not 1 (FIXME)
+ */
+/*----------------------------------------------------------------------------*/
+cpl_error_code irplib_polynomial_subtract(cpl_polynomial * self,
+                                          const cpl_polynomial * first,
+                                          const cpl_polynomial * second)
+{
+    cpl_size       degree0 = cpl_polynomial_get_degree(self);
+    const cpl_size degree1 = cpl_polynomial_get_degree(first);
+    const cpl_size degree2 = cpl_polynomial_get_degree(second);
+    const cpl_size maxdeg  = degree1 > degree2 ? degree1 : degree2;
+
+
+    cpl_ensure_code(self   != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(first  != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(second != NULL, CPL_ERROR_NULL_INPUT);
+
+    cpl_ensure_code(cpl_polynomial_get_dimension(self) ==
+                    cpl_polynomial_get_dimension(first),
+                    CPL_ERROR_INCOMPATIBLE_INPUT);
+    cpl_ensure_code(cpl_polynomial_get_dimension(self) ==
+                    cpl_polynomial_get_dimension(second),
+                    CPL_ERROR_INCOMPATIBLE_INPUT);
+
+    /* FIXME: */
+    cpl_ensure_code(cpl_polynomial_get_dimension(self) == 1,
+                    CPL_ERROR_UNSUPPORTED_MODE);
+
+    if (degree0 < maxdeg) {
+        degree0 = maxdeg;
+    } else {
+        /* Reset coefficients in self as needed */
+        for (; degree0 > maxdeg; degree0--) {
+            cpl_polynomial_set_coeff(self, &degree0, 0.0);
+        }
+    }
+
+    /* assert( degree0 == maxdeg ); */
+
+    for (; degree0 >= 0; degree0--) {
+        const double val1 = cpl_polynomial_get_coeff(first, &degree0);
+        const double val2 = cpl_polynomial_get_coeff(second, &degree0);
+        cpl_polynomial_set_coeff(self, &degree0, val1 - val2);
+    }
+
+    return CPL_ERROR_NONE;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Multiply a polynomial with a scalar
+  @param    self      The polynomial to hold the result
+  @param    other     The polynomial to scale, may equal self
+  @param    factor    The factor to multiply with
+  @return   CPL_ERROR_NONE or the relevant CPL error code
+
+  Possible CPL error code set in this function:
+  - CPL_ERROR_NULL_INPUT if an input pointer is NULL
+  - CPL_ERROR_UNSUPPORTED_MODE if the dimension is not 1 (FIXME)
+ */
+/*----------------------------------------------------------------------------*/
+cpl_error_code irplib_polynomial_multiply_scalar(cpl_polynomial * self,
+                                                 const cpl_polynomial * other,
+                                                 double factor)
+{
+
+    const cpl_size maxdeg  = cpl_polynomial_get_degree(other);
+    const cpl_size zerodeg = cpl_polynomial_get_degree(self);
+    cpl_size       degree;
+
+    cpl_ensure_code(self  != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(other != NULL, CPL_ERROR_NULL_INPUT);
+
+    cpl_ensure_code(cpl_polynomial_get_dimension(self) == 1,
+                    CPL_ERROR_UNSUPPORTED_MODE);
+    cpl_ensure_code(cpl_polynomial_get_dimension(other) == 1,
+                    CPL_ERROR_UNSUPPORTED_MODE);
+
+    for (degree = 0; degree <= maxdeg; degree++) {
+        const double val = factor * cpl_polynomial_get_coeff(other, &degree);
+        cpl_polynomial_set_coeff(self, &degree, val);
+    }
+
+    /* Reset coefficients in self as needed */
+    for (; degree <= zerodeg; degree++) {
+        cpl_polynomial_set_coeff(self, &zerodeg, 0.0);
+    }
+
+    return CPL_ERROR_NONE;
+}
+#endif
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Compute all n roots of p(x) = 0, where p(x) is of degree n, n > 0.
+  @param    self  The 1D-polynomial
+  @param    roots A pre-allocated vector of length n to hold the roots
+  @param    preal The number of real roots found, or undefined on error
+  @return   CPL_ERROR_NONE or the relevant CPL error code
+
+  The *preal real roots are stored first in ascending order, then follows for
+  each pair of complex conjugate roots, the real and imaginary parts of the
+  root in the positive imaginary half-plane, for example for a 3rd degree
+  polynomial with 1 real root, the roots are represented as:
+  x0 = v0
+  x1 = v1 + i v2
+  x2 = v1 - i v2,
+  where v0, v1, v2 are the elements of the roots vector.
+
+  Possible CPL error code set in this function:
+  - CPL_ERROR_NULL_INPUT if an input pointer is NULL
+  - CPL_ERROR_INVALID_TYPE if the polynomial has the wrong dimension
+  - CPL_ERROR_DATA_NOT_FOUND if the polynomial does not have a degree of at
+                             least 1.
+  - CPL_ERROR_INCOMPATIBLE_INPUT if the roots vector does not have length n
+  - CPL_ERROR_DIVISION_BY_ZERO if a division by zero occurs (n > 4)
+  - CPL_ERROR_CONTINUE if the algorithm does not converge (n > 4)
+ */
+/*----------------------------------------------------------------------------*/
+cpl_error_code irplib_polynomial_solve_1d_all(const cpl_polynomial * self,
+                                              cpl_vector * roots,
+                                              cpl_size * preal)
+{
+
+    cpl_error_code error = CPL_ERROR_NONE;
+    cpl_polynomial * p;
+
+    cpl_ensure_code(self  != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(roots != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(preal != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(cpl_polynomial_get_dimension(self) == 1,
+                    CPL_ERROR_INVALID_TYPE);
+    cpl_ensure_code(cpl_polynomial_get_degree(self) > 0,
+                    CPL_ERROR_DATA_NOT_FOUND);
+    cpl_ensure_code(cpl_polynomial_get_degree(self) ==
+                    cpl_vector_get_size(roots), CPL_ERROR_INCOMPATIBLE_INPUT);
+
+    *preal = 0;
+
+    p = cpl_polynomial_duplicate(self);
+
+    error = irplib_polynomial_solve_1d_nonzero(p, roots, preal);
+
+    cpl_polynomial_delete(p);
+
+    return error;
+
+}
+
+/**@}*/
+
+/*----------------------------------------------------------------------------*/
+/**
+  @internal
+  @brief    Compute all n roots of p(x) = 0, where p(x) is of degree n, n > 0.
+  @param    self  The 1D-polynomial
+  @param    roots A pre-allocated vector of length n to hold the roots
+  @param    preal The number of real roots found, or undefined on error
+  @return   CPL_ERROR_NONE or the relevant CPL error code
+
+  The *preal real roots are stored first in ascending order, then follows for
+  each pair of complex conjugate roots, the real and imaginary parts of the
+  root in the positive imaginary half-plane, for example for a 3rd degree
+  polynomial with 1 real root, the roots are represented as:
+  x0 = v0
+  x1 = v1 + i v2
+  x2 = v1 - i v2,
+  where v0, v1, v2 are the elements of the roots vector.
+
+  Possible CPL error code set in this function:
+  - CPL_ERROR_NULL_INPUT if an input pointer is NULL
+  - CPL_ERROR_INVALID_TYPE if the polynomial has the wrong dimension
+  - CPL_ERROR_DATA_NOT_FOUND if the polynomial has the degree 0.
+  - CPL_ERROR_INCOMPATIBLE_INPUT if the roots vector does not have length n
+  - CPL_ERROR_DIVISION_BY_ZERO if a division by zero occurs (n > 4)
+  - CPL_ERROR_CONTINUE if the algorithm does not converge (n > 4)
+*/
+/*----------------------------------------------------------------------------*/
+static cpl_error_code irplib_polynomial_solve_1d_nonzero(cpl_polynomial * self,
+                                                         cpl_vector * roots,
+                                                         cpl_size * preal)
+{
+    cpl_error_code error   = CPL_ERROR_NONE;
+    const cpl_size ncoeffs = 1 + cpl_polynomial_get_degree(self);
+
+    cpl_ensure_code(self  != NULL,  CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(roots != NULL,  CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(preal != NULL,  CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(cpl_polynomial_get_dimension(self) == 1,
+                    CPL_ERROR_INVALID_TYPE);
+    cpl_ensure_code(ncoeffs   > 1,  CPL_ERROR_DATA_NOT_FOUND);
+    cpl_ensure_code(*preal >= 0,    CPL_ERROR_ILLEGAL_INPUT);
+    cpl_ensure_code(ncoeffs + *preal == 1+cpl_vector_get_size(roots),
+                    CPL_ERROR_INCOMPATIBLE_INPUT);
+
+    switch (ncoeffs) {
+
+    case 2 : {
+        const cpl_size i1 = 1;
+        const cpl_size i0 = 0;
+        const double   p1 = cpl_polynomial_get_coeff(self, &i1);
+        const double   p0 = cpl_polynomial_get_coeff(self, &i0);
+
+        cpl_vector_set(roots, (*preal)++, -p0/p1);
+        break;
+    }
+    case 3 : {
+        const cpl_size i2 = 2;
+        const cpl_size i1 = 1;
+        const cpl_size i0 = 0;
+        const double   p2 = cpl_polynomial_get_coeff(self, &i2);
+        const double   p1 = cpl_polynomial_get_coeff(self, &i1);
+        const double   p0 = cpl_polynomial_get_coeff(self, &i0);
+        double         x1, x2;
+
+        if (irplib_polynomial_solve_1d_2(p2, p1, p0, &x1, &x2)) {
+            /* This is the complex root in the upper imaginary half-plane */
+            cpl_vector_set(roots, (*preal)  , x1);
+            cpl_vector_set(roots, (*preal)+1, x2);
+        } else {
+            cpl_vector_set(roots, (*preal)++, x1);
+            cpl_vector_set(roots, (*preal)++, x2);
+        }
+        break;
+    }
+    case 4 : {
+        const cpl_size i3 = 3;
+        const cpl_size i2 = 2;
+        const cpl_size i1 = 1;
+        const cpl_size i0 = 0;
+        const double   p3 = cpl_polynomial_get_coeff(self, &i3);
+        const double   p2 = cpl_polynomial_get_coeff(self, &i2);
+        const double   p1 = cpl_polynomial_get_coeff(self, &i1);
+        const double   p0 = cpl_polynomial_get_coeff(self, &i0);
+        double         x1, x2, x3;
+
+        if (irplib_polynomial_solve_1d_3(p3, p2, p1, p0, &x1, &x2, &x3,
+                                         NULL, NULL)) {
+            cpl_vector_set(roots, (*preal)++, x1);
+            /* This is the complex root in the upper imaginary half-plane */
+            cpl_vector_set(roots, (*preal)  , x2);
+            cpl_vector_set(roots, (*preal)+1, x3);
+        } else {
+            cpl_vector_set(roots, (*preal)++, x1);
+            cpl_vector_set(roots, (*preal)++, x2);
+            cpl_vector_set(roots, (*preal)++, x3);
+        }
+        break;
+    }
+    case 5 : {
+        const cpl_size i4 = 4;
+        const cpl_size i3 = 3;
+        const cpl_size i2 = 2;
+        const cpl_size i1 = 1;
+        const cpl_size i0 = 0;
+        const double   p4 = cpl_polynomial_get_coeff(self, &i4);
+        const double   p3 = cpl_polynomial_get_coeff(self, &i3);
+        const double   p2 = cpl_polynomial_get_coeff(self, &i2);
+        const double   p1 = cpl_polynomial_get_coeff(self, &i1);
+        const double   p0 = cpl_polynomial_get_coeff(self, &i0);
+        double         x1, x2, x3, x4;
+        cpl_size       nreal;
+
+        error = irplib_polynomial_solve_1d_4(p4, p3, p2, p1, p0, &nreal,
+                                             &x1, &x2, &x3, &x4);
+        if (!error) {
+            cpl_vector_set(roots, (*preal)  , x1);
+            cpl_vector_set(roots, (*preal)+1, x2);
+            cpl_vector_set(roots, (*preal)+2, x3);
+            cpl_vector_set(roots, (*preal)+3, x4);
+
+            *preal += nreal;
+        }
+        break;
+    }
+
+    default: {
+
+        /* Try to reduce the problem by finding a single root */
+#ifndef IPRLIB_POLYNOMIAL_USE_MONOMIAL_ROOT
+        const cpl_size    n0 = ncoeffs-1;
+        const double pn0 = cpl_polynomial_get_coeff(self, &n0);
+        const cpl_size    n1 = ncoeffs-2;
+        const double pn1 = cpl_polynomial_get_coeff(self, &n1);
+        /* First guess of root is the root average.
+           FIXME: May need refinement, e.g. via bisection */
+        const double rmean = -pn1 / (pn0 * n0);
+        double root = rmean;
+#else
+        /* Try an analytical solution to a (shifted) monomial */
+        cpl_polynomial * copy = cpl_polynomial_duplicate(self);
+        const cpl_size    i0 = 0;
+        const double rmean = irplib_polynomial_depress_1d(copy);
+        const double c0 = cpl_polynomial_get_coeff(copy, &i0);
+        double root = rmean + ((n0&1) && c0 < 0.0 ? -1.0 : 1.0)
+            * pow(fabs(c0), 1.0/n0);
+
+        cpl_polynomial_delete(copy);
+#endif
+
+        error = cpl_polynomial_solve_1d(self, root, &root, 1);
+
+        if (!error) {
+
+            cpl_vector_set(roots, (*preal)++, root);
+
+            irplib_polynomial_divide_1d_root(self, root, NULL);
+
+            error = irplib_polynomial_solve_1d_nonzero(self, roots, preal);
+
+            if (!error && *preal > 1) {
+                /* Sort the real roots */
+
+                /* FIXME: Assumes that all roots found so far are real */
+
+                cpl_vector * reals = cpl_vector_wrap(*preal,
+                                                     cpl_vector_get_data(roots));
+                cpl_vector_sort(reals, 1);
+                (void)cpl_vector_unwrap(reals);
+            }
+        }
+        break;
+    }
+    }
+
+    return error;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @internal
+  @brief    Solve the quadratic equation p2 * x^2 + p1 * x + p0 = 0, p2 != 0
+  @param    p2    The non-zero coefficient to x^2
+  @param    p1    The coefficient to x
+  @param    p0    The constant term
+  @param    px1   The 1st root or the real part of the complex roots
+  @param    px2   The 2nd root or the imaginary part of the complex roots
+  @return   CPL_TRUE iff the roots are complex
+
+ */
+/*----------------------------------------------------------------------------*/
+static cpl_boolean irplib_polynomial_solve_1d_2(double p2, double p1, double p0,
+                                                double * px1,
+                                                double * px2) {
+
+    const double sqrtD = sqrt(fabs(p1 * p1 - 4.0 * p2 * p0));
+    cpl_boolean is_complex = CPL_FALSE;
+    double x1 = -0.5 * p1 / p2; /* Double root */
+    double x2;
+
+    /* Compute residual, assuming D == 0 */
+    double res0 = irplib_polynomial_eval_2_max(p2, p1, p0, CPL_FALSE, x1, x1);
+    double res;
+
+    assert(px1 != NULL );
+    assert(px2 != NULL );
+
+    *px2 = *px1 = x1;
+
+    /* Compute residual, assuming D > 0 */
+
+    /* x1 is the root with largest absolute value */
+    if (p1 > 0.0) {
+        x1 = -0.5 * (p1 + sqrtD);
+        irplib_trace(); /* OK */
+    } else {
+        x1 = -0.5 * (p1 - sqrtD);
+        irplib_trace(); /* OK */
+    }
+    /* Compute smaller root via division to avoid
+       loss of precision due to cancellation */
+    x2 = p0 / x1;
+    x1 /= p2; /* Scale x1 with leading coefficient */
+
+    res = irplib_polynomial_eval_2_max(p2, p1, p0, CPL_FALSE, x1, x2);
+
+    if (res < res0) {
+        res0 = res;
+        if (x2 > x1) {
+            *px1 = x1;
+            *px2 = x2;
+            irplib_trace(); /* OK */
+        } else {
+            *px1 = x2;
+            *px2 = x1;
+            irplib_trace(); /* OK */
+        }
+    }
+
+    /* Compute residual, assuming D < 0 */
+
+    x1 = -0.5 * p1 / p2;          /* Real part of complex root */
+    x2 =  0.5 * sqrtD / fabs(p2); /* Positive, imaginary part of root */
+
+    res  = irplib_polynomial_eval_2_max(p2, p1, p0, CPL_TRUE,  x1, x2);
+
+    if (res < res0) {
+        *px1 = x1;
+        *px2 = x2;
+        is_complex = CPL_TRUE;
+        irplib_trace(); /* OK */
+    }
+
+    return is_complex;
+
+}
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Find the max residual on a 2nd degree 1D-polynomial on the roots
+  @param    p2   p2
+  @param    p1   p1
+  @param    p0   p0
+  @param    is_c CPL_TRUE iff the two roots are complex
+  @param    x1   The 1st point of evaluation (or real part on complex)
+  @param    x2   The 2nd point of evaluation (or imaginary part on complex)
+  @return   The result
+
+
+ */
+/*----------------------------------------------------------------------------*/
+static double irplib_polynomial_eval_2_max(double p2, double p1, double p0,
+                                           cpl_boolean is_c,
+                                           double x1, double x2)
+{
+    double res;
+
+    if (is_c) {
+        res = fabs(p0 + x1 * (p1 + x1 * p2) - p2 * x2 * x2);
+        irplib_trace(); /* OK */
+    } else {
+        const double r1 = fabs(p0 + x1 * (p1 + x1 * p2));
+        const double r2 = fabs(p0 + x2 * (p1 + x2 * p2));
+
+        res = r1 > r2 ? r1 : r2;
+        irplib_trace(); /* OK */
+    }
+
+    return res;
+}
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Find the max residual on a 3rd degree 1D-polynomial on the roots
+  @param    p3    p3
+  @param    p2    p2
+  @param    p1    p1
+  @param    p0    p0
+  @param    is_c  CPL_TRUE iff two roots are complex
+  @param    x1    The 1st point of evaluation (real)
+  @param    x2    The 2nd point of evaluation (or real part on complex)
+  @param    x3    The 3rd point of evaluation (or imaginary part on complex)
+  @return   The result
+
+
+ */
+/*----------------------------------------------------------------------------*/
+static double irplib_polynomial_eval_3_max(double p3, double p2,
+                                           double p1, double p0,
+                                           cpl_boolean is_c,
+                                           double x1, double x2, double x3)
+{
+    const double r1 = fabs(p0 + x1 * (p1 + x1 * (p2 + x1 * p3)));
+    double res;
+
+    if (is_c) {
+        const double r2 = fabs(p0 + x2 * (p1 + x2 * (p2 + x2 * p3))
+                               - x3 * x3 * ( 3.0 * p3 * x2 + p2));
+
+        res = r1 > r2 ? r1 : r2;
+        irplib_trace(); /* OK */
+    } else {
+        const double r2 = fabs(p0 + x2 * (p1 + x2 * (p2 + x2 * p3)));
+        const double r3 = fabs(p0 + x3 * (p1 + x3 * (p2 + x3 * p3)));
+        res = r1 > r2 ? (r1 > r3 ? r1 : r3) : (r2 > r3 ? r2 : r3);
+        irplib_trace(); /* OK */
+    }
+
+    /* cpl_msg_info(cpl_func, "%d: %g (%g)", __LINE__, res, r1); */
+
+    return res;
+}
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @internal
+  @brief    Solve the cubic equation p3 * x^3 + p2 * x^2 + p1 * x + p0 = 0
+  @param    p3    The non-zero coefficient to x^3
+  @param    p2    The coefficient to x^2
+  @param    p1    The coefficient to x
+  @param    p0    The constant term
+  @param    px1   The 1st root (real)
+  @param    px2   The 2nd root or the real part of the complex roots
+  @param    px3   The 3rd root or the imaginary part of the complex roots
+  @param    pdbl1 CPL_TRUE iff *px1 == *px2 (only for all real)
+  @param    pdbl2 CPL_TRUE iff *px2 == *px3 (only for all real)
+  @return   CPL_TRUE iff two of the roots are complex
+  @see gsl_poly_complex_solve_cubic() of GSL v. 1.9
+  @note px2 and px3 may be NULL, if in this case all three roots are real *px1
+        will be set to the largest root.
+
+ */
+/*----------------------------------------------------------------------------*/
+static cpl_boolean irplib_polynomial_solve_1d_3(double p3, double p2, double p1,
+                                                double p0,
+                                                double * px1,
+                                                double * px2,
+                                                double * px3,
+                                                cpl_boolean * pdbl1,
+                                                cpl_boolean * pdbl2) {
+    cpl_boolean is_complex = CPL_FALSE;
+    const double a = p2/p3;
+    const double b = p1/p3;
+    const double c = p0/p3;
+
+    const double q = (a * a - 3.0 * b);
+    const double r = (a * (2.0 * a * a - 9.0 * b) + 27.0 * c);
+
+    const double Q = q / 9.0;
+    const double R = r / 54.0;
+
+    const double Q3 = Q * Q * Q;
+    const double R2 = R * R;
+
+    double x1 = DBL_MAX; /* Fix (false) uninit warning */
+    double x2 = DBL_MAX; /* Fix (false) uninit warning */
+    double x3 = DBL_MAX; /* Fix (false) uninit warning */
+    double xx1 = DBL_MAX; /* Fix (false) uninit warning */
+    double xx2 = DBL_MAX; /* Fix (false) uninit warning */
+    double xx3 = DBL_MAX; /* Fix (false) uninit warning */
+
+    double resx = DBL_MAX;
+    double res  = DBL_MAX;
+    cpl_boolean is_first = CPL_TRUE;
+
+    cpl_boolean dbl2;
+
+
+    assert(px1 != NULL );
+
+    if (pdbl1 != NULL) *pdbl1 = CPL_FALSE;
+    if (pdbl2 != NULL) *pdbl2 = CPL_FALSE;
+
+    dbl2 = CPL_FALSE;
+
+    /*
+      All branches (for which the roots are defined) are evaluated, and
+      the branch with the smallest maximum-residual is chosen.
+      When two maximum-residual are identical, preference is given to
+      the purely real solution and if necessary to the solution with a
+      double root.
+    */
+
+    if ((R2 >= Q3 && R != 0.0) || R2 > Q3) {
+
+        cpl_boolean is_c = CPL_FALSE;
+
+        irplib_polynomial_solve_1d_3c(a, c, Q, Q3, R, R2, &x1, &x2, &x3,
+                                      &is_c, &dbl2);
+
+
+        res = resx = irplib_polynomial_eval_3_max(p3, p2, p1, p0, is_c,
+                                            x1, x2, x3);
+
+        is_first = CPL_FALSE;
+
+        if (pdbl1 != NULL) *pdbl1 = CPL_FALSE;
+        if (!is_c && pdbl2 != NULL) *pdbl2 = dbl2;
+        is_complex = is_c;
+        irplib_trace(); /* OK */
+   
+    }
+
+    if (Q > 0.0 && fabs(R / (Q * sqrt(Q))) <= 1.0) {
+
+        /* this test is actually R2 < Q3, written in a form suitable
+           for exact computation with integers */
+
+        /* assert( Q > 0.0 ); */
+
+        irplib_polynomial_solve_1d_3r(a, c, Q, R, &xx1, &xx2, &xx3);
+
+        resx = irplib_polynomial_eval_3_max(p3, p2, p1, p0, CPL_FALSE,
+                                            xx1, xx2, xx3);
+
+        if (is_first || (dbl2 ? resx < res : resx <= res)) {
+            is_first = CPL_FALSE;
+            res = resx;
+            x1 = xx1;
+            x2 = xx2;
+            x3 = xx3;
+            if (pdbl1 != NULL) *pdbl1 = CPL_FALSE;
+            if (pdbl2 != NULL) *pdbl2 = CPL_FALSE;
+            is_complex = CPL_FALSE;
+            irplib_trace(); /* OK */
+        }
+    }
+
+    if (Q >= 0) {
+        cpl_boolean dbl1 = CPL_FALSE;
+
+
+        irplib_polynomial_solve_1d_32(a, c, Q, &xx1, &xx2, &xx3, &dbl2);
+
+        resx = irplib_polynomial_eval_3_max(p3, p2, p1, p0, CPL_FALSE,
+                                            xx1, xx2, xx3);
+        /*
+        cpl_msg_info(cpl_func, "%d: %g = %g - %g (%u)", __LINE__,
+                     res - resx, res, resx, is_complex);
+        */
+
+        if (is_first || resx <= res) {
+            is_first = CPL_FALSE;
+            res = resx;
+            x1 = xx1;
+            x2 = xx2;
+            x3 = xx3;
+            if (pdbl1 != NULL) *pdbl1 = CPL_FALSE;
+            if (pdbl2 != NULL) *pdbl2 = dbl2;
+            is_complex = CPL_FALSE;
+            irplib_trace(); /* OK */
+        }
+
+
+        /* This branch also covers the case where the depressed cubic
+           polynomial has zero as triple root (i.e. Q == R == 0) */
+
+        irplib_polynomial_solve_1d_31(a, Q, &xx1, &xx2, &xx3, &dbl1);
+
+        resx = irplib_polynomial_eval_3_max(p3, p2, p1, p0, CPL_FALSE,
+                                            xx1, xx2, xx3);
+
+        if (resx <= res) {
+            is_first = CPL_FALSE;
+            res = resx;
+            x1 = xx1;
+            x2 = xx2;
+            x3 = xx3;
+            if (pdbl1 != NULL) *pdbl1 = dbl1;
+            if (pdbl2 != NULL) *pdbl2 = CPL_FALSE;
+            is_complex = CPL_FALSE;
+            irplib_trace(); /* OK */
+        }
+
+    }
+
+    if (px2 != NULL && px3 != NULL) {
+        *px1 = x1;
+        *px2 = x2;
+        *px3 = x3;
+        irplib_trace(); /* OK */
+    } else if (is_complex) {
+        *px1 = x1;
+        irplib_trace(); /* OK */
+    } else {
+        *px1 = x3;
+        irplib_trace(); /* OK */
+    }
+
+    return is_complex;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @internal
+  @brief    Solve the monic, depressed cubic with 1st and 2nd root as double
+  @param    a     p2/p3 for back-transform
+  @param    Q     The linear term, must be positive
+  @param    px1   The 1st root
+  @param    px2   The 2nd root
+  @param    px3   The 3rd root
+  @param    pdbl1 CPL_TRUE iff *px1 == *px2
+  @return   void
+  @see irplib_polynomial_solve_1d_3()
+
+ */
+/*----------------------------------------------------------------------------*/
+static void irplib_polynomial_solve_1d_31(double a, double Q,
+                                          double * px1, double * px2,
+                                          double * px3, cpl_boolean * pdbl1)
+{
+
+    const double sqrtQ = sqrt (Q);
+
+    double x1, x2, x3;
+
+    x2 = x1 = -sqrtQ - a / 3.0;
+    x3 = 2.0 * sqrtQ - a / 3.0;
+    if (pdbl1 != NULL) *pdbl1 = CPL_TRUE;
+
+    *px1 = x1;
+    *px2 = x2;
+    *px3 = x3;
+
+    irplib_trace(); /* OK */
+    return;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @internal
+  @brief    Solve the monic, depressed cubic with 2nd and 3rd root as double
+  @param    a     p2/p3 for back-transform
+  @param    c     p0/p3 for finding root via division of constant term
+  @param    Q     The linear term, must be positive
+  @param    px1   The 1st root
+  @param    px2   The 2nd root
+  @param    px3   The 3rd root
+  @param    pdbl2 CPL_TRUE iff *px2 == *px3
+  @return   void
+  @see irplib_polynomial_solve_1d_3()
+
+ */
+/*----------------------------------------------------------------------------*/
+static void irplib_polynomial_solve_1d_32(double a, double c, double Q,
+                                          double * px1, double * px2,
+                                          double * px3, cpl_boolean * pdbl2)
+{
+
+    const double sqrtQ = sqrt (Q);
+
+    double x1 = DBL_MAX;
+    double x2 = DBL_MAX;
+    double x3 = DBL_MAX;
+
+    if (a > 0.0) {
+        /* a and sqrt(Q) have same sign - or Q is zero */
+        x1 = -2.0 * sqrtQ - a / 3.0;
+        /* FIXME: Two small roots with opposite signs may
+           end up here, with the sign lost for one of them */
+        x3 = x2 = -a < x1 ? -sqrt(fabs(c / x1)) : sqrt(fabs(c / x1));
+        if (pdbl2 != NULL) *pdbl2 = CPL_TRUE;
+        irplib_trace(); /* OK */
+    } else if (a < 0.0) {
+        /* a and sqrt(Q) have opposite signs - or Q is zero */
+        x3 = x2 = sqrtQ - a / 3.0;
+        x1 = -c / (x2 * x2);
+        if (pdbl2 != NULL) *pdbl2 = CPL_TRUE;
+        irplib_trace(); /* OK */
+    } else {
+        x1 = -2.0 * sqrtQ;
+        x3 = x2 = sqrtQ;
+        if (pdbl2 != NULL) *pdbl2 = CPL_TRUE;
+        irplib_trace(); /* OK */
+    }
+
+    *px1 = x1;
+    *px2 = x2;
+    *px3 = x3;
+
+    return;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @internal
+  @brief    Solve the monic, depressed cubic with complex roots
+  @param    a     p2/p3 for back-transform
+  @param    c     p0/p3 for finding root via division of constant term
+  @param    Q     The linear term
+  @param    Q3    Q^3
+  @param    R     The constant term
+  @param    R2    R^2
+  @param    px1   The 1st root (real)
+  @param    px2   The 2nd root or the real part of the complex roots
+  @param    px3   The 3rd root or the imaginary part of the complex roots
+  @param    pis_c CPL_TRUE iff complex
+  @param    pdbl2 CPL_TRUE iff *px2 == *px3 (only for all real)
+  @return   void
+  @see irplib_polynomial_solve_1d_3()
+  @note If all roots are real, then two of them are a double root.
+
+ */
+/*----------------------------------------------------------------------------*/
+static void irplib_polynomial_solve_1d_3c(double a, double c,
+                                          double Q, double Q3,
+                                          double R, double R2,
+                                          double * px1,
+                                          double * px2, double * px3,
+                                          cpl_boolean * pis_c,
+                                          cpl_boolean * pdbl2)
+{
+
+    /* Due to finite precision some double roots may be missed, and
+       will be considered to be a pair of complex roots z = x +/-
+       epsilon i close to the real axis. */
+
+    /* Another case: A double root, which is small relative to the
+       last root, may cause this branch to be taken - with the
+       imaginary part eventually being truncated to zero. */
+
+    const double sgnR = (R >= 0 ? 1.0 : -1.0);
+    const double A = -sgnR * pow (fabs (R) + sqrt (R2 - Q3), 1.0 / 3.0);
+    const double B = Q / A;
+
+    double x1 = DBL_MAX;
+    double x2 = DBL_MAX;
+    double x3 = DBL_MAX;
+    cpl_boolean is_complex = CPL_FALSE;
+
+    if (( A > -B && a > 0.0) || (A < -B && a < 0.0)) {
+        /* A+B has same sign as a */
+
+        /* Real part of complex conjugate */
+        x2 = -0.5 * (A + B) - a / 3.0; /* No cancellation */
+        /* Positive, imaginary part of complex conjugate */
+        x3 = 0.5 * CPL_MATH_SQRT3 * fabs(A - B);
+
+        x1 = -c / (x2 * x2 + x3 * x3);
+        irplib_trace(); /* OK */
+    } else {
+        /* A+B and a have opposite signs - or exactly one is zero */
+        x1 = A + B - a / 3.0;
+        /* Positive, imaginary part of complex conjugate */
+        x3 = 0.5 * CPL_MATH_SQRT3 * fabs(A - B);
+
+        if (x3 > 0.0) {
+            /* Real part of complex conjugate */
+            x2 = -0.5 * (A + B) - a / 3.0; /* FIXME: Cancellation */
+            irplib_trace(); /* OK */
+        } else {
+
+            x2 = -a < x1 ? -sqrt(fabs(c / x1)) : sqrt(fabs(c / x1));
+            x3 = 0.0;
+            irplib_trace(); /* OK */
+        }
+    }
+
+    if (x3 > 0.0) {
+        is_complex = CPL_TRUE;
+        irplib_trace(); /* OK */
+    } else {
+        /* Whoaa, the imaginary part was truncated to zero
+           - return a real, double root */
+        x3 = x2;
+        if (pdbl2 != NULL) *pdbl2 = CPL_TRUE;
+        irplib_trace(); /* OK */
+    }
+
+    *px1 = x1;
+    *px2 = x2;
+    *px3 = x3;
+    *pis_c = is_complex;
+
+    return;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @internal
+  @brief    Solve the monic, depressed cubic with 3 distinct, real roots
+  @param    a     p2/p3 for back-transform
+  @param    c     p0/p3 for finding root via division of constant term
+  @param    Q     The linear term, must be positive
+  @param    R     The constant term
+  @param    px1   The 1st root
+  @param    px2   The 2nd root
+  @param    px3   The 3rd root
+  @return   void
+  @see irplib_polynomial_solve_1d_3()
+
+ */
+/*----------------------------------------------------------------------------*/
+static void irplib_polynomial_solve_1d_3r(double a, double c,
+                                          double Q, double R,
+                                          double * px1,
+                                          double * px2, double * px3)
+{
+
+    const double sqrtQ = sqrt(Q);
+    const double theta = acos (R / (Q * sqrtQ)); /* theta in range [0; pi] */
+
+    /* -1.0 <= cos((theta + CPL_MATH_2PI) / 3.0) <= -0.5
+       -0.5 <= cos((theta - CPL_MATH_2PI) / 3.0) <=  0.5
+        0.5 <= cos((theta                  ) / 3.0) <=  1.0 */
+
+#define TR1 (-2.0 * sqrtQ * cos( theta                    / 3.0))
+#define TR2 (-2.0 * sqrtQ * cos((theta - CPL_MATH_2PI) / 3.0))
+#define TR3 (-2.0 * sqrtQ * cos((theta + CPL_MATH_2PI) / 3.0))
+
+    /* TR1 < TR2 < TR3, except when theta == 0, then TR2 == TR3 */
+
+    /* The three roots must be transformed back via subtraction with a/3.
+       To prevent loss of precision due to cancellation, the root which
+       is closest to a/3 is computed using the relation
+       p3 * x1 * x2 * x3 = -p0 */
+
+    double x1 = DBL_MAX;
+    double x2 = DBL_MAX;
+    double x3 = DBL_MAX;
+
+    if (a > 0.0) {
+        x1 = TR1 - a / 3.0;
+        if (TR2 > 0.0 && (TR2 + TR3) > 2.0 * a) {
+            /* FIXME: Cancellation may still effect x3 ? */
+            x3 = TR3 - a / 3.0;
+            x2 = -c / ( x1 * x3 );
+            irplib_trace(); /* OK */
+        } else {
+            /* FIXME: Cancellation may still effect x2, especially
+               if x2, x3 is (almost) a double root, i.e.
+               if theta is close to zero. */
+            x2 = TR2 - a / 3.0;
+ 
+            x3 = -c / ( x1 * x2 );
+            irplib_trace(); /* OK */
+        }
+    } else if (a < 0.0) {
+        x3 = TR3 - a / 3.0;
+        if (TR2 < 0.0 && (TR1 + TR2) > 2.0 * a) {
+            x1 = TR1 - a / 3.0;
+            x2 = -c / ( x1 * x3 );
+            irplib_trace(); /* OK */
+        } else {
+            x2 = TR2 - a / 3.0;
+            x1 = -c / ( x2 * x3 );
+            irplib_trace(); /* OK */
+        }
+    } else {
+        x1 = TR1;
+        x2 = TR2;
+        x3 = TR3;
+        irplib_trace(); /* OK */
+    }
+
+    assert(x1 < x3);
+
+    if (x1 > x2) {
+        /* In absence of round-off:
+           theta == PI: x1 == x2,
+           theta  < PI: x1 <  x2,
+
+           The only way x1 could exceed x2 would be due to round-off when
+           theta is close to PI */
+     
+        x1 = x2 = 0.5 * ( x1 + x2 );
+        irplib_trace(); /* OK, tested only for x1 == x2 */
+    } else if (x2 > x3) {
+        /* In absence of round-off:
+           theta == 0: x2 == x3,
+           theta  > 0: x2 <  x3,
+
+           For small theta:
+           Round-off can cause x2 to become greater than x3 */
+     
+        x3 = x2 = 0.5 * ( x2 + x3 );
+        irplib_trace(); /* OK */
+    }
+
+    *px1 = x1;
+    *px2 = x2;
+    *px3 = x3;
+
+    return;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @internal
+  @brief    Solve the quartic equation
+            p4 * x^4 + p3 * x^3 + p2 * x^2 + p1 * x + p0 = 0
+  @param    p4    The non-zero coefficient to x^4
+  @param    p3    The coefficient to x^3
+  @param    p2    The coefficient to x^2
+  @param    p1    The coefficient to x
+  @param    p0    The constant term
+  @param    preal *preal is the number of real roots, or undefined on error
+  @param    px1   The 1st root or the real part of the 1st complex roots-pair
+  @param    px2   The 2nd root or the imaginary part of the 1st complex roots
+  @param    px3   The 3rd root or the real part of the 2nd complex roots-pair
+  @param    px4   The 4th root or the imaginary part of the 2nd complex roots
+  @return   CPL_ERROR_NONE or the relevant CPL error code
+
+ */
+/*----------------------------------------------------------------------------*/
+static cpl_error_code irplib_polynomial_solve_1d_4(double p4, double p3,
+                                                   double p2, double p1,
+                                                   double p0, cpl_size * preal,
+                                                   double * px1, double * px2,
+                                                   double * px3, double * px4)
+{
+
+    /* Construct the monic, depressed quartic using Horners scheme on 1 / p4 */
+    const double a = (p2 - 0.375 * p3 * p3 / p4) / p4;
+    const double b = (p1 - 0.5 * (p2 - 0.25 * p3 * p3 / p4 ) * p3 / p4 ) / p4;
+    const double c =
+        (p0 - 0.25 * (p1 - 0.25 * (p2 - 0.1875 * p3 * p3 / p4 ) * p3 / p4
+                      ) * p3 / p4 ) / p4;
+
+    double x1 = DBL_MAX; /* Fix (false) uninit warning */
+    double x2 = DBL_MAX; /* Fix (false) uninit warning */
+    double x3 = DBL_MAX; /* Fix (false) uninit warning */
+    double x4 = DBL_MAX; /* Fix (false) uninit warning */
+
+    assert(preal != NULL );
+    assert(px1   != NULL );
+    assert(px2   != NULL );
+    assert(px3   != NULL );
+    assert(px4   != NULL );
+
+    *preal = 4;
+
+    if (c == 0.0) {
+        /* The depressed quartic has zero as root */
+        /* Since the sum of the roots is zero, at least one is negative
+           and at least one is positive - unless they are all zero */
+        cpl_boolean dbl1, dbl2;
+        const cpl_boolean is_real =
+            !irplib_polynomial_solve_1d_3(1.0, 0.0, a, b, &x1, &x3, &x4,
+                                          &dbl1, &dbl2);
+
+        x1 -= 0.25 * p3 / p4;
+        x2 = -0.25 * p3 / p4;
+        x3 -= 0.25 * p3 / p4;
+        if (is_real) {
+
+            if (dbl2) {
+                x4 = x3;
+                assert( x1 <= x2);
+                assert( x2 <= x3);
+            } else {
+                x4 -= 0.25 * p3 / p4;
+                /* Need (only) a guarded swap of x2, x3 */
+                if (x2 > x3) {
+                    IRPLIB_SWAP(x2, x3);
+                }
+                if (dbl1) {
+                    assert( x1 <= x2); /* The cubic may have 0 as triple root */
+                    assert( x2 <= x3);
+                    assert( x2 <= x4);
+                } else {
+                    assert( x1 < x2);
+                    assert( x2 < x4);
+                }
+            }
+        } else {
+            *preal = 2;
+
+            if (x1 > x2) {
+                assert( x3 <= x2 ); /* Don't swap a complex root */
+
+                IRPLIB_SWAP(x1, x2);
+            } else {
+                assert( x3 >= x2 );
+            }
+        }
+
+    } else if (b == 0.0) {
+        /* The monic, depressed quartic is a monic, biquadratic equation */
+        double u1, u2;
+        const cpl_boolean is_complex = irplib_polynomial_solve_1d_2(1.0, a, c,
+                                                                    &u1, &u2);
+
+        if (is_complex) {
+            /* All four roots are conjugate, complex */
+            const double norm = sqrt(u1*u1 + u2*u2);
+            const double   v1 = sqrt(0.5*(norm+u1));
+            const double   v2 = u2 / sqrt(2.0*(norm+u1));
+
+
+            x1 = -0.25 * p3 / p4 - v1;
+            x3 = -0.25 * p3 / p4 + v1;
+
+            x4 = x2 = v2;
+
+            *preal = 0;
+
+        } else if (u1 >= 0.0) {
+            /* All four roots are real */
+            const double sv1 = sqrt(u1);
+            const double sv2 = sqrt(u2);
+
+
+            *preal = 4;
+
+            x1 = -0.25 * p3 / p4 - sv2;
+            x2 = -0.25 * p3 / p4 - sv1;
+            x3 = -0.25 * p3 / p4 + sv1;
+            x4 = -0.25 * p3 / p4 + sv2;
+        } else if (u2 < 0.0) {
+            /* All four roots are conjugate, complex */
+            const double sv1 = sqrt(-u2);
+            const double sv2 = sqrt(-u1);
+
+
+            *preal = 0;
+
+            x1 = x3 = -0.25 * p3 / p4;
+
+            x2 = sv1;
+            x4 = sv2;
+        } else {
+            /* Two roots are real, two roots are conjugate, complex */
+            const double sv1 = sqrt(-u1);
+            const double sv2 = sqrt(u2);
+
+
+            *preal = 2;
+
+            x1 = -0.25 * p3 / p4 - sv2;
+            x2 = -0.25 * p3 / p4 + sv2;
+
+            x3 = -0.25 * p3 / p4;
+            x4 = sv1;
+        }
+    } else {
+        /* Need a root from the nested, monic cubic */
+        const double q2 = -a;
+        const double q1 = -4.0 * c;
+        const double q0 = 4.0 * a * c - b * b;
+        double u1, sqrtd, sqrtrd;
+        double z1, z2, z3, z4;
+
+        cpl_boolean is_complex1, is_complex2;
+
+        /* Largest cubic root ensures real square roots when solving the
+           quartic equation */
+        (void)irplib_polynomial_solve_1d_3(1.0, q2, q1, q0, &u1, NULL, NULL,
+                                           NULL, NULL);
+
+
+        assert( u1 > a );
+
+        sqrtd = sqrt(u1 - a);
+
+        sqrtrd = 0.5 * b/sqrtd;
+
+        is_complex1 = irplib_polynomial_solve_1d_2(1.0,  sqrtd, 0.5*u1 - sqrtrd,
+                                                   &z1, &z2);
+
+        is_complex2 = irplib_polynomial_solve_1d_2(1.0, -sqrtd, 0.5*u1 + sqrtrd,
+                                                   &z3, &z4);
+
+        z1 -= 0.25 * p3 / p4;
+        z3 -= 0.25 * p3 / p4;
+        if (!is_complex1) z2 -= 0.25 * p3 / p4;
+        if (!is_complex2) z4 -= 0.25 * p3 / p4;
+
+        if (!is_complex1 && is_complex2) {
+            *preal = 2;
+            x1 = z1;
+            x2 = z2;
+            x3 = z3;
+            x4 = z4;
+        } else if (is_complex1 && !is_complex2) {
+            *preal = 2;
+            x1 = z3;
+            x2 = z4;
+            x3 = z1;
+            x4 = z2;
+        } else if (is_complex1 && is_complex2) {
+            *preal = 0;
+
+            if (z1 < z3 || (z1 == z3 && z2 <= z4)) {
+                x1 = z1;
+                x2 = z2;
+                x3 = z3;
+                x4 = z4;
+            } else {
+                x1 = z3;
+                x2 = z4;
+                x3 = z1;
+                x4 = z2;
+            }
+        } else {
+            *preal = 4;
+
+            if (z3 >= z2) {
+                x1 = z1;
+                x2 = z2;
+                x3 = z3;
+                x4 = z4;
+            } else if (z4 <= z1) {
+                x1 = z3;
+                x2 = z4;
+                x3 = z1;
+                x4 = z2;
+            } else if (z2 > z4) {
+                x1 = z3;
+                x2 = z1;
+                x3 = z4;
+                x4 = z2;
+            } else {
+                x1 = z1;
+                x2 = z3;
+                x3 = z2;
+                x4 = z4;
+            }
+        }
+    }
+
+    *px1 = x1;
+    *px2 = x2;
+    *px3 = x3;
+    *px4 = x4;
+
+    return CPL_ERROR_NONE;
+}
+
+#ifdef IPRLIB_POLYNOMIAL_USE_MONOMIAL_ROOT
+/*----------------------------------------------------------------------------*/
+/**
+  @internal
+  @brief    Depress a 1D-polynomial of degree at least 2.
+  @param    self   The 1D-polynomial to modify
+  @return   The mean of the roots of the input polynomial
+
+ */
+/*----------------------------------------------------------------------------*/
+static double irplib_polynomial_depress_1d(cpl_polynomial * self)
+{
+
+    const cpl_size degree = cpl_polynomial_get_degree(self);
+    const cpl_size nc1    = degree - 1;
+    const double   an     = cpl_polynomial_get_coeff(self, &degree);
+    const double   an1    = cpl_polynomial_get_coeff(self, &nc1);
+    double         rmean;
+    cpl_size       i;
+
+
+    cpl_ensure(degree > 0,   CPL_ERROR_DATA_NOT_FOUND, 0.0);
+
+    assert( an != 0.0 );
+
+    rmean = -an1/(an * (double)degree);
+
+    if (rmean != 0.0) {
+
+        cpl_polynomial_shift_1d(self, 0, rmean);
+
+        cpl_polynomial_set_coeff(self, &nc1, 0.0); /* Round-off... */
+
+    }
+
+    /* Set leading coefficient to one. */
+    for (i = 0; i < degree-1; i++) {
+        const double ai = cpl_polynomial_get_coeff(self, &i) / an;
+        cpl_polynomial_set_coeff(self, &i, ai);
+    }
+
+    cpl_polynomial_set_coeff(self, &degree, 1.0); /* Round-off... */
+
+    return rmean;
+}
+#endif
+
+/*----------------------------------------------------------------------------*/
+/**
+  @internal
+  @brief  Modify p, p(x) := p(x)/(x-r), where p(r) = 0.
+  @param  p    The polynomial to be modified in place
+  @param  r    The root
+  @param  pres If non-NULL, *pres is the residual of the original p, p(r).
+  @return CPL_ERROR_NONE or the relevant CPL error code
+
+  Possible #_cpl_error_code_ set in this function:
+  - CPL_ERROR_NULL_INPUT if an input pointer is NULL
+  - CPL_ERROR_INVALID_TYPE if the polynomial has the wrong dimension
+  - CPL_ERROR_DATA_NOT_FOUND if the polynomial does not have a degree of at
+                             least 1.
+ */
+/*----------------------------------------------------------------------------*/
+static
+cpl_error_code irplib_polynomial_divide_1d_root(cpl_polynomial * p, double r,
+                                                double * pres)
+{
+
+    const cpl_size n = cpl_polynomial_get_degree(p);
+    double         sum;
+    cpl_size       i;
+
+
+    cpl_ensure_code(p != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(cpl_polynomial_get_dimension(p) == 1,
+                    CPL_ERROR_INVALID_TYPE);
+    cpl_ensure_code(n > 0, CPL_ERROR_DATA_NOT_FOUND);
+
+    sum = cpl_polynomial_get_coeff(p, &n);
+    cpl_polynomial_set_coeff(p, &n, 0.0);
+
+    for (i = n-1; i >= 0; i--) {
+        const double coeff = cpl_polynomial_get_coeff(p, &i);
+
+        cpl_polynomial_set_coeff(p, &i, sum);
+
+        sum = coeff + r * sum;
+
+    }
+
+    if (pres != NULL) *pres = sum;
+
+    return CPL_ERROR_NONE;
+}
diff --git a/irplib/irplib_polynomial.h b/irplib/irplib_polynomial.h
new file mode 100644
index 0000000..78c947d
--- /dev/null
+++ b/irplib/irplib_polynomial.h
@@ -0,0 +1,70 @@
+/* $Id: irplib_polynomial.h,v 1.9 2012/01/12 10:40:21 llundin Exp $
+ *
+ * This file is part of the ESO Common Pipeline Library
+ * Copyright (C) 2007 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: llundin $
+ * $Date: 2012/01/12 10:40:21 $
+ * $Revision: 1.9 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifndef IRPLIB_POLYNOMIAL_H
+#define IRPLIB_POLYNOMIAL_H
+
+/*-----------------------------------------------------------------------------
+                                   Includes
+ -----------------------------------------------------------------------------*/
+
+#include <cpl.h>
+
+/*-----------------------------------------------------------------------------
+                              Function prototypes
+ -----------------------------------------------------------------------------*/
+
+/* TEMPORARY SUPPORT OF CPL 5.x */
+#ifndef CPL_SIZE_FORMAT
+#define CPL_SIZE_FORMAT "d"
+#define cpl_size int
+#endif
+
+#if defined CPL_VERSION_CODE && CPL_VERSION_CODE > CPL_VERSION(5, 92, 0)
+#define irplib_polynomial_add cpl_polynomial_add
+#define irplib_polynomial_subtract cpl_polynomial_subtract
+#define irplib_polynomial_multiply_scalar cpl_polynomial_multiply_scalar
+#else
+cpl_error_code irplib_polynomial_add(cpl_polynomial *,
+                                     const cpl_polynomial *,
+                                     const cpl_polynomial *);
+
+cpl_error_code irplib_polynomial_subtract(cpl_polynomial *,
+                                          const cpl_polynomial *,
+                                          const cpl_polynomial *);
+
+cpl_error_code irplib_polynomial_multiply_scalar(cpl_polynomial *,
+                                                 const cpl_polynomial *,
+                                                 double);
+#endif
+
+/* END TEMPORARY SUPPORT OF CPL 5.x */
+
+cpl_error_code irplib_polynomial_solve_1d_all(const cpl_polynomial *,
+                                              cpl_vector *, cpl_size *);
+
+#endif
diff --git a/irplib/irplib_ppm.c b/irplib/irplib_ppm.c
new file mode 100644
index 0000000..5f74061
--- /dev/null
+++ b/irplib/irplib_ppm.c
@@ -0,0 +1,494 @@
+/* $Id: irplib_ppm.c,v 1.30 2011/11/23 13:58:45 yjung Exp $
+ *
+ * This file is part of the irplib package
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: yjung $
+ * $Date: 2011/11/23 13:58:45 $
+ * $Revision: 1.30 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+/*-----------------------------------------------------------------------------
+                                   Includes
+ -----------------------------------------------------------------------------*/
+
+#include <math.h>
+#include <cpl.h>
+
+#include "irplib_ppm.h"
+#include "irplib_wlxcorr.h"
+#include "irplib_spectrum.h"
+
+/* TEMPORARY SUPPORT OF CPL 5.x */
+#ifndef CPL_SIZE_FORMAT
+#define CPL_SIZE_FORMAT "d"
+#define cpl_size int
+#endif
+/* END TEMPORARY SUPPORT OF CPL 5.x */
+
+/*-----------------------------------------------------------------------------
+                                   Private functions
+ -----------------------------------------------------------------------------*/
+#ifdef IRPLIB_PPM_USE_METHOD2
+static cpl_vector * irplib_ppm_convolve_line(const cpl_vector *, double,double);
+static cpl_vector * irplib_ppm_detect_lines(const cpl_vector *, double) ;
+#endif
+
+/*----------------------------------------------------------------------------*/
+/**
+ * @defgroup irplib_ppm     Point pattern matching
+ */
+/*----------------------------------------------------------------------------*/
+
+/**@{*/
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    The Wavelength Calibration using PPM
+  @param    spectrum        The spectrum vector
+  @param    lines_catalog   The lines catalog
+  @param    poly_init       Polynomial with the initial guess
+  @param    slitw           The slit width
+  @param    fwhm            The spectral FWHM [pixel]
+  @param    thresh          The threshold for lines detection
+  @param    degree          The polynomial degree
+  @param    doplot          Plotting level (zero for none)
+  @param    tab_infos       The computed solution table or NULL (computed) 
+  @return   the polynomial solution or NULL in error case
+
+  The returned table must be deallocated with cpl_table_delete().
+  The returned polynomial must be deallocated with cpl_polynomial_delete().
+ */
+/*----------------------------------------------------------------------------*/
+cpl_polynomial * irplib_ppm_engine(
+        const cpl_vector        *   spectrum,
+        const cpl_bivector      *   lines_catalog,
+        const cpl_polynomial    *   poly_init,
+        double                      slitw,
+        double                      fwhm,
+        double                      thresh,
+        int                         degree,
+        int                         doplot,
+        cpl_table               **  tab_infos)
+{
+#ifdef IRPLIB_PPM_USE_METHOD2
+    cpl_vector      *   spec_conv ;
+#endif
+    int                 spec_sz ;
+    cpl_vector      *   det_lines ;
+    double          *   pdet_lines ;
+    cpl_vector      *   cat_lines ;
+    double          *   pcat_lines ;
+    double              wmin, wmax ;
+    double              disp_min, disp_max, disp ;
+    int                 nlines_cat, nlines ;
+    const double    *   plines_catalog_x ;
+    const double    *   plines_catalog_y ;
+    cpl_bivector    *   matched ;
+    cpl_matrix      *   matchedx;
+    int                 match_sz;
+    cpl_polynomial  *   fitted ;
+    cpl_table       *   spc_table ;
+    const cpl_vector*   vectors_plot[3];
+    cpl_vector      *   plot_y ;
+    int                 wl_ind, start_ind, stop_ind ;
+    double              fill_val ;
+    cpl_size            deg_loc ;
+    int                 i ;
+    cpl_error_code      error;
+
+    /* Check entries */
+    if (spectrum == NULL) return NULL ;
+    if (lines_catalog == NULL) return NULL ;
+    if (poly_init == NULL) return NULL ;
+
+    /* Initialise */
+    spec_sz = cpl_vector_get_size(spectrum) ;
+    deg_loc = (cpl_size)degree ;
+   
+#ifdef IRPLIB_PPM_USE_METHOD2
+    /* METHOD 2 */
+    /* Correlate the spectrum with the line profile */
+    if ((spec_conv = irplib_ppm_convolve_line(spectrum, slitw, fwhm)) == NULL) {
+        cpl_msg_error(cpl_func, "Cannot convolve the signal") ;
+        return NULL ;
+    }
+   
+    /* Apply the lines detection */
+    if ((det_lines = irplib_ppm_detect_lines(spec_conv, 0.9)) == NULL) {
+        cpl_msg_error(cpl_func, "Cannot detect lines") ;
+        cpl_vector_delete(spec_conv) ;
+        return NULL ;
+    }
+    cpl_vector_delete(spec_conv) ;
+#else
+    /* METHOD 1 */
+    if ((det_lines = irplib_spectrum_detect_peaks(spectrum, fwhm,
+                    thresh, 0, NULL, NULL)) == NULL) {
+        cpl_msg_error(cpl_func, "Cannot convolve the signal") ;
+        return NULL ;
+    }
+#endif
+    cpl_msg_info(cpl_func, "Detected %"CPL_SIZE_FORMAT" lines", 
+            cpl_vector_get_size(det_lines));
+ 
+    /* Get the catalog lines */
+    wmin = cpl_polynomial_eval_1d(poly_init, 1.0, NULL) ;
+    wmax = cpl_polynomial_eval_1d(poly_init, spec_sz, NULL) ;
+    plines_catalog_x = cpl_bivector_get_x_data_const(lines_catalog) ;
+    plines_catalog_y = cpl_bivector_get_y_data_const(lines_catalog) ;
+    nlines = cpl_bivector_get_size(lines_catalog) ;
+    nlines_cat = 0 ;
+    start_ind = stop_ind = -1 ;
+    for (i=0 ; i<nlines ; i++) {
+        if (plines_catalog_x[i] > wmin && plines_catalog_x[i] < wmax &&
+                plines_catalog_y[i] > 0.0) {
+            nlines_cat++ ;
+            if (start_ind<0) start_ind = i ;
+            stop_ind = i ;
+        }
+    }
+    if (nlines_cat == 0) {
+        cpl_msg_error(cpl_func, "No lines in catalog") ;
+        cpl_vector_delete(det_lines) ;
+        return NULL ;
+    }
+    cat_lines = cpl_vector_new(nlines_cat) ;
+    pcat_lines = cpl_vector_get_data(cat_lines) ;
+    nlines_cat = 0 ;
+    for (i=0 ; i<nlines ; i++) {
+        if (plines_catalog_x[i] > wmin && plines_catalog_x[i] < wmax &&
+                plines_catalog_y[i] > 0.0) {
+            pcat_lines[nlines_cat] = plines_catalog_x[i] ; 
+            nlines_cat++ ;
+        }
+    }
+ 
+    /* Plot inputs */
+    if (doplot) {
+        /* Catalog */
+        irplib_wlxcorr_catalog_plot(lines_catalog, wmin, wmax) ;
+
+        /* Spectrum with detected lines */
+        fill_val = cpl_vector_get_max(spectrum) ;
+        plot_y = cpl_vector_new(spec_sz);
+        cpl_vector_fill(plot_y, 0.0) ;
+        pdet_lines = cpl_vector_get_data(det_lines) ;
+        for (i=0 ; i<cpl_vector_get_size(det_lines) ; i++) {
+            cpl_vector_set(plot_y, (int)pdet_lines[i], fill_val) ;
+        }
+        vectors_plot[0] = NULL ;
+        vectors_plot[1] = spectrum ;
+        vectors_plot[2] = plot_y ;
+
+        cpl_plot_vectors("set grid;set xlabel 'Position (Pixel)';set ylabel "
+                            "'Intensity (ADU/sec)';",
+                            "t 'Spectrum with detected lines' w lines", "",
+                            vectors_plot, 3);
+        cpl_vector_delete(plot_y) ;
+    }
+   
+    /* Apply the point pattern matching */
+    disp = (wmax-wmin) / spec_sz ;
+    disp_min = disp - (disp/10) ;
+    disp_max = disp + (disp/10) ;
+    matched = cpl_ppm_match_positions(det_lines, cat_lines, disp_min,
+                                      disp_max, 0.05, NULL, NULL);
+    cpl_vector_delete(det_lines) ;
+    cpl_vector_delete(cat_lines) ;
+
+    if (matched == NULL) {
+        cpl_msg_error(cpl_func, "Cannot apply the point pattern matching") ;
+        return NULL ;
+    }
+
+    match_sz = cpl_bivector_get_size(matched);
+
+    cpl_msg_info(cpl_func, "Matched %d lines", match_sz) ;
+
+    if (match_sz <= deg_loc) {
+        cpl_msg_error(cpl_func, "Not enough match for the fit") ;
+        cpl_bivector_delete(matched) ;
+        return NULL ;
+    }
+    
+    /* Plot if requested */
+    if (doplot) {
+        const double    *   pmatched ;
+        cpl_bivector    *   biplot ;
+        cpl_vector      *   plot_cat_x ;
+        cpl_vector      *   plot_cat_y ;
+        /* Spectrum with matched lines */
+        fill_val = cpl_vector_get_max(spectrum) ;
+        plot_y = cpl_vector_new(spec_sz);
+        cpl_vector_fill(plot_y, 0.0) ;
+        pmatched = cpl_bivector_get_x_data_const(matched) ;
+        for (i=0 ; i < match_sz; i++) {
+            cpl_vector_set(plot_y, (int)pmatched[i], fill_val) ;
+        }
+        vectors_plot[0] = NULL ;
+        vectors_plot[1] = spectrum ;
+        vectors_plot[2] = plot_y ;
+
+        cpl_plot_vectors("set grid;set xlabel 'Position (Pixel)';set ylabel "
+                            "'Intensity (ADU/sec)';",
+                            "t 'Spectrum with matched lines' w lines", "",
+                            vectors_plot, 3);
+        cpl_vector_delete(plot_y) ;
+
+        /* Catalog with matched lines */
+        plot_cat_x=cpl_vector_extract(cpl_bivector_get_x_const(lines_catalog), 
+                start_ind, stop_ind, 1) ;
+        plot_cat_y=cpl_vector_extract(cpl_bivector_get_y_const(lines_catalog), 
+                start_ind, stop_ind, 1) ;
+        biplot = cpl_bivector_wrap_vectors(plot_cat_x, plot_cat_y) ;
+        cpl_plot_bivector("set grid;set xlabel 'Wavelength';set ylabel "
+                             "'Emission';", "t 'Catalog' w impulses", "",
+                             biplot);
+        cpl_bivector_unwrap_vectors(biplot) ;
+
+        plot_y = cpl_vector_duplicate(plot_cat_y) ;
+        cpl_vector_fill(plot_y, 0.0) ;
+        pmatched = cpl_bivector_get_y_data_const(matched) ;
+        fill_val=cpl_vector_get_mean(plot_cat_y) ;
+        for (i=0 ; i < match_sz; i++) {
+            wl_ind = 0 ;
+            while (pmatched[i] > cpl_vector_get(plot_cat_x, wl_ind) 
+                    && wl_ind < spec_sz) wl_ind++ ;
+            if (wl_ind < spec_sz) cpl_vector_set(plot_y, wl_ind, fill_val) ;
+        }
+        biplot = cpl_bivector_wrap_vectors(plot_cat_x, plot_y) ;
+        cpl_plot_bivector("set grid;set xlabel 'Wavelength';set ylabel "
+                             "'Emission';", "t 'Catalog (matched lines)' w "
+                             "impulses", "", biplot) ;
+        cpl_bivector_unwrap_vectors(biplot) ;
+        cpl_vector_delete(plot_cat_x) ;
+        cpl_vector_delete(plot_cat_y) ;
+        cpl_vector_delete(plot_y) ;
+    }
+    
+    /* Apply the fit */
+    matchedx = cpl_matrix_wrap(1, match_sz, cpl_bivector_get_x_data(matched));
+    fitted = cpl_polynomial_new(1);
+    error = cpl_polynomial_fit(fitted, matchedx, NULL,
+                               cpl_bivector_get_y_const(matched), NULL,
+                               CPL_FALSE, NULL, &deg_loc);
+    cpl_bivector_delete(matched);
+    (void)cpl_matrix_unwrap(matchedx);
+    if (error) {
+        cpl_msg_error(cpl_func, "Cannot fit the polynomial") ;
+        cpl_polynomial_delete(fitted);
+        return NULL ;
+    }
+   
+    /* Create the infos table */
+    if ((spc_table = irplib_wlxcorr_gen_spc_table(spectrum,
+                    lines_catalog, slitw, fwhm, poly_init, fitted)) == NULL) {
+        cpl_msg_error(cpl_func, "Cannot generate the infos table") ;
+        cpl_polynomial_delete(fitted) ;
+        return NULL ;
+    }
+    if (tab_infos != NULL) *tab_infos = spc_table ;
+    else cpl_table_delete(spc_table) ;
+    return fitted ;
+}
+
+/**@}*/
+
+#ifdef IRPLIB_PPM_USE_METHOD2
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Spectrum convolution with a line profile
+  @param    spectrum        The spectrum vector
+  @param    slitw           The slit width
+  @param    fwhm            The spectral FWHM [pixel]
+  @param    doplot          Plotting level (zero for none)
+  @return   the convolved spectrum
+
+  The returned vector must be deallocated with cpl_vector_delete().
+ */
+/*----------------------------------------------------------------------------*/
+static cpl_vector * irplib_ppm_convolve_line(
+        const cpl_vector        *   spectrum,
+        double                      slitw,
+        double                      fwhm)
+{
+    cpl_vector  *   conv_kernel ;
+    cpl_vector  *   line_profile ;
+    cpl_vector  *   xcorrs ;
+    cpl_vector  *   spec_ext ;
+    cpl_vector  *   xc_single ;
+    int             hs, line_sz, sp_sz ;
+    int             i ;
+
+    /* Test entries */
+    if (spectrum == NULL) return NULL ;
+
+    /* Create the convolution kernel */
+    if ((conv_kernel = irplib_wlxcorr_convolve_create_kernel(slitw,
+                    fwhm)) == NULL) {
+        cpl_msg_error(cpl_func, "Cannot create kernel") ;
+        return NULL ;
+    }
+    hs = cpl_vector_get_size(conv_kernel) ;
+    line_sz = 2 * hs + 1 ;
+    
+    /* Create the line profile */
+    line_profile = cpl_vector_new(line_sz) ;
+    cpl_vector_fill(line_profile, 0.0) ;
+    cpl_vector_set(line_profile, hs, 1.0) ;
+    if (irplib_wlxcorr_convolve(line_profile, conv_kernel) != 0) {
+        cpl_msg_error(cpl_func, "Cannot create line profile") ;
+        cpl_vector_delete(line_profile) ;
+        cpl_vector_delete(conv_kernel) ;
+        return NULL ;
+    }
+    cpl_vector_delete(conv_kernel) ;
+    
+    /* Create the correlations values vector */
+    sp_sz = cpl_vector_get_size(spectrum) ;
+    xcorrs = cpl_vector_new(sp_sz) ;
+    cpl_vector_fill(xcorrs, 0.0) ;
+    xc_single = cpl_vector_new(1) ;
+
+    /* Loop on the pixels of the spectrum */
+    for (i=hs ; i<sp_sz-hs ; i++) {
+        /* Extract the current spectrum part */
+        if ((spec_ext = cpl_vector_extract(spectrum, i-hs, i+hs, 1)) == NULL) {
+            cpl_msg_error(cpl_func, "Cannot extract spectrum") ;
+            cpl_vector_delete(xc_single) ;
+            cpl_vector_delete(line_profile) ;
+            return NULL ;
+        }
+        if (cpl_vector_correlate(xc_single, spec_ext, line_profile) < 0) {
+            cpl_msg_error(cpl_func, "Cannot correlate") ;
+            cpl_vector_delete(xc_single) ;
+            cpl_vector_delete(line_profile) ;
+            cpl_vector_delete(spec_ext) ;
+            return NULL ;
+        }
+        cpl_vector_set(xcorrs, i, cpl_vector_get(xc_single, 0)) ;
+        cpl_vector_delete(spec_ext) ;
+    }
+    cpl_vector_delete(xc_single) ;
+    cpl_vector_delete(line_profile) ;
+
+    return xcorrs ;
+} 
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Detect lines in a vector
+  @param    spectrum        The spectrum vector
+  @param    threshold       The threshold for line detection
+  @return   the detected lines or NULL on error
+
+  The returned vector must be deallocated with cpl_vector_delete().
+ */
+/*----------------------------------------------------------------------------*/
+static cpl_vector * irplib_ppm_detect_lines(
+        const cpl_vector    *   spec,
+        double                  threshold)
+{
+    cpl_vector  *   spec_loc ;
+    double      *   pspec_loc ;
+    cpl_vector  *   lines ;
+    double      *   plines ;
+    int             spec_loc_sz, max_ind, nlines ;
+    double          max ;
+    int             i ;
+
+    /* Test inputs */
+    if (spec == NULL) return NULL ;
+
+    /* Local spectrum */
+    spec_loc = cpl_vector_duplicate(spec) ;
+    pspec_loc = cpl_vector_get_data(spec_loc) ;
+    spec_loc_sz = cpl_vector_get_size(spec_loc) ;
+
+    /* Threshold the local spectrum */
+    for (i=0 ; i<spec_loc_sz ; i++) 
+        if (pspec_loc[i] < threshold) pspec_loc[i] = 0.0 ;
+    
+    /* Allocate lines container */
+    lines = cpl_vector_new(spec_loc_sz) ;
+    plines = cpl_vector_get_data(lines) ;
+    nlines = 0 ;
+    
+    /* Loop as long as there are lines */
+    while ((max = cpl_vector_get_max(spec_loc)) > threshold) {
+        /* Find the max position */
+        max_ind = 0 ;
+        while (pspec_loc[max_ind]<max && max_ind<spec_loc_sz) max_ind++ ;
+        if (max_ind == spec_loc_sz) {
+            cpl_msg_error(cpl_func, "Cannot find maximum") ;
+            cpl_vector_delete(spec_loc) ;
+            cpl_vector_delete(lines) ;
+            return NULL ;
+        }
+        if (max_ind == 0 || max_ind == spec_loc_sz-1) {
+            pspec_loc[max_ind] = 0 ;
+            continue ;
+        }
+
+        /* Get the precise position from the neighbours values */
+        plines[nlines] =    pspec_loc[max_ind] * max_ind + 
+                            pspec_loc[max_ind-1] * (max_ind-1) +
+                            pspec_loc[max_ind+1] * (max_ind+1) ; 
+        plines[nlines] /= pspec_loc[max_ind] + pspec_loc[max_ind+1] +
+            pspec_loc[max_ind-1] ;
+        plines[nlines] ++ ;
+        nlines ++ ;
+
+        /* Clean the line */
+        i = max_ind ;
+        while (i>=0 && pspec_loc[i] > threshold) {
+            pspec_loc[i] = 0.0 ;
+            i-- ;
+        }
+        i = max_ind+1 ;
+        while (i<spec_loc_sz && pspec_loc[i] > threshold) {
+            pspec_loc[i] = 0.0 ;
+            i++ ;
+        }
+    }
+    cpl_vector_delete(spec_loc) ;
+   
+    /* Check if there are lines */
+    if (nlines == 0) {
+        cpl_msg_error(cpl_func, "Cannot detect any line") ;
+        cpl_vector_delete(lines) ;
+        return NULL ;
+    }
+    
+    /* Resize the vector */
+    cpl_vector_set_size(lines, nlines) ;
+
+    /* Sort the lines */
+    cpl_vector_sort(lines, 1) ;
+    
+    return lines ;
+}
+
+#endif
diff --git a/irplib/irplib_ppm.h b/irplib/irplib_ppm.h
new file mode 100644
index 0000000..f531d0f
--- /dev/null
+++ b/irplib/irplib_ppm.h
@@ -0,0 +1,40 @@
+/* $Id: irplib_ppm.h,v 1.5 2007/07/23 09:27:07 yjung Exp $
+ *
+ * This file is part of the irplib package
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: yjung $
+ * $Date: 2007/07/23 09:27:07 $
+ * $Revision: 1.5 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifndef IRPLIB_PPM_H
+#define IRPLIB_PPM_H
+
+/*-----------------------------------------------------------------------------
+                                   Includes
+ -----------------------------------------------------------------------------*/
+
+#include <cpl.h>
+
+cpl_polynomial * irplib_ppm_engine(const cpl_vector *, const cpl_bivector *,
+        const cpl_polynomial *, double, double, double, int, int, cpl_table **);
+
+#endif
diff --git a/irplib/irplib_slitpos.c b/irplib/irplib_slitpos.c
new file mode 100644
index 0000000..37d3e63
--- /dev/null
+++ b/irplib/irplib_slitpos.c
@@ -0,0 +1,568 @@
+/* $Id: irplib_slitpos.c,v 1.30 2011/11/23 13:58:45 yjung Exp $
+ *
+ * This file is part of the irplib package
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: yjung $
+ * $Date: 2011/11/23 13:58:45 $
+ * $Revision: 1.30 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+/* The IRPLIB-based application may have checked for the availability of
+   memrchr() in which case the macro HAVE_DECL_MEMRCHR is defined as either
+   0 or 1. Without checks it is assumed that the function is not available.
+   With a suitable version of autoconf the macro can be defined with this
+   entry in configure.ac:
+   AC_CHECK_DECLS([memrchr])
+*/
+
+/*-----------------------------------------------------------------------------
+                                Includes
+ -----------------------------------------------------------------------------*/
+
+#include <string.h>
+#include <math.h>
+#include <assert.h>
+#include <cpl.h>
+
+#include "irplib_slitpos.h"
+#include "irplib_flat.h"
+
+/*-----------------------------------------------------------------------------
+                                Defines
+ -----------------------------------------------------------------------------*/
+
+/* TEMPORARY SUPPORT OF CPL 5.x */
+#ifndef CPL_SIZE_FORMAT
+#define CPL_SIZE_FORMAT "d"
+#define cpl_size int
+#endif
+/* END TEMPORARY SUPPORT OF CPL 5.x */
+
+#ifndef IRPLIB_SLITPOS_KERNEL_SIZE_Y
+#define IRPLIB_SLITPOS_KERNEL_SIZE_Y      5
+#endif
+
+#ifndef IRPLIB_SLITPOS_MAX_EROSION
+#define IRPLIB_SLITPOS_MAX_EROSION     1024
+#endif
+
+/*-----------------------------------------------------------------------------
+                            Functions prototypes
+ -----------------------------------------------------------------------------*/
+
+static cpl_error_code irplib_slitpos_find_edges_one_line(const cpl_image *,
+                                                         int, int *, int *);
+static cpl_error_code irplib_slitpos_find_vert_slit_ends(const cpl_image *,
+                                                         int, int *, int *);
+static cpl_error_code irplib_slitpos_find_vert_pos(const cpl_image *, int,
+                                                   cpl_size *);
+static cpl_error_code irplib_image_filter_background_line(cpl_image *,
+                                                   const cpl_image *,
+                                                   int, cpl_boolean) ;
+
+/*----------------------------------------------------------------------------*/
+/**
+ * @defgroup irplib_slitpos     Functions for slit position
+ */
+/*----------------------------------------------------------------------------*/
+
+/**@{*/
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Detect the slit position, detect its ends, extract a thin image
+            containing only the slit and find its edges
+  @param    imslit          Input image with a vertical slit
+  @param    slit_max_width  Maximum slit width
+  @param    slit_flux       Some of the pixels values of the slit
+  @return   the table with the slit position or NULL on error
+
+  On success the created table contains rows of four columns labeled:
+     "SLIT_Y"      (int)
+     "SLIT_LEFT"   (double)
+     "SLIT_CENTER" (double)
+     "SLIT_RIGHT"  (double)
+
+  This function returns a table with 3 columns:
+
+  - Left or Lower edge of the slit
+  - Center of the slit
+  - Right or Upper edge of the slit
+
+  Additionally, the slit flux is computed. The passed slit_flux pointer
+  parameter can be NULL. In error case, its value is undefined.
+  
+  NB: Coordinates use FITS convention.
+ */
+/*----------------------------------------------------------------------------*/
+cpl_table * irplib_slitpos_analysis(const cpl_image * imslit,
+                                    int               slit_max_width,
+                                    double          * slit_flux)
+{
+    const int       size_x = cpl_image_get_size_x(imslit);
+    const int       size_y = cpl_image_get_size_y(imslit);
+    int             slit_length;
+    cpl_size        slit_pos;
+    cpl_image   *   filtered;
+    cpl_mask    *   mask;
+    cpl_image   *   thin_im;
+    int             slit_top_y = 0; /* Avoid (false) uninit warning */
+    int             slit_bot_y = 0; /* Avoid (false) uninit warning */
+    cpl_table   *   self;
+    double      *   slit_y,
+                *   slit_x_l,
+                *   slit_x_r;
+    double      *   coeff_r;
+    double      *   coeff_l;
+    int             i;
+    cpl_error_code error = CPL_ERROR_NONE;
+
+    /* Initialize */
+    if (slit_flux != NULL) *slit_flux = 0.0 ;
+
+    /* Median vertical filtering 3x3 */
+    mask = cpl_mask_new(3, 3) ;
+    cpl_mask_not(mask) ;
+    filtered = cpl_image_new(size_x, size_y, cpl_image_get_type(imslit));
+    error = cpl_image_filter_mask(filtered, imslit, mask,
+                                  CPL_FILTER_MEDIAN, CPL_BORDER_FILTER);
+    cpl_mask_delete(mask);
+
+    if (error) {
+        cpl_image_delete(filtered);
+        cpl_ensure(0, cpl_error_get_code(), NULL);
+    }
+
+    /* The background may vary strongly along the vertical line. */
+    /* Detect and remove background with a 1+2*Slit_max x 1 median filter */
+    error = irplib_image_filter_background_line(filtered, NULL, slit_max_width,
+                                                CPL_TRUE);
+
+    if (error) {
+        cpl_image_delete(filtered) ;
+        cpl_ensure(0, cpl_error_get_code(), NULL);
+    }
+
+    /* Find the position of the slit */
+    if (irplib_slitpos_find_vert_pos(filtered, slit_max_width/2, &slit_pos)) {
+        cpl_image_delete(filtered);
+        cpl_msg_error(cpl_func, "Could not find the slit position");
+        cpl_ensure(0, cpl_error_get_code(), NULL);
+    }
+
+    /* Extract a thin image containing the slit */
+    thin_im = cpl_image_extract(filtered, slit_pos-slit_max_width/2, 1,
+                                slit_pos+slit_max_width/2, size_y);
+    if (thin_im == NULL) {
+        cpl_msg_error(cpl_func, "Could not extract the %d pixel thin image "
+                      "around position %"CPL_SIZE_FORMAT, 
+                      slit_max_width, slit_pos);
+        cpl_image_delete(filtered);
+        cpl_ensure(0, cpl_error_get_code(), NULL);
+    }
+
+    /* Find the ends of the slit */
+    error = irplib_slitpos_find_vert_slit_ends(thin_im,
+                                               IRPLIB_SLITPOS_KERNEL_SIZE_Y,
+                                               &slit_bot_y,
+                                               &slit_top_y);
+    cpl_image_delete(thin_im);
+    if (error) {
+        cpl_image_delete(filtered);
+        cpl_ensure(0, cpl_error_get_code(), NULL);
+    }
+
+    /* Extract an image with exactly the slit */
+    thin_im = cpl_image_extract(filtered,
+                                slit_pos-slit_max_width/2,
+                                slit_bot_y,
+                                slit_pos+slit_max_width/2,
+                                slit_top_y);
+    cpl_image_delete(filtered);
+
+    cpl_ensure(thin_im != NULL, cpl_error_get_code(), NULL);
+
+    slit_length = 1 + slit_top_y - slit_bot_y;
+
+    /* Allocate some arrays */
+    slit_y = cpl_malloc(slit_length * sizeof(double));
+    slit_x_l = cpl_malloc(slit_length * sizeof(double));
+    slit_x_r = cpl_malloc(slit_length * sizeof(double));
+    
+    /* Find the edges of the slit */
+    for (i=0 ; i<slit_length ; i++) {
+        int right_pos = 0; /* Avoid (false) uninit warning */
+        int left_pos  = 0; /* Avoid (false) uninit warning */
+
+        if (irplib_slitpos_find_edges_one_line(thin_im,
+                                                i,
+                                                &left_pos,
+                                                &right_pos)) {
+            cpl_msg_error(cpl_func, "cannot find the edges of the [%d]th line", 
+                    i+1);
+            cpl_image_delete(thin_im);
+            return NULL;
+        }
+
+        /* Update the slit_flux */
+        if (slit_flux != NULL) {
+            *slit_flux += cpl_image_get_flux_window(thin_im, left_pos+1,
+                    i+1, right_pos+1, i+1) ;
+        }
+        
+        /* Store the edges for the fit */
+        slit_x_l[i] = (double)left_pos;
+        slit_x_r[i] = (double)right_pos;
+        slit_y[i]   = (double)(i+slit_bot_y-1);
+    }
+    cpl_image_delete(thin_im);
+
+    /* Linear regression to find the edges */
+    coeff_l = irplib_flat_fit_slope_robust(slit_y, slit_x_l, slit_length);
+    coeff_r = irplib_flat_fit_slope_robust(slit_y, slit_x_r, slit_length);
+    cpl_free(slit_y);
+    cpl_free(slit_x_l);
+    cpl_free(slit_x_r);
+
+    /* Allocate the table containing the results */
+    self = cpl_table_new(slit_length);
+    error |= cpl_table_new_column(self, "SLIT_Y",      CPL_TYPE_INT);
+    error |= cpl_table_new_column(self, "SLIT_LEFT",   CPL_TYPE_DOUBLE);
+    error |= cpl_table_new_column(self, "SLIT_CENTER", CPL_TYPE_DOUBLE);
+    error |= cpl_table_new_column(self, "SLIT_RIGHT",  CPL_TYPE_DOUBLE);
+
+    error |= cpl_table_set_column_unit(self, "SLIT_Y", "pixel");
+    error |= cpl_table_set_column_unit(self, "SLIT_LEFT", "pixel");
+    error |= cpl_table_set_column_unit(self, "SLIT_CENTER", "pixel");
+    error |= cpl_table_set_column_unit(self, "SLIT_RIGHT", "pixel");
+
+    cpl_ensure(!error, cpl_error_get_code(), NULL);
+
+    /* Rewrite the edges in the out table, and write the center */
+    for (i=0 ; i < slit_length ; i++) {
+        const int    islity = i + slit_bot_y;
+        const double dslit  = slit_pos - slit_max_width / 2.0;
+        const double dleft  = coeff_l[0] + coeff_l[1] * (double)islity + dslit;
+        const double dright = coeff_r[0] + coeff_r[1] * (double)islity + dslit;
+        const double dcent  = 0.5 * (dleft + dright);
+
+        if (cpl_table_set_int(self,    "SLIT_Y",      i, islity)) break;
+        if (cpl_table_set_double(self, "SLIT_LEFT",   i, dleft))  break;
+        if (cpl_table_set_double(self, "SLIT_RIGHT",  i, dright)) break;
+        if (cpl_table_set_double(self, "SLIT_CENTER", i, dcent))  break;
+    }
+
+    cpl_free(coeff_r);
+    cpl_free(coeff_l);
+
+    if (i != slit_length) {
+        cpl_table_delete(self);
+        cpl_ensure(0, cpl_error_get_code(), NULL);
+    }
+
+    return self;
+}
+
+/**@}*/
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Return the first pixel higher than avg starting from the
+            left and from the right of the line 
+  @param    self input image
+  @param    line_pos    line position
+  @param    left_pos    pointer to left position
+  @param    right_pos   pointer to right position
+  @return   0 iff successful
+  
+  Positions in C coordinates (first pixel position is 0)
+ */
+/*----------------------------------------------------------------------------*/
+static cpl_error_code irplib_slitpos_find_edges_one_line(const cpl_image * self,
+                                                         int          line_pos,
+                                                         int        * left_pos,
+                                                         int        * right_pos)
+{
+    const int     size_x = cpl_image_get_size_x(self);
+    const float * pself;
+    double        threshold;
+    int           i;
+
+    cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(cpl_image_get_type(self) == CPL_TYPE_FLOAT,
+                    CPL_ERROR_INVALID_TYPE);
+
+    pself = cpl_image_get_data_float_const(self);
+
+    /* Find the threshold */
+    threshold = cpl_image_get_mean_window(self, 1, line_pos+1, size_x,
+                                          line_pos+1);
+
+    /* Detect the left edge */
+    i = 0;
+    while (i < size_x && pself[line_pos*size_x+i] < threshold) i++;
+    *left_pos = i;
+
+    /* Detect the right edge */
+    i = size_x - 1;
+    while (i >= 0 && pself[line_pos*size_x+i] < threshold) i--;
+    *right_pos = i;
+
+    return CPL_ERROR_NONE;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Find the ends of a vertical slit (y coordinates in FITS convention)
+  @param    in  input image
+  @param    kernel_size vertical kernel size
+  @param    bot_slit_y  bottom slit y position
+  @param    top_slit_y  top slit y position
+  @return   0 iff successful
+  
+  The input image has to be as thin as possible to contain only the slit
+ */
+/*----------------------------------------------------------------------------*/
+static
+cpl_error_code irplib_slitpos_find_vert_slit_ends(const cpl_image * self,
+                                                  int        kernel_size,
+                                                  int      * bot_slit_y,
+                                                  int      * top_slit_y)
+{
+    cpl_mask         * binary;
+    cpl_mask         * copy = NULL;
+    cpl_mask         * kernel;
+    cpl_image        * label_image;
+    int                erosions_nb;
+    cpl_size           nobj ;
+    const int          size_x = cpl_image_get_size_x(self);
+    const int          size_y = cpl_image_get_size_y(self);
+    const int          npix = size_x * size_y;
+    const cpl_binary * pbinary;
+    const cpl_binary * pfind;
+    int                i, itop, ibot;
+
+
+    cpl_ensure_code(size_x      > 0, cpl_error_get_code());
+    cpl_ensure_code(kernel_size > 0, cpl_error_get_code());
+
+    /* Threshold to have a binary image */
+    binary = cpl_mask_threshold_image_create(self, cpl_image_get_mean(self),
+                                             cpl_image_get_max(self));
+    cpl_ensure_code(binary != NULL, cpl_error_get_code());
+
+    /* Erode until there is 1 object left in the image */
+    label_image = cpl_image_labelise_mask_create(binary, &nobj);
+    cpl_image_delete(label_image);
+
+    if (label_image == NULL) {
+        cpl_mask_delete(binary);
+        cpl_ensure_code(0, cpl_error_get_code());
+    }
+
+    /* Define the kernel for morpho operations */
+    kernel = cpl_mask_new(kernel_size, 1);
+    cpl_mask_not(kernel);
+    copy = cpl_mask_wrap(size_x, size_y, cpl_malloc(size_x * size_y *
+                                                    sizeof(cpl_binary)));
+    for (erosions_nb = 0; erosions_nb < IRPLIB_SLITPOS_MAX_EROSION && nobj > 1;
+         erosions_nb++) {
+        /* Should not be possible to break from this loop */
+        cpl_mask_copy(copy, binary, 1, 1);
+        if (cpl_mask_filter(binary, copy, kernel, CPL_FILTER_EROSION,
+                            CPL_BORDER_ZERO)) break;
+
+        label_image = cpl_image_labelise_mask_create(binary, &nobj);
+        if (label_image == NULL) break; /* Assuming nobj was not set to 1 */
+        cpl_image_delete(label_image);
+    }
+
+    if (nobj > 1) {
+        cpl_mask_delete(binary);
+        cpl_mask_delete(copy);
+        cpl_mask_delete(kernel);
+        if (erosions_nb >= IRPLIB_SLITPOS_MAX_EROSION) {
+            cpl_msg_error(cpl_func, "Number of erosions reached a limit of %d "
+                          "with %"CPL_SIZE_FORMAT" possible slits left",
+                          IRPLIB_SLITPOS_MAX_EROSION, nobj);
+            cpl_ensure_code(0, CPL_ERROR_CONTINUE);
+        }
+        cpl_ensure_code(0, cpl_error_get_code());
+    } else if (nobj < 1) {
+        cpl_mask_delete(binary);
+        cpl_mask_delete(copy);
+        cpl_mask_delete(kernel);
+        if (erosions_nb == 0)
+            cpl_msg_error(cpl_func, "No slit could be detected across %d "
+                          "pixels", size_x);
+        else 
+            cpl_msg_error(cpl_func, "The last of %d erosions removed all the "
+                          "possible slits", erosions_nb);
+        cpl_ensure_code(0, CPL_ERROR_DATA_NOT_FOUND);
+    }
+
+    /* Reconstruct the slit with dilations */
+    for (i=0 ; i < erosions_nb ; i++) {
+        cpl_mask_copy(copy, binary, 1, 1);
+        if (cpl_mask_filter(binary, copy, kernel, CPL_FILTER_DILATION,
+                            CPL_BORDER_ZERO)) break;
+    }
+    cpl_mask_delete(copy);
+    cpl_mask_delete(kernel);
+
+    if (i != erosions_nb) {
+        cpl_msg_error(cpl_func, "Dilation number %d out of %d failed",
+                      i, erosions_nb);
+        cpl_mask_delete(binary);
+        cpl_ensure_code(0, cpl_error_get_code());
+    }
+
+    /* Find the ends of the slit */
+    pbinary = cpl_mask_get_data(binary);
+    assert( pbinary != NULL );
+
+    pfind = memchr(pbinary, CPL_BINARY_1, (size_t)npix);
+    assert( pfind != NULL );
+
+    ibot = (int)(pfind - pbinary);
+
+#if defined HAVE_DECL_MEMRCHR && HAVE_DECL_MEMRCHR == 1
+    /* FIXME: Not tested */
+    pfind = memrchr(pfind, CPL_BINARY_1, (size_t)(npix - ibot));
+    assert( pfind != NULL );
+
+    itop = (int)(pfind - pbinary);
+#else
+
+    itop = npix - 1;
+    while (itop > ibot && pbinary[itop] != CPL_BINARY_1) itop--;
+
+#endif
+
+    *bot_slit_y = 1 + ibot / size_x;
+    *top_slit_y = 1 + itop / size_x;
+
+    cpl_msg_info(cpl_func, 
+            "Detected %"CPL_SIZE_FORMAT"-pixel slit from pixel %d to %d "
+            "using %d erosions/dilations", cpl_mask_count(binary),
+            *bot_slit_y, *top_slit_y, erosions_nb);
+
+    cpl_mask_delete(binary);
+
+    /* Should really be an assert() */
+    cpl_ensure_code(ibot <= itop, CPL_ERROR_DATA_NOT_FOUND);
+
+    return CPL_ERROR_NONE;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Find a vertical slit position (x coordinate of the slit)
+  @param    self      Filtered input image
+  @param    xwidth    Width of the boundary to not search (in x)
+  @param    slit_pos  Pointer to the searched position
+  @return   0 iff successful
+  
+  Coordinate given in FITS convention (ll is (1,1))
+ */
+/*----------------------------------------------------------------------------*/
+static cpl_error_code irplib_slitpos_find_vert_pos(const cpl_image * self,
+                                                   int               xwidth,
+                                                   cpl_size        * slit_pos)
+{
+    const int       size_x = cpl_image_get_size_x(self);
+    cpl_image   *   image1D;
+    cpl_size        yone;
+    cpl_error_code  error;
+
+
+    /* Collapse the image to a horizontal 1D image */
+    image1D = cpl_image_collapse_create(self, 0);
+
+    cpl_ensure_code(image1D != NULL, cpl_error_get_code());
+
+    /* Search the max of the 1D image to identify the slit position */
+    error = cpl_image_get_maxpos_window(image1D, 1+xwidth, 1, size_x-xwidth,
+                                        1, slit_pos, &yone);
+
+    cpl_image_delete(image1D);
+
+    cpl_ensure_code(!error, error);
+
+    return CPL_ERROR_NONE;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief  Filter the background of an image with horizontal or vertical lines
+  @param  self    Filtered image
+  @param  other   Image to filter, use NULL for in-place filtering
+  @param  hsize   Filtering half-size, total size is 1 + 2 * hsize
+  @param  vertical True iff the lines are vertical
+  @return CPL_ERROR_NONE or the relevant CPL error code
+
+  If the background varies strongly along the line, it can be detected
+  and removed with a unit width 1+2*hsize median filter, where hsize is an
+  upper bound on the line width.
+
+ */
+/*----------------------------------------------------------------------------*/
+static cpl_error_code irplib_image_filter_background_line(cpl_image * self,
+                                                   const cpl_image * other,
+                                                   int hsize,
+                                                   cpl_boolean vertical)
+{
+    const int      nx = cpl_image_get_size_x(self);
+    const int      ny = cpl_image_get_size_y(self);
+    const int      msize = 1 + 2 * hsize;
+    cpl_mask     * mask;
+    cpl_image    * background;
+    cpl_error_code error = CPL_ERROR_NONE;
+
+    cpl_ensure_code(self  != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(hsize >= 0,    CPL_ERROR_ILLEGAL_INPUT);
+
+    if (other == NULL) other = self;
+
+    mask = vertical ? cpl_mask_new(msize, 1) : cpl_mask_new(1, msize);
+
+    error |= cpl_mask_not(mask);
+
+    background = cpl_image_new(nx, ny, cpl_image_get_type(other));
+
+    error |= cpl_image_filter_mask(background, other, mask, CPL_FILTER_MEDIAN,
+                                   CPL_BORDER_FILTER);
+    cpl_mask_delete(mask);
+
+    if (self != other) {
+        error |= cpl_image_copy(self, other, 1, 1);
+    }
+
+    error |= cpl_image_subtract(self, background);
+    cpl_image_delete(background);
+
+    return error ? cpl_error_set_where(cpl_func) : CPL_ERROR_NONE;
+}
+
+
diff --git a/irplib/irplib_slitpos.h b/irplib/irplib_slitpos.h
new file mode 100644
index 0000000..be63807
--- /dev/null
+++ b/irplib/irplib_slitpos.h
@@ -0,0 +1,39 @@
+/* $Id: irplib_slitpos.h,v 1.6 2006/11/29 13:22:59 yjung Exp $
+ *
+ * This file is part of the irplib package
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: yjung $
+ * $Date: 2006/11/29 13:22:59 $
+ * $Revision: 1.6 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifndef IRPLIB_SLITPOS_H
+#define IRPLIB_SLITPOS_H
+
+/*-----------------------------------------------------------------------------
+                                   Includes
+ -----------------------------------------------------------------------------*/
+
+#include <cpl.h>
+
+cpl_table * irplib_slitpos_analysis(const cpl_image *, int, double *);
+
+#endif
diff --git a/irplib/irplib_spectrum.c b/irplib/irplib_spectrum.c
new file mode 100644
index 0000000..53dae07
--- /dev/null
+++ b/irplib/irplib_spectrum.c
@@ -0,0 +1,606 @@
+/* $Id: irplib_spectrum.c,v 1.29 2012/01/12 11:50:41 llundin Exp $
+ *
+ * This file is part of the irplib package
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: llundin $
+ * $Date: 2012/01/12 11:50:41 $
+ * $Revision: 1.29 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+/*-----------------------------------------------------------------------------
+                                Includes
+ -----------------------------------------------------------------------------*/
+
+#include <math.h>
+#include <float.h>
+#include <cpl.h>
+
+#include "irplib_wlxcorr.h"
+#include "irplib_spectrum.h"
+
+/*-----------------------------------------------------------------------------
+                                   Define
+ -----------------------------------------------------------------------------*/
+
+/* TEMPORARY SUPPORT OF CPL 5.x */
+#ifndef CPL_SIZE_FORMAT
+#define CPL_SIZE_FORMAT "d"
+#define cpl_size int
+#endif
+/* END TEMPORARY SUPPORT OF CPL 5.x */
+
+#define SPECTRUM_HW                     16
+#define MIN_THRESH_FACT                 0.9
+#define MAX_THRESH_FACT                 1.1
+#define SPEC_SHADOW_FACT                30.0 /* Negative spectrum intensity*/
+#define SPEC_MAXWIDTH                   48
+
+/*-----------------------------------------------------------------------------
+                            Functions prototypes
+ -----------------------------------------------------------------------------*/
+
+static int select_valid_spectra(cpl_image *, cpl_apertures *, int,
+        spec_shadows, int, int *, int **) ;
+static int valid_spectrum(cpl_image *, cpl_apertures *, int, spec_shadows, int,
+        int) ;
+
+/*----------------------------------------------------------------------------*/
+/**
+ * @defgroup irplib_spectrum     Functions for LSS spectra
+ */
+/*----------------------------------------------------------------------------*/
+
+/**@{*/
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Finds the brightest spectrum in an image 
+  @param    in                  spectral image with spectra 
+  @param    offset              the diff. between pos. and neg. spectra
+  @param    shadows             the spectral shadows
+  @param    min_bright          min. bright. required for a spectrum
+  @param    orient              1 for vertical spec. 0 for horizontal ones
+  @param    pos                 the computed spectrum position (1->npix)
+  @return   int 0 if ok, -1 in error case 
+
+  Finds the brightest spectrum in an image by collapsing the image orthogonally
+  to the spectrum orientation.
+  Spectra are assumed to be horizontal for orient==0, vertical for 1
+*/
+/*----------------------------------------------------------------------------*/
+int irplib_spectrum_find_brightest(
+        const cpl_image     *   in,
+        int                     offset,
+        spec_shadows            shadows,
+        double                  min_bright,
+        int                     orient,
+        double              *   pos)
+{
+    cpl_image       *   loc_ima ;
+    cpl_image       *   filt_image ;
+    cpl_image       *   collapsed ;
+    float           *   pcollapsed ;
+    cpl_vector      *   line ;
+    double          *   pline ;
+    cpl_vector      *   line_filt ;
+    double              threshold ;
+    double              median, stdev, max, mean ;
+    cpl_mask        *   mask ;
+    cpl_image       *   labels ;
+    cpl_size            nlabels ;
+    cpl_apertures   *   aperts ;
+    int                 n_valid_specs ;
+    int             *   valid_specs ;
+    double              brightness ;
+    int                 i ;
+
+    /* Test entries */
+    if (in == NULL) return -1 ;
+    if (orient!=0 && orient!=1) return -1 ;
+
+    /* Flip the image if necessary */
+    if (orient == 1) {
+        loc_ima = cpl_image_duplicate(in) ;
+        cpl_image_flip(loc_ima, 1) ;
+    } else {
+        loc_ima = cpl_image_duplicate(in) ;
+    }
+
+    /* Median vertical filtering 3x3 */
+    mask = cpl_mask_new(3, 3) ;
+    cpl_mask_not(mask) ;
+    filt_image = cpl_image_new(
+            cpl_image_get_size_x(loc_ima),
+            cpl_image_get_size_y(loc_ima),
+            cpl_image_get_type(loc_ima)) ;
+    if (cpl_image_filter_mask(filt_image, loc_ima, mask,
+                CPL_FILTER_MEDIAN, CPL_BORDER_FILTER) != CPL_ERROR_NONE) {
+        cpl_msg_error(__func__, "Cannot filter the image") ;
+        cpl_mask_delete(mask) ;
+        cpl_image_delete(filt_image) ;
+        return -1 ;
+    }
+    cpl_mask_delete(mask) ;
+    cpl_image_delete(loc_ima) ;
+
+    /* Collapse the image */
+    if ((collapsed = cpl_image_collapse_median_create(filt_image, 1, 0,
+                    0)) == NULL) {
+        cpl_msg_error(cpl_func, "collapsing image: aborting spectrum detection");
+        cpl_image_delete(filt_image) ;
+        return -1 ;
+    }
+    cpl_image_delete(filt_image) ;
+
+    /* Subtract low frequency signal */
+    line = cpl_vector_new_from_image_column(collapsed, 1) ;
+    cpl_image_delete(collapsed) ;
+    line_filt = cpl_vector_filter_median_create(line, SPECTRUM_HW) ;
+    cpl_vector_subtract(line, line_filt) ;
+    cpl_vector_delete(line_filt) ;
+
+    /* Get relevant stats for thresholding */
+    median = cpl_vector_get_median_const(line) ;
+    stdev = cpl_vector_get_stdev(line) ;
+    max = cpl_vector_get_max(line) ;
+    mean = cpl_vector_get_mean(line) ;
+
+    /* Set the threshold */
+    threshold = median + stdev ;
+    if (threshold > MIN_THRESH_FACT * max)  threshold = MIN_THRESH_FACT * max ;
+    if (threshold < MAX_THRESH_FACT * mean) threshold = MAX_THRESH_FACT * mean;
+
+    /* Recreate the image */
+    collapsed = cpl_image_new(1, cpl_vector_get_size(line), CPL_TYPE_FLOAT) ;
+    pcollapsed = cpl_image_get_data_float(collapsed) ;
+    pline = cpl_vector_get_data(line) ;
+    for (i=0 ; i<cpl_vector_get_size(line) ; i++)
+        pcollapsed[i] = (float)pline[i] ;
+    cpl_vector_delete(line) ;
+
+    /* Binarise the image */
+    if ((mask = cpl_mask_threshold_image_create(collapsed, threshold,
+            DBL_MAX)) == NULL) {
+        cpl_msg_error(cpl_func, "cannot binarise") ;
+        cpl_image_delete(collapsed) ;
+        return -1 ;
+    }
+    if (cpl_mask_count(mask) < 1) {
+        cpl_msg_error(cpl_func, "not enough signal to detect spectra") ;
+        cpl_image_delete(collapsed) ;
+        cpl_mask_delete(mask) ;
+        return -1 ;
+    }
+    /* Labelise the different detected apertures */
+    if ((labels = cpl_image_labelise_mask_create(mask, &nlabels))==NULL) {
+        cpl_msg_error(cpl_func, "cannot labelise") ;
+        cpl_image_delete(collapsed) ;
+        cpl_mask_delete(mask) ;
+        return -1 ;
+    }
+    cpl_mask_delete(mask) ;
+
+    /* Create the detected apertures list */
+    if ((aperts = cpl_apertures_new_from_image(collapsed, labels)) == NULL) {
+        cpl_msg_error(cpl_func, "cannot compute apertures") ;
+        cpl_image_delete(collapsed) ;
+        cpl_image_delete(labels) ;
+        return -1 ;
+    }
+    cpl_image_delete(labels) ;
+
+    /* Select only relevant specs, create corresponding LUT's */
+    if (select_valid_spectra(collapsed, aperts, offset, shadows, SPEC_MAXWIDTH,
+                &n_valid_specs, &valid_specs) == -1) {
+        cpl_msg_debug(cpl_func, 
+                "Could not select valid spectra from the %"CPL_SIZE_FORMAT
+                " apertures in %"CPL_SIZE_FORMAT"-col 1D-image, offset=%d"
+                ", min_bright=%d",
+                      cpl_apertures_get_size(aperts),
+                      cpl_image_get_size_y(collapsed), offset, SPEC_MAXWIDTH);
+        if (cpl_msg_get_level() <= CPL_MSG_DEBUG)
+            cpl_apertures_dump(aperts, stderr);
+        cpl_image_delete(collapsed);
+        cpl_apertures_delete(aperts);
+        return -1;
+    }
+    cpl_image_delete(collapsed) ;
+    if (n_valid_specs < 1) {
+        cpl_msg_error(cpl_func, "no valid spectrum detected") ;
+        cpl_free(valid_specs) ;
+        cpl_apertures_delete(aperts) ;
+        return -1 ;
+    }
+
+    /* Look for the brightest, among the detected spectra */
+    *pos = cpl_apertures_get_centroid_y(aperts, valid_specs[0]+1) ;
+    brightness = cpl_apertures_get_flux(aperts, valid_specs[0]+1) ;
+    for (i=0 ; i<n_valid_specs ; i++) {
+        if (cpl_apertures_get_flux(aperts, valid_specs[i]+1) > brightness) {
+            *pos = cpl_apertures_get_centroid_y(aperts, valid_specs[i]+1) ;
+            brightness = cpl_apertures_get_flux(aperts, valid_specs[i]+1) ;
+        }
+    }
+    cpl_apertures_delete(aperts) ;
+    cpl_free(valid_specs) ;
+
+    /* Minimum brightness required */
+    if (brightness < min_bright) {
+        cpl_msg_error(cpl_func, "brightness %f too low <%f", brightness,
+                min_bright) ;
+        return -1 ;
+    }
+
+    /* Return */
+    return 0 ;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Detect the brightest features in a spectrum
+  @param    in      the spectrum
+  @param    fwhm    the FWHM used for the lines convolution
+  @param    display the flag to display
+  @param    fwhms   the fwhms of the detected lines
+  @param    areas   the areas under the detected lines
+  @return   The bright lines positions or NULL in error case
+
+  The lines positions are in pixels (first pixel is 1)
+ */
+/*----------------------------------------------------------------------------*/
+cpl_vector * irplib_spectrum_detect_peaks(
+        const cpl_vector    *   in,
+        int                     fwhm,
+        double                  sigma,
+        int                     display,
+        cpl_vector          **  fwhms_out,
+        cpl_vector          **  areas_out)
+{
+    cpl_vector      *   filtered ;
+    cpl_vector      *   spec_clean ;
+    cpl_vector      *   spec_convolved ;
+    double          *   pspec_convolved ;
+    int                 filt_size ;
+    cpl_vector      *   conv_kernel ;
+    cpl_vector      *   extract ;
+    cpl_vector      *   extract_x ;
+    cpl_vector      *   big_detected ;
+    cpl_vector      *   big_fwhms ;
+    cpl_vector      *   big_area ;
+    double          *   pbig_detected ;
+    double          *   pbig_fwhms ;
+    double          *   pbig_area ;
+    cpl_vector      *   detected ;
+    double          *   pdetected ;
+    cpl_vector      *   fwhms ;
+    double          *   pfwhms ;
+    cpl_vector      *   area ;
+    double          *   parea ;
+    double              max, med, stdev, cur_val ;
+    double              x0, sig, norm, offset ;
+    int                 nb_det, nb_samples, hwidth, start, stop ;
+    int                 i, j ;
+
+    /* Test entries */
+    if (in == NULL) return NULL ;
+
+    /* Initialise */
+    nb_samples = cpl_vector_get_size(in) ;
+    filt_size = 5 ;
+    hwidth = 5 ;
+
+    /* Subtract the low frequency part */
+    cpl_msg_info(__func__, "Low Frequency signal removal") ;
+    if ((filtered=cpl_vector_filter_median_create(in, filt_size))==NULL){
+        cpl_msg_error(__func__, "Cannot filter the spectrum") ;
+        return NULL ;
+    }
+    spec_clean = cpl_vector_duplicate(in) ;
+    cpl_vector_subtract(spec_clean, filtered) ;
+    cpl_vector_delete(filtered) ;
+
+    /* Display if requested */
+    if (display) {
+        cpl_plot_vector(
+    "set grid;set xlabel 'Position (pixels)';set ylabel 'Intensity (ADU)';",
+        "t 'Filtered extracted spectrum' w lines", "", spec_clean);
+    }
+
+    /* Convolve */
+    spec_convolved = cpl_vector_duplicate(spec_clean) ;
+    if (fwhm > 0) {
+        cpl_msg_info(__func__, "Spectrum convolution") ;
+        /* Create convolution kernel */
+        if ((conv_kernel = irplib_wlxcorr_convolve_create_kernel(fwhm,
+                        fwhm)) == NULL) {
+            cpl_msg_error(cpl_func, "Cannot create convolution kernel") ;
+            cpl_vector_delete(spec_clean) ;
+            cpl_vector_delete(spec_convolved) ;
+            return NULL ;
+        }
+
+        /* Smooth the instrument resolution */
+        if (irplib_wlxcorr_convolve(spec_convolved, conv_kernel)) {
+            cpl_msg_error(cpl_func, "Cannot smoothe the signal");
+            cpl_vector_delete(spec_clean) ;
+            cpl_vector_delete(spec_convolved) ;
+            cpl_vector_delete(conv_kernel) ;
+            return NULL ;
+        }
+        cpl_vector_delete(conv_kernel) ;
+
+        /* Display if requested */
+        if (display) {
+            cpl_plot_vector(
+        "set grid;set xlabel 'Position (pixels)';set ylabel 'Intensity (ADU)';",
+            "t 'Convolved extracted spectrum' w lines", "", spec_convolved);
+        }
+    }
+
+    /* Apply the detection */
+    big_detected = cpl_vector_duplicate(spec_convolved) ;
+    big_fwhms = cpl_vector_duplicate(spec_convolved) ;
+    big_area = cpl_vector_duplicate(spec_convolved) ;
+    pbig_detected = cpl_vector_get_data(big_detected) ;
+    pbig_fwhms = cpl_vector_get_data(big_fwhms) ;
+    pbig_area = cpl_vector_get_data(big_area) ;
+    
+    pspec_convolved = cpl_vector_get_data(spec_convolved) ;
+
+    /* To avoid detection on the side */
+    pspec_convolved[0] = pspec_convolved[nb_samples-1] = 0.0 ;
+
+    /* Compute stats */
+    max     =   cpl_vector_get_max(spec_convolved) ;
+    stdev   =   cpl_vector_get_stdev(spec_convolved) ;
+    med     =   cpl_vector_get_median_const(spec_convolved) ;
+
+    /* Loop on the detected lines */
+    nb_det = 0 ;
+    while (max > med + stdev * sigma) {
+        /* Compute the position */
+        i=0 ;
+        while (pspec_convolved[i] < max) i++ ;
+        if (i<=0 || i>=nb_samples-1) break ;
+
+        /* Extract the line */
+        if (i - hwidth >= 0)                start = i - hwidth ;
+        else                                start = 0 ;
+        if (i + hwidth <= nb_samples-1)     stop = i + hwidth ;
+        else                                stop = nb_samples-1 ;
+        extract = cpl_vector_extract(spec_clean, start, stop, 1) ;
+        extract_x = cpl_vector_duplicate(extract) ;
+        for (j=0 ; j<cpl_vector_get_size(extract_x) ; j++) {
+            cpl_vector_set(extract_x, j, (double)j+1) ;
+        }
+        /* Fit the gaussian */
+        if (cpl_vector_fit_gaussian(extract_x, NULL, extract, NULL, 
+                    CPL_FIT_ALL, &x0, &sig, &norm, &offset, NULL, NULL, 
+                    NULL) != CPL_ERROR_NONE) {
+            cpl_msg_warning(__func__, 
+                    "Cannot fit a gaussian at [%d, %d]",
+                    start, stop) ;
+            cpl_error_reset() ;
+        } else {
+            pbig_detected[nb_det] = x0+start ;
+            pbig_area[nb_det] = norm ;
+            pbig_fwhms[nb_det] = 2*sig*sqrt(2*log(2)) ;
+            cpl_msg_debug(__func__, "Line nb %d at position %g",
+                    nb_det+1, pbig_detected[nb_det]) ;
+            nb_det ++ ;
+        }
+        cpl_vector_delete(extract) ;
+        cpl_vector_delete(extract_x) ;
+
+        /* Cancel out the line on the left */
+        j = i-1 ;
+        cur_val = pspec_convolved[i] ;
+        while (j>=0 && pspec_convolved[j] < cur_val) {
+            cur_val = pspec_convolved[j] ;
+            pspec_convolved[j] = 0.0 ;
+            j-- ;
+        }
+        /* Cancel out the line on the right */
+        j = i+1 ;
+        cur_val = pspec_convolved[i] ;
+        while (j<=nb_samples-1 && pspec_convolved[j] < cur_val) {
+            cur_val = pspec_convolved[j] ;
+            pspec_convolved[j] = 0.0 ;
+            j++ ;
+        }
+        /* Cancel out the line on center */
+        pspec_convolved[i] = 0.0 ;
+
+        /* Recompute the stats */
+        max     =   cpl_vector_get_max(spec_convolved) ;
+        stdev   =   cpl_vector_get_stdev(spec_convolved) ;
+        med     =   cpl_vector_get_median_const(spec_convolved) ;
+    }
+    cpl_vector_delete(spec_convolved) ;
+    cpl_vector_delete(spec_clean) ;
+
+    /* Create the output vector */
+    if (nb_det == 0) {
+        detected = NULL ;
+        area = NULL ;
+        fwhms = NULL ;
+    } else {
+        detected = cpl_vector_new(nb_det) ;
+        area = cpl_vector_new(nb_det) ;
+        fwhms = cpl_vector_new(nb_det) ;
+        pdetected = cpl_vector_get_data(detected) ;
+        parea = cpl_vector_get_data(area) ;
+        pfwhms = cpl_vector_get_data(fwhms) ;
+        for (i=0 ; i<nb_det ; i++) {
+            pdetected[i] = pbig_detected[i] ;
+            parea[i] = pbig_area[i] ;
+            pfwhms[i] = pbig_fwhms[i] ;
+        }
+    }
+    cpl_vector_delete(big_detected) ;
+    cpl_vector_delete(big_area) ;
+    cpl_vector_delete(big_fwhms) ;
+
+    /* Return  */
+    if (fwhms_out == NULL)  cpl_vector_delete(fwhms) ;
+    else                    *fwhms_out = fwhms ;
+    if (areas_out == NULL)  cpl_vector_delete(area) ;
+    else                    *areas_out = area ;
+    return detected ;
+}
+
+/**@}*/
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Selects the valid spectra in a spectral image
+  @param    in          the 1d image
+  @param    aperts      detected objects
+  @param    offset      the distance to the two shadows of the bright spectrum
+  @param    shadows     shadows mode
+  @param    max_spec_width  maximal spectrum width
+  @param    n_valid_specs   number of valid spectra
+  @param    valid_specs     lut giving the object number of a found spectrum
+  @return   0 if ok, -1 in error case
+*/
+/*----------------------------------------------------------------------------*/
+static int select_valid_spectra(
+        cpl_image       *   in,
+        cpl_apertures   *   aperts,
+        int                 offset,
+        spec_shadows        shadows,
+        int                 max_spec_width,
+        int             *   n_valid_specs,
+        int             **  valid_specs)
+{
+    int                 nb_aperts ;
+    int                 i, j ;
+
+    /* Initialise */
+    *valid_specs = NULL ;
+    nb_aperts = cpl_apertures_get_size(aperts) ;
+    *n_valid_specs = 0 ;
+
+    /* Test entries */
+    if (nb_aperts < 1) return -1 ;
+
+    /* Count nb of valid specs */
+    j = 0 ;
+    for (i=0 ; i<nb_aperts ; i++)
+        if (valid_spectrum(in, aperts, offset, shadows, max_spec_width,
+                    i+1)) (*n_valid_specs)++ ;
+
+    /* Associate to each spectrum, its object number */
+    if (*n_valid_specs) {
+        *valid_specs = cpl_calloc(*n_valid_specs, sizeof(int)) ;
+        j = 0 ;
+        for (i=0 ; i<nb_aperts ; i++)
+            if (valid_spectrum(in, aperts, offset, shadows, max_spec_width,
+                        i+1)) {
+                (*valid_specs)[j] = i ;
+                j++ ;
+            }
+    } else return -1 ;
+
+    return 0 ;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Helper function to select_valid_spectra 
+  @param    in          the 1d image
+  @param    aperts      detected objects
+  @param    offset      the distance to the two shadows of the bright spectrum
+  @param    shadows     shadows mode
+  @param    max_spec_width  maximal spectrum width
+  @param    objnum      index of the object to test (1 for the first)
+  @return   1 if valid 0 if not
+*/
+/*----------------------------------------------------------------------------*/
+static int valid_spectrum(
+        cpl_image       *   in,
+        cpl_apertures   *   aperts,
+        int                 offset,
+        spec_shadows        shadows,
+        int                 max_spec_width,
+        int                 objnum)
+{
+    int                 objwidth ;
+    double              valover, valunder, valcenter ;
+
+    /* Find objwidth */
+    objwidth = cpl_apertures_get_top(aperts, objnum) -
+        cpl_apertures_get_bottom(aperts, objnum) + 1 ;
+    if (objwidth > max_spec_width) {
+        cpl_msg_error(cpl_func, "object is too wide") ;
+        return 0 ;
+    }
+
+    /* Object is too small */
+    if (cpl_apertures_get_npix(aperts, objnum) < 2) return 0 ;
+
+    /* no shadow required */
+    if (shadows == NO_SHADOW) return 1 ;
+
+    /* Get the median of the object (valcenter) */
+    valcenter = cpl_apertures_get_median(aperts, objnum) ;
+
+    /* Get the black shadows medians (valunder and valover) */
+    if (cpl_apertures_get_bottom(aperts, objnum) - offset < 1) valunder = 0.0 ;
+    else valunder = cpl_image_get_median_window(in, 1,
+            cpl_apertures_get_bottom(aperts, objnum) - offset, 1, 
+            cpl_apertures_get_top(aperts, objnum) - offset) ;
+    
+    if (cpl_apertures_get_top(aperts, objnum) + offset > 1024) valover = 0.0 ;
+    else valover = cpl_image_get_median_window(in, 1,
+            cpl_apertures_get_bottom(aperts, objnum) + offset, 1, 
+            cpl_apertures_get_top(aperts, objnum) + offset) ;
+
+    switch (shadows) {
+        case TWO_SHADOWS:
+        if ((valunder < -fabs(valcenter/SPEC_SHADOW_FACT)) &&
+            (valover < -fabs(valcenter/SPEC_SHADOW_FACT))    &&
+            (valunder/valover > 0.5) &&
+            (valunder/valover < 2.0)) return 1 ;
+        break;
+
+        case ONE_SHADOW:
+        if ((valunder < -fabs(valcenter/SPEC_SHADOW_FACT)) ||
+            (valover < -fabs(valcenter/SPEC_SHADOW_FACT))) return 1 ;
+        break;
+
+        case NO_SHADOW:
+        return 1 ;
+
+        default:
+        cpl_msg_error(cpl_func, "unknown spec_detect_mode") ;
+        break ;
+    }
+
+    cpl_msg_debug(cpl_func, "No spectrum(%d): under=%g, center=%g, over=%g",
+                  shadows, valunder, valcenter, valover);
+
+    return 0 ;
+}
diff --git a/irplib/irplib_spectrum.h b/irplib/irplib_spectrum.h
new file mode 100644
index 0000000..6babc08
--- /dev/null
+++ b/irplib/irplib_spectrum.h
@@ -0,0 +1,59 @@
+/* $Id: irplib_spectrum.h,v 1.7 2009/07/30 12:38:37 yjung Exp $
+ *
+ * This file is part of the irplib package
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: yjung $
+ * $Date: 2009/07/30 12:38:37 $
+ * $Revision: 1.7 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifndef IRPLIB_SPECTRUM_H
+#define IRPLIB_SPECTRUM_H
+
+/*-----------------------------------------------------------------------------
+                                   Includes
+ -----------------------------------------------------------------------------*/
+
+#include <cpl.h>
+
+/*-----------------------------------------------------------------------------
+                                New types
+ -----------------------------------------------------------------------------*/
+
+typedef enum SPEC_SHADOWS {
+    /* 2 shadows above and below true spectrum */
+    TWO_SHADOWS,
+    /* 1 shadow at specified distance from spectrum */
+    ONE_SHADOW,
+    /* Do not search for shadow */
+    NO_SHADOW
+} spec_shadows ;
+
+/*-----------------------------------------------------------------------------
+                                Prototypes
+ -----------------------------------------------------------------------------*/
+
+int irplib_spectrum_find_brightest(const cpl_image *, int, spec_shadows, 
+        double, int, double *) ;
+cpl_vector * irplib_spectrum_detect_peaks(const cpl_vector *, int,
+        double, int, cpl_vector **, cpl_vector **) ;
+
+#endif
diff --git a/irplib/irplib_stdstar.c b/irplib/irplib_stdstar.c
new file mode 100644
index 0000000..b051659
--- /dev/null
+++ b/irplib/irplib_stdstar.c
@@ -0,0 +1,823 @@
+/* $Id: irplib_stdstar.c,v 1.41 2012/05/04 13:58:12 cgarcia Exp $
+ *
+ * This file is part of the irplib package
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: cgarcia $
+ * $Date: 2012/05/04 13:58:12 $
+ * $Revision: 1.41 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+/*-----------------------------------------------------------------------------
+                                   Includes
+ -----------------------------------------------------------------------------*/
+
+#include <string.h>
+#include <math.h>
+#include <float.h>
+
+#include <cpl.h>
+
+#include "irplib_stdstar.h"
+#include "irplib_utils.h"
+#include "irplib_wcs.h"
+
+
+/*----------------------------------------------------------------------------*/
+/**
+ * @defgroup irplib_stdstar     Functions for standard stars
+ */
+/*----------------------------------------------------------------------------*/
+/**@{*/
+
+/*-----------------------------------------------------------------------------
+                                   Functions code
+ -----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Write the ASCII catalogs as FITS files
+  @param    set_in          Input frameset wher the product is registered
+  @param    set_raw         Set of ASCII catalogs
+  @param    recipe_name     Recipe name
+  @param    pro_cat         PRO.CATG
+  @param    pro_type        PRO.TYPE
+  @param    package_name    Usually PACKAGE "/" PACKAGE_VERSION
+  @param    ins_name        Instrument name
+  @param    convert_ascii_table Conversion function
+  @return   0 if ok, -1 in error case
+
+  Every catalog will be written in a different extension, where EXTNAME
+  is the name of the catalog ASCII file name.
+ 
+  The conversion ascii -> cpl_table is done by convert_ascii_table() and
+  should be defined in each instrument
+ */
+/*----------------------------------------------------------------------------*/
+int irplib_stdstar_write_catalogs(
+        cpl_frameset        *   set_in,
+        const cpl_frameset  *   set_raw,
+        const char          *   recipe_name,
+        const char          *   pro_cat,
+        const char          *   pro_type,
+        const char          *   package_name,
+        const char          *   ins_name,
+        cpl_table * (*convert_ascii_table)(const char *))
+{
+    cpl_table           *   out ;
+    cpl_propertylist    *   plist ;
+    cpl_propertylist    *   plist_ext ;
+    cpl_parameterlist   *   parlist ;
+    const char          *   cat_name ;
+    char                *   out_name ;
+    int                     nb_catalogs ;
+    const cpl_frame     *   cur_frame ;
+    int                     i ;
+
+    /* Check entries */
+    if (set_in == NULL) return CPL_ERROR_NULL_INPUT;
+    if (set_raw == NULL) return CPL_ERROR_NULL_INPUT;
+    if (recipe_name == NULL) return CPL_ERROR_NULL_INPUT;
+    if (pro_cat == NULL) return CPL_ERROR_NULL_INPUT;
+    if (ins_name == NULL) return CPL_ERROR_NULL_INPUT;
+
+    /* Define the file name */
+    out_name = cpl_sprintf("%s.fits", recipe_name) ;
+    
+    /* Number of catalogs */
+    nb_catalogs = cpl_frameset_get_size(set_raw) ;
+
+    /* Get the catalog name */
+    cur_frame = cpl_frameset_get_frame_const(set_raw, 0) ;
+    cat_name = cpl_frame_get_filename(cur_frame) ;
+    
+    /* Create the output table */
+    if ((out = convert_ascii_table(cat_name)) == NULL) {
+        cpl_free(out_name) ;
+        return CPL_ERROR_UNSPECIFIED;
+    }
+
+    /* Some keywords  */
+    plist = cpl_propertylist_new() ;
+    cpl_propertylist_append_string(plist, "INSTRUME", ins_name) ;
+    cpl_propertylist_append_string(plist, CPL_DFS_PRO_CATG, pro_cat) ;
+    if (pro_type != NULL) {
+        cpl_propertylist_append_string(plist, CPL_DFS_PRO_TYPE, pro_type) ;
+    }
+    plist_ext = cpl_propertylist_new() ;
+    cpl_propertylist_append_string(plist_ext, "EXTNAME", cat_name) ;
+
+    /* Write the table */
+    parlist = cpl_parameterlist_new() ;
+    cpl_dfs_save_table(set_in, 
+            NULL,
+            parlist,
+            set_raw,
+            NULL,
+            out,
+            plist_ext,
+            recipe_name,
+            plist,
+            NULL,
+            package_name,
+            out_name) ;
+    cpl_parameterlist_delete(parlist) ;
+    cpl_propertylist_delete(plist) ;
+    cpl_propertylist_delete(plist_ext) ;
+    cpl_table_delete(out) ;
+    
+    /* Append the next catalogs */
+    for (i=1 ; i<nb_catalogs ; i++) {
+        /* Get the catalog name */
+        cur_frame = cpl_frameset_get_frame_const(set_raw, i) ;
+        cat_name = cpl_frame_get_filename(cur_frame) ;
+     
+        /* Create the output table */
+        if ((out = convert_ascii_table(cat_name)) == NULL) {
+            cpl_free(out_name) ;
+            return CPL_ERROR_UNSPECIFIED;
+        }
+
+        plist_ext = cpl_propertylist_new() ;
+        cpl_propertylist_append_string(plist_ext, "EXTNAME", cat_name) ;
+        cpl_table_save(out, NULL, plist_ext, out_name, CPL_IO_EXTEND) ;
+        cpl_table_delete(out) ;
+        cpl_propertylist_delete(plist_ext) ;
+    }
+    cpl_free(out_name) ;
+    return 0 ;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Load the FITS catalog in a table
+  @param    filename    Name of the FITS catalog
+  @param    ext_name    Name of the catalog or "all"
+  @return   The newly allocated table orNULL in error case.
+
+  The table is loaded from the specified extension.
+  If "all" is specified, all extension with the same columns as the
+  first one are loaded and put together in the returned table.
+  
+  The returned table must be de allocated with cpl_table_delete().
+ */
+/*----------------------------------------------------------------------------*/
+cpl_table * irplib_stdstar_load_catalog(
+        const char  *   filename, 
+        const char  *   ext_name)
+{
+    int                     next ;
+    cpl_propertylist    *   plist ;
+    const char          *   cur_name ;
+    cpl_table           *   out ;
+    cpl_table           *   out_cur ;
+    cpl_frame           *   cur_frame ;
+    int                     i ;
+
+    /* Check entries */
+    if (filename == NULL) return NULL ;
+    if (ext_name == NULL) return NULL ;
+    
+    /* Initialise */
+    out = NULL ;
+    
+    /* Get the number of extensions in the catalog */
+    cur_frame = cpl_frame_new() ;
+    cpl_frame_set_filename(cur_frame, filename) ;
+    next = cpl_frame_get_nextensions(cur_frame) ;
+    cpl_frame_delete(cur_frame) ;
+
+    /* Loop on the extentions */
+    for (i=0 ; i<next ; i++) {
+        /* Check the name of the current extension */
+        if ((plist = cpl_propertylist_load_regexp(filename, i+1, "EXTNAME", 
+                        0)) == NULL) {
+            cpl_msg_error(cpl_func, "Cannot load header of %d th extension",
+                    i+1);
+            return NULL ;
+        }
+        cur_name = cpl_propertylist_get_string(plist, "EXTNAME") ;
+        
+        /* Check the current extension */
+        if (!strcmp(cur_name, ext_name)) {
+            /* Load the table */
+            if (out == NULL) {
+                out = cpl_table_load(filename, i+1, 1) ;
+                cpl_table_new_column(out, IRPLIB_STDSTAR_CAT_COL, CPL_TYPE_STRING);
+                cpl_table_fill_column_window_string(out, IRPLIB_STDSTAR_CAT_COL,
+                                                    0, cpl_table_get_nrow(out),
+                                                    cur_name);
+                if (out == NULL) {
+                    cpl_msg_error(cpl_func, "Cannot load extension %d", i+1) ;
+                    cpl_propertylist_delete(plist) ;
+                    return NULL ;
+                }
+            }
+        } else if (!strcmp(ext_name, "all")) {
+            /* Load the table and append it */
+            if (i==0) {
+                /* Load the first table */
+                out = cpl_table_load(filename, i+1, 1) ;
+                cpl_table_new_column(out, IRPLIB_STDSTAR_CAT_COL, CPL_TYPE_STRING);
+                cpl_table_fill_column_window_string(out, IRPLIB_STDSTAR_CAT_COL,
+                                                    0, cpl_table_get_nrow(out),
+                                                    cur_name);
+                if (out == NULL) {
+                    cpl_msg_error(cpl_func, "Cannot load extension %d", i+1) ;
+                    cpl_propertylist_delete(plist) ; 
+                    return NULL ;
+                }
+            } else {
+                /* Load the current table */
+                out_cur = cpl_table_load(filename, i+1, 1) ;
+                if (out_cur == NULL) {
+                    cpl_msg_error(cpl_func, "Cannot load extension %d", i+1) ;
+                    cpl_table_delete(out) ;
+                    cpl_propertylist_delete(plist) ; 
+                    return NULL ;
+                }
+                cpl_table_new_column(out_cur, IRPLIB_STDSTAR_CAT_COL, CPL_TYPE_STRING);
+                cpl_table_fill_column_window_string(out_cur, IRPLIB_STDSTAR_CAT_COL,
+                                                    0, cpl_table_get_nrow(out_cur),
+                                                    cur_name);
+                /* Append the table */
+                if (cpl_table_insert(out, out_cur, 
+                            cpl_table_get_nrow(out)) != CPL_ERROR_NONE) {
+                    cpl_msg_error(cpl_func, "Cannot merge table %d", i+1) ;
+                    cpl_table_delete(out) ;
+                    cpl_table_delete(out_cur) ;
+                    cpl_propertylist_delete(plist) ; 
+                    return NULL ;
+                }
+                cpl_table_delete(out_cur) ;
+            }
+        }
+        cpl_propertylist_delete(plist) ;
+    }
+    return out ;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Check that the table has the relevant columns of a stdstar table
+  @param    catal    Table with the catalogue
+  @return   CPL_ERROR_NONE if the table has all the mandatory columns, 
+            a proper error code otherwise 
+
+  The table is checked for the presence of the mandatory keywords
+ */
+/*----------------------------------------------------------------------------*/
+cpl_error_code irplib_stdstar_check_columns_exist(
+        const cpl_table  *   catal)
+{
+    /* Check for all the mandatory columns */
+    if (!cpl_table_has_column(catal, IRPLIB_STDSTAR_STAR_COL)) {
+        return cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
+                "Missing column: %s",
+                IRPLIB_STDSTAR_STAR_COL);
+    }
+    if (!cpl_table_has_column(catal, IRPLIB_STDSTAR_TYPE_COL)) {
+        return cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
+                "Missing column: %s",
+                IRPLIB_STDSTAR_TYPE_COL);
+    }
+    if (!cpl_table_has_column(catal, IRPLIB_STDSTAR_CAT_COL)) {
+        return cpl_error_set_message(cpl_func, 
+                CPL_ERROR_ILLEGAL_INPUT,
+                "Missing column: %s",
+                IRPLIB_STDSTAR_CAT_COL);
+    }
+    if (!cpl_table_has_column(catal, IRPLIB_STDSTAR_RA_COL)) {
+        return cpl_error_set_message(cpl_func, 
+                CPL_ERROR_ILLEGAL_INPUT,
+                "Missing column: %s",
+                IRPLIB_STDSTAR_RA_COL);
+    }
+    if (!cpl_table_has_column(catal, IRPLIB_STDSTAR_DEC_COL)) {
+        return cpl_error_set_message(cpl_func, 
+                CPL_ERROR_ILLEGAL_INPUT,
+                "Missing column: %s",
+                IRPLIB_STDSTAR_DEC_COL);
+    }
+    return CPL_ERROR_NONE;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Select the stars that are within a given distance
+  @param    cat     the catalog
+  @param    ra      RA pos
+  @param    dec     DEC pos
+  @param    dist    the distancw
+  @return   0 if ok, -1 in error case
+
+  The stars that are within not further than dist from ra,dec are
+  selected in the table.
+ */
+/*----------------------------------------------------------------------------*/
+int irplib_stdstar_select_stars_dist(
+        cpl_table   *   cat, 
+        double          ra, 
+        double          dec, 
+        double          dist)
+{
+    double              distance ;
+    int                 nrows ;
+    int                 i ;
+    
+    /* Check entries */
+    if (cat == NULL) return -1;
+
+    /* Get the number of selected rows */
+    nrows = cpl_table_get_nrow(cat) ;
+    
+    /* Check if the columns are there */
+    if (!cpl_table_has_column(cat, IRPLIB_STDSTAR_RA_COL)) {
+        cpl_msg_error(cpl_func, "Missing %s column", IRPLIB_STDSTAR_RA_COL) ;
+        return -1 ;
+    }
+    if (!cpl_table_has_column(cat, IRPLIB_STDSTAR_DEC_COL)) {
+        cpl_msg_error(cpl_func, "Missing %s column", IRPLIB_STDSTAR_DEC_COL) ;
+        return -1 ;
+    }
+    
+    /* Compute distances of the selected rows */
+    for (i=0 ; i<nrows ; i++) {
+        if (cpl_table_is_selected(cat, i)) {
+            /* The row is selected - compute the distance */
+            distance = irplib_wcs_great_circle_dist(ra, dec, 
+                    cpl_table_get_double(cat, IRPLIB_STDSTAR_RA_COL, i, NULL),
+                    cpl_table_get_double(cat, IRPLIB_STDSTAR_DEC_COL, i, NULL));            
+            if (distance > dist) cpl_table_unselect_row(cat, i) ;
+        }
+    }
+    return 0;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Select the stars that have a known magnitude
+  @param    cat         the catalog
+  @param    mag_colname the column name with the searched magnitude
+  @return   0 if ok, -1 in error case
+
+  The stars whose magnitude in the mag band is known are selected in the table.
+ */
+/*----------------------------------------------------------------------------*/
+int irplib_stdstar_select_stars_mag(
+        cpl_table   *   cat, 
+        const char  *   mag_colname)
+{
+    /* Check entries */
+    if (cat == NULL) return -1 ;
+    if (mag_colname == NULL) return -1 ;
+
+    /* Check that the table has the mag column */
+    if (!cpl_table_has_column(cat, mag_colname)) {
+        cpl_msg_error(cpl_func, "Column %s does not exist in the catalog",
+                mag_colname) ;
+        return -1 ;
+    }
+
+    /* Apply the selection */
+    if (cpl_table_and_selected_double(cat, mag_colname, CPL_NOT_GREATER_THAN, 
+                98.0) <= 0) {
+        cpl_msg_error(cpl_func, "Column %s does not exist in the catalog",
+                mag_colname) ;
+        return -1 ;
+    }
+    return 0 ;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Find the closest star
+  @param    cat     the catalog
+  @param    ra      RA pos
+  @param    dec     DEC pos
+  @return   the index of the star in the table or -1 in error case
+  
+  Returns the index of the star that is closest to (ra,dec)
+ */
+/*----------------------------------------------------------------------------*/
+int irplib_stdstar_find_closest(
+        const cpl_table     *   cat, 
+        double                  ra, 
+        double                  dec)
+{
+    double              min_dist, distance ;
+    int                 nrows ;
+    int                 ind ;
+    int                 i ;
+
+    /* Check entries */
+    if (cat == NULL) return -1 ;
+
+    /* Initialize */
+    min_dist = 1000.0 ;
+    ind = -1 ;
+
+    /* Get the number of selected rows */
+    nrows = cpl_table_get_nrow(cat) ;
+
+    /* Check if the columns are there */
+    if (!cpl_table_has_column(cat, IRPLIB_STDSTAR_RA_COL)) {
+        cpl_msg_error(cpl_func, "Missing %s column", IRPLIB_STDSTAR_RA_COL) ;
+        return -1 ;
+    }
+    if (!cpl_table_has_column(cat, IRPLIB_STDSTAR_DEC_COL)) {
+        cpl_msg_error(cpl_func, "Missing %s column", IRPLIB_STDSTAR_DEC_COL) ;
+        return -1 ;
+    }
+    
+    /* Compute distances of the selected rows */
+    for (i=0 ; i<nrows ; i++) {
+        if (cpl_table_is_selected(cat, i)) {
+            /* The row is selected - compute the distance */
+            distance = irplib_wcs_great_circle_dist(ra, dec,
+                    cpl_table_get_double(cat, IRPLIB_STDSTAR_RA_COL, i, NULL),
+                    cpl_table_get_double(cat, IRPLIB_STDSTAR_DEC_COL, i, NULL));
+            if (distance <= min_dist) {
+                min_dist = distance ;
+                ind = i ;
+            }
+        }
+    }
+    return ind ;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Find the closest star to ra, dec in the catalog
+  @param    catfile  the catalog file name
+  @param    ra       RA pos where to search
+  @param    dec      DEC pos where to search
+  @param    band     the band name
+  @param    catname  the searched catalog name
+  @param    mag      the computed magnitude (output)
+  @param    name     the star name (output)
+  @param    type     the star type (output)
+  @param    star_ra  the star RA from the catalog (output)
+  @param    star_dec the star DEC from the catalog (output)
+  @param    dist_am  the distance in arc minutes
+  @return   CPL_ERROR_NONE if ok, or an appropiate error case otherwise
+
+  The closest star to ra, dec with defined magnitude is search in all the 
+  catalogues included in catfile.
+  If catname is "all", all the catalogs are searched at once.
+  The output pointers can be NULL if one is not interested in them.
+ */
+/*----------------------------------------------------------------------------*/
+cpl_error_code irplib_stdstar_find_star(
+        const char          *   catfile,
+        double                  ra, 
+        double                  dec,
+        const char          *   band,
+        const char          *   catname,
+        double              *   mag,
+        char                **  name,
+        char                **  type,
+        char                **  usedcatname,
+        double              *   star_ra,
+        double              *   star_dec,
+        double                  dist_am)
+{
+    cpl_errorstate prestate = cpl_errorstate_get();
+    cpl_table   *   catal ;
+    const double    dist = dist_am / 60.0 ;
+    int             ind ;
+
+    /* Check entries */
+    if (catfile == NULL) return cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT);
+    if (band    == NULL) return cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT);
+    if (catname == NULL) return cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT);
+    
+    /* Load the catalog */
+    if ((catal = irplib_stdstar_load_catalog(catfile, catname)) == NULL) {
+        return cpl_error_set_message(cpl_func, CPL_ERROR_FILE_NOT_FOUND,
+                                           "Cannot load the catalog %s from %s",
+                                           catname, catfile);
+    }
+    
+    /* Check the columns are present */
+    if (irplib_stdstar_check_columns_exist(catal) != CPL_ERROR_NONE) {
+        cpl_table_delete(catal);
+        return cpl_error_set_where(cpl_func);
+    }
+    
+    /* Select stars with known magnitude */
+    if (irplib_stdstar_select_stars_mag(catal, band) == -1) {
+        cpl_table_delete(catal) ;
+        return cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
+                                           "Cannot select stars in that band");
+    }
+
+    /* Select stars within a given distance */
+    if (irplib_stdstar_select_stars_dist(catal, ra, dec, dist) == -1) {
+        cpl_table_delete(catal) ;
+        return cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
+                                           "Cannot select close stars");
+    }
+
+    /* Take the closest */
+    if ((ind=irplib_stdstar_find_closest(catal, ra, dec)) < 0) {
+        cpl_table_delete(catal) ;
+        return cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
+                                           "Cannot get the closest star with "
+                                           "known %s magnitude",band);
+    }
+
+    if(mag != NULL)
+        *mag = cpl_table_get_double(catal, band, ind, NULL) ;
+
+    if(name != NULL)
+    {
+        *name = cpl_strdup(cpl_table_get_string(catal,
+                                                IRPLIB_STDSTAR_STAR_COL, ind));
+
+    }
+    if(type != NULL)
+    {
+        *type = cpl_strdup(cpl_table_get_string(catal, IRPLIB_STDSTAR_TYPE_COL,
+                                                ind));
+    }
+    if(usedcatname != NULL)
+    {
+        if(strcmp(catname, "all"))
+            *usedcatname = cpl_strdup(catname);
+        else
+        {
+            *usedcatname = cpl_strdup(cpl_table_get_string
+                                      (catal, IRPLIB_STDSTAR_CAT_COL, ind));
+        }
+    }
+    if(star_ra != NULL)
+        *star_ra  = cpl_table_get_double(catal, IRPLIB_STDSTAR_RA_COL, ind, NULL);
+    if(star_dec != NULL)
+        *star_dec = cpl_table_get_double(catal, IRPLIB_STDSTAR_DEC_COL, ind, NULL);
+    
+    /* Free and return */
+    cpl_table_delete(catal);
+    return cpl_errorstate_is_equal(prestate) ? CPL_ERROR_NONE
+        : cpl_error_set_where(cpl_func);
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Get the conversion
+  @param    spec    the extracted spectrum 
+  @param    dit     the DIT (in sec)
+  @param    surface the surface of the miror (in sq cm)
+  @param    gain    the gain of the instrument (ISAAC=4.5, SINFONI=2.42)
+  @param    mag     the star magnitude
+  @return   the newly allocated conversion or NULL in error case
+
+  conversion(wave) = (spec * gain * 10^(mag/2.5) * h * c) / 
+                     (dit * surface * dispersion * wave)
+ */
+/*----------------------------------------------------------------------------*/
+cpl_vector * irplib_stdstar_get_conversion(
+        const cpl_bivector  *   spec,
+        double                  dit,
+        double                  surface,
+        double                  gain,
+        double                  mag)
+{
+    double                      h = 6.62e-27 ;
+    double                      c = 3e18 ;
+    const cpl_vector    *       wave ;
+    const cpl_vector    *       extr ;
+    cpl_vector          *       out ;
+    double                      factor ;
+
+    /* Test entries */
+    if (spec == NULL) return NULL ;
+    if (dit <= 0.0) return NULL ;
+
+    /* Get the extracted spectrum */
+    wave = cpl_bivector_get_x_const(spec) ;
+    extr = cpl_bivector_get_y_const(spec) ;
+
+    /* Get the spectrum */
+    out = cpl_vector_duplicate(extr) ;
+
+    /* Divide by DIT */
+    cpl_vector_divide_scalar(out, dit) ;
+
+    /* Divide by the surface */
+    cpl_vector_divide_scalar(out, surface) ;
+
+    /* Multiply by the gain */
+    cpl_vector_multiply_scalar(out, gain) ;
+
+    /* Multiply by the difference magnitude */
+    factor = pow(10, mag/2.5) ;
+    cpl_vector_multiply_scalar(out, factor) ;
+
+    /* Divide by the dispersion */
+    factor = (cpl_vector_get(wave, cpl_vector_get_size(wave)-1) -
+            cpl_vector_get(wave, 0)) / cpl_vector_get_size(wave) ;
+    cpl_vector_divide_scalar(out, factor) ;
+
+    /* Multiply by the energy of the photon */
+    cpl_vector_multiply_scalar(out, h*c) ;
+    cpl_vector_divide(out, wave) ;
+
+    return out ;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Get the 0 magnitude spectrum
+  @param    sed     the SED in angstroms / ergs/s/cm^2/Angstrom
+  @param    waves   the wavelengths in angstroms
+  @param    cent_wl the central wavelength in microns
+  @return   the newly allocated spectrum or NULL in error case
+ */
+/*----------------------------------------------------------------------------*/
+cpl_vector * irplib_stdstar_get_mag_zero(
+        const cpl_bivector  *   sed,
+        const cpl_vector    *   waves,
+        double                  cent_wl)
+{
+    double              wmin, wmax, wstep ;
+    int                 nb_sed ;
+    const double    *   sed_x ;
+    const double    *   sed_y ;
+    cpl_bivector    *   sed_loc ;
+    double          *   sed_loc_x ;
+    double          *   sed_loc_y ;
+    cpl_vector      *   out ;
+    cpl_bivector    *   out_biv ;
+    double              f0_jan, f0_erg, cent_val ;
+    int                 i ;
+
+    /* Test entries */
+    if (sed == NULL) return NULL ;
+    if (waves == NULL) return NULL ;
+
+    /* Initialise */
+    nb_sed = cpl_bivector_get_size(sed) ;
+    sed_x = cpl_bivector_get_x_data_const(sed) ;
+    sed_y = cpl_bivector_get_y_data_const(sed) ;
+    wstep = sed_x[1] - sed_x[0] ;
+    wmin = cpl_vector_get(waves, 0) ;
+    wmax = cpl_vector_get(waves, cpl_vector_get_size(waves)-1) ;
+
+    /* Expand sed with 0 to have it bigger than the required wavelengths */
+    sed_loc = cpl_bivector_new(nb_sed + 4) ;
+    sed_loc_x = cpl_bivector_get_x_data(sed_loc) ;
+    sed_loc_y = cpl_bivector_get_y_data(sed_loc) ;
+    for (i=0 ; i<nb_sed ; i++) {
+        sed_loc_x[i+2] = sed_x[i] ;
+        sed_loc_y[i+2] = sed_y[i] ;
+    }
+
+    /* Low bound */
+    sed_loc_x[1] = sed_loc_x[2] - wstep ;
+    if (sed_loc_x[2] < wmin) {
+        sed_loc_x[0] = sed_loc_x[1] - wstep ;
+    } else {
+        sed_loc_x[0] = wmin - wstep ;
+    }
+    sed_loc_y[0] = 1e-20 ;
+    sed_loc_y[1] = 1e-20 ;
+
+    /* High bound */
+    sed_loc_x[nb_sed+2] = sed_loc_x[nb_sed+1] + wstep ;
+    if (sed_loc_x[nb_sed+1] > wmax) {
+        sed_loc_x[nb_sed+3] = sed_loc_x[nb_sed+2] + wstep ;
+    } else {
+        sed_loc_x[nb_sed+3] = wmax + wstep ;
+    }
+    sed_loc_y[nb_sed+2] = 1e-20 ;
+    sed_loc_y[nb_sed+3] = 1e-20 ;
+
+    /* Create the output bivector */
+    out = cpl_vector_duplicate(waves) ;
+    out_biv = cpl_bivector_wrap_vectors((cpl_vector*)waves, out) ;
+
+    /* Interpolate */
+    if (cpl_bivector_interpolate_linear(out_biv, sed_loc) != CPL_ERROR_NONE) {
+        cpl_msg_error(cpl_func, "Cannot interpolate the wavelength") ;
+        cpl_bivector_unwrap_vectors(out_biv) ;
+        cpl_vector_delete(out) ;
+        cpl_bivector_delete(sed_loc) ;
+        return NULL ;
+    }
+    cpl_bivector_unwrap_vectors(out_biv) ;
+    cpl_bivector_delete(sed_loc) ;
+
+    /* Compute f0_jan */
+    f0_jan = 5513.15 / ( pow(cent_wl,3) * (exp(1.2848/cent_wl)-1) ) ;
+
+    /* Convert f0 Jansky -> ergs/s/cm^2/Angstrom */
+    f0_erg = f0_jan * 1e-26 * 1e7 * 3e18 / (1e4 * cent_wl*cent_wl*1e4*1e4) ;
+
+    /* Scale out so that the central value is f0 */
+    cent_val = cpl_vector_get(out, cpl_vector_get_size(out)/2) ;
+    if (cent_val <= 0.0) {
+        cpl_msg_error(cpl_func, "Negative or 0 central value") ;
+        cpl_vector_delete(out) ;
+        return NULL ;
+    }
+    cpl_vector_multiply_scalar(out, f0_erg/cent_val) ;
+
+    /* Return */
+    return out ;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Get the SED
+  @param    seds_file   the table file name
+  @param    sptype      the requested spectral type
+  @return   the newly allocated SED or NULL in error case
+
+  wavelength in Angstroms
+  SED in 
+ */
+/*----------------------------------------------------------------------------*/
+cpl_bivector * irplib_stdstar_get_sed(
+        const char  *   seds_file,
+        const char  *   sptype)
+{
+    cpl_table           *   seds ;
+    cpl_bivector        *   out ;
+    cpl_vector          *   wave ;
+    cpl_vector          *   sed ;
+    cpl_bivector        *   tmp ;
+    int                     nlines ;
+
+    /* Test entries */
+    if (seds_file == NULL) return NULL ;
+    if (sptype == NULL) return NULL ;
+
+    /* Load the table */
+    if ((seds = cpl_table_load(seds_file, 1, 0)) == NULL) {
+        cpl_msg_error(cpl_func, "Cannot load the table") ;
+        return NULL ;
+    }
+
+    /* Check if the column is there */
+    if (!cpl_table_has_column(seds, sptype)) {
+        cpl_msg_error(cpl_func, "SED of the requested star not available") ;
+        cpl_table_delete(seds) ;
+        return NULL ;
+    }
+
+    /* Get the nb lines */
+    nlines = cpl_table_get_nrow(seds) ;
+
+    /* Get the wavelength as a vector */
+    if ((wave = cpl_vector_wrap(nlines,
+            cpl_table_get_data_double(seds, "Wavelength"))) == NULL) {
+        cpl_msg_error(cpl_func, "Cannot get the Wavelength column") ;
+        cpl_table_delete(seds) ;
+        return NULL ;
+    }
+
+    /* Get the SED as a vector */
+    if ((sed = cpl_vector_wrap(nlines,
+            cpl_table_get_data_double(seds, sptype))) == NULL) {
+        cpl_msg_error(cpl_func, "Cannot get the SED column") ;
+        cpl_table_delete(seds) ;
+        cpl_vector_unwrap(wave) ;
+        return NULL ;
+    }
+    tmp = cpl_bivector_wrap_vectors(wave, sed) ;
+
+    /* Create the output bivector */
+    out = cpl_bivector_duplicate(tmp) ;
+
+    /* Free */
+    cpl_bivector_unwrap_vectors(tmp) ;
+    cpl_vector_unwrap(wave) ;
+    cpl_vector_unwrap(sed) ;
+    cpl_table_delete(seds) ;
+
+    /* Return  */
+    return out ;
+}
+/**@}*/
diff --git a/irplib/irplib_stdstar.h b/irplib/irplib_stdstar.h
new file mode 100644
index 0000000..d537390
--- /dev/null
+++ b/irplib/irplib_stdstar.h
@@ -0,0 +1,78 @@
+/* $Id: irplib_stdstar.h,v 1.15 2011/12/14 08:53:04 cgarcia Exp $
+ *
+ * This file is part of the irplib package
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: cgarcia $
+ * $Date: 2011/12/14 08:53:04 $
+ * $Revision: 1.15 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifndef IRPLIB_STDSTAR_H
+#define IRPLIB_STDSTAR_H
+
+/*-----------------------------------------------------------------------------
+                                   Includes
+ -----------------------------------------------------------------------------*/
+
+#include <cpl.h>
+
+/*-----------------------------------------------------------------------------
+                                   Defines
+ -----------------------------------------------------------------------------*/
+
+#define     IRPLIB_STDSTAR_STAR_COL     "STARS"
+#define     IRPLIB_STDSTAR_TYPE_COL     "SP_TYPE"
+#define     IRPLIB_STDSTAR_RA_COL       "RA"
+#define     IRPLIB_STDSTAR_DEC_COL      "DEC"
+#define     IRPLIB_STDSTAR_CAT_COL      "CATALOG"
+
+/* Maximum allowed distance [arc minutes] between observation and
+   catalogue coordinates  */
+#define     IRPLIB_STDSTAR_MAXDIST       2.0
+
+/* Magical value to indicate an invalid magnitude  */
+#define     IRPLIB_STDSTAR_NOMAG         99.0
+
+/* Use this limit in comparisons regarding an invalid magnitude  */
+#define     IRPLIB_STDSTAR_LIMIT         (IRPLIB_STDSTAR_NOMAG-1.0)
+
+/*-----------------------------------------------------------------------------
+                                   Function prototypes
+ -----------------------------------------------------------------------------*/
+
+int irplib_stdstar_write_catalogs(cpl_frameset *, const cpl_frameset *, 
+        const char *, const char *, const char *, const char *,
+        const char *, cpl_table * (*convert_ascii_table)(const char *)) ;
+cpl_table * irplib_stdstar_load_catalog(const char *, const char *) ;
+cpl_error_code irplib_stdstar_check_columns_exist(const cpl_table  *);
+int irplib_stdstar_select_stars_dist(cpl_table *, double, double, double) ;
+int irplib_stdstar_select_stars_mag(cpl_table *, const char *) ;
+int irplib_stdstar_find_closest(const cpl_table *, double, double) ;
+cpl_error_code irplib_stdstar_find_star(const char *, double, double, const char *, 
+        const char *, double *, char **, char **, char **, 
+        double *, double  * , double);
+cpl_vector * irplib_stdstar_get_conversion(const cpl_bivector *, double, double,
+        double, double);
+cpl_vector * irplib_stdstar_get_mag_zero(const cpl_bivector *,
+        const cpl_vector *, double);
+cpl_bivector * irplib_stdstar_get_sed(const char *, const char *);
+
+#endif
diff --git a/irplib/irplib_strehl.c b/irplib/irplib_strehl.c
new file mode 100644
index 0000000..5f02d2c
--- /dev/null
+++ b/irplib/irplib_strehl.c
@@ -0,0 +1,806 @@
+/* $Id: irplib_strehl.c,v 1.43 2009/11/18 21:37:48 llundin Exp $
+ *
+ * This file is part of the irplib package
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: llundin $
+ * $Date: 2009/11/18 21:37:48 $
+ * $Revision: 1.43 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+/*-----------------------------------------------------------------------------
+                                   Includes
+ -----------------------------------------------------------------------------*/
+
+#include <string.h>
+#include <assert.h>
+#include <math.h>
+#include <float.h>
+
+#include <cpl.h>
+
+#include "irplib_utils.h"
+#include "irplib_strehl.h"
+
+/*----------------------------------------------------------------------------*/
+/**
+ * @defgroup irplib_strehl   Functions to compute the Strehl
+ */
+/*----------------------------------------------------------------------------*/
+
+/*-----------------------------------------------------------------------------
+                                   Define
+ -----------------------------------------------------------------------------*/
+
+#ifndef IRPLIB_STREHL_RAD_CENTRAL
+#define IRPLIB_STREHL_RAD_CENTRAL 5
+#endif
+
+#define IRPLIB_DISK_BG_MIN_PIX_NB    30
+#define IRPLIB_DISK_BG_REJ_LOW       0.1
+#define IRPLIB_DISK_BG_REJ_HIGH      0.1
+
+/*-----------------------------------------------------------------------------
+                                   Functions prototypes
+ -----------------------------------------------------------------------------*/
+
+static cpl_image * irplib_strehl_generate_otf(double, double, double, double,
+                                              int, double);
+static double PSF_H1(double, double, double);
+static double PSF_H2(double, double);
+static double PSF_G(double, double);
+static double PSF_sinc(double);
+static double PSF_TelOTF(double, double);
+static cpl_error_code update_bad_pixel_map(cpl_image* im);
+
+
+/*-----------------------------------------------------------------------------
+                                   Functions code
+ -----------------------------------------------------------------------------*/
+/**@{*/
+
+/**
+  @brief    Update the bad pixel map for the image - mark all pixels with NaN value as a bad
+  @param    im             Image with pixel-type float or double
+  @return   0 iff ok
+  */
+cpl_error_code update_bad_pixel_map(cpl_image* im)
+{
+	int szx = cpl_image_get_size_x(im);
+	int szy = cpl_image_get_size_y(im);
+	int x = 0;
+	cpl_mask* bpm = cpl_image_get_bpm(im);
+
+	for (x = 1; x <=szx; x++)
+	{
+		int y = 0;
+		for(y = 1; y <= szy; y++)
+		{
+			int isnull = 0;
+			double value = cpl_image_get(im, x, y, &isnull);
+			if (isnan(value))
+			{
+				cpl_mask_set(bpm, x, y, CPL_BINARY_1);
+			}
+		}
+	}
+	return cpl_error_get_code();
+}
+/**
+  @brief    Compute the strehl ratio in an image.
+ at param    im             Image with pixel-type float
+  @param    m1             Diameter of the M1 mirror [m]
+  @param    m2             Diameter of the M2 mirror [m]
+  @param    lam            Central wavelength [micron]
+  @param    dlam           Filter bandwidth [micron]
+  @param    pscale         Positive pixel scale
+  @param    size           Size of image to be used for internal PSF
+  @param    xpos           The x position of the ring center
+  @param    ypos           The y position of the ring center
+  @param    r1             The Star Radius, r1 > 0
+  @param    r2             The Internal Radius, r2 > 0
+  @param    r3             The External Radius, r3 > r2
+  @param    noise_box_sz   Pass -1 for default values
+  @param    noise_nsamples Pass -1 for default values
+  @param    strehl         Pointer to the Strehl Error (positive on success)
+  @param    strehl_err     Pointer to the Strehl Error (non-negative on success)
+  @param    star_bg        Pointer to the Star Background
+  @param    star_peak      Pointer to the Star Peak (positive on success)
+  @param    star_flux      Pointer to the Star Flux (positive on success)
+  @param    psf_peak       Pointer to the PSF Peak (positive on success)
+  @param    psf_flux       Pointer to the PSF Flux (1 on success)
+  @param    bg_noise       Pointer to the Background Noise
+  @return   0 iff ok
+  @note     The output is undefined on error. On success the Strehl Ratio may
+            exceed 1. Before computation, all NaN values in the image would be marked in the
+            bad pixel map. That means, parameter im would changed (bad pixel map would be updated / created).
+  */
+
+cpl_error_code irplib_strehl_mark_bad_and_compute(cpl_image *   im,
+                                     double              m1,
+                                     double              m2,
+                                     double              lam,
+                                     double              dlam,
+                                     double              pscale,
+                                     int                 size,
+                                     double              xpos,
+                                     double              ypos,
+                                     double              r1,
+                                     double              r2,
+                                     double              r3,
+                                     int                 noise_box_sz,
+                                     int                 noise_nsamples,
+                                     double          *   strehl,
+                                     double          *   strehl_err,
+                                     double          *   star_bg,
+                                     double          *   star_peak,
+                                     double          *   star_flux,
+                                     double          *   psf_peak,
+                                     double          *   psf_flux,
+                                     double          *   bg_noise)
+{
+	cpl_ensure_code(!update_bad_pixel_map(im), cpl_error_get_code());
+	return irplib_strehl_compute(im, m1, m2, lam, dlam, pscale, size, xpos, ypos,
+            r1,
+            r2,
+            r3,
+            noise_box_sz,
+            noise_nsamples,
+            strehl,
+            strehl_err,
+            star_bg,
+            star_peak,
+            star_flux,
+            psf_peak,
+            psf_flux,
+            bg_noise);
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Compute the strehl ratio in an image
+  @param    im             Image with pixel-type float
+  @param    m1             Diameter of the M1 mirror [m]
+  @param    m2             Diameter of the M2 mirror [m]
+  @param    lam            Central wavelength [micron]
+  @param    dlam           Filter bandwidth [micron]
+  @param    pscale         Positive pixel scale [Arcsecond/pixel]
+  @param    size           Size of image to be used for internal PSF [pixel]
+  @param    xpos           The x position of the ring center [pixel]
+  @param    ypos           The y position of the ring center [pixel]
+  @param    r1             The Star Radius, r1 > 0 [Arcsecond]
+  @param    r2             The Internal Radius, r2 > 0 [Arcsecond]
+  @param    r3             The External Radius, r3 > r2 [Arcsecond]
+  @param    noise_box_sz   Pass -1 for default values
+  @param    noise_nsamples Pass -1 for default values
+  @param    strehl         Pointer to the Strehl Error (positive on success)
+  @param    strehl_err     Pointer to the Strehl Error (non-negative on success)
+  @param    star_bg        Pointer to the Star Background
+  @param    star_peak      Pointer to the Star Peak (positive on success)
+  @param    star_flux      Pointer to the Star Flux (positive on success)
+  @param    psf_peak       Pointer to the PSF Peak (positive on success)
+  @param    psf_flux       Pointer to the PSF Flux (1 on success)
+  @param    bg_noise       Pointer to the Background Noise
+  @return   0 iff ok
+  @note     The output is undefined on error. On success the Strehl Ratio may
+            exceed 1. Strehl computation could fail if the image contains NaN values
+            and those values are not marked in the bad pixel map. In that case the function
+            rplib_strehl_mark_bad_and_compute could be used instead.
+ */
+/*----------------------------------------------------------------------------*/
+cpl_error_code irplib_strehl_compute(const cpl_image *   im,
+                                     double              m1,
+                                     double              m2,
+                                     double              lam,
+                                     double              dlam,
+                                     double              pscale,
+                                     int                 size,
+                                     double              xpos,
+                                     double              ypos,
+                                     double              r1,
+                                     double              r2,
+                                     double              r3,
+                                     int                 noise_box_sz,
+                                     int                 noise_nsamples,
+                                     double          *   strehl,
+                                     double          *   strehl_err,
+                                     double          *   star_bg,
+                                     double          *   star_peak,
+                                     double          *   star_flux,
+                                     double          *   psf_peak,
+                                     double          *   psf_flux,
+                                     double          *   bg_noise)
+{
+    cpl_image  * psf;
+    double       star_radius, max_radius;
+
+    /* FIXME: Arbitrary choice of image border */
+    const double window_size = (double)(IRPLIB_STREHL_RAD_CENTRAL);
+
+    /* Determined empirically by C. Lidman for Strehl error computation */
+    const double strehl_error_coefficient = CPL_MATH_PI * 0.007 / 0.0271;
+    double       ring[4];
+    /* cpl_flux_get_noise_ring() must succeed with this many tries */
+    int          ring_tries = 3;
+    cpl_errorstate prestate;
+
+    /* Check compile-time constant */
+    cpl_ensure_code(window_size > 0.0,  CPL_ERROR_ILLEGAL_INPUT);
+
+    /* Test inputs */
+    cpl_ensure_code(im != NULL,         CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(strehl != NULL,     CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(strehl_err != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(star_bg != NULL,    CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(star_peak != NULL,  CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(star_flux != NULL,  CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(psf_peak != NULL,   CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(psf_flux != NULL,   CPL_ERROR_NULL_INPUT);
+
+    cpl_ensure_code(pscale > 0.0,      CPL_ERROR_ILLEGAL_INPUT);
+
+    cpl_ensure_code(r1 > 0.0,      CPL_ERROR_ILLEGAL_INPUT);
+    cpl_ensure_code(r2 > 0.0,      CPL_ERROR_ILLEGAL_INPUT);
+    cpl_ensure_code(r3 > r2,       CPL_ERROR_ILLEGAL_INPUT);
+
+    /* Computing a Strehl ratio is a story between an ideal PSF */
+    /* and a candidate image supposed to approximate this ideal PSF. */
+
+    /* Generate first appropriate PSF to find max peak */
+    psf = irplib_strehl_generate_psf(m1, m2, lam, dlam, pscale, size);
+    cpl_ensure_code(psf != NULL,      CPL_ERROR_ILLEGAL_OUTPUT);
+
+    /* Compute flux in PSF and find max peak */
+    *psf_peak = cpl_image_get_max(psf);
+    cpl_image_delete(psf);
+
+    assert( *psf_peak > 0.0); /* The ideal PSF has a positive maximum */
+    *psf_flux = 1.0; /* The psf flux, cpl_image_get_flux(psf), is always 1 */
+
+    /* Measure the background in the candidate image */
+    *star_bg = irplib_strehl_ring_background(im, xpos, ypos, r2/pscale, r3/pscale,
+                                             IRPLIB_BG_METHOD_AVER_REJ);
+
+    /* Compute star_radius in pixels */
+    star_radius = r1/pscale;
+
+    /* Measure the flux on the candidate image */
+    *star_flux = irplib_strehl_disk_flux(im, xpos, ypos, star_radius, *star_bg);
+
+    cpl_ensure_code(*star_flux > 0.0,      CPL_ERROR_ILLEGAL_OUTPUT);
+
+    /* Find the peak value on the central part of the candidate image */
+    max_radius = window_size < star_radius ? window_size : star_radius;
+    cpl_ensure_code(!irplib_strehl_disk_max(im, xpos, ypos, max_radius,
+                                            star_peak), cpl_error_get_code());
+    *star_peak -= *star_bg;
+
+    cpl_ensure_code(*star_peak > 0.0,      CPL_ERROR_ILLEGAL_OUTPUT);
+
+    /* Compute Strehl */
+    /* (StarPeak / StarFlux) / (PsfPeak / PsfFlux) */
+    *strehl = (*star_peak * *psf_flux ) / ( *star_flux * *psf_peak);
+
+    if (*strehl > 1)
+        cpl_msg_warning(cpl_func, "Extreme Strehl-ratio=%g, star_peak=%g, "
+                        "star_flux=%g, psf_peak=%g, psf_flux=%g", *strehl,
+                        *star_peak, *star_flux, *psf_peak, *psf_flux);
+
+    /* Compute Strehl error */
+    /* computation could fail if the image contains pixels with NaN value*/
+    ring[0] = xpos;
+    ring[1] = ypos;
+    ring[2] = r2/pscale;
+    ring[3] = r3/pscale;
+
+    /* FIXME: With CPL 5.1 the recoverable error
+       will be CPL_ERROR_DATA_NOT_FOUND */
+    prestate = cpl_errorstate_get();
+    while (cpl_flux_get_noise_ring(im, ring, noise_box_sz, noise_nsamples,
+                                   bg_noise, NULL) && --ring_tries > 0);
+    if (ring_tries > 0) {
+        cpl_errorstate_set(prestate); /* Recover, if an error happened */
+    } else {
+        return cpl_error_set_where(cpl_func);
+    }
+
+    *strehl_err = strehl_error_coefficient * (*bg_noise) * pscale *
+        star_radius * star_radius / *star_flux;
+
+    /* This check should not be able to fail, but just to be sure */
+    cpl_ensure_code(*strehl_err >= 0.0,       CPL_ERROR_ILLEGAL_OUTPUT);
+
+    return CPL_ERROR_NONE;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Compute the flux from a disk
+  @param    im          Image with pixel-type float
+  @param    xpos        the x position of the disk center
+  @param    ypos        the y position of the disk center
+  @param    rad         the radius
+  @param    bg          the star background
+  @return   The computed flux or 0.0 on error
+  @note     (xpos, ypos) and may be outside the image, if so then a sufficiently
+            small rad will cause no pixels to be encircled, in which case the
+            returned flux is zero.
+
+  The nan values check has been added for SINFONI. The input image in
+  input should not contain nan values, but it does in  some cases...
+ */
+/*----------------------------------------------------------------------------*/
+double irplib_strehl_disk_flux(const cpl_image * im,
+                               double            xpos,
+                               double            ypos,
+                               double            rad,
+                               double            bg)
+{
+    const double    sqr = rad * rad;
+    double          sqrest;
+    const float *   pim;
+    double          flux = 0.0;
+    double          yj, xi;
+    int             nx, ny;
+    int             lx, ly, ux, uy;
+    int             i, j;
+
+
+    /* Check entries */
+    cpl_ensure(im != NULL, CPL_ERROR_NULL_INPUT, 0.0);
+    cpl_ensure(cpl_image_get_type(im) == CPL_TYPE_FLOAT,
+               CPL_ERROR_UNSUPPORTED_MODE, 0.0);
+    cpl_ensure(rad > 0.0, CPL_ERROR_ILLEGAL_INPUT, 0.0);
+
+    nx = cpl_image_get_size_x(im);
+    ny = cpl_image_get_size_y(im);
+
+    /* Round down */
+    lx = (int)(xpos - rad);
+    ly = (int)(ypos - rad);
+    if (lx < 0) lx = 0;
+    if (ly < 0) ly = 0;
+
+    /* Round up */
+    ux = (int)(xpos + rad) + 1;
+    uy = (int)(ypos + rad) + 1;
+    if (ux > (nx-1)) ux = nx-1;
+    if (uy > (ny-1)) uy = ny-1;
+
+    pim = cpl_image_get_data_float_const(im);
+    for (j=ly ; j<uy ; j++) {
+        yj = (double)j - ypos;
+        sqrest = sqr - yj * yj;
+        for (i=lx; i<ux ; i++) {
+            xi = (double)i - xpos;
+            if (sqrest >= xi * xi && irplib_isnan(pim[i+j*nx]) == 0) {
+                flux += (double)pim[i+j*nx] - bg;
+            }
+        }
+    }
+    return flux;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Compute the background in the image from a specified disk
+  @param    im          Image with pixel-type float
+  @param    xpos        the x position of the ring center
+  @param    ypos        the y position of the ring center
+  @param    rad_int     the internal radius
+  @param    rad_ext     the external radius
+  @param    mode        IRPLIB_BG_METHOD_AVER_REJ or IRPLIB_BG_METHOD_MEDIAN
+  @return   The computed background or 0.0 on error.
+
+  The nan values check has been added for SINFONI. The input image in
+  input should not contain nan values, but it does in  some cases...
+ */
+/*----------------------------------------------------------------------------*/
+double irplib_strehl_ring_background(const cpl_image *       im,
+                                     double                  xpos,
+                                     double                  ypos,
+                                     double                  rad_int,
+                                     double                  rad_ext,
+                                     irplib_strehl_bg_method mode)
+{
+    int             npix;
+    const double    sqr_int = rad_int * rad_int;
+    const double    sqr_ext = rad_ext * rad_ext;
+    double          dist;
+    cpl_vector  *   pix_arr;
+    const float *   pim;
+    double          flux = 0.0;
+    double          yj, xi;
+    int             lx, ly, ux, uy;
+    int             nx, ny;
+    int             i, j;
+
+    /* Check entries */
+    cpl_ensure(im != NULL, CPL_ERROR_NULL_INPUT, 0.0);
+    cpl_ensure(cpl_image_get_type(im) == CPL_TYPE_FLOAT,
+               CPL_ERROR_UNSUPPORTED_MODE, 0.0);
+    cpl_ensure(rad_int > 0.0, CPL_ERROR_ILLEGAL_INPUT, 0.0);
+    cpl_ensure(rad_ext > rad_int, CPL_ERROR_ILLEGAL_INPUT, 0.0);
+
+    cpl_ensure(mode == IRPLIB_BG_METHOD_AVER_REJ ||
+               mode == IRPLIB_BG_METHOD_MEDIAN,
+               CPL_ERROR_UNSUPPORTED_MODE, 0.0);
+
+    nx = cpl_image_get_size_x(im);
+    ny = cpl_image_get_size_y(im);
+
+    /* Round down */
+    lx = (int)(xpos - rad_ext);
+    ly = (int)(ypos - rad_ext);
+    if (lx < 0) lx = 0;
+    if (ly < 0) ly = 0;
+
+    /* Round up */
+    ux = (int)(xpos + rad_ext) + 1;
+    uy = (int)(ypos + rad_ext) + 1;
+    if (ux > (nx-1)) ux = nx-1;
+    if (uy > (ny-1)) uy = ny-1;
+
+    npix = (ux - lx + 1) * (uy - ly + 1);
+    cpl_ensure(npix >= IRPLIB_DISK_BG_MIN_PIX_NB, CPL_ERROR_DATA_NOT_FOUND, 0.0);
+
+    /* Allocate pixel array to hold values in the ring */
+    pix_arr = cpl_vector_new(npix);
+
+    /* Count number of pixels in the ring */
+    /* Retrieve all pixels which belong to the ring */
+    pim = cpl_image_get_data_float_const(im);
+    npix = 0;
+    for (j=ly ; j<uy ; j++) {
+        yj = (double)j - ypos;
+        for (i=lx ; i<ux; i++) {
+            xi = (double)i - xpos;
+            dist = yj * yj + xi * xi;
+            if (sqr_int <= dist && dist <= sqr_ext &&
+                irplib_isnan(pim[i+j*nx]) == 0) {
+                cpl_vector_set(pix_arr, npix, (double)pim[i+j*nx]);
+                npix++;
+            }
+        }
+    }
+
+    if (npix < IRPLIB_DISK_BG_MIN_PIX_NB) {
+        cpl_vector_delete(pix_arr);
+        cpl_ensure(0, CPL_ERROR_DATA_NOT_FOUND, 0.0);
+    }
+
+    /* Should not be able to fail now */
+
+    /* Resize pixel array to actual number of values within the ring */
+    cpl_vector_set_size(pix_arr, npix);
+
+    if (mode == IRPLIB_BG_METHOD_AVER_REJ) {
+        const int low_ind  = (int)((double)npix * IRPLIB_DISK_BG_REJ_LOW);
+        const int high_ind = (int)((double)npix
+                                   * (1.0 - IRPLIB_DISK_BG_REJ_HIGH));
+
+        /* Sort the array */
+        cpl_vector_sort(pix_arr, 1);
+
+        for (i=low_ind ; i<high_ind ; i++) {
+            flux += cpl_vector_get(pix_arr, i);
+        }
+        if (high_ind - low_ind > 1) flux /= (double)(high_ind - low_ind);
+    } else /* if (mode == IRPLIB_BG_METHOD_MEDIAN) */ {
+        flux = cpl_vector_get_median(pix_arr);
+    }
+
+    cpl_vector_delete(pix_arr);
+
+    return flux;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Compute the ideal PSF for a given telescope+instrument.
+  @param    m1          Diameter of the M1 mirror [meter]
+  @param    m2          Diameter of the M2 mirror [meter]
+  @param    lam         Central wavelength [micron]
+  @param    dlam        Filter bandwidth [micron]
+  @param    size        Generated image size (image will be square) [pixel]
+  @param    pscale      Pixel scale on the sky [Arcsecond/pixel]
+  @return   1 newly generated image.
+
+  This function computes the ideal PSF for a given telescope and instrument.
+  The PSF is computed by first generated the ideal OTF for the provided
+  conditions, and applying a Fourier transform to it to bring it back to real
+  space. The returned PSF is normalized to unity flux, to help Strehl ratio
+  computations.
+
+  The image halves of the returned PSF are swapped in both directions.
+
+ */
+/*----------------------------------------------------------------------------*/
+cpl_image * irplib_strehl_generate_psf(
+        double   m1,
+        double   m2,
+        double   lam,
+        double   dlam,
+        double   pscale,
+        int      size)
+{
+    cpl_image * otf_image = irplib_strehl_generate_otf(m1, m2, lam, dlam,
+            size, pscale);
+
+    if (otf_image == NULL) return NULL;
+
+    /* Transform back to real space
+       - Normalization is unnecessary, due to the subsequent normalisation.
+       - An OTF is point symmetric about its center, i.e. it is even,
+         i.e. the real space image is real.
+       - Because of this a forward FFT works as well.
+       - If the PSF ever needs to have its images halves swapped add
+         CPL_FFT_SWAP_HALVES to the FFT call.
+     */
+
+    if (cpl_image_fft(otf_image, NULL, CPL_FFT_UNNORMALIZED) ||
+
+        /* Compute absolute values of PSF */
+        cpl_image_abs(otf_image) ||
+
+        /* Normalize PSF to get flux=1  */
+        cpl_image_normalise(otf_image, CPL_NORM_FLUX)) {
+
+        cpl_image_delete(otf_image);
+        return NULL;
+    }
+
+    return otf_image;
+}
+
+/**@}*/
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Generate an image of an ideal Optical Transfer Function.
+  @param    m1          Diameter of the M1 mirror [m]
+  @param    m2          Diameter of the M2 mirror [m], m2 < m1
+  @param    lam         Central wavelength [micron]
+  @param    dlam        Filter bandwidth [micron]
+  @param    size        Generated image size (image will be square).
+  @param    pscale      Pixel scale on the sky [Arcsecond/pixel]
+  @return   1 newly generated cpl_image
+
+  Based on the paper "Amplitude estimation from speckle interferometry" by
+  Christian Perrier in "Diffraction-limited imaging with very large telescopes",
+  NATO ASI Series C, Vol. 274, edited by D. Alloin and J.-M. Mariotti, 1989
+  (p. 99).
+ */
+/*----------------------------------------------------------------------------*/
+static cpl_image * irplib_strehl_generate_otf(
+        double  m1,
+        double  m2,
+        double  lam,
+        double  dlam,
+        int     size,
+        double  pscale)
+{
+    cpl_image   *   otf_image;
+    double      *   otf_data;
+    double          obs_ratio ;  /* m1 / m2    */
+    double          f_max ;      /* cut-off frequency        */
+    int             pix0 ;      /* Pixel corresponding to the zero frequency */
+    double          a, x, y;
+    double          f, rsq, fc, invfc, lambda;
+    double          sincy;
+    double          invsize;
+    register int    pos;
+    int             i, j, k;
+
+
+    cpl_ensure(m2   > 0.0,      CPL_ERROR_ILLEGAL_INPUT, NULL);
+    cpl_ensure(m1   > m2,       CPL_ERROR_ILLEGAL_INPUT, NULL);
+    cpl_ensure(lam  > 0.0,      CPL_ERROR_ILLEGAL_INPUT, NULL);
+    cpl_ensure(dlam > 0.0,      CPL_ERROR_ILLEGAL_INPUT, NULL);
+    cpl_ensure(size > 0,        CPL_ERROR_ILLEGAL_INPUT, NULL);
+    cpl_ensure(pscale > 0.0,    CPL_ERROR_ILLEGAL_INPUT, NULL);
+
+    /* Convert pixel scale from sec to radians, microns in meters    */
+    pscale /= (double)206265;
+    lam /= (double)1.0e6;
+    dlam /= (double)1.0e6;
+
+    /* Obscuration ratio    */
+    obs_ratio = m2 / m1;
+
+    /* Pixel corresponding to the zero frequency    */
+    pix0 = size/2;
+    invsize = (double)1.0 / (double)size;
+
+    /* Cut-off frequency in pixels  */
+    f_max = m1 * pscale * (double)size / lam;
+
+    /* Allocate for output image    */
+    otf_image = cpl_image_new(size, size, CPL_TYPE_DOUBLE);
+    if (otf_image==NULL) return NULL;
+    otf_data = cpl_image_get_data_double(otf_image);
+
+    /* Now compute the OTF  */
+    /* OPTIMIZED CODE !!! LIMITED READABILITY !!!   */
+
+    for (k=1 ; k<=9 ; k++) {    /* iteration on the wavelength  */
+        /* Compute intermediate cut-off frequency   */
+        lambda = (double)(lam - dlam*(double)(k-5)/8.0);
+        fc = (double)f_max * (double)lam / lambda;
+        invfc = 1.0 / fc;
+
+        /* Convolution with the detector pixels */
+        pos = 0;
+        for (j=0 ; j<size ; j++) {
+            y = (double)(j-pix0);
+            sincy = PSF_sinc(CPL_MATH_PI * y * invsize);
+            for (i=0 ; i<size ; i++) {
+                x = (double)(i-pix0);
+                rsq = x*x + y*y;
+                if (rsq < fc*fc) {
+                    if (rsq < 0.01)
+                        a = 1.0;
+                    else {
+                        f = sqrt(rsq) * invfc;
+                        a = PSF_TelOTF(f,obs_ratio) *
+                            PSF_sinc(CPL_MATH_PI * x * invsize) * sincy;
+                    }
+                } else {
+                    a = 0.0;
+                }
+                otf_data[pos++] += a / 9.0;
+            }
+        }
+    }
+    return otf_image;
+}
+
+/*----------------------------------------------------------------------------*
+ * H1 function
+ *----------------------------------------------------------------------------*/
+static double PSF_H1(
+        double  f,
+        double  u,
+        double  v)
+{
+    const double e = fabs(1.0-v) > 0.0 ? -1.0 : 1.0; /* e = 1.0 iff v = 1.0 */
+
+    return((v*v/CPL_MATH_PI)*acos((f/v)*(1.0+e*(1.0-u*u)/(4.0*f*f))));
+}
+
+/*----------------------------------------------------------------------------*
+ * H2 function
+ *----------------------------------------------------------------------------*/
+static double PSF_H2(double  f,
+                     double  u)
+{
+    const double tmp1 = (2.0 * f) / (1.0 + u);
+    const double tmp2 = (1.0 - u) / (2.0 * f);
+
+    return -1.0 * (f/CPL_MATH_PI) * (1.0+u)
+        * sqrt((1.0-tmp1*tmp1)*(1.0-tmp2*tmp2));
+}
+
+/*----------------------------------------------------------------------------*
+ * G function
+ *----------------------------------------------------------------------------*/
+static double PSF_G(double  f,
+                    double  u)
+{
+    if (f <= (1.0-u)/2.0) return(u*u);
+    if (f >= (1.0+u)/2.0) return(0.0);
+    else return(PSF_H1(f,u,1.0) + PSF_H1(f,u,u) + PSF_H2(f,u));
+}
+
+/*----------------------------------------------------------------------------*
+ * sinc function
+ *----------------------------------------------------------------------------*/
+static double PSF_sinc(double x)
+{
+  return fabs(x) > fabs(sin(x)) ? sin(x)/x : 1.0;
+}
+
+/*----------------------------------------------------------------------------*
+ * Telescope OTF function
+ *----------------------------------------------------------------------------*/
+static double PSF_TelOTF(double  f,
+                         double  u)
+{
+    return((PSF_G(f,1.0)+u*u*PSF_G(f/u,1.0)-2.0*PSF_G(f,u))/(1.0-u*u));
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Find the peak flux inside a disk
+  @param    self        Image with pixel-type float
+  @param    xpos        The x position of the disk center
+  @param    ypos        The y position of the disk center
+  @param    radius      The positive radius
+  @param    ppeak       Pointer to the Star Peak
+  @return   0 iff successful
+  @note *ppeak is undefined on error
+
+ */
+/*----------------------------------------------------------------------------*/
+cpl_error_code irplib_strehl_disk_max(const cpl_image * self,
+                                             double            xpos,
+                                             double            ypos,
+                                             double            radius,
+                                             double          * ppeak)
+{
+
+    const double    sqr = radius * radius;
+    double          sqrest;
+    const float *   pself;
+    float           peak = FLT_MAX;  /* Avoid (false) uninit warning */
+    double          yj, xi;
+    int             nx, ny;
+    int             lx, ly, ux, uy;
+    int             i, j;
+    cpl_boolean     first = CPL_TRUE;
+
+
+    /* Check entries */
+    cpl_ensure_code(ppeak != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(self  != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(cpl_image_get_type(self) == CPL_TYPE_FLOAT,
+                    CPL_ERROR_UNSUPPORTED_MODE);
+    cpl_ensure_code(radius > 0.0, CPL_ERROR_ILLEGAL_INPUT);
+
+    nx = cpl_image_get_size_x(self);
+    ny = cpl_image_get_size_y(self);
+
+    /* Round down */
+    lx = (int)(xpos - radius);
+    ly = (int)(ypos - radius);
+    if (lx < 0) lx = 0;
+    if (ly < 0) ly = 0;
+
+    /* Round up */
+    ux = (int)(xpos + radius) + 1;
+    uy = (int)(ypos + radius) + 1;
+    if (ux > (nx-1)) ux = nx-1;
+    if (uy > (ny-1)) uy = ny-1;
+
+    pself = cpl_image_get_data_float_const(self);
+    for (j=ly ; j<uy ; j++) {
+        yj = (double)j - ypos;
+        sqrest = sqr - yj * yj;
+        for (i=lx; i<ux ; i++) {
+            xi = (double)i - xpos;
+            if (sqrest >= xi * xi && irplib_isnan(pself[i+j*nx]) == 0) {
+                if (first || pself[i+j*nx] > peak) {
+                    first = CPL_FALSE;
+                    peak = pself[i+j*nx];
+                }
+            }
+        }
+    }
+
+    cpl_ensure_code(!first, CPL_ERROR_DATA_NOT_FOUND);
+
+    *ppeak = (double)peak;
+
+    return CPL_ERROR_NONE;
+}
diff --git a/irplib/irplib_strehl.h b/irplib/irplib_strehl.h
new file mode 100644
index 0000000..9e1032b
--- /dev/null
+++ b/irplib/irplib_strehl.h
@@ -0,0 +1,75 @@
+/* $Id: irplib_strehl.h,v 1.12 2009/06/29 14:32:53 kmirny Exp $
+ *
+ * This file is part of the irplib package
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: kmirny $
+ * $Date: 2009/06/29 14:32:53 $
+ * $Revision: 1.12 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifndef IRPLIB_STREHL_H
+#define IRPLIB_STREHL_H
+
+/*-----------------------------------------------------------------------------
+                                   Includes
+ -----------------------------------------------------------------------------*/
+
+#include <cpl.h>
+
+/*-----------------------------------------------------------------------------
+                                   Define
+ -----------------------------------------------------------------------------*/
+
+#ifndef IRPLIB_STREHL_BORDER
+#define IRPLIB_STREHL_BORDER        5
+#endif
+
+typedef enum {
+    IRPLIB_BG_METHOD_AVER_REJ,
+    IRPLIB_BG_METHOD_MEDIAN
+} irplib_strehl_bg_method;
+
+/*-----------------------------------------------------------------------------
+                               Functions prototypes
+ -----------------------------------------------------------------------------*/
+
+cpl_error_code irplib_strehl_compute(const cpl_image *, double, double, double,
+                                     double, double, int, double, double,
+                                     double, double, double, int, int,
+                                     double *, double *, double *, double *,
+                                     double *, double *, double *, double *);
+cpl_error_code irplib_strehl_mark_bad_and_compute(
+					cpl_image *, double, double, double,
+					double, double, int, double, double,
+					double, double, double, int, int,
+					double *, double *, double *, double *,
+					double *, double *, double *, double *);
+double irplib_strehl_disk_flux(const cpl_image *, double, double, double,
+                               double);
+
+double irplib_strehl_ring_background(const cpl_image *, double, double, double,
+                                     double, irplib_strehl_bg_method);
+
+cpl_image * irplib_strehl_generate_psf(double, double, double, double, double,
+                                       int);
+cpl_error_code irplib_strehl_disk_max(const cpl_image *, double, double,
+                                             double, double *);
+#endif
diff --git a/irplib/irplib_utils.c b/irplib/irplib_utils.c
new file mode 100644
index 0000000..76925ca
--- /dev/null
+++ b/irplib/irplib_utils.c
@@ -0,0 +1,1659 @@
+/* $Id: irplib_utils.c,v 1.78 2012/05/08 13:56:09 llundin Exp $
+ *
+ * This file is part of the irplib package
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: llundin $
+ * $Date: 2012/05/08 13:56:09 $
+ * $Revision: 1.78 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+/*-----------------------------------------------------------------------------
+                                   Includes
+ -----------------------------------------------------------------------------*/
+
+#include <math.h>
+
+#include <string.h>
+#include <assert.h>
+
+#include <cpl.h>
+
+#include "irplib_utils.h"
+
+/*-----------------------------------------------------------------------------
+                           Defines
+ -----------------------------------------------------------------------------*/
+
+/* TEMPORARY SUPPORT OF CPL 5.x */
+#ifndef CPL_SIZE_FORMAT
+#define CPL_SIZE_FORMAT "d"
+#define cpl_size int
+#endif
+/* END TEMPORARY SUPPORT OF CPL 5.x */
+
+#ifndef inline
+#define inline /* inline */
+#endif
+
+/*-----------------------------------------------------------------------------
+                           Missing Function Prototypes
+ -----------------------------------------------------------------------------*/
+
+#if defined HAVE_ISNAN && HAVE_ISNAN != 0
+#if !defined isnan && defined HAVE_DECL_ISNAN && HAVE_DECL_ISNAN == 0
+/* HP-UX and Solaris may have isnan() available at link-time
+   without the prototype */
+int isnan(double);
+#endif
+#endif
+
+/*-----------------------------------------------------------------------------
+                           Private Function Prototypes
+ -----------------------------------------------------------------------------*/
+
+inline static double irplib_data_get_double(const void *, cpl_type, int)
+#ifdef CPL_HAVE_GNUC_NONNULL
+     __attribute__((nonnull))
+#endif
+    ;
+
+inline static void irplib_data_set_double(void *, cpl_type, int, double)
+#ifdef CPL_HAVE_GNUC_NONNULL
+     __attribute__((nonnull))
+#endif
+    ;
+
+
+static
+void irplib_errorstate_dump_one_level(void (*)(const char *,
+                                               const char *, ...)
+  #ifdef __GNUC__
+      __attribute__((format (printf, 2, 3)))
+  #endif
+                                      , unsigned, unsigned, unsigned);
+static double frame_get_exptime(const cpl_frame * pframe);
+static void quicksort(int* index, double* exptime, int left, int right);
+
+static cpl_error_code irplib_dfs_product_save(cpl_frameset *,
+                                              cpl_propertylist *,
+                                              const cpl_parameterlist *,
+                                              const cpl_frameset *,
+                                              const cpl_frame *,
+                                              const cpl_imagelist *,
+                                              const cpl_image *,
+                                              cpl_type,
+                                              const cpl_table *,
+                                              const cpl_propertylist *,
+                                              const char *,
+                                              const cpl_propertylist *,
+                                              const char *,
+                                              const char *,
+                                              const char *);
+
+/*----------------------------------------------------------------------------*/
+/**
+ * @defgroup irplib_utils     Miscellaneous Utilities
+ */
+/*----------------------------------------------------------------------------*/
+/**@{*/
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Dump a single CPL error at the CPL warning level
+  @param    self      The number of the current error to be dumped
+  @param    first     The number of the first error to be dumped
+  @param    last      The number of the last error to be dumped
+  @return   void
+  @see cpl_errorstate_dump_one
+
+  FIXME: Move this function to the CPL errorstate module.
+
+ */
+/*----------------------------------------------------------------------------*/
+void irplib_errorstate_dump_warning(unsigned self, unsigned first,
+                                    unsigned last)
+{
+
+    irplib_errorstate_dump_one_level(&cpl_msg_warning, self, first, last);
+
+}
+
+static cpl_polynomial * irplib_polynomial_fit_1d_create_common(
+		const cpl_vector    *   x_pos,
+        const cpl_vector    *   values,
+        int                     degree,
+        double              *   mse,
+        double				*  rechisq
+        );
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Dump a single CPL error at the CPL info level
+  @param    self      The number of the current error to be dumped
+  @param    first     The number of the first error to be dumped
+  @param    last      The number of the last error to be dumped
+  @return   void
+  @see cpl_errorstate_dump_one
+
+ */
+/*----------------------------------------------------------------------------*/
+void irplib_errorstate_dump_info(unsigned self, unsigned first,
+                                    unsigned last)
+{
+
+    irplib_errorstate_dump_one_level(&cpl_msg_info, self, first, last);
+
+}
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Dump a single CPL error at the CPL debug level
+  @param    self      The number of the current error to be dumped
+  @param    first     The number of the first error to be dumped
+  @param    last      The number of the last error to be dumped
+  @return   void
+  @see cpl_errorstate_dump_one
+
+ */
+/*----------------------------------------------------------------------------*/
+void irplib_errorstate_dump_debug(unsigned self, unsigned first,
+                                    unsigned last)
+{
+
+    irplib_errorstate_dump_one_level(&cpl_msg_debug, self, first, last);
+
+}
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief  Save an image as a DFS-compliant pipeline product
+  @param  allframes  The list of input frames for the recipe
+  @param  parlist    The list of input parameters
+  @param  usedframes The list of raw/calibration frames used for this product
+  @param  image      The image to be saved
+  @param  bpp        Bits per pixel
+  @param  recipe     The recipe name
+  @param  procat     The product category tag
+  @param  applist    Optional propertylist to append to primary header or NULL
+  @param  remregexp  Optional regexp of properties not to put in main header
+  @param  pipe_id    PACKAGE "/" PACKAGE_VERSION
+  @param  filename   Filename of created product
+  @note The image may be NULL in which case only the header information is saved
+        but passing a NULL image is deprecated, use cpl_dfs_save_propertylist().
+  @note remregexp may be NULL
+  @return CPL_ERROR_NONE or the relevant CPL error code on error
+  @see cpl_dfs_save_image().
+
+ */
+/*----------------------------------------------------------------------------*/
+cpl_error_code irplib_dfs_save_image(cpl_frameset            * allframes,
+                                     const cpl_parameterlist * parlist,
+                                     const cpl_frameset      * usedframes,
+                                     const cpl_image         * image,
+                                     cpl_type_bpp              bpp,
+                                     const char              * recipe,
+                                     const char              * procat,
+                                     const cpl_propertylist  * applist,
+                                     const char              * remregexp,
+                                     const char              * pipe_id,
+                                     const char              * filename)
+{
+    cpl_errorstate     prestate = cpl_errorstate_get();
+    cpl_propertylist * prolist  = applist ? cpl_propertylist_duplicate(applist)
+        : cpl_propertylist_new();
+
+    cpl_propertylist_update_string(prolist, CPL_DFS_PRO_CATG, procat);
+
+    irplib_dfs_save_image_(allframes, NULL, parlist, usedframes, NULL, image,
+                           bpp, recipe, prolist, remregexp, pipe_id, filename);
+
+    cpl_propertylist_delete(prolist);
+
+    cpl_ensure_code(cpl_errorstate_is_equal(prestate), cpl_error_get_code());
+
+    return CPL_ERROR_NONE;
+
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief  Save a propertylist as a DFS-compliant pipeline product
+  @param  allframes  The list of input frames for the recipe
+  @param  parlist    The list of input parameters
+  @param  usedframes The list of raw/calibration frames used for this product
+  @param  recipe     The recipe name
+  @param  procat     The product category tag
+  @param  applist    Optional propertylist to append to primary header or NULL
+  @param  remregexp  Optional regexp of properties not to put in main header
+  @param  pipe_id    PACKAGE "/" PACKAGE_VERSION
+  @param  filename   Filename of created product
+  @note remregexp may be NULL
+  @return CPL_ERROR_NONE or the relevant CPL error code on error
+  @see cpl_dfs_save_propertylist().
+
+ */
+/*----------------------------------------------------------------------------*/
+cpl_error_code
+irplib_dfs_save_propertylist(cpl_frameset            * allframes,
+                             const cpl_parameterlist * parlist,
+                             const cpl_frameset      * usedframes,
+                             const char              * recipe,
+                             const char              * procat,
+                             const cpl_propertylist  * applist,
+                             const char              * remregexp,
+                             const char              * pipe_id,
+                             const char              * filename)
+{
+    cpl_errorstate     prestate = cpl_errorstate_get();
+    cpl_propertylist * prolist  = applist ? cpl_propertylist_duplicate(applist)
+        : cpl_propertylist_new();
+
+    cpl_propertylist_update_string(prolist, CPL_DFS_PRO_CATG, procat);
+
+    cpl_dfs_save_propertylist(allframes, NULL, parlist, usedframes, NULL,
+                              recipe, prolist, remregexp, pipe_id, filename);
+
+    cpl_propertylist_delete(prolist);
+
+    cpl_ensure_code(cpl_errorstate_is_equal(prestate), cpl_error_get_code());
+
+    return CPL_ERROR_NONE;
+
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief  Save an imagelist as a DFS-compliant pipeline product
+  @param  allframes  The list of input frames for the recipe
+  @param  parlist    The list of input parameters
+  @param  usedframes The list of raw/calibration frames used for this product
+  @param  imagelist  The imagelist to be saved
+  @param  bpp        Bits per pixel
+  @param  recipe     The recipe name
+  @param  procat     The product category tag
+  @param  applist    Optional propertylist to append to primary header or NULL
+  @param  remregexp  Optional regexp of properties not to put in main header
+  @param  pipe_id    PACKAGE "/" PACKAGE_VERSION
+  @param  filename   Filename of created product
+  @note remregexp may be NULL
+  @return CPL_ERROR_NONE or the relevant CPL error code on error
+  @see cpl_dfs_save_imagelist().
+
+ */
+/*----------------------------------------------------------------------------*/
+cpl_error_code irplib_dfs_save_imagelist(cpl_frameset            * allframes,
+                                         const cpl_parameterlist * parlist,
+                                         const cpl_frameset      * usedframes,
+                                         const cpl_imagelist     * imagelist,
+                                         cpl_type_bpp              bpp,
+                                         const char              * recipe,
+                                         const char              * procat,
+                                         const cpl_propertylist  * applist,
+                                         const char              * remregexp,
+                                         const char              * pipe_id,
+                                         const char              * filename)
+{
+    cpl_errorstate     prestate = cpl_errorstate_get();
+    cpl_propertylist * prolist  = applist ? cpl_propertylist_duplicate(applist)
+        : cpl_propertylist_new();
+
+    cpl_propertylist_update_string(prolist, CPL_DFS_PRO_CATG, procat);
+
+    cpl_dfs_save_imagelist(allframes, NULL, parlist, usedframes, NULL,
+                           imagelist, bpp, recipe, prolist, remregexp, pipe_id,
+                           filename);
+
+    cpl_propertylist_delete(prolist);
+
+    cpl_ensure_code(cpl_errorstate_is_equal(prestate), cpl_error_get_code());
+
+    return CPL_ERROR_NONE;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief  Save a table as a DFS-compliant pipeline product
+  @param  allframes  The list of input frames for the recipe
+  @param  parlist    The list of input parameters
+  @param  usedframes The list of raw/calibration frames used for this product
+  @param  table      The table to be saved
+  @param  tablelist  Optional propertylist to use in table extension or NULL
+  @param  recipe     The recipe name
+  @param  procat     The product category tag
+  @param  applist    Optional propertylist to append to primary header or NULL
+  @param  remregexp  Optional regexp of properties not to put in main header
+  @param  pipe_id    PACKAGE "/" PACKAGE_VERSION
+  @param  filename   Filename of created product
+  @return CPL_ERROR_NONE or the relevant CPL error code on error
+  @see cpl_dfs_save_table().
+
+ */
+/*----------------------------------------------------------------------------*/
+cpl_error_code irplib_dfs_save_table(cpl_frameset            * allframes,
+                                     const cpl_parameterlist * parlist,
+                                     const cpl_frameset      * usedframes,
+                                     const cpl_table         * table,
+                                     const cpl_propertylist  * tablelist,
+                                     const char              * recipe,
+                                     const char              * procat,
+                                     const cpl_propertylist  * applist,
+                                     const char              * remregexp,
+                                     const char              * pipe_id,
+                                     const char              * filename)
+{
+
+    cpl_errorstate     prestate = cpl_errorstate_get();
+    cpl_propertylist * prolist  = applist ? cpl_propertylist_duplicate(applist)
+        : cpl_propertylist_new();
+
+    cpl_propertylist_update_string(prolist, CPL_DFS_PRO_CATG, procat);
+
+    cpl_dfs_save_table(allframes, NULL, parlist, usedframes, NULL,
+                           table, tablelist, recipe, prolist, remregexp,
+                           pipe_id, filename);
+
+    cpl_propertylist_delete(prolist);
+
+    cpl_ensure_code(cpl_errorstate_is_equal(prestate), cpl_error_get_code());
+
+    return CPL_ERROR_NONE;
+}
+
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief  Save an image as a DFS-compliant pipeline product
+  @param  allframes  The list of input frames for the recipe
+  @param  header     NULL, or filled with properties written to product header
+  @param  parlist    The list of input parameters
+  @param  usedframes The list of raw/calibration frames used for this product
+  @param  inherit    NULL or product frames inherit their header from this frame
+  @param  image      The image to be saved
+  @param  type       The type used to represent the data in the file
+  @param  recipe     The recipe name
+  @param  applist    Propertylist to append to primary header, w. PRO.CATG
+  @param  remregexp  Optional regexp of properties not to put in main header
+  @param  pipe_id    PACKAGE "/" PACKAGE_VERSION
+  @param  filename   Filename of created product
+  @note The image may be NULL in which case only the header information is saved
+        but passing a NULL image is deprecated, use cpl_dfs_save_propertylist().
+  @note remregexp may be NULL
+  @note applist must contain a string-property with key CPL_DFS_PRO_CATG
+  @note On success and iff header is non-NULL, it will be emptied and then
+        filled with the properties written to the primary header of the product
+  @return CPL_ERROR_NONE or the relevant CPL error code on error
+  @see cpl_dfs_save_image()
+  @note applist is copied with cpl_propertylist_copy_property_regexp() instead
+        pf cpl_propertylist_append()
+
+ */
+/*----------------------------------------------------------------------------*/
+cpl_error_code irplib_dfs_save_image_(cpl_frameset            * allframes,
+                                      cpl_propertylist        * header,
+                                      const cpl_parameterlist * parlist,
+                                      const cpl_frameset      * usedframes,
+                                      const cpl_frame         * inherit,
+                                      const cpl_image         * image,
+                                      cpl_type                  type,
+                                      const char              * recipe,
+                                      const cpl_propertylist  * applist,
+                                      const char              * remregexp,
+                                      const char              * pipe_id,
+                                      const char              * filename)
+{
+    return
+        irplib_dfs_product_save(allframes, header, parlist, usedframes, inherit,
+                                NULL, image, type, NULL, NULL, recipe,
+                                applist, remregexp, pipe_id, filename)
+        ? cpl_error_set_where(cpl_func) : CPL_ERROR_NONE;
+
+}
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief  Save either an image or table as a pipeline product
+  @param  allframes  The list of input frames for the recipe
+  @param  header     NULL, or filled with properties written to product header
+  @param  parlist    The list of input parameters
+  @param  usedframes The list of raw/calibration frames used for this product
+  @param  inherit    NULL, or frame from which header information is inherited
+  @param  imagelist  The imagelist to be saved or NULL
+  @param  image      The image to be saved or NULL
+  @param  type       The type used to represent the data in the file
+  @param  table      The table to be saved or NULL
+  @param  tablelist  Optional propertylist to use in table extension or NULL
+  @param  recipe     The recipe name
+  @param  applist    Optional propertylist to append to main header or NULL
+  @param  remregexp  Optional regexp of properties not to put in main header
+  @param  pipe_id    PACKAGE "/" PACKAGE_VERSION
+  @param  filename   Filename of created product
+  @return CPL_ERROR_NONE or the relevant CPL error code on error
+  @see cpl_dfs_product_save()
+  @note applist is copied with cpl_propertylist_copy_property_regexp() instead
+        pf cpl_propertylist_append()
+
+ */
+/*----------------------------------------------------------------------------*/
+
+static
+cpl_error_code irplib_dfs_product_save(cpl_frameset            * allframes,
+                                       cpl_propertylist        * header,
+                                       const cpl_parameterlist * parlist,
+                                       const cpl_frameset      * usedframes,
+                                       const cpl_frame         * inherit,
+                                       const cpl_imagelist     * imagelist,
+                                       const cpl_image         * image,
+                                       cpl_type                  type,
+                                       const cpl_table         * table,
+                                       const cpl_propertylist  * tablelist,
+                                       const char              * recipe,
+                                       const cpl_propertylist  * applist,
+                                       const char              * remregexp,
+                                       const char              * pipe_id,
+                                       const char              * filename) {
+
+    const char       * procat;
+    cpl_propertylist * plist;
+    cpl_frame        * product_frame;
+    /* Inside this function the product-types are numbered:
+       0: imagelist
+       1: table
+       2: image
+       3: propertylist only
+    */
+    const unsigned     pronum
+        = imagelist != NULL ? 0 : table != NULL ? 1 :  (image != NULL ? 2 : 3);
+    const char       * proname[] = {"imagelist", "table", "image",
+                                    "propertylist"};
+    /* FIXME: Define a frame type for an imagelist and when data-less */
+    const int          protype[] = {CPL_FRAME_TYPE_ANY, CPL_FRAME_TYPE_TABLE,
+                                    CPL_FRAME_TYPE_IMAGE, CPL_FRAME_TYPE_ANY};
+    cpl_error_code     error = CPL_ERROR_NONE;
+
+
+    /* No more than one of imagelist, table and image may be non-NULL */
+    /* tablelist may only be non-NULL when table is non-NULL */
+    if (imagelist != NULL) {
+        assert(pronum == 0);
+        assert(image == NULL);
+        assert(table == NULL);
+        assert(tablelist == NULL);
+    } else if (table != NULL) {
+        assert(pronum == 1);
+        assert(imagelist == NULL);
+        assert(image == NULL);
+    } else if (image != NULL) {
+        assert(pronum == 2);
+        assert(imagelist == NULL);
+        assert(table == NULL);
+        assert(tablelist == NULL);
+    } else {
+        assert(pronum == 3);
+        assert(imagelist == NULL);
+        assert(table == NULL);
+        assert(tablelist == NULL);
+        assert(image == NULL);
+    }
+
+    cpl_ensure_code(allframes  != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(parlist    != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(usedframes != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(recipe     != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(applist    != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(pipe_id    != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(filename   != NULL, CPL_ERROR_NULL_INPUT);
+
+    procat = cpl_propertylist_get_string(applist, CPL_DFS_PRO_CATG);
+
+    cpl_ensure_code(procat     != NULL, cpl_error_get_code());
+
+    cpl_msg_info(cpl_func, "Writing FITS %s product(%s): %s", proname[pronum],
+                 procat, filename);
+
+    product_frame = cpl_frame_new();
+
+    /* Create product frame */
+    error |= cpl_frame_set_filename(product_frame, filename);
+    error |= cpl_frame_set_tag(product_frame, procat);
+    error |= cpl_frame_set_type(product_frame, protype[pronum]);
+    error |= cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT);
+    error |= cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL);
+
+    if (error) {
+        cpl_frame_delete(product_frame);
+        return cpl_error_set_where(cpl_func);
+    }
+
+    if (header != NULL) {
+        cpl_propertylist_empty(header);
+        plist = header;
+    } else {
+        plist = cpl_propertylist_new();
+    }
+
+    /* Add any QC parameters here */
+    if (applist != NULL) error = cpl_propertylist_copy_property_regexp(plist,
+                                                                       applist,
+                                                                       ".", 0);
+
+    /* Add DataFlow keywords */
+    if (!error)
+        error = cpl_dfs_setup_product_header(plist, product_frame, usedframes,
+                                             parlist, recipe, pipe_id,
+                                             "PRO-1.15", inherit);
+
+    if (remregexp != NULL && !error) {
+        cpl_errorstate prestate = cpl_errorstate_get();
+        (void)cpl_propertylist_erase_regexp(plist, remregexp, 0);
+        if (!cpl_errorstate_is_equal(prestate)) error = cpl_error_get_code();
+    }
+
+    if (!error) {
+        switch (pronum) {
+            case 0:
+                error = cpl_imagelist_save(imagelist, filename, type, plist,
+                                           CPL_IO_CREATE);
+                break;
+            case 1:
+                error = cpl_table_save(table, plist, tablelist, filename,
+                                       CPL_IO_CREATE);
+                break;
+            case 2:
+                error = cpl_image_save(image, filename, type, plist,
+                                       CPL_IO_CREATE);
+                break;
+            default:
+                /* case 3: */
+                error = cpl_propertylist_save(plist, filename, CPL_IO_CREATE);
+        }
+    }
+
+    if (!error) {
+        /* Insert the frame of the saved file in the input frameset */
+        error = cpl_frameset_insert(allframes, product_frame);
+
+    } else {
+        cpl_frame_delete(product_frame);
+    }
+
+    if (plist != header) cpl_propertylist_delete(plist);
+
+    cpl_ensure_code(!error, error);
+
+    return CPL_ERROR_NONE;
+
+}    
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief Split the values in an image in three according to two thresholds
+  @param self       The image to split
+  @param im_low     If non-NULL low-valued pixels are assigned to this image
+  @param im_mid     If non-NULL middle-valued pixels are assigned to this image
+  @param im_high    If non-NULL high-valued pixels are assigned to this image
+  @param th_low     The lower threshold
+  @param isleq_low  Ift true use less than or equal
+  @param th_high    The upper threshold, must be at least th_low
+  @param isgeq_high Iff true use greater than or equal
+  @param alt_low    Assign this value when the pixel value is not low
+  @param alt_high   Assign this value, when the pixel value is not high
+  @param isbad_low  Flag non-low pixels as bad
+  @param isbad_mid  Flag non-mid pixels as bad
+  @param isbad_high Flag non-high pixels as bad
+  @return CPL_ERROR_NONE or the relevant CPL error code on error
+  @note At least one output image must be non-NULL; all non-NULL images must
+        be of identical size, but may be of any pixel-type.
+        self may be passed as one of the output images for an in-place split.
+
+
+   FIXME: This function is way too slow and perhaps over-engineered...
+
+  A split in two is achieved with th_low equal th_high (in this case there
+  is little reason for im_mid to be non-NULL).
+
+  All pixel values in the output images are reset,
+  as well as their bad pixels maps.
+
+  If an input pixel-value is flagged as bad, then the receiving pixel in the
+  output image is flagged as well.
+
+   @par The same image may be passed more than once which allows a split
+        into one image with the mid-valued pixels and another with both the
+        low and high-valued pixels, i.e.
+   @code
+       irplib_image_split(source, dest, im_mid, dest,
+                          th_low,  isleq_low, th_high, isgeq_high,
+                          alt_low, alt_high,
+                          isbad_low, isbad_mid, isbad_high);
+   @endcode
+
+   @par These two calls are equivalent:
+   @code
+     cpl_image_threshold(img, th_low, th_high, alt_low, alt_high);
+   @endcode
+
+   @code
+     irplib_image_split(img, NULL, img, NULL,
+                        th_low,  CPL_TRUE, th_high, CPL_TRUE,
+                        alt_low, alt_high, dontcare, CPL_FALSE, dontcare);
+   @endcode
+
+ */
+/*----------------------------------------------------------------------------*/
+cpl_error_code irplib_image_split(const cpl_image * self,
+                                  cpl_image * im_low,
+                                  cpl_image * im_mid,
+                                  cpl_image * im_high,
+                                  double th_low,
+                                  cpl_boolean isleq_low,
+                                  double th_high,
+                                  cpl_boolean isgeq_high,
+                                  double alt_low,
+                                  double alt_high,
+                                  cpl_boolean isbad_low,
+                                  cpl_boolean isbad_mid,
+                                  cpl_boolean isbad_high)
+{
+
+    const void       * selfdata = cpl_image_get_data_const(self);
+    /* hasbpm reduces check-overhead if self does not have a bpm, and if
+       self is also passed as an output image, that ends up with bad pixels */
+    /* FIXME: Need a proper way to know if a bpm has been allocated :-((((((( */
+    const cpl_boolean  hasbpm
+        = cpl_image_count_rejected(self) ? CPL_TRUE : CPL_FALSE;
+    const cpl_binary * selfbpm = hasbpm
+        ? cpl_mask_get_data_const(cpl_image_get_bpm_const(self)) : NULL;
+    const cpl_type     selftype = cpl_image_get_type(self);
+    const int          nx = cpl_image_get_size_x(self);
+    const int          ny = cpl_image_get_size_y(self);
+    const int          npix = nx * ny;
+    const cpl_boolean  do_low   = im_low  != NULL;
+    const cpl_boolean  do_mid   = im_mid  != NULL;
+    const cpl_boolean  do_high  = im_high != NULL;
+    void             * lowdata  = NULL;
+    void             * middata  = NULL;
+    void             * highdata = NULL;
+    cpl_binary       * lowbpm   = NULL;
+    cpl_binary       * midbpm   = NULL;
+    cpl_binary       * highbpm  = NULL;
+    const cpl_type     lowtype
+        = do_low ? cpl_image_get_type(im_low) : CPL_TYPE_INVALID;
+    const cpl_type     midtype
+        = do_mid ? cpl_image_get_type(im_mid) : CPL_TYPE_INVALID;
+    const cpl_type     hightype
+        = do_high ? cpl_image_get_type(im_high) : CPL_TYPE_INVALID;
+    int i;
+
+
+    cpl_ensure_code(self != NULL,                CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(do_low || do_mid || do_high, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(th_low <= th_high,           CPL_ERROR_ILLEGAL_INPUT);
+
+    if (do_low) {
+        cpl_ensure_code(cpl_image_get_size_x(im_low) == nx,
+                        CPL_ERROR_INCOMPATIBLE_INPUT);
+        cpl_ensure_code(cpl_image_get_size_y(im_low) == ny,
+                        CPL_ERROR_INCOMPATIBLE_INPUT);
+        lowdata = cpl_image_get_data(im_low);
+    }
+
+    if (do_mid) {
+        cpl_ensure_code(cpl_image_get_size_x(im_mid) == nx,
+                        CPL_ERROR_INCOMPATIBLE_INPUT);
+        cpl_ensure_code(cpl_image_get_size_y(im_mid) == ny,
+                        CPL_ERROR_INCOMPATIBLE_INPUT);
+        middata = cpl_image_get_data(im_mid);
+    }
+
+    if (do_high) {
+        cpl_ensure_code(cpl_image_get_size_x(im_high) == nx,
+                        CPL_ERROR_INCOMPATIBLE_INPUT);
+        cpl_ensure_code(cpl_image_get_size_y(im_high) == ny,
+                        CPL_ERROR_INCOMPATIBLE_INPUT);
+        highdata = cpl_image_get_data(im_high);
+    }
+
+    /* From this point a failure would indicate a serious bug in CPL */
+
+    for (i = 0; i < npix; i++) {
+        const double value = irplib_data_get_double(selfdata, selftype, i);
+        cpl_boolean  isalt_low   = do_low;
+        cpl_boolean  isalt_mid   = do_mid;
+        cpl_boolean  isalt_high  = do_high;
+        cpl_boolean  setbad_low  = do_low;
+        cpl_boolean  setbad_mid  = do_mid;
+        cpl_boolean  setbad_high = do_high;
+        const void * setdata     = NULL;
+        double       alt_mid     = 0.0; /* Avoid (false) uninit warning */
+
+        if (isleq_low ? value <= th_low : value < th_low) {
+            if (do_low) {
+                isalt_low = CPL_FALSE;
+                irplib_data_set_double(lowdata, lowtype, i, value);
+                setbad_low = hasbpm && selfbpm[i];
+                setdata = lowdata;
+            }
+            alt_mid = alt_low;
+        } else if (isgeq_high ? value >= th_high : value > th_high) {
+            if (do_high) {
+                isalt_high = CPL_FALSE;
+                irplib_data_set_double(highdata, hightype, i, value);
+                setbad_high = hasbpm && selfbpm[i];
+                setdata = highdata;
+            }
+            alt_mid = alt_high;
+        } else if (do_mid) {
+            isalt_mid = CPL_FALSE;
+            irplib_data_set_double(middata, midtype, i, value);
+            setbad_mid = hasbpm && selfbpm[i];
+            setdata = middata;
+        }
+
+        if (isalt_low && lowdata != setdata) {
+            irplib_data_set_double(lowdata, lowtype, i, alt_low);
+            setbad_low = isbad_low;
+        }
+        if (isalt_mid && middata != setdata) {
+            irplib_data_set_double(middata, midtype, i, alt_mid);
+            setbad_mid = isbad_mid;
+        }
+        if (isalt_high && highdata != setdata) {
+            irplib_data_set_double(highdata, hightype, i, alt_high);
+            setbad_high = isbad_high;
+        }
+
+        if (setbad_low) {
+            if (lowbpm == NULL) lowbpm
+                = cpl_mask_get_data(cpl_image_get_bpm(im_low));
+            lowbpm[i] = CPL_BINARY_1;
+        }
+        if (setbad_mid) {
+            if (midbpm == NULL) midbpm
+                = cpl_mask_get_data(cpl_image_get_bpm(im_mid));
+            midbpm[i] = CPL_BINARY_1;
+        }
+        if (setbad_high) {
+            if (highbpm == NULL) highbpm
+                = cpl_mask_get_data(cpl_image_get_bpm(im_high));
+            highbpm[i] = CPL_BINARY_1;
+        }
+    }
+
+    return CPL_ERROR_NONE;
+
+}
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief  Create a DFS product with one table from one or more (ASCII) file(s)
+  @param  self         Table with labels (and units) but no row data
+  @param  allframes    The list of input frames for the recipe
+  @param  useframes    The frames to process for the product
+  @param  maxlinelen   The maximum line length in the input file(s)
+  @param  commentchar  Skip lines that start with this character, e.g. '#'
+  @param  product_name The name of the created FITS table product or NULL
+  @param  procatg      The PROCATG of the created FITS table product
+  @param  parlist      The list of input parameters
+  @param  recipe_name  The name of the calling recipe
+  @param  mainlist     Optional propertylist to append to main header or NULL
+  @param  extlist      Optional propertylist to append to ext. header or NULL
+  @param  remregexp    Optional regexp of properties not to put in main header
+  @param  instrume     The value to use for the INSTRUME key, uppercase PACKAGE
+  @param  pipe_id      PACKAGE "/" PACKAGE_VERSION
+  @param  table_set_row Caller-defined function to insert one row in the table
+  @param  table_check  Optional caller-defined function to check table or NULL
+  @return CPL_ERROR_NONE or the relevant CPL error code on error
+  @see irplib_table_read_from_frameset(), cpl_dfs_save_table()
+  @note If product_name is NULL, the product will be named <recipe_name>.fits.
+
+   @par Example (error handling omitted for brevity):
+   @code
+      extern cpl_boolean my_table_set_row(cpl_table *, const char *, int,
+                                          const cpl_frame *,
+                                          const cpl_parameterlist *);
+      extern cpl_error_code my_table_check(cpl_table *,
+                                           const cpl_frameset *,
+                                           const cpl_parameterlist *);
+      const int expected_rows = 42;
+      cpl_table * self = cpl_table_new(expected_rows);
+
+      cpl_table_new_column(self, "MYLABEL1", CPL_TYPE_STRING);
+      cpl_table_new_column(self, "MYLABEL2", CPL_TYPE_DOUBLE);
+      cpl_table_set_column_unit(self, "MYLABEL2", "Some_SI_Unit");
+
+      irplib_dfs_table_convert(self, allframes, useframes, 1024, '#', NULL,
+                               "MYPROCATG", parlist, "myrecipe", NULL, NULL,
+                               NULL, "MYINSTRUME", PACKAGE "/" PACKAGE_VERSION,
+                               my_table_set_row, my_table_check);
+
+      cpl_table_delete(self);
+
+   @endcode
+
+ */
+/*----------------------------------------------------------------------------*/
+
+cpl_error_code
+irplib_dfs_table_convert(cpl_table               * self,
+                         cpl_frameset            * allframes,
+                         const cpl_frameset      * useframes,
+                         int                       maxlinelen,
+                         char                      commentchar,
+                         const char              * product_name,
+                         const char              * procatg,
+                         const cpl_parameterlist * parlist,
+                         const char              * recipe_name,
+                         const cpl_propertylist  * mainlist,
+                         const cpl_propertylist  * extlist,
+                         const char              * remregexp,
+                         const char              * instrume,
+                         const char              * pipe_id,
+                         cpl_boolean (*table_set_row)
+                         (cpl_table *, const char *, int,
+                          const cpl_frame *,
+                          const cpl_parameterlist *),
+                         cpl_error_code (*table_check)
+                         (cpl_table *,
+                          const cpl_frameset *,
+                          const cpl_parameterlist *))
+{
+
+    const char       * filename;
+    cpl_propertylist * applist    = NULL;
+    cpl_errorstate     prestate   = cpl_errorstate_get();
+    cpl_error_code     error;
+
+    cpl_ensure_code(self         != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(allframes    != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(useframes    != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(procatg      != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(parlist      != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(recipe_name  != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(instrume     != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(pipe_id      != NULL, CPL_ERROR_NULL_INPUT);
+
+    cpl_ensure_code(!irplib_table_read_from_frameset(self, useframes,
+                                                     maxlinelen,
+                                                     commentchar,
+                                                     parlist,
+                                                     table_set_row),
+                    cpl_error_get_code());
+
+    if (table_check != NULL && (table_check(self, useframes, parlist) ||
+                                !cpl_errorstate_is_equal(prestate))) {
+        return cpl_error_set_message(cpl_func, cpl_error_get_code(),
+                                     "Consistency check of table failed");
+    }
+
+    filename = product_name != NULL
+        ? product_name : cpl_sprintf("%s" CPL_DFS_FITS, recipe_name);
+
+    applist = mainlist == NULL
+        ? cpl_propertylist_new() : cpl_propertylist_duplicate(mainlist);
+
+    error = cpl_propertylist_update_string(applist, "INSTRUME", instrume);
+
+    if (!error)
+        error = irplib_dfs_save_table(allframes, parlist, useframes, self,
+                                      extlist, recipe_name, procatg, applist,
+                                      remregexp, pipe_id, filename);
+
+    cpl_propertylist_delete(applist);
+    if (filename != product_name) cpl_free((char*)filename);
+
+    /* Propagate the error, if any */
+    cpl_ensure_code(!error, error);
+
+    return CPL_ERROR_NONE;
+
+}
+
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief  Set the rows of a table with data from one or more (ASCII) files
+  @param  self           Table with labels (and units) but no row data
+  @param  useframes      The frames to process for the table
+  @param  maxlinelen     The maximum line length in the input file(s)
+  @param  commentchar    Skip lines that start with this character, e.g. '#'
+  @param  parlist        The list of input parameters
+  @param  table_set_row  Caller-defined function to insert one row in the table
+  @return CPL_ERROR_NONE or the relevant CPL error code on error
+
+  table_set_row() is a function that sets the specified row in a table
+  - it may optionally include a check of the line for consistency.
+  An integer is passed to table_set_row() to indicate which row
+  to set. Instead of setting the row table_set_row() may decide to discard
+  the data. Iff the row was set, table_set_row() should return CPL_TRUE.
+
+  It needs to know:
+    1) How to parse the lines - each line is read with fgets().
+    2) For each column: type/format (%lg/%s/%d) + label
+
+  During a succesful call self will have rows added or removed to exactly
+  match the number of lines converted. Any a priori knowledge about the
+  expected number of converted rows can be used in the creation of the
+  table (to reduce memory reallocation overhead).
+  On error the number of rows in self is undefined.
+
+   @par Example (error handling omitted for brevity):
+   @code
+      extern cpl_boolean my_table_set_row(cpl_table *, const char *, int,
+                                          const cpl_frame *,
+                                          const cpl_parameterlist *);
+      const int expected_rows = 42;
+      cpl_table * self = cpl_table_new(expected_rows);
+
+      cpl_table_new_column(self, "MYLABEL1", CPL_TYPE_STRING);
+      cpl_table_new_column(self, "MYLABEL2", CPL_TYPE_DOUBLE);
+      cpl_table_set_column_unit(self, "MYLABEL2", "Some_SI_Unit");
+
+      irplib_table_read_from_frameset(self, useframes, 1024, '#', parlist,
+                                      my_table_set_row);
+
+      // Use self...
+
+      cpl_table_delete(self);
+
+   @endcode
+
+ */
+/*----------------------------------------------------------------------------*/
+
+cpl_error_code
+irplib_table_read_from_frameset(cpl_table               * self,
+                                const cpl_frameset      * useframes,
+                                int                       maxlinelen,
+                                char                      commentchar,
+                                const cpl_parameterlist * parlist,
+                                cpl_boolean (*table_set_row)
+                                (cpl_table *, const char *, int,
+                                 const cpl_frame *,
+                                 const cpl_parameterlist *))
+{
+
+    const cpl_frame  * rawframe;
+    char             * linebuffer = NULL;
+    FILE             * stream     = NULL;
+    int                nfiles     = 0;
+    int                nrow       = cpl_table_get_nrow(self);
+    int                irow       = 0;
+    cpl_errorstate     prestate   = cpl_errorstate_get();
+
+    cpl_ensure_code(self         != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(useframes    != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(maxlinelen > 0, CPL_ERROR_ILLEGAL_INPUT);
+    cpl_ensure_code(parlist      != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(table_set_row != NULL, CPL_ERROR_NULL_INPUT);
+
+    linebuffer = cpl_malloc(maxlinelen);
+
+    for (rawframe = cpl_frameset_get_first_const(useframes);
+         rawframe != NULL;
+         rawframe = cpl_frameset_get_next_const(useframes), nfiles++) {
+
+        const char * rawfile = cpl_frame_get_filename(rawframe);
+        const char * done; /* Indicate when the reading is done */
+        const int irowpre = irow;
+        int iirow = 0;
+        int ierror;
+
+        if (rawfile == NULL) break; /* Should not happen... */
+
+        stream = fopen(rawfile, "r");
+
+        if (stream == NULL) {
+#if defined CPL_HAVE_VA_ARGS && CPL_HAVE_VA_ARGS != 0
+            cpl_error_set_message(cpl_func, CPL_ERROR_FILE_IO, "Could not "
+                                  "open %s for reading", rawfile);
+#else
+            cpl_error_set_message(cpl_func, CPL_ERROR_FILE_IO, "Could not "
+                                  "open file for reading");
+#endif
+            break;
+        }
+
+        for (;(done = fgets(linebuffer, maxlinelen, stream)) != NULL; iirow++) {
+
+            if (linebuffer[0] != commentchar) {
+                cpl_boolean didset;
+#if defined CPL_HAVE_VA_ARGS && CPL_HAVE_VA_ARGS != 0
+                const int prerow = irow;
+#endif
+
+                if (irow == nrow) {
+                    nrow += nrow ? nrow : 1;
+                    if (cpl_table_set_size(self, nrow)) break;
+                }
+
+                didset = table_set_row(self, linebuffer, irow, rawframe,
+                                       parlist);
+                if (didset) irow++;
+
+                if (!cpl_errorstate_is_equal(prestate)) {
+                    if (didset)
+#if defined CPL_HAVE_VA_ARGS && CPL_HAVE_VA_ARGS != 0
+                        cpl_error_set_message(cpl_func, cpl_error_get_code(),
+                                              "Failed to set table row %d "
+                                              "using line %d from %d. file %s",
+                                              1+prerow, iirow+1,
+                                              nfiles+1, rawfile);
+                    else
+                        cpl_error_set_message(cpl_func, cpl_error_get_code(),
+                                              "Failure with line %d from %d. "
+                                              "file %s", iirow+1,
+                                              nfiles+1, rawfile);
+#else
+                        cpl_error_set_message(cpl_func, cpl_error_get_code(),
+                                              "Failed to set table row"
+                                              "using catalogue line");
+                    else
+                        cpl_error_set_message(cpl_func, cpl_error_get_code(),
+                                              "Failure with catalogue line");
+#endif
+
+                    break;
+                }
+            }
+        }
+        if (done != NULL) break;
+
+        ierror = fclose(stream);
+        stream = NULL;
+        if (ierror) break;
+
+
+        if (irow == irowpre)
+            cpl_msg_warning(cpl_func, "No usable lines in the %d. file: %s",
+                            1+nfiles, rawfile);
+    }
+
+    cpl_free(linebuffer);
+    if (stream != NULL) fclose(stream);
+
+    /* Check for premature end */
+    cpl_ensure_code(rawframe == NULL, cpl_error_get_code());
+
+    if (irow == 0) {
+#if defined CPL_HAVE_VA_ARGS && CPL_HAVE_VA_ARGS != 0
+        return cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
+                                     "No usable lines in the %d input "
+                                     "frame(s)", nfiles);
+#else
+        return cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
+                                     "No usable lines in the input frame(s)");
+#endif
+    }
+
+    /* Resize the table to the actual number of rows set */
+    cpl_ensure_code(!cpl_table_set_size(self, irow), cpl_error_get_code());
+
+    return CPL_ERROR_NONE;
+}
+
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Reset IRPLIB state
+
+  This function resets all static memory used by IRPLIB to a well-defined,
+  initial state.
+
+  The function should be called (during initialization) by any application
+  using static memory facilities in IRPLIB.
+
+  Currently, this function does nothing.
+ */
+/*----------------------------------------------------------------------------*/
+void irplib_reset(void)
+{
+    return;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Comparison function to identify different input frames
+  @param    frame1  first frame
+  @param    frame2  second frame
+  @return   0 if frame1!=frame2, 1 if frame1==frame2, -1 in error case
+ */
+/*----------------------------------------------------------------------------*/
+int irplib_compare_tags(
+        cpl_frame   *   frame1,
+        cpl_frame   *   frame2)
+{
+    char            *   v1 ;
+    char            *   v2 ;
+
+    /* Test entries */
+    if (frame1==NULL || frame2==NULL) return -1 ;
+
+    /* Get the tags */
+    if ((v1 = (char*)cpl_frame_get_tag(frame1)) == NULL) return -1 ;
+    if ((v2 = (char*)cpl_frame_get_tag(frame2)) == NULL) return -1 ;
+
+    /* Compare the tags */
+    if (strcmp(v1, v2)) return 0 ;
+    else return 1 ;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+   @brief Find the filename with the given tag in a frame set.
+   @param self  A frame set.
+   @param tag   The frame tag to search for.
+   @return The filename or NULL if none found and on error.
+   @see cpl_frameset_find
+   @note If called with a CPL error code, the location will be updated and NULL
+     returned.
+
+   NULL is returned and no error code set if the tag is not found.
+
+   If the file is not unique, the name of the first one is returned and with
+   a warning.
+
+ */
+/*----------------------------------------------------------------------------*/
+const char * irplib_frameset_find_file(const cpl_frameset * self,
+                                      const char * tag)
+{
+    const cpl_frame * frame = cpl_frameset_find_const(self, tag);
+
+
+    cpl_ensure(!cpl_error_get_code(), cpl_error_get_code(), NULL);
+
+    if (frame == NULL) return NULL;
+
+    if (cpl_frameset_find_const(self, NULL))
+        cpl_msg_warning(cpl_func,
+			"Frameset has more than one file with tag: %s",
+                        tag);
+
+    return cpl_frame_get_filename(frame);
+
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Find the first frame belonging to the given group
+  @param    self   The frameset
+  @param    group  The group attribute
+  @return   The first frame belonging to the given group, or @c NULL if no
+            such frame was found. The function returns @c NULL if an error
+            occurs and sets the appropriate error code.
+
+ */
+/*----------------------------------------------------------------------------*/
+const
+cpl_frame * irplib_frameset_get_first_from_group(const cpl_frameset * self,
+                                                 cpl_frame_group      group)
+{
+    const cpl_frame * frame;
+
+    cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL);
+
+    for (frame = cpl_frameset_get_first_const(self); frame != NULL ;
+         frame = cpl_frameset_get_next_const(self)) {
+        if (cpl_frame_get_group(frame) == group) break;
+    }
+    return frame;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Find the aperture(s) with the greatest flux
+  @param    self   The aperture object
+  @param    ind  The aperture-indices in order of decreasing flux
+  @param    nfind  Number of indices to find
+  @return   CPL_ERROR_NONE or the relevant _cpl_error_code_ on error
+
+  nfind must be at least 1 and at most the size of the aperture object.
+
+  The ind array must be able to hold (at least) nfind integers.
+  On success the first nfind elements of ind point to indices of the
+  aperture object.
+
+  To find the single ind of the aperture with the maximum flux use simply:
+  int ind;
+  irplib_apertures_find_max_flux(self, &ind, 1);
+
+ */
+/*----------------------------------------------------------------------------*/
+cpl_error_code irplib_apertures_find_max_flux(const cpl_apertures * self,
+                                              int * ind, int nfind)
+{
+    const int    nsize = cpl_apertures_get_size(self);
+    int          ifind;
+
+
+    cpl_ensure_code(nsize > 0,      cpl_error_get_code());
+    cpl_ensure_code(ind,          CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(nfind > 0,      CPL_ERROR_ILLEGAL_INPUT);
+    cpl_ensure_code(nfind <= nsize, CPL_ERROR_ILLEGAL_INPUT);
+
+    for (ifind=0; ifind < nfind; ifind++) {
+        double maxflux = -1;
+        int maxind = -1;
+        int i;
+        for (i=1; i <= nsize; i++) {
+            int k;
+
+            /* The flux has to be the highest among those not already found */
+            for (k=0; k < ifind; k++) if (ind[k] == i) break;
+
+            if (k == ifind) {
+                /* i has not been inserted into ind */
+                const double flux = cpl_apertures_get_flux(self, i);
+
+                if (maxind < 0 || flux > maxflux) {
+                    maxind = i;
+                    maxflux = flux;
+                }
+            }
+        }
+        ind[ifind] = maxind;
+    }
+
+    return CPL_ERROR_NONE;
+
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+   @brief   portable isinf
+ */
+/*----------------------------------------------------------------------------*/
+int irplib_isinf(double value)
+{
+#if defined HAVE_ISINF && HAVE_ISINF
+    return isinf(value);
+#else
+    return value != 0 && value == 2 * value;
+#endif
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+   @brief   portable isnan
+ */
+/*----------------------------------------------------------------------------*/
+int irplib_isnan(double value)
+{
+#if defined HAVE_ISNAN && HAVE_ISNAN
+    return isnan(value);
+#else
+    return value != value;
+#endif
+}
+
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Dump a single CPL error
+  @param    self      The number of the current error to be dumped
+  @param    first     The number of the first error to be dumped
+  @param    last      The number of the last error to be dumped
+  @return   void
+  @note This function differs from cpl_errorstate_dump_one only in message level
+  @see cpl_errorstate_dump_one
+
+ */
+/*----------------------------------------------------------------------------*/
+void irplib_errorstate_warning(unsigned self, unsigned first, unsigned last)
+{
+
+    const cpl_boolean is_reverse = first > last ? CPL_TRUE : CPL_FALSE;
+    const unsigned    newest     = is_reverse ? first : last;
+    const unsigned    oldest     = is_reverse ? last : first;
+    const char      * revmsg     = is_reverse ? " in reverse order" : "";
+
+
+    assert( oldest <= self );
+    assert( newest >= self );
+
+    if (newest == 0) {
+        cpl_msg_info(cpl_func, "No error(s) to dump");
+        assert( oldest == 0);
+    } else {
+        assert( oldest > 0);
+        assert( newest >= oldest);
+        if (self == first) {
+            if (oldest == 1) {
+                cpl_msg_warning(cpl_func, "Dumping all %u error(s)%s:", newest,
+                              revmsg);
+            } else {
+                cpl_msg_warning(cpl_func, "Dumping the %u most recent error(s) "
+                              "out of a total of %u errors%s:",
+                              newest - oldest + 1, newest, revmsg);
+            }
+            cpl_msg_indent_more();
+        }
+
+        cpl_msg_warning(cpl_func, "[%u/%u] '%s' (%u) at %s", self, newest,
+                      cpl_error_get_message(), cpl_error_get_code(),
+                      cpl_error_get_where());
+
+        if (self == last) cpl_msg_indent_less();
+    }
+}
+
+
+/**@}*/
+
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief  Optimized version of cpl_image_get()
+  @param  self  A void pointer, e.g. from cpl_image_get_data_const()
+  @param  type  The data type, e.g. from  cpl_image_get_type()
+  @param  i     The index into the buffer after it has been cast to type
+  @return The value cast to double
+  @note This function has no error checking for speed
+  @see cpl_image_get()
+
+ */
+/*----------------------------------------------------------------------------*/
+inline static
+double irplib_data_get_double(const void * self, cpl_type type, int i)
+{
+
+    double value;
+
+
+    switch (type) {
+    case CPL_TYPE_FLOAT:
+        {
+            const float * pself = (const float*)self;
+            value = (double)pself[i];
+            break;
+        }
+    case CPL_TYPE_INT:
+        {
+            const int * pself = (const int*)self;
+            value = (double)pself[i];
+            break;
+        }
+    default: /* case CPL_TYPE_DOUBLE */
+        {
+            const double * pself = (const double*)self;
+            value = pself[i];
+            break;
+        }
+    }
+
+    return value;
+
+}
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief  Optimized version of cpl_image_set()
+  @param  self   A void pointer, e.g. from cpl_image_get_data_const()
+  @param  type   The data type, e.g. from  cpl_image_get_type()
+  @param  i      The index into the buffer after it has been cast to type
+  @param  value  The value to write
+  @note This function has no error checking for speed
+  @see cpl_image_set()
+
+ */
+/*----------------------------------------------------------------------------*/
+inline static
+void irplib_data_set_double(void * self, cpl_type type, int i, double value)
+{
+
+    switch (type) {
+    case CPL_TYPE_FLOAT:
+        {
+            float * pself = (float*)self;
+            pself[i] = (float)value;
+            break;
+        }
+    case CPL_TYPE_INT:
+        {
+            int * pself = (int*)self;
+            pself[i] = (int)value;
+            break;
+        }
+    default: /* case CPL_TYPE_DOUBLE */
+        {
+            double * pself = (double*)self;
+            pself[i] = value;
+            break;
+        }
+    }
+}
+
+
+
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Dump a single CPL error
+  @param    Pointer to one of cpl_msg_info(), cpl_msg_warning(), ...
+  @param    self      The number of the current error to be dumped
+  @param    first     The number of the first error to be dumped
+  @param    last      The number of the last error to be dumped
+  @return   void
+  @see irplib_errorstate_dump_one
+
+ */
+/*----------------------------------------------------------------------------*/
+static
+void irplib_errorstate_dump_one_level(void (*messenger)(const char *,
+                                                        const char *, ...),
+                                      unsigned self, unsigned first,
+                                      unsigned last)
+{
+
+    const cpl_boolean is_reverse = first > last ? CPL_TRUE : CPL_FALSE;
+    const unsigned    newest     = is_reverse ? first : last;
+    const unsigned    oldest     = is_reverse ? last : first;
+    const char      * revmsg     = is_reverse ? " in reverse order" : "";
+
+
+    /*
+    cx_assert( messenger != NULL );
+    cx_assert( oldest <= self );
+    cx_assert( newest >= self );
+    */
+
+    if (newest == 0) {
+        messenger(cpl_func, "No error(s) to dump");
+        /* cx_assert( oldest == 0); */
+    } else {
+        /*
+          cx_assert( oldest > 0);
+          cx_assert( newest >= oldest);
+        */
+        if (self == first) {
+            if (oldest == 1) {
+                messenger(cpl_func, "Dumping all %u error(s)%s:", newest,
+                          revmsg);
+            } else {
+                messenger(cpl_func, "Dumping the %u most recent error(s) "
+                          "out of a total of %u errors%s:",
+                          newest - oldest + 1, newest, revmsg);
+            }
+            cpl_msg_indent_more();
+        }
+
+        messenger(cpl_func, "[%u/%u] '%s' (%u) at %s", self, newest,
+                  cpl_error_get_message(), cpl_error_get_code(),
+                  cpl_error_get_where());
+
+        if (self == last) cpl_msg_indent_less();
+    }
+}
+
+cpl_polynomial * irplib_polynomial_fit_1d_create_chiq(
+		const cpl_vector    *   x_pos,
+        const cpl_vector    *   values,
+        int                     degree,
+        double              *   rechisq
+        )
+ {
+    return irplib_polynomial_fit_1d_create_common(x_pos, values, degree, NULL, rechisq);
+ }
+cpl_polynomial * irplib_polynomial_fit_1d_create(
+		const cpl_vector    *   x_pos,
+        const cpl_vector    *   values,
+        int                     degree,
+        double              *   mse
+        )
+{
+
+    return irplib_polynomial_fit_1d_create_common(x_pos, values, degree, mse, NULL);
+}
+static cpl_polynomial * irplib_polynomial_fit_1d_create_common(
+		const cpl_vector    *   x_pos,
+        const cpl_vector    *   values,
+        int                     degree,
+        double              *   mse,
+        double				*  rechisq
+        )
+{
+    cpl_polynomial * fit1d = NULL;
+    cpl_size loc_degree = (cpl_size)degree ;
+    int x_size = 0;
+    fit1d = cpl_polynomial_new(1);
+    x_size = cpl_vector_get_size(x_pos);    
+    if(fit1d != NULL && x_size > 1)
+    {
+      cpl_matrix     * samppos = NULL;
+      cpl_vector     * fitresidual = NULL;
+		cpl_ensure(!cpl_error_get_code(), cpl_error_get_code(), NULL);
+		samppos = cpl_matrix_wrap(1, x_size,
+												   (double*)cpl_vector_get_data_const(x_pos));
+		cpl_ensure(!cpl_error_get_code(), cpl_error_get_code(), NULL);
+		fitresidual = cpl_vector_new(x_size);
+		cpl_ensure(!cpl_error_get_code(), cpl_error_get_code(), NULL);
+		cpl_polynomial_fit(fit1d, samppos, NULL, values, NULL,
+						   CPL_FALSE, NULL, &loc_degree);
+		cpl_ensure(!cpl_error_get_code(), cpl_error_get_code(), NULL);
+		cpl_vector_fill_polynomial_fit_residual(fitresidual, values, NULL, fit1d,
+												samppos, rechisq);
+		cpl_ensure(!cpl_error_get_code(), cpl_error_get_code(), NULL);
+		if (mse)
+		{
+			*mse = cpl_vector_product(fitresidual, fitresidual)
+				/ cpl_vector_get_size(fitresidual);
+		}
+		cpl_matrix_unwrap(samppos);
+		cpl_vector_delete(fitresidual);
+    }
+    return fit1d;
+}
+
+static void quicksort(int* iindex, double* exptime, int left, int right)
+{
+	int i = left;
+	int j = right;
+	int pivot = (i + j) / 2;
+	double index_value = exptime[pivot];
+	do
+	{
+		while(exptime[i] < index_value) i++;
+		while(exptime[j] > index_value) j--;
+		if (i <= j)
+		{
+			if(i < j)
+			{
+				int tmp = iindex[i];
+				double dtmp = exptime[i];
+				iindex[i]=iindex[j];
+				iindex[j]=tmp;
+				exptime[i] = exptime[j];
+				exptime[j] = dtmp;
+			}
+			i++;
+			j--;
+		}
+	} while (i <= j);
+
+	if (i < right)
+	{
+		quicksort(iindex, exptime, i, right);
+	}
+	if (left < j)
+	{
+		quicksort(iindex, exptime,left, j);
+	}
+}
+cpl_error_code irplib_frameset_sort(const cpl_frameset *  self, int* iindex, double* exptime)
+{
+	int sz = 0;
+	int i = 0;
+	const cpl_frame* tmp_frame = 0;
+	cpl_error_code error = CPL_ERROR_NONE;
+	sz = cpl_frameset_get_size(self);
+
+	/* 1. get an array of frames */
+	tmp_frame = cpl_frameset_get_first_const(self);
+	while(tmp_frame)
+	{
+		exptime[i] = frame_get_exptime(tmp_frame);
+		iindex[i] = i;
+		tmp_frame = cpl_frameset_get_next_const(self);
+		i++;
+	}
+	/* 2.sort */
+	quicksort(iindex, exptime, 0, sz - 1);
+
+	return error;
+}
+
+static double frame_get_exptime(const cpl_frame * pframe)
+{
+    cpl_propertylist       *plist = 0;
+    double                  dval = 0;
+
+    plist = cpl_propertylist_load(cpl_frame_get_filename(pframe),0);
+	if(plist)
+	{
+      cpl_error_code err = CPL_ERROR_NONE;  
+	    dval = cpl_propertylist_get_double(plist, "EXPTIME");
+       err = cpl_error_get_code();
+       if (err != CPL_ERROR_NONE)
+       {
+         cpl_msg_error(cpl_func, "error during reading EXPTIME key from the frame [%s]", cpl_frame_get_filename(pframe));
+       }
+	}
+	/* Free and return */
+	cpl_propertylist_delete(plist);
+	return dval;
+}
diff --git a/irplib/irplib_utils.h b/irplib/irplib_utils.h
new file mode 100644
index 0000000..252e96a
--- /dev/null
+++ b/irplib/irplib_utils.h
@@ -0,0 +1,464 @@
+/* $Id: irplib_utils.h,v 1.55 2011/06/01 06:47:56 llundin Exp $
+ *
+ * This file is part of the irplib package
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: llundin $
+ * $Date: 2011/06/01 06:47:56 $
+ * $Revision: 1.55 $
+ * $Name: sinfo-2_3_2 $
+ * $Log: irplib_utils.h,v $
+ * Revision 1.55  2011/06/01 06:47:56  llundin
+ * skip_if_lt(): Fix previous edits switch of A and B in error message
+ *
+ * Revision 1.54  2011/05/26 08:08:56  llundin
+ * skip_if_lt(): Support printf-style error message, name-space protect temporary variables
+ *
+ * Revision 1.53  2011/05/09 07:51:18  llundin
+ * irplib_dfs_save_image_(): Modified from cpl_dfs_save_image(). irplib_dfs_save_image(): Use irplib_dfs_save_image_()
+ *
+ * Revision 1.52  2010/03/23 07:57:59  kmirny
+ * DFS08552, Documentation for irplib_frameset_sort
+ *
+ * Revision 1.51  2009/12/16 14:59:30  cgarcia
+ * Avoid name clash with index function
+ *
+ * Revision 1.50  2009/08/17 15:10:16  kmirny
+ *
+ * DFS07454 DFS07437
+ *
+ */
+
+#ifndef IRPLIB_UTILS_H
+#define IRPLIB_UTILS_H
+
+/*-----------------------------------------------------------------------------
+                                   Includes
+ -----------------------------------------------------------------------------*/
+
+#include <stdarg.h>
+
+#include <cpl.h>
+
+/*-----------------------------------------------------------------------------
+                                   Define
+ -----------------------------------------------------------------------------*/
+
+#define IRPLIB_XSTRINGIFY(TOSTRING) #TOSTRING
+#define IRPLIB_STRINGIFY(TOSTRING) IRPLIB_XSTRINGIFY(TOSTRING)
+
+/* FIXME: Remove when no longer used by any irplib-based pipelines */
+/* Useful for debugging */
+#define irplib_trace()  do if (cpl_error_get_code()) { \
+    cpl_msg_debug(cpl_func, __FILE__ " at line %d: ERROR '%s' at %s", \
+         __LINE__, cpl_error_get_message(), cpl_error_get_where()); \
+  } else { \
+    cpl_msg_debug(cpl_func, __FILE__ " at line %d: OK", __LINE__); \
+  } while (0)
+
+#define irplib_error_recover(ESTATE, ...)                                      \
+    do if (!cpl_errorstate_is_equal(ESTATE)) {                                 \
+        cpl_msg_warning(cpl_func, __VA_ARGS__);                                \
+        cpl_msg_indent_more();                                                 \
+        cpl_errorstate_dump(ESTATE, CPL_FALSE, irplib_errorstate_warning);     \
+        cpl_msg_indent_less();                                                 \
+        cpl_errorstate_set(ESTATE);                                            \
+    } while (0)
+
+
+
+/*----------------------------------------------------------------------------*/
+/*
+  @brief Declare a function suitable for use with irplib_dfs_table_convert()
+  @param  table_set_row    The name of the function to declare
+  @see irplib_dfs_table_convert(), irplib_table_read_from_frameset()
+
+*/
+/*----------------------------------------------------------------------------*/
+#define IRPLIB_UTIL_SET_ROW(table_set_row)                      \
+    cpl_boolean table_set_row(cpl_table *,                      \
+                              const char *,                     \
+                              int,                              \
+                              const cpl_frame *,                \
+                              const cpl_parameterlist *)
+
+
+/*----------------------------------------------------------------------------*/
+/*
+  @brief Declare a function suitable for use with irplib_dfs_table_convert()
+  @param  table_check    The name of the function to declare
+  @see irplib_dfs_table_convert()
+
+*/
+/*----------------------------------------------------------------------------*/
+#define IRPLIB_UTIL_CHECK(table_check)                          \
+    cpl_error_code table_check(cpl_table *,                     \
+                               const cpl_frameset *,            \
+                               const cpl_parameterlist *)
+
+
+/*----------------------------------------------------------------------------*/
+/*
+  @brief   Conditional skip to the (unqiue) return point of the function
+  @param   CONDITION    The condition to check
+  @see cpl_error_ensure()
+
+  skip_if() takes one argument, which is a logical expression.
+  If the logical expression is false skip_if() takes no action and
+  program execution continues.
+  If the logical expression is true this indicates an error. In this case
+  skip_if() will set the location of the error to the point where it
+  was invoked in the recipe code (unless the error location is already in the
+  recipe code). If no error code had been set, then skip_if() will set one.
+  Finally, skip_if() causes program execution to skip to the macro 'end_skip'.
+  The macro end_skip is located towards the end of the function, after
+  which all resource deallocation and the function return is located.
+
+  The use of skip_if() assumes the following coding practice:
+  1) Pointers used for dynamically allocated memory that they "own" shall always
+     point to either NULL or to allocated memory (including CPL-objects).
+  2) Such pointers may not be reused to point to memory whose deallocation
+     requires calls to different functions.
+  3) Pointers of type FILE should be set NULL when not pointing to an open
+     stream and their closing calls (fclose(), freopen(), etc.) following the
+     'end_skip' should be guarded against such NULL pointers.
+
+  Error checking with skip_if() is encouraged due to the following advantages:
+  1) It ensures that a CPL-error code is set.
+  2) It ensures that the location of the error in the _recipe_ code is noted.
+  3) The error checking may be confined to a single concise line.
+  4) It is not necessary to replicate memory deallocation for every error
+     condition.
+  5) If more extensive error reporting/handling is required it is not precluded
+     by the use of skip_if().
+  6) It allows for a single point of function return.
+  7) It allows for optional, uniformly formatted debugging/tracing information
+     at each macro invocation.
+
+  The implementation of skip_if() uses a goto/label construction.
+  According to Kerningham & Ritchie, The C Programming Language, 2nd edition,
+  Section 3.8:
+  "This organization is handy if the error-handling code is non-trivial,
+  and if errors can occur in several places."
+
+  The use of goto for any other purpose should be avoided.
+
+*/
+/*----------------------------------------------------------------------------*/
+#define skip_if(CONDITION)                                                     \
+    do {                                                                       \
+        cpl_error_ensure(!cpl_error_get_code(), cpl_error_get_code(),          \
+                         goto cleanup, "Propagating a pre-existing error");    \
+        cpl_error_ensure(!(CONDITION), cpl_error_get_code(),                   \
+                         goto cleanup, "Propagating error");\
+    } while (0)
+
+/*----------------------------------------------------------------------------*/
+/*
+  @brief   Skip if A < B
+  @param   A   The 1st double to compare
+  @param   B   The 2nd double to compare
+  @param   MSG A printf-style error message, 1st arg should be a string literal
+  @see skip_if()
+  @note A and B are evaluated exactly once
+
+  If no CPL error is set, sets CPL_ERROR_DATA_NOT_FOUND on failure
+*/
+/*----------------------------------------------------------------------------*/
+#define skip_if_lt(A, B, ...)                                                  \
+    do {                                                                       \
+        /* Name-space protected one-time only evaluation */                    \
+        const double irplib_utils_a = (double)(A);                             \
+        const double irplib_utils_b = (double)(B);                             \
+                                                                               \
+        cpl_error_ensure(!cpl_error_get_code(), cpl_error_get_code(),          \
+                         goto cleanup, "Propagating a pre-existing error");    \
+        if (irplib_utils_a < irplib_utils_b) {                                 \
+            char * irplib_utils_msg = cpl_sprintf(__VA_ARGS__);                \
+            (void)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,    \
+                                        "Need at least %g (not %g) %s",        \
+                                        irplib_utils_b, irplib_utils_a,        \
+                                        irplib_utils_msg);                     \
+            cpl_free(irplib_utils_msg);                                        \
+            goto cleanup;                                                      \
+        }                                                                      \
+    } while (0)
+
+/*----------------------------------------------------------------------------*/
+/*
+  @brief   Conditional skip on coding bug
+  @param   CONDITION    The condition to check
+  @see skip_if()
+  @note unlike assert() this check cannot be disabled
+ */
+/*----------------------------------------------------------------------------*/
+#define bug_if(CONDITION)                                                      \
+    do {                                                                       \
+        cpl_error_ensure(!cpl_error_get_code(), cpl_error_get_code(),          \
+                         goto cleanup, "Propagating an unexpected error, "     \
+                         "please report to " PACKAGE_BUGREPORT);               \
+        cpl_error_ensure(!(CONDITION), CPL_ERROR_UNSPECIFIED,                  \
+                         goto cleanup, "Internal error, please report to "     \
+                         PACKAGE_BUGREPORT);                                   \
+    } while (0)
+
+/*----------------------------------------------------------------------------*/
+/*
+  @brief   Conditional skip with error creation
+  @param   CONDITION    The condition to check
+  @param   ERROR        The error code to set
+  @param   MSG          A printf-style error message. As a matter of
+                        user-friendliness the message should mention any
+                        value that caused the @em CONDITION to fail.
+  @see skip_if()
+  @note unlike assert() this check cannot be disabled
+ */
+/*----------------------------------------------------------------------------*/
+#define error_if(CONDITION, ERROR, ...)                                 \
+    cpl_error_ensure(cpl_error_get_code() == CPL_ERROR_NONE &&          \
+                     !(CONDITION), ERROR, goto cleanup,  __VA_ARGS__)
+
+/*----------------------------------------------------------------------------*/
+/*
+  @brief   Propagate a preexisting error, if any
+  @param   MSG          A printf-style error message.
+  @see skip_if()
+ */
+/*----------------------------------------------------------------------------*/
+#define any_if(...)                                                     \
+    cpl_error_ensure(!cpl_error_get_code(), cpl_error_get_code(),       \
+                     goto cleanup,  __VA_ARGS__)
+
+/*----------------------------------------------------------------------------*/
+/*
+  @brief   Define the single point of resource deallocation and return
+  @see skip_if()
+  @note end_skip should be used exactly once in functions that use skip_if() etc
+*/
+/*----------------------------------------------------------------------------*/
+#define end_skip \
+    do {                                                                     \
+        cleanup:                                                             \
+        if (cpl_error_get_code())                                            \
+            cpl_msg_debug(cpl_func, "Cleanup in " __FILE__ " line %u with "  \
+                          "error '%s' at %s", __LINE__,                      \
+                          cpl_error_get_message(), cpl_error_get_where());   \
+        else                                                                 \
+            cpl_msg_debug(cpl_func, "Cleanup in " __FILE__ " line %u",       \
+                          __LINE__);                                         \
+    } while (0)
+
+
+/*----------------------------------------------------------------------------*/
+/**
+   @brief   Conditional skip to the (unqiue) return point of the function
+   @param   CONDITION           An error is set if this test condition
+                                evaluates to false
+   @param   ec                  The CPL error code
+   @param   msg                 A printf-style error
+                                message. As a matter of user-friendliness
+                                the message should mention any value
+                                that caused the @em CONDITION to fail.
+   @see skip_if()
+*/
+/*----------------------------------------------------------------------------*/
+#define irplib_ensure(CONDITION, ec, ...)                                      \
+    cpl_error_ensure(CONDITION, ec, goto cleanup,  __VA_ARGS__)
+
+/*----------------------------------------------------------------------------*/
+/**
+   @brief   Catch an error
+   @param   COMMAND         Command to execute and check. This command is
+                            expected to set the cpl_error_code in case of
+                            failure
+   @param   msg             A printf-style error message.
+   @see skip_if()
+
+   This macro is used to catch an error from a function that sets the
+   @c cpl_error_code in case of error.
+
+   Example:
+   @code
+   irplib_check( cpl_object_do_something(object), ("Could not do something"));
+   @endcode
+
+   If the @c cpl_error_code is set before or after calling the function,
+   execution jumps to the @em cleanup label.
+
+   The macro can also be used to check a sequence of commands:
+   @code
+   irplib_check(
+       x = cpl_table_get_int(table, "x", 0, NULL);
+       y = cpl_table_get_int(table, "y", 0, NULL);
+       z = cpl_table_get_int(table, "z", 0, NULL),    / *  Comma here!  * /
+       ("Error reading wavelength catalogue"));
+   @endcode
+
+*/
+/*----------------------------------------------------------------------------*/
+
+#define irplib_check(COMMAND, ...)                                             \
+  do {                                                                         \
+    cpl_errorstate irplib_check_prestate = cpl_errorstate_get();               \
+    skip_if(0);                                                                \
+    COMMAND;                                                                   \
+        irplib_trace(); \
+    irplib_ensure(cpl_errorstate_is_equal(irplib_check_prestate),              \
+                  cpl_error_get_code(), __VA_ARGS__);                          \
+        irplib_trace(); \
+  } while (0)
+
+/*-----------------------------------------------------------------------------
+                                   Function prototypes
+ -----------------------------------------------------------------------------*/
+
+cpl_error_code irplib_dfs_save_image(cpl_frameset            *,
+                                     const cpl_parameterlist *,
+                                     const cpl_frameset      *,
+                                     const cpl_image         *,
+                                     cpl_type_bpp             ,
+                                     const char              *,
+                                     const char              *,
+                                     const cpl_propertylist  *,
+                                     const char              *,
+                                     const char              *,
+                                     const char              *);
+
+
+cpl_error_code irplib_dfs_save_propertylist(cpl_frameset            *,
+                                            const cpl_parameterlist *,
+                                            const cpl_frameset      *,
+                                            const char              *,
+                                            const char              *,
+                                            const cpl_propertylist  *,
+                                            const char              *,
+                                            const char              *,
+                                            const char              *);
+
+cpl_error_code irplib_dfs_save_imagelist(cpl_frameset            *,
+                                         const cpl_parameterlist *,
+                                         const cpl_frameset      *,
+                                         const cpl_imagelist     *,
+                                         cpl_type_bpp             ,
+                                         const char              *,
+                                         const char              *,
+                                         const cpl_propertylist  *,
+                                         const char              *,
+                                         const char              *,
+                                         const char              *);
+
+cpl_error_code irplib_dfs_save_table(cpl_frameset            *,
+                                     const cpl_parameterlist *,
+                                     const cpl_frameset      *,
+                                     const cpl_table         *,
+                                     const cpl_propertylist  *,
+                                     const char              *,
+                                     const char              *,
+                                     const cpl_propertylist  *,
+                                     const char              *,
+                                     const char              *,
+                                     const char              *);
+
+cpl_error_code irplib_dfs_save_image_(cpl_frameset            *,
+                                      cpl_propertylist        *,
+                                      const cpl_parameterlist *,
+                                      const cpl_frameset      *,
+                                      const cpl_frame         *,
+                                      const cpl_image         *,
+                                      cpl_type                 ,
+                                      const char              *,
+                                      const cpl_propertylist  *,
+                                      const char              *,
+                                      const char              *,
+                                      const char              *);
+
+void irplib_reset(void);
+int irplib_compare_tags(cpl_frame *, cpl_frame *);
+const char * irplib_frameset_find_file(const cpl_frameset *, const char *);
+const cpl_frame * irplib_frameset_get_first_from_group(const cpl_frameset *,
+                                                       cpl_frame_group);
+
+cpl_error_code irplib_apertures_find_max_flux(const cpl_apertures *, int *,
+                                              int);
+
+int irplib_isinf(double value);
+int irplib_isnan(double value);
+
+void irplib_errorstate_warning(unsigned, unsigned, unsigned);
+
+cpl_error_code
+irplib_dfs_table_convert(cpl_table *, cpl_frameset *, const cpl_frameset *,
+                         int, char, const char *, const char *,
+                         const cpl_parameterlist *, const char *,
+                         const cpl_propertylist *, const cpl_propertylist *,
+                         const char *, const char *, const char *,
+                         cpl_boolean (*)(cpl_table *, const char *, int,
+                                            const cpl_frame *,
+                                            const cpl_parameterlist *),
+                         cpl_error_code (*)(cpl_table *,
+                                            const cpl_frameset *,
+                                            const cpl_parameterlist *));
+
+cpl_error_code irplib_table_read_from_frameset(cpl_table *,
+                                               const cpl_frameset *,
+                                               int,
+                                               char,
+                                               const cpl_parameterlist *,
+                                               cpl_boolean (*)
+                                               (cpl_table *, const char *,
+                                                int, const cpl_frame *,
+                                                const cpl_parameterlist *));
+
+cpl_error_code irplib_image_split(const cpl_image *,
+                                  cpl_image *, cpl_image *, cpl_image *,
+                                  double, cpl_boolean,
+                                  double, cpl_boolean,
+                                  double, double,
+                                  cpl_boolean, cpl_boolean, cpl_boolean);
+
+void irplib_errorstate_dump_warning(unsigned, unsigned, unsigned);
+void irplib_errorstate_dump_info(unsigned, unsigned, unsigned);
+void irplib_errorstate_dump_debug(unsigned, unsigned, unsigned);
+/* wrapper for replace deprecated function cpl_polynomial_fit_1d_create*/
+cpl_polynomial * irplib_polynomial_fit_1d_create(
+		const cpl_vector    *   x_pos,
+        const cpl_vector    *   values,
+        int                     degree,
+        double              *   mse
+        );
+cpl_polynomial * irplib_polynomial_fit_1d_create_chiq(
+		const cpl_vector    *   x_pos,
+        const cpl_vector    *   values,
+        int                     degree,
+        double              *   rechiq
+        );
+/*----------------------------------------------------------------------------*/
+/**
+   @brief   Sort a frameset based on the exposure time
+   @param   self         Frameset to sort (input)
+   @param   iindex       Index array with sort results (output), each element is
+					     a frame number
+   @param   exptime      Array with exposure time for each frame (output)
+*/
+cpl_error_code irplib_frameset_sort(
+        const cpl_frameset *  self,
+        int* iindex,
+        double* exptime);
+
+#endif
diff --git a/irplib/irplib_wavecal.c b/irplib/irplib_wavecal.c
new file mode 100644
index 0000000..ed5d472
--- /dev/null
+++ b/irplib/irplib_wavecal.c
@@ -0,0 +1,1646 @@
+/* $Id: irplib_wavecal.c,v 1.46 2012/03/02 09:01:04 amodigli Exp $
+ *
+ * This file is part of the IRPLIB Pipeline
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2012/03/02 09:01:04 $
+ * $Revision: 1.46 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+/*-----------------------------------------------------------------------------
+                                   Includes
+ -----------------------------------------------------------------------------*/
+
+/* TEMPORARY SUPPORT OF CPL 5.x */
+#include <cpl.h>
+
+#ifndef CPL_SIZE_FORMAT
+#define CPL_SIZE_FORMAT "d"
+#define cpl_size int
+#endif
+/* END TEMPORARY SUPPORT OF CPL 5.x */
+
+#include "irplib_wavecal_impl.h"
+
+/* Needed for irplib_errorstate_dump_debug() */
+#include "irplib_utils.h"
+
+#include <string.h>
+#include <math.h>
+
+#ifdef HAVE_GSL
+#include <gsl/gsl_multimin.h>
+#endif
+
+/*-----------------------------------------------------------------------------
+                               Private types
+ -----------------------------------------------------------------------------*/
+
+typedef struct {
+
+    const cpl_vector * observed;
+    cpl_polynomial   * disp1d;
+    cpl_vector       * spectrum;
+    irplib_base_spectrum_model * param;
+    cpl_error_code  (* filler)(cpl_vector *, const cpl_polynomial *,
+                               irplib_base_spectrum_model *, int);
+    cpl_vector       * vxc;
+    double             xc;
+    int                maxxc;
+    double             mxc;
+    cpl_polynomial   * mdisp;
+    int                ishift;
+
+} irplib_multimin;
+
+/*-----------------------------------------------------------------------------
+                               Defines
+ -----------------------------------------------------------------------------*/
+
+#ifndef inline
+#define inline /* inline */
+#endif
+
+#define IRPLIB_MAX(A,B) ((A) > (B) ? (A) : (B))
+#define IRPLIB_MIN(A,B) ((A) < (B) ? (A) : (B))
+
+/*-----------------------------------------------------------------------------
+                                   Private functions
+ -----------------------------------------------------------------------------*/
+
+#ifdef HAVE_GSL
+static double irplib_gsl_correlation(const gsl_vector *, void *);
+#endif
+
+/*----------------------------------------------------------------------------*/
+/**
+ * @defgroup irplib_wavecal     Spectro functionality
+ */
+/*----------------------------------------------------------------------------*/
+
+/**@{*/
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Count the positive Y-entries in a given X-range
+  @param    self     Bivector with increasing X-entries
+  @param    x_min    minimum X-entry
+  @param    x_max    maximum X-entry
+  @return   the number of matching entries, or negative on error
+ */
+/*----------------------------------------------------------------------------*/
+int irplib_bivector_count_positive(const cpl_bivector * self,
+                                  double               x_min,
+                                  double               x_max)
+{
+
+    const int      nself = cpl_bivector_get_size(self);
+    const double * px    = cpl_bivector_get_x_data_const(self);
+    const double * py    = cpl_bivector_get_y_data_const(self);
+    int            npos  = 0;
+    int            i     = 0;
+
+    cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, -1);
+    cpl_ensure(x_min <= x_max, CPL_ERROR_ILLEGAL_INPUT, -2);
+    
+    /* FIXME: Use cpl_vector_find() */
+    while (i < nself && px[i] < x_min) i++;
+    while (i < nself && px[i] < x_max)
+        if (py[i++] > 0) npos++;
+
+    return npos;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Fit a 2D-dispersion from an image of wavelengths
+  @param    self    2D-polynomial to hold fit
+  @param    imgwave Image map of wavelengths, any pixeltype
+  @param    fitdeg  Degree of fit
+  @param    presid  On success, points to fitting residual
+  @return   CPL_ERROR_NONE on success, otherwise the relevant CPL error code
+
+ */
+/*----------------------------------------------------------------------------*/
+cpl_error_code irplib_polynomial_fit_2d_dispersion(cpl_polynomial * self,
+                                                   const cpl_image * imgwave,
+                                                   int fitdeg, double * presid)
+{
+
+    const int        nx = cpl_image_get_size_x(imgwave);
+    const int        ny = cpl_image_get_size_y(imgwave);
+    const int        nbad = cpl_image_count_rejected(imgwave);
+    const int        nsamp = nx * ny - nbad;
+    cpl_matrix     * xy_pos;
+    double         * xdata;
+    double         * ydata;
+    cpl_vector     * wlen;
+    double         * dwlen;
+    const cpl_size   nfitdeg = (cpl_size)fitdeg;
+    int i, j;
+    int k = 0;
+
+    cpl_ensure_code(self    != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(imgwave != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(presid  != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(fitdeg > 0,      CPL_ERROR_ILLEGAL_INPUT);
+
+    cpl_ensure_code(cpl_polynomial_get_dimension(self) == 2,
+                    CPL_ERROR_ILLEGAL_INPUT);
+
+    xy_pos = cpl_matrix_new(2, nsamp);
+    xdata = cpl_matrix_get_data(xy_pos);
+    ydata = xdata + nsamp;
+
+    dwlen = (double*)cpl_malloc(nsamp * sizeof(double));
+    wlen = cpl_vector_wrap(nsamp, dwlen);
+
+    for (i=1; i <= nx; i++) {
+        for (j=1; j <= ny; j++) {
+            int is_bad;
+            const double value = cpl_image_get(imgwave, i, j, &is_bad);
+            if (!is_bad) {
+                xdata[k] = i;
+                ydata[k] = j;
+                dwlen[k] = value;
+                k++;
+            }
+        }
+    }
+
+    cpl_msg_info(cpl_func, "Fitting 2D polynomial to %d X %d image, ignoring "
+                 "%d poorly calibrated pixels", nx, ny, nbad);
+
+    if (cpl_polynomial_fit(self, xy_pos, NULL, wlen, NULL, CPL_FALSE, NULL,
+                           &nfitdeg) == CPL_ERROR_NONE && presid != NULL) {
+        cpl_vector_fill_polynomial_fit_residual(wlen, wlen, NULL, self, xy_pos,
+                                                NULL);
+        *presid = cpl_vector_product(wlen, wlen)/nsamp;
+    }
+    cpl_matrix_delete(xy_pos);
+    cpl_vector_delete(wlen);
+
+    cpl_ensure_code(k == nsamp, CPL_ERROR_UNSPECIFIED);
+
+    return CPL_ERROR_NONE;
+}
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief Modify self by maximizing the cross-correlation
+  @param self    1D-Dispersion relation to modify, at least of degree 1
+  @param maxdeg  Maximize the cross-correlation by modifying maxdeg degree
+  @param obs     The observed spectrum to correlate against
+  @param model   The model of the lines/OTF etc.
+  @param filler  The function to fill the model spectrum
+  @param pixtol  The (positive) dispersion tolerance, e.g. 1e-6
+  @param pixstep The step length used in the maximization, e.g. 0.5 [pixel]
+  @param hsize   Half the search-distance to ensure a global-maximum, hsize >= 0
+  @param maxite  Maximum number of iterations, e.g. 100 * maxdeg
+  @param pxc     On sucess, *pxc is the cross-correlation
+  @return CPL_ERROR_NONE on success, otherwise the relevant CPL error code
+  @note Fails with CPL_ERROR_UNSUPPORTED_MODE if compiled without GSL.
+        self must be increasing in the interval from 1 to the length of obs.
+
+ */
+/*----------------------------------------------------------------------------*/
+cpl_error_code
+irplib_polynomial_find_1d_from_correlation(cpl_polynomial * self,
+                                           int maxdeg,
+                                           const cpl_vector * obs,
+                                           irplib_base_spectrum_model * model,
+                                           cpl_error_code (* filler)
+                                           (cpl_vector *,
+                                            const cpl_polynomial *,
+                                            irplib_base_spectrum_model *, int),
+                                           double pixtol,
+                                           double pixstep,
+                                           int hsize,
+                                           int maxite,
+                                           double * pxc)
+{
+
+#ifdef HAVE_GSL
+    const gsl_multimin_fminimizer_type * T = gsl_multimin_fminimizer_nmsimplex;
+    gsl_multimin_fminimizer * minimizer;
+    gsl_multimin_function my_func;
+    irplib_multimin data;
+    gsl_vector * dispgsl;
+    gsl_vector * stepsize;
+    gsl_vector * dispprev;
+    int status = GSL_CONTINUE;
+    const int nobs = cpl_vector_get_size(obs);
+    const cpl_size nfit = maxdeg + 1;
+    cpl_errorstate prestate = cpl_errorstate_get();
+    /* Convert pixel step to wavelength step on detector center */
+    const double wlstep =
+        cpl_polynomial_eval_1d_diff(self, 0.5 * (nobs + pixstep),
+                                    0.5 * (nobs - pixstep), NULL);
+    double wlstepi = wlstep;
+    double size;
+    int iter;
+    cpl_size i;
+
+#endif
+
+    cpl_ensure_code(self   != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(obs    != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(model  != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(filler != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(pxc    != NULL, CPL_ERROR_NULL_INPUT);
+
+    cpl_ensure_code(cpl_polynomial_get_dimension(self) == 1,
+                    CPL_ERROR_ILLEGAL_INPUT);
+
+    cpl_ensure_code(cpl_polynomial_get_degree(self) > 0,
+                    CPL_ERROR_ILLEGAL_INPUT);
+
+    cpl_ensure_code(maxdeg  >=  0, CPL_ERROR_ILLEGAL_INPUT);
+    cpl_ensure_code(pixtol  > 0.0, CPL_ERROR_ILLEGAL_INPUT);
+    cpl_ensure_code(pixstep > 0.0, CPL_ERROR_ILLEGAL_INPUT);
+    cpl_ensure_code(hsize   >=  0, CPL_ERROR_ILLEGAL_INPUT);
+    cpl_ensure_code(maxite  >=  0, CPL_ERROR_ILLEGAL_INPUT);
+
+#ifndef HAVE_GSL
+    return cpl_error_set_message(cpl_func, CPL_ERROR_UNSUPPORTED_MODE,
+                                 "GSL is not available");
+#else
+
+    minimizer = gsl_multimin_fminimizer_alloc(T, (size_t)nfit);
+
+    cpl_ensure_code(minimizer != NULL, CPL_ERROR_ILLEGAL_OUTPUT);
+       
+    dispgsl  = gsl_vector_alloc((size_t)nfit);
+    stepsize = gsl_vector_alloc((size_t)nfit);
+    dispprev = gsl_vector_alloc((size_t)nfit);
+
+    for (i=0; i < nfit; i++) {
+        const double value = cpl_polynomial_get_coeff(self, &i);
+        gsl_vector_set(dispgsl, (size_t)i, value);
+        gsl_vector_set(stepsize, (size_t)i, wlstepi);
+        wlstepi /= (double)nobs;
+    }
+
+    my_func.n = nfit;
+    my_func.f = &irplib_gsl_correlation;
+    my_func.params = (void *)(&data);
+
+    data.observed = obs;
+    data.disp1d   = self;
+    data.spectrum = cpl_vector_new(nobs + 2 * hsize);
+    data.vxc      = cpl_vector_new(1 + 2 * hsize);
+    data.param    = model;
+    data.filler   = filler;
+    data.maxxc    = 0; /* Output */
+    data.ishift   = 0; /* Output */
+    data.mxc      = -1.0; /* Output */
+    data.mdisp    = NULL; /* Output */
+
+    gsl_multimin_fminimizer_set (minimizer, &my_func, dispgsl, stepsize);
+
+    for (iter = 0; status == GSL_CONTINUE && iter < maxite; iter++) {
+
+        const double fprev = minimizer->fval;
+
+        gsl_vector_memcpy(dispprev, minimizer->x);
+        status = gsl_multimin_fminimizer_iterate(minimizer);
+
+        if (status || !cpl_errorstate_is_equal(prestate)) break;
+
+        size = gsl_multimin_fminimizer_size (minimizer);
+        status = gsl_multimin_test_size (size, pixtol);
+     
+        if (status == GSL_SUCCESS) {
+            cpl_msg_debug(cpl_func, "converged to minimum at");
+
+            if (nfit == 0) {
+                cpl_msg_debug(cpl_func, "%5d %g df() = %g size = %g", 
+                              iter,
+                              gsl_vector_get (minimizer->x, 0)
+                              - gsl_vector_get (dispprev, 0), 
+                              minimizer->fval - fprev, size);
+            } else if (nfit == 1) {
+                cpl_msg_debug(cpl_func, "%5d %g %g df() = %g size = %g", 
+                              iter,
+                              gsl_vector_get (minimizer->x, 0)
+                              - gsl_vector_get (dispprev, 0), 
+                              gsl_vector_get (minimizer->x, 1)
+                              - gsl_vector_get (dispprev, 1), 
+                              minimizer->fval - fprev, size);
+            } else {
+                cpl_msg_debug(cpl_func, "%5d %g %g %g df() = %g size = %g", 
+                              iter,
+                              gsl_vector_get (minimizer->x, 0)
+                              - gsl_vector_get (dispprev, 0), 
+                              gsl_vector_get (minimizer->x, 1)
+                              - gsl_vector_get (dispprev, 1), 
+                              gsl_vector_get (minimizer->x, 2)
+                              - gsl_vector_get (dispprev, 2), 
+                              minimizer->fval - fprev, size);
+            }
+        }
+    }
+
+    if (status == GSL_SUCCESS && cpl_errorstate_is_equal(prestate)) {
+        if (data.mxc > -minimizer->fval) {
+            *pxc = data.mxc;
+            cpl_msg_warning(cpl_func, "Local maximum: %g(%d) > %g",
+                            data.mxc, data.ishift, -minimizer->fval);
+            cpl_polynomial_shift_1d(data.mdisp, 0, (double)data.ishift);
+            cpl_polynomial_copy(self, data.mdisp);
+            status = GSL_CONTINUE;
+        } else {
+            *pxc = -minimizer->fval;
+            for (i=0; i < nfit; i++) {
+                const double value = gsl_vector_get(minimizer->x, i);
+                cpl_polynomial_set_coeff(self, &i, value);
+            }
+        }
+    }
+
+    cpl_vector_delete(data.spectrum);
+    cpl_vector_delete(data.vxc);
+    cpl_polynomial_delete(data.mdisp);
+    gsl_multimin_fminimizer_free(minimizer);
+    gsl_vector_free(dispgsl);
+    gsl_vector_free(dispprev);
+    gsl_vector_free(stepsize);
+
+    cpl_ensure_code(status != GSL_CONTINUE, CPL_ERROR_CONTINUE);
+    cpl_ensure_code(status == GSL_SUCCESS, CPL_ERROR_DATA_NOT_FOUND);
+    cpl_ensure_code(cpl_errorstate_is_equal(prestate), cpl_error_get_code());
+
+    return CPL_ERROR_NONE;
+#endif
+}
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Generate a 1D spectrum from a model and a dispersion relation
+  @param    self    Vector to fill with spectrum
+  @param    disp    1D-Dispersion relation, at least of degree 1
+  @param    lsslamp Pointer to irplib_line_spectrum_model struct
+  @param    hsize   The 1st intensity in self will be disp(1-hsize), hsize >= 0
+  @return   CPL_ERROR_NONE on success, otherwise the relevant CPL error code
+
+  The model comprises these elements:
+  @code
+    double wslit;  // Slit Width
+    double wfwhm;  // FWHM of transfer function
+    double xtrunc; // Truncate transfer function beyond xtrunc, xtrunc > 0
+    const cpl_bivector * lines;    // Catalogue of intensities, with
+                                   //   increasing X-vector elements
+    cpl_vector         * linepix;  // NULL, or temporary work-space of size
+                                   // equal to the lines bivector
+                                   // - should be uninitialized to zero
+    unsigned             cost;     // Will be incremented for each call
+    unsigned             xcost;    // Will be incremented for each OK call
+  @endcode
+
+  The units of the X-values of the lines is assumed to be the same as
+  that of disp, the units of wslit, wfwhm and xtrunc are assumed to be the same
+  as the input unit of disp(), the units of self will be that of the Y-values
+  of the lines.
+
+ */
+/*----------------------------------------------------------------------------*/
+cpl_error_code
+irplib_vector_fill_line_spectrum(cpl_vector * self,
+                                 const cpl_polynomial * disp,
+                                 irplib_base_spectrum_model * lsslamp,
+                                 int hsize)
+{
+
+    irplib_line_spectrum_model * arclamp
+        = (irplib_line_spectrum_model *)lsslamp;
+    cpl_error_code error;
+
+    cpl_ensure_code(arclamp != NULL, CPL_ERROR_NULL_INPUT);
+
+    arclamp->cost++;
+
+    error = irplib_vector_fill_line_spectrum_model(self,
+                                                   arclamp->linepix,
+                                                   arclamp->erftmp,
+                                                   disp,
+                                                   arclamp->lines,
+                                                   arclamp->wslit,
+                                                   arclamp->wfwhm,
+                                                   arclamp->xtrunc,
+                                                   hsize, CPL_FALSE, CPL_FALSE,
+                                                   &(arclamp->ulines));
+    cpl_ensure_code(!error, error);
+
+    arclamp->xcost++;
+
+    return CPL_ERROR_NONE;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Generate a 1D spectrum from a model and a dispersion relation
+  @param    self    Vector to fill with spectrum
+  @param    disp    1D-Dispersion relation, at least of degree 1
+  @param    lsslamp Pointer to irplib_line_spectrum_model struct
+  @param    hsize   The 1st intensity in self will be disp(1-hsize), hsize >= 0
+  @return   CPL_ERROR_NONE on success, otherwise the relevant CPL error code
+  @note The logarithm is taken on the intensities
+  @see irplib_vector_fill_line_spectrum
+
+  log(1+I) is used for the (positive) intensities
+
+ */
+/*----------------------------------------------------------------------------*/
+cpl_error_code
+irplib_vector_fill_logline_spectrum(cpl_vector * self,
+                                    const cpl_polynomial * disp,
+                                    irplib_base_spectrum_model * lsslamp,
+                                    int hsize)
+{
+
+    irplib_line_spectrum_model * arclamp
+        = (irplib_line_spectrum_model *)lsslamp;
+    cpl_error_code error;
+
+    cpl_ensure_code(arclamp != NULL, CPL_ERROR_NULL_INPUT);
+
+    arclamp->cost++;
+
+    error = irplib_vector_fill_line_spectrum_model(self,
+                                                   arclamp->linepix,
+                                                   arclamp->erftmp,
+                                                   disp,
+                                                   arclamp->lines,
+                                                   arclamp->wslit,
+                                                   arclamp->wfwhm,
+                                                   arclamp->xtrunc,
+                                                   hsize, CPL_FALSE, CPL_TRUE,
+                                                   &(arclamp->ulines));
+    cpl_ensure_code(!error, error);
+
+    arclamp->xcost++;
+
+    return CPL_ERROR_NONE;
+}
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Generate a 1D spectrum from a model and a dispersion relation
+  @param    self    Vector to fill with spectrum
+  @param    disp    1D-Dispersion relation, at least of degree 1
+  @param    lsslamp Pointer to irplib_line_spectrum_model struct
+  @param    hsize   The 1st intensity in self will be disp(1-hsize), hsize >= 0
+  @return   CPL_ERROR_NONE on success, otherwise the relevant CPL error code
+  @see irplib_vector_fill_line_spectrum()
+
+  Complexity reduced from O(nw) to O(n + w), where n is number of lines and
+  truncation width [pixel] of the line.
+
+ */
+/*----------------------------------------------------------------------------*/
+cpl_error_code
+irplib_vector_fill_line_spectrum_fast(cpl_vector * self,
+                                      const cpl_polynomial * disp,
+                                      irplib_base_spectrum_model * lsslamp,
+                                      int hsize)
+{
+
+    irplib_line_spectrum_model * arclamp
+        = (irplib_line_spectrum_model *)lsslamp;
+    cpl_error_code error;
+
+    cpl_ensure_code(arclamp != NULL, CPL_ERROR_NULL_INPUT);
+
+    arclamp->cost++;
+
+    error = irplib_vector_fill_line_spectrum_model(self,
+                                                   arclamp->linepix,
+                                                   arclamp->erftmp,
+                                                   disp,
+                                                   arclamp->lines,
+                                                   arclamp->wslit,
+                                                   arclamp->wfwhm,
+                                                   arclamp->xtrunc,
+                                                   hsize, CPL_TRUE, CPL_FALSE,
+                                                   &(arclamp->ulines));
+    cpl_ensure_code(!error, error);
+
+    arclamp->xcost++;
+
+    return CPL_ERROR_NONE;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Generate a 1D spectrum from a model and a dispersion relation
+  @param    self    Vector to fill with spectrum
+  @param    disp    1D-Dispersion relation, at least of degree 1
+  @param    lsslamp Pointer to irplib_line_spectrum_model struct
+  @param    hsize   The 1st intensity in self will be disp(1-hsize), hsize >= 0
+  @return   CPL_ERROR_NONE on success, otherwise the relevant CPL error code
+  @note The logarithm is taken on the intensities
+  @see irplib_vector_fill_line_spectrum_fast()
+
+  log(1+I) is used for the (positive) intensities
+
+ */
+/*----------------------------------------------------------------------------*/
+cpl_error_code
+irplib_vector_fill_logline_spectrum_fast(cpl_vector * self,
+                                         const cpl_polynomial * disp,
+                                         irplib_base_spectrum_model * lsslamp,
+                                         int hsize)
+{
+
+    irplib_line_spectrum_model * arclamp
+        = (irplib_line_spectrum_model *)lsslamp;
+    cpl_error_code error;
+
+    cpl_ensure_code(arclamp != NULL, CPL_ERROR_NULL_INPUT);
+
+    arclamp->cost++;
+
+    error = irplib_vector_fill_line_spectrum_model(self,
+                                                   arclamp->linepix,
+                                                   arclamp->erftmp,
+                                                   disp,
+                                                   arclamp->lines,
+                                                   arclamp->wslit,
+                                                   arclamp->wfwhm,
+                                                   arclamp->xtrunc,
+                                                   hsize, CPL_TRUE, CPL_TRUE,
+                                                   &(arclamp->ulines));
+    cpl_ensure_code(!error, error);
+
+    arclamp->xcost++;
+
+    return CPL_ERROR_NONE;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Plot a 1D spectrum and one from a model
+  @param    self    Vector with observed spectrum
+  @param    disp1d  1D-Dispersion relation, at least of degree 1
+  @param    model   Pointer to model parameters
+  @param    filler  The function to fill the model spectrum
+  @return   CPL_ERROR_NONE on success, otherwise the relevant CPL error code
+  @see irplib_vector_fill_line_spectrum()
+
+ */
+/*----------------------------------------------------------------------------*/
+cpl_error_code irplib_plot_spectrum_and_model(const cpl_vector * self,
+                                              const cpl_polynomial * disp1d,
+                                              irplib_base_spectrum_model * model,
+                                              cpl_error_code (* filler)
+                                              (cpl_vector *,
+                                               const cpl_polynomial *,
+                                               irplib_base_spectrum_model *,
+                                               int))
+{
+
+    cpl_errorstate prestate = cpl_errorstate_get();
+    cpl_vector * wl;
+    cpl_vector * spectrum;
+    cpl_vector * vxc;
+    const int len = cpl_vector_get_size(self);
+    double maxval, xc;
+    int ixc;
+    int error = 0;
+
+    cpl_ensure_code(self   != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(disp1d != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(model  != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(filler != NULL, CPL_ERROR_NULL_INPUT);
+
+    cpl_ensure_code(cpl_polynomial_get_dimension(disp1d) == 1,
+                    CPL_ERROR_ILLEGAL_INPUT);
+
+    cpl_ensure_code(cpl_polynomial_get_degree(disp1d) > 0,
+                    CPL_ERROR_ILLEGAL_INPUT);
+
+    wl = cpl_vector_new(len);
+    spectrum = cpl_vector_new(len);
+    vxc = cpl_vector_new(1);
+
+    error |= (int)cpl_vector_fill_polynomial(wl, disp1d, 1.0, 1.0);
+    error |= filler(spectrum, disp1d, model, 0);
+
+    ixc = cpl_vector_correlate(vxc, self, spectrum);
+    xc = cpl_vector_get(vxc, ixc);
+
+    maxval = cpl_vector_get_max(spectrum);
+    if (maxval != 0.0) 
+        error |= cpl_vector_multiply_scalar(spectrum,
+                                             cpl_vector_get_max(self)/maxval);
+    if (!error) {
+        const cpl_vector * spair[] = {wl, self, spectrum};
+        char * pre = cpl_sprintf("set grid;set xlabel 'Wavelength (%g -> %g)'; "
+                                 "set ylabel 'Intensity';", cpl_vector_get(wl, 0),
+                                 cpl_vector_get(wl, len-1));
+        char * title = cpl_sprintf("t 'Observed and modelled spectra (%d pixel "
+                                   "XC=%g) ' w linespoints", len, xc);
+
+        (void)cpl_plot_vectors(pre, title, "", spair, 3);
+        cpl_free(pre);
+        cpl_free(title);
+    }
+
+    cpl_vector_delete(wl);
+    cpl_vector_delete(spectrum);
+    cpl_vector_delete(vxc);
+
+    cpl_errorstate_set(prestate);
+
+    return CPL_ERROR_NONE;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Find shift(s) that maximizes (locally) the cross-correlation
+  @param    self   list of shifts that maximizes the cross-correlation (locally)
+  @param    disp   1D-Dispersion relation, at least of degree 1
+  @param    obs    The observed spectrum to correlate against
+  @param    model  Pointer to model parameters
+  @param    filler The function to fill the model spectrum
+  @param    hsize  Half the search-distance, hsize > 0 [pixel]
+  @param    doplot Plot the cross-correlation as a function of pixel shift
+  @param    pxc    Iff non-NULL, set *pxc to cross-correlation on success
+  @return   CPL_ERROR_NONE on success, otherwise the relevant CPL error code
+  @note On success, self will be resized to fit the number of shifts.
+
+  The shifts are listed in order of decreasing cross-correlation. If pxc is
+  non-NULL, *pxc will be set to the cross-correlation at shift 0.
+
+ */
+/*----------------------------------------------------------------------------*/
+cpl_error_code
+irplib_bivector_find_shift_from_correlation(cpl_bivector * self,
+                                            const cpl_polynomial * disp,
+                                            const cpl_vector * obs,
+                                            irplib_base_spectrum_model * model,
+                                            cpl_error_code (*filler)
+                                            (cpl_vector *,
+                                             const cpl_polynomial *,
+                                             irplib_base_spectrum_model *, int),
+                                            int hsize,
+                                            cpl_boolean doplot,
+                                            double *pxc)
+{
+
+    const int      nobs   = cpl_vector_get_size(obs);
+    const int      nmodel = 2 * hsize + nobs;
+    cpl_vector   * xself = cpl_bivector_get_x(self);
+    cpl_vector   * yself = cpl_bivector_get_y(self);
+    cpl_vector   * mspec1d;
+    cpl_vector   * xcorr;
+    cpl_error_code error = CPL_ERROR_NONE;
+    double         xcprev, xcnext;
+    int            ixc, imax = 0;
+    int i;
+
+    cpl_ensure_code(self   != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(disp   != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(obs    != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(model  != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(filler != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(hsize  >  0,    CPL_ERROR_ILLEGAL_INPUT);
+
+    mspec1d = cpl_vector_new(nmodel);
+
+    if (filler(mspec1d, disp, model, hsize)) {
+        cpl_vector_delete(mspec1d);
+        return cpl_error_set_where(cpl_func);
+    }
+
+    /* Should not be able to fail now */
+    xcorr = cpl_vector_new(1 + 2 * hsize);
+    ixc = cpl_vector_correlate(xcorr, mspec1d, obs);
+
+#ifdef IRPLIB_SPC_DUMP
+    /* Need irplib_wavecal.c rev. 1.12 through 1.15 */
+    irplib_polynomial_dump_corr_step(disp, xcorr, "Shift");
+#endif
+
+    cpl_vector_delete(mspec1d);
+
+    /* Find local maxima. */
+    /* FIXME(?): Also include stationary points */
+    i = 0;
+    xcprev = cpl_vector_get(xcorr, i);
+    xcnext = cpl_vector_get(xcorr, i+1);
+
+    if (xcprev >= xcnext) {
+        /* 1st data point is an extreme */
+        /* FIXME: This could also be an error, recoverable by caller by
+           increasing hsize */
+        imax++;
+
+        cpl_vector_set(xself, 0, i - hsize);
+        cpl_vector_set(yself, 0, xcprev);
+
+    }
+
+    for (i = 1; i < 2 * hsize; i++) {
+        const double xc = xcnext;
+        xcnext = cpl_vector_get(xcorr, i+1);
+        if (xc >= xcprev && xc >= xcnext) {
+            /* Found (local) maximum at shift i - hsize */
+            int j;
+
+            imax++;
+
+            if (cpl_bivector_get_size(self) < imax) {
+                cpl_vector_set_size(xself, imax);
+                cpl_vector_set_size(yself, imax);
+            }
+
+            for (j = imax-1; j > 0; j--) {
+                if (xc <= cpl_vector_get(yself, j-1)) break;
+                cpl_vector_set(xself, j, cpl_vector_get(xself, j-1));
+                cpl_vector_set(yself, j, cpl_vector_get(yself, j-1));
+            }
+            cpl_vector_set(xself, j, i - hsize);
+            cpl_vector_set(yself, j, xc);
+        }
+        xcprev = xc;
+    }
+
+    /* assert( i == 2 * hsize ); */
+
+    if (xcnext >= xcprev) {
+        /* Last data point is an extreme */
+        /* FIXME: This could also be an error, recoverable by caller by
+           increasing hsize */
+        int j;
+
+        imax++;
+
+        if (cpl_bivector_get_size(self) < imax) {
+            cpl_vector_set_size(xself, imax);
+            cpl_vector_set_size(yself, imax);
+        }
+
+        for (j = imax-1; j > 0; j--) {
+            if (xcnext <= cpl_vector_get(yself, j-1)) break;
+            cpl_vector_set(xself, j, cpl_vector_get(xself, j-1));
+            cpl_vector_set(yself, j, cpl_vector_get(yself, j-1));
+        }
+        cpl_vector_set(xself, j, i - hsize);
+        cpl_vector_set(yself, j, xcnext);
+
+    }
+
+    if (doplot) {
+        cpl_vector * xvals = cpl_vector_new(1 + 2 * hsize);
+        cpl_bivector * bcorr = cpl_bivector_wrap_vectors(xvals, xcorr);
+        double x = (double)-hsize;
+        char * title = cpl_sprintf("t 'Cross-correlation of shifted %d-pixel "
+                                   "spectrum (XCmax=%g at %d)' w linespoints",
+                                   nobs, cpl_vector_get(xcorr, ixc),
+                                   ixc - hsize);
+
+        for (i = 0; i < 1 + 2 * hsize; i++, x += 1.0) {
+            cpl_vector_set(xvals, i, x);
+        }
+
+        cpl_plot_bivector("set grid;set xlabel 'Offset [pixel]';", title,
+                             "", bcorr);
+        cpl_bivector_unwrap_vectors(bcorr);
+        cpl_vector_delete(xvals);
+        cpl_free(title);
+    }
+
+    if (pxc != NULL) *pxc = cpl_vector_get(xcorr, hsize);
+
+    cpl_vector_delete(xcorr);
+
+    if (imax < 1) {
+        error = CPL_ERROR_DATA_NOT_FOUND;
+    } else if (cpl_bivector_get_size(self) > imax) {
+        cpl_vector_set_size(xself, imax);
+        cpl_vector_set_size(yself, imax);
+    }
+
+    /* Propagate error, if any */
+    return cpl_error_set(cpl_func, error);
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Shift self by the amount that maximizes the cross-correlation
+  @param    self   1D-Dispersion relation to shift, at least of degree 1
+  @param    obs    The observed spectrum to correlate against
+  @param    model  Pointer to model parameters
+  @param    filler The function to fill the model spectrum
+  @param    hsize  Half the search-distance, hsize > 0 [pixel]
+  @param    doplot Plot the cross-correlation as a function of pixel shift
+  @param    pxc    Iff non-NULL, set *pxc to cross-correlation on success
+  @return   CPL_ERROR_NONE on success, otherwise the relevant CPL error code
+
+ */
+/*----------------------------------------------------------------------------*/
+cpl_error_code
+irplib_polynomial_shift_1d_from_correlation(cpl_polynomial * self,
+                                            const cpl_vector * obs,
+                                            irplib_base_spectrum_model * model,
+                                            cpl_error_code (*filler)
+                                            (cpl_vector *,
+                                             const cpl_polynomial *,
+                                             irplib_base_spectrum_model *, int),
+                                            int hsize,
+                                            cpl_boolean doplot,
+                                            double * pxc)
+{
+
+    const int      nobs   = cpl_vector_get_size(obs);
+    const int      nmodel = 2 * hsize + nobs;
+    cpl_vector   * mspec1d;
+    cpl_vector   * xcorr;
+    cpl_error_code error;
+    int            ixc, xxc;
+    double         xc;
+
+    cpl_ensure_code(self   != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(obs    != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(model  != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(filler != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(hsize  >  0,    CPL_ERROR_ILLEGAL_INPUT);
+
+    mspec1d = cpl_vector_new(nmodel);
+
+    if (filler(mspec1d, self, model, hsize)) {
+        cpl_vector_delete(mspec1d);
+        cpl_ensure_code(0, cpl_error_get_code());
+    }
+
+    /* Should not be able to fail now */
+    xcorr = cpl_vector_new(1 + 2 * hsize);
+    ixc = cpl_vector_correlate(xcorr, mspec1d, obs);
+
+#ifdef IRPLIB_SPC_DUMP
+    /* Need irplib_wavecal.c rev. 1.12 through 1.15 */
+    irplib_polynomial_dump_corr_step(self, xcorr, "Shift");
+#endif
+
+    cpl_vector_delete(mspec1d);
+
+    xxc = ixc - hsize;
+
+    error = cpl_polynomial_shift_1d(self, 0, (double)xxc);
+
+    xc = cpl_vector_get(xcorr, ixc);
+
+    cpl_msg_info(cpl_func, "Shifting %d pixels (%g < %g)", xxc,
+                 cpl_vector_get(xcorr, hsize), xc);
+
+    if (doplot) {
+        cpl_vector * xvals = cpl_vector_new(1 + 2 * hsize);
+        cpl_bivector * bcorr = cpl_bivector_wrap_vectors(xvals, xcorr);
+        int i;
+        double x = (double)-hsize;
+        char * title = cpl_sprintf("t 'Cross-correlation of shifted %d-pixel "
+                                   "spectrum (XCmax=%g at %d)' w linespoints",
+                                   nobs, cpl_vector_get(xcorr, ixc), xxc);
+
+        for (i = 0; i < 1 + 2 * hsize; i++, x += 1.0) {
+            cpl_vector_set(xvals, i, x);
+        }
+
+        cpl_plot_bivector("set grid;set xlabel 'Offset [pixel]';", title,
+                             "", bcorr);
+        cpl_bivector_unwrap_vectors(bcorr);
+        cpl_vector_delete(xvals);
+        cpl_free(title);
+    }
+
+    cpl_vector_delete(xcorr);
+
+    cpl_ensure_code(!error, error);
+
+    if (pxc != NULL) *pxc = xc;
+
+    return CPL_ERROR_NONE;
+
+}
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Generate a 1D spectrum from (arc) lines and a dispersion relation
+  @param    self   Vector to fill with spectrum
+  @param    linepix Vector to update with best guess of line pixel position
+  @param    disp   1D-Dispersion relation, at least of degree 1
+  @param    lines  Catalogue of lines, with increasing wavelengths 
+  @param    wslit  Positive width of the slit
+  @param    wfwhm  Positive FWHM of the transfer function
+  @param    xtrunc Truncate the line profile beyond distance xtrunc, xtrunc > 0
+  @param    hsize  The 1st intensity in self will be disp(1-hsize), hsize >= 0
+  @param    dofast Iff true compose profile from pairs of two integer-placed
+  @param    dolog  Iff true log(1+I) is used for the (positive) intensities
+  @param    pulines Iff non-NULL, number of lines used, on success
+  @return   CPL_ERROR_NONE on success, otherwise the relevant CPL error code
+  @see irplib_vector_fill_line_spectrum()
+  @note This function is supposed to be called via
+          irplib_vector_fill_line_spectrum().
+
+ */
+/*----------------------------------------------------------------------------*/
+cpl_error_code
+irplib_vector_fill_line_spectrum_model(cpl_vector * self,
+                                       cpl_vector * linepix,
+                                       cpl_vector * erftmp,
+                                       const cpl_polynomial * disp,
+                                       const cpl_bivector * lines,
+                                       double wslit,
+                                       double wfwhm,
+                                       double xtrunc,
+                                       int hsize,
+                                       cpl_boolean dofast,
+                                       cpl_boolean dolog,
+                                       unsigned * pulines)
+{
+
+    cpl_errorstate     prestate;
+    const double       sigma = wfwhm * CPL_MATH_SIG_FWHM;
+    const cpl_vector * xlines  = cpl_bivector_get_x_const(lines);
+    const double     * dxlines = cpl_vector_get_data_const(xlines);
+    const double     * dylines = cpl_bivector_get_y_data_const(lines);
+    double           * plinepix
+        = linepix ? cpl_vector_get_data(linepix) : NULL;
+    const int          nlines  = cpl_vector_get_size(xlines);
+    const int          nself   = cpl_vector_get_size(self);
+    double           * dself   = cpl_vector_get_data(self);
+    cpl_polynomial   * dispi;
+    double           * profile = NULL;
+    const cpl_size     i0 = 0;
+    const double       p0 = cpl_polynomial_get_coeff(disp, &i0);
+    double             wl;
+    double             xpos = (double)(1-hsize)-xtrunc;
+    const double       xmax = (double)(nself-hsize)+xtrunc;
+    double             xderiv, xextreme;
+    cpl_error_code     error = CPL_ERROR_NONE;
+    int                iline;
+    unsigned           ulines = 0;
+
+    cpl_ensure_code(self    != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(disp    != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(lines   != NULL, CPL_ERROR_NULL_INPUT);
+
+    cpl_ensure_code(wslit  >  0.0, CPL_ERROR_ILLEGAL_INPUT);
+    cpl_ensure_code(wfwhm  >  0.0, CPL_ERROR_ILLEGAL_INPUT);
+    cpl_ensure_code(hsize  >= 0,   CPL_ERROR_ILLEGAL_INPUT);
+    cpl_ensure_code(xtrunc >  0.0, CPL_ERROR_ILLEGAL_INPUT);
+    cpl_ensure_code(nself  > 2 * hsize, CPL_ERROR_ILLEGAL_INPUT);
+
+    cpl_ensure_code(cpl_polynomial_get_dimension(disp) == 1,
+                    CPL_ERROR_ILLEGAL_INPUT);
+    cpl_ensure_code(cpl_polynomial_get_degree(disp) > 0,
+                    CPL_ERROR_ILLEGAL_INPUT);
+
+    /* The smallest wavelength contributing to the spectrum. */
+    wl = cpl_polynomial_eval_1d(disp, xpos, &xderiv);
+
+    if (wl <= 0.0) return
+        cpl_error_set_message_macro(cpl_func, CPL_ERROR_ILLEGAL_INPUT, __FILE__,
+                                    __LINE__, "Non-positive wavelength at x=%g: "
+                                    "P(x)=%g, P'(x)=%g", xpos, wl, xderiv);
+
+    if (xderiv <= 0.0) return
+        cpl_error_set_message_macro(cpl_func, CPL_ERROR_ILLEGAL_INPUT, __FILE__,
+                                    __LINE__, "Non-increasing dispersion at "
+                                    "x=%g: P'(x)=%g, P(x)=%g", xpos, xderiv, wl);
+
+    /* Find the 1st line */
+    iline = cpl_vector_find(xlines, wl);
+
+    /* The first line must be at least at wl */
+    if (dxlines[iline] < wl) iline++;
+
+    if (iline >= nlines) return
+        cpl_error_set_message_macro(cpl_func, CPL_ERROR_DATA_NOT_FOUND, __FILE__,
+                                    __LINE__, "The %d-line catalogue has only "
+                                    "lines below P(%g)=%g > %g", nlines, xpos,
+                                    wl, dxlines[nlines-1]);
+
+    memset(dself, 0, nself * sizeof(double));
+
+    dispi = cpl_polynomial_duplicate(disp);
+
+    /* Verify monotony of dispersion */
+    cpl_polynomial_derivative(dispi, 0);
+
+    prestate = cpl_errorstate_get();
+
+    if (cpl_polynomial_solve_1d(dispi, 0.5*(nlines+1), &xextreme, 1)) {
+        cpl_errorstate_set(prestate);
+    } else if (xpos < xextreme && xextreme < xmax) {
+        cpl_polynomial_delete(dispi);
+        return cpl_error_set_message_macro(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
+                                           __FILE__, __LINE__, "Non-monotone "
+                                           "dispersion at x=%g: P'(x)=0, "
+                                           "P(x)=%g", xextreme,
+                                           cpl_polynomial_eval_1d(disp, xextreme,
+                                                                  NULL));
+    }
+
+    if (dofast) {
+        const int npix = 1+(int)xtrunc;
+
+        if (erftmp != NULL && cpl_vector_get_size(erftmp) == npix &&
+            cpl_vector_get(erftmp, 0) > 0.0) {
+            profile = cpl_vector_get_data(erftmp);
+        } else {
+
+            const double yval =  0.5 / wslit;
+            const double x0p  =  0.5 * wslit + 0.5;
+            const double x0n  = -0.5 * wslit + 0.5;
+            double       x1diff
+                = irplib_erf_antideriv(x0p, sigma)
+                - irplib_erf_antideriv(x0n, sigma);
+            int          ipix;
+
+            if (erftmp == NULL) {
+                profile = (double*)cpl_malloc(sizeof(double)*(size_t)npix);
+            } else {
+                cpl_vector_set_size(erftmp, npix);
+                profile = cpl_vector_get_data(erftmp);
+            }
+
+            profile[0] = 2.0 * yval * x1diff;
+
+            for (ipix = 1; ipix < npix; ipix++) {
+                const double x1 = (double)ipix;
+                const double x1p = x1 + 0.5 * wslit + 0.5;
+                const double x1n = x1 - 0.5 * wslit + 0.5;
+                const double x0diff = x1diff;
+
+                x1diff = irplib_erf_antideriv(x1p, sigma)
+                    - irplib_erf_antideriv(x1n, sigma);
+
+                profile[ipix] = yval * (x1diff - x0diff);
+
+            }
+        }
+    }
+
+    cpl_polynomial_copy(dispi, disp);
+
+    /* FIXME: A custom version of cpl_polynomial_solve_1d() which returns
+       P'(xpos) can be used for the 1st NR-iteration. */
+    /* Further, the sign of P'(xpos) could be checked for all lines. */
+    /* Perform 1st NR-iteration in solving for P(xpos) = dxlines[iline] */
+    xpos -= (wl - dxlines[iline]) / xderiv;
+
+    /* Iterate through the lines */
+    for (; !error && iline < nlines; iline++) {
+
+        /* Lines may have a non-physical intensity (e.g. zero) to indicate some
+           property of the line, e.g. unknown intensity due to blending */
+        if (dylines[iline] <= 0.0) continue;
+
+        /* Use 1st guess, if available (Use 0.0 to flag unavailable) */
+        if (plinepix != NULL && plinepix[iline] > 0.0) xpos = plinepix[iline];
+
+        if (xpos > xmax) xpos = xmax; /* FIXME: Better to limit xpos ? */
+
+        /* Find the (sub-) pixel position of the line */
+        error = cpl_polynomial_set_coeff(dispi, &i0, p0 - dxlines[iline]) ||
+            cpl_polynomial_solve_1d(dispi, xpos, &xpos, 1);
+
+        if (xpos > xmax) {
+            if (error) {
+                error = 0;
+                cpl_msg_debug(cpl_func, "Stopping spectrum fill at line %d/%d "
+                             "at xpos=%g > xmax=%g",
+                             iline, nlines, xpos, xmax);
+                cpl_errorstate_dump(prestate, CPL_FALSE,
+                                    irplib_errorstate_dump_debug);
+                cpl_errorstate_set(prestate);
+            }
+            break;
+        } else if (error) {
+            if (linepix != NULL && ulines) (void)cpl_vector_fill(linepix, 0.0);
+            (void)cpl_error_set_message_macro(cpl_func, cpl_error_get_code(),
+                                              __FILE__, __LINE__,
+                                              "Could not find pixel-position "
+                                              "of line %d/%d at wavelength=%g."
+                                              " xpos=%g, xmax=%g",
+                                              iline, nlines, dxlines[iline],
+                                              xpos, xmax);
+            break;
+        } else if (dofast) {
+            const double frac  = fabs(xpos - floor(xpos));
+#ifdef IRPLIB_WAVECAL_FAST_FAST
+            const double frac0 = 1.0 - frac; /* Weight opposite of distance */
+#else
+            /* Center intensity correctly */
+            const double ep1pw = irplib_erf_antideriv(frac + 0.5 * wslit, sigma);
+            const double en1pw = irplib_erf_antideriv(frac + 0.5 * wslit - 1.0,
+                                                      sigma);
+            const double ep1nw = irplib_erf_antideriv(frac - 0.5 * wslit, sigma);
+            const double en1nw = irplib_erf_antideriv(frac - 0.5 * wslit - 1.0,
+                                                      sigma);
+            const double frac0
+                = (en1nw - en1pw) / (ep1pw - en1pw - ep1nw + en1nw);
+
+#endif
+            const double frac1 = 1.0 - frac0;
+            const double yval0 = frac0 * dylines[iline];
+            const double yval1 = frac1 * dylines[iline];
+            const int    npix  = 1+(int)xtrunc;
+            int          ipix;
+            int          i0n    = hsize - 1 + floor(xpos);
+            int          i0p    = i0n;
+            int          i1n    = i0n + 1;
+            int          i1p    = i1n;
+            cpl_boolean  didline = CPL_FALSE;
+
+
+            /* Update 1st guess for next time, if available */
+            if (plinepix != NULL) plinepix[iline] =  xpos;
+
+            if (frac0 < 0.0) {
+                (void)cpl_error_set_message_macro(cpl_func,
+                                                  CPL_ERROR_UNSPECIFIED,
+                                                  __FILE__, __LINE__,
+                                                  "Illegal split at x=%g: %g + "
+                                                  "%g = 1", xpos, frac0, frac1);
+#ifdef IRPLIB_WAVEVAL_DEBUG
+            } else {
+                cpl_msg_warning(cpl_func,"profile split at x=%g: %g + %g = 1",
+                                xpos, frac0, frac1);
+#endif
+            }
+
+            for (ipix = 0; ipix < npix; ipix++, i0n--, i0p++, i1n--, i1p++) {
+
+                if (i0n >= 0 && i0n < nself) {
+                    dself[i0n] += yval0 * profile[ipix];
+                    didline = CPL_TRUE;
+                }
+                if (i1n >= 0 && i1n < nself && ipix + 1 < npix) {
+                    dself[i1n] += yval1 * profile[ipix+1];
+                    didline = CPL_TRUE;
+                }
+
+                if (ipix == 0) continue;
+
+                if (i0p >= 0 && i0p < nself) {
+                    dself[i0p] += yval0 * profile[ipix];
+                    didline = CPL_TRUE;
+                }
+                if (i1p >= 0 && i1p < nself && ipix + 1 < npix) {
+                    dself[i1p] += yval1 * profile[ipix+1];
+                    didline = CPL_TRUE;
+                }
+            }
+
+            if (didline) ulines++;
+
+        } else {
+            const double yval = 0.5 * dylines[iline] / wslit;
+            const int    ifirst = IRPLIB_MAX((int)(xpos-xtrunc+0.5), 1-hsize);
+            const int    ilast  = IRPLIB_MIN((int)(xpos+xtrunc), nself-hsize);
+            int          ipix;
+            const double x0 = (double)ifirst - xpos;
+            const double x0p = x0 + 0.5*wslit - 0.5;
+            const double x0n = x0 - 0.5*wslit - 0.5;
+            double       x1diff
+                = irplib_erf_antideriv(x0p, sigma)
+                - irplib_erf_antideriv(x0n, sigma);
+
+            /* Update 1st guess for next time, if available */
+            if (plinepix != NULL) plinepix[iline] =  xpos;
+
+            if (ilast >= ifirst) ulines++;
+
+            for (ipix = ifirst; ipix <= ilast; ipix++) {
+                const double x1 = (double)ipix - xpos;
+                const double x1p = x1 + 0.5*wslit + 0.5;
+                const double x1n = x1 - 0.5*wslit + 0.5;
+                const double x0diff = x1diff;
+
+                x1diff = irplib_erf_antideriv(x1p, sigma)
+                    - irplib_erf_antideriv(x1n, sigma);
+
+                dself[ipix+hsize-1] += yval * (x1diff - x0diff);
+
+            }
+        }
+    }
+
+    cpl_polynomial_delete(dispi);
+    if (erftmp == NULL) cpl_free(profile);
+
+    cpl_ensure_code(!error, cpl_error_get_code());
+
+    if (dolog) {
+        int i;
+        for (i = 0; i < nself; i++) {
+            dself[i] = dself[i] > 0.0 ? log(1.0 + dself[i]) : 0.0;
+        }
+    }
+
+    if (!ulines) return
+        cpl_error_set_message_macro(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
+                                    __FILE__, __LINE__, "The %d-line "
+                                    "catalogue has no lines in the range "
+                                    "%g -> P(%g)=%g", nlines, wl, xmax,
+                                    cpl_polynomial_eval_1d(disp, xmax, NULL));
+
+    if (pulines != NULL) *pulines = ulines;
+
+    return CPL_ERROR_NONE;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    The antiderivative of erx(x/sigma/sqrt(2)) with respect to x
+  @param    x      x
+  @param    sigma  sigma
+  @return   The antiderivative
+  @note This function is even.
+
+ */
+/*----------------------------------------------------------------------------*/
+inline double irplib_erf_antideriv(double x, double sigma)
+{
+    return x * erf( x / (sigma * CPL_MATH_SQRT2))
+       + 2.0 * sigma/CPL_MATH_SQRT2PI * exp(-0.5 * x * x / (sigma * sigma));
+}
+
+
+#ifdef HAVE_GSL
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Compute minus the cross-correlation
+  @param    self  The 1D-dispersion relation
+  @param    data  Pointer to a irplib_multimin struct
+  @return   Minus the cross-correlation or GSL_NAN on error
+  @note Just a stub so far
+ */
+/*----------------------------------------------------------------------------*/
+static double irplib_gsl_correlation(const gsl_vector * self, void * data)
+{
+
+    irplib_multimin * mindata = (irplib_multimin *)data;
+    cpl_errorstate prestate = cpl_errorstate_get();
+    int nobs, nmodel, ndiff;
+    cpl_size i;
+
+    cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, GSL_NAN);
+    cpl_ensure(data != NULL, CPL_ERROR_NULL_INPUT, GSL_NAN);
+
+    cpl_ensure(mindata->filler   != NULL, CPL_ERROR_NULL_INPUT, GSL_NAN);
+    cpl_ensure(mindata->observed != NULL, CPL_ERROR_NULL_INPUT, GSL_NAN);
+    cpl_ensure(mindata->spectrum != NULL, CPL_ERROR_NULL_INPUT, GSL_NAN);
+
+    nobs   = cpl_vector_get_size(mindata->observed);
+    nmodel = cpl_vector_get_size(mindata->spectrum);
+    ndiff  = nmodel - nobs;
+
+    cpl_ensure((ndiff & 1) == 0, CPL_ERROR_ILLEGAL_INPUT, GSL_NAN);
+
+    cpl_ensure(cpl_vector_get_size(mindata->vxc) == 1 + ndiff,
+               CPL_ERROR_ILLEGAL_INPUT, GSL_NAN);
+
+    ndiff /= 2;
+
+    for (i=0; i < (cpl_size)self->size; i++) {
+        const double value = gsl_vector_get(self, (size_t)i);
+        cpl_polynomial_set_coeff(mindata->disp1d, &i, value);
+    }
+
+    if (mindata->filler(mindata->spectrum, mindata->disp1d,
+                        mindata->param, ndiff)
+        || !cpl_errorstate_is_equal(prestate)) {
+
+        /* The fill failed. Ensure the discarding of this candidate by
+           setting the cross-correlation to its minimum possible value. */
+
+        (void)cpl_vector_fill(mindata->vxc, -1.0);
+
+        mindata->maxxc = ndiff;
+
+        if (!cpl_errorstate_is_equal(prestate)) {
+                cpl_msg_debug(cpl_func, "Spectrum fill failed:");
+                cpl_errorstate_dump(prestate, CPL_FALSE,
+                                    irplib_errorstate_dump_debug);
+                cpl_errorstate_set(prestate);
+        }
+    } else {
+
+        mindata->maxxc = cpl_vector_correlate(mindata->vxc,
+                                              mindata->spectrum,
+                                              mindata->observed);
+    }
+
+#ifdef IRPLIB_SPC_DUMP
+    /* Need irplib_wavecal.c rev. 1.12 through 1.15 */
+    irplib_polynomial_dump_corr_step(mindata->disp1d, mindata->vxc,
+                                     "Optimize");
+#endif
+
+    mindata->xc = cpl_vector_get(mindata->vxc, ndiff);
+
+    if (mindata->maxxc != ndiff &&
+        cpl_vector_get(mindata->vxc, mindata->maxxc) > mindata->mxc) {
+        const irplib_base_spectrum_model * arclamp
+            = (const irplib_base_spectrum_model *)mindata->param;
+
+        if (mindata->mdisp == NULL) {
+            mindata->mdisp = cpl_polynomial_duplicate(mindata->disp1d);
+        } else {
+            cpl_polynomial_copy(mindata->mdisp, mindata->disp1d);
+        }
+        mindata->mxc = cpl_vector_get(mindata->vxc, mindata->maxxc);
+        mindata->ishift = mindata->maxxc - ndiff;
+        cpl_msg_debug(cpl_func, "Local maximum: %g(%d) > %g(%d) (cost=%u:%u. "
+                      "lines=%u)", mindata->mxc, mindata->maxxc, mindata->xc,
+                      ndiff, arclamp->cost, arclamp->xcost, arclamp->ulines);
+    }
+
+    return -mindata->xc;
+}
+
+#endif
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief Modify self by maximizing the cross-correlation across all maxima
+  @param self    1D-Dispersion relation to modify, at least of degree 1
+  @param maxdeg  Maximize the cross-correlation by modifying maxdeg degree
+  @param obs     The observed spectrum to correlate against
+  @param nmaxima Number of local maxima to try (0 for all, 1 for global only)
+  @param linelim Maximum number of lines allowed in iterative refinement
+  @param model   The model of the lines/OTF etc.
+  @param filler  The function to fill the model spectrum
+  @param pixtol  The (positive) dispersion tolerance, e.g. 1e-6
+  @param pixstep The step length used in the maximization, e.g. 0.5 [pixel]
+  @param hsize   Half the search-distance to ensure a global-maximum, hsize >= 0
+  @param maxite  Maximum number of iterations, e.g. 100 * maxdeg
+  @param maxfail Number of retries on failure
+  @param maxcont Number of retries on non-convergence
+  @param doplot  Plot the cross-correlation as a function of pixel shift
+  @param pxc     On sucess, *pxc is the cross-correlation
+  @return CPL_ERROR_NONE on success, otherwise the relevant CPL error code
+  @note Fails with CPL_ERROR_UNSUPPORTED_MODE if compiled without GSL.
+        self must be increasing in the interval from 1 to the length of obs.
+
+ */
+/*----------------------------------------------------------------------------*/
+cpl_error_code
+irplib_polynomial_find_1d_from_correlation_all(cpl_polynomial * self,
+                                               int maxdeg,
+                                               const cpl_vector * obs,
+                                               int nmaxima,
+                                               int linelim,
+                                               irplib_base_spectrum_model* model,
+                                               cpl_error_code (* filler)
+                                               (cpl_vector *,
+                                                const cpl_polynomial *,
+                                                irplib_base_spectrum_model *,
+                                                int),
+                                               double pixtol,
+                                               double pixstep,
+                                               int hsize,
+                                               int maxite,
+                                               int maxfail,
+                                               int maxcont,
+                                               cpl_boolean doplot,
+                                               double * pxc)
+{
+
+#ifdef HAVE_GSL
+
+    cpl_errorstate     prestate = cpl_errorstate_get();
+    cpl_polynomial   * start;
+    cpl_polynomial   * cand;
+    cpl_polynomial   * backup;
+    cpl_error_code     error = CPL_ERROR_NONE;
+    double             xc;
+    cpl_bivector     * xtshift = cpl_bivector_new(nmaxima ? nmaxima : 1);
+    const cpl_vector * xtshiftx = cpl_bivector_get_x_const(xtshift);
+    const cpl_vector * xtshifty = cpl_bivector_get_y_const(xtshift);
+    int                nshift;
+    int                imaximum = -1;
+    int                imaxima;
+
+#endif
+
+    cpl_ensure_code(self   != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(obs    != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(model  != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(filler != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(pxc    != NULL, CPL_ERROR_NULL_INPUT);
+
+    cpl_ensure_code(cpl_polynomial_get_dimension(self) == 1,
+                    CPL_ERROR_ILLEGAL_INPUT);
+
+    cpl_ensure_code(cpl_polynomial_get_degree(self) > 0,
+                    CPL_ERROR_ILLEGAL_INPUT);
+
+    cpl_ensure_code(maxdeg  >=  0, CPL_ERROR_ILLEGAL_INPUT);
+    cpl_ensure_code(pixtol  > 0.0, CPL_ERROR_ILLEGAL_INPUT);
+    cpl_ensure_code(pixstep > 0.0, CPL_ERROR_ILLEGAL_INPUT);
+    cpl_ensure_code(hsize   >=  0, CPL_ERROR_ILLEGAL_INPUT);
+    cpl_ensure_code(maxite  >=  0, CPL_ERROR_ILLEGAL_INPUT);
+    cpl_ensure_code(nmaxima >=  0, CPL_ERROR_ILLEGAL_INPUT);
+    cpl_ensure_code(maxfail >   0, CPL_ERROR_ILLEGAL_INPUT);
+    cpl_ensure_code(maxcont >   0, CPL_ERROR_ILLEGAL_INPUT);
+    cpl_ensure_code(linelim >=  0, CPL_ERROR_ILLEGAL_INPUT);
+
+#ifndef HAVE_GSL
+    /* Avoid unused variable warning */
+    cpl_ensure_code(doplot == CPL_TRUE || doplot == CPL_FALSE,
+                    CPL_ERROR_ILLEGAL_INPUT);
+    return cpl_error_set_message(cpl_func, CPL_ERROR_UNSUPPORTED_MODE,
+                                 "GSL is not available");
+#else
+
+    if (irplib_bivector_find_shift_from_correlation(xtshift, self, obs,
+                                                    model, filler,
+                                                    hsize, doplot, &xc)) {
+        cpl_bivector_delete(xtshift);
+        return cpl_error_set_where(cpl_func);
+    }
+
+    if (model->ulines > (unsigned)linelim) {
+        /* The initial, optimal (integer) shift */
+        const double xxc = cpl_vector_get(xtshiftx, 0);
+        const double xc0 = cpl_vector_get(xtshifty, 0);
+
+        cpl_msg_warning(cpl_func, "Doing only shift=%g pixels with lines=%u > "
+                        "%d and XC=%g", xxc, model->ulines, linelim, xc0);
+
+        cpl_polynomial_shift_1d(self, 0, xxc);
+
+        *pxc = xc0;
+
+        cpl_bivector_delete(xtshift);
+
+        return CPL_ERROR_NONE;
+    }
+
+    start  = cpl_polynomial_duplicate(self);
+    cand   = cpl_polynomial_new(1);
+    backup = cpl_polynomial_new(1);
+
+    /* Number of (local) maxima to use as starting point of the optimization */
+    nshift = cpl_bivector_get_size(xtshift);
+    if (nmaxima == 0 || nmaxima > nshift) nmaxima = nshift;
+
+    cpl_msg_info(cpl_func, "Optimizing %d/%d local shift-maxima "
+                 "(no-shift xc=%g. linelim=%d)", nmaxima, nshift, xc, linelim);
+    if (cpl_msg_get_level() <= CPL_MSG_DEBUG)
+        cpl_bivector_dump(xtshift, stdout);
+
+    for (imaxima = 0; imaxima < nmaxima; imaxima++) {
+        /* The initial, optimal (integer) shift */
+        const double xxc = cpl_vector_get(xtshiftx, imaxima);
+        double xtpixstep = pixstep;
+        double xtpixtol  = pixtol;
+        double xtxc;
+        cpl_boolean ok = CPL_FALSE;
+        int nfail;
+
+
+        cpl_polynomial_copy(cand, start);
+        cpl_polynomial_shift_1d(cand, 0, xxc);
+        cpl_polynomial_copy(backup, cand);
+
+        /* Increase tolerance until convergence */
+        for (nfail = 0; nfail < maxfail; nfail++, xtpixtol *= 2.0,
+                 xtpixstep *= 2.0) {
+            int restart = maxcont;
+            do {
+                error = irplib_polynomial_find_1d_from_correlation
+                    (cand, maxdeg, obs, model,
+                     filler, xtpixtol, xtpixstep, 2,
+                     maxite, &xtxc);
+            } while (error == CPL_ERROR_CONTINUE && --restart);
+
+            if (!error) {
+                cpl_msg_debug(cpl_func, "XC(imax=%d/%d:xtpixtol=%g): %g "
+                              "(cost=%u:%u)", 1+imaxima, nmaxima, xtpixtol,
+                              xtxc, model->cost, model->xcost);
+                break;
+            }
+            cpl_msg_warning(cpl_func, "Increasing xtpixtol from %g (%g, imax="
+                            "%d/%d)", xtpixtol, xtpixstep, 1+imaxima, nmaxima);
+            if (model->ulines > (unsigned)linelim) {
+                cpl_msg_warning(cpl_func, "Stopping search-refinement via "
+                                "catalogue with %u lines > %u", model->ulines,
+                                linelim);
+                break;
+            }
+            cpl_polynomial_copy(cand, start);
+        }
+
+        /* Decrease tolerance until inconvergence, keep previous */
+        for (; !error && xtpixtol > 0.0; xtpixtol *= 0.25, xtpixstep *= 0.5) {
+            int restart = maxcont;
+
+            cpl_polynomial_copy(backup, cand);
+            do {
+                error = irplib_polynomial_find_1d_from_correlation
+                    (cand, maxdeg, obs, model, filler,
+                     xtpixtol, xtpixstep, 2, maxite, &xtxc);
+            } while (error == CPL_ERROR_CONTINUE && --restart);
+            if (error) break;
+            ok = CPL_TRUE;
+            cpl_msg_debug(cpl_func, "XC(imax=%d/%d:xtpixtol=%g): %g (cost=%u:%u"
+                          ". ulines=%u)", 1+imaxima, nmaxima, xtpixtol, xtxc,
+                          model->cost, model->xcost, model->ulines);
+            if (model->ulines > (unsigned)linelim) {
+                cpl_msg_info(cpl_func, "Stopping search-refinement via "
+                             "catalogue with %u lines > %u", model->ulines,
+                             linelim);
+                break;
+            }
+        }
+
+        if (error) {
+            error = 0;
+            cpl_errorstate_dump(prestate, CPL_FALSE,
+                                irplib_errorstate_dump_debug);
+            cpl_errorstate_set(prestate);
+            cpl_polynomial_copy(cand, backup);
+        }
+        if (ok && xtxc > xc) {
+            imaximum = imaxima;
+            cpl_polynomial_copy(self, cand);
+            xc = xtxc;
+
+            cpl_msg_info(cpl_func, "XC(imax=%d/%d): %g -> %g (initial-shift=%g. "
+                         "cost=%u:%u. lines=%u)", 1+imaxima, nmaxima,
+                         cpl_vector_get(xtshifty, imaxima), xtxc,
+                         cpl_vector_get(xtshiftx, imaxima), model->cost,
+                         model->xcost, model->ulines);
+        } else {
+            cpl_msg_info(cpl_func, "xc(imax=%d/%d): %g -> %g (initial-shift=%g. "
+                         "cost=%u:%u. lines=%u)", 1+imaxima, nmaxima,
+                         cpl_vector_get(xtshifty, imaxima), xtxc,
+                         cpl_vector_get(xtshiftx, imaxima),
+                         model->cost, model->xcost, model->ulines);
+        }
+    }
+
+    cpl_polynomial_delete(start);
+    cpl_polynomial_delete(backup);
+    cpl_polynomial_delete(cand);
+
+    if (imaximum < 0) {
+        error = cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
+                                      "XC could not be optimized over %d "
+                                      "local shift-maxima (xc=%g)", nmaxima, xc);
+    } else {
+        cpl_msg_info(cpl_func, "Maximal XC=%g (up from %g, with initial pixel-"
+                     "shift of %g) at %d/%d local shift-maximi", xc,
+                     cpl_vector_get(xtshifty, imaximum),
+                     cpl_vector_get(xtshiftx, imaximum),
+                     1+imaximum, nmaxima);
+
+        if (doplot) {
+            irplib_plot_spectrum_and_model(obs, self, model, filler);
+        }
+
+        *pxc = xc;
+    }
+
+    cpl_bivector_delete(xtshift);
+
+    return error;
+
+#endif
+
+}
+/**@}*/
diff --git a/irplib/irplib_wavecal.h b/irplib/irplib_wavecal.h
new file mode 100644
index 0000000..64368b6
--- /dev/null
+++ b/irplib/irplib_wavecal.h
@@ -0,0 +1,184 @@
+/* $Id: irplib_wavecal.h,v 1.16 2009/10/21 14:49:42 llundin Exp $
+ *
+ * This file is part of the IRPLIB Pipeline
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: llundin $
+ * $Date: 2009/10/21 14:49:42 $
+ * $Revision: 1.16 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifndef IRPLIB_WAVECAL_H
+#define IRPLIB_WAVECAL_H
+
+/*-----------------------------------------------------------------------------
+                                   Includes
+ -----------------------------------------------------------------------------*/
+
+#include <cpl.h>
+
+
+/*-----------------------------------------------------------------------------
+                                   Define
+ -----------------------------------------------------------------------------*/
+
+#define IRPLIB_WAVECAL_MODEL_COEFFS       4
+/* The number of columns is 5 + IRPLIB_WAVECAL_MODEL_COEFFS */
+#define IRPLIB_WAVECAL_MODEL_COLS         9
+
+#define IRPLIB_WAVECAL_LAB_MODE           "SpecMode"
+#define IRPLIB_WAVECAL_LAB_RESID          "Residual"
+#define IRPLIB_WAVECAL_LAB_ORDER          "Fit_Order"
+#define IRPLIB_WAVECAL_LAB_XMIN           "XMin"
+#define IRPLIB_WAVECAL_LAB_XMAX           "XMax"
+#define IRPLIB_WAVECAL_LAB_C1             "C_1"
+#define IRPLIB_WAVECAL_LAB_C2             "C_2"
+#define IRPLIB_WAVECAL_LAB_C3             "C_3"
+#define IRPLIB_WAVECAL_LAB_C4             "C_4"
+
+#define IRPLIB_WAVECAL_LAB_WAVE           "WAVELENGTH"
+#define IRPLIB_WAVECAL_LAB_INTENS         "INTENSITY"
+
+
+/*-----------------------------------------------------------------------------
+                               New Types
+ -----------------------------------------------------------------------------*/
+
+/* Any spectrum model must have these members first! */
+typedef struct {
+    unsigned             cost;    /* May be incremented for cost counting */
+    unsigned             xcost;   /* Ditto (can exclude failed fills) */
+    unsigned             ulines;  /* May be set to number of lines used */
+
+} irplib_base_spectrum_model;
+
+typedef struct {
+    unsigned             cost;    /* May be incremented for cost counting */
+    unsigned             xcost;   /* Ditto (can exclude failed fills) */
+    unsigned             ulines;  /* May be set to number of lines used */
+
+    double               wslit;  /* Slit Width */
+    double               wfwhm;  /* FWHM of transfer function */
+    double               xtrunc; /* Truncate transfer function beyond xtrunc,
+                                    xtrunc > 0 */
+    const cpl_bivector * lines;  /* Catalogue of intensities, with
+                                    increasing X-vector elements */
+    cpl_vector         * linepix;  /* Catalogue of line pixel positions
+                                      - zero for uninitialized */
+    cpl_vector         * erftmp;  /* Temporary storage for erf() values
+                                      - zero for uninitialized */
+} irplib_line_spectrum_model;
+
+/*-----------------------------------------------------------------------------
+                                   Function Prototypes
+ -----------------------------------------------------------------------------*/
+
+cpl_error_code
+irplib_polynomial_find_1d_from_correlation_all(cpl_polynomial *,
+                                               int,
+                                               const cpl_vector *,
+                                               int, int,
+                                               irplib_base_spectrum_model *,
+                                               cpl_error_code (*)
+                                               (cpl_vector *,
+                                                const cpl_polynomial *,
+                                                irplib_base_spectrum_model *,
+                                                int),
+                                               double,
+                                               double,
+                                               int,
+                                               int,
+                                               int,
+                                               int,
+                                               cpl_boolean,
+                                               double *);
+
+cpl_error_code
+irplib_bivector_find_shift_from_correlation(cpl_bivector *,
+                                            const cpl_polynomial *,
+                                            const cpl_vector *,
+                                            irplib_base_spectrum_model *,
+                                            cpl_error_code (*)
+                                            (cpl_vector *,
+                                             const cpl_polynomial *,
+                                             irplib_base_spectrum_model *, int),
+                                            int,
+                                            cpl_boolean,
+                                            double *);
+
+cpl_error_code
+irplib_polynomial_shift_1d_from_correlation(cpl_polynomial *,
+                                            const cpl_vector *,
+                                            irplib_base_spectrum_model *,
+                                            cpl_error_code (*)
+                                            (cpl_vector *,
+                                             const cpl_polynomial *,
+                                             irplib_base_spectrum_model *, int),
+                                            int, cpl_boolean, double *);
+
+cpl_error_code
+irplib_polynomial_find_1d_from_correlation(cpl_polynomial *, int,
+                                           const cpl_vector *,
+                                           irplib_base_spectrum_model *,
+                                           cpl_error_code (*)
+                                           (cpl_vector *,
+                                            const cpl_polynomial *,
+                                            irplib_base_spectrum_model *, int),
+                                           double, double,
+                                           int, int, double *);
+
+cpl_error_code irplib_vector_fill_line_spectrum(cpl_vector *,
+                                                const cpl_polynomial *,
+                                                irplib_base_spectrum_model *,
+                                                int);
+
+cpl_error_code irplib_vector_fill_logline_spectrum(cpl_vector *,
+                                                   const cpl_polynomial *,
+                                                   irplib_base_spectrum_model *,
+                                                   int);
+
+cpl_error_code
+irplib_vector_fill_line_spectrum_fast(cpl_vector *,
+                                      const cpl_polynomial *,
+                                      irplib_base_spectrum_model *,
+                                      int);
+
+cpl_error_code
+irplib_vector_fill_logline_spectrum_fast(cpl_vector *,
+                                         const cpl_polynomial *,
+                                         irplib_base_spectrum_model *,
+                                         int);
+
+cpl_error_code irplib_plot_spectrum_and_model(const cpl_vector *,
+                                              const cpl_polynomial *,
+                                              irplib_base_spectrum_model *,
+                                              cpl_error_code (*)
+                                              (cpl_vector *,
+                                               const cpl_polynomial *,
+                                               irplib_base_spectrum_model *,
+                                               int));
+
+cpl_error_code irplib_polynomial_fit_2d_dispersion(cpl_polynomial *,
+                                                   const cpl_image *,
+                                                   int, double *);
+
+int irplib_bivector_count_positive(const cpl_bivector *, double, double);
+
+#endif
diff --git a/irplib/irplib_wavecal_impl.h b/irplib/irplib_wavecal_impl.h
new file mode 100644
index 0000000..cc046c6
--- /dev/null
+++ b/irplib/irplib_wavecal_impl.h
@@ -0,0 +1,56 @@
+/* $Id: irplib_wavecal_impl.h,v 1.6 2009/10/21 14:49:42 llundin Exp $
+ *
+ * This file is part of the IRPLIB Pipeline
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: llundin $
+ * $Date: 2009/10/21 14:49:42 $
+ * $Revision: 1.6 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifndef IRPLIB_WAVECAL_IMPL_H
+#define IRPLIB_WAVECAL_IMPL_H
+
+/*-----------------------------------------------------------------------------
+                                   Includes
+ -----------------------------------------------------------------------------*/
+
+#include "irplib_wavecal.h"
+
+/*-----------------------------------------------------------------------------
+                             Private Function Prototypes
+ -----------------------------------------------------------------------------*/
+
+cpl_error_code irplib_vector_fill_line_spectrum_model(cpl_vector *,
+                                                      cpl_vector *,
+                                                      cpl_vector *,
+                                                      const cpl_polynomial *,
+                                                      const cpl_bivector *,
+                                                      double,
+                                                      double,
+                                                      double,
+                                                      int,
+                                                      cpl_boolean,
+                                                      cpl_boolean,
+                                                      unsigned *);
+
+double irplib_erf_antideriv(double, double);
+
+#endif
diff --git a/irplib/irplib_wcs.c b/irplib/irplib_wcs.c
new file mode 100644
index 0000000..cb47d03
--- /dev/null
+++ b/irplib/irplib_wcs.c
@@ -0,0 +1,391 @@
+/* $Id: irplib_wcs.c,v 1.8 2010/10/07 14:10:55 llundin Exp $
+ *
+ * This file is part of the irplib package
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: llundin $
+ * $Date: 2010/10/07 14:10:55 $
+ * $Revision: 1.8 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+/*-----------------------------------------------------------------------------
+                                   Includes
+ -----------------------------------------------------------------------------*/
+
+#include <math.h>
+#include <cpl.h>
+
+#include "irplib_wcs.h"
+
+/*----------------------------------------------------------------------------*/
+/**
+ * @defgroup irplib_wcs   Functions related to WCS
+ */
+/*----------------------------------------------------------------------------*/
+
+static cpl_error_code irplib_wcs_is_iso8601(int, int, int, int, int, double);
+
+/**@{*/
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief Convert x, y coordinates (physical) to RA, DEC (World)
+  @param wcs    The World Coordinate System solution
+  @param x      The X coordinate (Physical)
+  @param y      The Y coordinate (Physical)
+  @param ra     The RA coordinate (World) (returned)
+  @param dec    The DEC coordinate (World) (returned)
+  @see cpl_wcs_convert()
+
+ */
+/*----------------------------------------------------------------------------*/
+cpl_error_code irplib_wcs_xytoradec(const cpl_wcs *wcs,
+                                    double         x,
+                                    double         y,
+                                    double        *ra,
+                                    double        *dec)
+{
+    cpl_matrix   * xy;
+    cpl_matrix   * radec  = NULL;
+    cpl_array    * status = NULL;
+    cpl_error_code error;
+
+    cpl_ensure_code(ra  != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(dec != NULL, CPL_ERROR_NULL_INPUT);
+
+    /* Load up the information */
+    xy = cpl_matrix_new(1, 2);
+    cpl_matrix_set(xy, 0, 0, x);
+    cpl_matrix_set(xy, 0, 1, y);
+
+    /* Call the conversion routine */
+    error = cpl_wcs_convert(wcs, xy, &radec, &status, CPL_WCS_PHYS2WORLD);
+
+    cpl_matrix_delete(xy);
+
+    if (!error) {
+
+        /* Pass it back now */
+        *ra  = cpl_matrix_get(radec, 0, 0);
+        *dec = cpl_matrix_get(radec, 0, 1);
+
+    }
+
+    /* Tidy and propagate error, if any */
+    cpl_matrix_delete(radec);
+    cpl_array_delete(status);
+
+    return cpl_error_set_where(cpl_func);
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief Convert RA, DEC (World) to x, y coordinates (physical)
+  @param wcs    The World Coordinate System solution
+  @param ra     The RA coordinate (World) (returned)
+  @param dec    The DEC coordinate (World)
+  @param x      The X coordinate (Physical) (returned)
+  @param y      The Y coordinate (Physical) (returned)
+  @see cpl_wcs_convert()
+
+ */
+/*----------------------------------------------------------------------------*/
+cpl_error_code irplib_wcs_radectoxy(const cpl_wcs * wcs,
+                                    double          ra,
+                                    double          dec,
+                                    double        * x,
+                                    double        * y)
+{
+    cpl_matrix   * radec;
+    cpl_matrix   * xy = NULL;
+    cpl_array    * status   = NULL;
+    cpl_error_code error;
+
+    cpl_ensure_code(x != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(y != NULL, CPL_ERROR_NULL_INPUT);
+
+    /* Feed the matrix with RA, DEC */
+    radec = cpl_matrix_new(1, 2);
+    cpl_matrix_set(radec, 0, 0, ra);
+    cpl_matrix_set(radec, 0, 1, dec);
+
+    error = cpl_wcs_convert(wcs, radec, &xy, &status, CPL_WCS_WORLD2PHYS);
+
+    cpl_matrix_delete(radec);
+
+    if (!error) {
+
+        *x  = cpl_matrix_get(xy, 0, 0);
+        *y  = cpl_matrix_get(xy, 0, 1);
+
+    }
+
+    /* Tidy and propagate error, if any */
+    cpl_array_delete(status);
+    cpl_matrix_delete(xy);
+
+    return cpl_error_set_where(cpl_func);
+
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief   Compute the great-circle distance between two points on a sphere
+  @param   ra1    Right ascension of first point [degrees]
+  @param   dec1   Declination of first point [degrees]
+  @param   ra2    Right ascension of second point [degrees]
+  @param   dec2   Declination of second point [degrees]
+  @return  Non-negative distance [degrees].
+  @see     http://en.wikipedia.org/wiki/Great-circle_distance (on 2005-10-23)
+ */
+/*----------------------------------------------------------------------------*/
+double irplib_wcs_great_circle_dist(double ra1,
+                                    double dec1,
+                                    double ra2,
+                                    double dec2)
+{
+
+    /* Convert all input from degrees to radian - and back for the result */
+    const double dra  = sin( CPL_MATH_RAD_DEG * (ra2  - ra1 )/2.0 );
+    const double ddec = sin( CPL_MATH_RAD_DEG * (dec2 - dec1)/2.0 );
+
+    dec1 *= CPL_MATH_RAD_DEG;
+    dec2 *= CPL_MATH_RAD_DEG;
+
+    return 2.0 * asin(sqrt( ddec*ddec + cos(dec1)*cos(dec2)*dra*dra))
+        * CPL_MATH_DEG_RAD;
+}
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief   Convert a date from ISO-8601 to Modified Julian Date (MJD)
+  @param   pmjd   On success, the MJD
+  @param   year   The ISO-8601 Year
+  @param   month  The ISO-8601 Month  (1 for first)
+  @param   day    The ISO-8601 Day    (1 for first)
+  @param   hour   The ISO-8601 Hour   (0 for first)
+  @param   minute The ISO-8601 Minute (0 for first)
+  @param   second The ISO-8601 Second (0 for first)
+  @return  CPL_ERROR_NONE on success, otherwise the error
+  @see The conversion code in wcslib version 4.4.4
+
+ */
+/*----------------------------------------------------------------------------*/
+cpl_error_code irplib_wcs_mjd_from_iso8601(double * pmjd, int year, int month,
+                                           int day, int hour, int minute,
+                                           double second)
+{
+
+    cpl_ensure_code(pmjd  != NULL,        CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(!irplib_wcs_is_iso8601(year, month, day, hour, minute,
+                                           second), cpl_error_get_code());
+
+    /* Compute MJD. */
+    *pmjd = (double)((1461*(year - (12-month)/10 + 4712))/4
+                     + (306*((month+9)%12) + 5)/10
+                     - (3*((year - (12-month)/10 + 4900)/100))/4
+                     + day - 2399904)
+        + (hour + (minute + second/60.0)/60.0)/24.0;
+
+    return CPL_ERROR_NONE;
+
+}
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief   Extract an ISO-8601 date from a string
+  @param   pyear   The ISO-8601 Year
+  @param   pmonth  The ISO-8601 Month  (1 for first)
+  @param   pday    The ISO-8601 Day    (1 for first)
+  @param   phour   The ISO-8601 Hour   (0 for first)
+  @param   pminute The ISO-8601 Minute (0 for first)
+  @param   psecond The ISO-8601 Second (0 for first)
+  @param   iso8601 The ISO-8601 formatted string
+  @return  CPL_ERROR_NONE on success, otherwise the error
+  @see irplib_wcs_mjd_from_iso8601()
+  @note The format must be the
+        standard year-2000 form: CCYY-MM-DD[Thh:mm:ss[.sss...]]
+
+ */
+/*----------------------------------------------------------------------------*/
+cpl_error_code irplib_wcs_iso8601_from_string(int * pyear, int * pmonth,
+                                              int * pday, int * phour,
+                                              int * pminute, double * psecond,
+                                              const char * iso8601)
+{
+
+    /* Standard year-2000 form: CCYY-MM-DD[Thh:mm:ss[.sss...]] */
+    const char * iso8601format = "%4d-%2d-%2dT%2d:%2d:%lf";
+
+    cpl_ensure_code(pyear   != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(pmonth  != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(pday    != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(phour   != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(pminute != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(psecond != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(iso8601 != NULL, CPL_ERROR_NULL_INPUT);
+
+    cpl_error_ensure(sscanf(iso8601, iso8601format, pyear, pmonth,
+                            pday, phour, pminute, psecond) == 6,
+                     CPL_ERROR_ILLEGAL_INPUT, return cpl_error_get_code(),
+                     "%s is not formatted as %s", iso8601, iso8601format);
+
+    cpl_ensure_code(!irplib_wcs_is_iso8601(*pyear, *pmonth, *pday, *phour,
+                                           *pminute, *psecond),
+                    cpl_error_get_code());
+
+    return CPL_ERROR_NONE;
+}
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief   Convert a date from a ISO-8601 string to Modified Julian Date (MJD)
+  @param   pmjd    On success, the MJD
+  @param   iso8601 The ISO-8601 formatted string
+  @return  CPL_ERROR_NONE on success, otherwise the error
+  @see irplib_wcs_iso8601_from_string(), irplib_wcs_mjd_from_iso8601()
+
+ */
+/*----------------------------------------------------------------------------*/
+cpl_error_code irplib_wcs_mjd_from_string(double * pmjd, const char * iso8601)
+{
+
+
+    int year, day, month, hour, minute;
+    double second;
+
+    return irplib_wcs_iso8601_from_string(&year, &month, &day, &hour,
+                                          &minute, &second, iso8601)
+        || irplib_wcs_mjd_from_iso8601(pmjd, year, month, day, hour, minute,
+                                       second)
+        ? cpl_error_set_where(cpl_func) : CPL_ERROR_NONE;
+}
+
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief   Convert a date from Modified Julian Date (MJD) to ISO-8601
+  @param   pyear   The ISO-8601 Year
+  @param   pmonth  The ISO-8601 Month  (1 for first)
+  @param   pday    The ISO-8601 Day    (1 for first)
+  @param   phour   The ISO-8601 Hour   (0 for first)
+  @param   pminute The ISO-8601 Minute (0 for first)
+  @param   psecond The ISO-8601 Second (0 for first)
+  @param   mjd     The MJD
+  @return  CPL_ERROR_NONE on success, otherwise the error
+  @see irplib_wcs_mjd_from_iso8601()
+
+ */
+/*----------------------------------------------------------------------------*/
+cpl_error_code irplib_wcs_iso8601_from_mjd(int * pyear, int * pmonth,
+                                           int * pday, int * phour,
+                                           int * pminute, double * psecond,
+                                           double mjd)
+{
+
+    int jd, n4, dd;
+    double t;
+
+    cpl_ensure_code(pyear   != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(pmonth  != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(pday    != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(phour   != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(pminute != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(psecond != NULL, CPL_ERROR_NULL_INPUT);
+
+    /* Copied from datfix() in wcslib (v. 4.4.4) */
+
+    jd = 2400001 + (int)mjd;
+
+    n4 =  4*(jd + ((2*((4*jd - 17918)/146097)*3)/4 + 1)/2 - 37);
+    dd = 10*(((n4-237)%1461)/4) + 5;
+
+    *pyear  = n4/1461 - 4712;
+    *pmonth = (2 + dd/306)%12 + 1;
+    *pday   = (dd%306)/10 + 1;
+
+    t = mjd - (int)mjd; /* t is now days */
+
+    t *= 24.0; /* t is now hours */
+    *phour = (int)t;
+    t = 60.0 * (t - *phour); /* t is now minutes */
+    *pminute = (int)t;
+    *psecond = 60.0 * (t - *pminute);
+
+    /* A failure here implies that this code has a bug */
+    cpl_ensure_code(!irplib_wcs_is_iso8601(*pyear, *pmonth, *pday, *phour,
+                                           *pminute, *psecond),
+                    CPL_ERROR_UNSPECIFIED);
+
+    return CPL_ERROR_NONE;
+}
+
+
+/**@}*/
+
+/*----------------------------------------------------------------------------*/
+/**
+  @internal
+  @brief   Verify that the six numbers comprise a valid ISO-8601 date
+  @param   year   The Year
+  @param   month  The Month  (1 for first)
+  @param   day    The Day    (1 for first)
+  @param   hour   The Hour   (0 for first)
+  @param   minute The Minute (0 for first)
+  @param   second The Second (0 for first)
+  @return  CPL_ERROR_NONE on valid input, otherwise CPL_ERROR_ILLEGAL_INPUT
+ */
+/*----------------------------------------------------------------------------*/
+static cpl_error_code irplib_wcs_is_iso8601(int year, int month,
+                                            int day, int hour,
+                                            int minute, double second)
+{
+
+    const cpl_boolean is_leap = year % 4 ? CPL_FALSE : CPL_TRUE;
+    const int mlen[] = {0, 31, is_leap ? 29 : 28, 31, 30, 31, 30, 31, 31, 30,
+                        31, 30, 31};
+
+    cpl_ensure_code(month > 0,            CPL_ERROR_ILLEGAL_INPUT);
+    cpl_ensure_code(month <= 12,          CPL_ERROR_ILLEGAL_INPUT);
+
+    cpl_ensure_code(day   > 0,            CPL_ERROR_ILLEGAL_INPUT);
+    cpl_ensure_code(day   <= mlen[month], CPL_ERROR_ILLEGAL_INPUT);
+
+    cpl_ensure_code(minute  < 60,         CPL_ERROR_ILLEGAL_INPUT);
+    cpl_ensure_code(minute  >= 0,         CPL_ERROR_ILLEGAL_INPUT);
+
+    cpl_ensure_code(second  < 60.0,       CPL_ERROR_ILLEGAL_INPUT);
+    cpl_ensure_code(second  >= 0.0,       CPL_ERROR_ILLEGAL_INPUT);
+
+    cpl_ensure_code(hour  >= 0,           CPL_ERROR_ILLEGAL_INPUT);
+    /* 24:00:00 is valid ISO-8601 */
+    cpl_ensure_code(hour  <= (minute > 0 || second > 0.0 ? 23 : 24),
+                    CPL_ERROR_ILLEGAL_INPUT);
+
+    return CPL_ERROR_NONE;
+}
diff --git a/irplib/irplib_wcs.h b/irplib/irplib_wcs.h
new file mode 100644
index 0000000..cce3c3b
--- /dev/null
+++ b/irplib/irplib_wcs.h
@@ -0,0 +1,66 @@
+/* $Id: irplib_wcs.h,v 1.7 2010/10/07 14:10:55 llundin Exp $
+ *
+ * This file is part of the irplib package
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: llundin $
+ * $Date: 2010/10/07 14:10:55 $
+ * $Revision: 1.7 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifndef IRPLIB_WCS_H
+#define IRPLIB_WCS_H
+
+/*-----------------------------------------------------------------------------
+                                   Includes
+ -----------------------------------------------------------------------------*/
+
+#include <cpl.h>
+
+cpl_error_code irplib_wcs_xytoradec(const cpl_wcs * wcs,
+                                    double          x,
+                                    double          y,
+                                    double        * ra,
+                                    double        * dec);
+
+cpl_error_code irplib_wcs_radectoxy(const cpl_wcs * wcs,
+                                    double          ra,
+                                    double          dec,
+                                    double        * x,
+                                    double        * y);
+
+double irplib_wcs_great_circle_dist(double ra1,
+                                    double dec1,
+                                    double ra2,
+                                    double dec2);
+
+
+cpl_error_code irplib_wcs_iso8601_from_string(int *, int *, int *, int *, int *,
+                                              double *, const char *);
+
+cpl_error_code irplib_wcs_mjd_from_iso8601(double *, int, int, int, int, int,
+                                           double);
+
+cpl_error_code irplib_wcs_mjd_from_string(double *, const char *);
+
+cpl_error_code irplib_wcs_iso8601_from_mjd(int *, int *, int *, int *, int *,
+                                           double *, double);
+
+#endif
diff --git a/irplib/irplib_wlxcorr.c b/irplib/irplib_wlxcorr.c
new file mode 100644
index 0000000..592aaf2
--- /dev/null
+++ b/irplib/irplib_wlxcorr.c
@@ -0,0 +1,1261 @@
+/* $Id: irplib_wlxcorr.c,v 1.55 2012/01/12 11:50:41 llundin Exp $
+ *
+ * This file is part of the IRPLIB package
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: llundin $
+ * $Date: 2012/01/12 11:50:41 $
+ * $Revision: 1.55 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+/*-----------------------------------------------------------------------------
+   								Includes
+ -----------------------------------------------------------------------------*/
+
+#include <math.h>
+#include <string.h>
+
+#include <cpl.h>
+
+#include "irplib_wavecal_impl.h"
+
+#include "irplib_wlxcorr.h"
+
+/*----------------------------------------------------------------------------*/
+/**
+ * @defgroup irplib_wlxcorr     Wavelength Cross correlation w. plotting
+ *
+ * @par Synopsis:
+ * @code
+ *   #include "irplib_wlxcorr.h"
+ * @endcode
+ *
+ */
+/*----------------------------------------------------------------------------*/
+
+/*-----------------------------------------------------------------------------
+                           Defines
+ -----------------------------------------------------------------------------*/
+
+/* TEMPORARY SUPPORT OF CPL 5.x */
+#ifndef CPL_SIZE_FORMAT
+#define CPL_SIZE_FORMAT "d"
+#define cpl_size int
+#endif
+/* END TEMPORARY SUPPORT OF CPL 5.x */
+
+#ifndef inline
+#define inline /* inline */
+#endif
+
+#define IRPLIB_MAX(A,B) ((A) > (B) ? (A) : (B))
+#define IRPLIB_MIN(A,B) ((A) < (B) ? (A) : (B))
+
+#define IRPLIB_PTR_SWAP(a,b)                                               \
+    do { void * irplib_ptr_swap =(a);(a)=(b);(b)=irplib_ptr_swap; } while (0)
+
+/*-----------------------------------------------------------------------------
+                           Private functions
+ -----------------------------------------------------------------------------*/
+
+static void irplib_wlxcorr_estimate(cpl_vector *, cpl_vector *,
+                                    const cpl_vector *,
+                                    const cpl_bivector *,
+                                    const cpl_vector *,
+                                    const cpl_polynomial *,
+                                    double, double);
+
+static int irplib_wlxcorr_signal_resample(cpl_vector *, const cpl_vector *, 
+        const cpl_bivector *) ;
+static cpl_error_code cpl_vector_fill_lss_profile_symmetric(cpl_vector *,
+                                                            double, double);
+static cpl_error_code irplib_wlcalib_fill_spectrum(cpl_vector *,
+                                                const cpl_bivector *,
+                                                const cpl_vector *,
+                                                const cpl_polynomial *, int);
+
+static cpl_boolean irplib_wlcalib_is_lines(const cpl_vector *,
+                                        const cpl_polynomial *,
+                                        int, double);
+
+/**@{*/
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Find the best polynomial in a given range
+  @param    spectrum        The spectrum vector
+  @param    lines_catalog   The lines catalog
+  @param    degree          The polynomial degree
+  @param    guess_poly      Guess Dispersion Polynomial 
+  @param    wl_error        Search range around the anchor points
+  @param    nsamples        Number of samples around the anchor points
+  @param    slitw           The slit width
+  @param    fwhm            The spectral FWHM [pixel]
+  @param    xc              Cross-correlation factor (returned)
+  @param    wlres           The table with the calibration results or NULL 
+  @param    xcorrs          The vector with the correlation values or NULL
+  @return   the best polynomial or NULL in error case
+  @note *wlres may be NULL also when no error code is set by the function
+
+  wl_error must be of size degree+1.
+  The returned polynomial must be deallocated with cpl_polynomial_delete().
+
+  On success:
+  If wlres is non-NULL, *wlres points to a table which must be deallocated
+  with cpl_table_delete(), and if xcorrs is non-NULL, *xcorrs points to a
+  vector which must be deallocated with cpl_vector_delete().
+
+  The complexity in terms of model spectra creation is O(N^D), where N is
+  nsamples and D is the length of wl_error.
+ 
+  Possible #_cpl_error_code_ set in this function:
+  - CPL_ERROR_NULL_INPUT if (one of) the input pointer(s) is NULL
+  - CPL_ERROR_ILLEGAL_INPUT if the wl_error vector has not the proper
+    size (with respect to the degree) of if the degree is outside the
+    allowed range
+  - CPL_ERROR_ILLEGAL_OUTPUT if the spectral table cannot be generated
+    from the solution polynomial
+ */
+/*----------------------------------------------------------------------------*/
+cpl_polynomial * irplib_wlxcorr_best_poly(const cpl_vector     * spectrum,
+                                          const cpl_bivector   * lines_catalog,
+                                          int                    degree,
+                                          const cpl_polynomial * guess_poly,
+                                          const cpl_vector     * wl_error,
+                                          int                    nsamples,
+                                          double                 slitw,
+                                          double                 fwhm,
+                                          double               * xc,
+                                          cpl_table           ** wlres,
+                                          cpl_vector          ** xcorrs)
+{
+    const int         spec_sz = cpl_vector_get_size(spectrum);
+    const int         nfree   = cpl_vector_get_size(wl_error);
+    int               ntests  = 1;
+    cpl_vector      * model;
+    cpl_vector      * vxc;
+    cpl_vector      * init_pts_wl;
+    cpl_matrix      * init_pts_x;
+    cpl_vector      * pts_wl;
+    cpl_vector      * vxcorrs;
+    cpl_vector      * conv_kernel = NULL;    
+    cpl_polynomial  * poly_sol;
+    cpl_polynomial  * poly_candi;
+    const double    * pwl_error = cpl_vector_get_data_const(wl_error); 
+    const double    * dxc;
+    cpl_size          degree_loc ;
+    const cpl_boolean symsamp = CPL_TRUE; /* init_pts_x is symmetric */
+    const cpl_boolean is_lines
+        = irplib_wlcalib_is_lines(cpl_bivector_get_x_const(lines_catalog),
+                               guess_poly, spec_sz, 1.0);
+    int               i;
+
+    /* FIXME: Need mode parameter for catalogue type (lines <=> profile) */
+
+    /* In case of failure */
+    if (wlres  != NULL) *wlres  = NULL;
+    if (xcorrs != NULL) *xcorrs = NULL;
+
+    /* Useful for knowing if resampling is used */
+    cpl_msg_debug(cpl_func, "Checking %d^%d dispersion polynomials (slitw=%g, "
+                  "fwhm=%g) against %d-point observed spectrum with%s "
+                  "catalog resampling", nsamples, nfree, slitw, fwhm, spec_sz,
+                  is_lines ? "out" : "");
+
+    cpl_ensure(xc            != NULL, CPL_ERROR_NULL_INPUT,    NULL);
+    *xc = -1.0;
+    cpl_ensure(spectrum      != NULL,  CPL_ERROR_NULL_INPUT,    NULL);
+    cpl_ensure(lines_catalog != NULL, CPL_ERROR_NULL_INPUT,    NULL);
+    cpl_ensure(guess_poly    != NULL, CPL_ERROR_NULL_INPUT,    NULL);
+    cpl_ensure(wl_error      != NULL, CPL_ERROR_NULL_INPUT,    NULL);
+    cpl_ensure(nfree         >= 2,    CPL_ERROR_ILLEGAL_INPUT, NULL);
+    cpl_ensure(nsamples      >  0,    CPL_ERROR_ILLEGAL_INPUT, NULL);
+    /* FIXME: degree is redundant */
+    cpl_ensure(1 + degree   == nfree, CPL_ERROR_ILLEGAL_INPUT, NULL);
+
+    cpl_ensure(cpl_polynomial_get_dimension(guess_poly) == 1,
+               CPL_ERROR_ILLEGAL_INPUT, NULL);
+
+    if (nsamples > 1) {
+        /* Search place must consist of more than one point */
+        /* FIXME: The bounds should probably not be negative */
+        for (i = 0; i < nfree; i++) {
+            if (pwl_error[i] != 0.0) break;
+        }
+        cpl_ensure(i < nfree, CPL_ERROR_ILLEGAL_INPUT, NULL);
+    }
+ 
+    if (!is_lines) {
+        /* Create the convolution kernel */
+        conv_kernel = irplib_wlxcorr_convolve_create_kernel(slitw, fwhm);
+        cpl_ensure(conv_kernel   != NULL, CPL_ERROR_ILLEGAL_INPUT, NULL);
+    }
+
+    /* Create initial test points */
+    init_pts_x  = cpl_matrix_new(1, nfree);
+    init_pts_wl = cpl_vector_new(nfree);
+    pts_wl      = cpl_vector_new(nfree);
+    for (i = 0; i < nfree; i++) {
+        const double xpos  = spec_sz * i / (double)degree;
+        const double wlpos = cpl_polynomial_eval_1d(guess_poly, xpos, NULL)
+            - 0.5 * pwl_error[i];
+
+        cpl_matrix_set(init_pts_x, 0, i, xpos);
+        cpl_vector_set(init_pts_wl,   i, wlpos);
+
+        ntests *= nsamples; /* Count number of tests */
+
+    }
+
+    vxcorrs = xcorrs != NULL ? cpl_vector_new(ntests) : NULL;
+
+    poly_sol   = cpl_polynomial_new(1);
+    poly_candi = cpl_polynomial_new(1);
+    model = cpl_vector_new(spec_sz);
+    vxc = cpl_vector_new(1);
+    dxc = cpl_vector_get_data_const(vxc);
+   
+    /* Create the polynomial candidates and estimate them */
+    for (i=0; i < ntests; i++) {
+        int    idiv = i;
+        int    deg;
+
+        /* Update wavelength at one anchor point - and reset wavelengths
+           to their default for any anchor point(s) at higher wavelengths */
+        for (deg = degree; deg >= 0; deg--, idiv /= nsamples) {
+            const int imod = idiv % nsamples;
+            const double wlpos = cpl_vector_get(init_pts_wl, deg)
+                               + imod * pwl_error[deg] / nsamples;
+
+            /* FIXME: If wlpos causes pts_wl to be non-increasing, the
+               solution will be non-physical with no need for evaluation.
+               (*xc could be set to -1 in this case). */
+            cpl_vector_set(pts_wl, deg, wlpos);
+
+            if (imod > 0) break;
+        }
+
+        /* Generate */
+        degree_loc = (cpl_size)degree ;
+        cpl_polynomial_fit(poly_candi, init_pts_x, &symsamp, pts_wl,
+                           NULL, CPL_FALSE, NULL, &degree_loc);
+        /* *** Estimate *** */
+        irplib_wlxcorr_estimate(vxc, model, spectrum, lines_catalog,
+                                conv_kernel, poly_candi, slitw, fwhm);
+        if (vxcorrs != NULL) cpl_vector_set(vxcorrs, i, *dxc);
+        if (*dxc > *xc) {
+            /* Found a better solution */
+            *xc = *dxc;
+            IRPLIB_PTR_SWAP(poly_sol, poly_candi);
+        }
+    }
+
+    cpl_vector_delete(model);
+    cpl_vector_delete(vxc);
+    cpl_vector_delete(conv_kernel);
+    cpl_vector_delete(pts_wl);
+    cpl_matrix_delete(init_pts_x);
+    cpl_vector_delete(init_pts_wl);
+    cpl_polynomial_delete(poly_candi);
+
+#ifdef CPL_WLCALIB_FAIL_ON_CONSTANT
+    /* FIXME: */
+    if (cpl_polynomial_get_degree(poly_sol) == 0) {
+        cpl_polynomial_delete(poly_sol);
+        cpl_vector_delete(vxcorrs);
+        *xc = 0.0;
+        cpl_error_set_message_macro(cpl_func, CPL_ERROR_ILLEGAL_OUTPUT,
+                                    __FILE__, __LINE__, "Found a constant "
+                                    "dispersion");
+            cpl_errorstate_dump(prestate, CPL_FALSE, NULL);
+        return NULL;
+    }
+#endif
+    
+    if (wlres != NULL) {
+        /* FIXME: A failure in the table creation is not considered a failure
+           of the whole function call (although all outputs may be useless) */
+
+        cpl_errorstate prestate = cpl_errorstate_get();
+        /* Create the spc_table  */
+        *wlres = irplib_wlxcorr_gen_spc_table(spectrum, lines_catalog, slitw,
+                                              fwhm, guess_poly, poly_sol);
+        if (*wlres == NULL) {
+            cpl_polynomial_delete(poly_sol);
+            cpl_vector_delete(vxcorrs);
+            *xc = -1.0;
+            cpl_error_set_message_macro(cpl_func, CPL_ERROR_ILLEGAL_OUTPUT,
+                                        __FILE__, __LINE__, "Cannot generate "
+                                        "infos table");
+            /* cpl_errorstate_dump(prestate, CPL_FALSE, NULL); */
+            cpl_errorstate_set(prestate);
+            return NULL;
+        }
+    } 
+    
+    if (xcorrs != NULL) {
+        *xcorrs = vxcorrs;
+    } else {
+        /* assert(vxcorrs == NULL); */
+    }
+
+    return poly_sol;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Generate the infos table
+  @param    spectrum        The spectrum vector
+  @param    lines_catalog   The lines catalog
+  @param    slitw           The slit width
+  @param    fwhm            The spectral FWHM [pixel]
+  @param    guess_poly      Guess Dispersion Polynomial 
+  @param    corr_poly       Corrected Dispersion Polynomial
+  @return   the table with the results of the calibration or NULL in error case
+
+  The returned table must be deallocated with cpl_table_delete().
+  
+  Possible #_cpl_error_code_ set in this function:
+  - CPL_ERROR_NULL_INPUT if (one of) the input pointer(s) is NULL
+  - CPL_ERROR_ILLEGAL_INPUT if the spectrum cannot be generated from the
+    catalog or if the convolution kernel cannot be created
+ */
+/*----------------------------------------------------------------------------*/
+cpl_table * irplib_wlxcorr_gen_spc_table(
+        const cpl_vector        *   spectrum,
+        const cpl_bivector      *   lines_catalog,
+        double                      slitw,
+        double                      fwhm,
+        const cpl_polynomial    *   guess_poly,
+        const cpl_polynomial    *   corr_poly)
+{
+
+    cpl_vector      *   conv_kernel = NULL;
+    cpl_bivector    *   gen_init ;
+    cpl_bivector    *   gen_corr ;
+    cpl_table       *   spc_table ;
+    const double    *   pgen ;
+    const double        xtrunc = 0.5 * slitw + 5.0 * fwhm * CPL_MATH_SIG_FWHM;
+    const int           spec_sz = cpl_vector_get_size(spectrum);
+    const cpl_boolean   guess_resamp
+        = !irplib_wlcalib_is_lines(cpl_bivector_get_x_const(lines_catalog),
+                                guess_poly, spec_sz, 1.0);
+    const cpl_boolean   corr_resamp
+        = !irplib_wlcalib_is_lines(cpl_bivector_get_x_const(lines_catalog),
+                                corr_poly, spec_sz, 1.0);
+    cpl_error_code      error;
+
+    cpl_msg_debug(cpl_func, "Tabel for guess dispersion polynomial (slitw=%g, "
+                  "fwhm=%g) with %d-point observed spectrum with%s catalog re"
+                  "sampling", slitw, fwhm, spec_sz, guess_resamp ? "out" : "");
+    cpl_msg_debug(cpl_func, "Tabel for corr. dispersion polynomial (slitw=%g, "
+                  "fwhm=%g) with %d-point observed spectrum with%s catalog re"
+                  "sampling", slitw, fwhm, spec_sz, corr_resamp ? "out" : "");
+
+    /* Test inputs */
+    cpl_ensure(spectrum, CPL_ERROR_NULL_INPUT, NULL) ;
+    cpl_ensure(lines_catalog, CPL_ERROR_NULL_INPUT, NULL) ;
+    cpl_ensure(guess_poly, CPL_ERROR_NULL_INPUT, NULL) ;
+    cpl_ensure(corr_poly, CPL_ERROR_NULL_INPUT, NULL) ;
+
+    /* Create the convolution kernel */
+    if (guess_resamp || corr_resamp) {
+        conv_kernel = irplib_wlxcorr_convolve_create_kernel(slitw, fwhm);
+
+        if (conv_kernel == NULL) {
+            cpl_error_set_message_macro(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
+                                        __FILE__, __LINE__, "Cannot create "
+                                        "convolution kernel") ;
+            return NULL ;
+        }
+    }
+
+    /* Get the emission at initial wavelengths */
+    gen_init = cpl_bivector_new(spec_sz);
+    if (guess_resamp) {
+        error = irplib_wlcalib_fill_spectrum(cpl_bivector_get_y(gen_init),
+                                          lines_catalog, conv_kernel,
+                                          guess_poly, 0);
+    } else {
+        error = irplib_vector_fill_line_spectrum_model
+            (cpl_bivector_get_y(gen_init), NULL, NULL,
+             guess_poly, lines_catalog,
+             slitw, fwhm, xtrunc, 0, CPL_FALSE, CPL_FALSE, NULL);
+    }
+
+    if (error || cpl_vector_fill_polynomial(cpl_bivector_get_x(gen_init),
+                                            guess_poly, 1, 1)) {
+        cpl_vector_delete(conv_kernel);
+        cpl_bivector_delete(gen_init);
+        cpl_error_set_message_macro(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
+                                    __FILE__, __LINE__, "Cannot get the "
+                                    "emission spectrum");
+        return NULL;
+    }
+ 
+    /* Get the emission at corrected wavelengths */
+    gen_corr = cpl_bivector_new(spec_sz);
+    if (corr_resamp) {
+        error = irplib_wlcalib_fill_spectrum(cpl_bivector_get_y(gen_corr),
+                                          lines_catalog, conv_kernel,
+                                          corr_poly, 0);
+    } else {
+        error = irplib_vector_fill_line_spectrum_model
+            (cpl_bivector_get_y(gen_corr), NULL, NULL,
+             corr_poly, lines_catalog,
+             slitw, fwhm, xtrunc, 0, CPL_FALSE, CPL_FALSE, NULL);
+    }
+
+    if (error || cpl_vector_fill_polynomial(cpl_bivector_get_x(gen_corr),
+                                            corr_poly, 1, 1)) {
+        cpl_vector_delete(conv_kernel);
+        cpl_bivector_delete(gen_init);
+        cpl_bivector_delete(gen_corr) ;
+        cpl_error_set_message_macro(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
+                                    __FILE__, __LINE__, "Cannot get the "
+                                    "emission spectrum");
+        return NULL;
+    }
+    cpl_vector_delete(conv_kernel) ;
+
+    /* Create the ouput table */
+    spc_table = cpl_table_new(spec_sz);
+    cpl_table_new_column(spc_table, IRPLIB_WLXCORR_COL_WAVELENGTH, 
+            CPL_TYPE_DOUBLE);
+    cpl_table_new_column(spc_table, IRPLIB_WLXCORR_COL_CAT_INIT, 
+            CPL_TYPE_DOUBLE);
+    cpl_table_new_column(spc_table, IRPLIB_WLXCORR_COL_CAT_FINAL, 
+            CPL_TYPE_DOUBLE);
+    cpl_table_new_column(spc_table, IRPLIB_WLXCORR_COL_OBS, CPL_TYPE_DOUBLE);
+    
+    /* Update table */
+    pgen = cpl_bivector_get_x_data_const(gen_corr) ;
+    cpl_table_copy_data_double(spc_table, IRPLIB_WLXCORR_COL_WAVELENGTH, pgen) ;
+    pgen = cpl_bivector_get_y_data_const(gen_corr) ;
+    cpl_table_copy_data_double(spc_table, IRPLIB_WLXCORR_COL_CAT_FINAL, pgen) ;
+    pgen = cpl_vector_get_data_const(spectrum) ;
+    cpl_table_copy_data_double(spc_table, IRPLIB_WLXCORR_COL_OBS, pgen) ;
+    pgen = cpl_bivector_get_y_data_const(gen_init) ;
+    cpl_table_copy_data_double(spc_table, IRPLIB_WLXCORR_COL_CAT_INIT, pgen);
+    cpl_bivector_delete(gen_init);
+    cpl_bivector_delete(gen_corr);
+
+    return spc_table ;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Extract a sub catalog
+  @param    lines_catalog   Bivector with the lines
+  @param    wave_min        The wavelength min
+  @param    wave_max        The wavelength max
+  @return   the extracted bivector or NULL in error case
+  
+  Possible #_cpl_error_code_ set in this function:
+  - CPL_ERROR_NULL_INPUT if (one of) the input pointer(s) is NULL
+  - CPL_ERROR_ILLEGAL_INPUT if the specified wavelength range is invalid
+ */
+/*----------------------------------------------------------------------------*/
+cpl_bivector * irplib_wlxcorr_cat_extract(
+        const cpl_bivector  *   lines_catalog,
+        double                  wave_min,
+        double                  wave_max)
+{
+    const int           nlines = cpl_bivector_get_size(lines_catalog);
+    int                 wave_min_id, wave_max_id ;
+    cpl_vector       *  sub_cat_wl ;
+    cpl_vector       *  sub_cat_int ;
+    const cpl_vector *  xlines  = cpl_bivector_get_x_const(lines_catalog);
+    const double     *  dxlines = cpl_vector_get_data_const(xlines);
+
+    cpl_ensure(lines_catalog != NULL, CPL_ERROR_NULL_INPUT,    NULL);
+
+    /* Find the 1st line */
+    wave_min_id = cpl_vector_find(xlines, wave_min);
+    /* The first line must be greater than (at least?) wave_min */
+    if (dxlines[wave_min_id] <= wave_min) wave_min_id++;
+
+    /* Find the last line */
+    wave_max_id = cpl_vector_find(xlines, wave_max);
+    /* The last line must be less than wave_max */
+    if (dxlines[wave_max_id] >= wave_min) wave_max_id--;
+
+    /* Checking the wavelength range at this point via the indices also
+       verifies that they were not found using non-increasing wavelengths */
+    cpl_ensure(wave_min_id <= wave_max_id, CPL_ERROR_ILLEGAL_INPUT, NULL);
+
+    if (wave_min_id < 0 || wave_max_id == nlines) {
+        cpl_error_set_message_macro(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
+                                    __FILE__, __LINE__, "The %d-line catalogue "
+                                    "has no lines in the range %g -> %g",
+                                    nlines, wave_min, wave_max);
+        return NULL ;
+    }
+
+    sub_cat_wl = cpl_vector_extract(xlines, wave_min_id, wave_max_id, 1);
+    sub_cat_int = cpl_vector_extract(cpl_bivector_get_y_const(lines_catalog), 
+                                     wave_min_id, wave_max_id, 1);
+ 
+    return cpl_bivector_wrap_vectors(sub_cat_wl, sub_cat_int);
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Create Right Half of a symmetric smoothing kernel
+  @param    slitw  The slit width [pixel]
+  @param    fwhm   The spectral FWHM [pixel]
+  @return   Right Half of (symmetric) smoothing vector
+
+  The smoothing function is the right half of the convolution of a Gaussian with
+  sigma =  fwhm / (2 * sqrt(2*log(2))) and a top-hat with a width equal to the
+  slit width, and area 1.
+  Since this function is symmetric only the central, maximum value and the
+  right half is returned. The length of the resulting vector is
+  1 + 5 * sigma + slitw/2 
+  
+  Possible #_cpl_error_code_ set in this function:
+  - CPL_ERROR_ILLEGAL_INPUT if the slit width or fwhm is non-positive
+ */
+/*----------------------------------------------------------------------------*/
+cpl_vector * irplib_wlxcorr_convolve_create_kernel(double  slitw,
+                                                   double  fwhm)
+{
+    const double  sigma  = fwhm * CPL_MATH_SIG_FWHM;
+    const int     size   = 1 + (int)(5.0 * sigma + 0.5*slitw);
+    cpl_vector  * kernel = cpl_vector_new(size);
+
+
+    if (cpl_vector_fill_lss_profile_symmetric(kernel, slitw, fwhm)) {
+        cpl_vector_delete(kernel);
+        cpl_ensure(0, cpl_error_get_code(), NULL);
+    }
+
+    return kernel;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Convolve a 1d-signal with a symmetric 1D-signal
+  @param    smoothed  Preallocated vector to be smoothed in place
+  @param    conv_kernel     Vector with symmetric convolution function
+  @return   0 or -1 in error case
+
+  The length of conv_kernel must be smaller than that of smoothed.
+  
+  Possible #_cpl_error_code_ set in this function:
+  - CPL_ERROR_NULL_INPUT if (one of) the input pointer(s) is NULL
+  - CPL_ERROR_ILLEGAL_INPUT if conv_kernel is longer than smoothed
+ */
+/*----------------------------------------------------------------------------*/
+int irplib_wlxcorr_convolve(
+        cpl_vector          *   smoothed,
+        const cpl_vector    *   conv_kernel)
+{
+    int             nsamples ;
+    int             ihwidth ;
+    cpl_vector  *   raw ;
+    double      *   psmoothe ;
+    double      *   praw ;
+    const double*   psymm ;
+    int             i, j ;
+
+    /* Test entries */
+    cpl_ensure(smoothed, CPL_ERROR_NULL_INPUT, -1) ;
+    cpl_ensure(conv_kernel, CPL_ERROR_NULL_INPUT, -1) ;
+
+    /* Initialise */
+    nsamples = cpl_vector_get_size(smoothed) ;
+    ihwidth = cpl_vector_get_size(conv_kernel) - 1 ;
+    cpl_ensure(ihwidth<nsamples, CPL_ERROR_ILLEGAL_INPUT, -1) ;
+    psymm = cpl_vector_get_data_const(conv_kernel) ;
+    psmoothe = cpl_vector_get_data(smoothed) ;
+    
+    /* Create raw vector */
+    raw = cpl_vector_duplicate(smoothed) ;
+    praw = cpl_vector_get_data(raw) ;
+
+    /* Convolve with the symmetric function */
+    for (i=0 ; i<ihwidth ; i++) {
+        psmoothe[i] = praw[i] * psymm[0];
+        for (j=1 ; j <= ihwidth ; j++) {
+            const int k = i-j < 0 ? 0 : i-j;
+            psmoothe[i] += (praw[k]+praw[i+j]) * psymm[j];
+        }
+    }
+
+    for (i=ihwidth ; i<nsamples-ihwidth ; i++) {
+        psmoothe[i] = praw[i] * psymm[0];
+        for (j=1 ; j<=ihwidth ; j++)
+            psmoothe[i] += (praw[i-j]+praw[i+j]) * psymm[j];
+    }
+    for (i=nsamples-ihwidth ; i<nsamples ; i++) {
+        psmoothe[i] = praw[i] * psymm[0];
+        for (j=1 ; j<=ihwidth ; j++) {
+            const int k = i+j > nsamples-1 ? nsamples - 1 : i+j;
+            psmoothe[i] += (praw[k]+praw[i-j]) * psymm[j];
+        }
+    }
+    cpl_vector_delete(raw) ;
+    return 0 ;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Plot the wavelength solution
+  @param    init        The initial guess
+  @param    comp        The computed solution
+  @param    sol         The real solution or NULL if not available
+  @param    pix_start   The first pixel
+  @param    pix_stop    The last pixel
+  @return   0 if ok, -1 otherwise
+ */
+/*----------------------------------------------------------------------------*/
+int irplib_wlxcorr_plot_solution(
+        const cpl_polynomial    *   init,
+        const cpl_polynomial    *   comp,
+        const cpl_polynomial    *   sol,
+        int                         pix_start,
+        int                         pix_stop) 
+{
+    int                 nsamples, nplots ;
+    cpl_vector      **  vectors ;
+    cpl_bivector    *   bivector ;
+    double              diff ;
+    int                 i ;
+    
+    /* Test entries */
+    if (init == NULL || comp == NULL) return -1 ;
+    
+    /* Initialise */
+    nsamples = pix_stop - pix_start + 1 ;
+    if (sol != NULL)    nplots = 3 ;
+    else                nplots = 2 ;
+    
+    /* Create vectors */
+    vectors = cpl_malloc((nplots+1)*sizeof(cpl_vector*)) ;
+    for (i=0 ; i<nplots+1 ; i++) vectors[i] = cpl_vector_new(nsamples) ;
+
+    /* First plot with the lambda/pixel relation */
+    /* Fill vectors */
+    for (i=0 ; i<nsamples ; i++) {
+        cpl_vector_set(vectors[0], i, pix_start+i) ;
+        cpl_vector_set(vectors[1], i, 
+                cpl_polynomial_eval_1d(init, (double)(pix_start+i), NULL)) ;
+        cpl_vector_set(vectors[2], i, 
+                cpl_polynomial_eval_1d(comp, (double)(pix_start+i), NULL)) ;
+        if (sol != NULL) 
+            cpl_vector_set(vectors[3], i, 
+                    cpl_polynomial_eval_1d(sol, (double)(pix_start+i), NULL)) ;
+    }
+
+    /* Plot */
+    cpl_plot_vectors("set grid;set xlabel 'Position (pixels)';", 
+        "t '1-Initial / 2-Computed / 3-Solution' w lines", 
+        "", (const cpl_vector **)vectors, nplots+1);
+
+    /* Free vectors */
+    for (i=0 ; i<nplots+1 ; i++) cpl_vector_delete(vectors[i]) ;
+    cpl_free(vectors) ;
+
+    /* Allocate vectors */
+    nplots -- ;
+    vectors = cpl_malloc((nplots+1)*sizeof(cpl_vector*)) ;
+    for (i=0 ; i<nplots+1 ; i++) vectors[i] = cpl_vector_new(nsamples) ;
+    
+    /* Second plot with the delta-lambda/pixel relation */
+    /* Fill vectors */
+    for (i=0 ; i<nsamples ; i++) {
+        cpl_vector_set(vectors[0], i, pix_start+i) ;
+        diff = cpl_polynomial_eval_1d(comp, (double)(pix_start+i), NULL) -
+            cpl_polynomial_eval_1d(init, (double)(pix_start+i), NULL) ;
+        cpl_vector_set(vectors[1], i, diff) ;
+        if (sol != NULL) {
+            diff = cpl_polynomial_eval_1d(sol, (double)(pix_start+i), NULL) -
+                cpl_polynomial_eval_1d(init, (double)(pix_start+i), NULL) ;
+            cpl_vector_set(vectors[2], i, diff) ;
+        }
+    }
+
+    /* Plot */
+    if (sol == NULL) {
+        bivector = cpl_bivector_wrap_vectors(vectors[0], vectors[1]) ;
+        cpl_plot_bivector(
+"set grid;set xlabel 'Position (pixels)';set ylabel 'Wavelength difference';", 
+            "t 'Computed-Initial wavelenth' w lines", "", bivector);
+        cpl_bivector_unwrap_vectors(bivector) ;
+    } else {
+        cpl_plot_vectors("set grid;set xlabel 'Position (pixels)';", 
+            "t '1-Computed - Initial / 2--Solution - Initial' w lines", 
+            "", (const cpl_vector **)vectors, nplots+1);
+    }
+    
+    /* Free vectors */
+    for (i=0 ; i<nplots+1 ; i++) cpl_vector_delete(vectors[i]) ;
+    cpl_free(vectors) ;
+
+    /* Return */
+    return 0 ;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Plot the spectral table
+  @param    spc_table       The spectral table
+  @param    title           A title
+  @return   0 if ok, -1 otherwise
+ */
+/*----------------------------------------------------------------------------*/
+int irplib_wlxcorr_plot_spc_table(
+        const cpl_table     *   spc_table, 
+        const char          *   title) 
+{
+    char                title_loc[1024] ;
+    cpl_vector      **  vectors ;
+    cpl_vector      **  sub_vectors ;
+    cpl_vector      *   tmp_vec ;
+    int                 nsamples ;
+    double              max, mean1, mean3 ;
+    int                 start_ind, stop_ind, nblines, hsize_pix ;
+    int                 i, j ;
+
+    /* Test entries */
+    if (spc_table == NULL) return -1 ;
+    
+    /* Initialise */
+    nsamples = cpl_table_get_nrow(spc_table) ;
+    hsize_pix = 10 ;
+    nblines = 0 ;
+    sprintf(title_loc, 
+        "t '%s - 1-Initial catalog/2-Corrected catalog/3-Observed' w lines",
+        title) ;
+    title_loc[1023] = (char)0 ;
+    
+    vectors = cpl_malloc(4*sizeof(cpl_vector*)) ;
+    vectors[0] = cpl_vector_wrap(nsamples, 
+            cpl_table_get_data_double((cpl_table*)spc_table,
+                IRPLIB_WLXCORR_COL_WAVELENGTH));
+    vectors[1] = cpl_vector_wrap(nsamples, 
+            cpl_table_get_data_double((cpl_table*)spc_table, 
+                IRPLIB_WLXCORR_COL_CAT_INIT));
+    vectors[2] = cpl_vector_wrap(nsamples, 
+            cpl_table_get_data_double((cpl_table*)spc_table, 
+                IRPLIB_WLXCORR_COL_CAT_FINAL));
+    vectors[3] = cpl_vector_wrap(nsamples, 
+            cpl_table_get_data_double((cpl_table*)spc_table, 
+                IRPLIB_WLXCORR_COL_OBS)) ;
+
+    /* Scale the signal for a bettre display */
+    mean1 = cpl_vector_get_mean(vectors[1]) ;
+    mean3 = cpl_vector_get_mean(vectors[3]) ;
+    if (fabs(mean3) > 1)
+        cpl_vector_multiply_scalar(vectors[3], fabs(mean1/mean3)) ;
+
+    cpl_plot_vectors("set grid;set xlabel 'Wavelength (nm)';", title_loc,
+        "", (const cpl_vector **)vectors, 4);
+
+    /* Unscale the signal */
+    if (fabs(mean3) > 1)
+        cpl_vector_multiply_scalar(vectors[3], mean3/mean1) ;
+
+    /* Loop on the brightest lines and zoom on them */
+    sprintf(title_loc, 
+"t '%s - 1-Initial catalog/2-Corrected catalog/3-Observed (ZOOMED)' w lines",
+        title) ;
+    title_loc[1023] = (char)0 ;
+    tmp_vec = cpl_vector_duplicate(vectors[2]) ;
+    for (i=0 ; i<nblines ; i++) {
+        /* Find the brightest line */
+        if ((max = cpl_vector_get_max(tmp_vec)) <= 0.0) break ;
+        for (j=0 ; i<nsamples ; j++) {
+            if (cpl_vector_get(tmp_vec, j) == max) break ;
+        }
+        if (j-hsize_pix < 0) start_ind = 0 ;
+        else start_ind = j-hsize_pix ;
+        if (j+hsize_pix > nsamples-1) stop_ind = nsamples-1 ;
+        else stop_ind = j+hsize_pix ;
+        for (j=start_ind ; j<=stop_ind ; j++) cpl_vector_set(tmp_vec, j, 0.0) ;
+
+        sub_vectors = cpl_malloc(4*sizeof(cpl_vector*)) ;
+        sub_vectors[0]=cpl_vector_extract(vectors[0],start_ind,stop_ind,1);
+        sub_vectors[1]=cpl_vector_extract(vectors[1],start_ind,stop_ind,1);
+        sub_vectors[2]=cpl_vector_extract(vectors[2],start_ind,stop_ind,1);
+        sub_vectors[3]=cpl_vector_extract(vectors[3],start_ind,stop_ind,1);
+
+        cpl_plot_vectors("set grid;set xlabel 'Wavelength (nm)';", title_loc,
+            "", (const cpl_vector **)sub_vectors, 4);
+
+        cpl_vector_delete(sub_vectors[0]) ;
+        cpl_vector_delete(sub_vectors[1]) ;
+        cpl_vector_delete(sub_vectors[2]) ;
+        cpl_vector_delete(sub_vectors[3]) ;
+        cpl_free(sub_vectors) ;
+    }
+    cpl_vector_delete(tmp_vec) ;
+    
+    cpl_vector_unwrap(vectors[0]) ;
+    cpl_vector_unwrap(vectors[1]) ;
+    cpl_vector_unwrap(vectors[2]) ;
+    cpl_vector_unwrap(vectors[3]) ;
+    cpl_free(vectors) ;
+
+    return 0 ;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Plot a part of the catalog
+  @param    cat         The catalog
+  @param    wmin        The minimum wavelength
+  @param    wmax        The maximum wavelength
+  @return   0 if ok, -1 in error case
+ */
+/*----------------------------------------------------------------------------*/
+int irplib_wlxcorr_catalog_plot(
+        const cpl_bivector      *   cat,
+        double                      wmin,
+        double                      wmax) 
+{
+    int                 start, stop ;
+    cpl_bivector    *   subcat ;
+    cpl_vector      *   subcat_x ;
+    cpl_vector      *   subcat_y ;
+    const double    *   pwave ;
+    int                 nvals, nvals_tot ;
+    int                 i ;
+
+    /* Test entries */
+    if (cat == NULL) return -1 ;
+    if (wmax <= wmin) return -1 ;
+
+    /* Initialise */
+    nvals_tot = cpl_bivector_get_size(cat) ;
+
+    /* Count the nb of values */
+    pwave = cpl_bivector_get_x_data_const(cat) ;
+    if (pwave[0] >= wmin) start = 0 ;
+    else start = -1 ;
+    if (pwave[nvals_tot-1] <= wmax) stop = nvals_tot-1 ;
+    else stop = -1 ;
+    i=0 ;
+    while ((pwave[i] < wmin) && (i<nvals_tot-1)) i++ ;
+    start = i ;
+    i= nvals_tot-1 ;
+    while ((pwave[i] > wmax) && (i>0)) i-- ;
+    stop = i ;
+
+    if (start>=stop) {
+        cpl_msg_error(cpl_func, "Cannot plot the catalog") ;
+        return -1 ;
+    }
+    nvals = start - stop + 1 ;
+
+    /* Create the bivector to plot */
+    subcat_x = cpl_vector_extract(cpl_bivector_get_x_const(cat),start,stop, 1) ;
+    subcat_y = cpl_vector_extract(cpl_bivector_get_y_const(cat),start,stop, 1) ;
+    subcat = cpl_bivector_wrap_vectors(subcat_x, subcat_y) ;
+
+    /* Plot */
+    if (nvals > 500) {
+        cpl_plot_bivector(
+                "set grid;set xlabel 'Wavelength (nm)';set ylabel 'Emission';",
+                "t 'Catalog Spectrum' w lines", "", subcat);
+    } else {
+        cpl_plot_bivector(
+                "set grid;set xlabel 'Wavelength (nm)';set ylabel 'Emission';",
+                "t 'Catalog Spectrum' w impulses", "", subcat);
+    }
+    cpl_bivector_unwrap_vectors(subcat) ;
+    cpl_vector_delete(subcat_x) ;
+    cpl_vector_delete(subcat_y) ;
+
+    return 0 ;
+}
+   
+/**@}*/
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Estimate a possible solution
+  @param    vxc             The vector of cross-correlation(s) to be filled
+  @param    model           The model spectrum
+  @param    spectrum        The observed spectrum
+  @param    lines_catalog   The lines catalog
+  @param    conv_kernel     The convolution kernel, or NULL for line spectrum
+  @param    poly_candi      Candidate Polynomial 
+  @param    slitw           The slit width [pixel]
+  @param    fwhm            The spectral FWHM [pixel]
+  @return   void
+  @note vxc is filled with 0.0 on failure, errors are reset
+
+ */
+/*----------------------------------------------------------------------------*/
+static void irplib_wlxcorr_estimate(cpl_vector           * vxc,
+                                    cpl_vector           * model,
+                                    const cpl_vector     * spectrum,
+                                    const cpl_bivector   * lines_catalog,
+                                    const cpl_vector     * conv_kernel,
+                                    const cpl_polynomial * poly_candi,
+                                    double                 slitw,
+                                    double                 fwhm)
+{
+    cpl_errorstate prestate = cpl_errorstate_get();
+    const int hsize = cpl_vector_get_size(vxc) / 2;
+
+    if (conv_kernel != NULL) {
+        irplib_wlcalib_fill_spectrum(model, lines_catalog, conv_kernel,
+                                  poly_candi, hsize);
+    } else {
+        const double xtrunc = 0.5 * slitw + 5.0 * fwhm * CPL_MATH_SIG_FWHM;
+
+        irplib_vector_fill_line_spectrum_model(model, NULL, NULL, poly_candi,
+                                               lines_catalog, slitw, fwhm,
+                                               xtrunc, 0, CPL_FALSE, CPL_FALSE,
+                                               NULL);
+    }
+
+    if (cpl_errorstate_is_equal(prestate))
+        cpl_vector_correlate(vxc, model, spectrum);
+
+    if (!cpl_errorstate_is_equal(prestate)) {
+        cpl_vector_fill(vxc, 0.0);
+
+        /* cpl_errorstate_dump(prestate, CPL_FALSE, NULL); */
+        cpl_errorstate_set(prestate);
+
+    }
+
+    return;
+}
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Try to guess if a catalogue is a sampled profile or (arc) lines
+  @param    wavelengths     Cector with the wavelengths of the catalogue
+  @param    disp1d          The 1D-polynomial for the wavelengths
+  @param    spec_sz         The spectrum size
+  @param    tol             The line tolerance [lines/pixel]
+  @return   CPL_TRUE iff the catalogue is a line catalogue
+
+ */
+/*----------------------------------------------------------------------------*/
+static cpl_boolean irplib_wlcalib_is_lines(const cpl_vector * wavelengths,
+                                        const cpl_polynomial * disp1d,
+                                        int spec_sz,
+                                        double tol)
+{
+    const int nlines = cpl_vector_get_size(wavelengths);
+    /* The dispersion on the detector center */
+    const double dispersion = cpl_polynomial_eval_1d_diff(disp1d,
+                                                          0.5 * spec_sz + 1.0,
+                                                          0.5 * spec_sz,
+                                                          NULL);
+    const double range = cpl_vector_get(wavelengths, nlines-1)
+        - cpl_vector_get(wavelengths, 0);
+
+    cpl_ensure(wavelengths != NULL, CPL_ERROR_NULL_INPUT,    CPL_FALSE);
+    cpl_ensure(disp1d      != NULL, CPL_ERROR_NULL_INPUT,    CPL_FALSE);
+    cpl_ensure(cpl_polynomial_get_dimension(disp1d) == 1,
+               CPL_ERROR_ILLEGAL_INPUT, CPL_FALSE);
+    cpl_ensure(range > 0.0,      CPL_ERROR_ILLEGAL_INPUT, CPL_FALSE);
+
+    return nlines * fabs(dispersion) <= tol * fabs(range) ? CPL_TRUE
+        : CPL_FALSE;
+
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Construct the model spectrum at the given wavelengths
+  @param    self            Vector to fill
+  @param    lines_catalog   Bivector with the lines
+  @param    slitw           The slit width
+  @param    fwhm            The spectral FWHM [pixel]
+  @param    poly            the polynomial for the wavelengths
+  @param    search_hs       the half size of the searching zone
+  @return   CPL_ERROR_NONE or the relevant CPL eror on failure
+
+  The expected emission is a model spectrum used to cross-correlate
+  against an actual observed spectrum. 
+  Its size is nsamples + 2 * search_hs
+ */
+/*----------------------------------------------------------------------------*/
+static
+cpl_error_code irplib_wlcalib_fill_spectrum(cpl_vector           * self,
+                                         const cpl_bivector   * lines_catalog,
+                                         const cpl_vector     * conv_kernel,
+                                         const cpl_polynomial * poly,
+                                         int                    search_hs)
+{
+
+
+    const int          size = cpl_vector_get_size(self);
+    const int          nlines = cpl_bivector_get_size(lines_catalog);
+    const cpl_vector * xlines  = cpl_bivector_get_x_const(lines_catalog);
+    const double     * dxlines = cpl_vector_get_data_const(xlines);
+    cpl_bivector     * sub_cat ;
+    cpl_vector       * sub_cat_x;
+    cpl_vector       * sub_cat_y;
+    cpl_vector       * wl_limits;
+    double             wave_min, wave_max;
+    int                wave_min_id, wave_max_id;
+    int                nsub;
+    int                error;
+
+    cpl_ensure_code(self          != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(lines_catalog != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(conv_kernel   != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(poly          != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(size > 0,              CPL_ERROR_ILLEGAL_INPUT);
+
+
+    /* Resample the spectrum */
+    wl_limits = cpl_vector_new(size + 1);
+    cpl_vector_fill_polynomial(wl_limits, poly, 0.5 - search_hs, 1);
+
+    /* The spectrum wavelength bounds */
+    wave_min = cpl_vector_get(wl_limits, 0);
+    wave_max = cpl_vector_get(wl_limits, size);
+
+    /* Find the 1st line */
+    wave_min_id = cpl_vector_find(xlines, wave_min);
+    /* The first line must be less than or equal to wave_min */
+    if (dxlines[wave_min_id] > wave_min) wave_min_id--;
+
+    if (wave_min_id < 0) {
+        cpl_vector_delete(wl_limits);
+        return cpl_error_set_message_macro(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
+                                           __FILE__, __LINE__, "The %d-line "
+                                           "catalogue only has lines above %g",
+                                           nlines, wave_min);
+    }
+
+    /* Find the last line */
+    wave_max_id = cpl_vector_find(xlines, wave_max);
+    /* The last line must be greater than or equal to wave_max */
+    if (dxlines[wave_max_id] < wave_max) wave_max_id++;
+
+    if (wave_max_id == nlines) {
+        cpl_vector_delete(wl_limits);
+        return cpl_error_set_message_macro(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
+                                           __FILE__, __LINE__, "The %d-line "
+                                           "catalogue only has lines below %g",
+                                           nlines, wave_max);
+    }
+
+    /* Checking the wavelength range at this point via the indices also
+       verifies that they were not found using non-increasing wavelengths */
+    nsub = 1 + wave_max_id - wave_min_id;
+    cpl_ensure_code(nsub > 1, CPL_ERROR_ILLEGAL_INPUT);
+
+    /* Wrap a new bivector around the relevant part of the catalog */
+    /* The data is _not_ modified */
+    sub_cat_x = cpl_vector_wrap(nsub, wave_min_id + (double*)dxlines);
+    sub_cat_y = cpl_vector_wrap(nsub, wave_min_id + (double*)
+                                cpl_bivector_get_y_data_const(lines_catalog));
+    sub_cat = cpl_bivector_wrap_vectors(sub_cat_x, sub_cat_y);
+
+    /* High resolution catalog */
+    error = irplib_wlxcorr_signal_resample(self, wl_limits, sub_cat);
+
+    cpl_vector_delete(wl_limits);
+    cpl_bivector_unwrap_vectors(sub_cat);
+    (void)cpl_vector_unwrap(sub_cat_x);
+    (void)cpl_vector_unwrap(sub_cat_y);
+
+    cpl_ensure_code(!error, CPL_ERROR_ILLEGAL_INPUT);
+
+    /* Smooth the instrument resolution */
+    cpl_ensure_code(!irplib_wlxcorr_convolve(self, conv_kernel),
+                    cpl_error_get_code());
+
+    return CPL_ERROR_NONE;
+}
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Smoothe a 1d-signal by averaging it
+  @param    resampled Preallocated vector to hold resampled signal
+  @param    xbounds   Vector with the wavelengths boundaries
+  @param    hires     Bivector with the high resolution signal
+  @return   0 if ok, -1 otherwise
+
+  The length of xbouns must be one higher than that of the resampled signal.
+ */
+/*----------------------------------------------------------------------------*/
+static int irplib_wlxcorr_signal_resample(
+        cpl_vector          *   resampled, 
+        const cpl_vector    *   xbounds,
+        const cpl_bivector  *   hires)
+{
+    const int           hrsize = cpl_bivector_get_size(hires);
+    const cpl_vector*   xhires ;
+    const cpl_vector*   yhires ;
+    const double    *   pxhires ;
+    const double    *   pyhires ;
+    const double    *   pxbounds ;
+    cpl_vector      *   ybounds ;
+    cpl_bivector    *   boundary ;
+    double          *   pybounds ;
+    double          *   presampled ;
+    int                 nsamples ;
+    int                 i, itt ;
+   
+    /* Test entries */
+    if ((!resampled) || (!xbounds) || (!hires)) return -1 ;
+
+    /* Initialise */
+    nsamples = cpl_vector_get_size(resampled) ;
+
+    /* Initialise */
+    presampled = cpl_vector_get_data(resampled) ;
+    pxbounds = cpl_vector_get_data_const(xbounds) ;
+    xhires = cpl_bivector_get_x_const(hires) ;
+    yhires = cpl_bivector_get_y_const(hires) ;
+    pxhires = cpl_vector_get_data_const(xhires) ;
+    pyhires = cpl_vector_get_data_const(yhires) ;
+    
+    /* Create a new vector */
+    ybounds = cpl_vector_new(cpl_vector_get_size(xbounds)) ;
+    boundary = cpl_bivector_wrap_vectors((cpl_vector*)xbounds,ybounds) ;
+    pybounds = cpl_vector_get_data(ybounds) ;
+
+    /* Test entries */
+    if (cpl_bivector_get_size(boundary) != nsamples + 1) {
+        cpl_bivector_unwrap_vectors(boundary) ;
+        cpl_vector_delete(ybounds) ;
+        return -1 ;
+    }
+
+    /* Get the ind  */
+    itt = cpl_vector_find(xhires, pxbounds[0]);
+
+    /* Interpolate the signal */
+    if (cpl_bivector_interpolate_linear(boundary, hires)) {
+        cpl_bivector_unwrap_vectors(boundary) ;
+        cpl_vector_delete(ybounds) ;
+        return -1 ;
+    }
+
+    /* At this point itt most likely points to element just below
+       pxbounds[0] */
+    while (pxhires[itt] < pxbounds[0]) itt++;
+
+    for (i=0; i < nsamples; i++) {
+        /* The i'th signal is the weighted average of the two interpolated
+           signals at the pixel boundaries and those table signals in
+           between */
+
+        double xlow  = pxbounds[i];
+        double x     = pxhires[itt];
+
+        if (x > pxbounds[i+1]) x = pxbounds[i+1];
+        /* Contribution from interpolated value at wavelength at lower pixel
+           boundary */
+        presampled[i] = pybounds[i] * (x - xlow);
+
+        /* Contribution from table values in between pixel boundaries */
+        while ((pxhires[itt] < pxbounds[i+1]) && (itt < hrsize)) {
+            const double xprev = x;
+            x = pxhires[itt+1];
+            if (x > pxbounds[i+1]) x = pxbounds[i+1];
+            presampled[i] += pyhires[itt] * (x - xlow);
+            xlow = xprev;
+            itt++;
+        }
+
+        /* Contribution from interpolated value at wavelength at upper pixel
+           boundary */
+        presampled[i] += pybounds[i+1] * (pxbounds[i+1] - xlow);
+
+        /* Compute average by dividing integral by length of pixel range
+           (the factor 2 comes from the contributions) */
+        presampled[i] /= 2 * (pxbounds[i+1] - pxbounds[i]);
+    }
+    cpl_bivector_unwrap_vectors(boundary) ;
+    cpl_vector_delete(ybounds) ;
+    return 0 ;
+}
+
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @internal
+  @brief    Fill right half of a symmetric long-slit spectroscopy line profile
+  @param    self   The pre-allocated vector to be filled
+  @param    slitw  The slit width [pixel]
+  @param    fwhm   The spectral FWHM [pixel]
+  @return   CPL_ERROR_NONE or the relevant error code on failure
+
+  The smoothing function is the right half of the convolution of a Gaussian with
+  sigma =  fwhm / (2 * sqrt(2*log(2))) and a top-hat with a width equal to the
+  slit width, and area 1, and a tophat with unit width and area.
+  (the convolution with a tophat with unit width and area equals integration
+   from  i-1/2 to 1+1/2).
+  Since this function is symmetric only the central, maximum value and the
+  right half is computed, 
+  
+  Possible #_cpl_error_code_ set in this function:
+  - CPL_ERROR_NULL_INPUT if a pointer is NULL
+  - CPL_ERROR_ILLEGAL_INPUT if the slit width or fwhm is non-positive
+ */
+/*----------------------------------------------------------------------------*/
+static cpl_error_code cpl_vector_fill_lss_profile_symmetric(cpl_vector * self,
+                                                            double  slitw,
+                                                            double  fwhm)
+{
+
+    const double sigma = fwhm * CPL_MATH_SIG_FWHM;
+    const int    n     = cpl_vector_get_size(self);
+    int          i;
+
+
+    cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(slitw > 0.0,  CPL_ERROR_ILLEGAL_INPUT);
+    cpl_ensure_code(fwhm  > 0.0,  CPL_ERROR_ILLEGAL_INPUT);
+
+    /* Cannot fail now */
+
+    /* Special case for i = 0 */
+    (void)cpl_vector_set(self, 0,
+                         (irplib_erf_antideriv(0.5*slitw + 0.5, sigma) -
+                          irplib_erf_antideriv(0.5*slitw - 0.5, sigma)) / slitw);
+
+    for (i = 1; i < n; i++) {
+        /* FIXME: Reuse two irplib_erf_antideriv() calls from previous value */
+        const double x1p = i + 0.5*slitw + 0.5;
+        const double x1n = i - 0.5*slitw + 0.5;
+        const double x0p = i + 0.5*slitw - 0.5;
+        const double x0n = i - 0.5*slitw - 0.5;
+        const double val = 0.5/slitw *
+            (irplib_erf_antideriv(x1p, sigma) - irplib_erf_antideriv(x1n, sigma) -
+             irplib_erf_antideriv(x0p, sigma) + irplib_erf_antideriv(x0n, sigma));
+        (void)cpl_vector_set(self, i, val);
+    }
+
+    return CPL_ERROR_NONE;
+}
diff --git a/irplib/irplib_wlxcorr.h b/irplib/irplib_wlxcorr.h
new file mode 100644
index 0000000..ede71eb
--- /dev/null
+++ b/irplib/irplib_wlxcorr.h
@@ -0,0 +1,73 @@
+/* $Id: irplib_wlxcorr.h,v 1.20 2008/11/06 12:45:28 llundin Exp $
+ *
+ * This file is part of the IRPLIB package
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: llundin $
+ * $Date: 2008/11/06 12:45:28 $
+ * $Revision: 1.20 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifndef IRPLIB_WLXCORR_H
+#define IRPLIB_WLXCORR_H
+
+/*-----------------------------------------------------------------------------
+                                Include
+ -----------------------------------------------------------------------------*/
+
+#include <cpl.h>
+
+/*-----------------------------------------------------------------------------
+                                    Define
+ -----------------------------------------------------------------------------*/
+
+/* The 4 columns of the table */
+#define IRPLIB_WLXCORR_COL_WAVELENGTH   "Wavelength"
+#define IRPLIB_WLXCORR_COL_CAT_INIT     "Catalog Initial"
+#define IRPLIB_WLXCORR_COL_CAT_FINAL    "Catalog Corrected"
+#define IRPLIB_WLXCORR_COL_OBS          "Observed"
+
+/*-----------------------------------------------------------------------------
+                                Functions prototypes
+ -----------------------------------------------------------------------------*/
+
+int irplib_wlxcorr_plot_spc_table(const cpl_table *, const char *) ;
+int irplib_wlxcorr_catalog_plot(const cpl_bivector *, double, double) ;
+int irplib_wlxcorr_plot_solution(const cpl_polynomial *, const cpl_polynomial *,
+        const cpl_polynomial *, int, int) ;
+
+cpl_polynomial * irplib_wlxcorr_best_poly(const cpl_vector *, 
+        const cpl_bivector *, int, const cpl_polynomial *, const cpl_vector *, 
+        int, double, double, double *, cpl_table **, cpl_vector **) ;
+cpl_table * irplib_wlxcorr_gen_spc_table(const cpl_vector *, 
+        const cpl_bivector *, double, double, const cpl_polynomial *,
+        const cpl_polynomial *) ;
+cpl_bivector * irplib_wlxcorr_cat_extract(const cpl_bivector *, double, double);
+cpl_vector * irplib_wlxcorr_convolve_create_kernel(double, double) ;
+int irplib_wlxcorr_convolve(cpl_vector *,const cpl_vector *) ;
+
+
+cpl_error_code irplib_wlxcorr_vector_fill_line_spectrum(cpl_vector *,
+                                                const cpl_polynomial *,
+                                                const cpl_bivector *,
+                                                double, double, double,
+                                                int);
+
+#endif
diff --git a/irplib/tests/Makefile.am b/irplib/tests/Makefile.am
new file mode 100644
index 0000000..893d5b8
--- /dev/null
+++ b/irplib/tests/Makefile.am
@@ -0,0 +1,90 @@
+## Process this file with automake to produce Makefile.in
+
+##   This file is part of the IRPLIB package
+##   Copyright (C) 2002,2003 European Southern Observatory
+
+##   This library is free software; you can redistribute it and/or modify
+##   it under the terms of the GNU General Public License as published by
+##   the Free Software Foundation; either version 2 of the License, or
+##   (at your option) any later version.
+
+##   This program is distributed in the hope that it will be useful,
+##   but WITHOUT ANY WARRANTY; without even the implied warranty of
+##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+##   GNU General Public License for more details.
+
+##   You should have received a copy of the GNU General Public License
+##   along with this program; if not, write to the Free Software
+##   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+
+AUTOMAKE_OPTIONS = 1.8 foreign
+
+DISTCLEANFILES = *~
+
+
+if MAINTAINER_MODE
+
+MAINTAINERCLEANFILES = Makefile.in
+
+endif
+
+INCLUDES = $(all_includes)
+
+LDADD = $(LIBIRPLIB) 
+
+pkginclude_HEADERS =
+
+noinst_HEADERS =
+
+check_PROGRAMS = irplib_wlxcorr-test \
+                 irplib_hist-test \
+                 irplib_polynomial-test \
+                 irplib_plugin-test \
+                 irplib_utils-test \
+                 irplib_framelist-test \
+                 irplib_wcs-test \
+                 irplib_cat-test
+
+irplib_framelist_test_SOURCES = irplib_framelist-test.c
+irplib_framelist_test_DEPENDENCIES = $(LIBIRPLIB)
+
+irplib_utils_test_SOURCES = irplib_utils-test.c
+irplib_utils_test_DEPENDENCIES = $(LIBIRPLIB)
+
+irplib_hist_test_SOURCES = irplib_hist-test.c
+irplib_hist_test_DEPENDENCIES = $(LIBIRPLIB)
+
+irplib_polynomial_test_SOURCES = irplib_polynomial-test.c
+irplib_polynomial_test_DEPENDENCIES = $(LIBIRPLIB)
+
+irplib_plugin_test_SOURCES = irplib_plugin-test.c
+irplib_plugin_test_DEPENDENCIES = $(LIBIRPLIB)
+
+irplib_wlxcorr_test_SOURCES = irplib_wlxcorr-test.c
+irplib_wlxcorr_test_DEPENDENCIES = $(LIBIRPLIB)
+
+irplib_wcs_test_SOURCES = irplib_wcs-test.c
+irplib_wcs_test_DEPENDENCIES = $(LIBIRPLIB)
+irplib_wcs_test_LDADD = $(LIBIRPLIB) $(LIBWCSLIB)
+irplib_wcs_test_LDFLAGS = $(WCSLIB_LDFLAGS)
+
+irplib_cat_test_SOURCES = irplib_cat-test.c
+irplib_cat_test_DEPENDENCIES = $(LIBIRPLIB)
+irplib_cat_test_LDADD = $(LIBIRPLIB) $(LIBWCSLIB)
+irplib_cat_test_LDFLAGS = $(WCSLIB_LDFLAGS)
+
+TESTS          = $(check_PROGRAMS)
+
+# Be sure to reexport important environment variables.
+TESTS_ENVIRONMENT = MAKE="$(MAKE)" CC="$(CC)" CFLAGS="$(CFLAGS)" \
+        CPPFLAGS="$(CPPFLAGS)" LD="$(LD)" LDFLAGS="$(LDFLAGS)" \
+        LIBS="$(LIBS)" LN_S="$(LN_S)" NM="$(NM)" RANLIB="$(RANLIB)" \
+        OBJEXT="$(OBJEXT)" EXEEXT="$(EXEEXT)"
+
+# We need to remove any files that the above tests created.
+clean-local: 
+	 $(RM) *.log *.paf *.fits .logfile
+
+#if PURIFY
+#include $(top_builddir)/Makefile.purify
+#endif
diff --git a/irplib/tests/Makefile.in b/irplib/tests/Makefile.in
new file mode 100644
index 0000000..4eac43c
--- /dev/null
+++ b/irplib/tests/Makefile.in
@@ -0,0 +1,766 @@
+# Makefile.in generated by automake 1.11 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009  Free Software Foundation,
+# Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+ at SET_MAKE@
+
+VPATH = @srcdir@
+pkgdatadir = $(datadir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkglibexecdir = $(libexecdir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
+target_triplet = @target@
+check_PROGRAMS = irplib_wlxcorr-test$(EXEEXT) \
+	irplib_hist-test$(EXEEXT) irplib_polynomial-test$(EXEEXT) \
+	irplib_plugin-test$(EXEEXT) irplib_utils-test$(EXEEXT) \
+	irplib_framelist-test$(EXEEXT) irplib_wcs-test$(EXEEXT) \
+	irplib_cat-test$(EXEEXT)
+subdir = irplib/tests
+DIST_COMMON = $(noinst_HEADERS) $(pkginclude_HEADERS) \
+	$(srcdir)/Makefile.am $(srcdir)/Makefile.in
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/m4macros/cpl.m4 \
+	$(top_srcdir)/m4macros/eso.m4 \
+	$(top_srcdir)/m4macros/libtool.m4 \
+	$(top_srcdir)/m4macros/ltoptions.m4 \
+	$(top_srcdir)/m4macros/ltsugar.m4 \
+	$(top_srcdir)/m4macros/ltversion.m4 \
+	$(top_srcdir)/m4macros/lt~obsolete.m4 \
+	$(top_srcdir)/m4macros/purify.m4 $(top_srcdir)/acinclude.m4 \
+	$(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+	$(ACLOCAL_M4)
+mkinstalldirs = $(install_sh) -d
+CONFIG_HEADER = $(top_builddir)/config.h
+CONFIG_CLEAN_FILES =
+CONFIG_CLEAN_VPATH_FILES =
+am_irplib_cat_test_OBJECTS = irplib_cat-test.$(OBJEXT)
+irplib_cat_test_OBJECTS = $(am_irplib_cat_test_OBJECTS)
+am__DEPENDENCIES_1 =
+irplib_cat_test_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
+	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+	$(irplib_cat_test_LDFLAGS) $(LDFLAGS) -o $@
+am_irplib_framelist_test_OBJECTS = irplib_framelist-test.$(OBJEXT)
+irplib_framelist_test_OBJECTS = $(am_irplib_framelist_test_OBJECTS)
+irplib_framelist_test_LDADD = $(LDADD)
+am_irplib_hist_test_OBJECTS = irplib_hist-test.$(OBJEXT)
+irplib_hist_test_OBJECTS = $(am_irplib_hist_test_OBJECTS)
+irplib_hist_test_LDADD = $(LDADD)
+am_irplib_plugin_test_OBJECTS = irplib_plugin-test.$(OBJEXT)
+irplib_plugin_test_OBJECTS = $(am_irplib_plugin_test_OBJECTS)
+irplib_plugin_test_LDADD = $(LDADD)
+am_irplib_polynomial_test_OBJECTS = irplib_polynomial-test.$(OBJEXT)
+irplib_polynomial_test_OBJECTS = $(am_irplib_polynomial_test_OBJECTS)
+irplib_polynomial_test_LDADD = $(LDADD)
+am_irplib_utils_test_OBJECTS = irplib_utils-test.$(OBJEXT)
+irplib_utils_test_OBJECTS = $(am_irplib_utils_test_OBJECTS)
+irplib_utils_test_LDADD = $(LDADD)
+am_irplib_wcs_test_OBJECTS = irplib_wcs-test.$(OBJEXT)
+irplib_wcs_test_OBJECTS = $(am_irplib_wcs_test_OBJECTS)
+irplib_wcs_test_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
+	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+	$(irplib_wcs_test_LDFLAGS) $(LDFLAGS) -o $@
+am_irplib_wlxcorr_test_OBJECTS = irplib_wlxcorr-test.$(OBJEXT)
+irplib_wlxcorr_test_OBJECTS = $(am_irplib_wlxcorr_test_OBJECTS)
+irplib_wlxcorr_test_LDADD = $(LDADD)
+DEFAULT_INCLUDES = -I. at am__isrc@ -I$(top_builddir)
+depcomp = $(SHELL) $(top_srcdir)/admin/depcomp
+am__depfiles_maybe = depfiles
+am__mv = mv -f
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+	--mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
+	$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+CCLD = $(CC)
+LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+	--mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
+	$(LDFLAGS) -o $@
+SOURCES = $(irplib_cat_test_SOURCES) $(irplib_framelist_test_SOURCES) \
+	$(irplib_hist_test_SOURCES) $(irplib_plugin_test_SOURCES) \
+	$(irplib_polynomial_test_SOURCES) $(irplib_utils_test_SOURCES) \
+	$(irplib_wcs_test_SOURCES) $(irplib_wlxcorr_test_SOURCES)
+DIST_SOURCES = $(irplib_cat_test_SOURCES) \
+	$(irplib_framelist_test_SOURCES) $(irplib_hist_test_SOURCES) \
+	$(irplib_plugin_test_SOURCES) \
+	$(irplib_polynomial_test_SOURCES) $(irplib_utils_test_SOURCES) \
+	$(irplib_wcs_test_SOURCES) $(irplib_wlxcorr_test_SOURCES)
+am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
+am__vpath_adj = case $$p in \
+    $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
+    *) f=$$p;; \
+  esac;
+am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`;
+am__install_max = 40
+am__nobase_strip_setup = \
+  srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'`
+am__nobase_strip = \
+  for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||"
+am__nobase_list = $(am__nobase_strip_setup); \
+  for p in $$list; do echo "$$p $$p"; done | \
+  sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \
+  $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \
+    if (++n[$$2] == $(am__install_max)) \
+      { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \
+    END { for (dir in files) print dir, files[dir] }'
+am__base_list = \
+  sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
+  sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
+am__installdirs = "$(DESTDIR)$(pkgincludedir)"
+HEADERS = $(noinst_HEADERS) $(pkginclude_HEADERS)
+ETAGS = etags
+CTAGS = ctags
+am__tty_colors = \
+red=; grn=; lgn=; blu=; std=
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+ACLOCAL = @ACLOCAL@
+AMTAR = @AMTAR@
+AR = @AR@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CPL_INCLUDES = @CPL_INCLUDES@
+CPL_LDFLAGS = @CPL_LDFLAGS@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CX_INCLUDES = @CX_INCLUDES@
+CX_LDFLAGS = @CX_LDFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+DOXYGEN = @DOXYGEN@
+DSYMUTIL = @DSYMUTIL@
+DUMPBIN = @DUMPBIN@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+ESO_DEBUG_FLAGS = @ESO_DEBUG_FLAGS@
+EXEEXT = @EXEEXT@
+FGREP = @FGREP@
+GREP = @GREP@
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+IRPLIB_INCLUDES = @IRPLIB_INCLUDES@
+IRPLIB_LDFLAGS = @IRPLIB_LDFLAGS@
+LATEX = @LATEX@
+LD = @LD@
+LDFLAGS = @LDFLAGS@
+LIBCEXT = @LIBCEXT@
+LIBCPLCORE = @LIBCPLCORE@
+LIBCPLDFS = @LIBCPLDFS@
+LIBCPLDRS = @LIBCPLDRS@
+LIBCPLUI = @LIBCPLUI@
+LIBIRPLIB = @LIBIRPLIB@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LIBSINFONI = @LIBSINFONI@
+LIBTOOL = @LIBTOOL@
+LIBTOOL_DEPS = @LIBTOOL_DEPS@
+LIPO = @LIPO@
+LN_S = @LN_S@
+LTLIBOBJS = @LTLIBOBJS@
+LT_AGE = @LT_AGE@
+LT_CURRENT = @LT_CURRENT@
+LT_REVISION = @LT_REVISION@
+MAINT = @MAINT@
+MAKEINFO = @MAKEINFO@
+MKDIR_P = @MKDIR_P@
+NM = @NM@
+NMEDIT = @NMEDIT@
+OBJDUMP = @OBJDUMP@
+OBJEXT = @OBJEXT@
+OTOOL = @OTOOL@
+OTOOL64 = @OTOOL64@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+PURIFY_CMD = @PURIFY_CMD@
+RANLIB = @RANLIB@
+SED = @SED@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+SINFONI_BINARY_AGE = @SINFONI_BINARY_AGE@
+SINFONI_BINARY_VERSION = @SINFONI_BINARY_VERSION@
+SINFONI_INCLUDES = @SINFONI_INCLUDES@
+SINFONI_INTERFACE_AGE = @SINFONI_INTERFACE_AGE@
+SINFONI_LDFLAGS = @SINFONI_LDFLAGS@
+SINFONI_MAJOR_VERSION = @SINFONI_MAJOR_VERSION@
+SINFONI_MICRO_VERSION = @SINFONI_MICRO_VERSION@
+SINFONI_MINOR_VERSION = @SINFONI_MINOR_VERSION@
+SINFONI_VERSION = @SINFONI_VERSION@
+STRIP = @STRIP@
+VERSION = @VERSION@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
+all_includes = @all_includes@
+all_ldflags = @all_ldflags@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build = @build@
+build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
+builddir = @builddir@
+configdir = @configdir@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
+exec_prefix = @exec_prefix@
+host = @host@
+host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localedir = @localedir@
+localstatedir = @localstatedir@
+lt_ECHO = @lt_ECHO@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+pipedocsdir = @pipedocsdir@
+plugindir = @plugindir@
+prefix = @prefix@
+privatelibdir = @privatelibdir@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
+sysconfdir = @sysconfdir@
+target = @target@
+target_alias = @target_alias@
+target_cpu = @target_cpu@
+target_os = @target_os@
+target_vendor = @target_vendor@
+top_build_prefix = @top_build_prefix@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+AUTOMAKE_OPTIONS = 1.8 foreign
+DISTCLEANFILES = *~
+ at MAINTAINER_MODE_TRUE@MAINTAINERCLEANFILES = Makefile.in
+INCLUDES = $(all_includes)
+LDADD = $(LIBIRPLIB) 
+pkginclude_HEADERS = 
+noinst_HEADERS = 
+irplib_framelist_test_SOURCES = irplib_framelist-test.c
+irplib_framelist_test_DEPENDENCIES = $(LIBIRPLIB)
+irplib_utils_test_SOURCES = irplib_utils-test.c
+irplib_utils_test_DEPENDENCIES = $(LIBIRPLIB)
+irplib_hist_test_SOURCES = irplib_hist-test.c
+irplib_hist_test_DEPENDENCIES = $(LIBIRPLIB)
+irplib_polynomial_test_SOURCES = irplib_polynomial-test.c
+irplib_polynomial_test_DEPENDENCIES = $(LIBIRPLIB)
+irplib_plugin_test_SOURCES = irplib_plugin-test.c
+irplib_plugin_test_DEPENDENCIES = $(LIBIRPLIB)
+irplib_wlxcorr_test_SOURCES = irplib_wlxcorr-test.c
+irplib_wlxcorr_test_DEPENDENCIES = $(LIBIRPLIB)
+irplib_wcs_test_SOURCES = irplib_wcs-test.c
+irplib_wcs_test_DEPENDENCIES = $(LIBIRPLIB)
+irplib_wcs_test_LDADD = $(LIBIRPLIB) $(LIBWCSLIB)
+irplib_wcs_test_LDFLAGS = $(WCSLIB_LDFLAGS)
+irplib_cat_test_SOURCES = irplib_cat-test.c
+irplib_cat_test_DEPENDENCIES = $(LIBIRPLIB)
+irplib_cat_test_LDADD = $(LIBIRPLIB) $(LIBWCSLIB)
+irplib_cat_test_LDFLAGS = $(WCSLIB_LDFLAGS)
+TESTS = $(check_PROGRAMS)
+
+# Be sure to reexport important environment variables.
+TESTS_ENVIRONMENT = MAKE="$(MAKE)" CC="$(CC)" CFLAGS="$(CFLAGS)" \
+        CPPFLAGS="$(CPPFLAGS)" LD="$(LD)" LDFLAGS="$(LDFLAGS)" \
+        LIBS="$(LIBS)" LN_S="$(LN_S)" NM="$(NM)" RANLIB="$(RANLIB)" \
+        OBJEXT="$(OBJEXT)" EXEEXT="$(EXEEXT)"
+
+all: all-am
+
+.SUFFIXES:
+.SUFFIXES: .c .lo .o .obj
+$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am  $(am__configure_deps)
+	@for dep in $?; do \
+	  case '$(am__configure_deps)' in \
+	    *$$dep*) \
+	      ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+	        && { if test -f $@; then exit 0; else break; fi; }; \
+	      exit 1;; \
+	  esac; \
+	done; \
+	echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign irplib/tests/Makefile'; \
+	$(am__cd) $(top_srcdir) && \
+	  $(AUTOMAKE) --foreign irplib/tests/Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+	@case '$?' in \
+	  *config.status*) \
+	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+	  *) \
+	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
+	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+	esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(am__aclocal_m4_deps):
+
+clean-checkPROGRAMS:
+	@list='$(check_PROGRAMS)'; test -n "$$list" || exit 0; \
+	echo " rm -f" $$list; \
+	rm -f $$list || exit $$?; \
+	test -n "$(EXEEXT)" || exit 0; \
+	list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \
+	echo " rm -f" $$list; \
+	rm -f $$list
+irplib_cat-test$(EXEEXT): $(irplib_cat_test_OBJECTS) $(irplib_cat_test_DEPENDENCIES) 
+	@rm -f irplib_cat-test$(EXEEXT)
+	$(irplib_cat_test_LINK) $(irplib_cat_test_OBJECTS) $(irplib_cat_test_LDADD) $(LIBS)
+irplib_framelist-test$(EXEEXT): $(irplib_framelist_test_OBJECTS) $(irplib_framelist_test_DEPENDENCIES) 
+	@rm -f irplib_framelist-test$(EXEEXT)
+	$(LINK) $(irplib_framelist_test_OBJECTS) $(irplib_framelist_test_LDADD) $(LIBS)
+irplib_hist-test$(EXEEXT): $(irplib_hist_test_OBJECTS) $(irplib_hist_test_DEPENDENCIES) 
+	@rm -f irplib_hist-test$(EXEEXT)
+	$(LINK) $(irplib_hist_test_OBJECTS) $(irplib_hist_test_LDADD) $(LIBS)
+irplib_plugin-test$(EXEEXT): $(irplib_plugin_test_OBJECTS) $(irplib_plugin_test_DEPENDENCIES) 
+	@rm -f irplib_plugin-test$(EXEEXT)
+	$(LINK) $(irplib_plugin_test_OBJECTS) $(irplib_plugin_test_LDADD) $(LIBS)
+irplib_polynomial-test$(EXEEXT): $(irplib_polynomial_test_OBJECTS) $(irplib_polynomial_test_DEPENDENCIES) 
+	@rm -f irplib_polynomial-test$(EXEEXT)
+	$(LINK) $(irplib_polynomial_test_OBJECTS) $(irplib_polynomial_test_LDADD) $(LIBS)
+irplib_utils-test$(EXEEXT): $(irplib_utils_test_OBJECTS) $(irplib_utils_test_DEPENDENCIES) 
+	@rm -f irplib_utils-test$(EXEEXT)
+	$(LINK) $(irplib_utils_test_OBJECTS) $(irplib_utils_test_LDADD) $(LIBS)
+irplib_wcs-test$(EXEEXT): $(irplib_wcs_test_OBJECTS) $(irplib_wcs_test_DEPENDENCIES) 
+	@rm -f irplib_wcs-test$(EXEEXT)
+	$(irplib_wcs_test_LINK) $(irplib_wcs_test_OBJECTS) $(irplib_wcs_test_LDADD) $(LIBS)
+irplib_wlxcorr-test$(EXEEXT): $(irplib_wlxcorr_test_OBJECTS) $(irplib_wlxcorr_test_DEPENDENCIES) 
+	@rm -f irplib_wlxcorr-test$(EXEEXT)
+	$(LINK) $(irplib_wlxcorr_test_OBJECTS) $(irplib_wlxcorr_test_LDADD) $(LIBS)
+
+mostlyclean-compile:
+	-rm -f *.$(OBJEXT)
+
+distclean-compile:
+	-rm -f *.tab.c
+
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/irplib_cat-test.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/irplib_framelist-test.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/irplib_hist-test.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/irplib_plugin-test.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/irplib_polynomial-test.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/irplib_utils-test.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/irplib_wcs-test.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/irplib_wlxcorr-test.Po at am__quote@
+
+.c.o:
+ at am__fastdepCC_TRUE@	$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+ at am__fastdepCC_TRUE@	$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCC_FALSE@	$(COMPILE) -c $<
+
+.c.obj:
+ at am__fastdepCC_TRUE@	$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
+ at am__fastdepCC_TRUE@	$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCC_FALSE@	$(COMPILE) -c `$(CYGPATH_W) '$<'`
+
+.c.lo:
+ at am__fastdepCC_TRUE@	$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+ at am__fastdepCC_TRUE@	$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCC_FALSE@	$(LTCOMPILE) -c -o $@ $<
+
+mostlyclean-libtool:
+	-rm -f *.lo
+
+clean-libtool:
+	-rm -rf .libs _libs
+install-pkgincludeHEADERS: $(pkginclude_HEADERS)
+	@$(NORMAL_INSTALL)
+	test -z "$(pkgincludedir)" || $(MKDIR_P) "$(DESTDIR)$(pkgincludedir)"
+	@list='$(pkginclude_HEADERS)'; test -n "$(pkgincludedir)" || list=; \
+	for p in $$list; do \
+	  if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
+	  echo "$$d$$p"; \
+	done | $(am__base_list) | \
+	while read files; do \
+	  echo " $(INSTALL_HEADER) $$files '$(DESTDIR)$(pkgincludedir)'"; \
+	  $(INSTALL_HEADER) $$files "$(DESTDIR)$(pkgincludedir)" || exit $$?; \
+	done
+
+uninstall-pkgincludeHEADERS:
+	@$(NORMAL_UNINSTALL)
+	@list='$(pkginclude_HEADERS)'; test -n "$(pkgincludedir)" || list=; \
+	files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
+	test -n "$$files" || exit 0; \
+	echo " ( cd '$(DESTDIR)$(pkgincludedir)' && rm -f" $$files ")"; \
+	cd "$(DESTDIR)$(pkgincludedir)" && rm -f $$files
+
+ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
+	list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	mkid -fID $$unique
+tags: TAGS
+
+TAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
+		$(TAGS_FILES) $(LISP)
+	set x; \
+	here=`pwd`; \
+	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	shift; \
+	if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
+	  test -n "$$unique" || unique=$$empty_fix; \
+	  if test $$# -gt 0; then \
+	    $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+	      "$$@" $$unique; \
+	  else \
+	    $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+	      $$unique; \
+	  fi; \
+	fi
+ctags: CTAGS
+CTAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
+		$(TAGS_FILES) $(LISP)
+	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	test -z "$(CTAGS_ARGS)$$unique" \
+	  || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+	     $$unique
+
+GTAGS:
+	here=`$(am__cd) $(top_builddir) && pwd` \
+	  && $(am__cd) $(top_srcdir) \
+	  && gtags -i $(GTAGS_ARGS) "$$here"
+
+distclean-tags:
+	-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+
+check-TESTS: $(TESTS)
+	@failed=0; all=0; xfail=0; xpass=0; skip=0; \
+	srcdir=$(srcdir); export srcdir; \
+	list=' $(TESTS) '; \
+	$(am__tty_colors); \
+	if test -n "$$list"; then \
+	  for tst in $$list; do \
+	    if test -f ./$$tst; then dir=./; \
+	    elif test -f $$tst; then dir=; \
+	    else dir="$(srcdir)/"; fi; \
+	    if $(TESTS_ENVIRONMENT) $${dir}$$tst; then \
+	      all=`expr $$all + 1`; \
+	      case " $(XFAIL_TESTS) " in \
+	      *[\ \	]$$tst[\ \	]*) \
+		xpass=`expr $$xpass + 1`; \
+		failed=`expr $$failed + 1`; \
+		col=$$red; res=XPASS; \
+	      ;; \
+	      *) \
+		col=$$grn; res=PASS; \
+	      ;; \
+	      esac; \
+	    elif test $$? -ne 77; then \
+	      all=`expr $$all + 1`; \
+	      case " $(XFAIL_TESTS) " in \
+	      *[\ \	]$$tst[\ \	]*) \
+		xfail=`expr $$xfail + 1`; \
+		col=$$lgn; res=XFAIL; \
+	      ;; \
+	      *) \
+		failed=`expr $$failed + 1`; \
+		col=$$red; res=FAIL; \
+	      ;; \
+	      esac; \
+	    else \
+	      skip=`expr $$skip + 1`; \
+	      col=$$blu; res=SKIP; \
+	    fi; \
+	    echo "$${col}$$res$${std}: $$tst"; \
+	  done; \
+	  if test "$$all" -eq 1; then \
+	    tests="test"; \
+	    All=""; \
+	  else \
+	    tests="tests"; \
+	    All="All "; \
+	  fi; \
+	  if test "$$failed" -eq 0; then \
+	    if test "$$xfail" -eq 0; then \
+	      banner="$$All$$all $$tests passed"; \
+	    else \
+	      if test "$$xfail" -eq 1; then failures=failure; else failures=failures; fi; \
+	      banner="$$All$$all $$tests behaved as expected ($$xfail expected $$failures)"; \
+	    fi; \
+	  else \
+	    if test "$$xpass" -eq 0; then \
+	      banner="$$failed of $$all $$tests failed"; \
+	    else \
+	      if test "$$xpass" -eq 1; then passes=pass; else passes=passes; fi; \
+	      banner="$$failed of $$all $$tests did not behave as expected ($$xpass unexpected $$passes)"; \
+	    fi; \
+	  fi; \
+	  dashes="$$banner"; \
+	  skipped=""; \
+	  if test "$$skip" -ne 0; then \
+	    if test "$$skip" -eq 1; then \
+	      skipped="($$skip test was not run)"; \
+	    else \
+	      skipped="($$skip tests were not run)"; \
+	    fi; \
+	    test `echo "$$skipped" | wc -c` -le `echo "$$banner" | wc -c` || \
+	      dashes="$$skipped"; \
+	  fi; \
+	  report=""; \
+	  if test "$$failed" -ne 0 && test -n "$(PACKAGE_BUGREPORT)"; then \
+	    report="Please report to $(PACKAGE_BUGREPORT)"; \
+	    test `echo "$$report" | wc -c` -le `echo "$$banner" | wc -c` || \
+	      dashes="$$report"; \
+	  fi; \
+	  dashes=`echo "$$dashes" | sed s/./=/g`; \
+	  if test "$$failed" -eq 0; then \
+	    echo "$$grn$$dashes"; \
+	  else \
+	    echo "$$red$$dashes"; \
+	  fi; \
+	  echo "$$banner"; \
+	  test -z "$$skipped" || echo "$$skipped"; \
+	  test -z "$$report" || echo "$$report"; \
+	  echo "$$dashes$$std"; \
+	  test "$$failed" -eq 0; \
+	else :; fi
+
+distdir: $(DISTFILES)
+	@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+	topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+	list='$(DISTFILES)'; \
+	  dist_files=`for file in $$list; do echo $$file; done | \
+	  sed -e "s|^$$srcdirstrip/||;t" \
+	      -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+	case $$dist_files in \
+	  */*) $(MKDIR_P) `echo "$$dist_files" | \
+			   sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+			   sort -u` ;; \
+	esac; \
+	for file in $$dist_files; do \
+	  if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+	  if test -d $$d/$$file; then \
+	    dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+	    if test -d "$(distdir)/$$file"; then \
+	      find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+	    fi; \
+	    if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+	      cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
+	      find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+	    fi; \
+	    cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
+	  else \
+	    test -f "$(distdir)/$$file" \
+	    || cp -p $$d/$$file "$(distdir)/$$file" \
+	    || exit 1; \
+	  fi; \
+	done
+check-am: all-am
+	$(MAKE) $(AM_MAKEFLAGS) $(check_PROGRAMS)
+	$(MAKE) $(AM_MAKEFLAGS) check-TESTS
+check: check-am
+all-am: Makefile $(HEADERS)
+installdirs:
+	for dir in "$(DESTDIR)$(pkgincludedir)"; do \
+	  test -z "$$dir" || $(MKDIR_P) "$$dir"; \
+	done
+install: install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+	@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+	$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+	  install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+	  `test -z '$(STRIP)' || \
+	    echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+	-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+	-test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
+	-test -z "$(DISTCLEANFILES)" || rm -f $(DISTCLEANFILES)
+
+maintainer-clean-generic:
+	@echo "This command is intended for maintainers to use"
+	@echo "it deletes files that may require special tools to rebuild."
+	-test -z "$(MAINTAINERCLEANFILES)" || rm -f $(MAINTAINERCLEANFILES)
+clean: clean-am
+
+clean-am: clean-checkPROGRAMS clean-generic clean-libtool clean-local \
+	mostlyclean-am
+
+distclean: distclean-am
+	-rm -rf ./$(DEPDIR)
+	-rm -f Makefile
+distclean-am: clean-am distclean-compile distclean-generic \
+	distclean-tags
+
+dvi: dvi-am
+
+dvi-am:
+
+html: html-am
+
+html-am:
+
+info: info-am
+
+info-am:
+
+install-data-am: install-pkgincludeHEADERS
+
+install-dvi: install-dvi-am
+
+install-dvi-am:
+
+install-exec-am:
+
+install-html: install-html-am
+
+install-html-am:
+
+install-info: install-info-am
+
+install-info-am:
+
+install-man:
+
+install-pdf: install-pdf-am
+
+install-pdf-am:
+
+install-ps: install-ps-am
+
+install-ps-am:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+	-rm -rf ./$(DEPDIR)
+	-rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-compile mostlyclean-generic \
+	mostlyclean-libtool
+
+pdf: pdf-am
+
+pdf-am:
+
+ps: ps-am
+
+ps-am:
+
+uninstall-am: uninstall-pkgincludeHEADERS
+
+.MAKE: check-am install-am install-strip
+
+.PHONY: CTAGS GTAGS all all-am check check-TESTS check-am clean \
+	clean-checkPROGRAMS clean-generic clean-libtool clean-local \
+	ctags distclean distclean-compile distclean-generic \
+	distclean-libtool distclean-tags distdir dvi dvi-am html \
+	html-am info info-am install install-am install-data \
+	install-data-am install-dvi install-dvi-am install-exec \
+	install-exec-am install-html install-html-am install-info \
+	install-info-am install-man install-pdf install-pdf-am \
+	install-pkgincludeHEADERS install-ps install-ps-am \
+	install-strip installcheck installcheck-am installdirs \
+	maintainer-clean maintainer-clean-generic mostlyclean \
+	mostlyclean-compile mostlyclean-generic mostlyclean-libtool \
+	pdf pdf-am ps ps-am tags uninstall uninstall-am \
+	uninstall-pkgincludeHEADERS
+
+
+# We need to remove any files that the above tests created.
+clean-local: 
+	 $(RM) *.log *.paf *.fits .logfile
+
+#if PURIFY
+#include $(top_builddir)/Makefile.purify
+#endif
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/irplib/tests/irplib_cat-test.c b/irplib/tests/irplib_cat-test.c
new file mode 100644
index 0000000..9c80a66
--- /dev/null
+++ b/irplib/tests/irplib_cat-test.c
@@ -0,0 +1,98 @@
+/* $Id: irplib_cat-test.c,v 1.9 2009/08/12 14:26:44 cgarcia Exp $
+ *
+ * This file is part of the ESO Common Pipeline Library
+ * Copyright (C) 2001-2008 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: cgarcia $
+ * $Date: 2009/08/12 14:26:44 $
+ * $Revision: 1.9 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+/*-----------------------------------------------------------------------------
+                                   Includes
+ -----------------------------------------------------------------------------*/
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <cpl_test.h>
+
+#include "irplib_cat.h"
+
+/*-----------------------------------------------------------------------------
+                                   Static functions
+ -----------------------------------------------------------------------------*/
+static void irplib_cat_all_test(void);
+
+/*-----------------------------------------------------------------------------
+                                  Main
+ -----------------------------------------------------------------------------*/
+int main (void)
+{
+
+    cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
+
+    irplib_cat_all_test();
+
+    return cpl_test_end(0);
+}
+
+static void irplib_cat_all_test(void)
+{
+    cpl_propertylist * prop_wcs;
+    cpl_wcs          * wcs = NULL;
+    double             ra1, ra2, dec1, dec2;
+
+    /* Create WCS object */
+    prop_wcs = cpl_propertylist_new();
+    cpl_test_nonnull(prop_wcs);
+    cpl_propertylist_append_double(prop_wcs, "CRVAL1", 0.);
+    cpl_propertylist_append_double(prop_wcs, "CRVAL2", 0.);
+    cpl_propertylist_append_int(prop_wcs, "CRPIX1", 1);
+    cpl_propertylist_append_int(prop_wcs, "CRPIX2", 1);
+    cpl_propertylist_append_double(prop_wcs, "CD1_1", .001);
+    cpl_propertylist_append_double(prop_wcs, "CD1_2", 0.);
+    cpl_propertylist_append_double(prop_wcs, "CD2_1", 00.);
+    cpl_propertylist_append_double(prop_wcs, "CD2_2", .001);
+    cpl_propertylist_append_int(prop_wcs, "NAXIS", 2);
+    cpl_propertylist_append_int(prop_wcs, "NAXIS1", 1000);
+    cpl_propertylist_append_int(prop_wcs, "NAXIS2", 1000);
+    wcs = cpl_wcs_new_from_propertylist(prop_wcs);
+    if(cpl_error_get_code() == CPL_ERROR_NO_WCS)
+    {
+        cpl_msg_warning(__func__,"No WCS present. Tests disabled");
+        cpl_test_error(CPL_ERROR_NO_WCS);
+        cpl_test_null(wcs);
+        cpl_propertylist_delete(prop_wcs);
+        return;
+    }
+    cpl_test_nonnull(wcs);
+
+    irplib_cat_get_image_limits(wcs, 0., &ra1, &ra2, &dec1, &dec2);
+    cpl_test_error(CPL_ERROR_NONE);
+    cpl_test_abs(ra1, 0.00, DBL_EPSILON);
+    cpl_test_abs(ra2,  0.99,  DBL_EPSILON);
+    cpl_test_abs(dec1,  0.00, DBL_EPSILON);
+    cpl_test_abs(dec2,  0.99,  DBL_EPSILON);
+
+    /* Free */
+    cpl_wcs_delete(wcs);
+    cpl_propertylist_delete(prop_wcs);
+}
diff --git a/irplib/tests/irplib_framelist-test.c b/irplib/tests/irplib_framelist-test.c
new file mode 100644
index 0000000..a2a6bdc
--- /dev/null
+++ b/irplib/tests/irplib_framelist-test.c
@@ -0,0 +1,98 @@
+/*                                                                            *
+ *   This file is part of the ESO IRPLIB package                              *
+ *   Copyright (C) 2004,2005 European Southern Observatory                    *
+ *                                                                            *
+ *   This library is free software; you can redistribute it and/or modify     *
+ *   it under the terms of the GNU General Public License as published by     *
+ *   the Free Software Foundation; either version 2 of the License, or        *
+ *   (at your option) any later version.                                      *
+ *                                                                            *
+ *   This program is distributed in the hope that it will be useful,          *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of           *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
+ *   GNU General Public License for more details.                             *
+ *                                                                            *
+ *   You should have received a copy of the GNU General Public License        *
+ *   along with this program; if not, write to the Free Software              *
+ *   Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA     *
+ *                                                                            */
+ 
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+/*-----------------------------------------------------------------------------
+                                Includes
+ -----------------------------------------------------------------------------*/
+
+#include <irplib_framelist.h>
+
+
+/*----------------------------------------------------------------------------*/
+/**
+ * @defgroup irplib_framelist_test Testing of the IRPLIB framelist object
+ */
+/*----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------*/
+/**
+   @brief   Unit tests of framelist module
+**/
+/*----------------------------------------------------------------------------*/
+
+int main(void)
+{
+
+    irplib_framelist * flist;
+    irplib_framelist * nulllist;
+    cpl_frameset     * fset;
+    cpl_frameset     * nullset;
+    int i;
+
+    /* Initialize CPL for unit testing */
+    cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
+
+    /* Some NULL tests */
+
+    irplib_framelist_delete(NULL);
+    cpl_test_error(CPL_ERROR_NONE);
+
+    nulllist = irplib_framelist_cast(NULL);
+    cpl_test_error(CPL_ERROR_NULL_INPUT);
+    cpl_test_null(nulllist);
+
+    nullset = irplib_frameset_cast(NULL);
+    cpl_test_error(CPL_ERROR_NULL_INPUT);
+    cpl_test_null(nullset);
+
+    irplib_framelist_empty(NULL);
+    cpl_test_error(CPL_ERROR_NONE);
+
+    i = irplib_framelist_get_size(NULL);
+    cpl_test_error(CPL_ERROR_NULL_INPUT);
+    cpl_test_leq(i, -1);
+
+
+    /* Some tests on an empty list */
+    flist = irplib_framelist_new();
+
+    cpl_test_zero(irplib_framelist_get_size(flist));
+
+    irplib_framelist_empty(flist);
+
+    cpl_test_zero(irplib_framelist_get_size(flist));
+
+    fset = irplib_frameset_cast(flist);
+
+    irplib_framelist_delete(flist);
+
+    flist = irplib_framelist_cast(fset);
+
+    cpl_test_zero(irplib_framelist_get_size(flist));
+
+    cpl_frameset_delete(fset);
+    irplib_framelist_delete(flist);
+
+    return cpl_test_end(0);
+}
diff --git a/irplib/tests/irplib_hist-test.c b/irplib/tests/irplib_hist-test.c
new file mode 100644
index 0000000..61947e7
--- /dev/null
+++ b/irplib/tests/irplib_hist-test.c
@@ -0,0 +1,150 @@
+/*                                                                              *
+ *   This file is part of the ESO IRPLIB package                                *
+ *   Copyright (C) 2004,2005 European Southern Observatory                      *
+ *                                                                              *
+ *   This library is free software; you can redistribute it and/or modify       *
+ *   it under the terms of the GNU General Public License as published by       *
+ *   the Free Software Foundation; either version 2 of the License, or          *
+ *   (at your option) any later version.                                        *
+ *                                                                              *
+ *   This program is distributed in the hope that it will be useful,            *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of             *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
+ *   GNU General Public License for more details.                               *
+ *                                                                              *
+ *   You should have received a copy of the GNU General Public License          *
+ *   along with this program; if not, write to the Free Software                *
+ *   Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA       *
+ *                                                                              */
+ 
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+/*----------------------------------------------------------------------------
+                                Includes
+ ----------------------------------------------------------------------------*/
+
+
+#include <irplib_hist.h>
+
+#include <math.h>
+/*---------------------------------------------------------------------------*/
+/*
+ * @defgroup irplib_hist_test   Testing of the IRPLIB utilities
+ */
+/*---------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+				Defines
+ ----------------------------------------------------------------------------*/
+
+#define NBINS 100
+
+/*----------------------------------------------------------------------------
+                            Private Function prototypes
+ ----------------------------------------------------------------------------*/
+
+static void irplib_hist_tests(void);
+
+/*---------------------------------------------------------------------------*/
+/*
+ * @brief   Unit tests of fit module
+ */
+/*---------------------------------------------------------------------------*/
+
+int main(void)
+{
+    /* Initialize CPL + IRPLIB */
+    cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
+
+    irplib_hist_tests();
+
+    return cpl_test_end(0);
+}
+
+static void irplib_hist_tests(void)
+{
+    irplib_hist * hist;
+    cpl_image * image;
+    cpl_error_code error;
+    int i, j;
+    float * data;
+
+    unsigned long max_where;
+
+    /* 1. trial: Create a right histogram */
+    hist = irplib_hist_new();
+    cpl_test_nonnull(hist);
+    cpl_test_error(CPL_ERROR_NONE);
+    irplib_hist_delete(hist);
+
+    /* 3. trial: Histogram for a uniform image */
+    image = cpl_image_new(100, 100, CPL_TYPE_FLOAT);
+    cpl_image_add_scalar(image, 202);
+
+    hist = irplib_hist_new();
+
+    error = irplib_hist_init(hist, NBINS, 0, 500);
+    cpl_test_zero(error);
+    error = irplib_hist_fill(hist, image);
+    cpl_test_zero(error);
+
+    for(i = 0; i < 40; i++) {
+	cpl_test_zero(irplib_hist_get_value(hist, i));
+    }
+
+    /* The following call retrieves the value of the 42-st bin */
+    /* When i = 41, 42-th is retrieved. 500 - 0 / 100 = 5; 202/5=40,xx
+       it should be in the 41-th bin but it is in the next one because
+       there is one before left empty for possible values out of range
+       0 (hinit) < 202 (image constant)
+    */
+
+    cpl_test_eq(irplib_hist_get_value(hist, 40), 10000);
+    for(i = 42; i < NBINS; i++) {
+	cpl_test_zero(irplib_hist_get_value(hist, i));
+    }
+
+    irplib_hist_delete(hist);
+    cpl_image_delete(image);
+
+    /* 4. trial: Histogram for a normal image: no checking of the output */
+    image = cpl_image_new(100, 100, CPL_TYPE_FLOAT);
+    cpl_image_fill_noise_uniform(image, 0, 200);
+
+    hist = irplib_hist_new();
+    error = irplib_hist_fill(hist,image);
+    cpl_test_zero(error);
+
+    irplib_hist_delete(hist);
+    cpl_image_delete(image);
+
+    /* 5. trial: Histogram */
+    image = cpl_image_new(100, 100, CPL_TYPE_FLOAT);
+    data = cpl_image_get_data_float(image);
+    for (i = 0; i < 100; i++) {
+	for (j = 0; j < 100; j++) {
+	    *(data + 100*i + j) = i +j;
+	}
+    }
+
+    hist = irplib_hist_new();
+    error = irplib_hist_fill(hist, image);
+
+    irplib_hist_get_max(hist, &max_where);
+
+    /* The following call retrieves the value of the 41-st bin */
+    /*  cpl_test_eq(irplib_hist_get_value(hist, 40), 10000);
+	for(i = 42; i < NBINS; i++) {
+	cpl_test_zero(irplib_hist_get_value(hist, i));
+	}*/
+
+    /* 6. trial: all by default ( we use the same image) */
+
+    cpl_test_eq(max_where, irplib_hist_get_nbins(hist)/2);
+
+    irplib_hist_delete(hist);
+    cpl_image_delete(image);
+}
diff --git a/irplib/tests/irplib_plugin-test.c b/irplib/tests/irplib_plugin-test.c
new file mode 100644
index 0000000..ad8dd5c
--- /dev/null
+++ b/irplib/tests/irplib_plugin-test.c
@@ -0,0 +1,129 @@
+/*                                                                            *
+ *   This file is part of the ESO IRPLIB package                              *
+ *   Copyright (C) 2004,2005 European Southern Observatory                    *
+ *                                                                            *
+ *   This library is free software; you can redistribute it and/or modify     *
+ *   it under the terms of the GNU General Public License as published by     *
+ *   the Free Software Foundation; either version 2 of the License, or        *
+ *   (at your option) any later version.                                      *
+ *                                                                            *
+ *   This program is distributed in the hope that it will be useful,          *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of           *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
+ *   GNU General Public License for more details.                             *
+ *                                                                            *
+ *   You should have received a copy of the GNU General Public License        *
+ *   along with this program; if not, write to the Free Software              *
+ *   Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA     *
+ *                                                                            */
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+/*-----------------------------------------------------------------------------
+                                Includes
+ -----------------------------------------------------------------------------*/
+
+#include <irplib_plugin.h>
+#include <string.h>
+#include <float.h>
+
+/*-----------------------------------------------------------------------------
+                                   Function prototypes
+ -----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------*/
+/**
+ * @defgroup irplib_plugin_test Testing of the IRPLIB utilities
+ */
+/*----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------*/
+/**
+   @brief   Unit tests of plugin module
+**/
+/*----------------------------------------------------------------------------*/
+
+int main(void)
+{
+
+
+
+    cpl_parameterlist * parlist;
+
+    /* Initialize CPL for unit testing */
+    cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
+
+    parlist = cpl_parameterlist_new();
+
+
+    (void)irplib_parameterlist_get_double(parlist, "INST", "RECIPE", NULL);
+    cpl_test_error(CPL_ERROR_NULL_INPUT);
+
+    (void)irplib_parameterlist_get_double(parlist, "INST", NULL, "PAR");
+    cpl_test_error(CPL_ERROR_NULL_INPUT);
+
+    (void)irplib_parameterlist_get_double(parlist, NULL, "RECIPE", "PAR");
+    cpl_test_error(CPL_ERROR_NULL_INPUT);
+
+    (void)irplib_parameterlist_get_double(NULL, "INST", "RECIPE", "PAR");
+    cpl_test_error(CPL_ERROR_NULL_INPUT);
+
+    (void)irplib_parameterlist_get_double(parlist, "INST", "RECIPE", "PAR");
+    cpl_test_error(CPL_ERROR_DATA_NOT_FOUND);
+
+
+    (void)irplib_parameterlist_get_int(parlist, "INST", "RECIPE", NULL);
+    cpl_test_error(CPL_ERROR_NULL_INPUT);
+
+    (void)irplib_parameterlist_get_int(parlist, "INST", NULL, "PAR");
+    cpl_test_error(CPL_ERROR_NULL_INPUT);
+
+    (void)irplib_parameterlist_get_int(parlist, NULL, "RECIPE", "PAR");
+    cpl_test_error(CPL_ERROR_NULL_INPUT);
+
+    (void)irplib_parameterlist_get_int(NULL, "INST", "RECIPE", "PAR");
+    cpl_test_error(CPL_ERROR_NULL_INPUT);
+
+    (void)irplib_parameterlist_get_int(parlist, "INST", "RECIPE", "PAR");
+    cpl_test_error(CPL_ERROR_DATA_NOT_FOUND);
+
+
+    (void)irplib_parameterlist_get_bool(parlist, "INST", "RECIPE", NULL);
+    cpl_test_error(CPL_ERROR_NULL_INPUT);
+
+    (void)irplib_parameterlist_get_bool(parlist, "INST", NULL, "PAR");
+    cpl_test_error(CPL_ERROR_NULL_INPUT);
+
+    (void)irplib_parameterlist_get_bool(parlist, NULL, "RECIPE", "PAR");
+    cpl_test_error(CPL_ERROR_NULL_INPUT);
+
+    (void)irplib_parameterlist_get_bool(NULL, "INST", "RECIPE", "PAR");
+    cpl_test_error(CPL_ERROR_NULL_INPUT);
+
+    (void)irplib_parameterlist_get_bool(parlist, "INST", "RECIPE", "PAR");
+    cpl_test_error(CPL_ERROR_DATA_NOT_FOUND);
+
+
+    (void)irplib_parameterlist_get_string(parlist, "INST", "RECIPE", NULL);
+    cpl_test_error(CPL_ERROR_NULL_INPUT);
+
+    (void)irplib_parameterlist_get_string(parlist, "INST", NULL, "PAR");
+    cpl_test_error(CPL_ERROR_NULL_INPUT);
+
+    (void)irplib_parameterlist_get_string(parlist, NULL, "RECIPE", "PAR");
+    cpl_test_error(CPL_ERROR_NULL_INPUT);
+
+    (void)irplib_parameterlist_get_string(NULL, "INST", "RECIPE", "PAR");
+    cpl_test_error(CPL_ERROR_NULL_INPUT);
+
+    (void)irplib_parameterlist_get_string(parlist, "INST", "RECIPE", "PAR");
+    cpl_test_error(CPL_ERROR_DATA_NOT_FOUND);
+
+
+    cpl_parameterlist_delete(parlist);
+
+    return cpl_test_end(0);
+}
diff --git a/irplib/tests/irplib_polynomial-test.c b/irplib/tests/irplib_polynomial-test.c
new file mode 100644
index 0000000..2013cbe
--- /dev/null
+++ b/irplib/tests/irplib_polynomial-test.c
@@ -0,0 +1,582 @@
+/* $Id: irplib_polynomial-test.c,v 1.35 2011/12/14 13:05:01 llundin Exp $
+ *
+ * This file is part of the ESO Common Pipeline Library
+ * Copyright (C) 2001-2004 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: llundin $
+ * $Date: 2011/12/14 13:05:01 $
+ * $Revision: 1.35 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+/*-----------------------------------------------------------------------------
+                                   Includes
+ -----------------------------------------------------------------------------*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <irplib_polynomial.h>
+#include <math.h>
+#include <float.h>
+
+/*-----------------------------------------------------------------------------
+                                   Defines
+ -----------------------------------------------------------------------------*/
+
+#define MAXDEGREE 6
+
+#define irplib_polynomial_test_root_all(A, B, C, D, E)                  \
+    irplib_polynomial_test_root_all_macro(A, B, C, D, E, __LINE__)
+
+/*-----------------------------------------------------------------------------
+                                   Static functions
+ -----------------------------------------------------------------------------*/
+
+static cpl_error_code irplib_polynomial_multiply_1d_factor(cpl_polynomial *,
+                                                        const cpl_vector *,
+                                                        cpl_size);
+static void irplib_polynomial_solve_1d_all_test(void);
+
+static void irplib_polynomial_test_root_all_macro(const cpl_vector *, cpl_size,
+                                                  double, double, double,
+                                                  unsigned);
+
+/*-----------------------------------------------------------------------------
+                                  Main
+ -----------------------------------------------------------------------------*/
+int main(void)
+{
+    /* Initialize CPL */
+    cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
+
+    irplib_polynomial_solve_1d_all_test();
+
+    return cpl_test_end(0);
+}
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @internal
+  @brief Test irplib_polynomial_solve_1d_all()
+  @see irplib_polynomial_solve_1d_all()
+  
+ */
+/*----------------------------------------------------------------------------*/
+static void irplib_polynomial_solve_1d_all_test(void)
+{
+
+    cpl_polynomial * p2d   = cpl_polynomial_new(2);
+    cpl_polynomial * p1d   = cpl_polynomial_new(1);
+    cpl_vector     * xtrue = cpl_vector_new(2);
+    const cpl_size   maxdegree = 4; /* Largest robustly handled degree */
+    cpl_size         nreal = 0;
+    cpl_size         i;
+
+    cpl_test_eq(irplib_polynomial_solve_1d_all(NULL, xtrue, &nreal),
+                CPL_ERROR_NULL_INPUT);
+    cpl_test_error(CPL_ERROR_NULL_INPUT);
+
+    cpl_test_eq(irplib_polynomial_solve_1d_all(p1d, NULL, &nreal),
+                CPL_ERROR_NULL_INPUT);
+    cpl_test_error(CPL_ERROR_NULL_INPUT);
+
+    cpl_test_eq(irplib_polynomial_solve_1d_all(p1d, xtrue, NULL),
+                CPL_ERROR_NULL_INPUT);
+    cpl_test_error(CPL_ERROR_NULL_INPUT);
+
+    cpl_test_eq(irplib_polynomial_solve_1d_all(p2d, xtrue, &nreal),
+                CPL_ERROR_INVALID_TYPE);
+    cpl_test_error(CPL_ERROR_INVALID_TYPE);
+
+    cpl_test_eq(irplib_polynomial_solve_1d_all(p1d, xtrue, &nreal),
+                CPL_ERROR_DATA_NOT_FOUND);
+    cpl_test_error(CPL_ERROR_DATA_NOT_FOUND);
+
+    /* Create a 1st degree polynomial, x = 0 */
+    i = 1;
+    cpl_test_eq(cpl_polynomial_set_coeff(p1d, &i, 1.0), CPL_ERROR_NONE);
+    cpl_test_eq(irplib_polynomial_solve_1d_all(p1d, xtrue, &nreal),
+                CPL_ERROR_INCOMPATIBLE_INPUT);
+    cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT);
+
+    cpl_polynomial_delete(p1d);
+    cpl_polynomial_delete(p2d);
+
+    for (nreal = 1; nreal <= maxdegree; nreal++) {
+        /* A single, zero-valued root with multiplicity equal to degree */
+        double xreal = 0.0;
+
+
+        cpl_vector_set_size(xtrue, nreal);
+
+        (void)cpl_vector_fill(xtrue, xreal);
+
+        irplib_polynomial_test_root_all(xtrue, nreal, CPL_MATH_PI,
+                                        2.0 * DBL_EPSILON, 2.0 * DBL_EPSILON);
+
+        /* A single, non-zero integer root with multiplicity equal to degree */
+        xreal = 1.0;
+
+        (void)cpl_vector_fill(xtrue, xreal);
+
+        irplib_polynomial_test_root_all(xtrue, nreal, 1.0,
+                                        2.0 * DBL_EPSILON, 2.0 * DBL_EPSILON);
+
+        /* degree distinct real roots - with rounding */
+        for (i = 0; i < nreal; i++) {
+            (void)cpl_vector_set(xtrue, i, 2.0 * (double)i - CPL_MATH_E);
+        }
+
+        irplib_polynomial_test_root_all(xtrue, nreal, CPL_MATH_PI,
+                                        20.0 * DBL_EPSILON,
+                                        300.0 * DBL_EPSILON);
+
+        /* All real, one zero, one positive, rest negative, sum zero */
+        for (i = 0; i < nreal-1; i++) {
+            (void)cpl_vector_set(xtrue, nreal-i-2, (double)(-i));
+        }
+        (void)cpl_vector_set(xtrue, nreal-1, (double)(nreal-1)); /* FIXME: ? */
+
+        irplib_polynomial_test_root_all(xtrue, nreal, CPL_MATH_PI,
+                                        16.0*DBL_EPSILON, 600.0*DBL_EPSILON);
+
+        if (nreal < 2) continue;
+        /* Two complex, conjugate roots, the rest is real
+           with multiplicity degree-2 */
+
+        (void)cpl_vector_fill(xtrue, 2.0);
+        (void)cpl_vector_set(xtrue, nreal-2, -1.0);
+        (void)cpl_vector_set(xtrue, nreal-1, 1.0);
+
+        irplib_polynomial_test_root_all(xtrue, nreal-2, CPL_MATH_PI,
+                                        30.0*DBL_EPSILON, 25.0*DBL_EPSILON);
+
+        if (nreal < 3) continue;
+        if (nreal > 4) {
+            /* Two real roots, the smaller with multiplicity degree-1 */
+            (void)cpl_vector_fill(xtrue, 1.0);
+            (void)cpl_vector_set(xtrue, nreal - 1 , 2.0);
+
+            irplib_polynomial_test_root_all(xtrue, nreal, CPL_MATH_PI,
+                                            DBL_EPSILON, DBL_EPSILON);
+            /* Same with negative roots */
+            (void)cpl_vector_fill(xtrue, -1.0);
+            (void)cpl_vector_set(xtrue, 0 , -2.0);
+
+            irplib_polynomial_test_root_all(xtrue, nreal, CPL_MATH_PI,
+                                            DBL_EPSILON, DBL_EPSILON);
+            /* Two real roots, the larger with multiplicity degree-1 */
+            (void)cpl_vector_fill(xtrue, 2.0);
+            (void)cpl_vector_set(xtrue, 0, 1.0);
+
+            irplib_polynomial_test_root_all(xtrue, nreal, CPL_MATH_PI,
+                                            DBL_EPSILON, DBL_EPSILON);
+        }
+
+        if (nreal > 3) continue;
+
+        /* Same with negative roots */
+        (void)cpl_vector_fill(xtrue, -2.0 * FLT_EPSILON);
+        (void)cpl_vector_set(xtrue, 0, -1.0);
+
+        irplib_polynomial_test_root_all(xtrue, nreal, CPL_MATH_PI,
+                                        DBL_EPSILON, 2.0*DBL_EPSILON);
+
+        /* A more extreme case: Same with negative roots */
+        (void)cpl_vector_fill(xtrue, -2.0e-4 * FLT_EPSILON);
+        (void)cpl_vector_set(xtrue, 0, -1.0);
+
+        irplib_polynomial_test_root_all(xtrue, nreal, CPL_MATH_PI,
+                                        FLT_EPSILON, 3.0*DBL_EPSILON);
+
+        if (nreal != 3) {
+            /* The most extreme case: Same with negative roots */
+            (void)cpl_vector_fill(xtrue, -2.0 * DBL_EPSILON);
+            (void)cpl_vector_set(xtrue, 0, -1.0);
+
+            irplib_polynomial_test_root_all(xtrue, nreal, CPL_MATH_PI,
+                                            DBL_EPSILON, 2.0*DBL_EPSILON);
+
+
+            (void)cpl_vector_set(xtrue, 0, -1.0);
+            (void)cpl_vector_set(xtrue, 1, -2.0e-4 * FLT_EPSILON);
+            (void)cpl_vector_set(xtrue, 2,  2.0e-4 * FLT_EPSILON);
+
+            irplib_polynomial_test_root_all(xtrue, nreal, CPL_MATH_PI,
+                                            FLT_EPSILON, 2.0*DBL_EPSILON);
+        }
+
+        /* Two complex conjugate roots, remaining:
+           small, with multiplicity degree-2 */
+        (void)cpl_vector_fill(xtrue, 2.0*DBL_EPSILON);
+        (void)cpl_vector_set(xtrue, nreal - 2 , 3.0);
+        (void)cpl_vector_set(xtrue, nreal - 1 , 2.0);
+
+        irplib_polynomial_test_root_all(xtrue, nreal - 2, CPL_MATH_PI,
+                                        4.0 * DBL_EPSILON, DBL_EPSILON);
+
+        /* Two complex conjugate roots with small real part, remaining:
+           with multiplicity degree-2 */
+        (void)cpl_vector_fill(xtrue, 3.0);
+        (void)cpl_vector_set(xtrue, nreal - 2 , -1.0);
+        (void)cpl_vector_set(xtrue, nreal - 1 , 2.0);
+
+        irplib_polynomial_test_root_all(xtrue, nreal - 2, CPL_MATH_PI,
+                                        6.0*DBL_EPSILON, 220.0*DBL_EPSILON);
+
+
+    }
+
+#if MAXDEGREE > 2
+    /* Cover branch fixing cancellation with one negative,
+         one positive near-zero and one positive root. */
+    nreal = 3;
+
+    cpl_vector_set_size(xtrue, nreal);
+
+    /* -2, epsilon, 1  */
+    (void)cpl_vector_set(xtrue, 0, -2.0);
+    (void)cpl_vector_set(xtrue, 1,  2.0 * DBL_EPSILON);
+    (void)cpl_vector_set(xtrue, 2,  1.5);
+
+    irplib_polynomial_test_root_all(xtrue, nreal, 1.0,
+                                    4.0*DBL_EPSILON, 30.0*DBL_EPSILON);
+
+#if MAXDEGREE > 3
+    nreal = 4;
+
+    cpl_vector_set_size(xtrue, nreal);
+
+    /* Depressed has zero as root */
+    (void)cpl_vector_set(xtrue, 0, -1.0);
+    (void)cpl_vector_set(xtrue, 1,  1.0);
+    (void)cpl_vector_set(xtrue, 2,  2.0);
+    (void)cpl_vector_set(xtrue, 3,  2.0);
+
+    irplib_polynomial_test_root_all(xtrue, nreal, CPL_MATH_PI,
+                                    2.0 * DBL_EPSILON, 2.0 * DBL_EPSILON);
+
+    /* Depressed has zero as root, and two complex roots*/
+    irplib_polynomial_test_root_all(xtrue, 2, CPL_MATH_PI,
+                                    2.0 * DBL_EPSILON, 2.0 * DBL_EPSILON);
+
+
+    /* Depressed is biquadratic, with 4 real roots */
+    (void)cpl_vector_set(xtrue, 0, -2.0);
+    (void)cpl_vector_set(xtrue, 1, -1.0);
+    (void)cpl_vector_set(xtrue, 2,  1.0);
+    (void)cpl_vector_set(xtrue, 3,  2.0);
+
+    irplib_polynomial_test_root_all(xtrue, nreal, CPL_MATH_PI,
+                                    2.0 * DBL_EPSILON, 2.0 * DBL_EPSILON);
+
+    /* Depressed is biquadratic, with 2 real roots */
+    (void)cpl_vector_set(xtrue, 0, -1.0);
+    (void)cpl_vector_set(xtrue, 1, 1.0);
+    (void)cpl_vector_set(xtrue, 2, 0.0);
+    (void)cpl_vector_set(xtrue, 3, 2.0);
+
+    irplib_polynomial_test_root_all(xtrue, 2, CPL_MATH_PI,
+                                    2.0 * DBL_EPSILON, 2.0 * DBL_EPSILON);
+
+    /* Depressed is biquadratic (the quadratic has real, negative roots),
+       with 0 real roots */
+    (void)cpl_vector_set(xtrue, 0, 1.0);
+    (void)cpl_vector_set(xtrue, 1, 2.0);
+    (void)cpl_vector_set(xtrue, 2, 1.0);
+    (void)cpl_vector_set(xtrue, 3, 3.0);
+
+    irplib_polynomial_test_root_all(xtrue, 0, CPL_MATH_PI,
+                                    10.0 * DBL_EPSILON, 10.0 * DBL_EPSILON);
+
+    /* roots: 0, 0, ai, -ai */
+    (void)cpl_vector_set(xtrue, 0,  0.0);
+    (void)cpl_vector_set(xtrue, 1,  0.0);
+    (void)cpl_vector_set(xtrue, 2,  0.0);
+    (void)cpl_vector_set(xtrue, 3,  2.0);
+
+    irplib_polynomial_test_root_all(xtrue, 2, CPL_MATH_PI,
+                                    2.0 * DBL_EPSILON, 2.0 * DBL_EPSILON);
+
+    p1d = cpl_polynomial_new(1);
+
+    i = 0;
+    cpl_polynomial_set_coeff(p1d, &i, -5.0);
+    i = 1;
+    cpl_polynomial_set_coeff(p1d, &i, -1.0);
+    i = 2;
+    cpl_polynomial_set_coeff(p1d, &i, -2.0);
+    i = 4;
+    cpl_polynomial_set_coeff(p1d, &i,  1.0);
+
+    cpl_test_eq(irplib_polynomial_solve_1d_all(p1d, xtrue, &nreal),
+                CPL_ERROR_NONE);
+
+    cpl_msg_info(cpl_func, "Computed roots (%" CPL_SIZE_FORMAT " real): ",
+                 nreal);
+    if (cpl_msg_get_level() <= CPL_MSG_INFO)
+        cpl_vector_dump(xtrue, stderr);
+    cpl_msg_info(cpl_func, "Residual: %g -> %g ", cpl_vector_get(xtrue, 0),
+                 cpl_polynomial_eval_1d(p1d, cpl_vector_get(xtrue, 0), NULL) );
+    cpl_msg_info(cpl_func, "Residual: %g -> %g ", cpl_vector_get(xtrue, 1),
+                 cpl_polynomial_eval_1d(p1d, cpl_vector_get(xtrue, 1), NULL) );
+
+    cpl_polynomial_delete(p1d);
+
+    (void)cpl_vector_set(xtrue, 0, 0.0);
+    (void)cpl_vector_set(xtrue, 1, 2.0);
+    (void)cpl_vector_set(xtrue, 2, 1.0);
+    (void)cpl_vector_set(xtrue, 3, 1.0);
+
+    irplib_polynomial_test_root_all(xtrue, 0, CPL_MATH_PI,
+                                    2.0 * DBL_EPSILON, 2.0 * DBL_EPSILON);
+
+    (void)cpl_vector_set(xtrue, 0, -1.0);
+    (void)cpl_vector_set(xtrue, 1, 2.0);
+    (void)cpl_vector_set(xtrue, 2, 1.0);
+    (void)cpl_vector_set(xtrue, 3, 3.0);
+
+    irplib_polynomial_test_root_all(xtrue, 0, CPL_MATH_PI,
+                                    3.0 * DBL_EPSILON, 3.0 * DBL_EPSILON);
+#if MAXDEGREE > 4
+    nreal = 5;
+
+    cpl_vector_set_size(xtrue, nreal);
+
+    /* Depressed has zero as root */
+    (void)cpl_vector_set(xtrue, 0, -1.0);
+    (void)cpl_vector_set(xtrue, 1,  1.0);
+    (void)cpl_vector_set(xtrue, 2,  2.0);
+    (void)cpl_vector_set(xtrue, 3,  3.0);
+    (void)cpl_vector_set(xtrue, 4,  4.0);
+
+    irplib_polynomial_test_root_all(xtrue, nreal, CPL_MATH_PI,
+                                    48.0 * DBL_EPSILON, 2800.0 * DBL_EPSILON);
+
+    irplib_polynomial_test_root_all(xtrue, nreal-2, CPL_MATH_PI,
+                                    8.0 * DBL_EPSILON, 4000.0 * DBL_EPSILON);
+
+    irplib_polynomial_test_root_all(xtrue, nreal-4, CPL_MATH_PI,
+                                    4.0 * DBL_EPSILON, 600.0 * DBL_EPSILON);
+
+#if MAXDEGREE > 5
+    nreal = 6;
+
+    cpl_vector_set_size(xtrue, nreal);
+
+    /* Depressed has zero as root */
+    (void)cpl_vector_set(xtrue, 0, -1.0);
+    (void)cpl_vector_set(xtrue, 1,  1.0);
+    (void)cpl_vector_set(xtrue, 2,  2.0);
+    (void)cpl_vector_set(xtrue, 3,  3.0);
+    (void)cpl_vector_set(xtrue, 4,  4.0);
+    (void)cpl_vector_set(xtrue, 5,  5.0);
+
+    irplib_polynomial_test_root_all(xtrue, nreal, CPL_MATH_PI,
+                                    240.0 * DBL_EPSILON, 50.0e3 * DBL_EPSILON);
+
+    irplib_polynomial_test_root_all(xtrue, nreal-2, CPL_MATH_PI,
+                                    8.0 * DBL_EPSILON, 25.0e3 * DBL_EPSILON);
+
+    irplib_polynomial_test_root_all(xtrue, nreal-4, CPL_MATH_PI,
+                                    12.0 * DBL_EPSILON, 1600.0 * DBL_EPSILON);
+
+#endif
+#endif
+#endif
+#endif
+
+    cpl_vector_delete(xtrue);
+
+    return;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @internal
+  @brief    Multiply a polynomial by (x-v1)(x-v2)...(x-vn)
+  @param    self  The 1D-polynomial to modify
+  @param    roots The roots to use for the extension
+  @pram     nreal The number of real roots
+  @return   CPL_ERROR_NONE or the relevant CPL error code.
+ 
+  
+ */
+/*----------------------------------------------------------------------------*/
+static
+cpl_error_code irplib_polynomial_multiply_1d_factor(cpl_polynomial * self,
+                                                    const cpl_vector * roots,
+                                                    cpl_size nreal)
+{
+
+    const cpl_size nroots = cpl_vector_get_size(roots);
+    cpl_size       i, degree;
+
+    cpl_ensure_code(self  != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(roots != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(cpl_polynomial_get_dimension(self) == 1,
+                     CPL_ERROR_ILLEGAL_INPUT);
+
+    cpl_ensure_code(nreal >= 0,    CPL_ERROR_ILLEGAL_INPUT);
+    cpl_ensure_code(nreal <= nroots,
+                     CPL_ERROR_ILLEGAL_INPUT);
+    cpl_ensure_code((cpl_vector_get_size(roots) - nreal) % 2 == 0,
+                     CPL_ERROR_ILLEGAL_INPUT);
+
+    i = 0;
+    degree = cpl_polynomial_get_degree(self);
+    cpl_ensure_code(degree > 0 || cpl_polynomial_get_coeff(self, &i) != 0.0,
+                     CPL_ERROR_DATA_NOT_FOUND);
+
+    for (i = 0; i < nreal; i++) {
+        const double root = cpl_vector_get(roots, i);
+        double prev = 0.0;
+        cpl_size j;
+
+        degree++;
+
+        for (j = degree; j >= 0; j--) {
+            double value = 0.0;
+            double newval;
+
+            if (j > 0) {
+                const cpl_size jj = j - 1;
+                newval = value = cpl_polynomial_get_coeff(self, &jj);
+            } else {
+                newval = 0.0;
+            }
+
+            if (j < degree) {
+                newval -= root * prev;
+            }
+
+            cpl_polynomial_set_coeff(self, &j, newval);
+
+            prev = value;
+
+        }
+    }
+
+    /* Multiplication with the complex conjugate root
+       (x-a-ib) (x-a+ib) p(x) = (x-a)^2 p(x) + b^2 p(x) */
+    for (; i < nroots; i += 2) {
+        const double a = cpl_vector_get(roots, i);
+        const double b = cpl_vector_get(roots, i+1);
+        cpl_vector * aroot = cpl_vector_new(2);
+        cpl_polynomial * copy = cpl_polynomial_duplicate(self);
+
+        cpl_vector_fill(aroot, a);
+
+        irplib_polynomial_multiply_1d_factor(self, aroot, 2);
+
+        irplib_polynomial_multiply_scalar(copy, copy, b * b);
+
+        irplib_polynomial_add(self, self, copy);
+
+        cpl_vector_delete(aroot);
+        cpl_polynomial_delete(copy);
+
+    }
+
+    return CPL_ERROR_NONE;
+
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @internal
+  @brief    Test the roots of a 1D-polynomial
+  @param    self      The roots to use for the extension
+  @pram     nreal     The number of real roots in self
+  @param    factor    The factor of the leading polynomial term
+  @param    tolerance The acceptable absolute tolerance on each root
+  @param    resitol   The acceptable absolute residual of each root
+  @param    line      __LINE__
+  @return   void 
+  
+ */
+/*----------------------------------------------------------------------------*/
+static void
+irplib_polynomial_test_root_all_macro(const cpl_vector * self, cpl_size nreal,
+                                      double factor, double tolerance,
+                                      double resitol, unsigned line)
+{
+
+    const cpl_size degree = cpl_vector_get_size(self);
+    cpl_polynomial * p1d = cpl_polynomial_new(1);
+    cpl_vector * roots = cpl_vector_new(degree);
+    cpl_size i = 0;
+    cpl_size jreal;
+
+    cpl_test_eq(cpl_polynomial_set_coeff(p1d, &i, factor), CPL_ERROR_NONE);
+
+    cpl_test_eq(irplib_polynomial_multiply_1d_factor(p1d, self, nreal),
+                CPL_ERROR_NONE);
+
+    cpl_test_eq(irplib_polynomial_solve_1d_all(p1d, roots, &jreal),
+                CPL_ERROR_NONE);
+
+    cpl_test_eq(jreal, nreal);
+    if (jreal != nreal) {
+        cpl_msg_info(cpl_func, "1D-polynomial:");
+        cpl_polynomial_dump(p1d, stderr);
+        cpl_msg_error(cpl_func, "True roots (%" CPL_SIZE_FORMAT
+                      " real): (line=%u)", nreal, line);
+        cpl_vector_dump(self, stderr);
+        cpl_msg_error(cpl_func, "Computed roots (%" CPL_SIZE_FORMAT " real): ",
+                      jreal);
+        cpl_vector_dump(roots, stderr);
+    } else if (cpl_msg_get_level() < CPL_MSG_WARNING) {
+        cpl_bivector * dump =
+            cpl_bivector_wrap_vectors((cpl_vector*)self, roots);
+
+        cpl_msg_warning(cpl_func, "Comparing %" CPL_SIZE_FORMAT " roots (%"
+                        CPL_SIZE_FORMAT " real): (line=%u)",
+                        degree, nreal, line);
+        cpl_bivector_dump(dump, stderr);
+        cpl_bivector_unwrap_vectors(dump);
+    }
+
+    for (i = 0; i < jreal; i++) {
+        const double root = cpl_vector_get(roots, i);
+        const double residual = cpl_polynomial_eval_1d(p1d, root, NULL);
+
+        cpl_test_abs(root, cpl_vector_get(self, i), tolerance);
+
+        cpl_test_abs(residual, 0.0, resitol);
+
+    }
+
+    for (i = nreal; i < degree; i++) {
+        const double root = cpl_vector_get(roots, i);
+
+        cpl_test_abs(root, cpl_vector_get(self, i), tolerance);
+
+        /* FIXME: Verify residual as well */
+
+    }
+
+    cpl_vector_delete(roots);
+    cpl_polynomial_delete(p1d);
+
+    return;
+}
diff --git a/irplib/tests/irplib_utils-test.c b/irplib/tests/irplib_utils-test.c
new file mode 100644
index 0000000..7d75f3f
--- /dev/null
+++ b/irplib/tests/irplib_utils-test.c
@@ -0,0 +1,331 @@
+/*                                                                            *
+ *   This file is part of the ESO IRPLIB package                              *
+ *   Copyright (C) 2004,2005 European Southern Observatory                    *
+ *                                                                            *
+ *   This library is free software; you can redistribute it and/or modify     *
+ *   it under the terms of the GNU General Public License as published by     *
+ *   the Free Software Foundation; either version 2 of the License, or        *
+ *   (at your option) any later version.                                      *
+ *                                                                            *
+ *   This program is distributed in the hope that it will be useful,          *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of           *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
+ *   GNU General Public License for more details.                             *
+ *                                                                            *
+ *   You should have received a copy of the GNU General Public License        *
+ *   along with this program; if not, write to the Free Software              *
+ *   Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA     *
+ *                                                                            */
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+/*-----------------------------------------------------------------------------
+                                Includes
+ -----------------------------------------------------------------------------*/
+
+#include <irplib_utils.h>
+#include <string.h>
+#include <float.h>
+
+/*-----------------------------------------------------------------------------
+                                   Function prototypes
+ -----------------------------------------------------------------------------*/
+
+static IRPLIB_UTIL_SET_ROW(my_table_set_row);
+static IRPLIB_UTIL_CHECK(my_table_check);
+
+static void test_irplib_image_split(void);
+static void test_irplib_dfs_table_convert(void);
+static void test_irplib_isnaninf(void);
+static void bench_irplib_image_split(int, int);
+static void frameset_sort_test(int sz);
+
+/*----------------------------------------------------------------------------*/
+/**
+ * @defgroup irplib_utils_test Testing of the IRPLIB utilities
+ */
+/*----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------*/
+/**
+   @brief   Unit tests of utils module
+**/
+/*----------------------------------------------------------------------------*/
+
+int main(void)
+{
+    /* Initialize CPL for unit testing */
+    cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
+
+    test_irplib_isnaninf();
+
+    test_irplib_dfs_table_convert();
+
+    test_irplib_image_split();
+
+    frameset_sort_test(122); /* test even */
+    frameset_sort_test(127); /* test odd  */
+
+    if (cpl_msg_get_level() <= CPL_MSG_INFO) {
+        bench_irplib_image_split(1024, 100);
+    } else {
+        bench_irplib_image_split(64, 1);
+    }
+
+    return cpl_test_end(0);
+}
+
+
+/*----------------------------------------------------------------------------*/
+/**
+   @internal
+   @brief   Test of irplib_isinf and irplib_isnan
+**/
+/*----------------------------------------------------------------------------*/
+static void test_irplib_isnaninf(void)
+{
+    double infinity = DBL_MAX * DBL_MAX;
+    double number[] = {17, 0};
+
+    /* The computation  oo/oo  must result in NaN according to
+       the IEEE 754 standard. However, some GCC 4.x versions erroneously
+       optimize this to 1.
+
+       Alternatively, a NaN could be produced using a IEEE 754 defined bit
+       pattern. But that is likely to depend on the machine's word size.
+       Therefore this test is disabled.
+
+       double not_a_number = infinity / infinity;
+    */
+
+    cpl_test_zero(irplib_isnan(infinity) );
+    /* cpl_test(  irplib_isnan(not_a_number) ); */
+    cpl_test_zero(irplib_isnan(number[0]) );
+    cpl_test_zero(irplib_isnan(number[1]) );
+
+    cpl_test(  irplib_isinf(infinity) );
+    /* cpl_test_zero(irplib_isinf(not_a_number) ); */
+    cpl_test_zero(irplib_isinf(number[0]) );
+    cpl_test_zero(irplib_isinf(number[1]) );
+
+    return;
+}
+
+
+static cpl_boolean my_table_set_row(cpl_table * self,
+                                    const char * line,
+                                    int irow,
+                                    const cpl_frame * rawframe,
+                                    const cpl_parameterlist * parlist)
+{
+
+    cpl_ensure_code(self     != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(line     != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(irow     >= 0,    CPL_ERROR_ILLEGAL_INPUT);
+    cpl_ensure_code(rawframe != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(parlist  != NULL, CPL_ERROR_NULL_INPUT);
+
+    return CPL_ERROR_NONE;
+
+}
+
+static cpl_error_code my_table_check(cpl_table * self,
+                                     const cpl_frameset * useframes,
+                                     const cpl_parameterlist * parlist)
+{
+
+    cpl_ensure_code(self      != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(useframes != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(parlist   != NULL, CPL_ERROR_NULL_INPUT);
+
+    return CPL_ERROR_NONE;
+
+}
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @internal
+  @brief  Test irplib_dfs_table_convert() and irplib_table_read_from_frameset()
+
+**/
+/*----------------------------------------------------------------------------*/
+static void test_irplib_dfs_table_convert(void)
+{
+
+    /* FIXME: Room for improvement... */
+    cpl_error_code error
+        = irplib_dfs_table_convert(NULL, NULL, NULL, 1024, '#',
+                                   NULL, NULL, NULL, NULL, NULL, NULL,
+                                   NULL, NULL, NULL, my_table_set_row,
+                                   my_table_check);
+
+    cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT);
+
+    error =
+        irplib_table_read_from_frameset(NULL, NULL, 1024, '#', NULL,
+                                        my_table_set_row);
+
+    cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT);
+}
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @internal
+  @brief  Test irplib_dfs_table_convert() and irplib_table_read_from_frameset()
+
+**/
+/*----------------------------------------------------------------------------*/
+static void bench_irplib_image_split(int nxy, int nsplit) {
+
+    const double th_low   =  0.0;
+    const double th_high  = 50.0;
+    const double alt_low  = th_low  - 1.0;
+    const double alt_high = th_high + 1.0;
+    cpl_image  * test     = cpl_image_new(nxy, nxy, CPL_TYPE_FLOAT);
+    double       tsum = 0.0;
+    int          i;
+
+    for (i = 0; i < nsplit; i++) {
+        double time1;
+        const double time0 = cpl_test_get_cputime();
+        const cpl_error_code error =
+            irplib_image_split(test, NULL, test, NULL,
+                               th_low,  CPL_TRUE, th_high, CPL_TRUE,
+                               alt_low, alt_high,
+                               CPL_TRUE, CPL_FALSE, CPL_TRUE);
+        time1 = cpl_test_get_cputime();
+
+        cpl_test_eq_error(error, CPL_ERROR_NONE);
+
+        if (time1 > time0) tsum += time1 - time0;
+    }
+
+    cpl_msg_info(cpl_func,"Time to split with image size %d [ms]: %g", nxy,
+                 1e3*tsum/nsplit);
+
+    cpl_image_delete(test);
+
+}
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @internal
+  @brief  Test irplib_dfs_table_convert() and irplib_table_read_from_frameset()
+
+**/
+/*----------------------------------------------------------------------------*/
+static void test_irplib_image_split(void) {
+
+    const double th_low   =  0.0;
+    const double th_high  = 50.0;
+    const double alt_low  = th_low  - 1.0;
+    const double alt_high = th_high + 1.0;
+
+    cpl_image * test   = cpl_image_new(100, 100, CPL_TYPE_DOUBLE);
+    cpl_image * result = cpl_image_new(100, 100, CPL_TYPE_DOUBLE);
+
+    /* Various error conditions */
+    cpl_error_code error
+        = irplib_image_split(NULL, test, result, test,
+                             0.0, CPL_FALSE, 0.0, CPL_FALSE,
+                             0.0, 0.0,
+                             CPL_FALSE, CPL_FALSE, CPL_FALSE);
+    cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT);
+
+
+    error = irplib_image_split(test, NULL, NULL, NULL,
+                               th_low,  CPL_TRUE, th_high, CPL_TRUE,
+                               alt_low, alt_high,
+                               CPL_TRUE, CPL_FALSE, CPL_TRUE);
+    cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT);
+
+    error = irplib_image_split(test, NULL, result, NULL,
+                               th_low,  CPL_TRUE, alt_low, CPL_TRUE,
+                               alt_low, alt_high,
+                               CPL_TRUE, CPL_FALSE, CPL_TRUE);
+
+    cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT);
+
+    /* Verify against cpl_image_threshold() */
+    error = cpl_image_fill_noise_uniform(test, -100.0, 100.0);
+    cpl_test_eq_error(error, CPL_ERROR_NONE);
+
+    error = irplib_image_split(test, NULL, result, NULL,
+                               th_low,  CPL_TRUE, th_high, CPL_TRUE,
+                               alt_low, alt_high,
+                               CPL_TRUE, CPL_FALSE, CPL_TRUE);
+    cpl_test_eq_error(error, CPL_ERROR_NONE);
+
+    error = cpl_image_threshold(test, th_low, th_high, alt_low, alt_high);
+    cpl_test_eq_error(error, CPL_ERROR_NONE);
+
+    error = cpl_image_subtract(result, test);
+    cpl_test_eq_error(error, CPL_ERROR_NONE);
+
+    cpl_test_leq(cpl_image_get_absflux(result), DBL_EPSILON);
+
+    cpl_image_delete(test);
+    cpl_image_delete(result);
+
+}
+
+static void frameset_sort_test(int sz)
+{
+    /* 1. create a test frameset - each frame should contain EXPTIME property */
+    cpl_frameset * pframeset = cpl_frameset_new();
+    int          * idx       = cpl_malloc(sz * sizeof(*idx));
+    double       * exptime   = cpl_malloc(sz * sizeof(*exptime));
+    cpl_error_code error;
+    int            i;
+
+    cpl_test_nonnull(pframeset);
+
+    for (i = 0; i < sz; i++) {
+        cpl_frame        * pframe   = cpl_frame_new();
+        cpl_propertylist * plist    = cpl_propertylist_new();
+        char             * filename = cpl_sprintf("dummyon%d.fits", i);
+        const double       value    = (i % 2) > 0 ? i : sz - i - 1;
+
+
+        cpl_test_nonnull(pframe);
+        /* assign exptime; */
+        error = cpl_frame_set_filename(pframe, filename);
+        cpl_test_eq_error(error, CPL_ERROR_NONE);
+        error = cpl_frame_set_tag(pframe, "ON");
+        cpl_test_eq_error(error, CPL_ERROR_NONE);
+        error = cpl_frame_set_type(pframe, CPL_FRAME_TYPE_IMAGE);
+        cpl_test_eq_error(error, CPL_ERROR_NONE);
+        error = cpl_frame_set_group(pframe, CPL_FRAME_GROUP_RAW);
+        cpl_test_eq_error(error, CPL_ERROR_NONE);
+
+        error = cpl_frameset_insert(pframeset, pframe);
+        cpl_test_eq_error(error, CPL_ERROR_NONE);
+        error = cpl_propertylist_append_double(plist, "EXPTIME", value);
+        cpl_test_eq_error(error, CPL_ERROR_NONE);
+        error = cpl_propertylist_save(plist, filename, CPL_IO_CREATE);
+        cpl_test_eq_error(error, CPL_ERROR_NONE);
+
+        cpl_propertylist_delete(plist);
+        cpl_free(filename);
+    }
+
+    error = irplib_frameset_sort(pframeset, idx, exptime);
+    cpl_test_eq_error(error, CPL_ERROR_NONE);
+
+    for (i = 0; i < sz; i++) {
+        int k = i + 1 - (sz % 2);
+        int j = sz -i - 1 ;
+        cpl_test_eq(idx[i], (((i + (sz % 2)) % 2)  == 0 ? k : j));
+    }
+
+    cpl_free(idx);
+    cpl_free(exptime);
+    cpl_frameset_delete(pframeset);
+    cpl_test_zero(system("rm *.fits"));
+}
diff --git a/irplib/tests/irplib_wcs-test.c b/irplib/tests/irplib_wcs-test.c
new file mode 100644
index 0000000..aaf2973
--- /dev/null
+++ b/irplib/tests/irplib_wcs-test.c
@@ -0,0 +1,307 @@
+/* $Id: irplib_wcs-test.c,v 1.8 2010/10/07 14:10:55 llundin Exp $
+ *
+ * This file is part of the ESO Common Pipeline Library
+ * Copyright (C) 2001-2008 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: llundin $
+ * $Date: 2010/10/07 14:10:55 $
+ * $Revision: 1.8 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+/*-----------------------------------------------------------------------------
+                                   Includes
+ -----------------------------------------------------------------------------*/
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <cpl_test.h>
+
+#include "irplib_wcs.h"
+
+/*-----------------------------------------------------------------------------
+                                   Static functions
+ -----------------------------------------------------------------------------*/
+static void irplib_wcs_all_test(void);
+
+static void irplib_wcs_mjd_test(void);
+
+
+/*-----------------------------------------------------------------------------
+                                  Main
+ -----------------------------------------------------------------------------*/
+int main (void)
+{
+
+    cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
+
+    irplib_wcs_all_test();
+
+    irplib_wcs_mjd_test();
+
+    return cpl_test_end(0);
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @internal
+  @brief    Test the WCS functions
+  @return   void
+ */
+/*----------------------------------------------------------------------------*/
+static void irplib_wcs_all_test(void)
+{
+    const double       xorig = 1.0;
+    const double       yorig = 2.0;
+    double             xnew,ynew;
+    double             ra, dec;
+    cpl_propertylist * prop_wcs; 
+    cpl_wcs *          wcs = NULL;
+    cpl_error_code     error;
+
+    
+    /* Create WCS object */
+    prop_wcs = cpl_propertylist_new();
+    cpl_test_nonnull(prop_wcs);
+
+    cpl_propertylist_append_double(prop_wcs, "CRVAL1", 10.);
+    cpl_propertylist_append_double(prop_wcs, "CRVAL2", 20.);
+    cpl_propertylist_append_int(prop_wcs, "CRPIX1", 1);
+    cpl_propertylist_append_int(prop_wcs, "CRPIX2", 2);
+    cpl_propertylist_append_double(prop_wcs, "CD1_1", 10.);
+    cpl_propertylist_append_double(prop_wcs, "CD1_2", 11.);
+    cpl_propertylist_append_double(prop_wcs, "CD2_1", 13.);
+    cpl_propertylist_append_double(prop_wcs, "CD2_2", 14.);
+
+    cpl_test_error(CPL_ERROR_NONE);
+
+    wcs = cpl_wcs_new_from_propertylist(prop_wcs);
+    cpl_propertylist_delete(prop_wcs);
+
+    if (cpl_error_get_code() == CPL_ERROR_NO_WCS) {
+
+        cpl_msg_warning(cpl_func, "No WCS present. Tests disabled");
+        cpl_test_error(CPL_ERROR_NO_WCS);
+        cpl_test_null(wcs);
+
+    } else {
+
+        cpl_test_nonnull(wcs);
+    
+        /* Test that a simple call to xytoradec does not fail*/
+        error = irplib_wcs_xytoradec(wcs, xorig, yorig, &ra, &dec);
+        cpl_test_eq_error(error, CPL_ERROR_NONE);
+    
+        /* Get the transformation back and compare */
+        error = irplib_wcs_radectoxy(wcs, ra, dec, &xnew, &ynew);
+        cpl_test_eq_error(error, CPL_ERROR_NONE);
+
+        cpl_test_abs(xnew, xorig, 2.0 * DBL_EPSILON);
+        cpl_test_abs(ynew, yorig, 2.0 * DBL_EPSILON);
+
+        /* Error testing */
+
+        error = irplib_wcs_xytoradec(wcs, xorig, yorig, NULL, &dec);
+        cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT);
+    
+        error = irplib_wcs_radectoxy(wcs, ra, dec, NULL, &ynew);
+        cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT);
+
+        error = irplib_wcs_xytoradec(wcs, xorig, yorig, &ra, NULL);
+        cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT);
+    
+        error = irplib_wcs_radectoxy(wcs, ra, dec, &xnew, NULL);
+        cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT);
+
+        cpl_wcs_delete(wcs);
+    
+    }    
+
+    /* Error testing */
+
+    error = irplib_wcs_xytoradec(NULL, xorig, yorig, &ra, &dec);
+    cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT);
+    
+    error = irplib_wcs_radectoxy(NULL, ra, dec, &xnew, &ynew);
+    cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT);
+
+
+}
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @internal
+  @brief    Test the MJD functions
+  @return   void
+ */
+/*----------------------------------------------------------------------------*/
+static void irplib_wcs_mjd_test(void)
+{
+
+    /* Matching example from some VLT header */
+    const char * iso8601  = "2010-07-13T23:24:39.284";
+    const double mjd  = 55390.97545467;
+
+    /* Two equal dates */
+    const char * iso8601a = "2010-07-13T24:00:00";
+    const char * iso8601b = "2010-07-14T00:00:00.000";
+
+    const double mstol = 1e-3/86400.0; /* 1ms tolerance in MJD */
+    int year, day, month, hour, minute;
+    double second;
+    double tmjd, tmjd2;
+    cpl_error_code error;
+
+    /* The MJD counts the number of days since November 17, 1858 */
+    /* Test 1a: Conversion of MJD == 0 */
+    error = irplib_wcs_iso8601_from_mjd(&year, &month, &day, &hour,
+                                        &minute, &second, 0.0);
+    cpl_test_eq_error(error, CPL_ERROR_NONE);
+
+    cpl_test_eq(year,  1858);
+    cpl_test_eq(month,   11);
+    cpl_test_eq(day,     17);
+    cpl_test_eq(hour,     0);
+    cpl_test_eq(minute,   0);
+    cpl_test_abs(second, 0.0, 2.0 * DBL_EPSILON);
+
+    /* Test 1b: - and convert back */
+    error = irplib_wcs_mjd_from_iso8601(&tmjd, year, month, day, hour, minute,
+                                        second);
+    cpl_test_eq_error(error, CPL_ERROR_NONE);
+
+    cpl_test_abs(tmjd, 0.0, 2.0 * DBL_EPSILON);
+
+    /* Test 2: Conversion back and forth of some recent date */
+    error = irplib_wcs_iso8601_from_string(&year, &month, &day, &hour,
+                                           &minute, &second, iso8601);
+    cpl_test_eq_error(error, CPL_ERROR_NONE);
+
+    error = irplib_wcs_mjd_from_iso8601(&tmjd, year, month, day, hour, minute,
+                                        second);
+    cpl_test_eq_error(error, CPL_ERROR_NONE);
+
+    cpl_test_abs(mjd, tmjd, mstol);
+
+    error = irplib_wcs_mjd_from_string(&tmjd, iso8601);
+    cpl_test_eq_error(error, CPL_ERROR_NONE);
+
+    cpl_test_abs(mjd, tmjd, mstol);
+
+    error = irplib_wcs_iso8601_from_mjd(&year, &month, &day, &hour,
+                                        &minute, &second, mjd);
+    cpl_test_eq_error(error, CPL_ERROR_NONE);
+
+    error = irplib_wcs_mjd_from_iso8601(&tmjd, year, month, day, hour, minute,
+                                        second);
+    cpl_test_eq_error(error, CPL_ERROR_NONE);
+
+    cpl_test_abs(mjd, tmjd, 2.0 * DBL_EPSILON);
+
+    /* Test 3: 24:00:00 == 00.00.00 + 1 day */
+    error = irplib_wcs_iso8601_from_string(&year, &month, &day, &hour,
+                                           &minute, &second, iso8601a);
+    cpl_test_eq_error(error, CPL_ERROR_NONE);
+
+    error = irplib_wcs_mjd_from_iso8601(&tmjd, year, month, day, hour, minute,
+                                        second);
+    cpl_test_eq_error(error, CPL_ERROR_NONE);
+
+    error = irplib_wcs_iso8601_from_string(&year, &month, &day, &hour,
+                                           &minute, &second, iso8601b);
+    cpl_test_eq_error(error, CPL_ERROR_NONE);
+
+    error = irplib_wcs_mjd_from_iso8601(&tmjd2, year, month, day, hour, minute,
+                                        second);
+    cpl_test_eq_error(error, CPL_ERROR_NONE);
+
+    cpl_test_abs(tmjd, tmjd2, 2.0 * DBL_EPSILON);
+
+    /* Test 4: Do not allow days from y10k */
+    error = irplib_wcs_iso8601_from_string(&year, &month, &day, &hour,
+                                           &minute, &second,
+                                           "10000-07-13T23:24:39.284");
+    cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT);
+
+    /* Test 5: Verify validation of length of a non-leap year month */
+    error = irplib_wcs_iso8601_from_string(&year, &month, &day, &hour,
+                                           &minute, &second,
+                                           "2010-02-29T23:24:39.284");
+    cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT);
+
+    /* Test 6: NULL pointer checking */
+    error = irplib_wcs_mjd_from_iso8601(NULL, year, month, day, hour, minute,
+                                        second);
+    cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT);
+
+    error = irplib_wcs_iso8601_from_string(NULL, &month, &day, &hour,
+                                           &minute, &second, iso8601);
+    cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT);
+
+    error = irplib_wcs_iso8601_from_string(&year, NULL, &day, &hour,
+                                           &minute, &second, iso8601);
+    cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT);
+
+    error = irplib_wcs_iso8601_from_string(&year, &month, NULL, &hour,
+                                           &minute, &second, iso8601);
+    cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT);
+
+    error = irplib_wcs_iso8601_from_string(&year, &month, &day, NULL,
+                                           &minute, &second, iso8601);
+    cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT);
+
+    error = irplib_wcs_iso8601_from_string(&year, &month, &day, &hour,
+                                           NULL, &second, iso8601);
+    cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT);
+
+    error = irplib_wcs_iso8601_from_string(&year, &month, &day, &hour,
+                                           &minute, NULL, iso8601);
+    cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT);
+
+    error = irplib_wcs_iso8601_from_string(&year, &month, &day, &hour,
+                                           &minute, &second, NULL);
+    cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT);
+
+    error = irplib_wcs_iso8601_from_mjd(NULL, &month, &day, &hour,
+                                        &minute, &second, mjd);
+    cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT);
+
+    error = irplib_wcs_iso8601_from_mjd(&year, NULL, &day, &hour,
+                                        &minute, &second, mjd);
+    cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT);
+
+    error = irplib_wcs_iso8601_from_mjd(&year, &month, NULL, &hour,
+                                        &minute, &second, mjd);
+    cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT);
+
+    error = irplib_wcs_iso8601_from_mjd(&year, &month, &day, NULL,
+                                        &minute, &second, mjd);
+    cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT);
+
+    error = irplib_wcs_iso8601_from_mjd(&year, &month, &day, &hour,
+                                        NULL, &second, mjd);
+    cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT);
+
+    error = irplib_wcs_iso8601_from_mjd(&year, &month, &day, &hour,
+                                        &minute, NULL, mjd);
+    cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT);
+
+}
diff --git a/irplib/tests/irplib_wlxcorr-test.c b/irplib/tests/irplib_wlxcorr-test.c
new file mode 100644
index 0000000..b9651d8
--- /dev/null
+++ b/irplib/tests/irplib_wlxcorr-test.c
@@ -0,0 +1,483 @@
+/* $Id: irplib_wlxcorr-test.c,v 1.15 2012/01/12 12:38:38 llundin Exp $
+ *
+ * This file is part of the ESO Common Pipeline Library
+ * Copyright (C) 2001-2004 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: llundin $
+ * $Date: 2012/01/12 12:38:38 $
+ * $Revision: 1.15 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+/*-----------------------------------------------------------------------------
+                                   Includes
+ -----------------------------------------------------------------------------*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <irplib_wlxcorr.h>
+
+#include <irplib_wavecal_impl.h>
+
+#include <cpl_plot.h>
+
+#include <math.h>
+#include <float.h>
+
+/* TEMPORARY SUPPORT OF CPL 5.x */
+#ifndef CPL_SIZE_FORMAT
+#define CPL_SIZE_FORMAT "d"
+#define cpl_size int
+#endif
+/* END TEMPORARY SUPPORT OF CPL 5.x */
+
+
+
+/*----------------------------------------------------------------------------*/
+/**
+ * @defgroup irplib_wlcalib_test Testing of the CPL Wavelength calibration
+ */
+/*----------------------------------------------------------------------------*/
+
+
+/*-----------------------------------------------------------------------------
+                            Private Function prototypes
+ -----------------------------------------------------------------------------*/
+
+static void irplib_wlxcorr_best_poly_test(void);
+static void irplib_wlxcorr_best_poly_test_one(int, int, cpl_boolean, int, int);
+static void irplib_wlxcorr_convolve_create_kernel_test(void);
+static void irplib_wlxcorr_convolve_create_kernel_test_one(double, double);
+static double irplib_wlcalib_lss(double, double, double);
+static void irplib_wavecal_profile_compare(int, double, double);
+
+
+/*----------------------------------------------------------------------------*/
+/**
+   @brief   Unit tests of wlcalib module
+**/
+/*----------------------------------------------------------------------------*/
+
+/*-----------------------------------------------------------------------------
+                                  Main
+ -----------------------------------------------------------------------------*/
+int main(void)
+{
+    /* Initialize CPL + IRPLIB */
+    cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
+
+    irplib_wavecal_profile_compare(100, 4.0, 4.0);
+    irplib_wlxcorr_convolve_create_kernel_test();
+    irplib_wlxcorr_best_poly_test();
+
+    return cpl_test_end(0);
+}
+
+
+static void irplib_wlxcorr_best_poly_test(void)
+{
+    cpl_polynomial  *   poly;
+    const cpl_boolean   do_bench = cpl_msg_get_level() <= CPL_MSG_INFO
+        ? CPL_TRUE : CPL_FALSE;
+    const int           spec_size = do_bench ? 1024 : 256;
+    const int           nreps     = do_bench ? 3 : 1;
+    const int           nsamples  = do_bench ? 30 : 10;
+
+
+    /* 1st test: NULL input */
+    poly = irplib_wlxcorr_best_poly(NULL, NULL, 1, NULL, NULL, 1, 1.0, 1.0,
+                                    NULL, NULL, NULL);
+    cpl_test_error(CPL_ERROR_NULL_INPUT);
+    cpl_test_null( poly );
+
+#if 1
+    /* 2nd test: Resampling of catalog lines */
+    irplib_wlxcorr_best_poly_test_one(spec_size, spec_size*10, CPL_TRUE,
+                                      nsamples, nreps);
+#endif
+
+    /* 3rd test: No resampling of catalog lines */
+    irplib_wlxcorr_best_poly_test_one(spec_size, spec_size/50,  CPL_FALSE,
+                                      nsamples, nreps);
+}
+
+static void irplib_wlxcorr_best_poly_test_one(int spec_size, int cat_size,
+                                              cpl_boolean do_resample,
+                                              int nsamples, int nreps)
+{
+    const int           degree     = 2;
+    cpl_vector      *   spectrum   = cpl_vector_new(spec_size);
+    cpl_bivector    *   catalog    = cpl_bivector_new(cat_size);
+    cpl_polynomial  *   true_poly  = cpl_polynomial_new(1);
+    cpl_polynomial  *   guess_poly = cpl_polynomial_new(1);
+    cpl_vector      *   wl_err     = cpl_vector_new(degree+1);
+    double              xc;
+    const double        slitw = 2.0;
+    const double        fwhm = 2.0;
+    const double        xtrunc = 0.5 * slitw + 5.0 * fwhm * CPL_MATH_SIG_FWHM;
+    const double        rel_error = 0.05; /* Introduce error */
+
+    /* A black-body with T=253K should emit mostly in the range [2;50[ micron */
+    const double        temp_bb = 253.0;
+
+    const double        b_true = 2e-6;
+    const double        a_true = 48e-6 / spec_size;
+
+    const double        a_error = a_true * rel_error;
+    const double        b_error = b_true * rel_error;
+    const double        a = a_true + a_error;
+    const double        b = b_true + b_error;
+    double              wl_errmax;
+    cpl_size            pow_ind;
+    int                 i;
+    FILE              * stream = cpl_msg_get_level() > CPL_MSG_INFO
+        ? fopen("/dev/null", "a") : stdout;
+
+
+    cpl_test_nonnull( stream );
+
+    /* First guess P(x) = ax + b */
+    /* The true and distorted polynomials */
+    pow_ind = 1;
+    cpl_polynomial_set_coeff(true_poly,  &pow_ind, a_true);
+    cpl_polynomial_set_coeff(guess_poly, &pow_ind, a);
+    pow_ind = 0;
+    cpl_polynomial_set_coeff(true_poly,  &pow_ind, b_true);
+    cpl_polynomial_set_coeff(guess_poly, &pow_ind, b);
+
+    cpl_msg_info(cpl_func, "First guess polynomial:");
+    cpl_polynomial_dump(guess_poly, stream);
+
+    /* Try also to shift the guess of the solution */
+    cpl_test_zero(cpl_polynomial_shift_1d(guess_poly, 0, 25.0));
+
+    cpl_msg_info(cpl_func, "True polynomial:");
+    cpl_polynomial_dump(true_poly, stream);
+
+
+    if (do_resample) {
+        cpl_vector * evalpoints = cpl_vector_new(spec_size);
+
+        /* Wavelengths of the spectrum */
+        cpl_vector_fill_polynomial(evalpoints, true_poly, 1.0, 1.0);
+
+        /* Catalog */
+        /* The sampled profile is a black body radiation */
+        cpl_vector_fill_polynomial(cpl_bivector_get_x(catalog), true_poly,
+                                   -1.0, 1.5 * spec_size / cat_size);
+
+        cpl_photom_fill_blackbody(cpl_bivector_get_y(catalog), CPL_UNIT_LESS,
+                                  cpl_bivector_get_x_const(catalog),
+                                  CPL_UNIT_LENGTH, temp_bb);
+
+        cpl_photom_fill_blackbody(spectrum, CPL_UNIT_LESS,
+                                  evalpoints, CPL_UNIT_LENGTH, temp_bb);
+
+        cpl_vector_delete(evalpoints);
+
+    } else {
+        /* Place some lines with different intensities */
+        double * dx = cpl_bivector_get_x_data(catalog);
+        double * dy = cpl_bivector_get_y_data(catalog);
+
+        for (i = 0; i < cat_size; i++) {
+            const double wli = cpl_polynomial_eval_1d(true_poly, 3.0 * i * i
+                                                      -10.0, NULL);
+
+            dx[i] = wli;
+            dy[i] = sin(i * CPL_MATH_PI / cat_size);
+
+        }
+
+        irplib_vector_fill_line_spectrum_model(spectrum, NULL, NULL, true_poly,
+                                               catalog, slitw, fwhm, xtrunc,
+                                               0, CPL_FALSE, CPL_FALSE, NULL);
+        cpl_test_error(CPL_ERROR_NONE);
+    }
+
+    /* FIXME: Add some random noise to the spectrum */
+    
+    if (cpl_msg_get_level() <= CPL_MSG_DEBUG) {
+        cpl_plot_bivector( "", "t 'Catalog' w lines", "", catalog);
+        cpl_plot_vector( "", "t 'Spectrum' w lines", "", spectrum);
+    }
+
+
+    /* Error */
+    /* Compute an error bound certain to include to true solution */
+    wl_errmax = cpl_polynomial_eval_1d(guess_poly, spec_size, NULL)
+        - cpl_polynomial_eval_1d(true_poly, spec_size, NULL);
+    cpl_vector_fill(wl_err, 2.0 * wl_errmax);
+
+    /* Multiple calls for bench-marking */
+
+    for (i=0; i < nreps; i++) {
+        cpl_table      * wl_res;
+        cpl_vector     * xcorrs;
+        cpl_polynomial * poly
+            = irplib_wlxcorr_best_poly(spectrum, catalog, degree,
+                                       guess_poly, wl_err, nsamples,
+                                       slitw, fwhm, &xc, &wl_res, &xcorrs);
+        cpl_test_nonnull(poly);
+        cpl_test_error(CPL_ERROR_NONE);
+
+        if (i == 0 && poly != NULL) {
+            if (cpl_msg_get_level() <= CPL_MSG_DEBUG) {
+                const char * labels[] = {IRPLIB_WLXCORR_COL_WAVELENGTH,
+                                         IRPLIB_WLXCORR_COL_CAT_INIT,
+                                         IRPLIB_WLXCORR_COL_CAT_FINAL,
+                                         IRPLIB_WLXCORR_COL_OBS};
+
+                cpl_plot_vector( "", "t 'X corr values' w lines", "", xcorrs);
+
+                cpl_test_zero(cpl_plot_columns("", "", "", wl_res, labels, 4));
+            }
+
+            cpl_msg_info(cpl_func, "Corrected polynomial:");
+            cpl_polynomial_dump(poly, stream);
+
+            /* Corrected polynomial must be monotone, with same sign
+               as a_true. */ 
+            cpl_test_zero(cpl_polynomial_derivative(poly, 0));
+            cpl_test_leq(0.0, a_true * cpl_polynomial_eval_1d(poly, 1.0, NULL));
+            cpl_test_leq(0.0, a_true
+                         * cpl_polynomial_eval_1d(poly, 0.5 * spec_size, NULL));
+            cpl_test_leq(0.0, a_true
+                         * cpl_polynomial_eval_1d(poly, spec_size, NULL));
+
+            cpl_test_error(CPL_ERROR_NONE);
+
+        }
+
+        cpl_table_delete(wl_res);
+        cpl_vector_delete(xcorrs);
+        cpl_polynomial_delete(poly);
+    }
+
+    cpl_vector_delete(wl_err);
+    cpl_vector_delete(spectrum);
+    cpl_bivector_delete(catalog);
+    cpl_polynomial_delete(true_poly);
+    cpl_polynomial_delete(guess_poly);
+    cpl_test_error(CPL_ERROR_NONE);
+
+    if (stream != stdout) cpl_test_zero( fclose(stream) );
+
+    return;
+}
+
+
+static void irplib_wlxcorr_convolve_create_kernel_test_one(double slitw,
+                                                           double fwhm)
+{
+
+    cpl_vector * kernel;
+    double       sum = 0.0;
+    /* Maximum value of profile */
+    const double maxval = irplib_wlcalib_lss(0.0, slitw, fwhm);
+    double       prev = maxval;
+    int          n, i;
+
+    cpl_msg_info(cpl_func, "Slit-width=%g, FWHM=%g", slitw, fwhm);
+
+    kernel = irplib_wlxcorr_convolve_create_kernel(0.0, fwhm);
+
+    cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
+    cpl_test_null(kernel);
+
+    kernel = irplib_wlxcorr_convolve_create_kernel(slitw, 0.0);
+
+    cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
+    cpl_test_null(kernel);
+
+    kernel = irplib_wlxcorr_convolve_create_kernel(slitw, fwhm);
+
+    cpl_test_nonnull(kernel);
+
+    n = cpl_vector_get_size(kernel);
+
+    for (i = 0; i < n; i++) {
+        const double val = cpl_vector_get(kernel, i);
+        sum += i ? 2.0*val : val; /* Non-central elements twice */
+
+        /* Profile consists of non-negative values */
+        cpl_test_leq(0.0, val);
+
+        /* The max of the profile is less than maxval and decreases */
+        cpl_test_leq(val, prev);
+
+        if (i > 0) {
+            /* The profile at i is less than the continuous profile at
+               i - 0.5, and greater than that at i + 0.5 */
+            cpl_test_leq(val, irplib_wlcalib_lss(i - 0.5, slitw, fwhm));
+            cpl_test_leq(irplib_wlcalib_lss(i + 0.5, slitw, fwhm), val);
+        }
+
+        /* The profile has a FWHM (sligthly) greater than slitw */
+        if ((double)i < 0.5 * slitw) {
+            /* Thus if x is less than half the slit width, then
+               the value has to be greater than half the maximum */
+            cpl_test_leq(0.5 * maxval, val);
+        } else if (val < 0.5 * maxval) {
+            /* On the other hand, if the value is less than the maximum,
+               then x must exceed half the slitw */
+            cpl_test_leq(0.5*slitw, (double)i);
+        }
+
+        prev = val;
+    }
+
+    /* Integral is supposed to be 1 */
+    cpl_test_abs(sum, 1.0, 1e-5); /* FIXME: Improve tolerance */
+
+    if (cpl_msg_get_level() <= CPL_MSG_DEBUG) {
+        char * title = cpl_sprintf("t 'LSS profile, slitw=%g, fwhm=%g' "
+                                   "w linespoints", slitw, fwhm);
+        cpl_plot_vector("set grid;", title, "", kernel);
+        cpl_free(title);
+    }
+
+    cpl_vector_delete(kernel);
+}
+
+static void irplib_wlxcorr_convolve_create_kernel_test(void)
+{
+
+    irplib_wlxcorr_convolve_create_kernel_test_one(0.86, 2.0);
+    irplib_wlxcorr_convolve_create_kernel_test_one(1.72, 3.0);
+    irplib_wlxcorr_convolve_create_kernel_test_one(40.0, 2.0);
+    irplib_wlxcorr_convolve_create_kernel_test_one(3.0, 40.0);
+
+}
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @internal
+  @brief    The intensity of the line profile at distance x
+  @param    x      x
+  @param    slitw  The slit width
+  @param    fwhm   The FWHM of the (Gaussian) transfer function
+  @return   The intensity of the line profile at distance x
+
+ */
+/*----------------------------------------------------------------------------*/
+static double irplib_wlcalib_lss(double x, double slitw, double fwhm)
+{
+  const double sigmasqrt2 = fwhm * CPL_MATH_SIG_FWHM * CPL_MATH_SQRT2;
+  const double result = 0.5 / slitw *
+      (erf((x+0.5*slitw)/sigmasqrt2) - erf((x-0.5*slitw)/sigmasqrt2));
+
+  cpl_test_lt(0.0, slitw);
+  cpl_test_lt(0.0, sigmasqrt2);
+
+  /* Protect against round-off (on SunOS 5.8) */
+  return result < 0.0 ? 0.0 : result;
+
+}
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @internal
+  @brief    Compare the standard and fast profiles
+  @param  spec_size Number of points in the spectrum
+  @param  slitw     The slit width
+  @param  fwhm      The FWHM of the (Gaussian) transfer function
+
+ */
+/*----------------------------------------------------------------------------*/
+static void irplib_wavecal_profile_compare(int spec_size, double slitw,
+                                           double fwhm)
+{
+
+    cpl_vector     * spectrum1  = cpl_vector_new(spec_size);
+    cpl_vector     * spectrum2  = cpl_vector_new(spec_size);
+    cpl_bivector   * catalog    = cpl_bivector_new(2);
+    cpl_polynomial * dispersion = cpl_polynomial_new(1);
+    const double     a = 1.0;
+    const double     b = 100.0;
+    const double     xtrunc = 0.5 * slitw + 2.0 * fwhm * CPL_MATH_SIG_FWHM;
+    double           mean;
+    cpl_error_code   error;
+    cpl_size         pow_ind;
+
+
+    pow_ind = 1;
+    cpl_polynomial_set_coeff(dispersion, &pow_ind, a);
+    pow_ind = 0;
+    cpl_polynomial_set_coeff(dispersion, &pow_ind, b);
+
+    cpl_vector_set(cpl_bivector_get_x(catalog), 0, b + spec_size / 3.0);
+    cpl_vector_set(cpl_bivector_get_y(catalog), 0, 100);
+
+    cpl_vector_set(cpl_bivector_get_x(catalog), 1, b + spec_size / 1.5);
+    cpl_vector_set(cpl_bivector_get_y(catalog), 1, 100);
+
+    cpl_test_error(CPL_ERROR_NONE);
+
+    error = irplib_vector_fill_line_spectrum_model(spectrum1, NULL, NULL,
+                                                   dispersion, catalog, slitw,
+                                                   fwhm, xtrunc, 0, CPL_FALSE,
+                                                   CPL_FALSE, NULL);
+    cpl_test_error(CPL_ERROR_NONE);
+    cpl_test_eq(error, CPL_ERROR_NONE);
+
+
+    error = irplib_vector_fill_line_spectrum_model(spectrum2, NULL, NULL,
+                                                   dispersion, catalog, slitw,
+                                                   fwhm, xtrunc, 0, CPL_TRUE,
+                                                   CPL_FALSE, NULL);
+    
+    cpl_test_error(CPL_ERROR_NONE);
+    cpl_test_eq(error, CPL_ERROR_NONE);
+
+    if (cpl_msg_get_level() <= CPL_MSG_DEBUG) {
+        error = cpl_plot_vector("set grid;", "t 'Spectrum' w lines", "",
+                                spectrum1);
+        cpl_test_error(CPL_ERROR_NONE);
+        cpl_test_eq(error, CPL_ERROR_NONE);
+        error = cpl_plot_vector("set grid;", "t 'Spectrum' w lines", "",
+                                spectrum2);
+        cpl_test_error(CPL_ERROR_NONE);
+        cpl_test_eq(error, CPL_ERROR_NONE);
+    }
+
+    cpl_vector_subtract(spectrum1, spectrum2);
+    mean = cpl_vector_get_mean(spectrum1);
+    if (mean != 0.0) {
+        cpl_msg_info(cpl_func, "Error: %g", mean);
+        if (cpl_msg_get_level() <= CPL_MSG_DEBUG) {
+            error = cpl_plot_vector("set grid;", "t 'Spectrum error' w lines",
+                                    "", spectrum1);
+            cpl_test_error(CPL_ERROR_NONE);
+            cpl_test_eq(error, CPL_ERROR_NONE);
+        }
+    }
+
+    cpl_polynomial_delete(dispersion);
+    cpl_vector_delete(spectrum1);
+    cpl_vector_delete(spectrum2);
+    cpl_bivector_delete(catalog);
+
+    cpl_test_error(CPL_ERROR_NONE);
+
+}
diff --git a/m4macros/cpl.m4 b/m4macros/cpl.m4
new file mode 100644
index 0000000..e1a27c1
--- /dev/null
+++ b/m4macros/cpl.m4
@@ -0,0 +1,1499 @@
+# CPL_CHECK_CFITSIO(version)
+#---------------------------
+# Checks for the cfitsio library and header files.
+AC_DEFUN([CPL_CHECK_CFITSIO],
+[
+
+    AC_REQUIRE([ESO_CHECK_THREADS_POSIX])
+        
+    cpl_cfitsio_check_version="$1"
+    cpl_cfitsio_check_header="fitsio.h"
+    cpl_cfitsio_check_lib="libcfitsio.a"
+
+    cpl_cfitsio_incdirs=""
+    cpl_cfitsio_libdirs=""
+    cpl_cfitsio_includes=""
+    cpl_cfitsio_libraries=""
+
+    AC_ARG_WITH(cfitsio,
+                AC_HELP_STRING([--with-cfitsio],
+                               [location where cfitsio is installed]),
+                [
+                    cpl_with_cfitsio=$withval
+                ])
+
+    AC_ARG_WITH(cfitsio-includes,
+                AC_HELP_STRING([--with-cfitsio-includes],
+                               [location of the cfitsio header files]),
+                cpl_with_cfitsio_includes=$withval)
+
+    AC_ARG_WITH(cfitsio-libs,
+                AC_HELP_STRING([--with-cfitsio-libs],
+                               [location of the cfitsio library]),
+                cpl_with_cfitsio_libs=$withval)
+
+    AC_ARG_ENABLE(cfitsio-test,
+                  AC_HELP_STRING([--disable-cfitsio-test],
+                                 [disables checks for the cfitsio library and headers]),
+                  cpl_enable_cfitsio_test=$enableval,
+                  cpl_enable_cfitsio_test=yes)
+
+
+    # We need libpthread for the folloing tests
+
+    if test -z "$LIBPTHREAD"; then
+        AC_MSG_ERROR([POSIX thread library was not found on your system! Please check!])
+    fi
+
+    
+    AC_MSG_CHECKING([for cfitsio])
+
+    if test "x$cpl_enable_cfitsio_test" = xyes; then
+
+        # Check for the cfitsio includes
+
+        if test -z "$cpl_with_cfitsio_includes"; then
+        
+            if test -z "$cpl_with_cfitsio"; then
+            
+                # Try some known system locations
+                
+                cpl_cfitsio_incdirs="/opt/cfitsio/include"
+                cpl_cfitsio_incdirs="$cpl_cfitsio_incdirs /usr/local/include/libcfitsio0"
+                cpl_cfitsio_incdirs="$cpl_cfitsio_incdirs /usr/local/include/cfitsio"
+                cpl_cfitsio_incdirs="$cpl_cfitsio_incdirs /usr/local/include"
+                cpl_cfitsio_incdirs="$cpl_cfitsio_incdirs /usr/include/libcfitsio0"
+                cpl_cfitsio_incdirs="$cpl_cfitsio_incdirs /usr/include/cfitsio"
+                cpl_cfitsio_incdirs="$cpl_cfitsio_incdirs /usr/include"
+
+                test -n "$CFITSIODIR" && \ 
+                    cpl_cfitsio_incdirs="$CFITSIODIR/include/libcfitsio0 \
+                                         $CFITSIODIR/include/cfitsio \
+                                         $CFITSIODIR/include \
+                                         $cpl_cfitsio_incdirs"
+
+                test -n "$CPLDIR" && \
+                    cpl_cfitsio_incdirs="$CPLDIR/include/libcfitsio0 \
+                                         $CPLDIR/include/cfitsio \
+                                         $CPLDIR/include \
+                                         $cpl_cfitsio_incdirs"
+
+            else
+
+                cpl_cfitsio_incdirs="$cpl_with_cfitsio/include/libcfitsio0"
+                cpl_cfitsio_incdirs="$cpl_cfitsio_incdirs $cpl_with_cfitsio/include/cfitsio"
+                cpl_cfitsio_incdirs="$cpl_cfitsio_incdirs $cpl_with_cfitsio/include"
+
+            fi
+            
+        else
+            cpl_cfitsio_incdirs="$cpl_with_cfitsio_includes"
+        fi
+
+        ESO_FIND_FILE($cpl_cfitsio_check_header, $cpl_cfitsio_incdirs,
+                      cpl_cfitsio_includes)
+
+
+        # Check for the cfitsio library
+
+        if test -z "$cpl_with_cfitsio_libs"; then
+
+            if test -z "$cpl_with_cfitsio"; then
+            
+                # Try some known system locations
+
+                cpl_cfitsio_libdirs="/opt/cfitsio/lib"
+                cpl_cfitsio_libdirs="$cpl_cfitsio_libdirs /usr/local/lib64"
+                cpl_cfitsio_libdirs="$cpl_cfitsio_libdirs /usr/local/lib"
+                cpl_cfitsio_libdirs="$cpl_cfitsio_libdirs /usr/local/lib32"
+                cpl_cfitsio_libdirs="$cpl_cfitsio_libdirs /usr/lib64"
+                cpl_cfitsio_libdirs="$cpl_cfitsio_libdirs /usr/lib"
+                cpl_cfitsio_libdirs="$cpl_cfitsio_libdirs /usr/lib32"
+
+                test -n "$CFITSIODIR" && \
+                    cpl_cfitsio_libdirs="$CFITSIODIR/lib64 $CFITSIODIR/lib \
+                                         $CFITSIODIR/lib32 $cpl_cfitsio_libdirs"
+
+                test -n "$CPLDIR" && \
+                    cpl_cfitsio_libdirs="$CPLDIR/lib64 $CPLDIR/lib $CPLDIR/lib32 \
+                                         $cpl_cfitsio_libdirs"
+
+            else
+
+                cpl_cfitsio_libdirs="$cpl_with_cfitsio/lib64"
+                cpl_cfitsio_libdirs="$cpl_cfitsio_libdirs $cpl_with_cfitsio/lib"
+                cpl_cfitsio_libdirs="$cpl_cfitsio_libdirs $cpl_with_cfitsio/lib32"
+
+            fi
+            
+        else
+            cpl_cfitsio_libdirs="$cpl_with_cfitsio_libs"
+        fi
+
+        ESO_FIND_FILE($cpl_cfitsio_check_lib, $cpl_cfitsio_libdirs,
+                      cpl_cfitsio_libraries)
+
+
+        if test x"$cpl_cfitsio_includes" = xno || \
+            test x"$cpl_cfitsio_libraries" = xno; then
+            cpl_cfitsio_notfound=""
+
+            if test x"$cpl_cfitsio_includes" = xno; then
+                if test x"$cpl_cfitsio_libraries" = xno; then
+                    cpl_cfitsio_notfound="(headers and libraries)"
+                else
+                    cpl_cfitsio_notfound="(headers)"
+                fi
+            else
+                cpl_cfitsio_notfound="(libraries)"
+            fi
+
+            AC_MSG_ERROR([cfitsio $cpl_cfitsio_notfound was not found on your system. Please check!])
+        else
+            AC_MSG_RESULT([libraries $cpl_cfitsio_libraries, headers $cpl_cfitsio_includes])
+        fi
+
+        # Set up the symbols
+
+        # Add '-lz' to the static library symbol, as distributors apparently
+        # remove the libz code from the cfitsio sources.
+        
+        CFITSIO_INCLUDES="-I$cpl_cfitsio_includes"
+        CFITSIO_LDFLAGS="-L$cpl_cfitsio_libraries"
+        LIBCFITSIO="-lcfitsio"
+        LIBCFITSIO_STATIC="$cpl_cfitsio_libraries/$cpl_cfitsio_check_lib"
+        
+        # Do not add redundant libraries        
+        echo $LIBS | grep -q -e '-lm' || LIBS="-lm $LIBS" 
+        
+
+        # Check whether cfitsio can be used
+
+        AC_MSG_CHECKING([whether cfitsio can be used])
+        AC_LANG_PUSH(C)
+        
+        cpl_cfitsio_cflags_save="$CFLAGS"
+        cpl_cfitsio_ldflags_save="$LDFLAGS"
+        cpl_cfitsio_libs_save="$LIBS"
+
+        CFLAGS="$CFITSIO_INCLUDES $CFLAGS"
+        LDFLAGS="$CFITSIO_LDFLAGS $LDFLAGS"
+        LIBS="$LIBCFITSIO_STATIC $LIBPTHREAD -lm"
+        
+        AC_LINK_IFELSE([AC_LANG_PROGRAM(
+                       [[
+                       #include <fitsio.h>
+                       ]],
+                       [
+                       float v;
+                       fits_get_version(&v);
+                       ])],
+                       [cpl_cfitsio_is_usable="yes"],
+                       [cpl_cfitsio_is_usable="no"])
+
+        AC_MSG_RESULT([$cpl_cfitsio_is_usable])
+        
+        AC_LANG_POP(C)
+        
+        CFLAGS="$cpl_cfitsio_cflags_save"
+        LDFLAGS="$cpl_cfitsio_ldflags_save"
+        LIBS="$cpl_cfitsio_libs_save"
+
+        if test x"$cpl_cfitsio_is_usable" = xno; then
+            AC_MSG_ERROR([Linking with cfitsio failed! Please check architecture!])
+        fi
+ 
+        
+        # Check cfitsio version
+
+        AC_MSG_CHECKING([for a cfitsio version >= $cpl_cfitsio_check_version])
+        
+        AC_LANG_PUSH(C)
+        
+        cpl_cfitsio_cflags_save="$CFLAGS"
+        cpl_cfitsio_ldflags_save="$LDFLAGS"
+        cpl_cfitsio_libs_save="$LIBS"
+
+        CFLAGS="$CFITSIO_INCLUDES $CFLAGS"
+        LDFLAGS="$CFITSIO_LDFLAGS $LDFLAGS"
+        LIBS="$LIBCFITSIO_STATIC $LIBPTHREAD -lm"
+        
+        AC_RUN_IFELSE([AC_LANG_PROGRAM(
+                      [[
+                      #include <stdio.h>
+                      #include <fitsio.h>
+                      ]],
+                      [
+                      int vlib = 0;
+                      int vmin = (int)(1000. * $cpl_cfitsio_check_version + 0.5);
+                       
+                      float v;
+
+                      fits_get_version(&v);
+                      vlib = (int)(v * 1000 + 0.5);
+                                            
+                      FILE* f = fopen("conftest.out", "w");
+                      fprintf(f, "%5.3f\n", v);
+                      fclose(f);
+                      
+                      if (vlib < vmin) {
+                          return 1;
+                      }
+
+                      return 0;
+                      ])],
+                      [cpl_cfitsio_version="`cat conftest.out`"],
+                      [
+                       cpl_cfitsio_version="no";
+                       cpl_cfitsio_version_found="`cat conftest.out`"
+                      ])
+
+        AC_MSG_RESULT([$cpl_cfitsio_version])
+        
+        AC_LANG_POP(C)
+        
+        CFLAGS="$cpl_cfitsio_cflags_save"
+        LDFLAGS="$cpl_cfitsio_ldflags_save"
+        LIBS="$cpl_cfitsio_libs_save"
+
+        if test x"$cpl_cfitsio_version" = xno; then
+            AC_MSG_ERROR([Installed cfitsio ($cpl_cfitsio_version_found) is too old. Please update to version $cpl_cfitsio_check_version or newer.])
+        fi
+ 
+        
+        # Check whether cfitsio has large file support
+        
+        AC_LANG_PUSH(C)
+        
+        cpl_cfitsio_cflags_save="$CFLAGS"
+        cpl_cfitsio_ldflags_save="$LDFLAGS"
+        cpl_cfitsio_libs_save="$LIBS"
+
+        CFLAGS="$CFITSIO_INCLUDES $CFLAGS"
+        LDFLAGS="$CFITSIO_LDFLAGS $LDFLAGS"
+        LIBS="$LIBCFITSIO_STATIC -lm $LIBPTHREAD"
+        
+        AC_MSG_CHECKING([whether cfitsio provides fits_hdu_getoff()])
+
+        AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
+                          [[
+                          #include <fitsio.h>
+                          ]],
+                          [
+                          fitsfile f;
+                          int sts;
+                          fits_get_hduoff(&f, NULL, NULL, NULL, &sts);
+                          ])],
+                          [cpl_cfitsio_have_fits_get_hduoff="yes"],
+                          [cpl_cfitsio_have_fits_get_hduoff="no"])
+
+        AC_MSG_RESULT([$cpl_cfitsio_have_fits_get_hduoff])
+        
+        AC_MSG_CHECKING([whether cfitsio provides fits_get_hduaddrll()])
+
+        AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
+                          [[
+                          #include <fitsio.h>
+                          ]],
+                          [
+                          fitsfile f;
+                          int sts;
+                          fits_get_hduaddrll(&f, NULL, NULL, NULL, &sts);
+                          ])],
+                          [cpl_cfitsio_have_fits_get_hduaddrll="yes"],
+                          [cpl_cfitsio_have_fits_get_hduaddrll="no"])
+
+        AC_MSG_RESULT([$cpl_cfitsio_have_fits_get_hduaddrll])
+
+        AC_LANG_POP(C)
+        
+        CFLAGS="$cpl_cfitsio_cflags_save"
+        LDFLAGS="$cpl_cfitsio_ldflags_save"
+        LIBS="$cpl_cfitsio_libs_save"
+
+
+        # Check whether cfitsio is thread-safe
+        
+        AC_MSG_CHECKING([whether cfitsio requires libpthread])
+        AC_LANG_PUSH(C)
+        
+        cpl_cfitsio_cflags_save="$CFLAGS"
+        cpl_cfitsio_ldflags_save="$LDFLAGS"
+        cpl_cfitsio_libs_save="$LIBS"
+
+        CFLAGS="$CFITSIO_INCLUDES $CFLAGS"
+        LDFLAGS="$CFITSIO_LDFLAGS $LDFLAGS"
+        LIBS="$LIBCFITSIO_STATIC -lm"
+        
+        
+        cpl_cfitsio_provides_pthread="no"
+        
+        AC_LINK_IFELSE([AC_LANG_PROGRAM(
+                       [[
+                       #include <fitsio.h>
+                       ]],
+                       [
+                       float v;
+                       fits_get_version(&v);
+                       ])],
+                       [cpl_cfitsio_requires_pthread="no"],
+                       [cpl_cfitsio_requires_pthread="undefined"])
+
+		if test x"$cpl_cfitsio_requires_pthread" = xno; then
+		
+	    	# If libpthread is not required this means either cfitsio is
+    		# not compiled with thread support, or the library dependencies
+    		# are compiled into cfitsio.
+
+			# Check whether shared library dependencies are present
+			# Don't use pthread_mutex_init/destroy here, since glibc
+			# provides these symbols too! Sigh!
+		
+	        AC_LINK_IFELSE([AC_LANG_PROGRAM(
+		                   [[
+	    	               #include <pthread.h>
+    	    	           #include <fitsio.h>
+        	    	       ]],
+            	    	   [                	       
+	                	   float v;
+    	            	   pthread_mutexattr_t attrb;
+    	            	   pthread_mutexattr_init(&attrb);
+            	           fits_get_version(&v);
+                		   pthread_mutexattr_destroy(&attrb);
+	                	   ])],
+	    	               [cpl_cfitsio_provides_pthread="yes"],
+    	    	           [cpl_cfitsio_provides_pthread="no"])
+            	           
+        else
+        
+            LIBS="$LIBCFITSIO_STATIC -lm $LIBPTHREAD"
+        
+            AC_LINK_IFELSE([AC_LANG_PROGRAM(
+                           [[
+                           #include <fitsio.h>
+                           ]],
+                           [
+                           float v;
+                           fits_get_version(&v);
+                           ])],
+                           [cpl_cfitsio_requires_pthread="yes"],
+                           AC_MSG_FAILURE([Cannot link with cfitsio! Please check!]))
+          
+        fi
+                       
+        AC_MSG_RESULT([$cpl_cfitsio_requires_pthread])
+        
+        AC_LANG_POP(C)
+        
+        CFLAGS="$cpl_cfitsio_cflags_save"
+        LDFLAGS="$cpl_cfitsio_ldflags_save"
+        LIBS="$cpl_cfitsio_libs_save"
+
+
+		AC_MSG_CHECKING([whether cfitsio was compiled with thread support])
+		
+		if test x"$cpl_cfitsio_requires_pthread" = xyes || \
+			test x"$cpl_cfitsio_provides_pthread" = xyes; then
+			cpl_cfitsio_is_thread_safe=yes
+		else
+			cpl_cfitsio_is_thread_safe=no
+		fi
+		
+		AC_MSG_RESULT([$cpl_cfitsio_is_thread_safe])
+		
+		
+        # Set compiler flags and libraries
+        
+        if test x"$cpl_cfitsio_have_fits_get_hduoff" = xyes || \
+          test x"$cpl_cfitsio_have_fits_get_hduaddrll" = xyes; then
+
+            CFLAGS="-D_LARGEFILE_SOURCE=1 -D_FILE_OFFSET_BITS=64 $CFLAGS"
+            
+            if test x"$cpl_cfitsio_have_fits_get_hduoff"; then
+                AC_DEFINE([HAVE_FITS_GET_HDUOFF], [1],
+                          [Define if you have the `fits_get_hduoff' function])
+            else
+                AC_DEFINE([HAVE_FITS_GET_HDUADDRLL],  [1],
+                          [Define if you have the `fits_get_hduaddrll' function])
+            fi
+                    
+        fi
+                
+        if test x"$cpl_cfitsio_requires_pthread" = xyes; then
+            echo $LIBS | grep -q -e "$LIBPTHREAD" || LIBS="$LIBPTHREAD $LIBS"
+        fi
+        
+    else
+        AC_MSG_RESULT([disabled])
+        AC_MSG_WARN([cfitsio checks have been disabled! This package may not build!])
+        CFITSIO_INCLUDES=""
+        CFITSIO_LDFLAGS=""
+        LIBCFITSIO=""
+        
+        cpl_cfitsio_is_thread_safe="undefined"
+        cpl_cfitsio_requires_pthread="undefined"
+    fi
+
+	AC_CACHE_VAL(cpl_cv_cfitsio_requires_pthread,
+	             cpl_cv_cfitsio_requires_pthread=$cpl_cfitsio_requires_pthread)
+	AC_CACHE_VAL(cpl_cv_cfitsio_is_thread_safe,
+	             cpl_cv_cfitsio_is_thread_safe=$cpl_cfitsio_is_thread_safe)
+	             
+    AC_SUBST(CFITSIO_INCLUDES)
+    AC_SUBST(CFITSIO_LDFLAGS)
+    AC_SUBST(LIBCFITSIO)
+
+])
+
+
+# CPL_CHECK_CEXT(incdirs=[], libdirs=[])
+#---------------------------------------
+# Checks for the C extension library and header files.
+AC_DEFUN([CPL_CHECK_CEXT],
+[
+
+    AC_MSG_CHECKING([for libcext])
+
+    cpl_cext_check_header="cxtypes.h"
+    cpl_cext_check_lib="libcext.a"
+
+    cpl_cext_incdirs=""
+    cpl_cext_libdirs=""
+
+    cpl_cext_includes=""
+    cpl_cext_libraries=""
+
+
+	# Initialize directory search paths with the arguments provided
+	
+	if test -n "$1"; then
+		cpl_cext_incdirs="$1"
+	fi
+
+	if test -n "$2"; then
+		cpl_cext_libdirs="$2"
+	fi
+
+
+    AC_ARG_WITH(cext,
+                AC_HELP_STRING([--with-cext],
+                               [location where libcext is installed]),
+                [
+                    cpl_with_cext=$withval
+                ])
+
+    AC_ARG_WITH(cext-includes,
+                AC_HELP_STRING([--with-cext-includes],
+                               [location of the libcext header files]),
+                cpl_with_cext_includes=$withval)
+
+    AC_ARG_WITH(cext-libs,
+                AC_HELP_STRING([--with-cext-libs],
+                               [location of the libcext library]),
+                cpl_with_cext_libs=$withval)
+
+    AC_ARG_ENABLE(cext-test,
+                  AC_HELP_STRING([--disable-cext-test],
+                                 [disables checks for the libcext library and headers]),
+                  cpl_enable_cext_test=$enableval,
+                  cpl_enable_cext_test=yes)
+
+
+    if test "x$cpl_enable_cext_test" = xyes; then
+    
+        # Check for the libcext includes
+
+        if test -z "$cpl_with_cext_includes"; then
+        
+            if test -z "$cpl_with_cext"; then
+            
+            	if test -z "$cpl_cext_incdirs"; then
+            
+	                # Try some known system locations
+                
+    	            cpl_cext_incdirs="/opt/cext/include"
+        	        cpl_cext_incdirs="$cpl_cext_incdirs /usr/local/include/cext"
+            	    cpl_cext_incdirs="$cpl_cext_incdirs /usr/local/include"
+                	cpl_cext_incdirs="$cpl_cext_incdirs /usr/include/cext"
+                	cpl_cext_incdirs="$cpl_cext_incdirs /usr/include"
+
+                	test -n "$CPLDIR" && \
+                    	cpl_cext_incdirs="$CPLDIR/include/cext \
+                        	              $CPLDIR/include \
+                            	          $cpl_cext_incdirs"
+
+				fi
+				
+            else
+
+                cpl_cext_incdirs="$cpl_with_cext/include/cext"
+                cpl_cext_incdirs="$cpl_cext_incdirs $cpl_with_cext/include"
+
+            fi
+            
+        else
+            cpl_cext_incdirs="$cpl_with_cext_includes"
+        fi
+
+        ESO_FIND_FILE($cpl_cext_check_header, $cpl_cext_incdirs,
+                      cpl_cext_includes)
+
+
+        # Check for the libcext library
+
+        if test -z "$cpl_with_cext_libs"; then
+
+            if test -z "$cpl_with_cext"; then
+            
+            	if test -z "$cpl_cext_libdirs"; then
+
+	                # Try some known system locations
+
+    	            cpl_cext_libdirs="/opt/cext/lib"
+                	cpl_cext_libdirs="$cpl_cext_libdirs /usr/local/lib64"
+                	cpl_cext_libdirs="$cpl_cext_libdirs /usr/local/lib"
+                	cpl_cext_libdirs="$cpl_cext_libdirs /usr/local/lib32"
+                	cpl_cext_libdirs="$cpl_cext_libdirs /usr/lib64"
+                	cpl_cext_libdirs="$cpl_cext_libdirs /usr/lib"
+                	cpl_cext_libdirs="$cpl_cext_libdirs /usr/lib32"
+
+                	test -n "$CPLDIR" && \
+                    	cpl_cext_libdirs="$CPLDIR/lib64 \
+                    					  $CPLDIR/lib \
+                    					  $CPLDIR/lib32 \
+                                          $cpl_cext_libdirs"
+                                          
+				fi
+				
+            else
+
+                cpl_cext_libdirs="$cpl_with_cext/lib64"
+                cpl_cext_libdirs="$cpl_cext_libdirs $cpl_with_cext/lib"
+                cpl_cext_libdirs="$cpl_cext_libdirs $cpl_with_cext/lib32"
+
+            fi
+            
+        else
+            cpl_cext_libdirs="$cpl_with_cext_libs"
+        fi
+
+        ESO_FIND_FILE($cpl_cext_check_lib, $cpl_cext_libdirs,
+                      cpl_cext_libraries)
+
+
+        if test x"$cpl_cext_includes" = xno || \
+            test x"$cpl_cext_libraries" = xno; then
+            cpl_cext_notfound=""
+
+            if test x"$cpl_cext_includes" = xno; then
+                if test x"$cpl_cext_libraries" = xno; then
+                    cpl_cext_notfound="(headers and libraries)"
+                else
+                    cpl_cext_notfound="(headers)"
+                fi
+            else
+                cpl_cext_notfound="(libraries)"
+            fi
+
+            AC_MSG_ERROR([libcext $cpl_cext_notfound was not found on your system. Please check!])
+        else
+            AC_MSG_RESULT([libraries $cpl_cext_libraries, headers $cpl_cext_includes])
+        fi
+
+
+        # Set up the symbols
+
+        CX_INCLUDES="-I$cpl_cext_includes"
+        CX_LDFLAGS="-L$cpl_cext_libraries"
+        LIBCEXT="-lcext"
+        
+        
+        AC_MSG_CHECKING([whether libcext can be used])
+        AC_LANG_PUSH(C)
+        
+        cpl_cext_cflags_save="$CFLAGS"
+        cpl_cext_ldflags_save="$LDFLAGS"
+        cpl_cext_libs_save="$LIBS"
+
+        CFLAGS="$CX_INCLUDES $CFLAGS"
+        LDFLAGS="$CX_LDFLAGS $LDFLAGS"
+        LIBS="$LIBCEXT"
+        
+        AC_LINK_IFELSE([AC_LANG_PROGRAM(
+                       [[
+                       #include <cxutils.h>
+                       ]],
+                       [
+                       cx_program_set_name("MyProgram");
+                       ])],
+                       [cpl_cext_is_usable="yes"],
+                       [cpl_cext_is_usable="no"])
+
+        AC_MSG_RESULT([$cpl_cext_is_usable])
+        
+        AC_LANG_POP(C)
+        
+        CFLAGS="$cpl_cext_cflags_save"
+        LDFLAGS="$cpl_cext_ldflags_save"
+        LIBS="$cpl_cext_libs_save"
+
+        if test x"$cpl_cext_is_usable" = xno; then
+            AC_MSG_ERROR([Linking with libcext failed! Please check architecture!])
+        fi
+        
+    else
+    
+        AC_MSG_RESULT([disabled])
+        AC_MSG_WARN([libcext checks have been disabled! This package may not build!])
+        CX_INCLUDES=""
+        CX_LDFLAGS=""
+        LIBCEXT=""
+        
+    fi
+
+    AC_SUBST(CX_INCLUDES)
+    AC_SUBST(CX_LDFLAGS)
+    AC_SUBST(LIBCEXT)
+
+])
+
+
+# CPL_CHECK_WCS(version)
+#-----------------------
+# Checks for the wcs library and header files.
+AC_DEFUN([CPL_CHECK_WCS],
+[
+    AC_MSG_CHECKING([for libwcs])
+
+
+    cpl_wcs_check_version="$1"
+    cpl_wcs_check_header="wcslib/wcslib.h"
+    cpl_wcs_check_lib="libwcs.a"
+
+    cpl_wcs_includes=""
+    cpl_wcs_libraries=""
+
+
+    AC_ARG_WITH(wcs,
+                AC_HELP_STRING([--with-wcs],
+                               [location where wcs is installed]),
+                [
+                    cpl_with_wcs=$withval
+                ])
+
+    AC_ARG_WITH(wcs-includes,
+                AC_HELP_STRING([--with-wcs-includes],
+                               [location of the libwcs header files]),
+                cpl_with_wcs_includes=$withval)
+
+    AC_ARG_WITH(wcs-libs,
+                AC_HELP_STRING([--with-wcs-libs],
+                               [location of the libwcs library]),
+                cpl_with_wcs_libs=$withval)
+
+
+    # Check for the wcs includes
+
+	if test -z "$cpl_with_wcs_includes"; then    
+    	
+    	if test -z "$cpl_with_wcs"; then
+    
+    		# Try some known system locations
+    	
+    		cpl_wcs_incdirs="/opt/wcslib/include/wcslib"
+    		cpl_wcs_incdirs="$cpl_wcs_incdirs /usr/local/include/wcslib"
+    		cpl_wcs_incdirs="$cpl_wcs_incdirs /usr/local/include"
+    		cpl_wcs_incdirs="$cpl_wcs_incdirs /usr/include/wcslib"
+    		cpl_wcs_incdirs="$cpl_wcs_incdirs /usr/include"
+    	
+        	test -n "$WCSDIR" && \
+        		cpl_wcs_incdirs="$WCSDIR/include \
+        					     $cpl_wcs_incdirs"
+        	
+    	else
+    	
+        	cpl_wcs_incdirs="$cpl_with_wcs/include"
+        	
+    	fi
+    
+    else
+    
+    	cpl_wcs_incdirs="$cpl_with_wcs_includes"
+    	
+    fi
+    
+    ESO_FIND_FILE($cpl_wcs_check_header, $cpl_wcs_incdirs, cpl_wcs_includes)
+
+
+    # Check for the wcs library
+    
+    if test -z "$cpl_with_wcs_libs"; then
+    
+    	if test -z "$cpl_with_wcs"; then
+    	
+    		# Try some known system locations
+    		
+    		cpl_wcs_libdirs="/opt/wcslib/lib64"
+    		cpl_wcs_libdirs="$cpl_wcs_libdirs /opt/wcslib/lib"
+    		cpl_wcs_libdirs="$cpl_wcs_libdirs /opt/wcslib/lib32"
+    		cpl_wcs_libdirs="$cpl_wcs_libdirs /usr/local/lib64"
+    		cpl_wcs_libdirs="$cpl_wcs_libdirs /usr/local/lib"
+    		cpl_wcs_libdirs="$cpl_wcs_libdirs /usr/local/lib32"
+    		cpl_wcs_libdirs="$cpl_wcs_libdirs /usr/lib64"
+    		cpl_wcs_libdirs="$cpl_wcs_libdirs /usr/lib"
+    		cpl_wcs_libdirs="$cpl_wcs_libdirs /usr/lib32"
+    		
+	        test -n "$WCSDIR" && \
+    	    	cpl_wcs_libdirs="$WCSDIR/lib64 \
+    	    	                 $WCSDIR/lib \
+    	    	                 $WCSDIR/lib32 \
+    	    	                 $cpl_wcs_libdirs"
+
+        else
+
+        	cpl_wcs_libdirs="$cpl_with_wcs/lib64"
+        	cpl_wcs_libdirs="$cpl_wcs_libdirs $cpl_with_wcs/lib"
+        	cpl_wcs_libdirs="$cpl_wcs_libdirs $cpl_with_wcs/lib32"
+
+        fi
+        	
+    else
+
+        cpl_wcs_libdirs="$cpl_with_wcs_libs"
+
+    fi
+    
+    ESO_FIND_FILE($cpl_wcs_check_lib, $cpl_wcs_libdirs, cpl_wcs_libraries)
+
+
+    if test x"$cpl_wcs_includes" = xno || \
+    	test x"$cpl_wcs_libraries" = xno; then
+    	cpl_wcs_notfound=""
+    	
+        if test x"$cpl_wcs_includes" = xno; then
+            if test x"$cpl_wcs_libraries" = xno; then
+                cpl_wcs_notfound="(headers and libraries)"
+            else
+                cpl_wcs_notfound="(headers)"
+            fi
+        else
+            cpl_wcs_notfound="(libraries)"
+        fi
+
+        AC_MSG_WARN([libwcs $cpl_wcs_notfound was not found on your system. WCS support will be disabled!])
+        
+    else
+    
+        AC_MSG_RESULT([libraries $cpl_wcs_libraries, headers $cpl_wcs_includes])
+        
+        
+        # Setup the symbols
+
+        WCS_INCLUDES="-I$cpl_wcs_includes/wcslib"
+        WCS_LDFLAGS="-L$cpl_wcs_libraries"
+        LIBWCS="-lwcs -lm"
+        LIBWCS_STATIC="$cpl_wcs_libraries/$cpl_wcs_check_lib -lm"
+
+        
+        # Check wcs library version
+
+        AC_MSG_CHECKING([for a libwcs version >= $cpl_wcs_check_version])
+        
+        AC_LANG_PUSH(C)
+        
+        cpl_wcs_cflags_save="$CFLAGS"
+        cpl_wcs_ldflags_save="$LDFLAGS"
+        cpl_wcs_libs_save="$LIBS"
+
+        CFLAGS="$WCS_INCLUDES $CFLAGS"
+        LDFLAGS="$WCS_LDFLAGS $LDFLAGS"
+        LIBS="$LIBWCS_STATIC"
+        
+        AC_RUN_IFELSE([AC_LANG_PROGRAM(
+                      [[
+                      #include <stdio.h>
+                      #include <wcslib.h>
+                      
+                      #define stringify(v) stringify_arg(v)
+                      #define stringify_arg(v) #v
+                      ]],
+                      [
+                      char vmin[[]] = "$cpl_wcs_check_version";
+                      char vlib[[]] = stringify(WCSLIB_VERSION);
+
+                      int min_major = 0;
+                      int min_minor = 0;
+                      int min_micro = 0;
+
+                      int lib_major = 0;
+                      int lib_minor = 0;
+                      int lib_micro = 0;
+
+                      sscanf(vmin, "%d.%d.%d", &min_major, &min_minor, &min_micro);
+                      sscanf(vlib, "%d.%d.%d", &lib_major, &lib_minor, &lib_micro);
+                     
+                      FILE* f = fopen("conftest.out", "w");
+                      fprintf(f, "%s\n", vlib);
+                      fclose(f);
+                                          
+                      if (lib_major < min_major) {
+                          return 1;
+                      }
+                      else {
+                          if (lib_major == min_major) {
+                              if (lib_minor <  min_minor) {
+                                  return 1;
+                              }
+                              else {
+                                  if (lib_minor == min_minor) {
+                                      if (lib_micro < min_micro) {
+                                          return 1;
+                                      }
+                                  }
+                              }
+                          }
+                      }
+
+                      return 0;                      
+                      ])],
+                      [cpl_wcs_version="`cat conftest.out`"],
+                      [
+                       cpl_wcs_version="no";
+                       cpl_wcs_version_found="`cat conftest.out`"
+                      ])
+
+        AC_MSG_RESULT([$cpl_wcs_version])
+        
+        AC_LANG_POP(C)
+        
+        CFLAGS="$cpl_wcs_cflags_save"
+        LDFLAGS="$cpl_wcs_ldflags_save"
+        LIBS="$cpl_wcs_libs_save"
+
+
+        if test x"$cpl_wcs_version" = xno; then
+        
+            AC_MSG_WARN([Installed libwcs ($cpl_wcs_version_found) is too old. WCS support will not be available!])
+            
+            WCS_INCLUDES=""
+            WCS_LDFLAGS=""
+            LIBWCS=""
+            
+        else	         
+    	    AC_DEFINE_UNQUOTED(CPL_WCS_INSTALLED, 1, [Defined if WCS is available])
+ 		fi
+ 
+        AC_SUBST(WCS_INCLUDES)
+        AC_SUBST(WCS_LDFLAGS)
+        AC_SUBST(LIBWCS)
+ 
+    fi
+
+])
+
+
+# CPL_CHECK_FFTW(version)
+#------------------------
+# Checks for the wcs library and header files.
+AC_DEFUN([CPL_CHECK_FFTW],
+[
+
+	cpl_fftw_check_version="$1"
+    cpl_fftw_check_header="fftw3.h"
+    cpl_fftw_check_lib="libfftw3.a"
+    cpl_fftwf_check_lib="libfftw3f.a"
+
+    cpl_fftw_includes=""
+    cpl_fftw_libraries=""
+    cpl_fftwf_libraries=""
+
+    AC_ARG_WITH(fftw,
+                AC_HELP_STRING([--with-fftw],
+                               [location where fftw is installed]),
+                [
+                    cpl_with_fftw=$withval
+                ])
+
+    AC_ARG_WITH(fftw-includes,
+                AC_HELP_STRING([--with-fftw-includes],
+                               [location of the fftw header files]),
+                cpl_with_fftw_includes=$withval)
+
+    AC_ARG_WITH(fftw-libs,
+                AC_HELP_STRING([--with-fftw-libs],
+                               [location of the fftw libraries]),
+                cpl_with_fftw_libs=$withval)
+
+
+    AC_MSG_CHECKING([for fftw (normal-precision)])
+
+
+    # Check for the fftw includes
+
+	if test -z "$cpl_with_fftw_includes"; then    
+    	
+    	if test -z "$cpl_with_fftw"; then
+    
+    		# Try some known system locations
+    	
+    		cpl_fftw_incdirs="/opt/fftw/include"
+    		cpl_fftw_incdirs="$cpl_fftw_incdirs /usr/local/include"
+    		cpl_fftw_incdirs="$cpl_fftw_incdirs /usr/include"
+    	
+        	test -n "$FFTWDIR" && \
+        		cpl_fftw_incdirs="$FFTWDIR/include \
+        					     $cpl_fftw_incdirs"
+        	
+    	else
+    	
+        	cpl_fftw_incdirs="$cpl_with_fftw/include"
+        	
+    	fi
+    
+    else
+    
+    	cpl_fftw_incdirs="$cpl_with_fftw_includes"
+    	
+    fi
+    
+    ESO_FIND_FILE($cpl_fftw_check_header, $cpl_fftw_incdirs, cpl_fftw_includes)
+
+
+    # Check for normal-precision fftw library
+    
+    if test -z "$cpl_with_fftw_libs"; then
+    
+    	if test -z "$cpl_with_fftw"; then
+    	
+    		# Try some known system locations
+    		
+    		cpl_fftw_libdirs="/opt/fftw/lib64"
+    		cpl_fftw_libdirs="$cpl_fftw_libdirs /opt/fftw/lib"
+    		cpl_fftw_libdirs="$cpl_fftw_libdirs /opt/fftw/lib32"
+    		cpl_fftw_libdirs="$cpl_fftw_libdirs /usr/local/lib64"
+    		cpl_fftw_libdirs="$cpl_fftw_libdirs /usr/local/lib"
+    		cpl_fftw_libdirs="$cpl_fftw_libdirs /usr/local/lib32"
+    		cpl_fftw_libdirs="$cpl_fftw_libdirs /usr/lib64"
+    		cpl_fftw_libdirs="$cpl_fftw_libdirs /usr/lib"
+    		cpl_fftw_libdirs="$cpl_fftw_libdirs /usr/lib32"
+    		
+	        test -n "$FFTWDIR" && \
+    	    	cpl_fftw_libdirs="$FFTWDIR/lib64 \
+    	    	                  $FFTWDIR/lib \
+    	    	                  $FFTWDIR/lib32 \
+    	    	                  $cpl_fftw_libdirs"
+
+        else
+
+        	cpl_fftw_libdirs="$cpl_with_fftw/lib64"
+        	cpl_fftw_libdirs="$cpl_fftw_libdirs $cpl_with_fftw/lib"
+        	cpl_fftw_libdirs="$cpl_fftw_libdirs $cpl_with_fftw/lib32"
+
+        fi
+        	
+    else
+
+        cpl_fftw_libdirs="$cpl_with_fftw_libs"
+
+    fi
+    
+    ESO_FIND_FILE($cpl_fftw_check_lib, $cpl_fftw_libdirs, cpl_fftw_libraries)
+
+    if test x"$cpl_fftw_includes" = xno || \
+    	test x"$cpl_fftw_libraries" = xno; then
+    	cpl_fftw_notfound=""
+    	
+        if test x"$cpl_fftw_includes" = xno; then
+            if test x"$cpl_fftw_libraries" = xno; then
+                cpl_fftw_notfound="(headers and libraries)"
+            else
+                cpl_fftw_notfound="(headers)"
+            fi
+        else
+            cpl_fftw_notfound="(libraries)"
+        fi
+
+		AC_MSG_RESULT([no])
+        AC_MSG_WARN([fftw (normal-precision) $cpl_fftw_notfound was not found on your system.])
+        
+    else
+    
+        AC_MSG_RESULT([libraries $cpl_fftw_libraries, headers $cpl_fftw_includes])
+
+	
+		# Set up the symbols
+	
+        FFTW_INCLUDES="-I$cpl_fftw_includes"
+        FFTW_LDFLAGS="-L$cpl_fftw_libraries"
+        LIBFFTW="-lfftw3 -lm"
+        LIBFFTW_STATIC="$cpl_fftw_libraries/$cpl_fftw_check_lib -lm"
+
+
+        # Check fftw (normal-precision) library version
+
+        AC_MSG_CHECKING([for a fftw (normal-precision) version >= $cpl_fftw_check_version])
+        
+        AC_LANG_PUSH(C)
+        
+        cpl_fftw_cflags_save="$CFLAGS"
+        cpl_fftw_ldflags_save="$LDFLAGS"
+        cpl_fftw_libs_save="$LIBS"
+
+        CFLAGS="$FFTW_INCLUDES $CFLAGS"
+        LDFLAGS="$FFTW_LDFLAGS $LDFLAGS"
+        LIBS="$LIBFFTW_STATIC"
+        
+        AC_RUN_IFELSE([AC_LANG_PROGRAM(
+                      [[
+                      #include <stdio.h>
+                      #include <stdlib.h>
+                      #include <string.h>
+                      #include <fftw3.h>
+                      ]],
+                      [
+                      char vmin[[]] = "$cpl_fftw_check_version";
+                      char *vstr    = strdup(fftw_version);
+                      char *vlib    = vstr;
+                      char *suffix  = NULL;
+
+                      int min_major = 0;
+                      int min_minor = 0;
+                      int min_micro = 0;
+
+                      int lib_major = 0;
+                      int lib_minor = 0;
+                      int lib_micro = 0;
+
+                      vlib = strchr(vstr, '-') + 1;
+                      suffix = strrchr(vlib, '-');
+					  
+					  if (suffix) {
+                          *suffix = '\0';
+					  }
+					  
+                      sscanf(vmin, "%d.%d.%d", &min_major, &min_minor, &min_micro);
+                      sscanf(vlib, "%d.%d.%d", &lib_major, &lib_minor, &lib_micro);
+                     
+                      FILE* f = fopen("conftest.out", "w");
+                      fprintf(f, "%s\n", vlib);
+                      fclose(f);
+                      
+                      free(vstr);
+                                          
+                      if (lib_major < min_major) {
+                          return 1;
+                      }
+                      else {
+                          if (lib_major == min_major) {
+                              if (lib_minor <  min_minor) {
+                                  return 1;
+                              }
+                              else {
+                                  if (lib_minor == min_minor) {
+                                      if (lib_micro < min_micro) {
+                                          return 1;
+                                      }
+                                  }
+                              }
+                          }
+                      }
+
+                      return 0;                      
+                      ])],
+                      [cpl_fftw_version="`cat conftest.out`"],
+                      [
+                       cpl_fftw_version="no";
+                       cpl_fftw_version_found="`cat conftest.out`"
+                      ])
+
+        AC_MSG_RESULT([$cpl_fftw_version])
+        
+        AC_LANG_POP(C)
+        
+        CFLAGS="$cpl_fftw_cflags_save"
+        LDFLAGS="$cpl_fftw_ldflags_save"
+        LIBS="$cpl_fftw_libs_save"
+
+        if test x"$cpl_fftw_version" = xno; then
+        
+            AC_MSG_WARN([Installed normal-precision fftw ($cpl_fftw_version_found) is too old])
+            
+            FFTW_INCLUDES=""
+            FFTW_LDFLAGS=""
+            LIBFFTW=""
+            
+        else	         
+	        AC_DEFINE_UNQUOTED(CPL_FFTW_INSTALLED, 1, [Defined if FFTW (normal-precision) is available])
+ 		fi
+ 
+        AC_SUBST(FFTW_INCLUDES)
+        AC_SUBST(FFTW_LDFLAGS)
+        AC_SUBST(LIBFFTW)
+			
+	fi
+	
+	
+	# Check for single-precision fftw
+	
+    AC_MSG_CHECKING([for fftw (single-precision)])
+
+    ESO_FIND_FILE($cpl_fftwf_check_lib, $cpl_fftw_libdirs, cpl_fftwf_libraries)
+
+    if test x"$cpl_fftw_includes" = xno || \
+    	test x"$cpl_fftwf_libraries" = xno; then
+    	cpl_fftw_notfound=""
+    	
+        if test x"$cpl_fftw_includes" = xno; then
+            if test x"$cpl_fftwf_libraries" = xno; then
+                cpl_fftw_notfound="(headers and libraries)"
+            else
+                cpl_fftw_notfound="(headers)"
+            fi
+        else
+            cpl_fftw_notfound="(libraries)"
+        fi
+
+		AC_MSG_RESULT([no])
+        AC_MSG_WARN([fftw (single-precision) $cpl_fftw_notfound was not found on your system.])
+        
+    else
+    
+        AC_MSG_RESULT([libraries $cpl_fftwf_libraries, headers $cpl_fftw_includes])
+
+	
+		# Set up the symbols
+	
+        FFTWF_INCLUDES="-I$cpl_fftw_includes"
+        FFTWF_LDFLAGS="-L$cpl_fftwf_libraries"
+        LIBFFTWF="-lfftw3f -lm"
+        LIBFFTWF_STATIC="$cpl_fftwf_libraries/$cpl_fftwf_check_lib -lm"
+
+
+        # Check fftw (single-precision) library version
+
+        AC_MSG_CHECKING([for a fftw (single-precision) version >= $cpl_fftw_check_version])
+        
+        AC_LANG_PUSH(C)
+        
+        cpl_fftw_cflags_save="$CFLAGS"
+        cpl_fftw_ldflags_save="$LDFLAGS"
+        cpl_fftw_libs_save="$LIBS"
+
+        CFLAGS="$FFTWF_INCLUDES $CFLAGS"
+        LDFLAGS="$FFTWF_LDFLAGS $LDFLAGS"
+        LIBS="$LIBFFTWF"
+        
+        AC_RUN_IFELSE([AC_LANG_PROGRAM(
+                      [[
+                      #include <stdio.h>
+                      #include <stdlib.h>
+                      #include <string.h>
+                      #include <fftw3.h>
+                      ]],
+                      [
+                      char vmin[[]] = "$cpl_fftw_check_version";
+                      char *vstr    = strdup(fftwf_version);
+                      char *vlib    = vstr;
+                      char *suffix  = NULL;
+
+                      int min_major = 0;
+                      int min_minor = 0;
+                      int min_micro = 0;
+
+                      int lib_major = 0;
+                      int lib_minor = 0;
+                      int lib_micro = 0;
+
+                      vlib = strchr(vstr, '-') + 1;
+                      suffix = strrchr(vlib, '-');
+					  
+					  if (suffix) {
+                          *suffix = '\0';
+					  }
+					  
+                      sscanf(vmin, "%d.%d.%d", &min_major, &min_minor, &min_micro);
+                      sscanf(vlib, "%d.%d.%d", &lib_major, &lib_minor, &lib_micro);
+                     
+                      FILE* f = fopen("conftest.out", "w");
+                      fprintf(f, "%s\n", vlib);
+                      fclose(f);
+                      
+                      free(vstr);
+                                          
+                      if (lib_major < min_major) {
+                          return 1;
+                      }
+                      else {
+                          if (lib_major == min_major) {
+                              if (lib_minor <  min_minor) {
+                                  return 1;
+                              }
+                              else {
+                                  if (lib_minor == min_minor) {
+                                      if (lib_micro < min_micro) {
+                                          return 1;
+                                      }
+                                  }
+                              }
+                          }
+                      }
+
+                      return 0;                      
+                      ])],
+                      [cpl_fftwf_version="`cat conftest.out`"],
+                      [
+                       cpl_fftwf_version="no";
+                       cpl_fftwf_version_found="`cat conftest.out`"
+                      ])
+
+        AC_MSG_RESULT([$cpl_fftwf_version])
+        
+        AC_LANG_POP(C)
+        
+        CFLAGS="$cpl_fftw_cflags_save"
+        LDFLAGS="$cpl_fftw_ldflags_save"
+        LIBS="$cpl_fftw_libs_save"
+
+        if test x"$cpl_fftwf_version" = xno; then
+        
+            AC_MSG_WARN([Installed single-precision fftw ($cpl_fftw_version_found) is too old!])
+            
+            FFTWF_INCLUDES=""
+            FFTWF_LDFLAGS=""
+            LIBFFTWF=""
+            
+        else	         
+	        AC_DEFINE_UNQUOTED(CPL_FFTWF_INSTALLED, 1, [Defined if FFTW (single-precision) is available])
+ 		fi
+ 
+        AC_SUBST(FFTWF_INCLUDES)
+        AC_SUBST(FFTWF_LDFLAGS)
+        AC_SUBST(LIBFFTWF)
+			
+	fi
+
+])
+
+
+#
+# CPL_CREATE_SYMBOLS(build=[])
+#-----------------------------
+# Sets the Makefile symbols for the CPL libraries. If an argument is
+# provided the symbols are setup for building CPL, if no argument is
+# given (default) the symbols are set for using the libraries
+# for external package development.
+AC_DEFUN([CPL_CREATE_SYMBOLS],
+[
+
+    if test -z "$1"; then
+        LIBCPLCORE='-lcplcore'
+        LIBCPLDRS='-lcpldrs'
+        LIBCPLUI='-lcplui'
+        LIBCPLDFS='-lcpldfs'
+    else
+        LIBCPLCORE='$(top_builddir)/cplcore/libcplcore.la'
+        LIBCPLDRS='$(top_builddir)/cpldrs/libcpldrs.la'
+        LIBCPLUI='$(top_builddir)/cplui/libcplui.la'
+        LIBCPLDFS='$(top_builddir)/cpldfs/libcpldfs.la'
+    fi
+
+   AC_SUBST(LIBCPLCORE)
+   AC_SUBST(LIBCPLDRS)
+   AC_SUBST(LIBCPLUI)
+   AC_SUBST(LIBCPLDFS)
+
+])
+
+
+# CPL_CHECK_LIBS
+#---------------
+# Checks for the CPL libraries and header files.
+AC_DEFUN([CPL_CHECK_LIBS],
+[
+
+    AC_MSG_CHECKING([for CPL])
+
+    cpl_check_cpl_header="cpl.h"
+    cpl_check_cpl_lib="libcplcore.a"
+
+    cpl_incdirs=""
+    cpl_libdirs=""
+    cpl_includes=""
+    cpl_libraries=""
+
+    AC_ARG_WITH(cpl,
+                AC_HELP_STRING([--with-cpl],
+                               [location where CPL is installed]),
+                [
+                    cpl_with_cpl=$withval
+                ])
+
+    AC_ARG_WITH(cpl-includes,
+                AC_HELP_STRING([--with-cpl-includes],
+                               [location of the CPL header files]),
+                cpl_with_cpl_includes=$withval)
+
+    AC_ARG_WITH(cpl-libs,
+                AC_HELP_STRING([--with-cpl-libs],
+                               [location of the CPL library]),
+                cpl_with_cpl_libs=$withval)
+
+    AC_ARG_ENABLE(cpl-test,
+                  AC_HELP_STRING([--disable-cpl-test],
+                                 [disables checks for the CPL library and headers]),
+                  cpl_enable_cpl_test=$enableval,
+                  cpl_enable_cpl_test=yes)
+
+
+    if test "x$cpl_enable_cpl_test" = xyes; then
+    
+        # Check for the CPL includes
+
+        if test -z "$cpl_with_cpl_includes"; then
+        
+            if test -z "$cpl_with_cpl"; then
+            
+                # Try some known system locations
+                
+                cpl_incdirs="/opt/cpl/include"
+                cpl_incdirs="$cpl_incdirs /usr/local/include"
+                cpl_incdirs="$cpl_incdirs /usr/include"
+
+                test -n "$CPLDIR" && \
+                    cpl_incdirs="$CPLDIR/include \
+                                 $cpl_incdirs"
+
+            else
+
+                cpl_incdirs="$cpl_with_cpl/include"
+
+            fi
+            
+        else
+            cpl_incdirs="$cpl_with_cpl_includes"
+        fi
+
+        ESO_FIND_FILE($cpl_check_cpl_header, $cpl_incdirs, cpl_includes)
+
+
+        # Check for the CPL libraries
+
+        if test -z "$cpl_with_cpl_libs"; then
+
+            if test -z "$cpl_with_cpl"; then
+            
+                # Try some known system locations
+
+                cpl_libdirs="/opt/cpl/lib"
+                cpl_libdirs="$cpl_libdirs /usr/local/lib64"
+                cpl_libdirs="$cpl_libdirs /usr/local/lib"
+                cpl_libdirs="$cpl_libdirs /usr/local/lib32"
+                cpl_libdirs="$cpl_libdirs /usr/lib64"
+                cpl_libdirs="$cpl_libdirs /usr/lib"
+                cpl_libdirs="$cpl_libdirs /usr/lib32"
+
+                test -n "$CPLDIR" && \
+                    cpl_libdirs="$CPLDIR/lib64 $CPLDIR/lib $CPLDIR/lib32 \
+                                 $cpl_libdirs"
+
+            else
+
+                cpl_libdirs="$cpl_with_cpl/lib64"
+                cpl_libdirs="$cpl_libdirs $cpl_with_cpl/lib"
+                cpl_libdirs="$cpl_libdirs $cpl_with_cpl/lib32"
+
+            fi
+            
+        else
+            cpl_libdirs="$cpl_with_cpl_libs"
+        fi
+
+        ESO_FIND_FILE($cpl_check_cpl_lib, $cpl_libdirs, cpl_libraries)
+
+
+        if test x"$cpl_includes" = xno || test x"$cpl_libraries" = xno; then
+            cpl_notfound=""
+
+            if test x"$cpl_includes" = xno; then
+                if test x"$cpl_libraries" = xno; then
+                    cpl_notfound="(headers and libraries)"
+                else
+                    cpl_notfound="(headers)"
+                fi
+            else
+                cpl_notfound="(libraries)"
+            fi
+
+            AC_MSG_ERROR([CPL $cpl_notfound was not found on your system. Please check!])
+        else
+            AC_MSG_RESULT([libraries $cpl_libraries, headers $cpl_includes])
+        fi
+
+    	# The libcext headers are required. By default it part of the
+    	# CPL installation and it is assumed that the cext headers are
+    	# present in the same location as the CPL headers
+   	      	   
+   	    CPL_CHECK_CEXT($cpl_includes, $cpl_libraries) 
+
+
+        # Set up the symbols
+
+        CPL_INCLUDES="-I$cpl_includes $CX_INCLUDES $CFITSIO_INCLUDES"
+        CPL_LDFLAGS="-L$cpl_libraries $CX_LDFLAGS $CFITSIO_LDFLAGS"
+        CPL_CREATE_SYMBOLS
+ 
+ 
+        AC_MSG_CHECKING([whether CPL can be used])
+        AC_LANG_PUSH(C)
+        
+        cpl_cflags_save="$CFLAGS"
+        cpl_ldflags_save="$LDFLAGS"
+        cpl_libs_save="$LIBS"
+
+        CFLAGS="$CPL_INCLUDES $CFLAGS"
+        LDFLAGS="$CPL_LDFLAGS $LDFLAGS"
+        LIBS="$LIBCPLCORE $LIBCEXT $LIBS"
+        
+        AC_LINK_IFELSE([AC_LANG_PROGRAM(
+                       [[
+                       #include <cpl.h>
+                       ]],
+                       [
+                       cpl_init(CPL_INIT_DEFAULT);
+                       ])],
+                       [cpl_is_usable="yes"],
+                       [cpl_is_usable="no"])
+
+        AC_MSG_RESULT([$cpl_is_usable])
+        
+        AC_LANG_POP(C)
+        
+        CFLAGS="$cpl_cflags_save"
+        LDFLAGS="$cpl_ldflags_save"
+        LIBS="$cpl_libs_save"
+
+        if test x"$cpl_is_usable" = xno; then
+            AC_MSG_ERROR([Linking with CPL failed! Please check architecture!])
+        fi
+        
+    else
+    
+        AC_MSG_RESULT([disabled])
+        AC_MSG_WARN([CPL checks have been disabled! This package may not build!])
+        CPL_INCLUDES=""
+        CPL_LDFLAGS=""
+        LIBCPLCORE=""
+        LIBCPLDRS=""
+        LIBCPLUI=""
+        LIBCPLDFS=""
+        
+    fi
+
+    AC_SUBST(CPL_INCLUDES)
+    AC_SUBST(CPL_LDFLAGS)
+    AC_SUBST(LIBCPLCORE)
+    AC_SUBST(LIBCPLDRS)
+    AC_SUBST(LIBCPLUI)
+    AC_SUBST(LIBCPLDFS)
+
+])
diff --git a/m4macros/eso.m4 b/m4macros/eso.m4
new file mode 100644
index 0000000..86e1839
--- /dev/null
+++ b/m4macros/eso.m4
@@ -0,0 +1,1065 @@
+# ESO_PROG_CC_FLAG(FLAG, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
+#-----------------------------------------------------------------
+AC_DEFUN([ESO_PROG_CC_FLAG],
+[
+    AC_REQUIRE([AC_PROG_CC])
+
+    flag=`echo $1 | sed 'y%.=/+-%___p_%'`
+    AC_CACHE_CHECK([whether $CC supports -$1],
+                   [eso_cv_prog_cc_$flag],
+                   [
+                       eval "eso_cv_prog_cc_$flag=no"
+                       AC_LANG_PUSH(C)
+
+                       echo 'int main() { return 0; }' >conftest.$ac_ext
+
+                       try_compile="`$CC -$1 -c conftest.$ac_ext 2>&1`"
+                       if test -z "$try_compile"; then
+                           try_link="`$CC -$1 -o conftest$ac_exeext \
+                                    conftest.$ac_ext 2>&1`"
+                           if test -z "$try_link"; then
+                               eval "eso_cv_prog_cc_$flag=yes"
+                           fi
+                       fi
+                       rm -f conftest*
+
+                       AC_LANG_POP(C)
+                   ])
+
+    if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then
+        :
+        $2
+    else
+        :
+        $3
+    fi
+])
+
+
+# ESO_ENABLE_DEBUG(debug=no)
+#---------------------------
+AC_DEFUN([ESO_ENABLE_DEBUG],
+[
+    AC_REQUIRE([AC_PROG_CC])
+
+    AC_ARG_ENABLE(debug,
+                  AC_HELP_STRING([--enable-debug],
+                                 [creates debugging code [[default=$1]]]),
+                  eso_enable_debug=$enableval, eso_enable_debug=$1)
+
+    AC_CACHE_CHECK([whether debugging code should be created],
+                   eso_cv_enable_debug,
+                   eso_cv_enable_debug=$eso_enable_debug)
+
+    if test x"$eso_cv_enable_debug" = xyes; then
+
+        eso_clean_CFLAGS="`echo $CFLAGS | sed -e 's/-O[[0-9]]//g' \
+                                              -e 's/-g[[0-9]]//g' \
+                                              -e 's/-g[[a-z,A-Z]]* / /g' \
+                                              -e 's/-[[Og]]//g'`"
+
+        ESO_PROG_CC_FLAG([g3], [CFLAGS="$CFLAGS -g3"])
+
+        if test x"$eso_cv_prog_cc_g3" = xyes; then
+            CFLAGS="-g3"
+        else
+            if test x"$ac_cv_prog_cc_g" = xyes; then
+                CFLAGS="-g"
+            else
+                CFLAGS=""
+            fi
+        fi
+
+        ESO_PROG_CC_FLAG([ggdb], [CFLAGS="$CFLAGS -ggdb"])
+        ESO_PROG_CC_FLAG([O0], [CFLAGS="$CFLAGS -O0"])
+        ESO_PROG_CC_FLAG([rdynamic], [CFLAGS="$CFLAGS -rdynamic"])
+        ESO_PROG_CC_FLAG([Wall], [CFLAGS="$CFLAGS -Wall"])
+        ESO_PROG_CC_FLAG([W], [CFLAGS="$CFLAGS -W"])
+
+        CFLAGS="$CFLAGS $eso_clean_CFLAGS"
+        ESO_DEBUG_FLAGS="-DESO_ENABLE_DEBUG"
+    else
+        ESO_DEBUG_FLAGS="-DNDEBUG"
+    fi
+
+    AC_SUBST(ESO_DEBUG_FLAGS)
+])
+
+
+# ESO_ENABLE_STRICT(strict=no)
+#-----------------------------
+AC_DEFUN([ESO_ENABLE_STRICT],
+[
+	AC_REQUIRE([AC_PROG_EGREP])
+    AC_REQUIRE([AC_PROG_CC])
+
+    AC_ARG_ENABLE(strict,
+                  AC_HELP_STRING([--enable-strict],
+                                 [compiles with strict compiler options (may not work!) [[default=$1]]]),
+                  eso_enable_strict=$enableval, eso_enable_strict=$1)
+
+    AC_CACHE_CHECK([whether strict compiler options should be used],
+                   eso_cv_enable_strict,
+                   eso_cv_enable_strict=$eso_enable_strict)
+
+
+    if test x"$eso_cv_enable_strict" = xyes; then
+    
+    	eso_enable_strict_std_set=no
+    	
+        if test -n "$CFLAGS"; then
+            echo $CFLAGS | $EGREP '(\-std=|-ansi)' >/dev/null 2>&1
+            if test x"$?" = x0; then
+            	eso_enable_strict_std_set=yes
+            fi
+        fi
+        
+        if test x"$eso_enable_strict_std_set" = xno; then
+        	ESO_PROG_CC_FLAG([std=c99], [CFLAGS="$CFLAGS -std=c99"])
+        fi
+        
+        ESO_PROG_CC_FLAG([pedantic], [CFLAGS="$CFLAGS -pedantic"])
+        
+    fi
+])
+
+
+# ESO_ENABLE_PROFILE(profile=no)
+#-----------------------------
+AC_DEFUN([ESO_ENABLE_PROFILE],
+[
+    AC_REQUIRE([AC_PROG_CC])
+
+    AC_ARG_ENABLE(profile,
+                  AC_HELP_STRING([--enable-profile],
+                                 [compiles with compiler options necessary for profiling (may not work!) [[default=$1]]]),
+                  eso_enable_profile=$enableval, eso_enable_profile=$1)
+
+    AC_CACHE_CHECK([whether profiling compiler options should be used],
+                   eso_cv_enable_profile,
+                   eso_cv_enable_profile=$eso_enable_profile)
+
+
+    if test x"$eso_cv_enable_profile" = xyes; then
+        ESO_PROG_CC_FLAG([pg], [CFLAGS="$CFLAGS -pg"])
+        ESO_PROG_CC_FLAG([g], [CFLAGS="$CFLAGS -g"])
+        ESO_PROG_CC_FLAG([static-libgcc], [CFLAGS="$CFLAGS -static-libgcc"])
+
+        AC_ENABLE_SHARED(no)
+        AC_ENABLE_STATIC(yes)
+    fi
+])
+
+
+# ESO_CHECK_DOCTOOLS
+#-------------------
+AC_DEFUN([ESO_CHECK_DOCTOOLS],
+[
+    AC_ARG_VAR([DOXYGEN], [doxygen command])
+    AC_PATH_PROG([DOXYGEN], [doxygen])
+
+    AC_ARG_VAR([LATEX], [latex command])
+    AC_PATH_PROG([LATEX], [latex])
+
+
+    if test -z "${DOXYGEN}"; then
+        DOXYGEN=":"
+    fi
+
+    if test -z "${LATEX}"; then
+        LATEX=":"
+    fi
+
+])
+
+
+# ESO_PROG_AR
+#------------
+# Checks if ar is in the path
+AC_DEFUN([ESO_PROG_AR],
+[
+    AC_CHECK_PROG(AR, ar, ar, NONE)
+
+    if test x"$AR" = xNONE; then
+        AC_MSG_ERROR([Cannot find \'ar\'])
+    fi
+
+])
+
+
+# ESO_CHECK_EXTRA_LIBS
+#---------------------
+# Check for non-standard headers and libraries
+AC_DEFUN([ESO_CHECK_EXTRA_LIBS],
+[
+
+    AC_ARG_WITH(extra-includes,
+                AC_HELP_STRING([--with-extra-includes=DIR],
+                               [adds non standard include paths]),
+                eso_with_extra_includes=$withval, eso_with_extra_includes=NONE)
+
+    AC_ARG_WITH(extra-libs,
+                AC_HELP_STRING([--with-extra-libs=DIR],
+                              [adds non standard library paths]),
+                eso_with_extra_libs=$withval, eso_with_extra_libs=NONE)
+
+    AC_MSG_CHECKING([for extra includes])
+    AC_CACHE_VAL([eso_cv_with_extra_includes],
+                 [
+                     eso_cv_with_extra_includes=$eso_with_extra_includes
+                 ])
+
+    if test x"$eso_cv_with_extra_includes" != xNONE; then
+        eso_save_IFS=$IFS
+        IFS=':'
+
+        for dir in $eso_cv_with_extra_includes; do
+            EXTRA_INCLUDES="$EXTRA_INCLUDES -I$dir"
+        done
+
+        IFS=$eso_save_IFS
+        AC_MSG_RESULT(added)
+    else
+        AC_MSG_RESULT(no)
+    fi
+
+
+    AC_MSG_CHECKING([for extra libs])
+    AC_CACHE_VAL([eso_cv_with_extra_libs],
+                 [
+                     eso_cv_with_extra_libs=$eso_with_extra_libs
+                 ])
+
+    if test x"$eso_cv_with_extra_libs" != xNONE; then
+        eso_save_IFS=$IFS
+        IFS=':'
+
+        for dir in $eso_cv_with_extra_libs; do
+            EXTRA_LDFLAGS="$EXTRA_LDFLAGS -L$dir"
+        done
+
+        IFS=$eso_save_IFS
+        AC_MSG_RESULT(added)
+    else
+        AC_MSG_RESULT(no)
+    fi
+
+])
+
+
+# ESO_CHECK_THREADS_POSIX
+#------------------------
+# Check whether the POSIX threads are available. The cached result is
+# set to 'yes' if either the compiler supports the '-pthread' flag, or linking
+# with the POSIX thread library works, and the header file defining the POSIX
+# threads symbols is present. If POSIX threads are not supported, the
+# result is set to 'no'. Whether the compiler supports POSIX threads,
+# or whether the library, and the header are available is stored in cache
+# variables.  
+AC_DEFUN([ESO_CHECK_THREADS_POSIX],
+[
+    AC_REQUIRE([AC_PROG_CC])
+
+    ESO_PROG_CC_FLAG([pthread], [], [])
+    
+    AC_CHECK_LIB([pthread], [pthread_create],
+                 [eso_threads_have_libpthread=yes],
+                 [eso_threads_have_libpthread=no])
+
+    AC_CHECK_HEADER([pthread.h],
+                    [eso_threads_have_pthread_h=yes],
+                    [eso_threads_have_pthread_h=no])
+
+    if test x"$eso_threads_have_pthread_h" != xyes; then
+        eso_threads_posix=no
+    else
+        if test x"$eso_threads_have_libpthread" != xyes && \
+          test x"$eso_cv_prog_cc_pthread" != xyes; then
+            eso_threads_posix=no
+        else
+            eso_threads_posix=yes
+        fi
+    fi
+    
+    
+    # Setup the POSIX thread symbols
+
+    if test x"$eso_threads_have_pthread_h" = xyes; then
+        AC_DEFINE([HAVE_PTHREAD_H], [1],
+                  [Define to 1 if you have <pthread.h>.])
+    fi
+    
+    if test x"$eso_threads_posix" = xyes; then
+    
+        if test x"$eso_cv_prog_cc_pthread" = xyes; then
+            PTHREAD_CFLAGS="-pthread"
+        else
+            PTHREAD_CFLAGS=""
+        fi
+        
+        if test x"$eso_threads_have_libpthread" = xyes; then
+            LIBPTHREAD="-lpthread"
+        else
+            LIBPTHREAD=""
+        fi
+        
+    fi  
+
+    AC_CACHE_VAL(eso_cv_threads_posix_header,
+                 eso_cv_threads_posix_header=$eso_threads_have_pthread_h)          
+    AC_CACHE_VAL(eso_cv_threads_posix_lib,
+                 eso_cv_threads_posix_lib=$eso_threads_have_libpthread)          
+    AC_CACHE_VAL(eso_cv_threads_posix_flags,
+                 eso_cv_threads_posix_flags=$eso_cv_prog_cc_pthread)          
+    AC_CACHE_VAL(eso_cv_threads_posix,
+                 eso_cv_threads_posix=$eso_threads_posix)
+
+    AC_SUBST(PTHREAD_CFLAGS)
+    AC_SUBST(LIBPTHREAD)
+    
+])
+
+
+# ESO_CHECK_FUNC(FUNCTION, INCLUDES, SYMBOL)
+#-------------------------------------------
+# Checks whether a function is available and declared.
+AC_DEFUN([ESO_CHECK_FUNC],
+[
+
+    AC_LANG_PUSH(C)
+
+    AC_CHECK_DECL($1, [], [], [$2])
+
+    eso_save_CFLAGS="$CFLAGS"
+
+    if test x"$GCC" = xyes; then
+        CFLAGS="$CFLAGS -pedantic-errors"
+    fi
+
+    AC_CHECK_FUNC($1)
+
+    CFLAGS="$eso_save_CFLAGS"
+
+    AC_LANG_POP(C)
+
+    if test x"$ac_cv_have_decl_$1" = xyes &&
+       test x"$ac_cv_func_$1" = xyes; then
+        AC_DEFINE($3)
+    fi
+
+])
+
+
+# ESO_FUNC_VSNPRINTF_C99
+#-----------------------
+# Check whether vsnprintf() has C99 semantics.
+AC_DEFUN([ESO_FUNC_VSNPRINTF_C99],
+[
+
+    AH_TEMPLATE([HAVE_VSNPRINTF_C99],
+                [Define if you have the C99 `vsnprintf' function.])
+
+    AC_CACHE_CHECK([whether vsnprintf has C99 semantics],
+                   [eso_cv_func_vsnprintf_c99],
+                   [
+                       AC_LANG_PUSH(C)
+
+                       eso_cppflags_save="$CPPFLAGS"
+                       eso_cflags_save="$CFLAGS"
+                       eso_ldflags_save="$LDFLAGS"
+                       eso_libs_save="$LIBS"
+
+                       if test x$GCC = xyes; then
+                           CFLAGS="$CFLAGS -pedantic-errors"
+                           CPPFLAGS="$CPPFLAGS $CFLAGS"
+                       fi
+
+                       AC_RUN_IFELSE(
+                       [
+AC_LANG_PROGRAM(
+[[
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+
+int
+doit(char * s, ...)
+{
+    char buffer[32];
+    va_list args;
+    int q, r;
+
+    va_start(args, s);
+    q = vsnprintf(NULL, 0, s, args);
+    r = vsnprintf(buffer, 5, s, args);
+    va_end(args);
+
+    if (q != 7 || r != 7)
+      exit(1);
+
+    exit(0);
+}
+]],
+[[
+    doit((char*)"1234567");
+    exit(1);
+]])
+                       ],
+                       [eso_cv_func_vsnprintf_c99=yes],
+                       [eso_cv_func_vsnprintf_c99=no],
+                       [eso_cv_func_vsnprintf_c99=no])
+
+                       CPPFLAGS="$eso_cppflags_save"
+                       CFLAGS="$eso_cflags_save"
+                       LDFLAGS="$eso_ldflags_save"
+                       LIBS="$eso_libs_save"
+
+                       AC_LANG_POP(C)
+                   ])
+
+# Note that the default is to be pessimistic in the case of cross compilation.
+# If you know that the target has a C99 vsnprintf(), you can get around this
+# by setting eso_func_vsnprintf_c99 to yes, as described in the Autoconf
+# manual.
+
+    if test x$eso_cv_func_vsnprintf_c99 = xyes; then
+        AC_DEFINE(HAVE_VSNPRINTF_C99)
+    fi
+
+])
+
+
+# ESO_CHECK_PRINTF_FORMATS
+#-------------------------
+# Checks for printf() format peculiarities.
+AC_DEFUN([ESO_CHECK_PRINTF_FORMATS],
+[
+
+    # Check if string format for NULL is `(null)'
+
+    AH_TEMPLATE([HAVE_PRINTF_STR_FMT_NULL],
+                [Define if printf outputs `(null)' when printing NULL using
+                 `%s'])
+
+    AC_RUN_IFELSE(
+    [
+AC_LANG_PROGRAM(
+[[
+#include <stdio.h>
+#include <string.h>
+]],
+[[
+    char s[128];
+
+    sprintf(s, "%s", NULL);
+    return strncmp(s, "(null)", 6) ? 1 : 0;
+]])
+    ],
+    [eso_have_printf_str_format_null=yes],
+    [eso_have_printf_str_format_null=no],
+    [eso_have_printf_str_format_null=no])
+
+    if test x$eso_have_printf_str_format_null = xyes; then
+        AC_DEFINE(HAVE_PRINTF_STR_FMT_NULL)
+    fi
+
+
+    # Check if pointer format for NULL is `(nil)'
+
+    AH_TEMPLATE([HAVE_PRINTF_PTR_FMT_NIL],
+                [Define if printf outputs `(nil)' when printing NULL using
+                 `%p'])
+
+    AC_RUN_IFELSE(
+    [
+AC_LANG_PROGRAM(
+[[
+#include <stdio.h>
+#include <string.h>
+]],
+[[
+    char s[128];
+
+    sprintf(s, "%p", NULL);
+    return strncmp(s, "(nil)", 5) ? 1 : 0;
+]])
+    ],
+    [eso_have_printf_ptr_format_nil=yes],
+    [eso_have_printf_ptr_format_nil=no],
+    [eso_have_printf_ptr_format_nil=no])
+
+    if test x$eso_have_printf_ptr_format_nil = xyes; then
+        AC_DEFINE(HAVE_PRINTF_PTR_FMT_NIL)
+    fi
+
+
+    # Check if output for `%p' is the same as `%#x'
+
+    AH_TEMPLATE([HAVE_PRINTF_PTR_FMT_ALTERNATE],
+                [Define if printf format `%p' produces the same output as
+                 `%#x' or `%#lx'])
+
+    AC_RUN_IFELSE(
+    [
+AC_LANG_PROGRAM(
+[[
+#include <stdio.h>
+#include <string.h>
+]],
+[[
+    char s1[128], s2[128];
+
+    sprintf(s1, "%p", s1);
+    sprintf(s2, "%#x", s1);
+    return strncmp(s1, s2, 3) ? 1 : 0;
+]])
+    ],
+    [eso_have_printf_ptr_format_alternate=yes],
+    [eso_have_printf_ptr_format_alternate=no],
+    [eso_have_printf_ptr_format_alternate=no])
+
+    if test x$eso_have_printf_ptr_format_alternate = xyes; then
+        AC_DEFINE(HAVE_PRINTF_PTR_FMT_ALTERNATE)
+    fi
+
+
+    # Check if pointers are treated as signed
+
+    AH_TEMPLATE([HAVE_PRINTF_PTR_FMT_SIGNED],
+                [Define if printf treats pointers as signed when using a sign
+                 flag])
+
+    AC_RUN_IFELSE(
+    [
+AC_LANG_PROGRAM(
+[[
+#include <stdio.h>
+]],
+[[
+    char s[128];
+
+    sprintf(s, "%+p", s);
+    return s[0] == '+' ? 0 : 1;
+]])
+    ],
+    [eso_have_printf_ptr_format_signed=yes],
+    [eso_have_printf_ptr_format_signed=no],
+    [eso_have_printf_ptr_format_signed=no])
+
+    if test x$eso_have_printf_ptr_format_signed = xyes; then
+        AC_DEFINE(HAVE_PRINTF_PTR_FMT_SIGNED)
+    fi
+
+
+    # Check if default precision for conversion specifier `g' is 1 (as
+    # required by ISO C) or 6.
+
+    AH_TEMPLATE([HAVE_PRINTF_FLT_FMT_G_STD],
+                [Define if printf default precision for format `g' is 1
+                 (ISO C standard) or 6])
+
+    AC_RUN_IFELSE(
+    [
+AC_LANG_PROGRAM(
+[[
+#include <stdio.h>
+]],
+[[
+    char s1[128], s2[128];
+    int n1, n2;
+
+    sprintf(s1, "%g%n", 1.123456, &n1);
+    sprintf(s2, "%.1g%n", 1.123456, &n2);
+    return n1 > n2 ? 1 : 0;
+]])
+    ],
+    [eso_have_printf_flt_format_g_std=yes],
+    [eso_have_printf_flt_format_g_std=no],
+    [eso_have_printf_flt_format_g_std=no])
+
+    if test x$eso_have_printf_flt_format_g_std = xyes; then
+        AC_DEFINE(HAVE_PRINTF_FLT_FMT_G_STD)
+    fi
+
+])
+
+
+# ESO_FUNC_VSNPRINTF
+#-------------------
+# Checks for vsnprintf and snprintf declaration and function.
+AC_DEFUN([ESO_FUNC_VSNPRINTF],
+[
+
+    eso_compile_snprintf=no
+
+    AH_TEMPLATE([HAVE_VSNPRINTF],
+                [Define if you have the `vsnprintf' function])
+    ESO_CHECK_FUNC(vsnprintf, [
+#include <stdio.h>
+#include <stdarg.h>
+                              ], HAVE_VSNPRINTF)
+
+    if test x$ac_cv_func_vsnprintf = xyes &&
+       test x$ac_cv_have_decl_vsnprintf = xyes; then
+
+        ESO_FUNC_VSNPRINTF_C99
+
+        if test x$eso_cv_func_vsnprintf_c99 != xyes; then
+            eso_compile_snprintf=yes
+        fi
+
+    else
+        eso_compile_snprintf=yes
+    fi
+
+    if test x$eso_compile_snprintf = xyes; then
+        if test -n "$LIBTOOL"; then
+            SNPRINTF=snprintf.lo
+        else
+            SNPRINTF=snprintf.$ac_objext
+        fi
+    fi
+
+    AC_SUBST(SNPRINTF)
+
+    # The symbols defined by the following macro are only needed to setup the
+    # vsnprintf() replacement. May be useless if the vsnprintf implementation
+    # changes.
+    ESO_CHECK_PRINTF_FORMATS
+
+    AH_TEMPLATE([HAVE_SNPRINTF],
+                [Define if you have the `snprintf' function])
+    ESO_CHECK_FUNC(snprintf, [#include <stdio.h>], HAVE_SNPRINTF)
+
+])
+
+
+# ESO_FUNC_VASPRINTF
+#-------------------
+# Checks for vasprintf and asprintf declaration and function.
+AC_DEFUN([ESO_FUNC_VASPRINTF],
+[
+
+    AH_TEMPLATE([HAVE_VASPRINTF],
+                [Define if you have the `vasprintf' function])
+    ESO_CHECK_FUNC(vasprintf, [
+#include <stdio.h>
+#include <stdarg.h>
+                              ], HAVE_VASPRINTF)
+
+    AH_TEMPLATE([HAVE_ASPRINTF],
+                [Define if you have the `asprintf' function])
+    ESO_CHECK_FUNC(asprintf, [
+#include <stdio.h>
+                             ], HAVE_ASPRINTF)
+
+])
+
+
+# ESO_FUNC_FPATHCONF
+#-------------------
+# Checks for fpathconf declaration and function.
+AC_DEFUN([ESO_FUNC_FPATHCONF],
+[
+
+    AH_TEMPLATE([HAVE_FPATHCONF],
+                [Define if you have the `fpathconf' function])
+    ESO_CHECK_FUNC(fpathconf, [#include <unistd.h>], HAVE_FPATHCONF)
+
+    # If we have fpathconf we should also have pathconf, but who knows.
+    AH_TEMPLATE([HAVE_PATHCONF],
+                [Define if you have the `pathconf' function])
+    ESO_CHECK_FUNC(pathconf, [#include <unistd.h>], HAVE_PATHCONF)
+
+])
+
+
+# ESO_FUNC_SYSCONF
+#-----------------
+# Checks for sysconf declaration and function.
+AC_DEFUN([ESO_FUNC_SYSCONF],
+[
+
+    AH_TEMPLATE([HAVE_SYSCONF],
+                [Define if you have the `sysconf' function])
+    ESO_CHECK_FUNC(sysconf, [#include <unistd.h>], HAVE_SYSCONF)
+
+])
+
+
+# ESO_FUNC_GETOPT
+#----------------
+# Checks for GNU getopt_long declaration and function.
+AC_DEFUN([ESO_FUNC_GETOPT],
+[
+
+    AH_TEMPLATE([HAVE_GETOPT_LONG],
+                [Define if you have the `getopt_long' function])
+
+    ESO_CHECK_FUNC(getopt_long, [#include <getopt.h>], HAVE_GETOPT_LONG)
+
+    if test x"$ac_cv_func_getopt_long" = xno ||
+       test x"$eso_cv_have_decl_getopt_long" = xno; then
+        if test -n "$LIBTOOL"; then
+            GETOPT="getopt.lo getopt1.lo"
+        else
+            GETOPT="getopt.$ac_objext getopt1.$ac_objext"
+        fi
+    fi
+
+    AC_SUBST(GETOPT)
+
+
+])
+
+
+# ESO_FUNC_GETPWUID
+#------------------
+# Checks for getpwuid declaration and function.
+AC_DEFUN([ESO_FUNC_GETPWUID],
+[
+
+    AH_TEMPLATE([HAVE_GETPWUID],
+                [Define if you have the `getpwuid' function])
+
+    ESO_CHECK_FUNC(getpwuid, [#include <pwd.h>], HAVE_GETPWUID)
+
+])
+
+
+# ESO_FUNC_GETUID
+#----------------
+AC_DEFUN([ESO_FUNC_GETUID],
+[
+
+    AH_TEMPLATE([HAVE_GETUID],
+                [Define if you have the `getuid' function])
+
+    ESO_CHECK_FUNC(getuid, [#include <unistd.h>], HAVE_GETUID)
+
+])
+
+
+# ESO_FUNC_LSTAT
+#---------------
+AC_DEFUN([ESO_FUNC_LSTAT],
+[
+
+    AH_TEMPLATE([HAVE_LSTAT],
+                [Define if you have the `lstat' function])
+
+    ESO_CHECK_FUNC(lstat, [#include <sys/stat.h>], HAVE_LSTAT)
+
+])
+
+
+# ESO_FUNC_STRDUP
+#----------------
+AC_DEFUN([ESO_FUNC_STRDUP],
+[
+
+    AH_TEMPLATE([HAVE_STRDUP],
+                [Define if you have the `strdup' function])
+
+    ESO_CHECK_FUNC(strdup, [#include <string.h>], HAVE_STRDUP)
+
+    AH_BOTTOM([
+#ifndef HAVE_STRDUP
+#  define strdup  cx_strdup
+#endif
+              ])
+])
+
+
+# ESO_FUNC_STPCPY
+#----------------
+AC_DEFUN([ESO_FUNC_STPCPY],
+[
+
+    AH_TEMPLATE([HAVE_STPCPY],
+                [Define if you have the `stpcpy' function])
+
+    ESO_CHECK_FUNC(stpcpy, [#include <stpcpy.h>], HAVE_STPCPY)
+
+])
+
+
+# ESO_FUNC_SYMLINK
+#-----------------
+AC_DEFUN([ESO_FUNC_SYMLINK],
+[
+
+    AH_TEMPLATE([HAVE_SYMLINK],
+                [Define if you have the `symlink' function])
+
+    ESO_CHECK_FUNC(symlink, [#include <unistd.h>], HAVE_SYMLINK)
+
+])
+
+
+# ESO_FUNC_WORDEXP
+#-----------------
+AC_DEFUN([ESO_FUNC_WORDEXP],
+[
+
+    AH_TEMPLATE([HAVE_WORDEXP],
+                [Define if you have the `wordexp' function])
+
+    ESO_CHECK_FUNC(wordexp, [#include <wordexp.h>], HAVE_WORDEXP)
+
+])
+
+
+# ESO_FUNC_GETTIMEOFDAY
+#----------------------
+AC_DEFUN([ESO_FUNC_GETTIMEOFDAY],
+[
+
+    AH_TEMPLATE([HAVE_GETTIMEOFDAY],
+                [Define if you have the `gettimeofday' function])
+
+    ESO_CHECK_FUNC(gettimeofday,
+                   [
+                       #include <unistd.h>
+                       #include <sys/time.h>
+                   ],
+                   HAVE_GETTIMEOFDAY)
+])
+
+
+# ESO_FUNC_VA_COPY(symbol)
+#-------------------------
+# Check for an implementation of va_copy(). The argument which must be
+# given is the preprocessor symbol that is defined to be either va_copy
+# or __va_copy depending on the available function, provided that an
+# implementation of va_copy is available at all.
+AC_DEFUN([ESO_FUNC_VA_COPY],
+[
+
+    # Check for all three va_copy possibilities, so we get
+    # all results in config.log for bug reports.
+
+    # Check for availability of va_copy(). This is ISO C. Available with
+    # gcc since version 3.0.
+    AC_CACHE_CHECK([for an implementation of va_copy()],
+                   [eso_cv_have_va_copy],
+                   [
+                       AC_RUN_IFELSE(
+                       [
+AC_LANG_PROGRAM(
+[[
+#ifdef HAVE_STDARG_H
+#include <stdarg.h>
+#endif
+
+void f(int i, ...)
+{
+  va_list args1, args2;
+  va_start (args1, i);
+  va_copy (args2, args1);
+   
+  if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
+    exit (1);
+   
+  va_end (args1);
+  va_end (args2);
+}
+]],
+[[
+  f(0, 42);
+]])
+                       ],
+                       [eso_cv_have_va_copy=yes],
+                       [eso_cv_have_va_copy=no],
+                       [eso_cv_have_va_copy=no])
+                   ])
+
+
+    # Check for availability of __va_copy(). Some compilers provide
+    # this. Available with gcc since version 2.8.1.
+    AC_CACHE_CHECK([for an implementation of __va_copy()],
+                   [eso_cv_have__va_copy],
+                   [
+                       AC_RUN_IFELSE(
+                       [
+AC_LANG_PROGRAM(
+[[
+#ifdef HAVE_STDARG_H
+#include <stdarg.h>
+#endif
+
+void f(int i, ...)
+{
+  va_list args1, args2;
+
+  va_start (args1, i);
+  __va_copy (args2, args1);
+
+  if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
+    exit (1);
+
+  va_end (args1);
+  va_end (args2);
+}
+]],
+[[
+  f(0, 42);
+]])
+                       ],
+                       [eso_cv_have__va_copy=yes],
+                       [eso_cv_have__va_copy=no],
+                       [eso_cv_have__va_copy=no])
+                   ])
+
+    AH_TEMPLATE([HAVE_VA_COPY],
+                [Define if you have an implementation of `va_copy()'.])
+    AH_TEMPLATE([HAVE___VA_COPY],
+                [Define if you have an implementation of `__va_copy()'.])
+
+    if test "x$eso_cv_have_va_copy" = "xyes"; then
+        eso_func_va_copy=va_copy
+        AC_DEFINE(HAVE_VA_COPY)
+    else
+        if test "x$eso_cv_have__va_copy" = "xyes"; then
+            eso_func_va_copy=__va_copy
+            AC_DEFINE(HAVE___VA_COPY)
+        fi
+    fi
+
+    AH_TEMPLATE([HAVE_VA_COPY_STYLE_FUNCTION],
+                [Define if you have an implementation of a `va_copy()' style
+                 function.])
+    AH_TEMPLATE([$1], [A `va_copy()' style function])
+
+    if test -n "$eso_func_va_copy"; then
+        AC_DEFINE_UNQUOTED([$1], $eso_func_va_copy)
+        AC_DEFINE(HAVE_VA_COPY_STYLE_FUNCTION)
+    fi
+
+    # Check whether va_lists can be copied by value
+    AC_CACHE_CHECK([whether va_lists can be copied by value],
+                   [eso_cv_have_va_value_copy],
+                   [
+                       AC_RUN_IFELSE(
+                       [
+AC_LANG_PROGRAM(
+[[                            
+#ifdef HAVE_STDARG_H
+#include <stdarg.h>
+#endif
+
+void f(int i, ...)
+{
+  va_list args1, args2;
+  va_start (args1, i);
+  args2 = args1;
+    
+  if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
+    exit (1);
+    
+  va_end (args1);
+  va_end (args2);
+}
+]],
+[[
+  f(0, 42);
+]])
+                       ],
+                       [eso_cv_have_va_value_copy=yes],
+                       [eso_cv_have_va_value_copy=no],
+                       [eso_cv_have_va_value_copy=no])
+                   ])
+
+    AH_TEMPLATE([HAVE_VA_LIST_COPY_BY_VALUE],
+                [Define if `va_lists' can be copied by value])
+    if test "x$eso_cv_have_va_value_copy" = "xyes"; then
+        AC_DEFINE(HAVE_VA_LIST_COPY_BY_VALUE)
+    fi
+
+])
+
+
+# ESO_FUNC_REALLOC_SANITY
+#-------------------------
+# Check whether realloc(NULL,) works.
+AC_DEFUN([ESO_FUNC_REALLOC_SANITY],
+[
+    AC_CACHE_CHECK([whether realloc(NULL,) works],
+                   [eso_cv_have_sane_realloc],
+                   [
+                       AC_RUN_IFELSE(
+                       [
+AC_LANG_PROGRAM(
+[[
+#include <stdlib.h>
+]],
+[[
+  return realloc (0, sizeof (int)) == 0;
+]])
+                       ],
+                       [eso_cv_have_sane_realloc=yes],
+                       [eso_cv_have_sane_realloc=no],
+                       [eso_cv_have_sane_realloc=no])
+                   ])
+
+    AH_TEMPLATE([HAVE_WORKING_REALLOC],
+                [Define if realloc(NULL,) works])
+
+    if test x$eso_cv_have_sane_realloc = xyes; then
+        AC_DEFINE(HAVE_WORKING_REALLOC)
+    fi
+
+])
+
+
+# ESO_FIND_FILE(file, directories, variable)
+#------------------------------------------
+# Search for file in directories. Set variable to the first location
+# where file was found, if file is not found at all variable is set to NO.
+AC_DEFUN([ESO_FIND_FILE],
+[
+    $3=no
+
+    for i in $2; do
+        for j in $1; do
+
+            echo "configure: __oline__: $i/$j" >&AC_FD_CC
+
+            if test -r "$i/$j"; then
+                echo "taking that" >&AC_FD_CC
+                $3=$i
+                break 2
+            fi
+        done
+    done
+])
+
+
+# ESO_SET_LIBRARY_VERSION([CURRENT], [REVISION], [AGE])
+#------------------------------------------------------
+# Sets the libtool versioning symbols LT_CURRENT, LT_REVISION, LT_AGE.
+AC_DEFUN([ESO_SET_LIBRARY_VERSION],
+[
+
+    if test -z "$1"; then
+        LT_CURRENT=0
+    else
+        LT_CURRENT="$1"
+    fi
+
+    if test -z "$2"; then
+        LT_REVISION=0
+    else
+        LT_REVISION="$2"
+    fi
+
+    if test -z "$3"; then
+        LT_AGE=0
+    else
+        LT_AGE="$3"
+    fi
+
+    AC_SUBST(LT_CURRENT)
+    AC_SUBST(LT_REVISION)
+    AC_SUBST(LT_AGE)
+])
diff --git a/m4macros/libtool.m4 b/m4macros/libtool.m4
new file mode 100644
index 0000000..671cde1
--- /dev/null
+++ b/m4macros/libtool.m4
@@ -0,0 +1,7360 @@
+# libtool.m4 - Configure libtool for the host system. -*-Autoconf-*-
+#
+#   Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005,
+#                 2006, 2007, 2008 Free Software Foundation, Inc.
+#   Written by Gordon Matzigkeit, 1996
+#
+# This file is free software; the Free Software Foundation gives
+# unlimited permission to copy and/or distribute it, with or without
+# modifications, as long as this notice is preserved.
+
+m4_define([_LT_COPYING], [dnl
+#   Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005,
+#                 2006, 2007, 2008 Free Software Foundation, Inc.
+#   Written by Gordon Matzigkeit, 1996
+#
+#   This file is part of GNU Libtool.
+#
+# GNU Libtool is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of
+# the License, or (at your option) any later version.
+#
+# As a special exception to the GNU General Public License,
+# if you distribute this file as part of a program or library that
+# is built using GNU Libtool, you may include this file under the
+# same distribution terms that you use for the rest of that program.
+#
+# GNU Libtool is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Libtool; see the file COPYING.  If not, a copy
+# can be downloaded from http://www.gnu.org/licenses/gpl.html, or
+# obtained by writing to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+])
+
+# serial 56 LT_INIT
+
+
+# LT_PREREQ(VERSION)
+# ------------------
+# Complain and exit if this libtool version is less that VERSION.
+m4_defun([LT_PREREQ],
+[m4_if(m4_version_compare(m4_defn([LT_PACKAGE_VERSION]), [$1]), -1,
+       [m4_default([$3],
+		   [m4_fatal([Libtool version $1 or higher is required],
+		             63)])],
+       [$2])])
+
+
+# _LT_CHECK_BUILDDIR
+# ------------------
+# Complain if the absolute build directory name contains unusual characters
+m4_defun([_LT_CHECK_BUILDDIR],
+[case `pwd` in
+  *\ * | *\	*)
+    AC_MSG_WARN([Libtool does not cope well with whitespace in `pwd`]) ;;
+esac
+])
+
+
+# LT_INIT([OPTIONS])
+# ------------------
+AC_DEFUN([LT_INIT],
+[AC_PREREQ([2.58])dnl We use AC_INCLUDES_DEFAULT
+AC_BEFORE([$0], [LT_LANG])dnl
+AC_BEFORE([$0], [LT_OUTPUT])dnl
+AC_BEFORE([$0], [LTDL_INIT])dnl
+m4_require([_LT_CHECK_BUILDDIR])dnl
+
+dnl Autoconf doesn't catch unexpanded LT_ macros by default:
+m4_pattern_forbid([^_?LT_[A-Z_]+$])dnl
+m4_pattern_allow([^(_LT_EOF|LT_DLGLOBAL|LT_DLLAZY_OR_NOW|LT_MULTI_MODULE)$])dnl
+dnl aclocal doesn't pull ltoptions.m4, ltsugar.m4, or ltversion.m4
+dnl unless we require an AC_DEFUNed macro:
+AC_REQUIRE([LTOPTIONS_VERSION])dnl
+AC_REQUIRE([LTSUGAR_VERSION])dnl
+AC_REQUIRE([LTVERSION_VERSION])dnl
+AC_REQUIRE([LTOBSOLETE_VERSION])dnl
+m4_require([_LT_PROG_LTMAIN])dnl
+
+dnl Parse OPTIONS
+_LT_SET_OPTIONS([$0], [$1])
+
+# This can be used to rebuild libtool when needed
+LIBTOOL_DEPS="$ltmain"
+
+# Always use our own libtool.
+LIBTOOL='$(SHELL) $(top_builddir)/libtool'
+AC_SUBST(LIBTOOL)dnl
+
+_LT_SETUP
+
+# Only expand once:
+m4_define([LT_INIT])
+])# LT_INIT
+
+# Old names:
+AU_ALIAS([AC_PROG_LIBTOOL], [LT_INIT])
+AU_ALIAS([AM_PROG_LIBTOOL], [LT_INIT])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AC_PROG_LIBTOOL], [])
+dnl AC_DEFUN([AM_PROG_LIBTOOL], [])
+
+
+# _LT_CC_BASENAME(CC)
+# -------------------
+# Calculate cc_basename.  Skip known compiler wrappers and cross-prefix.
+m4_defun([_LT_CC_BASENAME],
+[for cc_temp in $1""; do
+  case $cc_temp in
+    compile | *[[\\/]]compile | ccache | *[[\\/]]ccache ) ;;
+    distcc | *[[\\/]]distcc | purify | *[[\\/]]purify ) ;;
+    \-*) ;;
+    *) break;;
+  esac
+done
+cc_basename=`$ECHO "X$cc_temp" | $Xsed -e 's%.*/%%' -e "s%^$host_alias-%%"`
+])
+
+
+# _LT_FILEUTILS_DEFAULTS
+# ----------------------
+# It is okay to use these file commands and assume they have been set
+# sensibly after `m4_require([_LT_FILEUTILS_DEFAULTS])'.
+m4_defun([_LT_FILEUTILS_DEFAULTS],
+[: ${CP="cp -f"}
+: ${MV="mv -f"}
+: ${RM="rm -f"}
+])# _LT_FILEUTILS_DEFAULTS
+
+
+# _LT_SETUP
+# ---------
+m4_defun([_LT_SETUP],
+[AC_REQUIRE([AC_CANONICAL_HOST])dnl
+AC_REQUIRE([AC_CANONICAL_BUILD])dnl
+_LT_DECL([], [host_alias], [0], [The host system])dnl
+_LT_DECL([], [host], [0])dnl
+_LT_DECL([], [host_os], [0])dnl
+dnl
+_LT_DECL([], [build_alias], [0], [The build system])dnl
+_LT_DECL([], [build], [0])dnl
+_LT_DECL([], [build_os], [0])dnl
+dnl
+AC_REQUIRE([AC_PROG_CC])dnl
+AC_REQUIRE([LT_PATH_LD])dnl
+AC_REQUIRE([LT_PATH_NM])dnl
+dnl
+AC_REQUIRE([AC_PROG_LN_S])dnl
+test -z "$LN_S" && LN_S="ln -s"
+_LT_DECL([], [LN_S], [1], [Whether we need soft or hard links])dnl
+dnl
+AC_REQUIRE([LT_CMD_MAX_LEN])dnl
+_LT_DECL([objext], [ac_objext], [0], [Object file suffix (normally "o")])dnl
+_LT_DECL([], [exeext], [0], [Executable file suffix (normally "")])dnl
+dnl
+m4_require([_LT_FILEUTILS_DEFAULTS])dnl
+m4_require([_LT_CHECK_SHELL_FEATURES])dnl
+m4_require([_LT_CMD_RELOAD])dnl
+m4_require([_LT_CHECK_MAGIC_METHOD])dnl
+m4_require([_LT_CMD_OLD_ARCHIVE])dnl
+m4_require([_LT_CMD_GLOBAL_SYMBOLS])dnl
+
+_LT_CONFIG_LIBTOOL_INIT([
+# See if we are running on zsh, and set the options which allow our
+# commands through without removal of \ escapes INIT.
+if test -n "\${ZSH_VERSION+set}" ; then
+   setopt NO_GLOB_SUBST
+fi
+])
+if test -n "${ZSH_VERSION+set}" ; then
+   setopt NO_GLOB_SUBST
+fi
+
+_LT_CHECK_OBJDIR
+
+m4_require([_LT_TAG_COMPILER])dnl
+_LT_PROG_ECHO_BACKSLASH
+
+case $host_os in
+aix3*)
+  # AIX sometimes has problems with the GCC collect2 program.  For some
+  # reason, if we set the COLLECT_NAMES environment variable, the problems
+  # vanish in a puff of smoke.
+  if test "X${COLLECT_NAMES+set}" != Xset; then
+    COLLECT_NAMES=
+    export COLLECT_NAMES
+  fi
+  ;;
+esac
+
+# Sed substitution that helps us do robust quoting.  It backslashifies
+# metacharacters that are still active within double-quoted strings.
+sed_quote_subst='s/\([["`$\\]]\)/\\\1/g'
+
+# Same as above, but do not quote variable references.
+double_quote_subst='s/\([["`\\]]\)/\\\1/g'
+
+# Sed substitution to delay expansion of an escaped shell variable in a
+# double_quote_subst'ed string.
+delay_variable_subst='s/\\\\\\\\\\\$/\\\\\\$/g'
+
+# Sed substitution to delay expansion of an escaped single quote.
+delay_single_quote_subst='s/'\''/'\'\\\\\\\'\''/g'
+
+# Sed substitution to avoid accidental globbing in evaled expressions
+no_glob_subst='s/\*/\\\*/g'
+
+# Global variables:
+ofile=libtool
+can_build_shared=yes
+
+# All known linkers require a `.a' archive for static linking (except MSVC,
+# which needs '.lib').
+libext=a
+
+with_gnu_ld="$lt_cv_prog_gnu_ld"
+
+old_CC="$CC"
+old_CFLAGS="$CFLAGS"
+
+# Set sane defaults for various variables
+test -z "$CC" && CC=cc
+test -z "$LTCC" && LTCC=$CC
+test -z "$LTCFLAGS" && LTCFLAGS=$CFLAGS
+test -z "$LD" && LD=ld
+test -z "$ac_objext" && ac_objext=o
+
+_LT_CC_BASENAME([$compiler])
+
+# Only perform the check for file, if the check method requires it
+test -z "$MAGIC_CMD" && MAGIC_CMD=file
+case $deplibs_check_method in
+file_magic*)
+  if test "$file_magic_cmd" = '$MAGIC_CMD'; then
+    _LT_PATH_MAGIC
+  fi
+  ;;
+esac
+
+# Use C for the default configuration in the libtool script
+LT_SUPPORTED_TAG([CC])
+_LT_LANG_C_CONFIG
+_LT_LANG_DEFAULT_CONFIG
+_LT_CONFIG_COMMANDS
+])# _LT_SETUP
+
+
+# _LT_PROG_LTMAIN
+# ---------------
+# Note that this code is called both from `configure', and `config.status'
+# now that we use AC_CONFIG_COMMANDS to generate libtool.  Notably,
+# `config.status' has no value for ac_aux_dir unless we are using Automake,
+# so we pass a copy along to make sure it has a sensible value anyway.
+m4_defun([_LT_PROG_LTMAIN],
+[m4_ifdef([AC_REQUIRE_AUX_FILE], [AC_REQUIRE_AUX_FILE([ltmain.sh])])dnl
+_LT_CONFIG_LIBTOOL_INIT([ac_aux_dir='$ac_aux_dir'])
+ltmain="$ac_aux_dir/ltmain.sh"
+])# _LT_PROG_LTMAIN
+
+
+## ------------------------------------- ##
+## Accumulate code for creating libtool. ##
+## ------------------------------------- ##
+
+# So that we can recreate a full libtool script including additional
+# tags, we accumulate the chunks of code to send to AC_CONFIG_COMMANDS
+# in macros and then make a single call at the end using the `libtool'
+# label.
+
+
+# _LT_CONFIG_LIBTOOL_INIT([INIT-COMMANDS])
+# ----------------------------------------
+# Register INIT-COMMANDS to be passed to AC_CONFIG_COMMANDS later.
+m4_define([_LT_CONFIG_LIBTOOL_INIT],
+[m4_ifval([$1],
+          [m4_append([_LT_OUTPUT_LIBTOOL_INIT],
+                     [$1
+])])])
+
+# Initialize.
+m4_define([_LT_OUTPUT_LIBTOOL_INIT])
+
+
+# _LT_CONFIG_LIBTOOL([COMMANDS])
+# ------------------------------
+# Register COMMANDS to be passed to AC_CONFIG_COMMANDS later.
+m4_define([_LT_CONFIG_LIBTOOL],
+[m4_ifval([$1],
+          [m4_append([_LT_OUTPUT_LIBTOOL_COMMANDS],
+                     [$1
+])])])
+
+# Initialize.
+m4_define([_LT_OUTPUT_LIBTOOL_COMMANDS])
+
+
+# _LT_CONFIG_SAVE_COMMANDS([COMMANDS], [INIT_COMMANDS])
+# -----------------------------------------------------
+m4_defun([_LT_CONFIG_SAVE_COMMANDS],
+[_LT_CONFIG_LIBTOOL([$1])
+_LT_CONFIG_LIBTOOL_INIT([$2])
+])
+
+
+# _LT_FORMAT_COMMENT([COMMENT])
+# -----------------------------
+# Add leading comment marks to the start of each line, and a trailing
+# full-stop to the whole comment if one is not present already.
+m4_define([_LT_FORMAT_COMMENT],
+[m4_ifval([$1], [
+m4_bpatsubst([m4_bpatsubst([$1], [^ *], [# ])],
+              [['`$\]], [\\\&])]m4_bmatch([$1], [[!?.]$], [], [.])
+)])
+
+
+
+## ------------------------ ##
+## FIXME: Eliminate VARNAME ##
+## ------------------------ ##
+
+
+# _LT_DECL([CONFIGNAME], VARNAME, VALUE, [DESCRIPTION], [IS-TAGGED?])
+# -------------------------------------------------------------------
+# CONFIGNAME is the name given to the value in the libtool script.
+# VARNAME is the (base) name used in the configure script.
+# VALUE may be 0, 1 or 2 for a computed quote escaped value based on
+# VARNAME.  Any other value will be used directly.
+m4_define([_LT_DECL],
+[lt_if_append_uniq([lt_decl_varnames], [$2], [, ],
+    [lt_dict_add_subkey([lt_decl_dict], [$2], [libtool_name],
+	[m4_ifval([$1], [$1], [$2])])
+    lt_dict_add_subkey([lt_decl_dict], [$2], [value], [$3])
+    m4_ifval([$4],
+	[lt_dict_add_subkey([lt_decl_dict], [$2], [description], [$4])])
+    lt_dict_add_subkey([lt_decl_dict], [$2],
+	[tagged?], [m4_ifval([$5], [yes], [no])])])
+])
+
+
+# _LT_TAGDECL([CONFIGNAME], VARNAME, VALUE, [DESCRIPTION])
+# --------------------------------------------------------
+m4_define([_LT_TAGDECL], [_LT_DECL([$1], [$2], [$3], [$4], [yes])])
+
+
+# lt_decl_tag_varnames([SEPARATOR], [VARNAME1...])
+# ------------------------------------------------
+m4_define([lt_decl_tag_varnames],
+[_lt_decl_filter([tagged?], [yes], $@)])
+
+
+# _lt_decl_filter(SUBKEY, VALUE, [SEPARATOR], [VARNAME1..])
+# ---------------------------------------------------------
+m4_define([_lt_decl_filter],
+[m4_case([$#],
+  [0], [m4_fatal([$0: too few arguments: $#])],
+  [1], [m4_fatal([$0: too few arguments: $#: $1])],
+  [2], [lt_dict_filter([lt_decl_dict], [$1], [$2], [], lt_decl_varnames)],
+  [3], [lt_dict_filter([lt_decl_dict], [$1], [$2], [$3], lt_decl_varnames)],
+  [lt_dict_filter([lt_decl_dict], $@)])[]dnl
+])
+
+
+# lt_decl_quote_varnames([SEPARATOR], [VARNAME1...])
+# --------------------------------------------------
+m4_define([lt_decl_quote_varnames],
+[_lt_decl_filter([value], [1], $@)])
+
+
+# lt_decl_dquote_varnames([SEPARATOR], [VARNAME1...])
+# ---------------------------------------------------
+m4_define([lt_decl_dquote_varnames],
+[_lt_decl_filter([value], [2], $@)])
+
+
+# lt_decl_varnames_tagged([SEPARATOR], [VARNAME1...])
+# ---------------------------------------------------
+m4_define([lt_decl_varnames_tagged],
+[m4_assert([$# <= 2])dnl
+_$0(m4_quote(m4_default([$1], [[, ]])),
+    m4_ifval([$2], [[$2]], [m4_dquote(lt_decl_tag_varnames)]),
+    m4_split(m4_normalize(m4_quote(_LT_TAGS)), [ ]))])
+m4_define([_lt_decl_varnames_tagged],
+[m4_ifval([$3], [lt_combine([$1], [$2], [_], $3)])])
+
+
+# lt_decl_all_varnames([SEPARATOR], [VARNAME1...])
+# ------------------------------------------------
+m4_define([lt_decl_all_varnames],
+[_$0(m4_quote(m4_default([$1], [[, ]])),
+     m4_if([$2], [],
+	   m4_quote(lt_decl_varnames),
+	m4_quote(m4_shift($@))))[]dnl
+])
+m4_define([_lt_decl_all_varnames],
+[lt_join($@, lt_decl_varnames_tagged([$1],
+			lt_decl_tag_varnames([[, ]], m4_shift($@))))dnl
+])
+
+
+# _LT_CONFIG_STATUS_DECLARE([VARNAME])
+# ------------------------------------
+# Quote a variable value, and forward it to `config.status' so that its
+# declaration there will have the same value as in `configure'.  VARNAME
+# must have a single quote delimited value for this to work.
+m4_define([_LT_CONFIG_STATUS_DECLARE],
+[$1='`$ECHO "X$][$1" | $Xsed -e "$delay_single_quote_subst"`'])
+
+
+# _LT_CONFIG_STATUS_DECLARATIONS
+# ------------------------------
+# We delimit libtool config variables with single quotes, so when
+# we write them to config.status, we have to be sure to quote all
+# embedded single quotes properly.  In configure, this macro expands
+# each variable declared with _LT_DECL (and _LT_TAGDECL) into:
+#
+#    <var>='`$ECHO "X$<var>" | $Xsed -e "$delay_single_quote_subst"`'
+m4_defun([_LT_CONFIG_STATUS_DECLARATIONS],
+[m4_foreach([_lt_var], m4_quote(lt_decl_all_varnames),
+    [m4_n([_LT_CONFIG_STATUS_DECLARE(_lt_var)])])])
+
+
+# _LT_LIBTOOL_TAGS
+# ----------------
+# Output comment and list of tags supported by the script
+m4_defun([_LT_LIBTOOL_TAGS],
+[_LT_FORMAT_COMMENT([The names of the tagged configurations supported by this script])dnl
+available_tags="_LT_TAGS"dnl
+])
+
+
+# _LT_LIBTOOL_DECLARE(VARNAME, [TAG])
+# -----------------------------------
+# Extract the dictionary values for VARNAME (optionally with TAG) and
+# expand to a commented shell variable setting:
+#
+#    # Some comment about what VAR is for.
+#    visible_name=$lt_internal_name
+m4_define([_LT_LIBTOOL_DECLARE],
+[_LT_FORMAT_COMMENT(m4_quote(lt_dict_fetch([lt_decl_dict], [$1],
+					   [description])))[]dnl
+m4_pushdef([_libtool_name],
+    m4_quote(lt_dict_fetch([lt_decl_dict], [$1], [libtool_name])))[]dnl
+m4_case(m4_quote(lt_dict_fetch([lt_decl_dict], [$1], [value])),
+    [0], [_libtool_name=[$]$1],
+    [1], [_libtool_name=$lt_[]$1],
+    [2], [_libtool_name=$lt_[]$1],
+    [_libtool_name=lt_dict_fetch([lt_decl_dict], [$1], [value])])[]dnl
+m4_ifval([$2], [_$2])[]m4_popdef([_libtool_name])[]dnl
+])
+
+
+# _LT_LIBTOOL_CONFIG_VARS
+# -----------------------
+# Produce commented declarations of non-tagged libtool config variables
+# suitable for insertion in the LIBTOOL CONFIG section of the `libtool'
+# script.  Tagged libtool config variables (even for the LIBTOOL CONFIG
+# section) are produced by _LT_LIBTOOL_TAG_VARS.
+m4_defun([_LT_LIBTOOL_CONFIG_VARS],
+[m4_foreach([_lt_var],
+    m4_quote(_lt_decl_filter([tagged?], [no], [], lt_decl_varnames)),
+    [m4_n([_LT_LIBTOOL_DECLARE(_lt_var)])])])
+
+
+# _LT_LIBTOOL_TAG_VARS(TAG)
+# -------------------------
+m4_define([_LT_LIBTOOL_TAG_VARS],
+[m4_foreach([_lt_var], m4_quote(lt_decl_tag_varnames),
+    [m4_n([_LT_LIBTOOL_DECLARE(_lt_var, [$1])])])])
+
+
+# _LT_TAGVAR(VARNAME, [TAGNAME])
+# ------------------------------
+m4_define([_LT_TAGVAR], [m4_ifval([$2], [$1_$2], [$1])])
+
+
+# _LT_CONFIG_COMMANDS
+# -------------------
+# Send accumulated output to $CONFIG_STATUS.  Thanks to the lists of
+# variables for single and double quote escaping we saved from calls
+# to _LT_DECL, we can put quote escaped variables declarations
+# into `config.status', and then the shell code to quote escape them in
+# for loops in `config.status'.  Finally, any additional code accumulated
+# from calls to _LT_CONFIG_LIBTOOL_INIT is expanded.
+m4_defun([_LT_CONFIG_COMMANDS],
+[AC_PROVIDE_IFELSE([LT_OUTPUT],
+	dnl If the libtool generation code has been placed in $CONFIG_LT,
+	dnl instead of duplicating it all over again into config.status,
+	dnl then we will have config.status run $CONFIG_LT later, so it
+	dnl needs to know what name is stored there:
+        [AC_CONFIG_COMMANDS([libtool],
+            [$SHELL $CONFIG_LT || AS_EXIT(1)], [CONFIG_LT='$CONFIG_LT'])],
+    dnl If the libtool generation code is destined for config.status,
+    dnl expand the accumulated commands and init code now:
+    [AC_CONFIG_COMMANDS([libtool],
+        [_LT_OUTPUT_LIBTOOL_COMMANDS], [_LT_OUTPUT_LIBTOOL_COMMANDS_INIT])])
+])#_LT_CONFIG_COMMANDS
+
+
+# Initialize.
+m4_define([_LT_OUTPUT_LIBTOOL_COMMANDS_INIT],
+[
+
+# The HP-UX ksh and POSIX shell print the target directory to stdout
+# if CDPATH is set.
+(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
+
+sed_quote_subst='$sed_quote_subst'
+double_quote_subst='$double_quote_subst'
+delay_variable_subst='$delay_variable_subst'
+_LT_CONFIG_STATUS_DECLARATIONS
+LTCC='$LTCC'
+LTCFLAGS='$LTCFLAGS'
+compiler='$compiler_DEFAULT'
+
+# Quote evaled strings.
+for var in lt_decl_all_varnames([[ \
+]], lt_decl_quote_varnames); do
+    case \`eval \\\\\$ECHO "X\\\\\$\$var"\` in
+    *[[\\\\\\\`\\"\\\$]]*)
+      eval "lt_\$var=\\\\\\"\\\`\\\$ECHO \\"X\\\$\$var\\" | \\\$Xsed -e \\"\\\$sed_quote_subst\\"\\\`\\\\\\""
+      ;;
+    *)
+      eval "lt_\$var=\\\\\\"\\\$\$var\\\\\\""
+      ;;
+    esac
+done
+
+# Double-quote double-evaled strings.
+for var in lt_decl_all_varnames([[ \
+]], lt_decl_dquote_varnames); do
+    case \`eval \\\\\$ECHO "X\\\\\$\$var"\` in
+    *[[\\\\\\\`\\"\\\$]]*)
+      eval "lt_\$var=\\\\\\"\\\`\\\$ECHO \\"X\\\$\$var\\" | \\\$Xsed -e \\"\\\$double_quote_subst\\" -e \\"\\\$sed_quote_subst\\" -e \\"\\\$delay_variable_subst\\"\\\`\\\\\\""
+      ;;
+    *)
+      eval "lt_\$var=\\\\\\"\\\$\$var\\\\\\""
+      ;;
+    esac
+done
+
+# Fix-up fallback echo if it was mangled by the above quoting rules.
+case \$lt_ECHO in
+*'\\\[$]0 --fallback-echo"')dnl "
+  lt_ECHO=\`\$ECHO "X\$lt_ECHO" | \$Xsed -e 's/\\\\\\\\\\\\\\\[$]0 --fallback-echo"\[$]/\[$]0 --fallback-echo"/'\`
+  ;;
+esac
+
+_LT_OUTPUT_LIBTOOL_INIT
+])
+
+
+# LT_OUTPUT
+# ---------
+# This macro allows early generation of the libtool script (before
+# AC_OUTPUT is called), incase it is used in configure for compilation
+# tests.
+AC_DEFUN([LT_OUTPUT],
+[: ${CONFIG_LT=./config.lt}
+AC_MSG_NOTICE([creating $CONFIG_LT])
+cat >"$CONFIG_LT" <<_LTEOF
+#! $SHELL
+# Generated by $as_me.
+# Run this file to recreate a libtool stub with the current configuration.
+
+lt_cl_silent=false
+SHELL=\${CONFIG_SHELL-$SHELL}
+_LTEOF
+
+cat >>"$CONFIG_LT" <<\_LTEOF
+AS_SHELL_SANITIZE
+_AS_PREPARE
+
+exec AS_MESSAGE_FD>&1
+exec AS_MESSAGE_LOG_FD>>config.log
+{
+  echo
+  AS_BOX([Running $as_me.])
+} >&AS_MESSAGE_LOG_FD
+
+lt_cl_help="\
+\`$as_me' creates a local libtool stub from the current configuration,
+for use in further configure time tests before the real libtool is
+generated.
+
+Usage: $[0] [[OPTIONS]]
+
+  -h, --help      print this help, then exit
+  -V, --version   print version number, then exit
+  -q, --quiet     do not print progress messages
+  -d, --debug     don't remove temporary files
+
+Report bugs to <bug-libtool at gnu.org>."
+
+lt_cl_version="\
+m4_ifset([AC_PACKAGE_NAME], [AC_PACKAGE_NAME ])config.lt[]dnl
+m4_ifset([AC_PACKAGE_VERSION], [ AC_PACKAGE_VERSION])
+configured by $[0], generated by m4_PACKAGE_STRING.
+
+Copyright (C) 2008 Free Software Foundation, Inc.
+This config.lt script is free software; the Free Software Foundation
+gives unlimited permision to copy, distribute and modify it."
+
+while test $[#] != 0
+do
+  case $[1] in
+    --version | --v* | -V )
+      echo "$lt_cl_version"; exit 0 ;;
+    --help | --h* | -h )
+      echo "$lt_cl_help"; exit 0 ;;
+    --debug | --d* | -d )
+      debug=: ;;
+    --quiet | --q* | --silent | --s* | -q )
+      lt_cl_silent=: ;;
+
+    -*) AC_MSG_ERROR([unrecognized option: $[1]
+Try \`$[0] --help' for more information.]) ;;
+
+    *) AC_MSG_ERROR([unrecognized argument: $[1]
+Try \`$[0] --help' for more information.]) ;;
+  esac
+  shift
+done
+
+if $lt_cl_silent; then
+  exec AS_MESSAGE_FD>/dev/null
+fi
+_LTEOF
+
+cat >>"$CONFIG_LT" <<_LTEOF
+_LT_OUTPUT_LIBTOOL_COMMANDS_INIT
+_LTEOF
+
+cat >>"$CONFIG_LT" <<\_LTEOF
+AC_MSG_NOTICE([creating $ofile])
+_LT_OUTPUT_LIBTOOL_COMMANDS
+AS_EXIT(0)
+_LTEOF
+chmod +x "$CONFIG_LT"
+
+# configure is writing to config.log, but config.lt does its own redirection,
+# appending to config.log, which fails on DOS, as config.log is still kept
+# open by configure.  Here we exec the FD to /dev/null, effectively closing
+# config.log, so it can be properly (re)opened and appended to by config.lt.
+if test "$no_create" != yes; then
+  lt_cl_success=:
+  test "$silent" = yes &&
+    lt_config_lt_args="$lt_config_lt_args --quiet"
+  exec AS_MESSAGE_LOG_FD>/dev/null
+  $SHELL "$CONFIG_LT" $lt_config_lt_args || lt_cl_success=false
+  exec AS_MESSAGE_LOG_FD>>config.log
+  $lt_cl_success || AS_EXIT(1)
+fi
+])# LT_OUTPUT
+
+
+# _LT_CONFIG(TAG)
+# ---------------
+# If TAG is the built-in tag, create an initial libtool script with a
+# default configuration from the untagged config vars.  Otherwise add code
+# to config.status for appending the configuration named by TAG from the
+# matching tagged config vars.
+m4_defun([_LT_CONFIG],
+[m4_require([_LT_FILEUTILS_DEFAULTS])dnl
+_LT_CONFIG_SAVE_COMMANDS([
+  m4_define([_LT_TAG], m4_if([$1], [], [C], [$1]))dnl
+  m4_if(_LT_TAG, [C], [
+    # See if we are running on zsh, and set the options which allow our
+    # commands through without removal of \ escapes.
+    if test -n "${ZSH_VERSION+set}" ; then
+      setopt NO_GLOB_SUBST
+    fi
+
+    cfgfile="${ofile}T"
+    trap "$RM \"$cfgfile\"; exit 1" 1 2 15
+    $RM "$cfgfile"
+
+    cat <<_LT_EOF >> "$cfgfile"
+#! $SHELL
+
+# `$ECHO "$ofile" | sed 's%^.*/%%'` - Provide generalized library-building support services.
+# Generated automatically by $as_me ($PACKAGE$TIMESTAMP) $VERSION
+# Libtool was configured on host `(hostname || uname -n) 2>/dev/null | sed 1q`:
+# NOTE: Changes made to this file will be lost: look at ltmain.sh.
+#
+_LT_COPYING
+_LT_LIBTOOL_TAGS
+
+# ### BEGIN LIBTOOL CONFIG
+_LT_LIBTOOL_CONFIG_VARS
+_LT_LIBTOOL_TAG_VARS
+# ### END LIBTOOL CONFIG
+
+_LT_EOF
+
+  case $host_os in
+  aix3*)
+    cat <<\_LT_EOF >> "$cfgfile"
+# AIX sometimes has problems with the GCC collect2 program.  For some
+# reason, if we set the COLLECT_NAMES environment variable, the problems
+# vanish in a puff of smoke.
+if test "X${COLLECT_NAMES+set}" != Xset; then
+  COLLECT_NAMES=
+  export COLLECT_NAMES
+fi
+_LT_EOF
+    ;;
+  esac
+
+  _LT_PROG_LTMAIN
+
+  # We use sed instead of cat because bash on DJGPP gets confused if
+  # if finds mixed CR/LF and LF-only lines.  Since sed operates in
+  # text mode, it properly converts lines to CR/LF.  This bash problem
+  # is reportedly fixed, but why not run on old versions too?
+  sed '/^# Generated shell functions inserted here/q' "$ltmain" >> "$cfgfile" \
+    || (rm -f "$cfgfile"; exit 1)
+
+  _LT_PROG_XSI_SHELLFNS
+
+  sed -n '/^# Generated shell functions inserted here/,$p' "$ltmain" >> "$cfgfile" \
+    || (rm -f "$cfgfile"; exit 1)
+
+  mv -f "$cfgfile" "$ofile" ||
+    (rm -f "$ofile" && cp "$cfgfile" "$ofile" && rm -f "$cfgfile")
+  chmod +x "$ofile"
+],
+[cat <<_LT_EOF >> "$ofile"
+
+dnl Unfortunately we have to use $1 here, since _LT_TAG is not expanded
+dnl in a comment (ie after a #).
+# ### BEGIN LIBTOOL TAG CONFIG: $1
+_LT_LIBTOOL_TAG_VARS(_LT_TAG)
+# ### END LIBTOOL TAG CONFIG: $1
+_LT_EOF
+])dnl /m4_if
+],
+[m4_if([$1], [], [
+    PACKAGE='$PACKAGE'
+    VERSION='$VERSION'
+    TIMESTAMP='$TIMESTAMP'
+    RM='$RM'
+    ofile='$ofile'], [])
+])dnl /_LT_CONFIG_SAVE_COMMANDS
+])# _LT_CONFIG
+
+
+# LT_SUPPORTED_TAG(TAG)
+# ---------------------
+# Trace this macro to discover what tags are supported by the libtool
+# --tag option, using:
+#    autoconf --trace 'LT_SUPPORTED_TAG:$1'
+AC_DEFUN([LT_SUPPORTED_TAG], [])
+
+
+# C support is built-in for now
+m4_define([_LT_LANG_C_enabled], [])
+m4_define([_LT_TAGS], [])
+
+
+# LT_LANG(LANG)
+# -------------
+# Enable libtool support for the given language if not already enabled.
+AC_DEFUN([LT_LANG],
+[AC_BEFORE([$0], [LT_OUTPUT])dnl
+m4_case([$1],
+  [C],			[_LT_LANG(C)],
+  [C++],		[_LT_LANG(CXX)],
+  [Java],		[_LT_LANG(GCJ)],
+  [Fortran 77],		[_LT_LANG(F77)],
+  [Fortran],		[_LT_LANG(FC)],
+  [Windows Resource],	[_LT_LANG(RC)],
+  [m4_ifdef([_LT_LANG_]$1[_CONFIG],
+    [_LT_LANG($1)],
+    [m4_fatal([$0: unsupported language: "$1"])])])dnl
+])# LT_LANG
+
+
+# _LT_LANG(LANGNAME)
+# ------------------
+m4_defun([_LT_LANG],
+[m4_ifdef([_LT_LANG_]$1[_enabled], [],
+  [LT_SUPPORTED_TAG([$1])dnl
+  m4_append([_LT_TAGS], [$1 ])dnl
+  m4_define([_LT_LANG_]$1[_enabled], [])dnl
+  _LT_LANG_$1_CONFIG($1)])dnl
+])# _LT_LANG
+
+
+# _LT_LANG_DEFAULT_CONFIG
+# -----------------------
+m4_defun([_LT_LANG_DEFAULT_CONFIG],
+[AC_PROVIDE_IFELSE([AC_PROG_CXX],
+  [LT_LANG(CXX)],
+  [m4_define([AC_PROG_CXX], defn([AC_PROG_CXX])[LT_LANG(CXX)])])
+
+AC_PROVIDE_IFELSE([AC_PROG_F77],
+  [LT_LANG(F77)],
+  [m4_define([AC_PROG_F77], defn([AC_PROG_F77])[LT_LANG(F77)])])
+
+AC_PROVIDE_IFELSE([AC_PROG_FC],
+  [LT_LANG(FC)],
+  [m4_define([AC_PROG_FC], defn([AC_PROG_FC])[LT_LANG(FC)])])
+
+dnl The call to [A][M_PROG_GCJ] is quoted like that to stop aclocal
+dnl pulling things in needlessly.
+AC_PROVIDE_IFELSE([AC_PROG_GCJ],
+  [LT_LANG(GCJ)],
+  [AC_PROVIDE_IFELSE([A][M_PROG_GCJ],
+    [LT_LANG(GCJ)],
+    [AC_PROVIDE_IFELSE([LT_PROG_GCJ],
+      [LT_LANG(GCJ)],
+      [m4_ifdef([AC_PROG_GCJ],
+	[m4_define([AC_PROG_GCJ], defn([AC_PROG_GCJ])[LT_LANG(GCJ)])])
+       m4_ifdef([A][M_PROG_GCJ],
+	[m4_define([A][M_PROG_GCJ], defn([A][M_PROG_GCJ])[LT_LANG(GCJ)])])
+       m4_ifdef([LT_PROG_GCJ],
+	[m4_define([LT_PROG_GCJ], defn([LT_PROG_GCJ])[LT_LANG(GCJ)])])])])])
+
+AC_PROVIDE_IFELSE([LT_PROG_RC],
+  [LT_LANG(RC)],
+  [m4_define([LT_PROG_RC], defn([LT_PROG_RC])[LT_LANG(RC)])])
+])# _LT_LANG_DEFAULT_CONFIG
+
+# Obsolete macros:
+AU_DEFUN([AC_LIBTOOL_CXX], [LT_LANG(C++)])
+AU_DEFUN([AC_LIBTOOL_F77], [LT_LANG(Fortran 77)])
+AU_DEFUN([AC_LIBTOOL_FC], [LT_LANG(Fortran)])
+AU_DEFUN([AC_LIBTOOL_GCJ], [LT_LANG(Java)])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AC_LIBTOOL_CXX], [])
+dnl AC_DEFUN([AC_LIBTOOL_F77], [])
+dnl AC_DEFUN([AC_LIBTOOL_FC], [])
+dnl AC_DEFUN([AC_LIBTOOL_GCJ], [])
+
+
+# _LT_TAG_COMPILER
+# ----------------
+m4_defun([_LT_TAG_COMPILER],
+[AC_REQUIRE([AC_PROG_CC])dnl
+
+_LT_DECL([LTCC], [CC], [1], [A C compiler])dnl
+_LT_DECL([LTCFLAGS], [CFLAGS], [1], [LTCC compiler flags])dnl
+_LT_TAGDECL([CC], [compiler], [1], [A language specific compiler])dnl
+_LT_TAGDECL([with_gcc], [GCC], [0], [Is the compiler the GNU compiler?])dnl
+
+# If no C compiler was specified, use CC.
+LTCC=${LTCC-"$CC"}
+
+# If no C compiler flags were specified, use CFLAGS.
+LTCFLAGS=${LTCFLAGS-"$CFLAGS"}
+
+# Allow CC to be a program name with arguments.
+compiler=$CC
+])# _LT_TAG_COMPILER
+
+
+# _LT_COMPILER_BOILERPLATE
+# ------------------------
+# Check for compiler boilerplate output or warnings with
+# the simple compiler test code.
+m4_defun([_LT_COMPILER_BOILERPLATE],
+[m4_require([_LT_DECL_SED])dnl
+ac_outfile=conftest.$ac_objext
+echo "$lt_simple_compile_test_code" >conftest.$ac_ext
+eval "$ac_compile" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err
+_lt_compiler_boilerplate=`cat conftest.err`
+$RM conftest*
+])# _LT_COMPILER_BOILERPLATE
+
+
+# _LT_LINKER_BOILERPLATE
+# ----------------------
+# Check for linker boilerplate output or warnings with
+# the simple link test code.
+m4_defun([_LT_LINKER_BOILERPLATE],
+[m4_require([_LT_DECL_SED])dnl
+ac_outfile=conftest.$ac_objext
+echo "$lt_simple_link_test_code" >conftest.$ac_ext
+eval "$ac_link" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err
+_lt_linker_boilerplate=`cat conftest.err`
+$RM -r conftest*
+])# _LT_LINKER_BOILERPLATE
+
+# _LT_REQUIRED_DARWIN_CHECKS
+# -------------------------
+m4_defun_once([_LT_REQUIRED_DARWIN_CHECKS],[
+  case $host_os in
+    rhapsody* | darwin*)
+    AC_CHECK_TOOL([DSYMUTIL], [dsymutil], [:])
+    AC_CHECK_TOOL([NMEDIT], [nmedit], [:])
+    AC_CHECK_TOOL([LIPO], [lipo], [:])
+    AC_CHECK_TOOL([OTOOL], [otool], [:])
+    AC_CHECK_TOOL([OTOOL64], [otool64], [:])
+    _LT_DECL([], [DSYMUTIL], [1],
+      [Tool to manipulate archived DWARF debug symbol files on Mac OS X])
+    _LT_DECL([], [NMEDIT], [1],
+      [Tool to change global to local symbols on Mac OS X])
+    _LT_DECL([], [LIPO], [1],
+      [Tool to manipulate fat objects and archives on Mac OS X])
+    _LT_DECL([], [OTOOL], [1],
+      [ldd/readelf like tool for Mach-O binaries on Mac OS X])
+    _LT_DECL([], [OTOOL64], [1],
+      [ldd/readelf like tool for 64 bit Mach-O binaries on Mac OS X 10.4])
+
+    AC_CACHE_CHECK([for -single_module linker flag],[lt_cv_apple_cc_single_mod],
+      [lt_cv_apple_cc_single_mod=no
+      if test -z "${LT_MULTI_MODULE}"; then
+	# By default we will add the -single_module flag. You can override
+	# by either setting the environment variable LT_MULTI_MODULE
+	# non-empty at configure time, or by adding -multi_module to the
+	# link flags.
+	rm -rf libconftest.dylib*
+	echo "int foo(void){return 1;}" > conftest.c
+	echo "$LTCC $LTCFLAGS $LDFLAGS -o libconftest.dylib \
+-dynamiclib -Wl,-single_module conftest.c" >&AS_MESSAGE_LOG_FD
+	$LTCC $LTCFLAGS $LDFLAGS -o libconftest.dylib \
+	  -dynamiclib -Wl,-single_module conftest.c 2>conftest.err
+        _lt_result=$?
+	if test -f libconftest.dylib && test ! -s conftest.err && test $_lt_result = 0; then
+	  lt_cv_apple_cc_single_mod=yes
+	else
+	  cat conftest.err >&AS_MESSAGE_LOG_FD
+	fi
+	rm -rf libconftest.dylib*
+	rm -f conftest.*
+      fi])
+    AC_CACHE_CHECK([for -exported_symbols_list linker flag],
+      [lt_cv_ld_exported_symbols_list],
+      [lt_cv_ld_exported_symbols_list=no
+      save_LDFLAGS=$LDFLAGS
+      echo "_main" > conftest.sym
+      LDFLAGS="$LDFLAGS -Wl,-exported_symbols_list,conftest.sym"
+      AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])],
+	[lt_cv_ld_exported_symbols_list=yes],
+	[lt_cv_ld_exported_symbols_list=no])
+	LDFLAGS="$save_LDFLAGS"
+    ])
+    case $host_os in
+    rhapsody* | darwin1.[[012]])
+      _lt_dar_allow_undefined='${wl}-undefined ${wl}suppress' ;;
+    darwin1.*)
+      _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' ;;
+    darwin*) # darwin 5.x on
+      # if running on 10.5 or later, the deployment target defaults
+      # to the OS version, if on x86, and 10.4, the deployment
+      # target defaults to 10.4. Don't you love it?
+      case ${MACOSX_DEPLOYMENT_TARGET-10.0},$host in
+	10.0,*86*-darwin8*|10.0,*-darwin[[91]]*)
+	  _lt_dar_allow_undefined='${wl}-undefined ${wl}dynamic_lookup' ;;
+	10.[[012]]*)
+	  _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' ;;
+	10.*)
+	  _lt_dar_allow_undefined='${wl}-undefined ${wl}dynamic_lookup' ;;
+      esac
+    ;;
+  esac
+    if test "$lt_cv_apple_cc_single_mod" = "yes"; then
+      _lt_dar_single_mod='$single_module'
+    fi
+    if test "$lt_cv_ld_exported_symbols_list" = "yes"; then
+      _lt_dar_export_syms=' ${wl}-exported_symbols_list,$output_objdir/${libname}-symbols.expsym'
+    else
+      _lt_dar_export_syms='~$NMEDIT -s $output_objdir/${libname}-symbols.expsym ${lib}'
+    fi
+    if test "$DSYMUTIL" != ":"; then
+      _lt_dsymutil='~$DSYMUTIL $lib || :'
+    else
+      _lt_dsymutil=
+    fi
+    ;;
+  esac
+])
+
+
+# _LT_DARWIN_LINKER_FEATURES
+# --------------------------
+# Checks for linker and compiler features on darwin
+m4_defun([_LT_DARWIN_LINKER_FEATURES],
+[
+  m4_require([_LT_REQUIRED_DARWIN_CHECKS])
+  _LT_TAGVAR(archive_cmds_need_lc, $1)=no
+  _LT_TAGVAR(hardcode_direct, $1)=no
+  _LT_TAGVAR(hardcode_automatic, $1)=yes
+  _LT_TAGVAR(hardcode_shlibpath_var, $1)=unsupported
+  _LT_TAGVAR(whole_archive_flag_spec, $1)=''
+  _LT_TAGVAR(link_all_deplibs, $1)=yes
+  _LT_TAGVAR(allow_undefined_flag, $1)="$_lt_dar_allow_undefined"
+  case $cc_basename in
+     ifort*) _lt_dar_can_shared=yes ;;
+     *) _lt_dar_can_shared=$GCC ;;
+  esac
+  if test "$_lt_dar_can_shared" = "yes"; then
+    output_verbose_link_cmd=echo
+    _LT_TAGVAR(archive_cmds, $1)="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}"
+    _LT_TAGVAR(module_cmds, $1)="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}"
+    _LT_TAGVAR(archive_expsym_cmds, $1)="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}"
+    _LT_TAGVAR(module_expsym_cmds, $1)="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}"
+    m4_if([$1], [CXX],
+[   if test "$lt_cv_apple_cc_single_mod" != "yes"; then
+      _LT_TAGVAR(archive_cmds, $1)="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dsymutil}"
+      _LT_TAGVAR(archive_expsym_cmds, $1)="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dar_export_syms}${_lt_dsymutil}"
+    fi
+],[])
+  else
+  _LT_TAGVAR(ld_shlibs, $1)=no
+  fi
+])
+
+# _LT_SYS_MODULE_PATH_AIX
+# -----------------------
+# Links a minimal program and checks the executable
+# for the system default hardcoded library path. In most cases,
+# this is /usr/lib:/lib, but when the MPI compilers are used
+# the location of the communication and MPI libs are included too.
+# If we don't find anything, use the default library path according
+# to the aix ld manual.
+m4_defun([_LT_SYS_MODULE_PATH_AIX],
+[m4_require([_LT_DECL_SED])dnl
+AC_LINK_IFELSE(AC_LANG_PROGRAM,[
+lt_aix_libpath_sed='
+    /Import File Strings/,/^$/ {
+	/^0/ {
+	    s/^0  *\(.*\)$/\1/
+	    p
+	}
+    }'
+aix_libpath=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"`
+# Check for a 64-bit object if we didn't find anything.
+if test -z "$aix_libpath"; then
+  aix_libpath=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"`
+fi],[])
+if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi
+])# _LT_SYS_MODULE_PATH_AIX
+
+
+# _LT_SHELL_INIT(ARG)
+# -------------------
+m4_define([_LT_SHELL_INIT],
+[ifdef([AC_DIVERSION_NOTICE],
+	     [AC_DIVERT_PUSH(AC_DIVERSION_NOTICE)],
+	 [AC_DIVERT_PUSH(NOTICE)])
+$1
+AC_DIVERT_POP
+])# _LT_SHELL_INIT
+
+
+# _LT_PROG_ECHO_BACKSLASH
+# -----------------------
+# Add some code to the start of the generated configure script which
+# will find an echo command which doesn't interpret backslashes.
+m4_defun([_LT_PROG_ECHO_BACKSLASH],
+[_LT_SHELL_INIT([
+# Check that we are running under the correct shell.
+SHELL=${CONFIG_SHELL-/bin/sh}
+
+case X$lt_ECHO in
+X*--fallback-echo)
+  # Remove one level of quotation (which was required for Make).
+  ECHO=`echo "$lt_ECHO" | sed 's,\\\\\[$]\\[$]0,'[$]0','`
+  ;;
+esac
+
+ECHO=${lt_ECHO-echo}
+if test "X[$]1" = X--no-reexec; then
+  # Discard the --no-reexec flag, and continue.
+  shift
+elif test "X[$]1" = X--fallback-echo; then
+  # Avoid inline document here, it may be left over
+  :
+elif test "X`{ $ECHO '\t'; } 2>/dev/null`" = 'X\t' ; then
+  # Yippee, $ECHO works!
+  :
+else
+  # Restart under the correct shell.
+  exec $SHELL "[$]0" --no-reexec ${1+"[$]@"}
+fi
+
+if test "X[$]1" = X--fallback-echo; then
+  # used as fallback echo
+  shift
+  cat <<_LT_EOF
+[$]*
+_LT_EOF
+  exit 0
+fi
+
+# The HP-UX ksh and POSIX shell print the target directory to stdout
+# if CDPATH is set.
+(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
+
+if test -z "$lt_ECHO"; then
+  if test "X${echo_test_string+set}" != Xset; then
+    # find a string as large as possible, as long as the shell can cope with it
+    for cmd in 'sed 50q "[$]0"' 'sed 20q "[$]0"' 'sed 10q "[$]0"' 'sed 2q "[$]0"' 'echo test'; do
+      # expected sizes: less than 2Kb, 1Kb, 512 bytes, 16 bytes, ...
+      if { echo_test_string=`eval $cmd`; } 2>/dev/null &&
+	 { test "X$echo_test_string" = "X$echo_test_string"; } 2>/dev/null
+      then
+        break
+      fi
+    done
+  fi
+
+  if test "X`{ $ECHO '\t'; } 2>/dev/null`" = 'X\t' &&
+     echo_testing_string=`{ $ECHO "$echo_test_string"; } 2>/dev/null` &&
+     test "X$echo_testing_string" = "X$echo_test_string"; then
+    :
+  else
+    # The Solaris, AIX, and Digital Unix default echo programs unquote
+    # backslashes.  This makes it impossible to quote backslashes using
+    #   echo "$something" | sed 's/\\/\\\\/g'
+    #
+    # So, first we look for a working echo in the user's PATH.
+
+    lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
+    for dir in $PATH /usr/ucb; do
+      IFS="$lt_save_ifs"
+      if (test -f $dir/echo || test -f $dir/echo$ac_exeext) &&
+         test "X`($dir/echo '\t') 2>/dev/null`" = 'X\t' &&
+         echo_testing_string=`($dir/echo "$echo_test_string") 2>/dev/null` &&
+         test "X$echo_testing_string" = "X$echo_test_string"; then
+        ECHO="$dir/echo"
+        break
+      fi
+    done
+    IFS="$lt_save_ifs"
+
+    if test "X$ECHO" = Xecho; then
+      # We didn't find a better echo, so look for alternatives.
+      if test "X`{ print -r '\t'; } 2>/dev/null`" = 'X\t' &&
+         echo_testing_string=`{ print -r "$echo_test_string"; } 2>/dev/null` &&
+         test "X$echo_testing_string" = "X$echo_test_string"; then
+        # This shell has a builtin print -r that does the trick.
+        ECHO='print -r'
+      elif { test -f /bin/ksh || test -f /bin/ksh$ac_exeext; } &&
+	   test "X$CONFIG_SHELL" != X/bin/ksh; then
+        # If we have ksh, try running configure again with it.
+        ORIGINAL_CONFIG_SHELL=${CONFIG_SHELL-/bin/sh}
+        export ORIGINAL_CONFIG_SHELL
+        CONFIG_SHELL=/bin/ksh
+        export CONFIG_SHELL
+        exec $CONFIG_SHELL "[$]0" --no-reexec ${1+"[$]@"}
+      else
+        # Try using printf.
+        ECHO='printf %s\n'
+        if test "X`{ $ECHO '\t'; } 2>/dev/null`" = 'X\t' &&
+	   echo_testing_string=`{ $ECHO "$echo_test_string"; } 2>/dev/null` &&
+	   test "X$echo_testing_string" = "X$echo_test_string"; then
+	  # Cool, printf works
+	  :
+        elif echo_testing_string=`($ORIGINAL_CONFIG_SHELL "[$]0" --fallback-echo '\t') 2>/dev/null` &&
+	     test "X$echo_testing_string" = 'X\t' &&
+	     echo_testing_string=`($ORIGINAL_CONFIG_SHELL "[$]0" --fallback-echo "$echo_test_string") 2>/dev/null` &&
+	     test "X$echo_testing_string" = "X$echo_test_string"; then
+	  CONFIG_SHELL=$ORIGINAL_CONFIG_SHELL
+	  export CONFIG_SHELL
+	  SHELL="$CONFIG_SHELL"
+	  export SHELL
+	  ECHO="$CONFIG_SHELL [$]0 --fallback-echo"
+        elif echo_testing_string=`($CONFIG_SHELL "[$]0" --fallback-echo '\t') 2>/dev/null` &&
+	     test "X$echo_testing_string" = 'X\t' &&
+	     echo_testing_string=`($CONFIG_SHELL "[$]0" --fallback-echo "$echo_test_string") 2>/dev/null` &&
+	     test "X$echo_testing_string" = "X$echo_test_string"; then
+	  ECHO="$CONFIG_SHELL [$]0 --fallback-echo"
+        else
+	  # maybe with a smaller string...
+	  prev=:
+
+	  for cmd in 'echo test' 'sed 2q "[$]0"' 'sed 10q "[$]0"' 'sed 20q "[$]0"' 'sed 50q "[$]0"'; do
+	    if { test "X$echo_test_string" = "X`eval $cmd`"; } 2>/dev/null
+	    then
+	      break
+	    fi
+	    prev="$cmd"
+	  done
+
+	  if test "$prev" != 'sed 50q "[$]0"'; then
+	    echo_test_string=`eval $prev`
+	    export echo_test_string
+	    exec ${ORIGINAL_CONFIG_SHELL-${CONFIG_SHELL-/bin/sh}} "[$]0" ${1+"[$]@"}
+	  else
+	    # Oops.  We lost completely, so just stick with echo.
+	    ECHO=echo
+	  fi
+        fi
+      fi
+    fi
+  fi
+fi
+
+# Copy echo and quote the copy suitably for passing to libtool from
+# the Makefile, instead of quoting the original, which is used later.
+lt_ECHO=$ECHO
+if test "X$lt_ECHO" = "X$CONFIG_SHELL [$]0 --fallback-echo"; then
+   lt_ECHO="$CONFIG_SHELL \\\$\[$]0 --fallback-echo"
+fi
+
+AC_SUBST(lt_ECHO)
+])
+_LT_DECL([], [SHELL], [1], [Shell to use when invoking shell scripts])
+_LT_DECL([], [ECHO], [1],
+    [An echo program that does not interpret backslashes])
+])# _LT_PROG_ECHO_BACKSLASH
+
+
+# _LT_ENABLE_LOCK
+# ---------------
+m4_defun([_LT_ENABLE_LOCK],
+[AC_ARG_ENABLE([libtool-lock],
+  [AS_HELP_STRING([--disable-libtool-lock],
+    [avoid locking (might break parallel builds)])])
+test "x$enable_libtool_lock" != xno && enable_libtool_lock=yes
+
+# Some flags need to be propagated to the compiler or linker for good
+# libtool support.
+case $host in
+ia64-*-hpux*)
+  # Find out which ABI we are using.
+  echo 'int i;' > conftest.$ac_ext
+  if AC_TRY_EVAL(ac_compile); then
+    case `/usr/bin/file conftest.$ac_objext` in
+      *ELF-32*)
+	HPUX_IA64_MODE="32"
+	;;
+      *ELF-64*)
+	HPUX_IA64_MODE="64"
+	;;
+    esac
+  fi
+  rm -rf conftest*
+  ;;
+*-*-irix6*)
+  # Find out which ABI we are using.
+  echo '[#]line __oline__ "configure"' > conftest.$ac_ext
+  if AC_TRY_EVAL(ac_compile); then
+    if test "$lt_cv_prog_gnu_ld" = yes; then
+      case `/usr/bin/file conftest.$ac_objext` in
+	*32-bit*)
+	  LD="${LD-ld} -melf32bsmip"
+	  ;;
+	*N32*)
+	  LD="${LD-ld} -melf32bmipn32"
+	  ;;
+	*64-bit*)
+	  LD="${LD-ld} -melf64bmip"
+	;;
+      esac
+    else
+      case `/usr/bin/file conftest.$ac_objext` in
+	*32-bit*)
+	  LD="${LD-ld} -32"
+	  ;;
+	*N32*)
+	  LD="${LD-ld} -n32"
+	  ;;
+	*64-bit*)
+	  LD="${LD-ld} -64"
+	  ;;
+      esac
+    fi
+  fi
+  rm -rf conftest*
+  ;;
+
+x86_64-*kfreebsd*-gnu|x86_64-*linux*|ppc*-*linux*|powerpc*-*linux*| \
+s390*-*linux*|s390*-*tpf*|sparc*-*linux*)
+  # Find out which ABI we are using.
+  echo 'int i;' > conftest.$ac_ext
+  if AC_TRY_EVAL(ac_compile); then
+    case `/usr/bin/file conftest.o` in
+      *32-bit*)
+	case $host in
+	  x86_64-*kfreebsd*-gnu)
+	    LD="${LD-ld} -m elf_i386_fbsd"
+	    ;;
+	  x86_64-*linux*)
+	    LD="${LD-ld} -m elf_i386"
+	    ;;
+	  ppc64-*linux*|powerpc64-*linux*)
+	    LD="${LD-ld} -m elf32ppclinux"
+	    ;;
+	  s390x-*linux*)
+	    LD="${LD-ld} -m elf_s390"
+	    ;;
+	  sparc64-*linux*)
+	    LD="${LD-ld} -m elf32_sparc"
+	    ;;
+	esac
+	;;
+      *64-bit*)
+	case $host in
+	  x86_64-*kfreebsd*-gnu)
+	    LD="${LD-ld} -m elf_x86_64_fbsd"
+	    ;;
+	  x86_64-*linux*)
+	    LD="${LD-ld} -m elf_x86_64"
+	    ;;
+	  ppc*-*linux*|powerpc*-*linux*)
+	    LD="${LD-ld} -m elf64ppc"
+	    ;;
+	  s390*-*linux*|s390*-*tpf*)
+	    LD="${LD-ld} -m elf64_s390"
+	    ;;
+	  sparc*-*linux*)
+	    LD="${LD-ld} -m elf64_sparc"
+	    ;;
+	esac
+	;;
+    esac
+  fi
+  rm -rf conftest*
+  ;;
+
+*-*-sco3.2v5*)
+  # On SCO OpenServer 5, we need -belf to get full-featured binaries.
+  SAVE_CFLAGS="$CFLAGS"
+  CFLAGS="$CFLAGS -belf"
+  AC_CACHE_CHECK([whether the C compiler needs -belf], lt_cv_cc_needs_belf,
+    [AC_LANG_PUSH(C)
+     AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],[[]])],[lt_cv_cc_needs_belf=yes],[lt_cv_cc_needs_belf=no])
+     AC_LANG_POP])
+  if test x"$lt_cv_cc_needs_belf" != x"yes"; then
+    # this is probably gcc 2.8.0, egcs 1.0 or newer; no need for -belf
+    CFLAGS="$SAVE_CFLAGS"
+  fi
+  ;;
+sparc*-*solaris*)
+  # Find out which ABI we are using.
+  echo 'int i;' > conftest.$ac_ext
+  if AC_TRY_EVAL(ac_compile); then
+    case `/usr/bin/file conftest.o` in
+    *64-bit*)
+      case $lt_cv_prog_gnu_ld in
+      yes*) LD="${LD-ld} -m elf64_sparc" ;;
+      *)
+	if ${LD-ld} -64 -r -o conftest2.o conftest.o >/dev/null 2>&1; then
+	  LD="${LD-ld} -64"
+	fi
+	;;
+      esac
+      ;;
+    esac
+  fi
+  rm -rf conftest*
+  ;;
+esac
+
+need_locks="$enable_libtool_lock"
+])# _LT_ENABLE_LOCK
+
+
+# _LT_CMD_OLD_ARCHIVE
+# -------------------
+m4_defun([_LT_CMD_OLD_ARCHIVE],
+[AC_CHECK_TOOL(AR, ar, false)
+test -z "$AR" && AR=ar
+test -z "$AR_FLAGS" && AR_FLAGS=cru
+_LT_DECL([], [AR], [1], [The archiver])
+_LT_DECL([], [AR_FLAGS], [1])
+
+AC_CHECK_TOOL(STRIP, strip, :)
+test -z "$STRIP" && STRIP=:
+_LT_DECL([], [STRIP], [1], [A symbol stripping program])
+
+AC_CHECK_TOOL(RANLIB, ranlib, :)
+test -z "$RANLIB" && RANLIB=:
+_LT_DECL([], [RANLIB], [1],
+    [Commands used to install an old-style archive])
+
+# Determine commands to create old-style static archives.
+old_archive_cmds='$AR $AR_FLAGS $oldlib$oldobjs'
+old_postinstall_cmds='chmod 644 $oldlib'
+old_postuninstall_cmds=
+
+if test -n "$RANLIB"; then
+  case $host_os in
+  openbsd*)
+    old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB -t \$oldlib"
+    ;;
+  *)
+    old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB \$oldlib"
+    ;;
+  esac
+  old_archive_cmds="$old_archive_cmds~\$RANLIB \$oldlib"
+fi
+_LT_DECL([], [old_postinstall_cmds], [2])
+_LT_DECL([], [old_postuninstall_cmds], [2])
+_LT_TAGDECL([], [old_archive_cmds], [2],
+    [Commands used to build an old-style archive])
+])# _LT_CMD_OLD_ARCHIVE
+
+
+# _LT_COMPILER_OPTION(MESSAGE, VARIABLE-NAME, FLAGS,
+#		[OUTPUT-FILE], [ACTION-SUCCESS], [ACTION-FAILURE])
+# ----------------------------------------------------------------
+# Check whether the given compiler option works
+AC_DEFUN([_LT_COMPILER_OPTION],
+[m4_require([_LT_FILEUTILS_DEFAULTS])dnl
+m4_require([_LT_DECL_SED])dnl
+AC_CACHE_CHECK([$1], [$2],
+  [$2=no
+   m4_if([$4], , [ac_outfile=conftest.$ac_objext], [ac_outfile=$4])
+   echo "$lt_simple_compile_test_code" > conftest.$ac_ext
+   lt_compiler_flag="$3"
+   # Insert the option either (1) after the last *FLAGS variable, or
+   # (2) before a word containing "conftest.", or (3) at the end.
+   # Note that $ac_compile itself does not contain backslashes and begins
+   # with a dollar sign (not a hyphen), so the echo should work correctly.
+   # The option is referenced via a variable to avoid confusing sed.
+   lt_compile=`echo "$ac_compile" | $SED \
+   -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
+   -e 's: [[^ ]]*conftest\.: $lt_compiler_flag&:; t' \
+   -e 's:$: $lt_compiler_flag:'`
+   (eval echo "\"\$as_me:__oline__: $lt_compile\"" >&AS_MESSAGE_LOG_FD)
+   (eval "$lt_compile" 2>conftest.err)
+   ac_status=$?
+   cat conftest.err >&AS_MESSAGE_LOG_FD
+   echo "$as_me:__oline__: \$? = $ac_status" >&AS_MESSAGE_LOG_FD
+   if (exit $ac_status) && test -s "$ac_outfile"; then
+     # The compiler can only warn and ignore the option if not recognized
+     # So say no if there are warnings other than the usual output.
+     $ECHO "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' >conftest.exp
+     $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2
+     if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then
+       $2=yes
+     fi
+   fi
+   $RM conftest*
+])
+
+if test x"[$]$2" = xyes; then
+    m4_if([$5], , :, [$5])
+else
+    m4_if([$6], , :, [$6])
+fi
+])# _LT_COMPILER_OPTION
+
+# Old name:
+AU_ALIAS([AC_LIBTOOL_COMPILER_OPTION], [_LT_COMPILER_OPTION])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AC_LIBTOOL_COMPILER_OPTION], [])
+
+
+# _LT_LINKER_OPTION(MESSAGE, VARIABLE-NAME, FLAGS,
+#                  [ACTION-SUCCESS], [ACTION-FAILURE])
+# ----------------------------------------------------
+# Check whether the given linker option works
+AC_DEFUN([_LT_LINKER_OPTION],
+[m4_require([_LT_FILEUTILS_DEFAULTS])dnl
+m4_require([_LT_DECL_SED])dnl
+AC_CACHE_CHECK([$1], [$2],
+  [$2=no
+   save_LDFLAGS="$LDFLAGS"
+   LDFLAGS="$LDFLAGS $3"
+   echo "$lt_simple_link_test_code" > conftest.$ac_ext
+   if (eval $ac_link 2>conftest.err) && test -s conftest$ac_exeext; then
+     # The linker can only warn and ignore the option if not recognized
+     # So say no if there are warnings
+     if test -s conftest.err; then
+       # Append any errors to the config.log.
+       cat conftest.err 1>&AS_MESSAGE_LOG_FD
+       $ECHO "X$_lt_linker_boilerplate" | $Xsed -e '/^$/d' > conftest.exp
+       $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2
+       if diff conftest.exp conftest.er2 >/dev/null; then
+         $2=yes
+       fi
+     else
+       $2=yes
+     fi
+   fi
+   $RM -r conftest*
+   LDFLAGS="$save_LDFLAGS"
+])
+
+if test x"[$]$2" = xyes; then
+    m4_if([$4], , :, [$4])
+else
+    m4_if([$5], , :, [$5])
+fi
+])# _LT_LINKER_OPTION
+
+# Old name:
+AU_ALIAS([AC_LIBTOOL_LINKER_OPTION], [_LT_LINKER_OPTION])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AC_LIBTOOL_LINKER_OPTION], [])
+
+
+# LT_CMD_MAX_LEN
+#---------------
+AC_DEFUN([LT_CMD_MAX_LEN],
+[AC_REQUIRE([AC_CANONICAL_HOST])dnl
+# find the maximum length of command line arguments
+AC_MSG_CHECKING([the maximum length of command line arguments])
+AC_CACHE_VAL([lt_cv_sys_max_cmd_len], [dnl
+  i=0
+  teststring="ABCD"
+
+  case $build_os in
+  msdosdjgpp*)
+    # On DJGPP, this test can blow up pretty badly due to problems in libc
+    # (any single argument exceeding 2000 bytes causes a buffer overrun
+    # during glob expansion).  Even if it were fixed, the result of this
+    # check would be larger than it should be.
+    lt_cv_sys_max_cmd_len=12288;    # 12K is about right
+    ;;
+
+  gnu*)
+    # Under GNU Hurd, this test is not required because there is
+    # no limit to the length of command line arguments.
+    # Libtool will interpret -1 as no limit whatsoever
+    lt_cv_sys_max_cmd_len=-1;
+    ;;
+
+  cygwin* | mingw* | cegcc*)
+    # On Win9x/ME, this test blows up -- it succeeds, but takes
+    # about 5 minutes as the teststring grows exponentially.
+    # Worse, since 9x/ME are not pre-emptively multitasking,
+    # you end up with a "frozen" computer, even though with patience
+    # the test eventually succeeds (with a max line length of 256k).
+    # Instead, let's just punt: use the minimum linelength reported by
+    # all of the supported platforms: 8192 (on NT/2K/XP).
+    lt_cv_sys_max_cmd_len=8192;
+    ;;
+
+  amigaos*)
+    # On AmigaOS with pdksh, this test takes hours, literally.
+    # So we just punt and use a minimum line length of 8192.
+    lt_cv_sys_max_cmd_len=8192;
+    ;;
+
+  netbsd* | freebsd* | openbsd* | darwin* | dragonfly*)
+    # This has been around since 386BSD, at least.  Likely further.
+    if test -x /sbin/sysctl; then
+      lt_cv_sys_max_cmd_len=`/sbin/sysctl -n kern.argmax`
+    elif test -x /usr/sbin/sysctl; then
+      lt_cv_sys_max_cmd_len=`/usr/sbin/sysctl -n kern.argmax`
+    else
+      lt_cv_sys_max_cmd_len=65536	# usable default for all BSDs
+    fi
+    # And add a safety zone
+    lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4`
+    lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3`
+    ;;
+
+  interix*)
+    # We know the value 262144 and hardcode it with a safety zone (like BSD)
+    lt_cv_sys_max_cmd_len=196608
+    ;;
+
+  osf*)
+    # Dr. Hans Ekkehard Plesser reports seeing a kernel panic running configure
+    # due to this test when exec_disable_arg_limit is 1 on Tru64. It is not
+    # nice to cause kernel panics so lets avoid the loop below.
+    # First set a reasonable default.
+    lt_cv_sys_max_cmd_len=16384
+    #
+    if test -x /sbin/sysconfig; then
+      case `/sbin/sysconfig -q proc exec_disable_arg_limit` in
+        *1*) lt_cv_sys_max_cmd_len=-1 ;;
+      esac
+    fi
+    ;;
+  sco3.2v5*)
+    lt_cv_sys_max_cmd_len=102400
+    ;;
+  sysv5* | sco5v6* | sysv4.2uw2*)
+    kargmax=`grep ARG_MAX /etc/conf/cf.d/stune 2>/dev/null`
+    if test -n "$kargmax"; then
+      lt_cv_sys_max_cmd_len=`echo $kargmax | sed 's/.*[[	 ]]//'`
+    else
+      lt_cv_sys_max_cmd_len=32768
+    fi
+    ;;
+  *)
+    lt_cv_sys_max_cmd_len=`(getconf ARG_MAX) 2> /dev/null`
+    if test -n "$lt_cv_sys_max_cmd_len"; then
+      lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4`
+      lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3`
+    else
+      # Make teststring a little bigger before we do anything with it.
+      # a 1K string should be a reasonable start.
+      for i in 1 2 3 4 5 6 7 8 ; do
+        teststring=$teststring$teststring
+      done
+      SHELL=${SHELL-${CONFIG_SHELL-/bin/sh}}
+      # If test is not a shell built-in, we'll probably end up computing a
+      # maximum length that is only half of the actual maximum length, but
+      # we can't tell.
+      while { test "X"`$SHELL [$]0 --fallback-echo "X$teststring$teststring" 2>/dev/null` \
+	         = "XX$teststring$teststring"; } >/dev/null 2>&1 &&
+	      test $i != 17 # 1/2 MB should be enough
+      do
+        i=`expr $i + 1`
+        teststring=$teststring$teststring
+      done
+      # Only check the string length outside the loop.
+      lt_cv_sys_max_cmd_len=`expr "X$teststring" : ".*" 2>&1`
+      teststring=
+      # Add a significant safety factor because C++ compilers can tack on
+      # massive amounts of additional arguments before passing them to the
+      # linker.  It appears as though 1/2 is a usable value.
+      lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 2`
+    fi
+    ;;
+  esac
+])
+if test -n $lt_cv_sys_max_cmd_len ; then
+  AC_MSG_RESULT($lt_cv_sys_max_cmd_len)
+else
+  AC_MSG_RESULT(none)
+fi
+max_cmd_len=$lt_cv_sys_max_cmd_len
+_LT_DECL([], [max_cmd_len], [0],
+    [What is the maximum length of a command?])
+])# LT_CMD_MAX_LEN
+
+# Old name:
+AU_ALIAS([AC_LIBTOOL_SYS_MAX_CMD_LEN], [LT_CMD_MAX_LEN])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AC_LIBTOOL_SYS_MAX_CMD_LEN], [])
+
+
+# _LT_HEADER_DLFCN
+# ----------------
+m4_defun([_LT_HEADER_DLFCN],
+[AC_CHECK_HEADERS([dlfcn.h], [], [], [AC_INCLUDES_DEFAULT])dnl
+])# _LT_HEADER_DLFCN
+
+
+# _LT_TRY_DLOPEN_SELF (ACTION-IF-TRUE, ACTION-IF-TRUE-W-USCORE,
+#                      ACTION-IF-FALSE, ACTION-IF-CROSS-COMPILING)
+# ----------------------------------------------------------------
+m4_defun([_LT_TRY_DLOPEN_SELF],
+[m4_require([_LT_HEADER_DLFCN])dnl
+if test "$cross_compiling" = yes; then :
+  [$4]
+else
+  lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+  lt_status=$lt_dlunknown
+  cat > conftest.$ac_ext <<_LT_EOF
+[#line __oline__ "configure"
+#include "confdefs.h"
+
+#if HAVE_DLFCN_H
+#include <dlfcn.h>
+#endif
+
+#include <stdio.h>
+
+#ifdef RTLD_GLOBAL
+#  define LT_DLGLOBAL		RTLD_GLOBAL
+#else
+#  ifdef DL_GLOBAL
+#    define LT_DLGLOBAL		DL_GLOBAL
+#  else
+#    define LT_DLGLOBAL		0
+#  endif
+#endif
+
+/* We may have to define LT_DLLAZY_OR_NOW in the command line if we
+   find out it does not work in some platform. */
+#ifndef LT_DLLAZY_OR_NOW
+#  ifdef RTLD_LAZY
+#    define LT_DLLAZY_OR_NOW		RTLD_LAZY
+#  else
+#    ifdef DL_LAZY
+#      define LT_DLLAZY_OR_NOW		DL_LAZY
+#    else
+#      ifdef RTLD_NOW
+#        define LT_DLLAZY_OR_NOW	RTLD_NOW
+#      else
+#        ifdef DL_NOW
+#          define LT_DLLAZY_OR_NOW	DL_NOW
+#        else
+#          define LT_DLLAZY_OR_NOW	0
+#        endif
+#      endif
+#    endif
+#  endif
+#endif
+
+void fnord() { int i=42;}
+int main ()
+{
+  void *self = dlopen (0, LT_DLGLOBAL|LT_DLLAZY_OR_NOW);
+  int status = $lt_dlunknown;
+
+  if (self)
+    {
+      if (dlsym (self,"fnord"))       status = $lt_dlno_uscore;
+      else if (dlsym( self,"_fnord")) status = $lt_dlneed_uscore;
+      /* dlclose (self); */
+    }
+  else
+    puts (dlerror ());
+
+  return status;
+}]
+_LT_EOF
+  if AC_TRY_EVAL(ac_link) && test -s conftest${ac_exeext} 2>/dev/null; then
+    (./conftest; exit; ) >&AS_MESSAGE_LOG_FD 2>/dev/null
+    lt_status=$?
+    case x$lt_status in
+      x$lt_dlno_uscore) $1 ;;
+      x$lt_dlneed_uscore) $2 ;;
+      x$lt_dlunknown|x*) $3 ;;
+    esac
+  else :
+    # compilation failed
+    $3
+  fi
+fi
+rm -fr conftest*
+])# _LT_TRY_DLOPEN_SELF
+
+
+# LT_SYS_DLOPEN_SELF
+# ------------------
+AC_DEFUN([LT_SYS_DLOPEN_SELF],
+[m4_require([_LT_HEADER_DLFCN])dnl
+if test "x$enable_dlopen" != xyes; then
+  enable_dlopen=unknown
+  enable_dlopen_self=unknown
+  enable_dlopen_self_static=unknown
+else
+  lt_cv_dlopen=no
+  lt_cv_dlopen_libs=
+
+  case $host_os in
+  beos*)
+    lt_cv_dlopen="load_add_on"
+    lt_cv_dlopen_libs=
+    lt_cv_dlopen_self=yes
+    ;;
+
+  mingw* | pw32* | cegcc*)
+    lt_cv_dlopen="LoadLibrary"
+    lt_cv_dlopen_libs=
+    ;;
+
+  cygwin*)
+    lt_cv_dlopen="dlopen"
+    lt_cv_dlopen_libs=
+    ;;
+
+  darwin*)
+  # if libdl is installed we need to link against it
+    AC_CHECK_LIB([dl], [dlopen],
+		[lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-ldl"],[
+    lt_cv_dlopen="dyld"
+    lt_cv_dlopen_libs=
+    lt_cv_dlopen_self=yes
+    ])
+    ;;
+
+  *)
+    AC_CHECK_FUNC([shl_load],
+	  [lt_cv_dlopen="shl_load"],
+      [AC_CHECK_LIB([dld], [shl_load],
+	    [lt_cv_dlopen="shl_load" lt_cv_dlopen_libs="-ldld"],
+	[AC_CHECK_FUNC([dlopen],
+	      [lt_cv_dlopen="dlopen"],
+	  [AC_CHECK_LIB([dl], [dlopen],
+		[lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-ldl"],
+	    [AC_CHECK_LIB([svld], [dlopen],
+		  [lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-lsvld"],
+	      [AC_CHECK_LIB([dld], [dld_link],
+		    [lt_cv_dlopen="dld_link" lt_cv_dlopen_libs="-ldld"])
+	      ])
+	    ])
+	  ])
+	])
+      ])
+    ;;
+  esac
+
+  if test "x$lt_cv_dlopen" != xno; then
+    enable_dlopen=yes
+  else
+    enable_dlopen=no
+  fi
+
+  case $lt_cv_dlopen in
+  dlopen)
+    save_CPPFLAGS="$CPPFLAGS"
+    test "x$ac_cv_header_dlfcn_h" = xyes && CPPFLAGS="$CPPFLAGS -DHAVE_DLFCN_H"
+
+    save_LDFLAGS="$LDFLAGS"
+    wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $export_dynamic_flag_spec\"
+
+    save_LIBS="$LIBS"
+    LIBS="$lt_cv_dlopen_libs $LIBS"
+
+    AC_CACHE_CHECK([whether a program can dlopen itself],
+	  lt_cv_dlopen_self, [dnl
+	  _LT_TRY_DLOPEN_SELF(
+	    lt_cv_dlopen_self=yes, lt_cv_dlopen_self=yes,
+	    lt_cv_dlopen_self=no, lt_cv_dlopen_self=cross)
+    ])
+
+    if test "x$lt_cv_dlopen_self" = xyes; then
+      wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $lt_prog_compiler_static\"
+      AC_CACHE_CHECK([whether a statically linked program can dlopen itself],
+	  lt_cv_dlopen_self_static, [dnl
+	  _LT_TRY_DLOPEN_SELF(
+	    lt_cv_dlopen_self_static=yes, lt_cv_dlopen_self_static=yes,
+	    lt_cv_dlopen_self_static=no,  lt_cv_dlopen_self_static=cross)
+      ])
+    fi
+
+    CPPFLAGS="$save_CPPFLAGS"
+    LDFLAGS="$save_LDFLAGS"
+    LIBS="$save_LIBS"
+    ;;
+  esac
+
+  case $lt_cv_dlopen_self in
+  yes|no) enable_dlopen_self=$lt_cv_dlopen_self ;;
+  *) enable_dlopen_self=unknown ;;
+  esac
+
+  case $lt_cv_dlopen_self_static in
+  yes|no) enable_dlopen_self_static=$lt_cv_dlopen_self_static ;;
+  *) enable_dlopen_self_static=unknown ;;
+  esac
+fi
+_LT_DECL([dlopen_support], [enable_dlopen], [0],
+	 [Whether dlopen is supported])
+_LT_DECL([dlopen_self], [enable_dlopen_self], [0],
+	 [Whether dlopen of programs is supported])
+_LT_DECL([dlopen_self_static], [enable_dlopen_self_static], [0],
+	 [Whether dlopen of statically linked programs is supported])
+])# LT_SYS_DLOPEN_SELF
+
+# Old name:
+AU_ALIAS([AC_LIBTOOL_DLOPEN_SELF], [LT_SYS_DLOPEN_SELF])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AC_LIBTOOL_DLOPEN_SELF], [])
+
+
+# _LT_COMPILER_C_O([TAGNAME])
+# ---------------------------
+# Check to see if options -c and -o are simultaneously supported by compiler.
+# This macro does not hard code the compiler like AC_PROG_CC_C_O.
+m4_defun([_LT_COMPILER_C_O],
+[m4_require([_LT_DECL_SED])dnl
+m4_require([_LT_FILEUTILS_DEFAULTS])dnl
+m4_require([_LT_TAG_COMPILER])dnl
+AC_CACHE_CHECK([if $compiler supports -c -o file.$ac_objext],
+  [_LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)],
+  [_LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)=no
+   $RM -r conftest 2>/dev/null
+   mkdir conftest
+   cd conftest
+   mkdir out
+   echo "$lt_simple_compile_test_code" > conftest.$ac_ext
+
+   lt_compiler_flag="-o out/conftest2.$ac_objext"
+   # Insert the option either (1) after the last *FLAGS variable, or
+   # (2) before a word containing "conftest.", or (3) at the end.
+   # Note that $ac_compile itself does not contain backslashes and begins
+   # with a dollar sign (not a hyphen), so the echo should work correctly.
+   lt_compile=`echo "$ac_compile" | $SED \
+   -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
+   -e 's: [[^ ]]*conftest\.: $lt_compiler_flag&:; t' \
+   -e 's:$: $lt_compiler_flag:'`
+   (eval echo "\"\$as_me:__oline__: $lt_compile\"" >&AS_MESSAGE_LOG_FD)
+   (eval "$lt_compile" 2>out/conftest.err)
+   ac_status=$?
+   cat out/conftest.err >&AS_MESSAGE_LOG_FD
+   echo "$as_me:__oline__: \$? = $ac_status" >&AS_MESSAGE_LOG_FD
+   if (exit $ac_status) && test -s out/conftest2.$ac_objext
+   then
+     # The compiler can only warn and ignore the option if not recognized
+     # So say no if there are warnings
+     $ECHO "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' > out/conftest.exp
+     $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2
+     if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then
+       _LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)=yes
+     fi
+   fi
+   chmod u+w . 2>&AS_MESSAGE_LOG_FD
+   $RM conftest*
+   # SGI C++ compiler will create directory out/ii_files/ for
+   # template instantiation
+   test -d out/ii_files && $RM out/ii_files/* && rmdir out/ii_files
+   $RM out/* && rmdir out
+   cd ..
+   $RM -r conftest
+   $RM conftest*
+])
+_LT_TAGDECL([compiler_c_o], [lt_cv_prog_compiler_c_o], [1],
+	[Does compiler simultaneously support -c and -o options?])
+])# _LT_COMPILER_C_O
+
+
+# _LT_COMPILER_FILE_LOCKS([TAGNAME])
+# ----------------------------------
+# Check to see if we can do hard links to lock some files if needed
+m4_defun([_LT_COMPILER_FILE_LOCKS],
+[m4_require([_LT_ENABLE_LOCK])dnl
+m4_require([_LT_FILEUTILS_DEFAULTS])dnl
+_LT_COMPILER_C_O([$1])
+
+hard_links="nottested"
+if test "$_LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)" = no && test "$need_locks" != no; then
+  # do not overwrite the value of need_locks provided by the user
+  AC_MSG_CHECKING([if we can lock with hard links])
+  hard_links=yes
+  $RM conftest*
+  ln conftest.a conftest.b 2>/dev/null && hard_links=no
+  touch conftest.a
+  ln conftest.a conftest.b 2>&5 || hard_links=no
+  ln conftest.a conftest.b 2>/dev/null && hard_links=no
+  AC_MSG_RESULT([$hard_links])
+  if test "$hard_links" = no; then
+    AC_MSG_WARN([`$CC' does not support `-c -o', so `make -j' may be unsafe])
+    need_locks=warn
+  fi
+else
+  need_locks=no
+fi
+_LT_DECL([], [need_locks], [1], [Must we lock files when doing compilation?])
+])# _LT_COMPILER_FILE_LOCKS
+
+
+# _LT_CHECK_OBJDIR
+# ----------------
+m4_defun([_LT_CHECK_OBJDIR],
+[AC_CACHE_CHECK([for objdir], [lt_cv_objdir],
+[rm -f .libs 2>/dev/null
+mkdir .libs 2>/dev/null
+if test -d .libs; then
+  lt_cv_objdir=.libs
+else
+  # MS-DOS does not allow filenames that begin with a dot.
+  lt_cv_objdir=_libs
+fi
+rmdir .libs 2>/dev/null])
+objdir=$lt_cv_objdir
+_LT_DECL([], [objdir], [0],
+         [The name of the directory that contains temporary libtool files])dnl
+m4_pattern_allow([LT_OBJDIR])dnl
+AC_DEFINE_UNQUOTED(LT_OBJDIR, "$lt_cv_objdir/",
+  [Define to the sub-directory in which libtool stores uninstalled libraries.])
+])# _LT_CHECK_OBJDIR
+
+
+# _LT_LINKER_HARDCODE_LIBPATH([TAGNAME])
+# --------------------------------------
+# Check hardcoding attributes.
+m4_defun([_LT_LINKER_HARDCODE_LIBPATH],
+[AC_MSG_CHECKING([how to hardcode library paths into programs])
+_LT_TAGVAR(hardcode_action, $1)=
+if test -n "$_LT_TAGVAR(hardcode_libdir_flag_spec, $1)" ||
+   test -n "$_LT_TAGVAR(runpath_var, $1)" ||
+   test "X$_LT_TAGVAR(hardcode_automatic, $1)" = "Xyes" ; then
+
+  # We can hardcode non-existent directories.
+  if test "$_LT_TAGVAR(hardcode_direct, $1)" != no &&
+     # If the only mechanism to avoid hardcoding is shlibpath_var, we
+     # have to relink, otherwise we might link with an installed library
+     # when we should be linking with a yet-to-be-installed one
+     ## test "$_LT_TAGVAR(hardcode_shlibpath_var, $1)" != no &&
+     test "$_LT_TAGVAR(hardcode_minus_L, $1)" != no; then
+    # Linking always hardcodes the temporary library directory.
+    _LT_TAGVAR(hardcode_action, $1)=relink
+  else
+    # We can link without hardcoding, and we can hardcode nonexisting dirs.
+    _LT_TAGVAR(hardcode_action, $1)=immediate
+  fi
+else
+  # We cannot hardcode anything, or else we can only hardcode existing
+  # directories.
+  _LT_TAGVAR(hardcode_action, $1)=unsupported
+fi
+AC_MSG_RESULT([$_LT_TAGVAR(hardcode_action, $1)])
+
+if test "$_LT_TAGVAR(hardcode_action, $1)" = relink ||
+   test "$_LT_TAGVAR(inherit_rpath, $1)" = yes; then
+  # Fast installation is not supported
+  enable_fast_install=no
+elif test "$shlibpath_overrides_runpath" = yes ||
+     test "$enable_shared" = no; then
+  # Fast installation is not necessary
+  enable_fast_install=needless
+fi
+_LT_TAGDECL([], [hardcode_action], [0],
+    [How to hardcode a shared library path into an executable])
+])# _LT_LINKER_HARDCODE_LIBPATH
+
+
+# _LT_CMD_STRIPLIB
+# ----------------
+m4_defun([_LT_CMD_STRIPLIB],
+[m4_require([_LT_DECL_EGREP])
+striplib=
+old_striplib=
+AC_MSG_CHECKING([whether stripping libraries is possible])
+if test -n "$STRIP" && $STRIP -V 2>&1 | $GREP "GNU strip" >/dev/null; then
+  test -z "$old_striplib" && old_striplib="$STRIP --strip-debug"
+  test -z "$striplib" && striplib="$STRIP --strip-unneeded"
+  AC_MSG_RESULT([yes])
+else
+# FIXME - insert some real tests, host_os isn't really good enough
+  case $host_os in
+  darwin*)
+    if test -n "$STRIP" ; then
+      striplib="$STRIP -x"
+      old_striplib="$STRIP -S"
+      AC_MSG_RESULT([yes])
+    else
+      AC_MSG_RESULT([no])
+    fi
+    ;;
+  *)
+    AC_MSG_RESULT([no])
+    ;;
+  esac
+fi
+_LT_DECL([], [old_striplib], [1], [Commands to strip libraries])
+_LT_DECL([], [striplib], [1])
+])# _LT_CMD_STRIPLIB
+
+
+# _LT_SYS_DYNAMIC_LINKER([TAG])
+# -----------------------------
+# PORTME Fill in your ld.so characteristics
+m4_defun([_LT_SYS_DYNAMIC_LINKER],
+[AC_REQUIRE([AC_CANONICAL_HOST])dnl
+m4_require([_LT_DECL_EGREP])dnl
+m4_require([_LT_FILEUTILS_DEFAULTS])dnl
+m4_require([_LT_DECL_OBJDUMP])dnl
+m4_require([_LT_DECL_SED])dnl
+AC_MSG_CHECKING([dynamic linker characteristics])
+m4_if([$1],
+	[], [
+if test "$GCC" = yes; then
+  case $host_os in
+    darwin*) lt_awk_arg="/^libraries:/,/LR/" ;;
+    *) lt_awk_arg="/^libraries:/" ;;
+  esac
+  lt_search_path_spec=`$CC -print-search-dirs | awk $lt_awk_arg | $SED -e "s/^libraries://" -e "s,=/,/,g"`
+  if $ECHO "$lt_search_path_spec" | $GREP ';' >/dev/null ; then
+    # if the path contains ";" then we assume it to be the separator
+    # otherwise default to the standard path separator (i.e. ":") - it is
+    # assumed that no part of a normal pathname contains ";" but that should
+    # okay in the real world where ";" in dirpaths is itself problematic.
+    lt_search_path_spec=`$ECHO "$lt_search_path_spec" | $SED -e 's/;/ /g'`
+  else
+    lt_search_path_spec=`$ECHO "$lt_search_path_spec" | $SED  -e "s/$PATH_SEPARATOR/ /g"`
+  fi
+  # Ok, now we have the path, separated by spaces, we can step through it
+  # and add multilib dir if necessary.
+  lt_tmp_lt_search_path_spec=
+  lt_multi_os_dir=`$CC $CPPFLAGS $CFLAGS $LDFLAGS -print-multi-os-directory 2>/dev/null`
+  for lt_sys_path in $lt_search_path_spec; do
+    if test -d "$lt_sys_path/$lt_multi_os_dir"; then
+      lt_tmp_lt_search_path_spec="$lt_tmp_lt_search_path_spec $lt_sys_path/$lt_multi_os_dir"
+    else
+      test -d "$lt_sys_path" && \
+	lt_tmp_lt_search_path_spec="$lt_tmp_lt_search_path_spec $lt_sys_path"
+    fi
+  done
+  lt_search_path_spec=`$ECHO $lt_tmp_lt_search_path_spec | awk '
+BEGIN {RS=" "; FS="/|\n";} {
+  lt_foo="";
+  lt_count=0;
+  for (lt_i = NF; lt_i > 0; lt_i--) {
+    if ($lt_i != "" && $lt_i != ".") {
+      if ($lt_i == "..") {
+        lt_count++;
+      } else {
+        if (lt_count == 0) {
+          lt_foo="/" $lt_i lt_foo;
+        } else {
+          lt_count--;
+        }
+      }
+    }
+  }
+  if (lt_foo != "") { lt_freq[[lt_foo]]++; }
+  if (lt_freq[[lt_foo]] == 1) { print lt_foo; }
+}'`
+  sys_lib_search_path_spec=`$ECHO $lt_search_path_spec`
+else
+  sys_lib_search_path_spec="/lib /usr/lib /usr/local/lib"
+fi])
+library_names_spec=
+libname_spec='lib$name'
+soname_spec=
+shrext_cmds=".so"
+postinstall_cmds=
+postuninstall_cmds=
+finish_cmds=
+finish_eval=
+shlibpath_var=
+shlibpath_overrides_runpath=unknown
+version_type=none
+dynamic_linker="$host_os ld.so"
+sys_lib_dlsearch_path_spec="/lib /usr/lib"
+need_lib_prefix=unknown
+hardcode_into_libs=no
+
+# when you set need_version to no, make sure it does not cause -set_version
+# flags to be left without arguments
+need_version=unknown
+
+case $host_os in
+aix3*)
+  version_type=linux
+  library_names_spec='${libname}${release}${shared_ext}$versuffix $libname.a'
+  shlibpath_var=LIBPATH
+
+  # AIX 3 has no versioning support, so we append a major version to the name.
+  soname_spec='${libname}${release}${shared_ext}$major'
+  ;;
+
+aix[[4-9]]*)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  hardcode_into_libs=yes
+  if test "$host_cpu" = ia64; then
+    # AIX 5 supports IA64
+    library_names_spec='${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext}$versuffix $libname${shared_ext}'
+    shlibpath_var=LD_LIBRARY_PATH
+  else
+    # With GCC up to 2.95.x, collect2 would create an import file
+    # for dependence libraries.  The import file would start with
+    # the line `#! .'.  This would cause the generated library to
+    # depend on `.', always an invalid library.  This was fixed in
+    # development snapshots of GCC prior to 3.0.
+    case $host_os in
+      aix4 | aix4.[[01]] | aix4.[[01]].*)
+      if { echo '#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 97)'
+	   echo ' yes '
+	   echo '#endif'; } | ${CC} -E - | $GREP yes > /dev/null; then
+	:
+      else
+	can_build_shared=no
+      fi
+      ;;
+    esac
+    # AIX (on Power*) has no versioning support, so currently we can not hardcode correct
+    # soname into executable. Probably we can add versioning support to
+    # collect2, so additional links can be useful in future.
+    if test "$aix_use_runtimelinking" = yes; then
+      # If using run time linking (on AIX 4.2 or later) use lib<name>.so
+      # instead of lib<name>.a to let people know that these are not
+      # typical AIX shared libraries.
+      library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+    else
+      # We preserve .a as extension for shared libraries through AIX4.2
+      # and later when we are not doing run time linking.
+      library_names_spec='${libname}${release}.a $libname.a'
+      soname_spec='${libname}${release}${shared_ext}$major'
+    fi
+    shlibpath_var=LIBPATH
+  fi
+  ;;
+
+amigaos*)
+  case $host_cpu in
+  powerpc)
+    # Since July 2007 AmigaOS4 officially supports .so libraries.
+    # When compiling the executable, add -use-dynld -Lsobjs: to the compileline.
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+    ;;
+  m68k)
+    library_names_spec='$libname.ixlibrary $libname.a'
+    # Create ${libname}_ixlibrary.a entries in /sys/libs.
+    finish_eval='for lib in `ls $libdir/*.ixlibrary 2>/dev/null`; do libname=`$ECHO "X$lib" | $Xsed -e '\''s%^.*/\([[^/]]*\)\.ixlibrary$%\1%'\''`; test $RM /sys/libs/${libname}_ixlibrary.a; $show "cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a"; cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a || exit 1; done'
+    ;;
+  esac
+  ;;
+
+beos*)
+  library_names_spec='${libname}${shared_ext}'
+  dynamic_linker="$host_os ld.so"
+  shlibpath_var=LIBRARY_PATH
+  ;;
+
+bsdi[[45]]*)
+  version_type=linux
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  finish_cmds='PATH="\$PATH:/sbin" ldconfig $libdir'
+  shlibpath_var=LD_LIBRARY_PATH
+  sys_lib_search_path_spec="/shlib /usr/lib /usr/X11/lib /usr/contrib/lib /lib /usr/local/lib"
+  sys_lib_dlsearch_path_spec="/shlib /usr/lib /usr/local/lib"
+  # the default ld.so.conf also contains /usr/contrib/lib and
+  # /usr/X11R6/lib (/usr/X11 is a link to /usr/X11R6), but let us allow
+  # libtool to hard-code these into programs
+  ;;
+
+cygwin* | mingw* | pw32* | cegcc*)
+  version_type=windows
+  shrext_cmds=".dll"
+  need_version=no
+  need_lib_prefix=no
+
+  case $GCC,$host_os in
+  yes,cygwin* | yes,mingw* | yes,pw32* | yes,cegcc*)
+    library_names_spec='$libname.dll.a'
+    # DLL is installed to $(libdir)/../bin by postinstall_cmds
+    postinstall_cmds='base_file=`basename \${file}`~
+      dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
+      dldir=$destdir/`dirname \$dlpath`~
+      test -d \$dldir || mkdir -p \$dldir~
+      $install_prog $dir/$dlname \$dldir/$dlname~
+      chmod a+x \$dldir/$dlname~
+      if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
+        eval '\''$striplib \$dldir/$dlname'\'' || exit \$?;
+      fi'
+    postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~
+      dlpath=$dir/\$dldll~
+       $RM \$dlpath'
+    shlibpath_overrides_runpath=yes
+
+    case $host_os in
+    cygwin*)
+      # Cygwin DLLs use 'cyg' prefix rather than 'lib'
+      soname_spec='`echo ${libname} | sed -e 's/^lib/cyg/'``echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext}'
+      sys_lib_search_path_spec="/usr/lib /lib/w32api /lib /usr/local/lib"
+      ;;
+    mingw* | cegcc*)
+      # MinGW DLLs use traditional 'lib' prefix
+      soname_spec='${libname}`echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext}'
+      sys_lib_search_path_spec=`$CC -print-search-dirs | $GREP "^libraries:" | $SED -e "s/^libraries://" -e "s,=/,/,g"`
+      if $ECHO "$sys_lib_search_path_spec" | [$GREP ';[c-zC-Z]:/' >/dev/null]; then
+        # It is most probably a Windows format PATH printed by
+        # mingw gcc, but we are running on Cygwin. Gcc prints its search
+        # path with ; separators, and with drive letters. We can handle the
+        # drive letters (cygwin fileutils understands them), so leave them,
+        # especially as we might pass files found there to a mingw objdump,
+        # which wouldn't understand a cygwinified path. Ahh.
+        sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED -e 's/;/ /g'`
+      else
+        sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED  -e "s/$PATH_SEPARATOR/ /g"`
+      fi
+      ;;
+    pw32*)
+      # pw32 DLLs use 'pw' prefix rather than 'lib'
+      library_names_spec='`echo ${libname} | sed -e 's/^lib/pw/'``echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext}'
+      ;;
+    esac
+    ;;
+
+  *)
+    library_names_spec='${libname}`echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext} $libname.lib'
+    ;;
+  esac
+  dynamic_linker='Win32 ld.exe'
+  # FIXME: first we should search . and the directory the executable is in
+  shlibpath_var=PATH
+  ;;
+
+darwin* | rhapsody*)
+  dynamic_linker="$host_os dyld"
+  version_type=darwin
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${major}$shared_ext ${libname}$shared_ext'
+  soname_spec='${libname}${release}${major}$shared_ext'
+  shlibpath_overrides_runpath=yes
+  shlibpath_var=DYLD_LIBRARY_PATH
+  shrext_cmds='`test .$module = .yes && echo .so || echo .dylib`'
+m4_if([$1], [],[
+  sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/local/lib"])
+  sys_lib_dlsearch_path_spec='/usr/local/lib /lib /usr/lib'
+  ;;
+
+dgux*)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname$shared_ext'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  ;;
+
+freebsd1*)
+  dynamic_linker=no
+  ;;
+
+freebsd* | dragonfly*)
+  # DragonFly does not have aout.  When/if they implement a new
+  # versioning mechanism, adjust this.
+  if test -x /usr/bin/objformat; then
+    objformat=`/usr/bin/objformat`
+  else
+    case $host_os in
+    freebsd[[123]]*) objformat=aout ;;
+    *) objformat=elf ;;
+    esac
+  fi
+  version_type=freebsd-$objformat
+  case $version_type in
+    freebsd-elf*)
+      library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}'
+      need_version=no
+      need_lib_prefix=no
+      ;;
+    freebsd-*)
+      library_names_spec='${libname}${release}${shared_ext}$versuffix $libname${shared_ext}$versuffix'
+      need_version=yes
+      ;;
+  esac
+  shlibpath_var=LD_LIBRARY_PATH
+  case $host_os in
+  freebsd2*)
+    shlibpath_overrides_runpath=yes
+    ;;
+  freebsd3.[[01]]* | freebsdelf3.[[01]]*)
+    shlibpath_overrides_runpath=yes
+    hardcode_into_libs=yes
+    ;;
+  freebsd3.[[2-9]]* | freebsdelf3.[[2-9]]* | \
+  freebsd4.[[0-5]] | freebsdelf4.[[0-5]] | freebsd4.1.1 | freebsdelf4.1.1)
+    shlibpath_overrides_runpath=no
+    hardcode_into_libs=yes
+    ;;
+  *) # from 4.6 on, and DragonFly
+    shlibpath_overrides_runpath=yes
+    hardcode_into_libs=yes
+    ;;
+  esac
+  ;;
+
+gnu*)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}${major} ${libname}${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  hardcode_into_libs=yes
+  ;;
+
+hpux9* | hpux10* | hpux11*)
+  # Give a soname corresponding to the major version so that dld.sl refuses to
+  # link against other versions.
+  version_type=sunos
+  need_lib_prefix=no
+  need_version=no
+  case $host_cpu in
+  ia64*)
+    shrext_cmds='.so'
+    hardcode_into_libs=yes
+    dynamic_linker="$host_os dld.so"
+    shlibpath_var=LD_LIBRARY_PATH
+    shlibpath_overrides_runpath=yes # Unless +noenvvar is specified.
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+    soname_spec='${libname}${release}${shared_ext}$major'
+    if test "X$HPUX_IA64_MODE" = X32; then
+      sys_lib_search_path_spec="/usr/lib/hpux32 /usr/local/lib/hpux32 /usr/local/lib"
+    else
+      sys_lib_search_path_spec="/usr/lib/hpux64 /usr/local/lib/hpux64"
+    fi
+    sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec
+    ;;
+  hppa*64*)
+    shrext_cmds='.sl'
+    hardcode_into_libs=yes
+    dynamic_linker="$host_os dld.sl"
+    shlibpath_var=LD_LIBRARY_PATH # How should we handle SHLIB_PATH
+    shlibpath_overrides_runpath=yes # Unless +noenvvar is specified.
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+    soname_spec='${libname}${release}${shared_ext}$major'
+    sys_lib_search_path_spec="/usr/lib/pa20_64 /usr/ccs/lib/pa20_64"
+    sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec
+    ;;
+  *)
+    shrext_cmds='.sl'
+    dynamic_linker="$host_os dld.sl"
+    shlibpath_var=SHLIB_PATH
+    shlibpath_overrides_runpath=no # +s is required to enable SHLIB_PATH
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+    soname_spec='${libname}${release}${shared_ext}$major'
+    ;;
+  esac
+  # HP-UX runs *really* slowly unless shared libraries are mode 555.
+  postinstall_cmds='chmod 555 $lib'
+  ;;
+
+interix[[3-9]]*)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  dynamic_linker='Interix 3.x ld.so.1 (PE, like ELF)'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=no
+  hardcode_into_libs=yes
+  ;;
+
+irix5* | irix6* | nonstopux*)
+  case $host_os in
+    nonstopux*) version_type=nonstopux ;;
+    *)
+	if test "$lt_cv_prog_gnu_ld" = yes; then
+		version_type=linux
+	else
+		version_type=irix
+	fi ;;
+  esac
+  need_lib_prefix=no
+  need_version=no
+  soname_spec='${libname}${release}${shared_ext}$major'
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext} $libname${shared_ext}'
+  case $host_os in
+  irix5* | nonstopux*)
+    libsuff= shlibsuff=
+    ;;
+  *)
+    case $LD in # libtool.m4 will add one of these switches to LD
+    *-32|*"-32 "|*-melf32bsmip|*"-melf32bsmip ")
+      libsuff= shlibsuff= libmagic=32-bit;;
+    *-n32|*"-n32 "|*-melf32bmipn32|*"-melf32bmipn32 ")
+      libsuff=32 shlibsuff=N32 libmagic=N32;;
+    *-64|*"-64 "|*-melf64bmip|*"-melf64bmip ")
+      libsuff=64 shlibsuff=64 libmagic=64-bit;;
+    *) libsuff= shlibsuff= libmagic=never-match;;
+    esac
+    ;;
+  esac
+  shlibpath_var=LD_LIBRARY${shlibsuff}_PATH
+  shlibpath_overrides_runpath=no
+  sys_lib_search_path_spec="/usr/lib${libsuff} /lib${libsuff} /usr/local/lib${libsuff}"
+  sys_lib_dlsearch_path_spec="/usr/lib${libsuff} /lib${libsuff}"
+  hardcode_into_libs=yes
+  ;;
+
+# No shared lib support for Linux oldld, aout, or coff.
+linux*oldld* | linux*aout* | linux*coff*)
+  dynamic_linker=no
+  ;;
+
+# This must be Linux ELF.
+linux* | k*bsd*-gnu)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  finish_cmds='PATH="\$PATH:/sbin" ldconfig -n $libdir'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=no
+  # Some binutils ld are patched to set DT_RUNPATH
+  save_LDFLAGS=$LDFLAGS
+  save_libdir=$libdir
+  eval "libdir=/foo; wl=\"$_LT_TAGVAR(lt_prog_compiler_wl, $1)\"; \
+       LDFLAGS=\"\$LDFLAGS $_LT_TAGVAR(hardcode_libdir_flag_spec, $1)\""
+  AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])],
+    [AS_IF([ ($OBJDUMP -p conftest$ac_exeext) 2>/dev/null | grep "RUNPATH.*$libdir" >/dev/null],
+       [shlibpath_overrides_runpath=yes])])
+  LDFLAGS=$save_LDFLAGS
+  libdir=$save_libdir
+
+  # This implies no fast_install, which is unacceptable.
+  # Some rework will be needed to allow for fast_install
+  # before this can be enabled.
+  hardcode_into_libs=yes
+
+  # Add ABI-specific directories to the system library path.
+  sys_lib_dlsearch_path_spec="/lib64 /usr/lib64 /lib /usr/lib"
+
+  # Append ld.so.conf contents to the search path
+  if test -f /etc/ld.so.conf; then
+    lt_ld_extra=`awk '/^include / { system(sprintf("cd /etc; cat %s 2>/dev/null", \[$]2)); skip = 1; } { if (!skip) print \[$]0; skip = 0; }' < /etc/ld.so.conf | $SED -e 's/#.*//;/^[	 ]*hwcap[	 ]/d;s/[:,	]/ /g;s/=[^=]*$//;s/=[^= ]* / /g;/^$/d' | tr '\n' ' '`
+    sys_lib_dlsearch_path_spec="$sys_lib_dlsearch_path_spec $lt_ld_extra"
+  fi
+
+  # We used to test for /lib/ld.so.1 and disable shared libraries on
+  # powerpc, because MkLinux only supported shared libraries with the
+  # GNU dynamic linker.  Since this was broken with cross compilers,
+  # most powerpc-linux boxes support dynamic linking these days and
+  # people can always --disable-shared, the test was removed, and we
+  # assume the GNU/Linux dynamic linker is in use.
+  dynamic_linker='GNU/Linux ld.so'
+  ;;
+
+netbsd*)
+  version_type=sunos
+  need_lib_prefix=no
+  need_version=no
+  if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix'
+    finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir'
+    dynamic_linker='NetBSD (a.out) ld.so'
+  else
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}'
+    soname_spec='${libname}${release}${shared_ext}$major'
+    dynamic_linker='NetBSD ld.elf_so'
+  fi
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  hardcode_into_libs=yes
+  ;;
+
+newsos6)
+  version_type=linux
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  ;;
+
+*nto* | *qnx*)
+  version_type=qnx
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=no
+  hardcode_into_libs=yes
+  dynamic_linker='ldqnx.so'
+  ;;
+
+openbsd*)
+  version_type=sunos
+  sys_lib_dlsearch_path_spec="/usr/lib"
+  need_lib_prefix=no
+  # Some older versions of OpenBSD (3.3 at least) *do* need versioned libs.
+  case $host_os in
+    openbsd3.3 | openbsd3.3.*)	need_version=yes ;;
+    *)				need_version=no  ;;
+  esac
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix'
+  finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir'
+  shlibpath_var=LD_LIBRARY_PATH
+  if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
+    case $host_os in
+      openbsd2.[[89]] | openbsd2.[[89]].*)
+	shlibpath_overrides_runpath=no
+	;;
+      *)
+	shlibpath_overrides_runpath=yes
+	;;
+      esac
+  else
+    shlibpath_overrides_runpath=yes
+  fi
+  ;;
+
+os2*)
+  libname_spec='$name'
+  shrext_cmds=".dll"
+  need_lib_prefix=no
+  library_names_spec='$libname${shared_ext} $libname.a'
+  dynamic_linker='OS/2 ld.exe'
+  shlibpath_var=LIBPATH
+  ;;
+
+osf3* | osf4* | osf5*)
+  version_type=osf
+  need_lib_prefix=no
+  need_version=no
+  soname_spec='${libname}${release}${shared_ext}$major'
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  shlibpath_var=LD_LIBRARY_PATH
+  sys_lib_search_path_spec="/usr/shlib /usr/ccs/lib /usr/lib/cmplrs/cc /usr/lib /usr/local/lib /var/shlib"
+  sys_lib_dlsearch_path_spec="$sys_lib_search_path_spec"
+  ;;
+
+rdos*)
+  dynamic_linker=no
+  ;;
+
+solaris*)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  hardcode_into_libs=yes
+  # ldd complains unless libraries are executable
+  postinstall_cmds='chmod +x $lib'
+  ;;
+
+sunos4*)
+  version_type=sunos
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix'
+  finish_cmds='PATH="\$PATH:/usr/etc" ldconfig $libdir'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  if test "$with_gnu_ld" = yes; then
+    need_lib_prefix=no
+  fi
+  need_version=yes
+  ;;
+
+sysv4 | sysv4.3*)
+  version_type=linux
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  case $host_vendor in
+    sni)
+      shlibpath_overrides_runpath=no
+      need_lib_prefix=no
+      runpath_var=LD_RUN_PATH
+      ;;
+    siemens)
+      need_lib_prefix=no
+      ;;
+    motorola)
+      need_lib_prefix=no
+      need_version=no
+      shlibpath_overrides_runpath=no
+      sys_lib_search_path_spec='/lib /usr/lib /usr/ccs/lib'
+      ;;
+  esac
+  ;;
+
+sysv4*MP*)
+  if test -d /usr/nec ;then
+    version_type=linux
+    library_names_spec='$libname${shared_ext}.$versuffix $libname${shared_ext}.$major $libname${shared_ext}'
+    soname_spec='$libname${shared_ext}.$major'
+    shlibpath_var=LD_LIBRARY_PATH
+  fi
+  ;;
+
+sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*)
+  version_type=freebsd-elf
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  hardcode_into_libs=yes
+  if test "$with_gnu_ld" = yes; then
+    sys_lib_search_path_spec='/usr/local/lib /usr/gnu/lib /usr/ccs/lib /usr/lib /lib'
+  else
+    sys_lib_search_path_spec='/usr/ccs/lib /usr/lib'
+    case $host_os in
+      sco3.2v5*)
+        sys_lib_search_path_spec="$sys_lib_search_path_spec /lib"
+	;;
+    esac
+  fi
+  sys_lib_dlsearch_path_spec='/usr/lib'
+  ;;
+
+tpf*)
+  # TPF is a cross-target only.  Preferred cross-host = GNU/Linux.
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=no
+  hardcode_into_libs=yes
+  ;;
+
+uts4*)
+  version_type=linux
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  ;;
+
+*)
+  dynamic_linker=no
+  ;;
+esac
+AC_MSG_RESULT([$dynamic_linker])
+test "$dynamic_linker" = no && can_build_shared=no
+
+variables_saved_for_relink="PATH $shlibpath_var $runpath_var"
+if test "$GCC" = yes; then
+  variables_saved_for_relink="$variables_saved_for_relink GCC_EXEC_PREFIX COMPILER_PATH LIBRARY_PATH"
+fi
+
+if test "${lt_cv_sys_lib_search_path_spec+set}" = set; then
+  sys_lib_search_path_spec="$lt_cv_sys_lib_search_path_spec"
+fi
+if test "${lt_cv_sys_lib_dlsearch_path_spec+set}" = set; then
+  sys_lib_dlsearch_path_spec="$lt_cv_sys_lib_dlsearch_path_spec"
+fi
+
+_LT_DECL([], [variables_saved_for_relink], [1],
+    [Variables whose values should be saved in libtool wrapper scripts and
+    restored at link time])
+_LT_DECL([], [need_lib_prefix], [0],
+    [Do we need the "lib" prefix for modules?])
+_LT_DECL([], [need_version], [0], [Do we need a version for libraries?])
+_LT_DECL([], [version_type], [0], [Library versioning type])
+_LT_DECL([], [runpath_var], [0],  [Shared library runtime path variable])
+_LT_DECL([], [shlibpath_var], [0],[Shared library path variable])
+_LT_DECL([], [shlibpath_overrides_runpath], [0],
+    [Is shlibpath searched before the hard-coded library search path?])
+_LT_DECL([], [libname_spec], [1], [Format of library name prefix])
+_LT_DECL([], [library_names_spec], [1],
+    [[List of archive names.  First name is the real one, the rest are links.
+    The last name is the one that the linker finds with -lNAME]])
+_LT_DECL([], [soname_spec], [1],
+    [[The coded name of the library, if different from the real name]])
+_LT_DECL([], [postinstall_cmds], [2],
+    [Command to use after installation of a shared archive])
+_LT_DECL([], [postuninstall_cmds], [2],
+    [Command to use after uninstallation of a shared archive])
+_LT_DECL([], [finish_cmds], [2],
+    [Commands used to finish a libtool library installation in a directory])
+_LT_DECL([], [finish_eval], [1],
+    [[As "finish_cmds", except a single script fragment to be evaled but
+    not shown]])
+_LT_DECL([], [hardcode_into_libs], [0],
+    [Whether we should hardcode library paths into libraries])
+_LT_DECL([], [sys_lib_search_path_spec], [2],
+    [Compile-time system search path for libraries])
+_LT_DECL([], [sys_lib_dlsearch_path_spec], [2],
+    [Run-time system search path for libraries])
+])# _LT_SYS_DYNAMIC_LINKER
+
+
+# _LT_PATH_TOOL_PREFIX(TOOL)
+# --------------------------
+# find a file program which can recognize shared library
+AC_DEFUN([_LT_PATH_TOOL_PREFIX],
+[m4_require([_LT_DECL_EGREP])dnl
+AC_MSG_CHECKING([for $1])
+AC_CACHE_VAL(lt_cv_path_MAGIC_CMD,
+[case $MAGIC_CMD in
+[[\\/*] |  ?:[\\/]*])
+  lt_cv_path_MAGIC_CMD="$MAGIC_CMD" # Let the user override the test with a path.
+  ;;
+*)
+  lt_save_MAGIC_CMD="$MAGIC_CMD"
+  lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
+dnl $ac_dummy forces splitting on constant user-supplied paths.
+dnl POSIX.2 word splitting is done only on the output of word expansions,
+dnl not every word.  This closes a longstanding sh security hole.
+  ac_dummy="m4_if([$2], , $PATH, [$2])"
+  for ac_dir in $ac_dummy; do
+    IFS="$lt_save_ifs"
+    test -z "$ac_dir" && ac_dir=.
+    if test -f $ac_dir/$1; then
+      lt_cv_path_MAGIC_CMD="$ac_dir/$1"
+      if test -n "$file_magic_test_file"; then
+	case $deplibs_check_method in
+	"file_magic "*)
+	  file_magic_regex=`expr "$deplibs_check_method" : "file_magic \(.*\)"`
+	  MAGIC_CMD="$lt_cv_path_MAGIC_CMD"
+	  if eval $file_magic_cmd \$file_magic_test_file 2> /dev/null |
+	    $EGREP "$file_magic_regex" > /dev/null; then
+	    :
+	  else
+	    cat <<_LT_EOF 1>&2
+
+*** Warning: the command libtool uses to detect shared libraries,
+*** $file_magic_cmd, produces output that libtool cannot recognize.
+*** The result is that libtool may fail to recognize shared libraries
+*** as such.  This will affect the creation of libtool libraries that
+*** depend on shared libraries, but programs linked with such libtool
+*** libraries will work regardless of this problem.  Nevertheless, you
+*** may want to report the problem to your system manager and/or to
+*** bug-libtool at gnu.org
+
+_LT_EOF
+	  fi ;;
+	esac
+      fi
+      break
+    fi
+  done
+  IFS="$lt_save_ifs"
+  MAGIC_CMD="$lt_save_MAGIC_CMD"
+  ;;
+esac])
+MAGIC_CMD="$lt_cv_path_MAGIC_CMD"
+if test -n "$MAGIC_CMD"; then
+  AC_MSG_RESULT($MAGIC_CMD)
+else
+  AC_MSG_RESULT(no)
+fi
+_LT_DECL([], [MAGIC_CMD], [0],
+	 [Used to examine libraries when file_magic_cmd begins with "file"])dnl
+])# _LT_PATH_TOOL_PREFIX
+
+# Old name:
+AU_ALIAS([AC_PATH_TOOL_PREFIX], [_LT_PATH_TOOL_PREFIX])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AC_PATH_TOOL_PREFIX], [])
+
+
+# _LT_PATH_MAGIC
+# --------------
+# find a file program which can recognize a shared library
+m4_defun([_LT_PATH_MAGIC],
+[_LT_PATH_TOOL_PREFIX(${ac_tool_prefix}file, /usr/bin$PATH_SEPARATOR$PATH)
+if test -z "$lt_cv_path_MAGIC_CMD"; then
+  if test -n "$ac_tool_prefix"; then
+    _LT_PATH_TOOL_PREFIX(file, /usr/bin$PATH_SEPARATOR$PATH)
+  else
+    MAGIC_CMD=:
+  fi
+fi
+])# _LT_PATH_MAGIC
+
+
+# LT_PATH_LD
+# ----------
+# find the pathname to the GNU or non-GNU linker
+AC_DEFUN([LT_PATH_LD],
+[AC_REQUIRE([AC_PROG_CC])dnl
+AC_REQUIRE([AC_CANONICAL_HOST])dnl
+AC_REQUIRE([AC_CANONICAL_BUILD])dnl
+m4_require([_LT_DECL_SED])dnl
+m4_require([_LT_DECL_EGREP])dnl
+
+AC_ARG_WITH([gnu-ld],
+    [AS_HELP_STRING([--with-gnu-ld],
+	[assume the C compiler uses GNU ld @<:@default=no@:>@])],
+    [test "$withval" = no || with_gnu_ld=yes],
+    [with_gnu_ld=no])dnl
+
+ac_prog=ld
+if test "$GCC" = yes; then
+  # Check if gcc -print-prog-name=ld gives a path.
+  AC_MSG_CHECKING([for ld used by $CC])
+  case $host in
+  *-*-mingw*)
+    # gcc leaves a trailing carriage return which upsets mingw
+    ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;;
+  *)
+    ac_prog=`($CC -print-prog-name=ld) 2>&5` ;;
+  esac
+  case $ac_prog in
+    # Accept absolute paths.
+    [[\\/]]* | ?:[[\\/]]*)
+      re_direlt='/[[^/]][[^/]]*/\.\./'
+      # Canonicalize the pathname of ld
+      ac_prog=`$ECHO "$ac_prog"| $SED 's%\\\\%/%g'`
+      while $ECHO "$ac_prog" | $GREP "$re_direlt" > /dev/null 2>&1; do
+	ac_prog=`$ECHO $ac_prog| $SED "s%$re_direlt%/%"`
+      done
+      test -z "$LD" && LD="$ac_prog"
+      ;;
+  "")
+    # If it fails, then pretend we aren't using GCC.
+    ac_prog=ld
+    ;;
+  *)
+    # If it is relative, then search for the first ld in PATH.
+    with_gnu_ld=unknown
+    ;;
+  esac
+elif test "$with_gnu_ld" = yes; then
+  AC_MSG_CHECKING([for GNU ld])
+else
+  AC_MSG_CHECKING([for non-GNU ld])
+fi
+AC_CACHE_VAL(lt_cv_path_LD,
+[if test -z "$LD"; then
+  lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
+  for ac_dir in $PATH; do
+    IFS="$lt_save_ifs"
+    test -z "$ac_dir" && ac_dir=.
+    if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then
+      lt_cv_path_LD="$ac_dir/$ac_prog"
+      # Check to see if the program is GNU ld.  I'd rather use --version,
+      # but apparently some variants of GNU ld only accept -v.
+      # Break only if it was the GNU/non-GNU ld that we prefer.
+      case `"$lt_cv_path_LD" -v 2>&1 </dev/null` in
+      *GNU* | *'with BFD'*)
+	test "$with_gnu_ld" != no && break
+	;;
+      *)
+	test "$with_gnu_ld" != yes && break
+	;;
+      esac
+    fi
+  done
+  IFS="$lt_save_ifs"
+else
+  lt_cv_path_LD="$LD" # Let the user override the test with a path.
+fi])
+LD="$lt_cv_path_LD"
+if test -n "$LD"; then
+  AC_MSG_RESULT($LD)
+else
+  AC_MSG_RESULT(no)
+fi
+test -z "$LD" && AC_MSG_ERROR([no acceptable ld found in \$PATH])
+_LT_PATH_LD_GNU
+AC_SUBST([LD])
+
+_LT_TAGDECL([], [LD], [1], [The linker used to build libraries])
+])# LT_PATH_LD
+
+# Old names:
+AU_ALIAS([AM_PROG_LD], [LT_PATH_LD])
+AU_ALIAS([AC_PROG_LD], [LT_PATH_LD])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AM_PROG_LD], [])
+dnl AC_DEFUN([AC_PROG_LD], [])
+
+
+# _LT_PATH_LD_GNU
+#- --------------
+m4_defun([_LT_PATH_LD_GNU],
+[AC_CACHE_CHECK([if the linker ($LD) is GNU ld], lt_cv_prog_gnu_ld,
+[# I'd rather use --version here, but apparently some GNU lds only accept -v.
+case `$LD -v 2>&1 </dev/null` in
+*GNU* | *'with BFD'*)
+  lt_cv_prog_gnu_ld=yes
+  ;;
+*)
+  lt_cv_prog_gnu_ld=no
+  ;;
+esac])
+with_gnu_ld=$lt_cv_prog_gnu_ld
+])# _LT_PATH_LD_GNU
+
+
+# _LT_CMD_RELOAD
+# --------------
+# find reload flag for linker
+#   -- PORTME Some linkers may need a different reload flag.
+m4_defun([_LT_CMD_RELOAD],
+[AC_CACHE_CHECK([for $LD option to reload object files],
+  lt_cv_ld_reload_flag,
+  [lt_cv_ld_reload_flag='-r'])
+reload_flag=$lt_cv_ld_reload_flag
+case $reload_flag in
+"" | " "*) ;;
+*) reload_flag=" $reload_flag" ;;
+esac
+reload_cmds='$LD$reload_flag -o $output$reload_objs'
+case $host_os in
+  darwin*)
+    if test "$GCC" = yes; then
+      reload_cmds='$LTCC $LTCFLAGS -nostdlib ${wl}-r -o $output$reload_objs'
+    else
+      reload_cmds='$LD$reload_flag -o $output$reload_objs'
+    fi
+    ;;
+esac
+_LT_DECL([], [reload_flag], [1], [How to create reloadable object files])dnl
+_LT_DECL([], [reload_cmds], [2])dnl
+])# _LT_CMD_RELOAD
+
+
+# _LT_CHECK_MAGIC_METHOD
+# ----------------------
+# how to check for library dependencies
+#  -- PORTME fill in with the dynamic library characteristics
+m4_defun([_LT_CHECK_MAGIC_METHOD],
+[m4_require([_LT_DECL_EGREP])
+m4_require([_LT_DECL_OBJDUMP])
+AC_CACHE_CHECK([how to recognize dependent libraries],
+lt_cv_deplibs_check_method,
+[lt_cv_file_magic_cmd='$MAGIC_CMD'
+lt_cv_file_magic_test_file=
+lt_cv_deplibs_check_method='unknown'
+# Need to set the preceding variable on all platforms that support
+# interlibrary dependencies.
+# 'none' -- dependencies not supported.
+# `unknown' -- same as none, but documents that we really don't know.
+# 'pass_all' -- all dependencies passed with no checks.
+# 'test_compile' -- check by making test program.
+# 'file_magic [[regex]]' -- check by looking for files in library path
+# which responds to the $file_magic_cmd with a given extended regex.
+# If you have `file' or equivalent on your system and you're not sure
+# whether `pass_all' will *always* work, you probably want this one.
+
+case $host_os in
+aix[[4-9]]*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+beos*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+bsdi[[45]]*)
+  lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[ML]]SB (shared object|dynamic lib)'
+  lt_cv_file_magic_cmd='/usr/bin/file -L'
+  lt_cv_file_magic_test_file=/shlib/libc.so
+  ;;
+
+cygwin*)
+  # func_win32_libid is a shell function defined in ltmain.sh
+  lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL'
+  lt_cv_file_magic_cmd='func_win32_libid'
+  ;;
+
+mingw* | pw32*)
+  # Base MSYS/MinGW do not provide the 'file' command needed by
+  # func_win32_libid shell function, so use a weaker test based on 'objdump',
+  # unless we find 'file', for example because we are cross-compiling.
+  if ( file / ) >/dev/null 2>&1; then
+    lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL'
+    lt_cv_file_magic_cmd='func_win32_libid'
+  else
+    lt_cv_deplibs_check_method='file_magic file format pei*-i386(.*architecture: i386)?'
+    lt_cv_file_magic_cmd='$OBJDUMP -f'
+  fi
+  ;;
+
+cegcc)
+  # use the weaker test based on 'objdump'. See mingw*.
+  lt_cv_deplibs_check_method='file_magic file format pe-arm-.*little(.*architecture: arm)?'
+  lt_cv_file_magic_cmd='$OBJDUMP -f'
+  ;;
+
+darwin* | rhapsody*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+freebsd* | dragonfly*)
+  if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then
+    case $host_cpu in
+    i*86 )
+      # Not sure whether the presence of OpenBSD here was a mistake.
+      # Let's accept both of them until this is cleared up.
+      lt_cv_deplibs_check_method='file_magic (FreeBSD|OpenBSD|DragonFly)/i[[3-9]]86 (compact )?demand paged shared library'
+      lt_cv_file_magic_cmd=/usr/bin/file
+      lt_cv_file_magic_test_file=`echo /usr/lib/libc.so.*`
+      ;;
+    esac
+  else
+    lt_cv_deplibs_check_method=pass_all
+  fi
+  ;;
+
+gnu*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+hpux10.20* | hpux11*)
+  lt_cv_file_magic_cmd=/usr/bin/file
+  case $host_cpu in
+  ia64*)
+    lt_cv_deplibs_check_method='file_magic (s[[0-9]][[0-9]][[0-9]]|ELF-[[0-9]][[0-9]]) shared object file - IA64'
+    lt_cv_file_magic_test_file=/usr/lib/hpux32/libc.so
+    ;;
+  hppa*64*)
+    [lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|ELF-[0-9][0-9]) shared object file - PA-RISC [0-9].[0-9]']
+    lt_cv_file_magic_test_file=/usr/lib/pa20_64/libc.sl
+    ;;
+  *)
+    lt_cv_deplibs_check_method='file_magic (s[[0-9]][[0-9]][[0-9]]|PA-RISC[[0-9]].[[0-9]]) shared library'
+    lt_cv_file_magic_test_file=/usr/lib/libc.sl
+    ;;
+  esac
+  ;;
+
+interix[[3-9]]*)
+  # PIC code is broken on Interix 3.x, that's why |\.a not |_pic\.a here
+  lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so|\.a)$'
+  ;;
+
+irix5* | irix6* | nonstopux*)
+  case $LD in
+  *-32|*"-32 ") libmagic=32-bit;;
+  *-n32|*"-n32 ") libmagic=N32;;
+  *-64|*"-64 ") libmagic=64-bit;;
+  *) libmagic=never-match;;
+  esac
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+# This must be Linux ELF.
+linux* | k*bsd*-gnu)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+netbsd*)
+  if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then
+    lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|_pic\.a)$'
+  else
+    lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so|_pic\.a)$'
+  fi
+  ;;
+
+newos6*)
+  lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[ML]]SB (executable|dynamic lib)'
+  lt_cv_file_magic_cmd=/usr/bin/file
+  lt_cv_file_magic_test_file=/usr/lib/libnls.so
+  ;;
+
+*nto* | *qnx*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+openbsd*)
+  if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
+    lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|\.so|_pic\.a)$'
+  else
+    lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|_pic\.a)$'
+  fi
+  ;;
+
+osf3* | osf4* | osf5*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+rdos*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+solaris*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+sysv4 | sysv4.3*)
+  case $host_vendor in
+  motorola)
+    lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[ML]]SB (shared object|dynamic lib) M[[0-9]][[0-9]]* Version [[0-9]]'
+    lt_cv_file_magic_test_file=`echo /usr/lib/libc.so*`
+    ;;
+  ncr)
+    lt_cv_deplibs_check_method=pass_all
+    ;;
+  sequent)
+    lt_cv_file_magic_cmd='/bin/file'
+    lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[LM]]SB (shared object|dynamic lib )'
+    ;;
+  sni)
+    lt_cv_file_magic_cmd='/bin/file'
+    lt_cv_deplibs_check_method="file_magic ELF [[0-9]][[0-9]]*-bit [[LM]]SB dynamic lib"
+    lt_cv_file_magic_test_file=/lib/libc.so
+    ;;
+  siemens)
+    lt_cv_deplibs_check_method=pass_all
+    ;;
+  pc)
+    lt_cv_deplibs_check_method=pass_all
+    ;;
+  esac
+  ;;
+
+tpf*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+esac
+])
+file_magic_cmd=$lt_cv_file_magic_cmd
+deplibs_check_method=$lt_cv_deplibs_check_method
+test -z "$deplibs_check_method" && deplibs_check_method=unknown
+
+_LT_DECL([], [deplibs_check_method], [1],
+    [Method to check whether dependent libraries are shared objects])
+_LT_DECL([], [file_magic_cmd], [1],
+    [Command to use when deplibs_check_method == "file_magic"])
+])# _LT_CHECK_MAGIC_METHOD
+
+
+# LT_PATH_NM
+# ----------
+# find the pathname to a BSD- or MS-compatible name lister
+AC_DEFUN([LT_PATH_NM],
+[AC_REQUIRE([AC_PROG_CC])dnl
+AC_CACHE_CHECK([for BSD- or MS-compatible name lister (nm)], lt_cv_path_NM,
+[if test -n "$NM"; then
+  # Let the user override the test.
+  lt_cv_path_NM="$NM"
+else
+  lt_nm_to_check="${ac_tool_prefix}nm"
+  if test -n "$ac_tool_prefix" && test "$build" = "$host"; then
+    lt_nm_to_check="$lt_nm_to_check nm"
+  fi
+  for lt_tmp_nm in $lt_nm_to_check; do
+    lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
+    for ac_dir in $PATH /usr/ccs/bin/elf /usr/ccs/bin /usr/ucb /bin; do
+      IFS="$lt_save_ifs"
+      test -z "$ac_dir" && ac_dir=.
+      tmp_nm="$ac_dir/$lt_tmp_nm"
+      if test -f "$tmp_nm" || test -f "$tmp_nm$ac_exeext" ; then
+	# Check to see if the nm accepts a BSD-compat flag.
+	# Adding the `sed 1q' prevents false positives on HP-UX, which says:
+	#   nm: unknown option "B" ignored
+	# Tru64's nm complains that /dev/null is an invalid object file
+	case `"$tmp_nm" -B /dev/null 2>&1 | sed '1q'` in
+	*/dev/null* | *'Invalid file or object type'*)
+	  lt_cv_path_NM="$tmp_nm -B"
+	  break
+	  ;;
+	*)
+	  case `"$tmp_nm" -p /dev/null 2>&1 | sed '1q'` in
+	  */dev/null*)
+	    lt_cv_path_NM="$tmp_nm -p"
+	    break
+	    ;;
+	  *)
+	    lt_cv_path_NM=${lt_cv_path_NM="$tmp_nm"} # keep the first match, but
+	    continue # so that we can try to find one that supports BSD flags
+	    ;;
+	  esac
+	  ;;
+	esac
+      fi
+    done
+    IFS="$lt_save_ifs"
+  done
+  : ${lt_cv_path_NM=no}
+fi])
+if test "$lt_cv_path_NM" != "no"; then
+  NM="$lt_cv_path_NM"
+else
+  # Didn't find any BSD compatible name lister, look for dumpbin.
+  AC_CHECK_TOOLS(DUMPBIN, ["dumpbin -symbols" "link -dump -symbols"], :)
+  AC_SUBST([DUMPBIN])
+  if test "$DUMPBIN" != ":"; then
+    NM="$DUMPBIN"
+  fi
+fi
+test -z "$NM" && NM=nm
+AC_SUBST([NM])
+_LT_DECL([], [NM], [1], [A BSD- or MS-compatible name lister])dnl
+
+AC_CACHE_CHECK([the name lister ($NM) interface], [lt_cv_nm_interface],
+  [lt_cv_nm_interface="BSD nm"
+  echo "int some_variable = 0;" > conftest.$ac_ext
+  (eval echo "\"\$as_me:__oline__: $ac_compile\"" >&AS_MESSAGE_LOG_FD)
+  (eval "$ac_compile" 2>conftest.err)
+  cat conftest.err >&AS_MESSAGE_LOG_FD
+  (eval echo "\"\$as_me:__oline__: $NM \\\"conftest.$ac_objext\\\"\"" >&AS_MESSAGE_LOG_FD)
+  (eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out)
+  cat conftest.err >&AS_MESSAGE_LOG_FD
+  (eval echo "\"\$as_me:__oline__: output\"" >&AS_MESSAGE_LOG_FD)
+  cat conftest.out >&AS_MESSAGE_LOG_FD
+  if $GREP 'External.*some_variable' conftest.out > /dev/null; then
+    lt_cv_nm_interface="MS dumpbin"
+  fi
+  rm -f conftest*])
+])# LT_PATH_NM
+
+# Old names:
+AU_ALIAS([AM_PROG_NM], [LT_PATH_NM])
+AU_ALIAS([AC_PROG_NM], [LT_PATH_NM])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AM_PROG_NM], [])
+dnl AC_DEFUN([AC_PROG_NM], [])
+
+
+# LT_LIB_M
+# --------
+# check for math library
+AC_DEFUN([LT_LIB_M],
+[AC_REQUIRE([AC_CANONICAL_HOST])dnl
+LIBM=
+case $host in
+*-*-beos* | *-*-cygwin* | *-*-pw32* | *-*-darwin*)
+  # These system don't have libm, or don't need it
+  ;;
+*-ncr-sysv4.3*)
+  AC_CHECK_LIB(mw, _mwvalidcheckl, LIBM="-lmw")
+  AC_CHECK_LIB(m, cos, LIBM="$LIBM -lm")
+  ;;
+*)
+  AC_CHECK_LIB(m, cos, LIBM="-lm")
+  ;;
+esac
+AC_SUBST([LIBM])
+])# LT_LIB_M
+
+# Old name:
+AU_ALIAS([AC_CHECK_LIBM], [LT_LIB_M])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AC_CHECK_LIBM], [])
+
+
+# _LT_COMPILER_NO_RTTI([TAGNAME])
+# -------------------------------
+m4_defun([_LT_COMPILER_NO_RTTI],
+[m4_require([_LT_TAG_COMPILER])dnl
+
+_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=
+
+if test "$GCC" = yes; then
+  _LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=' -fno-builtin'
+
+  _LT_COMPILER_OPTION([if $compiler supports -fno-rtti -fno-exceptions],
+    lt_cv_prog_compiler_rtti_exceptions,
+    [-fno-rtti -fno-exceptions], [],
+    [_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)="$_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1) -fno-rtti -fno-exceptions"])
+fi
+_LT_TAGDECL([no_builtin_flag], [lt_prog_compiler_no_builtin_flag], [1],
+	[Compiler flag to turn off builtin functions])
+])# _LT_COMPILER_NO_RTTI
+
+
+# _LT_CMD_GLOBAL_SYMBOLS
+# ----------------------
+m4_defun([_LT_CMD_GLOBAL_SYMBOLS],
+[AC_REQUIRE([AC_CANONICAL_HOST])dnl
+AC_REQUIRE([AC_PROG_CC])dnl
+AC_REQUIRE([LT_PATH_NM])dnl
+AC_REQUIRE([LT_PATH_LD])dnl
+m4_require([_LT_DECL_SED])dnl
+m4_require([_LT_DECL_EGREP])dnl
+m4_require([_LT_TAG_COMPILER])dnl
+
+# Check for command to grab the raw symbol name followed by C symbol from nm.
+AC_MSG_CHECKING([command to parse $NM output from $compiler object])
+AC_CACHE_VAL([lt_cv_sys_global_symbol_pipe],
+[
+# These are sane defaults that work on at least a few old systems.
+# [They come from Ultrix.  What could be older than Ultrix?!! ;)]
+
+# Character class describing NM global symbol codes.
+symcode='[[BCDEGRST]]'
+
+# Regexp to match symbols that can be accessed directly from C.
+sympat='\([[_A-Za-z]][[_A-Za-z0-9]]*\)'
+
+# Define system-specific variables.
+case $host_os in
+aix*)
+  symcode='[[BCDT]]'
+  ;;
+cygwin* | mingw* | pw32* | cegcc*)
+  symcode='[[ABCDGISTW]]'
+  ;;
+hpux*)
+  if test "$host_cpu" = ia64; then
+    symcode='[[ABCDEGRST]]'
+  fi
+  ;;
+irix* | nonstopux*)
+  symcode='[[BCDEGRST]]'
+  ;;
+osf*)
+  symcode='[[BCDEGQRST]]'
+  ;;
+solaris*)
+  symcode='[[BDRT]]'
+  ;;
+sco3.2v5*)
+  symcode='[[DT]]'
+  ;;
+sysv4.2uw2*)
+  symcode='[[DT]]'
+  ;;
+sysv5* | sco5v6* | unixware* | OpenUNIX*)
+  symcode='[[ABDT]]'
+  ;;
+sysv4)
+  symcode='[[DFNSTU]]'
+  ;;
+esac
+
+# If we're using GNU nm, then use its standard symbol codes.
+case `$NM -V 2>&1` in
+*GNU* | *'with BFD'*)
+  symcode='[[ABCDGIRSTW]]' ;;
+esac
+
+# Transform an extracted symbol line into a proper C declaration.
+# Some systems (esp. on ia64) link data and code symbols differently,
+# so use this general approach.
+lt_cv_sys_global_symbol_to_cdecl="sed -n -e 's/^T .* \(.*\)$/extern int \1();/p' -e 's/^$symcode* .* \(.*\)$/extern char \1;/p'"
+
+# Transform an extracted symbol line into symbol name and symbol address
+lt_cv_sys_global_symbol_to_c_name_address="sed -n -e 's/^: \([[^ ]]*\) $/  {\\\"\1\\\", (void *) 0},/p' -e 's/^$symcode* \([[^ ]]*\) \([[^ ]]*\)$/  {\"\2\", (void *) \&\2},/p'"
+lt_cv_sys_global_symbol_to_c_name_address_lib_prefix="sed -n -e 's/^: \([[^ ]]*\) $/  {\\\"\1\\\", (void *) 0},/p' -e 's/^$symcode* \([[^ ]]*\) \(lib[[^ ]]*\)$/  {\"\2\", (void *) \&\2},/p' -e 's/^$symcode* \([[^ ]]*\) \([[^ ]]*\)$/  {\"lib\2\", (void *) \&\2},/p'"
+
+# Handle CRLF in mingw tool chain
+opt_cr=
+case $build_os in
+mingw*)
+  opt_cr=`$ECHO 'x\{0,1\}' | tr x '\015'` # option cr in regexp
+  ;;
+esac
+
+# Try without a prefix underscore, then with it.
+for ac_symprfx in "" "_"; do
+
+  # Transform symcode, sympat, and symprfx into a raw symbol and a C symbol.
+  symxfrm="\\1 $ac_symprfx\\2 \\2"
+
+  # Write the raw and C identifiers.
+  if test "$lt_cv_nm_interface" = "MS dumpbin"; then
+    # Fake it for dumpbin and say T for any non-static function
+    # and D for any global variable.
+    # Also find C++ and __fastcall symbols from MSVC++,
+    # which start with @ or ?.
+    lt_cv_sys_global_symbol_pipe="$AWK ['"\
+"     {last_section=section; section=\$ 3};"\
+"     /Section length .*#relocs.*(pick any)/{hide[last_section]=1};"\
+"     \$ 0!~/External *\|/{next};"\
+"     / 0+ UNDEF /{next}; / UNDEF \([^|]\)*()/{next};"\
+"     {if(hide[section]) next};"\
+"     {f=0}; \$ 0~/\(\).*\|/{f=1}; {printf f ? \"T \" : \"D \"};"\
+"     {split(\$ 0, a, /\||\r/); split(a[2], s)};"\
+"     s[1]~/^[@?]/{print s[1], s[1]; next};"\
+"     s[1]~prfx {split(s[1],t,\"@\"); print t[1], substr(t[1],length(prfx))}"\
+"     ' prfx=^$ac_symprfx]"
+  else
+    lt_cv_sys_global_symbol_pipe="sed -n -e 's/^.*[[	 ]]\($symcode$symcode*\)[[	 ]][[	 ]]*$ac_symprfx$sympat$opt_cr$/$symxfrm/p'"
+  fi
+
+  # Check to see that the pipe works correctly.
+  pipe_works=no
+
+  rm -f conftest*
+  cat > conftest.$ac_ext <<_LT_EOF
+#ifdef __cplusplus
+extern "C" {
+#endif
+char nm_test_var;
+void nm_test_func(void);
+void nm_test_func(void){}
+#ifdef __cplusplus
+}
+#endif
+int main(){nm_test_var='a';nm_test_func();return(0);}
+_LT_EOF
+
+  if AC_TRY_EVAL(ac_compile); then
+    # Now try to grab the symbols.
+    nlist=conftest.nm
+    if AC_TRY_EVAL(NM conftest.$ac_objext \| $lt_cv_sys_global_symbol_pipe \> $nlist) && test -s "$nlist"; then
+      # Try sorting and uniquifying the output.
+      if sort "$nlist" | uniq > "$nlist"T; then
+	mv -f "$nlist"T "$nlist"
+      else
+	rm -f "$nlist"T
+      fi
+
+      # Make sure that we snagged all the symbols we need.
+      if $GREP ' nm_test_var$' "$nlist" >/dev/null; then
+	if $GREP ' nm_test_func$' "$nlist" >/dev/null; then
+	  cat <<_LT_EOF > conftest.$ac_ext
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+_LT_EOF
+	  # Now generate the symbol file.
+	  eval "$lt_cv_sys_global_symbol_to_cdecl"' < "$nlist" | $GREP -v main >> conftest.$ac_ext'
+
+	  cat <<_LT_EOF >> conftest.$ac_ext
+
+/* The mapping between symbol names and symbols.  */
+const struct {
+  const char *name;
+  void       *address;
+}
+lt__PROGRAM__LTX_preloaded_symbols[[]] =
+{
+  { "@PROGRAM@", (void *) 0 },
+_LT_EOF
+	  $SED "s/^$symcode$symcode* \(.*\) \(.*\)$/  {\"\2\", (void *) \&\2},/" < "$nlist" | $GREP -v main >> conftest.$ac_ext
+	  cat <<\_LT_EOF >> conftest.$ac_ext
+  {0, (void *) 0}
+};
+
+/* This works around a problem in FreeBSD linker */
+#ifdef FREEBSD_WORKAROUND
+static const void *lt_preloaded_setup() {
+  return lt__PROGRAM__LTX_preloaded_symbols;
+}
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+_LT_EOF
+	  # Now try linking the two files.
+	  mv conftest.$ac_objext conftstm.$ac_objext
+	  lt_save_LIBS="$LIBS"
+	  lt_save_CFLAGS="$CFLAGS"
+	  LIBS="conftstm.$ac_objext"
+	  CFLAGS="$CFLAGS$_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)"
+	  if AC_TRY_EVAL(ac_link) && test -s conftest${ac_exeext}; then
+	    pipe_works=yes
+	  fi
+	  LIBS="$lt_save_LIBS"
+	  CFLAGS="$lt_save_CFLAGS"
+	else
+	  echo "cannot find nm_test_func in $nlist" >&AS_MESSAGE_LOG_FD
+	fi
+      else
+	echo "cannot find nm_test_var in $nlist" >&AS_MESSAGE_LOG_FD
+      fi
+    else
+      echo "cannot run $lt_cv_sys_global_symbol_pipe" >&AS_MESSAGE_LOG_FD
+    fi
+  else
+    echo "$progname: failed program was:" >&AS_MESSAGE_LOG_FD
+    cat conftest.$ac_ext >&5
+  fi
+  rm -rf conftest* conftst*
+
+  # Do not use the global_symbol_pipe unless it works.
+  if test "$pipe_works" = yes; then
+    break
+  else
+    lt_cv_sys_global_symbol_pipe=
+  fi
+done
+])
+if test -z "$lt_cv_sys_global_symbol_pipe"; then
+  lt_cv_sys_global_symbol_to_cdecl=
+fi
+if test -z "$lt_cv_sys_global_symbol_pipe$lt_cv_sys_global_symbol_to_cdecl"; then
+  AC_MSG_RESULT(failed)
+else
+  AC_MSG_RESULT(ok)
+fi
+
+_LT_DECL([global_symbol_pipe], [lt_cv_sys_global_symbol_pipe], [1],
+    [Take the output of nm and produce a listing of raw symbols and C names])
+_LT_DECL([global_symbol_to_cdecl], [lt_cv_sys_global_symbol_to_cdecl], [1],
+    [Transform the output of nm in a proper C declaration])
+_LT_DECL([global_symbol_to_c_name_address],
+    [lt_cv_sys_global_symbol_to_c_name_address], [1],
+    [Transform the output of nm in a C name address pair])
+_LT_DECL([global_symbol_to_c_name_address_lib_prefix],
+    [lt_cv_sys_global_symbol_to_c_name_address_lib_prefix], [1],
+    [Transform the output of nm in a C name address pair when lib prefix is needed])
+]) # _LT_CMD_GLOBAL_SYMBOLS
+
+
+# _LT_COMPILER_PIC([TAGNAME])
+# ---------------------------
+m4_defun([_LT_COMPILER_PIC],
+[m4_require([_LT_TAG_COMPILER])dnl
+_LT_TAGVAR(lt_prog_compiler_wl, $1)=
+_LT_TAGVAR(lt_prog_compiler_pic, $1)=
+_LT_TAGVAR(lt_prog_compiler_static, $1)=
+
+AC_MSG_CHECKING([for $compiler option to produce PIC])
+m4_if([$1], [CXX], [
+  # C++ specific cases for pic, static, wl, etc.
+  if test "$GXX" = yes; then
+    _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+    _LT_TAGVAR(lt_prog_compiler_static, $1)='-static'
+
+    case $host_os in
+    aix*)
+      # All AIX code is PIC.
+      if test "$host_cpu" = ia64; then
+	# AIX 5 now supports IA64 processor
+	_LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+      fi
+      ;;
+
+    amigaos*)
+      case $host_cpu in
+      powerpc)
+            # see comment about AmigaOS4 .so support
+            _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
+        ;;
+      m68k)
+            # FIXME: we need at least 68020 code to build shared libraries, but
+            # adding the `-m68020' flag to GCC prevents building anything better,
+            # like `-m68040'.
+            _LT_TAGVAR(lt_prog_compiler_pic, $1)='-m68020 -resident32 -malways-restore-a4'
+        ;;
+      esac
+      ;;
+
+    beos* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*)
+      # PIC is the default for these OSes.
+      ;;
+    mingw* | cygwin* | os2* | pw32* | cegcc*)
+      # This hack is so that the source file can tell whether it is being
+      # built for inclusion in a dll (and should export symbols for example).
+      # Although the cygwin gcc ignores -fPIC, still need this for old-style
+      # (--disable-auto-import) libraries
+      m4_if([$1], [GCJ], [],
+	[_LT_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT'])
+      ;;
+    darwin* | rhapsody*)
+      # PIC is the default on this platform
+      # Common symbols not allowed in MH_DYLIB files
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fno-common'
+      ;;
+    *djgpp*)
+      # DJGPP does not support shared libraries at all
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)=
+      ;;
+    interix[[3-9]]*)
+      # Interix 3.x gcc -fpic/-fPIC options generate broken code.
+      # Instead, we relocate shared libraries at runtime.
+      ;;
+    sysv4*MP*)
+      if test -d /usr/nec; then
+	_LT_TAGVAR(lt_prog_compiler_pic, $1)=-Kconform_pic
+      fi
+      ;;
+    hpux*)
+      # PIC is the default for 64-bit PA HP-UX, but not for 32-bit
+      # PA HP-UX.  On IA64 HP-UX, PIC is the default but the pic flag
+      # sets the default TLS model and affects inlining.
+      case $host_cpu in
+      hppa*64*)
+	;;
+      *)
+	_LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
+	;;
+      esac
+      ;;
+    *qnx* | *nto*)
+      # QNX uses GNU C++, but need to define -shared option too, otherwise
+      # it will coredump.
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared'
+      ;;
+    *)
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
+      ;;
+    esac
+  else
+    case $host_os in
+      aix[[4-9]]*)
+	# All AIX code is PIC.
+	if test "$host_cpu" = ia64; then
+	  # AIX 5 now supports IA64 processor
+	  _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+	else
+	  _LT_TAGVAR(lt_prog_compiler_static, $1)='-bnso -bI:/lib/syscalls.exp'
+	fi
+	;;
+      chorus*)
+	case $cc_basename in
+	cxch68*)
+	  # Green Hills C++ Compiler
+	  # _LT_TAGVAR(lt_prog_compiler_static, $1)="--no_auto_instantiation -u __main -u __premain -u _abort -r $COOL_DIR/lib/libOrb.a $MVME_DIR/lib/CC/libC.a $MVME_DIR/lib/classix/libcx.s.a"
+	  ;;
+	esac
+	;;
+      dgux*)
+	case $cc_basename in
+	  ec++*)
+	    _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+	    ;;
+	  ghcx*)
+	    # Green Hills C++ Compiler
+	    _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic'
+	    ;;
+	  *)
+	    ;;
+	esac
+	;;
+      freebsd* | dragonfly*)
+	# FreeBSD uses GNU C++
+	;;
+      hpux9* | hpux10* | hpux11*)
+	case $cc_basename in
+	  CC*)
+	    _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+	    _LT_TAGVAR(lt_prog_compiler_static, $1)='${wl}-a ${wl}archive'
+	    if test "$host_cpu" != ia64; then
+	      _LT_TAGVAR(lt_prog_compiler_pic, $1)='+Z'
+	    fi
+	    ;;
+	  aCC*)
+	    _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+	    _LT_TAGVAR(lt_prog_compiler_static, $1)='${wl}-a ${wl}archive'
+	    case $host_cpu in
+	    hppa*64*|ia64*)
+	      # +Z the default
+	      ;;
+	    *)
+	      _LT_TAGVAR(lt_prog_compiler_pic, $1)='+Z'
+	      ;;
+	    esac
+	    ;;
+	  *)
+	    ;;
+	esac
+	;;
+      interix*)
+	# This is c89, which is MS Visual C++ (no shared libs)
+	# Anyone wants to do a port?
+	;;
+      irix5* | irix6* | nonstopux*)
+	case $cc_basename in
+	  CC*)
+	    _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+	    _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
+	    # CC pic flag -KPIC is the default.
+	    ;;
+	  *)
+	    ;;
+	esac
+	;;
+      linux* | k*bsd*-gnu)
+	case $cc_basename in
+	  KCC*)
+	    # KAI C++ Compiler
+	    _LT_TAGVAR(lt_prog_compiler_wl, $1)='--backend -Wl,'
+	    _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
+	    ;;
+	  ecpc* )
+	    # old Intel C++ for x86_64 which still supported -KPIC.
+	    _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+	    _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+	    _LT_TAGVAR(lt_prog_compiler_static, $1)='-static'
+	    ;;
+	  icpc* )
+	    # Intel C++, used to be incompatible with GCC.
+	    # ICC 10 doesn't accept -KPIC any more.
+	    _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+	    _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
+	    _LT_TAGVAR(lt_prog_compiler_static, $1)='-static'
+	    ;;
+	  pgCC* | pgcpp*)
+	    # Portland Group C++ compiler
+	    _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+	    _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fpic'
+	    _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+	    ;;
+	  cxx*)
+	    # Compaq C++
+	    # Make sure the PIC flag is empty.  It appears that all Alpha
+	    # Linux and Compaq Tru64 Unix objects are PIC.
+	    _LT_TAGVAR(lt_prog_compiler_pic, $1)=
+	    _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
+	    ;;
+	  xlc* | xlC*)
+	    # IBM XL 8.0 on PPC
+	    _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+	    _LT_TAGVAR(lt_prog_compiler_pic, $1)='-qpic'
+	    _LT_TAGVAR(lt_prog_compiler_static, $1)='-qstaticlink'
+	    ;;
+	  *)
+	    case `$CC -V 2>&1 | sed 5q` in
+	    *Sun\ C*)
+	      # Sun C++ 5.9
+	      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+	      _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+	      _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld '
+	      ;;
+	    esac
+	    ;;
+	esac
+	;;
+      lynxos*)
+	;;
+      m88k*)
+	;;
+      mvs*)
+	case $cc_basename in
+	  cxx*)
+	    _LT_TAGVAR(lt_prog_compiler_pic, $1)='-W c,exportall'
+	    ;;
+	  *)
+	    ;;
+	esac
+	;;
+      netbsd*)
+	;;
+      *qnx* | *nto*)
+        # QNX uses GNU C++, but need to define -shared option too, otherwise
+        # it will coredump.
+        _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared'
+        ;;
+      osf3* | osf4* | osf5*)
+	case $cc_basename in
+	  KCC*)
+	    _LT_TAGVAR(lt_prog_compiler_wl, $1)='--backend -Wl,'
+	    ;;
+	  RCC*)
+	    # Rational C++ 2.4.1
+	    _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic'
+	    ;;
+	  cxx*)
+	    # Digital/Compaq C++
+	    _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+	    # Make sure the PIC flag is empty.  It appears that all Alpha
+	    # Linux and Compaq Tru64 Unix objects are PIC.
+	    _LT_TAGVAR(lt_prog_compiler_pic, $1)=
+	    _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
+	    ;;
+	  *)
+	    ;;
+	esac
+	;;
+      psos*)
+	;;
+      solaris*)
+	case $cc_basename in
+	  CC*)
+	    # Sun C++ 4.2, 5.x and Centerline C++
+	    _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+	    _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+	    _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld '
+	    ;;
+	  gcx*)
+	    # Green Hills C++ Compiler
+	    _LT_TAGVAR(lt_prog_compiler_pic, $1)='-PIC'
+	    ;;
+	  *)
+	    ;;
+	esac
+	;;
+      sunos4*)
+	case $cc_basename in
+	  CC*)
+	    # Sun C++ 4.x
+	    _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic'
+	    _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+	    ;;
+	  lcc*)
+	    # Lucid
+	    _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic'
+	    ;;
+	  *)
+	    ;;
+	esac
+	;;
+      sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*)
+	case $cc_basename in
+	  CC*)
+	    _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+	    _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+	    _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+	    ;;
+	esac
+	;;
+      tandem*)
+	case $cc_basename in
+	  NCC*)
+	    # NonStop-UX NCC 3.20
+	    _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+	    ;;
+	  *)
+	    ;;
+	esac
+	;;
+      vxworks*)
+	;;
+      *)
+	_LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no
+	;;
+    esac
+  fi
+],
+[
+  if test "$GCC" = yes; then
+    _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+    _LT_TAGVAR(lt_prog_compiler_static, $1)='-static'
+
+    case $host_os in
+      aix*)
+      # All AIX code is PIC.
+      if test "$host_cpu" = ia64; then
+	# AIX 5 now supports IA64 processor
+	_LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+      fi
+      ;;
+
+    amigaos*)
+      case $host_cpu in
+      powerpc)
+            # see comment about AmigaOS4 .so support
+            _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
+        ;;
+      m68k)
+            # FIXME: we need at least 68020 code to build shared libraries, but
+            # adding the `-m68020' flag to GCC prevents building anything better,
+            # like `-m68040'.
+            _LT_TAGVAR(lt_prog_compiler_pic, $1)='-m68020 -resident32 -malways-restore-a4'
+        ;;
+      esac
+      ;;
+
+    beos* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*)
+      # PIC is the default for these OSes.
+      ;;
+
+    mingw* | cygwin* | pw32* | os2* | cegcc*)
+      # This hack is so that the source file can tell whether it is being
+      # built for inclusion in a dll (and should export symbols for example).
+      # Although the cygwin gcc ignores -fPIC, still need this for old-style
+      # (--disable-auto-import) libraries
+      m4_if([$1], [GCJ], [],
+	[_LT_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT'])
+      ;;
+
+    darwin* | rhapsody*)
+      # PIC is the default on this platform
+      # Common symbols not allowed in MH_DYLIB files
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fno-common'
+      ;;
+
+    hpux*)
+      # PIC is the default for 64-bit PA HP-UX, but not for 32-bit
+      # PA HP-UX.  On IA64 HP-UX, PIC is the default but the pic flag
+      # sets the default TLS model and affects inlining.
+      case $host_cpu in
+      hppa*64*)
+	# +Z the default
+	;;
+      *)
+	_LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
+	;;
+      esac
+      ;;
+
+    interix[[3-9]]*)
+      # Interix 3.x gcc -fpic/-fPIC options generate broken code.
+      # Instead, we relocate shared libraries at runtime.
+      ;;
+
+    msdosdjgpp*)
+      # Just because we use GCC doesn't mean we suddenly get shared libraries
+      # on systems that don't support them.
+      _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no
+      enable_shared=no
+      ;;
+
+    *nto* | *qnx*)
+      # QNX uses GNU C++, but need to define -shared option too, otherwise
+      # it will coredump.
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared'
+      ;;
+
+    sysv4*MP*)
+      if test -d /usr/nec; then
+	_LT_TAGVAR(lt_prog_compiler_pic, $1)=-Kconform_pic
+      fi
+      ;;
+
+    *)
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
+      ;;
+    esac
+  else
+    # PORTME Check for flag to pass linker flags through the system compiler.
+    case $host_os in
+    aix*)
+      _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+      if test "$host_cpu" = ia64; then
+	# AIX 5 now supports IA64 processor
+	_LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+      else
+	_LT_TAGVAR(lt_prog_compiler_static, $1)='-bnso -bI:/lib/syscalls.exp'
+      fi
+      ;;
+
+    mingw* | cygwin* | pw32* | os2* | cegcc*)
+      # This hack is so that the source file can tell whether it is being
+      # built for inclusion in a dll (and should export symbols for example).
+      m4_if([$1], [GCJ], [],
+	[_LT_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT'])
+      ;;
+
+    hpux9* | hpux10* | hpux11*)
+      _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+      # PIC is the default for IA64 HP-UX and 64-bit HP-UX, but
+      # not for PA HP-UX.
+      case $host_cpu in
+      hppa*64*|ia64*)
+	# +Z the default
+	;;
+      *)
+	_LT_TAGVAR(lt_prog_compiler_pic, $1)='+Z'
+	;;
+      esac
+      # Is there a better lt_prog_compiler_static that works with the bundled CC?
+      _LT_TAGVAR(lt_prog_compiler_static, $1)='${wl}-a ${wl}archive'
+      ;;
+
+    irix5* | irix6* | nonstopux*)
+      _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+      # PIC (with -KPIC) is the default.
+      _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
+      ;;
+
+    linux* | k*bsd*-gnu)
+      case $cc_basename in
+      # old Intel for x86_64 which still supported -KPIC.
+      ecc*)
+	_LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+	_LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+	_LT_TAGVAR(lt_prog_compiler_static, $1)='-static'
+        ;;
+      # icc used to be incompatible with GCC.
+      # ICC 10 doesn't accept -KPIC any more.
+      icc* | ifort*)
+	_LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+	_LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
+	_LT_TAGVAR(lt_prog_compiler_static, $1)='-static'
+        ;;
+      # Lahey Fortran 8.1.
+      lf95*)
+	_LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+	_LT_TAGVAR(lt_prog_compiler_pic, $1)='--shared'
+	_LT_TAGVAR(lt_prog_compiler_static, $1)='--static'
+	;;
+      pgcc* | pgf77* | pgf90* | pgf95*)
+        # Portland Group compilers (*not* the Pentium gcc compiler,
+	# which looks to be a dead project)
+	_LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+	_LT_TAGVAR(lt_prog_compiler_pic, $1)='-fpic'
+	_LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+        ;;
+      ccc*)
+        _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+        # All Alpha code is PIC.
+        _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
+        ;;
+      xl*)
+	# IBM XL C 8.0/Fortran 10.1 on PPC
+	_LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+	_LT_TAGVAR(lt_prog_compiler_pic, $1)='-qpic'
+	_LT_TAGVAR(lt_prog_compiler_static, $1)='-qstaticlink'
+	;;
+      *)
+	case `$CC -V 2>&1 | sed 5q` in
+	*Sun\ C*)
+	  # Sun C 5.9
+	  _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+	  _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+	  _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+	  ;;
+	*Sun\ F*)
+	  # Sun Fortran 8.3 passes all unrecognized flags to the linker
+	  _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+	  _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+	  _LT_TAGVAR(lt_prog_compiler_wl, $1)=''
+	  ;;
+	esac
+	;;
+      esac
+      ;;
+
+    newsos6)
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+      _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+      ;;
+
+    *nto* | *qnx*)
+      # QNX uses GNU C++, but need to define -shared option too, otherwise
+      # it will coredump.
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared'
+      ;;
+
+    osf3* | osf4* | osf5*)
+      _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+      # All OSF/1 code is PIC.
+      _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
+      ;;
+
+    rdos*)
+      _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
+      ;;
+
+    solaris*)
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+      _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+      case $cc_basename in
+      f77* | f90* | f95*)
+	_LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld ';;
+      *)
+	_LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,';;
+      esac
+      ;;
+
+    sunos4*)
+      _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld '
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-PIC'
+      _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+      ;;
+
+    sysv4 | sysv4.2uw2* | sysv4.3*)
+      _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+      _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+      ;;
+
+    sysv4*MP*)
+      if test -d /usr/nec ;then
+	_LT_TAGVAR(lt_prog_compiler_pic, $1)='-Kconform_pic'
+	_LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+      fi
+      ;;
+
+    sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*)
+      _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+      _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+      ;;
+
+    unicos*)
+      _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+      _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no
+      ;;
+
+    uts4*)
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic'
+      _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+      ;;
+
+    *)
+      _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no
+      ;;
+    esac
+  fi
+])
+case $host_os in
+  # For platforms which do not support PIC, -DPIC is meaningless:
+  *djgpp*)
+    _LT_TAGVAR(lt_prog_compiler_pic, $1)=
+    ;;
+  *)
+    _LT_TAGVAR(lt_prog_compiler_pic, $1)="$_LT_TAGVAR(lt_prog_compiler_pic, $1)@&t at m4_if([$1],[],[ -DPIC],[m4_if([$1],[CXX],[ -DPIC],[])])"
+    ;;
+esac
+AC_MSG_RESULT([$_LT_TAGVAR(lt_prog_compiler_pic, $1)])
+_LT_TAGDECL([wl], [lt_prog_compiler_wl], [1],
+	[How to pass a linker flag through the compiler])
+
+#
+# Check to make sure the PIC flag actually works.
+#
+if test -n "$_LT_TAGVAR(lt_prog_compiler_pic, $1)"; then
+  _LT_COMPILER_OPTION([if $compiler PIC flag $_LT_TAGVAR(lt_prog_compiler_pic, $1) works],
+    [_LT_TAGVAR(lt_cv_prog_compiler_pic_works, $1)],
+    [$_LT_TAGVAR(lt_prog_compiler_pic, $1)@&t at m4_if([$1],[],[ -DPIC],[m4_if([$1],[CXX],[ -DPIC],[])])], [],
+    [case $_LT_TAGVAR(lt_prog_compiler_pic, $1) in
+     "" | " "*) ;;
+     *) _LT_TAGVAR(lt_prog_compiler_pic, $1)=" $_LT_TAGVAR(lt_prog_compiler_pic, $1)" ;;
+     esac],
+    [_LT_TAGVAR(lt_prog_compiler_pic, $1)=
+     _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no])
+fi
+_LT_TAGDECL([pic_flag], [lt_prog_compiler_pic], [1],
+	[Additional compiler flags for building library objects])
+
+#
+# Check to make sure the static flag actually works.
+#
+wl=$_LT_TAGVAR(lt_prog_compiler_wl, $1) eval lt_tmp_static_flag=\"$_LT_TAGVAR(lt_prog_compiler_static, $1)\"
+_LT_LINKER_OPTION([if $compiler static flag $lt_tmp_static_flag works],
+  _LT_TAGVAR(lt_cv_prog_compiler_static_works, $1),
+  $lt_tmp_static_flag,
+  [],
+  [_LT_TAGVAR(lt_prog_compiler_static, $1)=])
+_LT_TAGDECL([link_static_flag], [lt_prog_compiler_static], [1],
+	[Compiler flag to prevent dynamic linking])
+])# _LT_COMPILER_PIC
+
+
+# _LT_LINKER_SHLIBS([TAGNAME])
+# ----------------------------
+# See if the linker supports building shared libraries.
+m4_defun([_LT_LINKER_SHLIBS],
+[AC_REQUIRE([LT_PATH_LD])dnl
+AC_REQUIRE([LT_PATH_NM])dnl
+m4_require([_LT_FILEUTILS_DEFAULTS])dnl
+m4_require([_LT_DECL_EGREP])dnl
+m4_require([_LT_DECL_SED])dnl
+m4_require([_LT_CMD_GLOBAL_SYMBOLS])dnl
+m4_require([_LT_TAG_COMPILER])dnl
+AC_MSG_CHECKING([whether the $compiler linker ($LD) supports shared libraries])
+m4_if([$1], [CXX], [
+  _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols'
+  case $host_os in
+  aix[[4-9]]*)
+    # If we're using GNU nm, then we don't want the "-C" option.
+    # -C means demangle to AIX nm, but means don't demangle with GNU nm
+    if $NM -V 2>&1 | $GREP 'GNU' > /dev/null; then
+      _LT_TAGVAR(export_symbols_cmds, $1)='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B")) && ([substr](\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols'
+    else
+      _LT_TAGVAR(export_symbols_cmds, $1)='$NM -BCpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B")) && ([substr](\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols'
+    fi
+    ;;
+  pw32*)
+    _LT_TAGVAR(export_symbols_cmds, $1)="$ltdll_cmds"
+  ;;
+  cygwin* | mingw* | cegcc*)
+    _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[[BCDGRS]][[ ]]/s/.*[[ ]]\([[^ ]]*\)/\1 DATA/;/^.*[[ ]]__nm__/s/^.*[[ ]]__nm__\([[^ ]]*\)[[ ]][[^ ]]*/\1 DATA/;/^I[[ ]]/d;/^[[AITW]][[ ]]/s/.* //'\'' | sort | uniq > $export_symbols'
+  ;;
+  *)
+    _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols'
+  ;;
+  esac
+  _LT_TAGVAR(exclude_expsyms, $1)=['_GLOBAL_OFFSET_TABLE_|_GLOBAL__F[ID]_.*']
+], [
+  runpath_var=
+  _LT_TAGVAR(allow_undefined_flag, $1)=
+  _LT_TAGVAR(always_export_symbols, $1)=no
+  _LT_TAGVAR(archive_cmds, $1)=
+  _LT_TAGVAR(archive_expsym_cmds, $1)=
+  _LT_TAGVAR(compiler_needs_object, $1)=no
+  _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no
+  _LT_TAGVAR(export_dynamic_flag_spec, $1)=
+  _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols'
+  _LT_TAGVAR(hardcode_automatic, $1)=no
+  _LT_TAGVAR(hardcode_direct, $1)=no
+  _LT_TAGVAR(hardcode_direct_absolute, $1)=no
+  _LT_TAGVAR(hardcode_libdir_flag_spec, $1)=
+  _LT_TAGVAR(hardcode_libdir_flag_spec_ld, $1)=
+  _LT_TAGVAR(hardcode_libdir_separator, $1)=
+  _LT_TAGVAR(hardcode_minus_L, $1)=no
+  _LT_TAGVAR(hardcode_shlibpath_var, $1)=unsupported
+  _LT_TAGVAR(inherit_rpath, $1)=no
+  _LT_TAGVAR(link_all_deplibs, $1)=unknown
+  _LT_TAGVAR(module_cmds, $1)=
+  _LT_TAGVAR(module_expsym_cmds, $1)=
+  _LT_TAGVAR(old_archive_from_new_cmds, $1)=
+  _LT_TAGVAR(old_archive_from_expsyms_cmds, $1)=
+  _LT_TAGVAR(thread_safe_flag_spec, $1)=
+  _LT_TAGVAR(whole_archive_flag_spec, $1)=
+  # include_expsyms should be a list of space-separated symbols to be *always*
+  # included in the symbol list
+  _LT_TAGVAR(include_expsyms, $1)=
+  # exclude_expsyms can be an extended regexp of symbols to exclude
+  # it will be wrapped by ` (' and `)$', so one must not match beginning or
+  # end of line.  Example: `a|bc|.*d.*' will exclude the symbols `a' and `bc',
+  # as well as any symbol that contains `d'.
+  _LT_TAGVAR(exclude_expsyms, $1)=['_GLOBAL_OFFSET_TABLE_|_GLOBAL__F[ID]_.*']
+  # Although _GLOBAL_OFFSET_TABLE_ is a valid symbol C name, most a.out
+  # platforms (ab)use it in PIC code, but their linkers get confused if
+  # the symbol is explicitly referenced.  Since portable code cannot
+  # rely on this symbol name, it's probably fine to never include it in
+  # preloaded symbol tables.
+  # Exclude shared library initialization/finalization symbols.
+dnl Note also adjust exclude_expsyms for C++ above.
+  extract_expsyms_cmds=
+
+  case $host_os in
+  cygwin* | mingw* | pw32* | cegcc*)
+    # FIXME: the MSVC++ port hasn't been tested in a loooong time
+    # When not using gcc, we currently assume that we are using
+    # Microsoft Visual C++.
+    if test "$GCC" != yes; then
+      with_gnu_ld=no
+    fi
+    ;;
+  interix*)
+    # we just hope/assume this is gcc and not c89 (= MSVC++)
+    with_gnu_ld=yes
+    ;;
+  openbsd*)
+    with_gnu_ld=no
+    ;;
+  esac
+
+  _LT_TAGVAR(ld_shlibs, $1)=yes
+  if test "$with_gnu_ld" = yes; then
+    # If archive_cmds runs LD, not CC, wlarc should be empty
+    wlarc='${wl}'
+
+    # Set some defaults for GNU ld with shared library support. These
+    # are reset later if shared libraries are not supported. Putting them
+    # here allows them to be overridden if necessary.
+    runpath_var=LD_RUN_PATH
+    _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+    _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic'
+    # ancient GNU ld didn't support --whole-archive et. al.
+    if $LD --help 2>&1 | $GREP 'no-whole-archive' > /dev/null; then
+      _LT_TAGVAR(whole_archive_flag_spec, $1)="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive'
+    else
+      _LT_TAGVAR(whole_archive_flag_spec, $1)=
+    fi
+    supports_anon_versioning=no
+    case `$LD -v 2>&1` in
+      *\ [[01]].* | *\ 2.[[0-9]].* | *\ 2.10.*) ;; # catch versions < 2.11
+      *\ 2.11.93.0.2\ *) supports_anon_versioning=yes ;; # RH7.3 ...
+      *\ 2.11.92.0.12\ *) supports_anon_versioning=yes ;; # Mandrake 8.2 ...
+      *\ 2.11.*) ;; # other 2.11 versions
+      *) supports_anon_versioning=yes ;;
+    esac
+
+    # See if GNU ld supports shared libraries.
+    case $host_os in
+    aix[[3-9]]*)
+      # On AIX/PPC, the GNU linker is very broken
+      if test "$host_cpu" != ia64; then
+	_LT_TAGVAR(ld_shlibs, $1)=no
+	cat <<_LT_EOF 1>&2
+
+*** Warning: the GNU linker, at least up to release 2.9.1, is reported
+*** to be unable to reliably create shared libraries on AIX.
+*** Therefore, libtool is disabling shared libraries support.  If you
+*** really care for shared libraries, you may want to modify your PATH
+*** so that a non-GNU linker is found, and then restart.
+
+_LT_EOF
+      fi
+      ;;
+
+    amigaos*)
+      case $host_cpu in
+      powerpc)
+            # see comment about AmigaOS4 .so support
+            _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+            _LT_TAGVAR(archive_expsym_cmds, $1)=''
+        ;;
+      m68k)
+            _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/a2ixlibrary.data~$ECHO "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$ECHO "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$ECHO "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$ECHO "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)'
+            _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
+            _LT_TAGVAR(hardcode_minus_L, $1)=yes
+        ;;
+      esac
+      ;;
+
+    beos*)
+      if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then
+	_LT_TAGVAR(allow_undefined_flag, $1)=unsupported
+	# Joseph Beckenbach <jrb3 at best.com> says some releases of gcc
+	# support --undefined.  This deserves some investigation.  FIXME
+	_LT_TAGVAR(archive_cmds, $1)='$CC -nostart $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+      else
+	_LT_TAGVAR(ld_shlibs, $1)=no
+      fi
+      ;;
+
+    cygwin* | mingw* | pw32* | cegcc*)
+      # _LT_TAGVAR(hardcode_libdir_flag_spec, $1) is actually meaningless,
+      # as there is no search path for DLLs.
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
+      _LT_TAGVAR(allow_undefined_flag, $1)=unsupported
+      _LT_TAGVAR(always_export_symbols, $1)=no
+      _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes
+      _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[[BCDGRS]][[ ]]/s/.*[[ ]]\([[^ ]]*\)/\1 DATA/'\'' | $SED -e '\''/^[[AITW]][[ ]]/s/.*[[ ]]//'\'' | sort | uniq > $export_symbols'
+
+      if $LD --help 2>&1 | $GREP 'auto-import' > /dev/null; then
+        _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib'
+	# If the export-symbols file already is a .def file (1st line
+	# is EXPORTS), use it as is; otherwise, prepend...
+	_LT_TAGVAR(archive_expsym_cmds, $1)='if test "x`$SED 1q $export_symbols`" = xEXPORTS; then
+	  cp $export_symbols $output_objdir/$soname.def;
+	else
+	  echo EXPORTS > $output_objdir/$soname.def;
+	  cat $export_symbols >> $output_objdir/$soname.def;
+	fi~
+	$CC -shared $output_objdir/$soname.def $libobjs $deplibs $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib'
+      else
+	_LT_TAGVAR(ld_shlibs, $1)=no
+      fi
+      ;;
+
+    interix[[3-9]]*)
+      _LT_TAGVAR(hardcode_direct, $1)=no
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
+      _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
+      # Hack: On Interix 3.x, we cannot compile PIC because of a broken gcc.
+      # Instead, shared libraries are loaded at an image base (0x10000000 by
+      # default) and relocated if they conflict, which is a slow very memory
+      # consuming and fragmenting process.  To avoid this, we pick a random,
+      # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link
+      # time.  Moving up from 0x10000000 also allows more sbrk(2) space.
+      _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib'
+      _LT_TAGVAR(archive_expsym_cmds, $1)='sed "s,^,_," $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--retain-symbols-file,$output_objdir/$soname.expsym ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib'
+      ;;
+
+    gnu* | linux* | tpf* | k*bsd*-gnu)
+      tmp_diet=no
+      if test "$host_os" = linux-dietlibc; then
+	case $cc_basename in
+	  diet\ *) tmp_diet=yes;;	# linux-dietlibc with static linking (!diet-dyn)
+	esac
+      fi
+      if $LD --help 2>&1 | $EGREP ': supported targets:.* elf' > /dev/null \
+	 && test "$tmp_diet" = no
+      then
+	tmp_addflag=
+	tmp_sharedflag='-shared'
+	case $cc_basename,$host_cpu in
+        pgcc*)				# Portland Group C compiler
+	  _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`for conv in $convenience\"\"; do test  -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $ECHO \"$new_convenience\"` ${wl}--no-whole-archive'
+	  tmp_addflag=' $pic_flag'
+	  ;;
+	pgf77* | pgf90* | pgf95*)	# Portland Group f77 and f90 compilers
+	  _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`for conv in $convenience\"\"; do test  -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $ECHO \"$new_convenience\"` ${wl}--no-whole-archive'
+	  tmp_addflag=' $pic_flag -Mnomain' ;;
+	ecc*,ia64* | icc*,ia64*)	# Intel C compiler on ia64
+	  tmp_addflag=' -i_dynamic' ;;
+	efc*,ia64* | ifort*,ia64*)	# Intel Fortran compiler on ia64
+	  tmp_addflag=' -i_dynamic -nofor_main' ;;
+	ifc* | ifort*)			# Intel Fortran compiler
+	  tmp_addflag=' -nofor_main' ;;
+	lf95*)				# Lahey Fortran 8.1
+	  _LT_TAGVAR(whole_archive_flag_spec, $1)=
+	  tmp_sharedflag='--shared' ;;
+	xl[[cC]]*)			# IBM XL C 8.0 on PPC (deal with xlf below)
+	  tmp_sharedflag='-qmkshrobj'
+	  tmp_addflag= ;;
+	esac
+	case `$CC -V 2>&1 | sed 5q` in
+	*Sun\ C*)			# Sun C 5.9
+	  _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`new_convenience=; for conv in $convenience\"\"; do test -z \"$conv\" || new_convenience=\"$new_convenience,$conv\"; done; $ECHO \"$new_convenience\"` ${wl}--no-whole-archive'
+	  _LT_TAGVAR(compiler_needs_object, $1)=yes
+	  tmp_sharedflag='-G' ;;
+	*Sun\ F*)			# Sun Fortran 8.3
+	  tmp_sharedflag='-G' ;;
+	esac
+	_LT_TAGVAR(archive_cmds, $1)='$CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+
+        if test "x$supports_anon_versioning" = xyes; then
+          _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $output_objdir/$libname.ver~
+	    cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~
+	    echo "local: *; };" >> $output_objdir/$libname.ver~
+	    $CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-version-script ${wl}$output_objdir/$libname.ver -o $lib'
+        fi
+
+	case $cc_basename in
+	xlf*)
+	  # IBM XL Fortran 10.1 on PPC cannot create shared libs itself
+	  _LT_TAGVAR(whole_archive_flag_spec, $1)='--whole-archive$convenience --no-whole-archive'
+	  _LT_TAGVAR(hardcode_libdir_flag_spec, $1)=
+	  _LT_TAGVAR(hardcode_libdir_flag_spec_ld, $1)='-rpath $libdir'
+	  _LT_TAGVAR(archive_cmds, $1)='$LD -shared $libobjs $deplibs $compiler_flags -soname $soname -o $lib'
+	  if test "x$supports_anon_versioning" = xyes; then
+	    _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $output_objdir/$libname.ver~
+	      cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~
+	      echo "local: *; };" >> $output_objdir/$libname.ver~
+	      $LD -shared $libobjs $deplibs $compiler_flags -soname $soname -version-script $output_objdir/$libname.ver -o $lib'
+	  fi
+	  ;;
+	esac
+      else
+        _LT_TAGVAR(ld_shlibs, $1)=no
+      fi
+      ;;
+
+    netbsd*)
+      if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then
+	_LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable $libobjs $deplibs $linker_flags -o $lib'
+	wlarc=
+      else
+	_LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+	_LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+      fi
+      ;;
+
+    solaris*)
+      if $LD -v 2>&1 | $GREP 'BFD 2\.8' > /dev/null; then
+	_LT_TAGVAR(ld_shlibs, $1)=no
+	cat <<_LT_EOF 1>&2
+
+*** Warning: The releases 2.8.* of the GNU linker cannot reliably
+*** create shared libraries on Solaris systems.  Therefore, libtool
+*** is disabling shared libraries support.  We urge you to upgrade GNU
+*** binutils to release 2.9.1 or newer.  Another option is to modify
+*** your PATH or compiler configuration so that the native linker is
+*** used, and then restart.
+
+_LT_EOF
+      elif $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then
+	_LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+	_LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+      else
+	_LT_TAGVAR(ld_shlibs, $1)=no
+      fi
+      ;;
+
+    sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX*)
+      case `$LD -v 2>&1` in
+        *\ [[01]].* | *\ 2.[[0-9]].* | *\ 2.1[[0-5]].*)
+	_LT_TAGVAR(ld_shlibs, $1)=no
+	cat <<_LT_EOF 1>&2
+
+*** Warning: Releases of the GNU linker prior to 2.16.91.0.3 can not
+*** reliably create shared libraries on SCO systems.  Therefore, libtool
+*** is disabling shared libraries support.  We urge you to upgrade GNU
+*** binutils to release 2.16.91.0.3 or newer.  Another option is to modify
+*** your PATH or compiler configuration so that the native linker is
+*** used, and then restart.
+
+_LT_EOF
+	;;
+	*)
+	  # For security reasons, it is highly recommended that you always
+	  # use absolute paths for naming shared libraries, and exclude the
+	  # DT_RUNPATH tag from executables and libraries.  But doing so
+	  # requires that you compile everything twice, which is a pain.
+	  if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then
+	    _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+	    _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+	    _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+	  else
+	    _LT_TAGVAR(ld_shlibs, $1)=no
+	  fi
+	;;
+      esac
+      ;;
+
+    sunos4*)
+      _LT_TAGVAR(archive_cmds, $1)='$LD -assert pure-text -Bshareable -o $lib $libobjs $deplibs $linker_flags'
+      wlarc=
+      _LT_TAGVAR(hardcode_direct, $1)=yes
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      ;;
+
+    *)
+      if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then
+	_LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+	_LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+      else
+	_LT_TAGVAR(ld_shlibs, $1)=no
+      fi
+      ;;
+    esac
+
+    if test "$_LT_TAGVAR(ld_shlibs, $1)" = no; then
+      runpath_var=
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)=
+      _LT_TAGVAR(export_dynamic_flag_spec, $1)=
+      _LT_TAGVAR(whole_archive_flag_spec, $1)=
+    fi
+  else
+    # PORTME fill in a description of your system's linker (not GNU ld)
+    case $host_os in
+    aix3*)
+      _LT_TAGVAR(allow_undefined_flag, $1)=unsupported
+      _LT_TAGVAR(always_export_symbols, $1)=yes
+      _LT_TAGVAR(archive_expsym_cmds, $1)='$LD -o $output_objdir/$soname $libobjs $deplibs $linker_flags -bE:$export_symbols -T512 -H512 -bM:SRE~$AR $AR_FLAGS $lib $output_objdir/$soname'
+      # Note: this linker hardcodes the directories in LIBPATH if there
+      # are no directories specified by -L.
+      _LT_TAGVAR(hardcode_minus_L, $1)=yes
+      if test "$GCC" = yes && test -z "$lt_prog_compiler_static"; then
+	# Neither direct hardcoding nor static linking is supported with a
+	# broken collect2.
+	_LT_TAGVAR(hardcode_direct, $1)=unsupported
+      fi
+      ;;
+
+    aix[[4-9]]*)
+      if test "$host_cpu" = ia64; then
+	# On IA64, the linker does run time linking by default, so we don't
+	# have to do anything special.
+	aix_use_runtimelinking=no
+	exp_sym_flag='-Bexport'
+	no_entry_flag=""
+      else
+	# If we're using GNU nm, then we don't want the "-C" option.
+	# -C means demangle to AIX nm, but means don't demangle with GNU nm
+	if $NM -V 2>&1 | $GREP 'GNU' > /dev/null; then
+	  _LT_TAGVAR(export_symbols_cmds, $1)='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B")) && ([substr](\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols'
+	else
+	  _LT_TAGVAR(export_symbols_cmds, $1)='$NM -BCpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B")) && ([substr](\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols'
+	fi
+	aix_use_runtimelinking=no
+
+	# Test if we are trying to use run time linking or normal
+	# AIX style linking. If -brtl is somewhere in LDFLAGS, we
+	# need to do runtime linking.
+	case $host_os in aix4.[[23]]|aix4.[[23]].*|aix[[5-9]]*)
+	  for ld_flag in $LDFLAGS; do
+	  if (test $ld_flag = "-brtl" || test $ld_flag = "-Wl,-brtl"); then
+	    aix_use_runtimelinking=yes
+	    break
+	  fi
+	  done
+	  ;;
+	esac
+
+	exp_sym_flag='-bexport'
+	no_entry_flag='-bnoentry'
+      fi
+
+      # When large executables or shared objects are built, AIX ld can
+      # have problems creating the table of contents.  If linking a library
+      # or program results in "error TOC overflow" add -mminimal-toc to
+      # CXXFLAGS/CFLAGS for g++/gcc.  In the cases where that is not
+      # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS.
+
+      _LT_TAGVAR(archive_cmds, $1)=''
+      _LT_TAGVAR(hardcode_direct, $1)=yes
+      _LT_TAGVAR(hardcode_direct_absolute, $1)=yes
+      _LT_TAGVAR(hardcode_libdir_separator, $1)=':'
+      _LT_TAGVAR(link_all_deplibs, $1)=yes
+      _LT_TAGVAR(file_list_spec, $1)='${wl}-f,'
+
+      if test "$GCC" = yes; then
+	case $host_os in aix4.[[012]]|aix4.[[012]].*)
+	# We only want to do this on AIX 4.2 and lower, the check
+	# below for broken collect2 doesn't work under 4.3+
+	  collect2name=`${CC} -print-prog-name=collect2`
+	  if test -f "$collect2name" &&
+	   strings "$collect2name" | $GREP resolve_lib_name >/dev/null
+	  then
+	  # We have reworked collect2
+	  :
+	  else
+	  # We have old collect2
+	  _LT_TAGVAR(hardcode_direct, $1)=unsupported
+	  # It fails to find uninstalled libraries when the uninstalled
+	  # path is not listed in the libpath.  Setting hardcode_minus_L
+	  # to unsupported forces relinking
+	  _LT_TAGVAR(hardcode_minus_L, $1)=yes
+	  _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
+	  _LT_TAGVAR(hardcode_libdir_separator, $1)=
+	  fi
+	  ;;
+	esac
+	shared_flag='-shared'
+	if test "$aix_use_runtimelinking" = yes; then
+	  shared_flag="$shared_flag "'${wl}-G'
+	fi
+      else
+	# not using gcc
+	if test "$host_cpu" = ia64; then
+	# VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release
+	# chokes on -Wl,-G. The following line is correct:
+	  shared_flag='-G'
+	else
+	  if test "$aix_use_runtimelinking" = yes; then
+	    shared_flag='${wl}-G'
+	  else
+	    shared_flag='${wl}-bM:SRE'
+	  fi
+	fi
+      fi
+
+      _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-bexpall'
+      # It seems that -bexpall does not export symbols beginning with
+      # underscore (_), so it is better to generate a list of symbols to export.
+      _LT_TAGVAR(always_export_symbols, $1)=yes
+      if test "$aix_use_runtimelinking" = yes; then
+	# Warning - without using the other runtime loading flags (-brtl),
+	# -berok will link without error, but may produce a broken library.
+	_LT_TAGVAR(allow_undefined_flag, $1)='-berok'
+        # Determine the default libpath from the value encoded in an
+        # empty executable.
+        _LT_SYS_MODULE_PATH_AIX
+        _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath"
+        _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags `if test "x${allow_undefined_flag}" != "x"; then $ECHO "X${wl}${allow_undefined_flag}" | $Xsed; else :; fi` '"\${wl}$exp_sym_flag:\$export_symbols $shared_flag"
+      else
+	if test "$host_cpu" = ia64; then
+	  _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R $libdir:/usr/lib:/lib'
+	  _LT_TAGVAR(allow_undefined_flag, $1)="-z nodefs"
+	  _LT_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags ${wl}${allow_undefined_flag} '"\${wl}$exp_sym_flag:\$export_symbols"
+	else
+	 # Determine the default libpath from the value encoded in an
+	 # empty executable.
+	 _LT_SYS_MODULE_PATH_AIX
+	 _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath"
+	  # Warning - without using the other run time loading flags,
+	  # -berok will link without error, but may produce a broken library.
+	  _LT_TAGVAR(no_undefined_flag, $1)=' ${wl}-bernotok'
+	  _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-berok'
+	  # Exported symbols can be pulled into shared objects from archives
+	  _LT_TAGVAR(whole_archive_flag_spec, $1)='$convenience'
+	  _LT_TAGVAR(archive_cmds_need_lc, $1)=yes
+	  # This is similar to how AIX traditionally builds its shared libraries.
+	  _LT_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs ${wl}-bnoentry $compiler_flags ${wl}-bE:$export_symbols${allow_undefined_flag}~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$soname'
+	fi
+      fi
+      ;;
+
+    amigaos*)
+      case $host_cpu in
+      powerpc)
+            # see comment about AmigaOS4 .so support
+            _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+            _LT_TAGVAR(archive_expsym_cmds, $1)=''
+        ;;
+      m68k)
+            _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/a2ixlibrary.data~$ECHO "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$ECHO "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$ECHO "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$ECHO "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)'
+            _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
+            _LT_TAGVAR(hardcode_minus_L, $1)=yes
+        ;;
+      esac
+      ;;
+
+    bsdi[[45]]*)
+      _LT_TAGVAR(export_dynamic_flag_spec, $1)=-rdynamic
+      ;;
+
+    cygwin* | mingw* | pw32* | cegcc*)
+      # When not using gcc, we currently assume that we are using
+      # Microsoft Visual C++.
+      # hardcode_libdir_flag_spec is actually meaningless, as there is
+      # no search path for DLLs.
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)=' '
+      _LT_TAGVAR(allow_undefined_flag, $1)=unsupported
+      # Tell ltmain to make .lib files, not .a files.
+      libext=lib
+      # Tell ltmain to make .dll files, not .so files.
+      shrext_cmds=".dll"
+      # FIXME: Setting linknames here is a bad hack.
+      _LT_TAGVAR(archive_cmds, $1)='$CC -o $lib $libobjs $compiler_flags `$ECHO "X$deplibs" | $Xsed -e '\''s/ -lc$//'\''` -link -dll~linknames='
+      # The linker will automatically build a .lib file if we build a DLL.
+      _LT_TAGVAR(old_archive_from_new_cmds, $1)='true'
+      # FIXME: Should let the user specify the lib program.
+      _LT_TAGVAR(old_archive_cmds, $1)='lib -OUT:$oldlib$oldobjs$old_deplibs'
+      _LT_TAGVAR(fix_srcfile_path, $1)='`cygpath -w "$srcfile"`'
+      _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes
+      ;;
+
+    darwin* | rhapsody*)
+      _LT_DARWIN_LINKER_FEATURES($1)
+      ;;
+
+    dgux*)
+      _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      ;;
+
+    freebsd1*)
+      _LT_TAGVAR(ld_shlibs, $1)=no
+      ;;
+
+    # FreeBSD 2.2.[012] allows us to include c++rt0.o to get C++ constructor
+    # support.  Future versions do this automatically, but an explicit c++rt0.o
+    # does not break anything, and helps significantly (at the cost of a little
+    # extra space).
+    freebsd2.2*)
+      _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags /usr/lib/c++rt0.o'
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
+      _LT_TAGVAR(hardcode_direct, $1)=yes
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      ;;
+
+    # Unfortunately, older versions of FreeBSD 2 do not have this feature.
+    freebsd2*)
+      _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags'
+      _LT_TAGVAR(hardcode_direct, $1)=yes
+      _LT_TAGVAR(hardcode_minus_L, $1)=yes
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      ;;
+
+    # FreeBSD 3 and greater uses gcc -shared to do shared libraries.
+    freebsd* | dragonfly*)
+      _LT_TAGVAR(archive_cmds, $1)='$CC -shared -o $lib $libobjs $deplibs $compiler_flags'
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
+      _LT_TAGVAR(hardcode_direct, $1)=yes
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      ;;
+
+    hpux9*)
+      if test "$GCC" = yes; then
+	_LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$CC -shared -fPIC ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $libobjs $deplibs $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib'
+      else
+	_LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$LD -b +b $install_libdir -o $output_objdir/$soname $libobjs $deplibs $linker_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib'
+      fi
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir'
+      _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+      _LT_TAGVAR(hardcode_direct, $1)=yes
+
+      # hardcode_minus_L: Not really in the search PATH,
+      # but as the default location of the library.
+      _LT_TAGVAR(hardcode_minus_L, $1)=yes
+      _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
+      ;;
+
+    hpux10*)
+      if test "$GCC" = yes -a "$with_gnu_ld" = no; then
+	_LT_TAGVAR(archive_cmds, $1)='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags'
+      else
+	_LT_TAGVAR(archive_cmds, $1)='$LD -b +h $soname +b $install_libdir -o $lib $libobjs $deplibs $linker_flags'
+      fi
+      if test "$with_gnu_ld" = no; then
+	_LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir'
+	_LT_TAGVAR(hardcode_libdir_flag_spec_ld, $1)='+b $libdir'
+	_LT_TAGVAR(hardcode_libdir_separator, $1)=:
+	_LT_TAGVAR(hardcode_direct, $1)=yes
+	_LT_TAGVAR(hardcode_direct_absolute, $1)=yes
+	_LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
+	# hardcode_minus_L: Not really in the search PATH,
+	# but as the default location of the library.
+	_LT_TAGVAR(hardcode_minus_L, $1)=yes
+      fi
+      ;;
+
+    hpux11*)
+      if test "$GCC" = yes -a "$with_gnu_ld" = no; then
+	case $host_cpu in
+	hppa*64*)
+	  _LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}+h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags'
+	  ;;
+	ia64*)
+	  _LT_TAGVAR(archive_cmds, $1)='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags'
+	  ;;
+	*)
+	  _LT_TAGVAR(archive_cmds, $1)='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags'
+	  ;;
+	esac
+      else
+	case $host_cpu in
+	hppa*64*)
+	  _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags'
+	  ;;
+	ia64*)
+	  _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags'
+	  ;;
+	*)
+	  _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags'
+	  ;;
+	esac
+      fi
+      if test "$with_gnu_ld" = no; then
+	_LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir'
+	_LT_TAGVAR(hardcode_libdir_separator, $1)=:
+
+	case $host_cpu in
+	hppa*64*|ia64*)
+	  _LT_TAGVAR(hardcode_direct, $1)=no
+	  _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+	  ;;
+	*)
+	  _LT_TAGVAR(hardcode_direct, $1)=yes
+	  _LT_TAGVAR(hardcode_direct_absolute, $1)=yes
+	  _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
+
+	  # hardcode_minus_L: Not really in the search PATH,
+	  # but as the default location of the library.
+	  _LT_TAGVAR(hardcode_minus_L, $1)=yes
+	  ;;
+	esac
+      fi
+      ;;
+
+    irix5* | irix6* | nonstopux*)
+      if test "$GCC" = yes; then
+	_LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
+	# Try to use the -exported_symbol ld option, if it does not
+	# work, assume that -exports_file does not work either and
+	# implicitly export all symbols.
+        save_LDFLAGS="$LDFLAGS"
+        LDFLAGS="$LDFLAGS -shared ${wl}-exported_symbol ${wl}foo ${wl}-update_registry ${wl}/dev/null"
+        AC_LINK_IFELSE(int foo(void) {},
+          _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations ${wl}-exports_file ${wl}$export_symbols -o $lib'
+        )
+        LDFLAGS="$save_LDFLAGS"
+      else
+	_LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib'
+	_LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -exports_file $export_symbols -o $lib'
+      fi
+      _LT_TAGVAR(archive_cmds_need_lc, $1)='no'
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+      _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+      _LT_TAGVAR(inherit_rpath, $1)=yes
+      _LT_TAGVAR(link_all_deplibs, $1)=yes
+      ;;
+
+    netbsd*)
+      if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then
+	_LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags'  # a.out
+      else
+	_LT_TAGVAR(archive_cmds, $1)='$LD -shared -o $lib $libobjs $deplibs $linker_flags'      # ELF
+      fi
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
+      _LT_TAGVAR(hardcode_direct, $1)=yes
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      ;;
+
+    newsos6)
+      _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+      _LT_TAGVAR(hardcode_direct, $1)=yes
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+      _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      ;;
+
+    *nto* | *qnx*)
+      ;;
+
+    openbsd*)
+      if test -f /usr/libexec/ld.so; then
+	_LT_TAGVAR(hardcode_direct, $1)=yes
+	_LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+	_LT_TAGVAR(hardcode_direct_absolute, $1)=yes
+	if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
+	  _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags'
+	  _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-retain-symbols-file,$export_symbols'
+	  _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
+	  _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
+	else
+	  case $host_os in
+	   openbsd[[01]].* | openbsd2.[[0-7]] | openbsd2.[[0-7]].*)
+	     _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags'
+	     _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
+	     ;;
+	   *)
+	     _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags'
+	     _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
+	     ;;
+	  esac
+	fi
+      else
+	_LT_TAGVAR(ld_shlibs, $1)=no
+      fi
+      ;;
+
+    os2*)
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
+      _LT_TAGVAR(hardcode_minus_L, $1)=yes
+      _LT_TAGVAR(allow_undefined_flag, $1)=unsupported
+      _LT_TAGVAR(archive_cmds, $1)='$ECHO "LIBRARY $libname INITINSTANCE" > $output_objdir/$libname.def~$ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~$ECHO DATA >> $output_objdir/$libname.def~$ECHO " SINGLE NONSHARED" >> $output_objdir/$libname.def~$ECHO EXPORTS >> $output_objdir/$libname.def~emxexp $libobjs >> $output_objdir/$libname.def~$CC -Zdll -Zcrtdll -o $lib $libobjs $deplibs $compiler_flags $output_objdir/$libname.def'
+      _LT_TAGVAR(old_archive_from_new_cmds, $1)='emximp -o $output_objdir/$libname.a $output_objdir/$libname.def'
+      ;;
+
+    osf3*)
+      if test "$GCC" = yes; then
+	_LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*'
+	_LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
+      else
+	_LT_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*'
+	_LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib'
+      fi
+      _LT_TAGVAR(archive_cmds_need_lc, $1)='no'
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+      _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+      ;;
+
+    osf4* | osf5*)	# as osf3* with the addition of -msym flag
+      if test "$GCC" = yes; then
+	_LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*'
+	_LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags ${wl}-msym ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
+	_LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+      else
+	_LT_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*'
+	_LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags -msym -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib'
+	_LT_TAGVAR(archive_expsym_cmds, $1)='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done; printf "%s\\n" "-hidden">> $lib.exp~
+	$CC -shared${allow_undefined_flag} ${wl}-input ${wl}$lib.exp $compiler_flags $libobjs $deplibs -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib~$RM $lib.exp'
+
+	# Both c and cxx compiler support -rpath directly
+	_LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir'
+      fi
+      _LT_TAGVAR(archive_cmds_need_lc, $1)='no'
+      _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+      ;;
+
+    solaris*)
+      _LT_TAGVAR(no_undefined_flag, $1)=' -z defs'
+      if test "$GCC" = yes; then
+	wlarc='${wl}'
+	_LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-z ${wl}text ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags'
+	_LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~
+	  $CC -shared ${wl}-z ${wl}text ${wl}-M ${wl}$lib.exp ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags~$RM $lib.exp'
+      else
+	case `$CC -V 2>&1` in
+	*"Compilers 5.0"*)
+	  wlarc=''
+	  _LT_TAGVAR(archive_cmds, $1)='$LD -G${allow_undefined_flag} -h $soname -o $lib $libobjs $deplibs $linker_flags'
+	  _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~
+	  $LD -G${allow_undefined_flag} -M $lib.exp -h $soname -o $lib $libobjs $deplibs $linker_flags~$RM $lib.exp'
+	  ;;
+	*)
+	  wlarc='${wl}'
+	  _LT_TAGVAR(archive_cmds, $1)='$CC -G${allow_undefined_flag} -h $soname -o $lib $libobjs $deplibs $compiler_flags'
+	  _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~
+	  $CC -G${allow_undefined_flag} -M $lib.exp -h $soname -o $lib $libobjs $deplibs $compiler_flags~$RM $lib.exp'
+	  ;;
+	esac
+      fi
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      case $host_os in
+      solaris2.[[0-5]] | solaris2.[[0-5]].*) ;;
+      *)
+	# The compiler driver will combine and reorder linker options,
+	# but understands `-z linker_flag'.  GCC discards it without `$wl',
+	# but is careful enough not to reorder.
+	# Supported since Solaris 2.6 (maybe 2.5.1?)
+	if test "$GCC" = yes; then
+	  _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}-z ${wl}allextract$convenience ${wl}-z ${wl}defaultextract'
+	else
+	  _LT_TAGVAR(whole_archive_flag_spec, $1)='-z allextract$convenience -z defaultextract'
+	fi
+	;;
+      esac
+      _LT_TAGVAR(link_all_deplibs, $1)=yes
+      ;;
+
+    sunos4*)
+      if test "x$host_vendor" = xsequent; then
+	# Use $CC to link under sequent, because it throws in some extra .o
+	# files that make .init and .fini sections work.
+	_LT_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h $soname -o $lib $libobjs $deplibs $compiler_flags'
+      else
+	_LT_TAGVAR(archive_cmds, $1)='$LD -assert pure-text -Bstatic -o $lib $libobjs $deplibs $linker_flags'
+      fi
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
+      _LT_TAGVAR(hardcode_direct, $1)=yes
+      _LT_TAGVAR(hardcode_minus_L, $1)=yes
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      ;;
+
+    sysv4)
+      case $host_vendor in
+	sni)
+	  _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+	  _LT_TAGVAR(hardcode_direct, $1)=yes # is this really true???
+	;;
+	siemens)
+	  ## LD is ld it makes a PLAMLIB
+	  ## CC just makes a GrossModule.
+	  _LT_TAGVAR(archive_cmds, $1)='$LD -G -o $lib $libobjs $deplibs $linker_flags'
+	  _LT_TAGVAR(reload_cmds, $1)='$CC -r -o $output$reload_objs'
+	  _LT_TAGVAR(hardcode_direct, $1)=no
+        ;;
+	motorola)
+	  _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+	  _LT_TAGVAR(hardcode_direct, $1)=no #Motorola manual says yes, but my tests say they lie
+	;;
+      esac
+      runpath_var='LD_RUN_PATH'
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      ;;
+
+    sysv4.3*)
+      _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      _LT_TAGVAR(export_dynamic_flag_spec, $1)='-Bexport'
+      ;;
+
+    sysv4*MP*)
+      if test -d /usr/nec; then
+	_LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+	_LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+	runpath_var=LD_RUN_PATH
+	hardcode_runpath_var=yes
+	_LT_TAGVAR(ld_shlibs, $1)=yes
+      fi
+      ;;
+
+    sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[[01]].[[10]]* | unixware7* | sco3.2v5.0.[[024]]*)
+      _LT_TAGVAR(no_undefined_flag, $1)='${wl}-z,text'
+      _LT_TAGVAR(archive_cmds_need_lc, $1)=no
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      runpath_var='LD_RUN_PATH'
+
+      if test "$GCC" = yes; then
+	_LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+	_LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+      else
+	_LT_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+	_LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+      fi
+      ;;
+
+    sysv5* | sco3.2v5* | sco5v6*)
+      # Note: We can NOT use -z defs as we might desire, because we do not
+      # link with -lc, and that would cause any symbols used from libc to
+      # always be unresolved, which means just about no library would
+      # ever link correctly.  If we're not using GNU ld we use -z text
+      # though, which does catch some bad symbols but isn't as heavy-handed
+      # as -z defs.
+      _LT_TAGVAR(no_undefined_flag, $1)='${wl}-z,text'
+      _LT_TAGVAR(allow_undefined_flag, $1)='${wl}-z,nodefs'
+      _LT_TAGVAR(archive_cmds_need_lc, $1)=no
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R,$libdir'
+      _LT_TAGVAR(hardcode_libdir_separator, $1)=':'
+      _LT_TAGVAR(link_all_deplibs, $1)=yes
+      _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-Bexport'
+      runpath_var='LD_RUN_PATH'
+
+      if test "$GCC" = yes; then
+	_LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+	_LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+      else
+	_LT_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+	_LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+      fi
+      ;;
+
+    uts4*)
+      _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      ;;
+
+    *)
+      _LT_TAGVAR(ld_shlibs, $1)=no
+      ;;
+    esac
+
+    if test x$host_vendor = xsni; then
+      case $host in
+      sysv4 | sysv4.2uw2* | sysv4.3* | sysv5*)
+	_LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-Blargedynsym'
+	;;
+      esac
+    fi
+  fi
+])
+AC_MSG_RESULT([$_LT_TAGVAR(ld_shlibs, $1)])
+test "$_LT_TAGVAR(ld_shlibs, $1)" = no && can_build_shared=no
+
+_LT_TAGVAR(with_gnu_ld, $1)=$with_gnu_ld
+
+_LT_DECL([], [libext], [0], [Old archive suffix (normally "a")])dnl
+_LT_DECL([], [shrext_cmds], [1], [Shared library suffix (normally ".so")])dnl
+_LT_DECL([], [extract_expsyms_cmds], [2],
+    [The commands to extract the exported symbol list from a shared archive])
+
+#
+# Do we need to explicitly link libc?
+#
+case "x$_LT_TAGVAR(archive_cmds_need_lc, $1)" in
+x|xyes)
+  # Assume -lc should be added
+  _LT_TAGVAR(archive_cmds_need_lc, $1)=yes
+
+  if test "$enable_shared" = yes && test "$GCC" = yes; then
+    case $_LT_TAGVAR(archive_cmds, $1) in
+    *'~'*)
+      # FIXME: we may have to deal with multi-command sequences.
+      ;;
+    '$CC '*)
+      # Test whether the compiler implicitly links with -lc since on some
+      # systems, -lgcc has to come before -lc. If gcc already passes -lc
+      # to ld, don't add -lc before -lgcc.
+      AC_MSG_CHECKING([whether -lc should be explicitly linked in])
+      $RM conftest*
+      echo "$lt_simple_compile_test_code" > conftest.$ac_ext
+
+      if AC_TRY_EVAL(ac_compile) 2>conftest.err; then
+        soname=conftest
+        lib=conftest
+        libobjs=conftest.$ac_objext
+        deplibs=
+        wl=$_LT_TAGVAR(lt_prog_compiler_wl, $1)
+	pic_flag=$_LT_TAGVAR(lt_prog_compiler_pic, $1)
+        compiler_flags=-v
+        linker_flags=-v
+        verstring=
+        output_objdir=.
+        libname=conftest
+        lt_save_allow_undefined_flag=$_LT_TAGVAR(allow_undefined_flag, $1)
+        _LT_TAGVAR(allow_undefined_flag, $1)=
+        if AC_TRY_EVAL(_LT_TAGVAR(archive_cmds, $1) 2\>\&1 \| $GREP \" -lc \" \>/dev/null 2\>\&1)
+        then
+	  _LT_TAGVAR(archive_cmds_need_lc, $1)=no
+        else
+	  _LT_TAGVAR(archive_cmds_need_lc, $1)=yes
+        fi
+        _LT_TAGVAR(allow_undefined_flag, $1)=$lt_save_allow_undefined_flag
+      else
+        cat conftest.err 1>&5
+      fi
+      $RM conftest*
+      AC_MSG_RESULT([$_LT_TAGVAR(archive_cmds_need_lc, $1)])
+      ;;
+    esac
+  fi
+  ;;
+esac
+
+_LT_TAGDECL([build_libtool_need_lc], [archive_cmds_need_lc], [0],
+    [Whether or not to add -lc for building shared libraries])
+_LT_TAGDECL([allow_libtool_libs_with_static_runtimes],
+    [enable_shared_with_static_runtimes], [0],
+    [Whether or not to disallow shared libs when runtime libs are static])
+_LT_TAGDECL([], [export_dynamic_flag_spec], [1],
+    [Compiler flag to allow reflexive dlopens])
+_LT_TAGDECL([], [whole_archive_flag_spec], [1],
+    [Compiler flag to generate shared objects directly from archives])
+_LT_TAGDECL([], [compiler_needs_object], [1],
+    [Whether the compiler copes with passing no objects directly])
+_LT_TAGDECL([], [old_archive_from_new_cmds], [2],
+    [Create an old-style archive from a shared archive])
+_LT_TAGDECL([], [old_archive_from_expsyms_cmds], [2],
+    [Create a temporary old-style archive to link instead of a shared archive])
+_LT_TAGDECL([], [archive_cmds], [2], [Commands used to build a shared archive])
+_LT_TAGDECL([], [archive_expsym_cmds], [2])
+_LT_TAGDECL([], [module_cmds], [2],
+    [Commands used to build a loadable module if different from building
+    a shared archive.])
+_LT_TAGDECL([], [module_expsym_cmds], [2])
+_LT_TAGDECL([], [with_gnu_ld], [1],
+    [Whether we are building with GNU ld or not])
+_LT_TAGDECL([], [allow_undefined_flag], [1],
+    [Flag that allows shared libraries with undefined symbols to be built])
+_LT_TAGDECL([], [no_undefined_flag], [1],
+    [Flag that enforces no undefined symbols])
+_LT_TAGDECL([], [hardcode_libdir_flag_spec], [1],
+    [Flag to hardcode $libdir into a binary during linking.
+    This must work even if $libdir does not exist])
+_LT_TAGDECL([], [hardcode_libdir_flag_spec_ld], [1],
+    [[If ld is used when linking, flag to hardcode $libdir into a binary
+    during linking.  This must work even if $libdir does not exist]])
+_LT_TAGDECL([], [hardcode_libdir_separator], [1],
+    [Whether we need a single "-rpath" flag with a separated argument])
+_LT_TAGDECL([], [hardcode_direct], [0],
+    [Set to "yes" if using DIR/libNAME${shared_ext} during linking hardcodes
+    DIR into the resulting binary])
+_LT_TAGDECL([], [hardcode_direct_absolute], [0],
+    [Set to "yes" if using DIR/libNAME${shared_ext} during linking hardcodes
+    DIR into the resulting binary and the resulting library dependency is
+    "absolute", i.e impossible to change by setting ${shlibpath_var} if the
+    library is relocated])
+_LT_TAGDECL([], [hardcode_minus_L], [0],
+    [Set to "yes" if using the -LDIR flag during linking hardcodes DIR
+    into the resulting binary])
+_LT_TAGDECL([], [hardcode_shlibpath_var], [0],
+    [Set to "yes" if using SHLIBPATH_VAR=DIR during linking hardcodes DIR
+    into the resulting binary])
+_LT_TAGDECL([], [hardcode_automatic], [0],
+    [Set to "yes" if building a shared library automatically hardcodes DIR
+    into the library and all subsequent libraries and executables linked
+    against it])
+_LT_TAGDECL([], [inherit_rpath], [0],
+    [Set to yes if linker adds runtime paths of dependent libraries
+    to runtime path list])
+_LT_TAGDECL([], [link_all_deplibs], [0],
+    [Whether libtool must link a program against all its dependency libraries])
+_LT_TAGDECL([], [fix_srcfile_path], [1],
+    [Fix the shell variable $srcfile for the compiler])
+_LT_TAGDECL([], [always_export_symbols], [0],
+    [Set to "yes" if exported symbols are required])
+_LT_TAGDECL([], [export_symbols_cmds], [2],
+    [The commands to list exported symbols])
+_LT_TAGDECL([], [exclude_expsyms], [1],
+    [Symbols that should not be listed in the preloaded symbols])
+_LT_TAGDECL([], [include_expsyms], [1],
+    [Symbols that must always be exported])
+_LT_TAGDECL([], [prelink_cmds], [2],
+    [Commands necessary for linking programs (against libraries) with templates])
+_LT_TAGDECL([], [file_list_spec], [1],
+    [Specify filename containing input files])
+dnl FIXME: Not yet implemented
+dnl _LT_TAGDECL([], [thread_safe_flag_spec], [1],
+dnl    [Compiler flag to generate thread safe objects])
+])# _LT_LINKER_SHLIBS
+
+
+# _LT_LANG_C_CONFIG([TAG])
+# ------------------------
+# Ensure that the configuration variables for a C compiler are suitably
+# defined.  These variables are subsequently used by _LT_CONFIG to write
+# the compiler configuration to `libtool'.
+m4_defun([_LT_LANG_C_CONFIG],
+[m4_require([_LT_DECL_EGREP])dnl
+lt_save_CC="$CC"
+AC_LANG_PUSH(C)
+
+# Source file extension for C test sources.
+ac_ext=c
+
+# Object file extension for compiled C test sources.
+objext=o
+_LT_TAGVAR(objext, $1)=$objext
+
+# Code to be used in simple compile tests
+lt_simple_compile_test_code="int some_variable = 0;"
+
+# Code to be used in simple link tests
+lt_simple_link_test_code='int main(){return(0);}'
+
+_LT_TAG_COMPILER
+# Save the default compiler, since it gets overwritten when the other
+# tags are being tested, and _LT_TAGVAR(compiler, []) is a NOP.
+compiler_DEFAULT=$CC
+
+# save warnings/boilerplate of simple test code
+_LT_COMPILER_BOILERPLATE
+_LT_LINKER_BOILERPLATE
+
+## CAVEAT EMPTOR:
+## There is no encapsulation within the following macros, do not change
+## the running order or otherwise move them around unless you know exactly
+## what you are doing...
+if test -n "$compiler"; then
+  _LT_COMPILER_NO_RTTI($1)
+  _LT_COMPILER_PIC($1)
+  _LT_COMPILER_C_O($1)
+  _LT_COMPILER_FILE_LOCKS($1)
+  _LT_LINKER_SHLIBS($1)
+  _LT_SYS_DYNAMIC_LINKER($1)
+  _LT_LINKER_HARDCODE_LIBPATH($1)
+  LT_SYS_DLOPEN_SELF
+  _LT_CMD_STRIPLIB
+
+  # Report which library types will actually be built
+  AC_MSG_CHECKING([if libtool supports shared libraries])
+  AC_MSG_RESULT([$can_build_shared])
+
+  AC_MSG_CHECKING([whether to build shared libraries])
+  test "$can_build_shared" = "no" && enable_shared=no
+
+  # On AIX, shared libraries and static libraries use the same namespace, and
+  # are all built from PIC.
+  case $host_os in
+  aix3*)
+    test "$enable_shared" = yes && enable_static=no
+    if test -n "$RANLIB"; then
+      archive_cmds="$archive_cmds~\$RANLIB \$lib"
+      postinstall_cmds='$RANLIB $lib'
+    fi
+    ;;
+
+  aix[[4-9]]*)
+    if test "$host_cpu" != ia64 && test "$aix_use_runtimelinking" = no ; then
+      test "$enable_shared" = yes && enable_static=no
+    fi
+    ;;
+  esac
+  AC_MSG_RESULT([$enable_shared])
+
+  AC_MSG_CHECKING([whether to build static libraries])
+  # Make sure either enable_shared or enable_static is yes.
+  test "$enable_shared" = yes || enable_static=yes
+  AC_MSG_RESULT([$enable_static])
+
+  _LT_CONFIG($1)
+fi
+AC_LANG_POP
+CC="$lt_save_CC"
+])# _LT_LANG_C_CONFIG
+
+
+# _LT_PROG_CXX
+# ------------
+# Since AC_PROG_CXX is broken, in that it returns g++ if there is no c++
+# compiler, we have our own version here.
+m4_defun([_LT_PROG_CXX],
+[
+pushdef([AC_MSG_ERROR], [_lt_caught_CXX_error=yes])
+AC_PROG_CXX
+if test -n "$CXX" && ( test "X$CXX" != "Xno" &&
+    ( (test "X$CXX" = "Xg++" && `g++ -v >/dev/null 2>&1` ) ||
+    (test "X$CXX" != "Xg++"))) ; then
+  AC_PROG_CXXCPP
+else
+  _lt_caught_CXX_error=yes
+fi
+popdef([AC_MSG_ERROR])
+])# _LT_PROG_CXX
+
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([_LT_PROG_CXX], [])
+
+
+# _LT_LANG_CXX_CONFIG([TAG])
+# --------------------------
+# Ensure that the configuration variables for a C++ compiler are suitably
+# defined.  These variables are subsequently used by _LT_CONFIG to write
+# the compiler configuration to `libtool'.
+m4_defun([_LT_LANG_CXX_CONFIG],
+[AC_REQUIRE([_LT_PROG_CXX])dnl
+m4_require([_LT_FILEUTILS_DEFAULTS])dnl
+m4_require([_LT_DECL_EGREP])dnl
+
+AC_LANG_PUSH(C++)
+_LT_TAGVAR(archive_cmds_need_lc, $1)=no
+_LT_TAGVAR(allow_undefined_flag, $1)=
+_LT_TAGVAR(always_export_symbols, $1)=no
+_LT_TAGVAR(archive_expsym_cmds, $1)=
+_LT_TAGVAR(compiler_needs_object, $1)=no
+_LT_TAGVAR(export_dynamic_flag_spec, $1)=
+_LT_TAGVAR(hardcode_direct, $1)=no
+_LT_TAGVAR(hardcode_direct_absolute, $1)=no
+_LT_TAGVAR(hardcode_libdir_flag_spec, $1)=
+_LT_TAGVAR(hardcode_libdir_flag_spec_ld, $1)=
+_LT_TAGVAR(hardcode_libdir_separator, $1)=
+_LT_TAGVAR(hardcode_minus_L, $1)=no
+_LT_TAGVAR(hardcode_shlibpath_var, $1)=unsupported
+_LT_TAGVAR(hardcode_automatic, $1)=no
+_LT_TAGVAR(inherit_rpath, $1)=no
+_LT_TAGVAR(module_cmds, $1)=
+_LT_TAGVAR(module_expsym_cmds, $1)=
+_LT_TAGVAR(link_all_deplibs, $1)=unknown
+_LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds
+_LT_TAGVAR(no_undefined_flag, $1)=
+_LT_TAGVAR(whole_archive_flag_spec, $1)=
+_LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no
+
+# Source file extension for C++ test sources.
+ac_ext=cpp
+
+# Object file extension for compiled C++ test sources.
+objext=o
+_LT_TAGVAR(objext, $1)=$objext
+
+# No sense in running all these tests if we already determined that
+# the CXX compiler isn't working.  Some variables (like enable_shared)
+# are currently assumed to apply to all compilers on this platform,
+# and will be corrupted by setting them based on a non-working compiler.
+if test "$_lt_caught_CXX_error" != yes; then
+  # Code to be used in simple compile tests
+  lt_simple_compile_test_code="int some_variable = 0;"
+
+  # Code to be used in simple link tests
+  lt_simple_link_test_code='int main(int, char *[[]]) { return(0); }'
+
+  # ltmain only uses $CC for tagged configurations so make sure $CC is set.
+  _LT_TAG_COMPILER
+
+  # save warnings/boilerplate of simple test code
+  _LT_COMPILER_BOILERPLATE
+  _LT_LINKER_BOILERPLATE
+
+  # Allow CC to be a program name with arguments.
+  lt_save_CC=$CC
+  lt_save_LD=$LD
+  lt_save_GCC=$GCC
+  GCC=$GXX
+  lt_save_with_gnu_ld=$with_gnu_ld
+  lt_save_path_LD=$lt_cv_path_LD
+  if test -n "${lt_cv_prog_gnu_ldcxx+set}"; then
+    lt_cv_prog_gnu_ld=$lt_cv_prog_gnu_ldcxx
+  else
+    $as_unset lt_cv_prog_gnu_ld
+  fi
+  if test -n "${lt_cv_path_LDCXX+set}"; then
+    lt_cv_path_LD=$lt_cv_path_LDCXX
+  else
+    $as_unset lt_cv_path_LD
+  fi
+  test -z "${LDCXX+set}" || LD=$LDCXX
+  CC=${CXX-"c++"}
+  compiler=$CC
+  _LT_TAGVAR(compiler, $1)=$CC
+  _LT_CC_BASENAME([$compiler])
+
+  if test -n "$compiler"; then
+    # We don't want -fno-exception when compiling C++ code, so set the
+    # no_builtin_flag separately
+    if test "$GXX" = yes; then
+      _LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=' -fno-builtin'
+    else
+      _LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=
+    fi
+
+    if test "$GXX" = yes; then
+      # Set up default GNU C++ configuration
+
+      LT_PATH_LD
+
+      # Check if GNU C++ uses GNU ld as the underlying linker, since the
+      # archiving commands below assume that GNU ld is being used.
+      if test "$with_gnu_ld" = yes; then
+        _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib'
+        _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+
+        _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+        _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic'
+
+        # If archive_cmds runs LD, not CC, wlarc should be empty
+        # XXX I think wlarc can be eliminated in ltcf-cxx, but I need to
+        #     investigate it a little bit more. (MM)
+        wlarc='${wl}'
+
+        # ancient GNU ld didn't support --whole-archive et. al.
+        if eval "`$CC -print-prog-name=ld` --help 2>&1" |
+	  $GREP 'no-whole-archive' > /dev/null; then
+          _LT_TAGVAR(whole_archive_flag_spec, $1)="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive'
+        else
+          _LT_TAGVAR(whole_archive_flag_spec, $1)=
+        fi
+      else
+        with_gnu_ld=no
+        wlarc=
+
+        # A generic and very simple default shared library creation
+        # command for GNU C++ for the case where it uses the native
+        # linker, instead of GNU ld.  If possible, this setting should
+        # overridden to take advantage of the native linker features on
+        # the platform it is being used on.
+        _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $lib'
+      fi
+
+      # Commands to make compiler produce verbose output that lists
+      # what "hidden" libraries, object files and flags are used when
+      # linking a shared library.
+      output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "\-L"'
+
+    else
+      GXX=no
+      with_gnu_ld=no
+      wlarc=
+    fi
+
+    # PORTME: fill in a description of your system's C++ link characteristics
+    AC_MSG_CHECKING([whether the $compiler linker ($LD) supports shared libraries])
+    _LT_TAGVAR(ld_shlibs, $1)=yes
+    case $host_os in
+      aix3*)
+        # FIXME: insert proper C++ library support
+        _LT_TAGVAR(ld_shlibs, $1)=no
+        ;;
+      aix[[4-9]]*)
+        if test "$host_cpu" = ia64; then
+          # On IA64, the linker does run time linking by default, so we don't
+          # have to do anything special.
+          aix_use_runtimelinking=no
+          exp_sym_flag='-Bexport'
+          no_entry_flag=""
+        else
+          aix_use_runtimelinking=no
+
+          # Test if we are trying to use run time linking or normal
+          # AIX style linking. If -brtl is somewhere in LDFLAGS, we
+          # need to do runtime linking.
+          case $host_os in aix4.[[23]]|aix4.[[23]].*|aix[[5-9]]*)
+	    for ld_flag in $LDFLAGS; do
+	      case $ld_flag in
+	      *-brtl*)
+	        aix_use_runtimelinking=yes
+	        break
+	        ;;
+	      esac
+	    done
+	    ;;
+          esac
+
+          exp_sym_flag='-bexport'
+          no_entry_flag='-bnoentry'
+        fi
+
+        # When large executables or shared objects are built, AIX ld can
+        # have problems creating the table of contents.  If linking a library
+        # or program results in "error TOC overflow" add -mminimal-toc to
+        # CXXFLAGS/CFLAGS for g++/gcc.  In the cases where that is not
+        # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS.
+
+        _LT_TAGVAR(archive_cmds, $1)=''
+        _LT_TAGVAR(hardcode_direct, $1)=yes
+        _LT_TAGVAR(hardcode_direct_absolute, $1)=yes
+        _LT_TAGVAR(hardcode_libdir_separator, $1)=':'
+        _LT_TAGVAR(link_all_deplibs, $1)=yes
+        _LT_TAGVAR(file_list_spec, $1)='${wl}-f,'
+
+        if test "$GXX" = yes; then
+          case $host_os in aix4.[[012]]|aix4.[[012]].*)
+          # We only want to do this on AIX 4.2 and lower, the check
+          # below for broken collect2 doesn't work under 4.3+
+	  collect2name=`${CC} -print-prog-name=collect2`
+	  if test -f "$collect2name" &&
+	     strings "$collect2name" | $GREP resolve_lib_name >/dev/null
+	  then
+	    # We have reworked collect2
+	    :
+	  else
+	    # We have old collect2
+	    _LT_TAGVAR(hardcode_direct, $1)=unsupported
+	    # It fails to find uninstalled libraries when the uninstalled
+	    # path is not listed in the libpath.  Setting hardcode_minus_L
+	    # to unsupported forces relinking
+	    _LT_TAGVAR(hardcode_minus_L, $1)=yes
+	    _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
+	    _LT_TAGVAR(hardcode_libdir_separator, $1)=
+	  fi
+          esac
+          shared_flag='-shared'
+	  if test "$aix_use_runtimelinking" = yes; then
+	    shared_flag="$shared_flag "'${wl}-G'
+	  fi
+        else
+          # not using gcc
+          if test "$host_cpu" = ia64; then
+	  # VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release
+	  # chokes on -Wl,-G. The following line is correct:
+	  shared_flag='-G'
+          else
+	    if test "$aix_use_runtimelinking" = yes; then
+	      shared_flag='${wl}-G'
+	    else
+	      shared_flag='${wl}-bM:SRE'
+	    fi
+          fi
+        fi
+
+        _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-bexpall'
+        # It seems that -bexpall does not export symbols beginning with
+        # underscore (_), so it is better to generate a list of symbols to
+	# export.
+        _LT_TAGVAR(always_export_symbols, $1)=yes
+        if test "$aix_use_runtimelinking" = yes; then
+          # Warning - without using the other runtime loading flags (-brtl),
+          # -berok will link without error, but may produce a broken library.
+          _LT_TAGVAR(allow_undefined_flag, $1)='-berok'
+          # Determine the default libpath from the value encoded in an empty
+          # executable.
+          _LT_SYS_MODULE_PATH_AIX
+          _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath"
+
+          _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags `if test "x${allow_undefined_flag}" != "x"; then $ECHO "X${wl}${allow_undefined_flag}" | $Xsed; else :; fi` '"\${wl}$exp_sym_flag:\$export_symbols $shared_flag"
+        else
+          if test "$host_cpu" = ia64; then
+	    _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R $libdir:/usr/lib:/lib'
+	    _LT_TAGVAR(allow_undefined_flag, $1)="-z nodefs"
+	    _LT_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags ${wl}${allow_undefined_flag} '"\${wl}$exp_sym_flag:\$export_symbols"
+          else
+	    # Determine the default libpath from the value encoded in an
+	    # empty executable.
+	    _LT_SYS_MODULE_PATH_AIX
+	    _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath"
+	    # Warning - without using the other run time loading flags,
+	    # -berok will link without error, but may produce a broken library.
+	    _LT_TAGVAR(no_undefined_flag, $1)=' ${wl}-bernotok'
+	    _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-berok'
+	    # Exported symbols can be pulled into shared objects from archives
+	    _LT_TAGVAR(whole_archive_flag_spec, $1)='$convenience'
+	    _LT_TAGVAR(archive_cmds_need_lc, $1)=yes
+	    # This is similar to how AIX traditionally builds its shared
+	    # libraries.
+	    _LT_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs ${wl}-bnoentry $compiler_flags ${wl}-bE:$export_symbols${allow_undefined_flag}~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$soname'
+          fi
+        fi
+        ;;
+
+      beos*)
+	if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then
+	  _LT_TAGVAR(allow_undefined_flag, $1)=unsupported
+	  # Joseph Beckenbach <jrb3 at best.com> says some releases of gcc
+	  # support --undefined.  This deserves some investigation.  FIXME
+	  _LT_TAGVAR(archive_cmds, $1)='$CC -nostart $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+	else
+	  _LT_TAGVAR(ld_shlibs, $1)=no
+	fi
+	;;
+
+      chorus*)
+        case $cc_basename in
+          *)
+	  # FIXME: insert proper C++ library support
+	  _LT_TAGVAR(ld_shlibs, $1)=no
+	  ;;
+        esac
+        ;;
+
+      cygwin* | mingw* | pw32* | cegcc*)
+        # _LT_TAGVAR(hardcode_libdir_flag_spec, $1) is actually meaningless,
+        # as there is no search path for DLLs.
+        _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
+        _LT_TAGVAR(allow_undefined_flag, $1)=unsupported
+        _LT_TAGVAR(always_export_symbols, $1)=no
+        _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes
+
+        if $LD --help 2>&1 | $GREP 'auto-import' > /dev/null; then
+          _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib'
+          # If the export-symbols file already is a .def file (1st line
+          # is EXPORTS), use it as is; otherwise, prepend...
+          _LT_TAGVAR(archive_expsym_cmds, $1)='if test "x`$SED 1q $export_symbols`" = xEXPORTS; then
+	    cp $export_symbols $output_objdir/$soname.def;
+          else
+	    echo EXPORTS > $output_objdir/$soname.def;
+	    cat $export_symbols >> $output_objdir/$soname.def;
+          fi~
+          $CC -shared -nostdlib $output_objdir/$soname.def $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib'
+        else
+          _LT_TAGVAR(ld_shlibs, $1)=no
+        fi
+        ;;
+      darwin* | rhapsody*)
+        _LT_DARWIN_LINKER_FEATURES($1)
+	;;
+
+      dgux*)
+        case $cc_basename in
+          ec++*)
+	    # FIXME: insert proper C++ library support
+	    _LT_TAGVAR(ld_shlibs, $1)=no
+	    ;;
+          ghcx*)
+	    # Green Hills C++ Compiler
+	    # FIXME: insert proper C++ library support
+	    _LT_TAGVAR(ld_shlibs, $1)=no
+	    ;;
+          *)
+	    # FIXME: insert proper C++ library support
+	    _LT_TAGVAR(ld_shlibs, $1)=no
+	    ;;
+        esac
+        ;;
+
+      freebsd[[12]]*)
+        # C++ shared libraries reported to be fairly broken before
+	# switch to ELF
+        _LT_TAGVAR(ld_shlibs, $1)=no
+        ;;
+
+      freebsd-elf*)
+        _LT_TAGVAR(archive_cmds_need_lc, $1)=no
+        ;;
+
+      freebsd* | dragonfly*)
+        # FreeBSD 3 and later use GNU C++ and GNU ld with standard ELF
+        # conventions
+        _LT_TAGVAR(ld_shlibs, $1)=yes
+        ;;
+
+      gnu*)
+        ;;
+
+      hpux9*)
+        _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir'
+        _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+        _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
+        _LT_TAGVAR(hardcode_direct, $1)=yes
+        _LT_TAGVAR(hardcode_minus_L, $1)=yes # Not in the search PATH,
+				             # but as the default
+				             # location of the library.
+
+        case $cc_basename in
+          CC*)
+            # FIXME: insert proper C++ library support
+            _LT_TAGVAR(ld_shlibs, $1)=no
+            ;;
+          aCC*)
+            _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$CC -b ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib'
+            # Commands to make compiler produce verbose output that lists
+            # what "hidden" libraries, object files and flags are used when
+            # linking a shared library.
+            #
+            # There doesn't appear to be a way to prevent this compiler from
+            # explicitly linking system object files so we need to strip them
+            # from the output so that they don't get included in the library
+            # dependencies.
+            output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $EGREP "\-L"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; $ECHO "X$list" | $Xsed'
+            ;;
+          *)
+            if test "$GXX" = yes; then
+              _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$CC -shared -nostdlib -fPIC ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib'
+            else
+              # FIXME: insert proper C++ library support
+              _LT_TAGVAR(ld_shlibs, $1)=no
+            fi
+            ;;
+        esac
+        ;;
+
+      hpux10*|hpux11*)
+        if test $with_gnu_ld = no; then
+	  _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir'
+	  _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+
+          case $host_cpu in
+            hppa*64*|ia64*)
+              ;;
+            *)
+	      _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
+              ;;
+          esac
+        fi
+        case $host_cpu in
+          hppa*64*|ia64*)
+            _LT_TAGVAR(hardcode_direct, $1)=no
+            _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+            ;;
+          *)
+            _LT_TAGVAR(hardcode_direct, $1)=yes
+            _LT_TAGVAR(hardcode_direct_absolute, $1)=yes
+            _LT_TAGVAR(hardcode_minus_L, $1)=yes # Not in the search PATH,
+					         # but as the default
+					         # location of the library.
+            ;;
+        esac
+
+        case $cc_basename in
+          CC*)
+	    # FIXME: insert proper C++ library support
+	    _LT_TAGVAR(ld_shlibs, $1)=no
+	    ;;
+          aCC*)
+	    case $host_cpu in
+	      hppa*64*)
+	        _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
+	        ;;
+	      ia64*)
+	        _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
+	        ;;
+	      *)
+	        _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
+	        ;;
+	    esac
+	    # Commands to make compiler produce verbose output that lists
+	    # what "hidden" libraries, object files and flags are used when
+	    # linking a shared library.
+	    #
+	    # There doesn't appear to be a way to prevent this compiler from
+	    # explicitly linking system object files so we need to strip them
+	    # from the output so that they don't get included in the library
+	    # dependencies.
+	    output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $GREP "\-L"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; $ECHO "X$list" | $Xsed'
+	    ;;
+          *)
+	    if test "$GXX" = yes; then
+	      if test $with_gnu_ld = no; then
+	        case $host_cpu in
+	          hppa*64*)
+	            _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib -fPIC ${wl}+h ${wl}$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
+	            ;;
+	          ia64*)
+	            _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib -fPIC ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
+	            ;;
+	          *)
+	            _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
+	            ;;
+	        esac
+	      fi
+	    else
+	      # FIXME: insert proper C++ library support
+	      _LT_TAGVAR(ld_shlibs, $1)=no
+	    fi
+	    ;;
+        esac
+        ;;
+
+      interix[[3-9]]*)
+	_LT_TAGVAR(hardcode_direct, $1)=no
+	_LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+	_LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
+	_LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
+	# Hack: On Interix 3.x, we cannot compile PIC because of a broken gcc.
+	# Instead, shared libraries are loaded at an image base (0x10000000 by
+	# default) and relocated if they conflict, which is a slow very memory
+	# consuming and fragmenting process.  To avoid this, we pick a random,
+	# 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link
+	# time.  Moving up from 0x10000000 also allows more sbrk(2) space.
+	_LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib'
+	_LT_TAGVAR(archive_expsym_cmds, $1)='sed "s,^,_," $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--retain-symbols-file,$output_objdir/$soname.expsym ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib'
+	;;
+      irix5* | irix6*)
+        case $cc_basename in
+          CC*)
+	    # SGI C++
+	    _LT_TAGVAR(archive_cmds, $1)='$CC -shared -all -multigot $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib'
+
+	    # Archives containing C++ object files must be created using
+	    # "CC -ar", where "CC" is the IRIX C++ compiler.  This is
+	    # necessary to make sure instantiated templates are included
+	    # in the archive.
+	    _LT_TAGVAR(old_archive_cmds, $1)='$CC -ar -WR,-u -o $oldlib $oldobjs'
+	    ;;
+          *)
+	    if test "$GXX" = yes; then
+	      if test "$with_gnu_ld" = no; then
+	        _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
+	      else
+	        _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` -o $lib'
+	      fi
+	    fi
+	    _LT_TAGVAR(link_all_deplibs, $1)=yes
+	    ;;
+        esac
+        _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+        _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+        _LT_TAGVAR(inherit_rpath, $1)=yes
+        ;;
+
+      linux* | k*bsd*-gnu)
+        case $cc_basename in
+          KCC*)
+	    # Kuck and Associates, Inc. (KAI) C++ Compiler
+
+	    # KCC will only create a shared library if the output file
+	    # ends with ".so" (or ".sl" for HP-UX), so rename the library
+	    # to its proper name (with version) after linking.
+	    _LT_TAGVAR(archive_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib; mv \$templib $lib'
+	    _LT_TAGVAR(archive_expsym_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib ${wl}-retain-symbols-file,$export_symbols; mv \$templib $lib'
+	    # Commands to make compiler produce verbose output that lists
+	    # what "hidden" libraries, object files and flags are used when
+	    # linking a shared library.
+	    #
+	    # There doesn't appear to be a way to prevent this compiler from
+	    # explicitly linking system object files so we need to strip them
+	    # from the output so that they don't get included in the library
+	    # dependencies.
+	    output_verbose_link_cmd='templist=`$CC $CFLAGS -v conftest.$objext -o libconftest$shared_ext 2>&1 | $GREP "ld"`; rm -f libconftest$shared_ext; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; $ECHO "X$list" | $Xsed'
+
+	    _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
+	    _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic'
+
+	    # Archives containing C++ object files must be created using
+	    # "CC -Bstatic", where "CC" is the KAI C++ compiler.
+	    _LT_TAGVAR(old_archive_cmds, $1)='$CC -Bstatic -o $oldlib $oldobjs'
+	    ;;
+	  icpc* | ecpc* )
+	    # Intel C++
+	    with_gnu_ld=yes
+	    # version 8.0 and above of icpc choke on multiply defined symbols
+	    # if we add $predep_objects and $postdep_objects, however 7.1 and
+	    # earlier do not add the objects themselves.
+	    case `$CC -V 2>&1` in
+	      *"Version 7."*)
+	        _LT_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib'
+		_LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+		;;
+	      *)  # Version 8.0 or newer
+	        tmp_idyn=
+	        case $host_cpu in
+		  ia64*) tmp_idyn=' -i_dynamic';;
+		esac
+	        _LT_TAGVAR(archive_cmds, $1)='$CC -shared'"$tmp_idyn"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+		_LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared'"$tmp_idyn"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+		;;
+	    esac
+	    _LT_TAGVAR(archive_cmds_need_lc, $1)=no
+	    _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
+	    _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic'
+	    _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive$convenience ${wl}--no-whole-archive'
+	    ;;
+          pgCC* | pgcpp*)
+            # Portland Group C++ compiler
+	    case `$CC -V` in
+	    *pgCC\ [[1-5]]* | *pgcpp\ [[1-5]]*)
+	      _LT_TAGVAR(prelink_cmds, $1)='tpldir=Template.dir~
+		rm -rf $tpldir~
+		$CC --prelink_objects --instantiation_dir $tpldir $objs $libobjs $compile_deplibs~
+		compile_command="$compile_command `find $tpldir -name \*.o | $NL2SP`"'
+	      _LT_TAGVAR(old_archive_cmds, $1)='tpldir=Template.dir~
+		rm -rf $tpldir~
+		$CC --prelink_objects --instantiation_dir $tpldir $oldobjs$old_deplibs~
+		$AR $AR_FLAGS $oldlib$oldobjs$old_deplibs `find $tpldir -name \*.o | $NL2SP`~
+		$RANLIB $oldlib'
+	      _LT_TAGVAR(archive_cmds, $1)='tpldir=Template.dir~
+		rm -rf $tpldir~
+		$CC --prelink_objects --instantiation_dir $tpldir $predep_objects $libobjs $deplibs $convenience $postdep_objects~
+		$CC -shared $pic_flag $predep_objects $libobjs $deplibs `find $tpldir -name \*.o | $NL2SP` $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname -o $lib'
+	      _LT_TAGVAR(archive_expsym_cmds, $1)='tpldir=Template.dir~
+		rm -rf $tpldir~
+		$CC --prelink_objects --instantiation_dir $tpldir $predep_objects $libobjs $deplibs $convenience $postdep_objects~
+		$CC -shared $pic_flag $predep_objects $libobjs $deplibs `find $tpldir -name \*.o | $NL2SP` $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname ${wl}-retain-symbols-file ${wl}$export_symbols -o $lib'
+	      ;;
+	    *) # Version 6 will use weak symbols
+	      _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname -o $lib'
+	      _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname ${wl}-retain-symbols-file ${wl}$export_symbols -o $lib'
+	      ;;
+	    esac
+
+	    _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}--rpath ${wl}$libdir'
+	    _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic'
+	    _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`for conv in $convenience\"\"; do test  -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $ECHO \"$new_convenience\"` ${wl}--no-whole-archive'
+            ;;
+	  cxx*)
+	    # Compaq C++
+	    _LT_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib'
+	    _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname  -o $lib ${wl}-retain-symbols-file $wl$export_symbols'
+
+	    runpath_var=LD_RUN_PATH
+	    _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir'
+	    _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+
+	    # Commands to make compiler produce verbose output that lists
+	    # what "hidden" libraries, object files and flags are used when
+	    # linking a shared library.
+	    #
+	    # There doesn't appear to be a way to prevent this compiler from
+	    # explicitly linking system object files so we need to strip them
+	    # from the output so that they don't get included in the library
+	    # dependencies.
+	    output_verbose_link_cmd='templist=`$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "ld"`; templist=`$ECHO "X$templist" | $Xsed -e "s/\(^.*ld.*\)\( .*ld .*$\)/\1/"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; $ECHO "X$list" | $Xsed'
+	    ;;
+	  xl*)
+	    # IBM XL 8.0 on PPC, with GNU ld
+	    _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+	    _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic'
+	    _LT_TAGVAR(archive_cmds, $1)='$CC -qmkshrobj $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+	    if test "x$supports_anon_versioning" = xyes; then
+	      _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $output_objdir/$libname.ver~
+		cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~
+		echo "local: *; };" >> $output_objdir/$libname.ver~
+		$CC -qmkshrobj $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-version-script ${wl}$output_objdir/$libname.ver -o $lib'
+	    fi
+	    ;;
+	  *)
+	    case `$CC -V 2>&1 | sed 5q` in
+	    *Sun\ C*)
+	      # Sun C++ 5.9
+	      _LT_TAGVAR(no_undefined_flag, $1)=' -zdefs'
+	      _LT_TAGVAR(archive_cmds, $1)='$CC -G${allow_undefined_flag} -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
+	      _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G${allow_undefined_flag} -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-retain-symbols-file ${wl}$export_symbols'
+	      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
+	      _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`new_convenience=; for conv in $convenience\"\"; do test -z \"$conv\" || new_convenience=\"$new_convenience,$conv\"; done; $ECHO \"$new_convenience\"` ${wl}--no-whole-archive'
+	      _LT_TAGVAR(compiler_needs_object, $1)=yes
+
+	      # Not sure whether something based on
+	      # $CC $CFLAGS -v conftest.$objext -o libconftest$shared_ext 2>&1
+	      # would be better.
+	      output_verbose_link_cmd='echo'
+
+	      # Archives containing C++ object files must be created using
+	      # "CC -xar", where "CC" is the Sun C++ compiler.  This is
+	      # necessary to make sure instantiated templates are included
+	      # in the archive.
+	      _LT_TAGVAR(old_archive_cmds, $1)='$CC -xar -o $oldlib $oldobjs'
+	      ;;
+	    esac
+	    ;;
+	esac
+	;;
+
+      lynxos*)
+        # FIXME: insert proper C++ library support
+	_LT_TAGVAR(ld_shlibs, $1)=no
+	;;
+
+      m88k*)
+        # FIXME: insert proper C++ library support
+        _LT_TAGVAR(ld_shlibs, $1)=no
+	;;
+
+      mvs*)
+        case $cc_basename in
+          cxx*)
+	    # FIXME: insert proper C++ library support
+	    _LT_TAGVAR(ld_shlibs, $1)=no
+	    ;;
+	  *)
+	    # FIXME: insert proper C++ library support
+	    _LT_TAGVAR(ld_shlibs, $1)=no
+	    ;;
+	esac
+	;;
+
+      netbsd*)
+        if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then
+	  _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable  -o $lib $predep_objects $libobjs $deplibs $postdep_objects $linker_flags'
+	  wlarc=
+	  _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
+	  _LT_TAGVAR(hardcode_direct, $1)=yes
+	  _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+	fi
+	# Workaround some broken pre-1.5 toolchains
+	output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP conftest.$objext | $SED -e "s:-lgcc -lc -lgcc::"'
+	;;
+
+      *nto* | *qnx*)
+        _LT_TAGVAR(ld_shlibs, $1)=yes
+	;;
+
+      openbsd2*)
+        # C++ shared libraries are fairly broken
+	_LT_TAGVAR(ld_shlibs, $1)=no
+	;;
+
+      openbsd*)
+	if test -f /usr/libexec/ld.so; then
+	  _LT_TAGVAR(hardcode_direct, $1)=yes
+	  _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+	  _LT_TAGVAR(hardcode_direct_absolute, $1)=yes
+	  _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $lib'
+	  _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
+	  if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
+	    _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-retain-symbols-file,$export_symbols -o $lib'
+	    _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
+	    _LT_TAGVAR(whole_archive_flag_spec, $1)="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive'
+	  fi
+	  output_verbose_link_cmd=echo
+	else
+	  _LT_TAGVAR(ld_shlibs, $1)=no
+	fi
+	;;
+
+      osf3* | osf4* | osf5*)
+        case $cc_basename in
+          KCC*)
+	    # Kuck and Associates, Inc. (KAI) C++ Compiler
+
+	    # KCC will only create a shared library if the output file
+	    # ends with ".so" (or ".sl" for HP-UX), so rename the library
+	    # to its proper name (with version) after linking.
+	    _LT_TAGVAR(archive_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo "$lib" | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib; mv \$templib $lib'
+
+	    _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
+	    _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+
+	    # Archives containing C++ object files must be created using
+	    # the KAI C++ compiler.
+	    case $host in
+	      osf3*) _LT_TAGVAR(old_archive_cmds, $1)='$CC -Bstatic -o $oldlib $oldobjs' ;;
+	      *) _LT_TAGVAR(old_archive_cmds, $1)='$CC -o $oldlib $oldobjs' ;;
+	    esac
+	    ;;
+          RCC*)
+	    # Rational C++ 2.4.1
+	    # FIXME: insert proper C++ library support
+	    _LT_TAGVAR(ld_shlibs, $1)=no
+	    ;;
+          cxx*)
+	    case $host in
+	      osf3*)
+	        _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*'
+	        _LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $soname `test -n "$verstring" && $ECHO "X${wl}-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib'
+	        _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+		;;
+	      *)
+	        _LT_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*'
+	        _LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -msym -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib'
+	        _LT_TAGVAR(archive_expsym_cmds, $1)='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done~
+	          echo "-hidden">> $lib.exp~
+	          $CC -shared$allow_undefined_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -msym -soname $soname ${wl}-input ${wl}$lib.exp  `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib~
+	          $RM $lib.exp'
+	        _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir'
+		;;
+	    esac
+
+	    _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+
+	    # Commands to make compiler produce verbose output that lists
+	    # what "hidden" libraries, object files and flags are used when
+	    # linking a shared library.
+	    #
+	    # There doesn't appear to be a way to prevent this compiler from
+	    # explicitly linking system object files so we need to strip them
+	    # from the output so that they don't get included in the library
+	    # dependencies.
+	    output_verbose_link_cmd='templist=`$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "ld" | $GREP -v "ld:"`; templist=`$ECHO "X$templist" | $Xsed -e "s/\(^.*ld.*\)\( .*ld.*$\)/\1/"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; $ECHO "X$list" | $Xsed'
+	    ;;
+	  *)
+	    if test "$GXX" = yes && test "$with_gnu_ld" = no; then
+	      _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*'
+	      case $host in
+	        osf3*)
+	          _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib ${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
+		  ;;
+	        *)
+	          _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib ${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-msym ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
+		  ;;
+	      esac
+
+	      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+	      _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+
+	      # Commands to make compiler produce verbose output that lists
+	      # what "hidden" libraries, object files and flags are used when
+	      # linking a shared library.
+	      output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "\-L"'
+
+	    else
+	      # FIXME: insert proper C++ library support
+	      _LT_TAGVAR(ld_shlibs, $1)=no
+	    fi
+	    ;;
+        esac
+        ;;
+
+      psos*)
+        # FIXME: insert proper C++ library support
+        _LT_TAGVAR(ld_shlibs, $1)=no
+        ;;
+
+      sunos4*)
+        case $cc_basename in
+          CC*)
+	    # Sun C++ 4.x
+	    # FIXME: insert proper C++ library support
+	    _LT_TAGVAR(ld_shlibs, $1)=no
+	    ;;
+          lcc*)
+	    # Lucid
+	    # FIXME: insert proper C++ library support
+	    _LT_TAGVAR(ld_shlibs, $1)=no
+	    ;;
+          *)
+	    # FIXME: insert proper C++ library support
+	    _LT_TAGVAR(ld_shlibs, $1)=no
+	    ;;
+        esac
+        ;;
+
+      solaris*)
+        case $cc_basename in
+          CC*)
+	    # Sun C++ 4.2, 5.x and Centerline C++
+            _LT_TAGVAR(archive_cmds_need_lc,$1)=yes
+	    _LT_TAGVAR(no_undefined_flag, $1)=' -zdefs'
+	    _LT_TAGVAR(archive_cmds, $1)='$CC -G${allow_undefined_flag}  -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
+	    _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~
+	      $CC -G${allow_undefined_flag} ${wl}-M ${wl}$lib.exp -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$RM $lib.exp'
+
+	    _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
+	    _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+	    case $host_os in
+	      solaris2.[[0-5]] | solaris2.[[0-5]].*) ;;
+	      *)
+		# The compiler driver will combine and reorder linker options,
+		# but understands `-z linker_flag'.
+	        # Supported since Solaris 2.6 (maybe 2.5.1?)
+		_LT_TAGVAR(whole_archive_flag_spec, $1)='-z allextract$convenience -z defaultextract'
+	        ;;
+	    esac
+	    _LT_TAGVAR(link_all_deplibs, $1)=yes
+
+	    output_verbose_link_cmd='echo'
+
+	    # Archives containing C++ object files must be created using
+	    # "CC -xar", where "CC" is the Sun C++ compiler.  This is
+	    # necessary to make sure instantiated templates are included
+	    # in the archive.
+	    _LT_TAGVAR(old_archive_cmds, $1)='$CC -xar -o $oldlib $oldobjs'
+	    ;;
+          gcx*)
+	    # Green Hills C++ Compiler
+	    _LT_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-h $wl$soname -o $lib'
+
+	    # The C++ compiler must be used to create the archive.
+	    _LT_TAGVAR(old_archive_cmds, $1)='$CC $LDFLAGS -archive -o $oldlib $oldobjs'
+	    ;;
+          *)
+	    # GNU C++ compiler with Solaris linker
+	    if test "$GXX" = yes && test "$with_gnu_ld" = no; then
+	      _LT_TAGVAR(no_undefined_flag, $1)=' ${wl}-z ${wl}defs'
+	      if $CC --version | $GREP -v '^2\.7' > /dev/null; then
+	        _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $LDFLAGS $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-h $wl$soname -o $lib'
+	        _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~
+		  $CC -shared -nostdlib ${wl}-M $wl$lib.exp -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$RM $lib.exp'
+
+	        # Commands to make compiler produce verbose output that lists
+	        # what "hidden" libraries, object files and flags are used when
+	        # linking a shared library.
+	        output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "\-L"'
+	      else
+	        # g++ 2.7 appears to require `-G' NOT `-shared' on this
+	        # platform.
+	        _LT_TAGVAR(archive_cmds, $1)='$CC -G -nostdlib $LDFLAGS $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-h $wl$soname -o $lib'
+	        _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~
+		  $CC -G -nostdlib ${wl}-M $wl$lib.exp -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$RM $lib.exp'
+
+	        # Commands to make compiler produce verbose output that lists
+	        # what "hidden" libraries, object files and flags are used when
+	        # linking a shared library.
+	        output_verbose_link_cmd='$CC -G $CFLAGS -v conftest.$objext 2>&1 | $GREP "\-L"'
+	      fi
+
+	      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R $wl$libdir'
+	      case $host_os in
+		solaris2.[[0-5]] | solaris2.[[0-5]].*) ;;
+		*)
+		  _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}-z ${wl}allextract$convenience ${wl}-z ${wl}defaultextract'
+		  ;;
+	      esac
+	    fi
+	    ;;
+        esac
+        ;;
+
+    sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[[01]].[[10]]* | unixware7* | sco3.2v5.0.[[024]]*)
+      _LT_TAGVAR(no_undefined_flag, $1)='${wl}-z,text'
+      _LT_TAGVAR(archive_cmds_need_lc, $1)=no
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      runpath_var='LD_RUN_PATH'
+
+      case $cc_basename in
+        CC*)
+	  _LT_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+	  _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+	  ;;
+	*)
+	  _LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+	  _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+	  ;;
+      esac
+      ;;
+
+      sysv5* | sco3.2v5* | sco5v6*)
+	# Note: We can NOT use -z defs as we might desire, because we do not
+	# link with -lc, and that would cause any symbols used from libc to
+	# always be unresolved, which means just about no library would
+	# ever link correctly.  If we're not using GNU ld we use -z text
+	# though, which does catch some bad symbols but isn't as heavy-handed
+	# as -z defs.
+	_LT_TAGVAR(no_undefined_flag, $1)='${wl}-z,text'
+	_LT_TAGVAR(allow_undefined_flag, $1)='${wl}-z,nodefs'
+	_LT_TAGVAR(archive_cmds_need_lc, $1)=no
+	_LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+	_LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R,$libdir'
+	_LT_TAGVAR(hardcode_libdir_separator, $1)=':'
+	_LT_TAGVAR(link_all_deplibs, $1)=yes
+	_LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-Bexport'
+	runpath_var='LD_RUN_PATH'
+
+	case $cc_basename in
+          CC*)
+	    _LT_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+	    _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+	    ;;
+	  *)
+	    _LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+	    _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+	    ;;
+	esac
+      ;;
+
+      tandem*)
+        case $cc_basename in
+          NCC*)
+	    # NonStop-UX NCC 3.20
+	    # FIXME: insert proper C++ library support
+	    _LT_TAGVAR(ld_shlibs, $1)=no
+	    ;;
+          *)
+	    # FIXME: insert proper C++ library support
+	    _LT_TAGVAR(ld_shlibs, $1)=no
+	    ;;
+        esac
+        ;;
+
+      vxworks*)
+        # FIXME: insert proper C++ library support
+        _LT_TAGVAR(ld_shlibs, $1)=no
+        ;;
+
+      *)
+        # FIXME: insert proper C++ library support
+        _LT_TAGVAR(ld_shlibs, $1)=no
+        ;;
+    esac
+
+    AC_MSG_RESULT([$_LT_TAGVAR(ld_shlibs, $1)])
+    test "$_LT_TAGVAR(ld_shlibs, $1)" = no && can_build_shared=no
+
+    _LT_TAGVAR(GCC, $1)="$GXX"
+    _LT_TAGVAR(LD, $1)="$LD"
+
+    ## CAVEAT EMPTOR:
+    ## There is no encapsulation within the following macros, do not change
+    ## the running order or otherwise move them around unless you know exactly
+    ## what you are doing...
+    _LT_SYS_HIDDEN_LIBDEPS($1)
+    _LT_COMPILER_PIC($1)
+    _LT_COMPILER_C_O($1)
+    _LT_COMPILER_FILE_LOCKS($1)
+    _LT_LINKER_SHLIBS($1)
+    _LT_SYS_DYNAMIC_LINKER($1)
+    _LT_LINKER_HARDCODE_LIBPATH($1)
+
+    _LT_CONFIG($1)
+  fi # test -n "$compiler"
+
+  CC=$lt_save_CC
+  LDCXX=$LD
+  LD=$lt_save_LD
+  GCC=$lt_save_GCC
+  with_gnu_ld=$lt_save_with_gnu_ld
+  lt_cv_path_LDCXX=$lt_cv_path_LD
+  lt_cv_path_LD=$lt_save_path_LD
+  lt_cv_prog_gnu_ldcxx=$lt_cv_prog_gnu_ld
+  lt_cv_prog_gnu_ld=$lt_save_with_gnu_ld
+fi # test "$_lt_caught_CXX_error" != yes
+
+AC_LANG_POP
+])# _LT_LANG_CXX_CONFIG
+
+
+# _LT_SYS_HIDDEN_LIBDEPS([TAGNAME])
+# ---------------------------------
+# Figure out "hidden" library dependencies from verbose
+# compiler output when linking a shared library.
+# Parse the compiler output and extract the necessary
+# objects, libraries and library flags.
+m4_defun([_LT_SYS_HIDDEN_LIBDEPS],
+[m4_require([_LT_FILEUTILS_DEFAULTS])dnl
+# Dependencies to place before and after the object being linked:
+_LT_TAGVAR(predep_objects, $1)=
+_LT_TAGVAR(postdep_objects, $1)=
+_LT_TAGVAR(predeps, $1)=
+_LT_TAGVAR(postdeps, $1)=
+_LT_TAGVAR(compiler_lib_search_path, $1)=
+
+dnl we can't use the lt_simple_compile_test_code here,
+dnl because it contains code intended for an executable,
+dnl not a library.  It's possible we should let each
+dnl tag define a new lt_????_link_test_code variable,
+dnl but it's only used here...
+m4_if([$1], [], [cat > conftest.$ac_ext <<_LT_EOF
+int a;
+void foo (void) { a = 0; }
+_LT_EOF
+], [$1], [CXX], [cat > conftest.$ac_ext <<_LT_EOF
+class Foo
+{
+public:
+  Foo (void) { a = 0; }
+private:
+  int a;
+};
+_LT_EOF
+], [$1], [F77], [cat > conftest.$ac_ext <<_LT_EOF
+      subroutine foo
+      implicit none
+      integer*4 a
+      a=0
+      return
+      end
+_LT_EOF
+], [$1], [FC], [cat > conftest.$ac_ext <<_LT_EOF
+      subroutine foo
+      implicit none
+      integer a
+      a=0
+      return
+      end
+_LT_EOF
+], [$1], [GCJ], [cat > conftest.$ac_ext <<_LT_EOF
+public class foo {
+  private int a;
+  public void bar (void) {
+    a = 0;
+  }
+};
+_LT_EOF
+])
+dnl Parse the compiler output and extract the necessary
+dnl objects, libraries and library flags.
+if AC_TRY_EVAL(ac_compile); then
+  # Parse the compiler output and extract the necessary
+  # objects, libraries and library flags.
+
+  # Sentinel used to keep track of whether or not we are before
+  # the conftest object file.
+  pre_test_object_deps_done=no
+
+  for p in `eval "$output_verbose_link_cmd"`; do
+    case $p in
+
+    -L* | -R* | -l*)
+       # Some compilers place space between "-{L,R}" and the path.
+       # Remove the space.
+       if test $p = "-L" ||
+          test $p = "-R"; then
+	 prev=$p
+	 continue
+       else
+	 prev=
+       fi
+
+       if test "$pre_test_object_deps_done" = no; then
+	 case $p in
+	 -L* | -R*)
+	   # Internal compiler library paths should come after those
+	   # provided the user.  The postdeps already come after the
+	   # user supplied libs so there is no need to process them.
+	   if test -z "$_LT_TAGVAR(compiler_lib_search_path, $1)"; then
+	     _LT_TAGVAR(compiler_lib_search_path, $1)="${prev}${p}"
+	   else
+	     _LT_TAGVAR(compiler_lib_search_path, $1)="${_LT_TAGVAR(compiler_lib_search_path, $1)} ${prev}${p}"
+	   fi
+	   ;;
+	 # The "-l" case would never come before the object being
+	 # linked, so don't bother handling this case.
+	 esac
+       else
+	 if test -z "$_LT_TAGVAR(postdeps, $1)"; then
+	   _LT_TAGVAR(postdeps, $1)="${prev}${p}"
+	 else
+	   _LT_TAGVAR(postdeps, $1)="${_LT_TAGVAR(postdeps, $1)} ${prev}${p}"
+	 fi
+       fi
+       ;;
+
+    *.$objext)
+       # This assumes that the test object file only shows up
+       # once in the compiler output.
+       if test "$p" = "conftest.$objext"; then
+	 pre_test_object_deps_done=yes
+	 continue
+       fi
+
+       if test "$pre_test_object_deps_done" = no; then
+	 if test -z "$_LT_TAGVAR(predep_objects, $1)"; then
+	   _LT_TAGVAR(predep_objects, $1)="$p"
+	 else
+	   _LT_TAGVAR(predep_objects, $1)="$_LT_TAGVAR(predep_objects, $1) $p"
+	 fi
+       else
+	 if test -z "$_LT_TAGVAR(postdep_objects, $1)"; then
+	   _LT_TAGVAR(postdep_objects, $1)="$p"
+	 else
+	   _LT_TAGVAR(postdep_objects, $1)="$_LT_TAGVAR(postdep_objects, $1) $p"
+	 fi
+       fi
+       ;;
+
+    *) ;; # Ignore the rest.
+
+    esac
+  done
+
+  # Clean up.
+  rm -f a.out a.exe
+else
+  echo "libtool.m4: error: problem compiling $1 test program"
+fi
+
+$RM -f confest.$objext
+
+# PORTME: override above test on systems where it is broken
+m4_if([$1], [CXX],
+[case $host_os in
+interix[[3-9]]*)
+  # Interix 3.5 installs completely hosed .la files for C++, so rather than
+  # hack all around it, let's just trust "g++" to DTRT.
+  _LT_TAGVAR(predep_objects,$1)=
+  _LT_TAGVAR(postdep_objects,$1)=
+  _LT_TAGVAR(postdeps,$1)=
+  ;;
+
+linux*)
+  case `$CC -V 2>&1 | sed 5q` in
+  *Sun\ C*)
+    # Sun C++ 5.9
+
+    # The more standards-conforming stlport4 library is
+    # incompatible with the Cstd library. Avoid specifying
+    # it if it's in CXXFLAGS. Ignore libCrun as
+    # -library=stlport4 depends on it.
+    case " $CXX $CXXFLAGS " in
+    *" -library=stlport4 "*)
+      solaris_use_stlport4=yes
+      ;;
+    esac
+
+    if test "$solaris_use_stlport4" != yes; then
+      _LT_TAGVAR(postdeps,$1)='-library=Cstd -library=Crun'
+    fi
+    ;;
+  esac
+  ;;
+
+solaris*)
+  case $cc_basename in
+  CC*)
+    # The more standards-conforming stlport4 library is
+    # incompatible with the Cstd library. Avoid specifying
+    # it if it's in CXXFLAGS. Ignore libCrun as
+    # -library=stlport4 depends on it.
+    case " $CXX $CXXFLAGS " in
+    *" -library=stlport4 "*)
+      solaris_use_stlport4=yes
+      ;;
+    esac
+
+    # Adding this requires a known-good setup of shared libraries for
+    # Sun compiler versions before 5.6, else PIC objects from an old
+    # archive will be linked into the output, leading to subtle bugs.
+    if test "$solaris_use_stlport4" != yes; then
+      _LT_TAGVAR(postdeps,$1)='-library=Cstd -library=Crun'
+    fi
+    ;;
+  esac
+  ;;
+esac
+])
+
+case " $_LT_TAGVAR(postdeps, $1) " in
+*" -lc "*) _LT_TAGVAR(archive_cmds_need_lc, $1)=no ;;
+esac
+ _LT_TAGVAR(compiler_lib_search_dirs, $1)=
+if test -n "${_LT_TAGVAR(compiler_lib_search_path, $1)}"; then
+ _LT_TAGVAR(compiler_lib_search_dirs, $1)=`echo " ${_LT_TAGVAR(compiler_lib_search_path, $1)}" | ${SED} -e 's! -L! !g' -e 's!^ !!'`
+fi
+_LT_TAGDECL([], [compiler_lib_search_dirs], [1],
+    [The directories searched by this compiler when creating a shared library])
+_LT_TAGDECL([], [predep_objects], [1],
+    [Dependencies to place before and after the objects being linked to
+    create a shared library])
+_LT_TAGDECL([], [postdep_objects], [1])
+_LT_TAGDECL([], [predeps], [1])
+_LT_TAGDECL([], [postdeps], [1])
+_LT_TAGDECL([], [compiler_lib_search_path], [1],
+    [The library search path used internally by the compiler when linking
+    a shared library])
+])# _LT_SYS_HIDDEN_LIBDEPS
+
+
+# _LT_PROG_F77
+# ------------
+# Since AC_PROG_F77 is broken, in that it returns the empty string
+# if there is no fortran compiler, we have our own version here.
+m4_defun([_LT_PROG_F77],
+[
+pushdef([AC_MSG_ERROR], [_lt_disable_F77=yes])
+AC_PROG_F77
+if test -z "$F77" || test "X$F77" = "Xno"; then
+  _lt_disable_F77=yes
+fi
+popdef([AC_MSG_ERROR])
+])# _LT_PROG_F77
+
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([_LT_PROG_F77], [])
+
+
+# _LT_LANG_F77_CONFIG([TAG])
+# --------------------------
+# Ensure that the configuration variables for a Fortran 77 compiler are
+# suitably defined.  These variables are subsequently used by _LT_CONFIG
+# to write the compiler configuration to `libtool'.
+m4_defun([_LT_LANG_F77_CONFIG],
+[AC_REQUIRE([_LT_PROG_F77])dnl
+AC_LANG_PUSH(Fortran 77)
+
+_LT_TAGVAR(archive_cmds_need_lc, $1)=no
+_LT_TAGVAR(allow_undefined_flag, $1)=
+_LT_TAGVAR(always_export_symbols, $1)=no
+_LT_TAGVAR(archive_expsym_cmds, $1)=
+_LT_TAGVAR(export_dynamic_flag_spec, $1)=
+_LT_TAGVAR(hardcode_direct, $1)=no
+_LT_TAGVAR(hardcode_direct_absolute, $1)=no
+_LT_TAGVAR(hardcode_libdir_flag_spec, $1)=
+_LT_TAGVAR(hardcode_libdir_flag_spec_ld, $1)=
+_LT_TAGVAR(hardcode_libdir_separator, $1)=
+_LT_TAGVAR(hardcode_minus_L, $1)=no
+_LT_TAGVAR(hardcode_automatic, $1)=no
+_LT_TAGVAR(inherit_rpath, $1)=no
+_LT_TAGVAR(module_cmds, $1)=
+_LT_TAGVAR(module_expsym_cmds, $1)=
+_LT_TAGVAR(link_all_deplibs, $1)=unknown
+_LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds
+_LT_TAGVAR(no_undefined_flag, $1)=
+_LT_TAGVAR(whole_archive_flag_spec, $1)=
+_LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no
+
+# Source file extension for f77 test sources.
+ac_ext=f
+
+# Object file extension for compiled f77 test sources.
+objext=o
+_LT_TAGVAR(objext, $1)=$objext
+
+# No sense in running all these tests if we already determined that
+# the F77 compiler isn't working.  Some variables (like enable_shared)
+# are currently assumed to apply to all compilers on this platform,
+# and will be corrupted by setting them based on a non-working compiler.
+if test "$_lt_disable_F77" != yes; then
+  # Code to be used in simple compile tests
+  lt_simple_compile_test_code="\
+      subroutine t
+      return
+      end
+"
+
+  # Code to be used in simple link tests
+  lt_simple_link_test_code="\
+      program t
+      end
+"
+
+  # ltmain only uses $CC for tagged configurations so make sure $CC is set.
+  _LT_TAG_COMPILER
+
+  # save warnings/boilerplate of simple test code
+  _LT_COMPILER_BOILERPLATE
+  _LT_LINKER_BOILERPLATE
+
+  # Allow CC to be a program name with arguments.
+  lt_save_CC="$CC"
+  lt_save_GCC=$GCC
+  CC=${F77-"f77"}
+  compiler=$CC
+  _LT_TAGVAR(compiler, $1)=$CC
+  _LT_CC_BASENAME([$compiler])
+  GCC=$G77
+  if test -n "$compiler"; then
+    AC_MSG_CHECKING([if libtool supports shared libraries])
+    AC_MSG_RESULT([$can_build_shared])
+
+    AC_MSG_CHECKING([whether to build shared libraries])
+    test "$can_build_shared" = "no" && enable_shared=no
+
+    # On AIX, shared libraries and static libraries use the same namespace, and
+    # are all built from PIC.
+    case $host_os in
+      aix3*)
+        test "$enable_shared" = yes && enable_static=no
+        if test -n "$RANLIB"; then
+          archive_cmds="$archive_cmds~\$RANLIB \$lib"
+          postinstall_cmds='$RANLIB $lib'
+        fi
+        ;;
+      aix[[4-9]]*)
+	if test "$host_cpu" != ia64 && test "$aix_use_runtimelinking" = no ; then
+	  test "$enable_shared" = yes && enable_static=no
+	fi
+        ;;
+    esac
+    AC_MSG_RESULT([$enable_shared])
+
+    AC_MSG_CHECKING([whether to build static libraries])
+    # Make sure either enable_shared or enable_static is yes.
+    test "$enable_shared" = yes || enable_static=yes
+    AC_MSG_RESULT([$enable_static])
+
+    _LT_TAGVAR(GCC, $1)="$G77"
+    _LT_TAGVAR(LD, $1)="$LD"
+
+    ## CAVEAT EMPTOR:
+    ## There is no encapsulation within the following macros, do not change
+    ## the running order or otherwise move them around unless you know exactly
+    ## what you are doing...
+    _LT_COMPILER_PIC($1)
+    _LT_COMPILER_C_O($1)
+    _LT_COMPILER_FILE_LOCKS($1)
+    _LT_LINKER_SHLIBS($1)
+    _LT_SYS_DYNAMIC_LINKER($1)
+    _LT_LINKER_HARDCODE_LIBPATH($1)
+
+    _LT_CONFIG($1)
+  fi # test -n "$compiler"
+
+  GCC=$lt_save_GCC
+  CC="$lt_save_CC"
+fi # test "$_lt_disable_F77" != yes
+
+AC_LANG_POP
+])# _LT_LANG_F77_CONFIG
+
+
+# _LT_PROG_FC
+# -----------
+# Since AC_PROG_FC is broken, in that it returns the empty string
+# if there is no fortran compiler, we have our own version here.
+m4_defun([_LT_PROG_FC],
+[
+pushdef([AC_MSG_ERROR], [_lt_disable_FC=yes])
+AC_PROG_FC
+if test -z "$FC" || test "X$FC" = "Xno"; then
+  _lt_disable_FC=yes
+fi
+popdef([AC_MSG_ERROR])
+])# _LT_PROG_FC
+
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([_LT_PROG_FC], [])
+
+
+# _LT_LANG_FC_CONFIG([TAG])
+# -------------------------
+# Ensure that the configuration variables for a Fortran compiler are
+# suitably defined.  These variables are subsequently used by _LT_CONFIG
+# to write the compiler configuration to `libtool'.
+m4_defun([_LT_LANG_FC_CONFIG],
+[AC_REQUIRE([_LT_PROG_FC])dnl
+AC_LANG_PUSH(Fortran)
+
+_LT_TAGVAR(archive_cmds_need_lc, $1)=no
+_LT_TAGVAR(allow_undefined_flag, $1)=
+_LT_TAGVAR(always_export_symbols, $1)=no
+_LT_TAGVAR(archive_expsym_cmds, $1)=
+_LT_TAGVAR(export_dynamic_flag_spec, $1)=
+_LT_TAGVAR(hardcode_direct, $1)=no
+_LT_TAGVAR(hardcode_direct_absolute, $1)=no
+_LT_TAGVAR(hardcode_libdir_flag_spec, $1)=
+_LT_TAGVAR(hardcode_libdir_flag_spec_ld, $1)=
+_LT_TAGVAR(hardcode_libdir_separator, $1)=
+_LT_TAGVAR(hardcode_minus_L, $1)=no
+_LT_TAGVAR(hardcode_automatic, $1)=no
+_LT_TAGVAR(inherit_rpath, $1)=no
+_LT_TAGVAR(module_cmds, $1)=
+_LT_TAGVAR(module_expsym_cmds, $1)=
+_LT_TAGVAR(link_all_deplibs, $1)=unknown
+_LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds
+_LT_TAGVAR(no_undefined_flag, $1)=
+_LT_TAGVAR(whole_archive_flag_spec, $1)=
+_LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no
+
+# Source file extension for fc test sources.
+ac_ext=${ac_fc_srcext-f}
+
+# Object file extension for compiled fc test sources.
+objext=o
+_LT_TAGVAR(objext, $1)=$objext
+
+# No sense in running all these tests if we already determined that
+# the FC compiler isn't working.  Some variables (like enable_shared)
+# are currently assumed to apply to all compilers on this platform,
+# and will be corrupted by setting them based on a non-working compiler.
+if test "$_lt_disable_FC" != yes; then
+  # Code to be used in simple compile tests
+  lt_simple_compile_test_code="\
+      subroutine t
+      return
+      end
+"
+
+  # Code to be used in simple link tests
+  lt_simple_link_test_code="\
+      program t
+      end
+"
+
+  # ltmain only uses $CC for tagged configurations so make sure $CC is set.
+  _LT_TAG_COMPILER
+
+  # save warnings/boilerplate of simple test code
+  _LT_COMPILER_BOILERPLATE
+  _LT_LINKER_BOILERPLATE
+
+  # Allow CC to be a program name with arguments.
+  lt_save_CC="$CC"
+  lt_save_GCC=$GCC
+  CC=${FC-"f95"}
+  compiler=$CC
+  GCC=$ac_cv_fc_compiler_gnu
+
+  _LT_TAGVAR(compiler, $1)=$CC
+  _LT_CC_BASENAME([$compiler])
+
+  if test -n "$compiler"; then
+    AC_MSG_CHECKING([if libtool supports shared libraries])
+    AC_MSG_RESULT([$can_build_shared])
+
+    AC_MSG_CHECKING([whether to build shared libraries])
+    test "$can_build_shared" = "no" && enable_shared=no
+
+    # On AIX, shared libraries and static libraries use the same namespace, and
+    # are all built from PIC.
+    case $host_os in
+      aix3*)
+        test "$enable_shared" = yes && enable_static=no
+        if test -n "$RANLIB"; then
+          archive_cmds="$archive_cmds~\$RANLIB \$lib"
+          postinstall_cmds='$RANLIB $lib'
+        fi
+        ;;
+      aix[[4-9]]*)
+	if test "$host_cpu" != ia64 && test "$aix_use_runtimelinking" = no ; then
+	  test "$enable_shared" = yes && enable_static=no
+	fi
+        ;;
+    esac
+    AC_MSG_RESULT([$enable_shared])
+
+    AC_MSG_CHECKING([whether to build static libraries])
+    # Make sure either enable_shared or enable_static is yes.
+    test "$enable_shared" = yes || enable_static=yes
+    AC_MSG_RESULT([$enable_static])
+
+    _LT_TAGVAR(GCC, $1)="$ac_cv_fc_compiler_gnu"
+    _LT_TAGVAR(LD, $1)="$LD"
+
+    ## CAVEAT EMPTOR:
+    ## There is no encapsulation within the following macros, do not change
+    ## the running order or otherwise move them around unless you know exactly
+    ## what you are doing...
+    _LT_SYS_HIDDEN_LIBDEPS($1)
+    _LT_COMPILER_PIC($1)
+    _LT_COMPILER_C_O($1)
+    _LT_COMPILER_FILE_LOCKS($1)
+    _LT_LINKER_SHLIBS($1)
+    _LT_SYS_DYNAMIC_LINKER($1)
+    _LT_LINKER_HARDCODE_LIBPATH($1)
+
+    _LT_CONFIG($1)
+  fi # test -n "$compiler"
+
+  GCC=$lt_save_GCC
+  CC="$lt_save_CC"
+fi # test "$_lt_disable_FC" != yes
+
+AC_LANG_POP
+])# _LT_LANG_FC_CONFIG
+
+
+# _LT_LANG_GCJ_CONFIG([TAG])
+# --------------------------
+# Ensure that the configuration variables for the GNU Java Compiler compiler
+# are suitably defined.  These variables are subsequently used by _LT_CONFIG
+# to write the compiler configuration to `libtool'.
+m4_defun([_LT_LANG_GCJ_CONFIG],
+[AC_REQUIRE([LT_PROG_GCJ])dnl
+AC_LANG_SAVE
+
+# Source file extension for Java test sources.
+ac_ext=java
+
+# Object file extension for compiled Java test sources.
+objext=o
+_LT_TAGVAR(objext, $1)=$objext
+
+# Code to be used in simple compile tests
+lt_simple_compile_test_code="class foo {}"
+
+# Code to be used in simple link tests
+lt_simple_link_test_code='public class conftest { public static void main(String[[]] argv) {}; }'
+
+# ltmain only uses $CC for tagged configurations so make sure $CC is set.
+_LT_TAG_COMPILER
+
+# save warnings/boilerplate of simple test code
+_LT_COMPILER_BOILERPLATE
+_LT_LINKER_BOILERPLATE
+
+# Allow CC to be a program name with arguments.
+lt_save_CC="$CC"
+lt_save_GCC=$GCC
+GCC=yes
+CC=${GCJ-"gcj"}
+compiler=$CC
+_LT_TAGVAR(compiler, $1)=$CC
+_LT_TAGVAR(LD, $1)="$LD"
+_LT_CC_BASENAME([$compiler])
+
+# GCJ did not exist at the time GCC didn't implicitly link libc in.
+_LT_TAGVAR(archive_cmds_need_lc, $1)=no
+
+_LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds
+
+## CAVEAT EMPTOR:
+## There is no encapsulation within the following macros, do not change
+## the running order or otherwise move them around unless you know exactly
+## what you are doing...
+if test -n "$compiler"; then
+  _LT_COMPILER_NO_RTTI($1)
+  _LT_COMPILER_PIC($1)
+  _LT_COMPILER_C_O($1)
+  _LT_COMPILER_FILE_LOCKS($1)
+  _LT_LINKER_SHLIBS($1)
+  _LT_LINKER_HARDCODE_LIBPATH($1)
+
+  _LT_CONFIG($1)
+fi
+
+AC_LANG_RESTORE
+
+GCC=$lt_save_GCC
+CC="$lt_save_CC"
+])# _LT_LANG_GCJ_CONFIG
+
+
+# _LT_LANG_RC_CONFIG([TAG])
+# -------------------------
+# Ensure that the configuration variables for the Windows resource compiler
+# are suitably defined.  These variables are subsequently used by _LT_CONFIG
+# to write the compiler configuration to `libtool'.
+m4_defun([_LT_LANG_RC_CONFIG],
+[AC_REQUIRE([LT_PROG_RC])dnl
+AC_LANG_SAVE
+
+# Source file extension for RC test sources.
+ac_ext=rc
+
+# Object file extension for compiled RC test sources.
+objext=o
+_LT_TAGVAR(objext, $1)=$objext
+
+# Code to be used in simple compile tests
+lt_simple_compile_test_code='sample MENU { MENUITEM "&Soup", 100, CHECKED }'
+
+# Code to be used in simple link tests
+lt_simple_link_test_code="$lt_simple_compile_test_code"
+
+# ltmain only uses $CC for tagged configurations so make sure $CC is set.
+_LT_TAG_COMPILER
+
+# save warnings/boilerplate of simple test code
+_LT_COMPILER_BOILERPLATE
+_LT_LINKER_BOILERPLATE
+
+# Allow CC to be a program name with arguments.
+lt_save_CC="$CC"
+lt_save_GCC=$GCC
+GCC=
+CC=${RC-"windres"}
+compiler=$CC
+_LT_TAGVAR(compiler, $1)=$CC
+_LT_CC_BASENAME([$compiler])
+_LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)=yes
+
+if test -n "$compiler"; then
+  :
+  _LT_CONFIG($1)
+fi
+
+GCC=$lt_save_GCC
+AC_LANG_RESTORE
+CC="$lt_save_CC"
+])# _LT_LANG_RC_CONFIG
+
+
+# LT_PROG_GCJ
+# -----------
+AC_DEFUN([LT_PROG_GCJ],
+[m4_ifdef([AC_PROG_GCJ], [AC_PROG_GCJ],
+  [m4_ifdef([A][M_PROG_GCJ], [A][M_PROG_GCJ],
+    [AC_CHECK_TOOL(GCJ, gcj,)
+      test "x${GCJFLAGS+set}" = xset || GCJFLAGS="-g -O2"
+      AC_SUBST(GCJFLAGS)])])[]dnl
+])
+
+# Old name:
+AU_ALIAS([LT_AC_PROG_GCJ], [LT_PROG_GCJ])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([LT_AC_PROG_GCJ], [])
+
+
+# LT_PROG_RC
+# ----------
+AC_DEFUN([LT_PROG_RC],
+[AC_CHECK_TOOL(RC, windres,)
+])
+
+# Old name:
+AU_ALIAS([LT_AC_PROG_RC], [LT_PROG_RC])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([LT_AC_PROG_RC], [])
+
+
+# _LT_DECL_EGREP
+# --------------
+# If we don't have a new enough Autoconf to choose the best grep
+# available, choose the one first in the user's PATH.
+m4_defun([_LT_DECL_EGREP],
+[AC_REQUIRE([AC_PROG_EGREP])dnl
+AC_REQUIRE([AC_PROG_FGREP])dnl
+test -z "$GREP" && GREP=grep
+_LT_DECL([], [GREP], [1], [A grep program that handles long lines])
+_LT_DECL([], [EGREP], [1], [An ERE matcher])
+_LT_DECL([], [FGREP], [1], [A literal string matcher])
+dnl Non-bleeding-edge autoconf doesn't subst GREP, so do it here too
+AC_SUBST([GREP])
+])
+
+
+# _LT_DECL_OBJDUMP
+# --------------
+# If we don't have a new enough Autoconf to choose the best objdump
+# available, choose the one first in the user's PATH.
+m4_defun([_LT_DECL_OBJDUMP],
+[AC_CHECK_TOOL(OBJDUMP, objdump, false)
+test -z "$OBJDUMP" && OBJDUMP=objdump
+_LT_DECL([], [OBJDUMP], [1], [An object symbol dumper])
+AC_SUBST([OBJDUMP])
+])
+
+
+# _LT_DECL_SED
+# ------------
+# Check for a fully-functional sed program, that truncates
+# as few characters as possible.  Prefer GNU sed if found.
+m4_defun([_LT_DECL_SED],
+[AC_PROG_SED
+test -z "$SED" && SED=sed
+Xsed="$SED -e 1s/^X//"
+_LT_DECL([], [SED], [1], [A sed program that does not truncate output])
+_LT_DECL([], [Xsed], ["\$SED -e 1s/^X//"],
+    [Sed that helps us avoid accidentally triggering echo(1) options like -n])
+])# _LT_DECL_SED
+
+m4_ifndef([AC_PROG_SED], [
+############################################################
+# NOTE: This macro has been submitted for inclusion into   #
+#  GNU Autoconf as AC_PROG_SED.  When it is available in   #
+#  a released version of Autoconf we should remove this    #
+#  macro and use it instead.                               #
+############################################################
+
+m4_defun([AC_PROG_SED],
+[AC_MSG_CHECKING([for a sed that does not truncate output])
+AC_CACHE_VAL(lt_cv_path_SED,
+[# Loop through the user's path and test for sed and gsed.
+# Then use that list of sed's as ones to test for truncation.
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for lt_ac_prog in sed gsed; do
+    for ac_exec_ext in '' $ac_executable_extensions; do
+      if $as_executable_p "$as_dir/$lt_ac_prog$ac_exec_ext"; then
+        lt_ac_sed_list="$lt_ac_sed_list $as_dir/$lt_ac_prog$ac_exec_ext"
+      fi
+    done
+  done
+done
+IFS=$as_save_IFS
+lt_ac_max=0
+lt_ac_count=0
+# Add /usr/xpg4/bin/sed as it is typically found on Solaris
+# along with /bin/sed that truncates output.
+for lt_ac_sed in $lt_ac_sed_list /usr/xpg4/bin/sed; do
+  test ! -f $lt_ac_sed && continue
+  cat /dev/null > conftest.in
+  lt_ac_count=0
+  echo $ECHO_N "0123456789$ECHO_C" >conftest.in
+  # Check for GNU sed and select it if it is found.
+  if "$lt_ac_sed" --version 2>&1 < /dev/null | grep 'GNU' > /dev/null; then
+    lt_cv_path_SED=$lt_ac_sed
+    break
+  fi
+  while true; do
+    cat conftest.in conftest.in >conftest.tmp
+    mv conftest.tmp conftest.in
+    cp conftest.in conftest.nl
+    echo >>conftest.nl
+    $lt_ac_sed -e 's/a$//' < conftest.nl >conftest.out || break
+    cmp -s conftest.out conftest.nl || break
+    # 10000 chars as input seems more than enough
+    test $lt_ac_count -gt 10 && break
+    lt_ac_count=`expr $lt_ac_count + 1`
+    if test $lt_ac_count -gt $lt_ac_max; then
+      lt_ac_max=$lt_ac_count
+      lt_cv_path_SED=$lt_ac_sed
+    fi
+  done
+done
+])
+SED=$lt_cv_path_SED
+AC_SUBST([SED])
+AC_MSG_RESULT([$SED])
+])#AC_PROG_SED
+])#m4_ifndef
+
+# Old name:
+AU_ALIAS([LT_AC_PROG_SED], [AC_PROG_SED])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([LT_AC_PROG_SED], [])
+
+
+# _LT_CHECK_SHELL_FEATURES
+# ------------------------
+# Find out whether the shell is Bourne or XSI compatible,
+# or has some other useful features.
+m4_defun([_LT_CHECK_SHELL_FEATURES],
+[AC_MSG_CHECKING([whether the shell understands some XSI constructs])
+# Try some XSI features
+xsi_shell=no
+( _lt_dummy="a/b/c"
+  test "${_lt_dummy##*/},${_lt_dummy%/*},"${_lt_dummy%"$_lt_dummy"}, \
+      = c,a/b,, \
+    && eval 'test $(( 1 + 1 )) -eq 2 \
+    && test "${#_lt_dummy}" -eq 5' ) >/dev/null 2>&1 \
+  && xsi_shell=yes
+AC_MSG_RESULT([$xsi_shell])
+_LT_CONFIG_LIBTOOL_INIT([xsi_shell='$xsi_shell'])
+
+AC_MSG_CHECKING([whether the shell understands "+="])
+lt_shell_append=no
+( foo=bar; set foo baz; eval "$[1]+=\$[2]" && test "$foo" = barbaz ) \
+    >/dev/null 2>&1 \
+  && lt_shell_append=yes
+AC_MSG_RESULT([$lt_shell_append])
+_LT_CONFIG_LIBTOOL_INIT([lt_shell_append='$lt_shell_append'])
+
+if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then
+  lt_unset=unset
+else
+  lt_unset=false
+fi
+_LT_DECL([], [lt_unset], [0], [whether the shell understands "unset"])dnl
+
+# test EBCDIC or ASCII
+case `echo X|tr X '\101'` in
+ A) # ASCII based system
+    # \n is not interpreted correctly by Solaris 8 /usr/ucb/tr
+  lt_SP2NL='tr \040 \012'
+  lt_NL2SP='tr \015\012 \040\040'
+  ;;
+ *) # EBCDIC based system
+  lt_SP2NL='tr \100 \n'
+  lt_NL2SP='tr \r\n \100\100'
+  ;;
+esac
+_LT_DECL([SP2NL], [lt_SP2NL], [1], [turn spaces into newlines])dnl
+_LT_DECL([NL2SP], [lt_NL2SP], [1], [turn newlines into spaces])dnl
+])# _LT_CHECK_SHELL_FEATURES
+
+
+# _LT_PROG_XSI_SHELLFNS
+# ---------------------
+# Bourne and XSI compatible variants of some useful shell functions.
+m4_defun([_LT_PROG_XSI_SHELLFNS],
+[case $xsi_shell in
+  yes)
+    cat << \_LT_EOF >> "$cfgfile"
+
+# func_dirname file append nondir_replacement
+# Compute the dirname of FILE.  If nonempty, add APPEND to the result,
+# otherwise set result to NONDIR_REPLACEMENT.
+func_dirname ()
+{
+  case ${1} in
+    */*) func_dirname_result="${1%/*}${2}" ;;
+    *  ) func_dirname_result="${3}" ;;
+  esac
+}
+
+# func_basename file
+func_basename ()
+{
+  func_basename_result="${1##*/}"
+}
+
+# func_dirname_and_basename file append nondir_replacement
+# perform func_basename and func_dirname in a single function
+# call:
+#   dirname:  Compute the dirname of FILE.  If nonempty,
+#             add APPEND to the result, otherwise set result
+#             to NONDIR_REPLACEMENT.
+#             value returned in "$func_dirname_result"
+#   basename: Compute filename of FILE.
+#             value retuned in "$func_basename_result"
+# Implementation must be kept synchronized with func_dirname
+# and func_basename. For efficiency, we do not delegate to
+# those functions but instead duplicate the functionality here.
+func_dirname_and_basename ()
+{
+  case ${1} in
+    */*) func_dirname_result="${1%/*}${2}" ;;
+    *  ) func_dirname_result="${3}" ;;
+  esac
+  func_basename_result="${1##*/}"
+}
+
+# func_stripname prefix suffix name
+# strip PREFIX and SUFFIX off of NAME.
+# PREFIX and SUFFIX must not contain globbing or regex special
+# characters, hashes, percent signs, but SUFFIX may contain a leading
+# dot (in which case that matches only a dot).
+func_stripname ()
+{
+  # pdksh 5.2.14 does not do ${X%$Y} correctly if both X and Y are
+  # positional parameters, so assign one to ordinary parameter first.
+  func_stripname_result=${3}
+  func_stripname_result=${func_stripname_result#"${1}"}
+  func_stripname_result=${func_stripname_result%"${2}"}
+}
+
+# func_opt_split
+func_opt_split ()
+{
+  func_opt_split_opt=${1%%=*}
+  func_opt_split_arg=${1#*=}
+}
+
+# func_lo2o object
+func_lo2o ()
+{
+  case ${1} in
+    *.lo) func_lo2o_result=${1%.lo}.${objext} ;;
+    *)    func_lo2o_result=${1} ;;
+  esac
+}
+
+# func_xform libobj-or-source
+func_xform ()
+{
+  func_xform_result=${1%.*}.lo
+}
+
+# func_arith arithmetic-term...
+func_arith ()
+{
+  func_arith_result=$(( $[*] ))
+}
+
+# func_len string
+# STRING may not start with a hyphen.
+func_len ()
+{
+  func_len_result=${#1}
+}
+
+_LT_EOF
+    ;;
+  *) # Bourne compatible functions.
+    cat << \_LT_EOF >> "$cfgfile"
+
+# func_dirname file append nondir_replacement
+# Compute the dirname of FILE.  If nonempty, add APPEND to the result,
+# otherwise set result to NONDIR_REPLACEMENT.
+func_dirname ()
+{
+  # Extract subdirectory from the argument.
+  func_dirname_result=`$ECHO "X${1}" | $Xsed -e "$dirname"`
+  if test "X$func_dirname_result" = "X${1}"; then
+    func_dirname_result="${3}"
+  else
+    func_dirname_result="$func_dirname_result${2}"
+  fi
+}
+
+# func_basename file
+func_basename ()
+{
+  func_basename_result=`$ECHO "X${1}" | $Xsed -e "$basename"`
+}
+
+dnl func_dirname_and_basename
+dnl A portable version of this function is already defined in general.m4sh
+dnl so there is no need for it here.
+
+# func_stripname prefix suffix name
+# strip PREFIX and SUFFIX off of NAME.
+# PREFIX and SUFFIX must not contain globbing or regex special
+# characters, hashes, percent signs, but SUFFIX may contain a leading
+# dot (in which case that matches only a dot).
+# func_strip_suffix prefix name
+func_stripname ()
+{
+  case ${2} in
+    .*) func_stripname_result=`$ECHO "X${3}" \
+           | $Xsed -e "s%^${1}%%" -e "s%\\\\${2}\$%%"`;;
+    *)  func_stripname_result=`$ECHO "X${3}" \
+           | $Xsed -e "s%^${1}%%" -e "s%${2}\$%%"`;;
+  esac
+}
+
+# sed scripts:
+my_sed_long_opt='1s/^\(-[[^=]]*\)=.*/\1/;q'
+my_sed_long_arg='1s/^-[[^=]]*=//'
+
+# func_opt_split
+func_opt_split ()
+{
+  func_opt_split_opt=`$ECHO "X${1}" | $Xsed -e "$my_sed_long_opt"`
+  func_opt_split_arg=`$ECHO "X${1}" | $Xsed -e "$my_sed_long_arg"`
+}
+
+# func_lo2o object
+func_lo2o ()
+{
+  func_lo2o_result=`$ECHO "X${1}" | $Xsed -e "$lo2o"`
+}
+
+# func_xform libobj-or-source
+func_xform ()
+{
+  func_xform_result=`$ECHO "X${1}" | $Xsed -e 's/\.[[^.]]*$/.lo/'`
+}
+
+# func_arith arithmetic-term...
+func_arith ()
+{
+  func_arith_result=`expr "$[@]"`
+}
+
+# func_len string
+# STRING may not start with a hyphen.
+func_len ()
+{
+  func_len_result=`expr "$[1]" : ".*" 2>/dev/null || echo $max_cmd_len`
+}
+
+_LT_EOF
+esac
+
+case $lt_shell_append in
+  yes)
+    cat << \_LT_EOF >> "$cfgfile"
+
+# func_append var value
+# Append VALUE to the end of shell variable VAR.
+func_append ()
+{
+  eval "$[1]+=\$[2]"
+}
+_LT_EOF
+    ;;
+  *)
+    cat << \_LT_EOF >> "$cfgfile"
+
+# func_append var value
+# Append VALUE to the end of shell variable VAR.
+func_append ()
+{
+  eval "$[1]=\$$[1]\$[2]"
+}
+
+_LT_EOF
+    ;;
+  esac
+])
diff --git a/m4macros/ltoptions.m4 b/m4macros/ltoptions.m4
new file mode 100644
index 0000000..34151a3
--- /dev/null
+++ b/m4macros/ltoptions.m4
@@ -0,0 +1,368 @@
+# Helper functions for option handling.                    -*- Autoconf -*-
+#
+#   Copyright (C) 2004, 2005, 2007, 2008 Free Software Foundation, Inc.
+#   Written by Gary V. Vaughan, 2004
+#
+# This file is free software; the Free Software Foundation gives
+# unlimited permission to copy and/or distribute it, with or without
+# modifications, as long as this notice is preserved.
+
+# serial 6 ltoptions.m4
+
+# This is to help aclocal find these macros, as it can't see m4_define.
+AC_DEFUN([LTOPTIONS_VERSION], [m4_if([1])])
+
+
+# _LT_MANGLE_OPTION(MACRO-NAME, OPTION-NAME)
+# ------------------------------------------
+m4_define([_LT_MANGLE_OPTION],
+[[_LT_OPTION_]m4_bpatsubst($1__$2, [[^a-zA-Z0-9_]], [_])])
+
+
+# _LT_SET_OPTION(MACRO-NAME, OPTION-NAME)
+# ---------------------------------------
+# Set option OPTION-NAME for macro MACRO-NAME, and if there is a
+# matching handler defined, dispatch to it.  Other OPTION-NAMEs are
+# saved as a flag.
+m4_define([_LT_SET_OPTION],
+[m4_define(_LT_MANGLE_OPTION([$1], [$2]))dnl
+m4_ifdef(_LT_MANGLE_DEFUN([$1], [$2]),
+        _LT_MANGLE_DEFUN([$1], [$2]),
+    [m4_warning([Unknown $1 option `$2'])])[]dnl
+])
+
+
+# _LT_IF_OPTION(MACRO-NAME, OPTION-NAME, IF-SET, [IF-NOT-SET])
+# ------------------------------------------------------------
+# Execute IF-SET if OPTION is set, IF-NOT-SET otherwise.
+m4_define([_LT_IF_OPTION],
+[m4_ifdef(_LT_MANGLE_OPTION([$1], [$2]), [$3], [$4])])
+
+
+# _LT_UNLESS_OPTIONS(MACRO-NAME, OPTION-LIST, IF-NOT-SET)
+# -------------------------------------------------------
+# Execute IF-NOT-SET unless all options in OPTION-LIST for MACRO-NAME
+# are set.
+m4_define([_LT_UNLESS_OPTIONS],
+[m4_foreach([_LT_Option], m4_split(m4_normalize([$2])),
+	    [m4_ifdef(_LT_MANGLE_OPTION([$1], _LT_Option),
+		      [m4_define([$0_found])])])[]dnl
+m4_ifdef([$0_found], [m4_undefine([$0_found])], [$3
+])[]dnl
+])
+
+
+# _LT_SET_OPTIONS(MACRO-NAME, OPTION-LIST)
+# ----------------------------------------
+# OPTION-LIST is a space-separated list of Libtool options associated
+# with MACRO-NAME.  If any OPTION has a matching handler declared with
+# LT_OPTION_DEFINE, dispatch to that macro; otherwise complain about
+# the unknown option and exit.
+m4_defun([_LT_SET_OPTIONS],
+[# Set options
+m4_foreach([_LT_Option], m4_split(m4_normalize([$2])),
+    [_LT_SET_OPTION([$1], _LT_Option)])
+
+m4_if([$1],[LT_INIT],[
+  dnl
+  dnl Simply set some default values (i.e off) if boolean options were not
+  dnl specified:
+  _LT_UNLESS_OPTIONS([LT_INIT], [dlopen], [enable_dlopen=no
+  ])
+  _LT_UNLESS_OPTIONS([LT_INIT], [win32-dll], [enable_win32_dll=no
+  ])
+  dnl
+  dnl If no reference was made to various pairs of opposing options, then
+  dnl we run the default mode handler for the pair.  For example, if neither
+  dnl `shared' nor `disable-shared' was passed, we enable building of shared
+  dnl archives by default:
+  _LT_UNLESS_OPTIONS([LT_INIT], [shared disable-shared], [_LT_ENABLE_SHARED])
+  _LT_UNLESS_OPTIONS([LT_INIT], [static disable-static], [_LT_ENABLE_STATIC])
+  _LT_UNLESS_OPTIONS([LT_INIT], [pic-only no-pic], [_LT_WITH_PIC])
+  _LT_UNLESS_OPTIONS([LT_INIT], [fast-install disable-fast-install],
+  		   [_LT_ENABLE_FAST_INSTALL])
+  ])
+])# _LT_SET_OPTIONS
+
+
+## --------------------------------- ##
+## Macros to handle LT_INIT options. ##
+## --------------------------------- ##
+
+# _LT_MANGLE_DEFUN(MACRO-NAME, OPTION-NAME)
+# -----------------------------------------
+m4_define([_LT_MANGLE_DEFUN],
+[[_LT_OPTION_DEFUN_]m4_bpatsubst(m4_toupper([$1__$2]), [[^A-Z0-9_]], [_])])
+
+
+# LT_OPTION_DEFINE(MACRO-NAME, OPTION-NAME, CODE)
+# -----------------------------------------------
+m4_define([LT_OPTION_DEFINE],
+[m4_define(_LT_MANGLE_DEFUN([$1], [$2]), [$3])[]dnl
+])# LT_OPTION_DEFINE
+
+
+# dlopen
+# ------
+LT_OPTION_DEFINE([LT_INIT], [dlopen], [enable_dlopen=yes
+])
+
+AU_DEFUN([AC_LIBTOOL_DLOPEN],
+[_LT_SET_OPTION([LT_INIT], [dlopen])
+AC_DIAGNOSE([obsolete],
+[$0: Remove this warning and the call to _LT_SET_OPTION when you
+put the `dlopen' option into LT_INIT's first parameter.])
+])
+
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AC_LIBTOOL_DLOPEN], [])
+
+
+# win32-dll
+# ---------
+# Declare package support for building win32 dll's.
+LT_OPTION_DEFINE([LT_INIT], [win32-dll],
+[enable_win32_dll=yes
+
+case $host in
+*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-cegcc*)
+  AC_CHECK_TOOL(AS, as, false)
+  AC_CHECK_TOOL(DLLTOOL, dlltool, false)
+  AC_CHECK_TOOL(OBJDUMP, objdump, false)
+  ;;
+esac
+
+test -z "$AS" && AS=as
+_LT_DECL([], [AS],      [0], [Assembler program])dnl
+
+test -z "$DLLTOOL" && DLLTOOL=dlltool
+_LT_DECL([], [DLLTOOL], [0], [DLL creation program])dnl
+
+test -z "$OBJDUMP" && OBJDUMP=objdump
+_LT_DECL([], [OBJDUMP], [0], [Object dumper program])dnl
+])# win32-dll
+
+AU_DEFUN([AC_LIBTOOL_WIN32_DLL],
+[AC_REQUIRE([AC_CANONICAL_HOST])dnl
+_LT_SET_OPTION([LT_INIT], [win32-dll])
+AC_DIAGNOSE([obsolete],
+[$0: Remove this warning and the call to _LT_SET_OPTION when you
+put the `win32-dll' option into LT_INIT's first parameter.])
+])
+
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AC_LIBTOOL_WIN32_DLL], [])
+
+
+# _LT_ENABLE_SHARED([DEFAULT])
+# ----------------------------
+# implement the --enable-shared flag, and supports the `shared' and
+# `disable-shared' LT_INIT options.
+# DEFAULT is either `yes' or `no'.  If omitted, it defaults to `yes'.
+m4_define([_LT_ENABLE_SHARED],
+[m4_define([_LT_ENABLE_SHARED_DEFAULT], [m4_if($1, no, no, yes)])dnl
+AC_ARG_ENABLE([shared],
+    [AS_HELP_STRING([--enable-shared@<:@=PKGS@:>@],
+	[build shared libraries @<:@default=]_LT_ENABLE_SHARED_DEFAULT[@:>@])],
+    [p=${PACKAGE-default}
+    case $enableval in
+    yes) enable_shared=yes ;;
+    no) enable_shared=no ;;
+    *)
+      enable_shared=no
+      # Look at the argument we got.  We use all the common list separators.
+      lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR,"
+      for pkg in $enableval; do
+	IFS="$lt_save_ifs"
+	if test "X$pkg" = "X$p"; then
+	  enable_shared=yes
+	fi
+      done
+      IFS="$lt_save_ifs"
+      ;;
+    esac],
+    [enable_shared=]_LT_ENABLE_SHARED_DEFAULT)
+
+    _LT_DECL([build_libtool_libs], [enable_shared], [0],
+	[Whether or not to build shared libraries])
+])# _LT_ENABLE_SHARED
+
+LT_OPTION_DEFINE([LT_INIT], [shared], [_LT_ENABLE_SHARED([yes])])
+LT_OPTION_DEFINE([LT_INIT], [disable-shared], [_LT_ENABLE_SHARED([no])])
+
+# Old names:
+AC_DEFUN([AC_ENABLE_SHARED],
+[_LT_SET_OPTION([LT_INIT], m4_if([$1], [no], [disable-])[shared])
+])
+
+AC_DEFUN([AC_DISABLE_SHARED],
+[_LT_SET_OPTION([LT_INIT], [disable-shared])
+])
+
+AU_DEFUN([AM_ENABLE_SHARED], [AC_ENABLE_SHARED($@)])
+AU_DEFUN([AM_DISABLE_SHARED], [AC_DISABLE_SHARED($@)])
+
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AM_ENABLE_SHARED], [])
+dnl AC_DEFUN([AM_DISABLE_SHARED], [])
+
+
+
+# _LT_ENABLE_STATIC([DEFAULT])
+# ----------------------------
+# implement the --enable-static flag, and support the `static' and
+# `disable-static' LT_INIT options.
+# DEFAULT is either `yes' or `no'.  If omitted, it defaults to `yes'.
+m4_define([_LT_ENABLE_STATIC],
+[m4_define([_LT_ENABLE_STATIC_DEFAULT], [m4_if($1, no, no, yes)])dnl
+AC_ARG_ENABLE([static],
+    [AS_HELP_STRING([--enable-static@<:@=PKGS@:>@],
+	[build static libraries @<:@default=]_LT_ENABLE_STATIC_DEFAULT[@:>@])],
+    [p=${PACKAGE-default}
+    case $enableval in
+    yes) enable_static=yes ;;
+    no) enable_static=no ;;
+    *)
+     enable_static=no
+      # Look at the argument we got.  We use all the common list separators.
+      lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR,"
+      for pkg in $enableval; do
+	IFS="$lt_save_ifs"
+	if test "X$pkg" = "X$p"; then
+	  enable_static=yes
+	fi
+      done
+      IFS="$lt_save_ifs"
+      ;;
+    esac],
+    [enable_static=]_LT_ENABLE_STATIC_DEFAULT)
+
+    _LT_DECL([build_old_libs], [enable_static], [0],
+	[Whether or not to build static libraries])
+])# _LT_ENABLE_STATIC
+
+LT_OPTION_DEFINE([LT_INIT], [static], [_LT_ENABLE_STATIC([yes])])
+LT_OPTION_DEFINE([LT_INIT], [disable-static], [_LT_ENABLE_STATIC([no])])
+
+# Old names:
+AC_DEFUN([AC_ENABLE_STATIC],
+[_LT_SET_OPTION([LT_INIT], m4_if([$1], [no], [disable-])[static])
+])
+
+AC_DEFUN([AC_DISABLE_STATIC],
+[_LT_SET_OPTION([LT_INIT], [disable-static])
+])
+
+AU_DEFUN([AM_ENABLE_STATIC], [AC_ENABLE_STATIC($@)])
+AU_DEFUN([AM_DISABLE_STATIC], [AC_DISABLE_STATIC($@)])
+
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AM_ENABLE_STATIC], [])
+dnl AC_DEFUN([AM_DISABLE_STATIC], [])
+
+
+
+# _LT_ENABLE_FAST_INSTALL([DEFAULT])
+# ----------------------------------
+# implement the --enable-fast-install flag, and support the `fast-install'
+# and `disable-fast-install' LT_INIT options.
+# DEFAULT is either `yes' or `no'.  If omitted, it defaults to `yes'.
+m4_define([_LT_ENABLE_FAST_INSTALL],
+[m4_define([_LT_ENABLE_FAST_INSTALL_DEFAULT], [m4_if($1, no, no, yes)])dnl
+AC_ARG_ENABLE([fast-install],
+    [AS_HELP_STRING([--enable-fast-install@<:@=PKGS@:>@],
+    [optimize for fast installation @<:@default=]_LT_ENABLE_FAST_INSTALL_DEFAULT[@:>@])],
+    [p=${PACKAGE-default}
+    case $enableval in
+    yes) enable_fast_install=yes ;;
+    no) enable_fast_install=no ;;
+    *)
+      enable_fast_install=no
+      # Look at the argument we got.  We use all the common list separators.
+      lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR,"
+      for pkg in $enableval; do
+	IFS="$lt_save_ifs"
+	if test "X$pkg" = "X$p"; then
+	  enable_fast_install=yes
+	fi
+      done
+      IFS="$lt_save_ifs"
+      ;;
+    esac],
+    [enable_fast_install=]_LT_ENABLE_FAST_INSTALL_DEFAULT)
+
+_LT_DECL([fast_install], [enable_fast_install], [0],
+	 [Whether or not to optimize for fast installation])dnl
+])# _LT_ENABLE_FAST_INSTALL
+
+LT_OPTION_DEFINE([LT_INIT], [fast-install], [_LT_ENABLE_FAST_INSTALL([yes])])
+LT_OPTION_DEFINE([LT_INIT], [disable-fast-install], [_LT_ENABLE_FAST_INSTALL([no])])
+
+# Old names:
+AU_DEFUN([AC_ENABLE_FAST_INSTALL],
+[_LT_SET_OPTION([LT_INIT], m4_if([$1], [no], [disable-])[fast-install])
+AC_DIAGNOSE([obsolete],
+[$0: Remove this warning and the call to _LT_SET_OPTION when you put
+the `fast-install' option into LT_INIT's first parameter.])
+])
+
+AU_DEFUN([AC_DISABLE_FAST_INSTALL],
+[_LT_SET_OPTION([LT_INIT], [disable-fast-install])
+AC_DIAGNOSE([obsolete],
+[$0: Remove this warning and the call to _LT_SET_OPTION when you put
+the `disable-fast-install' option into LT_INIT's first parameter.])
+])
+
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AC_ENABLE_FAST_INSTALL], [])
+dnl AC_DEFUN([AM_DISABLE_FAST_INSTALL], [])
+
+
+# _LT_WITH_PIC([MODE])
+# --------------------
+# implement the --with-pic flag, and support the `pic-only' and `no-pic'
+# LT_INIT options.
+# MODE is either `yes' or `no'.  If omitted, it defaults to `both'.
+m4_define([_LT_WITH_PIC],
+[AC_ARG_WITH([pic],
+    [AS_HELP_STRING([--with-pic],
+	[try to use only PIC/non-PIC objects @<:@default=use both@:>@])],
+    [pic_mode="$withval"],
+    [pic_mode=default])
+
+test -z "$pic_mode" && pic_mode=m4_default([$1], [default])
+
+_LT_DECL([], [pic_mode], [0], [What type of objects to build])dnl
+])# _LT_WITH_PIC
+
+LT_OPTION_DEFINE([LT_INIT], [pic-only], [_LT_WITH_PIC([yes])])
+LT_OPTION_DEFINE([LT_INIT], [no-pic], [_LT_WITH_PIC([no])])
+
+# Old name:
+AU_DEFUN([AC_LIBTOOL_PICMODE],
+[_LT_SET_OPTION([LT_INIT], [pic-only])
+AC_DIAGNOSE([obsolete],
+[$0: Remove this warning and the call to _LT_SET_OPTION when you
+put the `pic-only' option into LT_INIT's first parameter.])
+])
+
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AC_LIBTOOL_PICMODE], [])
+
+## ----------------- ##
+## LTDL_INIT Options ##
+## ----------------- ##
+
+m4_define([_LTDL_MODE], [])
+LT_OPTION_DEFINE([LTDL_INIT], [nonrecursive],
+		 [m4_define([_LTDL_MODE], [nonrecursive])])
+LT_OPTION_DEFINE([LTDL_INIT], [recursive],
+		 [m4_define([_LTDL_MODE], [recursive])])
+LT_OPTION_DEFINE([LTDL_INIT], [subproject],
+		 [m4_define([_LTDL_MODE], [subproject])])
+
+m4_define([_LTDL_TYPE], [])
+LT_OPTION_DEFINE([LTDL_INIT], [installable],
+		 [m4_define([_LTDL_TYPE], [installable])])
+LT_OPTION_DEFINE([LTDL_INIT], [convenience],
+		 [m4_define([_LTDL_TYPE], [convenience])])
diff --git a/m4macros/ltsugar.m4 b/m4macros/ltsugar.m4
new file mode 100644
index 0000000..9000a05
--- /dev/null
+++ b/m4macros/ltsugar.m4
@@ -0,0 +1,123 @@
+# ltsugar.m4 -- libtool m4 base layer.                         -*-Autoconf-*-
+#
+# Copyright (C) 2004, 2005, 2007, 2008 Free Software Foundation, Inc.
+# Written by Gary V. Vaughan, 2004
+#
+# This file is free software; the Free Software Foundation gives
+# unlimited permission to copy and/or distribute it, with or without
+# modifications, as long as this notice is preserved.
+
+# serial 6 ltsugar.m4
+
+# This is to help aclocal find these macros, as it can't see m4_define.
+AC_DEFUN([LTSUGAR_VERSION], [m4_if([0.1])])
+
+
+# lt_join(SEP, ARG1, [ARG2...])
+# -----------------------------
+# Produce ARG1SEPARG2...SEPARGn, omitting [] arguments and their
+# associated separator.
+# Needed until we can rely on m4_join from Autoconf 2.62, since all earlier
+# versions in m4sugar had bugs.
+m4_define([lt_join],
+[m4_if([$#], [1], [],
+       [$#], [2], [[$2]],
+       [m4_if([$2], [], [], [[$2]_])$0([$1], m4_shift(m4_shift($@)))])])
+m4_define([_lt_join],
+[m4_if([$#$2], [2], [],
+       [m4_if([$2], [], [], [[$1$2]])$0([$1], m4_shift(m4_shift($@)))])])
+
+
+# lt_car(LIST)
+# lt_cdr(LIST)
+# ------------
+# Manipulate m4 lists.
+# These macros are necessary as long as will still need to support
+# Autoconf-2.59 which quotes differently.
+m4_define([lt_car], [[$1]])
+m4_define([lt_cdr],
+[m4_if([$#], 0, [m4_fatal([$0: cannot be called without arguments])],
+       [$#], 1, [],
+       [m4_dquote(m4_shift($@))])])
+m4_define([lt_unquote], $1)
+
+
+# lt_append(MACRO-NAME, STRING, [SEPARATOR])
+# ------------------------------------------
+# Redefine MACRO-NAME to hold its former content plus `SEPARATOR'`STRING'.
+# Note that neither SEPARATOR nor STRING are expanded; they are appended
+# to MACRO-NAME as is (leaving the expansion for when MACRO-NAME is invoked).
+# No SEPARATOR is output if MACRO-NAME was previously undefined (different
+# than defined and empty).
+#
+# This macro is needed until we can rely on Autoconf 2.62, since earlier
+# versions of m4sugar mistakenly expanded SEPARATOR but not STRING.
+m4_define([lt_append],
+[m4_define([$1],
+	   m4_ifdef([$1], [m4_defn([$1])[$3]])[$2])])
+
+
+
+# lt_combine(SEP, PREFIX-LIST, INFIX, SUFFIX1, [SUFFIX2...])
+# ----------------------------------------------------------
+# Produce a SEP delimited list of all paired combinations of elements of
+# PREFIX-LIST with SUFFIX1 through SUFFIXn.  Each element of the list
+# has the form PREFIXmINFIXSUFFIXn.
+# Needed until we can rely on m4_combine added in Autoconf 2.62.
+m4_define([lt_combine],
+[m4_if(m4_eval([$# > 3]), [1],
+       [m4_pushdef([_Lt_sep], [m4_define([_Lt_sep], m4_defn([lt_car]))])]]dnl
+[[m4_foreach([_Lt_prefix], [$2],
+	     [m4_foreach([_Lt_suffix],
+		]m4_dquote(m4_dquote(m4_shift(m4_shift(m4_shift($@)))))[,
+	[_Lt_sep([$1])[]m4_defn([_Lt_prefix])[$3]m4_defn([_Lt_suffix])])])])])
+
+
+# lt_if_append_uniq(MACRO-NAME, VARNAME, [SEPARATOR], [UNIQ], [NOT-UNIQ])
+# -----------------------------------------------------------------------
+# Iff MACRO-NAME does not yet contain VARNAME, then append it (delimited
+# by SEPARATOR if supplied) and expand UNIQ, else NOT-UNIQ.
+m4_define([lt_if_append_uniq],
+[m4_ifdef([$1],
+	  [m4_if(m4_index([$3]m4_defn([$1])[$3], [$3$2$3]), [-1],
+		 [lt_append([$1], [$2], [$3])$4],
+		 [$5])],
+	  [lt_append([$1], [$2], [$3])$4])])
+
+
+# lt_dict_add(DICT, KEY, VALUE)
+# -----------------------------
+m4_define([lt_dict_add],
+[m4_define([$1($2)], [$3])])
+
+
+# lt_dict_add_subkey(DICT, KEY, SUBKEY, VALUE)
+# --------------------------------------------
+m4_define([lt_dict_add_subkey],
+[m4_define([$1($2:$3)], [$4])])
+
+
+# lt_dict_fetch(DICT, KEY, [SUBKEY])
+# ----------------------------------
+m4_define([lt_dict_fetch],
+[m4_ifval([$3],
+	m4_ifdef([$1($2:$3)], [m4_defn([$1($2:$3)])]),
+    m4_ifdef([$1($2)], [m4_defn([$1($2)])]))])
+
+
+# lt_if_dict_fetch(DICT, KEY, [SUBKEY], VALUE, IF-TRUE, [IF-FALSE])
+# -----------------------------------------------------------------
+m4_define([lt_if_dict_fetch],
+[m4_if(lt_dict_fetch([$1], [$2], [$3]), [$4],
+	[$5],
+    [$6])])
+
+
+# lt_dict_filter(DICT, [SUBKEY], VALUE, [SEPARATOR], KEY, [...])
+# --------------------------------------------------------------
+m4_define([lt_dict_filter],
+[m4_if([$5], [], [],
+  [lt_join(m4_quote(m4_default([$4], [[, ]])),
+           lt_unquote(m4_split(m4_normalize(m4_foreach(_Lt_key, lt_car([m4_shiftn(4, $@)]),
+		      [lt_if_dict_fetch([$1], _Lt_key, [$2], [$3], [_Lt_key ])])))))])[]dnl
+])
diff --git a/m4macros/ltversion.m4 b/m4macros/ltversion.m4
new file mode 100644
index 0000000..f3c5309
--- /dev/null
+++ b/m4macros/ltversion.m4
@@ -0,0 +1,23 @@
+# ltversion.m4 -- version numbers			-*- Autoconf -*-
+#
+#   Copyright (C) 2004 Free Software Foundation, Inc.
+#   Written by Scott James Remnant, 2004
+#
+# This file is free software; the Free Software Foundation gives
+# unlimited permission to copy and/or distribute it, with or without
+# modifications, as long as this notice is preserved.
+
+# Generated from ltversion.in.
+
+# serial 3017 ltversion.m4
+# This file is part of GNU Libtool
+
+m4_define([LT_PACKAGE_VERSION], [2.2.6b])
+m4_define([LT_PACKAGE_REVISION], [1.3017])
+
+AC_DEFUN([LTVERSION_VERSION],
+[macro_version='2.2.6b'
+macro_revision='1.3017'
+_LT_DECL(, macro_version, 0, [Which release of libtool.m4 was used?])
+_LT_DECL(, macro_revision, 0)
+])
diff --git a/m4macros/lt~obsolete.m4 b/m4macros/lt~obsolete.m4
new file mode 100644
index 0000000..637bb20
--- /dev/null
+++ b/m4macros/lt~obsolete.m4
@@ -0,0 +1,92 @@
+# lt~obsolete.m4 -- aclocal satisfying obsolete definitions.    -*-Autoconf-*-
+#
+#   Copyright (C) 2004, 2005, 2007 Free Software Foundation, Inc.
+#   Written by Scott James Remnant, 2004.
+#
+# This file is free software; the Free Software Foundation gives
+# unlimited permission to copy and/or distribute it, with or without
+# modifications, as long as this notice is preserved.
+
+# serial 4 lt~obsolete.m4
+
+# These exist entirely to fool aclocal when bootstrapping libtool.
+#
+# In the past libtool.m4 has provided macros via AC_DEFUN (or AU_DEFUN)
+# which have later been changed to m4_define as they aren't part of the
+# exported API, or moved to Autoconf or Automake where they belong.
+#
+# The trouble is, aclocal is a bit thick.  It'll see the old AC_DEFUN
+# in /usr/share/aclocal/libtool.m4 and remember it, then when it sees us
+# using a macro with the same name in our local m4/libtool.m4 it'll
+# pull the old libtool.m4 in (it doesn't see our shiny new m4_define
+# and doesn't know about Autoconf macros at all.)
+#
+# So we provide this file, which has a silly filename so it's always
+# included after everything else.  This provides aclocal with the
+# AC_DEFUNs it wants, but when m4 processes it, it doesn't do anything
+# because those macros already exist, or will be overwritten later.
+# We use AC_DEFUN over AU_DEFUN for compatibility with aclocal-1.6. 
+#
+# Anytime we withdraw an AC_DEFUN or AU_DEFUN, remember to add it here.
+# Yes, that means every name once taken will need to remain here until
+# we give up compatibility with versions before 1.7, at which point
+# we need to keep only those names which we still refer to.
+
+# This is to help aclocal find these macros, as it can't see m4_define.
+AC_DEFUN([LTOBSOLETE_VERSION], [m4_if([1])])
+
+m4_ifndef([AC_LIBTOOL_LINKER_OPTION],	[AC_DEFUN([AC_LIBTOOL_LINKER_OPTION])])
+m4_ifndef([AC_PROG_EGREP],		[AC_DEFUN([AC_PROG_EGREP])])
+m4_ifndef([_LT_AC_PROG_ECHO_BACKSLASH],	[AC_DEFUN([_LT_AC_PROG_ECHO_BACKSLASH])])
+m4_ifndef([_LT_AC_SHELL_INIT],		[AC_DEFUN([_LT_AC_SHELL_INIT])])
+m4_ifndef([_LT_AC_SYS_LIBPATH_AIX],	[AC_DEFUN([_LT_AC_SYS_LIBPATH_AIX])])
+m4_ifndef([_LT_PROG_LTMAIN],		[AC_DEFUN([_LT_PROG_LTMAIN])])
+m4_ifndef([_LT_AC_TAGVAR],		[AC_DEFUN([_LT_AC_TAGVAR])])
+m4_ifndef([AC_LTDL_ENABLE_INSTALL],	[AC_DEFUN([AC_LTDL_ENABLE_INSTALL])])
+m4_ifndef([AC_LTDL_PREOPEN],		[AC_DEFUN([AC_LTDL_PREOPEN])])
+m4_ifndef([_LT_AC_SYS_COMPILER],	[AC_DEFUN([_LT_AC_SYS_COMPILER])])
+m4_ifndef([_LT_AC_LOCK],		[AC_DEFUN([_LT_AC_LOCK])])
+m4_ifndef([AC_LIBTOOL_SYS_OLD_ARCHIVE],	[AC_DEFUN([AC_LIBTOOL_SYS_OLD_ARCHIVE])])
+m4_ifndef([_LT_AC_TRY_DLOPEN_SELF],	[AC_DEFUN([_LT_AC_TRY_DLOPEN_SELF])])
+m4_ifndef([AC_LIBTOOL_PROG_CC_C_O],	[AC_DEFUN([AC_LIBTOOL_PROG_CC_C_O])])
+m4_ifndef([AC_LIBTOOL_SYS_HARD_LINK_LOCKS], [AC_DEFUN([AC_LIBTOOL_SYS_HARD_LINK_LOCKS])])
+m4_ifndef([AC_LIBTOOL_OBJDIR],		[AC_DEFUN([AC_LIBTOOL_OBJDIR])])
+m4_ifndef([AC_LTDL_OBJDIR],		[AC_DEFUN([AC_LTDL_OBJDIR])])
+m4_ifndef([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH], [AC_DEFUN([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH])])
+m4_ifndef([AC_LIBTOOL_SYS_LIB_STRIP],	[AC_DEFUN([AC_LIBTOOL_SYS_LIB_STRIP])])
+m4_ifndef([AC_PATH_MAGIC],		[AC_DEFUN([AC_PATH_MAGIC])])
+m4_ifndef([AC_PROG_LD_GNU],		[AC_DEFUN([AC_PROG_LD_GNU])])
+m4_ifndef([AC_PROG_LD_RELOAD_FLAG],	[AC_DEFUN([AC_PROG_LD_RELOAD_FLAG])])
+m4_ifndef([AC_DEPLIBS_CHECK_METHOD],	[AC_DEFUN([AC_DEPLIBS_CHECK_METHOD])])
+m4_ifndef([AC_LIBTOOL_PROG_COMPILER_NO_RTTI], [AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_NO_RTTI])])
+m4_ifndef([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE], [AC_DEFUN([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE])])
+m4_ifndef([AC_LIBTOOL_PROG_COMPILER_PIC], [AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_PIC])])
+m4_ifndef([AC_LIBTOOL_PROG_LD_SHLIBS],	[AC_DEFUN([AC_LIBTOOL_PROG_LD_SHLIBS])])
+m4_ifndef([AC_LIBTOOL_POSTDEP_PREDEP],	[AC_DEFUN([AC_LIBTOOL_POSTDEP_PREDEP])])
+m4_ifndef([LT_AC_PROG_EGREP],		[AC_DEFUN([LT_AC_PROG_EGREP])])
+m4_ifndef([LT_AC_PROG_SED],		[AC_DEFUN([LT_AC_PROG_SED])])
+m4_ifndef([_LT_CC_BASENAME],		[AC_DEFUN([_LT_CC_BASENAME])])
+m4_ifndef([_LT_COMPILER_BOILERPLATE],	[AC_DEFUN([_LT_COMPILER_BOILERPLATE])])
+m4_ifndef([_LT_LINKER_BOILERPLATE],	[AC_DEFUN([_LT_LINKER_BOILERPLATE])])
+m4_ifndef([_AC_PROG_LIBTOOL],		[AC_DEFUN([_AC_PROG_LIBTOOL])])
+m4_ifndef([AC_LIBTOOL_SETUP],		[AC_DEFUN([AC_LIBTOOL_SETUP])])
+m4_ifndef([_LT_AC_CHECK_DLFCN],		[AC_DEFUN([_LT_AC_CHECK_DLFCN])])
+m4_ifndef([AC_LIBTOOL_SYS_DYNAMIC_LINKER],	[AC_DEFUN([AC_LIBTOOL_SYS_DYNAMIC_LINKER])])
+m4_ifndef([_LT_AC_TAGCONFIG],		[AC_DEFUN([_LT_AC_TAGCONFIG])])
+m4_ifndef([AC_DISABLE_FAST_INSTALL],	[AC_DEFUN([AC_DISABLE_FAST_INSTALL])])
+m4_ifndef([_LT_AC_LANG_CXX],		[AC_DEFUN([_LT_AC_LANG_CXX])])
+m4_ifndef([_LT_AC_LANG_F77],		[AC_DEFUN([_LT_AC_LANG_F77])])
+m4_ifndef([_LT_AC_LANG_GCJ],		[AC_DEFUN([_LT_AC_LANG_GCJ])])
+m4_ifndef([AC_LIBTOOL_RC],		[AC_DEFUN([AC_LIBTOOL_RC])])
+m4_ifndef([AC_LIBTOOL_LANG_C_CONFIG],	[AC_DEFUN([AC_LIBTOOL_LANG_C_CONFIG])])
+m4_ifndef([_LT_AC_LANG_C_CONFIG],	[AC_DEFUN([_LT_AC_LANG_C_CONFIG])])
+m4_ifndef([AC_LIBTOOL_LANG_CXX_CONFIG],	[AC_DEFUN([AC_LIBTOOL_LANG_CXX_CONFIG])])
+m4_ifndef([_LT_AC_LANG_CXX_CONFIG],	[AC_DEFUN([_LT_AC_LANG_CXX_CONFIG])])
+m4_ifndef([AC_LIBTOOL_LANG_F77_CONFIG],	[AC_DEFUN([AC_LIBTOOL_LANG_F77_CONFIG])])
+m4_ifndef([_LT_AC_LANG_F77_CONFIG],	[AC_DEFUN([_LT_AC_LANG_F77_CONFIG])])
+m4_ifndef([AC_LIBTOOL_LANG_GCJ_CONFIG],	[AC_DEFUN([AC_LIBTOOL_LANG_GCJ_CONFIG])])
+m4_ifndef([_LT_AC_LANG_GCJ_CONFIG],	[AC_DEFUN([_LT_AC_LANG_GCJ_CONFIG])])
+m4_ifndef([AC_LIBTOOL_LANG_RC_CONFIG],	[AC_DEFUN([AC_LIBTOOL_LANG_RC_CONFIG])])
+m4_ifndef([_LT_AC_LANG_RC_CONFIG],	[AC_DEFUN([_LT_AC_LANG_RC_CONFIG])])
+m4_ifndef([AC_LIBTOOL_CONFIG],		[AC_DEFUN([AC_LIBTOOL_CONFIG])])
+m4_ifndef([_LT_AC_FILE_LTDLL_C],	[AC_DEFUN([_LT_AC_FILE_LTDLL_C])])
diff --git a/m4macros/purify.m4 b/m4macros/purify.m4
new file mode 100644
index 0000000..07ba478
--- /dev/null
+++ b/m4macros/purify.m4
@@ -0,0 +1,28 @@
+# PURIFY
+#------------------------
+# Checks for the INTROOT area
+AC_DEFUN([CHECK_PURIFY],
+[
+
+    AC_MSG_CHECKING([for PURIFY availability])
+
+    AC_ARG_ENABLE(purify,
+      AC_HELP_STRING([--disable-purify],
+        [disables the check for the PURIFY installation]),
+        enable_purify=$enableval,
+        enable_purify=yes)
+
+    if test "x$enable_purify" = xyes ; then
+      AC_CHECK_PROG([PURIFY_CMD], [purify], [purify],[NONE])
+      if test "$PURIFY_CMD" = "NONE" ; then
+        AC_MSG_RESULT([disabled])
+        enable_purify=no
+      else
+        AC_MSG_RESULT([enabled])
+      fi
+    else
+      AC_MSG_RESULT([disabled])
+    fi
+
+    AM_CONDITIONAL([PURIFY], [test "x$enable_purify" = "xyes"])
+])
diff --git a/recipes/Makefile.am b/recipes/Makefile.am
new file mode 100644
index 0000000..7761add
--- /dev/null
+++ b/recipes/Makefile.am
@@ -0,0 +1,278 @@
+## Process this file with automake to produce Makefile.in
+##   This file is part of the SINFONI Pipeline
+##   Copyright (C) 2002,2003 European Southern Observatory
+
+##   This library is free software; you can redistribute it and/or modify
+##   it under the terms of the GNU General Public License as published by
+##   the Free Software Foundation; either version 2 of the License, or
+##   (at your option) any later version.
+##   This program is distributed in the hope that it will be useful,
+##   but WITHOUT ANY WARRANTY; without even the implied warranty of
+##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+##   GNU General Public License for more details.
+
+##   You should have received a copy of the GNU General Public License
+##   along with this program; if not, write to the Free Software
+##   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+AUTOMAKE_OPTIONS = 1.6 foreign
+
+DISTCLEANFILES = *~
+
+SUBDIRS = tests
+
+INCLUDES = $(all_includes)
+
+if MAINTAINER_MODE
+
+MAINTAINERCLEANFILES = Makefile.in
+
+endif
+
+pkginclude_HEADERS =
+
+noinst_HEADERS = 
+
+plugin_LTLIBRARIES = \
+	sinfo_rec_detlin.la \
+	sinfo_rec_distortion.la \
+	sinfo_rec_jitter.la \
+	sinfo_rec_mdark.la \
+	sinfo_rec_mflat.la \
+	sinfo_rec_pupil.la \
+	sinfo_rec_wavecal.la \
+	sinfo_utl_bp_mask_add.la \
+	sinfo_utl_cube2ima.la \
+	sinfo_utl_cube2spectrum.la \
+	sinfo_utl_cube_arith.la \
+	sinfo_utl_cube_combine.la \
+	sinfo_utl_cube_create.la \
+	sinfo_utl_ima_arith.la \
+	sinfo_utl_ima_line_corr.la \
+	sinfo_utl_skycor.la \
+	sinfo_utl_skymap.la \
+	sinfo_utl_spectrum_divide_by_blackbody.la \
+	sinfo_utl_eff.la \
+	sinfo_utl_spectrum_wavelength_shift.la 
+
+#	sinfo_rec_lingain.la \
+#	sinfo_rec_mdark_detmon.la \
+#	sinfo_img_noise.la
+#	sinfo_utl_ima_cube_ks_test.la \
+#	sinfo_utl_ima_gauss.la \
+#	sinfo_utl_table_ex.la \
+#	sinfo_utl_seds.la \
+#	sinfo_utl_stdstars.la 
+
+#	sinfo_step_stdstar.la \
+#	sinfo_step_jitter.la \
+#	sinfo_rec_objnod.la \
+#	sinfo_rec_psf.la \
+#	sinfo_utl_illumcorr.la \
+#	sinfo_utl_table_test.la 
+
+#New recipes
+
+#sinfo_utl_table_test_la_SOURCES = sinfo_utl_table_test.c
+#sinfo_utl_table_test_la_LIBADD = $(LIBSINFONI)
+#sinfo_utl_table_test_la_LDFLAGS = -module -avoid-version
+#sinfo_utl_table_test_la_DEPENDENCIES = $(LIBSINFONI)
+
+#sinfo_rec_mdark_detmon_la_SOURCES = sinfo_rec_mdark_detmon.c
+#sinfo_rec_mdark_detmon_la_LIBADD = $(LIBSINFONI)
+#sinfo_rec_mdark_detmon_la_LDFLAGS = -module -avoid-version
+#sinfo_rec_mdark_detmon_la_DEPENDENCIES = $(LIBSINFONI)
+
+sinfo_rec_detlin_la_SOURCES = sinfo_rec_detlin.c
+sinfo_rec_detlin_la_LIBADD = $(LIBSINFONI)
+sinfo_rec_detlin_la_LDFLAGS = -module -avoid-version
+sinfo_rec_detlin_la_DEPENDENCIES = $(LIBSINFONI)
+
+sinfo_rec_distortion_la_SOURCES = sinfo_rec_distortion.c
+sinfo_rec_distortion_la_LIBADD = $(LIBSINFONI)
+sinfo_rec_distortion_la_LDFLAGS = -module -avoid-version
+sinfo_rec_distortion_la_DEPENDENCIES = $(LIBSINFONI) 
+
+sinfo_rec_jitter_la_SOURCES = sinfo_rec_jitter.c 
+sinfo_rec_jitter_la_LIBADD = $(LIBSINFONI)
+sinfo_rec_jitter_la_LDFLAGS = -module -avoid-version
+sinfo_rec_jitter_la_DEPENDENCIES = $(LIBSINFONI)
+
+
+#sinfo_rec_lingain_la_SOURCES = sinfo_rec_lingain.c
+#sinfo_rec_lingain_la_LIBADD = $(LIBSINFONI)
+#sinfo_rec_lingain_la_LDFLAGS = -module -avoid-version
+#sinfo_rec_lingain_la_DEPENDENCIES = $(LIBSINFONI)
+
+sinfo_rec_mdark_la_SOURCES = sinfo_rec_mdark.c
+sinfo_rec_mdark_la_LIBADD = $(LIBSINFONI)
+sinfo_rec_mdark_la_LDFLAGS = -module -avoid-version
+sinfo_rec_mdark_la_DEPENDENCIES = $(LIBSINFONI)
+
+sinfo_rec_mflat_la_SOURCES = sinfo_rec_mflat.c
+sinfo_rec_mflat_la_LIBADD = $(LIBSINFONI)
+sinfo_rec_mflat_la_LDFLAGS = -module -avoid-version
+sinfo_rec_mflat_la_DEPENDENCIES = $(LIBSINFONI)
+
+#sinfo_rec_objnod_la_SOURCES = sinfo_rec_objnod.c 
+#sinfo_rec_objnod_la_LIBADD = $(LIBSINFONI)
+#sinfo_rec_objnod_la_LDFLAGS = -module -avoid-version
+#sinfo_rec_objnod_la_DEPENDENCIES = $(LIBSINFONI)
+
+#sinfo_rec_psf_la_SOURCES = sinfo_rec_psf.c 
+#sinfo_rec_psf_la_LIBADD = $(LIBSINFONI) 
+#sinfo_rec_psf_la_LDFLAGS = -module -avoid-version
+#sinfo_rec_psf_la_DEPENDENCIES = $(LIBSINFONI)
+
+sinfo_rec_pupil_la_SOURCES = sinfo_rec_pupil.c 
+sinfo_rec_pupil_la_LIBADD = $(LIBSINFONI) 
+sinfo_rec_pupil_la_LDFLAGS = -module -avoid-version
+sinfo_rec_pupil_la_DEPENDENCIES = $(LIBSINFONI)
+
+#sinfo_rec_stdstar_la_SOURCES = sinfo_rec_stdstar.c 
+#sinfo_rec_stdstar_la_LIBADD = $(LIBSINFONI)
+#sinfo_rec_stdstar_la_LDFLAGS = -module -avoid-version
+#sinfo_rec_stdstar_la_DEPENDENCIES = $(LIBSINFONI)
+
+sinfo_rec_wavecal_la_SOURCES = sinfo_rec_wavecal.c 
+sinfo_rec_wavecal_la_LIBADD = $(LIBSINFONI)
+sinfo_rec_wavecal_la_LDFLAGS = -module -avoid-version
+sinfo_rec_wavecal_la_DEPENDENCIES = $(LIBSINFONI)
+
+#sinfo_step_jitter_la_SOURCES = sinfo_step_jitter.c 
+#sinfo_step_jitter_la_LIBADD = $(LIBSINFONI)
+#sinfo_step_jitter_la_LDFLAGS = -module -avoid-version
+#sinfo_step_jitter_la_DEPENDENCIES = $(LIBSINFONI)
+
+
+#sinfo_step_psf_la_SOURCES = sinfo_step_psf.c
+#sinfo_step_psf_la_LIBADD = $(LIBSINFONI)
+#sinfo_step_psf_la_LDFLAGS = -module -avoid-version
+#sinfo_step_psf_la_DEPENDENCIES = $(LIBSINFONI)
+
+#sinfo_step_stdstar_la_SOURCES = sinfo_step_stdstar.c
+#sinfo_step_stdstar_la_LIBADD = $(LIBSINFONI)
+#sinfo_step_stdstar_la_LDFLAGS = -module -avoid-version
+#sinfo_step_stdstar_la_DEPENDENCIES = $(LIBSINFONI)
+
+#sinfo_step_objnod_la_SOURCES = sinfo_step_objnod.c
+#sinfo_step_objnod_la_LIBADD = $(LIBSINFONI)
+#sinfo_step_objnod_la_LDFLAGS = -module -avoid-version
+#sinfo_step_objnod_la_DEPENDENCIES = $(LIBSINFONI)
+
+
+#sinfo_step_distortion_la_SOURCES = sinfo_step_distortion.c
+#sinfo_step_distortion_la_LIBADD = $(LIBSINFONI)
+#sinfo_step_distortion_la_LDFLAGS = -module -avoid-version
+#sinfo_step_distortion_la_DEPENDENCIES = $(LIBSINFONI)
+
+
+sinfo_utl_bp_mask_add_la_SOURCES = sinfo_utl_bp_mask_add.c
+sinfo_utl_bp_mask_add_la_LIBADD = $(LIBSINFONI)
+sinfo_utl_bp_mask_add_la_LDFLAGS = -module -avoid-version
+sinfo_utl_bp_mask_add_la_DEPENDENCIES = $(LIBSINFONI)
+
+sinfo_utl_cube2ima_la_SOURCES = sinfo_utl_cube2ima.c
+sinfo_utl_cube2ima_la_LIBADD = $(LIBSINFONI)
+sinfo_utl_cube2ima_la_LDFLAGS = -module -avoid-version
+sinfo_utl_cube2ima_la_DEPENDENCIES = $(LIBSINFONI)
+
+#sinfo_utl_ima_cube_ks_test_la_SOURCES = sinfo_utl_ima_cube_ks_test.c
+#sinfo_utl_ima_cube_ks_test_la_LIBADD = $(LIBSINFONI)
+#sinfo_utl_ima_cube_ks_test_la_LDFLAGS = -module -avoid-version
+#sinfo_utl_ima_cube_ks_test_la_DEPENDENCIES = $(LIBSINFONI)
+
+sinfo_utl_eff_la_SOURCES = sinfo_utl_eff.c
+sinfo_utl_eff_la_LIBADD = $(LIBSINFONI)
+sinfo_utl_eff_la_LDFLAGS = -module -avoid-version
+sinfo_utl_eff_la_DEPENDENCIES = $(LIBSINFONI)
+
+sinfo_utl_cube2spectrum_la_SOURCES = sinfo_utl_cube2spectrum.c
+sinfo_utl_cube2spectrum_la_LIBADD = $(LIBSINFONI)
+sinfo_utl_cube2spectrum_la_LDFLAGS = -module -avoid-version
+sinfo_utl_cube2spectrum_la_DEPENDENCIES = $(LIBSINFONI)
+
+sinfo_utl_cube_arith_la_SOURCES = sinfo_utl_cube_arith.c
+sinfo_utl_cube_arith_la_LIBADD = $(LIBSINFONI)
+sinfo_utl_cube_arith_la_LDFLAGS = -module -avoid-version
+sinfo_utl_cube_arith_la_DEPENDENCIES = $(LIBSINFONI)
+
+sinfo_utl_cube_combine_la_SOURCES = sinfo_utl_cube_combine.c
+sinfo_utl_cube_combine_la_LIBADD = $(LIBSINFONI)
+sinfo_utl_cube_combine_la_LDFLAGS = -module -avoid-version
+sinfo_utl_cube_combine_la_DEPENDENCIES = $(LIBSINFONI)
+
+sinfo_utl_cube_create_la_SOURCES = sinfo_utl_cube_create.c
+sinfo_utl_cube_create_la_LIBADD = $(LIBSINFONI)
+sinfo_utl_cube_create_la_LDFLAGS = -module -avoid-version
+sinfo_utl_cube_create_la_DEPENDENCIES = $(LIBSINFONI)
+
+#sinfo_utl_illumcorr_la_SOURCES = sinfo_utl_illumcorr.c 
+#sinfo_utl_illumcorr_la_LIBADD = $(LIBSINFONI)
+#sinfo_utl_illumcorr_la_LDFLAGS = -module -avoid-version
+#sinfo_utl_illumcorr_la_DEPENDENCIES = $(LIBSINFONI)
+
+sinfo_utl_ima_arith_la_SOURCES = sinfo_utl_ima_arith.c
+sinfo_utl_ima_arith_la_LIBADD = $(LIBSINFONI)
+sinfo_utl_ima_arith_la_LDFLAGS = -module -avoid-version
+sinfo_utl_ima_arith_la_DEPENDENCIES = $(LIBSINFONI)
+
+#sinfo_utl_ima_gauss_la_SOURCES = sinfo_utl_ima_gauss.c
+#sinfo_utl_ima_gauss_la_LIBADD = $(LIBSINFONI)
+#sinfo_utl_ima_gauss_la_LDFLAGS = -module -avoid-version
+#sinfo_utl_ima_gauss_la_DEPENDENCIES = $(LIBSINFONI)
+
+sinfo_utl_ima_line_corr_la_SOURCES = sinfo_utl_ima_line_corr.c
+sinfo_utl_ima_line_corr_la_LIBADD = $(LIBSINFONI)
+sinfo_utl_ima_line_corr_la_LDFLAGS = -module -avoid-version
+sinfo_utl_ima_line_corr_la_DEPENDENCIES = $(LIBSINFONI)
+
+sinfo_utl_skycor_la_SOURCES = sinfo_utl_skycor.c
+sinfo_utl_skycor_la_LIBADD = $(LIBSINFONI)
+sinfo_utl_skycor_la_LDFLAGS = -module -avoid-version
+sinfo_utl_skycor_la_DEPENDENCIES = $(LIBSINFONI)
+
+
+sinfo_utl_skymap_la_SOURCES = sinfo_utl_skymap.c
+sinfo_utl_skymap_la_LIBADD = $(LIBSINFONI)
+sinfo_utl_skymap_la_LDFLAGS = -module -avoid-version
+sinfo_utl_skymap_la_DEPENDENCIES = $(LIBSINFONI)
+
+#sinfo_utl_table_ex_la_SOURCES = sinfo_utl_table_ex.c
+#sinfo_utl_table_ex_la_LIBADD = $(LIBSINFONI)
+#sinfo_utl_table_ex_la_LDFLAGS = -module -avoid-version
+#sinfo_utl_table_ex_la_DEPENDENCIES = $(LIBSINFONI)
+
+#sinfo_img_noise_la_SOURCES = sinfo_img_noise.c
+#sinfo_img_noise_la_LIBADD = $(LIBSINFONI)
+#sinfo_img_noise_la_LDFLAGS = -module -avoid-version
+#sinfo_img_noise_la_DEPENDENCIES = $(LIBSINFONI)
+
+sinfo_utl_spectrum_divide_by_blackbody_la_SOURCES = sinfo_utl_spectrum_divide_by_blackbody.c
+sinfo_utl_spectrum_divide_by_blackbody_la_LIBADD = $(LIBSINFONI)
+sinfo_utl_spectrum_divide_by_blackbody_la_LDFLAGS = -module -avoid-version
+sinfo_utl_spectrum_divide_by_blackbody_la_DEPENDENCIES = $(LIBSINFONI)
+
+
+sinfo_utl_spectrum_wavelength_shift_la_SOURCES = sinfo_utl_spectrum_wavelength_shift.c
+sinfo_utl_spectrum_wavelength_shift_la_LIBADD = $(LIBSINFONI)
+sinfo_utl_spectrum_wavelength_shift_la_LDFLAGS = -module -avoid-version
+sinfo_utl_spectrum_wavelength_shift_la_DEPENDENCIES = $(LIBSINFONI)
+
+#sinfo_utl_stdstars_la_SOURCES = sinfo_utl_stdstars.c
+#sinfo_utl_stdstars_la_LIBADD = $(LIBSINFONI)
+#sinfo_utl_stdstars_la_LDFLAGS = -module -avoid-version
+#sinfo_utl_stdstars_la_DEPENDENCIES = $(LIBSINFONI)
+
+
+#sinfo_utl_seds_la_SOURCES = sinfo_utl_seds.c
+#sinfo_utl_seds_la_LIBADD = $(LIBSINFONI)
+#sinfo_utl_seds_la_LDFLAGS = -module -avoid-version
+#sinfo_utl_seds_la_DEPENDENCIES = $(LIBSINFONI)
+
+
+
+
+
+
+
diff --git a/recipes/Makefile.in b/recipes/Makefile.in
new file mode 100644
index 0000000..3e11a06
--- /dev/null
+++ b/recipes/Makefile.in
@@ -0,0 +1,1158 @@
+# Makefile.in generated by automake 1.11 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009  Free Software Foundation,
+# Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+ at SET_MAKE@
+
+
+VPATH = @srcdir@
+pkgdatadir = $(datadir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkglibexecdir = $(libexecdir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
+target_triplet = @target@
+subdir = recipes
+DIST_COMMON = $(noinst_HEADERS) $(pkginclude_HEADERS) \
+	$(srcdir)/Makefile.am $(srcdir)/Makefile.in
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/m4macros/cpl.m4 \
+	$(top_srcdir)/m4macros/eso.m4 \
+	$(top_srcdir)/m4macros/libtool.m4 \
+	$(top_srcdir)/m4macros/ltoptions.m4 \
+	$(top_srcdir)/m4macros/ltsugar.m4 \
+	$(top_srcdir)/m4macros/ltversion.m4 \
+	$(top_srcdir)/m4macros/lt~obsolete.m4 \
+	$(top_srcdir)/m4macros/purify.m4 $(top_srcdir)/acinclude.m4 \
+	$(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+	$(ACLOCAL_M4)
+mkinstalldirs = $(install_sh) -d
+CONFIG_HEADER = $(top_builddir)/config.h
+CONFIG_CLEAN_FILES =
+CONFIG_CLEAN_VPATH_FILES =
+am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
+am__vpath_adj = case $$p in \
+    $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
+    *) f=$$p;; \
+  esac;
+am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`;
+am__install_max = 40
+am__nobase_strip_setup = \
+  srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'`
+am__nobase_strip = \
+  for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||"
+am__nobase_list = $(am__nobase_strip_setup); \
+  for p in $$list; do echo "$$p $$p"; done | \
+  sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \
+  $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \
+    if (++n[$$2] == $(am__install_max)) \
+      { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \
+    END { for (dir in files) print dir, files[dir] }'
+am__base_list = \
+  sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
+  sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
+am__installdirs = "$(DESTDIR)$(plugindir)" \
+	"$(DESTDIR)$(pkgincludedir)"
+LTLIBRARIES = $(plugin_LTLIBRARIES)
+am__DEPENDENCIES_1 =
+am_sinfo_rec_detlin_la_OBJECTS = sinfo_rec_detlin.lo
+sinfo_rec_detlin_la_OBJECTS = $(am_sinfo_rec_detlin_la_OBJECTS)
+sinfo_rec_detlin_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
+	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+	$(sinfo_rec_detlin_la_LDFLAGS) $(LDFLAGS) -o $@
+am_sinfo_rec_distortion_la_OBJECTS = sinfo_rec_distortion.lo
+sinfo_rec_distortion_la_OBJECTS =  \
+	$(am_sinfo_rec_distortion_la_OBJECTS)
+sinfo_rec_distortion_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
+	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+	$(sinfo_rec_distortion_la_LDFLAGS) $(LDFLAGS) -o $@
+am_sinfo_rec_jitter_la_OBJECTS = sinfo_rec_jitter.lo
+sinfo_rec_jitter_la_OBJECTS = $(am_sinfo_rec_jitter_la_OBJECTS)
+sinfo_rec_jitter_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
+	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+	$(sinfo_rec_jitter_la_LDFLAGS) $(LDFLAGS) -o $@
+am_sinfo_rec_mdark_la_OBJECTS = sinfo_rec_mdark.lo
+sinfo_rec_mdark_la_OBJECTS = $(am_sinfo_rec_mdark_la_OBJECTS)
+sinfo_rec_mdark_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
+	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+	$(sinfo_rec_mdark_la_LDFLAGS) $(LDFLAGS) -o $@
+am_sinfo_rec_mflat_la_OBJECTS = sinfo_rec_mflat.lo
+sinfo_rec_mflat_la_OBJECTS = $(am_sinfo_rec_mflat_la_OBJECTS)
+sinfo_rec_mflat_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
+	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+	$(sinfo_rec_mflat_la_LDFLAGS) $(LDFLAGS) -o $@
+am_sinfo_rec_pupil_la_OBJECTS = sinfo_rec_pupil.lo
+sinfo_rec_pupil_la_OBJECTS = $(am_sinfo_rec_pupil_la_OBJECTS)
+sinfo_rec_pupil_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
+	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+	$(sinfo_rec_pupil_la_LDFLAGS) $(LDFLAGS) -o $@
+am_sinfo_rec_wavecal_la_OBJECTS = sinfo_rec_wavecal.lo
+sinfo_rec_wavecal_la_OBJECTS = $(am_sinfo_rec_wavecal_la_OBJECTS)
+sinfo_rec_wavecal_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
+	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+	$(sinfo_rec_wavecal_la_LDFLAGS) $(LDFLAGS) -o $@
+am_sinfo_utl_bp_mask_add_la_OBJECTS = sinfo_utl_bp_mask_add.lo
+sinfo_utl_bp_mask_add_la_OBJECTS =  \
+	$(am_sinfo_utl_bp_mask_add_la_OBJECTS)
+sinfo_utl_bp_mask_add_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
+	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+	$(sinfo_utl_bp_mask_add_la_LDFLAGS) $(LDFLAGS) -o $@
+am_sinfo_utl_cube2ima_la_OBJECTS = sinfo_utl_cube2ima.lo
+sinfo_utl_cube2ima_la_OBJECTS = $(am_sinfo_utl_cube2ima_la_OBJECTS)
+sinfo_utl_cube2ima_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
+	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+	$(sinfo_utl_cube2ima_la_LDFLAGS) $(LDFLAGS) -o $@
+am_sinfo_utl_cube2spectrum_la_OBJECTS = sinfo_utl_cube2spectrum.lo
+sinfo_utl_cube2spectrum_la_OBJECTS =  \
+	$(am_sinfo_utl_cube2spectrum_la_OBJECTS)
+sinfo_utl_cube2spectrum_la_LINK = $(LIBTOOL) --tag=CC \
+	$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \
+	$(AM_CFLAGS) $(CFLAGS) $(sinfo_utl_cube2spectrum_la_LDFLAGS) \
+	$(LDFLAGS) -o $@
+am_sinfo_utl_cube_arith_la_OBJECTS = sinfo_utl_cube_arith.lo
+sinfo_utl_cube_arith_la_OBJECTS =  \
+	$(am_sinfo_utl_cube_arith_la_OBJECTS)
+sinfo_utl_cube_arith_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
+	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+	$(sinfo_utl_cube_arith_la_LDFLAGS) $(LDFLAGS) -o $@
+am_sinfo_utl_cube_combine_la_OBJECTS = sinfo_utl_cube_combine.lo
+sinfo_utl_cube_combine_la_OBJECTS =  \
+	$(am_sinfo_utl_cube_combine_la_OBJECTS)
+sinfo_utl_cube_combine_la_LINK = $(LIBTOOL) --tag=CC \
+	$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \
+	$(AM_CFLAGS) $(CFLAGS) $(sinfo_utl_cube_combine_la_LDFLAGS) \
+	$(LDFLAGS) -o $@
+am_sinfo_utl_cube_create_la_OBJECTS = sinfo_utl_cube_create.lo
+sinfo_utl_cube_create_la_OBJECTS =  \
+	$(am_sinfo_utl_cube_create_la_OBJECTS)
+sinfo_utl_cube_create_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
+	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+	$(sinfo_utl_cube_create_la_LDFLAGS) $(LDFLAGS) -o $@
+am_sinfo_utl_eff_la_OBJECTS = sinfo_utl_eff.lo
+sinfo_utl_eff_la_OBJECTS = $(am_sinfo_utl_eff_la_OBJECTS)
+sinfo_utl_eff_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
+	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+	$(sinfo_utl_eff_la_LDFLAGS) $(LDFLAGS) -o $@
+am_sinfo_utl_ima_arith_la_OBJECTS = sinfo_utl_ima_arith.lo
+sinfo_utl_ima_arith_la_OBJECTS = $(am_sinfo_utl_ima_arith_la_OBJECTS)
+sinfo_utl_ima_arith_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
+	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+	$(sinfo_utl_ima_arith_la_LDFLAGS) $(LDFLAGS) -o $@
+am_sinfo_utl_ima_line_corr_la_OBJECTS = sinfo_utl_ima_line_corr.lo
+sinfo_utl_ima_line_corr_la_OBJECTS =  \
+	$(am_sinfo_utl_ima_line_corr_la_OBJECTS)
+sinfo_utl_ima_line_corr_la_LINK = $(LIBTOOL) --tag=CC \
+	$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \
+	$(AM_CFLAGS) $(CFLAGS) $(sinfo_utl_ima_line_corr_la_LDFLAGS) \
+	$(LDFLAGS) -o $@
+am_sinfo_utl_skycor_la_OBJECTS = sinfo_utl_skycor.lo
+sinfo_utl_skycor_la_OBJECTS = $(am_sinfo_utl_skycor_la_OBJECTS)
+sinfo_utl_skycor_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
+	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+	$(sinfo_utl_skycor_la_LDFLAGS) $(LDFLAGS) -o $@
+am_sinfo_utl_skymap_la_OBJECTS = sinfo_utl_skymap.lo
+sinfo_utl_skymap_la_OBJECTS = $(am_sinfo_utl_skymap_la_OBJECTS)
+sinfo_utl_skymap_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
+	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+	$(sinfo_utl_skymap_la_LDFLAGS) $(LDFLAGS) -o $@
+am_sinfo_utl_spectrum_divide_by_blackbody_la_OBJECTS =  \
+	sinfo_utl_spectrum_divide_by_blackbody.lo
+sinfo_utl_spectrum_divide_by_blackbody_la_OBJECTS =  \
+	$(am_sinfo_utl_spectrum_divide_by_blackbody_la_OBJECTS)
+sinfo_utl_spectrum_divide_by_blackbody_la_LINK = $(LIBTOOL) --tag=CC \
+	$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \
+	$(AM_CFLAGS) $(CFLAGS) \
+	$(sinfo_utl_spectrum_divide_by_blackbody_la_LDFLAGS) \
+	$(LDFLAGS) -o $@
+am_sinfo_utl_spectrum_wavelength_shift_la_OBJECTS =  \
+	sinfo_utl_spectrum_wavelength_shift.lo
+sinfo_utl_spectrum_wavelength_shift_la_OBJECTS =  \
+	$(am_sinfo_utl_spectrum_wavelength_shift_la_OBJECTS)
+sinfo_utl_spectrum_wavelength_shift_la_LINK = $(LIBTOOL) --tag=CC \
+	$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \
+	$(AM_CFLAGS) $(CFLAGS) \
+	$(sinfo_utl_spectrum_wavelength_shift_la_LDFLAGS) $(LDFLAGS) \
+	-o $@
+DEFAULT_INCLUDES = -I. at am__isrc@ -I$(top_builddir)
+depcomp = $(SHELL) $(top_srcdir)/admin/depcomp
+am__depfiles_maybe = depfiles
+am__mv = mv -f
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+	--mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
+	$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+CCLD = $(CC)
+LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+	--mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
+	$(LDFLAGS) -o $@
+SOURCES = $(sinfo_rec_detlin_la_SOURCES) \
+	$(sinfo_rec_distortion_la_SOURCES) \
+	$(sinfo_rec_jitter_la_SOURCES) $(sinfo_rec_mdark_la_SOURCES) \
+	$(sinfo_rec_mflat_la_SOURCES) $(sinfo_rec_pupil_la_SOURCES) \
+	$(sinfo_rec_wavecal_la_SOURCES) \
+	$(sinfo_utl_bp_mask_add_la_SOURCES) \
+	$(sinfo_utl_cube2ima_la_SOURCES) \
+	$(sinfo_utl_cube2spectrum_la_SOURCES) \
+	$(sinfo_utl_cube_arith_la_SOURCES) \
+	$(sinfo_utl_cube_combine_la_SOURCES) \
+	$(sinfo_utl_cube_create_la_SOURCES) \
+	$(sinfo_utl_eff_la_SOURCES) $(sinfo_utl_ima_arith_la_SOURCES) \
+	$(sinfo_utl_ima_line_corr_la_SOURCES) \
+	$(sinfo_utl_skycor_la_SOURCES) $(sinfo_utl_skymap_la_SOURCES) \
+	$(sinfo_utl_spectrum_divide_by_blackbody_la_SOURCES) \
+	$(sinfo_utl_spectrum_wavelength_shift_la_SOURCES)
+DIST_SOURCES = $(sinfo_rec_detlin_la_SOURCES) \
+	$(sinfo_rec_distortion_la_SOURCES) \
+	$(sinfo_rec_jitter_la_SOURCES) $(sinfo_rec_mdark_la_SOURCES) \
+	$(sinfo_rec_mflat_la_SOURCES) $(sinfo_rec_pupil_la_SOURCES) \
+	$(sinfo_rec_wavecal_la_SOURCES) \
+	$(sinfo_utl_bp_mask_add_la_SOURCES) \
+	$(sinfo_utl_cube2ima_la_SOURCES) \
+	$(sinfo_utl_cube2spectrum_la_SOURCES) \
+	$(sinfo_utl_cube_arith_la_SOURCES) \
+	$(sinfo_utl_cube_combine_la_SOURCES) \
+	$(sinfo_utl_cube_create_la_SOURCES) \
+	$(sinfo_utl_eff_la_SOURCES) $(sinfo_utl_ima_arith_la_SOURCES) \
+	$(sinfo_utl_ima_line_corr_la_SOURCES) \
+	$(sinfo_utl_skycor_la_SOURCES) $(sinfo_utl_skymap_la_SOURCES) \
+	$(sinfo_utl_spectrum_divide_by_blackbody_la_SOURCES) \
+	$(sinfo_utl_spectrum_wavelength_shift_la_SOURCES)
+RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \
+	html-recursive info-recursive install-data-recursive \
+	install-dvi-recursive install-exec-recursive \
+	install-html-recursive install-info-recursive \
+	install-pdf-recursive install-ps-recursive install-recursive \
+	installcheck-recursive installdirs-recursive pdf-recursive \
+	ps-recursive uninstall-recursive
+HEADERS = $(noinst_HEADERS) $(pkginclude_HEADERS)
+RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive	\
+  distclean-recursive maintainer-clean-recursive
+AM_RECURSIVE_TARGETS = $(RECURSIVE_TARGETS:-recursive=) \
+	$(RECURSIVE_CLEAN_TARGETS:-recursive=) tags TAGS ctags CTAGS \
+	distdir
+ETAGS = etags
+CTAGS = ctags
+DIST_SUBDIRS = $(SUBDIRS)
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+am__relativize = \
+  dir0=`pwd`; \
+  sed_first='s,^\([^/]*\)/.*$$,\1,'; \
+  sed_rest='s,^[^/]*/*,,'; \
+  sed_last='s,^.*/\([^/]*\)$$,\1,'; \
+  sed_butlast='s,/*[^/]*$$,,'; \
+  while test -n "$$dir1"; do \
+    first=`echo "$$dir1" | sed -e "$$sed_first"`; \
+    if test "$$first" != "."; then \
+      if test "$$first" = ".."; then \
+        dir2=`echo "$$dir0" | sed -e "$$sed_last"`/"$$dir2"; \
+        dir0=`echo "$$dir0" | sed -e "$$sed_butlast"`; \
+      else \
+        first2=`echo "$$dir2" | sed -e "$$sed_first"`; \
+        if test "$$first2" = "$$first"; then \
+          dir2=`echo "$$dir2" | sed -e "$$sed_rest"`; \
+        else \
+          dir2="../$$dir2"; \
+        fi; \
+        dir0="$$dir0"/"$$first"; \
+      fi; \
+    fi; \
+    dir1=`echo "$$dir1" | sed -e "$$sed_rest"`; \
+  done; \
+  reldir="$$dir2"
+ACLOCAL = @ACLOCAL@
+AMTAR = @AMTAR@
+AR = @AR@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CPL_INCLUDES = @CPL_INCLUDES@
+CPL_LDFLAGS = @CPL_LDFLAGS@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CX_INCLUDES = @CX_INCLUDES@
+CX_LDFLAGS = @CX_LDFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+DOXYGEN = @DOXYGEN@
+DSYMUTIL = @DSYMUTIL@
+DUMPBIN = @DUMPBIN@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+ESO_DEBUG_FLAGS = @ESO_DEBUG_FLAGS@
+EXEEXT = @EXEEXT@
+FGREP = @FGREP@
+GREP = @GREP@
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+IRPLIB_INCLUDES = @IRPLIB_INCLUDES@
+IRPLIB_LDFLAGS = @IRPLIB_LDFLAGS@
+LATEX = @LATEX@
+LD = @LD@
+LDFLAGS = @LDFLAGS@
+LIBCEXT = @LIBCEXT@
+LIBCPLCORE = @LIBCPLCORE@
+LIBCPLDFS = @LIBCPLDFS@
+LIBCPLDRS = @LIBCPLDRS@
+LIBCPLUI = @LIBCPLUI@
+LIBIRPLIB = @LIBIRPLIB@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LIBSINFONI = @LIBSINFONI@
+LIBTOOL = @LIBTOOL@
+LIBTOOL_DEPS = @LIBTOOL_DEPS@
+LIPO = @LIPO@
+LN_S = @LN_S@
+LTLIBOBJS = @LTLIBOBJS@
+LT_AGE = @LT_AGE@
+LT_CURRENT = @LT_CURRENT@
+LT_REVISION = @LT_REVISION@
+MAINT = @MAINT@
+MAKEINFO = @MAKEINFO@
+MKDIR_P = @MKDIR_P@
+NM = @NM@
+NMEDIT = @NMEDIT@
+OBJDUMP = @OBJDUMP@
+OBJEXT = @OBJEXT@
+OTOOL = @OTOOL@
+OTOOL64 = @OTOOL64@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+PURIFY_CMD = @PURIFY_CMD@
+RANLIB = @RANLIB@
+SED = @SED@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+SINFONI_BINARY_AGE = @SINFONI_BINARY_AGE@
+SINFONI_BINARY_VERSION = @SINFONI_BINARY_VERSION@
+SINFONI_INCLUDES = @SINFONI_INCLUDES@
+SINFONI_INTERFACE_AGE = @SINFONI_INTERFACE_AGE@
+SINFONI_LDFLAGS = @SINFONI_LDFLAGS@
+SINFONI_MAJOR_VERSION = @SINFONI_MAJOR_VERSION@
+SINFONI_MICRO_VERSION = @SINFONI_MICRO_VERSION@
+SINFONI_MINOR_VERSION = @SINFONI_MINOR_VERSION@
+SINFONI_VERSION = @SINFONI_VERSION@
+STRIP = @STRIP@
+VERSION = @VERSION@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
+all_includes = @all_includes@
+all_ldflags = @all_ldflags@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build = @build@
+build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
+builddir = @builddir@
+configdir = @configdir@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
+exec_prefix = @exec_prefix@
+host = @host@
+host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localedir = @localedir@
+localstatedir = @localstatedir@
+lt_ECHO = @lt_ECHO@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+pipedocsdir = @pipedocsdir@
+plugindir = @plugindir@
+prefix = @prefix@
+privatelibdir = @privatelibdir@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
+sysconfdir = @sysconfdir@
+target = @target@
+target_alias = @target_alias@
+target_cpu = @target_cpu@
+target_os = @target_os@
+target_vendor = @target_vendor@
+top_build_prefix = @top_build_prefix@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+AUTOMAKE_OPTIONS = 1.6 foreign
+DISTCLEANFILES = *~
+SUBDIRS = tests
+INCLUDES = $(all_includes)
+ at MAINTAINER_MODE_TRUE@MAINTAINERCLEANFILES = Makefile.in
+pkginclude_HEADERS = 
+noinst_HEADERS = 
+plugin_LTLIBRARIES = \
+	sinfo_rec_detlin.la \
+	sinfo_rec_distortion.la \
+	sinfo_rec_jitter.la \
+	sinfo_rec_mdark.la \
+	sinfo_rec_mflat.la \
+	sinfo_rec_pupil.la \
+	sinfo_rec_wavecal.la \
+	sinfo_utl_bp_mask_add.la \
+	sinfo_utl_cube2ima.la \
+	sinfo_utl_cube2spectrum.la \
+	sinfo_utl_cube_arith.la \
+	sinfo_utl_cube_combine.la \
+	sinfo_utl_cube_create.la \
+	sinfo_utl_ima_arith.la \
+	sinfo_utl_ima_line_corr.la \
+	sinfo_utl_skycor.la \
+	sinfo_utl_skymap.la \
+	sinfo_utl_spectrum_divide_by_blackbody.la \
+	sinfo_utl_eff.la \
+	sinfo_utl_spectrum_wavelength_shift.la 
+
+
+#	sinfo_rec_lingain.la \
+#	sinfo_rec_mdark_detmon.la \
+#	sinfo_img_noise.la
+#	sinfo_utl_ima_cube_ks_test.la \
+#	sinfo_utl_ima_gauss.la \
+#	sinfo_utl_table_ex.la \
+#	sinfo_utl_seds.la \
+#	sinfo_utl_stdstars.la 
+
+#	sinfo_step_stdstar.la \
+#	sinfo_step_jitter.la \
+#	sinfo_rec_objnod.la \
+#	sinfo_rec_psf.la \
+#	sinfo_utl_illumcorr.la \
+#	sinfo_utl_table_test.la 
+
+#New recipes
+
+#sinfo_utl_table_test_la_SOURCES = sinfo_utl_table_test.c
+#sinfo_utl_table_test_la_LIBADD = $(LIBSINFONI)
+#sinfo_utl_table_test_la_LDFLAGS = -module -avoid-version
+#sinfo_utl_table_test_la_DEPENDENCIES = $(LIBSINFONI)
+
+#sinfo_rec_mdark_detmon_la_SOURCES = sinfo_rec_mdark_detmon.c
+#sinfo_rec_mdark_detmon_la_LIBADD = $(LIBSINFONI)
+#sinfo_rec_mdark_detmon_la_LDFLAGS = -module -avoid-version
+#sinfo_rec_mdark_detmon_la_DEPENDENCIES = $(LIBSINFONI)
+sinfo_rec_detlin_la_SOURCES = sinfo_rec_detlin.c
+sinfo_rec_detlin_la_LIBADD = $(LIBSINFONI)
+sinfo_rec_detlin_la_LDFLAGS = -module -avoid-version
+sinfo_rec_detlin_la_DEPENDENCIES = $(LIBSINFONI)
+sinfo_rec_distortion_la_SOURCES = sinfo_rec_distortion.c
+sinfo_rec_distortion_la_LIBADD = $(LIBSINFONI)
+sinfo_rec_distortion_la_LDFLAGS = -module -avoid-version
+sinfo_rec_distortion_la_DEPENDENCIES = $(LIBSINFONI) 
+sinfo_rec_jitter_la_SOURCES = sinfo_rec_jitter.c 
+sinfo_rec_jitter_la_LIBADD = $(LIBSINFONI)
+sinfo_rec_jitter_la_LDFLAGS = -module -avoid-version
+sinfo_rec_jitter_la_DEPENDENCIES = $(LIBSINFONI)
+
+#sinfo_rec_lingain_la_SOURCES = sinfo_rec_lingain.c
+#sinfo_rec_lingain_la_LIBADD = $(LIBSINFONI)
+#sinfo_rec_lingain_la_LDFLAGS = -module -avoid-version
+#sinfo_rec_lingain_la_DEPENDENCIES = $(LIBSINFONI)
+sinfo_rec_mdark_la_SOURCES = sinfo_rec_mdark.c
+sinfo_rec_mdark_la_LIBADD = $(LIBSINFONI)
+sinfo_rec_mdark_la_LDFLAGS = -module -avoid-version
+sinfo_rec_mdark_la_DEPENDENCIES = $(LIBSINFONI)
+sinfo_rec_mflat_la_SOURCES = sinfo_rec_mflat.c
+sinfo_rec_mflat_la_LIBADD = $(LIBSINFONI)
+sinfo_rec_mflat_la_LDFLAGS = -module -avoid-version
+sinfo_rec_mflat_la_DEPENDENCIES = $(LIBSINFONI)
+
+#sinfo_rec_objnod_la_SOURCES = sinfo_rec_objnod.c 
+#sinfo_rec_objnod_la_LIBADD = $(LIBSINFONI)
+#sinfo_rec_objnod_la_LDFLAGS = -module -avoid-version
+#sinfo_rec_objnod_la_DEPENDENCIES = $(LIBSINFONI)
+
+#sinfo_rec_psf_la_SOURCES = sinfo_rec_psf.c 
+#sinfo_rec_psf_la_LIBADD = $(LIBSINFONI) 
+#sinfo_rec_psf_la_LDFLAGS = -module -avoid-version
+#sinfo_rec_psf_la_DEPENDENCIES = $(LIBSINFONI)
+sinfo_rec_pupil_la_SOURCES = sinfo_rec_pupil.c 
+sinfo_rec_pupil_la_LIBADD = $(LIBSINFONI) 
+sinfo_rec_pupil_la_LDFLAGS = -module -avoid-version
+sinfo_rec_pupil_la_DEPENDENCIES = $(LIBSINFONI)
+
+#sinfo_rec_stdstar_la_SOURCES = sinfo_rec_stdstar.c 
+#sinfo_rec_stdstar_la_LIBADD = $(LIBSINFONI)
+#sinfo_rec_stdstar_la_LDFLAGS = -module -avoid-version
+#sinfo_rec_stdstar_la_DEPENDENCIES = $(LIBSINFONI)
+sinfo_rec_wavecal_la_SOURCES = sinfo_rec_wavecal.c 
+sinfo_rec_wavecal_la_LIBADD = $(LIBSINFONI)
+sinfo_rec_wavecal_la_LDFLAGS = -module -avoid-version
+sinfo_rec_wavecal_la_DEPENDENCIES = $(LIBSINFONI)
+
+#sinfo_step_jitter_la_SOURCES = sinfo_step_jitter.c 
+#sinfo_step_jitter_la_LIBADD = $(LIBSINFONI)
+#sinfo_step_jitter_la_LDFLAGS = -module -avoid-version
+#sinfo_step_jitter_la_DEPENDENCIES = $(LIBSINFONI)
+
+#sinfo_step_psf_la_SOURCES = sinfo_step_psf.c
+#sinfo_step_psf_la_LIBADD = $(LIBSINFONI)
+#sinfo_step_psf_la_LDFLAGS = -module -avoid-version
+#sinfo_step_psf_la_DEPENDENCIES = $(LIBSINFONI)
+
+#sinfo_step_stdstar_la_SOURCES = sinfo_step_stdstar.c
+#sinfo_step_stdstar_la_LIBADD = $(LIBSINFONI)
+#sinfo_step_stdstar_la_LDFLAGS = -module -avoid-version
+#sinfo_step_stdstar_la_DEPENDENCIES = $(LIBSINFONI)
+
+#sinfo_step_objnod_la_SOURCES = sinfo_step_objnod.c
+#sinfo_step_objnod_la_LIBADD = $(LIBSINFONI)
+#sinfo_step_objnod_la_LDFLAGS = -module -avoid-version
+#sinfo_step_objnod_la_DEPENDENCIES = $(LIBSINFONI)
+
+#sinfo_step_distortion_la_SOURCES = sinfo_step_distortion.c
+#sinfo_step_distortion_la_LIBADD = $(LIBSINFONI)
+#sinfo_step_distortion_la_LDFLAGS = -module -avoid-version
+#sinfo_step_distortion_la_DEPENDENCIES = $(LIBSINFONI)
+sinfo_utl_bp_mask_add_la_SOURCES = sinfo_utl_bp_mask_add.c
+sinfo_utl_bp_mask_add_la_LIBADD = $(LIBSINFONI)
+sinfo_utl_bp_mask_add_la_LDFLAGS = -module -avoid-version
+sinfo_utl_bp_mask_add_la_DEPENDENCIES = $(LIBSINFONI)
+sinfo_utl_cube2ima_la_SOURCES = sinfo_utl_cube2ima.c
+sinfo_utl_cube2ima_la_LIBADD = $(LIBSINFONI)
+sinfo_utl_cube2ima_la_LDFLAGS = -module -avoid-version
+sinfo_utl_cube2ima_la_DEPENDENCIES = $(LIBSINFONI)
+
+#sinfo_utl_ima_cube_ks_test_la_SOURCES = sinfo_utl_ima_cube_ks_test.c
+#sinfo_utl_ima_cube_ks_test_la_LIBADD = $(LIBSINFONI)
+#sinfo_utl_ima_cube_ks_test_la_LDFLAGS = -module -avoid-version
+#sinfo_utl_ima_cube_ks_test_la_DEPENDENCIES = $(LIBSINFONI)
+sinfo_utl_eff_la_SOURCES = sinfo_utl_eff.c
+sinfo_utl_eff_la_LIBADD = $(LIBSINFONI)
+sinfo_utl_eff_la_LDFLAGS = -module -avoid-version
+sinfo_utl_eff_la_DEPENDENCIES = $(LIBSINFONI)
+sinfo_utl_cube2spectrum_la_SOURCES = sinfo_utl_cube2spectrum.c
+sinfo_utl_cube2spectrum_la_LIBADD = $(LIBSINFONI)
+sinfo_utl_cube2spectrum_la_LDFLAGS = -module -avoid-version
+sinfo_utl_cube2spectrum_la_DEPENDENCIES = $(LIBSINFONI)
+sinfo_utl_cube_arith_la_SOURCES = sinfo_utl_cube_arith.c
+sinfo_utl_cube_arith_la_LIBADD = $(LIBSINFONI)
+sinfo_utl_cube_arith_la_LDFLAGS = -module -avoid-version
+sinfo_utl_cube_arith_la_DEPENDENCIES = $(LIBSINFONI)
+sinfo_utl_cube_combine_la_SOURCES = sinfo_utl_cube_combine.c
+sinfo_utl_cube_combine_la_LIBADD = $(LIBSINFONI)
+sinfo_utl_cube_combine_la_LDFLAGS = -module -avoid-version
+sinfo_utl_cube_combine_la_DEPENDENCIES = $(LIBSINFONI)
+sinfo_utl_cube_create_la_SOURCES = sinfo_utl_cube_create.c
+sinfo_utl_cube_create_la_LIBADD = $(LIBSINFONI)
+sinfo_utl_cube_create_la_LDFLAGS = -module -avoid-version
+sinfo_utl_cube_create_la_DEPENDENCIES = $(LIBSINFONI)
+
+#sinfo_utl_illumcorr_la_SOURCES = sinfo_utl_illumcorr.c 
+#sinfo_utl_illumcorr_la_LIBADD = $(LIBSINFONI)
+#sinfo_utl_illumcorr_la_LDFLAGS = -module -avoid-version
+#sinfo_utl_illumcorr_la_DEPENDENCIES = $(LIBSINFONI)
+sinfo_utl_ima_arith_la_SOURCES = sinfo_utl_ima_arith.c
+sinfo_utl_ima_arith_la_LIBADD = $(LIBSINFONI)
+sinfo_utl_ima_arith_la_LDFLAGS = -module -avoid-version
+sinfo_utl_ima_arith_la_DEPENDENCIES = $(LIBSINFONI)
+
+#sinfo_utl_ima_gauss_la_SOURCES = sinfo_utl_ima_gauss.c
+#sinfo_utl_ima_gauss_la_LIBADD = $(LIBSINFONI)
+#sinfo_utl_ima_gauss_la_LDFLAGS = -module -avoid-version
+#sinfo_utl_ima_gauss_la_DEPENDENCIES = $(LIBSINFONI)
+sinfo_utl_ima_line_corr_la_SOURCES = sinfo_utl_ima_line_corr.c
+sinfo_utl_ima_line_corr_la_LIBADD = $(LIBSINFONI)
+sinfo_utl_ima_line_corr_la_LDFLAGS = -module -avoid-version
+sinfo_utl_ima_line_corr_la_DEPENDENCIES = $(LIBSINFONI)
+sinfo_utl_skycor_la_SOURCES = sinfo_utl_skycor.c
+sinfo_utl_skycor_la_LIBADD = $(LIBSINFONI)
+sinfo_utl_skycor_la_LDFLAGS = -module -avoid-version
+sinfo_utl_skycor_la_DEPENDENCIES = $(LIBSINFONI)
+sinfo_utl_skymap_la_SOURCES = sinfo_utl_skymap.c
+sinfo_utl_skymap_la_LIBADD = $(LIBSINFONI)
+sinfo_utl_skymap_la_LDFLAGS = -module -avoid-version
+sinfo_utl_skymap_la_DEPENDENCIES = $(LIBSINFONI)
+
+#sinfo_utl_table_ex_la_SOURCES = sinfo_utl_table_ex.c
+#sinfo_utl_table_ex_la_LIBADD = $(LIBSINFONI)
+#sinfo_utl_table_ex_la_LDFLAGS = -module -avoid-version
+#sinfo_utl_table_ex_la_DEPENDENCIES = $(LIBSINFONI)
+
+#sinfo_img_noise_la_SOURCES = sinfo_img_noise.c
+#sinfo_img_noise_la_LIBADD = $(LIBSINFONI)
+#sinfo_img_noise_la_LDFLAGS = -module -avoid-version
+#sinfo_img_noise_la_DEPENDENCIES = $(LIBSINFONI)
+sinfo_utl_spectrum_divide_by_blackbody_la_SOURCES = sinfo_utl_spectrum_divide_by_blackbody.c
+sinfo_utl_spectrum_divide_by_blackbody_la_LIBADD = $(LIBSINFONI)
+sinfo_utl_spectrum_divide_by_blackbody_la_LDFLAGS = -module -avoid-version
+sinfo_utl_spectrum_divide_by_blackbody_la_DEPENDENCIES = $(LIBSINFONI)
+sinfo_utl_spectrum_wavelength_shift_la_SOURCES = sinfo_utl_spectrum_wavelength_shift.c
+sinfo_utl_spectrum_wavelength_shift_la_LIBADD = $(LIBSINFONI)
+sinfo_utl_spectrum_wavelength_shift_la_LDFLAGS = -module -avoid-version
+sinfo_utl_spectrum_wavelength_shift_la_DEPENDENCIES = $(LIBSINFONI)
+all: all-recursive
+
+.SUFFIXES:
+.SUFFIXES: .c .lo .o .obj
+$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am  $(am__configure_deps)
+	@for dep in $?; do \
+	  case '$(am__configure_deps)' in \
+	    *$$dep*) \
+	      ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+	        && { if test -f $@; then exit 0; else break; fi; }; \
+	      exit 1;; \
+	  esac; \
+	done; \
+	echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign recipes/Makefile'; \
+	$(am__cd) $(top_srcdir) && \
+	  $(AUTOMAKE) --foreign recipes/Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+	@case '$?' in \
+	  *config.status*) \
+	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+	  *) \
+	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
+	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+	esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(am__aclocal_m4_deps):
+install-pluginLTLIBRARIES: $(plugin_LTLIBRARIES)
+	@$(NORMAL_INSTALL)
+	test -z "$(plugindir)" || $(MKDIR_P) "$(DESTDIR)$(plugindir)"
+	@list='$(plugin_LTLIBRARIES)'; test -n "$(plugindir)" || list=; \
+	list2=; for p in $$list; do \
+	  if test -f $$p; then \
+	    list2="$$list2 $$p"; \
+	  else :; fi; \
+	done; \
+	test -z "$$list2" || { \
+	  echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(plugindir)'"; \
+	  $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(plugindir)"; \
+	}
+
+uninstall-pluginLTLIBRARIES:
+	@$(NORMAL_UNINSTALL)
+	@list='$(plugin_LTLIBRARIES)'; test -n "$(plugindir)" || list=; \
+	for p in $$list; do \
+	  $(am__strip_dir) \
+	  echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(plugindir)/$$f'"; \
+	  $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(plugindir)/$$f"; \
+	done
+
+clean-pluginLTLIBRARIES:
+	-test -z "$(plugin_LTLIBRARIES)" || rm -f $(plugin_LTLIBRARIES)
+	@list='$(plugin_LTLIBRARIES)'; for p in $$list; do \
+	  dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \
+	  test "$$dir" != "$$p" || dir=.; \
+	  echo "rm -f \"$${dir}/so_locations\""; \
+	  rm -f "$${dir}/so_locations"; \
+	done
+sinfo_rec_detlin.la: $(sinfo_rec_detlin_la_OBJECTS) $(sinfo_rec_detlin_la_DEPENDENCIES) 
+	$(sinfo_rec_detlin_la_LINK) -rpath $(plugindir) $(sinfo_rec_detlin_la_OBJECTS) $(sinfo_rec_detlin_la_LIBADD) $(LIBS)
+sinfo_rec_distortion.la: $(sinfo_rec_distortion_la_OBJECTS) $(sinfo_rec_distortion_la_DEPENDENCIES) 
+	$(sinfo_rec_distortion_la_LINK) -rpath $(plugindir) $(sinfo_rec_distortion_la_OBJECTS) $(sinfo_rec_distortion_la_LIBADD) $(LIBS)
+sinfo_rec_jitter.la: $(sinfo_rec_jitter_la_OBJECTS) $(sinfo_rec_jitter_la_DEPENDENCIES) 
+	$(sinfo_rec_jitter_la_LINK) -rpath $(plugindir) $(sinfo_rec_jitter_la_OBJECTS) $(sinfo_rec_jitter_la_LIBADD) $(LIBS)
+sinfo_rec_mdark.la: $(sinfo_rec_mdark_la_OBJECTS) $(sinfo_rec_mdark_la_DEPENDENCIES) 
+	$(sinfo_rec_mdark_la_LINK) -rpath $(plugindir) $(sinfo_rec_mdark_la_OBJECTS) $(sinfo_rec_mdark_la_LIBADD) $(LIBS)
+sinfo_rec_mflat.la: $(sinfo_rec_mflat_la_OBJECTS) $(sinfo_rec_mflat_la_DEPENDENCIES) 
+	$(sinfo_rec_mflat_la_LINK) -rpath $(plugindir) $(sinfo_rec_mflat_la_OBJECTS) $(sinfo_rec_mflat_la_LIBADD) $(LIBS)
+sinfo_rec_pupil.la: $(sinfo_rec_pupil_la_OBJECTS) $(sinfo_rec_pupil_la_DEPENDENCIES) 
+	$(sinfo_rec_pupil_la_LINK) -rpath $(plugindir) $(sinfo_rec_pupil_la_OBJECTS) $(sinfo_rec_pupil_la_LIBADD) $(LIBS)
+sinfo_rec_wavecal.la: $(sinfo_rec_wavecal_la_OBJECTS) $(sinfo_rec_wavecal_la_DEPENDENCIES) 
+	$(sinfo_rec_wavecal_la_LINK) -rpath $(plugindir) $(sinfo_rec_wavecal_la_OBJECTS) $(sinfo_rec_wavecal_la_LIBADD) $(LIBS)
+sinfo_utl_bp_mask_add.la: $(sinfo_utl_bp_mask_add_la_OBJECTS) $(sinfo_utl_bp_mask_add_la_DEPENDENCIES) 
+	$(sinfo_utl_bp_mask_add_la_LINK) -rpath $(plugindir) $(sinfo_utl_bp_mask_add_la_OBJECTS) $(sinfo_utl_bp_mask_add_la_LIBADD) $(LIBS)
+sinfo_utl_cube2ima.la: $(sinfo_utl_cube2ima_la_OBJECTS) $(sinfo_utl_cube2ima_la_DEPENDENCIES) 
+	$(sinfo_utl_cube2ima_la_LINK) -rpath $(plugindir) $(sinfo_utl_cube2ima_la_OBJECTS) $(sinfo_utl_cube2ima_la_LIBADD) $(LIBS)
+sinfo_utl_cube2spectrum.la: $(sinfo_utl_cube2spectrum_la_OBJECTS) $(sinfo_utl_cube2spectrum_la_DEPENDENCIES) 
+	$(sinfo_utl_cube2spectrum_la_LINK) -rpath $(plugindir) $(sinfo_utl_cube2spectrum_la_OBJECTS) $(sinfo_utl_cube2spectrum_la_LIBADD) $(LIBS)
+sinfo_utl_cube_arith.la: $(sinfo_utl_cube_arith_la_OBJECTS) $(sinfo_utl_cube_arith_la_DEPENDENCIES) 
+	$(sinfo_utl_cube_arith_la_LINK) -rpath $(plugindir) $(sinfo_utl_cube_arith_la_OBJECTS) $(sinfo_utl_cube_arith_la_LIBADD) $(LIBS)
+sinfo_utl_cube_combine.la: $(sinfo_utl_cube_combine_la_OBJECTS) $(sinfo_utl_cube_combine_la_DEPENDENCIES) 
+	$(sinfo_utl_cube_combine_la_LINK) -rpath $(plugindir) $(sinfo_utl_cube_combine_la_OBJECTS) $(sinfo_utl_cube_combine_la_LIBADD) $(LIBS)
+sinfo_utl_cube_create.la: $(sinfo_utl_cube_create_la_OBJECTS) $(sinfo_utl_cube_create_la_DEPENDENCIES) 
+	$(sinfo_utl_cube_create_la_LINK) -rpath $(plugindir) $(sinfo_utl_cube_create_la_OBJECTS) $(sinfo_utl_cube_create_la_LIBADD) $(LIBS)
+sinfo_utl_eff.la: $(sinfo_utl_eff_la_OBJECTS) $(sinfo_utl_eff_la_DEPENDENCIES) 
+	$(sinfo_utl_eff_la_LINK) -rpath $(plugindir) $(sinfo_utl_eff_la_OBJECTS) $(sinfo_utl_eff_la_LIBADD) $(LIBS)
+sinfo_utl_ima_arith.la: $(sinfo_utl_ima_arith_la_OBJECTS) $(sinfo_utl_ima_arith_la_DEPENDENCIES) 
+	$(sinfo_utl_ima_arith_la_LINK) -rpath $(plugindir) $(sinfo_utl_ima_arith_la_OBJECTS) $(sinfo_utl_ima_arith_la_LIBADD) $(LIBS)
+sinfo_utl_ima_line_corr.la: $(sinfo_utl_ima_line_corr_la_OBJECTS) $(sinfo_utl_ima_line_corr_la_DEPENDENCIES) 
+	$(sinfo_utl_ima_line_corr_la_LINK) -rpath $(plugindir) $(sinfo_utl_ima_line_corr_la_OBJECTS) $(sinfo_utl_ima_line_corr_la_LIBADD) $(LIBS)
+sinfo_utl_skycor.la: $(sinfo_utl_skycor_la_OBJECTS) $(sinfo_utl_skycor_la_DEPENDENCIES) 
+	$(sinfo_utl_skycor_la_LINK) -rpath $(plugindir) $(sinfo_utl_skycor_la_OBJECTS) $(sinfo_utl_skycor_la_LIBADD) $(LIBS)
+sinfo_utl_skymap.la: $(sinfo_utl_skymap_la_OBJECTS) $(sinfo_utl_skymap_la_DEPENDENCIES) 
+	$(sinfo_utl_skymap_la_LINK) -rpath $(plugindir) $(sinfo_utl_skymap_la_OBJECTS) $(sinfo_utl_skymap_la_LIBADD) $(LIBS)
+sinfo_utl_spectrum_divide_by_blackbody.la: $(sinfo_utl_spectrum_divide_by_blackbody_la_OBJECTS) $(sinfo_utl_spectrum_divide_by_blackbody_la_DEPENDENCIES) 
+	$(sinfo_utl_spectrum_divide_by_blackbody_la_LINK) -rpath $(plugindir) $(sinfo_utl_spectrum_divide_by_blackbody_la_OBJECTS) $(sinfo_utl_spectrum_divide_by_blackbody_la_LIBADD) $(LIBS)
+sinfo_utl_spectrum_wavelength_shift.la: $(sinfo_utl_spectrum_wavelength_shift_la_OBJECTS) $(sinfo_utl_spectrum_wavelength_shift_la_DEPENDENCIES) 
+	$(sinfo_utl_spectrum_wavelength_shift_la_LINK) -rpath $(plugindir) $(sinfo_utl_spectrum_wavelength_shift_la_OBJECTS) $(sinfo_utl_spectrum_wavelength_shift_la_LIBADD) $(LIBS)
+
+mostlyclean-compile:
+	-rm -f *.$(OBJEXT)
+
+distclean-compile:
+	-rm -f *.tab.c
+
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_rec_detlin.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_rec_distortion.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_rec_jitter.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_rec_mdark.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_rec_mflat.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_rec_pupil.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_rec_wavecal.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_utl_bp_mask_add.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_utl_cube2ima.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_utl_cube2spectrum.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_utl_cube_arith.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_utl_cube_combine.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_utl_cube_create.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_utl_eff.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_utl_ima_arith.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_utl_ima_line_corr.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_utl_skycor.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_utl_skymap.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_utl_spectrum_divide_by_blackbody.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_utl_spectrum_wavelength_shift.Plo at am__quote@
+
+.c.o:
+ at am__fastdepCC_TRUE@	$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+ at am__fastdepCC_TRUE@	$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCC_FALSE@	$(COMPILE) -c $<
+
+.c.obj:
+ at am__fastdepCC_TRUE@	$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
+ at am__fastdepCC_TRUE@	$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCC_FALSE@	$(COMPILE) -c `$(CYGPATH_W) '$<'`
+
+.c.lo:
+ at am__fastdepCC_TRUE@	$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+ at am__fastdepCC_TRUE@	$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCC_FALSE@	$(LTCOMPILE) -c -o $@ $<
+
+mostlyclean-libtool:
+	-rm -f *.lo
+
+clean-libtool:
+	-rm -rf .libs _libs
+install-pkgincludeHEADERS: $(pkginclude_HEADERS)
+	@$(NORMAL_INSTALL)
+	test -z "$(pkgincludedir)" || $(MKDIR_P) "$(DESTDIR)$(pkgincludedir)"
+	@list='$(pkginclude_HEADERS)'; test -n "$(pkgincludedir)" || list=; \
+	for p in $$list; do \
+	  if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
+	  echo "$$d$$p"; \
+	done | $(am__base_list) | \
+	while read files; do \
+	  echo " $(INSTALL_HEADER) $$files '$(DESTDIR)$(pkgincludedir)'"; \
+	  $(INSTALL_HEADER) $$files "$(DESTDIR)$(pkgincludedir)" || exit $$?; \
+	done
+
+uninstall-pkgincludeHEADERS:
+	@$(NORMAL_UNINSTALL)
+	@list='$(pkginclude_HEADERS)'; test -n "$(pkgincludedir)" || list=; \
+	files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
+	test -n "$$files" || exit 0; \
+	echo " ( cd '$(DESTDIR)$(pkgincludedir)' && rm -f" $$files ")"; \
+	cd "$(DESTDIR)$(pkgincludedir)" && rm -f $$files
+
+# This directory's subdirectories are mostly independent; you can cd
+# into them and run `make' without going through this Makefile.
+# To change the values of `make' variables: instead of editing Makefiles,
+# (1) if the variable is set in `config.status', edit `config.status'
+#     (which will cause the Makefiles to be regenerated when you run `make');
+# (2) otherwise, pass the desired values on the `make' command line.
+$(RECURSIVE_TARGETS):
+	@failcom='exit 1'; \
+	for f in x $$MAKEFLAGS; do \
+	  case $$f in \
+	    *=* | --[!k]*);; \
+	    *k*) failcom='fail=yes';; \
+	  esac; \
+	done; \
+	dot_seen=no; \
+	target=`echo $@ | sed s/-recursive//`; \
+	list='$(SUBDIRS)'; for subdir in $$list; do \
+	  echo "Making $$target in $$subdir"; \
+	  if test "$$subdir" = "."; then \
+	    dot_seen=yes; \
+	    local_target="$$target-am"; \
+	  else \
+	    local_target="$$target"; \
+	  fi; \
+	  ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
+	  || eval $$failcom; \
+	done; \
+	if test "$$dot_seen" = "no"; then \
+	  $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \
+	fi; test -z "$$fail"
+
+$(RECURSIVE_CLEAN_TARGETS):
+	@failcom='exit 1'; \
+	for f in x $$MAKEFLAGS; do \
+	  case $$f in \
+	    *=* | --[!k]*);; \
+	    *k*) failcom='fail=yes';; \
+	  esac; \
+	done; \
+	dot_seen=no; \
+	case "$@" in \
+	  distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \
+	  *) list='$(SUBDIRS)' ;; \
+	esac; \
+	rev=''; for subdir in $$list; do \
+	  if test "$$subdir" = "."; then :; else \
+	    rev="$$subdir $$rev"; \
+	  fi; \
+	done; \
+	rev="$$rev ."; \
+	target=`echo $@ | sed s/-recursive//`; \
+	for subdir in $$rev; do \
+	  echo "Making $$target in $$subdir"; \
+	  if test "$$subdir" = "."; then \
+	    local_target="$$target-am"; \
+	  else \
+	    local_target="$$target"; \
+	  fi; \
+	  ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
+	  || eval $$failcom; \
+	done && test -z "$$fail"
+tags-recursive:
+	list='$(SUBDIRS)'; for subdir in $$list; do \
+	  test "$$subdir" = . || ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) tags); \
+	done
+ctags-recursive:
+	list='$(SUBDIRS)'; for subdir in $$list; do \
+	  test "$$subdir" = . || ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) ctags); \
+	done
+
+ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
+	list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	mkid -fID $$unique
+tags: TAGS
+
+TAGS: tags-recursive $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
+		$(TAGS_FILES) $(LISP)
+	set x; \
+	here=`pwd`; \
+	if ($(ETAGS) --etags-include --version) >/dev/null 2>&1; then \
+	  include_option=--etags-include; \
+	  empty_fix=.; \
+	else \
+	  include_option=--include; \
+	  empty_fix=; \
+	fi; \
+	list='$(SUBDIRS)'; for subdir in $$list; do \
+	  if test "$$subdir" = .; then :; else \
+	    test ! -f $$subdir/TAGS || \
+	      set "$$@" "$$include_option=$$here/$$subdir/TAGS"; \
+	  fi; \
+	done; \
+	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	shift; \
+	if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
+	  test -n "$$unique" || unique=$$empty_fix; \
+	  if test $$# -gt 0; then \
+	    $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+	      "$$@" $$unique; \
+	  else \
+	    $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+	      $$unique; \
+	  fi; \
+	fi
+ctags: CTAGS
+CTAGS: ctags-recursive $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
+		$(TAGS_FILES) $(LISP)
+	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	test -z "$(CTAGS_ARGS)$$unique" \
+	  || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+	     $$unique
+
+GTAGS:
+	here=`$(am__cd) $(top_builddir) && pwd` \
+	  && $(am__cd) $(top_srcdir) \
+	  && gtags -i $(GTAGS_ARGS) "$$here"
+
+distclean-tags:
+	-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+
+distdir: $(DISTFILES)
+	@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+	topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+	list='$(DISTFILES)'; \
+	  dist_files=`for file in $$list; do echo $$file; done | \
+	  sed -e "s|^$$srcdirstrip/||;t" \
+	      -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+	case $$dist_files in \
+	  */*) $(MKDIR_P) `echo "$$dist_files" | \
+			   sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+			   sort -u` ;; \
+	esac; \
+	for file in $$dist_files; do \
+	  if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+	  if test -d $$d/$$file; then \
+	    dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+	    if test -d "$(distdir)/$$file"; then \
+	      find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+	    fi; \
+	    if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+	      cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
+	      find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+	    fi; \
+	    cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
+	  else \
+	    test -f "$(distdir)/$$file" \
+	    || cp -p $$d/$$file "$(distdir)/$$file" \
+	    || exit 1; \
+	  fi; \
+	done
+	@list='$(DIST_SUBDIRS)'; for subdir in $$list; do \
+	  if test "$$subdir" = .; then :; else \
+	    test -d "$(distdir)/$$subdir" \
+	    || $(MKDIR_P) "$(distdir)/$$subdir" \
+	    || exit 1; \
+	  fi; \
+	done
+	@list='$(DIST_SUBDIRS)'; for subdir in $$list; do \
+	  if test "$$subdir" = .; then :; else \
+	    dir1=$$subdir; dir2="$(distdir)/$$subdir"; \
+	    $(am__relativize); \
+	    new_distdir=$$reldir; \
+	    dir1=$$subdir; dir2="$(top_distdir)"; \
+	    $(am__relativize); \
+	    new_top_distdir=$$reldir; \
+	    echo " (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) top_distdir="$$new_top_distdir" distdir="$$new_distdir" \\"; \
+	    echo "     am__remove_distdir=: am__skip_length_check=: am__skip_mode_fix=: distdir)"; \
+	    ($(am__cd) $$subdir && \
+	      $(MAKE) $(AM_MAKEFLAGS) \
+	        top_distdir="$$new_top_distdir" \
+	        distdir="$$new_distdir" \
+		am__remove_distdir=: \
+		am__skip_length_check=: \
+		am__skip_mode_fix=: \
+	        distdir) \
+	      || exit 1; \
+	  fi; \
+	done
+check-am: all-am
+check: check-recursive
+all-am: Makefile $(LTLIBRARIES) $(HEADERS)
+installdirs: installdirs-recursive
+installdirs-am:
+	for dir in "$(DESTDIR)$(plugindir)" "$(DESTDIR)$(pkgincludedir)"; do \
+	  test -z "$$dir" || $(MKDIR_P) "$$dir"; \
+	done
+install: install-recursive
+install-exec: install-exec-recursive
+install-data: install-data-recursive
+uninstall: uninstall-recursive
+
+install-am: all-am
+	@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-recursive
+install-strip:
+	$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+	  install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+	  `test -z '$(STRIP)' || \
+	    echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+	-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+	-test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
+	-test -z "$(DISTCLEANFILES)" || rm -f $(DISTCLEANFILES)
+
+maintainer-clean-generic:
+	@echo "This command is intended for maintainers to use"
+	@echo "it deletes files that may require special tools to rebuild."
+	-test -z "$(MAINTAINERCLEANFILES)" || rm -f $(MAINTAINERCLEANFILES)
+clean: clean-recursive
+
+clean-am: clean-generic clean-libtool clean-pluginLTLIBRARIES \
+	mostlyclean-am
+
+distclean: distclean-recursive
+	-rm -rf ./$(DEPDIR)
+	-rm -f Makefile
+distclean-am: clean-am distclean-compile distclean-generic \
+	distclean-tags
+
+dvi: dvi-recursive
+
+dvi-am:
+
+html: html-recursive
+
+html-am:
+
+info: info-recursive
+
+info-am:
+
+install-data-am: install-pkgincludeHEADERS install-pluginLTLIBRARIES
+
+install-dvi: install-dvi-recursive
+
+install-dvi-am:
+
+install-exec-am:
+
+install-html: install-html-recursive
+
+install-html-am:
+
+install-info: install-info-recursive
+
+install-info-am:
+
+install-man:
+
+install-pdf: install-pdf-recursive
+
+install-pdf-am:
+
+install-ps: install-ps-recursive
+
+install-ps-am:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-recursive
+	-rm -rf ./$(DEPDIR)
+	-rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-recursive
+
+mostlyclean-am: mostlyclean-compile mostlyclean-generic \
+	mostlyclean-libtool
+
+pdf: pdf-recursive
+
+pdf-am:
+
+ps: ps-recursive
+
+ps-am:
+
+uninstall-am: uninstall-pkgincludeHEADERS uninstall-pluginLTLIBRARIES
+
+.MAKE: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) ctags-recursive \
+	install-am install-strip tags-recursive
+
+.PHONY: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) CTAGS GTAGS \
+	all all-am check check-am clean clean-generic clean-libtool \
+	clean-pluginLTLIBRARIES ctags ctags-recursive distclean \
+	distclean-compile distclean-generic distclean-libtool \
+	distclean-tags distdir dvi dvi-am html html-am info info-am \
+	install install-am install-data install-data-am install-dvi \
+	install-dvi-am install-exec install-exec-am install-html \
+	install-html-am install-info install-info-am install-man \
+	install-pdf install-pdf-am install-pkgincludeHEADERS \
+	install-pluginLTLIBRARIES install-ps install-ps-am \
+	install-strip installcheck installcheck-am installdirs \
+	installdirs-am maintainer-clean maintainer-clean-generic \
+	mostlyclean mostlyclean-compile mostlyclean-generic \
+	mostlyclean-libtool pdf pdf-am ps ps-am tags tags-recursive \
+	uninstall uninstall-am uninstall-pkgincludeHEADERS \
+	uninstall-pluginLTLIBRARIES
+
+
+#sinfo_utl_stdstars_la_SOURCES = sinfo_utl_stdstars.c
+#sinfo_utl_stdstars_la_LIBADD = $(LIBSINFONI)
+#sinfo_utl_stdstars_la_LDFLAGS = -module -avoid-version
+#sinfo_utl_stdstars_la_DEPENDENCIES = $(LIBSINFONI)
+
+#sinfo_utl_seds_la_SOURCES = sinfo_utl_seds.c
+#sinfo_utl_seds_la_LIBADD = $(LIBSINFONI)
+#sinfo_utl_seds_la_LDFLAGS = -module -avoid-version
+#sinfo_utl_seds_la_DEPENDENCIES = $(LIBSINFONI)
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/recipes/sinfo_rec_detlin.c b/recipes/sinfo_rec_detlin.c
new file mode 100644
index 0000000..818ebb6
--- /dev/null
+++ b/recipes/sinfo_rec_detlin.c
@@ -0,0 +1,303 @@
+/* $Id: sinfo_rec_detlin.c,v 1.21 2008/02/04 17:23:02 amodigli Exp $
+ *
+ * This file is part of the SINFONI Pipeline
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2008/02/04 17:23:02 $
+ * $Revision: 1.21 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+/**
+ * @defgroup sinfo_rec_detlin Recipe to determine detector linearity
+ */
+/*---------------------------------------------------------------------------*/
+/**@{*/
+
+ /****************************************************************
+  *           Bad pixel search  (normal method)                  *
+  ****************************************************************/
+
+/* --------------------------------------------------------------- 
+                         INCLUDES
+   --------------------------------------------------------------- */
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+/*----------------------------------------------------------------------------
+                                Includes
+ ----------------------------------------------------------------------------*/
+
+/* std libraries */
+#include <strings.h>
+#include <string.h>
+#include <stdio.h>
+
+/* cpl */
+#include <cpl.h>
+
+/* irplib */
+#include <irplib_utils.h>
+
+
+/* sinfoni */
+#include <sinfo_utilities.h>
+#include <sinfo_general_config.h>
+#include <sinfo_bp_lin_config.h>
+#include <sinfo_bp_config.h>
+#include <sinfo_bp_lin.h>
+#include <sinfo_product_config.h>
+
+#include <sinfo_bp_lin.h> 
+#include <sinfo_tpl_utils.h>
+#include <sinfo_functions.h>
+#include <sinfo_tpl_dfs.h>
+#include <sinfo_msg.h>
+#include <sinfo_error.h>
+#include <sinfo_utils_wrappers.h>
+
+/*---------------------------------------------------------------------------
+                            Functions prototypes
+ ---------------------------------------------------------------------------*/
+
+
+static int sinfo_rec_detlin_create(cpl_plugin *plugin);
+static int sinfo_rec_detlin_exec(cpl_plugin *plugin);
+static int sinfo_rec_detlin_destroy(cpl_plugin *plugin);
+static int sinfo_rec_detlin(cpl_parameterlist *, cpl_frameset *);
+
+/*----------------------------------------------------------------------------
+                            Static variables
+ ----------------------------------------------------------------------------*/
+
+static char sinfo_rec_detlin_description[] =
+"This recipe computes detector non linearities and a bad pixel map.\n"
+"The input files are increasing intensity raw flats\n"
+"their associated tags should be LINEARITY_LAMP.\n"
+"The output are: \n"
+"A table (PRO.CATG=LIN_DET_INFO) with information \n"
+"on the detector non linearities\n"
+"A table (PRO.CATG=GAIN_INFO) with information on the detector gain\n"
+"A cube (PRO.CATG=BP_COEFF) with the polynomial fit parameters \n"
+"of the detector non linearities\n"
+"A bad pixel map (PRO.CATG=BP_MAP_NL)\n"
+"Information on relevant parameters can be found with\n"
+"esorex --params sinfo_rec_detlin\n"
+"esorex --help sinfo_rec_detlin\n"
+"\n";
+/*---------------------------------------------------------------------------
+                                Functions code
+ ---------------------------------------------------------------------------*/
+/*--------------------------------------------------------------------------*/
+/**
+  @brief    Build the list of available plugins, for this module. 
+  @param    list    the plugin list
+  @return   0 if everything is ok, -1 otherwise
+
+  Create the recipe instance and make it available to the application using the 
+  interface. This function is exported.
+ */
+/*--------------------------------------------------------------------------*/
+
+
+int cpl_plugin_get_info(cpl_pluginlist *list)
+{
+
+  cpl_recipe *recipe = cpl_calloc(1, sizeof *recipe);
+  cpl_plugin *plugin = &recipe->interface;
+
+
+  cpl_plugin_init(plugin,
+          CPL_PLUGIN_API,
+          SINFONI_BINARY_VERSION,
+          CPL_PLUGIN_TYPE_RECIPE,
+          "sinfo_rec_detlin",
+          "Detector's linearity & non linear bad pixels determination.",
+          sinfo_rec_detlin_description,
+          "Andrea Modigliani",
+          "Andrea.Modigliani at eso.org",
+          sinfo_get_license(),
+          sinfo_rec_detlin_create,
+          sinfo_rec_detlin_exec,
+          sinfo_rec_detlin_destroy);
+
+  cpl_pluginlist_append(list, plugin);
+
+  return 0;
+
+}
+
+/*--------------------------------------------------------------------------*/
+/**
+  @brief    Setup the recipe options    
+  @param    plugin  the plugin
+  @return   0 if everything is ok
+
+  Defining the command-line/configuration parameters for the recipe.
+ */
+/*--------------------------------------------------------------------------*/
+static int sinfo_rec_detlin_create(cpl_plugin *plugin)
+{
+
+  /*
+   * We have to provide the option we accept to the application.
+   * We need to setup our parameter list and hook it into the recipe
+   * interface.
+   */
+
+
+    cpl_recipe      * recipe ;
+
+    /* Check that the plugin is part of a valid recipe */
+    if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+        recipe = (cpl_recipe *)plugin ;
+    else return -1 ;
+
+    cpl_error_reset();
+    irplib_reset();
+    /* Create the parameters list in the cpl_recipe object */
+    recipe->parameters = cpl_parameterlist_new() ; 
+
+    sinfo_general_config_add(recipe->parameters);
+    sinfo_product_config_add(recipe->parameters);
+    sinfo_bp_lin_config_add(recipe->parameters); 
+  
+    return 0;
+
+}
+
+/*--------------------------------------------------------------------------*/
+/**
+  @brief    Execute the plugin instance given by the interface
+  @param    plugin  the plugin
+  @return   0 if everything is ok
+ */
+/*--------------------------------------------------------------------------*/
+
+static int sinfo_rec_detlin_exec(cpl_plugin *plugin)
+{
+     cpl_recipe  *   recipe ;
+    
+    /* Get the recipe out of the plugin */
+    cpl_errorstate initial_errorstate = cpl_errorstate_get();
+
+    if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+        recipe = (cpl_recipe *)plugin ;
+    else return -1 ;
+  
+    if (!cpl_errorstate_is_equal(initial_errorstate)) {                      
+        /* Dump the error history since recipe execution start.                
+           At this point the recipe cannot recover from the error */           
+        cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);              
+    } 
+
+  return sinfo_rec_detlin(recipe->parameters, recipe->frames);
+
+}
+/*--------------------------------------------------------------------------*/
+/**
+  @brief    Destroy what has been created by the 'create' function
+  @param    plugin  the plugin
+  @return   0 if everything is ok
+ */
+/*--------------------------------------------------------------------------*/
+
+static int sinfo_rec_detlin_destroy(cpl_plugin *plugin)
+{
+     cpl_recipe  *   recipe ;
+    
+    /* Get the recipe out of the plugin */
+    if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+        recipe = (cpl_recipe *)plugin ;
+    else return -1 ;
+
+    cpl_parameterlist_delete(recipe->parameters) ; 
+
+  return 0;
+
+}
+
+/*
+ * The actual recipe actually start here.
+ */
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Interpret the command line options and execute the data processing
+  @param    parlist     the parameters list
+  @param    frameset   the frames list
+  @return   0 if everything is ok
+
+ This recipe computes detector non linearities and a bad pixel map.
+ The input files are increasing intensity raw flats their associated tags 
+ should be LINEARITY_LAMP.
+
+ The output are:
+ 
+ A table (PRO.CATG=LIN_DET_INFO) with information on the detector non 
+ linearities
+ A table (PRO.CATG=GAIN_INFO) with information on the detector gain
+ A cube (PRO.CATG=BP_COEFF) with the polynomial fit parameters of the detector 
+ non linearities
+ A bad pixel map (PRO.CATG=BP_MAP_NL)
+
+ */
+/*--------------------------------------------------------------------------*/
+
+static int sinfo_rec_detlin(cpl_parameterlist *config, cpl_frameset *set)
+{
+  cpl_parameter *p=NULL;          
+  int line_cor=0;
+
+  sinfo_msg("Welcome to SINFONI Pipeline release %d.%d.%d",
+        SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
+  /* Hidden parameters */
+  /* name of the data cube storing the found polynomial coefficients */
+  sinfo_bp_config_add(config);  
+  check_nomsg(p = cpl_parameterlist_find(config,"sinfoni.bp.method"));
+  check_nomsg(cpl_parameter_set_string(p,"Linear"));   
+
+  ck0(sinfo_dfs_set_groups(set),"Cannot indentify RAW and CALIB frames") ;
+
+  check_nomsg(p=cpl_parameterlist_find(config, "sinfoni.general.lc_sw"));
+  check_nomsg(line_cor=cpl_parameter_get_bool(p));
+  if(line_cor==1) {
+     check_nomsg(sinfo_ima_line_cor(config,set));
+  }
+
+
+  sinfo_msg("---------------------------------------");
+  sinfo_msg("BP_MAP_NL BAD PIXEL MAP DETERMINATION  ");
+  sinfo_msg("---------------------------------------");
+  ck0(sinfo_new_bp_search_lin(cpl_func,config,set),
+    "BP_MAP_NL BAD PIXEL MAP DETERMINATION FAILED") ;
+  sinfo_msg("BP_MAP_NL BAD PIXEL MAP DETERMINATION SUCCESS") ;
+
+ cleanup:
+
+  if (cpl_error_get_code() != CPL_ERROR_NONE) {
+    return -1;
+  } else {
+    return 0;
+  }
+
+}
+
+/**@}*/
diff --git a/recipes/sinfo_rec_distortion.c b/recipes/sinfo_rec_distortion.c
new file mode 100644
index 0000000..e8a61ac
--- /dev/null
+++ b/recipes/sinfo_rec_distortion.c
@@ -0,0 +1,848 @@
+/* $Id: sinfo_rec_distortion.c,v 1.42 2011/11/16 13:36:19 amodigli Exp $
+ *
+ * This file is part of the SINFONI Pipeline
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2011/11/16 13:36:19 $
+ * $Revision: 1.42 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+ /****************************************************************
+  *          Distortions Frames Data Reduction                          *
+  ****************************************************************/
+#ifdef HAVE_CONFIG_H
+#include <config.h>          /* allows the program compilation */
+#endif
+
+/*-----------------------------------------------------------------------------
+                                Includes
+ ----------------------------------------------------------------------------*/
+/* std */
+#include <strings.h>
+#include <string.h>
+
+#include <stdio.h>
+#include <math.h>
+
+/* cpl */       
+#include <cpl.h>       
+
+/* irplib */
+#include <irplib_utils.h>
+
+#include <sinfo_hidden.h>
+#include <sinfo_pro_types.h>
+#include <sinfo_raw_types.h>
+#include <sinfo_key_names.h>
+
+#include <sinfo_globals.h>
+#include <sinfo_general_config.h>
+#include <sinfo_utilities.h>
+#include <sinfo_product_config.h>
+#include <sinfo_lamp_flats_config.h>
+#include <sinfo_bp_config.h>
+#include <sinfo_bp_dist_config.h>
+#include <sinfo_prepare_stacked_frames_config.h>
+
+#include <sinfo_north_south_test_config.h>
+#include <sinfo_distortion_config.h>
+#include <sinfo_new_lamp_flats.h>
+#include <sinfo_bp_norm.h>
+#include <sinfo_new_prepare_stacked_frames.h>
+#include <sinfo_new_find_distortions.h>
+#include <sinfo_new_nst.h>
+
+#include <sinfo_functions.h>
+#include <sinfo_tpl_utils.h>
+#include <sinfo_tpl_dfs.h>
+#include <sinfo_msg.h>
+#include <sinfo_error.h>
+#include <sinfo_utils_wrappers.h>
+//Only for sinfo_propertylist_has
+#include <sinfo_dfs.h>
+
+
+
+/*-----------------------------------------------------------------------------
+                            Functions prototypes
+ ----------------------------------------------------------------------------*/
+
+static int sinfo_rec_distortion_create(cpl_plugin *plugin);
+static int sinfo_rec_distortion_exec(cpl_plugin *plugin);
+static int sinfo_rec_distortion_destroy(cpl_plugin *plugin);
+static int sinfo_rec_distortion(cpl_parameterlist *config, cpl_frameset *set);
+static int new_pre_process(cpl_frameset* set, 
+        const float lo_rej, const float hi_rej, const char* name_o);
+
+/*-----------------------------------------------------------------------------
+                            Static variables
+ ----------------------------------------------------------------------------*/
+static char sinfo_rec_distortion_description1[] =
+"This recipe determines the optical distortions and the slitlets distances.\n"
+"Necessary input are:\n"
+"Several (usually 75) raw frames classified as FIBRE_NS\n"
+"Standard (an 'ON' and an 'OFF') flat frames having classified as FLAT_NS\n"
+"Standard (an 'ON' and an 'OFF') arc lamp frames having classified as WAVE_NS\n"
+"A corresponding (band) reference arc line list classified as REF_LINE_ARC\n"
+"A reference table with data reduction parameters classified as DRS_SETUP_WAVE.\n";
+
+
+static char sinfo_rec_distortion_description2[] =
+"Default output are (with their PRO.CATG)\n"
+"A master flat: MASTER_FLAT_LAMP\n"
+"A Bad pixel map: BP_MAP_DI\n"
+"A fake-off fibre stacked frame: FIBRE_NS_STACKED_OFF\n"
+"A fake-on fibre  stacked frame: FIBRE_NS_STACKED_ON\n"
+"A fake on-off fibre  stacked frame: FIBRE_NS_STACKED\n"
+"A table with optical distortion coefficients: DISTORTION\n";
+
+
+static char sinfo_rec_distortion_description3[] =
+"A distortion corrected frame: FIBRE_NS_STACKED_DIST\n"
+"A temporary frame: MASTER_SLIT\n"
+"A table with the slitlets distances: SLITLETS_DISTANCE\n"
+"Information on relevant parameters can be found with:\n"
+"esorex --params sinfo_rec_distortion\n"
+"esorex --help sinfo_rec_distortion\n"
+"\n";
+
+static char sinfo_rec_distortion_description[1300];
+
+/*-----------------------------------------------------------------------------
+                                Functions code
+ ----------------------------------------------------------------------------*/
+/*---------------------------------------------------------------------------*/
+/**
+ * @defgroup sinfo_rec_distortion   Recipe to compute optical distortions
+ */
+/*---------------------------------------------------------------------------*/
+/**@{*/
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Build the list of available plugins, for this module. 
+  @param    list    the plugin list
+  @return   0 if everything is ok, -1 otherwise
+
+  Create the recipe instance and make it available to the application using the 
+  interface. This function is exported.
+ */
+/*---------------------------------------------------------------------------*/
+int
+cpl_plugin_get_info(cpl_pluginlist *list)
+{
+
+  cpl_recipe *recipe = cpl_calloc(1, sizeof *recipe);
+  cpl_plugin *plugin = &recipe->interface;
+  strcpy(sinfo_rec_distortion_description,sinfo_rec_distortion_description1);
+  strcat(sinfo_rec_distortion_description,sinfo_rec_distortion_description2);
+  strcat(sinfo_rec_distortion_description,sinfo_rec_distortion_description3);
+ 
+
+  cpl_plugin_init(plugin,
+          CPL_PLUGIN_API,
+          SINFONI_BINARY_VERSION,
+          CPL_PLUGIN_TYPE_RECIPE,
+          "sinfo_rec_distortion",
+          "Finds optical distortions and slitlets distances",
+          sinfo_rec_distortion_description,
+          "Andrea Modigliani",
+          "Andrea.Modigliani at eso.org",
+          sinfo_get_license(),
+          sinfo_rec_distortion_create,
+          sinfo_rec_distortion_exec,
+          sinfo_rec_distortion_destroy);
+
+  cpl_pluginlist_append(list, plugin);
+
+  return 0;
+
+}
+
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Setup the recipe options    
+  @param    plugin  the plugin
+  @return   0 if everything is ok
+
+  Defining the command-line/configuration parameters for the recipe.
+ */
+/*---------------------------------------------------------------------------*/
+static int sinfo_rec_distortion_create(cpl_plugin *plugin)
+{
+    cpl_recipe      * recipe ;
+
+    /* Check that the plugin is part of a valid recipe */
+    if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+        recipe = (cpl_recipe *)plugin ;
+    else return -1 ;
+    cpl_error_reset();
+    irplib_reset();
+
+    /* Create the parameters list in the cpl_recipe object */
+    recipe->parameters = cpl_parameterlist_new() ; 
+
+
+  /*
+   * Fill the parameter list.
+   */
+
+
+  /* Output file name */
+  sinfo_general_config_add(recipe->parameters);
+  sinfo_product_config_add(recipe->parameters);
+  sinfo_lamp_flats_config_add(recipe->parameters);
+  sinfo_bp_config_add(recipe->parameters);  
+  sinfo_bp_dist_config_add(recipe->parameters); 
+  sinfo_prepare_stacked_frames_config_add(recipe->parameters);
+  sinfo_distortion_config_add(recipe->parameters);
+  sinfo_north_south_test_config_add(recipe->parameters);
+  
+
+  return 0;
+
+}
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Execute the plugin instance given by the interface
+  @param    plugin  the plugin
+  @return   0 if everything is ok
+ */
+/*---------------------------------------------------------------------------*/
+static int sinfo_rec_distortion_exec(cpl_plugin *plugin)
+{
+    cpl_recipe  *   recipe ;
+    int status=0;
+
+    cpl_errorstate initial_errorstate = cpl_errorstate_get();
+
+    /* Get the recipe out of the plugin */
+    if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+        recipe = (cpl_recipe *)plugin ;
+    else return -1 ;
+    status=sinfo_rec_distortion(recipe->parameters, recipe->frames);
+
+    if (!cpl_errorstate_is_equal(initial_errorstate)) {                      
+        /* Dump the error history since recipe execution start.                
+           At this point the recipe cannot recover from the error */           
+        cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);              
+    } 
+  return status;
+
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Destroy what has been created by the 'create' function
+  @param    plugin  the plugin
+  @return   0 if everything is ok
+ */
+/*---------------------------------------------------------------------------*/
+static int sinfo_rec_distortion_destroy(cpl_plugin *plugin)
+{
+    cpl_recipe  *   recipe ;
+    
+    /* Get the recipe out of the plugin */
+    if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+        recipe = (cpl_recipe *)plugin ;
+    else return -1 ;
+
+  cpl_parameterlist_delete(recipe->parameters);
+
+  return 0;
+
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Interpret the command line options and execute the data processing
+  @param    parlist     the parameters list
+  @param    frameset   the frames list
+  @return   0 if everything is ok
+ */
+/*---------------------------------------------------------------------------*/
+/*
+ * The actual recipe actually start here.
+ */
+
+static int
+sinfo_rec_distortion(cpl_parameterlist *config, cpl_frameset *set)
+{
+ 
+  cpl_parameter *p=NULL;
+  cpl_frame* frame=NULL;
+  cpl_propertylist* plist=NULL;
+  cpl_image* ima=NULL;
+  cpl_frameset* raw_set=NULL;
+  cpl_frameset* set_off=NULL;
+  cpl_frameset* set_on=NULL;
+  cpl_frameset* set_fibre_ns=NULL;
+  cpl_frameset* set_flat_ns=NULL;
+  cpl_frameset* set_wave_ns=NULL;
+  char file_name[FILE_NAME_SZ];
+
+  fake* fk=sinfo_fake_new();
+  int pdensity=0;
+  int line_cor=0;
+
+  check_nomsg(p=cpl_parameterlist_find(config,"sinfoni.product.density"));
+  check_nomsg(pdensity=cpl_parameter_get_int(p));
+
+
+  sinfo_msg("Welcome to SINFONI Pipeline release %d.%d.%d",
+        SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
+  if(sinfo_dfs_set_groups(set)) {
+    sinfo_msg_error("Cannot indentify RAW and CALIB frames") ;
+    return -1;
+  }
+
+  check_nomsg(p=cpl_parameterlist_find(config, "sinfoni.general.lc_sw"));
+  check_nomsg(line_cor=cpl_parameter_get_bool(p));
+  if(line_cor==1) {
+     check_nomsg(sinfo_ima_line_cor(config,set));
+  }
+
+  cknull_nomsg(set_fibre_ns=sinfo_frameset_extract(set,RAW_FIBRE_NS));
+  cknull_nomsg(set_flat_ns=sinfo_frameset_extract(set,RAW_FLAT_NS));
+  cknull_nomsg(set_wave_ns=sinfo_frameset_extract(set,RAW_WAVE_NS));
+  check_nomsg(p=cpl_parameterlist_find(config,"sinfoni.bp.method"));
+  check_nomsg(cpl_parameter_set_string(p,"Normal"));   
+  check_nomsg(raw_set=cpl_frameset_duplicate(set));
+    
+  sinfo_msg("-----------------------------");
+  sinfo_msg("  DETERMINE MASTER_LAMP_NS ");
+  sinfo_msg("-----------------------------");
+
+  sinfo_msg("REDUCE LAMPFLAT") ;    
+  ck0(sinfo_new_lamp_flats(cpl_func,config, set,set_flat_ns ),
+      "reducing lampflats") ;
+  sinfo_msg("SUCCES: DETERMINATION MASTER_LAMP_NS") ; 
+
+  sinfo_msg("-----------------------------");
+  sinfo_msg("  DETERMINE BP_MAP_DI        ");
+  sinfo_msg("-----------------------------");
+  
+  check_nomsg(p=cpl_parameterlist_find(config,"sinfoni.bp.method"));
+  check_nomsg(cpl_parameter_set_string(p,"Normal"));   
+       
+  ck0(sinfo_new_bp_search_normal(cpl_func,config,set,set_flat_ns,
+				 PRO_BP_MAP_DI),
+      "determining %s",PRO_BP_MAP_DI);
+  sinfo_msg("SUCCESS DETERMINATION %s",PRO_BP_MAP_DI);
+  /* 
+       ---------------------------------------------------------
+        pre iteration: get a collassed frame 
+       ---------------------------------------------------------
+   */
+
+   check_nomsg(set_off=cpl_frameset_duplicate(raw_set));
+   ck0_nomsg(new_pre_process(set_off, 0.0, 0.2,"out_fibre_off.fits"));
+
+  
+   /* add the off artificial frame to the frameset */
+   if(NULL != cpl_frameset_find(set_off,RAW_FIBRE_NS)) {
+       frame = cpl_frameset_find(set_off,RAW_FIBRE_NS);
+       cpl_frameset_erase(set,RAW_FIBRE_NS);
+       cpl_frameset_insert(set,cpl_frame_duplicate(frame));
+   } else {
+       sinfo_msg_error("Frame %s not found!", RAW_FIBRE_NS);
+       goto cleanup;
+   }
+ 
+ 
+   /* 
+       ---------------------------------------------------------
+        1st iteration: get off frame 
+       ---------------------------------------------------------
+    */
+
+   sinfo_msg("STACK FIBRE,NS TO GET FAKE OFF\n") ; 
+   strcpy(fk->pro_class,RAW_FIBRE_NS);
+   fk->frm_switch=1;
+   fk->mask_index=0;
+   fk->ind_index=0;
+   fk->flat_index=0;
+   fk->wfix_index=0;
+   fk->low_rej=0.0;
+   fk->hig_rej=0.2;
+
+ 
+   ck0(sinfo_new_prepare_stacked_frames(cpl_func,config, set, set_fibre_ns,
+                                        PRO_FIBRE_NS_STACKED_OFF,0,fk),
+       "Error stacking frame %s",PRO_FIBRE_NS_STACKED_OFF);
+
+   strcpy(file_name,"out_fibre_off.fits");
+   check_nomsg(ima=cpl_image_load(file_name,CPL_TYPE_FLOAT,0,0));
+   sinfo_free_frameset(&set_off);
+
+   cknull(plist = cpl_propertylist_load(file_name, 0),
+           "getting header from reference ima frame %s",file_name);
+
+     if (sinfo_propertylist_has(plist, KEY_NAME_LAMP_HALO)) {
+       cpl_propertylist_set_bool(plist, KEY_NAME_LAMP_HALO, LAMP_OFF);
+     } else {
+       cpl_propertylist_append_bool(plist, KEY_NAME_LAMP_HALO,LAMP_OFF);
+     }
+
+   sinfo_free_propertylist(&plist);
+   sinfo_free_image(&ima);
+   sinfo_msg("SUCCESS: STACKED FIBRE,NS TO GET FAKE OFF\n") ;      
+
+   /* 
+       ---------------------------------------------------------
+        2nd iteration: get on frame 
+       ---------------------------------------------------------
+    */
+
+   check_nomsg(set_on=cpl_frameset_duplicate(raw_set));
+
+   ck0_nomsg(new_pre_process(set_on, 0.0, 0.0,"out_fibre_on.fits"));
+
+   if(NULL != cpl_frameset_find(set_on,RAW_FIBRE_NS)) {
+     frame = cpl_frameset_find(set_on,RAW_FIBRE_NS);
+     cpl_frameset_erase(set,RAW_FIBRE_NS);
+     cpl_frameset_insert(set,cpl_frame_duplicate(frame));
+   } else {
+     sinfo_msg_error("Frame %s not found!", RAW_FIBRE_NS);
+     goto cleanup;
+   }
+
+
+   sinfo_msg("STACK FIBRE,NS TO GET FAKE ON\n") ; 
+
+   strcpy(fk->pro_class,RAW_FIBRE_NS);
+   fk->frm_switch=1;
+   fk->mask_index=0;
+   fk->ind_index=0;
+   fk->flat_index=0;
+   fk->wfix_index=0;
+   fk->low_rej=0.0;
+   fk->hig_rej=0.0;
+
+
+   ck0(sinfo_new_prepare_stacked_frames(cpl_func,config, set, set_fibre_ns,
+                                        PRO_FIBRE_NS_STACKED_ON,0,fk),
+                        "error stacking frame %s",PRO_FIBRE_NS_STACKED_ON);
+        sinfo_msg("SUCCESS DETERMINATION %s",PRO_FIBRE_NS_STACKED_ON) ; 
+
+   /* cpl_frameset_erase(set,RAW_FIBRE_NS); */
+   sinfo_free_frameset(&set_on);
+
+   /* here we have a problem with pipefile of following step product */
+   /* 
+       ---------------------------------------------------------
+                3rd iteration combines on and off fake frames
+       ---------------------------------------------------------
+   */
+
+   sinfo_msg("COMBINES FAKE ON AND OFF\n") ; 
+   strcpy(fk->pro_class,PRO_FIBRE_NS_STACKED);
+   fk->frm_switch=1;
+   fk->mask_index=0;
+   fk->ind_index=0;
+   fk->flat_index=1;
+   fk->wfix_index=0;
+   fk->low_rej=0.0;
+   fk->hig_rej=0.0;
+
+   ck0(sinfo_new_prepare_stacked_frames(cpl_func,config, set, set_fibre_ns,
+                                        PRO_FIBRE_NS_STACKED,0,fk),
+                          "Stacking frame %s",PRO_FIBRE_NS_STACKED);
+   sinfo_msg("SUCCESS DETERMINATION %s",PRO_FIBRE_NS_STACKED) ; 
+
+   /* cpl_frameset_erase(set,RAW_FIBRE_NS); */
+
+   /* 
+       ---------------------------------------------------------
+                STACK WAVECAL
+       ---------------------------------------------------------
+   */
+ 
+   sinfo_msg("STACK on WAVE frame\n") ;
+   strcpy(fk->pro_class,RAW_WAVE_NS);
+   fk->frm_switch=1;
+   fk->mask_index=0;
+   fk->ind_index=0;
+   fk->flat_index=1;
+   fk->wfix_index=0;
+   fk->low_rej=0.1;
+   fk->hig_rej=0.1;
+   
+   sinfo_msg("STACK on WAVE frame\n") ; 
+   ck0(sinfo_new_prepare_stacked_frames(cpl_func,config, set, set_wave_ns,
+                                        PRO_WAVE_LAMP_STACKED,0,fk),
+                          "spacking frame %s",PRO_WAVE_LAMP_STACKED);
+   sinfo_msg("SUCCESS DETERMINATION %s",PRO_WAVE_LAMP_STACKED) ; 
+
+   if(pdensity < 2) {
+     cpl_frameset_erase(set,PRO_FIBRE_NS_STACKED_OFF);
+     cpl_frameset_erase(set,PRO_FIBRE_NS_STACKED_ON);
+     cpl_frameset_erase(set,PRO_MASTER_FLAT_LAMP);
+   }
+   /* 
+       ---------------------------------------------------------
+                DISTORTIONS 
+       ---------------------------------------------------------
+   */
+
+   sinfo_msg("COMPUTE DISTORTIONS\n") ; 
+   ck0(sinfo_new_find_distortions(cpl_func,config, set,set_fibre_ns),
+       "computing distortions");
+
+
+   if(NULL != cpl_frameset_find(set,PRO_FIBRE_NS_STACKED)) {
+     frame = cpl_frameset_find(set,PRO_FIBRE_NS_STACKED);
+     strcpy(file_name,cpl_frame_get_filename(frame));
+   } else {
+     sinfo_msg_error("Frame %s not found!", PRO_FIBRE_NS_STACKED);
+     goto cleanup;
+   }
+   check_nomsg(ima=cpl_image_load(file_name,CPL_TYPE_FLOAT,0,0));
+
+   check(plist = cpl_propertylist_load(file_name, 0),
+     "getting header from reference ima frame %s",file_name);
+
+
+     if (cpl_propertylist_has(plist, KEY_NAME_LAMP_HALO)) {
+       cpl_propertylist_set_bool(plist, KEY_NAME_LAMP_HALO, LAMP_ON);
+     } else {
+       cpl_propertylist_append_bool(plist, KEY_NAME_LAMP_HALO,LAMP_ON);
+     }
+
+
+   /* Save the file */
+   /*
+   if (cpl_image_save(ima, file_name, CPL_BPP_IEEE_FLOAT, 
+                      plist,CPL_IO_DEFAULT)!=CPL_ERROR_NONE) {
+       sinfo_msg_error("Cannot save the product %s",file_name);
+       goto cleanup;
+
+   }
+   */
+     
+   sinfo_free_image(&ima);
+   sinfo_free_propertylist(&plist);
+   sinfo_msg("SUCCESS: COMPUTED DISTORTIONS\n") ; 
+
+   /* 
+       ---------------------------------------------------------
+       4th iteration: distort fake frame
+       ---------------------------------------------------------
+   */
+
+
+   
+   sinfo_msg("DISTORT FAKE FRAME\n") ; 
+
+   strcpy(fk->pro_class,PRO_FIBRE_NS_STACKED_DIST);
+   fk->frm_switch=1;
+   fk->mask_index=1;
+   fk->ind_index=1;
+   fk->flat_index=0;
+   fk->wfix_index=1;
+   fk->low_rej=0.0;
+   fk->hig_rej=0.0;
+
+   ck0(sinfo_new_prepare_stacked_frames(cpl_func,config, set, set_fibre_ns,
+                                        PRO_FIBRE_NS_STACKED_DIST,0,fk),
+                        "Stacking frame %s",PRO_FIBRE_NS_STACKED_DIST);
+
+   sinfo_msg("SUCCESS: DISTORTED FAKE FRAME\n") ;
+
+ 
+ 
+   if(NULL != cpl_frameset_find(set,PRO_FIBRE_NS_STACKED_DIST)) {
+     frame = cpl_frameset_find(set,PRO_FIBRE_NS_STACKED_DIST);
+     strcpy(file_name,cpl_frame_get_filename(frame));
+   } else {
+     sinfo_msg_error("Frame %s not found!", PRO_FIBRE_NS_STACKED_DIST);
+     goto cleanup;
+   }
+   check_nomsg(ima=cpl_image_load(file_name,CPL_TYPE_FLOAT,0,0));
+   check(plist = cpl_propertylist_load(file_name, 0),
+     "getting header from reference ima frame %s",file_name);
+
+
+     if (cpl_propertylist_has(plist, KEY_NAME_LAMP_HALO)) {
+       cpl_propertylist_set_bool(plist, KEY_NAME_LAMP_HALO, LAMP_ON);
+     } else {
+       cpl_propertylist_append_bool(plist, KEY_NAME_LAMP_HALO,LAMP_ON);
+     }
+
+   /* Save the file */
+   /*
+      if (cpl_image_save(ima, file_name, CPL_BPP_IEEE_FLOAT, 
+                         plist,CPL_IO_DEFAULT)!=CPL_ERROR_NONE) {
+       sinfo_msg_error("Cannot save the product %s",file_name);
+       goto cleanup;
+      }
+   */
+   sinfo_free_propertylist(&plist);
+   sinfo_free_image(&ima);
+
+   /* 
+       ---------------------------------------------------------
+                               NST 
+       ---------------------------------------------------------
+   */
+ 
+   if(pdensity < 2) {
+     cpl_frameset_erase(set,PRO_BP_MAP_DI);
+     cpl_frameset_erase(set,PRO_FIBRE_NS_STACKED);
+     cpl_frameset_erase(set,PRO_WAVE_LAMP_STACKED);
+   }
+
+  
+   sinfo_msg("RUN NORD SOUTH TEST\n") ; 
+   ck0(sinfo_new_nst(cpl_func,config, set,set_fibre_ns),
+       "Running north south test");
+
+
+   if(pdensity < 2) {
+     cpl_frameset_erase(set,PRO_FIBRE_NS_STACKED_DIST);
+   }
+
+   sinfo_msg("SUCCESS: RUNNED NORD SUD TEST\n") ; 
+   sinfo_msg("SUCCESS: RECIPE\n") ; 
+
+   sinfo_free_frameset(&raw_set);
+   sinfo_fake_delete(&fk);
+
+
+ cleanup:
+
+   sinfo_free_frameset(&set_on);
+   sinfo_free_frameset(&set_fibre_ns);
+   sinfo_free_frameset(&set_wave_ns);
+   sinfo_free_frameset(&set_flat_ns);
+   sinfo_free_image(&ima);
+   sinfo_free_propertylist(&plist) ;
+   sinfo_free_frameset(&set_off);
+   sinfo_free_frameset(&raw_set);
+   sinfo_free_frameset(&raw_set);
+   sinfo_fake_delete(&fk);
+
+  if (cpl_error_get_code() != CPL_ERROR_NONE) {
+    return -1;
+  } else {
+    return 0;
+  }
+
+
+}
+
+
+
+static int 
+new_pre_process(cpl_frameset* set, 
+const float lo_rej, const float hi_rej, const char* name_o)
+{
+
+  int nf=0;
+  int ng=10;
+  int ns=0;
+  int nr=0;
+  int nt=0;
+
+  int i=0;
+  int j=0;
+  int k=0;
+  int lo_cut=0;
+  int hi_cut=0;
+
+
+  cpl_frame* frame=NULL;
+  cpl_frame* pframe=NULL;
+  cpl_frameset* sof=NULL;
+  cpl_frameset* fibre_raw_set=NULL;
+  char* file_name=NULL;
+
+  cpl_propertylist* plist=NULL;
+  cpl_imagelist* imset_tmp=NULL;
+  cpl_imagelist* imset_tot=NULL;
+  cpl_image** avg_img_list=NULL;
+
+  cpl_image* img=NULL;
+  cpl_image* img_tmp=NULL;
+  cpl_image* img_dup=NULL;
+
+  cpl_image** img_list=NULL;
+
+
+  sof = cpl_frameset_duplicate(set);
+  fibre_raw_set = cpl_frameset_new();
+
+  sinfo_contains_frames_kind(sof,fibre_raw_set,RAW_FIBRE_NS);
+
+  nf = cpl_frameset_get_size(fibre_raw_set);
+  if(nf < 1) {
+    sinfo_msg_warning("No input frames in data set");
+    sinfo_free_frameset(&sof);
+    sinfo_free_frameset(&fibre_raw_set);
+    return -1;
+  }
+  frame = cpl_frameset_get_frame(fibre_raw_set,0);
+  file_name=(char*) cpl_frame_get_filename(frame);
+
+
+  if ((plist = cpl_propertylist_load(file_name, 0)) == NULL) {
+    sinfo_msg_error("getting header from  ima frame %s",file_name);
+    return -1 ;
+  }
+
+
+  if( nf > ng) {
+
+    sinfo_msg("Total raw frames nf=%d > max frm per group ng=%d",nf,ng);
+    ns = (nf+1)/ng;
+    nr = nf-ns*ng;
+    imset_tot=cpl_imagelist_new();
+    avg_img_list=cpl_malloc((ns+1) * sizeof(cpl_image *));
+
+
+    for (i=0;i<ns;i++) {
+      sinfo_msg("iteration i=%d\n",i);
+      imset_tmp=cpl_imagelist_new();
+      img_list=cpl_malloc(ng * sizeof(cpl_image *));
+
+
+      for (j=0;j<ng;j++) {
+	k=i*ng+j;
+        frame = cpl_frameset_get_frame(fibre_raw_set,k);
+        file_name=(char*)cpl_frame_get_filename(frame);
+        img_tmp=cpl_image_load(file_name,CPL_TYPE_FLOAT,0,0);
+        img_dup=cpl_image_duplicate(img_tmp); 
+        cpl_imagelist_set(imset_tmp,img_dup,j);
+        cpl_image_delete(img_tmp);
+      }
+
+         
+      nt=cpl_imagelist_get_size(imset_tmp);
+      lo_cut=(floor)(lo_rej*nt+0.5);
+      hi_cut=(floor)(hi_rej*nt+0.5);
+      avg_img_list[i]=cpl_imagelist_collapse_minmax_create(imset_tmp,
+                                                           lo_cut,hi_cut);
+      cpl_imagelist_set(imset_tot,avg_img_list[i],i);
+      cpl_imagelist_delete(imset_tmp);
+      cpl_free(img_list);
+
+    }
+ 
+    if(ns*ng<nf) {
+      imset_tmp=cpl_imagelist_new();
+      img_list=cpl_malloc((nf-ns*ng) * sizeof(cpl_image *));
+      for(i=0;i<nr;i++) {
+	k=i+ns*ng;
+        frame = cpl_frameset_get_frame(fibre_raw_set,k);
+        file_name  = (char*) cpl_frame_get_filename(frame);
+
+        img_list[i]=cpl_image_load(file_name,CPL_TYPE_FLOAT,0,0);
+        cpl_imagelist_set(imset_tmp,img_list[i],i);
+      }
+      nt=cpl_imagelist_get_size(imset_tmp);
+      lo_cut=(floor)(lo_rej*nt+0.5);
+      hi_cut=(floor)(hi_rej*nt+0.5);
+
+      avg_img_list[ns]=cpl_imagelist_collapse_minmax_create(imset_tmp,
+                                                            lo_cut,hi_cut);
+      cpl_imagelist_set(imset_tot,avg_img_list[ns],ns);
+
+      cpl_free(img);
+      cpl_imagelist_delete(imset_tmp);
+      cpl_free(img_list);
+    }
+ 
+  } else {
+
+    sinfo_msg("Total raw frames nf=%d < max frm per group ng=%d",nf,ng);
+    imset_tot=cpl_imagelist_new();
+    img_list=cpl_malloc(nf * sizeof(cpl_image *));
+    for (i=0;i<nf;i++) {
+      frame = cpl_frameset_get_frame(fibre_raw_set,i);
+      file_name  = (char*) cpl_frame_get_filename(frame);
+      img_list[i]=cpl_image_load(file_name,CPL_TYPE_FLOAT,0,0);
+      cpl_imagelist_set(imset_tot,img_list[i],i);
+    }
+    cpl_free(img_list);
+  }
+  cpl_free(avg_img_list);
+
+  cpl_frameset_delete(fibre_raw_set);
+  nt=cpl_imagelist_get_size(imset_tot);
+  lo_cut=(floor)(lo_rej*nt+0.5);
+  hi_cut=(floor)(hi_rej*nt+0.5);
+
+  if( (img = cpl_imagelist_collapse_minmax_create(imset_tot,
+                                                  lo_cut,hi_cut)) == NULL) {
+    sinfo_msg_error("Error code");
+    sinfo_msg_error((char* ) cpl_error_get_message());
+    cpl_imagelist_delete(imset_tot);
+    cpl_frameset_delete(sof);
+    cpl_propertylist_delete(plist) ;
+    return -1;
+  }
+
+  if (cpl_image_save(img,name_o, CPL_BPP_IEEE_FLOAT,
+		     plist,CPL_IO_DEFAULT)!=CPL_ERROR_NONE) {
+    sinfo_msg_error("Cannot save the product %s",name_o);
+    cpl_imagelist_delete(imset_tot);
+    cpl_frameset_delete(sof);
+    cpl_propertylist_delete(plist) ;
+    return -1 ;
+  }
+  cpl_imagelist_delete(imset_tot);
+  cpl_frameset_erase(set,RAW_FIBRE_NS);
+         
+  /* Create product frame */
+  pframe = cpl_frame_new();
+  cpl_frame_set_filename(pframe, name_o) ;
+  cpl_frame_set_tag(pframe, "FIBRE_NS") ;
+  cpl_frame_set_type(pframe, CPL_FRAME_TYPE_IMAGE) ;
+  cpl_frame_set_group(pframe, CPL_FRAME_GROUP_RAW) ;
+  cpl_frame_set_level(pframe, CPL_FRAME_LEVEL_FINAL) ;
+  if (cpl_error_get_code()) {
+    sinfo_msg_error("Error while initialising the product frame") ;
+    cpl_propertylist_delete(plist) ;
+    cpl_frame_delete(pframe) ;
+    cpl_image_delete(img) ;
+    return -1 ;
+  }
+    
+
+  /* Save the file */
+  if (cpl_image_save(img, name_o, CPL_BPP_IEEE_FLOAT, plist,
+		     CPL_IO_DEFAULT) != CPL_ERROR_NONE) {
+    sinfo_msg_error("Could not save product");
+    cpl_propertylist_delete(plist) ;
+    cpl_frame_delete(pframe) ;
+    cpl_image_delete(img) ;
+    return -1 ;
+  }
+  cpl_propertylist_delete(plist) ;
+  cpl_image_delete(img) ;
+
+  /* Log the saved file in the input frameset */
+  cpl_frameset_insert(set, pframe) ;
+  cpl_frameset_delete(sof);
+
+  return 0;
+}
+/**@}*/
diff --git a/recipes/sinfo_rec_jitter.c b/recipes/sinfo_rec_jitter.c
new file mode 100644
index 0000000..e6b73d6
--- /dev/null
+++ b/recipes/sinfo_rec_jitter.c
@@ -0,0 +1,386 @@
+/* $Id: sinfo_rec_jitter.c,v 1.33 2009/10/20 14:32:56 kmirny Exp $
+ *
+ * This file is part of the SINFONI Pipeline
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*
+ * $Author: kmirny $
+ * $Date: 2009/10/20 14:32:56 $
+ * $Revision: 1.33 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+ /****************************************************************
+  *           Object Data reduction                              *
+  ****************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>          /* allows the program compilation */
+#endif
+
+/*-----------------------------------------------------------------------------
+                                Includes
+ ----------------------------------------------------------------------------*/
+
+/* std */
+#include <strings.h>
+#include <string.h>
+#include <stdio.h>
+#include <math.h>
+#include <libgen.h>
+
+
+/* cpl */
+#include <cpl.h>
+
+/* irplib */
+#include <irplib_utils.h>
+
+/* sinfoni */
+#include <sinfo_utilities.h>
+#include <sinfo_pro_types.h>
+#include <sinfo_general_config.h>
+#include <sinfo_product_config.h>
+#include <sinfo_prepare_stacked_frames_config.h>
+#include <sinfo_objnod_config.h>
+#include <sinfo_skycor_config.h>
+#include <sinfo_psf_config.h>
+#include <sinfo_standard_star_config.h>
+#include <sinfo_new_prepare_stacked_frames.h>
+#include <sinfo_new_cubes_coadd.h>
+#include <sinfo_new_stdstar.h>
+#include <sinfo_new_psf.h>
+#include <sinfo_key_names.h>
+#include <sinfo_raw_types.h>
+#include <sinfo_functions.h>
+#include <sinfo_tpl_utils.h>
+#include <sinfo_tpl_dfs.h>
+#include <sinfo_hidden.h>
+#include <sinfo_globals.h>
+#include <sinfo_msg.h>
+#include <sinfo_rec_utils.h>
+#include <sinfo_error.h>
+#include <sinfo_utils_wrappers.h>
+
+/*-----------------------------------------------------------------------------
+                            Functions prototypes
+ ----------------------------------------------------------------------------*/
+
+static int sinfo_rec_jitter_create(cpl_plugin *) ;
+static int sinfo_rec_jitter_exec(cpl_plugin *) ;
+static int sinfo_rec_jitter_destroy(cpl_plugin *) ;
+static int sinfo_rec_jitter(cpl_parameterlist *config, cpl_frameset *set);
+/*-----------------------------------------------------------------------------
+                            Static variables
+ ----------------------------------------------------------------------------*/
+
+static char sinfo_rec_jitter_description1[] =
+"This recipe performs science data reduction.\n"
+"The input files are:\n"
+"science object and sky frames with tags OBJECT_NODDING and SKY_NODDING or\n"
+"Telluric standard star frames and sky frames with tags STD and SKY_STD or\n"
+"PSF standard star and sky frames with tags \n"
+"PSF_CALIBRATOR and SKY_PSF_CALIBRATOR\n"
+"and Master calibration frames:\n";
+
+
+static char sinfo_rec_jitter_description2[] =
+"A corresponding (band,preoptics) wavelength map image with tag WAVE_MAP\n"
+"A corresponding (band,preoptics) master flat field with tag MASTER_FLAT_LAMP\n"
+"A corresponding (band,preoptics) master bad pixel map with tag MASTER_BP_MAP\n"
+"A corresponding (band,preoptics) slitlets position frame with tag SLIT_POS\n"
+"A corresponding (band) distortion table with tag DISTORTION\n"
+"A corresponding (band) slitlet distance table with tag SLITLETS_DISTANCE\n";
+
+
+static char sinfo_rec_jitter_description3[] =
+"The output is an image resulting from the IMA1 op IMA2 where op indicates\n"
+"A reference table with the position of the first "
+"column with tag FIRST_COLUMN\n"
+"Relevant outputs are:\n"
+"combined cubes (PRO.CATG=x_OBS x=STD,OBJ,PSF)\n"
+"reconstructed cube (PRO.CATG=COADD_x_OBS x=STD,OBJ,PSF)\n"
+"An average along Z of the reconstructed cube \n"
+"(PRO.CATG=MED_x_OBS x=STD,OBJ,PSF)\n"
+"The bad pixel map associated to the cube \n"
+"(PRO.CATG=BP_MAP_COADD_x_OBS x=STD,OBJ,PSF)\n";
+
+
+static char sinfo_rec_jitter_description4[] =
+"Information on relevant parameters can be found with\n"
+"esorex --params sinfo_rec_jitter\n"
+"esorex --help sinfo_rec_jitter\n"
+"\n";
+
+static char sinfo_rec_jitter_description[1400];
+
+/*-----------------------------------------------------------------------------
+                                Functions code
+ ----------------------------------------------------------------------------*/
+/*---------------------------------------------------------------------------*/
+/**
+ * @defgroup sinfo_rec_jitter Recipe to reduce science, PSF, telluric standards
+ */
+/*---------------------------------------------------------------------------*/
+/**@{*/
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Build the list of available plugins, for this module.
+  @param    list    the plugin list
+  @return   0 if everything is ok, -1 otherwise
+
+  Create the recipe instance and make it available to the application using the
+  interface. This function is exported.
+ */
+/*---------------------------------------------------------------------------*/
+
+int
+cpl_plugin_get_info(cpl_pluginlist *list)
+{
+
+  cpl_recipe *recipe = cpl_calloc(1, sizeof *recipe);
+  cpl_plugin *plugin = &recipe->interface;
+
+  strcpy(sinfo_rec_jitter_description,sinfo_rec_jitter_description1);
+  strcat(sinfo_rec_jitter_description,sinfo_rec_jitter_description2);
+  strcat(sinfo_rec_jitter_description,sinfo_rec_jitter_description3);
+  strcat(sinfo_rec_jitter_description,sinfo_rec_jitter_description4);
+
+  cpl_plugin_init(plugin,
+          CPL_PLUGIN_API,
+          SINFONI_BINARY_VERSION,
+          CPL_PLUGIN_TYPE_RECIPE,
+          "sinfo_rec_jitter",
+          "Object or STD star or PSF star data reduction",
+           sinfo_rec_jitter_description,
+          "Andrea Modigliani",
+          "Andrea.Mdigliani at eso.org",
+          sinfo_get_license(),
+          sinfo_rec_jitter_create,
+          sinfo_rec_jitter_exec,
+          sinfo_rec_jitter_destroy);
+
+  cpl_pluginlist_append(list, plugin);
+
+  return 0;
+
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Setup the recipe options
+  @param    plugin  the plugin
+  @return   0 if everything is ok
+
+  Defining the command-line/configuration parameters for the recipe.
+ */
+/*---------------------------------------------------------------------------*/
+static int sinfo_rec_jitter_create(cpl_plugin *plugin)
+{
+    cpl_recipe      * recipe ;
+
+
+    /* Check that the plugin is part of a valid recipe */
+    if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
+        recipe = (cpl_recipe *)plugin ;
+    else return -1 ;
+  cpl_error_reset();
+  irplib_reset();
+
+    /* Create the parameters list in the cpl_recipe object */
+    recipe->parameters = cpl_parameterlist_new() ;
+
+
+  /*
+   * Fill the parameter list.
+   */
+
+  sinfo_general_config_add(recipe->parameters);
+  sinfo_product_config_add(recipe->parameters);
+  sinfo_prepare_stacked_frames_config_add(recipe->parameters);
+  sinfo_objnod_config_add(recipe->parameters);
+  sinfo_skycor_config_add(recipe->parameters);
+  sinfo_standard_star_config_add(recipe->parameters);
+  sinfo_psf_config_add(recipe->parameters);
+
+
+
+  return 0;
+
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Execute the plugin instance given by the interface
+  @param    plugin  the plugin
+  @return   0 if everything is ok
+ */
+/*---------------------------------------------------------------------------*/
+static int sinfo_rec_jitter_exec(cpl_plugin *plugin)
+{
+
+  cpl_recipe *recipe = (cpl_recipe *) plugin;
+
+    cpl_errorstate initial_errorstate = cpl_errorstate_get();
+
+  /* Get the recipe out of the plugin */
+  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
+      recipe = (cpl_recipe *)plugin ;
+  else return -1 ;
+
+    if (!cpl_errorstate_is_equal(initial_errorstate)) {
+        /* Dump the error history since recipe execution start.
+           At this point the recipe cannot recover from the error */
+        cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
+    }
+  return sinfo_rec_jitter(recipe->parameters, recipe->frames);
+
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Destroy what has been created by the 'create' function
+  @param    plugin  the plugin
+  @return   0 if everything is ok
+ */
+/*---------------------------------------------------------------------------*/
+static int sinfo_rec_jitter_destroy(cpl_plugin *plugin)
+{
+
+   cpl_recipe  *   recipe ;
+
+    /* Get the recipe out of the plugin */
+    if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
+        recipe = (cpl_recipe *)plugin ;
+    else return -1 ;
+
+  cpl_parameterlist_delete(recipe->parameters);
+
+  return 0;
+
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Interpret the command line options and execute the data processing
+  @param    parlist     the parameters list
+  @param    frameset   the frames list
+  @return   0 if everything is ok
+ */
+/*---------------------------------------------------------------------------*/
+
+/*
+ * The actual recipe actually start here.
+ */
+
+static int sinfo_rec_jitter(cpl_parameterlist *config, cpl_frameset *set)
+{
+  const char* pro_ctg_cube;
+  cpl_parameter* p=NULL;
+  int psf_sw=0;
+  int std_sw=0;
+  cpl_frameset* ref_set=NULL;
+  int line_cor=0;
+
+  sinfo_msg("Welcome to SINFONI Pipeline release %d.%d.%d",
+        SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
+
+  if(sinfo_dfs_set_groups(set)) {
+    sinfo_msg_error("Cannot indentify RAW and CALIB frames") ;
+    return -1;
+  }
+
+  check_nomsg(p=cpl_parameterlist_find(config, "sinfoni.general.lc_sw"));
+  check_nomsg(line_cor=cpl_parameter_get_bool(p));
+  if(line_cor==1) {
+     check_nomsg(sinfo_ima_line_cor(config,set));
+  }
+
+  check_nomsg(ref_set=cpl_frameset_duplicate(set));
+  /* ===============================================================
+     Defines several framesets each with a pair obj-sky,
+     stack each pair, put the results in set
+     =============================================================== */
+  ck0(sinfo_cub_stk_frames(config,&set,cpl_func,&pro_ctg_cube),
+      "Cannot stack RAW frames") ;
+
+  /* ===============================================================
+     SCI OBJNOD
+     =============================================================== */
+     sinfo_msg("------------------------------") ;
+     sinfo_msg("COADDING CUBES");
+     sinfo_msg("------------------------------") ;
+     ck0(sinfo_new_cubes_coadd(cpl_func,config, set, pro_ctg_cube),
+     "COADDING CUBES") ;
+
+     sinfo_msg("------------------------------") ;
+     sinfo_msg("COADDED CUBES");
+     sinfo_msg("------------------------------") ;
+
+  /* ===============================================================
+     PSF
+     =============================================================== */
+
+  if((strcmp(pro_ctg_cube,PRO_COADD_PSF) == 0) ||
+     (strcmp(pro_ctg_cube,PRO_COADD_STD) == 0) ||
+     (strcmp(pro_ctg_cube,PRO_COADD_PUPIL) == 0) ) {
+
+
+    p = cpl_parameterlist_find(config, "sinfoni.psf.switch");
+    psf_sw = cpl_parameter_get_bool(p);
+    sinfo_msg("switch=%d",psf_sw);
+    if(psf_sw) {
+      sinfo_msg("------------------------------") ;
+      sinfo_msg("REDUCE PSF STD STAR FRAMES");
+      sinfo_msg("------------------------------") ;
+      if ( -1 == sinfo_new_psf(cpl_func,config,set,set) ) {
+	sinfo_msg_error("REDUCING PSF STD STAR FRAMES") ;
+        cpl_error_reset();
+      } else {
+	sinfo_msg("SUCCESS REDUCE PSF STD STAR FRAMES") ;
+      }
+    }
+
+    p = cpl_parameterlist_find(config, "sinfoni.std_star.switch");
+    std_sw = cpl_parameter_get_bool(p);
+    sinfo_msg("switch=%d",std_sw);
+    if(std_sw) {
+      sinfo_msg("------------------------------") ;
+      sinfo_msg("STD STAR DATA REDUCTION");
+      sinfo_msg("------------------------------") ;
+      if ( -1 == sinfo_new_stdstar(cpl_func,config, set,set ) ) {
+	sinfo_msg_error("REDUCING STD STAR DATA") ;
+        cpl_error_reset();
+      } else {
+	sinfo_msg("STD STAR DATA REDUCTION SUCCESS") ;
+      }
+    }
+  }
+
+ cleanup:
+  sinfo_free_frameset(&ref_set);
+  if (cpl_error_get_code() != CPL_ERROR_NONE) {
+    sinfo_check_rec_status(0);
+    return -1;
+  } else {
+    return 0;
+  }
+
+
+}
+
+/**@}*/
diff --git a/recipes/sinfo_rec_mdark.c b/recipes/sinfo_rec_mdark.c
new file mode 100644
index 0000000..985ebac
--- /dev/null
+++ b/recipes/sinfo_rec_mdark.c
@@ -0,0 +1,444 @@
+/* $Id: sinfo_rec_mdark.c,v 1.22 2008/02/28 10:36:10 amodigli Exp $
+ *
+ * This file is part of the SINFONI Pipeline
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2008/02/28 10:36:10 $
+ * $Revision: 1.22 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+ /****************************************************************
+  *          Dark Frames Data Reduction                          *
+  ****************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>          /* allows the program compilation */
+#endif
+
+/*-----------------------------------------------------------------------------
+                                Includes
+ ----------------------------------------------------------------------------*/
+
+/* std */
+#include <strings.h>
+#include <string.h>
+#include <stdio.h>
+
+/* cpl */
+#include <cpl.h>    
+
+/* irplib */
+#include <irplib_utils.h>
+
+/* sinfoni */
+#include <sinfo_bp_noise.h> /* */
+#include <sinfo_new_dark.h>     /*  */ 
+#include <sinfo_utilities.h>
+#include <sinfo_general_config.h>
+#include <sinfo_bp_config.h>
+#include <sinfo_bp_noise_config.h>
+#include <sinfo_dark_config.h> 
+#include <sinfo_tpl_utils.h>
+#include <sinfo_tpl_dfs.h>
+#include <sinfo_pfits.h>
+#include <sinfo_functions.h>
+#include <sinfo_pfits.h>
+#include <sinfo_msg.h>
+#include <sinfo_error.h>
+#include <sinfo_utils_wrappers.h>
+/*-----------------------------------------------------------------------------
+                            Functions prototypes
+ ----------------------------------------------------------------------------*/
+
+static int sinfo_rec_mdark_create(cpl_plugin *plugin);
+static int sinfo_rec_mdark_exec(cpl_plugin *plugin);
+static int sinfo_rec_mdark_destroy(cpl_plugin *plugin);
+static int sinfo_rec_mdark(cpl_parameterlist *config, cpl_frameset *set);
+static int count_diff_ndit(cpl_frameset *set, cpl_vector** dit_val);
+
+/*-----------------------------------------------------------------------------
+                            Static variables
+ ----------------------------------------------------------------------------*/
+
+static char sinfo_rec_mdark_description[] =
+"This recipe perform raw sinfo_dark data reduction.\n"
+"The input files are raw sinfo_dark images\n"
+"Their associated tags should be DARK.\n"
+"The output are a master sinfo_dark (PRO.CATG=MASTER_DARK) and\n"
+"a hot pixels bad pixel map (PRO.CATG=BP_MAP_HP)\n"
+"Information on relevant parameters may be found with\n"
+"esorex --params sinfo_rec_mdark\n"
+"esorex --help sinfo_rec_mdark\n"
+"\n";
+
+
+/*-----------------------------------------------------------------------------
+                                Functions code
+ ----------------------------------------------------------------------------*/
+/*---------------------------------------------------------------------------*/
+/**
+ * @defgroup sinfo_rec_mdark   Recipe to compute master dark
+ */
+/*---------------------------------------------------------------------------*/
+/**@{*/
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Build the list of available plugins, for this module. 
+  @param    list    the plugin list
+  @return   0 if everything is ok, -1 otherwise
+
+  Create the recipe instance and make it available to the application using 
+  the interface. This function is exported.
+ */
+/*---------------------------------------------------------------------------*/
+int
+cpl_plugin_get_info(cpl_pluginlist *list)
+{
+
+  cpl_recipe *recipe = cpl_calloc(1, sizeof *recipe);
+  cpl_plugin *plugin = &recipe->interface;
+
+
+  cpl_plugin_init(plugin,
+          CPL_PLUGIN_API,
+          SINFONI_BINARY_VERSION,
+          CPL_PLUGIN_TYPE_RECIPE,
+          "sinfo_rec_mdark",
+          "Master dark and hot pixels mask generation.",
+          sinfo_rec_mdark_description,
+          "Andrea Modigliani",
+          "Andrea.Modigliani at eso.org",
+          sinfo_get_license(),
+          sinfo_rec_mdark_create,
+          sinfo_rec_mdark_exec,
+          sinfo_rec_mdark_destroy);
+
+  cpl_pluginlist_append(list, plugin);
+
+  return 0;
+
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Setup the recipe options    
+  @param    plugin  the plugin
+  @return   0 if everything is ok
+
+  Defining the command-line/configuration parameters for the recipe.
+ */
+/*---------------------------------------------------------------------------*/
+static int sinfo_rec_mdark_create(cpl_plugin *plugin)
+{
+    cpl_recipe      * recipe ;
+
+    /* Check that the plugin is part of a valid recipe */
+    if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+        recipe = (cpl_recipe *)plugin ;
+    else return -1 ;
+    cpl_error_reset();
+    irplib_reset();
+
+    /* Create the parameters list in the cpl_recipe object */
+    recipe->parameters = cpl_parameterlist_new() ; 
+
+
+  /*
+   * Fill the parameter list.
+   */
+  sinfo_general_config_add(recipe->parameters);
+  sinfo_bp_noise_config_add(recipe->parameters);
+  sinfo_dark_config_add(recipe->parameters);
+  return 0;
+
+}
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Execute the plugin instance given by the interface
+  @param    plugin  the plugin
+  @return   0 if everything is ok
+ */
+/*---------------------------------------------------------------------------*/
+static int sinfo_rec_mdark_exec(cpl_plugin *plugin)
+{
+    cpl_recipe  *   recipe ;
+
+    cpl_errorstate initial_errorstate = cpl_errorstate_get();
+
+    /* Get the recipe out of the plugin */
+    if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+        recipe = (cpl_recipe *)plugin ;
+    else return -1 ;
+
+    if (!cpl_errorstate_is_equal(initial_errorstate)) {                      
+        /* Dump the error history since recipe execution start.                
+           At this point the recipe cannot recover from the error */           
+        cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);              
+    } 
+
+    return sinfo_rec_mdark(recipe->parameters, recipe->frames);
+
+}
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Destroy what has been created by the 'create' function
+  @param    plugin  the plugin
+  @return   0 if everything is ok
+ */
+/*---------------------------------------------------------------------------*/
+static int sinfo_rec_mdark_destroy(cpl_plugin *plugin)
+{
+    cpl_recipe  *   recipe ;
+    
+    /* Get the recipe out of the plugin */
+    if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+        recipe = (cpl_recipe *)plugin ;
+    else return -1 ;
+
+    cpl_parameterlist_delete(recipe->parameters) ; 
+    return 0 ;
+
+}
+
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Interpret the command line options and execute the data processing
+  @param    parlist     the parameters list
+  @param    frameset   the frames list
+  @return   0 if everything is ok
+ */
+/*---------------------------------------------------------------------------*/
+/*
+ * The actual recipe actually start here.
+ */
+
+static int
+sinfo_rec_mdark(cpl_parameterlist *config, cpl_frameset *set)
+{
+ 
+  cpl_parameter* p=NULL;
+  int nset=0;
+  cpl_frameset  * wrk_set=NULL;
+  cpl_frameset  * cdb_set=NULL;
+  cpl_frameset  * tot_set=NULL;
+
+  cpl_frame* tmp_frm=NULL;
+  cpl_frame* dup_frm=NULL;
+  cpl_frame* cdb_frm=NULL;
+
+  char tmp_name[FILE_NAME_SZ];
+  char out_bpmap_name[FILE_NAME_SZ];
+  char out_dark_name[FILE_NAME_SZ];
+  double tmp_dit=0;
+  double ref_dit=0;
+
+  cpl_vector* dit_val=NULL;
+  cpl_propertylist* plist=NULL;
+
+  int i=0;
+  int j=0;
+  int line_cor=0;
+
+
+  int nraw=0;
+  int ncdb=0;
+  int nred=0;
+  int ntot=0;
+  sinfo_msg("Welcome to SINFONI Pipeline release %d.%d.%d",
+        SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
+  ck0(sinfo_dfs_set_groups(set),"Cannot indentify RAW and CALIB frames");
+
+  check_nomsg(p=cpl_parameterlist_find(config, "sinfoni.general.lc_sw"));
+  check_nomsg(line_cor=cpl_parameter_get_bool(p));
+  if(line_cor==1) {
+     check_nomsg(sinfo_ima_line_cor(config,set));
+  }
+
+
+  check_nomsg(cdb_set=cpl_frameset_new());
+  check_nomsg(tot_set=cpl_frameset_new());
+
+
+  sinfo_extract_mst_frames(set,cdb_set);
+  sinfo_bp_config_add(config);
+  nset=count_diff_ndit(set,&dit_val);
+
+  check_nomsg(nraw=cpl_frameset_get_size(set));
+  check_nomsg(ncdb=cpl_frameset_get_size(cdb_set));
+
+  for(i=0;i<nset;i++) {
+    check_nomsg(wrk_set=cpl_frameset_new());
+    check_nomsg(ref_dit=cpl_vector_get(dit_val,i));
+
+
+    for(j=0;j<nraw;j++) {
+      check_nomsg(tmp_frm=cpl_frameset_get_frame(set,j));
+      check_nomsg(strcpy(tmp_name,cpl_frame_get_filename(tmp_frm)));
+      plist=cpl_propertylist_load(tmp_name,0);
+      tmp_dit=sinfo_pfits_get_dit(plist);
+      sinfo_free_propertylist(&plist);
+
+      if(tmp_dit==ref_dit) {
+        check_nomsg(cpl_frameset_insert(wrk_set,cpl_frame_duplicate(tmp_frm)));
+      }
+    }
+
+    for(j=0;j<ncdb;j++) {
+      check_nomsg(cdb_frm=cpl_frameset_get_frame(cdb_set,j));
+      check_nomsg(cpl_frameset_insert(wrk_set,cpl_frame_duplicate(cdb_frm)));
+    }
+
+    /* reduce data */
+    ck0(sinfo_dfs_set_groups(wrk_set),"Cannot indentify RAW and CALIB frames");
+
+    /* Hidden parameters */
+    check_nomsg(p = cpl_parameterlist_find(config,"sinfoni.bp.method"));
+    check_nomsg(cpl_parameter_set_string(p,"Noise"));
+    ck0(sinfo_dfs_set_groups(set),"Cannot indentify RAW and CALIB frames") ;
+ 
+    if (nset>1) {
+      sprintf(out_bpmap_name,"%s%d%s","out_bp_noise",i,".fits");
+    } else {
+      strcpy(out_bpmap_name,"out_bp_noise.fits");
+    }
+
+    sinfo_msg("-----------------------------------------------");
+    sinfo_msg("BP_MAP_HP BAD PIXEL MAP DETERMINATION          ");
+    sinfo_msg("-----------------------------------------------");
+   
+    ck0(sinfo_new_bp_search_noise(cpl_func,config,wrk_set,out_bpmap_name),
+    "computing BP_MAP_HP") ;
+    sinfo_msg("BP_MAP_HP BAD PIXEL MAP DETERMINATION SUCCESS") ; 
+    
+    sinfo_msg("-----------------------------------------------");
+    sinfo_msg("MASTER DARK DETERMINATION                      ");
+    sinfo_msg("-----------------------------------------------");
+
+    if (nset>1) {
+      sprintf(out_dark_name,"%s%d%s","out_dark",i,".fits");
+    } else {
+      strcpy(out_dark_name,"out_dark.fits");
+    }
+
+    ck0(sinfo_new_dark(cpl_func,config, wrk_set, out_dark_name),
+     "Computing master dark") ;
+    sinfo_msg("MASTER DARK DETERMINATION SUCCESS") ;
+
+    nred=cpl_frameset_get_size(wrk_set);
+    for(j=0;j<nred;j++) {
+      check_nomsg(tmp_frm=cpl_frameset_get_frame(wrk_set,j));
+      check_nomsg(cpl_frameset_insert(tot_set,cpl_frame_duplicate(tmp_frm)));
+    }
+    sinfo_free_frameset(&wrk_set);
+
+  }
+
+  check_nomsg(ntot=cpl_frameset_get_size(tot_set));
+  for(j=0;j<ntot;j++) {
+    check_nomsg(tmp_frm=cpl_frameset_get_frame(tot_set,j));
+    check_nomsg(cpl_frameset_insert(set,cpl_frame_duplicate(tmp_frm)));
+  }
+
+  sinfo_free_frameset(&tot_set);
+  sinfo_free_my_vector(&dit_val);
+  sinfo_free_frameset(&cdb_set);
+
+
+
+
+
+
+ cleanup:
+
+  sinfo_free_propertylist(&plist);
+  sinfo_free_frame(&dup_frm);
+  sinfo_free_frameset(&wrk_set);
+  sinfo_free_frameset(&tot_set);
+  sinfo_free_my_vector(&dit_val);
+  sinfo_free_frameset(&cdb_set);
+
+
+  if (cpl_error_get_code() != CPL_ERROR_NONE) {
+    return -1;
+  } else {
+    return 0;
+  }
+
+
+
+}
+
+static int count_diff_ndit(cpl_frameset *set, cpl_vector** dit_val)
+{
+  cpl_frame* tmp_frm=NULL;
+  cpl_frame* dup_frm=NULL;
+
+
+  char  tmp_name[FILE_NAME_SZ];
+  int nraw=0;
+  int i=0;
+  int ndit=1;
+  double ref_dit=0;
+  cpl_vector* dit=NULL; 
+  cpl_propertylist* plist=NULL;
+
+  nraw=cpl_frameset_get_size(set);
+  dit=cpl_vector_new(nraw);
+  for(i=0;i<nraw;i++) {
+     tmp_frm = cpl_frameset_get_frame(set, i);
+     strcpy(tmp_name,cpl_frame_get_filename(tmp_frm));
+     plist= cpl_propertylist_load(tmp_name,0);
+     cpl_vector_set(dit,i,sinfo_pfits_get_dit(plist));
+     sinfo_free_propertylist(&plist);
+  }
+
+
+  cpl_vector_sort(dit,1);
+  ref_dit=cpl_vector_get(dit,0);
+
+
+  for(i=1;i<nraw;i++) {
+    if(ref_dit != cpl_vector_get(dit,i)) {
+      ref_dit=cpl_vector_get(dit,i);
+      ndit++;
+    }
+  }
+  *dit_val=cpl_vector_new(ndit);
+  ref_dit=cpl_vector_get(dit,0);
+  cpl_vector_set(*dit_val,0,cpl_vector_get(dit,0));
+  ndit=1;
+
+   for(i=1;i<nraw;i++) {
+    if(ref_dit != cpl_vector_get(dit,i)) {
+      cpl_vector_set(*dit_val,ndit,cpl_vector_get(dit,i));
+      ref_dit=cpl_vector_get(dit,i);
+      ndit++;
+    }
+  }
+
+  cpl_vector_delete(dit);
+  cpl_frame_delete(dup_frm);
+
+  return ndit;
+}
+
+/**@}*/
diff --git a/recipes/sinfo_rec_mflat.c b/recipes/sinfo_rec_mflat.c
new file mode 100644
index 0000000..0bdf278
--- /dev/null
+++ b/recipes/sinfo_rec_mflat.c
@@ -0,0 +1,318 @@
+/* $Id: sinfo_rec_mflat.c,v 1.22 2008/02/05 08:13:05 amodigli Exp $
+ *
+ * This file is part of the SINFONI Pipeline
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*
+ * $Author: amodigli $
+ * $Date: 2008/02/05 08:13:05 $
+ * $Revision: 1.22 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+ /****************************************************************
+  *          Rec_Lampflats Frames Data Reduction                          *
+  ****************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>          /* allows the program compilation */
+#endif
+
+/*-----------------------------------------------------------------------------
+                                Includes
+ ----------------------------------------------------------------------------*/
+
+/* std */
+#include <strings.h>
+#include <string.h>
+#include <stdio.h>
+
+/* cpl */
+#include <cpl.h>    
+#include <irplib_utils.h>
+/* sinfoni */
+#include <sinfo_pro_types.h>
+#include <sinfo_utilities.h>
+#include <sinfo_general_config.h>
+#include <sinfo_product_config.h>
+#include <sinfo_bp_config.h>
+#include <sinfo_bp_norm_config.h>
+#include <sinfo_lamp_flats_config.h>
+#include <sinfo_bp_norm.h>
+#include <sinfo_new_lamp_flats.h>
+#include <sinfo_functions.h>
+#include <sinfo_new_add_bp_map.h>
+#include <sinfo_tpl_utils.h>
+#include <sinfo_tpl_dfs.h>
+#include <sinfo_msg.h>
+#include <sinfo_error.h>
+#include <sinfo_utils_wrappers.h>
+
+/*-----------------------------------------------------------------------------
+                            Functions prototypes
+ ----------------------------------------------------------------------------*/
+static int sinfo_rec_mflat_create(cpl_plugin *);
+static int sinfo_rec_mflat_exec(cpl_plugin *);
+static int sinfo_rec_mflat_destroy(cpl_plugin *);
+static int sinfo_rec_mflat(cpl_parameterlist *, cpl_frameset *);
+
+
+/*-----------------------------------------------------------------------------
+                            Static variables
+ ----------------------------------------------------------------------------*/
+
+static char sinfo_rec_mflat_description[] =
+"This recipe reduce normal raw flat fields.\n"
+"The input files are a set of flat fields with tag FLAT_LAMP\n"
+"optionally one may have in input also several bad pixel maps to be coadded.\n"
+"The main products are a master flat field (PRO.CATG=MASTER_FLAT_LAMP) image\n"
+"a bad pixel map (PRO.CATG=BP_MAP_NO), "
+"a master bad pixel map (PRO.CATG=MASTER_BP_MAP) resulting by the coaddition\n"
+"of all bad pixel maps.\n"
+"Information on relevant parameters can be found with\n"
+"esorex --params sinfo_rec_mflat\n"
+"esorex --help sinfo_rec_mflat\n"
+"\n";
+
+
+
+/*-----------------------------------------------------------------------------
+                                Functions code
+ ----------------------------------------------------------------------------*/
+/*---------------------------------------------------------------------------*/
+/**
+ * @defgroup sinfo_rec_mflat   Recipe to compute master flat
+ */
+/*---------------------------------------------------------------------------*/
+/**@{*/
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Build the list of available plugins, for this module. 
+  @param    list    the plugin list
+  @return   0 if everything is ok, -1 otherwise
+
+  Create the recipe instance and make it available to the application using the 
+  interface. This function is exported.
+ */
+/*---------------------------------------------------------------------------*/
+
+int cpl_plugin_get_info(cpl_pluginlist *list)
+{
+
+  cpl_recipe *recipe = cpl_calloc(1, sizeof *recipe);
+  cpl_plugin *plugin = &recipe->interface;
+
+
+  cpl_plugin_init(plugin,
+          CPL_PLUGIN_API,
+          SINFONI_BINARY_VERSION,
+          CPL_PLUGIN_TYPE_RECIPE,
+          "sinfo_rec_mflat",
+          "Master flat determination",
+          sinfo_rec_mflat_description,
+          "Andrea Modigliani",
+          "Andrea.Modigliani at eso.org",
+          sinfo_get_license(),
+          sinfo_rec_mflat_create,
+          sinfo_rec_mflat_exec,
+          sinfo_rec_mflat_destroy);
+
+  cpl_pluginlist_append(list, plugin);
+
+  return 0;
+
+}
+
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Setup the recipe options    
+  @param    plugin  the plugin
+  @return   0 if everything is ok
+
+  Defining the command-line/configuration parameters for the recipe.
+ */
+/*---------------------------------------------------------------------------*/
+
+static int sinfo_rec_mflat_create(cpl_plugin *plugin)
+{
+
+    cpl_recipe      * recipe ;
+
+    /* Check that the plugin is part of a valid recipe */
+    if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+        recipe = (cpl_recipe *)plugin ;
+    else return -1 ;
+
+   /* Create the parameters list in the cpl_recipe object */
+    recipe->parameters = cpl_parameterlist_new() ; 
+
+  /*
+   * Fill the parameter list.
+   */
+  sinfo_general_config_add(recipe->parameters);
+  sinfo_product_config_add(recipe->parameters);
+  sinfo_bp_norm_config_add(recipe->parameters);
+  sinfo_lamp_flats_config_add(recipe->parameters);
+
+  return 0;
+
+}
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Execute the plugin instance given by the interface
+  @param    plugin  the plugin
+  @return   0 if everything is ok
+ */
+/*---------------------------------------------------------------------------*/
+static int sinfo_rec_mflat_exec(cpl_plugin *plugin)
+{
+    cpl_recipe  *   recipe ;
+    cpl_errorstate initial_errorstate = cpl_errorstate_get();
+    /* Get the recipe out of the plugin */
+    if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+        recipe = (cpl_recipe *)plugin ;
+    else return -1 ;
+    cpl_error_reset();
+    irplib_reset();
+
+    if (!cpl_errorstate_is_equal(initial_errorstate)) {                      
+        /* Dump the error history since recipe execution start.                
+           At this point the recipe cannot recover from the error */           
+        cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);              
+    } 
+  return sinfo_rec_mflat(recipe->parameters, recipe->frames);
+
+}
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Destroy what has been created by the 'create' function
+  @param    plugin  the plugin
+  @return   0 if everything is ok
+ */
+/*---------------------------------------------------------------------------*/
+static int sinfo_rec_mflat_destroy(cpl_plugin *plugin)
+{
+
+  cpl_recipe *recipe = (cpl_recipe *) plugin;
+
+  /* Get the recipe out of the plugin */
+  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+      recipe = (cpl_recipe *)plugin ;
+  else return -1 ;
+
+  cpl_parameterlist_delete(recipe->parameters);
+  return 0;
+
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Interpret the command line options and execute the data processing
+  @param    parlist     the parameters list
+  @param    frameset   the frames list
+  @return   0 if everything is ok
+ */
+/*---------------------------------------------------------------------------*/
+/*
+ * The actual recipe actually start here.
+ */
+
+
+static int
+sinfo_rec_mflat(cpl_parameterlist *config, cpl_frameset *set)
+{
+ 
+  cpl_parameter* p;
+  cpl_frameset* ref_set=NULL;
+  int pdensity=0;
+  int line_cor=0;
+
+  check_nomsg(p=cpl_parameterlist_find(config,"sinfoni.product.density"));
+  check_nomsg(pdensity=cpl_parameter_get_int(p));
+
+  sinfo_msg("Welcome to SINFONI Pipeline release %d.%d.%d",
+        SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
+  ck0(sinfo_dfs_set_groups(set),"Cannot indentify RAW and CALIB frames") ;
+
+  check_nomsg(p=cpl_parameterlist_find(config, "sinfoni.general.lc_sw"));
+  check_nomsg(line_cor=cpl_parameter_get_bool(p));
+  if(line_cor==1) {
+     check_nomsg(sinfo_ima_line_cor(config,set));
+  }
+
+
+
+  check_nomsg(ref_set=cpl_frameset_duplicate(set));
+  sinfo_bp_config_add(config);  
+  check_nomsg(p = cpl_parameterlist_find(config,"sinfoni.bp.method"));
+  check_nomsg(cpl_parameter_set_string(p,"Normal"));   
+  /* 
+       ---------------------------------------------------------
+                MASTER_FLAT
+       ---------------------------------------------------------
+  */
+ 
+  sinfo_msg("-------------------------------------------");
+  sinfo_msg("MASTER FLAT DETERMINATION                  ");
+  sinfo_msg("-------------------------------------------");
+    
+  ck0(sinfo_new_lamp_flats(cpl_func,config,set,ref_set),
+      "MASTER FLAT DETERMINATION FAILED");
+  sinfo_msg("MASTER FLAT DETERMINATION SUCCESS") ; 
+
+  sinfo_msg("-------------------------------------------");
+  sinfo_msg("BP_MAP_NO BAD PIXEL MAP DETERMINATION      ");
+  sinfo_msg("-------------------------------------------");
+  /* 
+       ---------------------------------------------------------
+                BP_SEARCH
+       ---------------------------------------------------------
+  */
+   
+  check_nomsg(p = cpl_parameterlist_find(config,"sinfoni.bp.method"));
+  check_nomsg(cpl_parameter_set_string(p,"Normal"));   
+  ck0(sinfo_new_bp_search_normal(cpl_func,config,set,ref_set,PRO_BP_MAP_NO),
+  "BP_MAP_NO BAD PIXEL MAP DETERMINATION FAILED") ;
+    
+  sinfo_msg("------------------------------------------");
+  sinfo_msg("MASTER_BP_MAP BAD PIXEL MAP DETERMINATION ");
+  sinfo_msg("------------------------------------------");
+  ck0(sinfo_new_add_bp_map(cpl_func,config, set,ref_set),
+     "MASTER_BP_MAP BAD PIXEL MAP FAILED") ;
+  sinfo_msg("MASTER_BP_MAP BAD PIXEL MAP DETERMINATION SUCCESS");
+    
+
+  if(pdensity < 2) {
+     check_nomsg(cpl_frameset_erase(set,PRO_BP_MAP_NO));
+  }
+
+ cleanup:
+
+  sinfo_free_frameset(&ref_set);
+
+  if (cpl_error_get_code() != CPL_ERROR_NONE) {
+    return -1;
+  } else {
+    return 0;
+  }
+
+}
+
+/**@}*/
+
+
diff --git a/recipes/sinfo_rec_pupil.c b/recipes/sinfo_rec_pupil.c
new file mode 100644
index 0000000..8478747
--- /dev/null
+++ b/recipes/sinfo_rec_pupil.c
@@ -0,0 +1,300 @@
+/* $Id: sinfo_rec_pupil.c,v 1.17 2008/02/12 14:56:50 amodigli Exp $
+ *
+ * This file is part of the SINFONI Pipeline
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+ 
+/*
+ * $Author: amodigli $
+ * $Date: 2008/02/12 14:56:50 $
+ * $Revision: 1.17 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+ /****************************************************************
+  *          Wave_Cal Frames Data Reduction                          *
+  ****************************************************************/
+
+/*-----------------------------------------------------------------------------
+                                Includes
+ -----------------------------------------------------------------------------*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>          /* allows the program compilation */
+#endif
+
+/* std */
+#include <strings.h>
+#include <string.h>
+#include <stdio.h>
+
+
+/* cpl */
+#include <cpl.h>      
+
+/* irplib */
+#include <irplib_utils.h>
+
+
+/* sinfoni */
+#include <sinfo_pro_types.h>
+#include <sinfo_product_config.h>
+#include <sinfo_prepare_stacked_frames_config.h>
+#include <sinfo_objnod_config.h>
+#include <sinfo_raw_types.h>
+#include <sinfo_tpl_utils.h>
+#include <sinfo_tpl_dfs.h>
+#include <sinfo_hidden.h>
+#include <sinfo_globals.h>
+#include <sinfo_functions.h>
+#include <sinfo_msg.h>
+#include <sinfo_new_prepare_stacked_frames.h>
+#include <sinfo_new_objnod.h>
+#include <sinfo_error.h>
+#include <sinfo_utils_wrappers.h>
+/*-----------------------------------------------------------------------------
+                            Functions prototypes
+ -----------------------------------------------------------------------------*/
+static int sinfo_rec_pupil_create(cpl_plugin *);
+static int sinfo_rec_pupil_exec(cpl_plugin *);
+static int sinfo_rec_pupil_destroy(cpl_plugin *);
+static int sinfo_rec_pupil(cpl_parameterlist *, cpl_frameset *);
+
+/*-----------------------------------------------------------------------------
+                            Static variables
+ -----------------------------------------------------------------------------*/
+static char sinfo_rec_pupil_description1[] =
+"This recipe performs science data reduction.\n"
+"The input files are science object and sky frames \n"
+"with tags OBJECT_NODDING and SKY_NODDING\n"
+"Master calibration frames:\n";
+
+
+static char sinfo_rec_pupil_description2[] =
+"A corresponding (band,preoptics) wavelength map image with tag WAVE_MAP\n"
+"A corresponding (band,preoptics) master flat field with tag MASTER_FLAT_LAMP\n"
+"A corresponding (band,preoptics) master bad pixel map with tag MASTER_BP_MAP\n"
+"A corresponding (band,preoptics) slitlets position frame with tag SLIT_POS\n"
+"A corresponding (band) distortion table with tag DISTORTION\n"
+"A corresponding (band) slitlet distance table with tag SLITLETS_DISTANCE\n";
+
+
+static char sinfo_rec_pupil_description3[] =
+"The output is an image resulting from the IMA1 op IMA2 where op indicates\n"
+"A reference table with the position of the 1st column with tag FIRST_COLUMN\n"
+"Relevant outputs are:\n"
+"combined cubes (PRO.CATG=x_OBS x=STD,OBJ,PSF)\n"
+"reconstructed cube (PRO.CATG=COADD_x_OBS x=STD,OBJ,PSF)\n"
+"An average along Z of the reconstructed cube \n"
+"(PRO.CATG=MED_x_OBS x=STD,OBJ,PSF)\n"
+"The bad pixel map associated to the cube \n"
+"(PRO.CATG=BP_MAP_COADD_x_OBS x=STD,OBJ,PSF)\n";
+
+
+static char sinfo_rec_pupil_description4[] =
+"Information on relevant parameters can be found with\n"
+"esorex --params sinfo_rec_pupil\n"
+"esorex --help sinfo_rec_pupil\n"
+"\n";
+
+static char sinfo_rec_pupil_description[1300];
+
+/*-----------------------------------------------------------------------------
+                                Functions code
+ ----------------------------------------------------------------------------*/
+/*---------------------------------------------------------------------------*/
+/**
+ * @defgroup sinfo_rec_pupil   Recipe to reduce pupil data
+ */
+/*---------------------------------------------------------------------------*/
+/**@{*/
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Build the list of available plugins, for this module. 
+  @param    list    the plugin list
+  @return   0 if everything is ok, -1 otherwise
+
+  Create the recipe instance and make it available to the application using the 
+  interface. This function is exported.
+ */
+/*---------------------------------------------------------------------------*/
+
+int
+cpl_plugin_get_info(cpl_pluginlist *list)
+{
+
+  cpl_recipe *recipe = cpl_calloc(1, sizeof *recipe);
+  cpl_plugin *plugin = &recipe->interface;
+
+
+  strcpy(sinfo_rec_pupil_description,sinfo_rec_pupil_description1);
+  strcat(sinfo_rec_pupil_description,sinfo_rec_pupil_description2);
+  strcat(sinfo_rec_pupil_description,sinfo_rec_pupil_description3);
+  strcat(sinfo_rec_pupil_description,sinfo_rec_pupil_description4);
+
+  cpl_plugin_init(plugin,
+          CPL_PLUGIN_API,
+          SINFONI_BINARY_VERSION,
+          CPL_PLUGIN_TYPE_RECIPE,
+          "sinfo_rec_pupil",
+          "Pupil data reduction",
+          sinfo_rec_pupil_description,
+          "Andrea Modigliani",
+          "Andrea.Modigliani at eso.org",
+          sinfo_get_license(),
+          sinfo_rec_pupil_create,
+          sinfo_rec_pupil_exec,
+          sinfo_rec_pupil_destroy);
+ 
+  cpl_pluginlist_append(list, plugin);
+
+  return 0;
+
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Setup the recipe options    
+  @param    plugin  the plugin
+  @return   0 if everything is ok
+
+  Defining the command-line/configuration parameters for the recipe.
+ */
+/*---------------------------------------------------------------------------*/
+ 
+static int sinfo_rec_pupil_create(cpl_plugin *plugin)
+{
+   cpl_recipe      * recipe ;
+
+    /* Check that the plugin is part of a valid recipe */
+    if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+        recipe = (cpl_recipe *)plugin ;
+    else return -1 ;
+    cpl_error_reset();
+    irplib_reset();
+
+    /* Create the parameters list in the cpl_recipe object */
+    recipe->parameters = cpl_parameterlist_new() ; 
+
+
+  /*
+   * Fill the parameter list.
+   */  
+
+  sinfo_product_config_add(recipe->parameters);
+  sinfo_prepare_stacked_frames_config_add(recipe->parameters);
+  sinfo_objnod_config_add(recipe->parameters);
+  return 0;
+
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Execute the plugin instance given by the interface
+  @param    plugin  the plugin
+  @return   0 if everything is ok
+ */
+/*---------------------------------------------------------------------------*/
+
+
+static int sinfo_rec_pupil_exec(cpl_plugin *plugin)
+{
+
+  cpl_recipe *recipe = (cpl_recipe *) plugin;
+   /* Get the recipe out of the plugin */
+    if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+        recipe = (cpl_recipe *)plugin ;
+    else return -1 ;
+
+  return sinfo_rec_pupil(recipe->parameters, recipe->frames);
+
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Destroy what has been created by the 'create' function
+  @param    plugin  the plugin
+  @return   0 if everything is ok
+ */
+/*---------------------------------------------------------------------------*/
+static int sinfo_rec_pupil_destroy(cpl_plugin *plugin)
+{
+  cpl_recipe  *   recipe ;
+    /* Get the recipe out of the plugin */
+    if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+        recipe = (cpl_recipe *)plugin ;
+    else return -1 ;
+
+  cpl_parameterlist_delete(recipe->parameters);
+
+  return 0;
+
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Interpret the command line options and execute the data processing
+  @param    parlist     the parameters list
+  @param    frameset   the frames list
+  @return   0 if everything is ok
+ */
+/*---------------------------------------------------------------------------*/
+/*
+ * The actual recipe actually start here.
+ */
+
+static int sinfo_rec_pupil(cpl_parameterlist *config, cpl_frameset *set)
+{
+ 
+  fake* fk=NULL;
+  fk=sinfo_fake_new();
+
+   sinfo_msg("Welcome to SINFONI Pipeline release %d.%d.%d",
+        SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
+
+   ck0(sinfo_dfs_set_groups(set),"Cannot indentify RAW and CALIB frames") ;
+
+   /* hidden parameters */
+   sinfo_msg("---------------------------------------------");
+   sinfo_msg("%s FRAME DETERMINATION", PRO_PUPIL_LAMP_STACKED);
+   sinfo_msg("---------------------------------------------");
+  
+   ck0(sinfo_new_prepare_stacked_frames(cpl_func,config, set, NULL,
+					PRO_PUPIL_LAMP_STACKED,0,fk ),
+       "Failed %s FRAME DETERMINATION", PRO_PUPIL_LAMP_STACKED);
+   sinfo_msg("%s FRAME DETERMINATION SUCCESS", PRO_PUPIL_LAMP_STACKED);
+  
+   sinfo_msg("---------------------------------------------");
+   sinfo_msg("PUPIL DATA REDUCTION");
+   sinfo_msg("---------------------------------------------");
+  
+   ck0(sinfo_new_objnod(cpl_func,config, set,PRO_COADD_PUPIL),
+       "Failed PUPIL DATA REDUCTION") ;
+   sinfo_msg("PUPIL DATA REDUCTION SUCCESS");
+ 
+ cleanup:
+  sinfo_fake_delete(&fk);
+
+  if (cpl_error_get_code() != CPL_ERROR_NONE) {
+    return -1;
+  } else {
+    return 0;
+  }
+
+
+}
+/**@}*/
diff --git a/recipes/sinfo_rec_wavecal.c b/recipes/sinfo_rec_wavecal.c
new file mode 100644
index 0000000..6ee81eb
--- /dev/null
+++ b/recipes/sinfo_rec_wavecal.c
@@ -0,0 +1,449 @@
+/* $Id: sinfo_rec_wavecal.c,v 1.30 2009/09/02 12:00:56 kmirny Exp $
+ *
+ * This file is part of the SINFONI Pipeline
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: kmirny $
+ * $Date: 2009/09/02 12:00:56 $
+ * $Revision: 1.30 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+ /****************************************************************
+  *          Wave_Cal Frames Data Reduction                          *
+  ****************************************************************/
+
+/*-----------------------------------------------------------------------------
+                                Includes
+ -----------------------------------------------------------------------------*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>          /* allows the program compilation */
+#endif
+
+/* std */
+#include <strings.h>
+#include <string.h>
+#include <stdio.h>
+
+
+/* cpl */
+#include <cpl.h>
+
+/* irplib */
+#include <irplib_utils.h>
+
+/* sinfoni */
+#include <sinfo_pro_types.h>
+#include <sinfo_general_config.h>
+#include <sinfo_utilities.h>
+#include <sinfo_product_config.h>
+#include <sinfo_prepare_stacked_frames_config.h>
+#include <sinfo_wavecal_config.h>
+#include <sinfo_raw_types.h>
+#include <sinfo_tpl_utils.h>
+#include <sinfo_tpl_dfs.h>
+#include <sinfo_hidden.h>
+#include <sinfo_globals.h>
+#include <sinfo_functions.h>
+#include <sinfo_msg.h>
+#include <sinfo_new_prepare_stacked_frames.h>
+#include <sinfo_new_wave_cal_slit2.h>
+#include <sinfo_error.h>
+#include <sinfo_utils_wrappers.h>
+
+#include <sinfo_key_names.h>
+
+/*-----------------------------------------------------------------------------
+                            Functions prototypes
+ -----------------------------------------------------------------------------*/
+static int sinfo_rec_wavecal_create(cpl_plugin *);
+static int sinfo_rec_wavecal_exec(cpl_plugin *);
+static int sinfo_rec_wavecal_destroy(cpl_plugin *);
+static int sinfo_rec_wavecal(cpl_parameterlist *, cpl_frameset *);
+
+/*-----------------------------------------------------------------------------
+                            Static variables
+ -----------------------------------------------------------------------------*/
+
+static char sinfo_rec_wavecal_description1[] =
+"This recipe performs wavelength calibration.\n"
+"The input files are on/off arc lamp frames with tag WAVE_LAMP\n"
+"Master calibration frame input is:\n"
+"A corresponding (band) reference line table with tag REF_LINE_ARC\n"
+"A corresponding (band) distortion table with tag DISTORTION\n"
+"A corresponding (band,preoptic) master flat with tag MASTER_FLAT_LAMP\n"
+"A corresponding (band,preoptics) master bad "
+"pixel map with tag MASTER_BP_MAP\n";
+
+
+static char sinfo_rec_wavecal_description2[] =
+"If wcal-estimate_ind=TRUE, a corresponding (band,preoptics) slitlet position\n"
+"guess table SLIT_POS_GUESS (for example a copy of the SLIT_POS product)\n"
+"If wcal-calib_indicator=FALSE, a corresponding (band,preoptics) parabolic \n"
+"fit coefficients table WAVE_COEF_SLIT\n"
+"If sinfoni.wavecal.slitpos_boostrap_switch=FALSE \n"
+"(wcal-calib-slitpos_bootstrap=0),\n"
+"a corresponding (band,preoptics) slitlets position table with tag SLIT_POS\n";
+
+
+
+static char sinfo_rec_wavecal_description3[] =
+"The main products are:\n"
+"The master flat field corrected for distortions \n"
+"(PRO.CATG=MFLAT_STACKED_DIST)\n"
+"The arc lamp frames stacked (PRO.CATG=WAVE_LAMP_STACKED)\n"
+"The wavelength map (PRO.CATG=WAVE_MAP)\n"
+"The slitlet position table (PRO.CATG=SLIT_POS)\n"
+"A parabolic fit coefficients table (PRO.CATG=WAVE_COEF_SLIT)\n"
+"Parameters relative to arc lamp line fit: (PRO.CATG=WAVE_FIT_PARAMS)\n"
+"Information on relevant parameters can be found with\n"
+"esorex --params sinfo_rec_wavecal\n"
+"esorex --help sinfo_rec_wavecal\n"
+"\n";
+
+
+static char sinfo_rec_wavecal_description[1500];
+
+/*-----------------------------------------------------------------------------
+                                Functions code
+ ----------------------------------------------------------------------------*/
+/*---------------------------------------------------------------------------*/
+/**
+ * @defgroup sinfo_rec_wavecal   Recipe to reduce arc lamp data
+ */
+/*---------------------------------------------------------------------------*/
+
+/**@{*/
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Build the list of available plugins, for this module.
+  @param    list    the plugin list
+  @return   0 if everything is ok, -1 otherwise
+
+  Create the recipe instance and make it available to the application using
+  the interface. This function is exported.
+ */
+/*---------------------------------------------------------------------------*/
+
+int
+cpl_plugin_get_info(cpl_pluginlist *list)
+{
+
+  cpl_recipe *recipe = cpl_calloc(1, sizeof *recipe);
+  cpl_plugin *plugin = &recipe->interface;
+
+
+  strcpy(sinfo_rec_wavecal_description,sinfo_rec_wavecal_description1);
+  strcat(sinfo_rec_wavecal_description,sinfo_rec_wavecal_description2);
+  strcat(sinfo_rec_wavecal_description,sinfo_rec_wavecal_description3);
+
+  cpl_plugin_init(plugin,
+          CPL_PLUGIN_API,
+          SINFONI_BINARY_VERSION,
+          CPL_PLUGIN_TYPE_RECIPE,
+          "sinfo_rec_wavecal",
+          "Wavelength calibration and slitpos determination",
+          sinfo_rec_wavecal_description,
+          "Andrea Modigliani",
+          "Andrea.Modigliani at eso.org",
+          sinfo_get_license(),
+          sinfo_rec_wavecal_create,
+          sinfo_rec_wavecal_exec,
+          sinfo_rec_wavecal_destroy);
+
+  cpl_pluginlist_append(list, plugin);
+
+  return 0;
+
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Setup the recipe options
+  @param    plugin  the plugin
+  @return   0 if everything is ok
+
+  Defining the command-line/configuration parameters for the recipe.
+ */
+/*---------------------------------------------------------------------------*/
+
+static int sinfo_rec_wavecal_create(cpl_plugin *plugin)
+{
+   cpl_recipe      * recipe ;
+
+    /* Check that the plugin is part of a valid recipe */
+    if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
+        recipe = (cpl_recipe *)plugin ;
+    else return -1 ;
+    cpl_error_reset();
+    irplib_reset();
+
+    /* Create the parameters list in the cpl_recipe object */
+    recipe->parameters = cpl_parameterlist_new() ;
+
+
+  /*
+   * Fill the parameter list.
+   */
+
+  /* Wavelength calibration  */
+  sinfo_general_config_add(recipe->parameters);
+  sinfo_product_config_add(recipe->parameters);
+  sinfo_prepare_stacked_frames_config_add(recipe->parameters);
+  sinfo_wavecal_config_add(recipe->parameters);
+  return 0;
+
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Execute the plugin instance given by the interface
+  @param    plugin  the plugin
+  @return   0 if everything is ok
+ */
+/*---------------------------------------------------------------------------*/
+
+
+static int sinfo_rec_wavecal_exec(cpl_plugin *plugin)
+{
+
+  cpl_recipe *recipe = (cpl_recipe *) plugin;
+
+  /* Get the recipe out of the plugin */
+  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
+      recipe = (cpl_recipe *)plugin ;
+  else return -1 ;
+
+  return sinfo_rec_wavecal(recipe->parameters, recipe->frames);
+
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Destroy what has been created by the 'create' function
+  @param    plugin  the plugin
+  @return   0 if everything is ok
+ */
+/*---------------------------------------------------------------------------*/
+static int sinfo_rec_wavecal_destroy(cpl_plugin *plugin)
+{
+  cpl_recipe  *   recipe ;
+    /* Get the recipe out of the plugin */
+    if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
+        recipe = (cpl_recipe *)plugin ;
+    else return -1 ;
+
+  cpl_parameterlist_delete(recipe->parameters);
+
+  return 0;
+
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Interpret the command line options and execute the data processing
+  @param    parlist     the parameters list
+  @param    frameset   the frames list
+  @return   0 if everything is ok
+ */
+/*---------------------------------------------------------------------------*/
+/*
+ * The actual recipe actually start here.
+ */
+
+static int sinfo_rec_wavecal(cpl_parameterlist *config, cpl_frameset *set)
+{
+
+  int sw=0;
+  fake* fk=NULL;
+  cpl_parameter* p=NULL;
+  cpl_frameset* wrk_set=NULL;
+  cpl_frame* frame=NULL;
+  int ind_index=0;
+  cpl_frameset* ref_set=NULL;
+  int pdensity=0;
+  int line_cor=0;
+
+  fk=sinfo_fake_new();
+
+   sinfo_msg("Welcome to SINFONI Pipeline release %d.%d.%d",
+        SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
+
+
+
+  ck0(sinfo_dfs_set_groups(set),"Cannot indentify RAW and CALIB frames") ;
+  check_nomsg(p=cpl_parameterlist_find(config, "sinfoni.general.lc_sw"));
+  check_nomsg(line_cor=cpl_parameter_get_bool(p));
+  if(line_cor==1) {
+     check_nomsg(sinfo_ima_line_cor(config,set));
+  }
+
+
+  check_nomsg(ref_set=cpl_frameset_duplicate(set));
+
+
+  check_nomsg(p=cpl_parameterlist_find(config,"sinfoni.product.density"));
+  check_nomsg(pdensity=cpl_parameter_get_int(p));
+
+  /* hidden parameters */
+  check_nomsg(p=cpl_parameterlist_find(config,
+                                       "sinfoni.wavecal.slitpos_boostrap"));
+  check_nomsg(sw=cpl_parameter_get_bool(p));
+  if( (sw == 1) ) {
+    check_nomsg(wrk_set=cpl_frameset_duplicate(set));
+
+    check_nomsg(p=cpl_parameterlist_find(config,"sinfoni.stacked.ind_index"));
+    check_nomsg(ind_index=cpl_parameter_get_bool(p));
+    check_nomsg(cpl_parameter_set_bool(p,TRUE));
+
+    sinfo_msg("---------------------------------------");
+    sinfo_msg("%s FRAME DETERMINATION", PRO_WAVE_LAMP_STACKED);
+    sinfo_msg("---------------------------------------");
+    ck0(sinfo_new_prepare_stacked_frames(cpl_func,config, wrk_set, NULL,
+                     PRO_WAVE_LAMP_STACKED,0,fk),
+       "FAILED STACKING FRAME %s",PRO_WAVE_LAMP_STACKED);
+
+    sinfo_msg("%s FRAME DETERMINATION SUCCESS", PRO_WAVE_LAMP_STACKED);
+
+    ck0(sinfo_new_wave_cal_slit2(cpl_func,config, wrk_set,ref_set),
+    "FIRST PART OF WAVELENGTH CALIBRATION FAILED") ;
+    sinfo_msg("FIRST PART OF WAVELENGTH CALIBRATION") ;
+
+    check_nomsg(frame = cpl_frameset_find(wrk_set,PRO_SLIT_POS_GUESS));
+    check_nomsg(cpl_frameset_insert(set,cpl_frame_duplicate(frame)));
+    check_nomsg(p=cpl_parameterlist_find(config,"sinfoni.stacked.ind_index"));
+    if(ind_index == 1) {
+       check_nomsg(cpl_parameter_set_bool(p,TRUE));
+       check_nomsg(p=cpl_parameterlist_find(config,
+                                           "sinfoni.wavecal.slitpos_boostrap"));
+       check_nomsg(cpl_parameter_set_bool(p,TRUE));
+       sinfo_msg("Set ind_index to TRUE");
+    } else {
+       check_nomsg(cpl_parameter_set_bool(p,FALSE));
+       check_nomsg(p=cpl_parameterlist_find(config,
+                                          "sinfoni.wavecal.slitpos_boostrap"));
+       check_nomsg(cpl_parameter_set_bool(p,FALSE));
+       sinfo_msg("Set ind_index to FALSE");
+    }
+    sinfo_free_frameset(&wrk_set);
+  }
+
+
+  sinfo_msg("---------------------------------------------");
+  sinfo_msg("%s FRAME DETERMINATION", PRO_WAVE_LAMP_STACKED);
+  sinfo_msg("---------------------------------------------");
+
+  /*
+   *  Modified code begins here...
+   */
+  {
+	  int i, nsky, ndark, nwave, non=0;
+	  cpl_frame * fr;
+	  const char * tag, * fname;
+	  char name[32];
+	  cpl_image * im;
+	  cpl_propertylist * plist;
+
+	  nsky = cpl_frameset_count_tags (set, RAW_SKY_NODDING);
+	  nwave = cpl_frameset_count_tags (set, RAW_WAVE_LAMP);
+	  ndark = cpl_frameset_count_tags (set, PRO_MASTER_DARK);
+
+	  if ( (nwave == 0) & (nsky>0) ) {
+		sinfo_msg ("No arc lamp frames found, using sky frames instead");
+		if (ndark == 0)
+		  sinfo_msg ("Including Master dark is recommended when running wavecal on sky frames");
+
+		i = 0;
+		while (i < cpl_frameset_get_size(set)) {
+		  fr = cpl_frameset_get_frame(set,i);
+		  tag = cpl_frame_get_tag (fr);
+
+		  if (strcmp(tag, RAW_SKY_NODDING)==0)
+		  {
+				cpl_frame * frnew = 0;
+				fname = cpl_frame_get_filename(fr);
+				sprintf (&name[0], "fakelamp_%d.fits", non++);
+				im = cpl_image_load(fname, CPL_TYPE_FLOAT, 0, 0);
+				plist = cpl_propertylist_load(fname,0);
+
+				/* Both if these needs to be changed to make sure the sky frame is
+				   interprated as ON-frame in sinfo_dfs.c
+
+				   The selection of KEY_NAME_LAMP_XE is arbitrary, but one of
+				   KEY_NAME_LAMP_* has to be set */
+				cpl_propertylist_set_bool (plist, KEY_NAME_LAMP_XE, 1);
+				cpl_propertylist_set_string (plist, KEY_NAME_DPR_TYPE, "WAVE,LAMP");
+
+				cpl_image_save (im, name, CPL_BPP_IEEE_FLOAT, plist, CPL_IO_DEFAULT);
+				cpl_image_delete (im);
+				cpl_propertylist_delete(plist);
+
+				/* Looks like it's not possible to modify the frame directly
+				   without duplicating it first. */
+				frnew = cpl_frame_duplicate (fr);
+				cpl_frame_set_filename(frnew, name);
+				cpl_frame_set_tag (frnew, RAW_WAVE_LAMP);
+				cpl_frameset_erase_frame (set, fr);
+				cpl_frameset_insert (set, frnew);
+		  }
+		  else
+		i++;
+		}
+	  }
+
+	  /*
+	   * Modified code ends here
+	   */
+  }
+  ck0(sinfo_new_prepare_stacked_frames(cpl_func,config, set, NULL,
+                       PRO_WAVE_LAMP_STACKED,0,fk),
+      "%s FRAME DETERMINATION FAILED",PRO_WAVE_LAMP_STACKED);
+  sinfo_msg("%s FRAME DETERMINATION SUCCESS", PRO_WAVE_LAMP_STACKED);
+
+  sinfo_msg("---------------------------------------------");
+  sinfo_msg("WAVELENGTH CALIBRATION");
+  sinfo_msg("---------------------------------------------");
+
+
+  ck0(sinfo_new_wave_cal_slit2(cpl_func,config, set,ref_set),
+      "FAILED WAVELENGTH CALIBRATION");
+  sinfo_msg("SUCCESS WAVELENGTH CALIBRATION");
+
+  sinfo_fake_delete(&fk);
+   if(pdensity < 2) {
+     check_nomsg(cpl_frameset_erase(set,PRO_STACK_MFLAT_DIST));
+     check_nomsg(cpl_frameset_erase(set,PRO_WAVE_LAMP_STACKED));
+   }
+
+ cleanup:
+
+  sinfo_free_frameset(&ref_set);
+  sinfo_free_frameset(&wrk_set);
+  sinfo_fake_delete(&fk);
+
+
+  if (cpl_error_get_code() != CPL_ERROR_NONE) {
+    return -1;
+  } else {
+    return 0;
+  }
+
+}
+/**@}*/
diff --git a/recipes/sinfo_utl_bp_mask_add.c b/recipes/sinfo_utl_bp_mask_add.c
new file mode 100644
index 0000000..7b86036
--- /dev/null
+++ b/recipes/sinfo_utl_bp_mask_add.c
@@ -0,0 +1,271 @@
+/* $Id: sinfo_utl_bp_mask_add.c,v 1.18 2008/08/21 09:46:47 amodigli Exp $
+ *
+ * This file is part of the CPL (Common Pipeline Library)
+ * Copyright (C) 2002 European Southern Observatory
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*
+ * $Author: amodigli $
+ * $Date: 2008/08/21 09:46:47 $
+ * $Revision: 1.18 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+ /****************************************************************
+  *           Bad pixel search  (normal method)                  *
+  ****************************************************************/
+
+/* --------------------------------------------------------------- 
+                         INCLUDES
+   --------------------------------------------------------------- */
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+/* std libraries */
+#include <strings.h>
+#include <string.h>
+#include <stdio.h>
+
+/* cpl */
+#include <cpl.h>     
+/* irplib */
+#include <irplib_utils.h>
+
+/* sinfoni */
+#include <sinfo_general_config.h>
+#include <sinfo_bp_norm_config.h>
+#include <sinfo_bp_lin_config.h>
+#include <sinfo_bp_noise_config.h>
+#include <sinfo_new_add_bp_map.h>
+#include <sinfo_tpl_utils.h>
+#include <sinfo_tpl_dfs.h>
+#include <sinfo_msg.h>
+#include <sinfo_error.h>
+#include <sinfo_utils_wrappers.h>
+
+/* --------------------------------------------------------------- 
+                         DEFINES
+   --------------------------------------------------------------- */
+/* --------------------------------------------------------------- 
+                         FUNCTIONS PROTOTYPES
+   --------------------------------------------------------------- */
+
+const char * sinfoni_get_licence(void);
+static int sinfo_utl_bp_mask_add_create(cpl_plugin *plugin);
+static int sinfo_utl_bp_mask_add_exec(cpl_plugin *plugin);
+static int sinfo_utl_bp_mask_add_destroy(cpl_plugin *plugin);
+static int sinfo_utl_bp_mask_add(cpl_parameterlist *, cpl_frameset *);
+
+/* --------------------------------------------------------------- 
+                         STATIC VARIABLES
+   --------------------------------------------------------------- */
+
+static char sinfo_utl_bp_mask_add_description[] =
+"This recipe performs bad pixel map coaddition.\n"
+"The input files are several (at least 2)  bad pixel masks in the sof file\n"
+"Their tab should contain the string BP_MAP.\n"
+"The output is an image resulting from the logical operator OR \n"
+"applied to all the masks.\n"
+"Information on relevant parameters can be found with\n"
+"esorex --params sinfo_utl_bp_mask_add\n"
+"esorex --help sinfo_utl_bp_mask_add\n"
+"\n";
+
+
+/* --------------------------------------------------------------- 
+                         FUNCTIONS CODE
+   --------------------------------------------------------------- */
+
+/*---------------------------------------------------------------------------*/
+/**
+ * @defgroup sinfo_utl_bp_mask_add  Recipe to coadd bad pixel masks
+ */
+/*---------------------------------------------------------------------------*/
+/**@{*/
+/* --------------------------------------------------------------- */
+
+int
+cpl_plugin_get_info(cpl_pluginlist *list)
+{
+
+  cpl_recipe *recipe = cpl_calloc(1, sizeof *recipe);
+  cpl_plugin *plugin = &recipe->interface;
+
+
+  cpl_plugin_init(plugin,
+          CPL_PLUGIN_API,
+          SINFONI_BINARY_VERSION,
+          CPL_PLUGIN_TYPE_RECIPE,
+          "sinfo_utl_bp_mask_add",
+          "Add bad pixels masks",
+          sinfo_utl_bp_mask_add_description,
+          "Andrea Modigliani",
+          "Andrea.Modigliani at eso.org",
+          sinfo_get_license(),
+          sinfo_utl_bp_mask_add_create,
+          sinfo_utl_bp_mask_add_exec,
+          sinfo_utl_bp_mask_add_destroy);
+
+  cpl_pluginlist_append(list, plugin);
+
+  return 0;
+
+}
+
+/* --------------------------------------------------------------- */
+/**
+  @brief   Set up the recipe options
+  @param   plugin   the plugin
+  @return  0 if everything is ok
+*/
+
+static int
+sinfo_utl_bp_mask_add_create(cpl_plugin *plugin)
+{
+
+  /*
+   * We have to provide the option we accept to the application.
+   * We need to setup our parameter list and hook it into the recipe
+   * interface.
+   */
+  cpl_recipe *recipe = (cpl_recipe *)plugin;
+  recipe->parameters = cpl_parameterlist_new();
+  if(recipe->parameters == NULL) {
+    return 1;
+  }
+  cpl_error_reset();
+  irplib_reset();
+
+  /*
+   * Fill the parameter list.
+   */
+
+
+  return 0;
+
+}
+
+/* --------------------------------------------------------------- */
+/**
+  @brief   Executes the plugin instance given by the interface
+  @param   plugin   the plugin
+  @return  0 if everything is ok
+*/
+static int
+sinfo_utl_bp_mask_add_exec(cpl_plugin *plugin)
+{
+ 
+
+  cpl_recipe *recipe = (cpl_recipe *) plugin;
+  cpl_errorstate initial_errorstate = cpl_errorstate_get();
+  int code=0;
+  
+  if(recipe->parameters == NULL ) {
+    return 1;
+  }
+  if(recipe->frames == NULL) {
+    return 1;
+  }
+
+  check_nomsg(code=sinfo_utl_bp_mask_add(recipe->parameters, recipe->frames));
+
+  if (!cpl_errorstate_is_equal(initial_errorstate)) {                      
+    /* Dump the error history since recipe execution start.                
+       At this point the recipe cannot recover from the error */           
+    cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);              
+  } 
+  cleanup:
+
+  return code;
+
+}
+
+/* --------------------------------------------------------------- */
+/**
+  @brief   Destroy what has been created by the 'create' function
+  @param   plugin   the plugin
+  @return  0 if everything is ok
+*/
+
+static int
+sinfo_utl_bp_mask_add_destroy(cpl_plugin *plugin)
+{
+  cpl_recipe *recipe = (cpl_recipe *) plugin;
+  /*
+   * We just destroy what was created during the plugin initializzation phase
+   * i.e. the parameter list. The frame set is managed by the application which
+   * called us, so that we must not touch it.
+   */
+
+  cpl_parameterlist_delete(recipe->parameters);
+  return 0;
+
+}
+
+/*
+ * The actual recipe actually start here.
+ */
+
+
+/* --------------------------------------------------------------- */
+/**
+  @brief   Do bad pixel search. Monitor parameters. Do something
+
+  @param   config   the parameter list
+  @param   set      the frames list
+  @return  0 if everything is ok
+
+  The parameter list must contain:
+
+  The parameters are used to combine the input images and generate
+  an output image which is saved on disk.
+
+*/
+static int
+sinfo_utl_bp_mask_add(cpl_parameterlist *config, cpl_frameset *sof)
+{
+  cpl_frameset* ref_set=NULL;
+  int n=0;
+  
+  sinfo_msg("Welcome to SINFONI Pipeline release %d.%d.%d",
+        SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
+
+   if(sinfo_dfs_set_groups(sof)) {
+       sinfo_msg_error("Cannot indentify RAW and CALIB frames") ;
+   }
+
+    n=cpl_frameset_get_size(sof);
+    if(n<1) {
+      sinfo_msg_error("Empty input frame list!");
+      goto cleanup ;
+    }
+
+   check_nomsg(ref_set=cpl_frameset_duplicate(sof));
+   ck0_nomsg(sinfo_new_add_bp_map(cpl_func,config,sof,ref_set));
+
+ cleanup:
+   sinfo_free_frameset(&ref_set);
+  if (cpl_error_get_code() != CPL_ERROR_NONE) {
+    return -1;
+  } else {
+    return 0;
+  }
+
+
+
+}
+/**@}*/
diff --git a/recipes/sinfo_utl_cube2ima.c b/recipes/sinfo_utl_cube2ima.c
new file mode 100644
index 0000000..d43b803
--- /dev/null
+++ b/recipes/sinfo_utl_cube2ima.c
@@ -0,0 +1,215 @@
+/* $Id: sinfo_utl_cube2ima.c,v 1.10 2007/10/26 09:40:28 amodigli Exp $
+ *
+ * This file is part of the SINFONI Pipeline
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2007/10/26 09:40:28 $
+ * $Revision: 1.10 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+/*-----------------------------------------------------------------------------
+                                Includes
+ ----------------------------------------------------------------------------*/
+/* cpl */
+#include <cpl.h>
+ 
+/* irplib */
+#include <irplib_utils.h>
+#include <sinfo_msg.h>
+#include <sinfo_tpl_utils.h>
+#include <sinfo_pfits.h>
+#include <sinfo_tpl_dfs.h>
+#include <sinfo_utl_cube2ima.h>
+/*-----------------------------------------------------------------------------
+                            Functions prototypes
+ ----------------------------------------------------------------------------*/
+
+static int sinfo_utl_cube2ima_create(cpl_plugin *) ;
+static int sinfo_utl_cube2ima_exec(cpl_plugin *) ;
+static int sinfo_utl_cube2ima_destroy(cpl_plugin *) ;
+
+/*-----------------------------------------------------------------------------
+                            Static variables
+ ----------------------------------------------------------------------------*/
+
+static char sinfo_utl_cube2ima_description[] =
+"This recipe performs cube to image comversion.\n"
+"The input file is a cube which is contained in the sof file\n"
+"Its tag should be CUBE.\n"
+"The output is an image resulting from the average of the \n"
+"cube over a  wavelength rage which can be set by parameters \n"
+"sinfoni.sinfo_utl_cube2ima.ws sinfoni.sinfo_utl_cube2ima.we\n"
+"having aliases 'ws' 'we'\n"
+"Information on relevant parameters can be found with\n"
+"esorex --params sinfo_utl_cube2ima\n"
+"esorex --help sinfo_utl_cube2ima\n"
+"\n";
+
+/*-----------------------------------------------------------------------------
+                                Functions code
+ ----------------------------------------------------------------------------*/
+/*---------------------------------------------------------------------------*/
+/**
+ * @defgroup sinfo_utl_cube2ima  Recipe to collapse a cube in an image
+ */
+/*---------------------------------------------------------------------------*/
+/**@{*/
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Build the list of available plugins, for this module. 
+  @param    list    the plugin list
+  @return   0 if everything is ok
+
+  This function is exported.
+ */
+/*---------------------------------------------------------------------------*/
+int cpl_plugin_get_info(cpl_pluginlist * list)
+{
+    cpl_recipe  *   recipe = cpl_calloc(1, sizeof *recipe ) ;
+    cpl_plugin  *   plugin = &recipe->interface ;
+
+    cpl_plugin_init(plugin,
+                    CPL_PLUGIN_API,
+                    SINFONI_BINARY_VERSION,
+                    CPL_PLUGIN_TYPE_RECIPE,
+                    "sinfo_utl_cube2ima",
+                    "Cube to image conversion",
+                    sinfo_utl_cube2ima_description,
+                    "Andrea Modigliani",
+                    "Andrea.Modigliani at eso.org",
+                    sinfo_get_license(),
+                    sinfo_utl_cube2ima_create,
+                    sinfo_utl_cube2ima_exec,
+                    sinfo_utl_cube2ima_destroy) ;
+
+    cpl_pluginlist_append(list, plugin) ;
+    
+    return 0;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Setup the recipe options    
+  @param    plugin  the plugin
+  @return   0 if everything is ok
+
+  Create the recipe instance and make it available to the application using the 
+  interface. 
+ */
+/*---------------------------------------------------------------------------*/
+static int sinfo_utl_cube2ima_create(cpl_plugin * plugin)
+{
+    cpl_recipe      * recipe ;
+    cpl_parameter   * p ;
+
+    /* Get the recipe out of the plugin */
+    if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+        recipe = (cpl_recipe *)plugin ;
+    else return -1 ;
+    cpl_error_reset();
+    irplib_reset();
+
+    /* Create the parameters list in the cpl_recipe object */
+    recipe->parameters = cpl_parameterlist_new() ; 
+
+    /* Fill the parameters list */
+    /* --stropt */
+
+    /* --doubleopt */
+    p = cpl_parameter_new_value("sinfoni.sinfo_utl_cube2ima.ws", 
+                                CPL_TYPE_DOUBLE, 
+                                "starting wavelength", 
+                                "sinfoni.sinfo_utl_cube2ima", 
+                                0.9999) ;
+    cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "ws") ;
+    cpl_parameterlist_append(recipe->parameters, p) ;
+
+
+    /* --doubleopt */
+    p = cpl_parameter_new_value("sinfoni.sinfo_utl_cube2ima.we", 
+                                CPL_TYPE_DOUBLE, 
+                                "starting wavelength", 
+                                "sinfoni.sinfo_utl_cube2ima", 
+                                2.999) ;
+    cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "we") ;
+    cpl_parameterlist_append(recipe->parameters, p) ;
+
+    /* Return */
+    return 0;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Execute the plugin instance given by the interface
+  @param    plugin  the plugin
+  @return   0 if everything is ok
+ */
+/*---------------------------------------------------------------------------*/
+static int sinfo_utl_cube2ima_exec(cpl_plugin * plugin)
+{
+    cpl_recipe  *   recipe ;
+    int result=0;
+    cpl_errorstate initial_errorstate = cpl_errorstate_get();
+
+    /* Get the recipe out of the plugin */
+    if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+        recipe = (cpl_recipe *)plugin ;
+    else return -1 ;
+
+      sinfo_msg("Welcome to SINFONI Pipeline release %d.%d.%d",
+        SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
+
+    result=sinfo_utl_cube2ima(recipe->parameters, recipe->frames) ;
+
+    if (!cpl_errorstate_is_equal(initial_errorstate)) {                      
+        /* Dump the error history since recipe execution start.                
+           At this point the recipe cannot recover from the error */           
+        cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);              
+    } 
+
+    return result ;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Destroy what has been created by the 'create' function
+  @param    plugin  the plugin
+  @return   0 if everything is ok
+ */
+/*---------------------------------------------------------------------------*/
+static int sinfo_utl_cube2ima_destroy(cpl_plugin * plugin)
+{
+    cpl_recipe  *   recipe ;
+
+    /* Get the recipe out of the plugin */
+    if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+        recipe = (cpl_recipe *)plugin ;
+    else return -1 ;
+
+    cpl_parameterlist_delete(recipe->parameters) ; 
+    return 0 ;
+}
+
+/**@}*/
diff --git a/recipes/sinfo_utl_cube2spectrum.c b/recipes/sinfo_utl_cube2spectrum.c
new file mode 100644
index 0000000..b7a1f76
--- /dev/null
+++ b/recipes/sinfo_utl_cube2spectrum.c
@@ -0,0 +1,289 @@
+/* $Id: sinfo_utl_cube2spectrum.c,v 1.12 2007/10/26 08:33:11 amodigli Exp $
+ *
+ * This file is part of the SINFONI Pipeline
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2007/10/26 08:33:11 $
+ * $Revision: 1.12 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+/*-----------------------------------------------------------------------------
+                                Includes
+ -----------------------------------------------------------------------------*/
+
+/* cpl */
+#include <cpl.h>
+/* irplib */
+#include <irplib_utils.h>
+
+#include <sinfo_tpl_utils.h>
+#include <sinfo_pfits.h>
+#include <sinfo_tpl_dfs.h>
+#include <sinfo_utl_cube2spectrum.h>
+#include <sinfo_msg.h>
+/*-----------------------------------------------------------------------------
+                            Functions prototypes
+ -----------------------------------------------------------------------------*/
+
+static int sinfo_utl_cube2spectrum_create(cpl_plugin *) ;
+static int sinfo_utl_cube2spectrum_exec(cpl_plugin *) ;
+static int sinfo_utl_cube2spectrum_destroy(cpl_plugin *) ;
+
+/*-----------------------------------------------------------------------------
+                            Static variables
+ -----------------------------------------------------------------------------*/
+
+static char sinfo_utl_cube2spectrum_description[] =
+"This recipe performs cube to 1D spectrum image conversion.\n"
+"The input files is a cube\n"
+"Its associated tag should be CUBE.\n"
+"The output is an image resulting from the cube manipulated \n"
+"according to the value of op\n"
+"Over an aperture as specified by the parameter \n"
+"sinfoni.sinfo_utl_cube2spectrum.aperture having alias 'op', 'ap'"
+"Information on relevant parameters can be found with\n"
+"esorex --params sinfo_utl_cube2spectrum\n"
+"esorex --help sinfo_utl_cube2spectrum\n"
+"\n";
+
+/*-----------------------------------------------------------------------------
+                                Functions code
+ ----------------------------------------------------------------------------*/
+/*---------------------------------------------------------------------------*/
+/**
+ * @defgroup sinfo_utl_cube2spectrum  Recipe to collapse a cube in a spectrum
+ */
+/*---------------------------------------------------------------------------*/
+
+/**@{*/
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Build the list of available plugins, for this module. 
+  @param    list    the plugin list
+  @return   0 if everything is ok
+
+  This function is exported.
+ */
+/*---------------------------------------------------------------------------*/
+int cpl_plugin_get_info(cpl_pluginlist * list)
+{
+    cpl_recipe  *   recipe = cpl_calloc(1, sizeof *recipe ) ;
+    cpl_plugin  *   plugin = &recipe->interface ;
+
+    cpl_plugin_init(plugin,
+                    CPL_PLUGIN_API,
+                    SINFONI_BINARY_VERSION,
+                    CPL_PLUGIN_TYPE_RECIPE,
+                    "sinfo_utl_cube2spectrum",
+                    "Collapse a cube to an image over an aperture",
+                    sinfo_utl_cube2spectrum_description,
+                    "Andrea Modigliani",
+                    "Andrea.Modigliani at eso.org",
+                    sinfo_get_license(),
+                    sinfo_utl_cube2spectrum_create,
+                    sinfo_utl_cube2spectrum_exec,
+                    sinfo_utl_cube2spectrum_destroy) ;
+
+    cpl_pluginlist_append(list, plugin) ;
+    
+    return 0;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Setup the recipe options    
+  @param    plugin  the plugin
+  @return   0 if everything is ok
+
+  Create the recipe instance and make it available to the application using the 
+  interface. 
+ */
+/*---------------------------------------------------------------------------*/
+static int sinfo_utl_cube2spectrum_create(cpl_plugin * plugin)
+{
+    cpl_recipe      * recipe ;
+    cpl_parameter   * p ;
+
+    /* Get the recipe out of the plugin */
+    if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+        recipe = (cpl_recipe *)plugin ;
+    else return -1 ;
+    cpl_error_reset();
+    irplib_reset();
+
+    /* Create the parameters list in the cpl_recipe object */
+    recipe->parameters = cpl_parameterlist_new() ; 
+
+    /* Fill the parameters list */
+    /* --stropt */
+    p = cpl_parameter_new_value("sinfoni.sinfo_utl_cube2spectrum.op", 
+            CPL_TYPE_STRING, "A possible operation:"
+            " average, clean_mean, median, sum", 
+            "sinfoni.sinfo_utl_cube2spectrum","average");
+    cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "op") ;
+    cpl_parameterlist_append(recipe->parameters, p) ;
+
+
+     /* --stropt */
+    p = cpl_parameter_new_value("sinfoni.sinfo_utl_cube2spectrum.ap", 
+            CPL_TYPE_STRING, "A possible aperture: rectangle, circle", 
+            "sinfoni.sinfo_utl_cube2spectrum","rectangle");
+    cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "ap") ;
+    cpl_parameterlist_append(recipe->parameters, p) ;
+
+
+    /* --doubleopt */
+    p = cpl_parameter_new_value("sinfoni.sinfo_utl_cube2spectrum.llx", 
+                                CPL_TYPE_INT, 
+                                "Lower left X rectangle coordinate", 
+                                "sinfoni.sinfo_utl_cube2spectrum", 2) ;
+    cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "llx") ;
+    cpl_parameterlist_append(recipe->parameters, p) ;
+
+
+    p = cpl_parameter_new_value("sinfoni.sinfo_utl_cube2spectrum.lly", 
+                                CPL_TYPE_INT, 
+                                "Lower left Y rectangle coordinate", 
+                                "sinfoni.sinfo_utl_cube2spectrum", 2) ;
+    cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "lly") ;
+    cpl_parameterlist_append(recipe->parameters, p) ;
+
+
+    p = cpl_parameter_new_value("sinfoni.sinfo_utl_cube2spectrum.urx", 
+            CPL_TYPE_INT, "Upper right X rectangle coordinate", 
+                                "sinfoni.sinfo_utl_cube2spectrum", 28) ;
+    cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "urx") ;
+    cpl_parameterlist_append(recipe->parameters, p) ;
+
+
+    p = cpl_parameter_new_value("sinfoni.sinfo_utl_cube2spectrum.ury", 
+                                CPL_TYPE_INT, 
+                                "Upper right Y rectangle coordinate", 
+                                "sinfoni.sinfo_utl_cube2spectrum", 28) ;
+    cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "ury") ;
+    cpl_parameterlist_append(recipe->parameters, p) ;
+
+
+
+    p = cpl_parameter_new_value("sinfoni.sinfo_utl_cube2spectrum.lo_rej", 
+                                CPL_TYPE_INT, 
+                                "Clean mean low rejection", 
+                                "sinfoni.sinfo_utl_cube2spectrum", 10) ;
+    cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "lo_rej") ;
+    cpl_parameterlist_append(recipe->parameters, p) ;
+
+
+    p = cpl_parameter_new_value("sinfoni.sinfo_utl_cube2spectrum.hi_rej", 
+                                CPL_TYPE_INT, 
+                                "Clean mean low rejection", 
+                                "sinfoni.sinfo_utl_cube2spectrum", 10) ;
+    cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "hi_rej") ;
+    cpl_parameterlist_append(recipe->parameters, p) ;
+
+
+
+    p = cpl_parameter_new_value("sinfoni.sinfo_utl_cube2spectrum.centerx", 
+                                CPL_TYPE_INT, 
+                                "Circle center X coordinate", 
+                                "sinfoni.sinfo_utl_cube2spectrum", 16) ;
+    cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "centerx") ;
+    cpl_parameterlist_append(recipe->parameters, p) ;
+
+
+    p = cpl_parameter_new_value("sinfoni.sinfo_utl_cube2spectrum.centery", 
+                                CPL_TYPE_INT, 
+                                "Circle center Y coordinate", 
+                                "sinfoni.sinfo_utl_cube2spectrum", 16) ;
+    cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "centery") ;
+    cpl_parameterlist_append(recipe->parameters, p) ;
+
+
+    p = cpl_parameter_new_value("sinfoni.sinfo_utl_cube2spectrum.radius", 
+                                CPL_TYPE_INT, "Circle radii", 
+                                "sinfoni.sinfo_utl_cube2spectrum", 5) ;
+    cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "radius") ;
+    cpl_parameterlist_append(recipe->parameters, p) ;
+
+ 
+    /* Return */
+    return 0;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Execute the plugin instance given by the interface
+  @param    plugin  the plugin
+  @return   0 if everything is ok
+ */
+/*---------------------------------------------------------------------------*/
+static int sinfo_utl_cube2spectrum_exec(cpl_plugin * plugin)
+{
+    cpl_recipe  *   recipe ;
+    int result=0;
+    cpl_errorstate initial_errorstate = cpl_errorstate_get();
+
+    /* Get the recipe out of the plugin */
+    if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+        recipe = (cpl_recipe *)plugin ;
+    else return -1 ;
+
+    if(sinfo_dfs_set_groups(recipe->frames)) {
+       sinfo_msg_error( "Cannot indentify RAW and CALIB frames") ;
+       return -1;
+    }
+      sinfo_msg("Welcome to SINFONI Pipeline release %d.%d.%d",
+        SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
+
+    result = sinfo_utl_cube2spectrum(recipe->parameters, recipe->frames,NULL);
+    if (!cpl_errorstate_is_equal(initial_errorstate)) {                      
+        /* Dump the error history since recipe execution start.                
+           At this point the recipe cannot recover from the error */           
+        cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);              
+    } 
+
+    return result;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Destroy what has been created by the 'create' function
+  @param    plugin  the plugin
+  @return   0 if everything is ok
+ */
+/*----------------------------------------------------------------------------*/
+static int sinfo_utl_cube2spectrum_destroy(cpl_plugin * plugin)
+{
+    cpl_recipe  *   recipe ;
+
+    /* Get the recipe out of the plugin */
+    if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+        recipe = (cpl_recipe *)plugin ;
+    else return -1 ;
+
+    cpl_parameterlist_delete(recipe->parameters) ; 
+    return 0 ;
+}
+
+/**@}*/
diff --git a/recipes/sinfo_utl_cube_arith.c b/recipes/sinfo_utl_cube_arith.c
new file mode 100644
index 0000000..42aad66
--- /dev/null
+++ b/recipes/sinfo_utl_cube_arith.c
@@ -0,0 +1,231 @@
+/* $Id: sinfo_utl_cube_arith.c,v 1.10 2007/10/26 09:40:28 amodigli Exp $
+ *
+ * This file is part of the SINFONI Pipeline
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2007/10/26 09:40:28 $
+ * $Revision: 1.10 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+/*-----------------------------------------------------------------------------
+                                Includes
+ ----------------------------------------------------------------------------*/
+#include <string.h>
+
+/* cpl */
+#include <cpl.h>
+/* irplib */
+#include <irplib_utils.h>
+
+#include <sinfo_tpl_utils.h>
+#include <sinfo_pfits.h>
+#include <sinfo_tpl_dfs.h>
+#include <sinfo_utl_cube_arith.h>
+#include <sinfo_msg.h>
+
+/*-----------------------------------------------------------------------------
+                            Functions prototypes
+ ----------------------------------------------------------------------------*/
+
+static int sinfo_utl_cube_arith_create(cpl_plugin *) ;
+static int sinfo_utl_cube_arith_exec(cpl_plugin *) ;
+static int sinfo_utl_cube_arith_destroy(cpl_plugin *) ;
+
+/*-----------------------------------------------------------------------------
+                            Static variables
+ ----------------------------------------------------------------------------*/
+
+static char sinfo_utl_cube_arith_description1[] =
+"This recipe perform cube arithmetics.\n"
+"If parameter value is specified the input frame is a cube \n"
+"in a sof file with tag CUBE\n"
+"Else the input files are a cube and an images or a spectrum\n"
+"their associated tags should be respectively CUBE, IMA or SPECTRUM.\n"
+"The output is a cube with tag PRO_CUBE resulting from the operation \n"
+"CUBE op IMA or \n"
+"CUBE op SPECTRUM or\n"
+"CUBE op value where op indicates\n"
+"the operation to be performed\n";
+
+
+static char sinfo_utl_cube_arith_description2[] =
+"Information on relevant parameters can be found with\n"
+"esorex --params sinfo_utl_cube_arith\n"
+"esorex --help sinfo_utl_cube_arith\n"
+"\n";
+
+static char sinfo_utl_cube_arith_description[600];
+
+
+
+/*-----------------------------------------------------------------------------
+                                Functions code
+ ----------------------------------------------------------------------------*/
+/*---------------------------------------------------------------------------*/
+/**
+ * @defgroup sinfo_utl_cube_arith  Recipe for cube arithmetics
+ */
+/*---------------------------------------------------------------------------*/
+/**@{*/
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Build the list of available plugins, for this module. 
+  @param    list    the plugin list
+  @return   0 if everything is ok
+
+  This function is exported.
+ */
+/*---------------------------------------------------------------------------*/
+int cpl_plugin_get_info(cpl_pluginlist * list)
+{
+    cpl_recipe  *   recipe = cpl_calloc(1, sizeof *recipe ) ;
+    cpl_plugin  *   plugin = &recipe->interface ;
+
+    strcpy(sinfo_utl_cube_arith_description,sinfo_utl_cube_arith_description1);
+    strcat(sinfo_utl_cube_arith_description,sinfo_utl_cube_arith_description2);
+
+    cpl_plugin_init(plugin,
+                    CPL_PLUGIN_API,
+                    SINFONI_BINARY_VERSION,
+                    CPL_PLUGIN_TYPE_RECIPE,
+                    "sinfo_utl_cube_arith",
+                    "Cube arithmetics",
+                    sinfo_utl_cube_arith_description,
+                    "Andrea Modigliani",
+                    "Andrea.Modigliani at eso.org",
+                    sinfo_get_license(),
+                    sinfo_utl_cube_arith_create,
+                    sinfo_utl_cube_arith_exec,
+                    sinfo_utl_cube_arith_destroy) ;
+
+    cpl_pluginlist_append(list, plugin) ;
+    
+    return 0;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Setup the recipe options    
+  @param    plugin  the plugin
+  @return   0 if everything is ok
+
+  Create the recipe instance and make it available to the application using 
+  the interface. 
+ */
+/*---------------------------------------------------------------------------*/
+static int sinfo_utl_cube_arith_create(cpl_plugin * plugin)
+{
+    cpl_recipe      * recipe ;
+    cpl_parameter   * p ;
+
+    /* Get the recipe out of the plugin */
+    if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+        recipe = (cpl_recipe *)plugin ;
+    else return -1 ;
+    cpl_error_reset();
+    irplib_reset();
+    /* Create the parameters list in the cpl_recipe object */
+    recipe->parameters = cpl_parameterlist_new() ; 
+
+    /* Fill the parameters list */
+    /* --stropt */
+    p = cpl_parameter_new_value("sinfoni.sinfo_utl_cube_arith.op", 
+                                CPL_TYPE_STRING, 
+                                "A possible operation: "
+                                "`/','*','+' or `-'", 
+                                "sinfoni.sinfo_utl_cube_arith","/");
+    cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "op") ;
+    cpl_parameterlist_append(recipe->parameters, p) ;
+
+
+    /* --doubleopt */
+    /*
+    p = cpl_parameter_new_value("sinfoni.sinfo_utl_cube_arith.temperature", 
+                                 CPL_TYPE_DOUBLE, "Black Body Temperature", 
+                                 "sinfoni.sinfo_utl_cube_arith", 100000.) ;
+    cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "temp") ;
+    cpl_parameterlist_append(recipe->parameters, p) ;
+    */
+
+    p = cpl_parameter_new_value("sinfoni.sinfo_utl_cube_arith.value", 
+                                CPL_TYPE_DOUBLE, "A constant to add", 
+                                "sinfoni.sinfo_utl_cube_arith", 99999.0) ;
+    cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "value") ;
+    cpl_parameterlist_append(recipe->parameters, p) ;
+ 
+    /* Return */
+    return 0;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Execute the plugin instance given by the interface
+  @param    plugin  the plugin
+  @return   0 if everything is ok
+ */
+/*---------------------------------------------------------------------------*/
+static int sinfo_utl_cube_arith_exec(cpl_plugin * plugin)
+{
+    cpl_recipe  *   recipe ;
+    int code=0;
+    cpl_errorstate initial_errorstate = cpl_errorstate_get();
+
+    /* Get the recipe out of the plugin */
+    if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+        recipe = (cpl_recipe *)plugin ;
+    else return -1 ;
+      sinfo_msg("Welcome to SINFONI Pipeline release %d.%d.%d",
+        SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
+
+    code = sinfo_utl_cube_arith(recipe->parameters, recipe->frames) ;
+
+    if (!cpl_errorstate_is_equal(initial_errorstate)) {                      
+        /* Dump the error history since recipe execution start.                
+           At this point the recipe cannot recover from the error */           
+        cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);              
+    } 
+    return code;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Destroy what has been created by the 'create' function
+  @param    plugin  the plugin
+  @return   0 if everything is ok
+ */
+/*---------------------------------------------------------------------------*/
+static int sinfo_utl_cube_arith_destroy(cpl_plugin * plugin)
+{
+    cpl_recipe  *   recipe ;
+
+    /* Get the recipe out of the plugin */
+    if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+        recipe = (cpl_recipe *)plugin ;
+    else return -1 ;
+
+    cpl_parameterlist_delete(recipe->parameters) ; 
+    return 0 ;
+}
+/**@}*/
diff --git a/recipes/sinfo_utl_cube_combine.c b/recipes/sinfo_utl_cube_combine.c
new file mode 100644
index 0000000..2a51c13
--- /dev/null
+++ b/recipes/sinfo_utl_cube_combine.c
@@ -0,0 +1,248 @@
+/* $Id: sinfo_utl_cube_combine.c,v 1.12 2007/10/26 09:40:28 amodigli Exp $
+ *
+ * This file is part of the SINFONI Pipeline
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2007/10/26 09:40:28 $
+ * $Revision: 1.12 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+/*-----------------------------------------------------------------------------
+                                Includes
+ ----------------------------------------------------------------------------*/
+
+/* cpl */
+#include <cpl.h>
+
+/* irplib */
+#include <irplib_utils.h>
+
+#include <sinfo_tpl_utils.h>
+#include <sinfo_pfits.h>
+#include <sinfo_tpl_dfs.h>
+#include <sinfo_msg.h>
+#include <sinfo_utl_cube_combine.h>
+
+/*-----------------------------------------------------------------------------
+                            Functions prototypes
+ ----------------------------------------------------------------------------*/
+
+static int sinfo_utl_cube_combine_create(cpl_plugin *) ;
+static int sinfo_utl_cube_combine_exec(cpl_plugin *) ;
+static int sinfo_utl_cube_combine_destroy(cpl_plugin *) ;
+
+/*-----------------------------------------------------------------------------
+                            Static variables
+ ----------------------------------------------------------------------------*/
+
+static char sinfo_utl_cube_combine_description[] =
+"This recipe perform cubes combination.\n"
+"The input files are several cubeses\n"
+"their associated tags should be the same that is supported by the \n"
+"recipe sinfo_rec_jitter: OBS_OBJ, OBS_STD, OBS_PSF.\n"
+"The output is a cube PRO_CUBE resulting from the input cubes accurding \n"
+"to the value of op, where op indicates\n"
+"the operation to be performed specified by the parameter \n"
+"sinfoni.sinfo_utl_cube_combine.op\n"
+" having alias 'op'\n"
+"Information on relevant parameters can be found with\n"
+"esorex --params sinfo_utl_cube_combine\n"
+"esorex --help sinfo_utl_cube_combine\n"
+"\n";
+
+/*-----------------------------------------------------------------------------
+                                Functions code
+ ----------------------------------------------------------------------------*/
+/*---------------------------------------------------------------------------*/
+/**
+ * @defgroup sinfo_utl_cube_combine  Recipe to coadd cubes
+ */
+/*---------------------------------------------------------------------------*/
+
+/**@{*/
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Build the list of available plugins, for this module. 
+  @param    list    the plugin list
+  @return   0 if everything is ok
+
+  This function is exported.
+ */
+/*---------------------------------------------------------------------------*/
+int cpl_plugin_get_info(cpl_pluginlist * list)
+{
+    cpl_recipe  *   recipe = cpl_calloc(1, sizeof *recipe ) ;
+    cpl_plugin  *   plugin = &recipe->interface ;
+
+    cpl_plugin_init(plugin,
+                    CPL_PLUGIN_API,
+                    SINFONI_BINARY_VERSION,
+                    CPL_PLUGIN_TYPE_RECIPE,
+                    "sinfo_utl_cube_combine",
+                    "Coadd cubes in an output cube according "
+                    "to user defined offsets",
+                    sinfo_utl_cube_combine_description,
+                    "Andrea Modigliani",
+                    "Andrea.Modigliani at eso.org",
+                    sinfo_get_license(),
+                    sinfo_utl_cube_combine_create,
+                    sinfo_utl_cube_combine_exec,
+                    sinfo_utl_cube_combine_destroy) ;
+
+    cpl_pluginlist_append(list, plugin) ;
+    
+    return 0;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Setup the recipe options    
+  @param    plugin  the plugin
+  @return   0 if everything is ok
+
+  Create the recipe instance and make it available to the application using the 
+  interface. 
+ */
+/*---------------------------------------------------------------------------*/
+static int sinfo_utl_cube_combine_create(cpl_plugin * plugin)
+{
+    cpl_recipe      * recipe ;
+    cpl_parameter   * p ;
+
+    /* Get the recipe out of the plugin */
+    if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+        recipe = (cpl_recipe *)plugin ;
+    else return -1 ;
+    cpl_error_reset();
+    irplib_reset();
+
+    /* Create the parameters list in the cpl_recipe object */
+    recipe->parameters = cpl_parameterlist_new() ; 
+
+    /* Fill the parameters list */
+    /* --stropt */
+    p = cpl_parameter_new_value("sinfoni.sinfo_utl_cube_combine.name_i", 
+            CPL_TYPE_STRING, 
+         "Input filename. This must be provided and allow the user to set X "
+         "and Y cumulative offsets in a two column format", 
+         "sinfoni.sinfo_utl_cube_combine","offset.list");
+    cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "name_i") ;
+    cpl_parameterlist_append(recipe->parameters, p) ;
+
+    p = cpl_parameter_new_value("sinfoni.sinfo_utl_cube_combine.name_o", 
+            CPL_TYPE_STRING, "Output filename", 
+             "sinfoni.sinfo_utl_cube_combine","out_coadd_cube.fits");
+    cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "name_o") ;
+    cpl_parameterlist_append(recipe->parameters, p) ;
+
+
+    p = cpl_parameter_new_value("sinfoni.sinfo_utl_cube_combine.ks_clip", 
+            CPL_TYPE_BOOL, "Kappa sigma clipping", 
+            "sinfoni.sinfo_utl_cube_combine",FALSE);
+    cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "ks_clip") ;
+    cpl_parameterlist_append(recipe->parameters, p) ;
+
+    p = cpl_parameter_new_value("sinfoni.sinfo_utl_cube_combine.scale_sky", 
+            CPL_TYPE_BOOL, "Scale spatial mean", 
+            "sinfoni.sinfo_utl_cube_combine",FALSE);
+    cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "scale_sky") ;
+    cpl_parameterlist_append(recipe->parameters, p) ;
+
+    p = cpl_parameter_new_value("sinfoni.sinfo_utl_cube_combine.kappa", 
+            CPL_TYPE_DOUBLE, "Kappa value for sigma clip", 
+            "sinfoni.sinfo_utl_cube_combine",2.);
+    cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "kappa") ;
+    cpl_parameterlist_append(recipe->parameters, p) ;
+
+
+    /* --doubleopt */
+    p = cpl_parameter_new_value("sinfoni.sinfo_utl_cube_combine.xsize", 
+            CPL_TYPE_INT, "Output cube X size", 
+            "sinfoni.sinfo_utl_cube_combine", 80) ;
+    cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "xsize") ;
+    cpl_parameterlist_append(recipe->parameters, p) ;
+
+
+    p = cpl_parameter_new_value("sinfoni.sinfo_utl_cube_combine.ysize", 
+            CPL_TYPE_INT, "Output cube Y size", 
+            "sinfoni.sinfo_utl_cube_combine", 80) ;
+    cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "ysize") ;
+    cpl_parameterlist_append(recipe->parameters, p) ;
+
+  
+    /* Return */
+    return 0;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Execute the plugin instance given by the interface
+  @param    plugin  the plugin
+  @return   0 if everything is ok
+ */
+/*---------------------------------------------------------------------------*/
+static int sinfo_utl_cube_combine_exec(cpl_plugin * plugin)
+{
+    cpl_recipe  *   recipe ;
+    int result=0;    
+    cpl_errorstate initial_errorstate = cpl_errorstate_get();
+
+    /* Get the recipe out of the plugin */
+    if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+        recipe = (cpl_recipe *)plugin ;
+    else return -1 ;
+       sinfo_msg("Welcome to SINFONI Pipeline release %d.%d.%d",
+        SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
+
+    result=sinfo_utl_cube_combine(recipe->parameters, recipe->frames) ;
+    if (!cpl_errorstate_is_equal(initial_errorstate)) {                      
+        /* Dump the error history since recipe execution start.                
+           At this point the recipe cannot recover from the error */           
+        cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);              
+    } 
+    return result;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Destroy what has been created by the 'create' function
+  @param    plugin  the plugin
+  @return   0 if everything is ok
+ */
+/*---------------------------------------------------------------------------*/
+static int sinfo_utl_cube_combine_destroy(cpl_plugin * plugin)
+{
+    cpl_recipe  *   recipe ;
+    
+    /* Get the recipe out of the plugin */
+    if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+        recipe = (cpl_recipe *)plugin ;
+    else return -1 ;
+
+    cpl_parameterlist_delete(recipe->parameters) ; 
+    return 0 ;
+}
+
+/**@}*/
diff --git a/recipes/sinfo_utl_cube_create.c b/recipes/sinfo_utl_cube_create.c
new file mode 100644
index 0000000..fb27e22
--- /dev/null
+++ b/recipes/sinfo_utl_cube_create.c
@@ -0,0 +1,676 @@
+/* $Id: sinfo_utl_cube_create.c,v 1.5 2008/08/29 11:34:03 amodigli Exp $
+ *
+ * This file is part of the SINFONI Pipeline
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2008/08/29 11:34:03 $
+ * $Revision: 1.5 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+/*-----------------------------------------------------------------------------
+                                Includes
+ ----------------------------------------------------------------------------*/
+
+
+/* cpl */
+#include <cpl.h>
+
+/* irplib */
+#include <irplib_utils.h>
+
+#include <sinfo_tpl_utils.h>
+#include <sinfo_pfits.h>
+#include <sinfo_tpl_dfs.h>
+#include <sinfo_msg.h>
+#include <sinfo_error.h>
+#include <sinfo_utils_wrappers.h>
+#include <sinfo_image_ops.h>
+#include <sinfo_wave_calibration.h>
+#include <sinfo_pro_save.h>
+#include <sinfo_raw_types.h>
+#include <sinfo_pro_types.h>
+#include <sinfo_coltilt.h>
+#include <sinfo_utilities_scired.h>
+/*-----------------------------------------------------------------------------
+                            Functions prototypes
+ ----------------------------------------------------------------------------*/
+
+static int sinfo_utl_cube_create_create(cpl_plugin *) ;
+static int sinfo_utl_cube_create_exec(cpl_plugin *) ;
+static int sinfo_utl_cube_create_destroy(cpl_plugin *) ;
+
+static int 
+sinfo_cube_create(cpl_parameterlist * parameters, cpl_frameset * frames);
+
+/*-----------------------------------------------------------------------------
+                            Static variables
+ ----------------------------------------------------------------------------*/
+
+static char sinfo_utl_cube_create_description[] =
+"This recipe perform cubes creation.\n"
+"The input files are:\n"
+"A raw frame on tagged as RAW_ON\n"
+"[optional] A raw frame off RAW_OFF\n"
+"A wavelength map, tagged as WAVE_MAP\n"
+"A wavelength map, tagged as WAVE_MAP\n"
+"A distortion table, tagged as DISTORTION\n"
+"A slitlets position table, tagged as SLIT_POS\n"
+"Information on relevant parameters can be found with\n"
+"esorex --params sinfo_utl_cube_create\n"
+"esorex --help sinfo_utl_cube_create\n"
+"\n";
+
+/*-----------------------------------------------------------------------------
+                                Functions code
+ ----------------------------------------------------------------------------*/
+/*---------------------------------------------------------------------------*/
+/**
+ * @defgroup sinfo_utl_cube_create  Recipe to coadd cubes
+ */
+/*---------------------------------------------------------------------------*/
+
+/**@{*/
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Build the list of available plugins, for this module. 
+  @param    list    the plugin list
+  @return   0 if everything is ok
+
+  This function is exported.
+ */
+/*---------------------------------------------------------------------------*/
+int cpl_plugin_get_info(cpl_pluginlist * list)
+{
+    cpl_recipe  *   recipe = cpl_calloc(1, sizeof *recipe ) ;
+    cpl_plugin  *   plugin = &recipe->interface ;
+
+    cpl_plugin_init(plugin,
+                    CPL_PLUGIN_API,
+                    SINFONI_BINARY_VERSION,
+                    CPL_PLUGIN_TYPE_RECIPE,
+                    "sinfo_utl_cube_create",
+                    "Generate a cube",
+                    sinfo_utl_cube_create_description,
+                    "Andrea Modigliani",
+                    "Andrea.Modigliani at eso.org",
+                    sinfo_get_license(),
+                    sinfo_utl_cube_create_create,
+                    sinfo_utl_cube_create_exec,
+                    sinfo_utl_cube_create_destroy) ;
+
+    cpl_pluginlist_append(list, plugin) ;
+    
+    return 0;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Setup the recipe options    
+  @param    plugin  the plugin
+  @return   0 if everything is ok
+
+  Create the recipe instance and make it available to the application using the 
+  interface. 
+ */
+/*---------------------------------------------------------------------------*/
+static int sinfo_utl_cube_create_create(cpl_plugin * plugin)
+{
+    cpl_recipe      * recipe ;
+    cpl_parameter   * p ;
+    cpl_parameterlist   * list ;
+
+    /* Get the recipe out of the plugin */
+    if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+        recipe = (cpl_recipe *)plugin ;
+    else return -1 ;
+    cpl_error_reset();
+    irplib_reset();
+
+    /* Create the parameters list in the cpl_recipe object */
+    recipe->parameters = cpl_parameterlist_new() ; 
+
+    list=recipe->parameters;
+  /* jitter mode indicator: yes: Auto-Jitter, no: user defined jitter
+     The next three parameters are only used if jitterInd is set to yes, 
+     that means in auto-jittering mode!
+  */
+  p = cpl_parameter_new_value("sinfoni.objnod.jitter_index",
+                  CPL_TYPE_BOOL,
+                              "jitter mode indicator: "
+                              "TRUE: Auto-Jitter, "
+                              "FALSE: user defined jitter. "
+                              "The size_x size_y kernel_type parameters "
+                              "are only used if jitterInd is set to yes, "
+                              "that means in auto-jittering mode.",
+                              "sinfoni.objnod",
+                              TRUE);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"objnod-jit_ind");
+  cpl_parameterlist_append(list, p);
+
+
+  /* Kernel Type */
+  /* the name of the interpolation kernel to shift the single cubes  to the 
+     correct places inside the big combined cube. That you want to generate 
+     using the eclipse routine sinfo_generate_interpolation_kernel()
+     Supported kernels are:
+
+                                     NULL:      default kernel, currently tanh
+                                     default: dito
+                                     tanh:    Hyperbolic tangent
+                                     sinc2:   Square sinc
+                                     lanczos: Lanczos2 kernel
+                                     hamming: Hamming kernel
+                                     hann:    Hann kernel
+  */
+  p = cpl_parameter_new_enum("sinfoni.objnod.kernel_type",
+                  CPL_TYPE_STRING,
+                              "Kernel Type:"
+                              "the name of the interpolation kernel to shift "
+                              "the single cubes  to the correct places inside "
+                             "the big combined cube",
+                              "sinfoni.objnod",
+                              "tanh",
+                               7,
+                              "NULL","default","tanh","sinc2",
+                              "lanczos","hamming","hann");
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"objnod-kernel_typ");
+  cpl_parameterlist_append(list, p);
+
+  /*Resampling */
+ /* number of coefficients for the polynomial interpolation */
+  p = cpl_parameter_new_value("sinfoni.objnod.n_coeffs",
+                  CPL_TYPE_INT,
+                              "number of coefficients for the polynomial "
+                              "interpolation ",
+                              "sinfoni.objnod",
+                               3);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"objnod-no_coeffs");
+  cpl_parameterlist_append(list, p);
+
+  /* Cube Creation */
+  /*indicates if the slitlet distances are determined by a north-south-test 
+     (yes) or slitlet edge fits (no)
+  */
+  p = cpl_parameter_new_value("sinfoni.objnod.nord_south_index",
+                  CPL_TYPE_BOOL,
+                              "Nord South Index Switch: "
+                              "indicates if the slitlet distances are "
+                              "determined by a north-south-test (TRUE) "
+                              "or slitlet edge fits (FALSE)",
+                              "sinfoni.objnod",
+                              TRUE);
+
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"objnod-ns_ind");
+  cpl_parameterlist_append(list, p);
+
+
+  /* Cube Creation */
+  /*indicates if the slitlet distances are determined by a north-south-test 
+     (yes) or slitlet edge fits (no)
+  */
+  p = cpl_parameter_new_value("sinfoni.objnod.flux_cor",
+                              CPL_TYPE_BOOL,
+                              "Flux correction: ",
+                              "sinfoni.objnod",
+                              FALSE);
+
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"objnod-flux_cor");
+  cpl_parameterlist_append(list, p);
+
+
+
+
+ /* Fine tuning */
+  /* Method */
+  p = cpl_parameter_new_enum("sinfoni.objnod.fine_tuning_method",
+                  CPL_TYPE_STRING,
+                              "Fine Tuning Method: "
+                              "indicator for the shifting method to use "
+                              "(P: polynomial interpolation, "
+                 /* " F: FFT, " */
+                              " S: cubic spline interpolation)",
+                              "sinfoni.objnod",
+                              "P",
+                               2,
+                              "P","S");
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"objnod-fine_tune_mtd");
+  cpl_parameterlist_append(list, p);
+
+  p = cpl_parameter_new_value("sinfoni.objnod.order",
+                  CPL_TYPE_INT,
+                              "Fine Tuning polynomial order: " 
+                              "order of the polynomial if the polynomial "
+                              "interpolation shifting method is used.",
+                              "sinfoni.objnod",
+                              2);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"objnod-order");
+  cpl_parameterlist_append(list, p);
+
+    /* Fill the parameters list */
+    /* --stropt */
+
+  
+    /* Return */
+    return 0;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Execute the plugin instance given by the interface
+  @param    plugin  the plugin
+  @return   0 if everything is ok
+ */
+/*---------------------------------------------------------------------------*/
+static int sinfo_utl_cube_create_exec(cpl_plugin * plugin)
+{
+    cpl_recipe  *   recipe ;
+    int result=0;    
+    cpl_errorstate initial_errorstate = cpl_errorstate_get();
+
+    /* Get the recipe out of the plugin */
+    if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+        recipe = (cpl_recipe *)plugin ;
+    else return -1 ;
+       sinfo_msg("Welcome to SINFONI Pipeline release %d.%d.%d",
+        SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
+
+    result=sinfo_cube_create(recipe->parameters, recipe->frames) ;
+    if (!cpl_errorstate_is_equal(initial_errorstate)) {                      
+        /* Dump the error history since recipe execution start.                
+           At this point the recipe cannot recover from the error */           
+        cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);              
+    } 
+    return result;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Destroy what has been created by the 'create' function
+  @param    plugin  the plugin
+  @return   0 if everything is ok
+ */
+/*---------------------------------------------------------------------------*/
+static int sinfo_utl_cube_create_destroy(cpl_plugin * plugin)
+{
+    cpl_recipe  *   recipe ;
+    
+    /* Get the recipe out of the plugin */
+    if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+        recipe = (cpl_recipe *)plugin ;
+    else return -1 ;
+
+    cpl_parameterlist_delete(recipe->parameters) ; 
+    return 0 ;
+}
+
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Create the cube
+  @param    parameters recipe input parameters
+  @param    frames recipe input frames
+  @return   0 if everything is ok
+ */
+/*---------------------------------------------------------------------------*/
+static int 
+sinfo_cube_create(cpl_parameterlist * parameters, cpl_frameset * frames)
+{
+
+   cpl_frame* frm_raw_on=NULL;
+   cpl_frame* frm_raw_off=NULL;
+   cpl_frame* frm_wav_map=NULL;
+   cpl_frame* frm_mflat=NULL;
+   cpl_frame* frm_distortion=NULL;
+   cpl_frame* frm_slit_pos=NULL;
+   cpl_frame* frm_slitlets_distance=NULL;
+
+   cpl_image* ima_raw_on=NULL;
+   cpl_image* ima_raw_off=NULL;
+   cpl_image* ima_wav_map=NULL;
+   cpl_image* ima_mflat=NULL;
+   cpl_image* ima_mflat_dist=NULL;
+   cpl_image* ima_obj_mflat=NULL;
+   cpl_image* ima_obj_dist=NULL;
+   cpl_image* ima_obj_res=NULL;
+   cpl_image* ima_wav_res=NULL;
+   cpl_image* ima_wav_dif=NULL;
+
+   cpl_imagelist* cube=NULL;
+   cpl_imagelist* outcube=NULL;
+   cpl_imagelist* outcube2=NULL;
+
+   //cpl_table* tab_distortion=NULL;
+   //cpl_table* tab_slit_pos=NULL;
+
+   float mi=0;
+   float ma=0;
+   double dis=0 ;
+   double cwav=0 ;
+   int cpix=0 ;
+   int nx=0;
+   int ny=0;
+    float fcol=0;
+   float* pd=NULL;
+   float* pw=NULL;
+   int i=0;
+   int j=0;
+   float** slit_edges=NULL;
+   float* distances=NULL;
+   float* correct_dist=NULL;
+   char kernel[80];
+   char poly_file[80];
+   char pos_list[80];
+   char dist_list[80];
+
+
+    int jit_ind=0;
+   int ns_index=0;
+   int n_coeffs=0;
+   int nrows=0;
+   cpl_parameter* p=NULL;
+   int nslits=32;
+   int flux_cor=0;
+   const char* fine_tuning_method=NULL;
+   int fine_tuning_pol_order=0;
+   float center_x=0;
+   float center_y=0;
+
+   /* Identify the RAW and CALIB frames in the input frameset */
+    check(sinfo_dfs_set_groups(frames),
+         "Cannot identify RAW and CALIB frames") ;
+
+   check_nomsg(p=cpl_parameterlist_find(parameters,
+                                        "sinfoni.objnod.flux_cor"));
+   check_nomsg(flux_cor=cpl_parameter_get_bool(p));
+
+   check_nomsg(p=cpl_parameterlist_find(parameters,
+                                        "sinfoni.objnod.jitter_index"));
+   check_nomsg(jit_ind=cpl_parameter_get_bool(p));
+
+   check_nomsg(p=cpl_parameterlist_find(parameters,
+                                        "sinfoni.objnod.kernel_type"));
+   check_nomsg(strcpy(kernel,cpl_parameter_get_string(p)));
+
+   check_nomsg(p=cpl_parameterlist_find(parameters,"sinfoni.objnod.n_coeffs"));
+   check_nomsg(n_coeffs=cpl_parameter_get_int(p));
+
+
+   check_nomsg(p=cpl_parameterlist_find(parameters,
+                                        "sinfoni.objnod.nord_south_index"));
+   check_nomsg(ns_index=cpl_parameter_get_bool(p));
+
+
+   check_nomsg(p=cpl_parameterlist_find(parameters,
+                                        "sinfoni.objnod.fine_tuning_method"));
+   check_nomsg(fine_tuning_method=cpl_parameter_get_string(p));
+
+   check_nomsg(p=cpl_parameterlist_find(parameters,
+                                        "sinfoni.objnod.order"));
+   check_nomsg(fine_tuning_pol_order=cpl_parameter_get_int(p));
+
+ 
+   cknull(frm_raw_on=cpl_frameset_find(frames,RAW_ON),
+          "Missing required input %s",RAW_ON);
+   cknull(frm_raw_off=cpl_frameset_find(frames,RAW_OFF),
+          "Missing required input %s",RAW_OFF);
+   cknull(frm_wav_map=cpl_frameset_find(frames,PRO_WAVE_MAP),
+                "Missing required input %s",PRO_WAVE_MAP);
+   cknull(frm_mflat=cpl_frameset_find(frames,PRO_MASTER_FLAT_LAMP),
+                "Missing required input %s",PRO_WAVE_MAP);
+
+   check_nomsg(frm_distortion=cpl_frameset_find(frames,PRO_DISTORTION));
+   check_nomsg(frm_slit_pos=cpl_frameset_find(frames,PRO_SLIT_POS));
+   check_nomsg(frm_slitlets_distance=
+               cpl_frameset_find(frames,PRO_SLITLETS_DISTANCE));
+
+   strcpy(pos_list,cpl_frame_get_filename(frm_slit_pos));
+   strcpy(dist_list,cpl_frame_get_filename(frm_slitlets_distance));
+   strcpy(poly_file,cpl_frame_get_filename(frm_distortion));
+
+ 
+   check_nomsg(ima_raw_on=cpl_image_load(cpl_frame_get_filename(frm_raw_on),
+                                         CPL_TYPE_FLOAT,0,0));
+ 
+   check_nomsg(ima_raw_off=cpl_image_load(cpl_frame_get_filename(frm_raw_off),
+                                          CPL_TYPE_FLOAT,0,0));
+
+ 
+   check_nomsg(ima_wav_map=cpl_image_load(cpl_frame_get_filename(frm_wav_map),
+                                          CPL_TYPE_FLOAT,0,0));
+ 
+   check_nomsg(ima_mflat=cpl_image_load(cpl_frame_get_filename(frm_mflat),
+                                          CPL_TYPE_FLOAT,0,0));
+
+ 
+
+   check_nomsg(cpl_image_subtract(ima_raw_on,ima_raw_off));
+   cpl_image_save(ima_raw_on,"ima_sub.fits", CPL_BPP_IEEE_FLOAT, 
+                  NULL,CPL_IO_DEFAULT);
+
+   cknull_nomsg(ima_obj_mflat=sinfo_new_div_images_robust(ima_raw_on,
+                                                         ima_mflat));
+   cpl_image_save(ima_obj_mflat,"ima_obj_mflat.fits", CPL_BPP_IEEE_FLOAT, 
+                  NULL,CPL_IO_DEFAULT);
+ 
+
+//The following is not needed
+   cknull_nomsg(ima_mflat_dist=sinfo_new_image_warp_fits(ima_mflat,kernel,
+                                                         poly_file));
+
+   cpl_image_save(ima_mflat_dist,"ima_mflat_dist.fits", CPL_BPP_IEEE_FLOAT, 
+                  NULL,CPL_IO_DEFAULT);
+
+   cknull_nomsg(ima_obj_dist=sinfo_new_image_warp_fits(ima_obj_mflat, 
+                                                       kernel, 
+                                                       poly_file));
+
+   cpl_image_save(ima_obj_dist,"ima_obj_dist.fits", CPL_BPP_IEEE_FLOAT, 
+                  NULL,CPL_IO_DEFAULT);
+ 
+   cknull(ima_obj_res = sinfo_new_defined_resampling(ima_obj_dist, 
+						    ima_wav_map, 
+						    n_coeffs,
+						    &nrows,
+						    &dis,
+						    &mi,
+						    &ma,
+						    &cwav,
+						    &cpix),
+	     " sinfo_definedResampling() failed" ) ;
+
+
+
+  cpl_image_save(ima_obj_res,"ima_obj_res.fits", CPL_BPP_IEEE_FLOAT, 
+                  NULL,CPL_IO_DEFAULT);
+
+
+    //We create an image with the derivatives
+  nx=cpl_image_get_size_x(ima_wav_map);
+  ny=cpl_image_get_size_y(ima_wav_map);
+
+      check_nomsg(ima_wav_dif=cpl_image_new(nx,ny,CPL_TYPE_FLOAT));
+      pw=cpl_image_get_data(ima_wav_map);
+      pd=cpl_image_get_data(ima_wav_dif);
+
+    
+      for(i=1;i<nx-1;i++) {
+	for(j=1;j<ny-1;j++) {
+	  if(!isnan(pd[nx*j+i])) {
+	    pd[nx*j+i]=2.0*dis/(pw[nx*(j+1)+i]-pw[nx*(j-1)+i]);
+	  }
+	}
+	if(!isnan(pd[i])) {
+	  pd[i]=dis/(pw[nx+i]-pw[i]);
+	}
+	if(!isnan(pd[nx*(ny-1)+i])) {
+	  pd[nx*(ny-1)+i]=dis/(pw[nx*(ny-1)+i]-pw[nx*(ny-2)+i]);
+	}
+      }
+    
+
+      //cpl_image_save(ima_wav_dif,"diff.fits", 
+      //CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT);
+
+
+
+      cknull(ima_wav_res = sinfo_new_defined_resampling(ima_wav_dif, 
+						    ima_wav_map, 
+						    n_coeffs,
+						    &nrows,
+						    &dis,
+						    &mi,
+						    &ma,
+						    &cwav,
+						    &cpix),
+	     " sinfo_definedResampling() failed" ) ;
+
+      if(flux_cor) {
+	sinfo_msg("Apply flux correction");
+	cpl_image_divide(ima_obj_res,ima_wav_res);
+      }
+
+
+      //cpl_image_save(ima_wav_res,"res_diff.fits", 
+      //CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT);
+
+
+
+  cpl_image_save(ima_wav_res,"ima_wav_res.fits", CPL_BPP_IEEE_FLOAT, 
+                  NULL,CPL_IO_DEFAULT);
+
+
+      //To rescale in flux we divide the resampled image and 
+      //the resampled derivatives. At this point ima_obj_res should have same 
+      //flux as input image (im.diff)
+
+      //ima_obj_res=cpl_image_duplicate(ima_wav_res);
+      //sinfo_free_image(&ima_wav_res);
+      if(flux_cor) {
+	sinfo_msg("Apply flux correction");
+	cpl_image_divide(ima_obj_res,ima_wav_res);
+      }
+
+
+
+
+      /*---select north-south-test or fitting of slitlet edges--*/
+      if (ns_index == 0) {
+	sinfo_msg("cfg->northsouthInd == 0");
+	cknull(slit_edges=sinfo_read_slitlets_edges(nslits,pos_list),
+	       "error reading slitlets edges");
+      } else {
+	sinfo_msg("cfg->northsouthInd != 0");
+	cknull(distances = sinfo_read_distances(nslits,dist_list),
+	       "error reading distances");
+      }
+ 
+      cknull(correct_dist = (float*) cpl_calloc(nslits, sizeof (float)),
+	     " could not allocate memory!") ;
+
+      sinfo_msg("Create cube object");
+      if (ns_index ==0 ) {
+
+        cknull(cube = sinfo_new_make_cube_spi(ima_obj_res,slit_edges,
+					      correct_dist),
+	       "could not construct data cube!") ;
+
+      }  else {
+	cknull(cube = sinfo_new_make_cube_dist(ima_obj_res,fcol,distances,
+					       correct_dist),
+	       "could not construct a data cube!") ;
+      }
+      sinfo_free_image(&ima_obj_res);
+
+
+     cknull(outcube2=sinfo_new_fine_tune(cube,
+					  correct_dist,
+					  fine_tuning_method,
+					  fine_tuning_pol_order,
+					  nslits),
+	     " could not fine tune the data cube") ;
+
+      sinfo_msg("Stretch output cube along Y direction");
+      cknull(outcube = sinfo_new_bin_cube(outcube2,1,2,0,63,0,63),
+	     "Error binning cube");
+      sinfo_free_imagelist(&cube);
+
+      ck0(sinfo_pro_save_ims(outcube,frames,frames,"out_cube.fits","CUBE",NULL,
+                             "sinfo_utl_cube_create",parameters),
+          "cannot save cube %s", "out_cube.fits");
+
+
+      check_nomsg(center_x = cpl_image_get_size_x(
+						  cpl_imagelist_get(outcube,0))/2.+0.5) ;
+      check_nomsg(center_y = cpl_image_get_size_y(
+						  cpl_imagelist_get(outcube,0))/2.+0.5 );
+
+     sinfo_new_set_wcs_cube(outcube,"out_cube.fits", cwav, dis, 
+			     cpix, center_x, center_y);
+
+
+  cleanup:      
+
+    if (ns_index ==0 ) {
+      if(slit_edges != NULL) {
+	sinfo_new_destroy_2Dfloatarray(&slit_edges,nslits);
+      }
+    } else {
+      if (distances != NULL ) {
+	sinfo_new_destroy_array(&distances);
+      }
+    }
+
+
+
+   
+      sinfo_free_float(&correct_dist) ;
+      sinfo_free_imagelist(&cube);
+      sinfo_free_imagelist(&outcube);
+      sinfo_free_imagelist(&outcube2);
+      sinfo_free_image(&ima_raw_on);
+      sinfo_free_image(&ima_raw_off);
+      sinfo_free_image(&ima_wav_map);
+      sinfo_free_image(&ima_mflat);
+      sinfo_free_image(&ima_mflat_dist);
+      sinfo_free_image(&ima_obj_res);
+      sinfo_free_image(&ima_obj_mflat);
+      sinfo_free_image(&ima_obj_dist);
+      sinfo_free_image(&ima_obj_res);
+      sinfo_free_image(&ima_wav_res);
+      sinfo_free_image(&ima_wav_dif);
+    
+      return 0 ;
+
+}
+
+
+/**@}*/
diff --git a/recipes/sinfo_utl_eff.c b/recipes/sinfo_utl_eff.c
new file mode 100644
index 0000000..0c344d2
--- /dev/null
+++ b/recipes/sinfo_utl_eff.c
@@ -0,0 +1,299 @@
+/* $Id: sinfo_utl_eff.c,v 1.7 2010/02/18 19:14:41 amodigli Exp $
+ *
+ * This file is part of the SINFONI Pipeline
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2010/02/18 19:14:41 $
+ * $Revision: 1.7 $
+ * $Log: sinfo_utl_eff.c,v $
+ * Revision 1.7  2010/02/18 19:14:41  amodigli
+ * some bug fixes
+ *
+ * Revision 1.6  2010/02/08 07:14:34  amodigli
+ * changed sinfo_utl_efficiency API
+ *
+ * Revision 1.5  2009/12/15 15:07:32  kmirny
+ * efficiency update
+ *
+ * Revision 1.4  2009/07/27 12:37:43  amodigli
+ * removed parlist from sinfo_utl_efficiency() API as not used
+ *
+ * Revision 1.3  2009/07/14 14:45:03  kmirny
+ * new recipe parameters
+ *
+ * Revision 1.2  2009/06/12 14:20:20  kmirny
+ * updating SINFONI efficiency calculation
+ *
+ * Revision 1.1  2009/06/10 14:57:14  kmirny
+ * sinfoni efficiency utility recipe
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+/*-----------------------------------------------------------------------------
+                                Includes
+ ----------------------------------------------------------------------------*/
+#include <string.h>
+
+/* cpl */
+#include <cpl.h>
+
+/* irplib */
+#include <irplib_utils.h>
+
+#include <sinfo_tpl_utils.h>
+#include <sinfo_pfits.h>
+#include <sinfo_tpl_dfs.h>
+#include <sinfo_key_names.h>
+#include <sinfo_pro_types.h>
+#include <sinfo_ref_types.h>
+#include <sinfo_functions.h>
+#include <sinfo_msg.h>
+#include <sinfo_error.h>
+#include <sinfo_utils_wrappers.h>
+#include <sinfo_utl_efficiency.h>
+
+/*-----------------------------------------------------------------------------
+                            Functions prototypes
+ ----------------------------------------------------------------------------*/
+
+static int sinfo_utl_eff_create(cpl_plugin *) ;
+static int sinfo_utl_eff_exec(cpl_plugin *) ;
+static int sinfo_utl_eff_destroy(cpl_plugin *) ;
+static int sinfo_utl_eff(cpl_parameterlist *, cpl_frameset *) ;
+
+/*-----------------------------------------------------------------------------
+                            Static variables
+ ----------------------------------------------------------------------------*/
+
+static char sinfo_utl_eff_description[] =
+"This recipe calculate a efficiency\n"
+"esorex --params sinfo_utl_eff\n"
+"esorex --help sinfo_utl_eff\n"
+"\n";
+
+
+
+/*-----------------------------------------------------------------------------
+                                Functions code
+ ----------------------------------------------------------------------------*/
+/*---------------------------------------------------------------------------*/
+/**
+ * @defgroup sinfo_utl_eff  Recipe to do operations on an image
+ */
+/*---------------------------------------------------------------------------*/
+
+/**@{*/
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Build the list of available plugins, for this module.
+  @param    list    the plugin list
+  @return   0 if everything is ok
+
+  This function is exported.
+ */
+/*---------------------------------------------------------------------------*/
+int cpl_plugin_get_info(cpl_pluginlist * list)
+{
+    cpl_recipe  *   recipe = cpl_calloc(1, sizeof *recipe ) ;
+    cpl_plugin  *   plugin = &recipe->interface ;
+
+    cpl_plugin_init(plugin,
+                    CPL_PLUGIN_API,
+                    SINFONI_BINARY_VERSION,
+                    CPL_PLUGIN_TYPE_RECIPE,
+                    "sinfo_utl_eff",
+                    "Produce a table with efficiency",
+                    sinfo_utl_eff_description,
+                    "Konstantin Mirny",
+                    "kmirny at eso.org",
+                    sinfo_get_license(),
+                    sinfo_utl_eff_create,
+                    sinfo_utl_eff_exec,
+                    sinfo_utl_eff_destroy) ;
+
+    cpl_pluginlist_append(list, plugin) ;
+
+    return 0;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Setup the recipe options
+  @param    plugin  the plugin
+  @return   0 if everything is ok
+
+  Create the recipe instance and make it available to the application using
+  the interface.
+ */
+/*---------------------------------------------------------------------------*/
+static int sinfo_utl_eff_create(cpl_plugin * plugin)
+{
+    cpl_recipe      * recipe ;
+
+    /* Get the recipe out of the plugin */
+    if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
+        recipe = (cpl_recipe *)plugin ;
+    else return -1 ;
+    cpl_error_reset();
+    irplib_reset();
+
+    /* Create the parameters list in the cpl_recipe object */
+    recipe->parameters = cpl_parameterlist_new() ;
+
+    /* Fill the parameters list */
+
+
+        /* Return */
+    return 0;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Execute the plugin instance given by the interface
+  @param    plugin  the plugin
+  @return   0 if everything is ok
+ */
+/*---------------------------------------------------------------------------*/
+static int sinfo_utl_eff_exec(cpl_plugin * plugin)
+{
+    cpl_recipe  *   recipe ;
+     int code=0;
+     cpl_errorstate initial_errorstate = cpl_errorstate_get();
+
+    /* Get the recipe out of the plugin */
+    if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
+        recipe = (cpl_recipe *)plugin ;
+    else return -1 ;
+    cpl_error_reset();
+    irplib_reset();
+    code = sinfo_utl_eff(recipe->parameters, recipe->frames) ;
+
+
+    if (!cpl_errorstate_is_equal(initial_errorstate)) {
+        /* Dump the error history since recipe execution start.
+           At this point the recipe cannot recover from the error */
+        cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
+    }
+
+    return code ;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Destroy what has been created by the 'create' function
+  @param    plugin  the plugin
+  @return   0 if everything is ok
+ */
+/*---------------------------------------------------------------------------*/
+static int sinfo_utl_eff_destroy(cpl_plugin * plugin)
+{
+    cpl_recipe  *   recipe ;
+
+    /* Get the recipe out of the plugin */
+    if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
+        recipe = (cpl_recipe *)plugin ;
+    else return -1 ;
+
+    cpl_parameterlist_delete(recipe->parameters) ;
+    return 0 ;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Get the command line options and execute the data reduction
+  @param    parlist     the parameters list
+  @param    framelist   the frames list
+  @return   0 if everything is ok
+ */
+/*---------------------------------------------------------------------------*/
+static int
+sinfo_utl_eff( cpl_parameterlist   *   parlist,
+               cpl_frameset        *   framelist)
+{
+
+   const char          *   name_o = NULL ;
+
+   cpl_frame*				product_frame = 0;
+   cpl_propertylist    *   plist = NULL ;
+   int pos = 0;
+   int npos = 0;
+   cpl_frame* frm_sci=NULL;
+   cpl_frame* frm_atm_ext=NULL;
+   cpl_frame* frm_std_cat=NULL;
+   cpl_table* eff_tbl=NULL;
+
+   sinfo_msg("Welcome to SINFONI Pipeline release %d.%d.%d",
+             SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
+   ck0(sinfo_dfs_set_groups(framelist),"Cannot indentify RAW and CALIB frames");
+
+   /* HOW TO GET THE VALUE OF A FITS KEYWORD */
+   check(plist=cpl_propertylist_new(),"Cannot create a Property List");
+
+
+   /* Now performing the data reduction */
+   name_o = "eff_res.fits" ;
+
+   check_nomsg(frm_sci=cpl_frameset_find (framelist, PRO_STD_STAR_SPECTRA));
+   check_nomsg(frm_std_cat=cpl_frameset_find (framelist, FLUX_STD_CATALOG));
+   check_nomsg(frm_atm_ext=cpl_frameset_find (framelist, EXTCOEFF_TABLE));
+   sinfo_msg("frm_sci=%p frm_std=%p frm_atm_ext=%p",frm_sci,frm_std_cat,frm_atm_ext);
+   check_nomsg(eff_tbl=sinfo_efficiency_compute(frm_sci,frm_std_cat,frm_atm_ext));
+   npos = cpl_frameset_get_size(framelist);
+   for (pos = 0; pos < npos; pos++)
+   {
+      cpl_frame* pframe = cpl_frameset_get_frame(framelist, pos);
+      cpl_frame_group group = cpl_frame_get_group(pframe);
+      if (CPL_FRAME_GROUP_PRODUCT == group)
+      {
+         check_nomsg(cpl_frame_set_group (pframe, CPL_FRAME_GROUP_CALIB));
+      }
+   }
+   /* Create product frame */
+   check_nomsg(product_frame = cpl_frame_new());
+   check_nomsg(cpl_frame_set_filename(product_frame, name_o)) ;
+   check_nomsg(cpl_frame_set_tag(product_frame,"sinfo_efficiency" )) ;
+   check_nomsg(cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_TABLE)) ;
+   check_nomsg(cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT)) ;
+   check(cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL),
+         "Error while initialising the product frame") ;
+
+   /* Add DataFlow keywords */
+   check_nomsg(cpl_propertylist_erase_regexp(plist, "^ESO PRO CATG",0));
+   /* Log the saved file in the input frameset */
+   check_nomsg(cpl_frameset_insert(framelist, product_frame)) ;
+   check(cpl_dfs_setup_product_header(plist,
+                                      product_frame,
+                                      framelist,
+                                      parlist,
+                                      "sinfo_utl_eff",
+                                      "SINFONI",
+                                      KEY_VALUE_HPRO_DID,NULL),
+         "Problem in the product DFS-compliance") ;
+   sinfo_free_propertylist(&plist) ;
+
+  cleanup:
+   sinfo_free_propertylist(&plist) ;
+   return (cpl_error_get_code()) ? -1 : 0;
+}
+/**@}*/
diff --git a/recipes/sinfo_utl_ima_arith.c b/recipes/sinfo_utl_ima_arith.c
new file mode 100644
index 0000000..f042371
--- /dev/null
+++ b/recipes/sinfo_utl_ima_arith.c
@@ -0,0 +1,423 @@
+/* $Id: sinfo_utl_ima_arith.c,v 1.14 2009/01/30 14:56:12 amodigli Exp $
+ *
+ * This file is part of the SINFONI Pipeline
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2009/01/30 14:56:12 $
+ * $Revision: 1.14 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+/*-----------------------------------------------------------------------------
+                                Includes
+ ----------------------------------------------------------------------------*/
+#include <string.h>
+
+/* cpl */
+#include <cpl.h>
+
+/* irplib */
+#include <irplib_utils.h>
+
+#include <sinfo_tpl_utils.h>
+#include <sinfo_pfits.h>
+#include <sinfo_tpl_dfs.h>
+#include <sinfo_key_names.h>
+#include <sinfo_pro_types.h>
+#include <sinfo_functions.h>
+#include <sinfo_msg.h>
+#include <sinfo_error.h>
+#include <sinfo_utils_wrappers.h>
+
+/*-----------------------------------------------------------------------------
+                            Functions prototypes
+ ----------------------------------------------------------------------------*/
+
+static int sinfo_utl_ima_arith_create(cpl_plugin *) ;
+static int sinfo_utl_ima_arith_exec(cpl_plugin *) ;
+static int sinfo_utl_ima_arith_destroy(cpl_plugin *) ;
+static int sinfo_utl_ima_arith(cpl_parameterlist *, cpl_frameset *) ;
+
+/*-----------------------------------------------------------------------------
+                            Static variables
+ ----------------------------------------------------------------------------*/
+
+static char sinfo_utl_ima_arith_description[] =
+"This recipe performs image computation.\n"
+"The input files are 2 images\n"
+"their associated tags should be IMA.\n"
+"The output is an image resulting from the IMA op IMA where op indicates\n"
+"the operation to be performed specified by the parameter \n"
+"sinfoni.sinfo_utl_ima_arith.op having alias 'op'\n"
+"Information on relevant parameters can be found with\n"
+"esorex --params sinfo_utl_ima_arith\n"
+"esorex --help sinfo_utl_ima_arith\n"
+"\n";
+
+/*-----------------------------------------------------------------------------
+                                Functions code
+ ----------------------------------------------------------------------------*/
+/*---------------------------------------------------------------------------*/
+/**
+ * @defgroup sinfo_utl_ima_arith  Recipe to do operations on an image
+ */
+/*---------------------------------------------------------------------------*/
+
+/**@{*/
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Build the list of available plugins, for this module. 
+  @param    list    the plugin list
+  @return   0 if everything is ok
+
+  This function is exported.
+ */
+/*---------------------------------------------------------------------------*/
+int cpl_plugin_get_info(cpl_pluginlist * list)
+{
+    cpl_recipe  *   recipe = cpl_calloc(1, sizeof *recipe ) ;
+    cpl_plugin  *   plugin = &recipe->interface ;
+
+    cpl_plugin_init(plugin,
+                    CPL_PLUGIN_API,
+                    SINFONI_BINARY_VERSION,
+                    CPL_PLUGIN_TYPE_RECIPE,
+                    "sinfo_utl_ima_arith",
+                    "Computes result of ima1 op ima2",
+                    sinfo_utl_ima_arith_description,
+                    "Andrea Modigliani",
+                    "Andrea.Modigliani at eso.org",
+                    sinfo_get_license(),
+                    sinfo_utl_ima_arith_create,
+                    sinfo_utl_ima_arith_exec,
+                    sinfo_utl_ima_arith_destroy) ;
+
+    cpl_pluginlist_append(list, plugin) ;
+    
+    return 0;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Setup the recipe options    
+  @param    plugin  the plugin
+  @return   0 if everything is ok
+
+  Create the recipe instance and make it available to the application using 
+  the interface. 
+ */
+/*---------------------------------------------------------------------------*/
+static int sinfo_utl_ima_arith_create(cpl_plugin * plugin)
+{
+    cpl_recipe      * recipe ;
+    cpl_parameter   * p ;
+
+    /* Get the recipe out of the plugin */
+    if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+        recipe = (cpl_recipe *)plugin ;
+    else return -1 ;
+    cpl_error_reset();
+    irplib_reset();
+
+    /* Create the parameters list in the cpl_recipe object */
+    recipe->parameters = cpl_parameterlist_new() ; 
+
+    /* Fill the parameters list */
+    /* --stropt */
+    p = cpl_parameter_new_value("sinfoni.sinfo_utl_ima_arith.op", 
+                                CPL_TYPE_STRING, 
+                                "A possible operation", 
+                                "sinfoni.sinfo_utl_ima_arith","+");
+    cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "op") ;
+    cpl_parameterlist_append(recipe->parameters, p) ;
+
+    /* --doubleopt */
+    p = cpl_parameter_new_value("sinfoni.sinfo_utl_ima_arith.value", 
+            CPL_TYPE_DOUBLE, "a value", "sinfoni.sinfo_utl_ima_arith", 9999.) ;
+    cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "value") ;
+    cpl_parameterlist_append(recipe->parameters, p) ;
+ 
+    /* Return */
+    return 0;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Execute the plugin instance given by the interface
+  @param    plugin  the plugin
+  @return   0 if everything is ok
+ */
+/*---------------------------------------------------------------------------*/
+static int sinfo_utl_ima_arith_exec(cpl_plugin * plugin)
+{
+    cpl_recipe  *   recipe ;
+     int code=0;
+     cpl_errorstate initial_errorstate = cpl_errorstate_get();
+
+    /* Get the recipe out of the plugin */
+    if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+        recipe = (cpl_recipe *)plugin ;
+    else return -1 ;
+    cpl_error_reset();
+    irplib_reset();
+    code = sinfo_utl_ima_arith(recipe->parameters, recipe->frames) ;
+
+
+    if (!cpl_errorstate_is_equal(initial_errorstate)) {                      
+        /* Dump the error history since recipe execution start.                
+           At this point the recipe cannot recover from the error */           
+        cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);              
+    } 
+
+    return code ;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Destroy what has been created by the 'create' function
+  @param    plugin  the plugin
+  @return   0 if everything is ok
+ */
+/*---------------------------------------------------------------------------*/
+static int sinfo_utl_ima_arith_destroy(cpl_plugin * plugin)
+{
+    cpl_recipe  *   recipe ;
+    
+    /* Get the recipe out of the plugin */
+    if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+        recipe = (cpl_recipe *)plugin ;
+    else return -1 ;
+
+    cpl_parameterlist_delete(recipe->parameters) ; 
+    return 0 ;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Get the command line options and execute the data reduction
+  @param    parlist     the parameters list
+  @param    framelist   the frames list
+  @return   0 if everything is ok
+ */
+/*---------------------------------------------------------------------------*/
+static int 
+sinfo_utl_ima_arith( cpl_parameterlist   *   parlist, 
+        cpl_frameset        *   framelist)
+{
+    cpl_parameter       *   param= NULL ;
+    const char          *   operation=NULL;
+    double                     value=1 ;
+    cpl_frame           *   frm_ima1=NULL ;
+    cpl_frame           *   frm_ima2=NULL ;
+    cpl_image           *   ima1=NULL ;
+    cpl_image           *   ima2=NULL ;
+    int switch_ima2     = 0;
+    const char                *   name_o=NULL ;
+    cpl_propertylist    *   plist=NULL ;
+    cpl_image           *   image=NULL ;
+    cpl_frame           *   product_frame=NULL;
+    cpl_frameset * raw_set=NULL;
+    int nraw=0;
+    int n=0;
+          sinfo_msg("Welcome to SINFONI Pipeline release %d.%d.%d",
+        SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
+
+    /* HOW TO RETRIEVE INPUT PARAMETERS */
+    /* --stropt */
+    check_nomsg(param=cpl_parameterlist_find(parlist, 
+                                             "sinfoni.sinfo_utl_ima_arith.op"));
+    check_nomsg(operation=cpl_parameter_get_string(param));
+
+    /* --boolopt */
+    check_nomsg(param=cpl_parameterlist_find(parlist,
+                                             "sinfoni.sinfo_utl_ima_arith.value"));
+    check_nomsg(value = cpl_parameter_get_double(param)) ;
+  
+    /* Identify the RAW and CALIB frames in the input frameset */
+    check(sinfo_dfs_set_groups(framelist),
+         "Cannot identify RAW and CALIB frames") ;
+ 
+    /* HOW TO ACCESS INPUT DATA */
+    n=cpl_frameset_get_size(framelist);
+    if(n<1) {
+      sinfo_msg_error("Empty input frame list!");
+      goto cleanup ;
+    }
+
+    /* HOW TO ACCESS INPUT DATA */
+    check_nomsg(raw_set=cpl_frameset_new());
+
+    check(sinfo_contains_frames_kind(framelist,raw_set,PRO_IMA),
+     "Found no input frames with tag %s",PRO_IMA);
+    check_nomsg(nraw=cpl_frameset_get_size(raw_set));
+    if (nraw<1) {
+      sinfo_msg_error("Found no input frames with tag %s",PRO_IMA);
+      goto cleanup;
+    } else {
+         check_nomsg(frm_ima1=cpl_frameset_get_frame(framelist,0));
+         check_nomsg(ima1=cpl_image_load(cpl_frame_get_filename(frm_ima1),
+                                         CPL_TYPE_FLOAT,0,0));
+     if (nraw>1) {
+         check_nomsg(frm_ima2=cpl_frameset_get_frame(framelist,1));
+         check_nomsg(ima2 = cpl_image_load(cpl_frame_get_filename(frm_ima2),
+                                           CPL_TYPE_FLOAT,0,0));
+         switch_ima2=1;
+      } else if (value == 9999.) {
+        sinfo_msg_error("Found only one input frames with tag %s",PRO_IMA);
+        goto cleanup; 
+      } else {
+        sinfo_msg("Perform image arithmetics on frame %s",PRO_IMA);
+      }
+    }
+
+    sinfo_free_frameset(&raw_set);
+
+    /* HOW TO GET THE VALUE OF A FITS KEYWORD */
+    check(plist=cpl_propertylist_load(cpl_frame_get_filename(frm_ima1),0),
+          "Cannot read the FITS header") ;
+
+    /* Now performing the data reduction */
+    /* Let's generate one image for the example */
+    if (value == 9999.) {
+
+      if(ima1 != NULL && ima2 != NULL) {
+    sinfo_msg("ima1 %s ima2",operation);
+    if (strcmp(operation,"+") == 0 ) {
+          check(image = cpl_image_add_create(ima1, ima2),
+                "Cannot generate the %s image",operation) ;
+    } else if (strcmp(operation,"-") == 0 ) {
+          check(image = cpl_image_subtract_create(ima1, ima2),               
+        "Cannot generate the %s image",operation) ;
+    } else if (strcmp(operation,"*") == 0 ) {
+          check(image = cpl_image_multiply_create(ima1, ima2),
+        "Cannot generate the %s image",operation) ;
+    } else if (strcmp(operation,"/") == 0 ) {
+      check(image = cpl_image_divide_create(ima1, ima2),
+        "Cannot generate the %s image",operation) ;
+    } else {
+          sinfo_msg_error("Operation %s not supported",operation);
+          goto cleanup;
+    }
+      sinfo_free_image(&ima1);
+      sinfo_free_image(&ima2);
+
+      }
+    
+    } else {
+      sinfo_msg("ima1 %s %f",operation,value);
+       
+      if(switch_ima2 == 1) {
+      sinfo_free_image(&ima2);
+      }
+       
+      if (strcmp(operation,"+") == 0 ) {
+    check(image = cpl_image_add_scalar_create(ima1, value),
+          "Cannot apply the %s operator",operation) ;
+      } else if (strcmp(operation,"-") == 0 ) {
+    check(image = cpl_image_subtract_scalar_create(ima1, value),
+          "Cannot apply the %s operator",operation) ;
+      } else if (strcmp(operation,"*") == 0 ) {
+    check(image = cpl_image_multiply_scalar_create(ima1, value),
+          "Cannot apply the %s operator",operation) ;
+      } else if (strcmp(operation,"/") == 0 ) {
+    check(image = cpl_image_divide_scalar_create(ima1, value),
+          "Cannot apply the %s operator",operation) ;
+      } else {
+    sinfo_msg_error("Operation %s not supported",operation);
+    goto cleanup;
+      }
+    
+      sinfo_free_image(&ima1);
+
+    }
+
+
+    /* HOW TO SAVE A PRODUCT ON DISK  */
+    /* Set the file name */
+    name_o = "ima_res.fits" ;
+
+    /* Create product frame */
+    check_nomsg(product_frame = cpl_frame_new());
+    check_nomsg(cpl_frame_set_filename(product_frame, name_o)) ;
+    check_nomsg(cpl_frame_set_tag(product_frame, SI_UTL_IMA_ARITH_PROIMA)) ;
+    check_nomsg(cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_IMAGE)) ;
+    check_nomsg(cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT)) ;
+    check(cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL),
+      "Error while initialising the product frame") ;
+    
+    /* Add DataFlow keywords */
+    check_nomsg(cpl_propertylist_erase_regexp(plist, "^ESO PRO CATG",0));
+#if defined CPL_VERSION_CODE && CPL_VERSION_CODE >= CPL_VERSION(4, 8, 0)  
+    check(cpl_dfs_setup_product_header(plist, 
+                                       product_frame, 
+                                       framelist, 
+                                       parlist,
+                                       "sinfo_utl_ima_arith", 
+                                       "SINFONI", 
+                                       KEY_VALUE_HPRO_DID,NULL),
+      "Problem in the product DFS-compliance") ;
+#else
+    check(cpl_dfs_setup_product_header(plist, 
+                                       product_frame, 
+                                       framelist, 
+                                       parlist,
+                                       "sinfo_utl_ima_arith", 
+                                       "SINFONI", 
+                                       KEY_VALUE_HPRO_DID),
+      "Problem in the product DFS-compliance") ;
+#endif
+
+    /* Save the file */
+    check(cpl_image_save(image, 
+                         name_o, 
+                         CPL_BPP_IEEE_FLOAT, 
+                         plist,
+                         CPL_IO_DEFAULT),
+      "Could not save product");
+    sinfo_free_propertylist(&plist) ;
+    sinfo_free_image(&image);
+
+    /* Log the saved file in the input frameset */
+    check_nomsg(cpl_frameset_insert(framelist, product_frame)) ;
+
+
+ cleanup:
+   
+    sinfo_free_image(&ima1);
+    sinfo_free_image(&ima2);
+    sinfo_free_frameset(&raw_set);
+    sinfo_free_propertylist(&plist) ;
+    /* This is usually freed by esorex: but what about if errors occurs?
+    sinfo_free_frame(&product_frame) ;
+    */
+    sinfo_free_image(&image) ;
+
+    if (cpl_error_get_code()) {
+        return -1 ;
+    } else {
+        return 0 ;
+    }
+
+}
+/**@}*/
diff --git a/recipes/sinfo_utl_ima_line_corr.c b/recipes/sinfo_utl_ima_line_corr.c
new file mode 100644
index 0000000..d0edb84
--- /dev/null
+++ b/recipes/sinfo_utl_ima_line_corr.c
@@ -0,0 +1,341 @@
+/* $Id: sinfo_utl_ima_line_corr.c,v 1.3 2009/06/05 08:18:55 amodigli Exp $
+ *
+ * This file is part of the SINFONI Pipeline
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2009/06/05 08:18:55 $
+ * $Revision: 1.3 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+/*-----------------------------------------------------------------------------
+                                Includes
+ ----------------------------------------------------------------------------*/
+#include <string.h>
+
+/* cpl */
+#include <cpl.h>
+
+/* irplib */
+#include <irplib_utils.h>
+
+#include <sinfo_tpl_utils.h>
+#include <sinfo_pfits.h>
+#include <sinfo_tpl_dfs.h>
+#include <sinfo_key_names.h>
+#include <sinfo_pro_types.h>
+#include <sinfo_functions.h>
+#include <sinfo_image_ops.h>
+#include <sinfo_msg.h>
+#include <sinfo_error.h>
+#include <sinfo_utils_wrappers.h>
+
+/*-----------------------------------------------------------------------------
+                            Functions prototypes
+ ----------------------------------------------------------------------------*/
+
+static int sinfo_utl_ima_line_corr_create(cpl_plugin *) ;
+static int sinfo_utl_ima_line_corr_exec(cpl_plugin *) ;
+static int sinfo_utl_ima_line_corr_destroy(cpl_plugin *) ;
+static int sinfo_utl_ima_line_corr(cpl_parameterlist *, cpl_frameset *) ;
+
+/*-----------------------------------------------------------------------------
+                            Static variables
+ ----------------------------------------------------------------------------*/
+
+static char sinfo_utl_ima_line_corr_description[] =
+"This recipe performs image computation.\n"
+"The input files are images\n"
+"their associated tags should be IMA.\n"
+"The output are the images cleaned by the defect introduced by SINFONI sw\n"
+"Information on relevant parameters can be found with\n"
+"esorex --params sinfo_utl_ima_line_corr\n"
+"esorex --help sinfo_utl_ima_line_corr\n"
+"\n";
+
+/*-----------------------------------------------------------------------------
+                                Functions code
+ ----------------------------------------------------------------------------*/
+/*---------------------------------------------------------------------------*/
+/**
+ * @defgroup sinfo_utl_ima_line_corr  Recipe to do operations on an image
+ */
+/*---------------------------------------------------------------------------*/
+
+/**@{*/
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Build the list of available plugins, for this module. 
+  @param    list    the plugin list
+  @return   0 if everything is ok
+
+  This function is exported.
+ */
+/*---------------------------------------------------------------------------*/
+int cpl_plugin_get_info(cpl_pluginlist * list)
+{
+    cpl_recipe  *   recipe = cpl_calloc(1, sizeof *recipe ) ;
+    cpl_plugin  *   plugin = &recipe->interface ;
+
+    cpl_plugin_init(plugin,
+                    CPL_PLUGIN_API,
+                    SINFONI_BINARY_VERSION,
+                    CPL_PLUGIN_TYPE_RECIPE,
+                    "sinfo_utl_ima_line_corr",
+                    "Computes result of ima1 op ima2",
+                    sinfo_utl_ima_line_corr_description,
+                    "Andrea Modigliani",
+                    "Andrea.Modigliani at eso.org",
+                    sinfo_get_license(),
+                    sinfo_utl_ima_line_corr_create,
+                    sinfo_utl_ima_line_corr_exec,
+                    sinfo_utl_ima_line_corr_destroy) ;
+
+    cpl_pluginlist_append(list, plugin) ;
+    
+    return 0;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Setup the recipe options    
+  @param    plugin  the plugin
+  @return   0 if everything is ok
+
+  Create the recipe instance and make it available to the application using 
+  the interface. 
+ */
+/*---------------------------------------------------------------------------*/
+static int sinfo_utl_ima_line_corr_create(cpl_plugin * plugin)
+{
+    cpl_recipe      * recipe ;
+    cpl_parameter   * p ;
+
+    /* Get the recipe out of the plugin */
+    if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+        recipe = (cpl_recipe *)plugin ;
+    else return -1 ;
+    cpl_error_reset();
+    irplib_reset();
+
+    /* Create the parameters list in the cpl_recipe object */
+    recipe->parameters = cpl_parameterlist_new() ; 
+
+    /* Fill the parameters list */
+    p = cpl_parameter_new_value("sinfoni.sinfo_utl_ima_line_corr.kappa", 
+                                CPL_TYPE_INT, 
+                                "Kappa sigma value", 
+                                "sinfoni.sinfo_utl_ima_line_corr",18);
+    cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "kappa") ;
+    cpl_parameterlist_append(recipe->parameters, p) ;
+
+     p = cpl_parameter_new_value("sinfoni.sinfo_utl_ima_line_corr.filt_rad", 
+				CPL_TYPE_INT,
+				"Filtering radii applied during median filter."
+                                " Should be small", 
+				"sinfoni.sinfo_utl_ima_line_corr",3) ;;
+    cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "filt_rad") ;
+    cpl_parameterlist_append(recipe->parameters, p) ;
+ 
+    /* Return */
+    return 0;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Execute the plugin instance given by the interface
+  @param    plugin  the plugin
+  @return   0 if everything is ok
+ */
+/*---------------------------------------------------------------------------*/
+static int sinfo_utl_ima_line_corr_exec(cpl_plugin * plugin)
+{
+    cpl_recipe  *   recipe ;
+     int code=0;
+     cpl_errorstate initial_errorstate = cpl_errorstate_get();
+
+    /* Get the recipe out of the plugin */
+    if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+        recipe = (cpl_recipe *)plugin ;
+    else return -1 ;
+    cpl_error_reset();
+    irplib_reset();
+    code = sinfo_utl_ima_line_corr(recipe->parameters, recipe->frames) ;
+
+
+    if (!cpl_errorstate_is_equal(initial_errorstate)) {                      
+        /* Dump the error history since recipe execution start.                
+           At this point the recipe cannot recover from the error */           
+        cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);              
+    } 
+
+    return code ;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Destroy what has been created by the 'create' function
+  @param    plugin  the plugin
+  @return   0 if everything is ok
+ */
+/*---------------------------------------------------------------------------*/
+static int sinfo_utl_ima_line_corr_destroy(cpl_plugin * plugin)
+{
+    cpl_recipe  *   recipe ;
+    
+    /* Get the recipe out of the plugin */
+    if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+        recipe = (cpl_recipe *)plugin ;
+    else return -1 ;
+
+    cpl_parameterlist_delete(recipe->parameters) ; 
+    return 0 ;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Get the command line options and execute the data reduction
+  @param    parlist     the parameters list
+  @param    framelist   the frames list
+  @return   0 if everything is ok
+ */
+/*---------------------------------------------------------------------------*/
+static int 
+sinfo_utl_ima_line_corr( cpl_parameterlist   *   parlist, 
+			 cpl_frameset        *   framelist)
+{
+    cpl_parameter       *   p= NULL ;
+    int                     kappa=18;
+    int                     filt_rad=3;
+    int width=4;
+
+    cpl_image           *   ima=NULL ;
+    cpl_image           *   ima_out=NULL ;
+    cpl_propertylist    *   plist=NULL ;
+    cpl_frame           *   product_frame=NULL;
+    cpl_frameset * raw_set=NULL;
+    int i=0;
+    cpl_frame * frm=NULL;
+    char name_o[MAX_NAME_SIZE];
+    const char* name=NULL;
+
+    int n=0;
+    sinfo_msg("Welcome to SINFONI Pipeline release %d.%d.%d",
+        SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
+
+    /* HOW TO RETRIEVE INPUT PARAMETERS */
+    /* --stropt */
+    check_nomsg(p=cpl_parameterlist_find(parlist, 
+                                         "sinfoni.sinfo_utl_ima_line_corr.kappa"));
+    check_nomsg(kappa=cpl_parameter_get_int(p));
+
+    /* --boolopt */
+    check_nomsg(p=cpl_parameterlist_find(parlist,
+                                         "sinfoni.sinfo_utl_ima_line_corr.filt_rad"));
+    check_nomsg(filt_rad = cpl_parameter_get_int(p)) ;
+  
+    /* Identify the RAW and CALIB frames in the input frameset */
+    check(sinfo_dfs_set_groups(framelist),
+         "Cannot identify RAW and CALIB frames") ;
+ 
+    /* HOW TO ACCESS INPUT DATA */
+    n=cpl_frameset_get_size(framelist);
+    if(n<1) {
+      sinfo_msg_error("Empty input frame list!");
+      goto cleanup ;
+    }
+    raw_set=cpl_frameset_new();
+    ck0_nomsg(sinfo_extract_raw_frames(framelist, &raw_set));
+    n=cpl_frameset_get_size(raw_set);
+    if(n<1) {
+      sinfo_msg_error("No raw data found in frame list!");
+      goto cleanup ;
+    }
+
+
+    for(i=0;i<n;i++) {
+      check_nomsg(frm=cpl_frameset_get_frame(raw_set,0));
+      check_nomsg(name=cpl_frame_get_filename(frm));
+      check_nomsg(ima=cpl_image_load(name,CPL_TYPE_FLOAT,0,0));
+
+      check_nomsg(sinfo_image_line_corr(width,filt_rad,kappa,ima,&ima_out));
+
+      sprintf(name_o,"%s%d%s","ima_cor",i,".fits") ;
+
+      /* Create product frame */
+      check_nomsg(product_frame = cpl_frame_new());
+      check_nomsg(cpl_frame_set_filename(product_frame, name_o));
+      check_nomsg(cpl_frame_set_tag(product_frame, "IMA_COR"));
+      check_nomsg(cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_IMAGE));
+      check_nomsg(cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT));
+      check(cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL),
+	    "Error while initialising the product frame") ;
+    
+      /* Add DataFlow keywords */
+      /*
+      check(cpl_dfs_setup_product_header(plist, 
+					 product_frame, 
+					 framelist, 
+					 parlist,
+					 "sinfo_utl_ima_line_corr", 
+					 "SINFONI", 
+					 KEY_VALUE_HPRO_DID),
+	    "Problem in the product DFS-compliance") ;
+      */
+
+      /* Save the file */
+      check(cpl_image_save(ima_out, 
+			   name_o, 
+			   CPL_BPP_IEEE_FLOAT, 
+			   plist,
+			   CPL_IO_DEFAULT),
+	    "Could not save product");
+      sinfo_free_propertylist(&plist) ;
+      sinfo_free_image(&ima_out);
+      sinfo_free_image(&ima);
+
+      /* Log the saved file in the input frameset */
+      check_nomsg(cpl_frameset_insert(framelist, product_frame)) ;
+
+    }
+
+ cleanup:
+    sinfo_free_image(&ima);
+    sinfo_free_image(&ima_out);
+      //sinfo_free_frameset(&raw_set);
+
+
+    /* This is usually freed by esorex: but what about if errors occurs?
+    sinfo_free_frame(&product_frame) ;
+    */
+
+
+    if (cpl_error_get_code()) {
+        return -1 ;
+    } else {
+        return 0 ;
+    }
+
+}
+/**@}*/
diff --git a/recipes/sinfo_utl_skycor.c b/recipes/sinfo_utl_skycor.c
new file mode 100644
index 0000000..dafaef8
--- /dev/null
+++ b/recipes/sinfo_utl_skycor.c
@@ -0,0 +1,359 @@
+/* $Id: sinfo_utl_skycor.c,v 1.13 2007/10/26 09:40:28 amodigli Exp $
+ *
+ * This file is part of the SINFONI Pipeline
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2007/10/26 09:40:28 $
+ * $Revision: 1.13 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+/*-----------------------------------------------------------------------------
+                                Includes
+ ----------------------------------------------------------------------------*/
+#include <string.h>
+#include <cpl.h>
+#include <irplib_utils.h>
+#include <sinfo_skycor.h>
+#include <sinfo_skycor_config.h>
+#include <sinfo_tpl_utils.h>
+#include <sinfo_tpl_dfs.h>
+#include <sinfo_pro_types.h>
+#include <sinfo_utils_wrappers.h>
+#include <sinfo_error.h>
+#include <sinfo_msg.h>
+#include <sinfo_pro_save.h>
+#include <sinfo_globals.h>
+/*-----------------------------------------------------------------------------
+                                Defines
+ ----------------------------------------------------------------------------*/
+
+/*-----------------------------------------------------------------------------
+                            Functions prototypes
+-----------------------------------------------------------------------------*/
+static int sinfo_utl_skycor_create(cpl_plugin *) ;
+static int sinfo_utl_skycor_exec(cpl_plugin *) ;
+static int sinfo_utl_skycor_destroy(cpl_plugin *) ;
+static int sinfo_utl_skycor(cpl_parameterlist * config, cpl_frameset* set);
+/*-----------------------------------------------------------------------------
+                            Static variables
+ -----------------------------------------------------------------------------*/
+
+static char sinfo_utl_skycor_description[] =
+"This recipe perform a correction of possible sky line residuals in the \n"
+"object cube after standard data reduction.\n"
+"Input frames are cubes with target and sky observations.\n"
+"Their tags can be respectively OBS_OBJ (or OBS_PSF or OBS_STD) and OBS_SKY.\n"
+"The output is a cube with same tag as the corresponding input target frame.\n"
+"\n";
+
+
+/*-----------------------------------------------------------------------------
+                                Functions code
+ ----------------------------------------------------------------------------*/
+
+/*---------------------------------------------------------------------------*/
+/**
+ * @defgroup sinfo_utl_skycor Recipe to correct sky residuals on science cubes
+ */
+/*---------------------------------------------------------------------------*/
+/**@{*/
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Build the list of available plugins, for this module. 
+  @param    list    the plugin list
+  @return   0 if everything is ok
+
+  This function is exported.
+ */
+/*---------------------------------------------------------------------------*/
+int cpl_plugin_get_info(cpl_pluginlist * list)
+{
+    cpl_recipe  *   recipe = cpl_calloc(1, sizeof *recipe ) ;
+    cpl_plugin  *   plugin = &recipe->interface ;
+
+    cpl_plugin_init(plugin,
+                    CPL_PLUGIN_API,
+                    SINFONI_BINARY_VERSION,
+                    CPL_PLUGIN_TYPE_RECIPE,
+                    "sinfo_utl_skycor",
+                    "Sky lines residuals correction",
+                    sinfo_utl_skycor_description,
+                    "Andrea Modigliani",
+                    "Andrea.Modigliani at eso.org",
+                    sinfo_get_license(),
+                    sinfo_utl_skycor_create,
+                    sinfo_utl_skycor_exec,
+                    sinfo_utl_skycor_destroy) ;
+
+    cpl_pluginlist_append(list, plugin) ;
+    return 0;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Setup the recipe options    
+  @param    plugin  the plugin
+  @return   0 if everything is ok
+
+  Create the recipe instance and make it available to the application 
+  using the interface. 
+ */
+/*--------------------------------------------------------------------------*/
+static int sinfo_utl_skycor_create(cpl_plugin * plugin)
+{
+    cpl_recipe      * recipe ;
+
+    /* Get the recipe out of the plugin */
+    if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+        recipe = (cpl_recipe *)plugin ;
+    else return -1 ;
+
+    /* reset error handling */
+    irplib_reset();
+    /* Create the parameters list in the cpl_recipe object */
+    recipe->parameters = cpl_parameterlist_new() ; 
+    sinfo_skycor_config_add(recipe->parameters);
+  
+    /* Return */
+    return 0;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Execute the plugin instance given by the interface
+  @param    plugin  the plugin
+  @return   0 if everything is ok
+ */
+/*---------------------------------------------------------------------------*/
+static int sinfo_utl_skycor_exec(cpl_plugin * plugin)
+{
+    cpl_recipe  *   recipe ;
+    int code=0;
+    /* Get the recipe out of the plugin */
+    cpl_errorstate initial_errorstate = cpl_errorstate_get();
+
+    if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+        recipe = (cpl_recipe *)plugin ;
+    else return -1 ;
+
+
+    code = sinfo_utl_skycor(recipe->parameters, recipe->frames) ;
+
+    if (!cpl_errorstate_is_equal(initial_errorstate)) {                      
+        /* Dump the error history since recipe execution start.                
+           At this point the recipe cannot recover from the error */           
+        cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);              
+    } 
+    return code;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Destroy what has been created by the 'create' function
+  @param    plugin  the plugin
+  @return   0 if everything is ok
+ */
+/*---------------------------------------------------------------------------*/
+static int sinfo_utl_skycor_destroy(cpl_plugin * plugin)
+{
+    cpl_recipe  *   recipe ;
+    
+    /* Get the recipe out of the plugin */
+    if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+        recipe = (cpl_recipe *)plugin ;
+    else return -1 ;
+
+    cpl_parameterlist_delete(recipe->parameters) ; 
+    return 0 ;
+}
+
+
+/**
+  @brief    Execute the plugin instance given by the interface
+  @param    config  parameter configuration
+  @param    set     input data set
+  @return   0 if everything is ok
+ */
+/*---------------------------------------------------------------------------*/
+static int 
+sinfo_utl_skycor(cpl_parameterlist * config, cpl_frameset* set)
+{
+ 
+  cpl_frame* obj_frm=NULL;
+  cpl_frame* sky_frm=NULL;
+  cpl_imagelist* obj_cor=NULL;
+  const char *   name_o=NULL ;
+  cpl_frame* product_frame=NULL;
+
+  cpl_propertylist* plist=NULL;
+  sinfo_skycor_qc* sqc=NULL;
+  char obj_tag[MAX_NAME_SIZE];
+  cpl_table* int_obj=NULL;
+
+      sinfo_msg("Welcome to SINFONI Pipeline release %d.%d.%d",
+        SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
+
+
+  ck0(sinfo_dfs_set_groups(set),"Cannot indentify RAW and CALIB frames") ;
+
+
+  // get input data 
+    obj_frm=cpl_frameset_find(set,PRO_OBS_OBJ);
+  if(obj_frm == NULL) {
+    obj_frm=cpl_frameset_find(set,PRO_OBS_PSF);
+    strcpy(obj_tag,PRO_OBS_PSF);
+  } else {
+    strcpy(obj_tag,PRO_OBS_OBJ);
+  }
+
+
+  if(obj_frm == NULL) {
+    obj_frm=cpl_frameset_find(set,PRO_OBS_STD);
+    strcpy(obj_tag,PRO_OBS_STD);
+  }
+  cknull(obj_frm,"No %s or %s or %s frame found",
+     PRO_OBS_OBJ,PRO_OBS_PSF,PRO_OBS_STD);
+  check(sky_frm=cpl_frameset_find(set,PRO_OBS_SKY),
+        "No %s found",PRO_OBS_SKY);
+  sqc=sinfo_skycor_qc_new();
+
+  check(plist=cpl_propertylist_load(cpl_frame_get_filename(obj_frm),0),
+          "Cannot read the FITS header") ;
+ 
+  ck0(sinfo_skycor(config, obj_frm,sky_frm,sqc,&obj_cor,&int_obj),
+     "determining sky residuals corrected object");
+  sinfo_msg("Write out adjusted cube");
+  /* Set the file name */
+
+  cpl_frameset_erase(set,obj_tag);
+  cpl_frameset_erase(set,PRO_OBS_SKY);
+  name_o = "out_obj_cor.fits" ;
+
+
+  /* Create product frame */
+  check_nomsg(product_frame = cpl_frame_new());
+  check_nomsg(cpl_frame_set_filename(product_frame, name_o)) ;
+  check_nomsg(cpl_frame_set_tag(product_frame, obj_tag)) ;
+  check_nomsg(cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_IMAGE)) ;
+  check_nomsg(cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT)) ;
+  check(cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL),
+        "Error while initialising the product frame") ;
+  // Add DataFlow keywords 
+
+    /*
+    check(plist=cpl_propertylist_load(name_o,0),
+          "Cannot read the FITS header") ;
+    check_nomsg(cpl_propertylist_erase_regexp(plist, "^ESO PRO CATG",0));
+    check(cpl_dfs_setup_product_header(plist, 
+                                       product_frame, 
+                                       set, 
+                                       parlist,
+                                       "sinfo_utl_skycor", 
+                                       "SINFONI", 
+                                       KEY_VALUE_HPRO_DID),
+        "Problem in the product DFS-compliance") ;
+    */
+
+  //save the file 
+
+  check(cpl_imagelist_save(obj_cor, 
+               name_o,
+               CPL_BPP_IEEE_FLOAT, 
+               plist,
+               CPL_IO_DEFAULT),
+    "Could not save product");
+  // Log the saved file in the input frameset 
+  check_nomsg(cpl_frameset_insert(set,cpl_frame_duplicate(product_frame))) ;
+  sinfo_free_frame(&product_frame);
+  /*
+  ck0(sinfo_pro_save_ims(obj_cor,set,set,"out_obj_cor.fits",
+             PRO_OBS_OBJ,NULL,cpl_func,config),
+      "cannot dump cube %s", "obj_cub.fits");
+  */
+    
+
+
+
+  sinfo_free_imagelist(&obj_cor);
+
+
+
+  name_o = "out_obj_int.fits" ;
+
+  /* Create product frame */
+  check_nomsg(product_frame = cpl_frame_new());
+  check_nomsg(cpl_frame_set_filename(product_frame, name_o)) ;
+  check_nomsg(cpl_frame_set_tag(product_frame, PRO_SPECTRA_QC)) ;
+  check_nomsg(cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_TABLE)) ;
+  check_nomsg(cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT)) ;
+  check(cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL),
+      "Error while initialising the product frame") ;
+  check_nomsg(cpl_propertylist_update_string(plist, "ESO PRO CATG",
+              PRO_SPECTRA_QC));
+
+
+    /* Add DataFlow keywords */
+    /*    
+    check(plist=cpl_propertylist_load(name_o,0),
+          "Cannot read the FITS header") ;
+
+    check_nomsg(cpl_propertylist_erase_regexp(plist, "^ESO PRO CATG",0));
+    check(cpl_dfs_setup_product_header(plist, 
+                                       product_frame, 
+                                       set, 
+                                       parlist,
+                                       "sinfo_utl_skycor", 
+                                       "SINFONI", 
+                                       KEY_VALUE_HPRO_DID),
+      "Problem in the product DFS-compliance") ;
+    */
+
+    /* Save the file */
+    check(cpl_table_save(int_obj, plist, NULL, name_o, 0),
+      "Could not save product");
+    sinfo_free_propertylist(&plist) ;
+ 
+    /* Log the saved file in the input frameset */
+    check_nomsg(cpl_frameset_insert(set, cpl_frame_duplicate(product_frame))) ;
+  sinfo_free_frame(&product_frame);
+
+
+
+
+ cleanup:
+  sinfo_free_imagelist(&obj_cor);
+  sinfo_free_table(&int_obj);
+  sinfo_skycor_qc_delete(&sqc);
+  sinfo_free_propertylist(&plist);
+  sinfo_free_frame(&product_frame);
+  if (cpl_error_get_code() != CPL_ERROR_NONE) {
+    return -1;
+  } else {
+    return 0;
+  }
+
+
+}
+/**@}*/
diff --git a/recipes/sinfo_utl_skymap.c b/recipes/sinfo_utl_skymap.c
new file mode 100644
index 0000000..cac24fa
--- /dev/null
+++ b/recipes/sinfo_utl_skymap.c
@@ -0,0 +1,435 @@
+/* $Id: sinfo_utl_skymap.c,v 1.13 2009/01/30 14:56:12 amodigli Exp $
+ *
+ * This file is part of the SINFONI Pipeline
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2009/01/30 14:56:12 $
+ * $Revision: 1.13 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+/*-----------------------------------------------------------------------------
+                                Includes
+ -----------------------------------------------------------------------------*/
+
+/* cpl */
+#include <cpl.h>
+/* irplib */
+#include <irplib_utils.h>
+
+/* sinfoni */
+#include <sinfo_tpl_utils.h>
+#include <sinfo_pfits.h>
+#include <sinfo_tpl_dfs.h>
+#include <sinfo_raw_types.h>
+#include <sinfo_pro_types.h>
+#include <sinfo_functions.h>
+#include <sinfo_key_names.h>
+#include <sinfo_msg.h>
+#include <sinfo_error.h>
+#include <sinfo_utils_wrappers.h>
+/*-----------------------------------------------------------------------------
+                            Functions prototypes
+ ----------------------------------------------------------------------------*/
+
+static int sinfo_utl_skymap_create(cpl_plugin *) ;
+static int sinfo_utl_skymap_exec(cpl_plugin *) ;
+static int sinfo_utl_skymap_destroy(cpl_plugin *) ;
+static int sinfo_utl_skymap(cpl_parameterlist *, cpl_frameset *) ;
+/*-----------------------------------------------------------------------------
+                            Static variables
+ ----------------------------------------------------------------------------*/
+
+static char sinfo_utl_skymap_description[] =
+"This recipe flags as bad pixels sky lines.\n"
+"Input are sky frames with tag SKY\n"
+"Output image is called out_skymap.fits\n"
+"Information on relevant parameters can be found with\n"
+"esorex --params sinfo_utl_skymap\n"
+"esorex --help sinfo_utl_skymap\n"
+"\n";
+
+/*-----------------------------------------------------------------------------
+                                Functions code
+ ----------------------------------------------------------------------------*/
+/*---------------------------------------------------------------------------*/
+/**
+ * @defgroup sinfo_utl_skymap  Recipe to generate a sky map for SINFONI SRTD
+ */
+/*---------------------------------------------------------------------------*/
+
+/**@{*/
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Build the list of available plugins, for this module. 
+  @param    list    the plugin list
+  @return   0 if everything is ok
+
+  This function is exported.
+ */
+/*---------------------------------------------------------------------------*/
+int cpl_plugin_get_info(cpl_pluginlist * list)
+{
+    cpl_recipe  *   recipe = cpl_calloc(1, sizeof *recipe ) ;
+    cpl_plugin  *   plugin = &recipe->interface ;
+
+    cpl_plugin_init(plugin,
+                    CPL_PLUGIN_API,
+                    SINFONI_BINARY_VERSION,
+                    CPL_PLUGIN_TYPE_RECIPE,
+                    "sinfo_utl_skymap",
+                    "Flags sky lines as bad pixels, with map generation",
+                    sinfo_utl_skymap_description,
+                    "Andrea Modigliani",
+                    "Andrea.Modigliani at eso.org",
+                    sinfo_get_license(),
+                    sinfo_utl_skymap_create,
+                    sinfo_utl_skymap_exec,
+                    sinfo_utl_skymap_destroy) ;
+
+    cpl_pluginlist_append(list, plugin) ;
+    
+    return 0;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Setup the recipe options    
+  @param    plugin  the plugin
+  @return   0 if everything is ok
+
+  Create the recipe instance and make it available to the application using 
+  the interface. 
+ */
+/*---------------------------------------------------------------------------*/
+static int sinfo_utl_skymap_create(cpl_plugin * plugin)
+{
+    cpl_recipe      * recipe ;
+    cpl_parameter   * p ;
+
+    /* Get the recipe out of the plugin */
+    if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+        recipe = (cpl_recipe *)plugin ;
+    else return -1 ;
+
+    /* Create the parameters list in the cpl_recipe object */
+    recipe->parameters = cpl_parameterlist_new() ; 
+
+    /* Fill the parameters list */
+
+
+    /* --doubleopt */
+    p = cpl_parameter_new_range("sinfoni.sinfo_utl_skymap.xsize", 
+            CPL_TYPE_INT, "X box size", "sinfoni.sinfo_utl_skymap", 1,1,2047) ;
+    cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "xsize") ;
+    cpl_parameterlist_append(recipe->parameters, p) ;
+
+    /* --doubleopt */
+    p = cpl_parameter_new_range("sinfoni.sinfo_utl_skymap.ysize", 
+            CPL_TYPE_INT, "Y box size", "sinfoni.sinfo_utl_skymap", 30,1,2047) ;
+    cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "ysize") ;
+    cpl_parameterlist_append(recipe->parameters, p) ;
+
+
+
+    /* --doubleopt */
+    p = cpl_parameter_new_value("sinfoni.sinfo_utl_skymap.threshold", 
+            CPL_TYPE_DOUBLE, "Threshold", "sinfoni.sinfo_utl_skymap", 30.) ;
+    cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "thresh") ;
+    cpl_parameterlist_append(recipe->parameters, p) ;
+
+    /* Return */
+    return 0;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Execute the plugin instance given by the interface
+  @param    plugin  the plugin
+  @return   0 if everything is ok
+ */
+/*---------------------------------------------------------------------------*/
+static int sinfo_utl_skymap_exec(cpl_plugin * plugin)
+{
+    cpl_recipe  *   recipe ;
+    int code=0;
+    cpl_errorstate initial_errorstate = cpl_errorstate_get();
+
+    /* Get the recipe out of the plugin */
+    if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+        recipe = (cpl_recipe *)plugin ;
+    else return -1 ;
+    cpl_error_reset();
+    //irplib_reset();
+    check_nomsg(code = sinfo_utl_skymap(recipe->parameters, recipe->frames)) ;
+    if (!cpl_errorstate_is_equal(initial_errorstate)) {                      
+        /* Dump the error history since recipe execution start.                
+           At this point the recipe cannot recover from the error */           
+        cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);              
+    } 
+  cleanup:
+    return code ;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Destroy what has been created by the 'create' function
+  @param    plugin  the plugin
+  @return   0 if everything is ok
+ */
+/*---------------------------------------------------------------------------*/
+static int sinfo_utl_skymap_destroy(cpl_plugin * plugin)
+{
+    cpl_recipe  *   recipe ;
+    
+    /* Get the recipe out of the plugin */
+    if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+        recipe = (cpl_recipe *)plugin ;
+    else return -1 ;
+
+    cpl_parameterlist_delete(recipe->parameters) ; 
+    return 0 ;
+}
+
+static int sinfo_utl_skymap(
+        cpl_parameterlist   *   parlist, 
+        cpl_frameset        *   framelist)
+{
+    cpl_parameter       *   param =NULL;
+    const char *            name_i=NULL;
+    int                    xsize=0;
+    int                    ysize=0;
+
+    cpl_frame           *   sky_frm=NULL;
+
+    const char          *   name_o=NULL ;
+    cpl_propertylist    *   plist =NULL;
+    cpl_frame           *   product_frame=NULL;
+    cpl_frameset        *   sky_set=NULL;
+    cpl_image           *   sky_ima=NULL;
+    cpl_image           *   sky_map=NULL;
+    double threshold=0;
+    int i=0;
+    int j=0;
+    double sinfo_median=0;
+    float* sky_ima_pix=NULL;
+    float* sky_map_pix=NULL;
+    int nx=0;
+    int ny=0;
+    int n=0;
+  
+    /* HOW TO RETRIEVE INPUT PARAMETERS */
+    /* --stropt */
+
+      sinfo_msg("Welcome to SINFONI Pipeline release %d.%d.%d",
+        SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
+
+    param = cpl_parameterlist_find(parlist, 
+                                   "sinfoni.sinfo_utl_skymap.out_filename");
+    name_o = "out_skymap.fits";
+
+    /* --intopt */
+    param = cpl_parameterlist_find(parlist,"sinfoni.sinfo_utl_skymap.xsize");
+    xsize = cpl_parameter_get_int(param) ;
+
+    /* --intopt */
+    param = cpl_parameterlist_find(parlist,"sinfoni.sinfo_utl_skymap.ysize");
+    ysize = cpl_parameter_get_int(param) ;
+  
+    param = cpl_parameterlist_find(parlist,
+				   "sinfoni.sinfo_utl_skymap.threshold");
+    threshold = cpl_parameter_get_double(param) ;
+ 
+    /* Identify the RAW and CALIB frames in the input frameset */
+    if (sinfo_dfs_set_groups(framelist)) {
+        sinfo_msg_error("Cannot identify RAW and CALIB frames") ;
+        return -1 ;
+    }
+    
+    /* HOW TO ACCESS INPUT DATA */
+    n=cpl_frameset_get_size(framelist);
+    if(n<1) {
+      sinfo_msg_error("Empty input frame list!");
+      return -1;
+    }
+    sky_set=cpl_frameset_new();
+    sinfo_extract_frames_type(framelist,sky_set,RAW_SKY);
+
+    n=cpl_frameset_get_size(framelist);
+    if(n<1) {
+      sinfo_msg_error("No sky frames in input list!");
+      sinfo_free_frameset(&sky_set);
+      return -1;
+    }
+
+
+    check_nomsg(sky_frm = cpl_frameset_get_frame(sky_set,0));
+
+   if ((plist=cpl_propertylist_load(cpl_frame_get_filename(sky_frm), 
+                    0)) == NULL) {
+        sinfo_msg_error("Cannot read the FITS header") ;
+        return -1 ;
+    }
+  
+
+    name_i=cpl_frame_get_filename(sky_frm);
+    sky_ima = cpl_image_load(name_i,CPL_TYPE_FLOAT,0,0);
+    sky_map=cpl_image_duplicate(sky_ima);
+    sky_ima_pix=cpl_image_get_data(sky_ima);
+    sky_map_pix=cpl_image_get_data(sky_map);
+    nx = cpl_image_get_size_x(sky_ima);
+    ny = cpl_image_get_size_y(sky_ima);
+    if (nx != SIZEX || ny != SIZEY) {
+       sinfo_msg_error("nx=%d ny=%d, expected nx=%d ny=%d",nx,ny,SIZEX,SIZEY);
+       goto cleanup;
+
+    }
+    for(i=1;i<nx;i++) {
+
+       for(j=ysize+1;j<ny-ysize;j++) {
+
+          sinfo_median=cpl_image_get_median_window(sky_ima,i,j-ysize,i,j+xsize);
+          if(cpl_error_get_code() != CPL_ERROR_NONE) {
+             sinfo_msg_error("Exit");
+             sinfo_free_image(&sky_ima);
+             sinfo_free_image(&sky_map);
+             sinfo_free_propertylist(&plist);
+             sinfo_free_frameset(&sky_set);
+             return -1;
+      }
+      if(sky_ima_pix[i+j*nx] > sinfo_median+threshold) {
+        sky_map_pix[i+j*nx]=0.;
+      } else {
+        sky_map_pix[i+j*nx]=1.;
+      }
+       }
+
+    }
+
+
+
+    for(i=1;i<nx;i++) {
+
+       for(j=0;j<ysize+1;j++) {
+
+             sky_map_pix[i+j*nx]=0.;
+
+       }
+
+       for(j=ny-ysize+1;j<ny;j++) {
+
+             sky_map_pix[i+j*nx]=0.;
+
+       }
+
+    }
+
+
+
+    /* Now performing the data reduction */
+    /* Let's generate one image for the example */
+
+
+    
+    /* HOW TO SAVE A PRODUCT ON DISK  */
+    /* Set the file name */
+    name_o = "sky_map.fits" ;
+
+    /* Create product frame */
+    product_frame = cpl_frame_new();
+    cpl_frame_set_filename(product_frame, name_o) ;
+    cpl_frame_set_tag(product_frame, PRO_SKY_DUMMY) ;
+    cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_IMAGE) ;
+    cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT) ;
+    cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL) ;
+
+    if (cpl_error_get_code()) {
+        sinfo_msg_error("Error while initialising the product frame") ;
+        sinfo_free_propertylist(&plist) ;
+        sinfo_free_frame(&product_frame) ;
+        return -1 ;
+    }
+
+    /* Add DataFlow keywords */
+#if defined CPL_VERSION_CODE && CPL_VERSION_CODE >= CPL_VERSION(4, 8, 0)     
+    if (cpl_dfs_setup_product_header(plist, product_frame, framelist, parlist,
+				     "sinfo_utl_skymap", 
+				     "SINFONI", KEY_VALUE_HPRO_DID,NULL) 
+	!= CPL_ERROR_NONE) {
+        sinfo_msg_error("Problem in the product DFS-compliance") ;
+        sinfo_free_propertylist(&plist) ;
+        sinfo_free_frame(&product_frame) ;
+        sinfo_free_image(&sky_ima);
+        sinfo_free_image(&sky_map);
+        sinfo_free_frameset(&sky_set);
+        return -1 ;
+    }
+#else
+    if (cpl_dfs_setup_product_header(plist, product_frame, framelist, parlist,
+				     "sinfo_utl_skymap", 
+				     "SINFONI", KEY_VALUE_HPRO_DID) 
+	!= CPL_ERROR_NONE) {
+        sinfo_msg_error("Problem in the product DFS-compliance") ;
+        sinfo_free_propertylist(&plist) ;
+        sinfo_free_frame(&product_frame) ;
+        sinfo_free_image(&sky_ima);
+        sinfo_free_image(&sky_map);
+        sinfo_free_frameset(&sky_set);
+        return -1 ;
+    }
+#endif    
+
+
+    /* Save the file */
+    if (cpl_image_save(sky_map, name_o, CPL_BPP_IEEE_FLOAT, plist,
+                       CPL_IO_DEFAULT) != CPL_ERROR_NONE) {
+        sinfo_msg_error("Could not save product");
+        sinfo_free_propertylist(&plist) ;
+        sinfo_free_frame(&product_frame) ;
+        sinfo_free_image(&sky_map) ;
+        return -1 ;
+    }
+    sinfo_free_propertylist(&plist) ;
+    sinfo_free_image(&sky_map) ;
+    sinfo_free_image(&sky_ima) ;
+
+    /* Log the saved file in the input frameset */
+    cpl_frameset_insert(framelist, product_frame) ;
+    sinfo_free_frameset(&sky_set);
+   
+
+
+  cleanup:
+    sinfo_free_image(&sky_ima);
+    sinfo_free_image(&sky_map);
+    sinfo_free_propertylist(&plist);
+    sinfo_free_frameset(&sky_set);
+
+    if(  cpl_error_get_code()!=CPL_ERROR_NONE) {
+        return -1 ;
+    } else {
+        return 0 ;
+    }
+}
+/**@}*/
diff --git a/recipes/sinfo_utl_spectrum_divide_by_blackbody.c b/recipes/sinfo_utl_spectrum_divide_by_blackbody.c
new file mode 100644
index 0000000..383e7ca
--- /dev/null
+++ b/recipes/sinfo_utl_spectrum_divide_by_blackbody.c
@@ -0,0 +1,208 @@
+/* $Id: sinfo_utl_spectrum_divide_by_blackbody.c,v 1.10 2007/10/26 09:40:28 amodigli Exp $
+ *
+ * This file is part of the SINFONI Pipeline
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2007/10/26 09:40:28 $
+ * $Revision: 1.10 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+/*-----------------------------------------------------------------------------
+                                Includes
+ ----------------------------------------------------------------------------*/
+
+/* cpl */
+#include <cpl.h>
+ 
+/* irplib */
+#include <irplib_utils.h>
+#include <string.h>
+#include <sinfo_tpl_utils.h>
+#include <sinfo_pfits.h>
+#include <sinfo_tpl_dfs.h>
+#include <sinfo_msg.h>
+#include <sinfo_utl_spectrum_divide_by_blackbody.h>
+/*-----------------------------------------------------------------------------
+                            Functions prototypes
+ ----------------------------------------------------------------------------*/
+
+static int sinfo_utl_spectrum_divide_by_blackbody_create(cpl_plugin *) ;
+static int sinfo_utl_spectrum_divide_by_blackbody_exec(cpl_plugin *) ;
+static int sinfo_utl_spectrum_divide_by_blackbody_destroy(cpl_plugin *) ;
+
+/*-----------------------------------------------------------------------------
+                            Static variables
+ ----------------------------------------------------------------------------*/
+
+static char sinfo_utl_spectrum_divide_by_blackbody_description1[] =
+"This recipe divides a spectrum by a black body "
+"spectrum of given temperature.\n"
+"The input file is a spectrum. Its associated tag must be SPECTRUM.\n"
+"The output is a spectrum\n";
+
+
+static char sinfo_utl_spectrum_divide_by_blackbody_description2[] =
+"Parameter is \n"
+"sinfoni.sinfo_utl_spectrum_divide_by_blackbody.temperature\n"
+"having aliases 'temp' \n"
+"Information on relevant parameters can be found with\n"
+"esorex --params sinfo_utl_spectrum_divide_by_blackbody\n"
+"esorex --help sinfo_utl_spectrum_divide_by_blackbody\n"
+"\n";
+
+static char sinfo_utl_spectrum_divide_by_blackbody_description[900];
+
+/*-----------------------------------------------------------------------------
+                                Functions code
+ ----------------------------------------------------------------------------*/
+/*---------------------------------------------------------------------------*/
+/**
+ * @defgroup sinfo_utl_spectrum_divide_by_blackbody  Recipe to correct a \
+   spectrum from the blackbody thermal emission 
+ */
+/*---------------------------------------------------------------------------*/
+/**@{*/
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Build the list of available plugins, for this module. 
+  @param    list    the plugin list
+  @return   0 if everything is ok
+
+  This function is exported.
+ */
+/*---------------------------------------------------------------------------*/
+int cpl_plugin_get_info(cpl_pluginlist * list)
+{
+    cpl_recipe  *   recipe = cpl_calloc(1, sizeof *recipe ) ;
+    cpl_plugin  *   plugin = &recipe->interface ;
+
+    strcpy(sinfo_utl_spectrum_divide_by_blackbody_description,
+           sinfo_utl_spectrum_divide_by_blackbody_description1);
+    strcat(sinfo_utl_spectrum_divide_by_blackbody_description,
+           sinfo_utl_spectrum_divide_by_blackbody_description2);
+
+    cpl_plugin_init(plugin,
+                    CPL_PLUGIN_API,
+                    SINFONI_BINARY_VERSION,
+                    CPL_PLUGIN_TYPE_RECIPE,
+                    "sinfo_utl_spectrum_divide_by_blackbody",
+                    "Spectrum normalization by a blackbody",
+                    sinfo_utl_spectrum_divide_by_blackbody_description,
+                    "Andrea Modigliani",
+                    "Andrea.Modigliani at eso.org",
+                    sinfo_get_license(),
+                    sinfo_utl_spectrum_divide_by_blackbody_create,
+                    sinfo_utl_spectrum_divide_by_blackbody_exec,
+                    sinfo_utl_spectrum_divide_by_blackbody_destroy) ;
+
+    cpl_pluginlist_append(list, plugin) ;
+    
+    return 0;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Setup the recipe options    
+  @param    plugin  the plugin
+  @return   0 if everything is ok
+
+  Create the recipe instance and make it available to the application using 
+  the interface. 
+ */
+/*---------------------------------------------------------------------------*/
+static int sinfo_utl_spectrum_divide_by_blackbody_create(cpl_plugin * plugin)
+{
+    cpl_recipe      * recipe ;
+    cpl_parameter   * p ;
+
+    /* Get the recipe out of the plugin */
+    if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+        recipe = (cpl_recipe *)plugin ;
+    else return -1 ;
+
+    cpl_error_reset();
+    irplib_reset();
+    /* Create the parameters list in the cpl_recipe object */
+    recipe->parameters = cpl_parameterlist_new() ; 
+
+    /* Fill the parameters list */
+    /* --stropt */
+    /* --doubleopt */
+    p = cpl_parameter_new_value("sinfoni.sinfo_utl_spectrum_divide_by_blackbody.temperature", 
+            CPL_TYPE_DOUBLE, "Black Body Temperature", 
+            "sinfoni.sinfo_utl_spectrum_divide_by_blackbody", 100000.) ;
+    cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "temp") ;
+    cpl_parameterlist_append(recipe->parameters, p) ;
+
+    /* Return */
+    return 0;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Execute the plugin instance given by the interface
+  @param    plugin  the plugin
+  @return   0 if everything is ok
+ */
+/*---------------------------------------------------------------------------*/
+static int sinfo_utl_spectrum_divide_by_blackbody_exec(cpl_plugin * plugin)
+{
+    cpl_recipe  *   recipe ;
+    int code=0;
+
+    /* Get the recipe out of the plugin */
+    if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+        recipe = (cpl_recipe *)plugin ;
+    else return -1 ;
+ 
+       sinfo_msg("Welcome to SINFONI Pipeline release %d.%d.%d",
+        SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
+    code=sinfo_utl_spectrum_divide_by_blackbody(recipe->parameters, 
+                                                  recipe->frames) ;
+    return code;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Destroy what has been created by the 'create' function
+  @param    plugin  the plugin
+  @return   0 if everything is ok
+ */
+/*---------------------------------------------------------------------------*/
+static int sinfo_utl_spectrum_divide_by_blackbody_destroy(cpl_plugin * plugin)
+{
+    cpl_recipe  *   recipe ;
+    
+    /* Get the recipe out of the plugin */
+    if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+        recipe = (cpl_recipe *)plugin ;
+    else return -1 ;
+
+    cpl_parameterlist_delete(recipe->parameters) ; 
+    return 0 ;
+}
+
+/**@}*/
diff --git a/recipes/sinfo_utl_spectrum_wavelength_shift.c b/recipes/sinfo_utl_spectrum_wavelength_shift.c
new file mode 100644
index 0000000..aeb7755
--- /dev/null
+++ b/recipes/sinfo_utl_spectrum_wavelength_shift.c
@@ -0,0 +1,223 @@
+/* $Id: sinfo_utl_spectrum_wavelength_shift.c,v 1.11 2007/10/26 09:40:28 amodigli Exp $
+ *
+ * This file is part of the SINFONI Pipeline
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2007/10/26 09:40:28 $
+ * $Revision: 1.11 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+/*-----------------------------------------------------------------------------
+                                Includes
+ -----------------------------------------------------------------------------*/
+#include <string.h>
+/* irplib */
+#include <cpl.h>
+ 
+/* irplib */
+#include <irplib_utils.h>
+#include <sinfo_msg.h>
+
+#include <sinfo_tpl_utils.h>
+#include <sinfo_pfits.h>
+#include <sinfo_tpl_dfs.h>
+#include <sinfo_utl_spectrum_wavelength_shift.h>
+/*-----------------------------------------------------------------------------
+                            Functions prototypes
+ ----------------------------------------------------------------------------*/
+
+static int sinfo_utl_spectrum_wavelength_shift_create(cpl_plugin *) ;
+static int sinfo_utl_spectrum_wavelength_shift_exec(cpl_plugin *) ;
+static int sinfo_utl_spectrum_wavelength_shift_destroy(cpl_plugin *) ;
+
+/*-----------------------------------------------------------------------------
+                            Static variables
+ ----------------------------------------------------------------------------*/
+
+static char sinfo_utl_spectrum_wavelength_shift_description1[] =
+"This recipe shifts a spectrum in wavelength using a given \n"
+"interpolation method. The input file is a spectrum.\n"
+"Its associated tag should be SPECTRUM.\n"
+"The output is a spectrum shifted by a given amount. \n";
+
+static char sinfo_utl_spectrum_wavelength_shift_description2[] =
+"Parameters are \n"
+"sinfoni.sinfo_utl_spectrum_arith.method\n"
+"sinfoni.sinfo_utl_spectrum_wavelength_shift.shift\n"
+"having aliases 'method' and 'shift' \n"
+"Information on relevant parameters can be found with\n"
+"esorex --params sinfo_utl_spectrum_wavelength_shift\n"
+"esorex --help sinfo_utl_spectrum_wavelength_shift\n"
+"\n";
+
+static char sinfo_utl_spectrum_wavelength_shift_description[900];
+
+/*-----------------------------------------------------------------------------
+                                Functions code
+ ----------------------------------------------------------------------------*/
+/*---------------------------------------------------------------------------*/
+/**
+ * @defgroup sinfo_utl_spectrum_wavelength_shift  \
+   Recipe to shift a spectrum in  wavelength
+ */
+/*---------------------------------------------------------------------------*/
+/**@{*/
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Build the list of available plugins, for this module. 
+  @param    list    the plugin list
+  @return   0 if everything is ok
+
+  This function is exported.
+ */
+/*---------------------------------------------------------------------------*/
+int cpl_plugin_get_info(cpl_pluginlist * list)
+{
+    cpl_recipe  *   recipe = cpl_calloc(1, sizeof *recipe ) ;
+    cpl_plugin  *   plugin = &recipe->interface ;
+
+    strcpy(sinfo_utl_spectrum_wavelength_shift_description,
+           sinfo_utl_spectrum_wavelength_shift_description1);
+    strcat(sinfo_utl_spectrum_wavelength_shift_description,
+           sinfo_utl_spectrum_wavelength_shift_description2);
+
+    cpl_plugin_init(plugin,
+                    CPL_PLUGIN_API,
+                    SINFONI_BINARY_VERSION,
+                    CPL_PLUGIN_TYPE_RECIPE,
+                    "sinfo_utl_spectrum_wavelength_shift",
+                    "Spectrum wavelength shift",
+                    sinfo_utl_spectrum_wavelength_shift_description,
+                    "Andrea Modigliani",
+                    "Andrea.Modigliani at eso.org",
+                    sinfo_get_license(),
+                    sinfo_utl_spectrum_wavelength_shift_create,
+                    sinfo_utl_spectrum_wavelength_shift_exec,
+                    sinfo_utl_spectrum_wavelength_shift_destroy) ;
+
+    cpl_pluginlist_append(list, plugin) ;
+    
+    return 0;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Setup the recipe options    
+  @param    plugin  the plugin
+  @return   0 if everything is ok
+
+  Create the recipe instance and make it available to the application using the 
+  interface. 
+ */
+/*---------------------------------------------------------------------------*/
+static int sinfo_utl_spectrum_wavelength_shift_create(cpl_plugin * plugin)
+{
+    cpl_recipe      * recipe ;
+    cpl_parameter   * p ;
+
+    /* Get the recipe out of the plugin */
+    if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+        recipe = (cpl_recipe *)plugin ;
+    else return -1 ;
+    cpl_error_reset();
+    irplib_reset();
+
+    /* Create the parameters list in the cpl_recipe object */
+    recipe->parameters = cpl_parameterlist_new() ; 
+
+    /* Fill the parameters list */
+     /* --stropt */
+    p = cpl_parameter_new_value("sinfoni.sinfo_utl_spectrum_arith.method", 
+                                CPL_TYPE_STRING, 
+                                "A spectral shift method: "
+                                "'S' (Spline),'P' (Polynomial)", 
+                                "sinfoni.sinfo_utl_spectrum_arith","S");
+    cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "method") ;
+    cpl_parameterlist_append(recipe->parameters, p) ;
+
+    /* --doubleopt */
+    p = cpl_parameter_new_value("sinfoni.sinfo_utl_spectrum_wavelength_shift.shift", 
+                                CPL_TYPE_DOUBLE, 
+                                "wavelength shift in micron", 
+                                "sinfoni.sinfo_utl_spectrum_wavelength_shift", 
+                                0.1) ;
+    cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "shift") ;
+    cpl_parameterlist_append(recipe->parameters, p) ;
+
+    /* Return */
+    return 0;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Execute the plugin instance given by the interface
+  @param    plugin  the plugin
+  @return   0 if everything is ok
+ */
+/*---------------------------------------------------------------------------*/
+static int sinfo_utl_spectrum_wavelength_shift_exec(cpl_plugin * plugin)
+{
+    cpl_recipe  *   recipe ;
+    int code=0;
+    cpl_errorstate initial_errorstate = cpl_errorstate_get();
+
+    /* Get the recipe out of the plugin */
+    if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+        recipe = (cpl_recipe *)plugin ;
+    else return -1 ;
+      sinfo_msg("Welcome to SINFONI Pipeline release %d.%d.%d",
+       SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
+    code = sinfo_utl_spectrum_wavelength_shift(recipe->parameters, 
+                                               recipe->frames) ;
+    if (!cpl_errorstate_is_equal(initial_errorstate)) {                      
+        /* Dump the error history since recipe execution start.                
+           At this point the recipe cannot recover from the error */           
+        cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);              
+    } 
+    return code ;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Destroy what has been created by the 'create' function
+  @param    plugin  the plugin
+  @return   0 if everything is ok
+ */
+/*---------------------------------------------------------------------------*/
+static int sinfo_utl_spectrum_wavelength_shift_destroy(cpl_plugin * plugin)
+{
+    cpl_recipe  *   recipe ;
+    
+    /* Get the recipe out of the plugin */
+    if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
+        recipe = (cpl_recipe *)plugin ;
+    else return -1 ;
+
+    cpl_parameterlist_delete(recipe->parameters) ; 
+    return 0 ;
+}
+
+/**@}*/
diff --git a/recipes/tests/Makefile.am b/recipes/tests/Makefile.am
new file mode 100644
index 0000000..49bb876
--- /dev/null
+++ b/recipes/tests/Makefile.am
@@ -0,0 +1,172 @@
+## Process this file with automake to produce Makefile.in
+
+##   This file is part of the SINFONI Pipeline Library
+##   Copyright (C) 2002,2003 European Southern Observatory
+
+##   This library is free software; you can redistribute it and/or modify
+##   it under the terms of the GNU General Public License as published by
+##   the Free Software Foundation; either version 2 of the License, or
+##   (at your option) any later version.
+
+##   This program is distributed in the hope that it will be useful,
+##   but WITHOUT ANY WARRANTY; without even the implied warranty of
+##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+##   GNU General Public License for more details.
+
+##   You should have received a copy of the GNU General Public License
+##   along with this program; if not, write to the Free Software
+##   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+
+AUTOMAKE_OPTIONS = 1.8 foreign
+
+DISTCLEANFILES = *~ .logfile
+
+
+if MAINTAINER_MODE
+
+MAINTAINERCLEANFILES = Makefile.in
+
+endif
+
+LIBSINFO = $(top_builddir)/sinfoni/libsinfo.la \
+          $(top_builddir)/irplib/libirplib.la
+
+OBJDIR = $(top_builddir)/recipes/.libs
+
+INCLUDES = $(all_includes)
+LDADD = $(LIBSINFO)
+
+check_PROGRAMS = sinfo_rec_detlin-test \
+                 sinfo_rec_distortion-test \
+                 sinfo_rec_jitter-test \
+                 sinfo_utl_cube2ima-test \
+                 sinfo_utl_cube2spectrum-test \
+		 sinfo_utl_spectrum_divide_by_blackbody-test 
+#                 sinfo_rec_mdark-test 
+#                 sinfo_rec_mdark_detmon-test \
+#                 sinfo_rec_lingain-test \
+#                 sinfo_rec_wavecal-test \
+#                 sinfo_rec_mflat-test \
+#		 sinfo_utl_skycor-test      \
+#                 sinfo_rec_pupil-test \
+#		 sinfo_utl_spectrum_wavelength_shift-test 
+#		 sinfo_utl_cube_arith-test  \
+#		 sinfo_utl_cube_combine-test \
+#		 sinfo_utl_cube_create-test \
+#		 sinfo_utl_ima_arith-test   \
+#		 sinfo_utl_skymap-test      \
+#                sinfo_utl_bp_mask_add-test \
+#		 sinfo_utl_ima_line_corr-test \
+#		 sinfo_utl_seds-test        \
+#		 sinfo_utl_stdstars-test    
+
+
+sinfo_rec_detlin_test_SOURCES = recipe_main.c
+sinfo_rec_detlin_test_LDADD   = $(OBJDIR)/sinfo_rec_detlin.o  $(LDADD) $(LIBALL)
+
+#sinfo_rec_lingain_test_SOURCES = recipe_main.c
+#sinfo_rec_lingain_test_LDADD   = $(OBJDIR)/sinfo_rec_lingain.o  $(LDADD) $(LIBALL)
+
+
+sinfo_rec_distortion_test_SOURCES = recipe_main.c
+sinfo_rec_distortion_test_LDADD   = $(OBJDIR)/sinfo_rec_distortion.o  $(LDADD) $(LIBALL)
+
+
+#sinfo_rec_mdark_test_SOURCES = recipe_main.c
+#sinfo_rec_mdark_test_LDADD   = $(OBJDIR)/sinfo_rec_mdark.o  $(LDADD) $(LIBALL)
+
+#sinfo_rec_mdark_detmon_test_SOURCES = recipe_main.c
+#sinfo_rec_mdark_detmon_test_LDADD   = $(OBJDIR)/sinfo_rec_mdark_detmon.o  $(LDADD) $(LIBALL)
+
+
+#sinfo_rec_mflat_test_SOURCES = recipe_main.c
+#sinfo_rec_mflat_test_LDADD   = $(OBJDIR)/sinfo_rec_mflat.o  $(LDADD) $(LIBALL)
+
+
+#sinfo_rec_wavecal_test_SOURCES = recipe_main.c
+#sinfo_rec_wavecal_test_LDADD   = $(OBJDIR)/sinfo_rec_wavecal.o  $(LDADD) $(LIBALL)
+
+
+sinfo_rec_jitter_test_SOURCES = recipe_main.c
+sinfo_rec_jitter_test_LDADD   = $(OBJDIR)/sinfo_rec_jitter.o  $(LDADD) $(LIBALL)
+
+#sinfo_rec_pupil_test_SOURCES = recipe_main.c
+#sinfo_rec_pupil_test_LDADD   = $(OBJDIR)/sinfo_rec_pupil.o  $(LDADD) $(LIBALL)
+
+
+#sinfo_utl_bp_mask_add_test_SOURCES = recipe_main.c
+#sinfo_utl_bp_mask_add_test_LDADD   = $(OBJDIR)/sinfo_utl_bp_mask_add.o  $(LDADD) $(LIBALL)
+
+
+
+sinfo_utl_cube2ima_test_SOURCES = recipe_main.c
+sinfo_utl_cube2ima_test_LDADD   = $(OBJDIR)/sinfo_utl_cube2ima.o  $(LDADD) $(LIBALL)
+
+
+sinfo_utl_cube2spectrum_test_SOURCES = recipe_main.c
+sinfo_utl_cube2spectrum_test_LDADD   = $(OBJDIR)/sinfo_utl_cube2spectrum.o  $(LDADD) $(LIBALL)
+
+
+#sinfo_utl_cube_arith_test_SOURCES = recipe_main.c
+#sinfo_utl_cube_arith_test_LDADD   = $(OBJDIR)/sinfo_utl_cube_arith.o  $(LDADD) $(LIBALL)
+
+
+#sinfo_utl_cube_combine_test_SOURCES = recipe_main.c
+#sinfo_utl_cube_combine_test_LDADD   = $(OBJDIR)/sinfo_utl_cube_combine.o  $(LDADD) $(LIBALL)
+
+
+#sinfo_utl_cube_create_test_SOURCES = recipe_main.c
+#sinfo_utl_cube_create_test_LDADD   = $(OBJDIR)/sinfo_utl_cube_create.o  $(LDADD) $(LIBALL)
+
+
+#sinfo_utl_ima_arith_test_SOURCES = recipe_main.c
+#sinfo_utl_ima_arith_test_LDADD   = $(OBJDIR)/sinfo_utl_ima_arith.o  $(LDADD) $(LIBALL)
+
+
+#sinfo_utl_ima_line_corr_test_SOURCES = recipe_main.c
+#sinfo_utl_ima_line_corr_test_LDADD   = $(OBJDIR)/sinfo_utl_ima_line_corr.o  $(LDADD) $(LIBALL)
+
+
+
+#sinfo_utl_skymap_test_SOURCES = recipe_main.c
+#sinfo_utl_skymap_test_LDADD   = $(OBJDIR)/sinfo_utl_skymap.o  $(LDADD) $(LIBALL)
+
+
+#sinfo_utl_skycor_test_SOURCES = recipe_main.c
+#sinfo_utl_skycor_test_LDADD   = $(OBJDIR)/sinfo_utl_skycor.o  $(LDADD) $(LIBALL)
+
+
+sinfo_utl_spectrum_divide_by_blackbody_test_SOURCES = recipe_main.c
+sinfo_utl_spectrum_divide_by_blackbody_test_LDADD   = $(OBJDIR)/sinfo_utl_spectrum_divide_by_blackbody.o  $(LDADD) $(LIBALL)
+
+
+#sinfo_utl_spectrum_wavelength_shift_test_SOURCES = recipe_main.c
+#sinfo_utl_spectrum_wavelength_shift_test_LDADD   = $(OBJDIR)/sinfo_utl_spectrum_wavelength_shift.o  $(LDADD) $(LIBALL)
+
+
+#sinfo_utl_seds_test_SOURCES = recipe_main.c
+#sinfo_utl_seds_test_LDADD   = $(OBJDIR)/sinfo_utl_seds.o  $(LDADD) $(LIBALL)
+
+#sinfo_utl_stdstars_test_SOURCES = recipe_main.c
+#sinfo_utl_stdstars_test_LDADD   = $(OBJDIR)/sinfo_utl_stdstars.o  $(LDADD) $(LIBALL)
+
+
+
+
+# Be sure to reexport important environment variables.
+# - And be sure the find the dynamic libraries
+TESTS_ENVIRONMENT = MAKE="$(MAKE)" CC="$(CC)" CFLAGS="$(CFLAGS)" \
+        CPPFLAGS="$(CPPFLAGS)" LD="$(LD)" LDFLAGS="$(LDFLAGS)" \
+        LIBS="$(LIBS)" LN_S="$(LN_S)" NM="$(NM)" RANLIB="$(RANLIB)" \
+        LD_LIBRARY_PATH="$(top_builddir)/sinfoni/.libs:$(top_builddir)/irplib/.libs:$(LD_LIBRARY_PATH)" \
+        OBJEXT="$(OBJEXT)" EXEEXT="$(EXEEXT)"
+
+TESTS = $(check_PROGRAMS)
+
+# We need to remove any files that the above tests created.
+clean-local:
+	$(RM) *.paf *.fits
+
+if PURIFY
+include $(top_builddir)/Makefile.purify
+endif
diff --git a/recipes/tests/Makefile.in b/recipes/tests/Makefile.in
new file mode 100644
index 0000000..dddcd84
--- /dev/null
+++ b/recipes/tests/Makefile.in
@@ -0,0 +1,770 @@
+# Makefile.in generated by automake 1.11 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009  Free Software Foundation,
+# Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+ at SET_MAKE@
+VPATH = @srcdir@
+pkgdatadir = $(datadir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkglibexecdir = $(libexecdir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
+target_triplet = @target@
+check_PROGRAMS = sinfo_rec_detlin-test$(EXEEXT) \
+	sinfo_rec_distortion-test$(EXEEXT) \
+	sinfo_rec_jitter-test$(EXEEXT) \
+	sinfo_utl_cube2ima-test$(EXEEXT) \
+	sinfo_utl_cube2spectrum-test$(EXEEXT) \
+	sinfo_utl_spectrum_divide_by_blackbody-test$(EXEEXT)
+subdir = recipes/tests
+DIST_COMMON = README $(srcdir)/Makefile.am $(srcdir)/Makefile.in
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/m4macros/cpl.m4 \
+	$(top_srcdir)/m4macros/eso.m4 \
+	$(top_srcdir)/m4macros/libtool.m4 \
+	$(top_srcdir)/m4macros/ltoptions.m4 \
+	$(top_srcdir)/m4macros/ltsugar.m4 \
+	$(top_srcdir)/m4macros/ltversion.m4 \
+	$(top_srcdir)/m4macros/lt~obsolete.m4 \
+	$(top_srcdir)/m4macros/purify.m4 $(top_srcdir)/acinclude.m4 \
+	$(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+	$(ACLOCAL_M4)
+mkinstalldirs = $(install_sh) -d
+CONFIG_HEADER = $(top_builddir)/config.h
+CONFIG_CLEAN_FILES =
+CONFIG_CLEAN_VPATH_FILES =
+am_sinfo_rec_detlin_test_OBJECTS = recipe_main.$(OBJEXT)
+sinfo_rec_detlin_test_OBJECTS = $(am_sinfo_rec_detlin_test_OBJECTS)
+sinfo_rec_detlin_test_DEPENDENCIES = $(OBJDIR)/sinfo_rec_detlin.o \
+	$(LDADD)
+am_sinfo_rec_distortion_test_OBJECTS = recipe_main.$(OBJEXT)
+sinfo_rec_distortion_test_OBJECTS =  \
+	$(am_sinfo_rec_distortion_test_OBJECTS)
+sinfo_rec_distortion_test_DEPENDENCIES =  \
+	$(OBJDIR)/sinfo_rec_distortion.o $(LDADD)
+am_sinfo_rec_jitter_test_OBJECTS = recipe_main.$(OBJEXT)
+sinfo_rec_jitter_test_OBJECTS = $(am_sinfo_rec_jitter_test_OBJECTS)
+sinfo_rec_jitter_test_DEPENDENCIES = $(OBJDIR)/sinfo_rec_jitter.o \
+	$(LDADD)
+am_sinfo_utl_cube2ima_test_OBJECTS = recipe_main.$(OBJEXT)
+sinfo_utl_cube2ima_test_OBJECTS =  \
+	$(am_sinfo_utl_cube2ima_test_OBJECTS)
+sinfo_utl_cube2ima_test_DEPENDENCIES = $(OBJDIR)/sinfo_utl_cube2ima.o \
+	$(LDADD)
+am_sinfo_utl_cube2spectrum_test_OBJECTS = recipe_main.$(OBJEXT)
+sinfo_utl_cube2spectrum_test_OBJECTS =  \
+	$(am_sinfo_utl_cube2spectrum_test_OBJECTS)
+sinfo_utl_cube2spectrum_test_DEPENDENCIES =  \
+	$(OBJDIR)/sinfo_utl_cube2spectrum.o $(LDADD)
+am_sinfo_utl_spectrum_divide_by_blackbody_test_OBJECTS =  \
+	recipe_main.$(OBJEXT)
+sinfo_utl_spectrum_divide_by_blackbody_test_OBJECTS =  \
+	$(am_sinfo_utl_spectrum_divide_by_blackbody_test_OBJECTS)
+sinfo_utl_spectrum_divide_by_blackbody_test_DEPENDENCIES =  \
+	$(OBJDIR)/sinfo_utl_spectrum_divide_by_blackbody.o $(LDADD)
+DEFAULT_INCLUDES = -I. at am__isrc@ -I$(top_builddir)
+depcomp = $(SHELL) $(top_srcdir)/admin/depcomp
+am__depfiles_maybe = depfiles
+am__mv = mv -f
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+	--mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
+	$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+CCLD = $(CC)
+LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+	--mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
+	$(LDFLAGS) -o $@
+SOURCES = $(sinfo_rec_detlin_test_SOURCES) \
+	$(sinfo_rec_distortion_test_SOURCES) \
+	$(sinfo_rec_jitter_test_SOURCES) \
+	$(sinfo_utl_cube2ima_test_SOURCES) \
+	$(sinfo_utl_cube2spectrum_test_SOURCES) \
+	$(sinfo_utl_spectrum_divide_by_blackbody_test_SOURCES)
+DIST_SOURCES = $(sinfo_rec_detlin_test_SOURCES) \
+	$(sinfo_rec_distortion_test_SOURCES) \
+	$(sinfo_rec_jitter_test_SOURCES) \
+	$(sinfo_utl_cube2ima_test_SOURCES) \
+	$(sinfo_utl_cube2spectrum_test_SOURCES) \
+	$(sinfo_utl_spectrum_divide_by_blackbody_test_SOURCES)
+ETAGS = etags
+CTAGS = ctags
+am__tty_colors = \
+red=; grn=; lgn=; blu=; std=
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+ACLOCAL = @ACLOCAL@
+AMTAR = @AMTAR@
+AR = @AR@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CPL_INCLUDES = @CPL_INCLUDES@
+CPL_LDFLAGS = @CPL_LDFLAGS@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CX_INCLUDES = @CX_INCLUDES@
+CX_LDFLAGS = @CX_LDFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+DOXYGEN = @DOXYGEN@
+DSYMUTIL = @DSYMUTIL@
+DUMPBIN = @DUMPBIN@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+ESO_DEBUG_FLAGS = @ESO_DEBUG_FLAGS@
+EXEEXT = @EXEEXT@
+FGREP = @FGREP@
+GREP = @GREP@
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+IRPLIB_INCLUDES = @IRPLIB_INCLUDES@
+IRPLIB_LDFLAGS = @IRPLIB_LDFLAGS@
+LATEX = @LATEX@
+LD = @LD@
+LDFLAGS = @LDFLAGS@
+LIBCEXT = @LIBCEXT@
+LIBCPLCORE = @LIBCPLCORE@
+LIBCPLDFS = @LIBCPLDFS@
+LIBCPLDRS = @LIBCPLDRS@
+LIBCPLUI = @LIBCPLUI@
+LIBIRPLIB = @LIBIRPLIB@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LIBSINFONI = @LIBSINFONI@
+LIBTOOL = @LIBTOOL@
+LIBTOOL_DEPS = @LIBTOOL_DEPS@
+LIPO = @LIPO@
+LN_S = @LN_S@
+LTLIBOBJS = @LTLIBOBJS@
+LT_AGE = @LT_AGE@
+LT_CURRENT = @LT_CURRENT@
+LT_REVISION = @LT_REVISION@
+MAINT = @MAINT@
+MAKEINFO = @MAKEINFO@
+MKDIR_P = @MKDIR_P@
+NM = @NM@
+NMEDIT = @NMEDIT@
+OBJDUMP = @OBJDUMP@
+OBJEXT = @OBJEXT@
+OTOOL = @OTOOL@
+OTOOL64 = @OTOOL64@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+PURIFY_CMD = @PURIFY_CMD@
+RANLIB = @RANLIB@
+SED = @SED@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+SINFONI_BINARY_AGE = @SINFONI_BINARY_AGE@
+SINFONI_BINARY_VERSION = @SINFONI_BINARY_VERSION@
+SINFONI_INCLUDES = @SINFONI_INCLUDES@
+SINFONI_INTERFACE_AGE = @SINFONI_INTERFACE_AGE@
+SINFONI_LDFLAGS = @SINFONI_LDFLAGS@
+SINFONI_MAJOR_VERSION = @SINFONI_MAJOR_VERSION@
+SINFONI_MICRO_VERSION = @SINFONI_MICRO_VERSION@
+SINFONI_MINOR_VERSION = @SINFONI_MINOR_VERSION@
+SINFONI_VERSION = @SINFONI_VERSION@
+STRIP = @STRIP@
+VERSION = @VERSION@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
+all_includes = @all_includes@
+all_ldflags = @all_ldflags@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build = @build@
+build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
+builddir = @builddir@
+configdir = @configdir@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
+exec_prefix = @exec_prefix@
+host = @host@
+host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localedir = @localedir@
+localstatedir = @localstatedir@
+lt_ECHO = @lt_ECHO@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+pipedocsdir = @pipedocsdir@
+plugindir = @plugindir@
+prefix = @prefix@
+privatelibdir = @privatelibdir@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
+sysconfdir = @sysconfdir@
+target = @target@
+target_alias = @target_alias@
+target_cpu = @target_cpu@
+target_os = @target_os@
+target_vendor = @target_vendor@
+top_build_prefix = @top_build_prefix@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+AUTOMAKE_OPTIONS = 1.8 foreign
+DISTCLEANFILES = *~ .logfile
+ at MAINTAINER_MODE_TRUE@MAINTAINERCLEANFILES = Makefile.in
+LIBSINFO = $(top_builddir)/sinfoni/libsinfo.la \
+          $(top_builddir)/irplib/libirplib.la
+
+OBJDIR = $(top_builddir)/recipes/.libs
+INCLUDES = $(all_includes)
+LDADD = $(LIBSINFO)
+#                 sinfo_rec_mdark-test 
+#                 sinfo_rec_mdark_detmon-test \
+#                 sinfo_rec_lingain-test \
+#                 sinfo_rec_wavecal-test \
+#                 sinfo_rec_mflat-test \
+#		 sinfo_utl_skycor-test      \
+#                 sinfo_rec_pupil-test \
+#		 sinfo_utl_spectrum_wavelength_shift-test 
+#		 sinfo_utl_cube_arith-test  \
+#		 sinfo_utl_cube_combine-test \
+#		 sinfo_utl_cube_create-test \
+#		 sinfo_utl_ima_arith-test   \
+#		 sinfo_utl_skymap-test      \
+#                sinfo_utl_bp_mask_add-test \
+#		 sinfo_utl_ima_line_corr-test \
+#		 sinfo_utl_seds-test        \
+#		 sinfo_utl_stdstars-test    
+sinfo_rec_detlin_test_SOURCES = recipe_main.c
+sinfo_rec_detlin_test_LDADD = $(OBJDIR)/sinfo_rec_detlin.o  $(LDADD) $(LIBALL)
+
+#sinfo_rec_lingain_test_SOURCES = recipe_main.c
+#sinfo_rec_lingain_test_LDADD   = $(OBJDIR)/sinfo_rec_lingain.o  $(LDADD) $(LIBALL)
+sinfo_rec_distortion_test_SOURCES = recipe_main.c
+sinfo_rec_distortion_test_LDADD = $(OBJDIR)/sinfo_rec_distortion.o  $(LDADD) $(LIBALL)
+
+#sinfo_rec_mdark_test_SOURCES = recipe_main.c
+#sinfo_rec_mdark_test_LDADD   = $(OBJDIR)/sinfo_rec_mdark.o  $(LDADD) $(LIBALL)
+
+#sinfo_rec_mdark_detmon_test_SOURCES = recipe_main.c
+#sinfo_rec_mdark_detmon_test_LDADD   = $(OBJDIR)/sinfo_rec_mdark_detmon.o  $(LDADD) $(LIBALL)
+
+#sinfo_rec_mflat_test_SOURCES = recipe_main.c
+#sinfo_rec_mflat_test_LDADD   = $(OBJDIR)/sinfo_rec_mflat.o  $(LDADD) $(LIBALL)
+
+#sinfo_rec_wavecal_test_SOURCES = recipe_main.c
+#sinfo_rec_wavecal_test_LDADD   = $(OBJDIR)/sinfo_rec_wavecal.o  $(LDADD) $(LIBALL)
+sinfo_rec_jitter_test_SOURCES = recipe_main.c
+sinfo_rec_jitter_test_LDADD = $(OBJDIR)/sinfo_rec_jitter.o  $(LDADD) $(LIBALL)
+
+#sinfo_rec_pupil_test_SOURCES = recipe_main.c
+#sinfo_rec_pupil_test_LDADD   = $(OBJDIR)/sinfo_rec_pupil.o  $(LDADD) $(LIBALL)
+
+#sinfo_utl_bp_mask_add_test_SOURCES = recipe_main.c
+#sinfo_utl_bp_mask_add_test_LDADD   = $(OBJDIR)/sinfo_utl_bp_mask_add.o  $(LDADD) $(LIBALL)
+sinfo_utl_cube2ima_test_SOURCES = recipe_main.c
+sinfo_utl_cube2ima_test_LDADD = $(OBJDIR)/sinfo_utl_cube2ima.o  $(LDADD) $(LIBALL)
+sinfo_utl_cube2spectrum_test_SOURCES = recipe_main.c
+sinfo_utl_cube2spectrum_test_LDADD = $(OBJDIR)/sinfo_utl_cube2spectrum.o  $(LDADD) $(LIBALL)
+
+#sinfo_utl_cube_arith_test_SOURCES = recipe_main.c
+#sinfo_utl_cube_arith_test_LDADD   = $(OBJDIR)/sinfo_utl_cube_arith.o  $(LDADD) $(LIBALL)
+
+#sinfo_utl_cube_combine_test_SOURCES = recipe_main.c
+#sinfo_utl_cube_combine_test_LDADD   = $(OBJDIR)/sinfo_utl_cube_combine.o  $(LDADD) $(LIBALL)
+
+#sinfo_utl_cube_create_test_SOURCES = recipe_main.c
+#sinfo_utl_cube_create_test_LDADD   = $(OBJDIR)/sinfo_utl_cube_create.o  $(LDADD) $(LIBALL)
+
+#sinfo_utl_ima_arith_test_SOURCES = recipe_main.c
+#sinfo_utl_ima_arith_test_LDADD   = $(OBJDIR)/sinfo_utl_ima_arith.o  $(LDADD) $(LIBALL)
+
+#sinfo_utl_ima_line_corr_test_SOURCES = recipe_main.c
+#sinfo_utl_ima_line_corr_test_LDADD   = $(OBJDIR)/sinfo_utl_ima_line_corr.o  $(LDADD) $(LIBALL)
+
+#sinfo_utl_skymap_test_SOURCES = recipe_main.c
+#sinfo_utl_skymap_test_LDADD   = $(OBJDIR)/sinfo_utl_skymap.o  $(LDADD) $(LIBALL)
+
+#sinfo_utl_skycor_test_SOURCES = recipe_main.c
+#sinfo_utl_skycor_test_LDADD   = $(OBJDIR)/sinfo_utl_skycor.o  $(LDADD) $(LIBALL)
+sinfo_utl_spectrum_divide_by_blackbody_test_SOURCES = recipe_main.c
+sinfo_utl_spectrum_divide_by_blackbody_test_LDADD = $(OBJDIR)/sinfo_utl_spectrum_divide_by_blackbody.o  $(LDADD) $(LIBALL)
+
+#sinfo_utl_spectrum_wavelength_shift_test_SOURCES = recipe_main.c
+#sinfo_utl_spectrum_wavelength_shift_test_LDADD   = $(OBJDIR)/sinfo_utl_spectrum_wavelength_shift.o  $(LDADD) $(LIBALL)
+
+#sinfo_utl_seds_test_SOURCES = recipe_main.c
+#sinfo_utl_seds_test_LDADD   = $(OBJDIR)/sinfo_utl_seds.o  $(LDADD) $(LIBALL)
+
+#sinfo_utl_stdstars_test_SOURCES = recipe_main.c
+#sinfo_utl_stdstars_test_LDADD   = $(OBJDIR)/sinfo_utl_stdstars.o  $(LDADD) $(LIBALL)
+
+# Be sure to reexport important environment variables.
+# - And be sure the find the dynamic libraries
+TESTS_ENVIRONMENT = MAKE="$(MAKE)" CC="$(CC)" CFLAGS="$(CFLAGS)" \
+        CPPFLAGS="$(CPPFLAGS)" LD="$(LD)" LDFLAGS="$(LDFLAGS)" \
+        LIBS="$(LIBS)" LN_S="$(LN_S)" NM="$(NM)" RANLIB="$(RANLIB)" \
+        LD_LIBRARY_PATH="$(top_builddir)/sinfoni/.libs:$(top_builddir)/irplib/.libs:$(LD_LIBRARY_PATH)" \
+        OBJEXT="$(OBJEXT)" EXEEXT="$(EXEEXT)"
+
+TESTS = $(check_PROGRAMS)
+all: all-am
+
+.SUFFIXES:
+.SUFFIXES: .c .lo .o .obj
+$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am  $(am__configure_deps)
+	@for dep in $?; do \
+	  case '$(am__configure_deps)' in \
+	    *$$dep*) \
+	      ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+	        && { if test -f $@; then exit 0; else break; fi; }; \
+	      exit 1;; \
+	  esac; \
+	done; \
+	echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign recipes/tests/Makefile'; \
+	$(am__cd) $(top_srcdir) && \
+	  $(AUTOMAKE) --foreign recipes/tests/Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+	@case '$?' in \
+	  *config.status*) \
+	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+	  *) \
+	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
+	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+	esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(am__aclocal_m4_deps):
+
+clean-checkPROGRAMS:
+	@list='$(check_PROGRAMS)'; test -n "$$list" || exit 0; \
+	echo " rm -f" $$list; \
+	rm -f $$list || exit $$?; \
+	test -n "$(EXEEXT)" || exit 0; \
+	list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \
+	echo " rm -f" $$list; \
+	rm -f $$list
+sinfo_rec_detlin-test$(EXEEXT): $(sinfo_rec_detlin_test_OBJECTS) $(sinfo_rec_detlin_test_DEPENDENCIES) 
+	@rm -f sinfo_rec_detlin-test$(EXEEXT)
+	$(LINK) $(sinfo_rec_detlin_test_OBJECTS) $(sinfo_rec_detlin_test_LDADD) $(LIBS)
+sinfo_rec_distortion-test$(EXEEXT): $(sinfo_rec_distortion_test_OBJECTS) $(sinfo_rec_distortion_test_DEPENDENCIES) 
+	@rm -f sinfo_rec_distortion-test$(EXEEXT)
+	$(LINK) $(sinfo_rec_distortion_test_OBJECTS) $(sinfo_rec_distortion_test_LDADD) $(LIBS)
+sinfo_rec_jitter-test$(EXEEXT): $(sinfo_rec_jitter_test_OBJECTS) $(sinfo_rec_jitter_test_DEPENDENCIES) 
+	@rm -f sinfo_rec_jitter-test$(EXEEXT)
+	$(LINK) $(sinfo_rec_jitter_test_OBJECTS) $(sinfo_rec_jitter_test_LDADD) $(LIBS)
+sinfo_utl_cube2ima-test$(EXEEXT): $(sinfo_utl_cube2ima_test_OBJECTS) $(sinfo_utl_cube2ima_test_DEPENDENCIES) 
+	@rm -f sinfo_utl_cube2ima-test$(EXEEXT)
+	$(LINK) $(sinfo_utl_cube2ima_test_OBJECTS) $(sinfo_utl_cube2ima_test_LDADD) $(LIBS)
+sinfo_utl_cube2spectrum-test$(EXEEXT): $(sinfo_utl_cube2spectrum_test_OBJECTS) $(sinfo_utl_cube2spectrum_test_DEPENDENCIES) 
+	@rm -f sinfo_utl_cube2spectrum-test$(EXEEXT)
+	$(LINK) $(sinfo_utl_cube2spectrum_test_OBJECTS) $(sinfo_utl_cube2spectrum_test_LDADD) $(LIBS)
+sinfo_utl_spectrum_divide_by_blackbody-test$(EXEEXT): $(sinfo_utl_spectrum_divide_by_blackbody_test_OBJECTS) $(sinfo_utl_spectrum_divide_by_blackbody_test_DEPENDENCIES) 
+	@rm -f sinfo_utl_spectrum_divide_by_blackbody-test$(EXEEXT)
+	$(LINK) $(sinfo_utl_spectrum_divide_by_blackbody_test_OBJECTS) $(sinfo_utl_spectrum_divide_by_blackbody_test_LDADD) $(LIBS)
+
+mostlyclean-compile:
+	-rm -f *.$(OBJEXT)
+
+distclean-compile:
+	-rm -f *.tab.c
+
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/recipe_main.Po at am__quote@
+
+.c.o:
+ at am__fastdepCC_TRUE@	$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+ at am__fastdepCC_TRUE@	$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCC_FALSE@	$(COMPILE) -c $<
+
+.c.obj:
+ at am__fastdepCC_TRUE@	$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
+ at am__fastdepCC_TRUE@	$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCC_FALSE@	$(COMPILE) -c `$(CYGPATH_W) '$<'`
+
+.c.lo:
+ at am__fastdepCC_TRUE@	$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+ at am__fastdepCC_TRUE@	$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCC_FALSE@	$(LTCOMPILE) -c -o $@ $<
+
+mostlyclean-libtool:
+	-rm -f *.lo
+
+clean-libtool:
+	-rm -rf .libs _libs
+
+ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
+	list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	mkid -fID $$unique
+tags: TAGS
+
+TAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
+		$(TAGS_FILES) $(LISP)
+	set x; \
+	here=`pwd`; \
+	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	shift; \
+	if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
+	  test -n "$$unique" || unique=$$empty_fix; \
+	  if test $$# -gt 0; then \
+	    $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+	      "$$@" $$unique; \
+	  else \
+	    $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+	      $$unique; \
+	  fi; \
+	fi
+ctags: CTAGS
+CTAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
+		$(TAGS_FILES) $(LISP)
+	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	test -z "$(CTAGS_ARGS)$$unique" \
+	  || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+	     $$unique
+
+GTAGS:
+	here=`$(am__cd) $(top_builddir) && pwd` \
+	  && $(am__cd) $(top_srcdir) \
+	  && gtags -i $(GTAGS_ARGS) "$$here"
+
+distclean-tags:
+	-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+
+check-TESTS: $(TESTS)
+	@failed=0; all=0; xfail=0; xpass=0; skip=0; \
+	srcdir=$(srcdir); export srcdir; \
+	list=' $(TESTS) '; \
+	$(am__tty_colors); \
+	if test -n "$$list"; then \
+	  for tst in $$list; do \
+	    if test -f ./$$tst; then dir=./; \
+	    elif test -f $$tst; then dir=; \
+	    else dir="$(srcdir)/"; fi; \
+	    if $(TESTS_ENVIRONMENT) $${dir}$$tst; then \
+	      all=`expr $$all + 1`; \
+	      case " $(XFAIL_TESTS) " in \
+	      *[\ \	]$$tst[\ \	]*) \
+		xpass=`expr $$xpass + 1`; \
+		failed=`expr $$failed + 1`; \
+		col=$$red; res=XPASS; \
+	      ;; \
+	      *) \
+		col=$$grn; res=PASS; \
+	      ;; \
+	      esac; \
+	    elif test $$? -ne 77; then \
+	      all=`expr $$all + 1`; \
+	      case " $(XFAIL_TESTS) " in \
+	      *[\ \	]$$tst[\ \	]*) \
+		xfail=`expr $$xfail + 1`; \
+		col=$$lgn; res=XFAIL; \
+	      ;; \
+	      *) \
+		failed=`expr $$failed + 1`; \
+		col=$$red; res=FAIL; \
+	      ;; \
+	      esac; \
+	    else \
+	      skip=`expr $$skip + 1`; \
+	      col=$$blu; res=SKIP; \
+	    fi; \
+	    echo "$${col}$$res$${std}: $$tst"; \
+	  done; \
+	  if test "$$all" -eq 1; then \
+	    tests="test"; \
+	    All=""; \
+	  else \
+	    tests="tests"; \
+	    All="All "; \
+	  fi; \
+	  if test "$$failed" -eq 0; then \
+	    if test "$$xfail" -eq 0; then \
+	      banner="$$All$$all $$tests passed"; \
+	    else \
+	      if test "$$xfail" -eq 1; then failures=failure; else failures=failures; fi; \
+	      banner="$$All$$all $$tests behaved as expected ($$xfail expected $$failures)"; \
+	    fi; \
+	  else \
+	    if test "$$xpass" -eq 0; then \
+	      banner="$$failed of $$all $$tests failed"; \
+	    else \
+	      if test "$$xpass" -eq 1; then passes=pass; else passes=passes; fi; \
+	      banner="$$failed of $$all $$tests did not behave as expected ($$xpass unexpected $$passes)"; \
+	    fi; \
+	  fi; \
+	  dashes="$$banner"; \
+	  skipped=""; \
+	  if test "$$skip" -ne 0; then \
+	    if test "$$skip" -eq 1; then \
+	      skipped="($$skip test was not run)"; \
+	    else \
+	      skipped="($$skip tests were not run)"; \
+	    fi; \
+	    test `echo "$$skipped" | wc -c` -le `echo "$$banner" | wc -c` || \
+	      dashes="$$skipped"; \
+	  fi; \
+	  report=""; \
+	  if test "$$failed" -ne 0 && test -n "$(PACKAGE_BUGREPORT)"; then \
+	    report="Please report to $(PACKAGE_BUGREPORT)"; \
+	    test `echo "$$report" | wc -c` -le `echo "$$banner" | wc -c` || \
+	      dashes="$$report"; \
+	  fi; \
+	  dashes=`echo "$$dashes" | sed s/./=/g`; \
+	  if test "$$failed" -eq 0; then \
+	    echo "$$grn$$dashes"; \
+	  else \
+	    echo "$$red$$dashes"; \
+	  fi; \
+	  echo "$$banner"; \
+	  test -z "$$skipped" || echo "$$skipped"; \
+	  test -z "$$report" || echo "$$report"; \
+	  echo "$$dashes$$std"; \
+	  test "$$failed" -eq 0; \
+	else :; fi
+
+distdir: $(DISTFILES)
+	@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+	topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+	list='$(DISTFILES)'; \
+	  dist_files=`for file in $$list; do echo $$file; done | \
+	  sed -e "s|^$$srcdirstrip/||;t" \
+	      -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+	case $$dist_files in \
+	  */*) $(MKDIR_P) `echo "$$dist_files" | \
+			   sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+			   sort -u` ;; \
+	esac; \
+	for file in $$dist_files; do \
+	  if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+	  if test -d $$d/$$file; then \
+	    dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+	    if test -d "$(distdir)/$$file"; then \
+	      find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+	    fi; \
+	    if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+	      cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
+	      find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+	    fi; \
+	    cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
+	  else \
+	    test -f "$(distdir)/$$file" \
+	    || cp -p $$d/$$file "$(distdir)/$$file" \
+	    || exit 1; \
+	  fi; \
+	done
+check-am: all-am
+	$(MAKE) $(AM_MAKEFLAGS) $(check_PROGRAMS)
+	$(MAKE) $(AM_MAKEFLAGS) check-TESTS
+check: check-am
+all-am: Makefile
+installdirs:
+install: install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+	@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+	$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+	  install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+	  `test -z '$(STRIP)' || \
+	    echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+	-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+	-test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
+	-test -z "$(DISTCLEANFILES)" || rm -f $(DISTCLEANFILES)
+
+maintainer-clean-generic:
+	@echo "This command is intended for maintainers to use"
+	@echo "it deletes files that may require special tools to rebuild."
+	-test -z "$(MAINTAINERCLEANFILES)" || rm -f $(MAINTAINERCLEANFILES)
+clean: clean-am
+
+clean-am: clean-checkPROGRAMS clean-generic clean-libtool clean-local \
+	mostlyclean-am
+
+distclean: distclean-am
+	-rm -rf ./$(DEPDIR)
+	-rm -f Makefile
+distclean-am: clean-am distclean-compile distclean-generic \
+	distclean-tags
+
+dvi: dvi-am
+
+dvi-am:
+
+html: html-am
+
+html-am:
+
+info: info-am
+
+info-am:
+
+install-data-am:
+
+install-dvi: install-dvi-am
+
+install-dvi-am:
+
+install-exec-am:
+
+install-html: install-html-am
+
+install-html-am:
+
+install-info: install-info-am
+
+install-info-am:
+
+install-man:
+
+install-pdf: install-pdf-am
+
+install-pdf-am:
+
+install-ps: install-ps-am
+
+install-ps-am:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+	-rm -rf ./$(DEPDIR)
+	-rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-compile mostlyclean-generic \
+	mostlyclean-libtool
+
+pdf: pdf-am
+
+pdf-am:
+
+ps: ps-am
+
+ps-am:
+
+uninstall-am:
+
+.MAKE: check-am install-am install-strip
+
+.PHONY: CTAGS GTAGS all all-am check check-TESTS check-am clean \
+	clean-checkPROGRAMS clean-generic clean-libtool clean-local \
+	ctags distclean distclean-compile distclean-generic \
+	distclean-libtool distclean-tags distdir dvi dvi-am html \
+	html-am info info-am install install-am install-data \
+	install-data-am install-dvi install-dvi-am install-exec \
+	install-exec-am install-html install-html-am install-info \
+	install-info-am install-man install-pdf install-pdf-am \
+	install-ps install-ps-am install-strip installcheck \
+	installcheck-am installdirs maintainer-clean \
+	maintainer-clean-generic mostlyclean mostlyclean-compile \
+	mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
+	tags uninstall uninstall-am
+
+
+# We need to remove any files that the above tests created.
+clean-local:
+	$(RM) *.paf *.fits
+
+ at PURIFY_TRUE@include $(top_builddir)/Makefile.purify
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/recipes/tests/README b/recipes/tests/README
new file mode 100644
index 0000000..3af48f7
--- /dev/null
+++ b/recipes/tests/README
@@ -0,0 +1,9 @@
+The pipeline recipes can executed in the following way:
+1) Create a new directory somewhere and let the environment
+variable RECIPE_SOF_PATH point to it
+2) For recipe <recipe>, create a .sof-file 
+$RECIPE_SOF_PATH/<recipe>.sof - the fits files listed in
+this sof should have a full path.
+3) make check
+   will then, after doing some error testing on the recipes,
+   execute them on the specified sofs.
diff --git a/recipes/tests/recipe_main.c b/recipes/tests/recipe_main.c
new file mode 100644
index 0000000..a3b5d5d
--- /dev/null
+++ b/recipes/tests/recipe_main.c
@@ -0,0 +1,279 @@
+/* $Id: recipe_main.c,v 1.5 2009/09/15 08:13:38 amodigli Exp $
+ *
+ * This file is part of the VISIR Pipeline
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2009/09/15 08:13:38 $
+ * $Revision: 1.5 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+/*-----------------------------------------------------------------------------
+                                Includes
+ -----------------------------------------------------------------------------*/
+
+#include <cpl.h>
+
+#include <irplib_plugin.h>
+#include <cpl_test.h>
+#include <sinfo_pro_types.h>
+#include <sinfo_msg.h>
+#include <sinfo_raw_types.h>
+
+
+/*----------------------------------------------------------------------------*/
+/**
+ * @defgroup recipe_main   General plugin tests
+ */
+/*----------------------------------------------------------------------------*/
+
+/**@{*/
+
+/*-----------------------------------------------------------------------------
+                            Function definitions
+ -----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Find a plugin and submit it to some tests
+  @return   0 iff succesful
+
+ */
+/*----------------------------------------------------------------------------*/
+int main(void)
+{
+
+    const char * tags[] = {
+       RAW_LINEARITY_LAMP,
+       RAW_DARK,
+       RAW_PINHOLE_LAMP,
+       RAW_SLIT_LAMP,
+       RAW_FIBRE_PSF,
+       RAW_FIBRE_DARK,
+       RAW_FIBRE_LAMP,
+       RAW_FIBRE_NS,
+       RAW_FIBRE_EW,
+       RAW_WAVE_LAMP,
+       RAW_WAVE_LAMP_DITHER,
+       RAW_WAVE_NS,
+       RAW_WAVE_NS_DITHER,
+       RAW_FLAT_LAMP,
+       RAW_FLAT_LAMP_DITHER,
+       RAW_FLAT_NS,
+       RAW_FLAT_NS_DITHER,
+       RAW_FLAT_SKY,
+       RAW_FLUX_LAMP,
+       RAW_PSF_CALIBRATOR,
+       RAW_FOCUS,
+       RAW_SKY_DUMMY,
+       RAW_PUPIL_LAMP,
+       RAW_OBJECT,
+       RAW_IMAGE_PRE_OBJECT,
+       RAW_IMAGE_PRE_SKY,
+       RAW_OBJECT_SKYSPIDER,
+       RAW_OBJECT_SKYSPIDER_DITHER,
+       RAW_OBJECT_NODDING,
+       RAW_SKY_NODDING,
+       RAW_OBJECT_JITTER,
+       RAW_SKY_JITTER,
+       RAW_OBJECT_NODDING_DITHER,
+       RAW_OBJECT_JITTER_DITHER,
+       RAW_SKY_NODDING_DITHER,
+       RAW_SKY_JITTER_DITHER,
+       RAW_ACQUISITION_SKY,
+       RAW_ACQUISITION_OBJECT,
+       RAW_STD,
+       RAW_STACKED_SLITPOS,
+       RAW_SKY_STD,
+       RAW_SKY_OH,
+       RAW_SKY_PSF_CALIBRATOR,
+       RAW_STD_STAR,
+       RAW_STD_STAR_DITHER,
+       SINFO_UTL_STDSTARS_RAW,
+       SINFO_UTL_SEDS_RAW,
+       RAW_OFF,
+       RAW_OFF1,
+       RAW_OFF2,
+       RAW_SKY,
+       RAW_SKY1,
+       RAW_SKY2,
+       RAW_ON,
+       RAW_ON1,
+       RAW_ON2,
+       RAW_INT_ON,
+       RAW_INT_OFF,
+       PRO_LIN_DET_INFO,
+       PRO_GAIN_INFO,
+       PRO_AO_INFO,
+       PRO_AO_PERFORMANCE,
+       PRO_ENC_ENERGY,
+       PRO_OBS_SKY,
+       PRO_SKY_MED,
+       PRO_SKY_DUMMY,
+       PRO_SKY_STACKED_DUMMY,
+       PRO_DEFAULT,
+       PRO_INT_COL_TILT_COR,
+       PRO_STD_STACKED,
+       PRO_SKY_STD_STACKED,
+       PRO_SKY_OH_STACKED,
+       PRO_SKY_PSF_CALIBRATOR_STACKED,
+       PRO_STD_STAR_STACKED,
+       PRO_STD_STAR_DITHER_STACKED,
+       PRO_SKY_STACKED,
+       PRO_NODDING_STACKED,
+       PRO_ILLUMCORR,
+       SINFO_UTL_STDSTARS_RES,
+       SINFO_UTL_SEDS_RES,
+       SINFO_CALIB_STDSTARS,
+       SINFO_CALIB_SED,
+       PRO_STACKED,
+       PRO_STACK_SKY_DIST,
+       PRO_STACK_MFLAT_DIST,
+       PRO_STACK_MFLAT_DITHER_DIST,
+       PRO_MFLAT_CUBE,
+       PRO_MFLAT_AVG,
+       PRO_MFLAT_MED,
+       PRO_ILL_COR,
+       PRO_BP_MAP,
+       PRO_BP_MAP_HP,
+       PRO_BP_MAP_NL,
+       PRO_BP_MAP_NO,
+       PRO_BP_MAP_DI,
+       PRO_BP_MAP_SKY,
+       PRO_MASTER_BP_MAP,
+       PRO_BP_MAP,
+       PRO_MASTER_DARK,
+       PRO_SLOPE,
+       PRO_DISTORTION,
+       PRO_SLITLETS_DISTANCE,
+       PRO_MASTER_SLIT,
+       PRO_MASTER_FLAT_LAMP,
+       PRO_MASTER_FLAT_LAMP1,
+       PRO_MASTER_FLAT_LAMP2,
+       PRO_SLIT_POS,
+       PRO_SLITLETS_POS_PREDIST,
+       PRO_SLIT_POS_GUESS,
+       PRO_FIBRE_EW_STACKED,
+       PRO_FIBRE_NS_STACKED_ON,
+       PRO_FIBRE_NS_STACKED_OFF,
+       PRO_FIBRE_NS_STACKED,
+       PRO_FIBRE_NS_STACKED_DIST,
+       PRO_FIBRE_LAMP_STACKED,
+       PRO_SLIT_LAMP_STACKED,
+       PRO_FLUX_LAMP_STACKED,
+       PRO_WAVE_LAMP_STACKED,
+       PRO_WAVE_SLITPOS_STACKED,
+       PRO_WAVE_LAMP_DITHER_STACKED,
+       PRO_WAVE_NS_STACKED,
+       PRO_WAVE_NS_DITHER_STACKED,
+       PRO_WAVE_PAR_LIST,
+       PRO_WAVE_COEF_SLIT,
+       PRO_PSF_CALIBRATOR_STACKED,
+       PRO_FOCUS_STACKED,
+       PRO_OBJECT_NODDING_STACKED,
+       PRO_OBJECT_SKYSPIDER_STACKED,
+       PRO_RESAMPLED_WAVE,
+       PRO_RESAMPLED_OBJ,
+       PRO_RESAMPLED_SKY,
+       PRO_RESAMPLED_FLAT_LAMP,
+       PRO_OBS_CUBE_SKY,
+       PRO_STD_CUBE_SKY,
+       PRO_PSF_CUBE_SKY,
+       PRO_PUPIL_CUBE_SKY,
+       PRO_PUPIL_CUBE,
+       PRO_OBS_MED_SKY,
+       PRO_STD_MED_SKY,
+       PRO_PSF_MED_SKY,
+       PRO_PUPIL_MED_SKY,
+       PRO_PUPIL_LAMP_STACKED,
+       PRO_SKY_NODDING_STACKED,
+       PRO_STD_NODDING_STACKED,
+       PRO_MASTER_LAMP_SPEC,
+       PRO_MASTER_TWIFLAT,
+       PRO_COEFF_LIST,
+       PRO_INDEX_LIST,
+       PRO_HALO_SPECT,
+       PRO_FIRST_COL,
+       PRO_MASK_CUBE,
+       PRO_PSF,
+       TMP_FOCUS,
+       TMP_FOCUS_ON,
+       TMP_FOCUS_OFF,
+       PRO_FOCUS,
+       PRO_FOCUS_GAUSS,
+       PRO_WAVE_MAP,
+       PRO_STD_STAR_SPECTRA,
+       PRO_STD_STAR_SPECTRUM,
+       PRO_CUBE,
+       PRO_IMA,
+       PRO_SPECTRUM,
+       PRO_COADD_SKY,
+       PRO_COADD_PSF,
+       PRO_COADD_STD,
+       PRO_COADD_OBJ,
+       PRO_COADD_PUPIL,
+       PRO_OBS_PSF,
+       PRO_OBS_STD,
+       PRO_OBS_OBJ,
+       PRO_OBS_PUPIL,
+       PRO_SPECTRA_QC,
+       PRO_MED_COADD_PSF,
+       PRO_MED_COADD_STD,
+       PRO_MED_COADD_OBJ,
+       PRO_MED_COADD_PUPIL,
+       PRO_MED_OBS_PSF,
+       PRO_MED_OBS_STD,
+       PRO_MED_OBS_OBJ,
+       PRO_MED_OBS_PUPIL,
+       PRO_CUBE_COLL,
+       PRO_SLOPEX,
+       PRO_SLOPEY,
+       PRO_MASK_CUBE,
+       PRO_MASK_COADD_PSF,
+       PRO_MASK_COADD_STD,
+       PRO_MASK_COADD_OBJ,
+       PRO_MASK_COADD_PUPIL,
+       PRO_OBJ_CUBE,
+       PRO_BP_COEFF
+    };
+
+    cpl_pluginlist * pluginlist;
+    const size_t ntags = sizeof(tags) / sizeof(char*);
+    cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
+    pluginlist = cpl_pluginlist_new();
+    
+    sinfo_msg("Hello wordl!");
+
+
+    cpl_test(!cpl_plugin_get_info(pluginlist));
+
+    cpl_test(!irplib_plugin_test(pluginlist, ntags, tags));
+
+    cpl_pluginlist_delete(pluginlist);
+
+    return cpl_test_end(0);
+}
+
+/**@}*/
diff --git a/regtests/Makefile.am b/regtests/Makefile.am
new file mode 100644
index 0000000..c19c6fa
--- /dev/null
+++ b/regtests/Makefile.am
@@ -0,0 +1,30 @@
+## Process this file with automake to produce Makefile.in
+
+##   This file is part of the VISIR Pipeline
+##   Copyright (C) 2002-2004 European Southern Observatory
+
+##   This library is free software; you can redistribute it and/or modify
+##   it under the terms of the GNU General Public License as published by
+##   the Free Software Foundation; either version 2 of the License, or
+##   (at your option) any later version.
+
+##   This program is distributed in the hope that it will be useful,
+##   but WITHOUT ANY WARRANTY; without even the implied warranty of
+##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+##   GNU General Public License for more details.
+
+##   You should have received a copy of the GNU General Public License
+##   along with this program; if not, write to the Free Software
+##   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+AUTOMAKE_OPTIONS = 1.8 foreign
+
+DISTCLEANFILES = *~
+
+
+if MAINTAINER_MODE
+
+MAINTAINERCLEANFILES = $(srcdir)/Makefile.in
+
+endif
+SUBDIRS = . tests
diff --git a/regtests/Makefile.in b/regtests/Makefile.in
new file mode 100644
index 0000000..4c6708e
--- /dev/null
+++ b/regtests/Makefile.in
@@ -0,0 +1,604 @@
+# Makefile.in generated by automake 1.11 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009  Free Software Foundation,
+# Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+ at SET_MAKE@
+VPATH = @srcdir@
+pkgdatadir = $(datadir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkglibexecdir = $(libexecdir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
+target_triplet = @target@
+subdir = regtests
+DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/m4macros/cpl.m4 \
+	$(top_srcdir)/m4macros/eso.m4 \
+	$(top_srcdir)/m4macros/libtool.m4 \
+	$(top_srcdir)/m4macros/ltoptions.m4 \
+	$(top_srcdir)/m4macros/ltsugar.m4 \
+	$(top_srcdir)/m4macros/ltversion.m4 \
+	$(top_srcdir)/m4macros/lt~obsolete.m4 \
+	$(top_srcdir)/m4macros/purify.m4 $(top_srcdir)/acinclude.m4 \
+	$(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+	$(ACLOCAL_M4)
+mkinstalldirs = $(install_sh) -d
+CONFIG_HEADER = $(top_builddir)/config.h
+CONFIG_CLEAN_FILES =
+CONFIG_CLEAN_VPATH_FILES =
+SOURCES =
+DIST_SOURCES =
+RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \
+	html-recursive info-recursive install-data-recursive \
+	install-dvi-recursive install-exec-recursive \
+	install-html-recursive install-info-recursive \
+	install-pdf-recursive install-ps-recursive install-recursive \
+	installcheck-recursive installdirs-recursive pdf-recursive \
+	ps-recursive uninstall-recursive
+RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive	\
+  distclean-recursive maintainer-clean-recursive
+AM_RECURSIVE_TARGETS = $(RECURSIVE_TARGETS:-recursive=) \
+	$(RECURSIVE_CLEAN_TARGETS:-recursive=) tags TAGS ctags CTAGS \
+	distdir
+ETAGS = etags
+CTAGS = ctags
+DIST_SUBDIRS = $(SUBDIRS)
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+am__relativize = \
+  dir0=`pwd`; \
+  sed_first='s,^\([^/]*\)/.*$$,\1,'; \
+  sed_rest='s,^[^/]*/*,,'; \
+  sed_last='s,^.*/\([^/]*\)$$,\1,'; \
+  sed_butlast='s,/*[^/]*$$,,'; \
+  while test -n "$$dir1"; do \
+    first=`echo "$$dir1" | sed -e "$$sed_first"`; \
+    if test "$$first" != "."; then \
+      if test "$$first" = ".."; then \
+        dir2=`echo "$$dir0" | sed -e "$$sed_last"`/"$$dir2"; \
+        dir0=`echo "$$dir0" | sed -e "$$sed_butlast"`; \
+      else \
+        first2=`echo "$$dir2" | sed -e "$$sed_first"`; \
+        if test "$$first2" = "$$first"; then \
+          dir2=`echo "$$dir2" | sed -e "$$sed_rest"`; \
+        else \
+          dir2="../$$dir2"; \
+        fi; \
+        dir0="$$dir0"/"$$first"; \
+      fi; \
+    fi; \
+    dir1=`echo "$$dir1" | sed -e "$$sed_rest"`; \
+  done; \
+  reldir="$$dir2"
+ACLOCAL = @ACLOCAL@
+AMTAR = @AMTAR@
+AR = @AR@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CPL_INCLUDES = @CPL_INCLUDES@
+CPL_LDFLAGS = @CPL_LDFLAGS@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CX_INCLUDES = @CX_INCLUDES@
+CX_LDFLAGS = @CX_LDFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+DOXYGEN = @DOXYGEN@
+DSYMUTIL = @DSYMUTIL@
+DUMPBIN = @DUMPBIN@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+ESO_DEBUG_FLAGS = @ESO_DEBUG_FLAGS@
+EXEEXT = @EXEEXT@
+FGREP = @FGREP@
+GREP = @GREP@
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+IRPLIB_INCLUDES = @IRPLIB_INCLUDES@
+IRPLIB_LDFLAGS = @IRPLIB_LDFLAGS@
+LATEX = @LATEX@
+LD = @LD@
+LDFLAGS = @LDFLAGS@
+LIBCEXT = @LIBCEXT@
+LIBCPLCORE = @LIBCPLCORE@
+LIBCPLDFS = @LIBCPLDFS@
+LIBCPLDRS = @LIBCPLDRS@
+LIBCPLUI = @LIBCPLUI@
+LIBIRPLIB = @LIBIRPLIB@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LIBSINFONI = @LIBSINFONI@
+LIBTOOL = @LIBTOOL@
+LIBTOOL_DEPS = @LIBTOOL_DEPS@
+LIPO = @LIPO@
+LN_S = @LN_S@
+LTLIBOBJS = @LTLIBOBJS@
+LT_AGE = @LT_AGE@
+LT_CURRENT = @LT_CURRENT@
+LT_REVISION = @LT_REVISION@
+MAINT = @MAINT@
+MAKEINFO = @MAKEINFO@
+MKDIR_P = @MKDIR_P@
+NM = @NM@
+NMEDIT = @NMEDIT@
+OBJDUMP = @OBJDUMP@
+OBJEXT = @OBJEXT@
+OTOOL = @OTOOL@
+OTOOL64 = @OTOOL64@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+PURIFY_CMD = @PURIFY_CMD@
+RANLIB = @RANLIB@
+SED = @SED@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+SINFONI_BINARY_AGE = @SINFONI_BINARY_AGE@
+SINFONI_BINARY_VERSION = @SINFONI_BINARY_VERSION@
+SINFONI_INCLUDES = @SINFONI_INCLUDES@
+SINFONI_INTERFACE_AGE = @SINFONI_INTERFACE_AGE@
+SINFONI_LDFLAGS = @SINFONI_LDFLAGS@
+SINFONI_MAJOR_VERSION = @SINFONI_MAJOR_VERSION@
+SINFONI_MICRO_VERSION = @SINFONI_MICRO_VERSION@
+SINFONI_MINOR_VERSION = @SINFONI_MINOR_VERSION@
+SINFONI_VERSION = @SINFONI_VERSION@
+STRIP = @STRIP@
+VERSION = @VERSION@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
+all_includes = @all_includes@
+all_ldflags = @all_ldflags@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build = @build@
+build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
+builddir = @builddir@
+configdir = @configdir@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
+exec_prefix = @exec_prefix@
+host = @host@
+host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localedir = @localedir@
+localstatedir = @localstatedir@
+lt_ECHO = @lt_ECHO@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+pipedocsdir = @pipedocsdir@
+plugindir = @plugindir@
+prefix = @prefix@
+privatelibdir = @privatelibdir@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
+sysconfdir = @sysconfdir@
+target = @target@
+target_alias = @target_alias@
+target_cpu = @target_cpu@
+target_os = @target_os@
+target_vendor = @target_vendor@
+top_build_prefix = @top_build_prefix@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+AUTOMAKE_OPTIONS = 1.8 foreign
+DISTCLEANFILES = *~
+ at MAINTAINER_MODE_TRUE@MAINTAINERCLEANFILES = $(srcdir)/Makefile.in
+SUBDIRS = . tests
+all: all-recursive
+
+.SUFFIXES:
+$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am  $(am__configure_deps)
+	@for dep in $?; do \
+	  case '$(am__configure_deps)' in \
+	    *$$dep*) \
+	      ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+	        && { if test -f $@; then exit 0; else break; fi; }; \
+	      exit 1;; \
+	  esac; \
+	done; \
+	echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign regtests/Makefile'; \
+	$(am__cd) $(top_srcdir) && \
+	  $(AUTOMAKE) --foreign regtests/Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+	@case '$?' in \
+	  *config.status*) \
+	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+	  *) \
+	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
+	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+	esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(am__aclocal_m4_deps):
+
+mostlyclean-libtool:
+	-rm -f *.lo
+
+clean-libtool:
+	-rm -rf .libs _libs
+
+# This directory's subdirectories are mostly independent; you can cd
+# into them and run `make' without going through this Makefile.
+# To change the values of `make' variables: instead of editing Makefiles,
+# (1) if the variable is set in `config.status', edit `config.status'
+#     (which will cause the Makefiles to be regenerated when you run `make');
+# (2) otherwise, pass the desired values on the `make' command line.
+$(RECURSIVE_TARGETS):
+	@failcom='exit 1'; \
+	for f in x $$MAKEFLAGS; do \
+	  case $$f in \
+	    *=* | --[!k]*);; \
+	    *k*) failcom='fail=yes';; \
+	  esac; \
+	done; \
+	dot_seen=no; \
+	target=`echo $@ | sed s/-recursive//`; \
+	list='$(SUBDIRS)'; for subdir in $$list; do \
+	  echo "Making $$target in $$subdir"; \
+	  if test "$$subdir" = "."; then \
+	    dot_seen=yes; \
+	    local_target="$$target-am"; \
+	  else \
+	    local_target="$$target"; \
+	  fi; \
+	  ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
+	  || eval $$failcom; \
+	done; \
+	if test "$$dot_seen" = "no"; then \
+	  $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \
+	fi; test -z "$$fail"
+
+$(RECURSIVE_CLEAN_TARGETS):
+	@failcom='exit 1'; \
+	for f in x $$MAKEFLAGS; do \
+	  case $$f in \
+	    *=* | --[!k]*);; \
+	    *k*) failcom='fail=yes';; \
+	  esac; \
+	done; \
+	dot_seen=no; \
+	case "$@" in \
+	  distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \
+	  *) list='$(SUBDIRS)' ;; \
+	esac; \
+	rev=''; for subdir in $$list; do \
+	  if test "$$subdir" = "."; then :; else \
+	    rev="$$subdir $$rev"; \
+	  fi; \
+	done; \
+	rev="$$rev ."; \
+	target=`echo $@ | sed s/-recursive//`; \
+	for subdir in $$rev; do \
+	  echo "Making $$target in $$subdir"; \
+	  if test "$$subdir" = "."; then \
+	    local_target="$$target-am"; \
+	  else \
+	    local_target="$$target"; \
+	  fi; \
+	  ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
+	  || eval $$failcom; \
+	done && test -z "$$fail"
+tags-recursive:
+	list='$(SUBDIRS)'; for subdir in $$list; do \
+	  test "$$subdir" = . || ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) tags); \
+	done
+ctags-recursive:
+	list='$(SUBDIRS)'; for subdir in $$list; do \
+	  test "$$subdir" = . || ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) ctags); \
+	done
+
+ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
+	list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	mkid -fID $$unique
+tags: TAGS
+
+TAGS: tags-recursive $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
+		$(TAGS_FILES) $(LISP)
+	set x; \
+	here=`pwd`; \
+	if ($(ETAGS) --etags-include --version) >/dev/null 2>&1; then \
+	  include_option=--etags-include; \
+	  empty_fix=.; \
+	else \
+	  include_option=--include; \
+	  empty_fix=; \
+	fi; \
+	list='$(SUBDIRS)'; for subdir in $$list; do \
+	  if test "$$subdir" = .; then :; else \
+	    test ! -f $$subdir/TAGS || \
+	      set "$$@" "$$include_option=$$here/$$subdir/TAGS"; \
+	  fi; \
+	done; \
+	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	shift; \
+	if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
+	  test -n "$$unique" || unique=$$empty_fix; \
+	  if test $$# -gt 0; then \
+	    $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+	      "$$@" $$unique; \
+	  else \
+	    $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+	      $$unique; \
+	  fi; \
+	fi
+ctags: CTAGS
+CTAGS: ctags-recursive $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
+		$(TAGS_FILES) $(LISP)
+	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	test -z "$(CTAGS_ARGS)$$unique" \
+	  || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+	     $$unique
+
+GTAGS:
+	here=`$(am__cd) $(top_builddir) && pwd` \
+	  && $(am__cd) $(top_srcdir) \
+	  && gtags -i $(GTAGS_ARGS) "$$here"
+
+distclean-tags:
+	-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+
+distdir: $(DISTFILES)
+	@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+	topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+	list='$(DISTFILES)'; \
+	  dist_files=`for file in $$list; do echo $$file; done | \
+	  sed -e "s|^$$srcdirstrip/||;t" \
+	      -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+	case $$dist_files in \
+	  */*) $(MKDIR_P) `echo "$$dist_files" | \
+			   sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+			   sort -u` ;; \
+	esac; \
+	for file in $$dist_files; do \
+	  if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+	  if test -d $$d/$$file; then \
+	    dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+	    if test -d "$(distdir)/$$file"; then \
+	      find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+	    fi; \
+	    if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+	      cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
+	      find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+	    fi; \
+	    cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
+	  else \
+	    test -f "$(distdir)/$$file" \
+	    || cp -p $$d/$$file "$(distdir)/$$file" \
+	    || exit 1; \
+	  fi; \
+	done
+	@list='$(DIST_SUBDIRS)'; for subdir in $$list; do \
+	  if test "$$subdir" = .; then :; else \
+	    test -d "$(distdir)/$$subdir" \
+	    || $(MKDIR_P) "$(distdir)/$$subdir" \
+	    || exit 1; \
+	  fi; \
+	done
+	@list='$(DIST_SUBDIRS)'; for subdir in $$list; do \
+	  if test "$$subdir" = .; then :; else \
+	    dir1=$$subdir; dir2="$(distdir)/$$subdir"; \
+	    $(am__relativize); \
+	    new_distdir=$$reldir; \
+	    dir1=$$subdir; dir2="$(top_distdir)"; \
+	    $(am__relativize); \
+	    new_top_distdir=$$reldir; \
+	    echo " (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) top_distdir="$$new_top_distdir" distdir="$$new_distdir" \\"; \
+	    echo "     am__remove_distdir=: am__skip_length_check=: am__skip_mode_fix=: distdir)"; \
+	    ($(am__cd) $$subdir && \
+	      $(MAKE) $(AM_MAKEFLAGS) \
+	        top_distdir="$$new_top_distdir" \
+	        distdir="$$new_distdir" \
+		am__remove_distdir=: \
+		am__skip_length_check=: \
+		am__skip_mode_fix=: \
+	        distdir) \
+	      || exit 1; \
+	  fi; \
+	done
+check-am: all-am
+check: check-recursive
+all-am: Makefile
+installdirs: installdirs-recursive
+installdirs-am:
+install: install-recursive
+install-exec: install-exec-recursive
+install-data: install-data-recursive
+uninstall: uninstall-recursive
+
+install-am: all-am
+	@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-recursive
+install-strip:
+	$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+	  install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+	  `test -z '$(STRIP)' || \
+	    echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+	-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+	-test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
+	-test -z "$(DISTCLEANFILES)" || rm -f $(DISTCLEANFILES)
+
+maintainer-clean-generic:
+	@echo "This command is intended for maintainers to use"
+	@echo "it deletes files that may require special tools to rebuild."
+	-test -z "$(MAINTAINERCLEANFILES)" || rm -f $(MAINTAINERCLEANFILES)
+clean: clean-recursive
+
+clean-am: clean-generic clean-libtool mostlyclean-am
+
+distclean: distclean-recursive
+	-rm -f Makefile
+distclean-am: clean-am distclean-generic distclean-tags
+
+dvi: dvi-recursive
+
+dvi-am:
+
+html: html-recursive
+
+html-am:
+
+info: info-recursive
+
+info-am:
+
+install-data-am:
+
+install-dvi: install-dvi-recursive
+
+install-dvi-am:
+
+install-exec-am:
+
+install-html: install-html-recursive
+
+install-html-am:
+
+install-info: install-info-recursive
+
+install-info-am:
+
+install-man:
+
+install-pdf: install-pdf-recursive
+
+install-pdf-am:
+
+install-ps: install-ps-recursive
+
+install-ps-am:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-recursive
+	-rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-recursive
+
+mostlyclean-am: mostlyclean-generic mostlyclean-libtool
+
+pdf: pdf-recursive
+
+pdf-am:
+
+ps: ps-recursive
+
+ps-am:
+
+uninstall-am:
+
+.MAKE: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) ctags-recursive \
+	install-am install-strip tags-recursive
+
+.PHONY: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) CTAGS GTAGS \
+	all all-am check check-am clean clean-generic clean-libtool \
+	ctags ctags-recursive distclean distclean-generic \
+	distclean-libtool distclean-tags distdir dvi dvi-am html \
+	html-am info info-am install install-am install-data \
+	install-data-am install-dvi install-dvi-am install-exec \
+	install-exec-am install-html install-html-am install-info \
+	install-info-am install-man install-pdf install-pdf-am \
+	install-ps install-ps-am install-strip installcheck \
+	installcheck-am installdirs installdirs-am maintainer-clean \
+	maintainer-clean-generic mostlyclean mostlyclean-generic \
+	mostlyclean-libtool pdf pdf-am ps ps-am tags tags-recursive \
+	uninstall uninstall-am
+
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/regtests/tests/Makefile.am b/regtests/tests/Makefile.am
new file mode 100644
index 0000000..290494d
--- /dev/null
+++ b/regtests/tests/Makefile.am
@@ -0,0 +1,61 @@
+## Process this file with automake to produce Makefile.in
+
+##   This file is part of the AMBER Pipeline
+##   Copyright (C) 2002-2004 European Southern Observatory
+
+##   This library is free software; you can redistribute it and/or modify
+##   it under the terms of the GNU General Public License as published by
+##   the Free Software Foundation; either version 2 of the License, or
+##   (at your option) any later version.
+
+##   This program is distributed in the hope that it will be useful,
+##   but WITHOUT ANY WARRANTY; without even the implied warranty of
+##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+##   GNU General Public License for more details.
+
+##   You should have received a copy of the GNU General Public License
+##   along with this program; if not, write to the Free Software
+##   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+AUTOMAKE_OPTIONS = 1.8 foreign
+
+DISTCLEANFILES = *~
+
+
+if MAINTAINER_MODE
+
+MAINTAINERCLEANFILES = $(srcdir)/Makefile.in
+
+
+endif
+
+reg0:
+	esoreg.pl  -force -id 0 ../../${PACKAGE}_reg/sof
+
+reg1:
+	esoreg.pl  -force -id 1 ../../${PACKAGE}_reg/sof
+
+valgrind:
+	esoreg.pl  -valgrind -preload  ../../${PACKAGE}_reg/sof
+
+check:
+	mkdir -p .purifydir
+	@if test -d ../../${PACKAGE}_reg/sof/; then esorex --version ; fi
+	@if test -d ../../${PACKAGE}_reg/sof/; then mkdir -p ../../${PACKAGE}_reg/sof/.purifydir ; fi
+	@if test -d ../../${PACKAGE}_reg/sof/.purifydir; then touch ../../${PACKAGE}_reg/sof/.purifydir/_dummy ; fi
+#	if test -d ../../${PACKAGE}_reg; then esoreg.pl  -force -id 0 ../../${PACKAGE}_reg/sof; fi
+#       link to the Reference data under ${SOF_DATA}/${PACKAGE}/ReferenceData/
+	if test -d ../../${PACKAGE}_reg; then  for i in ${SOF_DATA}/${PACKAGE}/ReferenceData/*.0; do ln -f -s  $$i ../../${PACKAGE}_reg/sof/ ; done ; fi
+	if test -d ../../${PACKAGE}_reg; then esoreg.pl  -force -id 1 ../../${PACKAGE}_reg/sof; fi 
+	@if test "$$?x" = "0x"; then echo PASS: regtests; fi
+	@if test "$$?x" != "0x"; then echo FAILED: regtests; fi
+	@if test -d ../../${PACKAGE}_reg/sof/.purifydir; then cp ../../${PACKAGE}_reg/sof/.purifydir/* .purifydir; fi
+
+if PURIFY
+include $(top_builddir)/Makefile.purify
+endif
+
+
+
+
+
diff --git a/regtests/tests/Makefile.in b/regtests/tests/Makefile.in
new file mode 100644
index 0000000..d1967b3
--- /dev/null
+++ b/regtests/tests/Makefile.in
@@ -0,0 +1,425 @@
+# Makefile.in generated by automake 1.11 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009  Free Software Foundation,
+# Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+ at SET_MAKE@
+VPATH = @srcdir@
+pkgdatadir = $(datadir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkglibexecdir = $(libexecdir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
+target_triplet = @target@
+subdir = regtests/tests
+DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/m4macros/cpl.m4 \
+	$(top_srcdir)/m4macros/eso.m4 \
+	$(top_srcdir)/m4macros/libtool.m4 \
+	$(top_srcdir)/m4macros/ltoptions.m4 \
+	$(top_srcdir)/m4macros/ltsugar.m4 \
+	$(top_srcdir)/m4macros/ltversion.m4 \
+	$(top_srcdir)/m4macros/lt~obsolete.m4 \
+	$(top_srcdir)/m4macros/purify.m4 $(top_srcdir)/acinclude.m4 \
+	$(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+	$(ACLOCAL_M4)
+mkinstalldirs = $(install_sh) -d
+CONFIG_HEADER = $(top_builddir)/config.h
+CONFIG_CLEAN_FILES =
+CONFIG_CLEAN_VPATH_FILES =
+SOURCES =
+DIST_SOURCES =
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+ACLOCAL = @ACLOCAL@
+AMTAR = @AMTAR@
+AR = @AR@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CPL_INCLUDES = @CPL_INCLUDES@
+CPL_LDFLAGS = @CPL_LDFLAGS@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CX_INCLUDES = @CX_INCLUDES@
+CX_LDFLAGS = @CX_LDFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+DOXYGEN = @DOXYGEN@
+DSYMUTIL = @DSYMUTIL@
+DUMPBIN = @DUMPBIN@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+ESO_DEBUG_FLAGS = @ESO_DEBUG_FLAGS@
+EXEEXT = @EXEEXT@
+FGREP = @FGREP@
+GREP = @GREP@
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+IRPLIB_INCLUDES = @IRPLIB_INCLUDES@
+IRPLIB_LDFLAGS = @IRPLIB_LDFLAGS@
+LATEX = @LATEX@
+LD = @LD@
+LDFLAGS = @LDFLAGS@
+LIBCEXT = @LIBCEXT@
+LIBCPLCORE = @LIBCPLCORE@
+LIBCPLDFS = @LIBCPLDFS@
+LIBCPLDRS = @LIBCPLDRS@
+LIBCPLUI = @LIBCPLUI@
+LIBIRPLIB = @LIBIRPLIB@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LIBSINFONI = @LIBSINFONI@
+LIBTOOL = @LIBTOOL@
+LIBTOOL_DEPS = @LIBTOOL_DEPS@
+LIPO = @LIPO@
+LN_S = @LN_S@
+LTLIBOBJS = @LTLIBOBJS@
+LT_AGE = @LT_AGE@
+LT_CURRENT = @LT_CURRENT@
+LT_REVISION = @LT_REVISION@
+MAINT = @MAINT@
+MAKEINFO = @MAKEINFO@
+MKDIR_P = @MKDIR_P@
+NM = @NM@
+NMEDIT = @NMEDIT@
+OBJDUMP = @OBJDUMP@
+OBJEXT = @OBJEXT@
+OTOOL = @OTOOL@
+OTOOL64 = @OTOOL64@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+PURIFY_CMD = @PURIFY_CMD@
+RANLIB = @RANLIB@
+SED = @SED@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+SINFONI_BINARY_AGE = @SINFONI_BINARY_AGE@
+SINFONI_BINARY_VERSION = @SINFONI_BINARY_VERSION@
+SINFONI_INCLUDES = @SINFONI_INCLUDES@
+SINFONI_INTERFACE_AGE = @SINFONI_INTERFACE_AGE@
+SINFONI_LDFLAGS = @SINFONI_LDFLAGS@
+SINFONI_MAJOR_VERSION = @SINFONI_MAJOR_VERSION@
+SINFONI_MICRO_VERSION = @SINFONI_MICRO_VERSION@
+SINFONI_MINOR_VERSION = @SINFONI_MINOR_VERSION@
+SINFONI_VERSION = @SINFONI_VERSION@
+STRIP = @STRIP@
+VERSION = @VERSION@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
+all_includes = @all_includes@
+all_ldflags = @all_ldflags@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build = @build@
+build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
+builddir = @builddir@
+configdir = @configdir@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
+exec_prefix = @exec_prefix@
+host = @host@
+host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localedir = @localedir@
+localstatedir = @localstatedir@
+lt_ECHO = @lt_ECHO@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+pipedocsdir = @pipedocsdir@
+plugindir = @plugindir@
+prefix = @prefix@
+privatelibdir = @privatelibdir@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
+sysconfdir = @sysconfdir@
+target = @target@
+target_alias = @target_alias@
+target_cpu = @target_cpu@
+target_os = @target_os@
+target_vendor = @target_vendor@
+top_build_prefix = @top_build_prefix@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+AUTOMAKE_OPTIONS = 1.8 foreign
+DISTCLEANFILES = *~
+ at MAINTAINER_MODE_TRUE@MAINTAINERCLEANFILES = $(srcdir)/Makefile.in
+all: all-am
+
+.SUFFIXES:
+$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am  $(am__configure_deps)
+	@for dep in $?; do \
+	  case '$(am__configure_deps)' in \
+	    *$$dep*) \
+	      ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+	        && { if test -f $@; then exit 0; else break; fi; }; \
+	      exit 1;; \
+	  esac; \
+	done; \
+	echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign regtests/tests/Makefile'; \
+	$(am__cd) $(top_srcdir) && \
+	  $(AUTOMAKE) --foreign regtests/tests/Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+	@case '$?' in \
+	  *config.status*) \
+	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+	  *) \
+	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
+	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+	esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(am__aclocal_m4_deps):
+
+mostlyclean-libtool:
+	-rm -f *.lo
+
+clean-libtool:
+	-rm -rf .libs _libs
+tags: TAGS
+TAGS:
+
+ctags: CTAGS
+CTAGS:
+
+
+distdir: $(DISTFILES)
+	@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+	topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+	list='$(DISTFILES)'; \
+	  dist_files=`for file in $$list; do echo $$file; done | \
+	  sed -e "s|^$$srcdirstrip/||;t" \
+	      -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+	case $$dist_files in \
+	  */*) $(MKDIR_P) `echo "$$dist_files" | \
+			   sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+			   sort -u` ;; \
+	esac; \
+	for file in $$dist_files; do \
+	  if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+	  if test -d $$d/$$file; then \
+	    dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+	    if test -d "$(distdir)/$$file"; then \
+	      find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+	    fi; \
+	    if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+	      cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
+	      find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+	    fi; \
+	    cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
+	  else \
+	    test -f "$(distdir)/$$file" \
+	    || cp -p $$d/$$file "$(distdir)/$$file" \
+	    || exit 1; \
+	  fi; \
+	done
+check-am: all-am
+check: check-am
+all-am: Makefile
+installdirs:
+install: install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+	@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+	$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+	  install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+	  `test -z '$(STRIP)' || \
+	    echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+	-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+	-test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
+	-test -z "$(DISTCLEANFILES)" || rm -f $(DISTCLEANFILES)
+
+maintainer-clean-generic:
+	@echo "This command is intended for maintainers to use"
+	@echo "it deletes files that may require special tools to rebuild."
+	-test -z "$(MAINTAINERCLEANFILES)" || rm -f $(MAINTAINERCLEANFILES)
+clean: clean-am
+
+clean-am: clean-generic clean-libtool mostlyclean-am
+
+distclean: distclean-am
+	-rm -f Makefile
+distclean-am: clean-am distclean-generic
+
+dvi: dvi-am
+
+dvi-am:
+
+html: html-am
+
+html-am:
+
+info: info-am
+
+info-am:
+
+install-data-am:
+
+install-dvi: install-dvi-am
+
+install-dvi-am:
+
+install-exec-am:
+
+install-html: install-html-am
+
+install-html-am:
+
+install-info: install-info-am
+
+install-info-am:
+
+install-man:
+
+install-pdf: install-pdf-am
+
+install-pdf-am:
+
+install-ps: install-ps-am
+
+install-ps-am:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+	-rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-generic mostlyclean-libtool
+
+pdf: pdf-am
+
+pdf-am:
+
+ps: ps-am
+
+ps-am:
+
+uninstall-am:
+
+.MAKE: install-am install-strip
+
+.PHONY: all all-am check check-am clean clean-generic clean-libtool \
+	distclean distclean-generic distclean-libtool distdir dvi \
+	dvi-am html html-am info info-am install install-am \
+	install-data install-data-am install-dvi install-dvi-am \
+	install-exec install-exec-am install-html install-html-am \
+	install-info install-info-am install-man install-pdf \
+	install-pdf-am install-ps install-ps-am install-strip \
+	installcheck installcheck-am installdirs maintainer-clean \
+	maintainer-clean-generic mostlyclean mostlyclean-generic \
+	mostlyclean-libtool pdf pdf-am ps ps-am uninstall uninstall-am
+
+
+reg0:
+	esoreg.pl  -force -id 0 ../../${PACKAGE}_reg/sof
+
+reg1:
+	esoreg.pl  -force -id 1 ../../${PACKAGE}_reg/sof
+
+valgrind:
+	esoreg.pl  -valgrind -preload  ../../${PACKAGE}_reg/sof
+
+check:
+	mkdir -p .purifydir
+	@if test -d ../../${PACKAGE}_reg/sof/; then esorex --version ; fi
+	@if test -d ../../${PACKAGE}_reg/sof/; then mkdir -p ../../${PACKAGE}_reg/sof/.purifydir ; fi
+	@if test -d ../../${PACKAGE}_reg/sof/.purifydir; then touch ../../${PACKAGE}_reg/sof/.purifydir/_dummy ; fi
+#	if test -d ../../${PACKAGE}_reg; then esoreg.pl  -force -id 0 ../../${PACKAGE}_reg/sof; fi
+#       link to the Reference data under ${SOF_DATA}/${PACKAGE}/ReferenceData/
+	if test -d ../../${PACKAGE}_reg; then  for i in ${SOF_DATA}/${PACKAGE}/ReferenceData/*.0; do ln -f -s  $$i ../../${PACKAGE}_reg/sof/ ; done ; fi
+	if test -d ../../${PACKAGE}_reg; then esoreg.pl  -force -id 1 ../../${PACKAGE}_reg/sof; fi 
+	@if test "$$?x" = "0x"; then echo PASS: regtests; fi
+	@if test "$$?x" != "0x"; then echo FAILED: regtests; fi
+	@if test -d ../../${PACKAGE}_reg/sof/.purifydir; then cp ../../${PACKAGE}_reg/sof/.purifydir/* .purifydir; fi
+
+ at PURIFY_TRUE@include $(top_builddir)/Makefile.purify
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/setup b/setup
new file mode 100755
index 0000000..fa17752
--- /dev/null
+++ b/setup
@@ -0,0 +1,77 @@
+#! /bin/sh
+#  This file is part of the SINFONI Pipeline
+#  Copyright (C) 2002,2003 European Southern Observatory
+
+#  This program is free software; you can redistribute it and/or modify
+#  it under the terms of the GNU General Public License as published by
+#  the Free Software Foundation; either version 2 of the License, or
+#  (at your option) any later version.
+
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software
+#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+# $Author: amodigli $
+# $Date: 2003/08/18 12:42:44 $
+# $Revision: 1.1.1.1 $
+# $Name: sinfo-2_3_2 $
+
+
+#   This script is the autoinstaller for the VLT instrument pipeline
+#   packages used by the Instrument Pipeline Installation Procedure
+#   (IPIP) to ease the pipeline installation for ESO System Engineering
+#   staff.
+
+
+error () {
+    echo "Error: $cmd: $1"
+    exit 1
+}
+
+
+#
+# Main
+#
+
+cmd=`basename $0`
+usage="Usage: $cmd installation-path"
+
+setup_configure="./configure --prefix=$1 --disable-fitsio"
+setup_make="make"
+
+# The destination directory for the installation is mandatory
+if test $# != 1; then
+    echo "$usage"
+    exit 1
+fi
+
+# Configure the package
+echo "Setting up pipeline package... "
+if eval $setup_configure; then
+    :
+else
+    error "Package setup failed! See logfile for details."
+fi
+
+# Compile the pipeline
+echo "Building pipeline package... "
+if eval $setup_make; then
+    :
+else
+    error "Package build failed! See logfile for details."
+fi
+
+# Install the pipeline
+echo "Installing pipeline package... "
+if eval $setup_make install install-html; then
+    :
+else
+    error "Package installation failed! See logfile for details."
+fi
+
+exit 0
diff --git a/sinfoni/Makefile.am b/sinfoni/Makefile.am
new file mode 100644
index 0000000..014df81
--- /dev/null
+++ b/sinfoni/Makefile.am
@@ -0,0 +1,337 @@
+## Process this file with automake to produce Makefile.in
+
+##   This file is part of the SINFONI Pipeline
+##   Copyright (C) 2002,2003 European Southern Observatory
+
+##   This library is free software; you can redistribute it and/or modify
+##   it under the terms of the GNU General Public License as published by
+##   the Free Software Foundation; either version 2 of the License, or
+##   (at your option) any later version.
+
+##   This program is distributed in the hope that it will be useful,
+##   but WITHOUT ANY WARRANTY; without even the implied warranty of
+##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+##   GNU General Public License for more details.
+
+##   You should have received a copy of the GNU General Public License
+##   along with this program; if not, write to the Free Software
+##   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+AUTOMAKE_OPTIONS = 1.6 foreign
+
+DISTCLEANFILES = *~
+
+SUBDIRS = . tests
+
+EXTRA_DIST = 
+
+
+CPPFLAGS = -DCX_LOG_DOMAIN=\"SinfoLib\"
+
+INCLUDES = $(all_includes) 
+
+noinst_HEADERS = \
+	sinfo_error.h \
+	sinfo_rec_utils.h \
+	sinfo_time.h \
+	sinfo_skycor.h \
+	sinfo_utils.h \
+        sinfo_dump.h \
+        sinfo_fit.h \
+	sinfo_utils_wrappers.h \
+	sinfo_hidden.h \
+	sinfo_stacked_hidden_config.h \
+	sinfo_skycor_config.h \
+	sinfo_bp_config.h \
+	sinfo_bp_dist_config.h \
+	sinfo_bp_lin_config.h \
+	sinfo_bp_noise_config.h \
+	sinfo_bp_norm_config.h \
+	sinfo_dark_config.h \
+	sinfo_distortion.h \
+	sinfo_distortion_config.h \
+	sinfo_focus_determination_config.h \
+	sinfo_general_config.h \
+	sinfo_lamp_flats_config.h \
+	sinfo_lamp_spec_config.h \
+	sinfo_north_south_test_config.h \
+	sinfo_objnod_config.h \
+	sinfo_objspider_config.h \
+	sinfo_prepare_stacked_frames_config.h \
+	sinfo_product_config.h \
+	sinfo_psf_config.h \
+	sinfo_standard_star_config.h \
+	sinfo_wavecal_config.h \
+	sinfo_badsky_ini_by_cpl.h \
+	sinfo_bp_sky_config.h \
+	sinfo_functions.h \
+	sinfo_wcal_functions.h \
+	sinfo_tpl_dfs.h \
+	sinfo_tpl_utils.h \
+	sinfo_bad_cfg.h \
+	sinfo_badsky_cfg.h \
+	sinfo_baddist_ini_by_cpl.h \
+	sinfo_badnorm_ini_by_cpl.h \
+	sinfo_bad_ini.h \
+	sinfo_dark_cfg.h \
+	sinfo_dark_ini.h \
+	sinfo_dark_ini_by_cpl.h \
+	sinfo_define_opt.h \
+	sinfo_detlin_cfg.h \
+	sinfo_detlin_ini.h \
+	sinfo_detlin_ini_by_cpl.h \
+	sinfo_detnoise_cfg.h \
+	sinfo_detnoise_ini.h \
+	sinfo_detnoise_ini_by_cpl.h \
+	sinfo_finddist_cfg.h \
+	sinfo_finddist_ini.h \
+	sinfo_finddist_ini_by_cpl.h \
+	sinfo_flat_cfg.h \
+	sinfo_flat_ini.h \
+	sinfo_flat_ini_by_cpl.h \
+	sinfo_focus_cfg.h \
+	sinfo_focus_ini.h \
+	sinfo_focus_ini_by_cpl.h \
+	sinfo_lamp_cfg.h \
+	sinfo_lamp_ini.h \
+	sinfo_lamp_ini_by_cpl.h \
+	sinfo_stack_cfg.h \
+	sinfo_stack_ini.h \
+	sinfo_stack_ini_by_cpl.h \
+	sinfo_ns_cfg.h \
+	sinfo_ns_ini.h \
+	sinfo_ns_ini_by_cpl.h \
+	sinfo_object_cfg.h \
+	sinfo_object_ini.h \
+	sinfo_objnod_ini_by_cpl.h \
+	sinfo_objspider_ini_by_cpl.h \
+	sinfo_psf_cfg.h \
+	sinfo_psf_ini.h \
+	sinfo_psf_ini_by_cpl.h \
+	sinfo_raw_types.h \
+	sinfo_pro_types.h \
+	sinfo_globals.h \
+	sinfo_key_names.h \
+	sinfo_ref_types.h \
+	sinfo_dfs.h \
+	sinfo_pro_save.h \
+	sinfo_pfits.h \
+	sinfo_solve_poly_root.h \
+	sinfo_spiffi_types.h \
+	sinfo_stack_ini.h \
+	sinfo_standstar_cfg.h \
+	sinfo_standstar_ini.h \
+	sinfo_standstar_ini_by_cpl.h \
+	sinfo_svd.h \
+	sinfo_tilt_cfg.h \
+	sinfo_tilt_ini.h \
+	sinfo_vltPort.h \
+	sinfo_wavecal_cfg.h \
+	sinfo_wavecal_ini.h \
+	sinfo_wavecal_ini_by_cpl.h \
+	sinfo_file_handling.h \
+	sinfo_new_resampling.h \
+	sinfo_msg.h \
+	sinfo_absolute.h \
+	sinfo_new_bezier.h \
+	sinfo_bp_lin.h \
+	sinfo_bp_noise.h \
+	sinfo_bp_norm.h \
+	sinfo_coltilt.h \
+	sinfo_cube_construct.h \
+	sinfo_new_cube_ops.h \
+	sinfo_new_cubes_build.h \
+	sinfo_new_cubes_coadd.h \
+	sinfo_new_dark.h \
+	sinfo_detlin.h \
+	sinfo_new_find_distortions.h \
+	sinfo_focus.h \
+	sinfo_image_ops.h \
+	sinfo_new_lamp_flats.h \
+	sinfo_merge.h \
+	sinfo_new_nst.h \
+	sinfo_new_objnod.h \
+	sinfo_new_prepare_stacked_frames.h \
+	sinfo_new_psf.h \
+	sinfo_recipes.h \
+	sinfo_shift_images.h \
+	sinfo_new_slit_pos.h \
+	sinfo_spectrum_ops.h \
+	sinfo_new_stdstar.h \
+	sinfo_utilities.h \
+	sinfo_utilities_scired.h \
+	sinfo_wavecal.h \
+	sinfo_wave_calibration.h \
+	sinfo_new_wave_cal_slit2.h \
+	sinfo_new_add_bp_map.h \
+	sinfo_utl_cube2ima.h \
+	sinfo_utl_cube2spectrum.h \
+	sinfo_utl_cube_arith.h \
+	sinfo_utl_cube_combine.h \
+	sinfo_utl_spectrum_divide_by_blackbody.h \
+	sinfo_utl_spectrum_wavelength_shift.h \
+	sinfo_fft_base.h \
+	sinfo_fit_curve.h \
+	sinfo_function_1d.h \
+	sinfo_ipow.h \
+	sinfo_local_types.h \
+	sinfo_matrix.h \
+	sinfo_median.h \
+	sinfo_pixel_handling.h \
+	sinfo_poly2d.h \
+	sinfo_baryvel.h \
+	sinfo_resampling.h \
+	sinfo_remove_crh_single.h \
+	sinfo_utl_efficiency.h \
+	sinfo_star_index.h \
+	sinfo_cpl_size.h \
+	sinfo_atmo_disp.h
+
+
+#	sinfo_irplib_cpl_wrp.h 
+
+pkginclude_HEADERS = 
+
+
+privatelib_LTLIBRARIES = libsinfo.la
+
+libsinfo_la_SOURCES = \
+	sinfo_utils.c \
+	sinfo_rec_utils.c \
+	sinfo_time.c \
+	sinfo_skycor.c \
+	sinfo_dump.c \
+        sinfo_fit.c \
+	sinfo_skycor_config.c \
+	sinfo_utils_wrappers.c \
+	sinfo_general_config.c \
+	sinfo_stacked_hidden_config.c \
+	sinfo_bp_config.c \
+	sinfo_bp_dist_config.c \
+	sinfo_bp_norm_config.c \
+	sinfo_bp_lin_config.c \
+	sinfo_bp_noise_config.c \
+	sinfo_dark_config.c \
+	sinfo_distortion.c \
+	sinfo_distortion_config.c \
+	sinfo_focus_determination_config.c \
+	sinfo_lamp_flats_config.c \
+	sinfo_lamp_spec_config.c \
+	sinfo_north_south_test_config.c \
+	sinfo_prepare_stacked_frames_config.c \
+	sinfo_product_config.c \
+	sinfo_objnod_config.c \
+	sinfo_objspider_config.c \
+	sinfo_psf_config.c \
+	sinfo_standard_star_config.c \
+	sinfo_wavecal_config.c \
+	sinfo_badsky_ini_by_cpl.c \
+	sinfo_bp_sky_config.c \
+	sinfo_tpl_dfs.c \
+	sinfo_tpl_utils.c \
+	sinfo_bad_cfg.c \
+	sinfo_badsky_cfg.c \
+	sinfo_baddist_ini_by_cpl.c \
+	sinfo_badnorm_ini_by_cpl.c \
+	sinfo_balance.c \
+	sinfo_companion.c \
+	sinfo_dark_cfg.c \
+	sinfo_dark_ini_by_cpl.c \
+	sinfo_detlin_cfg.c \
+	sinfo_detlin_ini_by_cpl.c \
+	sinfo_detnoise_cfg.c \
+	sinfo_detnoise_ini_by_cpl.c \
+	sinfo_finddist_cfg.c \
+	sinfo_finddist_ini_by_cpl.c \
+	sinfo_flat_cfg.c \
+	sinfo_flat_ini_by_cpl.c \
+	sinfo_focus_cfg.c \
+	sinfo_focus_ini_by_cpl.c \
+	sinfo_lamp_cfg.c \
+	sinfo_lamp_ini_by_cpl.c \
+	sinfo_stack_cfg.c \
+	sinfo_stack_ini_by_cpl.c \
+	sinfo_ns_cfg.c \
+	sinfo_ns_ini_by_cpl.c \
+	sinfo_object_cfg.c \
+	sinfo_objnod_ini_by_cpl.c \
+	sinfo_objspider_ini_by_cpl.c \
+	sinfo_psf_cfg.c \
+	sinfo_psf_ini_by_cpl.c \
+	sinfo_dfs.c \
+	sinfo_globals.c \
+	sinfo_pro_save.c \
+	sinfo_pfits.c \
+	sinfo_wcal_functions.c \
+	sinfo_solve_poly_root.c \
+	sinfo_standstar_cfg.c \
+	sinfo_standstar_ini_by_cpl.c \
+	sinfo_svd.c \
+	sinfo_tilt_cfg.c \
+	sinfo_wavecal_cfg.c \
+	sinfo_wavecal_ini_by_cpl.c \
+	sinfo_file_handling.c \
+	sinfo_new_resampling.c \
+	sinfo_msg.c \
+	sinfo_absolute.c \
+	sinfo_new_bezier.c \
+	sinfo_boltzmann.c \
+	sinfo_bp_lin.c \
+	sinfo_bp_noise.c \
+	sinfo_bp_norm.c \
+	sinfo_coltilt.c \
+	sinfo_cube_construct.c \
+	sinfo_new_cube_ops.c \
+	sinfo_new_cubes_build.c \
+	sinfo_new_cubes_coadd.c \
+	sinfo_new_dark.c \
+	sinfo_detlin.c \
+	sinfo_new_find_distortions.c \
+	sinfo_focus.c \
+	sinfo_image_ops.c \
+	sinfo_new_lamp_flats.c \
+	sinfo_merge.c \
+	sinfo_new_nst.c \
+	sinfo_new_objnod.c \
+	sinfo_new_prepare_stacked_frames.c \
+	sinfo_new_psf.c \
+	sinfo_recipes.c \
+	sinfo_shift_images.c \
+	sinfo_new_slit_pos.c \
+	sinfo_spectrum_ops.c \
+	sinfo_new_stdstar.c \
+	sinfo_utilities.c \
+	sinfo_utilities_scired.c \
+	sinfo_wavecal.c \
+	sinfo_wave_calibration.c \
+	sinfo_new_wave_cal_slit2.c \
+	sinfo_new_add_bp_map.c \
+	sinfo_utl_cube2ima.c \
+	sinfo_utl_cube2spectrum.c \
+	sinfo_utl_cube_arith.c \
+	sinfo_utl_cube_combine.c \
+	sinfo_utl_spectrum_divide_by_blackbody.c \
+	sinfo_utl_spectrum_wavelength_shift.c \
+	sinfo_fft_base.c \
+	sinfo_fit_curve.c \
+	sinfo_function_1d.c \
+	sinfo_ipow.c \
+	sinfo_matrix.c \
+	sinfo_median.c \
+	sinfo_pixel_handling.c \
+	sinfo_poly2d.c \
+	sinfo_qr.c \
+	sinfo_baryvel.c \
+	sinfo_resampling.c \
+	sinfo_remove_crh_single.c \
+	sinfo_utl_efficiency.c \
+	sinfo_star_index.c \
+	sinfo_atmo_disp.c
+
+
+
+
+
+libsinfo_la_LDFLAGS = $(CPL_LDFLAGS) -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE)
+libsinfo_la_LIBADD = $(LIBIRPLIB) $(LIBCPLDRS) $(LIBCPLUI) $(LIBCPLCORE) $(LIBRECIPES) $(LIBCEXT) 
+libsinfo_la_DEPENDENCIES =  $(LIBIRPLIB)
diff --git a/sinfoni/Makefile.in b/sinfoni/Makefile.in
new file mode 100644
index 0000000..55220be
--- /dev/null
+++ b/sinfoni/Makefile.in
@@ -0,0 +1,1231 @@
+# Makefile.in generated by automake 1.11 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009  Free Software Foundation,
+# Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+ at SET_MAKE@
+
+
+VPATH = @srcdir@
+pkgdatadir = $(datadir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkglibexecdir = $(libexecdir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
+target_triplet = @target@
+subdir = sinfoni
+DIST_COMMON = $(noinst_HEADERS) $(pkginclude_HEADERS) \
+	$(srcdir)/Makefile.am $(srcdir)/Makefile.in
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/m4macros/cpl.m4 \
+	$(top_srcdir)/m4macros/eso.m4 \
+	$(top_srcdir)/m4macros/libtool.m4 \
+	$(top_srcdir)/m4macros/ltoptions.m4 \
+	$(top_srcdir)/m4macros/ltsugar.m4 \
+	$(top_srcdir)/m4macros/ltversion.m4 \
+	$(top_srcdir)/m4macros/lt~obsolete.m4 \
+	$(top_srcdir)/m4macros/purify.m4 $(top_srcdir)/acinclude.m4 \
+	$(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+	$(ACLOCAL_M4)
+mkinstalldirs = $(install_sh) -d
+CONFIG_HEADER = $(top_builddir)/config.h
+CONFIG_CLEAN_FILES =
+CONFIG_CLEAN_VPATH_FILES =
+am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
+am__vpath_adj = case $$p in \
+    $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
+    *) f=$$p;; \
+  esac;
+am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`;
+am__install_max = 40
+am__nobase_strip_setup = \
+  srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'`
+am__nobase_strip = \
+  for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||"
+am__nobase_list = $(am__nobase_strip_setup); \
+  for p in $$list; do echo "$$p $$p"; done | \
+  sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \
+  $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \
+    if (++n[$$2] == $(am__install_max)) \
+      { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \
+    END { for (dir in files) print dir, files[dir] }'
+am__base_list = \
+  sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
+  sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
+am__installdirs = "$(DESTDIR)$(privatelibdir)" \
+	"$(DESTDIR)$(pkgincludedir)"
+LTLIBRARIES = $(privatelib_LTLIBRARIES)
+am__DEPENDENCIES_1 =
+am_libsinfo_la_OBJECTS = sinfo_utils.lo sinfo_rec_utils.lo \
+	sinfo_time.lo sinfo_skycor.lo sinfo_dump.lo sinfo_fit.lo \
+	sinfo_skycor_config.lo sinfo_utils_wrappers.lo \
+	sinfo_general_config.lo sinfo_stacked_hidden_config.lo \
+	sinfo_bp_config.lo sinfo_bp_dist_config.lo \
+	sinfo_bp_norm_config.lo sinfo_bp_lin_config.lo \
+	sinfo_bp_noise_config.lo sinfo_dark_config.lo \
+	sinfo_distortion.lo sinfo_distortion_config.lo \
+	sinfo_focus_determination_config.lo sinfo_lamp_flats_config.lo \
+	sinfo_lamp_spec_config.lo sinfo_north_south_test_config.lo \
+	sinfo_prepare_stacked_frames_config.lo sinfo_product_config.lo \
+	sinfo_objnod_config.lo sinfo_objspider_config.lo \
+	sinfo_psf_config.lo sinfo_standard_star_config.lo \
+	sinfo_wavecal_config.lo sinfo_badsky_ini_by_cpl.lo \
+	sinfo_bp_sky_config.lo sinfo_tpl_dfs.lo sinfo_tpl_utils.lo \
+	sinfo_bad_cfg.lo sinfo_badsky_cfg.lo \
+	sinfo_baddist_ini_by_cpl.lo sinfo_badnorm_ini_by_cpl.lo \
+	sinfo_balance.lo sinfo_companion.lo sinfo_dark_cfg.lo \
+	sinfo_dark_ini_by_cpl.lo sinfo_detlin_cfg.lo \
+	sinfo_detlin_ini_by_cpl.lo sinfo_detnoise_cfg.lo \
+	sinfo_detnoise_ini_by_cpl.lo sinfo_finddist_cfg.lo \
+	sinfo_finddist_ini_by_cpl.lo sinfo_flat_cfg.lo \
+	sinfo_flat_ini_by_cpl.lo sinfo_focus_cfg.lo \
+	sinfo_focus_ini_by_cpl.lo sinfo_lamp_cfg.lo \
+	sinfo_lamp_ini_by_cpl.lo sinfo_stack_cfg.lo \
+	sinfo_stack_ini_by_cpl.lo sinfo_ns_cfg.lo \
+	sinfo_ns_ini_by_cpl.lo sinfo_object_cfg.lo \
+	sinfo_objnod_ini_by_cpl.lo sinfo_objspider_ini_by_cpl.lo \
+	sinfo_psf_cfg.lo sinfo_psf_ini_by_cpl.lo sinfo_dfs.lo \
+	sinfo_globals.lo sinfo_pro_save.lo sinfo_pfits.lo \
+	sinfo_wcal_functions.lo sinfo_solve_poly_root.lo \
+	sinfo_standstar_cfg.lo sinfo_standstar_ini_by_cpl.lo \
+	sinfo_svd.lo sinfo_tilt_cfg.lo sinfo_wavecal_cfg.lo \
+	sinfo_wavecal_ini_by_cpl.lo sinfo_file_handling.lo \
+	sinfo_new_resampling.lo sinfo_msg.lo sinfo_absolute.lo \
+	sinfo_new_bezier.lo sinfo_boltzmann.lo sinfo_bp_lin.lo \
+	sinfo_bp_noise.lo sinfo_bp_norm.lo sinfo_coltilt.lo \
+	sinfo_cube_construct.lo sinfo_new_cube_ops.lo \
+	sinfo_new_cubes_build.lo sinfo_new_cubes_coadd.lo \
+	sinfo_new_dark.lo sinfo_detlin.lo \
+	sinfo_new_find_distortions.lo sinfo_focus.lo \
+	sinfo_image_ops.lo sinfo_new_lamp_flats.lo sinfo_merge.lo \
+	sinfo_new_nst.lo sinfo_new_objnod.lo \
+	sinfo_new_prepare_stacked_frames.lo sinfo_new_psf.lo \
+	sinfo_recipes.lo sinfo_shift_images.lo sinfo_new_slit_pos.lo \
+	sinfo_spectrum_ops.lo sinfo_new_stdstar.lo sinfo_utilities.lo \
+	sinfo_utilities_scired.lo sinfo_wavecal.lo \
+	sinfo_wave_calibration.lo sinfo_new_wave_cal_slit2.lo \
+	sinfo_new_add_bp_map.lo sinfo_utl_cube2ima.lo \
+	sinfo_utl_cube2spectrum.lo sinfo_utl_cube_arith.lo \
+	sinfo_utl_cube_combine.lo \
+	sinfo_utl_spectrum_divide_by_blackbody.lo \
+	sinfo_utl_spectrum_wavelength_shift.lo sinfo_fft_base.lo \
+	sinfo_fit_curve.lo sinfo_function_1d.lo sinfo_ipow.lo \
+	sinfo_matrix.lo sinfo_median.lo sinfo_pixel_handling.lo \
+	sinfo_poly2d.lo sinfo_qr.lo sinfo_baryvel.lo \
+	sinfo_resampling.lo sinfo_remove_crh_single.lo \
+	sinfo_utl_efficiency.lo sinfo_star_index.lo sinfo_atmo_disp.lo
+libsinfo_la_OBJECTS = $(am_libsinfo_la_OBJECTS)
+libsinfo_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
+	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+	$(libsinfo_la_LDFLAGS) $(LDFLAGS) -o $@
+DEFAULT_INCLUDES = -I. at am__isrc@ -I$(top_builddir)
+depcomp = $(SHELL) $(top_srcdir)/admin/depcomp
+am__depfiles_maybe = depfiles
+am__mv = mv -f
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+	--mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
+	$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+CCLD = $(CC)
+LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+	--mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
+	$(LDFLAGS) -o $@
+SOURCES = $(libsinfo_la_SOURCES)
+DIST_SOURCES = $(libsinfo_la_SOURCES)
+RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \
+	html-recursive info-recursive install-data-recursive \
+	install-dvi-recursive install-exec-recursive \
+	install-html-recursive install-info-recursive \
+	install-pdf-recursive install-ps-recursive install-recursive \
+	installcheck-recursive installdirs-recursive pdf-recursive \
+	ps-recursive uninstall-recursive
+HEADERS = $(noinst_HEADERS) $(pkginclude_HEADERS)
+RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive	\
+  distclean-recursive maintainer-clean-recursive
+AM_RECURSIVE_TARGETS = $(RECURSIVE_TARGETS:-recursive=) \
+	$(RECURSIVE_CLEAN_TARGETS:-recursive=) tags TAGS ctags CTAGS \
+	distdir
+ETAGS = etags
+CTAGS = ctags
+DIST_SUBDIRS = $(SUBDIRS)
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+am__relativize = \
+  dir0=`pwd`; \
+  sed_first='s,^\([^/]*\)/.*$$,\1,'; \
+  sed_rest='s,^[^/]*/*,,'; \
+  sed_last='s,^.*/\([^/]*\)$$,\1,'; \
+  sed_butlast='s,/*[^/]*$$,,'; \
+  while test -n "$$dir1"; do \
+    first=`echo "$$dir1" | sed -e "$$sed_first"`; \
+    if test "$$first" != "."; then \
+      if test "$$first" = ".."; then \
+        dir2=`echo "$$dir0" | sed -e "$$sed_last"`/"$$dir2"; \
+        dir0=`echo "$$dir0" | sed -e "$$sed_butlast"`; \
+      else \
+        first2=`echo "$$dir2" | sed -e "$$sed_first"`; \
+        if test "$$first2" = "$$first"; then \
+          dir2=`echo "$$dir2" | sed -e "$$sed_rest"`; \
+        else \
+          dir2="../$$dir2"; \
+        fi; \
+        dir0="$$dir0"/"$$first"; \
+      fi; \
+    fi; \
+    dir1=`echo "$$dir1" | sed -e "$$sed_rest"`; \
+  done; \
+  reldir="$$dir2"
+ACLOCAL = @ACLOCAL@
+AMTAR = @AMTAR@
+AR = @AR@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CPL_INCLUDES = @CPL_INCLUDES@
+CPL_LDFLAGS = @CPL_LDFLAGS@
+CPP = @CPP@
+CPPFLAGS = -DCX_LOG_DOMAIN=\"SinfoLib\"
+CX_INCLUDES = @CX_INCLUDES@
+CX_LDFLAGS = @CX_LDFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+DOXYGEN = @DOXYGEN@
+DSYMUTIL = @DSYMUTIL@
+DUMPBIN = @DUMPBIN@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+ESO_DEBUG_FLAGS = @ESO_DEBUG_FLAGS@
+EXEEXT = @EXEEXT@
+FGREP = @FGREP@
+GREP = @GREP@
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+IRPLIB_INCLUDES = @IRPLIB_INCLUDES@
+IRPLIB_LDFLAGS = @IRPLIB_LDFLAGS@
+LATEX = @LATEX@
+LD = @LD@
+LDFLAGS = @LDFLAGS@
+LIBCEXT = @LIBCEXT@
+LIBCPLCORE = @LIBCPLCORE@
+LIBCPLDFS = @LIBCPLDFS@
+LIBCPLDRS = @LIBCPLDRS@
+LIBCPLUI = @LIBCPLUI@
+LIBIRPLIB = @LIBIRPLIB@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LIBSINFONI = @LIBSINFONI@
+LIBTOOL = @LIBTOOL@
+LIBTOOL_DEPS = @LIBTOOL_DEPS@
+LIPO = @LIPO@
+LN_S = @LN_S@
+LTLIBOBJS = @LTLIBOBJS@
+LT_AGE = @LT_AGE@
+LT_CURRENT = @LT_CURRENT@
+LT_REVISION = @LT_REVISION@
+MAINT = @MAINT@
+MAKEINFO = @MAKEINFO@
+MKDIR_P = @MKDIR_P@
+NM = @NM@
+NMEDIT = @NMEDIT@
+OBJDUMP = @OBJDUMP@
+OBJEXT = @OBJEXT@
+OTOOL = @OTOOL@
+OTOOL64 = @OTOOL64@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+PURIFY_CMD = @PURIFY_CMD@
+RANLIB = @RANLIB@
+SED = @SED@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+SINFONI_BINARY_AGE = @SINFONI_BINARY_AGE@
+SINFONI_BINARY_VERSION = @SINFONI_BINARY_VERSION@
+SINFONI_INCLUDES = @SINFONI_INCLUDES@
+SINFONI_INTERFACE_AGE = @SINFONI_INTERFACE_AGE@
+SINFONI_LDFLAGS = @SINFONI_LDFLAGS@
+SINFONI_MAJOR_VERSION = @SINFONI_MAJOR_VERSION@
+SINFONI_MICRO_VERSION = @SINFONI_MICRO_VERSION@
+SINFONI_MINOR_VERSION = @SINFONI_MINOR_VERSION@
+SINFONI_VERSION = @SINFONI_VERSION@
+STRIP = @STRIP@
+VERSION = @VERSION@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
+all_includes = @all_includes@
+all_ldflags = @all_ldflags@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build = @build@
+build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
+builddir = @builddir@
+configdir = @configdir@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
+exec_prefix = @exec_prefix@
+host = @host@
+host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localedir = @localedir@
+localstatedir = @localstatedir@
+lt_ECHO = @lt_ECHO@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+pipedocsdir = @pipedocsdir@
+plugindir = @plugindir@
+prefix = @prefix@
+privatelibdir = @privatelibdir@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
+sysconfdir = @sysconfdir@
+target = @target@
+target_alias = @target_alias@
+target_cpu = @target_cpu@
+target_os = @target_os@
+target_vendor = @target_vendor@
+top_build_prefix = @top_build_prefix@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+AUTOMAKE_OPTIONS = 1.6 foreign
+DISTCLEANFILES = *~
+SUBDIRS = . tests
+EXTRA_DIST = 
+INCLUDES = $(all_includes) 
+noinst_HEADERS = \
+	sinfo_error.h \
+	sinfo_rec_utils.h \
+	sinfo_time.h \
+	sinfo_skycor.h \
+	sinfo_utils.h \
+        sinfo_dump.h \
+        sinfo_fit.h \
+	sinfo_utils_wrappers.h \
+	sinfo_hidden.h \
+	sinfo_stacked_hidden_config.h \
+	sinfo_skycor_config.h \
+	sinfo_bp_config.h \
+	sinfo_bp_dist_config.h \
+	sinfo_bp_lin_config.h \
+	sinfo_bp_noise_config.h \
+	sinfo_bp_norm_config.h \
+	sinfo_dark_config.h \
+	sinfo_distortion.h \
+	sinfo_distortion_config.h \
+	sinfo_focus_determination_config.h \
+	sinfo_general_config.h \
+	sinfo_lamp_flats_config.h \
+	sinfo_lamp_spec_config.h \
+	sinfo_north_south_test_config.h \
+	sinfo_objnod_config.h \
+	sinfo_objspider_config.h \
+	sinfo_prepare_stacked_frames_config.h \
+	sinfo_product_config.h \
+	sinfo_psf_config.h \
+	sinfo_standard_star_config.h \
+	sinfo_wavecal_config.h \
+	sinfo_badsky_ini_by_cpl.h \
+	sinfo_bp_sky_config.h \
+	sinfo_functions.h \
+	sinfo_wcal_functions.h \
+	sinfo_tpl_dfs.h \
+	sinfo_tpl_utils.h \
+	sinfo_bad_cfg.h \
+	sinfo_badsky_cfg.h \
+	sinfo_baddist_ini_by_cpl.h \
+	sinfo_badnorm_ini_by_cpl.h \
+	sinfo_bad_ini.h \
+	sinfo_dark_cfg.h \
+	sinfo_dark_ini.h \
+	sinfo_dark_ini_by_cpl.h \
+	sinfo_define_opt.h \
+	sinfo_detlin_cfg.h \
+	sinfo_detlin_ini.h \
+	sinfo_detlin_ini_by_cpl.h \
+	sinfo_detnoise_cfg.h \
+	sinfo_detnoise_ini.h \
+	sinfo_detnoise_ini_by_cpl.h \
+	sinfo_finddist_cfg.h \
+	sinfo_finddist_ini.h \
+	sinfo_finddist_ini_by_cpl.h \
+	sinfo_flat_cfg.h \
+	sinfo_flat_ini.h \
+	sinfo_flat_ini_by_cpl.h \
+	sinfo_focus_cfg.h \
+	sinfo_focus_ini.h \
+	sinfo_focus_ini_by_cpl.h \
+	sinfo_lamp_cfg.h \
+	sinfo_lamp_ini.h \
+	sinfo_lamp_ini_by_cpl.h \
+	sinfo_stack_cfg.h \
+	sinfo_stack_ini.h \
+	sinfo_stack_ini_by_cpl.h \
+	sinfo_ns_cfg.h \
+	sinfo_ns_ini.h \
+	sinfo_ns_ini_by_cpl.h \
+	sinfo_object_cfg.h \
+	sinfo_object_ini.h \
+	sinfo_objnod_ini_by_cpl.h \
+	sinfo_objspider_ini_by_cpl.h \
+	sinfo_psf_cfg.h \
+	sinfo_psf_ini.h \
+	sinfo_psf_ini_by_cpl.h \
+	sinfo_raw_types.h \
+	sinfo_pro_types.h \
+	sinfo_globals.h \
+	sinfo_key_names.h \
+	sinfo_ref_types.h \
+	sinfo_dfs.h \
+	sinfo_pro_save.h \
+	sinfo_pfits.h \
+	sinfo_solve_poly_root.h \
+	sinfo_spiffi_types.h \
+	sinfo_stack_ini.h \
+	sinfo_standstar_cfg.h \
+	sinfo_standstar_ini.h \
+	sinfo_standstar_ini_by_cpl.h \
+	sinfo_svd.h \
+	sinfo_tilt_cfg.h \
+	sinfo_tilt_ini.h \
+	sinfo_vltPort.h \
+	sinfo_wavecal_cfg.h \
+	sinfo_wavecal_ini.h \
+	sinfo_wavecal_ini_by_cpl.h \
+	sinfo_file_handling.h \
+	sinfo_new_resampling.h \
+	sinfo_msg.h \
+	sinfo_absolute.h \
+	sinfo_new_bezier.h \
+	sinfo_bp_lin.h \
+	sinfo_bp_noise.h \
+	sinfo_bp_norm.h \
+	sinfo_coltilt.h \
+	sinfo_cube_construct.h \
+	sinfo_new_cube_ops.h \
+	sinfo_new_cubes_build.h \
+	sinfo_new_cubes_coadd.h \
+	sinfo_new_dark.h \
+	sinfo_detlin.h \
+	sinfo_new_find_distortions.h \
+	sinfo_focus.h \
+	sinfo_image_ops.h \
+	sinfo_new_lamp_flats.h \
+	sinfo_merge.h \
+	sinfo_new_nst.h \
+	sinfo_new_objnod.h \
+	sinfo_new_prepare_stacked_frames.h \
+	sinfo_new_psf.h \
+	sinfo_recipes.h \
+	sinfo_shift_images.h \
+	sinfo_new_slit_pos.h \
+	sinfo_spectrum_ops.h \
+	sinfo_new_stdstar.h \
+	sinfo_utilities.h \
+	sinfo_utilities_scired.h \
+	sinfo_wavecal.h \
+	sinfo_wave_calibration.h \
+	sinfo_new_wave_cal_slit2.h \
+	sinfo_new_add_bp_map.h \
+	sinfo_utl_cube2ima.h \
+	sinfo_utl_cube2spectrum.h \
+	sinfo_utl_cube_arith.h \
+	sinfo_utl_cube_combine.h \
+	sinfo_utl_spectrum_divide_by_blackbody.h \
+	sinfo_utl_spectrum_wavelength_shift.h \
+	sinfo_fft_base.h \
+	sinfo_fit_curve.h \
+	sinfo_function_1d.h \
+	sinfo_ipow.h \
+	sinfo_local_types.h \
+	sinfo_matrix.h \
+	sinfo_median.h \
+	sinfo_pixel_handling.h \
+	sinfo_poly2d.h \
+	sinfo_baryvel.h \
+	sinfo_resampling.h \
+	sinfo_remove_crh_single.h \
+	sinfo_utl_efficiency.h \
+	sinfo_star_index.h \
+	sinfo_cpl_size.h \
+	sinfo_atmo_disp.h
+
+
+#	sinfo_irplib_cpl_wrp.h 
+pkginclude_HEADERS = 
+privatelib_LTLIBRARIES = libsinfo.la
+libsinfo_la_SOURCES = \
+	sinfo_utils.c \
+	sinfo_rec_utils.c \
+	sinfo_time.c \
+	sinfo_skycor.c \
+	sinfo_dump.c \
+        sinfo_fit.c \
+	sinfo_skycor_config.c \
+	sinfo_utils_wrappers.c \
+	sinfo_general_config.c \
+	sinfo_stacked_hidden_config.c \
+	sinfo_bp_config.c \
+	sinfo_bp_dist_config.c \
+	sinfo_bp_norm_config.c \
+	sinfo_bp_lin_config.c \
+	sinfo_bp_noise_config.c \
+	sinfo_dark_config.c \
+	sinfo_distortion.c \
+	sinfo_distortion_config.c \
+	sinfo_focus_determination_config.c \
+	sinfo_lamp_flats_config.c \
+	sinfo_lamp_spec_config.c \
+	sinfo_north_south_test_config.c \
+	sinfo_prepare_stacked_frames_config.c \
+	sinfo_product_config.c \
+	sinfo_objnod_config.c \
+	sinfo_objspider_config.c \
+	sinfo_psf_config.c \
+	sinfo_standard_star_config.c \
+	sinfo_wavecal_config.c \
+	sinfo_badsky_ini_by_cpl.c \
+	sinfo_bp_sky_config.c \
+	sinfo_tpl_dfs.c \
+	sinfo_tpl_utils.c \
+	sinfo_bad_cfg.c \
+	sinfo_badsky_cfg.c \
+	sinfo_baddist_ini_by_cpl.c \
+	sinfo_badnorm_ini_by_cpl.c \
+	sinfo_balance.c \
+	sinfo_companion.c \
+	sinfo_dark_cfg.c \
+	sinfo_dark_ini_by_cpl.c \
+	sinfo_detlin_cfg.c \
+	sinfo_detlin_ini_by_cpl.c \
+	sinfo_detnoise_cfg.c \
+	sinfo_detnoise_ini_by_cpl.c \
+	sinfo_finddist_cfg.c \
+	sinfo_finddist_ini_by_cpl.c \
+	sinfo_flat_cfg.c \
+	sinfo_flat_ini_by_cpl.c \
+	sinfo_focus_cfg.c \
+	sinfo_focus_ini_by_cpl.c \
+	sinfo_lamp_cfg.c \
+	sinfo_lamp_ini_by_cpl.c \
+	sinfo_stack_cfg.c \
+	sinfo_stack_ini_by_cpl.c \
+	sinfo_ns_cfg.c \
+	sinfo_ns_ini_by_cpl.c \
+	sinfo_object_cfg.c \
+	sinfo_objnod_ini_by_cpl.c \
+	sinfo_objspider_ini_by_cpl.c \
+	sinfo_psf_cfg.c \
+	sinfo_psf_ini_by_cpl.c \
+	sinfo_dfs.c \
+	sinfo_globals.c \
+	sinfo_pro_save.c \
+	sinfo_pfits.c \
+	sinfo_wcal_functions.c \
+	sinfo_solve_poly_root.c \
+	sinfo_standstar_cfg.c \
+	sinfo_standstar_ini_by_cpl.c \
+	sinfo_svd.c \
+	sinfo_tilt_cfg.c \
+	sinfo_wavecal_cfg.c \
+	sinfo_wavecal_ini_by_cpl.c \
+	sinfo_file_handling.c \
+	sinfo_new_resampling.c \
+	sinfo_msg.c \
+	sinfo_absolute.c \
+	sinfo_new_bezier.c \
+	sinfo_boltzmann.c \
+	sinfo_bp_lin.c \
+	sinfo_bp_noise.c \
+	sinfo_bp_norm.c \
+	sinfo_coltilt.c \
+	sinfo_cube_construct.c \
+	sinfo_new_cube_ops.c \
+	sinfo_new_cubes_build.c \
+	sinfo_new_cubes_coadd.c \
+	sinfo_new_dark.c \
+	sinfo_detlin.c \
+	sinfo_new_find_distortions.c \
+	sinfo_focus.c \
+	sinfo_image_ops.c \
+	sinfo_new_lamp_flats.c \
+	sinfo_merge.c \
+	sinfo_new_nst.c \
+	sinfo_new_objnod.c \
+	sinfo_new_prepare_stacked_frames.c \
+	sinfo_new_psf.c \
+	sinfo_recipes.c \
+	sinfo_shift_images.c \
+	sinfo_new_slit_pos.c \
+	sinfo_spectrum_ops.c \
+	sinfo_new_stdstar.c \
+	sinfo_utilities.c \
+	sinfo_utilities_scired.c \
+	sinfo_wavecal.c \
+	sinfo_wave_calibration.c \
+	sinfo_new_wave_cal_slit2.c \
+	sinfo_new_add_bp_map.c \
+	sinfo_utl_cube2ima.c \
+	sinfo_utl_cube2spectrum.c \
+	sinfo_utl_cube_arith.c \
+	sinfo_utl_cube_combine.c \
+	sinfo_utl_spectrum_divide_by_blackbody.c \
+	sinfo_utl_spectrum_wavelength_shift.c \
+	sinfo_fft_base.c \
+	sinfo_fit_curve.c \
+	sinfo_function_1d.c \
+	sinfo_ipow.c \
+	sinfo_matrix.c \
+	sinfo_median.c \
+	sinfo_pixel_handling.c \
+	sinfo_poly2d.c \
+	sinfo_qr.c \
+	sinfo_baryvel.c \
+	sinfo_resampling.c \
+	sinfo_remove_crh_single.c \
+	sinfo_utl_efficiency.c \
+	sinfo_star_index.c \
+	sinfo_atmo_disp.c
+
+libsinfo_la_LDFLAGS = $(CPL_LDFLAGS) -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE)
+libsinfo_la_LIBADD = $(LIBIRPLIB) $(LIBCPLDRS) $(LIBCPLUI) $(LIBCPLCORE) $(LIBRECIPES) $(LIBCEXT) 
+libsinfo_la_DEPENDENCIES = $(LIBIRPLIB)
+all: all-recursive
+
+.SUFFIXES:
+.SUFFIXES: .c .lo .o .obj
+$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am  $(am__configure_deps)
+	@for dep in $?; do \
+	  case '$(am__configure_deps)' in \
+	    *$$dep*) \
+	      ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+	        && { if test -f $@; then exit 0; else break; fi; }; \
+	      exit 1;; \
+	  esac; \
+	done; \
+	echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign sinfoni/Makefile'; \
+	$(am__cd) $(top_srcdir) && \
+	  $(AUTOMAKE) --foreign sinfoni/Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+	@case '$?' in \
+	  *config.status*) \
+	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+	  *) \
+	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
+	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+	esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(am__aclocal_m4_deps):
+install-privatelibLTLIBRARIES: $(privatelib_LTLIBRARIES)
+	@$(NORMAL_INSTALL)
+	test -z "$(privatelibdir)" || $(MKDIR_P) "$(DESTDIR)$(privatelibdir)"
+	@list='$(privatelib_LTLIBRARIES)'; test -n "$(privatelibdir)" || list=; \
+	list2=; for p in $$list; do \
+	  if test -f $$p; then \
+	    list2="$$list2 $$p"; \
+	  else :; fi; \
+	done; \
+	test -z "$$list2" || { \
+	  echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(privatelibdir)'"; \
+	  $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(privatelibdir)"; \
+	}
+
+uninstall-privatelibLTLIBRARIES:
+	@$(NORMAL_UNINSTALL)
+	@list='$(privatelib_LTLIBRARIES)'; test -n "$(privatelibdir)" || list=; \
+	for p in $$list; do \
+	  $(am__strip_dir) \
+	  echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(privatelibdir)/$$f'"; \
+	  $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(privatelibdir)/$$f"; \
+	done
+
+clean-privatelibLTLIBRARIES:
+	-test -z "$(privatelib_LTLIBRARIES)" || rm -f $(privatelib_LTLIBRARIES)
+	@list='$(privatelib_LTLIBRARIES)'; for p in $$list; do \
+	  dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \
+	  test "$$dir" != "$$p" || dir=.; \
+	  echo "rm -f \"$${dir}/so_locations\""; \
+	  rm -f "$${dir}/so_locations"; \
+	done
+libsinfo.la: $(libsinfo_la_OBJECTS) $(libsinfo_la_DEPENDENCIES) 
+	$(libsinfo_la_LINK) -rpath $(privatelibdir) $(libsinfo_la_OBJECTS) $(libsinfo_la_LIBADD) $(LIBS)
+
+mostlyclean-compile:
+	-rm -f *.$(OBJEXT)
+
+distclean-compile:
+	-rm -f *.tab.c
+
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_absolute.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_atmo_disp.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_bad_cfg.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_baddist_ini_by_cpl.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_badnorm_ini_by_cpl.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_badsky_cfg.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_badsky_ini_by_cpl.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_balance.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_baryvel.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_boltzmann.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_bp_config.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_bp_dist_config.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_bp_lin.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_bp_lin_config.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_bp_noise.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_bp_noise_config.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_bp_norm.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_bp_norm_config.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_bp_sky_config.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_coltilt.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_companion.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_cube_construct.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_dark_cfg.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_dark_config.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_dark_ini_by_cpl.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_detlin.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_detlin_cfg.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_detlin_ini_by_cpl.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_detnoise_cfg.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_detnoise_ini_by_cpl.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_dfs.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_distortion.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_distortion_config.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_dump.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_fft_base.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_file_handling.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_finddist_cfg.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_finddist_ini_by_cpl.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_fit.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_fit_curve.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_flat_cfg.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_flat_ini_by_cpl.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_focus.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_focus_cfg.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_focus_determination_config.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_focus_ini_by_cpl.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_function_1d.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_general_config.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_globals.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_image_ops.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_ipow.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_lamp_cfg.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_lamp_flats_config.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_lamp_ini_by_cpl.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_lamp_spec_config.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_matrix.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_median.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_merge.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_msg.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_new_add_bp_map.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_new_bezier.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_new_cube_ops.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_new_cubes_build.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_new_cubes_coadd.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_new_dark.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_new_find_distortions.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_new_lamp_flats.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_new_nst.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_new_objnod.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_new_prepare_stacked_frames.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_new_psf.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_new_resampling.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_new_slit_pos.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_new_stdstar.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_new_wave_cal_slit2.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_north_south_test_config.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_ns_cfg.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_ns_ini_by_cpl.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_object_cfg.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_objnod_config.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_objnod_ini_by_cpl.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_objspider_config.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_objspider_ini_by_cpl.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_pfits.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_pixel_handling.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_poly2d.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_prepare_stacked_frames_config.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_pro_save.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_product_config.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_psf_cfg.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_psf_config.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_psf_ini_by_cpl.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_qr.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_rec_utils.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_recipes.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_remove_crh_single.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_resampling.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_shift_images.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_skycor.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_skycor_config.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_solve_poly_root.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_spectrum_ops.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_stack_cfg.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_stack_ini_by_cpl.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_stacked_hidden_config.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_standard_star_config.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_standstar_cfg.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_standstar_ini_by_cpl.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_star_index.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_svd.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_tilt_cfg.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_time.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_tpl_dfs.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_tpl_utils.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_utilities.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_utilities_scired.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_utils.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_utils_wrappers.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_utl_cube2ima.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_utl_cube2spectrum.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_utl_cube_arith.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_utl_cube_combine.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_utl_efficiency.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_utl_spectrum_divide_by_blackbody.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_utl_spectrum_wavelength_shift.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_wave_calibration.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_wavecal.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_wavecal_cfg.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_wavecal_config.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_wavecal_ini_by_cpl.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_wcal_functions.Plo at am__quote@
+
+.c.o:
+ at am__fastdepCC_TRUE@	$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+ at am__fastdepCC_TRUE@	$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCC_FALSE@	$(COMPILE) -c $<
+
+.c.obj:
+ at am__fastdepCC_TRUE@	$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
+ at am__fastdepCC_TRUE@	$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCC_FALSE@	$(COMPILE) -c `$(CYGPATH_W) '$<'`
+
+.c.lo:
+ at am__fastdepCC_TRUE@	$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+ at am__fastdepCC_TRUE@	$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCC_FALSE@	$(LTCOMPILE) -c -o $@ $<
+
+mostlyclean-libtool:
+	-rm -f *.lo
+
+clean-libtool:
+	-rm -rf .libs _libs
+install-pkgincludeHEADERS: $(pkginclude_HEADERS)
+	@$(NORMAL_INSTALL)
+	test -z "$(pkgincludedir)" || $(MKDIR_P) "$(DESTDIR)$(pkgincludedir)"
+	@list='$(pkginclude_HEADERS)'; test -n "$(pkgincludedir)" || list=; \
+	for p in $$list; do \
+	  if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
+	  echo "$$d$$p"; \
+	done | $(am__base_list) | \
+	while read files; do \
+	  echo " $(INSTALL_HEADER) $$files '$(DESTDIR)$(pkgincludedir)'"; \
+	  $(INSTALL_HEADER) $$files "$(DESTDIR)$(pkgincludedir)" || exit $$?; \
+	done
+
+uninstall-pkgincludeHEADERS:
+	@$(NORMAL_UNINSTALL)
+	@list='$(pkginclude_HEADERS)'; test -n "$(pkgincludedir)" || list=; \
+	files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
+	test -n "$$files" || exit 0; \
+	echo " ( cd '$(DESTDIR)$(pkgincludedir)' && rm -f" $$files ")"; \
+	cd "$(DESTDIR)$(pkgincludedir)" && rm -f $$files
+
+# This directory's subdirectories are mostly independent; you can cd
+# into them and run `make' without going through this Makefile.
+# To change the values of `make' variables: instead of editing Makefiles,
+# (1) if the variable is set in `config.status', edit `config.status'
+#     (which will cause the Makefiles to be regenerated when you run `make');
+# (2) otherwise, pass the desired values on the `make' command line.
+$(RECURSIVE_TARGETS):
+	@failcom='exit 1'; \
+	for f in x $$MAKEFLAGS; do \
+	  case $$f in \
+	    *=* | --[!k]*);; \
+	    *k*) failcom='fail=yes';; \
+	  esac; \
+	done; \
+	dot_seen=no; \
+	target=`echo $@ | sed s/-recursive//`; \
+	list='$(SUBDIRS)'; for subdir in $$list; do \
+	  echo "Making $$target in $$subdir"; \
+	  if test "$$subdir" = "."; then \
+	    dot_seen=yes; \
+	    local_target="$$target-am"; \
+	  else \
+	    local_target="$$target"; \
+	  fi; \
+	  ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
+	  || eval $$failcom; \
+	done; \
+	if test "$$dot_seen" = "no"; then \
+	  $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \
+	fi; test -z "$$fail"
+
+$(RECURSIVE_CLEAN_TARGETS):
+	@failcom='exit 1'; \
+	for f in x $$MAKEFLAGS; do \
+	  case $$f in \
+	    *=* | --[!k]*);; \
+	    *k*) failcom='fail=yes';; \
+	  esac; \
+	done; \
+	dot_seen=no; \
+	case "$@" in \
+	  distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \
+	  *) list='$(SUBDIRS)' ;; \
+	esac; \
+	rev=''; for subdir in $$list; do \
+	  if test "$$subdir" = "."; then :; else \
+	    rev="$$subdir $$rev"; \
+	  fi; \
+	done; \
+	rev="$$rev ."; \
+	target=`echo $@ | sed s/-recursive//`; \
+	for subdir in $$rev; do \
+	  echo "Making $$target in $$subdir"; \
+	  if test "$$subdir" = "."; then \
+	    local_target="$$target-am"; \
+	  else \
+	    local_target="$$target"; \
+	  fi; \
+	  ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
+	  || eval $$failcom; \
+	done && test -z "$$fail"
+tags-recursive:
+	list='$(SUBDIRS)'; for subdir in $$list; do \
+	  test "$$subdir" = . || ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) tags); \
+	done
+ctags-recursive:
+	list='$(SUBDIRS)'; for subdir in $$list; do \
+	  test "$$subdir" = . || ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) ctags); \
+	done
+
+ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
+	list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	mkid -fID $$unique
+tags: TAGS
+
+TAGS: tags-recursive $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
+		$(TAGS_FILES) $(LISP)
+	set x; \
+	here=`pwd`; \
+	if ($(ETAGS) --etags-include --version) >/dev/null 2>&1; then \
+	  include_option=--etags-include; \
+	  empty_fix=.; \
+	else \
+	  include_option=--include; \
+	  empty_fix=; \
+	fi; \
+	list='$(SUBDIRS)'; for subdir in $$list; do \
+	  if test "$$subdir" = .; then :; else \
+	    test ! -f $$subdir/TAGS || \
+	      set "$$@" "$$include_option=$$here/$$subdir/TAGS"; \
+	  fi; \
+	done; \
+	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	shift; \
+	if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
+	  test -n "$$unique" || unique=$$empty_fix; \
+	  if test $$# -gt 0; then \
+	    $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+	      "$$@" $$unique; \
+	  else \
+	    $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+	      $$unique; \
+	  fi; \
+	fi
+ctags: CTAGS
+CTAGS: ctags-recursive $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
+		$(TAGS_FILES) $(LISP)
+	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	test -z "$(CTAGS_ARGS)$$unique" \
+	  || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+	     $$unique
+
+GTAGS:
+	here=`$(am__cd) $(top_builddir) && pwd` \
+	  && $(am__cd) $(top_srcdir) \
+	  && gtags -i $(GTAGS_ARGS) "$$here"
+
+distclean-tags:
+	-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+
+distdir: $(DISTFILES)
+	@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+	topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+	list='$(DISTFILES)'; \
+	  dist_files=`for file in $$list; do echo $$file; done | \
+	  sed -e "s|^$$srcdirstrip/||;t" \
+	      -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+	case $$dist_files in \
+	  */*) $(MKDIR_P) `echo "$$dist_files" | \
+			   sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+			   sort -u` ;; \
+	esac; \
+	for file in $$dist_files; do \
+	  if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+	  if test -d $$d/$$file; then \
+	    dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+	    if test -d "$(distdir)/$$file"; then \
+	      find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+	    fi; \
+	    if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+	      cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
+	      find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+	    fi; \
+	    cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
+	  else \
+	    test -f "$(distdir)/$$file" \
+	    || cp -p $$d/$$file "$(distdir)/$$file" \
+	    || exit 1; \
+	  fi; \
+	done
+	@list='$(DIST_SUBDIRS)'; for subdir in $$list; do \
+	  if test "$$subdir" = .; then :; else \
+	    test -d "$(distdir)/$$subdir" \
+	    || $(MKDIR_P) "$(distdir)/$$subdir" \
+	    || exit 1; \
+	  fi; \
+	done
+	@list='$(DIST_SUBDIRS)'; for subdir in $$list; do \
+	  if test "$$subdir" = .; then :; else \
+	    dir1=$$subdir; dir2="$(distdir)/$$subdir"; \
+	    $(am__relativize); \
+	    new_distdir=$$reldir; \
+	    dir1=$$subdir; dir2="$(top_distdir)"; \
+	    $(am__relativize); \
+	    new_top_distdir=$$reldir; \
+	    echo " (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) top_distdir="$$new_top_distdir" distdir="$$new_distdir" \\"; \
+	    echo "     am__remove_distdir=: am__skip_length_check=: am__skip_mode_fix=: distdir)"; \
+	    ($(am__cd) $$subdir && \
+	      $(MAKE) $(AM_MAKEFLAGS) \
+	        top_distdir="$$new_top_distdir" \
+	        distdir="$$new_distdir" \
+		am__remove_distdir=: \
+		am__skip_length_check=: \
+		am__skip_mode_fix=: \
+	        distdir) \
+	      || exit 1; \
+	  fi; \
+	done
+check-am: all-am
+check: check-recursive
+all-am: Makefile $(LTLIBRARIES) $(HEADERS)
+installdirs: installdirs-recursive
+installdirs-am:
+	for dir in "$(DESTDIR)$(privatelibdir)" "$(DESTDIR)$(pkgincludedir)"; do \
+	  test -z "$$dir" || $(MKDIR_P) "$$dir"; \
+	done
+install: install-recursive
+install-exec: install-exec-recursive
+install-data: install-data-recursive
+uninstall: uninstall-recursive
+
+install-am: all-am
+	@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-recursive
+install-strip:
+	$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+	  install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+	  `test -z '$(STRIP)' || \
+	    echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+	-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+	-test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
+	-test -z "$(DISTCLEANFILES)" || rm -f $(DISTCLEANFILES)
+
+maintainer-clean-generic:
+	@echo "This command is intended for maintainers to use"
+	@echo "it deletes files that may require special tools to rebuild."
+clean: clean-recursive
+
+clean-am: clean-generic clean-libtool clean-privatelibLTLIBRARIES \
+	mostlyclean-am
+
+distclean: distclean-recursive
+	-rm -rf ./$(DEPDIR)
+	-rm -f Makefile
+distclean-am: clean-am distclean-compile distclean-generic \
+	distclean-tags
+
+dvi: dvi-recursive
+
+dvi-am:
+
+html: html-recursive
+
+html-am:
+
+info: info-recursive
+
+info-am:
+
+install-data-am: install-pkgincludeHEADERS \
+	install-privatelibLTLIBRARIES
+
+install-dvi: install-dvi-recursive
+
+install-dvi-am:
+
+install-exec-am:
+
+install-html: install-html-recursive
+
+install-html-am:
+
+install-info: install-info-recursive
+
+install-info-am:
+
+install-man:
+
+install-pdf: install-pdf-recursive
+
+install-pdf-am:
+
+install-ps: install-ps-recursive
+
+install-ps-am:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-recursive
+	-rm -rf ./$(DEPDIR)
+	-rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-recursive
+
+mostlyclean-am: mostlyclean-compile mostlyclean-generic \
+	mostlyclean-libtool
+
+pdf: pdf-recursive
+
+pdf-am:
+
+ps: ps-recursive
+
+ps-am:
+
+uninstall-am: uninstall-pkgincludeHEADERS \
+	uninstall-privatelibLTLIBRARIES
+
+.MAKE: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) ctags-recursive \
+	install-am install-strip tags-recursive
+
+.PHONY: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) CTAGS GTAGS \
+	all all-am check check-am clean clean-generic clean-libtool \
+	clean-privatelibLTLIBRARIES ctags ctags-recursive distclean \
+	distclean-compile distclean-generic distclean-libtool \
+	distclean-tags distdir dvi dvi-am html html-am info info-am \
+	install install-am install-data install-data-am install-dvi \
+	install-dvi-am install-exec install-exec-am install-html \
+	install-html-am install-info install-info-am install-man \
+	install-pdf install-pdf-am install-pkgincludeHEADERS \
+	install-privatelibLTLIBRARIES install-ps install-ps-am \
+	install-strip installcheck installcheck-am installdirs \
+	installdirs-am maintainer-clean maintainer-clean-generic \
+	mostlyclean mostlyclean-compile mostlyclean-generic \
+	mostlyclean-libtool pdf pdf-am ps ps-am tags tags-recursive \
+	uninstall uninstall-am uninstall-pkgincludeHEADERS \
+	uninstall-privatelibLTLIBRARIES
+
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/sinfoni/sinfo_absolute.c b/sinfoni/sinfo_absolute.c
new file mode 100644
index 0000000..d87f0a5
--- /dev/null
+++ b/sinfoni/sinfo_absolute.c
@@ -0,0 +1,3638 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*****************************************************************************
+* E.S.O. - VLT project
+*
+*
+*
+* who       when      what
+* --------  --------  ----------------------------------------------
+* schreib  14/11/00  created
+*/
+/**@{*/
+/*---------------------------------------------------------------------------*/
+/**
+ * @defgroup sinfo_absolute_utils routines to determine the absolute positions 
+   of the slitlets out of an emission line frame
+ */
+/*---------------------------------------------------------------------------*/
+
+
+/************************************************************************
+*   NAME
+*        sinfo_absolute.c - routines to determine the absolute positions 
+*        of the slitlets out of an emission line frame
+*
+*   SYNOPSIS
+*   #include "absolute.h"
+*
+*   1) float sinfo_new_edge( float * xdat, float * parlist, 
+                             int * npar, int * ndat )
+*   2) void sinfo_new_edge_deriv( float * xdat, float * parlist, 
+                                  float * dervs, int * npar )
+*   3) static int sinfo_new_inv_mat_edge (void)
+*   4) static new_void sinfo_get_mat_edge ( float * xdat,
+*                                 int   * xdim,
+*                                 float * ydat,
+*                                 float * wdat,
+*                                 int   * ndat,
+*                                 float * fpar,
+*                                 float * epar,
+*                                 int   * npar )
+*   5) static int sinfo_new_get_vec_edge ( float * xdat,
+*                                int   * xdim,
+*                                float * ydat,
+*                                float * wdat,
+*                                int   * ndat,
+*                                float * fpar,
+*                                float * epar,
+*                                int   * npar )
+*   6) int sinfo_new_lsqfit_edge ( float * xdat,
+*                        int   * xdim,
+*                        float * ydat,
+*                        float * wdat,
+*                        int   * ndat,
+*                        float * fpar,
+*                        float * epar,
+*                        int   * mpar,
+*                        int   * npar,
+*                        float * tol ,
+*                        int   * its ,
+*                        float * lab  )
+*   7) int sinfo_new_fit_slits_edge( cpl_image   * lineImage, 
+*                        FitParams ** par,
+*                        float     ** sinfo_slit_pos,
+*                        int          box_length,
+*                        float        y_box,
+*                        float        diff_tol )
+*   8) int sinfo_new_fit_slits_edge_with_estimate ( cpl_image   * lineImage,
+*                                     float     ** sinfo_slit_pos,
+*                                     int          box_length,
+*                                     float        y_box,
+*                                     float        diff_tol,
+*                                     int          low_pos,
+*                                     int          high_pos )
+*
+*   DESCRIPTION
+*   1) calculates the value of a slope function with parameters 
+*      parlist at the position xdat 
+*   2) calculates the partial derivatives for a slope function with
+*      parameters parlist at position xdat 
+*   3) calculates the inverse of matrix2. The algorithm used 
+*      is the Gauss-Jordan algorithm described in Stoer,
+*      Numerische Mathematik, 1. Teil.
+*   4) builds the sinfo_matrix 
+*   5) calculates the correction sinfo_vector. The sinfo_matrix has been
+*      built by get_mat_edge(), we only have to rescale it for the 
+*      current value of labda. The sinfo_matrix is rescaled so that
+*      the diagonal gets the value 1 + labda.
+*      Next we calculate the inverse of the sinfo_matrix and then
+*      the correction sinfo_vector.
+*   6) this is a routine for making a least-squares fit of a
+*      function to a set of data points. The method used is
+*      described in: Marquardt, J.Soc.Ind.Appl.Math. 11. 431 (1963).
+*      This method is a mixture of the steepest descent method 
+*      and the Taylor method.
+*   7) fits the beginning and end position of the slitlets
+*      by using non-linear least square fitting of a step function
+*      fits a step function to the slitlet edges exposed and indicated
+*      by the brightest emission lines. To achieve this, the fit
+*      parameters are used to find the brightest emission line
+*      and to get its position for each column.
+*      The least squares fit is done by using a box smaller than
+*      the size of two slitlets
+*   8) fits the beginning and end position of the slitlets
+*      by using non-linear least square fitting of an sinfo_edge  function
+*      fits a linear edge function to the slitlet edges exposed and indicated
+*      by the brightest emission lines. The slitlet is searched within
+*      user given positions.
+*      The least squares fit is done by using a box smaller than
+*      the size of two slitlets 
+*
+*   FILES
+*
+*   ENVIRONMENT
+*
+*   RETURN VALUES
+*
+*   CAUTIONS
+*
+*   EXAMPLES
+*
+*   SEE ALSO
+*
+*   BUGS
+*
+*------------------------------------------------------------------------
+*/
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+#include "sinfo_vltPort.h"
+/*
+ * System Headers
+ */
+
+/*
+ * Local Headers
+ */
+
+#include "sinfo_absolute.h"
+#include "sinfo_recipes.h"
+/*----------------------------------------------------------------------------
+ *                                 Defines
+ *--------------------------------------------------------------------------*/
+static float  sqrarg ;
+#define SQR(a) (sqrarg = (a) , sqrarg*sqrarg)
+
+#define XDIMA         1         /* dimension of the x values */
+#define TOLA          0.001     /* fitting tolerance */
+#define LABA          0.1       /* labda parameter */
+#define ITSA          200       /* maximum number of iterations */
+#define LABFACA       10.0      /* labda step factor */
+#define LABMAXA       1.0e+10   /* maximum value for labda */
+#define LABMINA       1.0e-10   /* minimum value for labda */
+#define NPAR          4         /* number of fit parameters */
+
+/*----------------------------------------------------------------------------
+ *                                    Local variables
+ *--------------------------------------------------------------------------*/
+
+static double chi1 ;                    /* old reduced chi-squared */
+static double chi2 ;                    /* new reduced chi-squared */
+static double labda ;                   /* mixing parameter */
+static double vec[NPAR] ;               /* correction sinfo_vector */
+static double matrix1[NPAR][NPAR] ;     /* original sinfo_matrix */
+static double matrix2[NPAR][NPAR] ;     /* inverse of matrix1 */
+static int    nfree ;                   /* number of free parameters */
+static int    parptr[NPAR] ;            /* parameter pointer */
+static float  slopewidth ;              /* initial value for fit parameter 5: 
+                                           width of linear slope */
+
+/*----------------------------------------------------------------------------
+ *                    Functions private to this module
+ *--------------------------------------------------------------------------*/
+static int sinfo_new_inv_mat_edge (void) ;
+
+static void sinfo_new_get_mat_edge ( float * xdat,
+                           int   * xdim,
+                           float * ydat,
+                           float * wdat,
+                           int   * ndat,
+                           float * fpar,
+                           float * epar/*,
+                           int   * npar*/ ) ;
+
+static int sinfo_new_get_vec_edge ( float * xdat,
+                          int   * xdim,
+                          float * ydat,
+                          float * wdat,
+                          int   * ndat,
+                          float * fpar,
+                          float * epar,
+                          int   * npar ) ;
+float 
+sinfo_new_hat2 ( float * xdat, float * parlist/*, int * npar, int * ndat*/ );
+
+float 
+sinfo_new_hat1 ( float * xdat, float * parlist/*, int * npar, int * ndat*/ );
+
+void 
+sinfo_new_hat_deriv2(float * xdat, float * parlist, 
+                     float * dervs/*, int * npar*/ );
+
+void 
+sinfo_new_hat_deriv1( float * xdat, float * parlist, 
+                      float * dervs/*, int * npar*/ );
+
+int 
+sinfo_new_fit_slits1( cpl_image   * lineImage, 
+               FitParams ** par,
+               float     ** sinfo_slit_pos,
+               int          box_length,
+              float        y_box );
+
+int 
+sinfo_new_fit_slits( cpl_image   * lineImage, 
+              FitParams ** par,
+              float     ** sinfo_slit_pos,
+              int          box_length,
+              float        y_box,
+             float        slope_width );
+
+
+
+int 
+sinfo_new_fit_slits2( cpl_image   * lineImage, 
+               FitParams ** par,
+               float     ** sinfo_slit_pos,
+               int          box_length,
+               float        y_box,
+              float        diff_tol );
+/*----------------------------------------------------------------------------
+ *                            Function codes
+ *--------------------------------------------------------------------------*/
+
+/**
+   @name sinfo_new_edge()
+   input: position array xdat, parameter list parlist, number of
+                        parameters in the list npar
+   @param ndat number of data elements
+   The parameters are:
+   @param  parlist(0) pos1
+   @param  parlist(1) pos2
+   @param  parlist(2) intensity left
+   @param  parlist(3) intensity right
+   @return function value of a linear slope function that means a function 
+           with a constant intensity value for xdat values smaller than 
+           pos1, linear increasing between pos1 and pos2, constant intensity 
+           value for xdat values greater than pos2
+   @memo  calculates the value of a slope function with parameters
+          parlist at the position xdat
+ */
+
+float 
+sinfo_new_edge ( float * xdat, float * parlist/*, int * npar, int * ndat*/ )
+{
+    float return_value ;
+    float slope1 ;
+
+    /* compute the slopes */
+    slope1 = ( parlist[3] - parlist[2] ) / ( parlist[1] - parlist[0] ) ;
+
+    /* now build the hat function out of the parameters */
+    if ( xdat[0] <= parlist[0] )
+    {
+        return_value = parlist[2] ;
+    }
+    else if ( xdat[0] > parlist[0] && xdat[0] <= parlist[1] )
+    {
+        return_value = (xdat[0] - parlist[0]) * slope1 + parlist[2] ;
+    }
+    else if ( xdat[0] > parlist[1] )
+    {
+        return_value = parlist[3] ;
+    }
+    else
+    {
+        return_value = 0. ;
+    }
+    
+    return return_value ;
+}
+
+/**
+  @name  sinfo_new_hat2
+  @memo    calculates the value of a hat function with parameters 
+            parlist at the position xdat 
+ 
+  @param    xdat       position array
+  @param    parlist    parameter list
+
+  @return   function value of a linear hat function.
+
+ at note
+  -The parameter list values are:
+   -#                     parlist(0): pos1
+   -#                     parlist(1): pos2
+   -#                     parlist(2): pos3
+   -#                     parlist(3): pos4
+   -#                     parlist(4): background left
+   -#                     parlist(5): background right
+   -#                     parlist(6): intensity left
+   -#                     parlist(7): intensity right
+ at doc
+This function returns a function with a constant background value for 
+xdat values smaller than pos1, linear increasing between pos1 and pos2, 
+linear between pos2 and pos3, linear decreasing between pos3 and pos4, 
+and constant background value for xdat values greater than pos4.
+
+ */
+
+
+float 
+sinfo_new_hat2 ( float * xdat, float * parlist/*, int * npar, int * ndat*/ )
+{
+    float return_value ;
+    float slope1, slope2, slope3 ;
+
+    /* compute the slopes */
+    slope1 = ( parlist[6] - parlist[4] ) / ( parlist[1] - parlist[0] ) ;
+    slope2 = ( parlist[7] - parlist[5] ) / ( parlist[3] - parlist[2] ) ;
+    slope3 = ( parlist[7] - parlist[6] ) / ( parlist[2] - parlist[1] ) ;
+
+    /* now build the hat function out of the parameters */
+    if ( xdat[0] <= parlist[0] )
+    {
+        return_value = parlist[4] ;
+    }
+    else if ( xdat[0] > parlist[0] && xdat[0] <= parlist[1] )
+    {
+        return_value = (xdat[0] - parlist[0]) * slope1 + parlist[4] ;
+    }
+    else if ( xdat[0] > parlist[1] && xdat[0] <= parlist[2] )
+    {
+        return_value = (xdat[0] - parlist[1]) * slope3 + parlist[6] ;
+    }
+    else if ( xdat[0] > parlist[2] && xdat[0] <= parlist[3] )
+    {
+        return_value = (parlist[3] - xdat[0]) * slope2 + parlist[5] ;
+    }
+    else if ( xdat[0] > parlist[3] )
+    {
+        return_value = parlist[5] ;
+    }
+    else
+    {
+        return_value = 0. ;
+    }
+    
+    return return_value ;
+}
+
+
+/**
+  @name    sinfo_new_hat1
+  @memo    calculates the value of a hat function with parameters 
+            parlist at the position xdat 
+ 
+  @param    xdat       position array
+  @param    parlist    parameter list
+
+  @return   function value of a linear hat function.
+
+ at note
+  -The parameter list values are:
+   -#                     parlist(0): pos1
+   -#                     parlist(1): pos2
+   -#                     parlist(2): pos3
+   -#                     parlist(3): pos4
+   -#                     parlist(4): background left
+   -#                     parlist(5): background right
+   -#                     parlist(6): intensity left
+   -#                     parlist(7): intensity right
+
+ at doc
+This function returns a function with a constant background value for 
+xdat values smaller than pos1, linear increasing between pos1 and 
+pos1+slopewidth, constant value intensity between pos1+slopewidth and 
+pos2-slopewidth, linear decreasing between pos2-slopewidth and pos2, 
+and constant background value for xdat values greater than pos2.
+
+ */
+float 
+sinfo_new_hat1 ( float * xdat, float * parlist/*, int * npar, int * ndat*/ )
+{
+    float return_value=0 ;
+    float slope1, slope2 ;
+
+   /* take only positive values for the fit parameters */
+
+    /* compute the slopes */
+    slope1 = (parlist[4] - parlist[2]) / slopewidth ;
+    slope2 = (parlist[4] - parlist[3]) / slopewidth ;
+
+    /* now build the hat function out of the parameters */
+    if ( xdat[0] <= parlist[0] )
+    {
+        return_value = parlist[2] ;
+    }
+    else if ( xdat[0] > parlist[0] && xdat[0] <= parlist[0] + slopewidth )
+    {
+        return_value = (xdat[0] - parlist[0]) * slope1 + parlist[2] ;
+    }
+    else if ( xdat[0] > parlist[0] + slopewidth && 
+              xdat[0] <= parlist[1] - slopewidth )
+    {
+        return_value = parlist[4] ;
+    }
+    else if ( xdat[0] > parlist[1] - slopewidth && xdat[0] <= parlist[1] )
+    {
+        return_value = (parlist[1] - xdat[0]) * slope2 + parlist[3] ;
+    }
+    else if ( xdat[0] > parlist[1] )
+    {
+        return_value = parlist[3] ;
+    }
+    
+    return return_value ;
+}
+       
+
+/**
+  @name sinfo_new_edge_deriv()
+  @brief    calculates the partial derivatives for a slope function with
+                        parameters parlist at position xdat
+ 
+  @param    xdat       position array
+  @param    parlist    parameter list
+  @param    dervs      parameter derivatives (accuracies) list
+
+  @return   nothing (void) 
+
+ at note
+  -The parameter list values are: parlist
+   -#                     parlist[0]: pos1
+   -#                     parlist[1]: pos2
+   -#                     parlist[2]: intensity left
+   -#                     parlist[3]: intensity right
+  -The derivative values of a hat function at position xdat: dervs
+   -#                     dervs[0]: partial derivative by pos1
+   -#                     dervs[1]: partial derivative by pos2
+   -#                     dervs[2]: partial derivative by intensity left
+   -#                     dervs[3]: partial derivative by intensity right
+
+
+ */
+
+void 
+sinfo_new_edge_deriv( float * xdat, float * parlist, 
+                      float * dervs/*, int * npar*/ )
+{
+    float deriv1_slope1 ;
+
+    /* compute the slopes */
+    deriv1_slope1 =( parlist[3] - parlist[2] ) / SQR(parlist[1] - parlist[0]) ;
+
+    /* now build the hat derivatives out of the parameters */
+    if ( xdat[0] <= parlist[0] )
+    {
+        dervs[0] = 0. ;
+        dervs[1] = 0. ;
+        dervs[2] = 1. ;
+        dervs[3] = 0. ;
+    }
+    else if ( xdat[0] > parlist[0] && xdat[0] <= parlist[1] )
+    {
+        dervs[0] = ( xdat[0] - parlist[1] ) * deriv1_slope1  ;
+        dervs[1] = ( parlist[0] - xdat[0] ) * deriv1_slope1 ;
+        dervs[2] = ( parlist[0] - xdat[0] ) / ( parlist[1] - parlist[0] ) + 1.;
+        dervs[3] = ( xdat[0] - parlist[0] ) / ( parlist[1] - parlist[0] ) ;
+    }
+    else if ( xdat[0] > parlist[1] )
+    {
+        dervs[0] = 0. ;
+        dervs[1] = 0. ;
+        dervs[2] = 0. ;
+        dervs[3] = 1. ;
+    }
+}
+/**
+  @name sinfo_new_hat_deriv2
+  @memo    calculates the partial derivatives for a hat function with
+                        parameters parlist at position xdat
+ 
+  @param    xdat       position array
+  @param    parlist    parameter list
+  @param    dervs      parameter derivatives (accuracies) list
+
+  @return   nothing (void) 
+
+ at note
+  -The parameter list values are: parlist
+   -#                     parlist[0]: pos1
+   -#                     parlist[1]: pos2
+   -#                     parlist[3]: pos3
+   -#                     parlist[4]: pos4
+   -#                     parlist[5]: background left
+   -#                     parlist[6]: background right
+   -#                     parlist[7]: intensity left
+   -#                     parlist[8]: intensity right
+  -The derivative values of a hat function at position xdat: dervs
+   -#                     dervs[0]: partial derivative by pos1
+   -#                     dervs[1]: partial derivative by pos2
+   -#                     dervs[3]: partial derivative by pos3
+   -#                     dervs[4]: partial derivative by pos4
+   -#                     dervs[5]: partial derivative by background left
+   -#                     dervs[6]: partial derivative by background right
+   -#                     dervs[7]: partial derivative by intensity left
+   -#                     dervs[8]: partial derivative by intensity right
+
+
+ */
+
+void 
+sinfo_new_hat_deriv2(float * xdat, float * parlist, 
+                     float * dervs/*, int * npar*/ )
+{
+    float deriv1_slope1 ;
+    float deriv1_slope2 ;
+    float deriv1_slope3 ;
+
+    /* compute the slopes */
+    deriv1_slope1 = ( parlist[6] - parlist[4] ) / SQR(parlist[1] - parlist[0]);
+    deriv1_slope2 = ( parlist[7] - parlist[5] ) / SQR(parlist[3] - parlist[2]);
+    deriv1_slope3 = ( parlist[7] - parlist[6] ) / SQR(parlist[2] - parlist[1]);
+
+    /* now build the hat derivatives out of the parameters */
+    if ( xdat[0] <= parlist[0] )
+    {
+        dervs[0] = 0. ;
+        dervs[1] = 0. ;
+        dervs[2] = 0. ;
+        dervs[3] = 0. ;
+        dervs[4] = 1. ;
+        dervs[5] = 0. ;
+        dervs[6] = 0. ;
+        dervs[7] = 0. ;
+    }
+    else if ( xdat[0] > parlist[0] && xdat[0] <= parlist[1] )
+    {
+        dervs[0] = ( xdat[0] - parlist[1] ) * deriv1_slope1  ;
+        dervs[1] = ( parlist[0] - xdat[0] ) * deriv1_slope1 ;
+        dervs[2] = 0. ;
+        dervs[3] = 0. ;
+        dervs[4] = ( parlist[0] - xdat[0] ) / ( parlist[1] - parlist[0] ) + 1.;
+        dervs[5] = 0. ;
+        dervs[6] = ( xdat[0] - parlist[0] ) / ( parlist[1] - parlist[0] ) ;
+        dervs[7] = 0. ;
+    }
+    else if ( xdat[0] > parlist[1] && xdat[0] <= parlist[2] )
+    {
+        dervs[0] = 0. ;
+        dervs[1] = (xdat[0] - parlist[2]) * deriv1_slope3 ;
+        dervs[2] = (parlist[1] - xdat[0]) * deriv1_slope3 ;
+        dervs[3] = 0. ;
+        dervs[4] = 0. ;
+        dervs[5] = 0. ;
+        dervs[6] = (parlist[1] - xdat[0]) / (parlist[2] - parlist[1]) + 1. ;
+        dervs[7] = (xdat[0] - parlist[1]) / (parlist[2] - parlist[1]) ;
+    }
+    else if ( xdat[0] > parlist[2] && xdat[0] <= parlist[3] )
+    {
+        dervs[0] = 0. ;
+        dervs[1] = 0. ;
+        dervs[2] = ( parlist[3] - xdat[0] ) * deriv1_slope2 ;
+        dervs[3] = ( xdat[0] - parlist[2] ) * deriv1_slope2 ;
+        dervs[4] = 0. ; 
+        dervs[5] = ( xdat[0] - parlist[3] ) / ( parlist[3] - parlist[2] ) + 1.;
+        dervs[6] = 0. ;
+        dervs[7] = ( parlist[3] - xdat[0] ) / ( parlist[3] - parlist[2] ) ;
+    }
+    else if ( xdat[0] > parlist[3] )
+    {
+        dervs[0] = 0. ;
+        dervs[1] = 0. ;
+        dervs[2] = 0. ;
+        dervs[3] = 0. ;
+        dervs[4] = 0. ;
+        dervs[5] = 1. ;
+        dervs[6] = 0. ;
+        dervs[7] = 0. ;
+    }
+}
+
+/**
+  @name  sinfo_new_hat_deriv1
+  @memo    calculates the partial derivatives for a hat function with
+                        parameters parlist at position xdat
+ 
+  @param    xdat       position array
+  @param    parlist    parameter list
+  @param    dervs      parameter derivatives (accuracies) list
+
+  @return   nothing (void) 
+
+ at note
+  -The parameter list values are: parlist
+   -#                     parlist[0]: pos1
+   -#                     parlist[1]: pos2
+   -#                     parlist[2]: background1
+   -#                     parlist[3]: background2
+   -#                     parlist[4]: intensity
+  -The derivative values of a hat function at position xdat: dervs
+   -#                     dervs[0]: partial derivative by pos1
+   -#                     dervs[1]: partial derivative by pos2
+   -#                     dervs[2]: partial derivative by background1
+   -#                     dervs[3]: partial derivative by background2
+   -#                     dervs[4]: partial derivative by intensity
+
+
+ */
+
+void 
+sinfo_new_hat_deriv1( float * xdat, float * parlist, 
+                      float * dervs/*, int * npar*/ )
+{
+    /* now build the hat derivatives out of the parameters */
+    if ( xdat[0] <= parlist[0] )
+    {
+        dervs[0] = 0. ;
+        dervs[1] = 0. ;
+        dervs[2] = 1. ;
+        dervs[3] = 0. ;
+        dervs[4] = 0. ;
+    }
+    else if ( xdat[0] > parlist[0] && xdat[0] <= parlist[0] + slopewidth )
+    {
+        dervs[0] = ( parlist[2] - parlist[4] ) / slopewidth ;
+        dervs[1] = 0. ;
+        dervs[2] = (( parlist[0] - xdat[0] ) / slopewidth ) + 1. ;
+        dervs[3] = 0. ;
+        dervs[4] = ( xdat[0] - parlist[0] ) / slopewidth ;
+    }
+    else if ( xdat[0] > parlist[0] + slopewidth && xdat[0] <= 
+              parlist[1] - slopewidth )
+    {
+        dervs[0] = 0. ;
+        dervs[1] = 0. ;
+        dervs[2] = 0. ;
+        dervs[3] = 0. ;
+        dervs[4] = 1. ;
+    }
+    else if ( xdat[0] > parlist[1] - slopewidth && xdat[0] <= parlist[1] )
+    {
+        dervs[0] = 0. ;
+        dervs[1] = ( parlist[4] - parlist[3] ) / slopewidth ;
+        dervs[2] = 0. ;
+        dervs[3] = (( xdat[0] - parlist[1] ) / slopewidth ) + 1. ;
+        dervs[4] = ( parlist[1] - xdat[0] ) / slopewidth ; 
+    }
+    else if ( xdat[0] > parlist[1] )
+    {
+        dervs[0] = 0. ;
+        dervs[1] = 0. ;
+        dervs[2] = 0. ;
+        dervs[3] = 1. ;
+        dervs[4] = 0. ;
+    }
+}
+   
+/**
+  @name  sinfo_new_inv_mat_edge
+  @brief    calculates the inverse of matrix2. 
+
+  @doc      The algorithm used 
+            is the Gauss-Jordan algorithm described in Stoer,
+            Numerische Mathematik, 1. Teil.
+
+  @return   integer (0 if it worked, -6 if determinant is zero)
+
+ */
+static int 
+sinfo_new_inv_mat_edge (void)
+{
+    double even ;
+    double hv[NPAR] ;
+    double mjk ;
+    double rowmax ;
+    int evin ;
+    int i, j, k, row ;
+    int per[NPAR] ;
+   
+    /* set permutation array */
+    for ( i = 0 ; i < nfree ; i++ )
+    {
+        per[i] = i ;
+    }
+    
+    for ( j = 0 ; j < nfree ; j++ ) /* in j-th column */
+    {
+        /* determine largest element of a row */                           
+        rowmax = fabs ( matrix2[j][j] ) ;
+        row = j ;                         
+
+        for ( i = j + 1 ; i < nfree ; i++ )
+        {
+            if ( fabs ( matrix2[i][j] ) > rowmax )
+            {
+                rowmax = fabs( matrix2[i][j] ) ;
+                row = i ;
+            }
+        }
+
+        /* determinant is zero! */
+        if ( matrix2[row][j] == 0.0 )
+        {
+            return -6 ;
+        }
+        
+        /* if the largest element is not on the diagonal, then permutate rows */
+        if ( row > j )
+        {
+            for ( k = 0 ; k < nfree ; k++ )
+            {
+                even = matrix2[j][k] ;
+                matrix2[j][k] = matrix2[row][k] ;
+                matrix2[row][k] = even ;
+            }
+            /* keep track of permutation */
+            evin = per[j] ;
+            per[j] = per[row] ;
+            per[row] = evin ;
+        }
+        
+        /* modify column */
+        even = 1.0 / matrix2[j][j] ;
+        for ( i = 0 ; i < nfree ; i++ )
+        {
+            matrix2[i][j] *= even ;
+        }
+        matrix2[j][j] = even ;
+        
+        for ( k = 0 ; k < j ; k++ )
+        {
+            mjk = matrix2[j][k] ;
+            for ( i = 0 ; i < j ; i++ )
+            {
+                matrix2[i][k] -= matrix2[i][j] * mjk ;
+            }
+            for ( i = j + 1 ; i < nfree ; i++ )
+            {
+                matrix2[i][k] -= matrix2[i][j] * mjk ;
+            }
+            matrix2[j][k] = -even * mjk ;
+        }
+    
+        for ( k = j + 1 ; k < nfree ; k++ )
+        {
+            mjk = matrix2[j][k] ;
+            for ( i = 0 ; i < j ; i++ )
+            {
+                matrix2[i][k]  -= matrix2[i][j] * mjk ;
+            }
+            for ( i = j + 1 ; i < nfree ; i++ )
+            {
+                matrix2[i][k]  -= matrix2[i][j] * mjk ;
+            }
+            matrix2[j][k] = -even * mjk ;
+        }
+    }
+    
+    /* finally, repermute the columns */
+    for ( i = 0 ; i < nfree ; i++ )
+    {
+        for ( k = 0 ; k < nfree ; k++ )
+        {
+            hv[per[k]] = matrix2[i][k] ;
+        }
+        for ( k = 0 ; k < nfree ; k++ )
+        {
+            matrix2[i][k] = hv[k] ;
+        }
+    }
+        
+    /* all is well */
+    return 0 ;
+}
+    
+/**
+  @name sinfo_new_get_mat_edge
+  @memo    builds the sinfo_matrix
+ 
+  @param    xdat       position array
+  @param    xdim       factor of the indeces of the position array 
+  @param    ydat       real data
+  @param    wdat       weights
+  @param    ndat       number of data points
+  @param    fpar       function parameters
+  @param    epar       partial derivatives of the function
+  @param    npar       number of function parameters
+
+
+  @return   nothing (void) 
+
+ */
+
+static void 
+sinfo_new_get_mat_edge ( float * xdat,
+                           int   * xdim,
+                           float * ydat,
+                           float * wdat,
+                           int   * ndat,
+                           float * fpar,
+                           float * epar/*,
+                           int   * npar*/ )
+{
+    double wd ;
+    double wn ;
+    double yd ;
+    int i, j, n ;
+
+    for ( j = 0 ; j < nfree ; j++ )
+    {
+        vec[j] = 0.0 ; /* zero sinfo_vector */
+        for ( i = 0 ; i<= j ; i++ )   /* zero matrix only on and 
+                                         below diagonal */
+        {
+            matrix1[j][i] = 0.0 ;
+        }
+    }
+    chi2 = 0.0 ;  /* reset reduced chi-squared */
+    
+    /* loop through data points */
+    for ( n = 0 ; n < (*ndat) ; n++ )
+    {
+        wn = wdat[n] ;
+        if ( wn > 0.0 )  /* legal weight ? */
+        {
+            yd = ydat[n] - sinfo_new_edge( &xdat[(*xdim) * n], 
+                                           fpar/*, npar, ndat*/ ) ;
+            sinfo_new_edge_deriv( &xdat[(*xdim) * n], fpar, epar/*, npar */) ;
+            chi2 += yd * yd * wn ; /* add to chi-squared */
+            for ( j = 0 ; j < nfree ; j++ )
+            {
+                wd = epar[parptr[j]] * wn ;  /* weighted derivative */
+                vec[j] += yd * wd ;       /* fill sinfo_vector */
+                for ( i = 0 ; i <= j ; i++ ) /* fill sinfo_matrix */
+                {
+                    matrix1[j][i] += epar[parptr[i]] * wd ;
+                }
+            }
+        }
+    }                   
+}  
+                
+            
+
+/**
+  @name   sinfo_new_get_vec_edge 
+  @memo    Calculates the correction sinfo_vector.
+ 
+  @param    xdat       position array
+  @param    xdim       factor of the indeces of the position array 
+  @param    ydat       real data
+  @param    wdat       weights
+  @param    ndat       number of data points
+  @param    fpar       function parameters
+  @param    epar       partial derivatives of the function
+  @param    npar       number of function parameters
+
+
+  @return   integer ( # 0        if it had worked, 
+                      # -5 or -7  if diagonal element is wrong, or 
+                      # -6,       if determinant is zero )
+
+ at doc
+  Calculates the correction sinfo_vector. The sinfo_matrix has been built 
+  by get_mat_edge(), we only have to rescale it for the 
+  current value of labda. The sinfo_matrix is rescaled so that
+  the diagonal gets the value 1 + labda.
+  Next we calculate the inverse of the sinfo_matrix and then
+  the correction sinfo_vector.
+
+ */
+
+            
+static int 
+sinfo_new_get_vec_edge ( float * xdat,
+                          int   * xdim,
+                          float * ydat,
+                          float * wdat,
+                          int   * ndat,
+                          float * fpar,
+                          float * epar,
+                          int   * npar )
+{
+    double dj ;
+    double dy ;
+    double mii ;
+    double mji ;
+    double mjj ;
+    double wn ;
+    int i, j, n, r ;
+
+    /* loop to modify and scale the sinfo_matrix */
+    for ( j = 0 ; j < nfree ; j++ )
+    {
+        mjj = matrix1[j][j] ;
+        if ( mjj <= 0.0 )             /* diagonal element wrong */
+        {
+            return -5 ;
+        }
+        mjj = sqrt( mjj ) ;
+        for ( i = 0 ; i < j ; i++ )
+        {
+            mji = matrix1[j][i] / mjj / sqrt( matrix1[i][i] ) ;
+            matrix2[i][j] = matrix2[j][i] = mji ;
+        }
+        matrix2[j][j] = 1.0 + labda ;  /* scaled value on diagonal */
+    }    
+    
+    if ( (r = sinfo_new_inv_mat_edge()) ) /* sinfo_invert sinfo_matrix inlace */
+    {
+        return r ;
+    }
+    
+    for ( i = 0 ; i < (*npar) ; i ++ )
+    {
+        epar[i] = fpar[i] ;
+    }
+    
+    /* loop to calculate correction sinfo_vector */
+    for ( j = 0 ; j < nfree ; j++ )
+    {
+        dj = 0.0 ;
+        mjj = matrix1[j][j] ;
+        if ( mjj <= 0.0)               /* not allowed */
+        {
+            return -7 ;
+        }
+        mjj = sqrt ( mjj ) ;
+        for ( i = 0 ; i < nfree ; i++ )
+        {
+            mii = matrix1[i][i] ;
+            if ( mii <= 0.0 )
+            {
+                return -7 ;
+            }
+            mii = sqrt( mii ) ;
+            dj += vec[i] * matrix2[j][i] / mjj / mii ;
+        }
+        epar[parptr[j]] += dj ;       /* new parameters */
+    }    
+    chi1 = 0.0 ;                      /* reset reduced chi-squared */
+ 
+    /* loop through the data points */
+    for ( n = 0 ; n < (*ndat) ; n++ )
+    {
+        wn = wdat[n] ;               /* get weight */
+        if ( wn > 0.0 )              /* legal weight */
+        {
+            dy = ydat[n] - sinfo_new_edge( &xdat[(*xdim) * n], epar
+                                                /*, npar, ndat*/) ;
+            chi1 += wdat[n] * dy * dy ;
+        }
+    }
+    return 0 ;
+}   
+    
+        
+/**
+  @name sinfo_new_lsqfit_edge
+  @brief    Least square fit of a function to a set of data points
+
+  @param  xdat position, coordinates of data points.
+                             xdat is 2 dimensional: XDAT ( XDIM, NDAT )
+  @param  xdim dimension of fit
+  @param  ydat data points
+  @param  wdat weights for data points
+  @param  ndat number of data points
+  @param  fpar on input contains initial estimates of the 
+               parameters for non-linear fits, on output the
+               fitted parameters.
+  @param  epar contains estimates of the errors in fitted parameters
+  @param  mpar logical mask telling which parameters are free (non-zero)
+               and which parameters are fixed (0)
+  @param  npar number of function parameters ( free + fixed )
+  @param  tol  relative tolerance. sinfo_lsqfit_edge stops when successive 
+               iterations
+               fail to produce a decrement in reduced chi-squared less
+               than tol. If tol is less than the minimum tolerance 
+               possible, tol will be set to this value. This means
+               that maximum accuracy can be obtained by setting tol = 0.0.
+  @param  its  maximum number of iterations
+  @param  lab  mixing parameter, lab determines the initial weight
+               of steepest descent method relative to the Taylor method
+               lab should be a small value (i.e. 0.01). lab can only
+               be zero when the partial derivatives are independent
+               of the parameters. In fact in this case lab should be
+               exactly equal to zero.
+
+  @returns     returns number of iterations needed to achieve convergence
+               according to tol. When this number is negative, the fitting
+               was not continued because a fatal error occurred:
+               #         -1 too many free parameters, maximum is 32
+               #         -2 no free parameters
+               #         -3 not enough degrees of freedom
+               #         -4 maximum number of iterations too small to obtain
+                           a solution which satisfies tol.
+               #         -5 diagonal of sinfo_matrix contains elements which 
+                            are zero
+               #         -6 determinant of the coefficient sinfo_matrix is zero
+               #         -7 square root of a negative number 
+
+ at doc
+   this is a routine for making a least-squares fit of a function to a set of 
+   data points. The method used is described in: 
+   Marquardt, J.Soc.Ind.Appl.Math. 11. 431 (1963). 
+   This method is a mixture of the steepest descent method and the Taylor 
+   method.
+
+*/
+
+int 
+sinfo_new_lsqfit_edge ( float * xdat,
+                  int   * xdim,
+                  float * ydat,
+                  float * wdat,
+                  int   * ndat,
+                  float * fpar,
+                  float * epar,
+                  int   * mpar,
+                  int   * npar,
+                  float * tol ,
+                  int   * its ,
+                  float * lab  )
+{
+    int i, n, r ;
+    int itc ;                      /* fate of fit */
+    int found ;                    /* fit converged: 1, not yet converged: 0 */
+    int  nuse ;                    /* number of useable data points */
+    double tolerance ;             /* accuracy */
+
+    itc   = 0 ;                    /* fate of fit */
+    found = 0 ;                    /* reset */
+    nfree = 0 ;                    /* number of free parameters */
+    nuse  = 0 ;                    /* number of legal data points */
+
+    if ( *tol < (FLT_EPSILON * 10.0 ) )
+    {
+        tolerance = FLT_EPSILON * 10.0 ;  /* default tolerance */
+    }
+    else
+    {
+        tolerance = *tol ;                /* tolerance */
+    }
+    
+    labda = fabs( *lab ) * LABFACA ;      /* start value for mixing parameter */
+    for ( i = 0 ; i < (*npar) ; i++ )
+    {
+        if ( mpar[i] )
+        {
+            if ( nfree > NPAR )         /* too many free parameters */
+            {
+                return -1 ;
+            }
+            parptr[nfree++] = i ;         /* a free parameter */
+        }
+    }
+    
+    if (nfree == 0)                       /* no free parameters */     
+    {
+        return -2 ;
+    }
+    
+    for ( n = 0 ; n < (*ndat) ; n++ )
+    {
+        if ( wdat[n] > 0.0 )              /* legal weight */
+        {
+            nuse ++ ;
+        }
+    }
+    
+    if ( nfree >= nuse )
+    {
+        return -3 ;                       /* no degrees of freedom */
+    }
+    if ( labda == 0.0 )                   /* linear fit */
+    {
+        /* initialize fpar array */
+        for ( i = 0 ; i < nfree ; fpar[parptr[i++]] = 0.0 ) ; 
+        sinfo_new_get_mat_edge(xdat,xdim,ydat,wdat,ndat,fpar,epar/*, npar */) ;
+        r =  sinfo_new_get_vec_edge ( xdat, xdim, ydat, wdat, ndat, 
+                                      fpar, epar, npar ) ;
+        if ( r )                         /* error */
+        {
+            return r ;
+        }
+        for ( i = 0 ; i < (*npar) ; i++ )
+        {
+            fpar[i] = epar[i] ;           /* save new parameters */
+            epar[i] = 0.0 ;               /* and set errors to zero */
+        }
+        chi1 = sqrt( chi1 / (double) (nuse - nfree) ) ;
+        for ( i = 0 ; i < nfree ; i++ )
+        {
+            if ( (matrix1[i][i] <= 0.0 ) || (matrix2[i][i] <= 0.0) )
+            {
+                return -7 ;
+            }
+            epar[parptr[i]] = chi1 * sqrt( matrix2[i][i] ) / 
+                                     sqrt( matrix1[i][i] ) ;
+        }
+    }
+    else                                  /* non-linear fit */
+    {
+        /*----------------------------------------------------------------
+         * the non-linear fit uses the steepest descent method in combination
+         * with the Taylor method. The mixing of these methods is controlled
+         * by labda. In the outer loop ( called the iteration loop ) we build
+         * the sinfo_matrix and calculate the correction sinfo_vector. In the 
+         * inner loop
+         * (called the interpolation loop) we check whether we have obtained a
+         * better solution than the previous one. If so, we leave the inner loop
+         * else we increase labda ( give more weight to the steepest descent 
+         * method) calculate the correction sinfo_vector and check again. 
+         * After the inner loop
+         * we do a final check on the goodness of the fit and if this satisfies
+         * the tolerance we calculate the errors of the fitted parameters.
+         */
+        while ( !found )                  /* iteration loop */
+        {      
+            if ( itc++ == (*its) )        /* increase iteration counter */
+            {
+                return -4 ;               
+            }
+            sinfo_new_get_mat_edge( xdat, xdim, ydat, wdat, ndat, 
+                                    fpar, epar/*, npar*/ ) ;
+            
+            /*-------------------------------------------------------------
+             * here we decrease labda since we may assume that each iteration
+             * brings us closer to the answer.
+             */
+            if ( labda > LABMINA )
+            {
+                labda = labda / LABFACA ;         /* decrease labda */
+            }
+            r = sinfo_new_get_vec_edge ( xdat, xdim, ydat, wdat, ndat, 
+                                         fpar, epar, npar ) ;
+            if ( (int)fpar[1] - (int)fpar[0] <= 0 && fpar[1] / fpar[0] > 0. )
+            {
+                fpar[1] += 1. ;
+                continue ;
+            } 
+            if ( r )                      /* error */
+            {
+                return r ;
+            }
+
+            while ( chi1 >= chi2 )        /* interpolation loop */
+            {
+                /*-----------------------------------------------------------
+                 * The next statement is based on experience, not on the 
+                 * mathematics of the problem. It is assumed that we have 
+                 * reached convergence when the pure steepest descent method 
+                 * does not produce a better solution.
+                 */
+                if ( labda > LABMAXA )    /* assume solution found */
+                {
+                    break ;
+                }
+                labda = labda * LABFACA ;   /* increase mixing parameter */
+                r = sinfo_new_get_vec_edge ( xdat, xdim, ydat, wdat, 
+                                             ndat, fpar, epar, npar ) ;
+                if ( (int)fpar[1] - (int)fpar[0] <= 0 && 
+                     fpar[1] / fpar[0] > 0. )
+                {
+                    fpar[1] += 1. ;
+                    continue ;
+                } 
+                if ( r )                  /* error */
+                {
+                    return r ;
+                }
+            }
+
+            if ( labda <= LABMAXA )        /* save old parameters */
+            {
+                for ( i = 0 ; i < *npar ; i++ )
+                {
+                    fpar[i] = epar[i] ;
+                }
+            }
+            if ( (fabs( chi2 - chi1 ) <= (tolerance * chi1)) || 
+                  (labda > LABMAXA) )
+            {
+                /*------------------------------------------------------------
+                 * we have a satisfying solution, so now we need to calculate 
+                 * the correct errors of the fitted parameters. This we do by 
+                 * using the pure Taylor method because we are very close to 
+                 * the real solution.
+                 */
+                labda = LABMINA ;              /* for Taylor solution */
+                sinfo_new_get_mat_edge ( xdat, xdim, ydat, wdat, ndat, 
+                                         fpar, epar/*, npar */) ;
+                r = sinfo_new_get_vec_edge ( xdat, xdim, ydat, wdat, 
+                                             ndat, fpar, epar, npar ) ;
+
+                if ( r )                    /* error */
+                {
+                    return r ;
+                }
+                for ( i = 0 ; i < (*npar) ; i++ )
+                {
+                    epar[i] = 0.0 ;          /* set error to zero */
+                }
+                chi2 = sqrt ( chi2 / (double) (nuse - nfree) ) ;
+
+                for ( i = 0 ; i < nfree ; i++ )
+                {
+                    if ( (matrix1[i][i] <= 0.0) || (matrix2[i][i] <= 0.0) )
+                    {
+                        return -7 ;
+                    }
+                    epar[parptr[i]] = chi2 * sqrt( matrix2[i][i] ) / 
+                                             sqrt( matrix1[i][i] ) ;
+                }
+                found = 1 ;                  /* we found a solution */
+            }
+        }
+    }
+    return itc ;                             /* return number of iterations */
+}
+/**
+  @name sinfo_new_fit_slits1
+  @memo fits the beginning and end position of the slitlets by using non-linear
+        least square fitting of a hat function
+
+   @param   lineImage        emission line frame
+   @param   par              fit parameter data structure of fitted lines
+   @param   sinfo_slit_pos   allocated dummy array for the slitlet 
+                             positions [32][2]
+   @param   box_length       pixel length of the row box within the fit is done
+   @param   y_box            small box in spectral direction within the slitlet
+                              may lie.
+   @param   sinfo_slit_pos   (out) beginning and end position of the slitlets 
+                             to sub-pixel accuracy
+   @returns  #            0  if it worked,
+             #           -1  if there was no line image given,
+             #           -2  if there were no line fit parameters given,
+             #           -3  if there was no dummy array for the slit positions
+                            allocated
+             #           -4  if the given box length is impossible
+             #           -5  if the given y box length is impossible
+             #           -6  if there were no emission lines found in the 
+                             first image columns
+             #           -7  if not all slitlets could be found
+             #           -8  if the least squares fit failed
+  */
+
+
+int 
+sinfo_new_fit_slits1( cpl_image   * lineImage, 
+               FitParams ** par,
+               float     ** sinfo_slit_pos,
+               int          box_length,
+               float        y_box )
+{
+    float* position=NULL ;
+    int   * sinfo_edge, * edgeclean ;
+    int   * dummyedge ;
+    int   * pos_row, * pos_rowclean ;
+    Vector * box_buffer ;
+    float max_intensity ;
+    float row_pos ;
+    int   col ;
+    int   i, j, k, m, n, ed ;
+    int   found, init1, init2 ;
+    int   line ; 
+    int   column ;
+    int   slit_length ;
+    int   agreed ;
+    int   bad_line ;
+    int   margin ;
+    int   iters, xdim, ndat ;
+    int   numpar, its ;
+    int   * mpar ;
+    float * xdat, * wdat ;
+    float tol, lab ;
+    float fitpar[2*NPAR] ;
+    float dervpar[NPAR] ;
+    float minval, maxval ;
+    int ilx=0;
+    int ily=0;
+    float* pidata=NULL;
+
+
+    if ( NULL == lineImage )
+    {
+        sinfo_msg_error("no line image given!" ) ;
+        return -1 ;
+    }
+    ilx=cpl_image_get_size_x(lineImage);
+    ily=cpl_image_get_size_y(lineImage);
+    pidata=cpl_image_get_data_float(lineImage);
+
+    slit_length = (int) sqrt (ilx) ;
+    if ( NULL == par )
+    {
+        sinfo_msg_error("no line fit parameters given!") ;
+        return -2 ;
+    }
+
+    if ( NULL == sinfo_slit_pos )
+    {
+        sinfo_msg_error("no position array allocated!") ;
+        return -3 ;
+    }
+
+    if ( box_length <  slit_length ||
+         box_length >= 3*slit_length )
+    {
+        sinfo_msg_error("wrong fitting box length given!" ) ;
+        return -4 ;
+    }
+
+    if ( y_box <= 0.  || y_box > 3. )
+    {
+        sinfo_msg_error("wrong y box length given!" ) ;
+        return -5 ;
+    }
+
+    /* allocate memory for the edges and the row positon of the slitlets */
+    sinfo_edge         = (int*) cpl_calloc( 3*slit_length, sizeof(int) ) ;
+    dummyedge    = (int*) cpl_calloc( 3*slit_length, sizeof(int) ) ;
+    edgeclean    = (int*) cpl_calloc( slit_length-1, sizeof(int) ) ;
+    pos_row      = (int*) cpl_calloc( 3*slit_length, sizeof(int) ) ;
+    pos_rowclean = (int*) cpl_calloc( slit_length, sizeof(int) ) ;
+
+    /* ------------------------------------------------------------------------
+     * go through the first image columns and the fit parameters and find 
+     *  the line with the highest intensity 
+     */
+    agreed = -1 ;
+    bad_line = -1 ;
+    while( agreed == -1 )
+    {
+        found = -1 ;
+        max_intensity = -FLT_MAX ;
+        for ( col = 0 ; col < box_length ; col++ )
+        {
+            for ( i = 0 ; i < par[0]->n_params ; i++ )
+            {
+                if ( par[i]->column == col && par[i]->line != bad_line )
+                {
+                    if ( par[i]->fit_par[0] > max_intensity )
+                    {
+                        if ( par[i]->fit_par[1] > 0. )
+                        {
+                            max_intensity = par[i]->fit_par[0] ;
+                            found = i ;
+                        }
+                    }
+                }
+            }  
+        }
+
+        /* --------------------------------------------------------------------
+         * check if the found line is usable and if the neighbouring line 
+         * have intensity on near rows in neighbouring slitlets 
+         */
+        line    = par[found]->line ;
+        column  = par[found]->column ;
+        row_pos = par[found]->fit_par[2] ;
+        if ( found >= 0 && max_intensity > 0. )
+        {
+            for ( i = 0 ; i < par[0]->n_params ; i++ )
+            {
+                if ( par[i]->line == line-1 && 
+                     par[i]->column == column + slit_length )
+                {
+                    if ( par[i]->fit_par[2] <= (row_pos + y_box) &&
+                         par[i]->fit_par[2] >= (row_pos - y_box) )
+                    {
+                        bad_line = line ;
+                    } 
+                }
+            }
+            if ( bad_line != line )
+            {
+                agreed = 1 ;
+                break ;
+            }
+        }
+        else 
+        {
+          sinfo_msg_error("no emission line found in the first image columns");
+          return -6 ;
+        }    
+    }
+
+ 
+    if ( agreed == -1 )
+    {
+        sinfo_msg_error("no emission line found in the first image columns") ;
+        return -6 ;
+    }    
+ 
+    /* now find and store the raw sinfo_edge positions of the found slitlet */ 
+    n  = 0 ;
+    ed = 0 ;
+  
+
+    position=cpl_calloc(ilx,sizeof(float));
+    for ( col = 0 ; col < ilx ; col++ )
+    {
+        for ( i = 0 ; i < par[0]->n_params ; i++ )
+        {
+            if ( par[i]->column == col && par[i] -> line == line )
+            {
+                if ( par[i]->fit_par[0] > 0. && par[i]->fit_par[1] > 0. )
+                {
+                    position[n] = par[i]->fit_par[2] ;
+                    if ( n > 0 && fabs(position[n] - position[n-1]) > y_box )
+                    {
+                        sinfo_edge[ed] = col ; 
+                        pos_row[ed] = sinfo_new_nint( position[n-1] ) ;
+                        ed++ ;
+                        if ( col >= ilx - slit_length - 5 ) 
+                        {
+                            pos_row[ed] =  sinfo_new_nint( position[n] ) ;
+                        }
+                    }
+                    n++ ;
+                }
+            }
+        }
+    }
+    if ( ed < (slit_length - 1) )
+    {
+        sinfo_msg_error("not enough slitlets found") ;
+        return -7 ;
+    } 
+
+    /* now find the clean sinfo_edge and row positions of the slitlets */
+    for ( i = 1 ; i <= ed ; i ++ )
+    {
+        if (dummyedge[i-1] != -1)
+        {
+            dummyedge[i-1] = sinfo_edge[i-1] ;
+        }
+        if ( (sinfo_edge[i] - sinfo_edge[i-1]) < slit_length - 3 ||
+             (sinfo_edge[i] - sinfo_edge[i-1]) > slit_length + 3 )
+        {
+            dummyedge[i]   = -1 ;
+        }
+        if ( (sinfo_edge[i+1] - sinfo_edge[i]) < slit_length - 3 ||
+             (sinfo_edge[i+1] - sinfo_edge[i]) > slit_length + 3 )
+        {
+            dummyedge[i+1] = -1 ; 
+        }
+    }
+    
+    k = 0 ;
+    for ( i = 0 ; i < ed ; i++ )
+    {
+        if ( dummyedge[i] != -1 && dummyedge[i] != 0 )
+        {
+            edgeclean[k] = dummyedge[i] ;
+            pos_rowclean[k] = pos_row[i] ;
+            k++ ;
+            if( edgeclean[k-1] > (ilx - slit_length - 6 ) )
+            {
+                pos_rowclean[k] = pos_row[ed] ;
+            }
+        }
+    }
+
+    if ( k != slit_length - 1 )
+    {
+        sinfo_msg_error("not enough clean slitlets found") ;
+        return -7 ;
+    } 
+
+    /* determine the margins of the fitting box outside the slitlets */
+    margin = ( box_length - slit_length ) / 2 ;
+
+    /* now go through the slitlets and store the intensity in a 
+       buffer sinfo_vector */
+    for ( j = 0 ; j < k ; j++ )
+    {
+        m = 0 ;
+        if ( j == 0 )
+        {
+            box_buffer = sinfo_new_vector( edgeclean[0] + margin ) ;
+            for( col = 0 ; col < edgeclean[0] + margin ; col++ )
+            {
+                box_buffer->data[m] = pidata[col + ilx*pos_rowclean[0]] ;
+                m++ ;
+            }
+            fitpar[0] = 3. ;
+            fitpar[1] = 5. ;
+            fitpar[2] = (float) edgeclean[0] - 1. ;
+            fitpar[3] = (float) edgeclean[0] + 1. ;
+          
+        }
+        else if ( j < k - 1 )
+        {
+            box_buffer = sinfo_new_vector( edgeclean[j] - 
+                                           edgeclean[j-1] + 2*margin ) ;
+            for ( col = edgeclean[j - 1] - margin ; 
+                  col < edgeclean[j] + margin ; col++ )
+            {
+                box_buffer->data[m] = pidata[col + ilx*pos_rowclean[j]] ;
+                m++ ;
+            }
+            fitpar[0] = (float) margin - 1. ;
+            fitpar[1] = (float) margin + 1. ;
+            fitpar[2] = (float) (edgeclean[j] - edgeclean[j-1] + margin) - 1. ;
+            fitpar[3] = (float) (edgeclean[j] - edgeclean[j-1] + margin) + 1. ;
+        }
+        /*else if ( j == k - 1 )*/
+        else
+        {
+            box_buffer = sinfo_new_vector( ilx - edgeclean[k-1] + margin ) ;
+            for ( col = edgeclean[k - 1] - margin ; col < ilx ; col++ )
+            {
+                box_buffer->data[m] = pidata[col + ilx*pos_rowclean[k]] ;
+                m++ ;
+            }
+            fitpar[0] = (float) margin - 1. ;
+            fitpar[1] = (float) margin + 1. ;
+            fitpar[2] = (float) (ilx - edgeclean[k-1] + margin) - 3. ;
+            fitpar[3] = (float) (ilx - edgeclean[k-1] + margin) - 1. ;
+        }
+
+        xdat = (float *) cpl_calloc(box_buffer -> n_elements,sizeof (float) ) ;
+        wdat = (float *) cpl_calloc(box_buffer -> n_elements,sizeof (float) ) ;
+        mpar = (int *)   cpl_calloc(NPAR, sizeof (int) ) ;
+
+        /* set initial values for the fitting routine */
+        minval =  FLT_MAX ;
+        maxval = -FLT_MAX ;
+        for ( i = 0 ; i < box_buffer->n_elements ; i++ )
+        {
+            xdat[i] = i ;
+            wdat[i] = 1.0 ;
+            if ( box_buffer -> data[i] < minval )
+            {
+                minval = box_buffer -> data[i] ;
+            }
+            if ( box_buffer -> data[i] > maxval )
+            {
+                maxval = box_buffer -> data[i] ;
+            }
+        }
+
+        fitpar[4] = minval ;
+        fitpar[5] = minval ;
+        fitpar[6] = maxval ; 
+        fitpar[7] = maxval ;
+
+        /* search for both positions of the half intensity of the 
+           hat within the buffer */
+        init1 = -1 ; 
+        init2 = -1 ;
+        for ( i = 0 ; i < box_buffer->n_elements ; i++ )
+        {
+            if ( box_buffer -> data[i] >= ( maxval - minval ) / 2. )
+            {
+                init1 = i ;
+                break ;
+            }
+        }
+
+        for ( i = box_buffer->n_elements - 1 ; i >= 0  ; i-- )
+        {
+            if ( box_buffer -> data[i] >= ( maxval + minval ) / 2. )
+            {
+                init2 = i ;
+                break ;
+            }
+        }
+  
+        /* determine the initial positions from the found values */
+      /*  if ( init1 != -1 )
+        {
+            fitpar[0] = init1 - 1. ;
+            fitpar[1] = init1 + 1. ;
+        }
+        if ( init2 != -1 )
+        {
+            fitpar[2] = init2 - 1. ;
+            fitpar[3] = init2 + 1. ;
+        } */
+
+        for ( i = 0 ; i < NPAR ; i++ )
+        {
+            mpar[i] = 1 ;
+            dervpar[i] = 0. ;
+        }
+     
+        xdim     = XDIMA ;
+        ndat     = box_buffer -> n_elements ;
+        numpar   = NPAR ;
+        tol      = TOLA ;
+        lab      = LABA ;
+        its      = ITSA ;
+        
+        /* finally, do the least squares fit over the buffer data */
+        if ( 0 > ( iters = sinfo_new_lsqfit_edge( xdat, &xdim, 
+                                                  box_buffer -> data, 
+                                                  wdat, &ndat, fitpar,
+                                                  dervpar, mpar, 
+                                                  &numpar, &tol, 
+                                                  &its, &lab )) )
+        {
+            sinfo_msg_warning("least squares fit failed, error no.: %d", 
+			      iters) ;
+            return -8 ;
+        }
+
+
+        /* take care of the column position of the fit boxes to get 
+           the absolute positions */
+        if ( j == 0 )
+        {
+            sinfo_slit_pos[0][0] = (fitpar[0] + fitpar[1]) / 2. ;
+            sinfo_slit_pos[0][1] = (fitpar[2] + fitpar[3]) / 2. ;
+        }
+        else
+        {
+            sinfo_slit_pos[j][0] = (fitpar[0] + fitpar[1]) / 2. + 
+                                   (float)edgeclean[j-1] - (float)margin ;
+            sinfo_slit_pos[j][1] = (fitpar[2] + fitpar[3]) / 2. + 
+                                   (float)edgeclean[j-1] - (float)margin ;
+        }
+     
+        sinfo_slit_pos[k][0] = (fitpar[0] + fitpar[1]) / 2.  + 
+                               (float)edgeclean[k-1] - (float)margin ;
+        sinfo_slit_pos[k][1] = (fitpar[2] + fitpar[3]) / 2. + 
+                               (float)edgeclean[k-1] - (float)margin ;
+
+        sinfo_new_destroy_vector ( box_buffer ) ;
+        cpl_free( xdat ) ;
+        cpl_free( wdat ) ;
+        cpl_free( mpar ) ;
+    }
+        
+    cpl_free( sinfo_edge ) ;
+    cpl_free( pos_row ) ;
+    cpl_free( edgeclean ) ;
+    cpl_free( dummyedge ) ;
+    cpl_free( pos_rowclean ) ;
+    cpl_free( position );
+
+    return 0 ;
+}
+                              
+/**
+  @name   sinfo_new_fit_slits
+  @memo    fits the beginning and end position of the slitlets by using 
+           non-linear least square fitting of a hat function
+
+  @param   lineImage        emission line frame
+  @param   par              fit parameter data structure of fitted lines
+  @param   sinfo_slit_pos   allocated dummy array for the slitlet 
+                            positions [32][2]
+  @param   box_length       pixel length of the row box within the fit is done
+  @param   y_box            small box in spectral direction within the slitlet
+                                    may lie.
+  @param   slope_width      width of linear slope of the hat function, must be
+                            positive
+  @param   sinfo_slit_pos  beginning and end position of the slitlets to
+                                   sub-pixel accuracy
+  @returns  #             0  if it worked,
+            #            -1  if there was no line image given,
+            #            -2  if there were no line fit parameters given,
+            #            -3  if there was no dummy array for the slit positions
+            #                allocated
+            #            -4  if the given box length is impossible
+            #            -5  if the given y box length is impossible
+            #            -6  if the given width of the linear slope is wrong
+            #            -7  if there were no emission lines found in the 
+                             first image columns
+            #            -8  if not all slitlets could be found
+            #            -9  if the least squares fit failed
+*/
+
+
+int 
+sinfo_new_fit_slits( cpl_image   * lineImage, 
+              FitParams ** par,
+              float     ** sinfo_slit_pos,
+              int          box_length,
+              float        y_box,
+              float        slope_width )
+{
+    float* position=NULL ;
+
+    int   * sinfo_edge, * edgeclean ;
+    int   * dummyedge ;
+    int   * pos_row, * pos_rowclean ;
+    Vector * box_buffer ;
+    float max_intensity ;
+    float row_pos ;
+    int   col ;
+    int   i, j, k, m, n, ed ;
+    int   found ;
+    int   line ; 
+    int   column ;
+    int   slit_length ;
+    int   agreed ;
+    int   bad_line ;
+    int   margin ;
+    int   iters, xdim, ndat ;
+    int   numpar, its ;
+    int   * mpar ;
+    float * xdat, * wdat ;
+    float tol, lab ;
+    float fitpar[NPAR] ;
+    float dervpar[NPAR] ;
+    float minval, maxval ;
+    int ilx=0;
+    int ily=0;
+    float* pidata=NULL;
+
+
+    if ( NULL == lineImage )
+    {
+        sinfo_msg_error("no line image given!" ) ;
+        return -1 ;
+    }
+    ilx=cpl_image_get_size_x(lineImage);
+    ily=cpl_image_get_size_y(lineImage);
+    pidata=cpl_image_get_data_float(lineImage);
+
+    slit_length = (int) sqrt (ilx) ;
+    if ( NULL == par )
+    {
+        sinfo_msg_error("no line fit parameters given!" ) ;
+        return -2 ;
+    }
+
+    if ( NULL == sinfo_slit_pos )
+    {
+        sinfo_msg_error("no position array allocated!" ) ;
+        return -3 ;
+    }
+
+    if ( box_length <  slit_length ||
+         box_length >= 3*slit_length )
+    {
+        sinfo_msg_error("wrong fitting box length given!" ) ;
+        return -4 ;
+    }
+
+    if ( y_box <= 0.  || y_box > 3. )
+    {
+        sinfo_msg_error("wrong y box length given!" ) ;
+        return -5 ;
+    }
+
+    if ( slope_width <= 0. )
+    {
+        sinfo_msg_error("wrong width of linear slope given!") ;
+        return -6 ;
+    }
+
+    /* initialize module global variable slopewidth */
+    slopewidth = slope_width ;
+
+    /* allocate memory for the edges and the row positon of the slitlets */
+    sinfo_edge         = (int*) cpl_calloc( 3*slit_length, sizeof(int) ) ;
+    dummyedge    = (int*) cpl_calloc( 3*slit_length, sizeof(int) ) ;
+    edgeclean    = (int*) cpl_calloc( slit_length-1, sizeof(int) ) ;
+    pos_row      = (int*) cpl_calloc( 3*slit_length, sizeof(int) ) ;
+    pos_rowclean = (int*) cpl_calloc( slit_length, sizeof(int) ) ;
+
+    /* ------------------------------------------------------------------------
+     * go through the first image columns and the fit parameters and find 
+     * the line with the highest intensity 
+     */
+    agreed = -1 ;
+    bad_line = -1 ;
+    while( agreed == -1 )
+    {
+        found = -1 ;
+        max_intensity = -FLT_MAX ;
+        for ( col = 0 ; col < box_length ; col++ )
+        {
+            for ( i = 0 ; i < par[0]->n_params ; i++ )
+            {
+                if ( par[i]->column == col && par[i]->line != bad_line )
+                {
+                    if ( par[i]->fit_par[0] > max_intensity )
+                    {
+                        if ( par[i]->fit_par[1] > 0. )
+                        {
+                            max_intensity = par[i]->fit_par[0] ;
+                            found = i ;
+                        }
+                    }
+                }
+            }  
+        }
+
+        /* --------------------------------------------------------------------
+         * check if the found line is usable and if the neighbouring line 
+         * have intensity on near rows in neighbouring slitlets 
+         */
+        line    = par[found]->line ;
+        column  = par[found]->column ;
+        row_pos = par[found]->fit_par[2] ;
+        if ( found >= 0 && max_intensity > 0. )
+        {
+            for ( i = 0 ; i < par[0]->n_params ; i++ )
+            {
+                if ( par[i]->line == line-1 && 
+                     par[i]->column == column + slit_length )
+                {
+                    if ( par[i]->fit_par[2] <= (row_pos + y_box) &&
+                         par[i]->fit_par[2] >= (row_pos - y_box) )
+                    {
+                        bad_line = line ;
+                    } 
+                }
+            }
+            if ( bad_line != line )
+            {
+                agreed = 1 ;
+                break ;
+            }
+        }
+        else 
+        {
+          sinfo_msg_error("no emission line found in the first image columns");
+          return -7 ;
+        }    
+    }
+
+ 
+    if ( agreed == -1 )
+    {
+        sinfo_msg_error("no emission line found in the first image columns") ;
+        return -7 ;
+    }    
+ 
+    /* now find and store the raw sinfo_edge positions of the found slitlet */ 
+    n  = 0 ;
+    ed = 0 ;
+    position=cpl_calloc(ilx,sizeof(float)) ;
+
+    for ( col = 0 ; col < ilx ; col++ )
+    {
+        for ( i = 0 ; i < par[0]->n_params ; i++ )
+        {
+            if ( par[i]->column == col && par[i] -> line == line )
+            {
+                if ( par[i]->fit_par[0] > 0. && par[i]->fit_par[1] > 0. )
+                {
+                    position[n] = par[i]->fit_par[2] ;
+                    if ( n > 0 && fabs(position[n] - position[n-1]) > y_box )
+                    {
+                        sinfo_edge[ed] = col ; 
+                        pos_row[ed] = sinfo_new_nint( position[n-1] ) ;
+                        ed++ ;
+                        if ( col >= ilx - slit_length - 5 ) 
+                        {
+                            pos_row[ed] =  sinfo_new_nint( position[n] ) ;
+                        }
+                    }
+                    n++ ;
+                }
+            }
+        }
+    }
+    if ( ed < (slit_length - 1) )
+    {
+        sinfo_msg_error("not enough slitlets found") ;
+        return -8 ;
+    } 
+
+    /* now find the clean sinfo_edge and row positions of the slitlets */
+    for ( i = 1 ; i <= ed ; i ++ )
+    {
+        if (dummyedge[i-1] != -1)
+        {
+            dummyedge[i-1] = sinfo_edge[i-1] ;
+        }
+        if ( (sinfo_edge[i] - sinfo_edge[i-1]) < slit_length - 3 ||
+             (sinfo_edge[i] - sinfo_edge[i-1]) > slit_length + 3 )
+        {
+            dummyedge[i]   = -1 ;
+        }
+        if ( (sinfo_edge[i+1] - sinfo_edge[i]) < slit_length - 3 ||
+             (sinfo_edge[i+1] - sinfo_edge[i]) > slit_length + 3 )
+        {
+            dummyedge[i+1] = -1 ; 
+        }
+    }
+    
+    k = 0 ;
+    for ( i = 0 ; i < ed ; i++ )
+    {
+        if ( dummyedge[i] != -1 && dummyedge[i] != 0 )
+        {
+            edgeclean[k] = dummyedge[i] ;
+            pos_rowclean[k] = pos_row[i] ;
+            k++ ;
+            if( edgeclean[k-1] > (ilx - slit_length - 6 ) )
+            {
+                pos_rowclean[k] = pos_row[ed] ;
+            }
+        }
+    }
+
+    if ( k != slit_length - 1 )
+    {
+        sinfo_msg_error ("not enough clean slitlets found") ;
+        return -7 ;
+    } 
+
+    /* determine the margins of the fitting box outside the slitlets */
+    margin = ( box_length - slit_length ) / 2 ;
+
+    /* now go through the slitlets and store the intensity in a buffer 
+       sinfo_vector */
+    for ( j = 0 ; j < k ; j++ )
+    {
+        m = 0 ;
+        if ( j == 0 )
+        {
+            box_buffer = sinfo_new_vector( edgeclean[0] + margin ) ;
+            for( col = 0 ; col < edgeclean[0] + margin ; col++ )
+            {
+                box_buffer->data[m] = pidata[col + ilx*pos_rowclean[0]] ;
+                m++ ;
+            }
+            /* initial values for the fitted positions */
+            fitpar[0] = 1. ;
+            fitpar[1] = (float)edgeclean[0] ;
+          
+        }
+        else if ( j < k - 1 )
+        {
+            box_buffer = sinfo_new_vector( edgeclean[j] - 
+                                           edgeclean[j-1] + 2*margin ) ;
+            for ( col = edgeclean[j - 1] - margin ; 
+                  col < edgeclean[j] + margin ; col++ )
+            {
+                box_buffer->data[m] = pidata[col + ilx*pos_rowclean[j]] ;
+                m++ ;
+            }
+            /* initial values for the fitted positions */
+            fitpar[0] = (float)margin ;
+            fitpar[1] = (float)(edgeclean[j] - edgeclean[j-1] + margin ) ;
+        }
+        /*else if ( j == k - 1 )*/
+        else
+        {
+            box_buffer = sinfo_new_vector( ilx - edgeclean[k-1] + margin ) ;
+            for ( col = edgeclean[k - 1] - margin ; col < ilx ; col++ )
+            {
+                box_buffer->data[m] = pidata[col + ilx*pos_rowclean[k]] ;
+                m++ ;
+            }
+            /* initial values for the fitted positions */
+            fitpar[0] = (float)margin ;
+            fitpar[1] = (float)(m - 1) ;
+        }
+
+        xdat=(float *) cpl_calloc( box_buffer -> n_elements, sizeof (float) ) ;
+        wdat=(float *) cpl_calloc( box_buffer -> n_elements, sizeof (float) ) ;
+        mpar=(int *)   cpl_calloc( NPAR, sizeof (int) ) ;
+
+        /* set initial values for the fitting routine */
+        minval =  FLT_MAX ;
+        maxval = -FLT_MAX ;
+        for ( i = 0 ; i < box_buffer->n_elements ; i++ )
+        {
+            xdat[i] = i ;
+            wdat[i] = 1.0 ;
+            if ( box_buffer -> data[i] < minval )
+            {
+                minval = box_buffer -> data[i] ;
+            }
+            if ( box_buffer -> data[i] > maxval )
+            {
+                maxval = box_buffer -> data[i] ;
+            }
+        }
+
+        for ( i = 0 ; i < NPAR ; i++ )
+        {
+            mpar[i] = 1 ;
+            dervpar[i] = 0. ;
+        }
+     
+        xdim     = XDIMA ;
+        ndat     = box_buffer -> n_elements ;
+        numpar   = NPAR ;
+        tol      = TOLA ;
+        lab      = LABA ;
+        its      = ITSA ;
+        
+        fitpar[2] = minval ;
+        fitpar[3] = minval ;
+        fitpar[4] = maxval ;
+
+        /* finally, do the least squares fit over the buffer data */
+        if ( 0 > ( iters = sinfo_new_lsqfit_edge( xdat, &xdim, 
+                                                  box_buffer -> data, 
+                                                  wdat, &ndat, fitpar,
+                                                  dervpar, mpar, &numpar, 
+                                                  &tol, &its, &lab )) )
+        {
+            sinfo_msg_warning("least squares fit failed, error no.: %d", 
+			      iters) ;
+            return -9 ;
+        }
+
+
+        /* take care of the column position of the fit boxes 
+           to get the absolute positions */
+        if ( j == 0 )
+        {
+            sinfo_slit_pos[0][0] = fitpar[0] + slopewidth/2. ;
+            sinfo_slit_pos[0][1] = fitpar[1] - slopewidth/2. ;
+        }
+        else
+        {
+            sinfo_slit_pos[j][0] = fitpar[0] + slopewidth/2. + 
+                                   (float)edgeclean[j-1] - (float)margin ;
+            sinfo_slit_pos[j][1] = fitpar[1] - slopewidth/2. + 
+                                   (float)edgeclean[j-1] - (float)margin ;
+        }
+
+        sinfo_slit_pos[k][0] = fitpar[0] + slopewidth/2. + 
+                               (float)edgeclean[k-1] - (float)margin ;
+        sinfo_slit_pos[k][1] = fitpar[1] - slopewidth/2. + 
+                               (float)edgeclean[k-1] - (float)margin ;
+     
+        sinfo_new_destroy_vector ( box_buffer ) ;
+        cpl_free( xdat ) ;
+        cpl_free( wdat ) ;
+        cpl_free( mpar ) ;
+    }
+        
+
+    cpl_free( sinfo_edge ) ;
+    cpl_free( pos_row ) ;
+    cpl_free( edgeclean ) ;
+    cpl_free( dummyedge ) ;
+    cpl_free( pos_rowclean ) ;
+    cpl_free( position );
+    return 0 ;
+}
+                              
+/**
+ at name sinfo_new_fit_slits2
+ at memo  fits the beginning and end position of the slitlets by using non-linear 
+       least square fitting of a step function fits a step function to the 
+       slitlet edges exposed and indicated by the brightest emission lines.
+
+   @param  lineImage        emission line frame
+   @param  par              fit parameter data structure of fitted lines
+   @param  sinfo_slit_pos   allocated dummy array for the slitlet 
+                            positions [32][2]
+   @param  box_length       pixel length of the row box within the fit is done
+   @param  y_box            small box in spectral direction within the slitlet 
+                            may lie.
+   @param  diff_tol         maximum tolerable difference of the resulting fit 
+                            position with respect to the expected position. 
+                            If difference is 
+                            greater the expected position is taken.
+   @param  sinfo_slit_pos   beginning and end position of the slitlets to
+                                   sub-pixel accuracy
+           #              0  if it worked,
+           #             -1  if there was no line image given,
+           #             -2  if there were no line fit parameters given,
+           #             -3  if there was no dummy array for the slit positions
+           #                 allocated
+           #             -4  if the given box length is impossible
+           #             -5  if the given y box length is impossible
+           #             -6  if the given difference tolerance is too small
+           #             -7  if there were no emission lines found in the 
+                             first image columns
+           #             -8  if not all slitlets could be found
+
+
+                        fits the beginning and end position of the slitlets
+                        by using non-linear least square fitting of a step 
+                        function fits a step function to the slitlet edges 
+                        exposed and indicated by the brightest emission lines. 
+                        To achieve this, the fit parameters are used to find 
+                        the brightest emission line and to get its position 
+                        for each column. The least squares fit is done by 
+                        using a box bigger than the size of one slitlet and 
+                        divides the box into two parts
+                        for both edges within the fit function is shifted.
+ */
+
+int 
+sinfo_new_fit_slits2( cpl_image   * lineImage, 
+               FitParams ** par,
+               float     ** sinfo_slit_pos,
+               int          box_length,
+               float        y_box,
+               float        diff_tol )
+{
+    float* position=NULL ;
+    int   * sinfo_edge, * edgeclean ;
+    int   * dummyedge ;
+    int   * pos_row, * pos_rowclean ;
+    Vector * box_buffer ;
+    Vector * half_buffer ;
+    float max_intensity ;
+    float row_pos ;
+    int   col ;
+    int   i, j, k, m, n, ed ;
+    int   found, init1 ;
+    int   line ; 
+    int   nel, n_right, left_right ;
+    int   column ;
+    int   slit_length ;
+    int   agreed ;
+    int   bad_line ;
+    int   margin ;
+    int   iters, xdim, ndat ;
+    int   numpar, its ;
+    int   * mpar ;
+    float * xdat, * wdat ;
+    float tol, lab ;
+    float fitpar[NPAR] ;
+    float dervpar[NPAR] ;
+    float minval, maxval ;
+    float pos, last_pos ;
+    int ilx=0;
+    int ily=0;
+    float* pidata=NULL;
+
+
+    if ( NULL == lineImage )
+    {
+        sinfo_msg_error("no line image given!" ) ;
+        return -1 ;
+    }
+    ilx=cpl_image_get_size_x(lineImage);
+    ily=cpl_image_get_size_y(lineImage);
+    pidata=cpl_image_get_data_float(lineImage);
+
+    slit_length = (int) sqrt (ilx) ;
+
+    if ( NULL == par )
+    {
+        sinfo_msg_error("no line fit parameters given!" ) ;
+        return -2 ;
+    }
+
+    if ( NULL == sinfo_slit_pos )
+    {
+        sinfo_msg_error("no position array allocated!" ) ;
+        return -3 ;
+    }
+
+    if ( box_length <  slit_length ||
+         box_length >= 3*slit_length )
+    {
+        sinfo_msg_error("wrong fitting box length given!" ) ;
+        return -4 ;
+    }
+
+    if ( y_box <= 0.  || y_box > 3. )
+    {
+        sinfo_msg_error("wrong y box length given!" ) ;
+        return -5 ;
+    }
+
+    if ( diff_tol < 1. )
+    {
+        sinfo_msg_error("diff_tol too small!" ) ;
+        return -6 ;
+    }
+
+    /* allocate memory for the edges and the row positon of the slitlets */
+    sinfo_edge         = (int*) cpl_calloc( 3*slit_length, sizeof(int) ) ;
+    dummyedge    = (int*) cpl_calloc( 3*slit_length, sizeof(int) ) ;
+    edgeclean    = (int*) cpl_calloc( slit_length-1, sizeof(int) ) ;
+    pos_row      = (int*) cpl_calloc( 3*slit_length, sizeof(int) ) ;
+    pos_rowclean = (int*) cpl_calloc( slit_length, sizeof(int) ) ;
+
+    /* ------------------------------------------------------------------------
+     * go through the first image columns and the fit parameters and find 
+     * the line with the highest intensity 
+     */
+    agreed = -1 ;
+    bad_line = -1 ;
+    while( agreed == -1 )
+    {
+        found = -1 ;
+        max_intensity = -FLT_MAX ;
+        for ( col = 0 ; col < box_length ; col++ )
+        {
+            for ( i = 0 ; i < par[0]->n_params ; i++ )
+            {
+                if ( par[i]->column == col && par[i]->line != bad_line )
+                {
+                    if ( par[i]->fit_par[0] > max_intensity )
+                    {
+                        if ( par[i]->fit_par[1] > 0. )
+                        {
+                            max_intensity = par[i]->fit_par[0] ;
+                            found = i ;
+                        }
+                    }
+                }
+            }  
+        }
+
+        /* --------------------------------------------------------------------
+         * check if the found line is usable and if the neighbouring line 
+         * have intensity on near rows in neighbouring slitlets 
+         */
+        line    = par[found]->line ;
+        column  = par[found]->column ;
+        row_pos = par[found]->fit_par[2] ;
+        if ( found >= 0 && max_intensity > 0. )
+        {
+            for ( i = 0 ; i < par[0]->n_params ; i++ )
+            {
+                if ( par[i]->line == line-1 && 
+                     par[i]->column == column + slit_length )
+                {
+                    if ( par[i]->fit_par[2] <= (row_pos + y_box) &&
+                         par[i]->fit_par[2] >= (row_pos - y_box) )
+                    {
+                        bad_line = line ;
+                    } 
+                }
+            }
+            if ( bad_line != line )
+            {
+                agreed = 1 ;
+                break ;
+            }
+        }
+        else 
+        {
+          sinfo_msg_error("no emission line found in the first image columns");
+          return -7 ;
+        }    
+    }
+
+ 
+    if ( agreed == -1 )
+    {
+        sinfo_msg_error("no emission line found in the first image columns") ;
+        return -7 ;
+    }    
+ 
+    /* now find and store the raw sinfo_edge positions of the found slitlet */ 
+    n  = 0 ;
+    ed = 0 ;
+    position=cpl_calloc(ilx,sizeof(float)) ;
+
+    for ( col = 0 ; col < ilx ; col++ )
+    {
+        for ( i = 0 ; i < par[0]->n_params ; i++ )
+        {
+            if ( par[i]->column == col && par[i]->line == line )
+            {
+                if ( par[i]->fit_par[0] > 0. && par[i]->fit_par[1] > 0. )
+                {
+                    position[n] = par[i]->fit_par[2] ;
+                    if ( n > 0 && fabs(position[n] - position[n-1]) > y_box )
+                    {
+                        sinfo_edge[ed] = col ; 
+                        pos_row[ed] = sinfo_new_nint( position[n-1] ) ;
+                        ed++ ;
+                        if ( col >= ilx - slit_length - 5 ) 
+                        {
+                            pos_row[ed] =  sinfo_new_nint( position[n] ) ;
+                        }
+                    }
+                    n++ ;
+                }
+            }
+        }
+    }
+    if ( ed < (slit_length - 1) )
+    {
+        sinfo_msg_error("not enough slitlets found") ;
+        return -8 ;
+    } 
+
+    /* now find the clean sinfo_edge and row positions of the slitlets */
+    for ( i = 1 ; i <= ed ; i ++ )
+    {
+        if (dummyedge[i-1] != -1)
+        {
+            dummyedge[i-1] = sinfo_edge[i-1] ;
+        }
+        if ( (sinfo_edge[i] - sinfo_edge[i-1]) < slit_length - 3 ||
+             (sinfo_edge[i] - sinfo_edge[i-1]) > slit_length + 3 )
+        {
+            dummyedge[i]   = -1 ;
+        }
+        if ( (sinfo_edge[i+1] - sinfo_edge[i]) < slit_length - 3 ||
+             (sinfo_edge[i+1] - sinfo_edge[i]) > slit_length + 3 )
+        {
+            dummyedge[i+1] = -1 ; 
+        }
+    }
+    
+    k = 0 ;
+    for ( i = 0 ; i < ed ; i++ )
+    {
+        if ( dummyedge[i] != -1 && dummyedge[i] != 0 )
+        {
+            edgeclean[k] = dummyedge[i] ;
+            pos_rowclean[k] = pos_row[i] ;
+            k++ ;
+            if( edgeclean[k-1] > (ilx - slit_length - 6 ) )
+            {
+                pos_rowclean[k] = pos_row[ed] ;
+            }
+        }
+    }
+
+    if ( k != slit_length - 1 )
+    {
+        sinfo_msg_error("not enough clean slitlets found") ;
+        return -7 ;
+    } 
+
+    /* determine the margins of the fitting box outside the slitlets */
+    margin = ( box_length - slit_length ) / 2 ;
+
+    /* now go through the slitlets and store the intensity in a 
+       buffer sinfo_vector */
+    for ( j = 0 ; j <= k ; j++ )
+    {
+        m = 0 ;
+        if ( j == 0 )
+        {
+            box_buffer = sinfo_new_vector( edgeclean[0] + margin ) ;
+            for( col = 0 ; col < edgeclean[0] + margin ; col++ )
+            {
+                box_buffer->data[m] = pidata[col +ilx*pos_rowclean[0]] ;
+                m++ ;
+            }
+        }
+        else if ( j < k )
+        {
+            box_buffer = sinfo_new_vector( edgeclean[j] - 
+                                           edgeclean[j-1] + 2*margin ) ;
+            for ( col = edgeclean[j - 1] - margin ; 
+                  col < edgeclean[j] + margin ; col++ )
+            {
+                box_buffer->data[m] = pidata[col + ilx*pos_rowclean[j]] ;
+                m++ ;
+            }
+        }
+        else 
+        {
+            box_buffer = sinfo_new_vector( ilx - edgeclean[k-1] + margin ) ;
+            for ( col = edgeclean[k - 1] - margin ; col < ilx ; col++ )
+            {
+                box_buffer->data[m] = pidata[col + ilx*pos_rowclean[k]] ;
+                m++ ;
+            }
+        }
+
+        for ( left_right = 0 ; left_right <= 1 ; left_right++ )
+        { 
+            nel = 0 ;
+            if ( left_right == 0 )
+            {
+                nel = box_buffer -> n_elements / 2 ;
+            }
+            else
+            {
+                if ( box_buffer -> n_elements % 2 == 0 )
+                {
+                    nel = box_buffer -> n_elements / 2 ;
+                }
+                else
+                {
+                    nel = box_buffer -> n_elements / 2 + 1 ;
+                }
+            }
+
+            /* now split the buffer in the midth in a left and right 
+               part for fitting */
+            half_buffer = sinfo_new_vector( nel ) ;
+            if ( left_right == 0 )
+            {
+                for ( i = 0 ; i < nel ; i++ )
+                {
+                    half_buffer -> data[i] = box_buffer -> data[i] ;
+                }
+            }
+            else
+            {
+                n_right = 0 ;
+                for ( i = box_buffer -> n_elements - 1 ; 
+                      i >= box_buffer -> n_elements - nel ; i-- )
+                {
+                    half_buffer -> data[n_right] = box_buffer -> data[i] ;
+                    n_right++ ;
+                }
+            }
+
+            xdat = (float *) cpl_calloc( nel, sizeof (float) ) ;
+            wdat = (float *) cpl_calloc( nel, sizeof (float) ) ;
+            mpar = (int *)   cpl_calloc( NPAR, sizeof (int) ) ;
+
+            /* set initial values for the fitting routine */
+            minval =  FLT_MAX ;
+            maxval = -FLT_MAX ;
+            for ( i = 0 ; i < nel ; i++ )
+            {
+                xdat[i] = i ;
+                wdat[i] = 1.0 ;
+                if ( half_buffer -> data[i] < minval )
+                {
+                    minval = half_buffer -> data[i] ;
+                }
+                if ( half_buffer -> data[i] > maxval )
+                {
+                    maxval = half_buffer -> data[i] ;
+                }
+            }
+
+            fitpar[2] = minval ;
+            fitpar[3] = maxval ; 
+
+            /* search for both positions of the half intensity of 
+               the hat within the buffer */
+            init1 = -1 ; 
+            for ( i = 0 ; i < nel ; i++ )
+            {
+                if ( half_buffer -> data[i] >= ( maxval + minval ) / 2. )
+                {
+                    init1 = i ;
+                    break ;
+                }
+            }
+
+            /* determine the initial positions from the found values */
+            if ( init1 != -1 )
+            {
+                fitpar[0] = ((float)init1 - 1.) ;
+                fitpar[1] = ((float)init1 + 1.) ;
+            }
+
+            for ( i = 0 ; i < NPAR ; i++ )
+            {
+                mpar[i] = 1 ;
+                dervpar[i] = 0. ;
+            }
+      
+            xdim     = XDIMA ;
+            ndat     = nel ;
+            numpar   = NPAR ;
+            tol      = TOLA ;
+            lab      = LABA ;
+            its      = ITSA ;
+         
+            /* finally, do the least squares fit over the buffer data */
+            if ( 0 > ( iters = sinfo_new_lsqfit_edge( xdat, &xdim, 
+                                                      half_buffer -> data, 
+                                                      wdat, &ndat, fitpar,
+                                                      dervpar, mpar, &numpar, 
+                                                      &tol, &its, &lab )) )
+            { 
+                /* if the fit doesn't succeed the initial values are taken */
+                sinfo_msg_warning (" least squares fit failed, error"
+                                   " no.: %d in slitlet: %d\n", iters, j) ;
+                fitpar[0] = ((float)init1 - 1.) ;
+                fitpar[1] = ((float)init1 + 1.) ;
+            }
+
+            pos = (fitpar[0] + fitpar[1]) / 2. ;
+
+            /*---------------------------------------------------------------- 
+             * now discern the left and the right sinfo_edge fit of the 
+             * slitlets and associate the fit results with the absolute 
+             * positions in the image consider the difference of the fitted 
+             * slit position to the expected position and decide wether the 
+             * fit is taken or the expected value is taken.
+             */
+            if ( left_right == 0 )
+            {
+                /* take care of the column position of the fit boxes 
+                   to get the absolute positions */
+                if ( j == 0 )
+                {
+                    if ( fabs(pos - ((float)edgeclean[0] - 1. - 
+                         (float)slit_length)) < diff_tol )
+                    {
+                        sinfo_slit_pos[0][0] = pos ;
+                    }
+                    else
+                    {
+                        sinfo_msg_warning("something wrong with fitted left"
+                                          " position of slitlet 0") ;
+                        if ( (float) edgeclean[0] - 1. - 
+                             (float)slit_length < 0. )
+                        {
+                            sinfo_slit_pos[0][0] = 0. ;
+                        }
+                        else
+                        {
+                            sinfo_slit_pos[0][0] = (float)edgeclean[0] - 1. - 
+                            (float)slit_length ;
+                        }
+                    }
+                }
+                else if ( j < k )
+                {
+                    if ( fabs( pos - (float)margin ) < diff_tol )
+                    {
+                        sinfo_slit_pos[j][0] = pos + (float)edgeclean[j-1] - 
+                                               (float)margin ;
+                    }
+                    else
+                    {
+                        sinfo_msg_warning("something wrong with fitted left"
+                                          " position of slitlet %d", j) ;
+                        sinfo_slit_pos[j][0] = (float)edgeclean[j-1] - 1. ;
+                    }
+                }
+                else
+                {
+                    if ( fabs( pos - (float)margin ) < diff_tol )
+                    {
+                        sinfo_slit_pos[k][0] = pos + (float)edgeclean[k-1] - 
+                                               (float)margin ;
+                    }
+                    else
+                    {
+                        sinfo_msg_warning("something wrong with fitted left"
+                                          " position of slitlet %d", j) ;
+                        sinfo_slit_pos[k][0] = (float)edgeclean[k-1] - 1. ;
+                    }
+                }
+            }
+            else
+            {
+                /* take care of the column position of the fit boxes 
+                   to get the absolute positions */
+                if ( j == 0 )
+                {
+                    if ( fabs( (float)box_buffer->n_elements - pos - 
+                               (float)edgeclean[0] ) < diff_tol )
+                    {
+                        sinfo_slit_pos[0][1] = (float)(box_buffer->n_elements - 
+                                                1) - pos ;
+                    }
+                    else
+                    {
+                        sinfo_msg_warning("something wrong with fitted "
+                                          "right position of slitlet 0") ;
+                        sinfo_slit_pos[0][1] = (float)edgeclean[0] - 1. ;
+                    }
+                }
+                else if ( j < k )
+                {
+                    if ( fabs( (float)box_buffer->n_elements - pos
+                             + (float)edgeclean[j-1] - (float)margin - 
+                               (float)edgeclean[j] ) < diff_tol )
+                    {
+                        sinfo_slit_pos[j][1] = (float)(box_buffer->n_elements -
+                                        1) - pos
+                                       + (float)edgeclean[j-1] - (float)margin ;
+                    }
+                    else
+                    {
+                        sinfo_msg_warning("something wrong with fitted right "
+                                          "position of slitlet %d", j) ;
+                        sinfo_slit_pos[j][1] = (float)edgeclean[j] - 1. ;
+                    }
+                }
+                else
+                {
+                    if ( edgeclean[k-1] + slit_length > ilx )
+                    {
+                        last_pos = (float)(ilx - 1) ;
+                    }
+                    else
+                    {
+                        last_pos = (float)(edgeclean[k-1] - 1 + slit_length) ;
+                    }
+                    if ( fabs( (float)(box_buffer->n_elements - 1) - pos
+                             + (float)edgeclean[k-1] - (float)margin - 
+                               last_pos ) < diff_tol )
+                    {
+                        sinfo_slit_pos[k][1] = (float)(box_buffer->n_elements -
+                                               1) - pos
+                                       + (float)edgeclean[k-1] - (float)margin ;
+                    }
+                    else
+                    {
+                        sinfo_msg_warning("something wrong with fitted right "
+                                          "position of slitlet %d\n", j) ;
+                        sinfo_slit_pos[k][1] = last_pos ;
+                    }
+                }
+            }
+
+            sinfo_new_destroy_vector ( half_buffer ) ;
+            cpl_free( xdat ) ;
+            cpl_free( wdat ) ;
+            cpl_free( mpar ) ;
+        }
+        sinfo_new_destroy_vector ( box_buffer ) ;
+    }
+        
+    cpl_free( sinfo_edge ) ;
+    cpl_free( pos_row ) ;
+    cpl_free( edgeclean ) ;
+    cpl_free( dummyedge ) ;
+    cpl_free( pos_rowclean ) ;
+    cpl_free(position);
+    return 0 ;
+}
+                              
+/**
+   @name  sinfo_new_fit_slits_edge()
+   @param lineImage  emission line frame
+   @param par        fit parameter data structure of fitted lines
+   @param sinfo_slit_pos   allocated dummy array for the slitlet 
+                           positions [32][4]
+   @param box_length pixel length of the row box within the fit is done
+   @param y_box      small box in spectral direction within the slitlet may 
+                      lie.
+   @param diff_tol   maximum tolerable difference of the resulting fit position
+                     with respect to the expected position. If difference is
+                     greater the expected position is taken.
+   @return sinfo_slit_pos  beginning and end position of the slitlets to
+                            sub-pixel accuracy
+                     #    0  if it worked,
+                     #   -1  if there was no line image given,
+                     #   -2  if there were no line fit parameters given,
+                     #   -3  if there was no dummy array for the slit positions
+                            allocated
+                     #   -4  if the given box length is impossible
+                     #   -5  if the given y box length is impossible
+                     #   -6  if the given difference tolerance is too small
+                     #   -7  if there were no emission lines found in the first
+                             image columns
+                     #   -8  if not all slitlets could be found
+   @doc fits the beginning and end position of the slitlets by using non-linear
+        least square fitting of a hat function fits a step function to the 
+        slitlet edges exposed and indicated by the brightest emission lines. 
+        To achieve this, the fit parameters are used to find the brightest 
+        emission line and to get its position for each column.
+        The least squares fit is done by using a box smaller than the size of 
+        two slitlets 
+ */
+
+int 
+sinfo_new_fit_slits_edge( cpl_image   * lineImage, 
+                  FitParams ** par,
+                  float     ** sinfo_slit_pos,
+                  int          box_length,
+                  float        y_box,
+                  float        diff_tol )
+{
+    float* position=NULL ;
+    int   * sinfo_edge, * edgeclean ;
+    int   * dummyedge ;
+    int   * pos_row, * pos_rowclean ;
+    Vector * box_buffer ;
+    Vector * half_buffer ;
+    float max_intensity ;
+    float row_pos ;
+    int   row, col ;
+    int   i, j, k, m, n, ed ;
+    int   found, init1 ;
+    int   line ; 
+    int   nel, n_right, left_right ;
+    int   column ;
+    int   slit_length ;
+    int   agreed ;
+    int   bad_line ;
+    int   margin ;
+    int   iters, xdim, ndat ;
+    int   numpar, its ;
+    int   * mpar ;
+    float * xdat, * wdat ;
+    float tol, lab ;
+    float fitpar[NPAR] ;
+    float dervpar[NPAR] ;
+    float minval, maxval ;
+    float pos, last_pos ;
+    int ilx=0;
+    int ily=0;
+    float* pidata=NULL;
+
+
+    if ( NULL == lineImage )
+    {
+        sinfo_msg_error(" no line image given!" ) ;
+        return -1 ;
+    }
+    ilx=cpl_image_get_size_x(lineImage);
+    ily=cpl_image_get_size_y(lineImage);
+    pidata=cpl_image_get_data_float(lineImage);
+
+    slit_length = (int) sqrt (ilx) ;
+
+    if ( NULL == par )
+    {
+        sinfo_msg_error(" no line fit parameters given!" ) ;
+        return -2 ;
+    }
+
+    if ( NULL == sinfo_slit_pos )
+    {
+        sinfo_msg_error(" no position array allocated!" ) ;
+        return -3 ;
+    }
+
+    if ( box_length <  4 ||
+         box_length >= 2*slit_length )
+    {
+        sinfo_msg_error(" wrong fitting box length given!" ) ;
+        sinfo_msg_error(" Must be 4 <= box_length < %d ",2*slit_length ) ;
+        sinfo_msg_error(" You have chosen box_length = %d ",box_length);
+        return -4 ;
+    }
+
+    if ( y_box <= 0.  || y_box > 3. )
+    {
+        sinfo_msg_error(" wrong y box length given!" ) ;
+        sinfo_msg_error(" y_box=%f not in range (0,3]!",y_box);
+        return -5 ;
+    }
+
+    if ( diff_tol < 1. )
+    {
+        sinfo_msg_error(" diff_tol too small!" ) ;
+        return -6 ;
+    }
+
+    /* allocate memory for the edges and the row positon of the slitlets */
+    sinfo_edge         = (int*) cpl_calloc( 3*slit_length, sizeof(int) ) ;
+    dummyedge    = (int*) cpl_calloc( 3*slit_length, sizeof(int) ) ;
+    edgeclean    = (int*) cpl_calloc( slit_length-1, sizeof(int) ) ;
+    pos_row      = (int*) cpl_calloc( 3*slit_length, sizeof(int) ) ;
+    pos_rowclean = (int*) cpl_calloc( slit_length, sizeof(int) ) ;
+
+    /* ------------------------------------------------------------------------
+     * go through the first image columns and the fit parameters and find 
+     * the line with the highest intensity 
+     */
+    agreed = -1 ;
+    bad_line = -1 ;
+    while( agreed == -1 )
+    {
+        found = -1 ;
+        max_intensity = -FLT_MAX ;
+        for ( col = 0 ; col < slit_length ; col++ )
+        {
+            for ( i = 0 ; i < par[0]->n_params ; i++ )
+            {
+                if ( par[i]->column == col && par[i] -> line != bad_line )
+                {
+                    if ( par[i]->fit_par[0] > max_intensity )
+                    {
+                        if ( par[i]->fit_par[1] >= 1. && 
+                             par[i]->fit_par[2] > 0. )
+                        {
+                            max_intensity = par[i]->fit_par[0] ;
+                            found = i ;
+                        }
+                    }
+                }
+            }  
+        }
+
+        /* --------------------------------------------------------------------
+         * check if the found line is usable and if the neighbouring line 
+         * have intensity on near rows in neighbouring slitlets 
+         */
+        line    = par[found]->line ;
+        column  = par[found]->column ;
+        row_pos = par[found]->fit_par[2] ;
+        if ( found >= 0 && max_intensity > 0. )
+        {
+            for ( i = 0 ; i < par[0]->n_params ; i++ )
+            {
+                if ( par[i]->line == line-1 && 
+                     par[i]->column == column + slit_length )
+                {
+                    if ( par[i]->fit_par[2] <= (row_pos + y_box) &&
+                         par[i]->fit_par[2] >= (row_pos - y_box) )
+                    {
+                        bad_line = line ;
+                    } 
+                }
+            }
+            if ( bad_line != line )
+            {
+                agreed = 1 ;
+                break ;
+            }
+        }
+        else 
+        {
+            sinfo_msg_error("no emission line found in "
+                            "the first image columns") ;
+            cpl_free( sinfo_edge ) ;
+            cpl_free( pos_row ) ;
+            cpl_free( edgeclean ) ;
+            cpl_free( dummyedge ) ;
+            cpl_free( pos_rowclean ) ;
+            return -7 ;
+        }    
+    }
+
+ 
+    if ( agreed == -1 )
+    {
+        sinfo_msg_error(" no emission line found in the first image columns") ;
+        cpl_free( sinfo_edge ) ;
+        cpl_free( pos_row ) ;
+        cpl_free( edgeclean ) ;
+        cpl_free( dummyedge ) ;
+        cpl_free( pos_rowclean ) ;
+        return -7 ;
+    }    
+ 
+    /* now find and store the raw sinfo_edge positions of the found slitlet */ 
+    n  = 0 ;
+    ed = 0 ;
+    position=cpl_calloc(ilx,sizeof(float)) ;
+
+    for ( col = 0 ; col < ilx ; col++ )
+    {
+        for ( i = 0 ; i < par[0]->n_params ; i++ )
+        {
+            if ( par[i]->column == col && par[i]->line == line )
+            {
+                if ( par[i]->fit_par[0] > 0. && 
+                     par[i]->fit_par[1] >= 1.  && 
+                     par[i]->fit_par[2] > 0. )
+                {
+                    position[n] = par[i]->fit_par[2] ;
+                    if ( n > 0 && fabs(position[n] - position[n-1]) > y_box )
+                    {
+                        sinfo_edge[ed] = col ; 
+                        pos_row[ed] = sinfo_new_nint( position[n-1] ) ;
+                        ed++ ;
+                        if ( col >= ilx - slit_length - 5 ) 
+                        {
+                            pos_row[ed] =  sinfo_new_nint( position[n] ) ;
+                        }
+                    }
+                    n++ ;
+                }
+            }
+        }
+    }
+    if ( ed < (slit_length - 1) )
+    {
+        sinfo_msg_error(" not enough slitlets found") ;
+        cpl_free( sinfo_edge ) ;
+        cpl_free( pos_row ) ;
+        cpl_free( edgeclean ) ;
+        cpl_free( dummyedge ) ;
+        cpl_free( pos_rowclean ) ;
+        return -8 ;
+    } 
+
+    /* now find the clean sinfo_edge and row positions of the slitlets */
+    for ( i = 1 ; i <= ed ; i ++ )
+    {
+        if ( i == ed )
+        {
+            if ( (sinfo_edge[i-1] - sinfo_edge[i-2]) < slit_length - 3 ||
+                 (sinfo_edge[i-1] - sinfo_edge[i-2]) > slit_length + 3 )
+            {
+                dummyedge[i-1]   = -1 ;
+            }
+            
+        }
+        if (dummyedge[i-1] != -1)
+        {
+            dummyedge[i-1] = sinfo_edge[i-1] ;
+        }
+        else
+        {
+            continue ;
+        }
+        if ( i < ed )
+        {
+            if ( (sinfo_edge[i] - sinfo_edge[i-1]) < slit_length - 3 ||
+                 (sinfo_edge[i] - sinfo_edge[i-1]) > slit_length + 3 )
+            {
+                dummyedge[i]   = -1 ;
+            }
+        }
+        if ( i + 1 < ed && dummyedge[i] != -1 )
+        {
+            if ( (sinfo_edge[i+1] - sinfo_edge[i]) < slit_length - 3 ||
+                 (sinfo_edge[i+1] - sinfo_edge[i]) > slit_length + 3 )
+            {
+                dummyedge[i+1] = -1 ; 
+            }
+        }
+    }
+    
+    k = 0 ;
+    for ( i = 0 ; i < ed ; i++ )
+    {
+        if ( dummyedge[i] != -1 && dummyedge[i] != 0 )
+        {
+            edgeclean[k] = dummyedge[i] ;
+            pos_rowclean[k] = pos_row[i] ;
+            k++ ;
+            if( edgeclean[k-1] > (ilx - slit_length - 6 ) )
+            {
+                pos_rowclean[k] = pos_row[ed] ;
+            }
+        }
+    }
+
+    if ( k != slit_length - 1 )
+    {
+        sinfo_msg_error(" not enough clean slitlets found") ;
+        cpl_free( sinfo_edge ) ;
+        cpl_free( pos_row ) ;
+        cpl_free( edgeclean ) ;
+        cpl_free( dummyedge ) ;
+        cpl_free( pos_rowclean ) ;
+        return -8 ;
+    } 
+
+    /* determine the margins of the fitting box outside the slitlets */
+    margin = box_length / 2 ;
+
+    /* ------------------------------------------------------------------------
+     * now go through the slitlets, search along each column within a box with 
+     * half width y_box the maximum value and store these found values in a 
+     * buffer
+     */
+    for ( j = 0 ; j <= k ; j++ )
+    {
+        m = 0 ;
+        if ( j == 0 )
+        {
+            box_buffer = sinfo_new_vector( edgeclean[0] + margin ) ;
+            for( col = 0 ; col < edgeclean[0] + margin ; col++ )
+            {
+                maxval = -FLT_MAX ;
+                for ( row = pos_rowclean[0] - sinfo_new_nint(y_box) ; 
+                      row <= pos_rowclean[0] + sinfo_new_nint(y_box) ; row++ )
+                {
+                    if ( maxval < pidata[col + ilx*row] )
+                    {
+                        maxval = pidata[col + ilx*row] ;
+                    }
+                }
+                box_buffer->data[m] = maxval ;
+                m++ ;
+            }
+        }
+        else if ( j < k )
+        {
+            box_buffer = sinfo_new_vector( edgeclean[j] - 
+                                           edgeclean[j-1] + 2*margin ) ;
+            for ( col = edgeclean[j - 1] - margin ; 
+                  col < edgeclean[j] + margin ; col++ )
+            {
+                maxval = -FLT_MAX ;
+                for ( row = pos_rowclean[j] - sinfo_new_nint(y_box) ; 
+                      row <= pos_rowclean[j] + sinfo_new_nint(y_box) ; row++ )
+                {
+                    if ( maxval < pidata[col + ilx*row] )
+                    {
+                        maxval = pidata[col + ilx*row] ;
+                    }
+                }
+                box_buffer->data[m] = maxval ;
+                m++ ;
+            }
+        }
+        else 
+        {
+            box_buffer = sinfo_new_vector( ilx - edgeclean[k-1] + margin ) ;
+            for ( col = edgeclean[k - 1] - margin ; col < ilx ; col++ )
+            {
+                maxval = -FLT_MAX ;
+                for ( row = pos_rowclean[k] - sinfo_new_nint(y_box) ; 
+                      row <= pos_rowclean[k] + sinfo_new_nint(y_box) ; row++ )
+                {
+                    if ( maxval < pidata[col + ilx*row] )
+                    {
+                        maxval = pidata[col + ilx*row] ;
+                    }
+                }
+                box_buffer->data[m] = maxval ;
+                m++ ;
+            }
+        }
+
+        for ( left_right = 0 ; left_right <= 1 ; left_right++ )
+        { 
+            nel = 0 ;
+            if ( left_right == 0 )
+            {
+                nel = box_buffer -> n_elements / 2 ;
+            }
+            else
+            {
+                if ( box_buffer -> n_elements % 2 == 0 )
+                {
+                    nel = box_buffer -> n_elements / 2 ;
+                }
+                else
+                {
+                    nel = box_buffer -> n_elements / 2 + 1 ;
+                }
+            }
+
+            /* now split the buffer in the midth in a left and right 
+               part for fitting */
+            half_buffer = sinfo_new_vector( nel ) ;
+            if ( left_right == 0 )
+            {
+                for ( i = 0 ; i < nel ; i++ )
+                {
+                    half_buffer -> data[i] = box_buffer -> data[i] ;
+                }
+            }
+            else
+            {
+                n_right = 0 ;
+                for ( i = box_buffer -> n_elements - 1 ; 
+                      i >= box_buffer -> n_elements - nel ; i-- )
+                {
+                    half_buffer -> data[n_right] = box_buffer -> data[i] ;
+                    n_right++ ;
+                }
+            }
+
+            xdat = (float *) cpl_calloc( nel, sizeof (float) ) ;
+            wdat = (float *) cpl_calloc( nel, sizeof (float) ) ;
+            mpar = (int *)   cpl_calloc( NPAR, sizeof (int) ) ;
+
+            /* set initial values for the fitting routine */
+            minval =  FLT_MAX ;
+            maxval = -FLT_MAX ;
+            for ( i = 0 ; i < nel ; i++ )
+            {
+                xdat[i] = i ;
+                wdat[i] = 1.0 ;
+                if ( half_buffer -> data[i] < minval )
+                {
+                    minval = half_buffer -> data[i] ;
+                }
+                if ( half_buffer -> data[i] > maxval )
+                {
+                    maxval = half_buffer -> data[i] ;
+                }
+            }
+
+            fitpar[2] = minval ;
+            fitpar[3] = maxval ; 
+
+            /* search for both positions of the half intensity of 
+               the hat within the buffer */
+            init1 = -1 ; 
+            for ( i = 0 ; i < nel ; i++ )
+            {
+                if ( half_buffer -> data[i] >= ( maxval + minval ) / 2. )
+                {
+                    init1 = i ;
+                    break ;
+                }
+            }
+
+            /* determine the initial positions from the found values */
+            if ( init1 != -1 )
+            {
+                fitpar[0] = ((float)init1 - 1.) ;
+                fitpar[1] = ((float)init1 + 1.) ;
+            }
+
+            for ( i = 0 ; i < NPAR ; i++ )
+            {
+                mpar[i] = 1 ;
+                dervpar[i] = 0. ;
+            }
+      
+            xdim     = XDIMA ;
+            ndat     = nel ;
+            numpar   = NPAR ;
+            tol      = TOLA ;
+            lab      = LABA ;
+            its      = ITSA ;
+         
+            /* finally, do the least squares fit over the buffer data */
+            if ( 0 > ( iters = sinfo_new_lsqfit_edge( xdat, &xdim, 
+                                                      half_buffer -> data, 
+                                                      wdat, &ndat, fitpar,
+                                                      dervpar, mpar, &numpar, 
+                                                      &tol, &its, &lab )) )
+            { 
+                /* if the fit doesn't succeed the initial values are taken */
+                sinfo_msg_warning ("least squares fit failed, error "
+                                   "no.: %d in slitlet: %d", iters, j) ;
+                fitpar[0] = ((float)init1 - 1.) ;
+                fitpar[1] = ((float)init1 + 1.) ;
+            }
+
+            pos = (fitpar[0] + fitpar[1]) / 2. ;
+
+            /*----------------------------------------------------------------- 
+             * now discern the left and the right sinfo_edge fit of the 
+             * slitlets and associate the fit results with the absolute 
+             * positions in the image consider the difference of the fitted 
+             * slit position to the expected position and decide wether the 
+             * fit is taken or the expected value is taken.
+             */
+            if ( left_right == 0 )
+            {
+                /* take care of the column position of the fit boxes to get 
+                   the absolute positions */
+                if ( j == 0 )
+                {
+                    if ( fabs(pos - ((float)edgeclean[0] - 1. - 
+                         (float)slit_length)) < diff_tol )
+                    {
+                        sinfo_slit_pos[0][0] = pos ;
+                    }
+                    else
+                    {
+                        sinfo_msg_warning("something wrong with fitted "
+                                          "left position of slitlet 0") ;
+                        if ((float) edgeclean[0] - 1. - 
+                            (float)slit_length < 0. )
+                        {
+                            sinfo_slit_pos[0][0] = 0. ;
+                        }
+                        else
+                        {
+                            sinfo_slit_pos[0][0] = (float)edgeclean[0] - 1. - 
+                                                   (float)slit_length ;
+                        }
+                    }
+                }
+                else if ( j < k )
+                {
+                    if ( fabs( pos - (float)margin ) < diff_tol )
+                    {
+                        sinfo_slit_pos[j][0] = pos + (float)edgeclean[j-1] - 
+                                                     (float)margin ;
+                    }
+                    else
+                    {
+                        sinfo_msg_warning("something wrong with fitted "
+                                          "left position of slitlet %d", j) ;
+                        sinfo_slit_pos[j][0] = (float)edgeclean[j-1] - 1. ;
+                    }
+                }
+                else
+                {
+                    if ( fabs( pos - (float)margin ) < diff_tol )
+                    {
+                        sinfo_slit_pos[k][0] = pos + (float)edgeclean[k-1] - 
+                                                     (float)margin ;
+                    }
+                    else
+                    {
+                        sinfo_msg_warning("something wrong with fitted left "
+                                          "position of slitlet %d", j) ;
+                        sinfo_slit_pos[k][0] = (float)edgeclean[k-1] - 1. ;
+                    }
+                }
+            }
+            else
+            {
+                /* take care of the column position of the fit boxes to 
+                   get the absolute positions */
+                if ( j == 0 )
+                {
+                    if ( fabs( (float)box_buffer->n_elements - pos - 
+                               (float)edgeclean[0] ) < diff_tol )
+                    {
+                       sinfo_slit_pos[0][1] = (float)(box_buffer->n_elements - 
+                                               1) - pos ;
+                    }
+                    else
+                    {
+                        sinfo_msg_warning("something wrong with fitted "
+                                          "right position of slitlet 0") ;
+                        sinfo_slit_pos[0][1] = (float)edgeclean[0] - 1. ;
+                    }
+                }
+                else if ( j < k )
+                {
+                    if ( fabs( (float)box_buffer->n_elements - pos
+                             + (float)edgeclean[j-1] - (float)margin - 
+                               (float)edgeclean[j] ) < diff_tol )
+                    {
+                        sinfo_slit_pos[j][1] = (float)(box_buffer->n_elements -
+                                               1) - pos
+                                       + (float)edgeclean[j-1] - (float)margin;
+                    }
+                    else
+                    {
+                        sinfo_msg_warning("something wrong with fitted "
+                                          "right position of slitlet %d", j) ;
+                        sinfo_slit_pos[j][1] = (float)edgeclean[j] - 1. ;
+                    }
+                }
+                else
+                {
+                    if ( edgeclean[k-1] + slit_length > ilx )
+                    {
+                        last_pos = (float)(ilx - 1) ;
+                    }
+                    else
+                    {
+                        last_pos = (float)(edgeclean[k-1] - 1 + slit_length) ;
+                    }
+                    if ( fabs( (float)(box_buffer->n_elements - 1) - pos
+                             + (float)edgeclean[k-1] - (float)margin - 
+                               last_pos ) < diff_tol )
+                    {
+                        sinfo_slit_pos[k][1] = (float)(box_buffer->n_elements -
+                                               1) - pos
+                                       + (float)edgeclean[k-1] - (float)margin ;
+                    }
+                    else
+                    {
+                        sinfo_msg_warning("something wrong with fitted "
+                                          "right position of slitlet %d", j) ;
+                        sinfo_slit_pos[k][1] = last_pos ;
+                    }
+                }
+            }
+
+            sinfo_new_destroy_vector ( half_buffer ) ;
+            cpl_free( xdat ) ;
+            cpl_free( wdat ) ;
+            cpl_free( mpar ) ;
+        }
+        sinfo_new_destroy_vector ( box_buffer ) ;
+    }
+        
+    cpl_free( sinfo_edge ) ;
+    cpl_free( pos_row ) ;
+    cpl_free( edgeclean ) ;
+    cpl_free( dummyedge ) ;
+    cpl_free( pos_rowclean ) ;
+    cpl_free( position );
+    return 0 ;
+}
+
+/**
+   @name  sinfo_new_fit_slits_boltz_with_estimate()
+   @param lineImage  emission line frame
+   @param sinfo_slit_pos  estimation array for the slitlet positions [min32][2]
+   @param box_length  pixel length of the row box within the fit is done
+   @param y_box       small box in spectral direction within the slitlet
+                      may lie.
+   @param low_pos
+   @param high_pos    pixel positions in spectral direction between which the 
+                      line should be located.
+   @return sinfo_slit_pos  beginning and end position of the slitlets to
+                           sub-pixel accuracy 0  if it worked, -1  if it 
+                           failed,
+   @doc  fits the beginning and end position of the slitlets by using 
+         non-linear least square fitting of a Boltzmann function fits a 
+         Boltzmann function to the slitlet edges exposed and indicated by the 
+         brightest emission lines. The slitlet is searched within user given 
+         positions. The least squares fit is done by using a box smaller than
+         the size of two slitlets 
+ */
+
+
+int 
+sinfo_new_fit_slits_edge_with_estimate ( cpl_image   * lineImage,
+                               float     ** sinfo_slit_pos,
+                               int          box_length,
+                               float        y_box,
+                               float        diff_tol,
+                               int          low_pos,
+                               int          high_pos )
+{
+    int*   position=NULL ;
+    Vector * box_buffer ;
+    Vector * in_buffer ;
+    int   found_row ;
+    int   row, col ;
+    int   col_first, col_last ;
+    int   row_first, row_last ;
+    int   i, j, m, n ;
+    int   init1 ;
+    int   left_right ;
+    int   n_buf, shift ;
+    int   slit_length ;
+    int   iters, xdim, ndat ;
+    int   numpar, its ;
+    int   * mpar ;
+    float * xdat, * wdat ;
+    float tol, lab ;
+    float fitpar[NPAR] ;
+    float dervpar[NPAR] ;
+    float minval, maxval ;
+    float pos ;
+    float new_pos ;
+    int   slitposition[SLITLENGTH] ;
+    pixelvalue rowpos[SLITLENGTH] ;
+    int ilx=0;
+    int ily=0;
+    float* pidata=NULL;
+
+    slit_length = SLITLENGTH ; /* this is too high: 64 */
+    slit_length = N_SLITLETS ; /* this is better: 32 */
+
+
+    if ( NULL == lineImage )
+    {
+        sinfo_msg_error(" no line image given!" ) ;
+        return -1 ;
+    }
+    ilx=cpl_image_get_size_x(lineImage);
+    ily=cpl_image_get_size_y(lineImage);
+    pidata=cpl_image_get_data_float(lineImage);
+
+    if ( NULL == sinfo_slit_pos )
+    {
+        sinfo_msg_error(" no position array allocated!" ) ;
+        return -1 ;
+    }
+
+    if ( box_length < 4 ||
+         box_length > 2*slit_length )
+    {
+        sinfo_msg_error(" wrong fitting box length given!" ) ;
+        sinfo_msg_error(" Must be 4 <= box_length < %d ",2*slit_length ) ;
+        sinfo_msg_error(" You have chosen box_length = %d",box_length);
+
+
+        return -1 ;
+    }
+
+    if ( y_box <= 0. || y_box > 6. )
+    {
+        sinfo_msg_error("wrong y box length given!" ) ;
+        sinfo_msg_error("You have chosen y_box=%f not in range (0,6]!",y_box);
+        return -1 ;
+    }
+    if ( diff_tol <= 0. )
+    {
+        sinfo_msg_error(" wrong diff_tol given!" ) ;
+        return -1 ;
+    }
+
+        if ( low_pos >= high_pos || low_pos < 0 || 
+             high_pos <= 0 || high_pos > ily )
+    {
+        sinfo_msg_error(" wrong user given search positions!" ) ;
+        return -1 ;
+    }
+
+    /* now search for the maximum between the given positions for each col */
+    position=cpl_calloc(ilx,sizeof(int)) ;
+
+    for ( col = 0 ; col < ilx ; col++ )
+    {
+        found_row = -1 ;
+        maxval = -FLT_MAX ;
+        for ( row = low_pos ; row <= high_pos ; row++ )
+        {
+            if ( maxval < pidata[col+row*ilx] )
+            {
+                maxval = pidata[col+row*ilx] ;
+                found_row = row ;
+            }
+        }
+        if ( maxval > -FLT_MAX && found_row > low_pos )
+        {
+            position[col] = found_row ;
+        }
+        else
+        {
+            position[col] = 0 ;
+        }
+    }
+
+    /* ------------------------------------------------------------------------
+     * now go through the slitlets, search along each column within a box with
+     * half width y_box the maximum value and store these found values in a 
+     * buffer
+     */
+    for ( j = 0 ; j < slit_length ; j++ )
+    {
+        /* now go through the columns and determine the slitlet positions by
+         * calculating the sinfo_median of the found positions
+         */
+        n = 0 ;
+        for ( col = sinfo_new_nint(sinfo_slit_pos[j][0])+ 1 ; 
+              col < sinfo_new_nint(sinfo_slit_pos[j][1]) -1 ; col++ )
+        {
+            rowpos[n] = (pixelvalue)position[col] ;
+            n++ ;
+        }
+        slitposition[j] = (int)sinfo_new_median(rowpos, n) ;
+        for ( left_right = 0 ; left_right <= 1 ; left_right++ )
+
+        {
+            init1 = 0 ;
+            col_first = sinfo_new_nint( sinfo_slit_pos[j][left_right] ) - 
+                                        box_length/2 ;
+            col_last  = sinfo_new_nint( sinfo_slit_pos[j][left_right] ) + 
+                        box_length/2 ;
+            if ( col_first < 0 )
+            {
+                col_first = 0 ;
+                init1 = 1 ;
+            }
+            if ( col_last > ilx )
+            {
+                col_last = ilx ;
+                init1 = 1 ;
+            }
+            if ( col_last - col_first <= 0 )
+            {
+                sinfo_msg_error(" first and last column wrong!" ) ;
+                return -1 ;
+            }
+            box_buffer = sinfo_new_vector( col_last - col_first ) ;
+            m = 0 ;
+            if ( left_right == 0 )
+            {
+                for( col = col_first ; col < col_last ; col++ )
+                {
+                    row_first = slitposition[j] - sinfo_new_nint(y_box) ;
+                    row_last  = slitposition[j] + sinfo_new_nint(y_box) ;
+                    if ( row_first < 0 )
+                    {
+                        row_first = 0 ;
+                    }
+                    if ( row_last >= ily  )
+                    {
+                        row_last = ily - 1 ;
+                    }
+                    maxval = -FLT_MAX ;
+                    for ( row = row_first ; row <= row_last ; row++ )
+                    {
+                        if ( maxval < pidata[col + ilx*row] )
+                        {
+                            maxval = pidata[col + ilx*row] ;
+                        }
+                    }
+                    box_buffer->data[m] = maxval ;
+                    m++ ;
+                }
+            }
+            else
+            {
+                for( col = col_last-1 ; col >= col_first ; col-- )
+                {
+                    row_first = slitposition[j] - sinfo_new_nint(y_box) ;
+                    row_last  = slitposition[j] + sinfo_new_nint(y_box) ;
+                    if ( row_first < 0 )
+                    {
+                        row_first = 0 ;
+                    }
+                    if ( row_last >= ily  )
+                    {
+                        row_last = ily - 1 ;
+                    }
+                    maxval = -FLT_MAX ;
+                    for ( row = row_first ; row <= row_last ; row++ )
+                    {
+                        if ( maxval < pidata[col + ilx*row] )
+                        {
+                            maxval = pidata[col + ilx*row] ;
+                        }
+                    }
+                    box_buffer->data[m] = maxval ;
+                    m++ ;
+                }
+            }
+
+            xdat=(float *)cpl_calloc( box_buffer->n_elements, sizeof (float));
+            wdat=(float *)cpl_calloc( box_buffer->n_elements, sizeof (float));
+            mpar=(int *)  cpl_calloc( NPAR, sizeof (int) ) ;
+
+            /* set initial values for the fitting routine */
+            minval =  FLT_MAX ;
+            maxval = -FLT_MAX ;
+            for ( i = 0 ; i < box_buffer->n_elements ; i++ )
+            {
+                xdat[i] = i ;
+                wdat[i] = 1.0 ;
+                if ( box_buffer -> data[i] < minval )
+                {
+                    minval = box_buffer -> data[i] ;
+                }
+                if ( box_buffer -> data[i] > maxval )
+                {
+                    maxval = box_buffer -> data[i] ;
+                }
+            }
+            fitpar[2] = minval ;
+            fitpar[3] = maxval ;
+            /*----------------------------------------------------------------
+             * if we have too few left background values (at the image edges)
+             * the left margin of the buffer to fit is filled with the minimal
+             * values in order to get a good fit
+             */
+
+            if ( init1 == 1 )
+            {
+                n_buf = box_buffer->n_elements + box_length/2 ;
+                in_buffer = sinfo_new_vector( n_buf ) ;
+                for ( i = 0 ; i < box_length/2 ; i++ )
+                {
+                    in_buffer -> data[i] = minval ;
+                }
+                shift = 0 ;
+                for ( i = box_length/2 ; i < n_buf ; i++ )
+                {
+                    in_buffer -> data[i] = box_buffer -> data[shift] ;
+                    shift++ ;
+                }
+                sinfo_new_destroy_vector ( box_buffer ) ;
+                box_buffer = sinfo_new_vector ( n_buf ) ;
+                for ( i = 0 ; i < n_buf ; i++ )
+                {
+                    box_buffer -> data[i] = in_buffer -> data[i] ;
+                }
+                sinfo_new_destroy_vector ( in_buffer ) ;
+            }
+            /* determine the initial positions from the found values */
+            fitpar[0] = (float)box_buffer->n_elements/2. - 1. ;
+            fitpar[1] = (float)box_buffer->n_elements/2. + 1. ;
+
+            for ( i = 0 ; i < NPAR ; i++ )
+            {
+                mpar[i] = 1 ;
+                dervpar[i] = 0. ;
+            }
+
+            xdim     = XDIMA ;
+            ndat     = box_buffer->n_elements ;
+            numpar   = NPAR ;
+            tol      = TOLA ;
+            lab      = LABA ;
+            its      = ITSA ;
+
+            /* finally, do the least squares fit over the buffer data */
+            if ( 0 > ( iters = sinfo_new_lsqfit_edge( xdat, &xdim, 
+                                                      box_buffer -> data, 
+                                                      wdat, &ndat, fitpar,
+                                                      dervpar, mpar, &numpar, 
+                                                      &tol, &its, &lab )) )
+            {
+                sinfo_msg_warning (" least squares fit failed, error "
+                                   "no.: %d in slitlet: %d\n", iters, j) ;
+                sinfo_new_destroy_vector(box_buffer) ;
+                cpl_free( xdat ) ;
+                cpl_free( wdat ) ;
+                cpl_free( mpar ) ;
+                continue ;
+            }
+            if ( fitpar[1] <= fitpar[0] )
+            {
+                sinfo_msg_warning ("fit failed due to negative slope of "
+                                   "sinfo_new_edge function in slitlet: %d",j);
+                sinfo_new_destroy_vector(box_buffer) ;
+                cpl_free( xdat ) ;
+                cpl_free( wdat ) ;
+                cpl_free( mpar ) ;
+                continue ;
+            }
+
+            pos = (fitpar[0] + fitpar[1])/2. ;
+            if ( init1 == 1 )
+            {
+                pos -= (float)box_length/2. ;
+            }
+
+            /*-------------------------------------------------------------
+             * now compute the real slit positions using the guess positions
+             * if the fit did not work the guess positions are taken
+             * the same is done if the deviations are too big.
+             */
+            if ( pos != 0. )
+            {
+                if ( left_right == 0 )
+                {
+                    new_pos = (float)col_first + pos ;
+                }
+                else
+                {
+                    new_pos = (float)col_last-1 - pos ;
+                }
+                if ( fabs(new_pos - sinfo_slit_pos[j][left_right]) < diff_tol )
+                {
+                    sinfo_slit_pos[j][left_right] = new_pos ;
+                }
+                else
+                {
+                    sinfo_msg_warning (" deviation bigger than tolerance,"
+                                       " take the estimated slitlet positiona"
+                                       " in slitlet: %d\n", j) ;
+                }
+            }
+
+            cpl_free( xdat ) ;
+            cpl_free( wdat ) ;
+            cpl_free( mpar ) ;
+            sinfo_new_destroy_vector ( box_buffer ) ;
+        }
+    }
+    cpl_free(position);
+    return 0 ;
+}
+
+
+/**@}*/
diff --git a/sinfoni/sinfo_absolute.h b/sinfoni/sinfo_absolute.h
new file mode 100644
index 0000000..888bafe
--- /dev/null
+++ b/sinfoni/sinfo_absolute.h
@@ -0,0 +1,432 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*****************************************************************************
+* E.S.O. - VLT project
+*
+* "@(#) $Id: sinfo_absolute.h,v 1.3 2007/08/20 10:01:05 amodigli Exp $"
+*
+* who       when      what
+* --------  --------  ----------------------------------------------
+* schreib  14/11/00  created
+*/
+#ifndef SINFO_ABSOLUTE_H
+#define SINFO_ABSOLUTE_H
+/**
+ * @addtogroup sinfo_absolute
+ *
+ */
+/*----------------------------------------------------------------------------*/
+
+
+/************************************************************************
+ * absolute.h
+ * routines to determine the absolute positions of the slitlets out of 
+ * an emission line frame
+ *----------------------------------------------------------------------
+ */
+
+/*
+ * header files
+ */
+
+#include <cpl.h>
+#include "sinfo_spectrum_ops.h"
+#include "sinfo_msg.h"
+#include "sinfo_recipes.h"
+/*----------------------------------------------------------------------------
+ *                        Function ANSI C prototypes
+ *--------------------------------------------------------------------------*/
+
+/**
+   @name sinfo_new_edge()
+   input: position array xdat, parameter list parlist, number of
+                        parameters in the list npar
+   @param ndat number of data elements
+   The parameters are:
+   @param  parlist(0) pos1
+   @param  parlist(1) pos2
+   @param  parlist(2) intensity left
+   @param  parlist(3) intensity right
+   @return function value of a linear slope function that means a function 
+           with a constant intensity value for xdat values smaller than 
+           pos1, linear increasing between pos1 and pos2, constant intensity 
+           value for xdat values greater than pos2
+   @memo  calculates the value of a slope function with parameters
+          parlist at the position xdat
+ */
+
+float 
+sinfo_new_edge(float * xdat, float * parlist/*, int * npar, int * ndat */) ;
+
+/**
+   @name  sinfo_new_boltz()
+   In: position array xdat, parameter list parlist. The parameters are:
+   @param parlist(0) background1
+   @param parlist(1) background2
+   @param parlist(2) central position
+   @param parlist(3) width
+   @return function value of a Boltzmann function that is
+   y = (parlist(0)-parlist(1))/(1+exp((x-parlist(2))/parlist(3))) + parlist(1)
+   @memo calculates the value of a Boltzmann function with parameters parlist 
+         at the position xdat
+*/
+
+float 
+sinfo_new_boltz ( float * xdat, float * parlist ) ;
+
+/**
+   @name sinfo_new_edge_deriv()
+   In : position array xdat, parameter list parlist, number of parameters in 
+        the list npar. The parameters are:
+   @param parlist(0) pos1
+   @param parlist(1) pos2
+   @param parlist(2) intensity left
+   @param parlist(3) intensity right
+   derivative value of a hat function at position xdat: dervs
+   @param dervs[0] partial derivative by pos1
+   @param dervs[1] partial derivative by pos2
+   @param dervs[2] partial derivative by intensity left
+   @param dervs[3] partial derivative by intensity right
+   @return void
+   @memo calculates the partial derivatives for a slope function with
+         parameters parlist at position xdat
+*/
+
+void 
+sinfo_new_edge_deriv(float * xdat, 
+                     float * parlist, float * dervs/*, int * npar */) ;
+
+/**
+   @name sinfo_new_boltz_deriv()
+   In : position array xdat, parameter list parlist. The parameters are:
+   @param parlist(0) background1
+   @param parlist(1) background2
+   @param parlist(2) central position
+   @param parlist(3) width
+   derivative value of a Boltzmann function at position xdat: dervs
+   @param dervs[0] partial derivative by background1
+   @param dervs[1] partial derivative by background2
+   @param dervs[2] partial derivative by central position
+   @param dervs[3] partial derivative by the width
+   @return void
+   @memo calculates the partial derivatives for a Boltzmann function with
+         parameters parlist at position xdat
+*/
+
+void 
+sinfo_new_boltz_deriv( float * xdat, float * parlist, float * dervs ) ;
+
+/**
+   @name sinfo_new_lsqfit()
+   @param xdat  position, coordinates of data points.
+   @param xdat is 2 dimensional: XDAT ( XDIM, NDAT )
+   @param xdim  dimension of fit
+   @param ydat  data points
+   @param wdat  weights for data points
+   @param ndat  number of data points
+   @param fpar  on input contains initial estimates of the
+                parameters for non-linear fits, on output the
+                fitted parameters.
+   @param epar  contains estimates of the errors in fitted parameters
+   @param mpar  logical mask telling which parameters are free (non-zero)
+                and which parameters are fixed (0)
+   @param npar  number of function parameters ( free + fixed )
+   @param tol   relative tolerance. lsqfit stops when successive iterations
+                fail to produce a decrement in reduced chi-squared less
+                than tol. If tol is less than the minimum tolerance
+                possible, tol will be set to this value. This means
+                that maximum accuracy can be obtained by setting
+                tol = 0.0.
+   @param its   maximum number of iterations
+   @param lab   mixing parameter, lab determines the initial weight
+                of steepest descent method relative to the Taylor method
+                lab should be a small value (i.e. 0.01). lab can only
+                be zero when the partial derivatives are independent
+                of the parameters. In fact in this case lab should be
+                exactly equal to zero.
+   @return number of iterations needed to achieve convergence
+           according to tol. When this number is negative, the fitting
+           was not continued because a fatal error occurred:
+           #             -1 too many free parameters, maximum is 32
+           #             -2 no free parameters
+           #             -3 not enough degrees of freedom
+           #             -4 maximum number of iterations too small to obtain
+                           a solution which satisfies tol.
+           #             -5 diagonal of sinfo_matrix contains elements 
+                            which are zero
+           #             -6 determinant of the coefficient sinfo_matrix is zero
+           #             -7 square root of a negative number
+   @doc this is a routine for making a least-squares fit of a
+        function to a set of data points. The method used is
+        described in: Marquardt, J.Soc.Ind.Appl.Math. 11. 431 (1963).
+        This method is a mixture of the steepest descent method
+        and the Taylor method.
+ */
+
+int sinfo_new_lsqfit ( float * xdat,
+             int   * xdim,
+             float * ydat,
+             float * wdat,
+             int   * ndat,
+             float * fpar,
+             float * epar,
+             int   * mpar,
+             int   * npar,
+             float * tol ,
+             int   * its ,
+             float * lab  ) ;
+
+/**
+   @name    sinfo_new_lsqfit_edge()
+   @param   xdat  position, coordinates of data points.
+                              xdat is 2 dimensional: XDAT ( XDIM, NDAT )
+   @param   xdim  dimension of fit
+   @param   ydat  data points
+   @param   wdat  weights for data points
+   @param   ndat  number of data points
+   @param   fpar  on input contains initial estimates of the parameters for 
+                  non-linear fits, on output the fitted parameters.
+   @param   epar  contains estimates of the errors in fitted parameters
+   @param   mpar  logical mask telling which parameters are free (non-zero)
+                              and which parameters are fixed (0)
+   @param   npar  number of function parameters ( free + fixed )
+   @param   tol   relative tolerance. sinfo_lsqfit stops when successive 
+                  iterations fail to produce a decrement in reduced chi-squared
+                  less than tol. If tol is less than the minimum tolerance
+                  possible, tol will be set to this value. This means that 
+                  maximum accuracy can be obtained by setting tol = 0.0.
+   @param   its   maximum number of iterations
+   @param   lab   mixing parameter, lab determines the initial weight
+                  of steepest descent method relative to the Taylor method
+                  lab should be a small value (i.e. 0.01). lab can only
+                  be zero when the partial derivatives are independent
+                  of the parameters. In fact in this case lab should be
+                  exactly equal to zero.
+   @return number of iterations needed to achieve convergence according to tol.
+                  When this number is negative, the fitting
+                  was not continued because a fatal error occurred:
+                  #      -1 too many free parameters, maximum is 32
+                  #      -2 no free parameters
+                  #      -3 not enough degrees of freedom
+                  #      -4 maximum number of iterations too small to obtain
+                           a solution which satisfies tol.
+                  #      -5 diagonal of sinfo_matrix contains elements 
+                            which are zero
+                  #      -6 determinant of the coefficient sinfo_matrix is zero
+                  #      -7 square root of a negative number
+   @doc this is a routine for making a least-squares fit of a function to a 
+        set of data points. The method used is described in: 
+        Marquardt, J.Soc.Ind.Appl.Math. 11. 431 (1963).
+        This method is a mixture of the steepest descent method
+        and the Taylor method.
+ */
+
+int 
+sinfo_new_lsqfit_edge ( float * xdat,
+                  int   * xdim,
+                  float * ydat,
+                  float * wdat,
+                  int   * ndat,
+                  float * fpar,
+                  float * epar,
+                  int   * mpar,
+                  int   * npar,
+                  float * tol ,
+                  int   * its ,
+                  float * lab  ) ;
+
+/**
+   @name  sinfo_new_fit_slits_edge()
+   @param lineImage  emission line frame
+   @param par        fit parameter data structure of fitted lines
+   @param sinfo_slit_pos   allocated dummy array for the slitlet 
+                           positions [32][4]
+   @param box_length pixel length of the row box within the fit is done
+   @param y_box      small box in spectral direction within the slitlet may 
+                      lie.
+   @param diff_tol   maximum tolerable difference of the resulting fit position
+                     with respect to the expected position. If difference is
+                     greater the expected position is taken.
+   @return sinfo_slit_pos  beginning and end position of the slitlets to
+                            sub-pixel accuracy
+                     #    0  if it worked,
+                     #   -1  if there was no line image given,
+                     #   -2  if there were no line fit parameters given,
+                     #   -3  if there was no dummy array for the slit positions
+                            allocated
+                     #   -4  if the given box length is impossible
+                     #   -5  if the given y box length is impossible
+                     #   -6  if the given difference tolerance is too small
+                     #   -7  if there were no emission lines found in the first
+                             image columns
+                     #   -8  if not all slitlets could be found
+   @doc fits the beginning and end position of the slitlets by using non-linear
+        least square fitting of a hat function fits a step function to the 
+        slitlet edges exposed and indicated by the brightest emission lines. 
+        To achieve this, the fit parameters are used to find the brightest 
+        emission line and to get its position for each column.
+        The least squares fit is done by using a box smaller than the size of 
+        two slitlets 
+ */
+
+int 
+sinfo_new_fit_slits_edge( cpl_image   * lineImage,
+                  FitParams ** par,
+                  float     ** sinfo_slit_pos,
+                  int          box_length,
+                  float        y_box,
+                  float        diff_tol ) ;
+
+/**
+   @name sinfo_new_fit_slits_boltz()
+   @param lineImage  emission line frame
+   @param par        fit parameter data structure of fitted lines
+   @param sinfo_slit_pos   allocated dummy array for the slitlet 
+                           positions [32][2]
+   @param box_length pixel length of the row box within the fit is done
+   @param y_box      small box in spectral direction within the slitlet may lie.
+   @param diff_tol   maximum tolerable difference of the resulting fit position
+                     with respect to the expected position. If difference is
+                     greater the expected position is taken.
+   @return  sinfo_slit_pos  beginning and end position of the slitlets to
+                             sub-pixel accuracy
+                     #    0  if it worked,
+                     #   -1  if there was no line image given,
+                     #   -2  if there were no line fit parameters given,
+                     #   -3  if there was no dummy array for the slit positions
+                            allocated
+                     #   -4  if the given box length is impossible
+                     #   -5  if the given y box length is impossible
+                     #   -6  if the given difference tolerance is too small
+                     #   -7  if there were no emission lines found in the 
+                             first image columns
+                     #   -8  if not all slitlets could be found
+   @doc  fits the beginning and end position of the slitlets by using 
+         non-linear least square fitting of a Boltzmann function fits a 
+         Boltzmann function to the slitlet edges exposed and indicated
+         by the brightest emission lines. To achieve this, the fit
+         parameters are used to find the brightest emission line
+         and to get its position for each column. The least squares fit is 
+         done by using a box smaller than the size of two slitlets 
+ */
+
+int 
+sinfo_new_fit_slits_boltz( cpl_image   * lineImage,
+                   FitParams ** par,
+                   float     ** sinfo_slit_pos,
+                   int          box_length,
+                   float        y_box,
+                   float        diff_tol ) ;
+
+/**
+   @name  sinfo_new_fit_slits_boltz_single_line()
+   @param lineImage  emission line frame
+   @param sinfo_slit_pos   allocated dummy array for the slitlet 
+                           positions [32][2]
+   @param box_length  pixel length of the row box within the fit is done
+   @param y_box       small box in spectral direction within the slitlet
+                      may lie
+   @param low_pos
+   @param high_pos pixel positions in spectral direction between which the line
+                   should be located.
+   @return   sinfo_slit_pos  beginning and end position of the slitlets to
+                          sub-pixel accuracy 0  if it worked, -1  if it failed,
+   @doc  fits the beginning and end position of the slitlets by using 
+         non-linear least square fitting of a Boltzmann function fits a 
+         Boltzmann function to the slitlet edges exposed and indicated by the 
+         brightest emission lines. The slitlet is searched within user given 
+         positions. The least squares fit is done by using a box smaller than
+         the size of two slitlets
+*/
+
+int 
+sinfo_new_fit_slits_boltz_single_line ( cpl_image   * lineImage,
+                  float     ** sinfo_slit_pos,
+                  int          box_length,
+                  float        y_box,
+                  int          low_pos,
+                  int          high_pos ) ;
+
+
+/**
+   @name  sinfo_new_fit_slits_boltz_with_estimate()
+   @param lineImage  emission line frame
+   @param sinfo_slit_pos  estimation array for the slitlet positions [min32][2]
+   @param box_length  pixel length of the row box within the fit is done
+   @param y_box       small box in spectral direction within the slitlet
+                      may lie.
+   @param low_pos
+   @param high_pos    pixel positions in spectral direction between which the 
+                      line should be located.
+   @return sinfo_slit_pos  beginning and end position of the slitlets to
+                           sub-pixel accuracy 0  if it worked, -1  if it failed,
+   @doc  fits the beginning and end position of the slitlets by using 
+         non-linear least square fitting of a Boltzmann function fits a 
+         Boltzmann function to the slitlet edges exposed and indicated by the 
+         brightest emission lines. The slitlet is searched within user given 
+         positions. The least squares fit is done by using a box smaller than
+         the size of two slitlets 
+ */
+
+
+int 
+sinfo_new_fit_slits_boltz_with_estimate ( cpl_image   * lineImage,
+                                float     ** sinfo_slit_pos,
+                                int          box_length,
+                                float        y_box,
+                                float        diff_tol,
+                                int          low_pos,
+                                int          high_pos ) ;
+
+
+/**
+   @name  sinfo_new_fit_slits_edge_with_estimate()
+   @param lineImage  emission line frame
+   @param sinfo_slit_pos  estimation array for the slitlet positions [min32][2]
+   @param box_length pixel length of the row box within the fit is done
+   @param y_box      small box in spectral direction within the slitlet
+                     may lie.
+   @param low_pos
+   @param high_pos   pixel positions in spectral direction between which the 
+                     line should be located.
+   @doc   sinfo_slit_pos  beginning and end position of the slitlets to
+                           sub-pixel accuracy  0  if it worked,
+                             -1  if it failed,
+   @doc   fits the beginning and end position of the slitlets by using 
+          non-linear least square fitting of an sinfo_edge  function fits a 
+          linear sinfo_edge function to the slitlet edges exposed and indicated
+          by the brightest emission lines. The slitlet is searched within
+          user given positions.
+          The least squares fit is done by using a box smaller than
+          the size of two slitlets 
+ */
+
+int 
+sinfo_new_fit_slits_edge_with_estimate ( cpl_image   * lineImage,
+                                float    ** sinfo_slit_pos,
+                                int         box_length,
+                                float       y_box,
+                                float       diff_tol,
+                                int         low_pos,
+                                int         high_pos ) ;
+
+
+
+#endif /*!SINFO_ABSOLUTE_H*/
+/**@}*/
diff --git a/sinfoni/sinfo_atmo_disp.c b/sinfoni/sinfo_atmo_disp.c
new file mode 100644
index 0000000..e00490f
--- /dev/null
+++ b/sinfoni/sinfo_atmo_disp.c
@@ -0,0 +1,328 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004-2009 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2011/12/08 16:15:40 $
+ * $Revision: 1.7 $
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>          /* allows the program compilation */
+#endif
+
+#include <cpl.h>
+#include <string.h>
+#include <math.h>
+#include <sinfo_msg.h>
+#include <sinfo_utils_wrappers.h>
+#include "sinfo_atmo_disp.h"
+#include "sinfo_resampling.h"
+#include "sinfo_image_ops.h"
+
+struct _disp_data
+{
+	double p1;
+	double d1;
+	double d2;
+	double N0;
+	double predelta;
+	double parallactic_shiftX;
+	double parallactic_shiftY;
+};
+typedef struct _disp_data disp_data;
+static double sinfo_disp_calc_N(const disp_data* pdata, double lambda);
+static void 
+sinfo_disp_prepare_data(disp_data* pdata,
+			double lambda0,
+			double Tc,
+			double rh,
+			double airm,
+			double p,
+			double parallactic,
+			double pixelscale );
+
+static void 
+sinfo_disp_calc(disp_data* pdata, double lambda, double *shiftx, double *shiftY);
+static void 
+sinfo_atmo_rotate_point(double* x_value, double * y_value, double rot_angle);
+/*------------------------------------------------------------------------------------*/
+
+static double 
+sinfo_disp_calc_N(const disp_data* pdata, double lambda)
+{
+	double s = 1.0 /lambda;
+	double s2 = s  * s;
+	double s3 = s2 * s;
+	double s4 = s3 * s;
+	double s5 = s4 * s;
+	double s6 = s5 * s;
+
+	double a = 83939.7/(130   - s2);
+	double b =   4547.3/(38.99 - s2);
+	double c = 6487.31 + 58.058*s2 - 0.71150*s4 + 0.08851*s6;
+	double N =  1e-8 * ( ((2371.34 + a + b) * pdata->d1)  +  ( c * pdata->d2));
+	return N;
+
+}
+static void 
+sinfo_disp_prepare_data(disp_data* pdata,
+		double lambda0,
+		double Tc,
+        double rh,
+        double airm,
+        double p,
+        double parallactic,
+        double pixelscale )
+{
+    double ps,p2,p1,T,T2,T3;
+    double zenith;
+//    const double PI_NUMBer = 3.1415926535;
+
+    T  = Tc + 273.15;T2 = T  * T; T3 = T2 * T;
+    ps = -10474 + (116.43 * T) - (0.43284 *T2) + (0.00053840 * T3);
+    p2 = (rh/100)*ps;
+    p1 = p - p2;
+    pdata->d1 = (p1/T)*(1+p1*( (57.90e-8) - ((9.3250e-4)/T) + (0.25844/T2)));
+    pdata->d2 = (p2/T)*(1+p2*(1+3.7e-4*p2)*( (-2.37321e-3) + (2.23366/T) - (710.792/T2) + ((7.75141e-4)/T3) )) ;
+	pdata->N0 = sinfo_disp_calc_N(pdata, lambda0);
+    zenith     = acos(1/airm);
+    pdata->predelta      = ((tan(zenith)) / (PI_NUMB/180)) * 3600;
+    pdata->parallactic_shiftX = sin ( (parallactic)* (PI_NUMB/180) ) / pixelscale;
+    pdata->parallactic_shiftY = cos ( (parallactic)* (PI_NUMB/180) ) / pixelscale;
+    sinfo_msg_warning("atm disp N0[%f] d1[%f] d2[%f] pshiftX[%f] pshiftY[%f]",
+    		pdata->N0,pdata->d1, pdata->d2,  pdata->parallactic_shiftX ,
+    		pdata->parallactic_shiftY);
+}
+static void 
+sinfo_disp_calc(disp_data* pdata, double lambda, double *shiftx, double *shifty)
+{
+	double n = sinfo_disp_calc_N(pdata, lambda);
+	double delta = pdata->predelta * (n - pdata->N0);
+	*shiftx = -delta * pdata->parallactic_shiftX;
+	*shifty = delta * pdata->parallactic_shiftY ;
+}
+
+cpl_error_code 
+sinfo_atm_dispersion_cube(cpl_imagelist* pCube,
+		int centpix, // central plane in the cube CRPIX3
+		double centlambda, // wavelength of the central plane CRVAL3
+		double Tc, // temperature in Celsius TEL.AMBI.TEMP
+		double Rh, // relative humidity in % TEL.AMBI.RHUM
+		double airm, // airmass for the moment of observation TEL.AMBI.PRES
+		double p, // atmospheric pressure TEL.AMBI.PRES
+		double parallactic, // TEL.PARANG
+		double pixelscale, // could be for SINFONI 0.025, 0.100, 0.250
+		double pixelsz // microns per pixel CDELT3
+		)
+{
+	cpl_error_code err = CPL_ERROR_NONE;
+	int cubesize = cpl_imagelist_get_size(pCube);
+	double * kernel = sinfo_generate_interpolation_kernel("default");
+	disp_data ddata;
+	int i = 0;
+
+	sinfo_disp_prepare_data(&ddata, centlambda, Tc, Rh, airm, p, parallactic, pixelscale);
+
+	for (i = 0; i < cubesize; i++)
+	{
+		double shiftx = 0;
+		double shifty = 0;
+
+		cpl_image* pnewImage = 0;
+		// 1. get an image
+		cpl_image* plane = cpl_imagelist_get(pCube, i);
+
+		// 2. calculate dispersion and shift
+		double lambda = centlambda - (centpix - i) * pixelsz;
+		sinfo_disp_calc(&ddata, lambda, &shiftx, &shifty);
+		// 3. aplly shift
+//		int szx = cpl_image_get_size_x(plane);
+		//int szy = cpl_image_get_size_y(plane);
+		//if (i % 10 == 0)
+			sinfo_msg_warning(" shift image #%d, dx[%f] dy[%f]", i, shiftx, shifty);
+		pnewImage = sinfo_new_shift_image(
+		    plane,
+		    shiftx,
+		    shifty,
+		    kernel);
+		err = cpl_imagelist_set(pCube, pnewImage, i);
+		if (err != CPL_ERROR_NONE)
+			break;
+	}
+	cpl_free(kernel);
+	return err;
+
+}
+
+
+/*----------------------------------------------------
+ * Atmospheric correction using polynomial fit
+ *----------------------------------------------------*/
+cpl_polynomial* 
+sinfo_atmo_load_polynom(const char* filename)
+{
+	const char* COL_NAME_TEMPLATE = "col_%d";
+	const char* COL_NAME_VALUE = "value";
+	cpl_polynomial* poly = NULL;
+	cpl_table* ptable = NULL;
+
+	ptable = cpl_table_load(filename, 1, 0);
+	if (ptable)
+	{
+		int dim = 0;
+		int nrows = 0;
+		int i = 0;
+		cpl_size* expo = NULL;
+
+		dim = cpl_table_get_ncol(ptable) - 1;
+		poly = cpl_polynomial_new(dim );
+		nrows = cpl_table_get_nrow(ptable);
+		expo = cpl_malloc(dim * sizeof(expo[0]));
+		memset(&expo[0], 0, dim * sizeof(expo[0]));
+		for (i = 0; i < nrows; i++)
+		{
+			int j = 0;
+			int inull = 0;
+			double value = 0;
+			for (j = 0; j < dim; j++)
+			{
+				char col_name[255];
+				sprintf(col_name, COL_NAME_TEMPLATE, j);
+				expo[j] = cpl_table_get_int(ptable, col_name, i, &inull);
+			}
+			value = cpl_table_get(ptable, COL_NAME_VALUE, i, &inull);
+			cpl_polynomial_set_coeff(poly, expo, value);
+			if (cpl_error_get_code() != CPL_ERROR_NONE)
+			{
+				if (poly)
+				{
+					sinfo_free_polynomial(&poly);
+				}
+				break;
+			}
+		}
+		cpl_free(expo);
+	}
+	sinfo_free_table(&ptable);
+	return poly;
+}
+
+static void 
+sinfo_atmo_rotate_point(double* x_value, double * y_value, double rot_angle)
+{
+	double newx = *x_value * cos(rot_angle) - *y_value * sin(rot_angle);
+	double newy = *x_value * sin(rot_angle) + *y_value * cos(rot_angle);
+	*x_value = newx;
+	*y_value = newy;
+}
+
+cpl_imagelist* 
+sinfo_atmo_apply_cube_polynomial_shift(
+		cpl_polynomial* poly,
+		cpl_imagelist* pCube,
+		double lambda0,
+		double airmass,
+		double parallactic, // should be in radian
+		double pixelsz,
+		int centpix)
+{
+	cpl_imagelist* retcube = NULL;
+	cpl_error_code 	err = CPL_ERROR_NONE;
+	cpl_vector* vparams = NULL;
+	double * kernel = sinfo_generate_interpolation_kernel("default");
+	int cubesize = 0;
+	int i = 0;
+	// the following two parameters are necessary for computing the shift
+	// in case when polynom for H+K band is used for H or K
+	double l0_shift_x = 0; // shift for the central point by X
+	double l0_shift_y = 0; // shift for the central point by Y
+
+	vparams = cpl_vector_new(2);
+	cpl_vector_set(vparams, 0, airmass);
+	cpl_vector_set(vparams, 1, lambda0);
+	err = cpl_error_get_code();
+	if (err == CPL_ERROR_NONE)
+	{
+		l0_shift_y = cpl_polynomial_eval(poly, vparams); // North - South
+		l0_shift_x = 0; // (EAST-WEST direction)
+		// rotate the shift
+		sinfo_atmo_rotate_point(&l0_shift_x, &l0_shift_y, parallactic);
+		cubesize = cpl_imagelist_get_size(pCube);
+		err =  cpl_error_get_code();
+	}
+	if (err == CPL_ERROR_NONE)
+	{
+		retcube = cpl_imagelist_new();
+		for (i = 0; i < cubesize; i++)
+		{
+			// calculate the wavelength
+			double lambda = lambda0 - (centpix - i) * pixelsz;
+			double shift_y = 0;
+			double shift_x = 0;
+
+			cpl_vector_set(vparams, 1, lambda);
+			// calc the shift
+			shift_y = cpl_polynomial_eval(poly, vparams); // North - South
+			err = cpl_error_get_code();
+			if (err == CPL_ERROR_NONE)
+			{
+				double res_shift_x = -(shift_x - l0_shift_x);
+				double res_shift_y = -(shift_y - l0_shift_y);
+				cpl_image* plane = NULL;
+				cpl_image* pimresult = NULL;
+				// rotate the shift
+				sinfo_atmo_rotate_point(&res_shift_x, &res_shift_y, parallactic);
+				plane = cpl_imagelist_get(pCube, i);
+				pimresult = sinfo_new_shift_image(
+						plane,
+						res_shift_x, // x shift
+						res_shift_y, // y shift
+						kernel);
+				if (err == CPL_ERROR_NONE)
+				{
+					err = cpl_imagelist_set(retcube, pimresult, i);
+				}
+				else
+				{
+					sinfo_msg_error("Error sinfo_new_shift_image, %s",
+										cpl_error_get_where());
+				}
+				if (err != CPL_ERROR_NONE)
+					break;
+			}
+			else
+			{
+				sinfo_msg_error("Error polynomial_eval, %s",
+						cpl_error_get_where());
+			}
+			if (err != CPL_ERROR_NONE)
+				break;
+		}
+	}
+	if (err != CPL_ERROR_NONE)
+	{
+		sinfo_free_imagelist(&retcube);
+		sinfo_msg_error("Error during shift planes in the cube, %s",
+				cpl_error_get_where());
+	}
+    sinfoni_free_vector(&vparams);
+	cpl_free(kernel);
+	return retcube;
+}
diff --git a/sinfoni/sinfo_atmo_disp.h b/sinfoni/sinfo_atmo_disp.h
new file mode 100644
index 0000000..a26219f
--- /dev/null
+++ b/sinfoni/sinfo_atmo_disp.h
@@ -0,0 +1,70 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004-2009 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2010/02/08 07:15:18 $
+ * $Revision: 1.4 $
+ */
+
+#ifndef SINFO_ATMO_DISP_H_
+#define SINFO_ATMO_DISP_H_
+
+cpl_error_code 
+sinfo_atm_dispersion_cube(cpl_imagelist* pCube,
+		int centpix, // central plane in the cube CRPIX3
+		double centlambda, // wavelength of the central plane CRVAL3
+		double Tc, // temperature in Celsius TEL.AMBI.TEMP
+		double Rh, // relative humidity in % TEL.AMBI.RHUM
+		double airm, // airmass for the moment of observation TEL.AMBI.PRES
+		double p, // atmospheric pressure TEL.AMBI.PRES
+		double parallactic, // TEL.PARANG
+		double pixelscale, // could be for SINFONI 0.025, 0.100, 0.250
+		double pixelsz // microns per pixel CDELT3
+			  );
+
+
+void calcAtmosphericDispersion( double lambda, double lambda0, double *shiftX, double *shiftY, double *deltaR,
+                   double Tc,
+                   double rh,
+                   double airm,
+                   double p,
+                   double parallactic,
+                   double pixelscale);
+cpl_error_code sinfo_atmo_dispersion_cube(cpl_imagelist* pCube,
+		int centpix, // central plane in the cube
+		double centlambda, // wavelength of the central plane
+		double Tc, // temperature in Celsius TEL.AMBI.TEMP
+		double Rh, // relative humidity in % TEL.AMBI.RHUM
+		double airm, // airmass for the moment of observation TEL.AMBI.PRES
+		double p, // atmospheric pressure TEL.AMBI.PRES
+		double parallactic, // TEL.PARANG
+		double pixelscale, // could be for SINFONI 0.025, 0.100, 0.250
+		double pixelsz // microns per pixel CDELT3
+		);
+cpl_imagelist* sinfo_atmo_apply_cube_polynomial_shift(
+		cpl_polynomial* poly,
+		cpl_imagelist* pCube,
+		double lambda0,
+		double airmass,
+		double parallactic, // should be in radian
+		double pixelsz,
+		int centpix);
+cpl_polynomial* sinfo_atmo_load_polynom(const char* filename);
+#endif /* SINFO_ATM_DISP_H_ */
diff --git a/sinfoni/sinfo_bad_cfg.c b/sinfoni/sinfo_bad_cfg.c
new file mode 100644
index 0000000..13f025c
--- /dev/null
+++ b/sinfoni/sinfo_bad_cfg.c
@@ -0,0 +1,78 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*---------------------------------------------------------------------------
+   
+   File name     :    sinfo_bad_cfg.c
+   Autor    :       Juergen Schreiber
+   Created on    :    October 2001
+   Description    :    handles the data structure bad_config
+
+ *--------------------------------------------------------------------------*/
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+/*---------------------------------------------------------------------------
+                                   Includes
+ ---------------------------------------------------------------------------*/
+
+#include "sinfo_bad_cfg.h"
+/**@{*/
+/**
+ * @defgroup sinfo_bad_pix_search Bad Pixel Search
+ *
+ * TBD
+ */
+
+/*---------------------------------------------------------------------------
+                              Function codes
+ ---------------------------------------------------------------------------*/
+/**
+   @name    sinfo_bad_cfg_create()
+   @memo    allocate memory for a bad_cfg struct
+   @return  pointer to allocated base bad_cfg structure
+   @note    only the main (base) structure is allocated
+ */
+
+bad_config * 
+sinfo_bad_cfg_create(void)
+{
+    return cpl_calloc(1, sizeof(bad_config));
+}
+/**
+   @name   sinfo_bad_cfg_destroy()
+   @memo deallocate all memory associated with a bad_config data structure
+   @param  sc   bad_config to deallocate
+   @return void
+*/
+void 
+sinfo_bad_cfg_destroy(bad_config * sc)
+{
+
+    if (sc==NULL) return ;
+   
+    /* Free main struct */
+    cpl_free(sc);
+
+    return ;
+}
+
+/**@}*/
+
+
diff --git a/sinfoni/sinfo_bad_cfg.h b/sinfoni/sinfo_bad_cfg.h
new file mode 100644
index 0000000..482d891
--- /dev/null
+++ b/sinfoni/sinfo_bad_cfg.h
@@ -0,0 +1,124 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*---------------------------------------------------------------------------
+   
+   File name     :    bad_cfg.h
+   Author         :    Juergen Schreiber
+   Created on    :    October 2001
+   Description    :    bad_ini definitions + handling prototypes
+
+ ---------------------------------------------------------------------------*/
+#ifndef SINFO_BAD_CFG_H
+#define SINFO_BAD_CFG_H
+/*---------------------------------------------------------------------------
+                                   Includes
+ ---------------------------------------------------------------------------*/
+#include <stdlib.h>
+#include "sinfo_globals.h"
+#include <cpl.h>
+
+/*---------------------------------------------------------------------------
+                                   Defines
+ ---------------------------------------------------------------------------*/
+/*---------------------------------------------------------------------------
+                                   New types
+ ---------------------------------------------------------------------------*/
+/*
+  bad pixels search blackboard container
+
+  This structure holds all information related to the bad pixels search
+  routine. It is used as a container for the flux of ancillary data,
+  computed values, and algorithm status. Pixel flux is separated from
+  the blackboard.
+  */
+
+typedef struct bad_config {
+/*-------General---------*/
+        char inFile[FILE_NAME_SZ] ; /* file name of the file containing 
+                                       the list of all input frames */
+        char outName[FILE_NAME_SZ] ; /* output name of resulting bad pixel 
+                                        mask (fits file)*/
+        char ** framelist ; /* list of frames */
+        int     nframes ; /* number of frames in frame list */
+
+/*------ BadPix ------*/
+        /* factor of noise within which the pixels are used to fit a 
+           straight line to the column intensity */
+        float sigmaFactor ;      
+        /* factor of calculated standard deviation beyond which the 
+           deviation of a pixel value from the 
+           median of the 8 nearest neighbors declares a pixel as bad */
+        float factor ;
+        /* number of iterations of sinfo_median filter */
+        int iterations ;
+        /* percentage of extreme pixel value to reject when calculating 
+           the mean and stdev */
+        float loReject ;
+        float hiReject ;
+        /* pixel coordinate of lower left edge of a rectangle zone from 
+           which image statistics are computed */
+        int llx ;
+        int lly ;
+        /* pixel coordinate of upper right edge of a rectangle zone from 
+           which image statistics are computed */
+        int urx ;
+        int ury ;
+/*------ Thresh ------*/
+        /* indicates if the values beyond threshold values should 
+           be marked as bad before proceeding 
+           to sinfo_median filtering */
+        int threshInd ;
+        /* factor to the clean standard deviation to define the 
+           threshold deviation from the clean mean */
+        float meanfactor ;
+        /* minimum vlaue of good data */
+        float mincut ;
+        /* maximum vlaue of good data */
+        float maxcut ;
+        /* indicates which method will be used */
+        int methodInd ;
+} bad_config ;
+
+/*---------------------------------------------------------------------------
+                               Function prototypes
+ ---------------------------------------------------------------------------*/
+
+
+/**
+   @name    sinfo_bad_cfg_create()
+   @memo    allocate memory for a bad_cfg struct
+   @return  pointer to allocated base bad_cfg structure
+   @note    only the main (base) structure is allocated
+ */
+
+bad_config * 
+sinfo_bad_cfg_create(void);
+
+
+/**
+   @name   sinfo_bad_cfg_destroy()
+   @memo deallocate all memory associated with a bad_config data structure
+   @param  sc   bad_config to deallocate
+   @return void
+*/
+void 
+sinfo_bad_cfg_destroy(bad_config * sc);
+ 
+
+#endif
diff --git a/sinfoni/sinfo_bad_ini.h b/sinfoni/sinfo_bad_ini.h
new file mode 100644
index 0000000..31d58b5
--- /dev/null
+++ b/sinfoni/sinfo_bad_ini.h
@@ -0,0 +1,75 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+   
+   File name    :   bad_ini.h
+   Author       :   Juergen Schreiber
+   Created on   :   Oct 25, 2001
+   Description  :   prepare handling of .ini file for the search for static 
+                    bad pixels
+ ---------------------------------------------------------------------------*/
+#ifndef SINFO_BAD_INI_H
+#define SINFO_BAD_INI_H
+
+
+/*---------------------------------------------------------------------------
+                                Includes
+---------------------------------------------------------------------------*/
+#include "sinfo_bad_cfg.h"
+#include <cpl.h>
+/*---------------------------------------------------------------------------
+                                Defines
+---------------------------------------------------------------------------*/
+ 
+/*----------------------------------------------------------------------------
+                             Function prototypes 
+ ---------------------------------------------------------------------------*/
+
+/**
+  @name        generateBad_ini_file
+  @memo        Generate a default ini file for the bad pixel search command.
+  @param    ini_name    Name of the file to generate.
+  @param    name_i        Name of the input file.
+  @param    name_o        Name of the output file.
+  @return    int 0 if Ok, -1 otherwise.
+  @doc This function generates a default ini file for the bad pixel search 
+       command. The generated file will have the requested name. 
+ */
+int 
+generateBad_ini_file(
+        char * ini_name,
+        char * name_i,
+        char * name_o
+);
+ 
+
+/**
+  @name     parse_bad_ini_file
+  @memo     Parse an ini_name.ini file and create a blackboard.
+  @param    ini_name    Name of the ASCII file to parse.
+  @return   1 newly allocated bad_config blackboard structure.
+  @doc The requested ini file is parsed and a blackboard object is created, 
+       then updated accordingly. Returns NULL in case of error.
+ */
+
+
+bad_config * 
+parse_bad_ini_file(char * ini_name) ;
+
+#endif
diff --git a/sinfoni/sinfo_baddist_ini_by_cpl.c b/sinfoni/sinfo_baddist_ini_by_cpl.c
new file mode 100644
index 0000000..40f3a0a
--- /dev/null
+++ b/sinfoni/sinfo_baddist_ini_by_cpl.c
@@ -0,0 +1,302 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+   
+   File name    :   sinfo_baddist_ini_by_cpl.c
+   Author       :   Andrea Modigliani
+   Created on   :   Jun 16, 2004
+   Description  :   parse cpl input for the search of static bad pixels
+
+ ---------------------------------------------------------------------------*/
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+/*---------------------------------------------------------------------------
+                                Includes
+ ---------------------------------------------------------------------------*/
+#include <string.h>
+#include "sinfo_baddist_ini_by_cpl.h"
+#include "sinfo_hidden.h"
+#include "sinfo_pro_types.h"
+#include "sinfo_raw_types.h"
+#include "sinfo_globals.h"
+#include "sinfo_functions.h"
+#include "sinfo_file_handling.h"
+
+/*---------------------------------------------------------------------------
+                    Functions private to this module
+ ---------------------------------------------------------------------------*/
+
+static void  parse_section_frames(bad_config * cfg, 
+cpl_frameset* sof, const char* procatg, cpl_frameset** raw, int* status);
+static void parse_section_badpix(bad_config * cfg, cpl_parameterlist* cpl_cfg);
+static void parse_section_thresh(bad_config * cfg, cpl_parameterlist* cpl_cfg);
+
+/**@{*/
+/**
+ * @addtogroup sinfo_bad_pix_search Bad Pixel Search
+ *
+ * TBD
+ */
+
+/**
+  @name     sinfo_parse_cpl_input_badnorm
+  @memo     Parse input from CPL (parameters and set of input frames) 
+            to create a blackboard.
+  @param    config    cpl parameter list
+  @param    sof       cpl frames list
+  @return   1 newly allocated bad_config blackboard structure.
+  @doc
+
+  The requested cpl input is parsed and a blackboard object is created, then
+  updated accordingly. Returns NULL in case of error.
+ */
+
+
+bad_config * 
+sinfo_parse_cpl_input_baddist(cpl_parameterlist * cpl_cfg, 
+                                     cpl_frameset* sof,
+                                     const char* procatg,
+                                     cpl_frameset** raw) 
+{
+  bad_config    *       cfg ;
+  int status = 0;
+        /* Removed check on ini_file */
+        /* Removed load of ini file */
+
+  cfg = sinfo_bad_cfg_create();
+
+        /*
+         * Perform sanity checks, fill up the structure with what was
+         * found in the ini file
+         */
+
+  parse_section_badpix   (cfg, cpl_cfg);
+  parse_section_thresh   (cfg, cpl_cfg);
+  parse_section_frames   (cfg, sof, procatg, raw,&status);
+  if(status>0) {
+               sinfo_msg_error("parsing cpl input");
+                sinfo_bad_cfg_destroy(cfg);
+                cfg = NULL ;
+                return NULL ;
+  }
+  return cfg ;
+
+}
+
+/**
+  @name     parse_section_frames
+  @memo     Parse input frames
+  @param    cfg    pointer to bad_config structure 
+  @param    sof       cpl frames list
+  @param    procatg   PRO.CATG of product
+  @param    raw       raw set of frames
+  @param    status    status of operation
+  @return   void
+ */
+
+static void     
+parse_section_frames(bad_config   * cfg,
+                     cpl_frameset * sof,
+                     const char    * procatg,          
+                     cpl_frameset ** raw,
+                     int* status)
+{
+   int                i=0;
+   int                nraw = 0;
+   char *          tag=NULL;
+
+   int  nraw_good = 0;
+   cpl_frame* frame=NULL;
+   char spat_res[FILE_NAME_SZ];
+   char lamp_status[FILE_NAME_SZ];
+   char band[FILE_NAME_SZ];
+   int ins_set=0;
+
+
+     if(strcmp(procatg,PRO_BP_MAP_DI) == 0 ) {
+
+      sinfo_extract_raw_frames_type(sof,raw,PRO_MASTER_FLAT_LAMP);
+      nraw=cpl_frameset_get_size(*raw);
+
+   } else if(strcmp(procatg,PRO_BP_MAP_NO) == 0 ) {
+      
+      sinfo_extract_raw_frames_type(sof,raw,PRO_MASTER_FLAT_LAMP);
+      nraw=cpl_frameset_get_size(*raw);
+
+   } else {
+      sinfo_extract_raw_frames_type(sof,raw,RAW_FLAT_LAMP);
+      nraw=cpl_frameset_get_size(*raw);
+
+      if (nraw==0) {
+         sinfo_extract_raw_frames_type(sof,raw,RAW_FLAT_NS);
+         nraw=cpl_frameset_get_size(*raw);
+      }   
+
+   }
+    if (nraw==0) {
+         sinfo_extract_raw_frames_type(sof,raw,RAW_FLAT_LAMP);
+         nraw=cpl_frameset_get_size(*raw);
+    }
+
+    if (nraw==0) {
+         sinfo_extract_raw_frames_type(sof,raw,RAW_FLAT_NS);
+         nraw=cpl_frameset_get_size(*raw);
+    }
+
+
+
+   nraw=cpl_frameset_get_size(*raw);
+   if (nraw < 1) {
+      sinfo_msg_error("Too few (%d) raw frames (%s or %s) present in"
+             "frameset!Aborting...",nraw,
+                         RAW_FLAT_LAMP,RAW_FLAT_NS);
+      (*status)++;
+      return;
+   }
+        
+   /* Removed: get "general:infile" read it, check input sinfo_matrix */
+   /* Allocate structures to go into the blackboard */
+   cfg->framelist     = cpl_malloc(nraw * sizeof(char*));
+
+   /* read input frames */
+   for (i=0 ; i<nraw ; i++) {
+      frame = cpl_frameset_get_frame(*raw,i);
+      tag = (char*)cpl_frame_get_tag(frame) ;
+      if(sinfo_file_exists((char*) cpl_frame_get_filename(frame))==1) 
+    {
+             /* Store file name into framelist */
+             cfg->framelist[i]=(char*) cpl_frame_get_filename(frame);
+             nraw_good++;
+    }
+   }
+   if(nraw_good<1) {
+     sinfo_msg_error("Error: no good raw frame in input, something wrong!");
+     (*status)++;
+     return;
+   }
+
+   /* Copy relevant information into the blackboard */
+   cfg->nframes         = nraw_good ;
+
+   /* Output */
+   strcpy(cfg -> outName, BP_DIST_OUT_FILENAME);
+ 
+
+
+
+   frame = cpl_frameset_get_frame(*raw,0);
+   sinfo_get_spatial_res(frame,spat_res);
+ 
+    switch(sinfo_frame_is_on(frame)) 
+     {
+   case 0: 
+      strcpy(lamp_status,"on");
+      break;
+    case 1: 
+      strcpy(lamp_status,"off");
+      break;
+    case -1:
+      strcpy(lamp_status,"undefined");
+      break;
+    default: 
+      strcpy(lamp_status,"undefined");
+      break;
+     }
+
+    sinfo_get_band(frame,band);
+   sinfo_msg("Spatial resolution: %s lamp_status: %s band: %s \n",
+                     spat_res,    lamp_status,    band);
+   sinfo_get_ins_set(band,&ins_set);
+
+   return;
+
+}
+
+/**
+  @name     parse_section_badpix
+  @memo     Parse bad pixel parameters
+  @param    cfg      pointer to bad_config structure 
+  @param    cpl_cfg  input parameter list
+  @return   void
+ */
+static void     
+parse_section_badpix(bad_config    * cfg, cpl_parameterlist *   cpl_cfg)
+{
+   cpl_parameter *p;     
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_dist.sigma_factor");
+   cfg -> sigmaFactor = cpl_parameter_get_double(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_dist.method_index");
+   cfg -> methodInd = cpl_parameter_get_int(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_dist.factor");
+   cfg -> factor = cpl_parameter_get_double(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_dist.iterations");
+   cfg -> iterations = cpl_parameter_get_int(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_dist.low_rejection");
+   cfg -> loReject = cpl_parameter_get_double(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_dist.high_rejection");
+   cfg -> hiReject = cpl_parameter_get_double(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_dist.llx");
+   cfg -> llx = cpl_parameter_get_int(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_dist.lly");
+   cfg -> lly = cpl_parameter_get_int(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_dist.urx");
+   cfg -> urx = cpl_parameter_get_int(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_dist.ury");
+   cfg -> ury = cpl_parameter_get_int(p);
+
+}
+
+/**
+  @name     parse_section_thresh
+  @memo     Parse threshold parameters
+  @param    cfg    pointer to bad_config structure 
+  @param    cpl_cfg   input parameter list
+  @return   void
+ */
+static void     
+parse_section_thresh(bad_config    * cfg, cpl_parameterlist *   cpl_cfg)
+{
+   cpl_parameter *p;     
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_dist.threshold_index");
+   cfg -> threshInd  = cpl_parameter_get_bool(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_dist.mean_factor");
+   cfg -> meanfactor = cpl_parameter_get_double(p);
+
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_dist.min_cut");
+   cfg -> mincut = cpl_parameter_get_double(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_dist.max_cut");
+   cfg -> maxcut = cpl_parameter_get_double(p);
+
+}
+/**@}*/
diff --git a/sinfoni/sinfo_baddist_ini_by_cpl.h b/sinfoni/sinfo_baddist_ini_by_cpl.h
new file mode 100644
index 0000000..e31c303
--- /dev/null
+++ b/sinfoni/sinfo_baddist_ini_by_cpl.h
@@ -0,0 +1,75 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+   
+   File name    :   sinfo_baddist_ini_by_cpl.h
+   Author       :   Andrea Modigliani
+   Created on   :   Jun 16, 2004
+   Description  :   parse cpl input for the search for static bad pixels
+
+ ---------------------------------------------------------------------------*/
+
+
+#ifndef SINFO_BADDIST_INI_BY_CPL_H
+#define SINFO_BADDIST_INI_BY_CPL_H
+
+
+/*---------------------------------------------------------------------------
+                                Includes
+---------------------------------------------------------------------------*/
+#include <cpl.h>
+#include "sinfo_msg.h"
+#include "sinfo_bad_cfg.h"
+/*---------------------------------------------------------------------------
+                                Defines
+---------------------------------------------------------------------------*/
+ 
+/*----------------------------------------------------------------------------
+                             Function prototypes 
+ ---------------------------------------------------------------------------*/
+
+/**
+ at name sinfo_bad_free
+ at memo free a bad_config object
+ at param cfg pointer to bad_config structure
+ at return void
+*/
+void 
+sinfo_bad_free(bad_config * cfg);
+
+/**
+  @name     sinfo_parse_cpl_input_badnorm
+  @memo     Parse input from CPL (parameters and set of input frames) 
+            to create a blackboard.
+  @param    config    cpl parameter list
+  @param    sof       cpl frames list
+  @return   1 newly allocated bad_config blackboard structure.
+  @doc
+
+  The requested cpl input is parsed and a blackboard object is created, then
+  updated accordingly. Returns NULL in case of error.
+ */
+
+bad_config * 
+sinfo_parse_cpl_input_baddist(cpl_parameterlist * cpl_cfg, 
+                              cpl_frameset* sof, 
+                              const char* procatg, 
+                              cpl_frameset** raw);
+
+#endif
diff --git a/sinfoni/sinfo_badnorm_ini_by_cpl.c b/sinfoni/sinfo_badnorm_ini_by_cpl.c
new file mode 100644
index 0000000..518926d
--- /dev/null
+++ b/sinfoni/sinfo_badnorm_ini_by_cpl.c
@@ -0,0 +1,337 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+   
+   File name    :   sinfo_badnorm_ini_by_cpl.c
+   Author       :   Andrea Modigliani
+   Created on   :   Jun 16, 2004
+   Description  :   parse cpl input for the search of static bad pixels
+
+ ---------------------------------------------------------------------------*/
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+/*---------------------------------------------------------------------------
+                                Includes
+ ---------------------------------------------------------------------------*/
+
+#include <string.h>
+#include "sinfo_badnorm_ini_by_cpl.h"
+#include "sinfo_raw_types.h"
+#include "sinfo_pro_types.h"
+#include "sinfo_hidden.h"
+#include "sinfo_globals.h"
+#include "sinfo_functions.h"
+#include "sinfo_file_handling.h"
+/*---------------------------------------------------------------------------
+                    Functions private to this module
+ ---------------------------------------------------------------------------*/
+
+static void  parse_section_frames(bad_config * cfg, 
+cpl_frameset* sof, const char* procatg, cpl_frameset** raw, int* status);
+static void parse_section_badpix(bad_config * cfg, cpl_parameterlist* cpl_cfg);
+static void parse_section_thresh(bad_config * cfg, cpl_parameterlist* cpl_cfg);
+
+/**@{*/
+/**
+ * @addtogroup sinfo_bad_pix_search Bad Pixel Search
+ *
+ * TBD
+ */
+
+/**
+  @name     sinfo_parse_cpl_input_badnorm
+  @memo     Parse input from CPL (parameters and set of input frames) 
+            to create a blackboard.
+  @param    config    cpl parameter list
+  @param    sof       cpl frames list
+  @return   1 newly allocated bad_config blackboard structure.
+  @doc The requested cpl input is parsed and a blackboard object is created, 
+       then updated accordingly. Returns NULL in case of error.
+ */
+
+
+
+bad_config * 
+sinfo_parse_cpl_input_badnorm(cpl_parameterlist * cpl_cfg, 
+                                     cpl_frameset* sof,
+                                     const char* procatg,
+                                     cpl_frameset** raw) 
+{
+  bad_config    *       cfg ;
+  int status = 0;
+        /* Removed check on ini_file */
+        /* Removed load of ini file */
+
+  cfg = sinfo_bad_cfg_create();
+
+        /*
+         * Perform sanity checks, fill up the structure with what was
+         * found in the ini file
+         */
+
+  parse_section_badpix   (cfg, cpl_cfg);
+  parse_section_thresh   (cfg, cpl_cfg);
+  parse_section_frames   (cfg, sof, procatg, raw,&status);
+  if(status>0) {
+               sinfo_msg_error("parsing cpl input");
+                sinfo_bad_cfg_destroy(cfg);
+                cfg = NULL ;
+                return NULL ;
+  }
+  return cfg ;
+
+}
+
+
+/**
+  @name     parse_section_frames
+  @memo     Parse input frames 
+  @param    cfg   pointer to bad_config
+  @param    sof   cpl frames list
+  @param    procatg  PRO.CATG of product
+  @param    raw  raw set of frames
+  @param    status  status of operation
+  @return   void.
+ */
+
+
+static void     
+parse_section_frames(bad_config   * cfg,
+                     cpl_frameset * sof,
+                     const char         * procatg,          
+                     cpl_frameset ** raw,
+                     int* status)
+{
+   int                i=0;
+   int                nraw = 0;
+   char *          tag=NULL;
+
+   int  nraw_good = 0;
+   cpl_frame* frame=NULL;
+   char spat_res[FILE_NAME_SZ];
+   char lamp_status[FILE_NAME_SZ];
+   char band[FILE_NAME_SZ];
+   int ins_set=0;
+     if(strcmp(procatg,PRO_BP_MAP_DI) == 0 ) {
+
+      sinfo_extract_raw_frames_type(sof,raw,PRO_MASTER_FLAT_LAMP);
+      nraw=cpl_frameset_get_size(*raw);
+
+   } else if(strcmp(procatg,PRO_BP_MAP_NO) == 0 ) {
+      
+      sinfo_extract_raw_frames_type(sof,raw,PRO_MASTER_FLAT_LAMP);
+      nraw=cpl_frameset_get_size(*raw);
+
+   } else {
+      sinfo_extract_raw_frames_type(sof,raw,RAW_FLAT_LAMP);
+      nraw=cpl_frameset_get_size(*raw);
+
+      if (nraw==0) {
+         sinfo_extract_raw_frames_type(sof,raw,RAW_FLAT_NS);
+         nraw=cpl_frameset_get_size(*raw);
+      }   
+
+   }
+    if (nraw==0) {
+         sinfo_extract_raw_frames_type(sof,raw,RAW_FLAT_LAMP);
+         nraw=cpl_frameset_get_size(*raw);
+    }
+
+    if (nraw==0) {
+         sinfo_extract_raw_frames_type(sof,raw,RAW_FLAT_NS);
+         nraw=cpl_frameset_get_size(*raw);
+    }
+
+
+   if (nraw < 1) {
+      sinfo_msg_error("Too few (%d) raw frames (%s or %s or %s) present in"
+             "frameset!Aborting...",nraw,
+                         PRO_MASTER_FLAT_LAMP,RAW_FLAT_LAMP,RAW_FLAT_NS);
+      (*status)++;
+      return;
+   }
+        
+   /* Removed: get "general:infile" read it, check input sinfo_matrix */
+   /* Allocate structures to go into the blackboard */
+   cfg->framelist     = cpl_malloc(nraw * sizeof(char*));
+
+   /* read input frames */
+   for (i=0 ; i<nraw ; i++) {
+      frame = cpl_frameset_get_frame(*raw,i);
+      tag = (char*)cpl_frame_get_tag(frame) ;
+      if(sinfo_file_exists((char*) cpl_frame_get_filename(frame))==1) 
+    {
+             /* Store file name into framelist */
+             cfg->framelist[i]=(char*) cpl_frame_get_filename(frame);
+             nraw_good++;
+    }
+   }
+
+   if(nraw_good<1) {
+     sinfo_msg_error("Error: no good raw frame in input, something wrong!");
+     (*status)++;
+     return;
+   }
+
+   /* Copy relevant information into the blackboard */
+   cfg->nframes         = nraw_good ;
+
+   /* Output */
+          if (strcmp(procatg,PRO_BP_MAP_NO) == 0) {
+      strcpy(cfg -> outName, BP_NORM_OUT_FILENAME);
+   } else if (strcmp(procatg,PRO_BP_MAP_DI) == 0) {
+      strcpy(cfg -> outName, BP_DIST_OUT_FILENAME);
+   } else if (strcmp(procatg,PRO_DEFAULT) == 0) {
+      strcpy(cfg -> outName, BP_NORM_OUT_FILENAME);
+   } else {
+      sinfo_msg_error("Error: PRO.CATG %s, not supported!",procatg);
+      (*status)++;
+      return;
+   }
+
+
+
+   frame = cpl_frameset_get_frame(*raw,0);
+   sinfo_get_spatial_res(frame,spat_res);
+ 
+ 
+   switch(sinfo_frame_is_on(frame)) 
+     {
+   case 0: 
+      strcpy(lamp_status,"on");
+      break;
+    case 1: 
+      strcpy(lamp_status,"off");
+      break;
+    case -1:
+      strcpy(lamp_status,"undefined");
+      break;
+    default: 
+      strcpy(lamp_status,"undefined");
+      break;
+     }
+
+   sinfo_get_band(frame,band);
+   sinfo_msg("Spatial resolution: %s lamp status: %s band: %s \n",
+                     spat_res,              lamp_status,    band);
+
+
+   sinfo_get_ins_set(band,&ins_set);
+
+   return;
+
+}
+
+/**
+  @name     parse_section_badpix
+  @memo     Parse bad pixel parameters
+  @param    cfg   pointer to bad_config
+  @param    cpl_cfg input parameter list
+  @return   void.
+ */
+
+
+static void     
+parse_section_badpix(bad_config    * cfg, cpl_parameterlist *   cpl_cfg)
+{
+   cpl_parameter *p;     
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_norm.sigma_factor");
+   cfg -> sigmaFactor = cpl_parameter_get_double(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_norm.method_index");
+   cfg -> methodInd = cpl_parameter_get_int(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_norm.factor");
+   cfg -> factor = cpl_parameter_get_double(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_norm.iterations");
+   cfg -> iterations = cpl_parameter_get_int(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_norm.low_rejection");
+   cfg -> loReject = cpl_parameter_get_double(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_norm.high_rejection");
+   cfg -> hiReject = cpl_parameter_get_double(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_norm.llx");
+   cfg -> llx = cpl_parameter_get_int(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_norm.lly");
+   cfg -> lly = cpl_parameter_get_int(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_norm.urx");
+   cfg -> urx = cpl_parameter_get_int(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_norm.ury");
+   cfg -> ury = cpl_parameter_get_int(p);
+
+}
+
+/**
+  @name     parse_section_thresh
+  @memo     Parse threshold parameters
+  @param    cfg   pointer to bad_config
+  @param    cpl_cfg input parameter list
+  @return   void.
+ */
+
+
+static void     
+parse_section_thresh(bad_config    * cfg, cpl_parameterlist *   cpl_cfg)
+{
+   cpl_parameter *p;     
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_norm.threshold_index");
+   cfg -> threshInd  = cpl_parameter_get_bool(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_norm.mean_factor");
+   cfg -> meanfactor = cpl_parameter_get_double(p);
+
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_norm.min_cut");
+   cfg -> mincut = cpl_parameter_get_double(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_norm.max_cut");
+   cfg -> maxcut = cpl_parameter_get_double(p);
+
+}
+/**
+ at name sinfo_badnorm_free
+ at memo free a bad_config object
+ at param cfg pointer to bad_config structure
+ at return void
+*/
+
+void
+sinfo_badnorm_free(bad_config ** cfg)
+{  
+  if((*cfg) != NULL) {
+    if((*cfg)->framelist != NULL) {
+       cpl_free((*cfg)->framelist);
+       (*cfg)->framelist=NULL;
+    }
+    sinfo_bad_cfg_destroy((*cfg));
+    *cfg =NULL;
+  }
+  return;
+
+}
+/**@}*/
diff --git a/sinfoni/sinfo_badnorm_ini_by_cpl.h b/sinfoni/sinfo_badnorm_ini_by_cpl.h
new file mode 100644
index 0000000..afe5fbc
--- /dev/null
+++ b/sinfoni/sinfo_badnorm_ini_by_cpl.h
@@ -0,0 +1,66 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+   
+   File name    :   sinfo_badnorm_ini_by_cpl.h
+   Author       :   Andrea Modigliani
+   Created on   :   Jun 16, 2004
+   Description  :   parse cpl input for the search for static bad pixels
+ ---------------------------------------------------------------------------*/
+#ifndef SINFO_BADNORM_INI_BY_CPL_H
+#define SINFO_BADNORM_INI_BY_CPL_H
+/*---------------------------------------------------------------------------
+                                Includes
+---------------------------------------------------------------------------*/
+#include <cpl.h>
+#include "sinfo_msg.h"
+#include "sinfo_bad_cfg.h"
+/*---------------------------------------------------------------------------
+                                Defines
+---------------------------------------------------------------------------*/
+/*----------------------------------------------------------------------------
+                             Function prototypes 
+ ---------------------------------------------------------------------------*/
+/**
+  @name     sinfo_parse_cpl_input_badnorm
+  @memo     Parse input from CPL (parameters and set of input frames) 
+            to create a blackboard.
+  @param    config    cpl parameter list
+  @param    sof       cpl frames list
+  @return   1 newly allocated bad_config blackboard structure.
+  @doc The requested cpl input is parsed and a blackboard object is created, 
+       then updated accordingly. Returns NULL in case of error.
+ */
+bad_config * 
+sinfo_parse_cpl_input_badnorm(cpl_parameterlist * cpl_cfg, 
+                              cpl_frameset* sof, 
+                              const char* procatg, 
+                              cpl_frameset** raw);
+
+
+/**
+ at name sinfo_badnorm_free
+ at memo free a bad_config object
+ at param cfg pointer to bad_config structure
+ at return void
+*/
+void 
+sinfo_badnorm_free(bad_config ** cfg);
+
+#endif
diff --git a/sinfoni/sinfo_badsky_cfg.c b/sinfoni/sinfo_badsky_cfg.c
new file mode 100644
index 0000000..bfaddd8
--- /dev/null
+++ b/sinfoni/sinfo_badsky_cfg.c
@@ -0,0 +1,77 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*---------------------------------------------------------------------------
+   
+   File name     :    sinfo_badsky_cfg.c
+   Autor    :       Juergen Schreiber
+   Created on    :    October 2001
+   Description    :    handles the data structure bad_config
+
+ *--------------------------------------------------------------------------*/
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+/*---------------------------------------------------------------------------
+                                   Includes
+ ---------------------------------------------------------------------------*/
+
+#include "sinfo_badsky_cfg.h"
+/**@{*/
+/**
+ * @addtogroup sinfo_bad_pix_search Bad Pixel Search
+ *
+ * TBD
+ */
+
+/*---------------------------------------------------------------------------
+                              Function codes
+ ---------------------------------------------------------------------------*/
+/**
+   @name   sinfo_bad_cfg_create()
+   @memo   allocate memory for a bad_cfg struct
+   @return pointer to allocated base bad_cfg structure
+   @note   only the main (base) structure is allocated
+*/
+
+badsky_config * sinfo_badsky_cfg_create(void)
+{
+    return cpl_calloc(1, sizeof(badsky_config));
+}
+/**
+   @name  sinfo_bad_cfg_destroy()
+   @memo deallocate all memory associated with a bad_config data structure
+   @param sc   bad_config structure to deallocate
+   @return void 
+*/
+
+void sinfo_badsky_cfg_destroy(badsky_config * sc)
+{
+
+    if (sc==NULL) return ;
+   
+    /* Free main struct */
+    cpl_free(sc);
+
+    return ;
+}
+
+/**@}*/
+
+
diff --git a/sinfoni/sinfo_badsky_cfg.h b/sinfoni/sinfo_badsky_cfg.h
new file mode 100644
index 0000000..6f5cf59
--- /dev/null
+++ b/sinfoni/sinfo_badsky_cfg.h
@@ -0,0 +1,120 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*---------------------------------------------------------------------------
+   
+   File name     :    sinfo_badsky_cfg.h
+   Author         :    Juergen Schreiber
+   Created on    :    October 2001
+   Description    :    bad_ini definitions + handling prototypes
+
+ ---------------------------------------------------------------------------*/
+#ifndef SINFO_BADSKY_CFG_H
+#define SINFO_BADSKY_CFG_H
+/*---------------------------------------------------------------------------
+                                   Includes
+ ---------------------------------------------------------------------------*/
+#include <stdlib.h>
+#include "sinfo_globals.h"
+#include <cpl.h>
+/*---------------------------------------------------------------------------
+                                   Defines
+ ---------------------------------------------------------------------------*/
+/*---------------------------------------------------------------------------
+                                   New types
+ ---------------------------------------------------------------------------*/
+/*
+  bad pixels search blackboard container
+
+  This structure holds all information related to the bad pixels search
+  routine. It is used as a container for the flux of ancillary data,
+  computed values, and algorithm status. Pixel flux is separated from
+  the blackboard.
+  */
+
+typedef struct badsky_config {
+/*-------General---------*/
+        char inFile[FILE_NAME_SZ] ; /* file name of the 
+                                       file containing the list of 
+                                       all input frames */
+        char sinfo_dark[FILE_NAME_SZ] ; /* Input sinfo_dark */
+        char outName[FILE_NAME_SZ] ; /* output name of resulting 
+                                        bad pixel mask (fits file)*/
+        char ** framelist ; /* list of frames */
+        int     nframes ; /* number of frames in frame list */
+
+/*------ BadPix ------*/
+        /* factor of noise within which the pixels are used to fit a 
+           straight line to the column intensity */
+        float sigmaFactor ;      
+        /* factor of calculated standard deviation beyond 
+           which the deviation of a pixel value from the 
+           median of the 8 nearest neighbors declares a pixel as bad */
+        float factor ;
+        /* number of iterations of sinfo_median filter */
+        int iterations ;
+        /* percentage of extreme pixel value to reject 
+           when calculating the mean and stdev */
+        float loReject ;
+        float hiReject ;
+        /* pixel coordinate of lower left sinfo_edge of a 
+           rectangle zone from which image statistics are computed */
+        int llx ;
+        int lly ;
+        /* pixel coordinate of upper right sinfo_edge of a rectangle 
+           zone from which image statistics are computed */
+        int urx ;
+        int ury ;
+/*------ Thresh ------*/
+        /* indicates if the values beyond threshold values should be 
+           marked as bad before proceeding 
+           to sinfo_median filtering */
+        int threshInd ;
+        /* factor to the clean standard deviation to define the 
+           threshold deviation from the clean mean */
+        float meanfactor ;
+        /* minimum vlaue of good data */
+        float mincut ;
+        /* maximum vlaue of good data */
+        float maxcut ;
+        /* indicates which method will be used */
+        int methodInd ;
+} badsky_config ;
+/*---------------------------------------------------------------------------
+                               Function prototypes
+ ---------------------------------------------------------------------------*/
+
+/**
+   @name   sinfo_bad_cfg_create()
+   @memo   allocate memory for a bad_cfg struct
+   @return pointer to allocated base bad_cfg structure
+   @note   only the main (base) structure is allocated
+*/
+
+badsky_config * 
+sinfo_badsky_cfg_create(void);
+/**
+   @name  sinfo_bad_cfg_destroy()
+   @memo deallocate all memory associated with a bad_config data structure
+   @param sc   bad_config structure to deallocate
+   @return void 
+*/
+void 
+sinfo_badsky_cfg_destroy(badsky_config * sc);
+
+#endif
diff --git a/sinfoni/sinfo_badsky_ini_by_cpl.c b/sinfoni/sinfo_badsky_ini_by_cpl.c
new file mode 100644
index 0000000..0742700
--- /dev/null
+++ b/sinfoni/sinfo_badsky_ini_by_cpl.c
@@ -0,0 +1,295 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/*----------------------------------------------------------------------------
+   
+   File name    :   sinfo_badsky_ini_by_cpl.c
+   Author       :   Andrea Modigliani
+   Created on   :   Jun 16, 2004
+   Description  :   parse cpl input for the search of static bad pixels
+
+ ---------------------------------------------------------------------------*/
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+/*---------------------------------------------------------------------------
+                                Includes
+ ---------------------------------------------------------------------------*/
+#include <string.h>
+#include "sinfo_badsky_ini_by_cpl.h"
+#include "sinfo_raw_types.h"
+#include "sinfo_pro_types.h"
+#include "sinfo_hidden.h"
+#include "sinfo_globals.h"
+#include "sinfo_functions.h"
+#include "sinfo_file_handling.h"
+/*---------------------------------------------------------------------------
+                    Functions private to this module
+ ---------------------------------------------------------------------------*/
+
+static void  
+parse_section_frames(badsky_config * cfg, cpl_parameterlist* cpl_cfg, 
+cpl_frameset* sof, cpl_frameset** raw, int* status);
+static void 
+parse_section_badpix(badsky_config * cfg, cpl_parameterlist* cpl_cfg);
+static void 
+parse_section_thresh(badsky_config * cfg, cpl_parameterlist* cpl_cfg);
+/**
+ * @addtogroup sinfo_bad_pix_search Bad Pixel Search
+ *
+ * TBD
+ */
+/*---------------------------------------------------------------------------
+                              Function codes
+ ---------------------------------------------------------------------------*/
+/**
+  @name     sinfo_parse_cpl_input_badsky
+  @memo     Parse input from CPL (parameters and set of input frames) 
+            to create a blackboard.
+  @param    config    cpl parameter list
+  @param    sof       cpl frames list
+  @return   1 newly allocated bad_config blackboard structure.
+  @doc      The requested cpl input is parsed and a blackboard object is 
+            created, then updated accordingly. Returns NULL in case of error.
+ */
+
+badsky_config * 
+sinfo_parse_cpl_input_badsky(cpl_parameterlist * cpl_cfg, 
+                                     cpl_frameset* sof,
+                                     cpl_frameset** raw) 
+{
+  badsky_config    *       cfg ;
+  int status = 0;
+
+  cfg = sinfo_badsky_cfg_create();
+  parse_section_badpix   (cfg, cpl_cfg);
+  parse_section_thresh   (cfg, cpl_cfg);
+  parse_section_frames   (cfg, cpl_cfg, sof, raw,&status);
+  if(status>0) {
+    sinfo_msg_error("parsing cpl input");
+    sinfo_badsky_cfg_destroy(cfg);
+    cfg = NULL ;
+    return NULL ;
+  }
+  return cfg ;
+
+}
+
+/**
+  @name     parse_section_frames
+  @memo     Parse input frames 
+  @param    cfg    pointer to badsky_config
+  @param    cpl_cfg    input parameter list
+  @param    sof       cpl frames list
+  @param    raw raw set of frames
+  @param    status    status of operation
+  @return   void
+ */
+
+static void     
+parse_section_frames(badsky_config   * cfg,
+                     cpl_parameterlist  * cpl_cfg,
+                     cpl_frameset * sof,          
+                     cpl_frameset ** raw,
+                     int* status)
+{
+   int                i=0;
+   int                nraw = 0;
+   char *          tag=NULL;
+
+   int  nraw_good = 0;
+   cpl_frame* frame=NULL;
+   cpl_parameter *p;     
+   char spat_res[FILE_NAME_SZ];
+   char lamp_status[FILE_NAME_SZ];
+   char band[FILE_NAME_SZ];
+   int ins_set=0;
+
+   *raw=cpl_frameset_new();
+
+
+   sinfo_contains_frames_type(sof,raw,RAW_SKY);
+   nraw=cpl_frameset_get_size(*raw);
+   if (nraw < 1) {
+      sinfo_msg_error("Too few (%d) raw frames %s  present in"
+             "frameset!Aborting...",nraw,RAW_SKY);
+      (*status)++;
+      return;
+   }
+        
+   /* Removed: get "general:infile" read it, check input sinfo_matrix */
+   /* Allocate structures to go into the blackboard */
+   cfg->framelist     = cpl_malloc(nraw * sizeof(char*));
+
+   /* read input frames */
+   for (i=0 ; i<nraw ; i++) {
+      frame = cpl_frameset_get_frame(*raw,i);
+      tag = (char*)cpl_frame_get_tag(frame) ;
+      if(sinfo_file_exists((char*) cpl_frame_get_filename(frame))==1) 
+    {
+             /* Store file name into framelist */
+             cfg->framelist[i]=cpl_strdup(cpl_frame_get_filename(frame));
+             nraw_good++;
+    }
+   }
+
+   if(nraw_good<1) {
+     sinfo_msg_error("Error: no good raw frame in input, something wrong!");
+     (*status)++;
+     return;
+   }
+
+
+        if(NULL != cpl_frameset_find(sof,PRO_MASTER_DARK)) {
+            frame = cpl_frameset_find(sof,PRO_MASTER_DARK);
+            strcpy(cfg -> sinfo_dark, 
+		   cpl_strdup(cpl_frame_get_filename(frame)));
+         } else {
+            sinfo_msg_warning("Frame %s not found!", PRO_MASTER_DARK);
+         }
+
+   /* Copy relevant information into the blackboard */
+   cfg->nframes         = nraw_good ;
+
+   /* Output */
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_sky.out_filename");
+   strcpy(cfg -> outName, cpl_parameter_get_string(p));
+
+   frame = cpl_frameset_get_frame(*raw,0);
+   sinfo_get_spatial_res(frame,spat_res);
+ 
+
+   switch(sinfo_frame_is_on(frame)) 
+     {
+   case 0: 
+      strcpy(lamp_status,"on");
+      break;
+    case 1: 
+      strcpy(lamp_status,"off");
+      break;
+    case -1:
+      strcpy(lamp_status,"undefined");
+      break;
+    default: 
+      strcpy(lamp_status,"undefined");
+      break;
+     }
+
+   sinfo_get_band(frame,band);
+   sinfo_msg("Spatial resolution: %s lamp status: %s band: %s \n",
+                     spat_res,              lamp_status,    band);
+
+
+   sinfo_get_ins_set(band,&ins_set);
+   return;
+
+}
+
+/**
+  @name     parse_section_badpix
+  @memo     Parse badpixel parameters
+  @param    cfg    pointer to badsky_config
+  @param    cpl_cfg    input parameter list
+  @return   void
+ */
+
+static void     
+parse_section_badpix(badsky_config    * cfg, cpl_parameterlist *   cpl_cfg)
+{
+   cpl_parameter *p;     
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_sky.sigma_factor");
+   cfg -> sigmaFactor = cpl_parameter_get_double(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_sky.method_index");
+   cfg -> methodInd = cpl_parameter_get_int(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_sky.factor");
+   cfg -> factor = cpl_parameter_get_double(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_sky.iterations");
+   cfg -> iterations = cpl_parameter_get_int(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_sky.low_rejection");
+   cfg -> loReject = cpl_parameter_get_double(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_sky.high_rejection");
+   cfg -> hiReject = cpl_parameter_get_double(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_sky.llx");
+   cfg -> llx = cpl_parameter_get_int(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_sky.lly");
+   cfg -> lly = cpl_parameter_get_int(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_sky.urx");
+   cfg -> urx = cpl_parameter_get_int(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_sky.ury");
+   cfg -> ury = cpl_parameter_get_int(p);
+
+}
+
+/**
+  @name     parse_section_thresh
+  @memo     Parse threshold parameters
+  @param    cfg    pointer to badsky_config
+  @param    cpl_cfg    input parameter list
+  @return   void
+ */
+
+static void     
+parse_section_thresh(badsky_config    * cfg, cpl_parameterlist *   cpl_cfg)
+{
+   cpl_parameter *p;     
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_sky.threshold_index");
+   cfg -> threshInd  = cpl_parameter_get_bool(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_sky.mean_factor");
+   cfg -> meanfactor = cpl_parameter_get_double(p);
+
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_sky.min_cut");
+   cfg -> mincut = cpl_parameter_get_double(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_sky.max_cut");
+   cfg -> maxcut = cpl_parameter_get_double(p);
+
+}
+
+/**
+   @name   sinfo_badsky_free()
+   @memo   deallocate all memory associated with a bad_config data structure
+   @param  cfg   pointer to badsky_config structure to deallocate
+   @return void 
+*/
+
+void
+sinfo_badsky_free(badsky_config * cfg)
+{  
+  cpl_free(cfg->framelist);
+  sinfo_badsky_cfg_destroy(cfg);
+ 
+  return;
+
+}
+/**@}*/
diff --git a/sinfoni/sinfo_badsky_ini_by_cpl.h b/sinfoni/sinfo_badsky_ini_by_cpl.h
new file mode 100644
index 0000000..b96e960
--- /dev/null
+++ b/sinfoni/sinfo_badsky_ini_by_cpl.h
@@ -0,0 +1,50 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+   
+   File name    :   sinfo_badnorm_ini_by_cpl.h
+   Author       :   Andrea Modigliani
+   Created on   :   Jun 16, 2004
+   Description  :   parse cpl input for the search for static bad pixels
+
+ ---------------------------------------------------------------------------*/
+#ifndef SINFO_BADSKY_INI_BY_CPL_H
+#define SINFO_BADSKY_INI_BY_CPL_H
+/*---------------------------------------------------------------------------
+                                Includes
+---------------------------------------------------------------------------*/
+#include <cpl.h>
+#include "sinfo_badsky_cfg.h"
+#include "sinfo_msg.h"
+/*---------------------------------------------------------------------------
+                                Defines
+---------------------------------------------------------------------------*/
+/*----------------------------------------------------------------------------
+                             Function prototypes 
+ ---------------------------------------------------------------------------*/
+
+badsky_config * 
+sinfo_parse_cpl_input_badsky(cpl_parameterlist * cpl_cfg, 
+                             cpl_frameset* sof, 
+                             cpl_frameset** raw);
+
+void 
+sinfo_badsky_free(badsky_config * cfg);
+
+#endif
diff --git a/sinfoni/sinfo_balance.c b/sinfoni/sinfo_balance.c
new file mode 100644
index 0000000..7d9455a
--- /dev/null
+++ b/sinfoni/sinfo_balance.c
@@ -0,0 +1,145 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+#include "sinfo_solve_poly_root.h"
+
+
+#define RADIX 2
+#define RADIX2 (RADIX*RADIX)
+
+/**@{*/
+/**
+ * @defgroup sinfo_balance To be removed
+ *
+ * TBD
+ */
+
+/**
+ at name sinfo_balance_companion_matrix
+ at brief TBD
+ at param m matrix
+ at param nc size
+ at return TBD
+*/
+void
+sinfo_balance_companion_matrix (double *m, size_t nc)
+{
+  int not_converged = 1;
+
+  double row_norm = 0;
+  double col_norm = 0;
+
+  while (not_converged)
+    {
+      size_t i, j;
+      double g, f, s;
+
+      not_converged = 0;
+
+      for (i = 0; i < nc; i++)
+    {
+      /* column norm, excluding the diagonal */
+
+      if (i != nc - 1)
+        {
+          col_norm = fabs (MAT (m, i + 1, i, nc));
+        }
+      else
+        {
+          col_norm = 0;
+
+          for (j = 0; j < nc - 1; j++)
+        {
+          col_norm += fabs (MAT (m, j, nc - 1, nc));
+        }
+        }
+
+      /* row norm, excluding the diagonal */
+
+      if (i == 0)
+        {
+          row_norm = fabs (MAT (m, 0, nc - 1, nc));
+        }
+      else if (i == nc - 1)
+        {
+          row_norm = fabs (MAT (m, i, i - 1, nc));
+        }
+      else
+        {
+          row_norm = (fabs (MAT (m, i, i - 1, nc)) 
+                          + fabs (MAT (m, i, nc - 1, nc)));
+        }
+
+      if (col_norm == 0 || row_norm == 0)
+        {
+          continue;
+        }
+
+      g = row_norm / RADIX;
+      f = 1;
+      s = col_norm + row_norm;
+
+      while (col_norm < g)
+        {
+          f *= RADIX;
+          col_norm *= RADIX2;
+        }
+
+      g = row_norm * RADIX;
+
+      while (col_norm > g)
+        {
+          f /= RADIX;
+          col_norm /= RADIX2;
+        }
+
+      if ((row_norm + col_norm) < 0.95 * s * f)
+        {
+          not_converged = 1;
+
+          g = 1 / f;
+
+          if (i == 0)
+        {
+          MAT (m, 0, nc - 1, nc) *= g;
+        }
+          else
+        {
+          MAT (m, i, i - 1, nc) *= g;
+          MAT (m, i, nc - 1, nc) *= g;
+        }
+
+          if (i == nc - 1)
+        {
+          for (j = 0; j < nc; j++)
+            {
+              MAT (m, j, i, nc) *= f;
+            }
+        }
+          else
+        {
+          MAT (m, i + 1, i, nc) *= f;
+        }
+        }
+    }
+    }
+}
+/**@}*/
diff --git a/sinfoni/sinfo_baryvel.c b/sinfoni/sinfo_baryvel.c
new file mode 100644
index 0000000..b0ea20e
--- /dev/null
+++ b/sinfoni/sinfo_baryvel.c
@@ -0,0 +1,1110 @@
+/*                                                                            *
+ *   This file is part of the ESO SINFONI Pipeline                            *
+ *   Copyright (C) 2004,2005 European Southern Observatory                    *
+ *                                                                            *
+ *   This library is free software; you can redistribute it and/or modify     *
+ *   it under the terms of the GNU General Public License as published by     *
+ *   the Free Software Foundation; either version 2 of the License, or        *
+ *   (at your option) any later version.                                      *
+ *                                                                            *
+ *   This program is distributed in the hope that it will be useful,          *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of           *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
+ *   GNU General Public License for more details.                             *
+ *                                                                            *
+ *   You should have received a copy of the GNU General Public License        *
+ *   along with this program; if not, write to the Free Software              *
+ *   Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA     *
+ *                                                                            */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2012/03/02 08:42:20 $
+ * $Revision: 1.3 $
+ * $Name: sinfo-2_3_2 $
+ * $Log: sinfo_baryvel.c,v $
+ * Revision 1.3  2012/03/02 08:42:20  amodigli
+ * fixed some typos on doxygen
+ *
+ * Revision 1.2  2009/04/28 11:42:18  amodigli
+ * now return cpl_error_code
+ *
+ * Revision 1.1  2009/01/02 08:27:58  amodigli
+ * added to repository
+ *
+ * Revision 1.8  2007/06/06 08:17:33  amodigli
+ * replace tab with 4 spaces
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+
+/**@{*/
+/*---------------------------------------------------------------------------*/
+/**
+ * @defgroup sinfo_baryvel    Velocity correction
+ *
+ * Compute barycentric, heliocentric velocity corrections
+ *
+ * The code in this source file is a 1-to-1 translation of MIDAS COMPUT/BARYCOR
+ * as defined in /prim/general/src/compxy.for (only the necessary parts were
+ * translated). 
+ * The code is not meant to be particularly readable/maintainable. 
+ * To understand the computation the best starting point is probably
+ * P. Stumpff, A&A Suppl. Ser. 41, pp. 1-8 (1980)
+ *
+ */
+/*---------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+  Includes
+  ---------------------------------------------------------------------------*/
+
+#include <sinfo_baryvel.h>
+
+#include <sinfo_pfits.h>
+#include <sinfo_utils.h>
+#include <sinfo_error.h>
+#include <sinfo_msg.h>
+#include <sinfo_functions.h>
+
+#include <cpl.h>
+
+#include <math.h>
+
+#define H_GEOLAT "ESO TEL GEOLAT"
+#define H_GEOLON "ESO TEL GEOLON"
+#define H_UTC "UTC"
+
+/*-----------------------------------------------------------------------------
+  Local functions
+  ---------------------------------------------------------------------------*/
+
+static double sinfo_pfits_get_geolat(const cpl_propertylist * plist);
+static double sinfo_pfits_get_geolon(const cpl_propertylist * plist);
+static double sinfo_pfits_get_utc(const cpl_propertylist * plist);
+
+
+
+static void deg2dms(double in_val, 
+		    double *degs,
+		    double *minutes,
+		    double *seconds);
+
+static void deg2hms(double in_val, 
+		    double *hour,
+		    double *min,
+		    double *sec);
+
+static void compxy(double inputr[19], char inputc[4],
+		   double outputr[4],
+		   double utr, double mod_juldat);
+
+static void barvel(double DJE, double DEQ,
+		   double DVELH[4], double DVELB[4]);
+
+
+
+
+/*--------------------------------------------------------------------------*/
+
+/*--------------------------------------------------------------------------*/
+/**
+  @brief    Find out the telescope latitude
+  @param    plist       Header to read from
+  @return   The requested value, or undefined on error
+ */
+/*--------------------------------------------------------------------------*/
+static double sinfo_pfits_get_geolat(const cpl_propertylist * plist)
+{
+    double returnvalue = 0;
+    
+    check(returnvalue=cpl_propertylist_get_double(plist, H_GEOLAT), 
+       "Error reading keyword '%s'", H_GEOLAT);
+    
+  cleanup:
+    return returnvalue;
+}
+
+/*--------------------------------------------------------------------------*/
+/**
+  @brief    Find out the telescope longitude
+  @param    plist       Header to read from
+  @return   The requested value, or undefined on error
+ */
+/*--------------------------------------------------------------------------*/
+static double sinfo_pfits_get_geolon(const cpl_propertylist * plist)
+{
+    double returnvalue = 0;
+
+    check(returnvalue=cpl_propertylist_get_double(plist, H_GEOLON), 
+       "Error reading keyword '%s'", H_GEOLON);
+      
+  cleanup:
+    return returnvalue;
+}
+
+
+
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Find out the observation time
+  @param    plist       Header to read from
+  @return   The requested value, or undefined on error
+ */
+/*---------------------------------------------------------------------------*/
+static double sinfo_pfits_get_utc(const cpl_propertylist * plist)
+{
+    double returnvalue = 0;
+
+    check(returnvalue=cpl_propertylist_get_double(plist, H_UTC), 
+       "Error reading keyword '%s'", H_UTC);
+     
+  cleanup:
+    return returnvalue;
+}
+
+
+
+#if 0   /* Not used / needed.
+	   We simply get the julian date from the input FITS header */
+
+//      SUBROUTINE JULDAT(INDATE,UTR,JD)
+//C++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+//C
+//C.IDENTIFICATION
+//C  FORTRAN subroutine                    JULDAT     version 1.0       870102
+//C  original coding:                      D. Gillet        ESO - Garching
+//C  variables renamed and restructured:   D. Baade         ST-ECF, Garching
+//C
+//C.KEYWORDS
+//C  geocentric Julian date
+//C
+//C.PURPOSE
+//C  calculate geocentric Julian date for any civil date (time in UT)
+//C
+//C.ALGORITHM
+//C adapted from MEEUS J.,1980, ASTRONOMICAL FORMULAE FOR CALCULATORS
+//C
+//C.INPUT/OUTPUT
+//C the following are passed from and to the calling program:
+//C  INDATE(3)    :         civil date as year,month,day OR year.fraction
+//C  UT           :         universal time expressed in real hours
+//C  JD           :         real geocentric Julian date
+//C
+//C.REVISIONS
+//C made to accept also REAL dates         D. Baade             910408
+//C
+//C---------------------------------------------------------------------------
+//C
+
+static void 
+juldat(double *INDATE,
+       double UTR,
+       double *JD)
+{
+  double UT;
+
+  int DATE[4];
+
+  UT=UTR / 24.0;
+
+  /*
+    CHECK FORMAT OF DATE: may be either year,month,date OR year.fraction,0,0 
+    (Note that the fraction of the year must NOT include fractions of a day.)
+    For all other formats exit and terminate also calling command sequence.
+  
+    IF ((INDATE(1)-INT(INDATE(1))).GT.1.0E-6) THEN 
+    IF ((INDATE(2).GT.1.0E-6).OR.(INDATE(3).GT.1.0E-6)) 
+    +       CALL   STETER(1,'Error: Date was entered in wrong format.')
+
+    copy date input buffer copy to other buffer so that calling program 
+    does not notice any changes
+
+    FIRST CASE: format was year.fraction
+
+    DATE(1)=INT(INDATE(1))
+    FRAC=INDATE(1)-DATE(1)
+    DATE(2)=1
+    DATE(3)=1
+    ELSE
+  
+    SECOND CASE: format was year,month,day
+  */
+
+  DATE[1]=sinfo_round_double(INDATE[1]);
+
+  FRAC = 0;
+
+  DATE[2]=sinfo_round_double(INDATE[2]);
+
+  DATE[3]=sinfo_round_double(INDATE[3]);
+
+  if ((DATE[2] == 0) &&  (DATE[3] == 0)) {
+
+    DATE[2]=1;
+
+    DATE[3]=1;
+
+  }
+
+  /*
+    from here on, the normal procedure applies which is based on the 
+    format year,month,day:
+  */
+  if (DATE[2] > 2) {
+    YP=DATE[1];
+    P=DATE[2];
+  } else {
+    YP=DATE[1]-1;
+    P=DATE(2)+12.0;
+  }
+
+  C = DATE[1] + DATE[2]*1.E-2 + DATE[3]*1.E-4 + UT*1.E-6;
+
+  if (C  >   1582.1015E0) {
+    IA=(int) (YP/100.D0);
+    A=IA;
+    IB=2-IA+((int)(A/4.D0));
+  } else {
+    IB=0;
+  }
+
+  *JD = ((int) (365.25E0*YP)) + ((int)(30.6001D0*(P+1.D0))) + DATE[3] + UT
+    + IB + 1720994.5E0;
+
+  /*
+    finally, take into account fraction of year (if any), respect leap
+    year conventions
+  */
+  if (FRAC > 1.0E-6) {
+    ND=365;
+
+    IF (C >= 1582.1015E0) {
+      IC = DATE[1] % 4;
+      if (IC == 0) {
+        ND=366;
+        IC = DATE[1] % 100;
+        if (IC == 0) {
+	  IC = DATE[1] % 400;
+	  if (IC != 0) ND=365;
+        }
+      }
+    }
+
+    if (fabs(FRAC*ND-sinfo_round_double(FRAC*ND)) > 0.3) {
+      sinfo_msg_warning("Fraction of year MAY not correspond to "
+			"integer number of days");
+    }
+
+    *JD = *JD+sinfo_round_double(FRAC*ND);
+  }
+
+  return;
+}
+
+#endif
+
+/** To get the exact same behaviour as MIDAS this should
+    be define'd to 1. (Fixing it does not seem to make a
+    difference in the resulting numbers but do it anyway) */
+#define MIDAS_BUG 0
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    convert hours -> degrees, minutes, seconds
+   @param    in_val     the value to convert
+   @param    hours      (output) hours (integer). 360 degrees correspond to 24 h
+   @param    minutes    (output) minutes (integer)
+   @param    seconds    (output) seconds (fractional)
+*/
+/*---------------------------------------------------------------------------*/
+
+static void
+deg2hms(double in_val, 
+	double *hours,
+	double *minutes,
+	double *seconds)
+{
+  double tmp;
+  char sign;
+  if (in_val < 0) {
+    in_val = fabs(in_val);
+    sign = '-';
+  }
+  else {
+    sign = '+';
+  }
+
+  tmp   = in_val / 15;
+
+  /* takes the integer part = hours */
+#if MIDAS_BUG
+  *hours= sinfo_round_double(tmp);
+#else
+  *hours= (int) tmp;
+#endif
+
+  /* takes the mantissa */
+  tmp   = tmp - *hours;
+  /* converts the mantissa in minutes */
+  tmp   = tmp * 60;
+
+  /* takes the integer part = minutes */
+#if MIDAS_BUG
+  *minutes= sinfo_round_double(tmp);
+#else
+  *minutes= (int) tmp;
+#endif
+
+  /* takes the mantissa */
+  tmp   = tmp - *minutes;
+
+  /* converts the mantissa in seconds = seconds (with decimal) */
+  *seconds= tmp * 60;
+
+  /* Rather than returning it explicitly, just  attach sign to hours */
+  if (sign == '-') *hours = -(*hours);
+
+  return;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    convert degrees -> degrees, minutes, seconds
+   @param    in_val     the value to convert
+   @param    degs       (output) degrees (integer)
+   @param    minutes    (output) minutes (integer)
+   @param    seconds    (output) seconds (fractional)
+*/
+/*---------------------------------------------------------------------------*/
+
+static void
+deg2dms(double in_val, 
+	double *degs,
+	double *minutes,
+	double *seconds)
+{
+  deg2hms(in_val*15, degs, minutes, seconds);
+}
+
+
+
+
+
+/* @cond Convert FORTRAN indexing -> C indexing */
+#define DCFEL(x,y)  dcfel[y][x]
+#define DCFEPS(x,y) dcfeps[y][x]
+#define CCSEL(x,y)  ccsel[y][x]
+#define DCARGS(x,y) dcargs[y][x]
+#define CCAMPS(x,y) ccamps[y][x]
+#define CCSEC(x,y)  ccsec[y][x]
+#define DCARGM(x,y) dcargm[y][x]
+#define CCAMPM(x,y) ccampm[y][x]
+#define DCEPS(x)    dceps[x]
+#define FORBEL(x)   forbel[x]
+#define SORBEL(x)   sorbel[x]
+#define SN(x)       sn[x]
+#define SINLP(x)    sinlp[x]
+#define COSLP(x)    coslp[x]
+#define CCPAMV(x)   ccpamv[x]
+/* @endcond */
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    compute rectangular heliocentric and barycentric components of
+   the earth's orbital velocity
+   @param    DJE        Julian date
+   @param    DEQ        ???
+   @param    DVELH      (output) heliocentric velocity
+   @param    DVELB      (output) barycentric velocity
+
+   REFERENCE : STUMPFF P. ASTRON. ASTOPHYS. SUPPL. 41,1,1980
+   MODIFICATION : D. GILLET 1983-9-15
+
+*/
+/*---------------------------------------------------------------------------*/
+
+
+static 
+void barvel(double DJE, double DEQ,
+	    double DVELH[4], double DVELB[4])
+{
+  double sn[5];
+  double DT,DTL,DTSQ,DLOCAL;
+  double DRD,DRLD;
+  double DXBD,DYBD,DZBD,DZHD,DXHD,DYHD;
+  double DYAHD,DZAHD,DYABD,DZABD;
+  double DML,DEPS,PHI,PHID,PSID,DPARAM,PARAM;
+  double PLON,POMG,PECC;
+  double PERTL,PERTLD,PERTRD,PERTP,PERTR,PERTPD;
+  double SINA,TL;
+  double COSA,ESQ;
+  double A,B,F,SINF,COSF,T,TSQ,TWOE,TWOG;
+
+  double DPSI,D1PDRO,DSINLS;
+  double DCOSLS,DSINEP,DCOSEP;
+  double forbel[8], sorbel[18], sinlp[5], coslp[5];
+  double SINLM,COSLM,SIGMA;
+  int IDEQ,K,N;
+
+  double *E = sorbel + 1 - 1;
+  double *G = forbel + 1 - 1;
+  double DC2PI = 6.2831853071796E0;
+  double CC2PI = 6.283185;             /* ??? */
+
+  double DC1 = 1.0;
+  double DCT0 = 2415020.0E0;
+  double DCJUL = 36525.0E0;
+
+  double dcfel[][4] = { {0, 0, 0, 0},
+			{0, 1.7400353E+00, 6.2833195099091E+02, 5.2796E-06},
+			{0, 6.2565836E+00, 6.2830194572674E+02,-2.6180E-06},
+			{0, 4.7199666E+00, 8.3997091449254E+03,-1.9780E-05},
+			{0, 1.9636505E-01, 8.4334662911720E+03,-5.6044E-05},
+			{0, 4.1547339E+00, 5.2993466764997E+01, 5.8845E-06},
+			{0, 4.6524223E+00, 2.1354275911213E+01, 5.6797E-06},
+			{0, 4.2620486E+00, 7.5025342197656E+00, 5.5317E-06},
+			{0, 1.4740694E+00, 3.8377331909193E+00, 5.6093E-06} };
+    
+  double dceps[4] = {0, 4.093198E-01,-2.271110E-04,-2.860401E-08};
+
+  double ccsel[][4] = { {0, 0, 0, 0},
+			{0, 1.675104E-02, -4.179579E-05, -1.260516E-07},
+			{0, 2.220221E-01,  2.809917E-02,  1.852532E-05},
+			{0, 1.589963E+00,  3.418075E-02,  1.430200E-05},
+			{0, 2.994089E+00,  2.590824E-02,  4.155840E-06},
+			{0, 8.155457E-01,  2.486352E-02,  6.836840E-06},
+			{0, 1.735614E+00,  1.763719E-02,  6.370440E-06},
+			{0, 1.968564E+00,  1.524020E-02, -2.517152E-06},
+			{0, 1.282417E+00,  8.703393E-03,  2.289292E-05},
+			{0, 2.280820E+00,  1.918010E-02,  4.484520E-06},
+			{0, 4.833473E-02,  1.641773E-04, -4.654200E-07},
+			{0, 5.589232E-02, -3.455092E-04, -7.388560E-07},
+			{0, 4.634443E-02, -2.658234E-05,  7.757000E-08},
+			{0, 8.997041E-03,  6.329728E-06, -1.939256E-09},
+			{0, 2.284178E-02, -9.941590E-05,  6.787400E-08},
+			{0, 4.350267E-02, -6.839749E-05, -2.714956E-07},
+			{0, 1.348204E-02,  1.091504E-05,  6.903760E-07},
+			{0, 3.106570E-02, -1.665665E-04, -1.590188E-07} };
+
+
+  double dcargs[][3] = { {0, 0, 0},
+			 {0, 5.0974222E+00, -7.8604195454652E+02},
+			 {0, 3.9584962E+00, -5.7533848094674E+02},
+			 {0, 1.6338070E+00, -1.1506769618935E+03},
+			 {0, 2.5487111E+00, -3.9302097727326E+02},
+			 {0, 4.9255514E+00, -5.8849265665348E+02},
+			 {0, 1.3363463E+00, -5.5076098609303E+02},
+			 {0, 1.6072053E+00, -5.2237501616674E+02},
+			 {0, 1.3629480E+00, -1.1790629318198E+03},
+			 {0, 5.5657014E+00, -1.0977134971135E+03},
+			 {0, 5.0708205E+00, -1.5774000881978E+02},
+			 {0, 3.9318944E+00,  5.2963464780000E+01},
+			 {0, 4.8989497E+00,  3.9809289073258E+01},
+			 {0, 1.3097446E+00,  7.7540959633708E+01},
+			 {0, 3.5147141E+00,  7.9618578146517E+01},
+			 {0, 3.5413158E+00, -5.4868336758022E+02} };
+
+
+  double ccamps[][6] = 
+    {{0, 0, 0, 0, 0, 0},
+     {0, -2.279594E-5,  1.407414E-5,  8.273188E-6,  1.340565E-5, -2.490817E-7},
+     {0, -3.494537E-5,  2.860401E-7,  1.289448E-7,  1.627237E-5, -1.823138E-7},
+     {0,  6.593466E-7,  1.322572E-5,  9.258695E-6, -4.674248E-7, -3.646275E-7},
+     {0,  1.140767E-5, -2.049792E-5, -4.747930E-6, -2.638763E-6, -1.245408E-7},
+     {0,  9.516893E-6, -2.748894E-6, -1.319381E-6, -4.549908E-6, -1.864821E-7},
+     {0,  7.310990E-6, -1.924710E-6, -8.772849E-7, -3.334143E-6, -1.745256E-7},
+     {0, -2.603449E-6,  7.359472E-6,  3.168357E-6,  1.119056E-6, -1.655307E-7},
+     {0, -3.228859E-6,  1.308997E-7,  1.013137E-7,  2.403899E-6, -3.736225E-7},
+     {0,  3.442177E-7,  2.671323E-6,  1.832858E-6, -2.394688E-7, -3.478444E-7},
+     {0,  8.702406E-6, -8.421214E-6, -1.372341E-6, -1.455234E-6, -4.998479E-8},
+     {0, -1.488378E-6, -1.251789E-5,  5.226868E-7, -2.049301E-7,  0.0E0},
+     {0, -8.043059E-6, -2.991300E-6,  1.473654E-7, -3.154542E-7,  0.0E0},
+     {0,  3.699128E-6, -3.316126E-6,  2.901257E-7,  3.407826E-7,  0.0E0},
+     {0,  2.550120E-6, -1.241123E-6,  9.901116E-8,  2.210482E-7,  0.0E0},
+     {0, -6.351059E-7,  2.341650E-6,  1.061492E-6,  2.878231E-7,  0.0E0}};
+
+
+
+  double CCSEC3 = -7.757020E-08;
+
+  double ccsec[][4] = { {0, 0, 0, 0},
+			{0, 1.289600E-06,  5.550147E-01,  2.076942E+00},
+			{0, 3.102810E-05,  4.035027E+00,  3.525565E-01},
+			{0, 9.124190E-06,  9.990265E-01,  2.622706E+00},
+			{0, 9.793240E-07,  5.508259E+00,  1.559103E+01}};
+
+  double DCSLD =  1.990987E-07, CCSGD = 1.990969E-07;
+
+  double CCKM = 3.122140E-05, CCMLD = 2.661699E-06, CCFDI = 2.399485E-07;
+
+  double dcargm[][3] = {{0, 0, 0},
+			{0, 5.1679830E+00,  8.3286911095275E+03},
+			{0, 5.4913150E+00, -7.2140632838100E+03},
+			{0, 5.9598530E+00,  1.5542754389685E+04}};
+
+  double ccampm[][5] = {{0, 0, 0, 0, 0},
+			{0,  1.097594E-01,  2.896773E-07,  5.450474E-02,  1.438491E-07},
+			{0, -2.223581E-02,  5.083103E-08,  1.002548E-02, -2.291823E-08},
+			{0,  1.148966E-02,  5.658888E-08,  8.249439E-03,  4.063015E-08} };
+
+  double ccpamv[] = {0, 8.326827E-11, 1.843484E-11, 1.988712E-12, 1.881276E-12};
+
+  double DC1MME = 0.99999696E0;
+
+  IDEQ=DEQ;
+
+  DT=(DJE-DCT0)/DCJUL;
+
+  T=DT;
+
+  DTSQ=DT*DT;
+
+  TSQ=DTSQ;
+
+  DML = 0;  /* Suppress warning */
+  for (K = 1; K <= 8; K++) {
+
+    DLOCAL=fmod(DCFEL(1,K)+DT*DCFEL(2,K)+DTSQ*DCFEL(3,K),DC2PI);
+
+    if (K == 1)  DML=DLOCAL;
+
+    if (K != 1)  FORBEL(K-1)=DLOCAL;
+  }
+
+  DEPS=fmod(DCEPS(1)+DT*DCEPS(2)+DTSQ*DCEPS(3), DC2PI);
+
+  for (K = 1; K <= 17; K++) {
+
+    SORBEL(K)=fmod(CCSEL(1,K)+T*CCSEL(2,K)+TSQ*CCSEL(3,K),CC2PI);
+
+  }
+
+  for (K = 1; K <= 4; K++) {
+
+    A=fmod(CCSEC(2,K)+T*CCSEC(3,K),CC2PI);
+
+    SN(K)=sin(A);
+
+  }
+
+  PERTL =  CCSEC(1,1)          *SN(1) +CCSEC(1,2)*SN(2)
+    +(CCSEC(1,3)+T*CCSEC3)*SN(3) +CCSEC(1,4)*SN(4);
+
+  PERTLD=0.0;
+  PERTR =0.0;
+  PERTRD=0.0;
+
+  for (K = 1; K <= 15; K++) {
+
+    A=fmod(DCARGS(1,K)+DT*DCARGS(2,K), DC2PI);
+
+    COSA=cos(A);
+
+    SINA=sin(A);
+
+    PERTL =PERTL+CCAMPS(1,K)*COSA+CCAMPS(2,K)*SINA;
+
+    PERTR =PERTR+CCAMPS(3,K)*COSA+CCAMPS(4,K)*SINA;
+
+    if (K >= 11) break;
+
+    PERTLD=PERTLD+(CCAMPS(2,K)*COSA-CCAMPS(1,K)*SINA)*CCAMPS(5,K);
+
+    PERTRD=PERTRD+(CCAMPS(4,K)*COSA-CCAMPS(3,K)*SINA)*CCAMPS(5,K);
+
+  }
+
+
+  ESQ=E[1]*E[1];
+
+  DPARAM=DC1-ESQ;
+
+  PARAM=DPARAM;
+
+  TWOE=E[1]+E[1];
+
+  TWOG=G[1]+G[1];
+
+  PHI=TWOE*((1.0-ESQ*0.125  )*sin(G[1])+E[1]*0.625  *sin(TWOG)
+	    +ESQ*0.5416667  *sin(G[1]+TWOG) ) ;
+    
+  F=G[1]+PHI;
+
+  SINF=sin(F);
+
+  COSF=cos(F);
+
+  DPSI=DPARAM/(DC1+E[1]*COSF);
+
+  PHID=TWOE*CCSGD*((1.0+ESQ*1.5  )*COSF+E[1]*(1.25  -SINF*SINF*0.5  ));
+
+  PSID=CCSGD*E[1]*SINF/sqrt(PARAM);
+
+  D1PDRO=(DC1+PERTR);
+
+  DRD=D1PDRO*(PSID+DPSI*PERTRD);
+
+  DRLD=D1PDRO*DPSI*(DCSLD+PHID+PERTLD);
+
+  DTL=fmod(DML+PHI+PERTL, DC2PI);
+
+  DSINLS=sin(DTL);
+
+  DCOSLS=cos(DTL);
+
+  DXHD = DRD*DCOSLS-DRLD*DSINLS;
+
+  DYHD = DRD*DSINLS+DRLD*DCOSLS;
+
+  PERTL =0.0;
+
+  PERTLD=0.0;
+
+  PERTP =0.0;
+
+  PERTPD=0.0;
+
+  for (K = 1; K <= 3; K++) {
+    A=fmod(DCARGM(1,K)+DT*DCARGM(2,K), DC2PI);
+
+    SINA  =sin(A);
+
+    COSA  =cos(A);
+
+    PERTL =PERTL +CCAMPM(1,K)*SINA;
+
+    PERTLD=PERTLD+CCAMPM(2,K)*COSA;
+
+    PERTP =PERTP +CCAMPM(3,K)*COSA;
+
+    PERTPD=PERTPD-CCAMPM(4,K)*SINA;
+  }
+    
+  TL=FORBEL(2)+PERTL;
+
+  SINLM=sin(TL);
+
+  COSLM=cos(TL);
+
+  SIGMA=CCKM/(1.0+PERTP);
+
+  A=SIGMA*(CCMLD+PERTLD);
+
+  B=SIGMA*PERTPD;
+
+  DXHD=DXHD+A*SINLM+B*COSLM;
+
+  DYHD=DYHD-A*COSLM+B*SINLM;
+
+  DZHD=    -SIGMA*CCFDI* cos(FORBEL(3));
+
+  DXBD=DXHD*DC1MME;
+
+  DYBD=DYHD*DC1MME;
+
+  DZBD=DZHD*DC1MME;
+
+  for (K = 1; K <= 4; K++) {
+
+    PLON=FORBEL(K+3);
+
+    POMG=SORBEL(K+1);
+
+    PECC=SORBEL(K+9);
+
+    TL=fmod(PLON+2.0*PECC* sin(PLON-POMG), CC2PI);
+
+    SINLP(K)= sin(TL);
+
+    COSLP(K)= cos(TL);
+
+    DXBD=DXBD+CCPAMV(K)*(SINLP(K)+PECC*sin(POMG));
+
+    DYBD=DYBD-CCPAMV(K)*(COSLP(K)+PECC*cos(POMG));
+
+    DZBD=DZBD-CCPAMV(K)*SORBEL(K+13)*cos(PLON-SORBEL(K+5));
+
+  }
+    
+  DCOSEP=cos(DEPS);
+  DSINEP=sin(DEPS);
+  DYAHD=DCOSEP*DYHD-DSINEP*DZHD;
+  DZAHD=DSINEP*DYHD+DCOSEP*DZHD;
+  DYABD=DCOSEP*DYBD-DSINEP*DZBD;
+  DZABD=DSINEP*DYBD+DCOSEP*DZBD;
+
+  DVELH[1]=DXHD;
+  DVELH[2]=DYAHD;
+  DVELH[3]=DZAHD;
+
+  DVELB[1]=DXBD;
+  DVELB[2]=DYABD;
+  DVELB[3]=DZABD;
+
+  for (N = 1; N <= 3; N++) {
+    DVELH[N]=DVELH[N]*1.4959787E8;
+    DVELB[N]=DVELB[N]*1.4959787E8;
+  }
+  return;
+}
+
+
+
+
+/*--------------------------------------------------------------------------*/
+/**
+   @brief    Compute velocity correction
+   @param    inputr     input parameters
+   @param    inputc     input parameters
+   @param    outputr    output parameters
+   @param    utr        observation time (seconds)
+   @param    mod_juldat observation modified julian date
+
+   INPUTR/R/1/3    date: year,month,day
+   INPUTR/R/4/3    universal time: hour,min,sec
+   INPUTR/R/7/3    EAST longitude of observatory: degree,min,sec  !! NOTE
+   INPUTR/R/10/3   latitude of observatory: degree,min,sec
+   INPUTR/R/13/3   right ascension: hour,min,sec
+   INPUTR/R/16/3   declination: degree,min,sec
+   OUTPUTD/D/1/1   barycentric correction to time (days)
+   OUTPUTD/D/2/1   heliocentric correction to time (days)
+   OUTPUTR/R/1/1   barycentric correction to radial velocity (km/s)
+   OUTPUTR/R/2/1   heliocentric correction to radial velocity (km/s)
+   OUTPUTR/R/3/1   diurnal rotation of the earth
+
+*/
+/*--------------------------------------------------------------------------*/
+static void
+compxy(double inputr[19], char inputc[4],
+       double outputr[4],
+       double utr, double mod_juldat)
+{
+  double STR;
+  double t0, dl, theta0, pe, st0hg, stg;
+  double jd, jd0h;
+  double dvelb[4], dvelh[4];
+  double alp, del, beov, berv, EDV;
+  double HAR, phi, heov, herv;
+  double *rbuf;
+  char inpsgn[4];
+  double *olong, *olat, *alpha, *delta;
+  char signs[] = "+++";
+  rbuf = inputr;
+  inpsgn[1] = inputc[1];
+  inpsgn[2] = inputc[2];
+  inpsgn[3] = inputc[3];
+  olong = rbuf + 7 - 1;
+  olat  = rbuf + 10 - 1;
+  alpha = rbuf + 13 - 1;
+  delta = rbuf + 16 - 1;
+  // ... convert UT to real hours, calculate Julian date
+  /* We know this one already but convert seconds -> hours */
+  utr /= 3600;
+
+
+  jd = mod_juldat + 2400000.5;
+  
+  // ... likewise convert longitude and latitude of observatory to real hours
+  // ... and degrees, respectively; take care of signs
+  // ... NOTE: east longitude is assumed for input !!
+
+  if (olong[1] < 0 || olong[2] < 0 ||
+      olong[3] < 0 || inpsgn[1] == '-') {
+    signs[1] = '-';
+    olong[1] = fabs(olong[1]);
+    olong[2] = fabs(olong[2]);
+    olong[3] = fabs(olong[3]);
+  }
+  dl = olong[1]+olong[2]/60.  +olong[3]/3600.;
+  if (signs[1]   == '-') dl = -dl;
+  dl = -dl*24.  /360.;
+
+  if (olat[1] < 0 || olat[2] < 0 ||
+      olat[3] < 0 || inpsgn[2] == '-') {
+    signs[2] = '-';
+ 
+    olat[1] = fabs(olat[1]);
+    olat[2] = fabs(olat[2]);
+    olat[3] = fabs(olat[3]);
+
+  }
+
+  phi = olat[1]+olat[2]/60.  +olat[3]/3600.;
+
+  if (signs[2]   == '-') phi = -phi;
+
+  phi = phi*M_PI/180. ;
+
+  // ... convert right ascension and declination to real radians
+
+  alp = (alpha[1]*3600. +alpha[2]*60. +alpha[3])*M_PI/(12.  *3600.  );
+
+  if (delta[1] < 0 || delta[2] < 0 ||
+      delta[3] < 0 || inpsgn[3] == '-') {
+
+    signs[3] = '-';
+
+    delta[1] = fabs(delta[1]);
+    delta[2] = fabs(delta[2]);
+    delta[3] = fabs(delta[3]);
+
+  }
+
+  del = (delta[1]*3600.0  + delta[2]*60.   + delta[3])
+    * M_PI/(3600. *180. );
+
+
+
+  if (signs[3]   == '-') del = - del;
+
+  // ... calculate earth's orbital velocity in rectangular coordinates X,Y,Z
+  // ... for both heliocentric and barycentric frames (DVELH, DVELB)
+  // ... Note that setting the second argument of BARVEL to zero as done below
+  // ... means that the input coordinates will not be corrected for precession.
+
+
+  barvel(jd, 0.0, dvelh, dvelb);
+
+  // ... with the rectangular velocity components known, the respective projections
+  // ... HEOV and BEOV on a given line of sight (ALP,DEL) can be determined:
+
+  // ... REFERENCE: THE ASTRONOMICAL ALMANAC 1982 PAGE:B17
+
+  beov =
+    dvelb[1]*cos(alp)*cos(del)+
+    dvelb[2]*sin(alp)*cos(del)+
+    dvelb[3]*sin(del);
+      
+  heov =
+    dvelh[1]*cos(alp)*cos(del)+
+    dvelh[2]*sin(alp)*cos(del)+
+    dvelh[3]*sin(del);
+      
+
+  // ... For determination also of the contribution due to the diurnal rotation of
+  // ... the earth (EDV), the hour angle (HAR) is needed at which the observation
+  // ... was made which requires conversion of UT to sidereal time (ST).
+
+  // ... Therefore, first compute ST at 0 hours UT (ST0HG)
+
+  // ... REFERENCE : MEEUS J.,1980,ASTRONOMICAL FORMULAE FOR CALCULATORS
+
+
+  jd0h = jd - (utr/24.0);
+      
+  t0 = (jd0h-2415020.  )/36525. ;
+      
+
+  theta0 = 0.276919398  +100.0021359  *t0+0.000001075  *t0*t0 ;
+
+  pe = (int) theta0;
+
+  theta0 = theta0 - pe;
+
+  st0hg = theta0*24. ;
+
+  // ... now do the conversion UT -> ST (MEAN SIDEREAL TIME)
+
+  // ... REFERENCE : THE ASTRONOMICAL ALMANAC 1983, P B7
+  // ... IN 1983: 1 MEAN SOLAR DAY = 1.00273790931 MEAN SIDEREAL DAYS
+  // ... ST WITHOUT EQUATION OF EQUINOXES CORRECTION => ACCURACY +/- 1 SEC
+  //
+  stg = st0hg+utr*1.00273790931 ;
+      
+  if (stg < dl) stg = stg +24. ;
+
+  STR = stg-dl;
+
+
+  if (STR >= 24. ) STR = STR-24. ;
+
+  STR = STR*M_PI/12. ;
+
+  HAR = STR-alp;
+      
+
+  EDV = -0.4654  * sin(HAR)* cos(del)* cos(phi);
+
+  // ... the total correction (in km/s) is the sum of orbital and diurnal components
+
+
+  herv=heov+EDV;
+  berv=beov+EDV;
+
+  /* The following is not needed. Do not translate */
+
+#if 0
+  // ... Calculation of the barycentric and heliocentric correction times
+  // ... (BCT and HCT) requires knowledge of the earth's position in its
+  // ... orbit. Subroutine BARCOR returns the rectangular barycentric (DCORB)
+  // ... and heliocentric (DCORH) coordinates.
+
+  //      CALL BARCOR(DCORH,DCORB)
+
+  // ... from this, the correction times (in days) can be determined:
+  // ... (REFERENCE: THE ASTRONOMICAL ALMANAC 1982 PAGE:B16)
+
+  //      BCT=+0.0057756D0*(DCORB(1)*DCOS(ALP)*DCOS(DEL)+
+  //     1                DCORB(2)*DSIN(ALP)*DCOS(DEL)+
+  //     2                DCORB(3)*          DSIN(DEL))
+  //      HCT=+0.0057756D0*(DCORH(1)*DCOS(ALP)*DCOS(DEL)+
+  //     1                DCORH(2)*DSIN(ALP)*DCOS(DEL)+
+  //     2                DCORH(3)*          DSIN(DEL))
+
+  //... write results to keywords
+
+  //      CALL STKWRD('OUTPUTD',BCT,1,1,KUN,STAT)    ! barycentric correction time
+  //      CALL STKWRD('OUTPUTD',HCT,2,1,KUN,STAT)    ! heliocentric correction time
+#endif
+
+  rbuf[1] = berv;   /* barocentric RV correction */
+  rbuf[2] = herv;   /* heliocentric RV correction */
+  rbuf[3] = EDV;    /* diurnal RV correction */
+
+
+  outputr[1] = rbuf[1];
+  outputr[2] = rbuf[2];
+  outputr[3] = rbuf[3];
+
+  return;
+}
+
+
+
+/*----------------------------------------------------------------------------*/
+/**
+   @brief    Compute velocity correction
+   @param    raw_header input FITS header
+   @param    bary_corr  (output) baryocentric correction
+   @param    helio_corr (output) heliocentric correction
+*/
+/*----------------------------------------------------------------------------*/
+cpl_error_code
+sinfo_baryvel(const cpl_propertylist *raw_header,
+         double *bary_corr,
+         double *helio_corr)
+{
+
+    double outputr[4];
+
+    char inputc[] = "X+++";       /* 0th index not used */
+
+    double rneg = 1.0;
+
+    double inputr[19];                  /* Do not use the zeroth element */
+
+
+/*
+  qc_ra       = m$value({p1},O_POS(1))
+  qc_dec      = m$value({p1},O_POS(2))
+  qc_geolat   = m$value({p1},{h_geolat})
+  qc_geolon   = m$value({p1},{h_geolon})
+  qc_obs_time = m$value({p1},O_TIME(7))  !using an image as input it take the
+                                         !date from the descriptor O_TIME(1,2,3)
+                                         !and the UT from O_TIME(5)
+*/
+    double qc_ra;
+    double qc_dec;
+    double qc_geolat;
+    double qc_geolon;
+
+    double utr;
+    double mod_juldat;
+
+    double ra_hour, ra_min, ra_sec;
+    double dec_deg, dec_min, dec_sec;
+    double lat_deg, lat_min, lat_sec;
+    double lon_deg, lon_min, lon_sec;
+
+    check( qc_ra       = sinfo_pfits_get_ra(raw_header),  /* in degrees */
+       "Error getting object right ascension");
+    check( qc_dec      = sinfo_pfits_get_dec(raw_header),
+       "Error getting object declination");
+
+    check( qc_geolat   = sinfo_pfits_get_geolat(raw_header),
+       "Error getting telescope latitude");
+    check( qc_geolon   = sinfo_pfits_get_geolon(raw_header),
+       "Error getting telescope longitude");
+
+    /* double qc_obs_time = sinfo_pfits_get_exptime(raw_header);   Not used! */
+
+    check( utr         = sinfo_pfits_get_utc(raw_header),
+       "Error reading UTC");
+    check( mod_juldat  = sinfo_pfits_get_mjdobs(raw_header),
+       "Error julian date");
+
+    deg2hms(qc_ra,     &ra_hour, &ra_min, &ra_sec);
+    deg2dms(qc_dec,    &dec_deg, &dec_min, &dec_sec);
+    deg2dms(qc_geolat, &lat_deg, &lat_min, &lat_sec);
+    deg2dms(qc_geolon, &lon_deg, &lon_min, &lon_sec);
+
+
+    inputr[7] = lon_deg;
+    inputr[8] = lon_min;
+    inputr[9] = lon_sec;
+
+
+    rneg = (inputr[7]*3600.)+(inputr[8]*60.)+inputr[9];
+
+    inputc[1] = (lon_deg >= 0) ? '+' : '-';
+
+    if (rneg < 0) inputc[1] = '-';
+
+
+    inputr[10] = lat_deg;
+    inputr[11] = lat_min;
+    inputr[12] = lat_sec;
+
+
+    rneg = (inputr[10]*3600.)+(inputr[11]*60.)+inputr[12];
+
+    inputc[2] = (lat_deg >= 0) ? '+' : '-';
+
+    if (rneg < 0) inputc[2] = '-';
+
+
+    inputr[13] = ra_hour;
+    inputr[14] = ra_min;
+    inputr[15] = ra_sec;
+
+
+    inputr[16] = dec_deg;
+    inputr[17] = dec_min;
+    inputr[18] = dec_sec;
+
+
+    inputc[3] = (dec_deg >= 0) ? '+' : '-';
+
+    rneg = (inputr[16]*3600.)+(inputr[17]*60.)+inputr[18];
+
+    if (rneg < 0) inputc[3] = '-';
+    
+
+//C  INPUTR/R/1/3    date: year,month,day
+//C  INPUTR/R/4/3    universal time: hour,min,sec
+//C  INPUTR/R/7/3    EAST longitude of observatory: degree,min,sec  !! NOTE
+//C  INPUTR/R/10/3   latitude of observatory: degree,min,sec
+//C  INPUTR/R/13/3   right ascension: hour,min,sec
+//C  INPUTR/R/16/3   declination: degree,min,sec
+
+    /* compute the corrections */
+    compxy(inputr, inputc, outputr, utr, mod_juldat);
+
+   sinfo_msg_debug("        Total barycentric RV correction:  %f km/s", outputr[1]);
+   sinfo_msg_debug("        Total heliocentric RV correction: %f km/s", outputr[2]);
+   sinfo_msg_debug("          (incl. diurnal RV correction of %f km/s)", outputr[3]);
+
+
+   *bary_corr = outputr[1];
+   *helio_corr = outputr[2];
+
+  cleanup:
+    if (cpl_error_get_code() != CPL_ERROR_NONE) {
+       sinfo_check_rec_status(0);
+    }
+    return cpl_error_get_code();
+}
diff --git a/sinfoni/sinfo_baryvel.h b/sinfoni/sinfo_baryvel.h
new file mode 100644
index 0000000..b8d558e
--- /dev/null
+++ b/sinfoni/sinfo_baryvel.h
@@ -0,0 +1,61 @@
+/*
+ * This file is part of the ESO UVES Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2009/04/28 11:42:18 $
+ * $Revision: 1.2 $
+ * $Name: sinfo-2_3_2 $
+ * $Log: sinfo_baryvel.h,v $
+ * Revision 1.2  2009/04/28 11:42:18  amodigli
+ * now return cpl_error_code
+ *
+ * Revision 1.1  2009/01/02 08:38:07  amodigli
+ * added to CVS
+ *
+ * Revision 1.3  2007/06/06 08:17:33  amodigli
+ * replace tab with 4 spaces
+ *
+ * Revision 1.2  2007/04/24 12:50:29  jmlarsen
+ * Replaced cpl_propertylist -> uves_propertylist which is much faster
+ *
+ * Revision 1.1  2006/10/04 11:03:08  jmlarsen
+ * Implemented QC.VRAD parameters
+ *
+ * Revision 1.4  2006/08/17 13:56:52  jmlarsen
+ * Reduced max line length
+ *
+ * Revision 1.3  2006/02/28 09:15:22  jmlarsen
+ * Minor update
+ *
+ * Revision 1.2  2005/12/19 16:17:56  jmlarsen
+ * Replaced bool -> int
+ *
+ */
+#ifndef SINFO_BARYVEL_H
+#define SINFO_BARYVEL_H
+
+#include <cpl.h>
+
+cpl_error_code
+sinfo_baryvel(const cpl_propertylist *raw_header,
+         double *barycor,
+         double *helicor);
+
+#endif  /* SINFO_BARYVEL_H */
diff --git a/sinfoni/sinfo_boltzmann.c b/sinfoni/sinfo_boltzmann.c
new file mode 100644
index 0000000..544dadb
--- /dev/null
+++ b/sinfoni/sinfo_boltzmann.c
@@ -0,0 +1,2513 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*************************************************************************
+* E.S.O. - VLT project
+*
+*
+*
+* who       when      what
+* --------  --------  ----------------------------------------------
+* schreib  27/02/01  created
+*/
+
+/************************************************************************
+*   NAME
+*        new_boltzmann.c -
+*        routines to determine the absolute positions of the slitlets out
+*        of an emission line frame
+*
+*   SYNOPSIS
+*   #include "absolute.h"
+*
+*   1) float sinfo_new_boltz ( float * xdat, float * parlist )
+*   2) void sinfo_new_boltz_deriv( float * xdat, float * parlist, 
+                                   float * dervs )
+*   3) static int sinfo_new_inv_mat (void)
+*   4) static void sinfo_new_get_mat ( float * xdat,
+*                            int   * xdim,
+*                            float * ydat,
+*                            float * wdat,
+*                            int   * ndat,
+*                            float * fpar,
+*                            float * epar,
+*                            int   * npar )
+*   5) static int sinfo_new_get_vec ( float * xdat,
+*                           int   * xdim,
+*                           float * ydat,
+*                           float * wdat,
+*                           int   * ndat,
+*                           float * fpar,
+*                           float * epar,
+*                           int   * npar )
+*   6) int sinfo_new_lsqfit ( float * xdat,
+*                   int   * xdim,
+*                   float * ydat,
+*                   float * wdat,
+*                   int   * ndat,
+*                   float * fpar,
+*                   float * epar,
+*                   int   * mpar,
+*                   int   * npar,
+*                   float * tol ,
+*                   int   * its ,
+*                   float * lab  )
+*   7) int sinfo_new_fit_slits_boltz( cpl_image   * lineImage, 
+*                         FitParams ** par,
+*                         float     ** slit_pos,
+*                         int          box_length,
+*                         float        y_box,
+*                         float        diff_tol )
+*   8) int sinfo_new_fit_slits_boltz_single_line ( cpl_image   * lineImage, 
+*                                    float     ** slit_pos,
+*                                    int          box_length,
+*                                    float        y_box,
+*                                int          low_pos,
+*                                    int          high_pos )
+*   9) int sinfo_new_fit_slits_boltz_with_estimate ( cpl_image   * lineImage, 
+*                                      float     ** slit_pos,
+*                                      int          box_length,
+*                                      float        y_box,
+*                                      float        diff_tol,
+*                                      int          low_pos,
+*                           int          high_pos )
+*
+*   DESCRIPTION
+*   1) calculates the value of a Boltzmann function with parameters 
+*      parlist at the position xdat 
+*   2) calculates the partial derivatives for a Boltzmann function with
+*      parameters parlist at position xdat 
+*   3) calculates the inverse of matrix2. The algorithm used 
+*      is the Gauss-Jordan algorithm described in Stoer,
+*      Numerische Mathematik, 1. Teil.
+*   4) builds the sinfo_matrix 
+*   5) calculates the correction sinfo_vector. The sinfo_matrix has been
+*      built by get_mat(), we only have to rescale it for the 
+*      current value of labda. The sinfo_matrix is rescaled so that
+*      the diagonal gets the value 1 + labda.
+*      Next we calculate the inverse of the sinfo_matrix and then
+*      the correction sinfo_vector.
+*   6) this is a routine for making a least-squares fit of a
+*      function to a set of data points. The method used is
+*      described in: Marquardt, J.Soc.Ind.Appl.Math. 11. 431 (1963).
+*      This method is a mixture of the steepest descent method 
+*      and the Taylor method.
+*   7) fits the beginning and end position of the slitlets
+*      by using non-linear least square fitting of Boltzmann function
+*      fits a Boltzmann function to the slitlet edges exposed and indicated
+*      by the brightest emission lines. To achieve this, the fit
+*      parameters are used to find the brightest emission line
+*      and to get its position for each column.
+*      The least squares fit is done by using a box smaller than
+*      the size of two slitlets
+*   8) fits the beginning and end position of the slitlets
+*      by using non-linear least square fitting of a Boltzmann function
+*      fits a Boltzmann function to the slitlet edges exposed and indicated
+*      by the brightest emission lines. The slitlet is searched within
+*      user given positions.
+*      The least squares fit is done by using a box smaller than
+*      the size of two slitlets 
+*   9) fits the beginning and end position of the slitlets
+*      by using non-linear least square fitting of a Boltzmann function
+*      fits a Boltzmann function to the slitlet edges exposed and indicated
+*      by the brightest emission lines. The slitlet is searched within
+*      user given positions.
+*      The least squares fit is done by using a box smaller than
+*      the size of two slitlets 
+*
+*   FILES
+*
+*   ENVIRONMENT
+*
+*   RETURN VALUES
+*
+*   CAUTIONS
+*
+*   EXAMPLES
+*
+*   SEE ALSO
+*
+*   BUGS
+*
+*------------------------------------------------------------------------
+*/
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+#include "sinfo_vltPort.h"
+
+/*
+ * System Headers
+ */
+
+/*
+ * Local Headers
+ */
+
+#include "sinfo_absolute.h"
+#include "sinfo_recipes.h"
+
+/*----------------------------------------------------------------------------
+ *                                 Defines
+ *--------------------------------------------------------------------------*/
+
+#define XDIMA         1         /* dimension of the x values */
+#define TOLA          0.001     /* fitting tolerance */
+#define LABA          0.1       /* labda parameter */
+#define ITSA          200       /* maximum number of iterations */
+#define LABFACA       10.0      /* labda step factor */
+#define LABMAXA       1.0e+10   /* maximum value for labda */
+#define LABMINA       1.0e-10   /* minimum value for labda */
+#define NPAR          4         /* number of fit parameters */
+
+/*----------------------------------------------------------------------------
+ *                                    Local variables
+ *--------------------------------------------------------------------------*/
+
+static double chi1 ;                    /* old reduced chi-squared */
+static double chi2 ;                    /* new reduced chi-squared */
+static double labda ;                   /* mixing parameter */
+static double vec[NPAR] ;               /* correction sinfo_vector */
+static double matrix1[NPAR][NPAR] ;     /* original sinfo_matrix */
+static double matrix2[NPAR][NPAR] ;     /* inverse of matrix1 */
+static int    nfree ;                   /* number of free parameters */
+static int    parptr[NPAR] ;            /* parameter pointer */
+
+/*----------------------------------------------------------------------------
+ *                    Functions private to this module
+ *--------------------------------------------------------------------------*/
+
+static int sinfo_new_inv_mat (void) ;
+
+static void sinfo_new_get_mat ( float * xdat,
+                      int   * xdim,
+                      float * ydat,
+                      float * wdat,
+                      int   * ndat,
+                      float * fpar,
+                      float * epar/*,
+                      int   * npar*/ ) ;
+
+static int sinfo_new_get_vec ( float * xdat,
+                     int   * xdim,
+                     float * ydat,
+                     float * wdat,
+                     int   * ndat,
+                     float * fpar,
+                     float * epar,
+                     int   * npar ) ;
+/**
+ * @defgroup sinfo_boltzmann Boltzmann function operations
+ *
+ * TBD
+ */
+
+/**@{*/
+/*----------------------------------------------------------------------------
+ *                            Function codes
+ *--------------------------------------------------------------------------*/
+
+/**
+ at brief calculates the value of a Boltzmann function with parameters 
+                        parlist at the position xdat 
+ 
+   @param   xdat        position array
+   @param   parlist     parameter list
+
+                        The parameters are:
+            #            parlist(0): background1
+            #            parlist(1): background2
+            #            parlist(2): central position
+            #            parlist(3): width
+  @returns              function value of a Boltzmann function
+                        that is 
+                        y = (parlist(0) - parlist(1)) / 
+                            (1+exp((x-parlist(2))/parlist(3))) + parlist(1)
+   
+*/
+
+float sinfo_new_boltz ( float * xdat, float * parlist )
+{
+    float return_value ;
+
+    /* now build the boltzman function out of the parameters */
+    return_value = 
+    (parlist[0] - parlist[1]) / (1 + exp(( xdat[0] - parlist[2] ) / 
+     parlist[3])) + parlist[1] ;
+    
+    return return_value ;
+}
+       
+/**
+ @brief calculates the partial derivatives for a Boltzmann function with
+                        parameters parlist at position xdat 
+   
+  @param    xdat        position array xdat
+  @param    parlist     parameter list 
+  #                      The parameters are:
+  #                      parlist(0): background1
+  #                      parlist(1): background2
+  #                      parlist(2): central position
+  #                      parlist(3): width
+  @param    dervs       derivative value of a Boltzmann function at\ 
+                         position xdat: dervs
+  #                      dervs[0]: partial derivative by background1
+  #                      dervs[1]: partial derivative by background2 
+  #                      dervs[2]: partial derivative by central position
+  #                      dervs[3]: partial derivative by the width
+
+  @returns               nothing, void
+   */
+
+void sinfo_new_boltz_deriv( float * xdat, float * parlist, float * dervs )
+{
+    float subst ;
+ 
+    subst = (xdat[0] - parlist[2]) / parlist[3] ;
+
+    dervs[0] = 1. / ( 1. + exp(subst) ) ;
+
+    dervs[1] = -1. / ( 1. + exp(subst) ) + 1. ;
+
+    dervs[2] = ( (parlist[0] - parlist[1]) / parlist[3] * exp(subst) ) /
+               ( (1. + exp(subst)) * (1. + exp(subst)) ) ;
+
+    dervs[3] = ( (parlist[0] - parlist[1]) * (xdat[0] - parlist[2]) /
+               (parlist[3]*parlist[3]) * exp(subst) ) /
+               ( (1. + exp(subst)) * (1. + exp(subst)) ) ;
+}
+
+/**
+ @brief calculates the inverse of matrix2.
+   
+   @param               void
+   @returns             integer (0 if it worked, -6 if determinant is zero) 
+
+   The algorithm used is the Gauss-Jordan algorithm described in Stoer,
+   Numerische Mathematik, 1. Teil.
+ */
+
+static int sinfo_new_inv_mat (void)
+{
+    double even ;
+    double hv[NPAR] ;
+    double mjk ;
+    double rowmax ;
+    int evin ;
+    int i, j, k, row ;
+    int per[NPAR] ;
+   
+    /* set permutation array */
+    for ( i = 0 ; i < nfree ; i++ )
+    {
+        per[i] = i ;
+    }
+    
+    for ( j = 0 ; j < nfree ; j++ ) /* in j-th column */
+    {
+        /* determine largest element of a row */                                
+        rowmax = fabs ( matrix2[j][j] ) ;
+        row = j ;                         
+
+        for ( i = j + 1 ; i < nfree ; i++ )
+        {
+            if ( fabs ( matrix2[i][j] ) > rowmax )
+            {
+                rowmax = fabs( matrix2[i][j] ) ;
+                row = i ;
+            }
+        }
+
+        /* determinant is zero! */
+        if ( matrix2[row][j] == 0.0 )
+        {
+            return -6 ;
+        }
+        
+        /* if the largest element is not on the diagonal, then permutate rows */
+        if ( row > j )
+        {
+            for ( k = 0 ; k < nfree ; k++ )
+            {
+                even = matrix2[j][k] ;
+                matrix2[j][k] = matrix2[row][k] ;
+                matrix2[row][k] = even ;
+            }
+            /* keep track of permutation */
+            evin = per[j] ;
+            per[j] = per[row] ;
+            per[row] = evin ;
+        }
+        
+        /* modify column */
+        even = 1.0 / matrix2[j][j] ;
+        for ( i = 0 ; i < nfree ; i++ )
+        {
+            matrix2[i][j] *= even ;
+        }
+        matrix2[j][j] = even ;
+        
+        for ( k = 0 ; k < j ; k++ )
+        {
+            mjk = matrix2[j][k] ;
+            for ( i = 0 ; i < j ; i++ )
+            {
+                matrix2[i][k] -= matrix2[i][j] * mjk ;
+            }
+            for ( i = j + 1 ; i < nfree ; i++ )
+            {
+                matrix2[i][k] -= matrix2[i][j] * mjk ;
+            }
+            matrix2[j][k] = -even * mjk ;
+        }
+    
+        for ( k = j + 1 ; k < nfree ; k++ )
+        {
+            mjk = matrix2[j][k] ;
+            for ( i = 0 ; i < j ; i++ )
+            {
+                matrix2[i][k]  -= matrix2[i][j] * mjk ;
+            }
+            for ( i = j + 1 ; i < nfree ; i++ )
+            {
+                matrix2[i][k]  -= matrix2[i][j] * mjk ;
+            }
+            matrix2[j][k] = -even * mjk ;
+        }
+    }
+    
+    /* finally, repermute the columns */
+    for ( i = 0 ; i < nfree ; i++ )
+    {
+        for ( k = 0 ; k < nfree ; k++ )
+        {
+            hv[per[k]] = matrix2[i][k] ;
+        }
+        for ( k = 0 ; k < nfree ; k++ )
+        {
+            matrix2[i][k] = hv[k] ;
+        }
+    }
+        
+    /* all is well */
+    return 0 ;
+}
+    
+/**
+ at brief  builds the sinfo_matrix
+   
+   @param                     xdat position
+   @param                     xdim factor of the indices of the position array
+   @param                     ydat real data
+   @param                     wdat weights
+   @param                     ndat number of data points
+   @param                     fpar function parameters
+   @param                     epar partial derivatives of the function
+   @param                     npar number of function parameters
+   @return                    void
+  */
+
+static void sinfo_new_get_mat ( float * xdat,
+                      int   * xdim,
+                      float * ydat,
+                      float * wdat,
+                      int   * ndat,
+                      float * fpar,
+                      float * epar/*,
+                      int   * npar*/ )
+{
+    double wd ;
+    double wn ;
+    double yd ;
+    int i, j, n ;
+
+    for ( j = 0 ; j < nfree ; j++ )
+    {
+        vec[j] = 0.0 ; /* zero sinfo_vector */
+        for ( i = 0 ; i<= j ; i++ ) /* zero sinfo_matrix only 
+                                       on and below diagonal */
+        {
+            matrix1[j][i] = 0.0 ;
+        }
+    }
+    chi2 = 0.0 ;  /* reset reduced chi-squared */
+    
+    /* loop through data points */
+    for ( n = 0 ; n < (*ndat) ; n++ )
+    {
+        wn = wdat[n] ;
+        if ( wn > 0.0 )  /* legal weight ? */
+        {
+            yd = ydat[n] - sinfo_new_boltz( &xdat[(*xdim) * n], fpar ) ;
+            sinfo_new_boltz_deriv( &xdat[(*xdim) * n], fpar, epar ) ;
+            chi2 += yd * yd * wn ; /* add to chi-squared */
+            for ( j = 0 ; j < nfree ; j++ )
+            {
+                wd = epar[parptr[j]] * wn ;  /* weighted derivative */
+                vec[j] += yd * wd ;       /* fill sinfo_vector */
+                for ( i = 0 ; i <= j ; i++ ) /* fill sinfo_matrix */
+                {
+                    matrix1[j][i] += epar[parptr[i]] * wd ;
+                }
+            }
+        }
+    }                   
+}  
+                
+            
+/**
+ @brief calculates the correction sinfo_vector.
+   
+   @param           :       xdat: position
+   @param                     xdim: factor of the indices of the position array
+   @param                     ydat: real data
+   @param                     wdat: weights
+   @param                     ndat: number of data points
+   @param                     fpar: function parameters
+   @param                     epar: partial derivatives of the function
+   @param                     npar: number of function parameters
+   @returns                 integer (0 if it had worked, 
+                                    -5 or -7 if diagonal element is wrong, or 
+                                    -6, if determinant is zero )
+
+   The sinfo_matrix has been built by get_mat(), we only have to rescale 
+   it for the current value of labda. The matrix is rescaled so that 
+   the diagonal gets the value 1 + labda. Next we calculate the inverse of 
+   the sinfo_matrix and then the correction sinfo_vector.
+ */
+            
+static int sinfo_new_get_vec ( float * xdat,
+                     int   * xdim,
+                     float * ydat,
+                     float * wdat,
+                     int   * ndat,
+                     float * fpar,
+                     float * epar,
+                     int   * npar )
+{
+    double dj ;
+    double dy ;
+    double mii ;
+    double mji ;
+    double mjj ;
+    double wn ;
+    int i, j, n, r ;
+
+    /* loop to modify and scale the sinfo_matrix */
+    for ( j = 0 ; j < nfree ; j++ )
+    {
+        mjj = matrix1[j][j] ;
+        if ( mjj <= 0.0 )             /* diagonal element wrong */
+        {
+            return -5 ;
+        }
+        mjj = sqrt( mjj ) ;
+        for ( i = 0 ; i < j ; i++ )
+        {
+            mji = matrix1[j][i] / mjj / sqrt( matrix1[i][i] ) ;
+            matrix2[i][j] = matrix2[j][i] = mji ;
+        }
+        matrix2[j][j] = 1.0 + labda ;  /* scaled value on diagonal */
+    }    
+    
+    if ( (r = sinfo_new_inv_mat()) ) /* sinfo_invert sinfo_matrix inlace */
+    {
+        return r ;
+    }
+    
+    for ( i = 0 ; i < (*npar) ; i ++ )
+    {
+        epar[i] = fpar[i] ;
+    }
+    
+    /* loop to calculate correction sinfo_vector */
+    for ( j = 0 ; j < nfree ; j++ )
+    {
+        dj = 0.0 ;
+        mjj = matrix1[j][j] ;
+        if ( mjj <= 0.0)               /* not allowed */
+        {
+            return -7 ;
+        }
+        mjj = sqrt ( mjj ) ;
+        for ( i = 0 ; i < nfree ; i++ )
+        {
+            mii = matrix1[i][i] ;
+            if ( mii <= 0.0 )
+            {
+                return -7 ;
+            }
+            mii = sqrt( mii ) ;
+            dj += vec[i] * matrix2[j][i] / mjj / mii ;
+        }
+        epar[parptr[j]] += dj ;       /* new parameters */
+    }    
+    chi1 = 0.0 ;                      /* reset reduced chi-squared */
+ 
+    /* loop through the data points */
+    for ( n = 0 ; n < (*ndat) ; n++ )
+    {
+        wn = wdat[n] ;               /* get weight */
+        if ( wn > 0.0 )              /* legal weight */
+        {
+            dy = ydat[n] - sinfo_new_boltz( &xdat[(*xdim) * n], epar) ;
+            chi1 += wdat[n] * dy * dy ;
+        }
+    }
+    return 0 ;
+}   
+    
+        
+
+/**
+ @brief makes a least-squares fit of a function to a set of data points.
+   
+   @param               xdat: position, coordinates of data points.
+                              xdat is 2 dimensional: XDAT ( XDIM, NDAT )
+   @param               xdim: dimension of fit
+   @param               ydat: data points
+   @param               wdat: weights for data points
+   @param               ndat: number of data points
+   @param               fpar: on input contains initial estimates of the 
+                              parameters for non-linear fits, on output the
+                              fitted parameters.
+   @param               epar: contains estimates of the errors in fitted 
+                              parameters
+   @param               mpar: logical mask telling which parameters are free 
+                              (non-zero) and which parameters are fixed (0)
+   @param               npar: number of function parameters ( free + fixed )
+   @param               tol:  relative tolerance. sinfo_lsqfit stops when 
+                              successive iterations fail to produce a decrement
+                              in reduced chi-squared less than tol. If tol is 
+                              less than the minimum tolerance possible, tol 
+                              will be set to this value. This means
+                              that maximum accuracy can be obtained by setting
+                              tol = 0.0.
+   @param               its:  maximum number of iterations
+   @param               lab:  mixing parameter, lab determines the initial 
+                              weight of steepest descent method relative to 
+                              the Taylor method lab should be a small value 
+                              (i.e. 0.01). lab can only be zero when the 
+                              partial derivatives are independent of the 
+                              parameters. In fact in this case lab should be
+                              exactly equal to zero.
+   @return number of iterations needed to achieve convergence according to 
+           tol. When this number is negative, the fitting
+                        was not continued because a fatal error occurred:
+    #                    -1 too many free parameters, maximum is 32
+    #                    -2 no free parameters
+    #                    -3 not enough degrees of freedom
+    #                    -4 maximum number of iterations too small to obtain
+                           a solution which satisfies tol.
+    #                    -5 diagonal of sinfo_matrix contains elements which 
+                            are zero
+    #                    -6 determinant of the coefficient sinfo_matrix is zero
+    #                    -7 square root of a negative number 
+   
+The method used is described in: Marquardt, J.Soc.Ind.Appl.Math. 11. 431 (1963).
+This method is a mixture of the steepest descent method and the Taylor method.
+ */
+
+int sinfo_new_lsqfit ( float * xdat,
+             int   * xdim,
+             float * ydat,
+             float * wdat,
+             int   * ndat,
+             float * fpar,
+             float * epar,
+             int   * mpar,
+             int   * npar,
+             float * tol ,
+             int   * its ,
+             float * lab  )
+{
+    int i, n, r ;
+    int itc ;                      /* fate of fit */
+    int found ;                    /* fit converged: 1, not yet converged: 0 */
+    int  nuse ;                    /* number of useable data points */
+    double tolerance ;             /* accuracy */
+
+    itc   = 0 ;                    /* fate of fit */
+    found = 0 ;                    /* reset */
+    nfree = 0 ;                    /* number of free parameters */
+    nuse  = 0 ;                    /* number of legal data points */
+
+    if ( *tol < (FLT_EPSILON * 10.0 ) )
+    {
+        tolerance = FLT_EPSILON * 10.0 ;  /* default tolerance */
+    }
+    else
+    {
+        tolerance = *tol ;                /* tolerance */
+    }
+    
+    labda = fabs( *lab ) * LABFACA ;   /* start value for mixing parameter */
+    for ( i = 0 ; i < (*npar) ; i++ )
+    {
+        if ( mpar[i] )
+        {
+            if ( nfree > NPAR )         /* too many free parameters */
+            {
+                return -1 ;
+            }
+            parptr[nfree++] = i ;         /* a free parameter */
+        }
+    }
+    
+    if (nfree == 0)                       /* no free parameters */     
+    {
+        return -2 ;
+    }
+    
+    for ( n = 0 ; n < (*ndat) ; n++ )
+    {
+        if ( wdat[n] > 0.0 )              /* legal weight */
+        {
+            nuse ++ ;
+        }
+    }
+    
+    if ( nfree >= nuse )
+    {
+        return -3 ;                       /* no degrees of freedom */
+    }
+    if ( labda == 0.0 )                   /* linear fit */
+    {
+        /* initialize fpar array */
+        for ( i = 0 ; i < nfree ; fpar[parptr[i++]] = 0.0 ) ;  
+        sinfo_new_get_mat(xdat,xdim,ydat,wdat,ndat,fpar,epar/*, npar*/ ) ;
+        r =  sinfo_new_get_vec(xdat,xdim,ydat,wdat,ndat,fpar,epar,npar) ;
+        if ( r )                         /* error */
+        {
+            return r ;
+        }
+        for ( i = 0 ; i < (*npar) ; i++ )
+        {
+            fpar[i] = epar[i] ;           /* save new parameters */
+            epar[i] = 0.0 ;               /* and set errors to zero */
+        }
+        chi1 = sqrt( chi1 / (double) (nuse - nfree) ) ;
+        for ( i = 0 ; i < nfree ; i++ )
+        {
+            if ( (matrix1[i][i] <= 0.0 ) || (matrix2[i][i] <= 0.0) )
+            {
+                return -7 ;
+            }
+            epar[parptr[i]] = chi1 * sqrt( matrix2[i][i] ) / 
+                                     sqrt( matrix1[i][i] ) ;
+        }
+    }
+    else                                  /* non-linear fit */
+    {
+        /*----------------------------------------------------------------
+         * the non-linear fit uses the steepest descent method in combination
+         * with the Taylor method. The mixing of these methods is controlled
+         * by labda. In the outer loop ( called the iteration loop ) we build
+         * the sinfo_matrix and calculate the correction sinfo_vector. 
+         * In the inner loop
+         * (called the interpolation loop) we check whether we have obtained a
+         * better solution than the previous one. If so, we leave the inner 
+         * loop
+         * else we increase labda ( give more weight to the steepest descent 
+         * method) calculate the correction sinfo_vector and check again. 
+         * After the inner loop
+         * we do a final check on the goodness of the fit and if this satisfies
+         * the tolerance we calculate the errors of the fitted parameters.
+         */
+        while ( !found )                  /* iteration loop */
+        {      
+            if ( itc++ == (*its) )        /* increase iteration counter */
+            {
+                return -4 ;               
+            }
+            sinfo_new_get_mat(xdat,xdim,ydat,wdat,ndat,fpar,epar/*, npar */) ;
+            
+            /*-------------------------------------------------------------
+             * here we decrease labda since we may assume that each iteration
+             * brings us closer to the answer.
+             */
+            if ( labda > LABMINA )
+            {
+                labda = labda / LABFACA ;         /* decrease labda */
+            }
+            r = sinfo_new_get_vec ( xdat, xdim, ydat, wdat, 
+                                    ndat, fpar, epar, npar ) ;
+
+            if ( r )                      /* error */
+            {
+                return r ;
+            }
+
+            while ( chi1 >= chi2 )        /* interpolation loop */
+            {
+                /*-----------------------------------------------------------
+                 * The next statement is based on experience, not on the 
+                 * mathematics of the problem. It is assumed that we have 
+                 * reached convergence when the pure steepest descent method 
+                 * does not produce a better solution.
+                 */
+                if ( labda > LABMAXA )    /* assume solution found */
+                {
+                    break ;
+                }
+                labda = labda * LABFACA ;  /* increase mixing parameter */
+                r = sinfo_new_get_vec ( xdat, xdim, ydat, wdat, 
+                                        ndat, fpar, epar, npar ) ;
+
+                if ( r )                  /* error */
+                {
+                    return r ;
+                }
+            }
+
+            if ( labda <= LABMAXA )        /* save old parameters */
+            {
+                for ( i = 0 ; i < *npar ; i++ )
+                {
+                    fpar[i] = epar[i] ;
+                }
+            }
+            if ( (fabs( chi2 - chi1 ) <= (tolerance * chi1)) || 
+                 (labda > LABMAXA) )
+            {
+                /*---------------------------------------------------------
+                 * we have a satisfying solution, so now we need to calculate 
+                 * the correct errors of the fitted parameters. This we do by 
+                 * using the pure Taylor method because we are very close to 
+                 * the real solution.
+                 */
+                labda = LABMINA ;              /* for Taylor solution */
+                sinfo_new_get_mat(xdat,xdim,ydat,wdat,ndat,fpar,epar/*,npar*/);
+                r = sinfo_new_get_vec(xdat,xdim,ydat,wdat,ndat,fpar,epar,npar);
+
+                if ( r )                    /* error */
+                {
+                    return r ;
+                }
+                for ( i = 0 ; i < (*npar) ; i++ )
+                {
+                    epar[i] = 0.0 ;          /* set error to zero */
+                }
+                chi2 = sqrt ( chi2 / (double) (nuse - nfree) ) ;
+
+                for ( i = 0 ; i < nfree ; i++ )
+                {
+                    if ( (matrix1[i][i] <= 0.0) || (matrix2[i][i] <= 0.0) )
+                    {
+                        return -7 ;
+                    }
+                    epar[parptr[i]] = chi2 * sqrt( matrix2[i][i] ) / 
+                                             sqrt( matrix1[i][i] ) ;
+                }
+                found = 1 ;                  /* we found a solution */
+            }
+        }
+    }
+    return itc ;                             /* return number of iterations */
+}
+
+/**
+ at brief fits the beginning and end position of the slitlets by using non-linear 
+       least square fitting of a Boltzmann function fits a Boltzmann function 
+       to the slitlet edges exposed and indicated by the brightest emission 
+       lines.
+   
+   @param   lineImage:  emission line frame
+   @param   par:        fit parameter data structure of fitted lines
+   @param   slit_pos:   allocated dummy array for the slitlet positions [32][2]
+   @param   box_length: pixel length of the row box within the fit is done
+   @param   y_box:      small box in spectral direction within the slitlet may 
+                        lie.
+   @param   diff_tol:   maximum tolerable difference of the resulting fit 
+                        position
+                        with respect to the expected position. If difference is 
+                        greater the expected position is taken.
+   @returns slit_pos:  beginning and end position of the slitlets to
+                                   sub-pixel accuracy
+           #              0  if it worked,
+           #             -1  if there was no line image given,
+           #             -2  if there were no line fit parameters given,
+           #             -3  if there was no dummy array for the slit positions
+           #                 allocated
+           #             -4  if the given box length is impossible
+           #             -5  if the given y box length is impossible
+           #             -6  if the given difference tolerance is too small
+           #             -7  if there were no emission lines found in the first
+                             image columns
+           #             -8  if not all slitlets could be found
+ 
+
+  @Note   fits the beginning and end position of the slitlets by using 
+          non-linear least square fitting of a Boltzmann function fits a 
+          Boltzmann function to the slitlet edges exposed and indicated by the 
+          brightest emission lines. To achieve this, the fit parameters are 
+          used to find the brightest emission line and to get its position for 
+          each column. The least squares fit is done by using a box smaller 
+          than the size of two slitlets 
+ ---------------------------------------------------------------------------*/
+
+int sinfo_new_fit_slits_boltz ( cpl_image   * lineImage, 
+                    FitParams ** par,
+                    float     ** slit_pos,
+                    int          box_length,
+                    float        y_box,
+                    float        diff_tol )
+{
+    float* position=NULL ;
+    int   * sinfo_edge, * edgeclean ;
+    int   * dummyedge ;
+    int   * pos_row, * pos_rowclean ;
+    Vector * box_buffer ;
+    Vector * half_buffer ;
+    Vector * in_buffer ;
+    float max_intensity ;
+    float row_pos ;
+    int   row, col ;
+    int   i, j, k, m, n, ed ;
+    int   found, init1 ;
+    int   line ; 
+    int   nel, n_right, left_right ;
+    int   n_buf, edge_ind, shift ;
+    int   column ;
+    int   slit_length ;
+    int   agreed ;
+    int   bad_line ;
+    int   margin ;
+    int   iters, xdim, ndat ;
+    int   numpar, its ;
+    int   * mpar ;
+    float * xdat, * wdat ;
+    float tol, lab ;
+    float fitpar[NPAR] ;
+    float dervpar[NPAR] ;
+    float minval, maxval ;
+    float min ;
+    float pos, last_pos ;
+    int old_col=0;
+    int old_pos=0;
+    int ilx=0;
+    int ily=0;
+    float* pidata=NULL;
+
+
+    slit_length = SLITLENGTH ;
+    if ( NULL == lineImage )
+    {
+        sinfo_msg_error(" no line image given!" ) ;
+        return -1 ;
+    }
+
+    if ( NULL == par )
+    {
+        sinfo_msg_error(" no line fit parameters given!" ) ;
+        return -2 ;
+    }
+
+    if ( NULL == slit_pos )
+    {
+        sinfo_msg_error(" no position array allocated!" ) ;
+        return -3 ;
+    }
+
+    if ( box_length <  4 ||
+         box_length > 2*slit_length )
+    {
+        sinfo_msg_error(" wrong fitting box length given!" ) ;
+        return -4 ;
+    }
+
+    if ( y_box <= 0.  || y_box > 6. )
+    {
+        sinfo_msg_error(" wrong y box length given!" ) ;
+        return -5 ;
+    }
+
+    if ( diff_tol < 1. )
+    {
+        sinfo_msg_error(" diff_tol too small!" ) ;
+        return -6 ;
+    }
+ 
+    /* allocate memory for the edges and the row positon of the slitlets */
+    sinfo_edge         = (int*) cpl_calloc( 3*slit_length, sizeof(int) ) ;
+    dummyedge    = (int*) cpl_calloc( 3*slit_length, sizeof(int) ) ;
+    edgeclean    = (int*) cpl_calloc( slit_length-1, sizeof(int) ) ;
+    pos_row      = (int*) cpl_calloc( 3*slit_length, sizeof(int) ) ;
+    pos_rowclean = (int*) cpl_calloc( slit_length, sizeof(int) ) ;
+
+
+    /* -----------------------------------------------------------------------
+     * go through the first image columns and the fit parameters and find the 
+       line with the highest intensity 
+     */
+    agreed = -1 ;
+    bad_line = -1 ;
+    while( agreed == -1 )
+    {
+        found = -1 ;
+        max_intensity = -FLT_MAX ;
+        for ( col = 0 ; col < slit_length ; col++ )
+        {
+            for ( i = 0 ; i < par[0]->n_params ; i++ )
+            {
+                if ( par[i]->column == col && par[i]->line != bad_line )
+                {
+                    if ( par[i]->fit_par[0] > max_intensity )
+                    {
+                        if ( par[i]->fit_par[1] >= 1. && 
+                             par[i]->fit_par[2] > 0. )
+                        {
+                            max_intensity = par[i]->fit_par[0] ;
+                            found = i ;
+                        }
+                    }
+                }
+            }  
+        }
+
+        /* --------------------------------------------------------------------
+         * check if the found line is usable and if the neighbouring line 
+         * have intensity on near rows in neighbouring slitlets 
+         */
+        line    = par[found]->line ;
+        column  = par[found]->column ;
+        row_pos = par[found]->fit_par[2] ;
+        if ( found >= 0 && max_intensity > 0. )
+        {
+            for ( i = 0 ; i < par[0]->n_params ; i++ )
+            {
+                if ( par[i]->line == line-1 && 
+                     par[i]->column == column + slit_length )
+                {
+                    if ( par[i]->fit_par[2] <= (row_pos + y_box) &&
+                         par[i]->fit_par[2] >= (row_pos - y_box) )
+                    {
+                        bad_line = line ;
+                    } 
+                }
+            }
+            if ( bad_line != line )
+            {
+                agreed = 1 ;
+                break ;
+            }
+        }
+        else 
+        {
+          sinfo_msg_error("no emission line found in the first image columns") ;
+            cpl_free( sinfo_edge ) ;
+            cpl_free( pos_row ) ;
+            cpl_free( edgeclean ) ;
+            cpl_free( dummyedge ) ;
+            cpl_free( pos_rowclean ) ;
+            return -7 ;
+        }    
+    }
+
+
+
+    if ( agreed == -1 )
+    {
+        sinfo_msg_error(" no emission line found in the first image columns") ;
+        cpl_free( sinfo_edge ) ;
+        cpl_free( pos_row ) ;
+        cpl_free( edgeclean ) ;
+        cpl_free( dummyedge ) ;
+        cpl_free( pos_rowclean ) ;
+        return -7 ;
+    }    
+
+    ilx=cpl_image_get_size_x(lineImage);
+    ily=cpl_image_get_size_y(lineImage);
+    pidata=cpl_image_get_data_float(lineImage);
+
+    /* now find and store the raw sinfo_edge positions of the found slitlet */ 
+    n  = 0 ;
+    ed = 0 ;
+    position=cpl_calloc(ilx,sizeof(float)) ;
+
+    /* was for ( col = 0 ; col < ilx - slit_length/2 ; col++ ) */
+    for ( col = slit_length/2 ; col < ilx - slit_length/2 ; col++ )
+    {
+        for ( i = 0 ; i < par[0]->n_params ; i++ )
+      {   
+        /*
+              printf("p1=%f p2=%f p3=%f\n",
+              par[i]->fit_par[0],par[i]->fit_par[1],par[i]->fit_par[2]);
+        */
+            if ( par[i]->column == col && par[i]->line == line )
+            {
+                if ( par[i]->fit_par[0] > 0.  && 
+                     par[i]->fit_par[1] >= 1. && 
+                     par[i]->fit_par[2] > 0. )
+                {
+                    position[n] = par[i]->fit_par[2] ;
+                    old_pos=position[n];
+                    if ( n > 0 && 
+                         fabs(position[n] - position[n-1]) > y_box && 
+                         (col-old_col) > (slit_length-SLIT_POS_ERR) )
+                    {
+
+              old_col=col;
+              sinfo_edge[ed] = col ; 
+              pos_row[ed] = sinfo_new_nint( position[n-1] ) ;
+                      /* printf("sinfo_edge[%d]=%d , pos_row=%d\n",
+                                 ed,sinfo_edge[ed],pos_row[ed]); */ 
+              ed++ ;
+              if ( col >= ilx - slit_length - SLIT_POS_ERR ) {
+              pos_row[ed] =  sinfo_new_nint( position[n] ) ;
+              } 
+            } else if ( ((col-old_col) > 
+                                  (slit_length+SLIT_POS_ERR)) &&
+                                  (col>120) ) {
+              old_col=col;
+              sinfo_edge[ed] = col ; 
+              pos_row[ed] = sinfo_new_nint( position[n-1] ) ;
+                      sinfo_msg_warning("add1 slitlet edge[%d]=%d, pos_row=%d",
+                     ed,sinfo_edge[ed],pos_row[ed]);
+              ed++ ;
+              if ( col >= ilx - slit_length - SLIT_POS_ERR ) {
+              pos_row[ed] =  sinfo_new_nint( position[n] ) ;
+              } 
+            }
+                    n++ ;
+                }
+            } else if ( ((col-old_col) > (slit_length+SLIT_POS_ERR)) && 
+                        (col>120) ) {
+          /*
+              printf("check col=%d col-old_col=%d check=%d\n",
+                     col,(col-old_col),(slit_length+SLIT_POS_ERR));
+          */
+          position[n] = old_pos ;
+             
+          old_col+=slit_length;
+          sinfo_edge[ed] = old_col; ; 
+          pos_row[ed] = sinfo_new_nint( position[n-1] ) ;
+
+
+          sinfo_msg_warning("added2 slitlet sinfo_edge[%d]=%d, pos_row=%d",
+                  ed,sinfo_edge[ed],pos_row[ed]);
+          ed++ ;
+          if ( old_col >= ilx - slit_length - SLIT_POS_ERR ) {
+        pos_row[ed] =  old_pos ;
+          }
+          n++;
+        }
+        }
+    }
+
+
+    if ( ed < (N_SLITLETS - 1) )
+    {
+        sinfo_msg_error(" not enough slitlets, found: %d", ed) ;
+        cpl_free( sinfo_edge ) ;
+        cpl_free( pos_row ) ;
+        cpl_free( edgeclean ) ;
+        cpl_free( dummyedge ) ;
+        cpl_free( pos_rowclean ) ;
+        return -8 ;
+    } 
+
+    /* now find the clean sinfo_edge and row positions of the slitlets */
+    /* printf("ed=%d\n",ed); */
+    for ( i = 1 ; i <= ed ; i ++ )
+    {
+        if ( i == ed )
+        {
+            if ( (sinfo_edge[i-1] - sinfo_edge[i-2]) < 
+                  slit_length - SLIT_LEN_ERR ||
+                 (sinfo_edge[i-1] - sinfo_edge[i-2]) > 
+                  slit_length + SLIT_LEN_ERR )
+            {
+        /* printf("e(i-1)=%d e(i-2)=%d i=%d\n",
+                       edge[i-1], edge[i-2],i); */
+                dummyedge[i-1]   = -1 ;
+            }
+        }
+        if (dummyedge[i-1] != -1)
+        {
+            dummyedge[i-1] = sinfo_edge[i-1] ;
+        }
+        else
+        {
+            continue ;
+        }
+        if ( i < ed )
+        {
+            if ( (sinfo_edge[i] - sinfo_edge[i-1]) < 
+                  slit_length - SLIT_LEN_ERR ||
+                 (sinfo_edge[i] - sinfo_edge[i-1]) > 
+                  slit_length + SLIT_LEN_ERR )
+            {
+        /* printf("e(i)=%d e(i-1)=%d i=%d\n",edge[i], edge[i-1],i); */
+                dummyedge[i]   = -1 ;
+            }
+        }
+        if ( i+1 < ed && dummyedge[i] != -1 )
+        {
+            if ( (sinfo_edge[i+1] - sinfo_edge[i]) < 
+                  slit_length - SLIT_LEN_ERR ||
+                 (sinfo_edge[i+1] - sinfo_edge[i]) > 
+                  slit_length + SLIT_LEN_ERR )
+            {
+        /* printf("e(i+1)=%d e(i)=%d i=%d\n",edge[i+1], edge[i],i); */
+                dummyedge[i+1] = -1 ; 
+            }
+        }
+    }
+
+    k = 0 ;
+    for ( i = 0 ; i < ed ; i++ )
+    {
+        if ( dummyedge[i] != -1 && dummyedge[i] != 0 )
+        {
+            edgeclean[k] = dummyedge[i] ;
+            pos_rowclean[k] = pos_row[i] ;
+            k++ ;
+            if( edgeclean[k-1] > (ilx - slit_length -2*SLIT_LEN_ERR ) )
+            {
+                pos_rowclean[k] = pos_row[ed] ;
+            } 
+        }
+    }
+    /*
+    for ( i = 0 ; i < k ; i++ )
+    {
+      sinfo_msg_warning("%d %d", edgeclean[i], pos_rowclean[i]);
+    }
+    */
+    if ( k != N_SLITLETS - 1 )
+    {
+        sinfo_msg_error(" wrong number of clean slitlets found: %d", k+1) ;
+        cpl_free( sinfo_edge ) ;
+        cpl_free( pos_row ) ;
+        cpl_free( edgeclean ) ;
+        cpl_free( dummyedge ) ;
+        cpl_free( pos_rowclean ) ;
+        return -7 ;
+    } 
+
+    /* determine the margins of the fitting box outside the slitlets */
+    margin = box_length / 2 ;
+
+    /* ----------------------------------------------------------------------
+     * now go through the slitlets, search along each column within a box with 
+     * half width y_box the maximum value and store these found values 
+     * in a buffer
+     */
+     if(
+         ( (pos_rowclean[0]-sinfo_new_nint(y_box)) < 0 ) ||
+         ( (pos_rowclean[0]+sinfo_new_nint(y_box)) >ily )
+       ) {
+
+             sinfo_msg_error("pos_rowclean[0] <0 something wrong!") ;
+             cpl_free( sinfo_edge ) ;
+             cpl_free( pos_row ) ;
+             cpl_free( edgeclean ) ;
+             cpl_free( dummyedge ) ;
+             cpl_free( pos_rowclean ) ;
+             return -7 ;
+
+    }
+
+    for ( j = 0 ; j <= k ; j++ )
+    {
+        m = 0 ;
+        if ( j == 0 )
+        {
+            box_buffer = sinfo_new_vector( edgeclean[0] + margin ) ;
+            for( col = 0 ; col < edgeclean[0] + margin ; col++ )
+            {
+                maxval = -FLT_MAX ;
+                for ( row = pos_rowclean[0] - sinfo_new_nint(y_box) ; 
+                      row <= pos_rowclean[0] + sinfo_new_nint(y_box) ; row++ )
+                {
+                    if ( maxval < pidata[col + ilx*row] )
+                    {
+                        maxval = pidata[col + ilx*row] ;
+                    }
+                }
+                box_buffer->data[m] = maxval ;
+                m++ ;
+            }
+        }
+        else if ( j < k )
+        {
+            box_buffer = sinfo_new_vector( edgeclean[j] - 
+                                           edgeclean[j-1] + 2*margin ) ;
+            for ( col = edgeclean[j - 1] - margin ; 
+                  col < edgeclean[j] + margin ; col++ )
+            {
+                maxval = -FLT_MAX ;
+                for ( row = pos_rowclean[j] - sinfo_new_nint(y_box) ; 
+                      row <= pos_rowclean[j] + sinfo_new_nint(y_box) ; row++ )
+                {
+                    if ( maxval < pidata[col + ilx*row] )
+                    {
+                        maxval = pidata[col + ilx*row] ;
+                    }
+                }
+                box_buffer->data[m] = maxval ;
+                m++ ;
+            }
+        }
+        else 
+        {
+            box_buffer = sinfo_new_vector( ilx - edgeclean[k-1] + margin ) ;
+            for ( col = edgeclean[k - 1] - margin ; col < ilx ; col++ )
+            {
+                maxval = -FLT_MAX ;
+                for ( row = pos_rowclean[k-2] - sinfo_new_nint(y_box) ; 
+                      row <= pos_rowclean[k-2] + sinfo_new_nint(y_box) ; row++ )
+                {
+                    if ( maxval < pidata[col + ilx*row] )
+                    {
+                        maxval = pidata[col + ilx*row] ;
+                    }
+                }
+                if(maxval>0) box_buffer->data[m] = maxval ;
+        else box_buffer->data[m] = 0;
+        m++ ;
+            }
+        }
+
+        /* determine the minimum value in the box to get background1 
+           value for the sinfo_edge slitlets */
+        min = FLT_MAX ;
+        for ( i = 0 ; i < box_buffer->n_elements ; i++ )
+        {
+            if ( box_buffer -> data[i] < min )
+            {
+                min = box_buffer -> data[i] ;
+            }
+        }
+
+        for ( left_right = 0 ; left_right <= 1 ; left_right++ )
+        { 
+            nel = 0 ;
+            if ( left_right == 0 )
+            {
+                nel = box_buffer -> n_elements / 2 ;
+            }
+            else
+            {
+                if ( box_buffer -> n_elements % 2 == 0 )
+                {
+                    nel = box_buffer -> n_elements / 2 ;
+                }
+                else
+                {
+                    nel = box_buffer -> n_elements / 2 + 1 ;
+                }
+            }
+
+            /* now split the buffer in the midth in a left and right 
+               part for fitting */
+            half_buffer = sinfo_new_vector( nel ) ;
+            if ( left_right == 0 )
+            {
+                for ( i = 0 ; i < nel ; i++ )
+                {
+                    half_buffer -> data[i] = box_buffer -> data[i] ;
+                }
+            }
+            else
+            {
+                n_right = 0 ;
+                for ( i = box_buffer -> n_elements - 1 ; 
+                      i >= box_buffer -> n_elements - nel ; i-- )
+                {
+                    half_buffer -> data[n_right] = box_buffer -> data[i] ;
+                    n_right++ ;
+                }
+            }
+
+            xdat = (float *) cpl_calloc( nel, sizeof (float) ) ;
+            wdat = (float *) cpl_calloc( nel, sizeof (float) ) ;
+            mpar = (int *)   cpl_calloc( NPAR, sizeof (int) ) ;
+
+            /* set initial values for the fitting routine */
+            minval =  FLT_MAX ;
+            maxval = -FLT_MAX ;
+            for ( i = 0 ; i < nel ; i++ )
+            {
+                xdat[i] = i ;
+                wdat[i] = 1.0 ;
+                if ( half_buffer -> data[i] < minval )
+                {
+                    minval = half_buffer -> data[i] ;
+                }
+                if ( half_buffer -> data[i] > maxval )
+                {
+                    maxval = half_buffer -> data[i] ;
+                }
+            }
+
+            fitpar[0] = minval ;
+            fitpar[1] = maxval ; 
+
+            /* search for both positions of the half intensity 
+               of the hat within the buffer */
+            init1 = -1 ; 
+            for ( i = 0 ; i < nel ; i++ )
+            {
+                if ( half_buffer -> data[i] >= ( maxval + minval ) / 2. )
+                {
+                    init1 = i ;
+                    break ;
+                }
+            }
+
+            /*----------------------------------------------------------------
+             * if we have too few left background values (at the image edges)
+             * the left margin of the buffer to fit is filled with the minimal
+             * values in order to get a good fit
+             */
+              
+            edge_ind = 0 ;
+            if ( init1 < 3 )
+            {
+                n_buf = half_buffer->n_elements + margin ;
+                in_buffer = sinfo_new_vector( n_buf ) ;     
+                for ( i = 0 ; i < margin ; i++ )
+                {
+                    in_buffer -> data[i] = min ;
+                }
+                shift = 0 ;
+                for ( i = margin ; i < n_buf ; i++ )
+                {
+                    in_buffer -> data[i] = half_buffer -> data[shift] ;
+                    shift++ ;
+                }
+                sinfo_new_destroy_vector ( half_buffer ) ;
+                half_buffer = sinfo_new_vector ( n_buf ) ;
+                for ( i = 0 ; i < n_buf ; i++ )
+                {
+                    half_buffer -> data[i] = in_buffer -> data[i] ;
+                }
+                edge_ind = 1 ;
+                init1 += margin ;
+                sinfo_new_destroy_vector ( in_buffer ) ;
+            }
+
+            /* determine the initial positions from the found values */
+            if ( init1 != -1 )
+            {
+                fitpar[2] = (float)init1 ;
+            }
+            fitpar[3] = 1. ;
+
+            for ( i = 0 ; i < NPAR ; i++ )
+            {
+                mpar[i] = 1 ;
+                dervpar[i] = 0. ;
+            }
+      
+            xdim     = XDIMA ;
+            ndat     = nel ;
+            numpar   = NPAR ;
+            tol      = TOLA ;
+            lab      = LABA ;
+            its      = ITSA ;
+         
+            /* finally, do the least squares fit over the buffer data */
+            if ( 0 > ( iters = sinfo_new_lsqfit( xdat, &xdim, 
+                                                 half_buffer -> data, 
+                                                 wdat, &ndat, fitpar,
+                                                 dervpar, mpar, &numpar, 
+                                                 &tol, &its, &lab )) )
+            { 
+                /* if the fit doesn't succeed the initial values are taken */
+                sinfo_msg_warning (" least squares fit failed,"
+                                   " error no.: %d in slitlet: %d", iters, j) ;
+                fitpar[2] = (float)init1 ;
+            }
+
+            pos = fitpar[2] ;
+            if ( edge_ind == 1 )
+            {
+                pos -= (float)margin ;
+            }
+
+            /*---------------------------------------------------------------- 
+             * now discern the left and the right sinfo_edge fit of the 
+             * slitlets and associate the fit results with the absolute 
+             * positions in the image consider the difference of the fitted 
+             * slit position to the expected position and decide wether the 
+             * fit is taken or the expected value is taken.
+             */
+            if ( left_right == 0 )
+            {
+                /* take care of the column position of the fit boxes to get 
+                   the absolute positions */
+                if ( j == 0 )
+                {
+                    if ( fabs(pos - ((float)edgeclean[0] - 1. - 
+                                     (float)slit_length)) < diff_tol )
+                    {
+                        slit_pos[0][0] = pos ;
+                    }
+                    else
+                    {
+                        sinfo_msg_warning("something wrong with fitted "
+                                          "left position of slitlet 0") ;
+                        if ( (float) edgeclean[0] - 1. - 
+                             (float)slit_length < 0. )
+                        {
+                            slit_pos[0][0] = 0. ;
+                        }
+                        else
+                        {
+                            slit_pos[0][0] = (float)edgeclean[0] - 1. - 
+                                             (float)slit_length ;
+                        }
+                    }
+                }
+                else if ( j < k )
+                {
+                    if ( fabs( pos - (float)margin ) < diff_tol )
+                    {
+                        slit_pos[j][0] = pos + (float)edgeclean[j-1] - 
+                                               (float)margin ;
+                    }
+                    else
+                    {
+                        sinfo_msg_warning("something wrong with fitted "
+                                          "left position of slitlet %d", j) ;
+                        slit_pos[j][0] = (float)edgeclean[j-1] - 1. ;
+                    }
+                }
+                else
+                {
+                    if ( fabs( pos - (float)margin ) < diff_tol )
+                    {
+                        slit_pos[k][0] = pos + (float)edgeclean[k-1] - 
+                                               (float)margin ;
+                    }
+                    else
+                    {
+                        sinfo_msg_warning("something wrong with fitted "
+                                          "left position of slitlet %d", j) ;
+                        slit_pos[k][0] = (float)edgeclean[k-1] - 1. ;
+                    }
+                }
+            }
+            else
+            {
+                /* take care of the column position of the fit boxes to 
+                   get the absolute positions */
+                if ( j == 0 )
+                {
+                    if ( fabs( (float)box_buffer->n_elements - pos - 
+                               (float)edgeclean[0] ) < diff_tol )
+                    {
+                        slit_pos[0][1] = (float)(box_buffer->n_elements - 1) - 
+                                         pos ;
+                    }
+                    else
+                    {
+                        sinfo_msg_warning("something wrong with fitted "
+                                          "right position of slitlet 0") ;
+                        slit_pos[0][1] = (float)edgeclean[0] - 1. ;
+                    }
+                }
+                else if ( j < k )
+                {
+                    if ( fabs( (float)box_buffer->n_elements - pos
+                             + (float)edgeclean[j-1] - (float)margin - 
+                               (float)edgeclean[j] ) < diff_tol )
+                    {
+                        slit_pos[j][1] = (float)(box_buffer->n_elements - 1) - 
+                                         pos
+                                       + (float)edgeclean[j-1] - (float)margin ;
+                    }
+                    else
+                    {
+                        sinfo_msg_warning("something wrong with fitted "
+                                          "right position of slitlet %d", j) ;
+                        slit_pos[j][1] = (float)edgeclean[j] - 1. ;
+                    }
+                }
+                else
+                {
+                    if ( edgeclean[k-1] + slit_length > ilx )
+                    {
+                        last_pos = (float)(ilx - 1) ;
+                    }
+                    else
+                    {
+                        last_pos = (float)(edgeclean[k-1] - 1 + slit_length) ;
+                    }
+                    if ( fabs( (float)(box_buffer->n_elements - 1) - pos
+                             + (float)edgeclean[k-1] - (float)margin - 
+                               last_pos ) < diff_tol )
+                    {
+                        slit_pos[k][1] = (float)(box_buffer->n_elements - 1) - 
+                                         pos
+                                       + (float)edgeclean[k-1] - (float)margin ;
+                    }
+                    else
+                    {
+                        sinfo_msg_warning("something wrong with fitted "
+                                          "right position of slitlet %d", j) ;
+                        slit_pos[k][1] = last_pos ;
+                    }
+                }
+            }
+
+            sinfo_new_destroy_vector ( half_buffer ) ;
+            cpl_free( xdat ) ;
+            cpl_free( wdat ) ;
+            cpl_free( mpar ) ;
+        }
+        sinfo_new_destroy_vector ( box_buffer ) ;
+    }
+     
+
+    cpl_free( sinfo_edge ) ;
+    cpl_free( pos_row ) ;
+    cpl_free( edgeclean ) ;
+    cpl_free( dummyedge ) ;
+    cpl_free( pos_rowclean ) ;
+    cpl_free( position);
+    return 0 ;
+}
+
+/**
+ at brief fits the beginning and end position of the slitlets by using 
+       non-linear least square fitting of a Boltzmann function
+ at param lineImage  emission line frame
+ at param slit_pos   allocated dummy array for the slitlet positions [min32][2]
+ at param box_length pixel length of the row box within the fit is done
+ at param y_box:      small box in spectral direction within the slitlet 
+                   may lie.
+ at param low_pos  pixel positions in spectral direction between which the line
+                       should be located.
+ at param high_pos pixel positions in spectral direction between which the line
+                       should be located.
+ at return      slit_pos:  beginning and end position of the slitlets to
+                                   sub-pixel accuracy
+          #               0  if it worked,
+          #              -1  if it failed,
+
+
+   @Note  fits the beginning and end position of the slitlets
+          by using non-linear least square fitting of a Boltzmann function
+          fits a Boltzmann function to the slitlet edges exposed and indicated
+          by the brightest emission lines. The slitlet is searched with
+          user given positions.
+          The least squares fit is done by using a box smaller than
+          the size of two slitlets
+ */
+
+int 
+sinfo_new_fit_slits_boltz_single_line ( cpl_image   * lineImage, 
+                              float     ** slit_pos,
+                              int          box_length,
+                              float        y_box,
+                  int          low_pos,
+                  int          high_pos )
+{
+    int*     position=NULL ;
+    int   * sinfo_edge, * edgeclean ;
+    int   * dummyedge ;
+    int   * pos_row, * pos_rowclean ;
+    Vector * box_buffer ;
+    Vector * half_buffer ;
+    Vector * in_buffer ;
+    int   found_row ;
+    int   row, col ;
+    int   i, j, k, m, ed ;
+    int   init1 ;
+    int   nel, n_right, left_right ;
+    int   n_buf, edge_ind, shift ;
+    int   slit_length ;
+    int   margin ;
+    int   iters, xdim, ndat ;
+    int   numpar, its ;
+    int   * mpar ;
+    float * xdat, * wdat ;
+    float tol, lab ;
+    float fitpar[NPAR] ;
+    float dervpar[NPAR] ;
+    float minval, maxval ;
+    float min ;
+    float pos, last_pos ;
+    int ilx=0;
+    int ily=0;
+    float* pidata=NULL;
+
+    slit_length = SLITLENGTH ;
+
+    if ( NULL == lineImage )
+    {
+        sinfo_msg_error(" no line image given!" ) ;
+        return -1 ;
+    }
+
+    if ( NULL == slit_pos )
+    {
+        sinfo_msg_error(" no position array allocated!" ) ;
+        return -1 ;
+    }
+
+    if ( box_length <  4 ||
+         box_length >  2*slit_length )
+    {
+        sinfo_msg_error(" wrong fitting box length given!" ) ;
+        return -1 ;
+    }
+
+    if ( y_box <= 0. || y_box > 6. )
+    {
+        sinfo_msg_error(" wrong y box length given!" ) ;
+        return -1 ;
+    }
+
+    ilx=cpl_image_get_size_x(lineImage);
+    ily=cpl_image_get_size_y(lineImage);
+    pidata=cpl_image_get_data_float(lineImage);
+
+    if ( low_pos >= high_pos || low_pos < 0 || 
+         high_pos <= 0 || high_pos >= ilx )
+    {
+        sinfo_msg_error(" wrong user given search positions!" ) ;
+        return -1 ;
+    }
+
+    /* allocate memory for the edges and the row position of the slitlets */
+    sinfo_edge         = (int*) cpl_calloc( ilx/2, sizeof(int) ) ;
+    dummyedge    = (int*) cpl_calloc( ilx/2, sizeof(int) ) ;
+    edgeclean    = (int*) cpl_calloc( ilx/2, sizeof(int) ) ;
+    pos_row      = (int*) cpl_calloc( ilx/2, sizeof(int) ) ;
+    pos_rowclean = (int*) cpl_calloc( ilx/2, sizeof(int) ) ;
+
+    /* now search for the maximum between the given positions for each col */
+    position=cpl_calloc(ilx,sizeof(int)); ;
+
+    for ( col = 0 ; col < ilx ; col++ )
+    {
+        found_row = -1 ;
+        maxval = -FLT_MAX ;
+    for ( row = low_pos ; row <= high_pos ; row++ )
+    {
+        if ( maxval < pidata[col+row*ilx] )
+            {
+        maxval = pidata[col+row*ilx] ;
+                found_row = row ;
+        }
+    }
+    if ( maxval > -FLT_MAX && found_row > low_pos )
+    {
+            position[col] = found_row ;
+        }
+    else
+    {
+        position[col] = 0 ;
+        }
+    }
+
+    /* now find and store the raw sinfo_edge positions of the found slitlet */ 
+    ed = 0 ;
+    for ( col = 0 ; col < (ilx) - 1 ; col++ )
+    {
+        if ( position[col] > 0 && position[col+1] > 0 &&
+         abs(position[col+1] - position[col]) > 10 ) 
+        {
+            sinfo_edge[ed] = col ; 
+            pos_row[ed] = position[col] ;
+            ed++ ;
+        }
+
+    }
+    if (ed <= 1)
+    {
+        sinfo_msg_error(" no slitlets found!" ) ;
+        cpl_free( sinfo_edge ) ;
+        cpl_free( pos_row ) ;
+        cpl_free( edgeclean ) ;
+        cpl_free( dummyedge ) ;
+        cpl_free( pos_rowclean ) ;
+        return -1 ;
+    }
+
+    /* now find the clean sinfo_edge and row positions of the slitlets */
+    for ( i = 1 ; i <= ed ; i ++ )
+    {
+        if ( i == ed )
+        {
+            if ( (sinfo_edge[i-1] - sinfo_edge[i-2]) < 
+                  slit_length - SLIT_LEN_ERR ||
+                 (sinfo_edge[i-1] - sinfo_edge[i-2]) > 
+                  slit_length + SLIT_LEN_ERR )
+            {
+                dummyedge[i-1]   = -1 ;
+            }
+        }
+        if (dummyedge[i-1] != -1)
+        {
+            dummyedge[i-1] = sinfo_edge[i-1] ;
+        }
+        else
+        {
+            continue ;
+        }
+        if ( i < ed )
+        {
+            if ( (sinfo_edge[i] - sinfo_edge[i-1]) < 
+                  slit_length - SLIT_LEN_ERR ||
+                 (sinfo_edge[i] - sinfo_edge[i-1]) > 
+                  slit_length + SLIT_LEN_ERR )
+            {
+                dummyedge[i]   = -1 ;
+            }
+        }
+        if ( i+1 < ed && dummyedge[i] != -1 )
+        {
+            if ( (sinfo_edge[i+1] - sinfo_edge[i]) < 
+                  slit_length - SLIT_LEN_ERR ||
+                 (sinfo_edge[i+1] - sinfo_edge[i]) > 
+                  slit_length + SLIT_LEN_ERR )
+            {
+                dummyedge[i+1] = -1 ; 
+            }
+        }
+    }
+    
+    k = 0 ;
+    for ( i = 0 ; i < ed ; i++ )
+    {
+        if ( dummyedge[i] != -1 && dummyedge[i] != 0 )
+        {
+            edgeclean[k] = dummyedge[i] ;
+            pos_rowclean[k] = pos_row[i] ;
+            k++ ;
+            if( edgeclean[k-1] > (ilx - slit_length - 2*SLIT_LEN_ERR ) )
+            {
+                pos_rowclean[k] = pos_row[ed] ;
+            }
+        }
+    }
+
+    /* determine the margins of the fitting box outside the slitlets */
+    margin = box_length / 2 ;
+
+    /* ------------------------------------------------------------------------
+     * now go through the slitlets, search along each column within a box with 
+     * half width y_box the maximum value and store these found values in a 
+     * buffer
+     */
+    for ( j = 0 ; j <= k ; j++ )
+    {
+        m = 0 ;
+        if ( j == 0 )
+        {
+            box_buffer = sinfo_new_vector( edgeclean[0] + margin ) ;
+            for( col = 0 ; col < edgeclean[0] + margin ; col++ )
+            {
+                maxval = -FLT_MAX ;
+                for ( row = pos_rowclean[0] - sinfo_new_nint(y_box) ; 
+                      row <= pos_rowclean[0] + sinfo_new_nint(y_box) ; row++ )
+                {
+                    if ( maxval < pidata[col + ilx*row] )
+                    {
+                        maxval = pidata[col + ilx*row] ;
+                    }
+                }
+                box_buffer->data[m] = maxval ;
+                m++ ;
+            }
+        }
+        else if ( j < k )
+        {
+            box_buffer = sinfo_new_vector( edgeclean[j] - 
+                                           edgeclean[j-1] + 2*margin ) ;
+            for ( col = edgeclean[j - 1] - margin ; 
+                  col < edgeclean[j] + margin ; col++ )
+            {
+                maxval = -FLT_MAX ;
+                for ( row = pos_rowclean[j] - sinfo_new_nint(y_box) ; 
+                      row <= pos_rowclean[j] + sinfo_new_nint(y_box) ; row++ )
+                {
+                    if ( maxval < pidata[col + ilx*row] )
+                    {
+                        maxval = pidata[col + ilx*row] ;
+                    }
+                }
+                box_buffer->data[m] = maxval ;
+                m++ ;
+            }
+        }
+        else 
+        {
+            box_buffer = sinfo_new_vector( ilx - edgeclean[k-1] + margin ) ;
+            for ( col = edgeclean[k - 1] - margin ; col < ilx ; col++ )
+            {
+        if ( col < 0 )
+        {
+            col = 0 ;
+                }
+
+                maxval = -FLT_MAX ;
+                for ( row = pos_rowclean[k] - sinfo_new_nint(y_box) ; 
+                      row <= pos_rowclean[k] + sinfo_new_nint(y_box) ; row++ )
+                {
+            if ( row < 0 )
+                    {
+            continue ;
+                    }
+                    if ( maxval < pidata[col + row * ilx] )
+                    {
+                        maxval = pidata[col + row * ilx] ;
+                    }
+                }
+                box_buffer->data[m] = maxval ;
+                m++ ;
+            }
+        }
+
+        /* determine the minimum value in the box to get background1 
+           value for the sinfo_edge slitlets */
+        min = FLT_MAX ;
+        for ( i = 0 ; i < box_buffer->n_elements ; i++ )
+        {
+            if ( box_buffer -> data[i] < min )
+            {
+                min = box_buffer -> data[i] ;
+            }
+        }
+
+        for ( left_right = 0 ; left_right <= 1 ; left_right++ )
+        { 
+            nel = 0 ;
+            if ( left_right == 0 )
+            {
+                nel = box_buffer -> n_elements / 2 ;
+            }
+            else
+            {
+                if ( box_buffer -> n_elements % 2 == 0 )
+                {
+                    nel = box_buffer -> n_elements / 2 ;
+                }
+                else
+                {
+                    nel = box_buffer -> n_elements / 2 + 1 ;
+                }
+            }
+
+            /* now split the buffer in the midth in a left and 
+               right part for fitting */
+            half_buffer = sinfo_new_vector( nel ) ;
+            if ( left_right == 0 )
+            {
+                for ( i = 0 ; i < nel ; i++ )
+                {
+                    half_buffer -> data[i] = box_buffer -> data[i] ;
+                }
+            }
+            else
+            {
+                n_right = 0 ;
+                for ( i = box_buffer -> n_elements - 1 ; 
+                      i >= box_buffer -> n_elements - nel ; i-- )
+                {
+                    half_buffer -> data[n_right] = box_buffer -> data[i] ;
+                    n_right++ ;
+                }
+            }
+
+            xdat = (float *) cpl_calloc( nel, sizeof (float) ) ;
+            wdat = (float *) cpl_calloc( nel, sizeof (float) ) ;
+            mpar = (int *)   cpl_calloc( NPAR, sizeof (int) ) ;
+
+            /* set initial values for the fitting routine */
+            minval =  FLT_MAX ;
+            maxval = -FLT_MAX ;
+            for ( i = 0 ; i < nel ; i++ )
+            {
+                xdat[i] = i ;
+                wdat[i] = 1.0 ;
+                if ( half_buffer -> data[i] < minval )
+                {
+                    minval = half_buffer -> data[i] ;
+                }
+                if ( half_buffer -> data[i] > maxval )
+                {
+                    maxval = half_buffer -> data[i] ;
+                }
+            }
+            fitpar[0] = minval ;
+            fitpar[1] = maxval ; 
+
+            /* search for both positions of the half intensity of 
+               the hat within the buffer */
+            init1 = -1 ; 
+            for ( i = 0 ; i < nel ; i++ )
+            {
+                if ( half_buffer -> data[i] >= ( maxval + minval ) / 2. )
+                {
+                    init1 = i ;
+                    break ;
+                }
+            }
+
+            /*---------------------------------------------------------------
+             * if we have too few left background values (at the image edges)
+             * the left margin of the buffer to fit is filled with the minimal
+             * values in order to get a good fit
+             */
+              
+            edge_ind = 0 ;
+            if ( init1 < 3 )
+            {
+                n_buf = half_buffer->n_elements + margin ;
+                in_buffer = sinfo_new_vector( n_buf ) ;     
+                for ( i = 0 ; i < margin ; i++ )
+                {
+                    in_buffer -> data[i] = min ;
+                }
+                shift = 0 ;
+                for ( i = margin ; i < n_buf ; i++ )
+                {
+                    in_buffer -> data[i] = half_buffer -> data[shift] ;
+                    shift++ ;
+                }
+                sinfo_new_destroy_vector ( half_buffer ) ;
+                half_buffer = sinfo_new_vector ( n_buf ) ;
+                for ( i = 0 ; i < n_buf ; i++ )
+                {
+                    half_buffer -> data[i] = in_buffer -> data[i] ;
+                }
+                edge_ind = 1 ;
+                init1 += margin ;
+                sinfo_new_destroy_vector ( in_buffer ) ;
+            }
+
+            /* determine the initial positions from the found values */
+            if ( init1 != -1 )
+            {
+                fitpar[2] = (float)init1 ;
+            }
+            fitpar[3] = 1. ;
+
+            for ( i = 0 ; i < NPAR ; i++ )
+            {
+                mpar[i] = 1 ;
+                dervpar[i] = 0. ;
+            }
+      
+            xdim     = XDIMA ;
+            ndat     = nel ;
+            numpar   = NPAR ;
+            tol      = TOLA ;
+            lab      = LABA ;
+            its      = ITSA ;
+         
+            /* finally, do the least squares fit over the buffer data */
+            if ( 0 > ( iters = sinfo_new_lsqfit( xdat, &xdim, 
+                                                 half_buffer -> data, 
+                                                 wdat, &ndat, fitpar,
+                                                 dervpar, mpar, &numpar, 
+                                                 &tol, &its, &lab )) )
+            { 
+                sinfo_msg_warning (" least squares fit failed, error "
+                                   "no.: %d in slitlet: %d", iters, j) ;
+                fitpar[2] = 0. ;
+            }
+        if ( fitpar[3] <=0. )
+            { 
+                sinfo_msg_warning(" fit failed due to negative width"
+                                  " of boltzmann function in slitlet: %d", j) ;
+                fitpar[2] = 0. ;
+            }
+
+            pos = fitpar[2] ;
+            if ( edge_ind == 1 )
+            {
+                pos -= (float)margin ;
+            }
+
+            /*------------------------------------------------------------- 
+             * now discern the left and the right sinfo_edge fit of the 
+             * slitlets and associate the fit results with the absolute 
+             * positions in the image consider the difference of the fitted 
+             * slit position to the expected position and decide wether the 
+             * fit is taken or the expected value is taken.
+             */
+            if ( left_right == 0 )
+            {
+                /* take care of the column position of the fit boxes to 
+                   get the absolute positions */
+                if ( j == 0 )
+                {
+                    slit_pos[0][0] = pos ;
+            if ( slit_pos[0][0] - (int) slit_pos[0][0] == 0.)
+            {
+                        slit_pos[0][0] = 0. ;
+                    }
+                }
+                else if ( j < k )
+                {
+                    slit_pos[j][0] = pos + (float)edgeclean[j-1] - 
+                                           (float)margin ;
+            if ( slit_pos[j][0] - (int) slit_pos[j][0] == 0.)
+            {
+                        slit_pos[j][0] = 0. ;
+                    }
+                }
+                else
+                {
+                    slit_pos[k][0] = pos + (float)edgeclean[k-1] - 
+                                           (float)margin ;
+            if ( slit_pos[k][0] - (int) slit_pos[k][0] == 0.)
+            {
+                        slit_pos[k][0] = 0. ;
+                    }
+                }
+            }
+            else
+            {
+                /* take care of the column position of the fit boxes to 
+                   get the absolute positions */
+                if ( j == 0 )
+                {
+                    slit_pos[0][1] = (float)(box_buffer->n_elements - 1) - pos;
+            if ( slit_pos[0][1] - (int) slit_pos[0][1] == 0.)
+            {
+                        slit_pos[0][1] = 0. ;
+                    }
+                }
+                else if ( j < k )
+                {
+                    slit_pos[j][1] = (float)(box_buffer->n_elements - 1) - pos
+                                     + (float)edgeclean[j-1] - (float)margin ;
+            if ( slit_pos[j][1] - (int) slit_pos[j][1] == 0.)
+            {
+                        slit_pos[j][1] = 0. ;
+                    }
+                }
+                else
+                {
+                    last_pos = (float)(edgeclean[k-1] - 1 + slit_length) ;
+                    slit_pos[k][1] = (float)(box_buffer->n_elements - 1) - pos
+                                     + (float)edgeclean[k-1] - (float)margin ;
+            if ( slit_pos[k][1] - (int) slit_pos[k][1] == 0.)
+            {
+                        slit_pos[k][1] = 0. ;
+                    }
+                }
+            }
+
+            sinfo_new_destroy_vector ( half_buffer ) ;
+            cpl_free( xdat ) ;
+            cpl_free( wdat ) ;
+            cpl_free( mpar ) ;
+        }
+        sinfo_new_destroy_vector ( box_buffer ) ;
+    }
+        
+    cpl_free( sinfo_edge ) ;
+    cpl_free( pos_row ) ;
+    cpl_free( edgeclean ) ;
+    cpl_free( dummyedge ) ;
+    cpl_free( pos_rowclean ) ;
+    cpl_free( position );
+    return 0 ;
+}
+
+/**
+ at brief its the beginning and end position of the slitlets by using 
+         non-linear least square fitting of a Boltzmann function
+
+ at param lineImage  emission line frame
+ at param slit_pos   estimation array for the slitlet positions [min32][2]
+ at param box_length pixel length of the row box within the fit is done
+ at param y_box      small box in spectral direction within the slitlet 
+                  may lie.
+ at param diff_tol   tolerance on slitlets position
+ at param low_pos  pixel positions in spectral direction between which the line
+        should be located.
+ at param high_pos pixel positions in spectral direction between which the line
+            should be located.
+
+ at return slit_pos  beginning and end position of the slitlets to
+                   sub-pixel accuracy
+            #             0  if it worked,
+            #            -1  if it failed,
+   @note fits the beginning and end position of the slitlets
+         by using non-linear least square fitting of a Boltzmann function
+         fits a Boltzmann function to the slitlet edges exposed and indicated
+         by the brightest emission lines. The slitlet is searched within
+     user given positions.
+         The least squares fit is done by using a box smaller than
+         the size of two slitlets 
+*/
+
+int 
+sinfo_new_fit_slits_boltz_with_estimate ( cpl_image   * lineImage, 
+                                float     ** slit_pos,
+                                int          box_length,
+                                float        y_box,
+                                float        diff_tol,
+                    int          low_pos,
+                    int          high_pos )
+{
+    int*     position=NULL ;
+    Vector * box_buffer ;
+    Vector * in_buffer ;
+    int   found_row ;
+    int   row, col ;
+    int   col_first, col_last ;
+    int   row_first, row_last ;
+    int   i, j, m, n ;
+    int   init1 ;
+    int   left_right ;
+    int   n_buf, shift ;
+    int   slit_length ;
+    int   iters, xdim, ndat ;
+    int   numpar, its ;
+    int   * mpar ;
+    float * xdat, * wdat ;
+    float tol, lab ;
+    float fitpar[NPAR] ;
+    float dervpar[NPAR] ;
+    float minval, maxval ;
+    float pos ;
+    float new_pos ;
+    int   slitposition[SLITLENGTH] ;
+    pixelvalue rowpos[SLITLENGTH] ;
+
+    int ilx=0;
+    int ily=0;
+    float* pidata=NULL;
+
+    slit_length = SLITLENGTH ; /* this setting is too much 64 */
+    slit_length = N_SLITLETS ; /* this setting is better: 32 */
+
+    if ( NULL == lineImage )
+    {
+        sinfo_msg_error(" no line image given!" ) ;
+        return -1 ;
+    }
+
+    if ( NULL == slit_pos )
+    {
+        sinfo_msg_error(" no position array allocated!" ) ;
+        return -1 ;
+    }
+
+    if ( box_length < 4 ||
+         box_length > 2*slit_length )
+    {
+        sinfo_msg_error(" wrong fitting box length given!" ) ;
+        return -1 ;
+    }
+
+    if ( y_box <= 0. || y_box > 6. )
+    {
+        sinfo_msg_error(" wrong y box length given!" ) ;
+        return -1 ;
+    }
+    if ( diff_tol <= 0. )
+    {
+        sinfo_msg_error(" wrong diff_tol given!" ) ;
+        return -1 ;
+    }
+
+    ilx=cpl_image_get_size_x(lineImage);
+    ily=cpl_image_get_size_y(lineImage);
+    pidata=cpl_image_get_data_float(lineImage);
+
+    if ( low_pos >= high_pos || low_pos < 0 || 
+         high_pos <= 0 || high_pos > ily )
+    {
+        sinfo_msg_error(" wrong user given search positions!" ) ;
+        return -1 ;
+    }
+
+    /* now search for the maximum between the given positions for each col */
+    position=cpl_calloc(ilx,sizeof(int)) ;
+    for ( col = 0 ; col < ilx ; col++ )
+    {
+        found_row = -1 ;
+        maxval = -FLT_MAX ;
+    for ( row = low_pos ; row <= high_pos ; row++ )
+    {
+        if ( maxval < pidata[col+row*ilx] )
+            {
+        maxval = pidata[col+row*ilx] ;
+                found_row = row ;
+        }
+    }
+    if ( maxval > -FLT_MAX && found_row > low_pos )
+    {
+            position[col] = found_row ;
+        }
+    else
+    {
+        position[col] = 0 ;
+        }
+    }
+    
+    /* ------------------------------------------------------------------------
+     * now go through the slitlets, search along each column within a box with 
+     * half width y_box the maximum value and store these found values in a 
+     * buffer
+     */
+    for ( j = 0 ; j < slit_length ; j++ )
+    {
+        /* now go through the columns and determine the slitlet positions by
+         * calculating the median of the found positions 
+         */
+        n = 0 ;
+        
+        for ( col = sinfo_new_nint(slit_pos[j][0])+ 1 ; 
+              col < sinfo_new_nint(slit_pos[j][1]) -1 ; col++ )
+        {
+            rowpos[n] = (pixelvalue)position[col] ;
+            n++ ;
+        }
+
+        slitposition[j] = (int)sinfo_new_median(rowpos, n) ;
+        for ( left_right = 0 ; left_right <= 1 ; left_right++ )
+        {
+            init1 = 0 ;
+            col_first = sinfo_new_nint( slit_pos[j][left_right] ) - 
+                                        box_length/2 ;
+            col_last  = sinfo_new_nint( slit_pos[j][left_right] ) + 
+                                        box_length/2 ;
+            if ( col_first < 0 )
+            {
+                col_first = 0 ;
+                init1 = 1 ;
+            }
+            if ( col_last > ilx )
+            {
+                col_last = ilx ;
+                init1 = 1 ;
+            }
+            if ( col_last - col_first <= 0 )
+            {
+                sinfo_msg_error(" first and last column wrong!" ) ;
+                return -1 ;
+            }
+            box_buffer = sinfo_new_vector( col_last - col_first ) ;
+            m = 0 ;
+
+
+            if ( left_right == 0 )
+            {
+                for( col = col_first ; col < col_last ; col++ )
+                {
+                    row_first = slitposition[j] - sinfo_new_nint(y_box) ;
+                    row_last  = slitposition[j] + sinfo_new_nint(y_box) ;
+                    if ( row_first < 0 )
+                    {
+                        row_first = 0 ;
+                    }
+                    if ( row_last >= ily  )
+                    {
+                        row_last = ily - 1 ;
+                    }
+                    maxval = -FLT_MAX ;
+                    for ( row = row_first ; row <= row_last ; row++ )
+                    {
+                        if ( maxval < pidata[col + ilx*row] )
+                        {
+                            maxval = pidata[col + ilx*row] ;
+                        }
+                    }
+                    box_buffer->data[m] = maxval ;
+                    m++ ;
+                }
+
+            }
+            else 
+            {
+
+                for( col = col_last-1 ; col >= col_first ; col-- )
+                {
+                    row_first = slitposition[j] - sinfo_new_nint(y_box) ;
+                    row_last  = slitposition[j] + sinfo_new_nint(y_box) ;
+                    if ( row_first < 0 )
+                    {
+                        row_first = 0 ;
+                    }
+                    if ( row_last >= ily  )
+                    {
+                        row_last = ily - 1 ;
+                    }
+                    maxval = -FLT_MAX ;
+                    for ( row = row_first ; row <= row_last ; row++ )
+                    {
+                        if ( maxval < pidata[col + ilx*row] )
+                        {
+                            maxval = pidata[col + ilx*row] ;
+                        }
+                    }
+                    box_buffer->data[m] = maxval ;
+                    m++ ;
+                }
+
+            }
+
+            xdat=(float *) cpl_calloc(box_buffer->n_elements, sizeof (float) );
+            wdat=(float *) cpl_calloc(box_buffer->n_elements, sizeof (float) );
+            mpar=(int *)   cpl_calloc(NPAR, sizeof (int) ) ;
+
+            /* set initial values for the fitting routine */
+            minval =  FLT_MAX ;
+            maxval = -FLT_MAX ;
+
+            for ( i = 0 ; i < box_buffer->n_elements ; i++ )
+            {
+                xdat[i] = i ;
+                wdat[i] = 1.0 ;
+                if ( box_buffer -> data[i] < minval )
+                {
+                    minval = box_buffer -> data[i] ;
+                }
+                if ( box_buffer -> data[i] > maxval )
+                {
+                    maxval = box_buffer -> data[i] ;
+                }
+            }
+            fitpar[0] = minval ;
+            fitpar[1] = maxval ; 
+
+            /*-----------------------------------------------------------------
+             * if we have too few left background values (at the image edges)
+             * the left margin of the buffer to fit is filled with the minimal
+             * values in order to get a good fit
+             */
+            
+  
+            if ( init1 == 1 )
+            {
+                n_buf = box_buffer->n_elements + box_length/2 ;
+                in_buffer = sinfo_new_vector( n_buf ) ;     
+                for ( i = 0 ; i < box_length/2 ; i++ )
+                {
+                    in_buffer -> data[i] = minval ;
+                }
+                shift = 0 ;
+                for ( i = box_length/2 ; i < n_buf ; i++ )
+                {
+                    in_buffer -> data[i] = box_buffer -> data[shift] ;
+                    shift++ ;
+                }
+                sinfo_new_destroy_vector ( box_buffer ) ;
+                box_buffer = sinfo_new_vector ( n_buf ) ;
+                for ( i = 0 ; i < n_buf ; i++ )
+                {
+                    box_buffer -> data[i] = in_buffer -> data[i] ;
+                }
+                sinfo_new_destroy_vector ( in_buffer ) ;
+            }
+
+            /* determine the initial positions from the found values */
+            fitpar[2] = (float)box_buffer->n_elements/2.  ;
+            fitpar[3] = 1. ;
+
+            for ( i = 0 ; i < NPAR ; i++ )
+            {
+                mpar[i] = 1 ;
+                dervpar[i] = 0. ;
+            }
+      
+            xdim     = XDIMA ;
+            ndat     = box_buffer->n_elements ;
+            numpar   = NPAR ;
+            tol      = TOLA ;
+            lab      = LABA ;
+            its      = ITSA ;
+         
+            /* finally, do the least squares fit over the buffer data */
+            if ( 0 > ( iters = sinfo_new_lsqfit( xdat, &xdim, 
+                                                 box_buffer -> data, 
+                                                 wdat, &ndat, fitpar,
+                                                 dervpar, mpar, &numpar, 
+                                                 &tol, &its, &lab )) )
+            { 
+                sinfo_msg_warning ("least squares fit failed, error "
+                                   "no.: %d in slitlet: %d\n", iters, j) ;
+                sinfo_new_destroy_vector(box_buffer) ;
+                cpl_free( xdat ) ;
+                cpl_free( wdat ) ;
+                cpl_free( mpar ) ;
+                continue ;
+            }
+
+        if ( fitpar[3] <=0. )
+            { 
+                sinfo_msg_warning ("fit failed due to negative width of "
+                                   "boltzmann function in slitlet: %d\n", j) ;
+                sinfo_new_destroy_vector(box_buffer) ;
+                cpl_free( xdat ) ;
+                cpl_free( wdat ) ;
+                cpl_free( mpar ) ;
+                continue ;
+            }
+            pos = fitpar[2] ;
+            if ( init1 == 1 )
+            {
+                pos -= (float)box_length/2. ;
+            }
+
+            /*-------------------------------------------------------------
+             * now compute the real slit positions using the guess positions
+             * if the fit did not work the guess positions are taken
+             * the same is done if the deviations are too big.
+             */
+            if ( pos != 0. )  
+            {
+                if ( left_right == 0 )
+                {
+                    new_pos = (float)col_first + pos ;
+                }
+                else
+                {
+                    new_pos = (float)col_last-1 - pos ;
+                }
+                if ( fabs(new_pos - slit_pos[j][left_right]) < diff_tol )
+                {
+                    slit_pos[j][left_right] = new_pos ;
+                }
+                else
+                {
+                    sinfo_msg_warning (" deviation bigger than tolerance,"
+                                       " take the estimated slitlet position "
+                                       " in slitlet: %d\n", j) ;
+                }
+            }
+
+            cpl_free( xdat ) ;
+            cpl_free( wdat ) ;
+            cpl_free( mpar ) ;
+            sinfo_new_destroy_vector ( box_buffer ) ;
+
+        }
+    }
+    cpl_free(position);
+    return 0 ;
+}
+                              
+/*--------------------------------------------------------------------------*/
+/**@}*/
diff --git a/sinfoni/sinfo_bp_config.c b/sinfoni/sinfo_bp_config.c
new file mode 100644
index 0000000..08075ae
--- /dev/null
+++ b/sinfoni/sinfo_bp_config.c
@@ -0,0 +1,81 @@
+/* $Id: sinfo_bp_config.c,v 1.5 2012/03/02 08:42:20 amodigli Exp $
+ *
+ * This file is part of the CPL (Common Pipeline Library)
+ * Copyright (C) 2002 European Southern Observatory
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*
+ * $Author: amodigli $
+ * $Date: 2012/03/02 08:42:20 $
+ * $Revision: 1.5 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+ /****************************************************************
+  *           Bad pixel search                                   *
+  ****************************************************************/
+
+#include "sinfo_bp_config.h"
+ /**@{*/
+/**
+ * @addtogroup sinfo_bad_pix_search Bad Pixel Search
+ *
+ * TBD
+ */
+
+ /**
+  * @brief
+  *   Adds parameters for the spectrum extraction
+  *
+  * @param list Parameter list to which parameters are added.
+  *
+  * @return Nothing.
+  *
+  * TBD
+  */
+
+  /* Bad pixel parameters */
+
+void
+ sinfo_bp_config_add(cpl_parameterlist *list)
+{
+
+  cpl_parameter *p;
+
+  if (!list) {
+    return;
+  }
+
+  /* indicates which method will be used */
+  p = cpl_parameter_new_enum("sinfoni.bp.method",
+                  CPL_TYPE_STRING,
+                              "Data reduction method: ",
+                              "sinfoni.general_noise",
+                              "Normal",
+                              3,
+                              "Normal","Linear","Noise");
+
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "bp-method");
+  cpl_parameterlist_append(list, p);
+
+  return;
+
+}
+/**@}*/
diff --git a/sinfoni/sinfo_bp_config.h b/sinfoni/sinfo_bp_config.h
new file mode 100644
index 0000000..0621f06
--- /dev/null
+++ b/sinfoni/sinfo_bp_config.h
@@ -0,0 +1,37 @@
+/* $Id: sinfo_bp_config.h,v 1.1 2006/10/20 08:06:32 amodigli Exp $
+ *
+ * This file is part of the CPL (Common Pipeline Library)
+ * Copyright (C) 2002 European Southern Observatory
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*
+ * $Author: amodigli $
+ * $Date: 2006/10/20 08:06:32 $
+ * $Revision: 1.1 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+ /****************************************************************
+  *           Bad pixel search  (normal method)                  *
+  ****************************************************************/
+#ifndef SINFO_BP_CONFIG_H
+#define SINFO_BP_CONFIG_H
+
+#include "cpl.h"  
+
+void sinfo_bp_config_add(cpl_parameterlist *list);
+
+#endif
diff --git a/sinfoni/sinfo_bp_dist_config.c b/sinfoni/sinfo_bp_dist_config.c
new file mode 100644
index 0000000..a0641ba
--- /dev/null
+++ b/sinfoni/sinfo_bp_dist_config.c
@@ -0,0 +1,273 @@
+/* $Id: sinfo_bp_dist_config.c,v 1.4 2007/06/06 07:10:45 amodigli Exp $
+ *
+ * This file is part of the CPL (Common Pipeline Library)
+ * Copyright (C) 2002 European Southern Observatory
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*
+ * $Author: amodigli $
+ * $Date: 2007/06/06 07:10:45 $
+ * $Revision: 1.4 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+ /****************************************************************
+  *           Bad pixel search  (normal method)                  *
+  ****************************************************************/
+#include "sinfo_bp_dist_config.h"
+/**
+ * @addtogroup sinfo_bad_pix_search Bad Pixel Search
+ *
+ * TBD
+ */
+
+ /**@{*/
+ /**
+  * @brief
+  *   Adds parameters for the spectrum extraction
+  *
+  * @param list Parameter list to which parameters are added.
+  *
+  * @return Nothing.
+  *
+  * TBD
+  */
+
+  /* Bad pixel parameters */
+
+void
+ sinfo_bp_dist_config_add(cpl_parameterlist *list)
+{
+  cpl_parameter *p;
+
+  if (!list) {
+    return;
+  }
+
+
+
+/* factor of noise within which the pixels are used to fit a straight line 
+   to the column intensity */
+  p = cpl_parameter_new_value("sinfoni.bp_dist.sigma_factor",
+                  CPL_TYPE_DOUBLE,
+                              "Threshold Sigma Factor: "
+                              "to remove the column intensity tilt only "
+                              "pixels which lie within a defined noise"
+                              "limit are used to fit a straight line",
+                              "sinfoni.bp_dist",
+                              2.0);
+
+  cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI, "bp_dist-s_factor");
+  cpl_parameterlist_append(list, p);
+
+  /* bad pixel search determination method */
+ p = cpl_parameter_new_enum("sinfoni.bp_dist.method_index",
+                  CPL_TYPE_INT,
+                              "Bad pixel Method Index"
+                              "1: median of nearest neighbors,"
+                              "2: absolute distances check, "
+                              "3: mean of nearest spectral neighbors",
+                              "sinfoni.bp_dist",
+                              1,
+                              3,1,2,3);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"bp_dist-method_ind");
+  cpl_parameterlist_append(list, p);
+
+  /* factor of calculated standard deviation beyond which the deviation 
+     of a pixel value from the median of the 8 nearest neighbors declares 
+     a pixel as bad */
+  p = cpl_parameter_new_value("sinfoni.bp_dist.factor",
+                  CPL_TYPE_DOUBLE,
+                              "Factor: "
+           "if |pixel - sinfo_median| > factor * standard deviation -> "
+                              "then the pixel value is replaced by "
+                              "the median of the 8 nearest neighbors",
+                              "sinfoni.bp_dist",
+                              999.0);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"bp_dist-fct");
+  cpl_parameterlist_append(list, p);
+
+ /* no of iterations to find bad pix clusters */
+  /* number of iterations of sinfo_median filter */
+  p = cpl_parameter_new_value("sinfoni.bp_dist.iterations",
+                  CPL_TYPE_INT,
+                              "Iterations: number of iterations to of median"
+                              " filtering to find bad pixel clusters",
+                              "sinfoni.bp_dist",
+                              8);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"bp_dist-it");
+  cpl_parameterlist_append(list, p);
+
+  /* float 
+     threshold used in the clean mean percentage of rejection used to reject 
+     low and high frame */
+ /* percentage of extreme pixel value to reject when calculating the mean 
+    and stdev */
+  p = cpl_parameter_new_range("sinfoni.bp_dist.low_rejection",
+                  CPL_TYPE_DOUBLE,
+                              "low_rejection: "
+                              "percentage of rejected low intensity "
+                              "pixels before averaging",
+                              "sinfoni.bp_dist",
+                              0.1,0.0,1.0);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"bp_dist-lo_rej");
+  cpl_parameterlist_append(list, p);
+
+  /* float 
+     threshold used in the clean mean percentage of rejection used to reject 
+     low and high frame */
+ /* percentage of extreme pixel value to reject when calculating the mean 
+    and stdev */
+  p = cpl_parameter_new_range("sinfoni.bp_dist.high_rejection",
+                  CPL_TYPE_DOUBLE,
+                              "high_rejection: "
+                              "percentage of rejected high intensity "
+                              "pixels before averaging",
+                              "sinfoni.bp_dist",
+                              0.1,0.0,1.0);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"bp_dist-hi_rej");
+  cpl_parameterlist_append(list, p);
+
+
+  /* position in the frame lower left in X */
+  /* pixel coordinate of lower left sinfo_edge of a rectangle zone from which 
+     image statistics are computed */
+  p = cpl_parameter_new_range("sinfoni.bp_dist.llx",
+                  CPL_TYPE_INT,
+                              "llx: "
+                              "to compute image statistics on a rectangular"
+                              "zone of the image the coordinates of the "
+                              "rectangle are needed:" 
+                              "lower left x coordinate",
+                              "sinfoni.bp_dist",
+                              1350,DET_PIX_MIN,DET_PIX_MAX);
+  /* 1000 */
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"bp_dist-llx");
+  cpl_parameterlist_append(list, p);
+
+
+
+  /* position in the frame lower left in Y */
+  /* pixel coordinate of lower left sinfo_edge of a rectangle zone from which 
+     image statistics are computed */
+  p = cpl_parameter_new_range("sinfoni.bp_dist.lly",
+                  CPL_TYPE_INT,
+                              "lly: "
+                              "to compute image statistics on a rectangular"
+                              "zone of the image the coordinates of the "
+                              "rectangle are needed:" 
+                              "lower left y coordinate",
+                              "sinfoni.bp_dist",
+                              1000,DET_PIX_MIN,DET_PIX_MAX);
+  /* 1000 */
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"bp_dist-lly");
+  cpl_parameterlist_append(list, p);
+
+  /* Upper right position in CCD : should be urx */
+  /* pixel coordinate of upper right sinfo_edge of a rectangle zone from which 
+    image statistics are computed */
+  p = cpl_parameter_new_range("sinfoni.bp_dist.urx",
+                  CPL_TYPE_INT,
+                              "urx: "
+                              "to compute image statistics on a rectangular"
+                              "zone of the image the coordinates of the "
+                              "rectangle are needed:" 
+                              "upper right x coordinate",
+                              "sinfoni.bp_dist",
+                              1390,DET_PIX_MIN,DET_PIX_MAX);
+  /* 1350*/
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"bp_dist-urx");
+  cpl_parameterlist_append(list, p);
+
+  /* Upper right position in CCD : should be ury */
+  /* pixel coordinate of upper right sinfo_edge of a rectangle zone from which 
+    image statistics are computed */
+  p = cpl_parameter_new_range("sinfoni.bp_dist.ury",
+                  CPL_TYPE_INT,
+                              "ury: "
+                              "to compute image statistics on a rectangular"
+                              "zone of the image the coordinates of the "
+                              "rectangle are needed:" 
+                              "upper right y coordinate",
+                              "sinfoni.bp_dist",
+                              1200,DET_PIX_MIN,DET_PIX_MAX);
+  /* 1390 */
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"bp_dist-ury");
+  cpl_parameterlist_append(list, p);
+
+  /* boolean (implemented as integer) useda s a switch */
+  /* indicates if the values beyond threshold values should be marked 
+     as bad before proceeding to sinfo_median filtering */
+  p = cpl_parameter_new_value("sinfoni.bp_dist.threshold_index",
+                  CPL_TYPE_BOOL,
+                              "Threshold Index: "
+                              "indicator that indicates if the values "
+                              "beyond a threshold deviation from the mean "
+                              "are flagged as bad pixels",
+                              "sinfoni.bp_dist",
+                              TRUE);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"bp_dist-thr_ind");
+  cpl_parameterlist_append(list, p);
+
+  /* threshold value. Float. Threshold used to find bad pixel */
+  /* factor to the clean standard deviation to define the threshold 
+     deviation from the clean mean */
+  p = cpl_parameter_new_range("sinfoni.bp_dist.mean_factor",
+                  CPL_TYPE_DOUBLE,
+                              "Mean Factor: "
+                              "factor to the clean standard deviation to "
+                              "define the threshold deviation from the "
+                              "clean mean",
+                              "sinfoni.bp_dist",
+                              999.,0.1,1.e10);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"bp_dist-mean_fct");
+  cpl_parameterlist_append(list, p);
+
+
+
+  p = cpl_parameter_new_value("sinfoni.bp_dist.min_cut",
+                  CPL_TYPE_DOUBLE,
+                              "the minimum value of real data",
+                              "sinfoni.bp_dist",
+                              0.1);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"bp_dist-min_cut");
+  cpl_parameterlist_append(list, p);
+
+
+  p = cpl_parameter_new_value("sinfoni.bp_dist.max_cut",
+                  CPL_TYPE_DOUBLE,
+                              "the minimum value of real data",
+                              "sinfoni.bp_dist",
+                              50000.);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"bp_dist-max_cut");
+  cpl_parameterlist_append(list, p);
+
+  return;
+
+}
+/**@}*/
diff --git a/sinfoni/sinfo_bp_dist_config.h b/sinfoni/sinfo_bp_dist_config.h
new file mode 100644
index 0000000..92ff437
--- /dev/null
+++ b/sinfoni/sinfo_bp_dist_config.h
@@ -0,0 +1,41 @@
+/* $Id: sinfo_bp_dist_config.h,v 1.1 2006/10/20 08:06:32 amodigli Exp $
+ *
+ * This file is part of the CPL (Common Pipeline Library)
+ * Copyright (C) 2002 European Southern Observatory
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*
+ * $Author: amodigli $
+ * $Date: 2006/10/20 08:06:32 $
+ * $Revision: 1.1 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+ /****************************************************************
+  *           Bad pixel search  (normal method)                  *
+  ****************************************************************/
+#ifndef SINFO_BP_DIST_CONFIG_H
+#define SINFO_BP_DIST_CONFIG_H
+
+#include "cpl.h"  
+/*
+#include "sinfo_dfs.h"
+*/
+#include "sinfo_globals.h"
+
+void sinfo_bp_dist_config_add(cpl_parameterlist *list);
+
+#endif
diff --git a/sinfoni/sinfo_bp_lin.c b/sinfoni/sinfo_bp_lin.c
new file mode 100644
index 0000000..48e735e
--- /dev/null
+++ b/sinfoni/sinfo_bp_lin.c
@@ -0,0 +1,385 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+
+   File name    :       sinfo_bp_lin.c
+   Author       :    J. Schreiber
+   Created on   :    May 5, 2003
+   Description  :    Different methods for searching for bad pixels
+                        used in the recipe spiffi_badsearch
+
+ ---------------------------------------------------------------------------*/
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+/*----------------------------------------------------------------------------
+                                Includes
+ ---------------------------------------------------------------------------*/
+//#include <cpl_imagelist_basic.h>
+#include <cpl.h>
+#include "sinfo_bp_lin.h"
+#include "sinfo_detlin.h"
+#include "sinfo_detlin_ini_by_cpl.h"
+#include "sinfo_pro_save.h"
+#include "sinfo_pro_types.h"
+#include "sinfo_functions.h"
+#include "sinfo_hidden.h"
+#include "sinfo_error.h"
+#include "sinfo_utils_wrappers.h"
+
+
+/**
+ * @addtogroup sinfo_bad_pix_search Bad Pixel Search
+ *
+ * TBD
+ */
+
+/*----------------------------------------------------------------------------
+                                Defines
+ ---------------------------------------------------------------------------*/
+/*----------------------------------------------------------------------------
+                             Function Definitions
+ ---------------------------------------------------------------------------*/
+/**
+   @name sinfo_new_bp_search_lin
+   @memo Search pixels which have a non linear response
+   @param   plugin_id recipe name
+   @param   config input parameters list
+   @param   sof  input set of frames
+
+   @returns integer (0 if it worked, -1 if it doesn't)
+   @doc
+   this function searches for static bad pixels in stacks of flatfield frames
+   with in/decreasing intensities. For each pixel position a curve is plotted
+   of the pixel intensity in each plane against the clean mean of the whole
+   plane.
+
+   A polynomial is fit and the found coefficients are stored sequentially in
+   a data cube. Then the deviation of the linear coefficients from the clean
+   mean is computed for each pixel and the pixel are declared bad if the
+   deviations exceed a threshold defined by a factor of the clean standard
+   deviation.
+
+   For the resting good pixels the non-linear coefficients are examined.
+   If one coefficients deviate more than a user given threshold the pixel
+   is also declared as bad. The data cubus with the fit results and
+   a bad pixel mask image is stored
+
+ */
+int
+sinfo_new_bp_search_lin(const char* plugin_id,
+                        cpl_parameterlist* config,
+                        cpl_frameset* sof)
+{
+  detlin_config * cfg=NULL;
+  cpl_imagelist * imgl=NULL ;
+  cpl_imagelist * coeffs_imgl=NULL;
+  cpl_image * img_tmp=NULL ;
+  cpl_image * mask=NULL;
+  cpl_vector* cube_mean=NULL;
+  cpl_frameset* raw=NULL;
+  cpl_frameset* raw_on=NULL;
+  cpl_frameset* raw_of=NULL;
+  cpl_frame* frm=NULL;
+  cpl_frame* frm_dup=NULL;
+
+  cpl_table* qclog_tbl=NULL;
+
+  cpl_parameter *p=NULL;
+  cpl_polynomial *pol=NULL;
+  cpl_vector* vec_adl=NULL;
+  cpl_vector* vec_med=NULL;
+  double* mse=NULL;
+  int i=0;
+  int n_bad=0 ;
+  int nff=0;
+  char key_value[FILE_NAME_SZ];
+  char key_name[FILE_NAME_SZ];
+  cpl_table* det_lin=NULL;
+  int nraw=0;
+  int* status=NULL;
+  cpl_table* gain=NULL;
+  int ngain=0;
+  int sz_imgl=0;
+
+  int llx=270;
+  int lly=1030;
+  int urx=310;
+  int ury=1060;
+  int zone[4];
+  //int kappa=5;
+  //int nclip=25;
+  int pdensity=0;
+
+
+  check_nomsg(p=cpl_parameterlist_find(config,"sinfoni.product.density"));
+  check_nomsg(pdensity=cpl_parameter_get_int(p));
+
+
+  /* parse the file names and parameters to the bad_config
+     data structure cfg */
+  check_nomsg(raw=cpl_frameset_new());
+  cknull(cfg = sinfo_parse_cpl_input_detlin(config,sof,&raw),
+	 "could not parse .ini file!");
+
+  /* ======================================================================
+     DETERMINES LINEARITY COEFF AS DFO DOES
+     ======================================================================
+  */
+  nff=cpl_frameset_get_size(raw);
+  raw_on=cpl_frameset_new();
+  raw_of=cpl_frameset_new();
+  /* separates on and off frames */
+
+  for(i=0;i<nff;i++) {
+    frm=cpl_frameset_get_frame(raw,i);
+    frm_dup=cpl_frame_duplicate(frm);
+    if(sinfo_frame_is_on(frm)) {
+      cpl_frameset_insert(raw_on,frm_dup);
+    } else {
+      cpl_frameset_insert(raw_of,frm_dup);
+    }
+  }
+  /*
+    cknull(det_lin=sinfo_get_linearity(raw_on,raw_of),
+    "Error computing linearity");
+  */
+  zone[0]=llx;
+  zone[1]=lly;
+  zone[2]=urx;
+  zone[3]=ury;
+
+  //If one refers to a larger area
+  zone[0]=20;
+  zone[1]=2028;
+  zone[2]=20;
+  zone[3]=2028;
+
+  /*
+    cknull(det_lin=irplib_compute_linearity(raw_on,raw_of),
+    "Error computing linearity");
+  */
+
+  if(pdensity > 1 ) {
+
+    sinfo_msg("Computes linearity");
+    cknull(det_lin=sinfo_compute_linearity(raw_on,raw_of),
+	   "Error computing linearity");
+
+    check_nomsg(nraw=cpl_table_get_nrow(det_lin));
+    check_nomsg(vec_adl=cpl_vector_new(nraw));
+    check_nomsg(vec_med=cpl_vector_new(nraw));
+
+    for(i=0;i<nraw;i++) {
+      cpl_vector_set(vec_adl,i,cpl_table_get_double(det_lin,"adl",i,status));
+      cpl_vector_set(vec_med,i,cpl_table_get_double(det_lin,"med",i,status));
+    }
+    check_nomsg(pol=sinfo_polynomial_fit_1d_create(vec_adl,vec_med,
+						 cfg->order,mse));
+    sinfo_free_my_vector(&vec_adl);
+    sinfo_free_my_vector(&vec_med);
+
+    cknull_nomsg(qclog_tbl=sinfo_qclog_init());
+    cpl_size deg=0;
+    for(deg=0;deg<cfg->order+1;deg++) {
+
+      snprintf(key_name,MAX_NAME_SIZE-1,"%s%" CPL_SIZE_FORMAT "%s","QC BP-MAP LIN",deg," MED");
+      sinfo_qclog_add_double(qclog_tbl,key_name,
+			     cpl_polynomial_get_coeff(pol,&deg),
+			     "Linearity Polynomial Coeff","%g");
+    }
+    sinfo_free_polynomial(&pol);
+
+    check_nomsg(p = cpl_parameterlist_find(config, "sinfoni.bp.method"));
+    snprintf(key_value, MAX_NAME_SIZE-1,"%s",cpl_parameter_get_string(p));
+    ck0_nomsg(sinfo_qclog_add_string(qclog_tbl,"QC BP-MAP METHOD",key_value,
+				     "BP search method","%s"));
+
+    ck0(sinfo_pro_save_tbl(det_lin,raw,sof,BP_LIN_LIN_DET_INFO_OUT_FILENAME,
+			   PRO_LIN_DET_INFO,qclog_tbl,plugin_id,config),
+	"cannot dump ims %s",BP_LIN_LIN_DET_INFO_OUT_FILENAME);
+
+    sinfo_free_table(&det_lin);
+    sinfo_free_table(&qclog_tbl);
+  }
+
+  /*=======================================================*/
+  if(pdensity > 1 ) {
+    sinfo_msg("Computes gain");
+
+    cknull(gain=sinfo_compute_gain(raw_on,raw_of),"Error computing gain");
+
+    //cknull(gain=irplib_compute_gain(raw_on,raw_of,zone,kappa,nclip),
+    //         "Error computing gain");
+
+    sinfo_free_frameset(&raw_on);
+    sinfo_free_frameset(&raw_of);
+
+    check_nomsg(ngain=cpl_table_get_nrow(gain));
+    cknull_nomsg(qclog_tbl=sinfo_qclog_init());
+
+    for(i=0;i<ngain;i++) {
+      snprintf(key_name,MAX_NAME_SIZE-1,"%s%i","QC GAIN",i);
+      ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,key_name,
+				       cpl_table_get_double(gain,"gain",i,status),
+				       "Detector gain","%g"));
+    }
+
+    ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC GAIN",
+				     cpl_table_get_column_median(gain,"gain"),"Detector gain median","%g"));
+    ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC GAINERR",
+				     cpl_table_get_column_stdev(gain,"gain"),"Detector gain error","%g"));
+
+    ck0(sinfo_pro_save_tbl(gain,raw,sof,BP_LIN_GAIN_OUT_FILENAME,PRO_GAIN_INFO,
+			   qclog_tbl,plugin_id,config),
+	"cannot dump tbl %s", BP_LIN_GAIN_OUT_FILENAME);
+
+    sinfo_free_table(&gain);
+    sinfo_free_table(&qclog_tbl);
+  }
+
+  /* =======================================================================
+     DETERMINES LINEARITY COEFF AS MPE DOES
+     =======================================================================
+  */
+
+
+  check_nomsg(imgl = cpl_imagelist_new());
+  for ( i = 0 ; i < cfg->nframes ; i++ )
+    {
+      if(sinfo_is_fits_file (cfg->framelist[i]) != 1) {
+	sinfo_msg_error("Input file %s is not FITS",cfg->framelist[i] );
+	return -1;
+      }
+      check_nomsg(img_tmp=cpl_image_load(cfg->framelist[i],CPL_TYPE_FLOAT,0,0));
+      check_nomsg(cpl_imagelist_set(imgl,img_tmp,i));
+    }
+
+  /*----------------------------------------------------------------
+   *---------------------- SEARCH FOR BAD PIXELS---------------------
+   *--------------------------------------------------------------*/
+  sinfo_msg("Search for bad pixels");
+  cknull(coeffs_imgl=sinfo_new_fit_intensity_course(imgl,
+						    cfg->order,
+						    cfg->loReject,
+						    cfg->hiReject),
+	 "could not fit polynomial and store coeffs in a data cube!");
+
+  sinfo_free_imagelist(&imgl) ;
+  check_nomsg(sz_imgl=cpl_imagelist_get_size(coeffs_imgl));
+
+
+  /*---store the polynomial fit coefficients in a data cube----*/
+  /* CUBE NOT DUMPED BECAUSE PROBLEMS ON LAST PLANE */
+  cube_mean=cpl_vector_new(sz_imgl);
+
+  /* QC LOG */
+  cknull_nomsg(qclog_tbl=sinfo_qclog_init());
+  for(i=0;i<sz_imgl;i++) {
+    cpl_vector_set(cube_mean,i,
+		   cpl_image_get_median(cpl_imagelist_get(coeffs_imgl,i)));
+
+    snprintf(key_name,MAX_NAME_SIZE-1,"%s%i%s","QC BP-MAP LIN",i," MEAN");
+    snprintf(key_value,MAX_NAME_SIZE-1,"%g",cpl_vector_get(cube_mean,i));
+    ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,key_name,
+				     cpl_vector_get(cube_mean,i),
+				     "Linearity Polynomial Coeff","%g"));
+
+  }
+  sinfo_free_my_vector(&cube_mean);
+  check_nomsg(p = cpl_parameterlist_find(config, "sinfoni.bp.method"));
+  snprintf(key_value, MAX_NAME_SIZE-1,"%s",cpl_parameter_get_string(p));
+  ck0_nomsg(sinfo_qclog_add_string(qclog_tbl,"QC BP-MAP METHOD",key_value,
+				   "BP search method","%s"));
+
+
+  ck0(sinfo_pro_save_ims(coeffs_imgl,raw,sof,cfg->coeffsCubeName,
+			 PRO_BP_COEFF,qclog_tbl,plugin_id,config),
+      "cannot dump ims %s", cfg->coeffsCubeName);
+
+  sinfo_free_table(&qclog_tbl);
+
+  /* =======================================================================
+     DETERMINES BAD PIXEL MAP
+     =======================================================================
+  */
+  sinfo_msg("Generates bad pixel map");
+  cknull(mask = sinfo_new_search_bad_pixels (coeffs_imgl,
+					     cfg->threshSigmaFactor,
+					     cfg->nonlinearThresh,
+					     cfg->loReject,
+					     cfg->hiReject),
+	 "could not create bad pixel mask!") ;
+
+  sinfo_free_imagelist(&coeffs_imgl) ;
+
+  check_nomsg(n_bad = sinfo_new_count_bad_pixels(mask)) ;
+  sinfo_msg( "No of bad pixels: %d", n_bad ) ;
+
+  /* QC LOG */
+  cknull_nomsg(qclog_tbl=sinfo_qclog_init());
+  check_nomsg(p = cpl_parameterlist_find(config, "sinfoni.bp.method"));
+  snprintf(key_value, MAX_NAME_SIZE-1,"%s",cpl_parameter_get_string(p));
+  ck0_nomsg(sinfo_qclog_add_string(qclog_tbl,"QC BP-MAP METHOD",key_value,
+				   "BP search method","%s"));
+
+  ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC BP-MAP NBADPIX",n_bad,
+				"No of bad pixels","%d"));
+
+  ck0(sinfo_pro_save_ima(mask,raw,sof,cfg->outName,PRO_BP_MAP_NL,qclog_tbl,
+			 plugin_id,config),
+      "cannot save ima %s", cfg->outName);
+
+
+  /* ======================================================================
+     FREE MEMORY
+     ======================================================================
+  */
+
+
+
+  sinfo_free_table(&qclog_tbl);
+  sinfo_free_image(&mask);
+  sinfo_free_frameset(&raw);
+  sinfo_detlin_free(&cfg);
+
+  return 0;
+
+ cleanup:
+  sinfo_free_frameset(&raw_on);
+  sinfo_free_frameset(&raw_of);
+
+  sinfo_free_image(&mask) ;
+  sinfo_free_my_vector(&cube_mean);
+  sinfo_free_imagelist(&imgl);
+  sinfo_free_imagelist(&coeffs_imgl);
+  sinfo_free_table(&gain);
+  sinfo_free_table(&qclog_tbl);
+  sinfo_free_table(&det_lin);
+  sinfo_free_my_vector(&vec_adl);
+  sinfo_free_my_vector(&vec_med);
+  sinfo_free_polynomial(&pol);
+  sinfo_detlin_free(&cfg);
+  sinfo_free_frameset(&raw);
+
+  return -1;
+
+
+}
diff --git a/sinfoni/sinfo_bp_lin.h b/sinfoni/sinfo_bp_lin.h
new file mode 100644
index 0000000..693f374
--- /dev/null
+++ b/sinfoni/sinfo_bp_lin.h
@@ -0,0 +1,59 @@
+#ifndef SINFO_BP_LIN_H
+#define SINFO_BP_LIN_H
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*******************************************************************************
+* E.S.O. - VLT project
+*
+* "@(#) $Id: sinfo_bp_lin.h,v 1.2 2007/06/06 07:10:45 amodigli Exp $"
+*
+* who       when      what
+* --------  --------  ----------------------------------------------
+* schreib  06/05/03  created
+*/
+
+/************************************************************************
+ * bp_lin.h
+ * routines to search for bad pixels
+ *----------------------------------------------------------------------
+ */
+
+/*
+ * header files
+ */
+
+#include <cpl.h>
+#include "sinfo_msg.h"
+/*----------------------------------------------------------------------------
+ *                        Function ANSI C prototypes
+ *--------------------------------------------------------------------------*/
+/**
+ at name sinfo_new_bp_search_lin
+ at memo search for non linear (bad) pixels
+ at param plugin_id name of plugin
+ at param config input parameter list
+ at param set input set of frames
+ at return 0 if success -1 else
+*/
+int 
+sinfo_new_bp_search_lin (const char* plugin_id, 
+                         cpl_parameterlist* config, 
+                         cpl_frameset* set);
+#endif 
+/*--------------------------------------------------------------------------*/
diff --git a/sinfoni/sinfo_bp_lin_config.c b/sinfoni/sinfo_bp_lin_config.c
new file mode 100644
index 0000000..0164187
--- /dev/null
+++ b/sinfoni/sinfo_bp_lin_config.c
@@ -0,0 +1,148 @@
+/* $Id: sinfo_bp_lin_config.c,v 1.5 2012/03/02 08:42:20 amodigli Exp $
+ *
+ * This file is part of the CPL (Common Pipeline Library)
+ * Copyright (C) 2002 European Southern Observatory
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*
+ * $Author: amodigli $
+ * $Date: 2012/03/02 08:42:20 $
+ * $Revision: 1.5 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+ /****************************************************************
+  *           Bad pixel search  (Linear method)                  *
+  ****************************************************************/
+
+#include "sinfo_bp_lin_config.h"  
+
+ /**@{*/
+/**
+ * @addtogroup sinfo_bad_pix_search Bad Pixel Search
+ *
+ * TBD
+ */
+
+ /**
+  * @brief
+  *   Adds parameters for the spectrum extraction
+  *
+  * @param list Parameter list to which parameters are added.
+  *
+  * @return Nothing.
+  *
+  * TBD
+  */
+
+  /* Bad pixel parameters */
+
+void
+ sinfo_bp_lin_config_add(cpl_parameterlist *list)
+{
+
+  cpl_parameter *p;
+
+  if (!list) {
+    return;
+  }
+
+
+
+  /* order of the fit polynomial = number of coefficents - 1 */
+  p = cpl_parameter_new_value("sinfoni.bp_lin.order",
+                  CPL_TYPE_INT,
+                              "Order: "
+                              "order of the fit polynomial = "
+                              "number of coefficents - 1",
+                              "sinfoni.bp_lin",
+                              2);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"bp_lin-order");
+  cpl_parameterlist_append(list, p);
+
+
+
+ p = cpl_parameter_new_value("sinfoni.bp_lin.thresh_sigma_factor",
+                  CPL_TYPE_DOUBLE,
+                              "Threshold Sigma Factor: "
+                              "threshold factor of the clean standard "
+                              "deviation. If the deviations of the linear "
+                              "polynomial coefficients exceed this threshold "
+                 "the corresponding pixels are declared as bad ",
+                              "sinfoni.bp_noise",
+                              10.);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"bp_lin-thresh_sigma_fct");
+  cpl_parameterlist_append(list, p);
+
+
+
+  /* if a non-linear coefficient exceeds this value the 
+     corresponding pixel is declared as bad
+  */
+  p = cpl_parameter_new_value("sinfoni.bp_lin.nlin_threshold",
+                  CPL_TYPE_DOUBLE,
+                              "Non Linear Threshold",
+                              "sinfoni.bp_lin",
+                              0.5);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"bp_lin-nlin_threshold");
+  cpl_parameterlist_append(list, p);
+
+
+ /* float 
+     threshold used in the clean mean percentage of rejection used to reject 
+     low and high frame */
+ /* percentage of extreme pixel value to reject when calculating the mean 
+    and stdev */
+  p = cpl_parameter_new_range("sinfoni.bp_lin.low_rejection",
+                  CPL_TYPE_DOUBLE,
+                              "low_rejection: "
+                              "percentage of rejected low intensity "
+                              "pixels before averaging",
+                              "sinfoni.bp_lin",
+                              10.,
+                              0.,
+                              100.);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"bp_lin-lo_rej");
+  cpl_parameterlist_append(list, p);
+
+  /* float 
+     threshold used in the clean mean percentage of rejection used to reject 
+     low and high frame */
+ /* percentage of extreme pixel value to reject when calculating the mean 
+    and stdev */
+  p = cpl_parameter_new_range("sinfoni.bp_lin.high_rejection",
+                  CPL_TYPE_DOUBLE,
+                              "high_rejection: "
+                              "percentage of rejected high intensity "
+                              "pixels before averaging",
+                              "sinfoni.bp_lin",
+                              10.,0.,100.);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"bp_lin-hi_rej");
+  cpl_parameterlist_append(list, p);
+
+
+  return;
+
+}
+/**@}*/
diff --git a/sinfoni/sinfo_bp_lin_config.h b/sinfoni/sinfo_bp_lin_config.h
new file mode 100644
index 0000000..b6b6715
--- /dev/null
+++ b/sinfoni/sinfo_bp_lin_config.h
@@ -0,0 +1,37 @@
+/* $Id: sinfo_bp_lin_config.h,v 1.2 2006/10/22 14:12:27 amodigli Exp $
+ *
+ * This file is part of the CPL (Common Pipeline Library)
+ * Copyright (C) 2002 European Southern Observatory
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*
+ * $Author: amodigli $
+ * $Date: 2006/10/22 14:12:27 $
+ * $Revision: 1.2 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+ /****************************************************************
+  *           Bad pixel search  (normal method)                  *
+  ****************************************************************/
+#ifndef SINFO_BP_LIN_CONFIG_H
+#define SINFO_BP_LIN_CONFIG_H
+
+#include "cpl.h"  
+
+void sinfo_bp_lin_config_add(cpl_parameterlist *list);
+
+#endif
diff --git a/sinfoni/sinfo_bp_noise.c b/sinfoni/sinfo_bp_noise.c
new file mode 100644
index 0000000..20d8c5b
--- /dev/null
+++ b/sinfoni/sinfo_bp_noise.c
@@ -0,0 +1,158 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+   
+   File name    :       sinfo_bp_noise.c
+   Author       :    J. Schreiber
+   Created on   :    May 5, 2003
+   Description  :    Different methods for searching for bad pixels
+                        used in the recipe spiffi_bp_noise 
+
+ ---------------------------------------------------------------------------*/
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+/*----------------------------------------------------------------------------
+                                Includes
+ ---------------------------------------------------------------------------*/
+#include "sinfo_bp_noise.h"
+#include "sinfo_detnoise_ini_by_cpl.h"
+#include "sinfo_pro_save.h"
+#include "sinfo_pro_types.h"
+#include "sinfo_raw_types.h"
+#include "sinfo_functions.h"
+#include "sinfo_detlin.h"
+#include "sinfo_error.h"
+#include "sinfo_utils_wrappers.h"
+
+/**
+ * @addtogroup sinfo_bad_pix_search Bad Pixel Search
+ *
+ * TBD
+ */
+/*----------------------------------------------------------------------------
+                                Defines
+ ---------------------------------------------------------------------------*/
+/*----------------------------------------------------------------------------
+                             Function Definitions
+ ---------------------------------------------------------------------------*/
+
+/**
+   @name  sinfo_new_bp_search_noise
+   @memo Finds hot pixels
+   
+   @param   plugin_id recipe name
+   @param   config input parameters list
+   @param   sof  input set of frames
+   @param out_name name of product
+
+   @returns         integer (0 if it worked, -1 if it doesn't) 
+   @doc
+
+   this function searches for static bad pixels in stacks of sinfo_dark frames
+   taken with NDIT = 1 and equal exposure times
+   The noise in each pixel is computed and compared to the clean mean noise 
+   A pixel is declared bad if the deviation exceeds a threshold
+*/
+int 
+sinfo_new_bp_search_noise (const char* plugin_id,
+                               cpl_parameterlist* config, 
+                               cpl_frameset* sof, 
+                               const char* out_name )
+{
+
+    detnoise_config * cfg =NULL;
+
+    cpl_imagelist * image_list=NULL ;
+    cpl_image * img_tmp=NULL ;
+    cpl_image       *  mask=NULL ;
+    cpl_parameter *p=NULL;
+    cpl_frameset* raw=NULL;
+    cpl_table* qclog_tbl=NULL;
+    char key_value[FILE_NAME_SZ];
+    int i=0;
+    int n_bad =0;
+
+    /*parse the file names and parameters to the detnoise_config data 
+      structure cfg*/
+    check_nomsg(raw=cpl_frameset_new());
+    ck0(sinfo_extract_raw_frames_type1(sof,raw,RAW_DARK),
+        "Error extracting %s frames",RAW_DARK);
+    cknull(cfg = sinfo_parse_cpl_input_detnoise(config,sof,&raw),
+           " could not parse .ini file!") ;
+    check_nomsg(image_list = cpl_imagelist_new());
+    for ( i = 0 ; i < cfg->nframes ; i++ )
+    {
+      if(sinfo_is_fits_file (cfg->framelist[i]) != 1) {
+    sinfo_msg_error("Input file %s is not FITS",cfg->framelist[i] );
+    goto cleanup;
+      }
+      check_nomsg(img_tmp=cpl_image_load(cfg->framelist[i],
+                                         CPL_TYPE_FLOAT,0,0));
+
+      check_nomsg(cpl_imagelist_set(image_list,img_tmp,i));
+    }
+
+    /*-----------------------------------------------------------------
+     *---------------------- SEARCH FOR BAD PIXELS---------------------
+     *-----------------------------------------------------------------*/
+    sinfo_msg("Noise Search for bad pixels");
+    /*---generate the bad pixel mask-------------*/
+    cknull(mask=sinfo_new_search_bad_pixels_via_noise (image_list, 
+                               cfg->threshSigmaFactor,
+                               cfg->loReject,
+                               cfg->hiReject),
+       " could not create bad pixel mask!") ;
+    
+    n_bad = sinfo_new_count_bad_pixels(mask) ;
+    sinfo_msg ("number of bad pixels: %d\n", n_bad) ;
+
+    /* QC LOG */
+    cknull_nomsg(qclog_tbl = sinfo_qclog_init());
+    check_nomsg(p = cpl_parameterlist_find(config, "sinfoni.bp.method"));
+    snprintf(key_value, MAX_NAME_SIZE-1,"%s",cpl_parameter_get_string(p));
+    ck0_nomsg(sinfo_qclog_add_string(qclog_tbl,"QC BP-MAP METHOD",key_value,
+                                     "BP search method","%s"));
+    ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC BP-MAP NBADPIX",n_bad,
+                                     "No of bad pixels","%d"));
+
+    ck0(sinfo_pro_save_ima(mask,raw,sof,(char *) out_name,
+               PRO_BP_MAP_HP,qclog_tbl,plugin_id,config),
+                           "cannot save ima %s", out_name);
+
+    sinfo_free_image(&mask);
+    sinfo_free_table(&qclog_tbl);
+    sinfo_free_imagelist(&image_list) ;
+    sinfo_detnoise_free(cfg);
+    sinfo_free_frameset(&raw);
+
+    return 0 ;
+
+ cleanup:
+
+    sinfo_free_table(&qclog_tbl);
+    sinfo_free_imagelist(&image_list) ;
+    sinfo_free_image(&mask) ;
+    sinfo_detnoise_free(cfg);
+    sinfo_free_frameset(&raw);
+   return -1 ;
+
+}
+/**@}*/
diff --git a/sinfoni/sinfo_bp_noise.h b/sinfoni/sinfo_bp_noise.h
new file mode 100644
index 0000000..4eaf551
--- /dev/null
+++ b/sinfoni/sinfo_bp_noise.h
@@ -0,0 +1,51 @@
+#ifndef SINFO_BP_NOISE_H
+#define SINFO_BP_NOISE_H
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*******************************************************************************
+* E.S.O. - VLT project
+*
+* "@(#) $Id: sinfo_bp_noise.h,v 1.3 2007/06/06 07:10:45 amodigli Exp $"
+*
+* who       when      what
+* --------  --------  ----------------------------------------------
+* schreib  06/05/03  created
+*/
+
+/************************************************************************
+ * bp_noise.h
+ * routine to search for bad pixels
+ *----------------------------------------------------------------------
+ */
+/*
+ * header files
+ */
+#include <cpl.h>
+#include "sinfo_msg.h"
+/*----------------------------------------------------------------------------
+ *                        Function ANSI C prototypes
+ *--------------------------------------------------------------------------*/
+
+int 
+sinfo_new_bp_search_noise (const char* plugin_id, 
+                           cpl_parameterlist* config, 
+                           cpl_frameset* set, 
+                           const char* out_name);
+
+#endif 
diff --git a/sinfoni/sinfo_bp_noise_config.c b/sinfoni/sinfo_bp_noise_config.c
new file mode 100644
index 0000000..ce94d92
--- /dev/null
+++ b/sinfoni/sinfo_bp_noise_config.c
@@ -0,0 +1,117 @@
+/* $Id: sinfo_bp_noise_config.c,v 1.5 2008/01/17 07:54:04 amodigli Exp $
+ *
+ * This file is part of the CPL (Common Pipeline Library)
+ * Copyright (C) 2002 European Southern Observatory
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*
+ * $Author: amodigli $
+ * $Date: 2008/01/17 07:54:04 $
+ * $Revision: 1.5 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+ /****************************************************************
+  *           Bad pixel search  (noise method)                  *
+  ****************************************************************/
+#include "sinfo_bp_noise_config.h"
+/**
+ * @addtogroup sinfo_bad_pix_search Bad Pixel Search
+ *
+ * TBD
+ */
+
+ /**@{*/
+ /**
+  * @brief
+  *   Adds parameters for the spectrum extraction
+  *
+  * @param list Parameter list to which parameters are added.
+  *
+  * @return Nothing.
+  *
+  * TBD
+  */
+
+  /* Bad pixel parameters */
+
+void
+ sinfo_bp_noise_config_add(cpl_parameterlist *list)
+{
+
+  cpl_parameter *p;
+
+  if (!list) {
+    return;
+  }
+
+
+
+/* factor of noise within which the pixels are used to fit a straight line 
+   to the column intensity */
+  p = cpl_parameter_new_value("sinfoni.bp_noise.thresh_sigma_factor",
+                  CPL_TYPE_DOUBLE,
+                              "Threshold Sigma Factor: "
+                              "If the mean noise exceeds this "
+                              "threshold times the clean standard deviation "
+                              "of the clean mean the corresponding pixels "
+                              "are declared as bad ",
+                              "sinfoni.bp_noise",
+                              10.);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
+			  "bp_noise-thresh_sigma_fct");
+  cpl_parameterlist_append(list, p);
+
+/* float 
+     threshold used in the clean mean percentage of rejection used to reject 
+     low and high frame */
+ /* percentage of extreme pixel value to reject when calculating the mean 
+    and stdev */
+  p = cpl_parameter_new_range("sinfoni.bp_noise.low_rejection",
+                  CPL_TYPE_DOUBLE,
+                              "low_rejection: "
+                              "percentage of rejected low intensity "
+                              "pixels before averaging",
+                              "sinfoni.bp_noise",
+                              10.,0.,100.);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"bp_noise-lo_rej");
+  cpl_parameterlist_append(list, p);
+
+  /* float 
+     threshold used in the clean mean percentage of rejection used to reject 
+     low and high frame */
+ /* percentage of extreme pixel value to reject when calculating the mean 
+    and stdev */
+  p = cpl_parameter_new_range("sinfoni.bp_noise.high_rejection",
+                  CPL_TYPE_DOUBLE,
+                              "high_rejection: "
+                              "percentage of rejected high intensity "
+                              "pixels before averaging",
+                              "sinfoni.bp_noise",
+                              10.,0.,100.);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"bp_noise-hi_rej");
+  cpl_parameterlist_append(list, p);
+
+  return;
+
+}
+/**@}*/
diff --git a/sinfoni/sinfo_bp_noise_config.h b/sinfoni/sinfo_bp_noise_config.h
new file mode 100644
index 0000000..45b7122
--- /dev/null
+++ b/sinfoni/sinfo_bp_noise_config.h
@@ -0,0 +1,37 @@
+/* $Id: sinfo_bp_noise_config.h,v 1.2 2006/10/22 14:12:27 amodigli Exp $
+ *
+ * This file is part of the CPL (Common Pipeline Library)
+ * Copyright (C) 2002 European Southern Observatory
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*
+ * $Author: amodigli $
+ * $Date: 2006/10/22 14:12:27 $
+ * $Revision: 1.2 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+ /****************************************************************
+  *           Bad pixel search  (noise method)                  *
+  ****************************************************************/
+#ifndef SINFO_BP_NOISE_CONFIG_H
+#define SINFO_BP_NOISE_CONFIG_H
+
+#include "cpl.h"   
+
+void sinfo_bp_noise_config_add(cpl_parameterlist *list);
+
+#endif
diff --git a/sinfoni/sinfo_bp_norm.c b/sinfoni/sinfo_bp_norm.c
new file mode 100644
index 0000000..38a53ff
--- /dev/null
+++ b/sinfoni/sinfo_bp_norm.c
@@ -0,0 +1,392 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+   
+   File name    :       sinfo_bp_norm.c
+   Author       :    J. Schreiber
+   Created on   :    May 5, 2003
+   Description  :    Different methods for searching for bad pixels
+                        used in the recipe sinfo_rec_mflat 
+
+ ---------------------------------------------------------------------------*/
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+/*----------------------------------------------------------------------------
+                                Includes
+ ---------------------------------------------------------------------------*/
+#include "sinfo_bp_norm.h"
+#include "sinfo_image_ops.h"
+#include "sinfo_detlin.h"
+#include "sinfo_badnorm_ini_by_cpl.h"
+#include "sinfo_baddist_ini_by_cpl.h"
+#include "sinfo_pro_save.h"
+#include "sinfo_functions.h"
+#include "sinfo_pro_types.h"
+#include "sinfo_hidden.h"
+#include "sinfo_error.h"
+#include "sinfo_utils_wrappers.h"
+/**@{*/
+/**
+ * @addtogroup sinfo_bad_pix_search Bad Pixel Search
+ *
+ * TBD
+ */
+/*----------------------------------------------------------------------------
+                                Defines
+ ---------------------------------------------------------------------------*/
+/*----------------------------------------------------------------------------
+                             Function Definitions
+ ---------------------------------------------------------------------------*/
+/**
+   @name  sinfo_new_bp_search_norm
+   @memo finds pixels whose intensity differs from the median more 
+         than a given threshold
+
+   @param   plugin_id recipe name
+   @param   config input parameters list
+   @param   sof  input set of frames
+   @param   procatg PRO.CATG of product.
+   @return    integer (0 if it worked, -1 if it doesn't) 
+   @doc
+   this function searches for static bad pixels in stacks of flatfield frames, 
+   that means it stacks the flatfield in a data cube and takes the sinfo_median 
+   along the z-axis to be sure to have no cosmics, then the intensity tilt of 
+   each column is removed. 
+
+   The standard deviation and mean of the pixel values within a defined 
+   rectangular zone is determined in a way that the extreme low and high 
+   values are cut off.
+
+   The next step is to indicate each pixel as bad that has a deviation from 
+   the mean greater than a user defined factor times the standard deviation. 
+   This step can be leaped over if wished.
+   The next step is to calculate the median of the 8 nearest neighbors for 
+   each pixel and to determine the deviation of each pixel value from this 
+   sinfo_median. 
+
+   If this deviation is greater than a defined factor times the standard 
+   deviation the pixel value is replaced by the sinfo_median. The last step is 
+   repeated to be able to consider also clusters of bad pixels. Then the 
+   resulting image is compared with the input image with the column intensity 
+   tilt removed and each changed pixel is indicated as bad. Finally, a bad 
+   pixel mask is produced that means each good pixel is marked with 1 and each 
+   bad pixel with 0.
+                      
+ */
+
+
+int 
+sinfo_new_bp_search_normal (const char* plugin_id,
+                     cpl_parameterlist* config, 
+                     cpl_frameset* sof, 
+                     cpl_frameset* ref_set, 
+                     const char* procatg)
+{
+  bad_config * cfg =NULL;
+  cpl_imagelist * image_list =NULL;
+  cpl_image ** med=NULL ;
+  cpl_image * medImage =NULL;
+  cpl_image * medIm =NULL;
+  cpl_image * colImage =NULL;
+  cpl_image * compImage =NULL;
+  cpl_image * maskImage =NULL;
+  cpl_image * threshIm =NULL;
+
+
+  Stats * stats =NULL;
+
+  cpl_parameter *p=NULL;             
+
+  int no=0;
+  float lo_cut=0.;
+  float hi_cut=0.;
+
+  int i=0;
+  int n=0;
+  int half_box_size=0 ;
+
+  cpl_frameset* raw=NULL;
+  cpl_table* qclog_tbl=NULL;
+  char key_value[FILE_NAME_SZ];
+
+  /* parse the file names and parameters to the bad_config data structure 
+       cfg */
+ 
+  sinfo_check_rec_status(0);
+  check_nomsg(raw=cpl_frameset_new());
+  sinfo_check_rec_status(1);
+  if (strcmp(procatg,PRO_BP_MAP_NO) == 0) {
+    cknull(cfg = sinfo_parse_cpl_input_badnorm(config,sof,procatg,&raw),
+       "could not parse cpl input!");
+  } else if (strcmp(procatg,PRO_BP_MAP_DI) == 0) {
+    cknull(cfg = sinfo_parse_cpl_input_baddist(config,sof,procatg,&raw),
+       "could not parse cpl input!");
+  } else if (strcmp(procatg,PRO_DEFAULT) == 0) {
+    cknull(cfg = sinfo_parse_cpl_input_badnorm(config,sof,procatg,&raw),
+       "could not parse cpl input!");
+  } else {
+    sinfo_msg_error("Error: PRO.CATG %s, not supported!",procatg);
+    goto cleanup;
+  }
+  sinfo_check_rec_status(2);
+  /* take a clean mean of the frames */
+  sinfo_msg("Takes a clean mean of the frames");
+
+  check_nomsg(image_list = cpl_imagelist_new());
+  sinfo_check_rec_status(3);
+
+  for ( i = 0 ; i < cfg->nframes ; i++ ){
+    if(sinfo_is_fits_file (cfg->framelist[i]) != 1) {
+      sinfo_msg_error("Input file %s is not FITS",cfg->framelist[i] );
+      goto cleanup;
+    }
+
+    check_nomsg(cpl_imagelist_set(image_list, 
+                cpl_image_load(cfg->framelist[i],CPL_TYPE_FLOAT,0,0),i));
+
+  }
+
+  /* finally take the average image of the cube by 
+     rejecting the extreme values */
+
+  check_nomsg(no=cpl_imagelist_get_size(image_list));
+  lo_cut=(floor)(cfg->loReject*no+0.5);
+  hi_cut=(floor)(cfg->hiReject*no+0.5);
+  cknull(medImage=cpl_imagelist_collapse_minmax_create(image_list,
+                                                       lo_cut,
+                                                       hi_cut),
+     "error in sinfo_average_with_rejection") ;
+ 
+  /* free memory */
+  sinfo_free_imagelist(&image_list) ;
+
+  /*----------------------------------------------
+   * remove the intensity tilt from every column
+   * and compute the standard deviation on a rectangular zone
+   */
+  cknull(medIm = sinfo_new_thresh_image(medImage, cfg->mincut, cfg->maxcut),
+      "error sinfo_new_thresh_image");
+  cknull(colImage  = sinfo_new_col_tilt( medIm, cfg->sigmaFactor ),
+        "sinfo_colTilt failed" ) ;
+
+
+  cknull(stats = sinfo_new_image_stats_on_rectangle(colImage, 
+                            cfg->loReject, 
+                            cfg->hiReject,
+                            cfg->llx,
+                            cfg->lly,
+                            cfg->urx,
+                            cfg->ury),
+     " sinfo_get_image_stats_on_vig failed") ;
+  if(stats!=NULL) {
+     sinfo_msg("Clean stdev: %f\n", stats->cleanstdev ) ;
+     sinfo_msg("Clean mean: %f\n",  stats->cleanmean ) ;
+  }
+    
+
+
+  /*
+    cknull_nomsg(qclog_tbl = sinfo_qclog_init());
+    ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC ICTILT STDEV",
+                                     stats->cleanstdev,
+                                     "Intensity column clean stdev","%g"));
+ 
+    ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC ICTILT MEAN",
+                                     stats->cleanmean,
+                                     "Intensity column clean mean","%g"));
+
+    ck0(sinfo_pro_save_ima(colImage,raw,sof,
+                           (char*) BP_NORM_INT_COL_TILT_CORR_OUT_FILENAME,
+                           PRO_INT_COL_TILT_COR,qclog_tbl,plugin_id,config),
+                           "cannot save ima %s",
+                           BP_NORM_INT_COL_TILT_CORR_OUT_FILENAME);
+
+    sinfo_free_table(&qclog_tbl);
+  */
+    
+  /* indicate pixels with great deviations from the clean mean as bad */
+  if (cfg->threshInd == 1) {
+    cknull(threshIm = sinfo_new_thresh_image(colImage, 
+                      stats->cleanmean-cfg->meanfactor*stats->cleanstdev, 
+                      stats->cleanmean+cfg->meanfactor*stats->cleanstdev),
+       " sinfo_threshImage failed" ) ;
+
+  }
+
+  if (cfg->threshInd == 0 ) {
+    threshIm = colImage ;
+  }
+  /* AMO here invalid fread? */
+  med = (cpl_image**) cpl_calloc (cfg -> iterations, sizeof(cpl_image*)) ;
+    
+
+  /* filter iteratively the images by a sinfo_median filter of the nearest 
+     neighbors under the condition of a deviation greater than a factor 
+     times the standard deviation */
+  sinfo_msg("Apply sinfo_median filter on pixel nearest neighbors");
+  if (cfg->methodInd == 1) {
+    if (cfg->factor>0) {
+      cknull(med[0]=sinfo_new_median_image(threshIm,
+                                           -cfg->factor*stats->cleanstdev),
+                                           " sinfo_medianImage failed (1)" ) ;
+
+      for ( i = 0 ; i < cfg->iterations - 1 ; i++ ) {
+    cknull(med[i+1]=sinfo_new_median_image(med[i], 
+                                               -cfg->factor*stats->cleanstdev),
+                                               "sinfo_medianImage failed (2)");
+      }
+
+    } else {
+      cknull(med[0] = sinfo_new_median_image(threshIm, -cfg->factor),
+         " sinfo_medianImage failed (1)" ) ;
+
+      for ( i = 0 ; i < cfg->iterations - 1 ; i++ ) {
+    cknull(med[i+1] = sinfo_new_median_image(med[i], -cfg->factor),
+           " sinfo_medianImage failed (%d)",i ) ;
+      }
+    }
+  } else if (cfg->methodInd == 2) {
+
+    cknull(med[0] = sinfo_new_abs_dist_image(threshIm, -cfg->factor),
+       " sinfo_absDistImage failed (1)" ) ;
+
+    for ( i = 0 ; i < cfg->iterations -1 ; i++ ) {
+      cknull(med[i+1] = sinfo_new_abs_dist_image(med[i], -cfg->factor),
+         " sinfo_absDistImage failed (2)" ) ;
+    }
+  } else if (cfg->methodInd == 3) {
+    cknull(med[0] = sinfo_new_mean_image_in_spec(threshIm, 
+                                           -cfg->factor*stats->cleanstdev),
+                                       "sinfo_meanImageInSpec failed (1)");
+    for ( i = 0 ; i < cfg->iterations - 1 ; i++ ) {
+      cknull(med[i+1] = sinfo_new_mean_image_in_spec(med[i], 
+                                               -cfg->factor*stats->cleanstdev),
+                                         " sinfo_meanImageInSpec failed (2)");
+    }
+  } else if (cfg->methodInd == 4) {
+    half_box_size = (cfg->urx - cfg->llx) / 2 ;
+    cknull(med[0] = sinfo_new_local_median_image(threshIm, 
+                       -cfg->factor,
+                       cfg->loReject,
+                       cfg->hiReject,
+                       half_box_size),
+       " sinfo_localMedianImage failed (1)" ) ;
+
+    for ( i = 0 ; i < cfg->iterations - 1 ; i++ ) {
+      cknull(med[i+1] = sinfo_new_local_median_image(med[i],
+                           -cfg->factor,
+                           cfg->loReject,
+                           cfg->hiReject,
+                           half_box_size),
+         " sinfo_localMedianImage failed (2)" ) ;
+    }
+  } else {
+    sinfo_msg_error (" wrong indicator methodInd !" ) ;
+    goto cleanup ;
+  }
+
+  /* compare the filtered image with the input image */
+  cknull(compImage = sinfo_new_compare_images(threshIm, 
+                                              med[cfg->iterations - 1], 
+                                              medImage),
+                                              " sinfo_compareImages failed" ) ;
+    
+  /* generate the bad pixel mask */
+  sinfo_msg("Generates bad pixel map");
+  cknull(maskImage = sinfo_new_promote_image_to_mask( compImage, &n ),
+     " error in sinfo_promoteImageToMask" ) ;
+  sinfo_msg("No of bad pixels:  %d\n", n ) ;
+
+  cknull_nomsg(qclog_tbl = sinfo_qclog_init());
+  check_nomsg(p = cpl_parameterlist_find(config, "sinfoni.bp.method"));
+  snprintf(key_value, MAX_NAME_SIZE-1,"%s", cpl_parameter_get_string(p));
+
+  ck0_nomsg(sinfo_qclog_add_string(qclog_tbl,"QC BP-MAP METHOD",
+                                   key_value,"BP search method","%s"));
+
+  ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC BP-MAP NBADPIX",n,
+                                           "No of bad pixels","%d"));
+
+    ck0(sinfo_pro_save_ima(maskImage,ref_set,sof,cfg->outName,
+			   procatg,qclog_tbl,plugin_id,config),
+	"cannot save ima %s", cfg->outName);
+
+  sinfo_free_table(&qclog_tbl);
+  sinfo_free_image(&maskImage);
+  sinfo_free_image(&compImage);
+  if (med != NULL) {
+    for ( i = 0 ; i < cfg->iterations ; i++ ) {
+      if(med[i] != NULL) {
+    cpl_image_delete(med[i]) ;
+    med[i]=NULL;
+      }
+    }
+    cpl_free(med) ; 
+    med=NULL;
+  }
+  if (stats != NULL) {
+    cpl_free(stats) ;
+    stats=NULL;
+  }
+  sinfo_free_image(&medIm);
+  sinfo_free_image(&medImage);
+  sinfo_free_image(&colImage);
+  if (cfg->threshInd == 1 ) {
+    sinfo_free_image(&threshIm);
+  }
+  sinfo_badnorm_free(&cfg) ;
+  sinfo_free_frameset(&raw);
+  return 0;
+
+ cleanup:
+
+
+  if (med != NULL) {
+    for ( i = 0 ; i < cfg->iterations ; i++ ) {
+      if(med[i] != NULL) {
+    cpl_image_delete(med[i]) ;
+    med[i]=NULL;
+      }
+    }
+    cpl_free(med) ; 
+         med=NULL;
+  }
+  sinfo_free_image(&compImage) ;
+  sinfo_free_image(&maskImage) ;
+  sinfo_free_image(&threshIm) ;
+  sinfo_free_table(&qclog_tbl);
+  sinfo_free_image(&threshIm) ;
+  if (stats != NULL) {
+    cpl_free(stats) ;
+    stats=NULL;
+  }
+  sinfo_free_image(&medIm);
+  sinfo_free_image(&medImage);
+  sinfo_free_image(&colImage);
+  sinfo_free_imagelist(&image_list) ;
+  sinfo_free_frameset(&raw);
+  sinfo_badnorm_free(&cfg);
+
+  return -1;
+
+}
+
+/**@}*/
diff --git a/sinfoni/sinfo_bp_norm.h b/sinfoni/sinfo_bp_norm.h
new file mode 100644
index 0000000..24d32d7
--- /dev/null
+++ b/sinfoni/sinfo_bp_norm.h
@@ -0,0 +1,54 @@
+#ifndef SINFO_BP_NORM_H
+#define SINFO_BP_NORM_H
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*******************************************************************************
+* E.S.O. - VLT project
+*
+* "@(#) $Id: sinfo_bp_norm.h,v 1.4 2007/09/21 14:13:43 amodigli Exp $"
+*
+* who       when      what
+* --------  --------  ----------------------------------------------
+* schreib  06/05/03  created
+*/
+
+/************************************************************************
+ * bp_norm.h
+ * routine to search for bad pixels
+ *----------------------------------------------------------------------
+ */
+
+/*
+ * header files
+ */
+#include <cpl.h>
+#include "sinfo_msg.h"
+/*----------------------------------------------------------------------------
+ *                        Function ANSI C prototypes
+ *--------------------------------------------------------------------------*/
+
+int 
+sinfo_new_bp_search_normal (const char* plugin_id, 
+                            cpl_parameterlist* config, 
+                            cpl_frameset* set, 
+                            cpl_frameset* ref_set, 
+                            const char* procatg);
+#endif
+
+/*--------------------------------------------------------------------------*/
diff --git a/sinfoni/sinfo_bp_norm_config.c b/sinfoni/sinfo_bp_norm_config.c
new file mode 100644
index 0000000..d7f9548
--- /dev/null
+++ b/sinfoni/sinfo_bp_norm_config.c
@@ -0,0 +1,274 @@
+/* $Id: sinfo_bp_norm_config.c,v 1.4 2007/06/06 07:10:45 amodigli Exp $
+ *
+ * This file is part of the CPL (Common Pipeline Library)
+ * Copyright (C) 2002 European Southern Observatory
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*
+ * $Author: amodigli $
+ * $Date: 2007/06/06 07:10:45 $
+ * $Revision: 1.4 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+ /****************************************************************
+  *           Bad pixel search  (normal method)                  *
+  ****************************************************************/
+#include "sinfo_bp_norm_config.h"
+/**
+ * @addtogroup sinfo_bad_pix_search Bad Pixel Search
+ *
+ * TBD
+ */
+
+ /**@{*/
+ /**
+  * @brief
+  *   Adds parameters for the spectrum extraction
+  *
+  * @param list Parameter list to which parameters are added.
+  *
+  * @return Nothing.
+  *
+  * TBD
+  */
+
+  /* Bad pixel parameters */
+
+void
+ sinfo_bp_norm_config_add(cpl_parameterlist *list)
+{
+  cpl_parameter *p;
+
+  if (!list) {
+    return;
+  }
+
+
+ 
+
+/* factor of noise within which the pixels are used to fit a straight line 
+   to the column intensity */
+  p = cpl_parameter_new_value("sinfoni.bp_norm.sigma_factor",
+                  CPL_TYPE_DOUBLE,
+                              "Threshold Sigma Factor: "
+                              "to remove the column intensity tilt only "
+                              "pixels which lie within a defined noise"
+                              "limit are used to fit a straight line",
+                              "sinfoni.bp_noise",
+                              5.0);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"bp_norm-s_factor");
+  cpl_parameterlist_append(list, p);
+
+  /* bad pixel search determination method */
+ p = cpl_parameter_new_enum("sinfoni.bp_norm.method_index",
+                  CPL_TYPE_INT,
+                              "Bad pixel Method Index"
+                              "1: median of nearest neighbors,"
+                              "2: absolute distances check, "
+                              "3: mean of nearest spectral neighbors",
+                              "sinfoni.bp_norm",
+                              1,
+                              3,1,2,3);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"bp_norm-method_ind");
+  cpl_parameterlist_append(list, p);
+
+  /* factor of calculated standard deviation beyond which the deviation 
+     of a pixel value from the median of the 8 nearest neighbors declares 
+     a pixel as bad */
+  p = cpl_parameter_new_value("sinfoni.bp_norm.factor",
+                  CPL_TYPE_DOUBLE,
+                              "Factor: "
+           "if |pixel - median| > factor * standard deviation -> "
+                              "then the pixel value is replaced by "
+                              "the median of the 8 nearest neighbors",
+                              "sinfoni.bp_norm",
+                              10.0);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"bp_norm-fct");
+  cpl_parameterlist_append(list, p);
+
+ /* no of iterations to find bad pix clusters */
+  /* number of iterations of sinfo_median filter */
+  p = cpl_parameter_new_value("sinfoni.bp_norm.iterations",
+                  CPL_TYPE_INT,
+                              "Iterations: number of iterations to of median"
+                              " filtering to find bad pixel clusters",
+                              "sinfoni.bp_norm",
+                              8);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"bp_norm-it");
+  cpl_parameterlist_append(list, p);
+
+  /* float 
+     threshold used in the clean mean percentage of rejection used to reject 
+     low and high frame */
+ /* percentage of extreme pixel value to reject when calculating the mean 
+    and stdev */
+  p = cpl_parameter_new_range("sinfoni.bp_norm.low_rejection",
+                  CPL_TYPE_DOUBLE,
+                              "low_rejection: "
+                              "percentage of rejected low intensity "
+                              "pixels before averaging",
+                              "sinfoni.bp_norm",
+                              0.1,0.0,1.0);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"bp_norm-lo_rej");
+  cpl_parameterlist_append(list, p);
+
+  /* float 
+     threshold used in the clean mean percentage of rejection used to reject 
+     low and high frame */
+ /* percentage of extreme pixel value to reject when calculating the mean 
+    and stdev */
+  p = cpl_parameter_new_range("sinfoni.bp_norm.high_rejection",
+                  CPL_TYPE_DOUBLE,
+                              "high_rejection: "
+                              "percentage of rejected high intensity "
+                              "pixels before averaging",
+                              "sinfoni.bp_norm",
+                              0.1,0.0,1.0);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"bp_norm-hi_rej");
+  cpl_parameterlist_append(list, p);
+
+
+  /* position in the frame lower left in X */
+  /* pixel coordinate of lower left sinfo_edge of a rectangle zone from which 
+     image statistics are computed */
+  p = cpl_parameter_new_range("sinfoni.bp_norm.llx",
+                  CPL_TYPE_INT,
+                              "llx: "
+                              "to compute image statistics on a rectangular"
+                              "zone of the image the coordinates of the "
+                              "rectangle are needed:" 
+                              "lower left x coordinate",
+                              "sinfoni.bp_norm",
+                              270,DET_PIX_MIN,DET_PIX_MAX);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"bp_norm-llx");
+  cpl_parameterlist_append(list, p);
+
+
+
+  /* position in the frame lower left in Y */
+  /* pixel coordinate of lower left sinfo_edge of a rectangle zone from which 
+     image statistics are computed */
+  p = cpl_parameter_new_range("sinfoni.bp_norm.lly",
+                  CPL_TYPE_INT,
+                              "lly: "
+                              "to compute image statistics on a rectangular"
+                              "zone of the image the coordinates of the "
+                              "rectangle are needed:" 
+                              "lower left y coordinate",
+                              "sinfoni.bp_norm",
+                              LLY,DET_PIX_MIN,DET_PIX_MAX);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"bp_norm-lly");
+  cpl_parameterlist_append(list, p);
+
+  /* Upper right position in CCD : should be urx */
+  /* pixel coordinate of upper right sinfo_edge of a rectangle zone from which 
+    image statistics are computed */
+  p = cpl_parameter_new_range("sinfoni.bp_norm.urx",
+                  CPL_TYPE_INT,
+                              "urx: "
+                              "to compute image statistics on a rectangular"
+                              "zone of the image the coordinates of the "
+                              "rectangle are needed:" 
+                              "upper right x coordinate",
+                              "sinfoni.bp_norm",
+                              310,DET_PIX_MIN,DET_PIX_MAX);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"bp_norm-urx");
+  cpl_parameterlist_append(list, p);
+
+  /* Upper right position in CCD : should be ury */
+  /* pixel coordinate of upper right sinfo_edge of a rectangle zone from which 
+    image statistics are computed */
+  p = cpl_parameter_new_range("sinfoni.bp_norm.ury",
+                  CPL_TYPE_INT,
+                              "ury: "
+                              "to compute image statistics on a rectangular"
+                              "zone of the image the coordinates of the "
+                              "rectangle are needed:" 
+                              "upper right y coordinate",
+                              "sinfoni.bp_norm",
+                              URY,DET_PIX_MIN,DET_PIX_MAX);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"bp_norm-ury");
+  cpl_parameterlist_append(list, p);
+
+  /* boolean (implemented as integer) useda s a switch */
+  /* indicates if the values beyond threshold values should be marked 
+     as bad before proceeding to sinfo_median filtering */
+  p = cpl_parameter_new_value("sinfoni.bp_norm.threshold_index",
+                  CPL_TYPE_BOOL,
+                              "Threshold Index: "
+                              "indicator that indicates if the values "
+                              "beyond a threshold deviation from the mean "
+                              "are flagged as bad pixels",
+                              "sinfoni.bp_norm",
+                              TRUE);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"bp_norm-thr_ind");
+  cpl_parameterlist_append(list, p);
+
+  /* threshold value. Float. Threshold used to find bad pixel */
+  /* factor to the clean standard deviation to define the threshold 
+     deviation from the clean mean */
+  p = cpl_parameter_new_range("sinfoni.bp_norm.mean_factor",
+                  CPL_TYPE_DOUBLE,
+                              "Mean Factor: "
+                              "factor to the clean standard deviation to "
+                              "define the threshold deviation from the "
+                              "clean mean",
+                              "sinfoni.bp_norm",
+                              100.,0.1,1.e10);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"bp_norm-mean_fct");
+  cpl_parameterlist_append(list, p);
+
+
+
+  p = cpl_parameter_new_value("sinfoni.bp_norm.min_cut",
+                  CPL_TYPE_DOUBLE,
+                              "the minimum value of real data",
+                              "sinfoni.bp_norm",
+                              0.0);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"bp_norm-min_cut");
+  cpl_parameterlist_append(list, p);
+
+
+  p = cpl_parameter_new_value("sinfoni.bp_norm.max_cut",
+                  CPL_TYPE_DOUBLE,
+                              "the minimum value of real data",
+                              "sinfoni.bp_norm",
+                              50000.);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"bp_norm-max_cut");
+  cpl_parameterlist_append(list, p);
+
+  return;
+
+}
+/**@}*/
diff --git a/sinfoni/sinfo_bp_norm_config.h b/sinfoni/sinfo_bp_norm_config.h
new file mode 100644
index 0000000..b2c7f5d
--- /dev/null
+++ b/sinfoni/sinfo_bp_norm_config.h
@@ -0,0 +1,41 @@
+/* $Id: sinfo_bp_norm_config.h,v 1.1 2006/10/20 08:06:32 amodigli Exp $
+ *
+ * This file is part of the CPL (Common Pipeline Library)
+ * Copyright (C) 2002 European Southern Observatory
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*
+ * $Author: amodigli $
+ * $Date: 2006/10/20 08:06:32 $
+ * $Revision: 1.1 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+ /****************************************************************
+  *           Bad pixel search  (normal method)                  *
+  ****************************************************************/
+#ifndef SINFO_BP_NORM_CONFIG_H
+#define SINFO_BP_NORM_CONFIG_H
+
+#include "cpl.h"  
+/*
+#include "sinfo_dfs.h"
+*/
+#include "sinfo_globals.h"
+
+void sinfo_bp_norm_config_add(cpl_parameterlist *list);
+
+#endif
diff --git a/sinfoni/sinfo_bp_sky_config.c b/sinfoni/sinfo_bp_sky_config.c
new file mode 100644
index 0000000..0b9c4d4
--- /dev/null
+++ b/sinfoni/sinfo_bp_sky_config.c
@@ -0,0 +1,284 @@
+/* $Id: sinfo_bp_sky_config.c,v 1.4 2007/06/06 07:10:45 amodigli Exp $
+ *
+ * This file is part of the CPL (Common Pipeline Library)
+ * Copyright (C) 2002 European Southern Observatory
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*
+ * $Author: amodigli $
+ * $Date: 2007/06/06 07:10:45 $
+ * $Revision: 1.4 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+ /****************************************************************
+  *           Bad pixel search  (normal method)                  *
+  ****************************************************************/
+#include "sinfo_bp_sky_config.h"
+/**
+ * @addtogroup sinfo_bad_pix_search Bad Pixel Search
+ *
+ * TBD
+ */
+
+ /**@{*/
+ /**
+  * @brief
+  *   Adds parameters for the spectrum extraction
+  *
+  * @param list Parameter list to which parameters are added.
+  *
+  * @return Nothing.
+  *
+  * TBD
+  */
+
+  /* Bad pixel parameters */
+
+void
+ sinfo_bp_sky_config_add(cpl_parameterlist *list)
+{
+  cpl_parameter *p;
+
+  if (!list) {
+    return;
+  }
+
+
+  /* Output file name */
+  p = cpl_parameter_new_value("sinfoni.bp_sky.out_filename",
+                  CPL_TYPE_STRING,
+                              "Output File Name: ",
+                              "sinfoni.bp_sky",
+                              "out_bp_sky.fits");
+
+
+  cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI, "out-bp_sky_filename");
+  cpl_parameterlist_append(list, p);
+
+
+/* factor of noise within which the pixels are used to fit a straight line 
+   to the column intensity */
+  p = cpl_parameter_new_value("sinfoni.bp_sky.sigma_factor",
+                  CPL_TYPE_DOUBLE,
+                              "Threshold Sigma Factor: "
+                              "to remove the column intensity tilt only "
+                              "pixels which lie within a defined noise"
+                              "limit are used to fit a straight line",
+                              "sinfoni.bp_noise",
+                              5.0);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"bp_sky-s_factor");
+  cpl_parameterlist_append(list, p);
+
+  /* bad pixel search determination method */
+ p = cpl_parameter_new_enum("sinfoni.bp_sky.method_index",
+                  CPL_TYPE_INT,
+                              "Bad pixel Method Index"
+                              "1: median of nearest neighbors,"
+                              "2: absolute distances check, "
+                              "3: mean of nearest spectral neighbors",
+                              "sinfoni.bp_sky",
+                              1,
+                              3,1,2,3);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"bp_sky-method_ind");
+  cpl_parameterlist_append(list, p);
+
+  /* factor of calculated standard deviation beyond which the deviation 
+     of a pixel value from the median of the 8 nearest neighbors declares 
+     a pixel as bad */
+  p = cpl_parameter_new_value("sinfoni.bp_sky.factor",
+                  CPL_TYPE_DOUBLE,
+                              "Factor: "
+           "if |pixel - sinfo_median| > factor * standard deviation -> "
+                              "then the pixel value is replaced by "
+                              "the median of the 8 nearest neighbors",
+                              "sinfoni.bp_sky",
+                              3.0);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"bp_sky-fct");
+  cpl_parameterlist_append(list, p);
+
+ /* no of iterations to find bad pix clusters */
+  /* number of iterations of sinfo_median filter */
+  p = cpl_parameter_new_value("sinfoni.bp_sky.iterations",
+                  CPL_TYPE_INT,
+                              "Iterations: number of iterations to of median"
+                              " filtering to find bad pixel clusters",
+                              "sinfoni.bp_sky",
+                              8);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"bp_sky-it");
+  cpl_parameterlist_append(list, p);
+
+  /* float 
+     threshold used in the clean mean percentage of rejection used to reject 
+     low and high frame */
+ /* percentage of extreme pixel value to reject when calculating the mean 
+    and stdev */
+  p = cpl_parameter_new_range("sinfoni.bp_sky.low_rejection",
+                  CPL_TYPE_DOUBLE,
+                              "low_rejection: "
+                              "percentage of rejected low intensity "
+                              "pixels before averaging",
+                              "sinfoni.bp_sky",
+                              0.1,0.0,1.0);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"bp_sky-low_rej");
+  cpl_parameterlist_append(list, p);
+
+  /* float 
+     threshold used in the clean mean percentage of rejection used to reject 
+     low and high frame */
+ /* percentage of extreme pixel value to reject when calculating the mean 
+    and stdev */
+  p = cpl_parameter_new_range("sinfoni.bp_sky.high_rejection",
+                  CPL_TYPE_DOUBLE,
+                              "high_rejection: "
+                              "percentage of rejected high intensity "
+                              "pixels before averaging",
+                              "sinfoni.bp_sky",
+                              0.1,0.0,1.0);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"bp_sky-upp_rej");
+  cpl_parameterlist_append(list, p);
+
+
+  /* position in the frame lower left in X */
+  /* pixel coordinate of lower left sinfo_edge of a rectangle zone from which 
+     image statistics are computed */
+  p = cpl_parameter_new_range("sinfoni.bp_sky.llx",
+                  CPL_TYPE_INT,
+                              "llx: "
+                              "to compute image statistics on a rectangular"
+                              "zone of the image the coordinates of the "
+                              "rectangle are needed:" 
+                              "lower left x coordinate",
+                              "sinfoni.bp_sky",
+                              LLX,DET_PIX_MIN,DET_PIX_MAX);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"bp_sky-llx");
+  cpl_parameterlist_append(list, p);
+
+
+
+  /* position in the frame lower left in Y */
+  /* pixel coordinate of lower left sinfo_edge of a rectangle zone from which 
+     image statistics are computed */
+  p = cpl_parameter_new_range("sinfoni.bp_sky.lly",
+                  CPL_TYPE_INT,
+                              "lly: "
+                              "to compute image statistics on a rectangular"
+                              "zone of the image the coordinates of the "
+                              "rectangle are needed:" 
+                              "lower left y coordinate",
+                              "sinfoni.bp_sky",
+                              LLY,DET_PIX_MIN,DET_PIX_MAX);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"bp_sky-lly");
+  cpl_parameterlist_append(list, p);
+
+  /* Upper right position in CCD : should be urx */
+  /* pixel coordinate of upper right sinfo_edge of a rectangle zone from which 
+    image statistics are computed */
+  p = cpl_parameter_new_range("sinfoni.bp_sky.urx",
+                  CPL_TYPE_INT,
+                              "urx: "
+                              "to compute image statistics on a rectangular"
+                              "zone of the image the coordinates of the "
+                              "rectangle are needed:" 
+                              "upper right x coordinate",
+                              "sinfoni.bp_sky",
+                              URX,DET_PIX_MIN,DET_PIX_MAX);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"bp_sky-urx");
+  cpl_parameterlist_append(list, p);
+
+  /* Upper right position in CCD : should be ury */
+  /* pixel coordinate of upper right sinfo_edge of a rectangle zone from which 
+    image statistics are computed */
+  p = cpl_parameter_new_range("sinfoni.bp_sky.ury",
+                  CPL_TYPE_INT,
+                              "ury: "
+                              "to compute image statistics on a rectangular"
+                              "zone of the image the coordinates of the "
+                              "rectangle are needed:" 
+                              "upper right y coordinate",
+                              "sinfoni.bp_sky",
+                              URY,DET_PIX_MIN,DET_PIX_MAX);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"bp_sky-ury");
+  cpl_parameterlist_append(list, p);
+
+  /* boolean (implemented as integer) useda s a switch */
+  /* indicates if the values beyond threshold values should be marked 
+     as bad before proceeding to sinfo_median filtering */
+  p = cpl_parameter_new_value("sinfoni.bp_sky.threshold_index",
+                  CPL_TYPE_BOOL,
+                              "Threshold Index: "
+                              "indicator that indicates if the values "
+                              "beyond a threshold deviation from the mean "
+                              "are flagged as bad pixels",
+                              "sinfoni.bp_sky",
+                              TRUE);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"bp_sky-thr-ind");
+  cpl_parameterlist_append(list, p);
+
+  /* threshold value. Float. Threshold used to find bad pixel */
+  /* factor to the clean standard deviation to define the threshold 
+     deviation from the clean mean */
+  p = cpl_parameter_new_range("sinfoni.bp_sky.mean_factor",
+                  CPL_TYPE_DOUBLE,
+                              "Mean Factor: "
+                              "factor to the clean standard deviation to "
+                              "define the threshold deviation from the "
+                              "clean mean",
+                              "sinfoni.bp_sky",
+                              10.,0.1,1.e10);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"bp_sky-mean-fct");
+  cpl_parameterlist_append(list, p);
+
+
+
+  p = cpl_parameter_new_value("sinfoni.bp_sky.min_cut",
+                  CPL_TYPE_DOUBLE,
+                              "the minimum value of real data",
+                              "sinfoni.bp_sky",
+                              0.1);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"bp_sky-min_cut");
+  cpl_parameterlist_append(list, p);
+
+
+  p = cpl_parameter_new_value("sinfoni.bp_sky.max_cut",
+                  CPL_TYPE_DOUBLE,
+                              "the minimum value of real data",
+                              "sinfoni.bp_sky",
+                              50000.);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"bp_sky-max_cut");
+  cpl_parameterlist_append(list, p);
+
+  return;
+
+}
+/**@}*/
diff --git a/sinfoni/sinfo_bp_sky_config.h b/sinfoni/sinfo_bp_sky_config.h
new file mode 100644
index 0000000..889c516
--- /dev/null
+++ b/sinfoni/sinfo_bp_sky_config.h
@@ -0,0 +1,38 @@
+/* $Id: sinfo_bp_sky_config.h,v 1.1 2006/10/20 08:06:32 amodigli Exp $
+ *
+ * This file is part of the CPL (Common Pipeline Library)
+ * Copyright (C) 2002 European Southern Observatory
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*
+ * $Author: amodigli $
+ * $Date: 2006/10/20 08:06:32 $
+ * $Revision: 1.1 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+ /****************************************************************
+  *           Bad pixel search  (normal method)                  *
+  ****************************************************************/
+#ifndef SINFO_BP_SKY_CONFIG_H
+#define SINFO_BP_SKY_CONFIG_H
+
+#include "cpl.h"  
+#include "sinfo_globals.h"
+
+void sinfo_bp_sky_config_add(cpl_parameterlist *list);
+
+#endif
diff --git a/sinfoni/sinfo_coltilt.c b/sinfoni/sinfo_coltilt.c
new file mode 100644
index 0000000..4f3b5df
--- /dev/null
+++ b/sinfoni/sinfo_coltilt.c
@@ -0,0 +1,1200 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*******************************************************************************
+* E.S.O. - VLT project
+*
+*
+*
+* who       when      what
+* --------  --------  ----------------------------------------------
+* schreib  19/12/00  created
+*/
+
+/************************************************************************
+*   NAME
+*        sinfo_coltilt.c -
+*        procedures to correct for tilted spectra 
+*
+*   SYNOPSIS
+*   1) float sinfo_new_slope_of_spectrum(cpl_image * ns_image,
+*                             int        box_length,
+*                             float      fwhm,
+*                             float      minDiff )
+*   2) cpl_image * sinfo_new_shift_rows(cpl_image * image,
+*                            float      slope )
+*   3) void sinfo_new_parameter_to_ascii ( float * parameter, 
+*                              int n,
+*                              char * filename )
+*   4) float * sinfo_new_ascii_to_parameter ( char * filename,
+*                                 int * n )
+*   5) double * sinfo_new_curvature_of_spectrum( cpl_image * ns_image,
+*                              int        order,
+*                                    int        box_length,
+*                                    int        left_pos,
+*                                    int        right_pos,
+*                                    float      fwhm,
+*                                    float      minDiff )
+*
+*
+*   DESCRIPTION
+*   1)  determines the sub-pixel shifts of each row by using
+*       an image with at least one continuum spectrum of a pinhole
+*       this is done by searching the spectrum within the image
+*       then fitting the spectrum along the rows within a given box
+*       by a sinfo_gaussian, so that the exact position is determined for
+*       each row. Afterwards, a straight line is fitted through the
+*       fitted positions. The slope of this linear fit is returned.
+*   2)  shifts the rows of a raw image by using the output of 
+*       sinfo_slopeOfSpectrum and applying polynomial interpolation
+*   3)  stores parameters in an ASCII file 
+*   4)  writes parameters stored in an ASCII file in an float array
+*   5)  this routine determines the curvature of a spectrum by fitting
+*       a polynomial to a continuum spectrum. This is done by using
+*       an image with at least one continuum spectrum of a pinhole.
+*       this is done by searching the spectrum within the image
+*       then fitting the spectrum along the rows within a given box
+*       by a sinfo_gaussian, so that the exact position is determined for
+*       each row. Afterwards, a polynomial is fitted through the
+*       found positions. The polynomial coefficients are returned.
+*
+*
+*   FILES
+*
+*   ENVIRONMENT
+*
+*   RETURN VALUES
+*
+*   CAUTIONS
+*
+*   EXAMPLES
+*
+*   SEE ALSO
+*
+*   BUGS
+*
+*------------------------------------------------------------------------
+*/
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#define POSIX_SOURCE 1
+#include "sinfo_vltPort.h"
+
+/*
+ * System Headers
+ */
+
+/*
+ * Local Headers
+ */
+
+#include "sinfo_coltilt.h"
+#include "sinfo_new_resampling.h"
+#include "sinfo_fit_curve.h"
+#include "sinfo_functions.h"
+/**@{*/
+/**
+ * @defgroup sinfo_coltilt Column tilt computation
+ *
+ * TBD
+ */
+
+/*----------------------------------------------------------------------------
+ *                            Function codes
+ *--------------------------------------------------------------------------*/
+
+/**
+   @name   sinfo_new_slope_of_spectrum()
+   @memo determines the sub-pixel shifts of each row
+   @param  ns_image   image with at least one continuum spectrum of a pinhole
+   @param  box_length width of the box in which the lines are fit by a Gaussian
+   @param  fwhm       first guess of the full width at half maximum
+   @param  min_amplitude_factor factor peak/background below given threshold 
+           the fit is not carried through
+   @return slope of a straight line fitted to the spectrum. -FLT_MAX if 
+           something went wrong.
+   @doc    determines the sub-pixel shifts of each row by using an image with 
+           at least one continuum spectrum of a pinhole this is done by 
+           searching the spectrum within the image then fitting the spectrum 
+           along the rows within a given box by a Gaussian, so that the exact 
+           position is determined for each row. Afterwards, a straight line is 
+           fitted through the fitted positions. The slope of this linear fit 
+           is returned.
+
+  */
+
+float 
+sinfo_new_slope_of_spectrum( cpl_image * ns_image,
+                       int        box_length,
+                       float      fwhm,
+                       float      minDiff )
+{
+    int i, k, row, col ;
+    int counter, iters ;
+    int xdim, ndat, its, numpar ;
+    float maxval ;
+    float tol, lab ;
+    float* col_value=NULL ;
+    float* column_value=NULL ;
+    pixelvalue* col_position=NULL ;
+    int* column_position=NULL ;
+    float* x_position=NULL ;
+
+
+    int col_median ;
+    float * xdat, * wdat ;
+    int * mpar ;
+    Vector * line ;
+    FitParams ** dec_par ;
+    FitParams *  par ;
+
+    float* x=NULL; 
+    float* y=NULL; 
+    float* sig=NULL ;
+
+    int position ;
+    int ndata, mwt ;
+    float a, b, siga, sigb, chi2, q ;
+    int bad_ind ;
+    int lx=0;
+    int ly=0;
+    float* pdata=NULL;
+
+    if ( ns_image == NULL )
+    {
+        sinfo_msg_error(" sorry, no image given") ;
+        return FLAG ;
+    }
+    lx=cpl_image_get_size_x(ns_image);
+    ly=cpl_image_get_size_x(ns_image);
+
+
+    if ( box_length <= 1 || box_length >= (int) sqrt(lx) )
+    {
+        sinfo_msg_error(" wrong box length given") ;
+        return FLAG ;
+    }
+    if ( fwhm < 1. || fwhm > 10. )
+    {
+        sinfo_msg_error("wrong full width at half maximum given") ;
+        return FLAG ;
+    }
+    if ( minDiff < 1. )
+    {
+        sinfo_msg_error("wrong amplitude threshold given") ;
+        return FLAG ;
+    }
+
+
+
+    col_value=cpl_calloc(ly,sizeof(float)) ;
+    column_value=cpl_calloc(ly,sizeof(float)) ;
+    col_position=(pixelvalue*)cpl_calloc(ly,sizeof(pixelvalue)) ;
+    column_position=cpl_calloc(ly,sizeof(int)) ;
+    x_position=cpl_calloc(ly,sizeof(float)) ;
+
+
+
+    x=cpl_calloc(lx,sizeof(float)); 
+    y=cpl_calloc(lx,sizeof(float)); 
+    sig=cpl_calloc(lx,sizeof(float)) ;
+    pdata=cpl_image_get_data_float(ns_image);
+    /* go through the image rows */
+    for ( row = 0 ; row < ly ; row++ )
+    {
+        col_value[row] = -FLT_MAX ;
+        col_position[row] = -1. ;
+        /* find the maximum value in each row and store the found column */
+        for ( col = 0 ; col < lx ; col++ )
+        {
+            if ( pdata[col+row*lx] > col_value[row] )
+            {
+                col_value[row]    = pdata[col+row*lx] ;
+                col_position[row] = (pixelvalue)col ;
+            }
+        }
+    }
+
+    /* now determine the sinfo_new_median of the found columns to be sure 
+       to have the brightest spectrum */
+    col_median = (int)sinfo_new_median(col_position, ly) ;
+    sinfo_msg ("sinfo_new_median column position of brightest spectrum %d\n", 
+              col_median) ;
+
+    /* now find the peaks around col_median over the whole spectral range */
+    for ( row = 0 ; row < ly ; row++ )
+    {
+        x_position[row] = 0. ;
+        column_value[row] = -FLT_MAX ;
+        column_position[row] = -1 ;
+        for ( col = col_median - box_length ; 
+              col <= col_median + box_length ; col++ )
+        {
+            if ( pdata[col+row*lx] > column_value[row] )
+            {
+                column_value[row] = pdata[col+row*lx] ; 
+                column_position[row] = col ;
+            }
+        }
+
+        /* allocate memory for the array where the line is fitted in */
+        if ( NULL == (line = sinfo_new_vector (2*box_length + 1)) )
+        {
+            sinfo_msg_error ("cannot allocate new Vector in row %d", row) ;
+            return FLAG ;
+        }
+
+        /* allocate memory */
+        xdat = (float *) cpl_calloc( line -> n_elements, sizeof (float) ) ;
+        wdat = (float *) cpl_calloc( line -> n_elements, sizeof (float) ) ;
+        mpar = (int *)   cpl_calloc( MAXPAR, sizeof (int) ) ;
+        dec_par = sinfo_new_fit_params(1) ;
+    par = dec_par[0];
+
+        counter = 0 ;
+        bad_ind = 0 ;
+        /* store the values to fit in a Vector object */
+        for ( col = column_position[row] - box_length ; 
+              col <= column_position[row] + box_length ; col++ )
+        {
+            if ( col < 0 || col >= lx )
+            {
+                sinfo_msg_error ("wrong spectrum position or box_length "
+                                 "given in row: %d", row) ;
+                cpl_free (xdat) ;
+                cpl_free (wdat) ;
+                cpl_free (mpar) ;
+                sinfo_new_destroy_fit_params(&dec_par) ;
+                sinfo_new_destroy_vector( line ) ;
+                return FLAG ;
+            }
+            else if ( isnan(pdata[col+row*lx]) )
+            {
+                bad_ind = 1 ;
+            }
+            else
+            {
+                line -> data[counter] = pdata[col + row*lx] ;
+                counter++ ;
+            }
+        }
+ 
+        /* go to the next row if a bad pixel is inside the box */
+        if ( bad_ind == 1 )
+        {
+            sinfo_msg_warning ("sorry, bad pixel inside fitting "
+                               "box in row: %d", row) ;
+            cpl_free (xdat) ;
+            cpl_free (wdat) ;
+            cpl_free (mpar) ;
+            sinfo_new_destroy_fit_params(&dec_par) ;
+            sinfo_new_destroy_vector( line ) ;
+            continue ;
+        }
+
+        /*--------------------------------------------------------------------
+         * go through the line sinfo_vector
+         * determine the maximum pixel value in the line sinfo_vector
+         */
+        maxval = -FLT_MAX ;
+        position = -INT32_MAX ;
+        for ( i = 0 ; i < counter ; i++ )
+        {
+            xdat[i] = i ;
+            wdat[i] = 1.0 ;
+            if ( line -> data[i] >= maxval )
+            {
+                maxval = line -> data[i] ;
+                position = i ;
+            }
+        }
+
+        /* set initial values for the fitting routine */
+        xdim     = XDIM ;
+        ndat     = line -> n_elements ;
+        numpar   = MAXPAR ;
+        tol      = TOL ;
+        lab      = LAB ;
+        its      = ITS ;
+        (*par).fit_par[1] = fwhm ;
+        (*par).fit_par[2] = (float) position ;
+        (*par).fit_par[3] = (float) (line -> data[0] + 
+                            line -> data[line->n_elements - 1]) / 2.0 ;
+
+        (*par).fit_par[0]  = maxval - ((*par).fit_par[3]) ;
+        /* exclude negative peaks and low signal cases */
+        if ( (*par).fit_par[0] < minDiff )
+        {
+            sinfo_msg_warning ("sorry, negative peak or signal of line "
+                               "too low to fit in row: %d", row) ;
+            cpl_free (xdat) ;
+            cpl_free (wdat) ;
+            cpl_free (mpar) ;
+            sinfo_new_destroy_fit_params(&dec_par) ;
+            sinfo_new_destroy_vector( line ) ;
+            continue ;
+        }
+
+        for ( k = 0 ; k < MAXPAR ; k++ )
+        {
+            (*par).derv_par[k] = 0.0 ;
+            mpar[k] = 1 ;
+        }
+
+        /* finally, do the least square fit using a sinfo_gaussian */
+        if ( 0 > ( iters = sinfo_new_lsqfit_c( xdat, &xdim, 
+                                               line -> data, wdat, 
+                                               &ndat, (*par).fit_par,
+                                               (*par).derv_par, mpar, 
+                                               &numpar, &tol, &its, &lab )) )
+        {
+            sinfo_msg_warning ("sinfo_new_lsqfit_c: least squares fit "
+                               "failed in row: %d, error no.: %d",row,iters) ;
+            cpl_free (xdat) ;
+            cpl_free (wdat) ;
+            cpl_free (mpar) ;
+            sinfo_new_destroy_fit_params(&dec_par) ;
+            sinfo_new_destroy_vector( line ) ;
+            continue ;
+        }
+
+        /* check for negative fit results */
+        if ( (*par).fit_par[0] <= 0. || (*par).fit_par[1] <= 0. ||
+             (*par).fit_par[2] <= 0. )
+        {
+            sinfo_msg_warning ("negative parameters as fit result, "
+                               "not used! in row: %d", row) ;
+            cpl_free (xdat) ;
+            cpl_free (wdat) ;
+            cpl_free (mpar) ;
+            sinfo_new_destroy_fit_params(&dec_par) ;
+            sinfo_new_destroy_vector( line ) ;
+            continue ;
+        }
+
+        /* correct the fitted position for the given row of the line in 
+           image coordinates */
+        x_position[row] =  (float) (column_position[row] - box_length) + 
+                           (*par).fit_par[2] ;
+
+        /* store the fit errors of the positions as weights for the later 
+           linear fit */
+        sig[row] = (*par).derv_par[2] ;
+
+        /* free memory */
+        sinfo_new_destroy_fit_params(&dec_par) ;
+        sinfo_new_destroy_vector ( line ) ;
+        cpl_free ( xdat ) ;
+        cpl_free ( wdat ) ;
+        cpl_free ( mpar ) ;
+    }
+
+    /* -----------------------------------------------------------------------
+     * now that we have a sub-pixel resolved list of spectral maxima stored 
+     * in x_position[row]
+     * We can fit a flux weighted straight line to the positions to determine 
+     * the spectral column shifts.
+     */
+    ndata = 0 ;
+    for ( row = 0 ; row < lx ; row++ )
+    {
+        if ( x_position[row] == 0. || sig[row] == 0. )
+        {
+            continue ;
+        }
+        else 
+        {
+            y[ndata]   = x_position[row] ;
+            x[ndata]   = (float)row ;
+            sig[ndata] = sig[row] ;
+            ndata++ ;
+        }
+    }
+    if ( ndata < 10 )
+    {
+        sinfo_msg_error("not enough positions to do the linear fit") ;
+        return FLAG ;
+    }
+
+    /* now do the fit and return the slope of the straight line */
+    mwt = 0 ;
+    sinfo_my_fit(x, y, ndata, sig, mwt, &a, &b, &siga, &sigb, &chi2, &q) ;
+
+    cpl_free(col_value) ;
+    cpl_free(column_value) ;
+    cpl_free(col_position) ;
+    cpl_free(column_position) ;
+    cpl_free(x_position) ;
+
+    cpl_free(x); 
+    cpl_free(y); 
+    cpl_free(sig) ;
+
+    return b ;
+}
+
+/**
+   @name sinfo_new_shift_rows()
+   @param image   raw image in which the rows should be shifted
+   @param slope   slope of a fitted straight line along a spectrum
+                  output of sinfo_slopeOfSpectrum
+   @param n_order order of the interpolation polynom
+   @return resulting image with shifted rows
+   @doc   shifts the rows of a raw image by using the output of
+          sinfo_slopeOfSpectrum and applying polynomial interpolation
+   
+ */
+
+cpl_image * 
+sinfo_new_shift_rows( cpl_image * image,
+                      float      slope, 
+                      int        n_order )
+{
+    cpl_image * returnImage=NULL ;
+    float xshift=0 ;
+    int   intshift = 0 ;
+    float sum=0;
+    float new_sum=0;
+
+    float* xnum=NULL ;
+    float* row_data=NULL ;
+    float* corrected_row_data=NULL ;
+
+    float eval=0 /*, dy*/ ;
+    float * imageptr=NULL ;
+    int col=0;
+    int row=0;
+    int firstpos=0;
+    int n_points=0;
+    int i=0;
+    int flag=0;
+    int ilx=0;
+    int ily=0;
+    int olx=0;
+    int oly=0;
+    float* pidata=NULL;
+    float* podata=NULL;
+
+    if ( image == NULL )
+    {
+        sinfo_msg_error("sorry, no image given") ;
+        return NULL ;
+    }
+
+    if ( slope == 0. )
+    {
+        sinfo_msg_error("there is no need to shift the image rows!") ;
+        return NULL ;
+    }
+
+    if ( n_order <= 0 )
+    {
+        sinfo_msg_error("wrong order of interpolation polynom given!") ;
+        return NULL ;
+    }
+
+    returnImage = cpl_image_duplicate( image ) ;
+    ilx=cpl_image_get_size_x(image);
+    ily=cpl_image_get_size_y(image);
+    olx=cpl_image_get_size_x(returnImage);
+    oly=cpl_image_get_size_y(returnImage);
+    pidata=cpl_image_get_data_float(image);
+    podata=cpl_image_get_data_float(returnImage);
+
+
+    n_points = n_order + 1 ;
+    if ( n_points % 2 == 0 )
+    {
+        firstpos = (int)(n_points/2) - 1 ;
+    }
+    else
+    {
+        firstpos = (int)(n_points/2) ;
+    }
+
+
+    xnum=cpl_calloc(n_order + 1,sizeof(float)) ;
+    row_data=cpl_calloc(ilx,sizeof(float)) ;
+    corrected_row_data=cpl_calloc(ilx,sizeof(float)) ;
+
+    /* fill the xa[] array for the polint function */
+    for ( i = 0 ; i < n_points ; i++ )
+    {
+        xnum[i] = i ;
+    }
+
+    /* go through the image rows */
+    for ( row = 0 ; row < ily ; row++ )
+    {
+        /* determine the shift for each row, the middle row is not shifted */
+        xshift = slope * (float)( (ily / 2) - row ) ;
+
+        intshift = sinfo_new_nint(xshift) ;
+        xshift = xshift - (float)intshift ;
+
+        for ( col = 0 ; col < ilx ; col++ )
+        {
+            corrected_row_data[col] = 0. ;
+        }
+        sum = 0. ; /* initialize flux for later rescaling */
+        /* go through the image columns */
+        for ( col = 0 ; col < ilx ; col++ )
+        {
+        /* consider integer pixel shifts */
+        if ( intshift < 0 )
+            {
+        if ( col - intshift < ilx )
+        {
+            row_data[col] = pidata[col-intshift+row*ilx] ;
+                }
+        else
+        {
+            row_data[col] = 0. ;
+                }
+        }
+        else if ( intshift > 0 )
+        {
+        if ( col - intshift >= 0 )
+        {
+            row_data[col] = pidata[col-intshift+row*ilx] ;
+                }
+        else
+        {
+            row_data[col] = 0. ;
+        }
+        }
+        else
+        {
+               row_data[col] = pidata[col+row*ilx] ;
+        }
+
+            /* don't consider the sinfo_edge pixels for flux calculation */
+            if ( col != 0 && col != ilx - 1 && !isnan(row_data[col]) )
+            {
+                sum += row_data[col] ;
+            }
+            if (isnan(row_data[col])) 
+            {
+                row_data[col] = 0. ;
+                for (i = col - firstpos ; i < col - firstpos + n_points ; i++ )
+                {
+                    if ( i < 0 ) continue ;
+                    if ( i >= ilx) continue ;
+                    corrected_row_data[i] = ZERO ;
+                }
+            }
+        }
+
+
+        /* --------------------------------------------------------------------
+         * now we do the polynomial interpolation to achieve the fractional
+         * shift that means call polint
+         */
+        new_sum = 0. ;
+        for ( col = 0 ; col < ilx ; col++ )
+        {
+            /* ---------------------------------------------------------------
+             * now determine the arrays of size n_points with which the
+             * polynom is determined and determine the position eval
+             * where the polynom is evaluated in polint of N.R..
+             * Take care of the points near the row edges!
+             */
+            if ( isnan(corrected_row_data[col]) )
+            {
+                 continue ;
+            }
+            if ( col - firstpos < 0 )
+            {
+                imageptr = &row_data[0] ;
+                eval     = (float)col - xshift ;
+            }
+            else if ( col - firstpos + n_points >= ilx )
+            {
+                imageptr = &row_data[ilx - n_points] ;
+                eval     = (float)(col + n_points - ilx) - xshift ;
+            }
+            else
+            {
+                imageptr = &row_data[col-firstpos] ;
+                eval     = (float)firstpos - xshift ;
+            }
+
+        flag=0;
+        corrected_row_data[col]=sinfo_new_nev_ille(xnum,imageptr,
+                                                       n_order,eval,&flag);
+            /*polint( xnum - 1, imageptr, n_points, eval, 
+                      &corrected_row_data[col], &dy ) ;*/
+
+            /* don't take the sinfo_edge points to calculate 
+               the scaling factor */
+            if (col != 0 && col != ilx - 1 && !isnan(corrected_row_data[col]) )
+            {
+                new_sum += corrected_row_data[col] ;
+            }
+        }
+
+        if ( new_sum == 0. )
+        {
+            new_sum = 1. ;
+        }
+        for ( col = 0 ; col < ilx ; col++ )
+        {
+            if ( isnan(corrected_row_data[col]))
+            {
+                podata[col+row*ilx] = ZERO ;
+            }
+            else
+            {
+              /* rescale the row data and fill the returned image */
+              /* This gives sometimes inconsistent results if 
+                 bad pixels are around */
+              /* rescaling is commented out because it delivers wrong results
+                 in case of appearance of blanks or bad pixels */
+             /*   corrected_row_data[col] *= sum / new_sum ; */
+                podata[col+row*ilx] = corrected_row_data[col] ;
+            }
+        }
+    }      
+
+    cpl_free(xnum) ;
+    cpl_free(row_data) ;
+    cpl_free(corrected_row_data);
+
+    return returnImage ;
+}
+
+
+/**
+   @name  sinfo_new_parameter_to_ascii()
+   @memo stores parameters in an ASCII file
+   @param parameter float parameter array to be stored in an ASCII file
+   @param number number of parameters
+   @param filename filename of ASCII file
+   @return void
+    
+*/
+
+void 
+sinfo_new_parameter_to_ascii ( float * parameter, 
+                        int n,
+                        char * filename )
+{
+    FILE * fp ;
+    int     i=0 ;
+
+    if ( parameter == NULL || filename == NULL || n <= 0 )
+    {
+        sinfo_msg_error ("input is missing or wrong!") ;
+        return ;
+    }
+    
+    if ( NULL == (fp = fopen ( filename, "w" ) ) )
+    {
+        sinfo_msg_error("cannot open %s", filename) ;
+        return ;
+    }
+
+    for ( i = 0 ; i < n ; i++ )
+    {
+        fprintf (fp, "%le\n", parameter[i] ) ;
+    }
+    fclose (fp ) ;
+}
+
+/**
+   @name  sinfo_new_ascii_to_parameter()
+   @param filename filename of ASCII file
+   @param n number of parameters in the parameter array array of parameters
+   @doc writes parameters stored in an ASCII file in an float array
+*/
+
+float * 
+sinfo_new_ascii_to_parameter ( char * filename,
+                           int * n )
+{
+    FILE * fp ;
+    float * parameter=NULL ;
+    int     i=0 ;
+
+    if ( filename == NULL || n == NULL )
+    {
+        sinfo_msg_error ("Input is missing or wrong") ;
+        return NULL ;
+    }
+    
+    if ( NULL == (fp = fopen ( filename, "r" ) ) )
+    {
+        sinfo_msg_error("cannot open %s", filename) ;
+        return NULL ;
+    }
+
+    /* allocate memory */
+
+    if (NULL == ( parameter = (float*) cpl_calloc (ESTIMATE, sizeof(float)) ) )
+    {
+        sinfo_msg_error ("cannot allocate memory") ;
+        fclose (fp ) ;
+        return NULL ;
+    }
+
+    i = 0 ;
+    while ( fscanf(fp, "%g\n", &parameter[i]) != EOF )
+    {
+        i++ ;
+    }
+    *n = i ;
+
+    fclose (fp ) ;
+
+    return parameter ;
+}
+
+
+/**
+    @name  sinfo_new_curvature_of_spectrum()
+   @param ns_image   image with at least one continuum spectrum of a pinhole
+   @param order      order of the fit polynomial
+   @param box_length width of the box in which the lines are fit by a Gaussian
+   @param left_pos
+   @param right_pos left and right positions between which the spectrum should 
+                    be located
+   @param fwhm      first guess of the full width at half maximum
+   @param min_amplitude_factor factor peak/background below given
+                       threshold the fit is not carried through
+   @return resulting polynomial coefficients.
+   @doc    this routine determines the curvature of a spectrum by fitting
+           a polynomial to a continuum spectrum. This is done by using
+       an image with at least one continuum spectrum of a pinhole.
+       this is done by searching the spectrum within the image
+       then fitting the spectrum along the rows within a given box
+       by a sinfo_gaussian, so that the exact position is determined for
+       each row. Afterwards, a polynomial is fitted through the
+       found positions. The polynomial coefficients are returned.
+*/  
+
+double * 
+sinfo_new_curvature_of_spectrum( cpl_image * ns_image,
+                    int        order,
+                         int        box_length,
+                 int        left_pos,
+             int        right_pos,
+                         float      fwhm,
+                         float      minDiff )
+{
+    int i=0;
+    int k=0;
+    int row=0;
+    int col=0;
+    int counter=0;
+    int iters=0;
+    int xdim=0;
+    int ndat=0;
+    int its=0;
+    int numpar=0;
+    float maxval=0 ;
+    float tol=0;
+    float lab=0;
+
+    float* col_value=NULL ;
+    float* column_value=NULL ;
+    pixelvalue* col_position=NULL ;
+    int* column_position=NULL ;
+    float* x_position=NULL ;
+
+    int col_median=0;
+    float * xdat=NULL;
+    float * wdat=NULL;
+    int * mpar=NULL;
+    Vector * line=NULL;
+    FitParams ** dec_par=NULL ;
+    FitParams * par=NULL ;
+    int position=0 ;
+    int ndata=0 ;
+    int bad_ind=0 ;
+    dpoint * list=NULL ;
+    double * coeffs=NULL ;
+    double offset=0 ;
+    int lx=0;
+    int ly=0;
+    float* pdata=NULL;
+
+    if ( ns_image == NULL )
+    {
+        sinfo_msg_error("sorry, no image given") ;
+        return NULL ;
+    }
+    lx=cpl_image_get_size_x(ns_image);
+    ly=cpl_image_get_size_y(ns_image);
+
+    if ( box_length <= 1 || box_length >= right_pos - left_pos )
+    {
+        sinfo_msg_error("wrong box length given") ;
+        return NULL ;
+    }
+    if ( fwhm < 1. || fwhm > 10. )
+    {
+        sinfo_msg_error("wrong full width at half maximum given") ;
+        return NULL ;
+    }
+    if ( left_pos < 0 || right_pos <= left_pos || right_pos > lx )
+    {
+        sinfo_msg_error("wrong left and right positions") ;
+        return NULL ;
+    }
+    if ( minDiff < 1. )
+    {
+        sinfo_msg_error("wrong amplitude threshold given!") ;
+        return NULL ;
+    }
+
+
+
+    col_value=cpl_calloc(ly,sizeof(float)) ;
+    column_value=cpl_calloc(ly,sizeof(float)) ;
+    col_position=(pixelvalue*)cpl_calloc(ly,sizeof(pixelvalue)) ;
+    column_position=cpl_calloc(ly,sizeof(int)) ;
+    x_position=cpl_calloc(ly,sizeof(float)) ;
+
+    /* go through the image rows */
+    for ( row = 0 ; row < ly ; row++ )
+    {
+        col_value[row] = -FLT_MAX ;
+        col_position[row] = -1. ;
+        /* find the maximum value in each row and store the found column */
+        for ( col = left_pos ; col < right_pos ; col++ )
+        {
+            if ( pdata[col+row*lx] > col_value[row] )
+            {
+                col_value[row]    = pdata[col+row*lx] ;
+                col_position[row] = (pixelvalue)col ;
+            }
+        }
+    }
+
+    /* now determine the sinfo_new_median of the found columns to be sure 
+       to have the brightest spectrum */
+    col_median = (int)sinfo_new_median(col_position, right_pos - left_pos) ;
+
+    /* now find the peaks around col_median over the whole spectral range */
+    for ( row = 0 ; row < ly ; row++ )
+    {
+        x_position[row] = 0. ;
+        column_value[row] = -FLT_MAX ;
+        column_position[row] = -1 ;
+        for ( col = col_median - box_length ; 
+              col <= col_median + box_length ; col++ )
+        {
+            if ( pdata[col+row*lx] > column_value[row] )
+            {
+                column_value[row] = pdata[col+row*lx] ; 
+                column_position[row] = col ;
+            }
+        }
+
+        /* allocate memory for the array where the line is fitted in */
+        if ( NULL == (line = sinfo_new_vector (2*box_length + 1)) )
+        {
+            sinfo_msg_error ("cannot allocate new Vector in row: %d", row) ;
+            return NULL ;
+        }
+
+        /* allocate memory */
+        xdat = (float *) cpl_calloc( line -> n_elements, sizeof (float) ) ;
+        wdat = (float *) cpl_calloc( line -> n_elements, sizeof (float) ) ;
+        mpar = (int *)   cpl_calloc( MAXPAR, sizeof (int) ) ;
+        dec_par = sinfo_new_fit_params(1) ;
+        par = dec_par[0];
+    
+        counter = 0 ;
+        bad_ind = 0 ;
+        /* store the values to fit in a Vector object */
+        for ( col = column_position[row] - box_length ; 
+              col <= column_position[row] + box_length ; col++ )
+        {
+            if ( col < 0 || col >= lx )
+            {
+                sinfo_msg_error ("wrong spectrum position or box_length "
+                                 "given in row: %d", row) ;
+                cpl_free (xdat) ;
+                cpl_free (wdat) ;
+                cpl_free (mpar) ;
+                sinfo_new_destroy_fit_params(&dec_par) ;
+                sinfo_new_destroy_vector( line ) ;
+                return NULL ;
+            }
+            else if ( isnan(pdata[col+row*lx]) )
+            {
+                bad_ind = 1 ;
+            }
+            else
+            {
+                line -> data[counter] = pdata[col + row*lx] ;
+                counter++ ;
+            }
+        }
+ 
+        /* go to the next row if a bad pixel is inside the box */
+        if ( bad_ind == 1 )
+        {
+            sinfo_msg_warning ("sorry, bad pixel inside fitting box "
+                               "in row: %d", row) ;
+            cpl_free (xdat) ;
+            cpl_free (wdat) ;
+            cpl_free (mpar) ;
+            sinfo_new_destroy_fit_params(&dec_par) ;
+            sinfo_new_destroy_vector( line ) ;
+            continue ;
+        }
+
+        /*--------------------------------------------------------------------
+         * go through the line sinfo_vector
+         * determine the maximum pixel value in the line sinfo_vector
+         */
+        maxval = -FLT_MAX ;
+        position = -INT32_MAX ;
+        for ( i = 0 ; i < counter ; i++ )
+        {
+            xdat[i] = i ;
+            wdat[i] = 1.0 ;
+            if ( line -> data[i] >= maxval )
+            {
+                maxval = line -> data[i] ;
+                position = i ;
+            }
+        }
+
+        /* set initial values for the fitting routine */
+        xdim     = XDIM ;
+        ndat     = line -> n_elements ;
+        numpar   = MAXPAR ;
+        tol      = TOL ;
+        lab      = LAB ;
+        its      = ITS ;
+        (*par).fit_par[1] = fwhm ;
+        (*par).fit_par[2] = (float) position ;
+        (*par).fit_par[3] = (float) (line -> data[0] + 
+                                     line -> data[line->n_elements - 1]) / 2.0;
+
+        (*par).fit_par[0]  = maxval - ((*par).fit_par[3]) ;
+        /* exclude negative peaks and low signal cases */
+        if ( (*par).fit_par[0] < minDiff )
+        {
+            sinfo_msg_warning ("sorry, negative peak or signal of line "
+                               "too low to fit in row: %d", row) ;
+            cpl_free (xdat) ;
+            cpl_free (wdat) ;
+            cpl_free (mpar) ;
+            sinfo_new_destroy_fit_params(&dec_par) ;
+            sinfo_new_destroy_vector( line ) ;
+            continue ;
+        }
+
+        for ( k = 0 ; k < MAXPAR ; k++ )
+        {
+            (*par).derv_par[k] = 0.0 ;
+            mpar[k] = 1 ;
+        }
+
+        /* finally, do the least square fit using a sinfo_gaussian */
+        if ( 0 > ( iters = sinfo_new_lsqfit_c( xdat, &xdim, 
+                                               line -> data, wdat, 
+                                               &ndat, (*par).fit_par,
+                                               (*par).derv_par, mpar, 
+                                               &numpar, &tol, &its, &lab )) )
+        {
+            sinfo_msg_warning ("least squares fit failed in row: "
+                               "%d, error no.: %d", row, iters) ;
+            cpl_free (xdat) ;
+            cpl_free (wdat) ;
+            cpl_free (mpar) ;
+            sinfo_new_destroy_fit_params(&dec_par) ;
+            sinfo_new_destroy_vector( line ) ;
+            continue ;
+        }
+
+        /* check for negative fit results */
+        if ( (*par).fit_par[0] <= 0. || (*par).fit_par[1] <= 1. ||
+             (*par).fit_par[2] <= 0. )
+        {
+            sinfo_msg_warning ("negative parameters as fit result, "
+                               "not used! in row: %d", row) ;
+            cpl_free (xdat) ;
+            cpl_free (wdat) ;
+            cpl_free (mpar) ;
+            sinfo_new_destroy_fit_params(&dec_par) ;
+            sinfo_new_destroy_vector( line ) ;
+            continue ;
+        }
+
+        /* correct the fitted position for the given row of the line 
+           in image coordinates */
+        x_position[row] =  (float) (column_position[row] - box_length) + 
+                                   (*par).fit_par[2] ;
+        printf("%d %f %f\n",row, (*par).fit_par[1], x_position[row] ) ;
+
+        /* free memory */
+        sinfo_new_destroy_fit_params(&dec_par) ;
+        sinfo_new_destroy_vector ( line ) ;
+        cpl_free ( xdat ) ;
+        cpl_free ( wdat ) ;
+        cpl_free ( mpar ) ;
+    }
+    /* now allocate memory for the data to fit */
+    if ( NULL == ( list = (dpoint*) cpl_calloc (ly, sizeof (dpoint)) ) ) 
+    {
+        sinfo_msg_error("could not allocate memory!") ;
+        return NULL ;
+    }
+
+    /* ------------------------------------------------------------------------
+     * now that we have a sub-pixel resolved list of spectral maxima stored 
+     * in x_position[row] We can fit a flux weighted straight line to the 
+     * positions to determine the spectral column shifts.
+     */
+    offset = (double) ly/2. ;
+    ndata = 0 ;
+    for ( row = 0 ; row < ly ; row++ )
+    {
+        if ( x_position[row] == 0. )
+        {
+            continue ;
+        }
+        else 
+        {
+            list[ndata].y   = (double)x_position[row] ;
+            list[ndata].x   = (double)row - offset ;
+            ndata++ ;
+        }
+    }
+    
+
+    if ( NULL == (coeffs = sinfo_fit_1d_poly(order, list, ndata, NULL)) )
+    {
+        sinfo_msg_error("eclipse function sinfo_fit_1d_poly() did not work!") ;
+        return NULL ;
+    }
+    cpl_free ( list ) ;
+
+
+
+    cpl_free(col_value) ;
+    cpl_free(column_value) ;
+    cpl_free(col_position) ;
+    cpl_free(column_position) ;
+    cpl_free(x_position) ;
+     
+    return coeffs ;
+}
+
+/**
+ at name sinfo_new_image_warp_fits
+ at memo correct optical distortions
+ at param image distorted image
+ at param kernel_type type of kernel to correct distortions
+ at param poly_table table containing distortion coefficients
+ at return image distortion corrected
+*/    
+cpl_image * 
+sinfo_new_image_warp_fits( cpl_image * image,
+                      char      * kernel_type, 
+                      char      * poly_table )
+{
+        cpl_image  * warped=NULL;
+    /* Following are for polynomial transforms */
+    cpl_polynomial    * poly_u=NULL;        /* polynomial definition */
+    cpl_polynomial    * poly_v=NULL;        /* polynomial definition */
+        cpl_table* poly_tbl=NULL;
+    cpl_vector      *   profile=NULL ;
+        cpl_size local_pow[2];
+        int             i=0;
+
+    /*fscanf(poly_in,"%s",poly_string);*/
+    /* sinfo_msg("%s",poly_string); */
+    
+    poly_u = cpl_polynomial_new(2);
+        if (poly_u == NULL) {
+            sinfo_msg_error("cannot read 2D poly from arc table") ;
+            return NULL ;
+        }
+ 
+        if (poly_u != NULL) {
+      sinfo_msg_debug("Get the arc distortion from the file %s",
+                          poly_table);
+      if(sinfo_is_fits_file(poly_table) != 1) {
+        sinfo_msg_error("Input file %s is not FITS",poly_table);
+        return NULL;
+      }
+
+      if(NULL==(poly_tbl = cpl_table_load(poly_table,1,0))) {
+        sinfo_msg_error("cannot load the arc table") ;
+        cpl_polynomial_delete(poly_u) ;
+        return NULL ;
+      }
+
+      for (i=0 ; i<cpl_table_get_nrow(poly_tbl) ; i++) {
+            local_pow[0] = cpl_table_get_int(poly_tbl, "degx", i, NULL) ; 
+            local_pow[1] = cpl_table_get_int(poly_tbl, "degy", i, NULL) ;
+            cpl_polynomial_set_coeff(poly_u, local_pow,
+           cpl_table_get_double(poly_tbl, "coeff", i, NULL)) ;
+      }
+
+      cpl_table_delete(poly_tbl) ;
+    } else {
+      sinfo_msg("Use the ID polynomial for the arc dist") ;
+      local_pow[0] = 1 ;
+      local_pow[1] = 0 ;
+      cpl_polynomial_set_coeff(poly_u, local_pow, 1.0) ;
+    }
+
+        poly_v=cpl_polynomial_new(2);
+        local_pow[0]=0;
+        local_pow[1]=1;
+
+        cpl_polynomial_set_coeff(poly_v,local_pow,1.0);
+    profile = cpl_vector_new(CPL_KERNEL_DEF_SAMPLES) ;
+    cpl_vector_fill_kernel_profile(profile, CPL_KERNEL_TANH,
+                       CPL_KERNEL_DEF_WIDTH) ;
+    warped=sinfo_new_warp_image_generic(image,kernel_type,poly_u,poly_v);
+    /* YVES WAY 
+      warped = cpl_image_new(cpl_image_get_size_x(image),
+                                 cpl_image_get_size_y(image),
+                                 CPL_TYPE_FLOAT);
+       
+    if (cpl_image_warp_polynomial(warped, image, poly_u, poly_v, 
+                      profile,CPL_KERNEL_DEF_WIDTH,
+                      profile,CPL_KERNEL_DEF_WIDTH)
+        != CPL_ERROR_NONE) {
+            sinfo_msg_error("cannot correct the distortion") ;
+            cpl_image_delete(warped) ;
+            cpl_polynomial_delete(poly_u) ;
+            cpl_polynomial_delete(poly_v) ;
+            cpl_vector_delete(profile) ;
+            return NULL;
+    }
+    */
+
+      cpl_vector_delete(profile) ;
+      if (poly_u!=NULL) cpl_polynomial_delete(poly_u);
+      if (poly_v!=NULL) cpl_polynomial_delete(poly_v);
+    
+      return warped;
+}
+    
+/**@}*/
diff --git a/sinfoni/sinfo_coltilt.h b/sinfoni/sinfo_coltilt.h
new file mode 100644
index 0000000..a41c462
--- /dev/null
+++ b/sinfoni/sinfo_coltilt.h
@@ -0,0 +1,162 @@
+#ifndef SINFO_COLTILT_H
+#define SINFO_COLTILT_H
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*******************************************************************************
+* E.S.O. - VLT project
+*
+* "@(#) $Id: sinfo_coltilt.h,v 1.4 2007/06/06 07:10:45 amodigli Exp $"
+*
+* who       when      what
+* --------  --------  ----------------------------------------------
+* schreib  20/12/00  created
+*/
+
+/************************************************************************
+ * sinfo_coltilt.h
+ * routines to calculate and correct the spatial tilt of spectra in raw images
+ *----------------------------------------------------------------------
+ */
+
+/*
+ * header files
+ */
+#include <cpl.h> 
+#include "sinfo_msg.h"
+#include "sinfo_recipes.h"
+#include "sinfo_wave_calibration.h"
+#include "sinfo_spiffi_types.h"
+/*----------------------------------------------------------------------------
+ *                        Function ANSI C prototypes
+ *--------------------------------------------------------------------------*/
+/*----------------------------------------------------------------------------
+   @name   sinfo_new_slope_of_spectrum()
+   @param  ns_image   image with at least one continuum spectrum of a pinhole
+   @param  box_length width of the box in which the lines are fit by a Gaussian
+   @param  fwhm       first guess of the full width at half maximum
+   @param  min_amplitude_factor factor peak/background below given threshold 
+           the fit is not carried through
+   @return slope of a straight line fitted to the spectrum. -FLT_MAX if 
+           something went wrong.
+   @doc    determines the sub-pixel shifts of each row by using an image with 
+           at least one continuum spectrum of a pinhole this is done by 
+           searching the spectrum within the image then fitting the spectrum 
+           along the rows within a given box by a Gaussian, so that the exact 
+           position is determined for each row. Afterwards, a straight line is 
+           fitted through the fitted positions. The slope of this linear fit 
+           is returned.
+*/
+
+float 
+sinfo_new_slope_of_spectrum(cpl_image * ns_image,
+                       int        box_length,
+                       float      fwhm,
+                       float      min_amplitude_factor ) ;
+
+/**
+   @name sinfo_new_shift_rows()
+   @param image   raw image in which the rows should be shifted
+   @param slope   slope of a fitted straight line along a spectrum
+                  output of sinfo_slopeOfSpectrum
+   @param n_order order of the interpolation polynom
+   @return resulting image with shifted rows
+   @doc   shifts the rows of a raw image by using the output of
+          sinfo_slopeOfSpectrum and applying polynomial interpolation
+*/
+
+
+cpl_image * 
+sinfo_new_shift_rows(cpl_image * image,
+             float      slope,
+             int        n_order ) ;
+
+
+/**
+   @name  sinfo_new_parameter_to_ascii()
+   @memo stores parameters in an ASCII file
+   @param parameter float parameter array to be stored in an ASCII file
+   @param number number of parameters
+   @param filename filename of ASCII file
+   @return void
+*/
+
+
+void 
+sinfo_new_parameter_to_ascii ( float * parameter,
+                        int n,
+                        char * filename ) ;
+
+
+/**
+   @name  sinfo_new_ascii_to_parameter()
+   @param filename filename of ASCII file
+   @param n number of parameters in the parameter array array of parameters
+   @doc writes parameters stored in an ASCII file in an float array
+*/
+
+float * 
+sinfo_new_ascii_to_parameter ( char * filename,
+                           int  * n ) ;
+
+/**
+   @name  sinfo_new_curvature_of_spectrum()
+   @param ns_image   image with at least one continuum spectrum of a pinhole
+   @param order      order of the fit polynomial
+   @param box_length width of the box in which the lines are fit by a Gaussian
+   @param left_pos
+   @param right_pos left and right positions between which the spectrum should 
+                    be located
+   @param fwhm      first guess of the full width at half maximum
+   @param min_amplitude_factor factor peak/background below given
+                       threshold the fit is not carried through
+   @return resulting polynomial coefficients.
+   @doc    this routine determines the curvature of a spectrum by fitting
+           a polynomial to a continuum spectrum. This is done by using
+       an image with at least one continuum spectrum of a pinhole.
+       this is done by searching the spectrum within the image
+       then fitting the spectrum along the rows within a given box
+       by a sinfo_gaussian, so that the exact position is determined for
+       each row. Afterwards, a polynomial is fitted through the
+       found positions. The polynomial coefficients are returned.
+*/
+
+double * 
+sinfo_new_curvature_of_spectrum(cpl_image * ns_image,
+                int        order, 
+             int        box_length,
+             int        left_pos,
+                         int        right_pos,
+                         float      fwhm,
+                         float      min_amplitude_factor ) ;
+
+/**
+ at name sinfo_new_image_warp_fits
+ at memo correct optical distortions
+ at param image distorted image
+ at param kernel_type type of kernel to correct distortions
+ at param poly_table table containing distortion coefficients
+ at return image distortion corrected
+*/
+cpl_image * 
+sinfo_new_image_warp_fits(cpl_image * image,
+                      char      * kernel_type, 
+                      char      * poly_table );
+
+#endif /*!SINFO_COLTILT_H*/
+
diff --git a/sinfoni/sinfo_companion.c b/sinfoni/sinfo_companion.c
new file mode 100644
index 0000000..680a1d1
--- /dev/null
+++ b/sinfoni/sinfo_companion.c
@@ -0,0 +1,54 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+#include "sinfo_solve_poly_root.h"
+
+/**@{*/
+/**
+ * @defgroup sinfo_companion To be removed
+ *
+ * TBD
+ */
+
+/**
+ at name sinfo_set_companion_matrix 
+ at brief TBD
+ at param a matrix
+ at param nc size
+ at param  m matrix
+ at return TBD
+*/
+void
+sinfo_set_companion_matrix (const double *a, size_t nc, double *m)
+{
+  size_t i, j;
+
+  for (i = 0; i < nc; i++)
+    for (j = 0; j < nc; j++)
+      MAT (m, i, j, nc) = 0.0;
+
+  for (i = 1; i < nc; i++)
+    MAT (m, i, i - 1, nc) = 1.0;
+
+  for (i = 0; i < nc; i++)
+    MAT (m, i, nc - 1, nc) = -a[i] / a[nc];
+}
+/**@}*/
diff --git a/sinfoni/sinfo_cpl_size.h b/sinfoni/sinfo_cpl_size.h
new file mode 100644
index 0000000..31b6fc9
--- /dev/null
+++ b/sinfoni/sinfo_cpl_size.h
@@ -0,0 +1,17 @@
+/*
+ * sinfo_cpl_size.h
+ *
+ *  Created on: Nov 23, 2011
+ *      Author: amodigli
+ */
+
+#ifndef SINFO_CPL_SIZE_H_
+#define SINFO_CPL_SIZE_H_
+
+#include <cpl.h>
+#if defined CPL_VERSION_CODE && CPL_VERSION_CODE <= CPL_VERSION(5, 5, 0)
+typedef int cpl_size; /* The type as is was up to CPL 5.3 */
+#define CPL_SIZE_FORMAT "d"
+#endif
+
+#endif /* SINFO_CPL_SIZE_H_ */
diff --git a/sinfoni/sinfo_cube_construct.c b/sinfoni/sinfo_cube_construct.c
new file mode 100644
index 0000000..6ec70bb
--- /dev/null
+++ b/sinfoni/sinfo_cube_construct.c
@@ -0,0 +1,3572 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/************************************************************************
+* E.S.O. - VLT project
+*
+*
+*
+* who       when      what
+* --------  --------  ----------------------------------------------
+* schreib  30/08/00  created
+*/
+
+/************************************************************************
+*   NAME
+*        sinfo_cube_construct.c -
+*        some procedures to construct a data cube
+*
+*   SYNOPSIS
+*
+*   1) cpl_image * sinfo_new_convolve_ns_image_by_gauss( cpl_image * lineImage,
+*                                         int        hw )
+*
+*   2) float * sinfo_north_south_test( cpl_image * ns_image,
+*                                int        n_slitlets,
+*                                int        halfWidth,
+*                                float      fwhm,
+*                                float      minDiff,
+*                                float      estimated_dist,
+*                                float      devtol )
+*
+*   3) cpl_imagelist * sinfo_new_make_cube ( cpl_image * calibImage,
+*                           float    * distances,
+*                           float    * correct_diff_dist )
+*
+*   4) cpl_imagelist * sinfo_new_make_cube_spi ( cpl_image *  calibImage,
+*                              float    ** slit_edges,
+*                              float    *  shift )
+*
+*   5) cpl_imagelist * sinfo_new_make_cube_dist ( cpl_image * calibImage,
+*                               float      firstCol,
+*                               float    * distances,
+*                               float    * shift )
+*
+*   6) cpl_imagelist * sinfo_new_make_3D_cube_dist ( cpl_image * calibImage,
+*                                 float      firstCol,
+*                                 float    * distances,
+*                                 float    * shift )
+*
+*   7) cpl_imagelist * sinfo_new_make_3D_cube ( cpl_image * calibImage,
+*                             int      * kpixshift,  
+*                             int        kpixfirst )
+*
+*   8) cpl_imagelist * 
+       sinfo_new_determine_mask_cube(cpl_imagelist * sourceMaskCube,
+*                                    float     lowLimit,
+*                                    float     highLimit )
+*
+*   9) cpl_imagelist * sinfo_new_interpol_cube ( cpl_imagelist * sourceCube,
+*                               cpl_imagelist * maskCube,
+*                               int       n_neighbors, 
+*                               int       max_radius )
+*
+*   10) cpl_imagelist * sinfo_new_fine_tune_cube( cpl_imagelist * cube,
+*                              float   * correct_diff_dist )
+*
+*   11) cpl_imagelist * sinfo_new_fine_tune_cube_by_FFT( cpl_imagelist * cube,
+*                                   float   * correct_diff_dist )
+*
+*   12) cpl_imagelist * sinfo_new_fine_tune_cube_by_spline(cpl_imagelist * cube,
+*                                        float   * correct_diff_dist )
+*
+*   DESCRIPTION
+*
+*   1) convolves a north-south-test image with a sinfo_gaussian
+*      with user given integer half width by using the eclipse
+*      routine sinfo_function1d_filter_lowpass().
+*   2) determines the distances of the slitlets
+*   3) makes a data cube out of a resampled source image
+*      this SPIFFI specific routine takes into account the
+*      Spiffi slitlet order on the detector.
+*      Also shifts the resulting image rows by one pixel if
+*      necessary according to the distances array gained from
+*      the north-south test routine.
+*      Can do the same with the bad pixel map image to generate a
+*      bad pixel mask cube.
+*   4) makes a data cube out of a resampled source image
+*      this SPIFFI specific routine takes into account the
+*      Spiffi slitlet order on the detector.
+*      This routine takes fitted slitlet positions into account.
+*      Can do the same with the bad pixel map image to generate a
+*      bad pixel mask cube.
+*   5) makes a data cube out of a resampled source image
+*      this SPIFFI specific routine takes into account the
+*      Spiffi slitlet order on the detector.
+*      Also shifts the resulting image rows by one pixel if
+*      necessary according to the distances array gained from
+*      the north-south test routine.
+*      Can do the same with the bad pixel map image to generate a
+*      bad pixel mask cube.
+*   6) makes a data cube out of a resampled source image
+*      this 3D specific routine takes into account the
+*      3D slitlet order on the detector.
+*      Also shifts the resulting image rows by one pixel if
+*      necessary according to the distances array gained from
+*      the north-south test routine.
+*      Can do the same with the bad pixel map image to generate a
+*      bad pixel mask cube.
+*   7) makes a data cube out of a resampled source image
+*      this MPE 3D specific routine takes into account the
+*      3D slitlet order on the detector.
+*      Also shifts the resulting image row by an integer pixel shift if
+*      necessary according to the input kpixshift array 
+*      Can do the same with the bad pixel map image to generate a
+*      bad pixel mask cube.
+*   8) converts resampled bad pixels to real bad pixels in data cubes.
+*   9) Bad pixel interpolation 3D like (saturated pixels exist):
+*      interpolates the bad pixels of the source cube by
+*      using the nearest neighbors. 
+*      first it is checked if the bad pixel is interpolatable:
+*      it is only interpolatable if the number of good pixels 
+*      in its spectrum of length 2*n_neighbors+1 exceeds 3 and
+*      if there is at least one good pixel on either side of the
+*      central pixel.
+*      Afterwards good neighboring pixels are searched within the 
+*      image plane of the bad pixel by using an increasing pixel radius. 
+*      Good pixels mean, the corresponding spectral pixels of the 
+*      bad pixel and its spatial neighboring pixel must have
+*      at least 2 valid pixel pairs to be able to be used for
+*      the interpolation. The search is stopped if 9 valid neighboring
+*      pixels are found. 
+*      Now normalize the found spectral values, collect the valid pixels 
+*      (there must be at least 18) and take the sinfo_median of the valid 
+*      pixels with which the bad pixel is replaced.
+*   10) fine tunes each row in the right position according 
+*      to the distances of the slitlets to each other
+*      (output of the north-south test).
+*      This means that the rows must be realigned by a 
+*      fraction of a pixel to accomodate non-integer slit 
+*      length. The fractional realignment is done by using
+*      the polynomial interpolation algorithm of N.R. 
+*      Each row is rescaled so that the total flux is
+*      conserved.
+*  11) fine tunes each row in the right position according 
+*      to the distances of the slitlets to each other
+*      (output of the north-south test).
+*      This means that the rows must be realigned by a 
+*      fraction of a pixel to accomodate non-integer slit 
+*      length. The fractional realignment is done by using
+*      the FFT algorithm four1() of N.R. 
+*  12) fine tunes each row in the right position according 
+*      to the distances of the slitlets to each other
+*      (output of the north-south test).
+*      This means that the rows must be realigned by a 
+*      fraction of a pixel to accomodate non-integer slit 
+*      length. The fractional realignment is done by using
+*      the spline interpolation algorithm splint in connection
+*      with the algorithm spline of N.R. 
+*      This algorithms assume that each row is a tabulated
+*      function. The first derivatives of the interpolating
+*      function at the first and last point must be given.
+*      These are set higher than 1xe^30, so the routine
+*      sets the corresponding boundary condition for a natural
+*      spline, with zero second derivative on that boundary.
+*      Each row is rescaled so that the total flux is
+*      conserved.
+*
+*   FILES
+*
+*   ENVIRONMENT
+*
+*   RETURN VALUES
+*
+*   CAUTIONS
+*
+*   EXAMPLES
+*
+*   SEE ALSO
+*
+*   BUGS
+*
+*------------------------------------------------------------------------
+*/
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+#define POSIX_SOURCE 1
+#include "sinfo_vltPort.h"
+
+/*
+ * System Headers
+ */
+
+/*
+ * Local Headers
+ */
+#include "sinfo_function_1d.h"
+#include "sinfo_cube_construct.h"
+#include "sinfo_spectrum_ops.h"
+#include "sinfo_wave_calibration.h"
+#include "sinfo_utilities.h"
+#include "sinfo_local_types.h"
+#include "sinfo_fft_base.h"
+
+static int
+sinfo_sort_slitlets(const int kslit);
+
+
+static int
+sinfo_sort_slitlets_array(const int slit, int* row_index);
+
+/**@{*/
+/**
+ * @defgroup sinfo_cube_construct Cube generation functions
+ *
+ * TBD
+ */
+
+/*----------------------------------------------------------------------------
+ *                            Function codes
+ *--------------------------------------------------------------------------*/
+/**
+   @name   sinfo_new_convolve_ns_image_by_gauss()
+   @memo convolves a north-south-test image with a Gaussian
+                        with user given integer half width by using the
+                        routine sinfo_function1d_filter_lowpass().
+   @param lineImage  North-south-test image
+   @param hw          kernel half width of the Gaussian response function
+   @result  north-south-test image convolved with a Gaussian
+ */
+
+cpl_image * 
+sinfo_new_convolve_ns_image_by_gauss( cpl_image * lineImage,
+                                   int        hw )
+{
+    cpl_image * returnImage ;
+    float* row_buffer=NULL ;
+    float * filter ;
+    int col, row ;
+    int ilx=0;
+    int ily=0;
+ 
+    float* pidata=NULL;
+    float* podata=NULL;
+
+    if ( lineImage == NULL )
+    {
+        sinfo_msg_error("no input image given!\n") ;
+        return NULL ;
+    }
+    ilx=cpl_image_get_size_x(lineImage);
+    ily=cpl_image_get_size_y(lineImage);
+    pidata=cpl_image_get_data_float(lineImage);
+    if ( hw < 1 )
+    {
+        sinfo_msg_error(" wrong half width given!\n") ;
+        return NULL ;
+    }
+
+    /* allocate memory for returned image */
+    if ( NULL == ( returnImage = cpl_image_new(ilx,ily,CPL_TYPE_FLOAT ) ))
+    {
+        sinfo_msg_error("cannot allocate a new image\n");
+        return NULL ;
+    }
+    podata=cpl_image_get_data_float(returnImage);
+
+    /* go through the image rows and save them in a buffer */
+    row_buffer=cpl_calloc(ily,sizeof(float)) ;
+
+    for ( row = 0 ; row < ily ; row++ )
+    {
+        for ( col = 0 ; col < ilx ; col++ )
+        {
+            if ( isnan(pidata[col+row*ilx]) )
+            {
+                row_buffer[col] = 0. ;
+            }
+            else
+            {
+                row_buffer[col] = pidata[col + row*ilx] ;
+            }
+        }
+
+        /*--------------------------------------------------------------------
+         * now low pass filter the rows by the gaussian and fill the return
+         * image.
+         */
+        filter = sinfo_function1d_filter_lowpass( row_buffer,
+                                            ilx,
+                                            LOW_PASS_GAUSSIAN,
+                                            hw ) ;
+        for ( col = 0 ; col < ily ; col++ )
+        {
+            podata[col + row*ilx] = filter[col] ;
+        }
+        /* deallocate memory */
+        sinfo_function1d_del (filter) ;
+    }
+    cpl_free(row_buffer);    
+    return returnImage ;
+}
+
+/**
+   @name  sinfo_north_south_test()
+   @memo determines the distances of the slitlets
+   @param ns_image   north-south image
+   @param n_slitlets number of slitlets
+   @param halfWidth  half width of the box in which the lines
+                                    are fit by a sinfo_gaussian
+   @param fwhm       first guess of the full width at half maximum
+   @param minDiff    amplitude threshold for Gaussian: 
+                    below this intensity the fit will not 
+                    be carried through
+   @param estimated_dist estimated average distance of spectra
+   @param devtol     maximal pixel deviation of slitlet distances
+   @result            array of the distances of the slitlets from each other
+*/
+
+float * 
+sinfo_north_south_test( cpl_image * ns_image,
+                          int        n_slitlets,
+                          int        halfWidth,
+                          float      fwhm,
+                          float      minDiff,
+                          float      estimated_dist,
+                          float      devtol,
+              int         bottom,
+              int         top )
+{
+    int i, j, k, m, row, col, n, ni, na ;
+    int position, counter, iters ;
+    int xdim, ndat, its, numpar ;
+    pixelvalue row_buf[cpl_image_get_size_x(ns_image)] ;
+    float sum, mean, maxval ;
+    float tol, lab ;
+    float * distances ;
+    float distances_buf[cpl_image_get_size_y(ns_image)][n_slitlets-1] ;
+    float x_position[n_slitlets] ;
+    float * xdat, * wdat ;
+    int * mpar ;
+    int found[3*n_slitlets], found_clean[3*n_slitlets] ;
+    int found_cleanit[3*n_slitlets] ;
+    Vector * line ;
+    FitParams ** par ;
+    int foundit, begin, end ;
+    int zeroindicator ;
+    int ilx=0;
+    int ily=0;
+ 
+    float* pidata=NULL;
+ 
+    if ( ns_image == NULL )
+    {
+        sinfo_msg_error("sorry, no image given\n") ;
+        return NULL ;
+    }
+    ilx=cpl_image_get_size_x(ns_image);
+    ily=cpl_image_get_size_y(ns_image);
+    pidata=cpl_image_get_data_float(ns_image);
+
+
+    if ( n_slitlets < 1 )
+    {
+        sinfo_msg_error("wrong number of slitlets given\n") ;
+        return NULL ;
+    }
+    if ( halfWidth < 0 || halfWidth >= estimated_dist )
+    {
+        sinfo_msg_error("wrong half width given\n") ;
+        return NULL ;
+    }
+    if ( fwhm <= 0. )
+    {
+        sinfo_msg_error("wrong fwhm given\n") ;
+        return NULL ;
+    }
+    if ( minDiff < 1. )
+    {
+        sinfo_msg_error("wrong minDiff given\n") ;
+        return NULL ;
+    }
+
+    /* allocate memory for output array */
+    if (NULL == (distances = (float *) cpl_calloc ( n_slitlets - 1 , 
+                                                    sizeof (float) ))) 
+    {
+        sinfo_msg_error("could not allocate memory\n") ;
+        return NULL ;
+    }
+
+    /* go through the image rows */
+    for ( row = bottom ; row < top ; row++ )
+    {
+        zeroindicator = 0 ;
+
+        /* initialize the distance buffer */
+        for ( i = 0 ; i < n_slitlets-1 ; i++ )
+        {
+            distances_buf[row][i] = ZERO ;
+        }
+
+        /* fill the row buffer array with image data */
+        for ( col = 0 ; col < ilx ; col++ )
+        {
+            row_buf[col] = pidata[col + row*ilx] ;
+        }
+
+        /* determine the mean of the row data */
+        sum = 0. ;
+        n = 0 ;
+        for ( i = 0 ; i < ilx ; i++ )
+        {
+            if ( isnan(row_buf[i]) )
+            {
+                continue ;
+            }
+            sum += row_buf[i] ;
+            n++ ;
+        }
+        mean = sum / (float)n ;
+
+
+        /* store the positions of image values greater than the mean */
+        n = 0 ;
+        for ( i = 0 ; i < ilx ; i++ )
+        {
+            if (isnan(row_buf[i]))
+            {
+                continue ;
+            }
+            if ( row_buf[i] >  sqrt(mean*mean*9) )
+            {
+                found[n] = i ;
+                n++ ;
+            } 
+        }
+       
+        if ( n < n_slitlets )
+        {
+            sinfo_msg_warning("t1 wrong number of intensity columns found "
+                              "in row: %d, found number: %d, mean: %g",
+                              row, n, mean) ;
+            continue ;
+        }
+        else
+        { 
+            /* find the maximum value position around the found columns */
+            na = 0 ;
+            for ( i = 1 ; i < n ; i ++ )
+            {
+                if ( found[i] - found[i-1] < halfWidth )
+                {
+                    begin = found[i] - halfWidth ;
+                    if ( begin < 0 )
+                    {
+                        begin = 0 ;
+                    }
+                    end = found[i] + halfWidth ;
+                    if ( end >= ilx )
+                    {
+                        end = ilx - 1 ;
+                    }
+                    /* find the maximum value inside the box 
+                       around the found positions*/
+                    maxval = -FLT_MAX ;
+                    foundit = 0 ;
+                    for ( j = begin ; j <= end ; j++ )
+                    {
+                        /* do not consider boxes that contain bad pixels */
+                        if (isnan(row_buf[j]))
+                        {
+                            continue ;
+                        }
+                        if (row_buf[j] >= maxval )
+                        {
+                            maxval = row_buf[j] ;
+                            foundit = j ;
+                        }
+                    }
+                    if (maxval == -FLT_MAX)
+                    {
+                        continue ;
+                    }
+                    for ( k = 0 ; k < na ; k++ )
+                    {
+                        if ( found_cleanit[k] >= begin && 
+                             found_cleanit[k] < foundit )
+                        {
+                            na-- ;
+                        }
+                    }
+                    for ( k = 0 ; k < n ; k++ )
+                    {
+                        if ( found[k] == foundit)
+                        {
+                 if (na>0){
+                            if ( found_cleanit[na-1] != found[k] )
+                            {
+                                found_cleanit[na] = found[k] ;
+                                na++ ;
+                            }
+             }
+             else{
+                found_cleanit[na] = found[k] ;  
+                            na++ ;
+             } 
+                      }
+                    }
+                }
+                else
+                {
+                    if ( i == 1 )
+                    {
+                        found_cleanit[na] = found[0] ;
+                        na++ ;
+                        found_cleanit[na] = found[1] ;
+                        na++ ;
+                    }
+                    else
+                    {   
+                if (na>0){
+                            if ( found_cleanit[na-1] != found[i-1])
+                            {
+                                found_cleanit[na] = found[i-1] ;
+                                na++ ;
+                            }
+                            if ( found_cleanit[na-1] != found[i])
+                            {
+                                found_cleanit[na] = found[i] ;
+                                na++ ;
+                            }
+                        }
+            else
+                        {
+                            found_cleanit[na] = found[i] ;
+                            na++ ;
+                        }
+            }  
+                }
+            }
+            /* determine only one pixel position for each slitlet intensity */
+            j = 1 ;
+            for ( i = 1 ; i < na ; i++ )
+            {
+                if ( (float)(found_cleanit[i] - found_cleanit[i-1]) < 
+                            (estimated_dist - devtol) ||
+                     (float)(found_cleanit[i] - found_cleanit[i-1]) > 
+                            (estimated_dist + devtol) )
+                {
+                    continue ;
+                }
+                else
+                {
+                    found_clean[j-1] = found_cleanit[i-1] ;
+                    found_clean[j]   = found_cleanit[i] ;
+                    j++ ;
+                }
+            }
+        }
+        if ( j > n_slitlets )
+        {
+            /* check the distance again */
+            ni = 1 ;
+            for ( i = 1 ; i < j ; i++ )
+            {
+                if ( (float)(found_clean[i] - found_clean[i-1]) < 
+                            (estimated_dist - devtol ) ||
+                     (float)(found_clean[i] - found_clean[i-1]) > 
+                            (estimated_dist + devtol ) )
+                { 
+                    continue ;
+                }
+                else
+                {
+
+                    found_clean[ni-1] = found_clean[i-1] ;
+                    found_clean[ni]   = found_clean[i] ;
+                    ni++ ;
+                }
+            }
+            if ( ni != n_slitlets )
+            {
+                sinfo_msg_warning("t2 wrong number of intensity columns"
+                                  " found in row: %d,  found number: %d",
+                                  row, ni) ;
+                continue ;
+            }
+            else 
+            {
+                j = ni ;
+            }
+        }
+        else if ( j < n_slitlets )
+        {
+            cpl_msg_debug ("north_south_test3:",
+                            "t3 wrong number of intensity columns "
+                            "found in row: %d , found number: %d, mean: %g\n", 
+                            row, j, mean) ;
+            continue ;
+        }
+        counter = 0 ;
+        /* go through the found intensity pixels in one row */
+        for ( i = 0 ; i < j ; i++ )
+        {
+            /* allocate memory for the array where the line is fitted in */
+            if ( NULL == (line = sinfo_new_vector (2*halfWidth + 1)) )
+            {
+                sinfo_msg_error ("cannot allocate new Vector \n") ;
+                cpl_free(distances) ;
+                return NULL ;
+            }
+
+            /* allocate memory */
+            xdat = (float *) cpl_calloc( line -> n_elements, sizeof (float) ) ;
+            wdat = (float *) cpl_calloc( line -> n_elements, sizeof (float) ) ;
+            mpar = (int *)   cpl_calloc( MAXPAR, sizeof (int) ) ;
+            par = sinfo_new_fit_params(1) ;
+
+            m = 0 ;
+            for ( k = found_clean[i]-halfWidth ; 
+                  k <= found_clean[i]+halfWidth ; k++ )
+            {
+                if ( k < 0 )
+                {
+                    k = 0. ;
+                }
+                else if ( k >= ilx )
+                {
+                    k = ilx - 1 ;
+                }
+                else if ( isnan(row_buf[k]) )
+                {
+                    zeroindicator = 1 ;
+                    break ;
+                }
+                else
+                {
+                    line -> data[m] = row_buf[k] ;
+                    m++ ;
+                }
+            }
+            if ( zeroindicator == 1 )
+            {
+                sinfo_new_destroy_vector(line) ;
+                cpl_free(xdat) ;
+                cpl_free(wdat) ;
+                cpl_free(mpar) ;
+                sinfo_new_destroy_fit_params(&par) ;
+                break ;
+            }
+
+            /*----------------------------------------------------------------
+             * go through the spectral sinfo_vector
+             * determine the maximum pixel value in the spectral sinfo_vector
+             */
+            maxval = -FLT_MAX ;
+            position = -INT32_MAX ;
+            for ( k = 0 ; k < m ; k++ )
+            {
+                xdat[k] = k ;
+                wdat[k] = 1.0 ;
+                if ( line -> data[k] >= maxval )
+                {
+                    maxval = line -> data[k] ;
+                    position = k ;
+                }
+            }
+
+            /* set initial values for the fitting routine */
+            xdim     = XDIM ;
+            ndat     = line -> n_elements ;
+            numpar   = MAXPAR ;
+            tol      = TOL ;
+            lab      = LAB ;
+            its      = ITS ;
+            (*par) -> fit_par[1] = fwhm ;
+            (*par) -> fit_par[2] = (float) position ;
+            (*par) -> fit_par[3] = (float) (line -> data[0] + 
+                                   line -> data[line->n_elements - 1]) / 2.0 ;
+            (*par) -> fit_par[0]  = maxval - ((*par) -> fit_par[3]) ;
+
+
+            /* exclude negative peaks and low signal cases */
+            if ( (*par) -> fit_par[0] < minDiff )
+            {
+                sinfo_msg_warning ("sorry, signal of line too low to fit "
+                                   "in row: %d in slitlet %d\n", row, i) ;
+                sinfo_new_destroy_vector(line) ;
+                cpl_free(xdat) ;
+                cpl_free(wdat) ;
+                cpl_free(mpar) ;
+                sinfo_new_destroy_fit_params(&par) ;
+                continue ;
+            }
+
+            for ( k = 0 ; k < MAXPAR ; k++ )
+            {
+                (*par) -> derv_par[k] = 0.0 ;
+                mpar[k] = 1 ;
+            }
+            /* finally, do the least square fit using a Gaussian */
+            if ( 0 > ( iters = sinfo_new_lsqfit_c( xdat, &xdim, 
+                                                   line -> data, wdat, &ndat, 
+                                                   (*par) -> fit_par,
+                                                   (*par) -> derv_par, mpar, 
+                                                   &numpar, &tol, &its, &lab)) )
+            {
+          /*
+                cpl_msg_debug ("north_south_test:",
+                               "sinfo_lsqfit_c: least squares fit failed,"
+                               " error no.: %d in row: %d in slitlet %d\n",
+                                iters, row, i) ;
+          */
+                sinfo_new_destroy_vector(line) ;
+                cpl_free(xdat) ;
+                cpl_free(wdat) ;
+                cpl_free(mpar) ;
+                sinfo_new_destroy_fit_params(&par) ;
+                continue ;
+            }
+
+            /* check for negative fit results */
+            if ( (*par) -> fit_par[0] <= 0. || 
+                 (*par) -> fit_par[1] <= 0. ||
+                 (*par) -> fit_par[2] < 0. )
+            {
+                sinfo_msg_warning ("negative parameters as fit result, "
+                                   "not used! in row %d in slitlet %d", 
+                                   row, i) ;
+                sinfo_new_destroy_vector(line) ;
+                cpl_free(xdat) ;
+                cpl_free(wdat) ;
+                cpl_free(mpar) ;
+                sinfo_new_destroy_fit_params(&par) ;
+                continue ;
+            }
+
+            /* correct the fitted position for the given row of the line 
+               in image coordinates */
+            (*par) -> fit_par[2] =  (float) (found_clean[i] - halfWidth) + 
+                                            (*par) -> fit_par[2] ;
+            x_position[counter] = (*par) -> fit_par[2] ;
+            counter ++ ;
+
+            /* free memory */
+            sinfo_new_destroy_fit_params(&par) ;
+            sinfo_new_destroy_vector ( line ) ;
+            cpl_free ( xdat ) ;
+            cpl_free ( wdat ) ;
+            cpl_free ( mpar ) ;
+        }
+        if (zeroindicator == 1)
+        {
+            sinfo_msg_debug ("bad pixel in fitting box in row: %d\n", row) ;
+            continue ;
+        }
+
+        if ( counter != n_slitlets )
+        {
+            continue ;
+            sinfo_msg_warning("wrong number of slitlets found in row: %d",row);
+        }
+        /* store the distances between the sources in a buffer */
+        for ( i = 1 ; i < n_slitlets ; i++ )
+        {
+            distances_buf[row][i-1] = x_position[i] - x_position[i-1] ;
+        }
+    }
+
+    /* ----------------------------------------------------------------
+     * go through the rows again and take the mean of the distances, 
+     * throw away the runaways 
+     */
+    for ( i = 0 ; i < n_slitlets-1 ; i++ )
+    {
+        n   = 0 ;
+        sum = 0. ;
+        for ( row = bottom ; row < top ; row++ )
+        {
+            if ( fabs( distances_buf[row][i] - estimated_dist ) > devtol || 
+                 isnan(distances_buf[row][i]) )
+            {
+            /*
+          sinfo_msg("dist=%g devtol=%g isan=%d", 
+            distances_buf[row][i],
+            devtol,
+            isnan(distances_buf[row][i]));
+            */
+                continue ;
+            }
+            sum += distances_buf[row][i] ;
+            n++ ;
+        }
+        if ( n < 2 )
+        {
+            sinfo_msg_error("distances array could not be determined "
+                            "completely!, deviations of distances from number "
+                            "of slitlets too big\n" ) ;
+            cpl_free(distances) ;
+            return NULL ;
+        }
+        else
+        {
+            distances[i] = sum / (float)n ;
+        }
+    }
+    return distances ; 
+}
+
+/**
+   @name     sinfo_new_make_cube()
+   @memo     makes a data cube out of a resampled source image
+   @param    calibImage:  resampled source image
+   @param    distances:   distances of the slitlets from each other
+                          output of function ns_test
+   @param     correct_diff_dist: dummy array with 32 elements
+   @return    resulting source data cube
+   @note      correct_diff_dist: differences of the slitlets from
+                                           distance 32 given in the correct
+                                           Spiffi sequence. The first slitlet
+                                           is the reference, therefore element
+                                           23 is set 0.
+   @doc      makes a data cube out of a resampled source image
+             this SPIFFI specific routine takes into account the
+             Spiffi slitlet order on the detector.
+             Also shifts the resulting image rows by one pixel if
+             necessary according to the distances array gained from
+             the north-south test routine.
+             Can do the same with the bad pixel map image to generate a
+             bad pixel mask cube.
+ */
+
+cpl_imagelist * 
+sinfo_new_make_cube ( cpl_image * calibImage,
+                     float    * distances,
+                     float    * correct_diff_dist )
+{
+    cpl_imagelist * returnCube ;
+    int imsize, kslit, kpix ;
+    int slit_index ;
+    int z, col, recol ;
+    int ilx=0;
+    int ily=0;
+
+    float* podata=NULL;
+    float* pidata=NULL;
+    cpl_image* o_img;
+
+    if ( NULL == calibImage )
+    {
+        sinfo_msg_error("no resampled image given!\n") ;
+        return NULL ;
+    }
+    ilx=cpl_image_get_size_x(calibImage);
+    ily=cpl_image_get_size_y(calibImage);
+    pidata=cpl_image_get_data_float(calibImage);
+
+    if ( NULL == distances )
+    {
+        sinfo_msg_error("no distances array from ns_test given!/n") ;
+        return NULL ;
+    }
+
+    if ( NULL == correct_diff_dist )
+    {
+        sinfo_msg_error("correct_diff_dist array is not allocated!/n") ;
+        return NULL ;
+    }
+       
+    if ( N_SLITLETS != 32 )
+    {
+        sinfo_msg_error ("wrong number of slitlets given \n" ) ;
+        return NULL ;
+    }
+    imsize = ilx / N_SLITLETS ;
+
+    /* allocate memory */  
+    if ( NULL == (returnCube = cpl_imagelist_new()) )
+    {
+        sinfo_msg_error ("cannot allocate new cube \n" ) ;
+        return NULL ;
+    }
+
+    /* now build the data cube out of the resampled image */
+    for ( z = 0 ; z < ily ; z++ ) /* go through the z-axis */
+    {
+
+      o_img=cpl_image_new(imsize,N_SLITLETS,CPL_TYPE_FLOAT);
+      podata=cpl_image_get_data_float(o_img);
+        kpix       = 0 ;
+        kslit      = 0 ;
+        slit_index = -1 ;
+        recol      = -1 ;
+        for ( col = 0 ; col < ilx ; col++ ) /* go through the image columns */
+        {
+            if ( col % imsize == 0 )
+            {
+                recol = 0 ;
+                kslit = col/imsize ;
+                /* sort the slitlets in the right spiffi specific way */
+                if((slit_index=sinfo_sort_slitlets(kslit)) == -1) {
+                  sinfo_msg_error("wrong slitlet index: couldn't be a "
+                               "spiffi image,  there must be 32 slitlets!") ;
+                        cpl_imagelist_delete(returnCube) ;
+                        return NULL ;
+                }
+
+                if ( kslit != 0 )
+                {
+                    /*-------------------------------------------------------- 
+                     * shift the first pixel by an integer if the absolute 
+                     * amount of distances[]
+                     * is bigger than 0.5 
+                     */
+                    kpix = sinfo_new_nint(distances[kslit-1]) ;
+
+                    /*----------------------------------------------- 
+                     * now sort the distances array according to the row order 
+                     * and add a 0 value for the first (reference) slitlet 
+                     * that means row 8 
+                     */
+                    correct_diff_dist[slit_index] = distances[kslit-1] - 
+                                                    (float)kpix ;
+                }
+                /* refer all distances to the first slitlet */
+                else
+                {
+                    correct_diff_dist[slit_index] = 0. ;
+                }
+            }
+
+            /* fill each cube plane with one image row */
+            podata[recol+slit_index*imsize] = pidata[col+kpix+z*ilx];
+            recol++ ;
+
+            if ( recol > imsize )
+            {
+                sinfo_msg_error("wrong column of reconstructed "
+                                "image, shouldn't happen!\n") ; 
+                cpl_imagelist_delete(returnCube) ;
+                return NULL ;
+            }
+        }
+    }
+    return returnCube ;
+}
+
+
+
+/**
+   @name sinfo_sort_slitlets()
+   @brief sort the slitlets in the right spiffi specific way
+   @param kslit slit number
+   @return spiffi slit index or -1
+*/
+
+static int
+sinfo_sort_slitlets(const int kslit)
+{
+  int slit_index=0;
+
+  switch (kslit)
+    {
+    case 0:
+      slit_index = 8 ;
+      break ;
+    case 1:
+      slit_index = 7 ;
+      break ;
+    case 2:
+      slit_index = 9 ;
+      break ;
+    case 3:
+      slit_index = 6 ;
+      break ;
+    case 4:
+      slit_index = 10 ;
+      break ;
+    case 5:
+      slit_index = 5 ;
+      break ;
+    case 6:
+      slit_index = 11 ;
+      break ;
+    case 7:
+      slit_index = 4 ;
+      break ;
+    case 8:
+      slit_index = 12 ;
+      break ;
+    case 9:
+      slit_index = 3 ;
+      break ;
+    case 10:
+      slit_index = 13 ;
+      break ;
+    case 11:
+      slit_index = 2 ;
+      break ;
+    case 12:
+      slit_index = 14 ;
+      break ;
+    case 13:
+      slit_index = 1 ;
+      break ;
+    case 14:
+      slit_index = 15 ;
+      break ;
+    case 15:
+      slit_index = 0 ;
+      break ;
+    case 16:
+      slit_index = 31 ;
+      break ;
+    case 17:
+      slit_index = 16 ;
+      break ;
+    case 18:
+      slit_index = 30 ;
+      break ;
+    case 19:
+      slit_index = 17 ;
+      break ;
+    case 20:
+      slit_index = 29 ;
+      break ;
+    case 21:
+      slit_index = 18 ;
+      break ;
+    case 22:
+      slit_index = 28 ;
+      break ;
+    case 23:
+      slit_index = 19 ;
+      break ;
+    case 24:
+      slit_index = 27 ;
+      break ;
+    case 25:
+      slit_index = 20 ;
+      break ;
+    case 26:
+      slit_index = 26 ;
+      break ;
+    case 27:
+      slit_index = 21 ;
+      break ;
+    case 28:
+      slit_index = 25 ;
+      break ;
+    case 29:
+      slit_index = 22 ;
+      break ;
+    case 30:
+      slit_index = 24 ;
+      break ;
+    case 31:
+      slit_index = 23 ;
+      break ;
+    default:
+      sinfo_msg_error("wrong slitlet index: couldn't be a "
+                      "spiffi image,  there must be 32 slitlets!") ;
+      return -1 ;
+      break ;
+                
+   }
+   return slit_index;
+
+}
+
+/**
+   @name sinfo_new_make_cube_spi()
+   @short sort spiffi slitlets
+   @param  slit slit id
+   @param  row_index array with sorted indeces
+   @doc sort the slitlets in the right spiffi specific way
+        the row_index describes the row index of the current slitlet 
+        in the resulting cube images.
+*/
+
+static int
+sinfo_sort_slitlets_array(const int slit, int* row_index)
+{
+
+  switch (slit)
+    {
+    case 0:
+      row_index[0] = 8 ;
+      break ;
+    case 1:
+      row_index[1] = 7 ;
+      break ;
+    case 2:
+      row_index[2] = 9 ;
+      break ;
+    case 3:
+      row_index[3] = 6 ;
+      break ;
+    case 4:
+      row_index[4] = 10 ;
+      break ;
+    case 5:
+      row_index[5] = 5 ;
+      break ;
+    case 6:
+      row_index[6] = 11 ;
+      break ;
+    case 7:
+      row_index[7] = 4 ;
+      break ;
+    case 8:
+      row_index[8] = 12 ;
+      break ;
+    case 9:
+      row_index[9] = 3 ;
+      break ;
+    case 10:
+      row_index[10] = 13 ;
+      break ;
+    case 11:
+      row_index[11] = 2 ;
+      break ;
+    case 12:
+      row_index[12] = 14 ;
+      break ;
+    case 13:
+      row_index[13] = 1 ;
+      break ;
+    case 14:
+      row_index[14] = 15 ;
+      break ;
+    case 15:
+      row_index[15] = 0 ;
+      break ;
+    case 16:
+      row_index[16] = 31 ;
+      break ;
+    case 17:
+      row_index[17] = 16 ;
+      break ;
+    case 18:
+      row_index[18] = 30 ;
+      break ;
+    case 19:
+      row_index[19] = 17 ;
+      break ;
+    case 20:
+      row_index[20] = 29 ;
+      break ;
+    case 21:
+      row_index[21] = 18 ;
+      break ;
+    case 22:
+      row_index[22] = 28 ;
+      break ;
+    case 23:
+      row_index[23] = 19 ;
+      break ;
+    case 24:
+      row_index[24] = 27 ;
+      break ;
+    case 25:
+      row_index[25] = 20 ;
+      break ;
+    case 26:
+      row_index[26] = 26 ;
+      break ;
+    case 27:
+      row_index[27] = 21 ;
+      break ;
+    case 28:
+      row_index[28] = 25 ;
+      break ;
+    case 29:
+      row_index[29] = 22 ;
+      break ;
+    case 30:
+      row_index[30] = 24 ;
+      break ;
+    case 31:
+      row_index[31] = 23 ;
+      break ;
+    default:
+      sinfo_msg_error("wrong slitlet index: couldn't be a spiffi "
+                      "image,  there must be 32 slitlets!\n") ;
+      return -1 ;
+    }
+
+  return 0;
+
+}
+
+
+
+/**
+   @name sinfo_new_make_cube_spi()
+   @param  calibImage  resampled source image
+   @param  slit_edges  absolute beginning and ending positions of
+                                     slitlet, output of sinfo_fitSlits().
+   @param  shift       sub_pixel shifts referred to the reference slit
+                                     sinfo_edge
+   @result  resulting source data cube
+   @doc     makes a data cube out of a resampled source image
+            this SPIFFI specific routine takes into account the
+            Spiffi slitlet order on the detector.
+            This routine takes fitted slitlet positions into account.
+            Can do the same with the bad pixel map image to generate a
+            bad pixel mask cube.
+*/
+
+cpl_imagelist * 
+sinfo_new_make_cube_spi ( cpl_image *  calibImage,
+                        float    ** slit_edges,
+                        float    *  shift )
+{
+    cpl_imagelist * returnCube ;
+    float diff, start ;
+    float * center ;
+    int * row_index ;
+    int slit ;
+    int col, z ;
+    int imsize ;
+    int * beginCol ;
+    int col_counter ;
+    int ilx=0;
+    int ily=0;
+
+    float* podata=NULL;
+    float* pidata=NULL;
+    cpl_image* o_img;
+
+
+    if ( NULL == calibImage )
+    {
+        sinfo_msg_error("no resampled image given!\n") ;
+        return NULL ;
+    }
+    ilx=cpl_image_get_size_x(calibImage);
+    ily=cpl_image_get_size_y(calibImage);
+    pidata=cpl_image_get_data_float(calibImage);
+
+    if ( NULL == slit_edges )
+    {
+        sinfo_msg_error("no slit_edges array given from sinfo_fitSlits()!/n") ;
+        return NULL ;
+    }
+
+    if ( N_SLITLETS != 32 )
+    {
+        sinfo_msg_error ("wrong number of slitlets given \n" ) ;
+        return NULL ;
+    }
+    imsize = ilx / N_SLITLETS ;
+
+    /* allocate memory */  
+    if ( NULL == (row_index = (int*) cpl_calloc(N_SLITLETS, sizeof(int)) ) )
+    {
+        sinfo_msg_error ("cannot allocate memory \n" ) ;
+        return NULL ;
+    }
+    if ( NULL == (beginCol = (int*) cpl_calloc(N_SLITLETS, sizeof(int)) ) )
+    {
+        sinfo_msg_error ("cannot allocate memory \n" ) ;
+        cpl_free(row_index) ;
+        return NULL ;
+    }
+    if ( NULL == (center = (float*) cpl_calloc(N_SLITLETS, sizeof(float)) ) )
+    {
+        sinfo_msg_error ("cannot allocate memory \n" ) ;
+        cpl_free (row_index) ;
+        cpl_free (beginCol) ;
+        return NULL ;
+    }
+    if ( NULL == (returnCube = cpl_imagelist_new()) )
+    {
+        sinfo_msg_error ("cannot allocate new cube \n" ) ;
+        cpl_free (row_index) ;
+        cpl_free (beginCol) ;
+        cpl_free (center) ;
+        return NULL ;
+    }
+    /* determine the absolute center of the slitlets and the distances 
+       inside the image*/
+    for ( slit = 0 ; slit < N_SLITLETS ; slit++ ) 
+    /* go through the slitlets of each row of the resampled image */
+    {
+        center[slit] = (slit_edges[slit][1] + slit_edges[slit][0]) / 2. ;
+        /* -------------------------------------------------------------
+         * sort the slitlets in the right spiffi specific way
+         * the row_index describes the row index of the current slitlet 
+         * in the resulting cube images.
+         */
+        if(-1 == sinfo_sort_slitlets_array(slit,row_index)) {
+	  cpl_imagelist_delete(returnCube) ;
+	  cpl_free (row_index) ;
+          cpl_free (beginCol) ;
+          cpl_free (center) ;
+          return NULL ;
+        }
+        /* determine the integer column on which the slitlet starts, center the
+           slitlet on the image row */
+        start = center[slit] - (float) (imsize - 1)/2. ;
+        beginCol[slit] = sinfo_new_nint (start) ;
+        /* determine the error of using integer pixels */
+        diff = start - (float)beginCol[slit] ;
+
+        /*-------------------------------------------------------------------- 
+         * determine the output shift values by which the rows are finally 
+           shifted, consider the integer pixel errors  
+         * resort shift array to get the row index 
+         */
+        shift[row_index[slit]] = diff ;
+    }   
+
+    /* now build the data cube out of the resampled image */
+    for ( z = 0 ; z < ily ; z++ ) /* go through the z-axis */
+    {
+      o_img=cpl_image_new(imsize,N_SLITLETS,CPL_TYPE_FLOAT);
+      podata=cpl_image_get_data_float(o_img);
+      for ( slit = 0 ; slit < N_SLITLETS ; slit++ )
+        {
+      col_counter = beginCol[slit] ;
+      /* each slitlet is centered on the final image row */
+      for ( col = 0 ; col < imsize ; col++ )
+            {
+          if ( col_counter > ilx-1 )
+                {
+          col_counter-- ;
+                }
+          if ( col_counter + z*ilx < 0 )
+                {
+          podata[col+row_index[slit]*imsize] = pidata[0] ;
+                }
+              else
+                {   
+                  podata[col+row_index[slit]*imsize]=pidata[col_counter+z*ilx];
+                }
+
+                col_counter++ ;
+            }
+        }
+      cpl_imagelist_set(returnCube,o_img,z);    
+    }
+    cpl_free (row_index) ;
+    cpl_free (beginCol) ;
+    cpl_free (center) ;
+
+    return returnCube ;
+}
+/**
+   @name   sinfo_new_make_cube_dist()
+   @memo   makes a data cube out of a resampled source image
+   @param  calibImage  resampled source image
+   @param  firstCol    floating point value of the first column of
+                                     the first slitlet in the resampled image,
+                                     determined "by hand"
+   @param  distances   distances of the slitlets from each other
+                                     output of function ns_test
+   @param  shift       dummy array with 32 elements
+   @result              resulting source data cube
+   @note       shift differences of the slitlets from
+                               distance 32 given in the correct
+                               Spiffi row sequence. The first slitlet
+                               is the reference, therefore element
+                               23 is set 0.
+   @doc        makes a data cube out of a resampled source image
+                        this SPIFFI specific routine takes into account the
+                        Spiffi slitlet order on the detector.
+                        Also shifts the resulting image rows by one pixel if
+                        necessary according to the distances array gained from
+                        the north-south test routine.
+                Can do the same with the bad pixel map image to generate a
+                bad pixel mask cube.
+*/
+
+cpl_imagelist * 
+sinfo_new_make_cube_dist ( cpl_image * calibImage,
+                         float      firstCol,
+                         float    * distances,
+                         float    * shift )
+{
+    cpl_imagelist * returnCube ;
+    float di ;
+    float diff, start ;
+    int * row_index ;
+    int slit ;
+    int col, z ;
+    int imsize ;
+    int * beginCol ;
+    int col_counter ;
+    int ilx=0;
+    int ily=0;
+
+    float* podata=NULL;
+    float* pidata=NULL;
+    cpl_image* o_img;
+
+    if ( NULL == calibImage )
+    {
+        sinfo_msg_error(" no resampled image given!\n") ;
+        return NULL ;
+    }
+    ilx=cpl_image_get_size_x(calibImage);
+    ily=cpl_image_get_size_y(calibImage);
+    pidata=cpl_image_get_data_float(calibImage);
+
+    if ( NULL == distances )
+    {
+        sinfo_msg_error("no distances array given from north_south_test()!") ;
+        return NULL ;
+    }
+
+    if ( N_SLITLETS != 32 )
+    {
+        sinfo_msg_error ("wrong number of slitlets given \n" ) ;
+        return NULL ;
+    }
+    imsize = ilx / N_SLITLETS ;
+
+    /* allocate memory */  
+    if ( NULL == (row_index = (int*) cpl_calloc(N_SLITLETS, sizeof(int)) ) )
+    {
+        sinfo_msg_error ("cannot allocate memory \n" ) ;
+        return NULL ;
+    }
+    if ( NULL == (beginCol = (int*) cpl_calloc(N_SLITLETS, sizeof(int)) ) )
+    {
+        sinfo_msg_error ("cannot allocate memory \n" ) ;
+        cpl_free(row_index) ;
+        return NULL ;
+    }
+    if ( NULL == (returnCube = cpl_imagelist_new()) )
+    {
+        sinfo_msg_error ("cannot allocate new cube \n" ) ;
+        cpl_free(row_index) ;
+        cpl_free(beginCol) ;
+        return NULL ;
+    }
+
+    di = 0. ;
+    /* determine the absolute beginning of the slitlets and the distances 
+       inside the image*/
+    for ( slit = 0 ; slit < N_SLITLETS ; slit++ ) 
+    /* go through the slitlets of each row of the resampled image */
+    {
+
+        /* -------------------------------------------------------------
+         * sort the slitlets in the right spiffi specific way
+         * the row_index describes the row index of the current slitlet 
+         * in the resulting cube images.
+         */
+        if(-1 == sinfo_sort_slitlets_array(slit,row_index)) {
+	  cpl_imagelist_delete(returnCube) ;
+	  cpl_free(row_index) ;
+	  cpl_free(beginCol) ;
+	  return NULL ;
+        }
+
+        /* determine the integer column on which the slitlet starts */
+        if ( slit == 0 )
+        {
+            start = firstCol ;
+        }
+        else
+        {
+            di += distances[slit-1] ;
+            start = firstCol + di ;
+        }
+        beginCol[slit] = sinfo_new_nint(start) ;
+
+        /* determine the error of using integer pixels, its always smaller 
+           than 1 */
+        diff = start - (float)beginCol[slit] ;
+
+        /*---------------------------------------------------------------- 
+         * determine the output shift values by which the rows are finally 
+         * shifted, consider the integer pixel errors and resort shift array 
+         * to get the row index 
+         */
+        shift[row_index[slit]] = diff ;
+    }   
+
+    /* now build the data cube out of the resampled image */
+    for ( z = 0 ; z < ily ; z++ ) /* go through the z-axis */
+    {
+      o_img=cpl_image_new(imsize,N_SLITLETS,CPL_TYPE_FLOAT);
+      podata=cpl_image_get_data_float(o_img);
+      for ( slit = 0 ; slit < N_SLITLETS ; slit++ )
+        {
+      col_counter = beginCol[slit] ;
+      /* each slitlet is centered on the final image row */
+      for ( col = 0 ; col < imsize ; col++ )
+            {
+          if ( col_counter > ilx-1 )
+                {
+          col_counter-- ;
+                }
+                if ( col_counter + z*ilx < 0 )
+                {
+          podata[col+row_index[slit]*imsize] = podata[0] ;
+                }
+                else
+                {   
+                  podata[col+row_index[slit]*imsize]=pidata[col_counter+z*ilx];
+                }
+
+                col_counter++ ;
+            }
+        }  
+      cpl_imagelist_set(returnCube,o_img,z);  
+    }
+    cpl_free (row_index) ;
+    cpl_free (beginCol) ;
+
+    return returnCube ;
+}
+/**
+   @name   sinfo_new_make_3D_cube_dist()
+   @param  calibImage  resampled source image
+   @param  firstCol    floating point value of the first column of
+                                     the first slitlet in the resampled image,
+                                     determined "by hand"
+   @param  distances   distances of the slitlets from each other
+                                     output of function ns_test
+   @param  shift       dummy array with 32 elements
+   @return resulting source data cube
+   @note   shift differences of the slitlets from
+                               distance 32 given in the correct
+                               Spiffi row sequence. The first slitlet
+                               is the reference, therefore element
+                               23 is set 0.
+   @doc       makes a data cube out of a resampled source image
+                        this 3D specific routine takes into account the
+                        3D slitlet order on the detector.
+                        Also shifts the resulting image rows by one pixel if
+                        necessary according to the distances array gained from
+                        the north-south test routine.
+              Can do the same with the bad pixel map image to generate a
+              bad pixel mask cube.
+*/
+
+
+cpl_imagelist * 
+sinfo_new_make_3D_cube_dist ( cpl_image * calibImage,
+                           float      firstCol,
+                           float    * distances,
+                           float    * shift )
+{
+    cpl_imagelist * returnCube ;
+    float di ;
+    float diff, start ;
+    int * row_index ;
+    int slit ;
+    int col, z ;
+    int imsize ;
+    int * beginCol ;
+    int col_counter ;
+    int ilx=0;
+    int ily=0;
+
+    float* podata=NULL;
+    float* pidata=NULL;
+    cpl_image* o_img;
+
+    if ( NULL == calibImage )
+    {
+        sinfo_msg_error(" no resampled image given!\n") ;
+        return NULL ;
+    }
+    ilx=cpl_image_get_size_x(calibImage);
+    ily=cpl_image_get_size_y(calibImage);
+    pidata=cpl_image_get_data_float(calibImage);
+
+    if ( NULL == distances )
+    {
+        sinfo_msg_error("no distances array given from north_south_test()!") ;
+        return NULL ;
+    }
+
+    if ( N_SLITLETS != 16 )
+    {
+        sinfo_msg_error ("wrong number of slitlets given \n" ) ;
+        return NULL ;
+    }
+    imsize = ilx / N_SLITLETS ;
+
+    /* allocate memory */  
+    if ( NULL == (row_index = (int*) cpl_calloc(N_SLITLETS, sizeof(int)) ) )
+    {
+        sinfo_msg_error ("cannot allocate memory \n" ) ;
+        return NULL ;
+    }
+    if ( NULL == (beginCol = (int*) cpl_calloc(N_SLITLETS, sizeof(int)) ) )
+    {
+        sinfo_msg_error ("cannot allocate memory \n" ) ;
+        cpl_free(row_index) ;
+        return NULL ;
+    }
+    if ( NULL == (returnCube = cpl_imagelist_new()) )
+    {
+        sinfo_msg_error ("cannot allocate new cube \n" ) ;
+        cpl_free(row_index) ;
+        cpl_free(beginCol) ;
+        return NULL ;
+    }
+
+    di = 0. ;
+    /* determine the absolute beginning of the slitlets and the distances 
+       inside the image*/
+    for ( slit = 0 ; slit < N_SLITLETS ; slit++ ) 
+    /* go through the slitlets of each row of the resampled image */
+    {
+
+        /* --------------------------------------------------------------
+         * sort the slitlets in the right 3D specific way
+         * the row_index describes the row index of the current slitlet 
+         * in the resulting cube images.
+         */
+        row_index[slit] = slit ;
+
+        /* determine the integer column on which the slitlet starts */
+        if ( slit == 0 )
+        {
+            start = firstCol ;
+        }
+        else
+        {
+            di += distances[slit-1] ;
+            start = firstCol + di ;
+        }
+        beginCol[slit] = sinfo_new_nint(start) ;
+
+        /* determine the error of using integer pixels, 
+           `its always smaller than 1 */
+        diff = start - (float)beginCol[slit] ;
+
+        /*---------------------------------------------------------------- 
+         * determine the output shift values by which the rows are finally 
+           shifted, consider the integer pixel errors and resort shift array 
+           to get the row index 
+         */
+        shift[row_index[slit]] = diff ;
+    }   
+
+    /* now build the data cube out of the resampled image */
+    for ( z = 0 ; z < ily ; z++ ) /* go through the z-axis */
+    {
+      o_img=cpl_image_new(imsize,N_SLITLETS,CPL_TYPE_FLOAT);
+      podata=cpl_image_get_data_float(o_img);
+        for ( slit = 0 ; slit < N_SLITLETS ; slit++ )
+        {
+            col_counter = beginCol[slit] ;
+            /* each slitlet is centered on the final image row */
+            for ( col = 0 ; col < imsize ; col++ )
+            {
+                if ( col_counter > ilx-1 )
+                {
+                    col_counter-- ;
+                }
+                podata[col+row_index[slit]*imsize]=pidata[col_counter+z*ilx];
+                col_counter++ ;
+            }
+        } 
+        cpl_imagelist_set(returnCube,o_img,z);   
+    }
+    cpl_free (row_index) ;
+    cpl_free (beginCol) ;
+
+    return returnCube ;
+}
+
+/**
+  @name   sinfo_new_make_3D_cube()
+  @param  calibImage  resampled source image
+  @param  kpixshift   integer pixel shifts of the resulting image
+                                     plane rows.
+  @param  kpixfirst   first valid pixel
+  @result resulting source data cube
+  @doc    makes a data cube out of a resampled source image
+          this MPE 3D specific routine takes into account the
+          3D slitlet order on the detector.
+          Also shifts the resulting image row by an integer pixel shift if
+          necessary according to the input kpixshift array 
+          Can do the same with the bad pixel map image to generate a
+          bad pixel mask cube.
+*/
+
+
+cpl_imagelist * 
+sinfo_new_make_3D_cube ( cpl_image * calibImage,
+                       int      * kpixshift, 
+                       int        kpixfirst )
+{
+    cpl_imagelist * returnCube ;
+    int imsize, kslit, kpix ;
+    int z, col, recol ;
+    int ilx=0;
+    int ily=0;
+
+    float* podata=NULL;
+    float* pidata=NULL;
+    cpl_image* o_img;
+
+    if ( NULL == calibImage )
+    {
+        sinfo_msg_error("no resampled image given!\n") ;
+        return NULL ;
+    }
+    ilx=cpl_image_get_size_x(calibImage);
+    ily=cpl_image_get_size_y(calibImage);
+    pidata=cpl_image_get_data_float(calibImage);
+
+    if ( NULL == kpixshift )
+    {
+        sinfo_msg_error("no shift array given!/n") ;
+        return NULL ;
+    }
+
+    if ( kpixfirst < 0 )
+    {
+        sinfo_msg_error("wrong first valid pixel given!/n") ;
+        return NULL ;
+    }
+
+    if ( N_SLITLETS != 16 )
+    {
+        sinfo_msg_error ("wrong number of slitlets given \n" ) ;
+        return NULL ;
+    }
+    imsize = ilx / N_SLITLETS ;
+
+    if ( NULL == (returnCube = cpl_imagelist_new()) )
+    {
+        sinfo_msg_error ("cannot allocate new cube \n" ) ;
+        return NULL ;
+    }
+
+    /* now build the data cube out of the resampled image */
+    for ( z = 0 ; z < ily ; z++ ) /* go through the z-axis */
+    {
+      o_img=cpl_image_new(imsize,N_SLITLETS,CPL_TYPE_FLOAT);
+      podata=cpl_image_get_data_float(o_img);
+        kpix       = 0 ;
+        kslit      = 0 ;
+        recol      = -1 ;
+        for ( col = 0 ; col < ilx ; col++ ) /* go through the image columns */
+        {
+            if ( col % imsize == 0 ) 
+            {
+                recol = 0 ;
+                kslit = col/imsize ;
+                kpix  = kpixfirst + kpixshift[kslit] ;
+            }
+
+            /* fill each cube plane with one image row */
+            podata[recol+kslit*imsize] = pidata[col+kpix+z*ilx] ;
+            recol++ ;
+            if ( recol > imsize )
+            {
+                sinfo_msg_error("wrong column of reconstructed image, i"
+                                "shouldn't happen!\n") ; 
+                cpl_imagelist_delete(returnCube) ;
+                return NULL ;
+            }
+        }
+        cpl_imagelist_set(returnCube,o_img,z);
+    }
+    return returnCube ;
+}
+
+/**
+   @name     sinfo_new_determine_mask_cube()
+   @memo converts resampled bad pixels to real bad pixels in data cubes.
+   @param    sourceMaskCube  bad pixel mask cube generated by using
+                              the bad pixel mask frame (0: bad, 1: good)
+                              and going through the same reduction steps 
+                              as with the observation frame.
+   @param lowLimit        low limit of pixel value (about -0.7)
+   @param highLimit       high limit of bad pixel value (about 0.7)
+   @result resulting bad pixel data cube (bad pixels: 0, good pixels: 1).
+*/
+
+cpl_imagelist * 
+sinfo_new_determine_mask_cube ( cpl_imagelist * sourceMaskCube,
+                              float     lowLimit,
+                              float     highLimit )
+{
+    cpl_imagelist * retCube ; 
+    int z, n ;
+    int ilx=0;
+    int ily=0;
+    int inp=0;
+    int olx=0;
+    int oly=0;
+    int onp=0;
+    float* podata=NULL;
+    cpl_image* o_img;
+
+    if ( sourceMaskCube == NULL )
+    {
+        sinfo_msg_error("no cube given!\n") ;
+        return NULL ;
+    }
+    ilx=cpl_image_get_size_x(cpl_imagelist_get(sourceMaskCube,0));
+    ily=cpl_image_get_size_y(cpl_imagelist_get(sourceMaskCube,0));
+    inp=cpl_imagelist_get_size(sourceMaskCube);
+
+
+    if ( lowLimit > 0. )
+    {
+        sinfo_msg_error("lowLimit wrong!\n") ;
+        return NULL ;
+    }
+    if ( highLimit >= 1. || highLimit < 0. )
+    {
+        sinfo_msg_error("highLimit wrong!\n") ;
+        return NULL ;
+    }
+
+    retCube = cpl_imagelist_duplicate (sourceMaskCube) ;
+    onp=inp;
+    olx=ilx;
+    oly=ily;
+
+    for ( z = 0 ; z < onp ; z++ )
+    {
+      o_img=cpl_imagelist_get(retCube,0);
+      podata=cpl_image_get_data_float(o_img);
+        for ( n = 0 ; n < (int) olx*oly; n++ )
+        {
+            if ( podata[n] == 0. )
+            {
+               continue ;
+            }
+            if ( podata[n] == 1. )
+            {
+               continue ;
+            }
+            if ( podata[n] >= lowLimit && 
+                 podata[n] <= highLimit )
+            {
+                podata[n] = 0. ;
+            }
+            else 
+            {
+                podata[n] = 1. ;
+            }
+        }
+    }
+    return retCube ;
+}
+/**
+   @name     sinfo_new_interpol_cube()
+   @param    sourceCube  reconstructed source cube from sinfo_makeCube
+                                     without fine tuning of rows
+   @param    maskCube    bad pixel mask cube, bad pixel are marked
+                          with 0., good and interpolated pixels with 1.
+                          this maskCube is changed within the routine
+                          if a bad pixel was interpolated.
+   @param    n_neighbors number of neighbors in one spectral direction
+                          with which the bad pixel will be interpolated (7)
+   @param    max_radius  maximal pixel radius within an image plane
+                          inside which valid pixels are searched to
+                          be used for interpolation. If there aren't
+                          found 9 good neighboring pixels within this
+                          radius the loop is left. (5)
+   @result   resulting interpolated data cube.
+             changed maskCube at the positions of the interpolated pixels
+   @doc      Bad pixel interpolation 3D like (saturated pixels exist):
+             interpolates the bad pixels of the source cube by
+             using the nearest neighbors.
+             first it is checked if the bad pixel is interpolatable:
+             it is only interpolatable if the number of good pixels
+             in its spectrum of length 2*n_neighbors+1 exceeds 3 and
+             if there is at least one good pixel on either side of the
+             central pixel.
+             Afterwards good neighboring pixels are searched within the
+             image plane of the bad pixel by using an increasing pixel radius.
+             Good pixels mean, the corresponding spectral pixels of the
+             bad pixel and its spatial neighboring pixel must have
+             at least 2 valid pixel pairs to be able to be used for
+             the interpolation. The search is stopped if 9 valid neighboring
+             pixels are found.
+             Now normalize the found spectral values, collect the valid pixels
+             (there must be at least 18) and take the sinfo_median of the valid
+             pixels with which the bad pixel is replaced.
+*/
+
+
+cpl_imagelist * 
+sinfo_new_interpol_cube ( cpl_imagelist * sourceCube,
+                         cpl_imagelist * maskCube,
+                         int       n_neighbors, /* 7 */
+                         int       max_radius ) /* 5 */
+{
+    cpl_imagelist  * returnCube ;
+    float** spec=NULL ;
+    float* spec1=NULL ;
+    int n_im, n_bad, n_bad1, n_bad2 ;
+    int n_planes, specn, nspec1 ;
+    int i, m, n, z, ni, kk, p ;
+    int dis, dismin, dismax ;
+    int agreed ;
+    int xcordi, ycordi, xcordm, ycordm ;
+
+
+
+    int ilx=0;
+    int ily=0;
+    int inp=0;
+   
+    float* pidata=NULL;
+    float* pmdata=NULL;
+    float* podata=NULL;
+    cpl_image* i_img=NULL;
+    cpl_image* m_img=NULL;
+    cpl_image* o_img=NULL;
+
+    if ( NULL == sourceCube )
+    {
+        sinfo_msg_error(" no source cube given!\n") ;
+        return NULL ;
+    }
+
+
+    ilx=cpl_image_get_size_x(cpl_imagelist_get(sourceCube,0));
+    ily=cpl_image_get_size_y(cpl_imagelist_get(sourceCube,0));
+    inp=cpl_imagelist_get_size(sourceCube);
+
+    if ( NULL == maskCube )
+    {
+        sinfo_msg_error("no bad pixel mask cube given!\n") ;
+        return NULL ;
+    }
+
+    if ( n_neighbors <= 0 )
+    {
+        sinfo_msg_error("wrong number of neighbors in the spectral "
+                        "direction given!") ;
+        return NULL ;
+    }
+   
+    if ( max_radius <= 0 )
+    {
+        sinfo_msg_error("wrong maximal radius for interpolation inside "
+                        "an image plane given!") ;
+        return NULL ;
+    }
+
+    returnCube = cpl_imagelist_duplicate(sourceCube) ;
+    
+    n_im     = ilx * ily ;
+    n_planes = inp ;
+
+    spec1=cpl_calloc(300,sizeof(float)) ;
+    spec=sinfo_new_2Dfloatarray(100,2*n_neighbors+1) ;
+
+    /* loop over the image planes and look for bad pixels and correct them */
+    for ( z = 0 ; z < n_planes ; z++ ) /* go through image planes */
+    {
+      m_img=cpl_imagelist_get(maskCube,z);
+      pmdata=cpl_image_get_data_float(m_img);
+      o_img=cpl_imagelist_get(returnCube,z);
+      podata=cpl_image_get_data_float(o_img);
+
+        /*-------------------------------------------------------------------
+         * determine n, the length of one wing in one spectrum with which the 
+         * bad pixel will be interpolated. The length of one wing is 
+           n_neighbors but less at the edges of the cube. 
+         */
+        if ( z < n_neighbors )
+        {
+            n = z ;
+        }
+        else if ( n_planes - z <= n_neighbors)
+        {
+            n = n_planes - z -1 ;
+        }
+        else
+        { 
+            n = n_neighbors ;
+        }
+
+        for ( i = 0 ; i < n_im ; i ++ ) /* go through one image */
+        {
+            /* continue if the pixel is a good one */
+            if ( pmdata[i] != 0. )
+            {
+                continue ;
+            }
+        
+            /*-------------------------------------------------------------
+             * exclude pixels with too many bad neighbors in the spectrum.
+             * exit if: too few good pixels in the neighboring spectrum or 
+             * good pixels are only on one side of the spectrum.
+             */
+            n_bad  = 0 ;
+            n_bad1 = 0 ;
+            n_bad2 = 0 ;
+            /* go through the neighbor spectral pixels */
+            for ( ni = z-n ; ni <= z+n ; ni++ ) 
+            {
+                if ( pmdata[i] == 0. )
+                {
+                    n_bad++ ;
+                    /* count bad pixels on either spectral side of 
+                       the bad pixel to be interpolated */
+                    if ( ni < z )
+                    {
+                        n_bad1++ ;
+                    }
+                    if ( ni > z )
+                    {
+                        n_bad2++ ;
+                    }
+                }
+            }
+         
+            /*--------------------------------------------------------------- 
+             * now the criteria are checked which the neighborhood in the 
+               spectral dimension has to match if the pixel is interpolatable.
+             * The total number of the good pixel in the spectrum must be more 
+               than 3 and there must be at least one good pixel on either side 
+               of the central pixel.
+             */
+            if ( (2*n+1 - n_bad) < 3 || (n - n_bad1) < 1 || (n - n_bad2) < 1 )
+            {
+                continue ;
+            }
+            
+            /* read the master spectrum into the first row of the array spec */
+            kk = 0 ;
+            for ( ni = z-n ; ni <= z+n ; ni++ )
+            {
+          i_img=cpl_imagelist_get(sourceCube,ni);
+              pidata=cpl_image_get_data_float(i_img);
+                spec[1][kk] = pmdata[i] != 0. ? pidata[i] : ZERO ;
+                kk++ ; /* length of spectrum */
+            }
+            
+            /* look for appropriate neighbors in the x-y neighborhood */
+            agreed = 1 ; /* loop guard */
+            specn  = 2 ; /* number of spectra in spec. 
+                            First is master spectrum */
+            dismin = 0 ; /* x+y minimal distance to bad pixel */
+            dismax = 1 ; /* x+y maximal distance to bad pixel */
+            do
+            {
+                for ( m = 0 ; m < n_im ; m++ )
+                {
+                    if ( pmdata[m] == 0. )
+                    {
+                        continue ;
+                    }
+
+                    /* --------------------------------------------------------
+                     * determine the x and y coordinates of the bad pixel (i)
+                     * and the pixels used to interpolate (m) 
+                     */
+                    xcordi = i % ilx ;
+                    xcordm = m % ilx ;
+                    ycordi = i / ilx ;
+                    ycordm = m / ilx ;
+                    /*----------------------------------------------------- 
+                     * check the distance: take only close pixels
+                     * extension 'i' is coordinate of the bad pixel to be 
+                       interpolated
+                     */
+                    dis = abs(xcordi-xcordm) + abs(ycordi-ycordm) ;
+                    if ( dis <= dismin || dis > dismax )
+                    {
+                        continue ;
+                    }
+                    /*--------------------------------------------------------
+                     * check on number of bad pixels in the spectrum of a 
+                     * neighbor pixel; reject it if it contains less than 2 
+                     * usable pixel pairs. a bit more explanation:
+                     * let this be a 15 pixel spectrum with the pixel to be 
+                     * interpolated denoted by '0' and other bad pixels marked 
+                     * with 'b'. Good pixels are marked with '1'. Below a 
+                     * neighbor spectrum is drawn containing bad pixels as 
+                     * well. The third line shows the position of the usable 
+                     * pixel pairs, spectral
+                     * positions, where both spectra have valid pixels.
+                     *
+                     *   1 1 1 b b 1 1 0 b 1 b b 1 b b
+                     *   b 1 1 1 b b 1 1 1 1 1 1 b b 1
+                     *     ^ ^       ^     ^             4 good pixel pairs
+                     */
+      
+                    n_bad = 0 ;
+                    for ( ni = z-n ; ni <= z+n ; ni++ )
+                    {
+                        if ( pmdata[i] == 0. || pmdata[m] == 0. )
+                        {
+                            n_bad++ ;
+                        }
+                    }
+                    if ( n_bad > 2*n-1 ) 
+                    /* we need at least 2 usable pixel pairs */
+                    {
+                        continue ;
+                    }
+                    
+                    /* transfer the spectrum to the next position 
+                       of array spec */
+                    kk = 0 ;
+                    for ( ni = z-n ; ni <= z+n ; ni++ )
+                    {
+              i_img=cpl_imagelist_get(sourceCube,ni);
+              pidata=cpl_image_get_data_float(i_img);
+                        spec[specn][kk] = pmdata[m] != 0. ? pidata[m] : ZERO ;
+                        kk++ ;
+                    }
+                    specn++ ;
+                    if ( specn > 10 ) /* if we have 9 neighbors then break */
+                    {
+                        agreed = 0 ;
+                        break ;
+                    }
+                }
+                /* if no break, increase search radius and continue */
+                dismin++ ;        
+                dismax++ ;
+                /* if search radius is too big, exit with fewer 
+                   good neighbors */
+                if ( dismax > max_radius )
+                {
+                    agreed = 0 ;
+                }
+            }   while(agreed) ;    
+                       
+            specn-- ;
+            dismax -= 2 ;
+            /* TODO: why compute dismax is later this is not used? */
+            /* ---------------------------------------------------------------
+             * Take the master spectrum with the bad pixel in the middle and 
+               divide it by each of the neighbor spectra and normalize the 
+               division with the value in  the center position.
+             */
+            for ( kk = 0 ; kk < 2*n+1 ; kk++ )
+            {
+                if ( kk == n )    /* do not divide the master bad pixel */
+                {
+                    continue ;
+                }
+
+                /* do not divide bad pixels in the master spectrum */
+                if ( isnan(spec[1][kk]) ) 
+                {
+                    for ( p = 2 ; p <= specn ; p++ )
+                    {
+                        spec[p][kk] = ZERO ;
+                    }
+                }    
+                else       /* all is well, now divide */
+                {
+                    for ( p = 2 ; p <= specn ; p++ )
+                    {
+                        if ( !isnan(spec[p][kk]) && spec[p][kk] != 0. &&
+                             !isnan(spec[p][n]) )
+                        {
+                            spec[p][kk] = spec[1][kk] / 
+                                          spec[p][kk] * spec[p][n] ;
+                        }
+                        else
+                        {
+                            spec[p][kk] = ZERO ;
+                        }
+                    }
+                }
+            }
+ 
+            /*-----------------------------------------------------------------
+             * determine the sinfo_median of all values. With 9 good neighbors 
+             * and at least 2 good values per neighbor we have between 18 and 
+             * 9*14 values for the statistics. If there are not enough good 
+             * neighbors available, only continue if we have collected at 
+             * least 18 values.
+             */
+            nspec1 = 0 ;  
+            /* collect the good values in the array spec1 */ 
+            for ( p = 2 ; p <= specn ; p++ )
+            {
+                for ( kk = 0 ; kk < 2*n+1 ; kk++ )
+                {
+                    if ( !isnan(spec[p][kk]) && kk != n )
+                    {
+                        spec1[nspec1] = spec[p][kk] ;
+                        nspec1++ ;
+                    }
+                }
+            }
+            
+            /* now test if we have at least 18 values */
+            if ( nspec1 < 18 )
+            {
+                continue ;
+            }
+ 
+            /* interpolate the bad pixel by the sinfo_median of spec1 */
+            podata[i] = sinfo_new_median(spec1, nspec1) ;
+            pmdata[i] = 1 ;
+        }
+    }           
+    sinfo_new_destroy_2Dfloatarray(&spec,2*n_neighbors+1) ;
+    cpl_free(spec1);
+    return returnCube ;
+}
+/**
+   @name     sinfo_new_fine_tune_cube()
+   @param    cube  cube, output of sinfo_makeCube
+   @param  correct_diff_dist  differences of the slitlets from
+                              distance 32 given in the correct
+                              Spiffi row sequence. The first slitlet
+                              is the reference, therefore element
+                              23 is set 0.
+                              Output of sinfo_makeCube!
+   @result resulting data cube having the exact row positions
+   @doc    fine tunes each row in the right position according
+           to the distances of the slitlets to each other
+           (output of the north-south test).
+           This means that the rows must be realigned by a
+           fraction of a pixel to accomodate non-integer slit
+           length. The fractional realignment is done by using
+           tanh interpolation.
+           Each row is rescaled so that the total flux is conserved.
+*/
+ 
+cpl_imagelist * 
+sinfo_new_fine_tune_cube( cpl_imagelist * cube,
+                                     float   * correct_diff_dist,
+                                     int       n_order )
+{
+    cpl_imagelist * returnCube ;
+    float* row_data=NULL ;
+    float* corrected_row_data=NULL ;
+    float* xnum=NULL ;
+    float sum, new_sum ;
+    float eval/*, dy*/ ;
+    float * imageptr ;
+    int row, col ;
+    int i, z ;
+    int imsize, n_points ;
+    int firstpos ;
+    int  flag;
+    int ilx=0;
+    int ily=0;
+    int inp=0;
+   
+    float* pidata=NULL;
+    float* podata=NULL;
+    cpl_image* i_img=NULL;
+    cpl_image* o_img=NULL;
+
+
+    if ( NULL == cube )
+    {
+        sinfo_msg_error("no input cube given!\n") ;
+        return NULL ;
+    }
+    ilx=cpl_image_get_size_x(cpl_imagelist_get(cube,0));
+    ily=cpl_image_get_size_y(cpl_imagelist_get(cube,0));
+    inp=cpl_imagelist_get_size(cube);
+
+    if ( NULL == correct_diff_dist )
+    {
+        sinfo_msg_error("no distances array from ns_test given!n") ;
+        return NULL ;
+    }
+  
+    if ( n_order <= 0 )
+    {
+        sinfo_msg_error("wrong order of interpolation polynom given!") ;
+    returnCube = cpl_imagelist_duplicate(cube);
+        return returnCube ;
+    }
+
+    returnCube = cpl_imagelist_duplicate(cube);
+    
+    imsize = ily ;
+    if ( imsize != N_SLITLETS )
+    {
+        sinfo_msg_error ("wrong image size\n" ) ;
+        return NULL ;
+    }
+
+    n_points = n_order + 1 ;
+    if ( n_points % 2 == 0 )
+    {
+        firstpos = (int)(n_points/2) - 1 ;
+    }
+    else
+    {
+        firstpos = (int)(n_points/2) ;
+    }
+    xnum=cpl_calloc(n_order+1,sizeof(float)) ;
+
+    for ( i = 0 ; i < n_points ; i++ )
+    {
+        xnum[i] = i ;
+    }    
+
+    row_data=cpl_calloc(ilx,sizeof(float)) ;
+    corrected_row_data=cpl_calloc(ilx,sizeof(float)) ;
+
+    for ( z = 0 ; z < inp ; z++ )
+    {
+      i_img=cpl_imagelist_get(cube,z);
+      pidata=cpl_image_get_data_float(i_img);
+      o_img=cpl_imagelist_get(returnCube,z);
+      podata=cpl_image_get_data_float(o_img);
+
+
+        for ( row = 0 ; row < imsize ; row++ )
+        {
+            for ( col = 0 ; col < ilx ; col++ )
+            {
+                corrected_row_data[col] = 0. ;
+            }
+            sum = 0. ; 
+            for ( col = 0 ; col < ilx ; col++ )
+            {
+                row_data[col] = pidata[col+row*ilx] ;
+                if ( isnan(row_data[col]) )
+                {
+                    row_data[col] = 0. ;
+                    for ( i = col - firstpos ; 
+                          i < col -firstpos+n_points ; i++ )
+                    {
+                        if ( i < 0 ) continue ;
+                        if ( i >= ilx) continue ; 
+                        corrected_row_data[i] = ZERO ;
+                    }
+                }
+                if ( col != 0 && col != ilx - 1 )
+                {
+                    sum += row_data[col] ;
+                }
+            }
+
+           
+            new_sum = 0. ;
+            for ( col = 0 ; col < ilx ; col++ )
+            {
+                
+                if ( isnan(corrected_row_data[col]) )
+                {
+                    continue ;
+                }
+                if ( col - firstpos < 0 )
+                {
+                    imageptr = &row_data[0] ;
+                    eval     = correct_diff_dist[row] + col ;
+                }
+                else if ( col - firstpos + n_points >= ilx )
+                {
+                    imageptr = &row_data[ilx - n_points] ;
+                    eval     = correct_diff_dist[row] + col + n_points - ilx ;
+                }
+                else
+                {
+                    imageptr = &row_data[col-firstpos] ;
+                    eval     = correct_diff_dist[row] + firstpos ;
+                }
+
+        
+        flag = 0;
+        corrected_row_data[col]=sinfo_new_nev_ille(xnum, imageptr, 
+                                                       n_order, eval, &flag);
+
+               
+                if ( col != 0 && col != ilx - 1 )
+                {
+                    new_sum += corrected_row_data[col] ;
+                }
+            }
+            for ( col = 0 ; col < ilx ; col++ )
+            {
+                
+                if ( col == 0 )
+                {
+                    podata[col+row*ilx] = ZERO ;
+                }
+                else if ( col == ilx - 1 )
+                {
+                    podata[col+row*ilx] = ZERO ;
+                }
+                else
+                {
+                    if ( isnan(corrected_row_data[col]) ) 
+                    {
+                        podata[col+row*ilx] = ZERO ;
+                    }
+                    else
+                    {
+                        if ( new_sum == 0. ) new_sum = 1. ;
+                     
+                        podata[col+row*ilx] = corrected_row_data[col] ;
+                    }
+                }
+            }
+        }
+    }       
+
+    cpl_free(xnum) ;
+    cpl_free(row_data) ;
+    cpl_free(corrected_row_data) ;
+
+    return returnCube ;
+}
+
+/**
+   @name   sinfo_new_fine_tune_cube_by_FFT()
+   @param  cube:  cube, output of sinfo_makeCube
+   @param  correct_diff_dist: differences of the slitlets from
+                  distance 32 given in the correct
+                  Spiffi row sequence. The first slitlet
+                  is the reference, therefore element
+                  23 is set 0.
+                  Output of sinfo_makeCube!
+   @param  resulting data cube having the exact row positions
+   @doc    fine tunes each row in the right position according
+                        to the distances of the slitlets to each other
+                        (output of the north-south test).
+                        This means that the rows must be realigned by a
+                        fraction of a pixel to accomodate non-integer slit
+                        length. The fractional realignment is done by using
+                        the FFT algorithm four1() of N.R.
+*/
+
+cpl_imagelist * 
+sinfo_new_fine_tune_cube_by_FFT( cpl_imagelist * cube,
+                                           float   * correct_diff_dist )
+{
+    cpl_imagelist * returnCube ;
+
+    float* row_data=NULL ;
+    dcomplex* data=NULL ;
+    dcomplex* corrected_data=NULL ;
+
+    unsigned nn[2];
+    /*float corrected_row_data[cube->lx] ;*/
+    float phi, pphi ;
+    float coph, siph ;
+    int row, col ;
+    int i, z ;
+    int imsize ;
+    int blank_indicator ;
+
+
+    int ilx=0;
+    int ily=0;
+    int inp=0;
+   
+    float* pidata=NULL;
+    float* podata=NULL;
+    cpl_image* i_img=NULL;
+    cpl_image* o_img=NULL;
+
+
+
+    if ( NULL == cube )
+    {
+        sinfo_msg_error(" no input cube given!\n") ;
+        return NULL ;
+    }
+    ilx=cpl_image_get_size_x(cpl_imagelist_get(cube,0));
+    ily=cpl_image_get_size_y(cpl_imagelist_get(cube,0));
+    inp=cpl_imagelist_get_size(cube);
+
+    nn[1] = ilx ;
+    if ( NULL == correct_diff_dist )
+    {
+        sinfo_msg_error("no distances array from ns_test given!") ;
+        return NULL ;
+    }
+
+    returnCube = cpl_imagelist_duplicate( cube ) ;
+
+    imsize = ily ;
+    if ( imsize != N_SLITLETS )
+    {
+        sinfo_msg_error ("wrong image size\n" ) ;
+        return NULL ;
+    }
+
+    data=cpl_calloc(ilx,sizeof(dcomplex)) ;
+    corrected_data=cpl_calloc(ilx,sizeof(dcomplex)) ;
+
+    row_data=cpl_calloc(ilx,sizeof(float)) ;
+    /* loop over the image planes */
+    for ( z = 0 ; z < inp ; z++ )
+    {
+      i_img=cpl_imagelist_get(cube,z);
+      pidata=cpl_image_get_data_float(i_img);
+      o_img=cpl_imagelist_get(returnCube,z);
+      podata=cpl_image_get_data_float(o_img);
+        /* consider one row at a time */
+        for ( row = 0 ; row < imsize ; row++ )
+        {
+            blank_indicator = 1 ;
+            for ( col = 0 ; col < ilx ; col++ )
+            {
+                /* transfer the row data to a double sized array */
+                row_data[col] = pidata[col+row*ilx] ;
+        data[col].x = row_data[col] ;
+        data[col].y = 0. ;
+                /* if row contains a blank pixel proceed */
+                if ( isnan(row_data[col]) )
+                {
+                    blank_indicator = 0 ; 
+                }
+            }
+
+            /* if row contains a blank don't apply FFT but proceed */
+            if ( blank_indicator == 0 )
+            {
+                for ( col = 0 ; col < ilx ; col++ )
+                {
+                    podata[col+row*ilx] = ZERO ;
+                }
+                continue ;
+            }
+           
+            /* FFT algorithm of eclipse */
+            sinfo_fftn( data, nn, 1, 1 ) ;
+ 
+            /* calculate the corrected phase shift for each frequency */
+            phi = 2*PI_NUMB/(float)ilx * correct_diff_dist[row] ;
+            for ( i = 0 ; i < ilx ; i++ )
+            {
+                /* positive frequencies */
+                if ( i <= ilx/2 )
+                {
+                    /* phase shift */
+                    pphi = phi * (float)(i) ;
+                    /* Euler factor */
+                    coph = cos ( pphi ) ;
+                    siph = sin ( pphi ) ;
+                }
+                else /* negative frequencies */
+                {
+                    /* phase shift */
+                    pphi = phi * (float)(i - ilx/2) ;
+                    /* Euler factor */
+                    coph = cos ( pphi ) ;
+                    siph = sin ( pphi ) ;
+                }
+
+                /* ------------------------------------------------------------
+                 * now calculate the shift in the pixel space by multiplying
+                 * the fourier transform by the Euler factor of the phase shift
+                 * and inverse fourier transforming.
+                 * used Fourier pair: h(x-x0) <==> H(k)*exp(2*pi*i*k*x0) 
+                 */
+                /* calculate real part */
+                corrected_data[i].x   = data[i].x * coph - data[i].y * siph ; 
+                /* calculate imaginary part */
+                corrected_data[i].y = data[i].x * siph + data[i].y * coph ;
+            }
+ 
+            /* transform back: inverse FFT */
+            sinfo_fftn( corrected_data, nn, 1, -1 ) ;
+
+            /* normalize */ 
+            for ( i = 0 ; i < ilx ; i++ )
+            {
+                corrected_data[i].x /= ilx ;
+        corrected_data[i].y /= ilx ;
+            } 
+
+            /* now transfer row to output, leave the left-most 
+               and right-most pixel column */
+            for ( col = 0 ; col < ilx ; col++ )
+            {
+                if ( col == 0 )
+                {
+                    podata[col+row*ilx] = ZERO ;
+                }
+                else if ( col == ilx - 1 )
+                {
+                    podata[col+row*ilx] = ZERO ;
+                }
+                else
+                {
+                    podata[col+row*ilx] = corrected_data[col].x ; 
+                }
+            }
+        }
+    }
+
+    cpl_free(data) ;
+    cpl_free(corrected_data) ;
+
+
+    cpl_free(row_data);
+    return returnCube ;
+}
+/**
+   @name    sinfo_new_fine_tune_cube_by_spline()
+   @param   cube:  cube, output of sinfo_makeCube
+   @param   correct_diff_dist: differences of the slitlets from
+                        distance 32 given in the correct
+                        Spiffi row sequence. The first slitlet
+                        is the reference, therefore element
+                        23 is set 0.
+                        Output of sinfo_makeCube!
+   @result  resulting data cube having the exact row positions
+   @doc     fine tunes each row in the right position according
+                        to the distances of the slitlets to each other
+                        (output of the north-south test).
+                        This means that the rows must be realigned by a
+                        fraction of a pixel to accomodate non-integer slit
+                        length. The fractional realignment is done by using
+                        the spline interpolation algorithm splint in connection
+                        with the algorithm spline of N.R.
+                        This algorithms assume that each row is a tabulated
+                        function. The first derivatives of the interpolating
+                        function at the first and last point must be given.
+                        These are set higher than 1xe^30, so the routine
+                        sets the corresponding boundary condition for a natural
+                        spline, with zero second derivative on that boundary.
+                        Each row is rescaled so that the total flux is
+                        conserved.
+ */
+cpl_imagelist * sinfo_new_fine_tune_cube_by_spline ( cpl_imagelist * cube,
+                                               float   * correct_diff_dist )
+{
+    cpl_imagelist * returnCube ;
+
+    float* row_data=NULL ;
+    float* corrected_row_data=NULL ;
+    float* xnum=NULL ;
+    float* eval=NULL ;
+
+    float sum, new_sum ;
+    int row, col ;
+    int i, z ;
+    int imsize ;
+    int ilx=0;
+    int ily=0;
+    int inp=0;
+   
+    float* pidata=NULL;
+    float* podata=NULL;
+    cpl_image* i_img=NULL;
+    cpl_image* o_img=NULL;
+
+ 
+    if ( NULL == cube )
+    {
+        sinfo_msg_error("no input cube given!\n") ;
+        return NULL ;
+    }
+    ilx=cpl_image_get_size_x(cpl_imagelist_get(cube,0));
+    ily=cpl_image_get_size_y(cpl_imagelist_get(cube,0));
+    inp=cpl_imagelist_get_size(cube);
+
+    if ( NULL == correct_diff_dist )
+    {
+        sinfo_msg_error("no distances array from ns_test given!/n") ;
+        return NULL ;
+    }
+  
+    imsize = ily ;
+    if ( imsize != N_SLITLETS )
+    {
+        sinfo_msg_error ("wrong image size\n" ) ;
+        return NULL ;
+    }
+  
+    returnCube = cpl_imagelist_duplicate( cube ) ;
+
+    row_data=cpl_calloc(ilx,sizeof(float)) ;
+    corrected_row_data=cpl_calloc(ilx,sizeof(float)) ;
+    xnum=cpl_calloc(ilx,sizeof(float)) ;
+    eval=cpl_calloc(ilx,sizeof(float)) ;
+  
+    /* fill the xa[] array for a polynomial interpolation */
+    for ( i = 0 ; i < ilx ; i++ )
+    {
+        xnum[i] = i ;
+    }    
+
+    /* loop over the image planes */
+    for ( z = 0 ; z < inp ; z++ )
+    {
+      i_img=cpl_imagelist_get(cube,z);
+      pidata=cpl_image_get_data_float(i_img);
+      o_img=cpl_imagelist_get(returnCube,z);
+      podata=cpl_image_get_data_float(o_img);
+        /* consider 1 row at a time */
+        for ( row = 0 ; row < imsize ; row++ )
+        {
+            for ( col = 0 ; col < ilx ; col++ )
+            {
+                corrected_row_data[col] = 0. ;
+            }
+        sum = 0. ; /* initialize flux for later rescaling */
+            /* go through the columns and compute the flux for each 
+               row (leave the sinfo_edge points) */
+            for ( col = 0 ; col < ilx ; col++ )
+            {   
+            eval[col] = correct_diff_dist[row] + (float)col ;
+                row_data[col] = pidata[col+row*ilx] ;
+                if (col != 0 && col != ilx - 1 && !isnan(row_data[col]) )
+                {
+                    sum += row_data[col] ;
+                }
+                if (isnan(row_data[col]) )
+                {
+                    for ( i = col -1 ; i <= col+1 ; i++ ) 
+                    {
+                        if ( i < 0 ) continue ;
+                        if ( i >= ilx ) continue ;
+                        corrected_row_data[i] = ZERO ; 
+                    }
+                    row_data[col] = 0. ;
+                }
+        }
+
+
+            /* ---------------------------------------------------------------
+             * now we do the cubic spline interpolation to achieve the 
+               fractional (see eclipse).
+             */
+            if ( -1 == sinfo_function1d_natural_spline(xnum,row_data, ilx, 
+                                                       eval,corrected_row_data,
+                                                       ilx ) )
+        {
+            sinfo_msg_error("error in spline interpolation\n") ;
+        cpl_imagelist_delete(returnCube) ;
+        return NULL ;
+        }    
+
+            new_sum = 0. ;
+            for ( col = 0 ; col < ilx ; col++ )
+            {
+                if (isnan(corrected_row_data[col])) continue ;
+                /* don't take the sinfo_edge points to calculate 
+                   the scaling factor */
+                if ( col != 0 && col != ilx - 1 )
+                {
+                    new_sum += corrected_row_data[col] ;
+                }
+            }
+            for ( col = 0 ; col < ilx ; col++ )
+            {
+                /* ----------------------------------------------------------
+                 * rescale the row data and fill the returned cube, 
+                 * leave the left-most and right-most
+                 * pixel column 
+                 */
+                if ( col == 0 )
+                {
+                    podata[col+row*ilx] = ZERO ;
+                }
+                else if ( col == ilx - 1 )
+                {
+                    podata[col+row*ilx] = ZERO ;
+                }
+                else
+                {
+                    if ( isnan(corrected_row_data[col]) ) 
+                    {
+                        podata[col+row*ilx] = ZERO ;
+                    }
+                    else
+                    {
+                        if (new_sum == 0.) new_sum = 1. ;
+                     /* rescaling is commented out because it delivers 
+                        wrong results
+                        in case of appearance of blanks or bad pixels */
+                  /*       corrected_row_data[col] *= sum / new_sum ; */
+                        podata[col+row*ilx] = corrected_row_data[col] ;
+                    }
+                }
+            }
+        }
+    }       
+
+    cpl_free(row_data) ;
+    cpl_free(corrected_row_data) ;
+    cpl_free(xnum) ;
+    cpl_free(eval) ;
+
+    return returnCube ;
+}
+
+/**
+ at name sinfo_new_calibrate_ns_test perform a nord shouth test
+   @param ns_image:   north-south image
+   @param n_slitlets: number of slitlets
+   @param halfWidth:  half width of the box in which the lines
+                                    are fit by a sinfo_gaussian
+   @param fwhm:       first guess of the full width at half maximum
+   @param minDiff:    minimum amplitude below which the fit
+                                    will not be carried through
+   @param estimated_dist: estimated average distance of spectra
+   @param devtol:     maximal pixel deviation of the distances from
+                                    slitlet center
+   @param bottom  bottom image raw
+   @param top     top image raw 
+
+   @return      array of the distances of the slitlets from each other
+   @doc determines the distances of the spectra from the center
+        of the slitlets to be able to find the correct angle of
+        the north-south entrance slit.
+*/
+
+float * 
+sinfo_new_calibrate_ns_test( cpl_image * ns_image,
+                           int        n_slitlets,
+                           int        halfWidth,
+                           float      fwhm,
+                           float      minDiff,
+                           float      estimated_dist,
+                           float      devtol,
+               int        bottom,
+               int        top )
+{
+    int i, j, k, m, row, col, n, ni, na ;
+    int position, counter, iters ;
+    int xdim, ndat, its, numpar ;
+    float sum, mean, maxval ;
+    float tol, lab ;
+    float * distances ;
+    float * ret_distances ;
+
+    float * xdat, * wdat ;
+    int * mpar ;
+
+    pixelvalue* row_buf=NULL ;
+    float** distances_buf=NULL ;
+    float* x_position=NULL ;
+    int* found=NULL;
+    int* found_clean=NULL ;
+    int* found_cleanit=NULL ;
+
+    Vector * line ;
+    FitParams ** par ;
+    int foundit, begin, end ;
+    int zeroindicator ;
+    int row_index ;
+
+    int ilx=0;
+    int ily=0;
+    float* pidata=NULL;
+
+    if ( ns_image == NULL )
+    {
+        sinfo_msg_error("sorry, no image given\n") ;
+        return NULL ;
+    }
+    if ( n_slitlets < 1 )
+    {
+        sinfo_msg_error("wrong number of slitlets given\n") ;
+        return NULL ;
+    }
+    if ( halfWidth < 0 || halfWidth >= estimated_dist )
+    {
+        sinfo_msg_error("wrong half width given\n") ;
+        return NULL ;
+    }
+    if ( fwhm <= 0. )
+    {
+        sinfo_msg_error("wrong fwhm given\n") ;
+        return NULL ;
+    }
+    if ( minDiff < 1. )
+    {
+        sinfo_msg_error("wrong minDiff given\n") ;
+        return NULL ;
+    }
+
+    /* allocate memory for output array */
+    if (NULL==(distances=(float *)cpl_calloc( n_slitlets , sizeof (float) ))) 
+    {
+        sinfo_msg_error("could not allocate memory\n") ;
+        return NULL ;
+    }
+    /* allocate memory for output array */
+    if (NULL == (ret_distances = (float *) cpl_calloc ( n_slitlets , 
+                                           sizeof (float) ))) 
+    {
+        sinfo_msg_error("could not allocate memory\n") ;
+        return NULL ;
+    }
+
+    ilx=cpl_image_get_size_x(ns_image);
+    ily=cpl_image_get_size_y(ns_image);
+    pidata=cpl_image_get_data_float(ns_image);
+
+    row_buf=(pixelvalue*)cpl_calloc(ilx,sizeof(pixelvalue)) ;
+    x_position=cpl_calloc(n_slitlets,sizeof(float)) ;
+    found=cpl_calloc(3*n_slitlets,sizeof(int));
+    found_clean=cpl_calloc(3*n_slitlets,sizeof(int)) ;
+    found_cleanit=cpl_calloc(3*n_slitlets,sizeof(int)) ;
+    distances_buf=sinfo_new_2Dfloatarray(ily,n_slitlets) ;
+
+    /* go through the image rows */
+    for ( row = 0 ; row < ily ; row++ )
+    {
+        zeroindicator = 0 ;
+
+        /* initialize the distance buffer */
+        for ( i = 0 ; i < n_slitlets ; i++ )
+        {
+            distances_buf[row][i] = ZERO ;
+        }
+
+        /* fill the row buffer array with image data */
+        for ( col = 0 ; col < ilx ; col++ )
+        {
+            row_buf[col] = pidata[col + row*ilx] ;
+        }
+
+        /* determine the mean of the row data */
+        sum = 0. ;
+        n = 0 ;
+        for ( i = 0 ; i < ilx ; i++ )
+        {
+            if ( isnan(row_buf[i]) )
+            {
+                continue ;
+            }
+            sum += row_buf[i] ;
+            n++ ;
+        }
+        mean = sum / (float)n ;
+
+        /* store the positions of image values greater than the mean */
+        n = 0 ;
+        for ( i = 0 ; i < ilx ; i++ )
+        {
+            if (isnan(row_buf[i]))
+            {
+                continue ;
+            }
+            if ( row_buf[i] > mean + ESTIMATE )
+            {
+                found[n] = i ;
+                n++ ;
+            }
+        }
+       
+        if ( n < n_slitlets )
+        {
+            sinfo_msg_warning("t4 wrong number of intensity columns "
+                              "found in row: %d, found number: %d", row, n) ;
+            continue ;
+        }
+        else
+        { 
+            /* find the maximum value position around the found columns */
+            na = 0 ;
+            for ( i = 1 ; i < n ; i ++ )
+            {
+                if ( found[i] - found[i-1] < halfWidth )
+                {
+                    begin = found[i] - halfWidth ;
+                    if ( begin < 0 )
+                    {
+                        begin = 0 ;
+                    }
+                    end = found[i] + halfWidth ;
+                    if ( end >= ilx )
+                    {
+                        end = ilx - 1 ;
+                    }
+                    /* find the maximum value inside the box around 
+                       the found positions*/
+                    maxval = -FLT_MAX ;
+                    foundit = 0 ;
+                    for ( j = begin ; j <= end ; j++ )
+                    {
+                        /* do not consider boxes that contain bad pixels */
+                        if (isnan(row_buf[j]))
+                        {
+                            continue ;
+                        }
+                        if (row_buf[j] >= maxval )
+                        {
+                            maxval = row_buf[j] ;
+                            foundit = j ;
+                        }
+                    }
+                    if (maxval == -FLT_MAX)
+                    {
+                        continue ;
+                    }
+                    for ( k = 0 ; k < na ; k++ )
+                    {
+                        if ( found_cleanit[k] >= begin && 
+                             found_cleanit[k] < foundit )
+                        {
+                            na-- ;
+                        }
+                    }
+                    for ( k = 0 ; k < n ; k++ )
+                    {
+                        if ( found[k] == foundit)
+                        {
+                            if ( found_cleanit[na-1] != found[k] )
+                            {
+                                found_cleanit[na] = found[k] ;
+                                na++ ;
+                            }
+                        }
+                    }
+                }
+                else
+                {
+                    if ( i == 1 )
+                    {
+                        found_cleanit[na] = found[0] ;
+                        na++ ;
+                        found_cleanit[na] = found[1] ;
+                        na++ ;
+                    }
+                    else
+                    {
+                        if ( found_cleanit[na-1] != found[i-1])
+                        {
+                            found_cleanit[na] = found[i-1] ;
+                            na++ ;
+                        }
+                        if ( found_cleanit[na-1] != found[i])
+                        {
+                            found_cleanit[na] = found[i] ;
+                            na++ ;
+                        }
+                    }
+                }
+            }
+
+            /* determine only one pixel position for each slitlet intensity */
+            j = 1 ;
+            for ( i = 1 ; i < na ; i++ )
+            {
+                if ( (float)(found_cleanit[i] - found_cleanit[i-1]) < 
+                             (estimated_dist - devtol) ||
+                     (float)(found_cleanit[i] - found_cleanit[i-1]) > 
+                             (estimated_dist + devtol) )
+                {
+                    continue ;
+                }
+                else
+                {
+                    found_clean[j-1] = found_cleanit[i-1] ;
+                    found_clean[j]   = found_cleanit[i] ;
+                    j++ ;
+                }
+            }
+        }
+        if ( j > n_slitlets )
+        {
+            /* check the distance again */
+            ni = 1 ;
+            for ( i = 1 ; i < j ; i++ )
+            {
+                if ( (float)(found_clean[i] - found_clean[i-1]) < 
+                            (estimated_dist - devtol ) ||
+                     (float)(found_clean[i] - found_clean[i-1]) > 
+                            (estimated_dist + devtol ) )
+                { 
+                    continue ;
+                }
+                else
+                {
+                    found_clean[ni-1] = found_clean[i-1] ;
+                    found_clean[ni]   = found_clean[i] ;
+                    ni++ ;
+                }
+            }
+            if ( ni != n_slitlets )
+            {
+                sinfo_msg_warning("t5 wrong number of intensity columns "
+                                  "found in row: %d, found number: %d",
+                                  row,ni) ;
+                continue ;
+            }
+            else 
+            {
+                j = ni ;
+            }
+        }
+        else if ( j < n_slitlets )
+        {
+            sinfo_msg_warning("t6 wrong number of intensity columns found "
+                              "in row: %d , found number: %d\n", row, j) ;
+            continue ;
+        }
+        counter = 0 ;
+        /* go through the found intensity pixels in one row */
+        for ( i = 0 ; i < j ; i++ )
+        {
+            /* allocate memory for the array where the line is fitted in */
+            if ( NULL == (line = sinfo_new_vector (2*halfWidth + 1)) )
+            {
+                sinfo_msg_error ("cannot allocate new Vector \n") ;
+                cpl_free(distances) ;
+                return NULL ;
+            }
+
+            /* allocate memory */
+            xdat = (float *) cpl_calloc( line -> n_elements, sizeof (float) ) ;
+            wdat = (float *) cpl_calloc( line -> n_elements, sizeof (float) ) ;
+            mpar = (int *)   cpl_calloc( MAXPAR, sizeof (int) ) ;
+            par = sinfo_new_fit_params(1) ;
+
+            m = 0 ;
+            for ( k = found_clean[i]-halfWidth ; 
+                  k <= found_clean[i]+halfWidth ; k++ )
+            {
+                if ( k < 0 )
+                {
+                    k = 0. ;
+                }
+                else if ( k >= ilx )
+                {
+                    k = ilx - 1 ;
+                }
+                else if ( isnan(row_buf[k]) )
+                {
+                    zeroindicator = 1 ;
+                    break ;
+                }
+                else
+                {
+                    line -> data[m] = row_buf[k] ;
+                    m++ ;
+                }
+            }
+            if ( zeroindicator == 1 )
+            {
+                sinfo_new_destroy_vector(line) ;
+                cpl_free(xdat) ;
+                cpl_free(wdat) ;
+                cpl_free(mpar) ;
+                sinfo_new_destroy_fit_params(&par) ;
+                break ;
+            }
+
+            /*-----------------------------------------------------------------
+             * go through the spectral sinfo_vector
+             * determine the maximum pixel value in the spectral sinfo_vector
+             */
+            maxval = -FLT_MAX ;
+            position = -INT32_MAX ;
+            for ( k = 0 ; k < m ; k++ )
+            {
+                xdat[k] = k ;
+                wdat[k] = 1.0 ;
+                if ( line -> data[k] >= maxval )
+                {
+                    maxval = line -> data[k] ;
+                    position = k ;
+                }
+            }
+
+            /* set initial values for the fitting routine */
+            xdim     = XDIM ;
+            ndat     = line -> n_elements ;
+            numpar   = MAXPAR ;
+            tol      = TOL ;
+            lab      = LAB ;
+            its      = ITS ;
+            (*par) -> fit_par[1] = fwhm ;
+            (*par) -> fit_par[2] = (float) position ;
+            (*par) -> fit_par[3] = (float) (line -> data[0] + 
+                                    line -> data[line->n_elements - 1]) / 2.0 ;
+            (*par) -> fit_par[0]  = maxval - ((*par) -> fit_par[3]) ;
+
+
+            /* exclude negative peaks and low signal cases */
+            if ( (*par) -> fit_par[0] < minDiff )
+            {
+                sinfo_msg_warning ("sorry, signal of line too low to fit "
+                                   "in row: %d in slitlet %d\n", row, i) ;
+                sinfo_new_destroy_vector(line) ;
+                cpl_free(xdat) ;
+                cpl_free(wdat) ;
+                cpl_free(mpar) ;
+                sinfo_new_destroy_fit_params(&par) ;
+                continue ;
+            }
+
+            for ( k = 0 ; k < MAXPAR ; k++ )
+            {
+                (*par) -> derv_par[k] = 0.0 ;
+                mpar[k] = 1 ;
+            }
+            /* finally, do the least square fit using a sinfo_gaussian */
+            if ( 0 > ( iters = sinfo_new_lsqfit_c(xdat, &xdim, 
+                                                  line -> data, wdat, 
+                                                  &ndat, (*par) -> fit_par,
+                                                  (*par) -> derv_par, mpar, 
+                                                  &numpar, &tol, 
+                                                  &its, &lab )) )
+            {
+          /*
+               cpl_msg_debug ("sinfo_calibrate_ns_test:",
+                              "sinfo_lsqfit_c: least squares fit failed,"
+                              " error no.: %d in row: %d in slitlet %d\n", 
+                              iters, row, i) ;
+          */
+                sinfo_new_destroy_vector(line) ;
+                cpl_free(xdat) ;
+                cpl_free(wdat) ;
+                cpl_free(mpar) ;
+                sinfo_new_destroy_fit_params(&par) ;
+                continue ;
+            }
+
+            /* check for negative fit results */
+            if ( (*par) -> fit_par[0] <= 0. || (*par) -> fit_par[1] <= 0. ||
+                 (*par) -> fit_par[2] < 0. )
+            {
+                sinfo_msg_warning ("negative parameters as fit result, not "
+                                   "used! in row %d in slitlet %d", row, i) ;
+                sinfo_new_destroy_vector(line) ;
+                cpl_free(xdat) ;
+                cpl_free(wdat) ;
+                cpl_free(mpar) ;
+                sinfo_new_destroy_fit_params(&par) ;
+                continue ;
+            }
+
+            /* correct the fitted position for the given row of the line 
+               in image coordinates */
+            (*par) -> fit_par[2] =  (float) (found_clean[i] - halfWidth) + 
+                                    (*par) -> fit_par[2] ;
+            x_position[counter] = (*par) -> fit_par[2] ;
+            counter ++ ;
+
+            /* free memory */
+            sinfo_new_destroy_fit_params(&par) ;
+            sinfo_new_destroy_vector ( line ) ;
+            cpl_free ( xdat ) ;
+            cpl_free ( wdat ) ;
+            cpl_free ( mpar ) ;
+        }
+        if (zeroindicator == 1)
+        {
+            sinfo_msg_debug ("bad pixel in fitting box in row: %d\n", row) ;
+            continue ;
+        }
+
+        if ( counter != n_slitlets )
+        {
+            sinfo_msg_warning("wrong number of slitlets found "
+                              "in row: %d", row) ;
+            continue ;
+        }
+        /* store the distances between the sources and the slitlet centers */
+        for ( i = 0 ; i < n_slitlets ; i++ )
+        {
+            distances_buf[row][i] = x_position[i] - (15.5 + 32.*(float)i) ;
+        }
+    }
+
+    /* ----------------------------------------------------------------
+     * go through the rows again and take the mean of the distances, 
+     * throw away the runaways 
+     */
+    for ( i = 0 ; i < n_slitlets ; i++ )
+    {
+        n   = 0 ;
+        sum = 0. ;
+        for ( row = bottom ; row < top ; row++ )
+        {
+            if ( fabs( distances_buf[row][i] ) > devtol || 
+                 isnan(distances_buf[row][i]) )
+            {
+             /*
+          sinfo_msg("dist=%g devtol=%g isan=%d", 
+            distances_buf[row][i],
+            devtol,
+            isnan(distances_buf[row][i]));
+              */              
+                continue ;
+            }
+            sum += distances_buf[row][i] ;
+            n++ ;
+        }
+        if ( n < 2 )
+        {
+            sinfo_msg_error("distances array could not be determined"
+                            " completely!, deviations of distances from"
+                            " devtol too big" ) ;
+            cpl_free(distances) ;
+            return NULL ;
+        }
+        else
+        {
+            distances[i] = sum / (float)n ;
+        }
+    }
+
+    /* now sort the result according to the row sequence in the 
+       reconstructed image*/
+    for ( i = 0 ; i < n_slitlets ; i++ )
+    {
+      if( (row_index=sinfo_sort_slitlets(i)) == -1) {
+	sinfo_msg_error("wrong number of a slitlet\n") ;
+	cpl_free (distances) ;
+	return NULL ;
+      }
+      ret_distances[row_index] = distances[i] ;
+    }
+    cpl_free(distances) ;
+
+    cpl_free(row_buf) ;
+    cpl_free(x_position) ;
+    cpl_free(found);
+    cpl_free(found_clean) ;
+    cpl_free(found_cleanit) ;
+    sinfo_new_destroy_2Dfloatarray(&distances_buf,n_slitlets) ;
+
+
+    return ret_distances ; 
+}
+/**
+   @memo makes a data cube out of a resampled source image this SPIFFI 
+         specific routine takes into account the Spiffi slitlet order on 
+         the detector.
+   
+   @param calibImage:  resampled source image
+   @param distances:   distances of the slitlets from each other
+                                     output of function ns_test
+   @param correct_diff_dist: dummy array with 32 elements
+   @return  # resulting source data cube
+            # correct_diff_dist: differences of the slitlets from
+                                 distance 32 given in the correct
+                                 Spiffi row sequence. The first slitlet
+                                 is the reference, therefore element 
+                                 23 is set 0. 
+
+   @doc  makes a data cube out of a resampled source image this SPIFFI specific
+         routine takes into account the Spiffi slitlet order on the detector.
+         Also shifts the resulting image rows by one pixel if necessary 
+         according to the distances array gained from the north-south test 
+         routine. Can do the same with the bad pixel map image to generate a
+         bad pixel mask cube.
+ */
+
+cpl_image * 
+sinfo_new_make_true_resamp(cpl_image * calibImage, 
+                           cpl_image * wavemap)
+{
+    cpl_image * returnImage ;
+    float edges[33] ;
+    int imsize, kslit,i,j ;
+    int slit_index ;
+    int z, col, recol ;
+    int wlx=0;
+    int wly=0;
+    int clx=0;
+    int cly=0;
+  
+    float* pcdata=NULL;
+    float* pwdata=NULL;
+    float* prdata=NULL;
+
+
+    wlx=cpl_image_get_size_x(wavemap);
+    wly=cpl_image_get_size_y(wavemap);
+    pwdata=cpl_image_get_data_float(wavemap);
+
+    edges[0]=0;
+    j=1;
+    for(i=0;i<wlx-1;i++)
+    {
+        if((pwdata[i]-pwdata[i+1])>0.0025 || (pwdata[i]-pwdata[i+1])<-0.0025)
+    {
+        sinfo_msg_error("wavemap sinfo_edge %d", i+1);
+        edges[j]=i+1;
+        j++;
+    }
+    }
+    edges[32]=2048;
+
+    clx=cpl_image_get_size_x(calibImage);
+    cly=cpl_image_get_size_y(calibImage);
+    pcdata=cpl_image_get_data_float(calibImage);
+ 
+    imsize = clx / N_SLITLETS ;
+
+    /* allocate memory */  
+    returnImage = cpl_image_new(clx,cly,CPL_TYPE_FLOAT);
+    prdata=cpl_image_get_data_float(returnImage);
+    for ( z = 0 ; z < cly ; z++ ) /* go through the z-axis */
+    {
+        for ( col = 0 ; col < clx ; col++ ) /* go through the image columns */
+        prdata[col+z*clx]=ZERO;
+    }
+    
+
+    /* now build the data cube out of the resampled image */
+    for ( z = 0 ; z < cly ; z++ ) /* go through the z-axis */
+    {
+        kslit      = 0 ;
+        slit_index = -1 ;
+        recol      = -1 ;
+        for ( col = 0 ; col < clx ; col++ ) /* go through the image columns */
+        {
+            /*if ( col % imsize == 0 )
+            {*/
+                recol = 0 ;
+                /*kslit = col/imsize ;*/
+        for(i=0;i<32;i++)
+        {
+          if(col>=sinfo_new_nint(edges[i]) && 
+                     col<sinfo_new_nint(edges[i+1]))
+            kslit=i;
+        }
+                /* sort the slitlets in the right spiffi specific way */
+	if( (slit_index=sinfo_sort_slitlets(kslit)) == -1) {
+            sinfo_msg_error("wrong slitlet index: couldn't be a "
+                             "spiffi image,  there must be 32 "
+			    "slitlets!") ;
+	    
+	}
+
+            /*}*/
+
+            /* fill each cube plane with one image row */
+        if((col-sinfo_new_nint(edges[kslit]))>0 && 
+               (col-sinfo_new_nint(edges[kslit]))<imsize-1 )
+                prdata[(col-sinfo_new_nint(edges[kslit]))+
+                       slit_index*imsize+z*clx] = 
+                      pcdata[col+z*clx] ;
+            else
+            prdata[(col-sinfo_new_nint(edges[kslit]))+
+                        slit_index*imsize+z*clx] = ZERO;
+            /*recol++ ;*/
+
+        }
+    }
+    return returnImage ;
+}
+
+/*The old slitlet order*/
+/*switch (kslit)
+                {
+                    case 0:
+                        slit_index = 23 ;
+                        break ;
+                    case 1:
+                        slit_index = 24 ;
+                        break ;
+                    case 2:
+                        slit_index = 22 ;
+                        break ;
+                    case 3:
+                        slit_index = 25 ;
+                        break ;
+                    case 4:
+                        slit_index = 21 ;
+                        break ;
+                    case 5:
+                        slit_index = 26 ;
+                        break ;
+                    case 6:
+                        slit_index = 20 ;
+                        break ;
+                    case 7:
+                        slit_index = 27 ;
+                        break ;
+                    case 8:
+                        slit_index = 19 ;
+                        break ;
+                    case 9:
+                        slit_index = 28 ;
+                        break ;
+                    case 10:
+                        slit_index = 18 ;
+                        break ;
+                    case 11:
+                        slit_index = 29 ;
+                        break ;
+                    case 12:
+                        slit_index = 17 ;
+                        break ;
+                    case 13:
+                        slit_index = 30 ;
+                        break ;
+                    case 14:
+                        slit_index = 16 ;
+                        break ;
+                    case 15:
+                        slit_index = 31 ;
+                        break ;
+                    case 16:
+                        slit_index = 0 ;
+                        break ;
+                    case 17:
+                        slit_index = 15 ;
+                        break ;
+                    case 18:
+                        slit_index = 1 ;
+                        break ;
+                    case 19:
+                        slit_index = 14 ;
+                        break ;
+                    case 20:
+                        slit_index = 2 ;
+                        break ;
+                    case 21:
+                        slit_index = 13 ;
+                        break ;
+                    case 22:
+                        slit_index = 3 ;
+                        break ;
+                    case 23:
+                        slit_index = 12 ;
+                        break ;
+                    case 24:
+                        slit_index = 4 ;
+                        break ;
+                    case 25:
+                        slit_index = 11 ;
+                        break ;
+                    case 26:
+                        slit_index = 5 ;
+                        break ;
+                    case 27:
+                        slit_index = 10 ;
+                        break ;
+                    case 28:
+                        slit_index = 6 ;
+                        break ;
+                    case 29:
+                        slit_index = 9 ;
+                        break ;
+                    case 30:
+                        slit_index = 7 ;
+                        break ;
+                    case 31:
+                        slit_index = 8 ;
+                        break ;
+                    default:
+                        sinfo_msg_error("wrong slitlet index: couldn't "
+                                        "be a spiffi image,  \
+                                 there must be 32 slitlets!\n") ;
+                        cpl_imagelist_delete(returnCube) ;
+                        return NULL ;
+                        break ;
+                }*/
+
+
+/*--------------------------------------------------------------------------*/
+/**@}*/
diff --git a/sinfoni/sinfo_cube_construct.h b/sinfoni/sinfo_cube_construct.h
new file mode 100644
index 0000000..ee03d30
--- /dev/null
+++ b/sinfoni/sinfo_cube_construct.h
@@ -0,0 +1,406 @@
+#ifndef SINFO_CUBE_CONSTRUCT_H
+#define SINFO_CUBE_CONSTRUCT_H
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*******************************************************************************
+* E.S.O. - VLT project
+*
+* "@(#) $Id: sinfo_cube_construct.h,v 1.4 2007/06/06 07:10:45 amodigli Exp $"
+*
+* who       when      what
+* --------  --------  ----------------------------------------------
+* schreib  06/10/00  created
+*/
+
+/************************************************************************
+ * ned_cube_construct.h
+ * routines needed to construct a 3D-data cube
+ *----------------------------------------------------------------------
+ */
+
+/*
+ * header files
+ */
+
+#include "sinfo_new_cube_ops.h"
+
+/*
+ * function prototypes
+ */
+
+/**
+   @name   sinfo_new_convolve_ns_image_by_gauss()
+   @memo convolves a north-south-test image with a Gaussian
+                        with user given integer half width by using the
+                        routine sinfo_function1d_filter_lowpass().
+   @param lineImage  North-south-test image
+   @param hw          kernel half width of the Gaussian response function
+   @result  north-south-test image convolved with a Gaussian
+ */
+
+cpl_image * 
+sinfo_new_convolve_ns_image_by_gauss( cpl_image * lineImage,int hw);
+
+/**
+   @name  sinfo_north_south_test()
+   @memo determines the distances of the slitlets
+   @param ns_image   north-south image
+   @param n_slitlets number of slitlets
+   @param halfWidth  half width of the box in which the lines
+                                    are fit by a sinfo_gaussian
+   @param fwhm       first guess of the full width at half maximum
+   @param minDiff    amplitude threshold for Gaussian: 
+                    below this intensity the fit will not 
+                    be carried through
+   @param estimated_dist estimated average distance of spectra
+   @param devtol     maximal pixel deviation of slitlet distances
+   @result            array of the distances of the slitlets from each other
+*/
+
+float * 
+sinfo_north_south_test( cpl_image * ns_image,
+                          int        n_slitlets,
+                          int        halfWidth,
+                          float      fwhm,
+                          float      minDiff,
+                          float      estimated_dist,
+                          float      devtol,
+              int        top,
+              int        bottom ) ;
+
+
+/**
+   @name     sinfo_new_make_cube()
+   @memo     makes a data cube out of a resampled source image
+   @param    calibImage:  resampled source image
+   @param    distances:   distances of the slitlets from each other
+                          output of function ns_test
+   @param     correct_diff_dist: dummy array with 32 elements
+   @return    resulting source data cube
+   @note      correct_diff_dist: differences of the slitlets from
+                                           distance 32 given in the correct
+                                           Spiffi sequence. The first slitlet
+                                           is the reference, therefore element
+                                           23 is set 0.
+   @doc      makes a data cube out of a resampled source image
+             this SPIFFI specific routine takes into account the
+             Spiffi slitlet order on the detector.
+             Also shifts the resulting image rows by one pixel if
+             necessary according to the distances array gained from
+             the north-south test routine.
+             Can do the same with the bad pixel map image to generate a
+             bad pixel mask cube.
+ */
+
+cpl_imagelist * 
+sinfo_new_make_cube ( cpl_image * calibImage,
+                     float    * distances,
+                     float    * correct_diff_dist ) ;
+
+/**
+   @name sinfo_new_make_cube_spi()
+   @param  calibImage  resampled source image
+   @param  slit_edges  absolute beginning and ending positions of
+                                     slitlet, output of sinfo_fitSlits().
+   @param  shift       sub_pixel shifts referred to the reference slit
+                                     sinfo_edge
+   @result  resulting source data cube
+   @doc     makes a data cube out of a resampled source image
+            this SPIFFI specific routine takes into account the
+            Spiffi slitlet order on the detector.
+            This routine takes fitted slitlet positions into account.
+            Can do the same with the bad pixel map image to generate a
+            bad pixel mask cube.
+*/
+
+cpl_imagelist * 
+sinfo_new_make_cube_spi ( cpl_image *  calibImage,
+                        float    ** slit_edges,
+                        float    *  shift ) ;
+
+
+/**
+   @name   sinfo_new_make_cube_dist()
+   @memo   makes a data cube out of a resampled source image
+   @param  calibImage  resampled source image
+   @param  firstCol    floating point value of the first column of
+                                     the first slitlet in the resampled image,
+                                     determined "by hand"
+   @param  distances   distances of the slitlets from each other
+                                     output of function ns_test
+   @param  shift       dummy array with 32 elements
+   @result              resulting source data cube
+   @note       shift differences of the slitlets from
+                               distance 32 given in the correct
+                               Spiffi row sequence. The first slitlet
+                               is the reference, therefore element
+                               23 is set 0.
+   @doc        makes a data cube out of a resampled source image
+                        this SPIFFI specific routine takes into account the
+                        Spiffi slitlet order on the detector.
+                        Also shifts the resulting image rows by one pixel if
+                        necessary according to the distances array gained from
+                        the north-south test routine.
+                Can do the same with the bad pixel map image to generate a
+                bad pixel mask cube.
+*/
+
+cpl_imagelist * 
+sinfo_new_make_cube_dist ( cpl_image * calibImage,
+                         float      firstCol,
+                         float    * distances,
+                         float    * shift ) ;
+
+
+/**
+   @name   sinfo_new_make_3D_cube_dist()
+   @param  calibImage  resampled source image
+   @param  firstCol    floating point value of the first column of
+                                     the first slitlet in the resampled image,
+                                     determined "by hand"
+   @param  distances   distances of the slitlets from each other
+                                     output of function ns_test
+   @param  shift       dummy array with 32 elements
+   @return resulting source data cube
+   @note   shift differences of the slitlets from
+                               distance 32 given in the correct
+                               Spiffi row sequence. The first slitlet
+                               is the reference, therefore element
+                               23 is set 0.
+   @doc       makes a data cube out of a resampled source image
+                        this 3D specific routine takes into account the
+                        3D slitlet order on the detector.
+                        Also shifts the resulting image rows by one pixel if
+                        necessary according to the distances array gained from
+                        the north-south test routine.
+              Can do the same with the bad pixel map image to generate a
+              bad pixel mask cube.
+*/
+
+cpl_imagelist * 
+sinfo_new_make_3D_cube_dist ( cpl_image * calibImage,
+                           float      firstCol,
+                           float    * distances,
+                           float    * shift ) ;
+
+
+/**
+  @name   sinfo_new_make_3D_cube()
+  @param  calibImage  resampled source image
+  @param  kpixshift   integer pixel shifts of the resulting image
+                                     plane rows.
+  @param  kpixfirst   first valid pixel
+  @result resulting source data cube
+  @doc    makes a data cube out of a resampled source image
+          this MPE 3D specific routine takes into account the
+          3D slitlet order on the detector.
+          Also shifts the resulting image row by an integer pixel shift if
+          necessary according to the input kpixshift array 
+          Can do the same with the bad pixel map image to generate a
+          bad pixel mask cube.
+*/
+
+cpl_imagelist * 
+sinfo_new_make_3D_cube ( cpl_image * calibImage,
+                       int      * kpixshift,
+                       int        kpixfirst ) ;
+
+
+/**
+   @name     sinfo_new_determine_mask_cube()
+   @memo converts resampled bad pixels to real bad pixels in data cubes.
+   @param    sourceMaskCube  bad pixel mask cube generated by using
+                              the bad pixel mask frame (0: bad, 1: good)
+                              and going through the same reduction steps 
+                              as with the observation frame.
+   @param lowLimit        low limit of pixel value (about -0.7)
+   @param highLimit       high limit of bad pixel value (about 0.7)
+   @result resulting bad pixel data cube (bad pixels: 0, good pixels: 1).
+*/
+
+cpl_imagelist * 
+sinfo_new_determine_mask_cube ( cpl_imagelist * sourceMaskCube,
+                              float     lowLimit,
+                              float     highLimit ) ;
+
+
+/**
+   @name     sinfo_new_interpol_cube()
+   @param    sourceCube  reconstructed source cube from sinfo_makeCube
+                                     without fine tuning of rows
+   @param    maskCube    bad pixel mask cube, bad pixel are marked
+                          with 0., good and interpolated pixels with 1.
+                          this maskCube is changed within the routine
+                          if a bad pixel was interpolated.
+   @param    n_neighbors number of neighbors in one spectral direction
+                          with which the bad pixel will be interpolated (7)
+   @param    max_radius  maximal pixel radius within an image plane
+                          inside which valid pixels are searched to
+                          be used for interpolation. If there aren't
+                          found 9 good neighboring pixels within this
+                          radius the loop is left. (5)
+   @result   resulting interpolated data cube.
+             changed maskCube at the positions of the interpolated pixels
+   @doc      Bad pixel interpolation 3D like (saturated pixels exist):
+             interpolates the bad pixels of the source cube by
+             using the nearest neighbors.
+             first it is checked if the bad pixel is interpolatable:
+             it is only interpolatable if the number of good pixels
+             in its spectrum of length 2*n_neighbors+1 exceeds 3 and
+             if there is at least one good pixel on either side of the
+             central pixel.
+             Afterwards good neighboring pixels are searched within the
+             image plane of the bad pixel by using an increasing pixel radius.
+             Good pixels mean, the corresponding spectral pixels of the
+             bad pixel and its spatial neighboring pixel must have
+             at least 2 valid pixel pairs to be able to be used for
+             the interpolation. The search is stopped if 9 valid neighboring
+             pixels are found.
+             Now normalize the found spectral values, collect the valid pixels
+             (there must be at least 18) and take the sinfo_median of the valid
+             pixels with which the bad pixel is replaced.
+*/
+
+cpl_imagelist * 
+sinfo_new_interpol_cube ( cpl_imagelist * sourceCube,
+                         cpl_imagelist * maskCube,
+                         int       n_neighbors,   /* 7 */
+                         int       max_radius ) ; /* 5 */
+
+
+/**
+   @name     sinfo_new_fine_tune_cube()
+   @param    cube  cube, output of sinfo_makeCube
+   @param  correct_diff_dist  differences of the slitlets from
+                              distance 32 given in the correct
+                              Spiffi row sequence. The first slitlet
+                              is the reference, therefore element
+                              23 is set 0.
+                              Output of sinfo_makeCube!
+   @result resulting data cube having the exact row positions
+   @doc    fine tunes each row in the right position according
+           to the distances of the slitlets to each other
+           (output of the north-south test).
+           This means that the rows must be realigned by a
+           fraction of a pixel to accomodate non-integer slit
+           length. The fractional realignment is done by using
+           tanh interpolation.
+           Each row is rescaled so that the total flux is conserved.
+*/
+
+
+cpl_imagelist * 
+sinfo_new_fine_tune_cube( cpl_imagelist * cube,
+                         float   * correct_diff_dist,
+                         int       n_order) ;
+
+
+/**
+   @name   sinfo_new_fine_tune_cube_by_FFT()
+   @param  cube:  cube, output of sinfo_makeCube
+   @param  correct_diff_dist: differences of the slitlets from
+                  distance 32 given in the correct
+                  Spiffi row sequence. The first slitlet
+                  is the reference, therefore element
+                  23 is set 0.
+                  Output of sinfo_makeCube!
+   @param  resulting data cube having the exact row positions
+   @doc    fine tunes each row in the right position according
+                        to the distances of the slitlets to each other
+                        (output of the north-south test).
+                        This means that the rows must be realigned by a
+                        fraction of a pixel to accomodate non-integer slit
+                        length. The fractional realignment is done by using
+                        the FFT algorithm four1() of N.R.
+*/
+
+
+cpl_imagelist * 
+sinfo_new_fine_tune_cube_by_FFT( cpl_imagelist * cube,
+                                float   * correct_diff_dist ) ;
+
+/**
+   @name    sinfo_new_fine_tune_cube_by_spline()
+   @param   cube:  cube, output of sinfo_makeCube
+   @param   correct_diff_dist: differences of the slitlets from
+                        distance 32 given in the correct
+                        Spiffi row sequence. The first slitlet
+                        is the reference, therefore element
+                        23 is set 0.
+                        Output of sinfo_makeCube!
+   @result  resulting data cube having the exact row positions
+   @doc     fine tunes each row in the right position according
+                        to the distances of the slitlets to each other
+                        (output of the north-south test).
+                        This means that the rows must be realigned by a
+                        fraction of a pixel to accomodate non-integer slit
+                        length. The fractional realignment is done by using
+                        the spline interpolation algorithm splint in connection
+                        with the algorithm spline of N.R.
+                        This algorithms assume that each row is a tabulated
+                        function. The first derivatives of the interpolating
+                        function at the first and last point must be given.
+                        These are set higher than 1xe^30, so the routine
+                        sets the corresponding boundary condition for a natural
+                        spline, with zero second derivative on that boundary.
+                        Each row is rescaled so that the total flux is
+                        conserved.
+ */
+
+
+cpl_imagelist * 
+sinfo_new_fine_tune_cube_by_spline ( cpl_imagelist * cube,
+                                 float   * correct_diff_dist ) ;
+
+/**
+   @name  sinfo_new_calibrate_ns_test()
+   @param ns_image:   north-south image
+   @param n_slitlets: number of slitlets
+   @param halfWidth:  half width of the box in which the lines
+                                    are fit by a sinfo_gaussian
+   @param fwhm:       first guess of the full width at half maximum
+   @param minDiff:    minimum amplitude below which the fit
+                                    will not be carried through
+   @param estimated_dist: estimated average distance of spectra
+   @param devtol:     maximal pixel deviation of the distances from
+                                    slitlet center
+   @return      array of the distances of the slitlets from each other
+   @doc determines the distances of the spectra from the center
+                        of the slitlets to be able to find the correct angle of
+                        the north-south entrance slit.
+*/
+
+
+float * 
+sinfo_new_calibrate_ns_test( cpl_image * ns_image,
+                           int        n_slitlets,
+                           int        halfWidth,
+                           float      fwhm,
+                           float      minDiff,
+                           float      estimated_dist,
+                           float      devtol,
+               int        bottom,
+               int        top ) ;
+
+
+cpl_image * 
+sinfo_new_make_true_resamp(cpl_image * calibImage, cpl_image* wavemap);
+
+
+#endif /*!SINFO_CUBE_CONSTRUCT_H*/
diff --git a/sinfoni/sinfo_dark_cfg.c b/sinfoni/sinfo_dark_cfg.c
new file mode 100644
index 0000000..792fca5
--- /dev/null
+++ b/sinfoni/sinfo_dark_cfg.c
@@ -0,0 +1,77 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*---------------------------------------------------------------------------
+   
+   File name     :    sinfo_dark_cfg.c
+   Author     :       Juergen Schreiber
+   Created on    :    February 2002
+   Description    :    configuration handling tools for the generation of
+                        master sinfo_dark frames 
+
+ *--------------------------------------------------------------------------*/
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+/*---------------------------------------------------------------------------
+                                   Includes
+ ---------------------------------------------------------------------------*/
+#include "sinfo_dark_cfg.h"
+/**@{*/
+/**
+ * @defgroup sinfo_dark_cfg Dark manipulation functions
+ *
+ * TBD
+ */
+
+/*---------------------------------------------------------------------------
+                              Function codes
+ ---------------------------------------------------------------------------*/
+/**
+   @name    sinfo_dark_cfg_create()
+   @memo    allocate memory for a dark_config struct
+   @return  pointer to allocated base dark_cfg structure
+   @note    only the main (base) structure is allocated
+ */
+
+dark_config * 
+sinfo_dark_cfg_create(void)
+{
+    return cpl_calloc(1, sizeof(dark_config));
+}
+
+/**
+   @name    sinfo_dark_cfg_destroy()
+   @memo   deallocate all memory associated with a dark_config data structure
+   @param   dark_config to deallocate
+   @return  void
+*/
+
+void sinfo_dark_cfg_destroy(dark_config * cc)
+{
+    if (cc==NULL) return ;
+
+    /* Free main struct */
+    cpl_free(cc);
+
+    return ;
+}
+
+/**@}*/
+
+
diff --git a/sinfoni/sinfo_dark_cfg.h b/sinfoni/sinfo_dark_cfg.h
new file mode 100644
index 0000000..46dbb96
--- /dev/null
+++ b/sinfoni/sinfo_dark_cfg.h
@@ -0,0 +1,106 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*---------------------------------------------------------------------------
+   File name     :    sinfo_dark_cfg.h
+   Author    :    Juergen Schreiber
+   Created on    :    February 2002
+   Description    :    sinfo_dark_cfg.c definitions + handling prototypes
+ ---------------------------------------------------------------------------*/
+#ifndef SINFO_DARK_CFG_H
+#define SINFO_DARK_CFG_H
+/*---------------------------------------------------------------------------
+                                   Includes
+ ---------------------------------------------------------------------------*/
+#include <stdlib.h>
+#include "sinfo_globals.h"
+#include <cpl.h>
+/*---------------------------------------------------------------------------
+                                   Defines
+ ---------------------------------------------------------------------------*/
+/*---------------------------------------------------------------------------
+                                   New types
+ ---------------------------------------------------------------------------*/
+/*
+  master dark frame generation blackboard container
+
+  This structure holds all information related to the master dark 
+  frame generation
+  routine. It is used as a container for the flux of ancillary data,
+  computed values, and algorithm status. Pixel flux is separated from
+  the blackboard.
+  */
+
+typedef struct dark_config {
+/*-------General---------*/
+        char inFile[FILE_NAME_SZ] ;       /* file name of frame list */
+        char ** inFrameList ; /* input averaged, bad pixel corrected, 
+                                 off subtracted, flatfielded, spectral 
+                                 tilt corrected list of frames */
+        int nframes ;         /* number of frames in the list */
+        char outName[FILE_NAME_SZ] ; /* output name of resulting fits 
+                                        data cube */
+
+/*------ CleanMean ------*/
+        /* the fraction [0...1] of rejected low intensity pixels when 
+           taking the average of columns */
+        float lo_reject ;
+        /* the fraction [0...1] of rejected high intensity pixels when 
+           taking the average of columns */
+        float hi_reject ;
+/*------ QCLOG ------*/
+        /* RON */
+        
+  int qc_ron_xmin;
+  int qc_ron_xmax;
+  int qc_ron_ymin;
+  int qc_ron_ymax;
+  int qc_ron_hsize;
+  int qc_ron_nsamp;
+  /* FPN */
+  int qc_fpn_xmin;
+  int qc_fpn_xmax;
+  int qc_fpn_ymin;
+  int qc_fpn_ymax;
+  int qc_fpn_hsize;
+  int qc_fpn_nsamp;
+
+} dark_config ;
+/*---------------------------------------------------------------------------
+                               Function prototypes
+ ---------------------------------------------------------------------------*/
+/**
+   @name    sinfo_dark_cfg_create()
+   @memo    allocate memory for a dark_config struct
+   @return  pointer to allocated base dark_cfg structure
+   @note    only the main (base) structure is allocated
+ */
+
+dark_config * 
+sinfo_dark_cfg_create(void);
+/**
+   @name    sinfo_dark_cfg_destroy()
+   @memo   deallocate all memory associated with a dark_config data structure
+   @param   dark_config to deallocate
+   @return  void
+*/
+void 
+sinfo_dark_cfg_destroy(dark_config * cc);
+ 
+
+#endif
diff --git a/sinfoni/sinfo_dark_config.c b/sinfoni/sinfo_dark_config.c
new file mode 100644
index 0000000..3bb02ad
--- /dev/null
+++ b/sinfoni/sinfo_dark_config.c
@@ -0,0 +1,218 @@
+/* $Id: sinfo_dark_config.c,v 1.5 2012/03/02 08:42:20 amodigli Exp $
+ *
+ * This file is part of the CPL (Common Pipeline Library)
+ * Copyright (C) 2002 European Southern Observatory
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*
+ * $Author: amodigli $
+ * $Date: 2012/03/02 08:42:20 $
+ * $Revision: 1.5 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+ /****************************************************************
+  *   Dark Frames Data Reduction Parameter Initialization        *
+  ****************************************************************/
+#include "sinfo_dark_config.h"
+/**@{*/
+/**
+ * @addtogroup sinfo_dark_cfg Dark manipulation functions
+ *
+ * TBD
+ */
+
+ /**
+  * @brief
+  *   Adds parameters for the spectrum extraction
+  *
+  * @param list Parameter list to which parameters are added.
+  *
+  * @return Nothing.
+  *
+  * TBD
+  */
+
+  /* Dark Frame Data Reduction parameters */
+   
+
+void
+ sinfo_dark_config_add(cpl_parameterlist *list)
+{
+
+  cpl_parameter *p;
+
+  if (!list) {
+    return;
+  }
+
+  /* float 
+     threshold used in the clean mean percentage of rejection used to reject 
+     low and high frame */
+ /* percentage of extreme pixel value to reject when calculating the mean 
+    and stdev */
+  p = cpl_parameter_new_range("sinfoni.dark.low_rejection",
+                  CPL_TYPE_DOUBLE,
+                              "lower rejection",
+                              "sinfoni.dark",
+                              0.1,0.0,1.0);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"dark-lo_rej");
+  cpl_parameterlist_append(list, p);
+
+  /* float 
+     threshold used in the clean mean percentage of rejection used to reject 
+     low and high frame */
+ /* percentage of extreme pixel value to reject when calculating the mean 
+    and stdev */
+
+
+  /* QC LOG */
+  /* RON */
+
+  p = cpl_parameter_new_range("sinfoni.dark.high_rejection",
+                  CPL_TYPE_DOUBLE,
+                              "higher rejection",
+                              "sinfoni.dark",
+                              0.1,0.0,1.0);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"dark-hi_rej");
+  cpl_parameterlist_append(list, p);
+
+
+ 
+  p = cpl_parameter_new_range("sinfoni.dark.qc_ron_xmin",
+                  CPL_TYPE_INT,
+                              "qc_ron_xmin",
+                              "sinfoni.dark",
+                              1,DET_PIX_MIN,DET_PIX_MAX);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"dark-qc_ron_xmin");
+  cpl_parameterlist_append(list, p);
+  
+ 
+  p = cpl_parameter_new_range("sinfoni.dark.qc_ron_xmax",
+                  CPL_TYPE_INT,
+                              "qc_ron_xmax",
+                              "sinfoni.dark",
+                              2048,DET_PIX_MIN,DET_PIX_MAX);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"dark-qc_ron_xmax");
+  cpl_parameterlist_append(list, p);
+
+  p = cpl_parameter_new_range("sinfoni.dark.qc_ron_ymin",
+                  CPL_TYPE_INT,
+                              "qc_ron_ymin",
+                              "sinfoni.dark",
+                              1,DET_PIX_MIN,DET_PIX_MAX);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"dark-qc_ron_ymin");
+  cpl_parameterlist_append(list, p);
+
+
+  p = cpl_parameter_new_range("sinfoni.dark.qc_ron_ymax",
+                  CPL_TYPE_INT,
+                              "qc_ron_ymax",
+                              "sinfoni.dark",
+                              2048,DET_PIX_MIN,DET_PIX_MAX);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"dark-qc_ron_ymax");
+  cpl_parameterlist_append(list, p);
+
+  p = cpl_parameter_new_value("sinfoni.dark.qc_ron_hsize",
+                  CPL_TYPE_INT,
+                              "qc_ron_hsize",
+                              "sinfoni.dark",
+                              4);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"dark-qc_ron_hsize");
+  cpl_parameterlist_append(list, p);
+ 
+  p = cpl_parameter_new_value("sinfoni.dark.qc_ron_nsamp",
+                  CPL_TYPE_INT,
+                              "qc_ron_nsamp",
+                              "sinfoni.dark",
+                              100);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"dark-qc_ron_nsamp");
+  cpl_parameterlist_append(list, p);
+ 
+  /* FPN */
+
+
+ p = cpl_parameter_new_range("sinfoni.dark.qc_fpn_xmin",
+                  CPL_TYPE_INT,
+                              "qc_fpn_xmin",
+                              "sinfoni.dark",
+                              1,DET_PIX_MIN,DET_PIX_MAX);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"dark-qc_fpn_xmin");
+  cpl_parameterlist_append(list, p);
+  
+ 
+  p = cpl_parameter_new_range("sinfoni.dark.qc_fpn_xmax",
+                  CPL_TYPE_INT,
+                              "qc_fpn_xmax",
+                              "sinfoni.dark",
+                              2047,DET_PIX_MIN,DET_PIX_MAX);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"dark-qc_fpn_xmax");
+  cpl_parameterlist_append(list, p);
+
+  p = cpl_parameter_new_range("sinfoni.dark.qc_fpn_ymin",
+                  CPL_TYPE_INT,
+                              "qc_fpn_ymin",
+                              "sinfoni.dark",
+                              1,DET_PIX_MIN,DET_PIX_MAX);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"dark-qc_fpn_ymin");
+  cpl_parameterlist_append(list, p);
+
+
+  p = cpl_parameter_new_range("sinfoni.dark.qc_fpn_ymax",
+                  CPL_TYPE_INT,
+                              "qc_fpn_ymax",
+                              "sinfoni.dark",
+                              2047,DET_PIX_MIN,DET_PIX_MAX);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"dark-qc_fpn_ymax");
+  cpl_parameterlist_append(list, p);
+
+
+
+  p = cpl_parameter_new_value("sinfoni.dark.qc_fpn_hsize",
+                  CPL_TYPE_INT,
+                              "qc_fpn_hsize",
+                              "sinfoni.dark",
+                              2);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"dark-qc_fpn_hsize");
+  cpl_parameterlist_append(list, p);
+ 
+  p = cpl_parameter_new_value("sinfoni.dark.qc_fpn_nsamp",
+                  CPL_TYPE_INT,
+                              "qc_fpn_nsamp",
+                              "sinfoni.dark",
+                              1000);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"dark-qc_fpn_nsamp");
+  cpl_parameterlist_append(list, p);
+
+}
+/**@}*/
diff --git a/sinfoni/sinfo_dark_config.h b/sinfoni/sinfo_dark_config.h
new file mode 100644
index 0000000..cb8dfb9
--- /dev/null
+++ b/sinfoni/sinfo_dark_config.h
@@ -0,0 +1,36 @@
+/* $Id: sinfo_dark_config.h,v 1.1 2006/10/20 08:06:32 amodigli Exp $
+ *
+ * This file is part of the CPL (Common Pipeline Library)
+ * Copyright (C) 2002 European Southern Observatory
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*
+ * $Author: amodigli $
+ * $Date: 2006/10/20 08:06:32 $
+ * $Revision: 1.1 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+ /****************************************************************
+  *   Dark Frames Data Reduction Parameter Initialization        *
+  ****************************************************************/
+#include <cpl.h>    /* defines parlist structure */
+/*
+#include "sinfo_dfs.h"
+*/
+#include "sinfo_globals.h"
+void sinfo_dark_config_add(cpl_parameterlist *list);
+
diff --git a/sinfoni/sinfo_dark_ini.h b/sinfoni/sinfo_dark_ini.h
new file mode 100644
index 0000000..47f390e
--- /dev/null
+++ b/sinfoni/sinfo_dark_ini.h
@@ -0,0 +1,68 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+   
+   File name    :   sinfo_dark_ini.h
+   Author       :    Juergen Schreiber
+   Created on   :    Feb 13, 2002
+   Description  :    ini file handling for SPIFFIs sinfo_dark frame handling
+
+ ---------------------------------------------------------------------------*/
+#ifndef SINFO_DARK_INI_H
+#define SINFO_DARK_INI_H
+/*---------------------------------------------------------------------------
+                                Includes
+---------------------------------------------------------------------------*/
+#include "sinfo_fitshead.h"
+#include "sinfo_dark_cfg.h"
+#include <cpl.h>
+/*----------------------------------------------------------------------------
+                             Function prototypes 
+ ---------------------------------------------------------------------------*/
+/**
+  @name    generateDark_ini_file
+  @memo    Generate a default ini file for the master dark frame generation.
+  @param   ini_name    Name of the file to generate.
+  @param   name_i        Name of the input file.
+  @param   name_o        Name of the output file.
+  @return  int 0 if Ok, -1 otherwise.
+  @doc     This function generates a default ini file for the master dark 
+           frame generation command. The generated file will have the 
+           requested name. If you do not want to provide names for the 
+           input/output/calib files, feed either NULL pointers
+           or character strings starting with (char)0.
+ */
+int 
+generateDark_ini_file(
+        char * ini_name,
+        char * name_i,
+        char * name_o
+);
+/**
+  @name     parse_dark_ini_file
+  @memo     Parse a ini_name.ini file and create a blackboard.
+  @param    ini_name    Name of the ASCII file to parse.
+  @return   1 newly allocated dark_config blackboard structure.
+  @doc      The requested ini file is parsed and a blackboard object is 
+            created, then updated accordingly. Returns NULL in case of error.
+ */
+dark_config * 
+parse_dark_ini_file(char * ini_name) ;
+
+#endif
diff --git a/sinfoni/sinfo_dark_ini_by_cpl.c b/sinfoni/sinfo_dark_ini_by_cpl.c
new file mode 100644
index 0000000..2955a8c
--- /dev/null
+++ b/sinfoni/sinfo_dark_ini_by_cpl.c
@@ -0,0 +1,294 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+   
+   File name    :   sinfo_dark_ini_by_cpl.c
+   Author       :   Andrea Modigliani
+   Created on   :   May 18, 2004
+   Description  :   sinfo_dark cpl input file handling for SPIFFI
+ ---------------------------------------------------------------------------*/
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+/*---------------------------------------------------------------------------
+                                Includes
+ ---------------------------------------------------------------------------*/
+#include <string.h>
+#include "sinfo_dark_ini_by_cpl.h"
+#include "sinfo_raw_types.h"
+#include "sinfo_pro_types.h"
+#include "sinfo_globals.h"
+#include "sinfo_hidden.h"
+#include "sinfo_functions.h"
+/*---------------------------------------------------------------------------
+                    Functions private to this module
+ ---------------------------------------------------------------------------*/
+static void     
+parse_section_frames(dark_config *, cpl_frameset* sof, 
+                     cpl_frameset** raw, int* status);
+static void     
+parse_section_cleanmean(dark_config *, cpl_parameterlist* cpl_cfg);
+static void     
+parse_section_qclog(dark_config * cfg, cpl_parameterlist * cpl_cfg);
+
+void sinfo_detnoise_free(dark_config * cfg);
+
+/**@{*/
+/**
+ * @addtogroup sinfo_dark_cfg Dark manipulation functions
+ *
+ * TBD
+ */
+
+/**
+  @name     sinfo_parse_cpl_input_dark
+  @memo     Parse input frames & parameters and create a blackboard.
+  @param    cpl_cfg pointer to parameterlist
+  @param    sof pointer to input set of frames
+  @param    raw pointer to input set of raw frames
+  @return   1 newly allocated dark_config blackboard structure.
+  @doc
+
+  The requested ini file is parsed and a blackboard object is created, then
+  updated accordingly. Returns NULL in case of error.
+ */
+
+dark_config * 
+sinfo_parse_cpl_input_dark(cpl_parameterlist * cpl_cfg, 
+                           cpl_frameset* sof, 
+                           cpl_frameset** raw)
+{
+ int status=0;
+
+        dark_config   *       cfg ;
+
+        /* Removed check on ini_file */
+        /* Removed load of ini file */
+
+        cfg = sinfo_dark_cfg_create();
+
+        /*
+         * Perform sanity checks, fill up the structure with what was
+         * found in the ini file
+         */
+        parse_section_cleanmean    (cfg, cpl_cfg);
+        parse_section_qclog    (cfg, cpl_cfg); 
+        parse_section_frames       (cfg, sof, raw, &status);
+        if (status > 0) {
+                sinfo_msg_error("parsing cpl input");
+                sinfo_dark_cfg_destroy(cfg);
+                cfg = NULL ;
+                return NULL ;
+        }
+
+        return cfg ;
+}
+
+/**
+  @name     parse_section_frames
+  @memo     Parse input frames and create a blackboard.
+  @param    cfg pointer to dark_config
+  @param    sof pointer to input set of frames
+  @param    raw pointer to input set of raw frames
+  @param    status status of function
+  @return   void
+  */
+
+static void     
+parse_section_frames(dark_config * cfg,
+             cpl_frameset * sof,
+                     cpl_frameset** raw,
+                     int* status)
+{
+
+   int                     i;
+   int                   nraw=0;
+   int                   nraw_good=0;
+   cpl_frame* frame=NULL;
+
+   char spat_res[FILE_NAME_SZ];
+   char lamp_status[FILE_NAME_SZ];
+   char band[FILE_NAME_SZ];
+   int ins_set=0;
+   sinfo_extract_raw_frames_type(sof,raw,RAW_DARK);
+
+   nraw=cpl_frameset_get_size(*raw);
+   if (nraw < 1) {
+      sinfo_msg_error("Too few (%d) raw frames (%s) present in"
+            "frameset!Aborting...",nraw,RAW_DARK);
+          (*status)++;
+          return;
+   }
+
+
+
+   /* Removed: get "general:infile" read it, check input sinfo_matrix */
+   /* Allocate structures to go into the blackboard */
+   cfg->inFrameList     = cpl_malloc(nraw * sizeof(char*));
+
+
+   /* read input frames */
+   for (i=0 ; i<nraw ; i++) {
+      frame = cpl_frameset_get_frame(*raw,i);
+      /* Store file name into framelist */
+      cfg->inFrameList[i]=cpl_strdup(cpl_frame_get_filename(frame));
+      nraw_good++;
+   }
+
+   if(nraw_good<1) {
+     sinfo_msg_error("no good raw frame in input, something wrong!");
+     (*status)++;
+     return;
+   }
+   /* Copy relevant information into the blackboard */
+   cfg->nframes         = nraw ;
+
+   strcpy(cfg -> outName, DARK_OUT_FILENAME);
+  
+
+   frame = cpl_frameset_get_frame(*raw,0);
+   sinfo_get_spatial_res(frame,spat_res);
+ 
+   switch(sinfo_frame_is_on(frame)) 
+     {
+   case 0: 
+      strcpy(lamp_status,"on");
+      break;
+    case 1: 
+      strcpy(lamp_status,"off");
+      break;
+    case -1:
+      strcpy(lamp_status,"undefined");
+      break;
+    default: 
+      strcpy(lamp_status,"undefined");
+      break;
+
+
+     }
+
+   sinfo_get_band(frame,band);
+   sinfo_msg("Spatial resolution: %s lamp status: %s band: %s \n",
+                     spat_res,    lamp_status,    band);
+
+
+   sinfo_get_ins_set(band,&ins_set);
+   return ;
+}
+
+/**
+  @name     parse_section_cleanmean
+  @memo     Parse cleanmean parameters.
+  @param    cfg pointer to dark_config
+  @param    cpl_cfg pointer to input parameters
+  @return   void
+  */
+
+static void     
+parse_section_cleanmean(dark_config * cfg, cpl_parameterlist *   cpl_cfg)
+{
+   cpl_parameter *p;  
+   
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.dark.low_rejection");
+   cfg -> lo_reject = cpl_parameter_get_double(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.dark.high_rejection");
+   cfg -> hi_reject = cpl_parameter_get_double(p);
+
+}
+
+/**
+  @name     parse_section_qclog
+  @memo     Parse qclog parameters.
+  @param    cfg pointer to dark_config
+  @param    cpl_cfg pointer to input parameters
+  @return   void
+  */
+static void     
+parse_section_qclog(dark_config * cfg, cpl_parameterlist *   cpl_cfg)
+{
+   cpl_parameter *p;  
+   
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.dark.qc_ron_xmin");
+   cfg -> qc_ron_xmin = cpl_parameter_get_int(p);
+   
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.dark.qc_ron_xmax");
+   cfg -> qc_ron_xmax = cpl_parameter_get_int(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.dark.qc_ron_ymin");
+   cfg -> qc_ron_ymin = cpl_parameter_get_int(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.dark.qc_ron_ymax");
+   cfg -> qc_ron_ymax = cpl_parameter_get_int(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.dark.qc_ron_hsize");
+   cfg -> qc_ron_hsize = cpl_parameter_get_int(p);
+   
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.dark.qc_ron_nsamp");
+   cfg -> qc_ron_nsamp = cpl_parameter_get_int(p);
+
+
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.dark.qc_fpn_xmin");
+   cfg -> qc_fpn_xmin = cpl_parameter_get_int(p);
+   
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.dark.qc_fpn_xmax");
+   cfg -> qc_fpn_xmax = cpl_parameter_get_int(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.dark.qc_fpn_ymin");
+   cfg -> qc_fpn_ymin = cpl_parameter_get_int(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.dark.qc_fpn_ymax");
+   cfg -> qc_fpn_ymax = cpl_parameter_get_int(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.dark.qc_fpn_hsize");
+   cfg -> qc_fpn_hsize = cpl_parameter_get_int(p);
+   
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.dark.qc_fpn_nsamp");
+   cfg -> qc_fpn_nsamp = cpl_parameter_get_int(p);
+
+   
+}
+
+/**
+ at name sinfo_dark_free
+ at memo deallocates dark_config structure
+ at param cfg pointer to dark_config structure
+ at return void
+*/
+void
+sinfo_dark_free(dark_config ** cfg)
+{  
+  int i=0;
+ 
+  if((*cfg) != NULL) {
+    for(i=0;i<(*cfg)->nframes;i++) {
+      if((*cfg)->inFrameList[i] != NULL) {
+    cpl_free((*cfg)->inFrameList[i]);
+    (*cfg)->inFrameList[i]=NULL;
+      }
+    }
+    cpl_free((*cfg)->inFrameList);
+    (*cfg)->inFrameList=NULL;
+    sinfo_dark_cfg_destroy((*cfg));
+    *cfg = NULL;
+  }
+  return;
+
+}
diff --git a/sinfoni/sinfo_dark_ini_by_cpl.h b/sinfoni/sinfo_dark_ini_by_cpl.h
new file mode 100644
index 0000000..eb7b706
--- /dev/null
+++ b/sinfoni/sinfo_dark_ini_by_cpl.h
@@ -0,0 +1,65 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+   
+   File name    :   sinfo_dark_ini_by_cpl.h
+   Author       :   Andrea Modigliani
+   Created on   :   May 18, 2004
+   Description  :   cpl input file handling for SINFONI 
+                    dark frame handling
+
+ ---------------------------------------------------------------------------*/
+#ifndef SINFO_DARK_INI_BY_CPL_H
+#define SINFO_DARK_INI_BY_CPL_H
+/*---------------------------------------------------------------------------
+                                Includes
+---------------------------------------------------------------------------*/
+#include <cpl.h>
+#include "sinfo_msg.h"
+#include "sinfo_dark_cfg.h"
+/*----------------------------------------------------------------------------
+                             Function prototypes 
+ ---------------------------------------------------------------------------*/
+/**
+  @name     sinfo_parse_cpl_input_dark
+  @memo     Parse input frames & parameters and create a blackboard.
+  @param    cpl_cfg pointer to parameterlist
+  @param    sof pointer to input set of frames
+  @param    raw pointer to input set of raw frames
+  @return   1 newly allocated dark_config blackboard structure.
+  @doc
+
+  The requested ini file is parsed and a blackboard object is created, then
+  updated accordingly. Returns NULL in case of error.
+ */
+dark_config * 
+sinfo_parse_cpl_input_dark(cpl_parameterlist * cpl_cfg, 
+                           cpl_frameset* sof, 
+               cpl_frameset** raw);
+
+/**
+ at name sinfo_dark_free
+ at memo deallocates dark_config structure
+ at param cfg pointer to dark_config structure
+ at return void
+*/
+void 
+sinfo_dark_free(dark_config ** cfg);
+
+#endif
diff --git a/sinfoni/sinfo_define_opt.h b/sinfoni/sinfo_define_opt.h
new file mode 100644
index 0000000..d631608
--- /dev/null
+++ b/sinfoni/sinfo_define_opt.h
@@ -0,0 +1,29 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+#ifndef SINFO_DEFINE_OPT_H
+#define SINFO_DEFINE_OPT_H
+#define OPT_FILE        1001
+#define OPT_GENERATE            1002
+#define OPT_RB            1003
+#define OPT_SORT        1004
+#define OPT_IN            2000
+#define OPT_OUT            2001
+#define OPT_CALIB        2002
+#define OPT_CIN         2003
+#endif
diff --git a/sinfoni/sinfo_detlin.c b/sinfoni/sinfo_detlin.c
new file mode 100644
index 0000000..538f4d7
--- /dev/null
+++ b/sinfoni/sinfo_detlin.c
@@ -0,0 +1,1217 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*******************************************************************************
+* E.S.O. - VLT project
+*
+*
+*
+* who       when      what
+* --------  --------  ----------------------------------------------
+* amodigli  18/04/02  created
+*/
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+#define POSIX_SOURCE 1
+#include "sinfo_vltPort.h"
+
+/*
+ * System Headers
+ */
+
+/*
+ * Local Headers
+ */
+
+#include "sinfo_detlin.h"
+#include "sinfo_recipes.h"
+#include "sinfo_fit_curve.h"
+
+/**@{*/
+/**
+ * @defgroup sinfo_detlin Detector Linearity Determination Functions
+ *
+ * TBD
+ */
+
+/*----------------------------------------------------------------------------
+ *                            Function codes
+ *--------------------------------------------------------------------------*/
+
+/**
+ at brief this routine fits polynomials along the z-axis of a data cube and 
+       stores the resulting coefficients in a data cube.
+   
+   @param flatStack: flats with in/decreasing intensity
+                                   stacked in a data cube
+   @param order:     order of the fit polynomial
+   @return  data cube containing the fit result. the first polynomial 
+            coefficients in the first plane and so on. 
+
+   @doc this routine fits polynomials along the z-axis of a data cube and 
+        stores the resulting coefficients in a data cube. The eclipse routine 
+        sinfo_fit_1d_poly() is used for polynomial fitting The input is 
+        assumed to be a cube containing flatfield frames of different 
+        intensities (usually increasing or decreasing).
+        for each pixel position on the detector, a curve is plotted
+        of the pixel intensity in each plane against the clean mean
+        intensity of the plane. Then a polynomial of user defined
+        order is fitted to the curves.
+ */
+
+cpl_imagelist * 
+sinfo_new_fit_intensity_course(cpl_imagelist * flatStack,
+                              int       order,
+                              float     loReject,
+                              float     hiReject )
+{
+    cpl_imagelist * ret_iml ;
+    dpoint  * points ;
+    int       i, z ;
+    double * coeffs ;
+    Stats  ** stats=NULL ;
+    int sx;
+    int sy;
+    int sz;
+    float* psrcdata;
+    float* presdata;
+    cpl_image* img_tmp=NULL;
+    sx=cpl_image_get_size_x(cpl_imagelist_get(flatStack,0));
+    sy=cpl_image_get_size_y(cpl_imagelist_get(flatStack,0));
+    sz=cpl_imagelist_get_size(flatStack);
+
+    stats=(Stats**) cpl_calloc(sz,sizeof(Stats*)) ;
+  
+    if ( NULL == flatStack )
+    {
+        sinfo_msg_error("no input cube given!") ;
+        return NULL ;
+    }
+    if ( order <= 0 )
+    {
+        sinfo_msg_error("wrong order of polynomial given!") ;
+        return NULL ;
+    }
+    /* allocate memory for returned cube */
+    ret_iml = cpl_imagelist_new();
+    for ( z = 0 ; z < order+1 ; z++ )
+    {
+      img_tmp=cpl_image_new(sx,sy,CPL_TYPE_FLOAT);
+      cpl_imagelist_set(ret_iml,img_tmp,z);
+    }
+
+    for ( z = 0 ; z < sz ; z++ )
+    {
+      stats[z]=
+       sinfo_new_image_stats_on_rectangle(cpl_imagelist_get(flatStack,z), 
+                                                loReject, 
+                                                hiReject, 
+                                                0, 
+                                                0, 
+                                                sx-1, 
+                                                sy-1) ;
+        if ( stats[z] == NULL )
+        {
+            sinfo_msg_error("could not compute image statistics "
+                            "in plane: %d", z) ;
+            cpl_imagelist_delete(ret_iml) ;
+            return NULL ;
+        }
+    }
+
+    /* go through the image plane and store the spectra in a double 
+       points data structure */
+    
+    for ( i = 0 ; i < sx*sy ; i++ )
+    {
+      /* allocate dpoint object */
+      if ( NULL == ( points = (dpoint*) cpl_calloc(sz, sizeof(dpoint)) ) )
+    {
+      sinfo_msg_error("could not allocate memory!\n") ;
+      cpl_imagelist_delete(ret_iml) ;
+      return NULL ;
+    }
+
+      for ( z = 0 ; z < sz ; z++ )
+      {
+      if(NULL==(img_tmp = cpl_imagelist_get(flatStack,z))) {
+        sinfo_msg_error("could not get image!");
+          cpl_imagelist_delete(ret_iml) ;
+            return NULL;
+      } else {
+        psrcdata=cpl_image_get_data_float(img_tmp);
+        points[z].x = (double)stats[z]->cleanmean ;
+        points[z].y = (double)psrcdata[i] ;
+      }
+      }
+
+
+      if ( NULL == ( coeffs = sinfo_fit_1d_poly(order, points, sz, NULL) ) )
+      {
+      sinfo_msg_warning("could not fit spectrum of pixel: %d\n", i) ;
+      for ( z = 0 ; z < order+1 ; z++ )
+        {
+          presdata=cpl_image_get_data_float(cpl_imagelist_get(ret_iml,z));
+          presdata[i] = ZERO ;
+        }
+      }
+      else
+      {
+    for ( z = 0 ; z < order+1 ; z++ )
+        {
+          if(NULL==(img_tmp = cpl_imagelist_get(ret_iml,z))) {
+        sinfo_msg_error("could not get image!");
+        cpl_imagelist_delete(ret_iml) ;
+        return NULL;
+          } else {
+        presdata=cpl_image_get_data_float(img_tmp);
+        presdata[i] = coeffs[z] ;
+          }
+    }
+      }
+      cpl_free(points) ;
+      cpl_free(coeffs) ;
+    }
+
+    for ( z = 0 ; z < sz ; z++ )
+    {
+        cpl_free (stats[z]) ;
+    }
+    cpl_free(stats);
+    return ret_iml ;
+}
+
+
+/**
+ at brief search bad pixels
+   
+   @param coeffs: fitted polynomial coefficients stored in a cube
+   @param threshSigmaFactor: factor of determined standard deviation
+                             of zero and slope coefficients to determine the 
+                             threshold for good or bad pixels
+   @param nonlinearThresh:   absolute threshold value of the found
+                             non-linear polynomial coefficients beyond
+                             which the pixels are declared as bad.
+   @param loReject, 
+   @param hiReject: percentage (0...100) of extreme pixel 
+                    values that is not considered for image
+                                            statistics
+   @return        Bad pixel mask image (1: good pixel, 0: bad pixel). 
+
+
+   Job  this routine searches for static bad pixel positions
+        by searching the fitted first and second polynomial coefficients 
+        of each pixel response (linear) for outliers.
+        Pixel with high non-linear response are also declared as bad.
+ */
+
+cpl_image * sinfo_new_search_bad_pixels( cpl_imagelist *  coeffs,
+                            double     threshSigmaFactor,
+                            double     nonlinearThresh,
+                            float      loReject,
+                            float      hiReject )
+{
+     int i, z ;
+    Stats * stats ;
+    int sx=0;
+    int sy=0;
+    int sz=0;
+
+    cpl_image * img_res ;
+    cpl_image* img_src=NULL;
+
+    float* psrcdata=NULL;
+    float* presdata=NULL;
+
+    if ( NULL == coeffs )
+    {
+        sinfo_msg_error("no input cube given!\n") ;
+        return NULL ;
+    }
+    if ( threshSigmaFactor <= 0. )
+    {
+        sinfo_msg_error("wrong sigma factor given, 0 or negativ!\n") ;
+        return NULL ;
+    }
+    if ( nonlinearThresh <= 0. )
+    {
+        sinfo_msg_error("wrong nonlinear threshold value given, "
+                        "0 or negative!") ;
+        return NULL ;
+    }
+
+    sz=cpl_imagelist_get_size(coeffs);
+
+    if ( sz <= 1 )
+    {
+        sinfo_msg_error("no cube given, only one plane!\n") ;
+        return NULL ;
+    }
+
+    /* Note that we refer to image #1! */
+    img_src=cpl_imagelist_get(coeffs,1);
+    sx=cpl_image_get_size_x(img_src);
+    sy=cpl_image_get_size_y(img_src);
+
+    /* allocate memory for return image */
+    if ( NULL == (img_res = cpl_image_new(sx, sy,CPL_TYPE_FLOAT)) )
+    {
+        sinfo_msg_error("could not allocate memory!\n") ;
+        return NULL ;
+    }
+
+
+    /* first test the sensitivity deviations of each pixel */
+    /* determine the clean mean and clean standard deviation 
+       in the whole image frame */
+   
+    stats = sinfo_new_image_stats_on_rectangle(img_src, 
+                                               loReject, 
+                                               hiReject, 0, 0, 
+                                               sx-1, sy-1) ;
+    if ( NULL == stats )
+    {
+        sinfo_msg_error("could not determine image statistics!\n") ;
+        cpl_image_delete(img_res) ;
+        return NULL ;
+    }
+    
+
+    psrcdata=cpl_image_get_data_float(img_src);
+    presdata=cpl_image_get_data_float(img_res);
+    for ( i = 0 ; i < (int) sx*sy ; i++ )
+    {
+
+        if ( isnan(psrcdata[i]) )
+        {
+            presdata[i] = 0. ;
+        }
+        else if ( stats->cleanmean - psrcdata[i] > 
+                  threshSigmaFactor*stats->cleanstdev )
+        {
+            presdata[i] = 0. ;
+        }
+        else
+        {
+           presdata[i] = 1. ;
+        }
+    }
+    cpl_free(stats) ;
+
+
+    /* -----------------------------------------------------
+     * now test additionally the non-linearity if available. 
+     * if a strong non-linearity occurs for pixels which are 
+     * declared "good" so far (normal linear coefficients)
+     * these pixels will be declared bad.    
+     */
+    if (sz > 1) 
+    {
+        for ( z = 2 ; z < sz ; z++ )
+        {
+      img_src=cpl_imagelist_get(coeffs,z);
+          sx=cpl_image_get_size_x(img_src);
+          sy=cpl_image_get_size_y(img_src);
+
+          psrcdata=cpl_image_get_data_float(img_src);
+            stats = sinfo_new_image_stats_on_rectangle(img_src, loReject, 
+                                                 hiReject, 0, 0, sx-1, sy-1) ;
+            if ( NULL == stats )
+            {
+                sinfo_msg_error("could not determine image statistics!\n") ;
+                cpl_image_delete(img_res) ;
+                return NULL ;
+            }
+          presdata=cpl_image_get_data_float(img_res);
+            for ( i = 0 ; i < (int) sx*sy ; i++ )
+            {
+                if ( presdata[i] == 1. && 
+                     (fabs(psrcdata[i] - stats->cleanmean) > 
+                                     threshSigmaFactor*stats->cleanstdev ||
+              fabs(psrcdata[i]) > nonlinearThresh ) ) 
+                {
+                    presdata[i] = 0. ;
+                }
+            }
+            cpl_free(stats) ;
+        }
+    }
+
+    return img_res ;
+}
+
+
+
+
+/**
+ at brief search bad pixels
+  
+   @param darks: sequence of darks (NDIT = 1) 
+                 stored in a cube, at least 10 to get good statistics
+   @param threshSigmaFactor: factor to determined standard deviation
+                             in each pixel to determine the threshold
+                             beyond which a pixel is declared as bad. 
+   @param loReject, 
+   @param hiReject: percentage (0...100) of extreme pixel values that is \
+                    not considered for image statistics
+
+   @return Bad pixel mask image (1: good pixel, 0: bad pixel). 
+
+   Job  this routine searches for static bad pixel positions
+        This is done by building a cube of sinfo_dark frames and examine 
+        the noise variations in each pixel. If big deviations
+        from a clean mean pixel noise occurr, the pixel is declared as bad.
+ */
+
+cpl_image * sinfo_new_search_bad_pixels_via_noise(cpl_imagelist *  darks,
+                                    float      threshSigmaFactor,
+                                    float      loReject,
+                                    float      hiReject )
+{
+    cpl_image * bp_map ;
+    int        z, n, i ;
+    int        lx, ly ;
+    int        row, col ;
+    int        low_n, high_n ;
+    float    * spectrum ;
+    double     pix_sum ;
+    double     sqr_sum ;
+    Stats    * stats ;
+    cpl_image* img_src=NULL;
+
+    float* psrcdata=NULL;
+    float* pbpdata=NULL;
+
+    int lz=0;
+    
+    if ( NULL == darks )
+    {
+        sinfo_msg_error("no input cube given!\n") ;
+        return NULL ;
+    }
+
+    if ( threshSigmaFactor <= 0. )
+    {
+        sinfo_msg_error("factor is smaller or equal zero!\n") ;
+        return NULL ;
+    }
+    if ( loReject < 0. || hiReject < 0. || (loReject + hiReject) >= 100.  )
+    {
+        sinfo_msg_error("wrong reject percentage values!\n") ;
+        return NULL ;
+    }
+
+    lz=cpl_imagelist_get_size(darks);
+    if ( lz < 1 )
+    {
+        sinfo_msg_error("not enough dark frames given for good statistics!") ;
+        return NULL ;
+    }
+    img_src=cpl_imagelist_get(darks,0);
+    
+    lx = cpl_image_get_size_x(img_src) ;
+    ly = cpl_image_get_size_y(img_src) ;
+  
+    low_n  = (int)(loReject/100. *(float)lz) ;
+    high_n = (int)(hiReject/100. *(float)lz) ;
+    if (NULL == (bp_map = cpl_image_new (lx, ly,CPL_TYPE_FLOAT) ) )
+    {
+        sinfo_msg_error("could not allocate new memory!\n") ;
+        return NULL ;
+    }
+    pbpdata=cpl_image_get_data(bp_map);
+    if (NULL == (spectrum = (float*) cpl_calloc(lz, sizeof(float)) ) )
+    {
+        sinfo_msg_error("could not allocate new memory!\n") ;
+        return NULL ;
+    }
+    for ( row = 0 ; row < ly ; row++ ) {
+
+      for ( col = 0 ; col < lx ; col++ ) {
+
+    for ( z = 0 ; z < lz ; z++ ) {
+      img_src=cpl_imagelist_get(darks,z);
+      psrcdata=cpl_image_get_data(img_src);
+      spectrum[z] = psrcdata[col+lx*row] ;
+    }
+    sinfo_pixel_qsort(spectrum, lz) ;
+    n = 0  ;
+    pix_sum = 0.; 
+    sqr_sum = 0.; 
+    for ( i = low_n ; i < lz - high_n ; i++ ) {
+      pix_sum += (double)spectrum[i] ;
+      sqr_sum += ((double)spectrum[i]*(double)spectrum[i]) ;
+      n++ ;
+    }
+        /* compute the noise in each pixel */
+    pix_sum /= (double)n ;
+    sqr_sum /= (double)n ;
+
+        pbpdata[col+lx*row] = (float)sqrt(sqr_sum - pix_sum*pix_sum) ;
+      }
+    }
+    cpl_free(spectrum) ;
+    if ( NULL == (stats = sinfo_new_image_stats_on_rectangle (bp_map, loReject, 
+                                       hiReject, 200, 200, 800, 800) ) )
+    {
+        sinfo_msg_error("could not get image statistics!\n") ;
+        cpl_image_delete (bp_map) ;
+        return NULL ;
+    }
+ 
+
+    /* now build the bad pixel mask */
+    for ( row = 0 ; row < ly ; row++ ) {
+      for ( col = 0 ; col < lx ; col++ ) {
+         if (pbpdata[col+lx*row] >
+             stats->cleanmean+threshSigmaFactor*stats->cleanstdev ||
+             pbpdata[col+lx*row] < 
+             stats->cleanmean-threshSigmaFactor*stats->cleanstdev) 
+       {
+             pbpdata[col+lx*row] = 0. ;
+       }
+           else
+           {
+         pbpdata[col+lx*row] = 1. ;
+           }
+      }
+    }
+    cpl_free (stats) ;
+    return bp_map ;
+}
+
+
+
+/**
+ at brief this routine counts the number of bad pixels
+  
+  @param  bad: bad pixel mask
+  @return number of bad pixels. 
+
+ */
+
+int sinfo_new_count_bad_pixels (cpl_image * bad )
+{
+    int i, n ;
+    int sx=cpl_image_get_size_x(bad);
+    int sy=cpl_image_get_size_y(bad);
+    float* pbpdata=cpl_image_get_data(bad);
+
+    n = 0 ;
+    for ( i = 0 ; i < (int) sx*sy ; i++ )
+    {
+        if ( pbpdata[i] == 0 || isnan(pbpdata[i]) )
+        {
+            n++ ;
+        }
+    }
+    return n ;
+}
+
+
+/**
+ at brief  filter, calculates the absolute distances of the nearest neighbors
+        for an image by using the 8 closest pixels of every pixel.
+   
+   @param image, a threshold parameter
+   @return resulting image
+
+   @doc filter, calculates the absolute distances of the nearest neighbors for 
+        an image by using the 8 closest pixels of every pixel.
+        The values in the output image are determined according
+        to the values of the input parameter.
+        If fmedian = 0: always replace by abs. distances
+        if fmedian < 0: replace by abs. distances 
+        if |median_dist - dist| > -fmedian
+        if fmedian > 0: replace by abs. distances (fmedian as a factor of
+        the square root of the distance itself)
+        if |median_dist - dist| >= fmedian * sqrt ( dist )
+        This can be used to consider photon noise.
+        This considers a dependence of the differences on the
+        pixel values themselves.
+
+
+   @Note it is assumed that most of the 8 nearest neighbor pixels
+         are not bad pixels!
+         blank pixels are not replaced!
+ */
+
+cpl_image * sinfo_new_abs_dist_image(cpl_image * im, float fmedian )
+{
+
+    cpl_image *   image       ;
+    pixelvalue * value       ;
+    pixelvalue   dist      ;
+    pixelvalue   median_dist      ;
+    pixelvalue*   pix_dist=NULL ;
+    int        * position    ;
+    int          nposition   ;
+    int          n, m, i, j ;
+    double       sum, sum2 ;
+    double       stdev ;
+    float* pdata=NULL;
+    int lx=0;
+    int ly=0;
+
+    if ( im == NULL )
+     {
+        sinfo_msg_error ("no image input\n") ;
+        return NULL ;
+    }
+
+    image = cpl_image_duplicate ( im ) ;
+
+    /*----------------------------------------------------------------------
+     * go through all pixels
+     */
+
+    sum = 0. ;
+    sum2 = 0. ;
+    m = 0 ;
+    
+    pdata = cpl_image_get_data(im);
+    lx=cpl_image_get_size_x(im);
+    ly=cpl_image_get_size_y(im);
+    pix_dist=(pixelvalue*)cpl_calloc(lx*ly,sizeof(pixelvalue)) ;
+
+    for ( i = 0 ;  i < (int) lx*ly ; i++ )
+    {
+      /* blank pixels are not replaced */
+      if ( isnan(pdata[i]) )
+        {
+      continue ;
+        }
+
+        /* initialize the buffer variables for the 8 nearest neighbors */
+        value = (pixelvalue * )cpl_calloc ( 8, sizeof ( pixelvalue * ) ) ;
+        position = ( int * ) cpl_calloc ( 8, sizeof ( int * ) ) ;
+
+        /*--------------------------------------------------------------------
+         * determine the pixel position of the 8 nearest neighbors
+         */
+
+        position[0] = i + lx - 1 ; /* upper left  */
+        position[1] = i + lx     ; /* upper       */
+        position[2] = i + lx + 1 ; /* upper right */
+        position[3] = i + 1      ; /* right       */
+        position[4] = i - lx + 1 ; /* lower right */
+        position[5] = i - lx     ; /* lower       */
+        position[6] = i - lx - 1 ; /* lower left  */
+        position[7] = i - 1      ; /* left        */
+
+        /*--------------------------------------------------------------------
+         * determine the positions of the image margins, top positions are 
+         * changed to low positions and vice versa. Right positions are 
+         * changed to left positions and vice versa.
+         */
+
+        if ( i >= 0 && i < lx )    /* bottom line */
+        {
+            position[4] += 2 * lx ;
+            position[5] += 2 * lx ;
+            position[6] += 2 * lx ;
+        }
+        else if ( i >= ((int) lx*ly - lx ) && i < (int) lx*ly ) /* top line */
+        {
+            position[0] -= 2 * lx ;
+            position[1] -= 2 * lx ;
+            position[2] -= 2 * lx ;
+        }
+        else if ( i % lx == 0 )    /* left side */
+        {
+            position[0] += 2 ;
+            position[6] += 2 ;
+            position[7] += 2 ;
+        }
+        else if ( i % lx == lx - 1 )    /* right side */
+        {
+            position[2] -= 2 ;
+            position[3] -= 2 ;
+            position[4] -= 2 ;
+        }
+
+        /* -------------------------------------------------------------------
+         * read the pixel values of the neighboring pixels,
+         * blanks are not considered
+         */
+
+        nposition = 8 ;
+        n = 0 ;
+        for ( j = 0 ; j < nposition ; j ++ )
+        {
+            if ( !isnan(pdata[position[j]]) )
+            {
+                value[n] = pdata[position[j]] ;
+                n ++ ;
+            }
+        }
+        nposition = n ;
+
+        if ( nposition <= 1 )  /* almost all neighbors are blank */
+        {
+            pdata[i] = ZERO ;
+            cpl_free(value) ;
+            cpl_free(position) ;
+            continue ;
+        }
+
+        /* determine the absolute distances */
+        dist = 0. ;
+        for ( n = 0 ; n < nposition ; n++ )
+        {
+            dist += (pdata[i] - value[n])*(pdata[i] - value[n]) ;    
+        }
+        dist = sqrt(dist)/(float) nposition ;
+        pix_dist[m] = dist ;
+        m++ ;
+        sum += (double)dist ;
+        sum2 += (double)dist * (double)dist ;
+        cpl_free(value) ;
+        cpl_free(position) ;
+    }
+    sum /= (double)m ;
+    sum2 /= (double)m ;
+    stdev = sqrt(sum2 - sum*sum) ;
+
+    median_dist = sinfo_new_median(pix_dist, m) ;
+
+    for ( i = 0 ; i < (int) lx*ly ; i++ )
+    {
+        /* blank pixels are not replaced */
+        if ( isnan(pdata[i]) )
+        {
+            continue ;
+        }
+
+        /* initialize the buffer variables for the 8 nearest neighbors */
+        value = (pixelvalue * )cpl_calloc ( 8, sizeof ( pixelvalue * ) ) ;
+        position = ( int * ) cpl_calloc ( 8, sizeof ( int * ) ) ;
+
+        /*-------------------------------------------------------------------
+         * determine the pixel position of the 8 nearest neighbors
+         */
+
+        position[0] = i + lx - 1 ; /* upper left  */
+        position[1] = i + lx     ; /* upper       */
+        position[2] = i + lx + 1 ; /* upper right */
+        position[3] = i + 1      ; /* right       */
+        position[4] = i - lx + 1 ; /* lower right */
+        position[5] = i - lx     ; /* lower       */
+        position[6] = i - lx - 1 ; /* lower left  */
+        position[7] = i - 1      ; /* left        */
+
+        /*-------------------------------------------------------------
+         * determine the positions of the image margins, top positions are 
+         * changed to low positions and vice versa. Right positions are 
+         * changed to left positions and vice versa.
+         */
+
+        if ( i >= 0 && i < lx )    /* bottom line */
+        {
+            position[4] += 2 * lx ;
+            position[5] += 2 * lx ;
+            position[6] += 2 * lx ;
+        }
+        else if ( i >= ((int) lx*ly - lx ) && i < (int) lx*ly ) /* top line */
+        {
+            position[0] -= 2 * lx ;
+            position[1] -= 2 * lx ;
+            position[2] -= 2 * lx ;
+        }
+        else if ( i % lx == 0 )    /* left side */
+        {
+            position[0] += 2 ;
+            position[6] += 2 ;
+            position[7] += 2 ;
+        }
+        else if ( i % lx == lx - 1 )    /* right side */
+        {
+            position[2] -= 2 ;
+            position[3] -= 2 ;
+            position[4] -= 2 ;
+        }
+
+        /* -------------------------------------------------------------------
+         * read the pixel values of the neighboring pixels,
+         * blanks are not considered
+         */
+
+        nposition = 8 ;
+        n = 0 ;
+        for ( j = 0 ; j < nposition ; j ++ )
+        {
+            if ( !isnan(pdata[position[j]]) )
+            {
+                value[n] = pdata[position[j]] ;
+                n ++ ;
+            }
+        }
+        nposition = n ;
+
+        if ( nposition <= 1 )  /* almost all neighbors are blank */
+        {
+            pdata[i] = ZERO ;
+            cpl_free(value) ;
+            cpl_free(position) ;
+            continue ;
+        }
+
+        /* determine the absolute distances */
+        dist = 0. ;
+        for ( n = 0 ; n < nposition ; n++ )
+        {
+            dist += (pdata[i] - value[n])*(pdata[i] - value[n]) ;    
+        }
+        dist = sqrt(dist)/(float) nposition ;
+
+
+        /* -----------------------------------------------------------------
+         * replace the pixel value by the sinfo_median on conditions:
+         * fmedian = 0: always replace with sinfo_median.
+         * fmedian < 0: interpret as absolute condition:
+         *              if |pixel - sinfo_median| > -fmedian
+         *              replace with sinfo_median.
+         * fmedian > 0: replace by sinfo_median (fmedian as a factor of
+         *              the square root of the sinfo_median itself)
+         *              if |pixel - median| >= fmedian * sqrt ( median )
+         *              considers a dependence on the pixel value.
+         *              This can be used to consider photon noise.
+         */
+
+        if ( fmedian == 0 )
+        {
+            pdata[i] = dist ;
+        }
+        else if ( fmedian < 0 &&
+                  fabs ( median_dist - dist ) >= -fmedian*stdev )
+        {
+            pdata[i] = dist ;
+        }
+        else if ( fmedian > 0 &&
+                  fabs ( median_dist - dist ) >= 
+                  fmedian*stdev * sqrt(fabs(dist)) )
+        {
+            pdata[i] = dist ;
+        }
+        else
+        {
+            cpl_free (value) ;
+            cpl_free (position) ;
+            continue ;
+        }
+
+        cpl_free (value) ;
+        cpl_free (position) ;
+    }
+    cpl_free(pix_dist);
+    return image ;
+}
+
+
+
+
+
+
+/*----------------------------------------------------------------------------
+   Function:       sinfo_new_local_median_image()
+   In      :       im: input image
+                   fmedian:  a factor to the local standard deviation
+                   loReject, hiReject: fraction of rejected values to determine
+                                       a clean standard deviation
+                   half_box_size: integer half size of the running box to 
+                              determine the local clean standard deviation
+   Out     :       resulting image
+   Job     :       filter, calculates the local stdev in a moving box
+                   Then it calculates the difference of the pixel to the median
+                   of the nearest neighbors
+                   by using the 8 closest pixels of every pixel.
+                   The values in the output image are determined according
+                   to the values of the input parameter.
+                   If fmedian = 0: always replace by median
+                   if fmedian < 0: replace median if |median_dist - dist| >
+                                   fmedian * stdev 
+                   if fmedian > 0: replace by median (fmedian as a factor of
+                                   the square root of the median itself)
+                                   if |pixel - median| >= fmedian*sqrt(median)
+                   This can be used to consider photon noise.
+                   This considers a dependence of the differences on the
+                   pixel values themselves.
+   Notice       :  it is assumed that most of the 8 nearest neighbor pixels
+                   are not bad pixels!
+                   blank pixels are not replaced!
+ ---------------------------------------------------------------------------*/
+
+cpl_image * sinfo_new_local_median_image( cpl_image * im, 
+                             float fmedian, 
+                             float loReject,
+                             float hiReject,
+                             int half_box_size )
+{
+    cpl_image *   image       ;
+    pixelvalue * value       ;
+    pixelvalue   median      ;
+    int        * position    ;
+    int          nposition   ;
+    int          n, i, j ;
+    int          llx, lly, urx, ury ;
+    Stats *      stats ;
+    int lx=0;
+    int ly=0;
+    float* pidata=NULL;
+    float* podata=NULL;
+
+    if ( im == NULL )
+    {
+        sinfo_msg_error ("no image input") ;
+        return NULL ;
+    }
+    if ( half_box_size < 0 )
+    {
+        sinfo_msg_error ("negativ box_size given") ;
+        return NULL ;
+    }
+
+    image = cpl_image_duplicate ( im ) ;
+    lx=cpl_image_get_size_x(im);
+    ly=cpl_image_get_size_y(im);
+    pidata=cpl_image_get_data(im);
+    podata=cpl_image_get_data(image);
+    /*----------------------------------------------------------------------
+     * go through all pixels
+     */
+
+    for ( i = 0 ; i < (int) lx*ly ; i++ )
+    {
+        /* blank pixels are not replaced */
+        if ( isnan(pidata[i]) )
+        {
+            continue ;
+        }
+
+        /* compute the image statistics in the box area */
+        llx = i%lx - half_box_size ; 
+        if ( llx < 0 ) llx = 0 ;
+        lly = i%ly - half_box_size ;
+        if ( lly < 0 ) lly = 0 ;
+        urx = i%lx + half_box_size ; 
+        if ( urx >= lx ) urx = lx - 1 ;
+        ury = i%ly + half_box_size ;
+        if ( ury >= ly ) ury = ly - 1 ;
+
+        if ( NULL == (stats = sinfo_new_image_stats_on_rectangle (im, loReject,
+                               hiReject, llx, lly, urx, ury)) ) 
+        {
+            sinfo_msg_warning("could not determine image statistics ");
+            sinfo_msg_warning("in pixel %d", i) ;
+            continue ;
+        }
+
+        /* initialize the buffer variables for the 8 nearest neighbors */
+        value = (pixelvalue * )cpl_calloc ( 8, sizeof ( pixelvalue * ) ) ;
+        position = ( int * ) cpl_calloc ( 8, sizeof ( int * ) ) ;
+
+        /*----------------------------------------------------------------------
+         * determine the pixel position of the 8 nearest neighbors
+         */
+
+        position[0] = i + lx - 1 ; /* upper left  */
+        position[1] = i + lx     ; /* upper       */
+        position[2] = i + lx + 1 ; /* upper right */
+        position[3] = i + 1            ; /* right       */
+        position[4] = i - lx + 1 ; /* lower right */
+        position[5] = i - lx     ; /* lower       */
+        position[6] = i - lx - 1 ; /* lower left  */
+        position[7] = i - 1            ; /* left        */
+
+        /*---------------------------------------------------------------------
+         * determine the positions of the image margins, top positions are 
+         * changed to low positions and vice versa. Right positions are 
+         * changed to left positions and vice versa.
+         */
+
+        if ( i >= 0 && i < lx )    /* bottom line */
+        {
+            position[4] += 2 * lx ;
+            position[5] += 2 * lx ;
+            position[6] += 2 * lx ;
+        }
+        else if ( i >= ((int) lx*ly - lx ) && i < (int) lx*ly ) /* top line */
+        {
+            position[0] -= 2 * lx ;
+            position[1] -= 2 * lx ;
+            position[2] -= 2 * lx ;
+        }
+        else if ( i % lx == 0 )    /* left side */
+        {
+            position[0] += 2 ;
+            position[6] += 2 ;
+            position[7] += 2 ;
+        }
+        else if ( i % lx == lx - 1 )    /* right side */
+        {
+            position[2] -= 2 ;
+            position[3] -= 2 ;
+            position[4] -= 2 ;
+        }
+
+        /* ------------------------------------------------------------------
+         * read the pixel values of the neighboring pixels,
+         * blanks are not considered
+         */
+
+        nposition = 8 ;
+        n = 0 ;
+        for ( j = 0 ; j < nposition ; j ++ )
+        {
+            if ( !isnan(pidata[position[j]]) )
+            {
+                value[n] = pidata[position[j]] ;
+                n ++ ;
+            }
+        }
+        nposition = n ;
+
+        if ( nposition <= 1 )  /* almost all neighbors are blank */
+        {
+            podata[i] = ZERO ;
+            cpl_free(value) ;
+            cpl_free(position) ;
+            cpl_free(stats) ;
+            continue ;
+        }
+
+        /* sort the values and determine the median */
+
+        sinfo_pixel_qsort( value, nposition ) ;
+        if ( nposition % 2 == 1 )
+        {
+            median = value [ nposition/2 ] ;
+        }
+        else
+        {
+            median = ( value [nposition/2 - 1] + value [nposition/2] ) / 2. ;
+        }
+
+        /* -----------------------------------------------------------------
+         * replace the pixel value by the median on conditions:
+         * fmedian = 0: always replace with median.
+         * fmedian > 0: replace by median (fmedian as a factor of
+         *              the square root of the median itself)
+         *              if |pixel - median| >= fmedian * sqrt ( median )
+         *              considers a dependence on the pixel value.
+         *              This can be used to consider photon noise.
+         */
+
+        if ( fmedian == 0 )
+        {
+            podata[i] = median ;
+        }
+        else if ( fmedian < 0 &&
+                  fabs ( median - pidata[i] ) >= -fmedian * stats->cleanstdev)
+        {
+            podata[i] = median ;
+        }
+        else if ( fmedian > 0 &&
+                  fabs ( median - pidata[i] ) >= fmedian * sqrt(fabs(median)) )
+        {
+            podata[i] = median ;
+        }
+        else
+        {
+            cpl_free (value) ;
+            cpl_free (position) ;
+            cpl_free (stats) ;
+            continue ;
+        }
+
+        cpl_free (value) ;
+        cpl_free (position) ;
+        cpl_free (stats) ;
+    }
+    return image ;
+}
+
+
+
+/*----------------------------------------------------------------------------
+   Function:       sinfo_new_mean_image_in_spec()
+   In      :       image, a threshold parameter
+   Out     :       resulting image
+   Job     :       mean filter, calculates the mean for an image
+                   by using the 4 closest pixels of every pixel in spectral 
+                   direction (column).
+                   The values in the output image are determined according
+                   to the values of the input parameter.
+                   If fmedian = 0: always replace by mean
+                   if fmedian < 0: replace by mean if |pixel - mean| >
+                                        -fmedian
+                   if fmedian > 0: replace by mean (fmedian as a factor of
+                                   the square root of the mean itself)
+                                   if |pixel - mean| >= fmedian * sqrt ( mean )
+                   This can be used to consider photon noise.
+                   This considers a dependence of the differences on the
+                   pixel values themselves.
+   Notice       :  it is assumed that most of the 4 nearest neighbor pixels
+                   are not bad pixels!
+                   blank pixels are not replaced!
+ ---------------------------------------------------------------------------*/
+
+cpl_image * sinfo_new_mean_image_in_spec( cpl_image * im, float fmedian )
+{
+    cpl_image *   image       ;
+    pixelvalue * value       ;
+    pixelvalue   mean      ;
+    int        * position    ;
+    int          nposition   ;
+    int          n, i, j ;
+    int lx=0;
+    int ly=0;
+    float* pidata=NULL;
+    float* podata=NULL;
+
+    if ( im == NULL )
+    {
+        sinfo_msg_error ("no image input") ;
+        return NULL ;
+    }
+
+    image = cpl_image_duplicate ( im ) ;
+    lx=cpl_image_get_size_x(im);
+    ly=cpl_image_get_size_y(im);
+    pidata=cpl_image_get_data(im);
+    podata=cpl_image_get_data(image);
+
+    /*----------------------------------------------------------------------
+     * go through all pixels
+     */
+
+    for ( i = 0 ; i < (int) lx*ly ; i++ )
+    {
+        /* blank pixels are not replaced */
+        if ( isnan(pidata[i]) )
+        {
+            continue ;
+        }
+
+        /* initialize the buffer variables for the 2 nearest 
+           spectral neighbors */
+        value = (pixelvalue * )cpl_calloc ( 4, sizeof ( pixelvalue * ) ) ;
+        position = ( int * ) cpl_calloc ( 4, sizeof ( int * ) ) ;
+
+        /*--------------------------------------------------------------------
+         * determine the pixel position of the 8 nearest neighbors
+         */
+
+        position[0] = i + lx     ; /* upper       */
+        position[1] = i + 2*lx   ; /* upper       */
+        position[2] = i - lx     ; /* lower       */
+        position[3] = i - 2*lx   ; /* lower       */
+
+        /*-------------------------------------------------------------------
+         * determine the positions of the image margins, top positions are 
+         * changed to low positions and vice versa. Right positions are changed
+         * to left positions and vice versa.
+         */
+
+        if ( i >= 0 && i < lx )    /* bottom line */
+        {
+            position[2] += 2 * lx ;
+            position[3] += 4 * lx ;
+        }
+        else if ( i >= ((int) lx*ly - lx ) && i < (int) lx*ly ) /* top line */
+        {
+            position[0] -= 2 * lx ;
+            position[1] -= 4 * lx ;
+        }
+
+        /* -------------------------------------------------------------------
+         * read the pixel values of the neighboring pixels,
+         * blanks are not considered
+         */
+
+        nposition = 4 ;
+        n = 0 ;
+        for ( j = 0 ; j < nposition ; j ++ )
+        {
+            if ( !isnan(pidata[position[j]]) )
+            {
+                value[n] = pidata[position[j]] ;
+                n ++ ;
+            }
+        }
+        nposition = n ;
+
+        if ( nposition < 1 )  /* all neighbors are blank */
+        {
+            podata[i] = ZERO ;
+            cpl_free(value) ;
+            cpl_free(position) ;
+            continue ;
+        }
+
+        /* determine the mean */
+        mean = 0. ;
+        for ( n = 0 ; n < nposition ; n++ )
+        {
+            mean += value[n] ;
+        }
+        mean /= (float) nposition ;
+
+        /* -----------------------------------------------------------------
+         * replace the pixel value by the median on conditions:
+         * fmedian = 0:","always replace with mean.
+         * fmedian < 0: interpret as absolute condition:
+         *              if |pixel - mean| > -fmedian
+         *              replace with mean.
+         */
+
+        if ( fmedian == 0 )
+        {
+            podata[i] = mean ;
+        }
+        else if ( fmedian < 0 &&
+                  fabs ( mean - pidata[i] ) >= -fmedian )
+        {
+            podata[i] = mean ;
+        }
+        else if ( fmedian > 0 &&
+                  fabs ( mean - pidata[i] ) >= fmedian * sqrt(fabs(mean)) )
+        {
+            podata[i] = mean ;
+        }
+        else
+        {
+            cpl_free (value) ;
+            cpl_free (position) ;
+            continue ;
+        }
+
+        cpl_free (value) ;
+        cpl_free (position) ;
+    }
+    return image ;
+}
+
+
+
+
+
+
+/**@}*/
diff --git a/sinfoni/sinfo_detlin.h b/sinfoni/sinfo_detlin.h
new file mode 100644
index 0000000..92e2588
--- /dev/null
+++ b/sinfoni/sinfo_detlin.h
@@ -0,0 +1,217 @@
+#ifndef SINFO_DETLIN_H
+#define SINFO_DETLIN_H
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/*******************************************************************************
+* E.S.O. - VLT project
+*
+* "@(#) $Id: sinfo_detlin.h,v 1.5 2007/06/06 07:10:45 amodigli Exp $"
+*
+* who       when      what
+* --------  --------  ----------------------------------------------
+* amodigli  04/01/06  created
+*/
+
+/************************************************************************
+ * sinfo_detlin.h
+ * detector linearity routines
+ * to search for static bad pixels
+ *----------------------------------------------------------------------
+ */
+
+/*
+ * header files
+ */
+#include "sinfo_image_ops.h"
+
+/*----------------------------------------------------------------------------
+ *                        Function ANSI C prototypes
+ *--------------------------------------------------------------------------*/
+/**
+   @name      sinfo_new_fit_intensity_course()
+   @param     flatStack: flats with in/decreasing intensity
+                         stacked in a data cube
+   @param     order:     order of the fit polynomial
+   @return    data cube containing the fit result. The first polynomial 
+              coefficients in the first plane and so on.
+   @doc       this routine fits polynomials along the z-axis of
+              a data cube and stores the resulting coefficients
+              in a data cube. The eclipse routine sinfo_fit_1d_poly()
+              is used for polynomial fitting
+              The input is assumed to be a cube containing flatfield frames of
+              different intensities (usually increasing or decreasing).
+              for each pixel position on the detector, a curve is plotted
+              of the pixel intensity in each plane against the clean mean
+              intensity of the plane. Then a polynomial of user defined
+              order is fitted to the curves.
+*/
+
+cpl_imagelist * 
+sinfo_new_fit_intensity_course(cpl_imagelist * flatStack,
+                              int       order,
+                              float     loReject,
+                              float     hiReject ) ;
+
+
+
+/**
+   @name    sinfo_new_search_bad_pixels()
+   @param   coeffs fitted polynomial coefficients stored in a cube
+   @param   threshSigmaFactor factor of determined sigma of an
+                              image plane to determine the
+                              threshold for good or bad pixels
+   @param    nonlinearThresh   absolute threshold value of the found
+                               non-linear polynomial coefficients beyond
+                               which the pixels are declared as bad.
+   @param    loReject 
+   @param    hiReject percentage (0...100) of extreme pixel values that is not
+                      considered for image statistics
+   @return   Bad pixel mask image (1: good pixel, 0: bad pixel).
+   @doc      this routine searches for static bad pixel positions
+             by searching the fitted polynomial coefficients of each pixel 
+             response for outliers.
+             Pixel with high non-linear response are also declared as bad.
+*/
+
+cpl_image * 
+sinfo_new_search_bad_pixels(cpl_imagelist *  coeffs,
+                            double     threshSigmaFactor,
+                            double     nonlinearThresh,
+                            float      loReject,
+                            float      hiReject ) ;
+
+/**
+   @name     sinfo_new_search_bad_pixels_via_noise()
+   @param    darks sequence of darks (NDIT = 1)
+                   stored in a cube, at least 10 to get good statistics
+   @param    threshSigmaFactor factor to determined standard deviation
+                               in each pixel to determine the threshold
+                               beyond which a pixel is declared as bad.
+   @param    loReject 
+   @param    hiReject percentage (0...100) of extreme pixel
+                      values that is not considered for image statistics
+   @return  Bad pixel mask image (1: good pixel, 0: bad pixel).
+   @doc     this routine searches for static bad pixel positions
+            This is done by building a cube of sinfo_dark frames and examine
+            the noise variations in each pixel. If big deviations
+            from a clean mean pixel noise occurr, the pixel is
+            declared as bad.
+*/
+cpl_image * 
+sinfo_new_search_bad_pixels_via_noise( cpl_imagelist *  darks,
+                                    float      threshSigmaFactor,
+                                    float      loReject,
+                                    float      hiReject ) ;
+
+
+/*
+   @name   sinfo_new_count_bad_pixels()
+   @memo     this routine counts the number of bad pixels
+   @param  bad bad pixel mask
+   @return      number of bad pixels.
+*/
+
+int 
+sinfo_new_count_bad_pixels ( cpl_image * bad ) ;
+
+
+/*
+   @name   sinfo_new_abs_dist_image()
+   @param  image, a threshold parameter
+   @result resulting image
+   @doc    filter, calculates the absolute distances of the nearest neighbors 
+           for an image by using the 8 closest pixels of every pixel.
+           The values in the output image are determined according
+           to the values of the input parameter.
+           If fmedian = 0: always replace by abs. distances
+           if fmedian < 0: replace by abs. distances if |median_dist - dist| >
+                                        -fmedian
+           if fmedian > 0: replace by abs. distances (fmedian as a factor of
+                           the square root of the distance itself)
+           if |median_dist - dist| >= fmedian * sqrt ( dist )
+           This can be used to consider photon noise.
+           This considers a dependence of the differences on the
+           pixel values themselves.
+   @note   it is assumed that most of the 8 nearest neighbor pixels
+           are not bad pixels! blank pixels are not replaced!
+*/
+
+
+cpl_image * 
+sinfo_new_abs_dist_image(cpl_image * im, float fmedian ) ;
+
+
+/**
+   @name  sinfo_new_mean_image_in_spec()
+   @param image, a threshold parameter
+   @return resulting image
+   @doc    mean filter, calculates the mean for an image
+           by using the 4 closest pixels of every pixel in spectral direction
+          (column).
+          The values in the output image are determined according
+          to the values of the input parameter.
+          If fmedian = 0: always replace by mean
+          if fmedian < 0: replace by mean if |pixel - mean| > -fmedian
+          if fmedian > 0: replace by mean (fmedian as a factor of
+          the square root of the mean itself)
+          if |pixel - mean| >= fmedian * sqrt ( mean )
+          This can be used to consider photon noise.
+          This considers a dependence of the differences on the
+          pixel values themselves.
+   @note  it is assumed that most of the 4 nearest neighbor pixels
+          are not bad pixels! blank pixels are not replaced!
+*/
+
+
+cpl_image * 
+sinfo_new_mean_image_in_spec(cpl_image * im, float fmedian ) ;
+
+/**
+   @name  sinfo_new_local_median_image()
+   @param im input image
+   @param fmedian  a factor to the local standard deviation
+   @param loReject
+   @param hiReject fraction of rejected values to determine
+                   a clean standard deviation
+   @param half_box_size integer half size of the running box to determine
+                        the local clean standard deviation
+   @return  resulting image
+   @doc     filter, calculates the local stdev in a moving box
+            Then it calculates the difference of the pixel to the sinfo_median
+            of the nearest neighbors by using the 8 closest pixels of every 
+            pixel. The values in the output image are determined according
+            to the values of the input parameter.
+            If fmedian = 0: always replace by sinfo_median
+            if fmedian > 0: replace sinfo_median if |median_dist - dist| >
+                            fmedian * stdev
+   @note it is assumed that most of the 8 nearest neighbor pixels are not bad 
+         pixels! blank pixels are not replaced!
+*/
+
+cpl_image * 
+sinfo_new_local_median_image(cpl_image * im,
+                             float fmedian,
+                             float loReject,
+                             float hiReject,
+                             int half_box_size ) ;
+
+
+#endif /*!SINFO_DETLIN_H*/
+
diff --git a/sinfoni/sinfo_detlin_cfg.c b/sinfoni/sinfo_detlin_cfg.c
new file mode 100644
index 0000000..88a0864
--- /dev/null
+++ b/sinfoni/sinfo_detlin_cfg.c
@@ -0,0 +1,73 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*---------------------------------------------------------------------------
+   
+   File name     :    sinfo_detlin_cfg.c
+   Autor    :       Juergen Schreiber
+   Created on    :    April 2002
+   Description    :    handles the data structure detlin_config
+ *--------------------------------------------------------------------------*/
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+/*---------------------------------------------------------------------------
+ ---------------------------------------------------------------------------*/
+#include "sinfo_detlin_cfg.h"
+/**@{*/
+/**
+ * @addtogroup sinfo_detlin Detector Linearity Determination Functions
+ *
+ * TBD
+ */
+/*---------------------------------------------------------------------------
+                              Function codes
+ ---------------------------------------------------------------------------*/
+/**
+   @name   sinfo_detlin_cfg_create()
+   @memo   allocate memory for a detlin_cfg struct
+   @return pointer to allocated base detlin_cfg structure
+   @note   only the main (base) structure is allocated
+*/
+
+detlin_config * 
+sinfo_detlin_cfg_create(void)
+{
+    return cpl_calloc(1, sizeof(detlin_config));
+}
+
+/**
+  @name   sinfo_detlin_cfg_destroy()
+  @memo   deallocate all memory associated with a detlin_config data structure
+  @param  detlin_config to deallocate
+  @return void
+*/
+void sinfo_detlin_cfg_destroy(detlin_config * sc)
+{
+
+    if (sc==NULL) return ;
+    /* cpl_free(sc->framelist) ; */
+    /* Free main struct */
+    cpl_free(sc);
+
+    return ;
+}
+
+/**@}*/
+
+
diff --git a/sinfoni/sinfo_detlin_cfg.h b/sinfoni/sinfo_detlin_cfg.h
new file mode 100644
index 0000000..7067908
--- /dev/null
+++ b/sinfoni/sinfo_detlin_cfg.h
@@ -0,0 +1,100 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*---------------------------------------------------------------------------
+   
+   File name     :    sinfo_detlin_cfg.h
+   Author         :    Juergen Schreiber
+   Created on    :    April 2002
+   Description    :    sinfo_detlin_ini definitions + handling prototypes
+ ---------------------------------------------------------------------------*/
+#ifndef SINFO_DETLIN_CFG_H
+#define SINFO_DETLIN_CFG_H
+/*---------------------------------------------------------------------------
+                                   Includes
+ ---------------------------------------------------------------------------*/
+#include <stdlib.h>
+#include "sinfo_globals.h"
+#include <cpl.h>
+/*---------------------------------------------------------------------------
+                                   Defines
+ ---------------------------------------------------------------------------*/
+/*---------------------------------------------------------------------------
+                                   New types
+ ---------------------------------------------------------------------------*/
+/*
+  bad pixels search blackboard container
+
+  This structure holds all information related to the bad pixels search
+  routine. It is used as a container for the flux of ancillary data,
+  computed values, and algorithm status. Pixel flux is separated from
+  the blackboard.
+  */
+
+typedef struct detlin_config {
+/*-------General---------*/
+        char inFile[FILE_NAME_SZ] ; /* file name of the file containing 
+                                       the list of all input frames */
+        char outName[FILE_NAME_SZ] ; /* output name of resulting bad pixel 
+                                        mask (fits file)*/
+        char ** framelist ; /* list of frames */
+        int     nframes ; /* number of frames in frame list */
+
+/*------ Response------*/
+        /* order of the fit polynomial */
+        int order ;      
+        /* factor to the standard deviation of the zero and slope polynomial 
+           coefficient. if the deviation exceeds the resulting value the 
+           corresponding pixel is declared as bad */ 
+        double threshSigmaFactor ;      
+        /*if a non-linear coefficient exceeds this value the corresponding 
+          pixel is declared as bad*/
+        double nonlinearThresh ;      
+        /* percentage of rejected low intensity pixels before determining
+           image statistics (mean and standard deviation)*/
+        float loReject ;
+        /* percentage of rejected high intensity pixels before determining
+           image statistics (mean and standard deviation) */
+        float hiReject ;
+        /*name of the data cube storing the found polynomial coefficients*/
+        char coeffsCubeName[FILE_NAME_SZ] ;
+} detlin_config ;
+
+/*---------------------------------------------------------------------------
+                               Function prototypes
+ ---------------------------------------------------------------------------*/
+/**
+   @name   sinfo_detlin_cfg_create()
+   @memo   allocate memory for a detlin_cfg struct
+   @return pointer to allocated base detlin_cfg structure
+   @note   only the main (base) structure is allocated
+*/
+
+detlin_config * 
+sinfo_detlin_cfg_create(void);
+
+/**
+  @name   sinfo_detlin_cfg_destroy()
+  @memo   deallocate all memory associated with a detlin_config data structure
+  @param  detlin_config to deallocate
+  @return void
+*/
+void 
+sinfo_detlin_cfg_destroy(detlin_config * sc);
+
+#endif
diff --git a/sinfoni/sinfo_detlin_ini.h b/sinfoni/sinfo_detlin_ini.h
new file mode 100644
index 0000000..fe87cd6
--- /dev/null
+++ b/sinfoni/sinfo_detlin_ini.h
@@ -0,0 +1,67 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+   
+   File name    :   sinfo_detlin_ini.h
+   Author       :    Juergen Schreiber
+   Created on   :    April 19, 2002
+   Description  :    prepare handling of .ini file for the search for static 
+                        bad pixels
+ ---------------------------------------------------------------------------*/
+#ifndef SINFO_DETLIN_INI_H
+#define SINFO_DETLIN_INI_H
+/*---------------------------------------------------------------------------
+                                Includes
+---------------------------------------------------------------------------*/
+#include <cpl.h>
+#include "sinfo_detlin_cfg.h"
+/*---------------------------------------------------------------------------
+                                Defines
+---------------------------------------------------------------------------*/
+/*----------------------------------------------------------------------------
+                             Function prototypes 
+ ---------------------------------------------------------------------------*/
+/**
+  @name        generateDetlin_ini_file
+  @memo        Generate a default ini file for the bad pixel search command.
+  @param    ini_name    Name of the file to generate.
+  @param    name_i        Name of the input file.
+  @param    name_o        Name of the output file.
+  @return    int 0 if Ok, -1 otherwise.
+  @doc          This function generates a default ini file for the bad pixel 
+                search command. The generated file will have the requested 
+                name. 
+ */
+int 
+generateDetlin_ini_file(
+        char * ini_name,
+        char * name_i,
+        char * name_o
+);
+/**
+  @name     parse_detlin_ini_file
+  @memo     Parse an ini_name.ini file and create a blackboard.
+  @param    ini_name    Name of the ASCII file to parse.
+  @return   1 newly allocated detlin_config blackboard structure.
+  @doc      The requested ini file is parsed and a blackboard object is 
+            created, the updated accordingly. Returns NULL in case of error.
+ */
+detlin_config * 
+parse_detlin_ini_file(char * ini_name) ;
+#endif
diff --git a/sinfoni/sinfo_detlin_ini_by_cpl.c b/sinfoni/sinfo_detlin_ini_by_cpl.c
new file mode 100644
index 0000000..6eb2b80
--- /dev/null
+++ b/sinfoni/sinfo_detlin_ini_by_cpl.c
@@ -0,0 +1,263 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+   
+   File name    :   sinfo_detlin_ini_by_cpl.c
+   Author       :   Andrea Modigliani
+   Created on   :    May 17, 2004
+   Description  :    produce and read an .ini file for the search of static
+                        bad pixels
+ ---------------------------------------------------------------------------*/
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+/*---------------------------------------------------------------------------
+                                Includes
+ ---------------------------------------------------------------------------*/
+#include <string.h>
+#include "sinfo_detlin_ini_by_cpl.h"
+#include "sinfo_error.h"
+#include "sinfo_hidden.h"
+#include "sinfo_raw_types.h"
+#include "sinfo_functions.h"
+#include "sinfo_file_handling.h"
+/*---------------------------------------------------------------------------
+                    Functions private to this module
+ ---------------------------------------------------------------------------*/
+static void     
+parse_section_frames(detlin_config *, 
+                cpl_frameset* sof, cpl_frameset** raw,int* status);
+static void     
+parse_section_response(detlin_config *, cpl_parameterlist* cpl_cfg);
+
+/**@{*/
+/**
+ * @addtogroup sinfo_detlin Detector Linearity Determination Functions
+ *
+ * TBD
+ */
+
+/**
+  @name     sinfo_parse_cpl_input_detlin
+  @memo     Parse input frames & parameters and create a blackboard.
+  @param    cpl_cfg pointer to parameterlist
+  @param    sof pointer to input set of frames
+  @param    raw pointer to input set of raw frames
+  @return   1 newly allocated detlin_config blackboard structure.
+
+  @doc      The requested ini file is parsed and a blackboard object is 
+            created, then updated accordingly. Returns NULL in case of error.
+ */
+
+detlin_config * 
+sinfo_parse_cpl_input_detlin(cpl_parameterlist * cpl_cfg, cpl_frameset* sof, 
+ cpl_frameset** raw)
+{
+
+        detlin_config    *    cfg ;
+        int                   status ;
+
+        /* check on input ini file removed */
+        /* loading input ini file removed */
+
+
+        cfg = sinfo_detlin_cfg_create();
+
+        /*
+         * Perform sanity checks, fill up the structure with what was
+         * found in the ini file
+         */
+
+        status = 0 ;
+        parse_section_response(cfg, cpl_cfg);
+        parse_section_frames(cfg, sof, raw,  &status);
+        if (status > 0) {
+                sinfo_msg_error("parsing cpl input");
+                sinfo_detlin_free(&cfg);
+                cfg = NULL ;
+                return NULL ;
+        }
+        return cfg ;
+}
+
+/**
+  @name     parse_section_frames
+  @memo     Parse input frames.
+  @param    cfg pointer to detlin_config structure
+  @param    sof pointer to input set of frames
+  @param    raw pointer to input set of raw frames
+  @param    status status of function
+  @return   void
+
+ */
+
+static void   
+parse_section_frames(detlin_config * cfg,
+             cpl_frameset * sof,
+                     cpl_frameset** raw,
+                     int* status)
+{
+
+   int                     i=0;
+   char* tag=NULL;
+   int  nraw = 0;
+   int  nraw_good = 0;
+   cpl_frame* frame=NULL;
+   char spat_res[FILE_NAME_SZ];
+   char lamp_status[FILE_NAME_SZ];
+   char band[FILE_NAME_SZ];
+   int ins_set=0;
+  
+   sinfo_extract_raw_frames_type(sof,raw,RAW_LINEARITY_LAMP);
+
+   nraw=cpl_frameset_get_size(*raw);
+ 
+   if (nraw < 1) {
+      sinfo_msg_error( "Too few (%d) raw frames (%s)  present in"
+             "frameset!Aborting...",nraw, RAW_LINEARITY_LAMP);
+      (*status)++;
+      return;
+   }
+
+
+
+   /* get "general:infile" read it, check input sinfo_matrix */
+   /* Allocate structures to go into the blackboard */
+   cfg->framelist = cpl_malloc(nraw * sizeof(char*)); 
+   
+  /* read input frames */
+   for (i=0 ; i<nraw ; i++) {
+     /* cfg->framelist[i] = cpl_malloc(FILE_NAME_SZ * sizeof(char));  */
+      frame = cpl_frameset_get_frame(*raw,i);
+     if(sinfo_file_exists((char*)cpl_frame_get_filename(frame))==1) 
+    {
+          tag = (char*)cpl_frame_get_tag(frame) ;
+      if(sinfo_is_flat_lindet(tag) || sinfo_is_dark(tag)) {
+          /* Store file name into framelist */
+             cfg->framelist[i]=cpl_strdup(cpl_frame_get_filename(frame));
+             nraw_good++;
+      }
+    }
+   }
+
+   /* Copy relevant information into the blackboard */
+   cfg->nframes         = nraw_good ;
+
+
+   if (nraw_good < (cfg->order+1)) {
+      sinfo_msg_error( "Too few (%d) raw frames (%s)  present in"
+             "frameset as we do a %d order polymnomial fit" 
+                         "!Aborting...",nraw_good, 
+                         RAW_LINEARITY_LAMP,cfg->order);
+
+      (*status)++;
+      return;
+   }
+
+
+   strcpy(cfg -> outName, BP_LIN_OUT_FILENAME);
+
+   check_nomsg(frame = cpl_frameset_get_frame(*raw,0));
+   sinfo_get_spatial_res(frame,spat_res);
+ 
+   switch(sinfo_frame_is_on(frame)) 
+     {
+   case 0: 
+      strcpy(lamp_status,"on");
+      break;
+    case 1: 
+      strcpy(lamp_status,"off");
+      break;
+    case -1:
+      strcpy(lamp_status,"undefined");
+      break;
+    default: 
+      strcpy(lamp_status,"undefined");
+      break;
+
+
+     }
+
+   sinfo_get_band(frame,band);
+   sinfo_msg("Spatial resolution: %s lamp status: %s band: %s \n",
+                     spat_res,              lamp_status,    band);
+
+
+   sinfo_get_ins_set(band,&ins_set);
+
+  
+  cleanup:
+
+   return;
+}
+/**
+  @name     parse_section_response
+  @memo     Parse response parameters.
+  @param    cfg pointer to detlin_config structure
+  @param    cpl_cfg pointer to input parameters
+  @return   void
+
+ */
+static void     
+parse_section_response(detlin_config * cfg,cpl_parameterlist *   cpl_cfg)
+{
+   cpl_parameter *p;     
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_lin.order");
+   cfg -> order = cpl_parameter_get_int(p);
+ 
+   p = cpl_parameterlist_find(cpl_cfg,"sinfoni.bp_lin.thresh_sigma_factor");
+   cfg->threshSigmaFactor = (float) cpl_parameter_get_double(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_lin.low_rejection");
+   cfg -> loReject = (float) cpl_parameter_get_double(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_lin.high_rejection");
+   cfg -> hiReject = (float) cpl_parameter_get_double(p);
+
+   p = cpl_parameterlist_find(cpl_cfg,"sinfoni.bp_lin.nlin_threshold");
+   cfg->nonlinearThresh = (float) cpl_parameter_get_double(p);
+
+   /* name of the data cube storing the found polynomial coefficients */
+   strcpy(cfg->coeffsCubeName, BP_LIN_COEFFS_CUBE_OUT_FILENAME);
+
+   return ;
+}
+/**
+ at name sinfo_detlin_free
+ at memo deallocates detlin_config structure
+ at param cfg pointer to detlin_config structure
+ at return void
+*/
+void
+sinfo_detlin_free(detlin_config ** cfg)
+{  
+  int i=0;
+  if(*cfg!=NULL) {
+    for(i=0;i<(*cfg)->nframes; i++) {
+      if((*cfg)->framelist[i] != NULL) cpl_free((*cfg)->framelist[i]);
+    }
+    cpl_free((*cfg)->framelist);
+    sinfo_detlin_cfg_destroy((*cfg));
+    *cfg = NULL;
+  }
+  return;
+
+}
+/**@}*/
diff --git a/sinfoni/sinfo_detlin_ini_by_cpl.h b/sinfoni/sinfo_detlin_ini_by_cpl.h
new file mode 100644
index 0000000..b221465
--- /dev/null
+++ b/sinfoni/sinfo_detlin_ini_by_cpl.h
@@ -0,0 +1,66 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+   
+   File name    :   sinfo_detlin_ini_by_cpl.h
+   Author       :   Andrea Modigliani
+   Created on   :   May 17, 2004
+   Description  :   prepare handling of .ini file for the search for static 
+                    bad pixels
+ ---------------------------------------------------------------------------*/
+#ifndef SINFO_DETLIN_INI_BY_CPL_H
+#define SINFO_DETLIN_INI_BY_CPL_H
+/*---------------------------------------------------------------------------
+                                Includes
+---------------------------------------------------------------------------*/
+#include <cpl.h>
+#include "sinfo_detlin_cfg.h"
+#include "sinfo_msg.h"
+/*---------------------------------------------------------------------------
+                                Defines
+---------------------------------------------------------------------------*/
+/*----------------------------------------------------------------------------
+                             Function prototypes 
+ ---------------------------------------------------------------------------*/
+/**
+  @name     sinfo_parse_cpl_input_detlin
+  @memo     Parse input frames & parameters and create a blackboard.
+  @param    cpl_cfg pointer to parameterlist
+  @param    sof pointer to input set of frames
+  @param    raw pointer to input set of raw frames
+  @return   1 newly allocated detlin_config blackboard structure.
+
+  @doc      The requested ini file is parsed and a blackboard object is 
+            created, then updated accordingly. Returns NULL in case of error.
+ */
+detlin_config * 
+sinfo_parse_cpl_input_detlin(cpl_parameterlist * cpl_cfg, 
+                             cpl_frameset* sof, 
+                             cpl_frameset** raw);
+
+/**
+ at name sinfo_detlin_free
+ at memo deallocates detlin_config structure
+ at param cfg pointer to detlin_config structure
+ at return void
+*/
+void 
+sinfo_detlin_free(detlin_config ** cfg);
+
+#endif
diff --git a/sinfoni/sinfo_detnoise_cfg.c b/sinfoni/sinfo_detnoise_cfg.c
new file mode 100644
index 0000000..ab36477
--- /dev/null
+++ b/sinfoni/sinfo_detnoise_cfg.c
@@ -0,0 +1,75 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*---------------------------------------------------------------------------
+   
+   File name     :    sinfo_detnoise_cfg.c
+   Autor    :       Juergen Schreiber
+   Created on    :    September 2002
+   Description    :    handles the data structure detnoise_config
+
+ *--------------------------------------------------------------------------*/
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+/*---------------------------------------------------------------------------
+                                   Includes
+ ---------------------------------------------------------------------------*/
+#include "sinfo_detnoise_cfg.h"
+/**@{*/
+/**
+ * @addtogroup sinfo_bad_pix_search Bad Pixel Search
+ *
+ * TBD
+ */
+
+/*---------------------------------------------------------------------------
+                              Function codes
+ ---------------------------------------------------------------------------*/
+/**
+   @name    sinfo_detnoise_cfg_create()
+   @return  pointer to allocated base detnoise_cfg structure
+   @memo    allocate memory for a detnoise_cfg struct
+   @note    only the main (base) structure is allocated
+ */
+detnoise_config * 
+sinfo_detnoise_cfg_create(void)
+{
+    return cpl_calloc(1, sizeof(detnoise_config));
+}
+
+/**
+   @name    sinfo_detnoise_cfg_destroy()
+   @memo deallocate all memory associated with a detnoise_config data structure
+   @param   detnoise_config to deallocate
+   @return  void
+*/
+void 
+sinfo_detnoise_cfg_destroy(detnoise_config * sc)
+{
+    if (sc==NULL) return ;
+    /* Free main struct */
+    cpl_free(sc);
+
+    return ;
+}
+
+/**@}*/
+
+
diff --git a/sinfoni/sinfo_detnoise_cfg.h b/sinfoni/sinfo_detnoise_cfg.h
new file mode 100644
index 0000000..ccfddb5
--- /dev/null
+++ b/sinfoni/sinfo_detnoise_cfg.h
@@ -0,0 +1,89 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*---------------------------------------------------------------------------
+   
+   File name     :    sinfo_detnoise_cfg.h
+   Author         :    Juergen Schreiber
+   Created on    :    September 2002
+   Description    :    sinfo_detnoise_ini definitions + handling prototypes
+ ---------------------------------------------------------------------------*/
+#ifndef SINFO_DETNOISE_CFG_H
+#define SINFO_DETNOISE_CFG_H
+/*---------------------------------------------------------------------------
+                                   Includes
+ ---------------------------------------------------------------------------*/
+#include <stdlib.h>
+#include "sinfo_globals.h"
+#include <cpl.h>
+/*---------------------------------------------------------------------------
+                                   Defines
+ ---------------------------------------------------------------------------*/
+/*---------------------------------------------------------------------------
+                                   New types
+ ---------------------------------------------------------------------------*/
+/*
+  bad pixels search blackboard container
+
+  This structure holds all information related to the bad pixels search
+  routine. It is used as a container for the flux of ancillary data,
+  computed values, and algorithm status. Pixel flux is separated from
+  the blackboard.
+  */
+
+typedef struct detnoise_config {
+/*-------General---------*/
+        char inFile[FILE_NAME_SZ] ; /* file name of the file containing 
+                                       the list of all input frames */
+        char outName[FILE_NAME_SZ] ; /* output name of resulting bad 
+                                        pixel mask (fits file)*/
+        char ** framelist ; /* list of frames */
+        int     nframes ; /* number of frames in frame list */
+
+/*------searchBad------*/
+        /* factor to the standard deviation of the mean standard deviation. */
+        double threshSigmaFactor ;      
+        /* percentage of rejected low intensity pixels before determining
+           image statistics (mean and standard deviation)*/
+        float loReject ;
+        /* percentage of rejected high intensity pixels before determining
+           image statistics (mean and standard deviation) */
+        float hiReject ;
+} detnoise_config ;
+/*---------------------------------------------------------------------------
+                               Function prototypes
+ ---------------------------------------------------------------------------*/
+/**
+   @name    sinfo_detnoise_cfg_create()
+   @return  pointer to allocated base detnoise_cfg structure
+   @memo    allocate memory for a detnoise_cfg struct
+   @note    only the main (base) structure is allocated
+ */
+
+detnoise_config * 
+sinfo_detnoise_cfg_create(void);
+/**
+   @name    sinfo_detnoise_cfg_destroy()
+   @memo deallocate all memory associated with a detnoise_config data structure
+   @param   detnoise_config to deallocate
+   @return  void
+*/
+void 
+sinfo_detnoise_cfg_destroy(detnoise_config * sc);
+
+#endif
diff --git a/sinfoni/sinfo_detnoise_ini.h b/sinfoni/sinfo_detnoise_ini.h
new file mode 100644
index 0000000..b320be4
--- /dev/null
+++ b/sinfoni/sinfo_detnoise_ini.h
@@ -0,0 +1,70 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+   
+   File name    :   sinfo_detnoise_ini.h
+   Author       :   Juergen Schreiber
+   Created on   :   September 3, 2002
+   Description  :   prepare handling of .ini file for the search for static 
+                    bad pixels
+ ---------------------------------------------------------------------------*/
+#ifndef SINFO_DETNOISE_INI_H
+#define SINFO_DETNOISE_INI_H
+/*---------------------------------------------------------------------------
+                                Includes
+---------------------------------------------------------------------------*/
+#include <cpl.h>
+#include "sinfo_detnoise_cfg.h"
+/*---------------------------------------------------------------------------
+                                Defines
+---------------------------------------------------------------------------*/
+/*----------------------------------------------------------------------------
+                             Function prototypes 
+ ---------------------------------------------------------------------------*/
+/*-------------------------------------------------------------------------*/
+/**
+  @name        generateDetnoise_ini_file
+  @memo        Generate a default ini file for the bad pixel search command.
+  @param    ini_name    Name of the file to generate.
+  @param    name_i        Name of the input file.
+  @param    name_o        Name of the output file.
+  @return    int 0 if Ok, -1 otherwise.
+  @doc          This function generates a default ini file for the bad pixel 
+                search command. The generated file will have the requested 
+                name. 
+ */
+int 
+generateDetnoise_ini_file(
+        char * ini_name,
+        char * name_i,
+        char * name_o
+);
+/**
+  @name     parse_detnoise_ini_file
+  @memo     Parse an ini_name.ini file and create a blackboard.
+  @param    ini_name    Name of the ASCII file to parse.
+  @return   1 newly allocated detnoise_config blackboard structure.
+  @doc      The requested ini file is parsed and a blackboard object is 
+            created, then updated accordingly. Returns NULL in case of error.
+ */
+detnoise_config * 
+parse_detnoise_ini_file(char * ini_name) ;
+ 
+
+#endif
diff --git a/sinfoni/sinfo_detnoise_ini_by_cpl.c b/sinfoni/sinfo_detnoise_ini_by_cpl.c
new file mode 100644
index 0000000..6f4180e
--- /dev/null
+++ b/sinfoni/sinfo_detnoise_ini_by_cpl.c
@@ -0,0 +1,226 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+   
+   File name    :   sinfo_detnoise_ini.c
+   Author       :   Andrea Modiglini
+   Created on   :   May 17, 2004
+   Description  :   produce and read an .ini file for the search of static
+                    bad pixels
+ ---------------------------------------------------------------------------*/
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+/*---------------------------------------------------------------------------
+                                Includes
+ ---------------------------------------------------------------------------*/
+#include <string.h>
+#include "sinfo_detnoise_ini_by_cpl.h"
+#include "sinfo_raw_types.h"
+#include "sinfo_globals.h"
+#include "sinfo_hidden.h"
+#include "sinfo_functions.h"
+/*---------------------------------------------------------------------------
+                    Functions private to this module
+ ---------------------------------------------------------------------------*/
+
+static void  
+parse_section_frames(detnoise_config * cfg, 
+                     cpl_frameset* sof, 
+                     cpl_frameset** raw, 
+                     int* status);
+static void  
+parse_section_badsearch(detnoise_config * cfg, cpl_parameterlist* cpl_cfg);
+
+/**@{*/
+/**
+ * @addtogroup sinfo_bad_pix_search Bad Pixel Search
+ *
+ * TBD
+ */
+
+/****************************************************************************/
+/**
+  @name     sinfo_parse_cpl_input_detnoise
+  @memo     Parse input frames & parameters and create a blackboard.
+  @param    sof pointer to input set of frames
+  @param    raw pointer to input set of raw frames
+  @return   1 newly allocated detnoise_config blackboard structure.
+
+  @doc      The requested ini file is parsed and a blackboard object is 
+            created, then updated accordingly. Returns NULL in case of error.
+ 
+ */
+detnoise_config * 
+sinfo_parse_cpl_input_detnoise(cpl_parameterlist * cpl_cfg, 
+                               cpl_frameset* sof, 
+                               cpl_frameset** raw)
+{
+
+  detnoise_config    *    cfg ;
+  int status=0;
+  /* Removed check on ini_file */
+  /* Removed load of ini file */
+
+  cfg = sinfo_detnoise_cfg_create();
+
+   /*
+   * Perform sanity checks, fill up the structure with what was
+   * found in the ini file
+   */
+  parse_section_badsearch(cfg, cpl_cfg);
+  parse_section_frames(cfg, sof, raw, &status);
+
+         if (status > 0) {
+                sinfo_msg_error("parsing cpl input");
+                sinfo_detnoise_free(cfg);
+                cfg = NULL ;
+                return NULL ;
+        }
+  return cfg ;
+}
+
+
+/**
+  @name     parse_section_frames
+  @memo     Parse input frames.
+  @param    cfg pointer to detnoise_config
+  @param    sof pointer to input set of frames
+  @param    raw pointer to input set of raw frames
+  @param    status status of operation
+  @return   1 newly allocated detnoise_config blackboard structure.
+ */
+
+static void     
+parse_section_frames(detnoise_config * cfg,
+             cpl_frameset * sof,
+                     cpl_frameset** raw,
+                     int* status)
+{
+   int                     i;
+
+   int  nraw = 0;
+   cpl_frame* frame=NULL;
+
+    char spat_res[FILE_NAME_SZ];
+   char lamp_status[FILE_NAME_SZ];
+   char band[FILE_NAME_SZ];
+   int ins_set=0;
+
+
+
+   sinfo_extract_raw_frames_type2(sof,raw,RAW_DARK);
+
+   nraw = cpl_frameset_get_size(*raw);
+   if (nraw < 1) {
+      sinfo_msg_error("Too few (%d) raw frames (%s) present in"
+            "frameset!Aborting...",nraw,RAW_DARK);
+      (*status)++;
+          return;
+   }
+ 
+   /* get "general:infile" read it, check input sinfo_matrix */
+   /* Allocate structures to go into the blackboard */
+   /* Copy relevant information into the blackboard */
+   cfg->nframes       = nraw ;
+   cfg->framelist  =  cpl_malloc(nraw*sizeof(char*)); 
+  /* read input frames */
+   for (i=0 ; i<nraw ; i++) {
+      frame = cpl_frameset_get_frame(*raw,i);
+      /* Store file name into framelist */
+       cfg->framelist[i]=cpl_strdup(cpl_frame_get_filename(frame));
+   }
+ 
+   strcpy(cfg -> outName, BP_NOISE_OUT_FILENAME);
+
+   frame = cpl_frameset_get_frame(*raw,0);
+   sinfo_get_spatial_res(frame,spat_res);
+   switch(sinfo_frame_is_on(frame)) 
+     {
+   case 0: 
+      strcpy(lamp_status,"on");
+      break;
+    case 1: 
+      strcpy(lamp_status,"off");
+      break;
+    case -1:
+      strcpy(lamp_status,"undefined");
+      break;
+    default: 
+      strcpy(lamp_status,"undefined");
+      break;
+     }
+
+   sinfo_get_band(frame,band);
+   sinfo_msg("Spatial resolution: %s lamp status: %s band: %s \n",
+                     spat_res,    lamp_status,    band);
+   
+
+   sinfo_get_ins_set(band,&ins_set);
+   return;
+
+
+
+
+}
+
+/**
+  @name     parse_section_frames
+  @memo     Parse input frames.
+  @param    cfg pointer to detnoise_config
+  @param    cpl_cfg pointer to input parameters
+  @return   1 newly allocated detnoise_config blackboard structure.
+ */
+static void     
+parse_section_badsearch(detnoise_config * cfg,cpl_parameterlist *   cpl_cfg)
+{  
+   cpl_parameter *p;   
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_noise.low_rejection");
+   cfg -> loReject = cpl_parameter_get_double(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_noise.high_rejection");
+   cfg -> hiReject = cpl_parameter_get_double(p);
+
+   p = cpl_parameterlist_find(cpl_cfg,"sinfoni.bp_noise.thresh_sigma_factor");
+   cfg->threshSigmaFactor = cpl_parameter_get_double(p);
+
+}
+/**
+   @name    sinfo_detnoise_free()
+   @memo deallocate all memory associated with a detnoise_config data structure
+   @param   cfg detnoise_config to deallocate
+   @return  void
+*/
+
+void
+sinfo_detnoise_free(detnoise_config * cfg)
+{
+  int i=0;
+  if(cfg != NULL) {
+    for(i=0;i<cfg->nframes;i++){
+      if(cfg->framelist[i] != NULL) cpl_free(cfg->framelist[i]);
+    }
+    if(cfg->framelist) {
+      if(cfg->framelist != NULL) cpl_free(cfg->framelist);
+    }
+    sinfo_detnoise_cfg_destroy(cfg);
+  }
+}
+/**@}*/
diff --git a/sinfoni/sinfo_detnoise_ini_by_cpl.h b/sinfoni/sinfo_detnoise_ini_by_cpl.h
new file mode 100644
index 0000000..4fd7664
--- /dev/null
+++ b/sinfoni/sinfo_detnoise_ini_by_cpl.h
@@ -0,0 +1,67 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+   
+   File name    :   sinfo_detnoise_ini.h
+   Author       :    Juergen Schreiber
+   Created on   :    September 3, 2002
+   Description  :   prepare handling of .ini file for the search for static 
+                        bad pixels
+ ---------------------------------------------------------------------------*/
+#ifndef SINFO_DETNOISE_INI_BY_CPL_H
+#define SINFO_DETNOISE_INI_BY_CPL_H
+/*---------------------------------------------------------------------------
+                                Includes
+---------------------------------------------------------------------------*/
+#include <cpl.h>
+#include "sinfo_detnoise_cfg.h"
+#include "sinfo_msg.h" 
+/*---------------------------------------------------------------------------
+                                Defines
+---------------------------------------------------------------------------*/
+/*----------------------------------------------------------------------------
+                             Function prototypes 
+ ---------------------------------------------------------------------------*/
+/*-------------------------------------------------------------------------*/
+/**
+  @name     sinfo_parse_cpl_input_detnoise
+  @memo     Parse an ini_name.ini file and create a blackboard.
+  @param    cpl_cfg pointer to parameterlist
+  @param    sof     pointer to set of frame
+  @param    raw     pointer to set of raw frames
+  @return   1 newly allocated detnoise_config blackboard structure.
+  @doc      The requested ini file is parsed and a blackboard object is 
+            created, then updated accordingly. Returns NULL in case of error.
+ */
+
+detnoise_config * 
+sinfo_parse_cpl_input_detnoise(cpl_parameterlist * cpl_cfg, 
+                               cpl_frameset* sof, 
+                               cpl_frameset** raw);
+
+/**
+   @name    sinfo_detnoise_free()
+   @memo deallocate all memory associated with a detnoise_config data structure
+   @param   cfg detnoise_config to deallocate
+   @return  void
+*/
+void 
+sinfo_detnoise_free(detnoise_config * cfg);
+
+#endif
diff --git a/sinfoni/sinfo_dfs.c b/sinfoni/sinfo_dfs.c
new file mode 100644
index 0000000..c529a3e
--- /dev/null
+++ b/sinfoni/sinfo_dfs.c
@@ -0,0 +1,4739 @@
+/* $Id: sinfo_dfs.c,v 1.41 2012/04/26 14:44:48 amodigli Exp $
+ *
+ * This file is part of the SINFONI Pipeline
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2012/04/26 14:44:48 $
+ * $Revision: 1.41 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+/*----------------------------------------------------------------------------
+  Macros
+  ----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+  Private to this module
+  ----------------------------------------------------------------------------*/
+
+
+/*-----------------------------------------------------------------------------
+  Includes
+  ----------------------------------------------------------------------------*/
+#include "sinfo_dfs.h"
+#include <assert.h>
+#include <cpl.h>
+#include <math.h>
+#include "sinfo_error.h"
+#include "sinfo_utilities.h"
+#include "sinfo_utils_wrappers.h"
+#include "sinfo_msg.h"
+#include "sinfo_globals.h"
+#include "sinfo_pro_save.h"
+#include "sinfo_skycor.h"
+#include "sinfo_file_handling.h"
+#include <unistd.h>
+#include <stdio.h>
+/**@{*/
+/*---------------------------------------------------------------------------*/
+/**
+ * @defgroup sinfo_dfs  DFS related Utilities
+ *
+ * TBD
+ */
+/*---------------------------------------------------------------------------*/
+
+/* defines */
+
+#define FITS_MAGIC_SZ      6
+#define SINFO_FIT_AMOEBA_NMAX 5000
+
+/* function prototypes */
+/*
+  static int
+  sinfo_stat_rectangle(cpl_image* img,
+  const int kappa,
+  const int nclip,
+  double *mean,
+  double *stdev);
+*/
+static void
+sinfo_fit_amoeba_get_psum(int ndim, int mpts, double** p, double* psum);
+
+
+static  double
+sinfo_fit_amotry(double** p,
+                 double y[],
+                 double psum[],
+                 int ndim,
+                 double (*funk)(double[]),
+                 int ihi,
+                 double fac);
+
+
+static double
+get_chisq(int N, int D,
+          int (*f)(const double x[], const double a[], double *result),
+          const double *a,
+          const double *x,
+          const double *y,
+          const double *sigma);
+
+static int get_candidate(const double *a, const int ia[],
+                         int M, int N, int D,
+                         double lambda,
+                         int    (*f)(const double x[], const double a[],
+                                     double *result),
+                         int (*dfda)(const double x[], const double a[],
+                                     double result[]),
+                         const double *x,
+                         const double *y,
+                         const double *sigma,
+                         double *partials,
+                         cpl_matrix *alpha,
+                         cpl_matrix *beta,
+                         double *a_da);
+
+
+
+int
+sinfo_frame_is_raw_dark(char * tag);
+
+/**@{*/
+
+
+
+
+/*---------------------------------------------------------------------------*/
+/**
+ * @brief  Extract frames with given tag from frameset
+ * @param  frames      frame set
+ * @param  tag         to search for
+ * @return newly allocated, possibly empty, frameset, or NULL on error
+ */
+/*---------------------------------------------------------------------------*/
+cpl_frameset *
+sinfo_frameset_extract(const cpl_frameset *frames,
+                       const char *tag)
+{
+   cpl_frameset *subset = NULL;
+   const cpl_frame *f;
+
+
+
+   assure( frames != NULL, CPL_ERROR_ILLEGAL_INPUT, "Null frameset" );
+   assure( tag    != NULL, CPL_ERROR_ILLEGAL_INPUT, "Null tag" );
+
+   subset = cpl_frameset_new();
+
+   for (f = cpl_frameset_find_const(frames, tag);
+        f != NULL;
+        f = cpl_frameset_find_const(frames, NULL)) {
+
+      cpl_frameset_insert(subset, cpl_frame_duplicate(f));
+   }
+  cleanup:
+   return subset;
+}
+
+
+
+/**
+   @brief    Check if an error has happened and returns error kind and location
+   @param    val input value
+   @return   0 if no error is detected,-1 else
+*/
+int sinfo_print_rec_status(const int val) {
+   if(cpl_error_get_code() != CPL_ERROR_NONE) {
+      sinfo_msg_error("Recipe status at %d",val);
+      sinfo_msg_error("%s",(const char*) cpl_error_get_message());
+      sinfo_msg_error("%s",(const char*) cpl_error_get_where());
+      return -1;
+   }
+   return 0;
+}
+
+
+/**
+   @brief   Kappa-sigma clip of vector values
+   @param   vin      Input vector
+   @param   kappa   Value of kappa
+   @param   n       Number of iterations
+   @param   method  Possible method:
+
+   0: are rejected
+   values ||val-mean|| > kappa*sigma
+
+   1: are rejected
+   values ||val-median|| > kappa*sigma
+
+   @return  clipped vector
+*/
+
+cpl_vector*
+sinfo_vector_clip(const cpl_vector* vinp,
+                  const double kappa,
+                  const int n,
+                  const int method)
+{
+   cpl_vector* vout=NULL;
+   cpl_vector* vtmp=NULL;
+   int size=0;
+   int j=0;
+   register int i=0;
+
+   double mean=0;
+   double median=0;
+   double stdev=0;
+   double* pt=NULL;
+   double* po=NULL;
+
+   cknull(vinp,"Null input vector");
+   check_nomsg(vout=cpl_vector_duplicate(vinp));
+   check_nomsg(mean=cpl_vector_get_mean(vout));
+   check_nomsg(median=cpl_vector_get_median_const(vout));
+   check_nomsg(stdev=cpl_vector_get_stdev(vout));
+   check_nomsg(pt=cpl_vector_get_data(vtmp));
+
+   if(method == 0) {
+      /*
+         are rejected
+         values ||val-mean|| > kappa*sigma
+      */
+      for(j=0;j<n;j++) {
+
+         check_nomsg(cpl_vector_sort(vout,1));  /* sort by increasing data */
+         check_nomsg(po=cpl_vector_get_data(vout));
+
+         if( (size > 1) && (fabs(po[size-1]-mean) > kappa*stdev)) {
+
+            size--;
+            check_nomsg(vtmp=cpl_vector_new(size));
+            check_nomsg(pt=cpl_vector_get_data(vtmp));
+            for(i=0;i<size;i++) {
+               pt[i]=po[i];
+            }
+            check_nomsg(cpl_vector_delete(vout));
+            check_nomsg(vout=cpl_vector_duplicate(vtmp));
+            check_nomsg(cpl_vector_delete(vtmp));
+
+            check_nomsg(mean=cpl_vector_get_mean(vout));
+            check_nomsg(stdev=cpl_vector_get_stdev(vout));
+
+         }
+
+      }
+
+   } else {
+      /*
+         are rejected
+         values ||val-median|| > kappa*sigma
+      */
+
+
+      for(j=0;j<n;j++) {
+
+         check_nomsg(cpl_vector_sort(vout,1));  /* sort by increasing data */
+         check_nomsg(po=cpl_vector_get_data(vout));
+
+         if( (size > 1) && (fabs(po[size-1]-median) > kappa*stdev)) {
+
+            size--;
+            check_nomsg(vtmp=cpl_vector_new(size));
+            check_nomsg(pt=cpl_vector_get_data(vtmp));
+            for(i=0;i<size;i++) {
+               pt[i]=po[i];
+            }
+            check_nomsg(cpl_vector_delete(vout));
+            check_nomsg(vout=cpl_vector_duplicate(vtmp));
+            check_nomsg(cpl_vector_delete(vtmp));
+
+            check_nomsg(median=cpl_vector_get_median_const(vout));
+            check_nomsg(stdev=cpl_vector_get_stdev(vout));
+
+         }
+
+      }
+
+
+
+
+   }
+   return vout;
+  cleanup:
+   return NULL;
+
+
+}
+
+
+
+/*----------------------------------------------------------------------------*/
+/**
+   @brief   Get new position in parameter space (L-M algorithm)
+   @param   a       Current fit parameters.
+   @param   ia      Non-NULL array defining with non-zero values which
+   parameters participate in the fit.
+   @param   M       Number of fit parameters
+   @param   N       Number of positions
+   @param   D       Dimension of x-positions
+   @param   lambda  Lambda in L-M algorithm.
+   @param   f       Function that evaluates the fit function.
+   @param   dfda    Function that evaluates the partial derivaties
+   of the fit function w.r.t. fit parameters.
+   @param   x       The input positions (pointer to MxD matrix buffer).
+   @param   y       The N values to fit.
+   @param   sigma   A vector of size N containing the uncertainties of the
+   y-values. If NULL, a constant uncertainty equal to 1 is
+   assumed.
+   @param   partials The partial derivatives (work space).
+   @param   alpha   Alpha in L-M algorithm (work space).
+   @param   beta    Beta in L-M algorithm (work space).
+   @param   a_da    (output) Candidate position in parameter space.
+
+   @return  0 iff okay.
+
+   This function computes a potentially better set of parameters @em a + @em da,
+   where @em da solves the equation @em alpha(@em lambda) * @em da = @em beta .
+
+   Possible #_cpl_error_code_ set in this function:
+   - CPL_ERROR_ILLEGAL_INPUT if the fit function or its derivative could
+   not be evaluated.
+   - CPL_ERROR_SINGULAR_MATRIX if @em alpha is singular.
+
+*/
+/*----------------------------------------------------------------------------*/
+static int
+get_candidate(const double *a, const int ia[],
+              int M, int N, int D,
+              double lambda,
+              int    (*f)(const double x[], const double a[], double *result),
+              int (*dfda)(const double x[], const double a[], double result[]),
+              const double *x,
+              const double *y,
+              const double *sigma,
+              double *partials,
+              cpl_matrix *alpha,
+              cpl_matrix *beta,
+              double *a_da)
+{
+   int Mfit = 0;         /* Number of non-constant fit parameters */
+   cpl_matrix *da;       /* Solution of   alpha * da = beta */
+   double *alpha_data;
+   double *beta_data;
+   double *da_data;
+   int i, imfit = 0;
+   int j, jmfit = 0;
+   int k = 0;
+
+   /* For efficiency, don't check input in this static function */
+
+   Mfit = cpl_matrix_get_nrow(alpha);
+
+   alpha_data    = cpl_matrix_get_data(alpha);
+   beta_data     = cpl_matrix_get_data(beta);
+
+   /* Build alpha, beta:
+    *
+    *  alpha[i,j] = sum_{k=1,N} (sigma_k)^-2 * df/da_i * df/da_j  *
+    *                           (1 + delta_ij lambda) ,
+    *
+    *   beta[i]   = sum_{k=1,N} (sigma_k)^-2 * ( y_k - f(x_k) ) * df/da_i
+    *
+    * where (i,j) loop over the non-constant parameters (0 to Mfit-1),
+    * delta is Kronecker's delta, and all df/da are evaluated in x_k
+    */
+
+   cpl_matrix_fill(alpha, 0.0);
+   cpl_matrix_fill(beta , 0.0);
+
+   for (k = 0; k < N; k++)
+   {
+      double sm2 = 0.0;                /* (sigma_k)^-2 */
+      double fx_k = 0.0;               /* f(x_k)       */
+      const double *x_k = &(x[0+k*D]); /* x_k          */
+
+      if (sigma == NULL)
+      {
+         sm2 = 1.0;
+      }
+      else
+      {
+         sm2 = 1.0 / (sigma[k] * sigma[k]);
+      }
+
+      /* Evaluate f(x_k) */
+      cpl_ensure( f(x_k, a, &fx_k) == 0, CPL_ERROR_ILLEGAL_INPUT, -1);
+
+      /* Evaluate (all) df/da (x_k) */
+      cpl_ensure( dfda(x_k, a, partials) == 0,
+                  CPL_ERROR_ILLEGAL_INPUT, -1);
+
+      for (i = 0, imfit = 0; i < M; i++)
+      {
+         if (ia[i] != 0)
+         {
+            /* Beta */
+            beta_data[imfit] +=
+               sm2 * (y[k] - fx_k) * partials[i];
+
+            /* Alpha is symmetrical, so compute
+               only lower-left part */
+            for (j = 0, jmfit = 0; j < i; j++)
+            {
+               if (ia[j] != 0)
+               {
+                  alpha_data[jmfit + imfit*Mfit] +=
+                     sm2 * partials[i] *
+                     partials[j];
+
+                  jmfit += 1;
+               }
+            }
+
+            /* Alpha, diagonal terms */
+            j = i;
+            jmfit = imfit;
+
+            alpha_data[jmfit + imfit*Mfit] +=
+               sm2 * partials[i] *
+               partials[j] * (1 + lambda);
+
+            imfit += 1;
+         }
+      }
+
+      assert( imfit == Mfit );
+   }
+
+   /* Create upper-right part of alpha */
+   for (i = 0, imfit = 0; i < M; i++) {
+      if (ia[i] != 0) {
+         for (j = i+1, jmfit = imfit+1; j < M; j++) {
+            if (ia[j] != 0) {
+               alpha_data[jmfit+imfit*Mfit] = alpha_data[imfit+jmfit*Mfit];
+               jmfit += 1;
+            }
+         }
+         assert( jmfit == Mfit );
+         imfit += 1;
+      }
+   }
+   assert( imfit == Mfit );
+
+   da = cpl_matrix_solve(alpha, beta);
+
+   cpl_ensure(da != NULL, cpl_error_get_code(), -1);
+
+   /* Create a+da vector by adding a and da */
+   da_data   = cpl_matrix_get_data(da);
+
+   for (i = 0, imfit = 0; i < M; i++)
+   {
+      if (ia[i] != 0)
+      {
+         a_da[i] = a[i] + da_data[0 + imfit*1];
+
+         imfit += 1;
+      }
+      else
+      {
+         a_da[i] = a[i];
+      }
+   }
+
+   assert( imfit == Mfit );
+
+   cpl_matrix_delete(da);
+
+   return 0;
+}
+
+/*----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------*/
+/**
+   @brief   Compute chi square
+   @param   N       Number of positions
+   @param   D       Dimension of x-positions
+   @param   f       Function that evaluates the fit function.
+   @param   a       The fit parameters.
+   @param   x       Where to evaluate the fit function (N x D matrix).
+   @param   y       The N values to fit.
+   @param   sigma   A vector of size N containing the uncertainties of the
+   y-values. If NULL, a constant uncertainty equal to 1 is
+   assumed.
+
+   @return  chi square, or a negative number on error.
+
+   This function calculates chi square defined as
+   sum_i (y_i - f(x_i, a))^2/sigma_i^2
+
+   Possible #_cpl_error_code_ set in this function:
+   - CPL_ERROR_ILLEGAL_INPUT if the fit function could not be evaluated
+*/
+/*----------------------------------------------------------------------------*/
+
+static double
+get_chisq(int N, int D,
+          int (*f)(const double x[], const double a[], double *result),
+          const double *a,
+          const double *x,
+          const double *y,
+          const double *sigma)
+{
+   double chi_sq;     /* Result */
+   int i = 0;
+
+   /* For efficiency, don't check input in this static function */
+   chi_sq = 0.0;
+   for (i = 0; i < N; i++)
+   {
+      double fx_i;
+      double residual;                 /* Residual in units of uncertainty */
+      const double *x_i = &(x[0+i*D]);
+
+      /* Evaluate */
+      cpl_ensure( f(x_i,
+                    a,
+                    &fx_i) == 0, CPL_ERROR_ILLEGAL_INPUT, -1.0);
+
+      /* Accumulate */
+      if (sigma == NULL)
+      {
+         residual = (fx_i - y[i]);
+      }
+      else
+      {
+         residual = (fx_i - y[i]) / sigma[i];
+      }
+
+      chi_sq += residual*residual;
+
+   }
+
+   return chi_sq;
+}
+
+
+
+#ifndef CPL_VECTOR_FIT_MAXITER
+#define CPL_VECTOR_FIT_MAXITER 1000
+#endif
+/*----------------------------------------------------------------------------*/
+/**
+   @brief   Fit a function to a set of data
+   @param   x        N x D matrix of the positions to fit.
+   Each matrix row is a D-dimensional position.
+   @param   sigma_x  Uncertainty (one sigma, gaussian errors assumed)
+   assosiated with @em x. Taking into account the
+   uncertainty of the independent variable is currently
+   unsupported, and this parameter must therefore be set
+   to NULL.
+   @param   y        The N values to fit.
+   @param   sigma_y  Vector of size N containing the uncertainties of
+   the y-values. If this parameter is NULL, constant
+   uncertainties are assumed.
+   @param   a        Vector containing M fit parameters. Must contain
+   a guess solution on input and contains the best
+   fit parameters on output.
+   @param   ia       Array of size M defining which fit parameters participate
+   in the fit (non-zero) and which fit parameters are held
+   constant (zero). At least one element must be non-zero.
+   Alternatively, pass NULL to fit all parameters.
+   @param   f        Function that evaluates the fit function
+   at the position specified by the first argument (an array of
+   size D) using the fit parameters specified by the second
+   argument (an array of size M). The result must be output
+   using the third parameter, and the function must return zero
+   iff the evaluation succeded.
+   @param   dfda     Function that evaluates the first order partial
+   derivatives of the fit function with respect to the fit
+   parameters at the position specified by the first argument
+   (an array of size D) using the parameters specified by the
+   second argument (an array of size M). The result must
+   be output using the third parameter (array of size M), and
+   the function must return zero iff the evaluation succeded.
+   @param mse        If non-NULL, the mean squared error of the best fit is
+   computed.
+   @param red_chisq  If non-NULL, the reduced chi square of the best fit is
+   computed. This requires @em sigma_y to be specified.
+   @param covariance If non-NULL, the formal covariance matrix of the best
+   fit parameters is computed (or NULL on error). On success
+   the diagonal terms of the covariance matrix are guaranteed
+   to be positive. However, terms that involve a constant
+   parameter (as defined by the input array @em ia) are
+   always set to zero. Computation of the covariacne matrix
+   requires @em sigma_y to be specified.
+
+
+   @return  CPL_ERROR_NONE iff OK.
+
+   This function makes a minimum chi squared fit of the specified function
+   to the specified data set using the Levenberg-Marquardt algorithm.
+
+   Possible #_cpl_error_code_ set in this function:
+   - CPL_ERROR_NULL_INPUT if an input pointer other than @em sigma_x, @em
+   sigma_y, @em mse, @em red_chisq or @em covariance is NULL.
+   - CPL_ERROR_ILLEGAL_INPUT if an input matrix/vector is empty, if @em ia
+   contains only zero values, if N <= M and @em red_chisq is non-NULL,
+   if any element of @em sigma_x or @em sigma_y is non-positive, or if
+   evaluation of the fit function or its derivative failed.
+   - CPL_ERROR_INCOMPATIBLE_INPUT if the dimensions of the input
+   vectors/matrices do not match, or if chi square or covariance computation
+   is requested and @em sigma_y is NULL.
+   - CPL_ERROR_ILLEGAL_OUTPUT if memory allocation failed.
+   - CPL_ERROR_CONTINUE if the Levenberg-Marquardt algorithm failed to converge.
+   - CPL_ERROR_SINGULAR_MATRIX if the covariance matrix could not be computed.
+
+*/
+/*----------------------------------------------------------------------------*/
+cpl_error_code
+sinfo_fit_lm(const cpl_matrix *x,
+             const cpl_matrix *sigma_x,
+             const cpl_vector *y,
+             const cpl_vector *sigma_y,
+             cpl_vector *a,
+             const int ia[],
+             int    (*f)(const double x[],
+                         const double a[],
+                         double *result),
+             int (*dfda)(const double x[],
+                         const double a[],
+                         double result[]),
+             double *mse,
+             double *red_chisq,
+             cpl_matrix **covariance)
+{
+   const double *x_data     = NULL; /* Pointer to input data                  */
+   const double *y_data     = NULL; /* Pointer to input data                  */
+   const double *sigma_data = NULL; /* Pointer to input data                  */
+   int N    = 0;                    /* Number of data points                  */
+   int D    = 0;                    /* Dimension of x-points                  */
+   int M    = 0;                    /* Number of fit parameters               */
+   int Mfit = 0;                    /* Number of non-constant fit
+                                       parameters                             */
+
+   double lambda    = 0.0;          /* Lambda in L-M algorithm                */
+   double MAXLAMBDA = 10e40;        /* Parameter to control the graceful exit
+                                       if steepest descent unexpectedly fails */
+   double chi_sq    = 0.0;          /* Current  chi^2                         */
+   int count        = 0;            /* Number of successive small improvements
+                                       in chi^2 */
+   int iterations   = 0;
+
+   cpl_matrix *alpha  = NULL;       /* The MxM ~curvature matrix used in L-M  */
+   cpl_matrix *beta   = NULL;       /* Mx1 matrix = -.5 grad(chi^2)           */
+   double *a_data     = NULL;       /* Parameters, a                          */
+   double *a_da       = NULL;       /* Candidate position a+da                */
+   double *part       = NULL;       /* The partial derivatives df/da          */
+   int *ia_local      = NULL;       /* non-NULL version of ia                 */
+
+   /* If covariance computation is requested, then either
+    * return the covariance matrix or return NULL.
+    */
+   if (covariance != NULL) *covariance = NULL;
+
+   /* Validate input */
+   cpl_ensure_code(x       != NULL, CPL_ERROR_NULL_INPUT);
+   cpl_ensure_code(sigma_x == NULL, CPL_ERROR_UNSUPPORTED_MODE);
+   cpl_ensure_code(y       != NULL, CPL_ERROR_NULL_INPUT);
+   cpl_ensure_code(a       != NULL, CPL_ERROR_NULL_INPUT);
+   /* ia may be NULL */
+   cpl_ensure_code(f       != NULL, CPL_ERROR_NULL_INPUT);
+   cpl_ensure_code(dfda    != NULL, CPL_ERROR_NULL_INPUT);
+
+   /* Chi^2 and covariance computations require sigmas to be known */
+   cpl_ensure_code( sigma_y != NULL ||
+                    (red_chisq == NULL && covariance == NULL),
+                    CPL_ERROR_INCOMPATIBLE_INPUT);
+
+   D = cpl_matrix_get_ncol(x);
+   N = cpl_matrix_get_nrow(x);
+   M = cpl_vector_get_size(a);
+   cpl_ensure_code(N > 0 && D > 0 && M > 0, CPL_ERROR_ILLEGAL_INPUT);
+
+   cpl_ensure_code( cpl_vector_get_size(y) == N,
+                    CPL_ERROR_INCOMPATIBLE_INPUT);
+
+   x_data = cpl_matrix_get_data_const(x);
+   y_data = cpl_vector_get_data_const(y);
+   a_data = cpl_vector_get_data(a);
+
+   if (sigma_y != NULL)
+   {
+      cpl_ensure_code( cpl_vector_get_size(sigma_y) == N,
+                       CPL_ERROR_INCOMPATIBLE_INPUT);
+      /* Sigmas must be positive */
+      cpl_ensure_code( cpl_vector_get_min (sigma_y) > 0,
+                       CPL_ERROR_ILLEGAL_INPUT);
+      sigma_data = cpl_vector_get_data_const(sigma_y);
+   }
+
+   ia_local = cpl_malloc(M * sizeof(int));
+   cpl_ensure_code(ia_local != NULL, CPL_ERROR_ILLEGAL_OUTPUT);
+
+   /* Count non-constant fit parameters, copy ia */
+   if (ia != NULL)
+   {
+      int i;
+
+      Mfit = 0;
+      for (i = 0; i < M; i++)
+      {
+         ia_local[i] = ia[i];
+
+         if (ia[i] != 0)
+         {
+            Mfit += 1;
+         }
+      }
+
+      if (! (Mfit > 0))
+      {
+         cpl_free(ia_local);
+         cpl_ensure_code( CPL_FALSE,
+                          CPL_ERROR_ILLEGAL_INPUT);
+      }
+   }
+   else
+   {
+      /* All parameters participate */
+      int i;
+
+      Mfit = M;
+
+      for (i = 0; i < M; i++)
+      {
+         ia_local[i] = 1;
+      }
+   }
+
+   /* To compute reduced chi^2, we need N > Mfit */
+   if (! ( red_chisq == NULL || N > Mfit ) )
+   {
+      cpl_free(ia_local);
+      cpl_ensure_code(
+         CPL_FALSE,
+         CPL_ERROR_ILLEGAL_INPUT);
+   }
+
+   /* Create alpha, beta, a_da, part  work space */
+   alpha = cpl_matrix_new(Mfit, Mfit);
+   if (alpha == NULL)
+   {
+      cpl_free(ia_local);
+      cpl_ensure_code(
+         CPL_FALSE,
+         CPL_ERROR_ILLEGAL_OUTPUT);
+   }
+
+   beta = cpl_matrix_new(Mfit, 1);
+   if (beta == NULL)
+   {
+      cpl_free(ia_local);
+      cpl_matrix_delete(alpha);
+      cpl_ensure_code(
+         CPL_FALSE,
+         CPL_ERROR_ILLEGAL_OUTPUT);
+   }
+
+   a_da = cpl_malloc(M * sizeof(double));
+   if (a_da == NULL)
+   {
+      cpl_free(ia_local);
+      cpl_matrix_delete(alpha);
+      cpl_matrix_delete(beta);
+      cpl_ensure_code(
+         CPL_FALSE,
+         CPL_ERROR_ILLEGAL_OUTPUT);
+   }
+
+   part = cpl_malloc(M * sizeof(double));
+   if (part == NULL)
+   {
+      cpl_free(ia_local);
+      cpl_matrix_delete(alpha);
+      cpl_matrix_delete(beta);
+      cpl_free(a_da);
+      cpl_ensure_code(
+         CPL_FALSE,
+         CPL_ERROR_ILLEGAL_OUTPUT);
+   }
+
+   /* Initialize loop variables */
+   lambda = 0.001;
+   count = 0;
+   iterations = 0;
+   if( (chi_sq = get_chisq(N, D, f, a_data, x_data, y_data, sigma_data)) < 0)
+   {
+      cpl_free(ia_local);
+      cpl_matrix_delete(alpha);
+      cpl_matrix_delete(beta);
+      cpl_free(a_da);
+      cpl_free(part);
+      cpl_ensure_code(
+         CPL_FALSE,
+         cpl_error_get_code());
+   }
+
+   /* uves_msg_debug("Initial chi^2 = %f", chi_sq); */
+
+   /* Iterate until chi^2 didn't improve substantially many (say, 5)
+      times in a row */
+   while (count < 5 &&
+          lambda < MAXLAMBDA &&
+          iterations < CPL_VECTOR_FIT_MAXITER)
+   {
+      /* In each iteration lambda increases, or chi^2 decreases or
+         count increases. Because chi^2 is bounded from below
+         (and lambda and count from above), the loop will terminate */
+
+      double chi_sq_candidate = 0.0;
+      int returncode = 0;
+
+      /* Get candidate position in parameter space = a+da,
+       * where  alpha * da = beta .
+       * Increase lambda until alpha is non-singular
+       */
+
+      while( (returncode = get_candidate(a_data, ia_local,
+                                         M, N, D,
+                                         lambda, f, dfda,
+                                         x_data, y_data, sigma_data,
+                                         part, alpha, beta, a_da)
+                ) != 0
+             && cpl_error_get_code() == CPL_ERROR_SINGULAR_MATRIX
+             && lambda < MAXLAMBDA)
+      {
+         /* uves_msg_debug("Singular matrix. lambda = %e", lambda); */
+         cpl_error_reset();
+         lambda *= 9.0;
+      }
+
+      /* Set error if lambda diverged */
+      if ( !( lambda < MAXLAMBDA ) )
+      {
+         cpl_free(ia_local);
+         cpl_matrix_delete(alpha);
+         cpl_matrix_delete(beta);
+         cpl_free(a_da);
+         cpl_free(part);
+         cpl_ensure_code(
+            CPL_FALSE,
+            CPL_ERROR_CONTINUE);
+      }
+
+      if (returncode != 0)
+      {
+         cpl_free(ia_local);
+         cpl_matrix_delete(alpha);
+         cpl_matrix_delete(beta);
+         cpl_free(a_da);
+         cpl_free(part);
+         cpl_ensure_code(
+            CPL_FALSE,
+            cpl_error_get_code());
+      }
+
+      /* Get chi^2(a+da) */
+      if ((chi_sq_candidate = get_chisq(N, D, f, a_da,
+                                        x_data, y_data, sigma_data)) < 0)
+      {
+         cpl_free(ia_local);
+         cpl_matrix_delete(alpha);
+         cpl_matrix_delete(beta);
+         cpl_free(a_da);
+         cpl_free(part);
+         cpl_ensure_code(
+            CPL_FALSE,
+            cpl_error_get_code());
+      }
+
+      /* uves_msg_debug("Chi^2 = %f  Candidate = %f  Lambda = %e",
+         chi_sq, chi_sq_candidate, lambda);  */
+
+      if (chi_sq_candidate > chi_sq)
+      {
+         /* Move towards steepest descent */
+         lambda *= 9.0;
+      }
+      else
+      {
+         /* Move towards Newton's algorithm */
+         lambda /= 10.0;
+
+         /* Count the number of successive improvements in chi^2 of
+            less than 0.01 relative */
+         if ( chi_sq == 0 ||
+              (chi_sq - chi_sq_candidate)/chi_sq < .01)
+         {
+            count += 1;
+         }
+         else
+         {
+            /* Chi^2 improved by a significant amount,
+               reset counter */
+            count = 0;
+         }
+
+         /* chi^2 improved, update a and chi^2 */
+         {
+            int i;
+            for (i = 0; i < M; i++) a_data[i] = a_da[i];
+         }
+         chi_sq = chi_sq_candidate;
+      }
+      iterations++;
+   }
+
+   /* Set error if we didn't converge */
+   if ( !( lambda < MAXLAMBDA && iterations < CPL_VECTOR_FIT_MAXITER ) )
+   {
+      cpl_free(ia_local);
+      cpl_matrix_delete(alpha);
+      cpl_matrix_delete(beta);
+      cpl_free(a_da);
+      cpl_free(part);
+      cpl_ensure_code(
+         CPL_FALSE,
+         CPL_ERROR_CONTINUE);
+   }
+
+   /* Compute mse if requested */
+   if (mse != NULL)
+   {
+      int i;
+
+      *mse = 0.0;
+
+      for(i = 0; i < N; i++)
+      {
+         double fx_i = 0.0;
+         double residual = 0.0;
+
+         /* Evaluate f(x_i) at the best fit parameters */
+         if( f(&(x_data[i*D]),
+               a_data,
+               &fx_i) != 0)
+         {
+            cpl_free(ia_local);
+            cpl_matrix_delete(alpha);
+            cpl_matrix_delete(beta);
+            cpl_free(a_da);
+            cpl_free(part);
+            cpl_ensure_code(
+               CPL_FALSE,
+               CPL_ERROR_ILLEGAL_INPUT);
+         }
+
+         residual = y_data[i] - fx_i;
+         *mse += residual * residual;
+      }
+      *mse /= N;
+   }
+
+   /* Compute reduced chi^2 if requested */
+   if (red_chisq != NULL)
+   {
+      /* We already know the optimal chi^2 (and that N > Mfit)*/
+      *red_chisq = chi_sq / (N-Mfit);
+   }
+
+   /* Compute covariance matrix if requested
+    * cov = alpha(lambda=0)^-1
+    */
+   if (covariance != NULL)
+   {
+      cpl_matrix *cov;
+
+      if( get_candidate(a_data, ia_local,
+                        M, N, D, 0.0, f, dfda,
+                        x_data, y_data, sigma_data,
+                        part, alpha, beta, a_da)
+          != 0)
+      {
+         cpl_free(ia_local);
+         cpl_matrix_delete(alpha);
+         cpl_matrix_delete(beta);
+         cpl_free(a_da);
+         cpl_free(part);
+         cpl_ensure_code(
+            CPL_FALSE,
+            cpl_error_get_code());
+      }
+
+      cov = cpl_matrix_invert_create(alpha);
+      if (cov == NULL)
+      {
+         cpl_free(ia_local);
+         cpl_matrix_delete(alpha);
+         cpl_matrix_delete(beta);
+         cpl_free(a_da);
+         cpl_free(part);
+         cpl_ensure_code(
+            CPL_FALSE,
+            cpl_error_get_code());
+      }
+
+      /* Make sure that variances are positive */
+      {
+         int i;
+         for (i = 0; i < Mfit; i++)
+         {
+            if ( !(cpl_matrix_get(cov, i, i) > 0) )
+            {
+               cpl_free(ia_local);
+               cpl_matrix_delete(alpha);
+               cpl_matrix_delete(beta);
+               cpl_free(a_da);
+               cpl_free(part);
+               cpl_matrix_delete(cov);
+               *covariance = NULL;
+               cpl_ensure_code(
+                  CPL_FALSE,
+                  CPL_ERROR_SINGULAR_MATRIX);
+            }
+         }
+      }
+
+      /* Expand covariance matrix from Mfit x Mfit
+         to M x M. Set rows/columns corresponding to fixed
+         parameters to zero */
+
+      *covariance = cpl_matrix_new(M, M);
+      if (*covariance == NULL)
+      {
+         cpl_free(ia_local);
+         cpl_matrix_delete(alpha);
+         cpl_matrix_delete(beta);
+         cpl_free(a_da);
+         cpl_free(part);
+         cpl_matrix_delete(cov);
+         cpl_ensure_code(
+            CPL_FALSE,
+            CPL_ERROR_ILLEGAL_OUTPUT);
+      }
+
+      {
+         int j, jmfit;
+
+         for (j = 0, jmfit = 0; j < M; j++)
+            if (ia_local[j] != 0)
+            {
+               int i, imfit;
+
+               for (i = 0, imfit = 0; i < M; i++)
+                  if (ia_local[i] != 0)
+                  {
+                     cpl_matrix_set(*covariance, i, j,
+                                    cpl_matrix_get(
+                                       cov, imfit, jmfit));
+                     imfit += 1;
+                  }
+
+               assert( imfit == Mfit );
+
+               jmfit += 1;
+            }
+
+         assert( jmfit == Mfit );
+      }
+
+      cpl_matrix_delete(cov);
+   }
+
+   cpl_free(ia_local);
+   cpl_matrix_delete(alpha);
+   cpl_matrix_delete(beta);
+   cpl_free(a_da);
+   cpl_free(part);
+
+   return CPL_ERROR_NONE;
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+/*-------------------------------------------------------------------------*/
+
+/**
+   @name        sinfo_fit_amoeba_get_psum
+   @memo        computes sum of p values
+   @param        ndim vector's dimension
+   @param        mpts No of points
+   @param        p matrix of size [1...ndim+1][1...ndim]
+   @param        psum result
+   @return    void
+
+*/
+
+static void
+sinfo_fit_amoeba_get_psum(int ndim, int mpts, double** p, double* psum)
+{
+   int i=0;
+   int j=0;
+   double sum=0;
+   for (j=0;j<ndim;j++) {
+      for (sum=0.0,i=0;i<mpts;i++) {
+         sum += p[i][j];
+      }
+      psum[j]=sum;
+   }
+
+}
+
+
+#define SINFO_FIT_AMOEBA_SWAP(a,b) {swap=(a);(a)=(b);(b)=swap;}
+
+
+
+/**
+   @name        sinfo_fit_amoeba
+   @memo        Imp-lements amoeba function for multidimensional minimizzation
+   @param        p matrix of size [1...ndim+1][1...ndim]
+   @param        y vector[1...ndim+1]
+   @param        psum
+   @param        ndim vector's dimension
+   @param        funk function to be minimized
+   @param        ihi
+   @param        fac
+   @return    int 0, 1, or -1
+   @doc
+   Multidimensional minimizzation of the function funk(x) where x[1..ndim] is
+   a vector in ndim dimensions, by the downhill simplex method of Nedler and
+   Mead. The matrix p[1..ndim+1][1..ndim] is input. Its ndim+1 rows are
+   ndim-dimensional vectors which are the vertices of the starting simplex.
+   Also input is the vector y[1..ndim+1], whose components must be
+   pre-initialized to the values of funk avaluated at the ndim+1 vertices (rows)
+   of p; and ftol the fractional convergence tolerance to be achieved in the
+   function value (N.B.). On output, p and y will have been reset to ndim+1 new
+   points all within ftol of a minimum function value, and nfunc gives the
+   number of functions taken.
+
+*/
+
+
+void
+sinfo_fit_amoeba(
+   double**p,
+   double y[],
+   int ndim,
+   double ftol,
+   double (*funk)(double[]),
+   int* nfunk)
+{
+
+
+   int i=0;
+   int ihi=0;
+   int ilo=0;
+   int inhi=0;
+   int j=0;
+   int mpts=ndim+1;
+   double rtol=0;
+   double swap=0;
+   double ysave=0;
+   double ytry=0;
+   cpl_vector* sum=NULL;
+   double* psum=NULL;
+
+   sum=cpl_vector_new(ndim);
+   psum=cpl_vector_get_data(sum);
+   *nfunk=0;
+
+   sinfo_fit_amoeba_get_psum(ndim,mpts,p,psum);
+
+   for(;;) {
+      ilo=0;
+      /*
+        First we must determine which point is the highest (worst),
+        next-highest, and lowest (best), by looping over the points
+        in the simplex
+      */
+      ihi=y[0]>y[1] ? (inhi=1,0) : (inhi=0,1);
+
+      for (i=0;i< mpts;i++) {
+         if (y[i] <= y[ilo]) ilo=i;
+         if (y[i] > y[ihi]) {
+            inhi=ihi;
+            ihi=i;
+         } else if (y[i] > y[inhi] && i != ihi) inhi=i;
+      }
+      rtol=2.0*fabs(y[ihi]-y[ilo])/(fabs(y[ihi])+fabs(y[ilo]));
+
+      /*
+        compute the fractional range from highest to lowest and return if
+        satisfactory
+      */
+      if(rtol < ftol) { // if returning, but best point and value is in slot 1
+         SINFO_FIT_AMOEBA_SWAP(y[0],y[ilo]);
+         for (i=0;i<ndim;i++) SINFO_FIT_AMOEBA_SWAP(p[1][i],p[ilo][i]);
+         break;
+      }
+      if (*nfunk >= SINFO_FIT_AMOEBA_NMAX) {
+         sinfo_msg_error("NMAX exceeded");
+         SINFO_FIT_AMOEBA_SWAP(y[0],y[ilo]);
+         for (i=0;i<ndim;i++) SINFO_FIT_AMOEBA_SWAP(p[1][i],p[ilo][i]);
+         for (i=0;i<ndim;i++) {
+            sinfo_msg("p[1][i]=%g p[ilo][i]=%g ilo=%d",p[1][i],p[ilo][i],ilo);
+         }
+         assure(*nfunk >= SINFO_FIT_AMOEBA_NMAX,CPL_ERROR_UNSPECIFIED,
+                "NMAX exceeded");
+         break;
+
+      }
+      *nfunk +=2;
+      /*
+        Begin a new iteration. First extrapolate by a Factor -1 through the face
+        of the simplex across the high point, i.e. reflect the simplex from the
+        high point
+      */
+      ytry=sinfo_fit_amotry(p,y,psum,ndim,funk,ihi,-1.0);
+      if(ytry <= y[ilo]) {
+         /*
+            Gives a result better than the best point, so try an additional
+            extrapolation by a factor 2
+         */
+         ytry=sinfo_fit_amotry(p,y,psum,ndim,funk,ihi,2.0);
+      } else if (ytry >= y[inhi]) {
+
+         /*
+           The reflected point is worse than the second highest, so look for an
+           intermediate lower point, i.e. do a one-dimensional contraction
+         */
+         ysave=y[ihi];
+         ytry=sinfo_fit_amotry(p,y,psum,ndim,funk,ihi,0.5);
+         if(ytry >= ysave) {
+            /*
+               Can't seem to get rid of that high point.
+               Better contract around the lowest (best) point
+            */
+            for(i=0;i<mpts;i++) {
+               if(i != ilo) {
+                  for( j=0;j<ndim;j++) {
+                     p[i][j]=psum[j]=0.5*(p[i][j]+p[ilo][j]);
+                  }
+                  y[i]=(*funk)(psum);
+               }
+            }
+            *nfunk += ndim; /* Keep track of function evaluations */
+            sinfo_fit_amoeba_get_psum(ndim,mpts,p,psum);/* Recomputes psum */
+         }
+      } else {
+         --(*nfunk);
+         /* Go back for the test of doneness and the next iteration */
+      }
+   }
+  cleanup:
+   cpl_vector_delete(sum);
+}
+
+
+static  double
+sinfo_fit_amotry(double** p, double y[], double psum[], int ndim,
+                 double (*funk)(double[]),int ihi, double fac)
+{
+   int j;
+   double fac1=0;
+   double fac2=0;
+   double ytry=0;
+   cpl_vector * vtry=NULL;
+   double *ptry=NULL;
+
+   vtry=cpl_vector_new(ndim);
+   ptry=cpl_vector_get_data(vtry);
+
+   fac1=(1.0-fac)/ndim;
+   fac2=fac1-fac;
+
+   for (j=0;j<ndim;j++) {
+      ptry[j]=psum[j]*fac1-p[ihi][j]*fac2;
+   }
+   ytry=(*funk)(ptry);
+   if (ytry < y[ihi]) {
+      y[ihi]=ytry;
+      for (j=0;j<ndim;j++) {
+         psum[j] += ptry[j]-p[ihi][j];
+         p[ihi][j]=ptry[j];
+      }
+   }
+   sinfo_free_my_vector(&vtry);
+   return ytry;
+}
+
+/*-------------------------------------------------------------------------*/
+/*-------------------------------------------------------------------------*/
+/**
+   @name        sinfo_vector_dindgen
+   @memo        Fill a vector with values from 0 to vector_size-1
+   @param    v vector to be filled
+   @return    int 0, -1
+   @doc
+
+   Returns in case of succes -1 else.
+*/
+/*--------------------------------------------------------------------------*/
+
+int sinfo_vector_dindgen(cpl_vector** v)
+{
+
+   int sz=0;
+   int i=0;
+
+   cknull(*v,"Null input vector");
+   check(sz=cpl_vector_get_size(*v),"Getting size of a vector");
+
+   for(i=0;i<sz;i++) {
+      cpl_vector_set(*v,i,(double)i);
+   }
+
+   return 0;
+  cleanup:
+   return -1;
+
+}
+
+/*-------------------------------------------------------------------------*/
+/**
+   @name        sinfo_is_fits_file
+   @memo        returns 1 if file is in FITS format, 0 else
+   @param    filename name of the file to check
+   @return    int 0, 1, or -1
+   @doc
+
+   Returns 1 if the file name corresponds to a valid FITS file. Returns
+   0 else. If the file does not exist, returns -1.
+*/
+/*--------------------------------------------------------------------------*/
+
+int sinfo_is_fits_file(const char *filename)
+{
+   FILE    *fp ;
+   char    *magic ;
+   int        isfits ;
+
+   if ((fp = fopen(filename, "r"))==NULL) {
+      sinfo_msg_error("cannot open file [%s]", filename) ;
+      return -1 ;
+   }
+
+   magic = cpl_calloc(FITS_MAGIC_SZ+1, sizeof(char)) ;
+   (void)fread(magic, 1, FITS_MAGIC_SZ, fp) ;
+   (void)fclose(fp) ;
+   magic[FITS_MAGIC_SZ] = (char)0 ;
+   if (strstr(magic, "SIMPLE")!=NULL)
+      isfits = 1 ;
+   else
+      isfits = 0 ;
+   cpl_free(magic) ;
+   return isfits ;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Extracts raw frames
+   @param    set     The input frameset
+   @return   CPL_ERROR_NONE iff ok
+*/
+/*---------------------------------------------------------------------------*/
+cpl_error_code
+sinfo_table_correl(cpl_table * t1, cpl_table* t2, cpl_table* range,double* xcor)
+{
+
+   double wsr=0;
+   double wer=0;
+   int nr=0;
+   int i=0;
+   int status=0;
+   int nrows=0;
+   double mean=0;
+   double prod=0;
+
+   cpl_table* tmp_t1=NULL;
+   cpl_table* tmp_t2=NULL;
+
+   check_nomsg(nr=cpl_table_get_nrow(range));
+   for(i=0;i<nr;i++) {
+      wsr=cpl_table_get_double(range,"WSTART",i,&status);
+      wer=cpl_table_get_double(range,"WEND",i,&status);
+      cpl_table_and_selected_double(t1,"WAVE",CPL_NOT_LESS_THAN,wsr);
+      cpl_table_and_selected_double(t1,"WAVE",CPL_NOT_GREATER_THAN,wer);
+      tmp_t1=cpl_table_extract_selected(t1);
+      cpl_table_and_selected_double(t2,"WAVE",CPL_NOT_LESS_THAN,wsr);
+      cpl_table_and_selected_double(t2,"WAVE",CPL_NOT_GREATER_THAN,wer);
+      tmp_t2=cpl_table_extract_selected(t2);
+      cpl_table_duplicate_column(tmp_t1,"INT1",tmp_t1,"INT");
+      cpl_table_duplicate_column(tmp_t1,"INT2",tmp_t2,"INT");
+      cpl_table_multiply_columns(tmp_t1,"INT1","INT2");
+      mean=cpl_table_get_column_mean(tmp_t1,"INT1");
+      nrows=cpl_table_get_nrow(tmp_t1);
+      prod=mean*nrows;
+      *xcor+=prod;
+   }
+
+  cleanup:
+   return cpl_error_get_code();
+}
+/**
+   @brief    Extracts raw frames
+   @param    set     The input frameset
+   @return   CPL_ERROR_NONE iff ok
+*/
+/*----------------------------------------------------------------------------*/
+cpl_error_code
+sinfo_frameset_merge(cpl_frameset * set1, cpl_frameset* set2)
+{
+
+   cpl_frame* frm_tmp=NULL;
+   cpl_frame* frm_dup=NULL;
+
+   passure(set1 != NULL, "Wrong input set");
+
+   check_nomsg(frm_tmp = cpl_frameset_get_first(set2));
+   while (frm_tmp != NULL)
+   {
+      frm_dup=cpl_frame_duplicate(frm_tmp);
+      cpl_frameset_insert(set1,frm_dup);
+      frm_tmp = cpl_frameset_get_next(set2);
+   }
+
+  cleanup:
+   return cpl_error_get_code();
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+   @brief    Extracts frames of a given type
+   @param    set     The input frameset
+   @param    ext     The output frameset
+   @param    type    The frame type
+   @return   CPL_ERROR_NONE iff ok
+*/
+/*----------------------------------------------------------------------------*/
+
+cpl_error_code
+sinfo_extract_frames_group_type(const cpl_frameset * set,
+                                cpl_frameset** ext,
+                                cpl_frame_group type)
+{
+   const cpl_frame* frm_tmp=NULL;
+   cpl_frame* frm_dup=NULL;
+   cpl_frame_group g;
+
+   check_nomsg(*ext = cpl_frameset_new());
+   check_nomsg(frm_tmp = cpl_frameset_get_first_const(set));
+   while (frm_tmp != NULL)
+   {
+      g=cpl_frame_get_group(frm_tmp);
+      if(g == type) {
+         frm_dup=cpl_frame_duplicate(frm_tmp);
+         cpl_frameset_insert(*ext,frm_dup);
+         sinfo_msg_debug("group %d insert file %s ",
+                         type,cpl_frame_get_filename(frm_dup));
+      }
+      frm_tmp = cpl_frameset_get_next_const(set);
+   }
+
+  cleanup:
+   return cpl_error_get_code();
+}
+
+
+
+
+/**
+   @brief    Get what object shift
+   @param    iml imagelist
+   @param    n   imagelist sequence
+   @param    qclog_tbl qclog table
+   @return   0 if standard 0 if pixel scale changes in input Strehl data
+*/
+
+
+
+int
+sinfo_get_pupil_shift(cpl_imagelist* iml,const int n,cpl_table** qclog_tbl)
+{
+   cpl_size max_ima_x=0;
+   cpl_size max_ima_y=0;
+   int nx=0;
+   int ny=0;
+
+   double xshift=0;
+   double yshift=0;
+
+   double max_ima_cx=0;
+   double max_ima_cy=0;
+
+   cpl_image* img=NULL;
+   cpl_image* img_dup=NULL;
+
+   char key_name[FILE_NAME_SZ];
+
+   img=cpl_imagelist_collapse_median_create(iml);
+   nx=cpl_image_get_size_x(img);
+   ny=cpl_image_get_size_y(img);
+
+   img_dup=cpl_image_duplicate(img);
+   sinfo_clean_nan(&img_dup);
+   cpl_image_get_maxpos(img_dup,&max_ima_x,&max_ima_y);
+   max_ima_cx=cpl_image_get_centroid_x_window(img_dup,1,1,nx,ny);
+   max_ima_cy=cpl_image_get_centroid_y_window(img_dup,1,1,nx,ny);
+
+   cpl_image_delete(img_dup);
+
+
+   xshift=max_ima_cx-(double)nx/2;
+   yshift=max_ima_cy-(double)ny/2;
+
+   snprintf(key_name,sizeof(key_name),"%s%d%s","QC PUPIL",n," SHIFTX");
+   sinfo_qclog_add_double(*qclog_tbl,key_name,xshift,
+                          "X shift centroid - center image","%f");
+
+   snprintf(key_name,sizeof(key_name),"%s%d%s","QC PUPIL",n," SHIFTY");
+   sinfo_qclog_add_double(*qclog_tbl,key_name,yshift,
+                          "Y shift centroid - center image","%f");
+   cpl_image_delete(img);
+
+   return 0;
+}
+
+
+
+/**
+   @brief    Get what kind of Strehl data one has
+   @param    sof    input set of frames
+   @return   0 if standard 0 if pixel scale changes in input Strehl data
+*/
+
+int sinfo_get_strehl_type(cpl_frameset* sof)
+{
+   int strehl_sw=0;
+   int nobs=0;
+   int i=0;
+   cpl_frameset* obs=NULL;
+
+   cpl_frame* frame=NULL;
+   float* pix_scale=NULL;
+   cpl_propertylist* plist=NULL;
+
+   obs = cpl_frameset_new();
+
+   sinfo_contains_frames_kind(sof,obs,PRO_OBS_PSF);
+
+   nobs=cpl_frameset_get_size(obs);
+   if (nobs < 1) {
+      sinfo_contains_frames_kind(sof,obs,PRO_OBS_STD);
+      nobs=cpl_frameset_get_size(obs);
+   }
+
+   nobs=cpl_frameset_get_size(obs);
+
+   if (nobs < 1) {
+      return 0;
+   } else {
+      pix_scale=cpl_calloc(nobs,sizeof(float));
+      for(i=0;i<nobs;i++) {
+         frame=cpl_frameset_get_frame(obs,i);
+         plist=cpl_propertylist_load(cpl_frame_get_filename(frame),0);
+         pix_scale[i]=sinfo_pfits_get_pixscale(plist);
+         cpl_propertylist_delete(plist);
+      }
+      if(sinfo_pix_scale_isnot_const(pix_scale,nobs)) {
+         strehl_sw=1;
+      }
+      cpl_free(pix_scale);
+   }
+   cpl_frameset_delete(obs);
+
+   return strehl_sw;
+
+}
+
+
+
+/**
+   @brief    Set central wave as a function of band
+   @param    band    input band
+   @return   central wavelength
+*/
+
+double sinfo_get_wave_cent(const char* band)
+{
+   double lam=0.;
+   if (strcmp(band,"H+K") == 0) {
+      lam=1.950;
+   } else if (strcmp(band,"K") == 0) {
+      lam=2.175;
+   } else if (strcmp(band,"J") == 0) {
+      lam=1.225;
+   } else if (strcmp(band,"H") == 0) {
+      lam=1.675;
+   }
+   return lam;
+
+}
+
+
+
+/**
+   @brief    Check if pixel scale changes
+   @param    pix_scale    input pixel scale
+   @param    n            input array index
+   @return   1 if changes 0 else
+*/
+
+
+int sinfo_pix_scale_isnot_const(float* pix_scale, const int n) {
+   int i=0;
+   float eps=0.0001;
+   float ref=pix_scale[0];
+
+   for(i=1;i<n;i++) {
+      if(fabs(pix_scale[i]-ref) > eps) return 1;
+   }
+   return 0;
+}
+
+
+/**
+   @brief    Get pixel scale string
+   @param    ps      input pixel scale
+   @return   pixel scale
+*/
+
+
+const char* sinfo_get_pix_scale(float ps) {
+
+   const char* key_value;
+   float eps=0.0001;
+
+   if(fabs(ps - 0.025) < eps) {
+      key_value="0.025";
+   }
+   else if (fabs(ps - 0.1) < eps) {
+      key_value="0.1";
+   }
+   else if (fabs(ps - 0.25) < eps) {
+      key_value="0.25";
+   }
+   else if (fabs(ps - 1.0) < eps) {
+      key_value="pupil";
+   } else {
+      sinfo_msg_error("ps=%f. Failed to set pixel scale",ps);
+      return NULL;
+   }
+
+   return key_value;
+}
+
+
+/**
+   @brief    Get clean mean and stdev of an image over a window
+   @param    img input image
+   @param    llx input lower left x image's window coordinate
+   @param    lly input lower left y image's window coordinate
+   @param    urx input upper right y image's window coordinate
+   @param    ury input upper right y image's window coordinate
+   @param    kappa  input kappa of kappa-sigma clip
+   @param    nclip input max no of kappa-sigma clip iterations
+   @param    clean_mean output upper right y image's window coordinate
+   @param    clean_stdev output upper right y image's window coordinate
+   @return   pixel scale
+*/
+
+
+int  sinfo_get_clean_mean_window(cpl_image* img,
+                                 int llx, int lly, int urx, int ury,
+                                 const int kappa, const int nclip,
+                                 double* local_clean_mean,
+                                 double* clean_stdev)
+{
+
+   double mean=0;
+   double stdev=0;
+   double threshold=0;
+   double lo_cut=0;
+   double hi_cut=0;
+   cpl_mask* mask=NULL;
+   cpl_image* tmp=NULL;
+   cpl_stats* stats=NULL;
+   int i=0;
+
+   tmp=cpl_image_extract(img,llx,lly,urx,ury);
+   cpl_image_accept_all(tmp);
+   for(i=0;i<nclip;i++) {
+
+
+      cpl_stats_delete(stats);
+      stats = cpl_stats_new_from_image(tmp, CPL_STATS_MEAN | CPL_STATS_STDEV);
+      mean = cpl_stats_get_mean(stats);
+      stdev = cpl_stats_get_stdev(stats);
+
+      threshold=kappa*stdev;
+      lo_cut=mean-threshold;
+      hi_cut=mean+threshold;
+      cpl_image_accept_all(tmp);
+      mask=cpl_mask_threshold_image_create(tmp,lo_cut,hi_cut);
+
+      cpl_mask_not(mask);
+      cpl_image_reject_from_mask(tmp,mask);
+      cpl_mask_delete(mask);
+
+
+   }
+   *local_clean_mean=mean;
+   *clean_stdev=stdev;
+   cpl_image_delete(tmp);
+   cpl_stats_delete(stats);
+
+
+   return 0;
+
+
+}
+/**
+   @brief    Check if an error has happened and returns error kind and location
+   @param    val input value
+   @return   0 if no error is detected,-1 else
+*/
+int sinfo_check_rec_status(const int val) {
+   if(cpl_error_get_code() != CPL_ERROR_NONE) {
+      sinfo_msg_error("error before %d",val);
+      sinfo_msg_error((char* ) cpl_error_get_message());
+      sinfo_msg_error((char* ) cpl_error_get_where());
+      return -1;
+   }
+   return 0;
+}
+
+/**
+   @brief    Remove NANs from an image
+   @param    im input image
+   @return   0 after successful operation
+*/
+
+int
+sinfo_clean_nan(cpl_image** im)
+{
+   int i=0;
+   int j=0;
+   int nx=0;
+   int ny=0;
+   float* data=NULL;
+
+   nx=cpl_image_get_size_x(*im);
+   ny=cpl_image_get_size_y(*im);
+   data=cpl_image_get_data_float(*im);
+
+   for(j=0;j<ny;j++) {
+      for(i=0;i<nx;i++) {
+         if(isnan(data[j*nx+i]) != 0) {
+            data[j*nx+i] = 0;
+         }
+      }
+   }
+   return 0;
+}
+
+/**
+   @brief    Add standard DFS keys to FITS header
+   @param    plist input propertylist
+   @param    pro_catg input poduct category
+   @param    file_name input file name
+   @param    out_name product name
+   @return   none
+*/
+
+void
+sinfo_add_pro_fits_key(cpl_propertylist * plist,
+                       char* pro_catg,
+                       char* file_name,
+                       char* out_name)
+{
+
+   char* date=NULL;
+   date     = sinfo_get_datetime_iso8601() ;
+
+   cpl_propertylist_insert_after_string(plist, "EXPTIME",
+                                        KEY_NAME_PIPEFILE, out_name) ;
+   cpl_propertylist_set_comment(plist, KEY_NAME_PIPEFILE,KEY_HELP_PIPEFILE) ;
+
+   cpl_propertylist_insert_after_string(plist, "EXPTIME",
+                                        KEY_NAME_HPRO_DID, KEY_VALUE_HPRO_DID) ;
+   cpl_propertylist_set_comment(plist, KEY_NAME_HPRO_DID,KEY_HELP_HPRO_DID) ;
+
+   cpl_propertylist_insert_after_string(plist, "EXPTIME",
+                                        KEY_NAME_HPRO_TYPE, "REDUCED") ;
+   cpl_propertylist_set_comment(plist, KEY_NAME_HPRO_TYPE, KEY_HELP_HPRO_TYPE) ;
+
+   cpl_propertylist_insert_after_string(plist, "EXPTIME",
+                                        KEY_NAME_HPRO_CATG, pro_catg) ;
+   cpl_propertylist_set_comment(plist, KEY_NAME_HPRO_CATG,  KEY_HELP_HPRO_CATG);
+
+   cpl_propertylist_insert_after_string(plist, "EXPTIME",
+                                        KEY_NAME_HPRO_STATUS, "OK") ;
+   cpl_propertylist_set_comment(plist, KEY_NAME_HPRO_STATUS,KEY_HELP_HPRO_CATG);
+
+   cpl_propertylist_insert_after_string(plist, "EXPTIME",
+                                        KEY_NAME_HPRO_DATE, date) ;
+   cpl_propertylist_set_comment(plist, KEY_NAME_HPRO_DATE, KEY_HELP_HPRO_DATE);
+
+   cpl_propertylist_insert_after_string(plist, "EXPTIME",
+                                        KEY_NAME_HPRO_RECID, file_name) ;
+   cpl_propertylist_set_comment(plist, KEY_NAME_HPRO_RECID,KEY_HELP_HPRO_RECID);
+
+   cpl_propertylist_insert_after_string(plist, "EXPTIME",
+                                        KEY_NAME_HPRO_DRSID, PACKAGE_VERSION);
+   cpl_propertylist_set_comment(plist, KEY_NAME_HPRO_DRSID,KEY_HELP_HPRO_DRSID);
+
+
+}
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Comparison function to identify different input frames
+   @param    frame1  first frame
+   @param    frame2  second frame
+   @return   0 if frame1!=frame2, 1 if frame1==frame2, -1 in error case
+*/
+/*---------------------------------------------------------------------------*/
+int  sinfo_compare_tags(
+   const cpl_frame   *   frame1,
+   const cpl_frame   *   frame2)
+{
+   char            *   v1 ;
+   char            *   v2 ;
+
+   /* Test entries */
+   if (frame1==NULL || frame2==NULL) return -1 ;
+
+   /* Get the tags */
+   if ((v1 = (char*)cpl_frame_get_tag(frame1)) == NULL) return -1 ;
+   if ((v2 = (char*)cpl_frame_get_tag(frame2)) == NULL) return -1 ;
+
+   /* Compare the tags */
+   if (strcmp(v1, v2)) return 0 ;
+   else return 1 ;
+}
+
+/**
+   @brief    Extracts raw pinhole frames
+   @param    sof input frameset
+   @param    raw output frameset
+   @return   0 if success
+*/
+
+
+int sinfo_extract_raw_pinhole_frames(cpl_frameset * sof, cpl_frameset** raw)
+{
+   char* tag=NULL;
+   char* name=NULL;
+   cpl_frame* frame   = NULL;
+   int nsof=0;
+   int i=0;
+   nsof = cpl_frameset_get_size(sof);
+   for (i=0 ; i<nsof ; i++) {
+      frame = cpl_frameset_get_frame(sof,i);
+      name= (char*) cpl_frame_get_filename(frame);
+      if(sinfo_is_fits_file(name) == 1) {
+         /* to go on the file must exist */
+         if(cpl_frame_get_tag(frame) != NULL) {
+            /* If the frame has a tag we process it. Else it is an object */
+            tag= (char*) cpl_frame_get_tag(frame);
+            if(sinfo_frame_is_pinhole_lamp(tag) == 1) {
+               cpl_frameset_insert(*raw,frame);
+            }
+         }
+      }
+   }
+   return 0;
+}
+
+
+int sinfo_get_ins_set(char* band,int* ins_set){
+
+   if (strcmp(band,"H") == 0) {
+      *ins_set = 0;
+   }
+   else if (strcmp(band,"H+K") == 0) {
+      *ins_set = 1;
+   }
+   else if (strcmp(band,"K") == 0) {
+      *ins_set = 2;
+   }
+   else if (strcmp(band,"J") == 0) {
+      *ins_set = 3;
+   }
+   return 0;
+
+
+}
+int sinfo_extract_raw_frames(cpl_frameset * sof, cpl_frameset** raw)
+{
+   char* tag=NULL;
+   char* name=NULL;
+   cpl_frame* frame   = NULL;
+   int nsof=0;
+   int i=0;
+   nsof = cpl_frameset_get_size(sof);
+   for (i=0 ; i<nsof ; i++) {
+      frame = cpl_frameset_get_frame(sof,i);
+      name= (char*) cpl_frame_get_filename(frame);
+      if(sinfo_is_fits_file(name) == 1) {
+         /* to go on the file must exist */
+         if(cpl_frame_get_tag(frame) != NULL) {
+            /* If the frame has a tag we process it. Else it is an object */
+            tag= (char*) cpl_frame_get_tag(frame);
+            if(sinfo_frame_is_raw(tag) == 1) {
+               cpl_frameset_insert(*raw,frame);
+            }
+         }
+      }
+   }
+   return 0;
+}
+
+int sinfo_remove_qc_frames(cpl_frameset* sof,cpl_frameset** raw)
+{
+   char* tag=NULL;
+   char* name=NULL;
+   cpl_frame* frame   = NULL;
+   int nsof=0;
+   int i=0;
+
+   nsof = cpl_frameset_get_size(sof);
+   for (i=0 ; i<nsof ; i++) {
+      frame = cpl_frameset_get_frame(sof,i);
+      name= (char*) cpl_frame_get_filename(frame);
+      /* sinfo_msg("name=%s",name); */
+      if(sinfo_is_fits_file(name) == 1) {
+         /* sinfo_msg("\t exist "); */
+         /* to go on the file must exist */
+         if(cpl_frame_get_tag(frame) != NULL) {
+            /* If the frame has a tag we process it. Else it is an object */
+            tag= (char*) cpl_frame_get_tag(frame);
+            /* sinfo_msg("\t tag %s\n ",tag); */
+            if(strstr(tag,"QC") != NULL) {
+               /* sinfo_msg("remove frame %s\n",name); */
+               cpl_frameset_erase(*raw,tag);
+            }
+         }
+      } else {
+         /* sinfo_msg("remove frame\n"); */
+         cpl_frameset_erase_frame(*raw,frame);
+      }
+   }
+   return 0;
+
+}
+
+
+int sinfo_contains_frames_kind(cpl_frameset * sof,
+                               cpl_frameset* raw,
+                               const char*         type)
+{
+   char* tag=NULL;
+   char* name=NULL;
+   cpl_frame* frame   = NULL;
+   cpl_frame* frame_dup   = NULL;
+
+   int nsof=0;
+   int i=0;
+   nsof = cpl_frameset_get_size(sof);
+   for (i=0 ; i<nsof ; i++) {
+     frame = cpl_frameset_get_frame(sof,i);
+      name= (char*) cpl_frame_get_filename(frame);
+      if(sinfo_is_fits_file(name) == 1) {
+         /* to go on the file must exist */
+         if(cpl_frame_get_tag(frame) != NULL) {
+            /* If the frame has a tag we process it. Else it is an object */
+            tag= (char*) cpl_frame_get_tag(frame);
+            /* sinfo_msg("name=%s tag=%s type=%s\n",name,tag,type); */
+            if(strstr(tag,type) != NULL) {
+               /* sinfo_msg("Match name=%s tag=%s type=%s\n",name,tag,type); */
+               frame_dup = cpl_frame_duplicate(frame);
+               cpl_frameset_insert(raw,frame_dup);
+               /* sinfo_msg("inserted\n"); */
+            }
+         }
+      }
+   }
+   return 0;
+}
+
+
+
+
+int sinfo_is_fibres_on_off(cpl_frameset * sof,
+                           cpl_frameset* raw)
+{
+   char* tag=NULL;
+   char* name=NULL;
+   cpl_frame* frame   = NULL;
+   cpl_frame* frame_dup   = NULL;
+
+   int nsof=0;
+   int i=0;
+   nsof = cpl_frameset_get_size(sof);
+   for (i=0 ; i<nsof ; i++) {
+      frame = cpl_frameset_get_frame(sof,i);
+      name= (char*) cpl_frame_get_filename(frame);
+      if(sinfo_is_fits_file(name) == 1) {
+         /* to go on the file must exist */
+         if(cpl_frame_get_tag(frame) != NULL) {
+            /* If the frame has a tag we process it. Else it is an object */
+            tag= (char*) cpl_frame_get_tag(frame);
+            /* sinfo_msg("name=%s tag=%s type=%s\n",name,tag,type); */
+            if( strcmp(tag,PRO_FIBRE_NS_STACKED ) == 0) {
+               /* sinfo_msg("Match name=%s tag=%s type=%s\n",name,tag); */
+               frame_dup = cpl_frame_duplicate(frame);
+               cpl_frameset_insert(raw,frame_dup);
+               /* sinfo_msg("inserted\n"); */
+            }
+         }
+      }
+   }
+   return 0;
+}
+
+
+int sinfo_contains_frames_type(cpl_frameset * sof,
+                               cpl_frameset** raw,
+                               const char*          type)
+{
+   char* tag=NULL;
+   char* name=NULL;
+   cpl_frame* frame   = NULL;
+   cpl_frame* frame_dup   = NULL;
+   int nsof=0;
+   int i=0;
+   nsof = cpl_frameset_get_size(sof);
+   for (i=0 ; i<nsof ; i++) {
+      frame = cpl_frameset_get_frame(sof,i);
+      name= (char*) cpl_frame_get_filename(frame);
+      if(sinfo_is_fits_file(name) == 1) {
+         /* to go on the file must exist */
+         if(cpl_frame_get_tag(frame) != NULL) {
+            /* If the frame has a tag we process it. Else it is an object */
+            tag= (char*) cpl_frame_get_tag(frame);
+            if(strstr(tag,type) != NULL) {
+               /* sinfo_msg("name=%s tag=%s type=%s\n",name,tag,type); */
+               frame_dup=cpl_frame_duplicate(frame);
+               cpl_frameset_insert(*raw,frame_dup);
+            }
+         }
+      }
+   }
+   return 0;
+}
+
+int sinfo_extract_raw_frames_type2(cpl_frameset * sof,
+                                   cpl_frameset** raw,
+                                   const char*          type)
+{
+
+   cpl_frame* frame=NULL;
+   cpl_frame* frame_dup   = NULL;
+   frame = cpl_frameset_find(sof,type);
+   while(frame) {
+      frame_dup=cpl_frame_duplicate(frame);
+      cpl_frameset_insert(*raw,frame_dup);
+      frame = cpl_frameset_find(sof,NULL);
+   }
+   return 0;
+
+}
+
+
+int sinfo_extract_raw_frames_type1(cpl_frameset * sof,
+                                   cpl_frameset* raw,
+                                   const char*          type)
+{
+
+   cpl_frame* frame=NULL;
+   cpl_frame* frame_dup   = NULL;
+   frame = cpl_frameset_find(sof,type);
+   while(frame) {
+      frame_dup=cpl_frame_duplicate(frame);
+      cpl_frameset_insert(raw,frame_dup);
+      frame = cpl_frameset_find(sof,NULL);
+   }
+   return 0;
+
+}
+
+int sinfo_extract_raw_frames_type(cpl_frameset * sof,
+                                  cpl_frameset** raw,
+                                  const char*          type)
+{
+   char tag[FILE_NAME_SZ];
+   char name[FILE_NAME_SZ];
+   cpl_frame* frame   = NULL;
+   cpl_frame* frame_dup   = NULL;
+   int nsof=0;
+   int i=0;
+   nsof = cpl_frameset_get_size(sof);
+   for (i=0 ; i<nsof ; i++) {
+      frame = cpl_frameset_get_frame(sof,i);
+      strcpy(name, cpl_frame_get_filename(frame));
+      if(sinfo_is_fits_file(name) == 1) {
+         /* to go on the file must exist */
+         if(cpl_frame_get_tag(frame) != NULL) {
+            /* If the frame has a tag we process it. Else it is an object */
+            strcpy(tag,cpl_frame_get_tag(frame));
+            if(strcmp(tag,type) == 0) {
+               /* sinfo_msg("name=%s tag=%s type=%s\n",name,tag,type); */
+               frame_dup=cpl_frame_duplicate(frame);
+
+               cpl_frameset_insert(*raw,frame_dup);
+            }
+         }
+      }
+   }
+   return 0;
+}
+
+int sinfo_extract_frames_type(cpl_frameset * sof,
+                              cpl_frameset * raw,
+                              const char*          type)
+{
+   char* tag=NULL;
+   char* name=NULL;
+   cpl_frame* frame   = NULL;
+   cpl_frame* frame_dup   = NULL;
+   int nsof=0;
+   int i=0;
+   nsof = cpl_frameset_get_size(sof);
+   for (i=0 ; i<nsof ; i++) {
+      frame = cpl_frameset_get_frame(sof,i);
+      name= (char*) cpl_frame_get_filename(frame);
+      if(sinfo_is_fits_file(name) == 1) {
+         /* to go on the file must exist */
+         if(cpl_frame_get_tag(frame) != NULL) {
+            /* If the frame has a tag we process it. Else it is an object */
+            tag= (char*) cpl_frame_get_tag(frame);
+            if(strcmp(tag,type) == 0) {
+               /* sinfo_msg("name=%s tag=%s type=%s\n",name,tag,type); */
+               frame_dup=cpl_frame_duplicate(frame);
+               cpl_frameset_insert(raw,frame_dup);
+            }
+         }
+      }
+   }
+   return 0;
+}
+
+
+int sinfo_extract_obj_frames(cpl_frameset * sof, cpl_frameset* obj)
+{
+   char* tag=NULL;
+   char* name=NULL;
+   cpl_frame* frame   = NULL;
+   cpl_frame* frame_dup   = NULL;
+
+   int nsof=0;
+   int i=0;
+   nsof = cpl_frameset_get_size(sof);
+   for (i=0 ; i<nsof ; i++) {
+      frame = cpl_frameset_get_frame(sof,i);
+      name= (char*) cpl_frame_get_filename(frame);
+      if(sinfo_is_fits_file(name) ==1) {
+         /* to go on the file must exist */
+         if(cpl_frame_get_tag(frame) != NULL) {
+            /* If the frame has a tag we process it. Else it is an object */
+            tag= (char*) cpl_frame_get_tag(frame);
+            if(sinfo_tag_is_obj(tag) == 1) {
+               frame_dup=cpl_frame_duplicate(frame);
+               cpl_frameset_insert(obj,frame_dup);
+            }
+         }
+      }
+   }
+
+   return 0;
+}
+
+
+int sinfo_extract_obj_products(cpl_frameset * sof, cpl_frameset* obj)
+{
+   char* tag=NULL;
+   char* name=NULL;
+   cpl_frame* frame   = NULL;
+   cpl_frame* frame_dup   = NULL;
+
+   int nsof=0;
+   int i=0;
+   nsof = cpl_frameset_get_size(sof);
+   for (i=0 ; i<nsof ; i++) {
+      frame = cpl_frameset_get_frame(sof,i);
+      name= (char*) cpl_frame_get_filename(frame);
+      if(sinfo_is_fits_file(name) ==1) {
+         /* to go on the file must exist */
+         if(cpl_frame_get_tag(frame) != NULL) {
+            /* If the frame has a tag we process it. Else it is an object */
+            tag= (char*) cpl_frame_get_tag(frame);
+            if(sinfo_tag_is_objpro(tag) == 1) {
+               frame_dup=cpl_frame_duplicate(frame);
+               cpl_frameset_insert(obj,frame_dup);
+            }
+         }
+      }
+   }
+
+   return 0;
+}
+
+int sinfo_extract_on_frames(cpl_frameset * sof, cpl_frameset* on)
+{
+   cpl_frame* frame   = NULL;
+   cpl_frame* frame_dup   = NULL;
+
+   int nsof=0;
+   int i=0;
+   nsof = cpl_frameset_get_size(sof);
+   for (i=0 ; i<nsof ; i++) {
+      frame = cpl_frameset_get_frame(sof,i);
+      if(sinfo_frame_is_on(frame) ==1) {
+         frame_dup=cpl_frame_duplicate(frame);
+         cpl_frameset_insert(on,frame_dup);
+      }
+   }
+
+   return 0;
+}
+
+int sinfo_extract_sky_frames(cpl_frameset * sof, cpl_frameset* sky)
+{
+   char* tag=NULL;
+   char* name=NULL;
+   cpl_frame* frame   = NULL;
+   cpl_frame* frame_dup   = NULL;
+   int nsof=0;
+   int i=0;
+   nsof = cpl_frameset_get_size(sof);
+   for (i=0 ; i<nsof ; i++) {
+      frame = cpl_frameset_get_frame(sof,i);
+      name= (char*) cpl_frame_get_filename(frame);
+      if(sinfo_is_fits_file(name) ==1) {
+         /* to go on the file must exist */
+         if(cpl_frame_get_tag(frame) != NULL) {
+            /* If the frame has a tag we process it. Else it is an object */
+            tag= (char*) cpl_frame_get_tag(frame);
+            if(sinfo_tag_is_sky(tag) == 1) {
+               frame_dup=cpl_frame_duplicate(frame);
+               cpl_frameset_insert(sky,frame_dup);
+            }
+         }
+      }
+   }
+
+   return 0;
+}
+
+
+
+int sinfo_extract_off_frames(cpl_frameset * sof, cpl_frameset* off)
+{
+   cpl_frame* frame   = NULL;
+   cpl_frame* frame_dup   = NULL;
+   int nsof=0;
+   int i=0;
+   nsof = cpl_frameset_get_size(sof);
+   for (i=0 ; i<nsof ; i++) {
+      frame = cpl_frameset_get_frame(sof,i);
+      if(sinfo_frame_is_on(frame)) {
+         frame_dup=cpl_frame_duplicate(frame);
+         cpl_frameset_insert(off,frame_dup);
+      }
+   }
+
+   return 0;
+}
+
+int sinfo_extract_mst_frames(cpl_frameset * sof, cpl_frameset* cdb)
+{
+   char* tag=NULL;
+   char* name=NULL;
+   cpl_frame* frame   = NULL;
+   cpl_frame* frame_dup   = NULL;
+   int nsof=0;
+   int i=0;
+
+   nsof = cpl_frameset_get_size(sof);
+   for (i=0 ; i<nsof ; i++) {
+      frame = cpl_frameset_get_frame(sof,i);
+      name= (char*) cpl_frame_get_filename(frame);
+      if(sinfo_is_fits_file(name) ==1) {
+         /* to go on the file must exist */
+         if(cpl_frame_get_tag(frame) != NULL) {
+            /* If the frame has a tag we process it. Else it is an object */
+            tag= (char*) cpl_frame_get_tag(frame);
+            if(sinfo_frame_is_cdb(tag) == 1) {
+               frame_dup=cpl_frame_duplicate(frame);
+               cpl_frameset_insert(cdb,frame_dup);
+            }
+         }
+      }
+   }
+
+   return 0;
+}
+
+cpl_frameset* sinfo_frameset_join(cpl_frameset* fs1,cpl_frameset* fs2) {
+
+   cpl_frameset* join=NULL;
+   cpl_frame* frm=NULL;
+   cpl_frame* frm_dup=NULL;
+   int i=0;
+   int n=0;
+
+   join=cpl_frameset_new();
+
+   n=cpl_frameset_get_size(fs1);
+   for(i=0;i<n; i++) {
+      frm=cpl_frameset_get_frame(fs1,i);
+      frm_dup= cpl_frame_duplicate(frm);
+      cpl_frameset_insert(join,frm_dup);
+   }
+
+   n=cpl_frameset_get_size(fs2);
+   for(i=0;i<n; i++) {
+      frm=cpl_frameset_get_frame(fs2,i);
+      frm_dup= cpl_frame_duplicate(frm);
+      cpl_frameset_insert(join,frm_dup);
+   }
+
+
+   return join;
+
+}
+
+
+int sinfo_extract_stk_frames(cpl_frameset * sof,
+                             cpl_frameset* res)
+{
+   char* tag=NULL;
+   char* name=NULL;
+   cpl_frame* frame   = NULL;
+   cpl_frame* frame_dup   = NULL;
+   int nsof=0;
+   int i=0;
+
+   nsof = cpl_frameset_get_size(sof);
+   for (i=0 ; i<nsof ; i++) {
+      frame = cpl_frameset_get_frame(sof,i);
+      name= (char*) cpl_frame_get_filename(frame);
+      if(sinfo_is_fits_file(name) ==1) {
+         /* to go on the file must exist */
+         if(cpl_frame_get_tag(frame) != NULL) {
+            /* If the frame has a tag we process it. Else it is an object */
+            tag= (char*) cpl_frame_get_tag(frame);
+            if(sinfo_frame_is_stk(tag) == 1) {
+               frame_dup=cpl_frame_duplicate(frame);
+               cpl_frameset_insert(res,frame_dup);
+            }
+         }
+      }
+   }
+
+   return 0;
+}
+
+
+int
+sinfo_extract_preoptic_frames(cpl_frameset * sof,
+                              cpl_frameset** res,
+                              const char* val)
+{
+   char* name=NULL;
+   cpl_frame* frame   = NULL;
+   cpl_frame* frame_dup   = NULL;
+   int nsof=0;
+   int i=0;
+
+   nsof = cpl_frameset_get_size(sof);
+   for (i=0 ; i<nsof ; i++) {
+      frame = cpl_frameset_get_frame(sof,i);
+      name= (char*) cpl_frame_get_filename(frame);
+      if(sinfo_is_fits_file(name) ==1) {
+         if(sinfo_frame_is_preoptic(frame,val) == 1) {
+            frame_dup=cpl_frame_duplicate(frame);
+            cpl_frameset_insert(*res,frame_dup);
+         }
+      }
+   }
+
+   return 0;
+}
+
+int sinfo_extract_raw_stack_frames(cpl_frameset * sof, cpl_frameset** pro)
+{
+   char* tag=NULL;
+   char* name=NULL;
+   cpl_frame* frame   = NULL;
+   cpl_frame* frame_dup   = NULL;
+
+   int nsof=0;
+   int i=0;
+   nsof = cpl_frameset_get_size(sof);
+
+   for (i=0 ; i<nsof ; i++) {
+      frame = cpl_frameset_get_frame(sof,i);
+      name= (char*) cpl_frame_get_filename(frame);
+      if(sinfo_is_fits_file(name) ==1) {
+         /* to go on the file must exist */
+         if(cpl_frame_get_tag(frame) != NULL) {
+            /* If the frame has a tag we process it. Else it is an object */
+            tag= (char*) cpl_frame_get_tag(frame);
+            /* sinfo_msg("tag=%s\n",tag); */
+            if(sinfo_frame_is_raw_stack(tag) == 1) {
+               frame_dup   = cpl_frame_duplicate(frame);
+               cpl_frameset_insert(*pro,frame_dup);
+            }
+         }
+      }
+   }
+
+   return 0;
+}
+
+
+int sinfo_extract_raw_slit_frames(cpl_frameset * sof, cpl_frameset** pro)
+{
+   char* tag=NULL;
+   char* name=NULL;
+   cpl_frame* frame   = NULL;
+   int nsof=0;
+   int i=0;
+   nsof = cpl_frameset_get_size(sof);
+   for (i=0 ; i<nsof ; i++) {
+      frame = cpl_frameset_get_frame(sof,i);
+      name= (char*) cpl_frame_get_filename(frame);
+      if(sinfo_is_fits_file(name) ==1) {
+         /* to go on the file must exist */
+         if(cpl_frame_get_tag(frame) != NULL) {
+            /* If the frame has a tag we process it. Else it is an object */
+            tag= (char*) cpl_frame_get_tag(frame);
+            if(sinfo_frame_is_slit_lamp(tag) == 1) {
+               cpl_frameset_insert(*pro,frame);
+            }
+         }
+      }
+   }
+
+   return 0;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Define the input raw frames for sinfo_frame_is_raw
+   @param    tag     The candidate DO_CATG
+   @return   0 for no, 1 for yes, -1 in error case
+*/
+/*---------------------------------------------------------------------------*/
+int sinfo_frame_is_raw(char * tag)
+{
+   /* Test entries */
+   if (tag == NULL) return -1 ;
+
+   if (!strcmp(tag, RAW_LINEARITY_LAMP)) return 1 ;
+   if (!strcmp(tag, RAW_DARK)) return 1 ;
+   if (!strcmp(tag, RAW_PINHOLE_LAMP)) return 1 ;
+   if (!strcmp(tag, RAW_SLIT_LAMP)) return 1 ;
+   if (!strcmp(tag, RAW_WAVE_LAMP)) return 1 ;
+   if (!strcmp(tag, RAW_FLAT_LAMP)) return 1 ;
+   if (!strcmp(tag, RAW_WAVE_NS)) return 1 ;
+   if (!strcmp(tag, RAW_FLAT_NS)) return 1 ;
+   if (!strcmp(tag, RAW_FIBRE_LAMP)) return 1 ;
+   if (!strcmp(tag, RAW_FIBRE_EW)) return 1 ;
+   if (!strcmp(tag, RAW_FIBRE_NS)) return 1 ;
+   if (!strcmp(tag, RAW_FLAT_SKY)) return 1 ;
+   if (!strcmp(tag, RAW_FLUX_LAMP)) return 1 ;
+   if (!strcmp(tag, RAW_PSF_CALIBRATOR)) return 1 ;
+   if (!strcmp(tag, RAW_FOCUS)) return 1 ;
+
+   if (!strcmp(tag, RAW_STD)) return 1 ;
+   if (!strcmp(tag, RAW_STD_STAR)) return 1 ;
+   if (!strcmp(tag, RAW_STD_STAR_DITHER)) return 1 ;
+   if (!strcmp(tag, RAW_SKY_STD)) return 1 ;
+   if (!strcmp(tag, RAW_SKY_OH)) return 1 ;
+   if (!strcmp(tag, RAW_SKY_PSF_CALIBRATOR)) return 1 ;
+
+   if (!strcmp(tag, RAW_PUPIL_LAMP)) return 1 ;
+   if (!strcmp(tag, RAW_OBJECT_JITTER)) return 1 ;
+   if (!strcmp(tag, RAW_SKY_JITTER)) return 1 ;
+   if (!strcmp(tag, RAW_OBJECT_NODDING)) return 1 ;
+   if (!strcmp(tag, RAW_OBJECT_SKYSPIDER)) return 1 ;
+   if (!strcmp(tag, RAW_SKY_NODDING)) return 1 ;
+
+   if (!strcmp(tag, RAW_FLAT_LAMP_DITHER)) return 1 ;
+   if (!strcmp(tag, RAW_WAVE_LAMP_DITHER)) return 1 ;
+   if (!strcmp(tag, RAW_STD_STAR_DITHER)) return 1 ;
+   if (!strcmp(tag, RAW_OBJECT_NODDING_DITHER)) return 1 ;
+   if (!strcmp(tag, RAW_OBJECT_SKYSPIDER_DITHER)) return 1 ;
+   if (!strcmp(tag, RAW_SKY_NODDING_DITHER)) return 1 ;
+
+
+   return 0 ;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Define the input raw frames for sinfo_frame_is_raw
+   @param    tag     The candidate DO_CATG
+   @return   0 for no, 1 for yes, -1 in error case
+*/
+/*---------------------------------------------------------------------------*/
+int sinfo_frame_is_raw_stack(char * tag)
+{
+   /* Test entries */
+   if (tag == NULL) return -1 ;
+
+
+   if (!strcmp(tag, PRO_SKY_DUMMY)) return 1 ;
+   if (!strcmp(tag, RAW_WAVE_LAMP)) return 1 ;
+   if (!strcmp(tag, RAW_WAVE_LAMP_DITHER)) return 1 ;
+   if (!strcmp(tag, RAW_WAVE_NS)) return 1 ;
+   if (!strcmp(tag, RAW_WAVE_NS_DITHER)) return 1 ;
+
+   if (!strcmp(tag, RAW_FLUX_LAMP)) return 1 ;
+   if (!strcmp(tag, RAW_FIBRE_NS)) return 1 ;
+   if (!strcmp(tag, RAW_FIBRE_EW)) return 1 ;
+
+   if (!strcmp(tag, RAW_PSF_CALIBRATOR)) return 1 ;
+   if (!strcmp(tag, RAW_FIBRE_PSF)) return 1 ;
+   if (!strcmp(tag, RAW_FIBRE_DARK)) return 1 ;
+
+   if (!strcmp(tag, RAW_FOCUS)) return 1 ;
+
+   if (!strcmp(tag, RAW_PUPIL_LAMP)) return 1 ;
+   if (!strcmp(tag, RAW_OBJECT_JITTER)) return 1 ;
+   if (!strcmp(tag, RAW_SKY_JITTER)) return 1 ;
+   if (!strcmp(tag, RAW_OBJECT_NODDING)) return 1 ;
+   if (!strcmp(tag, RAW_OBJECT_SKYSPIDER)) return 1 ;
+   if (!strcmp(tag, RAW_SKY_NODDING)) return 1 ;
+
+   if (!strcmp(tag, RAW_OBJECT_NODDING_DITHER)) return 1 ;
+   if (!strcmp(tag, RAW_OBJECT_SKYSPIDER_DITHER)) return 1 ;
+   if (!strcmp(tag, RAW_SKY_NODDING_DITHER)) return 1 ;
+
+
+   if (!strcmp(tag, RAW_IMAGE_PRE_OBJECT)) return 1 ;
+   if (!strcmp(tag, RAW_IMAGE_PRE_SKY)) return 1 ;
+   if (!strcmp(tag, RAW_STD)) return 1 ;
+   if (!strcmp(tag, RAW_SKY_STD)) return 1 ;
+   if (!strcmp(tag, RAW_SKY_OH)) return 1 ;
+   if (!strcmp(tag, RAW_SKY_PSF_CALIBRATOR)) return 1 ;
+   if (!strcmp(tag, RAW_STD_STAR)) return 1 ;
+   if (!strcmp(tag, RAW_SKY)) return 1 ;
+
+   return 0 ;
+}
+
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Define the input raw frames for sinfo_frame_is_raw
+   @param    tag     The candidate DO_CATG
+   @return   0 for no, 1 for yes, -1 in error case
+*/
+/*---------------------------------------------------------------------------*/
+int sinfo_frame_is_raw_dark(char * tag)
+{
+   /* Test entries */
+   if (tag == NULL) return -1 ;
+
+   if (!strcmp(tag, RAW_DARK)) return 1 ;
+
+   return 0 ;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Define the input raw frames for sinfo_frame_is_raw
+   @param    tag     The candidate DO_CATG
+   @return   0 for no, 1 for yes, -1 in error case
+*/
+/*---------------------------------------------------------------------------*/
+int sinfo_frame_is_slit_lamp(char * tag)
+{
+   /* Test entries */
+   if (tag == NULL) return -1 ;
+
+   if (!strcmp(tag, RAW_SLIT_LAMP)) return 1 ;
+
+   return 0 ;
+}
+
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Define the input raw frames for sinfo_frame_is_raw
+   @param    tag     The candidate DO_CATG
+   @return   0 for no, 1 for yes, -1 in error case
+*/
+/*---------------------------------------------------------------------------*/
+int sinfo_frame_is_pinhole_lamp(char * tag)
+{
+   /* Test entries */
+   if (tag == NULL) return -1 ;
+
+   if (!strcmp(tag, RAW_PINHOLE_LAMP)) return 1 ;
+
+   return 0 ;
+}
+
+
+int sinfo_frame_is_cdb(char * tag)
+{
+   /* Test entries */
+   if (tag == NULL) return -1 ;
+   /* For the moment not checked the following:
+
+   PRO_STACKED
+   PRO_SLIT_ON
+   PRO_FLUX_LAMP_STACKED
+   PRO_WAVE_LAMP_STACKED
+   PRO_PSF_CALIBRATOR_STACKED
+   PRO_FOCUS_STACKED
+   PRO_OBJECT_NODDING_STACKED
+   PRO_OBJECT_SKYSPIDER_STACKED
+   PRO_SKY_NODDING_STACKED
+   PRO_STD_NODDING_STACKED
+   PRO_MASK_CUBE
+   PRO_PSF
+   TMP_FOCUS
+   TMP_FOCUS_ON
+   TMP_FOCUS_OFF
+   PRO_FOCUS
+   PRO_FOCUS_GAUSS
+   PRO_SPECTRA
+   PRO_CUBE
+   PRO_CUBE_COLL
+   PRO_SLOPEX
+   PRO_SLOPEY
+   PRO_MASK_CUBE
+   PRO_OBJ_CUBE
+   PRO_BP_COEFF
+   */
+
+   if (!strcmp(tag, REF_LINE_ARC)) return 1 ;
+   if (!strcmp(tag, PRO_BP_MAP)) return 1 ;
+   if (!strcmp(tag, PRO_BP_MAP_HP)) return 1 ;
+   if (!strcmp(tag, PRO_BP_MAP_DI)) return 1 ;
+   if (!strcmp(tag, PRO_BP_MAP_NO)) return 1 ;
+   if (!strcmp(tag, PRO_BP_MAP_NL)) return 1 ;
+   if (!strcmp(tag, PRO_MASTER_BP_MAP)) return 1 ;
+   if (!strcmp(tag, PRO_MASTER_DARK)) return 1 ;
+   if (!strcmp(tag, PRO_SLOPE)) return 1 ;
+   if (!strcmp(tag, PRO_DISTORTION)) return 1 ;
+   if (!strcmp(tag, PRO_SLITLETS_DISTANCE)) return 1 ;
+   if (!strcmp(tag, PRO_MASTER_FLAT_LAMP)) return 1 ;
+   if (!strcmp(tag, PRO_MASTER_FLAT_LAMP1)) return 1 ;
+   if (!strcmp(tag, PRO_MASTER_FLAT_LAMP2)) return 1 ;
+   if (!strcmp(tag, PRO_SLIT_POS)) return 1 ;
+   if (!strcmp(tag, PRO_SLIT_POS_GUESS)) return 1 ;
+   if (!strcmp(tag, PRO_WAVE_PAR_LIST)) return 1 ;
+   if (!strcmp(tag, PRO_WAVE_COEF_SLIT)) return 1 ;
+   if (!strcmp(tag, PRO_MASTER_LAMP_SPEC)) return 1 ;
+   if (!strcmp(tag, PRO_MASTER_TWIFLAT)) return 1 ;
+   if (!strcmp(tag, PRO_COEFF_LIST)) return 1 ;
+   if (!strcmp(tag, PRO_INDEX_LIST)) return 1 ;
+   if (!strcmp(tag, PRO_HALO_SPECT)) return 1 ;
+   if (!strcmp(tag, PRO_FIRST_COL)) return 1 ;
+   if (!strcmp(tag, PRO_FOCUS)) return 1 ;
+   if (!strcmp(tag, PRO_WAVE_MAP)) return 1 ;
+   if (!strcmp(tag, PRO_REF_ATM_REF_CORR)) return 1 ;
+
+   return 0;
+
+}
+
+
+
+
+int sinfo_frame_is_stk(char * tag)
+{
+   /* Test entries */
+   if (tag == NULL) return -1 ;
+   /* For the moment not checked the following: */
+
+
+   if (!strcmp(tag, PRO_SKY_STACKED_DUMMY)) return 1 ;
+   if (!strcmp(tag, PRO_STACK_SKY_DIST)) return 1 ;
+   if (!strcmp(tag, PRO_STACK_MFLAT_DIST)) return 1 ;
+   if (!strcmp(tag, PRO_PSF_CALIBRATOR_STACKED)) return 1 ;
+
+
+   return 0;
+
+}
+
+int
+sinfo_propertylist_has(cpl_propertylist* plist,
+                       const char* key) {
+
+   return cpl_propertylist_has(plist,key);
+
+}
+
+int sinfo_frame_is_preoptic(cpl_frame* frame,const char* val)
+{
+
+   char* file=NULL;
+   char popt[FILE_NAME_SZ];
+   cpl_propertylist* plist=NULL;
+
+
+   file = cpl_strdup(cpl_frame_get_filename(frame)) ;
+   if ((cpl_error_code)((plist = cpl_propertylist_load(file, 0)) == NULL)) {
+      sinfo_msg_error( "getting header from reference frame %s",file);
+      cpl_propertylist_delete(plist) ;
+      cpl_free(file);
+      return -1 ;
+   }
+
+   if (sinfo_propertylist_has(plist, KEY_NAME_PREOPTICS)) {
+      strcpy(popt,cpl_propertylist_get_string(plist, KEY_NAME_PREOPTICS));
+   } else {
+      sinfo_msg_error("keyword %s does not exist",KEY_NAME_PREOPTICS);
+      cpl_free(file);
+      return -1;
+   }
+   cpl_propertylist_delete(plist) ;
+   cpl_free(file);
+
+   if (strstr(val,popt) != NULL) return 1 ;
+
+
+   return 0;
+
+}
+
+
+int sinfo_get_preoptic(const char* file, const char* val)
+{
+
+   cpl_propertylist* plist=NULL;
+
+
+   if ((cpl_error_code)((plist = cpl_propertylist_load(file, 0)) == NULL)) {
+      sinfo_msg_error( "getting header from reference frame %s",file);
+      cpl_propertylist_delete(plist) ;
+      return -1 ;
+   }
+
+   if (sinfo_propertylist_has(plist, KEY_NAME_PREOPTICS)) {
+      strcpy((char*)val,cpl_propertylist_get_string(plist, KEY_NAME_PREOPTICS));
+   } else {
+      sinfo_msg_error("keyword %s does not exist",KEY_NAME_PREOPTICS);
+      return -1;
+   }
+   cpl_propertylist_delete(plist) ;
+
+   return 0;
+
+}
+
+/*
+  static int
+  sinfo_stat_rectangle(cpl_image* img,
+  const int kappa,
+  const int nclip,
+  double *mean,
+  double *stdev)
+  {
+
+  double sum=0;
+  double sum2=0;
+  double noise=0;
+
+  double* pim=NULL;
+  int i=0;
+  int j=0;
+  int kk=0;
+  int sx=0;
+  int sy=0;
+
+  *mean=0;
+  pim=cpl_image_get_data(img);
+  kk=0;
+  for(i=0;i<sx*sy;i++) {
+  *mean+=pim[i];
+  }
+  *mean/=(sx*sy);
+
+  for(i=0;i<sx*sy;i++) {
+  sum+=(pim[i]-*mean)*(pim[i]-*mean);
+  }
+  noise=sqrt(sum/(sx*sy));
+
+
+  //clean a bit the bad pixels
+  for(j=0;j<nclip;j++) {
+  sum=0;
+  sum2=0;
+  kk=0;
+  for(i=0;i<sx*sy;i++) {
+  if(fabs(pim[i]-*mean)<kappa*noise) {
+
+  sum  +=(pim[i]-*mean)*(pim[i]-*mean);
+  sum2 += pim[i];
+  kk+=1;
+  }
+  noise=sqrt(sum/kk);
+  *mean=sum2/kk;
+
+  }
+
+  }
+  *stdev=noise;
+
+  return 0;
+
+  }
+*/
+
+cpl_table* sinfo_compute_gain(cpl_frameset* son, cpl_frameset* sof)
+{
+
+
+   cpl_frame*    frm=NULL;
+
+   cpl_image* img_on1=NULL;
+   cpl_image* img_on2=NULL;
+   cpl_image* img_on_dif=NULL;
+   cpl_image* img_on_sub=NULL;
+
+
+   cpl_image* img_of1=NULL;
+   cpl_image* img_of2=NULL;
+   cpl_image* img_of_dif=NULL;
+   cpl_image* img_of_sub=NULL;
+
+   cpl_table* res_tbl=NULL;
+   cpl_vector* dit_on=NULL;
+   cpl_vector* dit_of=NULL;
+   cpl_vector* exptime_on=NULL;
+   cpl_vector* exptime_of=NULL;
+   cpl_propertylist* plist=NULL;
+
+   int non=0;
+   int nof=0;
+   int nfr=0;
+   double avg_on1=0;
+   double avg_on2=0;
+   double avg_of1=0;
+   double avg_of2=0;
+   double std=0;
+
+   double sig_on_dif=0;
+   double sig_of_dif=0;
+   char* name=NULL;
+   int i=0;
+   int m=0;
+
+   int llx=270;
+   int lly=1000;
+   int urx=320;
+   int ury=1050;
+   int zone[4];
+   double gain=0;
+   double dit_ref=0;
+   double dit_tmp=0;
+   double exptime_ref=0;
+   double exptime_tmp=0;
+   int kappa=5;
+   int nclip=25;
+   double centre=0;
+
+   non = cpl_frameset_get_size(son);
+   nof = cpl_frameset_get_size(sof);
+   nfr = (non <= nof) ? non : nof;
+
+   dit_on=cpl_vector_new(nfr);
+   dit_of=cpl_vector_new(nfr);
+   exptime_on=cpl_vector_new(nfr);
+   exptime_of=cpl_vector_new(nfr);
+
+   for(i=0;i<nfr;i++) {
+
+      frm=cpl_frameset_get_frame(son,i);
+      name=(char*)cpl_frame_get_filename(frm);
+      plist=cpl_propertylist_load(name,0);
+      dit_ref=sinfo_pfits_get_dit(plist);
+      exptime_ref=(double)sinfo_pfits_get_exp_time(plist);
+      cpl_propertylist_delete(plist);
+      cpl_vector_set(dit_on,i,dit_ref);
+      cpl_vector_set(exptime_on,i,exptime_ref);
+
+      frm=cpl_frameset_get_frame(sof,i);
+      name=(char*)cpl_frame_get_filename(frm);
+      plist=cpl_propertylist_load(name,0);
+      dit_ref=sinfo_pfits_get_dit(plist);
+      exptime_ref=(double)sinfo_pfits_get_exp_time(plist);
+      cpl_propertylist_delete(plist);
+      cpl_vector_set(dit_of,i,dit_ref);
+      cpl_vector_set(exptime_of,i,exptime_ref);
+
+   }
+
+
+
+   zone[0]=270;
+   zone[1]=1030;
+   zone[2]=310;
+   zone[3]=1060;
+
+
+
+   zone[0]=20;
+   zone[1]=2028;
+   zone[2]=20;
+   zone[3]=2028;
+
+
+
+   check_nomsg(res_tbl=cpl_table_new(nfr));
+   cpl_table_new_column(res_tbl,"adu", CPL_TYPE_DOUBLE);
+   cpl_table_new_column(res_tbl,"gain", CPL_TYPE_DOUBLE);
+
+   for(i=0;i<nfr;i++) {
+      frm=cpl_frameset_get_frame(son,i);
+      name=(char*)cpl_frame_get_filename(frm);
+      img_on1=cpl_image_load(name,CPL_TYPE_DOUBLE,0,0);
+
+      frm=cpl_frameset_get_frame(sof,i);
+      name=(char*)cpl_frame_get_filename(frm);
+      img_of1=cpl_image_load(name,CPL_TYPE_DOUBLE,0,0);
+
+
+      dit_ref=cpl_vector_get(dit_on,i);
+      exptime_ref=cpl_vector_get(exptime_on,i);
+
+
+      for(m=0;m<nfr; m++) {
+         if(m != i) {
+            frm=cpl_frameset_get_frame(son,m);
+            name=(char*)cpl_frame_get_filename(frm);
+            dit_tmp=cpl_vector_get(dit_on,m);
+            exptime_tmp=cpl_vector_get(exptime_on,m);
+            if(dit_tmp == dit_ref && exptime_tmp == exptime_ref) {
+               /* sinfo_msg("m=%d i=%d\n",m,i); */
+               img_on2=cpl_image_load(name,CPL_TYPE_DOUBLE,0,0);
+               frm=cpl_frameset_get_frame(sof,m);
+               name=(char*)cpl_frame_get_filename(frm);
+               img_of2=cpl_image_load(name,CPL_TYPE_DOUBLE,0,0);
+
+               img_on_dif=cpl_image_subtract_create(img_on1,img_on2);
+               img_of_dif=cpl_image_subtract_create(img_of1,img_of2);
+
+               img_on_sub=cpl_image_extract(img_on_dif,llx,lly,urx,ury);
+               img_of_sub=cpl_image_extract(img_of_dif,llx,lly,urx,ury);
+
+               sinfo_get_clean_mean_window(img_on1,llx,lly,urx,ury,kappa,
+                                           nclip,&avg_on1,&std);
+               sinfo_get_clean_mean_window(img_on2,llx,lly,urx,ury,kappa,
+                                           nclip,&avg_on2,&std);
+               sinfo_get_clean_mean_window(img_of1,llx,lly,urx,ury,kappa,
+                                           nclip,&avg_of1,&std);
+               sinfo_get_clean_mean_window(img_of2,llx,lly,urx,ury,kappa,
+                                           nclip,&avg_of2,&std);
+               /*
+                 cpl_image_save(img_on_sub,"ima_on_sub.fits",
+                                CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT);
+                 cpl_image_save(img_of_sub,"ima_of_sub.fits",
+                                CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT);
+               */
+               /*
+               //worse accuracy
+               sinfo_stat_rectangle(img_on_dif,kappa,nclip,
+                                    &centre,&sig_on_dif);
+               sinfo_stat_rectangle(img_of_dif,kappa,nclip,
+                                    &centre,&sig_of_dif);
+               */
+
+
+               //better accuracy
+               sinfo_get_clean_mean_window(img_on_dif,llx,lly,urx,ury,kappa,
+                                           nclip,&centre,&sig_on_dif);
+               sinfo_get_clean_mean_window(img_of_dif,llx,lly,urx,ury,kappa,
+                                           nclip,&centre,&sig_of_dif);
+               /**
+                //medium accuracy
+                ck0(sinfo_image_estimate_noise(img_on_sub,1,
+                                               &centre,&sig_on_dif),
+                                               "computing noise");
+                ck0(sinfo_image_estimate_noise(img_of_sub,1,
+                                               &centre,&sig_of_dif),
+                                               "computing noise");
+
+
+                cpl_flux_get_noise_window(img_on_dif,zone,2,100,
+                                          &sig_on_dif,NULL);
+                cpl_flux_get_noise_window(img_of_dif,zone,2,100,
+                                          &sig_of_dif,NULL);
+                sinfo_msg("noise=%g %g",sig_on_dif,sig_of_dif);
+               */
+               cpl_image_delete(img_on2);
+               cpl_image_delete(img_of2);
+               cpl_image_delete(img_on_dif);
+               cpl_image_delete(img_of_dif);
+               cpl_image_delete(img_on_sub);
+               cpl_image_delete(img_of_sub);
+
+               gain=((avg_on1+avg_on2)-(avg_of1+avg_of2))/
+                  ((sig_on_dif*sig_on_dif)-(sig_of_dif*sig_of_dif));
+
+               cpl_table_set_double(res_tbl,"gain",m,gain);
+               cpl_table_set_double(res_tbl,"adu",m,
+                                    ((avg_on1+avg_on2)/2-(avg_of1+avg_of2)/2));
+               /* sinfo_msg("gain=%f ADU=%f\n",gain,
+                  (avg_on1+avg_on2)/2-(avg_of1+avg_of2)/2);
+                  sinfo_msg("g=%f avg_on1=%f avg_on2=%f",gain,avg_on1,avg_on2);
+                 sinfo_msg("avg_of1=%f avg_of2=%f sig_on_dif=%f sig_of_dif=%f",
+                  avg_of1,avg_of2,sig_on_dif,sig_of_dif);
+               */
+
+            }
+         }
+      }
+      cpl_image_delete(img_on1);
+      cpl_image_delete(img_of1);
+   }
+
+
+   /*
+     sinfo_get_clean_mean_window(img_on_dif,llx,lly,urx,ury,kappa,
+     nclip,&avg,&sig_on_dif);
+     sinfo_get_clean_mean_window(img_of_dif,llx,lly,urx,ury,kappa,
+     nclip,&avg,&sig_of_dif);
+   */
+
+   cpl_vector_delete(dit_on);
+   cpl_vector_delete(dit_of);
+   cpl_vector_delete(exptime_on);
+   cpl_vector_delete(exptime_of);
+
+   return res_tbl;
+
+  cleanup:
+   return NULL;
+
+}
+
+
+/*-------------------------------------------------------------------------*/
+/**
+   @name        sinfo_image_estimate_noise
+   @memo        Estimate image noise
+   @param    obj_frm input object frame
+   @param    centre  output centre of object's intensity histogram
+   @param    noise   output noise
+   @return    int
+   if success: 0
+   else -1
+
+*/
+/*--------------------------------------------------------------------------*/
+
+int
+sinfo_image_estimate_noise(cpl_image* img,
+                           const int noise_fit,
+                           double* centre,
+                           double* noise)
+{
+
+   int nbins=0;
+
+   int xsz=0;
+   int ysz=0;
+   int n=0;
+   int i=0;
+   int r=0;
+
+   int ndist=0;
+   double min_fct=HISTO_DIST_TEMPC_MIN_FCT;
+   double max_fct=HISTO_DIST_TEMPC_MAX_FCT;
+   double avg_d=0;
+   double std_d=0;
+   double hmin=0;
+   double hmax=0;
+   double kappa=3;
+
+   double* pdata=NULL;
+   double* disth=NULL;
+   double* distx=NULL;
+
+   double peak=0;
+   double tempc=0;
+   double value=0;
+   double x0=0;
+   double sigma=0;
+   double area=0;
+   double offset=0;
+   //double mse=0;
+   //double chired=0;
+
+   cpl_table* data_tbl=NULL;
+   cpl_table* histo=NULL;
+   cpl_table* dist=NULL;
+   cpl_table* min_xi=NULL;
+   cpl_table* tmp_tbl1=NULL;
+   cpl_table* tmp_tbl2=NULL;
+   cpl_vector* vx=NULL;
+   cpl_vector* vy=NULL;
+   cpl_vector* sx=NULL;
+   cpl_vector* sy=NULL;
+
+   // Get Object relevant information
+   check_nomsg(xsz=cpl_image_get_size_x(img));
+   check_nomsg(ysz=cpl_image_get_size_y(img));
+   n=xsz*ysz;
+   nbins=sqrt(n);
+   check_nomsg(data_tbl=cpl_table_new(n));
+   check_nomsg(cpl_table_new_column(data_tbl,"DATA",CPL_TYPE_DOUBLE));
+
+   check_nomsg(pdata=cpl_image_get_data(img));
+   for(i=0;i<n;i++) {
+      if(!isnan(pdata[i])) {
+         cpl_table_set_double(data_tbl,"DATA",r,pdata[i]);
+         r++;
+      }
+   }
+
+   check_nomsg(cpl_table_erase_invalid(data_tbl));
+   check_nomsg(avg_d=cpl_table_get_column_mean(data_tbl,"DATA"));
+   check_nomsg(std_d=cpl_table_get_column_stdev(data_tbl,"DATA"));
+
+   cpl_table_save(data_tbl, NULL, NULL, "out_data.fits", CPL_IO_DEFAULT);
+
+   hmin=avg_d-kappa*std_d;
+   hmax=avg_d+kappa*std_d;
+   //sinfo_msg("mean=%g stdv=%g",avg_d,std_d);
+   //sinfo_msg("hmin=%g hmax=%g",hmin,hmax);
+   //sinfo_msg("Computes histogram");
+   ck0(sinfo_histogram(data_tbl,nbins,hmin,hmax,&histo),"building histogram");
+
+   value=(double)(hmax-hmin)/nbins/2.;
+   //sinfo_msg("value=%10.8f",value);
+   //cpl_table_save(histo, NULL, NULL, "out_pippo.fits", CPL_IO_DEFAULT0);
+
+   check_nomsg(peak=cpl_table_get_column_max(histo,"HY"));
+   //sinfo_msg("peak=%f",peak);
+   sinfo_free_table(&tmp_tbl1);
+
+   check_nomsg(tmp_tbl1=sinfo_extract_table_rows(histo,"HY",CPL_EQUAL_TO,peak));
+
+   //cpl_table_save(tmp_tbl1, NULL, NULL, "out_tmp_tbl1.fits", CPL_IO_DEFAULT);
+
+
+   check_nomsg(*centre=cpl_table_get_column_mean(tmp_tbl1,"HL"));
+   //sinfo_msg("Background level=%f",*centre);
+
+   sinfo_free_table(&tmp_tbl1);
+   check_nomsg(tmp_tbl1=sinfo_extract_table_rows(histo,"HY",
+                                                 CPL_GREATER_THAN,
+                                                 peak/HISTO_Y_CUT));
+   sinfo_free_table(&tmp_tbl2);
+   check_nomsg(tmp_tbl2=sinfo_extract_table_rows(tmp_tbl1,"HY",
+                                                 CPL_LESS_THAN,peak));
+   sinfo_free_table(&tmp_tbl1);
+
+   check_nomsg(tempc=*centre-cpl_table_get_column_min(tmp_tbl2,"HL"));
+   //sinfo_msg("min HX %f",cpl_table_get_column_min(tmp_tbl2,"HL"));
+   sinfo_free_table(&tmp_tbl2);
+   //sinfo_msg("Tempc=%f",tempc);
+   check_nomsg(dist=sinfo_where_tab_min_max(histo,"HL",
+                                            CPL_GREATER_THAN,
+                                            *centre-min_fct*tempc,
+                                            CPL_NOT_GREATER_THAN,
+                                            *centre+max_fct*tempc));
+
+   offset=cpl_table_get_column_min(histo,"HY");
+   sinfo_free_table(&histo);
+
+
+   check_nomsg(ndist=cpl_table_get_nrow(dist));
+   check_nomsg(cpl_table_cast_column(dist,"HY","HYdouble",CPL_TYPE_DOUBLE));
+   check_nomsg(disth=cpl_table_get_data_double(dist,"HYdouble"));
+   check_nomsg(distx=cpl_table_get_data_double(dist,"HL"));
+   cpl_table_save(dist, NULL, NULL, "out_dist.fits", CPL_IO_DEFAULT);
+
+   //TODO
+   //gaussfit(distx,disty,dista,nterms=3);
+   //*noise=dista[2];
+   *noise=tempc/2;
+   /* THIS DOES NOT WORK */
+   //sinfo_msg("FWHM/2=%f",*noise);
+
+   if(noise_fit == 1) {
+      check_nomsg(vy=cpl_vector_wrap(ndist,disth));
+      check_nomsg(vx=cpl_vector_wrap(ndist,distx));
+      check_nomsg(sx=cpl_vector_new(ndist));
+      check_nomsg(cpl_vector_fill(sx,1.));
+      check_nomsg(sy=cpl_vector_duplicate(sx));
+      x0=*centre;
+      sigma=tempc/2;
+
+      if(CPL_ERROR_NONE != cpl_vector_fit_gaussian(vx,NULL,
+                                                   vy,NULL,
+                                                   CPL_FIT_ALL,
+                                                   &x0,&sigma,&area,&offset,
+                                                   NULL,NULL,NULL)) {
+         cpl_error_reset();
+      }
+      //sinfo_msg("Gauss fit parameters:"
+      //          "x0=%f sigma=%f area=%f offset=%f mse=%f chired=%f",
+      //           x0,sigma,area,offset,mse,chired);
+      //sinfo_msg("Background level=%f",*centre);
+      //sinfo_msg("Noise=%f",sigma);
+      *noise=sigma;
+      sinfo_unwrap_vector(&vx);
+      sinfo_unwrap_vector(&vy);
+      sinfo_free_my_vector(&sx);
+      sinfo_free_my_vector(&sy);
+   }
+   sinfo_free_table(&dist);
+
+   return 0;
+
+  cleanup:
+   sinfo_free_table(&min_xi);
+   sinfo_free_table(&tmp_tbl1);
+   sinfo_free_table(&tmp_tbl2);
+   sinfo_free_table(&histo);
+   sinfo_free_table(&dist);
+   sinfo_free_table(&data_tbl);
+   sinfo_free_my_vector(&sx);
+   sinfo_free_my_vector(&sy);
+   sinfo_unwrap_vector(&vx);
+   sinfo_unwrap_vector(&vy);
+
+   return -1;
+
+}
+
+
+
+
+
+cpl_table* sinfo_compute_linearity(cpl_frameset* son, cpl_frameset* sof)
+{
+
+   cpl_frame*    frm=NULL;
+
+   int* status=0;
+   int non=0;
+   int nof=0;
+   int nfr=0;
+   int i=0;
+   double med_on=0;
+   double avg_on=0;
+   double med_of=0;
+   double avg_of=0;
+   double med_dit=0;
+   double avg_dit=0;
+
+   double med=0;
+   double avg=0;
+
+   char* name=NULL;
+   cpl_image* img=NULL;
+   cpl_vector* vec_adl=NULL;
+   cpl_vector* vec_dit=NULL;
+   cpl_vector* vec_avg=NULL;
+   cpl_vector* vec_med=NULL;
+   cpl_vector* vec_avg_dit=NULL;
+   cpl_vector* vec_med_dit=NULL;
+   cpl_propertylist* plist=NULL;
+
+   double dit=0;
+   cpl_table* lin_tbl=NULL;
+
+
+   non = cpl_frameset_get_size(son);
+   nof = cpl_frameset_get_size(sof);
+   nfr = (non <= nof) ? non : nof;
+
+   lin_tbl=cpl_table_new(nfr);
+   cpl_table_new_column(lin_tbl,"med", CPL_TYPE_DOUBLE);
+   cpl_table_new_column(lin_tbl,"avg", CPL_TYPE_DOUBLE);
+   cpl_table_new_column(lin_tbl,"med_dit", CPL_TYPE_DOUBLE);
+   cpl_table_new_column(lin_tbl,"avg_dit", CPL_TYPE_DOUBLE);
+   cpl_table_new_column(lin_tbl,"dit", CPL_TYPE_DOUBLE);
+   vec_med=cpl_vector_new(nfr);
+   vec_avg=cpl_vector_new(nfr);
+   vec_med_dit=cpl_vector_new(nfr);
+   vec_avg_dit=cpl_vector_new(nfr);
+   vec_dit=cpl_vector_new(nfr);
+   vec_adl=cpl_vector_new(nfr);
+
+   for(i=0;i<nfr;i++) {
+      frm=cpl_frameset_get_frame(son,i);
+      name=(char*)cpl_frame_get_filename(frm);
+      img=cpl_image_load(name,CPL_TYPE_FLOAT,0,0);
+      med_on=cpl_image_get_median(img);
+      avg_on=cpl_image_get_mean(img);
+      cpl_image_delete(img);
+
+      frm=cpl_frameset_get_frame(sof,i);
+      name=(char*)cpl_frame_get_filename(frm);
+      img=cpl_image_load(name,CPL_TYPE_FLOAT,0,0);
+      med_of=cpl_image_get_median(img);
+      avg_of=cpl_image_get_mean(img);
+      cpl_image_delete(img);
+
+      med=med_on-med_of;
+      avg=avg_on-avg_of;
+      plist=cpl_propertylist_load(name,0);
+      dit=(double)sinfo_pfits_get_dit(plist);
+      cpl_propertylist_delete(plist);
+      avg_dit=avg/dit;
+      med_dit=med/dit;
+
+      cpl_vector_set(vec_dit,i,dit);
+      cpl_vector_set(vec_avg,i,avg);
+      cpl_vector_set(vec_med,i,med);
+      cpl_vector_set(vec_avg_dit,i,avg_dit);
+      cpl_vector_set(vec_med_dit,i,med_dit);
+
+      cpl_table_set_double(lin_tbl,"dit",i,dit);
+      cpl_table_set_double(lin_tbl,"med",i,med);
+      cpl_table_set_double(lin_tbl,"avg",i,avg);
+      cpl_table_set_double(lin_tbl,"med_dit",i,med_dit);
+      cpl_table_set_double(lin_tbl,"avg_dit",i,avg_dit);
+
+   }
+   cpl_table_new_column(lin_tbl,"adl", CPL_TYPE_DOUBLE);
+   med_dit=cpl_vector_get_mean(vec_med_dit);
+   avg_dit=cpl_vector_get_mean(vec_avg_dit);
+
+   for(i=0;i<nfr;i++) {
+      dit = cpl_table_get_double(lin_tbl,"dit",i,status);
+      cpl_vector_set(vec_adl,i,dit*med_dit);
+      cpl_table_set_double(lin_tbl,"adl",i,dit*med_dit);
+   }
+
+   cpl_vector_delete(vec_dit);
+   cpl_vector_delete(vec_adl);
+   cpl_vector_delete(vec_avg);
+   cpl_vector_delete(vec_med);
+   cpl_vector_delete(vec_avg_dit);
+   cpl_vector_delete(vec_med_dit);
+
+
+   return lin_tbl;
+
+}
+
+/*--------------------------------------------------------------------*/
+/**
+   @brief    The recipe data reduction ('ron' part) is implemented here
+   @param    framelist   the frames list of the current set
+   @param    set         the complete frames set
+   @return   0 if ok, -1 in error case
+*/
+/*--------------------------------------------------------------------*/
+int
+sinfo_get_ron(cpl_frameset    *   framelist,
+              const int ron_xmin,
+              const int ron_xmax,
+              const int ron_ymin,
+              const int ron_ymax,
+              const int ron_hsize,
+              const int ron_nsamp,
+              double** ron)
+{
+   cpl_imagelist   *   iset =NULL;
+   cpl_image       *   tmp_im =NULL;
+   cpl_size                 zone[4] ;
+   double              rms  =0;
+   double              ndit =0;
+   cpl_frame       *   frame =NULL;
+   int                 i;
+   cpl_propertylist* plist=NULL;
+
+   /* Test entries */
+
+   if (framelist == NULL) return -1 ;
+
+   /* Load the current set */
+   if ((iset = sinfo_new_frameset_to_iset(framelist)) == NULL) {
+      sinfo_msg_error( "Cannot load the data") ;
+      return -1 ;
+   }
+
+   /* Initialise */
+   zone[0]=ron_xmin;
+   zone[1]=ron_xmax;
+   zone[2]=ron_ymin;
+   zone[3]=ron_ymax;
+
+   /* Loop on all pairs */
+   for (i=0 ; i<cpl_imagelist_get_size(iset)-1 ; i++) {
+
+      /* Compute the current subtracted image */
+      if ((tmp_im=cpl_image_subtract_create(cpl_imagelist_get(iset,i),
+                                            cpl_imagelist_get(iset, i+1)))
+          == NULL) {
+         sinfo_msg_error( "Cannot subtract the images") ;
+         sinfo_free_imagelist(&iset) ;
+         return -1 ;
+      }
+
+      /* Compute the read-out noise */
+      if (cpl_flux_get_noise_window(tmp_im, zone, ron_hsize,
+                                    ron_nsamp, &rms, NULL) != CPL_ERROR_NONE) {
+         sinfo_msg_error( "Cannot compute the RON") ;
+         sinfo_free_image(&tmp_im) ;
+         sinfo_free_imagelist(&iset) ;
+         return -1 ;
+      }
+      sinfo_free_image(&tmp_im) ;
+      /* Normalise the RON with NDIT */
+      frame = cpl_frameset_get_frame(framelist, i) ;
+      cknull_nomsg(plist=cpl_propertylist_load(cpl_frame_get_filename(frame),
+                                               0));
+      ndit=sinfo_pfits_get_ndit(plist);
+      sinfo_free_propertylist(&plist);
+
+      (*ron)[i] = rms * sqrt(ndit/2.0) ;
+
+   }
+
+   /* Free and return */
+   sinfo_free_imagelist(&iset) ;
+   return 0 ;
+
+  cleanup:
+   sinfo_free_image(&tmp_im);
+   sinfo_free_imagelist(&iset);
+   sinfo_free_propertylist(&plist);
+   return -1;
+
+}
+
+
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Define the input raw frames for sinfoni_img_combine
+   @param    tag     The candidate DO_CATG
+   @return   0 for no, 1 for yes, -1 in error case
+*/
+/*---------------------------------------------------------------------------*/
+int sinfo_stack_get_pro_tag(char * tag_in, char* tag_out)
+{
+   /* Test entries */
+   if (tag_in == NULL) return -1 ;
+   /* here for the moment we set the same PRO ID as a non stacked frame */
+   if (strcmp(tag_in,RAW_WAVE_LAMP_DITHER) == 0 ) {
+      strcpy(tag_out,PRO_WAVE_LAMP_STACKED);
+      return 0 ;
+   }
+
+
+   if (strcmp(tag_in,RAW_WAVE_LAMP) == 0 ) {
+      strcpy(tag_out,PRO_WAVE_LAMP_STACKED);
+      return 0 ;
+   }
+
+   if (strcmp(tag_in,RAW_WAVE_NS_DITHER) == 0 ) {
+      strcpy(tag_out,PRO_WAVE_NS_STACKED);
+      return 0 ;
+   }
+
+
+   if (strcmp(tag_in,RAW_WAVE_NS) == 0 ) {
+      strcpy(tag_out,PRO_WAVE_NS_STACKED);
+      return 0 ;
+   }
+
+
+   if (strcmp(tag_in,RAW_FIBRE_LAMP) == 0 ) {
+      strcpy(tag_out,PRO_FIBRE_LAMP_STACKED);
+      return 0 ;
+   }
+
+   if (strcmp(tag_in,RAW_FIBRE_EW) == 0 ) {
+      strcpy(tag_out,PRO_FIBRE_EW_STACKED);
+      return 0 ;
+   }
+
+   if (strcmp(tag_in,RAW_FIBRE_NS) == 0 ) {
+      strcpy(tag_out,PRO_FIBRE_NS_STACKED);
+      return 0 ;
+   }
+
+
+   if (strcmp(tag_in,PRO_FIBRE_NS_STACKED_ON) == 0 ) {
+      strcpy(tag_out,PRO_FIBRE_NS_STACKED);
+      return 0 ;
+   }
+
+   if (strcmp(tag_in,PRO_FIBRE_NS_STACKED) == 0 ) {
+      strcpy(tag_out,PRO_FIBRE_NS_STACKED_DIST);
+      return 0 ;
+   }
+
+
+   if (strcmp(tag_in,RAW_SLIT_LAMP) == 0 ) {
+      strcpy(tag_out,PRO_SLIT_LAMP_STACKED);
+      return 0 ;
+   }
+
+
+   if (strstr(tag_in, "FLUX") != NULL ) {
+      strcpy(tag_out,PRO_FLUX_LAMP_STACKED);
+      return 0 ;
+   }
+
+   if (strstr(tag_in, "PSF") != NULL ) {
+      strcpy(tag_out,PRO_PSF_CALIBRATOR_STACKED);
+      return 0 ;
+   }
+
+
+   if (strstr(tag_in, "FOCUS") != NULL ) {
+      strcpy(tag_out,PRO_FOCUS_STACKED);
+      return 0 ;
+   }
+
+   if (strstr(tag_in, "OBJECT_NODDING") != NULL ) {
+      strcpy(tag_out,PRO_OBJECT_NODDING_STACKED);
+      return 0 ;
+   }
+
+   if (strstr(tag_in, "SKY_NODDING") != NULL ) {
+      strcpy(tag_out,PRO_SKY_NODDING_STACKED);
+      return 0 ;
+   }
+
+   if (strstr(tag_in, "STD_NODDING") != NULL ) {
+      strcpy(tag_out,PRO_STD_NODDING_STACKED);
+      return 0 ;
+   }
+
+   if (strstr(tag_in, "OBJECT_SKYSPIDER") != NULL ) {
+      strcpy(tag_out,PRO_OBJECT_SKYSPIDER_STACKED);
+      return 0 ;
+   }
+
+
+   if (strstr(tag_in, RAW_STD) != NULL ) {
+      strcpy(tag_out,PRO_STD_STACKED);
+      return 0 ;
+   }
+
+
+   if (strstr(tag_in, RAW_SKY_STD) != NULL ) {
+      strcpy(tag_out,PRO_SKY_STD_STACKED);
+      return 0 ;
+   }
+
+   if (strstr(tag_in, RAW_SKY_OH) != NULL ) {
+      strcpy(tag_out,PRO_SKY_OH_STACKED);
+      return 0 ;
+   }
+
+   if (strstr(tag_in, RAW_SKY_PSF_CALIBRATOR) != NULL ) {
+      strcpy(tag_out,PRO_SKY_PSF_CALIBRATOR_STACKED);
+      return 0 ;
+   }
+
+   if (strstr(tag_in, RAW_STD_STAR) != NULL ) {
+      strcpy(tag_out,PRO_STD_STAR_STACKED);
+      return 0 ;
+   }
+
+   if (strstr(tag_in, RAW_STD_STAR) != NULL ) {
+      strcpy(tag_out,PRO_STD_STAR_DITHER_STACKED);
+      return 0 ;
+   }
+
+   if (strstr(tag_in, RAW_SKY) != NULL ) {
+      strcpy(tag_out,PRO_SKY_STACKED);
+      return 0 ;
+   }
+
+
+   return 1 ;
+}
+
+
+int sinfo_is_dark(char * tag)
+{
+   /* Test entries */
+   if (tag == NULL) return -1 ;
+
+   if (!strcmp(tag, RAW_DARK)) return 1 ;
+   if (!strcmp(tag, PRO_MASTER_DARK)) return 1 ;
+   return 0 ;
+}
+
+int sinfo_is_flat_bp(char * tag)
+{
+   /* Test entries */
+   if (tag == NULL) return -1 ;
+
+   if (!strcmp(tag, RAW_LINEARITY_LAMP)) return 1 ;
+   return 0 ;
+}
+
+int sinfo_is_flat_lindet(char * tag)
+{
+   /* Test entries */
+   if (tag == NULL) return -1 ;
+
+   if (!strcmp(tag, RAW_LINEARITY_LAMP)) return 1 ;
+   return 0 ;
+}
+
+
+int sinfo_blank2dot(const char * in, char* ou)
+{
+   int len=0;
+   int i=0;
+
+   strcpy(ou,in);
+   len = strlen(in);
+   for (i=0;i<len;i++)
+   {
+      if (in[i] == ' ') {
+         ou[i] =  '.';
+      }
+   }
+   return 0;
+}
+
+
+int sinfo_is_sky_flat(char * tag)
+{
+   /* Test entries */
+   if (tag == NULL) return -1 ;
+   if (!strcmp(tag, RAW_FLAT_SKY)) return 1 ;
+   return 0 ;
+}
+
+
+
+int sinfo_is_master_flat(char * tag)
+{
+   /* Test entries */
+   if (tag == NULL) return -1 ;
+
+   if (!strcmp(tag, PRO_MASTER_FLAT_LAMP)) return 1 ;
+   if (!strcmp(tag, PRO_MASTER_FLAT_LAMP1)) return 1 ;
+   return 0 ;
+}
+
+int sinfo_is_master_flat_dither(char * tag)
+{
+   /* Test entries */
+   if (tag == NULL) return -1 ;
+
+   if (!strcmp(tag, PRO_MASTER_FLAT_LAMP2)) return 1 ;
+   return 0 ;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Define the input raw frames for sinfoni_util_inputs
+   @param    tag     The candidate DO_CATG
+   @return   0 for no, 1 for yes, -1 in error case
+*/
+/*---------------------------------------------------------------------------*/
+int sinfo_is_stack(char * tag)
+{
+   /* Test entries */
+   if (tag == NULL) return -1 ;
+
+   if (strstr(tag, PRO_STACKED) != NULL) return 1 ;
+   return 0 ;
+}
+
+int sinfo_is_mflat(char * tag)
+{
+   /* Test entries */
+   if (tag == NULL) return -1 ;
+
+   if (!strcmp(tag, PRO_MASTER_FLAT_LAMP)) return 1 ;
+   if (!strcmp(tag, PRO_MASTER_FLAT_LAMP1)) return 1 ;
+   if (!strcmp(tag, PRO_MASTER_FLAT_LAMP2)) return 1 ;
+   return 0 ;
+}
+
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Define the input raw frames for sinfoni_util_inputs
+   @param    tag     The candidate DO_CATG
+   @return   0 for no, 1 for yes, -1 in error case
+*/
+/*---------------------------------------------------------------------------*/
+int sinfo_is_psf_calibrator_stacked(char * tag)
+{
+   /* Test entries */
+   if (tag == NULL) return -1 ;
+
+   if (!strcmp(tag, PRO_PSF_CALIBRATOR_STACKED)) return 1 ;
+   return 0 ;
+}
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Define the input raw frames for sinfoni_util_inputs
+   @param    tag     The candidate DO_CATG
+   @return   0 for no, 1 for yes, -1 in error case
+*/
+/*---------------------------------------------------------------------------*/
+int sinfo_is_focus_stacked(char * tag)
+{
+   /* Test entries */
+   if (tag == NULL) return -1 ;
+
+   if (!strcmp(tag, PRO_FOCUS_STACKED)) return 1 ;
+   return 0 ;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Define the input raw frames for sinfoni_util_inputs
+   @param    tag     The candidate DO_CATG
+   @return   0 for no, 1 for yes, -1 in error case
+*/
+/*---------------------------------------------------------------------------*/
+int sinfo_is_lamp_wave_stacked(char * tag)
+{
+   /* Test entries */
+   if (tag == NULL) return -1 ;
+
+   if (!strcmp(tag, PRO_WAVE_LAMP_STACKED)) return 1 ;
+   return 0 ;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Define the input raw frames for sinfoni_util_inputs
+   @param    tag     The candidate DO_CATG
+   @return   0 for no, 1 for yes, -1 in error case
+*/
+/*---------------------------------------------------------------------------*/
+int sinfo_is_lamp_flux_stacked(char * tag)
+{
+   /* Test entries */
+   if (tag == NULL) return -1 ;
+
+   if (!strcmp(tag, PRO_FLUX_LAMP_STACKED)) return 1 ;
+   return 0 ;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Define the input raw frames for sinfoni_util_inputs
+   @param    tag     The candidate DO_CATG
+   @return   0 for no, 1 for yes, -1 in error case
+*/
+/*---------------------------------------------------------------------------*/
+int sinfo_is_object_nodding_stacked(char * tag)
+{
+   /* Test entries */
+   if (tag == NULL) return -1 ;
+
+   if (!strcmp(tag, PRO_OBJECT_NODDING_STACKED)) return 1 ;
+   return 0 ;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Define the input raw frames for sinfoni_util_inputs
+   @param    tag     The candidate DO_CATG
+   @return   0 for no, 1 for yes, -1 in error case
+*/
+/*---------------------------------------------------------------------------*/
+int sinfo_is_object_skyspider_stacked(char * tag)
+{
+   /* Test entries */
+   if (tag == NULL) return -1 ;
+
+   if (!strcmp(tag, PRO_OBJECT_SKYSPIDER_STACKED)) return 1 ;
+   return 0 ;
+}
+
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Define the input raw frames for sinfoni_util_inputs
+   @param    tag     The candidate DO_CATG
+   @return   0 for no, 1 for yes, -1 in error case
+*/
+/*---------------------------------------------------------------------------*/
+int sinfo_is_sky_nodding_stacked(char * tag)
+{
+   /* Test entries */
+   if (tag == NULL) return -1 ;
+
+   if (!strcmp(tag, PRO_SKY_NODDING_STACKED)) return 1 ;
+   return 0 ;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Define the input raw frames for sinfoni_util_inputs
+   @param    tag     The candidate DO_CATG
+   @return   0 for no, 1 for yes, -1 in error case
+*/
+/*---------------------------------------------------------------------------*/
+int sinfo_is_wavemap(char * tag)
+{
+   /* Test entries */
+   if (tag == NULL) return -1 ;
+
+   if (!strcmp(tag, PRO_WAVE_MAP)) return 1 ;
+   return 0 ;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Define the input raw frames for sinfoni_util_inputs
+   @param    tag     The candidate DO_CATG
+   @return   0 for no, 1 for yes, -1 in error case
+*/
+/*---------------------------------------------------------------------------*/
+int sinfo_is_halosp(char * tag)
+{
+   /* Test entries */
+   if (tag == NULL) return -1 ;
+
+   if (!strcmp(tag, PRO_HALO_SPECT)) return 1 ;
+   return 0 ;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Define the input raw frames for sinfoni_util_inputs
+   @param    tag     The candidate DO_CATG
+   @return   0 for no, 1 for yes, -1 in error case
+*/
+/*---------------------------------------------------------------------------*/
+int sinfo_is_distlist(char * tag)
+{
+   /* Test entries */
+   if (tag == NULL) return -1 ;
+
+   if (!strcmp(tag, PRO_SLITLETS_DISTANCE)) return 1 ;
+   return 0 ;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Define the input raw frames for sinfoni_util_inputs
+   @param    tag     The candidate DO_CATG
+   @return   0 for no, 1 for yes, -1 in error case
+*/
+/*---------------------------------------------------------------------------*/
+int sinfo_is_slitpos(char * tag)
+{
+   /* Test entries */
+   if (tag == NULL) return -1 ;
+
+   if (!strcmp(tag, PRO_SLIT_POS)) return 1 ;
+   return 0 ;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Define the input raw frames for sinfoni_util_inputs
+   @param    tag     The candidate DO_CATG
+   @return   0 for no, 1 for yes, -1 in error case
+*/
+/*---------------------------------------------------------------------------*/
+int sinfo_is_firstcol(char * tag)
+{
+   /* Test entries */
+   if (tag == NULL) return -1 ;
+
+   if (!strcmp(tag, PRO_FIRST_COL)) return 1 ;
+   return 0 ;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Define the bad pixel map
+   @param    tag     The candidate DO_CATG
+   @return   0 for no, 1 for yes, -1 in error case
+*/
+/*---------------------------------------------------------------------------*/
+int sinfo_is_bpmap(char * tag)
+{
+   /* Test entries */
+   if (tag == NULL) return -1 ;
+
+   if (!strcmp(tag, PRO_BP_MAP)) return 1 ;
+   return 0 ;
+}
+
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Add PRO* keywords to a SINFONI FITS header
+   @param    ref_file      product status
+   @param    set_id        instrument setting id
+   @return   0 if ok, -1 otherwise
+
+   DFS only. See the DICB dictionaries to have details on the keywords.
+*/
+/*---------------------------------------------------------------------------*/
+
+int sinfo_get_band(cpl_frame * ref_frame,char * band)
+{
+
+   char* ref_file=NULL;
+   cpl_propertylist* plist=NULL;
+
+   ref_file = cpl_strdup(cpl_frame_get_filename(ref_frame)) ;
+   if ((cpl_error_code)((plist = cpl_propertylist_load(ref_file, 0)) == NULL)) {
+      sinfo_msg_error( "getting header from reference frame %s",ref_file);
+      cpl_propertylist_delete(plist) ;
+      return -1 ;
+   }
+
+   if (sinfo_propertylist_has(plist, KEY_NAME_FILT_NAME)) {
+      strcpy(band, cpl_propertylist_get_string(plist, KEY_NAME_FILT_NAME));
+      /* sinfo_msg("%s value is %s", KEY_NAME_FILT_NAME, band); */
+
+   } else {
+      sinfo_msg_warning("keyword %s does not exist",KEY_NAME_FILT_NAME);
+      return -1;
+   }
+
+   cpl_free(ref_file);
+   cpl_propertylist_delete(plist);
+   return 0;
+}
+
+
+
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Add PRO* keywords to a SINFONI FITS header
+   @param    ref_file      product status
+   @return   0 if ok, -1 otherwise
+
+   DFS only. See the DICB dictionaries to have details on the keywords.
+*/
+/*---------------------------------------------------------------------------*/
+
+int sinfo_get_obsname(cpl_frame * ref_frame, const char* obs_name)
+{
+
+   char* ref_file=NULL;
+   cpl_propertylist* plist=NULL;
+
+   ref_file = cpl_strdup(cpl_frame_get_filename(ref_frame)) ;
+   if ((cpl_error_code)((plist = cpl_propertylist_load(ref_file, 0)) == NULL)) {
+      sinfo_msg_error( "getting header from reference frame %s",ref_file);
+      cpl_propertylist_delete(plist) ;
+      return -1 ;
+   }
+
+   if (sinfo_propertylist_has(plist, KEY_NAME_OBS_NAME)) {
+      strcpy((char*)obs_name, cpl_propertylist_get_string(plist,
+                                                          KEY_NAME_OBS_NAME));
+      /* sinfo_msg("%s value is %s", KEY_NAME_OBS_NAME, obs_name); */
+
+   } else {
+      sinfo_msg_warning("keyword %s does not exist",KEY_NAME_OBS_NAME);
+      return -1;
+   }
+
+   cpl_free(ref_file);
+   cpl_propertylist_delete(plist);
+   return 0;
+}
+
+
+
+
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Get keywords value from SINFONI FITS header
+   @param    ref_frame   input frame
+   @param    key_name    keyword name
+   @return   key_value if ok, -1 otherwise
+
+*/
+/*---------------------------------------------------------------------------*/
+
+int sinfo_get_keyvalue_int(cpl_frame * ref_frame, const char* key_name)
+{
+
+   char* ref_file=NULL;
+   cpl_propertylist* plist=NULL;
+   int result=0;
+
+   ref_file = cpl_strdup(cpl_frame_get_filename(ref_frame)) ;
+
+   if ((cpl_error_code)((plist = cpl_propertylist_load(ref_file, 0)) == NULL)) {
+      sinfo_msg_error( "getting header from reference frame %s",ref_file);
+      cpl_propertylist_delete(plist) ;
+      return -1;
+   }
+
+
+   if (sinfo_propertylist_has(plist, key_name)) {
+      result=cpl_propertylist_get_int(plist,key_name);
+   } else {
+      sinfo_msg_warning("keyword %s does not exist",key_name);
+      return -1;
+   }
+
+   cpl_free(ref_file);
+   cpl_propertylist_delete(plist);
+
+   return result;
+}
+
+
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Get keywords value from SINFONI FITS header
+   @param    ref_frame   input frame
+   @param    key_name    keyword name
+   @return   key_value if ok, -1 otherwise
+
+*/
+/*---------------------------------------------------------------------------*/
+
+float sinfo_get_keyvalue_float(cpl_frame * ref_frame, const char* key_name)
+{
+
+   char* ref_file=NULL;
+   cpl_propertylist* plist=NULL;
+   float result=0;
+
+   ref_file = cpl_strdup(cpl_frame_get_filename(ref_frame)) ;
+
+   if ((cpl_error_code)((plist = cpl_propertylist_load(ref_file, 0)) == NULL)) {
+      sinfo_msg_error( "getting header from reference frame %s",ref_file);
+      cpl_propertylist_delete(plist) ;
+      return -1;
+   }
+
+
+   if (sinfo_propertylist_has(plist, key_name)) {
+      result=cpl_propertylist_get_float(plist,key_name);
+   } else {
+      sinfo_msg_warning("keyword %s does not exist",key_name);
+      return -1;
+   }
+
+   cpl_free(ref_file);
+   cpl_propertylist_delete(plist);
+
+   return result;
+}
+
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Get keywords value from SINFONI FITS header
+   @param    ref_frame   input frame
+   @param    key_name    keyword name
+   @return   key_value if ok, -1 otherwise
+
+*/
+/*---------------------------------------------------------------------------*/
+
+char sinfo_get_keyvalue_bool(cpl_frame * ref_frame, const char* key_name)
+{
+
+   char* ref_file=NULL;
+   cpl_propertylist* plist=NULL;
+   int res_val=0;
+
+   ref_file = cpl_strdup(cpl_frame_get_filename(ref_frame)) ;
+
+   if ((cpl_error_code)((plist = cpl_propertylist_load(ref_file, 0)) == NULL)) {
+      sinfo_msg_error( "getting header from reference frame %s",ref_file);
+      cpl_propertylist_delete(plist) ;
+      return '0';
+   }
+
+
+   if (sinfo_propertylist_has(plist, key_name)) {
+      res_val=cpl_propertylist_get_bool(plist,key_name);
+   } else {
+      sinfo_msg_warning("keyword %s does not exist",key_name);
+      return '0';
+   }
+
+   cpl_free(ref_file);
+   cpl_propertylist_delete(plist);
+   if(res_val == 1) {
+      return 'T';
+   } else {
+      return 'F';
+   }
+}
+
+
+
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Get keywords value from SINFONI FITS header
+   @param    ref_frame   input frame
+   @param    key_name    keyword name
+   @return   key_value if ok, -1 otherwise
+
+*/
+/*---------------------------------------------------------------------------*/
+
+const char*
+sinfo_get_keyvalue_string(cpl_frame * ref_frame, const char* key_name)
+{
+
+   char* ref_file=NULL;
+   cpl_propertylist* plist=NULL;
+   const char* result=NULL;
+
+   ref_file = cpl_strdup(cpl_frame_get_filename(ref_frame)) ;
+
+   if ((cpl_error_code)((plist = cpl_propertylist_load(ref_file, 0)) == NULL)) {
+      sinfo_msg_error( "getting header from reference frame %s",ref_file);
+      cpl_propertylist_delete(plist) ;
+      return FALSE;
+   }
+
+
+   if (sinfo_propertylist_has(plist, key_name)) {
+      result=cpl_propertylist_get_string(plist,key_name);
+   } else {
+      sinfo_msg_warning("keyword %s does not exist",key_name);
+      return NULL;
+   }
+
+   cpl_free(ref_file);
+   cpl_propertylist_delete(plist);
+
+   return result;
+}
+
+
+
+double sinfo_get_mjd_obs(cpl_frame * frame)
+{
+   cpl_propertylist* plist=NULL;
+   const char* file=NULL;
+
+   double mjd_obs=0.;
+   file = cpl_frame_get_filename(frame) ;
+
+   if ((cpl_error_code)((plist = cpl_propertylist_load(file, 0)) == NULL)) {
+      sinfo_msg_error( "getting header from reference frame %s",file);
+      sinfo_free_propertylist(&plist) ;
+      return -1 ;
+   }
+
+   if (sinfo_propertylist_has(plist, KEY_NAME_MJD_OBS)) {
+      mjd_obs=cpl_propertylist_get_double(plist, KEY_NAME_MJD_OBS);
+   } else {
+      sinfo_msg_error("keyword %s does not exist",KEY_NAME_MJD_OBS);
+      sinfo_free_propertylist(&plist) ;
+      return -1;
+   }
+   sinfo_free_propertylist(&plist) ;
+
+   return mjd_obs;
+
+}
+
+
+
+
+double sinfo_get_cumoffsetx(cpl_frame * frame)
+{
+   cpl_propertylist* plist=NULL;
+   char* file=NULL;
+
+   double result=0.;
+   file = cpl_strdup( cpl_frame_get_filename(frame)) ;
+
+   if ((cpl_error_code)((plist = cpl_propertylist_load(file, 0)) == NULL)) {
+      sinfo_msg_error( "getting header from reference frame %s",file);
+      cpl_propertylist_delete(plist) ;
+      cpl_free(file);
+      return -1 ;
+   }
+
+   if (sinfo_propertylist_has(plist, KEY_NAME_CUMOFFX)) {
+      result=cpl_propertylist_get_double(plist, KEY_NAME_CUMOFFX);
+   } else {
+      sinfo_msg_error("keyword %s does not exist",KEY_NAME_CUMOFFX);
+      cpl_propertylist_delete(plist) ;
+      return -1;
+   }
+   cpl_propertylist_delete(plist) ;
+   cpl_free(file);
+
+   return result;
+
+}
+
+
+
+
+double sinfo_get_cumoffsety(cpl_frame * frame)
+{
+   cpl_propertylist* plist=NULL;
+   char* file=NULL;
+
+   double result=0.;
+   file = cpl_strdup( cpl_frame_get_filename(frame)) ;
+
+   if ((cpl_error_code)((plist = cpl_propertylist_load(file, 0)) == NULL)) {
+      sinfo_msg_error( "getting header from reference frame %s",file);
+      cpl_propertylist_delete(plist) ;
+      cpl_free(file);
+      return -1 ;
+   }
+
+   if (sinfo_propertylist_has(plist, KEY_NAME_CUMOFFY)) {
+      result=cpl_propertylist_get_double(plist, KEY_NAME_CUMOFFY);
+   } else {
+      sinfo_msg_error("keyword %s does not exist",KEY_NAME_CUMOFFY);
+      cpl_propertylist_delete(plist) ;
+      return -1;
+   }
+   cpl_propertylist_delete(plist) ;
+   cpl_free(file);
+
+   return result;
+
+}
+
+int sinfo_frame_is_dither(cpl_frame * frame)
+{
+
+   char file[256];
+   char band[FILE_NAME_SZ];
+
+
+   cpl_propertylist* plist=NULL;
+   int grat_encoder=0;
+   int dith_status=1;
+   int len=0;
+
+
+   cknull(frame,"Null input frame. Exit!");
+
+   cknull_nomsg(strcpy(file,cpl_frame_get_filename(frame)));
+   len= strlen(file);
+
+   if(len<1) goto cleanup;
+   if(sinfo_file_exists(file)==0) goto cleanup;
+   //file = cpl_strdup(cpl_frame_get_filename(frame)) ;
+   cknull(plist = cpl_propertylist_load(file, 0),
+      "getting header from reference frame %s",file);
+
+   if (sinfo_propertylist_has(plist, KEY_NAME_FILT_NAME)) {
+      strcpy(band,cpl_propertylist_get_string(plist, KEY_NAME_FILT_NAME));
+   } else {
+      sinfo_msg_error("keyword %s does not exist",KEY_NAME_FILT_NAME);
+      sinfo_free_propertylist(&plist) ;
+      return -1;
+   }
+
+   if (sinfo_propertylist_has(plist, KEY_NAME_GRAT_ENC)) {
+      grat_encoder = cpl_propertylist_get_int(plist, KEY_NAME_GRAT_ENC);
+   } else {
+      sinfo_msg_error("keyword %s does not exist",KEY_NAME_GRAT_ENC);
+      sinfo_free_propertylist(&plist) ;
+      return -1;
+   }
+
+   sinfo_free_propertylist(&plist) ;
+
+   if (strcmp(band,"H") == 0) {
+      if( abs(grat_encoder - GRAT_VAL2_H) <= GRAT_VAL_TOL ) {
+         dith_status = 0;
+      } else {
+         dith_status = 0;
+      }
+   }
+   else if (strcmp(band,"H+K") == 0) {
+      if( abs(grat_encoder - GRAT_VAL2_HK) <= GRAT_VAL_TOL ) {
+         dith_status = 0;
+      } else {
+         dith_status = 0;
+      }
+   }
+   else if (strcmp(band,"K") == 0) {
+      if( abs(grat_encoder - GRAT_VAL2_K) <= GRAT_VAL_TOL ) {
+         dith_status = 0;
+      } else {
+         dith_status = 0;
+      }
+   }
+   else if (strcmp(band,"J") == 0) {
+      if( abs(grat_encoder - GRAT_VAL2_J) <= GRAT_VAL_TOL ) {
+         dith_status = 0;
+      } else {
+         dith_status = 0;
+      }
+   }
+ cleanup:
+
+   sinfo_free_propertylist(&plist) ;
+   if(cpl_error_get_code() != CPL_ERROR_NONE) {
+     return -1;
+   } else {
+     return dith_status;
+   }
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Add PRO* keywords to a SINFONI FITS header
+   @param    ref_file      product status
+   @param    spat_res      spatial resolution
+   @return   0 if ok, -1 otherwise
+
+   DFS only. See the DICB dictionaries to have details on the keywords.
+*/
+/*---------------------------------------------------------------------------*/
+
+int sinfo_get_spatial_res(cpl_frame * ref_frame, char * spat_res)
+{
+
+   const char* ref_file;
+   cpl_propertylist* plist=NULL;
+
+   ref_file=cpl_frame_get_filename(ref_frame) ;
+   if ((cpl_error_code)((plist = cpl_propertylist_load(ref_file, 0)) == NULL)) {
+      sinfo_msg_error( "getting header from reference frame %s",ref_file);
+      sinfo_free_propertylist(&plist) ;
+      return -1 ;
+
+   }
+
+   if (sinfo_propertylist_has(plist, KEY_NAME_PREOPTICS)) {
+      strcpy(spat_res,cpl_propertylist_get_string(plist, KEY_NAME_PREOPTICS));
+      /* sinfo_msg("%s value is %s", KEY_NAME_PREOPTICS, spat_res); */
+   } else {
+      sinfo_msg_warning("keyword %s does not exist",KEY_NAME_PREOPTICS);
+      sinfo_free_propertylist(&plist);
+      return -1;
+   }
+   sinfo_free_propertylist(&plist);
+   return 0;
+
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Add PRO* keywords to a SINFONI FITS header
+   @param    ref_file      product status
+   @return   0 if ok, -1 otherwise
+
+   DFS only. See the DICB dictionaries to have details on the keywords.
+*/
+/*---------------------------------------------------------------------------*/
+
+int sinfo_frame_is_sky(cpl_frame * ref_frame)
+{
+
+   char  dpr_type[FILE_NAME_SZ];
+   char* ref_file=NULL;
+   const char* sval=NULL;
+
+   int result=0;
+   cpl_propertylist* plist=NULL;
+
+   sval = cpl_frame_get_filename(ref_frame) ;
+   ref_file = cpl_strdup(sval) ;
+
+   if ((cpl_error_code)((plist = cpl_propertylist_load(ref_file, 0)) == NULL)) {
+      sinfo_msg_error( "getting header from reference frame %s",ref_file);
+      cpl_propertylist_delete(plist) ;
+      cpl_free(ref_file);
+      return -1 ;
+   }
+
+   if (sinfo_propertylist_has(plist, KEY_NAME_DPR_TYPE)) {
+      strcpy(dpr_type,cpl_propertylist_get_string(plist, KEY_NAME_DPR_TYPE));
+      /* sinfo_msg("%s value is %d", KEY_NAME_DPR_TYPE, dpr_type); */
+   } else {
+      sinfo_msg_warning("keyword %s does not exist",KEY_NAME_DPR_TYPE);
+      cpl_propertylist_delete(plist) ;
+      cpl_free(ref_file);
+      return -1;
+   }
+   cpl_propertylist_delete(plist);
+   if(strstr(dpr_type,RAW_SKY) != NULL) {
+      result=1;
+   }
+   cpl_free(ref_file);
+
+   return result;
+
+}
+
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Add PRO* keywords to a SINFONI FITS header
+   @param    tag     product status
+   @return   0 if ok, -1 otherwise
+
+   DFS only. See the DICB dictionaries to have details on the keywords.
+*/
+/*---------------------------------------------------------------------------*/
+
+int sinfo_tag_is_sky(char * tag)
+{
+
+   int result=0;
+
+   if(
+      (strcmp(tag,RAW_SKY) == 0)         ||
+      (strcmp(tag,RAW_IMAGE_PRE_SKY) == 0)         ||
+      (strcmp(tag,RAW_SKY_NODDING) == 0) ||
+      (strcmp(tag,RAW_SKY_JITTER) == 0) ||
+      (strcmp(tag,RAW_SKY_STD) == 0)     ||
+      (strcmp(tag,RAW_FIBRE_DARK) == 0) ||
+      (strcmp(tag,RAW_SKY_OH) == 0)      ||
+      (strcmp(tag,RAW_SKY_PSF_CALIBRATOR) == 0)
+      ) {
+      result=1;
+   }
+
+   return result;
+
+}
+
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Add PRO* keywords to a SINFONI FITS header
+   @param    tag     product status
+   @return   0 if ok, -1 otherwise
+
+   DFS only. See the DICB dictionaries to have details on the keywords.
+*/
+/*---------------------------------------------------------------------------*/
+
+int sinfo_tag_is_obj(char * tag)
+{
+
+   int result=0;
+
+   if(
+      (strcmp(tag,RAW_PUPIL_LAMP) == 0) ||
+      (strcmp(tag,RAW_OBJECT) == 0)         ||
+      (strcmp(tag,RAW_IMAGE_PRE_OBJECT) == 0)         ||
+      (strcmp(tag,RAW_OBJECT_NODDING) == 0) ||
+      (strcmp(tag,RAW_OBJECT_JITTER) == 0) ||
+      (strcmp(tag,RAW_PSF_CALIBRATOR) == 0) ||
+      (strcmp(tag,RAW_FIBRE_PSF) == 0) ||
+      (strcmp(tag,RAW_STD) == 0)            ||
+      (strcmp(tag,RAW_STD_STAR) == 0)
+
+      ) {
+      result=1;
+   }
+
+   return result;
+
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Add PRO* keywords to a SINFONI FITS header
+   @param    tag     product status
+   @return   0 if ok, -1 otherwise
+
+   DFS only. See the DICB dictionaries to have details on the keywords.
+*/
+/*---------------------------------------------------------------------------*/
+
+int sinfo_tag_is_objpro(char * tag)
+{
+
+   int result=0;
+
+   if(
+      (strcmp(tag,PRO_COADD_OBJ) == 0) ||
+      (strcmp(tag,PRO_COADD_PSF) == 0) ||
+      (strcmp(tag,PRO_COADD_STD) == 0) ||
+      (strcmp(tag,PRO_OBS_OBJ) == 0) ||
+      (strcmp(tag,PRO_OBS_PSF) == 0) ||
+      (strcmp(tag,PRO_OBS_STD) == 0) ||
+      (strcmp(tag,PRO_PSF_CALIBRATOR_STACKED) == 0) ||
+      (strcmp(tag,PRO_SKY_PSF_CALIBRATOR_STACKED) == 0) ||
+      (strcmp(tag,PRO_STD_STACKED) == 0) ||
+      (strcmp(tag,PRO_SKY_STD_STACKED) == 0) ||
+      (strcmp(tag,PRO_OBJECT_NODDING_STACKED) == 0) ||
+      (strcmp(tag,PRO_SKY_NODDING_STACKED) == 0)
+      ) {
+      result=1;
+   }
+
+   return result;
+
+}
+
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Add PRO* keywords to a SINFONI FITS header
+   @param    ref_file      product status
+   @return   1 if on 0 if off if ok, -1 if unknown
+
+   DFS only. See the DICB dictionaries to have details on the keywords.
+*/
+/*---------------------------------------------------------------------------*/
+
+int sinfo_frame_is_on(cpl_frame * ref_frame)
+{
+
+   char ref_file[FILE_NAME_SZ];
+   char dpr_type[FILE_NAME_SZ];
+   int lamp_Xe=0;
+   int lamp_Kr=0;
+   int lamp_Ne=0;
+   int lamp_Ar=0;
+   int lamp_Halo=0;
+   int len=0;
+   int result=0;
+   cpl_propertylist* plist=NULL;
+   const char* filename=NULL;
+   cknull(ref_frame,"Null input frame. Exit!");
+
+   cknull_nomsg(filename=cpl_frame_get_filename(ref_frame));
+   len= strlen(filename);
+   if(len<1) goto cleanup;
+
+   check_nomsg(strcpy(ref_file, filename)) ;
+   if ((cpl_error_code)((plist = cpl_propertylist_load(ref_file,0)) == NULL)) {
+      sinfo_msg_error( "getting header from reference frame %s",ref_file);
+      sinfo_free_propertylist(&plist) ;
+      return -1 ;
+   }
+
+/*-----------------------------------------------------------------------
+  in J  Argon (4)
+  in H Xenon and Argon (1+4)
+  in K Neon (3)
+  in H+K Xenon (1)
+  -------------------------------------------------------------------------*/
+   if (sinfo_propertylist_has(plist, KEY_NAME_DPR_TYPE)) {
+      strcpy(dpr_type,cpl_propertylist_get_string(plist, KEY_NAME_DPR_TYPE));
+      /* sinfo_msg("%s value is %s", KEY_NAME_DPR_TYPE, dpr_type); */
+   } else {
+      sinfo_msg_warning("keyword %s does not exist",KEY_NAME_DPR_TYPE);
+      sinfo_free_propertylist(&plist);
+      return -1;
+   }
+
+   /*
+     In order to use the frame tag to identify frames we have to add this line
+     strcpy(dpr_type,cpl_frame_get_tag(ref_frame));
+
+   */
+
+   if(strstr(dpr_type,"STD") != NULL) {
+      result = 1;
+      sinfo_free_propertylist(&plist);
+      return result;
+   }
+
+   if(strstr(dpr_type,"PSF") != NULL) {
+      result = 1;
+      sinfo_free_propertylist(&plist);
+      return result;
+   }
+
+   if(strstr(dpr_type,"SKY") != NULL) {
+      result = 0;
+      sinfo_free_propertylist(&plist);
+      return result;
+   }
+
+
+   if(strstr(dpr_type,"OBJECT") != NULL) {
+      result = 1;
+      sinfo_free_propertylist(&plist);
+      return result;
+   }
+   /*
+     if(strstr(dpr_type,"PUPIL") != NULL) {
+     result = 1;
+     cpl_propertylist_delete(plist);
+     return result;
+     }
+   */
+
+   if (sinfo_propertylist_has(plist, KEY_NAME_LAMP_XE)) {
+      lamp_Xe=cpl_propertylist_get_bool(plist, KEY_NAME_LAMP_XE);
+      /* sinfo_msg("%s value is %d", KEY_NAME_LAMP_XE, lamp_Xe); */
+   } else {
+      sinfo_msg_warning("keyword %s does not exist",KEY_NAME_LAMP_XE);
+      sinfo_free_propertylist(&plist);
+      return -1;
+   }
+
+   if (sinfo_propertylist_has(plist, KEY_NAME_LAMP_KR)) {
+      lamp_Kr=cpl_propertylist_get_bool(plist, KEY_NAME_LAMP_KR);
+      /* sinfo_msg("%s value is %d", KEY_NAME_LAMP_KR, lamp_Kr); */
+   } else {
+      sinfo_msg_warning("keyword %s does not exist",KEY_NAME_LAMP_KR);
+      sinfo_free_propertylist(&plist);
+      return -1;
+   }
+
+   if (sinfo_propertylist_has(plist, KEY_NAME_LAMP_NE)) {
+      lamp_Ne=cpl_propertylist_get_bool(plist, KEY_NAME_LAMP_NE);
+      /* sinfo_msg("%s value is %d", KEY_NAME_LAMP_NE, lamp_Ne); */
+   } else {
+      sinfo_msg_warning("keyword %s does not exist",KEY_NAME_LAMP_NE);
+      sinfo_free_propertylist(&plist);
+      return -1;
+   }
+
+   if (sinfo_propertylist_has(plist, KEY_NAME_LAMP_AR)) {
+      lamp_Ar=cpl_propertylist_get_bool(plist, KEY_NAME_LAMP_AR);
+      /* sinfo_msg("%s value is %d", KEY_NAME_LAMP_AR, lamp_Ar); */
+   } else {
+      sinfo_msg_warning("keyword %s does not exist",KEY_NAME_LAMP_AR);
+      sinfo_free_propertylist(&plist);
+      return -1;
+   }
+
+   if (sinfo_propertylist_has(plist, KEY_NAME_LAMP_HALO)) {
+      lamp_Halo=cpl_propertylist_get_bool(plist, KEY_NAME_LAMP_HALO);
+      /* sinfo_msg("%s value is %d", KEY_NAME_LAMP_HALO, lamp_Halo); */
+   } else {
+      sinfo_msg_warning("keyword %s does not exist",KEY_NAME_LAMP_HALO);
+      sinfo_free_propertylist(&plist);
+      return -1;
+   }
+
+
+
+
+   if(lamp_Xe) {
+      result=1;
+   }
+
+   if(lamp_Kr) {
+      result=1;
+   }
+
+   if(lamp_Ne) {
+      result=1;
+   }
+
+   if(lamp_Ar) {
+      result=1;
+   }
+
+
+   if(lamp_Halo) {
+      result=1;
+   }
+
+  cleanup:
+   sinfo_free_propertylist(&plist);
+   return result;
+
+
+}
+
+
+
+int
+sinfo_pfits_add_qc(cpl_propertylist       *   plist,
+                   qc_log          *   qclog)
+{
+   char            key_name[80] ;
+   char            key_value[80] ;
+
+   int             i =0;
+
+   /* Test entries */
+   if (plist == NULL) return -1 ;
+
+   /* Parameter Name:    PIPEFILE */
+   /* we add ESO prefix to FITS keywords" */
+   for(i=0;i<qclog[0].n;i++) {
+      strcpy(key_name,"ESO ");
+      strcat(key_name,qclog[i].name);
+      if(strcmp(qclog[i].type,"string") == 0) {
+         snprintf(key_value,sizeof(key_value)-1,"%s",qclog[i].s_val);
+         cpl_propertylist_append_string(plist, key_name,key_value) ;
+         cpl_propertylist_set_comment(plist, key_name,qclog[i].comm) ;
+
+      } else if(strcmp(qclog[i].type,"bool") == 0) {
+         snprintf(key_value,sizeof(key_value),"%i",(int)qclog[i].n_val);
+         cpl_propertylist_append_bool(plist, key_name,(int)qclog[i].n_val) ;
+         cpl_propertylist_set_comment(plist, key_name,qclog[i].comm) ;
+      } else if(strcmp(qclog[i].type,"int") == 0) {
+         snprintf(key_value,sizeof(key_value),"%i",(int)qclog[i].n_val);
+         cpl_propertylist_append_int(plist, key_name,(int)qclog[i].n_val) ;
+         cpl_propertylist_set_comment(plist, key_name,qclog[i].comm) ;
+      } else if(strcmp(qclog[i].type,"float") == 0) {
+         snprintf(key_value,sizeof(key_value),"%f",(float)qclog[i].n_val);
+         cpl_propertylist_append_float(plist, key_name,(float)qclog[i].n_val) ;
+         cpl_propertylist_set_comment(plist, key_name,qclog[i].comm) ;
+      } else if(strcmp(qclog[i].type,"double") == 0) {
+         snprintf(key_value,sizeof(key_value),"%f",qclog[i].n_val);
+         cpl_propertylist_append_double(plist, key_name,qclog[i].n_val) ;
+         cpl_propertylist_set_comment(plist, key_name,qclog[i].comm) ;
+      }
+
+   }
+
+   return 0 ;
+}
+
+
+
diff --git a/sinfoni/sinfo_dfs.h b/sinfoni/sinfo_dfs.h
new file mode 100644
index 0000000..a9805d3
--- /dev/null
+++ b/sinfoni/sinfo_dfs.h
@@ -0,0 +1,52 @@
+/* $Id: sinfo_dfs.h,v 1.3 2010/02/17 09:23:43 amodigli Exp $
+ *
+ * This file is part of the SINFONI Pipeline
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This proram is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2010/02/17 09:23:43 $
+ * $Revision: 1.3 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifndef SINFO_DFS_H
+#define SINFO_DFS_H
+
+/*--------------------------------------------------------------------------
+                                 general Includes
+ --------------------------------------------------------------------------*/
+#include <config.h>
+#include <string.h>
+#include <cpl.h>
+#include "sinfo_pfits.h"
+/* #include "utilities.h" */   /* critical for other modules */
+/*------------------------------------------------------------------------
+                                   Defines
+ --------------------------------------------------------------------------*/
+#include "sinfo_globals.h"
+#include "sinfo_raw_types.h"
+#include "sinfo_ref_types.h"
+#include "sinfo_pro_types.h"
+#include "sinfo_key_names.h"
+/* ---------------------------------------------------------------------- 
+   functions
+---------------------------------------------------------------------- */
+#include "sinfo_functions.h"
+CPL_END_DECLS
+#endif
diff --git a/sinfoni/sinfo_distortion.c b/sinfoni/sinfo_distortion.c
new file mode 100644
index 0000000..9c39328
--- /dev/null
+++ b/sinfoni/sinfo_distortion.c
@@ -0,0 +1,1605 @@
+/* $Id: sinfo_distortion.c,v 1.37 2012/03/05 16:34:06 amodigli Exp $
+ *
+ * This file is part of the irplib package
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2012/03/05 16:34:06 $
+ * $Revision: 1.37 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <sinfo_cpl_size.h>
+
+/*----------------------------------------------------------------------------
+                                   Includes
+ ----------------------------------------------------------------------------*/
+
+#include <cpl.h>
+#include <sinfo_cpl_size.h>
+#include <math.h>
+
+
+#include "sinfo_distortion.h"
+#include "sinfo_functions.h"
+#include "sinfo_msg.h"
+#include "sinfo_error.h"
+#include "irplib_flat.h"
+#include "sinfo_utils_wrappers.h"
+//#include "sinfo_irplib_cpl_wrp.h"
+#include "sinfo_utilities.h"
+/*-----------------------------------------------------------------------------
+                                   Define
+ ----------------------------------------------------------------------------*/
+
+#define ARC_NBSAMPLES       20
+#define ARC_THRESHFACT      (1.0/3.0)
+#define ARC_MINGOODPIX      100
+#define ARC_MINARCLENFACT   1.19   /* 1.1-2 */
+#define ARC_MINNBARCS       32     /* 4-32 */
+#define ARC_RANGE_FACT      3.0
+#define ARC_WINDOWSIZE      10  /* 32 */
+
+#define TRESH_MEDIAN_MIN    0.0
+#define TRESH_SIGMA_MAX     200.0
+
+/**@{*/
+/*---------------------------------------------------------------------------*/
+/**
+ * @defgroup sinfo_distortion       Distortion correction functions
+ */
+/*---------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+                                Functions prototypes
+ ----------------------------------------------------------------------------*/
+static cpl_apertures *
+sinfo_distortion_detect_arcs_new(cpl_image* ,cpl_image   **,
+                                 int,int,double,int,int,int,int,double,int);
+
+static
+cpl_apertures * sinfo_distortion_detect_arcs(cpl_image *,
+        cpl_image **, int, int, int, int, int, int) ;
+static int
+sinfo_distortion_fill_badzones(cpl_image *, int, int, int, int, double) ;
+static int
+sinfo_distortion_threshold1d(cpl_image *, double, cpl_image *, double) ;
+static int
+sinfo_distortion_purge_arcs(cpl_image *, cpl_apertures **,
+                            cpl_image **, int, int, double) ;
+static cpl_bivector **
+sinfo_distortion_get_arc_positions(cpl_image *,
+                                   cpl_image *,
+                                   cpl_apertures *, int, double **) ;
+static double sinfo_distortion_fine_pos(cpl_image *, cpl_image *, int, int) ;
+static int sinfo_distortion_sub_hor_lowpass(cpl_image *, int) ;
+static cpl_image * sinfo_distortion_remove_ramp(const cpl_image *) ;
+static cpl_image *
+sinfo_distortion_smooth(cpl_image* inp,const int r,const int d);
+
+
+
+
+/*----------------------------------------------------------------------------
+                                Functions code
+ ----------------------------------------------------------------------------*/
+
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Perform running mean filter of a given radius along a given
+            direction
+  @param    im image to be filtered
+  @param    rad filter radius
+  @param    direction: 0 (X) or 1 (Y)
+  @return   smoothed image if succes, NULL else
+*/
+
+static cpl_image *
+sinfo_distortion_smooth(cpl_image* inp,const int r,const int d)
+{
+
+  int sx=0;
+  int sy=0;
+  int i=0;
+  int j=0;
+  int z=0;
+
+  float sum;
+  cpl_image* out=NULL;
+  float* pi=NULL;
+  float* po=NULL;
+  int min=0;
+
+  cknull(inp,"Null input image!");
+  check_nomsg(sx=cpl_image_get_size_x(inp));
+  check_nomsg(sy=cpl_image_get_size_y(inp));
+  check_nomsg(out=cpl_image_duplicate(inp));
+  check_nomsg(pi=cpl_image_get_data_float(inp));
+  check_nomsg(po=cpl_image_get_data_float(out));
+  min = r/2;
+  switch (d) {
+  case 0:
+    for(j=0;j<sy;j++) {
+      for(i=min;i<sx-min;i++) {
+    sum=0;
+    for(z=i-min;z<i+min+1;z++) {
+      sum+=pi[z+j*sx];
+    }
+        po[i+j*sx]=sum/r;
+      }
+    }
+    break;
+
+  case 1:
+    for(i=0;i<sx;i++) {
+      for(j=min;j<sy-min;j++) {
+    sum=0;
+    for(z=j-min;z<j+min+1;z++) {
+      sum+=pi[i+z*sx];
+    }
+        po[i+j*sx]=sum;
+      }
+    }
+    break;
+
+  default:
+    sinfo_msg_error("case not supported");
+    goto cleanup;
+
+  }
+  check_nomsg(cpl_image_delete(inp));
+  return out;
+ cleanup:
+  return NULL;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Restores signal considering pixels in a given range along a given
+            direction
+  @param    im image to be filtered
+  @param    rad filter radius
+  @param    d direction: 0 (X) or 1 (Y)
+  @param    k kappa value in kappa-sigma clip
+  @param    ks_method method used in kappa-sigma clip: 0 (average) 1 (median)
+  @param    n number iterations kappa-sigma clip
+  @return   smoothed image if succes, NULL else
+*/
+
+cpl_image *
+sinfo_distortion_image_restore(const cpl_image* inp,
+                               const int r,
+                               const int d,
+                               const double kappa,
+                               const int ks_method,
+                               const int n)
+{
+
+  int sx=0;
+  int sy=0;
+  int i=0;
+  int j=0;
+  int z=0;
+  int k=0;
+
+
+  cpl_image* out=NULL;
+  const float* pi=NULL;
+  float* po=NULL;
+  int min=0;
+  cpl_vector* vec=NULL;
+  double* pv=NULL;
+  double mean=0;
+  double median=0;
+
+  cknull(inp,"Null input image!");
+  check_nomsg(sx=cpl_image_get_size_x(inp));
+  check_nomsg(sy=cpl_image_get_size_y(inp));
+  check_nomsg(out=cpl_image_duplicate(inp));
+  check_nomsg(pi=cpl_image_get_data_float_const(inp));
+  check_nomsg(po=cpl_image_get_data_float(out));
+  min = r/2;
+  check_nomsg(vec=cpl_vector_new(r));
+  check_nomsg(pv=cpl_vector_get_data(vec));
+  switch (d) {
+  case 0:
+    for(j=0;j<sy;j++) {
+      for(i=min;i<sx-min;i++) {
+    k=0;
+    for(z=i-min;z<i+min+1;z++) {
+      pv[k]=(double)pi[z+j*sx];
+          k++;
+    }
+        cknull_nomsg(vec=sinfo_vector_clip(vec,kappa,n,ks_method));
+        check_nomsg(mean=cpl_vector_get_mean(vec));
+        check_nomsg(median=cpl_vector_get_mean(vec));
+        po[i+j*sx]+=(mean-median);
+      }
+    }
+    break;
+
+  case 1:
+    for(i=0;i<sx;i++) {
+      for(j=min;j<sy-min;j++) {
+        k=0;
+    for(z=j-min;z<j+min+1;z++) {
+      pv[k]=(double)pi[i+z*sx];
+          k++;
+    }
+        cknull_nomsg(vec=sinfo_vector_clip(vec,kappa,n,ks_method));
+        check_nomsg(mean=cpl_vector_get_mean(vec));
+        check_nomsg(median=cpl_vector_get_mean(vec));
+        po[i+j*sx]+=(mean-median);
+      }
+    }
+    break;
+
+  default:
+    sinfo_msg_error("case not supported");
+    goto cleanup;
+
+  }
+  check_nomsg(cpl_image_delete((cpl_image*)inp));
+  return out;
+ cleanup:
+  return NULL;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Estimate the distortion using vertical curved arcs
+  @param    org     the input image
+  @param    xmin
+  @param    ymin    Define the zone to take into account
+  @param    xmax
+  @param    ymax
+  @param    auto_ramp_sub   To automatically clean the image before detection
+  @param    arc_sat Saturation threshold for the arcs
+  @param    max_arc_width   Maximum arc width allowed in pixels
+  @param    kappa   Kappa for arc detection (0.33 = good default)
+  @param    degree  The degree of the fitted polynomial
+  @param    arcs    The found arcs
+  @return   The 2d polynomial describing the distortion or NULL in error case
+
+  The arcs are expected to be vertical.
+
+  If (Xi, yi) define positions on the curved arcs, and (xi, yi) the associated
+  positions on the straight arcs, the created polynomial is Xi = P(xi, yi).
+
+  This polynomial can be used as it is by the CPL warping function to correct
+  the image.
+ */
+/*---------------------------------------------------------------------------*/
+cpl_polynomial * sinfo_distortion_estimate_new(
+        const cpl_image *   org,
+        int                 xmin,
+        int                 ymin,
+        int                 xmax,
+        int                 ymax,
+        int                 auto_ramp_sub,
+        int                 arc_sat,
+        int                 max_arc_width,
+        double              kappa,
+        double              arcs_min_arclen_factor,
+        int                 arcs_window_size,
+        int                 smooth_rad,
+        int                 degree,
+        double              offset,
+        cpl_apertures   **  arcs)
+{
+    cpl_image       *   local_im ;
+    cpl_image       *   label_image ;
+    double              rightmost, leftmost ;
+    cpl_bivector    **  arcs_pos ;
+    double          *   parc_posx ;
+    double          *   parc_posy ;
+    double          *   lines_pos ;
+    cpl_bivector    *   grid ;
+    double          *   pgridx ;
+    double          *   pgridy ;
+    cpl_vector      *   values_to_fit ;
+    double          *   pvalues_to_fit ;
+    int                 min_arc_range ;
+    int                 n_calib ;
+    int                 n_arcs ;
+    cpl_polynomial  *   poly2d ;
+    int                 nx ;
+    int                 i, j ;
+
+    /* AMO added to use offset */
+    cpl_vector    *     lines_pos_tmp ;
+    cpl_bivector    *   grid_tmp ;
+    cpl_vector* grid_tot=0;
+    double* pgrid_tmp_x=NULL;
+    double* pgrid_tmp_y=NULL;
+    double* pgrid_tot=NULL;
+    double* plines_pos_tmp=NULL;
+    int n_lines=0;
+    int k=0;
+
+
+    /* Check entries */
+    if (org == NULL) return NULL ;
+    if (kappa < 0.0) return NULL ;
+
+    /* Initialise */
+    n_calib = ARC_NBSAMPLES ;
+    nx = cpl_image_get_size_x(org) ;
+
+    if (auto_ramp_sub) {
+        local_im = sinfo_distortion_remove_ramp(org) ;
+    } else {
+        /* Local copy of input image */
+        local_im = cpl_image_duplicate(org) ;
+    }
+    if (local_im == NULL) {
+        cpl_msg_error(cpl_func, "Cannot clean the image") ;
+        return NULL ;
+    }
+    if(smooth_rad > 1) {
+      local_im=sinfo_distortion_smooth(local_im,smooth_rad,1);
+      //cpl_image_save(local_im,"out_local_im.fits",CPL_BPP_IEEE_FLOAT,
+      //               NULL,CPL_IO_DEFAULT);
+      //local_im=sinfo_distortion_image_restore(local_im,smooth_rad,1,2,0,2);
+      //cpl_image_save(local_im,"out_local_im_post.fits",
+      //               CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT);
+
+    }
+    /* Detect the arcs in the input image */
+    cpl_msg_info(cpl_func, "Detect arcs") ;
+    if ((*arcs = sinfo_distortion_detect_arcs_new(local_im,
+                    &label_image,
+                    arc_sat, max_arc_width, kappa,
+                    xmin, ymin, xmax, ymax,
+                    arcs_min_arclen_factor,arcs_window_size)) == NULL) {
+        cpl_image_delete(local_im) ;
+        cpl_msg_error(cpl_func, "Cannot detect the arcs") ;
+        return NULL ;
+    }
+    n_arcs = cpl_apertures_get_size(*arcs) ;
+    cpl_msg_info(cpl_func, "%d detected arcs", n_arcs) ;
+
+    /* Check that the arcs are not concentrated in the same zone */
+    rightmost = leftmost = cpl_apertures_get_pos_x(*arcs, 1) ;
+    for (i=1 ; i<n_arcs ; i++) {
+        if (cpl_apertures_get_pos_x(*arcs, i+1) < leftmost)
+            leftmost = cpl_apertures_get_pos_x(*arcs, i+1) ;
+        if (cpl_apertures_get_pos_x(*arcs, i+1) > rightmost)
+            rightmost = cpl_apertures_get_pos_x(*arcs, i+1) ;
+    }
+    min_arc_range = (int)(nx / ARC_RANGE_FACT) ;
+    if ((int)(rightmost-leftmost) < min_arc_range) {
+        cpl_msg_error(cpl_func, "too narrow range (%g-%g)<%d",
+                rightmost, leftmost, min_arc_range) ;
+        cpl_apertures_delete(*arcs) ;
+        cpl_image_delete(local_im) ;
+        cpl_image_delete(label_image) ;
+        return NULL ;
+    }
+
+    /* Create a 2-D deformation grid with detected arcs */
+    cpl_msg_info(cpl_func, "Create deformation grid") ;
+    lines_pos = cpl_malloc(n_arcs * sizeof(double)) ;
+    if ((arcs_pos = sinfo_distortion_get_arc_positions(local_im,
+                    label_image, *arcs, n_calib, &lines_pos))==NULL){
+        cpl_msg_error(cpl_func, "cannot get arcs positions") ;
+        cpl_apertures_delete(*arcs) ;
+        cpl_image_delete(local_im) ;
+        cpl_free(lines_pos) ;
+        cpl_image_delete(label_image) ;
+        return NULL ;
+    }
+    cpl_image_delete(label_image) ;
+    cpl_image_delete(local_im) ;
+
+    /* Prepare the fitting */
+    lines_pos_tmp=cpl_vector_new(n_arcs);
+    plines_pos_tmp=cpl_vector_get_data(lines_pos_tmp);
+
+
+    sinfo_msg("Fit the 2d polynomial") ;
+    grid = cpl_bivector_new(n_arcs * n_calib) ;
+    pgridx = cpl_bivector_get_x_data(grid) ;
+    pgridy = cpl_bivector_get_y_data(grid) ;
+    values_to_fit = cpl_vector_new(n_arcs * n_calib) ;
+    pvalues_to_fit = cpl_vector_get_data(values_to_fit) ;
+
+    for (i=0 ; i<n_arcs ; i++) {
+        parc_posx = cpl_bivector_get_x_data(arcs_pos[i]) ;
+        parc_posy = cpl_bivector_get_y_data(arcs_pos[i]) ;
+        for (j=0 ; j<n_calib ; j++) {
+            plines_pos_tmp[i]=lines_pos[i] ;
+            pgridx[j+i*n_calib] = lines_pos[i] ;
+            pgridy[j+i*n_calib] = parc_posy[j] ;
+            pvalues_to_fit[j+i*n_calib] = parc_posx[j] ;
+        }
+    }
+    /* AMO new to use offset */
+    n_lines= n_arcs/32.0;
+    if(n_lines < 1) {
+      n_lines=1;
+    }
+    cpl_vector_sort(lines_pos_tmp,1);
+    plines_pos_tmp=cpl_vector_get_data(lines_pos_tmp);
+    grid_tmp=cpl_bivector_duplicate(grid);
+    grid_tot=cpl_vector_new(n_calib);
+    pgrid_tmp_x = cpl_bivector_get_x_data(grid_tmp) ;
+    pgrid_tmp_y = cpl_bivector_get_y_data(grid_tmp) ;
+    pgrid_tot = cpl_vector_get_data(grid_tot);
+    for(j=0;j<n_calib;j++) {
+      pgrid_tot[j]=0;
+      for(i=n_lines ;i<n_arcs;i=i+n_lines)
+    {
+      for(k=0;k<n_lines;k++) {
+        pgrid_tot[j] += (plines_pos_tmp[i+k]-
+                             plines_pos_tmp[k]);
+        /*
+            sinfo_msg("diff=%g",(plines_pos_tmp[i+k]-
+                 plines_pos_tmp[k]));
+        */
+      }
+    }
+      /*
+      sinfo_msg("j=%d pgrid_tot=%g",j,pgrid_tot[j]);
+      */
+    }
+
+    for(j=0;j<n_calib;j++) {
+      for (i=0 ; i<n_arcs ; i++) {
+     pgridx[j+i*n_calib]=pgridx[j+i*n_calib]*
+                             ((nx/32.0)*n_lines*(31*32/2))/pgrid_tot[j]-offset;
+     /*
+         sinfo_msg_error("AMo after corr grid[%d,%d]=%g",
+                          i,k,pgridx[k+i*n_calib]);
+     */
+     pgrid_tmp_x[j+i*n_calib]=pgrid_tmp_x[j+i*n_calib]*
+                                  ((nx/32.0)*n_lines*(31*32/2))/pgrid_tot[j]-
+                                  offset;
+
+      }
+    }
+    cpl_vector_delete(lines_pos_tmp);
+    cpl_bivector_delete(grid_tmp);
+    cpl_vector_delete(grid_tot);
+    /* end AMO: to use the offset */
+
+
+    for (i=0 ; i<n_arcs ; i++) cpl_bivector_delete(arcs_pos[i]) ;
+    cpl_free(arcs_pos) ;
+    cpl_free(lines_pos) ;
+
+    /* Apply the fitting */
+    if ((poly2d = sinfo_polynomial_fit_2d_create(grid, values_to_fit,
+                    degree, NULL))==NULL) {
+        cpl_msg_error(cpl_func, "cannot apply the 2d fit") ;
+        cpl_bivector_delete(grid) ;
+        cpl_vector_delete(values_to_fit) ;
+        cpl_apertures_delete(*arcs) ;
+        return NULL ;
+    }
+
+    /* Free and return */
+    cpl_bivector_delete(grid) ;
+    cpl_vector_delete(values_to_fit) ;
+    return poly2d ;
+}
+
+
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Detect the vertical arcs in an image
+  @param    im          the input image
+  @param    label_im    the output label image
+  @param    arc_sat     Saturation threshold for the arcs
+  @param    max_arc_width   Maximum arc width allowed
+  @param    kappa           For arcs detection (0.33 is a good default)
+  @param    xmin
+  @param    ymin        Define the zone to take into account
+  @param    xmax
+  @param    ymax
+  @return   The arcs or NULL in error case
+
+  The arcs are expected to be vertical.
+ */
+/*---------------------------------------------------------------------------*/
+static cpl_apertures * sinfo_distortion_detect_arcs_new(
+        cpl_image   *   im,
+        cpl_image   **  label_im,
+        int             arc_sat,
+        int             max_arc_width,
+        double          kappa,
+        int             xmin,
+        int             ymin,
+        int             xmax,
+        int             ymax,
+        double arcs_min_arclen_factor,
+        int arcs_window_size)
+{
+    cpl_image       *   filt_im ;
+    cpl_matrix      *   filter ;
+    cpl_image       *   collapsed ;
+    cpl_mask        *   bin_im ;
+    double              threshold, fillval, median_val, sigma ;
+    int                 min_arclen = 0 ;
+    cpl_apertures   *   det ;
+    cpl_size                 nobj ;
+    int                 ngoodpix ;
+    int                 ny ;
+
+    ny = cpl_image_get_size_y(im) ;
+    /* Default values for output parameters */
+    *label_im = NULL ;
+
+    /* Clear zones to be ignored (to avoid false detections) */
+    median_val = cpl_image_get_median_dev(im, &sigma) ;
+    fillval = median_val-sigma/2.0 ;
+    if (sinfo_distortion_fill_badzones(im, xmin, ymin, xmax, ymax,
+                fillval) == -1) {
+        cpl_msg_error(cpl_func, "cannot fill bad zones") ;
+        return NULL ;
+    }
+    /* Median vertical filter */
+    filter = cpl_matrix_new(3, 1) ;
+    cpl_matrix_fill(filter, 1.0) ;
+    /* filt_im = cpl_image_filter_median(im, filter) ; */
+    filt_im = cpl_image_duplicate(im) ;
+    cpl_matrix_delete(filter) ;
+
+    /* Subtract a low-pass */
+    /* AMO: suppressed as may remove arcs */
+    if (sinfo_distortion_sub_hor_lowpass(filt_im, arcs_window_size) == -1) {
+        cpl_image_delete(filt_im) ;
+        return NULL ;
+    }
+    //cpl_image_save(filt_im,"out_filt_im_lp.fits",CPL_BPP_IEEE_FLOAT,
+    //               NULL,CPL_IO_DEFAULT);
+
+    /* Get relevant stats for thresholding */
+    median_val = cpl_image_get_median_dev(filt_im, &sigma) ;
+
+    /* Correct median_val and sigma if necessary */
+    if (median_val < TRESH_MEDIAN_MIN) median_val = TRESH_MEDIAN_MIN ;
+    if (sigma > TRESH_SIGMA_MAX) sigma = TRESH_SIGMA_MAX ;
+
+    /* Set the threshold */
+    threshold = median_val + sigma * kappa ;
+
+    /* Collapse the image */
+    collapsed = cpl_image_collapse_median_create(filt_im, 0, 0, 0) ;
+
+    /* Threshold to keep only the arcs - use of the collapsed image */
+    if (sinfo_distortion_threshold1d(filt_im, median_val,
+                                     collapsed, 0.0)==-1) {
+        cpl_msg_error(cpl_func, "cannot threshold the filtered image") ;
+        cpl_image_delete(filt_im) ;
+        cpl_image_delete(collapsed) ;
+        return NULL ;
+    }
+    cpl_image_delete(collapsed) ;
+
+    /* Binarize the image */
+    bin_im = cpl_mask_threshold_image_create(filt_im, threshold,
+            SINFO_DBL_MAX);
+    cpl_image_delete(filt_im) ;
+    if (bin_im == NULL) {
+        cpl_msg_error(cpl_func, "cannot binarise the image") ;
+        return NULL ;
+    }
+
+    /* Test if there are enough good pixels */
+    ngoodpix = cpl_mask_count(bin_im) ;
+    if (ngoodpix < ARC_MINGOODPIX) {
+        cpl_msg_error(cpl_func, "Too few (%d) white pixels", ngoodpix) ;
+        cpl_mask_delete(bin_im) ;
+        return NULL ;
+    }
+
+    /* Apply a morphological closing to clean the isolated pixels */
+    filter = cpl_matrix_new(3, 3) ;
+    cpl_matrix_fill(filter, 1.0) ;
+    cpl_mask_closing(bin_im, filter) ;
+    cpl_matrix_delete(filter) ;
+
+    /* Labelize pixel map to a label image */
+    *label_im = cpl_image_labelise_mask_create(bin_im, &nobj) ;
+    cpl_mask_delete(bin_im) ;
+    //cpl_image_save(*label_im,"out_label_im.fits",CPL_BPP_IEEE_FLOAT,
+    //               NULL,CPL_IO_DEFAULT);
+
+    /* Compute statistics on objects */
+    if ((det = cpl_apertures_new_from_image(im, *label_im)) == NULL) {
+        cpl_msg_error(cpl_func, "Cannot compute arcs stats") ;
+        cpl_image_delete(*label_im) ;
+        *label_im = NULL ;
+        return NULL ;
+    }
+    /* Set min_arclen */
+    min_arclen = (int)(ny /arcs_min_arclen_factor) ;
+    //cpl_image_save(im,"out_im.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT);
+
+    /* Purge non-relevant arcs */
+    /* cpl_apertures_dump(det,stdout); */
+    if (sinfo_distortion_purge_arcs(im, &det, label_im, min_arclen,
+                max_arc_width, arc_sat) == -1) {
+        cpl_msg_error(cpl_func, "Cannot purge the arcs") ;
+        cpl_image_delete(*label_im) ;
+        *label_im = NULL ;
+        cpl_apertures_delete(det) ;
+        return NULL ;
+    }
+    /* cpl_apertures_dump(det,stdout); */
+    if (cpl_apertures_get_size(det) < ARC_MINNBARCS) {
+        cpl_msg_error(cpl_func, "Not enough valid arcs (%" 
+                      CPL_SIZE_FORMAT " < %d)",
+                cpl_apertures_get_size(det), ARC_MINNBARCS) ;
+        cpl_image_delete(*label_im) ;
+        *label_im = NULL ;
+        cpl_apertures_delete(det) ;
+        return NULL ;
+    }
+
+    /* Return  */
+    return det ;
+}
+
+
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Estimate the distortion using vertical curved arcs
+  @param    org     the input image
+  @param    xmin
+  @param    ymin    Define the zone to take into account
+  @param    xmax
+  @param    ymax
+  @param    auto_ramp_sub   To automatically clean the image before detection
+  @param    arc_sat Saturation threshold for the arcs
+  @param    max_arc_width   Maximum arc width allowed in pixels
+  @param    degree  The degree of the fitted polynomial
+  @param    offset  The degree of the fitted polynomial
+  @param    arcs    The found arcs
+  @return   The 2d polynomial describing the distortion or NULL in error case
+
+  The arcs are expected to be vertical.
+
+  If (Xi, yi) define positions on the curved arcs, and (xi, yi) the associated
+  positions on the straight arcs, the created polynomial is Xi = P(xi, yi).
+
+  This polynomial can be used as it is by the CPL warping function to correct
+  the image.
+ */
+/*---------------------------------------------------------------------------*/
+cpl_polynomial * sinfo_distortion_estimate(
+        const cpl_image *   org,
+        int                 xmin,
+        int                 ymin,
+        int                 xmax,
+        int                 ymax,
+        int                 auto_ramp_sub,
+        int                 arc_sat,
+        int                 max_arc_width,
+        int                 degree,
+        double              offset,
+        cpl_apertures   **  arcs)
+{
+    const char      *   fctid = "sinfo_distortion_estimate" ;
+    cpl_image       *   local_im ;
+    cpl_image       *   label_image ;
+    double              rightmost, leftmost ;
+    cpl_bivector    **  arcs_pos ;
+    double          *   parc_posx ;
+    double          *   parc_posy ;
+    double          *   lines_pos ;
+    cpl_bivector    *   grid ;
+    double          *   pgridx ;
+    double          *   pgridy ;
+    cpl_vector      *   values_to_fit ;
+    double          *   pvalues_to_fit ;
+    int                 min_arc_range ;
+    int                 n_calib ;
+    int                 n_arcs ;
+    cpl_polynomial  *   poly2d ;
+    int                 nx ;
+    int                 i, j ;
+
+    /* AMO added to use offset */
+    cpl_vector    *     lines_pos_tmp ;
+    cpl_bivector    *   grid_tmp ;
+    int n_lines=0;
+    int k=0;
+    cpl_vector* grid_tot=0;
+    double* pgrid_tmp_x=NULL;
+    double* pgrid_tmp_y=NULL;
+    double* pgrid_tot=NULL;
+    double* plines_pos_tmp=NULL;
+
+    /* Check entries */
+    if (org == NULL) return NULL ;
+
+    /* Initialise */
+    n_calib = ARC_NBSAMPLES ;
+    nx = cpl_image_get_size_x(org) ;
+
+    if (auto_ramp_sub) {
+        local_im = sinfo_distortion_remove_ramp(org) ;
+    } else {
+        /* Local copy of input image */
+        local_im = cpl_image_duplicate(org) ;
+    }
+    if (local_im == NULL) {
+        cpl_msg_error(fctid, "Cannot clean the image") ;
+        return NULL ;
+    }
+
+    /* Detect the arcs in the input image */
+    cpl_msg_info(fctid, "Detect arcs") ;
+    if ((*arcs = sinfo_distortion_detect_arcs(local_im,
+                    &label_image,
+                    arc_sat, max_arc_width,
+                    xmin, ymin, xmax, ymax)) == NULL) {
+        cpl_image_delete(local_im) ;
+        cpl_msg_error(fctid, "Cannot detect the arcs") ;
+        return NULL ;
+    }
+    n_arcs = cpl_apertures_get_size(*arcs) ;
+    cpl_msg_info(fctid, "%d detected arcs", n_arcs) ;
+
+    /* Check that the arcs are not concentrated in the same zone */
+    rightmost = leftmost = cpl_apertures_get_pos_x(*arcs, 1) ;
+    for (i=1 ; i<n_arcs ; i++) {
+        if (cpl_apertures_get_pos_x(*arcs, i+1) < leftmost)
+            leftmost = cpl_apertures_get_pos_x(*arcs, i+1) ;
+        if (cpl_apertures_get_pos_x(*arcs, i+1) > rightmost)
+            rightmost = cpl_apertures_get_pos_x(*arcs, i+1) ;
+    }
+    min_arc_range = (int)(nx / ARC_RANGE_FACT) ;
+    if ((int)(rightmost-leftmost) < min_arc_range) {
+        cpl_msg_error(fctid, "too narrow range (%g-%g)<%d",
+                rightmost, leftmost, min_arc_range) ;
+        cpl_apertures_delete(*arcs) ;
+        cpl_image_delete(local_im) ;
+        cpl_image_delete(label_image) ;
+        return NULL ;
+    }
+
+    /* Create a 2-D deformation grid with detected arcs */
+    cpl_msg_info(fctid, "Create deformation grid") ;
+    lines_pos = cpl_malloc(n_arcs * sizeof(double)) ;
+    if ((arcs_pos = sinfo_distortion_get_arc_positions(local_im,
+                    label_image, *arcs, n_calib, &lines_pos))==NULL){
+        cpl_msg_error(fctid, "cannot get arcs positions") ;
+        cpl_apertures_delete(*arcs) ;
+        cpl_image_delete(local_im) ;
+        cpl_free(lines_pos) ;
+        cpl_image_delete(label_image) ;
+        return NULL ;
+    }
+    cpl_image_delete(label_image) ;
+    cpl_image_delete(local_im) ;
+
+    /* Prepare the fitting */
+    lines_pos_tmp=cpl_vector_new(n_arcs);
+    plines_pos_tmp=cpl_vector_get_data(lines_pos_tmp);
+
+    cpl_msg_info(fctid, "Fit the 2d polynomial") ;
+    grid = cpl_bivector_new(n_arcs * n_calib) ;
+    pgridx = cpl_bivector_get_x_data(grid) ;
+    pgridy = cpl_bivector_get_y_data(grid) ;
+    values_to_fit = cpl_vector_new(n_arcs * n_calib) ;
+    pvalues_to_fit = cpl_vector_get_data(values_to_fit) ;
+    for (i=0 ; i<n_arcs ; i++) {
+        parc_posx = cpl_bivector_get_x_data(arcs_pos[i]) ;
+        parc_posy = cpl_bivector_get_y_data(arcs_pos[i]) ;
+        for (j=0 ; j<n_calib ; j++) {
+            plines_pos_tmp[i]=lines_pos[i] ;
+            pgridx[j+i*n_calib] = lines_pos[i] ;
+            pgridy[j+i*n_calib] = parc_posy[j] ;
+            pvalues_to_fit[j+i*n_calib] = parc_posx[j];
+
+/*
+      sinfo_msg("pgridx=%g pgridy=%g pvalues=%g",
+          pgridx[j+i*n_calib],pgridy[j+i*n_calib],pvalues_to_fit[j+i*n_calib]);
+*/
+        }
+    }
+
+
+    /* AMO new to use offset */
+    n_lines= n_arcs/32.0;
+    if(n_lines < 1) {
+      n_lines=1;
+    }
+    cpl_vector_sort(lines_pos_tmp,1);
+    plines_pos_tmp=cpl_vector_get_data(lines_pos_tmp);
+
+    grid_tmp=cpl_bivector_duplicate(grid);
+    grid_tot=cpl_vector_new(n_calib);
+    pgrid_tmp_x = cpl_bivector_get_x_data(grid_tmp) ;
+    pgrid_tmp_y = cpl_bivector_get_y_data(grid_tmp) ;
+    pgrid_tot = cpl_vector_get_data(grid_tot);
+    for(j=0;j<n_calib;j++) {
+      pgrid_tot[j]=0;
+      for(i=n_lines ;i<n_arcs;i=i+n_lines)
+    {
+      for(k=0;k<n_lines;k++) {
+        pgrid_tot[j] += (plines_pos_tmp[i+k]-
+                             plines_pos_tmp[k]);
+        /*
+            sinfo_msg("diff=%g",(plines_pos_tmp[i+k]-
+                 plines_pos_tmp[k]));
+        */
+      }
+    }
+      /*
+      sinfo_msg("j=%d pgrid_tot=%g",j,pgrid_tot[j]);
+      */
+    }
+
+    for(j=0;j<n_calib;j++) {
+      for (i=0 ; i<n_arcs ; i++) {
+     pgridx[j+i*n_calib]=pgridx[j+i*n_calib]*
+                             ((nx/32.0)*n_lines*(31*32/2))/pgrid_tot[j]-offset;
+     /*
+         sinfo_msg_error("AMo after corr grid[%d,%d]=%g",
+                          i,k,pgridx[k+i*n_calib]);
+     */
+     pgrid_tmp_x[j+i*n_calib]=pgrid_tmp_x[j+i*n_calib]*
+                                  ((nx/32.0)*n_lines*(31*32/2))/pgrid_tot[j]-
+                                   offset;
+
+      }
+    }
+    /* end AMO: to use the offset */
+
+
+    for (i=0 ; i<n_arcs ; i++) cpl_bivector_delete(arcs_pos[i]) ;
+    cpl_free(arcs_pos) ;
+    cpl_free(lines_pos) ;
+
+    /* Apply the fitting */
+    if ((poly2d = sinfo_polynomial_fit_2d_create(grid, values_to_fit,
+                    degree, NULL))==NULL) {
+        cpl_msg_error(fctid, "cannot apply the 2d fit") ;
+        cpl_bivector_delete(grid) ;
+        cpl_vector_delete(values_to_fit) ;
+        cpl_apertures_delete(*arcs) ;
+        return NULL ;
+    }
+
+    /* Free and return */
+    cpl_bivector_delete(grid) ;
+    cpl_vector_delete(values_to_fit) ;
+    return poly2d ;
+}
+
+/**@}*/
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Detect the vertical arcs in an image
+  @param    im          the input image
+  @param    label_im    the output label image
+  @param    arc_sat     Saturation threshold for the arcs
+  @param    max_arc_width   Maximum arc width allowed
+  @param    xmin
+  @param    ymin        Define the zone to take into account
+  @param    xmax
+  @param    ymax
+  @return   The arcs or NULL in error case
+
+  The arcs are expected to be vertical.
+ */
+/*---------------------------------------------------------------------------*/
+static cpl_apertures * sinfo_distortion_detect_arcs(
+        cpl_image   *   im,
+        cpl_image   **  label_im,
+        int             arc_sat,
+        int             max_arc_width,
+        int             xmin,
+        int             ymin,
+        int             xmax,
+        int             ymax)
+{
+    const char      *   fctid = "sinfo_distortion_detect_arcs" ;
+    cpl_image       *   filt_im ;
+    cpl_matrix      *   filter ;
+    cpl_image       *   collapsed ;
+    cpl_mask        *   bin_im ;
+    double              threshold, fillval, median_val, sigma ;
+    int                 min_arclen = 0 ;
+    cpl_apertures   *   det ;
+    cpl_size                 nobj ;
+    int                 ngoodpix ;
+    int                 ny ;
+
+    ny = cpl_image_get_size_y(im) ;
+
+    /* Default values for output parameters */
+    *label_im = NULL ;
+
+    /* Clear zones to be ignored (to avoid false detections) */
+    median_val = cpl_image_get_median_dev(im, &sigma) ;
+    fillval = median_val-sigma/2.0 ;
+    if (sinfo_distortion_fill_badzones(im, xmin, ymin, xmax, ymax,
+                fillval) == -1) {
+        cpl_msg_error(fctid, "cannot fill bad zones") ;
+        return NULL ;
+    }
+
+    /* Median vertical filter */
+    filter = cpl_matrix_new(3, 1) ;
+    cpl_matrix_fill(filter, 1.0) ;
+    /* filt_im = cpl_image_filter_median(im, filter) ; */
+    filt_im = cpl_image_duplicate(im) ;
+    cpl_matrix_delete(filter) ;
+
+    /* Subtract a low-pass */
+    if (sinfo_distortion_sub_hor_lowpass(filt_im, ARC_WINDOWSIZE) == -1) {
+        cpl_image_delete(filt_im) ;
+        return NULL ;
+    }
+
+    /* Get relevant stats for thresholding */
+    median_val = cpl_image_get_median_dev(filt_im, &sigma) ;
+
+    /* Correct median_val and sigma if necessary */
+    if (median_val < TRESH_MEDIAN_MIN) median_val = TRESH_MEDIAN_MIN ;
+    if (sigma > TRESH_SIGMA_MAX) sigma = TRESH_SIGMA_MAX ;
+
+    /* Set the threshold */
+    threshold = median_val + sigma * ARC_THRESHFACT ;
+
+    /* Collapse the image */
+    collapsed = cpl_image_collapse_median_create(filt_im, 0, 0, 0) ;
+
+    /* Threshold to keep only the arcs - use of the collapsed image */
+    if (sinfo_distortion_threshold1d(filt_im, median_val,
+                                     collapsed, 0.0)==-1) {
+        cpl_msg_error(fctid, "cannot threshold the filtered image") ;
+        cpl_image_delete(filt_im) ;
+        cpl_image_delete(collapsed) ;
+        return NULL ;
+    }
+    cpl_image_delete(collapsed) ;
+
+    /* Binarize the image */
+    bin_im = cpl_mask_threshold_image_create(filt_im, threshold,
+            SINFO_DBL_MAX);
+    cpl_image_delete(filt_im) ;
+    if (bin_im == NULL) {
+        cpl_msg_error(fctid, "cannot binarise the image") ;
+        return NULL ;
+    }
+
+    /* Test if there are enough good pixels */
+    ngoodpix = cpl_mask_count(bin_im) ;
+    if (ngoodpix < ARC_MINGOODPIX) {
+        cpl_msg_error(fctid, "Too few (%d) white pixels", ngoodpix) ;
+        cpl_mask_delete(bin_im) ;
+        return NULL ;
+    }
+
+    /* Apply a morphological closing to clean the isolated pixels */
+    filter = cpl_matrix_new(3, 3) ;
+    cpl_matrix_fill(filter, 1.0) ;
+    cpl_mask_closing(bin_im, filter) ;
+    cpl_matrix_delete(filter) ;
+
+    /* Labelize pixel map to a label image */
+    *label_im = cpl_image_labelise_mask_create(bin_im, &nobj) ;
+    cpl_mask_delete(bin_im) ;
+
+    /* Compute statistics on objects */
+    if ((det = cpl_apertures_new_from_image(im, *label_im)) == NULL) {
+        cpl_msg_error(fctid, "Cannot compute arcs stats") ;
+        cpl_image_delete(*label_im) ;
+        *label_im = NULL ;
+        return NULL ;
+    }
+
+    /* Set min_arclen */
+    min_arclen = (int)(ny / ARC_MINARCLENFACT) ;
+
+    /* Purge non-relevant arcs */
+    if (sinfo_distortion_purge_arcs(im, &det, label_im, min_arclen,
+                max_arc_width, arc_sat) == -1) {
+        cpl_msg_error(fctid, "Cannot purge the arcs") ;
+        cpl_image_delete(*label_im) ;
+        *label_im = NULL ;
+        cpl_apertures_delete(det) ;
+        return NULL ;
+    }
+    if (cpl_apertures_get_size(det) < ARC_MINNBARCS) {
+        cpl_msg_error(fctid, "Not enough valid arcs (%" 
+                      CPL_SIZE_FORMAT " < %d)",
+                cpl_apertures_get_size(det), ARC_MINNBARCS) ;
+        cpl_image_delete(*label_im) ;
+        *label_im = NULL ;
+        cpl_apertures_delete(det) ;
+        return NULL ;
+    }
+
+    /* Return  */
+    return det ;
+}
+
+static int sinfo_distortion_fill_badzones(
+        cpl_image   *   im,
+        int             xmin,
+        int             ymin,
+        int             xmax,
+        int             ymax,
+        double          fillval)
+{
+    float       *   pfi ;
+    int             nx, ny ;
+    int             i, j ;
+
+    /* Check entries */
+    if (im == NULL) return -1 ;
+    if (cpl_image_get_type(im) != CPL_TYPE_FLOAT) return -1 ;
+
+    /* Get the data */
+    pfi = cpl_image_get_data_float(im) ;
+    nx = cpl_image_get_size_x(im) ;
+    ny = cpl_image_get_size_y(im) ;
+
+    /* Fill the zone */
+    for (i=0 ; i<nx ; i++) {
+        for (j=0 ; j<ny ; j++) {
+            if ((i<xmin-1) || (i>xmax-1) || (j<ymin-1) || (j>ymax-1)) {
+                pfi[i+j*nx] = (float)fillval ;
+            }
+        }
+    }
+    return 0 ;
+}
+
+static int sinfo_distortion_threshold1d(
+        cpl_image   *   im,
+        double          threshold,
+        cpl_image   *   im1d,
+        double          newval)
+{
+    float       *   pim ;
+    float       *   pim1d ;
+    int             nx, ny ;
+    int             i, j ;
+
+    /* Check entries */
+    if (im == NULL) return -1 ;
+    if (im1d == NULL) return -1 ;
+    if (cpl_image_get_type(im) != CPL_TYPE_FLOAT) return -1 ;
+    if (cpl_image_get_type(im1d) != CPL_TYPE_FLOAT) return -1 ;
+
+    /* Get access to the im / im1d data */
+    pim = cpl_image_get_data_float(im) ;
+    pim1d = cpl_image_get_data_float(im1d) ;
+    nx = cpl_image_get_size_x(im) ;
+    ny = cpl_image_get_size_y(im) ;
+
+    /* Apply the thresholding */
+    for (i=0 ; i<nx ; i++)
+        if (pim1d[i] < threshold) {
+            for (j=0 ; j<ny ; j++) pim[i+j*nx] = (float)newval ;
+        }
+
+    /* Return */
+    return 0 ;
+}
+
+static int sinfo_distortion_sub_hor_lowpass(
+        cpl_image   *   im,
+        int             filt_size)
+{
+    cpl_vector  *   linehi ;
+    cpl_vector  *   linelo ;
+    cpl_vector  *   avglinehi ;
+    cpl_vector  *   avglinelo ;
+    double      *   pavglinehi ;
+    float       *   pim ;
+    int             lopos, hipos, nx, ny ;
+    int             i, j ;
+
+    /* Test entries */
+    if (im == NULL) return -1 ;
+    if (filt_size <= 0) return -1 ;
+
+    /* Initialise */
+    nx = cpl_image_get_size_x(im) ;
+    ny = cpl_image_get_size_y(im) ;
+    lopos = (int)(ny/4) ;
+    hipos = (int)(3*ny/4) ;
+
+    /* Get the vectors out of the image */
+    if ((linehi = cpl_vector_new_from_image_row(im, hipos)) == NULL) {
+        return -1 ;
+    }
+    if ((linelo = cpl_vector_new_from_image_row(im, lopos)) == NULL) {
+        cpl_vector_delete(linehi) ;
+        return -1 ;
+    }
+
+    /* Filter the vectors */
+    if ((avglinehi = cpl_vector_filter_median_create(linehi,
+                    filt_size)) == NULL) {
+        cpl_vector_delete(linehi) ;
+        cpl_vector_delete(linelo) ;
+        return -1 ;
+    }
+    cpl_vector_delete(linehi) ;
+
+    if ((avglinelo = cpl_vector_filter_median_create(linelo,
+                    filt_size)) == NULL) {
+        cpl_vector_delete(linelo) ;
+        cpl_vector_delete(avglinehi) ;
+        return -1 ;
+    }
+    cpl_vector_delete(linelo) ;
+
+    /* Average the filtered vectors to get the low freq signal */
+    cpl_vector_add(avglinehi, avglinelo) ;
+    cpl_vector_delete(avglinelo) ;
+    cpl_vector_divide_scalar(avglinehi, 2.0) ;
+
+    /* Subtract the low frequency signal */
+    pavglinehi = cpl_vector_get_data(avglinehi) ;
+    pim = cpl_image_get_data_float(im) ;
+    for (i=0 ; i<nx ; i++) {
+        for (j=0 ; j<ny ; j++) {
+            pim[i+j*nx] -= pavglinehi[i] ;
+        }
+    }
+    cpl_vector_delete(avglinehi) ;
+
+    return 0 ;
+}
+
+
+
+
+
+
+
+
+static int sinfo_distortion_purge_arcs(
+        cpl_image       *   im,
+        cpl_apertures   **  arcs,
+        cpl_image       **  lab_im,
+        int                 min_arclen,
+        int                 max_arcwidth,
+        double              arc_sat)
+{
+    const char  *   fctid = "sinfo_distortion_purge_arcs" ;
+    int             nb_arcs ;
+    int         *   selection ;
+    int             arclen, arcwidth, edge ;
+    double          mean ;
+    int         *   plabim ;
+    cpl_mask    *   bin_im ;
+    int             nx, ny ;
+    int             i, j ;
+
+    /* Check entries */
+    if (arcs == NULL) return -1 ;
+    if (*arcs == NULL) return -1 ;
+    if (*lab_im == NULL) return -1 ;
+
+    /* Get number of arcs */
+    nb_arcs = cpl_apertures_get_size(*arcs) ;
+    nx = cpl_image_get_size_x(*lab_im) ;
+    ny = cpl_image_get_size_y(*lab_im) ;
+
+    /* Allocate selection array */
+    selection = cpl_malloc(nb_arcs * sizeof(int)) ;
+    /* Loop on the different arcs candidates */
+    /* sinfo_msg("min_arclen=%d max_arcwidth=%d",min_arclen,max_arcwidth); */
+    for (i=0 ; i<nb_arcs ; i++) {
+        arclen = cpl_apertures_get_top(*arcs, i+1) -
+            cpl_apertures_get_bottom(*arcs, i+1) + 1 ;
+        arcwidth = cpl_apertures_get_right(*arcs, i+1) -
+            cpl_apertures_get_left(*arcs, i+1) + 1 ;
+        edge = cpl_apertures_get_left_y(*arcs, i+1) ;
+        mean = cpl_apertures_get_mean(*arcs, i+1) ;
+
+        /* Test if the current object is a valid arc */
+
+        if (
+            (arclen>min_arclen) &&
+        (arcwidth<max_arcwidth) &&
+            (edge>0) &&
+            (mean < arc_sat)) {
+      /*
+        sinfo_msg_warning("Take Pos=%5.4d len=%d width=%d edge=%d mean=%f ",
+    (cpl_apertures_get_right(*arcs, i+1)+cpl_apertures_get_left(*arcs, i+1))/2,
+     arclen,arcwidth,edge,mean);
+      */
+            selection[i] = 1 ;
+        } else {
+      /*
+    sinfo_msg_warning("Rej Pos=%5.4d len=%d width=%d edge=%d mean=%f i=%d",
+         (cpl_apertures_get_right(*arcs, i+1)+
+          cpl_apertures_get_left(*arcs, i+1))/2,arclen,arcwidth,edge,mean,i);
+      */
+            selection[i] = 0 ;
+        }
+    }
+
+    /* Update the labelised image by erasing non valid arcs */
+    for (i=0 ; i<nb_arcs ; i++) {
+        if (selection[i] == 0) {
+            plabim = cpl_image_get_data_int(*lab_im) ;
+            for (j=0 ; j<nx*ny ; j++) {
+                if (plabim[j] == i+1) plabim[j] = 0 ;
+            }
+        }
+    }
+    cpl_free(selection) ;
+
+    /* Reset the labels to have consecutive ones */
+    bin_im = cpl_mask_threshold_image_create(*lab_im, 0.5, SINFO_DBL_MAX) ;
+    cpl_image_delete(*lab_im) ;
+    *lab_im = cpl_image_labelise_mask_create(bin_im, NULL) ;
+    cpl_mask_delete(bin_im) ;
+
+    /* Purge the bad arcs */
+    cpl_apertures_delete(*arcs) ;
+    *arcs = cpl_apertures_new_from_image(im, *lab_im) ;
+
+    /* Check if there are some valid arcs */
+    if (cpl_apertures_get_size(*arcs) <= 0) {
+        cpl_msg_error(fctid, "No valid arc found") ;
+        return -1 ;
+    }
+    /* Return  */
+    return 0 ;
+}
+
+static cpl_bivector **
+sinfo_distortion_get_arc_positions(
+        cpl_image       *   in,
+        cpl_image       *   label_im,
+        cpl_apertures   *   det,
+        int                 nb_samples,
+        double          **  lines_pos)
+{
+    const char      *   fctid = "sinfo_distortion_get_arc_positions" ;
+    int                 n_arcs ;
+    cpl_image       *   filt_img ;
+    cpl_matrix      *   kernel ;
+    cpl_bivector    **  pos ;
+    double          *   biv_x ;
+    double          *   biv_y ;
+    double              x_finepos ;
+    int             *   plabel_im ;
+    int             *   arcs_samples_y ;
+    int             *   computed ;
+    double              arclen ;
+    int                 use_this_arc ;
+    int                 obj ;
+    int                 nx, ny ;
+    int                 i, j, k ;
+#if defined CPL_VERSION_CODE && CPL_VERSION_CODE >= CPL_VERSION(4, 8, 0)
+    cpl_mask*          mask=NULL;
+#endif
+
+    /* Check entries */
+
+    /* Initialise */
+    n_arcs = cpl_apertures_get_size(det) ;
+    nx = cpl_image_get_size_x(label_im) ;
+    ny = cpl_image_get_size_y(label_im) ;
+
+    /* Allocate positions (pos. of n_arcs*nb_samples pts on the arcs) */
+    pos = cpl_calloc(n_arcs, sizeof(cpl_bivector*)) ;
+    for (i=0 ; i<n_arcs ; i++) pos[i] = cpl_bivector_new(nb_samples) ;
+
+    /* Median filter on input image */
+    kernel = cpl_matrix_new(3, 3) ;
+    cpl_matrix_fill(kernel, 1.0) ;
+#if defined CPL_VERSION_CODE && CPL_VERSION_CODE >= CPL_VERSION(4, 8, 0)
+    filt_img=cpl_image_duplicate(in);
+    mask=cpl_mask_new(3,3);
+    cpl_mask_not(mask);
+    cpl_image_filter_mask(filt_img,in,mask,CPL_FILTER_MEDIAN,CPL_BORDER_FILTER);
+    cpl_mask_delete(mask);
+#else
+    filt_img = cpl_image_filter_median(in, kernel) ;
+#endif
+    cpl_matrix_delete(kernel) ;
+
+    /* Measured Arcs coordinates along curvature */
+    arcs_samples_y = cpl_malloc(n_arcs * nb_samples * sizeof(int)) ;
+    computed = cpl_calloc(n_arcs*nb_samples, sizeof(int)) ;
+
+    /* Find out the Y coordinates along the arcs  */
+    for (j=0 ; j<n_arcs ; j++) {
+        arclen = cpl_apertures_get_top(det,j+1) -
+            cpl_apertures_get_bottom(det,j+1) + 1 ;
+        for (i=0 ; i<nb_samples ; i++) {
+            arcs_samples_y[i+j*nb_samples] =
+                (int)(cpl_apertures_get_bottom(det, j+1) +
+                      (arclen * (i + 0.5)) / (double)nb_samples) ;
+        }
+    }
+
+    /* Find out the X coord. at nb_samples Y positions on all arcs */
+    plabel_im = cpl_image_get_data_int(label_im) ;
+    for (i=0 ; i<nx ; i++) {
+        for (j=0 ; j<ny ; j++) {
+            /* use_this_arc is set to 1 if we are on the arc at a y */
+            /* coordinate where the x coord should be found */
+            obj = plabel_im[i + j * nx] ;
+            /* Handle background */
+            if (obj==0) continue ;
+            /* Decrease by one to index the array from 0 */
+            else obj-- ;
+
+            use_this_arc = 0 ;
+            for (k=0 ; k<nb_samples ; k++) {
+                if (arcs_samples_y[k+obj*nb_samples] == j) {
+                    use_this_arc = 1 ;
+                    break ;
+                }
+            }
+            if ((use_this_arc)  && (computed[k+obj*nb_samples] == 0)) {
+                /* Find x coordinate of obj at the Y coord. */
+                if ((x_finepos = sinfo_distortion_fine_pos(filt_img,
+                                label_im, i, j)) < 0.0) {
+                    cpl_msg_error(fctid, "cannot find fine arc position") ;
+                    cpl_image_delete(filt_img) ;
+                    cpl_free(arcs_samples_y);
+                    cpl_free(computed) ;
+                    for (i=0 ; i<n_arcs ; i++) cpl_bivector_delete(pos[i]);
+                    cpl_free(pos) ;
+                    return NULL ;
+                } else {
+                    biv_x = cpl_bivector_get_x_data(pos[obj]) ;
+                    biv_y = cpl_bivector_get_y_data(pos[obj]) ;
+                    biv_x[k] = x_finepos ;
+                    biv_y[k] = j ;
+                    (*lines_pos)[obj] = cpl_apertures_get_centroid_x(det,obj+1);
+                    computed[k+obj*nb_samples] = 1 ;
+                }
+            }
+        }
+    }
+
+    /* Free and return */
+    cpl_image_delete(filt_img) ;
+    cpl_free(arcs_samples_y) ;
+    cpl_free(computed) ;
+    return pos ;
+}
+
+static double
+sinfo_distortion_fine_pos(
+        cpl_image   *   im,
+        cpl_image   *   label_im,
+        int             x,
+        int             y)
+{
+    float   *   pim ;
+    int     *   plabel_im ;
+    int         objnum ;
+    int         curr_obj ;
+    int         start_pos ;
+    double      grav_c ;
+    double      sum ;
+    double      max ;
+    double      val ;
+    int         maxpos ;
+    int         im_extrem ;
+    double      arc_pos ;
+    int         nx ;
+
+    /* Initialize */
+    nx = cpl_image_get_size_x(im) ;
+    grav_c = 0.0 ;
+    sum    = 0.0 ;
+    start_pos = x ;
+    maxpos = start_pos ;
+    pim = cpl_image_get_data_float(im) ;
+    max    = (double)pim[start_pos + y * nx] ;
+    plabel_im = cpl_image_get_data_int(label_im) ;
+    objnum = plabel_im[start_pos + y * nx] ;
+    im_extrem = nx ;
+
+    /* While we stay in the same object... */
+    do {
+        val = (double)pim[start_pos + y * nx] ;
+        if (start_pos == 0) grav_c = 0.0 ;
+        else grav_c += start_pos * val ;
+        sum += val ;
+        if (val > max) {
+            max = val ;
+            maxpos = start_pos ;
+        }
+
+        /* Next point */
+        start_pos++ ;
+
+        curr_obj = plabel_im[start_pos + y * nx] ;
+    } while (curr_obj == objnum) ;
+
+    /* Returned position is the gravity center or the max in bad cases */
+    if ((fabs(grav_c) < 1.0e-40) || (fabs(sum) < 1.0e-40)) {
+        arc_pos = maxpos ;
+    } else {
+        arc_pos = grav_c / sum ;
+        if (fabs(arc_pos) >= start_pos) arc_pos = maxpos ;
+    }
+
+    /* Return */
+    return arc_pos ;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Detect and remove a dark ramp in an image
+  @param    in  input image
+  @return   a newly allocated clean image
+ */
+/*---------------------------------------------------------------------------*/
+#define IS_NB_TESTPOINTS    8
+#define IS_MIN_SLOPE        0.01
+#define IS_MAX_SLOPE_DIF    0.075
+#define IS_MAX_FIT_EDGE_DIF 0.05
+#define IS_MIN_RAMP         10.0
+#define IS_MAX_MNERR        13.0
+#define IS_MAX_MNERR_DIF    8.0
+#define IS_MAX_INTER_DIF    20.0
+#define IS_SKIPZONE         2.5
+#define SQR(x) ((x)*(x))
+static cpl_image * sinfo_distortion_remove_ramp(const cpl_image * in)
+{
+    const char      *   fctid = "sinfo_distortion_remove_ramp" ;
+    int                 ramp_present ;
+    int                 nx, ny ;
+    int                 y, yhi, ylo;
+    cpl_vector      *   tmp_vector ;
+    cpl_bivector    *   testpointlo ;
+    double          *   testpointlo_x ;
+    double          *   testpointlo_y ;
+    cpl_bivector    *   testpointhi ;
+    double          *   testpointhi_x ;
+    double          *   testpointhi_y ;
+    int                 spacing;
+    double              rampdif, fitslope;
+    double          *   pol_coefhi,
+                    *   pol_coeflo ;
+    cpl_vector      *   median ;
+    double          *   median_data ;
+    double              medianerrlo, medianerrhi;
+    double              slope ;
+    cpl_image       *   out ;
+    float           *   pout ;
+    float               val ;
+    int                 i, j ;
+
+    /* Initialise */
+    nx = cpl_image_get_size_x(in) ;
+    ny = cpl_image_get_size_y(in) ;
+
+    /* Check entries */
+    if (in==NULL) return NULL ;
+
+    if (ny<IS_SKIPZONE*IS_NB_TESTPOINTS){
+        cpl_msg_error(fctid, "image has %d lines, min=%d ",
+                ny, (int)(IS_SKIPZONE*IS_NB_TESTPOINTS*2));
+        return NULL ;
+    }
+
+    slope=0.0 ;
+    spacing= ny / (IS_SKIPZONE*IS_NB_TESTPOINTS) ;
+    yhi = (int)(ny/2) ;
+    ylo = yhi - 1 ;
+    /* Fill the vectors */
+    testpointhi = cpl_bivector_new(IS_NB_TESTPOINTS) ;
+    testpointhi_x = cpl_bivector_get_x_data(testpointhi) ;
+    testpointhi_y = cpl_bivector_get_y_data(testpointhi) ;
+    testpointlo = cpl_bivector_new(IS_NB_TESTPOINTS) ;
+    testpointlo_x = cpl_bivector_get_x_data(testpointlo) ;
+    testpointlo_y = cpl_bivector_get_y_data(testpointlo) ;
+    for (i=0 ; i<IS_NB_TESTPOINTS ; i++) {
+        y = yhi + i * spacing;
+        tmp_vector = cpl_vector_new_from_image_row(in, y+1) ;
+        testpointhi_x[i] = y - ny / 2;
+        testpointhi_y[i] = cpl_vector_get_median_const(tmp_vector) ;
+        cpl_vector_delete(tmp_vector) ;
+        y = ylo - i * spacing;
+        tmp_vector = cpl_vector_new_from_image_row(in, y+1) ;
+        testpointlo_x[IS_NB_TESTPOINTS-i-1] = y ;
+        testpointlo_y[IS_NB_TESTPOINTS-i-1]=
+	  cpl_vector_get_median_const(tmp_vector);
+        cpl_vector_delete(tmp_vector) ;
+    }
+
+    /* Apply the fit */
+    pol_coefhi = irplib_flat_fit_slope_robust(testpointhi_x,
+            testpointhi_y, IS_NB_TESTPOINTS) ;
+    pol_coeflo = irplib_flat_fit_slope_robust(testpointlo_x,
+            testpointlo_y, IS_NB_TESTPOINTS) ;
+
+    /* Compute the errors */
+    median = cpl_vector_new(IS_NB_TESTPOINTS) ;
+    median_data = cpl_vector_get_data(median) ;
+    for (i=0 ; i<IS_NB_TESTPOINTS ; i++) {
+        median_data[i]=SQR(testpointhi_y[i]
+                - pol_coefhi[0] - pol_coefhi[1] * testpointhi_x[i]);
+    }
+    medianerrhi = cpl_vector_get_median_const(median) ;
+    for (i=0; i<IS_NB_TESTPOINTS; i++) {
+        median_data[i]=SQR(testpointlo_y[i]
+                - pol_coeflo[0] - pol_coeflo[1] * testpointlo_x[i]);
+    }
+    medianerrlo = cpl_vector_get_median_const(median) ;
+    cpl_vector_delete(median) ;
+    rampdif = testpointlo_y[IS_NB_TESTPOINTS-1] - testpointhi_y[0];
+    slope = rampdif / (ny/2.0) ;
+    fitslope = (pol_coefhi[1] + pol_coeflo[1]) / 2.0 ;
+
+    cpl_bivector_delete(testpointlo);
+    cpl_bivector_delete(testpointhi);
+
+    /* Decide if there is a ramp or not  */
+    if (fabs(rampdif)<IS_MIN_RAMP ||
+            fabs(pol_coefhi[1]) < IS_MIN_SLOPE ||
+            fabs(pol_coeflo[1]) < IS_MIN_SLOPE ||
+            pol_coefhi[1]/pol_coeflo[1]<0.5 ||
+            pol_coefhi[1]/pol_coeflo[1]>2.0 ||
+            fabs(pol_coefhi[1]-pol_coeflo[1])>IS_MAX_SLOPE_DIF ||
+            fabs(pol_coefhi[0]-pol_coeflo[0]) > IS_MAX_INTER_DIF ||
+            medianerrlo> IS_MAX_MNERR ||
+            medianerrhi> IS_MAX_MNERR ||
+            fabs(medianerrlo-medianerrhi) >IS_MAX_MNERR_DIF ||
+            fabs(slope-fitslope) > IS_MAX_FIT_EDGE_DIF ||
+            slope/fitslope<0.5 ||
+            slope/fitslope>2.0) ramp_present = 0 ;
+    else ramp_present = 1 ;
+
+    cpl_free(pol_coeflo) ;
+    cpl_free(pol_coefhi) ;
+
+    /* Correct the ramp if it is there */
+    out = cpl_image_duplicate(in) ;
+    pout = cpl_image_get_data_float(out) ;
+    if (ramp_present == 1) {
+        for (j=0 ; j<ny/2 ; j++) {
+            val = slope * (j-ny/2) ;
+            for (i=0 ; i<nx ; i++)
+                pout[i+j*nx] -= val ;
+        }
+        for (j=ny/2 ; j<ny ; j++) {
+            val = slope * (j-ny) ;
+            for (i=0 ; i<nx ; i++)
+                pout[i+j*nx] -= val ;
+        }
+
+    }
+
+    return out ;
+}
+
+/**@}*/
diff --git a/sinfoni/sinfo_distortion.h b/sinfoni/sinfo_distortion.h
new file mode 100644
index 0000000..e169fe6
--- /dev/null
+++ b/sinfoni/sinfo_distortion.h
@@ -0,0 +1,75 @@
+/* $Id: sinfo_distortion.h,v 1.7 2007/06/06 07:10:45 amodigli Exp $
+ *
+ * This file is part of the irplib package
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2007/06/06 07:10:45 $
+ * $Revision: 1.7 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifndef SINFO_DISTORTION_H
+#define SINFO_DISTORTION_H
+
+/*-----------------------------------------------------------------------------
+                                   Includes
+-----------------------------------------------------------------------------*/
+#include <cpl.h>
+/*-----------------------------------------------------------------------------
+                                       Prototypes
+-----------------------------------------------------------------------------*/
+cpl_polynomial * 
+sinfo_distortion_estimate(const cpl_image *, 
+                          int, 
+                          int, 
+                          int, 
+                          int, 
+                          int, 
+                          int, 
+                          int, 
+                          int, 
+                          double, 
+                          cpl_apertures **) ;
+
+cpl_polynomial * sinfo_distortion_estimate_new(
+        const cpl_image *   org,
+        int                 xmin,
+        int                 ymin,
+        int                 xmax,
+        int                 ymax,
+        int                 auto_ramp_sub,
+        int                 arc_sat,
+        int                 max_arc_width,
+        double              kappa,
+        double              arcs_min_arclen_factor,
+        int                 arcs_window_size,
+        int                 smooth_rad,
+        int                 degree,
+        double              offset,
+        cpl_apertures   **  arcs);
+
+cpl_image *
+sinfo_distortion_image_restore(const cpl_image* inp,
+                               const int r,
+                               const int d,
+                               const double kappa,
+                               const int ks_method,
+                               const int n);
+#endif
diff --git a/sinfoni/sinfo_distortion_config.c b/sinfoni/sinfo_distortion_config.c
new file mode 100644
index 0000000..6e294f4
--- /dev/null
+++ b/sinfoni/sinfo_distortion_config.c
@@ -0,0 +1,542 @@
+/* $Id: sinfo_distortion_config.c,v 1.6 2012/03/02 08:42:20 amodigli Exp $
+ *
+ * This file is part of the CPL (Common Pipeline Library)
+ * Copyright (C) 2002 European Southern Observatory
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*
+ * $Author: amodigli $
+ * $Date: 2012/03/02 08:42:20 $
+ * $Revision: 1.6 $
+ * $Name: sinfo-2_3_2 $
+ */
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+ /****************************************************************
+  *   Wavecal Frames Data Reduction Parameter Initialization        *
+  ****************************************************************/
+
+#include "sinfo_distortion_config.h"
+#include "sinfo_globals.h"
+/**@{*/
+/*---------------------------------------------------------------------------*/
+/**
+ * @addtogroup sinfo_distortion       Distortion correction functions
+ */
+/*---------------------------------------------------------------------------*/
+
+ void
+ sinfo_distortion_config_add(cpl_parameterlist *list)
+{
+
+  cpl_parameter *p;
+
+  if (!list) {
+    return;
+  }
+
+  /* Output file name */
+/* output name of resulting fits wavelength map */
+
+
+/* Find Lines */
+/* indicates if the dispersion relation is already determined or not */
+  p = cpl_parameter_new_value("sinfoni.distortion.calib_indicator",
+                  CPL_TYPE_BOOL,
+                              "Calib Indicator: "
+                              "FALSE: if the dispersion relation is already "
+                              "known, the routine can jump to the waveMap "
+                              "section "
+                              "TRUE: if the dispersion relation "
+                              "must first be determined",
+                              "sinfoni.distortion",
+                              TRUE);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"dist-calib_indicator");
+  cpl_parameterlist_append(list, p);
+
+
+/* minimal difference of mean and sinfo_median column intensity */
+  p = cpl_parameter_new_value("sinfoni.distortion.min_diff_mean_med_col_int",
+                  CPL_TYPE_DOUBLE,
+                              "Minimum Of Difference: "
+                              "minimum difference of mean and median column "
+                              "intensity to carry out the cross correlation",
+                              "sinfoni.distortion",
+                              10.);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
+                          "dist-min_diff_mean_med_col_int");
+  cpl_parameterlist_append(list, p);
+
+/* half width of a box within which the line must sit */
+  p = cpl_parameter_new_value("sinfoni.distortion.half_width",
+                  CPL_TYPE_INT,
+                              "Half Width: "
+                              "half width of a box within which the line "
+                              "must be placed",
+                              "sinfoni.distortion",
+                              7);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"dist-hw");
+  cpl_parameterlist_append(list, p);
+
+/* sigma of Gaussian of artificial model spectra */
+  p = cpl_parameter_new_value("sinfoni.distortion.sigma",
+                  CPL_TYPE_DOUBLE,
+                              "Sigma: sigma of Gaussian which is convolved "
+                              "with the artificial spectrum generated using "
+                              "the line list",
+                              "sinfoni.distortion",
+                               2.);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"dist-sigma");
+  cpl_parameterlist_append(list, p);
+
+  /* Wavelength Calibration */
+/* guess value for fwhm of emission lines */
+  p = cpl_parameter_new_value("sinfoni.distortion.fwhm",
+                  CPL_TYPE_DOUBLE,
+                              "FWHM: initial guess value for the fwhm of "
+                              "the Gaussian used for the line fit",
+                              "sinfoni.distortion",
+                               2.83);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"dist-fwhm");
+  cpl_parameterlist_append(list, p);
+
+/* minimum amplitude of a line to be fitted */
+  p = cpl_parameter_new_value("sinfoni.distortion.min_amplitude",
+                  CPL_TYPE_DOUBLE,
+                              "Minimum Of Amplitude: "
+                              "of the Gaussian to do the fit",
+                              "sinfoni.distortion",
+                              5.);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"dist-min_amplitude");
+  cpl_parameterlist_append(list, p);
+
+/* maximal residual value for a valid fit */
+  p = cpl_parameter_new_value("sinfoni.distortion.max_residual",
+                  CPL_TYPE_DOUBLE,
+                              "Maximum Residuals value: "
+                              "beyond this value the fit is rejected",
+                              "sinfoni.distortion",
+                              0.5);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"dist-max_residual");
+  cpl_parameterlist_append(list, p);
+
+/* # of polynomial coefficients used for the dispersion relation */
+  p = cpl_parameter_new_value("sinfoni.distortion.n_a_coefficients",
+                  CPL_TYPE_INT,
+                              "Number of A coefficients: number of "
+                              "polynomial coefficients for the "
+                              "dispersion relation",
+                              "sinfoni.distortion",
+                              4);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"dist-n_a_coeffs");
+  cpl_parameterlist_append(list, p);
+
+ /* # of polynomial coefficients used for the fit of the dispersion 
+    coefficients */
+  p = cpl_parameter_new_value("sinfoni.distortion.n_b_coefficients",
+                  CPL_TYPE_INT,
+                              "Number of B coefficients: "
+                              "number of polynomial coefficients for the "
+                              "polynomial fit of the dispersion coefficients",
+                              "sinfoni.distortion",
+                              2);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"dist-n_b_coeffs");
+  cpl_parameterlist_append(list, p);
+
+ /* minimal factor of the standard deviation of the fit coefficients */
+  p = cpl_parameter_new_value("sinfoni.distortion.sigma_factor",
+                  CPL_TYPE_DOUBLE,
+                              "Sigma Factor: "
+                              "Factor of the standard deviation of the "
+                              "polynomial coefficients of the dispersion "
+                              "relation beyond which the coefficients are "
+                              "not used for the fit",
+                              "sinfoni.distortion",
+                              1.5);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"dist-sigma_factor");
+  cpl_parameterlist_append(list, p);
+
+  /* indicates if the parameterized dispersion relation coefficients 
+       should be written into an ASCII file */
+  p = cpl_parameter_new_value("sinfoni.distortion.write_coeffs_ind",
+                  CPL_TYPE_BOOL,
+                              "Write Coefficients Index: "
+                              "indicates if the coefficients should "
+                              "be written into a file or not",
+                              "sinfoni.distortion",
+                              TRUE);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"dist-wcoeff_ind");
+  cpl_parameterlist_append(list, p);
+
+  /* indicates if the fit parameters should be written into an ASCII file */
+  p = cpl_parameter_new_value("sinfoni.distortion.write_par_ind",
+                  CPL_TYPE_BOOL,
+                              "Write Parameter Index: "
+                              "indicates if the fit parameters should "
+                              "be written into a file or not ",
+                              "sinfoni.distortion",
+                              TRUE);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"dist-par_ind");
+  cpl_parameterlist_append(list, p);
+
+
+  /* minimal distance of the slitlets in spectral direction */
+  p = cpl_parameter_new_value("sinfoni.distortion.pixel_dist",
+                  CPL_TYPE_INT,
+                         "Minimal Slitlets's Distance in spectral direction",
+                              "sinfoni.distortion",
+                              15);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"dist-pixel_dist");
+  cpl_parameterlist_append(list, p);
+
+
+
+  /* allowed pixel position tolerance between estimated and fitted line 
+     position
+  */
+  p = cpl_parameter_new_value("sinfoni.distortion.pixel_tol",
+                  CPL_TYPE_DOUBLE,
+                              "Pixel Tolerance: allowed pixel position "
+                              "tolerance between estimated and fitted "
+                  "line position",
+                              "sinfoni.distortion",
+                              5.0);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"dist-pixel_tol");
+  cpl_parameterlist_append(list, p);
+
+  /* Wavelength Map */
+/* indicator if wavelength map should be generated or not */
+  p = cpl_parameter_new_value("sinfoni.distortion.wave_map_ind",
+                  CPL_TYPE_BOOL,
+                              "Wavelength Map Indicator: "
+                              "indicates if the wavelength calibration map "
+                              "should be generated (TRUE) or not (FALSE)",
+                              "sinfoni.distortion",
+                              FALSE);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"dist-wave_map_ind");
+  cpl_parameterlist_append(list, p);
+
+  /* magnifying factor for FFT */
+  p = cpl_parameter_new_value("sinfoni.distortion.mag_factor",
+                  CPL_TYPE_INT,
+                              "Magnificator Factor: "
+                              "magnifying factor for the number of pixels "
+                              "in the columns needed for FFT",
+                              "sinfoni.distortion",
+                              8);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"dist-mag_factor");
+  cpl_parameterlist_append(list, p);
+
+/* Fits Slits */
+/* indicator if the fit of the slit edge positions is carried through or not */
+  p = cpl_parameter_new_value("sinfoni.distortion.slit_pos_indicator",
+                  CPL_TYPE_BOOL,
+                              "Slit Position Indicator: "
+                              "indicates if the fits of the slitlet "
+                              "edge positions should be carried "
+                              "through or not",
+                              "sinfoni.distortion",
+                              TRUE);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"dist-slit_pos_ind");
+  cpl_parameterlist_append(list, p);
+
+/* indicator if the fit model function is a Boltzmann function or not */
+  p = cpl_parameter_new_value("sinfoni.distortion.fit_boltz_indicator",
+                  CPL_TYPE_BOOL ,
+                              "Fit Boltzmann Indicator: "
+                              "indicates if the fits of the slitlet edge "
+                              "positions is carried trough by using a "
+                              "Boltzmann function as model function",
+                              "sinfoni.distortion",
+                              TRUE);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"dist-fit_boltz_ind");
+  cpl_parameterlist_append(list, p);
+
+/* indicator if the fit model function is a simple edge function or not */
+  p = cpl_parameter_new_value("sinfoni.distortion.fit_edge_indicator",
+                  CPL_TYPE_BOOL,
+                              "Fit Edge Indicator: "
+                              "indicates if the fits of the slitlet edge "
+                              "positions is carried through by using a "
+                              "simple edge function as model function",
+                              "sinfoni.distortion",
+                              FALSE);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"dist-fit_edge_ind");
+  cpl_parameterlist_append(list, p);
+
+ /* indicator if the fit guess position are user 
+    given or calculated automatically */
+
+  p = cpl_parameter_new_value("sinfoni.distortion.estimate_indicator",
+                  CPL_TYPE_BOOL,
+                              "Estimate Indicator: "
+                              "indicates if the fits of the slitlet edge "
+                              "positions is carried through by using a list "
+                              "of estimated guess positions in a file (TRUE)"
+                              "or if the initial positions are calculated "
+                              "automatically (FALSE). The estimation case "
+                              "is more stable",
+                              "sinfoni.distortion",
+                              FALSE);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"dist-estimate_ind");
+  cpl_parameterlist_append(list, p);
+
+/* pixel length of the row box within which 
+   the fit of the slitlet positions is carried out*/
+
+  p = cpl_parameter_new_value("sinfoni.distortion.box_length",
+                  CPL_TYPE_INT,
+                              "Box Length: "
+                              "pixel length of the row box within "
+                              "which the fit is carried out",
+                              "sinfoni.distortion",
+                              32);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"dist-box_len");
+  cpl_parameterlist_append(list, p);
+
+/* float box half width in spectral direction */
+  p = cpl_parameter_new_value("sinfoni.distortion.y_box",
+                  CPL_TYPE_DOUBLE,
+                              "Y Box: half width of a small box in "
+                              "spectral direction within which the "
+                              "maximal intensity pixel is searched",
+                              "sinfoni.distortion",
+                              5.);
+
+ cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"dist-y_box");
+  cpl_parameterlist_append(list, p);
+
+/* maximal tolerable difference to the expected slitlet positions */
+  p = cpl_parameter_new_value("sinfoni.distortion.diff_tol",
+                  CPL_TYPE_DOUBLE,
+                              "Difference Tolearance: "
+                              "maximal tolerable difference of the "
+                              "resulting fit positions of the slitlet "
+                              "edges with respect to the expected positions",
+                              "sinfoni.distortion",
+                              2.);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"dist-diff_toll");
+  cpl_parameterlist_append(list, p);
+
+
+ p = cpl_parameter_new_value("sinfoni.distortion.qc_thresh_min",
+                  CPL_TYPE_INT,
+                              "qc_thresh_min",
+                              "sinfoni.distortion",
+                              0);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"dist-qc_thresh_min");
+  cpl_parameterlist_append(list, p);
+
+
+  p = cpl_parameter_new_value("sinfoni.distortion.qc_thresh_max",
+                  CPL_TYPE_INT,
+                              "qc_thresh_max",
+                              "sinfoni.distortion",
+                              49000);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"dist-qc_thresh_max");
+  cpl_parameterlist_append(list, p);
+
+
+
+
+
+
+  /* NORD SOUTH TEST */
+
+
+
+  /* Clean Mean */
+  p = cpl_parameter_new_range("sinfoni.distortion.lower_rejection",
+                  CPL_TYPE_DOUBLE,
+                              "lower rejection: "
+                              "percentage of rejected low intensity pixels "
+                              "before averaging",
+                              "sinfoni.distortion",
+                               0.1,0.0,1.0);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"ns-lo_rejection");
+  cpl_parameterlist_append(list, p);
+
+  p = cpl_parameter_new_range("sinfoni.distortion.higher_rejection",
+                  CPL_TYPE_DOUBLE,
+                              "higher rejection: "
+                              "percentage of rejected high intensity pixels "
+                              "before averaging",
+                              "sinfoni.distortion",
+                              0.1,0.0,1.0);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"ns-hi_rejection");
+  cpl_parameterlist_append(list, p);
+
+
+  p = cpl_parameter_new_value("sinfoni.distortion.mask_ind",
+                  CPL_TYPE_BOOL,
+                              "Mask Index: "
+                             "indicator if a bad pixel mask is applied or not",
+                              "sinfoni.distortion",
+                              FALSE);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"ns-mask_ind");
+  cpl_parameterlist_append(list, p);
+
+
+  /* Gauss Convolution */
+  p = cpl_parameter_new_value("sinfoni.distortion.gauss_ind",
+                  CPL_TYPE_BOOL,
+                              "Gauss Index: ",
+                              "sinfoni.distortion",
+                              FALSE);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"ns-gauss_ind");
+  cpl_parameterlist_append(list, p);
+
+  p = cpl_parameter_new_value("sinfoni.distortion.kernel_half_width",
+                  CPL_TYPE_INT,
+                              "Kernel Half Width "
+                              "kernel half width of the Gaussian "
+                              "response function",
+                              "sinfoni.distortion",
+                               2);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"ns-khw");
+  cpl_parameterlist_append(list, p);
+
+
+
+  /* North South Test */
+
+
+
+  p = cpl_parameter_new_value("sinfoni.distortion.ns_half_width",
+                  CPL_TYPE_INT,
+                              "Half Width",
+                              "sinfoni.distortion",
+                               4);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"ns-hw");
+  cpl_parameterlist_append(list, p);
+
+  p = cpl_parameter_new_value("sinfoni.distortion.ns_fwhm",
+                  CPL_TYPE_DOUBLE,
+                              "FWHM",
+                              "sinfoni.distortion",
+                               2.);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"ns-fwhm");
+  cpl_parameterlist_append(list, p);
+
+
+  p = cpl_parameter_new_value("sinfoni.distortion.min_diff",
+                  CPL_TYPE_DOUBLE,
+                              "Minimum of Difference",
+                              "sinfoni.distortion",
+                              1.);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"ns-min_diff");
+  cpl_parameterlist_append(list, p);
+
+
+  p = cpl_parameter_new_value("sinfoni.distortion.dev_tol",
+                  CPL_TYPE_DOUBLE,
+                              "Dev Tol",
+                              "sinfoni.distortion",
+                              20.);
+
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"ns-dev_tol");
+  cpl_parameterlist_append(list, p);
+
+
+  p = cpl_parameter_new_value("sinfoni.distortion.arcs_thresh_factor",
+                  CPL_TYPE_DOUBLE,
+                              "arcs threshold factor. "
+                              "median_value(image)+ kappa*sigma is the "
+                              "minimum intensity threshold of accepted image"
+                              "pixels",
+                              "sinfoni.distortion",
+                              0.33333);
+
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"arcs_thresh_factor");
+  cpl_parameterlist_append(list, p);
+
+
+
+  p = cpl_parameter_new_value("sinfoni.distortion.arcs_min_arclen_factor",
+                  CPL_TYPE_DOUBLE,
+                              "factor which sets minimum arc length (1.0-2)",
+                              "sinfoni.distortion",
+                              1.19);
+
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"arcs_min_arclen_factor");
+  cpl_parameterlist_append(list, p);
+
+
+  p = cpl_parameter_new_value("sinfoni.distortion.arcs_window_size",
+                  CPL_TYPE_INT,
+                              "Size of window for low pass fileter used in"
+                              "an horizzontal low pass filter to remove "
+                              "unwanted arcs (5-64)",
+                              "sinfoni.distortion",
+                              14);
+
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"arcs_window_size");
+  cpl_parameterlist_append(list, p);
+
+
+  p = cpl_parameter_new_value("sinfoni.distortion.smooth_rad",
+                  CPL_TYPE_INT,
+                              "Size of smoothing factor (1-11) used to "
+                              "prevent for possible intensity drops from "
+                              "detector electronics on fibre illuminated "
+                              "slitlets (1-11)",
+                              "sinfoni.distortion",
+                              3);
+
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"smooth_rad");
+  cpl_parameterlist_append(list, p);
+
+}
+/**@}*/
diff --git a/sinfoni/sinfo_distortion_config.h b/sinfoni/sinfo_distortion_config.h
new file mode 100644
index 0000000..4041927
--- /dev/null
+++ b/sinfoni/sinfo_distortion_config.h
@@ -0,0 +1,32 @@
+/* $Id: sinfo_distortion_config.h,v 1.1 2006/10/20 08:06:32 amodigli Exp $
+ *
+ * This file is part of the CPL (Common Pipeline Library)
+ * Copyright (C) 2002 European Southern Observatory
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*
+ * $Author: amodigli $
+ * $Date: 2006/10/20 08:06:32 $
+ * $Revision: 1.1 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+ /****************************************************************
+  *   Wavecal Frames Data Reduction Parameter Initialization        *
+  ****************************************************************/
+#include <cpl.h>    /* defines parlist structure */
+void sinfo_distortion_config_add(cpl_parameterlist *list);
+
diff --git a/sinfoni/sinfo_dump.c b/sinfoni/sinfo_dump.c
new file mode 100644
index 0000000..c064edc
--- /dev/null
+++ b/sinfoni/sinfo_dump.c
@@ -0,0 +1,422 @@
+/*                                                                           *
+ *   This file is part of the SINFONI   Pipeline                             *
+ *   Copyright (C) 2002,2003 European Southern Observatory                   *
+ *                                                                           *
+ *   This library is free software; you can redistribute it and/or modify    *
+ *   it under the terms of the GNU General Public License as published by    *
+ *   the Free Software Foundation; either version 2 of the License, or       *
+ *   (at your option) any later version.                                     *
+ *                                                                           *
+ *   This program is distributed in the hope that it will be useful,         *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
+ *   GNU General Public License for more details.                            *
+ *                                                                           *
+ *   You should have received a copy of the GNU General Public License       *
+ *   along with this program; if not, write to the Free Software             *
+ *   Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA    *
+ *                                                                           */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2012/03/02 08:42:20 $
+ * $Revision: 1.8 $
+ * $Name: sinfo-2_3_2 $
+ * $Log: sinfo_dump.c,v $
+ * Revision 1.8  2012/03/02 08:42:20  amodigli
+ * fixed some typos on doxygen
+ *
+ * Revision 1.7  2011/11/23 17:29:19  amodigli
+ * fix warning with cpl6
+ *
+ * Revision 1.6  2008/01/17 07:54:04  amodigli
+ * shorten long lines
+ *
+ * Revision 1.5  2007/08/11 10:45:47  amodigli
+ * upgrade to CPL4, fixed compil warnings
+ *
+ * Revision 1.4  2007/06/06 07:10:45  amodigli
+ * replaced tab with 4 spaces
+ *
+ * Revision 1.3  2006/10/20 08:07:05  amodigli
+ * using prefix sinfo_ in place of sinfoni_ for includes
+ *
+ * Revision 1.2  2006/10/16 07:26:23  amodigli
+ * shortened line length
+ *
+ * Revision 1.1  2006/08/09 12:20:11  amodigli
+ * added sinfo_dump.h sinfo_dump.c
+ *
+ * Revision 1.7  2006/05/12 15:02:05  jmlarsen
+ * Support NULL tags
+ *
+ * Revision 1.6  2006/02/28 09:15:22  jmlarsen
+ * Minor update
+ *
+ * Revision 1.5  2006/02/15 13:19:15  jmlarsen
+ * Reduced source code max. line length
+ *
+ * Revision 1.4  2005/12/19 16:17:56  jmlarsen
+ * Replaced bool -> int
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+/**@{*/
+
+/*----------------------------------------------------------------------------*/
+/**
+   @defgroup sinfo_dump  Print CPL objects
+
+   Functions that enables dumping (using CPL's messaging system) some
+   otherwise non-dumpable CPL objects
+ */
+/*----------------------------------------------------------------------------*/
+
+
+#include <sinfo_dump.h>
+#include <sinfo_utils.h>
+#include <sinfo_error.h>
+#include <sinfo_msg.h>
+#include <cpl.h>
+
+/*----------------------------------------------------------------*/
+/** 
+ * @brief Print a property list.
+ * @param pl      The property list to print.
+ * @param low     Index of first property to print.
+ * @param high    Index of first property not to print.
+ * @return CPL_ERROR_NONE iff OK.
+ *
+ * This function prints all properties in the property list @em pl
+ * in the range from @em low (included) to @em high (not included)
+ * counting from zero.
+ */
+/*----------------------------------------------------------------*/
+cpl_error_code
+sinfo_print_cpl_propertylist(const cpl_propertylist *pl, long low, long high)
+{
+    cpl_property *prop;
+    long i = 0;
+    
+    assure (0 <= low && high <= cpl_propertylist_get_size(pl) && low <= high,
+        CPL_ERROR_ILLEGAL_INPUT, "Illegal range");
+    /* Printing an empty range is allowed but only when low == high */
+
+    if (pl == NULL){
+    sinfo_msg("NULL");
+    }
+    else if (cpl_propertylist_is_empty(pl))  {
+    sinfo_msg("[Empty property list]");
+    }
+    else    
+    for (i = low; i < high; i++)
+        {
+        /* bug workaround: remove const cast when declaration 
+           of cpl_propertylist_get() is changed */
+        prop = cpl_propertylist_get((cpl_propertylist *)pl, i);
+        check (sinfo_print_cpl_property(prop), 
+                "Error printing property");
+        }
+    
+  cleanup:
+    return cpl_error_get_code();
+}
+/*----------------------------------------------------------------*/
+/** 
+ * @brief Print a property.
+ * @param prop      The property to print.
+ * @return CPL_ERROR_NONE iff OK.
+ *
+ * This function prints a property's name, value and comment.
+ */
+/*----------------------------------------------------------------*/
+
+cpl_error_code
+sinfo_print_cpl_property(const cpl_property *prop)
+{
+    cpl_type t;
+
+    if (prop == NULL)
+    {
+        sinfo_msg("NULL");
+    }
+    else
+    {   
+        /* print property with this formatting
+           NAME =
+             VALUE
+           COMMENT
+        */
+
+        /* print name */
+        
+        sinfo_msg("%s =", cpl_property_get_name(prop));
+
+        /* print value */
+        
+        check( t = cpl_property_get_type(prop), 
+                  "Could not read property type");
+        
+        switch(t & (~CPL_TYPE_FLAG_ARRAY))
+        {
+        case CPL_TYPE_CHAR:
+            if (t & CPL_TYPE_FLAG_ARRAY)  /* if type is string */
+            {
+                sinfo_msg("  '%s'", cpl_property_get_string(prop));
+            }
+            else                          /* an ordinary char */
+            {
+                sinfo_msg("  %c", cpl_property_get_char(prop));
+            }
+            break;
+        case CPL_TYPE_BOOL:    if (cpl_property_get_bool(prop))
+            {sinfo_msg("  true");}
+        else
+            {sinfo_msg("  false");}
+            break;
+        case CPL_TYPE_UCHAR: 
+	  sinfo_msg("%c",cpl_property_get_char(prop)); 
+          break;
+        case CPL_TYPE_INT:   
+	  sinfo_msg("%d",cpl_property_get_int(prop)); 
+          break;
+        case CPL_TYPE_UINT:  
+          sinfo_msg("%d",cpl_property_get_int(prop)); 
+          break;
+        case CPL_TYPE_LONG: 
+          sinfo_msg("%ld",cpl_property_get_long(prop)); 
+          break;
+        case CPL_TYPE_ULONG: 
+          sinfo_msg("%ld",cpl_property_get_long(prop)); 
+          break;
+        case CPL_TYPE_FLOAT: 
+          sinfo_msg("%f",cpl_property_get_float(prop)); 
+          break;
+        case CPL_TYPE_DOUBLE: 
+          sinfo_msg("%f",cpl_property_get_double(prop)); 
+          break;
+        case CPL_TYPE_POINTER: 
+          sinfo_msg("POINTER");    
+          break;
+        case CPL_TYPE_INVALID: 
+          sinfo_msg("INVALID");    
+          break;
+        default: 
+          sinfo_msg("  unrecognized property");  
+          break;
+        }
+        
+        /* Is this property an array? */
+        if (t & CPL_TYPE_FLAG_ARRAY){
+           cpl_msg_info(cpl_func,"  (array size = %" CPL_SIZE_FORMAT " )", 
+              cpl_property_get_size(prop));
+        }
+
+        /* Print comment */
+        if (cpl_property_get_comment(prop) != NULL){
+        sinfo_msg("    %s", cpl_property_get_comment(prop));
+        }
+    }
+
+  cleanup:
+    return cpl_error_get_code();
+}
+
+/*----------------------------------------------------------------*/
+/** 
+ * @brief Print a frame set
+ * @param frames Frame set to print
+ * @return CPL_ERROR_NONE iff OK.
+ *
+ * This function prints all frames in a CPL frame set.
+ */
+/*----------------------------------------------------------------*/
+cpl_error_code
+sinfo_print_cpl_frameset(const cpl_frameset *frames)
+{
+    /* Two special cases: a NULL frame set and an empty frame set */
+
+    if (frames == NULL)
+    {
+        sinfo_msg("NULL");
+    }
+    else
+    {
+        const cpl_frame *f = NULL;
+        check( f = cpl_frameset_get_first_const(frames), 
+                   "Error reading frameset");
+        
+        if (f == NULL)
+        {
+            sinfo_msg("[Empty frame set]");
+        }
+        else
+        {
+            while(f != NULL)
+            {
+                check( sinfo_print_cpl_frame(f), 
+                                  "Could not print frame");
+                check( f = cpl_frameset_get_next_const(frames), 
+                                  "Error reading frameset");
+            }
+        }
+    }
+    
+  cleanup:
+    return cpl_error_get_code();
+}
+
+/*----------------------------------------------------------------*/
+/** 
+ * @brief Print a frame
+ * @param f Frame to print
+ * @return CPL_ERROR_NONE iff OK.
+ *
+ * This function prints a CPL frame.
+ */
+/*----------------------------------------------------------------*/
+cpl_error_code
+sinfo_print_cpl_frame(const cpl_frame *f)
+{
+    if (f == NULL)
+    {
+        sinfo_msg("NULL");
+    }
+    else
+    {
+        sinfo_msg("%-7s %-20s '%s'", 
+             sinfo_tostring_cpl_frame_group(cpl_frame_get_group(f)),
+             cpl_frame_get_tag(f) != NULL ? 
+                     cpl_frame_get_tag(f) : "Null",
+             cpl_frame_get_filename(f));
+        
+        sinfo_msg_debug("type \t= %s",   
+            sinfo_tostring_cpl_frame_type (cpl_frame_get_type (f)));
+        sinfo_msg_debug("group \t= %s",  
+            sinfo_tostring_cpl_frame_group(cpl_frame_get_group(f)));
+        sinfo_msg_debug("level \t= %s",  
+            sinfo_tostring_cpl_frame_level(cpl_frame_get_level(f)));
+    }
+
+    return cpl_error_get_code();
+}
+
+/*----------------------------------------------------------------*/
+/** 
+ * @brief Convert a frame type to a string
+ * @param ft  Frame type to convert
+ * @return A textual representation of @em  ft.
+ */
+/*----------------------------------------------------------------*/
+const char *
+sinfo_tostring_cpl_frame_type(cpl_frame_type ft)
+{    
+    switch(ft)
+    {
+    case CPL_FRAME_TYPE_NONE:   return "NONE";      break;
+    case CPL_FRAME_TYPE_IMAGE:  return "IMAGE";     break;
+    case CPL_FRAME_TYPE_MATRIX: return "MATRIX";    break;
+    case CPL_FRAME_TYPE_TABLE:  return "TABLE";     break;
+    default: return "unrecognized frame type";
+    }
+}
+
+/*----------------------------------------------------------------*/
+/** 
+ * @brief Convert a frame group to a string
+ * @param fg  Frame group to convert
+ * @return A textual representation of @em  fg.
+ */
+/*----------------------------------------------------------------*/
+const char *
+sinfo_tostring_cpl_frame_group(cpl_frame_group fg)
+{
+    switch(fg)
+    {
+    case CPL_FRAME_GROUP_NONE:    return "NONE";                    break;
+    case CPL_FRAME_GROUP_RAW:     return CPL_FRAME_GROUP_RAW_ID;    break;
+    case CPL_FRAME_GROUP_CALIB:   return CPL_FRAME_GROUP_CALIB_ID;  break;
+    case CPL_FRAME_GROUP_PRODUCT: return CPL_FRAME_GROUP_PRODUCT_ID;break;
+    default:
+        return "unrecognized frame group";
+    }
+}
+
+/*----------------------------------------------------------------*/
+/** 
+ * @brief Convert a frame level to a string
+ * @param fl  Frame level to convert
+ * @return A textual representation of @em  fl.
+ */
+/*----------------------------------------------------------------*/
+const char *
+sinfo_tostring_cpl_frame_level(cpl_frame_level fl)
+{
+    
+    switch(fl)
+    {
+    case CPL_FRAME_LEVEL_NONE:        return "NONE";        break;
+    case CPL_FRAME_LEVEL_TEMPORARY:   return "TEMPORARY";   break;
+    case CPL_FRAME_LEVEL_INTERMEDIATE:return "INTERMEDIATE";break;
+    case CPL_FRAME_LEVEL_FINAL:       return "FINAL";       break;
+    default: return "unrecognized frame level";
+    }
+}
+
+
+/*----------------------------------------------------------------*/
+/** 
+ * @brief Convert a CPL type to a string
+ * @param t  Type to convert
+ * @return A textual representation of @em  t.
+ */
+/*----------------------------------------------------------------*/
+const char *
+sinfo_tostring_cpl_type(cpl_type t)
+{
+
+    /* Note that CPL_TYPE_STRING is shorthand
+       for CPL_TYPE_CHAR | CPL_TYPE_FLAG_ARRAY . */
+
+    if (!(t & CPL_TYPE_FLAG_ARRAY))
+    switch(t & (~CPL_TYPE_FLAG_ARRAY))
+        {
+        case CPL_TYPE_CHAR:       return "char";    break;
+        case CPL_TYPE_UCHAR:      return "uchar";   break;
+        case CPL_TYPE_BOOL:       return "boolean"; break;
+        case CPL_TYPE_INT:        return "int";     break;
+        case CPL_TYPE_UINT:       return "uint";    break;
+        case CPL_TYPE_LONG:       return "long";    break;
+        case CPL_TYPE_ULONG:      return "ulong";   break;
+        case CPL_TYPE_FLOAT:      return "float";   break;
+        case CPL_TYPE_DOUBLE:     return "double";  break;
+        case CPL_TYPE_POINTER:    return "pointer"; break;
+/* not in CPL3.0: case CPL_TYPE_COMPLEX:    return "complex"; break; */
+        case CPL_TYPE_INVALID:    return "invalid"; break;
+        default:
+        return "unrecognized type";
+        }
+    else
+    switch(t & (~CPL_TYPE_FLAG_ARRAY))
+        {
+        case CPL_TYPE_CHAR:       return "string (char array)"; break;
+        case CPL_TYPE_UCHAR:      return "uchar array";         break;
+        case CPL_TYPE_BOOL:       return "boolean array";       break;
+        case CPL_TYPE_INT:        return "int array";           break;
+        case CPL_TYPE_UINT:       return "uint array";          break;
+        case CPL_TYPE_LONG:       return "long array";          break;
+        case CPL_TYPE_ULONG:      return "ulong array";         break;
+        case CPL_TYPE_FLOAT:      return "float array";         break;
+        case CPL_TYPE_DOUBLE:     return "double array";        break;
+        case CPL_TYPE_POINTER:    return "pointer array";       break;
+/* not in CPL3.0: case CPL_TYPE_COMPLEX:    return "complex array"; break; */
+        case CPL_TYPE_INVALID:    return "invalid (array)";     break;
+        default:
+        return "unrecognized type";
+        }
+}
+/**@}*/
diff --git a/sinfoni/sinfo_dump.h b/sinfoni/sinfo_dump.h
new file mode 100644
index 0000000..5e39994
--- /dev/null
+++ b/sinfoni/sinfo_dump.h
@@ -0,0 +1,84 @@
+/*                                                                           *
+ *   This file is part of the ESO UVES  Pipeline                             *
+ *   Copyright (C) 2004,2005 European Southern Observatory                   *
+ *                                                                           *
+ *   This library is free software; you can redistribute it and/or modify    *
+ *   it under the terms of the GNU General Public License as published by    *
+ *   the Free Software Foundation; either version 2 of the License, or       *
+ *   (at your option) any later version.                                     *
+ *                                                                           *
+ *   This program is distributed in the hope that it will be useful,         *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
+ *   GNU General Public License for more details.                            *
+ *                                                                           *
+ *   You should have received a copy of the GNU General Public License       *
+ *   along with this program; if not, write to the Free Software             *
+ *   Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA    *
+ *                                                                           */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2011/11/23 17:29:09 $
+ * $Revision: 1.6 $
+ * $Name: sinfo-2_3_2 $
+ * $Log: sinfo_dump.h,v $
+ * Revision 1.6  2011/11/23 17:29:09  amodigli
+ * fix warning with cpl6
+ *
+ * Revision 1.5  2006/10/25 06:46:09  amodigli
+ * fixed warnings from static checks
+ *
+ * Revision 1.4  2006/10/17 11:13:30  amodigli
+ * added config.h
+ *
+ * Revision 1.3  2006/10/16 07:26:23  amodigli
+ * shortened line length
+ *
+ * Revision 1.2  2006/10/04 06:17:45  amodigli
+ * added doxygen doc
+ *
+ * Revision 1.1  2006/08/09 12:20:11  amodigli
+ * added sinfo_dump.h sinfo_dump.c
+ *
+ * Revision 1.2  2005/12/19 16:17:56  jmlarsen
+ * Replaced bool -> int
+ *
+ */
+#ifndef SINFO_DUMP_H
+#define SINFO_DUMP_H
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#include <cpl.h>
+#include <sinfo_cpl_size.h>
+
+cpl_error_code 
+sinfo_print_cpl_propertylist(const cpl_propertylist *pl, 
+                             long low, 
+                             long high);
+
+cpl_error_code 
+sinfo_print_cpl_property(const cpl_property *);
+
+cpl_error_code 
+sinfo_print_cpl_frameset(const cpl_frameset *);
+
+cpl_error_code 
+sinfo_print_cpl_frame(const cpl_frame *);
+
+const char *
+sinfo_tostring_cpl_type(cpl_type t);
+
+const char *
+sinfo_tostring_cpl_frame_type(cpl_frame_type);
+
+const char *
+sinfo_tostring_cpl_frame_group(cpl_frame_group);
+
+const char *
+sinfo_tostring_cpl_frame_level(cpl_frame_level);
+
+#endif /* SINFO_DUMP_H */
diff --git a/sinfoni/sinfo_error.h b/sinfoni/sinfo_error.h
new file mode 100644
index 0000000..0f03831
--- /dev/null
+++ b/sinfoni/sinfo_error.h
@@ -0,0 +1,410 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2007/10/26 09:42:36 $
+ * $Revision: 1.13 $
+ * $Name: sinfo-2_3_2 $
+ * $Log: sinfo_error.h,v $
+ * Revision 1.13  2007/10/26 09:42:36  amodigli
+ * removed check on CPL_VERSION_CODE (now works only for CPL4)
+ *
+ * Revision 1.12  2007/08/14 10:01:41  amodigli
+ * added sinfo_stop_if_error
+ *
+ * Revision 1.11  2007/08/11 10:46:18  amodigli
+ * clean
+ *
+ * Revision 1.9  2007/08/08 11:17:26  amodigli
+ * change to support CPL31 & CPL40
+ *
+ * Revision 1.8  2007/06/06 07:10:45  amodigli
+ * replaced tab with 4 spaces
+ *
+ * Revision 1.7  2006/11/21 11:56:10  amodigli
+ * replaced __func__ by cpl_func
+ *
+ * Revision 1.6  2006/10/16 07:26:23  amodigli
+ * shortened line length
+ *
+ * Revision 1.5  2006/10/13 08:09:42  amodigli
+ * shorten line length
+ *
+ * Revision 1.4  2006/10/13 06:34:40  amodigli
+ * shorten line length
+ *
+ * Revision 1.3  2006/10/04 06:17:45  amodigli
+ * added doxygen doc
+ *
+ * Revision 1.2  2006/07/31 06:33:34  amodigli
+ * fixed  bug in ck0 macro
+ *
+ * Revision 1.1  2006/05/30 09:09:37  amodigli
+ * added to repository
+ *
+ *
+ */
+
+#ifndef SINFO_ERROR_H
+#define SINFO_ERROR_H
+/**
+    @defgroup sinfo_error  Error handling
+*/
+/**@{*/
+
+/*-----------------------------------------------------------------------------
+                    Includes
+-----------------------------------------------------------------------------*/
+#include <cpl_error.h>
+#include <cpl.h>
+
+#include <irplib_utils.h>
+/*-----------------------------------------------------------------------------
+                             Defines
+-----------------------------------------------------------------------------*/
+/* To save some key-strokes, use the irplib error handling macros
+   under different (shorter) names.
+   Additionally, irplib macros require the VA_ARGS to be enclosed in (),
+*/
+
+#define assure(BOOL, CODE, ...) \
+  cpl_error_ensure(BOOL, CODE, goto cleanup,__VA_ARGS__)
+
+#define assure_nomsg(BOOL, CODE, ...)				\
+  cpl_error_ensure(BOOL, CODE, goto cleanup,__VA_ARGS__)
+
+#define sinfo_stop_if_error() \
+     do if(cpl_error_get_code()) { \
+     cpl_msg_error(__func__,"Traced error"); \
+     irplib_trace(); \
+     goto cleanup; \
+     } while (0) 
+
+#define ck0(IEXP, ...) \
+  cpl_error_ensure(IEXP == 0, CPL_ERROR_UNSPECIFIED, \
+   goto cleanup,__VA_ARGS__)
+
+#define ck0_nomsg(IEXP) ck0(IEXP," ")
+
+#define cknull(NULLEXP, ...) \
+  cpl_error_ensure((NULLEXP) != NULL, \
+  CPL_ERROR_UNSPECIFIED, goto cleanup,__VA_ARGS__)
+
+#define cknull_nomsg(NULLEXP) cknull(NULLEXP," ")
+
+#define  check(CMD, ...)                                                 \
+  cpl_error_ensure((sinfo_msg_softer(), (CMD), sinfo_msg_louder(),      \
+              cpl_error_get_code() == CPL_ERROR_NONE),       \
+                       cpl_error_get_code(), goto cleanup,__VA_ARGS__)
+
+#define  check_nomsg(CMD) check(CMD, " ")
+
+#define passure(BOOL, ...)                                               \
+  cpl_error_ensure(BOOL, CPL_ERROR_UNSPECIFIED, goto cleanup,\
+                      ("Internal error. Please report to "                \
+                      PACKAGE_BUGREPORT " " __VA_ARGS__))
+                       //  Assumes that PACKAGE_BUGREPORT
+               //contains no formatting special characters  
+   
+
+/**@}*/
+
+
+/**
+   @addtogroup sinfo_error
+ 
+   This error handling module extends CPL's error handler by adding error 
+   tracing and automatic memory deallocation in case of an error.
+   Like in CPL the current error state is indicated by the 
+   @c cpl_error_code (returned by the function @c cpl_error_get_code() ).
+
+   The error tracing makes it possible to see where (source file, 
+   function name, line number) an error first occured, as well as the sequence 
+   of function calls preceding the error. A typical output looks like:
+   @code
+   An error occured, dumping error trace:
+   
+   Wavelength calibration did not converge. After 13 iterations the RMS was 
+   0.300812 pixels. Try to improve
+   the initial guess solution (The iterative process did not converge)
+     in [3]sinfo_wavecal_identify() at sinfo_wavecal_identify.c :101
+    
+   Could not calibrate orders
+     in [2]sinfo_wavecal_process_chip() at sinfo_wavecal.c  :426
+     
+   Wavelength calibration failed
+     in [1]sinfo_wavecal() at sinfo_wavecal.c  :679
+   @endcode
+
+   However, the main motivation of this extension is to simplify the error 
+   checking and handling. A single line of source code
+   
+   @code
+   check( dispersion_relation = sinfo_wavecal_identify(linetable[window-1],
+                                                      line_refer,
+                                                      initial_dispersion, 
+                                                      WAVECAL_MODE, DEGREE, 
+                                                      TOLERANCE, ALPHA, 
+                                                      MAXERROR),
+           "Could not calibrate orders");
+   @endcode
+
+   has the same effect as
+
+   @code
+   if (cpl_error_get_code() != CPL_ERROR_NONE) {
+      cpl_msg_error(cpl_func, 
+                    "An unexpected error (%s) has occurred "
+                    "in %s() at %-15s :%-3d",
+                           cpl_error_get_message(),
+                           cpl_func,
+                           __FILE__,
+                           __LINE__);
+      sinfo_free_image(&spectrum);
+      sinfo_free_image(&cropped_image);
+      sinfo_free_image(&debug_image);
+      sinfo_free_cpl(&relative_order);
+      polynomial_delete(&initial_dispersion);
+      polynomial_delete(&dispersion_relation);
+      return NULL;
+   }
+
+   dispersion_relation = sinfo_wavecal_identify(linetable[window-1],
+                                               line_refer,
+                                               initial_dispersion, 
+                                               WAVECAL_MODE, DEGREE, 
+                                               TOLERANCE, ALPHA, MAXERROR);
+
+   if (cpl_error_get_code() != CPL_ERROR_NONE) {
+      cpl_msg_error(cpl_func, "ERROR: Could not calibrate orders (%s) in %s() 
+      at %-15s :%-3d",
+                           cpl_error_get_message(),
+                           cpl_func,
+                           __FILE__,
+                           __LINE__);
+      sinfo_free_image(&spectrum);
+      sinfo_free_image(&cropped_image);
+      sinfo_free_image(&debug_image);
+      sinfo_free_cpl(&relative_order);
+      polynomial_delete(&initial_dispersion);
+      polynomial_delete(&dispersion_relation);
+      return NULL;
+   }
+   @endcode
+
+   This of course makes the source code more compact and hence easier to 
+   read (and maintain) and allows for intensive error checking with minimal 
+   effort.
+
+   Additionally, editing the @c check() macro (described below) allows for 
+   debugging/tracing information at every function entry and exit.
+
+   @par Usage
+
+   New errors are set with the macros @c assure() and @c passure(), and 
+   sub-functions that might set a @c cpl_error_code
+   are checked using the macros @c check() and @c pcheck() . 
+   The function @c _sinfo_error_set() should never be called
+   directly. These macros check if an error occured and, if so, jumps to
+   the @c cleanup label which must be defined at the end of each function. 
+   After the @c cleanup label every pointer used by the function is deallocated 
+   and the function returns. Also a string variable named @c fctid (function
+   identification), must be defined in every function and contain the name of 
+   the current function.
+
+   At the very end of a recipe the error state should be checked and @c 
+   sinfo_error_dump() called on error:
+   @code
+   if ( cpl_error_get_code() != CPL_ERROR_NONE )
+   {
+      sinfo_error_dump(cpl_func);
+   }
+   @endcode
+
+   When using this scheme:
+
+   - There should be only one @c return statement per function (after the 
+     @c cleanup label).
+
+   - All pointers to dynamically allocated memory must be declared at the 
+     beginning of a function.
+
+   - Pointers must be initialized to NULL (which is a good idea anyway).
+
+   - Pointers must be set to NULL when they are not used (which is a good 
+     idea anyway).
+
+   Consider the example
+
+   @code
+   int function_name(...)
+   {
+      cpl_image * image = NULL;
+      cpl_image * another_image;       / *  Wrong: Pointer must be initialized 
+                                                   to NULL. On cleanup, 
+                                                   cpl_image_delete() will try 
+                                                   to deallocate whatever
+                                                   this pointer points to. If 
+                                                   the pointer is NULL,
+                                                   the deallocator function 
+                                                   will do nothing.  * /
+      :
+      :
+
+      {
+         cpl_object * object = NULL;   / *  Wrong: Pointer must be declared at 
+                                                   the beginning of a function.
+                                                   This object will not be 
+                                                   deallocated, if the following
+                                                   check() fails. * /
+     
+         object = cpl_object_new();
+
+         :
+         :
+              
+         check( ... );
+
+         :
+         :
+
+         cpl_object_delete(object);    / *  Wrong: The pointer must be set to 
+                                                   NULL after deallocation, or
+                                                   the following assure() might
+                                                   cause the already 
+                                                   deallocated object
+                                                   to be deallocated again.  * /
+         :
+         :
+     
+         assure( ... );
+
+         return 7;                     / *  Wrong: Only one exit point per 
+                                            function. * /
+
+      }
+      
+      :
+      :
+
+    cleanup:
+      cpl_image_delete(image);
+      cpl_image_delete(another_image);
+
+      return 7;
+   }
+   @endcode
+
+   This is easily fixed:
+
+   @code
+   int function_name(...)
+   {
+      cpl_image  * image         = NULL;  / *  All pointers are declared at 
+                                               the beginning  * /
+      cpl_image  * another_image = NULL;  / *  of the function an initialized 
+                                               to NULL.     * /
+      cpl_object * object        = NULL;
+
+      :
+      :
+
+      {
+
+         object = cpl_object_new();
+
+         :
+         :
+              
+         check( ... );
+
+         :
+         :
+
+         sinfo_free_object(&object);            / *  The object is deallocated 
+                                                     and the pointer set to 
+                                                     NULL.  * /
+
+         :
+         :
+     
+         assure( ... );
+
+      }
+      
+      :
+      :
+
+    cleanup:
+      sinfo_free_image (&image);                / *  All objects are 
+                                                     deallocated here.  * /
+      sinfo_free_image (&another_image);
+      sinfo_free_object(&object);
+
+      return 7;                           / *  This is the only exit point of 
+                                               the function. * /
+   }
+   @endcode
+
+   (Note that @c sinfo_free_image() et al. can be used instead of 
+              @c cpl_image_delete() et al. as a way to ensure
+   that a pointer is always set to NULL after deallocation).
+
+   @par Recovering from an error
+
+   To recover from an error, call @c sinfo_error_reset(), not 
+     @c cpl_error_reset(). Example:
+
+   @code
+   n = cpl_table_get_nrow(t);
+   if (cpl_error_get_code() == CPL_ERROR_NULL_INPUT)  / *  This error code is 
+                                                           set if 't' is NULL.
+                                                        * /
+   {
+      / *  Recover from this error  * /
+
+      sinfo_error_reset();
+      n = -3;
+   }
+   else  / *  Also check for unexpected errors  * /
+   {
+      assure( cpl_error_get_code() == CPL_ERROR_NONE, cpl_error_get_code(), 
+              "Error reading table size");
+   }
+   @endcode
+
+   However, error recovery is usually best avoided, and the functionality above
+   is better written as:
+
+   @code
+   if (t != NULL)
+   {
+      check( n = cpl_table_get_nrow(t), "Error reading table size");
+   }
+   else
+   {
+      n = -3;
+   }
+   @endcode
+
+      
+*/
+
+#endif
diff --git a/sinfoni/sinfo_fft_base.c b/sinfoni/sinfo_fft_base.c
new file mode 100644
index 0000000..d9f7cbe
--- /dev/null
+++ b/sinfoni/sinfo_fft_base.c
@@ -0,0 +1,242 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*---------------------------------------------------------------------------
+   
+   File name     :    sinfo_fft_base.c
+   Author         :    N. Devillard
+   Created on    :    October 1999
+   Description    :    base FFT routines
+
+ *--------------------------------------------------------------------------*/
+/*
+    $Id: sinfo_fft_base.c,v 1.7 2012/03/02 08:42:20 amodigli Exp $
+    $Author: amodigli $
+    $Date: 2012/03/02 08:42:20 $
+    $Revision: 1.7 $
+*/
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+/*---------------------------------------------------------------------------
+                                   Includes
+ ---------------------------------------------------------------------------*/
+#include "sinfo_fft_base.h"
+#include "sinfo_globals.h"
+/**@{*/
+/**
+ * @addtogroup sinfo_utilities Function to compute FFT
+ *
+ * TBD
+ */
+/*---------------------------------------------------------------------------
+                              Function codes
+ ---------------------------------------------------------------------------*/
+/**
+  @name        sinfo_fftn
+  @memo        N-dimensional FFT.
+  @param    data        N-dimensional data set stored in 1d.
+  @param    nn            Dimensions of the set.
+  @param    ndim        How many dimensions this set has.
+  @param    isign        Transform direction.
+  @return    void
+  @doc
+
+  This routine is a public domain FFT. See extract of Usenet article
+  below. Found on {\tt  http://www.tu-chemnitz.de/~arndt/joerg.html}.
+
+  \begin{verbatim}
+  From: alee at tybalt.caltech.edu (Andrew Lee)
+  Newsgroups: comp.sources.misc
+  Subject: N-dimensional, Radix 2 FFT Routine
+  Date: 17 Jul 87 22:26:29 GMT
+  Approved: allbery at ncoast.UUCP
+  X-Archive: comp.sources.misc/8707/48
+
+  [..]
+  Now for the usage (finally):
+  data[] is the array of complex numbers to be transformed,
+  nn[] is the array giving the dimensions (I mean size) of the array,
+  ndim is the number of dimensions of the array, and
+  isign is +1 for a forward transform, and -1 for an inverse transform.
+
+  data[] and nn[] are stored in the "natural" order for C:
+  nn[0] gives the number of elements along the leftmost index,
+  nn[ndim - 1] gives the number of elements along the rightmost index, and
+  data should be declared along the lines of
+  struct (f)complex data[nn[0], nn[1], ..., nn[ndim - 1]]
+
+  Additional notes: The routine does NO NORMALIZATION, so if you do a
+  forward, and then an inverse transform on an array, the result will
+  be identical to the original array MULTIPLIED BY THE NUMBER OF
+  ELEMENTS IN THE ARRAY.  Also, of course, the dimensions of data[]
+  must all be powers of 2.
+  \end{verbatim}
+
+ */
+
+void
+sinfo_fftn(
+    dcomplex data[],
+    unsigned nn[],
+    int ndim, 
+    int isign)
+{
+  int        idim=0;
+  unsigned   i1=0;
+  unsigned   i2rev=0;
+  unsigned   i3rev=0;
+  unsigned   ibit=0;
+  unsigned   ip2=0;
+  unsigned   ifp1=0;
+  unsigned   ifp2=0;
+  unsigned   k2=0;
+  unsigned   n=0;
+  unsigned   nprev = 1;
+  unsigned   ntot = 1;
+  register   unsigned i2=0;
+  register   unsigned i3=0;
+  double        theta=0;
+  dcomplex   w, wp;
+  double        wtemp=0;
+  dcomplex   temp, wt;
+  double       t1=0;
+  double     t2=0;
+
+  /*      Compute total number of complex values  */
+  for (idim = 0; idim < ndim; ++idim) {
+    ntot *= nn[idim];
+  }
+
+  for (idim = ndim - 1; idim >= 0; --idim) {
+    n = nn[idim];
+
+    ip2 = nprev * n;        /*  Unit step for next dimension */
+    i2rev = 0;              /*  Bit reversed i2 */
+
+    /*      This is the bit reversal section of the routine */
+    /*      Loop over current dimension     */
+    for (i2 = 0; i2 < ip2; i2 += nprev) {
+      if (i2 < i2rev) {
+    /*      Loop over lower dimensions      */
+    for (i1 = i2; i1 < i2 + nprev; ++i1) {
+      /*      Loop over higher dimensions  */
+      for (i3 = i1; i3 < ntot; i3 += ip2) {
+        i3rev = i3 + i2rev - i2;
+        temp = data[i3];
+        data[i3] = data[i3rev];
+        data[i3rev] = temp;
+      }
+    }
+      }
+      ibit = ip2;
+      /*      Increment from high end of i2rev to low */
+      do {
+    ibit >>= 1;
+    i2rev ^= ibit;
+      } while (ibit >= nprev && !(ibit & i2rev));
+    }
+
+    /*      Here begins the Danielson-Lanczos section of the routine */
+    /*      Loop over step sizes    */
+    for (ifp1 = nprev; ifp1 < ip2; ifp1 <<= 1) {
+      ifp2 = ifp1 << 1;
+      /*  Initialize for the trig. recurrence */
+      theta = isign * 2.0 * PI_NUMB / (ifp2 / nprev);
+      wp.x = sin(0.5 * theta);
+      wp.x *= -2.0 * wp.x;
+      wp.y = sin(theta);
+      w.x = 1.0;
+      w.y = 0.0;
+
+      /*  Loop by unit step in current dimension  */
+      for (i3 = 0; i3 < ifp1; i3 += nprev) {
+    /*      Loop over lower dimensions      */
+    for (i1 = i3; i1 < i3 + nprev; ++i1) {
+      /*  Loop over higher dimensions */
+      for (i2 = i1; i2 < ntot; i2 += ifp2) {
+        /*      Danielson-Lanczos formula */
+        k2 = i2 + ifp1;
+        wt = data[k2];
+
+            /* Complex multiply using 3 real multiplies.  
+               Should usually be faster.    */
+        data[k2].x = data[i2].x - (temp.x =
+                       (t1 = w.x * wt.x) - (t2 = w.y * wt.y));
+        data[k2].y = data[i2].y - (temp.y =
+                       (w.x + w.y) * (wt.x + wt.y) - t1 - t2);
+        data[i2].x += temp.x;
+        data[i2].y += temp.y;
+      }
+    }
+    /*      Trigonometric recurrence        */
+    wtemp = w.x;
+        /*    Complex multiply using 3 real multiplies.    */
+    w.x += (t1 = w.x * wp.x) - (t2 = w.y * wp.y);
+    w.y += (wtemp + w.y) * (wp.x + wp.y) - t1 - t2;
+      }
+    }
+    nprev *= n;
+  }
+    
+  return ;
+}
+
+
+
+
+/**
+  @name        sinfo_is_power_of_2
+  @memo        Find if a given integer is a power of 2.
+  @param    p    Integer to check.
+  @return    The corresponding power of 2, or -1.
+  @doc
+
+  If the given number is a power of 2, the power is returned.
+  Otherwise -1 is returned.
+
+  Example:
+  \begin{verbatim}
+  sinfo_is_power_of_2(1024) returns 10
+  sinfo_is_power_of_2(1023) returns -1
+  \end{verbatim}
+ */
+
+int
+sinfo_is_power_of_2(int p)
+{
+    float    c ;
+    int        power2 ;
+
+    if (p == 0) { /* Yes, 0 is a power of 2    */
+        power2 =  1 ;
+    } else if (p<0) { /* No, negatives are no power of 2 (in R at least) */
+        power2 = -1 ;
+    } else { /* Compute log in base 2    */
+        c = (float)(log((double)p) / log(2.0)) ;
+        if (c == (float)((int)c)) {
+            power2 = (int)c ;
+        } else {
+            power2 = -1 ;
+        }
+    }
+    
+    return power2 ;
+}
+
+/**@}*/
diff --git a/sinfoni/sinfo_fft_base.h b/sinfoni/sinfo_fft_base.h
new file mode 100644
index 0000000..7dae4d8
--- /dev/null
+++ b/sinfoni/sinfo_fft_base.h
@@ -0,0 +1,118 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*---------------------------------------------------------------------------
+   File name     :    sinfo_sinfo_fft_base.h
+   Author         :    N. Devillard
+   Created on    :    October 1999
+   Description    :    base FFT routines
+ *--------------------------------------------------------------------------*/
+/*
+    $Id: sinfo_fft_base.h,v 1.6 2007/06/06 07:10:45 amodigli Exp $
+    $Author: amodigli $
+    $Date: 2007/06/06 07:10:45 $
+    $Revision: 1.6 $
+*/
+#ifndef SINFO_FFT_BASE_H
+#define SINFO_FFT_BASE_H
+/*---------------------------------------------------------------------------
+                                   Includes
+ ---------------------------------------------------------------------------*/
+#include <math.h>
+#include "cpl.h"
+#include "sinfo_local_types.h"
+/*---------------------------------------------------------------------------
+                                   New types
+ ---------------------------------------------------------------------------*/
+/*---------------------------------------------------------------------------
+                                   Defines
+ ---------------------------------------------------------------------------*/
+#define FFT_FORWARD         1
+#define FFT_INVERSE        -1
+/*---------------------------------------------------------------------------
+                              Function codes
+ ---------------------------------------------------------------------------*/
+/**
+  @name     sinfo_fftn
+  @memo     N-dimensional FFT.
+  @param    data        N-dimensional data set stored in 1d.
+  @param    nn          Dimensions of the set.
+  @param    ndim        How many dimensions this set has.
+  @param    isign       Transform direction.
+  @return   void
+  @doc      This routine is a public domain FFT. See extract of Usenet article
+  below. Found on {\tt  http://www.tu-chemnitz.de/~arndt/joerg.html}.
+ 
+  \begin{verbatim}
+  From: alee at tybalt.caltech.edu (Andrew Lee)
+  Newsgroups: comp.sources.misc
+  Subject: N-dimensional, Radix 2 FFT Routine
+  Date: 17 Jul 87 22:26:29 GMT
+  Approved: allbery at ncoast.UUCP
+  X-Archive: comp.sources.misc/8707/48
+ 
+  [..]
+  Now for the usage (finally):
+  data[] is the array of complex numbers to be transformed,
+  nn[] is the array giving the dimensions (I mean size) of the array,
+  ndim is the number of dimensions of the array, and
+  isign is +1 for a forward transform, and -1 for an inverse transform.
+ 
+  data[] and nn[] are stored in the "natural" order for C:
+  nn[0] gives the number of elements along the leftmost index,
+  nn[ndim - 1] gives the number of elements along the rightmost index, and
+  data should be declared along the lines of
+  struct (f)complex data[nn[0], nn[1], ..., nn[ndim - 1]]
+ 
+  Additional notes: The routine does NO NORMALIZATION, so if you do a
+  forward, and then an inverse transform on an array, the result will
+  be identical to the original array MULTIPLIED BY THE NUMBER OF
+  ELEMENTS IN THE ARRAY.  Also, of course, the dimensions of data[]
+  must all be powers of 2.
+  \end{verbatim}
+ 
+ */
+
+void
+sinfo_fftn(
+    dcomplex data[],
+    unsigned nn[],
+    int ndim, 
+    int isign);
+
+/**
+  @name     sinfo_is_power_of_2
+  @memo     Find if a given integer is a power of 2.
+  @param    p   Integer to check.
+  @return   The corresponding power of 2, or -1.
+  @doc      If the given number is a power of 2, the power is returned.
+            Otherwise -1 is returned.
+ 
+  Example:
+  \begin{verbatim}
+  sinfo_is_power_of_2(1024) returns 10
+  sinfo_is_power_of_2(1023) returns -1
+  \end{verbatim}
+ */
+
+int sinfo_is_power_of_2(int p);
+
+
+#endif
+/*--------------------------------------------------------------------------*/
+
diff --git a/sinfoni/sinfo_file_handling.c b/sinfoni/sinfo_file_handling.c
new file mode 100644
index 0000000..aa159ee
--- /dev/null
+++ b/sinfoni/sinfo_file_handling.c
@@ -0,0 +1,68 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+#include <stdio.h>
+#include <string.h>
+#include "sinfo_file_handling.h"
+
+/**@{*/
+/**
+ * @addtogroup sinfo_utilities Function to handle files
+ *
+ * TBD
+ */
+
+/*----------------------------------------------------------------------------
+                                                        Function codes
+ ---------------------------------------------------------------------------*/
+
+
+/*-------------------------------------------------------------------------*/
+/**
+  @name     sinfo_file_exists
+  @memo     Find if a given file name corresponds to an existing file.
+  @param    filename    Name of the file to look up.
+  @return   int 1 if file exists, 0 if not
+  @doc
+
+  Find out if the given character string corresponds to a file that
+  can be stat()'ed.
+ */
+/*--------------------------------------------------------------------------*/
+
+
+int sinfo_file_exists(const char * filename)
+{
+  int exists=0;
+  FILE* fo=NULL;
+  if ((fo=fopen(filename,"r"))==NULL) {
+     exists=0;
+   } else {
+     exists=1;
+   }
+
+  if(fo!=NULL) {
+     fclose(fo);
+  }
+
+   return exists;
+}
+/**@}*/
diff --git a/sinfoni/sinfo_file_handling.h b/sinfoni/sinfo_file_handling.h
new file mode 100644
index 0000000..6e5c386
--- /dev/null
+++ b/sinfoni/sinfo_file_handling.h
@@ -0,0 +1,38 @@
+#ifndef SINFO_FILE_HANDLING_H
+#define SINFO_FILE_HANDLING_H
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*---------------------------------------------------------------------------
+                                                Function ANSI C prototypes
+ --------------------------------------------------------------------------*/
+
+/**
+  @name         sinfo_file_exists
+  @memo         Find if a given file name corresponds to an existing file.
+  @param        filename        Name of the file to look up.
+  @return       int 1 if file exists, 0 if not
+  @doc
+
+  Find out if the given character string corresponds to a file that
+  can be stat()'ed.
+ */
+int 
+sinfo_file_exists(const char * filename);
+
+#endif
diff --git a/sinfoni/sinfo_finddist_cfg.c b/sinfoni/sinfo_finddist_cfg.c
new file mode 100644
index 0000000..22f5ce4
--- /dev/null
+++ b/sinfoni/sinfo_finddist_cfg.c
@@ -0,0 +1,76 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*---------------------------------------------------------------------------
+   
+   File name     :    sinfo_wavecal_cfg.c
+   Author         : Juergen Schreiber
+   Created on    :    September 2001
+   Description    :    wavelength calibration configuration handling tools
+ *--------------------------------------------------------------------------*/
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+/*---------------------------------------------------------------------------
+                                   Includes
+ ---------------------------------------------------------------------------*/
+#include "sinfo_finddist_cfg.h"
+/**@{*/
+/**
+ * @defgroup sinfo_finddist_cfg functions to determine slitlets distances
+ *
+ * TBD
+ */
+
+/*---------------------------------------------------------------------------
+                              Function codes
+ ---------------------------------------------------------------------------*/
+/**
+   @name    sinfo_finddist_cfg_create()
+   @memo    allocate memory for a wave_cfg struct
+   @return  pointer to allocated base wave_cfg structure
+   @note    only the main (base) structure is allocated
+*/
+finddist_config * 
+sinfo_finddist_cfg_create(void)
+{
+    return cpl_calloc(1, sizeof(finddist_config));
+}
+
+/**
+   @name    sinfo_finddist_cfg_destroy()
+   @memo    deallocate all memory associated with a wave_config data structure
+   @param   wave_config to deallocate
+   @return  void
+*/
+
+void 
+sinfo_finddist_cfg_destroy(finddist_config * wc)
+{
+    if (wc==NULL) return ;
+
+    /* Free main struct */
+    cpl_free(wc);
+
+    return ;
+}
+/**@}*/
+
+
+
diff --git a/sinfoni/sinfo_finddist_cfg.h b/sinfoni/sinfo_finddist_cfg.h
new file mode 100644
index 0000000..c9f56e2
--- /dev/null
+++ b/sinfoni/sinfo_finddist_cfg.h
@@ -0,0 +1,155 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*---------------------------------------------------------------------------
+   
+   File name     :    sinfo_wavecal_cfg.h
+   Author         :    Juergen Schreiber
+   Created on    :    September 2001
+   Description    :    wavecal_ini definitions + handling prototypes
+
+ ---------------------------------------------------------------------------*/
+#ifndef SINFO_FINDDIST_CFG_H
+#define SINFO_FINDDIST_CFG_H
+/*---------------------------------------------------------------------------
+                                   Includes
+ ---------------------------------------------------------------------------*/
+#include "sinfo_globals.h"
+#include <cpl.h>
+/*---------------------------------------------------------------------------
+                                   Defines
+ ---------------------------------------------------------------------------*/
+/*---------------------------------------------------------------------------
+                                   New types
+ ---------------------------------------------------------------------------*/
+/*
+  Wavelength calibration blackboard container
+
+  This structure holds all information related to the wavelength calibration
+  routine. It is used as a container for the flux of ancillary data,
+  computed values, and algorithm status. Pixel flux is separated from
+  the blackboard.
+  */
+
+typedef struct finddist_config {
+/*-------General---------*/
+        char inFrame[FILE_NAME_SZ] ; /* input emission line frame */
+        char lineList[FILE_NAME_SZ] ; /* input wavelength and intensity 
+                                         line list */
+        char outName[FILE_NAME_SZ] ; /* output name of resulting fits 
+                                        wavelength map */
+        char nsFrame[FILE_NAME_SZ] ; /* input north-south frame */
+        char mask[FILE_NAME_SZ] ;    /* input north-south frame */
+        char fitsname[FILE_NAME_SZ] ;  
+        char drs_setup[FILE_NAME_SZ] ;  
+/*------ FindLines ------*/
+        /* estimated central wavelength of the image */
+        float guessBeginWavelength ;
+        /* estimated linear dispersion of emission line frame */
+        float guessDispersion1 ;
+        /* estimated square dispersion of emission line frame */
+        float guessDispersion2 ;
+        /* minimal difference of mean and sinfo_median column intensity */
+        float mindiff ;
+        /* half width of a box within which the line must sit */
+        int halfWidth ;
+        /* sigma of Gaussian of artificial model spectra */
+        float sigma ; 
+
+/*------ WaveCalib ------*/
+        /* guess value for fwhm of emission lines */ 
+        float fwhm ;
+        /* minimum amplitude of a line to be fitted */
+        float minAmplitude ;
+        /* maximal residual value for a valid fit */
+        float maxResidual ;
+        /* # of polynomial coefficients used for the dispersion relation */
+        int nrDispCoefficients ;
+        /* # of polynomial coefficients used for the fit of the dispersion 
+             coefficients */
+        int nrCoefCoefficients ;
+        /* minimal factor of the standard deviation of the fit coefficients */
+        float sigmaFactor ;
+        /* number of slitlets */
+        int    nslitlets ;
+        /* minimal pixel distance of slitlets in spectral direction */
+        int    pixeldist ;
+        /* allowed pixel position tolerance between estimated and 
+           fitted line position */
+        float  pixel_tolerance  ;
+
+/*------ WaveMap ------*/
+    /* magnifying factor for FFT */
+    int magFactor ;
+
+/*------ FitSlits ------*/
+    /* pixel length of the row box within which the fit of the 
+           slitlet positions is carried out*/
+    int boxLength ;
+        /* lower row position for the estimate fit */
+    int loPos ;
+        /* upper row position for the estimate fit */
+    int hiPos ;
+    /* float box half width in spectral direction */
+        float yBox ;
+        /* maximal tolerable difference to the expected slitlet positions */
+        float diffTol ;
+/*------ NorthSouthTest ------*/
+        /* number of slitlets */
+        int nslits ;      
+        /* pixel half width of a box within which the spatial 
+           profile is fitted by a Gaussian */
+        int nshalfWidth ;
+        /* first guess of the fwhm of the Gaussian fit function */
+        float nsfwhm ;
+        /* minimum amplitude above which the fit is carried out */
+        float minDiff ;
+        /* estimated average distance of spectra */
+        float estimated_dist ;
+        /* maximal pixel tolerance of the slitlet distances */
+        float devtol ;
+
+  /*----qg log --------*/
+  int qc_thresh_min;
+  int qc_thresh_max;
+
+
+} finddist_config ;
+/*---------------------------------------------------------------------------
+                               Function prototypes
+ ---------------------------------------------------------------------------*/
+/**
+   @name    sinfo_wave_cfg_create()
+   @memo    allocate memory for a wave_cfg struct
+   @return  pointer to allocated base wave_cfg structure
+   @note    only the main (base) structure is allocated
+*/
+
+finddist_config * 
+sinfo_finddist_cfg_create(void);
+
+/**
+   @name    sinfo_wave_cfg_destroy()
+   @memo    deallocate all memory associated with a wave_config data structure
+   @param   wave_config to deallocate
+   @return  void
+*/
+void 
+sinfo_finddist_cfg_destroy(finddist_config * jc);
+
+#endif
diff --git a/sinfoni/sinfo_finddist_ini.h b/sinfoni/sinfo_finddist_ini.h
new file mode 100644
index 0000000..0efef99
--- /dev/null
+++ b/sinfoni/sinfo_finddist_ini.h
@@ -0,0 +1,71 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+   
+   File name    :   sinfo_wavecal_ini.h
+   Author       :    Juergen Schreiber
+   Created on   :    Sept 14, 2001
+   Description  :    wavelength calibration ini file handling for SPIFFI
+ ---------------------------------------------------------------------------*/
+#ifndef SINFO_FINDDIST_INI_H
+#define SINFO_FINDDIST_INI_H
+/*---------------------------------------------------------------------------
+                                Includes
+---------------------------------------------------------------------------*/
+#include "sinfo_finddist_cfg.h"
+/*----------------------------------------------------------------------------
+                             Function prototypes 
+ ---------------------------------------------------------------------------*/
+/**
+  @name   generateWave_ini_file
+  @memo   Generate a default ini file for the wavelength calibration command.
+  @param  ini_name    Name of the file to generate.
+  @param  name_i        Name of the input file.
+  @param  name_o        Name of the output file.
+  @param  name_c        Name of the calibration file.
+  @return int 0 if Ok, -1 otherwise.
+  @doc          This function generates a default ini file for the wavelength 
+                calibration command. The generated file will have the requested
+                name. If you do not want to provide names for the 
+                input/output/calib files, feed either NULL pointers
+                or character strings starting with (char)0.
+ */
+
+int 
+generatefinddist_ini_file(
+        char * ini_name,
+        char * name_i,
+        char * name_o,
+        char * name_n,
+        char * name_c
+);
+
+/**
+  @name     parse_wave_ini_file
+  @memo     Parse a ini_name.ini file and create a blackboard.
+  @param    ini_name    Name of the ASCII file to parse.
+  @return   1 newly allocated wave_config blackboard structure.
+  @doc      The requested ini file is parsed and a blackboard object is 
+            created, then updated accordingly. Returns NULL in case of error.
+ */
+
+finddist_config * 
+parse_finddist_ini_file(char * ini_name) ;
+
+#endif
diff --git a/sinfoni/sinfo_finddist_ini_by_cpl.c b/sinfoni/sinfo_finddist_ini_by_cpl.c
new file mode 100644
index 0000000..855bba0
--- /dev/null
+++ b/sinfoni/sinfo_finddist_ini_by_cpl.c
@@ -0,0 +1,523 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+   
+   File name    :   sinfo_finddist_ini_by_cpl.c
+   Author       :   Andrea Modigliani
+   Created on   :   Aug 12, 2004
+   Description  :   distortion, slitlet distances, first column CPL input 
+                    handling for SINFONI
+ ---------------------------------------------------------------------------*/
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+/*---------------------------------------------------------------------------
+                                Includes
+ ---------------------------------------------------------------------------*/
+#include <string.h>
+#include "sinfo_finddist_ini_by_cpl.h"
+#include "sinfo_pro_types.h"
+#include "sinfo_hidden.h"
+#include "sinfo_raw_types.h"
+#include "sinfo_ref_types.h"
+/*---------------------------------------------------------------------------
+                    Functions private to this module
+ ---------------------------------------------------------------------------*/
+static void     
+parse_section_frames(finddist_config *, cpl_parameterlist* cpl_cfg, 
+                     cpl_frameset* sof, cpl_frameset** raw, int* status);
+static void     
+parse_section_findlines(finddist_config *, cpl_parameterlist* cpl_cfg);
+static void     
+parse_section_wavecalib(finddist_config *, cpl_parameterlist* cpl_cfg);
+static void     
+parse_section_wavemap(finddist_config *, cpl_parameterlist* cpl_cfg);
+static void     
+parse_section_fitslits(finddist_config *, cpl_parameterlist* cpl_cfg);
+static void     
+parse_section_northsouthtest(finddist_config *, cpl_parameterlist* cpl_cfg);
+static void     
+parse_section_qclog      (finddist_config * cfg, cpl_parameterlist* cpl_cfg);
+
+/**@{*/
+/**
+ * @addtogroup sinfo_finddist_cfg functions to determine slitlets distances
+ *
+ * TBD
+ */
+
+
+/**
+  @name     sinfo_parse_cpl_input_finddist
+  @memo     Parse CPL input.
+  @param    cpl_cfg   pointer to parameter list
+  @param    sof pointer to input set of frames
+  @param    raw pointer to input set of raw frames
+  @return   1 newly allocated wave_config blackboard structure.
+  @doc      The requested ini file is parsed and a blackboard object is 
+            created, then updated accordingly. Returns NULL in case of error.
+ */
+
+finddist_config * 
+sinfo_parse_cpl_input_finddist(cpl_parameterlist * cpl_cfg, 
+                               cpl_frameset* sof, 
+                               cpl_frameset** raw)
+{
+        finddist_config   *       cfg ;
+        int                   status =0;
+
+        cfg = sinfo_finddist_cfg_create();
+
+        parse_section_findlines (cfg, cpl_cfg);
+        parse_section_wavecalib (cfg, cpl_cfg);
+        parse_section_wavemap   (cfg, cpl_cfg); 
+        parse_section_fitslits  (cfg, cpl_cfg); 
+        parse_section_northsouthtest (cfg, cpl_cfg);
+        parse_section_qclog(cfg,cpl_cfg);
+        parse_section_frames   (cfg, cpl_cfg, sof, raw, &status);
+
+        if (status > 0) {
+                sinfo_msg_error("parsing cpl input");
+                sinfo_finddist_cfg_destroy(cfg);
+                cfg = NULL ;
+                return NULL ;
+        }
+        return cfg ;
+}
+
+
+/**
+  @name     parse_section_frames
+  @memo     Parse input frames
+  @param    cfg pointer to finddist_config structure
+  @param    cpl_cfg   pointer to parameter list
+  @param    sof pointer to input set of frames
+  @param    raw pointer to input set of raw frames
+  @param    status status of function
+  @return   1 newly allocated wave_config blackboard structure.
+ */
+
+static void     
+parse_section_frames(finddist_config * cfg,
+             cpl_parameterlist * cpl_cfg,
+             cpl_frameset * sof,
+                     cpl_frameset** raw,
+                     int* status)
+{
+
+
+
+   int nframes=0;
+   int nraw=0;
+   cpl_frame* frame   = NULL;
+   cpl_parameter *p; 
+
+
+   char spat_res[FILE_NAME_SZ];
+   char lamp_status[FILE_NAME_SZ];
+   char band[FILE_NAME_SZ];
+   int ins_set=0;
+   cpl_table* drs_tab=NULL;
+   wcal* w=NULL;
+   int check=0;
+   nstpar* nstp=NULL;
+   distpar* d=NULL;
+
+   d=sinfo_distpar_new();
+   w=sinfo_wcal_new();
+
+   nframes = cpl_frameset_get_size(sof);
+
+    /* Get the raw and the calibration files */
+
+
+   sinfo_extract_raw_frames_type(sof,raw,PRO_FIBRE_NS_STACKED);
+   
+
+   nraw=cpl_frameset_get_size(*raw);
+   if (nraw < 1) {
+      sinfo_msg_error("Too few (%d) raw frames (%s) present "
+                      "in frameset!Aborting...",nraw,PRO_FIBRE_NS_STACKED);
+        sinfo_distpar_delete(d);
+    sinfo_wcal_delete(w);
+          (*status)++;
+          return;
+   }
+
+
+   if(NULL != cpl_frameset_find(sof,PRO_WAVE_LAMP_STACKED)) {
+      frame = cpl_frameset_find(sof,PRO_WAVE_LAMP_STACKED);
+      strcpy(cfg -> inFrame,cpl_frame_get_filename(frame));
+   } else {
+      sinfo_msg_error("Frame %s not found! Exit!", PRO_WAVE_LAMP_STACKED);
+        sinfo_distpar_delete(d);
+    sinfo_wcal_delete(w);
+        (*status)++;
+      return;
+   }
+
+   strcpy(cfg -> outName, DISTORTION_OUT_FILENAME);
+
+
+   if(NULL != cpl_frameset_find(sof,REF_LINE_ARC)) {
+      frame = cpl_frameset_find(sof,REF_LINE_ARC);
+      strcpy(cfg -> lineList,cpl_frame_get_filename(frame));
+   } else {
+      sinfo_msg_error("Frame %s not found! Exit!", REF_LINE_ARC);
+        sinfo_distpar_delete(d);
+    sinfo_wcal_delete(w);
+        (*status)++;
+      return;
+   }
+
+   if(NULL != cpl_frameset_find(sof,PRO_FIBRE_NS_STACKED)) {
+      frame = cpl_frameset_find(sof,PRO_FIBRE_NS_STACKED);
+      strcpy(cfg -> nsFrame,cpl_frame_get_filename(frame));
+   } else {
+      sinfo_msg_error("Frame %s not found! Exit!", PRO_FIBRE_NS_STACKED);
+        sinfo_distpar_delete(d);
+    sinfo_wcal_delete(w);
+        (*status)++;
+      return;
+   }
+
+
+   if(NULL != cpl_frameset_find(sof,PRO_BP_MAP_DI)) {
+      frame = cpl_frameset_find(sof,PRO_BP_MAP_DI);
+      strcpy(cfg -> mask,cpl_frame_get_filename(frame));
+   } else {
+      sinfo_msg_error("Frame %s not found! Exit!", PRO_BP_MAP_DI);
+        sinfo_distpar_delete(d);
+    sinfo_wcal_delete(w);
+        (*status)++;
+      return;
+   }
+
+
+  
+   frame = cpl_frameset_get_frame(*raw,0);
+   sinfo_get_spatial_res(frame,spat_res);
+ 
+   switch(sinfo_frame_is_on(frame)) 
+     {
+   case 0: 
+      strcpy(lamp_status,"on");
+      break;
+    case 1: 
+      strcpy(lamp_status,"off");
+      break;
+    case -1:
+      strcpy(lamp_status,"undefined");
+      break;
+    default: 
+      strcpy(lamp_status,"undefined");
+      break;
+     }
+
+   sinfo_get_band(frame,band);
+   sinfo_msg("Spatial resolution: %s lamp_status: %s band: %s \n",
+                     spat_res,    lamp_status,    band);
+
+
+   sinfo_get_ins_set(band,&ins_set);
+    if(NULL != cpl_frameset_find(sof,DRS_SETUP_WAVE)) {
+     frame = cpl_frameset_find(sof,DRS_SETUP_WAVE);
+        strcpy(cfg -> drs_setup,cpl_frame_get_filename(frame));
+        drs_tab = cpl_table_load(cfg->drs_setup,1,0);
+        w->wstart=cpl_table_get_double(drs_tab,"W_START",ins_set,&check);
+        w->wgdisp1=cpl_table_get_double(drs_tab,"W_DISP1",ins_set,&check);
+        w->wgdisp2=cpl_table_get_double(drs_tab,"W_DISP2",ins_set,&check);
+        w->hw=cpl_table_get_int(drs_tab,"W_HW",ins_set,&check);
+        w->fwhm=cpl_table_get_double(drs_tab,"W_FWHM",ins_set,&check);
+        w->min_amp=cpl_table_get_double(drs_tab,"W_MIN_AMP",ins_set,&check);
+    /*
+        w->min_dif=cpl_table_get_double(drs_tab,"W_MIN_DIF",ins_set,&check);
+        w->na_coef=cpl_table_get_int(drs_tab,"W_NA_COEFF",ins_set,&check);
+        w->nb_coef=cpl_table_get_int(drs_tab,"W_NB_COEFF",ins_set,&check);
+        w->pixel_tol=cpl_table_get_double(drs_tab,"W_PIX_TOL",ins_set,&check);
+        w->y_box=cpl_table_get_double(drs_tab,"W_Y_BOX",ins_set,&check);
+    */
+        w->low_pos=cpl_table_get_int(drs_tab,"W_LOW_POS",ins_set,&check);
+        w->hig_pos=cpl_table_get_int(drs_tab,"W_HI_POS",ins_set,&check);
+
+    cfg -> guessBeginWavelength = w->wstart;
+    cfg -> guessDispersion1 =  w->wgdisp1;
+    cfg -> guessDispersion2 =  w->wgdisp2;
+    cfg -> halfWidth =         w->hw;
+    cfg -> fwhm =              w->fwhm;
+    cfg -> minAmplitude =      w->min_amp;
+    /*
+    cfg -> mindiff =           w->min_dif;
+    cfg -> nrDispCoefficients = w->na_coef;
+    cfg -> nrCoefCoefficients = w->nb_coef;
+    cfg -> pixel_tolerance =    w->pixel_tol;
+    cfg -> yBox =               w->y_box;
+    */
+    cfg -> loPos =              DISTORTION_LOPOS;
+    cfg -> hiPos =              DISTORTION_HIPOS;
+    cfg -> pixel_tolerance =    w->pixel_tol;
+        cfg-> diffTol = d->diff_tol[ins_set];
+	/*
+        sinfo_msg("cfg->guessBeginWavelength %g",cfg -> guessBeginWavelength);
+        sinfo_msg("cfg->guessDispersion1 %g",cfg -> guessDispersion1);
+        sinfo_msg("cfg->guessDispersion2 %g",cfg -> guessDispersion2);
+        sinfo_msg("cfg->mindiff %g",cfg -> mindiff);
+        sinfo_msg("cfg->halfWidth %d",cfg ->  halfWidth);
+        sinfo_msg("cfg->fwhm %g",cfg -> fwhm);
+        sinfo_msg("cfg->minAmplitude %g",cfg -> minAmplitude);
+        sinfo_msg("cfg->nrDispCoefficients %d",cfg -> nrDispCoefficients);
+        sinfo_msg("cfg->nrCoefCoefficients %d",cfg -> nrCoefCoefficients);
+        sinfo_msg("cfg->pixel_tolerance  %g",cfg -> pixel_tolerance);
+        sinfo_msg("cfg->loPos %d",cfg -> loPos);
+        sinfo_msg("cfg->hiPos %d",cfg -> hiPos);
+        sinfo_msg("cfg->yBox  %f",cfg -> yBox);
+	*/
+        sinfo_distpar_delete(d);
+    sinfo_wcal_delete(w);
+        cpl_table_delete(drs_tab);
+        if(-1 == sinfo_check_rec_status(0)) {
+      (*status)++;
+      return;
+    }
+
+   } else {
+    sinfo_msg_error("Frame %s not found! Exit!", DRS_SETUP_WAVE);
+        sinfo_distpar_delete(d);
+    sinfo_wcal_delete(w);
+        (*status)++;
+        return;
+   }
+
+
+   nstp=sinfo_nstpar_new();  
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.ns_fwhm");
+   if(cpl_parameter_get_default_flag(p) == 0) {
+      cfg->nsfwhm=nstp->fwhm[ins_set];
+   } else {
+      cfg->nsfwhm=cpl_parameter_get_double(p);
+   }
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.min_diff");
+   if(cpl_parameter_get_default_flag(p) == 0) {
+     cfg->minDiff=nstp->min_dif[ins_set];
+   } else {
+     cfg->minDiff=cpl_parameter_get_double(p);
+   }
+   sinfo_nstpar_delete(nstp);
+   //sinfo_msg("cfg -> nsfwhm  %f",cfg -> nsfwhm);
+   //sinfo_msg("cfg -> minDiff  %f",cfg -> minDiff);
+
+
+   return;
+
+}
+
+
+/**
+  @name     parse_section_findlines
+  @memo     Parse input findlines parameters
+  @param    cfg pointer to finddist_config structure
+  @param    cpl_cfg   pointer to parameter list
+  @return   void
+ */
+
+static void     
+parse_section_findlines(finddist_config * cfg,cpl_parameterlist * cpl_cfg)
+{
+
+   cpl_parameter* p;
+
+   p = cpl_parameterlist_find(cpl_cfg, 
+                              "sinfoni.distortion.min_diff_mean_med_col_int");
+   cfg -> mindiff =  cpl_parameter_get_double(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.half_width");
+   cfg -> halfWidth = cpl_parameter_get_int(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.sigma");
+   cfg -> sigma =  cpl_parameter_get_double(p);
+
+   return ;
+
+}
+
+/**
+  @name     parse_section_wavecalib
+  @memo     Parse input wavecalib parameters
+  @param    cfg pointer to finddist_config structure
+  @param    cpl_cfg   pointer to parameter list
+  @return   void
+ */
+static void     
+parse_section_wavecalib(finddist_config * cfg,cpl_parameterlist * cpl_cfg)
+{
+
+
+   cpl_parameter* p;
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.fwhm");
+   cfg -> fwhm =  cpl_parameter_get_double(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.min_amplitude");
+   cfg -> minAmplitude =  cpl_parameter_get_double(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.max_residual");
+   cfg -> maxResidual =  cpl_parameter_get_double(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.n_a_coefficients");
+   cfg -> nrDispCoefficients = cpl_parameter_get_int(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.n_b_coefficients");
+   cfg -> nrCoefCoefficients = cpl_parameter_get_int(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.sigma_factor");
+   cfg -> sigmaFactor =  cpl_parameter_get_double(p);
+
+
+   cfg -> nslitlets = NSLITLETS;
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.pixel_dist");
+   cfg -> pixeldist = cpl_parameter_get_int(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.pixel_tol");
+   cfg -> pixel_tolerance = cpl_parameter_get_double(p);
+
+
+
+}
+
+/**
+  @name     parse_section_wavemap
+  @memo     Parse input wavemap parameters
+  @param    cfg pointer to finddist_config structure
+  @param    cpl_cfg   pointer to parameter list
+  @return   void
+ */
+static void     
+parse_section_wavemap(finddist_config * cfg,cpl_parameterlist * cpl_cfg)
+{
+   cpl_parameter* p;
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.mag_factor");
+   cfg -> magFactor = cpl_parameter_get_int(p);
+
+}
+
+/**
+  @name     parse_section_findslits
+  @memo     Parse input findlists parameters
+  @param    cfg pointer to finddist_config structure
+  @param    cpl_cfg   pointer to parameter list
+  @return   void
+ */
+static void     
+parse_section_fitslits(finddist_config * cfg,cpl_parameterlist * cpl_cfg)
+{
+
+   cpl_parameter* p;
+
+   cfg -> loPos =  DISTORTION_LOPOS;
+   cfg -> hiPos =  DISTORTION_HIPOS;
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.box_length");
+   cfg -> boxLength = cpl_parameter_get_int(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.y_box");
+   cfg -> yBox = cpl_parameter_get_double(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.diff_tol");
+   cfg -> diffTol =  cpl_parameter_get_double(p);
+
+}
+
+/**
+  @name     parse_section_qclog
+  @memo     Parse input qclog parameters
+  @param    cfg pointer to finddist_config structure
+  @param    cpl_cfg   pointer to parameter list
+  @return   void
+ */
+static void     
+parse_section_qclog      (finddist_config * cfg, cpl_parameterlist* cpl_cfg)
+{
+   cpl_parameter* p;
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.qc_thresh_min");
+   cfg ->  qc_thresh_min = cpl_parameter_get_int(p);
+
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.qc_thresh_max");
+   cfg ->  qc_thresh_max = cpl_parameter_get_int(p);
+
+
+}
+
+
+/**
+  @name     parse_section_northsouthtest
+  @memo     Parse input northsouthtest parameters
+  @param    cfg pointer to finddist_config structure
+  @param    cpl_cfg   pointer to parameter list
+  @return   void
+ */
+static void     
+parse_section_northsouthtest(finddist_config * cfg,cpl_parameterlist * cpl_cfg)
+{
+
+   cpl_parameter *p;   
+   strcat(cfg -> fitsname, DISTORTION_NS_OUT_FILENAME);
+
+   cfg -> nslits = NSLITLETS;
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.ns_half_width");
+   cfg -> nshalfWidth = cpl_parameter_get_int(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.ns_fwhm");
+   cfg -> nsfwhm = cpl_parameter_get_double(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.min_diff");
+   cfg -> minDiff = cpl_parameter_get_double(p);
+
+   cfg -> estimated_dist = ESTIMATED_SLITLETS_DISTANCE;
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.dev_tol");
+   cfg -> devtol = cpl_parameter_get_double(p);
+
+   return ;
+
+}
+
+/**
+ @name sinfo_finddist_free
+ @memo deallocate finddist_config structure
+ @param cfg pointer to finddist_config structure
+ @return void
+*/
+
+void
+sinfo_finddist_free(finddist_config ** cfg)
+{  
+
+  if(*cfg!=NULL) {
+    sinfo_finddist_cfg_destroy(*cfg);
+    *cfg=NULL;
+  }
+  return;
+
+}
diff --git a/sinfoni/sinfo_finddist_ini_by_cpl.h b/sinfoni/sinfo_finddist_ini_by_cpl.h
new file mode 100644
index 0000000..5da9f6c
--- /dev/null
+++ b/sinfoni/sinfo_finddist_ini_by_cpl.h
@@ -0,0 +1,64 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+   
+   File name    :   sinfo_finddist_ini_by_cpl.h
+   Author       :   Andrea Modigliani
+   Created on   :   Aug 12, 2004
+   Description  :   Distortions, slitlets distances, 
+                    first column determination cpl input 
+                    parameters parsing for SINFONI
+ ---------------------------------------------------------------------------*/
+#ifndef SINFO_FINDDIST_INI_BY_CPL_H
+#define SINFO_FINDDIST_INI_BY_CPL_H
+/*---------------------------------------------------------------------------
+                                Includes
+---------------------------------------------------------------------------*/
+#include <cpl.h>
+#include "sinfo_functions.h"
+#include "sinfo_finddist_cfg.h"
+#include "sinfo_msg.h"
+/*----------------------------------------------------------------------------
+                             Function prototypes 
+ ---------------------------------------------------------------------------*/
+/**
+  @name     sinfo_parse_cpl_input_finddist
+  @memo     Parse CPL input.
+  @param    cpl_cfg   pointer to parameter list
+  @param    sof pointer to input set of frames
+  @param    raw pointer to input set of raw frames
+  @return   1 newly allocated wave_config blackboard structure.
+  @doc      The requested ini file is parsed and a blackboard object is 
+            created, then updated accordingly. Returns NULL in case of error.
+ */
+
+finddist_config * 
+sinfo_parse_cpl_input_finddist(cpl_parameterlist * cpl_cfg, 
+                               cpl_frameset* sof, 
+                   cpl_frameset** raw);
+/**
+ @name sinfo_finddist_free
+ @memo deallocate finddist_config structure
+ @param cfg pointer to finddist_config structure
+ @return void
+*/
+void 
+sinfo_finddist_free(finddist_config ** cfg);
+
+#endif
diff --git a/sinfoni/sinfo_fit.c b/sinfoni/sinfo_fit.c
new file mode 100644
index 0000000..8ec3988
--- /dev/null
+++ b/sinfoni/sinfo_fit.c
@@ -0,0 +1,395 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+#include <sinfo_fit.h>
+#include <sinfo_msg.h>
+#include <stdio.h>
+#include <math.h>
+/**@{*/
+/**
+ * @defgroup sinfo_fit Fit functions
+ *
+ * TBD
+ */
+
+
+static double 
+sinfo_spline(double x,
+             double cons[],
+             double ak[],
+             double *sp,
+             double *spp,
+             double *sppp,
+             int n);
+
+
+
+
+
+
+/**
+ at brief perform a amoeba minimization of the function ftbm(d2,ncon)
+ at param    d0 has nvar values, it is the average excluding the highest of d1
+ at param    d1 has nvar x nvar+1 values.  it is the simplex array of values
+ at param    d2 has ncons values at all times, it is the interface with ftbm
+ at param    value is the last nvar+1 values from ftbm
+ at param    range range of parameter varaiability
+ at param    tol   tolerance
+ at param    ivorf is 0 for fixed parameters, 1 for those varied.
+ at param    ncon
+ at param    nref is the maximum number of reflections
+ at param    ftbm function to be fit
+ at note     parameters begin varying as d2(i)+-range(i) 
+*/
+double 
+sinfo_amsub(double d0[],
+            double d1[],
+            double d2[],
+            double value[],
+            double range[],
+            double tol,
+            int ivorf[], 
+            int ncon,
+            int nref,
+            double(*ftbm)(double[],int ncon)) 
+
+{
+  double alpha=1.0,loc_gamma=1.5;
+  double sf,bsave,temp,sum,cval,ccval,beta;
+  int idone,nvar,nvec,nrefl,i,j,k,kd1,kval,isign,jvar,imin,imax,i2max,
+    it1,it2,itemp;
+  idone=0;
+  isign=1;
+  // we require that nvec=nvar+1, define nvar
+  nvar=0;
+ for(i=0;i<ncon;++i) {
+   if(ivorf[i] == 1) {
+      nvar=nvar+1;
+   }
+ }
+ nvec=nvar+1;
+ // sf is the 'shrink' factor
+ sf=1e5*nvec;
+ nrefl=0;
+ value[0]=(*ftbm)(d2,ncon);
+ // sinfo_msg("value[0] = %lg",value[0]);
+ // initial and shrink calculation of the d1 array, uses range
+ // set d2 in the first position -- using Fortran convention of 1st
+ // array element moving first
+ cont20:
+ kd1=-1;
+ for(i=0;i<ncon;++i) {
+   if(ivorf[i]==1) {
+     kd1=kd1+1;
+     d1[kd1]=d2[i];
+   }
+ }
+ // now for the next nvar values
+ kval=0;
+ for(jvar=0;jvar<ncon;++jvar) {
+   if(ivorf[jvar] == 1) {
+     kval=kval+1;
+     bsave=d2[jvar];
+     isign=-isign;
+     d2[jvar]=d2[jvar]+isign*range[jvar];
+     value[kval]=(*ftbm)(d2,ncon);
+     for(i=0;i<ncon;++i) {
+       if(ivorf[i]==1) {
+     kd1=kd1+1;
+         d1[kd1]=d2[i];
+       }
+     }
+     d2[jvar]=bsave;
+   }
+ }
+ // sinfo_msg(" d1 ");
+ // for (j=0;j<nvec;++j) {
+ //   for(i=0;i<nvar;++i) {
+ //     sinfo_msg("%12.4lg ",d1[i+j*nvar]);
+ //   }
+ // }
+ /* find highest, second highest, and minimum values
+    imax points to the vector with the largest value
+    i2max points to the vector with the second largest value
+    imin points to the vector with the smallest value  */
+ cont40:
+ imin=1;
+ if(value[0]>value[1]) {
+   imax=0;
+   i2max=1;
+ } else {
+   imax=1;
+   i2max=0;
+ }
+ for(i=0;i<nvec;++i) {
+   if(value[i]<value[imin]) imin=i;
+   if(value[i]>value[imax]) {
+     i2max=imax;
+     imax=i;
+   } else if( (value[i]>value[i2max]) && (i != imax) ) {
+       i2max=i;
+   }
+ }
+ // sinfo_msg(" values after sorting ");
+ // for(i=0;i<nvec;++i)sinfo_msg("%12.4lg ",value[i]);
+ // sinfo_msg("imin %d,i2max %d,imax %d",imin,i2max,imax); 
+ // scanf("%d",&itest);
+
+ // check if done
+
+ if(nrefl>=nref) {
+   sinfo_msg(" maximum number of reflection reached");
+   idone=1;
+   goto cont400;
+ }
+ if(value[imin]!=0.0) {
+   temp=(value[imax]-value[imin])/value[imin];
+   if(fabs(temp)<=tol) {
+     sinfo_msg(" reached tolerance %lg temp %lg tol",temp,tol);
+     idone=1;
+     goto cont400;
+   }
+ }
+ if(value[imax]-value[imin]<=tol) {
+    sinfo_msg("value[max]-value[min]<=tol");
+    idone=1;
+    goto cont400;
+ }
+    
+ // *** form d0 the average of all but imax
+ for(j=0;j<nvar;++j) {
+   sum=0.0;
+   for(i=0;i<nvec;++i) {
+      if(i!=imax)sum=sum+d1[i*nvar+j];
+   }
+   d0[j]=sum/(nvec-1);
+ }
+ // sinfo_msg(" D0 values ");
+ // for(i=0;i<nvar;++i)sinfo_msg("%12.4lg ",d0[i]);
+ // scanf("%d",&itest);
+ // reflection
+
+ nrefl=nrefl+1;
+ k=-1;
+ for(j=0;j<ncon;++j) {
+   if(ivorf[j]==1) {
+     k=k+1;
+     it1=imax*nvar+k;
+     d2[j]=(1+alpha)*d0[k]-alpha*d1[it1];
+   }
+ }
+
+ // sinfo_msg(" refl d2 ");
+ // for(i=0;i<nvar;++i) sinfo_msg("%12.4lg ",d2[i]);
+
+ cval=(*ftbm)(d2,ncon);
+ // sinfo_msg("refl ftbm %lg",cval);  
+
+ // value is higher than i2max so do contraction
+ if(cval>=value[i2max]) goto cont200;
+
+ // value is less than i2max - normal - update d1 and value
+
+ value[imax]=cval;
+ k=-1;
+ for(j=0;j<ncon;++j) {
+   if(ivorf[j]==1) {
+     k=k+1;
+     it1=imax*nvar+k;
+     d1[it1]=d2[j];
+   }
+ }
+
+ // value is less than imin, try expansion
+ if(cval<value[imin]) goto cont300;
+ goto cont40;
+
+ // contraction
+ cont200:
+ // sinfo_msg(" contraction ");
+ beta=0.75;
+ for(itemp=0;itemp<3;++itemp) {
+   if(cval<=value[imax]) {
+     value[imax]=cval;
+     k=-1;
+     for(j=0;j<ncon;++j) {
+       if(ivorf[j]==1) {
+         k=k+1;
+         it1=imax*nvar+k;
+         d1[it1]=d2[j];
+       }
+     }
+   }
+   k=-1;
+   for(j=0;j<ncon;++j) {
+     if(ivorf[j]==1) {
+       k=k+1;
+       it1=imax*nvar+k;
+       d2[j]=beta*d1[it1]+(1.-beta)*d0[k];
+     }
+   }
+   cval=ftbm(d2,ncon);
+
+   // sinfo_msg(" contraction beta %lg cval %lg ",beta,cval);
+   // value is better
+   if(cval<value[i2max]) {
+     value[imax]=cval;
+     k=-1;
+     for(j=0;j<ncon;++j) {
+       if(ivorf[j]==1) {
+         k=k+1;
+         it1=imax*nvar+k;
+         d1[it1]=d2[j];
+       }
+     }
+     if(cval<value[imin]) sinfo_msg(" contraction minimum %lg",cval);
+     goto cont40;
+   }
+   beta=beta-0.25;
+ }
+ sinfo_msg(" contraction failed  ==>shrink");
+ // scanf("%d",&itest);
+ // value is worse so shrink it
+
+ goto cont400;
+
+ // expansion
+
+ cont300:
+ sinfo_msg(" reflection min %lg \n", cval);
+ k=-1;
+ for(j=0;j<ncon;++j) {
+   if(ivorf[j]==1) {
+     k=k+1;
+     d2[j]=loc_gamma*d2[j]+(1.-loc_gamma)*d0[k];
+   }
+ }
+ ccval=(*ftbm)(d2,ncon);
+ // value is higher than reflected value ==> discard
+ if(ccval>cval) goto cont40;
+ // value is better so use it rather than the reflected point
+ sinfo_msg(" expansion minimum %lg \n",ccval);
+ value[imax]=ccval;
+ k=-1;
+ for(j=0;j<ncon;++j) {
+   if(ivorf[j]==1) {
+     k=k+1;
+     it1=imax*nvar+k;
+     d1[it1]=d2[j];
+   }
+ }
+ goto cont40;
+
+ cont400:
+ // sinfo_msg(" following cont400 ");
+ // scanf("%d",&itest);
+ // recalculate d2 and range
+ // the range is the average of dist**2 from d1 with min value
+ k=-1;
+ for(j=0;j<ncon;++j) {
+   if(ivorf[j]==1) {
+     k=k+1;
+     it1=imin*nvar+k;
+     d2[j]=d1[it1];
+     sum=0.0;
+     for(i=0;i<nvec;++i) {
+       it1=i*nvar+k;
+       it2=imin*nvar+k;
+       sum=sum+(d1[it1]-d1[it2])*(d1[it1]-d1[it2]);
+     }
+     range[j]=sf*sqrt(sum/(nvec-1));
+   }
+ }
+ value[1]=value[imin];
+ sf=.75*sf;
+ if(sf<0.1)idone=1;
+ sinfo_msg(" shrink factor %lg ",sf);
+ if(idone!=1)goto cont20;
+ return value[1];
+
+}
+
+static double 
+sinfo_spline(double x,
+             double cons[],
+             double ak[],
+             double *sp,
+             double *spp,
+             double *sppp,
+             int n)
+{
+double retval=0;
+double xm=0;
+double xm2=0;
+double xm3=0;
+
+int i=0;
+
+
+ *sp=0;
+ *spp=0;
+ *sppp=0;
+
+ for(i=0;i<n;++i) {
+   if(ak[i] >= x) {
+     xm=ak[i]-x;
+     xm2=xm*xm;
+     xm3=xm*xm2;
+     sinfo_msg("cons=%g",cons[i]);
+     retval+=cons[i]*xm3;
+     *sp-=3*cons[i]*xm2;
+     *spp+=6*cons[i]*xm;
+     *sppp-=6*cons[i];
+   }
+ }
+ sinfo_msg("1x=%g retval=%g",x,retval);
+ return retval;
+
+}
+
+
+
+
+double 
+sinfo_ftbm(const double x, double cons[])
+{
+  double retval=0;
+  double ak[4]={-1,-.666666666666666,-.333333333333,0};
+  double sm1=0;
+  double spm1=0;
+  double sppm1=0;
+  double spppm1=0;
+
+  int n=4;
+
+  sm1=sinfo_spline(x,cons,ak,&spm1,&sppm1,&spppm1,n)-1;
+  sinfo_msg("x=%g val=%g",x,sm1+1);
+
+  retval=sm1*sm1+spm1*spm1+sppm1*sppm1+spppm1*spppm1;
+  sinfo_msg("fitbm: x=%g retval=%g",x,retval);
+  
+  return retval;
+
+}
+
+
+
+/**@}*/
diff --git a/sinfoni/sinfo_fit.h b/sinfoni/sinfo_fit.h
new file mode 100644
index 0000000..bc66fb7
--- /dev/null
+++ b/sinfoni/sinfo_fit.h
@@ -0,0 +1,38 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+#ifndef SINFO_FIT_H
+#define SINFO_FIT_H
+double 
+sinfo_amsub(double d0[],
+            double d1[],
+            double d2[],
+            double value[],
+            double range[],
+            double tol,
+            int ivorf[], 
+            int ncon,
+            int nref,
+        double(*ftbm)(double[],int ncon));
+
+
+
+double 
+sinfo_ftbm(const double x, double cons[]);
+
+#endif
diff --git a/sinfoni/sinfo_fit_curve.c b/sinfoni/sinfo_fit_curve.c
new file mode 100644
index 0000000..1f6f1a8
--- /dev/null
+++ b/sinfoni/sinfo_fit_curve.c
@@ -0,0 +1,161 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*---------------------------------------------------------------------------
+   
+   File name     :    fit_curve.c
+   Author         :    N. Devillard
+   Created on    :    July 1998
+   Description    :    1d and 2d fit related routines
+
+ ---------------------------------------------------------------------------*/
+/*
+    $Id: sinfo_fit_curve.c,v 1.4 2012/03/02 08:42:20 amodigli Exp $
+    $Author: amodigli $
+    $Date: 2012/03/02 08:42:20 $
+    $Revision: 1.4 $
+*/
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+/*---------------------------------------------------------------------------
+                                   Includes
+ ---------------------------------------------------------------------------*/
+#include <math.h>
+#include "sinfo_fit_curve.h"
+#include "sinfo_ipow.h"
+/**@{*/
+/**
+ * @addtogroup sinfo_fit Fit functions
+ *
+ * TBD
+ */
+
+
+/*---------------------------------------------------------------------------
+                            Private functions
+ ---------------------------------------------------------------------------*/
+/*---------------------------------------------------------------------------
+                              Function codes
+ ---------------------------------------------------------------------------*/
+/**
+  @name        sinfo_fit_1d_poly
+  @memo        Fit a polynomial to a list of dpoints.
+  @param    poly_deg    Degree of the polynomial to fit.
+  @param    list        List of dpoints.
+  @param    np            Number of points in the list.
+  @param    mse            Output mean squared error.
+  @return    Array of (np+1) polynomial coefficients.
+  @doc
+
+  The fitted polynomial is such that:
+  \[
+    P(x) = c_0 + c_1 x + c_2 x^2 + ... + c_n x^n
+  \]
+  So requesting a polynomial of degree n will return n+1 coefficients.
+  Beware that with such polynomials, two input points shall never be
+  on the same vertical!
+
+  If you are not interested in getting the mean squared error back,
+  feed in NULL instead of a pointer to a double for mse.
+ */
+
+double *
+sinfo_fit_1d_poly(
+    int            poly_deg,
+    dpoint    *    list,
+    int            np,
+    double    *    mse
+)
+{
+    int            i, k ;
+    Matrix        mA, mB, mX ;
+    double    *    c ;
+    double        err ;
+    double        xp, y ;
+
+    if (np<poly_deg+1) {
+        sinfo_msg_error("not enough points") ;
+        sinfo_msg_error("cannot fit %dth degree polynomial with %d points",
+                poly_deg, np);
+        return NULL;
+    }
+
+    mA = sinfo_create_mx(poly_deg+1, np) ;
+    mB = sinfo_create_mx(1, np) ;
+
+    for (i=0 ; i<np ; i++) {
+        mA->m[i] = 1.0 ;
+        for (k=1 ; k<=poly_deg ; k++) {
+            mA->m[i+k*np] = sinfo_ipow(list[i].x, k) ;
+        }
+        mB->m[i] = list[i].y ;
+    }
+
+    /*
+     * Solve XA=B by a least-square solution (aka pseudo-inverse).
+     */
+    mX = sinfo_least_sq_mx(mA,mB) ;
+    /*
+     * Delete input matrices
+     */
+    sinfo_close_mx(mA) ;
+    sinfo_close_mx(mB) ;
+    /*
+     * Examine result
+     */
+    if (mX==NULL) {
+        sinfo_msg_error("cannot fit: non-invertible sinfo_matrix") ;
+        return NULL ;
+    }
+
+    c = cpl_malloc((poly_deg+1)*sizeof(double)) ;
+    for (i=0 ; i<(poly_deg+1) ; i++) {
+        c[i] = mX->m[i] ;
+    }
+    sinfo_close_mx(mX) ;
+
+    /*
+     * If requested, compute mean squared error
+     */
+    if (mse != NULL) {
+        err = 0.00 ;
+        for (i=0 ; i<np ; i++) {
+            y = c[0] ;
+            /*
+             * Compute the value obtained through the fit
+             */
+            for (k=1 ; k<=poly_deg ; k++) {
+                xp = sinfo_ipow(list[i].x, k) ;
+                y += c[k] * xp ; 
+            }
+            /*
+             * Subtract from the true value, square, accumulate
+             */
+            xp   = sinfo_ipow(list[i].y - y, 2) ;
+            err += xp ; 
+        }
+        /* Average the error term */
+        err /= (double)np ;
+        *mse = err ;
+    }
+    return c ;
+}
+
+
+/**@}*/
diff --git a/sinfoni/sinfo_fit_curve.h b/sinfoni/sinfo_fit_curve.h
new file mode 100644
index 0000000..7c8e5f2
--- /dev/null
+++ b/sinfoni/sinfo_fit_curve.h
@@ -0,0 +1,78 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*---------------------------------------------------------------------------
+   
+   File name     :    sinfo_fit_curve.h
+   Author         :    N. Devillard
+   Created on    :    July 1998
+   Description    :    1d and 2d fit related routines
+
+ *--------------------------------------------------------------------------*/
+
+/*
+    $Id: sinfo_fit_curve.h,v 1.4 2007/06/06 07:10:45 amodigli Exp $
+    $Author: amodigli $
+    $Date: 2007/06/06 07:10:45 $
+    $Revision: 1.4 $
+*/
+
+#ifndef SINFO_FIT_CURVE_H
+#define SINFO_FIT_CURVE_H
+/*---------------------------------------------------------------------------
+                                   Includes
+ ---------------------------------------------------------------------------*/
+#include "sinfo_matrix.h"
+#include "sinfo_local_types.h"
+#include "sinfo_msg.h"
+/*---------------------------------------------------------------------------
+                              Function codes
+ ---------------------------------------------------------------------------*/
+/*-------------------------------------------------------------------------*/
+/**
+  @name     sinfo_fit_1d_poly
+  @memo     Fit a polynomial to a list of dpoints.
+  @param    poly_deg    Degree of the polynomial to fit.
+  @param    list        List of dpoints.
+  @param    np          Number of points in the list.
+  @param    mse         Output mean squared error.
+  @return   Array of (np+1) polynomial coefficients.
+  @doc
+ 
+  The fitted polynomial is such that:
+  \[
+    P(x) = c_0 + c_1 x + c_2 x^2 + ... + c_n x^n
+  \]
+  So requesting a polynomial of degree n will return n+1 coefficients.
+  Beware that with such polynomials, two input points shall never be
+  on the same vertical!
+ 
+  If you are not interested in getting the mean squared error back,
+  feed in NULL instead of a pointer to a double for mse.
+ */
+/*--------------------------------------------------------------------------*/
+
+double *
+sinfo_fit_1d_poly(
+    int         poly_deg,
+    dpoint  *   list,
+    int         np,
+    double  *   mean_squared_error
+) ;
+
+#endif
diff --git a/sinfoni/sinfo_flat_cfg.c b/sinfoni/sinfo_flat_cfg.c
new file mode 100644
index 0000000..a94d201
--- /dev/null
+++ b/sinfoni/sinfo_flat_cfg.c
@@ -0,0 +1,80 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*---------------------------------------------------------------------------
+   
+   File name     :    sinfo_flat_cfg.c
+   Author         : Juergen Schreiber
+   Created on    :    March 2002
+   Description    :    prepare flatfield frames configuration handling tools
+ *--------------------------------------------------------------------------*/
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+/*---------------------------------------------------------------------------
+                                   Includes
+ ---------------------------------------------------------------------------*/
+#include "sinfo_flat_cfg.h"
+
+/**@{*/
+/**
+ * @defgroup sinfo_flat_cfg Flat manipulation functions
+ *
+ * TBD
+ */
+
+/*---------------------------------------------------------------------------
+                              Function codes
+ ---------------------------------------------------------------------------*/
+/**
+   @name    sinfo_flat_cfg_create()
+   @memo    allocate memory for a flat_cfg struct
+   @return  pointer to allocated base flat_cfg structure
+   @note    only the main (base) structure is allocated
+ */
+
+
+flat_config * sinfo_flat_cfg_create(void)
+{
+    return cpl_calloc(1, sizeof(flat_config));
+}
+/**
+   @name    sinfo_flat_cfg_destroy()
+   @memo    deallocate all memory associated with a flat_config data structure
+   @param   flat_config to deallocate
+   @return  void
+*/
+
+void sinfo_flat_cfg_destroy(flat_config * sc)
+{
+    if (sc==NULL) return ;
+
+    /* Free list of frame types */
+    /*cpl_free(sc->frametype);*/
+    /* Free positions */
+    /*cpl_free(sc->frameposition);*/
+
+    /* Free main struct */
+    cpl_free(sc);
+
+    return ;
+}
+/**@}*/
+
+
+
diff --git a/sinfoni/sinfo_flat_cfg.h b/sinfoni/sinfo_flat_cfg.h
new file mode 100644
index 0000000..9ece880
--- /dev/null
+++ b/sinfoni/sinfo_flat_cfg.h
@@ -0,0 +1,158 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*---------------------------------------------------------------------------
+   
+   File name     :    sinfo_flat_cfg.h
+   Author         :    Juergen Schreiber
+   Created on    :    march 2002
+   Description    :    flat_ini definitions + handling prototypes
+ ---------------------------------------------------------------------------*/
+#ifndef SINFO_FLAT_CFG_H
+#define SINFO_FLAT_CFG_H
+/*---------------------------------------------------------------------------
+                                   Includes
+ ---------------------------------------------------------------------------*/
+#include <stdlib.h>
+#include <cpl.h>
+#include "sinfo_globals.h"
+/*---------------------------------------------------------------------------
+                                   Defines
+ ---------------------------------------------------------------------------*/
+/*---------------------------------------------------------------------------
+                                   New types
+ ---------------------------------------------------------------------------*/
+/*
+  prepare lamp flat fields blackboard container
+
+  This structure holds all information related to the flatfield handling
+  routine. It is used as a container for the flux of ancillary data,
+  computed values, and algorithm status. Pixel flux is separated from
+  the blackboard.
+  */
+
+typedef struct flat_config {
+/*-------General---------*/
+        char inFile[FILE_NAME_SZ] ; /* file name of the file containing the 
+                                       list of all input frames */
+        char outName[FILE_NAME_SZ] ; /* output name of resulting fits 
+                                        wavelength map */
+        char ** framelist ; /* list of frames */
+        int  * frametype ; /* list of frame types on or off */
+        int  * frameposition ; /* list of grating positions */  
+        int    contains_sky ; /* indicates if off or sky frames were exposed */
+     int    contains_dither ; /* indicates if spectral dithering was applied */
+        int    nframes ; /* number of frames in frame list */
+        int    nobj ;  /* number of object frames in frame list */
+        int    noff ;  /* number of off frames in frame list */
+     int    nditherobj ; /* number of dithered object frames in frame list */
+        int    nditheroff ; /* number of dithered off frames in frame list */
+/*------ CleanMean ------*/
+        /* percentage of rejected low intensity pixels */
+        float loReject ;      
+        /* percentage of rejected high intensity pixels */
+        float hiReject ;
+/*------ BadPixel ------*/
+        /* indicator if the bad pixels of the flat field are known and 
+           if they should be interpolated or not */
+        int interpolInd ;
+        /* file name of the bad pixel mask fits file */
+        char mask[FILE_NAME_SZ] ;
+        /* maximal pixel distance from the bad pixel to which valid 
+           pixels are searched for*/ 
+        int maxRad ;
+        /* file name of the slitlet sinfo_edge position list */
+        char slitposList[FILE_NAME_SZ] ;
+/*------ BadPix ------*/
+        /* indicator if a bad pixel mask should be generated or not */
+        int badInd ;
+        /* name of the static bad pixel mask to be generated */
+        char maskname[FILE_NAME_SZ] ;
+        /* factor of noise within which the pixels are used to fit a 
+           straight line to the column intensity */
+        float sigmaFactor ;
+        /* factor of calculated standard deviation beyond which the 
+           deviation of a pixel value from the
+           median of the 8 nearest neighbors declares a pixel as bad */
+        float factor ;
+        /* number of iterations of sinfo_median filter */
+        int iterations ;
+        /* percentage of extreme pixel value to reject when calculating 
+           the mean and stdev */
+        float badLoReject ;
+        float badHiReject ;
+        /* pixel coordinate of lower left edge of a rectangle zone 
+           from which image statistics are computed */
+        int llx ;
+        int lly ;
+        /* pixel coordinate of upper right edge of a rectangle zone from 
+           which image statistics are computed */
+        int urx ;
+        int ury ;
+/*------ Thresh ------*/
+        /* indicates if the values beyond threshold values should be 
+           marked as bad before proceeding
+           to sinfo_median filtering */
+        int threshInd ;
+        /* factor to the clean standard deviation to define the 
+           threshold deviation from the clean mean */
+        float meanfactor ;
+
+
+  /* QC LOG */
+
+  /* FPN */
+  int qc_fpn_xmin1;
+  int qc_fpn_xmax1;
+  int qc_fpn_ymin1;
+  int qc_fpn_ymax1;
+
+  int qc_fpn_xmin2;
+  int qc_fpn_xmax2;
+  int qc_fpn_ymin2;
+  int qc_fpn_ymax2;
+
+  int qc_thresh_min;
+  int qc_thresh_max;
+
+
+} flat_config ;
+ 
+/*---------------------------------------------------------------------------
+                               Function prototypes
+ ---------------------------------------------------------------------------*/
+/**
+   @name    sinfo_flat_cfg_create()
+   @memo    allocate memory for a flat_cfg struct
+   @return  pointer to allocated base flat_cfg structure
+   @note    only the main (base) structure is allocated
+ */
+
+flat_config * 
+sinfo_flat_cfg_create(void);
+/**
+   @name    sinfo_flat_cfg_destroy()
+   @memo    deallocate all memory associated with a flat_config data structure
+   @param   flat_config to deallocate
+   @return  void
+*/
+
+void 
+sinfo_flat_cfg_destroy(flat_config * sc);
+
+#endif
diff --git a/sinfoni/sinfo_flat_ini.h b/sinfoni/sinfo_flat_ini.h
new file mode 100644
index 0000000..a351b88
--- /dev/null
+++ b/sinfoni/sinfo_flat_ini.h
@@ -0,0 +1,57 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+   
+   File name    :   sinfo_flat_ini.h
+   Author       :    Juergen Schreiber
+   Created on   :    Mar 04, 2002
+   Description  :    preparing flatfield ini file handling for SPIFFI
+ ---------------------------------------------------------------------------*/
+#ifndef SINFO_FLAT_INI_H
+#define SINFO_FLAT_INI_H
+/*---------------------------------------------------------------------------
+                                Includes
+---------------------------------------------------------------------------*/
+#include "sinfo_flat_cfg.h"
+#include <cpl.h>
+/*---------------------------------------------------------------------------
+                                Defines
+---------------------------------------------------------------------------*/
+#define FRAME_ON     1 /* object frames */
+#define FRAME_OFF    0 /* off frames, that means sky frames or 
+                          calibration frames with lamp switched off */
+#define FRAME_POS1   2 /* frames exposed with grating position 1 */
+#define FRAME_POS2   3 /* frames exposed with dithered grating position 2 */
+/*----------------------------------------------------------------------------
+                             Function prototypes 
+ ---------------------------------------------------------------------------*/
+
+/**
+  @name     parse_flat_ini_file
+  @memo     Parse a ini_name.ini file and create a blackboard.
+  @param    ini_name    Name of the ASCII file to parse.
+  @return   1 newly allocated flat_config blackboard structure.
+  @doc      The requested ini file is parsed and a blackboard object is 
+            created, then updated accordingly. Returns NULL in case of error.
+ */
+
+flat_config * 
+parse_flat_ini_file(char * ini_name) ;
+
+#endif
diff --git a/sinfoni/sinfo_flat_ini_by_cpl.c b/sinfoni/sinfo_flat_ini_by_cpl.c
new file mode 100644
index 0000000..24dddc3
--- /dev/null
+++ b/sinfoni/sinfo_flat_ini_by_cpl.c
@@ -0,0 +1,531 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+   
+   File name    :   sinfo_flat_ini_by_cpl.c
+   Author       :   Andrea Modigliani
+   Created on   :   May 19, 2004
+   Description  :   read cpl input for SPIFFI
+ ---------------------------------------------------------------------------*/
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+/*---------------------------------------------------------------------------
+                                Includes
+ ---------------------------------------------------------------------------*/
+#include <string.h>
+#include "sinfo_flat_ini_by_cpl.h"
+#include "sinfo_error.h"
+#include "sinfo_hidden.h"
+#include "sinfo_pro_types.h"
+#include "sinfo_raw_types.h"
+#include "sinfo_functions.h"
+#include "sinfo_file_handling.h"
+/*---------------------------------------------------------------------------
+                    Functions private to this module
+ ---------------------------------------------------------------------------*/
+void sinfo_flat_free_alloc(flat_config * cfg);
+static void 
+parse_section_frames(flat_config *, cpl_frameset* sof, 
+                     cpl_frameset** raw, int* status);
+static void parse_section_cleanmean(flat_config *, cpl_parameterlist* cpl_cfg);
+static void parse_section_badpixel(flat_config *, cpl_parameterlist* cpl_cfg);
+static void parse_section_badpix(flat_config *, cpl_parameterlist* cpl_cfg);
+static void parse_section_thresh(flat_config *, cpl_parameterlist* cpl_cfg);
+static void     
+parse_section_qclog(flat_config * cfg, cpl_parameterlist *   cpl_cfg);
+/**@{*/
+/**
+ * @addtogroup sinfo_flat_cfg Flat manipulation functions
+ *
+ * TBD
+ */
+
+
+
+/**
+  @name     sinfo_parse_cpl_input_flat
+  @memo     Parse input frames & parameters file and create a blackboard.
+  @param    cpl_cfg pointer to parameterlist
+  @param    sof pointer to input set of frames
+  @param    raw pointer to input set of raw frames
+  @return   1 newly allocated flat_config blackboard structure.
+  @doc
+
+  The requested ini file is parsed and a blackboard object is created, then
+  updated accordingly. Returns NULL in case of error.
+ */
+flat_config * 
+sinfo_parse_cpl_input_flat(cpl_parameterlist* cpl_cfg, 
+                                   cpl_frameset* sof, 
+                                   cpl_frameset** raw)
+{
+        flat_config   *       cfg = sinfo_flat_cfg_create();
+        int status=0;
+        /*
+         * Perform sanity checks, fill up the structure with what was
+         * found in the ini file
+         */
+        parse_section_badpixel  (cfg, cpl_cfg);
+        parse_section_cleanmean (cfg, cpl_cfg);
+        parse_section_badpix    (cfg, cpl_cfg);
+        parse_section_thresh    (cfg, cpl_cfg); 
+        parse_section_qclog     (cfg,cpl_cfg);
+      
+        parse_section_frames    (cfg, sof, raw,  &status);
+        if (status > 0) {
+                sinfo_msg_error("parsing cpl input");
+                sinfo_flat_cfg_destroy(cfg);
+                cfg = NULL ;
+                return NULL ;
+        }
+        return cfg ;
+}
+
+/**
+  @name     parse_section_frames
+  @memo     Parse input frames.
+  @param    cfg pointer to flat_config structure
+  @param    sof pointer to input set of frames
+  @param    raw pointer to input set of raw frames
+  @param    status status of function
+  @return   void.
+*/
+static void     
+parse_section_frames(flat_config * cfg,
+             cpl_frameset * sof,
+             cpl_frameset ** raw,
+                     int* status)
+{
+   int                     i;
+
+   char           *       name ;
+
+   int                     nobj, noff ;
+   int                     nditherobj, nditheroff ;
+   int                     found_sky ;
+   int                     found_dither ;
+   int nframes=0;
+   int nraw=0;
+   char* tag;
+   char spat_res[FILE_NAME_SZ];
+   char lamp_status[FILE_NAME_SZ];
+   char band[FILE_NAME_SZ];
+   int ins_set=0;
+
+   cpl_frame* frame   = NULL;
+
+
+   nframes = cpl_frameset_get_size(sof);
+
+   sinfo_extract_raw_frames_type(sof,raw,RAW_FLAT_LAMP);
+   nraw=cpl_frameset_get_size(*raw);
+
+   if (nraw==0) {
+      sinfo_extract_raw_frames_type(sof,raw,RAW_FLAT_NS);
+   }   
+
+
+   nraw=cpl_frameset_get_size(*raw);
+   if (nraw==0) {
+       sinfo_msg("Frame %s or %s not found!", RAW_FLAT_LAMP,RAW_FLAT_NS);
+       (*status)++;
+       return   ;
+   }
+
+   nraw  = cpl_frameset_get_size(*raw);
+
+   sinfo_msg("nraw=%d",nraw);
+   if(nraw<1) {
+     sinfo_msg_error("no good raw frame in input, something wrong!");
+     (*status)++;
+     return;
+   }
+
+   cknull_nomsg(frame = cpl_frameset_get_frame(*raw,0));
+
+   ck0_nomsg(sinfo_get_spatial_res(frame,spat_res));
+   switch(sinfo_frame_is_on(frame))
+     {
+
+    case 0: 
+      strcpy(lamp_status,"on");
+      break;
+    case 1: 
+      strcpy(lamp_status,"off");
+      break;
+    case -1:
+      strcpy(lamp_status,"undefined");
+      break;
+    default: 
+      strcpy(lamp_status,"undefined");
+      break;
+
+     }
+
+   sinfo_get_band(frame,band);
+   sinfo_msg("Spatial resolution: %s lamp status: %s band: %s \n",
+                     spat_res,              lamp_status,    band);
+
+   
+   sinfo_get_ins_set(band,&ins_set);
+
+
+   /* Allocate structures to go into the blackboard */
+   cfg->framelist     = cpl_malloc(nraw * sizeof(char*));
+   cfg->frametype     = cpl_malloc(nraw * sizeof(int));
+   cfg->frameposition = cpl_malloc(nraw * sizeof(int));
+
+   found_sky     = 0 ;
+   found_dither  = 0 ;
+   nobj          = 0 ;
+   noff          = 0 ;
+   nditheroff    = 0 ;
+   nditherobj    = 0 ;
+   for (i=0;i<nraw;i++) {
+     cfg->framelist[i]=NULL;
+     cfg->frametype[i]=-1;
+     cfg->frameposition[i]=-1;
+   }
+
+
+   cfg->nframes         = nraw ;
+    /* Browse through the charmatrix to get names and file types */
+   for (i=0 ; i<nraw ; i++) {
+      frame = cpl_frameset_get_frame(*raw,i);
+      name= (char*) cpl_frame_get_filename(frame);
+      if(sinfo_file_exists(name)==1) {
+    /* to go on the file must exist */
+    if(cpl_frame_get_tag(frame) != NULL) {
+      /* If the frame has a tag we process it. Else it is an object */ 
+      tag= (char*) cpl_frame_get_tag(frame);
+          /* sinfo_msg("frame %s tag =%s \n",name,tag); */
+          if((sinfo_frame_is_on(frame)  == 0) ||
+             (sinfo_frame_is_sky(frame)  == 1) ) 
+        {
+
+             cfg->framelist[i]=(char*) cpl_frame_get_filename(frame);
+             cfg->frametype[i] = FRAME_OFF ;
+             found_sky = 1;
+             if (sinfo_frame_is_dither(frame)) 
+           {
+                cfg->frameposition[i] = FRAME_POS2 ;
+                found_dither = 1 ;
+                nditheroff++ ;
+           }
+             else 
+           {
+                 cfg->frameposition[i] = FRAME_POS1 ;
+                 noff++ ;
+           }
+        }
+          else if(sinfo_frame_is_on(frame)  == 1) 
+        {
+           cfg->framelist[i]=(char*) cpl_frame_get_filename(frame);
+           cfg->frametype[i] = FRAME_ON ;
+          if (sinfo_frame_is_dither(frame))
+        {
+          cfg->frameposition[i] = FRAME_POS2 ;
+          found_dither = 1 ;
+          nditherobj++ ;
+        }
+              else 
+        {
+          cfg->frameposition[i] = FRAME_POS1 ;
+          nobj++ ;
+        }
+        }
+ 
+    }
+       
+        else 
+      {
+            /* No type means an object */
+            /* No type means position 1 */
+    /*
+        cfg->frametype[i] = FRAME_ON ;
+        cfg->frameposition[i] = FRAME_POS1 ;
+        nobj ++ ;
+    */
+      }
+      }
+      /* Store file name into framelist */
+      /* sinfo_msg("frame=%s\n",cfg->framelist[i]); */
+    }
+   
+   /*
+   sinfo_msg("Noff= %d Nobj= %d Nditheroff= %d Nditherobj= %d",
+                     noff,nobj,nditheroff,nditherobj);
+   */
+
+
+   if((nobj<1) && (nditherobj< 1)) {
+     sinfo_msg_error("no ON raw frame in input, something wrong!");
+     sinfo_flat_free_alloc(cfg);
+     (*status)++;
+     return;
+   }
+ 
+   /* Copy relevant information into the blackboard */
+   cfg->nobj            = nobj ;
+   cfg->noff            = noff ;
+   cfg->nditherobj      = nditherobj ;
+   cfg->nditheroff      = nditheroff ;
+   cfg->contains_sky    = found_sky ;
+   cfg->contains_dither = found_dither ;
+
+   strcpy(cfg -> outName, LAMP_FLATS_OUT_FILENAME);
+
+   if(cfg->interpolInd != 0) {
+
+      if(NULL != cpl_frameset_find(sof,PRO_BP_MAP)) {
+         frame = cpl_frameset_find(sof,PRO_BP_MAP);
+         strcpy(cfg -> mask,cpl_frame_get_filename(frame));
+         if(sinfo_file_exists(cfg->mask)==1) {
+         } else {
+            sinfo_msg_error("Filename %s for Frame %s not found!", 
+                       cfg->mask, PRO_BP_MAP);
+            sinfo_flat_free_alloc(cfg);
+            (*status)++;
+           return;
+ 
+         }
+
+      } else {
+        sinfo_msg_error("Frame %s not found!", PRO_BP_MAP);
+        sinfo_flat_free_alloc(cfg);
+        (*status)++;
+       return;
+      } 
+      if(NULL != cpl_frameset_find(sof,PRO_SLIT_POS)) {
+         frame = cpl_frameset_find(sof,PRO_SLIT_POS);
+         strcpy(cfg -> slitposList,cpl_frame_get_filename(frame));
+         if(sinfo_file_exists(cfg->mask) == 1) {
+         } else {
+            sinfo_msg_error("Filename %s for Frame %s not found!", 
+                       cfg->slitposList, PRO_SLIT_POS);
+            sinfo_flat_free_alloc(cfg);
+            (*status)++;
+            return;
+     }
+      } else {
+        sinfo_msg_error("Frame %s not found!", PRO_SLIT_POS);
+        sinfo_flat_free_alloc(cfg);
+        (*status)++;
+        return;
+      }
+
+   }
+
+  cleanup:
+
+   return;
+}
+
+/**
+  @name     parse_section_cleanmean
+  @memo     Parse cleanmean parameters.
+  @param    cfg pointer to flat_config structure
+  @param    cpl_cfg pointer to input cpl parameters
+  @return   void.
+*/
+static void     
+parse_section_cleanmean(flat_config * cfg, cpl_parameterlist * cpl_cfg)
+{
+   cpl_parameter *p; 
+  
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.low_rejection");
+   cfg -> loReject = cpl_parameter_get_double(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.high_rejection");
+   cfg -> hiReject = cpl_parameter_get_double(p);
+
+}
+
+/**
+  @name     parse_section_badpixel
+  @memo     Parse badpixel parameters.
+  @param    cfg pointer to flat_config structure
+  @param    cpl_cfg pointer to input cpl parameters
+  @return   void.
+*/
+static void     
+parse_section_badpixel(flat_config * cfg, cpl_parameterlist * cpl_cfg)
+{
+   cpl_parameter *p; 
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.interpol_index");
+   cfg -> interpolInd = cpl_parameter_get_bool(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.max_rad");
+   cfg -> maxRad =  cpl_parameter_get_int(p);
+
+}
+
+/**
+  @name     parse_section_badpix
+  @memo     Parse badpix parameters.
+  @param    cfg pointer to flat_config structure
+  @param    cpl_cfg pointer to input cpl parameters
+  @return   void.
+*/
+static void     
+parse_section_badpix(flat_config * cfg, cpl_parameterlist * cpl_cfg)
+{
+
+   cpl_parameter* p;
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.bad_ind");
+   cfg ->  badInd = cpl_parameter_get_bool(p);
+
+   strcpy(cfg -> maskname, LAMP_FLATS_OUT_BPMAP);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.sigma_factor");
+   cfg -> sigmaFactor = cpl_parameter_get_double(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.factor");
+   cfg -> factor = cpl_parameter_get_double(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.iterations");
+   cfg -> iterations = cpl_parameter_get_int(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.bad_low_rejection");
+   cfg -> badLoReject = cpl_parameter_get_double(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.bad_high_rejection");
+   cfg -> badHiReject = cpl_parameter_get_double(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.llx");
+   cfg -> llx = cpl_parameter_get_int(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.lly");
+   cfg -> lly = cpl_parameter_get_int(p);
+ 
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.urx");
+   cfg -> urx = cpl_parameter_get_int(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.ury");
+   cfg -> ury = cpl_parameter_get_int(p);
+
+}
+
+/**
+  @name     parse_section_thresh
+  @memo     Parse thresh parameters.
+  @param    cfg pointer to flat_config structure
+  @param    cpl_cfg pointer to input cpl parameters
+  @return   void.
+*/
+static void     
+parse_section_thresh(flat_config * cfg,cpl_parameterlist* cpl_cfg)
+{
+
+   cpl_parameter* p;
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.thresh_ind");
+   cfg -> threshInd =cpl_parameter_get_bool(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.mean_factor");
+   cfg -> meanfactor = cpl_parameter_get_double(p);
+
+
+}
+
+
+/**
+  @name     parse_section_qclog
+  @memo     Parse qclog parameters.
+  @param    cfg pointer to flat_config structure
+  @param    cpl_cfg pointer to input cpl parameters
+  @return   void.
+*/
+static void     
+parse_section_qclog(flat_config * cfg, cpl_parameterlist *   cpl_cfg)
+{
+   cpl_parameter *p;  
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.qc_fpn_xmin1");
+   cfg -> qc_fpn_xmin1 = cpl_parameter_get_int(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.qc_fpn_xmax1");
+   cfg -> qc_fpn_xmax1 = cpl_parameter_get_int(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.qc_fpn_ymin1");
+   cfg -> qc_fpn_ymin1 = cpl_parameter_get_int(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.qc_fpn_ymax1");
+   cfg -> qc_fpn_ymax1 = cpl_parameter_get_int(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.qc_fpn_xmin2");
+   cfg -> qc_fpn_xmin2 = cpl_parameter_get_int(p);
+   
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.qc_fpn_xmax2");
+   cfg -> qc_fpn_xmax2 = cpl_parameter_get_int(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.qc_fpn_ymin2");
+   cfg -> qc_fpn_ymin2 = cpl_parameter_get_int(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.qc_fpn_ymax2");
+   cfg -> qc_fpn_ymax2 = cpl_parameter_get_int(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.qc_thresh_min");
+   cfg -> qc_thresh_min = cpl_parameter_get_int(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.qc_thresh_max");
+   cfg -> qc_thresh_max = cpl_parameter_get_int(p);
+
+}
+/**
+ at name sinfo_flat_free
+ at memo free flat_config structure
+ at param cfg pointer to flat_config structure
+ at return void
+*/
+
+void
+sinfo_flat_free(flat_config ** cfg)
+{  
+  if ((*cfg) != NULL) {
+    sinfo_flat_free_alloc(*cfg);
+    sinfo_flat_cfg_destroy(*cfg);
+    *cfg=NULL;
+  }
+  return;
+
+}
+/**
+ at name sinfo_flat_allog
+ at memo free flat_config structure
+ at param cfg pointer to flat_config structure
+ at return void
+*/
+
+void 
+sinfo_flat_free_alloc(flat_config * cfg)
+{
+  if(cfg->frametype != NULL){
+       cpl_free(cfg->frametype); 
+  }
+  if(cfg->framelist != NULL) {
+     cpl_free(cfg->framelist);
+  }
+  if(cfg->frameposition != NULL) {
+     cpl_free(cfg->frameposition);
+  }
+return ;
+}
diff --git a/sinfoni/sinfo_flat_ini_by_cpl.h b/sinfoni/sinfo_flat_ini_by_cpl.h
new file mode 100644
index 0000000..382eb7e
--- /dev/null
+++ b/sinfoni/sinfo_flat_ini_by_cpl.h
@@ -0,0 +1,71 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+   
+   File name    :   sinfo_flat_ini.h
+   Author       :   Andrea Modigliani
+   Created on   :   Mar 04, 2004
+   Description  :   flatfield cpl_input handling for SPIFFI
+ ---------------------------------------------------------------------------*/
+#ifndef SINFO_FLAT_INI_BY_CPL_H
+#define SINFO_FLAT_INI_BY_CPL_H
+/*---------------------------------------------------------------------------
+                                Includes
+---------------------------------------------------------------------------*/
+#include <cpl.h>
+#include "sinfo_flat_cfg.h"
+#include "sinfo_msg.h"
+/*---------------------------------------------------------------------------
+                                Defines
+---------------------------------------------------------------------------*/
+#define FRAME_ON     1 /* object frames */
+#define FRAME_OFF    0 /* off frames, that means sky frames or 
+                          calibration frames with lamp switched off */
+#define FRAME_POS1   2 /* frames exposed with grating position 1 */
+#define FRAME_POS2   3 /* frames exposed with dithered grating position 2 */
+/*----------------------------------------------------------------------------
+                             Function prototypes 
+ ---------------------------------------------------------------------------*/
+
+/**
+  @name     sinfo_parse_cpl_input_flat
+  @memo     Parse input frames & parameters file and create a blackboard.
+  @param    cpl_cfg pointer to parameterlist
+  @param    sof pointer to input set of frames
+  @param    raw pointer to input set of raw frames
+  @return   1 newly allocated flat_config blackboard structure.
+  @doc
+
+  The requested ini file is parsed and a blackboard object is created, then
+  updated accordingly. Returns NULL in case of error.
+ */
+flat_config * 
+sinfo_parse_cpl_input_flat(cpl_parameterlist * cpl_cfg, 
+               cpl_frameset* sof, 
+                           cpl_frameset** raw) ;
+
+/**
+ at name sinfo_flat_free
+ at memo free flat_config structure
+ at param cfg pointer to flat_config structure
+ at return void
+*/
+void sinfo_flat_free(flat_config ** cfg);
+
+#endif
diff --git a/sinfoni/sinfo_focus.c b/sinfoni/sinfo_focus.c
new file mode 100644
index 0000000..ca1f122
--- /dev/null
+++ b/sinfoni/sinfo_focus.c
@@ -0,0 +1,1578 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*******************************************************************************
+* E.S.O. - VLT project
+*
+*
+*
+* who       when      what
+* --------  --------  ----------------------------------------------
+* schreib  16/01/02  created
+*/
+
+/************************************************************************
+*   NAME
+*        sinfo_focus.c -
+*        routines to determine the focus position of the detector
+*
+*   SYNOPSIS
+*   #include "sinfo_focus.h"
+*
+*   1) double sinfo_new_gaussian_ellipse ( double * xdat, double * parlist )
+*   2) void sinfo_new_gaussian_ellipse_deriv( double * xdat, 
+                                              double * parlist, 
+                                              double * dervs )
+*   3) static int new_inv_mat (void)
+*   4) static void new_get_mat ( double * xdat,
+*                            int    * xdim,
+*                            double * ydat,
+*                            double * wdat,
+*                            int    * ndat,
+*                            double * fpar,
+*                            double * epar,
+*                            int    * npar )
+*   5) static int new_get_vec ( double * xdat,
+*                           int    * xdim,
+*                           double * ydat,
+*                           double * wdat,
+*                           int    * ndat,
+*                           double * fpar,
+*                           double * epar,
+*                           int    * npar )
+*   6) int new_lsqfit ( double * xdat,
+*                   int    * xdim,
+*                   double * ydat,
+*                   double * wdat,
+*                   int    * ndat,
+*                   double * fpar,
+*                   double * epar,
+*                   int    * mpar,
+*                   int    * npar,
+*                   double * tol ,
+*                   int    * its ,
+*                   double * lab  )
+*   7) int sinfo_new_fit_2d_gaussian( cpl_image   * lineImage, 
+*                         double     * fit_par, 
+*                         double     * derv_par   
+*                         int        * mpar,
+*                         int          lleftx,
+*                         int          llefty,
+*                         int          halfbox_x,
+*                         int          halfbox_y, int* check )
+*   8) cpl_image * sinfo_new_plot_gaussian ( cpl_image   * image, 
+*                                double     * parlist )
+*   9) static int new_gauss2ellipse ( double     * parlist ,
+*  10) float sinfo_new_determine_conversion_factor ( cpl_imagelist * cube, 
+*                                        float     mag,
+*                                        float     exptime,
+*                                        int       lleftx,
+*                                        int       llefty,
+*                                        int       halfbox_x,
+*                                        int       halfbox_y, 
+*                                        int* check )
+*
+*   DESCRIPTION
+*   1) Compute the value of a 2d Gaussian function at a given point.
+*      The ellptical 2D Gaussian is:
+*      F(x,y) = par(2) * EXP( -4.0*log(2.0)*[(xr/par(4))^2+(yr/par(5))^2]) + 
+                par(3),
+*      where: xr = xo * cos(par(6)) + yo * sin(par(6))
+*      yr = -xo * sin(par(6)) + yo * cos(par(6))
+*      and:   x0 = x - par(0)
+*             y0 = y - par(1)
+*   2) calculates the partial derivatives for a 2d Gaussian function with
+*      parameters parlist at position xdat 
+*   3) calculates the inverse of matrix2. The algorithm used 
+*      is the Gauss-Jordan algorithm described in Stoer,
+*      Numerische Mathematik, 1. Teil.
+*   4) builds the sinfo_matrix 
+*   5) calculates the correction sinfo_vector. The sinfo_matrix has been
+*      built by get_mat(), we only have to rescale it for the 
+*      current value of labda. The sinfo_matrix is rescaled so that
+*      the diagonal gets the value 1 + labda.
+*      Next we calculate the inverse of the sinfo_matrix and then
+*      the correction sinfo_vector.
+*   6) this is a routine for making a least-squares fit of a
+*      function to a set of data points. The method used is
+*      described in: Marquardt, J.Soc.Ind.Appl.Math. 11. 431 (1963).
+*      This method is a mixture of the steepest descent method 
+*      and the Taylor method.
+*   7) fits the image of a point source by using a 2-D Gaussian
+*      fit.
+*   8) plots an image of a given 2D-Gaussian 
+*   9) converts gauss parameters to ellipse parameters. 
+*  10) determines an intensity conversion factor for the instrument
+*      by fitting a 2D-Gaussian to an collapsed image of a standard star
+*      with known brightness (only for non-AO observations).
+*      Then the resulting Gaussian is integrated and the counts
+*      are divided by the exposure time (Fits header information) 
+*
+*   FILES
+*
+*   ENVIRONMENT
+*
+*   RETURN VALUES
+*
+*   CAUTIONS
+*
+*   EXAMPLES
+*
+*   SEE ALSO
+*
+*   BUGS
+*
+*------------------------------------------------------------------------
+*/
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+#include "sinfo_vltPort.h"
+
+/*
+ * System Headers
+ */
+
+/*
+ * Local Headers
+ */
+
+#include "sinfo_focus.h"
+#include "sinfo_recipes.h"
+#include <float.h>
+
+/*----------------------------------------------------------------------------
+ *                                 Defines
+ *--------------------------------------------------------------------------*/
+
+#define XDIMG          2         /* dimension of the x values */
+#define TOLG           0.001     /* fitting tolerance */
+#define LABG           0.1       /* labda parameter */
+#define ITSG           200       /* maximum number of iterations */
+#define LABFACG        10.0      /* labda step factor */
+#define LABMAXG        1.0e+10   /* maximum value for labda */
+#define LABMING        1.0e-10   /* minimum value for labda */
+#define NPAR           7         /* number of fit parameters */
+#define PI_NUMB        (3.1415926535897932384626433832795) /* pi */
+
+
+/*----------------------------------------------------------------------------
+ *                                    Local variables
+ *--------------------------------------------------------------------------*/
+
+static double chi1 ;                    /* old reduced chi-squared */
+static double chi2 ;                    /* new reduced chi-squared */
+static double labda ;                   /* mixing parameter */
+static double vec[NPAR] ;               /* correction sinfo_vector */
+static double matrix1[NPAR][NPAR] ;     /* original sinfo_matrix */
+static double matrix2[NPAR][NPAR] ;     /* inverse of matrix1 */
+static int    nfree ;                   /* number of free parameters */
+static int    parptr[NPAR] ;            /* parameter pointer */
+
+/*----------------------------------------------------------------------------
+ *                    Functions private to this module
+ *--------------------------------------------------------------------------*/
+
+static int new_inv_mat (void) ;
+
+static void new_get_mat ( double * xdat,
+                      int    * xdim,
+                      double * ydat,
+                      double * wdat,
+                      int    * ndat,
+                      double * fpar,
+                      double * epar/*,
+                      int    * npar */) ;
+
+static int new_get_vec ( double * xdat,
+                     int    * xdim,
+                     double * ydat,
+                     double * wdat,
+                     int    * ndat,
+                     double * fpar,
+                     double * epar,
+                     int    * npar ) ;
+
+static int new_gauss2Ellipse ( double  * parlist ) ;
+/**@{*/
+/**
+ * @defgroup sinfo_focus Focus determination functions
+ *
+ * TBD
+ */
+
+
+/*----------------------------------------------------------------------------
+ *                            Function codes
+ *--------------------------------------------------------------------------*/
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief Compute the value of a 2d Gaussian function at a given point.
+  @param xdat    position array
+  @param parlist parameters array:
+
+  # parlist[0]:     center of Gaussian in x direction
+  # parlist[1]:     center of Gaussian in y direction
+  # parlist[2]:     Amplitude of the 2d Gaussian
+  # parlist[3]:     Background level
+  # parlist[4]:     FWHMx, fwhm of the axis of the ellipse near the x-axis
+  # parlist[5]:     FWHMy, fwhm of the axis of the ellipse near the y-axis
+  # parlist[6]:     theta, position angle of the fwhmx line (-PI/4 to PI/4)
+ 
+  @return           double value of the 2d Gaussian at position xdat.
+
+  Compute the value of a 2d Gaussian function at a given point.
+  The ellptical 2D Gaussian is:
+  F(x,y) = par(2) * EXP( -4.0*log(2.0)*[(xr/par(4))^2+(yr/par(5))^2]) + par(3),
+  where: xr = x0 * cos(par(6)) + y0 * sin(par(6))
+         yr = -x0 * sin(par(6)) + y0 * cos(par(6))
+  and:   x0 = x - par(0)
+         y0 = y - par(1)
+ */
+/*--------------------------------------------------------------------------*/
+
+double sinfo_new_gaussian_ellipse(double * xdat, double * parlist)
+{
+    double  result ;
+    double x ;
+    double y ;
+    double fwhmx ;
+    double fwhmy ;
+    double costheta ;
+    double sintheta ;
+    double argX ;           /* arguments in the exponent */
+    double argY ;
+
+    /* some abbreviations */
+    x =  xdat[0] -  parlist[0] ;
+    y =  xdat[1] -  parlist[1] ;
+
+    fwhmx = fabs(parlist[4]) ;
+    fwhmy = fabs(parlist[5]) ;
+    
+    costheta = cos ( parlist[6] ) ;
+    sintheta = sin ( parlist[6] ) ;
+
+    argX = x * costheta + y * sintheta ;
+    argY = -x * sintheta + y * costheta ;
+    
+    /* function */
+    result =  parlist[2] * exp(-4.*log(2.0)*((argX/fwhmx)*(argX/fwhmx)+
+                                             (argY/fwhmy)*(argY/fwhmy))) +
+              parlist[3] ; 
+
+    return result ;
+}
+
+/**
+   @brief calculates the partial derivatives for a 2d Gaussian i
+          function with parameters parlist at position xdat
+   @param xdat    positiona array
+   @param parlist parameter list:
+   #                     parlist(0): center of Gaussian in x direction
+   #                     parlist(1): center of Gaussian in y direction
+   #                     parlist(2): Amplitude of 2d Gaussian
+   #                     parlist(3): Background level
+   #                     parlist(4): FWHMx
+   #                     parlist(5): FWHMy
+   #                     parlist(6): theta
+   @param dervs  derivative value of a 2d Gaussian function at position xdat:
+   #                     dervs[0]: partial derivative by center x
+   #                     dervs[1]: partial derivative by center y 
+   #                     dervs[2]: partial derivative by the amplitude
+   #                     dervs[3]: partial derivative by the background
+   #                     dervs[4]: partial derivative by FWHMx 
+   #                     dervs[5]: partial derivative by FWHMy
+   #                     dervs[6]: partial derivative by theta
+  @return nothing, void
+
+*/
+
+void 
+sinfo_new_gaussian_ellipse_deriv(double * xdat, 
+                                 double * parlist, 
+                                 double * dervs )
+{
+    double x ;
+    double y ;
+    double fwhmx ;
+    double fwhmy ;
+    double argX ;
+    double argY ;
+    double expon ;
+    double e8log2 ;
+    double fwx2 ;
+    double fwy2 ;
+    double costheta ;
+    double sintheta ;
+
+    /* some abbreviations */
+    x = xdat[0] - parlist[0] ;
+    y = xdat[1] - parlist[1] ;
+
+    fwhmx = fabs(parlist[4]) ;
+    fwhmy = fabs(parlist[5]) ;
+    fwx2 = fwhmx * fwhmx ;
+    fwy2 = fwhmy * fwhmy ;
+
+    costheta = cos ( parlist[6] ) ;
+    sintheta = sin ( parlist[6] ) ;
+
+    argX = x * costheta + y * sintheta ;
+    argY = -x * sintheta + y * costheta ;
+
+    expon = exp ( -4.0 * log(2.0) * ((argX/fwhmx)*(argX/fwhmx) + 
+                                     (argY/fwhmy)*(argY/fwhmy)) ) ;
+    e8log2 = expon * 8.0 * log(2.0) ;
+
+    /* determine the derivatives */
+    /* partial derivative x-position */
+    dervs[0] = -parlist[2]*e8log2 * (-argX*costheta/fwx2 + argY*sintheta/fwy2);
+    /* partial derivative y-position */
+    dervs[1] = -parlist[2]*e8log2 * (-argX*sintheta/fwx2 - argY*costheta/fwy2);
+    /* partial derivative amplitude */
+    dervs[2] = expon ;
+    /* partial derivative background */
+    dervs[3] = 1. ;
+    /* partial derivative fwhmx */
+    dervs[4] = parlist[2]*e8log2 * argX*argX/(fwx2*fwhmx) ;
+    /* partial derivative fwhmy */
+    dervs[5] = parlist[2]*e8log2 * argY*argY/(fwy2*fwhmy) ;
+    /* partial derivative theta */
+    dervs[6] = -parlist[2]*e8log2 * argY * argX * (1.0/fwx2 - 1.0/fwy2) ;
+    
+}
+
+/**
+ at brief Calculates the inverse of matrix2.
+   
+   
+   @return integer (0 if it worked, -6 if determinant is zero) 
+   
+   The algorithm used is the Gauss-Jordan algorithm described in Stoer,
+   Numerische Mathematik, 1. Teil.
+ */
+
+static int new_inv_mat (void)
+{
+    double even ;
+    double hv[NPAR] ;
+    double mjk ;
+    double rowmax ;
+    int evin ;
+    int i, j, k, row ;
+    int per[NPAR] ;
+   
+    /* set permutation array */
+    for ( i = 0 ; i < nfree ; i++ )
+    {
+        per[i] = i ;
+    }
+    
+    for ( j = 0 ; j < nfree ; j++ ) /* in j-th column */
+    {
+        /* determine largest element of a row */                                
+        rowmax = fabs ( matrix2[j][j] ) ;
+        row = j ;                         
+
+        for ( i = j + 1 ; i < nfree ; i++ )
+        {
+            if ( fabs ( matrix2[i][j] ) > rowmax )
+            {
+                rowmax = fabs( matrix2[i][j] ) ;
+                row = i ;
+            }
+        }
+
+        /* determinant is zero! */
+        if ( matrix2[row][j] == 0.0 )
+        {
+            return -6 ;
+        }
+        
+        /* if the largest element is not on the diagonal, 
+           then permutate rows */
+        if ( row > j )
+        {
+            for ( k = 0 ; k < nfree ; k++ )
+            {
+                even = matrix2[j][k] ;
+                matrix2[j][k] = matrix2[row][k] ;
+                matrix2[row][k] = even ;
+            }
+            /* keep track of permutation */
+            evin = per[j] ;
+            per[j] = per[row] ;
+            per[row] = evin ;
+        }
+        
+        /* modify column */
+        even = 1.0 / matrix2[j][j] ;
+        for ( i = 0 ; i < nfree ; i++ )
+        {
+            matrix2[i][j] *= even ;
+        }
+        matrix2[j][j] = even ;
+        
+        for ( k = 0 ; k < j ; k++ )
+        {
+            mjk = matrix2[j][k] ;
+            for ( i = 0 ; i < j ; i++ )
+            {
+                matrix2[i][k] -= matrix2[i][j] * mjk ;
+            }
+            for ( i = j + 1 ; i < nfree ; i++ )
+            {
+                matrix2[i][k] -= matrix2[i][j] * mjk ;
+            }
+            matrix2[j][k] = -even * mjk ;
+        }
+    
+        for ( k = j + 1 ; k < nfree ; k++ )
+        {
+            mjk = matrix2[j][k] ;
+            for ( i = 0 ; i < j ; i++ )
+            {
+                matrix2[i][k]  -= matrix2[i][j] * mjk ;
+            }
+            for ( i = j + 1 ; i < nfree ; i++ )
+            {
+                matrix2[i][k]  -= matrix2[i][j] * mjk ;
+            }
+            matrix2[j][k] = -even * mjk ;
+        }
+    }
+    
+    /* finally, repermute the columns */
+    for ( i = 0 ; i < nfree ; i++ )
+    {
+        for ( k = 0 ; k < nfree ; k++ )
+        {
+            hv[per[k]] = matrix2[i][k] ;
+        }
+        for ( k = 0 ; k < nfree ; k++ )
+        {
+            matrix2[i][k] = hv[k] ;
+        }
+    }
+        
+    /* all is well */
+    return 0 ;
+}
+    
+/**
+ at brief build the matrix
+   
+   @param xdat: position
+   @param xdim: factor of the indices of the position array
+   @param ydat: real data
+   @param wdat: weights
+   @param ndat: number of data points
+   @param fpar: function parameters
+   @param epar: partial derivatives of the function
+   @param npar: number of function parameters
+   @return void
+    
+ */
+
+static void new_get_mat ( double * xdat,
+                      int    * xdim,
+                      double * ydat,
+                      double * wdat,
+                      int    * ndat,
+                      double * fpar,
+                      double * epar/*,
+                      int    * npar */)
+{
+    double wd ;
+    double wn ;
+    double yd ;
+    int i, j, n ;
+
+    for ( j = 0 ; j < nfree ; j++ )
+    {
+        vec[j] = 0.0 ; /* zero sinfo_vector */
+        for ( i = 0 ; i<= j ; i++ )   /* zero sinfo_matrix only on 
+                                         and below diagonal */
+        {
+            matrix1[j][i] = 0.0 ;
+        }
+    }
+    chi2 = 0.0 ;  /* reset reduced chi-squared */
+    
+    /* loop through data points */
+    for ( n = 0 ; n < (*ndat) ; n++ )
+    {
+        wn = wdat[n] ;
+        if ( wn > 0.0 )  /* legal weight ? */
+        {
+            yd=ydat[n] - sinfo_new_gaussian_ellipse(&xdat[(*xdim) * n],fpar) ;
+            sinfo_new_gaussian_ellipse_deriv( &xdat[(*xdim) * n], fpar, epar ) ;
+            chi2 += yd * yd * wn ; /* add to chi-squared */
+            for ( j = 0 ; j < nfree ; j++ )
+            {
+                wd = epar[parptr[j]] * wn ;  /* weighted derivative */
+                vec[j] += yd * wd ;       /* fill sinfo_vector */
+                for ( i = 0 ; i <= j ; i++ ) /* fill sinfo_matrix */
+                {
+                    matrix1[j][i] += epar[parptr[i]] * wd ;
+                }
+            }
+        }
+    }                   
+}  
+                
+            
+/**
+ at brief Computes the correction vector
+  
+  @param xdat: position
+  @param xdim: factor of the indices of the position array
+  @param ydat: real data
+  @param wdat: weights
+  @param ndat: number of data points
+  @param fpar: function parameters
+  @param epar: partial derivatives of the function
+  @param npar: number of function parameters
+
+  @return integer (
+          # 0 if it had worked, 
+          # -5 or -7 if diagonal element is wrong, or 
+          # -6, if determinant is zero 
+          )
+ 
+
+calculates the correction sinfo_vector. The sinfo_matrix has been
+built by get_mat(), we only have to rescale it for the current value of labda. 
+The sinfo_matrix is rescaled so that the diagonal gets the value 1 + labda.
+Next we calculate the inverse of the matrix and then the correction vector.
+ */
+            
+static int new_get_vec ( double * xdat,
+                     int    * xdim,
+                     double * ydat,
+                     double * wdat,
+                     int    * ndat,
+                     double * fpar,
+                     double * epar,
+                     int    * npar )
+{
+    double dj ;
+    double dy ;
+    double mii ;
+    double mji ;
+    double mjj ;
+    double wn ;
+    int i, j, n, r ;
+
+    /* loop to modify and scale the sinfo_matrix */
+    for ( j = 0 ; j < nfree ; j++ )
+    {
+        mjj = matrix1[j][j] ;
+        if ( mjj <= 0.0 )             /* diagonal element wrong */
+        {
+            return -5 ;
+        }
+        mjj = sqrt( mjj ) ;
+        for ( i = 0 ; i < j ; i++ )
+        {
+            mji = matrix1[j][i] / mjj / sqrt( matrix1[i][i] ) ;
+            matrix2[i][j] = matrix2[j][i] = mji ;
+        }
+        matrix2[j][j] = 1.0 + labda ;  /* scaled value on diagonal */
+    }    
+    
+    if ( (r = new_inv_mat()) ) /* sinfo_invert sinfo_matrix inlace */
+    {
+        return r ;
+    }
+    
+    for ( i = 0 ; i < (*npar) ; i ++ )
+    {
+        epar[i] = fpar[i] ;
+    }
+    
+    /* loop to calculate correction sinfo_vector */
+    for ( j = 0 ; j < nfree ; j++ )
+    {
+        dj = 0.0 ;
+        mjj = matrix1[j][j] ;
+        if ( mjj <= 0.0)               /* not allowed */
+        {
+            return -7 ;
+        }
+        mjj = sqrt ( mjj ) ;
+        for ( i = 0 ; i < nfree ; i++ )
+        {
+            mii = matrix1[i][i] ;
+            if ( mii <= 0.0 )
+            {
+                return -7 ;
+            }
+            mii = sqrt( mii ) ;
+            dj += vec[i] * matrix2[j][i] / mjj / mii ;
+        }
+        epar[parptr[j]] += dj ;       /* new parameters */
+    }    
+    chi1 = 0.0 ;                      /* reset reduced chi-squared */
+ 
+    /* loop through the data points */
+    for ( n = 0 ; n < (*ndat) ; n++ )
+    {
+        wn = wdat[n] ;               /* get weight */
+        if ( wn > 0.0 )              /* legal weight */
+        {
+            dy=ydat[n] - sinfo_new_gaussian_ellipse(&xdat[(*xdim) * n],epar);
+            chi1 += wdat[n] * dy * dy ;
+        }
+    }
+    return 0 ;
+}   
+    
+        
+
+/**
+ at brief Least-squares fit of a function to a set of data points.
+   
+   @param xdat: position, coordinates of data points.
+                xdat is 2 dimensional: XDAT ( XDIMG, NDAT )
+   @param xdim: dimension of fit
+   @param ydat: data points
+   @param wdat: weights for data points
+   @param ndat: number of data points
+   @param fpar: on input contains initial estimates of the parameters for 
+                non-linear fits, on output the fitted parameters.
+   @param epar: contains estimates of the errors in fitted parameters
+   @param mpar: logical mask telling which parameters are free (non-zero)
+                              and which parameters are fixed (0)
+   @param npar: number of function parameters ( free + fixed )
+   @param tol:  relative tolerance. sinfo_lsqfit stops when successive 
+                iterations
+                fail to produce a decrement in reduced chi-squared less
+                than tol. If tol is less than the minimum tolerance 
+                possible, tol will be set to this value. This means
+                that maximum accuracy can be obtained by setting tol = 0.0.
+   @param its:  maximum number of iterations
+   @param lab:  mixing parameter, lab determines the initial weight
+                of steepest descent method relative to the Taylor method
+                lab should be a small value (i.e. 0.01). lab can only
+                be zero when the partial derivatives are independent
+                of the parameters. In fact in this case lab should be
+                exactly equal to zero.
+
+   @return returns number of iterations needed to achieve convergence according 
+           to tol. When this number is negative, the fitting was not continued
+           because a fatal error occurred:
+           #             -1 too many free parameters, maximum is 32
+           #             -2 no free parameters
+           #             -3 not enough degrees of freedom
+           #             -4 maximum number of iterations too small to obtain
+                           a solution which satisfies tol.
+           #             -5 diagonal of matrix contains elements which are zero
+           #             -6 determinant of the coefficient matrix is zero
+           #             -7 square root of a negative number 
+   
+ This is a routine for making a least-squares fit of a function to a set of 
+ data points. The method used is described in: 
+ Marquardt, J.Soc.Ind.Appl.Math. 11. 431 (1963).
+ This method is a mixture of the steepest descent method and the Taylor method.
+ */
+
+int sinfo_new_lsqfitd ( double * xdat,
+              int    * xdim,
+              double * ydat,
+              double * wdat,
+              int    * ndat,
+              double * fpar,
+              double * epar,
+              int    * mpar,
+              int    * npar,
+              double * tol ,
+              int    * its ,
+              double * lab  )
+{
+    int i, n, r ;
+    int itc ;                      /* fate of fit */
+    int found ;                    /* fit converged: 1, not yet converged: 0 */
+    int  nuse ;                    /* number of useable data points */
+    double tolerance ;             /* accuracy */
+
+    itc   = 0 ;                    /* fate of fit */
+    found = 0 ;                    /* reset */
+    nfree = 0 ;                    /* number of free parameters */
+    nuse  = 0 ;                    /* number of legal data points */
+
+    if ( *tol < (DBL_EPSILON * 10.0 ) )
+    {
+        tolerance = DBL_EPSILON * 10.0 ;  /* default tolerance */
+    }
+    else
+    {
+        tolerance = *tol ;                /* tolerance */
+    }
+    
+    labda = fabs( *lab ) * LABFACG ; /* start value for mixing parameter */
+    for ( i = 0 ; i < (*npar) ; i++ )
+    {
+        if ( mpar[i] )
+        {
+            if ( nfree > NPAR )         /* too many free parameters */
+            {
+                return -1 ;
+            }
+            parptr[nfree++] = i ;         /* a free parameter */
+        }
+    }
+    
+    if (nfree == 0)                       /* no free parameters */     
+    {
+        return -2 ;
+    }
+    
+    for ( n = 0 ; n < (*ndat) ; n++ )
+    {
+        if ( wdat[n] > 0.0 )              /* legal weight */
+        {
+            nuse ++ ;
+        }
+    }
+    
+    if ( nfree >= nuse )
+    {
+        return -3 ;                       /* no degrees of freedom */
+    }
+    if ( labda == 0.0 )                   /* linear fit */
+    {
+        /* initialize fpar array */
+        for ( i = 0 ; i < nfree ; fpar[parptr[i++]] = 0.0 ) ;  
+        new_get_mat ( xdat, xdim, ydat, wdat, ndat, fpar, epar/*, npar */) ;
+        r =  new_get_vec ( xdat, xdim, ydat, wdat, ndat, fpar, epar, npar ) ;
+        if ( r )                         /* error */
+        {
+            return r ;
+        }
+        for ( i = 0 ; i < (*npar) ; i++ )
+        {
+            fpar[i] = epar[i] ;           /* save new parameters */
+            epar[i] = 0.0 ;               /* and set errors to zero */
+        }
+        chi1 = sqrt( chi1 / (double) (nuse - nfree) ) ;
+        for ( i = 0 ; i < nfree ; i++ )
+        {
+            if ( (matrix1[i][i] <= 0.0 ) || (matrix2[i][i] <= 0.0) )
+            {
+                return -7 ;
+            }
+            epar[parptr[i]] = chi1 * sqrt( matrix2[i][i] ) / 
+                                     sqrt( matrix1[i][i] ) ;
+        }
+    }
+    else                                  /* non-linear fit */
+    {
+        /*----------------------------------------------------------------
+         * the non-linear fit uses the steepest descent method in combination
+         * with the Taylor method. The mixing of these methods is controlled
+         * by labda. In the outer loop ( called the iteration loop ) we build
+         * the matrix and calculate the correction sinfo_vector. In the 
+           inner loop
+         * (called the interpolation loop) we check whether we have obtained a
+         * better solution than the previous one. If so, we leave the inner loop
+         * else we increase lambda ( give more weight to the steepest descent 
+         * method) calculate the correction vector and check again. After the 
+         * inner loop
+         * we do a final check on the goodness of the fit and if this satisfies
+         * the tolerance we calculate the errors of the fitted parameters.
+         */
+        while ( !found )                  /* iteration loop */
+        {      
+            if ( itc++ == (*its) )        /* increase iteration counter */
+            {
+                return -4 ;               
+            }
+            new_get_mat( xdat, xdim, ydat, wdat, ndat, fpar, epar/*, npar*/ ) ;
+            
+            /*-------------------------------------------------------------
+             * here we decrease labda since we may assume that each iteration
+             * brings us closer to the answer.
+             */
+            if ( labda > LABMING )
+            {
+                labda = labda / LABFACG ;         /* decrease labda */
+            }
+            r = new_get_vec ( xdat, xdim, ydat, wdat, ndat, fpar, epar, npar ) ;
+
+            if ( r )                      /* error */
+            {
+                return r ;
+            }
+
+            while ( chi1 >= chi2 )        /* interpolation loop */
+            {
+                /*-----------------------------------------------------------
+                 * The next statement is based on experience, not on the 
+                 * mathematics of the problem. It is assumed that we have 
+                 * reached convergence when the pure steepest descent method 
+                 * does not produce a better solution.
+                 */
+                if ( labda > LABMAXG )    /* assume solution found */
+                {
+                    break ;
+                }
+                labda = labda * LABFACG ; /* increase mixing parameter */
+                r = new_get_vec(xdat,xdim,ydat,wdat,ndat,fpar,epar,npar) ;
+
+                if ( r )                  /* error */
+                {
+                    return r ;
+                }
+            }
+
+            if ( labda <= LABMAXG )        /* save old parameters */
+            {
+                for ( i = 0 ; i < *npar ; i++ )
+                {
+                    fpar[i] = epar[i] ;
+                }
+            }
+            if ( (fabs( chi2 - chi1 ) <= (tolerance * chi1)) || 
+                      (labda > LABMAXG) )
+            {
+                /*-----------------------------------------------------------
+                 * we have a satisfying solution, so now we need to calculate 
+                 * the correct errors of the fitted parameters. This we do by 
+                 * using the pure Taylor
+                 * method because we are very close to the real solution.
+                 */
+                labda = LABMING ;              /* for Taylor solution */
+                new_get_mat(xdat,xdim,ydat,wdat,ndat,fpar,epar/*, npar */) ;
+                r=new_get_vec(xdat,xdim,ydat,wdat,ndat,fpar,epar,npar ) ;
+
+                if ( r )                    /* error */
+                {
+                    return r ;
+                }
+                for ( i = 0 ; i < (*npar) ; i++ )
+                {
+                    epar[i] = 0.0 ;          /* set error to zero */
+                }
+                chi2 = sqrt ( chi2 / (double) (nuse - nfree) ) ;
+
+                for ( i = 0 ; i < nfree ; i++ )
+                {
+                    if ( (matrix1[i][i] <= 0.0) || (matrix2[i][i] <= 0.0) )
+                    {
+                        return -7 ;
+                    }
+                    epar[parptr[i]] = chi2 * sqrt( matrix2[i][i] ) / 
+                                             sqrt( matrix1[i][i] ) ;
+                }
+                found = 1 ;                  /* we found a solution */
+            }
+        }
+    }
+    return itc ;                             /* return number of iterations */
+}
+
+/**
+  @brief fits the image of a point source by using a 2-D Gaussian fit.
+   
+  @param image reconstructed image of a point source 
+  @param fit_par    array of 7 free fit parameters of a 2D-Gauss
+  @param derv_par   derivatives of the fit_par array
+  @param mpar       mask to set free parameters, 1: free, 0: fixed. 
+  @param lleftx     lower left starting point of the box in which the fit is 
+                    carried throught to find the maximum of point source image
+  @param llefty     lower left starting point of the box in which the fit is 
+                    carried throught to find the maximum of point source image
+  @param halfbox_x  half box length in x-direction in pixels inside which 
+                    the fit is carried through
+  @param halfbox_y  half box length in y-direction in pixels inside 
+                    which the fit is carried through
+
+  @param check      check switch (start at 0 and is increased in case of 
+                    failure
+  @return number of needed iterations
+          #              -1 if an error occurred.
+   
+  Remark on the fit results for the fit parameters 
+  (fwhmx and fwhmy and theta): 
+  theta will always be between -PI/4 and +PI/4, exchange of the fwhmx and fwhmy
+  values corresponds to a shift of theta by PI/2. Consequently, an expected 
+  theta > |PI/4| will result in an exchange of the fwhm values and a shift of 
+  theta by PI/2 to a value < |PI/4| what yields exactly the same image.
+ */
+
+int 
+sinfo_new_fit_2d_gaussian ( cpl_image   * image, 
+                    double     * fit_par, 
+                    double     * derv_par,   
+                    int        * mpar,
+                    int          lleftx,
+                    int          llefty,
+                    int          halfbox_x,
+                    int          halfbox_y, 
+                    int* check )
+{
+    int i, j, n ;
+    int col, row ;
+    int boxi, boxj ;
+    int iters ;
+    int ndata ;
+    int xdim ;
+    int npar ;
+    int its ;
+    double lab ;
+    double tol ;
+    double maxval ;
+    double background ;
+    double amplitude ;
+    float * backarray=NULL ;
+    double M, Mx, My ;
+    double Mxx, Mxy, Myy ; 
+    double X0, Y0 ;
+    double xydat[4 *halfbox_x*halfbox_y][XDIMG] ;
+    double zdat[4*halfbox_x*halfbox_y] ;
+    double wdat[4*halfbox_x*halfbox_y] ;
+    double xco, yco ;
+    double value ;
+    double denom ;
+    double temp ;
+    int llx, lly ;
+    int foundrow ;
+    int foundcol ;
+    int k ;
+    int ilx=0;
+    int ily=0;
+    float* pidata=NULL;
+
+
+    if ( NULL == image )
+    {
+        sinfo_msg_error("no image given") ;
+        return -1 ;
+    }
+    ilx=cpl_image_get_size_x(image);
+    ily=cpl_image_get_size_y(image);
+
+    if ( NULL == fit_par )
+    {
+        sinfo_msg_error("no fit parameters given") ;
+        return -1 ;
+    }
+    if ( NULL == derv_par )
+    {
+        sinfo_msg_error("no derivatives of fit parameters given") ;
+        return -1 ;
+    }
+    if ( lleftx < 0 || lleftx + 2*halfbox_x >= ilx ||
+         llefty < 0 || llefty + 2*halfbox_y >= ily )
+    {
+        sinfo_msg_error("wrong lower left point of fitting box given!") ;
+        return -1 ;
+    }
+    if ( halfbox_x <= 1 || halfbox_y <= 1 )
+    {
+        sinfo_msg_error("wrong box dimensions given") ;
+        return -1 ;
+    }
+    /* allocate memory */
+    if ( NULL == (backarray = (float*) cpl_calloc(4*halfbox_x+4*halfbox_y, 
+                  sizeof(float) ) ) ) 
+    {
+        sinfo_msg_error("could not allocate memory") ;
+        return -1 ;
+    }
+
+    /* -------------------------------------------------------------------
+     * find the initial estimates for the free parameters
+     */
+
+    /* first search for the position of the maximum intensity */
+    foundrow = 0 ;
+    foundcol = 0 ;
+    maxval   = -SINFO_DBL_MAX ;
+    pidata=cpl_image_get_data_float(image);
+    for ( col = lleftx ; col < lleftx + 2*halfbox_x ; col++ )
+    {
+        for ( row = llefty ; row < llefty + 2*halfbox_y ; row++ )
+        {
+            if ( isnan(pidata[col+row*ilx]) )
+            {
+                continue ;
+            }
+            if ( maxval < pidata[col+row*ilx] ) 
+            {
+                maxval = pidata[col+row*ilx] ;
+                foundrow = row ;
+                foundcol = col ;
+            }
+        }
+    }
+
+    if ( foundrow == 0 || foundcol == 0 || maxval <= 0. ||
+         foundrow == ilx-1 || foundcol == ily-1 )
+    {
+        sinfo_msg_warning("no maximum found") ;
+        cpl_free(backarray) ;
+        return -1 ;
+    }
+
+    /* determine the lower left sinfo_edge of the fitting box, center it 
+       on the maximum value */
+    llx = foundcol - halfbox_x ;
+    lly = foundrow - halfbox_y ;
+    if ((foundcol - halfbox_x) > 0) {
+      llx = (foundcol - halfbox_x);
+    } else {
+      llx=1;
+      check++;
+    }
+
+    if ((foundrow - halfbox_y) > 0) {
+      lly = (foundrow - halfbox_y);
+    } else {
+      lly=1;
+      check++;
+    } 
+
+    if ( ( llx + 2*halfbox_x) <  ilx-1 ) {
+      halfbox_x=halfbox_x;
+    } else {
+       halfbox_x=(int) (ilx-2-llx)/2;
+      check++;
+    }
+
+    if ( ( lly + 2*halfbox_y) <  ily-1 ) {
+      halfbox_y= halfbox_y;
+    } else {
+      halfbox_y=(int) (ily-2-lly)/2;
+      check++;
+    }
+
+    if ( llx <= 0 || lly < 0 || llx + 2*halfbox_x >= ilx-1 ||
+         lly + 2*halfbox_y >= ily )
+    {
+        sinfo_msg_error("box does not fit into image") ;
+        cpl_free(backarray) ;
+        return -1 ;
+    }
+    
+    /* determine the zeroth and first order moments of the image  
+       within the fitting box */ 
+    M = Mx = My = 0. ;
+    n = 0 ;
+    boxi = boxj = 0 ;
+    for ( j = lly ; j < lly + 2*halfbox_y ; j++ )
+    {
+        boxj = j - lly ;
+        for ( i = llx ; i < llx + 2*halfbox_x ; i++ )
+        {
+            boxi = i - llx ;
+            if ( !isnan(pidata[i+j*ilx]) )
+            {
+                M  += pidata[i+j*ilx] ;  
+                Mx += (double)boxi * pidata[i+j*ilx] ;
+                My += (double)boxj * pidata[i+j*ilx] ;
+                /*-----------------------------------------------------------
+                 * estimate the amplitude and the background 
+                 * go through the margins of the fitting box 
+                 * and calculate the clean mean to
+                 * determine the background 
+                 */
+                if ( i == llx || i == llx + 2*halfbox_x -1 ||
+                     j == lly || j == lly + 2*halfbox_y -1 )
+                {
+                    backarray[n] = pidata[i+j*ilx] ;
+                    n++ ;
+                }
+            }
+        }
+    }
+    if ( M <= 0. )
+    {
+        sinfo_msg_warning("only negative or zero values") ;
+        cpl_free(backarray) ;
+        return -1 ;
+    }
+    if ( n < 3 )
+    {
+        sinfo_msg_error("not enough data points to calculate background") ;
+        cpl_free(backarray) ;
+        return -1 ;
+    }
+    /* determine the background as sinfo_median of the surrounding pixels */
+    if (FLT_MAX==(background=sinfo_new_clean_mean(backarray,n,10.,10.))) 
+    {
+        sinfo_msg_error("it was not possible to compute the "
+                        "clean mean of the background values") ;
+        cpl_free(backarray) ;
+        return -1 ;
+    }
+    cpl_free (backarray) ;
+    /* now calculate the amplitude estimation */
+    amplitude = maxval - background ;
+    if ( amplitude < 1e-12 )
+    {
+        sinfo_msg_warning("amplitude is too small") ;
+        return -1 ;
+    }
+
+    /* determine the center of gravity = centroid */
+    X0 = Mx / M ;
+    Y0 = My / M ;
+    /* if one of the values is outside the fitting box return with error */
+    if ( X0 <= 0. || Y0 <= 0. || X0 >= 2.*(double)halfbox_x || 
+         Y0 >= 2.*(double)halfbox_y )
+    {
+        sinfo_msg_warning("center of gravity is outside the fitting box!") ;
+        return -1 ;
+    }
+    
+    /*------------------------------------------------------------------------ 
+     * put the data in the 2-d array xydat[][] (pixel position) and zdat[] 
+     * (data values) additionally, determine the second order momentum
+     */
+    n = 0 ;
+    M = Mx = Mxx = My = Myy = Mxy = 0. ;
+    boxi = boxj = 0 ;
+    for ( j = lly ; j < lly + 2*halfbox_y ; j++ )
+    {
+        boxj = j - lly ;
+        for ( i = llx ; i < llx + 2*halfbox_x ; i++ )
+        {
+            boxi = i - llx ;
+            value = pidata[i+j*ilx] ;
+            if ( !isnan(value) )
+            {
+                xydat[n][0] = (double) boxi ;
+                xydat[n][1] = (double) boxj ;
+                zdat[n]     = value ;
+                wdat[n]     = 1. ;
+                n++ ; 
+               
+                /* now calculate the moments without background in the 
+                   centroid coordinate system */
+                value -= background ;
+                xco = (double) boxi - X0 ;
+                yco = (double) boxj - Y0 ;
+                M   += value ;
+                Mx  += xco * value ;
+                My  += yco * value ;
+                Mxx += xco * xco * value ;
+                Myy += yco * yco * value ;
+                Mxy += xco * yco * value ;
+            }
+        }
+    }
+    if ( M <= 0. )
+    {
+        sinfo_msg_warning("only negative or zero values") ;
+        return -1 ;
+    }
+  
+    /* ----------------------------------------------------------------
+     * estimate the fwhm_x and fwhm_y and theta 
+     */ 
+  
+    /* first scale the moments */
+    /* TODO: why use Mx is later this is never used? */
+    Mx  /= M ;
+    My  /= M ;
+    Mxx /= M ;
+    Myy /= M ;
+    Mxy /= M ;
+   
+    denom = 2. * (Mxx*Myy - Mxy*Mxy) ;
+    if ( denom == 0. )
+    {
+        sinfo_msg_error("denominator is zero!") ;
+        return -1 ;
+    }
+    
+    /* now associate the parameter list with the found estimates */
+    fit_par[0] = X0 ;
+    fit_par[1] = Y0 ;
+    fit_par[2] = amplitude ;
+    fit_par[3] = background ;
+    fit_par[4] = Myy/denom ;
+    fit_par[5] = Mxx/denom ;
+    fit_par[6] = -Mxy/denom ;
+
+    /* convert the moments to ellipse paramters */
+    if ( 0 > new_gauss2Ellipse (fit_par) )
+    {
+        sinfo_msg_warning("gauss2Ellipse does not run!") ;
+        return -1 ;
+    }
+
+    /* total number of data points */
+    ndata = 4 * halfbox_x * halfbox_y ;
+    xdim = XDIMG ; /* dimension of xydat array */
+    npar = NPAR ; /* number of parameters in the fit */
+    its = ITSG ;
+    lab = LABG ;
+    tol = TOLG ;
+    for ( i = 0 ; i < NPAR ; i++ )
+    {
+        derv_par[i] = 0. ;
+    }
+    
+    if ( 0 > ( iters = sinfo_new_lsqfitd ( &xydat[0][0],
+                                 &xdim,
+                                 zdat,
+                                 wdat, 
+                                 &ndata,
+                                 fit_par,
+                                 derv_par,
+                                 mpar,
+                                 &npar,
+                                 &tol,
+                                 &its,
+                                 &lab )) ) 
+    {
+        sinfo_msg_warning(" least squares fit failed, error no: %d!", iters) ;
+        return -1 ;
+    }
+
+    /* exclude impossible fit results */
+    if ( fit_par[2] <= 0. || fit_par[4] < 0. || fit_par[5] < 0. )
+    {
+        sinfo_msg_error("sorry, some impossible negative fit results!") ;
+        return -1 ;
+    }
+    fit_par[0] += llx ;
+    fit_par[1] += lly ;
+    if ( fit_par[0] < llx || fit_par[0] >= llx + 2*halfbox_x ||
+         fit_par[1] < lly || fit_par[1] >= lly + 2*halfbox_y )
+    {
+        sinfo_msg_error("sorry, centroid after the fit "
+                        "outside the fitting box") ;
+        return -1 ;
+    }
+
+    /* exchange fwhmx and fwhmy if |theta| is bigger than 
+       pi/4 and subtract pi/2 from theta */
+    if ( fabs ( fit_par[6] ) > PI_NUMB / 4. )
+    {
+        /* first convert angle to smaller than 2 pi */
+        if ( fabs (fit_par[6]) >= 2. * PI_NUMB )
+        { 
+            k = (int) (fit_par[6] / (2.*PI_NUMB)) ;
+            if ( k > 0 ) 
+            {
+                fit_par[6] -= k*2.*PI_NUMB ;
+            }
+            else
+            {
+                fit_par[6] += k*2.*PI_NUMB ;
+            }
+        }
+        /* first convert angle to smaller than pi/2 */
+        if ( fabs (fit_par[6]) > PI_NUMB / 2. )
+        {
+            if ( fit_par[6] > 0. )
+            {
+                fit_par[6] -= PI_NUMB ;
+            }
+            else
+            {
+                fit_par[6] += PI_NUMB ;
+            }
+        }
+
+        if ( fabs (fit_par[6]) > PI_NUMB / 4. )
+        {
+            temp       = fit_par[4] ;
+            fit_par[4] = fit_par[5] ;
+            fit_par[5] = temp ;
+            if ( fit_par[6] < 0. )
+            { 
+                fit_par[6] += PI_NUMB / 2. ;
+            }
+            else
+            {
+                fit_par[6] -= PI_NUMB / 2. ;
+            }  
+        }
+    }
+    
+    return iters ;
+}
+
+/**
+ at brief image of the 2D-Gaussian
+   
+   @param image: image which should be fitted
+   @param parlist: parameters of 2D-Gaussian
+   @return image of the 2D-Gaussian
+
+ */
+
+cpl_image * 
+sinfo_new_plot_gaussian (cpl_image   * image, 
+                         double     * parlist )
+{
+    int col, row ;
+    cpl_image * retImage ;
+    double xdat[2] ;
+    int ilx=0;
+    int ily=0;
+    float* podata=NULL;
+
+    if ( image == NULL )
+    {
+        sinfo_msg_error("no input image given!") ;
+        return NULL ;
+    }
+    ilx=cpl_image_get_size_x(image);
+    ily=cpl_image_get_size_y(image);
+
+    if ( parlist == NULL ) 
+    {
+        sinfo_msg_error("no Gaussian parameters given!") ;
+        return NULL ;
+    }
+ 
+    retImage = cpl_image_new (ilx, ily, CPL_TYPE_FLOAT) ;
+    podata=cpl_image_get_data_float(retImage);
+    for ( row = 0 ; row < ily ; row++ )
+    {
+        for ( col = 0 ; col < ilx ; col++ )
+        {
+            xdat[0] = (double) col ;
+            xdat[1] = (double) row ;
+            podata[col+row*ilx] = sinfo_new_gaussian_ellipse( xdat , parlist) ; 
+        }
+    }
+
+    return retImage ;
+}
+
+/**
+ at brief converts gauss parameters to ellipse parameters.
+
+   @param parlist: parameters of 2D-Gaussian
+   @return parlist: transformed Gaussian parameters to ellipse parameters
+  */
+
+static int new_gauss2Ellipse ( double     * parlist )
+{
+    double a, b, c ;
+    double ellipseconst ;
+    double axisX, axisY, phi ;
+    double p ;
+    
+    if ( parlist == NULL )
+    {
+        sinfo_msg_error(" no parameters given!\n") ;
+        return -1 ;
+    }
+
+    a = parlist[4] ; /* fwhmx */
+    b = parlist[5] ; /* fwhmy */
+    c = parlist[6] ; /* theta */
+
+    ellipseconst = 2. * log(2.) ;
+
+    if ( a*b - c*c <= 0. )
+    {
+        sinfo_msg_warning("estimates of moments are unusable, "
+                          "they do not make an ellipse!") ;
+        return -1 ;
+    }
+    
+    if ( a == b )
+    { 
+        phi = 0. ;
+    }
+    else
+    {
+        phi = 0.5 * atan( 2. * c / (a-b) ) ;
+    }
+
+    p = sqrt ( (a-b) * (a-b) + 4. * c*c ) ;
+
+    if ( a > b )
+    {
+        axisX = 2. * sqrt ( ellipseconst / (a+b+p) ) ;
+        axisY = 2. * sqrt ( ellipseconst / (a+b-p) ) ;
+    }
+    else
+    {
+        axisX = 2. * sqrt ( ellipseconst / (a+b-p) ) ;
+        axisY = 2. * sqrt ( ellipseconst / (a+b+p) ) ;
+    }
+
+    parlist[4] = axisX ;
+    parlist[5] = axisY ;
+    parlist[6] = phi ;
+
+    return 0 ;
+}
+
+/**
+ at brief Determines the convertion factor for an instrument
+   
+   @param cube       reduced data cube of a standard star
+   @param mag        brightness of the standard star
+   @param exptime    exposure time read from the fits header
+   @param llx        lower left point of fitting box
+   @param lly        lower left point of fitting box
+   @param halfbox_x  half width of a box inside which
+                     a 2D-Gauss fit is carried out
+   @param halfbox_y  half width of a box inside which
+                     a 2D-Gauss fit is carried out
+   @param check      if search box is outside image definition.
+
+   @return intensity conversion value: magnitude per counts/s.
+           -FLT_MAX if error occurred.
+   
+   determines an intensity conversion factor for the instrument by fitting a
+   2D-Gaussian to an collapsed image of a standard star with known brightness 
+   (only for non-AO observations). Then the resulting Gaussian is integrated 
+   and the counts are divided by the exposure time (Fits header information) 
+ */
+
+float sinfo_new_determine_conversion_factor ( cpl_imagelist * cube, 
+                                  float     mag,
+                                  float     exptime,
+                                  int       llx,
+                                  int       lly,
+                                  int       halfbox_x,
+                                  int       halfbox_y, 
+                                  int* check )
+{
+    int row, col, i ;
+    int first_row, first_col ;
+    int last_row, last_col ;
+    float factor ;
+    int mpar[7] ;
+    double fit_par[7] ;
+    double derv_par[7] ;
+    int fitInd ;
+    double sum ;
+    double xdat[2] ;
+    cpl_image * summedIm ;
+
+    int ilx=0;
+    int ily=0;
+    int inp=0;
+
+    if ( NULL == cube )
+    {
+        sinfo_msg_error(" no cube given!\n") ;
+        return -FLT_MAX ;
+    }
+
+    ilx=cpl_image_get_size_x(cpl_imagelist_get(cube,0));
+    ily=cpl_image_get_size_y(cpl_imagelist_get(cube,0));
+    inp=cpl_imagelist_get_size(cube);
+
+    if ( halfbox_x <= 0 || halfbox_y <= 0 || 
+       2*halfbox_x > ilx || 2*halfbox_y > ily)
+    {
+        sinfo_msg_error(" wrong width of halfbox given!") ;
+        return -FLT_MAX ;
+    }
+    if ( exptime <= 0. )
+    {
+        sinfo_msg_error(" impossible exposure time given !") ;
+        return -FLT_MAX ;
+    }
+
+    /* collapse the cube to be able to do 2D-Gaussian fitting */
+    if ( NULL == (summedIm = sinfo_new_sum_cube_to_image(cube)) )
+    {
+        sinfo_msg_error(" sinfo_averageCubeToImage failed!") ;
+        return -FLT_MAX ;
+    }
+
+    /* call the 2D-Gaussian fit routine */
+    for ( i = 0 ; i < 7 ; i++ )
+    {
+        mpar[i] = 1 ;
+    }
+    if ( -1 == (fitInd = sinfo_new_fit_2d_gaussian(summedIm, fit_par, derv_par,
+                                                   mpar, llx, lly, halfbox_x, 
+                                                   halfbox_y, check)) )
+    {
+        sinfo_msg_warning("sinfo_fit2dGaussian failed!") ;
+        cpl_image_delete( summedIm) ;
+        return -FLT_MAX ;
+    }
+    cpl_image_delete(summedIm) ;
+
+    /* now integrate the found 2D Gaussian by first 
+       subtracting the background */
+    if  ((fit_par[0] - halfbox_x) < 0) {
+      first_col=0;
+      check++;
+    } else {
+      first_col=(fit_par[0] - halfbox_x);
+    }
+
+    if ((fit_par[0] + halfbox_x) < ilx) {
+      last_col  = (fit_par[0] + halfbox_x);
+    } else {
+      last_col = (ilx-1) ;
+      check++;
+    }
+
+    if ((fit_par[1] - halfbox_y) < 0) {
+      first_row=0;
+      check++;
+    } else {
+      first_row=(fit_par[1] - halfbox_y) ;
+    }
+
+    if ((fit_par[1] + halfbox_y) < ily) {
+      last_row=(fit_par[1] + halfbox_y);
+    } else {
+      last_row= (ily-1);
+      check++;
+    }
+
+
+    if ( first_col < 0 || first_row < 0 || last_col >= ilx || last_row >= ily )
+    {
+        sinfo_msg_error("star badly centered in FOV or fitting box too big!") ;
+        return -FLT_MAX ;
+    }
+    sum = 0. ;
+    for ( row = first_row ; row < last_row ; row++ )  
+    {
+        for( col = first_col ; col < last_col ; col++ )
+        {
+            xdat[0] = (double) col ;
+            xdat[1] = (double) row ;
+            sum += (sinfo_new_gaussian_ellipse( xdat, fit_par ) - fit_par[3]) ;
+        }
+    }
+    if ( sum <= 0. )
+    {
+        sinfo_msg_error("zero or negative sum of counts!") ;
+        return -FLT_MAX ;
+    }
+    factor = mag / (float)sum * exptime ;
+    return factor ;
+}
+                              
+/*--------------------------------------------------------------------------*/
+/**@}*/
diff --git a/sinfoni/sinfo_focus.h b/sinfoni/sinfo_focus.h
new file mode 100644
index 0000000..0c5687b
--- /dev/null
+++ b/sinfoni/sinfo_focus.h
@@ -0,0 +1,238 @@
+#ifndef SINFO_FOCUS_H
+#define SINFO_FOCUS_H
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*******************************************************************************
+* E.S.O. - VLT project
+*
+* "@(#) $Id: sinfo_focus.h,v 1.3 2007/06/06 07:10:45 amodigli Exp $"
+*
+* who       when      what
+* --------  --------  ----------------------------------------------
+* schreib  04/02/02  created
+*/
+
+/************************************************************************
+ * sinfo_focus.h
+ * some functions to fit a 2-D Gaussian for focus finding
+ *----------------------------------------------------------------------
+ */
+
+/*
+ * header files
+ */
+
+#include <cpl.h>
+#include "sinfo_utilities.h"
+#include "sinfo_new_cube_ops.h"
+/*----------------------------------------------------------------------------
+ *                        Function ANSI C prototypes
+ *--------------------------------------------------------------------------*/
+/**
+  @name     sinfo_new_gaussian_ellipse()
+  @param    parlist(0)     center of Gaussian in x direction
+  @param    parlist(1)     center of Gaussian in y direction
+  @param    parlist(2)     Amplitude of the 2d Gaussian
+  @param    parlist(3)     Background level
+  @param    parlist(4)     FWHMx, fwhm of the axis of the ellipse 
+                           near the x-axis
+  @param    parlist(5)     FWHMy, fwhm of the axis of the ellipse 
+                           near the y-axis
+  @param    parlist(6)     theta, position angle of the fwhmx line 
+                            (-PI/4 to PI/4)
+
+  @result   double value of the 2d Gaussian at position xdat.
+
+  @doc      Compute the value of a 2d Gaussian function at a given point.
+            The ellptical 2D Gaussian is:
+  F(x,y) = par(2) * EXP( -4.0*log(2.0)*[(xr/par(4))^2+(yr/par(5))^2]) + par(3),
+  where: xr = xo * cos(par(6)) + yo * sin(par(6))
+         yr = -xo * sin(par(6)) + yo * cos(par(6))
+  and:   x0 = x - par(0)
+         y0 = y - par(1)
+ */
+
+
+double 
+sinfo_new_gaussian_ellipse(double * xdat, double * parlist) ;
+
+/**
+   @name                     sinfo_new_gaussian_ellipse_deriv()
+   @memo calculates the partial derivatives for a 2d Gaussian function with
+         parameters parlist at position xdat
+   @param xdat           position array, 
+   @param parlist        parameter list 
+                        The parameters are:
+                      #  parlist(0): center of Gaussian in x direction
+                      #  parlist(1): center of Gaussian in y direction
+                      #  parlist(2): Amplitude of 2d Gaussian
+                      #  parlist(3): Background level
+                      #  parlist(4): FWHMx
+                      #  parlist(5): FWHMy
+                      #  parlist(6): theta
+   @param dervs   derivative value of a 2d Gaussian function at position xdat
+                      #  dervs[0]: partial derivative by center x
+                      #  dervs[1]: partial derivative by center y
+                      #  dervs[2]: partial derivative by the amplitude
+                      #  dervs[3]: partial derivative by the background
+                      #  dervs[4]: partial derivative by FWHMx
+                      #  dervs[5]: partial derivative by FWHMy
+                      #  dervs[6]: partial derivative by theta
+   @return void
+*/
+
+void 
+sinfo_new_gaussian_ellipse_deriv( double * xdat, 
+                                  double * parlist, 
+                                  double * dervs ) ;
+
+/**
+   @name    sinfo_new_lsqfitd()
+   @param   xdat  position, coordinates of data points.
+                  xdat is 2 dimensional: XDAT ( XDIM, NDAT )
+   @param   xdim  dimension of fit
+   @param   ydat  data points
+   @param   wdat  weights for data points
+   @param   ndat  number of data points
+   @param   fpar  on input contains initial estimates of the
+                  parameters for non-linear fits, on output the
+                  fitted parameters.
+   @param   epar  contains estimates of the errors in fitted parameters
+   @param   mpar  logical mask telling which parameters are free (non-zero)
+                  and which parameters are fixed (0)
+   @param   npar number of function parameters ( free + fixed )
+   @param   tol  relative tolerance. lsqfit stops when successive iterations
+                 fail to produce a decrement in reduced chi-squared less
+                 than tol. If tol is less than the minimum tolerance
+                 possible, tol will be set to this value. This means
+                 that maximum accuracy can be obtained by setting tol = 0.0.
+   @param   its  maximum number of iterations
+   @param   lab  mixing parameter, lab determines the initial weight
+                 of steepest descent method relative to the Taylor method
+                 lab should be a small value (i.e. 0.01). lab can only
+                 be zero when the partial derivatives are independent
+                 of the parameters. In fact in this case lab should be
+                 exactly equal to zero.
+   @param   returns number of iterations needed to achieve convergence
+            according to tol. When this number is negative, the fitting
+            was not continued because a fatal error occurred:
+                     #   -1 too many free parameters, maximum is 32
+                     #   -2 no free parameters
+                     #   -3 not enough degrees of freedom
+                     #   -4 maximum number of iterations too small to obtain
+                           a solution which satisfies tol.
+                     #   -5 diagonal of sinfo_matrix contains elements 
+                            which are zero
+                     #   -6 determinant of the coefficient sinfo_matrix is zero
+                     #   -7 square root of a negative number
+   @doc     this is a routine for making a least-squares fit of a
+            function to a set of data points. The method used is
+            described in: Marquardt, J.Soc.Ind.Appl.Math. 11. 431 (1963).
+            This method is a mixture of the steepest descent method
+            and the Taylor method.
+*/
+int 
+sinfo_new_lsqfitd ( double * xdat,
+              int    * xdim,
+              double * ydat,
+              double * wdat,
+              int    * ndat,
+              double * fpar,
+              double * epar,
+              int    * mpar,
+              int    * npar,
+              double * tol ,
+              int    * its ,
+              double * lab  ) ;
+
+/**
+   @name  sinfo_new_fit_2d_gaussian()
+   @param image      reconstructed image of a point source
+   @param fit_par    array of 7 free fit parameters of a 2D-Gauss
+   @param derv_par   derivatives of the fit_par array
+   @param mpar       mask to set free parameters, 1: free, 0: fixed.
+   @param lleftx
+   @param llefty     lower left starting point of the box in which the fit 
+                     is carried through to find the maximum of point source 
+                     image
+   @param halfbox_x  half box length in x-direction in pixels inside which the 
+                     fit is carried through
+   @param halfbox_y  half box length in y-direction in pixels inside which the 
+                     fit is carried through
+   @return number of needed iterations -1 if an error occurred.
+   @doc fits the image of a point source by using a 2-D Gaussian fit.
+        Remark on the fit results for the fit parameters (fwhmx and fwhmy and 
+        theta): theta will always be between -PI/4 and +PI/4, exchange of the 
+        fwhmx and fwhmy values corresponds to a shift of theta by PI/2.
+        Consequently, an expected theta > |PI/4| will result
+        in an exchange of the fwhm values and a shift of theta by
+        PI/2 to a value < |PI/4| what yields exactly the same image.
+*/
+
+int 
+sinfo_new_fit_2d_gaussian ( cpl_image   * image,
+                    double     * fit_par,
+                    double     * derv_par,
+                    int        * mpar,
+                    int          lleftx,
+                    int          llefty,
+                    int          halfbox_x,
+                    int          halfbox_y, int* check ) ;
+
+/**
+   @name   sinfo_new_plot_gaussian()
+   @memo    plots an image of a given 2D-Gaussian
+   @param  image: image which should be fitted
+   @param  parlist: parameters of 2D-Gaussian
+   @return image of the 2D-Gaussian
+*/
+
+cpl_image * 
+sinfo_new_plot_gaussian ( cpl_image   * image,
+                          double     * parlist ) ;
+
+/**
+   @name      sinfo_new_determine_conversion_factor()
+   @param     cube reduced data cube of a standard star
+   @param     mag  brightness of the standard star
+   @param     exptime exposure time read from the fits header
+   @param     llx
+   @param     lly lower left point of fitting box
+   @param     halfbox_x
+   @param     halfbox_y half width of a box inside which
+                        a 2D-Gauss fit is carried out
+   @return    intensity conversion value: magnitude per counts/s
+              -FLT_MAX if error occurred.
+   @return    determines an intensity conversion factor for the instrument
+              by fitting a 2D-Gaussian to an collapsed image of a standard star
+              with known brightness (only for non-AO observations).
+              Then the resulting Gaussian is integrated and the counts
+              are divided by the exposure time (Fits header information)
+*/
+float 
+sinfo_new_determine_conversion_factor ( cpl_imagelist * cube,
+                                  float     mag,
+                                  float     exptime,
+                                  int       llx,
+                                  int       lly,
+                                  int       halfbox_x,
+                                  int       halfbox_y, int* check ) ;
+
+#endif /*!SINFO_FOCUS_H*/
+
diff --git a/sinfoni/sinfo_focus_cfg.c b/sinfoni/sinfo_focus_cfg.c
new file mode 100644
index 0000000..770c987
--- /dev/null
+++ b/sinfoni/sinfo_focus_cfg.c
@@ -0,0 +1,77 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*---------------------------------------------------------------------------
+   
+   File name     :    sinfo_focus_cfg.c
+   Author     :       Juergen Schreiber
+   Created on    :    February 2002
+   Description    :    configuration handling tools for the 2d-Gaussian fit 
+                        of a point source
+
+ *--------------------------------------------------------------------------*/
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+/*---------------------------------------------------------------------------
+                                   Includes
+ ---------------------------------------------------------------------------*/
+#include "sinfo_focus_cfg.h"
+/**@{*/
+/**
+ * @addtogroup sinfo_focus Focus determination functions
+ *
+ * TBD
+ */
+
+
+/*---------------------------------------------------------------------------
+                              Function codes
+ ---------------------------------------------------------------------------*/
+/**
+   @name     sinfo_focus_cfg_create()
+   @return   pointer to allocated base focus_cfg structure
+   @memo     allocate memory for a focus_config struct
+   @note     only the main (base) structure is allocated
+ */
+focus_config * 
+sinfo_focus_cfg_create(void)
+{
+    return cpl_calloc(1, sizeof(focus_config));
+}
+/**
+   @name   sinfo_focus_cfg_destroy()
+   @memo   deallocate all memory associated with a focus_config data structure
+   @param  focus_config to deallocate
+   @return void
+*/
+void 
+sinfo_focus_cfg_destroy(focus_config * cc)
+{
+    if (cc==NULL) return ;
+
+    /* Free main struct */
+    cpl_free(cc);
+
+    return ;
+}
+/**@}*/
+
+
+
diff --git a/sinfoni/sinfo_focus_cfg.h b/sinfoni/sinfo_focus_cfg.h
new file mode 100644
index 0000000..fe010ed
--- /dev/null
+++ b/sinfoni/sinfo_focus_cfg.h
@@ -0,0 +1,134 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*---------------------------------------------------------------------------
+   
+   File name     :    sinfo_focus_cfg.h
+   Author    :    Juergen Schreiber
+   Created on    :    February 2002
+   Description    :    focus_cfg.c definitions + handling prototypes
+ ---------------------------------------------------------------------------*/
+#ifndef SINFO_FOCUS_CFG_H
+#define SINFO_FOCUS_CFG_H
+/*---------------------------------------------------------------------------
+                                   Includes
+ ---------------------------------------------------------------------------*/
+#include <stdlib.h>
+#include <cpl.h>
+#include "sinfo_globals.h"
+/*---------------------------------------------------------------------------
+                                   Defines
+ ---------------------------------------------------------------------------*/
+/*---------------------------------------------------------------------------
+                                   New types
+ ---------------------------------------------------------------------------*/
+/*
+  point source 2D-Gaussian fit blackboard container
+
+  This structure holds all information related to the 2D-Gaussian fit
+  routine. It is used as a container for the flux of ancillary data,
+  computed values, and algorithm status. Pixel flux is separated from
+  the blackboard.
+  */
+
+typedef struct focus_config {
+/*-------General---------*/
+        char inFile[FILE_NAME_SZ] ;       /* file name of frame list */
+        char ** inFrameList ; /* input averaged, bad pixel corrected, 
+                                 off subtracted, flatfielded, spectral tilt 
+                                 corrected list of frames */
+        int nframes ;        /* number of frames in the list */
+        char outName[FILE_NAME_SZ] ; /* output name of resulting 
+                                        fits data cube */
+
+/*------ Reconstruction ------*/
+        /* the fraction [0...1] of rejected low intensity pixels 
+           when taking the average of columns */
+        float lo_reject ;
+        /* the fraction [0...1] of rejected high intensity pixels 
+           when taking the average of columns */
+        float hi_reject ;
+        /* indicates if the slitlet distances are determined by a 
+           north-south test (1) 
+           or slitlet edge fits (0) */ 
+        int northsouthInd  ;
+        /* name of the ASCII list of the fitted slitlet edge 
+          positions or the distances of the slitlets */
+        char poslist[FILE_NAME_SZ] ;
+        /* number of slitlets (32) */
+        int nslits ;
+        /* sub pixel position of the column position of the left sinfo_edge of 
+           the first slitlet needed if the slitlet distances were determined 
+           by a north south test */
+        char firstCol[FILE_NAME_SZ] ;
+    /* indicator for the shifting method to use */
+    char  method[1] ;
+        /* order of polynomial if the polynomial interpolation shifting 
+           method is used */
+        int order ;
+/*------ Gauss2Dfit ------*/
+        /* lower left sinfo_edge coordinates of fitting box for 2D 
+           Gaussian fit */
+        int llx ;
+        int lly ;
+        /* half length in pixels of the box within the point source 
+           is fitted in x and y-direction */
+        int halfbox_x ;
+        int halfbox_y ;
+        /* mask parameters ( 1 or 0 ) for the fit parameters. If 1 
+           the corresponding parameter
+           is set free, if 0 the parameter is kept fixed. */
+        int mpar0 ; /* mask for the x-position */
+        int mpar1 ; /* mask for the y-position */
+        int mpar2 ; /* mask for the amplitude */
+        int mpar3 ; /* mask for the background */
+        int mpar4 ; /* mask for the fwhmx */
+        int mpar5 ; /* mask for the fwhmy */
+        int mpar6 ; /* mask for the position angle of fwhmx line */
+        /* name of the resulting ASCII file containing the fit parameters */
+        char fitlist[FILE_NAME_SZ] ;
+        /* indicator if the resulting 2D-Gaussian is stored in a fits 
+           file or not */
+        int plotGaussInd ;
+        /* name of the fits file containing the resulting 2D-Gaussian */
+        char gaussplotName[FILE_NAME_SZ] ;
+} focus_config ;
+
+/*---------------------------------------------------------------------------
+                               Function prototypes
+ ---------------------------------------------------------------------------*/
+/**
+   @name     sinfo_focus_cfg_create()
+   @return   pointer to allocated base focus_cfg structure
+   @memo     allocate memory for a focus_config struct
+   @note     only the main (base) structure is allocated
+ */
+
+focus_config * 
+sinfo_focus_cfg_create(void);
+
+/**
+   @name   sinfo_focus_cfg_destroy()
+   @memo   deallocate all memory associated with a focus_config data structure
+   @param  focus_config to deallocate
+   @return void
+*/
+void 
+sinfo_focus_cfg_destroy(focus_config * cc);
+
+#endif
diff --git a/sinfoni/sinfo_focus_determination_config.c b/sinfoni/sinfo_focus_determination_config.c
new file mode 100644
index 0000000..80107b3
--- /dev/null
+++ b/sinfoni/sinfo_focus_determination_config.c
@@ -0,0 +1,299 @@
+/* $Id: sinfo_focus_determination_config.c,v 1.6 2012/03/02 08:42:20 amodigli Exp $
+ *
+ * This file is part of the CPL (Common Pipeline Library)
+ * Copyright (C) 2002 European Southern Observatory
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2012/03/02 08:42:20 $
+ * $Revision: 1.6 $
+ * $Name: sinfo-2_3_2 $
+ */
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+ /****************************************************************
+  *   Focus Determination                                        *
+  ****************************************************************/
+#include "cpl_parameterlist.h"    /* defines parlist structure */
+#include "sinfo_dfs.h"
+#include "sinfo_focus_determination_config.h"
+
+/**@{*/
+/**
+ * @addtogroup sinfo_focus Focus determination functions
+ *
+ * TBD
+ */
+
+
+  /* Focus Determination Parameters Definition */
+   
+
+void
+ sinfo_focus_determination_config_add(cpl_parameterlist *list)
+{
+
+  cpl_parameter *p;
+
+  if (!list) {
+    return;
+  }
+
+  /* Output file name */
+  /* output name of resulting fits wavelength map */
+  p = cpl_parameter_new_value("sinfoni.focus.output_filename",
+                  CPL_TYPE_STRING,
+                              "Output File Name: ",
+                              "sinfoni.focus",
+                              FOCUS_OUT_FILENAME);
+
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"out-focus_filename");
+  cpl_parameterlist_append(list, p);
+
+
+
+ p = cpl_parameter_new_enum("sinfoni.focus.method",
+                  CPL_TYPE_STRING,
+                              "Shifting method to use: ",
+                              "sinfoni.focus",
+                              "P",
+                               3,
+                              "P","F","S");
+
+  cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,"focus-method");
+  cpl_parameterlist_append(list, p);
+
+
+  /* Reconstruction */
+
+ /* float 
+     threshold used in the clean mean percentage of rejection used to reject 
+     low and high frame */
+ /* percentage of extreme pixel value to reject when calculating the mean 
+    and stdev */
+  p = cpl_parameter_new_range("sinfoni.focus.lower_rejection",
+                  CPL_TYPE_DOUBLE,
+                              "lower rejection",
+                              "sinfoni.focus",
+                               0.1,0.0,1.0);
+
+
+  cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,"focus-det-low_rejection");
+  cpl_parameterlist_append(list, p);
+
+  /* float 
+     threshold used in the clean mean percentage of rejection used to reject 
+     low and high frame */
+ /* percentage of extreme pixel value to reject when calculating the mean 
+    and stdev */
+  p = cpl_parameter_new_range("sinfoni.focus.higher_rejection",
+                  CPL_TYPE_DOUBLE,
+                              "high rejection",
+                              "sinfoni.focus",
+                               0.1,0.0,1.0);
+
+
+  cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI,"focus-det-high_rejection");
+  cpl_parameterlist_append(list, p);
+
+/* indicates if the slitlet distances are determined by 
+   a north-south test (1) 
+           or 
+   slitlet sinfo_edge fits (0) */ 
+  p = cpl_parameter_new_value("sinfoni.focus.north_south_index",
+                  CPL_TYPE_BOOL,
+                              "North South Index",
+                              "sinfoni.focus",
+                              TRUE);
+
+  cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,"focus-det-ns_index");
+  cpl_parameterlist_append(list, p);
+
+  /* number of slitlets (32) */
+  p = cpl_parameter_new_value("sinfoni.focus.nslits",
+                  CPL_TYPE_INT,
+                              "Number Of Slits",
+                              "sinfoni.focus",
+                              32);
+
+
+  cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,"focus-det-nslits");
+  cpl_parameterlist_append(list, p);
+
+  p = cpl_parameter_new_value("sinfoni.focus.order",
+                  CPL_TYPE_INT,
+                              "Order",
+                              "sinfoni.focus",
+                              2);
+
+  cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,"focus-det-order");
+  cpl_parameterlist_append(list, p);
+
+
+  /* Gauss 2D Fit */
+  /* lower left sinfo_edge coordinates of fitting box for 2D Gaussian fit */
+  p = cpl_parameter_new_range("sinfoni.focus.llx",
+                  CPL_TYPE_INT,
+                              "llx",
+                              "sinfoni.focus",
+                              9,DET_PIX_MIN,DET_PIX_MAX);
+
+  cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,"focus-det-llx");
+  cpl_parameterlist_append(list, p);
+
+  /* lower left sinfo_edge coordinates of fitting box for 2D Gaussian fit */
+  p = cpl_parameter_new_range("sinfoni.focus.lly",
+                  CPL_TYPE_INT,
+                              "lly",
+                              "sinfoni.focus",
+                              9,DET_PIX_MIN,DET_PIX_MAX);
+
+
+  cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,"focus-det-lly");
+  cpl_parameterlist_append(list, p);
+
+/* half length in pixels of the box within the point source is fitted in x 
+   and y-direction */
+  p = cpl_parameter_new_range("sinfoni.focus.halfbox_x",
+                  CPL_TYPE_INT,
+                              "half box x",
+                              "sinfoni.focus",
+                              7,DET_PIX_MIN,DET_PIX_MAX);
+
+  cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,"focus-det-hbx");
+  cpl_parameterlist_append(list, p);
+
+/* half length in pixels of the box within the point source is fitted in x 
+   and y-direction */
+  p = cpl_parameter_new_range("sinfoni.focus.halfbox_y",
+                  CPL_TYPE_INT,
+                              "half box y",
+                              "sinfoni.focus",
+                              7,DET_PIX_MIN,DET_PIX_MAX);
+
+
+  cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,"focus-det-hby");
+  cpl_parameterlist_append(list, p);
+
+  /* mask for the x-position */
+  p = cpl_parameter_new_value("sinfoni.focus.mpar0",
+                  CPL_TYPE_INT,
+                              "mask par 0",
+                              "sinfoni.focus",
+                              1);
+
+  cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,"focus-det-mpar0");
+  cpl_parameterlist_append(list, p);
+
+  /* mask for the y-position */
+  p = cpl_parameter_new_value("sinfoni.focus.mpar1",
+                  CPL_TYPE_INT,
+                              "mask par 1",
+                              "sinfoni.focus",
+                              1);
+
+  cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,"focus-det-mpar1");
+  cpl_parameterlist_append(list, p);
+
+  /* mask for the amplitude */
+  p = cpl_parameter_new_value("sinfoni.focus.mpar2",
+                  CPL_TYPE_INT,
+                              "mask par 2",
+                              "sinfoni.focus",
+                              1);
+
+  cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,"focus-det-mpar2");
+  cpl_parameterlist_append(list, p);
+
+  /* mask for the background */
+  p = cpl_parameter_new_value("sinfoni.focus.mpar3",
+                  CPL_TYPE_INT,
+                              "mask par 3",
+                              "sinfoni.focus",
+                              1);
+
+  cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,"focus-det-mpar3");
+  cpl_parameterlist_append(list, p);
+
+  /* mask for the fwhmx */
+  p = cpl_parameter_new_value("sinfoni.focus.mpar4",
+                  CPL_TYPE_INT,
+                              "mask par 4",
+                              "sinfoni.focus",
+                              1);
+
+  cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,"focus-det-mpar4");
+  cpl_parameterlist_append(list, p);
+
+  /* mask for the fwhmy */
+  p = cpl_parameter_new_value("sinfoni.focus.mpar5",
+                  CPL_TYPE_INT,
+                              "mask par 5",
+                              "sinfoni.focus",
+                              1);
+
+  cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,"focus-det-mpar5");
+  cpl_parameterlist_append(list, p);
+
+  /* mask for the position angle of fwhmx line */
+  p = cpl_parameter_new_value("sinfoni.focus.mpar6",
+                  CPL_TYPE_INT,
+                              "mask par 6",
+                              "sinfoni.focus",
+                              1);
+
+  cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,"focus-det-mpar6");
+  cpl_parameterlist_append(list, p);
+
+  /* name of the resulting ASCII file containing the fit parameters */
+  p = cpl_parameter_new_value("sinfoni.focus.fit_list",
+                  CPL_TYPE_STRING,
+                              "Fit List: ",
+                              "sinfoni.fit_list",
+                              FOCUS_FITPAR_OUT_FILENAME);
+
+  cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,"focus-det-fit_list");
+  cpl_parameterlist_append(list, p);
+
+ /* indicator if the resulting 2D-Gaussian is stored in a fits file or not */
+  p = cpl_parameter_new_value("sinfoni.focus.plot_gauss_ind",
+                  CPL_TYPE_BOOL,
+                              "Plot Gauss Ind",
+                              "sinfoni.focus",
+                              TRUE);
+
+  cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,"focus-det-gauss_ind");
+  cpl_parameterlist_append(list, p);
+
+
+  /* name of the fits file containing the resulting 2D-Gaussian */
+  p = cpl_parameter_new_value("sinfoni.focus.gauss_plot_name",
+                  CPL_TYPE_STRING,
+                              "Gauss Plot Name: ",
+                              "sinfoni.focus",
+                              FOCUS_GAUSSPLOT_OUT_FILENAME);
+
+  cpl_parameter_set_alias(p,  
+       CPL_PARAMETER_MODE_CLI,"focus-det-gauss_plot_name");
+  cpl_parameterlist_append(list, p);
+
+}
+/**@}*/
diff --git a/sinfoni/sinfo_focus_determination_config.h b/sinfoni/sinfo_focus_determination_config.h
new file mode 100644
index 0000000..99a87d7
--- /dev/null
+++ b/sinfoni/sinfo_focus_determination_config.h
@@ -0,0 +1,36 @@
+/* $Id: sinfo_focus_determination_config.h,v 1.1 2006/10/20 08:06:32 amodigli Exp $
+ *
+ * This file is part of the CPL (Common Pipeline Library)
+ * Copyright (C) 2002 European Southern Observatory
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2006/10/20 08:06:32 $
+ * $Revision: 1.1 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+ /****************************************************************
+  *   Focus Determination                                        *
+  ****************************************************************/
+#include "cpl.h"    /* defines parlist structure */
+/*
+#include "sinfo_dfs.h"
+*/
+#include "sinfo_hidden.h"
+void sinfo_focus_determination_config_add(cpl_parameterlist *list);
diff --git a/sinfoni/sinfo_focus_ini.h b/sinfoni/sinfo_focus_ini.h
new file mode 100644
index 0000000..aa157f4
--- /dev/null
+++ b/sinfoni/sinfo_focus_ini.h
@@ -0,0 +1,72 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+   
+   File name    :   sinfo_focus_ini.h
+   Author       :    Juergen Schreiber
+   Created on   :    Feb 13, 2002
+   Description  :    ini file handling for SPIFFIs focus finding
+ ---------------------------------------------------------------------------*/
+#ifndef SINFO_FOCUS_INI_H
+#define SINFO_FOCUS_INI_H
+/*---------------------------------------------------------------------------
+                                Includes
+---------------------------------------------------------------------------*/
+#include "sinfo_focus_cfg.h"
+#include <cpl.h>
+/*----------------------------------------------------------------------------
+                             Function prototypes 
+ ---------------------------------------------------------------------------*/
+/*-------------------------------------------------------------------------*/
+/**
+  @name        generateFocus_ini_file
+  @memo        Generate a default ini file for the focus determination command.
+  @param    ini_name    Name of the file to generate.
+  @param    name_i        Name of the input file.
+  @param    name_o        Name of the output file.
+  @return    int 0 if Ok, -1 otherwise.
+  @doc          This function generates a default ini file for the focus 
+                determination command. The generated file will have the 
+                requested name. If you do not want to provide names for the 
+                input/output/calib files, feed either NULL pointers
+                or character strings starting with (char)0.
+ */
+/*--------------------------------------------------------------------------*/
+int 
+generateFocus_ini_file(
+        char * ini_name,
+        char * name_i,
+        char * name_o
+);
+ 
+/**
+  @name     parse_focus_ini_file
+  @memo     Parse a ini_name.ini file and create a blackboard.
+  @param    ini_name    Name of the ASCII file to parse.
+  @return   1 newly allocated focus_config blackboard structure.
+  @doc
+
+  The requested ini file is parsed and a blackboard object is created, then
+  updated accordingly. Returns NULL in case of error.
+ */
+focus_config * 
+parse_focus_ini_file(char * ini_name) ;
+ 
+
+#endif
diff --git a/sinfoni/sinfo_focus_ini_by_cpl.c b/sinfoni/sinfo_focus_ini_by_cpl.c
new file mode 100644
index 0000000..680c397
--- /dev/null
+++ b/sinfoni/sinfo_focus_ini_by_cpl.c
@@ -0,0 +1,326 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+   
+   File name    :   sinfo_focus_ini_by_cpl.c
+   Author       :   Andrea Modigliani
+   Created on   :   May 20, 2004
+   Description  :   cpl input handling for SPIFFI
+ ---------------------------------------------------------------------------*/
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+/*---------------------------------------------------------------------------
+                                Includes
+ ---------------------------------------------------------------------------*/
+#include <string.h>
+#include "sinfo_focus_ini_by_cpl.h"
+#include "sinfo_pro_types.h"
+#include "sinfo_functions.h"
+#include "sinfo_file_handling.h"
+/*---------------------------------------------------------------------------
+                    Functions private to this module
+ ---------------------------------------------------------------------------*/
+static void 
+parse_section_frames(focus_config *, cpl_parameterlist* cpl_cfg, 
+                   cpl_frameset* sof,cpl_frameset** stk, int* status);
+static void 
+parse_section_reconstruction(focus_config *, cpl_parameterlist* cpl_cfg);
+static void 
+parse_section_gauss2dfit(focus_config *, cpl_parameterlist* cpl_cfg);
+
+/**@{*/
+/**
+ * @addtogroup sinfo_focus Focus determination functions
+ *
+ * TBD
+ */
+
+
+
+/**
+  @name     sinfo_parse_cpl_input_focus
+  @memo     Parse input frames and parameters and create a blackboard.
+  @param    cpl_cfg pointer to parameterlist
+  @param    sof pointer to input set of frames
+  @param    stk pointer to input set of stacked frames
+  @return   1 newly allocated focus_config blackboard structure.
+  @doc
+
+  The requested ini file is parsed and a blackboard object is created, then
+  updated accordingly. Returns NULL in case of error.
+ */
+
+focus_config * 
+sinfo_parse_cpl_input_focus(cpl_parameterlist * cpl_cfg, cpl_frameset* sof,
+                     cpl_frameset** stk)
+{
+        focus_config  *       cfg = sinfo_focus_cfg_create();
+  int status=0;
+        /*
+         * Perform sanity checks, fill up the structure with what was
+         * found in the ini file
+         */
+
+        parse_section_reconstruction   (cfg, cpl_cfg);
+        parse_section_gauss2dfit       (cfg, cpl_cfg);
+        parse_section_frames           (cfg, cpl_cfg,sof,stk,&status);
+        if (status > 0) {
+                sinfo_msg_error("parsing cpl input");
+                sinfo_focus_cfg_destroy(cfg);
+                cfg = NULL ;
+                return NULL ;
+        }
+        return cfg ;
+}
+
+/**
+  @name     parse_section_frames
+  @memo     Parse input frames.
+  @param    cfg pointer to focus_config structure
+  @param    cpl_cfg pointer to parameterlist
+  @param    sof pointer to input set of frames
+  @param    raw pointer to input set of raw frames
+  @param    status status of function
+  @return   void
+ */
+static void   
+parse_section_frames(focus_config * cfg,
+                     cpl_parameterlist* cpl_cfg,
+                     cpl_frameset* sof,
+                     cpl_frameset** raw, 
+                     int* status)
+{
+
+
+   char            *       name ;
+    int nframes=0;
+   int nraw=0;
+   cpl_frame* frame   = NULL;
+   cpl_parameter *p; 
+
+
+   char spat_res[FILE_NAME_SZ];
+   char lamp_status[FILE_NAME_SZ];
+   char band[FILE_NAME_SZ];
+   int ins_set=0;
+
+
+   char * tag;
+   int i=0;
+   nframes = cpl_frameset_get_size(sof);
+    /* Get the raw and the calibration files */
+    /* Labelise the input frames according to their tags */
+
+  *raw=cpl_frameset_new();
+   sinfo_extract_raw_frames_type(sof,raw,PRO_FOCUS_STACKED);
+
+
+   nraw=cpl_frameset_get_size(*raw);
+   if (nraw < 1) {
+      sinfo_msg_error("Too few (%d) raw frames (%s) present in"
+            "frameset!Aborting...",nraw,PRO_FOCUS_STACKED);
+          (*status)++;
+          return;
+   }
+   /* Allocate structures to go into the blackboard */
+   cfg->inFrameList     = cpl_malloc(nraw * sizeof(char*));
+ 
+   /* Browse through the charmatrix to get names and file types */
+   for (i=0 ; i<nraw ; i++) {
+      frame = cpl_frameset_get_frame(*raw,i);
+      name= (char*) cpl_frame_get_filename(frame);
+      if(sinfo_file_exists(name)==1) {
+    /* to go on the file must exist */
+    if(cpl_frame_get_tag(frame) != NULL) {
+      /* If the frame has a tag we process it. Else it is an object */ 
+      tag= (char*) cpl_frame_get_tag(frame);
+          if(sinfo_is_stack(tag)) 
+        {
+             cfg->inFrameList[i]=cpl_strdup(cpl_frame_get_filename(frame));
+        }
+          else {
+            sinfo_msg_error("No good frame tag %s in input frame set",tag);
+        (*status)++;
+            return;
+      }
+    }
+      }
+      /* Store file name into inFrameList */
+   }
+
+   /* Copy relevant information into the blackboard */
+   cfg->nframes = nraw ;
+
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.output_filename");
+   strcpy(cfg -> outName, cpl_parameter_get_string(p));
+
+   if(NULL != cpl_frameset_find(sof,PRO_FIRST_COL)) {
+      frame = cpl_frameset_find(sof,PRO_FIRST_COL);
+      strcpy(cfg -> firstCol,cpl_strdup(cpl_frame_get_filename(frame)));
+   } else {
+      sinfo_msg_error("Frame %s not found! Exit!", PRO_FIRST_COL);
+        (*status)++;
+      return;
+   }
+
+   if(NULL != cpl_frameset_find(sof,PRO_SLITLETS_DISTANCE)) {
+      frame = cpl_frameset_find(sof,PRO_SLITLETS_DISTANCE);
+      strcpy(cfg -> poslist,cpl_strdup(cpl_frame_get_filename(frame)));
+   } else {
+      sinfo_msg_error("Frame %s not found! Exit!", PRO_SLITLETS_DISTANCE);
+        (*status)++;
+      return;
+   }
+
+
+
+   frame = cpl_frameset_get_frame(*raw,0);
+   sinfo_get_spatial_res(frame,spat_res);
+ 
+   switch(sinfo_frame_is_on(frame)) 
+     {
+   case 0: 
+      strcpy(lamp_status,"on");
+      break;
+    case 1: 
+      strcpy(lamp_status,"off");
+      break;
+    case -1:
+      strcpy(lamp_status,"undefined");
+      break;
+    default: 
+      strcpy(lamp_status,"undefined");
+      break;
+     }
+
+   sinfo_get_band(frame,band);
+   sinfo_msg("Spatial resolution: %s lamp_status: %s band: %s \n",
+                     spat_res,    lamp_status,    band);
+
+
+   sinfo_get_ins_set(band,&ins_set);
+   return;
+}
+
+/**
+  @name     parse_section_reconstruction
+  @memo     Parse reconstruction parameters.
+  @param    cfg pointer to focus_config structure
+  @param    cpl_cfg pointer to parameterlist
+  @return   void
+ */
+static void     
+parse_section_reconstruction(focus_config * cfg,cpl_parameterlist * cpl_cfg)
+{
+
+
+  cpl_parameter* p;
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.lower_rejection");
+   cfg -> lo_reject = cpl_parameter_get_double(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.higher_rejection");
+   cfg -> hi_reject =  cpl_parameter_get_double(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.north_south_index");
+   cfg -> northsouthInd = cpl_parameter_get_bool(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.nslits");
+   cfg -> nslits = cpl_parameter_get_int(p);
+ 
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.method");
+   strcpy(cfg->method, cpl_parameter_get_string(p));
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.order");
+   cfg -> order= cpl_parameter_get_int(p);
+
+}
+
+/**
+  @name     parse_section_gauss2dfit
+  @memo     Parse gauss2dfit parameters.
+  @param    cfg pointer to focus_config structure
+  @param    cpl_cfg pointer to parameterlist
+  @return   void
+ */
+static void     
+parse_section_gauss2dfit(focus_config * cfg,cpl_parameterlist * cpl_cfg)
+{
+ cpl_parameter* p;
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.llx");
+   cfg -> llx = cpl_parameter_get_int(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.lly");
+   cfg -> lly = cpl_parameter_get_int(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.halfbox_x");
+   cfg -> halfbox_x =  cpl_parameter_get_int(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.halfbox_y");
+   cfg -> halfbox_y = cpl_parameter_get_int(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.mpar0");
+   cfg -> mpar0 = cpl_parameter_get_int(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.mpar1");
+   cfg -> mpar1 = cpl_parameter_get_int(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.mpar2");
+   cfg -> mpar2 = cpl_parameter_get_int(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.mpar3");
+   cfg -> mpar3 = cpl_parameter_get_int(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.mpar4");
+   cfg -> mpar4 = cpl_parameter_get_int(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.mpar5");
+   cfg -> mpar5 = cpl_parameter_get_int(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.mpar6");
+   cfg -> mpar6 = cpl_parameter_get_int(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.fit_list");
+   strcpy(cfg -> fitlist, cpl_parameter_get_string(p));
+
+   /* int or string ?*/
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.plot_gauss_ind");
+   cfg -> plotGaussInd = cpl_parameter_get_bool(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.gauss_plot_name");
+   strcpy( cfg -> gaussplotName, cpl_parameter_get_string(p));
+
+   return ;
+}
+/**
+ at name sinfo_free_focus
+ at memo free sinfo_config structure
+ at param cfg pointer to focus_config structure
+ at return void
+*/
+void
+sinfo_free_focus(focus_config * cfg) {
+   cpl_free(cfg->inFrameList);
+   sinfo_focus_cfg_destroy (cfg);
+  
+   return;
+}
+/**@}*/
diff --git a/sinfoni/sinfo_focus_ini_by_cpl.h b/sinfoni/sinfo_focus_ini_by_cpl.h
new file mode 100644
index 0000000..d7ecc79
--- /dev/null
+++ b/sinfoni/sinfo_focus_ini_by_cpl.h
@@ -0,0 +1,65 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+   
+   File name    :   sinfo_focus_ini_by_cpl.h
+   Author       :   Andrea Modigliani
+   Created on   :   May 20, 2004
+   Description  :   cpl input handling for SPIFFIs focus finding
+ ---------------------------------------------------------------------------*/
+#ifndef SINFO_FOCUS_INI_BY_CPL_H
+#define SINFO_FOCUS_INI_BY_CPL_H
+/*---------------------------------------------------------------------------
+                                Includes
+---------------------------------------------------------------------------*/
+#include <stdio.h>
+#include <cpl.h>
+#include "sinfo_msg.h"
+#include "sinfo_focus_cfg.h"
+/*----------------------------------------------------------------------------
+                             Function prototypes 
+ ---------------------------------------------------------------------------*/
+
+/**
+ at name sinfo_free_focus
+ at memo free sinfo_config structure
+ at param cfg pointer to focus_config structure
+ at return void
+*/
+void 
+sinfo_free_focus(focus_config * cfg);
+
+/**
+  @name     sinfo_parse_cpl_input_focus
+  @memo     Parse input frames and parameters and create a blackboard.
+  @param    cpl_cfg pointer to parameterlist
+  @param    sof pointer to input set of frames
+  @param    stk pointer to input set of stacked frames
+  @return   1 newly allocated focus_config blackboard structure.
+  @doc
+
+  The requested ini file is parsed and a blackboard object is created, then
+  updated accordingly. Returns NULL in case of error.
+ */
+focus_config * 
+sinfo_parse_cpl_input_focus(cpl_parameterlist * cpl_cfg, 
+                            cpl_frameset* sof, 
+                            cpl_frameset** stk) ;
+
+#endif
diff --git a/sinfoni/sinfo_function_1d.c b/sinfoni/sinfo_function_1d.c
new file mode 100644
index 0000000..736b38c
--- /dev/null
+++ b/sinfoni/sinfo_function_1d.c
@@ -0,0 +1,995 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+   
+   File name     :    function_1d.c
+   Author         :    Nicolas Devillard
+   Created on    :    Tue, Sept 23 1997    
+   Description    :    1d signal processing related routines    
+
+ ---------------------------------------------------------------------------*/
+/*
+ $Id: sinfo_function_1d.c,v 1.7 2012/03/02 08:42:20 amodigli Exp $
+ $Author: amodigli $
+ $Date: 2012/03/02 08:42:20 $
+ $Revision: 1.7 $
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+/*----------------------------------------------------------------------------
+                                   Includes
+ ---------------------------------------------------------------------------*/
+#include <math.h>
+#include <string.h>
+#include "sinfo_function_1d.h"
+#include "sinfo_fit_curve.h"
+#include "sinfo_median.h"
+
+/**@{*/
+/**
+ * @defgroup sinfo_function_1d 1d functions
+ *
+ * TBD
+ */
+
+
+/*----------------------------------------------------------------------------
+                                   Defines
+ ---------------------------------------------------------------------------*/
+/*
+ * This parameter sets up the half size of the domain around which a
+ * centroid position will be computed.
+ */
+#define HALF_CENTROID_DOMAIN    5
+/*----------------------------------------------------------------------------
+                        Private function prototypes
+ ---------------------------------------------------------------------------*/
+static double * function1d_generate_smooth_kernel(int filt_type, int hw);
+
+static int
+function1d_search_value(
+    pixelvalue  *   x,
+    int             len,
+    pixelvalue      key,
+    int         *   foundPtr
+) ;
+
+/*----------------------------------------------------------------------------
+                              Function codes
+ ---------------------------------------------------------------------------*/
+/**
+  @name        sinfo_function1d_new
+  @memo        Allocates a new array of pixelvalues.
+  @param    nsamples    Number of values to store in the array.
+  @return    Pointer to newly allocated array of pixelvalues.
+  @doc
+
+  The returned array must be freed using sinfo_function1d_del(), 
+  not cpl_free().
+  This is in case some further housekeeping attributes are allocated
+  together with the object in the future.
+
+  Returns NULL in case of error.
+
+ */
+
+pixelvalue *
+sinfo_function1d_new(int nsamples)
+{
+    if (nsamples<1) return NULL ;
+    return cpl_calloc(nsamples, sizeof(pixelvalue)) ;
+}
+
+
+/**
+  @name        sinfo_function1d_del
+  @memo        Deallocate an array of pixelvalues.
+  @param    s    Array to deallocate.
+  @return    void
+  @doc
+
+  Deallocates an array allocated by sinfo_function1d_new().
+ */
+void 
+sinfo_function1d_del(pixelvalue * s)
+{
+    if (s)
+        cpl_free(s);
+    return ;
+}
+
+/**
+  @name        sinfo_function1d_dup
+  @memo        Copy an array of pixelvalues to a new array.
+  @param    arr        Array to copy.
+  @param    ns        Number of samples in the array.
+  @return    Pointer to newly allocated array of pixelvalues.
+  @doc
+
+  Creates a new array using sinfo_function1d_new(), with the same number of
+  samples as the input signal, then copies over all values from source
+  to destination array using memcpy().
+
+  The returned array must be freed using sinfo_function1d_del(), 
+  not cpl_free().
+
+ */
+pixelvalue * 
+sinfo_function1d_dup(pixelvalue * arr, int ns)
+{
+    pixelvalue    *    n_arr ;
+
+    n_arr = sinfo_function1d_new(ns);
+    memcpy(n_arr, arr, ns * sizeof(pixelvalue));
+    return n_arr ;
+}
+
+/**
+  @name        sinfo_function1d_find_centroid
+  @memo        Find out a line centroid to subpixel precision.
+  @param    line    Array of pixels.
+  @param    npix    Number of pixels in the array.
+  @return    Centroid position as a double.
+  @doc
+
+  The input signal is assumed to be flat almost everywhere, with a
+  single peak somewhere around the middle. Other kinds of signals are
+  not handled correctly.
+
+  The position of the peak is located to subpixel precision by
+  simply weighting positions with pixelvalues.
+ */
+double
+sinfo_function1d_find_centroid(
+    pixelvalue    *    line,    /*    the input line    */
+    int    npix    /*     number of pixels in this line    */
+)
+{
+    pixelvalue    max ;
+    double        centroid ;
+    double        weights ;
+    int            i, maxpos ;
+
+    /*
+     * Search for the maximum pixel value on the line
+     */
+
+    max = line[0] ;
+    maxpos = 0 ;
+    for (i=1 ; i<npix ; i++) {
+        if (line[i]>max) {
+            max = line[i] ;
+            maxpos = i ;
+        }
+    }
+
+    /*
+     * The centroid position is the weighted average over the maximum 
+     * pixel neighborhood.
+     */
+
+    centroid = 0.0 ;
+    weights  = 0.0 ;
+    for (i=maxpos-HALF_CENTROID_DOMAIN; 
+            i<=maxpos+HALF_CENTROID_DOMAIN; i++) {
+        centroid += (double)line[i] * (double)i ;
+        weights  += (double)line[i] ;
+    }
+
+    centroid /= weights ;
+    return centroid ;    
+}
+
+/**
+  @name        sinfo_function1d_find_locmax
+  @memo        Find out a local maximum in a 1d signal around a position.
+  @param    line    Array of pixels.
+  @param    npix    Number of pixels in the array.
+  @param    where    Where to look around.
+  @param    hs        Half-size of the search domain.
+  @return    Local maximum position as a double.
+  @doc
+
+  The closest local maximum to the given position is located to subpixel
+  precision. This precision is achieved by simply weighting positions with
+  pixelvalues.
+
+  The 'where' parameter indicates where to look for a maximum as an index
+  in the array, i.e. it must lie between 0 and npix-1 (inclusive). The 'hs'
+  parameter indicates the half-size of the search domain, i.e. if hs=5 a
+  local maximum will be searched +/-5 pixels around the requested position.
+
+  Returns a negative value if an error occurred.
+ */
+
+double
+sinfo_function1d_find_locmax(
+    pixelvalue    *    line,
+    int                npix,
+    int                where,
+    int                hs
+)
+{
+    pixelvalue    max ;
+    double        centroid ;
+    double        weights ;
+    int            i, maxpos ;
+
+
+    if ((where<hs) || (where>(npix-hs-1))) {
+        return (double)-1.0 ;
+    }
+    
+    /*
+     * Search for the closest local maximal around the requested range.
+     */
+    max = line[where] ;
+    maxpos = where ;
+    for (i=-hs ; i<=hs ; i++) {
+        if (line[where+i]>max) {
+            max = line[where+i] ;
+            maxpos = where+i ;
+        }
+    }
+
+    /*
+     * The centroid position is the weighted average over the maximum 
+     * pixel neighborhood.
+     */
+
+    centroid = 0.0 ;
+    weights  = 0.0 ;
+    for (i=maxpos-hs; i<=maxpos+hs; i++) {
+        centroid += (double)line[i] * (double)i ;
+        weights  += (double)line[i] ;
+    }
+    if (fabs(weights)>1e-6) {
+        centroid /= weights ;
+    } else {
+        centroid = -1.0 ;
+    }
+    return centroid ;    
+}
+
+/**
+  @name        sinfo_function1d_filter_lowpass
+  @memo        Apply a low-pass filter to a 1d signal.
+  @param    input_sig    Input signal
+  @param    samples        Number of samples in the signal
+  @param    filter_type    Type of filter to use.
+  @param    hw            Filter half-width.
+  @return    Pointer to newly allocated array of pixels.
+  @doc
+
+  This kind of low-pass filtering consists in a convolution with a
+  given kernel. The chosen filter type determines the kind of kernel
+  to apply for convolution. Possible kernels and associated symbols
+  can be found in function_1d.h.
+
+  Smoothing the signal is done by applying this kind of low-pass
+  filter several times.
+
+  The returned smooth signal has been allocated using
+  sinfo_function1d_new(), it must be freed using sinfo_function1d_del(). The
+  returned signal has exactly as many samples as the input signal.
+
+ */
+
+pixelvalue *
+sinfo_function1d_filter_lowpass(
+    pixelvalue    *    input_sig,
+    int                samples,
+    int                filter_type,
+    int                hw
+)
+{
+    pixelvalue    *    out_sig ;
+    int                i, j ;
+    double            replace ;
+    double        *    kernel ;
+
+    /* allocate output signal */
+    out_sig = sinfo_function1d_new(samples);
+
+    /* generate low-pass filter kernel */
+    kernel = function1d_generate_smooth_kernel(filter_type, hw) ;
+
+    /* compute sinfo_edge effects for the first hw elements */
+    for (i=0 ; i<hw ; i++) {
+        replace = 0.0 ;
+        for (j=-hw ; j<=hw ; j++) {
+            if (i+j<0) {
+                replace += kernel[hw+j] * (double)input_sig[0] ;
+            } else {
+                replace += kernel[hw+j] * (double)input_sig[i+j] ;
+            }
+        }
+        out_sig[i] = (pixelvalue)replace ;
+    }
+
+    /* compute sinfo_edge effects for the last hw elements */
+    for (i=samples-hw ; i<samples ; i++) {
+        replace = 0.0 ;
+        for (j=-hw ; j<=hw ; j++) {
+            if (i+j>samples-1) {
+                replace += kernel[hw+j] * (double)input_sig[samples-1] ;
+            } else {
+                replace += kernel[hw+j] * (double)input_sig[i+j] ;
+            }
+        }
+        out_sig[i] = (pixelvalue)replace ;
+    }
+
+    /* compute all other elements */
+    for (i=hw ; i<samples-hw ; i++) {
+        replace = 0.0 ;
+        for (j=-hw ; j<=hw ; j++) {
+            replace += kernel[hw+j] * (double)input_sig[i+j] ;
+        }
+        out_sig[i] = (pixelvalue)replace ;
+    }
+
+    cpl_free(kernel) ;
+    return out_sig ;
+
+}
+
+/**
+  @name        function1d_generate_smooth_kernel
+  @memo        Generate a kernel for smoothing filters (low-pass).
+  @param    filt_type    Type of kernel to generate.
+  @param    hw            Kernel half-width.
+  @return    Pointer to newly allocated kernel.
+  @doc
+
+  Supported kernels can be found in function_1d.h
+
+  The returned array has been allocated with cpl_calloc(), it must be
+  freed using cpl_free(). The returned array contains 2h+1 doubles, where
+  h is the kernel half-width.
+
+ */
+
+static double * 
+function1d_generate_smooth_kernel(int filt_type, int hw)
+{
+    double  *   kernel ;
+    double      norm ;
+    int         i ;
+
+    kernel = (double*)cpl_calloc(2*hw+1, sizeof(double)) ;
+
+    switch(filt_type) {
+
+        case LOW_PASS_LINEAR:
+        for (i=-hw ; i<=hw ; i++) {
+            /* flat kernel */
+            kernel[hw+i] = 1.0 / (double)(2*hw+1) ;
+        }
+        break ;
+
+        case LOW_PASS_GAUSSIAN:
+        norm = 0.00 ;
+        for (i=-hw ; i<=hw ; i++) {
+            /* sinfo_gaussian kernel */
+            kernel[hw+i] = exp(-(double)(i*i)) ;
+            norm += kernel[hw+i] ;
+        }
+        for (i=0 ; i<2*hw+1 ; i++) {
+            kernel[i] /= norm ;
+        }
+        break ;
+
+        default:
+        sinfo_msg_error("unrecognized low pass filter: "
+                                "cannot generate kernel") ;
+        return (double*)NULL ;
+        break ;
+    }
+
+    return kernel ;
+}
+
+/**
+  @name        sinfo_function1d_median_smooth
+  @memo        Apply a 1d sinfo_median filter of given half-width.
+  @param    list        List of input pixelvalues.
+  @param    np            Number of points in the list.
+  @param    hw            Filter half-width.
+  @return    Pointer to newly allocated array of pixelvalues.
+  @doc
+
+  This function applies a sinfo_median smoothing to a given signal and
+  returns a newly allocated signal containing a sinfo_median-smoothed
+  version of the input. The returned array has exactly as many samples
+  as the input array. It has been allocated using sinfo_function1d_new() and
+  must be deallocated using sinfo_function1d_del().
+
+  For half-widths of 1,2,3,4, the filtering is optimized for speed.
+ */
+
+pixelvalue * 
+sinfo_function1d_median_smooth(
+    pixelvalue * list,
+    int          np,
+    int             hw)
+{
+    int             i,j ;
+    pixelvalue    *    row ;
+    pixelvalue    *     smoothed ;
+
+    /* simply copy first 3 and last 3 items */
+    smoothed = sinfo_function1d_new(np);
+    for (i=0 ; i<hw ; i++) {
+        smoothed[i] = list[i] ;
+    }
+    for (i=np-hw ; i<np ; i++) {
+        smoothed[i] = list[i] ;
+    }
+
+    /* sinfo_median filter on all central items */
+    row = sinfo_function1d_new(2*hw+1);
+    for (i=hw ; i<np-hw ; i++) {
+        for (j=-hw ; j<=hw ; j++) {
+            row[j+hw] = list[i+j] ;
+        }
+        smoothed[i] = sinfo_median_pixelvalue(row, 2*hw+1) ; 
+    }
+    sinfo_function1d_del(row) ;
+    return smoothed ;
+}
+
+/**
+  @name        sinfo_function1d_remove_lowfreq
+  @memo        Subtract low-frequency components from a signal.
+  @param    pixel_signal    Input signal.
+  @param    ns        Number of samples.
+  @return    Pointer to newly allocated array of pixelvalues.
+  @doc
+
+  The returned signal is such as: out = in - smooth(in).
+
+  The returned array has been allocated using sinfo_function1d_dup(), it
+  must be deallocated using sinfo_function1d_del(). The returned array has
+  exactly as many elements as the input array.
+
+ */
+
+#define LOWFREQ_PASSES        5
+
+pixelvalue * 
+sinfo_function1d_remove_lowfreq(
+    pixelvalue * pixel_signal,
+    int             ns)
+{
+    pixelvalue    *    sig_in ;
+    pixelvalue    *    smooth ;
+    int                i ;
+    
+    
+    /* Apply severe low-pass filter several times */
+    sig_in = sinfo_function1d_dup(pixel_signal, ns);
+    for (i=0 ; i<LOWFREQ_PASSES ; i++) {
+        smooth = sinfo_function1d_filter_lowpass( sig_in, ns, 
+                         LOW_PASS_LINEAR, 5);
+        cpl_free(sig_in);
+        sig_in = smooth ;
+    }
+
+    /* Subtract smoothed signal from input signal */
+    for (i=0 ; i<ns ; i++) {
+        smooth[i] = pixel_signal[i] - smooth[i];
+    }
+    return smooth ;
+}
+
+#undef LOWFREQ_PASSES
+
+/**
+  @name        sinfo_function1d_remove_thermalbg
+  @memo        Remove thermal background from a signal.
+  @param    pixel_signal    Input signal.
+  @param    ns        Number of samples in the input signal.
+  @return    Pointer to newly allocated array of pixelvalues.
+  @doc
+
+  Many assumptions are made about the input signal. What is expected
+  is typically the a collapsed image taken in K band, where the
+  thermal background is rising as an exponential of the wavelength.
+
+  This function tries to remove the thermal background contribution by
+  first estimating it, then interpolating missing background values,
+  and finally subtracting it from the input signal.
+
+  The returned array has been allocated using sinfo_function1d_new(), it
+  must be freed using sinfo_function1d_del(). The returned array has exactly
+  as many samples as the input array.
+ */
+
+#define SAMPLE_BORDER    10
+
+pixelvalue * 
+sinfo_function1d_remove_thermalbg(
+    pixelvalue * pixel_signal,
+    int             ns)
+{
+    pixelvalue    *    smooth ;
+    int                i ;
+    
+    int                nmin ;
+    pixelvalue        lef[2], rig[2];
+
+    pixelvalue    *    x,
+                *    y,
+                *    spl_x,
+                *    spl_y ;
+    double            med_y ;
+    double            avg2med ;
+    double            dist ;
+
+    
+    /* Detect all local minima */
+    nmin = 0 ;
+    x = sinfo_function1d_new(ns);
+    y = sinfo_function1d_new(ns);
+
+    for (i=SAMPLE_BORDER ; i<(ns-SAMPLE_BORDER) ; i++) {
+        lef[0] = pixel_signal[i-2];
+        lef[1] = pixel_signal[i-1];
+        rig[0] = pixel_signal[i+1];
+        rig[1] = pixel_signal[i+2];
+
+        if ( (pixel_signal[i] < lef[0]) &&
+             (pixel_signal[i] < lef[1]) &&
+             (pixel_signal[i] < rig[0]) &&
+             (pixel_signal[i] < rig[1])) {
+            x[nmin] = (pixelvalue)i ;
+            y[nmin] = pixel_signal[i];
+            nmin ++ ;
+        }
+    }
+
+
+    /* Interpolate linearly missing values */
+    spl_x = sinfo_function1d_new(ns);
+    spl_y = sinfo_function1d_new(ns);
+    for (i=0 ; i<ns ; i++) {
+        spl_x[i] = (pixelvalue)i ;
+    }
+    sinfo_function1d_interpolate_linear(x, y, nmin, spl_x, spl_y, ns);
+
+    sinfo_function1d_del(x) ;
+    sinfo_function1d_del(y) ;
+    sinfo_function1d_del(spl_x);
+
+    /* Compute sinfo_median and average distance to the sinfo_median */
+    med_y = (double)sinfo_median_pixelvalue(pixel_signal, ns);
+    avg2med = 0.0 ;
+    for (i=0 ; i<ns ; i++) {
+        avg2med += fabs((double)pixel_signal[i] - med_y) ;
+    }
+    avg2med /= (double)ns ;
+
+    /* Reset all pixels out of sinfo_median + 2 * avg2med to zero. */
+    for (i=0 ; i<ns ; i++) {
+        dist = fabs((double)pixel_signal[i] - med_y);
+        if (dist > (2.0*avg2med)) {
+            spl_y[i] = (pixelvalue)0 ;
+        }
+    }
+
+
+    smooth = sinfo_function1d_new(ns);
+    for (i=0 ; i<ns ; i++) {
+        if (spl_y[i]>1e-4) {
+            smooth[i] = pixel_signal[i] - spl_y[i];
+        } else {
+            smooth[i] = 0.0 ;
+        }
+    }
+    sinfo_function1d_del(spl_y);
+    return smooth ;
+}
+
+#undef LOWFREQ_PASSES
+
+/**
+  @name        sinfo_function1d_interpolate_linear
+  @memo        Linear signal interpolation.
+  @param    x        Input list of x positions.
+  @param    y        Input list of y positions.
+  @param    len        Number of samples in x and y.
+  @param    spl_x    List of abscissas where the signal must be computed.
+  @param    spl_y    Output list of computed signal values.
+  @param    spl_len    Number of samples in spl_x and spl_y.
+  @return    void
+  @doc
+
+  To apply this interpolation, you need to provide a list of x and y
+  positions, and a list of x positions where you want y to be computed
+  (with linear interpolation).
+
+  The returned signal has spl_len samples. It has been allocated using
+  sinfo_function1d_new() and must be deallocated using sinfo_function1d_del().
+
+ */
+
+void 
+sinfo_function1d_interpolate_linear(
+    pixelvalue    *    x,
+    pixelvalue    *    y,
+    int                len,
+    pixelvalue    *    spl_x,
+    pixelvalue    *    spl_y,
+    int                spl_len
+)
+{
+    double        a, b ;
+    int            i, j ;
+    int            found ;
+
+    for (i=0 ; i<spl_len ; i++) {
+        /* Find (x1,y1) on the left of the current point */
+        found = 0 ;
+        for (j=0 ; j<(len-1) ; j++) {
+            if ((spl_x[i]>=x[j]) && (spl_x[i]<=x[j+1])) {
+                found++ ;
+                break ;
+            }
+        }
+        if (!found) {
+            spl_y[i] = 0.0;
+        } else {
+            a = ((double)y[j+1]-(double)y[j]) /
+                ((double)x[j+1]-(double)x[j]);
+            b = (double)y[j] - a * (double)x[j] ;
+            spl_y[i] = (pixelvalue)(a * (double)spl_x[i] + b) ;
+        }
+    }
+    return ;
+}
+
+/**
+  @name        function1d_search_value
+  @memo        Conducts a binary search for a value.
+  @param    x     Contains the abscissas of interpolation.
+  @param    len     Length of the x array.
+  @param    key     The value to locate in x.
+  @param    foundPtr Output flag, 1 if value was found, else 0.
+  @return    The index of the largest value in x for which x[i]<key.
+  @doc
+
+  This function does a binary search for a value in an array. This
+  routine is to be called only if key is in the interval between x[0]
+  and x[len-1]. The input x array is supposed sorted.
+
+ */
+
+static int
+function1d_search_value(
+    pixelvalue    *    x,
+    int             len,
+    pixelvalue         key,
+    int         *    foundPtr
+)
+{
+    int    high,
+        low,
+        middle;
+
+    low  = 0;
+    high = len - 1;
+
+    while (high >= low) {
+        middle = (high + low) / 2;
+        if (key > x[middle]) {
+            low = middle + 1;
+        } else if (key < x[middle]) {
+            high = middle - 1;
+        } else {
+            *foundPtr = 1;
+            return (middle);
+        }
+    }
+    *foundPtr = 0;
+    return (low);
+}
+
+/**
+  @name        sinfo_function1d_natural_spline
+  @memo        Interpolate a sinfo_vector along new abscissas.
+  @param    x        List of x positions.
+  @param    y        List of y positions.
+  @param    len        Number of samples in x and y.
+  @param    splX    Input new list of x positions.
+  @param    splY    Output list of interpolated y positions.
+  @param    splLen    Number of samples in splX and splY.
+  @return    Int 0 if Ok, -1 if error.
+  @doc
+
+  Reference:
+
+  \begin{verbatim}
+      Numerical Analysis, R. Burden, J. Faires and A. Reynolds.
+      Prindle, Weber & Schmidt 1981 pp 112
+  \end{verbatim}
+
+  Provide in input a known list of x and y values, and a list where
+  you want the signal to be interpolated. The returned signal is
+  written into splY.
+
+ */
+
+int
+sinfo_function1d_natural_spline(
+    pixelvalue    *     x,
+    pixelvalue    *     y,
+    int             len,
+    pixelvalue    *     splX,
+    pixelvalue    *     splY,
+    int             splLen
+)
+{
+    int             end;
+    int             loc,
+                    found;
+    register int     i,
+                    j,
+                    n;
+    double         *    h; /* sinfo_vector of deltas in x */
+    double         *    alpha;
+    double         *    l,
+                *    mu,
+                *    z,
+                *    a,
+                *    b,
+                *    c,
+                *    d,
+                    v;
+
+    end = len - 1;
+
+    a = cpl_malloc(sizeof(double) * splLen * 9) ;
+    b = a + len;
+    c = b + len;
+    d = c + len;
+    h = d + len;
+    l = h + len;
+    z = l + len;
+    mu = z + len;
+    alpha = mu + len;
+
+    for (i = 0; i < len; i++) {
+        a[i] = (double)y[i];
+    }
+
+    /* Calculate sinfo_vector of differences */
+    for (i = 0; i < end; i++) {
+        h[i] = (double)x[i + 1] - (double)x[i];
+        if (h[i] < 0.0) {
+            cpl_free(a) ;
+            return -1;
+        }
+    }
+
+    /* Calculate alpha sinfo_vector */
+    for (n = 0, i = 1; i < end; i++, n++) {
+        /* n = i - 1 */
+        alpha[i] = 3.0 * ((a[i+1] / h[i]) - (a[i] / h[n]) - (a[i] / h[i]) +
+                  (a[n] / h[n]));
+    }
+
+    /* Vectors to solve the tridiagonal sinfo_matrix */
+    l[0] = l[end] = 1.0;
+    mu[0] = mu[end] = 0.0;
+    z[0] = z[end] = 0.0;
+    c[0] = c[end] = 0.0;
+
+    /* Calculate the intermediate results */
+    for (n = 0, i = 1; i < end; i++, n++) {
+        /* n = i-1 */
+        l[i] = 2 * (h[i] + h[n]) - h[n] * mu[n];
+        mu[i] = h[i] / l[i];
+        z[i] = (alpha[i] - h[n] * z[n]) / l[i];
+    }
+    for (n = end, j = end - 1; j >= 0; j--, n--) {
+        /* n = j + 1 */
+        c[j] = z[j] - mu[j] * c[n];
+        b[j] = (a[n] - a[j]) / h[j] - h[j] * (c[n] + 2.0 * c[j]) / 3.0;
+        d[j] = (c[n] - c[j]) / (3.0 * h[j]);
+    }
+
+    /* Now calculate the new values */
+    for (j = 0; j < splLen; j++) {
+         v = (double)splX[j];
+     splY[j] = (pixelvalue)0;
+
+     /* Is it outside the interval? */
+     if ((v < (double)x[0]) || (v > (double)x[end])) {
+        continue;
+     }
+     /* Search for the interval containing v in the x sinfo_vector */
+     loc = function1d_search_value(x, len, (pixelvalue)v, &found);
+     if (found) {
+        splY[j] = y[loc];
+     } else {
+        loc--;
+        v -= (double)x[loc];
+        splY[j] = (pixelvalue)(    a[loc] +
+                        v * (b[loc] +
+                   v * (c[loc] +
+                    v * d[loc])));
+        }
+    }
+    cpl_free(a) ;
+    return 0;
+}
+
+/**
+  @name        sinfo_function1d_average_reject
+  @memo        Sorts the input signal, takes out highest and lowest
+          values, and returns the average of the remaining pixels.
+  @param    line        Input signal.
+  @param    npix        Number of samples in the input signal.
+  @param    pix_low        Number of lowest pixels to reject.
+  @param    pix_high    Number of highest pixels to reject.
+  @return    The filtered average of the input signal.
+  @doc
+
+  No input parameter is modified.
+
+  The input signal is first copied. This copy is then sorted, and the
+  highest and lowest pixels are taken out of the list. Remaining
+  pixelvalues are averaged and the result is returned.
+ */
+
+pixelvalue
+sinfo_function1d_average_reject(
+    pixelvalue    *    line,
+    int                npix,
+    int                pix_low,
+    int                pix_high)
+{
+    pixelvalue    *    sorted ;
+    int                i ;
+    double            avg ;
+
+    /* Sanity tests */
+    if ((line==NULL) || (npix<1)) return (pixelvalue)0 ;
+    if ((pix_low+pix_high)>=npix) return (pixelvalue)0 ;
+
+    /* Copy input line and sort it */
+    sorted = cpl_malloc(npix * sizeof(pixelvalue)) ;
+    memcpy(sorted, line, npix * sizeof(pixelvalue)) ;
+    sinfo_pixel_qsort(sorted, npix);
+
+    /* Find out average of remaining values */
+    avg = 0.00 ;
+    for (i=pix_low+1 ; i<(npix-pix_high) ; i++) {
+        avg += (double)sorted[i] ;
+    }
+    cpl_free(sorted);
+    avg /= (double)(npix - pix_high - pix_low) ;
+
+    return (pixelvalue)avg ;
+}
+
+/**
+  @name        sinfo_function1d_xcorrelate
+  @memo        Cross-sinfo_correlation of two 1d signals.
+  @param    line_i        The reference signal.
+  @param    width_i        Number of samples in reference signal.
+  @param    line_t        Candidate signal to compare.
+  @param    width_t        Number of samples in candidate signal.
+  @param    half_search    Half-size of the search domain.
+  @param    delta        Output sinfo_correlation offset.
+  @return    Maximum cross-sinfo_correlation value as a double.
+  @doc
+
+  Two signals are expected in input of this function: a reference
+  signal and a candidate signal. They are expected to be roughly the
+  same signal up to an offset.
+
+  A cross-sinfo_correlation is computed on 2*half_search+1 values. The
+  maximum of likelihood is the maximum cross-sinfo_correlation value between
+  signals. The offset corresponding to this position is returned.
+
+  Returns -100.0 in case of error. Normally, the cross-sinfo_correlation
+  coefficient is normalized so it should stay between -1 and +1.
+ */
+
+
+#define STEP_MIN    (-half_search)
+#define STEP_MAX    (half_search)
+
+double 
+sinfo_function1d_xcorrelate(
+    pixelvalue *    line_i,
+    int             width_i,
+    pixelvalue *    line_t,
+    int             width_t,
+    int                half_search,
+    double     *    delta
+)
+{
+    double * xcorr ;
+    double   xcorr_max ;
+    double   mean_i, mean_t ;
+    double   rms_i, rms_t ;
+    double   sum, sqsum ;
+    double   norm ;
+    int      maxpos ;
+    int      nsteps ;
+    int      i ;
+    int      step ;
+    int      nval ;
+
+
+    /* Compute normalization factors */
+    sum = sqsum = 0.00 ;
+    for (i=0 ; i<width_i ; i++) {
+        sum += (double)line_i[i] ;
+        sqsum += (double)line_i[i] * (double)line_i[i];
+    }
+    mean_i = sum / (double)width_i ;
+    sqsum /= (double)width_i ;
+    rms_i = sqsum - mean_i*mean_i ;
+
+    sum = sqsum = 0.00 ;
+    for (i=0 ; i<width_t ; i++) {
+        sum += (double)line_t[i] ;
+        sqsum += (double)line_t[i] * (double)line_t[i];
+    }
+    mean_t = sum / (double)width_t ;
+    sqsum /= (double)width_t ;
+    rms_t = sqsum - mean_t*mean_t ;
+
+    norm = 1.00 / sqrt(rms_i * rms_t);
+
+    nsteps = (STEP_MAX - STEP_MIN) +1 ;
+    xcorr = cpl_malloc(nsteps * sizeof(double));
+    for (step=STEP_MIN ; step<=STEP_MAX ; step++) {
+        xcorr[step-STEP_MIN] = 0.00 ;
+        nval = 0 ;
+        for (i=0 ; i<width_t ; i++) {
+            if ((i+step > 0) &&
+                (i+step < width_i)) {
+            xcorr[step-STEP_MIN] += ((double)line_t[i] - mean_t) *
+                                    ((double)line_i[i+step] - mean_i) *
+                                    norm ;
+                nval++ ;
+            }
+        }
+        xcorr[step-STEP_MIN] /= (double)nval ;
+    }
+    xcorr_max = xcorr[0] ;
+    maxpos    = 0 ;
+    for (i=0 ; i<nsteps ; i++) {
+        if (xcorr[i]>xcorr_max) {
+            maxpos = i ;
+            xcorr_max = xcorr[i];
+        }
+    }
+    cpl_free(xcorr);
+    (*delta) = + ((double)STEP_MIN + (double)maxpos);
+    return xcorr_max ;
+}
+/**@}*/
diff --git a/sinfoni/sinfo_function_1d.h b/sinfoni/sinfo_function_1d.h
new file mode 100644
index 0000000..f4d09ca
--- /dev/null
+++ b/sinfoni/sinfo_function_1d.h
@@ -0,0 +1,383 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+   
+   File name     :    sinfo_function_1d.h
+   Author         :    Nicolas Devillard
+   Created on    :    Tue, Sept 23 1997    
+   Description    :    1d signal processing related routines    
+ ---------------------------------------------------------------------------*/
+/*
+ $Id: sinfo_function_1d.h,v 1.6 2008/03/25 08:20:43 amodigli Exp $
+ $Author: amodigli $
+ $Date: 2008/03/25 08:20:43 $
+ $Revision: 1.6 $
+ */
+#ifndef SINFO_FUNCTION_1D_H
+#define SINFO_FUNCTION_1D_H
+/*----------------------------------------------------------------------------
+                                   Includes
+ ---------------------------------------------------------------------------*/
+#include <math.h>
+#include "sinfo_local_types.h"
+#include "sinfo_pixel_handling.h"
+#include "sinfo_msg.h"
+#include <cpl.h>
+/*----------------------------------------------------------------------------
+                                   Defines
+ ---------------------------------------------------------------------------*/
+/* Low pass filter types: */
+
+#define LOW_PASS_LINEAR            100
+#define LOW_PASS_GAUSSIAN        101
+/*----------------------------------------------------------------------------
+                          Function ANSI C prototypes
+ ---------------------------------------------------------------------------*/
+/**
+  @name     sinfo_function1d_new
+  @memo     Allocates a new array of pixelvalues.
+  @param    nsamples    Number of values to store in the array.
+  @return   Pointer to newly allocated array of pixelvalues.
+  @doc
+ 
+  The returned array must be freed using sinfo_function1d_del(), not free().
+  This is in case some further housekeeping attributes are allocated
+  together with the object in the future.
+ 
+  Returns NULL in case of error.
+ 
+ */
+
+pixelvalue * 
+sinfo_function1d_new(int nsamples);
+
+/**
+  @name     sinfo_function1d_del
+  @memo     Deallocate an array of pixelvalues.
+  @param    s   Array to deallocate.
+  @return   void
+  @doc
+ 
+  Deallocates an array allocated by sinfo_function1d_new().
+ */
+void 
+sinfo_function1d_del(pixelvalue * s);
+/**
+  @name     sinfo_function1d_dup
+  @memo     Copy an array of pixelvalues to a new array.
+  @param    arr     Array to copy.
+  @param    ns      Number of samples in the array.
+  @return   Pointer to newly allocated array of pixelvalues.
+  @doc
+ 
+  Creates a new array using sinfo_function1d_new(), with the same number of
+  samples as the input signal, then copies over all values from source
+  to destination array using memcpy().
+ 
+  The returned array must be freed using sinfo_function1d_del(), not free().
+ 
+ */
+
+pixelvalue * 
+sinfo_function1d_dup(pixelvalue * arr, int ns);
+
+/**
+  @name     sinfo_function1d_find_centroid
+  @memo     Find out a line centroid to subpixel precision.
+  @param    line    Array of pixels.
+  @param    npix    Number of pixels in the array.
+  Centroid position as a double.
+  @doc
+ 
+  The input signal is assumed to be flat almost everywhere, with a
+  single peak somewhere around the middle. Other kinds of signals are
+  not handled correctly.
+ 
+  The position of the peak is located to subpixel precision by
+  simply weighting positions with pixelvalues.
+ */
+
+double
+sinfo_function1d_find_centroid(
+    pixelvalue  *   line,   /*  the input line                  */
+    int             npix    /*  number of pixels in this line   */
+);
+
+/**
+  @name     sinfo_function1d_find_locmax
+  @memo     Find out a local maximum in a 1d signal around a position.
+  @param    line    Array of pixels.
+  @param    npix    Number of pixels in the array.
+  @param    where   Where to look around.
+  @param    hs      Half-size of the search domain.
+  @return   Local maximum position as a double.
+  @doc
+ 
+  The closest local maximum to the given position is located to subpixel
+  precision. This precision is achieved by simply weighting positions with
+  pixelvalues.
+ 
+  The 'where' parameter indicates where to look for a maximum as an index
+  in the array, i.e. it must lie between 0 and npix-1 (inclusive). The 'hs'
+  parameter indicates the half-size of the search domain, i.e. if hs=5 a
+  local maximum will be searched +/-5 pixels around the requested position.
+ 
+  Returns a negative value if an error occurred.
+ */
+ 
+double
+sinfo_function1d_find_locmax(
+    pixelvalue  *   line,
+    int             npix,
+    int             where,
+    int             hs
+) ;
+
+
+/**
+  @name     sinfo_function1d_filter_lowpass
+  @memo     Apply a low-pass filter to a 1d signal.
+  @param    input_sig   Input signal
+  @param    samples     Number of samples in the signal
+  @param    filter_type Type of filter to use.
+  @param    hw          Filter half-width.
+  @return   Pointer to newly allocated array of pixels.
+  @doc
+ 
+  This kind of low-pass filtering consists in a convolution with a
+  given kernel. The chosen filter type determines the kind of kernel
+  to apply for convolution. Possible kernels and associated symbols
+  can be found in function_1d.h.
+ 
+  Smoothing the signal is done by applying this kind of low-pass
+  filter several times.
+ 
+  The returned smooth signal has been allocated using
+  sinfo_function1d_new(), it must be freed using sinfo_function1d_del(). The
+  returned signal has exactly as many samples as the input signal.
+ 
+ */
+
+pixelvalue *
+sinfo_function1d_filter_lowpass(
+    pixelvalue  *   input_sig,
+    int             samples,
+    int             filter_type,
+    int             hw
+) ;
+
+/**
+  @name     sinfo_function1d_median_smooth
+  @memo     Apply a 1d sinfo_median filter of given half-width.
+  @param    list        List of input pixelvalues.
+  @param    np          Number of points in the list.
+  @param    hw          Filter half-width.
+  @return   Pointer to newly allocated array of pixelvalues.
+  @doc
+ 
+  This function applies a sinfo_median smoothing to a given signal and
+  returns a newly allocated signal containing a sinfo_median-smoothed
+  version of the input. The returned array has exactly as many samples
+  as the input array. It has been allocated using sinfo_function1d_new() and
+  must be deallocated using sinfo_function1d_del().
+ 
+  For half-widths of 1,2,3,4, the filtering is optimized for speed.
+ */
+ 
+pixelvalue * 
+sinfo_function1d_median_smooth(
+    pixelvalue * list,
+    int          np,
+    int          hw);
+
+/**
+  @name     sinfo_function1d_remove_lowfreq
+  @memo     Subtract low-frequency components from a signal.
+  @param    loc_signal  Input signal.
+  @param    ns      Number of samples.
+  @return   Pointer to newly allocated array of pixelvalues.
+  @doc
+ 
+  The returned signal is such as: out = in - smooth(in).
+ 
+  The returned array has been allocated using sinfo_function1d_dup(), it
+  must be deallocated using sinfo_function1d_del(). The returned array has
+  exactly as many elements as the input array.
+ 
+ */
+
+pixelvalue * 
+sinfo_function1d_remove_lowfreq(
+    pixelvalue * loc_signal,
+    int          ns);
+
+/**
+  @name     sinfo_function1d_remove_thermalbg
+  @memo     Remove thermal background from a signal.
+  @param    pixel_signal  Input signal.
+  @param    ns      Number of samples in the input signal.
+  @return   Pointer to newly allocated array of pixelvalues.
+  @doc
+ 
+  Many assumptions are made about the input signal. What is expected
+  is typically the a collapsed image taken in K band, where the
+  thermal background is rising as an exponential of the wavelength.
+ 
+  This function tries to remove the thermal background contribution by
+  first estimating it, then interpolating missing background values,
+  and finally subtracting it from the input signal.
+ 
+  The returned array has been allocated using sinfo_function1d_new(), it
+  must be freed using sinfo_function1d_del(). The returned array has exactly
+  as many samples as the input array.
+ */
+
+pixelvalue * 
+sinfo_function1d_remove_thermalbg(
+    pixelvalue * pixel_signal,
+    int          ns);
+
+
+/**
+  @name     sinfo_function1d_interpolate_linear
+  @memo     Linear signal interpolation.
+  @param    x       Input list of x positions.
+  @param    y       Input list of y positions.
+  @param    len     Number of samples in x and y.
+  @param    spl_x   List of abscissas where the signal must be computed.
+  @param    spl_y   Output list of computed signal values.
+  @param    spl_len Number of samples in spl_x and spl_y.
+  @return   void
+  @doc
+ 
+  To apply this interpolation, you need to provide a list of x and y
+  positions, and a list of x positions where you want y to be computed
+  (with linear interpolation).
+ 
+  The returned signal has spl_len samples. It has been allocated using
+  sinfo_function1d_new() and must be deallocated using sinfo_function1d_del().
+ 
+ */
+
+void 
+sinfo_function1d_interpolate_linear(
+    pixelvalue  *   x,
+    pixelvalue  *   y,
+    int             len,
+    pixelvalue  *   spl_x,
+    pixelvalue  *   spl_y,
+    int             spl_len
+);
+
+
+/**
+  @name     sinfo_function1d_natural_spline
+  @memo     Interpolate a sinfo_vector along new abscissas.
+  @param    x       List of x positions.
+  @param    y       List of y positions.
+  @param    len     Number of samples in x and y.
+  @param    splX    Input new list of x positions.
+  @param    splY    Output list of interpolated y positions.
+  @param    splLen  Number of samples in splX and splY.
+  @return   Int 0 if Ok, -1 if error.
+  @doc
+ 
+  Reference:
+ 
+  \begin{verbatim}
+    Numerical Analysis, R. Burden, J. Faires and A. Reynolds.
+    Prindle, Weber & Schmidt 1981 pp 112
+  \end{verbatim}
+ 
+  Provide in input a known list of x and y values, and a list where
+  you want the signal to be interpolated. The returned signal is
+  written into splY.
+ 
+ */
+ 
+int
+sinfo_function1d_natural_spline(
+    pixelvalue  *   x,
+    pixelvalue  *   y,
+    int             len,
+    pixelvalue  *   splX,
+    pixelvalue  *   splY,
+    int             splLen
+) ;
+
+
+/**
+  @name     sinfo_function1d_average_reject
+  @memo     Sorts the input signal, takes out highest and lowest
+            values, and returns the average of the remaining pixels.
+  @param    line        Input signal.
+  @param    npix        Number of samples in the input signal.
+  @param    pix_low     Number of lowest pixels to reject.
+  @param    pix_high    Number of highest pixels to reject.
+  @return   The filtered average of the input signal.
+  @doc
+ 
+  No input parameter is modified.
+ 
+  The input signal is first copied. This copy is then sorted, and the
+  highest and lowest pixels are taken out of the list. Remaining
+  pixelvalues are averaged and the result is returned.
+ */
+
+pixelvalue
+sinfo_function1d_average_reject(
+    pixelvalue  *   line,
+    int             npix,
+    int             pix_low,
+    int             pix_high);
+
+/**
+  @name     sinfo_function1d_xcorrelate
+  @memo     Cross-sinfo_correlation of two 1d signals.
+  @param    line_i      The reference signal.
+  @param    width_i     Number of samples in reference signal.
+  @param    line_t      Candidate signal to compare.
+  @param    width_t     Number of samples in candidate signal.
+  @param    half_search Half-size of the search domain.
+  @param    delta       Output sinfo_correlation offset.
+  @return   Maximum cross-sinfo_correlation value as a double.
+  @doc
+ 
+  Two signals are expected in input of this function: a reference
+  signal and a candidate signal. They are expected to be roughly the
+  same signal up to an offset.
+ 
+  A cross-sinfo_correlation is computed on 2*half_search+1 values. The
+  maximum of likelihood is the maximum cross-sinfo_correlation value between
+  signals. The offset corresponding to this position is returned.
+ 
+  Returns -100.0 in case of error. Normally, the cross-sinfo_correlation
+  coefficient is normalized so it should stay between -1 and +1.
+ */
+
+double 
+sinfo_function1d_xcorrelate(
+    pixelvalue *    line_i,
+    int             width_i,
+    pixelvalue *    line_t,
+    int             width_t,
+    int             half_search,
+    double     *    delta);
+
+#endif
diff --git a/sinfoni/sinfo_functions.h b/sinfoni/sinfo_functions.h
new file mode 100644
index 0000000..eeb71b7
--- /dev/null
+++ b/sinfoni/sinfo_functions.h
@@ -0,0 +1,273 @@
+/* $Id: sinfo_functions.h,v 1.13 2009/03/04 10:17:38 amodigli Exp $
+ *
+ * This file is part of the SINFONI Pipeline
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This proram is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2009/03/04 10:17:38 $
+ * $Revision: 1.13 $
+ * $Name: sinfo-2_3_2 $
+ */
+#ifndef SINFO_FUNCTIONS_H
+#define SINFO_FUNCTIONS_H
+
+#include <cpl.h>
+#include <sinfo_time.h>
+#include <sinfo_globals.h>
+#include <sinfo_skycor.h>
+
+int sinfo_print_rec_status(const int val);
+
+cpl_frameset *
+sinfo_frameset_extract(const cpl_frameset *frames,const char *tag);
+
+int 
+sinfo_propertylist_has(cpl_propertylist* plist,const char* key);
+
+cpl_vector* 
+sinfo_vector_clip(const cpl_vector* vinp, 
+                  const double kappa, 
+                  const int n, 
+                  const int method);
+
+
+int
+sinfo_image_estimate_noise(cpl_image* img,
+                            const int noise_fit, 
+                            double* centre, 
+               double* noise);
+
+
+cpl_table* sinfo_compute_gain(cpl_frameset* son, cpl_frameset* sof);
+cpl_table* sinfo_compute_linearity(cpl_frameset* son, cpl_frameset* sof);
+cpl_error_code sinfo_fit_lm(const cpl_matrix *x, 
+                            const cpl_matrix *sigma_x,
+                const cpl_vector *y, 
+                            const cpl_vector *sigma_y,
+                      cpl_vector *a, 
+                            const int ia[],
+                int    (*f)(const double x[], 
+                                        const double a[], 
+                          double *result),
+                 int (*dfda)(const double x[], 
+                                             const double a[], 
+                         double result[]),
+                 double *mse,
+                 double *red_chisq,
+                 cpl_matrix **covariance);
+
+void
+sinfo_fit_amoeba(double**p, 
+       double y[], 
+       int ndim, 
+       double ftol, 
+       double (*funk)(double[]),
+       int* nfunk);
+
+int sinfo_vector_dindgen(cpl_vector** v);
+int sinfo_is_fits_file(const char *filename);
+cpl_error_code
+sinfo_extract_frames_group_type(const cpl_frameset * set, 
+                                cpl_frameset** ext, cpl_frame_group type);
+cpl_error_code sinfo_frameset_merge(cpl_frameset * set1, 
+                                    cpl_frameset* set2);
+cpl_error_code
+sinfo_table_correl(cpl_table * t1, 
+                   cpl_table* t2, 
+                   cpl_table* range,
+                   double* xcor);
+int 
+sinfo_get_pupil_shift(cpl_imagelist* iml,const int n,cpl_table** qclog_tbl);
+int sinfo_get_preoptic(const char* file,const char* val);
+int sinfo_get_keyvalue_int(cpl_frame * ref_frame, const char* key_name);
+float sinfo_get_keyvalue_float(cpl_frame * ref_frame, const char* key_name);
+double sinfo_get_keyvalue_double(cpl_frame * ref_frame, const char* key_name);
+char sinfo_get_keyvalue_bool(cpl_frame * ref_frame, const char* key_name);
+const char* 
+sinfo_get_keyvalue_string(cpl_frame * ref_frame, const char* key_name);
+int sinfo_get_strehl_type(cpl_frameset* sof);
+double sinfo_get_wave_cent(const char* band);
+void sinfo_memory_status(void);
+int sinfo_check_rec_status(const int val);
+void 
+sinfo_add_pro_fits_key(cpl_propertylist * plist,  
+                       char* pro_catg, 
+                       char* file_name, 
+                       char* out_name);
+/* ---------------------------------------------------------------------- 
+   group of frames
+---------------------------------------------------------------------- */
+
+
+
+int 
+sinfoni_extract_raw_linearity_frames(cpl_frameset * sof, cpl_frameset** raw);
+int sinfoni_extract_raw_dark_frames(cpl_frameset * sof, cpl_frameset** raw);
+int sinfo_extract_raw_pinhole_frames(cpl_frameset * sof, cpl_frameset** raw);
+int sinfo_extract_raw_slit_frames(cpl_frameset * sof, cpl_frameset** raw);
+int sinfo_extract_raw_stack_frames(cpl_frameset * sof, cpl_frameset** pro);
+int sinfo_extract_on_frames(cpl_frameset * sof, cpl_frameset* on);
+int sinfo_extract_off_frames(cpl_frameset * sof, cpl_frameset* off);
+
+int sinfo_extract_raw_frames(cpl_frameset * sof, cpl_frameset** raw); 
+int sinfoni_extract_pro_frames(cpl_frameset * sof, cpl_frameset** pro); 
+int sinfo_extract_cdb_frames(cpl_frameset * sof, cpl_frameset** cdb);
+ 
+int sinfo_extract_obj_frames(cpl_frameset * sof, cpl_frameset* obj);
+int sinfo_extract_sky_frames(cpl_frameset * sof, cpl_frameset* sky);
+int sinfo_extract_mst_frames(cpl_frameset * sof, cpl_frameset* cdb); 
+int sinfo_extract_stk_frames(cpl_frameset * sof, cpl_frameset* res);
+int 
+sinfo_extract_preoptic_frames(cpl_frameset * sof, 
+                              cpl_frameset** res, 
+                              const char* pre_opt);
+
+double sinfo_get_cumoffsetx(cpl_frame * frame);
+double sinfo_get_cumoffsety(cpl_frame * frame);
+int sinfo_tag_is_objpro(char * tag);
+int sinfo_extract_obj_products(cpl_frameset * sof, cpl_frameset* obj);
+
+cpl_frameset* sinfo_frameset_join(cpl_frameset* fs1,cpl_frameset* fs2);
+
+const char* sinfo_get_pix_scale(float ps);
+int sinfo_pix_scale_isnot_const(float* pix_scale, int size);
+
+int sinfo_contains_frames_kind(cpl_frameset * sof, 
+                                 cpl_frameset* raw,
+                                 const char*         type);
+
+int sinfo_contains_frames_type(cpl_frameset * sof, 
+                                    cpl_frameset** raw,
+                                    const char*          type);
+
+
+int sinfo_extract_raw_frames_type(cpl_frameset * sof, 
+                                    cpl_frameset** raw,
+                                    const char*          type);
+
+int sinfo_extract_raw_frames_type2(cpl_frameset * sof, 
+                                    cpl_frameset** raw,
+                                    const char*          type);
+
+int sinfo_extract_raw_frames_type1(cpl_frameset * sof, 
+                                    cpl_frameset* raw,
+                                    const char*          type);
+
+int sinfo_extract_frames_type(cpl_frameset * sof, 
+                                cpl_frameset * raw,
+                const char*          type);
+
+int sinfo_remove_qc_frames(cpl_frameset* sof,cpl_frameset** raw);
+/* ---------------------------------------------------------------------- 
+   single frames
+---------------------------------------------------------------------- */
+double sinfo_get_mjd_obs(cpl_frame * frame);
+int sinfo_frame_is_raw(char * tag); 
+int sinfoni_frame_is_pro(char * tag); 
+int sinfo_frame_is_cdb(char * tag); 
+int sinfo_frame_is_stk(char * tag); 
+int sinfo_frame_is_preoptic(cpl_frame*, const char* val); 
+
+int sinfo_frame_is_pinhole_lamp(char * tag); 
+int sinfo_frame_is_raw_stack(char * tag); 
+int sinfo_frame_is_slit_lamp(char * tag); 
+
+
+int sinfo_is_flat_bp(char * tag);
+int sinfo_is_flat_lindet(char * tag);
+int sinfo_is_dark(char * tag);
+int sinfoni_is_pinhole_lamp(char * tag) ;
+int sinfoni_is_raw_stack(char * tag) ;
+
+int sinfoni_is_lamp_slit(char * tag) ;
+int sinfo_is_sky_flat(char * tag) ;
+
+int sinfo_is_mflat(char * tag) ;
+int sinfo_is_master_flat(char * tag) ;
+int sinfo_is_master_flat_dither(char * tag) ;
+
+int sinfo_is_stack(char * tag) ;
+int sinfo_is_lamp_wave_stacked(char * tag) ;
+int sinfo_is_lamp_flux_stacked(char * tag) ;
+int sinfo_is_psf_calibrator_stacked(char * tag) ;
+int sinfo_is_focus_stacked(char * tag) ;
+int sinfo_is_object_nodding_stacked(char * tag) ;
+int sinfo_is_sky_nodding_stacked(char * tag) ;
+int sinfo_is_object_skyspider_stacked(char * tag) ;
+
+
+int sinfo_blank2dot(const char * in, char* ou) ;
+int sinfo_is_bpmap(char *) ;
+int sinfo_is_slitpos(char * tag) ;
+int sinfo_is_wavemap(char * tag) ;
+int sinfo_is_halosp(char * tag) ;
+int sinfo_is_distlist(char * tag) ;
+int sinfo_is_firstcol(char * tag) ;
+int sinfo_is_fibres_on_off(cpl_frameset * sof, 
+                 cpl_frameset* raw);
+/* ---------------------------------------------------------------------- 
+   Extra functionalities
+---------------------------------------------------------------------- */
+int
+sinfo_clean_nan(cpl_image** im);
+
+int  sinfo_get_clean_mean_window(cpl_image* img, 
+                                 int llx, 
+                                 int lly, 
+                                 int urx, 
+                                 int ury, 
+                                 const int kappa, 
+                                 const int nclip, 
+                                 double* sinfo_clean_mean, 
+                                 double* clean_stdev);
+
+int sinfo_get_obsname(cpl_frame * ref_frame, const char* ob_name);
+
+
+ int sinfo_get_ron(cpl_frameset    *   framelist,
+                const int ron_xmin,
+                const int ron_xmax,
+                const int ron_ymin,
+                const int ron_ymax,
+                const int ron_hsize,
+                const int ron_nsamp,
+             double** ron);
+int sinfo_stack_get_pro_tag(char * tag_in, char* tag_out) ; 
+int sinfo_compare_tags(const cpl_frame *, const cpl_frame *) ;
+
+int sinfo_get_spatial_res(cpl_frame * ref_frame,char * spat_res);
+int sinfo_frame_is_dither(cpl_frame * ref_frame);
+int sinfo_frame_is_sky(cpl_frame * ref_frame);
+int sinfo_tag_is_obj(char * ref_frame);
+int sinfo_tag_is_sky(char * ref_frame);
+
+int sinfo_frame_is_on(cpl_frame * ref_frame);
+int sinfo_get_band(cpl_frame * ref_frame,char * band);
+int sinfo_get_ins_set(char* band,int* ins_set);
+int sinfoni_get_ins_setting(cpl_frame * ref_file,char * set_id);
+int sinfo_pfits_add_qc(cpl_propertylist * plist,qc_log * qclog);
+
+
+
+
+
+
+CPL_END_DECLS
+
+#endif
diff --git a/sinfoni/sinfo_general_config.c b/sinfoni/sinfo_general_config.c
new file mode 100644
index 0000000..08a9717
--- /dev/null
+++ b/sinfoni/sinfo_general_config.c
@@ -0,0 +1,110 @@
+/* $Id: sinfo_general_config.c,v 1.6 2012/03/02 08:42:20 amodigli Exp $
+ *
+ * This file is part of the CPL (Common Pipeline Library)
+ * Copyright (C) 2002 European Southern Observatory
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*
+ * $Author: amodigli $
+ * $Date: 2012/03/02 08:42:20 $
+ * $Revision: 1.6 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+ /****************************************************************
+  *           Bad pixel search  (normal method)                  *
+  ****************************************************************/
+
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#include "sinfo_general_config.h"
+
+/**@{*/
+/**
+ * @defgroup spiffi_general_config General configuration parameters
+ *
+ * TBD
+ */
+
+  /**
+  * @brief
+  *   Adds parameters for the spectrum extraction
+  *
+  * @param list Parameter list to which parameters are added.
+  *
+  * @return Nothing.
+  *
+  * TBD
+  */
+
+  /* General data reduction parameters */
+
+void
+ sinfo_general_config_add(cpl_parameterlist *list)
+{
+
+  cpl_parameter *p;
+
+  if (!list) {
+    return;
+  }
+
+  /* indicates if parameters will be overwritten */
+  p = cpl_parameter_new_value("sinfoni.general.overwrite_parameters",
+                  CPL_TYPE_BOOL,
+                              "Overwrite DRS ini parameters: ",
+                              "sinfoni.general",
+                              TRUE);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "gen-overpar");
+  cpl_parameterlist_append(list, p);
+
+  p = cpl_parameter_new_value("sinfoni.general.lc_sw",
+                              CPL_TYPE_BOOL,
+                              "Correct for bad lines introduced by "
+                              "instrument software: ",
+                              "sinfoni.general",
+                              FALSE);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "lc_sw");
+  cpl_parameterlist_append(list, p);
+
+
+  /* Fill the parameters list */
+  p = cpl_parameter_new_value("sinfoni.general.lc_kappa", 
+                              CPL_TYPE_INT,
+                              "Kappa sigma value", 
+                              "sinfoni.general",18);
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "lc_kappa") ;
+  cpl_parameterlist_append(list, p) ;
+
+  p = cpl_parameter_new_value("sinfoni.general.lc_filt_rad", 
+                              CPL_TYPE_INT,
+			      "Filtering radii applied during median filter."
+                              " Should be small", 
+			      "sinfoni.general",3) ;
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "lc_filt_rad") ;
+  cpl_parameterlist_append(list, p) ;
+
+
+  return;
+
+}
+/**@}*/
diff --git a/sinfoni/sinfo_general_config.h b/sinfoni/sinfo_general_config.h
new file mode 100644
index 0000000..0796500
--- /dev/null
+++ b/sinfoni/sinfo_general_config.h
@@ -0,0 +1,37 @@
+/* $Id: sinfo_general_config.h,v 1.1 2006/10/20 08:06:32 amodigli Exp $
+ *
+ * This file is part of the CPL (Common Pipeline Library)
+ * Copyright (C) 2002 European Southern Observatory
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*
+ * $Author: amodigli $
+ * $Date: 2006/10/20 08:06:32 $
+ * $Revision: 1.1 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+ /****************************************************************
+  *           Bad pixel search  (noise method)                  *
+  ****************************************************************/
+#ifndef SINFO_GENERAL_CONFIG_H
+#define SINFO_GENERAL_CONFIG_H
+
+#include <cpl.h>   
+
+void sinfo_general_config_add(cpl_parameterlist *list);
+
+#endif
diff --git a/sinfoni/sinfo_globals.c b/sinfoni/sinfo_globals.c
new file mode 100644
index 0000000..8b8a196
--- /dev/null
+++ b/sinfoni/sinfo_globals.c
@@ -0,0 +1,251 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+#include <string.h>
+#include "sinfo_globals.h"
+#include "sinfo_utils_wrappers.h"
+#include <cpl.h>
+
+/**@{*/
+/**
+ * @defgroup sinfo_globals global functions
+ *
+ * TBD
+ */
+
+
+/**
+ at name sinfo_amoeba_new
+ at brief structure to change behaviour of amoeba function
+ at return pointer to structure
+
+*/
+amoeba_dat*
+sinfo_amoeba_new(cpl_vector* vx, 
+                 cpl_vector* vy, 
+                 cpl_vector* sx, 
+                 cpl_vector* sy)
+ {
+   amoeba_dat * a;
+   a= cpl_malloc(sizeof(amoeba_dat));
+
+   a->vx=cpl_vector_duplicate(vx);
+   a->vy=cpl_vector_duplicate(vy);
+   a->sx=cpl_vector_duplicate(sx);
+   a->sy=cpl_vector_duplicate(sy);
+
+
+  return a;
+
+}
+/**
+ at name sinfo_amoeba_delete
+ at brief function to free a fake structure
+ at return void
+
+*/
+void
+sinfo_amoeba_delete(amoeba_dat** a)
+{
+  sinfo_free_my_vector(&((*a)->vx));
+  sinfo_free_my_vector(&((*a)->vy));
+  sinfo_free_my_vector(&((*a)->sx));
+  sinfo_free_my_vector(&((*a)->sy));
+
+  cpl_free(*a);
+  *a=NULL;
+}
+
+
+/**
+ at name sinfo_fake_new
+ at brief structure to change behaviour of prepare stacked frame function
+ at return pointer to structure
+
+*/
+fake*
+sinfo_fake_new(void)
+ {
+   fake * f;
+   f= cpl_malloc(sizeof(fake));
+
+  strcpy(f->pro_class,"DEFAULT");
+  f->frm_switch=0;
+  f->is_fake_sky=0;
+  f->mask_index=1;
+  f->ind_index=0;
+  f->flat_index=1;
+  f->wfix_index=1;
+  f->low_rej=0.1;
+  f->hig_rej=0.1;
+  return f;
+}
+/**
+ at name sinfo_fake_delete
+ at brief function to free a fake structure
+ at return void
+
+*/
+void
+sinfo_fake_delete(fake** f)
+{
+  cpl_free(*f);
+  *f=NULL;
+}
+
+/**
+ at name sinfo_wcal_new
+ at brief structure to change behaviour of prepare stacked frame function
+ at return pointer to structure
+
+*/
+wcal*
+sinfo_wcal_new(void)
+ {
+   wcal * w;
+   w= cpl_malloc(sizeof(wcal));
+
+   w->wstart=1.65;
+   w->wgdisp1=-0.000200018796022;
+   w->wgdisp2=9.30345245278e-10;
+   w->min_dif=10.0;
+   w->hw=7;
+   w->fwhm=2.83;
+   w->min_amp=5.0;
+   w->na_coef=3;
+   w->nb_coef=2;
+   w->pixel_tol=7.0;
+   w->y_box=2.0;
+   w->low_pos=750;
+   w->hig_pos=1000;
+ 
+  return w;
+}
+/**
+ at name sinfo_wcal_delete
+ at brief function to free a wcal structure
+ at return void
+
+*/
+void
+sinfo_wcal_delete(wcal* w)
+{
+  cpl_free(w);
+}
+
+
+/**
+ at name sinfo_stack_new
+ at brief structure to change behaviour of prepare stacked frame function
+ at return pointer to structure
+
+*/
+
+stack*
+sinfo_stack_new(void)
+ {
+   stack * s;
+   s= cpl_malloc(sizeof(stack));
+
+   strcpy(s->do_class,"DEFAULT");
+   strcpy(s->index_list,"indexlist");
+   s->warp_fix_ind=1;
+  
+  return s;
+}
+/**
+ at name sinfo_stack_delete
+ at brief function to free a stack structure
+ at return void
+
+*/
+void
+sinfo_stack_delete(stack* s)
+{
+  cpl_free(s);
+}
+/**
+ at name sinfo_nstpar_new
+ at brief structure to change behaviour of prepare stacked frame function
+ at return pointer to structure
+
+*/
+nstpar*
+sinfo_nstpar_new(void)
+ {
+   nstpar * n;
+   n= cpl_malloc(sizeof(nstpar));
+
+   n->fwhm[0]=2.0;
+   n->fwhm[1]=5.0;
+   n->fwhm[2]=2.0;
+   n->fwhm[3]=2.0;
+
+   n->min_dif[0]=1.0;
+   n->min_dif[1]=5.0;
+   n->min_dif[2]=5.0;
+   n->min_dif[3]=5.0;
+ 
+  return n;
+}
+/**
+ at name sinfo_nstpar_delete
+ at brief function to free a nstpar structure
+ at return void
+
+*/
+void
+sinfo_nstpar_delete(nstpar* n)
+{
+  cpl_free(n);
+}
+/**
+ at name sinfo_distpar_new
+ at brief structure to change behaviour of prepare stacked frame function
+ at return pointer to structure
+
+*/
+
+distpar*
+sinfo_distpar_new(void)
+ {
+   distpar * d;
+   d= cpl_malloc(sizeof(distpar));
+
+   d->diff_tol[0]=2.0;
+   d->diff_tol[1]=4.0;
+   d->diff_tol[2]=2.0;
+   d->diff_tol[3]=4.0;
+ 
+  return d;
+}
+/**
+ at name sinfo_distpar_delete
+ at brief function to free a distpar structure
+ at return void
+
+*/
+void
+sinfo_distpar_delete(distpar* d)
+{
+  cpl_free(d);
+}
+
diff --git a/sinfoni/sinfo_globals.h b/sinfoni/sinfo_globals.h
new file mode 100644
index 0000000..56c1e8f
--- /dev/null
+++ b/sinfoni/sinfo_globals.h
@@ -0,0 +1,180 @@
+/* $Id: sinfo_globals.h,v 1.6 2007/10/09 15:58:00 amodigli Exp $
+ *
+ * This file is part of the SINFONI Pipeline
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This proram is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2007/10/09 15:58:00 $
+ * $Revision: 1.6 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifndef SINFO_GLOBALS_H
+#define SINFO_GLOBALS_H
+#include <cpl.h>
+/*------------------------------------------------------------------------
+                                   Defines
+ --------------------------------------------------------------------------*/
+#define SINFO_RESAMP_NROWS 2560
+#define PI_NUMB     (3.1415926535897932384626433832795)
+#define ZERO    0./0.
+#define FLAG    -1.e+9
+#define QC_DID_ID                          "SINFONI-1.0.0"
+#define FILE_NAME_SZ                       512
+#define MAX_NAME_SIZE                      512
+#define TELESCOPE_SURFACE                  52.8101279
+
+#define NOISE_HSIZE                        4
+#define NOISE_NSAMPLES                     100
+#define SINFO_DBL_MIN 1e-37
+#define SINFO_DBL_MAX 1e+37
+
+#define IMA_PIX_START                      0
+#define IMA_PIX_END                        2047
+#define SIZEX                              2048
+#define SIZEY                              2048
+#define DET_PIX_MIN                        1
+#define DET_PIX_MAX                        2048
+
+
+#define LLX                                1350
+#define LLY                                1000
+#define URX                                1390
+#define URY                                1200
+
+#define DISTORTION_LOPOS                    974
+#define DISTORTION_HIPOS                   1074
+
+#define GRAT_VAL1_HK                       3997330
+#define GRAT_VAL2_HK                       3997339
+#define GRAT_VAL1_H                        2948723
+#define GRAT_VAL2_H                        2948733
+#define GRAT_VAL1_K                        1893844
+#define GRAT_VAL2_K                        1893854
+#define GRAT_VAL1_J                         849618
+#define GRAT_VAL2_J                         849628
+#define GRAT_VAL_TOL                             4
+
+#define SKY_FLUX                                 0
+#define BKG_VARIANCE                            9.6
+#define GAIN                                    2.42
+#define MAGNITUDE                              11
+
+#define MSG_OVER_WRITE_PAR        "Using default data reduction parameters"
+#define LAMP_ON     TRUE
+#define LAMP_OFF    FALSE
+
+struct amoeba_ {
+  cpl_vector*   vx;
+  cpl_vector*   vy;
+  cpl_vector*   sx;
+  cpl_vector*   sy;
+};
+typedef struct amoeba_ amoeba_dat; 
+
+amoeba_dat* sinfo_amoeba_new(cpl_vector* vx, 
+                             cpl_vector* vy, 
+                             cpl_vector* sx, 
+                             cpl_vector* sy);
+void sinfo_amoeba_delete(amoeba_dat** a);
+
+struct qc_log_ {
+  char   name[30];
+  char   type[30];
+  char   s_val[30];
+  char   comm[30];
+  double n_val;
+  int    n;
+};
+typedef struct qc_log_ qc_log; 
+
+struct fake_ {
+  char  pro_class[FILE_NAME_SZ];
+  int   frm_switch;
+  int   is_fake_sky;
+  int   mask_index;
+  int   ind_index;
+  int   flat_index;
+  int   wfix_index;
+  double   low_rej;
+  double   hig_rej;
+};
+
+typedef struct fake_ fake;
+fake* sinfo_fake_new(void);
+void sinfo_fake_delete(fake** f);
+
+
+struct wcal_ {
+  double wstart;
+  double wgdisp1;
+  double wgdisp2;
+  double min_dif;
+  double fwhm;
+  double min_amp;
+  double pixel_tol;
+  double y_box;
+  int low_pos;
+  int hig_pos;
+  int    hw;
+  int    na_coef;
+  int    nb_coef;
+
+};
+
+typedef struct wcal_ wcal;
+
+wcal* sinfo_wcal_new(void);
+void sinfo_wcal_delete(wcal* f);
+
+
+struct stack_ {
+  char do_class[FILE_NAME_SZ];
+  char index_list[FILE_NAME_SZ];
+  int  warp_fix_ind;
+};
+
+typedef struct stack_ stack;
+
+stack* sinfo_stack_new(void);
+void sinfo_stack_delete(stack* s);
+
+
+
+struct nst_ {
+  double min_dif[4];
+  double fwhm[4];
+};
+
+typedef struct nst_ nstpar;
+
+nstpar* sinfo_nstpar_new(void);
+void sinfo_nstpar_delete(nstpar* n);
+
+struct dist_ {
+  double diff_tol[4];
+};
+
+typedef struct dist_ distpar;
+
+distpar* sinfo_distpar_new(void);
+void sinfo_distpar_delete(distpar* d);
+
+
+#endif
diff --git a/sinfoni/sinfo_hidden.h b/sinfoni/sinfo_hidden.h
new file mode 100644
index 0000000..7fcd870
--- /dev/null
+++ b/sinfoni/sinfo_hidden.h
@@ -0,0 +1,112 @@
+/* $Id: sinfo_hidden.h,v 1.7 2010/02/12 17:56:35 amodigli Exp $
+ *
+ * This file is part of the CPL (Common Pipeline Library)
+ * Copyright (C) 2002 European Southern Observatory
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*
+ * $Author: amodigli $
+ * $Date: 2010/02/12 17:56:35 $
+ * $Revision: 1.7 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+ /****************************************************************
+  *           Bad pixel search  (noise method)                  *
+  ****************************************************************/
+#ifndef SINFO_HIDDEN_H
+#define SINFO_HIDDEN_H
+
+#define BP_LIN_OUT_FILENAME               "out_bp_lin.fits"
+#define BP_LIN_GAIN_OUT_FILENAME          "out_gain_info.fits"
+#define BP_LIN_LIN_DET_INFO_OUT_FILENAME  "out_lin_det_info.fits"
+#define BP_LIN_COEFFS_CUBE_OUT_FILENAME   "out_bplin_coeffsCube.fits"
+#define BP_NOISE_OUT_FILENAME             "out_bp_noise.fits"
+
+#define BP_NORM_INT_COL_TILT_CORR_OUT_FILENAME  "out_int_col_tilt_corr.fits"
+
+#define DARK_OUT_FILENAME        "out_dark.fits"
+
+#define LAMP_FLATS_OUT_FILENAME   "out_flat.fits"
+#define LAMP_FLATS_OUT_BPMAP      "out_bpmask.fits"
+#define BP_NORM_OUT_FILENAME      "out_bp_norm.fits"
+#define MASTER_BPMAP_OUT_FILENAME "out_bpmap_sum.fits"
+
+#define DISTORTION_NS_OUT_FILENAME "out_ns_distortion.fits"
+#define DISTORTION_OUT_FILENAME    "out_distortion.fits"
+#define DISTORTION_STACK_OFF_OUT_FILENAME   "out_ns_stack_off.fits"
+#define DISTORTION_STACK_ON_OUT_FILENAME    "out_ns_stack_on.fits"
+
+
+#define SLITPOS_OUT_FILENAME       "out_slit_pos.fits"
+#define BP_DIST_OUT_FILENAME       "out_bp_dist.fits"
+#define COEFF_OUT_FILENAME         "out_coef_params.fits"
+#define NS_TEST_DISTANCES_OUT_FILENAME "out_distances.fits"
+#define NS_TEST_OUT_FILENAME           "out_ns.fits"
+
+
+#define WAVECAL_OUT_FILENAME              "out_wavemap_ima.fits"
+#define WAVECAL_FIT_PARAMS_OUT_FILENAME   "out_fit_params.fits"
+#define WAVECAL_FIT_PARAMS_OUT_FILEASCII   "out_fit_params.ascii"
+#define WAVECAL_COEFF_SLIT_OUT_FILENAME   "outCoeffsSlit.fits"
+#define WAVECAL_SLIT_POS_OUT_FILENAME     "out_slitpos.fits"
+#define WAVECAL_RESAMPLED_OUT_FILENAME   "out_resampled_arclamp.fits"
+
+
+#define STACKED_OUT_FILENAME                 "out_stack.fits"
+#define STACK_MFLAT_DIST_OUT_FILENAME        "out_stack_mflat_dist.fits"
+#define STACK_MFLAT_DITHER_DIST_OUT_FILENAME "out_stack_mflat_dither_dist.fits"
+
+#define STACK_SKY_DIST_OUT_FILENAME             "out_sky_stack_dist"
+
+#define ESTIMATED_SLITLETS_DISTANCE 64.
+
+
+#define PSF_OUT_FILENAME                   "out_psf.fits"
+#define PSF_MED_CUB_025_FILENAME           "out_med_cube_025_mas.fits"
+#define PSF_MED_CUB_100_FILENAME           "out_med_cube_100_mas.fits"
+#define PSF_AO_PERFORMANCE_OUT_FILENAME    "out_ao_performance.fits"
+#define PSF_ENC_ENERGY_OUT_FILENAME        "out_encircled_energy.fits"
+#define STDSTAR_OUT_FILENAME               "out_starspectrum.fits"
+#define STDSTAR_OUT_TABLE                  "out_std_star_spectrum.fits"
+#define STDSTAR_CONV_OUT_FILENAME          "out_convfactor.fits"
+#define SKYPMAP_OUT_FILENAME               "out_skymap.fits"
+#define NSLITLETS               32
+
+#define OBJNOD_OUT_BPMAP        "out_objnod_bpmap.fits"
+#define OBJNOD_OUT_MED_CUBE     "out_objnod_med_cube.fits"
+#define OBJNOD_OUT_FILENAME     "out_objnod.fits"
+
+#define OBJNOD_OUT_MFLAT_CUBE_FILENAME     "out_mflat_cube.fits"
+#define OBJNOD_OUT_MFLAT_AVG_FILENAME      "out_mflat_avg.fits"
+#define OBJNOD_OUT_MFLAT_MED_FILENAME      "out_mflat_med.fits"
+#define RESAMPLED_OUT_OBJ_FILENAME         "out_resampled_obj"
+#define RESAMPLED_OUT_SKY_FILENAME         "out_resampled_sky"
+#define RESAMPLED_OUT_FLAT_FILENAME        "out_resampled_flat"
+
+
+#define STDSTAR_OUT_MED_CUBE    "out_stdstar_med_cube.fits"
+
+#define FOCUS_OUT_FILENAME             "out_focus.fits"
+#define FOCUS_FITPAR_OUT_FILENAME      "out_focus_fitpar.fits"
+#define FOCUS_GAUSSPLOT_OUT_FILENAME   "out_focus_gaussplot.fits"
+
+#define LAMPSPEC_OUT_FILENAME "out_lampspec.fits"
+#define TWIFLAT_OUT_FILENAME  "out_twiflat.fits"
+#define SKYSPIDER_OUT_FILENAME "out_objnod.fits"
+#define SKYSPIDER_MASK_OUT_FILENAME "out_mask_cube_spider.fits"
+#define EFFICIENCY_FILENAME "out_efficiency.fits"
+#endif
diff --git a/sinfoni/sinfo_image_ops.c b/sinfoni/sinfo_image_ops.c
new file mode 100644
index 0000000..c05c210
--- /dev/null
+++ b/sinfoni/sinfo_image_ops.c
@@ -0,0 +1,3516 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*************************************************************************
+* M.P.E. - SPIFFI project
+*
+*
+*
+* who       when      what
+* --------  --------  ----------------------------------------------
+* rabuter 2004-12-03 support one dimensional image in sinfo_shiftImage
+* schreib  23/05/00  created
+*/
+
+/************************************************************************
+*   NAME
+*        sinfo_image_ops.c -
+*        image arithmetic routines
+*
+*   SYNOPSIS
+*   #include "sinfo_image_ops.h"
+*
+*   1) Vector * sinfo_new_mean_of_columns( cpl_image *im )
+*   2) Vector * sinfo_new_clean_mean_of_columns( cpl_image *im,
+*                                   double lo_reject,
+*                                   double hi_reject)
+*   3) cpl_image * sinfo_new_div_image_by_row( cpl_image *im, Vector *row )
+*   4) cpl_image * sinfo_new_mult_row_to_image( cpl_image *im, Vector *row )
+*   5) cpl_image * sinfo_new_col_tilt ( cpl_image * image, float sigmaFactor )
+*   6) cpl_image * sinfo_new_median_image( cpl_image * im, float fmedian )
+*   7) cpl_image * sinfo_new_compare_images( cpl_image * im1,
+                                             cpl_image * im2,
+                                             cpl_image * origim )
+*   8) cpl_image * sinfo_new_thresh_image ( cpl_image * im,
+                                            float lo_cut, float hi_cut )
+*   9) pixel_map * sinfo_new_promote_image_to_pixelmap ( cpl_image * im )
+*  10) cpl_image * sinfo_new_promote_image_to_mask ( cpl_image * im,
+                                                     int * n_badpixels )
+*  11) cpl_image * sinfo_new_mult_image_by_mask ( cpl_image * im,
+                                                  cpl_image * mask )
+*  12) cpl_image * sinfo_new_interpol_image ( cpl_image * im,
+*                                 cpl_image * mask,
+*                                 int        max_radius,
+*                                 int        n_pixels )
+*  13) cpl_image * sinfo_interpol_source_image ( cpl_image * im,
+*                                       cpl_image * mask,
+*                                       int        max_rad,
+*                                       float   ** slit_edges )
+*  14) cpl_image * sinfo_new_stack_row_to_image ( Vector * row, int ly )
+*  15) Stats * sinfo_new_image_stats_on_rectangle ( cpl_image * im,
+*                                      float      loReject,
+*                                      float      hiReject,
+*                                      int        llx,
+*                                      int        lly,
+*                                      int        urx,
+*                                      int        ury )
+*  16) cpl_image * sinfo_new_normalize_to_central_pixel ( cpl_image * image )
+*  17) cpl_image *
+*      sinfo_new_shift_image(
+*            cpl_image    *    image_in,
+*            double           shift_x,
+*            double           shift_y,
+*            double       *   interp_kernel)
+*  18) cpl_image * sinfo_new_combine_masks ( cpl_image * firstMask,
+                                             cpl_image * secondMask )
+*  19) cpl_image * sinfo_new_slice_cube (cpl_imagelist * cube, int x, int y )
+*  20) cpl_image * sinfo_new_div_images_robust ( cpl_image * im1,
+                                                 cpl_image * im2 )
+*
+*
+*   DESCRIPTION
+*   1) takes the average of each image column
+*   2) takes the average of each image column by sorting the
+*      column values and rejecting the given percentage of
+*      the highest and lowest values  [0...1]
+*   3) divides each image column by a row value
+*   4) multiplies each image column with a row value
+*   5) first calculates statistics for each column of an image.
+*      sinfo_median value and standard deviation of columns are de-
+*      termined, blank values are excluded. Fits a straight
+*      line through the pixel values of each column and subtracts
+*      the fit in order to remove the tilt of each column.
+*      Only those pixels are used for the fit that are within
+*      a defined factor of sigma noise limit. The noise is
+*      calculated from pixels between the 10percentil and
+*      90percentil points.
+*      if the straight line could not be determined, the sinfo_median
+*      of the column is subtracted from the column
+*   6) sinfo_median filter, calculates the sinfo_median for an image
+*      by using the 8 closest pixels to each pixel.
+*      The values in the output image are determined according
+*      to the values of the input parameter.
+*      If fmedian = 0: always replace by sinfo_median
+*      if fmedian < 0: replace by sinfo_median if |pixel - sinfo_median| >
+*                      -fmedian
+*      if fmedian > 0: replace by sinfo_median (fmedian as a factor of
+*                      the square root of the sinfo_median itself)
+*                      if |pixel - median| >= fmedian * sqrt ( median )
+*                      This can be used to consider photon noise.
+*                      This considers a dependence of the differences on the
+*                      pixel values themselves.
+*   7) if a pixel value of one image (im1) equals
+*      the pixel value of the other image keep the
+*      pixel value of the original image otherwise replace
+*      it with ZEROs
+*   8) simple search for static bad pixels for a flat field
+*      or sinfo_dark frame, values below and above the threshold
+*      values are set to ZERO.
+*   9) changes an image with ZERO indicated bad pixels to
+*      a bad pixel map.
+*  10) changes an image with ZERO indicated bad pixels to
+*      a bad pixel mask image, that means the returned
+*      image has values 1 at positions of good pixels and
+*      ZEROs at positions of bad pixels.
+*  11) changes an image to an image that has ZERO indicated
+*      static bad pixels
+*  12) interpolates all bad pixels indicated by the bad pixel mask.
+*      Therefore, the mean of at least 2 valid values of
+*      the nearest 8 neighbors is taken. If too much
+*      neighbors are also bad pixels
+*      the neighbor radius is increased to a maximum of
+*      max_radius until n_pixels valid pixels are found.
+*      The valid neighbors are searched by going through
+*      the columns and rows around the central square that
+*      was already searched.
+*      The bad pixel is interpolated by the mean of these
+*      valid pixels (less than 9) or by the sinfo_median of them
+*      (more than 8).
+*  13) interpolates all bad pixels indicated by the bad pixel mask.
+*      Therefore, the mean of the nearest 4 neighbors is taken,
+*      two in spectral direction and 2 in spatial direction.
+*      The routine cares about the image and slitlet edges.
+*      If there are no good pixel found within the nearest neighbors,
+*      the next 4 nearest neighbors in spatial and spectral direction
+*      are searched for valid pixels until a limit of max_rad.
+*      A maximum of 4 valid pixels are used for interpolation by their mean.
+*  14) stack a given image row to build a whole image
+*  15) computes the mean and standard deviation of
+*      a given rectangle on an image by leaving the extreme
+*      intensity values.
+*  16) normalizes a raw flatfield image by dividing by the median of the
+       central spectral pixels to produce a master flatfield
+*  17) This function is a conversion to CPL of the ECLIPSE function
+       shift_image()
+*      but slightly changed. If a blank (ZERO) pixel appears the blank pixel
+*      is shifted but preserved as blank.
+*      If a blank (ZERO) pixel appears within the
+*      interpolation kernel the blank pixel is set to 0.
+*
+*      This function shifts an image by a non-integer offset, using
+*      interpolation. You can either generate an interpolation kernel once and
+*      pass it to this function, or let it generate a default kernel. In the
+*      former case, use sinfo_generate_interpolation_kernel() to generate an
+*      appropriate kernel. In the latter case, pass NULL as last argument. A
+*      default interpolation kernel is then generated then discarded
+       before this function returns.
+*
+*      The returned image is a newly allocated object, it must be deallocated
+*      using cpl_image_delete().
+*  18) combines two bad pixel mask to one using an or relation
+*  19) slices a data cube in x or y direction
+*  20) divides two images by considering blanks and
+*      calculating first 1/im2 by
+*      cutting the very high values and setting to 1,
+*      then multiplying im1 * 1/im2.
+*
+*   FILES
+*
+*   ENVIRONMENT
+*
+*   RETURN VALUES
+*
+*   CAUTIONS
+*
+*   EXAMPLES
+*
+*   SEE ALSO
+*
+*   BUGS
+*
+*------------------------------------------------------------------------
+*/
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+#include "sinfo_vltPort.h"
+
+/*
+ * System Headers
+ */
+#include <errno.h>
+/*
+ * Local Headers
+ */
+
+#include "sinfo_image_ops.h"
+#include "sinfo_error.h"
+#include "sinfo_resampling.h"
+#include "sinfo_local_types.h"
+#include "sinfo_utils_wrappers.h"
+/**@{*/
+/**
+ * @defgroup sinfo_image_ops Image operations
+ *
+ * TBD
+ */
+
+
+static cpl_image *
+sinfo_gen_lowpass(const int xs,
+                  const int ys,
+                  const double sigma_x,
+                  const double sigma_y);
+
+
+static void quicksort_int(int* data, int left, int right);
+/**@{*/
+
+/*----------------------------------------------------------------------------
+ *                            Function codes
+ *--------------------------------------------------------------------------*/
+
+
+
+/**
+ at name sinfo_image_line_cor
+ at brief Corrects for line artifacts in long exposure images
+ at param width
+ at param filt_rad
+ at param kappa
+ at param ima
+ at param ima_out
+ at return cpl error code
+*/
+
+cpl_error_code
+sinfo_image_line_corr(const int width,
+                const int filt_rad,
+                const int kappa,
+                cpl_image* ima_in,
+                cpl_image** ima_out)
+{
+
+  cpl_image* mask=NULL;
+
+  cpl_image* ima_backpix=NULL;
+  cpl_image* ima_backpos=NULL;
+  cpl_image* ima_ybackpix=NULL;
+  cpl_image* ima_diffbackpix=NULL;
+  cpl_image* ima_filt=NULL;
+  cpl_image* ima = NULL;
+
+  cpl_matrix* filter=NULL;
+  //cpl_mask* bpm_good=NULL; //Is this really useful?
+  cpl_mask* bpm_bad=NULL;
+
+  int sx=0;
+  int sy=0;
+  int i=0;
+  int j=0;
+  int k=0;
+  double med_back=0;
+  double sigma_back=0;
+  double medvalue=0;
+
+  float* pima=NULL;
+  float* ppix=NULL;
+  float* pmsk=NULL;
+  int* ppos=NULL;
+  int* pbackpix=NULL;
+  cpl_binary* pbin=NULL;
+  double tot=0;
+  double mean=0;
+  int* ybad=NULL;
+
+  int nrow=0;
+  int nbad=0;
+  int yval=0;
+  int yprev=0;
+
+
+  check_nomsg(sx=cpl_image_get_size_x(ima_in));
+  check_nomsg(sy=cpl_image_get_size_y(ima_in));
+  check_nomsg(*ima_out=cpl_image_duplicate(ima_in));
+
+  check_nomsg(mask=cpl_image_new(sx,sy,CPL_TYPE_FLOAT));
+  check_nomsg(pmsk=cpl_image_get_data_float(mask));
+
+  for(i=0;i<width;i++) {
+    for(j=width;j<sy-width;j++) {
+      pmsk[j*sx+i]=1;
+    }
+  }
+
+  for(i=sx-width;i<sx;i++) {
+    for(j=width;j<sy-width;j++) {
+      pmsk[j*sx+i]=1;
+    }
+  }
+  sinfo_free_image(&mask); //is mask needed?
+
+
+  nrow=2*width*(sy-2*width);
+  check_nomsg(ima_backpix=cpl_image_new(nrow,1,CPL_TYPE_FLOAT));
+  check_nomsg(ima_backpos=cpl_image_new(nrow,1,CPL_TYPE_INT));
+
+  check_nomsg(pima=cpl_image_get_data_float(ima_in));
+  check_nomsg(ppix=cpl_image_get_data_float(ima_backpix));
+  check_nomsg(ppos=cpl_image_get_data_int(ima_backpos));
+
+  k=0;
+  for(i=0;i<width;i++) {
+    for(j=width;j<sy-width;j++) {
+      ppix[k]=pima[j*sx+i];
+      ppos[k]=j*sx+i;
+      k++;
+    }
+  }
+
+  for(i=sx-width;i<sx;i++) {
+    for(j=width;j<sy-width;j++) {
+      ppix[k]=pima[j*sx+i];
+      ppos[k]=j*sx+i;
+      k++;
+    }
+  }
+
+  check_nomsg(ima_ybackpix=cpl_image_duplicate(ima_backpos));
+  sinfo_free_image(&ima_backpos);
+
+  check_nomsg(pbackpix=cpl_image_get_data_int(ima_ybackpix));
+
+  check_nomsg(cpl_image_divide_scalar(ima_ybackpix,sx));
+  check_nomsg(pbackpix=cpl_image_get_data_int(ima_ybackpix));
+
+
+  check_nomsg(med_back=cpl_image_get_median(ima_backpix));
+  check_nomsg(ima_diffbackpix=cpl_image_duplicate(ima_backpix));
+  //sinfo_msg("med_back=%g",med_back);
+  check_nomsg(cpl_image_subtract_scalar(ima_diffbackpix,med_back));
+  //check_nomsg(cpl_image_save(ima_diffbackpix,"ima_diff.fits",
+  //                           CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT));
+
+  check_nomsg(filter=cpl_matrix_new(1,filt_rad));
+  check_nomsg(cpl_matrix_fill(filter,1.));
+  check_nomsg(ima_filt=sinfo_image_filter_median(ima_diffbackpix,filter));
+  sinfoni_free_matrix(&filter);
+  //check_nomsg(cpl_image_save(ima_filt,"ima_filt.fits",CPL_BPP_IEEE_FLOAT,
+  //		     NULL,CPL_IO_DEFAULT));
+
+  
+  check_nomsg(sigma_back=cpl_image_get_stdev(ima_filt));
+  sinfo_free_image(&ima_filt);
+
+  check_nomsg(ima=cpl_image_duplicate(ima_diffbackpix));
+  sinfo_free_image(&ima_diffbackpix);
+
+  check_nomsg(cpl_image_abs(ima));
+  //sinfo_msg("sigma_back=%g",sigma_back);
+
+  //find good pixels
+  check_nomsg(bpm_bad=cpl_mask_threshold_image_create(ima,kappa*sigma_back,
+						      SINFO_DBL_MAX));
+  /*check_nomsg(bpm_good=cpl_mask_threshold_image_create(ima,SINFO_DBL_MIN,
+						       kappa*sigma_back));
+  sinfo_free_mask(&bpm_good);
+*/
+  check_nomsg(cpl_image_reject_from_mask(ima_backpix,bpm_bad));
+  check_nomsg(medvalue=cpl_image_get_median(ima_backpix));
+  //sinfo_msg("medvalue=%g",sigma_back);
+  check_nomsg(nbad=cpl_mask_count(bpm_bad));
+  //sinfo_msg("nbad=%d",nbad);
+  check_nomsg(cpl_image_reject_from_mask(ima_backpix,bpm_bad));
+  sinfo_free_image(&ima_backpix);
+
+  yprev=-1;
+
+  check_nomsg(pbin=cpl_mask_get_data(bpm_bad));
+  check_nomsg(pbackpix=cpl_image_get_data_int(ima_ybackpix));
+  cpl_msg_debug(cpl_func, "%d lines detected", nbad);
+  if(nbad)
+  {
+
+	  ybad = cpl_calloc(nbad,sizeof(int));
+	  k=0;
+
+	  for(i=0;i<nrow;i++) {
+		if(pbin[i] == CPL_BINARY_1) {
+		   ybad[k]=pbackpix[i] + 1;
+		   k++;
+		}
+	  }
+	  sinfo_free_mask(&bpm_bad);
+	  sinfo_free_image(&ima_ybackpix);
+
+	  quicksort_int(&(ybad[0]), 0, nbad-1);
+	  yprev=-1;
+	  for(k=0;k<nbad;k++) {
+		yval=ybad[k];
+		if(yval == yprev) {
+		  sinfo_msg_debug("skyp %d",yval);
+		}
+		else {
+		  yprev=yval;
+		  sinfo_msg_debug("correct raw %d",yval);
+		  check_nomsg(tot=cpl_image_get_flux_window(ima_in,1,yval,width,yval));
+		  check_nomsg(tot+=cpl_image_get_flux_window(ima_in,sx-width+1,
+							yval,sx,yval));
+		  mean=tot/(2. * width);
+		  check_nomsg(pima=cpl_image_get_data_float(*ima_out));
+		  for(i=width;i<sx-width;i++) {
+		pima[i+(yval-1)*sx]+=(float)(mean-medvalue);
+		  }
+
+		}
+	  }
+  }
+
+
+ cleanup:
+
+  sinfo_free_image(&mask); //is mask needed?
+  sinfo_free_image(&ima_backpos);
+  sinfoni_free_matrix(&filter);
+  sinfo_free_image(&ima_filt);
+  sinfo_free_image(&ima_diffbackpix);
+//  sinfo_free_mask(&bpm_good);
+  sinfo_free_image(&ima_backpix);
+  sinfo_free_mask(&bpm_bad);
+  sinfo_free_image(&ima_ybackpix);
+  cpl_image_delete(ima);
+  cpl_free(ybad);
+  return cpl_error_get_code();
+
+}
+
+
+/**
+ at name sinfo_new_my_median_image
+ at brief Computes the median of an image
+ at param im image
+ at return clean median
+ at note The median is computed rejecting NANs
+*/
+
+double sinfo_new_my_median_image(cpl_image* im)
+{
+  double m=0;
+  register int i=0;
+  int n=0;
+  pixelvalue* pv=0;
+  int ilx=0;
+  int ily=0;
+  float* pidata=NULL;
+
+
+  if(im==NULL) sinfo_msg_error("Null Image");
+  ilx=cpl_image_get_size_x(im);
+  ily=cpl_image_get_size_y(im);
+  pidata=cpl_image_get_data_float(im);
+
+   for ( i = 0 ; i < (int) ilx*ily ; i++ )
+    {
+      if ( isnan(pidata[i]) )
+        {
+
+    } else {
+      n++;
+    }
+    }
+   pv = cpl_calloc(n,sizeof(pixelvalue));
+   n=0;
+   for ( i = 0 ; i < (int) ilx*ily ; i++ )
+    {
+      if ( isnan(pidata[i]) )
+        {
+
+    } else {
+      pv[n]=pidata[i];
+          n++;
+    }
+    }
+   if(pv == NULL || n == 0) {
+     m=0;
+   } else {
+     m=sinfo_new_median(pv,n);
+   }
+   cpl_free(pv);
+   if(isnan(m)){
+     m=0;
+   }
+  return m;
+}
+
+/**
+ at name sinfo_new_mean_of_columns
+ at brief   takes the average of each image column
+ @param image
+ @return resulting row array
+ @note NANs are not considered
+ */
+
+Vector * sinfo_new_mean_of_columns( cpl_image *im )
+{
+    Vector * row=NULL ;
+    int i=0;
+    int j=0;
+    int ilx=0;
+    int ily=0;
+    float* pidata=NULL;
+
+    if ( im == NULL )
+    {
+        sinfo_msg_error ("null image") ;
+        return NullVector ;
+    }
+    ilx=cpl_image_get_size_x(im);
+    ily=cpl_image_get_size_y(im);
+    pidata=cpl_image_get_data_float(im);
+
+    /* allocate memory for a row with the length of the image x-axis */
+    if ( NULL == (row = sinfo_new_vector (ilx)) )
+    {
+        sinfo_msg_error ("not able to allocate a sinfo_vector" ) ;
+        return NullVector ;
+    }
+
+    for ( i = 0 ; i < ilx ; i++ )
+    {
+        for ( j = 0 ; j < ily ; j++ )
+        {
+            if (!isnan(pidata[i+j*ilx]))
+            {
+                row->data[i] += pidata[i + j*(ilx)] ;
+            }
+        }
+
+        row->data[i] /= ily ;
+    }
+    return row ;
+}
+/**
+ at name sinfo_new_clean_mean_of_columns
+ at brief computes the clean mean of image columns
+
+  @param image , percentage of lowest and highest values to reject
+  @return resulting row image
+  @doc
+  takes the average of each image column by sorting the column values and
+  rejecting the given percentage of the highest and lowest values  [0...1]
+ */
+
+cpl_image * sinfo_new_clean_mean_of_columns( cpl_image *im,
+                             float lo_reject,
+                             float hi_reject)
+{
+    cpl_image     * row=NULL ;
+    pixelvalue*   buffer=NULL ;
+    int          i=0;
+    int          j=0;
+    int          k=0;
+    int          nv=0;
+    int          lo_n=0;
+    int          hi_n=0;
+    int ilx=0;
+    int ily=0;
+    float* pidata=NULL;
+    float* podata=NULL;
+
+    if ( im == NULL )
+    {
+        sinfo_msg_error ("null image") ;
+        return NULL ;
+    }
+    ilx=cpl_image_get_size_x(im);
+    ily=cpl_image_get_size_y(im);
+    pidata=cpl_image_get_data_float(im);
+
+    if ((lo_reject + hi_reject) > 0.9)
+    {
+        sinfo_msg_error("illegal rejection thresholds: [%f] and [%f]",
+                        lo_reject, hi_reject) ;
+        sinfo_msg_error("threshold sum should not be over "
+                        "0.90 aborting average") ;
+        return NULL ;
+    }
+
+    lo_n = (int) (ily * lo_reject + 0.5) ;
+    hi_n = (int) (ily * hi_reject + 0.5) ;
+    if (lo_n + hi_n >= ily)
+    {
+        sinfo_msg_error ("everything would be rejected") ;
+        return NULL ;
+    }
+
+    /* allocate memory for a row with the length of the image x-axis */
+    if ( NULL == (row = cpl_image_new (ilx, 1,CPL_TYPE_FLOAT)) )
+    {
+        sinfo_msg_error ("cannot allocate new image") ;
+        return NULL ;
+    }
+    podata=cpl_image_get_data_float(row);
+
+    buffer=(pixelvalue*) cpl_calloc(ily,sizeof(pixelvalue)) ;
+
+    for ( i = 0 ; i < ilx ; i++ )
+    {
+        for ( j = 0 ; j < ily ; j++ )
+        {
+            buffer[j] = pidata[i + j*(ilx)] ;
+        }
+        sinfo_pixel_qsort (buffer, ily) ;
+
+        nv = 0 ;
+        for (k = lo_n ; k < ily - hi_n ; k ++)
+        {
+            if ( !isnan(buffer[k]) )
+            {
+                podata[i] += buffer[k] ;
+                nv ++ ;
+            }
+        }
+        podata[i] /= nv ;
+
+    }
+    cpl_free(buffer);
+    return row ;
+}
+
+
+/**
+ at name sinfo_new_div_image_by_row
+ at brief divides each image column by a row value
+
+   @param image, row array
+   @return resulting image
+   @note NANs values are not considered
+ */
+
+cpl_image * sinfo_new_div_image_by_row( cpl_image *im, Vector *row )
+{
+    cpl_image *image=NULL ;
+    int         i=0;
+    int         j=0;
+    int ilx=0;
+    int ily=0;
+    float* pidata=NULL;
+    float* podata=NULL;
+
+    if ( im == NULL || row == NULL )
+    {
+        sinfo_msg_error ("null image or null row") ;
+        return NULL ;
+    }
+    ilx=cpl_image_get_size_x(im);
+    ily=cpl_image_get_size_y(im);
+    pidata=cpl_image_get_data_float(im);
+
+    if ( ilx != row -> n_elements )
+    {
+        sinfo_msg_error("image and row size not compatible") ;
+        return NULL ;
+    }
+
+    if ( NULL == (image = cpl_image_duplicate (im)) )
+    {
+        sinfo_msg_error ("cannot copy image") ;
+        return NULL ;
+    }
+    podata=cpl_image_get_data_float(image);
+
+    for (i = 0 ; i < ilx ; i++ )
+    {
+        for (j = 0 ; j < ily ; j++)
+        {
+            if ( !isnan(pidata[i + j*(ilx)]) )
+            {
+                podata[i + j*(ilx)] = pidata[i + j*(ilx)] / row -> data[i] ;
+            }
+        }
+    }
+    return image ;
+}
+
+
+/**
+ at name sinfo_new_mult_row_to_image
+ at brief multiplies each image column with a row value
+
+   @param image, row array
+   @return resulting image
+   @note NANs values are not considered
+ */
+
+cpl_image * sinfo_new_mult_row_to_image( cpl_image *im, Vector *row )
+{
+    cpl_image *image=NULL;
+    int         i=0;
+    int         j=0;
+    int ilx=0;
+    int ily=0;
+    float* pidata=NULL;
+    float* podata=NULL;
+
+
+
+
+    if ( im == NULL || row == NULL )
+    {
+        sinfo_msg_error ("null image or null row") ;
+        return NULL ;
+    }
+    ilx=cpl_image_get_size_x(im);
+    ily=cpl_image_get_size_y(im);
+    pidata=cpl_image_get_data_float(im);
+
+    if ( ilx != row -> n_elements )
+    {
+        sinfo_msg_error("image and row size not compatible") ;
+        return NULL ;
+    }
+
+    if ( NULL == (image = cpl_image_duplicate (im)) )
+    {
+        sinfo_msg_error ("cannot copy image") ;
+        return NULL ;
+    }
+    podata=cpl_image_get_data_float(image);
+
+    for (i = 0 ; i < ilx ; i++ )
+    {
+        for (j = 0 ; j < ily ; j++)
+        {
+            if ( !isnan(pidata[i + j*(ilx)]) )
+            {
+                podata[i + j*(ilx)] = pidata[i + j*(ilx)] * row -> data[i] ;
+            }
+        }
+    }
+    return image ;
+}
+
+
+
+
+
+
+/**
+ at brief
+   @name sinfo_new_col_tilt
+
+   @param image , factor of sigma noise limit to determine
+                        pixels that are used for the fit.
+   @return image
+
+
+   @doc         : first calculates statistics for each column of an image.
+                  median value and standard deviation of columns are de-
+                  termined, blank values are excluded. Fits a straight
+                  line through the pixel values of each column and subtracts
+                  the fit in order to remove the tilt of each column.
+                  Only those pixels are used for the fit that are within
+                  a defined factor of sigma noise limit. The noise is
+                  calculated from pixels between the 10percentil and
+                  90 percentil points.
+                  if the straight line could not be determined, the median
+                  of the column is subtracted from the column
+   @note       :  works only for raw or averaged raw images
+*/
+
+cpl_image * sinfo_new_col_tilt ( cpl_image * image, float sigmaFactor )
+{
+    cpl_image   * im=NULL;
+    float      * column=NULL ;
+    double       sum=0;
+    double  sum2=0;
+    double  mean=0;
+    float   sinfo_median=0;
+    float   noise=0 ;
+    float      * sig=NULL;
+    float    * dat=NULL;
+    float        a=0;
+    float        b=0;
+    float        siga=0;
+    float        sigb=0;
+    float        chi2=0;
+    float        q=0;
+    int          i=0;
+    int          j=0;
+    int          colnum=0;
+    int         npix=0;
+    int         mwt=0 ;
+    int lx=0;
+    int ly=0;
+    float* p_in_data=NULL;
+    float* p_ou_data=NULL;
+
+
+    if ( image == NULL )
+    {
+        sinfo_msg_error ("no image given" ) ;
+        return NULL ;
+    }
+
+    if ( sigmaFactor <= 0. )
+    {
+        sinfo_msg_error ("no or negative sigma factor") ;
+        return NULL ;
+    }
+    lx = cpl_image_get_size_x(image);
+    ly = cpl_image_get_size_y(image);
+
+
+    /* allocate memory */
+    if ( NULL == (im = cpl_image_new (lx,ly,CPL_TYPE_FLOAT )) )
+    {
+        sinfo_msg_error ("cannot allocate new image" ) ;
+        return NULL ;
+    }
+
+    /* go through the columns */
+    p_in_data = cpl_image_get_data_float(image);
+    p_ou_data = cpl_image_get_data_float(im);
+    for ( i = 0 ; i < lx ; i ++ )
+    {
+        /* initialize the buffer variables for each column */
+        colnum = 0 ;
+        column = (float *) cpl_calloc ( ly , sizeof (float *) ) ;
+        sig    = (float *) cpl_calloc ( ly , sizeof (float *) ) ;
+        dat    = (float *) cpl_calloc ( ly , sizeof (float *) ) ;
+
+        /*select only non-ZERO values of one column*/
+        for ( j = 0 ; j < ly ; j++ )
+        {
+            if ( !isnan(p_in_data[i + j*lx]) )
+            {
+                column[j] = p_in_data[i + j*lx] ;
+                colnum ++ ;
+            }
+        }
+        if ( colnum < 10 )
+        {
+            /*sinfo_msg_warning ("sinfo_new_col_tilt:",
+          "column %d has almost only blank pixels and is set to blank", i+1) ;*/
+            for ( j = 0 ; j < ly ; j++ )
+            {
+                p_ou_data[i + j*lx] = ZERO;
+            }
+            /*
+            cpl_free (column) ;
+            cpl_free (sig);
+            cpl_free (dat) ;
+            continue ;
+            */
+        }
+
+        /*-------------------------------------------------------------------
+         * sort the data, clip off the extremes, determine the noise
+         * and get the range for the valid data. It is assumed here
+         * that most pixels are o.k.
+         */
+
+        sinfo_pixel_qsort (column, colnum) ;
+
+        sum   = 0. ;
+        sum2  = 0. ;
+        npix  = 0  ;
+
+        for ( j = 0.1*colnum + 1 ; j <= 0.9*colnum ; j++ )
+        {
+            sum  += column[j] ;
+            sum2 += column[j] * column[j] ;
+            npix ++ ;
+        }
+
+        if (npix <= 1)
+        {
+            noise = sigmaFactor * 1000.;
+        }
+        else
+        {
+            mean   = sum/(float)npix ;
+            noise  = sqrt( (sum2 - sum*mean)/(double)(npix -1) ) ;
+            noise *= sigmaFactor ;
+        }
+
+        /* -------------------------------------------------------------
+         * determine sinfo_median if colnum is odd, sinfo_median will be the
+           colnum/2 th value, otherwise
+         * sinfo_median is the mean of colnum/2-1 th and colnum/2 th value.
+         */
+
+        if ( colnum % 2 == 1 )
+        {
+            sinfo_median = column[colnum/2] ;
+        }
+        else
+        {
+            sinfo_median = (column[colnum/2 - 1] + column[colnum/2])/2. ;
+        }
+
+        /* now select the pixels for the tilt calculation */
+
+        colnum = 0 ;
+        for ( j = 0; j < ly ; j ++ )
+        {
+            if ( !isnan(p_in_data[i+j*lx]) &&
+                 fabs ( (p_in_data[i+j*lx]) - sinfo_median) <= noise )
+            {
+                column[colnum] = p_in_data[i+j*lx] ;
+                dat[colnum] = (float) j ;
+                sig[colnum] = 1. ;
+                colnum ++ ;
+            }
+        }
+
+        if ( colnum == 0 )
+        {
+            /*for ( j = 0; j < ly; j++ )
+            {
+                p_ou_data[i+j*lx] -= sinfo_median ;
+            }
+            cpl_free (column) ;
+            cpl_free (sig)    ;
+            cpl_free (dat)    ;
+            continue ;*/
+        a=0./0.;
+        b=0./0.;
+        }
+    else
+    {
+        mwt = 0 ;
+        sinfo_my_fit ( dat, column, colnum, sig, mwt, &a,
+                       &b, &siga, &sigb, &chi2, &q ) ;
+    }
+        if ( fabs(b) >= SLOPE || fabs(a) >= SATURATION  ||
+             isnan(b) || isnan(a))
+        {
+            sinfo_msg_warning ("linear fit: slope is greater than limit: %f"
+                               " saturation level is reached: %f in column"
+                               " number %d ", b, a , i+1) ;
+        }
+
+        /* subtract fit or sinfo_median from data */
+        for ( j = 0; j < ly; j++ )
+        {
+            if ( !isnan(p_in_data[i+j*lx]) &&
+                 fabs(b) < SLOPE && fabs(a) < SATURATION )
+            {
+                p_ou_data[i+j*lx] = p_in_data[i+j*lx] - (a + b * (float)j) ;
+            }
+            else if ( isnan(p_in_data[i+j*lx]) )
+            {
+                p_ou_data[i+j*lx] = ZERO ;
+            }
+            else if ( (fabs(b) >= SLOPE ||
+                       fabs(a) >= SATURATION || isnan(a) || isnan(b)) &&
+                      !isnan(p_in_data[i+j*lx]) )
+            {
+                p_ou_data[i+j*lx] -= sinfo_median ;
+            }
+            else
+            {
+                sinfo_msg_error (" case is not possible! %f %f", b,a) ;
+                /*cpl_free (column) ;
+                cpl_free (sig)    ;
+                cpl_free (dat)    ;
+                cpl_image_delete(im) ;
+                return NULL ;*/
+            }
+        }
+        cpl_free (column) ;
+        cpl_free (sig)    ;
+        cpl_free (dat)    ;
+    }
+
+    return im     ;
+}
+
+
+
+
+
+/**
+   @name sinfo_new_median_image
+   @brief median filter
+   @param image, a sinfo_median threshold parameter
+   @return resulting image
+   @doc
+   median filter, calculates the sinfo_median for an image
+   by using the 8 closest pixels of every pixel.
+   The values in the output image are determined according
+   to the values of the input parameter.
+   If fmedian = 0: always replace by sinfo_median
+   if fmedian < 0: replace by sinfo_median if |pixel - median| > -fmedian
+   if fmedian > 0: replace by sinfo_median (fmedian as a factor of
+                   the square root of the median itself)
+   if |pixel - median| >= fmedian * sqrt ( median )
+   This can be used to consider photon noise.
+   This considers a dependence of the differences on the pixel values
+   themselves.
+   @note it is assumed that most of the 8 nearest neighbor pixels
+                        are not bad pixels!
+                        blank pixels are not replaced!
+ */
+
+cpl_image * sinfo_new_median_image( cpl_image * im, float fmedian )
+{
+    cpl_image *   image=NULL       ;
+    pixelvalue * value=NULL       ;
+    pixelvalue   sinfo_median=0      ;
+    int        * position=NULL    ;
+    int          nposition=0   ;
+    int          n=0;
+    int          i=0;
+    int          j=0;
+    int lx=0;
+    int ly=0;
+    float* p_in_data=NULL;
+    float* p_ou_data=NULL;
+    int im_size=0;
+    if ( im == NULL )
+    {
+        sinfo_msg_error ("no image input") ;
+        return NULL ;
+    }
+
+    image = cpl_image_duplicate ( im ) ;
+    lx=cpl_image_get_size_x(im);
+    ly=cpl_image_get_size_y(im);
+    im_size=lx*ly;
+    p_in_data=cpl_image_get_data_float(im);
+    p_ou_data=cpl_image_get_data_float(image);
+
+    /*----------------------------------------------------------------------
+     * go through all pixels
+     */
+
+    for ( i = 0 ; i < im_size ; i++ )
+    {
+        /* blank pixels are not replaced */
+        if ( isnan(p_in_data[i]) )
+        {
+            continue ;
+        }
+
+        /* initialize the buffer variables for the 8 nearest neighbors */
+        value = (pixelvalue * )cpl_calloc ( 8, sizeof ( pixelvalue * ) ) ;
+        position = ( int * ) cpl_calloc ( 8, sizeof ( int * ) ) ;
+
+        /*--------------------------------------------------------------------
+         * determine the pixel position of the 8 nearest neighbors
+         */
+
+        position[0] = i + lx - 1 ; /* upper left  */
+        position[1] = i + lx     ; /* upper       */
+        position[2] = i + lx + 1 ; /* upper right */
+        position[3] = i + 1      ; /* right       */
+        position[4] = i - lx + 1 ; /* lower right */
+        position[5] = i - lx     ; /* lower       */
+        position[6] = i - lx - 1 ; /* lower left  */
+        position[7] = i - 1      ; /* left        */
+
+        /*-------------------------------------------------------------------
+         * determine the positions of the image margins, top positions are
+           changed to low positions and vice versa. Right positions are
+           changed to left positions and vice versa.
+         */
+
+        if ( i >= 0 && i < lx )    /* bottom line */
+        {
+            position[4] += 2 * lx ;
+            position[5] += 2 * lx ;
+            position[6] += 2 * lx ;
+        }
+        else if ( i >= ((int) lx*ly - lx ) && i < (int) lx*ly ) /* top line */
+        {
+            position[0] -= 2 * lx ;
+            position[1] -= 2 * lx ;
+            position[2] -= 2 * lx ;
+        }
+        else if ( i % lx == 0 )    /* left side */
+        {
+            position[0] += 2 ;
+            position[6] += 2 ;
+            position[7] += 2 ;
+        }
+        else if ( i % lx == lx - 1 )    /* right side */
+        {
+            position[2] -= 2 ;
+            position[3] -= 2 ;
+            position[4] -= 2 ;
+        }
+
+        /* --------------------------------------------------------------------
+         * read the pixel values of the neighboring pixels,
+         * blanks are not considered
+         */
+
+        nposition = 8 ;
+        n = 0 ;
+        for ( j = 0 ; j < nposition ; j ++ )
+        {
+           if((position[j] >-1 ) && (position[j]<im_size)) {
+              if ( !isnan(p_in_data[position[j]]) )
+              {
+                value[n] = p_in_data[position[j]] ;
+                n ++ ;
+              }
+           }
+        }
+        nposition = n ;
+
+        if ( nposition <= 1 )  /* almost all neighbors are blank */
+        {
+            p_ou_data[i] = ZERO ;
+            cpl_free(value) ;
+            cpl_free(position) ;
+            continue ;
+        }
+
+        /* sort the values and determine the sinfo_median */
+
+        sinfo_pixel_qsort ( value, nposition ) ;
+        if ( nposition % 2 == 1 )
+        {
+            sinfo_median = value [ nposition/2 ] ;
+        }
+        else
+        {
+            sinfo_median = ( value [nposition/2 - 1] +
+                             value [nposition/2] ) / 2. ;
+        }
+
+        /* -----------------------------------------------------------------
+         * replace the pixel value by the sinfo_median on conditions:
+         * fmedian = 0: always replace with sinfo_median.
+         * fmedian < 0: interpret as absolute condition:
+         *              if |pixel - sinfo_median| > -fmedian
+         *              replace with sinfo_median.
+         * fmedian > 0: replace by sinfo_median (fmedian as a factor of
+         *              the square root of the sinfo_median itself)
+         *              if |pixel - sinfo_median| >= fmedian *
+                                                     sqrt ( sinfo_median )
+         *              considers a dependence on the pixel value.
+         *              This can be used to consider photon noise.
+         */
+
+        if ( fmedian == 0 )
+        {
+            p_ou_data[i] = sinfo_median ;
+        }
+        else if ( fmedian < 0 &&
+                  fabs ( sinfo_median - p_in_data[i] ) >= -fmedian )
+        {
+            p_ou_data[i] = sinfo_median ;
+        }
+        else if ( fmedian > 0 &&
+                  fabs ( sinfo_median - p_in_data[i] ) >= fmedian *
+                                                      sqrt(fabs(sinfo_median)) )
+        {
+            p_ou_data[i] = sinfo_median ;
+        }
+        else
+        {
+            cpl_free (value) ;
+            cpl_free (position) ;
+            continue ;
+        }
+
+        cpl_free (value) ;
+        cpl_free (position) ;
+    }
+    return image ;
+}
+
+
+
+
+/**
+   @name sinfo_new_compare_images
+   @brief if a pixel value of one image (im1) equals the pixel value
+          of the other image keep the pixel value of the original image
+          otherwise replace it with ZEROs
+   @param sinfo_new_compare_images()
+   @param two images to be compared and the original image
+   @return resulting image
+ */
+
+cpl_image *
+sinfo_new_compare_images(cpl_image * im1,cpl_image * im2,cpl_image * origim )
+{
+    cpl_image * image=NULL ;
+    int            i=0 ;
+    int lx1=0;
+    int ly1=0;
+    int lx2=0;
+    int ly2=0;
+    float* p_in1_data=NULL;
+    float* p_in2_data=NULL;
+    float* p_ou_data=NULL;
+    float* p_org_data=NULL;
+
+
+    if ( im1 == NULL || im2 == NULL || origim == NULL )
+    {
+        sinfo_msg_error ("Null images as input" ) ;
+        return NULL ;
+    }
+    lx1=cpl_image_get_size_x(im1);
+    ly1=cpl_image_get_size_y(im1);
+
+    lx2=cpl_image_get_size_x(im2);
+    ly2=cpl_image_get_size_y(im2);
+
+    p_in1_data=cpl_image_get_data_float(im1);
+    p_in2_data=cpl_image_get_data_float(im2);
+    p_org_data=cpl_image_get_data_float(origim);
+    if ( lx1 != lx2 || ly1 != ly2 )
+    {
+        sinfo_msg_error ("incompatible image sizes" ) ;
+        return NULL ;
+    }
+
+    /* allocate memory */
+    if ( NULL == (image = cpl_image_new ( lx1, ly1, CPL_TYPE_FLOAT )) )
+    {
+        sinfo_msg_error ("cannot allocate new image" ) ;
+        return NULL ;
+    }
+    p_ou_data=cpl_image_get_data_float(image);
+    for ( i = 0 ; i < (int) lx1*ly1 ; i ++ )
+    {
+        if ( isnan(p_in1_data[i]) && isnan(p_in2_data[i]) )
+        {
+            p_ou_data[i] = ZERO ;
+        }
+        else
+        {
+            if ( p_in1_data[i] == p_in2_data[i] )
+            {
+                p_ou_data[i] = p_org_data[i] ;
+            }
+            else
+            {
+                p_ou_data[i] = ZERO ;
+            }
+        }
+    }
+    return image ;
+}
+
+
+
+/**
+  @name info_new_promote_image_to_mask
+  @brief changes an image with ZERO indicated bad pixels to a bad pixel mask
+         image, that means the returned image has values 1 at positions of
+         good pixels and 0 at positions of bad pixels.
+  @name sinfo_new_promote_image_to_mask()
+  @param image with ZERO indicating bad pixels
+  @return resulting mask image that means 1 for good pixels and 0 for bad pixel
+          positions n_badpixels: number of bad pixels
+ */
+
+cpl_image *
+sinfo_new_promote_image_to_mask (cpl_image * im, int * n_badpixels )
+{
+    cpl_image * reImage=NULL ;
+    int        i=0 ;
+    int lx=0;
+    int ly=0;
+    float* p_in_data=NULL;
+    float* p_ou_data=NULL;
+
+    if ( NULL == im )
+    {
+        sinfo_msg_error("no input image given!") ;
+        return NULL ;
+    }
+    lx=cpl_image_get_size_x(im);
+    ly=cpl_image_get_size_y(im);
+    p_in_data=cpl_image_get_data_float(im);
+
+    /* allocate memory for the returned image */
+    if ( NULL == (reImage = cpl_image_new (lx,ly,CPL_TYPE_FLOAT )) )
+    {
+        sinfo_msg_error ("cannot allocate new image!") ;
+        return NULL ;
+    }
+    p_ou_data=cpl_image_get_data_float(reImage);
+
+    *n_badpixels = 0 ;
+    for ( i = 0 ; i < (int) lx*ly ; i ++ )
+    {
+        if ( isnan(p_in_data[i]) )
+        {
+            p_ou_data[i] = 0. ;
+            (*n_badpixels)++ ;
+        }
+        else
+        {
+            p_ou_data[i] = 1. ;
+        }
+    }
+    return reImage ;
+}
+
+
+/**
+ @name sinfo_new_mult_image_by_mask
+ @brief changes an image to an image that has ZERO indicated static bad pixels
+ @name        sinfo_new_mult_image_by_mask()
+ @param im:   input image
+ @param mask: mask image
+ @return resulting image that means the input image with marked
+                        static bad pixels (ZERO values)
+ */
+
+cpl_image * sinfo_new_mult_image_by_mask (cpl_image * im,cpl_image * mask )
+{
+    cpl_image * reImage=NULL ;
+    int        i=0 ;
+    int ix=0;
+    int iy=0;
+    int mx=0;
+    int my=0;
+
+
+    float* pmdata=NULL;
+    float* podata=NULL;
+
+    if ( NULL == im )
+    {
+        sinfo_msg_error("no input image given!") ;
+        return NULL ;
+    }
+    if ( NULL == mask )
+    {
+        sinfo_msg_error("no mask image given!") ;
+        return NULL ;
+    }
+    ix=cpl_image_get_size_x(im);
+    iy=cpl_image_get_size_y(im);
+    mx=cpl_image_get_size_x(mask);
+    my=cpl_image_get_size_y(mask);
+
+    if ( ix != mx || iy != my)
+    {
+        sinfo_msg_error("image sizes are not correspondent!") ;
+        return NULL ;
+    }
+
+    reImage = cpl_image_duplicate( im ) ;
+    podata=cpl_image_get_data_float(reImage);
+    pmdata=cpl_image_get_data_float(mask);
+
+    for ( i = 0 ; i < (int) ix*iy ; i ++ )
+    {
+        if ( pmdata[i] == 0. )
+        {
+            podata[i] = ZERO ;
+        }
+    }
+
+    return reImage ;
+}
+
+
+
+/**
+   @name sinfo_new_thresh_image
+   @brief simple search for static bad pixels for a flat field or dark frame,
+          values below and above the threshold values are set to ZERO.
+
+   @param image, low cut pixel value, high cut pixel value
+   @return resulting image
+ */
+
+cpl_image *
+sinfo_new_thresh_image (cpl_image * im, float lo_cut, float hi_cut )
+{
+    cpl_image * image=NULL ;
+    float* p_inp_data=NULL;
+    float* p_out_data=NULL;
+    int lx=0;
+    int ly=0;
+
+    int            i=0 ;
+
+    if (im == NULL)
+    {
+        sinfo_msg_error ("null image given") ;
+        return NULL ;
+    }
+    lx=cpl_image_get_size_x(im);
+    ly=cpl_image_get_size_y(im);
+
+    image = cpl_image_duplicate(im) ;
+    p_inp_data=cpl_image_get_data(im);
+    p_out_data=cpl_image_get_data(image);
+    for ( i = 0 ; i < (int) lx*ly ; i ++ )
+    {
+        if ( p_inp_data[i] > (pixelvalue) hi_cut ||
+             p_inp_data[i] < (pixelvalue) lo_cut )
+        {
+             p_out_data[i] = ZERO ;
+        }
+    }
+    return image ;
+}
+
+
+
+
+/**
+ @brief interpolates all bad pixels indicated by the bad pixel mask.
+ @name   :       sinfo_new_interpol_image()
+ @param im: raw image
+ @param mask: bad pixel mask
+ @param max_radius: maximum x and y distance in pixels from the
+                    bad pixel within which valid pixels for
+                    interpolation are searched.
+ @param n_pixels:   minimal number of pixels with which the bad
+                    pixel is interpolated if not enough
+                    valid nearest neighbors are found.
+ @return resulting interpolated image without any ZEROS
+ @doc
+ interpolates all bad pixels indicated by the bad pixel mask.
+ Therefore, the mean of at least 2 valid values of the nearest 8 neighbors
+ is taken. If too much neighbors are also bad pixels
+ the neighbor radius is increased to a maximum of
+ max_radius until n_pixels valid pixels are found.
+ The valid neighbors are searched by going through
+ the columns and rows around the central square that was already searched.
+ The bad pixel is interpolated by the mean of these valid pixels (less than 9)
+ or by the sinfo_median of them (more than 8).
+ */
+
+cpl_image * sinfo_new_interpol_image ( cpl_image * im,
+                           cpl_image * mask,
+                           int        max_radius,
+                           int        n_pixels )
+{
+    cpl_image * returnImage=NULL ;
+    float* neighbors=NULL ;
+    float sum=0;
+    float mean=0;
+    int i=0;
+    int j=0;
+    int k=0;
+    int row=0;
+    int col=0;
+    int n_valid=0;
+    int agreed=0;
+
+    int ilx=0;
+    int ily=0;
+    int mlx=0;
+    int mly=0;
+    float* pidata=NULL;
+    float* podata=NULL;
+    float* pmdata=NULL;
+
+    if ( NULL == im )
+    {
+        sinfo_msg_error("sorry, no input image given!") ;
+        return NULL ;
+    }
+    ilx=cpl_image_get_size_x(im);
+    ily=cpl_image_get_size_y(im);
+    pidata=cpl_image_get_data_float(im);
+
+    if ( NULL == mask )
+    {
+        sinfo_msg_error("sorry, no mask image given!") ;
+        return NULL ;
+    }
+
+    mlx=cpl_image_get_size_x(mask);
+    mly=cpl_image_get_size_y(mask);
+    pmdata=cpl_image_get_data_float(mask);
+
+    if ( mlx != ilx || mly != mly )
+    {
+        sinfo_msg_error("images not compatible !") ;
+        return NULL ;
+    }
+
+    if ( max_radius <= 0 )
+    {
+        sinfo_msg_error("wrong number of pixels for maximal "
+                        "search radius given!") ;
+        return NULL ;
+    }
+
+    if ( n_pixels <= 2 )
+    {
+        sinfo_msg_error("wrong number of pixels used "
+                        "for interpolation given!") ;
+        return NULL ;
+    }
+
+    returnImage = cpl_image_duplicate ( im ) ;
+    podata=cpl_image_get_data_float(returnImage);
+
+    /* go through the columns and rows of the input and mask image */
+    neighbors=cpl_calloc(4*max_radius*max_radius,sizeof(float)) ;
+
+    for ( col = 0 ; col < ilx ; col++ )
+    {
+        for ( row = 0 ; row < ily ; row++ )
+        {
+            /* look for the ZEROS that means the detected bad pixels */
+            if ( isnan(pmdata[col+row*ilx]) || pmdata[col+row*ilx] == 0. )
+            {
+                /* now the neighbors must be considered */
+                n_valid = 0 ;
+                agreed  = 0 ;
+                for ( j = 1 ; j <= max_radius ; j++ )
+                {
+
+                    /* go through the left column */
+                    for ( k = -j ; k < j ; k++ )
+                    {
+                        if ( col-j >= 0 && row+k < ily && row+k >= 0 )
+                        {
+                            if ( !isnan(pmdata[col-j+(row+k)*mlx]) ||
+                                 pmdata[col-j+(row+k)*mlx] != 0 )
+                            {
+                                neighbors[n_valid]=pidata[col-j+(row+k)*ilx] ;
+                                n_valid++ ;
+                            }
+                        }
+                    }
+
+                    /* go through the upper row */
+                    for ( k = -j ; k < j ; k++ )
+                    {
+                        if ( col+k < ilx && col+k >= 0 && row+j < ily )
+                        {
+                            if ( !isnan(pmdata[col+k+(row+j)*mlx]) ||
+                                 pmdata[col+k+(row+j)*mlx] != 0. )
+                            {
+                                neighbors[n_valid]=pidata[col+k+(row+j)*ilx] ;
+                                n_valid++ ;
+                            }
+                        }
+                    }
+
+                    /* go through the right column */
+                    for ( k = -j ; k < j ; k++ )
+                    {
+                        if ( col+j < ilx  && row-k >= 0 && row-k < ily )
+                        {
+                            if ( !isnan(pmdata[col+j+(row-k)*mlx]) ||
+                                 pmdata[col+j+(row-k)*mlx] != 0. )
+                            {
+                                neighbors[n_valid]=pidata[col+j+(row-k)*ilx] ;
+                                n_valid++ ;
+                            }
+                        }
+                    }
+
+                    /* go through the lower row */
+                    for ( k = -j ; k < j ; k++ )
+                    {
+                        if ( col-k >= 0 && col-k < ilx && row-j < ily )
+                        {
+                            if ( !isnan(pmdata[col-k+(row-j)*mlx]) ||
+                                 pmdata[col-k+(row-j)*mlx] != 0. )
+                            {
+                                neighbors[n_valid]=pidata[col-k+(row-j)*ilx] ;
+                                n_valid++ ;
+                            }
+                        }
+                    }
+
+                    /* control if the breaking criteria is fullfilled */
+                    if ( n_valid >= n_pixels )
+                    {
+                        agreed = 1 ;
+                        break ;
+                    }
+                    /* do a break if more than 2 nearest neighbors are found */
+                    if ( j == 1 && n_valid >= 2 )
+                    {
+                        agreed = 1 ;
+                        break ;
+                    }
+                }
+                if ( n_valid < n_pixels && agreed == 0 )
+                {
+                    sinfo_msg_error("not enough valid neighbors found to "
+                                    "interpolate bad pixel in col: "
+                                    "%d, row: %d", col, row ) ;
+                    return NULL ;
+                }
+                else
+                {
+                    /* ------------------------------------------------------
+                     * take the mean of the valid neighboring pixels if less
+                     * than 9 valid pixels are available else take the
+                       sinfo_median.
+                     */
+                    if ( n_valid <= 8 )
+                    {
+                        sum = 0. ;
+
+                        for ( i = 0 ; i < n_valid ; i++ )
+                        {
+                            sum += neighbors[i] ;
+                        }
+                        mean = sum / n_valid ;
+
+                        podata[col+row*ilx] = mean ;
+                    }
+                    else
+                    {
+                       podata[col+row*ilx]=sinfo_new_median(neighbors,n_valid);
+                    }
+                }
+            }
+        }
+    }
+    cpl_free(neighbors);
+    return returnImage ;
+}
+
+
+/**
+ at brief
+ @name     :       sinfo_interpol_source_image()
+ @param im:         source raw image
+ @param mask:       bad pixel mask
+ @param max_rad:    maximum pixel distance from the bad pixel to
+                    interpolate where
+                    valid pixel values are searched for.
+ @param slit_edges: array of the edges of the slitlets.
+ @return resulting interpolated image hopefully without any ZEROS
+
+ @doc
+ interpolates all bad pixels indicated by the bad pixel mask.
+ Therefore, the mean of the nearest 4 neighbors is taken,
+ two in spectral direction and 2 in spatial direction.
+ The routine cares about the image and slitlet edges.
+ If there are no good pixel found within the nearest neighbors,
+ the next 4 nearest neighbors in spatial and spectral direction
+ are searched for valid pixels until a limit of max_rad.
+ A maximum of 4 valid pixels are used for interpolation by their mean.
+ */
+
+cpl_image * sinfo_interpol_source_image ( cpl_image * im,
+                                 cpl_image * mask,
+                                 int        max_rad,
+                                 float   ** slit_edges )
+{
+    cpl_image * returnImage=NULL ;
+    float validpixel[6] ;
+    float sum=0 ;
+    int n=0;
+    int row=0;
+    int col=0;
+    int i=0;
+    int k=0;
+    int slitlet=0;
+    int n_slitlets=0;
+    int ilx=0;
+    int ily=0;
+    int mlx=0;
+    int mly=0;
+
+    float* pidata=NULL;
+    float* podata=NULL;
+    float* pmdata=NULL;
+
+
+    if ( NULL == im )
+    {
+        sinfo_msg_error("sorry, no input image given!") ;
+        return NULL ;
+    }
+    ilx=cpl_image_get_size_x(im);
+    ily=cpl_image_get_size_y(im);
+    pidata=cpl_image_get_data_float(im);
+
+    if ( NULL == mask )
+    {
+        sinfo_msg_error("sorry, no bad pixel mask image given!") ;
+        return NULL ;
+    }
+    mlx=cpl_image_get_size_x(mask);
+    mly=cpl_image_get_size_y(mask);
+    pmdata=cpl_image_get_data_float(mask);
+
+    if ( mlx != ilx || mly != ily )
+    {
+        sinfo_msg_error("images not compatible in size!") ;
+        return NULL ;
+    }
+
+    if ( max_rad < 1 )
+    {
+        sinfo_msg_error("sorry, wrong maximum distance given!") ;
+        return NULL ;
+    }
+
+    if ( slit_edges == NULL )
+    {
+        sinfo_msg_error("sorry, array slit_edges is empty!") ;
+        return NULL ;
+    }
+
+    /* determine the number of slitlets */
+    n_slitlets = N_SLITLETS ;
+
+    /* copy the original image in the image that will be returned */
+    returnImage = cpl_image_duplicate( im ) ;
+    podata=cpl_image_get_data_float(returnImage);
+
+    /* go through the rows and columns of the image and search for
+      the bad pixels */
+    for ( row = 0 ; row < ily ; row++ )
+    {
+        for ( col = 0 ; col < ilx ; col++ )
+        {
+            n = 0 ;
+            if ( isnan(pmdata[col + row*mlx]) ||
+                 pmdata[col + row*mlx] == 0. ||
+                 isnan(pidata[col + row*mlx]) )
+            {
+                /* look for the slitlet where the bad pixel is found */
+                slitlet = -1000 ;
+                for ( k = 0 ; k < n_slitlets ; k++ )
+                {
+                    if ( sinfo_new_nint(slit_edges[k][0]) <= col &&
+                         sinfo_new_nint(slit_edges[k][1]) >= col )
+                    {
+                        slitlet = k ;
+                    }
+/* The following else statement is wrong, because in the
+     end slitlet will always be -1000
+            else
+                    {
+                        slitlet = -1000 ;
+                    }
+*/
+                }
+                for ( i = 0 ; i < 6 ; i++ )
+                {
+                    validpixel[i] = 0. ;
+                }
+                /* look for the valid nearest neighbors
+                   and collect them but only a maximum of 4 */
+                for ( i = 1 ; i <= max_rad ; i++ )
+                {
+                    if ( row + i < ily)
+                    {
+                        if ( !isnan(pmdata[col + (row+i) * mlx])
+                             && pmdata[col + (row+i) * mlx] != 0. &&
+                                !isnan(pidata[col + (row+i) * ilx]) )
+                        {
+                            validpixel[n] = pidata[col + (row+i) * ilx] ;
+                            n++ ;
+                        }
+                    }
+                    if ( row - i >= 0 )
+                    {
+                        if ( !isnan(pmdata[col + (row-i) * mlx])
+                             && pmdata[col + (row-i) * mlx] != 0. &&
+                                !isnan(pidata[col + (row-i) * ilx]) )
+                        {
+                            validpixel[n] = pidata[col + (row-i) * ilx] ;
+                            n++ ;
+                        }
+                    }
+
+                    /* be aware of the slitlet edges in the
+                       spatial direction */
+                    if ( col + i < ilx )
+                    {
+                      if (  slitlet != -1000 )
+                      {
+                         if (col+i <= sinfo_new_nint(slit_edges[slitlet][1]) &&
+                             !isnan(pmdata[col + i + row * mlx]) &&
+                             pmdata[col + i + row * mlx] != 0. &&
+                             !isnan(pidata[col + i + row * ilx]) )
+                         {
+                             validpixel[n] = pidata[col + i + row * ilx] ;
+                             n++ ;
+                         }
+                      }
+                    }
+                    if ( col - i >= 0 )
+                    {
+                      if ( slitlet != -1000 )
+                      {
+                         if (col-i >= sinfo_new_nint(slit_edges[slitlet][0]) &&
+                             !isnan(pmdata[col - i + row * mlx]) &&
+                             pmdata[col - i + row * mlx] != 0. &&
+                             !isnan(pidata[col - i + row * ilx]) )
+                         {
+                             validpixel[n] = pidata[col - i + row * ilx] ;
+                             n++ ;
+                         }
+                      }
+                    }
+
+                    if ( i == 1 && n > 1 )
+                    {
+                        break ;
+                    }
+                    if ( n > 2 )
+                    {
+                        break ;
+                    }
+                }
+
+                if ( n == 0 )
+                {
+                    podata[col + row*ilx] = ZERO ;
+            /*sinfo_msg_warning("sinfo_interpolSourceImage:",
+                                        "bad pixel in column: %d and row: %d"
+                                        " could not be interpolated!",col,row);
+                             */
+                }
+                else
+                {
+                    /* now compute the mean and replace
+                       the bad pixel value by the mean */
+                    sum = 0. ;
+                    for ( i = 0 ; i < n ; i++ )
+                    {
+                        sum += validpixel[i] ;
+                    }
+                    podata[col + row*ilx] = sum/n ;
+                }
+            }
+        }
+    }
+
+    return returnImage ;
+}
+
+/**
+ at brief stack a given image row to build a whole image
+ at name sinfo_new_stack_row_to_image()
+ at param row: one image row as sinfo_vector data structure
+ at param ly:  image length
+ at return  resulting image
+
+ */
+
+cpl_image * sinfo_new_stack_row_to_image ( Vector * row, int ly )
+{
+    cpl_image * image=NULL;
+    int        col=0;
+    int        ro=0;
+    float* podata=NULL;
+
+    if ( row == NullVector )
+    {
+        sinfo_msg_error ("Null sinfo_vector as input" ) ;
+        return NULL ;
+    }
+    if ( ly <= 1 )
+    {
+        sinfo_msg_error ("wrong image length given" ) ;
+        return NULL ;
+    }
+
+    /* allocate memory */
+    if (NULL == (image = cpl_image_new(row->n_elements ,ly,CPL_TYPE_FLOAT )) )
+    {
+        sinfo_msg_error ("cannot allocate new image" ) ;
+        return NULL ;
+    }
+    podata=cpl_image_get_data_float(image);
+
+    for ( col = 0 ; col < row -> n_elements ; col++ )
+    {
+        for ( ro = 0 ; ro < ly ; ro++ )
+        {
+            podata[col + ro*ly] = row -> data[col] ;
+        }
+    }
+    return image ;
+}
+
+/**
+ at brief computes the mean and standard deviation of a given
+       rectangle on an image by leaving the extreme intensity values.
+   @name  sinfo_new_image_stats_on_rectangle()
+   @param im: flatfield image to search for bad pix
+   @param loReject,
+   @param hiReject: percentage (0...100) of extrem values
+                                            that should not be considered
+   @param llx,
+   @param lly: lower left pixel position of rectangle
+   @param urx,
+   @param ury: upper right pixel position of rectangle
+   @return data structure giving the mean and standard deviation
+ */
+
+Stats * sinfo_new_image_stats_on_rectangle ( cpl_image * im,
+                                float      loReject,
+                                float      hiReject,
+                                int        llx,
+                                int        lly,
+                                int        urx,
+                                int        ury )
+{
+    Stats * retstats=NULL;
+    int i=0 ;
+    int row=0;
+    int col=0;
+    int n=0;
+    int npix=0;
+    int lo_n=0;
+    int hi_n=0;
+    double pix_sum=0;
+    double sqr_sum=0;
+    float * pix_array=NULL;
+    int im_lx=0;
+    int im_ly=0;
+    float* pim=NULL;
+
+    if ( NULL == im )
+    {
+        sinfo_msg_error("sorry, no input image given!") ;
+        return NULL ;
+    }
+    if ( loReject+hiReject >= 100. )
+    {
+        sinfo_msg_error("sorry, too much pixels rejected!") ;
+        return NULL ;
+    }
+    if ( loReject < 0. || loReject >= 100. ||
+         hiReject < 0. || hiReject >= 100. )
+    {
+        sinfo_msg_error("sorry, negative reject values!") ;
+        return NULL ;
+    }
+
+    im_lx=cpl_image_get_size_x(im);
+    im_ly=cpl_image_get_size_y(im);
+
+    if ( llx < 0 || lly < 0 || urx < 0 || ury < 0 ||
+         llx >= im_lx || lly >= im_ly || urx >= im_lx ||
+         ury >= im_ly || ury <= lly || urx <= llx )
+    {
+        sinfo_msg_error("sorry, wrong pixel coordinates of rectangle!") ;
+        return NULL ;
+    }
+
+     /* allocate memory */
+    retstats = (Stats*) cpl_calloc(1, sizeof(Stats)) ;
+    npix = (urx - llx + 1) * (ury - lly + 1) ;
+    pix_array = (float*) cpl_calloc ( npix, sizeof(float) ) ;
+
+    /*-------------------------------------------------------------------------
+     * go through the rectangle and copy the pixel values into an array.
+     */
+    n = 0 ;
+    pim = cpl_image_get_data_float(im);
+    for ( row = lly ; row <= ury ; row++ )
+    {
+        for ( col = llx ; col <= urx ; col++ )
+        {
+            if ( !isnan(pim[col + row*im_lx]) )
+            {
+                pix_array[n] = pim[col + row*im_lx] ;
+                n++ ;
+            }
+    }
+    }
+
+    npix = n;
+    /*if (n != npix)
+    {
+        sinfo_msg_error("the computed number of pixel equals "
+                        "not the counted number, impossible!") ;
+        cpl_free(retstats) ;
+        cpl_free(pix_array) ;
+        return NULL ;
+    }*/
+
+    /* determining the clean mean is already done in the recipes */
+    if ( FLT_MAX == (retstats->cleanmean = sinfo_new_clean_mean(pix_array,
+                                           npix, loReject, hiReject)) )
+    {
+        sinfo_msg_error("sinfo_new_clean_mean() did not work!") ;
+        cpl_free(retstats) ;
+        cpl_free(pix_array) ;
+        return NULL ;
+    }
+
+    /* now the clean standard deviation must be calculated */
+    /* initialize sums */
+    lo_n = (int) (loReject / 100. * (float)npix) ;
+    hi_n = (int) (hiReject / 100. * (float)npix) ;
+    pix_sum = 0. ;
+    sqr_sum = 0. ;
+    n = 0 ;
+    for ( i = lo_n ; i <= npix - hi_n ; i++ )
+    {
+        pix_sum += (double)pix_array[i] ;
+        sqr_sum += ((double)pix_array[i] * (double)pix_array[i]) ;
+        n++ ;
+    }
+
+    if ( n == 0 )
+    {
+        sinfo_msg_error("number of clean pixels is zero!") ;
+        cpl_free(retstats) ;
+        cpl_free(pix_array) ;
+        return NULL ;
+    }
+    retstats -> npix = n ;
+    pix_sum /= (double) n ;
+    sqr_sum /= (double) n ;
+    retstats -> cleanstdev = (float)sqrt(sqr_sum - pix_sum * pix_sum) ;
+    cpl_free (pix_array) ;
+    return retstats ;
+}
+
+
+
+/**
+ at brief normalizes a raw flatfield image by dividing by the median of the
+       central spectral pixels to produce a master flatfield
+ at name     :       sinfo_new_normalize_to_central_pixel()
+ at param image: image to normalize
+ at return resulting image
+ */
+
+cpl_image * sinfo_new_normalize_to_central_pixel ( cpl_image * image )
+{
+    int col=0;
+    int row=0;
+    int i=0;
+    int n=0;
+    float* array=NULL ;
+    float divisor=0;
+    cpl_image * retImage=NULL;
+    int ilx=0;
+    int ily=0;
+    float* pidata=NULL;
+    float* podata=NULL;
+
+    if ( image == NULL )
+    {
+        sinfo_msg_error("no image given!") ;
+        return NULL ;
+    }
+    ilx=cpl_image_get_size_x(image);
+    ily=cpl_image_get_size_y(image);
+    pidata=cpl_image_get_data_float(image);
+
+    retImage = cpl_image_duplicate(image) ;
+    podata=cpl_image_get_data_float(retImage);
+
+    n = 0 ;
+    /* go through the central two image rows and store
+       the values in an array */
+    array=cpl_calloc(2*ilx,sizeof(float)) ;
+
+    for ( row = ily/2 ; row < ily/2+1 ; row++ )
+    {
+        for ( col = 0 ; col < ilx ; col++ )
+        {
+            if ( !isnan(pidata[col+ilx*row]) )
+            {
+                array[n] = pidata[col+ilx*row] ;
+                n++ ;
+            }
+        }
+    }
+    /* compute the sinfo_median of the central 2 spectral
+       values of all spatial pixels*/
+    if ( isnan(divisor = sinfo_new_median(array, n) ) )
+    {
+        sinfo_msg_error("no sinfo_median possible!") ;
+        return NULL ;
+    }
+    if ( 0 == divisor )
+    {
+        sinfo_msg_error("cannot divide by 0") ;
+        return NULL ;
+    }
+
+    for ( i = 0 ; i < (int) ilx*ily ; i++ )
+    {
+        if ( isnan(pidata[i]) )
+        {
+            podata[i] = ZERO ;
+        }
+        else
+        {
+            podata[i] = pidata[i]/divisor ;
+        }
+    }
+    cpl_free(array);
+    return retImage ;
+}
+
+/*-------------------------------------------------------------------------*/
+/**
+  @name         sinfo_new_mpe_shift_image
+  @memo         Shift an image by a given (non-integer) 2d offset.
+  @param        image_in                Image to shift.
+  @param        shift_x                 Shift in x.
+  @param        shift_y                 Shift in y.
+  @param        interp_kernel   Interpolation kernel to use.
+  @return       1 newly allocated image.
+  @see          sinfo_generate_interpolation_kernel
+  @doc
+
+  This function is a conversion to CPL of the ECLIPSE function shift_image()
+  but slightly changed. If a blank (ZERO) pixel appears the blank pixel
+  is shifted but preserved as blank.
+  If a blank (ZERO) pixel appears within the
+  interpolation kernel the blank pixel is set to 0.
+
+  This function shifts an image by a non-integer offset, using
+  interpolation. You can either generate an interpolation kernel once and
+  pass it to this function, or let it generate a default kernel. In the
+  former case, use sinfo_generate_interpolation_kernel() to generate an
+  appropriate kernel. In the latter case, pass NULL as last argument. A
+  default interpolation kernel is then generated then discarded before this
+  function returns.
+
+  The returned image is a newly allocated object, it must be deallocated
+  using cpl_image_delete().
+ */
+/*--------------------------------------------------------------------------*/
+
+cpl_image *
+sinfo_new_mpe_shift_image(
+    cpl_image    *    image_in,
+    double           shift_x,
+    double           shift_y,
+    double       *   interp_kernel)
+{
+    cpl_image    *       shifted=NULL ;
+    pixelvalue  *       first_pass=NULL ;
+    pixelvalue  *       second_pass=NULL ;
+    int             samples = KERNEL_SAMPLES ;
+    int          i=0, j=0 ;
+    double           fx=0, fy=0 ;
+    double           rx=0, ry=0 ;
+    int             px=0, py=0 ;
+    int             tabx=0, taby=0 ;
+    double           value=0 ;
+    size_t          pos ;
+    register pixelvalue     *   pix ;
+    register pixelvalue     *   pixint ;
+    int             mid=0;
+    double          norm=0 ;
+    double       *      ker=NULL ;
+    int                         freeKernel = 1 ;
+
+    int ilx=0;
+    int ily=0;
+    float* pidata=NULL;
+    float* psdata=NULL;
+
+
+    /* error handling: test entries */
+    if (image_in==NULL) return NULL ;
+
+    /* Shifting by a zero offset returns a copy of the input image */
+    if ((fabs(shift_x)<1e-2) && (fabs(shift_y)<1e-2))
+      return cpl_image_duplicate(image_in) ;
+    ilx=cpl_image_get_size_x(image_in);
+    ily=cpl_image_get_size_y(image_in);
+    pidata=cpl_image_get_data_float(image_in);
+
+
+        /* See if a kernel needs to be generated */
+    if (interp_kernel == NULL) {
+        ker = sinfo_generate_interpolation_kernel("default") ;
+        if (ker == NULL) {
+            sinfo_msg_error("kernel generation failure:aborting resampling") ;
+            return NULL ;
+        }
+    } else {
+        ker = interp_kernel ;
+        freeKernel = 0 ;
+    }
+
+    mid = (int)samples/(int)2 ;
+    first_pass = cpl_calloc(ilx, ily*sizeof(pixelvalue)) ;
+    shifted = cpl_image_new(ilx, ily,CPL_TYPE_FLOAT) ;
+    psdata=cpl_image_get_data_float(shifted);
+
+    second_pass = psdata ;
+
+    pix = pidata ;
+    if ( ilx != 1 )
+    {
+    for (j=0 ; j<ily ; j++)
+        {
+         for (i=0 ; i<ilx ; i++) {
+           fx = (double)i-shift_x ;
+           px = (int)fx ;
+           rx = fx - (double)px ;
+           pos = px + j * ilx ;
+
+           if ((px>1) && (px<(ilx-2)))
+           {
+           tabx = (int)(fabs((double)mid * rx)) ;
+           /* exclude blank (ZERO) pixels from interpolation */
+           if (isnan(pix[pos]))
+               {
+               value = ZERO ;
+               }
+           else
+               {
+               if (isnan(pix[pos-1]))
+               {
+               pix[pos-1] = 0. ;
+               }
+               if (isnan(pix[pos+1]))
+               {
+               pix[pos+1] = 0. ;
+               }
+               if (isnan(pix[pos+2]))
+               {
+               pix[pos+2] = 0. ;
+               }
+
+               /*
+            * Sum up over 4 closest pixel values,
+            * weighted by interpolation kernel values
+            */
+               value =     (double)pix[pos-1] * ker[mid+tabx] +
+               (double)pix[pos] * ker[tabx] +
+               (double)pix[pos+1] * ker[mid-tabx] +
+               (double)pix[pos+2] * ker[samples-tabx-1] ;
+               /*
+            * Also sum up interpolation kernel coefficients
+            * for further normalization
+            */
+               norm =      (double)ker[mid+tabx] +
+               (double)ker[tabx] +
+               (double)ker[mid-tabx] +
+               (double)ker[samples-tabx-1] ;
+               if (fabs(norm) > 1e-4) {
+               value /= norm ;
+               }
+               }
+           } else {
+           value = ZERO ;
+           }
+           /*
+        * There may be a problem of rounding here if pixelvalue
+        * has not enough bits to sustain the accuracy.
+        */
+           if ( isnan(value) )
+           {
+           first_pass[i+j*ilx] = ZERO ;
+           }
+           else
+           {
+           first_pass[i+j*ilx] = (pixelvalue)value ;
+           }
+         }
+        }
+    }
+    else
+    {
+    memcpy(first_pass,pix,ily*sizeof(pixelvalue));
+    }
+
+    pixint = first_pass ;
+    for (i=0 ; i<ilx ; i++) {
+        for (j=0 ; j<ily ; j++) {
+            fy = (double)j - shift_y ;
+            py = (int)fy ;
+            ry = fy - (double)py ;
+            pos = i + py * ilx ;
+
+            taby = (int)(fabs((double)mid * ry)) ;
+
+            if ((py>(int)1) && (py<(ily-2))) {
+                /* exclude blank (ZERO) pixels from interpolation */
+                if (isnan(pixint[pos]) && ilx != 1 )
+                {
+                    value = ZERO ;
+                }
+                else
+                {
+                    if (isnan(pixint[pos-ilx]))
+                    {
+                        pixint[pos-ilx] = 0. ;
+                    }
+                    if (isnan(pixint[pos+ilx]))
+                    {
+                        pixint[pos+ilx] = 0. ;
+                    }
+                    if (isnan(pixint[pos+2*ilx]))
+                    {
+                        pixint[pos+2*ilx] = 0. ;
+                    }
+                    /*
+                     * Sum up over 4 closest pixel values,
+                     * weighted by interpolation kernel values
+                     */
+                    value = (double)pixint[pos-ilx] * ker[mid+taby] +
+                            (double)pixint[pos] * ker[taby] +
+                            (double)pixint[pos+ilx] * ker[mid-taby] +
+                            (double)pixint[pos+2*ilx]*ker[samples-taby-1];
+                    /*
+                     * Also sum up interpolation kernel coefficients
+                     * for further normalization
+                     */
+                    norm =      (double)ker[mid+taby] +
+                                (double)ker[taby] +
+                                (double)ker[mid-taby] +
+                                (double)ker[samples-taby-1] ;
+
+                    if (fabs(norm) > 1e-4) {
+                        value /= norm ;
+                    }
+                }
+            } else {
+                value = ZERO ;
+            }
+            if (isnan(value))
+            {
+                second_pass[i+j*ilx] = ZERO ;
+            }
+            else
+            {
+                second_pass[i+j*ilx] = (pixelvalue)value ;
+            }
+        }
+    }
+
+    cpl_free(first_pass) ;
+    if (freeKernel)
+        cpl_free(ker) ;
+    return shifted ;
+}
+
+
+/*-------------------------------------------------------------------------*/
+/**
+  @name         sinfo_new_shift_image_in_cube
+  @memo         Shift a cube plane by a given (non-integer) 2d offset.
+  @param        image_in                Image to shift.
+  @param        shift_x                 Shift in x.
+  @param        shift_y                 Shift in y.
+  @param        interp_kernel           Interpolation kernel to use.
+  @param        shifted                 final shifted image
+  @param        first_pass              temporary data
+  @return       void, shifted image is in shifted
+  @see          sinfo_generate_interpolation_kernel
+  @doc
+
+  This function is a conversion to CPL of the ECLIPSE function shift_image()
+  but slightly changed. If a blank (ZERO) pixel appears the blank pixel
+  is shifted but preserved as blank.
+  If a blank (ZERO) pixel appears within the
+  interpolation kernel the blank pixel is set to 0.
+
+  This function shifts an image by a non-integer offset, using
+  interpolation. You can either generate an interpolation kernel once and
+  pass it to this function, or let it generate a default kernel. In the
+  former case, use sinfo_generate_interpolation_kernel() to generate an
+  appropriate kernel. In the latter case, pass NULL as last argument. A
+  default interpolation kernel is then generated then discarded before this
+  function returns.
+
+  The returned image is a newly allocated object, it must be deallocated
+  using sinfo_image_delete().
+ */
+/*--------------------------------------------------------------------------*/
+
+void
+sinfo_new_shift_image_in_cube(
+    cpl_image     *   image_in,
+    double           shift_x,
+    double           shift_y,
+    double       *   interp_kernel,
+    cpl_image     *   shifted,
+    pixelvalue   *   first_pass)
+{
+    pixelvalue  *       second_pass=NULL ;
+    int             samples = KERNEL_SAMPLES ;
+    int          i=0, j=0 ;
+    double           fx=0, fy=0 ;
+    double           rx=0, ry=0 ;
+    int             px=0, py=0 ;
+    int             tabx=0, taby=0 ;
+    double           value=0 ;
+    size_t          pos ;
+    register pixelvalue     *   pix ;
+    register pixelvalue     *   pixint ;
+    int             mid=0;
+    double          norm=0 ;
+    double       *      ker=NULL ;
+    int                         freeKernel = 1 ;
+
+    int ilx=0;
+    int ily=0;
+    int slx=0;
+    int sly=0;
+    float* pidata=NULL;
+    float* psdata=NULL;
+
+    /* error handling: test entries */
+        if (image_in==NULL) shifted = NULL ;
+        pidata=cpl_image_get_data_float(image_in);
+        ilx=cpl_image_get_size_x(image_in);
+        ily=cpl_image_get_size_y(image_in);
+
+        shifted=cpl_image_new(ilx,ily,CPL_TYPE_FLOAT);
+        slx=ilx;
+        sly=ily;
+
+        psdata=cpl_image_get_data_float(shifted);
+
+        /* Shifting by a zero offset returns a copy of the input image */
+        if ((fabs(shift_x)<1e-2) && (fabs(shift_y)<1e-2))
+                memcpy(psdata,pidata, (size_t) slx*sly * sizeof(pixelvalue)) ;
+
+        /* See if a kernel needs to be generated */
+    if (interp_kernel == NULL) {
+        ker = sinfo_generate_interpolation_kernel("default") ;
+        if (ker == NULL) {
+            sinfo_msg_error("kernel generation failure:aborting resampling") ;
+            shifted = NULL ;
+        }
+    } else {
+        ker = interp_kernel ;
+        freeKernel = 0 ;
+    }
+
+    mid = (int)samples/(int)2 ;
+    second_pass = psdata ;
+
+    pix = pidata ;
+    for (j=0 ; j<ily ; j++) {
+        for (i=1 ; i<ilx-2 ; i++) {
+            fx = (double)i-shift_x ;
+            px = (int)fx ;
+            rx = fx - (double)px ;
+
+            pos = px + j * ilx ;
+
+            if ((px>1) && (px<(ilx-2))) {
+                tabx = (int)(fabs((double)mid * rx)) ;
+                /* exclude blank (ZERO) pixels from interpolation */
+                if (isnan(pix[pos]))
+                {
+                    value = ZERO ;
+                }
+                else
+                {
+                    if (isnan(pix[pos-1]))
+                    {
+                        pix[pos-1] = 0. ;
+                    }
+                    if (isnan(pix[pos+1]))
+                    {
+                        pix[pos+1] = 0. ;
+                    }
+                    if (isnan(pix[pos+2]))
+                    {
+                        pix[pos+2] = 0. ;
+                    }
+
+                    /*
+                     * Sum up over 4 closest pixel values,
+                     * weighted by interpolation kernel values
+                     */
+                    value =     (double)pix[pos-1] * ker[mid+tabx] +
+                                (double)pix[pos] * ker[tabx] +
+                                (double)pix[pos+1] * ker[mid-tabx] +
+                                (double)pix[pos+2] * ker[samples-tabx-1] ;
+                    /*
+                     * Also sum up interpolation kernel coefficients
+                     * for further normalization
+                     */
+                    norm =      (double)ker[mid+tabx] +
+                                (double)ker[tabx] +
+                                (double)ker[mid-tabx] +
+                                (double)ker[samples-tabx-1] ;
+                    if (fabs(norm) > 1e-4) {
+                        value /= norm ;
+                    }
+                }
+            } else {
+                value = 0.0 ;
+            }
+            /*
+             * There may be a problem of rounding here if pixelvalue
+             * has not enough bits to sustain the accuracy.
+             */
+            if ( isnan(value) )
+            {
+                first_pass[i+j*ilx] = ZERO ;
+            }
+            else
+            {
+                first_pass[i+j*ilx] = (pixelvalue)value ;
+            }
+        }
+    }
+    pixint = first_pass ;
+    for (i=0 ; i< ilx ; i++) {
+        for (j=1 ; j< ily-2 ; j++) {
+            fy = (double)j - shift_y ;
+            py = (int)fy ;
+            ry = fy - (double)py ;
+            pos = i + py * ilx ;
+
+            taby = (int)(fabs((double)mid * ry)) ;
+
+            if ((py>(int)1) && (py<(ily-2))) {
+                /* exclude blank (ZERO) pixels from interpolation */
+                if (isnan(pixint[pos]))
+                {
+                    value = ZERO ;
+                }
+                else
+                {
+                    if (isnan(pixint[pos-ilx]))
+                    {
+                        pixint[pos-ilx] = 0. ;
+                    }
+                    if (isnan(pixint[pos+ilx]))
+                    {
+                        pixint[pos+ilx] = 0. ;
+                    }
+                    if (isnan(pixint[pos+2*ilx]))
+                    {
+                        pixint[pos+2*ilx] = 0. ;
+                    }
+                    /*
+                     * Sum up over 4 closest pixel values,
+                     * weighted by interpolation kernel values
+                     */
+                    value = (double)pixint[pos-ilx] * ker[mid+taby] +
+                            (double)pixint[pos] * ker[taby] +
+                            (double)pixint[pos+ilx] * ker[mid-taby] +
+                            (double)pixint[pos+2*ilx]*ker[samples-taby-1];
+                    /*
+                     * Also sum up interpolation kernel coefficients
+                     * for further normalization
+                     */
+                    norm =      (double)ker[mid+taby] +
+                                (double)ker[taby] +
+                                (double)ker[mid-taby] +
+                                (double)ker[samples-taby-1] ;
+
+                    if (fabs(norm) > 1e-4) {
+                        value /= norm ;
+                    }
+                }
+            } else {
+          /* value = 0.0 ; AMo: This affect slitlet #1 */
+            }
+            if (isnan(value))
+            {
+                second_pass[i+j*ilx] = ZERO ;
+            }
+            else
+            {
+                second_pass[i+j*ilx] = (pixelvalue)value ;
+            }
+        }
+    }
+
+    if (freeKernel)
+        cpl_free(ker) ;
+}
+
+/* function to delete the image statistics within python */
+void sinfo_new_del_Stats( Stats * st)
+{
+    cpl_free (st) ;
+}
+
+/**
+ at brief combines two bad pixel mask to one using an or relation
+   @param firstMask, secondMask: bad pixel masks to combine
+   @return resulting image
+ */
+
+cpl_image *
+sinfo_new_combine_masks ( cpl_image * firstMask, cpl_image * secondMask )
+{
+    cpl_image * retMask=NULL ;
+    int n=0 ;
+    int olx=0;
+    int oly=0;
+    float* podata=NULL;
+    float* pm1data=NULL;
+    float* pm2data=NULL;
+
+    if ( firstMask == NULL || secondMask == NULL )
+    {
+        sinfo_msg_error ("no input mask image given!") ;
+        return NULL ;
+    }
+    retMask = cpl_image_duplicate (firstMask) ;
+    podata = cpl_image_get_data_float(retMask);
+    pm1data = cpl_image_get_data_float(firstMask);
+    pm2data = cpl_image_get_data_float(secondMask);
+    olx=cpl_image_get_size_x(retMask);
+    oly=cpl_image_get_size_y(retMask);
+
+    for ( n = 0 ; n < (int) olx*oly ; n++ )
+    {
+       if ( podata[n] == 0. || pm2data[n] == 0. )
+       {
+           podata[n] = 0. ;
+       }
+       else
+       {
+           podata[n] = 1. ;
+       }
+    }
+    return retMask ;
+}
+
+/**
+ at brief slices a data cube in x or y direction
+   @param cube: input reduced data cube
+   @param x  x slice pixel value
+   @param y  y slice pixel value
+   @return resulting slice image
+*/
+
+cpl_image * sinfo_new_slice_cube (cpl_imagelist * cube, int x, int y )
+{
+    cpl_image * retImage=NULL ;
+    int col=0, row=0, z=0 ;
+    int inp=0;
+    int ilx=0;
+    int ily=0;
+    cpl_image* img=NULL;
+    float* podata=NULL;
+    float* pidata=NULL;
+
+    if ( cube == NULL )
+    {
+        sinfo_msg_error("no cube given!") ;
+        return NULL ;
+    }
+    if ( x > 31 || y > 31 )
+    {
+        sinfo_msg_warning("wrong x or y values!") ;
+    }
+
+    img=cpl_imagelist_get(cube,0);
+    ilx=cpl_image_get_size_x(img);
+    ily=cpl_image_get_size_y(img);
+    inp=cpl_imagelist_get_size(cube);
+    if ( x < 0 )
+    {
+        /* allocate memory */
+        if ( NULL == (retImage = cpl_image_new(ilx, inp, CPL_TYPE_FLOAT)) )
+        {
+            sinfo_msg_error("could not allocate memory!") ;
+            return NULL ;
+        }
+        podata=cpl_image_get_data_float(retImage);
+        for ( z = 0 ; z < inp ; z++ )
+        {
+
+            pidata=cpl_image_get_data_float(cpl_imagelist_get(cube,z));
+            for ( col = 0 ; col < ilx ; col++ )
+            {
+                podata[col+z*ilx] = pidata[col+y*ilx] ;
+            }
+        }
+    }
+    else if ( y < 0 )
+    {
+        /* allocate memory */
+        if ( NULL == (retImage = cpl_image_new(ily, inp,CPL_TYPE_FLOAT)) )
+        {
+            sinfo_msg_error("could not allocate memory!") ;
+            return NULL ;
+        }
+        podata=cpl_image_get_data_float(retImage);
+
+        for ( z = 0 ; z < inp ; z++ )
+        {
+            pidata=cpl_image_get_data_float(cpl_imagelist_get(cube,z));
+            for ( row = 0 ; row < ily ; row++ )
+            {
+                podata[row+z*ily] = pidata[x+row*ily] ;
+            }
+        }
+    }
+    else
+    {
+        sinfo_msg_error("wrong input!") ;
+        return NULL ;
+    }
+    return retImage ;
+}
+
+/**
+ at brief divides two images by considering blanks and calculating
+       first 1/im2 by cutting the very high values and setting to 1,
+       then multiplying im1 * 1/im2.
+
+
+   @param im1
+   @param im2 input images im1/im2
+   @return resulting divided image
+ */
+
+cpl_image * sinfo_new_div_images_robust ( cpl_image * im1, cpl_image * im2 )
+{
+    cpl_image * retIm=NULL ;
+    float help=0 ;
+    int i=0 ;
+    int lx1=0;
+    int ly1=0;
+    int lx2=0;
+    int ly2=0;
+
+    float* p1data=NULL;
+    float* p2data=NULL;
+    float* podata=NULL;
+
+    if ( im1 == NULL || im2 == NULL )
+    {
+        sinfo_msg_error("no input images given!") ;
+        return NULL ;
+    }
+    lx1=cpl_image_get_size_x(im1);
+    ly1=cpl_image_get_size_y(im1);
+    lx2=cpl_image_get_size_x(im2);
+    ly2=cpl_image_get_size_y(im2);
+    p1data=cpl_image_get_data_float(im1);
+    p2data=cpl_image_get_data_float(im2);
+
+    if ( lx1 != lx2 || ly1 != ly2 )
+    {
+        sinfo_msg_error("images not compatible!") ;
+        return NULL ;
+    }
+    if ( NULL == (retIm = cpl_image_new(lx1, ly1, CPL_TYPE_FLOAT)) )
+    {
+        sinfo_msg_error("could not allocate memory!") ;
+        return NULL ;
+    }
+    podata=cpl_image_get_data_float(retIm);
+
+    for ( i = 0 ; i < (int) lx2*ly2 ; i++ )
+    {
+        if ( !isnan(p2data[i]) )
+        {
+            help = 1./p2data[i] ;
+            if (fabs( help )> THRESH )
+            {
+               help = 1. ;
+            }
+        }
+        else
+        {
+            help = ZERO ;
+        }
+        if ( isnan(help) || isnan(p1data[i]) )
+        {
+            podata[i] = ZERO ;
+        }
+        else
+        {
+            podata[i] = p1data[i] * help ;
+        }
+    }
+    return retIm ;
+}
+
+cpl_image * sinfo_new_null_edges ( cpl_image * image)
+{
+    cpl_image * new=NULL ;
+    int i=0,j=0 ;
+    int ilx=0;
+    int ily=0;
+    int olx=0;
+    int oly=0;
+
+    float* pidata=NULL;
+    float* podata=NULL;
+
+    if ( image == NULL )
+    {
+        sinfo_msg_error ("no input image given!\n") ;
+        return NULL ;
+    }
+
+
+    new = cpl_image_duplicate (image) ;
+    ilx=cpl_image_get_size_x(image);
+    ily=cpl_image_get_size_y(image);
+    olx=cpl_image_get_size_x(new);
+    oly=cpl_image_get_size_y(new);
+    pidata=cpl_image_get_data_float(image);
+    podata=cpl_image_get_data_float(new);
+
+    for ( i = 0 ; i < olx ; i++ )
+    {
+        for ( j = 0 ; j < 4 ; j++)
+    {
+        podata[i+j*olx]=0;
+        podata[i+(oly-j-1)*olx]=0;
+    }
+    }
+    for ( i = 0 ; i < oly ; i++ )
+    {
+        for ( j = 0 ; j < 4 ; j++)
+    {
+        podata[j+i*olx]=0;
+        podata[(olx-j-1)+i*olx]=0;
+    }
+    }
+    return new ;
+}
+
+
+void sinfo_new_used_cor_map( cpl_image *im, cpl_image *map)
+{
+    int i=0,j=0,loc_index=0;
+    float temp_array[2048];
+    int lx=cpl_image_get_size_x(im);
+    int ly=cpl_image_get_size_y(im);
+    float* pidata=cpl_image_get_data_float(im);
+    float* pmdata=cpl_image_get_data_float(map);
+
+    for( j=0; j<ly; j++)
+    {
+    for( i=0;i<lx;i++)
+        {
+          loc_index = (int)pmdata[i+j*lx];
+           temp_array[i] = pidata[loc_index+j*lx];
+        }
+    for( i=0;i<lx;i++)
+        {
+          pidata[i+j*lx]= temp_array[i];
+        }
+    }
+}
+
+
+
+
+/*-------------------------------------------------------------------------*/
+/**
+  @name        sinfo_new_shift_image
+  @memo        Shift an image by a given (non-integer) 2d offset.
+  @param    image_in        Image to shift.
+  @param    shift_x            Shift in x.
+  @param    shift_y            Shift in y.
+  @param    interp_kernel    Interpolation kernel to use.
+  @return    1 newly allocated image.
+  @see        sinfo_generate_interpolation_kernel
+  @doc
+
+  This function shifts an image by a non-integer offset, using
+  interpolation. You can either generate an interpolation kernel once and
+  pass it to this function, or let it generate a default kernel. In the
+  former case, use sinfo_generate_interpolation_kernel() to generate an
+  appropriate kernel. In the latter case, pass NULL as last argument. A
+  default interpolation kernel is then generated then discarded before this
+  function returns.
+
+  The returned image is a newly allocated object, it must be deallocated
+  using sinfo_image_delete().
+ */
+/*--------------------------------------------------------------------------*/
+
+cpl_image *
+sinfo_new_shift_image(
+    cpl_image    *    image_in,
+    double           shift_x,
+    double           shift_y,
+    double       *    interp_kernel)
+{
+    cpl_image    *    shifted=NULL ;
+    float  *    first_pass=NULL ;
+    float  *    second_pass=NULL ;
+    int             samples = KERNEL_SAMPLES ;
+    int          i=0, j=0 ;
+    double           fx=0, fy=0 ;
+    double           rx=0, ry=0 ;
+    int             px=0, py=0 ;
+    int             tabx=0, taby=0 ;
+    double           value=0 ;
+    size_t          pos ;
+    register float     *    pix=NULL ;
+    register float     *    pixint=NULL ;
+    int             mid=0;
+    double          norm=0 ;
+    double       *    ker=NULL ;
+    int                freeKernel = 1 ;
+    int ilx=0;
+    int ily=0;
+
+    /* error handling: test entries */
+    if (image_in==NULL) return NULL ;
+
+    /* Shifting by a zero offset returns a copy of the input image */
+    if ((fabs(shift_x)<1e-2) && (fabs(shift_y)<1e-2))
+        return cpl_image_duplicate(image_in) ;
+
+    /* See if a kernel needs to be generated */
+    if (interp_kernel == NULL) {
+        ker = sinfo_generate_interpolation_kernel("default") ;
+        if (ker == NULL) {
+            sinfo_msg_error("kernel generation failure: aborting resampling") ;
+            return NULL ;
+        }
+    } else {
+        ker = interp_kernel ;
+        freeKernel = 0 ;
+    }
+
+    ilx=cpl_image_get_size_x(image_in);
+    ily=cpl_image_get_size_y(image_in);
+
+
+    pix = cpl_image_get_data_float(image_in);
+    if (pix)
+    {
+        mid = (int)samples/(int)2 ;
+        first_pass = cpl_calloc(ilx, ily*sizeof(float)) ;
+        shifted = cpl_image_new(ilx, ily,CPL_TYPE_FLOAT) ;
+        second_pass = cpl_image_get_data_float(shifted);
+		for (j=0 ; j<ily ; j++) {
+			for (i=1 ; i<ilx-2 ; i++) {
+				fx = (double)i-shift_x ;
+				px = (int)fx ;
+				rx = fx - (double)px ;
+
+				pos = px + j * ilx ;
+
+				if ((px>1) && (px<(ilx-3))) {
+					tabx = (int)(fabs((double)mid * rx)) ;
+					/*
+					 * Sum up over 4 closest pixel values,
+					 * weighted by interpolation kernel values
+					 */
+					value =     (double)pix[pos-1] * ker[mid+tabx] +
+								(double)pix[pos] * ker[tabx] +
+								(double)pix[pos+1] * ker[mid-tabx] +
+								(double)pix[pos+2] * ker[samples-tabx-1] ;
+					/*
+					 * Also sum up interpolation kernel coefficients
+					 * for further normalization
+					 */
+					norm =      (double)ker[mid+tabx] +
+								(double)ker[tabx] +
+								(double)ker[mid-tabx] +
+								(double)ker[samples-tabx-1] ;
+					if (fabs(norm) > 1e-4) {
+						value /= norm ;
+					}
+				} else {
+					value = 0.0 ;
+				}
+				/*
+				 * There may be a problem of rounding here if pixelvalue
+				 * has not enough bits to sustain the accuracy.
+				 */
+				first_pass[i+j*ilx] = (float)value ;
+			}
+		}
+		pixint = first_pass ;
+		for (i=0 ; i<ilx ; i++) {
+			for (j=1 ; j<ily-3 ; j++) {
+				fy = (double)j - shift_y ;
+				py = (int)fy ;
+				ry = fy - (double)py ;
+				pos = i + py * ilx ;
+
+				taby = (int)(fabs((double)mid * ry)) ;
+
+				if ((py>(int)1) && (py<(ily-2))) {
+					/*
+					 * Sum up over 4 closest pixel values,
+					 * weighted by interpolation kernel values
+					 */
+					value = (double)pixint[pos-ilx] * ker[mid+taby] +
+							(double)pixint[pos] * ker[taby] +
+							(double)pixint[pos+ilx] * ker[mid-taby] +
+							(double)pixint[pos+2*ilx]*ker[samples-taby-1];
+					/*
+					 * Also sum up interpolation kernel coefficients
+					 * for further normalization
+					 */
+					norm =      (double)ker[mid+taby] +
+								(double)ker[taby] +
+								(double)ker[mid-taby] +
+								(double)ker[samples-taby-1] ;
+
+					if (fabs(norm) > 1e-4) {
+						value /= norm ;
+					}
+				} else {
+					value = 0.0 ;
+				}
+				second_pass[i+j*ilx] = (float)value ;
+			}
+		}
+    }
+    else
+    {
+    	cpl_msg_warning(cpl_func, "cannot get a data from an image");
+    }
+    cpl_free(first_pass) ;
+    if (freeKernel)
+        cpl_free(ker) ;
+    return shifted ;
+}
+
+
+/*-------------------------------------------------------------------------*/
+/**
+  @name        sinfo_image_hermite_interpol
+  @memo        Smooth an image usinh Hermite splines.
+  @param       inp        Image to shift.
+  @return      1 newly allocated image.
+  @see         sinfo_spline_hermite
+  @doc
+
+  This function interpolate an image using hermite splines.
+
+  The returned image is a newly allocated object, it must be deallocated
+  using sinfo_image_delete().
+ */
+/*--------------------------------------------------------------------------*/
+
+cpl_image *
+sinfo_image_hermite_interpol(cpl_image * inp)
+{
+
+  /*
+   @param xp     x-value to interpolate
+   @param x      x-values
+   @param y      y-values
+   @param n      array length
+   @param istart    (input/output) initial row (set to 0 to search all row)
+
+  sinfo_spline_hermite( double xp, const double *x,
+                        const double *y, int n, int *istart );
+
+  */
+  float* pinp=NULL;
+  float* pout=NULL;
+  int sx=0;
+  int sy=0;
+  int i=0;
+  int j=0;
+  int r=5;
+  int k=0;
+
+  cpl_image* out=NULL;
+
+  cknull(inp,"Null in put image, exit");
+  check_nomsg(out=cpl_image_duplicate(inp));
+  check_nomsg(sx=cpl_image_get_size_x(inp));
+  check_nomsg(sy=cpl_image_get_size_y(inp));
+  check_nomsg(pinp=cpl_image_get_data_float(inp));
+  check_nomsg(pout=cpl_image_get_data_float(out));
+  for(j=r;j<sy-r;j++) {
+    for(i=0;i<sx;i++) {
+      for(k=-r;k<r;k++) {
+	pout[j*sx+i]+=pinp[(j+k)*sx+i];
+      }
+      pout[j*sx+i]/=2*r;
+    }
+  }
+
+ cleanup:
+
+  if(cpl_error_get_code() != CPL_ERROR_NONE) {
+    return NULL;
+  } else {
+    return out;
+
+  }
+
+}
+
+
+
+/*-------------------------------------------------------------------------*/
+/**
+  @name        sinfo_image_smooth_y
+  @memo        Smooth an image using a simple mean.
+  @param       inp        Image to shift.
+  @return      1 newly allocated image.
+  @see         sinfo_spline_hermite
+  @doc
+
+  This function interpolate an image using hermite splines.
+
+  The returned image is a newly allocated object, it must be deallocated
+  using sinfo_image_delete().
+ */
+/*--------------------------------------------------------------------------*/
+
+cpl_image *
+sinfo_image_smooth_y(cpl_image * inp, const int r)
+{
+
+  /*
+   @param xp     x-value to interpolate
+   @param x      x-values
+   @param y      y-values
+   @param n      array length
+   @param istart    (input/output) initial row (set to 0 to search all row)
+
+  */
+  float* pinp=NULL;
+  float* pout=NULL;
+  int sx=0;
+  int sy=0;
+  int i=0;
+  int j=0;
+  int k=0;
+
+  cpl_image* out=NULL;
+
+  cknull(inp,"Null in put image, exit");
+  check_nomsg(out=cpl_image_duplicate(inp));
+  check_nomsg(sx=cpl_image_get_size_x(inp));
+  check_nomsg(sy=cpl_image_get_size_y(inp));
+  check_nomsg(pinp=cpl_image_get_data_float(inp));
+  check_nomsg(pout=cpl_image_get_data_float(out));
+  for(j=r;j<sy-r;j++) {
+    for(i=0;i<sx;i++) {
+      for(k=-r;k<r;k++) {
+	pout[j*sx+i]+=pinp[(j+k)*sx+i];
+      }
+      pout[j*sx+i]/=2*r;
+    }
+  }
+
+ cleanup:
+
+  if(cpl_error_get_code() != CPL_ERROR_NONE) {
+    return NULL;
+  } else {
+    return out;
+
+  }
+
+}
+
+
+/*-------------------------------------------------------------------------*/
+/**
+  @name        sinfo_image_smooth_mean_y
+  @memo        Smooth an image using a simple mean.
+  @param       inp        Image to shift.
+  @return      1 newly allocated image.
+  @see         sinfo_spline_hermite
+  @doc
+
+  This function interpolate an image using hermite splines.
+
+  The returned image is a newly allocated object, it must be deallocated
+  using sinfo_image_delete().
+ */
+/*--------------------------------------------------------------------------*/
+
+cpl_image *
+sinfo_image_smooth_mean_y(cpl_image * inp, const int r)
+{
+
+  /*
+   @param xp     x-value to interpolate
+   @param x      x-values
+   @param y      y-values
+   @param n      array length
+   @param istart    (input/output) initial row (set to 0 to search all row)
+
+  */
+  float* pinp=NULL;
+  float* pout=NULL;
+  int sx=0;
+  int sy=0;
+  int i=0;
+  int j=0;
+  int k=0;
+
+  cpl_image* out=NULL;
+
+  cknull(inp,"Null in put image, exit");
+  check_nomsg(out=cpl_image_duplicate(inp));
+  check_nomsg(sx=cpl_image_get_size_x(inp));
+  check_nomsg(sy=cpl_image_get_size_y(inp));
+  check_nomsg(pinp=cpl_image_get_data_float(inp));
+  check_nomsg(pout=cpl_image_get_data_float(out));
+  for(j=r;j<sy-r;j++) {
+    for(i=0;i<sx;i++) {
+      for(k=-r;k<r;k++) {
+	pout[j*sx+i]+=pinp[(j+k)*sx+i];
+      }
+      pout[j*sx+i]/=2*r;
+    }
+  }
+
+ cleanup:
+
+  if(cpl_error_get_code() != CPL_ERROR_NONE) {
+    return NULL;
+  } else {
+    return out;
+
+  }
+
+}
+
+
+/*-------------------------------------------------------------------------*/
+/**
+  @name        sinfo_image_smooth_median_y
+  @memo        Smooth an image using a simple mean.
+  @param       inp        Image to shift.
+  @return      1 newly allocated image.
+  @see         sinfo_spline_hermite
+  @doc
+
+  This function interpolate an image using hermite splines.
+
+  The returned image is a newly allocated object, it must be deallocated
+  using sinfo_image_delete().
+ */
+/*--------------------------------------------------------------------------*/
+
+cpl_image *
+sinfo_image_smooth_median_y(cpl_image * inp, const int r)
+{
+
+  /*
+   @param xp     x-value to interpolate
+   @param x      x-values
+   @param y      y-values
+   @param n      array length
+   @param istart    (input/output) initial row (set to 0 to search all row)
+
+  */
+  float* pout=NULL;
+  int sx=0;
+  int sy=0;
+  int i=0;
+  int j=0;
+
+  cpl_image* out=NULL;
+
+
+  cknull(inp,"Null in put image, exit");
+  check_nomsg(out=cpl_image_duplicate(inp));
+  check_nomsg(sx=cpl_image_get_size_x(inp));
+  check_nomsg(sy=cpl_image_get_size_y(inp));
+  check_nomsg(pout=cpl_image_get_data_float(out));
+
+  for(j=r+1;j<sy-r;j++) {
+    for(i=1;i<sx;i++) {
+      pout[j*sx+i]=(float)cpl_image_get_median_window(inp,i,j,i,j+r);
+    }
+  }
+
+ cleanup:
+
+  if(cpl_error_get_code() != CPL_ERROR_NONE) {
+    return NULL;
+  } else {
+    return out;
+
+  }
+
+}
+
+/*-------------------------------------------------------------------------*/
+/**
+  @name        sinfo_image_smooth_fft
+  @memo        Smooth an image using a FFT.
+  @param       inp  Image to filter
+  @param       fy  Image to filter
+  @return      1 newly allocated image.
+  @doc
+  This function applies a lowpass spatial filter of frequency fy along Y.
+
+  The returned image is a newly allocated object, it must be deallocated
+  using sinfo_free_image().
+ */
+/*--------------------------------------------------------------------------*/
+
+cpl_image *
+sinfo_image_smooth_fft(cpl_image * inp, const int fy)
+{
+
+  int sx=0;
+  int sy=0;
+
+  cpl_image* out=NULL;
+  cpl_image* im_re=NULL;
+  cpl_image* im_im=NULL;
+  cpl_image* ifft_re=NULL;
+  cpl_image* ifft_im=NULL;
+  cpl_image* filter=NULL;
+
+  int sigma_x=0;
+  int sigma_y=fy;
+
+  cknull(inp,"Null in put image, exit");
+  check_nomsg(im_re = cpl_image_cast(inp, CPL_TYPE_DOUBLE));
+  check_nomsg(im_im = cpl_image_cast(inp, CPL_TYPE_DOUBLE));
+
+  // Compute FFT
+  check_nomsg(cpl_image_fft(im_re,im_im,CPL_FFT_DEFAULT));
+
+  check_nomsg(sx=cpl_image_get_size_x(inp));
+  check_nomsg(sy=cpl_image_get_size_y(inp));
+  sigma_x=sx;
+
+  //Generates filter image
+  check_nomsg(filter = sinfo_gen_lowpass(sx,sy,sigma_x,sigma_y));
+
+  //Apply filter
+  cpl_image_multiply(im_re,filter);
+  cpl_image_multiply(im_im,filter);
+
+  sinfo_free_image(&filter);
+
+  check_nomsg(ifft_re = cpl_image_duplicate(im_re));
+  check_nomsg(ifft_im = cpl_image_duplicate(im_im));
+
+  sinfo_free_image(&im_re);
+  sinfo_free_image(&im_im);
+
+  //Computes FFT-INVERSE
+  check_nomsg(cpl_image_fft(ifft_re,ifft_im,CPL_FFT_INVERSE));
+  check_nomsg(out = cpl_image_cast(ifft_re, CPL_TYPE_FLOAT));
+
+ cleanup:
+
+  sinfo_free_image(&ifft_re);
+  sinfo_free_image(&ifft_im);
+  sinfo_free_image(&filter);
+  sinfo_free_image(&im_re);
+  sinfo_free_image(&im_im);
+
+  if(cpl_error_get_code() != CPL_ERROR_NONE) {
+    return NULL;
+  } else {
+    return out;
+  }
+
+}
+
+
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief	Generate a low pass filter for FFT convolution .
+  @param	xs	x size of the generated image.
+  @param	ys	y size of the generated image.
+  @param	sigma_x	Sigma for the gaussian distribution.
+  @param	sigma_y      Sigma for the gaussian distribution.
+  @return	1 newly allocated image.
+
+  This function generates an image of a 2d gaussian, modified in such
+  a way that the different quadrants have a quadrants of the gaussian
+  in the corner. This image is suitable for FFT convolution.
+  Copied from eclipse, src/iproc/generate.c
+
+  The returned image must be deallocated.
+ */
+/*--------------------------------------------------------------------------*/
+static cpl_image *
+sinfo_gen_lowpass(const int xs,
+                  const int ys,
+                  const double sigma_x,
+                  const double sigma_y)
+{
+
+    int i= 0.0;
+    int j= 0.0;
+    int hlx= 0.0;
+    int hly = 0.0;
+    double x= 0.0;
+    double y= 0.0;
+    double gaussval= 0.0;
+    double inv_sigma_x=1./sigma_x;
+    double inv_sigma_y=1./sigma_y;
+
+    float *data;
+
+    cpl_image 	*lowpass_image=NULL;
+
+
+    lowpass_image = cpl_image_new (xs, ys, CPL_TYPE_FLOAT);
+    if (lowpass_image == NULL) {
+        sinfo_msg_error("Cannot generate lowpass filter <%s>",
+                        cpl_error_get_message());
+        return NULL;
+    }
+
+    hlx = xs/2;
+    hly = ys/2;
+
+    data = cpl_image_get_data_float(lowpass_image);
+
+/* Given an image with pixels 0<=i<N, 0<=j<M then the convolution image
+   has the following properties:
+
+   ima[0][0] = 1
+   ima[i][0] = ima[N-i][0] = exp (-0.5 * (i/sig_i)^2)   1<=i<N/2
+   ima[0][j] = ima[0][M-j] = exp (-0.5 * (j/sig_j)^2)   1<=j<M/2
+   ima[i][j] = ima[N-i][j] = ima[i][M-j] = ima[N-i][M-j]
+             = exp (-0.5 * ((i/sig_i)^2 + (j/sig_j)^2))
+*/
+
+    data[0] = 1.0;
+
+    /* first row */
+    for (i=1 ; i<=hlx ; i++) {
+        x = i * inv_sigma_x;
+        gaussval = exp(-0.5*x*x);
+        data[i] = gaussval;
+        data[xs-i] = gaussval;
+    }
+
+    for (j=1; j<=hly ; j++) {
+        y = j * inv_sigma_y;
+      /* first column */
+        data[j*xs] = exp(-0.5*y*y);
+        data[(ys-j)*xs] = exp(-0.5*y*y);
+
+        for (i=1 ; i<=hlx ; i++) {
+	/* Use internal symetries */
+            x = i * inv_sigma_x;
+            gaussval = exp (-0.5*(x*x+y*y));
+            data[j*xs+i] = gaussval;
+            data[(j+1)*xs-i] = gaussval;
+            data[(ys-j)*xs+i] = gaussval;
+            data[(ys+1-j)*xs-i] = gaussval;
+
+        }
+    }
+
+    /* FIXME: for the moment, reset errno which is coming from exp()
+            in first for-loop at i=348. This is causing cfitsio to
+            fail when loading an extension image (bug in cfitsio too).
+    */
+    if(errno != 0)
+        errno = 0;
+
+    return lowpass_image;
+}
+
+static void quicksort_int(int* data, int left, int right)
+{
+	int i = left;
+	int j = right;
+	int pivot = (i + j) / 2;
+	double index_value = data[pivot];
+	do
+	{
+		while(data[i] < index_value) i++;
+		while(data[j] > index_value) j--;
+		if (i <= j)
+		{
+			if(i < j)
+			{
+				int tmp = data[i];
+				data[i]=data[j];
+				data[j]=tmp;
+			}
+			i++;
+			j--;
+		}
+	} while (i <= j);
+
+	if (i < right)
+	{
+		quicksort_int(data, i, right);
+	}
+	if (left < j)
+	{
+		quicksort_int(data, left, j);
+	}
+}
+
+/*--------------------------------------------------------------------------*/
+/**@}*/
diff --git a/sinfoni/sinfo_image_ops.h b/sinfoni/sinfo_image_ops.h
new file mode 100644
index 0000000..a24f7f4
--- /dev/null
+++ b/sinfoni/sinfo_image_ops.h
@@ -0,0 +1,451 @@
+#ifndef SINFO_IMAGE_OPS_H
+#define SINFO_IMAGE_OPS_H
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*******************************************************************************
+* E.S.O. - VLT project
+*
+* "@(#) $Id: sinfo_image_ops.h,v 1.9 2008/03/25 08:20:43 amodigli Exp $"
+*
+* who       when      what
+* --------  --------  ----------------------------------------------
+* amodigli  04/01/06  created
+*/
+
+/************************************************************************
+ * sinfo_image_ops.h
+ * image arithmetic routines
+ *----------------------------------------------------------------------
+ */
+#include <cpl.h>
+
+#include "sinfo_spiffi_types.h" 
+#include "sinfo_spectrum_ops.h" 
+#include "sinfo_recipes.h"
+/*----------------------------------------------------------------------------
+ *                        Function ANSI C prototypes
+ *--------------------------------------------------------------------------*/
+
+
+
+cpl_image *
+sinfo_image_smooth_y(cpl_image * inp, const int r);
+
+cpl_error_code
+sinfo_image_line_corr(const int width,
+		      const int filt_rad,
+		      const int kappa,
+		      cpl_image* ima,
+		      cpl_image** ima_out);
+
+
+/**
+  @name     sinfo_new_shift_image
+  @memo     Shift an image by a given (non-integer) 2d offset.
+  @param    image_in        Image to shift.
+  @param    shift_x         Shift in x.
+  @param    shift_y         Shift in y.
+  @param    interp_kernel   Interpolation kernel to use.
+  @return   1 newly allocated image.
+  @see      sinfo_generate_interpolation_kernel
+  @doc This function shifts an image by a non-integer offset, using
+  interpolation. You can either generate an interpolation kernel once and
+  pass it to this function, or let it generate a default kernel. In the
+  former case, use sinfo_generate_interpolation_kernel() to generate an
+  appropriate kernel. In the latter case, pass NULL as last argument. A
+  default interpolation kernel is then generated then discarded before this
+  function returns.
+ 
+  The returned image is a newly allocated object, it must be deallocated
+  using cpl_image_delete().
+ */
+
+cpl_image *
+sinfo_new_shift_image(
+    cpl_image    *    image_in,
+    double           shift_x,
+    double           shift_y,
+    double       *    interp_kernel) ;
+/**
+   @name  sinfo_new_mean_of_columns()
+   @param im    input image
+   @result  resulting row array
+   @doc   takes the average of each image column
+*/
+Vector * 
+sinfo_new_mean_of_columns( cpl_image * im ) ;
+
+
+/**
+   @name       sinfo_new_clean_mean_of_columns()
+   @param      image, percentage of lowest and highest values to reject
+   @result     resulting row image
+   @doc        takes the average of each image column by sorting the
+               column values and rejecting the given percentage of
+               the highest and lowest values  [0...1]
+*/
+
+double 
+sinfo_new_my_median_image(cpl_image* im);
+
+
+cpl_image * 
+sinfo_new_clean_mean_of_columns( cpl_image * im,
+                               float lo_reject,
+                               float hi_reject) ;
+
+
+/**
+   @name  sinfo_new_div_image_by_row()
+   @memo      divides each image column by a row value
+   @param im      input image
+   @param row array
+   @result resulting image
+*/
+
+cpl_image * 
+sinfo_new_div_image_by_row( cpl_image * im, Vector * row ) ;
+
+/**
+   @name  sinfo_new_mult_row_to_image()
+   @param im image
+   @param row array
+   @doc     resulting image
+   @memo     multiplies each image column with a row value
+*/
+
+cpl_image * 
+sinfo_new_mult_row_to_image( cpl_image *im, Vector *row ) ;
+
+/**
+   @memo     sinfo_new_col_tilt()
+   @param    image input image 
+   @param    sigmaFactor image factor of sigma noise limit to determine 
+             pixels that are used for the fit.
+   @return      image
+   @doc      first calculates statistics for each column of an image.
+             median value and standard deviation of columns are de-
+             termined, blank values are excluded. Fits a straight 
+             line through the pixel values of each column and subtracts
+             the fit in order to remove the tilt of each column.
+             Only those pixels are used for the fit that are within 
+             a defined factor of sigma noise limit. The noise is 
+             calculated from pixels between the 10percentil and 
+             90percentil points. 
+   @note    works only for raw or averaged raw images
+*/
+
+cpl_image * 
+sinfo_new_col_tilt ( cpl_image * image, float sigmaFactor ) ;
+/**
+   @name     sinfo_new_median_image()
+   @param    image a median threshold parameter
+   @return   resulting image
+   @doc      median filter, calculates the sinfo_median for an image
+             by using the 8 closest pixels to each pixel.
+   The values in the output image are determined according
+   to the values of the input parameter. 
+   If fmedian = 0: always replace by median
+   if fmedian < 0: replace by sinfo_median if |pixel - sinfo_median| > -fmedian
+   if fmedian > 0: replace by sinfo_median if (fmedian as a factor of
+                   the square root of the sinfo_median itself
+   if |pixel - sinfo_median| >= fmedian * sqrt ( sinfo_median )
+   This can be used to consider photon noise.
+   This considers a dependence of the differences on the pixel values 
+   themselves.
+   @note  it is assumed that most of the 8 nearest neighbor pixels are not 
+          bad pixels! blank pixels are not replaced!
+*/
+
+cpl_image * 
+sinfo_new_median_image( cpl_image * im, float fmedian ) ;
+
+/**
+   @name    sinfo_new_compare_images()
+   @param   im1 original image
+   @param   im2 image to be compared 
+   @return  resulting image
+   @doc if a pixel value of one image (im1) equals the pixel value of the 
+        other image keep the pixel value of the original image otherwise 
+        replace it with ZEROs
+*/
+
+cpl_image * 
+sinfo_new_compare_images(cpl_image * im1, cpl_image * im2, cpl_image * origim);
+/**
+   @name   sinfo_threshImage()
+   @param  im image
+   @param  lo_cut low cut pixel value
+   @param  hi_cut high cut pixel value
+   @result resulting image
+   @doc    simple search for static bad pixels for a flat field or dark frame, 
+           values below and above the threshold values are set to BLANK.
+*/
+
+cpl_image * 
+sinfo_new_thresh_image ( cpl_image * im, float lo_cut, float hi_cut ) ;
+
+/**
+   @name sinfo_new_promote_image_to_mask()
+   @param  image with ZERO indicating bad pixels
+   @param  n_badpixels: number of bad pixels
+   @result resulting mask image that means 1 for good pixels
+           and ZEROS for bad pixel positions
+   @doc    changes an image with ZERO indicated bad pixels to
+           a bad pixel mask image, that means the returned
+           image has values 1 at positions of good pixels and
+           ZEROs at positions of bad pixels.
+*/
+cpl_image * 
+sinfo_new_promote_image_to_mask(cpl_image * im, int * n_badpixels ) ;
+/**
+   @name sinfo_new_mult_image_by_mask()
+   @param  im   input image
+   @param  mask mask image
+   @result resulting image that means the input image with marked
+           static bad pixels (ZERO values)
+   @doc    changes an image to an image that has ZERO indicated static bad 
+           pixels
+*/
+
+cpl_image * sinfo_new_mult_image_by_mask ( cpl_image * im, cpl_image * mask ) ;
+
+/**
+   @name  sinfo_new_interpol_image()
+   @param im   raw image
+   @param mask bad pixel mask
+   @param max_radius maximum x and y distance in pixels from the
+                     bad pixel within which valid pixels for
+                     interpolation are searched.
+   @param n_pixels   minimal number of pixels with which the bad
+                     pixel is interpolated if not enough
+                     valid nearest neighbors are found.
+   @result resulting interpolated image without any ZEROS
+   @doc    interpolates all bad pixels indicated by the bad pixel mask.
+           Therefore, the mean of at least 2 valid values of
+           the nearest 8 neighbors is taken. If too much neighbors are also 
+           bad pixels the neighbor radius is increased to a maximum of
+           max_radius until n_pixels valid pixels are found.
+           The valid neighbors are searched by going through the columns and 
+           rows around the central square that was already searched.
+           The bad pixel is interpolated by the mean of these valid pixels 
+           (less than 9) or by the sinfo_median of them (more than 8).
+*/
+
+cpl_image * 
+sinfo_new_interpol_image ( cpl_image * im,
+                           cpl_image * mask,
+                           int        max_radius,
+                           int        n_pixels ) ;
+
+/**
+   @name  sinfo_interpol_source_image()
+   @param im         source raw image
+   @param mask       bad pixel mask
+   @param max_rad    maximum pixel distance from the bad pixel to
+                     interpolate where valid pixel values are searched for.
+   @param slit_edges array of the edges of the slitlets.
+   @result resulting interpolated image hopefully without any ZEROS
+   @doc    interpolates all bad pixels indicated by the bad pixel mask.
+           Therefore, the mean of the nearest 4 neighbors is taken,
+           two in spectral direction and 2 in spatial direction.
+           The routine cares about the image and slitlet edges.
+           If there are no good pixel found within the nearest neighbors,
+           the next 4 nearest neighbors in spatial and spectral direction
+           are searched for valid pixels until a limit of max_rad.
+          A maximum of 4 valid pixels are used for interpolation by their mean.
+*/
+
+cpl_image * 
+sinfo_interpol_source_image ( cpl_image * im,
+                                 cpl_image * mask,
+                                 int        max_rad,
+                                 float   ** slit_edges ) ;
+
+/**
+   @name    sinfo_new_stack_row_to_image()
+   @memo   stack a given image row to build a whole image
+   @param   row one image row as sinfo_vector data structure
+   @param   ly  image length
+   @return  resulting image
+*/
+
+
+cpl_image * 
+sinfo_new_stack_row_to_image ( Vector * row, int ly ) ;
+
+
+/**
+   @name sinfo_new_image_stats_on_rectangle()
+   @param im: flatfield image to search for bad pix
+   @param loReject
+   @param hiReject: percentage (0...100) of extrem values that should not be 
+                    considered
+   @param llx
+   @param lly lower left pixel position of rectangle
+   @param urx
+   @param ury upper right pixel position of rectangle
+   @return data structure giving the mean and standard deviation
+   @doc  computes the mean and standard deviation of a given rectangle on an 
+         image by leaving the extreme intensity values.
+*/
+
+
+Stats * 
+sinfo_new_image_stats_on_rectangle ( cpl_image * im,
+                                float      loReject,
+                                float      hiReject,
+                                int        llx,
+                                int        lly,
+                                int        urx,
+                                int        ury ) ;
+
+/**
+   @name   sinfo_new_normalize_to_central_pixel()
+   @memo normalizes a raw flatfield image by dividing by the median of the 
+         central spectral pixels to produce a master flatfield
+   @param  image: image to normalize
+   @result resulting image
+ */
+
+
+cpl_image * 
+sinfo_new_normalize_to_central_pixel ( cpl_image * image ) ;
+
+/**
+  @name         sinfo_new_shift_image
+  @memo         Shift an image by a given (non-integer) 2d offset.
+  @param        image_in                Image to shift.
+  @param        shift_x                 Shift in x.
+  @param        shift_y                 Shift in y.
+  @param        interp_kernel   Interpolation kernel to use.
+  @return       1 newly allocated image.
+  @see          sinfo_generate_interpolation_kernel
+  @doc
+
+  This function is a conversion to CPL of the ECLIPSE function shift_image()
+  but slightly changed. If a blank (ZERO) pixel appears the blank pixel
+  is shifted but preserved as blank.
+  If a blank (ZERO) pixel appears within the
+  interpolation kernel the blank pixel is set to 0.
+
+  This function shifts an image by a non-integer offset, using
+  interpolation. You can either generate an interpolation kernel once and
+  pass it to this function, or let it generate a default kernel. In the
+  former case, use sinfo_generate_interpolation_kernel() to generate an
+  appropriate kernel. In the latter case, pass NULL as last argument. A
+  default interpolation kernel is then generated then discarded before this
+  function returns.
+
+  The returned image is a newly allocated object, it must be deallocated
+  using cpl_image_delete().
+ */
+
+
+cpl_image *
+sinfo_new_mpe_shift_image(
+    cpl_image    *    image_in,
+    double           shift_x,
+    double           shift_y,
+    double       *   interp_kernel) ;
+
+/**
+ at name sinfo_new_shift_image_in_cube
+ at param shift_x  image shift along X
+ at param shift_y  image shift along Y
+ at param interp_kernel interolation kernel
+ at param shifted resulting shifted image
+ at param firs_pass low pass band filter
+*/
+
+void
+sinfo_new_shift_image_in_cube(
+    cpl_image     *   image_in,
+    double           shift_x,
+    double           shift_y,
+    double       *   interp_kernel,
+    cpl_image     *   shifted,
+    pixelvalue   *   first_pass) ;
+
+
+void sinfo_new_del_Stats (Stats *) ;
+
+
+/**
+   @name   sinfo_new_combine_masks()
+   @memo    combines two bad pixel mask to one using an or relation
+   @param  firstMask bad pixel mask to combine
+   @param  secondMask bad pixel masks to combine
+   @result resulting image
+*/
+
+cpl_image * 
+sinfo_new_combine_masks ( cpl_image * firstMask, cpl_image * secondMask ) ;
+
+/**
+   @name    sinfo_new_slice_cube()
+   @memo   slices a data cube in x or y direction
+   @param   cube: input reduced data cube
+   @param   x x slice pixel value 
+   @param   y y slice pixel value
+   @result  resulting slice image
+*/
+
+
+cpl_image * 
+sinfo_new_slice_cube (cpl_imagelist * cube, int x, int y ) ;
+
+
+/**
+   @name  sinfo_new_div_images_robust()
+   @param im1 input image im1
+   @param im2 input image im2
+   @result resulting divided image
+   @doc divides two images by considering blanks and calculating first 1/im2 by
+        cutting the very high values and setting to 1,then multiplying 
+        im1 * 1/im2.
+*/
+
+cpl_image * 
+sinfo_new_div_images_robust ( cpl_image * im1, cpl_image * im2 ) ;
+
+
+
+cpl_image * 
+sinfo_new_null_edges ( cpl_image * image) ;
+
+
+
+void 
+sinfo_new_used_cor_map( cpl_image *im, cpl_image *map);
+
+
+cpl_image *
+sinfo_image_smooth_mean_y(cpl_image * inp,const int r);
+
+cpl_image *
+sinfo_image_smooth_median_y(cpl_image * inp,const int r);
+
+cpl_image *
+sinfo_image_hermite_interpol(cpl_image * inp);
+
+cpl_image *
+sinfo_image_smooth_fft(cpl_image * inp, const int r);
+
+#endif
diff --git a/sinfoni/sinfo_ipow.c b/sinfoni/sinfo_ipow.c
new file mode 100644
index 0000000..5603a3d
--- /dev/null
+++ b/sinfoni/sinfo_ipow.c
@@ -0,0 +1,89 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+/*
+ * This function is so generic and used everywhere, it diserves its
+ * own source file...
+ */
+/*
+ $Id: sinfo_ipow.c,v 1.4 2012/03/02 08:42:20 amodigli Exp $
+ $Author: amodigli $
+ $Date: 2012/03/02 08:42:20 $
+ $Revision: 1.4 $
+ */
+/**@{*/
+/**
+ * @addtogroup sinfo_utilities ipow
+ *
+ * TBD
+ */
+
+/**
+  @name        sinfo_ipow
+  @memo        Same as pow(x,y) but for integer values of y only (faster).
+  @param    x    A double number.
+  @param    p    An integer power.
+  @return    x to the power p.
+  @doc
+
+  This is much faster than the math function due to the integer. Some
+  compilers make this optimization already, some do not.
+
+  p can be positive, negative or null.
+ */
+
+#include "sinfo_ipow.h"
+double sinfo_ipow(double x, int p)
+{
+    double r, recip ;
+
+    /* Get rid of trivial cases */
+    switch (p) {
+        case 0:
+        return 1.00 ;
+
+        case 1:
+        return x ;
+
+        case 2:
+        return x*x ;
+
+        case 3:
+        return x*x*x ;
+
+        case -1:
+        return 1.00 / x ;
+
+        case -2:
+        return (1.00 / x) * (1.00 / x) ;
+    }
+    if (p>0) {
+        r = x ;
+        while (--p) r *= x ;
+    } else {
+        r = recip = 1.00 / x ;
+        while (++p) r *= recip ;
+    }
+    return r;
+}
+
+
+/**@}*/
diff --git a/sinfoni/sinfo_ipow.h b/sinfoni/sinfo_ipow.h
new file mode 100644
index 0000000..923630b
--- /dev/null
+++ b/sinfoni/sinfo_ipow.h
@@ -0,0 +1,56 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*---------------------------------------------------------------------------
+   
+   File name     :    sinfo_ipow.h
+   Author         :    N. Devillard
+   Created on    :    June 1999
+   Description    :    integer powers
+ *--------------------------------------------------------------------------*/
+
+/*
+ $Id: sinfo_ipow.h,v 1.3 2007/06/06 07:10:45 amodigli Exp $
+ $Author: amodigli $
+ $Date: 2007/06/06 07:10:45 $
+ $Revision: 1.3 $
+ */
+
+#ifndef SINFO_IPOW_H
+#define SINFO_IPOW_H
+/*---------------------------------------------------------------------------
+                               Function prototypes
+ ---------------------------------------------------------------------------*/
+/**
+  @name     sinfo_ipow
+  @memo     Same as pow(x,y) but for integer values of y only (faster).
+  @param    x   A double number.
+  @param    p   An integer power.
+  @return   x to the power p.
+  @doc
+ 
+  This is much faster than the math function due to the integer. Some
+  compilers make this optimization already, some do not.
+ 
+  p can be positive, negative or null.
+ */
+
+double 
+sinfo_ipow(double x, int p);
+
+#endif
diff --git a/sinfoni/sinfo_key_names.h b/sinfoni/sinfo_key_names.h
new file mode 100644
index 0000000..acb1487
--- /dev/null
+++ b/sinfoni/sinfo_key_names.h
@@ -0,0 +1,228 @@
+/* $Id: sinfo_key_names.h,v 1.1 2006/10/20 08:06:32 amodigli Exp $
+ *
+ * This file is part of the SINFONI Pipeline
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This proram is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2006/10/20 08:06:32 $
+ * $Revision: 1.1 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifndef SINFO_KEY_NAMES_H
+#define SINFO_KEY_NAMES_H
+
+
+
+CPL_BEGIN_DECLS
+#define KEY_NAME_CDELT1                     "CDELT1"
+#define KEY_NAME_CDELT2                     "CDELT2"
+#define KEY_NAME_CDELT3                     "CDELT3"
+
+#define KEY_NAME_CRPIX1                     "CRPIX1"
+#define KEY_NAME_CRPIX2                     "CRPIX2"
+#define KEY_NAME_CRPIX3                     "CRPIX3"
+
+#define KEY_NAME_CRVAL1                     "CRVAL1"
+#define KEY_NAME_CRVAL2                     "CRVAL2"
+#define KEY_NAME_CRVAL3                     "CRVAL3"
+
+#define KEY_NAME_LOOP_STATE                "ESO AOS RTC LOOP STATE"
+#define KEY_NAME_LOOP_LGS                  "ESO AOS RTC LOOP LGS"
+#define KEY_NAME_INS1_MODE                 "ESO INS1 MODE"
+
+#define PAF_NAME_LOOP_STATE                "AOS RTC LOOP STATE"
+#define PAF_NAME_LOOP_LGS                  "AOS RTC LOOP LGS"
+#define PAF_NAME_INS1_MODE                 "INS1 MODE"
+
+#define KEY_HELP_LOOP_STATE                "Loop state, open or closed"
+#define KEY_HELP_LOOP_LGS                  "LGS loop on or off"
+#define KEY_HELP_INS1_MODE                 "Instrument mode used."
+
+#define KEY_NAME_CUMOFFX                   "ESO SEQ CUMOFFSETX"
+#define KEY_NAME_CUMOFFY                   "ESO SEQ CUMOFFSETY"
+
+#define KEY_NAME_MJD_OBS                   "MJD-OBS"
+#define KEY_NAME_OBS_NAME                   "ESO OBS NAME"
+
+#define KEY_NAME_PRO_CATG                  "ESO PRO CATG"
+#define PAF_NAME_PRO_CATG                  "PRO CATG"
+#define KEY_HELP_PRO_CATG                  "Category of pipeline product frame"
+
+
+#define KEY_NAME_DET_DIT                   "ESO DET DIT"
+#define PAF_NAME_DET_DIT                   "DET DIT"
+#define KEY_HELP_DET_DIT                   "Integration Time"
+
+#define KEY_NAME_DET_NDIT                  "ESO DET NDIT"
+#define PAF_NAME_DET_NDIT                  "DET NDIT"
+#define KEY_HELP_DET_NDIT                  "# of Sub-Integrations"
+
+#define KEY_NAME_NCORRS_NAME               "ESO DET NCORRS NAME"
+#define PAF_NAME_NCORRS_NAME               "DET NCORRS NAME"
+#define KEY_HELP_NCORRS_NAME               "Read-Out Mode Name"
+
+#define KEY_NAME_DET_NDSAMPLES             "ESO DET NDSAMPLES"
+#define KEY_HELP_DET_NDSAMPLES             "# of Non-Dest. Samples"
+#define PAF_NAME_DET_NDSAMPLES             "DET NDSAMPLES"
+
+
+#define KEY_NAME_FILT_NAME                 "ESO INS FILT1 NAME"
+#define PAF_NAME_FILT_NAME                 "INS FILT1 NAME"
+#define KEY_HELP_FILT_NAME                 "Filter name."
+
+#define KEY_NAME_FILT_ID                   "ESO INS FILT1 ID"
+#define PAF_NAME_FILT_ID                   "INS FILT1 ID"
+#define KEY_HELP_FILT_ID                   "Filter unique id."
+
+#define KEY_NAME_GRAT_NAME                 "ESO INS GRAT1 NAME"
+#define PAF_NAME_GRAT_NAME                 "INS GRAT1 NAME"
+#define KEY_HELP_GRAT_NAME                 "Grating common name."
+
+#define KEY_NAME_INS_SETUP                 "ESO INS SETUP ID"
+#define PAF_NAME_INS_SETUP                 "INS SETUP ID"
+#define KEY_HELP_INS_SETUP                 "Instrument setup identifier."
+
+#define KEY_NAME_GRAT_WLEN                 "ESO INS GRAT1 WLEN"
+#define PAF_NAME_GRAT_WLEN                 "INS GRAT1 WLEN"
+#define KEY_HELP_GRAT_WLEN                 "Grating central wavelength [nm]."
+
+
+#define KEY_NAME_PRO_REC1_RAW1_NAME        "ESO PRO REC1 RAW1 NAME"
+
+#define KEY_NAME_LAMP_XE                   "ESO INS1 LAMP1 ST"
+#define KEY_NAME_LAMP_KR                   "ESO INS1 LAMP2 ST"
+#define KEY_NAME_LAMP_NE                   "ESO INS1 LAMP3 ST"
+#define KEY_NAME_LAMP_AR                   "ESO INS1 LAMP4 ST"
+#define KEY_NAME_LAMP_HALO                 "ESO INS1 LAMP5 ST"
+#define PAF_NAME_LAMP_HALO                 "INS1 LAMP5 ST"
+#define KEY_HELP_LAMP_HALO                 "Lamp activated."
+
+#define KEY_NAME_SHUT2_ST                  "ESO INS1 SHUT2 ST"
+#define PAF_NAME_SHUT2_ST                  "INS1 SHUT2 ST"
+#define KEY_HELP_SHUT2_ST                  "Shutter open."
+
+#define KEY_NAME_PREOPTICS                 "ESO INS OPTI1 NAME"
+#define PAF_NAME_PREOPTICS                 "INS OPTI1 NAME"
+#define KEY_HELP_PREOPTICS                 "OPTIi name."
+
+#define KEY_NAME_DPR_TYPE                  "ESO DPR TYPE"
+#define PAF_NAME_DPR_TYPE                  "DPR TYPE"
+#define KEY_HELP_DPR_TYPE                  "Observation type"
+
+#define KEY_NAME_DPR_CATG                  "ESO DPR CATG"
+#define PAF_NAME_DPR_CATG                  "DPR CATG"
+#define KEY_HELP_DPR_CATG                  "Observation category"
+
+#define KEY_NAME_DPR_TECH                  "ESO DPR TECH"
+#define PAF_NAME_DPR_TECH                  "DPR TECH"
+#define KEY_HELP_DPR_TECH                  "Observation technique"
+
+#define KEY_NAME_PIPE_ID                   "ESO PRO REC1 PIPE ID"
+#define PAF_NAME_PIPE_ID                   "PRO REC1 PIPE ID"
+#define KEY_HELP_PIPE_ID                   "Pipeline (unique) identifier"
+
+#define KEY_NAME_PIPEFILE                  "PIPEFILE"
+#define KEY_HELP_PIPEFILE                  "Filename of data product"
+
+#define KEY_NAME_PRO_TYPE                  "ESO PRO TYPE"
+#define PAF_NAME_PRO_TYPE                  "PRO TYPE"
+#define KEY_HELP_PRO_TYPE                  "Product Type"
+
+#define KEY_NAME_PRO_REDLEVEL              "ESO PRO REDLEVEL"
+
+#define KEY_NAME_PRO_CATG                  "ESO PRO CATG"
+#define PAF_NAME_PRO_CATG                  "PRO CATG"
+
+#define KEY_NAME_PRO_STATUS                "ESO PRO STATUS"
+
+#define KEY_NAME_PRO_DATE                  "ESO PRO DATE"
+
+#define KEY_NAME_DATE_OBS                  "DATE-OBS"
+#define KEY_HELP_DATE_OBS                  "Observing date"
+
+#define KEY_NAME_TEL_AIRM_START            "ESO TEL AIRM START"
+#define PAF_NAME_TEL_AIRM_START            "TEL AIRM START"
+#define KEY_HELP_TEL_AIRM_START            "Airmass at start"
+
+
+
+#define KEY_NAME_ARCFILE                   "ARCFILE"
+#define KEY_HELP_ARCFILE                   "Archive file name"
+
+
+#define KEY_NAME_TPL_ID                    "ESO TPL ID"
+#define PAF_NAME_TPL_ID                    "TPL ID"
+#define KEY_HELP_TPL_ID                    "Template sig"
+
+#define KEY_NAME_DATANCOM                  "DATANCOM"
+#define KEY_NAME_PRO_DATANCOM              "ESO PRO DATANCOM"
+#define PAF_NAME_PRO_DATANCOM              "PRO DATANCOM"
+#define KEY_HELP_PRO_DATANCOM              "Number of frames combined"
+
+#define KEY_NAME_PRO_RECID                "ESO PRO REC1 ID"
+#define PAF_NAME_PRO_RECID                "PRO REC1 ID"
+#define KEY_HELP_PRO_RECID                "Pipeline recipe (unique) identifier"
+
+#define KEY_NAME_PRO_DRSID                 "ESO PRO REC1 DRS ID"
+#define PAF_NAME_PRO_DRSID                 "PRO REC1 DRS ID"
+#define KEY_HELP_PRO_DRSID                 "Data Reduction System identifier"
+
+#define KEY_NAME_HPRO_TYPE                 "HIERARCH ESO PRO TYPE"
+#define KEY_HELP_HPRO_TYPE                "product type"
+
+#define KEY_NAME_HPRO_CATG                 "HIERARCH ESO PRO CATG"
+#define KEY_HELP_HPRO_CATG                 "product category"
+
+#define KEY_NAME_HPRO_STATUS               "HIERARCH ESO PRO STATUS"
+#define KEY_HELP_HPRO_STATUS               "pipeline status"
+
+#define KEY_NAME_HPRO_DATE                 "HIERARCH ESO PRO DATE"
+#define KEY_HELP_HPRO_DATE                 "pipeline execution date"
+
+
+#define KEY_NAME_HPRO_RECID                "HIERARCH ESO PRO REC ID"
+#define KEY_HELP_HPRO_RECID                "recipe ID"
+
+#define KEY_NAME_HPRO_DRSID                "HIERARCH ESO PRO DRS ID"
+#define KEY_HELP_HPRO_DRSID                "data reduction system ID"
+
+#define KEY_NAME_HPRO_DATANCOM             "HIERARCH ESO PRO DATANCOM"
+#define KEY_NAME_HPRO_DID                  "HIERARCH ESO PRO DID"
+#define KEY_VALUE_HPRO_DID                 "PRO-1.15"
+#define KEY_HELP_HPRO_DID                  "Data dictionary for PRO"
+
+
+#define KEY_NAME_HPRO_DOID                  "HIERARCH ESO PRO DO ID"
+#define KEY_VALUE_HPRO_DOID                 "DO-1_18"
+#define KEY_HELP_HPRO_DOID                  "Data Organizer identification ID"
+
+
+#define KEY_NAME_HPRO_RBSID                  "HIERARCH ESO PRO RBS ID"
+#define KEY_VALUE_HPRO_RBSID                 "RBS-1_11"
+#define KEY_HELP_HPRO_RBSID      "Reduction Block Scheduler identification ID"
+
+#define KEY_NAME_REC1_RAW1_NAME            "ESO PRO REC1 RAW1 NAME"
+
+#define KEY_NAME_GRAT_ENC                  "ESO INS GRAT1 ENC"
+
+
+CPL_END_DECLS
+
+#endif
diff --git a/sinfoni/sinfo_lamp_cfg.c b/sinfoni/sinfo_lamp_cfg.c
new file mode 100644
index 0000000..17c5cbc
--- /dev/null
+++ b/sinfoni/sinfo_lamp_cfg.c
@@ -0,0 +1,76 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*---------------------------------------------------------------------------
+   
+   File name     :sinfo_lamp_cfg.c
+   Author     :Juergen Schreiber
+   Created on    :March 2002
+   Description    :prepare halogen lamp spectrum frames configuration 
+                 handling tools
+ *--------------------------------------------------------------------------*/
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+/*---------------------------------------------------------------------------
+                                   Includes
+ ---------------------------------------------------------------------------*/
+#include "sinfo_lamp_cfg.h"
+/**@{*/
+/**
+ * @defgroup sinfo_lamp_cfg Flat frame manipulation functions
+ *
+ * TBD
+ */
+
+/*---------------------------------------------------------------------------
+                              Function codes
+ ---------------------------------------------------------------------------*/
+/**
+   @name    sinfo_lamp_cfg_create()
+   @memo    allocate memory for a lamp_cfg struct
+   @return  pointer to allocated base lamp_cfg structure
+   @note    only the main (base) structure is allocated
+ */
+lamp_config * 
+sinfo_lamp_cfg_create(void)
+{
+    return cpl_calloc(1, sizeof(lamp_config));
+}
+
+/**
+   @name    sinfo_lamp_cfg_destroy()
+   @memo    deallocate all memory associated with a lamp_config data structure
+   @param  sc lamp_config to deallocate
+   @return  void
+*/
+void 
+sinfo_lamp_cfg_destroy(lamp_config * sc)
+{
+    if (sc==NULL) return ;
+
+    /* Free main struct */
+    cpl_free(sc);
+
+    return ;
+}
+/**@}*/
+
+
+
diff --git a/sinfoni/sinfo_lamp_cfg.h b/sinfoni/sinfo_lamp_cfg.h
new file mode 100644
index 0000000..0f00393
--- /dev/null
+++ b/sinfoni/sinfo_lamp_cfg.h
@@ -0,0 +1,94 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*---------------------------------------------------------------------------
+   File name     :    sinfo_lamp_cfg.h
+   Author         :    Juergen Schreiber
+   Created on    :    March 2002
+   Description    :    lamp_ini definitions + handling prototypes
+ ---------------------------------------------------------------------------*/
+#ifndef SINFO_LAMP_CFG_H
+#define SINFO_LAMP_CFG_H
+/*---------------------------------------------------------------------------
+                                   Includes
+ ---------------------------------------------------------------------------*/
+#include <stdlib.h>
+#include <cpl.h>
+#include "sinfo_globals.h"
+/*---------------------------------------------------------------------------
+                                   Defines
+ ---------------------------------------------------------------------------*/
+/*---------------------------------------------------------------------------
+                                   New types
+ ---------------------------------------------------------------------------*/
+/*
+  prepare lamp spectrum blackboard container
+
+  This structure holds all information related to the halogen lamp 
+  spectrum handling
+  routine. It is used as a container for the flux of ancillary data,
+  computed values, and algorithm status. Pixel flux is separated from
+  the blackboard.
+  */
+
+typedef struct lamp_config {
+/*-------General---------*/
+        char inFrame[FILE_NAME_SZ] ; /* file name of the input halogen 
+                                        lamp frame */
+        char wavemapim[FILE_NAME_SZ] ; /* file name of the wavelength map */
+        char outName[FILE_NAME_SZ] ; /* output name of resulting fits frame */
+/*------ Resampling ------*/
+        /* number of coefficients for the polynomial interpolation 
+          (order + 1) */
+        int ncoeffs ;
+        /* number of rows in the resulting resampled image = 
+           number of spectral bins */
+        int nrows ;
+/*------ Extractspectrum ------*/
+        /* percentage of rejected low intensity pixels */
+        float loReject ;      
+        /* percentage of rejected high intensity pixels */
+        float hiReject ;
+        /* conversion factor of detector counts per intensity unit */
+        float countsToIntensity ;
+} lamp_config ;
+
+/*---------------------------------------------------------------------------
+                               Function prototypes
+ ---------------------------------------------------------------------------*/
+/**
+   @name    sinfo_lamp_cfg_create()
+   @memo    allocate memory for a lamp_cfg struct
+   @return  pointer to allocated base lamp_cfg structure
+   @note    only the main (base) structure is allocated
+ */
+
+lamp_config * 
+sinfo_lamp_cfg_create(void);
+
+/**
+   @name    sinfo_lamp_cfg_destroy()
+   @memo    deallocate all memory associated with a lamp_config data structure
+   @param  sc lamp_config to deallocate
+   @return  void
+*/
+
+void 
+sinfo_lamp_cfg_destroy(lamp_config * sc);
+
+#endif
diff --git a/sinfoni/sinfo_lamp_flats_config.c b/sinfoni/sinfo_lamp_flats_config.c
new file mode 100644
index 0000000..d4f0ef7
--- /dev/null
+++ b/sinfoni/sinfo_lamp_flats_config.c
@@ -0,0 +1,370 @@
+/* $Id: sinfo_lamp_flats_config.c,v 1.4 2012/03/02 08:42:20 amodigli Exp $
+ *
+ * This file is part of the CPL (Common Pipeline Library)
+ * Copyright (C) 2002 European Southern Observatory
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*
+ * $Author: amodigli $
+ * $Date: 2012/03/02 08:42:20 $
+ * $Revision: 1.4 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+ /****************************************************************
+  *   Lamp_Spec Frames Data Reduction Parameter Initialization        *
+  ****************************************************************/
+
+#include "sinfo_lamp_flats_config.h"
+/**@{*/
+/**
+ * @addtogroup sinfo_lamp_cfg Flat frame manipulation functions
+ *
+ * TBD
+ */
+
+void
+ sinfo_lamp_flats_config_add(cpl_parameterlist *list)
+{
+
+  cpl_parameter *p;
+
+  if (!list) {
+    return;
+  }
+
+  /*Reconstruction */
+ /* the fraction [0...1] of rejected low intensity pixels when taking 
+the average of columns */
+  p = cpl_parameter_new_range("sinfoni.lamp_flats.low_rejection",
+                  CPL_TYPE_DOUBLE,
+                              "lower rejection: "
+                              "percentage of rejected low intensity "
+                              "pixels before averaging",
+                              "sinfoni.lamp_flats",
+                              0.1,0.0,1.0);
+
+  cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,"lamp_flats-lo_rej");
+  cpl_parameterlist_append(list, p);
+
+ /* the fraction [0...1] of rejected high intensity pixels when taking 
+    the average of columns */
+  p = cpl_parameter_new_range("sinfoni.lamp_flats.high_rejection",
+                  CPL_TYPE_DOUBLE,
+                              "high rejection: "
+                              "percentage of rejected high intensity "
+                              "pixels before averaging",
+                              "sinfoni.lamp_flats",
+                              0.1,0.0,1.0);
+
+  cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,"lamp_flats-hi_rej");
+  cpl_parameterlist_append(list, p);
+
+
+  /* indicator if the bad pixels of the flatfield should be interpolated */
+  p = cpl_parameter_new_value("sinfoni.lamp_flats.interpol_index",
+                  CPL_TYPE_BOOL,
+                              "Interpolation index switch: "
+                              "indicator if the bad pixels of the flatfield "
+                              "should be interpolated",
+                              "sinfoni.lamp_flats",
+                              FALSE);
+
+
+  cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,
+                          "lamp_flats-interpol_index");
+  cpl_parameterlist_append(list, p);
+
+ 
+  /* maximal pixel distance from bad pixel to take valid pixels */
+  p = cpl_parameter_new_value("sinfoni.lamp_flats.max_rad",
+                  CPL_TYPE_INT,
+                              "Max Rad: "
+                              "maximal pixel distance from bad pixel "
+                              "to take valid pixels",
+                              "sinfoni.lamp_flats",
+                              4);
+
+  cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,"lamp_flats-max_rad");
+  cpl_parameterlist_append(list, p);
+
+
+  /*  indicator if a bad pixel mask should be generated or not */ 
+  p = cpl_parameter_new_value("sinfoni.lamp_flats.bad_ind",
+                  CPL_TYPE_BOOL,
+                              "indicator if a bad pixel mask should be "
+                              "generated or not",
+                              "sinfoni.lamp_flats",
+                              FALSE);
+
+  cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,"lamp_flats-bad_ind");
+  cpl_parameterlist_append(list, p);
+
+  /*
+   factor of the sigma noise limit; to remove the column intensity tilt only 
+   pixels which lie within a defined noise limit are used to fit a straight 
+   line
+  */
+  p = cpl_parameter_new_value("sinfoni.lamp_flats.sigma_factor",
+                  CPL_TYPE_DOUBLE,
+                              "Sigma Factor: "
+                              "factor of the sigma noise limit; "
+                              "to remove the column intensity tilt only "
+                              "pixels which lie within a defined noise "
+                              "limit are used to fit a straight line",
+                              "sinfoni.lamp_flats",
+                              5.);
+
+  cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,"lamp_flats-sigma_factor");
+  cpl_parameterlist_append(list, p);
+
+  /* 
+   if |pixel - sinfo_median| > factor * standard deviation -> then the
+    pixel value is replaced by the median of the 8 nearest neighbors
+  */
+  p = cpl_parameter_new_value("sinfoni.lamp_flats.factor",
+                  CPL_TYPE_DOUBLE,
+                              "Factor: "
+                   "if |pixel - median| > factor * standard deviation -> "
+                   "then the pixel value is replaced by the median of the 8 "
+                   "nearest neighbors",
+                              "sinfoni.lamp_flats",
+                              3.);
+
+  cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,"lamp_flats-factor");
+  cpl_parameterlist_append(list, p);
+
+  /* number of iterations to of sinfo_median filtering to find bad 
+     pixel clusters */
+  p = cpl_parameter_new_value("sinfoni.lamp_flats.iterations",
+                  CPL_TYPE_INT,
+                              "Iterations: "
+                              "number of iterations to of median filtering "
+                              "to find bad pixel clusters",
+                              "sinfoni.lamp_flats",
+                              8);
+
+  cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,"lamp_flats-iterations");
+  cpl_parameterlist_append(list, p);
+
+  /* percentage of rejected low intensity pixels before averaging */
+  p = cpl_parameter_new_range("sinfoni.lamp_flats.bad_low_rejection",
+                  CPL_TYPE_DOUBLE,
+                              "low rejection: "
+                              "Percentage for bad pixel low rejection",
+                              "sinfoni.lamp_flats",
+                              10.,0.,100.);
+
+  cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,"lamp_flats-bad_lo_rej");
+  cpl_parameterlist_append(list, p);
+
+  /* percentage of rejected high intensity pixels before averaging */
+  p = cpl_parameter_new_range("sinfoni.lamp_flats.bad_high_rejection",
+                  CPL_TYPE_DOUBLE,
+                              "high rejection: "
+                              "Percentage for bad pixel high rejection",
+                              "sinfoni.lamp_flats",
+                              10.,0.,100.);
+
+  cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,"lamp_flats-bad_hi_rej");
+  cpl_parameterlist_append(list, p);
+
+
+  /* to compute image statistics on a rectangular zone of the image
+     the coordinates of the rectangle are needed
+  */
+  /* lower left x coordinate */
+  p = cpl_parameter_new_range("sinfoni.lamp_flats.llx",
+                  CPL_TYPE_INT,
+                              "Lower Lext X corner",
+                              "sinfoni.lamp_flats",
+                              1350,DET_PIX_MIN,DET_PIX_MAX);
+
+  cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,"lamp_flats-llx");
+  cpl_parameterlist_append(list, p);
+
+  /* lower left y coordinate */
+  p = cpl_parameter_new_range("sinfoni.lamp_flats.lly",
+                  CPL_TYPE_INT,
+                              "Lower Lext Y corner",
+                              "sinfoni.lamp_flats",
+                              1000,DET_PIX_MIN,DET_PIX_MAX);
+
+  cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,"lamp_flats-lly");
+  cpl_parameterlist_append(list, p);
+
+  /* upper right x coordinate */
+  p = cpl_parameter_new_range("sinfoni.lamp_flats.urx",
+                  CPL_TYPE_INT,
+                              "Upper right X corner",
+                              "sinfoni.lamp_flats",
+                              1390,DET_PIX_MIN,DET_PIX_MAX);
+
+  cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,"lamp_flats-rrx");
+  cpl_parameterlist_append(list, p);
+
+  /* upper right y coordinate */
+  p = cpl_parameter_new_range("sinfoni.lamp_flats.ury",
+                  CPL_TYPE_INT,
+                              "Upper right Y corner",
+                              "sinfoni.lamp_flats",
+                              1200,DET_PIX_MIN,DET_PIX_MAX);
+
+  cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,"lamp_flats-ury");
+  cpl_parameterlist_append(list, p);
+
+  /* indicator that indicates if the values beyond a threshold deviation */
+  p = cpl_parameter_new_value("sinfoni.lamp_flats.thresh_ind",
+                  CPL_TYPE_BOOL,
+                              "Treshold index: ",
+                              "sinfoni.lamp_flats",
+                              FALSE);
+
+
+  cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,"lamp_flats-tresh_ind");
+  cpl_parameterlist_append(list, p);
+
+  /* 
+  factor to the clean standard deviation to define the threshold deviation
+  from the clean mean
+  */
+  p = cpl_parameter_new_value("sinfoni.lamp_flats.mean_factor",
+                  CPL_TYPE_DOUBLE,
+                              "Mean Factor: "
+                              "factor to the clean standard deviation to "
+                              "define the threshold deviation "
+                              "from the clean mean",
+                              "sinfoni.lamp_flats",
+                              10.);
+
+  cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,"lamp_flats-mean_factor");
+  cpl_parameterlist_append(list, p);
+
+
+  /* QC LOG */
+ /* FPN */
+
+
+ p = cpl_parameter_new_range("sinfoni.lamp_flats.qc_fpn_xmin1",
+                  CPL_TYPE_INT,
+                              "qc_fpn_xmin1",
+                              "sinfoni.lamp_flats",
+                              512,DET_PIX_MIN,DET_PIX_MAX);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"lamp_flats-qc_fpn_xmin1");
+  cpl_parameterlist_append(list, p);
+  
+ 
+  p = cpl_parameter_new_range("sinfoni.lamp_flats.qc_fpn_xmax1",
+                  CPL_TYPE_INT,
+                              "qc_fpn_xmax1",
+                              "sinfoni.lamp_flats",
+                              1536,DET_PIX_MIN,DET_PIX_MAX);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"lamp_flats-qc_fpn_xmax1");
+  cpl_parameterlist_append(list, p);
+
+  p = cpl_parameter_new_range("sinfoni.lamp_flats.qc_fpn_ymin1",
+                  CPL_TYPE_INT,
+                              "qc_fpn_ymin1",
+                              "sinfoni.lamp_flats",
+                              512,DET_PIX_MIN,DET_PIX_MAX);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"lamp_flats-qc_fpn_ymin1");
+  cpl_parameterlist_append(list, p);
+
+
+  p = cpl_parameter_new_range("sinfoni.lamp_flats.qc_fpn_ymax1",
+                  CPL_TYPE_INT,
+                              "qc_fpn_ymax1",
+                              "sinfoni.lamp_flats",
+                              1536,DET_PIX_MIN,DET_PIX_MAX);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"lamp_flats-qc_fpn_ymax1");
+  cpl_parameterlist_append(list, p);
+
+
+
+
+
+
+ p = cpl_parameter_new_range("sinfoni.lamp_flats.qc_fpn_xmin2",
+                  CPL_TYPE_INT,
+                              "qc_fpn_xmin2",
+                              "sinfoni.lamp_flats",
+                              1350,DET_PIX_MIN,DET_PIX_MAX);
+
+  cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI, "lamp_flats-qc_fpn_xmin2");
+  cpl_parameterlist_append(list, p);
+  
+ 
+  p = cpl_parameter_new_range("sinfoni.lamp_flats.qc_fpn_xmax2",
+                  CPL_TYPE_INT,
+                              "qc_fpn_xmax2",
+                              "sinfoni.lamp_flats",
+                              1390,DET_PIX_MIN,DET_PIX_MAX);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"lamp_flats-qc_fpn_xmax2");
+  cpl_parameterlist_append(list, p);
+
+  p = cpl_parameter_new_range("sinfoni.lamp_flats.qc_fpn_ymin2",
+                  CPL_TYPE_INT,
+                              "qc_fpn_ymin2",
+                              "sinfoni.lamp_flats",
+                              1000,DET_PIX_MIN,DET_PIX_MAX);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"lamp_flats-qc_fpn_ymin2");
+  cpl_parameterlist_append(list, p);
+
+
+  p = cpl_parameter_new_range("sinfoni.lamp_flats.qc_fpn_ymax2",
+                  CPL_TYPE_INT,
+                              "qc_fpn_ymax2",
+                              "sinfoni.lamp_flats",
+                              1200,DET_PIX_MIN,DET_PIX_MAX);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"lamp_flats-qc_fpn_ymax2");
+  cpl_parameterlist_append(list, p);
+
+
+
+
+
+  p = cpl_parameter_new_value("sinfoni.lamp_flats.qc_thresh_min",
+                  CPL_TYPE_INT,
+                              "qc_thresh_min",
+                              "sinfoni.lamp_flats",
+                              0);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"lamp_flats-qc_thresh_min");
+  cpl_parameterlist_append(list, p);
+
+
+  p = cpl_parameter_new_value("sinfoni.lamp_flats.qc_thresh_max",
+                  CPL_TYPE_INT,
+                              "qc_thresh_max",
+                              "sinfoni.lamp_flats",
+                              49000);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"lamp_flats-qc_thresh_max");
+  cpl_parameterlist_append(list, p);
+
+
+}
+/**@}*/
diff --git a/sinfoni/sinfo_lamp_flats_config.h b/sinfoni/sinfo_lamp_flats_config.h
new file mode 100644
index 0000000..ae31eaf
--- /dev/null
+++ b/sinfoni/sinfo_lamp_flats_config.h
@@ -0,0 +1,39 @@
+/* $Id: sinfo_lamp_flats_config.h,v 1.1 2006/10/20 08:06:32 amodigli Exp $
+ *
+ * This file is part of the CPL (Common Pipeline Library)
+ * Copyright (C) 2002 European Southern Observatory
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*
+ * $Author: amodigli $
+ * $Date: 2006/10/20 08:06:32 $
+ * $Revision: 1.1 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+ /****************************************************************
+  *   Lamp_Spec Frames Data Reduction Parameter Initialization        *
+  ****************************************************************/
+#include <cpl.h>    /* defines parlist structure */
+
+/*
+#include "sinfo_dfs.h"
+*/
+#include "sinfo_globals.h"
+
+void
+sinfo_lamp_flats_config_add(cpl_parameterlist *list);
+
diff --git a/sinfoni/sinfo_lamp_ini.h b/sinfoni/sinfo_lamp_ini.h
new file mode 100644
index 0000000..2c692f5
--- /dev/null
+++ b/sinfoni/sinfo_lamp_ini.h
@@ -0,0 +1,68 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+   File name    :   sinfo_lamp_ini.h
+   Author       :    Juergen Schreiber
+   Created on   :    Mar 08, 2002
+   Description  :    preparing lamp ini file handling for SPIFFI
+ ---------------------------------------------------------------------------*/
+#ifndef SINFO_LAMP_INI_H
+#define SINFO_LAMP_INI_H
+/*---------------------------------------------------------------------------
+                                Includes
+---------------------------------------------------------------------------*/
+#include <cpl.h>
+#include "sinfo_lamp_cfg.h"
+/*----------------------------------------------------------------------------
+                             Function prototypes 
+ ---------------------------------------------------------------------------*/
+/**
+  @name        generateLamp_ini_file
+  @memo        Generate a default ini file for the preparing 
+                of halogen lamp spectrum command.
+  @param    ini_name    Name of the file to generate.
+  @param    name_i        Name of the input file.
+  @param    name_o        Name of the output file.
+  @return    int 0 if Ok, -1 otherwise.
+  @doc          This function generates a default ini file for the preparing 
+                of flatfield frames command. The generated file will have the 
+                requested name. 
+ */
+/*--------------------------------------------------------------------------*/
+int 
+generateLamp_ini_file(
+        char * ini_name,
+        char * name_i,
+        char * name_o,
+        char * name_c
+);
+
+/**
+  @name     parse_lamp_ini_file
+  @memo     Parse a ini_name.ini file and create a blackboard.
+  @param    ini_name    Name of the ASCII file to parse.
+  @return   1 newly allocated lamp_config blackboard structure.
+  @doc      The requested ini file is parsed and a blackboard object is 
+            created, then updated accordingly. Returns NULL in case of error.
+ */
+
+lamp_config * 
+parse_lamp_ini_file(char * ini_name) ;
+
+#endif
diff --git a/sinfoni/sinfo_lamp_ini_by_cpl.c b/sinfoni/sinfo_lamp_ini_by_cpl.c
new file mode 100644
index 0000000..622f9c3
--- /dev/null
+++ b/sinfoni/sinfo_lamp_ini_by_cpl.c
@@ -0,0 +1,240 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+   
+   File name    :   sinfo_lamp_ini_by_cpl.c
+   Author       :   Andrea Modigliani
+   Created on   :   May 26, 2004
+   Description  :   lamp spectrum cpl input handling for SPIFFI
+ ---------------------------------------------------------------------------*/
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+/*---------------------------------------------------------------------------
+                                Includes
+ ---------------------------------------------------------------------------*/
+#include <string.h>
+#include "sinfo_lamp_ini_by_cpl.h"
+#include "sinfo_functions.h"
+#include "sinfo_pro_types.h"
+/*---------------------------------------------------------------------------
+                    Functions private to this module
+ ---------------------------------------------------------------------------*/
+static void     
+parse_section_frames(lamp_config *, 
+                     cpl_parameterlist* cpl_cfg, 
+                     cpl_frameset* sof, 
+                     cpl_frameset** raw, 
+                     int* status);
+
+static void     
+parse_section_resampling(lamp_config *, cpl_parameterlist* cpl_cfg);
+static void     
+parse_section_extractspectrum(lamp_config *, cpl_parameterlist* cpl_cfg);
+
+/**@{*/
+/**
+ * @addtogroup sinfo_lamp_cfg Flat frame manipulation functions
+ *
+ * TBD
+ */
+
+
+/**
+  @name     sinfo_parse_cpl_input_lamp
+  @memo     Parse input frames & parameters and create a blackboard.
+  @param    cpl_cfg pointer to parameterlist
+  @param    sof pointer to input set of frames
+  @param    raw pointer to input set of raw frames
+  @return   1 newly allocated lamp_config blackboard structure.
+  @doc      The requested ini file is parsed and a blackboard object is 
+            created, then updated accordingly. Returns NULL in case of error.
+ */
+lamp_config * 
+sinfo_parse_cpl_input_lamp(cpl_parameterlist* cpl_cfg, 
+                           cpl_frameset* sof, 
+               cpl_frameset** raw)
+
+{
+        lamp_config   *       cfg= sinfo_lamp_cfg_create();
+        int status=0;
+        /*
+         * Perform sanity checks, fill up the structure with what was
+         * found in the ini file
+         */
+
+
+        parse_section_resampling    (cfg, cpl_cfg);
+        parse_section_extractspectrum (cfg, cpl_cfg);
+        parse_section_frames    (cfg, cpl_cfg, sof, raw,&status);
+ 
+        if (status > 0) {
+                sinfo_msg_error("parsing cpl input");
+                sinfo_lamp_cfg_destroy(cfg);
+                cfg = NULL ;
+                return NULL ;
+        }
+        return cfg ;
+}
+
+
+/**
+  @name     parse_section_frames
+  @memo     Parse input frames.
+  @param    cfg pointer to lamp_config structure
+  @param    cpl_cfg pointer to parameterlist
+  @param    sof pointer to input set of frames
+  @param    raw pointer to input set of raw frames
+  @return   void.
+ */
+static void     
+parse_section_frames(lamp_config * cfg,
+             cpl_parameterlist * cpl_cfg,
+             cpl_frameset * sof,
+             cpl_frameset ** raw,
+                     int* status)
+{
+
+   cpl_frame* frame   = NULL;
+   cpl_parameter *p; 
+   int nraw=0;
+    char spat_res[FILE_NAME_SZ];
+   char lamp_status[FILE_NAME_SZ];
+   char band[FILE_NAME_SZ];
+   int ins_set=0;
+
+   /* Input */
+
+   *raw=cpl_frameset_new();
+   sinfo_extract_raw_frames_type(sof,raw,PRO_FLUX_LAMP_STACKED);   
+
+   nraw    = cpl_frameset_get_size(*raw);
+
+   if(nraw<1) {
+     sinfo_msg_error("no good raw frame %s in input!",PRO_FLUX_LAMP_STACKED);
+     (*status)++;
+     return;
+   }
+   frame = cpl_frameset_get_frame(*raw,0);
+   strcpy(cfg -> inFrame,cpl_strdup(cpl_frame_get_filename(frame)));
+
+   /* Output */
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_spec.output_filename");
+   strcpy(cfg -> outName, cpl_parameter_get_string(p));
+
+   sinfo_get_spatial_res(frame,spat_res);
+   switch(sinfo_frame_is_on(frame))
+     {
+
+    case 0: 
+      strcpy(lamp_status,"on");
+      break;
+    case 1: 
+      strcpy(lamp_status,"off");
+      break;
+    case -1:
+      strcpy(lamp_status,"undefined");
+      break;
+    default: 
+      strcpy(lamp_status,"undefined");
+      break;
+
+     }
+   sinfo_get_band(frame,band);
+   sinfo_msg("Spatial resolution: %s lamp_status: %s band: %s \n",
+                     spat_res,    lamp_status,    band);
+
+   
+   sinfo_get_ins_set(band,&ins_set);
+
+   if(NULL != cpl_frameset_find(sof,PRO_WAVE_MAP)) {
+      frame = cpl_frameset_find(sof,PRO_WAVE_MAP);
+      strcpy(cfg -> wavemapim,cpl_strdup(cpl_frame_get_filename(frame)));
+   } else {
+     sinfo_msg_error("Frame %s not found! Exit!", PRO_WAVE_MAP);
+     (*status)++;
+     return;
+   }
+
+
+   return ;
+
+}
+
+
+
+/**
+  @name     parse_section_resampling
+  @memo     Parse resampling parameters.
+  @param    cfg pointer to lamp_config structure
+  @param    cpl_cfg pointer to parameterlist
+  @return   void.
+ */
+static void     
+parse_section_resampling(lamp_config * cfg, cpl_parameterlist * cpl_cfg)
+{
+
+   cpl_parameter *p; 
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_spec.ncoeffs");
+   cfg -> ncoeffs =  cpl_parameter_get_int(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_spec.nrows");
+   cfg -> nrows =  cpl_parameter_get_int(p);
+
+   return ;
+
+}
+/**
+  @name     parse_section_extractspectrum
+  @memo     Parse extractspectrum parameters.
+  @param    cfg pointer to lamp_config structure
+  @param    cpl_cfg pointer to parameterlist
+  @return   void.
+ */
+static void     
+parse_section_extractspectrum(lamp_config * cfg, cpl_parameterlist * cpl_cfg)
+{
+   cpl_parameter *p; 
+  
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_spec.lower_rejection");
+   cfg -> loReject = cpl_parameter_get_double(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_spec.higher_rejection");
+   cfg -> hiReject = cpl_parameter_get_double(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_spec.counts_to_intensity");
+   cfg -> countsToIntensity = cpl_parameter_get_double(p);
+
+   return ;
+
+}
+/**
+ at name sinfo_lamp_free
+ at memo deallocate lamp_config structure
+ at param cfg pointer to lamp_config structure
+ at return void
+*/
+void
+sinfo_lamp_free(lamp_config * cfg)
+{  
+  sinfo_lamp_cfg_destroy(cfg);
+  return;
+
+}
+/**@}*/
diff --git a/sinfoni/sinfo_lamp_ini_by_cpl.h b/sinfoni/sinfo_lamp_ini_by_cpl.h
new file mode 100644
index 0000000..ba16646
--- /dev/null
+++ b/sinfoni/sinfo_lamp_ini_by_cpl.h
@@ -0,0 +1,61 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+   File name    :   sinfo_lamp_ini_by_cpl.h
+   Author       :   Andrea Modigliani
+   Created on   :   May 26, 2004
+   Description  :   lamp cpl input handling for SPIFFI
+ ---------------------------------------------------------------------------*/
+#ifndef SINFO_LAMP_INI_BY_CPL_H
+#define SINFO_LAMP_INI_BY_CPL_H
+/*---------------------------------------------------------------------------
+                                Includes
+---------------------------------------------------------------------------*/
+#include <cpl.h>
+#include "sinfo_msg.h"
+#include "sinfo_lamp_cfg.h"
+/*----------------------------------------------------------------------------
+                             Function prototypes 
+ ---------------------------------------------------------------------------*/
+/**
+  @name     sinfo_parse_cpl_input_lamp
+  @memo     Parse input frames & parameters and create a blackboard.
+  @param    cpl_cfg pointer to parameterlist
+  @param    sof pointer to input set of frames
+  @param    raw pointer to input set of raw frames
+  @return   1 newly allocated lamp_config blackboard structure.
+  @doc      The requested ini file is parsed and a blackboard object is 
+            created, then updated accordingly. Returns NULL in case of error.
+ */
+lamp_config * 
+sinfo_parse_cpl_input_lamp(cpl_parameterlist* cpl_cfg, 
+                           cpl_frameset* sof, 
+                           cpl_frameset** raw) ;
+
+/**
+ at name sinfo_lamp_free
+ at memo deallocate lamp_config structure
+ at param cfg pointer to lamp_config structure
+ at return void
+*/
+void 
+sinfo_lamp_free(lamp_config * cfg);
+
+
+#endif
diff --git a/sinfoni/sinfo_lamp_spec_config.c b/sinfoni/sinfo_lamp_spec_config.c
new file mode 100644
index 0000000..8f45763
--- /dev/null
+++ b/sinfoni/sinfo_lamp_spec_config.c
@@ -0,0 +1,126 @@
+/* $Id: sinfo_lamp_spec_config.c,v 1.5 2012/03/02 08:42:20 amodigli Exp $
+ *
+ * This file is part of the CPL (Common Pipeline Library)
+ * Copyright (C) 2002 European Southern Observatory
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*
+ * $Author: amodigli $
+ * $Date: 2012/03/02 08:42:20 $
+ * $Revision: 1.5 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+ /****************************************************************
+  *   Lamp_Spec Frames Data Reduction Parameter Initialization        *
+  ****************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+#include "sinfo_lamp_spec_config.h"
+#include "sinfo_globals.h"
+  
+/**@{*/
+/**
+ * @defgroup sinfo_lamp_spec_config Spectroscopic flats manipulation
+ *
+ * TBD
+ */
+
+void
+ sinfo_lamp_spec_config_add(cpl_parameterlist *list)
+{
+
+  cpl_parameter *p;
+
+  if (!list) {
+    return;
+  }
+
+  /* Input file name */
+  /* Output file name */
+/* output name of resulting fits wavelength map */
+  p = cpl_parameter_new_value("sinfoni.lamp_spec.output_filename",
+                  CPL_TYPE_STRING,
+                              "Output File Name: ",
+                              "sinfoni.lamp_spec",
+                              "out_flatspec.fits");
+
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"out-lampspec_filename");
+  cpl_parameterlist_append(list, p);
+
+
+  /* number of coefficients for the polynomial interpolation */
+ p = cpl_parameter_new_value("sinfoni.lamp_spec.ncoeffs",
+                  CPL_TYPE_INT,
+                              "No of polynomial coeffs",
+                              "sinfoni.lamp_spec",
+                              3);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"lamp_spec-ncoeffs");
+  cpl_parameterlist_append(list, p);
+
+  /* number of image rows in the resampled frame 
+    (1280 for single frames, 2560 for interleaved frames) */
+ p = cpl_parameter_new_value("sinfoni.lamp_spec.nrows",
+                  CPL_TYPE_INT,
+                              "No of image rows in resampled frame",
+                              "sinfoni.lamp_spec",
+                              SINFO_RESAMP_NROWS);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"lamp_spec-nrows");
+  cpl_parameterlist_append(list, p);
+
+
+
+  /*Reconstruction */
+ /* the fraction [0...1] of rejected low intensity pixels when taking 
+the average of columns */
+  p = cpl_parameter_new_range("sinfoni.lamp_spec.lower_rejection",
+                  CPL_TYPE_DOUBLE,
+                              "lower rejection",
+                              "sinfoni.lamp_spec",
+                              0.1,0.0,1.0);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"lamp_spec-low_rejection");
+  cpl_parameterlist_append(list, p);
+
+ /* the fraction [0...1] of rejected high intensity pixels when taking 
+the average of columns */
+  p = cpl_parameter_new_range("sinfoni.lamp_spec.higher_rejection",
+                  CPL_TYPE_DOUBLE,
+                              "high rejection",
+                              "sinfoni.lamp_spec",
+                              0.1,0.0,1.0);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"lamp_spec-high_rejection");
+  cpl_parameterlist_append(list, p);
+
+
+  p = cpl_parameter_new_value("sinfoni.lamp_spec.counts_to_intensity",
+                  CPL_TYPE_DOUBLE,
+                              "Counts To Intensity",
+                              "sinfoni.lamp_spec",
+                              1.);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"lamp_spec-cnt2int");
+  cpl_parameterlist_append(list, p);
+
+
+}
+/**@}*/
diff --git a/sinfoni/sinfo_lamp_spec_config.h b/sinfoni/sinfo_lamp_spec_config.h
new file mode 100644
index 0000000..9248fb4
--- /dev/null
+++ b/sinfoni/sinfo_lamp_spec_config.h
@@ -0,0 +1,35 @@
+/* $Id: sinfo_lamp_spec_config.h,v 1.1 2006/10/20 08:06:32 amodigli Exp $
+ *
+ * This file is part of the CPL (Common Pipeline Library)
+ * Copyright (C) 2002 European Southern Observatory
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*
+ * $Author: amodigli $
+ * $Date: 2006/10/20 08:06:32 $
+ * $Revision: 1.1 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+ /****************************************************************
+  *   Lamp_Spec Frames Data Reduction Parameter Initialization        *
+  ****************************************************************/
+#include "cpl.h"    /* defines parlist structure */
+
+
+
+void
+sinfo_lamp_spec_config_add(cpl_parameterlist *list);
diff --git a/sinfoni/sinfo_local_types.h b/sinfoni/sinfo_local_types.h
new file mode 100644
index 0000000..93de90a
--- /dev/null
+++ b/sinfoni/sinfo_local_types.h
@@ -0,0 +1,131 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+   
+   File name     :    sinfo_local_types.h
+   Author         :    Nicolas Devillard
+   Created on    :    Nov 27, 1995
+   Description    :    all shared local types for eclipse
+
+ ---------------------------------------------------------------------------*/
+/*---------------------------------------------------------------------------
+    PUBLIC NOTICE AS REQUIRED BY LAW: Any use of this product, in any
+    manner whatsoever, will increase the amount of disorder in the
+    universe. Although no liability is implied herein, the consumer is
+    warned that this process will ultimately lead to the heat death of the
+    universe.
+ ---------------------------------------------------------------------------*/
+/*
+    $Id: sinfo_local_types.h,v 1.4 2007/06/06 07:10:45 amodigli Exp $
+    $Author: amodigli $
+    $Date: 2007/06/06 07:10:45 $
+    $Revision: 1.4 $
+ */
+
+#ifndef SINFO_LOCAL_TYPES_H
+#define SINFO_LOCAL_TYPES_H
+/*----------------------------------------------------------------------------
+                                   Includes
+ *--------------------------------------------------------------------------*/
+/*----------------------------------------------------------------------------
+                                   Defines
+ *--------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+                                   New types
+ ---------------------------------------------------------------------------*/
+/*
+ * These types are defined for portability issues
+ * On DEC-Alpha stations, long is 64 bits, but int is 32
+ * We have to redefine all int values accordingly to ensure
+ * portability!
+ */
+
+#ifdef _DEC_ALPHA
+typedef unsigned int ulong32 ;
+typedef int long32 ;
+#else
+typedef unsigned long ulong32 ;
+typedef long long32 ;
+#endif
+
+typedef unsigned short ushort16 ;
+typedef short short16 ;
+
+typedef unsigned char uchar8 ;
+typedef char char8 ;
+ 
+typedef unsigned char BYTE ;
+
+/* defined in limits.h, redefined here for portability  */
+
+#define LONG32_MIN  (long32)(-2147483647-1) 
+#define LONG32_MAX  (long32)(2147483647)
+#define ULONG32_MAX (ulong32)(4294967295)
+
+#define SHRT16_MIN  (short16)(-32768)
+#define SHRT16_MAX  (short16)(32767)
+#define USHRT16_MAX (ushort16)(65535)
+
+typedef struct _DOUBLE_COMPLEX_ {
+    double x, y ;
+} dcomplex ;
+
+/*--------------------------------------------------------------------------*/
+/* pixelvalue is the internal Pixel representation  */
+
+#ifdef DOUBLEPIX
+typedef double    pixelvalue ;
+#else
+typedef float    pixelvalue ;
+#endif
+
+
+
+/*
+ * dpoint: useful to store point coordinates in double precision
+ */
+
+typedef struct _DPOINT_ {
+    double x ;
+    double y ;
+} dpoint ;
+
+
+
+
+/*--------------------------------------------------------------------------*/
+/* Pixel map */
+
+
+typedef uchar8 binpix ;
+
+typedef struct _PIXEL_MAP_
+{
+    int            lx, ly ;
+    int            nbpix ;
+    int            ngoodpix ;
+    binpix    *    data ;
+} pixel_map ;
+
+
+#define NullMap (pixel_map*)NULL
+
+
+#endif 
diff --git a/sinfoni/sinfo_matrix.c b/sinfoni/sinfo_matrix.c
new file mode 100644
index 0000000..331530c
--- /dev/null
+++ b/sinfoni/sinfo_matrix.c
@@ -0,0 +1,424 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+   
+   File name     :    sinfo_matrix.c
+   Author         :    Nicolas Devillard
+   Created on    :    1994
+   Description    :    basic 2d sinfo_eclipse_matrix handling routines
+
+ ---------------------------------------------------------------------------*/
+/*
+ $Id: sinfo_matrix.c,v 1.4 2012/03/02 08:42:20 amodigli Exp $
+ $Author: amodigli $
+ $Date: 2012/03/02 08:42:20 $
+ $Revision: 1.4 $
+ */
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+/*----------------------------------------------------------------------------
+                                   Includes
+ ---------------------------------------------------------------------------*/
+#include "sinfo_matrix.h"
+/**@{*/
+/**
+ * @addtogroup sinfo_utilities matrix functions
+ *
+ * TBD
+ */
+
+
+/*----------------------------------------------------------------------------
+                                   Macros
+ ---------------------------------------------------------------------------*/
+#define dtiny(a) ((a)<0?(a)> -1.e-30:(a)<1.e-30)
+/*----------------------------------------------------------------------------
+                        Private function prototypes
+ ---------------------------------------------------------------------------*/
+static int gauss_pivot(double *ptra, double *ptrc, int n);
+/*----------------------------------------------------------------------------
+                              Function codes
+ ---------------------------------------------------------------------------*/
+
+/**
+  @name     sinfo_create_mx
+  @memo     Allocates a new sinfo_eclipse_matrix.
+  @param    nr  Number of rows.
+  @param    nc  Number of columns.
+  @return   Pointer to newly allocated sinfo_eclipse_matrix.
+  @doc
+
+  Allocates a new sinfo_eclipse_matrix.
+ */
+
+Matrix
+sinfo_create_mx(int nr, int nc)
+{
+    Matrix b;
+    b = (Matrix)cpl_calloc(1,sizeof(sinfo_eclipse_matrix));
+    b->m = (double*)cpl_calloc(nr*nc,sizeof(double));
+    b->nr= nr;
+    b->nc= nc;
+    return b;
+}
+
+/**
+  @name     sinfo_copy_mx
+  @memo     Copy a sinfo_eclipse_matrix.
+  @param    a   Matrix to copy.
+  @return   Pointer to newly allocated sinfo_eclipse_matrix.
+  @doc
+
+  Copy a sinfo_eclipse_matrix.
+ */
+Matrix
+sinfo_copy_mx(Matrix a)
+{
+    Matrix b = sinfo_create_mx(a->nr,a->nc);
+    if (b!=NULL) {
+        register int s = a->nr*a->nc;
+        register double *mm = b->m+s;
+        register double *am = a->m+s;
+        while (s--) *--mm = *--am;
+    }
+    return b;
+}
+
+/**
+  @name     sinfo_close_mx
+  @memo     Frees memory associated to a sinfo_eclipse_matrix.
+  @param    a   Matrix to free.
+  @return   void
+  @doc
+
+  Free a sinfo_eclipse_matrix.
+ */
+void
+sinfo_close_mx(Matrix a)
+{
+    if (a==NULL) return ;
+    if (a->m != NULL)
+        cpl_free(a->m);
+    cpl_free(a);
+    return;
+}
+
+/**
+  @name     sinfo_mul_mx
+  @memo     Multiplies 2 matrices.
+  @param    a   Matrix on the left side of the multiplication.
+  @param    b   Matrix on the right side of the multiplication.
+  @return   Matrix a*b.
+  @doc
+
+  Multiply matrices.
+ */
+Matrix
+sinfo_mul_mx(Matrix a, Matrix b)
+{
+    Matrix c, d;
+    int n1=a->nr, n2=a->nc, n3=b->nc;
+    register double *a0;
+    register double *c0;
+    register double *d0;
+    register int i,j,k;
+
+    if(n2!=b->nr) return NULL;
+    c = sinfo_create_mx(n1,n3);
+    d = sinfo_transp_mx(b);
+
+    for (i=0,c0=c->m;i<n1;i++)
+        for (j=0,d0=d->m;j<n3;j++,c0++)
+            for (k=0,*c0=0,a0=a->m+i*n2;k<n2;k++)
+                *c0 += *a0++ * *d0++;
+    sinfo_close_mx(d);
+    return c;
+}
+
+/**
+  @name     sinfo_invert_mx
+  @memo     Inverts a sinfo_eclipse_matrix.
+  @param    aa  (Square) sinfo_eclipse_matrix to sinfo_invert
+  @return   Newly allocated sinfo_eclipse_matrix.
+  @doc
+ 
+  The sinfo_eclipse_matrix inversion procedure is hardcoded for optimized speed
+  in the case of 1x1, 2x2 and 3x3 matrices. This function is not suitable
+  for large matrices.
+ */
+Matrix
+sinfo_invert_mx(Matrix aa)
+{
+    Matrix bb;
+    int test=1;
+
+    if(aa->nr!=aa->nc) return NULL;
+    bb = sinfo_create_mx(aa->nr,aa->nc);
+
+    if(aa->nr==1)
+    {
+        double det;
+        register double ted;
+        det= *(aa->m);
+        if(dtiny(det)) test=0;
+        ted=1./det;
+        *(bb->m)=ted;
+    }
+    else if(aa->nr==2)
+    {
+        double det;
+        register double ted;
+        register double *mm=aa->m;
+        double a= *(mm++),b= *(mm++);
+        double c= *(mm++),d= *(mm);
+        det=a*d-b*c;
+        if(dtiny(det)) test=0;
+        ted=1./det;
+        mm=bb->m;
+        *(mm++)= d*ted,*(mm++)= -b*ted;
+        *(mm++)= -c*ted,*(mm)= a*ted;
+    }
+    else if(aa->nr==3)
+    {
+        double det;
+        register double ted;
+        register double *mm=aa->m;
+        double a= *(mm++),b= *(mm++),c= *(mm++);
+        double d= *(mm++),e= *(mm++),f= *(mm++);
+        double g= *(mm++),h= *(mm++),i= *(mm);
+        det=a*e*i-a*h*f-b*d*i+b*g*f+c*d*h-c*g*e;
+        if(dtiny(det)) test=0;
+        ted=1./det;
+        mm=bb->m;
+        *(mm++)=(e*i-f*h)*ted,
+                *(mm++)=(c*h-b*i)*ted,
+                *(mm++)=(b*f-e*c)*ted;
+
+        *(mm++)=(f*g-d*i)*ted,
+                *(mm++)=(a*i-g*c)*ted,
+                *(mm++)=(d*c-a*f)*ted;
+
+        *(mm++)=(d*h-g*e)*ted,
+                *(mm++)=(g*b-a*h)*ted,
+                *(mm)=(a*e-d*b)*ted;
+    }
+    else
+    {
+        Matrix temp=sinfo_copy_mx(aa);
+        if(gauss_pivot(temp->m,bb->m,aa->nr)==0) test=0;
+        sinfo_close_mx(temp);
+    }
+    if(test==0)
+    {
+        sinfo_msg_error("not invertible, aborting inversion");
+        return NULL;
+    }
+    return bb;
+}
+
+/**
+  @name     sinfo_transp_mx
+  @memo     Transposes a sinfo_eclipse_matrix.
+  @param    a   Matrix to transpose.
+  @return   Newly allocated sinfo_eclipse_matrix.
+  @doc
+
+  Transpose a sinfo_eclipse_matrix.
+ */
+Matrix
+sinfo_transp_mx(Matrix a)
+{
+    register int nc=a->nc, nr=a->nr;
+    register double *a0;
+    register double *b0;
+    register int i,j;
+    Matrix b = sinfo_create_mx(nc,nr);
+
+    if (b == (Matrix)NULL) return b ;
+    for (i=0,b0=b->m;i<nc;i++)
+        for (j=0,a0=a->m+i;j<nr;j++,a0+=nc,b0++)
+            *b0 = *a0;
+    return b;
+}
+
+/**
+  @name     gauss_pivot
+  @memo     Line simplification with Gauss method.
+  @param    ptra    A sinfo_eclipse_matrix line.
+  @param    ptrc    A sinfo_eclipse_matrix line.
+  @param    n       Number of rows in each line.
+  @return   int 1 if Ok, 0 else.
+  @doc
+ 
+  This function is used only for the general case in sinfo_eclipse_matrix 
+  inversion.
+ */
+static int
+gauss_pivot(double *ptra, double *ptrc, int n)
+/* c(n,n) = a(n,n)^-1 */
+{
+#define SINFO_ABS(a) (((a) > 0) ? (a) : -(a))
+
+    register int i,j,k,l;
+    int maj;
+    double max,r,t;
+    double *ptrb;
+
+    ptrb=(double *)cpl_calloc(n*n,sizeof(double));
+    for(i=0;i<n;i++)
+        ptrb[i*n+i]= 1.0;
+
+    for (i=1;i <= n;i++)
+    {
+        /* Search max in current column  */
+        max = SINFO_ABS(*(ptra + n*i-n));
+        maj = i;
+        for (j = i;j <= n;j++)
+            if (SINFO_ABS(*(ptra+n*j+i-n-1)) > max)
+            {
+                maj = j;
+                max = SINFO_ABS(*(ptra+n*j+i-n-1));
+            }
+
+        /* swap lines i and maj */
+        if (maj != i)
+        {
+            for (j = i;j <= n;j++)
+            {
+                r = *(ptra+n*maj+j-n-1);
+                *(ptra+n*maj+j-n-1) = *(ptra+n*i+j-n-1);
+                *(ptra+n*i+j-n-1) = r;
+            }
+            for(l=0;l<n;l++)
+            {
+                r = *(ptrb+l*n+maj-1);
+                *(ptrb+l*n+maj-1) = *(ptrb+l*n+i-1);
+                *(ptrb+l*n+i-1) = r;
+            }
+        }
+
+        /* Subtract line by line */
+        for (j = i + 1;j <= n;j++)
+        {
+            t = (*(ptra+(n+1)*i-n-1));
+            if(dtiny(t)) return(0);
+            r = (*(ptra+n*j+i-n-1)) / t;
+            for(l=0;l<n;l++)
+                *(ptrb+l*n+j-1) -= r * (*(ptrb+l*n+i-1));
+            for (k = i;k <= n;k++)
+                *(ptra+n*j+k-n-1) -= r * (*(ptra+n*i+k-n-1));
+        }
+    }
+
+    /* Triangular system resolution    */
+    for(l=0;l<n;l++)
+       for (i = n;i >= 1;i--)
+       {
+        t = (*(ptra+(n+1)*i-n-1));
+        if(dtiny(t)) return(0);
+        *(ptrc+l+(i-1)*n) = (*(ptrb+l*n+i-1)) / t;
+        if (i > 1)
+           for (j = i - 1;j > 0;j--)
+            *(ptrb+l*n+j-1) -= (*(ptra+n*j+i-n-1)) * 
+                                           (*(ptrc+l+(i-1)*n));
+        }
+    cpl_free(ptrb);
+    return(1);
+}
+
+/**
+  @name     sinfo_least_sq_mx
+  @memo     Compute the solution of an equation using a pseudo-inverse.
+  @param    A   Matrix.
+  @param    B   Matrix.
+  @return   Pointer to newly allocated sinfo_eclipse_matrix.
+  @doc
+ 
+  The equation is XA=B.
+ 
+  The pseudo-inverse solution to this equation is defined as:
+  \begin{verbatim}
+  P = B.tA.inv(A.tA)
+  \end{verbatim}
+ 
+  P is solving the equation using a least-squares criterion.
+  Demonstration left to the reader.
+ */
+
+Matrix 
+sinfo_least_sq_mx(
+    Matrix    A,
+    Matrix    B
+)
+{
+    Matrix    m1,
+            m2,
+            m3,
+            m4,
+            m5 ;
+
+
+
+    m1 = sinfo_transp_mx(A) ;
+    m2 = sinfo_mul_mx(A, m1) ;
+    m3 = sinfo_invert_mx(m2) ;
+    m4 = sinfo_mul_mx(B, m1) ;
+    m5 = sinfo_mul_mx(m4, m3) ;
+
+    sinfo_close_mx(m1) ;
+    sinfo_close_mx(m2) ;
+    sinfo_close_mx(m3) ;
+    sinfo_close_mx(m4) ;
+
+    return m5 ;
+}
+
+/**
+  @name     sinfo_print_mx
+  @memo     Prints out a sinfo_eclipse_matrix on stdout.
+  @param    M       Matrix to print out
+  @param    name    Name of the sinfo_eclipse_matrix to print out.
+  @return   void
+  @doc
+ 
+  The sinfo_eclipse_matrix name is printed out, then all values row by row.
+  Used for debugging purposes mostly.
+ */
+
+void 
+sinfo_print_mx(
+    Matrix    M,
+    const char *    name
+)
+{
+    int    i, j ;
+
+    fprintf(stdout, "# sinfo_eclipse_matrix %s is [%d x %d]\n", 
+        name, M->nr, M->nc) ;
+    for (j=0 ; j<M->nr ; j++) {
+        for (i=0 ; i<M->nc ; i++) {
+            fprintf(stdout, "%g\t", M->m[i+j*M->nc]) ;
+        }
+        fprintf(stdout, "\n") ;
+    }
+    fprintf(stdout, "\n") ;
+}
+
+/**@}*/
diff --git a/sinfoni/sinfo_matrix.h b/sinfoni/sinfo_matrix.h
new file mode 100644
index 0000000..18b4e58
--- /dev/null
+++ b/sinfoni/sinfo_matrix.h
@@ -0,0 +1,203 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+   
+   File name     :    sinfo_matrix.h
+   Author         :    Nicolas Devillard
+   Created on    :    1994
+   Description    :    basic 2d sinfo_eclipse_matrix handling routines
+
+ ---------------------------------------------------------------------------*/
+/*
+ $Id: sinfo_matrix.h,v 1.3 2007/06/06 07:10:45 amodigli Exp $
+ $Author: amodigli $
+ $Date: 2007/06/06 07:10:45 $
+ $Revision: 1.3 $
+ */
+
+#ifndef SINFO_MATRIX_H
+#define SINFO_MATRIX_H
+
+
+/*---------------------------------------------------------------------------
+                                   Includes
+ ---------------------------------------------------------------------------*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include "sinfo_msg.h"
+#include <cpl.h>
+
+/*---------------------------------------------------------------------------
+                                   Defines
+ ---------------------------------------------------------------------------*/
+
+#define _(b,i,j) (*((b)->m+(i)*(b)->nc+(j))) /* b(i,j)*/
+
+#define mx_get(M,i,j)    ((M)->m[(i)+(j)*(M)->nc])
+#define mx_set(M,i,j,v)    (mx_get(M,i,j)=v)
+
+
+/*---------------------------------------------------------------------------
+                                   New Types
+ ---------------------------------------------------------------------------*/
+
+
+typedef struct _MATRIX_ {
+    double    *    m;
+    int         nr;
+    int         nc;
+} sinfo_eclipse_matrix, *Matrix;
+
+
+
+/*---------------------------------------------------------------------------
+                          Function ANSI C prototypes
+ ---------------------------------------------------------------------------*/
+
+/**
+  @name        sinfo_create_mx
+  @memo        Allocates a new sinfo_eclipse_matrix.
+  @param    nr    Number of rows.
+  @param    nc    Number of columns.
+  @return    Pointer to newly allocated sinfo_eclipse_matrix.
+  @doc
+ 
+  Allocates a new sinfo_eclipse_matrix.
+ */
+
+Matrix
+sinfo_create_mx(int nr, int nc) ;
+
+/**
+  @name        sinfo_copy_mx
+  @memo        Copy a sinfo_eclipse_matrix.
+  @param    a    Matrix to copy.
+  @return    Pointer to newly allocated sinfo_eclipse_matrix.
+  @doc
+ 
+  Copy a sinfo_eclipse_matrix.
+ */
+
+Matrix
+sinfo_copy_mx(Matrix a) ;
+
+/**
+  @name        sinfo_close_mx
+  @memo        Frees memory associated to a sinfo_eclipse_matrix.
+  @param    a    Matrix to free.
+  @return    void
+  @doc
+ 
+  Free a sinfo_eclipse_matrix.
+ */
+
+void
+sinfo_close_mx(Matrix a) ;
+
+
+/**
+  @name        sinfo_mul_mx
+  @memo        Multiplies 2 matrices.
+  @param    a    Matrix on the left side of the multiplication.
+  @param    b    Matrix on the right side of the multiplication.
+  @return    Matrix a*b.
+  @doc
+ 
+  Multiply matrices.
+ */
+
+Matrix
+sinfo_mul_mx(Matrix a, Matrix b) ;
+
+/**
+  @name        sinfo_invert_mx
+  @memo        Inverts a sinfo_eclipse_matrix.
+  @param    aa    (Square) sinfo_eclipse_matrix to sinfo_invert
+  @return    Newly allocated sinfo_eclipse_matrix.
+  @doc
+
+  The sinfo_eclipse_matrix inversion procedure is hardcoded for 
+  optimized speed in
+  the case of 1x1, 2x2 and 3x3 matrices. This function is not suitable
+  for large matrices.
+ */
+
+Matrix
+sinfo_invert_mx(Matrix aa) ;
+
+
+/**
+  @name        sinfo_transp_mx
+  @memo        Transposes a sinfo_eclipse_matrix.
+  @param    a    Matrix to transpose.
+  @return    Newly allocated sinfo_eclipse_matrix.
+  @doc
+ 
+  Transpose a sinfo_eclipse_matrix.
+ */
+
+Matrix
+sinfo_transp_mx(Matrix a) ;
+
+/**
+  @name        sinfo_least_sq_mx
+  @memo        Compute the solution of an equation using a pseudo-inverse.
+  @param    A    Matrix.
+  @param    B    Matrix.
+  @return    Pointer to newly allocated sinfo_eclipse_matrix.
+  @doc
+
+  The equation is XA=B.
+
+  The pseudo-inverse solution to this equation is defined as:
+  \begin{verbatim}
+  P = B.tA.inv(A.tA)
+  \end{verbatim}
+
+  P is solving the equation using a least-squares criterion.
+  Demonstration left to the reader.
+ */
+
+Matrix sinfo_least_sq_mx(
+    Matrix  A,
+    Matrix  B
+) ;
+
+
+/**
+  @name        sinfo_print_mx
+  @memo        Prints out a sinfo_eclipse_matrix on stdout.
+  @param    M        Matrix to print out
+  @param    name    Name of the sinfo_eclipse_matrix to print out.
+  @return    void
+  @doc
+
+  The sinfo_eclipse_matrix name is printed out, then all values row by row.
+  Used for debugging purposes mostly.
+ */
+
+void sinfo_print_mx(
+    Matrix  M,
+    const char *  name
+) ;
+
+
+#endif
diff --git a/sinfoni/sinfo_median.c b/sinfoni/sinfo_median.c
new file mode 100644
index 0000000..88f3dbc
--- /dev/null
+++ b/sinfoni/sinfo_median.c
@@ -0,0 +1,374 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*---------------------------------------------------------------------------
+   
+   File name     :    sinfo_median.c
+   Author         :    N. Devillard
+   Created on    :    1998
+   Description    :    Fast sinfo_median finding routines.
+
+ *--------------------------------------------------------------------------*/
+/*
+    $Id: sinfo_median.c,v 1.4 2012/03/02 08:42:20 amodigli Exp $
+    $Author: amodigli $
+    $Date: 2012/03/02 08:42:20 $
+    $Revision: 1.4 $
+*/
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+/*---------------------------------------------------------------------------
+                                   Includes
+ ---------------------------------------------------------------------------*/
+#include "sinfo_median.h"
+/**@{*/
+/**
+ * @addtogroup sinfo_utilities median computation functions
+ *
+ * TBD
+ */
+
+/*---------------------------------------------------------------------------
+                                   Macros
+ ---------------------------------------------------------------------------*/
+#define median_WIRTH(a,n) sinfo_kth_smallest(a,n,(((n)&1)?((n)/2):(((n)/2)-1)))
+/*---------------------------------------------------------------------------
+                              Function codes
+ ---------------------------------------------------------------------------*/
+/**
+  @name        sinfo_kth_smallest
+  @memo        Find the kth smallest element in an array.
+  @param    a    Array to consider for sinfo_median search.
+  @param    n    Number of elements in the array.
+  @param    k    Rank of the element to find (between 0 and n-1).
+  @return    One element from the array.
+  @doc
+
+  Provide an array of n pixelvalues and the rank of the value you want
+  to find. A rank of 0 means the minimum element, a rank of n-1 is the
+  maximum element, and a rank of n/2 is the sinfo_median. Use the
+  median_WIRTH macro to find the sinfo_median directly.
+
+  NB: The input array is modified. Some elements are swapped, until
+  the requested value is found. The array is left in an undefined
+  sorted state.
+  
+  This algorithm was taken from the following book:
+  \begin{verbatim}
+                Author: Wirth, Niklaus 
+                 Title: Algorithms + data structures = programs 
+             Publisher: Englewood Cliffs: Prentice-Hall, 1976 
+  Physical description: 366 p. 
+                Series: Prentice-Hall Series in Automatic Computation 
+  \end{verbatim}
+ */
+
+#define PIX_SWAP(a,b) { register pixelvalue t=(a);(a)=(b);(b)=t; }
+
+pixelvalue 
+sinfo_kth_smallest(pixelvalue a[], int n, int k)
+{
+    register int i,j,l,m ;
+    register pixelvalue x ;
+
+    l=0 ; m=n-1 ;
+    while (l<m) {
+        x=a[k] ;
+        i=l ;
+        j=m ;
+        do {
+            while (a[i]<x) i++ ;
+            while (x<a[j]) j-- ;
+            if (i<=j) {
+                PIX_SWAP(a[i],a[j]) ;
+                i++ ; j-- ;
+            }
+        } while (i<=j) ;
+        if (j<k) l=i ;
+        if (k<i) m=j ;
+    }
+    return a[k] ;
+}
+
+#undef PIX_SWAP
+
+/**
+  @name        sinfo_kth_smallest_double
+  @memo        Find the kth smallest element in a double array.
+  @param    a    Array to consider for sinfo_median search.
+  @param    n    Number of elements in the array.
+  @param    k    Rank of the element to find (between 0 and n-1).
+  @return    One element from the array.
+  @doc
+
+  See sinfo_kth_smallest() function in the same file.
+
+  NB: THE INPUT ARRAY IS MODIFIED.
+ */
+
+#define DBL_SWAP(a,b) { register double t=(a);(a)=(b);(b)=t; }
+
+double 
+sinfo_kth_smallest_double(double a[], int n, int k)
+{
+    register int i,j,l,m ;
+    register double x ;
+
+    l=0 ; m=n-1 ;
+    while (l<m) {
+        x=a[k] ;
+        i=l ;
+        j=m ;
+        do {
+            while (a[i]<x) i++ ;
+            while (x<a[j]) j-- ;
+            if (i<=j) {
+                DBL_SWAP(a[i],a[j]) ;
+                i++ ; j-- ;
+            }
+        } while (i<=j) ;
+        if (j<k) l=i ;
+        if (k<i) m=j ;
+    }
+    return a[k] ;
+}
+
+#undef DBL_SWAP
+
+#define PIX_SORT(a,b) { if ((a)>(b)) PIX_SWAP((a),(b)); }
+#define PIX_SWAP(a,b) { pixelvalue temp=(a);(a)=(b);(b)=temp; }
+
+/**
+  @name        sinfo_opt_med3
+  @memo        Optimized search of the sinfo_median of 3 values.
+  @param    p    Array of 3 pixelvalues
+  @return    Median of the input values.
+  @doc
+
+  Found on sci.image.processing. Cannot go faster unless some
+  assumptions are made about the nature of the input signal, or the
+  underlying hardware.
+
+  The input array is modified.
+ */
+
+pixelvalue
+sinfo_opt_med3(
+    pixelvalue  *   p
+)
+{
+    PIX_SORT(p[0],p[1]) ; PIX_SORT(p[1],p[2]) ; PIX_SORT(p[0],p[1]) ;
+    return(p[1]) ;
+}
+
+/**
+  @name        sinfo_opt_med5
+  @memo        Optimized search of the sinfo_median of 5 values.
+  @param    p    Array of 5 pixelvalues
+  @return    Median of the input values.
+  @doc
+
+  Found on sci.image.processing. Cannot go faster unless some
+  assumptions are made about the nature of the input signal, or the
+  underlying hardware.
+
+  The input array is modified.
+ */
+
+pixelvalue
+sinfo_opt_med5(
+    pixelvalue  *   p
+)
+{
+    PIX_SORT(p[0],p[1]) ; PIX_SORT(p[3],p[4]) ; PIX_SORT(p[0],p[3]) ;
+    PIX_SORT(p[1],p[4]) ; PIX_SORT(p[1],p[2]) ; PIX_SORT(p[2],p[3]) ;
+    PIX_SORT(p[1],p[2]) ; return(p[2]) ;
+}
+
+/**
+  @name        sinfo_opt_med7
+  @memo        Optimized search of the sinfo_median of 7 values.
+  @param    p    Array of 7 pixelvalues
+  @return    Median of the input values.
+  @doc
+
+  Found on sci.image.processing. Cannot go faster unless some
+  assumptions are made about the nature of the input signal, or the
+  underlying hardware.
+
+  The input array is modified.
+ */
+
+pixelvalue
+sinfo_opt_med7(
+    pixelvalue  *   p
+)
+{
+    PIX_SORT(p[0], p[5]) ; PIX_SORT(p[0], p[3]) ; PIX_SORT(p[1], p[6]) ;
+    PIX_SORT(p[2], p[4]) ; PIX_SORT(p[0], p[1]) ; PIX_SORT(p[3], p[5]) ;
+    PIX_SORT(p[2], p[6]) ; PIX_SORT(p[2], p[3]) ; PIX_SORT(p[3], p[6]) ;
+    PIX_SORT(p[4], p[5]) ; PIX_SORT(p[1], p[4]) ; PIX_SORT(p[1], p[3]) ;
+    PIX_SORT(p[3], p[4]) ; return (p[3]) ;
+}
+
+/**
+  @name        sinfo_opt_med9
+  @memo        Optimized search of the sinfo_median of 9 values.
+  @param    p    Array of 9 pixelvalues
+  @return    Median of the input values.
+  @doc
+
+  Formula from:
+  \begin{verbatim}
+  XILINX XCELL magazine, vol. 23 by John L. Smith
+  \end{verbatim}
+
+  The result array is guaranteed to contain the sinfo_median value in middle
+  position, but other elements are NOT sorted.
+
+  The input array is modified.
+ */
+
+pixelvalue
+sinfo_opt_med9(
+    pixelvalue  *   p
+)
+{
+    PIX_SORT(p[1], p[2]) ; PIX_SORT(p[4], p[5]) ; PIX_SORT(p[7], p[8]) ;
+    PIX_SORT(p[0], p[1]) ; PIX_SORT(p[3], p[4]) ; PIX_SORT(p[6], p[7]) ;
+    PIX_SORT(p[1], p[2]) ; PIX_SORT(p[4], p[5]) ; PIX_SORT(p[7], p[8]) ;
+    PIX_SORT(p[0], p[3]) ; PIX_SORT(p[5], p[8]) ; PIX_SORT(p[4], p[7]) ;
+    PIX_SORT(p[3], p[6]) ; PIX_SORT(p[1], p[4]) ; PIX_SORT(p[2], p[5]) ;
+    PIX_SORT(p[4], p[7]) ; PIX_SORT(p[4], p[2]) ; PIX_SORT(p[6], p[4]) ;
+    PIX_SORT(p[4], p[2]) ; return(p[4]) ;
+}
+
+/**
+  @name        sinfo_opt_med25
+  @memo        Optimized search of the sinfo_median of 25 values.
+  @param    p    Array of 25 pixelvalues
+  @return    Median of the input values.
+  @doc
+
+  Formula from:
+  \begin{verbatim}
+  Graphic Gems source code
+  \end{verbatim}
+
+  The result array is guaranteed to contain the sinfo_median value in middle
+  position, but other elements are NOT sorted.
+
+  The input array is modified.
+ */
+ 
+pixelvalue
+sinfo_opt_med25(
+    pixelvalue  *   p
+)
+{ 
+    PIX_SORT(p[0], p[1]) ;   PIX_SORT(p[3], p[4]) ;   PIX_SORT(p[2], p[4]) ;
+    PIX_SORT(p[2], p[3]) ;   PIX_SORT(p[6], p[7]) ;   PIX_SORT(p[5], p[7]) ;
+    PIX_SORT(p[5], p[6]) ;   PIX_SORT(p[9], p[10]) ;  PIX_SORT(p[8], p[10]) ;
+    PIX_SORT(p[8], p[9]) ;   PIX_SORT(p[12], p[13]) ; PIX_SORT(p[11], p[13]) ;
+    PIX_SORT(p[11], p[12]) ; PIX_SORT(p[15], p[16]) ; PIX_SORT(p[14], p[16]) ;
+    PIX_SORT(p[14], p[15]) ; PIX_SORT(p[18], p[19]) ; PIX_SORT(p[17], p[19]) ;
+    PIX_SORT(p[17], p[18]) ; PIX_SORT(p[21], p[22]) ; PIX_SORT(p[20], p[22]) ;
+    PIX_SORT(p[20], p[21]) ; PIX_SORT(p[23], p[24]) ; PIX_SORT(p[2], p[5]) ;
+    PIX_SORT(p[3], p[6]) ;   PIX_SORT(p[0], p[6]) ;   PIX_SORT(p[0], p[3]) ;
+    PIX_SORT(p[4], p[7]) ;   PIX_SORT(p[1], p[7]) ;   PIX_SORT(p[1], p[4]) ;
+    PIX_SORT(p[11], p[14]) ; PIX_SORT(p[8], p[14]) ;  PIX_SORT(p[8], p[11]) ;
+    PIX_SORT(p[12], p[15]) ; PIX_SORT(p[9], p[15]) ;  PIX_SORT(p[9], p[12]) ;
+    PIX_SORT(p[13], p[16]) ; PIX_SORT(p[10], p[16]) ; PIX_SORT(p[10], p[13]) ;
+    PIX_SORT(p[20], p[23]) ; PIX_SORT(p[17], p[23]) ; PIX_SORT(p[17], p[20]) ;
+    PIX_SORT(p[21], p[24]) ; PIX_SORT(p[18], p[24]) ; PIX_SORT(p[18], p[21]) ;
+    PIX_SORT(p[19], p[22]) ; PIX_SORT(p[8], p[17]) ;  PIX_SORT(p[9], p[18]) ;
+    PIX_SORT(p[0], p[18]) ;  PIX_SORT(p[0], p[9]) ;   PIX_SORT(p[10], p[19]) ;
+    PIX_SORT(p[1], p[19]) ;  PIX_SORT(p[1], p[10]) ;  PIX_SORT(p[11], p[20]) ;
+    PIX_SORT(p[2], p[20]) ;  PIX_SORT(p[2], p[11]) ;  PIX_SORT(p[12], p[21]) ;
+    PIX_SORT(p[3], p[21]) ;  PIX_SORT(p[3], p[12]) ;  PIX_SORT(p[13], p[22]) ;
+    PIX_SORT(p[4], p[22]) ;  PIX_SORT(p[4], p[13]) ;  PIX_SORT(p[14], p[23]) ;
+    PIX_SORT(p[5], p[23]) ;  PIX_SORT(p[5], p[14]) ;  PIX_SORT(p[15], p[24]) ;
+    PIX_SORT(p[6], p[24]) ;  PIX_SORT(p[6], p[15]) ;  PIX_SORT(p[7], p[16]) ;
+    PIX_SORT(p[7], p[19]) ;  PIX_SORT(p[13], p[21]) ; PIX_SORT(p[15], p[23]) ;
+    PIX_SORT(p[7], p[13]) ;  PIX_SORT(p[7], p[15]) ;  PIX_SORT(p[1], p[9]) ;
+    PIX_SORT(p[3], p[11]) ;  PIX_SORT(p[5], p[17]) ;  PIX_SORT(p[11], p[17]) ;
+    PIX_SORT(p[9], p[17]) ;  PIX_SORT(p[4], p[10]) ;  PIX_SORT(p[6], p[12]) ;
+    PIX_SORT(p[7], p[14]) ;  PIX_SORT(p[4], p[6]) ;   PIX_SORT(p[4], p[7]) ;
+    PIX_SORT(p[12], p[14]) ; PIX_SORT(p[10], p[14]) ; PIX_SORT(p[6], p[7]) ;
+    PIX_SORT(p[10], p[12]) ; PIX_SORT(p[6], p[10]) ;  PIX_SORT(p[6], p[17]) ;
+    PIX_SORT(p[12], p[17]) ; PIX_SORT(p[7], p[17]) ;  PIX_SORT(p[7], p[10]) ;
+    PIX_SORT(p[12], p[18]) ; PIX_SORT(p[7], p[12]) ;  PIX_SORT(p[10], p[18]) ;
+    PIX_SORT(p[12], p[20]) ; PIX_SORT(p[10], p[20]) ; PIX_SORT(p[10], p[12]) ;
+ 
+    return (p[12]);
+} 
+
+#undef PIX_SORT
+#undef PIX_SWAP
+
+/**
+  @name        sinfo_median_pixelvalue
+  @memo        Compute the sinfo_median pixel value of an array.
+  @param    a    Array to consider.
+  @param    n    Number of pixels in the array.
+  @return    The sinfo_median of the array.
+  @doc
+
+  This is the generic method that should be called to get the sinfo_median
+  out of an array of pixelvalues. It calls in turn the most efficient
+  method depending on the number of values in the array.
+
+  The input array is always modified.
+ */
+
+pixelvalue 
+sinfo_median_pixelvalue(pixelvalue * a, int n)
+{
+    pixelvalue    sinfo_median ;
+
+    switch(n) {
+        case 3:
+        sinfo_median = sinfo_opt_med3(a);
+        break ;
+
+        case 5:
+        sinfo_median = sinfo_opt_med5(a);
+        break ;
+
+        case 7:
+        sinfo_median = sinfo_opt_med7(a);
+        break ;
+
+        case 9:
+        sinfo_median = sinfo_opt_med9(a);
+        break ;
+
+        case 25:
+        sinfo_median = sinfo_opt_med25(a);
+        break ;
+
+        default:
+        sinfo_median = median_WIRTH(a,n);
+        break ;
+    }
+    return sinfo_median;
+}
+
+/**@}*/
diff --git a/sinfoni/sinfo_median.h b/sinfoni/sinfo_median.h
new file mode 100644
index 0000000..6ce64f0
--- /dev/null
+++ b/sinfoni/sinfo_median.h
@@ -0,0 +1,221 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*---------------------------------------------------------------------------
+   
+   File name     :    sinfo_median.h
+   Author         :    N. Devillard
+   Created on    :    1998
+   Description    :    Fast sinfo_median finding routines
+ *--------------------------------------------------------------------------*/
+/*
+    $Id: sinfo_median.h,v 1.3 2007/06/06 07:10:45 amodigli Exp $
+    $Author: amodigli $
+    $Date: 2007/06/06 07:10:45 $
+    $Revision: 1.3 $
+*/
+#ifndef SINFO_MEDIAN_H
+#define SINFO_MEDIAN_H
+
+
+/*---------------------------------------------------------------------------
+                                   Includes
+ ---------------------------------------------------------------------------*/
+
+/* Get the definition of a pixelvalue */
+#include "sinfo_local_types.h"
+
+/*---------------------------------------------------------------------------
+                               Function prototypes
+ ---------------------------------------------------------------------------*/
+/**
+  @name     sinfo_kth_smallest
+  @memo     Find the kth smallest element in an array.
+  @param    a   Array to consider for sinfo_median search.
+  @param    n   Number of elements in the array.
+  @param    k   Rank of the element to find (between 0 and n-1).
+  @return   One element from the array.
+  @doc
+ 
+  Provide an array of n pixelvalues and the rank of the value you want
+  to find. A rank of 0 means the minimum element, a rank of n-1 is the
+  maximum element, and a rank of n/2 is the sinfo_median. Use the
+  median_WIRTH macro to find the sinfo_median directly.
+ 
+  NB: The input array is modified. Some elements are swapped, until
+  the requested value is found. The array is left in an undefined
+  sorted state.
+ 
+  This algorithm was taken from the following book:
+  \begin{verbatim}
+                Author: Wirth, Niklaus
+                 Title: Algorithms + data structures = programs
+             Publisher: Englewood Cliffs: Prentice-Hall, 1976
+  Physical description: 366 p.
+                Series: Prentice-Hall Series in Automatic Computation
+  \end{verbatim}
+ */
+/*--------------------------------------------------------------------------*/
+
+pixelvalue 
+sinfo_kth_smallest(pixelvalue a[], int n, int k);
+
+/**
+  @name     sinfo_kth_smallest_double
+  @memo     Find the kth smallest element in a double array.
+  @param    a   Array to consider for sinfo_median search.
+  @param    n   Number of elements in the array.
+  @param    k   Rank of the element to find (between 0 and n-1).
+  @return   One element from the array.
+  @doc
+ 
+  See sinfo_kth_smallest() function in the same file.
+ 
+  NB: THE INPUT ARRAY IS MODIFIED.
+ */
+
+double 
+sinfo_kth_smallest_double(double a[], int n, int k) ;
+
+#define median_double(a,n) \
+sinfo_kth_smallest_double(a,n,(((n)&1)?((n)/2):(((n)/2)-1)))
+
+/**
+  @name     sinfo_opt_med3
+  @memo     Optimized search of the sinfo_median of 3 values.
+  @param    p   Array of 3 pixelvalues
+  @return   Median of the input values.
+  @doc
+ 
+  Found on sci.image.processing. Cannot go faster unless some
+  assumptions are made about the nature of the input signal, or the
+  underlying hardware.
+ 
+  The input array is modified.
+ */
+
+pixelvalue
+sinfo_opt_med3(
+    pixelvalue  *   p
+) ;
+
+/**
+  @name     sinfo_opt_med5
+  @memo     Optimized search of the sinfo_median of 5 values.
+  @param    p   Array of 5 pixelvalues
+  @return   Median of the input values.
+  @doc
+ 
+  Found on sci.image.processing. Cannot go faster unless some
+  assumptions are made about the nature of the input signal, or the
+  underlying hardware.
+ 
+  The input array is modified.
+ */
+
+pixelvalue
+sinfo_opt_med5(
+    pixelvalue  *   p
+);
+
+
+/**
+  @name     sinfo_opt_med7
+  @memo     Optimized search of the sinfo_median of 7 values.
+  @param    p   Array of 7 pixelvalues
+  @return   Median of the input values.
+  @doc
+ 
+  Found on sci.image.processing. Cannot go faster unless some
+  assumptions are made about the nature of the input signal, or the
+  underlying hardware.
+ 
+  The input array is modified.
+ */
+
+pixelvalue
+sinfo_opt_med7(
+    pixelvalue  *   p
+) ;
+
+/**
+  @name     sinfo_opt_med9
+  @memo     Optimized search of the sinfo_median of 9 values.
+  @param    p   Array of 9 pixelvalues
+  @return   Median of the input values.
+  @doc
+ 
+  Formula from:
+  \begin{verbatim}
+  XILINX XCELL magazine, vol. 23 by John L. Smith
+  \end{verbatim}
+ 
+  The result array is guaranteed to contain the sinfo_median value in middle
+  position, but other elements are NOT sorted.
+ 
+  The input array is modified.
+ */
+
+pixelvalue
+sinfo_opt_med9(
+    pixelvalue  *   p
+) ;
+
+/**
+  @name     sinfo_opt_med25
+  @memo     Optimized search of the sinfo_median of 25 values.
+  @param    p   Array of 25 pixelvalues
+  @return   Median of the input values.
+  @doc
+ 
+  Formula from:
+  \begin{verbatim}
+  Graphic Gems source code
+  \end{verbatim}
+ 
+  The result array is guaranteed to contain the sinfo_median value in middle
+  position, but other elements are NOT sorted.
+ 
+  The input array is modified.
+ */
+
+pixelvalue
+sinfo_opt_med25(
+    pixelvalue  *   p
+) ;
+
+
+/**
+  @name     sinfo_median_pixelvalue
+  @memo     Compute the sinfo_median pixel value of an array.
+  @param    a   Array to consider.
+  @param    n   Number of pixels in the array.
+  @return   The sinfo_median of the array.
+  @doc
+ 
+  This is the generic method that should be called to get the sinfo_median
+  out of an array of pixelvalues. It calls in turn the most efficient
+  method depending on the number of values in the array.
+ 
+  The input array is always modified.
+ */
+
+pixelvalue 
+sinfo_median_pixelvalue(pixelvalue * a, int n);
+
+#endif
diff --git a/sinfoni/sinfo_merge.c b/sinfoni/sinfo_merge.c
new file mode 100644
index 0000000..800cad9
--- /dev/null
+++ b/sinfoni/sinfo_merge.c
@@ -0,0 +1,1048 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/************************************************************************
+* E.S.O. - VLT project
+*
+* 
+*
+* who       when      what
+* --------  --------  ----------------------------------------------
+* schreib  04/07/00  created
+*/
+
+/************************************************************************
+*   NAME              
+*        sinfo_merge.c - merges the rows of two image data frames into
+*                  one frame with doubled column length     
+*        
+*   SYNOPSIS
+*   #include "merge.h"
+*
+*   a) cpl_image * sinfo_sinfo_merge_images ( cpl_image * im1, 
+*                               cpl_image * im2, 
+*                               cpl_image * res_image )
+*
+*   1) cpl_image * sinfo_new_remove_general_offset( cpl_image * im1, 
+*                                      cpl_image * im2, 
+*                                      cpl_image * res_image, 
+*                                      int n )
+*
+*   2) cpl_image * sinfo_new_remove_regional_tilt ( cpl_image * im1,
+*                                      cpl_image * im2, 
+*                                      cpl_image * res_image )
+*
+*   3) cpl_image * sinfo_new_remove_column_offset ( cpl_image * im1, 
+*                                      cpl_image * im2, 
+*                                      cpl_image * res_image )
+*
+*   4) cpl_image * sinfo_new_remove_residual_tilt ( cpl_image * im2, 
+                                                   cpl_image * res_image )
+*
+*   5) cpl_image * sinfo_new_remove_residual_offset( cpl_image * im2, 
+                                                    cpl_image * res_image )
+*
+*   DESCRIPTION
+*   a) merges the rows of two image frames in a way that the resulting
+*      image has double length in y-direction
+*
+*        The procedures are used in the SPIFFI data reduction to merge two 
+*        data frames. In order to fully match the two input frames there
+*        are five steps (procedures) foreseen:
+*        1) remove general offset between the frames, created by e.g. different
+*           air masses. 
+*        2) remove regional tilt between frames, created by e.g. different 
+*           emissivities.
+*        3) remove individual column offsets, created e.g. by imperfect 
+*           guiding, offset is divided out.
+*        4) remove residual individual column tilts, created by previous 
+*           operations.
+*        5) remove residual column offsets by subtracting the sinfo_median.
+*
+*   FILES
+*
+*   ENVIRONMENT
+*
+*   RETURN VALUES 
+*   always the pointer to the image data structure cpl_image
+*
+*   CAUTIONS 
+*
+*   EXAMPLES
+*
+*   SEE ALSO
+*   Python script merging.py
+*
+*   BUGS   
+*
+*------------------------------------------------------------------------
+*/
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+#include "sinfo_vltPort.h"
+
+/* 
+ * System Headers
+ */
+
+/* 
+ * Local Headers
+ */
+
+#include "sinfo_merge.h"
+#include "sinfo_globals.h"
+/**@{*/
+/**
+ * @addtogroup sinfo_utilities merging functions
+ *
+ * TBD
+ */
+
+/**
+ at brief merges the rows of two image frames in a way that the resulting 
+       image has double length in y-direction
+ @name sinfo_sinfo_merge_images()
+ @param im1 image to merge,
+ @param im2 image to merge 
+ @param  res_image dummy for residual image
+ @note: first must have smaller wavelength than the 
+        second for the same pixel row.
+ @return resulting merged image, final residual image
+ */
+
+cpl_image * sinfo_sinfo_merge_images ( cpl_image * im1, 
+                         cpl_image * im2, 
+                         cpl_image * res_image )
+{
+    cpl_image * out_image ;
+    cpl_image * residual ;
+    int i, j ;
+
+    int lx1=0;
+    int ly1=0;
+    int lx2=0;
+    int ly2=0;
+
+
+    float* pi1data=NULL;
+    float* pi2data=NULL;
+    float* pirdata=NULL;
+    float* poutdata=NULL;
+    float* ptmpdata=NULL;
+
+
+
+    if ( im1 == NULL || im2 == NULL || res_image == NULL)
+    {
+        sinfo_msg_error (" null image as input") ;
+        return NULL ;
+    }
+    lx1=cpl_image_get_size_x(im1);
+    ly1=cpl_image_get_size_y(im1);
+
+    lx2=cpl_image_get_size_x(im2);
+    ly2=cpl_image_get_size_y(im2);
+
+
+
+    pi1data=cpl_image_get_data_float(im1);
+    pi2data=cpl_image_get_data_float(im2);
+    pirdata=cpl_image_get_data_float(res_image);
+
+
+    if ( lx1 != lx2 || ly1 != ly2 )
+    {
+        sinfo_msg_error ("input images are not compatible in size") ;
+        return NULL ;
+    }
+
+    /* allocate memory */
+    if ( NULL == (out_image = cpl_image_new (lx1, 2 * ly1,CPL_TYPE_FLOAT)) )
+    {
+        sinfo_msg_error (" cannot allocate new image") ;
+        return NULL ;
+    }
+    poutdata=cpl_image_get_data_float(out_image);
+
+    if ( NULL == (residual = cpl_image_new (lx1, ly1,CPL_TYPE_FLOAT)) )
+    {
+        sinfo_msg_error (" cannot allocate new image ") ;
+        return NULL ;
+    }
+    ptmpdata=cpl_image_get_data_float(residual);
+
+    /* now compute the final residual image */
+    for ( i = 0 ; i < (int) lx1*ly1 ; i ++ )
+    {
+        if ( isnan(pi1data[i]) || isnan(pi2data[i]) )
+        {
+            ptmpdata[i] = ZERO ;
+        }   
+        else
+        {
+            ptmpdata[i] = pi1data[i] - pi2data[i] ;
+        }
+        pirdata[i] = ptmpdata[i] ;
+    }
+
+    /* now merge the two images */
+    for ( i = 0 ; i < ly1 ; i ++ )
+    {
+        for ( j = 0 ; j < lx1 ; j ++ )
+        {
+            /* transfer rows to output */
+            poutdata[2*i*lx1 + j] = pi1data[i*lx1 + j]  ;
+            poutdata[(2*i+1) * lx1 + j] = pi2data[i*lx1 + j] ;
+        }     
+    }
+
+    cpl_image_delete (residual) ;
+
+    return out_image ;
+}
+    
+
+/**
+ at brief removes the offset between two images
+ at name sinfo_new_remove_general_offset()
+ at param im1 
+ at param im2 two images, 
+ at param res_image result image
+ at param n number of rows from which the offset is determined.
+
+ at return changed second image, residual image if wanted or needed
+
+ at doc       
+adds general offset between two frames to the second image and delivers the 
+residual image, assuming that the background cancellation did 
+not work perfectly well.
+ */
+
+cpl_image * sinfo_new_remove_general_offset( cpl_image * im1, 
+                                cpl_image * im2, 
+                                cpl_image * res_image, 
+                                int n )
+{
+    cpl_image * out_image ;
+    cpl_image * residual  ;
+    pixelvalue sum, sqr_sum ;
+    pixelvalue mean, stdev  ;
+    int i, npix ;
+
+    int lx1=0;
+    int ly1=0;
+    int lx2=0;
+    int ly2=0;
+    int lxr=0;
+    int lyr=0;
+    int lxt=0;
+    int lyt=0;
+
+    float* pi1data=NULL;
+    float* pi2data=NULL;
+    float* pirdata=NULL;
+    float* poutdata=NULL;
+    float* ptmpdata=NULL;
+
+
+
+    if ( im1 == NULL || im2 == NULL )
+    {
+        sinfo_msg_error (" null image as input") ;
+        return NULL ;
+    }
+    lx1=cpl_image_get_size_x(im1);
+    ly1=cpl_image_get_size_y(im1);
+
+    lx2=cpl_image_get_size_x(im2);
+    ly2=cpl_image_get_size_y(im2);
+
+
+
+    pi1data=cpl_image_get_data_float(im1);
+    pi2data=cpl_image_get_data_float(im2);
+
+
+    if ( lx1 != lx2 || ly1 != ly2 )
+    {
+        sinfo_msg_error (" input images are not compatible in size") ;
+        return NULL ;
+    }
+    
+    if ( n <= 0 )
+    {
+        sinfo_msg_error("number of rows for offset determination "
+                        "is 0 or smaller ") ;
+        return NULL ;
+    }
+        
+    /* allocate memory */
+    if ( NULL == (residual = cpl_image_new (lx1, ly1, CPL_TYPE_FLOAT)) )
+    {
+        sinfo_msg_error (" cannot allocate new image ") ;
+        return NULL ;
+    }
+       
+    out_image = cpl_image_duplicate( im2 ) ;
+    poutdata=cpl_image_get_data_float(out_image);
+    ptmpdata=cpl_image_get_data_float(residual);
+    lxt=cpl_image_get_size_x(residual);
+    lyt=cpl_image_get_size_y(residual);
+
+    /* ---------------------------------------------------------------------
+     * first we determine the "good" pixels and subtract the two images 
+     * then we determine the mean and 3 sigma
+     */
+
+    sum = 0. ;
+    sqr_sum = 0. ;
+    npix = 0 ;
+    for ( i = 0 ; i < (int) lx1*ly1 ; i ++ )
+    {
+        if ( isnan(pi1data[i]) || isnan(pi2data[i]) )
+        {
+            ptmpdata[i] = ZERO ;
+            continue ;
+        }   
+        else
+        {
+            ptmpdata[i] = pi1data[i] - pi2data[i] ;
+        }
+
+        sum += ptmpdata[i] ;
+        sqr_sum += (ptmpdata[i]) * (ptmpdata[i]) ;
+        npix ++ ;
+    }
+    if ( npix <= 1 )
+    {
+        mean = 0. ;
+        stdev = 0. ;
+    }
+    else
+    {
+        mean = sum / (pixelvalue) npix ;   
+        /* stdev is 3 sigma */
+        stdev = 3 * sqrt(( sqr_sum - sum*mean ) / (pixelvalue)(npix - 1)) ;
+    }
+    
+    /* exclude everything > 3 sigma */
+    
+    for ( i = 0 ; i < (int) lxt*lyt ; i++ )
+    {
+        if ( fabs( ptmpdata[i] - mean ) > stdev )
+        {
+            ptmpdata[i] = ZERO ;
+        }
+    }
+    
+    /* now subtract the general offset which is determined 
+       as mean of the first n rows */
+    
+    sum = 0. ;
+    npix = 0 ;
+    for ( i = 0 ; i < n * lxt ; i++ )
+    {
+        if ( isnan(ptmpdata[i]) )
+        {
+            continue ;
+        }
+
+        sum += ptmpdata[i] ;
+        npix ++ ;
+    }
+    if ( npix == 0 )
+    {
+        mean = 0. ;
+    }
+    else
+    {
+        mean = sum / (pixelvalue) npix ;      
+    } 
+    
+    /* now apply this to the second input image */
+    for ( i = 0 ; i < (int) lx2*ly2 ; i++ )
+    {
+        if ( isnan(pi2data[i]) )
+        {
+            poutdata[i] = ZERO ;
+            continue ;
+        }
+        poutdata[i] = pi2data[i] + mean ;
+    }    
+ 
+    /* now determine the residual image if available */
+    if ( res_image != NULL )
+    {
+
+       lxr=cpl_image_get_size_x(res_image);
+       lyr=cpl_image_get_size_y(res_image);
+       pirdata=cpl_image_get_data_float(res_image);
+
+
+        for ( i = 0 ; i < (int) lxt*lyt ; i++ )
+        {
+            if ( isnan(ptmpdata[i]) )
+            {
+                pirdata[i] = ZERO ;
+                continue ;
+            }
+            pirdata[i] = ptmpdata[i] - mean ;
+        }
+    }    
+
+    cpl_image_delete (residual) ;
+
+    return out_image ;
+}
+
+/**
+ at brief removes a general tilt from the spectra , created e.g. 
+       by different emissivities of the telescope itself and
+       delivers the residual image
+   @name sinfo_new_remove_regional_tilt()
+   @param im1 
+   @param im2 both images to merge, 
+   @param res_image residual image (obligatory no NULL).
+   @return changed second image, residual image 
+    
+ */
+
+cpl_image * sinfo_new_remove_regional_tilt ( cpl_image * im1, 
+                                cpl_image * im2, 
+                                cpl_image * res_image )
+{
+    cpl_image * out_image ;
+    cpl_image * filtered  ;
+    int i, j, k, npix, nrunning ;
+    pixelvalue a, b, sum, sumx, sumy, sumc, sum2 ;
+    int lx1=0;
+    int ly1=0;
+    int lx2=0;
+    int ly2=0;
+    int lxr=0;
+    int lyr=0;
+    int lxf=0;
+    int lyf=0;
+
+    float* pi1data=NULL;
+    float* pi2data=NULL;
+    float* pirdata=NULL;
+    float* poutdata=NULL;
+    float* pfildata=NULL;
+
+
+    if ( im1 == NULL || im2 == NULL || res_image == NULL )
+    {
+        sinfo_msg_error ("null image as input") ;
+        return NULL ;
+    }
+    lx1=cpl_image_get_size_x(im1);
+    ly1=cpl_image_get_size_y(im1);
+
+    lx2=cpl_image_get_size_x(im2);
+    ly2=cpl_image_get_size_y(im2);
+
+    lxr=cpl_image_get_size_x(res_image);
+    lyr=cpl_image_get_size_y(res_image);
+
+
+    pi1data=cpl_image_get_data_float(im1);
+    pi2data=cpl_image_get_data_float(im2);
+    pirdata=cpl_image_get_data_float(res_image);
+
+    if ( lx1 != lx2 || ly1 != ly2 ||
+         lx2 != lxr || ly2 != lyr )
+    {
+        sinfo_msg_error ("input images are not compatible in size") ;
+        return NULL ;
+    }
+
+    /* allocate memory */
+    if ( NULL == ( filtered = cpl_image_new (lx2, ly2,CPL_TYPE_FLOAT)) )
+    {
+        sinfo_msg_error ("cannot allocate new image ") ;
+        return NULL ;
+    }
+
+    out_image = cpl_image_duplicate( im2 ) ;
+    poutdata=cpl_image_get_data_float(out_image);
+    pfildata=cpl_image_get_data_float(filtered);
+    lxf=cpl_image_get_size_x(filtered);
+    lyf=cpl_image_get_size_y(filtered);
+    
+    /*-------------------------------------------------------------------------
+     * Now work in the given difference image res_image on each 
+       column separately. This image is first smoothed columnwise 
+       by a running box
+     */
+    
+    nrunning = 31 ; /* # of points in the running box, odd number required */
+
+    for ( j = 0 ; j < lyr ; j ++ ) /* select a row */
+    {
+        for ( i = 0 ; i < lxr ; i ++ ) /* go through one row */
+        {
+            npix = 0 ;
+            sum = 0. ;
+            for (k = i - (nrunning-1)/2 ; k < i + (nrunning+1)/2; k ++ )
+            {
+                /* marginal pixels are not considered */
+                if ( k < 2 )
+                {
+                    continue ;
+                }
+                if ( k > (lxr) - 2 )
+                {
+                    break ;
+
+                }
+                if ( isnan(pirdata[j*lxr + k]) )
+                {
+                    continue ;
+                }
+                npix ++ ;
+                sum += pirdata[j*lxr + k] ;
+            }
+            if ( npix != 0 )
+            {
+                pfildata[j*lxr + i] = sum/npix ;
+            }
+            else
+            {
+                pfildata[j*lxr + i] = ZERO ;
+            }
+        }
+    }                  
+   
+    /*------------------------------------------------------------------
+     * now determine the tilt in each column and remove it in such a way
+     * that the first rows are used as references that are not changed
+     * a free regression fit is (index i means the sum over i):
+     * ax + b: a = [<xiyi>-<xi><yi>]/[<xi^2>-<xi>^2]
+     * =>    : a = [xiyi - xi<yi>]/[xi^2 - xi<xi>]
+     *         b = <yi> - a<xi>
+     */
+    
+    for ( i = 0 ; i < lxf ; i ++ ) /* one column selected */
+    {
+        sumy = 0. ;                   /* yi   */
+        sumc = 0. ;                   /* xiyi */
+        sumx = 0. ;                   /* xi   */
+        sum2 = 0. ;                   /* xi^2 */
+        npix = 0  ;  
+          
+        for ( j = 0 ; j < lyf ; j ++ ) 
+        {
+            if ( isnan(pfildata[i + j*lxf]) )
+            {
+                continue ;
+            }
+            sumy +=  pfildata[i + j*lxf] ;
+            sumc += (pfildata[i + j*lxf]) * j ;
+            sum2 += j*j ;
+            sumx += j   ;
+            npix ++     ;
+        }
+        if ( npix > 2 && fabs(sum2 - sumx*sumx/npix) >= 1e-6 ) 
+        {
+            a = ( sumc - sumx*sumy/npix ) / ( sum2 - sumx*sumx/npix ) ;
+            b = ( sumy - a*sumx ) / npix ;
+        } 
+        else
+        {
+            a = ZERO ;
+            b = ZERO ;
+        }
+
+        /*-----------------------------------------------------------
+         * now correct the second input image im2 and the res_image.
+         */ 
+
+        if ( !isnan(a) && !isnan(b) && fabs(a) < 1e8 && fabs(b) < 1e8 )
+        {
+            for ( j = 0 ; j < lyf ; j ++ ) /* the same column */
+            {
+                if ( !isnan(poutdata[i + j*lxf]) )
+                {
+                    poutdata[i + j*lxf] += a*j+b ;        
+                }
+            }
+        }
+    }
+   
+    /* now compute the final residual image */
+    for ( i = 0 ; i < (int) lx1*ly1 ; i ++ )
+    {
+        if ( isnan(pi1data[i]) || isnan(poutdata[i]) )
+        {
+            pirdata[i] = ZERO ;
+        }   
+        else
+        {
+            pirdata[i] = pi1data[i] - poutdata[i] ;
+        }
+    }
+
+    cpl_image_delete (filtered) ;
+   
+    return out_image ;
+}
+
+
+/**
+ at brief removes individual column offset, created e.g. by imperfect guiding. 
+       The offset is divided out. The ratio is derived from the medians of 
+       the contributions.
+   @name  sinfo_new_remove_column_offset()
+   @param im1 first image 
+   @param im2 already corrected second image to merge, 
+   @param res_image residual image (obligatory no NULL).
+   @return changed second image, residual image 
+   
+ */
+
+cpl_image * sinfo_new_remove_column_offset ( cpl_image * im1, 
+                                cpl_image * im2, 
+                                cpl_image * res_image )
+{
+    cpl_image * out_image ;
+    int i, j, npix, nrunning ;
+    pixelvalue sum, sum2, mean, stdev, median1, median2, ratio ;
+    pixelvalue * column1, * column2 ;
+    int lx1=0;
+    int ly1=0;
+    int lx2=0;
+    int ly2=0;
+    int lxr=0;
+    int lyr=0;
+    float* pi1data=NULL;
+    float* pi2data=NULL;
+    float* pirdata=NULL;
+    float* poutdata=NULL;
+
+    if ( im1 == NULL || im2 == NULL || res_image == NULL )
+    {
+        sinfo_msg_error ("null image as input") ;
+        return NULL ;
+    }
+    lx1=cpl_image_get_size_x(im1);
+    ly1=cpl_image_get_size_y(im1);
+
+    lx2=cpl_image_get_size_x(im2);
+    ly2=cpl_image_get_size_y(im2);
+
+    lxr=cpl_image_get_size_x(res_image);
+    lyr=cpl_image_get_size_y(res_image);
+
+
+    pi1data=cpl_image_get_data_float(im1);
+    pi2data=cpl_image_get_data_float(im2);
+    pirdata=cpl_image_get_data_float(res_image);
+
+    if ( lx1 != lx2 || ly1 != ly2 ||
+         lx2 != lxr || ly2 != lyr )
+    {
+        sinfo_msg_error ("input images are not compatible in size") ;
+        return NULL ;
+    }
+
+    out_image = cpl_image_duplicate( im2 ) ;
+    poutdata=cpl_image_get_data_float(out_image);
+
+    /*------------------------------------------------------------------------- 
+     *  now we deal with a constant offset in every column. We assume that it 
+        is due to redistribution of the flux. So we should divide the offset 
+        out.  The ratio is derived from the medians of the contributions 
+        rather than the means.
+     */
+
+    for ( i = 0 ; i < lx2 ; i ++ ) /* select a column */
+    {
+        /* statistics on columns */
+        sum  = 0.  ;
+        sum2 = 0. ;
+        npix = 0  ;
+        for ( j = 0 ; j < ly2 ; j ++ )
+        {
+            /* first select only the good pixels */
+            if ( isnan(pirdata[i + j*lxr]) )
+            {
+                continue ;
+            }
+            sum  += pirdata[i + j*lxr] ;
+            sum2 += pirdata[i + j*lxr] * 
+                    pirdata[i + j*lxr] ; 
+            npix ++ ;
+        }
+        if ( npix <= 1 )
+        {
+            continue ;
+        }
+        else
+        {
+            mean  = sum/(pixelvalue) npix ;
+            if ( (sum2 - sum * mean) < 0 )
+            {
+                sinfo_msg_error ("variance is negative") ; 
+                continue ;
+            }
+            else
+            {
+                /* 2 sigma */
+                stdev = 2 * sqrt ( (sum2 - sum*mean)/(pixelvalue)(npix - 1) ) ;
+            }
+        }
+
+        /* do it only if the S/N is high enough */
+        if ( fabs(mean)/stdev < 0.5 )
+        {
+            continue ;
+        }
+
+        /* exclude everything > 2 sigma */
+        for ( j = 0 ; j < lyr ; j ++ )
+        {
+            if ( pirdata[i + j*lxr] < mean - stdev ||
+                 pirdata[i + j*lxr] > mean + stdev )
+            {
+                pirdata[i + j*lxr] = ZERO ;
+            }
+        } 
+        
+        /* now deal with the offset */
+        median1 = 0. ;
+        median2 = 0. ;
+        nrunning = 0 ;
+        /* allocate memory for the column buffers */
+        column1 = (pixelvalue *) cpl_calloc ( ly1 , sizeof (pixelvalue *) ) ;
+        column2 = (pixelvalue *) cpl_calloc ( ly2 , sizeof (pixelvalue *) ) ; 
+
+        for ( j = 0 ; j < lyr ; j++ ) /* go through one column */
+        {
+            if ( isnan(pirdata[i + j*lxr]) )
+            {
+                continue ;
+            }
+            if ( isnan(pi1data[i+j*lx1]) || isnan(pi2data[i+j*lx2]) )
+            {
+                continue ;
+            }
+        column1[nrunning] = pi1data[i + j*lx1] ;
+            column2[nrunning] = pi2data[i + j*lx2] ;
+            nrunning ++ ;
+        }
+
+        /* change the second input image only if there are more then 
+           10 % good pixels in a column */
+        if ( nrunning > 0.1*lyr )
+        {
+            /* --------------------------------------------------------------
+             * determine the medians of the columns of both images and compute 
+               the ratio, the columns of the second input image are multiplied 
+               by this ratio to adjust the column offsets. 
+             */
+            median2 = sinfo_new_median( column2, nrunning ) ;
+            if ( median2 != 0. )
+            {
+                median1 = sinfo_new_median( column1, nrunning ) ;
+                ratio = median1 / median2 ;
+                if ( ratio > 0 )
+                {
+                    for ( j = 0 ; j < ly2 ; j++ ) /* go through one column */
+                    {
+                        if ( !isnan(pi2data[i + j*lx2]) )
+                        {
+                            poutdata[i + j*lx2] = pi2data[i + j*lx2] * ratio ;
+                        }
+                        else
+                        {
+                            poutdata[i + j*lx2] = ZERO ;
+                        }
+                    }
+                }
+            }
+        }   
+        cpl_free ( column1 ) ;
+        cpl_free ( column2 ) ;
+    }
+
+    /* now compute the final residual image */
+    for ( i = 0 ; i < (int) lx1*ly1 ; i ++ )
+    {
+        if ( isnan(pi1data[i]) || isnan(poutdata[i]) )
+        {
+            pirdata[i] = ZERO ;
+        }   
+        else
+        {
+            pirdata[i] = pi1data[i] - poutdata[i] ;
+        }
+    }
+   
+    return out_image ;
+}
+
+
+/**
+ at brief removes a residual column tilt (determined from the residual image) 
+       created by previous operations
+   @name sinfo_new_remove_residual_tilt()
+   @param im2 second image to merge, 
+   @param res_image residual image (obligatory no NULL).
+   @return changed second image, residual image  
+ */
+
+cpl_image * 
+sinfo_new_remove_residual_tilt ( cpl_image * im2, cpl_image * res_image )
+{
+    cpl_image * out_image ;
+    cpl_image * residual  ;
+    int i, j, npix ;
+    pixelvalue a, b, sum, sumx, sumy, sumc, sum2, mean, stdev ;
+    int lx2=0;
+    int ly2=0;
+    int rlx=0;
+    int rly=0;
+    float* pi2data=NULL;
+    float* pirdata=NULL;
+    float* poutdata=NULL;
+    float* ptmpdata=NULL;
+
+
+
+
+    if ( im2 == NULL || res_image == NULL )
+    {
+        sinfo_msg_error ("null image as input") ;
+        return NULL ;
+    }
+    lx2=cpl_image_get_size_x(im2);
+    ly2=cpl_image_get_size_y(im2);
+    rlx=cpl_image_get_size_x(res_image);
+    rly=cpl_image_get_size_y(res_image);
+    pi2data=cpl_image_get_data_float(im2);
+    pirdata=cpl_image_get_data_float(res_image);
+
+    if ( lx2 != rlx || ly2 != rly )
+    {
+        sinfo_msg_error ("input images are not compatible in size") ;
+        return NULL ;
+    }
+
+    out_image = cpl_image_duplicate( im2 ) ;
+    residual  = cpl_image_duplicate( res_image ) ;
+    poutdata=cpl_image_get_data_float(out_image);
+    ptmpdata=cpl_image_get_data_float(residual);
+
+    for ( i = 0 ; i < lx2; i++ ) /* select one column */
+    {
+        sum  = 0. ;
+        sum2 = 0. ;
+        npix = 0  ;
+        for ( j = 0 ; j < ly2 ; j++ ) 
+        {
+            /* first select good pixels and derive the mean 
+               and sigma of each column */
+            if ( isnan(pirdata[i + j*rlx]) )
+            {
+                continue ;
+            }
+            sum  += pirdata[i + j*rlx] ;
+            sum2 += pirdata[i + j*rlx] *
+                    pirdata[i + j*rlx] ;
+            npix ++ ;
+        }
+        
+        if ( npix <= 1 )
+        {
+            continue ;
+        }
+        else
+        {
+            mean  = sum / (pixelvalue) npix ;
+            stdev = 1.5 * sqrt( (sum2 - sum*mean) / (pixelvalue)(npix - 1) ) ;
+        }
+ 
+        /* exclude everything > 1.5 sigma */
+        for ( j = 0 ; j < ly2 ; j++ )
+        {
+            if ( pirdata[i + j*rlx] < mean - stdev ||
+                 pirdata[i + j*rlx] > mean + stdev )
+            {
+                pirdata[i + j*rlx] = ZERO ;
+            }
+        }
+
+        /* now determine the tilt, see function sinfo_removeRegionalTilt 
+           for explanation */
+        sumy = 0. ;                   /* yi   */
+        sumc = 0. ;                   /* xiyi */
+        sumx = 0. ;                   /* xi   */
+        sum2 = 0. ;                   /* xi^2 */
+        npix = 0  ;  
+          
+        for ( j = 0 ; j < rly ; j ++ ) 
+        {
+            if ( isnan(pirdata[i + j*rlx]) )
+            {
+                continue ;
+            }
+            sumy +=  pirdata[i + j*rlx] ;
+            sumc += (pirdata[i + j*rlx]) * j ;
+            sum2 += j*j ;
+            sumx += j   ;
+            npix ++     ;
+        }
+        if ( npix > 2 && fabs(sum2 - sumx*sumx/npix) >= 1e-6 ) 
+        {
+            a = ( sumc - sumx*sumy/npix ) / ( sum2 - sumx*sumx/npix ) ;
+            b = ( sumy - a*sumx ) / npix ;
+        } 
+        else
+        {
+            a = ZERO ;
+            b = ZERO ;
+        }
+
+        /*-------------------------------------------------------------------
+         * now correct the second input image im2 and the res_image.
+         */ 
+
+        if ( !isnan(a) && !isnan(b) && fabs(a) < 1e8 && fabs(b) < 1e8 )
+        {
+            for ( j = 0 ; j < ly2 ; j ++ ) /* the same column */
+            {
+                if ( !isnan(poutdata[i+j*lx2]) )
+                {
+                    poutdata[i + j*lx2] += a*j+b ;        
+                    pirdata[i + j*lx2] = ptmpdata[i + j*lx2] -(a*j+b) ;
+                }
+            }
+        }
+    }
+
+    cpl_image_delete (residual) ;
+
+    return out_image ;
+}
+
+
+/**
+ at brief removes the residual offset by adding the median of the residual 
+       image to each column 
+   @name sinfo_new_remove_residual_offset()
+   @param im2 second image that will be changed,
+   @param res_image residual image must be given.
+   @return changed second image, residual image
+
+ */
+
+cpl_image * 
+sinfo_new_remove_residual_offset( cpl_image * im2, cpl_image * res_image )
+{
+    cpl_image * out_image ;
+    int i, j, npix ;
+    pixelvalue res_median ;
+    pixelvalue * column ;
+    int lx2=0;
+    int ly2=0;
+    int rlx=0;
+    int rly=0;
+    int olx=0;
+    int oly=0;
+    float* pi2data=NULL;
+    float* pirdata=NULL;
+    float* poudata=NULL;
+
+
+    if ( im2 == NULL || res_image == NULL )
+    {
+        sinfo_msg_error ("null image as input") ;
+        return NULL ;
+    }
+    lx2=cpl_image_get_size_x(im2);
+    ly2=cpl_image_get_size_y(im2);
+    rlx=cpl_image_get_size_x(res_image);
+    rly=cpl_image_get_size_y(res_image);
+    pi2data=cpl_image_get_data_float(im2);
+    pirdata=cpl_image_get_data_float(res_image);
+
+
+    if ( lx2 != rlx || ly2 != rly )
+    {
+        sinfo_msg_error ("input images are not compatible in size") ;
+        return NULL ;
+    }
+
+    out_image = cpl_image_duplicate( im2 ) ;
+    poudata=cpl_image_get_data_float(res_image);
+    olx=cpl_image_get_size_x(res_image);
+    oly=cpl_image_get_size_y(res_image);
+
+    column = (pixelvalue *) cpl_calloc ( ly2 , sizeof (pixelvalue *) ) ;
+    
+    for ( i = 0 ; i < lx2 ; i++ ) /* select one column */
+    {
+        npix = 0  ;
+    for (j=0;j<ly2;j++)
+        column[j]=0;
+
+        for ( j = 0 ; j < rly ; j++ ) /* go through one column */
+        {
+            if ( isnan(pirdata[i + j*rlx]) )
+            {
+                continue ;
+            }
+   
+            column[npix] = pirdata[i + j*rlx] ;
+            npix ++ ;
+        }
+            
+        /* determine the sinfo_median of a column of the residual image */
+        if ( npix > 0.1 * rly )
+        {
+            res_median = sinfo_new_median( column, npix ) ;
+        }
+        else
+        {
+            continue ;
+        }
+        
+        for ( j = 0 ; j < ly2 ; j++ ) /* go through one column */
+        {
+            if ( !isnan(pi2data[i+j*lx2]))
+            {
+                poudata[i + j*lx2] = pi2data[i + j*lx2] + res_median ;
+            }
+            else
+            {
+                poudata[i + j*lx2] = ZERO ;
+            }
+            if ( !isnan(pirdata[i + j*rlx]) )
+            {
+                pirdata[i + j*rlx] -= res_median ;
+            }
+        }
+    }
+    cpl_free ( column ) ;
+    return out_image ;
+}
+/**@}*/
+/*___oOo___*/
diff --git a/sinfoni/sinfo_merge.h b/sinfoni/sinfo_merge.h
new file mode 100644
index 0000000..73e8394
--- /dev/null
+++ b/sinfoni/sinfo_merge.h
@@ -0,0 +1,142 @@
+#ifndef SINFO_MERGE_H
+#define SINFO_MERGE_H
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*******************************************************************************
+* E.S.O. - VLT project
+*
+* "@(#) $Id: sinfo_merge.h,v 1.4 2007/06/06 07:10:45 amodigli Exp $"
+*
+* who       when      what
+* --------  --------  ----------------------------------------------
+* schreib  04/07/00  created
+*/
+
+/************************************************************************
+ * sinfo_merge.h
+ * merges the rows of two image data frames into one frame with doubled
+ * column length
+ *----------------------------------------------------------------------
+ */
+
+/*
+ * header files
+ */
+#include <cpl.h>
+#include "sinfo_msg.h"
+#include "sinfo_recipes.h"
+
+/*
+ * function prototypes
+ */
+
+/**
+  @name  sinfo_sinfo_merge_images()
+  @memo merges the rows of two image frames in a way that the resulting
+        image has double length in y-direction
+  @param im1  image to merge
+  @param im2  image to merge
+  @param res_image dummy for residual image
+  @note first must have smaller wavelength than the second for the same pixel 
+        row.
+  @result merged image, final residual image
+*/
+
+cpl_image * 
+sinfo_sinfo_merge_images (cpl_image * im1, 
+                  cpl_image * im2,
+                  cpl_image * res_image ) ;
+
+/**
+   @name   sinfo_new_remove_general_offset()
+   @memo  adds general offset between two frames to the second image and 
+          delivers the residual image, assuming that the background
+          cancellation did not work perfectly well.   @param  im1 image 
+   @param  im2 image number of rows from which the offset is determined
+   @param  residual image.
+   @result changed second image, residual image
+
+*/
+
+
+cpl_image * 
+sinfo_new_remove_general_offset(cpl_image * im1, 
+                      cpl_image * im2, 
+                      cpl_image * res_image,
+                      int n ) ;
+
+/**
+  @name sinfo_new_remove_regional_tilt()
+  @memo  removes a general tilt from the spectra , created e.g. by different 
+         emissivities of the telescope itself and delivers the residual image
+  @param im1 image to merge
+  @param im2 image to merge
+  @param  residual image (obligatory no NullImage).
+  @result changed second image, residual image 
+*/
+
+cpl_image * 
+sinfo_new_remove_regional_tilt (cpl_image * im1,
+              cpl_image * im2, 
+              cpl_image * res_image ) ;
+
+/**
+   @name  sinfo_new_remove_column_offset()
+   @memo removes individual column offset, created e.g. by imperfect
+         guiding. The offset is divided out. The ratio is derived
+         from the medians of the contributions.
+   @param im1 first image
+   @param im2 already corrected second image to merge,
+   @param residual image (obligatory no NullImage).
+   @result changed second image, residual image
+*/
+
+cpl_image * sinfo_new_remove_column_offset (cpl_image * im1,
+                      cpl_image * im2,
+                      cpl_image * res_image );
+
+/**
+  @name  sinfo_new_remove_residual_tilt()
+  @memo removes a residual column tilt (determined from the 
+            residual image) created by previous operations
+  @param im2 second image to merge
+  @param res_image residual image (obligatory no NullImage).
+  @result changed second image, residual image
+*/
+
+cpl_image * 
+sinfo_new_remove_residual_tilt (cpl_image * im2,cpl_image * res_image ) ;
+
+
+/**
+   @name  sinfo_new_remove_residual_offset()
+   @param im2     second image that will be changed,
+   @param res_image        residual image must be given.
+   @result changed second image, residual image
+   @memo   removes the residual offset by subtracting the sinfo_median
+           of the residual image from each column
+*/
+
+
+cpl_image * 
+sinfo_new_remove_residual_offset(cpl_image * im2,cpl_image * res_image);
+
+
+#endif /*!SINFO_MERGE_H*/
+
diff --git a/sinfoni/sinfo_msg.c b/sinfoni/sinfo_msg.c
new file mode 100644
index 0000000..9811125
--- /dev/null
+++ b/sinfoni/sinfo_msg.c
@@ -0,0 +1,327 @@
+/*                                                                          *
+ *   This file is part of the ESO SINFO Pipeline                            *
+ *   Copyright (C) 2004,2005 European Southern Observatory                  *
+ *                                                                          *
+ *   This library is free software; you can redistribute it and/or modify   *
+ *   it under the terms of the GNU General Public License as published by   *
+ *   the Free Software Foundation; either version 2 of the License, or      *
+ *   (at your option) any later version.                                    *
+ *                                                                          *
+ *   This program is distributed in the hope that it will be useful,        *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of         *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
+ *   GNU General Public License for more details.                           *
+ *                                                                          *
+ *   You should have received a copy of the GNU General Public License      *
+ *   along with this program; if not, write to the Free Software            *
+ *   Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA   *
+ *                                                                          */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2008/02/12 14:57:39 $
+ * $Revision: 1.7 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#include <sinfo_msg.h>
+#include <cpl.h>
+#include <stdarg.h>
+#include <stdio.h>
+
+/**@{*/
+/*--------------------------------------------------------------------------*/
+/**
+ * @defgroup sinfo_msg        Messaging
+ *
+ * CPL's info message level is expanded to a set of relative message level.
+ * The functions sinfo_msg_louder() and sinfo_msg_softer() are used to turn 
+   up/down the message level (instead of setting the verbosity to an absolute 
+   level)
+ * These two functions should be used consistently, so that the level is always
+ * the same on function exit as on function entry.
+ *
+ * These functions never fail, but print warnings if called inconsistently.
+ */
+/*---------------------------------------------------------------------------*/
+
+#define DEBUG_CALLER 0  /* Define whether to check consistency of 
+                           msg_louder/softer calls */
+/* #define DEBUG_CALLER */
+
+#define MAXLEVEL 256
+#define MAXSTRINGLENGTH 1000
+
+static int level = 0;  /* Current message & indentation level 
+                          from 0 to MAXLEVEL-1.
+            0 is the most verbose level. */
+static int outlevel = -1; /* Only print message if level is 
+                             in {0, 1, ..., outlevel}.
+             Always print if outlevel = - 1 */
+#ifdef DEBUG_CALLER
+const char *sinfo_callers[MAXLEVEL]; /* Check the consistency of 
+                                         calls to softer/louder  */
+#endif
+
+static char printbuffer[MAXSTRINGLENGTH]; /* Used to pass variable argument 
+                                             list to cpl_msg_info() */
+
+static const char *domain = "Undefined domain";
+                                     /* This is to support getting the 
+                                        current domain 
+                      * which is currently not available in CPL
+                      */
+static int initialized = FALSE;
+
+static int number_of_warnings = 0;     /* Coun't the number of warnings since 
+                                          initialization */
+
+/*--------------------------------------------------------------------------*/
+/**
+   @brief    Initialize messaging
+   @param    olevel          The output level
+   @param    dom             The message domain
+
+   Only messages at levels 0 (most important) to @em outlevel are printed 
+   as 'info'.  Messages at levels above @em outlevel are printed as 'debug'.
+   
+   Therefore, set @em outlevel = 0 to print fewest messages. 
+   Increase @em outlevel
+   to increase verbosity.
+
+   To print all messages as 'info' set @em outlevel to the special value -1
+   (which has the effect of infinity).
+   
+*/
+/*--------------------------------------------------------------------------*/
+void sinfo_msg_init(int olevel, const char *dom)
+{
+    /* Initialize per recipe: */
+    number_of_warnings = 0;
+        
+    if (!initialized)
+    {
+        /* Initialize once: */
+        outlevel = olevel;
+
+        cpl_msg_set_indentation(2);
+        
+        /*  CPL message format is
+         *  [Time][Verbosity][domain][component] message
+         *
+         *  Don't show the (variable length and wildly
+         *  fluctuating) component. It interferes with
+         *  indentation. The component is available anyway
+         *  on CPL_MSG_DEBUG level.
+         */
+        cpl_msg_set_time_on();
+        sinfo_msg_set_domain(dom);
+        cpl_msg_set_domain_on();
+        cpl_msg_set_component_off();
+
+        initialized = TRUE;
+    }
+}
+
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Set output level
+   @param    olevel          The output level
+
+   See @c sinfo_msg_init() .
+*/
+/*---------------------------------------------------------------------------*/
+void sinfo_msg_set_level(int olevel) 
+{
+    outlevel = olevel; 
+} 
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Decrease message level
+   @param    fctid Identity of calling function
+
+   Don't call this function directly, use @c sinfo_msg_softer().
+
+*/
+/*---------------------------------------------------------------------------*/
+void sinfo_msg_softer_macro(const char *fctid)
+{
+    if (level + 1 < MAXLEVEL)
+    {
+        level++;
+        cpl_msg_indent_more();
+#if DEBUG_CALLER
+        sinfo_callers[level] = fctid;
+#else
+        fctid = fctid; /* Satisfy compiler */
+#endif
+        }
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Increase message level
+   @param    fctid           Identity of calling function
+
+   Don't call this function directly, use @c sinfo_msg_louder().
+
+*/
+/*---------------------------------------------------------------------------*/
+void sinfo_msg_louder_macro(const char *fctid)
+{
+    if (level == 0)
+    {
+        /* 0 is the loudest, ignore request */
+        return;
+    }
+    
+    /* Only make louder, if called from the same function which called
+       sinfo_msg_softer. (disable check if level is more than MAXLEVEL)
+    */
+#if DEBUG_CALLER
+    if (level >= MAXLEVEL || strcmp(sinfo_callers[level], fctid) == 0)
+#else
+    fctid = fctid;              /* Satisfy compiler */
+#endif
+    {
+        level--;
+        cpl_msg_indent_less();
+    }
+#if DEBUG_CALLER
+    else
+    {
+     sinfo_msg_warning("Message level decreased by '%s' but increased by '%s'",
+		       sinfo_callers[level], fctid);
+    }
+#endif
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Print a message on 'info' or 'debug' level
+   @param    fct           Identity of calling function
+   @param    format          A printf()-like format string
+
+   Don't call this function directly, use @c sinfo_msg().
+
+   If the current level (which might be equal to the current depth
+   of the function call-tree) is less than the output level, the 
+   message printed
+   on the 'info' level, otherwise it is printed on the 'debug' level.
+*/
+/*---------------------------------------------------------------------------*/
+void sinfo_msg_macro(const char *fct, const char *format, ...)
+{
+    va_list al;
+    
+    va_start(al, format);
+    vsnprintf(printbuffer, MAXSTRINGLENGTH - 1, format, al);
+    va_end(al);
+
+    printbuffer[MAXSTRINGLENGTH - 1] = '\0';
+    
+    if (outlevel < 0 || level <= outlevel)
+    {
+/*
+#undef cpl_msg_info
+*/
+        cpl_msg_info(fct, "%s", printbuffer);
+/*
+#define cpl_msg_info(...)  use__sinfo_msg__instead__of__cpl_msg_info
+*/
+    }
+    else
+    {
+        cpl_msg_debug(fct, "%s", printbuffer);
+    }
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Get number of warnings printed so far
+   @return Number of warnings since initialization of messaging
+*/
+/*---------------------------------------------------------------------------*/
+int sinfo_msg_get_warnings(void)
+{
+    return number_of_warnings;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Accumulate warnings
+   @param    n              Number of warnings to add
+
+   The (internal) number of warnings (returned by @c sinfo_msg_get_warnings())
+   is increased by @em n, but without actually printing any warnings.
+
+*/
+/*---------------------------------------------------------------------------*/
+void sinfo_msg_add_warnings(int n)
+{
+    number_of_warnings += n;
+}
+
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Print a warning message
+   @param    fct             Identity of calling function
+   @param    format          A printf()-like format string
+
+   Don't call this function directly, use @c sinfo_msg_warning().
+
+   This function is used instead of @c cpl_msg_warning(), and saves
+   the user from typing the calling function name.
+
+   Additionally, record is kept on the total number of warnings printed
+   (see @c sinfo_msg_get_warnings()).
+*/
+/*---------------------------------------------------------------------------*/
+void sinfo_msg_warning_macro(const char *fct, const char *format, ...)
+{
+    va_list al;
+    
+    va_start(al, format);
+    vsnprintf(printbuffer, MAXSTRINGLENGTH - 1, format, al);
+    va_end(al);
+
+    printbuffer[MAXSTRINGLENGTH - 1] = '\0';
+    
+    cpl_msg_warning(fct, "%s", printbuffer);
+
+    number_of_warnings += 1;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Get current message domain
+   @return    The current message domain set by @c sinfo_msg_init() or 
+             @c sinfo_msg_set_domain().
+*/
+/*---------------------------------------------------------------------------*/
+const char *sinfo_msg_get_domain(void)
+{
+    return domain;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Set message domain
+   @param    d            The new message domain
+*/
+/*---------------------------------------------------------------------------*/
+void sinfo_msg_set_domain(const char *d)
+{
+    /* Set domain and remember */
+    cpl_msg_set_domain(d);
+    domain = d;
+}
+
+/**@}*/
diff --git a/sinfoni/sinfo_msg.h b/sinfoni/sinfo_msg.h
new file mode 100644
index 0000000..85da8c0
--- /dev/null
+++ b/sinfoni/sinfo_msg.h
@@ -0,0 +1,145 @@
+/*
+ * This file is part of the ESO SINFO Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2006/11/21 11:56:10 $
+ * $Revision: 1.2 $
+ * $Name: sinfo-2_3_2 $
+ */
+#ifndef SINFO_MSG_H
+#define SINFO_MSG_H
+
+/*
+#include <sinfo_utils.h>
+*/
+#include <cpl_msg.h>
+
+/* Nothing bad happens if user also calls cpl_msg_info()
+ * but prevent it as a service to the user of this module
+#define cpl_msg_info(...)  use__sinfo_msg__instead__of__cpl_msg_info
+#define cpl_msg_indent()
+ */
+
+/*----------------------------------------------------------------------------*/
+/**
+ * @addtogroup sinfo_msg
+ *
+ */
+/*----------------------------------------------------------------------------*/
+/**@{*/
+
+
+void sinfo_msg_init(int outlevel, const char *dom);
+
+
+void sinfo_msg_set_level(int olevel);
+
+const char *sinfo_msg_get_domain(void);
+void sinfo_msg_set_domain(const char *d);
+
+
+/* Convenience macros to save the user from typing function id */
+
+/*----------------------------------------------------------------------------*/
+/**
+   @brief    Print an error message
+   @param    ...             Message to print
+
+   This function is used instead of @c cpl_msg_error(), and saves
+   the user from typing the calling function name.
+*/
+/*----------------------------------------------------------------------------*/
+#define sinfo_msg_error(...) cpl_msg_error(cpl_func, __VA_ARGS__)
+
+/*----------------------------------------------------------------------------*/
+/**
+   @brief    Print a progress message
+   @param    i           See @c cpl_msg_progress()
+   @param    iter        See @c cpl_msg_progress()
+   @param    ...         Message to print
+
+   This function is used instead of @c cpl_msg_progress(), and saves
+   the user from typing the calling function name.
+*/
+/*----------------------------------------------------------------------------*/
+#define sinfo_msg_progress(i, iter, ...) \
+  cpl_msg_progress(cpl_func, (i), (iter), __VA_ARGS__)
+/*----------------------------------------------------------------------------*/
+/**
+   @brief    Print an warning message
+   @param    ...             Message to print
+
+   This function is used instead of @c cpl_msg_warning(), and saves
+   the user from typing the calling function name.
+*/
+/*----------------------------------------------------------------------------*/
+#define sinfo_msg_warning(...) sinfo_msg_warning_macro(cpl_func, __VA_ARGS__)
+/*----------------------------------------------------------------------------*/
+/**
+   @brief    Print a debug message
+   @param    ...             Message to print
+
+   This function is used instead of @c cpl_msg_debug(), and saves
+   the user from typing the calling function name.
+*/
+/*----------------------------------------------------------------------------*/
+#define sinfo_msg_debug(...) cpl_msg_debug(cpl_func, __VA_ARGS__)
+
+/*----------------------------------------------------------------------------*/
+/**
+   @brief    Print a message on a lower message level
+   @param    ...             Message to print
+*/
+/*----------------------------------------------------------------------------*/
+#define sinfo_msg_low(...)  do {                     \
+                           sinfo_msg_softer();       \
+                           sinfo_msg(__VA_ARGS__);   \
+                           sinfo_msg_louder();       \
+                           } while (FALSE)
+
+
+
+
+#define sinfo_msg(...) sinfo_msg_macro(cpl_func, __VA_ARGS__)
+#define sinfo_msg_softer() sinfo_msg_softer_macro(cpl_func)
+#define sinfo_msg_louder() sinfo_msg_louder_macro(cpl_func)
+
+
+void sinfo_msg_macro(const char *fct, const char *format, ...)
+#ifdef __GNUC__
+__attribute__((format (printf, 2, 3)))
+#endif
+;
+
+void sinfo_msg_warning_macro(const char *fct, const char *format, ...)
+#ifdef __GNUC__
+__attribute__((format (printf, 2, 3)))
+#endif
+;
+
+int sinfo_msg_get_warnings(void);
+void sinfo_msg_add_warnings(int n);
+
+void sinfo_msg_softer_macro(const char *fct);
+void sinfo_msg_louder_macro(const char *fct);
+
+#endif /* SINFO_MSG_H */
+
+/**@}*/
diff --git a/sinfoni/sinfo_new_add_bp_map.c b/sinfoni/sinfo_new_add_bp_map.c
new file mode 100644
index 0000000..ad429ee
--- /dev/null
+++ b/sinfoni/sinfo_new_add_bp_map.c
@@ -0,0 +1,288 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+   
+   File name    :       sinfo_new_add_bp_map.c
+   Author       :    A. Modigliani
+   Created on   :    Oct 13, 2004
+   Description  :    Coadd different BP MAP 
+
+ ---------------------------------------------------------------------------*/
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+/*----------------------------------------------------------------------------
+                                Includes
+ ---------------------------------------------------------------------------*/
+#include "sinfo_new_add_bp_map.h"
+#include "sinfo_pro_save.h"
+#include "sinfo_error.h"
+#include "sinfo_utils_wrappers.h"
+/* #include "image_ops.h" */
+#include "sinfo_pro_types.h"
+#include "sinfo_functions.h"
+#include "sinfo_detlin.h"
+/*----------------------------------------------------------------------------
+                                Prototypes
+ ---------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+                                Defines
+ ---------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+  Function Definitions
+  ---------------------------------------------------------------------------*/
+/**@{*/
+/**
+ * @addtogroup sinfo_bad_pix_search Bad Pixel Search
+ *
+ * TBD
+ */
+
+
+/**
+   @brief coadd bad pixel maps
+   @name sinfo_new_add_bp_map()
+   @param plugin_id name of plug-in
+   @param config    recipe configuration parameters
+   @param sof       set of frame
+   @return integer (0 if it worked, -1 if it doesn't)  
+*/
+
+int 
+sinfo_new_add_bp_map (const char* plugin_id,
+                      cpl_parameterlist* config, 
+                      cpl_frameset* sof,cpl_frameset* ref_set)
+{
+
+  int  nmsk =0;
+  int  nmsk_ref_fits =0;
+  int i=0;
+  int k=0;
+  int n_bad=0;
+  cpl_image**  img_sum=NULL;
+  cpl_image*   img_set=NULL;
+  cpl_image*   img_tot=NULL;
+  cpl_frameset* msk_set=NULL;
+  cpl_frameset* msk_ref_fits=NULL;
+  cpl_frame* frame=NULL;
+  double max=0;
+  char frame_name[FILE_NAME_SZ];
+  char out_msk[FILE_NAME_SZ];
+      
+  cpl_table* qclog_tbl=NULL;
+  char * tag=NULL;
+  char * tmp_tag=NULL;
+
+  strcpy(out_msk, MASTER_BPMAP_OUT_FILENAME);
+
+
+  /* cpl_parameterlist_dump(config); */
+  check_nomsg(msk_set=cpl_frameset_new());
+  ck0_nomsg(sinfo_contains_frames_kind(sof,msk_set,"BP_MAP"));
+  check_nomsg(nmsk = cpl_frameset_get_size(msk_set));
+  if(nmsk == 0) {
+    sinfo_msg_warning("No bad pixel masks to add");
+    goto cleanup;
+  }
+
+
+  check_nomsg(frame = cpl_frameset_get_frame(msk_set,0));
+  strcpy(frame_name,cpl_frame_get_filename(frame));
+  check_nomsg(tag = (char*) cpl_frame_get_tag(frame));
+  {
+    check_nomsg(msk_ref_fits=cpl_frameset_new());
+    if (nmsk < 1) {
+      sinfo_msg_error("No input frames. Nothing to do.");
+      goto cleanup;
+    } else if (nmsk==1) {
+
+      sinfo_msg_warning("Only one input frames. Use it as master.");
+      check_nomsg(frame = cpl_frameset_get_frame(msk_set,0));
+      strcpy(frame_name,cpl_frame_get_filename(frame));
+      check_nomsg(tag = (char*) cpl_frame_get_tag(frame));
+
+    } else {
+       
+      ck0_nomsg(sinfo_contains_frames_kind(msk_set,
+					   msk_ref_fits,PRO_BP_MAP_NO));
+      check_nomsg(nmsk_ref_fits = cpl_frameset_get_size(msk_ref_fits));
+
+      if (nmsk_ref_fits < 1) {
+	sinfo_msg_warning("No %s input frames. Uses %s for FITS header",
+			  PRO_BP_MAP_NO,PRO_BP_MAP_DI);
+
+	ck0_nomsg(sinfo_contains_frames_kind(msk_set,
+					     msk_ref_fits,PRO_BP_MAP_DI));
+	check_nomsg(nmsk_ref_fits = cpl_frameset_get_size(msk_ref_fits));
+
+
+	if (nmsk_ref_fits < 1) {
+
+	  sinfo_msg_warning("No %s input frames. Uses %s for FITS header",
+			    PRO_BP_MAP_DI,PRO_BP_MAP_NL);
+        
+	  ck0_nomsg(sinfo_contains_frames_kind(msk_set,
+					       msk_ref_fits,PRO_BP_MAP_NL));
+	  check_nomsg(nmsk_ref_fits = cpl_frameset_get_size(msk_ref_fits));
+
+	  if (nmsk_ref_fits < 1) {
+
+	    sinfo_msg_warning("No %s input frames. Uses 1st mask in the list",
+			      PRO_BP_MAP_NL);
+	    sinfo_free_frameset(&msk_ref_fits);
+	    check_nomsg(msk_ref_fits=cpl_frameset_duplicate(msk_set));
+	    check_nomsg(frame = cpl_frameset_get_frame(msk_set,0));
+	    check_nomsg(cpl_frameset_erase_frame(msk_set,frame));
+	    check_nomsg(tag = (char*) cpl_frame_get_tag(frame));
+
+	  } else {
+	    sinfo_msg("Uses as reference frame %s",PRO_BP_MAP_NL);
+	    check_nomsg(frame = cpl_frameset_get_frame(msk_ref_fits,0));
+	    strcpy(frame_name,cpl_frame_get_filename(frame));
+	    tag = (char*) PRO_BP_MAP_NL;
+	  }
+	} else {
+          sinfo_msg("Uses as reference frame %s",PRO_BP_MAP_DI);
+	  check_nomsg(frame = cpl_frameset_get_frame(msk_ref_fits,0));
+	  strcpy(frame_name,cpl_frame_get_filename(frame));
+	  tag = (char*) PRO_BP_MAP_DI;
+	}
+      } else {
+        sinfo_msg("Uses as reference frame %s",PRO_BP_MAP_NO);
+	check_nomsg(frame = cpl_frameset_get_frame(msk_ref_fits,0));
+	strcpy(frame_name,cpl_frame_get_filename(frame));
+	tag = (char*) PRO_BP_MAP_NO;
+      }
+    }
+
+    check_nomsg(nmsk = cpl_frameset_get_size(msk_set));  
+    cknull_nomsg(img_sum = (cpl_image**) cpl_calloc ((nmsk+1), 
+						     sizeof(cpl_image*))) ;
+    cknull_nomsg(img_sum[0]=cpl_image_load(frame_name,CPL_TYPE_FLOAT,0,0));
+
+    /* here mem leak */
+    for (i=0;i<nmsk;i++) {
+      check_nomsg(frame = cpl_frameset_get_frame(msk_set,i));
+      check_nomsg(strcpy(frame_name,cpl_frame_get_filename(frame)));
+      check_nomsg(tmp_tag=(char*)cpl_frame_get_tag(frame));
+
+      if(strcmp(tmp_tag,tag) == 0 ) {
+	cknull_nomsg(img_set=cpl_image_load(frame_name,CPL_TYPE_FLOAT,0,0));
+        check_nomsg(max=cpl_image_get_max(img_set));
+	if((strcmp(tmp_tag,PRO_BP_MAP_NL) == 0) && max>1 ) {
+	  sinfo_msg("corr1");
+	  check_nomsg(cpl_image_threshold(img_set,0.5,0.9,1,0));
+          sinfo_free_image(&(img_sum[0]));
+          check_nomsg(img_sum[0]=cpl_image_duplicate(img_set));
+	}
+
+      } else {
+
+	cknull_nomsg(img_set=cpl_image_load(frame_name,CPL_TYPE_FLOAT,0,0));
+        check_nomsg(max=cpl_image_get_max(img_set));
+	if((strcmp(tmp_tag,PRO_BP_MAP_NL) == 0) &&  max>1 ) {
+	  sinfo_msg("corr2 name=%s tag=%s",frame_name,tmp_tag);
+	  check_nomsg(cpl_image_threshold(img_set,0.5,0.9,1,0));
+	}
+   
+	cknull_nomsg(img_sum[k+1]=sinfo_new_combine_masks (img_sum[k], img_set));
+	k++;
+	sinfo_free_image(&img_set);
+	sinfo_free_image(&(img_sum[k-1]));
+      }
+    }
+    img_tot=cpl_image_duplicate(img_sum[k]);
+    sinfo_free_image(&(img_sum[k]));
+    sinfo_free_array_image(&img_sum);
+    /*
+
+    frame = cpl_frameset_get_frame(msk_set,0);
+    strcpy(frame_name,cpl_frame_get_filename(frame));
+    img_sum=cpl_image_load(frame_name,CPL_TYPE_INT,0,0);
+	    
+    for (i=1;i<nmsk;i++) {
+    frame = cpl_frameset_get_frame(msk_set,i);
+    strcpy(frame_name,cpl_frame_get_filename(frame));
+    img_set=cpl_image_load(frame_name,CPL_TYPE_INT,0,0);
+    cpl_mask_and(img_sum, img_set);
+
+    }
+    
+    */
+
+    n_bad = sinfo_new_count_bad_pixels(img_tot) ;
+    sinfo_msg ("number of bad pixels: %d\n", n_bad) ;
+    cknull_nomsg(qclog_tbl = sinfo_qclog_init());
+    ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC MBP_MAP NBADPIX",
+				  n_bad,"No of bad pixels","%d"));
+
+    if (nmsk>1) {
+      ck0(sinfo_pro_save_ima(img_tot,ref_set,sof,out_msk,
+			     PRO_MASTER_BP_MAP,qclog_tbl,
+			     plugin_id,config),
+	  "cannot save ima %s", out_msk);   
+
+    } else {
+      ck0(sinfo_pro_save_ima(img_tot,ref_set,sof,out_msk,
+			     PRO_MASTER_BP_MAP,qclog_tbl,
+			     plugin_id,config),
+	  "cannot save ima %s", out_msk);   
+    }
+
+    sinfo_free_image(&img_tot);
+    sinfo_free_table(&qclog_tbl);
+    sinfo_free_frameset(&msk_ref_fits);
+    sinfo_free_frameset(&msk_set);
+  
+  }
+
+ cleanup:
+
+  sinfo_free_image(&img_tot);
+  if(img_sum!=NULL) {
+    for(i=0;i<nmsk;i++) {
+      if(img_sum[i] != NULL) {
+	sinfo_free_image(&(img_sum[i]));
+	img_sum[i]=NULL;         
+      }
+    }
+    sinfo_free_array_image(&img_sum);
+    img_sum=NULL;
+  }
+  sinfo_free_image(&img_set);
+  sinfo_free_table(&qclog_tbl);
+  sinfo_free_frameset(&msk_set);
+  sinfo_free_frameset(&msk_ref_fits);
+
+  if (cpl_error_get_code() != CPL_ERROR_NONE) {
+     return -1; 
+  } else {
+     return 0;
+  }
+
+
+}
+
+
+
+/**@}*/
diff --git a/sinfoni/sinfo_new_add_bp_map.h b/sinfoni/sinfo_new_add_bp_map.h
new file mode 100644
index 0000000..398196c
--- /dev/null
+++ b/sinfoni/sinfo_new_add_bp_map.h
@@ -0,0 +1,64 @@
+#ifndef SINFO_NEW_ADD_BP_MAP_H
+#define SINFO_NEW_ADD_BP_MAP_H
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*******************************************************************************
+* E.S.O. - VLT project
+*
+* "@(#) $Id: sinfo_new_add_bp_map.h,v 1.7 2007/09/21 14:13:43 amodigli Exp $"
+*
+* who       when      what
+* --------  --------  ----------------------------------------------
+* amodigli  13/10/04  created
+*/
+
+/************************************************************************
+ * sinfo_add_bp_map.h
+ * routines to search for bad pixels
+ *----------------------------------------------------------------------
+ */
+
+/*
+ * header files
+ */
+#include <cpl.h>
+#include <sinfo_hidden.h>  
+#include "sinfo_msg.h"
+/*----------------------------------------------------------------------------
+ *                        Function ANSI C prototypes
+ *--------------------------------------------------------------------------*/
+/**
+   @name       sinfo_new_add_bp_map()
+   @param      plugin_id  recipe name
+   @param      config     input parameter list
+   @param      set        input set of frames
+
+   @return     integer (0 if it worked, -1 if it doesn't) 
+*/
+
+int 
+sinfo_new_add_bp_map(const char* plugin_id, 
+                     cpl_parameterlist* config, 
+                     cpl_frameset* set,
+                     cpl_frameset* ref_set);
+
+
+#endif 
+
+/*--------------------------------------------------------------------------*/
diff --git a/sinfoni/sinfo_new_bezier.c b/sinfoni/sinfo_new_bezier.c
new file mode 100644
index 0000000..2c89fd0
--- /dev/null
+++ b/sinfoni/sinfo_new_bezier.c
@@ -0,0 +1,1632 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*****************************************************************************
+* M.P.E. - SPIFFI project
+*
+*
+*
+* who       when      what
+
+* --------  --------  ----------------------------------------------
+* rabuter 2004-11-04 Fixed error on Find Cosmic when no valid neighboors
+                     where found in the subcube
+* rabuter 10/07/03  created
+*/
+
+/************************************************************************
+*   NAME
+*        sinfo_new_bezier.c -
+*        procedures to correct for bad pixels using bezier splines
+*
+*   SYNOPSIS
+*
+*   DESCRIPTION
+*
+*   FILES
+*
+*   ENVIRONMENT
+*
+*   RETURN VALUES
+*
+*   CAUTIONS
+*
+*   EXAMPLES
+*
+*   SEE ALSO
+*
+*   BUGS
+*
+*------------------------------------------------------------------------
+*/
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+#define POSIX_SOURCE 1
+#include "sinfo_vltPort.h"
+
+/*
+ * System Headers
+ */
+
+/*
+ * Local Headers
+ */
+
+#include "sinfo_new_bezier.h"
+#include "sinfo_msg.h"
+/**@{*/
+/**
+ * @addtogroup sinfo_new_bezier Bezier Functions
+ *
+ * TBD
+ */
+
+/*----------------------------------------------------------------------------
+ *                            Function codes
+ *--------------------------------------------------------------------------*/
+
+/**
+ at name sinfo_im_xy
+ at brief computes  (x+size_x*y)
+ at param im input image
+ at param X  point X
+ at param Y  point Y
+ at return  (x+size_x*y)
+*/
+int sinfo_im_xy(cpl_image* im, int X, int Y)
+{
+  int res=0;
+
+   res=X+Y*cpl_image_get_size_x(im);
+  return res;
+}
+/**
+ at brief computes (x+size_x*y+size_x*size_y*z)
+ at param im input image
+ at param X  point X
+ at param Y  point Y
+ at param Z  point Z
+ at return  (x+size_x*y+size_x*size_y*z)
+*/
+int sinfo_im_xyz(cpl_image* im, int X, int Y, int Z)
+{
+  int res=0;
+   res = X+
+         Y*cpl_image_get_size_x(im)+
+         Z*cpl_image_get_size_x(im)*
+           cpl_image_get_size_y(im);
+  return res;
+}
+
+
+
+/**
+ at brief computes (x+size_x*y)
+ at param cu input imagelist
+ at param X  point X
+ at param Y  point Y
+ at return  (x+size_x*y)
+*/
+
+int sinfo_cu_xy(cpl_imagelist* cu, int X, int Y)
+{
+  int res=0;
+
+   res=X+Y*cpl_image_get_size_x(cpl_imagelist_get(cu,0));
+  return res;
+}
+/**
+ at name sinfo_cu_xyz
+ at brief computes (x+size_x*y+size_x*size_y*z)
+ at param im input image
+ at param X  point X
+ at param Y  point Y
+ at param Z  point Z
+ at return  (x+size_x*y+size_x*size_y*z)
+*/
+
+int sinfo_cu_xyz(cpl_imagelist* cu, int X, int Y, int Z)
+{
+  int res=0;
+   res = X+
+         Y*cpl_image_get_size_x(cpl_imagelist_get(cu,0))+
+         Z*cpl_image_get_size_x(cpl_imagelist_get(cu,0))*
+           cpl_image_get_size_y(cpl_imagelist_get(cu,0));
+  return res;
+}
+
+/**
+ at name sinfo_new_c_bezier_interpolate_image(
+ at brief interpolates an image with a bezier function (TBV)
+ at param im         input image
+ at param mask       input bad pixel map
+ at param look       input look-up table
+ at param rx         input radius on X
+ at param ry         input radius on Y
+ at param rz         input radius on Z
+ at param max_rad    max radius
+ at param slit_edges slitlet edges
+
+*/
+
+cpl_image *
+sinfo_new_c_bezier_interpolate_image(cpl_image *im,
+                                     cpl_image *mask,
+                                     new_Lookup *look,
+                                           short rx,
+                                           short ry,
+                                           short rz,
+                           int max_rad ,
+                                           float   ** slit_edges )
+{
+
+    int i,j,count;
+    cpl_imagelist * sc_im,* drs_sc_mask;
+    cpl_image /**auxMask,*/*auxImage;
+    cpl_image *tempMask;
+    short szx,szy,szz;
+    short rx_loop, ry_loop, rz_loop;
+    /*float ant,new,dif;*/
+
+    int ilx=0;
+    int ily=0;
+    int mlx=0;
+    int mly=0;
+
+    float* pidata=NULL;
+    float* pmdata=NULL;
+    float* ptdata=NULL;
+    float* padata=NULL;
+
+    cpl_image* sc_img=NULL;
+    cpl_image* drs_img=NULL;
+
+    mlx=cpl_image_get_size_x(mask);
+    mly=cpl_image_get_size_y(mask);
+    ilx=cpl_image_get_size_x(im);
+    ily=cpl_image_get_size_y(im);
+
+    pmdata=cpl_image_get_data_float(mask);
+    pidata=cpl_image_get_data_float(im);
+
+    if ( mlx != ilx || mly != ily )
+    {
+        sinfo_msg_error(" data & mask images not compatible in size\n") ;
+        return NULL ;
+    }
+
+    /* allocate memory for sub cubes*/
+    szx = (rx * 2 ) + 1;
+    szy = (ry * 2 ) + 1;
+    szz = (rz * 2 ) + 1;
+
+    if ( NULL == ( sc_im = cpl_imagelist_new() ) )
+    {
+        sinfo_msg_error(" could not allocate memory for data subcube\n") ;
+        return NULL ;
+    }
+
+    for(i=0;i<szz;i++) {
+      sc_img=cpl_image_new(szx,szy,CPL_TYPE_FLOAT);
+      cpl_imagelist_set(sc_im,sc_img,i);
+    }
+
+    if ( NULL == ( drs_sc_mask = cpl_imagelist_new() ) )
+    {
+        sinfo_msg_error(" could not allocate memory for mask subcube\n") ;
+        return NULL ;
+    }
+    for(i=0;i<szz;i++) {
+      drs_img=cpl_image_new(szx,szy,CPL_TYPE_FLOAT);
+      cpl_imagelist_set(drs_sc_mask,drs_img,i);
+    }
+
+    if ( NULL == ( tempMask = cpl_image_new(mlx, mly, CPL_TYPE_FLOAT) ) )
+    {
+        sinfo_msg_error("could not allocate memory for temporary "
+                        "dead pixel mask\n") ;
+        return NULL ;
+    }
+    ptdata=cpl_image_get_data_float(tempMask);
+
+    count=0;
+    for ( i = 0 ; i < mlx; i++ )
+    {
+        for ( j = 0 ; j < mly ; j++ )
+        {
+        if ( pmdata[sinfo_im_xy(im,i,j)] ==  cubePT_BADPIXEL )
+        {
+          rx_loop = 1 ; ry_loop = 1 ; rz_loop = 1 ;
+          pidata[sinfo_im_xy(im,i,j)] =
+                   sinfo_new_c_bezier_correct_pixel( i, j, im, mask, sc_im,
+                               drs_sc_mask, look, rx_loop, ry_loop, rz_loop );
+          /* if not enough neighbors found, increase size of sub
+                     cube until max radius is reached */
+          while ( pidata[sinfo_im_xy(im,i,j)] == cubeNONEIGHBOR &&
+                          rx_loop < rx && ry_loop < ry && rz_loop < rz )
+            {
+              rx_loop++ ; ry_loop++; rz_loop++;
+              /* sinfo_msg_warning("Increasing radius to %d, in %d %d",
+                                            rx_loop, i, j) ; */
+
+              pidata[sinfo_im_xy(im,i,j)] =
+                        sinfo_new_c_bezier_correct_pixel( i, j, im, mask, sc_im,
+                                drs_sc_mask, look, rx_loop, ry_loop, rz_loop );
+            }
+          /* If still not enough neighbors, make result NaN = ZERO
+                     in spred convention */
+          if ( pidata[sinfo_im_xy(im,i,j)] == cubeNONEIGHBOR )
+            {
+              pidata[sinfo_im_xy(im,i,j)] = ZERO ;
+            }
+        count++;
+        }
+        if ( pidata[sinfo_im_xy(im,i,j)] == ZERO )
+          {
+        ptdata[sinfo_im_xy(tempMask,i,j)] = 0 ;
+          }
+         else
+          {
+        ptdata[sinfo_im_xy(tempMask,i,j)] = 1 ;
+          }
+        }
+    }
+
+
+    sinfo_msg("Replacing NaN\n");
+    auxImage=sinfo_interpol_source_image( im, tempMask, max_rad, slit_edges );
+    padata=cpl_image_get_data_float(auxImage);
+    for ( i = 0 ; i < mlx; i++ )
+    {
+        for ( j = 0 ; j < mly ; j++ )
+        {
+
+        if ( isnan(pidata[sinfo_im_xy(im,i,j)])) /*<= -2e10ZERO )*/
+        {
+          /* sinfo_msg_warning("Replacing NaN -> %d %d %f\n",
+                                       i,j, padata[sinfo_im_xy(im,i,j)] ); */
+        pidata[sinfo_im_xy(im,i,j)] = padata[sinfo_im_xy(im,i,j)];
+        }
+        }
+    }
+    cpl_image_delete(auxImage);
+    cpl_imagelist_delete(sc_im);
+    cpl_imagelist_delete(drs_sc_mask);
+
+    sinfo_msg("bad pixels count: %d\n",count);
+
+
+    return im;
+}
+
+cpl_image *
+sinfo_new_c_bezier_find_bad( cpl_image *im,
+                                   cpl_image *mask,
+                                   /* Lookup *look,*/
+                                   short rx,
+                                   short ry,
+                                   short rz,
+                       short lowerI,
+                                   short highI,
+                                   short lowerJ,
+                                   short highJ,
+                                   float factor )
+{
+
+    int i,j,count;
+    cpl_imagelist * sc_im,* drs_sc_mask;
+    short szx,szy,szz;
+    float /*ant,*/newValue,old/*,dif,porcentage,distance*/;
+    double med, stdev;
+    /*cpl_image *out;*/
+    short rx_loop, ry_loop, rz_loop;
+
+    int ilx=0;
+    int ily=0;
+    int mlx=0;
+    int mly=0;
+
+    float* pidata=NULL;
+    float* pmdata=NULL;
+
+    cpl_image* sc_img=NULL;
+    cpl_image* drs_img=NULL;
+
+
+    mlx=cpl_image_get_size_x(mask);
+    mly=cpl_image_get_size_y(mask);
+    ilx=cpl_image_get_size_x(im);
+    ily=cpl_image_get_size_y(im);
+
+    pmdata=cpl_image_get_data_float(mask);
+    pidata=cpl_image_get_data_float(im);
+
+
+    if ( mlx != ilx || mly != ily )
+    {
+        sinfo_msg_error(" data & mask images not compatible in size\n") ;
+        return NULL ;
+    }
+
+    /* allocate memory for sub cubes*/
+    szx = (rx * 2 ) + 1;
+    szy = (ry * 2 ) + 1;
+    szz = (rz * 2 ) + 1;
+
+    if ( NULL == ( sc_im = cpl_imagelist_new() ) )
+    {
+        sinfo_msg_error(" could not allocate memory for data subcube\n") ;
+        return NULL ;
+    }
+    for(i=0;i<szz;i++) {
+      sc_img=cpl_image_new(szx,szy,CPL_TYPE_FLOAT);
+      cpl_imagelist_set(sc_im,sc_img,i);
+    }
+
+    if ( NULL == ( drs_sc_mask = cpl_imagelist_new() ) )
+    {
+        sinfo_msg_error(" could not allocate memory for mask subcube\n") ;
+        return NULL ;
+    }
+    for(i=0;i<szz;i++) {
+      drs_img=cpl_image_new(szx,szy,CPL_TYPE_FLOAT);
+      cpl_imagelist_set(drs_sc_mask,drs_img,i);
+    }
+
+    count=0;
+    for ( i = 0 ; i < mlx; i++ )
+    {
+        for ( j = 0 ; j < mly ; j++ )
+        {
+        if ( i >= lowerI && i < highI && j >= lowerJ && j < highJ )
+        {
+
+        rx_loop = 1 ; ry_loop = 1 ; rz_loop = 1 ;
+        newValue = sinfo_new_c_bezier_correct_pixel_2D( i, j, im,
+                                                                mask,
+                                                                sc_im,
+                                                                drs_sc_mask,
+                                                                /* look,*/
+                                                                rx_loop,
+                                                                ry_loop,
+                                                                rz_loop,
+                                                                &med,
+                                                                &stdev,
+                                                                factor );
+            /* if NaN returned, increase size of sub cube
+                   until max radius is reached */
+        while ( newValue == ZERO && rx_loop < rx &&
+                        ry_loop < ry && rz_loop < rz )
+            {
+              rx_loop++ ; ry_loop++; rz_loop++;
+              /*sinfo_msg_warning("Increasing radius to %d,
+                        in %d %d", rx_loop, i, j) ;  */
+                   newValue = sinfo_new_c_bezier_correct_pixel_2D( i, j, im,
+                                                                      mask,
+                                                                      sc_im,
+                                                                    drs_sc_mask,
+                                                                    /*, look*/
+                                                                    rx_loop,
+                                                                    ry_loop,
+                                                                    rz_loop,
+                                                                    &med,
+                                                                    &stdev,
+                                                                    factor );
+            }
+        if ( isnan(newValue)) /*<= -3.e10 ZERO )*/
+            continue;
+
+        old = pidata[sinfo_im_xy(im,i,j)];
+        if ( newValue != old )
+            {
+            pidata[sinfo_im_xy(im,i,j)] = newValue;
+            /*sinfo_msg_warning("[%d,%d]=%f -> %f, med= %f,
+                      stdev=%f\n",i,j, old, newValue, med, stdev );*/
+            count++;
+            }
+        }
+        }
+    }
+
+
+    sinfo_msg("bad pixels count: %d\n",count);
+
+
+    cpl_imagelist_delete(sc_im);
+    cpl_imagelist_delete(drs_sc_mask);
+    return im;
+}
+
+float
+sinfo_new_c_bezier_correct_pixel(int ipos,
+                                 int jpos,
+                                 cpl_image * im,
+                                 cpl_image * mask,
+                     cpl_imagelist * sc_im,
+                                 cpl_imagelist * drs_sc_mask,
+                                 new_Lookup * look,
+                                 short rx,
+                                 short ry,
+                                 short rz )
+{
+    short ic, jc, kc, ii, jj, kk/*, sjj, skk*/,is,js,ks;
+    short i, j, k, indexJ, indexI, lx, ly, lz, szx, szy, szz;
+    /*float indexIf,indexJf,sp;*/
+    cpl_image * X, * Y, * Z, * hX;
+    cpl_imagelist  * id, * jd;
+
+    int idlx=0;
+    int idly=0;
+    int idnp=0;
+
+    int drslx=0;
+    int drsly=0;
+    int drsnp=0;
+
+
+    float* pXdata=NULL;
+    float* pYdata=NULL;
+    float* pZdata=NULL;
+    float* phXdata=NULL;
+    float* pidata=NULL;
+    float* pmdata=NULL;
+    float* piddata=NULL;
+    float* pjddata=NULL;
+    float* pscdata=NULL;
+    float* pdrsdata=NULL;
+
+    cpl_image* id_img=NULL;
+    cpl_image* jd_img=NULL;
+    cpl_image* sc_img=NULL;
+    cpl_image* drs_img=NULL;
+
+    X  = look -> X;
+    Y  = look -> Y;
+    Z  = look -> Z;
+    hX = look -> hX;
+    id = look -> id;
+    jd = look -> jd;
+
+    /*
+      phXdata=cpl_image_get_data_float(hX);
+      if ( phXdata[sinfo_im_xy( hX, ipos, jpos)] > 1 )
+    {
+    sinfo_msg_error(" double hit in position [%d,%d]=%f, "
+                        "can not correct\n",
+        ipos,jpos,phXdata[sinfo_im_xy(hX,ipos,jpos)]) ;
+    return ( -2e10 );
+    }*/
+
+    pidata=cpl_image_get_data_float(im);
+    pmdata=cpl_image_get_data_float(mask);
+
+    phXdata=cpl_image_get_data_float(hX);
+    if ( phXdata[sinfo_im_xy( hX, ipos, jpos)] < 1 )
+    {
+    /*sinfo_msg_error("no lookup in position [%d,%d]=%f, can not correct",
+      ipos,jpos,phXdata[sinfo_im_xy(hX,ipos,jpos)]) ;*/
+    return ( ZERO );
+    }
+    pXdata=cpl_image_get_data_float(X);
+    pYdata=cpl_image_get_data_float(Y);
+    pZdata=cpl_image_get_data_float(Z);
+
+
+    ic = pXdata[sinfo_im_xy( X, ipos, jpos)];
+    jc = pYdata[sinfo_im_xy( Y, ipos, jpos)];
+    kc = pZdata[sinfo_im_xy( Z, ipos, jpos)];
+    /*if ( !(ipos % 16 )  )*/
+#ifdef DEBUG
+    sinfo_msg_debug("Correcting bad pixel : ipos=%d,jpos=%d, "
+                    "in Cube -> ic=%d, jc=%d, kc=%d\n",
+                    ipos,jpos, ic, jc, kc );
+#endif
+    /*limit to start not before the beginning of the cube*/
+    ii = ic - rx; if ( ii < 0 ) ii = 0;
+    jj = jc - ry; if ( jj < 0 ) jj = 0;
+    kk = kc - rz; if ( kk < 0 ) kk = 0;
+
+#ifdef DEBUG
+    sinfo_msg_debug("Start Point in Cube -> ii=%d,jj=%d,kk=%d\n", ii, jj, kk );
+#endif
+
+    /*limit to end not outside of the cube */
+    szx = (rx * 2 ) + 1;
+    szy = (ry * 2 ) + 1;
+    szz = (rz * 2 ) + 1;
+
+    idlx=cpl_image_get_size_x(cpl_imagelist_get(id,0));
+    idly=cpl_image_get_size_y(cpl_imagelist_get(id,0));
+    idnp=cpl_imagelist_get_size(id);
+
+    lx = idlx;
+    ly = idly;
+    lz = idnp;
+
+    if ( ( ic + rx ) >= idlx )
+    szx = szx - ( (ic+rx)-(lx-1) );
+
+    if ( ( jc + ry ) >= idly )
+    szy = szy - ( (jc+ry)-(ly-1) );
+
+    if ( ( kc + rz ) >= idnp )
+    szz = szz - ( (kc+rz)-(lz-1) );
+
+    drslx=cpl_image_get_size_x(cpl_imagelist_get(drs_sc_mask,0));
+    drsly=cpl_image_get_size_y(cpl_imagelist_get(drs_sc_mask,0));
+    drsnp=cpl_imagelist_get_size(drs_sc_mask);
+#ifdef DEBUG
+
+
+    sinfo_msg_error("Size of subcube: szx=%d,szy=%d,szz=%d\n", szx, szy, szz );
+    /*fill whole mask with not available*/
+    sinfo_msg_error("Fill Mask subcube of size: %d,%d,%d, with NOINFO\n",
+                     drslx, drsly,  drsnp);
+#endif
+    for( i = 0; i < drslx; i++) {
+      for( j = 0; j < drsly; j++) {
+    for( k = 0; k < drsnp; k++) {
+      drs_img=cpl_imagelist_get(drs_sc_mask,k);
+          pdrsdata=cpl_image_get_data_float(drs_img);
+      pdrsdata[sinfo_cu_xy(drs_sc_mask,i,j)] = cubePT_NOINFO;
+    }
+      }
+    }
+
+     for( i = ii,is=0;  i < ii+szx; i++,is++)
+     {
+     for( j = jj,js=0;  j < jj+szy; j++,js++)
+         {
+         for( k = kk,ks=0;  k < kk+szz; k++,ks++)
+         {
+#ifdef DEBUG
+         sinfo_msg_debug("i=%d j=%d k=%d is=%d ij=%d ik=%d",
+                                  i,j,k,is,js,ks);
+#endif
+                 id_img=cpl_imagelist_get(id,k);
+                 jd_img=cpl_imagelist_get(jd,k);
+                 piddata=cpl_image_get_data_float(id_img);
+                 pjddata=cpl_image_get_data_float(jd_img);
+
+                 drs_img=cpl_imagelist_get(drs_sc_mask,ks);
+                 pdrsdata=cpl_image_get_data_float(drs_img);
+                 sc_img=cpl_imagelist_get(sc_im,ks);
+                 pscdata=cpl_image_get_data_float(sc_img);
+
+         indexI = sinfo_new_nint( piddata[sinfo_cu_xy(id,i,j)] );
+         indexJ = sinfo_new_nint( pjddata[sinfo_cu_xy(jd,i,j)] );
+         if ( indexJ <= -1 || indexJ>=2048 || indexI == -1 )
+           {
+             pdrsdata[sinfo_cu_xy(drs_sc_mask,is,js)] = cubePT_NOINFO;
+             continue;
+           }
+         pscdata[sinfo_cu_xy(sc_im,is,js)]  =
+                         pidata[sinfo_im_xy(im,indexI,indexJ)];
+         pdrsdata[sinfo_cu_xy(drs_sc_mask,is,js)]  =
+                         pmdata[sinfo_im_xy(mask,indexI,indexJ)];
+#ifdef DEBUG
+        sinfo_msg_debug("Cube i=%d, j=%d, k=%d  ;"
+                                "  Sub is=%d, js=%d, ks=%d  ;"
+                                "  Plane I=%d,J=%d ; mask %f ; im %f",
+                        i, j, k, is, js, ks, indexI, indexJ,
+                                mask -> data[sinfo_im_xy(mask,indexI,indexJ)],
+                                im   -> data[sinfo_im_xy(im,indexI,indexJ)]);
+#endif
+
+         }
+         }
+     }
+
+
+    /*signal to correct this pixel*/
+     drs_img=cpl_imagelist_get(drs_sc_mask,rz);
+     pdrsdata=cpl_image_get_data_float(drs_img);
+    pdrsdata[sinfo_cu_xy(drs_sc_mask,rx,ry)] = cubePT_FIND;
+    return ( sinfo_new_c_bezier_interpol( sc_im, drs_sc_mask ) );
+}
+
+float
+sinfo_new_c_bezier_correct_pixel_2D(int ipos,
+                                    int jpos,
+                                    cpl_image * im,
+                                    cpl_image * mask,
+                        cpl_imagelist * sc_im,
+                                    cpl_imagelist * drs_sc_mask,
+                                    /* Lookup * look,*/
+                                    short rx, short ry,
+                                    short rz ,
+                                    double *med ,
+                        double *stdev,
+                                    float factor )
+{
+    short ic, jc, kc, ii, jj, kk/*, sjj, skk*/,is,js,ks;
+    short i, j, k, indexJ, indexI, lx, ly, lz, szx, szy, szz;
+    double sum,aux;
+    int counter;
+    float sumarr[100];
+
+
+    int ilx=0;
+    int ily=0;
+
+    int drslx=0;
+    int drsly=0;
+    int drsnp=0;
+
+
+    float* pidata=0;
+    float* pmdata=0;
+    float* pscdata=0;
+    float* pdrsdata=0;
+
+    cpl_image* drs_img=NULL;
+    cpl_image* sc_img=NULL;
+
+    jc = 0;
+    ic = ipos;
+    kc = jpos;
+    sinfo_msg_debug("Correcting bad pixel : ipos=%d,jpos=%d, "
+                    "in Cube -> ic=%d, jc=%d, kc=%d", ipos,jpos, ic, jc, kc );
+    /*limit to start not before the beginning of the cube*/
+    ii = ic - rx; if ( ii < 0 ) ii = 0;
+    jj = jc - ry; if ( jj < 0 ) jj = 0;
+    kk = kc - rz; if ( kk < 0 ) kk = 0;
+
+    sinfo_msg_debug("Start Point in Cube -> ii=%d,jj=%d,kk=%d", ii, jj, kk );
+
+    ilx=cpl_image_get_size_x(im);
+    ily=cpl_image_get_size_y(im);
+
+    /*limit to end not outside of the cube */
+    szx = (rx * 2 ) + 1;
+    szy = (ry * 2 ) + 1;
+    szz = (rz * 2 ) + 1;
+    lx = ilx;
+    ly = ily;
+    lz = ily;
+    if ( ( ic + rx ) >= ilx )
+    szx = szx - ( (ic+rx)-(lx-1) );
+
+    if ( ( jc + ry ) >= ily )
+    szy = szy - ( (jc+ry)-(ly-1) );
+
+    if ( ( kc + rz ) >= ily )
+    szz = szz - ( (kc+rz)-(lz-1) );
+
+#ifdef DEBUG
+    drslx=cpl_image_get_size_x(cpl_imagelist_get(drs_sc_mask,0));
+    drsly=cpl_image_get_size_y(cpl_imagelist_get(drs_sc_mask,0));
+    drsnp=cpl_imagelist_get_size(drs_sc_mask);
+    sinfo_msg_debug("Size of subcube : szx=%d,szy=%d,szz=%d", szx, szy, szz );
+    /*fill whole mask with not available*/
+    sinfo_msg_debug("Fill Mask subcube of size:%d,%d,%d, with NOINFO",
+                    drslx, drsly,  drsnp);
+#endif
+    for( i = 0; i < drslx; i++) {
+      for( j = 0; j < drsly; j++) {
+    for( k = 0; k < drsnp; k++) {
+      drs_img=cpl_imagelist_get(drs_sc_mask,k);
+      pdrsdata=cpl_image_get_data_float(drs_img);
+      pdrsdata[sinfo_cu_xy(drs_sc_mask,i,j)] = cubePT_NOINFO;
+    }
+      }
+    }
+    counter = 0;
+    sum=0;
+    memset(sumarr,0x00,sizeof(sumarr));
+    pidata=cpl_image_get_data(im);
+    pmdata=cpl_image_get_data(mask);
+
+     for( i = ii,is=0;  i < ii+szx; i++,is++)
+     {
+     for( j = jj,js=0;  j < jj+szy; j++,js++)
+         {
+         for( k = kk,ks=0;  k < kk+szz; k++,ks++)
+         {
+#ifdef DEBUG
+         sinfo_msg_debug("i=%d j=%d k=%d is=%d ij=%d ik=%d",
+                                  i,j,k,is,js,ks);
+#endif
+         indexI = i;
+         indexJ = k;
+         if ( isnan(pidata[sinfo_im_xy(mask,indexI,indexJ)]) )
+           pmdata[sinfo_im_xy(mask,indexI,indexJ)] = 0;
+
+         if ( pmdata[sinfo_im_xy(mask,indexI,indexJ)] == 1 &&
+                            ( indexI != ipos || indexJ != jpos) )
+           {
+             /*sumarr[counter] = pidata[sinfo_im_xy(im,indexI,indexJ)];*/
+             sum = sum + pidata[sinfo_im_xy(im,indexI,indexJ)];
+             counter++;
+           }
+         sc_img=cpl_imagelist_get(sc_im,ks);
+         pscdata[sinfo_cu_xy(sc_im,is,js)]=
+                        pidata[sinfo_im_xy(im,indexI,indexJ)];
+                 drs_img=cpl_imagelist_get(drs_sc_mask,ks);
+                 pdrsdata=cpl_image_get_data_float(drs_img);
+         pdrsdata[sinfo_cu_xy(drs_sc_mask,is,js)]=
+                         pmdata[sinfo_im_xy(mask,indexI,indexJ)];
+#ifdef DEBUG
+         sinfo_msg_debug("Cube i=%d, j=%d, k=%d  ;  "
+                                 "Sub is=%d, js=%d, ks=%d  ; "
+                                " Plane I=%d,J=%d ; mask %f ; im %f",
+                        i, j, k, is, js, ks, indexI, indexJ,
+                                pmdata[sinfo_im_xy(mask,indexI,indexJ)],
+                                pidata[sinfo_im_xy(im,indexI,indexJ)]);
+#endif
+
+         }
+         }
+     }
+
+
+    /*signal to correct this pixel*/
+    drs_img=cpl_imagelist_get(drs_sc_mask,rz);
+    pdrsdata=cpl_image_get_data_float(drs_img);
+    pdrsdata[sinfo_cu_xy(drs_sc_mask,rx,ry)] = cubePT_FIND;
+    if ( counter )
+    /**med = sinfo_median(sumarr,counter);*/
+    *med = sum/counter;
+    else
+    return(pidata[sinfo_im_xy(im,ipos,jpos)]);
+
+    /*sinfo_msg_debug("%f %f %d\n",
+                      sum ,pidata[sinfo_im_xy(im,ipos,jpos)], counter);*/
+
+
+
+    sum =0;
+    counter=0;
+    for( i = ii,is=0;  i < ii+szx; i++,is++)
+      {
+    for( j = jj,js=0;  j < jj+szy; j++,js++)
+      {
+        for( k = kk,ks=0;  k < kk+szz; k++,ks++)
+          {
+        drs_img=cpl_imagelist_get(drs_sc_mask,ks);
+        pdrsdata=cpl_image_get_data_float(drs_img);
+        indexI = i;
+        indexJ = k;
+        if ( pdrsdata[sinfo_cu_xy(drs_sc_mask,is,js)] == 1 &&
+                         ( indexI != ipos || indexJ != jpos) )
+          {
+              sc_img=cpl_imagelist_get(sc_im,ks);
+              pscdata=cpl_image_get_data_float(sc_img);
+
+            sum=sum+((pscdata[sinfo_cu_xy(drs_sc_mask,is,js)]- *med) *
+             (pscdata[sinfo_cu_xy(drs_sc_mask,is,js)] - *med ) );
+            counter++;
+          }
+          }
+      }
+      }
+
+    aux = sum;
+    sum   = sum / (counter - 1);
+    *stdev = sqrt( sum );
+
+    if ( (fabs( pidata[sinfo_im_xy(im,ipos,jpos)] - *med ) >
+         factor * *stdev) ||
+	 isnan(pidata[sinfo_im_xy(im,ipos,jpos)]) )
+    {
+    /*sinfo_msg_debug("[%d,%d]: distance to mean = %f,"
+                          " thres =%f sum=%f, stdev=%f, counter=%d, aux= %f",
+                ipos,jpos, fabs( pidata[sinfo_im_xy(im,ipos,jpos)] - *med),
+                    factor * *stdev, sum,*stdev, counter,aux );
+    pmdata[sinfo_im_xy(mask,ipos,jpos)] = 0;*/
+    return ( sinfo_new_c_bezier_interpol( sc_im, drs_sc_mask ) );
+    }
+    return(pidata[sinfo_im_xy(im,ipos,jpos)]);
+}
+
+
+
+float
+sinfo_new_c_bezier_interpol( cpl_imagelist * im, cpl_imagelist * action )
+{
+    short pos;
+    unsigned short i,j,k;
+    new_XYZW  indata[1000];
+    new_XYZW  res;
+    new_XYZW  selected;
+    float step,cumstep,distance,selected_distance;
+    new_Dim *point=NULL;
+    double munk;
+    int ilx=0;
+    int ily=0;
+    int inp=0;
+
+    float* padata=NULL;
+    float* pidata=NULL;
+    cpl_image* i_img=NULL;
+    cpl_image* a_img=NULL;
+
+    selected.w = 0;
+    memset(indata,0x00,1000*sizeof(new_XYZW));
+    ilx=cpl_image_get_size_x(cpl_imagelist_get(im,0));
+    ily=cpl_image_get_size_y(cpl_imagelist_get(im,0));
+    inp=cpl_imagelist_get_size(im);
+
+    pos=0;
+    for( i=0; i < ilx; i++)
+    {
+    for( j=0; j < ily; j++)
+        {
+        for( k=0; k < inp; k++)
+        {
+          a_img=cpl_imagelist_get(action,k);
+                  padata=cpl_image_get_data_float(a_img);
+          i_img=cpl_imagelist_get(action,k);
+                  pidata=cpl_image_get_data_float(i_img);
+        if ( padata[sinfo_cu_xy(action,i,j)] == cubePT_USE )
+            {
+#ifdef DEBUG
+            sinfo_msg_debug("Used im[%d,%d,%d]=%lf\n",
+                                      i,j,k,pidata[sinfo_im_xy(im,i,j)]);
+#endif
+            indata[pos].x = i;
+            indata[pos].y = j;
+            indata[pos].z = k;
+            indata[pos].w = pidata[sinfo_cu_xy(im,i,j)];
+            pos++;
+            }
+        else
+            {
+            if ( padata[sinfo_cu_xy(action,i,j)] == cubePT_FIND )
+            {
+               (*point).x = i;
+               (*point).y = j;
+               (*point).z = k;
+#ifdef DEBUG
+            sinfo_msg_debug("Find for im[%d,%d,%d]=%lf reason:%f",
+                        i,j,k,pidata[sinfo_im_xy(im,i,j)],
+                        padata[sinfo_cu_xy(action,i,j)]);
+#endif
+            }
+            else
+            {
+#ifdef DEBUG
+            sinfo_msg_debug("Ignored im[%d,%d,%d]=%lf reason:%f",
+                        i,j,k,pidata[sinfo_im_xy(im,i,j)],
+                        padata[sinfo_im_xy(action,i,j)]);
+#endif
+            }
+            }
+        }
+        }
+    }
+
+    /**/
+    if ( pos < 2 )
+    {
+#ifdef DEBUG
+       sinfo_msg_debug("subcube contains no valid pixels "
+                       "to use in iterpolation");
+#endif
+    /*i_img=cpl_imagelist_get((*point).z);
+          pidata=cpl_image_get_data_float(i_img);
+          return( pidata[sinfo_im_xy(im,(*point).x,(*point).y)] );*/
+    return( cubeNONEIGHBOR );
+
+    }
+
+
+    step    = 0.01;
+    cumstep = 0.0;
+    selected_distance=1000;
+    munk = pow( 1.0-cumstep, (double)pos - 1 );
+    for ( i = 0 ; ( i < 100 ) && ( munk != 0.0 ); i++ )
+    {
+    memset( &res, 0x00, sizeof(new_XYZW) );
+    sinfo_new_bezier( indata, pos-1, cumstep, munk, &res);
+    distance = sqrt( pow( ((*point).x-res.x), 2)+
+                     pow( ((*point).y-res.y), 2)+
+                     pow( ((*point).z-res.z), 2) );
+    /*sinfo_msg_debug("%lf %lf %lf %lf %lf\n",
+                          res.x,res.y,res.z,res.w,distance);*/
+    if ( distance < selected_distance )
+        {
+        selected_distance = distance;
+        selected.x = res.x;
+        selected.y = res.y;
+        selected.z = res.z;
+        selected.w = res.w;
+        }
+    cumstep = cumstep + step;
+    munk = pow( 1.0 - cumstep, (double)pos - 1 );
+
+    }
+
+#ifdef DEBUG
+   sinfo_msg_debug("Selected %lf %lf %lf %lf, distance=%lf",
+                    selected.x,selected.y,selected.z,
+                    selected.w,selected_distance);
+#endif
+   i_img=cpl_imagelist_get(im,(*point).z);
+    pidata=cpl_image_get_data_float(i_img);
+    pidata[sinfo_cu_xy(im,(*point).x,(*point).y)] = selected.w;
+
+    return selected.w;
+}
+
+
+
+int
+sinfo_new_bezier(new_XYZW *p,int n,double mu,double munk,new_XYZW *res )
+{
+   int k, kn, nn, nkn;
+   double blend, muk;
+
+   muk = 1;
+   for ( k = 0; k <= n; k++ ) {
+      nn = n;
+      kn = k;
+      nkn = n - k;
+      blend = muk * munk;
+      muk *= mu;
+      munk /= ( 1.0 - mu );
+      while ( nn >= 1 ) {
+         blend *= (double)nn;
+         nn--;
+         if ( kn > 1 ) {
+            blend /= (double)kn;
+            kn--;
+         }
+         if ( nkn > 1 ) {
+            blend /= (double)nkn;
+            nkn--;
+         }
+      }
+      res -> x += p[k].x * blend;
+      res -> y += p[k].y * blend;
+      res -> z += p[k].z * blend;
+      res -> w += p[k].w * blend;
+   }
+   return( 0 );
+}
+
+int
+sinfo_new_c_create_XYZ( new_Lookup *l )
+{
+    cpl_image *imX,*imY,*imZ,*imcX;
+    short i,j,k,indexI,indexJ,x,y,z;
+    int size;
+    int idlx=0;
+    int idly=0;
+    int idnp=0;
+    float* piddata=NULL;
+    float* pjddata=NULL;
+    float* pXdata=NULL;
+    float* pYdata=NULL;
+    float* pZdata=NULL;
+    float* phXdata=NULL;
+
+    cpl_image* i_img=NULL;
+    cpl_image* j_img=NULL;
+
+    idlx=cpl_image_get_size_x(cpl_imagelist_get(l->id,0));
+    idly=cpl_image_get_size_y(cpl_imagelist_get(l->id,0));
+    idnp=cpl_imagelist_get_size(l->id);
+
+    size = idlx*idly;
+    /* allocate memory */
+    if ( NULL == (imX = cpl_image_new(size, size, CPL_TYPE_FLOAT)) )
+        {
+    sinfo_msg_error(" could not allocate memory for X !\n") ;
+    return -1 ;
+        }
+    if ( NULL == (imY = cpl_image_new(size, size, CPL_TYPE_FLOAT)) )
+        {
+    sinfo_msg_error(" could not allocate memory for Y !\n") ;
+    return -1 ;
+        }
+    if ( NULL == (imZ = cpl_image_new(size, size, CPL_TYPE_FLOAT)) )
+        {
+    sinfo_msg_error(" could not allocate memory for Z !\n") ;
+    return -1 ;
+        }
+    if ( NULL == (imcX = cpl_image_new(size, size, CPL_TYPE_FLOAT)) )
+        {
+    sinfo_msg_error(" could not allocate memory for cX !\n") ;
+    return -1 ;
+        }
+
+    l -> X  = imX;
+    l -> Y  = imY;
+    l -> Z  = imZ;
+    l -> hX = imcX;
+
+    /*Round id*/
+    for( i = 0; i < idlx; i++)
+    {
+    for( j = 0; j < idly; j++)
+        {
+        for( k = 0; k < idnp; k++)
+        {
+          i_img=cpl_imagelist_get(l->id,k);
+          piddata=cpl_image_get_data_float(i_img);
+          piddata[sinfo_cu_xy(l->id,i,j)] =
+                  (float)sinfo_new_nint(piddata[sinfo_cu_xy(l->id,i,j)]);
+        }
+        }
+    }
+
+    /*Round jd*/
+    for( i = 0; i < idlx; i++)
+    {
+    for( j = 0; j < idly; j++)
+        {
+        for( k = 0; k < idnp; k++)
+        {
+          j_img=cpl_imagelist_get(l->jd,k);
+          pjddata=cpl_image_get_data_float(j_img);
+          pjddata[sinfo_cu_xy(l->jd,i,j)] =
+                 (float)sinfo_new_nint(pjddata[sinfo_cu_xy(l->jd,i,j)]);
+        }
+        }
+    }
+
+    /*Fill with -1 X Y Z*/
+    for( i = 0; i < cpl_image_get_size_x(l -> X); i++)
+    {
+    for( j = 0; j < cpl_image_get_size_y(l -> X); j++)
+        {
+          pXdata=cpl_image_get_data_float(l->X);
+          pYdata=cpl_image_get_data_float(l->Y);
+          pZdata=cpl_image_get_data_float(l->Z);
+
+          pXdata[sinfo_im_xy(l->X,i,j)] = ZERO;
+          pYdata[sinfo_im_xy(l->Y,i,j)] = ZERO;
+          pZdata[sinfo_im_xy(l->Z,i,j)] = ZERO;
+        }
+    }
+#define  FORW
+#ifdef BACK
+    for( x = idlx - 1;x>=0;x--)
+    {
+    for( y = idly - 1;y>=0;y--)
+        {
+        for( z = idnp - 1;z>=0;z--)
+#endif
+#ifdef FORW
+    for( x = 0; x <  idlx; x++)
+    {
+    for( y = 0; y < idly; y++)
+        {
+        for( z = 0; z < idnp; z++)
+#endif
+          {
+        i_img=cpl_imagelist_get(l->id,z);
+        piddata=cpl_image_get_data_float(i_img);
+        j_img=cpl_imagelist_get(l->jd,z);
+        pjddata=cpl_image_get_data_float(j_img);
+        indexI = piddata [sinfo_cu_xy(l->id,x,y)];
+        indexJ = pjddata [sinfo_cu_xy(l->jd,x,y)];
+        if ( indexI > 0.0  && indexI < size  &&
+             indexJ > 0.0  && indexJ < size )
+            {
+            /*sinfo_msg_debug("%d %d %d = %f, %f\n",
+                      x,y,z,(float)ICube(x,y,z),(float)JCube(x,y,z));*/
+              pXdata=cpl_image_get_data_float(l->X);
+              pYdata=cpl_image_get_data_float(l->Y);
+              pZdata=cpl_image_get_data_float(l->Z);
+              phXdata=cpl_image_get_data_float(l->hX);
+
+              pXdata[sinfo_im_xy(l->X ,indexI,indexJ)] = x;
+              phXdata[sinfo_im_xy(l->hX,indexI,indexJ)] =
+                         phXdata[sinfo_im_xy(l->hX,indexI,indexJ)] + 1;
+
+            pYdata[sinfo_im_xy(l->Y ,indexI,indexJ)] = y;
+            /*phXdata[sinfo_im_xy(l->hX,indexI,indexJ)] =
+                      phXdata[sinfo_im_xy(l->hX,indexI,indexJ)] + 1;*/
+
+            pZdata[sinfo_im_xy(l->Z ,indexI,indexJ)] = z;
+            /*phXdata[sinfo_im_xy(l->hX,indexI,indexJ)] =
+                      phXdata[sinfo_im_xy(l->hX,indexI,indexJ)] + 1;*/
+            }
+        }
+        }
+    }
+
+
+    sinfo_msg("Filled X Y Z , cX cY cZ 2D frames\n");
+    return(0);
+}
+
+/**
+ at name sinfo_new_Lookup
+ at brief computes a new look-up object
+ at return pointer to new look-up object
+*/
+new_Lookup *
+sinfo_new_lookup( void )
+{
+    new_Lookup *l;
+    l = (new_Lookup*)cpl_calloc(1, sizeof(new_Lookup));
+    return (l);
+}
+/**
+ at name sinfo_new_destroy_lookup
+ at brief frees a new Lookup object
+ at param l pointer to look-up object
+ at return void
+*/
+void
+sinfo_new_destroy_lookup( new_Lookup *l )
+{
+    if ( l )
+    cpl_free(l);
+}
+/**
+ at name sinfo_new_change_mask
+ at brief frees a new Lookup object
+ at param mask pointer to bad pixel map
+ at param im pointer to image
+ at return if succes 0, else -1
+*/
+int
+sinfo_new_change_mask (cpl_image * mask, cpl_image * im)
+{
+    int i ;
+    int mlx=0;
+    int mly=0;
+    int ilx=0;
+    int ily=0;
+    float* pidata=NULL;
+    float* pmdata=NULL;
+
+    if (mask == NULL || im == NULL) return -1 ;
+    ilx=cpl_image_get_size_x(im);
+    ily=cpl_image_get_size_y(im);
+    pidata=cpl_image_get_data_float(im);
+
+    mlx=cpl_image_get_size_x(mask);
+    mly=cpl_image_get_size_y(mask);
+    pmdata=cpl_image_get_data_float(mask);
+
+    for ( i = 0 ; i < (int) ilx*ily ; i++ )
+    {
+        if (isnan(pidata[i]))
+        {
+            pmdata[i] = 0. ;
+        }
+    }
+    return 0 ;
+}
+
+
+/**
+ at name sinfo_new_c_bezier_find_cosmic
+ at brief Find cosmic rays in an image
+ at param im pointer to image
+ at param mask pointer to bad pixel map
+ at param look pointer to look-up table
+ at param rx radius on X
+ at param ry radius on Y
+ at param rz radius on Z
+ at param lowerI  lower I
+ at param highI   higher I
+ at param highJ   higher J
+ at param factor  threshold factor
+
+ at return if succes 0, else -1
+*/
+cpl_image *
+sinfo_new_c_bezier_find_cosmic( cpl_image *im,
+                                      cpl_image *mask,
+                                      new_Lookup *look,
+                                      short rx,
+                                      short ry,
+                                      short rz,
+                          short lowerI,
+                                      short highI,
+                                      short lowerJ,
+                                      short highJ,
+                                      float factor )
+{
+
+    int i,j,count;
+    cpl_imagelist * sc_im,* drs_sc_mask;
+    short szx,szy,szz;
+    float /*ant,*/newValue,old/*,dif,porcentage,distance*/;
+    double med, stdev;
+    /*cpl_image *out;*/
+    short rx_loop, ry_loop, rz_loop;
+
+
+    cpl_image* o_img=NULL;
+    float* pmdata=NULL;
+    float* pidata=NULL;
+
+
+
+    int ilx=0;
+    int ily=0;
+
+    int mlx=0;
+    int mly=0;
+
+
+
+
+    mlx=cpl_image_get_size_x(mask);
+    mly=cpl_image_get_size_y(mask);
+    pmdata=cpl_image_get_data_float(mask);
+
+    ilx=cpl_image_get_size_x(im);
+    ily=cpl_image_get_size_y(im);
+    pidata=cpl_image_get_data_float(im);
+
+    if ( mlx != ilx || mly != ily )
+    {
+        sinfo_msg_error(" data & mask images not compatible in size\n") ;
+        return NULL ;
+    }
+
+    /* allocate memory for sub cubes*/
+    szx = (rx * 2 ) + 1;
+    szy = (ry * 2 ) + 1;
+    szz = (rz * 2 ) + 1;
+
+    if ( NULL == ( sc_im = cpl_imagelist_new() ) )
+    {
+        sinfo_msg_error(" could not allocate memory for data subcube\n") ;
+        return NULL ;
+    }
+    for(i=0;i<szz;i++){
+      o_img=cpl_image_new(szx,szy,CPL_TYPE_FLOAT);
+      cpl_imagelist_set(sc_im,o_img,i);
+    }
+
+    if ( NULL == ( drs_sc_mask = cpl_imagelist_new() ) )
+    {
+        sinfo_msg_error(" could not allocate memory for mask subcube\n") ;
+        return NULL ;
+    }
+
+    for(i=0;i<szz;i++){
+      o_img=cpl_image_new(szx,szy,CPL_TYPE_FLOAT);
+      cpl_imagelist_set(drs_sc_mask,o_img,i);
+    }
+
+
+
+
+    count=0;
+    for ( i = 0 ; i < mlx; i++ )
+    {
+        for ( j = 0 ; j < mly ; j++ )
+        {
+        if ( i >= lowerI && i < highI && j >= lowerJ && j < highJ )
+        {
+
+        rx_loop = 1 ; ry_loop = 1 ; rz_loop = 1 ;
+        newValue = sinfo_new_c_bezier_correct_cosmic( i, j, im,
+                                                              mask, sc_im,
+                                                              drs_sc_mask,
+                                                              look,
+                                                              rx_loop,
+                                                              ry_loop,
+                                                              rz_loop,
+                                                              &med,
+                                                              &stdev,
+                                                              factor );
+            /* if no valid neighboors are found, increase size of
+                   sub cube until max radius is reached */
+        while ( newValue == cubeNONEIGHBOR && rx_loop < rx &&
+                        ry_loop < ry && rz_loop < rz )
+            {
+              rx_loop++ ; ry_loop++; rz_loop++;
+              /*sinfo_msg_debug("Increasing radius to %d, in %d %d",
+                          rx_loop, i, j) ;  */
+                   newValue = sinfo_new_c_bezier_correct_cosmic( i, j, im,
+                                                                    mask,
+                                                                    sc_im,
+                                                                    drs_sc_mask,
+                                                                    look,
+                                                                    rx_loop,
+                                                                    ry_loop,
+                                                                    rz_loop,
+                                                                    &med,
+                                                                    &stdev,
+                                                                     factor );
+            }
+        /*give up on increasing the size*/
+        if ( isnan(newValue) || newValue == cubeNONEIGHBOR )
+                /*<= -3.e10 ZERO )*/
+            continue;
+
+        old = pidata[sinfo_im_xy(im,i,j)];
+        if ( newValue != old )
+            {
+            pidata[sinfo_im_xy(im,i,j)] = newValue;
+            /*sinfo_msg_debug("[%d,%d]=%f -> %f, med= %f, stdev=%f",
+                      i,j, old, newValue, med, stdev ); */
+            count++;
+            }
+        }
+        }
+    }
+
+
+    sinfo_msg_debug("bad pixels count: %d",count);
+
+
+    cpl_imagelist_delete(sc_im);
+    cpl_imagelist_delete(drs_sc_mask);
+    return im;
+}
+
+
+/**
+ at name sinfo_new_c_bezier_correct_cosmic
+ at brief Correct cosmic rays in an image
+ at param im pointer to image
+ at param mask pointer to bad pixel map
+ at param sc_im image list
+ at param drs_sc_mask list of image maps
+ at param look pointer to look-up table
+ at param rx radius on X
+ at param ry radius on Y
+ at param rz radius on Z
+ at param med  output median
+ at param stdev output standard deviation
+ at param factor  threshold factor
+
+ at return if succes 0, else -1
+*/
+float
+sinfo_new_c_bezier_correct_cosmic(int ipos,
+                                  int jpos,
+                                  cpl_image * im,
+                                  cpl_image * mask,
+                      cpl_imagelist * sc_im,
+                                  cpl_imagelist * drs_sc_mask,
+                                  new_Lookup * look,
+                                  short rx,
+                                  short ry,
+                                  short rz ,
+                                  double *med ,
+                      double *stdev,
+                                  float factor )
+{
+    short ic, jc, kc, ii, jj, kk/*, sjj, skk*/,is,js,ks;
+    short i, j, k, indexJ, indexI, lx, ly, lz, szx, szy, szz;
+    /*float indexIf,indexJf,sp;*/
+    cpl_image * X, * Y, * Z, * hX;
+    cpl_imagelist  * id, * jd;
+    short counter;
+    double sum;
+    float* phXdata=NULL;
+    float* pXdata=NULL;
+    float* pYdata=NULL;
+    float* pZdata=NULL;
+
+    float* pimdata=NULL;
+    float* pscdata=NULL;
+    float* pdrsdata=NULL;
+    float* piddata=NULL;
+    float* pjddata=NULL;
+    float* pmaskdata=NULL;
+
+
+    int idlx=0;
+    int idly=0;
+    int idnp=0;
+
+    int drslx=0;
+    int drsly=0;
+    int drsnp=0;
+
+
+    X  = look -> X;
+    Y  = look -> Y;
+    Z  = look -> Z;
+    hX = look -> hX;
+    id = look -> id;
+    jd = look -> jd;
+
+    phXdata=cpl_image_get_data_float(hX);
+    /*if ( phXdata[sinfo_im_xy( hX, ipos, jpos)] > 1 )
+    {
+    sinfo_msg_error("double hit in position [%d,%d]=%f, can not correct",
+        ipos,jpos,phXdata[sinfo_im_xy(hX,ipos,jpos)]) ;
+    return ( -2e10 );
+    }*/
+    if ( phXdata[sinfo_im_xy( hX, ipos, jpos)] < 1 )
+    {
+    /*sinfo_msg_error("no lookup  in position [%d,%d]=%f, can not correct",
+      ipos,jpos,phXdata[sinfo_im_xy(hX,ipos,jpos)]) ;*/
+    return ( ZERO );
+    }
+
+    pXdata=cpl_image_get_data_float(X);
+    pYdata=cpl_image_get_data_float(Y);
+    pZdata=cpl_image_get_data_float(Z);
+
+    ic = pXdata[sinfo_im_xy( X, ipos, jpos)];
+    jc = pYdata[sinfo_im_xy( Y, ipos, jpos)];
+    kc = pZdata[sinfo_im_xy( Z, ipos, jpos)];
+    /*if ( !(ipos % 16 )  )*/
+#ifdef DEBUG
+    sinfo_msg_debug("Correcting bad pixel : ipos=%d,jpos=%d, "
+                    "in Cube -> ic=%d, jc=%d, kc=%d", ipos,jpos, ic, jc, kc );
+#endif
+    /*limit to start not before the beginning of the cube*/
+    ii = ic - rx; if ( ii < 0 ) ii = 0;
+    jj = jc - ry; if ( jj < 0 ) jj = 0;
+    kk = kc - rz; if ( kk < 0 ) kk = 0;
+
+#ifdef DEBUG
+    sinfo_msg_debug("Start Point in Cube -> ii=%d,jj=%d,kk=%d", ii, jj, kk );
+#endif
+
+    /*limit to end not outside of the cube */
+    szx = (rx * 2 ) + 1;
+    szy = (ry * 2 ) + 1;
+    szz = (rz * 2 ) + 1;
+
+    idlx = cpl_image_get_size_x(cpl_imagelist_get(id,0));
+    idly = cpl_image_get_size_y(cpl_imagelist_get(id,0));
+    idnp = cpl_imagelist_get_size(id);
+
+    lx = idlx;
+    ly = idly;
+    lz = idnp;
+    if ( ( ic + rx ) >= idlx )
+    szx = szx - ( (ic+rx)-(lx-1) );
+
+    if ( ( jc + ry ) >= idly )
+    szy = szy - ( (jc+ry)-(ly-1) );
+
+    if ( ( kc + rz ) >= idnp )
+    szz = szz - ( (kc+rz)-(lz-1) );
+
+#ifdef DEBUG
+    sinfo_msg_error("Size of subcube : szx=%d,szy=%d,szz=%d\n", szx, szy, szz );
+    /*fill whole mask with not available*/
+    drsnp=cpl_imagelist_get_size(drs_sc_mask);
+    drslx=cpl_image_get_size_x(cpl_imagelist_get(drs_sc_mask,0));
+    drsly=cpl_image_get_size_y(cpl_imagelist_get(drs_sc_mask,0));
+
+    sinfo_msg_error("Fill Mask subcube of size: %d,%d,%d, with NOINFO",
+                     drslx, drsly,  drsnp);
+#endif
+    for( i = 0; i < drslx; i++) {
+      for( j = 0; j < drsly; j++) {
+    for( k = 0; k < drsnp; k++) {
+      pdrsdata=cpl_image_get_data_float(cpl_imagelist_get(drs_sc_mask,k));
+      pdrsdata[sinfo_cu_xy(drs_sc_mask,i,j)] = cubePT_NOINFO;
+    }
+      }
+    }
+    pimdata=cpl_image_get_data_float(im);
+    pmaskdata=cpl_image_get_data_float(mask);
+    for( i = ii,is=0;  i < ii+szx; i++,is++)
+      {
+    for( j = jj,js=0;  j < jj+szy; j++,js++)
+      {
+        for( k = kk,ks=0;  k < kk+szz; k++,ks++)
+          {
+#ifdef DEBUG
+        sinfo_msg_debug("i=%d j=%d k=%d is=%d ij=%d ik=%d",
+                i,j,k,is,js,ks);
+#endif
+        piddata=cpl_image_get_data_float(cpl_imagelist_get(id,k));
+        pjddata=cpl_image_get_data_float(cpl_imagelist_get(id,k));
+          pdrsdata=cpl_image_get_data_float(cpl_imagelist_get(drs_sc_mask,ks));
+                pscdata=cpl_image_get_data_float(cpl_imagelist_get(sc_im,ks));
+
+
+        indexI = sinfo_new_nint( piddata[sinfo_cu_xy(id,i,j)] );
+        indexJ = sinfo_new_nint( pjddata[sinfo_cu_xy(jd,i,j)] );
+        if ( indexJ <= -1 || indexJ>=2048 || indexI == -1 )
+          {
+            pdrsdata[sinfo_cu_xy(drs_sc_mask,is,js)] = cubePT_NOINFO;
+            continue;
+          }
+        pscdata[sinfo_cu_xy(sc_im,is,js)]=
+                         pimdata[sinfo_im_xy(im,indexI,indexJ)];
+        pdrsdata[sinfo_cu_xy(drs_sc_mask,is,js)]=
+                         pmaskdata[sinfo_im_xy(mask,indexI,indexJ)];
+#ifdef DEBUG
+        sinfo_msg_debug("Cube i=%d, j=%d, k=%d  ; "
+                                " Sub is=%d, js=%d, ks=%d  ; "
+                                " Plane I=%d,J=%d ; mask %f ; im %f\n",
+                        i, j, k, is, js, ks, indexI, indexJ,
+                                pmaskdata[sinfo_im_xy(mask,indexI,indexJ)],
+                                pimdata[sinfo_im_xy(im,indexI,indexJ)]);
+#endif
+
+          }
+      }
+      }
+
+    /* ignoring the elements in the slitlet of the tested pixel */
+
+    for( i = 0; i < szx; i++) {
+      for( k = 0;  k < szz; k++) {
+    pdrsdata=cpl_image_get_data_float(cpl_imagelist_get(drs_sc_mask,k));
+    pdrsdata[sinfo_cu_xy(drs_sc_mask,i,ry)] = cubePT_NOINFO;
+      }
+    }
+/* now calculate mean and stdev in subcube */
+
+    counter = 0;
+    sum=0;
+    for( i = 0; i < szx; i++)
+      {
+    for( j = 0;  j < szy; j++)
+      {
+        for( k = 0;  k < szz; k++)
+          {
+        pdrsdata=cpl_image_get_data_float(cpl_imagelist_get(drs_sc_mask,k));
+        pscdata=cpl_image_get_data_float(cpl_imagelist_get(sc_im,k));
+        if (pscdata[sinfo_cu_xy(sc_im ,i ,j)] != ZERO &&
+                    pdrsdata[sinfo_cu_xy(drs_sc_mask,i ,j)] != cubePT_NOINFO)
+          {
+            sum = sum + pscdata[sinfo_cu_xy(sc_im ,i ,j)];
+            counter++;
+          }
+          }
+      }
+      }
+
+    *med = sum / counter ;
+
+    counter = 0;
+    sum=0;
+    for( i = 0; i < szx; i++)
+      {
+    for( j = 0;  j < szy; j++)
+      {
+        for( k = 0;  k < szz; k++)
+          {
+        pscdata=cpl_image_get_data_float(cpl_imagelist_get(sc_im,k));
+        pdrsdata=cpl_image_get_data_float(cpl_imagelist_get(drs_sc_mask,k));
+        if (pscdata[sinfo_cu_xy(sc_im ,i ,j)] != ZERO &&
+                    pdrsdata[sinfo_cu_xy(drs_sc_mask,i ,j)] != cubePT_NOINFO)
+          {
+               sum = sum + (pscdata[sinfo_cu_xy(sc_im ,i ,j)] - *med) *
+                                   (pscdata[sinfo_cu_xy(sc_im ,i ,j)] - *med) ;
+               counter++;
+          }
+          }
+      }
+      }
+
+    *stdev = sqrt( sum / ( counter - 1 ) );
+
+
+    if ( (fabs( pimdata[sinfo_im_xy(im,ipos,jpos)] - *med ) >
+          factor * *stdev) ||
+          isnan(pimdata[sinfo_im_xy(im,ipos,jpos)]) )
+    {
+    pdrsdata=cpl_image_get_data_float(cpl_imagelist_get(drs_sc_mask,rz));
+    pdrsdata[sinfo_cu_xy(drs_sc_mask,rx,ry)] = cubePT_FIND;
+    return ( sinfo_new_c_bezier_interpol( sc_im, drs_sc_mask ) );
+    }
+    else
+        return(pimdata[sinfo_im_xy(im,ipos,jpos)]);
+
+
+}
+
+/**@}*/
diff --git a/sinfoni/sinfo_new_bezier.h b/sinfoni/sinfo_new_bezier.h
new file mode 100644
index 0000000..7f81f8a
--- /dev/null
+++ b/sinfoni/sinfo_new_bezier.h
@@ -0,0 +1,184 @@
+#ifndef SINFO_NEW_BEZIER_H
+#define SINFO_NEW_BEZIER_H
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*************************************************************************
+* E.S.O. - VLT project
+*
+* "@(#) $Id: sinfo_new_bezier.h,v 1.12 2007/06/06 07:10:45 amodigli Exp $"
+*
+* who       when      what
+* --------  --------  ----------------------------------------------
+* schreib  10/10/03  created
+*/
+
+/************************************************************************
+ * bezier.h
+ * bad pixel interpolation routines using bezier splines
+ *----------------------------------------------------------------------
+ */
+
+/*
+ * header files
+ */
+
+#include <cpl.h>
+#include "sinfo_spectrum_ops.h"
+#include "sinfo_msg.h"
+#include "sinfo_image_ops.h"
+/*----------------------------------------------------------------------------
+ *                        Function ANSI C prototypes
+ *--------------------------------------------------------------------------*/
+#define cubeNONEIGHBOR  -1000000 
+/* define new number that indicates that not enough neighors 
+   are available for sinfo_Bezier correction */
+#define cubePT_BADPIXEL   0 /*Bad pixel*/
+#define cubePT_USE        1 /*Good pixel*/
+#define cubePT_FIND       2 /*Correct that pixel*/
+#define cubePT_NOINFO     3 
+
+typedef struct new_dim_ {
+  unsigned short x;
+  unsigned short y;
+  unsigned short z;
+} new_Dim;
+
+typedef struct new_xyzw_ {
+  double x;
+  double y;
+  double z;
+  double w;
+} new_XYZW;
+
+typedef struct new_lookup_ {
+    cpl_image *X;
+    cpl_image *hX;
+    cpl_image *Y;
+    cpl_image *Z;
+    cpl_imagelist  *id;
+    cpl_imagelist  *jd;
+} new_Lookup;
+
+
+int sinfo_im_xy(cpl_image* im, int X, int Y); 
+int sinfo_im_xyz(cpl_image* im, int X, int Y, int Z); 
+int sinfo_cu_xy(cpl_imagelist* cu, int X, int Y); 
+int sinfo_cu_xyz(cpl_imagelist* cu, int X, int Y, int Z); 
+
+/*----------------------------------------------------------------------------
+ *                        Function ANSI C prototypes
+ *--------------------------------------------------------------------------*/
+
+cpl_image * 
+sinfo_new_c_bezier_interpolate_image(cpl_image *im, 
+                                          cpl_image *mask, 
+                                          new_Lookup *look, 
+                                          short rx, 
+                                          short ry, 
+                                          short rz,
+                          int max_rad , 
+                                          float   ** slit_edges );
+
+cpl_image * 
+sinfo_new_c_bezier_find_bad(cpl_image *im, 
+                                 cpl_image *mask/*, sinfo_new_lookup *look*/, 
+                                 short rx, 
+                                 short ry, 
+                                 short rz,
+                     short lowerI, 
+                                 short highI, 
+                                 short lowerJ, 
+                                 short highJ, 
+                                 float factor );
+
+
+float      
+sinfo_new_c_bezier_correct_pixel(int ipos, 
+                                     int jpos, 
+                     cpl_image *im, 
+                     cpl_image *mask, 
+                     cpl_imagelist  *sc_im, 
+                     cpl_imagelist  *drs_sc_mask, 
+                     new_Lookup *look, 
+                                     short rx, 
+                                     short ry, 
+                                     short rz  );
+
+
+float      
+sinfo_new_c_bezier_correct_pixel_2D( int ipos ,
+                                        int jpos, 
+                        cpl_image *im, 
+                        cpl_image *mask, 
+                        cpl_imagelist  *sc_im, 
+                        cpl_imagelist  *drs_sc_mask, 
+                        /*new_Lookup *look,*/ 
+                                        short rx, 
+                                        short ry, 
+                                        short rz , 
+                                        double *med, 
+                                        double *stdev, 
+                                        float factor );
+
+float sinfo_new_c_bezier_interpol(cpl_imagelist * im, cpl_imagelist * action );
+
+int sinfo_new_bezier(new_XYZW *p,int n,double mu,double munk,new_XYZW *res );
+
+float      
+sinfo_new_c_bezier_correct_cosmic( int ipos ,
+                                       int jpos,
+                                       cpl_image *im,
+                                       cpl_image *mask,
+                                       cpl_imagelist  *sc_im,
+                                       cpl_imagelist  *drs_sc_mask,
+                                       new_Lookup *look, 
+                                       short rx, 
+                                       short ry, 
+                                       short rz , 
+                                       double *med, 
+                                       double *stdev, 
+                                       float factor );
+
+
+cpl_image * 
+sinfo_new_c_bezier_find_cosmic(cpl_image *im, 
+                                    cpl_image *mask, 
+                                    new_Lookup *look, 
+                                    short rx, 
+                                    short ry, 
+                                    short rz,
+                                    short lowerI, 
+                                    short highI, 
+                                    short lowerJ, 
+                                    short highJ, 
+                                    float factor );
+
+
+int sinfo_new_c_create_XYZ( new_Lookup *l );
+
+new_Lookup * sinfo_new_lookup( void ) ;
+
+void sinfo_new_destroy_lookup( new_Lookup *l ) ;
+
+int sinfo_new_change_mask(cpl_image * mask,cpl_image * im ) ;
+
+
+#endif /*!SINFO_BEZIER_H*/
+
+/*--------------------------------------------------------------------------*/
diff --git a/sinfoni/sinfo_new_cube_ops.c b/sinfoni/sinfo_new_cube_ops.c
new file mode 100644
index 0000000..161d1b2
--- /dev/null
+++ b/sinfoni/sinfo_new_cube_ops.c
@@ -0,0 +1,5365 @@
+/*$Id: sinfo_new_cube_ops.c,v 1.44 2012/03/03 09:50:51 amodigli Exp $
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*************************************************************************
+* E.S.O. - VLT project
+*
+*
+*
+* who       when      what
+* --------  --------  ----------------------------------------------
+* schreib  17/05/00  created
+*/
+/*
+ * $Author: amodigli $
+ * $Date: 2012/03/03 09:50:51 $
+ * $Revision: 1.44 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+/************************************************************************
+*   NAME
+*       sinfo_new_cube_ops.c -
+*       cube arithmetic routines
+*
+*   SYNOPSIS
+*    #include "sinfo_new_cube_ops.h"
+*
+*
+*
+*    2) cpl_imagelist *
+*       sinfo_new_cube_ops( cpl_imagelist    *    cube1,
+*                cpl_imagelist    *    cube2,
+*                int        operation)
+*
+*    3) cpl_imagelist *
+*       sinfo_new_cube_const_ops(
+*                     cpl_imagelist    * cube1,
+*                     double    constant,
+*                     int        operation)
+*
+*    4) cpl_imagelist *
+*       sinfo_new_cube_sub(
+*               cpl_imagelist    *    c1,
+*               cpl_imagelist    *    c2 )
+*
+*    5) cpl_imagelist *
+*       sinfo_new_cube_add(
+*               cpl_imagelist    *    c1,
+*               cpl_imagelist    *    c2  )
+*    6) cpl_imagelist *
+*       sinfo_new_cube_mul(
+*               cpl_imagelist    *    c1,
+*               cpl_imagelist    *    c2 )
+*
+*    7) cpl_imagelist *
+*       sinfo_new_cube_div(
+*               cpl_imagelist    *    c1,
+*               cpl_imagelist    *    c2 )
+*
+*    8) cpl_imagelist * sinfo_new_add_image_to_cube(cpl_imagelist * cu,
+                                                    cpl_image * im)
+*
+*    9) cpl_imagelist * sinfo_new_sub_image_from_cube (cpl_imagelist * cu,
+                                                    cpl_image * im)
+*
+*    10) cpl_imagelist * sinfo_new_mul_image_to_cube(cpl_imagelist * cu,
+                                                    cpl_image * im)
+*
+*    11) cpl_imagelist * sinfo_new_div_cube_by_image(cpl_imagelist * cu,
+                                                    cpl_image * im)
+*
+*    12) cpl_imagelist * sinfo_new_add_spectrum_to_cube(cpl_imagelist *cu,
+                                                    Vector *spec)
+*
+*    13) cpl_imagelist * sinfo_new_sub_spectrum_from_cube(cpl_imagelist *cu,
+                                                    Vector *spec)
+*
+*    14) cpl_imagelist * sinfo_new_mul_spectrum_to_cube(cpl_imagelist *cu,
+                                                    Vector *spec)
+*
+*    15) cpl_imagelist * sinfo_new_div_cube_by_spectrum(cpl_imagelist *cu,
+                                                    Vector *spec)
+*
+*    16) Vector * sinfo_new_clean_mean_of_spectra(cpl_imagelist * cube,
+*                                    int llx,
+*                                    int lly,
+*                                    int urx,
+*                                    int ury,
+*                                    double lo_reject,
+*                                    double hi_reject)
+*
+*    17) cpl_image * sinfo_new_median_cube(cpl_imagelist * cube)
+*
+*    18) cpl_image * sinfo_new_average_cube_to_image(cpl_imagelist * cube)
+*
+*    19) cpl_image * sinfo_new_sum_cube_to_image(cpl_imagelist * cube)
+*
+*    20) cpl_image *
+         sinfo_new_average_cube_to_image_between_waves (cpl_imagelist * cube,
+*                                                   float     dispersion,
+*                                                   float     centralWave,
+*                                                   float     initialLambda,
+*                                                   float     finalLambda)
+*
+*    21) cpl_image * sinfo_new_extract_image_from_cube(cpl_imagelist * cube,
+                                                    int plane_index)
+*
+*    22) Vector * sinfo_new_extract_spectrum_from_cube( cpl_imagelist * cube,
+                                                    int x_pos, int y_pos )
+*    23) cpl_imagelist *
+         sinfo_new_combine_jittered_cubes ( cpl_imagelist ** cubes,
+*                                         cpl_imagelist  * mergedCube,
+*                                         int        n_cubes,
+*                                         float    * cumoffsetx,
+*                                         float    * cumoffsety,
+*                                         float    * exptimes,
+*                                         char     * kernel_type )
+*    24) cpl_imagelist * sinfo_new_interpol_cube_simple( cpl_imagelist * cube,
+*                                      cpl_imagelist * badcube,
+*                                      int       maxdist )
+*
+*
+*    25) cpl_imagelist * sinfo_cube_zshift(const cpl_imagelist * cube,
+*                                          const double shift,
+*                                          double* rest)
+*
+*    26) cpl_imagelist * sinfo_cube_zshift_poly(const cpl_imagelist * cube,
+*                                               const double shift,
+*                                               const int    order)
+*
+*    27) cpl_imagelist * sinfo_cube_zshift_spline3(const cpl_imagelist * cube,
+*                                                  const double shift)
+*
+*
+*
+*
+*   DESCRIPTION
+*    2) 4 operations between 2 cubes
+*    3) 4 operations between a cube and a constant
+*    4)    subtract one cube from another
+*    5) add a cube to another
+*    6) multiply two cubes
+*    7) divide two cubes
+*    8) add an image to all planes in the cube
+*    9) subtract an image from all planes in the cube
+*    10) multiply an image to all planes in the cube
+*    11) divide all planes in the cube by an image
+*    12) adds a spectrum (in z-direction) to all data
+*                        points in a cube
+*    13) subtracts a spectrum (in z-direction) from all
+*                        data points in a cube
+*    14) multiplies a spectrum (in z-direction) to all data
+*                        points in a cube
+*    15) divides all data points of a cube by a spectrum
+*                        (in z-direction)
+*    16) averaging routine to get a better spectral S/N, sorts
+*        the values of the same z-position, cuts the lowest and
+*        highest values according to given thresholds and then
+*        takes the average within the x-y plane , cannot have
+*        a sum of low and high rejected values greater than 90%
+*        of all values
+*    17) determines the sinfo_new_median value in every pixel position
+*        by considering all pixels along the third axis.
+*        ZERO pixels in a plane are not considered. If all
+*        pixels at a position are not valid the result will
+*        be 'ZERO'.
+*    18) determines the average value in every pixel position
+*        by considering all pixels along the third axis.
+*        ZERO pixels in a plane are not considered. If all
+*        pixels at a position are not valid the result will
+*        be 'ZERO'.
+*    19) determines the sum value in every pixel position
+*        by considering all pixels along the third axis.
+*        ZERO pixels in a plane are not considered. If all
+*        pixels at a position are not valid the result will
+*        be 'ZERO'.
+*    20) determines the average value in every pixel position
+*        by considering only the pixels along the third axis
+*        which lie between the given wavelength values.
+*        These values are first recalculated to plane indices
+*        by using the given dispersion and minimum wavelength in
+*        the cube.
+*        ZERO pixels in a plane are not considered. If all
+*        pixels at a position are not valid the result will
+*        be 'ZERO'.
+*    21) returns the wanted image plane of the cube
+*    22) returns the wanted single spectrum of the cube
+*    23) merges jittered data cubes to one bigger cube
+*        by averaging the overlap regions weighted by
+*        the integration times. The x, y size of the final data
+*        cube is user given, and should be between 32 and 64
+*        pixels, while the relative pixel-offset (sub-pixel
+*        accuracy) of the single cubes with respect to the
+*        first cube in the list is read from the SEQ CUMOFFSETX,Y
+*        fits header keyword.
+*   24)  interpolates bad pixel of an object cube if a bad pixel
+*        mask cube is available by using the nearest neighbors
+*        in 3 dimensions.
+*
+*   25)  shifts an imagelist by a given amount to integer pixel accuracy
+*   26)  shifts an imagelist by a given amount to sub-pixel accuracy
+*   27)  shifts an imagelist by a given amount to sub-pixel accuracy
+*   FILES
+*
+*   ENVIRONMENT
+*
+*   RETURN VALUES
+*
+*   CAUTIONS
+*
+*   EXAMPLES
+*
+*   SEE ALSO
+*
+*   BUGS
+*
+*------------------------------------------------------------------------
+*/
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#include "sinfo_vltPort.h"
+
+/*
+ * System Headers
+ */
+
+#include <sys/types.h>
+#include <sys/times.h>
+#include <math.h>
+/*
+ * Local Headers
+ */
+#include "sinfo_dfs.h"
+#include "sinfo_new_cube_ops.h"
+#include "sinfo_resampling.h"
+#include "sinfo_function_1d.h"
+#include "sinfo_error.h"
+#include "sinfo_globals.h"
+#include "sinfo_utils_wrappers.h"
+
+#include <cpl_vector.h>
+/*----------------------------------------------------------------------------
+ *                            Function codes
+ *--------------------------------------------------------------------------*/
+
+
+static int
+sinfo_shift_cubes(cpl_imagelist** tmpcubes,
+                  char* kernel_type,
+                  const int n_cubes,
+                  cpl_imagelist** cubes,
+                  const int z_min,
+                  const int z_max,
+                  float* sub_offsetx,
+                  float* sub_offsety,
+                  const int mlx,
+                  const int mly,
+                  cpl_imagelist* mask);
+
+static int
+sinfo_build_mask_cube(const int z_min,
+                      const int z_max,
+                      const int olx,
+                      const int oly,
+                      const int n_cubes,
+                      const int* llx,
+                      const int* lly,
+		      double    * exptimes,
+                      cpl_imagelist** cubes,
+                      cpl_imagelist** tmpcubes,
+                      cpl_imagelist* mask);
+
+static int
+sinfo_build_mask_cube_thomas(const int z_min,
+                             const int z_max,
+                             const int olx,
+                             const int oly,
+                             const int n_cubes,
+                             const int* llx,
+                             const int* lly,
+		             double    * exptimes,
+                             cpl_imagelist** cubes,
+                             cpl_imagelist** tmpcubes,
+			     cpl_imagelist* mask);
+static int
+sinfo_compute_weight_average(const int z_min,
+                             const int z_max,
+                             const int ilx,
+                             const int ily,
+			     const int n_cubes,
+                             cpl_imagelist* mergedCube,
+                             cpl_imagelist* mask,
+                             cpl_imagelist** tmpcubes,
+			     double* exptimes,
+                             int* llx,
+                             int* lly);
+
+static int
+sinfo_check_input(cpl_imagelist** cubes,
+                          const int n_cubes,
+                          float* cumoffsetx,
+                          float* cumoffsety,
+			  double* exptimes);
+static int
+sinfo_coadd_with_ks_clip2(const int z_min,
+			const int z_max,
+			const int ilx,
+			const int ily,
+			const int n_cubes,
+			const double kappa,
+			int* llx,
+			int* lly,
+                        double* exptimes,
+			cpl_imagelist* mask,
+			cpl_imagelist* mergedCube,
+                          cpl_imagelist** tmpcubes);
+
+
+/* temporally commented out as not yet used
+static int
+sinfo_ks_clip(
+	      const int n_cubes,
+              const int nc,
+	      const int ilx,
+	      const int ily,
+	      const double kappa,
+	      int* llx,
+	      int* lly,
+	      double* exptimes,
+	      cpl_imagelist** tmpcubes,
+              float* podata,
+              float* pmdata,
+	      const int x,
+	      const int y,
+	      const int m,
+	      const int mlx,
+	      const int olx
+	      );
+
+
+*/
+
+static int
+sinfo_coadd_with_ks_clip(const int z_min,
+			const int z_max,
+			const int ilx,
+			const int ily,
+			const int n_cubes,
+			const double kappa,
+			int* llx,
+			int* lly,
+                        double* exptimes,
+			cpl_imagelist* mask,
+			cpl_imagelist* mergedCube,
+                        cpl_imagelist** tmpcubes);
+
+
+/**@{*/
+/**
+ * @defgroup sinfo_new_cube_ops Cube operations
+ *
+ * TBD
+ */
+
+
+
+
+/**
+   @name       sinfo_new_cube_ops()
+   @memo       4 operations between 2 cubes
+   @param      cube1 1st cube
+   @param      cube2 2nd cube
+   @param      operation
+   @out        result cube
+   @note       possible operations are:
+          #        Addition    '+'
+          #        Subtraction     '-'
+          #        Multiplication    '*'
+          #        Division    '/'
+*/
+
+cpl_imagelist *
+sinfo_new_cube_ops(
+    cpl_imagelist    *    cube1,
+    cpl_imagelist    *    cube2,
+    int        operation)
+{
+
+    if (cube1==NULL || cube2==NULL)
+    {
+        sinfo_msg_error("null cubes");
+        return NULL ;
+    }
+
+    switch(operation)
+    {
+    case '+':
+    return sinfo_new_cube_add(cube1, cube2) ;
+    break ;
+    case '-':
+    return sinfo_new_cube_sub(cube1, cube2) ;
+    break ;
+
+    case '*':
+    return sinfo_new_cube_mul(cube1, cube2) ;
+    break ;
+
+    case '/':
+    return sinfo_new_cube_div(cube1, cube2) ;
+    break ;
+
+    default:
+    sinfo_msg_error("illegal requested operation: aborting cube arithmetic") ;
+    return NULL ;
+    }
+}
+
+
+/*----------------------------------------------------------------------------
+   Function    :    sinfo_new_cube_const_ops()
+   In         :    1 cube, 1 constant, operation to perform
+   Out         :    result cube
+   Job        :    4 operations between a cube and a constant
+   Notice    :    possible operations are:
+                  Addition    '+'
+                  Subtraction     '-'
+                  Multiplication    '*'
+                  Division    '/'
+                  Logarithm    'l'
+                  Power        '^'
+                  Exponentiation    'e'
+
+ ---------------------------------------------------------------------------*/
+
+cpl_imagelist *
+sinfo_new_cube_const_ops(
+    cpl_imagelist    *    c1,
+    double        constant,
+    int        operation)
+{
+    int ilx1=0;
+    int ily1=0;
+    int inp1=0;
+    cpl_imagelist* c2=NULL;
+    cpl_image* img1=NULL;
+
+
+
+    if (c1 == NULL)
+    {
+         sinfo_msg_error("null cube") ;
+         return NULL ;
+    }
+    inp1=cpl_imagelist_get_size(c1);
+    img1=cpl_imagelist_get(c1,0);
+    ilx1=cpl_image_get_size_x(img1);
+    ily1=cpl_image_get_size_y(img1);
+
+
+
+
+
+    if ((constant == 0.0) && (operation == '/'))
+    {
+        sinfo_msg_error("division by zero requested "
+                        "in cube/constant operation") ;
+        return NULL ;
+    }
+
+    if ( NULL == (c2 = cpl_imagelist_new()) )
+    {
+        sinfo_msg_error ("cannot allocate new cube" ) ;
+        return NULL ;
+    }
+
+    c2=cpl_imagelist_duplicate(c1);
+    if(operation == '+') {
+      cpl_imagelist_add_scalar(c2,constant);
+    } else if (operation == '-') {
+      cpl_imagelist_subtract_scalar(c2,constant);
+    } else if (operation == '*') {
+      cpl_imagelist_multiply_scalar(c2,constant);
+    } else if (operation == '/') {
+      cpl_imagelist_divide_scalar(c2,constant);
+
+    } else {
+      sinfo_msg_error("operation not supported");
+      return NULL;
+    }
+    return c2 ;
+}
+
+
+/*----------------------------------------------------------------------------
+ * Function    :    sinfo_new_cube_sub()
+ * In         :    two cubes
+ * Out         :    result cube
+ * Job        :    subtract one cube from another
+ *--------------------------------------------------------------------------*/
+
+cpl_imagelist *
+sinfo_new_cube_sub(
+    cpl_imagelist    *    c1,
+    cpl_imagelist    *    c2
+)
+{
+    cpl_imagelist   *                 c3 ;
+    ulong32            i ;
+    int                     np ;
+    int ilx1=0;
+    int ily1=0;
+    int inp1=0;
+    int ilx2=0;
+    int ily2=0;
+    int inp2=0;
+
+
+    cpl_image* i_img=NULL;
+    cpl_image* img1=NULL;
+    cpl_image* img2=NULL;
+    cpl_image* img3=NULL;
+    float* p1data=NULL;
+    float* p2data=NULL;
+    float* p3data=NULL;
+
+
+
+    inp1=cpl_imagelist_get_size(c1);
+    i_img=cpl_imagelist_get(c1,0);
+    ilx1=cpl_image_get_size_x(i_img);
+    ily1=cpl_image_get_size_y(i_img);
+
+
+    inp2=cpl_imagelist_get_size(c2);
+    i_img=cpl_imagelist_get(c2,0);
+    ilx2=cpl_image_get_size_x(i_img);
+    ily2=cpl_image_get_size_y(i_img);
+
+    if ((ilx1 != ilx2) ||
+    (ily1 != ily2))
+    {
+    sinfo_msg_error("incompatible size: cannot subtract") ;
+    return NULL ;
+    }
+
+    if ((inp2 != inp1) &&
+    (inp2 != 1))
+    {
+    sinfo_msg_error("cannot compute with these number of planes") ;
+    return NULL ;
+    }
+
+    if ( NULL == (c3 = cpl_imagelist_new()) )
+    {
+        sinfo_msg_error ("cannot allocate new cube" ) ;
+        return NULL ;
+    }
+
+    for (np=0 ; np < inp1 ; np++)
+    {
+      img3=cpl_image_new(ilx1,ily1,CPL_TYPE_FLOAT);
+      cpl_imagelist_set(c3,img3,np);
+    }
+
+
+    for (np=0 ; np < inp1 ; np++)
+    {
+      img1=cpl_imagelist_get(c1,np);
+      p1data=cpl_image_get_data_float(img1);
+      img2=cpl_imagelist_get(c2,np);
+      p2data=cpl_image_get_data_float(img2);
+      img3=cpl_imagelist_get(c3,np);
+      p3data=cpl_image_get_data_float(img3);
+
+        for (i=0 ; i< (ulong32)ilx1*ily1 ; i++)
+        {
+            p3data[i] = p1data[i] - p2data[i] ;
+    }
+    }
+
+    return c3 ;
+}
+
+
+/*----------------------------------------------------------------------------
+ * Function    :    sinfo_new_cube_add()
+ * In         :    two cubes
+ * Out         :    result cube
+ * Job        :    add a cube to another
+ *--------------------------------------------------------------------------*/
+
+cpl_imagelist *
+sinfo_new_cube_add(
+    cpl_imagelist    *    c1,
+    cpl_imagelist    *    c2
+)
+{
+    cpl_imagelist  *          c3 ;
+    ulong32        i ;
+    int         np ;
+    int ilx1=0;
+    int ily1=0;
+    int inp1=0;
+    int ilx2=0;
+    int ily2=0;
+    int inp2=0;
+
+
+    cpl_image* i_img=NULL;
+    cpl_image* img1=NULL;
+    cpl_image* img2=NULL;
+    cpl_image* img3=NULL;
+    float* p1data=NULL;
+    float* p2data=NULL;
+    float* p3data=NULL;
+
+
+
+    inp1=cpl_imagelist_get_size(c1);
+    i_img=cpl_imagelist_get(c1,0);
+    ilx1=cpl_image_get_size_x(i_img);
+    ily1=cpl_image_get_size_y(i_img);
+
+
+    inp2=cpl_imagelist_get_size(c2);
+    i_img=cpl_imagelist_get(c2,0);
+    ilx2=cpl_image_get_size_x(i_img);
+    ily2=cpl_image_get_size_y(i_img);
+    if ((ilx1 != ilx2) || (ily1 != ily2))
+    {
+    sinfo_msg_error("incompatible size: cannot add") ;
+    return NULL ;
+    }
+    if ((inp2 != inp1) && (inp2 != 1))
+    {
+    sinfo_msg_error("cannot compute with these number of planes") ;
+    return NULL ;
+    }
+
+    if (NULL == (c3 = cpl_imagelist_new()) )
+    {
+        sinfo_msg_error ("cannot allocate new cube") ;
+        return NULL ;
+    }
+
+    for (np=0 ; np < inp1 ; np++)
+    {
+      img3=cpl_image_new(ilx1,ily1,CPL_TYPE_FLOAT);
+      cpl_imagelist_set(c3,img3,np);
+    }
+
+    for (np=0 ; np < inp1 ; np++)
+    {
+      img1=cpl_imagelist_get(c1,np);
+      p1data=cpl_image_get_data_float(img1);
+      img2=cpl_imagelist_get(c2,np);
+      p2data=cpl_image_get_data_float(img2);
+      img3=cpl_imagelist_get(c3,np);
+      p3data=cpl_image_get_data_float(img3);
+        for (i=0 ; i< (ulong32)ilx1*ily1 ; i++)
+        {
+        p3data[i] = p1data[i] + p2data[i] ;
+        }
+    }
+
+    return c3 ;
+}
+
+/*----------------------------------------------------------------------------
+ * Function    :    sinfo_new_cube_mul()
+ * In         :    two cubes
+ * Out         :    result cube
+ * Job        :    multiply 2 cubes
+ *--------------------------------------------------------------------------*/
+
+cpl_imagelist *
+sinfo_new_cube_mul(
+    cpl_imagelist    *    c1,
+    cpl_imagelist    *    c2
+)
+{
+    cpl_imagelist             *c3 ;
+    ulong32        i ;
+    int                np ;
+    int ilx1=0;
+    int ily1=0;
+    int inp1=0;
+    int ilx2=0;
+    int ily2=0;
+    int inp2=0;
+
+
+    cpl_image* i_img=NULL;
+    cpl_image* img1=NULL;
+    cpl_image* img2=NULL;
+    cpl_image* img3=NULL;
+    float* p1data=NULL;
+    float* p2data=NULL;
+    float* p3data=NULL;
+
+
+
+
+    inp1=cpl_imagelist_get_size(c1);
+    i_img=cpl_imagelist_get(c1,0);
+    ilx1=cpl_image_get_size_x(i_img);
+    ily1=cpl_image_get_size_y(i_img);
+
+
+    inp2=cpl_imagelist_get_size(c2);
+    i_img=cpl_imagelist_get(c2,0);
+    ilx2=cpl_image_get_size_x(i_img);
+    ily2=cpl_image_get_size_y(i_img);
+
+    if ((ilx1 != ilx2) || (ily1 != ily2))
+    {
+    sinfo_msg_error("incompatible size: cannot multiply") ;
+    return NULL ;
+    }
+
+    if ((inp2 != inp1) && (inp2 != 1))
+    {
+    sinfo_msg_error("cannot compute with these number of planes") ;
+    return NULL ;
+    }
+
+    if ( NULL == (c3 = cpl_imagelist_new()) )
+    {
+        sinfo_msg_error ("cannot allocate new cube" ) ;
+        return NULL ;
+    }
+
+
+    for (np=0 ; np < inp1 ; np++)
+    {
+      img3=cpl_image_new(ilx1,ily1,CPL_TYPE_FLOAT);
+      cpl_imagelist_set(c3,img3,np);
+    }
+
+    for (np=0 ; np < inp1 ; np++)
+    {
+      img1=cpl_imagelist_get(c1,np);
+      p1data=cpl_image_get_data_float(img1);
+      img2=cpl_imagelist_get(c2,np);
+      p2data=cpl_image_get_data_float(img2);
+      img3=cpl_imagelist_get(c3,np);
+      p3data=cpl_image_get_data_float(img3);
+        for (i=0 ; i< (ulong32)ilx1*ilx2 ; i++)
+        {
+            p3data[i] = p1data[i] * p2data[i] ;
+        }
+    }
+
+    return c3 ;
+}
+
+
+/*----------------------------------------------------------------------------
+ * Function    :    sinfo_new_cube_div()
+ * In         :    two cubes
+ * Out         :    result cube
+ * Job        :    divide 2 cubes
+ *--------------------------------------------------------------------------*/
+
+cpl_imagelist *
+sinfo_new_cube_div(
+    cpl_imagelist    *    c1,
+    cpl_imagelist    *    c2
+)
+{
+    cpl_imagelist *           c3 ;
+    ulong32        i ;
+    int         np ;
+    int ilx1=0;
+    int ily1=0;
+    int inp1=0;
+    int ilx2=0;
+    int ily2=0;
+    int inp2=0;
+
+
+    cpl_image* i_img=NULL;
+    cpl_image* img1=NULL;
+    cpl_image* img2=NULL;
+    cpl_image* img3=NULL;
+    float* p1data=NULL;
+    float* p2data=NULL;
+    float* p3data=NULL;
+
+
+    inp1=cpl_imagelist_get_size(c1);
+    i_img=cpl_imagelist_get(c1,0);
+    ilx1=cpl_image_get_size_x(i_img);
+    ily1=cpl_image_get_size_y(i_img);
+
+
+    inp2=cpl_imagelist_get_size(c2);
+    i_img=cpl_imagelist_get(c2,0);
+    ilx2=cpl_image_get_size_x(i_img);
+    ily2=cpl_image_get_size_y(i_img);
+
+    if ((ilx1 != ilx2) ||
+    (ily1 != ily2))
+    {
+    sinfo_msg_error("incompatible size: cannot divide") ;
+    return NULL ;
+    }
+
+    if ((inp2 != inp1) && (inp2 != 1))
+    {
+    sinfo_msg_error("cannot compute with these number of planes") ;
+    return NULL ;
+    }
+
+    if (NULL == (c3 = cpl_imagelist_new()) )
+    {
+        sinfo_msg_error ("cannot allocate a new cube") ;
+        return NULL ;
+    }
+
+    for (np=0 ; np < inp1 ; np++)
+    {
+      img3=cpl_image_new(ilx1,ily1,CPL_TYPE_FLOAT);
+      cpl_imagelist_set(c3,img3,np);
+    }
+
+    for (np=0 ; np < inp1 ; np++)
+    {
+      img1=cpl_imagelist_get(c1,np);
+      p1data=cpl_image_get_data_float(img1);
+      img2=cpl_imagelist_get(c2,np);
+      p2data=cpl_image_get_data_float(img2);
+      img3=cpl_imagelist_get(c3,np);
+      p3data=cpl_image_get_data_float(img3);
+
+
+        for (i=0 ; i< (ulong32) ilx1*ily1 ; i++)
+        {
+            if (fabs((double)p2data[i]) < 1e-10)
+            {
+            p3data[i] = 0.0 ;
+            }
+            else
+            {
+                p3data[i] = p1data[i] / p2data[i] ;
+            }
+        }
+    }
+
+    return c3 ;
+}
+
+
+
+/*---------------------------------------------------------------------------
+   Function    :    sinfo_new_add_image_to_cube()
+   In         :    1 allocated cube, 1 allocated image
+   Out         :    result cube
+   Job        :    add an image to all planes in the cube
+ ---------------------------------------------------------------------------*/
+
+cpl_imagelist *
+sinfo_new_add_image_to_cube(cpl_imagelist * cu, cpl_image * im)
+{
+    cpl_imagelist *   cube ;
+    int               i ;
+    int clx=0;
+    int cly=0;
+    int cnp=0;
+    int ilx=0;
+    int ily=0;
+
+
+    cpl_image* i_img=NULL;
+
+    if (cu==NULL || im==NULL)
+    {
+       sinfo_msg_error ("null cube or null image") ;
+       return NULL ;
+    }
+    cnp=cpl_imagelist_get_size(cu);
+    i_img=cpl_imagelist_get(cu,0);
+    clx=cpl_image_get_size_x(i_img);
+    cly=cpl_image_get_size_y(i_img);
+
+    ilx=cpl_image_get_size_x(im);
+    ily=cpl_image_get_size_y(im);
+
+    if ((clx != ilx) || (cly != ily))
+    {
+        sinfo_msg_error("incompatible size: cannot add image to cube") ;
+    return NULL ;
+    }
+
+    cube = cpl_imagelist_duplicate (cu) ;
+
+    for (i=0 ; i<cnp ; i++)
+    {
+      /* AMO
+        here may be we have to use cpl_image_add_create and cpl_imagelist_set
+       */
+    cpl_image_add(cpl_imagelist_get(cube,i), im) ;
+    }
+
+    return cube ;
+}
+
+/*---------------------------------------------------------------------------
+   Function    :    sinfo_new_sub_image_from_cube()
+   In         :    1 allocated cube, 1 allocated image
+   Out         :       result cube
+   Job        :    subtract an image from all planes in the cube
+ ---------------------------------------------------------------------------*/
+
+cpl_imagelist *
+sinfo_new_sub_image_from_cube (cpl_imagelist * cu, cpl_image * im)
+{
+    cpl_imagelist   * cube ;
+    int               i ;
+    int clx=0;
+    int cly=0;
+    int cnp=0;
+    int ilx=0;
+    int ily=0;
+
+
+    cpl_image* i_img=NULL;
+
+    if (cu==NULL || im==NULL)
+    {
+        sinfo_msg_error ("null cube or null image") ;
+        return NULL ;
+    }
+    cnp=cpl_imagelist_get_size(cu);
+    i_img=cpl_imagelist_get(cu,0);
+    clx=cpl_image_get_size_x(i_img);
+    cly=cpl_image_get_size_y(i_img);
+
+    ilx=cpl_image_get_size_x(im);
+    ily=cpl_image_get_size_y(im);
+
+    if ((clx != ilx) || (cly != ily))
+    {
+
+    sinfo_msg_error("incompatible size: cannot subtract image from cube") ;
+        return NULL ;
+    }
+
+    cube = cpl_imagelist_duplicate (cu) ;
+
+    for (i=0 ; i<cnp ; i++)
+    {
+      /* AMO
+        here may be we have to use cpl_image_add_create and cpl_imagelist_set
+       */
+    cpl_image_subtract(cpl_imagelist_get(cube,i), im) ;
+    }
+    return cube ;
+}
+
+/*---------------------------------------------------------------------------
+   Function    :    sinfo_new_mul_image_to_cube()
+   In         :    1 allocated cube, 1 allocated image
+   Out         :    result cube
+   Job        :    multiply an image to all planes in the cube
+ ---------------------------------------------------------------------------*/
+
+cpl_imagelist *
+sinfo_new_mul_image_to_cube(cpl_imagelist * cu, cpl_image * im)
+{
+    cpl_imagelist   * cube ;
+    int               i ;
+    int clx=0;
+    int cly=0;
+    int cnp=0;
+    int ilx=0;
+    int ily=0;
+
+
+    cpl_image* i_img=NULL;
+
+    if (cu==NULL || im==NULL)
+    {
+        sinfo_msg_error("null cube or null image") ;
+        return NULL ;
+    }
+    cnp=cpl_imagelist_get_size(cu);
+    i_img=cpl_imagelist_get(cu,0);
+    clx=cpl_image_get_size_x(i_img);
+    cly=cpl_image_get_size_y(i_img);
+
+    ilx=cpl_image_get_size_x(im);
+    ily=cpl_image_get_size_y(im);
+
+    if ((clx != ilx) || (cly != ily))
+    {
+    sinfo_msg_error("incompatible size: cannot multiply image by cube") ;
+    return NULL ;
+    }
+
+    cube = cpl_imagelist_duplicate (cu) ;
+
+    for (i=0 ; i<cnp ; i++)
+    {
+      /* AMO
+        here may be we have to use cpl_image_add_create and cpl_imagelist_set
+       */
+    cpl_image_multiply(cpl_imagelist_get(cube,i), im) ;
+    }
+
+    return cube ;
+}
+
+/*---------------------------------------------------------------------------
+   Function    :    sinfo_new_div_cube_by_image()
+   In         :    1 allocated cube, 1 allocated image
+   Out         :    result cube
+   Job        :    divide all planes in the cube by an image
+ ---------------------------------------------------------------------------*/
+
+cpl_imagelist *
+sinfo_new_div_cube_by_image(cpl_imagelist * cu, cpl_image * im)
+{
+    cpl_imagelist   * cube ;
+    int               i ;
+    int clx=0;
+    int cly=0;
+    int cnp=0;
+    int ilx=0;
+    int ily=0;
+
+
+    cpl_image* i_img=NULL;
+
+    if (cu==NULL || im==NULL)
+    {
+        sinfo_msg_error ("null cube or null image") ;
+        return NULL ;
+    }
+    cnp=cpl_imagelist_get_size(cu);
+    i_img=cpl_imagelist_get(cu,0);
+    clx=cpl_image_get_size_x(i_img);
+    cly=cpl_image_get_size_y(i_img);
+
+    ilx=cpl_image_get_size_x(im);
+    ily=cpl_image_get_size_y(im);
+
+    if ((clx != ilx) || (cly != ily))
+    {
+    sinfo_msg_error("incompatible size: cannot divide cube by image") ;
+    return NULL ;
+    }
+
+    cube = cpl_imagelist_duplicate (cu) ;
+
+    for (i=0 ; i<cnp ; i++)
+    {
+      /* AMO
+        here may be we have to use cpl_image_add_create and cpl_imagelist_set
+       */
+    cpl_image_divide(cpl_imagelist_get(cube,i), im) ;
+    }
+
+    return cube ;
+}
+
+
+/*---------------------------------------------------------------------------
+   Function    :    sinfo_new_add_spectrum_to_cube()
+   In         :    1 allocated cube, 1 allocated spectrum sinfo_vector
+   Out         :    result cube
+   Job        :    adds a spectrum (in z-direction) to all data
+                        points in a cube
+ ---------------------------------------------------------------------------*/
+
+cpl_imagelist *
+sinfo_new_add_spectrum_to_cube(cpl_imagelist *cu, Vector *spec)
+{
+    cpl_imagelist *   cube ;
+    int         i ,j ;
+    int ilx=0;
+    int ily=0;
+    int inp=0;
+    float* pidata=NULL;
+    float* podata=NULL;
+    cpl_image* i_img=NULL;
+    cpl_image* o_img=NULL;
+
+    if (cu == NULL || spec == NULL)
+    {
+        sinfo_msg_error ("null cube or null spectrum") ;
+        return NULL ;
+    }
+    inp=cpl_imagelist_get_size(cu);
+    i_img=cpl_imagelist_get(cu,0);
+    ilx=cpl_image_get_size_x(i_img);
+    ily=cpl_image_get_size_y(i_img);
+
+    if ( inp != spec -> n_elements )
+    {
+        sinfo_msg_error("cube length and spectrum length are not compatible") ;
+        return NULL ;
+    }
+
+    if ( NULL == (cube = cpl_imagelist_new ()) )
+    {
+        sinfo_msg_error ("cannot allocate new cube" ) ;
+        return NULL ;
+    }
+    for ( i = 0; i < inp; i++)
+    {
+      o_img=cpl_image_new(ilx,ily,CPL_TYPE_FLOAT);
+      cpl_imagelist_set(cube,o_img,i);
+    }
+
+
+    for ( i = 0; i < inp; i++)
+    {
+      i_img=cpl_imagelist_get(cu,i);
+      pidata=cpl_image_get_data_float(i_img);
+      o_img=cpl_imagelist_get(cube,i);
+      podata=cpl_image_get_data_float(o_img);
+        for ( j = 0; j < (int) ilx*ily; j++)
+        {
+            podata[j] = pidata[j] + spec -> data[i] ;
+        }
+    }
+
+    return cube ;
+}
+
+/*---------------------------------------------------------------------------
+   Function    :    sinfo_new_sub_spectrum_from_cube()
+   In         :    1 allocated cube, 1 allocated spectrum sinfo_vector
+   Out         :    result cube
+   Job        :    subtracts a spectrum (in z-direction) from all
+                        data points in a cube
+ ---------------------------------------------------------------------------*/
+
+cpl_imagelist *
+sinfo_new_sub_spectrum_from_cube(cpl_imagelist *cu, Vector *spec)
+{
+    cpl_imagelist *   cube ;
+    int         i ,j ;
+    int ilx=0;
+    int ily=0;
+    int inp=0;
+    float* pidata=NULL;
+    float* podata=NULL;
+    cpl_image* i_img=NULL;
+    cpl_image* o_img=NULL;
+
+    if (cu == NULL || spec == NULL)
+    {
+        sinfo_msg_error ("null cube or null spectrum") ;
+        return NULL ;
+    }
+    inp=cpl_imagelist_get_size(cu);
+    i_img=cpl_imagelist_get(cu,0);
+    ilx=cpl_image_get_size_x(i_img);
+    ily=cpl_image_get_size_y(i_img);
+
+    if ( inp != spec -> n_elements )
+    {
+        sinfo_msg_error("cube length and spectrum length are not compatible") ;
+        return NULL ;
+    }
+
+    if ( NULL == (cube = cpl_imagelist_new()) )
+    {
+        sinfo_msg_error ("cannot allocate new cube" ) ;
+        return NULL ;
+    }
+    for ( i = 0; i < inp; i++)
+    {
+      o_img=cpl_image_new(ilx,ily,CPL_TYPE_FLOAT);
+      cpl_imagelist_set(cube,o_img,i);
+    }
+
+    for ( i = 0; i < inp; i++)
+    {
+      i_img=cpl_imagelist_get(cu,i);
+      pidata=cpl_image_get_data_float(i_img);
+      o_img=cpl_imagelist_get(cube,i);
+      podata=cpl_image_get_data_float(o_img);
+        for ( j = 0; j < (int) ilx*ily; j++)
+        {
+            if ( isnan(pidata[j]) || isnan(spec -> data[i]) )
+            {
+                podata[j] = ZERO ;
+            }
+            else
+            {
+                podata[j] = pidata[j] - spec -> data[i] ;
+            }
+        }
+    }
+
+    return cube ;
+}
+
+
+/*---------------------------------------------------------------------------
+   Function    :    sinfo_new_mul_spectrum_to_cube()
+   In         :    1 allocated cube, 1 allocated spectrum sinfo_vector
+   Out         :    result cube
+   Job        :    multiplies a spectrum (in z-direction) to all data
+                        points in a cube
+ ---------------------------------------------------------------------------*/
+
+cpl_imagelist *
+sinfo_new_mul_spectrum_to_cube(cpl_imagelist *cu, Vector *spec)
+{
+    cpl_imagelist *   cube ;
+    int         i ,j ;
+    int ilx=0;
+    int ily=0;
+    int inp=0;
+    float* pidata=NULL;
+    float* podata=NULL;
+    cpl_image* i_img=NULL;
+    cpl_image* o_img=NULL;
+
+    if (cu == NULL || spec == NULL)
+    {
+        sinfo_msg_error ("null cube or null spectrum") ;
+        return NULL ;
+    }
+    inp=cpl_imagelist_get_size(cu);
+    i_img=cpl_imagelist_get(cu,0);
+    ilx=cpl_image_get_size_x(i_img);
+    ily=cpl_image_get_size_y(i_img);
+
+    if ( inp != spec -> n_elements )
+    {
+        sinfo_msg_error("cube length and spectrum length are not compatible") ;
+        return NULL ;
+    }
+
+    if ( NULL == (cube = cpl_imagelist_new ()) )
+    {
+        sinfo_msg_error ("cannot allocate new cube" ) ;
+        return NULL ;
+    }
+
+    for ( i = 0; i < inp; i++)
+    {
+      o_img=cpl_image_new(ilx,ily,CPL_TYPE_FLOAT);
+      cpl_imagelist_set(cube,o_img,i);
+    }
+
+    for ( i = 0; i < inp; i++)
+    {
+      i_img=cpl_imagelist_get(cu,i);
+      pidata=cpl_image_get_data_float(i_img);
+      o_img=cpl_imagelist_get(cube,i);
+      podata=cpl_image_get_data_float(o_img);
+        for ( j = 0; j < (int) ilx*ily; j++)
+        {
+            if ( isnan(pidata[j]) || isnan(spec->data[i]) )
+            {
+                podata[j] = ZERO ;
+            }
+            else
+            {
+                podata[j] = pidata[j] * spec -> data[i] ;
+            }
+        }
+    }
+
+    return cube ;
+}
+
+
+/*---------------------------------------------------------------------------
+   Function    :    sinfo_new_div_cube_by_spectrum()
+   In         :    1 allocated cube, 1 allocated spectrum sinfo_vector
+   Out         :    result cube
+   Job        :    divides all data points of a cube by a spectrum
+                        (in z-direction)
+ ---------------------------------------------------------------------------*/
+
+cpl_imagelist *
+sinfo_new_div_cube_by_spectrum(cpl_imagelist *cu, Vector *spec)
+{
+    cpl_imagelist *   cube ;
+    float       help ;
+    int         i ,j ;
+    int ilx=0;
+    int ily=0;
+    int inp=0;
+    float* pidata=NULL;
+    float* podata=NULL;
+    cpl_image* i_img=NULL;
+    cpl_image* o_img=NULL;
+
+    if (cu == NULL || spec == NULL)
+    {
+        sinfo_msg_error ("null cube or null spectrum") ;
+        return NULL ;
+    }
+    inp=cpl_imagelist_get_size(cu);
+    i_img=cpl_imagelist_get(cu,0);
+    ilx=cpl_image_get_size_x(i_img);
+    ily=cpl_image_get_size_y(i_img);
+
+    if ( inp != spec -> n_elements )
+    {
+        sinfo_msg_error("cube length and spectrum length are not compatible") ;
+        return NULL ;
+    }
+
+    if (NULL == (cube = cpl_imagelist_new ()) )
+    {
+        sinfo_msg_error ("cannot allocate new cube") ;
+        return NULL ;
+    }
+
+    for ( i = 0; i < inp; i++)
+    {
+      o_img=cpl_image_new(ilx,ily,CPL_TYPE_FLOAT);
+      cpl_imagelist_set(cube,o_img,i);
+    }
+
+    for ( i = 0; i < inp; i++)
+    {
+
+      i_img=cpl_imagelist_get(cu,i);
+      pidata=cpl_image_get_data_float(i_img);
+      o_img=cpl_imagelist_get(cube,i);
+      podata=cpl_image_get_data_float(o_img);
+        for ( j = 0; j < (int) ilx*ily; j++)
+        {
+            if (!isnan(spec->data[i]) && spec->data[i] != 0.)
+            {
+                help = 1/spec->data[i] ;
+                if ( help > THRESH )
+                {
+                    help = 1. ;
+                }
+            }
+            else
+            {
+                help = ZERO ;
+            }
+
+            if ( isnan(help) || isnan(pidata[j]) )
+            {
+                podata[j] = ZERO ;
+            }
+            else
+            {
+                podata[j] = pidata[j] * help ;
+            }
+        }
+    }
+    return cube ;
+}
+
+
+/*---------------------------------------------------------------------------
+   Function    :    sinfo_new_clean_mean_of_spectra()
+   In         :    1 allocated cube, position of rectangle in x-y plane ,
+                        low and high cut threshold
+   Out         :    result spectrum sinfo_vector
+   Job        :    averaging routine to get a better spectral S/N, sorts
+                        the values of the same z-position, cuts the lowest and
+                        highest values according to given thresholds and then
+                        takes the average within the x-y plane , cannot have
+                        a sum of low and high rejected values greater than 90%
+                        of all values
+ ---------------------------------------------------------------------------*/
+
+Vector *
+sinfo_new_clean_mean_of_spectra(cpl_imagelist * cube,
+                             int llx,
+                             int lly,
+                             int urx,
+                             int ury,
+                             double lo_reject,
+                             double hi_reject)
+{
+    Vector                           * mean ;
+    pixelvalue                   *local_rectangle ;
+    int                    i, j, k, l, m ;
+    int             recsize, lo_n, hi_n, nv ;
+    int ilx=0;
+    int ily=0;
+    int inp=0;
+    float* pidata=NULL;
+    cpl_image* i_img=NULL;
+
+    if ( cube == NULL || cpl_imagelist_get_size(cube) < 1 )
+    {
+        sinfo_msg_error ("no cube to take the mean of his spectra") ;
+        return NullVector ;
+    }
+    inp=cpl_imagelist_get_size(cube);
+    i_img=cpl_imagelist_get(cube,0);
+    ilx=cpl_image_get_size_x(i_img);
+    ily=cpl_image_get_size_y(i_img);
+
+    if ((llx<1) || (llx>ilx) ||
+        (urx<1) || (urx>ilx) ||
+        (lly<1) || (lly>ily) ||
+        (ury<1) || (ury>ily) ||
+        (llx>=urx) || (lly>=ury))
+    {
+        sinfo_msg_error("invalid rectangle coordinates:") ;
+        sinfo_msg_error("lower left is [%d %d] upper right is [%d %d]",
+                        llx, lly, urx, ury) ;
+        return NullVector ;
+    }
+
+    if ((lo_reject + hi_reject) > 0.9)
+    {
+        sinfo_msg_error("illegal rejection thresholds: [%f] and [%f]",
+                        lo_reject, hi_reject) ;
+        sinfo_msg_error("threshold sum should not be over 0.9"
+                        " aborting average") ;
+        return NullVector ;
+    }
+
+    /* shift from FITS coordinates to C coordinates */
+    llx -- ;
+    lly -- ;
+    urx -- ;
+    ury -- ;
+
+    recsize = (urx - llx + 1) * (ury - lly + 1) ;
+
+    lo_n = (int) (recsize * lo_reject + 0.5) ;
+    hi_n = (int) (recsize * hi_reject + 0.5) ;
+
+    if (lo_n + hi_n >= recsize)
+    {
+        sinfo_msg_error ("everything would be rejected") ;
+        return NullVector;
+    }
+
+    /* allocate a new sinfo_vector to store the average spectral values */
+    if (NULL == (mean = sinfo_new_vector (inp)) )
+    {
+        sinfo_msg_error ("cannot allocate a new sinfo_vector") ;
+        return NullVector ;
+    }
+
+    /*------------------------------------------------------------------------
+     *  loop through the cube planes, through the x axis and the y-axis of the
+     *  plane rectangle and store pixel values in a buffer.
+     */
+    for ( i = 0 ; i < inp ; i++ )
+    {
+      i_img=cpl_imagelist_get(cube,i);
+      pidata=cpl_image_get_data_float(i_img);
+      m = 0 ;
+      local_rectangle=(pixelvalue *)cpl_calloc(recsize, sizeof (pixelvalue*));
+
+        for ( j = lly ; j <= ury ; j++ )
+        {
+            for ( k = llx ; k <= urx ; k++ )
+            {
+                local_rectangle[m] = pidata[k + j * ilx] ;
+                m ++ ;
+            }
+        }
+        /*sorts the pixelvalues in the buffer*/
+        sinfo_pixel_qsort (local_rectangle, recsize) ;
+
+        nv = 0 ;
+        for ( l = lo_n ; l < (recsize - hi_n) ; l++ )
+        {
+            mean -> data[i] += local_rectangle[l] ;
+            nv ++;
+        }
+        mean -> data[i] /= nv ;
+
+        cpl_free ( local_rectangle ) ;
+    }
+    return mean ;
+}
+
+
+/*---------------------------------------------------------------------------
+   Function    :sinfo_new_median_cube()
+   In         :1 allocated cube
+   Out         :result image
+   Job        :determines the sinfo_new_median value in every pixel position
+                 by considering all pixels along the third axis.
+                 ZERO pixels in a plane are not considered. If all
+                 pixels at a position are not valid the result will
+                 be 'ZERO'.
+ ---------------------------------------------------------------------------*/
+cpl_image *
+sinfo_new_median_cube(cpl_imagelist * cube)
+{
+    cpl_image  *         im ;
+    pixelvalue *    buffer ;
+    int        i, j, k, nz ;
+    int ilx=0;
+    int ily=0;
+    int inp=0;
+    float* pidata=NULL;
+    float* podata=NULL;
+    cpl_image* i_img=NULL;
+
+    if ( cube == NULL )
+    {
+        sinfo_msg_error ("null cube") ;
+        return NULL ;
+    }
+    inp=cpl_imagelist_get_size(cube);
+    i_img=cpl_imagelist_get(cube,0);
+    ilx=cpl_image_get_size_x(i_img);
+    ily=cpl_image_get_size_y(i_img);
+
+    /* allocate memory */
+    if (NULL == (im = cpl_image_new (ilx, ily, CPL_TYPE_FLOAT )) )
+    {
+        sinfo_msg_error ("cannot allocate new image") ;
+        return NULL ;
+    }
+
+    /*------------------------------------------------------------------------
+     * transfer each sinfo_vector in z direction in a buffer and collect
+       only non-blank data.
+     */
+
+    podata=cpl_image_get_data_float(im);
+    for ( i = 0 ; i < (int) ilx*ily ; i++ )
+    {
+        buffer = (pixelvalue *) cpl_calloc (inp, sizeof (pixelvalue *));
+        k = 0 ;
+        for ( j = 0 ; j < inp ; j ++ )
+        {
+          i_img=cpl_imagelist_get(cube,j);
+      pidata=cpl_image_get_data_float(i_img);
+            if ( !isnan(pidata[i]) )
+            {
+                buffer[k] = pidata[i] ;
+                k ++ ;
+            }
+        }
+        nz = k ;
+
+        /* proceed depending on the number of valid pixels */
+        if ( nz > 2 )
+        {
+            podata[i] = sinfo_new_median ( buffer, nz ) ;
+        }
+        else if (nz == 2)
+        {
+            podata[i] = (buffer[0] + buffer[1]) / 2. ;
+        }
+        else if (nz == 1)
+        {
+            podata[i] = buffer[0] ;
+        }
+        else if (nz == 0)
+        {
+            podata[i] = ZERO ;
+        }
+
+        cpl_free ( buffer ) ;
+    }
+
+    return im ;
+}
+
+
+/*---------------------------------------------------------------------------
+   Function    :    sinfo_new_average_cube_to_image()
+   In         :    1 allocated cube
+   Out         :    result image
+   Job        :    determines the average value in every pixel position
+                        by considering all pixels along the third axis.
+                        ZERO pixels in a plane are not considered. If all
+                        pixels at a position are not valid the result will
+                        be 'ZERO'.
+ ---------------------------------------------------------------------------*/
+cpl_image *
+sinfo_new_average_cube_to_image(cpl_imagelist * cube)
+{
+    cpl_image  *      im ;
+    int        i, j, nz ;
+    int ilx=0;
+    int ily=0;
+    int inp=0;
+    float* pidata=NULL;
+    float* podata=NULL;
+    cpl_image* i_img=NULL;
+
+    if ( cube == NULL )
+    {
+        sinfo_msg_error ("null cube") ;
+        return NULL ;
+    }
+    inp=cpl_imagelist_get_size(cube);
+    i_img=cpl_imagelist_get(cube,0);
+    ilx=cpl_image_get_size_x(i_img);
+    ily=cpl_image_get_size_y(i_img);
+
+    /* allocate memory */
+    if (NULL == (im = cpl_image_new (ilx, ily,CPL_TYPE_FLOAT )) )
+    {
+        sinfo_msg_error ("cannot allocate new image") ;
+        return NULL ;
+    }
+
+    /*------------------------------------------------------------------------
+     * transfer each vector in z direction in a buffer and collect
+       only non-blank data.
+     */
+
+    podata=cpl_image_get_data_float(im);
+    for ( i = 0 ; i < (int) ilx*ily ; i++ )
+    {
+        nz = 0 ;
+        for ( j = 0 ; j < inp ; j ++ )
+        {
+          i_img=cpl_imagelist_get(cube,j);
+      pidata=cpl_image_get_data_float(i_img);
+            if ( !isnan(pidata[i]) )
+            {
+                nz ++ ;
+                podata[i] += pidata[i] ;
+            }
+        }
+
+        /* proceed depending on the number of valid pixels */
+        if ( nz >= 1 )
+        {
+            podata[i] /= nz ;
+        }
+        else if (nz == 0)
+        {
+            podata[i] = ZERO ;
+        }
+    }
+
+    return im ;
+}
+
+/*---------------------------------------------------------------------------
+   Function     :       sinfo_new_sum_cube_to_image()
+   In           :       1 allocated cube
+   Out          :       result image
+   Job          :       determines the sum value in every pixel position
+                        by considering all pixels along the third axis.
+                        ZERO pixels in a plane are not considered. If all
+                        pixels at a position are not valid the result will
+                        be 'ZERO'.
+ ---------------------------------------------------------------------------*/
+cpl_image *
+sinfo_new_sum_cube_to_image(cpl_imagelist * cube)
+{
+    cpl_image  *      im ;
+    int        i, j, nz ;
+    int ilx=0;
+    int ily=0;
+    int inp=0;
+    float* pidata=NULL;
+    float* podata=NULL;
+    cpl_image* i_img=NULL;
+
+    if ( cube == NULL )
+    {
+        sinfo_msg_error ("null cube") ;
+        return NULL ;
+    }
+    inp=cpl_imagelist_get_size(cube);
+    i_img=cpl_imagelist_get(cube,0);
+    ilx=cpl_image_get_size_x(i_img);
+    ily=cpl_image_get_size_y(i_img);
+
+    /* allocate memory */
+    if (NULL == (im = cpl_image_new (ilx, ily, CPL_TYPE_FLOAT )) )
+    {
+        sinfo_msg_error ("cannot allocate new image") ;
+        return NULL ;
+    }
+
+    /*-------------------------------------------------------------------------
+     * transfer each vector in z direction in a buffer and collect only
+       non-blank data.
+     */
+
+    podata=cpl_image_get_data_float(im);
+    for ( i = 0 ; i < (int) ilx*ily ; i++ )
+    {
+        nz = 0 ;
+        for ( j = 0 ; j < inp ; j ++ )
+        {
+          i_img=cpl_imagelist_get(cube,j);
+      pidata=cpl_image_get_data_float(i_img);
+            if ( !isnan(pidata[i]) )
+            {
+                nz++ ;
+                podata[i] += pidata[i] ;
+            }
+        }
+
+        /* proceed depending on the number of valid pixels */
+        if (nz == 0)
+        {
+            podata[i] = ZERO ;
+        }
+    }
+
+    return im ;
+}
+
+/*---------------------------------------------------------------------------
+   Function    sinfo_new_average_cube_to_image_between_waves()
+   In         cube: data cube to collapse
+                dispersion: dispersion per pixel in microns/pixel
+                (derived from fits header information)
+                centralWave: central wavelength in the cube in microns
+                                       (derived from fits header information)
+                initialLambda, finalLambda: wavelength values in microns
+                                            within which the cube is averaged
+   Out         :resulting averaged image
+   Job        :determines the average value in every pixel position
+                 by considering only the pixels along the third axis
+                 which lie between the given wavelength values.
+                 These values are first recalculated to plane indices
+                 by using the given dispersion and minimum wavelength in
+                 the cube.
+                 ZERO pixels in a plane are not considered. If all
+                 pixels at a position are not valid the result will
+                 be 'ZERO'.
+ ---------------------------------------------------------------------------*/
+cpl_image *
+sinfo_new_average_cube_to_image_between_waves (cpl_imagelist * cube,
+                                           float     dispersion,
+                                           float     centralWave,
+                                           float     initialLambda,
+                                           float     finalLambda)
+{
+    cpl_image  *      im ;
+    int        firstPlane ;
+    int        lastPlane ;
+    int        i, j, nz ;
+    float      minWave ;
+    int ilx=0;
+    int ily=0;
+    int inp=0;
+    float* pidata=NULL;
+    float* podata=NULL;
+    cpl_image* i_img=NULL;
+
+    if ( cube == NULL )
+    {
+        sinfo_msg_error ("null cube") ;
+        return NULL ;
+    }
+    i_img=cpl_imagelist_get(cube,0);
+    ilx=cpl_image_get_size_x(i_img);
+    ily=cpl_image_get_size_y(i_img);
+
+    inp=cpl_imagelist_get_size(cube);
+
+    minWave = centralWave - (float) (inp / 2)*dispersion ;
+
+    if ( dispersion <= 0. || minWave <= 0. )
+    {
+        sinfo_msg_error ("wrong dispersion or minimum wavelength given") ;
+        return NULL ;
+    }
+
+    if ( initialLambda < minWave ||
+        (initialLambda >= minWave + dispersion * inp) )
+    {
+        sinfo_msg_error ("wrong initial wavelength given") ;
+        return NULL ;
+    }
+
+    if ( finalLambda <= minWave ||
+        (finalLambda > minWave + dispersion * inp) )
+    {
+        sinfo_msg_error ("wrong final wavelength given") ;
+        return NULL ;
+    }
+
+    /* allocate memory */
+    if (NULL == (im = cpl_image_new (ilx, ily, CPL_TYPE_FLOAT )) )
+    {
+        sinfo_msg_error ("cannot allocate new image") ;
+        return NULL ;
+    }
+
+    /* transfer the wavelength range to image plane indices */
+    firstPlane = sinfo_new_nint ((double) ((initialLambda - minWave) /
+                                          dispersion)) ;
+    lastPlane  = sinfo_new_nint ((double) ((finalLambda - minWave) /
+                                          dispersion)) ;
+
+    if ( firstPlane < 0 || firstPlane >= inp ||
+         lastPlane  < 0 || lastPlane  >  inp )
+    {
+        sinfo_msg_error ("wrong values given!") ;
+        return NULL ;
+    }
+
+    /*------------------------------------------------------------------------
+     * transfer each vector in z direction in a buffer and collect only
+       non-blank data.
+     */
+
+
+
+    podata=cpl_image_get_data_float(im);
+    for ( i = 0 ; i < (int) ilx*ily ; i++ )
+    {
+        nz = 0 ;
+
+        for ( j = firstPlane ; j <= lastPlane ; j ++ )
+        {
+          i_img=cpl_imagelist_get(cube,j);
+      pidata=cpl_image_get_data_float(i_img);
+            if ( !isnan(pidata[i]) )
+            {
+                nz ++ ;
+                podata[i] += pidata[i] ;
+            }
+        }
+
+        /* proceed depending on the number of valid pixels */
+        if ( nz >= 1 )
+        {
+            podata[i] /= nz ;
+        }
+        else if (nz == 0)
+        {
+            podata[i] = ZERO ;
+        }
+    }
+
+    return im ;
+}
+
+/*---------------------------------------------------------------------------
+   Function    :    sinfo_new_extract_image_from_cube()
+   In         :    1 allocated cube
+                        index of cube plane
+   Out         :    extracted image
+   Job        :    returns the wanted image plane of the cube
+ ---------------------------------------------------------------------------*/
+cpl_image *
+sinfo_new_extract_image_from_cube(cpl_imagelist * cube, int plane_index)
+{
+    if ( cube == NULL )
+    {
+        sinfo_msg_error ("null cube") ;
+        return NULL ;
+    }
+
+    if ( plane_index < 0 || plane_index >= cpl_imagelist_get_size(cube) )
+    {
+        sinfo_msg_error ("wrong plane index for image to be extracted") ;
+        return NULL ;
+    }
+
+    return cpl_imagelist_get(cube,plane_index) ;
+}
+
+/*---------------------------------------------------------------------------
+   Function    :sinfo_new_extract_spectrum_from_cube()
+   In         :cube: 1 allocated cube
+                 x_pos, y_pos: x, y pixel position of the
+                               spectrum counted from 0
+   Out         :extracted spectral sinfo_vector object
+   Job        :returns the wanted single spectrum of the cube
+ ---------------------------------------------------------------------------*/
+Vector *
+sinfo_new_extract_spectrum_from_cube(cpl_imagelist * cube,
+                                     int x_pos, int y_pos)
+{
+    Vector * returnedSpectrum ;
+    int i ;
+    int ilx=0;
+    int ily=0;
+    int inp=0;
+    float* pidata=NULL;
+    cpl_image* i_img=NULL;
+
+    if ( cube == NULL )
+    {
+        sinfo_msg_error ("no cube given!") ;
+        return NullVector ;
+    }
+    i_img=cpl_imagelist_get(cube,0);
+    ilx=cpl_image_get_size_x(i_img);
+    ily=cpl_image_get_size_y(i_img);
+    inp=cpl_imagelist_get_size(cube);
+
+    if ( x_pos < 0 || x_pos >= ilx )
+    {
+        sinfo_msg_error ("wrong x-positon of spectrum given!") ;
+        return NullVector ;
+    }
+
+    if ( y_pos < 0 || y_pos >= ily )
+    {
+        sinfo_msg_error ("wrong y-positon of spectrum given!") ;
+        return NullVector ;
+    }
+
+    /* allocate memory */
+    if ( NULL == (returnedSpectrum = sinfo_new_vector ( inp )) )
+    {
+        sinfo_msg_error ("cannot allocate new spectrum!") ;
+        return NullVector ;
+    }
+
+    for ( i = 0 ; i < inp ; i++ )
+    {
+      i_img=cpl_imagelist_get(cube,i);
+      pidata=cpl_image_get_data_float(i_img);
+      returnedSpectrum -> data[i] = pidata[x_pos + ilx*y_pos] ;
+    }
+
+    return returnedSpectrum ;
+}
+
+/*---------------------------------------------------------------------------
+   Function     :       sinfo_new_combine_jittered_cubes()
+   In           :       cubes: list of jittered cubes to mosaic
+                        mergedCube: resulting merged cube containing the
+                                      jittered cubes
+                        n_cubes: number of cubes in the list to merge
+                        cumoffsetx,y: array of relative x, y pixel offsets
+                                      with respect to the first frame in the
+                                      same sequence as the cube list.
+                        exptimes: exposure times array giving the time
+                                  in the same sequence as the cube list
+                        kernel_type: the name of the interpolation kernel
+                                     that you want to generate using the
+                                     eclipse routine
+                                     sinfo_generate_interpolation_kernel()
+                                     Supported kernels are:
+                                     NULL:      default kernel, currently tanh
+                                     "default": dito
+                                     "tanh":    Hyperbolic tangent
+                                     "sinc2":   Square sinc
+                                     "lanczos": Lanczos2 kernel
+                                     "hamming": Hamming kernel
+                                     "hann":    Hann kernel
+   Out          :       mask: cube of the same size as combinedCube
+                              containing 0 for blank (ZERO pixels) and
+                              the summed integration times for
+                              overlapping regions
+                        mergedCube: final data cube containing the
+                                    jittered cubes
+   Job          :       merges jittered data cubes to one bigger cube
+                        by averaging the overlap regions weighted by
+                        the integration times. The x, y size of the final data
+                        cube is user given, and should be between 32 and 64
+                        pixels, while the relative pixel-offset (sub-pixel
+                        accuracy) of the single cubes with respect to the
+                        first cube in the list is read from the
+                        SEQ CUMOFFSETX,Y
+                        fits header keyword.
+ ---------------------------------------------------------------------------*/
+cpl_imagelist *
+sinfo_new_combine_jittered_cubes ( cpl_imagelist ** cubes,
+                                 cpl_imagelist  * mergedCube,
+                                 int        n_cubes,
+                                 float    * cumoffsetx,
+                                 float    * cumoffsety,
+                                 float    * exptimes,
+                                 char     * kernel_type )
+{
+
+    int i=0 ;
+    int x=0;
+    int y=0;
+    int z=0;
+    int llx0=0;
+    int lly0=0;
+    int posx=0;
+    int posy=0;
+    float weight=0;
+    cpl_imagelist * mask=NULL;
+    double * kernel=NULL;
+    /*cpl_image * shiftedImage ;*/
+
+    int* llx=NULL ;
+    int* lly=NULL ;
+
+    float* sub_offsetx=NULL ;
+    float* sub_offsety=NULL ;
+
+    cpl_imagelist ** tmpcubes=NULL ;
+    pixelvalue * tmpspace=NULL;
+
+
+  int ilx=0;
+  int ily=0;
+  int olx=0;
+  int oly=0;
+  int mlx=0;
+  int onp=0;
+  int inp=0;
+
+
+
+  float* podata=NULL;
+  float* pmdata=NULL;
+  float* ptdata=NULL;
+
+  cpl_image* i_img=NULL;
+  cpl_image* o_img=NULL;
+  cpl_image* m_img=NULL;
+  cpl_image* t_img=NULL;
+
+
+    if ( cubes == NULL )
+    {
+        sinfo_msg_error ("no cube list given!") ;
+        return NULL ;
+    }
+    if ( n_cubes <= 0 )
+    {
+        sinfo_msg_error ("wrong number of data cubes in list!") ;
+        return NULL ;
+    }
+    if ( cumoffsetx == NULL || cumoffsety == NULL )
+    {
+        sinfo_msg_error ("no cumoffsetx/y given!") ;
+        return NULL ;
+    }
+    if ( exptimes == NULL )
+    {
+        sinfo_msg_error ("no exposure time array given!") ;
+        return NULL ;
+    }
+
+    o_img=cpl_imagelist_get(mergedCube,0);
+    olx=cpl_image_get_size_x(o_img);
+    oly=cpl_image_get_size_y(o_img);
+    onp=cpl_imagelist_get_size(mergedCube);
+    if ( NULL == (mask = cpl_imagelist_new()) )
+    {
+        sinfo_msg_error ("could not allocate cube!") ;
+        return NULL ;
+    }
+    for(i=0;i<onp;i++){
+      o_img=cpl_image_new(olx,oly,CPL_TYPE_FLOAT);
+      cpl_imagelist_set(mergedCube,o_img,i);
+    }
+
+    i_img=cpl_imagelist_get(cubes[0],0);
+    ilx=cpl_image_get_size_x(i_img);
+    ily=cpl_image_get_size_y(i_img);
+
+    inp=cpl_imagelist_get_size(cubes[0]);
+
+    /*--------------------------------------------------------------------
+     * center the cubes within the allocated big cube
+     * that means define the (0,0) positions of the cubes in the image planes
+     * to sub-pixel accuracy by using cumoffsetx,y and the reference cube
+     */
+    /* position of first reference frame, centered in big cube */
+    llx0 = olx/2 - ilx/2 ;
+    lly0 = oly/2 - ily/2 ;
+
+    /*--------------------------------------------------------------------
+     * go through the frame list and determine the lower left edge position
+     * of the shifted cubes. Additionnally, the sub-pixel offsets are
+     * determined.
+     */
+
+    llx=cpl_calloc(n_cubes,sizeof(int)); ;
+    lly=cpl_calloc(n_cubes,sizeof(int)) ;
+
+    sub_offsetx=cpl_calloc(n_cubes,sizeof(float)) ;
+    sub_offsety=cpl_calloc(n_cubes,sizeof(float)) ;
+
+    for ( i = 0 ; i < n_cubes ; i++ )
+    {
+        llx[i] = llx0 - sinfo_new_nint(cumoffsetx[i]) ;
+        sub_offsetx[i] = (float)sinfo_new_nint(cumoffsetx[i]) - cumoffsetx[i] ;
+        lly[i] = lly0 - sinfo_new_nint(cumoffsety[i]) ;
+        sub_offsety[i] = (float)sinfo_new_nint(cumoffsety[i]) - cumoffsety[i] ;
+    }
+
+
+    /* -------------------------------------------------------------
+     * shift the cubes according to the computed sub-pixel offsets
+     * that means shift the single image planes of each cube
+     * first determine an interpolation kernel
+     */
+    if ( NULL == (kernel = sinfo_generate_interpolation_kernel(kernel_type)))
+    {
+        sinfo_msg_warning ("could not generate desired interpolation kernel"
+                           " or no kernel_typ was given, the default kernel"
+                           " is used now!") ;
+    }
+    /* go through the frame list */
+
+
+    tmpcubes=(cpl_imagelist**)cpl_calloc(n_cubes,sizeof(cpl_imagelist*)) ;
+
+    for ( i = 0 ; i < n_cubes ; i++ )
+    {
+        tmpspace = cpl_calloc(ilx, ily*sizeof(pixelvalue)) ;
+        tmpcubes[i] = cpl_imagelist_new();
+
+        for ( z = 0 ; z < inp ; z++ )
+        {
+
+
+            t_img=sinfo_new_shift_image(cpl_imagelist_get(cubes[i],z),
+                                  sub_offsetx[i], sub_offsety[i], kernel);
+
+        if (t_img==NULL)
+            {
+                sinfo_msg_error ("could not shift image plane no %d"
+                                 " in cube no %d!", z, i) ;
+                cpl_imagelist_delete(mergedCube) ;
+                cpl_imagelist_delete(mask) ;
+                cpl_free(kernel) ;
+                return NULL ;
+            }
+            cpl_imagelist_set(tmpcubes[i],t_img,z);
+        }
+    cpl_free(tmpspace);
+    }
+
+    /*-------------------------------------------------------------------------
+     * Build the mask data cube.
+     * The mask is 0 where no data is available, otherwise the integration
+       time of one frame, respectively the summed integration
+     * times in the overlapping regions are inserted
+     */
+    /* go through the frame list */
+    for ( i = 0 ; i < n_cubes ; i++ )
+    {
+
+        /* go through the first image plane of the big data cube */
+        for ( y = 0 ; y < oly ; y++ )
+        {
+            for ( x = 0 ; x < olx ; x++ )
+            {
+                /* find the position of the present cube and
+                   go through the single spectra */
+                if ( y >= lly[i] && y < lly[i]+ily &&
+                     x >= llx[i] && x < llx[i]+ilx )
+                {
+                    posx = x - llx[i] ;
+                    posy = y - lly[i] ;
+                    for ( z = 0 ; z < onp ; z++ )
+                    {
+              t_img=cpl_imagelist_get(tmpcubes[i],z);
+                      ptdata=cpl_image_get_data_float(t_img);
+              m_img=cpl_imagelist_get(mask,z);
+                      pmdata=cpl_image_get_data_float(m_img);
+                        if (!isnan(ptdata[posx+posy*ilx]) &&
+                                         ptdata[posx+posy*ilx] != 0.)
+                        {
+                            pmdata[x+y*mlx] += exptimes[i] ;
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+
+
+
+
+
+    /* calculate a weighted average using the
+       exposure time of the single frames
+       of the overlapping regions of the cubes */
+    for ( i = 0 ; i < n_cubes ; i++ )
+    {
+
+        /* go through the first image plane of the big data cube */
+        for ( y = 0 ; y < oly ; y++ )
+        {
+
+            for ( x = 0 ; x < olx ; x++ )
+            {
+
+                /* find the position of the present cube
+                   and go through the single spectra */
+                if ( y >= lly[i] && y < lly[i]+ily &&
+                     x >= llx[i] && x < llx[i]+ilx )
+                {
+
+                    posx = x - llx[i] ;
+                    posy = y - lly[i] ;
+                    for ( z = 0 ; z < onp ; z++ )
+                    {
+
+              t_img=cpl_imagelist_get(tmpcubes[i],z);
+                      ptdata=cpl_image_get_data_float(t_img);
+              m_img=cpl_imagelist_get(mask,z);
+                      pmdata=cpl_image_get_data_float(m_img);
+                      mlx=cpl_image_get_size_x(m_img);
+
+              o_img=cpl_imagelist_get(mergedCube,z);
+                      podata=cpl_image_get_data_float(o_img);
+                      podata[x+y*olx]=0;
+                        if (!isnan(ptdata[posx+posy*ilx]))
+                        {
+                            if (pmdata[x+y*mlx] != 0.)
+                            {
+                /* adjust the intensities to
+                                   the first reference cube */
+                                weight = exptimes[0] / pmdata[x+y*mlx] ;
+                            }
+                            else
+                            {
+                                weight = 0. ;
+                            }
+                            podata[x+y*olx] +=
+                               weight*ptdata[posx+posy*ilx] ;
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+
+
+
+    /* convert the "free space" in the cube to blank pixels */
+    /* convert_0_to_ZERO_for_cubes(mergedCube) ; */
+    cpl_free(kernel) ; /* originated by eclise-malloc */
+    for( i = 0 ; i < n_cubes ; i++ )
+    {
+        cpl_imagelist_delete (tmpcubes[i]) ;
+    }
+
+    cpl_free(tmpcubes); ;
+    cpl_free(llx); ;
+    cpl_free(lly) ;
+
+    cpl_free(sub_offsetx) ;
+    cpl_free(sub_offsety) ;
+
+    return mask ;
+}
+
+
+
+
+
+
+
+
+/**
+
+   @name sinfo_build_mask_cube
+   @brief Build the mask data cube.
+   @param z_min  minimum cube's plane processed
+   @param z_max  maximum cube's plane processed
+   @param olx    output cube x size
+   @param oly    output cube y size
+   @param n_cubes: number of cubes in the list to merge
+   @param llx    lower left edge x position of the shifted cubes.
+   @param lly    lower left edge y position of the shifted cubes.
+   @param exptimes: exposure times array giving the time
+                    in the same sequence as the cube list
+
+   @param  cubes: list of jittered cubes to mosaic
+   @param  tmpcubes: list of shifted jittered cubes to mosaic
+   @param  mask: cube of the same size as combinedCube
+                 containing 0 for blank (ZERO pixels) and
+                 the summed integration times for
+                 overlapping regions
+
+
+   @doc Build the mask data cube.
+        The mask is 0 where no data is available, otherwise the
+        integration time of one frame, respectively the summed integration
+        times in the overlapping regions are inserted
+
+*/
+
+static int
+sinfo_build_mask_cube(const int z_min,
+                      const int z_max,
+                      const int olx,
+                      const int oly,
+                      const int n_cubes,
+                      const int* llx,
+                      const int* lly,
+		      double    * exptimes,
+                      cpl_imagelist** cubes,
+                      cpl_imagelist** tmpcubes,
+                      cpl_imagelist* mask)
+{
+
+  int i=0;
+  int y=0;
+  int z=0;
+  int ilx=0;
+  int ily=0;
+  cpl_image* i_img=NULL;
+  cpl_image* t_img=NULL;
+  int posx=0;
+  int posy=0;
+  float* ptdata=NULL;
+  float* pmdata=NULL;
+  int m=0;
+  int x=0;
+  int mlx=0;
+  cpl_image* m_img=NULL;
+
+
+  for ( z = z_min, m=0 ; z < z_max ; z++, m++ ) {
+
+    // go through the first image plane of the big data cube
+    for ( y = 0 ; y < oly ; y++ ) {
+      for ( x = 0 ; x < olx ; x++ ) {
+	for ( i = 0 ; i < n_cubes ; i++ ) {
+
+          i_img=cpl_imagelist_get(cubes[i],0);
+          ilx=cpl_image_get_size_x(i_img);
+          ily=cpl_image_get_size_y(i_img);
+
+
+	  // find the position of the present cube and go
+          // through the single spectra */
+          if ( y >= lly[i] && y < lly[i]+ily &&
+               x >= llx[i] && x < llx[i]+ilx )
+	    {
+	      posx = x - llx[i] ;
+	      posy = y - lly[i] ;
+
+
+              t_img=cpl_imagelist_get(tmpcubes[i],m);
+              ptdata=cpl_image_get_data_float(t_img);
+              m_img=cpl_imagelist_get(mask,z);
+              pmdata=cpl_image_get_data_float(m_img);
+	      mlx=cpl_image_get_size_x(m_img);
+
+              if (!isnan(ptdata[posx+posy*ilx]) &&
+                         ptdata[posx+posy*ilx] != 0.)
+		{
+		  pmdata[x+y*mlx] += (float)exptimes[i] ;
+		} else if (isnan(ptdata[posx+posy*ilx])) {
+		sinfo_msg_debug("ptdata %d, %d, %d is NAN\t",x,y,z);
+	      } else if (ptdata[posx+posy*ilx] == 0.) {
+		sinfo_msg_debug("ptdata %d, %d, %d is 0\t",x,y,z);
+	      }
+
+	    } else {
+	    sinfo_msg_debug("point %d, %d, %d outside range\n",x,y,z);
+	  }
+        }
+      }
+    }
+  }
+  return 0;
+
+}
+
+
+
+
+static int
+sinfo_build_mask_cube_thomas(const int z_min,
+                      const int z_max,
+                      const int olx,
+                      const int oly,
+                      const int n_cubes,
+                      const int* llx,
+                      const int* lly,
+		      double    * exptimes,
+                      cpl_imagelist** cubes,
+                      cpl_imagelist** tmpcubes,
+                      cpl_imagelist* mask)
+{
+
+  int i=0;
+  int y=0;
+  int z=0;
+  int ilx=0;
+  int ily=0;
+  int inp=0;
+  cpl_image* i_img=NULL;
+  cpl_image* t_img=NULL;
+  int posx=0;
+  int posy=0;
+  float* ptdata=NULL;
+  float* pmdata=NULL;
+  int m=0;
+  int x=0;
+  int mlx=0;
+  cpl_image* m_img=NULL;
+
+  for ( i = 0 ; i < n_cubes ; i++ ) {
+
+    i_img=cpl_imagelist_get(cubes[i],0);
+    ilx=cpl_image_get_size_x(i_img);
+    ily=cpl_image_get_size_y(i_img);
+    inp=cpl_imagelist_get_size(cubes[i]);
+
+    //go through the first image plane of the big data cube
+    for ( y = 0 ; y < oly ; y++ ){
+      for ( x = 0 ; x < olx ; x++ ){
+	// find the position of the present cube and go
+	// through the single spectra
+        if ( y >= lly[i] && y < lly[i]+ily &&
+             x >= llx[i] && x < llx[i]+ilx ) {
+	  posx = x - llx[i] ;
+          posy = y - lly[i] ;
+
+	  for ( z = z_min,m=0 ; z < z_max ; z++,m++ ) {
+	    t_img=cpl_imagelist_get(tmpcubes[i],m);
+            ptdata=cpl_image_get_data_float(t_img);
+            m_img=cpl_imagelist_get(mask,z);
+            pmdata=cpl_image_get_data_float(m_img);
+            mlx=cpl_image_get_size_x(m_img);
+
+            if (!isnan(ptdata[posx+posy*ilx]) &&
+		ptdata[posx+posy*ilx] != 0.) {
+	      pmdata[x+y*mlx] += (float)exptimes[i]  ;
+	    }
+	  }
+	}
+      }
+    }
+  }
+  return 0;
+}
+
+
+
+
+
+/**
+
+   @name   sinfo_new_combine_jittered_cubes()
+   @param  cubes: list of jittered cubes to mosaic
+   @param  mergedCube: resulting merged cube containing the
+                                      jittered cubes
+   @param  mask: cube of the same size as combinedCube
+                 containing 0 for blank (ZERO pixels) and
+                 the summed integration times for
+                 overlapping regions
+
+   @param n_cubes: number of cubes in the list to merge
+   @param cumoffsetx: array of relative x pixel offsets
+                      with respect to the first frame in the
+                      same sequence as the cube list.
+
+   @param cumoffsety: array of relative y pixel offsets
+                      with respect to the first frame in the
+                      same sequence as the cube list.
+
+   @param exptimes: exposure times array giving the time
+                    in the same sequence as the cube list
+   @param kernel_type: the name of the interpolation kernel
+                       that you want to generate using the
+                       eclipse routine
+                       sinfo_generate_interpolation_kernel()
+                       Supported kernels are:
+                       NULL:      default kernel, currently tanh
+                                     "default": dito
+                                     "tanh":    Hyperbolic tangent
+                                     "sinc2":   Square sinc
+                                     "lanczos": Lanczos2 kernel
+                                     "hamming": Hamming kernel
+                                     "hann":    Hann kernel
+   @param z_min  minimum cube's plane processed
+   @param z_max  maximum cube's plane processed
+
+
+   @doc merges jittered data cubes to one bigger cube
+        by averaging the overlap regions weighted by
+        the integration times. The x, y size of the final data
+        cube is user given, and should be between 32 and 64
+        pixels, while the relative pixel-offset (sub-pixel
+        accuracy) of the single cubes with respect to the
+        first cube in the list is read from the
+        SEQ CUMOFFSETX,Y fits header keyword.
+*/
+
+
+
+int
+sinfo_new_combine_jittered_cubes_range ( cpl_imagelist ** cubes,
+                                 cpl_imagelist  * mergedCube,
+                                 cpl_imagelist  * mask,
+                                 int        n_cubes,
+                                 float    * cumoffsetx,
+                                 float    * cumoffsety,
+                                 double    * exptimes,
+                                 char     * kernel_type,
+                                 const int z_min, const int z_max )
+{
+
+  int i;
+  int llx0, lly0 ;
+  cpl_imagelist ** tmpcubes=NULL ;
+  int* llx=NULL ;
+  int* lly=NULL ;
+  float* sub_offsetx=NULL ;
+  float* sub_offsety=NULL ;
+
+  int ilx=0;
+  int ily=0;
+  int olx=0;
+  int oly=0;
+  int mlx=0;
+  int mly=0;
+
+  cpl_image* i_img=NULL;
+  cpl_image* o_img=NULL;
+
+
+  if(sinfo_check_input(cubes,n_cubes,cumoffsetx,cumoffsety,exptimes) == -1) {
+    return -1;
+  }
+
+    o_img=cpl_imagelist_get(mergedCube,z_min);
+    olx=cpl_image_get_size_x(o_img);
+    oly=cpl_image_get_size_y(o_img);
+    i_img=cpl_imagelist_get(cubes[0],0);
+    ilx=cpl_image_get_size_x(i_img);
+    ily=cpl_image_get_size_y(i_img);
+    mlx=olx;
+    mly=oly;
+
+
+    /*--------------------------------------------------------------------
+     * center the cubes within the allocated big cube
+     * that means define the (0,0) positions of the cubes in the image planes
+     * to sub-pixel accuracy by using cumoffsetx,y and the reference cube
+     */
+    /* position of first reference frame, centered in big cube */
+    llx0 = olx/2 - ilx/2 ;
+    lly0 = oly/2 - ily/2 ;
+
+    /*--------------------------------------------------------------------
+     * go through the frame list and determine the lower left edge position
+     * of the shifted cubes. Additionnally, the sub-pixel offsets are
+     * determined.
+     */
+
+
+    llx=cpl_calloc(n_cubes,sizeof(int)) ;
+    lly=cpl_calloc(n_cubes,sizeof(int)) ;
+    sub_offsetx=cpl_calloc(n_cubes,sizeof(float)) ;
+    sub_offsety=cpl_calloc(n_cubes,sizeof(float)) ;
+
+    for ( i = 0 ; i < n_cubes ; i++ )
+    {
+        llx[i] = llx0 - sinfo_new_nint(cumoffsetx[i]) ;
+        sub_offsetx[i] = (float)sinfo_new_nint(cumoffsetx[i]) - cumoffsetx[i] ;
+        lly[i] = lly0 - sinfo_new_nint(cumoffsety[i]) ;
+        sub_offsety[i] = (float)sinfo_new_nint(cumoffsety[i]) - cumoffsety[i] ;
+    }
+
+    tmpcubes=(cpl_imagelist**)cpl_calloc(n_cubes,sizeof(cpl_imagelist*)) ;
+    /* -------------------------------------------------------------
+     * shift the cubes according to the computed sub-pixel offsets
+     * that means shift the single image planes of each cube
+     * first determine an interpolation kernel
+     */
+    if(sinfo_shift_cubes(tmpcubes,kernel_type,n_cubes,cubes,z_min, z_max,
+			 sub_offsetx,sub_offsety,mlx,mly,mask) == -1) {
+      return -1;
+    }
+
+
+    /*-----------------------------------------------------------------------
+     * Build the mask data cube.
+     * The mask is 0 where no data is available, otherwise the
+       integration time of
+     * one frame, respectively the summed integration
+     * times in the overlapping regions are inserted
+     */
+    /* go through the frame list */
+    sinfo_build_mask_cube(z_min,z_max,olx,oly,n_cubes,llx,lly,exptimes,
+                          cubes,tmpcubes,mask);
+
+
+    /* calculate a weighted average using the exposure time of the
+       single frames of the overlapping regions of the cubes */
+
+    sinfo_compute_weight_average(z_min,z_max,ilx,ily,n_cubes,mergedCube,mask,
+                                 tmpcubes,exptimes,llx,lly);
+
+    /* convert the "free space" in the cube to blank pixels */
+     /* convert_0_to_ZERO_for_cubes(mergedCube) ; */
+
+    for( i = 0 ; i < n_cubes ; i++ )
+    {
+        cpl_imagelist_delete (tmpcubes[i]) ;
+    }
+
+
+    cpl_free(tmpcubes) ;
+    cpl_free(llx) ;
+    cpl_free(lly) ;
+    cpl_free(sub_offsetx) ;
+    cpl_free(sub_offsety) ;
+
+     return 0 ;
+}
+
+/**
+   @name   sinfo_new_combine_jittered_cubes()
+   @short check input of cube coaddition functions
+   @param  cubes: list of jittered cubes to mosaic
+   @param n_cubes: number of cubes in the list to merge
+   @param cumoffsetx: array of relative x pixel offsets
+                      with respect to the first frame in the
+                      same sequence as the cube list.
+
+   @param cumoffsety: array of relative y pixel offsets
+                      with respect to the first frame in the
+                      same sequence as the cube list.
+
+   @param exptimes: exposure times array giving the time
+                    in the same sequence as the cube list
+
+*/
+static int
+sinfo_check_input(cpl_imagelist** cubes,
+                          const int n_cubes,
+                          float* cumoffsetx,
+                          float* cumoffsety,
+			  double* exptimes)
+{
+   if ( cubes == NULL )
+    {
+        sinfo_msg_error ("no cube list given!") ;
+        return -1 ;
+    }
+    if ( n_cubes <= 0 )
+    {
+        sinfo_msg_error ("wrong number of data cubes in list!") ;
+        return -1 ;
+    }
+    if ( cumoffsetx == NULL || cumoffsety == NULL )
+    {
+        sinfo_msg_error ("no cumoffsetx/y given!") ;
+        return -1;
+    }
+    if ( exptimes == NULL )
+    {
+        sinfo_msg_error ("no exposure time array given!") ;
+        return -1 ;
+    }
+
+    return 0;
+}
+
+/**
+   @name   sinfo_compute_weight_average
+   @short compute weighted mean of shifted cubes
+   @param z_min  minimum cube's plane processed
+   @param z_max  maximum cube's plane processed
+   @param ilx    input cube component x size
+   @param ily    input cube component y size
+   @param n_cubes: number of cubes in the list to merge
+   @param  cubes: list of jittered cubes to mosaic
+   @param  mergedCube: resulting merged cube containing the
+                                      jittered cubes
+   @param  mask: cube of the same size as combinedCube
+                 containing 0 for blank (ZERO pixels) and
+                 the summed integration times for
+                 overlapping regions
+
+   @param  tmpcubes: shifted list of jittered cubes to mosaic
+
+   @param exptimes: exposure times array giving the time
+                    in the same sequence as the cube list
+
+   @doc calculate a weighted average using the exposure time of the
+        single frames of the overlapping regions of the cubes
+
+*/
+static int
+sinfo_compute_weight_average(const int z_min,
+                             const int z_max,
+                             const int ilx,
+                             const int ily,
+			     const int n_cubes,
+                             cpl_imagelist* mergedCube,
+                             cpl_imagelist* mask,
+                             cpl_imagelist** tmpcubes,
+			     double* exptimes,
+                             int* llx,
+                             int* lly)
+{
+
+  int m=0;
+  int x=0;
+  int y=0;
+  int z=0;
+  int i=0;
+
+  int mlx=0;
+  int mly=0;
+  int olx=0;
+  int oly=0;
+
+  cpl_image* o_img=NULL;
+  cpl_image* m_img=NULL;
+  cpl_image* t_img=NULL;
+
+  float* podata=NULL;
+  float* pmdata=NULL;
+  float* ptdata=NULL;
+  double weight=0;
+
+  int posx=0;
+  int posy=0;
+
+
+  o_img=cpl_imagelist_get(mergedCube,z_min);
+  olx=cpl_image_get_size_x(o_img);
+  oly=cpl_image_get_size_y(o_img);
+  mlx=olx;
+  mly=oly;
+
+  /* calculate a weighted average using the exposure time of the
+     single frames of the overlapping regions of the cubes */
+  for ( z = z_min, m = 0 ; z < z_max ; z++, m++ ) {
+    o_img=cpl_imagelist_get(mergedCube,z);
+    podata=cpl_image_get_data_float(o_img);
+    m_img=cpl_imagelist_get(mask,z);
+    pmdata=cpl_image_get_data_float(m_img);
+    mlx=cpl_image_get_size_x(m_img);
+
+    /* go through the first image plane of the big data cube */
+    for ( y = 0 ; y < oly ; y++ ) {
+      for ( x = 0 ; x < olx ; x++ ) {
+
+       /* find the position of the present cube and
+          go through the single spectra */
+
+	for ( i = 0 ; i < n_cubes ; i++ ) {
+
+          if ( y >= lly[i] && y < lly[i]+ily &&
+               x >= llx[i] && x < llx[i]+ilx ) {
+	    posx = x - llx[i] ;
+            posy = y - lly[i] ;
+
+            t_img=cpl_imagelist_get(tmpcubes[i],m);
+            ptdata=cpl_image_get_data_float(t_img);
+            /* To prevent black regions in peculiar batterfly cases
+              podata[x+y*olx]=0;
+            */
+	    if (!isnan(ptdata[posx+posy*ilx])) {
+	      if (pmdata[x+y*mlx] != 0.) {
+                /* adjust the intensities to the
+                   first reference cube */
+		weight = exptimes[0] / pmdata[x+y*mlx] ;
+	      } else {
+		weight = 0. ;
+	      }
+              podata[x+y*olx] += weight*ptdata[posx+posy*ilx] ;
+
+	    }
+	  }
+	}
+      }
+    }
+  }
+  return 0;
+}
+
+
+/**
+
+   @name sinfo_shift_cubes
+   @brief shift the cubes according to the computed sub-pixel offsets
+   @param tmpcubes the shifted cubes list
+   @param kernel_type: the name of the interpolation kernel
+                       that you want to generate using the
+                       eclipse routine
+                       sinfo_generate_interpolation_kernel()
+                       Supported kernels are:
+                       NULL:      default kernel, currently tanh
+                                     "default": dito
+                                     "tanh":    Hyperbolic tangent
+                                     "sinc2":   Square sinc
+                                     "lanczos": Lanczos2 kernel
+                                     "hamming": Hamming kernel
+                                     "hann":    Hann kernel
+
+   @param n_cubes: number of cubes in the list to merge
+   @param  cubes: list of jittered cubes to mosaic
+   @param z_min  minimum cube's plane processed
+   @param z_max  maximum cube's plane processed
+   @param sub_offsetx lower left edge x sub pixel position of the
+                 shifted cubes.
+   @param sub_offsety lower left edge y sub pixel position of the
+                 shifted cubes.
+
+   @param mlx    output mask cube x size
+   @param mly    output mask cube y size
+   @param  mask: cube of the same size as combinedCube
+                 containing 0 for blank (ZERO pixels) and
+                 the summed integration times for
+                 overlapping regions
+
+    @doc shift the cubes according to the computed sub-pixel offsets
+         that means shift the single image planes of each cube
+         first determine an interpolation kernel
+*/
+
+static int
+sinfo_shift_cubes(cpl_imagelist** tmpcubes,
+                  char* kernel_type,
+                  const int n_cubes,
+                  cpl_imagelist** cubes,
+                  const int z_min,
+                  const int z_max,
+                  float* sub_offsetx,
+                  float* sub_offsety,
+                  const int mlx,
+                  const int mly,
+                  cpl_imagelist* mask)
+{
+
+   double * kernel ;
+   int i=0;
+   cpl_image* i_img=NULL;
+   int ilx=0;
+   int ily=0;
+   int inp=0;
+   pixelvalue * tmpspace;
+   int z=0;
+   cpl_image* t_img=NULL;
+   cpl_image* m_img=NULL;
+   int m=0;
+
+    /* -------------------------------------------------------------
+     * shift the cubes according to the computed sub-pixel offsets
+     * that means shift the single image planes of each cube
+     * first determine an interpolation kernel
+     */
+
+   if ( NULL == (kernel = sinfo_generate_interpolation_kernel(kernel_type)) )
+    {
+        sinfo_msg_warning ("could not generate desired interpolation kernel"
+                           "or no kernel_typ was given, the default kernel"
+                           "is used now!") ;
+    }
+    /* go through the frame list */
+
+    for ( i = 0 ; i < n_cubes ; i++ )
+    {
+
+      i_img=cpl_imagelist_get(cubes[i],0);
+      ilx=cpl_image_get_size_x(i_img);
+      ily=cpl_image_get_size_y(i_img);
+      inp=cpl_imagelist_get_size(cubes[i]);
+      tmpspace = cpl_calloc(ilx, ily*sizeof(pixelvalue)) ;
+      tmpcubes[i]=cpl_imagelist_new();
+
+        for ( z = z_min, m=0 ; z < z_max ; z++, m++ )
+        {
+              t_img=sinfo_new_shift_image(cpl_imagelist_get(cubes[i],z),
+                                          sub_offsetx[i],
+                                          sub_offsety[i],
+                                          kernel);
+
+        if (t_img==NULL)
+            {
+                sinfo_msg_error("could not shift image plane no %d "
+                                "in cube no %d!", z, i) ;
+                cpl_free(kernel) ;
+                return -1 ;
+            }
+
+            cpl_imagelist_set(tmpcubes[i],t_img,m);
+            m_img=cpl_image_new(mlx,mly,CPL_TYPE_FLOAT);
+            cpl_imagelist_set(mask,m_img,z);
+        }
+
+     cpl_free(tmpspace);
+
+    }
+    if(kernel != NULL) cpl_free(kernel) ;
+
+    return 0;
+
+}
+
+
+/* Temporally commented out as not yet used
+static int
+sinfo_ks_clip(
+	      const int n_cubes,
+              const int nc,
+	      const int ilx,
+	      const int ily,
+	      const double kappa,
+	      int* llx,
+	      int* lly,
+	      double* exptimes,
+	      cpl_imagelist** tmpcubes,
+              float* podata,
+              float* pmdata,
+	      const int x,
+	      const int y,
+	      const int m,
+	      const int mlx,
+	      const int olx
+  )
+{
+
+
+  int posx=0;
+  int posy=0;
+  int i=0;
+  int nclip=0;
+  int ks=0;
+
+  float sig=0;
+  float med=0;
+  float ovr=0;
+  float avg=0;
+
+  float* ptdata=NULL;
+  float* pvdata=NULL;
+
+  cpl_image* t_img=NULL;
+  float  msk_sum=0;
+  float  val_msk_sum=0;
+  cpl_image* v_img=NULL;
+
+  cpl_vector* val=NULL;
+  cpl_vector* msk=NULL;
+
+  msk=cpl_vector_new(n_cubes);
+  for (i=0;i<n_cubes;i++) {
+    cpl_vector_set(msk,i,1);
+  }
+
+  // k-s clipping
+  nclip=0;
+
+  for (ks=0;ks<nc;ks++) {
+
+    sig=0;
+    med=0;
+    ovr=0;
+    if(nc-nclip >0) {
+      val=cpl_vector_new(nc-nclip);
+    }
+
+    // fill val
+    for ( i = 0 ; i < n_cubes ; i++ ) {
+      t_img=cpl_imagelist_get(tmpcubes[i],m);
+      ptdata=cpl_image_get_data_float(t_img);
+      if ( y >= lly[i] && y < lly[i]+ily &&
+	   x >= llx[i] && x < llx[i]+ilx ) {
+	posx = x - llx[i] ;
+	posy = y - lly[i] ;
+	if (!isnan(ptdata[posx+posy*ilx]) &&
+	    ptdata[posx+posy*ilx] != 0. &&
+	    (cpl_vector_get(msk,i) != 0)) {
+	  cpl_vector_set(val,ovr,(double)ptdata[posx+posy*ilx]);
+	  ovr++;
+	}
+      }
+    }
+
+    // get avg, med, sig
+    if(ovr>0) {
+      avg=cpl_vector_get_mean(val);
+      med=cpl_vector_get_median_const(val);
+      if(ovr>1) {
+	sig=cpl_vector_get_stdev(val);
+      } else {
+	sig=0;
+      }
+      cpl_vector_delete(val);
+    }
+
+    for ( i = 0 ; i < n_cubes ; i++ ) {
+      t_img=cpl_imagelist_get(tmpcubes[i],m);
+      ptdata=cpl_image_get_data_float(t_img);
+      // Do k-s clipping at each pixel
+      if ( y >= lly[i] && y < lly[i]+ily &&
+	   x >= llx[i] && x < llx[i]+ilx ) {
+	posx = x - llx[i] ;
+	posy = y - lly[i] ;
+	//sinfo_msg_warning("llx[%d]=%d lly[%d],=%d",i,llx[i],i,lly[i]);
+	//sinfo_msg_warning("posx=%d posy=%d",posx,posy);
+	if (!isnan(ptdata[posx+posy*ilx]) &&
+	    ptdata[posx+posy*ilx] != 0. &&
+	    (cpl_vector_get(msk,i) != 0)) {
+	  if(abs((ptdata[posx+posy*ilx]-med))> kappa*sig) {
+	    ptdata[posx+posy*ilx]=0;
+
+	    pmdata[x+y*mlx] -= exptimes[i]  ;
+
+	    cpl_vector_set(msk,i,0);
+	    nclip++;
+	  }
+	}
+      }
+
+    }
+  }
+
+  msk_sum=0;
+  val_msk_sum=0;
+  for ( i = 0 ; i < n_cubes ; i++ ) {
+    v_img=cpl_imagelist_get(tmpcubes[i],m);
+    pvdata=cpl_image_get_data_float(v_img);
+    // computes sky at each point
+    if ( y >= lly[i] && y < lly[i]+ily &&
+	 x >= llx[i] && x < llx[i]+ilx ) {
+      posx = x - llx[i] ;
+      posy = y - lly[i] ;
+      if (!isnan(pvdata[posx+posy*ilx]) &&
+	  pvdata[posx+posy*ilx] != 0. &&
+	  (cpl_vector_get(msk,i) != 0)) {
+
+	msk_sum+= pmdata[x+y*mlx];
+
+	val_msk_sum+=pvdata[posx+posy*ilx]*
+	  pmdata[x+y*mlx];
+
+      }
+    }
+  }
+
+  podata[x+y*olx]=val_msk_sum/msk_sum;
+  cpl_vector_delete(msk);
+
+  return 0;
+
+}
+
+*/
+
+/**
+
+   @name   sinfo_new_combine_jittered_cubes_thomas_range()
+   @param  cubes: list of jittered cubes to mosaic (over a given range
+                  with kappa-sigma clipping of outliers)
+   @param  mergedCube: resulting merged cube containing the
+                                      jittered cubes
+   @param  mask: cube of the same size as combinedCube
+                 containing 0 for blank (ZERO pixels) and
+                 the summed integration times for
+                 overlapping regions
+
+   @param n_cubes: number of cubes in the list to merge
+   @param cumoffsetx: array of relative x pixel offsets
+                      with respect to the first frame in the
+                      same sequence as the cube list.
+
+   @param cumoffsety: array of relative y pixel offsets
+                      with respect to the first frame in the
+                      same sequence as the cube list.
+
+   @param exptimes: exposure times array giving the time
+                    in the same sequence as the cube list
+   @param kernel_type: the name of the interpolation kernel
+                       that you want to generate using the
+                       eclipse routine
+                       sinfo_generate_interpolation_kernel()
+                       Supported kernels are:
+                       NULL:      default kernel, currently tanh
+                                     "default": dito
+                                     "tanh":    Hyperbolic tangent
+                                     "sinc2":   Square sinc
+                                     "lanczos": Lanczos2 kernel
+                                     "hamming": Hamming kernel
+                                     "hann":    Hann kernel
+   @param z_min  minimum cube's plane processed
+   @param z_max  maximum cube's plane processed
+   @param kappa  value for kappa-sigma clipping
+
+   @doc merges jittered data cubes to one bigger cube
+        by averaging the overlap regions weighted by
+        the integration times. The x, y size of the final data
+        cube is user given, and should be between 32 and 64
+        pixels, while the relative pixel-offset (sub-pixel
+        accuracy) of the single cubes with respect to the
+        first cube in the list is read from the
+        SEQ CUMOFFSETX,Y fits header keyword.
+*/
+
+int
+sinfo_new_combine_jittered_cubes_thomas_range(cpl_imagelist ** cubes,
+                    cpl_imagelist  * mergedCube,
+                    cpl_imagelist  * mask,
+                    int        n_cubes,
+                    float    * cumoffsetx,
+                    float    * cumoffsety,
+                    double    * exptimes,
+                    char     * kernel_type,
+                    const int z_min,
+                    const int z_max,
+                                    const double kappa )
+{
+	const int VERY_BIG_INT = 268431360;
+  int i ;
+  int llx0, lly0 ;
+  int* llx=NULL;
+  int* lly=NULL ;
+  float* sub_offsetx=NULL ;
+  float* sub_offsety=NULL ;
+  cpl_imagelist ** tmpcubes=NULL ;
+  const int z_siz=z_max-z_min;
+  int ilx=0;
+  int ily=0;
+  int olx=0;
+  int oly=0;
+  int mlx=0;
+  int mly=0;
+  int onp=0;
+  cpl_image* i_img=NULL;
+  cpl_image* o_img=NULL;
+  int min_lx = VERY_BIG_INT;
+  int min_ly = VERY_BIG_INT;
+
+
+  if(sinfo_check_input(cubes,n_cubes,cumoffsetx,cumoffsety,exptimes) == -1) {
+    return -1;
+  }
+
+  if (z_siz <= 0 ){
+    sinfo_msg_error ("z_max <= z_min given!") ;
+    return -1 ;
+  }
+
+  i_img=cpl_imagelist_get(cubes[0],0);
+  o_img=cpl_imagelist_get(mergedCube,0);
+  ilx=cpl_image_get_size_x(i_img);
+  ily=cpl_image_get_size_y(i_img);
+  olx=cpl_image_get_size_x(o_img);
+  oly=cpl_image_get_size_y(o_img);
+  mlx=olx;
+  mly=oly;
+//  sinfo_msg_warning(" cube size [%d:%d] merged cube size[%d:%d]" , ilx, ily, olx, oly);
+  /*--------------------------------------------------------------------
+   * center the cubes within the allocated big cube
+   * that means define the (0,0) positions of the cubes in the image planes
+   * to sub-pixel accuracy by using cumoffsetx,y and the reference cube
+   */
+  /* position of first reference frame, centered in big cube */
+  llx0 = (1.0 * olx- 1.0 * ilx)/2.0 ;
+  lly0 = (1.0 * oly - 1.0 * ily)/2.0 ;
+//  sinfo_msg_warning(" zero point [%d:%d]" , llx0, lly0);
+  /*--------------------------------------------------------------------
+   * go through the frame list and determine the lower left edge position
+   * of the shifted cubes. Additionnally, the sub-pixel offsets are
+   * determined.
+   */
+
+  llx=cpl_calloc(n_cubes,sizeof(int));
+  lly=cpl_calloc(n_cubes,sizeof(int)) ;
+  sub_offsetx=cpl_calloc(n_cubes,sizeof(float)) ;
+  sub_offsety=cpl_calloc(n_cubes,sizeof(float)) ;
+
+  for ( i = 0 ; i < n_cubes ; i++ ) {
+    llx[i] = llx0 - sinfo_new_nint(cumoffsetx[i]) ;
+
+    sub_offsetx[i] = (float)sinfo_new_nint(cumoffsetx[i]) - cumoffsetx[i] ;
+    lly[i] = lly0 - sinfo_new_nint(cumoffsety[i]) ;
+    sub_offsety[i] = (float)sinfo_new_nint(cumoffsety[i]) - cumoffsety[i] ;
+/*    sinfo_msg_warning("suboff[%d]= %f %f  ll[%d:%d] cumoffset[%f:%f]" ,
+    		i,sub_offsetx[i],sub_offsety[i], llx[i], lly[i],
+    		cumoffsetx[i], cumoffsety[i]);*/
+    if (llx[i] < min_lx)
+    {
+    	min_lx = llx[i];
+    }
+    if (lly[i] < min_ly)
+    {
+    	min_ly = lly[i];
+    }
+  }
+  /***********---------
+   * "normalize" the shift - minimum should be 0
+   **********************************************/
+  if (min_lx != 0)
+  {
+  	for (i = 0 ; i < n_cubes ; i++ )
+  	{
+  		llx[i] = llx[i] - min_lx;
+  	}
+  }
+  if (min_ly != 0)
+  {
+  	for (i = 0 ; i < n_cubes ; i++ )
+  	{
+  		lly[i] = lly[i] - min_ly;
+  	}
+  }
+
+  /* -------------------------------------------------------------
+   * shift the cubes according to the computed sub-pixel offsets
+   * that means shift the single image planes of each cube
+   * first determine an interpolation kernel
+   */
+
+  tmpcubes=(cpl_imagelist**)cpl_calloc(n_cubes,sizeof(cpl_imagelist*)) ;
+
+  if(sinfo_shift_cubes(tmpcubes,kernel_type,n_cubes,cubes,z_min, z_max,
+		       sub_offsetx,sub_offsety,mlx,mly,mask) == -1) {
+    return -1;
+
+  }
+
+
+  /*-------------------------------------------------------------------------
+   * Build the mask data cube.
+   * The mask is 0 where no data is available, otherwise the integration
+   * time of one frame, respectively the summed integration
+   * times in the overlapping regions are inserted
+   */
+  /* go through the frame list */
+
+
+  o_img=cpl_imagelist_get(mergedCube,0);
+  olx=cpl_image_get_size_x(o_img);
+  oly=cpl_image_get_size_y(o_img);
+  onp=cpl_imagelist_get_size(mergedCube);
+
+  if(-1 == sinfo_build_mask_cube_thomas(z_min,z_max,olx,oly,n_cubes,llx,lly,
+					exptimes,cubes,tmpcubes,mask) ) {
+    return -1;
+  }
+/////////////////////////////////// use an optimized version ///////////////
+/*
+  check_nomsg(sinfo_coadd_with_ks_clip_optimized(z_min,z_max,n_cubes,
+                                           kappa,llx,lly,
+                                           exptimes,mask,mergedCube,tmpcubes));
+*/
+////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////// not_optimized version ///////////////
+  check_nomsg(sinfo_coadd_with_ks_clip2(z_min,z_max,ilx,ily,n_cubes,kappa,llx,lly,
+                                        exptimes,mask,mergedCube,tmpcubes));
+
+////////////////////////////////////////////////////////////////////////////
+  /* convert the "free space" in the cube to blank pixels */
+  /* convert_0_to_ZERO_for_cubes(mergedCube) ; */
+  /* convert_0_to_ZERO_for_cubes(mergedSky) ; */
+  //cpl_free(kernel) ; /* originated by eclise-malloc */
+
+  cleanup:
+
+  for( i = 0 ; i < n_cubes ; i++ ) {
+    cpl_imagelist_delete (tmpcubes[i]) ;
+  }
+
+  cpl_free(tmpcubes);
+  cpl_free(llx);
+  cpl_free(lly) ;
+  cpl_free(sub_offsetx) ;
+  cpl_free(sub_offsety) ;
+  sinfo_print_rec_status(0);
+
+  return 0 ;
+}
+
+/**
+   @name sinfo_new_interpol_cube_simple()
+   @param cube: 1 allocated cube
+   @param badcube: bad pixel mask cube (0: bad, 1: good pixel)
+   @param maxdist: maximal pixel distance from bad pixel
+                   to search for good pixels, don't make this
+                   value too big!
+   @return interpolated cube, and corrected bad pixel mask cube
+   @doc interpolates bad pixel of an object cube if a bad pixel
+        mask cube is available by using the nearest neighbors
+        in 3 dimensions.
+ */
+
+cpl_imagelist *
+sinfo_new_interpol_cube_simple( cpl_imagelist * cube,
+                      cpl_imagelist * badcube,
+                      int       maxdist )
+{
+  cpl_imagelist * intercube ;
+  float*     goodNeighbors=NULL ;
+  int z, row, col ;
+  int nx, ny, nz ;
+  int llx, lly, llz ;
+  int zi, coli, rowi ;
+  int n ;
+
+
+
+
+  int clx=0;
+  int cly=0;
+  int blx=0;
+  int bly=0;
+
+  int cnp=0;
+
+
+  float* pbdata=NULL;
+  float* pidata=NULL;
+  float* pbzidata=NULL;
+  float* pczidata=NULL;
+
+  cpl_image* c_img=NULL;
+  cpl_image* b_img=NULL;
+  cpl_image* i_img=NULL;
+
+  cpl_image* bzi_img=NULL;
+  cpl_image* czi_img=NULL;
+
+
+
+    if ( cube == NULL || badcube == NULL )
+    {
+        sinfo_msg_error("no cube given!") ;
+        return NULL ;
+    }
+    if ( maxdist < 1 )
+    {
+        sinfo_msg_error("wrong maxrad given!") ;
+        return NULL ;
+    }
+    intercube = cpl_imagelist_duplicate(cube) ;
+
+    goodNeighbors=cpl_calloc((2*maxdist+1)*(2*maxdist+1)*(2*maxdist+1) -1,
+                             sizeof(float)) ;
+
+    cnp=cpl_imagelist_get_size(cube);
+    for ( z = 0 ; z < cnp ; z++ )
+    {
+      b_img=cpl_imagelist_get(badcube,z);
+      i_img=cpl_imagelist_get(intercube,z);
+      pbdata=cpl_image_get_data_float(b_img);
+      pidata=cpl_image_get_data_float(i_img);
+      blx=cpl_image_get_size_x(b_img);
+      bly=cpl_image_get_size_y(b_img);
+
+      c_img=cpl_imagelist_get(cube,z);
+      clx=cpl_image_get_size_x(c_img);
+      cly=cpl_image_get_size_y(c_img);
+
+        for ( row = 0 ; row < cly ; row++ )
+        {
+            for ( col = 0 ; col < clx ; col++ )
+            {
+                if ( pbdata[col+row*clx] == 0 )
+                {
+                    /* determine the lower left sinfo_edge of the cube */
+                    llx = col - maxdist ;
+                    nx = 2*maxdist +1 ;
+                    if (llx < 0)
+                    {
+                       nx += llx ;
+                       llx = 0 ;
+                    }
+                    if ( llx + nx > clx )
+                    {
+                        nx -= (llx + nx - clx) ;
+                    }
+
+                    lly = row - maxdist ;
+                    ny = 2*maxdist +1 ;
+                    if (lly < 0)
+                    {
+                       ny += lly ;
+                       lly = 0 ;
+                    }
+                    if ( lly + ny > cly )
+                    {
+                        ny -= (lly + ny - cly) ;
+                    }
+
+                    llz = z - maxdist ;
+                    nz = 2*maxdist +1 ;
+                    if (llz < 0)
+                    {
+                       nz += llz ;
+                       llz = 0 ;
+                    }
+                    if ( llz + nz > cnp )
+                    {
+                        nz -= (llz + nz - cnp) ;
+                    }
+                    n = 0 ;
+                    for ( zi = llz ; zi < llz+nz ; zi++ )
+                    {
+              bzi_img=cpl_imagelist_get(badcube,zi);
+              czi_img=cpl_imagelist_get(cube,zi);
+                      pbzidata=cpl_image_get_data_float(bzi_img);
+                      pczidata=cpl_image_get_data_float(czi_img);
+
+                        for ( rowi = lly ; rowi < lly+ny ; rowi++ )
+                        {
+                            for ( coli = llx ; coli < llx+nx ; coli++ )
+                            {
+                                if ( pbzidata[coli+rowi*blx] == 1 )
+                                {
+                  goodNeighbors[n] = pczidata[coli+rowi*clx] ;
+                  n++ ;
+                                }
+                            }
+                        }
+                    }
+                    if ( n > 0 )
+                    {
+                        pidata[col+row*clx]=sinfo_new_median(goodNeighbors,n);
+                        pbdata[col+row*clx]=1 ;
+                    }
+                    else
+                    {
+                        continue ;
+                    }
+                }
+            }
+        }
+    }
+    cpl_free(goodNeighbors) ;
+    return intercube ;
+}
+
+
+
+
+
+/**
+
+   @name   sinfo_new_combine_cubes()
+   @param  cubes: list of jittered cubes to mosaic
+   @param  mergedCube: resulting merged cube containing the
+                                      jittered cubes
+   @param  mask: cube of the same size as combinedCube
+                 containing 0 for blank (ZERO pixels) and
+                 the summed integration times for
+                 overlapping regions
+
+   @param n_cubes: number of cubes in the list to merge
+   @param cumoffsetx: array of relative x pixel offsets
+                      with respect to the first frame in the
+                      same sequence as the cube list.
+
+   @param cumoffsety: array of relative y pixel offsets
+                      with respect to the first frame in the
+                      same sequence as the cube list.
+
+
+   @factor: sigma factor beyond which pixels are thrown away.
+   @param kernel_type: the name of the interpolation kernel
+                       that you want to generate using the
+                       eclipse routine
+                       sinfo_generate_interpolation_kernel()
+                       Supported kernels are:
+                       NULL:      default kernel, currently tanh
+                                     "default": dito
+                                     "tanh":    Hyperbolic tangent
+                                     "sinc2":   Square sinc
+                                     "lanczos": Lanczos2 kernel
+                                     "hamming": Hamming kernel
+                                     "hann":    Hann kernel
+
+   @return mask: cube of the same size as combinedCube
+                containing 0 for blank (ZERO pixels) and
+                n used pixels for overlapping regions
+          mergedCube: final data cube containing the jittered cubes
+
+
+   @doc          merges jittered data cubes to one bigger cube
+                 by taking the sinfo_new_median in each pixel and throw
+                 away the high deviation pixels (bigger than factor * sigma)
+                 The x, y size of the final data
+                 cube is user given, and should be between 32 and 64
+                 pixels, while the relative pixel-offset (sub-pixel
+                 accuracy) of the single cubes with respect to the
+                 first cube in the list is read from the SEQ CUMOFFSETX,Y
+                 fits header keyword.
+*/
+
+cpl_imagelist *
+sinfo_new_combine_cubes ( cpl_imagelist ** cubes,
+                         cpl_imagelist  * mergedCube,
+                         int        n_cubes,
+                         float    * cumoffsetx,
+                         float    * cumoffsety,
+                         float      factor,
+                         char     * kernel_type )
+{
+  int i=0 ;
+  int x=0;
+  int y=0;
+  int z=0;
+  int llx0=0;
+  int lly0=0;
+  int posx=0;
+  int posy=0;
+  cpl_imagelist * mask=NULL ;
+  double * kernel=NULL ;
+  cpl_image * shiftedImage=NULL ;
+  int n=0;
+  int ns=0;
+  double sum=0;
+  double sum2=0;
+  double mean=0;
+  double sigma=0;
+
+  cpl_imagelist ** tmpcubes=NULL ;
+
+  int* llx=NULL ;
+  int* lly=NULL ;
+
+  float* sub_offsetx=NULL ;
+  float* sub_offsety=NULL ;
+  float* cubedata=NULL ;
+
+  int mlx=0;
+  int mly=0;
+  int clx=0;
+  int cly=0;
+  int mnp=0;
+  int cnp=0;
+
+
+  float* ptdata=NULL;
+  float* podata=NULL;
+  float* pmdata=NULL;
+
+  cpl_image* tmp_img=NULL;
+  cpl_image* o_img=NULL;
+  cpl_image* m_img=NULL;
+  cpl_image* c_img=NULL;
+  cpl_image* t_img=NULL;
+
+
+
+
+  if ( cubes == NULL )
+    {
+        sinfo_msg_error ("no cube list given!") ;
+        return NULL ;
+    }
+
+
+  if ( mergedCube == NULL )
+    {
+        sinfo_msg_error ("no out cube  given!") ;
+        return NULL ;
+    }
+
+
+    if ( n_cubes <= 0 )
+    {
+        sinfo_msg_error ("wrong number of data cubes in list!") ;
+        return NULL ;
+    }
+    if ( cumoffsetx == NULL || cumoffsety == NULL )
+    {
+        sinfo_msg_error ("no cumoffsetx/y given!") ;
+        return NULL;
+    }
+
+  if ( factor <= 0. )
+    {
+        sinfo_msg_error ("wrong factor given!") ;
+        return NULL ;
+    }
+
+  m_img=cpl_imagelist_get(mergedCube,0);
+  mlx=cpl_image_get_size_x(m_img);
+  mly=cpl_image_get_size_y(m_img);
+  cnp=cpl_imagelist_get_size(cubes[0]);
+  c_img=cpl_imagelist_get(cubes[0],0);
+  clx=cpl_image_get_size_x(c_img);
+  cly=cpl_image_get_size_y(c_img);
+
+
+  tmpcubes=(cpl_imagelist**)cpl_calloc(n_cubes,sizeof(cpl_imagelist*)) ;
+
+        /* allocation for a cube structure without the image planes  */
+    /*
+   for ( i = 0 ; i < n_cubes ; i++ )
+    {
+         tmpcubes[i] = (cpl_imagelist*)cpl_malloc(sizeof(cpl_imagelist)) ;
+        tmpcubes[i]->plane = (cpl_image**)cpl_calloc(cubes[0]->np ,
+                              sizeof(cpl_image*)) ;
+
+        tmpcubes[i]->lx = cubes[0]->lx ;
+        tmpcubes[i]->ly = cubes[0]->ly ;
+        tmpcubes[i]->np = cubes[0]->np ;
+        tmpcubes[i]->nbpix = (ulong32)cubes[0]->lx *
+                             (ulong32)cubes[0]->ly *
+                             (ulong32)cubes[0]->np ;
+        tmpcubes[i]->history = (char*)NULL ;
+        tmpcubes[i]->n_comments = 0 ;
+        tmpcubes[i]->orig_ptype = BPP_DEFAULT ;
+        tmpcubes[i]->filename = NULL ;
+    }
+    */
+    tmpcubes[0]=cpl_imagelist_duplicate(cubes[0]);
+
+    /*--------------------------------------------------------------------
+     * center the cubes within the allocated big cube
+     * that means define the (0,0) positions of the cubes in the image planes
+     * to sub-pixel accuracy by using cumoffsetx,y and the reference cube
+     */
+    /* position of first reference frame, centered in big cube */
+    llx0 = mlx/2 - clx/2 ;
+    lly0 = mly/2 - cly/2 ;
+
+    /*--------------------------------------------------------------------
+     * go through the frame list and determine the lower left edge position
+     * of the shifted cubes. Additionnally, the sub-pixel offsets are
+     * determined.
+     */
+
+
+    llx=cpl_calloc(n_cubes,sizeof(int)) ;
+    lly=cpl_calloc(n_cubes,sizeof(int)) ;
+    sub_offsetx=cpl_calloc(n_cubes,sizeof(float)) ;
+    sub_offsety=cpl_calloc(n_cubes,sizeof(float)) ;
+
+    for ( i = 0 ; i < n_cubes ; i++ )
+    {
+        llx[i] = llx0 - sinfo_new_nint(cumoffsetx[i]) ;
+        sub_offsetx[i] = (float)sinfo_new_nint(cumoffsetx[i]) - cumoffsetx[i] ;
+        lly[i] = lly0 - sinfo_new_nint(cumoffsety[i]) ;
+        sub_offsety[i] = (float)sinfo_new_nint(cumoffsety[i]) - cumoffsety[i] ;
+    }
+
+    /* -------------------------------------------------------------
+     * shift the cubes according to the computed sub-pixel offsets
+     * that means shift the single image planes of each cube
+     * first determine an interpolation kernel
+     */
+    if ( NULL == (kernel = sinfo_generate_interpolation_kernel(kernel_type)) )
+    {
+        sinfo_msg_warning ("could not generate desired interpolation kernel"
+                           " or no kernel_typ was given, the default kernel"
+                           " is used now!") ;
+    }
+    /* go through the frame list */
+    for ( i = 0 ; i < n_cubes ; i++ )
+    {
+      /* go through the image planes and shift each plane by a
+         sub-pixel value */
+      for ( z = 0 ; z < cnp ; z++ )
+        {
+      tmp_img=cpl_imagelist_get(cubes[i],z);
+      if ( NULL == (shiftedImage = sinfo_new_shift_image(tmp_img,
+                               sub_offsetx[i],
+                               sub_offsety[i],
+                               kernel ) ) )
+            {
+          sinfo_msg_error ("could not shift image plane no %d "
+                               "in cube no %d!", z, i) ;
+          cpl_imagelist_delete(mergedCube) ;
+          cpl_imagelist_delete(mask) ;
+          cpl_free(kernel) ;
+          return NULL ;
+            }
+      cpl_imagelist_set(tmpcubes[i],shiftedImage,z);
+        }
+    }
+
+    cubedata=cpl_calloc(n_cubes,sizeof(float)) ;
+
+    for ( y = 0 ; y < mly ; y++ )
+    {
+        for ( x = 0 ; x < mlx ; x++ )
+        {
+            for ( z = 0 ; z < mnp ; z++ )
+            {
+                sum = 0. ;
+                sum2 = 0. ;
+                n = 0 ;
+                for ( i = 0 ; i < n_cubes ; i++ )
+                {
+          c_img=cpl_imagelist_get(cubes[i],z);
+
+          clx=cpl_image_get_size_x(c_img);
+          cly=cpl_image_get_size_y(c_img);
+
+          t_img=cpl_imagelist_get(tmpcubes[i],z);
+                  ptdata=cpl_image_get_data_float(t_img);
+
+          m_img=cpl_imagelist_get(mergedCube,z);
+                  pmdata=cpl_image_get_data_float(m_img);
+          o_img=cpl_imagelist_get(mask,z);
+                  podata=cpl_image_get_data_float(o_img);
+                  /*
+                    find the position of the present cube and go
+                    through the single spectra
+                   */
+                    if ( y >= lly[i] && y < lly[i]+cly &&
+                         x >= llx[i] && x < llx[i]+clx )
+                    {
+                        posx = x - llx[i] ;
+                        posy = y - lly[i] ;
+                        if (!isnan(ptdata[posx+posy*clx]))
+                        {
+                            sum += ptdata[posx+posy*clx] ;
+                            sum2 += (ptdata[posx+posy*clx] *
+                                     ptdata[posx+posy*clx]) ;
+                            cubedata[n] = ptdata[posx+posy*clx] ;
+                            n++ ;
+                        }
+                    }
+                }
+
+                if ( n == 0 )
+                {
+                    mean = 0. ;
+                    sigma = 0. ;
+                    pmdata[x+y*mlx] = 0. ;
+                    podata[x+y*mlx] = 0 ;
+                }
+                else if ( n == 1 )
+                {
+                    mean = sum ;
+                    sigma = 0. ;
+                    pmdata[x+y*mlx] = mean ;
+                    podata[x+y*mlx] = 1 ;
+                }
+                else
+                {
+                    mean = sum/(double)n ;
+                    sigma = sqrt( (sum2 - sum*mean) / (double)(n - 1) ) ;
+                    ns = 0 ;
+                    for ( i = 0 ; i < n ; i++ )
+                    {
+                        if ( cubedata[i] > mean+factor*sigma ||
+                             cubedata[i] < mean-factor*sigma )
+                        {
+                            continue ;
+                        }
+                        else
+                        {
+                            pmdata[x+y*mlx] += cubedata[i] ;
+                            ns++ ;
+                        }
+                    }
+                    if ( ns == 0 )
+                    {
+                        pmdata[x+y*mlx] = 0. ;
+                    }
+                    else
+                    {
+                        pmdata[x+y*mlx] /= (float)ns ;
+                    }
+                    podata[x+y*mlx] = (float)ns ;
+                }
+            }
+        }
+    }
+
+    for( i = 0 ; i < n_cubes ; i++ )
+    {
+        cpl_imagelist_delete (tmpcubes[i]) ;
+    }
+    cpl_free(tmpcubes);
+    cpl_free(llx);
+    cpl_free(lly);
+    cpl_free(sub_offsetx);
+    cpl_free(sub_offsety);
+    cpl_free(cubedata);
+
+    /* convert the "free space" in the cube to blank pixels */
+    sinfo_new_convert_0_to_ZERO_for_cubes(mergedCube) ;
+    cpl_free(kernel) ;
+    return mask ;
+}
+
+cpl_imagelist *
+sinfo_new_bin_cube(cpl_imagelist *cu,
+                             int xscale,
+                             int yscale,
+                             int xmin,
+                             int xmax,
+                             int ymin,
+                             int ymax)
+{
+  int i,j,k;
+  cpl_imagelist * cube;
+  int ilx=0;
+  int ily=0;
+  int olx=0;
+  int oly=0;
+  int inp=0;
+
+  float* pidata=NULL;
+  float* podata=NULL;
+  cpl_image* i_img=NULL;
+  cpl_image* o_img=NULL;
+
+
+  /* old code
+  if (NULL == (cube = sinfo_newCube (xmax-xmin+1,ymax-ymin+1, cu->np)) )
+  {
+      sinfo_msg_error ("cannot allocate new cube") ;
+      return NULL ;
+  }
+  */
+  inp=cpl_imagelist_get_size(cu);
+  i_img=cpl_imagelist_get(cu,0);
+  ilx=cpl_image_get_size_x(i_img);
+  ily=cpl_image_get_size_y(i_img);
+  olx=xmax-xmin+1;
+  oly=ymax-ymin+1;
+
+
+  cube=cpl_imagelist_new();
+  for ( i = 0 ; i < inp ; i++ ) {
+    o_img = cpl_image_new(olx,oly,CPL_TYPE_FLOAT);
+    cpl_imagelist_set(cube,o_img,i);
+  }
+
+
+  for (i=0;i<inp;i++){
+      i_img=cpl_imagelist_get(cu,i);
+      pidata=cpl_image_get_data_float(i_img);
+      o_img=cpl_imagelist_get(cube,i);
+      podata=cpl_image_get_data_float(o_img);
+      for (j=0 ; j < olx ; j++) {
+          for (k=0 ; k< oly ; k++) {
+          podata[j+k*olx]=pidata[((int) (j+xmin)/xscale)+
+                                     ((int) (k+ymin)/yscale)*ilx]/
+                                       (xscale*yscale);
+      }
+      }
+  }
+
+  return cube;
+}
+
+
+cpl_imagelist *
+sinfo_new_scale_cube(cpl_imagelist *cu,
+                               float xscale,
+                               float yscale,
+                               char * kernel_type)
+{
+    cpl_imagelist    *    cube ;
+    int             i, j, k, l ;
+    int             lx_out, ly_out ;
+    double           cur ;
+    double      *    invert_transform ;
+    double           neighbors[16] ;
+    double           rsc[8],
+                    sumrs ;
+    double        param[6];
+    double           x, y ;
+    int             px, py ;
+    int             pos ;
+    int             tabx, taby ;
+    double      *    kernel ;
+    int                  leaps[16] ;
+    int                 ilx=0;
+    int                 ily=0;
+    int                 tlx=0;
+    int                 tly=0;
+    int                 inp;
+    float*              podata=0;
+    cpl_image*          in_img=NULL;
+    cpl_image*          ou_img=NULL;
+
+
+    if (cu == NULL)
+    {
+        sinfo_msg_error ("null cube") ;
+        return NULL ;
+    }
+
+    param[0]=xscale;
+    param[1]=0;
+    param[2]=0;
+    param[3]=0;
+    param[4]=yscale;
+    param[5]=0;
+
+
+    invert_transform = sinfo_invert_linear_transform(param) ;
+    if (invert_transform == NULL) {
+        sinfo_msg_error("cannot compute sinfo_invert transform: "
+                        "aborting warping") ;
+        return NULL ;
+    }
+
+    /* Generate default interpolation kernel */
+    kernel = sinfo_generate_interpolation_kernel(kernel_type) ;
+    if (kernel == NULL) {
+        sinfo_msg_error("cannot generate kernel: aborting resampling") ;
+        return NULL ;
+    }
+
+    /* Compute new image size   */
+    /* Compute new image size   */
+    ilx=cpl_image_get_size_x(cpl_imagelist_get(cu,0));
+    ily=cpl_image_get_size_y(cpl_imagelist_get(cu,0));
+    inp=cpl_imagelist_get_size(cu);
+
+    lx_out = (int) ilx*xscale ;
+    ly_out = (int) ily*yscale ;
+
+    cube=cpl_imagelist_new();
+    for ( l = 0 ; l < inp ; i++ ) {
+     in_img = cpl_image_new(ilx,ily,CPL_TYPE_FLOAT);
+     cpl_imagelist_set(cube,in_img,l);
+    }
+
+    /* old code
+    if (NULL == (cube = sinfo_newCube (lx_out, ly_out, cu->np)) )
+    {
+        sinfo_msg_error (" cannot allocate new cube") ;
+        return NULL ;
+    }
+    */
+
+    for (l=0;l<inp;l++){
+      in_img=cpl_imagelist_get(cu,l);
+      ou_img=cpl_imagelist_get(cube,l);
+      tlx=cpl_image_get_size_x(in_img);
+      tly=cpl_image_get_size_y(in_img);
+      podata=cpl_image_get_data_float(ou_img);
+        /* Pre compute leaps for 16 closest neighbors positions */
+        leaps[0] = -1 - tlx ;
+        leaps[1] =    - tlx ;
+        leaps[2] =  1 - tlx ;
+        leaps[3] =  2 - tlx ;
+
+        leaps[4] = -1 ;
+        leaps[5] =  0 ;
+        leaps[6] =  1 ;
+        leaps[7] =  2 ;
+
+        leaps[8] = -1 + tlx ;
+        leaps[9] =      tlx ;
+        leaps[10]=  1 + tlx ;
+        leaps[11]=  2 + tlx ;
+
+        leaps[12]= -1 + 2*tlx ;
+        leaps[13]=      2*tlx ;
+        leaps[14]=  1 + 2*tlx ;
+        leaps[15]=  2 + 2*tlx ;
+
+        /* Double loop on the output image  */
+        for (j=0 ; j < ly_out ; j++) {
+            for (i=0 ; i< lx_out ; i++) {
+                /* Compute the original source for this pixel   */
+
+                x = invert_transform[0] * (double)i +
+                    invert_transform[1] * (double)j +
+                invert_transform[2] ;
+
+                y = invert_transform[3] * (double)i +
+                invert_transform[4] * (double)j +
+                invert_transform[5] ;
+
+            /* Which is the closest integer positioned neighbor?    */
+                px = (int)x ;
+        py = (int)y ;
+
+                if ((px < 1) ||
+                    (px > (tlx-2)) ||
+                    (py < 1) ||
+                    (py > (tly-2)))
+                    podata[i+j*lx_out] = (pixelvalue)0.0 ;
+                else {
+                    /* Now feed the positions for the closest 16 neighbors  */
+                    pos = px + py * tlx ;
+                    for (k=0 ; k<16 ; k++){
+                        if(!isnan(podata[(int)(pos+leaps[k])])) neighbors[k] =
+                         (double)(podata[(int)(pos+leaps[k])]) ;
+                else neighbors[k]=0;
+            }
+
+                    /* Which tabulated value index shall we use?    */
+                    tabx = (x - (double)px) * (double)(TABSPERPIX) ;
+                    taby = (y - (double)py) * (double)(TABSPERPIX) ;
+
+                    /* Compute resampling coefficients  */
+                    /* rsc[0..3] in x, rsc[4..7] in y   */
+
+                    rsc[0] = kernel[TABSPERPIX + tabx] ;
+                    rsc[1] = kernel[tabx] ;
+                    rsc[2] = kernel[TABSPERPIX - tabx] ;
+                    rsc[3] = kernel[2 * TABSPERPIX - tabx] ;
+                    rsc[4] = kernel[TABSPERPIX + taby] ;
+                    rsc[5] = kernel[taby] ;
+                    rsc[6] = kernel[TABSPERPIX - taby] ;
+                    rsc[7] = kernel[2 * TABSPERPIX - taby] ;
+
+                    sumrs = (rsc[0]+rsc[1]+rsc[2]+rsc[3]) *
+                        (rsc[4]+rsc[5]+rsc[6]+rsc[7]) ;
+
+                    /* Compute interpolated pixel now   */
+                    cur =   rsc[4] * (  rsc[0]*neighbors[0] +
+                                    rsc[1]*neighbors[1] +
+                                    rsc[2]*neighbors[2] +
+                                    rsc[3]*neighbors[3] ) +
+                        rsc[5] * (  rsc[0]*neighbors[4] +
+                                    rsc[1]*neighbors[5] +
+                                    rsc[2]*neighbors[6] +
+                                    rsc[3]*neighbors[7] ) +
+                        rsc[6] * (  rsc[0]*neighbors[8] +
+                                    rsc[1]*neighbors[9] +
+                                    rsc[2]*neighbors[10] +
+                                    rsc[3]*neighbors[11] ) +
+                        rsc[7] * (  rsc[0]*neighbors[12] +
+                                    rsc[1]*neighbors[13] +
+                                    rsc[2]*neighbors[14] +
+                                    rsc[3]*neighbors[15] ) ;
+
+                    /* Affect the value to the output image */
+                    podata[i+j*lx_out] = (pixelvalue)(cur/sumrs) ;
+                    /* done ! */
+                }
+            }
+        }
+    }
+    cpl_free(kernel) ;
+    cpl_free(invert_transform) ;
+    return cube ;
+}
+
+
+/**
+ @short shifts an imagelist by a given amount to integer pixel accuracy
+ @name sinfo_cube_zshift
+ @param cube  input cube to be shifted
+ @param shift amount of z shift to be applied
+ @param rest  amout of fractional shift remaining (<1)
+
+*/
+
+cpl_imagelist *
+sinfo_cube_zshift(const cpl_imagelist * cube_inp,
+                  const double shift,
+                  double* sub_shift)
+{
+
+    cpl_imagelist * cube_out=NULL ;
+    const cpl_image* img_inp=NULL;
+    cpl_image* img_out=NULL;
+    int        col, row,z ;
+    int        int_shift ;
+    int ilx=0;
+    int ily=0;
+    int ilz=0;
+
+    int olx=0;
+    int oly=0;
+    int olz=0;
+    int i=0;
+    const float* pidata=NULL;
+    float* podata=NULL;
+
+    cknull(cube_inp,"no input cube given!") ;
+    check_nomsg(img_inp=cpl_imagelist_get_const(cube_inp,0));
+    check_nomsg(ilx=cpl_image_get_size_x(img_inp));
+    check_nomsg(ily=cpl_image_get_size_y(img_inp));
+    check_nomsg(ilz=cpl_imagelist_get_size(cube_inp));
+
+    olx=ilx;
+    oly=ily;
+    olz=ilz;
+
+    int_shift = sinfo_new_nint(shift) ;
+    *sub_shift = shift - (double) int_shift ;
+    if ( int_shift == 0 )
+    {
+        cube_out =cpl_imagelist_duplicate(cube_inp) ;
+        return cube_out ;
+    }
+    else
+    {
+      /* allocate memory */
+      cknull(cube_out = cpl_imagelist_new(),"could not allocate memory!") ;
+      for ( i = 0 ; i < olz ; i++ ) {
+        check_nomsg(img_out=cpl_image_new(olx,oly,CPL_TYPE_FLOAT));
+        check_nomsg(cpl_imagelist_set(cube_out,img_out,i));
+     }
+    }
+
+    for(z=0; z< ilz; z++) {
+      if ( (z-int_shift >= 0 ) && (z - int_shift < olz) ) {
+        check_nomsg(img_inp=cpl_imagelist_get_const(cube_inp,z));
+        check_nomsg(img_out=cpl_imagelist_get(cube_out,z-int_shift));
+	check_nomsg(pidata=cpl_image_get_data_float_const(img_inp));
+	check_nomsg(podata=cpl_image_get_data_float(img_out));
+    for ( col = 0 ; col < ilx ; col++ ) {
+      for ( row = 0 ; row < ily ; row++ ) {
+        podata[col+row*olx] = pidata[col+row*olx] ;
+      }
+    }
+      }
+    }
+    return cube_out ;
+
+ cleanup:
+    sinfo_free_imagelist(&cube_out);
+    return NULL ;
+}
+
+/**
+ @short shifts an imagelist by a given amount to sub-pixel accuracy
+ @name sinfo_cube_zshift
+ @param cube  input cube to be shifted
+ @param shift amount of z shift to be applied
+ @param order polynomial order
+
+*/
+
+cpl_imagelist *
+sinfo_cube_zshift_poly(const cpl_imagelist * cube_inp,
+                       const double sub_shift,
+                       const int    order)
+{
+  cpl_imagelist * cube_out ;
+
+  float* spec=NULL ;
+  float* corrected_spec=NULL ;
+  float* xnum=NULL ;
+
+  float sum=0;
+  float new_sum=0 ;
+  float eval=0 ;
+  float * imageptr=NULL ;
+  int row=0;
+  int col=0 ;
+  int firstpos=0 ;
+  int n_points=0 ;
+  int i=0 ;
+  int flag=0;
+  int ilx=0;
+  int ily=0;
+  int ilz=0;
+
+  int olx=0;
+  int oly=0;
+  int olz=0;
+  int z=0;
+
+  const float* pidata=NULL;
+  float* podata=NULL;
+  const cpl_image* img_inp=NULL;
+  cpl_image* img_out=NULL;
+
+  if ( cube_inp == NULL ) {
+    sinfo_msg_error("no imagelist given!") ;
+    return NULL ;
+  }
+
+  img_inp=cpl_imagelist_get_const(cube_inp,0);
+
+  ilx=cpl_image_get_size_x(img_inp);
+  ily=cpl_image_get_size_y(img_inp);
+  ilz=cpl_imagelist_get_size(cube_inp);
+
+  if ( order <= 0 ) {
+    sinfo_msg_error("wrong order of interpolation polynom given!") ;
+    return NULL ;
+  }
+
+
+  olx=ilx;
+  oly=ily;
+  olz=ilz;
+  /* allocate memory */
+
+  if ( NULL == (cube_out = cpl_imagelist_new()) ) {
+    sinfo_msg_error ("could not allocate memory!") ;
+    return NULL ;
+  } else {
+    for ( i = 0 ; i < ilz ; i++ ) {
+      img_out=cpl_image_new(olx,oly,CPL_TYPE_FLOAT);
+      cpl_imagelist_set(cube_out,img_out,i);
+    }
+  }
+
+
+  n_points = order + 1 ;
+  if ( n_points % 2 == 0 ) {
+    firstpos = (int)(n_points/2) - 1 ;
+  } else {
+    firstpos = (int)(n_points/2) ;
+  }
+
+  spec=cpl_calloc(ilz,sizeof(float)) ;
+  corrected_spec=cpl_calloc(ilz,sizeof(float)) ;
+  xnum=cpl_calloc(order+1,sizeof(float)) ;
+
+
+  /* fill the xa[] array for the polint function */
+  for ( i = 0 ; i < n_points ; i++ ) {
+    xnum[i] = i ;
+  }
+
+  for ( col = 0 ; col < ilx ; col++ ) {
+    for ( row = 0 ; row < ily ; row++ ) {
+      for( z=0; z< ilz; z++) {
+        corrected_spec[z] = 0. ;
+      }
+      sum = 0. ;
+      for ( z = 0 ; z < ilz ; z++ ) {
+    img_inp=cpl_imagelist_get_const(cube_inp,z);
+        pidata=cpl_image_get_data_float_const(img_inp);
+    spec[z] = pidata[col + row*ilx] ;
+    if (isnan(spec[z]) ) {
+          spec[z] = 0. ;
+
+      for ( i = z - firstpos ; i < z-firstpos+n_points ; i++ ) {
+        if ( i < 0 ) continue ;
+            if ( i >= ilz) continue  ;
+            corrected_spec[i] = ZERO ;
+          }
+        }
+        if ( z != 0 && z != ilz - 1 ) {
+          sum += spec[z] ;
+        }
+
+      }
+
+      new_sum = 0. ;
+      for ( z = 0 ; z < ilz ; z++ ) {
+
+        /* ---------------------------------------------------------------
+         * now determine the arrays of size n_points with which the
+         * polynom is determined and determine the position eval
+         * where the polynom is evaluated in polynomial interpolation.
+         * Take care of the points near the row edges!
+         */
+        if (isnan(corrected_spec[z])) continue ;
+        if ( z - firstpos < 0 ) {
+          imageptr = &spec[0] ;
+          eval     = sub_shift + z ;
+        } else if ( z - firstpos + n_points >= ilz ) {
+          imageptr = &spec[ilz - n_points] ;
+          eval     = sub_shift + z + n_points - ilz ;
+        } else {
+      imageptr = &spec[z-firstpos] ;
+          eval     = sub_shift + firstpos ;
+        }
+
+        flag=0;
+        corrected_spec[z]=sinfo_new_nev_ille(xnum,imageptr,order,eval,&flag);
+        if ( z != 0 && z != ilz - 1 ) {
+          new_sum += corrected_spec[z] ;
+        }
+      }
+
+      /* fill the output spectrum */
+      for (z = 0 ; z < ilz ; z++ )
+      {
+        img_out=cpl_imagelist_get(cube_out,z);
+        podata=cpl_image_get_data_float(img_out);
+        if ( new_sum == 0. ) {
+          new_sum = 1. ;
+        }
+        if ( z == 0 ) {
+          podata[col+row*olx] = ZERO ;
+        } else if ( z == ilz - 1 ) {
+          podata[col+row*olx] = ZERO ;
+        } else if ( isnan(corrected_spec[z]) ) {
+          podata[col+row*olx] = ZERO ;
+        } else {
+          corrected_spec[z] *= sum / new_sum ;
+          podata[col+row*olx] = corrected_spec[z] ;
+    }
+      }
+
+    }
+  }
+
+  cpl_free(spec) ;
+  cpl_free(corrected_spec) ;
+  cpl_free(xnum) ;
+  return cube_out ;
+
+
+}
+
+/**
+ @short shifts an imagelist by a given amount to sub-pixel accuracy
+ @name sinfo_cube_zshift
+ @param cube  input cube to be shifted
+ @param shift amount of z shift to be applied
+
+*/
+
+cpl_imagelist *
+sinfo_cube_zshift_spline3(const cpl_imagelist * cube_inp,
+                          const double sub_shift)
+{
+
+  cpl_imagelist * cube_out=NULL ;
+  float* spec=NULL ;
+  float* corrected_spec=NULL ;
+  float* xnum=NULL ;
+  float* eval=NULL ;
+  float sum=0;
+  float new_sum=0 ;
+  int row=0;
+  int col=0;
+  int i=0;
+  int z=0;
+
+  int ilx=0;
+  int ily=0;
+  int ilz=0;
+  int olx=0;
+  int oly=0;
+  int olz=0;
+
+  const float* pidata=NULL;
+  float* podata=NULL;
+  const cpl_image* img_inp=NULL;
+  cpl_image* img_out=NULL;
+
+  if ( cube_inp == NULL ) {
+    sinfo_msg_error("no imagelist given!") ;
+    return NULL ;
+  }
+
+  img_inp=cpl_imagelist_get_const(cube_inp,0);
+  ilx=cpl_image_get_size_x(img_inp);
+  ily=cpl_image_get_size_y(img_inp);
+  ilz=cpl_imagelist_get_size(cube_inp);
+
+
+  olx=ilx;
+  oly=ily;
+  olz=ilz;
+  /* allocate memory */
+  if ( NULL == (cube_out = cpl_imagelist_new()) ) {
+    sinfo_msg_error ("could not allocate memory!") ;
+    return NULL ;
+  } else {
+    for ( i = 0 ; i < ilz ; i++ ) {
+      img_out=cpl_image_new(olx,oly,CPL_TYPE_FLOAT);
+      cpl_imagelist_set(cube_out,img_out,i);
+    }
+  }
+
+  xnum=cpl_calloc(ilz,sizeof(float)) ;
+  /* fill the xa[] array for the spline function */
+  for ( i = 0 ; i < ilz ; i++ ) {
+    xnum[i] = i ;
+  }
+
+  spec=cpl_calloc(ilz,sizeof(float)) ;
+  corrected_spec=cpl_calloc(ilz,sizeof(float)) ;
+  eval=cpl_calloc(ilz,sizeof(float)) ;
+
+  for ( col = 0 ; col < ilx ; col++ ) {
+    for ( row = 0 ; row < ily ; row++ ) {
+      sum = 0. ;
+      for ( z = 0 ; z < ilz ; z++ ) {
+    img_inp=cpl_imagelist_get_const(cube_inp,z);
+        pidata=cpl_image_get_data_float_const(img_inp);
+    spec[z] = pidata[col + row*ilx] ;
+    if (isnan(spec[z]) ) {
+      for ( i = z-1 ; i <= z+1 ; i++ ) {
+        if ( i < 0 ) continue ;
+        if ( i >= ilz) continue ;
+        corrected_spec[i] = ZERO ;
+      }
+      spec[z] = 0. ;
+    }
+    sum += spec[z] ;
+    eval[z] = (float)sub_shift+(float)z ;
+      }
+      /* now we do the spline interpolation*/
+      if ( -1 == sinfo_function1d_natural_spline( xnum, spec, ilz, eval,
+                                              corrected_spec, ilz ) )
+        {
+      sinfo_msg_error("error in spline interpolation!") ;
+      return NULL ;
+        }
+
+      new_sum = 0. ;
+      for ( z = 0 ; z < ilz ; z++ ) {
+    if ( isnan(corrected_spec[z]) ) {
+      continue ;
+    }
+    new_sum += corrected_spec[z] ;
+      }
+      /* fill output imagelist */
+      for ( z = 0 ; z < ilz ; z++ ) {
+        img_out=cpl_imagelist_get(cube_out,z);
+        podata=cpl_image_get_data_float(img_out);
+    if ( new_sum == 0. ) new_sum =1. ;
+    {
+      if ( isnan(corrected_spec[z]) ) {
+        podata[col+row*olx] = ZERO ;
+      } else {
+        corrected_spec[z] *= sum / new_sum ;
+        podata[col+row*olx] = corrected_spec[z] ;
+      }
+    }
+      }
+    }
+  }
+  cpl_free(xnum);
+  cpl_free(spec) ;
+  cpl_free(corrected_spec) ;
+  cpl_free(eval) ;
+
+  return cube_out ;
+}
+
+/////////////////////////////////////////// kappa-sigma optimized version //////////////////////////////
+/* The structure for stroing index data for kappa-sigma
+ *
+ * */
+struct _CubeData
+{
+	int iCubeNumber;
+	int iLocalX;
+	int iLocalY;
+};
+typedef struct _CubeData CubeData;
+
+struct _CubeDataVector
+{
+	int size;
+	CubeData** pdata;
+};
+typedef struct _CubeDataVector CubeDataVector;
+/**
+ @short implamentation of kappa-sigma clipping
+ @name sinfo_kappa_sigma_offset_with_mask
+ @param globalSizeX size of the result image by X axis
+ @param globalSizeY size of the result image by Y axis
+ @param z_min  plane number to start coaadition
+ @param z_max  the last plane number to be used for coaddition
+ @param nCubes number of cubes in the inputCubes array
+ @param inputCubes array of the input cubes, each cube is an cpl_imagelist
+ @param exptimes exposure times array, one element for each cube in inputCubes
+ @param imResult result cube
+ @param offsetX each element represents the offset of the corresponding cube by X axis
+ @param offsetY each element represents the offset of the corresponding cube by Y axis
+ @param skyMask output parameter shows "bad pixels", pixels which were not taken to calculation due kappa-sigma
+ @param kappa parameter for kappa-sigma algorithm
+
+*/
+static int sinfo_kappa_sigma_offset_with_mask(
+		int z_min,
+		int z_max,
+		int nCubes,
+		cpl_imagelist** inputCubes,
+		double* exptimes,
+		cpl_imagelist* imResult,
+		int* offsetX,
+		int* offsetY,
+		cpl_imagelist* sky_mask,
+		const double kappa
+		);
+void kappa_sigma_CubeDataVector(
+		int globalX,
+		int globalY,
+		CubeDataVector* pCubeDataVector,
+		cpl_imagelist* imlistResult,
+		cpl_imagelist** input_cubes,
+		cpl_imagelist* sky_mask,
+		int iPlanesNumber,
+		int z_min,
+		const double kappa,
+		double* exptimes
+		);
+
+double kappa_sigma_array_with_mask(cpl_array* parray, int szArray, const double kappa,cpl_image* imMask, double* exptimes, int x, int y, double mask_delta)
+{
+	double result = 0;
+	int nInvalidPoints = 0;
+	const double EPS = 1E-10;
+	//sinfo_msg("kappa_sigma_array_with_mask, x[%d] y[%d]"
+	double mask_adjustment = mask_delta;
+	do
+	{
+		double median = 0;
+		double sig = 0;
+		int z = 0;
+		nInvalidPoints = 0;
+
+		check_nomsg(median = cpl_array_get_median(parray));
+		check_nomsg(sig = cpl_array_get_stdev(parray));
+		for (z = 0; z < szArray; z++)
+		{
+			int isnull = 0;
+			double value = 0;
+			check_nomsg(value = cpl_array_get(parray, z, &isnull));
+			if(!isnull)
+			{
+				if (fabs(value - median) > (kappa * sig))
+				{
+
+   //                       sinfo_msg("entered");
+	//		  sinfo_msg("val=%g check=%g",
+	//			    fabs(value - median),(kappa * sig));
+//			  sinfo_msg("kappa=%f sig=%g median=%g value=%g",
+//				    kappa,sig,median,value);
+
+					//double msk_new_value = 0;
+					cpl_array_fill_window_invalid(parray, z, 1);
+					mask_adjustment += exptimes[z];
+					++nInvalidPoints;
+				}
+			}
+		}
+		/*if (nInvalidPoints)
+		{
+			sinfo_msg("nInvalidPoints %d[%d][%d] median[%f] sig[%f]", nInvalidPoints,x,y, median, sig );
+		}*/
+
+	}
+	while (nInvalidPoints);
+	if(imMask && fabs(mask_adjustment) > EPS)
+	{
+		// adjust mask image
+		int px_rejected = 0;
+		double msk_value = 0;
+		check_nomsg(msk_value = cpl_image_get(imMask, x, y, &px_rejected));
+		check_nomsg(cpl_image_set(imMask, x,y, msk_value - mask_adjustment));
+	}
+	// get a result value for the point
+	check_nomsg(result = cpl_array_get_mean(parray));
+	return result;
+	cleanup:
+	sinfo_msg("Error in kappa_sigma_array_with_mask");
+	return 0;
+}
+
+
+int sinfo_coadd_with_ks_clip_optimized(
+			const int z_min,
+			const int z_max,
+			const int n_cubes,
+			const double kappa,
+			int* llx,
+			int* lly,
+            double* exptimes,
+			cpl_imagelist* sky_mask,
+			cpl_imagelist* mergedCube,
+            cpl_imagelist** tmpcubes
+            )
+{
+  /*
+	sinfo_msg("sinfo_coadd_with_ks_clip_optimized() z_min[%d] z_max[%d] n_cubes[%d] kappa[%f] llx[%d] lly[%d] exptimes[%d] sky_mask[%d]",
+			z_min, z_max, ilx, ily, n_cubes, kappa,llx, lly,exptimes,sky_mask);
+  */
+   int result=0;
+   check_nomsg(result=sinfo_kappa_sigma_offset_with_mask(z_min, z_max, n_cubes, tmpcubes, exptimes, mergedCube, llx, lly, sky_mask, kappa));
+
+  cleanup:
+
+	return result;
+
+}
+
+static int sinfo_kappa_sigma_offset_with_mask(
+		int z_min,
+		int z_max,
+		int nCubes,
+		cpl_imagelist** inputCubes,
+		double* exptimes,
+		cpl_imagelist* imResult,
+		int* global_offsetX,
+		int* global_offsetY,
+		cpl_imagelist* sky_mask,
+		const double kappa
+		)
+{
+	const int BIG_ENOUGH_INT = 65535;
+	CubeDataVector*** indexX = 0;
+	int x = 0;
+	int y = 0;
+	int z = 0;
+	int iPlanesNumber = z_max - z_min;
+	int nIndexXbytes = 0;
+	int globalSizeX = 0 ;
+	int globalSizeY = 0;
+
+	int xmax = -BIG_ENOUGH_INT;
+	int ymax = -BIG_ENOUGH_INT;
+	int xmin = BIG_ENOUGH_INT;
+	int ymin = BIG_ENOUGH_INT;
+	int* offsetX = 0; // local offset of the cubes, normalized
+	int* offsetY = 0;
+	//sinfo_msg(" starting kappa-sigma clipping for cubes[%d] planes[%d]", nCubes, z_max - z_min );
+	// determine size of the coadded cube
+        sinfo_check_rec_status(0);
+	for (z = 0; z < nCubes; z++)
+	{
+
+		cpl_imagelist* pCube = inputCubes[z];
+		cpl_image* pImage = 0;
+		int localMaxX = 0;
+		int localMaxY = 0;
+		int localMinX = 0;
+		int localMinY = 0;
+
+		pImage = cpl_imagelist_get(pCube, 0);
+
+		localMaxX = cpl_image_get_size_x(pImage) + global_offsetX[z];
+		localMaxY = cpl_image_get_size_y(pImage) + global_offsetY[z];
+		localMinX = global_offsetX[z];
+		localMinY = global_offsetY[z];
+
+		if(localMaxX > xmax) xmax = localMaxX;
+		if(localMaxY > ymax) ymax = localMaxY;
+
+		if(localMinX < xmin) xmin = localMinX;
+		if(localMinY < ymin) ymin = localMinY;
+	}
+        sinfo_check_rec_status(1);
+
+	// DFS09121 xmax and ymax could be more then output cube - check and adjust
+	{
+		int msize_x = 0;
+		int msize_y = 0;
+		//sinfo_msg("DFS09121 before:  xmax=%d ymax=%d", xmax, ymax);
+		cpl_image * pmaskimage = cpl_imagelist_get(sky_mask, 0);
+		msize_x = cpl_image_get_size_x(pmaskimage);
+		msize_y = cpl_image_get_size_y(pmaskimage);
+		xmax = msize_x < xmax ? msize_x : xmax;
+		ymax = msize_y < ymax ? msize_y : ymax;
+		//sinfo_msg("DFS09121 after:  xmax=%d ymax=%d", xmax, ymax);
+	}
+	// rely on the data received outside
+	globalSizeX = xmax;// - xmin;
+	globalSizeY = ymax;// - ymin;
+	// calculate local offset
+	check_nomsg(offsetX = cpl_malloc(sizeof(offsetX[0]) * nCubes));
+	check_nomsg(offsetY = cpl_malloc(sizeof(offsetY[0]) * nCubes));
+        sinfo_check_rec_status(2);
+	for (z = 0; z < nCubes; z++) // use the offset from the caller
+	{
+		offsetX[z] = global_offsetX[z];// - xmin;
+		offsetY[z] = global_offsetY[z];// - ymin;
+//		sinfo_msg("for cube [%d] offset X[%d : %d] Y[%d : %d]", z, offsetX[z], global_offsetX[z], offsetY[z], global_offsetY[z]);
+	}
+        sinfo_check_rec_status(3);
+    // Because of DFS09121, the allocated size is taken +1
+	nIndexXbytes = sizeof(CubeDataVector**) * (globalSizeX+1 );
+//	sinfo_msg("   kappa_sigma_offset, globalSizeX[%d] globalSizeY[%d] nIndexXbytes[%d]", globalSizeX, globalSizeY, nIndexXbytes);
+	indexX = cpl_malloc(nIndexXbytes);
+	memset(&indexX[0], 0, (globalSizeX+1 )* sizeof(indexX[0]));
+	// prepare result planes and mask
+
+	// 1. Fill indexes - do it only for a 0 plane in the cube
+	for (z = 0; z < nCubes; z++)
+	{
+		int iCubeSizeX = 0;
+		int iCubeSizeY = 0;
+		int iOffsetX = 0;
+		int iOffsetY = 0;
+
+		cpl_imagelist* pCube = inputCubes[z];
+		cpl_image* pImage = 0;
+		pImage = cpl_imagelist_get(pCube, 0);
+
+		iCubeSizeX = cpl_image_get_size_x(pImage);
+		iCubeSizeY = cpl_image_get_size_y(pImage);
+		iOffsetX = offsetX[z];
+		iOffsetY = offsetY[z];
+//		sinfo_msg("   processing cube [%d] offsetX[%d] offsetY[%d] iCubeSizeX[%d] iCubeSizeY[%d]", z, iOffsetX, iOffsetY, iCubeSizeX, iCubeSizeY);
+		for (x = 1; x <= iCubeSizeX; x++)
+		{
+			int iGlobalX = x + iOffsetX;
+
+			CubeDataVector** ppVector = 0;
+			if (indexX[iGlobalX - 1] == 0)
+			{
+			    // Because of DFS09121, the allocated size is taken +1
+				int nBytes = sizeof(CubeDataVector*) * (globalSizeY+1 );
+				ppVector= cpl_malloc(nBytes);
+				memset(&ppVector[0],0,(globalSizeY+1) * sizeof(ppVector[0]));
+				indexX[iGlobalX - 1] = ppVector;
+			}
+			else
+			{
+				ppVector = indexX[iGlobalX - 1];
+			}
+			for (y = 1; y <=iCubeSizeY; y++)
+			{
+				CubeData* pCubeData = 0;
+				int iGlobalY = y + iOffsetY;
+				CubeDataVector* pVector = ppVector[iGlobalY - 1];
+				if(pVector == 0)
+				{
+					int nbytes = sizeof(CubeDataVector);
+					check_nomsg(pVector = cpl_malloc(nbytes));
+					ppVector[iGlobalY - 1] = pVector;
+					pVector->size = 0;
+					nbytes = sizeof(CubeData*) * nCubes;
+					pVector->pdata = cpl_malloc(nbytes);
+//					memset(&pVector->pdata[0], 0, nCubes * sizeof(pVector->pdata[0]));
+				}
+				pCubeData = cpl_malloc(sizeof(CubeData));
+				pVector->pdata[(pVector->size)++] = pCubeData;
+				pCubeData->iCubeNumber = z;
+				pCubeData->iLocalX = x;
+				pCubeData->iLocalY = y;
+			}
+		}
+	}
+        sinfo_check_rec_status(4);
+
+	// 2. for each index value in global coordinates (x,y) call kappa-sigma
+	for (x = 1; x <= globalSizeX; x++)
+	{
+		CubeDataVector** pDataX = indexX[x - 1];
+		if (pDataX)
+		{
+			for (y = 1; y <= globalSizeY; y++)
+			{
+				CubeDataVector* pDataY = pDataX[y - 1];
+				if (pDataY && pDataY->size)
+				{
+					kappa_sigma_CubeDataVector(x, y, pDataY, imResult, inputCubes, sky_mask, iPlanesNumber, z_min, kappa, exptimes);
+				}
+				if (pDataY)
+				{
+					check_nomsg(cpl_free(pDataY->pdata));
+					check_nomsg(cpl_free(pDataY));
+				}
+			}
+			check_nomsg(cpl_free(pDataX));
+		}
+	}
+    sinfo_check_rec_status(5);
+    cleanup:
+	cpl_free(indexX);
+	cpl_free(offsetX);
+	cpl_free(offsetY);
+	return 0;
+
+}
+
+void kappa_sigma_CubeDataVector(
+		int globalX,
+		int globalY,
+		CubeDataVector* pCubeDataVector,
+		cpl_imagelist* imlistResult,
+		cpl_imagelist** input_cubes,
+		cpl_imagelist* sky_mask,
+		int iPlanesNumber,
+		int z_min,
+		const double kappa,
+		double* exptimes
+		)
+{
+	int plane = 0;
+	int z = 0;
+
+	// iterate through all planes
+	cpl_array* pArray = 0;
+	check_nomsg(pArray = cpl_array_new(pCubeDataVector->size, CPL_TYPE_DOUBLE));
+
+
+	for (plane = z_min; plane < z_min + iPlanesNumber; plane++)
+	{
+		double val_msk = 0; // value of the mask in the point
+		int px = 0;
+		cpl_image* imResult = 0;
+		cpl_image* imMask = 0;
+        double mask_adjustment = 0;
+        int nValidPoints = 0;
+		cpl_array_fill_window_invalid(pArray, 0, pCubeDataVector->size);
+		check_nomsg(imMask = cpl_imagelist_get(sky_mask, plane - z_min));
+		check_nomsg(val_msk = cpl_image_get(imMask, globalX, globalY, &px));
+		for (z = 0; z < pCubeDataVector->size; z++) // through all cubes for that point - prepare the array
+		{
+
+			cpl_imagelist* pCube = 0;
+			CubeData* pCubeData = pCubeDataVector->pdata[z];
+			pCube = input_cubes[pCubeData->iCubeNumber];
+			if (pCube)
+			{
+				cpl_image* pImage = cpl_imagelist_get(pCube, plane - z_min);
+
+				if (pImage)
+				{
+					int is_rejected = 0;
+					double value = 0;
+					check_nomsg(value = cpl_image_get(pImage, pCubeData->iLocalX, pCubeData->iLocalY, &is_rejected));
+					if (!isnan(value))
+					{
+						check_nomsg(cpl_array_set(pArray, z, value));
+						++nValidPoints;
+                    }
+					else
+					{
+						mask_adjustment += exptimes[z];
+					}
+				}
+				else
+				{
+					sinfo_msg("kappa_sigma_CubeDataVector() - pImage is null");
+				}
+			}
+		}
+		if(nValidPoints)
+		{
+		   kappa_sigma_array_with_mask(pArray, pCubeDataVector->size, kappa, imMask, exptimes, globalX, globalY, mask_adjustment);
+		   check_nomsg(imResult = cpl_imagelist_get(imlistResult, plane));
+		   if (imResult)
+		   {
+			  check_nomsg(cpl_image_set(imResult, globalX, globalY, cpl_array_get_mean(pArray)));
+		   }
+		   else
+		   {
+			  sinfo_msg("kappa_sigma_CubeDataVector() - imResult is null");
+		   }
+		} else
+		{
+			// adjust the mask
+			check_nomsg(cpl_image_set(imMask, globalX,globalY, 0));
+		}
+    }
+	for (z = 0; z < pCubeDataVector->size; z++) // through all cubes  - delete the data
+	{
+		CubeData* pCubeData = pCubeDataVector->pdata[z];
+		cpl_free(pCubeData);
+	}
+	cpl_array_delete(pArray);
+	return;
+	cleanup:
+//	sinfo_msg("   -----cleanup from kappa_sigma_CubeDataVector");
+	return;
+}
+
+
+static int
+sinfo_coadd_with_ks_clip(const int z_min,
+			const int z_max,
+			const int ilx,
+			const int ily,
+			const int n_cubes,
+			const double kappa,
+			int* llx,
+			int* lly,
+                        double* exptimes,
+			cpl_imagelist* mask,
+			cpl_imagelist* mergedCube,
+                        cpl_imagelist** tmpcubes)
+
+{
+
+  int m=0;
+  int x=0;
+  int y=0;
+  int z=0;
+
+  int mlx=0;
+  int mly=0;
+  int nc=0;
+  int olx=0;
+  int oly=0;
+  int posx=0;
+  int posy=0;
+  int i=0;
+  int nclip=0;
+  int ks=0;
+
+  float sig=0;
+  float med=0;
+  float ovr=0;
+  float  msk_sum=0;
+  float  val_msk_sum=0;
+  float avg=0;
+
+  float* pmdata=NULL;
+  float* podata=NULL;
+  float* ptdata=NULL;
+  float* pvdata=NULL;
+
+  cpl_image* m_img=NULL;
+  cpl_image* o_img=NULL;
+  cpl_image* t_img=NULL;
+  cpl_image* v_img=NULL;
+
+
+  cpl_vector* val=NULL;
+  cpl_vector* msk=NULL;
+
+
+  o_img=cpl_imagelist_get(mergedCube,0);
+  olx=cpl_image_get_size_x(o_img);
+  oly=cpl_image_get_size_y(o_img);
+
+  m=0;
+  for ( z = z_min; z < z_max ; z++ ) {
+    m_img=cpl_imagelist_get(mask,z);
+    pmdata=cpl_image_get_data_float(m_img);
+    o_img=cpl_imagelist_get(mergedCube,z);
+    podata=cpl_image_get_data_float(o_img);
+    mlx=cpl_image_get_size_x(m_img);
+    mly=cpl_image_get_size_y(m_img);
+    // go through the first image plane of the big data cube 
+    for ( y = 0 ; y < oly ; y++ ) {
+      for ( x = 0 ; x < olx ; x++ ) {
+	avg=0;
+	nc=0;
+	// computes nc 
+	for ( i = 0 ; i < n_cubes ; i++ ) {
+	  t_img=cpl_imagelist_get(tmpcubes[i],m);
+	  ptdata=cpl_image_get_data_float(t_img);
+          if ( y >= lly[i] && y < lly[i]+ily &&
+               x >= llx[i] && x < llx[i]+ilx ) {
+	    posx = x - llx[i] ;
+	    posy = y - lly[i] ;
+            if (!isnan(ptdata[posx+posy*ilx]) &&
+                       ptdata[posx+posy*ilx] != 0.) {
+	      nc++;
+	    }
+	  }
+	}
+        if( nc > 0 ) {
+
+	  
+	  msk=cpl_vector_new(n_cubes);
+	  for (i=0;i<n_cubes;i++) {
+	    cpl_vector_set(msk,i,1);
+	  }
+
+	  // k-s clipping 
+	  nclip=0;
+
+
+	  for (ks=0;ks<nc;ks++) {
+	    sig=0;
+	    med=0;
+	    ovr=0;
+	    if(nc-nclip >0) {
+	      val=cpl_vector_new(nc-nclip);
+	    }
+	    // fill val 
+	    for ( i = 0 ; i < n_cubes ; i++ ) {
+	      t_img=cpl_imagelist_get(tmpcubes[i],m);
+	      ptdata=cpl_image_get_data_float(t_img);
+              if ( y >= lly[i] && y < lly[i]+ily &&
+                   x >= llx[i] && x < llx[i]+ilx ) {
+		posx = x - llx[i] ;
+		posy = y - lly[i] ;
+                if (!isnan(ptdata[posx+posy*ilx]) &&
+                           ptdata[posx+posy*ilx] != 0. &&
+		    (cpl_vector_get(msk,i) != 0)) {
+		  cpl_vector_set(val,ovr,(double)ptdata[posx+posy*ilx]);
+		  ovr++;
+		}
+	      }
+	    }
+
+	    // get avg, med, sig 
+	    if(ovr>0) {
+	      avg=cpl_vector_get_mean(val);
+	      med=cpl_vector_get_median_const(val);
+	      if(ovr>1) {
+		sig=cpl_vector_get_stdev(val);
+	      } else {
+		sig=0;
+	      }
+	      cpl_vector_delete(val);
+	    }
+
+	    for ( i = 0 ; i < n_cubes ; i++ ) {
+	      t_img=cpl_imagelist_get(tmpcubes[i],m);
+	      ptdata=cpl_image_get_data_float(t_img);
+	      // Do k-s clipping at each pixel 
+              if ( y >= lly[i] && y < lly[i]+ily &&
+                   x >= llx[i] && x < llx[i]+ilx ) {
+		posx = x - llx[i] ;
+		posy = y - lly[i] ;
+                if (!isnan(ptdata[posx+posy*ilx]) &&
+                           ptdata[posx+posy*ilx] != 0. &&
+		    (cpl_vector_get(msk,i) != 0)) {
+		  if(abs((ptdata[posx+posy*ilx]-med))> kappa*sig) {
+                    ptdata[posx+posy*ilx]=0;
+		    pmdata[x+y*mlx] -= exptimes[i]  ;
+		    cpl_vector_set(msk,i,0);
+		    nclip++;
+		  }
+		}
+	      }
+	    }
+	  } // end of k-s clipping 
+
+	  msk_sum=0;
+	  val_msk_sum=0;
+	  for ( i = 0 ; i < n_cubes ; i++ ) {
+	    v_img=cpl_imagelist_get(tmpcubes[i],m);
+	    pvdata=cpl_image_get_data_float(v_img);
+	    // computes sky at each point 
+            if ( y >= lly[i] && y < lly[i]+ily &&
+                 x >= llx[i] && x < llx[i]+ilx ) {
+	      posx = x - llx[i] ;
+	      posy = y - lly[i] ;
+              //sinfo_msg_warning("llx[%d]=%d lly[%d],=%d",i,llx[i],i,lly[i]);
+              //sinfo_msg_warning("posx=%d posy=%d",posx,posy);
+              if (!isnan(pvdata[posx+posy*ilx]) &&
+                         pvdata[posx+posy*ilx] != 0. &&
+		  (cpl_vector_get(msk,i) != 0)) {
+		msk_sum+=pmdata[x+y*mlx];
+                val_msk_sum+=pvdata[posx+posy*ilx]*
+		  pmdata[x+y*mlx];
+	      }
+	    }
+	  }
+	  podata[x+y*olx]=val_msk_sum/msk_sum;
+	  cpl_vector_delete(msk);
+	  /*
+ 	  sinfo_ks_clip(n_cubes,nc,ilx,ily,kappa,llx,lly,exptimes,
+			tmpcubes,podata,pmdata,x,y,m,mlx,oly);
+
+	  */
+
+	} // end check if overlap nc >0  
+      } // end loop over x 
+    } // end loop over y 
+    m++;
+  } // end loop over z 
+
+  return 0;
+
+
+}
+
+
+
+
+static int
+sinfo_compute_contributes_at_pos(cpl_imagelist** tmpcubes, 
+                                 int* llx, int* lly, 
+                                 const int x, const int y,
+                                 const int ilx, const int ily, 
+                                 const int m,const int n_cubes)
+{
+
+   int result=0;
+   int i=0;
+   int lox=0;
+   int loy=0;
+   int upx=0;
+   int upy=0;
+   int post=0;
+   int posx=0;
+   int posy=0;
+
+   float* ptdata=NULL;
+   cpl_image* t_img=NULL;
+  
+ 
+   /* computes nc the number of intensity contributes from 
+      each overlapping cube point intensity at x,y
+   */
+   for ( i = 0 ; i < n_cubes ; i++ ) {
+      t_img=cpl_imagelist_get(tmpcubes[i],m);
+      ptdata=cpl_image_get_data_float(t_img);
+      lox=llx[i];
+      loy=lly[i];
+      upx=llx[i]+ilx;
+      upy=lly[i]+ily;
+
+      if ( y >= loy && y < upy && x >= lox && x < upx ) {
+         posx = x - lox;
+         posy = y - loy;
+         post = posx+posy*ilx;
+
+         if (!isnan(ptdata[post]) && ptdata[post] != 0.) {
+            result++;
+         }
+      }
+   }
+
+
+   return result;
+
+}
+
+
+
+
+static int
+sinfo_cubes_coadd_with_ks_clip(cpl_imagelist** tmpcubes, 
+                               const int n_cubes,const int nc,
+                               const int x, const int y, const int m,
+                               int* llx, int* lly, 
+                               const int ilx, const int ily,
+                               const double kappa, 
+                               double* exptimes, float** pmdata, 
+                               cpl_vector** msk, const int mlx)
+
+
+{
+
+ 
+   cpl_vector* val=NULL;
+   cpl_image* t_img=NULL;
+
+   int i=0;
+   int nclip=0;
+   int ks=0;
+   
+   int lox=0;
+   int loy=0;
+   int upx=0;
+   int upy=0;
+
+   int posx=0;
+   int posy=0;
+   int post=0;
+
+   int ovr=0;
+
+   float sig=0;
+   float avg=0;
+   float med=0;
+
+   float* ptdata=NULL;
+   
+
+   // k-s clipping 
+   nclip=0;
+
+
+   for (ks=0;ks<nc;ks++) {
+      sig=0;
+      med=0;
+      ovr=0;
+      if(nc-nclip >0) {
+         check_nomsg(val=cpl_vector_new(nc-nclip));
+      }
+      // fill val 
+      for ( i = 0 ; i < n_cubes ; i++ ) {
+         check_nomsg(t_img=cpl_imagelist_get(tmpcubes[i],m));
+         check_nomsg(ptdata=cpl_image_get_data_float(t_img));
+
+         lox=llx[i];
+         loy=lly[i];
+         upx=llx[i]+ilx;
+         upy=lly[i]+ily;
+
+         if ( y >= loy && y < upy && x >= lox && x < upx ) {
+            posx = x - lox ;
+            posy = y - loy ;
+            post=posx+posy*ilx;
+
+            if (!isnan(ptdata[post]) && ptdata[post] != 0. &&
+                (cpl_vector_get(*msk,i) != 0)) {
+               cpl_vector_set(val,ovr,(double)ptdata[post]);
+               ovr++;
+            }
+         }
+      }
+
+      // get avg, med, sig 
+      if(ovr>0) {
+         check_nomsg(avg=cpl_vector_get_mean(val));
+         med=cpl_vector_get_median_const(val);
+         if(ovr>1) {
+            sig=cpl_vector_get_stdev(val);
+         } else {
+            sig=0;
+         }
+         cpl_vector_delete(val);
+      }
+
+      for ( i = 0 ; i < n_cubes ; i++ ) {
+         t_img=cpl_imagelist_get(tmpcubes[i],m);
+         ptdata=cpl_image_get_data_float(t_img);
+
+         lox=llx[i];
+         loy=lly[i];
+         upx=llx[i]+ilx;
+         upy=lly[i]+ily;
+
+         // Do k-s clipping at each pixel 
+         if ( y >= loy && y < upy && x >= lox && x < upx ) {
+            posx = x - lox ;
+            posy = y - loy ;
+            post = posx+posy*ilx;
+            if (!isnan(ptdata[post]) && ptdata[post] != 0. &&
+                (cpl_vector_get(*msk,i) != 0)) {
+               if( abs( (ptdata[post]-med) ) > kappa*sig ) {
+                  ptdata[post]=0;
+                  (*pmdata)[x+y*mlx] -= exptimes[i]  ;
+                  check_nomsg(cpl_vector_set(*msk,i,0));
+                  nclip++;
+               }
+            }
+         }
+      }
+   } // end of k-s clipping 
+
+  cleanup:
+   return 0;
+}
+
+/**
+   @name sinfo_coadd_with_ks_clip coadd cubes with kappa-sigma clip of overlapping pixels intensity outliers
+   @param z_min: min cube's plane to be processed
+   @param z_max: max cube's plane to be processed
+   @param ilx: input image X size
+   @param ily: input image Y size
+   @param n_cubes: number of cubes to be coadded
+   @param kappa value for kappa-sigma clip rejection
+   @param llx: array holding lower left X for each input cube
+   @param lly: array holding lower left Y for each input cube
+   @param exptimes: array holding exposure times for each input cube
+   @param mask: output cube mask   
+   @param mergedCube: output coadded cube 
+   @param tmccubes: input cubes to be coadded
+
+   @return interpolated cube, and corrected bad pixel mask cube
+   @doc interpolates bad pixel of an object cube if a bad pixel
+        mask cube is available by using the nearest neighbors
+        in 3 dimensions.
+ */
+
+
+static int
+sinfo_coadd_with_ks_clip2(const int z_min,
+			const int z_max,
+			const int ilx,
+			const int ily,
+			const int n_cubes,
+			const double kappa,
+			int* llx,
+			int* lly,
+                        double* exptimes,
+			cpl_imagelist* mask,
+			cpl_imagelist* mergedCube,
+                        cpl_imagelist** tmpcubes)
+
+{
+
+  int m=0;
+  int x=0;
+  int y=0;
+  int z=0;
+
+  int mlx=0;
+  int mly=0;
+  int nc=0;
+  int olx=0;
+  int oly=0;
+  int posx=0;
+  int posy=0;
+  int i=0;
+
+  float  msk_sum=0;
+  float  val_msk_sum=0;
+  float avg=0;
+
+  float* pmdata=NULL;
+  float* podata=NULL;
+  float* pvdata=NULL;
+
+  cpl_image* m_img=NULL;
+  cpl_image* o_img=NULL;
+  cpl_image* v_img=NULL;
+
+
+  cpl_vector* msk=NULL;
+
+
+  o_img=cpl_imagelist_get(mergedCube,0);
+  olx=cpl_image_get_size_x(o_img);
+  oly=cpl_image_get_size_y(o_img);
+
+  m=0;
+  for ( z = z_min; z < z_max ; z++ ) {
+    m_img=cpl_imagelist_get(mask,z);
+    pmdata=cpl_image_get_data_float(m_img);
+    o_img=cpl_imagelist_get(mergedCube,z);
+    podata=cpl_image_get_data_float(o_img);
+    mlx=cpl_image_get_size_x(m_img);
+    mly=cpl_image_get_size_y(m_img);
+    // go through the first image plane of the big data cube 
+    for ( y = 0 ; y < oly ; y++ ) {
+      for ( x = 0 ; x < olx ; x++ ) {
+	avg=0;
+	nc=0;
+	// computes nc 
+
+        nc=sinfo_compute_contributes_at_pos(tmpcubes,llx,lly,x,y,
+                                            ilx,ily,m,n_cubes);
+
+        if( nc > 0 ) {
+
+	  
+	  msk=cpl_vector_new(n_cubes);
+	  for (i=0;i<n_cubes;i++) {
+	    cpl_vector_set(msk,i,1);
+	  }
+
+
+           sinfo_cubes_coadd_with_ks_clip(tmpcubes, n_cubes,nc,x,y,m,
+                                          llx,lly,ilx,ily,kappa, 
+                                          exptimes,&pmdata, &msk,mlx);
+
+	  msk_sum=0;
+	  val_msk_sum=0;
+	  for ( i = 0 ; i < n_cubes ; i++ ) {
+	    v_img=cpl_imagelist_get(tmpcubes[i],m);
+	    pvdata=cpl_image_get_data_float(v_img);
+	    // computes sky at each point 
+            if ( y >= lly[i] && y < lly[i]+ily &&
+                 x >= llx[i] && x < llx[i]+ilx ) {
+	      posx = x - llx[i] ;
+	      posy = y - lly[i] ;
+              //sinfo_msg_warning("llx[%d]=%d lly[%d],=%d",i,llx[i],i,lly[i]);
+              //sinfo_msg_warning("posx=%d posy=%d",posx,posy);
+              if (!isnan(pvdata[posx+posy*ilx]) &&
+                         pvdata[posx+posy*ilx] != 0. &&
+		  (cpl_vector_get(msk,i) != 0)) {
+		msk_sum+=pmdata[x+y*mlx];
+                val_msk_sum+=pvdata[posx+posy*ilx]*
+		  pmdata[x+y*mlx];
+	      }
+	    }
+	  }
+	  podata[x+y*olx]=val_msk_sum/msk_sum;
+	  cpl_vector_delete(msk);
+	  /*
+ 	  sinfo_ks_clip(n_cubes,nc,ilx,ily,kappa,llx,lly,exptimes,
+			tmpcubes,podata,pmdata,x,y,m,mlx,oly);
+
+	  */
+
+	} // end check if overlap nc >0  
+      } // end loop over x 
+    } // end loop over y 
+    m++;
+  } // end loop over z 
+
+  return 0;
+
+
+}
+
+
+/**@}*/
diff --git a/sinfoni/sinfo_new_cube_ops.h b/sinfoni/sinfo_new_cube_ops.h
new file mode 100644
index 0000000..cd74317
--- /dev/null
+++ b/sinfoni/sinfo_new_cube_ops.h
@@ -0,0 +1,864 @@
+#ifndef SINFO_NEW_CUBE_OPS_H
+#define SINFO_NEW_CUBE_OPS_H
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/************************************************************************
+* E.S.O. - VLT project
+*
+* who       when      what
+* --------  --------  ----------------------------------------------
+* schreib  18/05/00  created
+*/
+
+/************************************************************************
+ * sinfo_new_cube_ops.h
+ * cube arithmetic routines
+ *----------------------------------------------------------------------
+ */
+
+/*
+ * header files
+ */
+
+#include "sinfo_image_ops.h"
+#include <cpl.h>
+#include "sinfo_msg.h"
+
+
+/*----------------------------------------------------------------------------
+ *                        Function ANSI C prototypes
+ *--------------------------------------------------------------------------*/
+
+
+/**
+   @name   sinfo_new_cube_ops()
+   @memo   2 cubes, operation to perform
+   @param  cube1 1st cube
+   @param  cube2 2nd cube
+   @param  operation operation to perform between cubes
+   @result result cube
+   @short  4 operations between 2 cubes
+
+ */
+
+cpl_imagelist *
+sinfo_new_cube_ops(
+    cpl_imagelist *  cube1,
+    cpl_imagelist *   cube2,
+    int         operation);
+
+
+/**
+   @name    sinfo_new_cube_const_ops()
+   @memo    1 cube, 1 constant, operation to perform
+   @param   cube1 input cube to be operated
+   @param   constant value to be applied
+   @param   operation operation index
+   @return  result cube
+   @short   4 operations between a cube and a constant
+   @note    possible operations are:
+                Addition        '+'
+                Subtraction     '-'
+                Multiplication  '*'
+                Division        '/'
+                Logarithm       'l'
+                Power           '^'
+                Exponentiation  'e'
+
+
+*/
+
+cpl_imagelist *
+sinfo_new_cube_const_ops(
+    cpl_imagelist *  cube1,
+    double     constant,
+    int        operation);
+
+
+/**
+   @name  sinfo_new_cube_sub()
+   @memo subtract one cube from another
+   @param c1  1st cube
+   @param c2  2nd cube
+   @result result cube
+ */
+
+cpl_imagelist *
+sinfo_new_cube_sub(
+    cpl_imagelist    *    c1,
+    cpl_imagelist    *    c2
+) ;
+
+
+
+/**
+   @name sinfo_new_cube_add()
+   @memo add a cube to another
+   @param c1  1st cube
+   @param c2  2nd cube
+   @result result cube
+*/
+
+cpl_imagelist *
+sinfo_new_cube_add(
+    cpl_imagelist    *    c1,
+    cpl_imagelist    *    c2
+) ;
+
+
+/**
+   @name sinfo_new_cube_mul()
+   @memo multiply two cubes
+   @param c1  1st cube
+   @param c2  2nd cube
+   @result result cube
+ */
+
+cpl_imagelist *
+sinfo_new_cube_mul(
+    cpl_imagelist    *    c1,
+    cpl_imagelist    *    c2
+) ;
+
+
+/**
+   @name  sinfo_new_cube_div()
+   @memo  divides two cubes
+   @param c1  1st cube
+   @param c2  2nd cube
+   @result result cube
+
+ */
+
+cpl_imagelist *
+sinfo_new_cube_div(
+    cpl_imagelist    *    c1,
+    cpl_imagelist    *    c2
+) ;
+
+/**
+   @name   sinfo_new_add_image_to_cube()
+   @memo   add an image to all planes in the cube
+   @param  cu 1 allocated cube
+   @param  im 1 allocated image
+   @return result cube
+ */
+
+cpl_imagelist *
+sinfo_new_add_image_to_cube(cpl_imagelist * cu, cpl_image * im);
+
+/**
+   @name      sinfo_new_sub_image_from_cube()
+   @memo      subtract an image from all planes in the cube
+   @param cu  1 allocated cube,
+   @param im  1 allocated image
+   @result    result cube
+ */
+
+cpl_imagelist *
+sinfo_new_sub_image_from_cube(cpl_imagelist * cu, cpl_image * im);
+
+/**
+   @name     sinfo_new_mul_image_to_cube()
+   @memo multiply an image to all planes in the cube
+   @param    cu   1 allocated cube,
+   @param    im   1 allocated image
+   @result   result cube
+ */
+
+cpl_imagelist *
+sinfo_new_mul_image_to_cube(cpl_imagelist * cu, cpl_image * im);
+
+/**
+   @name    sinfo_new_div_cube_by_image ()
+   @memo    divide all planes in the cube by an image
+   @param   cu     1 allocated cube,
+   @param   im     1 allocated image
+   @return  result cube
+*/
+
+cpl_imagelist *
+sinfo_new_div_cube_by_image(cpl_imagelist * cu, cpl_image * im);
+
+
+/**
+   @name    sinfo_new_add_spectrum_to_cube()
+   @memo   adds a spectrum (in z-direction) from all data points in a cube
+   @param   cu       1 allocated cube,
+   @parm    spec       1 allocated spectrum sinfo_vector
+   @return       result cube
+ */
+
+cpl_imagelist *
+sinfo_new_add_spectrum_to_cube(cpl_imagelist *cu, Vector *spec);
+
+
+/**
+   @name     sinfo_new_sub_spectrum_from_cube()
+   @memo  subtracts a spectrum (in z-direction) from all data points in a cube
+   @param    cu       1 allocated cube,
+   @param    im       1 allocated spectrum sinfo_vector
+   @return  result cube
+ */
+
+cpl_imagelist *
+sinfo_new_sub_spectrum_from_cube(cpl_imagelist *cu, Vector *spec);
+
+
+/**
+   @name     sinfo_new_mul_spectrum_to_cube()
+   @memo multiplies a spectrum (in z-direction) to all data points in a cube
+   @param    cu     1 allocated cube,
+   @param    spec   1 allocated spectrum sinfo_vector
+   @result   result cube
+*/
+
+cpl_imagelist *
+sinfo_new_mul_spectrum_to_cube(cpl_imagelist *cu, Vector *spec);
+
+
+/**
+   @name sinfo_new_div_cube_by_spectrum()
+   @param cu  1 allocated cube,
+   @param spec  1 allocated spectrum sinfo_vector
+   @result  result cube
+   @memo divides all data points of a cube by a spectrum (in z-direction)
+ */
+
+cpl_imagelist *
+sinfo_new_div_cube_by_spectrum(cpl_imagelist *cu, Vector *spec);
+
+/**
+   @name  sinfo_new_clean_mean_of_spectra()
+   @memo  clean mean of a cube in a rectangle
+   @param cu  1 allocated cube,
+   @param llx lower left x position of rectangle in x-y plane ,
+   @param lly lower left y position of rectangle in x-y plane ,
+   @param urx upper right x position of rectangle in x-y plane ,
+   @param ury upper right y position of rectangle in x-y plane ,
+   @param lo_reject lower cut intensity threshold
+   @param hi_reject upper cut intensity threshold
+   @return result spectrum vector
+   @doc  averaging routine to get a better spectral S/N, sorts
+         the values of the same z-position, cuts the lowest and
+         highest values according to given thresholds and then
+         takes the average within the x-y plane , cannot have
+         a sum of low and high rejected values greater than 90%
+         of all values
+ */
+
+Vector *
+sinfo_new_clean_mean_of_spectra(cpl_imagelist * cube,
+                             int llx,
+                             int lly,
+                             int urx,
+                             int ury,
+                             double lo_reject,
+                             double hi_reject);
+
+/**
+   @name   sinfo_new_median_cube()
+   @memo clean (remove 'BLANK' pixels) median of a cube along z axis
+   @param  cube       1 allocated cube
+   @result result image
+   @doc    determines the median value in every pixel position
+           by considering all pixels along the third axis.
+           BLANK pixels in a plane are not considered. If all
+           pixels at a position are not valid the result will
+           be 'BLANK'.
+*/
+cpl_image *
+sinfo_new_median_cube(cpl_imagelist * cube) ;
+
+/**
+   @name sinfo_new_average_cube_to_image()
+   @memo clean (remove 'ZERO' pixels) average of a cube along z axis
+   @param cube       1 allocated cube
+   @result  result image
+   @doc  determines the average value in every pixel position
+         by considering all pixels along the third axis.
+         ZERO pixels in a plane are not considered. If all
+         pixels at a position are not valid the result will
+         be 'ZERO'.
+ */
+cpl_image *
+sinfo_new_average_cube_to_image(cpl_imagelist * cube) ;
+
+/**
+   @name  sinfo_new_sum_cube_to_image()
+   @param cube       1 allocated cube
+   @result result image
+   @doc  determines the sum value in every pixel position
+         by considering all pixels along the third axis.
+         ZERO pixels in a plane are not considered. If all
+         pixels at a position are not valid the result will
+         be 'ZERO'.
+ */
+cpl_image *
+sinfo_new_sum_cube_to_image(cpl_imagelist * cube) ;
+
+/**
+   @name                sinfo_new_average_cube_to_image_between_waves()
+   @memo  clean average of a cube within a given wavelength range
+   @param               cube: data cube to collapse
+   @param               dispersion: dispersion per pixel in microns/pixel
+                                    (derived from fits header information)
+   @param               centralWave: central wavelength in the cube in microns
+                                       (derived from fits header information)
+   @param               initialLambda start wavelength values in microns
+   @param               finalLambda: end   wavelength values in microns
+                                    within which the cube is averaged
+   @result              resulting averaged image
+   @doc                 determines the average value in every pixel position
+                        by considering only the pixels along the third axis
+                        which lie between the given wavelength values.
+                        These values are first recalculated to plane indices
+                        by using the given dispersion and minimum wavelength in
+                        the cube.
+                        ZERO pixels in a plane are not considered. If all
+                        pixels at a position are not valid the result will
+                        be 'ZERO'.
+ */
+cpl_image *
+sinfo_new_average_cube_to_image_between_waves (cpl_imagelist * cube,
+                                           float     dispersion,
+                                           float     centralWave,
+                                           float     initialLambda,
+                                           float     finalLambda) ;
+
+/**
+   @name     sinfo_new_extract_image_from_cube()
+   @memo     returns the wanted image plane of the cube
+   @param    cube      1 allocated cube
+   @param    index of cube plane
+   @result   extracted image
+*/
+cpl_image *
+sinfo_new_extract_image_from_cube(cpl_imagelist * cube, int plane_index) ;
+
+/**
+   @name     sinfo_new_extract_spectrum_from_cube()
+   @param    cube: 1 allocated cube
+   @param    x_pos x pixel position of the spectrum counted from 0
+   @param    y_pos y pixel position of the spectrum counted from 0
+   @result   extracted spectral sinfo_vector object
+   @memo     returns the wanted single spectrum of the cube
+*/
+Vector *
+sinfo_new_extract_spectrum_from_cube(cpl_imagelist * cube,
+                                     int x_pos,
+                                     int y_pos ) ;
+
+/**
+   @name         sinfo_new_combine_jittered_cubes()
+   @name         cubes: list of jittered cubes to mosaic
+   @param        mergedCube: resulting merged cube containing the
+                                    jittered cubes
+   @param        n_cubes: number of cubes in the list to merge
+   @param        cumoffsetx: array of relative x pixel offset
+                             with respect to the first frame in the
+                             same sequence as the cube list.
+   @param        cumoffsety: array of relative y pixel offsets
+                             with respect to the first frame in the
+                             same sequence as the cube list.
+   @param        exptimes:   exposure times array giving the time
+                             in the same sequence as the cube list
+   @param        kernel_type: the name of the interpolation kernel
+                              that you want to generate using the eclipse
+                              routine sinfo_generate_interpolation_kernel()
+                              Supported kernels are:
+                                     NULL:      default kernel, currently tanh
+                                     "default": dito
+                                     "tanh":    Hyperbolic tangent
+                                     "sinc2":   Square sinc
+                                     "lanczos": Lanczos2 kernel
+                                     "hamming": Hamming kernel
+                                     "hann":    Hann kernel
+   @result       mask: cube of the same size as combinedCube
+                       containing 0 for blank (ZERO pixels) and
+                       the summed integration times for overlapping regions
+   @doc                merges jittered data cubes to one bigger cube
+                       by averaging the overlap regions weighted by
+                       the integration times. The x, y size of the final data
+                       cube is user given, and should be between 32 and 64
+                       pixels, while the relative pixel-offset (sub-pixel
+                       accuracy) of the single cubes with respect to the
+                       first cube in the list is read from the SEQ CUMOFFSETX,Y
+                       fits header keyword.
+ */
+
+
+
+cpl_imagelist *
+sinfo_new_combine_jittered_cubes ( cpl_imagelist ** cubes,
+                                 cpl_imagelist  * mergedCube,
+                                 int        n_cubes,
+                                 float    * cumoffsetx,
+                                 float    * cumoffsety,
+                                 float    * exptimes,
+                   char     * kernel_type );
+
+/**
+   @name         sinfo_new_combine_jittered_cubes()
+   @name         cubes: list of jittered cubes to mosaic
+   @param        mergedCube: resulting merged cube containing the
+                                    jittered cubes
+   @param        n_cubes: number of cubes in the list to merge
+   @param        cumoffsetx: array of relative x pixel offset
+                             with respect to the first frame in the
+                             same sequence as the cube list.
+   @param        cumoffsety: array of relative y pixel offsets
+                             with respect to the first frame in the
+                             same sequence as the cube list.
+   @param        exptimes:   exposure times array giving the time
+                             in the same sequence as the cube list
+   @param        kernel_type: the name of the interpolation kernel
+                              that you want to generate using the eclipse
+                              routine sinfo_generate_interpolation_kernel()
+                              Supported kernels are:
+                                     NULL:      default kernel, currently tanh
+                                     "default": dito
+                                     "tanh":    Hyperbolic tangent
+                                     "sinc2":   Square sinc
+                                     "lanczos": Lanczos2 kernel
+                                     "hamming": Hamming kernel
+                                     "hann":    Hann kernel
+
+   @param        z     plane at which the cube is combined.
+   @result       mask: cube of the same size as combinedCube
+                       containing 0 for blank (ZERO pixels) and
+                       the summed integration times for overlapping regions
+   @doc                merges jittered data cubes to one bigger cube
+                       by averaging the overlap regions weighted by
+                       the integration times. The x, y size of the final data
+                       cube is user given, and should be between 32 and 64
+                       pixels, while the relative pixel-offset (sub-pixel
+                       accuracy) of the single cubes with respect to the
+                       first cube in the list is read from the SEQ CUMOFFSETX,Y
+                       fits header keyword.
+ */
+
+
+cpl_imagelist *
+new_combine_jittered_cubes_it ( cpl_imagelist ** cubes,
+                                 cpl_imagelist *  mergedCube,
+                                 cpl_imagelist *  mask,
+                                 int        n_cubes,
+                                 float    * cumoffsetx,
+                                 float    * cumoffsety,
+                                 float    * exptimes,
+                                 char     * kernel_type,
+                                 const int z) ;
+
+
+/**
+   @name         sinfo_new_combine_jittered_cubes_thomas_range()
+   @name         cubes: list of jittered cubes to mosaic
+   @param        mergedCube: resulting merged cube containing the
+                                    jittered cubes
+   @param        n_cubes: number of cubes in the list to merge
+   @param        cumoffsetx: array of relative x pixel offset
+                             with respect to the first frame in the
+                             same sequence as the cube list.
+   @param        cumoffsety: array of relative y pixel offsets
+                             with respect to the first frame in the
+                             same sequence as the cube list.
+   @param        exptimes:   exposure times array giving the time
+                             in the same sequence as the cube list
+   @param        kernel_type: the name of the interpolation kernel
+                              that you want to generate using the eclipse
+                              routine sinfo_generate_interpolation_kernel()
+                              Supported kernels are:
+                                     NULL:      default kernel, currently tanh
+                                     "default": dito
+                                     "tanh":    Hyperbolic tangent
+                                     "sinc2":   Square sinc
+                                     "lanczos": Lanczos2 kernel
+                                     "hamming": Hamming kernel
+                                     "hann":    Hann kernel
+   @param       z_min         min z of plane  to be combined
+   @param       z_max         max z of plane  to be combined
+   @param       kappa         kappa of kappa-sigma clipping algorithm
+   @result       mask: cube of the same size as combinedCube
+                       containing 0 for blank (ZERO pixels) and
+                       the summed integration times for overlapping regions
+   @doc                merges jittered data cubes to one bigger cube
+                       by averaging the overlap regions weighted by
+                       the integration times. The x, y size of the final data
+                       cube is user given, and should be between 32 and 64
+                       pixels, while the relative pixel-offset (sub-pixel
+                       accuracy) of the single cubes with respect to the
+                       first cube in the list is read from the SEQ CUMOFFSETX,Y
+                       fits header keyword.
+ */
+
+int
+sinfo_new_combine_jittered_cubes_thomas_range(cpl_imagelist ** cubes,
+                    cpl_imagelist  * mergedCube,
+                    cpl_imagelist  * mask,
+                    int        n_cubes,
+                    float    * cumoffsetx,
+                    float    * cumoffsety,
+                    double    * exptimes,
+                    char     * kernel_type,
+                    const int z_min,
+                    const int z_max,
+                                    const double kappa );
+
+/**
+   @name         sinfo_new_combine_jittered_cubes_sky_range()
+   @name         cubes: list of jittered cubes to mosaic
+   @param        mergedCube: resulting merged cube containing the
+                                    jittered cubes
+   @param        n_cubes: number of cubes in the list to merge
+   @param        cumoffsetx: array of relative x pixel offset
+                             with respect to the first frame in the
+                             same sequence as the cube list.
+   @param        cumoffsety: array of relative y pixel offsets
+                             with respect to the first frame in the
+                             same sequence as the cube list.
+   @param        exptimes:   exposure times array giving the time
+                             in the same sequence as the cube list
+   @param        kernel_type: the name of the interpolation kernel
+                              that you want to generate using the eclipse
+                              routine sinfo_generate_interpolation_kernel()
+                              Supported kernels are:
+                                     NULL:      default kernel, currently tanh
+                                     "default": dito
+                                     "tanh":    Hyperbolic tangent
+                                     "sinc2":   Square sinc
+                                     "lanczos": Lanczos2 kernel
+                                     "hamming": Hamming kernel
+                                     "hann":    Hann kernel
+   @param       z_min         min z of plane  to be combined
+   @param       z_max         max z of plane  to be combined
+   @result       mask: cube of the same size as combinedCube
+                       containing 0 for blank (ZERO pixels) and
+                       the summed integration times for overlapping regions
+   @doc                merges jittered data cubes to one bigger cube
+                       by averaging the overlap regions weighted by
+                       the integration times. The x, y size of the final data
+                       cube is user given, and should be between 32 and 64
+                       pixels, while the relative pixel-offset (sub-pixel
+                       accuracy) of the single cubes with respect to the
+                       first cube in the list is read from the SEQ CUMOFFSETX,Y
+                       fits header keyword.
+ */
+
+int
+new_combine_jittered_cubes_sky_range (cpl_imagelist ** cubes,
+                   cpl_imagelist  * mergedCube,
+                   cpl_imagelist  * mask,
+                   cpl_imagelist  * mergedSky,
+                   cpl_imagelist  * mergedMsk,
+                   cpl_imagelist  * mergeMed,
+                   cpl_imagelist  * mergeAvg,
+                   cpl_imagelist  * mergeStd,
+                   cpl_imagelist  * mergeNc,
+                   int        n_cubes,
+                   float    * cumoffsetx,
+                   float    * cumoffsety,
+                   float    * exptimes,
+                   char     * kernel_type,
+                   const int z_min,
+                   const int z_max);
+
+/**
+   @name         sinfo_new_combine_jittered_cubes_range()
+   @name         cubes: list of jittered cubes to mosaic
+   @param        mergedCube: resulting merged cube containing the
+                                    jittered cubes
+   @param        n_cubes: number of cubes in the list to merge
+   @param        cumoffsetx: array of relative x pixel offset
+                             with respect to the first frame in the
+                             same sequence as the cube list.
+   @param        cumoffsety: array of relative y pixel offsets
+                             with respect to the first frame in the
+                             same sequence as the cube list.
+   @param        exptimes:   exposure times array giving the time
+                             in the same sequence as the cube list
+   @param        kernel_type: the name of the interpolation kernel
+                              that you want to generate using the eclipse
+                              routine sinfo_generate_interpolation_kernel()
+                              Supported kernels are:
+                                     NULL:      default kernel, currently tanh
+                                     "default": dito
+                                     "tanh":    Hyperbolic tangent
+                                     "sinc2":   Square sinc
+                                     "lanczos": Lanczos2 kernel
+                                     "hamming": Hamming kernel
+                                     "hann":    Hann kernel
+   @param       z_min         min z of plane  to be combined
+   @param       z_max         max z of plane  to be combined
+   @result       mask: cube of the same size as combinedCube
+                       containing 0 for blank (ZERO pixels) and
+                       the summed integration times for overlapping regions
+   @doc                merges jittered data cubes to one bigger cube
+                       by averaging the overlap regions weighted by
+                       the integration times. The x, y size of the final data
+                       cube is user given, and should be between 32 and 64
+                       pixels, while the relative pixel-offset (sub-pixel
+                       accuracy) of the single cubes with respect to the
+                       first cube in the list is read from the SEQ CUMOFFSETX,Y
+                       fits header keyword.
+ */
+int
+sinfo_new_combine_jittered_cubes_range ( cpl_imagelist ** cubes,
+                                 cpl_imagelist  * mergedCube,
+                                 cpl_imagelist  * mask,
+                                 int        n_cubes,
+                                 float    * cumoffsetx,
+                                 float    * cumoffsety,
+                                 double    * exptimes,
+                                 char     * kernel_type,
+                                 const int z_min, const int z_max );
+
+/**
+   @name         sinfo_new_combine_jittered_cubes_sky_range2()
+   @name         cubes: list of jittered cubes to mosaic
+   @param        mergedCube: resulting merged cube containing the
+                                    jittered cubes
+   @param        n_cubes: number of cubes in the list to merge
+   @param        cumoffsetx: array of relative x pixel offset
+                             with respect to the first frame in the
+                             same sequence as the cube list.
+   @param        cumoffsety: array of relative y pixel offsets
+                             with respect to the first frame in the
+                             same sequence as the cube list.
+   @param        exptimes:   exposure times array giving the time
+                             in the same sequence as the cube list
+   @param        kernel_type: the name of the interpolation kernel
+                              that you want to generate using the eclipse
+                              routine sinfo_generate_interpolation_kernel()
+                              Supported kernels are:
+                                     NULL:      default kernel, currently tanh
+                                     "default": dito
+                                     "tanh":    Hyperbolic tangent
+                                     "sinc2":   Square sinc
+                                     "lanczos": Lanczos2 kernel
+                                     "hamming": Hamming kernel
+                                     "hann":    Hann kernel
+   @param       z_min         min z of plane  to be combined
+   @param       z_max         max z of plane  to be combined
+   @result       mask: cube of the same size as combinedCube
+                       containing 0 for blank (ZERO pixels) and
+                       the summed integration times for overlapping regions
+   @doc                merges jittered data cubes to one bigger cube
+                       by averaging the overlap regions weighted by
+                       the integration times. The x, y size of the final data
+                       cube is user given, and should be between 32 and 64
+                       pixels, while the relative pixel-offset (sub-pixel
+                       accuracy) of the single cubes with respect to the
+                       first cube in the list is read from the SEQ CUMOFFSETX,Y
+                       fits header keyword.
+ */
+
+int
+new_combine_jittered_cubes_sky_range2 (cpl_imagelist ** cubes,
+                   cpl_imagelist  * mergedCube,
+                   cpl_imagelist  * mask,
+                   cpl_imagelist  * mergedSky,
+                   cpl_imagelist  * mergedMsk,
+                   cpl_imagelist  * mergeMed,
+                   cpl_imagelist  * mergeAvg,
+                   cpl_imagelist  * mergeStd,
+                   cpl_imagelist  * mergeNc,
+                   int        n_cubes,
+                   float    * cumoffsetx,
+                   float    * cumoffsety,
+                   double    * exptimes,
+                   char     * kernel_type,
+                   const int z_min,
+                   const int z_max);
+
+
+/**
+   @name     sinfo_new_interpol_cube_simple()
+   @param    cube: 1 allocated cube
+   @param    badcube: bad pixel mask cube (0: bad, 1: good pixel)
+   @param    maxdist: maximal pixel distance from bad pixel
+                      to search for good pixels, don't make this
+                      value too big!
+   @return   interpolated cube, and corrected bad pixel mask cube
+   @doc      interpolates bad pixel of an object cube if a bad pixel
+             mask cube is available by using the nearest neighbors
+             in 3 dimensions.
+ */
+cpl_imagelist *
+sinfo_new_interpol_cube_simple( cpl_imagelist * cube,
+                              cpl_imagelist * badcube,
+                              int       maxdist ) ;
+
+/**
+   @name     sinfo_new_combine_cubes()
+   @param    cubes: list of jittered cubes to mosaic
+   @param    mergedCube: resulting merged cube containing the
+                                      jittered cubes
+   @param    n_cubes: number of cubes in the list to merge
+   @param    cumoffsetx: array of relative x pixel offsets with respect to
+                         the first frame in the same sequence as the cube list.
+   @param    cumoffsety: array of relative y pixel offsets with respect to
+                         the first frame in the same sequence as the cube list.
+   @param    factor:     sigma factor beyond which pixels are thrown away.
+   @param    kernel_type: the name of the interpolation kernel that you want
+                          to generate using the routine
+                          sinfo_generate_interpolation_kernel()
+                          Supported kernels are:
+                                     NULL:      default kernel, currently tanh
+                                     "default": dito
+                                     "tanh":    Hyperbolic tangent
+                                     "sinc2":   Square sinc
+                                     "lanczos": Lanczos2 kernel
+                                     "hamming": Hamming kernel
+                                     "hann":    Hann kernel
+   @return mask: cube of the same size as combinedCube
+                              containing 0 for blank (ZERO pixels) and
+                              n used pixels for overlapping regions
+   @doc             merges jittered data cubes to one bigger cube
+                    by taking the sinfo_median in each pixel and throw away the
+                    high deviation pixels (bigger than factor * sigma)
+                    The x, y size of the final data
+                    cube is user given, and should be between 32 and 64
+                    pixels, while the relative pixel-offset (sub-pixel
+                    accuracy) of the single cubes with respect to the
+                    first cube in the list is read from the SEQ CUMOFFSETX,Y
+                    fits header keyword.
+ */
+
+cpl_imagelist *
+sinfo_new_combine_cubes ( cpl_imagelist ** cubes,
+                         cpl_imagelist  * mergedCube,
+                         int        n_cubes,
+                         float    * cumoffsetx,
+                         float    * cumoffsety,
+                         float      factor,
+                         char     * kernel_type ) ;
+
+/**
+ at name sinfo_new_bin_cube
+ at param cu input cube
+ at param xscale scale on X axis
+ at param yscale scale on Y axis
+ at param xmin   minimum X
+ at param xmax   maximum X
+ at param ymin   minimum Y
+ at param ymax   maximum Y
+
+*/
+cpl_imagelist *
+sinfo_new_bin_cube(cpl_imagelist *cu,
+                   int xscale,
+                   int yscale,
+                   int xmin,
+                   int xmax,
+                   int ymin,
+                   int ymax);
+
+/**
+ at name sinfo_new_scale_cube
+ at param cu input cube
+ at param xscale scale on X axis
+ at param yscale scale on Y axis
+ at param    kernel_type: the name of the interpolation kernel that you want
+                          to generate using the routine
+                          sinfo_generate_interpolation_kernel()
+                          Supported kernels are:
+                                     NULL:      default kernel, currently tanh
+                                     "default": dito
+                                     "tanh":    Hyperbolic tangent
+                                     "sinc2":   Square sinc
+                                     "lanczos": Lanczos2 kernel
+                                     "hamming": Hamming kernel
+                                     "hann":    Hann kernel
+
+*/
+
+cpl_imagelist *
+sinfo_new_scale_cube(cpl_imagelist *cu,
+                     float xscale,
+                     float yscale,
+                     char * kernel_type);
+
+
+/**
+ @short shifts an imagelist by a given amount to integer pixel accuracy
+ @name sinfo_cube_zshift
+ @param cube  input cube to be shifted
+ @param shift amount of z shift to be applied
+ @param rest  amout of fractional shift remaining (<1)
+
+*/
+
+cpl_imagelist *
+sinfo_cube_zshift(const cpl_imagelist * cube,
+                  const double shift,
+                  double* rest);
+
+/**
+ @short shifts an imagelist by a given amount to sub-pixel accuracy
+ @name sinfo_cube_zshift
+ @param cube  input cube to be shifted
+ @param shift amount of z shift to be applied
+ @param order polynomial order
+
+*/
+
+cpl_imagelist *
+sinfo_cube_zshift_poly(const cpl_imagelist * cube,
+                       const double shift,
+                       const int    order);
+
+/**
+ @short shifts an imagelist by a given amount to sub-pixel accuracy
+ @name sinfo_cube_zshift
+ @param cube  input cube to be shifted
+ @param shift amount of z shift to be applied
+
+*/
+
+cpl_imagelist *
+sinfo_cube_zshift_spline3(const cpl_imagelist * cube,
+                          const double shift);
+
+
+int
+sinfo_coadd_with_ks_clip_optimized(const int z_min,
+			const int z_max,
+			const int n_cubes,
+			const double kappa,
+			int* llx,
+			int* lly,
+                        double* exptimes,
+			cpl_imagelist* mask,
+			cpl_imagelist* mergedCube,
+                        cpl_imagelist** tmpcubes);
+
+double kappa_sigma_array_with_mask(
+		cpl_array* parray,
+		int szArray,
+		const double kappa,
+		cpl_image* imMask,
+		double* exptimes,
+		int x, int y, double mas_adjustment
+		/*, double* val_msk_sum*/);
+#endif /*!SINFO_NEW_CUBE_OPS_H*/
+
+
+
+/*--------------------------------------------------------------------------*/
diff --git a/sinfoni/sinfo_new_cubes_build.c b/sinfoni/sinfo_new_cubes_build.c
new file mode 100644
index 0000000..1b43d13
--- /dev/null
+++ b/sinfoni/sinfo_new_cubes_build.c
@@ -0,0 +1,922 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+
+File name    :       sinfo_new_cubes_build.c
+Author       :    J. Schreiber
+Created on   :    December 3, 2003
+Description  :    Creates data cubes or merges data cubes
+out of jittered object-sky
+nodding observations
+---------------------------------------------------------------------------*/
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+/*----------------------------------------------------------------------------
+  Includes
+  ---------------------------------------------------------------------------*/
+#include "sinfo_new_cubes_build.h"
+#include "sinfo_pfits.h"
+#include "sinfo_msg.h"
+#include "sinfo_pro_save.h"
+#include "sinfo_objnod_ini_by_cpl.h"
+#include "sinfo_functions.h"
+#include "sinfo_hidden.h"
+#include "sinfo_utilities_scired.h"
+#include "sinfo_wave_calibration.h"
+#include "sinfo_cube_construct.h"
+#include "sinfo_skycor.h"
+#include "sinfo_product_config.h"
+#include "sinfo_error.h"
+#include "sinfo_utils_wrappers.h"
+#include "sinfo_atmo_disp.h"
+/*----------------------------------------------------------------------------
+  Defines
+  ---------------------------------------------------------------------------*/
+#define PI_NUMB        (3.1415926535897932384626433832795) /* pi */
+
+
+static void sinfo_atm_correction(cpl_imagelist** ppCube,
+		cpl_frameset* sof,
+		const char* polyshiftname,
+		double dis_cube,
+		double centralLambda_cube,
+		int centralpix_cube);
+
+/*----------------------------------------------------------------------------
+  Function Definitions
+  ---------------------------------------------------------------------------*/
+/* Temporally commented out as not used
+static cpl_image*
+sinfo_flux_corr(const cpl_image* inp,const cpl_image* wav,const double dis);
+*/
+/**@{*/
+/**
+ * @addtogroup sinfo_rec_jitter Cube construction
+ *
+ * TBD
+ */
+
+
+/*----------------------------------------------------------------------------
+  Function     : sinfo_new_cubes_build()
+  In           : ini_file: file name of according .ini file
+  Out          : integer (0 if it worked, -1 if it doesn't)
+  Job          : this routine carries through the data cube creation of an
+  object science observation using object-sky nodding
+  and jittering. This script expects jittered frames that
+  were already sky-subtracted
+  averaged, flatfielded, spectral tilt corrected and
+  interleaved if necessary
+  ---------------------------------------------------------------------------*/
+int sinfo_new_cubes_build (const char* plugin_id,cpl_parameterlist* config,
+			   cpl_frameset* sof, const char* procatg, const int frame_index)
+{
+
+  object_config * cfg=NULL ;
+  cpl_image * im=NULL ;
+  cpl_image * wavemapim=NULL ;
+  cpl_image * wim=NULL ;
+  cpl_image * res_obj=NULL ;
+  cpl_image * calim=NULL ;
+  cpl_image * halospec=NULL ;
+  cpl_image * sky_im=NULL;
+  cpl_image* res_ima=NULL;
+  cpl_image* res_wim=NULL;
+  cpl_image* res_flat=NULL;
+  cpl_image* res_sky=NULL;
+  cpl_image* flat_im=NULL;
+  cpl_image* eima_avg=NULL;
+  cpl_image* eima_med=NULL;
+  cpl_imagelist  * cube=NULL ;
+  cpl_imagelist  * outcube=NULL ;
+  cpl_imagelist  * outcube2=NULL ;
+  cpl_imagelist* cflat=NULL;
+  cpl_imagelist* cflat2=NULL;
+  cpl_imagelist* csky=NULL;
+  cpl_imagelist* csky2=NULL;
+  cpl_propertylist* plist=NULL;
+  cpl_frame* obj_frm=NULL;
+  cpl_frame* sky_frm=NULL;
+  cpl_imagelist* obj_cor=NULL;
+
+  int sky_cor=0;
+  int flux_cor=0;
+  int n=0 ;
+  int cpix=0 ;
+  float mi=0 ;
+  float ma=0 ;
+  float fcol=0 ;
+  float center_x=0;
+  float center_y=0;
+  float *  correct_dist=NULL ;
+  float * distances=NULL ;
+  float ** slit_edges=NULL ;
+  int nx=0;
+  int ny=0;
+  cpl_image* dif=NULL;
+  float* pd=NULL;
+  float* pw=NULL;
+  int i=0;
+  int j=0;
+
+  double dis=0 ;
+  double cwav=0 ;
+
+  char pro_mjit[MAX_NAME_SIZE];
+  char pro_obs[MAX_NAME_SIZE];
+  char pro_med[MAX_NAME_SIZE];
+
+
+  char * name=NULL ;
+  char file_name[FILE_NAME_SZ];
+
+  cpl_table* qclog_tbl=NULL;
+  cpl_frameset* stk=NULL;
+  cpl_parameter* p=NULL;
+  int pdensity=0;
+  sinfo_skycor_qc* sqc=NULL;
+  cpl_table* int_obj=NULL;
+
+  check_nomsg(p=cpl_parameterlist_find(config,"sinfoni.product.density"));
+  check_nomsg(pdensity=cpl_parameter_get_int(p));
+
+  if (strcmp(procatg,PRO_COADD_STD) == 0) {
+    strcpy(pro_mjit,PRO_MASK_COADD_STD);
+    strcpy(pro_obs,PRO_OBS_STD);
+    strcpy(pro_med,PRO_MED_COADD_STD);
+
+  } else if (strcmp(procatg,PRO_COADD_PSF) == 0) {
+    strcpy(pro_mjit,PRO_MASK_COADD_PSF);
+    strcpy(pro_obs,PRO_OBS_PSF);
+    strcpy(pro_med,PRO_MED_COADD_PSF);
+  } else {
+    strcpy(pro_mjit,PRO_MASK_COADD_OBJ);
+    strcpy(pro_obs,PRO_OBS_OBJ);
+    strcpy(pro_med,PRO_MED_COADD_OBJ);
+  }
+
+
+  /*----parse input data and parameters to set cube_config cfg---*/
+  check_nomsg(stk = cpl_frameset_new());
+
+  cknull(cfg = sinfo_parse_cpl_input_objnod(config,sof,&stk),
+	 "Error setting parameter configuration");
+
+  ck0(sinfo_check_input_data(cfg),"error checking input");
+
+
+  check_nomsg(p=cpl_parameterlist_find(config,"sinfoni.objnod.fcol"));
+  check_nomsg(fcol=(float)cpl_parameter_get_double(p));
+
+  for ( n = 0 ; n < cfg->nframes ; n++ )
+    {
+
+      sinfo_msg_debug("Read FITS information");
+      name = cfg->framelist[n] ;
+      if( sinfo_is_fits_file(name) != 1) {
+	sinfo_msg_error("Input file %s is not FITS",name);
+	goto cleanup;
+      }
+
+
+      sinfo_msg_debug("frame no.: %d, name: %s\n", n, name) ;
+      cknull(im = cpl_image_load(name,CPL_TYPE_FLOAT,0,0),
+	     " could not load frame %s!",name) ;
+
+
+      /*
+       *--------------------------------------------------------------
+       *---------------------RESAMPLING-------------------------------
+       *--------------------------------------------------------------
+       */
+      sinfo_msg("Resampling object");
+      cknull(wavemapim = cpl_image_load(cfg->wavemap,CPL_TYPE_FLOAT,0,0),
+	     "could not load wavemap");
+      check_nomsg(wim=cpl_image_duplicate(wavemapim));
+
+      check_nomsg(p=cpl_parameterlist_find(config,
+					   "sinfoni.objnod.flux_cor"));
+      check_nomsg(flux_cor=cpl_parameter_get_bool(p));
+
+
+      nx=cpl_image_get_size_x(wim);
+      ny=cpl_image_get_size_y(wim);
+      /*
+        check_nomsg(pd=cpl_image_get_data(im));
+        //To compare statistics we make sure that the input image has all 1s
+
+	for(i=0;i<nx;i++) {
+	for(j=0;j<ny;j++) {
+	pd[nx*j+i]=1.;
+	}
+	}
+	cpl_image_save(im,"im.fits", CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT);
+      */
+
+      cknull(res_ima = sinfo_new_defined_resampling(im,
+						    wim,
+						    cfg->ncoeffs,
+						    &cfg->nrows,
+						    &dis,
+						    &mi,
+						    &ma,
+						    &cwav,
+						    &cpix),
+	     " sinfo_definedResampling() failed" ) ;
+
+
+
+      //cpl_image_save(res_ima,"res_im.fits",
+      //CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT);
+
+      //We create an image with the derivatives
+      check_nomsg(dif=cpl_image_new(nx,ny,CPL_TYPE_FLOAT));
+      pw=cpl_image_get_data(wim);
+      pd=cpl_image_get_data(dif);
+
+
+      for(i=1;i<nx-1;i++) {
+	for(j=1;j<ny-1;j++) {
+	  if(!isnan(pd[nx*j+i])) {
+	    pd[nx*j+i]=2.0*dis/(pw[nx*(j+1)+i]-pw[nx*(j-1)+i]);
+	  }
+	}
+	if(!isnan(pd[i])) {
+	  pd[i]=dis/(pw[nx+i]-pw[i]);
+	}
+	if(!isnan(pd[nx*(ny-1)+i])) {
+	  pd[nx*(ny-1)+i]=dis/(pw[nx*(ny-1)+i]-pw[nx*(ny-2)+i]);
+	}
+      }
+
+
+      //cpl_image_save(dif,"diff.fits",
+      //CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT);
+
+
+
+      cknull(res_wim = sinfo_new_defined_resampling(dif,
+						    wim,
+						    cfg->ncoeffs,
+						    &cfg->nrows,
+						    &dis,
+						    &mi,
+						    &ma,
+						    &cwav,
+						    &cpix),
+	     " sinfo_definedResampling() failed" ) ;
+
+
+
+      //cpl_image_save(res_wim,"res_diff.fits",
+      //CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT);
+
+
+
+
+
+      //To rescale in flux we divide the resampled image and
+      //the resampled derivatives. At this point res_obj should have same
+      //flux as input image (im.diff)
+
+      res_obj=cpl_image_duplicate(res_ima);
+      sinfo_free_image(&res_ima);
+      if(flux_cor) {
+	sinfo_msg("Apply flux correction");
+	cpl_image_divide(res_obj,res_wim);
+      }
+      //cpl_image_save(res_obj,"res_obj.fits",
+      //CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT);
+
+
+      sinfo_free_image(&wim);
+
+      if((pdensity == 3) || (pdensity == 2 && frame_index == 0)) {
+	snprintf(file_name,MAX_NAME_SIZE-1,"%s%d%s",
+		 RESAMPLED_OUT_OBJ_FILENAME,
+		 frame_index,".fits");
+	ck0(sinfo_pro_save_ima(res_obj,sof,sof,file_name,
+			       PRO_RESAMPLED_OBJ,
+                               qclog_tbl,plugin_id,config),
+	    "cannot save image %s", file_name);
+      }
+
+
+      if(strcmp(cfg->sky_dist,"no_sky")!=0) {
+	sinfo_msg("Resampling sky");
+	check_nomsg(sky_im=cpl_image_load(cfg->sky_dist,CPL_TYPE_FLOAT,0,0));
+	check_nomsg(wim=cpl_image_duplicate(wavemapim));
+	cknull(res_ima = sinfo_new_defined_resampling(sky_im,
+						      wim,
+						      cfg->ncoeffs,
+						      &cfg->nrows,
+						      &dis,
+						      &mi,
+						      &ma,
+						      &cwav,
+						      &cpix),
+	       " sinfo_definedResampling() failed" );
+        res_sky=cpl_image_duplicate(res_ima);
+        sinfo_free_image(&res_ima);
+        if(flux_cor) {
+          sinfo_msg("Apply flux correction");
+	  cpl_image_divide(res_sky,res_wim);
+	}
+
+	sinfo_free_image(&wim);
+	sinfo_free_image(&sky_im) ;
+	if((pdensity == 3) || (pdensity == 2 && frame_index == 0)){
+
+	  snprintf(file_name,MAX_NAME_SIZE-1,"%s%d%s",
+		   RESAMPLED_OUT_SKY_FILENAME,frame_index,".fits");
+	  ck0(sinfo_pro_save_ima(res_sky,sof,sof,file_name,
+				 PRO_RESAMPLED_SKY,
+				 qclog_tbl,plugin_id,config),
+	      "cannot save image %s", file_name);
+	}
+
+
+
+      }
+
+
+      if(n ==0) {
+	if(strcmp(cfg->mflat_dist,"not_found") != 0) {
+	  sinfo_msg("Resampling master flat");
+	  cknull(flat_im=cpl_image_load(cfg->mflat_dist,CPL_TYPE_FLOAT,0,0),
+		 "Distorted master flat field not found\n"
+		 "You may have set --stack-flat_ind=FALSE\n"
+		 "Flat field resampling skipped");
+	  check_nomsg(wim=cpl_image_duplicate(wavemapim));
+	  cknull(res_ima = sinfo_new_defined_resampling(flat_im,
+							wim,
+							cfg->ncoeffs,
+							&cfg->nrows,
+							&dis,
+							&mi,
+							&ma,
+							&cwav,
+							&cpix),
+		 " sinfo_definedResampling() failed" ) ;
+
+
+	  res_flat=cpl_image_duplicate(res_ima);
+	  sinfo_free_image(&res_ima);
+	  if(flux_cor) {
+	    sinfo_msg("Apply flux correction");
+	    cpl_image_divide(res_flat,res_wim);
+	  }
+	  sinfo_free_image(&wim);
+	  sinfo_free_image(&flat_im) ;
+	  if((pdensity == 3) || (pdensity == 2 && frame_index == 0)) {
+	    snprintf(file_name,MAX_NAME_SIZE-1,"%s%d%s",
+		     RESAMPLED_OUT_FLAT_FILENAME,frame_index,".fits");
+	    ck0(sinfo_pro_save_ima(res_flat,sof,sof,file_name,
+				   PRO_RESAMPLED_FLAT_LAMP,
+				   qclog_tbl,plugin_id,config),
+		"cannot save image %s", file_name);
+	  }
+
+
+	}
+
+      }
+
+      sinfo_msg("wmin %f wmax %f wcent %f wstep %f cpix %d",
+		mi,ma,cwav,dis,cpix);
+      sinfo_free_image(&res_wim);
+      sinfo_free_image(&im) ;
+      sinfo_free_image(&wavemapim) ;
+
+      /*
+       *-------------------------------------------------------------------
+       *----------------Calibration----------------------------------------
+       *-------------------------------------------------------------------
+       */
+      /*----Multiply with calibrated halogen lamp spectrum----*/
+      if (cfg->halocorrectInd == 1)
+        {
+	  sinfo_msg("Calibration");
+	  check_nomsg(halospec = cpl_image_load(cfg->halospectrum,
+                                                CPL_TYPE_FLOAT,0,0)) ;
+
+	  cknull(calim = sinfo_new_multiply_image_with_spectrum(res_obj,
+                                                                halospec),
+		 " sinfo_new_multiply_image_with_spectrum() failed" ) ;
+
+	  sinfo_free_image(&halospec) ;
+	  sinfo_free_image(&res_obj) ;
+	  res_obj = cpl_image_duplicate(calim) ;
+	  sinfo_free_image(&calim);
+        }
+
+      /*
+       *-------------------------------------------------------------------
+       *------------------CUBECREATION-------------------------------------
+       *-------------------------------------------------------------------
+       */
+      sinfo_msg("Cube creation");
+      /*---select north-south-test or fitting of slitlet edges--*/
+      if (cfg->northsouthInd == 0) {
+	sinfo_msg("cfg->northsouthInd == 0");
+	cknull(slit_edges=sinfo_read_slitlets_edges(cfg->nslits,cfg->poslist),
+	       "error reading slitlets edges");
+      } else {
+	sinfo_msg("cfg->northsouthInd != 0");
+	cknull(distances = sinfo_read_distances(cfg->nslits,cfg->distlist),
+	       "error reading distances");
+      }
+
+      cknull(correct_dist = (float*) cpl_calloc(cfg->nslits, sizeof (float)),
+	     " could not allocate memory!") ;
+
+      sinfo_msg("Create cube object");
+      if (cfg->northsouthInd ==0 ) {
+
+        cknull(cube = sinfo_new_make_cube_spi(res_obj,slit_edges,
+					      correct_dist),
+	       "could not construct data cube!") ;
+
+      }  else {
+	cknull(cube = sinfo_new_make_cube_dist(res_obj,fcol,distances,
+					       correct_dist),
+	       "could not construct a data cube!") ;
+      }
+      sinfo_free_image(&res_obj);
+
+
+      if(strcmp(cfg->sky_dist,"no_sky")!=0) {
+
+        sinfo_msg("Create cube sky");
+        if (cfg->northsouthInd ==0 ) {
+          cknull(csky = sinfo_new_make_cube_spi(res_sky,slit_edges,
+						correct_dist),
+		 "could not construct data cube!") ;
+        }  else {
+          cknull(csky = sinfo_new_make_cube_dist(res_sky,fcol,distances,
+						 correct_dist),
+		 "could not construct a data cube!") ;
+        }
+        sinfo_free_image(&res_sky);
+      }
+
+      if(n==0) {
+	if(strcmp(cfg->mflat_dist,"not_found")!=0) {
+	  sinfo_msg("Create cube master flat");
+	  if (cfg->northsouthInd ==0 ) {
+	    cknull(cflat=sinfo_new_make_cube_spi(res_flat,slit_edges,
+						 correct_dist),
+		   "could not construct data cube!") ;
+	  }  else {
+	    cknull(cflat = sinfo_new_make_cube_dist(res_flat,fcol,distances,
+						    correct_dist),
+		   "could not construct a data cube!") ;
+	  }
+	  sinfo_free_image(&res_flat);
+	}
+      }
+
+      if (cfg->northsouthInd ==0 )
+	{
+	  sinfo_new_destroy_2Dfloatarray(&slit_edges,cfg->nslits);
+	}
+      else
+	{
+	  sinfo_new_destroy_array(&distances);
+	}
+
+      /*
+       *--------------------------------------------------------------------
+       *------------------------FINETUNING----------------------------------
+       *--------------------------------------------------------------------
+       * shift the rows of the reconstructed images of the data cube to the
+       * correct sub pixel position select the shift method: polynomial
+       * interpolation, FFT or cubic spline interpolation
+       *--------------------------------------------------------------------
+       */
+
+      if(strcmp(cfg->sky_dist,"no_sky")!=0) {
+	if(pdensity > 0) {
+	  cknull(csky2=sinfo_new_fine_tune(csky,
+					   correct_dist,
+					   cfg->method,
+					   cfg->order,
+					   cfg->nslits),
+		 " could not fine tune the data cube") ;
+
+	  sinfo_free_imagelist(&csky);
+	  sinfo_msg("Stretch output cube along Y direction");
+
+	  cknull(csky = sinfo_new_bin_cube(csky2,1,2,0,63,0,63),
+		 "error rebinning sky cube");
+	  sinfo_free_imagelist(&csky2);
+
+
+
+	  snprintf(file_name,MAX_NAME_SIZE-1,"%s%2.2d%s","out_sky_cube",
+		   frame_index,".fits");
+	  ck0(sinfo_pro_save_ims(csky,sof,sof,file_name,
+				 PRO_OBS_SKY,NULL,plugin_id,config),
+	      "cannot dump cube %s", file_name);
+	  cknull(eima_med=sinfo_new_median_cube(csky),
+		 "Creating an average image");
+	  check_nomsg(center_x = cpl_image_get_size_x(eima_med)/ 2. + 0.5);
+	  check_nomsg(center_y = cpl_image_get_size_y(eima_med)/ 2. + 0.5);
+
+	  sinfo_new_set_wcs_cube(csky,file_name, cwav,
+				 dis, cpix, center_x, center_y);
+
+	  sinfo_free_imagelist(&csky) ;
+
+	  snprintf(file_name,MAX_NAME_SIZE-1,"%s%2.2d%s","out_sky_med",
+		   frame_index,".fits");
+	  ck0(sinfo_pro_save_ima(eima_med,sof,sof,file_name,
+				 PRO_SKY_MED,NULL,plugin_id,config),
+	      "cannot save ima %s",file_name);
+
+	  check_nomsg(sinfo_new_set_wcs_image(eima_med,file_name, center_x, center_y));
+	  sinfo_free_image(&eima_med);
+	}
+      }
+
+
+
+      if(n==0) {
+	if(strcmp(cfg->mflat_dist,"not_found")!=0) {
+	  if(pdensity > 1) {
+	    cknull(cflat2=sinfo_new_fine_tune(cflat,
+					      correct_dist,
+					      cfg->method,
+					      cfg->order,
+					      cfg->nslits),
+		   " could not fine tune the data cube") ;
+
+	    sinfo_free_imagelist(&cflat);
+	    sinfo_msg("Stretch output cube along Y direction");
+
+	    cknull(cflat = sinfo_new_bin_cube(cflat2,1,2,0,63,0,63),
+		   "Error binning flat cube");
+	    sinfo_free_imagelist(&cflat2);
+
+	    ck0(sinfo_pro_save_ims(cflat,sof,sof,OBJNOD_OUT_MFLAT_CUBE_FILENAME,
+				   PRO_MFLAT_CUBE,NULL,plugin_id,config),
+		"cannot save cube %s", OBJNOD_OUT_MFLAT_CUBE_FILENAME);
+
+	    sinfo_new_set_wcs_cube(cflat,OBJNOD_OUT_MFLAT_CUBE_FILENAME,cwav, dis,
+				   cpix, center_x, center_y);
+
+	    cknull(eima_avg=sinfo_new_average_cube_to_image(cflat),
+		   "Creating an average image");
+
+	    ck0(sinfo_pro_save_ima(eima_avg,sof,sof,"out_mflat_avg.fits",
+				   "MFLAT_AVG",NULL,plugin_id,config),
+		"cannot save ima %s", "out_mflat_avg.fits");
+
+	    sinfo_free_image(&eima_avg);
+
+	    cknull(eima_med=sinfo_new_median_cube(cflat),
+		   "Error computing median on cube flat");
+
+	    ck0(sinfo_pro_save_ima(eima_med,sof,sof,"out_mflat_med.fits",
+				   "MFLAT_MED",NULL,plugin_id,config),
+		"cannot save ima %s", "out_mflat_med.fits");
+
+	    sinfo_free_imagelist(&cflat);
+	    sinfo_free_image(&eima_med);
+	  }
+	}
+      }
+
+      cknull(outcube2=sinfo_new_fine_tune(cube,
+					  correct_dist,
+					  cfg->method,
+					  cfg->order,
+					  cfg->nslits),
+	     " could not fine tune the data cube") ;
+
+      sinfo_msg("Stretch output cube along Y direction");
+      cknull(outcube = sinfo_new_bin_cube(outcube2,1,2,0,63,0,63),
+	     "Error binning cube");
+      sinfo_free_imagelist(&cube);
+      cknull_nomsg(qclog_tbl=sinfo_qclog_init());
+      sinfo_get_pupil_shift(outcube,n,&qclog_tbl);
+      snprintf(file_name,MAX_NAME_SIZE-1,"%s%2.2d%s","out_cube_obj",
+	       frame_index,".fits");
+
+      check_nomsg(center_x = cpl_image_get_size_x(
+						  cpl_imagelist_get(outcube,0))/2.+0.5) ;
+      check_nomsg(center_y = cpl_image_get_size_y(
+						  cpl_imagelist_get(outcube,0))/2.+0.5 );
+
+      /*----------- atmospheric correction --------------*/
+      if (cfg->polyshiftname && strlen(cfg->polyshiftname))
+      {
+    	  sinfo_atm_correction(&outcube,
+    	  		sof,
+    	  		cfg->polyshiftname,
+    	  		dis,
+    	  		cwav,
+    	  		cpix);
+      }
+      /*-------------------------------------------------*/
+
+      ck0(sinfo_pro_save_ims(outcube,sof,sof,file_name,
+			     pro_obs,qclog_tbl,plugin_id,config),
+	  "cannot save cube %s", file_name);
+
+      sinfo_new_set_wcs_cube(outcube, file_name, cwav, dis,
+			     cpix, center_x, center_y);
+      /* free memory */
+      /* to prevent error message comment next line */
+
+      check_nomsg(p=cpl_parameterlist_find(config,
+					   "sinfoni.objnod.sky_cor"));
+
+      check_nomsg(sky_cor=cpl_parameter_get_bool(p));
+      if(sky_cor == 1 && (pdensity == 1 || pdensity == 3) &&
+    		  strcmp(cfg->sky_dist,"no_sky")!=0)
+      {
+		obj_frm=cpl_frameset_find(sof,pro_obs);
+		sky_frm=cpl_frameset_find(sof,PRO_OBS_SKY);
+		sqc=sinfo_skycor_qc_new();
+		ck0(sinfo_skycor(config, obj_frm,sky_frm,sqc,&obj_cor,&int_obj),
+			"determining sky residuals corrected object");
+		cpl_frameset_erase(sof,pro_obs);
+		snprintf(file_name,MAX_NAME_SIZE-1,"%s%2.2d%s","out_cube_obj_cor",
+			 frame_index,".fits");
+		ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC SKYCOR THBKGFIT",
+						  sqc->th_fit,"Thermal background fit success","%d"));
+
+		ck0(sinfo_pro_save_ims(obj_cor,sof,sof,file_name,
+			       pro_obs,qclog_tbl,plugin_id,config),
+	    "cannot save cube %s", file_name);
+
+		sinfo_skycor_qc_delete(&sqc);
+
+        sinfo_new_set_wcs_cube(obj_cor, file_name, cwav, dis,
+			       cpix, center_x, center_y);
+
+        sinfo_free_imagelist(&obj_cor) ;
+        snprintf(file_name,MAX_NAME_SIZE-1,"%s%2.2d%s","out_int_obj",
+		 frame_index,".fits");
+
+        ck0(sinfo_pro_save_tbl(int_obj,sof,sof,file_name,
+			       PRO_SPECTRA_QC,qclog_tbl,plugin_id,config),
+	    "cannot save cube %s", file_name);
+		sinfo_free_table(&int_obj) ;
+      }
+      sinfo_free_table(&qclog_tbl);
+      sinfo_free_imagelist(&outcube2);
+      sinfo_free_imagelist(&outcube) ;
+      sinfo_free_float(&correct_dist) ;
+
+    } /* end loop over n (nframes) */
+
+  /* free memory */
+  sinfo_objnod_free(&cfg);
+  sinfo_free_frameset(&stk);
+
+
+  return 0;
+
+ cleanup:
+  sinfo_skycor_qc_delete(&sqc);
+  sinfo_free_imagelist(&obj_cor) ;
+  sinfo_free_propertylist(&plist);
+  sinfo_free_imagelist(&outcube2) ;
+  sinfo_free_imagelist(&outcube) ;
+  sinfo_free_table(&qclog_tbl);
+  sinfo_free_image(&eima_avg);
+  sinfo_free_image(&eima_med);
+  sinfo_free_imagelist(&cflat) ;
+  sinfo_free_imagelist(&cflat2) ;
+  sinfo_free_imagelist(&cube) ;
+  sinfo_free_imagelist(&csky) ;
+  sinfo_free_imagelist(&csky2) ;
+
+  if(cfg!=NULL) {
+    if (cfg->northsouthInd ==0 ) {
+      if(slit_edges != NULL) {
+	sinfo_new_destroy_2Dfloatarray(&slit_edges,cfg->nslits);
+      }
+    } else {
+      if (distances != NULL ) {
+	sinfo_new_destroy_array(&distances);
+      }
+    }
+  }
+
+  sinfo_free_float(&correct_dist);
+  sinfo_free_image(&res_flat);
+  sinfo_free_image(&res_sky);
+  sinfo_free_image(&res_wim);
+  sinfo_free_image(&calim);
+  sinfo_free_image(&halospec) ;
+  sinfo_free_image(&sky_im) ;
+  sinfo_free_image(&res_obj);
+  sinfo_free_image(&flat_im) ;
+  sinfo_free_image(&wavemapim);
+  sinfo_free_image(&wim);
+  sinfo_free_image(&im);
+  sinfo_objnod_free(&cfg);
+  sinfo_free_frameset(&stk);
+
+  return -1;
+
+
+
+}
+
+static void 
+sinfo_atm_correction(cpl_imagelist** ppCube,
+		cpl_frameset* sof,
+		const char* polyshiftname,
+		double dis_cube,
+		double centralLambda_cube,
+		int centralpix_cube)
+{
+	cpl_polynomial* poly = NULL;
+	cpl_frame* first_frame=NULL;
+	const char* ref_file=NULL;
+	cpl_propertylist *plist_cube = NULL;
+	cpl_propertylist* ppolylist = NULL;
+	cpl_imagelist* retcube = NULL;
+
+        /* we use the pointer outcube as a handle to  *ppCube 
+             (don't initialize to NULL!)*/
+	cpl_imagelist* outcube = *ppCube; 
+	   /* Get the reference file  */
+	first_frame = cpl_frameset_get_first(sof) ;
+	ref_file = cpl_frame_get_filename(first_frame) ;
+	if (ref_file && strlen(ref_file))
+	{
+		/* Get FITS header from reference file */
+		sinfo_msg_warning("adjusting atmospheric correction ref_file[%s]", ref_file);
+		plist_cube = cpl_propertylist_load(ref_file, 0);
+		if (plist_cube)
+		{
+			  // check the OPTI1.NAME
+		        ppolylist = cpl_propertylist_load(polyshiftname,0);
+			if (ppolylist)
+			{
+				double pixelscale = sinfo_pfits_get_pixscale(plist_cube);
+				double poly_pixelscale = sinfo_pfits_get_pixscale(ppolylist);
+				if (fabs(poly_pixelscale - pixelscale) < 1E-8)
+				{
+					poly = sinfo_atmo_load_polynom(polyshiftname);
+					if (!poly)
+					{
+						sinfo_msg_warning("Cannot load polynom from [%s]", polyshiftname);
+					}
+					else
+					{
+						sinfo_msg_warning("polynom from [%s] is loaded", polyshiftname);
+					}
+				}
+				else
+				{
+					sinfo_msg_warning("pixelscale for the polynomial fit "
+							"is different: provided[%f] expected[%f]",
+							poly_pixelscale, pixelscale);
+				}
+				sinfo_free_propertylist(&ppolylist);
+			}
+			if (!poly)
+			{
+				sinfo_msg_warning("Pixel shift due atmospheric refraction"
+					  " would not be applied");
+			}
+		}
+		else
+		{
+			sinfo_msg_warning("cannot load propertylist for the frame");
+		}
+		if (poly)
+		{
+			double airmass = (
+		    	  (cpl_propertylist_get_double(plist_cube, "ESO TEL AIRM START") +
+		    	  cpl_propertylist_get_double(plist_cube, "ESO TEL AIRM END"))
+		    	  / 2
+		    	  );
+			double angle = (
+		    	  (cpl_propertylist_get_double(plist_cube, "ESO ADA ABSROT START") +
+		    	  cpl_propertylist_get_double(plist_cube, "ESO ADA ABSROT END"))
+		    	  / 2
+		    	  ) * PI_NUMB / 180;
+			sinfo_msg("dis_cube[%f] centralLambda_cube[%f] centralpix_cube[%d]",dis_cube,centralLambda_cube,centralpix_cube);
+			retcube = sinfo_atmo_apply_cube_polynomial_shift(
+					poly, outcube,
+					centralLambda_cube,
+					airmass,
+					angle,
+					dis_cube,
+					centralpix_cube);
+		 sinfo_free_polynomial(&poly);
+		 if (retcube)
+		 {
+			 sinfo_free_imagelist(&outcube);
+			 *ppCube = retcube;
+		 }
+	  }
+	  sinfo_free_propertylist(&plist_cube);
+	}
+
+
+	return;
+}
+
+/* Temporally commented out as not yet used
+static cpl_image*
+sinfo_flux_corr(const cpl_image* inp,const cpl_image* wav,const double dis)
+{
+
+  cpl_image* out=NULL;
+  cpl_image* dif=NULL;
+  const float* pi=NULL;
+  const float* pw=NULL;
+  float* po=NULL;
+  float* pd=NULL;
+
+  int i=0;
+  int j=0;
+  int nx=0;
+  int ny=0;
+  int stat=0;
+  nx=cpl_image_get_size_x(inp);
+  ny=cpl_image_get_size_y(inp);
+
+  out=cpl_image_new(nx,ny,CPL_TYPE_FLOAT);
+  dif=cpl_image_new(nx,ny,CPL_TYPE_FLOAT);
+  pi=cpl_image_get_data_const(inp);
+  pw=cpl_image_get_data_const(wav);
+  po=cpl_image_get_data(out);
+  pd=cpl_image_get_data(dif);
+
+  sinfo_msg("dif=%10.8f",2.*dis/(cpl_image_get(wav,500,501,&stat)-
+				 cpl_image_get(wav,500,499,&stat)));
+
+  sinfo_msg("dif=%10.8f",2.*dis/(cpl_image_get(wav,500,101,&stat)-
+				 cpl_image_get(wav,500,99,&stat)));
+
+  sinfo_msg("dif=%10.8f",2.*dis/(cpl_image_get(wav,500,1001,&stat)-
+				 cpl_image_get(wav,500,999,&stat)));
+
+  for(i=0;i<nx;i++) {
+    for(j=1;j<ny-1;j++) {
+      if(pi[nx*j+i] != ZERO || pw[nx*j+i] != ZERO) {
+	po[nx*j+i]=pi[nx*j+i]*dis/((pw[nx*(j+1)+i]-pw[nx*(j-1)+i])*0.5);
+	pd[nx*j+i]=dis/((pw[nx*(j+1)+i]-pw[nx*(j-1)+i])*0.5);
+      } else {
+	po[nx*j+i]=ZERO;
+	pd[nx*j+i]=ZERO;
+      }
+    }
+
+
+    if(pi[i] != ZERO || pw[i] != ZERO) {
+      po[i]=pi[i]*dis/(pw[nx+i]-pw[i]);
+      pd[i]=dis/(pw[nx+i]-pw[i]);
+    } else {
+      po[i]=ZERO;
+      pd[i]=ZERO;
+    }
+
+
+
+    if(pi[nx*(ny-1)+i] != ZERO || pw[nx*(ny-1)+i] != ZERO) {
+      po[nx*(ny-1)+i]=pi[nx*(ny-1)+i]*dis/(pw[nx*(ny-1)+i]-pw[nx*(ny-2)+i]);
+      pd[nx*(ny-1)+i]=dis/(pw[nx*(ny-1)+i]-pw[nx*(ny-2)+i]);
+    } else {
+      po[nx*(ny-1)+i]=ZERO;
+      pd[nx*(ny-1)+i]=ZERO;
+    }
+
+  }
+  //cpl_image_save(dif,"diff.fits", CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT);
+
+  sinfo_free_image(&dif);
+
+
+  return out;
+
+}
+*/
+/**@}*/
diff --git a/sinfoni/sinfo_new_cubes_build.h b/sinfoni/sinfo_new_cubes_build.h
new file mode 100644
index 0000000..a75f25c
--- /dev/null
+++ b/sinfoni/sinfo_new_cubes_build.h
@@ -0,0 +1,76 @@
+#ifndef SINFO_NEW_CUBES_BUILD_H
+#define SINFO_NEW_CUBES_BUILD_H
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*******************************************************************************
+* E.S.O. - VLT project
+*
+* "@(#) $Id: sinfo_new_cubes_build.h,v 1.11 2007/06/06 07:10:45 amodigli Exp $"
+*
+* who       when      what
+* --------  --------  ----------------------------------------------
+* schreib  06/05/03  created
+*/
+
+/************************************************************************
+ * sinfo_cubes_build.h
+ * routines to create a data cube
+ *----------------------------------------------------------------------
+ */
+
+/*
+ * header files
+ */
+#include <math.h>
+#include <cpl.h>   
+#include "sinfo_msg.h"
+/*----------------------------------------------------------------------------
+ *                        Function ANSI C prototypes
+ *--------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+   @name sinfo_new_cubes_build()
+   @param  plugin_id name of recipe plugin
+   @param  config input parameter list
+   @param  sof input frameset
+   @param  procatg
+   @param  frame_index index of processed frame
+   @return integer (0 if it worked, -1 if it doesn't) 
+   @doc this routine does the resampling of an offset-corrected,
+        flatfielded, bad pixel corrected and
+        eventually interleaved data frame. Additionally, an intensity 
+        calibration is carried through by using
+        a standard star or a black body measurement. 
+        The spectral features of the flatfield halogen lamp are corrected.
+        Afterwards a data cube is created out of the resampled image.
+    It is the users choice to use either
+        the fitted sinfo_edge positions of the slitlets or the distances
+    of the slitlets gained from a north-south-test. 
+ ---------------------------------------------------------------------------*/
+int 
+sinfo_new_cubes_build (const char* plugin_id,
+                       cpl_parameterlist* config, 
+                       cpl_frameset* sof, 
+                       const char* procatg, 
+                       const int frame_index) ;
+
+
+#endif /*!SINFO_CUBES_BUILD_H*/
+
+/*--------------------------------------------------------------------------*/
diff --git a/sinfoni/sinfo_new_cubes_coadd.c b/sinfoni/sinfo_new_cubes_coadd.c
new file mode 100644
index 0000000..fa8d88d
--- /dev/null
+++ b/sinfoni/sinfo_new_cubes_coadd.c
@@ -0,0 +1,642 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+
+File name    :       sinfo_new_cubes_coadd.c
+Author       :    J. Schreiber
+Created on   :    December 3, 2003
+Description  :    Creates data cubes or merges data cubes
+out of jittered object-sky
+nodding observations
+---------------------------------------------------------------------------*/
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+/*----------------------------------------------------------------------------
+  Includes
+  ---------------------------------------------------------------------------*/
+#include "sinfo_new_cubes_coadd.h"
+#include "sinfo_pfits.h"
+#include "sinfo_baryvel.h"
+#include "sinfo_pro_save.h"
+#include "sinfo_objnod_ini_by_cpl.h"
+#include "sinfo_functions.h"
+#include "sinfo_utilities_scired.h"
+#include "sinfo_wave_calibration.h"
+#include "sinfo_cube_construct.h"
+#include "sinfo_error.h"
+#include "sinfo_utils_wrappers.h"
+//Used only for sinfo_propertylist_has
+#include "sinfo_dfs.h"
+/*----------------------------------------------------------------------------
+  Defines
+  ---------------------------------------------------------------------------*/
+#define PI_NUMB        (3.1415926535897932384626433832795) /* pi */
+
+
+/*----------------------------------------------------------------------------
+  Function Definitions
+  ---------------------------------------------------------------------------*/
+
+/**@{*/
+/**
+ * @addtogroup sinfo_rec_jitter Cube construction
+ *
+ * TBD
+ */
+
+
+/*----------------------------------------------------------------------------
+  Function     : sinfo_new_cubes_coadd()
+  In           : ini_file: file name of according .ini file
+  Out          : integer (0 if it worked, -1 if it doesn't)
+  Job          : this routine carries through the data cube creation of an
+  object science observation using object-sky nodding
+  and jittering. This script expects jittered frames that
+  were already sky-subtracted
+  averaged, flatfielded, spectral tilt corrected and
+  interleaved if necessary
+  ---------------------------------------------------------------------------*/
+int
+sinfo_new_cubes_coadd (const char* plugin_id,cpl_parameterlist* config,
+                       cpl_frameset* sof, const char* procatg)
+{
+
+   object_config * cfg=NULL ;
+   cpl_image * im=NULL ;
+   cpl_image* jitter_image=NULL;
+   cpl_imagelist  ** cube_tmp=NULL ;
+
+   cpl_imagelist  ** cubeobject=NULL ;
+   cpl_imagelist  * jittercube=NULL ;
+   cpl_imagelist  * maskcube=NULL ;
+   cpl_propertylist* plist=NULL;
+   int sky_cor=0;
+   int pdensity=0;
+
+   int i=0;
+   int n=0 ;
+   int partind = 0 ;
+   int centralpix=0 ;
+   int z_siz=0;
+   int z_min=0;
+   int z_max=0;
+   int z=0;
+   int z_stp=100;
+   int scales_sky=0;
+   int ks_clip=0;
+   double kappa=2.0;
+
+   float ref_offx=0;
+   float ref_offy=0;
+   float newcenter_x=0 ;
+   float newcenter_y=0 ;
+   float cd1_1=0;
+   float cd1_2=0;
+   float cd2_1=0;
+   float cd2_2=0;
+   double pixelscale=0;
+   double angle=0;
+   float radangle=0 ;
+   double exptime=0 ;
+
+   double * times=NULL ;
+   float * offsetx=NULL;
+   float * offsety=NULL;
+   float offx_min=1.e10;
+   float offy_min=1.e10;
+   float offx_max=-1.e10;
+   float offy_max=-1.e10;
+
+   double dis=0 ;
+   double centralLambda=0 ;
+   double mjd_obs=0;
+
+   char name_jitter[MAX_NAME_SIZE] ;
+   char pro_mjit[MAX_NAME_SIZE];
+   char pro_obs[MAX_NAME_SIZE];
+   char pro_med[MAX_NAME_SIZE];
+
+
+   char * name=NULL ;
+   char * partname=NULL;
+   char * partname2=NULL ;
+   char file_name[MAX_NAME_SIZE];
+   int vllx=0;
+   int vlly=0;
+   int vurx=0;
+   int vury=0;
+
+   int onp=0;
+   int j=0;
+   cpl_image* j_img=NULL;
+   cpl_image* m_img=NULL;
+   cpl_table* qclog_tbl=NULL;
+   cpl_image* ill_cor=NULL;
+   cpl_frame* frame=NULL;
+   cpl_frameset* stk=NULL;
+   cpl_parameter* p=NULL;
+   int mosaic_max_size=0;
+   double barycor=0;
+   double helicor=0;
+   cpl_table* qclog=NULL;
+
+   check_nomsg(p=cpl_parameterlist_find(config,
+                                        "sinfoni.objnod.mosaic_max_size"));
+   check_nomsg(mosaic_max_size=cpl_parameter_get_int(p));
+   check_nomsg(p=cpl_parameterlist_find(config,"sinfoni.product.density"));
+   check_nomsg(pdensity=cpl_parameter_get_int(p));
+
+   if (strcmp(procatg,PRO_COADD_STD) == 0) {
+      strcpy(pro_mjit,PRO_MASK_COADD_STD);
+      strcpy(pro_obs,PRO_OBS_STD);
+      strcpy(pro_med,PRO_MED_COADD_STD);
+
+   } else if (strcmp(procatg,PRO_COADD_PSF) == 0) {
+      strcpy(pro_mjit,PRO_MASK_COADD_PSF);
+      strcpy(pro_obs,PRO_OBS_PSF);
+      strcpy(pro_med,PRO_MED_COADD_PSF);
+   } else {
+      strcpy(pro_mjit,PRO_MASK_COADD_OBJ);
+      strcpy(pro_obs,PRO_OBS_OBJ);
+      strcpy(pro_med,PRO_MED_COADD_OBJ);
+   }
+
+   /*----parse input data and parameters to set cube_config cfg---*/
+   check_nomsg(stk = cpl_frameset_new());
+
+   cknull(cfg = sinfo_parse_cpl_input_objnod(config,sof,&stk),
+          "Error setting parameter configuration");
+
+   ck0(sinfo_check_input_data(cfg),"error checking input");
+
+   if ( cfg->jitterind == 1 )
+   {
+      cknull(times = (double*) cpl_calloc (cfg->nframes, sizeof (double)),
+             " could not allocate memory!") ;
+
+      cknull(offsetx = (float*) cpl_calloc (cfg->nframes, sizeof(float)),
+             " could not allocate memory!") ;
+
+      cknull(offsety = (float*) cpl_calloc (cfg->nframes, sizeof(float)),
+             " could not allocate memory!") ;
+   }
+
+   if (cfg->jitterind == 0)
+   {
+      if ( NULL != (partname = strtok(cfg->outName, ".")))
+      {
+         partname2 = strtok (NULL, ".") ;
+         partind = 1 ;
+      }
+   }
+
+   ck0(sinfo_auto_size_cube5(cfg,&ref_offx,&ref_offy,
+                             &offx_min,&offy_min,
+                             &offx_max,&offy_max),
+       "Error resizing cube");
+
+   if(NULL != cpl_frameset_find(sof,PRO_ILL_COR)) {
+      frame = cpl_frameset_find(sof,PRO_ILL_COR);
+      ill_cor=cpl_image_load(cpl_frame_get_filename(frame),CPL_TYPE_FLOAT,0,0);
+   } else {
+      sinfo_msg("Illumination correction image not provided");
+      cpl_error_reset();
+   }
+
+   for ( n = 0 ; n < cfg->nframes ; n++ )
+   {
+
+      sinfo_msg_debug("Read FITS information");
+      name = cfg->framelist[n] ;
+      if (n == 0)
+      {
+         strcpy (name_jitter, name) ;
+      }
+      if( sinfo_is_fits_file(name) != 1) {
+         sinfo_msg_error("Input file %s is not FITS",name);
+         goto cleanup;
+      }
+
+
+      /* get some header values and compute the CD-sinfo_matrix */
+      plist=cpl_propertylist_load(name,0);
+
+      if (sinfo_propertylist_has(plist, KEY_NAME_MJD_OBS)) {
+         mjd_obs=cpl_propertylist_get_double(plist, KEY_NAME_MJD_OBS);
+      } else {
+         sinfo_msg_error("keyword %s does not exist",KEY_NAME_MJD_OBS);
+         cpl_propertylist_delete(plist) ;
+         return -1;
+      }
+
+
+      pixelscale = sinfo_pfits_get_pixscale(plist) /2;
+      angle = sinfo_pfits_get_posangle(plist) ;
+      /* in PUPIL data there is not posangle info: we reset the error */
+      if(cpl_error_get_code() != CPL_ERROR_NONE) {
+         cpl_error_reset();
+      }
+
+      sinfo_free_propertylist(&plist);
+      // The following 5 lines are not really used here!
+      radangle = angle * PI_NUMB / 180. ;
+      cd1_1 = cos(radangle) ;
+      cd1_2 = sin(radangle) ;
+      cd2_1 = -sin(radangle) ;
+      cd2_2 = cos(radangle) ;
+
+      sinfo_msg_debug("frame no.: %d, name: %s\n", n, name) ;
+      cknull(im = cpl_image_load(name,CPL_TYPE_FLOAT,0,0),
+             " could not load frame %s!",name) ;
+
+      if (cfg->jitterind == 1)
+      {
+         exptime = sinfo_pfits_get_ditndit(name) ;
+
+         if (exptime == FLAG)
+         {
+            sinfo_msg_error("could not read fits header keyword exptime!");
+            goto cleanup;
+         }
+         times[n] = exptime ;
+
+         ck0(sinfo_new_assign_offset(n,name,offsetx,offsety,
+                                     ref_offx,ref_offy),
+             "Error assigning offsets");
+
+      }
+      sinfo_free_image(&im);
+
+   } /* end loop over n (nframes) */
+
+
+   /* leak free */
+   if(cfg->jitterind == 0) {
+      goto exit;
+   }
+
+   /* Here in case of autojitter we estimate the sky */
+   if( (cfg->size_x*cfg->size_y*cfg->nframes) > (100*mosaic_max_size) ) {
+      sinfo_msg_warning("Coadd cube size:%d,%d. N frames: %d",
+                        cfg->size_x,cfg->size_y,cfg->nframes);
+      sinfo_msg_warning("Max allowed should be such "
+                        "that sixeX*sixeY*Nframes < 100*%d",mosaic_max_size);
+      goto exit;
+   }
+
+   if ( cfg->jitterind == 1 )
+   {
+      check_nomsg(p = cpl_parameterlist_find(config, "sinfoni.objnod.vllx"));
+      check_nomsg(vllx = cpl_parameter_get_int(p));
+      check_nomsg(p = cpl_parameterlist_find(config, "sinfoni.objnod.vlly"));
+      check_nomsg(vlly = cpl_parameter_get_int(p));
+      check_nomsg(p = cpl_parameterlist_find(config, "sinfoni.objnod.vurx"));
+      check_nomsg(vurx = cpl_parameter_get_int(p));
+      check_nomsg(p = cpl_parameterlist_find(config, "sinfoni.objnod.vury"));
+      check_nomsg(vury = cpl_parameter_get_int(p));
+      cknull(cube_tmp = (cpl_imagelist**) cpl_calloc (cfg->nframes,
+                                                      sizeof (cpl_imagelist*)),
+             "Could not allocate memory for cube_tmp");
+
+
+      cknull(cubeobject = (cpl_imagelist**) cpl_calloc (cfg->nframes,
+                                                        sizeof (cpl_imagelist*)),
+             "Could not allocate memory for cubeobject");
+      check_nomsg(p=cpl_parameterlist_find(config,
+                                           "sinfoni.objnod.sky_cor"));
+      check_nomsg(sky_cor=cpl_parameter_get_bool(p));
+
+
+      for ( n = 0 ; n < cfg->nframes ; n++ ) {
+         if(sky_cor == 1 && (pdensity == 1 || pdensity == 3) &&
+            strcmp(cfg->sky_dist,"no_sky")!=0) {
+            sinfo_msg("load sky corrected cubes");
+
+            snprintf(file_name,MAX_NAME_SIZE-1,"%s%2.2d%s","out_cube_obj_cor",
+                     n,".fits");
+
+         } else {
+            snprintf(file_name,MAX_NAME_SIZE-1,"%s%2.2d%s","out_cube_obj",n,
+                     ".fits");
+         }
+         check_nomsg(cube_tmp[n] = cpl_imagelist_load(file_name,
+                                                      CPL_TYPE_FLOAT,0));
+
+
+       	 check_nomsg(cubeobject[n] = sinfo_new_cube_getvig(
+							 cube_tmp[n],
+                             1+vllx,1+vlly,
+                             64 - vurx, 64 - vury));
+       	 check_nomsg(sinfo_free_imagelist(&cube_tmp[n]));
+
+      }
+      sinfo_free_array_imagelist(&cube_tmp);
+
+
+   }
+
+
+   /*
+     ---------------------------------------------------------------------
+     ------------------------JITTERING------------------------------------
+     ---------------------------------------------------------------------
+   */
+
+   if (cfg->jitterind == 1)
+   {
+      sinfo_msg("Jittering...");
+
+      sinfo_msg("Coadded cube size. x: %d y: %d",
+                cfg->size_x,cfg->size_y);
+      check_nomsg(jittercube = cpl_imagelist_new()) ;
+
+
+      /*
+         ---------------------------------------------------------------------
+         -------------------THOMAS ALGORITHM----------------------------------
+         ---------------------------------------------------------------------
+      */
+
+      check_nomsg(p=cpl_parameterlist_find(config,
+                                           "sinfoni.objnod.scales_sky"));
+      check_nomsg(scales_sky=cpl_parameter_get_bool(p));
+      check_nomsg(p=cpl_parameterlist_find(config,"sinfoni.objnod.ks_clip"));
+      check_nomsg(ks_clip = cpl_parameter_get_bool(p));
+      check_nomsg(p=cpl_parameterlist_find(config,"sinfoni.objnod.kappa"));
+      check_nomsg(kappa = cpl_parameter_get_double(p));
+
+
+      if(scales_sky == 1) {
+         sinfo_msg("Subtract spatial sinfo_median to each cube plane");
+         for(n=0;n<cfg->nframes;n++) {
+            sinfo_msg("Process cube %d\n",n);
+            sinfo_new_sinfoni_correct_median_it(&(cubeobject[n]));
+         }
+      }
+
+
+      /* AMO CHECK */
+
+      cknull(maskcube=cpl_imagelist_new(),"could not allocate cube!");
+
+      /* Illumination correction */
+      if(ill_cor != NULL) {
+         for(n=0;n<cfg->nframes;n++) {
+            cpl_imagelist_divide_image(cubeobject[n],ill_cor);
+         }
+      }
+      sinfo_free_image(&ill_cor);
+
+      sinfo_msg("Combine jittered cubes");
+
+
+      if(ks_clip == 1) {
+         sinfo_msg("Cube coaddition with kappa-sigma");
+      }
+      check_nomsg(onp=cpl_imagelist_get_size(cubeobject[0]));
+      for(z=0;z<onp;z+=z_stp) {
+         z_siz=(z_stp < (onp-z)) ? z_stp : (onp-z);
+         z_min=z;
+         z_max=z_min+z_siz;
+         sinfo_msg("Coadding cubes: range [%4.4d,%4.4d) of 0-%d\n",
+                   z_min,z_max,onp);
+
+         for(j=z_min;j<z_max;j++) {
+            check_nomsg(j_img=cpl_image_new(cfg->size_x,
+                                            cfg->size_y,CPL_TYPE_FLOAT));
+            check_nomsg(cpl_imagelist_set(jittercube,j_img,j));
+            check_nomsg(m_img = cpl_image_new(cfg->size_x,
+                                              cfg->size_y,CPL_TYPE_FLOAT));
+            check_nomsg(cpl_imagelist_set(maskcube,m_img,j));
+         }
+         if(ks_clip == 1) {
+            sinfo_new_combine_jittered_cubes_thomas_range(cubeobject,
+                                                          jittercube,
+                                                          maskcube,
+                                                          cfg->nframes,
+                                                          offsetx,offsety,
+                                                          times,
+                                                          cfg->kernel_type,
+                                                          z_min,
+                                                          z_max,
+                                                          kappa);
+
+         } else {
+            sinfo_new_combine_jittered_cubes_range(cubeobject,
+                                                   jittercube,
+                                                   maskcube,
+                                                   cfg->nframes,
+                                                   offsetx,
+                                                   offsety,
+                                                   times,
+                                                   cfg->kernel_type,
+                                                   z_min,
+                                                   z_max) ;
+         }
+      }
+      sinfo_new_convert_0_to_ZERO_for_cubes(jittercube) ;
+
+      if (jittercube == NULL)
+      {
+         sinfo_msg_error(" could not allocate new data cube!") ;
+         goto cleanup;
+      }
+
+      if (maskcube == NULL)
+      {
+         sinfo_msg_error(" could not merge the jittered data cubes\n") ;
+         goto cleanup;
+      }
+
+      for ( i = 0 ; i <cfg->nframes  ; i++ ) {
+         sinfo_free_imagelist(&cubeobject[i]);
+         //sinfo_msg("offx[%d]=%f,offy[%d]=%f",i,offsetx[i],i,offsety[i]);
+      }
+      sinfo_free_array_imagelist(&cubeobject);
+
+      //Old setting
+      //newcenter_x = cfg->size_x / 2. + 0.5 ;
+      //newcenter_y = cfg->size_y / 2. + 0.5 ;
+
+
+      /* new setting */
+      /*
+        sinfo_msg("offx_min=%f,offy_min=%f",offx_min,offy_min);
+        sinfo_msg("offx_max=%f,offy_max=%f",offx_max,offy_max);
+        sinfo_msg("ref_offx=%f,ref_offy=%f",ref_offx,ref_offy);
+
+        newcenter_x=2*floor(fabs(offx_min)+0.5)+32+8;
+        newcenter_y=-2*floor(fabs(offy_max)+0.5)+32-2;
+
+
+        newcenter_x=cfg->size_x / 2. -offsetx[0];
+        newcenter_y=cfg->size_y / 2. -offsety[0];
+      */
+
+
+
+      if (mjd_obs > 53825. ) {
+         /* April 1st 2006 */
+         newcenter_x=cfg->size_x / 2. +2*ref_offx;
+         newcenter_y=cfg->size_y / 2. +2*ref_offy;
+      } else if ((mjd_obs > 53421.58210082 ) && (mjd_obs <= 53825.)){
+         /* after detector's upgrade */
+         newcenter_x=cfg->size_x / 2. -2*ref_offx;
+         newcenter_y=cfg->size_y / 2. +2*ref_offy;
+      } else {
+         /* before detector's upgrade */
+         newcenter_x=cfg->size_x / 2. +2*ref_offx;
+         newcenter_y=cfg->size_y / 2. -2*ref_offy;
+      }
+
+
+      //sinfo_msg("CRPIX=%f,%f", newcenter_x, newcenter_y);
+      //newcenter_x=2*floor(fabs(ref_offx)+0.5);
+      //newcenter_y=-2*floor(fabs(ref_offy)+0.5);
+      //sinfo_msg_warning("Center image: %f %f",newcenter_x,newcenter_y);
+      cknull_nomsg(qclog = sinfo_qclog_init());
+      plist=cpl_propertylist_load(file_name,0);
+      if(sinfo_baryvel(plist, &barycor,&helicor) != CPL_ERROR_NONE) {
+         sinfo_msg_warning("Could not compute velocity corrections");
+         cpl_error_reset();
+      } else {
+
+         check_nomsg(sinfo_qclog_add_double(qclog,
+                                            "QC VRAD BARYCOR",
+                                            barycor,
+                                            "Barycentric radial velocity correction ",
+                                            "%13.6f"));
+
+         check_nomsg(sinfo_qclog_add_double(qclog,
+                                            "QC VRAD HELICOR",
+                                            helicor,
+                                            "Heliocentric radial velocity correction ",
+                                            "%13.6f"));
+         sinfo_msg("Barycor=%g Helicor=%g",barycor,helicor);
+
+         sinfo_free_propertylist(&plist);
+
+      }
+
+      ck0(sinfo_pro_save_ims(jittercube,sof,sof,cfg->outName,
+                             procatg,qclog,plugin_id,config),
+          "cannot save cube %s", cfg->outName);
+
+      sinfo_free_table(&qclog);
+
+      /* we need to set again the following 3 */
+      plist=cpl_propertylist_load(file_name,0);
+      dis=sinfo_pfits_get_cdelt3(plist);
+      centralLambda=sinfo_pfits_get_crval3(plist);
+      centralpix=sinfo_pfits_get_crpix3(plist);
+      sinfo_free_propertylist(&plist);
+      sinfo_new_set_wcs_cube(jittercube, cfg->outName,
+                             centralLambda, dis,
+                             centralpix, newcenter_x, newcenter_y);
+
+      cknull(jitter_image = sinfo_new_median_cube(jittercube),
+             " could not do sinfo_medianCube()");
+      cknull_nomsg(qclog = sinfo_qclog_init());
+      update_bad_pixel_map(jitter_image);
+   	  check_nomsg(sinfo_qclog_add_double(qclog,
+                                               "QC FRMDIF MEANSTD",
+                                               cpl_image_get_mean(jitter_image),
+                                               "mean of the collapesd cube",
+                                               "%13.6f"));
+      check_nomsg(sinfo_qclog_add_double(qclog,
+                                               "QC FRMDIF STDEV",
+                                               cpl_image_get_stdev(jitter_image),
+                                               "standard deviation of the collapesd cube",
+                                               "%13.6f"));
+      ck0(sinfo_pro_save_ima(jitter_image,sof,sof,cfg->med_cube_name,
+                             pro_med,qclog,plugin_id,config),
+          "cannot save ima %s", cfg->outName);
+      sinfo_free_table(&qclog);
+
+      sinfo_new_set_wcs_image(jitter_image, cfg->med_cube_name,
+                              newcenter_x,newcenter_y);
+
+      sinfo_free_image(&jitter_image);
+
+      ck0(sinfo_pro_save_ims(maskcube,sof,sof,cfg->maskname,
+                             pro_mjit,NULL,plugin_id,config),
+          "cannot save cube %s", cfg->maskname);
+
+      sinfo_new_set_wcs_cube(maskcube, cfg->maskname,
+                             centralLambda, dis, centralpix,
+                             newcenter_x, newcenter_y);
+
+      sinfo_free_double(&times) ;
+      sinfo_free_float(&offsetx) ;
+      sinfo_free_float(&offsety) ;
+      sinfo_free_imagelist(&maskcube) ;
+      sinfo_free_imagelist(&jittercube) ;
+
+   } /* end of jittering */
+
+  exit:
+
+   /* free memory */
+   sinfo_objnod_free(&cfg);
+   sinfo_free_frameset(&stk);
+   return 0;
+
+  cleanup:
+
+   sinfo_free_image(&jitter_image);
+   sinfo_free_imagelist(&jittercube) ;
+   sinfo_free_imagelist(&maskcube) ;
+   sinfo_free_table(&qclog);
+
+   if(cfg != NULL) {
+      if(cube_tmp != NULL) {
+         for ( n = 0 ; n < cfg->nframes ; n++ ) {
+            sinfo_free_imagelist(&(cube_tmp[n]));
+         }
+         sinfo_free_array_imagelist(&cube_tmp);
+      }
+      if(cubeobject != NULL) {
+         for ( n = 0 ; n < cfg->nframes ; n++ ) {
+            sinfo_free_imagelist(&(cubeobject[n]));
+         }
+         sinfo_free_array_imagelist(&cubeobject);
+      }
+
+   }
+   sinfo_free_table(&qclog_tbl);
+   sinfo_free_image(&im);
+   sinfo_free_image(&ill_cor);
+   sinfo_free_float(&offsety);
+   sinfo_free_float(&offsetx);
+   sinfo_free_double(&times);
+   sinfo_objnod_free(&cfg);
+   sinfo_free_frameset(&stk);
+
+   if (cpl_error_get_code() != CPL_ERROR_NONE) {
+      sinfo_check_rec_status(0);
+   }
+   return -1;
+
+
+
+}
+
+/**@}*/
diff --git a/sinfoni/sinfo_new_cubes_coadd.h b/sinfoni/sinfo_new_cubes_coadd.h
new file mode 100644
index 0000000..4821974
--- /dev/null
+++ b/sinfoni/sinfo_new_cubes_coadd.h
@@ -0,0 +1,71 @@
+#ifndef SINFO_NEW_CUBES_COADD_H
+#define SINFO_NEW_CUBES_COADD_H
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*******************************************************************************
+* E.S.O. - VLT project
+*
+* "@(#) $Id: sinfo_new_cubes_coadd.h,v 1.10 2007/06/06 07:10:45 amodigli Exp $"
+*
+* who       when      what
+* --------  --------  ----------------------------------------------
+* schreib  06/05/03  created
+*/
+
+/************************************************************************
+ * sinfo_new_cubes_coadd.h
+ * routines to create a data cube
+ *----------------------------------------------------------------------
+ */
+
+/*
+ * header files
+ */
+#include <math.h>
+#include <cpl.h>   
+#include "sinfo_msg.h"
+/*----------------------------------------------------------------------------
+ *                        Function ANSI C prototypes
+ *--------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+   @name sinfo_new_cubes_coadd()
+   @param ini_file: file name of according .ini file
+   @param integer (0 if it worked, -1 if it doesn't) 
+   @doc this routine does the resampling of an offset-corrected,
+        flatfielded, bad pixel corrected and
+        eventually interleaved data frame. Additionally, an intensity 
+    calibration is carried through by using
+        a standard star or a black body measurement. 
+    The spectral features of the flatfield halogen lamp are corrected.
+        Afterwards a data cube is created out of the resampled image.
+    It is the users choice to use either
+        the fitted sinfo_edge positions of the slitlets or the distances
+    of the slitlets gained from a north-south-test. 
+ ---------------------------------------------------------------------------*/
+int 
+sinfo_new_cubes_coadd (const char* plugin_id,
+                       cpl_parameterlist* config, 
+                       cpl_frameset* sof, 
+                       const char* procatg) ;
+
+
+#endif /*!SINFO_CUBES_COADD2_H*/
+
+/*--------------------------------------------------------------------------*/
diff --git a/sinfoni/sinfo_new_dark.c b/sinfoni/sinfo_new_dark.c
new file mode 100644
index 0000000..557c7bf
--- /dev/null
+++ b/sinfoni/sinfo_new_dark.c
@@ -0,0 +1,731 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+   
+   File name    :       sinfo_new_dark.c
+   Author       :    A. Modigliani
+   Created on   :    Sep 17, 2003
+   Description  :    Master sinfo_dark creation 
+
+ ---------------------------------------------------------------------------*/
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+/*----------------------------------------------------------------------------
+                                Includes
+ ---------------------------------------------------------------------------*/
+#include "sinfo_new_dark.h"
+#include "sinfo_utilities.h"
+#include "sinfo_pro_save.h"
+#include "sinfo_dark_ini_by_cpl.h"
+#include "sinfo_dfs.h"
+#include "sinfo_pfits.h"
+#include "sinfo_error.h"
+#include "sinfo_utils_wrappers.h"
+/*----------------------------------------------------------------------------
+                                Defines
+ ---------------------------------------------------------------------------*/
+static int sinfo_dark_ron_reduce(cpl_frameset * framelist,
+                            dark_config* cfg,
+                            cpl_table* qclog);
+
+
+static int 
+sinfo_dark_compare(const cpl_frame * frame1, const cpl_frame * frame2);
+
+/**@{*/
+/**
+ * @addtogroup sinfo_rec_mdark Master dark generation
+ *
+ * TBD
+ */
+
+
+
+/*----------------------------------------------------------------------------
+                             Function Definitions
+ ---------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+   @name  sinfo_new_dark()
+   @param  plugin_id recipe id
+   @param  config input parameterlist
+   @param  sof    input set of frames
+   @return integer (0 if it worked, -1 if it doesn't) 
+   @doc 
+                  1) Sorts frames according to integration time
+                  2) Take the clean mean of a stack of frames with the 
+                  same integration time
+
+ ---------------------------------------------------------------------------*/
+
+int sinfo_new_dark (const char* plugin_id, cpl_parameterlist* config, 
+          cpl_frameset* sof, char* dark_name)
+{
+    
+    dark_config * cfg=NULL ;
+    cpl_imagelist * image_list=NULL ;
+    cpl_imagelist * object_list=NULL ;
+
+   
+    cpl_image * image=NULL ;
+    cpl_image * eclipse_image=NULL ;
+
+    cpl_image* dark_img=NULL;
+    cpl_frame* first_frame=NULL;
+    cpl_vector* qc_dark_median=NULL;
+    cpl_frameset* raw=NULL;
+    cpl_table* qclog_tbl=NULL;
+    cpl_propertylist* rplist=NULL;
+    cpl_frameset* f_one=NULL;
+    int no=0;
+    float lo_cut=0.;
+    float hi_cut=0.;
+
+    int i = 0;
+    int j = 0;
+    int n = 0;
+    int count = 0;
+    int* n_times=NULL;
+    double exp_time = 0.;    
+    float* int_time=NULL;   
+    float time_val = 0.; 
+
+    char   ref_file[MAX_NAME_SIZE];
+    cpl_size zone_def[4];
+    double qc_ron_val=0;
+    double qc_ron_err=0;
+    double qc_darkmed_ave=0;
+    double qc_darkmed_stdev=0;
+    double fpn=0;
+    cpl_size zone[4];
+    int naxis1=0;
+    int naxis2=0;
+
+    cpl_size* selection=NULL;
+    cpl_size nsets=0;
+    /* 
+       -----------------------------------------------------------------
+       1) parse the file names and parameters to the dark_config data 
+          structure cfg 
+       -----------------------------------------------------------------
+     */
+ 
+    check_nomsg(raw=cpl_frameset_new());
+    cknull(cfg = sinfo_parse_cpl_input_dark(config,sof,&raw),
+           "could not parse cpl input!") ;
+
+    /* 
+       -----------------------------------------------------------------
+       2) GET FRAMES AND SORT ACCORDING TO EXPOSURE TIME 
+       -----------------------------------------------------------------
+     */
+     
+    /* 
+       2.1) get the total integration time from the fits header and 
+            store it in an array
+     */
+
+    /* 2.1.1) get a data cube to stack darks */
+    sinfo_msg("Build data cube");
+    /* take a clean mean of the frames */
+    check_nomsg(image_list = cpl_imagelist_new());
+    int_time = (float*) cpl_calloc(cfg -> nframes, sizeof(float)) ;
+    sinfo_check_rec_status(0);
+ 
+    for ( i = 0 ; i < cfg->nframes ; i++ )
+    {
+        if (sinfo_is_fits_file (cfg->inFrameList[i]) != 1) {
+       sinfo_msg_error("Input file %s is not FITS",cfg->inFrameList[i]);
+           goto cleanup;
+        }
+
+    check_nomsg(cpl_imagelist_set(image_list,
+                    cpl_image_load(cfg->inFrameList[i],CPL_TYPE_FLOAT,0,0),i));
+
+        exp_time = sinfo_pfits_get_exptime(cfg->inFrameList[i]);
+    if(cpl_error_get_code() != CPL_ERROR_NONE) {
+       sinfo_msg_error("could not get exposure time from fits header!\n");
+           goto cleanup;
+    }
+        sinfo_new_array_set_value(int_time, (float)exp_time, i);
+    }
+    no=cfg->nframes;
+
+
+    /*
+       2.2) find the number of frames with the same integration time
+     */
+    sinfo_msg("Find frames with same tint");
+    n = 0;
+
+    n_times = (int*) cpl_calloc(cfg -> nframes, sizeof(int));
+    sinfo_msg("Sort frames with same tint");
+
+    for ( i = 0 ; i < cfg->nframes-1 ; i++ )
+    {
+         if ( sinfo_new_array_get_value(int_time, i+1) != 
+              sinfo_new_array_get_value(int_time, i)
+        ) {
+
+    n_times[n] = i+1;
+        n = n+1;
+    }
+    
+    }
+
+    /* 
+       2.3) store the images with the same tint in data cubes and take 
+            clean means
+     */
+    sinfo_msg("Do clean mean");
+    if ( n == 0 ) {
+
+      sinfo_msg("n == 0 ");
+       time_val = sinfo_new_array_get_value(int_time, 0);
+
+      cknull(object_list = cpl_imagelist_new(),
+         "could not allocate memory for object_list");
+
+       /* here we have a leak of 80 bytes */
+
+
+       count = 0;
+       /* do also QC log */
+       check_nomsg(qc_dark_median=cpl_vector_new(cfg->nframes));
+
+       /* AMo here there is a leak */
+       for ( j = 0 ; j < cfg->nframes ; j++ ) {
+     check_nomsg(cpl_imagelist_set(object_list,
+                     cpl_image_duplicate(cpl_imagelist_get(image_list,j)),
+                     count));
+     check_nomsg(cpl_vector_set(qc_dark_median,j,
+                     cpl_image_get_median(cpl_imagelist_get(image_list,j))));
+         count = count + 1;
+       }
+
+
+ 
+       check_nomsg(qc_darkmed_ave=cpl_vector_get_mean(qc_dark_median));
+       if (cfg->nframes > 1) {
+          check_nomsg(qc_darkmed_stdev=cpl_vector_get_stdev(qc_dark_median));
+       }
+       /* 
+        rms   = stdev * sqrt(1-1/(double)cpl_vector_get_size(myvector)); 
+       qc_darkmed_stdev = qc_darkmed_stdev * 
+                       sqrt(1-1/(double)cpl_vector_get_size(qc_dark_median));
+        */  
+
+       check_nomsg(no=cpl_imagelist_get_size(object_list));
+       lo_cut=(floor)(cfg->lo_reject*no+0.5);
+       hi_cut=(floor)(cfg->hi_reject*no+0.5);
+
+ 
+  
+       cknull(image=cpl_imagelist_collapse_minmax_create(object_list,
+                                                         lo_cut,hi_cut),
+          "sinfo_average_with_rejection failed");
+
+       sinfo_free_imagelist(&object_list);
+
+       sinfo_msg("dark_name=%s\n",dark_name);
+       
+       check_nomsg(first_frame = cpl_frameset_get_frame(raw, 0)) ;
+   
+       strcpy(ref_file,cpl_frame_get_filename(first_frame)) ;
+       cknull_nomsg(rplist = cpl_propertylist_load(ref_file, 0));
+
+       check_nomsg(naxis1=cpl_propertylist_get_int(rplist,"NAXIS1"));
+       check_nomsg(naxis2=cpl_propertylist_get_int(rplist,"NAXIS1"));
+       sinfo_free_propertylist(&rplist);
+
+       if(cfg->qc_ron_xmin < 1) {
+     sinfo_msg_error("qc_ron_xmin %d < 1",cfg->qc_ron_xmin);
+         goto cleanup;
+       }
+
+       if(cfg->qc_ron_xmax > naxis1) {
+     sinfo_msg_error("qc_ron_xmax %d > %d",cfg->qc_ron_xmax,naxis1);
+         goto cleanup;
+       }
+
+       if(cfg->qc_ron_ymin < 1) {
+     sinfo_msg_error("qc_ron_ymin %d < 1",cfg->qc_ron_ymin);
+         goto cleanup;
+       }
+
+       if(cfg->qc_ron_ymax > naxis2) {
+     sinfo_msg_error("qc_ron_ymax %d > %d",cfg->qc_ron_ymax,naxis2);
+         goto cleanup;
+       }
+
+       zone_def[0]=cfg->qc_ron_xmin;
+       zone_def[1]=cfg->qc_ron_xmax;
+       zone_def[2]=cfg->qc_ron_ymin;
+       zone_def[3]=cfg->qc_ron_ymax;
+
+
+
+       check(cpl_flux_get_noise_window(image,
+                       zone_def,
+                       cfg->qc_ron_hsize,
+                       cfg->qc_ron_nsamp,
+                       &qc_ron_val,
+                       &qc_ron_err),
+         "In computation RON on image %s",dark_name);
+      
+ 
+
+       if(cfg->qc_fpn_xmin < 1) {
+     sinfo_msg_error("qc_fpn_xmin %d < 1",cfg->qc_fpn_xmin);
+         goto cleanup;
+       }
+
+       if(cfg->qc_fpn_xmax > naxis1) {
+     sinfo_msg_error("qc_fpn_xmax %d > %d",cfg->qc_fpn_xmax,naxis1);
+         goto cleanup;
+       }
+
+       if(cfg->qc_fpn_ymin < 1) {
+     sinfo_msg_error("qc_fpn_ymin %d < 1",cfg->qc_fpn_ymin);
+         goto cleanup;
+       }
+
+       if(cfg->qc_fpn_ymax > naxis2) {
+     sinfo_msg_error("qc_fpn_ymax %d > %d",cfg->qc_fpn_ymax,naxis2);
+         goto cleanup;
+       }
+
+       zone[0]=cfg->qc_fpn_xmin;
+       zone[1]=cfg->qc_fpn_xmax;
+       zone[2]=cfg->qc_fpn_ymin;
+       zone[3]=cfg->qc_fpn_ymax;
+       check(cpl_flux_get_noise_window(image, zone, cfg->qc_fpn_hsize,
+                       cfg->qc_fpn_nsamp, &fpn, NULL),
+         "Error computing noise in a window");
+
+       /* QC LOG */
+       cknull_nomsg(qclog_tbl = sinfo_qclog_init());
+
+       ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC DARKMED AVE",
+             qc_darkmed_ave,"Average of raw darks medians","%f"));
+
+       ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC DARKMED STDEV",
+                     qc_darkmed_stdev,"STDEV of raw darks medians","%f"));
+
+       ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC RON",
+                     qc_ron_val,"Read Out Noise","%f"));
+       
+       ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC RONRMS",
+                     qc_ron_err,"RMS on Read Out Noise","%f"));
+
+       ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC DARKFPN",
+                     fpn,"Fixed Pattern Noise of combined frames","%g"));
+
+ 
+       /* special way to calculate RON: for each couple */
+       
+       check(selection = cpl_frameset_labelise(raw,sinfo_dark_compare,&nsets),
+         "Error labelizing");
+
+
+
+       for ( i = 0 ; i < nsets ; i++ ) {
+         sinfo_msg("Reduce data set no %d out of %" CPL_SIZE_FORMAT "", i+1, nsets);
+         cpl_msg_indent_more();
+     check_nomsg(f_one = cpl_frameset_extract(raw,selection,i));
+         if (cpl_frameset_get_size(f_one) < 2) {
+           sinfo_msg_warning("Skip %d set. One frame, not enough "
+                             "to get ron",i+1);
+     } else {
+           if (sinfo_dark_ron_reduce(f_one,cfg,qclog_tbl) ) {
+         sinfo_msg_warning( "Cannot reduce set number %d", i+1) ;
+       }
+     }
+         sinfo_free_frameset(&f_one);
+         cpl_msg_indent_less();
+
+       }
+       cpl_free(selection);
+
+
+       /* generate a dummy_set with the master dark and a dummy 
+              dark=2*master_dark */
+
+       ck0(sinfo_pro_save_ima(image,raw,sof,dark_name,
+                 PRO_MASTER_DARK,qclog_tbl,plugin_id,config),
+                           "cannot save ima %s", dark_name);
+       sinfo_free_table(&qclog_tbl);
+       sinfo_free_image(&image);
+ 
+    } else if (n == 1) {
+
+       sinfo_msg("n == 1");
+       time_val = sinfo_new_array_get_value(int_time, 0);
+       cknull(object_list = cpl_imagelist_new(),
+           "could not allocate memory");
+
+       count = 0;
+
+       for (j =0; j < n_times[0]; j++) {
+
+     check_nomsg(cpl_imagelist_set(object_list,
+                     cpl_image_duplicate(cpl_imagelist_get(image_list,j)),
+                     count));
+     count = count + 1;
+       }
+
+
+       check_nomsg(no=cpl_imagelist_get_size(object_list));
+       lo_cut=(floor)(cfg->lo_reject*no+0.5);
+       hi_cut=(floor)(cfg->hi_reject*no+0.5);
+       check(image=cpl_imagelist_collapse_minmax_create(object_list,
+                                                        lo_cut,hi_cut),
+                                 "sinfo_average_with_rejection failed!");
+
+       sinfo_free_imagelist(&object_list);
+
+       cknull_nomsg(qclog_tbl = sinfo_qclog_init());
+       ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC NAME",1,
+                                     "A description","%d"));
+
+       ck0(sinfo_pro_save_ima(image,raw,sof,dark_name,
+                  PRO_MASTER_DARK,qclog_tbl,plugin_id,config),
+                          "cannot save ima %s", dark_name);
+
+
+       sinfo_free_image(&image);
+       sinfo_free_table(&qclog_tbl);
+
+       time_val = sinfo_new_array_get_value(int_time, n_times[0]);
+       cknull(object_list = cpl_imagelist_new(),
+          "could not allocate memory");
+       count = 0;
+
+
+       for (j = n_times[0]; j < cfg->nframes; j++) {
+
+     check_nomsg(cpl_imagelist_set(object_list,
+                     cpl_image_duplicate(cpl_imagelist_get(image_list,j)),
+                     count));
+         count = count + 1;
+       }
+
+
+       check_nomsg(no=cpl_imagelist_get_size(object_list));
+       lo_cut=(floor)(cfg->lo_reject*no+0.5);
+       hi_cut=(floor)(cfg->hi_reject*no+0.5);
+       cknull(eclipse_image=cpl_imagelist_collapse_minmax_create(object_list,
+                                                                 lo_cut,hi_cut),
+          "sinfo_average_with_rejection failed!");
+
+       sinfo_free_imagelist(&object_list);
+
+
+       cknull_nomsg(qclog_tbl = sinfo_qclog_init());
+       ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC NAME",1,
+                                     "A description","%d"));
+
+       ck0(sinfo_pro_save_ima(eclipse_image,raw,sof,dark_name,
+                  PRO_MASTER_DARK,qclog_tbl,plugin_id,config),
+                          "cannot save ima %s", dark_name);
+
+       sinfo_free_image(&eclipse_image);
+       sinfo_free_table(&qclog_tbl);
+
+    } else {
+
+       sinfo_msg("n==else\n");
+
+       for (i= 0; i < n+1; i++) {
+         if ( i == 0 ) {
+           time_val = sinfo_new_array_get_value(int_time, 0);
+        check(object_list = cpl_imagelist_new(),
+               "could not allocate memory");
+
+            count = 0;
+            for (j = 0; j < n_times[0]; j++) {
+          check_nomsg(cpl_imagelist_set(object_list,
+                          cpl_image_duplicate(cpl_imagelist_get(image_list,j)),
+                          count));
+          count = count + 1;
+        }
+        check_nomsg(no=cpl_imagelist_get_size(object_list));
+        lo_cut=(floor)(cfg->lo_reject*no+0.5);
+        hi_cut=(floor)(cfg->hi_reject*no+0.5);
+            check(image=cpl_imagelist_collapse_minmax_create(object_list,
+                                                             lo_cut,hi_cut),
+                                    "Error computing average with rejection");
+            sinfo_free_imagelist(&object_list);
+
+            sinfo_msg("dark_name-%s\n",dark_name);
+            cknull_nomsg(qclog_tbl = sinfo_qclog_init());
+            ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC NAME",1,
+                                          "A description","%d"));
+
+            ck0(sinfo_pro_save_ima(image,raw,sof,dark_name,
+                   PRO_MASTER_DARK,qclog_tbl,plugin_id,config),
+              "cannot save ima %s", dark_name);
+
+
+            sinfo_free_table(&qclog_tbl);
+            sinfo_free_image(&image);
+     } else if ( i == n ) {
+            time_val = sinfo_new_array_get_value(int_time, n_times[n-1]);
+            cknull(object_list = cpl_imagelist_new(), 
+               "could not allocate memory");
+
+            count = 0;
+            for (j = n_times[n-1]; j < cfg->nframes; j++) {
+          check_nomsg(cpl_imagelist_set(object_list,
+                          cpl_image_duplicate(cpl_imagelist_get(image_list,j)),
+                          count));
+          count = count + 1;
+        }
+        check_nomsg(no=cpl_imagelist_get_size(object_list));
+        lo_cut=(floor)(cfg->lo_reject*no+0.5);
+        hi_cut=(floor)(cfg->hi_reject*no+0.5);
+            check(image=cpl_imagelist_collapse_minmax_create(object_list,
+                                                             lo_cut,hi_cut),
+                  "Error computing average with rejection");
+
+            sinfo_free_imagelist(&object_list);
+
+            cknull_nomsg(qclog_tbl = sinfo_qclog_init());
+            ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC NAME",1,
+                                          "A description","%d"));
+
+            ck0(sinfo_pro_save_ima(image,raw,sof,dark_name,
+                   PRO_MASTER_DARK,qclog_tbl,plugin_id,config),
+        "cannot save ima %s", dark_name);
+            sinfo_free_table(&qclog_tbl);
+            sinfo_free_image(&image);
+    } else {
+        time_val = sinfo_new_array_get_value(int_time, n_times[i-1]);
+        cknull(object_list = cpl_imagelist_new(), 
+                   "could not allocate memory");
+
+            count = 0;
+            for (j = n_times[i-1]; j < n_times[i]; j++) {
+          check_nomsg(cpl_imagelist_set(object_list,
+                          cpl_image_duplicate(cpl_imagelist_get(image_list,j)),
+                          count));
+          count = count + 1;
+        }
+        check_nomsg(no=cpl_imagelist_get_size(object_list));
+        lo_cut=(floor)(cfg->lo_reject*no+0.5);
+        hi_cut=(floor)(cfg->hi_reject*no+0.5);
+            cknull(image=cpl_imagelist_collapse_minmax_create(object_list,
+                                                              lo_cut,hi_cut),
+                                     "Error computing average with rejection");
+
+            sinfo_free_imagelist(&object_list);
+
+            cknull_nomsg(qclog_tbl = sinfo_qclog_init());
+            ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC NAME",1,
+                                          "A description","%d"));
+
+            ck0(sinfo_pro_save_ima(image,raw,sof,dark_name,
+                   PRO_MASTER_DARK,qclog_tbl,plugin_id,config),
+                                   "cannot save ima %s", dark_name);
+
+            sinfo_free_image(&image);
+            sinfo_free_table(&qclog_tbl);
+    }
+       
+       } /* end for loop */
+    } /* end else over n */
+
+ 
+
+       sinfo_free_imagelist(&image_list);
+       sinfo_free_my_vector(&qc_dark_median);
+       sinfo_free_int(&n_times);
+       sinfo_free_float(&int_time);
+       sinfo_dark_free(&cfg);
+       sinfo_free_frameset(&raw);
+
+      return 0;
+
+ cleanup:
+       sinfo_free_frameset(&f_one);
+       cpl_free(selection);
+       sinfo_free_image(&eclipse_image);
+       sinfo_free_table(&qclog_tbl);
+       sinfo_free_image(&dark_img);
+       sinfo_free_image(&image);
+       sinfo_free_propertylist(&rplist);
+       sinfo_free_my_vector(&qc_dark_median);
+       sinfo_free_imagelist(&object_list);
+       sinfo_free_int(&n_times);
+       sinfo_free_float(&int_time);
+       sinfo_free_imagelist(&image_list);
+       sinfo_dark_free(&cfg);
+       sinfo_free_frameset(&raw);
+
+       return -1;
+
+}
+
+
+
+
+
+
+/*--------------------------------------------------------------------*/
+    /**
+          @brief    The recipe data reduction ('ron' part) is implemented here 
+          @param    framelist   the frames list of the current set 
+          @param    set         the complete frames set
+          @return   0 if ok, -1 in error case
+     */
+/*--------------------------------------------------------------------*/
+ static int 
+sinfo_dark_ron_reduce(cpl_frameset    *   framelist,
+              dark_config     *   cfg,
+              cpl_table       *   qclog_tbl)
+{
+  cpl_imagelist   *   iset =NULL;
+  int                 i =0;
+  double* ron=NULL;
+  /* int nraw=0; */
+  int niset=0;
+  char key_name[MAX_NAME_SIZE];
+  /* Test entries */
+
+  cknull_nomsg(framelist);
+
+  /* Load the current set */
+  if ((iset = sinfo_new_frameset_to_iset(framelist)) == NULL) {
+    sinfo_msg_error( "Cannot load the data") ;
+    return -1 ;
+  }
+  /* Loop on all pairs */
+  /* nraw = cpl_table_get_nrow(qclog_tbl); */
+  niset=cpl_imagelist_get_size(iset);
+
+  ron = cpl_calloc(niset,sizeof(double));
+
+  sinfo_get_ron(framelist,
+                cfg->qc_ron_xmin,cfg->qc_ron_xmax,
+                cfg->qc_ron_ymin,cfg->qc_ron_ymax,
+                cfg->qc_ron_hsize,cfg->qc_ron_nsamp,
+                &ron);
+
+  for (i=0 ; i<niset-1 ; i++) {
+
+    /* Write the paf file on disk */
+    /* Write QC LOG */
+
+    snprintf(key_name,MAX_NAME_SIZE-1,"%s%d","QC RON",i+1);
+    sinfo_qclog_add_double(qclog_tbl,key_name,ron[i],
+               "Read Out Noise","%f");
+
+  }
+
+  cpl_free(ron);
+  sinfo_free_imagelist(&iset) ;
+
+  return 0 ;
+ cleanup:
+  cpl_free(ron);
+  ron=NULL;
+  sinfo_free_imagelist(&iset) ;
+
+  return -1;
+
+}
+
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Comparison function to identify different settings
+  @param    frame1  first frame 
+  @param    frame2  second frame 
+  @return   0 if frame1!=frame2, 1 if frame1==frame2, -1 in error case
+ */
+/*---------------------------------------------------------------------------*/
+static int sinfo_dark_compare(
+        const cpl_frame   *   frame1,
+        const cpl_frame   *   frame2)
+{
+    int                 comparison=0 ;
+    cpl_propertylist *  plist1=NULL;
+    cpl_propertylist *  plist2=NULL;
+
+    char            *   sval ;
+    char                mode1[512] ;
+    char                mode2[512] ;
+    double              dval1=0;
+    double              dval2=0;
+    int                 ival1=0;
+    int                 ival2=0;
+
+    /* Test entries */
+    if (frame1==NULL || frame2==NULL) return -1 ;
+
+    /* Get property lists */
+    cknull(plist1=cpl_propertylist_load(cpl_frame_get_filename(frame1),0),
+        "getting header from reference frame");
+
+    cknull(plist2=cpl_propertylist_load(cpl_frame_get_filename(frame2),0),
+        "getting header from reference frame");
+     
+    /* Compare exposure time */
+    comparison = 1 ;
+    check(dval1=sinfo_pfits_get_exp_time(plist1),"To get exptime");
+    check(dval2=sinfo_pfits_get_exp_time(plist2),"To get exptime");
+
+    if (fabs(dval1-dval2) > 1e-5) comparison = 0 ;
+
+    /* Compare the readout mode */
+    check(ival1=sinfo_pfits_get_rom(plist1),"to get read out mode");
+    check(ival2=sinfo_pfits_get_rom(plist2),"to get read out mode");
+    if (ival1 != ival2) comparison = 0 ;
+
+
+    /* Compare the detector mode */
+    cknull(sval=sinfo_pfits_get_mode(plist1),"to get detector mode");
+    strcpy(mode1, sval) ;
+
+    cknull(sval=sinfo_pfits_get_mode(plist2),"to get detector mode");
+    strcpy(mode2, sval) ;
+
+
+    if (strcmp(mode1, mode2)) comparison = 0 ;
+
+    /* Files have to be consequtive */
+    /*
+    check(ival1 = sinfo_pfits_get_expno(plist1),"to get exposure number");
+    check(ival2 = sinfo_pfits_get_expno(plist1),"to get exposure number");
+    if (ival1 != ival2) comparison = 0 ;
+    */
+    sinfo_free_propertylist(&plist1);
+    sinfo_free_propertylist(&plist2);
+
+    return comparison ;
+ cleanup:
+    sinfo_free_propertylist(&plist1);
+    sinfo_free_propertylist(&plist2);
+    return -1 ;
+
+
+}
+/**@}*/
diff --git a/sinfoni/sinfo_new_dark.h b/sinfoni/sinfo_new_dark.h
new file mode 100644
index 0000000..108b51e
--- /dev/null
+++ b/sinfoni/sinfo_new_dark.h
@@ -0,0 +1,64 @@
+#ifndef SINFO_NEW_DARK_H
+#define SINFO_NEW_DARK_H
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*****************************************************************************
+* E.S.O. - VLT project
+*
+* "@(#) $Id: sinfo_new_dark.h,v 1.6 2007/06/06 07:10:45 amodigli Exp $"
+*
+* who       when      what
+* --------  --------  ----------------------------------------------
+* amodigli  17/09/03  created
+*/
+
+/************************************************************************
+ * sinfo_dark.h
+ * routines to create a master sinfo_dark
+ *----------------------------------------------------------------------
+ */
+
+/*
+ * header files
+ */
+#include <cpl.h>    
+#include "sinfo_msg.h"
+/*@-skipposixheaders@*/
+/*@=skipposixheaders@*/
+/*----------------------------------------------------------------------------
+ *                        Function ANSI C prototypes
+ *--------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+   @name cpl_dark()
+   @param ini_file: file name of according .ini file
+   @param cpl_parameterlist: structure containing recipe's parameters
+   @param cpl_frameset: structure containing recipe's input files
+   @result integer (0 if it worked, -1 if it doesn't) 
+   @doc Sorts frames according to integration time
+        Take the clean mean of a stack of frames with the same
+        integration time
+
+ ---------------------------------------------------------------------------*/
+int 
+sinfo_new_dark (const char* plugin_id, cpl_parameterlist* config, 
+          cpl_frameset* set, char* dark_name);
+#endif 
+
+/*--------------------------------------------------------------------------*/
diff --git a/sinfoni/sinfo_new_find_distortions.c b/sinfoni/sinfo_new_find_distortions.c
new file mode 100644
index 0000000..0c1c5c8
--- /dev/null
+++ b/sinfoni/sinfo_new_find_distortions.c
@@ -0,0 +1,759 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+
+   File name    :       sinfo_find_distortions.c
+   Author       :    A. Modigliani
+   Created on   :    Aug 12, 2004
+   Description  :
+
+ ---------------------------------------------------------------------------*/
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+#include <sinfo_cpl_size.h>
+
+/*----------------------------------------------------------------------------
+                                Includes
+ ---------------------------------------------------------------------------*/
+
+#include "sinfo_new_find_distortions.h"
+#include "sinfo_pro_save.h"
+#include "sinfo_pro_types.h"
+#include "sinfo_finddist_ini_by_cpl.h"
+#include "sinfo_wave_calibration.h"
+#include "sinfo_cube_construct.h"
+#include "sinfo_absolute.h"
+#include "sinfo_distortion.h"
+#include "sinfo_utilities.h"
+#include "sinfo_recipes.h"
+#include "sinfo_utils_wrappers.h"
+#include "sinfo_error.h"
+#include "sinfo_globals.h"
+
+/*----------------------------------------------------------------------------
+                                Defines
+ ---------------------------------------------------------------------------*/
+#define SINFO_ARC_SATURATION                 100000
+#define SINFO_ARC_MAX_WIDTH                  64
+
+
+/**@{*/
+/**
+ * @addtogroup sinfo_rec_mflat Master flat generation
+ *
+ * TBD
+ */
+
+
+/*----------------------------------------------------------------------------
+                             Function Definitions
+ ---------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+   Function     :       sinfo_find_distortions()
+   In           :
+   Out          :
+   Job          :
+
+ ---------------------------------------------------------------------------*/
+static double
+new_compute_shift(double x,
+          double y,
+          double c00,
+          double c10,
+          double c01,
+          double c11,
+          double c20,
+          double c02,
+          double c21,
+          double c12,
+          double c30,
+          double c03);
+
+int
+sinfo_new_find_distortions(const char* plugin_id,
+                           cpl_parameterlist* config,
+                           cpl_frameset* sof,
+			   cpl_frameset* set_fibre_ns)
+{
+
+  finddist_config * cfg=NULL ;
+  cpl_image * imonind=NULL ;
+  cpl_image * impoly=NULL ;
+  cpl_image * im=NULL ;
+  cpl_image *  map=NULL ;
+  cpl_image *  mask=NULL ;
+
+  int*            degx=NULL;
+  int*            degy=NULL;
+  int* n_found_lines=NULL;
+  int* sum_pointer=NULL;
+  int** row_clean=NULL;
+  int pdensity=0;
+
+
+  int x_l=SIZEX/4*1;
+  int x_u=SIZEX/4*3;
+  int y_l=SIZEY/4*1;
+  int y_u=SIZEY/4*3;
+  int x_c=SIZEX/4*2;
+  int y_c=SIZEY/4*2;
+  const int pdx=4;
+  const int pdy=4;
+  int check = 0;
+  int i = 0;
+  int lx=0;
+  int ly=0;
+
+
+  int sum=0;
+  int n_lines=0;
+  int fit=0;
+  int n=0;
+  int j=0;
+  cpl_size coef_pow[2];
+  int arcs_window_size=0;
+
+  float value=0;
+  float newval=0;
+  float total_dist=0;
+  float shift=0;
+
+  float* distances=NULL;
+  float** wavelength_clean=NULL;
+  float** slit_pos=NULL;
+  float** acoefs=NULL;
+  float* wave=NULL;
+  float* intens=NULL;
+  float* first =NULL;
+
+  double*         coef=NULL;
+
+  double xshift=0.;
+  double arcs_thres_factor=0;
+
+  double arcs_min_arclen_factor=0;
+  double pcf[pdx][pdy];
+
+
+  char tbl_name[FILE_NAME_SZ];
+  char key_name[FILE_NAME_SZ];
+
+  cpl_table* poly_tbl=NULL;
+  cpl_table* tbl_spos=NULL;
+  cpl_table* tbl_line_list=NULL;
+
+  FitParams** par=NULL;
+
+  cpl_frameset* stk=NULL;
+  cpl_table* qclog_tbl=NULL;
+
+  cpl_polynomial* distor_poly=NULL;
+  cpl_apertures       *   arcs=NULL ;
+  cpl_parameter* p=NULL;
+  int smooth_rad=0;
+
+
+  check_nomsg(p=cpl_parameterlist_find(config,"sinfoni.product.density"));
+  check_nomsg(pdensity=cpl_parameter_get_int(p));
+
+  /*
+    parse the file names and parameters to the finddist_config
+    data structure cfg
+   */
+  check_nomsg(stk=cpl_frameset_new());
+  cknull(cfg = sinfo_parse_cpl_input_finddist(config,sof,&stk),
+     "could not parse CPL input!");
+
+  if(sinfo_is_fits_file (cfg->inFrame) != 1) {
+    sinfo_msg_error("Input file %s is not FITS",cfg->inFrame);
+    goto cleanup;
+  }
+
+  /* load the emission line frame--- */
+  check(im = cpl_image_load(cfg->inFrame,CPL_TYPE_FLOAT,0,0),
+    "could not load arc image");
+
+  /* load the fake on - fake off frame--- */
+  check(imonind = cpl_image_load(cfg->nsFrame,CPL_TYPE_FLOAT,0,0),
+    "could not load on-off fake image");
+
+  check(impoly  = cpl_image_load(cfg->nsFrame,CPL_TYPE_FLOAT,0,0),
+    "could not load on-off fake image");
+
+  /* load the fake on - fake off frame--- */
+  check(mask = cpl_image_load(cfg->mask,CPL_TYPE_FLOAT,0,0),
+    "could not load mask image");
+
+  check(cpl_image_multiply (im,mask),
+    "Failing to correct arc ima by bp mask");
+
+  check(cpl_image_multiply (imonind,mask),
+    "Failing to correct on-off fake ima by bp mask");
+
+  check(cpl_image_multiply(impoly,mask),
+    "Failing to correct on-off fake ima by bp mask");
+
+  sinfo_free_image(&mask);
+
+  check_nomsg(lx = cpl_image_get_size_x(im));
+  check_nomsg(ly = cpl_image_get_size_y(im));
+  /* TO BE CHENGED THE FOLLOWING INPUT */
+  /* open the line list and read the number of lines */
+  check(tbl_line_list = cpl_table_load(cfg->lineList,1,0),
+    "problems loading table %s",cfg->lineList);
+
+  check_nomsg(n_lines = cpl_table_get_nrow(tbl_line_list));
+  check_nomsg(wave=cpl_table_get_data_float(tbl_line_list,"wave"));
+  check_nomsg(intens = cpl_table_get_data_float(tbl_line_list,"int"));
+
+  /*
+       #---------------------------------------------------------------------
+       #---------------------------FINDLINES---------------------------------
+       #---------------------------------------------------------------------
+  */
+
+  sinfo_msg("Find Lines");
+  /*
+       do the wavelength calibration, that means:
+       find the dispersion relation and parameterize its coefficients
+  */
+
+  acoefs  = sinfo_new_2Dfloatarray(cfg->nrDispCoefficients, lx);
+  /* allocate memory */
+  n_found_lines    = sinfo_new_intarray(lx);
+  row_clean        = sinfo_new_2Dintarray(lx, n_lines);
+  wavelength_clean = sinfo_new_2Dfloatarray(lx, n_lines);
+  sum_pointer      = sinfo_new_intarray(1);
+
+  /* find the emission lines in each image column */
+  sinfo_new_intarray_set_value(sum_pointer, 0, 0);
+
+  ck0(check = sinfo_new_find_lines(im,
+                   wave,
+                   intens,
+                   n_lines,
+                   row_clean,
+                   wavelength_clean,
+                   cfg->guessBeginWavelength,
+                   cfg->guessDispersion1,
+                   cfg->guessDispersion2,
+                   cfg->mindiff,
+                   cfg->halfWidth,
+                   n_found_lines,
+                   cfg->sigma,
+                   sum_pointer ),
+      "FindLines failed!");
+
+  sinfo_free_table(&tbl_line_list);
+
+  /*
+   #-------------------------------------------------------------------------
+   #---------------------------WAVECALIB-------------------------------------
+   #-------------------------------------------------------------------------
+    */
+  sinfo_msg("Do wave calib");
+  sum = sinfo_new_intarray_get_value(sum_pointer,0);
+
+  /* #allocate memory for the fit parameters */
+  cknull(par = sinfo_new_fit_params( sum ),
+     "sinfo_new_fit_params failed!");
+
+  /*
+      fit each line, make a polynomial fit and fit the resulting fit
+       coefficients across the columns of the slitlet
+  */
+  cknull(map = sinfo_new_wave_cal(im,
+                             par,
+                      acoefs,
+                      cfg->nslitlets,
+                      row_clean,
+                      wavelength_clean,
+                      n_found_lines,
+                      cfg->guessDispersion1,
+                      cfg->halfWidth,
+                      cfg->minAmplitude,
+                      cfg->maxResidual,
+                      cfg->fwhm,
+                      cfg->nrDispCoefficients,
+                      cfg->nrCoefCoefficients,
+                      cfg->sigmaFactor,
+                      cfg->pixeldist,
+                      cfg->pixel_tolerance),
+     "sinfo_waveCal failed!");
+  /* here mem leak */
+
+  sinfo_msg("Check line positions");
+  shift = sinfo_new_check_line_positions (im, acoefs,
+                                          cfg->nrDispCoefficients,
+                                          cfg->guessDispersion1,par);
+
+  if (FLAG == shift) {
+    sinfo_msg_error ( "checkForLinePositions failed!");
+    goto cleanup;
+  }
+  sinfo_free_image(&map);
+
+
+ /* free memory */
+  sinfo_new_destroy_2Dfloatarray ( &wavelength_clean, lx );
+  sinfo_new_destroy_2Dintarray (&row_clean, lx);
+  sinfo_new_destroy_intarray(&n_found_lines );
+  sinfo_new_destroy_intarray(&sum_pointer );
+  sinfo_new_destroy_2Dfloatarray ( &acoefs, cfg->nrDispCoefficients );
+  /*
+  sinfo_new_destroy_array (& wave );
+  sinfo_new_destroy_array (& intens );
+  */
+  /*
+  #----------------------------------------------------------------------------
+  #-------------------------SLITFITS-------------------------------------------
+  #----------------------------------------------------------------------------
+  #--fit the slitlet sinfo_edge positions if desired--
+  */
+
+  sinfo_msg("Find slit pos");
+  /*allocate memory for the slitlet position array */
+  slit_pos = sinfo_new_2Dfloatarray(32,2);
+
+  fit = sinfo_new_fit_slits_boltz( im, par, slit_pos, cfg->boxLength,
+                      cfg->yBox, cfg->diffTol );
+
+
+  if (fit < 0) {
+    sinfo_msg_error( "sinfo_fitSlitsBoltz failed" );
+    goto cleanup;
+  }
+  sinfo_new_destroy_fit_params(&par);
+
+  check_nomsg(tbl_spos=cpl_table_new(32));
+  check_nomsg(cpl_table_new_column(tbl_spos,"pos1", CPL_TYPE_DOUBLE));
+  check_nomsg(cpl_table_new_column(tbl_spos,"pos2", CPL_TYPE_DOUBLE));
+  check_nomsg(cpl_table_set_column_format(tbl_spos,"pos1", "15.9f"));
+  check_nomsg(cpl_table_set_column_format(tbl_spos,"pos2", "15.9f"));
+
+  for (i =0; i< 32; i++) {
+      check_nomsg(cpl_table_set_double(tbl_spos,"pos1",i,
+                                sinfo_new_array2D_get_value(slit_pos,i,0)));
+      check_nomsg(cpl_table_set_double(tbl_spos,"pos2",i,
+                                sinfo_new_array2D_get_value(slit_pos,i,1)));
+
+  }
+
+  if(pdensity > 2) {
+    strcpy(tbl_name,"out_slitlets_pos_predist.fits");
+    ck0(sinfo_pro_save_tbl(tbl_spos,set_fibre_ns,sof,tbl_name,
+			   PRO_SLITLETS_POS_PREDIST,NULL,plugin_id,config),
+	"cannot save tbl %s", tbl_name);
+  }
+  sinfo_free_table(&tbl_spos);
+
+  /*
+  #---------------------------------------------------------
+  # do the north - south - test
+  #---------------------------------------------------------
+  */
+  sinfo_msg("Do north south test");
+  /*
+  sinfo_msg("cfg->nslits =%d\n", cfg->nslits);
+  sinfo_msg("cfg->nshalfWidth =%d\n", cfg->nshalfWidth);
+  sinfo_msg("cfg->nsfwhm=%f\n",cfg->nsfwhm );
+  sinfo_msg("cfg->minDiff=%f\n", cfg->minDiff);
+  sinfo_msg("cfg->estimated_dist=%f\n", cfg->estimated_dist);
+  sinfo_msg("cfg->devtol=%f\n", cfg->devtol);
+  sinfo_msg("cfg->loPos=%d\n", cfg->loPos);
+  sinfo_msg("cfg->hiPos=%d\n",cfg->hiPos);
+  */
+  cknull(distances = sinfo_north_south_test(imonind,
+                      cfg->nslits,
+                      cfg->nshalfWidth,
+                      cfg->nsfwhm ,
+                      cfg->minDiff,
+                      cfg->estimated_dist,
+                      cfg->devtol,
+                      cfg->loPos,
+                      cfg->hiPos),
+     "north_south_test failed");
+
+  sinfo_free_image(&imonind);
+
+  /*
+  #---------------------------------------------------------
+  # get firstcol
+  #---------------------------------------------------------
+  */
+  sinfo_msg("get first col");
+  first = sinfo_new_floatarray(61);
+  total_dist=0;
+  n=0;
+
+  for (i=0; i< 31; i++) {
+    total_dist=total_dist+sinfo_new_array_get_value(distances,i);
+
+    for (j=0; j< 2; j++) {
+      if (j == 0) {
+        if (i != 30) {
+      newval = sinfo_new_array2D_get_value(slit_pos,i+1,j) - total_dist;
+      sinfo_new_array_set_value(first, newval, n);
+      n = n+1;
+        }
+      }
+      if (j == 1) {
+        newval = sinfo_new_array2D_get_value(slit_pos,i,j) - total_dist;
+        sinfo_new_array_set_value(first, newval, n);
+        n = n+1;
+      }
+    }
+  }
+  value = sinfo_new_f_median(first,61);
+  sinfo_msg("Firstcol =%f", value);
+  sinfo_new_destroy_array(&first);
+  sinfo_new_destroy_array(&distances);
+  sinfo_new_destroy_2Dfloatarray ( &slit_pos, 32 );
+
+  /*
+  #---------------------------------------------------------
+  # Determine distortions
+  #---------------------------------------------------------
+  */
+  sinfo_msg("Determine distortions");
+  degx=cpl_calloc(8,sizeof(int));
+  degy=cpl_calloc(8,sizeof(int));
+  coef=cpl_calloc(8,sizeof(double));
+
+  check_nomsg(p=cpl_parameterlist_find(config,
+                "sinfoni.distortion.arcs_thresh_factor"));
+  check_nomsg(arcs_thres_factor=cpl_parameter_get_double(p));
+
+  check_nomsg(p=cpl_parameterlist_find(config,
+                "sinfoni.distortion.arcs_min_arclen_factor"));
+  check_nomsg(arcs_min_arclen_factor=cpl_parameter_get_double(p));
+
+  check_nomsg(p=cpl_parameterlist_find(config,
+                "sinfoni.distortion.arcs_window_size"));
+  check_nomsg(arcs_window_size=cpl_parameter_get_int(p));
+
+  check_nomsg(p=cpl_parameterlist_find(config,
+                "sinfoni.distortion.smooth_rad"));
+  check_nomsg(smooth_rad=cpl_parameter_get_int(p));
+
+
+  cknull(distor_poly=sinfo_distortion_estimate_new(impoly,
+						   0,
+						   0,
+                                                 cpl_image_get_size_x(impoly),
+                                                 cpl_image_get_size_y(impoly),
+                                                   FALSE,
+                                                   SINFO_ARC_SATURATION,
+                                                   SINFO_ARC_MAX_WIDTH,
+                                                   arcs_thres_factor,
+                                                   arcs_min_arclen_factor,
+                                                   arcs_window_size,
+                                                   smooth_rad,
+                                                   3,
+                                                   (double)value,
+                                                   &arcs),
+     "cannot estimage distortion") ;
+  /*AMo: additional mem leaks */
+
+  sinfo_free_apertures(&arcs);
+  coef_pow[0]=0;
+  coef_pow[1]=0;
+  check_nomsg(pcf[0][0]=cpl_polynomial_get_coeff(distor_poly,coef_pow));
+  sinfo_msg("Polynomial fit results: coeff[%d][%d]=%g",0,0,pcf[0][0]);
+  /*
+  pcf[0][0]+=value;
+  */
+  sinfo_msg("Polynomial fit results: coeff[%d][%d]=%g",0,0,pcf[0][0]);
+  check_nomsg(cpl_polynomial_set_coeff(distor_poly,coef_pow,pcf[0][0]));
+
+  /* up to here ok */
+  /* To check mem leaks */
+  sinfo_free_image(&impoly);
+
+  //sinfo_msg("Polynomial fit results: deg=%d",
+  //      cpl_polynomial_get_degree(distor_poly));
+
+
+  coef_pow[0]=0;
+  coef_pow[1]=0;
+  check_nomsg(pcf[0][0]=cpl_polynomial_get_coeff(distor_poly,coef_pow));
+  //sinfo_msg("Polynomial fit results: coeff[%d][%d]=%g",0,0,pcf[0][0]);
+
+  coef_pow[0]=1;
+  coef_pow[1]=0;
+  check_nomsg(pcf[1][0]=cpl_polynomial_get_coeff(distor_poly,coef_pow));
+  //sinfo_msg("Polynomial fit results: coeff[%d][%d]=%g",1,0,pcf[1][0]);
+
+  coef_pow[0]=0;
+  coef_pow[1]=1;
+  check_nomsg(pcf[0][1]=cpl_polynomial_get_coeff(distor_poly,coef_pow));
+  //sinfo_msg("Polynomial fit results: coeff[%d][%d]=%g",0,1,pcf[0][1]);
+
+  coef_pow[0]=1;
+  coef_pow[1]=1;
+  check_nomsg(pcf[1][1]=cpl_polynomial_get_coeff(distor_poly,coef_pow));
+  //sinfo_msg("Polynomial fit results: coeff[%d][%d]=%g",1,1,pcf[1][1]);
+
+  coef_pow[0]=2;
+  coef_pow[1]=0;
+  check_nomsg(pcf[2][0]=cpl_polynomial_get_coeff(distor_poly,coef_pow));
+  //sinfo_msg("Polynomial fit results: coeff[%d][%d]=%g",2,0,pcf[2][0]);
+
+  coef_pow[0]=0;
+  coef_pow[1]=2;
+  check_nomsg(pcf[0][2]=cpl_polynomial_get_coeff(distor_poly,coef_pow));
+  //sinfo_msg("Polynomial fit results: coeff[%d][%d]=%g",0,2,pcf[0][2]);
+
+  coef_pow[0]=2;
+  coef_pow[1]=1;
+  check_nomsg(pcf[2][1]=cpl_polynomial_get_coeff(distor_poly,coef_pow));
+  //sinfo_msg("Polynomial fit results: coeff[%d][%d]=%g",2,1,pcf[2][1]);
+
+  coef_pow[0]=1;
+  coef_pow[1]=2;
+  check_nomsg(pcf[1][2]=cpl_polynomial_get_coeff(distor_poly,coef_pow));
+  //sinfo_msg("Polynomial fit results: coeff[%d][%d]=%g",1,2,pcf[1][2]);
+
+  coef_pow[0]=3;
+  coef_pow[1]=0;
+  check_nomsg(pcf[3][0]=cpl_polynomial_get_coeff(distor_poly,coef_pow));
+  //sinfo_msg("Polynomial fit results: coeff[%d][%d]=%g",3,0,pcf[3][0]);
+
+  coef_pow[0]=0;
+  coef_pow[1]=3;
+  check_nomsg(pcf[0][3]=cpl_polynomial_get_coeff(distor_poly,coef_pow));
+  //sinfo_msg("Polynomial fit results: coeff[%d][%d]=%g",0,3,pcf[0][3]);
+
+  sinfo_msg("Save results");
+
+  check_nomsg(poly_tbl=cpl_table_new(10));
+  check_nomsg(cpl_table_new_column(poly_tbl,"degx", CPL_TYPE_INT));
+  check_nomsg(cpl_table_new_column(poly_tbl,"degy", CPL_TYPE_INT));
+  check_nomsg(cpl_table_new_column(poly_tbl,"coeff", CPL_TYPE_DOUBLE));
+  check_nomsg(cpl_table_set_int(poly_tbl,"degx",0,0));
+  check_nomsg(cpl_table_set_int(poly_tbl,"degx",1,1));
+  check_nomsg(cpl_table_set_int(poly_tbl,"degx",2,0));
+  check_nomsg(cpl_table_set_int(poly_tbl,"degx",3,1));
+  check_nomsg(cpl_table_set_int(poly_tbl,"degx",4,2));
+  check_nomsg(cpl_table_set_int(poly_tbl,"degx",5,0));
+  check_nomsg(cpl_table_set_int(poly_tbl,"degx",6,2));
+  check_nomsg(cpl_table_set_int(poly_tbl,"degx",7,1));
+  check_nomsg(cpl_table_set_int(poly_tbl,"degx",8,3));
+  check_nomsg(cpl_table_set_int(poly_tbl,"degx",9,0));
+
+  check_nomsg(cpl_table_set_int(poly_tbl,"degy",0,0));
+  check_nomsg(cpl_table_set_int(poly_tbl,"degy",1,0));
+  check_nomsg(cpl_table_set_int(poly_tbl,"degy",2,1));
+  check_nomsg(cpl_table_set_int(poly_tbl,"degy",3,1));
+  check_nomsg(cpl_table_set_int(poly_tbl,"degy",4,0));
+  check_nomsg(cpl_table_set_int(poly_tbl,"degy",5,2));
+  check_nomsg(cpl_table_set_int(poly_tbl,"degy",6,1));
+  check_nomsg(cpl_table_set_int(poly_tbl,"degy",7,2));
+  check_nomsg(cpl_table_set_int(poly_tbl,"degy",8,0));
+  check_nomsg(cpl_table_set_int(poly_tbl,"degy",9,3));
+
+  check_nomsg(cpl_table_set_double(poly_tbl,"coeff",0,pcf[0][0]));
+  check_nomsg(cpl_table_set_double(poly_tbl,"coeff",1,pcf[1][0]));
+  check_nomsg(cpl_table_set_double(poly_tbl,"coeff",2,pcf[0][1]));
+  check_nomsg(cpl_table_set_double(poly_tbl,"coeff",3,pcf[1][1]));
+  check_nomsg(cpl_table_set_double(poly_tbl,"coeff",4,pcf[2][0]));
+  check_nomsg(cpl_table_set_double(poly_tbl,"coeff",5,pcf[0][2]));
+  check_nomsg(cpl_table_set_double(poly_tbl,"coeff",6,pcf[2][1]));
+  check_nomsg(cpl_table_set_double(poly_tbl,"coeff",7,pcf[1][2]));
+  check_nomsg(cpl_table_set_double(poly_tbl,"coeff",8,pcf[3][0]));
+  check_nomsg(cpl_table_set_double(poly_tbl,"coeff",9,pcf[0][3]));
+
+  //sinfo_msg("Polynomial distortion coefficients \n");
+  //sinfo_msg("c= %g   %g  %g  %g  %g  %g  %g  %g %g %g\n",
+  //       pcf[0][0],pcf[1][0],pcf[0][1],pcf[1][1],
+  //           pcf[2][0],pcf[0][2],pcf[2][1],pcf[1][2],pcf[3][0],pcf[0][3]);
+
+  /* QC LOG */
+  check_nomsg(qclog_tbl = sinfo_qclog_init());
+  snprintf(key_name,MAX_NAME_SIZE-1,"%s%d%d","QC COEFF",0,0);
+  ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,key_name,pcf[0][0],
+             "Polynomial distortion coefficient","%g"));
+
+  snprintf(key_name,MAX_NAME_SIZE-1,"%s%d%d","QC COEFF",1,0);
+  ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,key_name,pcf[1][0],
+             "Polynomial distortion coefficient","%g"));
+
+  snprintf(key_name,MAX_NAME_SIZE-1,"%s%d%d","QC COEFF",0,1);
+  ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,key_name,pcf[0][1],
+             "Polynomial distortion coefficient","%g"));
+
+  snprintf(key_name,MAX_NAME_SIZE-1,"%s%d%d","QC COEFF",1,1);
+  ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,key_name,pcf[1][1],
+             "Polynomial distortion coefficient","%g"));
+
+  snprintf(key_name,MAX_NAME_SIZE-1,"%s%d%d","QC COEFF",2,0);
+  ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,key_name,pcf[2][0],
+             "Polynomial distortion coefficient","%g"));
+
+  snprintf(key_name,MAX_NAME_SIZE-1,"%s%d%d","QC COEFF",0,2);
+  ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,key_name,pcf[0][2],
+             "Polynomial distortion coefficient","%g"));
+
+  snprintf(key_name,MAX_NAME_SIZE-1,"%s%d%d","QC COEFF",2,1);
+  ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,key_name,pcf[2][1],
+             "Polynomial distortion coefficient","%g"));
+
+  snprintf(key_name,MAX_NAME_SIZE-1,"%s%d%d","QC COEFF",1,2);
+  ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,key_name,pcf[1][2],
+             "Polynomial distortion coefficient","%g"));
+
+  snprintf(key_name,MAX_NAME_SIZE-1,"%s%d%d","QC COEFF",3,0);
+  ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,key_name,pcf[3][0],
+             "Polynomial distortion coefficient","%g"));
+
+  snprintf(key_name,MAX_NAME_SIZE-1,"%s%d%d","QC COEFF",0,3);
+  ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,key_name,pcf[0][3],
+             "Polynomial distortion coefficient","%g"));
+
+  snprintf(key_name,MAX_NAME_SIZE-1,"%s","QC OFFSET");
+  ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,key_name,value,
+             "Polynomial distortion coefficient","%g"));
+
+  xshift=new_compute_shift(x_c,y_c,pcf[0][0],pcf[1][0],pcf[0][1],
+                                   pcf[1][1],pcf[2][0],pcf[0][2],
+                                   pcf[2][1],pcf[1][2],pcf[3][0],pcf[0][3]);
+
+  ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC XSHIFT CC",xshift,
+                                   "X shift in x_c,y_c","%g"));
+
+
+  xshift=new_compute_shift(x_l,y_l,pcf[0][0],pcf[1][0],pcf[0][1],
+                                   pcf[1][1],pcf[2][0],pcf[0][2],
+                                   pcf[2][1],pcf[1][2],pcf[3][0],pcf[0][3]);
+
+  ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC XSHIFT LL",xshift,
+                                   "X shift in x_l,y_l","%g"));
+
+  xshift=new_compute_shift(x_l,y_u,pcf[0][0],pcf[1][0],pcf[0][1],
+                                   pcf[1][1],pcf[2][0],pcf[0][2],
+                                   pcf[2][1],pcf[1][2],pcf[3][0],pcf[0][3]);
+
+  ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC XSHIFT UL",xshift,
+                                   "X shift in x_l,y_u","%g"));
+
+  xshift=new_compute_shift(x_u,y_u,pcf[0][0],pcf[1][0],pcf[0][1],
+                                   pcf[1][1],pcf[2][0],pcf[0][2],
+                                   pcf[2][1],pcf[1][2],pcf[3][0],pcf[0][3]);
+
+  ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC XSHIFT UR",xshift,
+                                   "X shift in x_u,y_u","%g"));
+
+
+  xshift=new_compute_shift(x_u,y_l,pcf[0][0],pcf[1][0],pcf[0][1],
+                                   pcf[1][1],pcf[2][0],pcf[0][2],
+                                   pcf[2][1],pcf[1][2],pcf[3][0],pcf[0][3]);
+
+  ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC XSHIFT LR",xshift,
+                                   "X shift in x_u,y_l","%g"));
+
+
+  ck0(sinfo_pro_save_tbl(poly_tbl,set_fibre_ns,sof,cfg->outName,
+             PRO_DISTORTION,qclog_tbl,plugin_id,config),
+      "cannot dump tbl %s", cfg->outName);
+
+  sinfo_free_table(&poly_tbl);
+  sinfo_free_table(&qclog_tbl);
+  sinfo_free_polynomial(&distor_poly);
+  sinfo_free_int(&degx);
+  sinfo_free_int(&degy);
+  sinfo_free_double(&coef);
+  sinfo_free_image(&im);
+  sinfo_free_frameset(&stk);
+  sinfo_finddist_free (&cfg);
+
+  return 0;
+
+ cleanup:
+  sinfo_free_table(&poly_tbl);
+  sinfo_free_table(&qclog_tbl);
+  sinfo_free_polynomial(&distor_poly);
+  sinfo_free_int(&degx);
+  sinfo_free_int(&degy);
+  sinfo_free_double(&coef);
+  sinfo_free_apertures(&arcs);
+
+
+
+  /*if(wave != NULL) sinfo_new_destroy_array (& wave );*/
+  /*if(intens != NULL) sinfo_new_destroy_array (& intens );*/
+  if(first != NULL) sinfo_new_destroy_array(&first);
+  sinfo_free_table(&tbl_spos);
+  if(slit_pos != NULL) sinfo_new_destroy_2Dfloatarray (&slit_pos,32);
+  if(distances != NULL) sinfo_new_destroy_array(&distances);
+  if(par!=NULL) sinfo_new_destroy_fit_params(&par);
+  if(n_found_lines != NULL) sinfo_new_destroy_intarray(&n_found_lines );
+  if(row_clean != NULL) sinfo_new_destroy_2Dintarray(&row_clean, lx);
+  if(wavelength_clean != NULL) {
+      sinfo_new_destroy_2Dfloatarray(&wavelength_clean,lx);
+  }
+  if(sum_pointer != NULL) sinfo_new_destroy_intarray(&sum_pointer);
+  if(acoefs != NULL) {
+      sinfo_new_destroy_2Dfloatarray(&acoefs, cfg->nrDispCoefficients );
+  }
+  sinfo_free_table(&tbl_line_list);
+  sinfo_free_image(&mask);
+  sinfo_free_image(&impoly);
+  sinfo_free_image(&imonind);
+  sinfo_free_image(&map);
+  sinfo_free_image(&im);
+  sinfo_finddist_free (&cfg);
+  sinfo_free_frameset(&stk);
+  return -1;
+
+}
+
+
+static double
+new_compute_shift(double x,
+              double y,
+              double c00,
+              double c10,
+              double c01,
+              double c11,
+              double c20,
+              double c02,
+              double c21,
+              double c12,
+              double c30,
+              double c03)
+{
+
+  double x_shift=0;
+  double shift=0;
+  //sinfo_msg("c= %g   %g  %g  %g  %g  %g  %g  %g %g %g\n",
+  //       c00,c10,c01,c11,
+  //       c20,c02,c21,c12,c30,c03);
+
+  shift=c00+c10*x+c01*y+
+        c11*x*y+c20*x*x+c02*y*y+
+        c21*x*x*y+c12*x*y*y+c30*x*x*x+c03*y*y*y;
+  x_shift=x-shift;
+  return x_shift;
+
+
+
+}
+/**@}*/
diff --git a/sinfoni/sinfo_new_find_distortions.h b/sinfoni/sinfo_new_find_distortions.h
new file mode 100644
index 0000000..0cc7639
--- /dev/null
+++ b/sinfoni/sinfo_new_find_distortions.h
@@ -0,0 +1,65 @@
+#ifndef SINFO_NEW_FIND_DISTORTIONS_H
+#define SINFO_NEW_FIND_DISTORTIONS_H
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/****************************************************************************
+* E.S.O. - VLT project
+*
+* "@(#) $Id: sinfo_new_find_distortions.h,v 1.9 2007/09/14 14:40:04 amodigli Exp $"
+*
+* who       when      what
+* --------  --------  ----------------------------------------------
+* amodigli  12/08/04  created
+*/
+
+/************************************************************************
+ * sinfo_find_distortions.h
+
+ *----------------------------------------------------------------------
+ */
+
+/*
+ * header files
+ */
+
+#include <cpl.h>   
+#include "sinfo_msg.h"
+
+
+/*----------------------------------------------------------------------------
+ *                        Function ANSI C prototypes
+ *--------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+   Function     :       sinfo_find_distortions()
+   In           :       
+   Out          :        
+   Job          :
+
+ ---------------------------------------------------------------------------*/
+int 
+sinfo_new_find_distortions (const char* plugin_id,
+                            cpl_parameterlist* config, 
+                            cpl_frameset* sof,
+			    cpl_frameset* set_fibre_ns) ;
+
+
+#endif 
+
+/*--------------------------------------------------------------------------*/
diff --git a/sinfoni/sinfo_new_lamp_flats.c b/sinfoni/sinfo_new_lamp_flats.c
new file mode 100644
index 0000000..6daab9d
--- /dev/null
+++ b/sinfoni/sinfo_new_lamp_flats.c
@@ -0,0 +1,1009 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+ 
+     File name    :       sinfo_new_lamp_flats.c
+   Author       :    A. Modigliani
+   Created on   :    Sep 29, 2003
+   Description  : 
+
+ * this step handles stacks of lamp flat fields, 
+ *  o it takes a clean mean,
+ *  o subtracts the off- from the on-frames, 
+ *  o corrects for static bad pixels and normalizes for a master flat field. 
+ *  o It distinguishes the spectrally dithered frames and 
+ *  o treats them the same way. 
+ *  o It can also generate a static bad pixel mask if wished.
+
+
+ ---------------------------------------------------------------------------*/
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+/*----------------------------------------------------------------------------
+                                Includes
+ ---------------------------------------------------------------------------*/
+#include "sinfo_new_lamp_flats.h"
+#include "sinfo_flat_ini_by_cpl.h"
+#include "sinfo_pro_save.h"
+#include "sinfo_pro_types.h"
+#include "sinfo_functions.h"
+#include "sinfo_new_cube_ops.h"
+#include "sinfo_error.h"
+#include "sinfo_utils_wrappers.h"
+#include "sinfo_image_ops.h"
+#include "sinfo_utilities.h"
+#include "sinfo_globals.h"
+/*----------------------------------------------------------------------------
+                                Defines
+ ---------------------------------------------------------------------------*/
+
+static int 
+new_qc_get_cnt(cpl_frameset* on_set, cpl_frameset* of_set, flat_config* cfg);
+static int 
+new_lamp_flats_det_ncounts(cpl_frameset* raw, flat_config* config);
+
+static struct {
+
+  double avg_on; 
+  double std_on;
+  double avg_of; 
+  double std_of;
+  double avg_di; 
+  double std_di;
+  double nsat_on;
+  double noise_on;
+  double noise_of;
+  double flux_on;
+  double    nsat;
+
+} qc_lampflat;
+
+/*----------------------------------------------------------------------------
+                             Function Definitions
+ ---------------------------------------------------------------------------*/
+/**@{*/
+/**
+ * @addtogroup sinfo_lamp_cfg Flat frame manipulation functions
+ *
+ * TBD
+ */
+
+/*----------------------------------------------------------------------------
+   @name  sinfo_new_lamp_flats()
+   @param  plugin_id recipe id
+   @param  config input parameterlist
+   @param  sof    input set of frames
+   @return integer (0 if it worked, -1 if it doesn't) 
+   @doc 
+
+ * this step handles stacks of lamp flat fields, 
+ *  o it takes a clean mean,
+ *  o subtracts the off- from the on-frames, 
+ *  o corrects for static bad pixels and normalizes for a master flat field. 
+ *  o It distinguishes the spectrally dithered frames and 
+ *  o treats them the same way. 
+ *  o It can also generate a static bad pixel mask if wished.
+
+
+ ---------------------------------------------------------------------------*/
+
+
+
+
+int 
+sinfo_new_lamp_flats (const char* plugin_id, 
+                      cpl_parameterlist* config, 
+                      cpl_frameset* sof,
+                      cpl_frameset* ref_set)
+{
+  flat_config * cfg =NULL;
+  cpl_imagelist* list_object=NULL;
+  cpl_imagelist* list_dither_object=NULL ;
+  cpl_imagelist* list_sky=NULL ;
+  cpl_imagelist* list_dither_sky=NULL;
+  cpl_image ** im=NULL ;
+  cpl_image * norm_dith =NULL;
+  cpl_image * im_obj =NULL;
+  cpl_image * int_im =NULL;
+  cpl_image * int_im_dith =NULL;
+  cpl_image * im_sky =NULL;
+  cpl_image * im_dither =NULL;
+  cpl_image * im_obj_sub =NULL;
+  cpl_image * im_dither_sub =NULL;
+  cpl_image * im_dither_sky =NULL;
+  cpl_image ** imMed=NULL ;
+  cpl_image * colImage =NULL;
+  cpl_image * mask_im =NULL;
+  cpl_image * norm =NULL;
+  cpl_image * compImage =NULL;
+  cpl_image * maskImage =NULL;
+  cpl_image * threshIm =NULL;
+
+  char name[MAX_NAME_SIZE];
+
+  int typ;
+  Stats * stats =NULL;
+  int i = 0;
+  int* n=NULL;
+  int nob =0;
+  int nsky = 0; 
+  int nobjdith = 0;
+  int nskydith = 0; 
+  int n_badpixels =0;
+  int pos =0;
+
+  float** slit_edges=NULL;
+  float local_clean_mean =0.;
+  float clean_stdev =0.;
+  float mean_factor =0.;
+  float val_x=0;
+  float val_y=0;
+
+  char outNameDither[MAX_NAME_SIZE];
+  char name_list[MAX_NAME_SIZE];
+  char tbl_slitpos_name[MAX_NAME_SIZE];
+
+  cpl_table* tbl_slitpos=NULL;
+  int* status=NULL;
+
+  int n_im_med=0;
+  cpl_frameset* raw=NULL;
+
+  cpl_table* qclog_tbl=NULL;
+  int naxis1=0;
+  int naxis2=0;
+  double fpn_stdev1=0;
+  double fpn_stdev2=0;
+
+  int no=0;
+  float lo_cut=0;
+  float hi_cut=0;
+
+  /*
+       -----------------------------------------------------------------
+       1) parse the file names and parameters to the tilt_config data 
+          structure cfg 
+       -----------------------------------------------------------------
+  */
+
+  cknull_nomsg(raw=cpl_frameset_new());
+
+  cknull(cfg = sinfo_parse_cpl_input_flat(config,sof,&raw),
+     "could not parse cpl input!");
+
+  if (cfg->interpolInd == 1) {
+    if(sinfo_is_fits_file(cfg->mask) != 1) {
+      sinfo_msg_error("Input file %s is not FITS",cfg->mask);
+      goto cleanup;
+    }
+    if (sinfo_is_fits_file(cfg->slitposList) != 1) {
+      sinfo_msg_error("Input file %s is not FITS",cfg->slitposList);
+      goto cleanup;
+    }
+  }
+
+  /*
+    #---------------------------------------------------------
+    # Take a clean mean of several images
+    # input is 1 or more similar images
+    #---------------------------------------------------------
+  */
+  sinfo_msg("Takes clean mean of several images");
+  /* #allocate memory for lists of object, sky and dithered frames--*/
+  cknull(list_object = cpl_imagelist_new (),"could not allocate memory");
+
+  if (cfg->contains_dither == 1) {
+    cknull(list_dither_object=cpl_imagelist_new(),"could not allocate memory");
+  }
+
+  if (cfg->contains_sky == 1) {
+    cknull(list_sky=cpl_imagelist_new(),"could not allocate memory");
+  }
+
+  if (cfg->contains_dither == 1 && cfg->nditheroff > 0) {
+    cknull(list_dither_sky=cpl_imagelist_new(),"could not allocate memory");
+  }
+
+  if (cfg->contains_dither == 0 && cfg->nditheroff > 0){
+    sinfo_msg_error("please use non-dithered off-frames, remove the 2!");
+    goto cleanup;
+  }
+ 
+
+  /* problem with im as image holder: cleanup then does not work */
+  im = (cpl_image**) cpl_calloc (cfg -> nframes, sizeof(cpl_image*)); 
+
+  for (i=0; i< cfg->nframes; i++) {
+    strcpy(name,cfg->framelist[i]);
+    if(sinfo_is_fits_file(name) != 1) {
+      sinfo_msg_error("PP Input file %s %d is not FITS",name,i);
+      goto cleanup;
+    }
+    im[i]=cpl_image_load(name,CPL_TYPE_FLOAT,0,0);
+
+  }
+
+  for (i=0; i< cfg->nframes; i++) {
+    typ = cfg->frametype[i];
+    pos = cfg->frameposition[i];
+    cknull(im[i],"could not load image %d",i);
+    if (pos == 2) {
+      if (typ == 1) {
+        cpl_imagelist_set( list_object, cpl_image_duplicate(im[i]), nob );  
+        nob = nob + 1;
+      } else {
+        cpl_imagelist_set( list_sky, cpl_image_duplicate(im[i]), nsky );
+        nsky = nsky + 1 ;
+      }
+    } else {
+      if (typ == 1) {
+        cpl_imagelist_set(list_dither_object, 
+                          cpl_image_duplicate(im[i]), nobjdith );  
+        nobjdith = nobjdith + 1;
+      } else {
+        cpl_imagelist_set( list_dither_sky, 
+                          cpl_image_duplicate(im[i]), nskydith );
+        nskydith = nskydith + 1 ;
+      }
+    }
+  }
+
+
+  if (nob != cfg->nobj || cfg->noff != nsky || 
+      nobjdith != cfg->nditherobj || nskydith != cfg->nditheroff) {
+      sinfo_msg_error("something is wrong with the number of "
+                      "the different types of frames");
+      goto cleanup;
+  }
+
+  /* # create and fill cubes with the different image lists- */
+  sinfo_msg("Creates and fills cubes with the different image lists");
+  cknull(list_object,"could not create data cube!");
+
+  if (cfg->contains_dither == 1) {
+    cknull(list_dither_object,"could not create data cube!");
+  }
+  if (cfg->contains_sky == 1 && nsky > 0) {
+    cknull(list_sky,"could not create data cube!");
+  }
+
+  if (cfg->contains_dither == 1 && nskydith > 0) {
+    cknull(list_dither_sky,"could not create data cube!");
+  }
+
+ 
+  /*-take the average of the different cubes -*/
+  sinfo_msg("Takes the average of the different cubes");
+  if (cfg->loReject*cfg->nobj < 1. && cfg->hiReject *cfg->nobj < 1.) {
+    cknull(im_obj = sinfo_new_average_cube_to_image(list_object ),
+          "sinfo_averageCubeToImage failed" );
+  } else {
+
+    no=cpl_imagelist_get_size(list_object);
+    lo_cut=(floor)(cfg->loReject*no+0.5);
+    hi_cut=(floor)(cfg->hiReject*no+0.5);
+    cknull(im_obj=cpl_imagelist_collapse_minmax_create(list_object,
+                                                      lo_cut,
+                                                      hi_cut),
+                 "sinfo_average_with_rejection failed" );
+  }
+   sinfo_free_imagelist(&list_object);
+
+  if (cfg->contains_sky == 1) {
+    if (cfg->loReject * nsky < 1. && cfg->hiReject * nsky < 1.) {
+      cknull(im_sky = sinfo_new_average_cube_to_image(list_sky ),
+      "sinfo_new_average_cube_to_image failed" );
+    } else {
+
+    no=cpl_imagelist_get_size(list_sky);
+    lo_cut=(floor)(cfg->loReject*no+0.5);
+    hi_cut=(floor)(cfg->hiReject*no+0.5);
+    cknull(im_sky=cpl_imagelist_collapse_minmax_create(list_sky,lo_cut,hi_cut),
+           "sinfo_average_with_rejection failed" );
+    }
+    sinfo_free_imagelist(&list_sky);
+  }
+
+  if (cfg->contains_dither == 1) {
+    if (cfg->loReject*nobjdith < 1. && cfg->hiReject * nobjdith < 1.) {
+      cknull(im_dither = sinfo_new_average_cube_to_image(list_dither_object ),
+             "sinfo_new_average_cube_to_image failed" );
+   } else {
+
+
+     no=cpl_imagelist_get_size(list_dither_object);
+     lo_cut=(floor)(cfg->loReject*no+0.5);
+     hi_cut=(floor)(cfg->hiReject*no+0.5);
+     cknull(im_dither=cpl_imagelist_collapse_minmax_create(list_dither_object,
+                                                           lo_cut,hi_cut),
+                                      "sinfo_average_with_rejection failed" );
+   }
+   sinfo_free_imagelist(&list_dither_object);
+  }
+
+  if (cfg->contains_dither == 1 && nskydith > 0 ) {
+    if (cfg->loReject*nskydith < 1. && cfg->hiReject*nskydith < 1.) {
+      cknull(im_dither_sky = sinfo_new_average_cube_to_image(list_dither_sky ),
+            "sinfo_new_average_cube_to_image failed" );
+    } else {
+      no=cpl_imagelist_get_size(list_dither_sky);
+      lo_cut=(floor)(cfg->loReject*no+0.5);
+      hi_cut=(floor)(cfg->hiReject*no+0.5);
+      cknull(im_dither_sky=cpl_imagelist_collapse_minmax_create(list_dither_sky,
+                                                                lo_cut,hi_cut),
+                                          "new_average_with_rejection failed" );
+    }
+    sinfo_free_imagelist(&list_dither_sky);
+  }   
+
+  /*
+  #---------------------------------------------------------
+  # Subtract the resulting off-frame (sky) from the on-frame 
+  #-------------------------------------------------------
+  #finally, subtract off from on frames and store the result in the 
+  # object cube----------------
+  */
+
+  sinfo_msg("Subtracts the resulting off-frame (sky) from the on-frame");
+  if (cfg->contains_sky == 1) {
+     cknull(im_obj_sub = cpl_image_subtract_create(im_obj, im_sky),
+            "could not sinfo_sub_image");
+     sinfo_free_image(&im_obj);
+     if (((cfg->contains_dither == 1) && (nskydith > 0)) || 
+         (cfg->contains_dither == 0)) {
+       sinfo_free_image(&im_sky);
+     }
+     im_obj = im_obj_sub;
+  }
+
+  if (cfg->contains_dither == 1 && nskydith > 0) {
+     cknull(im_dither_sub=cpl_image_subtract_create(im_dither, im_dither_sky),
+            "could not sinfo_sub_image");
+     sinfo_free_image(&im_dither);
+     sinfo_free_image(&im_dither_sky);
+     im_dither = im_dither_sub;
+   } else if (cfg->contains_dither == 1 && 
+                          nskydith == 0 && 
+              cfg->contains_sky == 1) {
+     cknull(im_dither_sub = cpl_image_subtract_create(im_dither, im_sky),
+        "could not sinfo_sub_image");
+     sinfo_free_image(&im_dither);
+     sinfo_free_image(&im_sky);
+     im_dither = im_dither_sub;
+   }
+   /*
+   #---------------------------------------------------------
+   # Generating a static bad pixel mask:
+   # remove the intensity tilt from every column
+   # and compute the standard deviation on a rectangular zone
+   #---------------------------------------------------------
+   */
+
+   sinfo_msg("Generating a static bad pixel mask");
+   n_im_med = cfg->iterations+1;
+
+   imMed=(cpl_image**) cpl_calloc(n_im_med, sizeof(cpl_image*));
+
+   if (cfg->badInd == 1) {
+     sinfo_msg("removes the intensity tilt from every column and");
+     sinfo_msg("computes the standard deviation on a rectangular zone");
+
+     /* this call originates 36 bytes leaks */
+     cknull(colImage  = sinfo_new_col_tilt( im_obj, cfg->sigmaFactor ),
+        "sinfo_colTilt failed" );
+
+     cknull(stats = sinfo_new_image_stats_on_rectangle(colImage, 
+                                   cfg->badLoReject, 
+                                   cfg->badHiReject, 
+                                   cfg->llx, 
+                                   cfg->lly, 
+                                   cfg->urx, 
+                               cfg->ury),
+                                   "sinfo_get_image_stats_on_vig failed\n");
+     
+     local_clean_mean = stats->cleanmean;
+     clean_stdev = stats->cleanstdev;
+
+
+     /* indicate pixels with great deviations from the clean mean as bad */
+     if (cfg->threshInd == 1) {
+         cknull(threshIm = sinfo_new_thresh_image(colImage, 
+            local_clean_mean-mean_factor*clean_stdev,
+            local_clean_mean+mean_factor*clean_stdev),
+        " sinfo_threshImage failed\n" );
+     }
+     if (cfg->threshInd == 0) {
+        threshIm = colImage;
+     }
+
+     /*
+     filter iteratively the images by a sinfo_median filter of the nearest 
+     neighbors under the condition of a deviation greater than a factor 
+     times the standard deviation
+     */
+
+     cknull(imMed[0]= sinfo_new_median_image(threshIm,-cfg->factor*clean_stdev),
+                                            " sinfo_medianImage failed" );
+     
+
+       /* AMO check again if here the loop start and ending point are proper */
+
+     for (i=1; i< cfg->iterations+1; i++) {
+       cknull(imMed[i]=sinfo_new_median_image(imMed[i-1], 
+                          -cfg->factor*clean_stdev),
+                                          "sinfo_medianImage failed" );
+     }
+
+     /* compare the filtered image with the input image */
+     cknull(compImage=sinfo_new_compare_images(threshIm, 
+                                               imMed[cfg->iterations], 
+                                               im_obj),
+        "sinfo_compareImages failed" );
+
+     /*---generate the bad pixel mask */
+     n = (int*)cpl_calloc(1,sizeof(int));
+     cknull(maskImage = sinfo_new_promote_image_to_mask( compImage, n ),
+            "error in sinfo_promoteImageToMask" );
+
+
+     n_badpixels = n[0];
+     sinfo_msg("No of bad pixels: %d", n_badpixels);
+
+     cknull_nomsg(qclog_tbl = sinfo_qclog_init());
+     ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC BP-MAP NBADPIX",n_badpixels,
+                                   "No of bad pixels","%d"));
+
+     ck0(sinfo_pro_save_ima(maskImage,ref_set,sof,cfg->maskname,
+                  PRO_BP_MAP,qclog_tbl,plugin_id,config),
+               "cannot save ima %s", cfg->maskname);
+
+
+     /* free memory */
+     sinfo_free_table(&qclog_tbl);
+ 
+     sinfo_new_del_Stats(stats);
+     sinfo_free_int(&n);
+     sinfo_free_image(&threshIm); /* */
+     if (cfg->threshInd == 1) {
+       sinfo_free_image(&colImage);
+     }
+     sinfo_free_image(&compImage);
+     sinfo_free_image(&maskImage);
+
+     for (i=0; i< cfg->iterations+1; i++) {
+       sinfo_free_image(&imMed[i]);
+     }
+
+   }
+
+   cpl_free(imMed);
+   imMed=NULL;
+
+   /*
+   #---------------------------------------------------------
+   # Master flat field: static bad pixel correction and normalizing
+   #---------------------------------------------------------
+   */
+
+   sinfo_msg("Creates a Master flat field");
+   if (cfg->interpolInd == 1) {
+     cknull(mask_im = cpl_image_load(cfg->mask,CPL_TYPE_FLOAT,0,0),
+        "could not load static bad pixel mask" );
+
+      /* open the ASCII list of the slitlet positions */
+
+      /* slit_edges = sinfo_new_2Dfloat_array(32, 2) ; */
+      slit_edges = (float **) cpl_calloc( 32, sizeof (float*) ) ;
+      for ( i = 0 ; i < 32 ; i++ )
+        {
+            slit_edges[i] = (float *) cpl_calloc( 2, sizeof (float)) ;
+        }
+      /*READ TFITS TABLE*/
+      if(sinfo_is_fits_file(cfg->slitposList) !=1 ) {
+          sinfo_msg_error("Input file %s is not FITS", cfg->slitposList);
+          goto cleanup;
+      }
+      strcpy(tbl_slitpos_name,cfg->slitposList);
+      check(tbl_slitpos = cpl_table_load(tbl_slitpos_name,1,0),
+         "error loading tbl %s",tbl_slitpos_name);
+
+      for (i =0 ; i< 32; i++){
+            val_x=cpl_table_get_double(tbl_slitpos,"pos1",i,status);
+            val_y=cpl_table_get_double(tbl_slitpos,"pos2",i,status);
+            slit_edges[i][0]=val_x;
+        slit_edges[i][1]=val_y;
+      }
+      sinfo_free_table(&tbl_slitpos);
+
+      cknull(int_im = sinfo_interpol_source_image (im_obj, mask_im, 
+                                                 cfg->maxRad, slit_edges),
+                         "could not carry out sinfo_interpolSourceImage" );
+      
+      sinfo_free_image(&im_obj);
+      cknull(norm = sinfo_new_normalize_to_central_pixel(int_im),
+             "could not normalize flatfield" );
+      sinfo_free_image(&int_im);
+      im_obj = norm; 
+
+      if (cfg->contains_dither == 1) {
+        cknull(int_im_dith = sinfo_interpol_source_image(im_dither, 
+                               mask_im,
+                               cfg->maxRad,
+                               slit_edges),
+           "could not carry out sinfo_interpolSourceImage" );
+      
+        cpl_image_delete(im_dither);
+        cknull(norm_dith = sinfo_new_normalize_to_central_pixel(int_im_dith),
+           "could not normalize flatfield" );
+        sinfo_free_image(&int_im_dith);
+        im_dither = norm_dith;
+      }
+      /* sinfo_new_destroy_2Dfloatarray(slit_edges, 32); */    
+      for ( i = 0 ; i < 32 ; i++ )
+        {
+            cpl_free( slit_edges[i] );
+        }
+      cpl_free( slit_edges ) ;
+      sinfo_free_image(&mask_im);
+
+   }
+
+   if (cfg->interpolInd != 1) {
+     cknull(norm = sinfo_new_normalize_to_central_pixel(im_obj),
+            "could not normalize flatfield" );
+      sinfo_free_image(&im_obj);
+      im_obj = norm; 
+
+      if (cfg->contains_dither == 1) {
+        cknull(norm_dith = sinfo_new_normalize_to_central_pixel(im_dither),
+           "could not normalize flatfield" );
+        sinfo_free_image(&im_dither);
+        im_dither = norm_dith;
+      }
+   }
+
+   naxis1=cpl_image_get_size_x(im_obj);
+   naxis2=cpl_image_get_size_y(im_obj);
+
+
+   if(cfg->qc_fpn_xmin1 < 1) {
+     sinfo_msg_error("qc_ron_xmin < 1");
+     goto cleanup;
+   }
+
+   if(cfg->qc_fpn_xmax1 > naxis1) {
+     sinfo_msg_error("qc_ron_xmax < %d",naxis1);
+     goto cleanup;
+   }
+
+   if(cfg->qc_fpn_ymin1 < 1) {
+     sinfo_msg_error("qc_ron_ymin < 1");
+     goto cleanup;
+   }
+
+   if(cfg->qc_fpn_ymax1 > naxis2) {
+     sinfo_msg_error("qc_ron_ymax < %d",naxis2);
+     goto cleanup;
+   }
+   fpn_stdev1 = cpl_image_get_stdev_window(im_obj,
+                       cfg->qc_fpn_xmin1,
+                       cfg->qc_fpn_ymin1,
+                       cfg->qc_fpn_xmax1,
+                       cfg->qc_fpn_ymax1);
+
+
+   if(cfg->qc_fpn_xmin2 < 1) {
+     sinfo_msg_error("qc_ron_xmin < %d",1);
+     goto cleanup;
+   }
+
+
+   if(cfg->qc_fpn_xmax2 > naxis1) {
+     sinfo_msg_error("qc_ron_xmax < %d",naxis1);
+     goto cleanup;
+   }
+
+   if(cfg->qc_fpn_ymin2 < 1) {
+     sinfo_msg_error("qc_ron_ymin < 1");
+     goto cleanup;
+   }
+
+   if(cfg->qc_fpn_ymax2 > naxis2) {
+     sinfo_msg_error("qc_ron_ymax < %d",naxis2);
+     goto cleanup;
+   }
+   fpn_stdev2 = cpl_image_get_stdev_window(im_obj,
+                       cfg->qc_fpn_xmin2,
+                       cfg->qc_fpn_ymin2,
+                       cfg->qc_fpn_xmax2,
+                       cfg->qc_fpn_ymax2);
+
+
+
+   ck0(new_lamp_flats_det_ncounts(raw,cfg),"error computing number of counts");
+   cknull_nomsg(qclog_tbl = sinfo_qclog_init());
+   ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC SPECFLAT NCNTSAVG",
+                                    qc_lampflat.avg_di,"Average counts","%g"));
+   ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC SPECFLAT NCNTSSTD",
+                                    qc_lampflat.std_di,"Stdev counts","%g"));
+   ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC SPECFLAT OFFFLUX",
+                                    qc_lampflat.avg_of,
+                                    "Average flux off frames","%g"));
+
+    ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,
+                                     "QC LFLAT FPN1",
+                                     fpn_stdev1,
+                                     "Fixed Pattern Noise of combined frames",
+                                     "%f"));
+
+    ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,
+                                     "QC LFLAT FPN2",
+                                     fpn_stdev2,
+                                     "Fixed Pattern Noise of combined frames",
+                                     "%f"));
+
+      ck0(sinfo_pro_save_ima(im_obj,ref_set,sof,cfg->outName,
+			     PRO_MASTER_FLAT_LAMP,qclog_tbl,plugin_id,config),
+	  "cannot save ima %s", cfg->outName);
+
+    sinfo_free_table(&qclog_tbl);
+    sinfo_free_image(&im_obj);
+
+ 
+    if (cfg->contains_dither == 1) {
+
+      if (strstr(cfg->outName, ".fits" ) != NULL ) {
+
+    snprintf(name_list, MAX_NAME_SIZE-1,"%s%s", 
+	     sinfo_new_get_rootname(cfg->outName),
+                "_dither");
+        strcpy(outNameDither,name_list);
+        strcat(outNameDither,strstr(cfg->outName,".fits"));
+       
+      } else {
+        strcpy(outNameDither,cfg->outName);
+        strcat(outNameDither,"_dither");
+      }
+
+
+      naxis1=cpl_image_get_size_x(im_dither);
+      naxis2=cpl_image_get_size_y(im_dither);
+
+
+      if(cfg->qc_fpn_xmin1 < 1) {
+     sinfo_msg_error("qc_ron_xmin1 < 1");
+         goto cleanup;
+      }
+
+      if(cfg->qc_fpn_xmax1 > naxis1) {
+     sinfo_msg_error("qc_ron_xmax1 < %d",naxis1);
+         goto cleanup;
+      }
+
+      if(cfg->qc_fpn_ymin1 < 1) {
+     sinfo_msg_error("qc_ron_ymin1 < 1");
+         goto cleanup;
+      }
+
+      if(cfg->qc_fpn_ymax1 > naxis2) {
+     sinfo_msg_error("qc_ron_ymax1 < %d",naxis2);
+         goto cleanup;
+      }
+
+ 
+      fpn_stdev1 = cpl_image_get_stdev_window(im_dither,
+                          cfg->qc_fpn_xmin1,
+                          cfg->qc_fpn_ymin1,
+                          cfg->qc_fpn_xmax1,
+                          cfg->qc_fpn_ymax1);
+
+      if(cfg->qc_fpn_xmin2 < 1) {
+     sinfo_msg_error("qc_ron_xmin2 < 1");
+         goto cleanup;
+      }
+
+      if(cfg->qc_fpn_xmax2 > naxis1) {
+     sinfo_msg_error("qc_ron_xmax2 < %d",naxis1);
+         goto cleanup;
+      }
+
+      if(cfg->qc_fpn_ymin2 < 1) {
+     sinfo_msg_error("qc_ron_ymin2 < 1");
+         goto cleanup;
+      }
+
+      if(cfg->qc_fpn_ymax2 > naxis2) {
+     sinfo_msg_error("qc_ron_ymax2 < %d",naxis2);
+         goto cleanup;
+      }
+ 
+      fpn_stdev2 = cpl_image_get_stdev_window(im_dither,
+					      cfg->qc_fpn_xmin2,
+					      cfg->qc_fpn_ymin2,
+					      cfg->qc_fpn_xmax2,
+					      cfg->qc_fpn_ymax2);
+
+
+      ck0(new_lamp_flats_det_ncounts(raw,cfg),"error computing ncounts");
+      cknull_nomsg(qclog_tbl = sinfo_qclog_init());
+      ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC SPECFLAT NCNTSAVG",
+				       qc_lampflat.avg_di,"Average counts","%g"));
+
+      ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC SPECFLAT NCNTSSTD",
+				       qc_lampflat.std_di,"Stdev counts","%g"));
+
+      ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC SPECFLAT OFFFLUX",
+				       qc_lampflat.avg_of,"Average flux off frames","%g"));
+
+      ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC LFLAT FPN1",fpn_stdev1,
+				       "Fixed Pattern Noise of combined frames","%f"));
+
+      ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC LFLAT FPN2",fpn_stdev2,
+				       "Fixed Pattern Noise of combined frames","%f"));
+ 
+
+	ck0(sinfo_pro_save_ima(im_dither,ref_set,sof,outNameDither,
+			       PRO_MASTER_FLAT_LAMP,qclog_tbl,plugin_id,config),
+	    "cannot save ima %s", outNameDither);
+
+      sinfo_free_table(&qclog_tbl);
+      sinfo_free_image(&im_dither);
+
+    }
+
+
+    /* could be done earlier? */
+    sinfo_free_image_array(&im,cfg->nframes);
+    sinfo_free_frameset(&raw);
+    sinfo_flat_free(&cfg);
+    return 0;
+
+cleanup:
+
+
+    /* free memory */
+    if(slit_edges != NULL) {
+      for ( i = 0 ; i < 32 ; i++ )
+        {
+      if(slit_edges[i] != NULL) {
+            cpl_free( slit_edges[i] );
+      }
+          slit_edges[i]=NULL;
+        }
+      cpl_free( slit_edges ) ;
+    }
+    sinfo_free_image(&mask_im);
+    sinfo_free_table(&qclog_tbl);
+    if(stats) {
+      sinfo_new_del_Stats(stats);
+    }
+    sinfo_free_int(&n);
+    sinfo_free_image(&threshIm);
+    sinfo_free_image(&maskImage);
+    if(imMed != NULL) sinfo_free_image_array(&imMed,cfg->iterations);
+    if(stats!= NULL) {
+        sinfo_new_del_Stats(stats);
+        stats=NULL;
+    }
+    sinfo_free_image(&compImage);
+    sinfo_free_image(&colImage);
+    sinfo_free_imagelist(&list_dither_object);
+    sinfo_free_imagelist(&list_dither_sky);
+    if(list_sky != NULL) {
+       sinfo_free_imagelist(&list_sky);
+    }
+    sinfo_free_imagelist(&list_object);
+    sinfo_free_image(&im_dither);
+    sinfo_free_image(&im_dither_sky);
+    sinfo_free_image(&im_obj);
+    sinfo_free_image(&im_sky);
+    if(im != NULL) sinfo_free_image_array(&im,cfg->nframes);
+    sinfo_free_frameset(&raw);
+    if(cfg != NULL) {
+      sinfo_flat_free(&cfg);
+    }
+    return -1;
+
+}
+
+static int
+new_lamp_flats_det_ncounts(cpl_frameset* raw, flat_config* cfg)
+{
+ int i=0;
+ int j=0;
+
+ int nraw=0;
+ int non=0;
+ int noff=0;
+
+ double mjd_on=0;
+ double mjd_of=0;
+ double mjd_of_frm=0;
+
+ char filename[MAX_NAME_SIZE];
+
+ cpl_frame* frm=NULL;
+ cpl_frame* frm_dup=NULL;
+ cpl_frame* on_frm=NULL;
+ cpl_frame* of_frm=NULL;
+ cpl_frame* tmp_of_frm=NULL;
+
+
+ cpl_frameset* on_set=NULL;
+ cpl_frameset* of_set=NULL;
+ cpl_frameset* wrk_set=NULL;
+
+ on_set=cpl_frameset_new();
+ of_set=cpl_frameset_new();
+
+ nraw = cpl_frameset_get_size(raw);
+
+ for (i=0; i< nraw; i++) {
+   frm = cpl_frameset_get_frame(raw,i);
+   frm_dup = cpl_frame_duplicate(frm);
+   if(sinfo_frame_is_on(frm) == 1) {
+     cpl_frameset_insert(on_set,frm_dup);
+     non++;
+   } else {
+     cpl_frameset_insert(of_set,frm_dup);
+     noff++;
+   }
+ }
+
+
+ if (non == noff) {
+   new_qc_get_cnt(on_set,of_set,cfg);
+
+ } else if (non == 0) {
+   sinfo_msg("non == 0");
+   sinfo_msg_warning("QC SPECFLAT NCNTAVG/NCTNTSTD/OFFFLUX=0 ");
+ 
+ } else if ( noff == 0 ) {
+   sinfo_msg("noff == 0");
+   sinfo_msg_warning("QC SPECFLAT NCNTAVG/NCTNTSTD/OFFFLUX=0 ");
+
+ } else {
+
+   sinfo_msg_warning("non != noff, => QC SPECFLAT NCNTAVG/NCTNTSTD/OFFFLUX=0 ");
+
+    for (i=0;i<non;i++) {
+       wrk_set=cpl_frameset_new();
+       on_frm=cpl_frameset_get_frame(on_set,i);
+       mjd_on=sinfo_get_mjd_obs(on_frm);
+       of_frm=cpl_frameset_get_frame(of_set,0);
+       mjd_of=sinfo_get_mjd_obs(of_frm);
+       strcpy(filename,cpl_frame_get_filename(of_frm));
+       for (j=1;j<noff;j++) {
+          tmp_of_frm = cpl_frameset_get_frame(of_set,j);
+          mjd_of_frm = sinfo_get_mjd_obs(tmp_of_frm);
+
+          if(1000.*(mjd_of_frm-mjd_on)*(mjd_of_frm-mjd_on) <
+             1000.*(mjd_of-    mjd_on)*(mjd_of-    mjd_on) ) {
+            mjd_of=mjd_of_frm;
+             of_frm=cpl_frame_duplicate(tmp_of_frm);
+       }
+       }
+       strcpy(filename,cpl_frame_get_filename(of_frm));
+       frm_dup=cpl_frame_duplicate(of_frm);
+       cpl_frameset_insert(wrk_set,frm_dup);
+       strcpy(filename,cpl_frame_get_filename(of_frm));
+    }
+    /* Commented out as algorithm non robust if non != noff */
+    new_qc_get_cnt(on_set,wrk_set,cfg); 
+
+ }
+
+ cpl_frameset_delete(wrk_set);
+ cpl_frameset_delete(on_set);
+ cpl_frameset_delete(of_set);
+ return 0;
+
+
+}
+
+static int
+new_qc_get_cnt(cpl_frameset* on_set, cpl_frameset* of_set, flat_config* cfg)
+{
+
+  int i=0;
+  int nsat=0;
+  int non=0;
+  int nof=0;
+  int nfr=0;
+
+  char name[MAX_NAME_SIZE];
+  cpl_vector* vec_on=NULL;
+  cpl_vector* vec_of=NULL;
+  cpl_vector* vec_di=NULL;
+  cpl_vector* vec_nsat=NULL;
+  cpl_frame* on_frm=NULL;
+  cpl_frame* of_frm=NULL;
+
+  cpl_image* dif_ima=NULL;
+  cpl_image* on_ima=NULL;
+  cpl_image* of_ima=NULL;
+  cpl_image* tmp_ima=NULL;
+
+  double med=0;
+    non = cpl_frameset_get_size(on_set);
+    nof = cpl_frameset_get_size(of_set);
+    nfr = (non <= nof) ? non : nof;
+    vec_on = cpl_vector_new(nfr);
+    vec_of = cpl_vector_new(nfr);
+    vec_di = cpl_vector_new(nfr);
+    vec_nsat = cpl_vector_new(nfr);
+
+
+    for (i=0; i< nfr; i++) {
+      on_frm = cpl_frameset_get_frame(on_set,i);
+      strcpy(name,cpl_frame_get_filename(on_frm));
+      on_ima = cpl_image_load(name,CPL_TYPE_FLOAT,0,0);
+      med= cpl_image_get_median(on_ima);
+      cpl_vector_set(vec_on,i,med);
+
+      tmp_ima = cpl_image_duplicate(on_ima);
+      cpl_image_threshold(tmp_ima,SINFO_DBL_MIN,
+                          cfg->qc_thresh_max,0,1);
+      nsat=cpl_image_get_flux(tmp_ima);
+      cpl_vector_set(vec_nsat,i,nsat);
+
+   /* Are you sure to have same frames off as on ? */
+      of_frm = cpl_frameset_get_frame(of_set,i);
+      strcpy(name,cpl_frame_get_filename(of_frm));
+      of_ima = cpl_image_load(name,CPL_TYPE_FLOAT,0,0);
+      med= cpl_image_get_median(of_ima);
+      cpl_vector_set(vec_of,i,med);
+      dif_ima = cpl_image_subtract_create(on_ima,of_ima);
+      med= cpl_image_get_median(dif_ima);
+      cpl_vector_set(vec_di,i,med);
+
+    cpl_image_delete(on_ima);
+    cpl_image_delete(of_ima);
+    cpl_image_delete(dif_ima);
+    cpl_image_delete(tmp_ima);
+    }
+    qc_lampflat.avg_on=cpl_vector_get_mean(vec_on);
+    qc_lampflat.avg_of=cpl_vector_get_mean(vec_of);
+    qc_lampflat.avg_di=cpl_vector_get_mean(vec_di);
+    if(nfr > 1 ) {
+       qc_lampflat.std_on=cpl_vector_get_stdev(vec_on);
+       qc_lampflat.std_of=cpl_vector_get_stdev(vec_of);
+       qc_lampflat.std_di=cpl_vector_get_stdev(vec_di);
+    }
+    qc_lampflat.nsat=cpl_vector_get_mean(vec_nsat);
+    cpl_vector_delete(vec_on);
+    cpl_vector_delete(vec_of);
+    cpl_vector_delete(vec_di);
+    cpl_vector_delete(vec_nsat);
+    /*
+    sinfo_msg( "sinfo_qc_get_cnt","avg_on=%g std_on=%g ",
+                      qc_lampflat.avg_on,qc_lampflat.std_on);
+    sinfo_msg( "sinfo_qc_get_cnt","avg_of=%g std_of=%g ",
+                      qc_lampflat.avg_of,qc_lampflat.std_of);
+    sinfo_msg( "sinfo_qc_get_cnt","avg_di=%g std_di=%g ",
+                      qc_lampflat.avg_di,qc_lampflat.std_di);
+    sinfo_msg( "sinfo_qc_get_cnt","nsat=%g ",qc_lampflat.nsat);
+    */
+    return 0;
+}
+
+/**@}*/
diff --git a/sinfoni/sinfo_new_lamp_flats.h b/sinfoni/sinfo_new_lamp_flats.h
new file mode 100644
index 0000000..e4b2fb7
--- /dev/null
+++ b/sinfoni/sinfo_new_lamp_flats.h
@@ -0,0 +1,77 @@
+#ifndef SINFO_NEW_LAMP_FLATS_H
+#define SINFO_NEW_LAMP_FLATS_H
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*****************************************************************************
+* E.S.O. - VLT project
+*
+* "@(#) $Id: sinfo_new_lamp_flats.h,v 1.9 2007/09/21 14:13:43 amodigli Exp $"
+*
+* who       when      what
+* --------  --------  ----------------------------------------------
+* amodigli  17/09/03  created
+*/
+
+/************************************************************************
+ * sinfo_new_lamp_flats.h
+ * this step handles stacks of lamp flat fields, 
+ *  o it takes a clean mean,
+ *  o subtracts the off- from the on-frames, 
+ *  o corrects for static bad pixels and normalizes for a master flat field. 
+ *  o It distinguishes the spectrally dithered frames and 
+ *  o treats them the same way. 
+ *  o It can also generate a static bad pixel mask if wished.
+ *----------------------------------------------------------------------
+ */
+
+/*
+ * header files
+ */
+#include <cpl.h> 
+#include "sinfo_msg.h"
+
+/*----------------------------------------------------------------------------
+ *                        Function ANSI C prototypes
+ *--------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+   Function     :       sinfo_new_lamp_flats()
+   In           :       ini_file: file name of according .ini file
+   Out          :       integer (0 if it worked, -1 if it doesn't) 
+   Job          :
+       
+ * this step handles stacks of lamp flat fields, 
+ *  o it takes a clean mean,
+ *  o subtracts the off- from the on-frames, 
+ *  o corrects for static bad pixels and normalizes for a master flat field. 
+ *  o It distinguishes the spectrally dithered frames and 
+ *  o treats them the same way. 
+ *  o It can also generate a static bad pixel mask if wished.
+
+ ---------------------------------------------------------------------------*/
+int 
+sinfo_new_lamp_flats (const char* plugin_id,
+                      cpl_parameterlist* config, 
+                      cpl_frameset* sof,
+                      cpl_frameset* ref_set) ;
+
+
+#endif 
+
+/*--------------------------------------------------------------------------*/
diff --git a/sinfoni/sinfo_new_nst.c b/sinfoni/sinfo_new_nst.c
new file mode 100644
index 0000000..dda5241
--- /dev/null
+++ b/sinfoni/sinfo_new_nst.c
@@ -0,0 +1,392 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+ 
+     File name    :       spiffi_north_south_test.c
+   Author       :    A. Modigliani
+   Created on   :    Sep 17, 2003
+   Description  : 
+
+ * nsh.h
+ * Result of a north-south test exposure are 32 continuum spectra of a 
+ * pinhole that means one spectrum in each slitlet at the same spatial 
+ * position.
+ * Each spectrum is fitted in sp[atial direction by a Gaussian to get the 
+ * sub-pixel positions for each row.
+ *
+ * Then the distances are determined in each row and averaged
+ *
+ * Result: are distances of each slitlet from each other => 31 values stored 
+ *  in an ASCII file this Python script needs a frame of a pinhole source with 
+ *  a continuous spectrum, that is shifted exactly perpendicular to the 
+ *  slitlets. It fits the spectra in spatial direction by a Gaussian fit 
+ *  function and therefore determines the sub-pixel position of the source.
+ *
+ *  Then the distances of the slitlets from each other are determined and 
+ *   saved in an ASCII list. 
+ *
+
+
+ ---------------------------------------------------------------------------*/
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+/*----------------------------------------------------------------------------
+                                Includes
+ ---------------------------------------------------------------------------*/
+#include "sinfo_new_nst.h"
+#include "sinfo_pro_save.h"
+#include "sinfo_pro_types.h"
+#include "sinfo_functions.h"
+#include "sinfo_ns_ini_by_cpl.h"
+#include "sinfo_cube_construct.h"
+#include "sinfo_utilities.h"
+#include "sinfo_utils_wrappers.h"
+#include "sinfo_error.h"
+#include "sinfo_globals.h"
+
+/*----------------------------------------------------------------------------
+                                Defines
+ ---------------------------------------------------------------------------*/
+
+/**@{*/
+/**
+ * @addtogroup sinfo_rec_distortion North South test
+ *
+ * TBD
+ */
+
+/*----------------------------------------------------------------------------
+                             Function Definitions
+ ---------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+   Function     :       north_south_test()
+   In           :       ini_file: file name of according .ini file
+   Out          :       integer (0 if it worked, -1 if it doesn't) 
+   Job          : Result of a north-south test exposure are 32 continuum 
+                  spectra of a pinhole    that means one spectrum in each 
+                  slitlet at the same spatial position.
+
+                  Each spectrum is fitted in sp[atial direction by a Gaussian
+                  to get the sub-pixel positions for each row.
+
+                  Then the distances are determined in each row and averaged
+
+                  Result: are distances of each slitlet from each other =>
+                          31 values stored in an ASCII file
+
+
+ ---------------------------------------------------------------------------*/
+int 
+sinfo_new_nst(const char* plugin_id, 
+              cpl_parameterlist* config, 
+              cpl_frameset* sof,
+              cpl_frameset* ref_set)
+{
+  ns_config * cfg=NULL ;
+  cpl_imagelist * list_object=NULL ;
+  cpl_imagelist * list_off=NULL;
+  cpl_image * im_on=NULL;
+  cpl_image * im_on_sub=NULL ;
+  cpl_image * im_on_ind=NULL ;
+  cpl_image * im_on_gauss=NULL ;
+  cpl_image * im_mask=NULL ;
+  cpl_image * im_off=NULL ;
+
+  char* name=NULL;
+  char tbl_name[MAX_NAME_SIZE];
+  int typ=0;
+  int i = 0;
+
+  int nob =0;
+  int nof =0;
+
+  float* distances=NULL;
+  cpl_table* tbl_dist=NULL;
+
+  cpl_vector* qc_dist=NULL;
+
+  double  qc_dist_mean=0;
+  double  qc_dist_stdev=0;
+  cpl_frameset* raw=NULL;
+
+  cpl_table* qclog_tbl=NULL;
+  char key_value[MAX_NAME_SIZE];
+  char key_name[MAX_NAME_SIZE];
+  int  no=0;
+  double lo_cut=0.;
+  double hi_cut=0.;
+  int pdensity=0;
+
+  /* 
+       -----------------------------------------------------------------
+       1) parse the file names and parameters to the ns_config data 
+          structure cfg
+       -----------------------------------------------------------------
+  */
+
+  /* 
+      parse the file names and parameters to the ns_config data structure cfg 
+  */
+
+  sinfo_msg("Parse cpl input");
+  check_nomsg(raw=cpl_frameset_new());
+  cknull(cfg = sinfo_parse_cpl_input_ns(config,sof,&raw),
+     "could not parse cpl input!") ;
+
+  if (cfg->maskInd == 1) {
+    if(sinfo_is_fits_file(cfg->mask) != 1) {
+      sinfo_msg_error("Input file %s is not FITS",cfg->mask); 
+      goto cleanup;
+    }
+  }
+  /*
+     --------------------------------------------------------------------
+     stack the frames in data cubes and take the clean mean of all frames
+     --------------------------------------------------------------------
+  */
+  /* allocate memory for lists of object and off-frames */
+  sinfo_msg("stack the frames in data cubes");
+  check(list_object = cpl_imagelist_new(),
+          "could not allocate memory");
+
+  if (cfg->noff > 0 ) {
+    check(list_off = cpl_imagelist_new(),
+      "could not allocate memory");
+  }
+ 
+  /*
+      #build different image lists for the different cases----
+  */
+  sinfo_msg("build different image lists for the different cases");
+  nob = 0;
+  nof = 0;
+
+  for (i=0; i< cfg->nframes; i++){
+    name = cfg->framelist[i];
+    if(sinfo_is_fits_file(name) != 1) {
+      sinfo_msg_error("Input file %s is not FITS",name);
+      goto cleanup;
+    } else {
+      typ = sinfo_new_intarray_get_value( cfg->frametype, i );
+      if (typ == 1) {
+    cpl_imagelist_set(list_object,
+                          cpl_image_load(name,CPL_TYPE_FLOAT,0,0),nob);
+    nob = nob + 1;
+      } else {
+    cpl_imagelist_set(list_off,
+                          cpl_image_load(name,CPL_TYPE_FLOAT,0,0),nof);
+    nof = nof + 1;
+      }
+    }
+  }
+
+  if (cfg->noff != nof || cfg->nobj != nob ){       
+      sinfo_msg_error("something wrong with the number of the "
+                      "different types of frames");
+      goto cleanup;
+  }
+  
+  /*
+  #---take the average of the different cubes -------------
+  */
+  sinfo_msg("take the average of the different cubes");
+
+  check_nomsg(no=cpl_imagelist_get_size(list_object));
+  lo_cut=(floor)(cfg->loReject*no+0.5);
+  hi_cut=(floor)(cfg->hiReject*no+0.5);
+  check(im_on=cpl_imagelist_collapse_minmax_create(list_object,lo_cut,hi_cut),
+              "sinfo_average_with_rejection failed" );
+
+  if (cfg->noff != 0) {
+    /*
+      im_off = sinfo_average_with_rejection( cube_off, 
+                                       cfg->loReject, cfg->hiReject );
+    */
+    check_nomsg(no=cpl_imagelist_get_size(list_off));
+    lo_cut=(floor)(cfg->loReject*no+0.5);
+    hi_cut=(floor)(cfg->hiReject*no+0.5);
+    check(im_off=cpl_imagelist_collapse_minmax_create(list_off,lo_cut,hi_cut),
+      "sinfo_average_with_rejection failed" );
+      sinfo_free_imagelist(&list_off);
+  }
+  sinfo_free_imagelist(&list_object);
+
+  /*
+  #finally, subtract off from on frames and store the result in the object cube
+  */
+
+  if (cfg->noff != 0) {
+    sinfo_msg("subtract off from on frames");
+    check(im_on_sub = cpl_image_subtract_create(im_on, im_off),
+      "sinfo_sub_image failed" );
+
+    sinfo_free_image(&im_on);
+    sinfo_free_image(&im_off);
+  } else {
+    check_nomsg(im_on_sub = cpl_image_duplicate(im_on));
+    sinfo_free_image(&im_on);
+  }
+
+  /*
+  #---------------------------------------------------------
+  # convolution with Gaussian if recommended
+  #---------------------------------------------------------
+  */
+  if (cfg->gaussInd == 1) {
+    sinfo_msg("convolution with Gaussian");
+    cknull(im_on_gauss = sinfo_new_convolve_ns_image_by_gauss(im_on_sub, 
+                                                              cfg->hw),
+                     "could not carry out sinfo_convolveNSImageByGauss" );
+
+    sinfo_free_image(&im_on_sub);
+    check_nomsg(im_on_sub = cpl_image_duplicate(im_on_gauss));
+    sinfo_free_image(&im_on_gauss);
+  }
+
+  /*
+  #---------------------------------------------------------
+  # static bad pixel indication
+  #---------------------------------------------------------
+  */
+
+   if (cfg->maskInd == 1) {
+     sinfo_msg("static bad pixel indication");
+     check(im_mask = cpl_image_load(cfg->mask,CPL_TYPE_FLOAT,0,0),
+       "could not load static bad pixel mask" );
+     cknull(im_on_ind = sinfo_new_mult_image_by_mask(im_on_sub, im_mask),
+        "could not carry out sinfo_multImageByMask" );
+     sinfo_free_image(&im_mask);
+     sinfo_free_image(&im_on_sub);
+  
+   } else {
+      check_nomsg(im_on_ind = cpl_image_duplicate(im_on_sub));
+      sinfo_free_image(&im_on_sub);
+   }
+
+   if(pdensity > 1 && strcmp(plugin_id,"sinfo_rec_distortion")!=0) {
+     ck0(sinfo_pro_save_ima(im_on_ind,ref_set,sof,cfg->fitsname,
+			    PRO_MASTER_SLIT,NULL,plugin_id,config),
+	 "cannot save ima %s", cfg->fitsname);
+   }
+ 
+   /*
+   #---------------------------------------------------------
+   # do the north - south - test
+   #---------------------------------------------------------
+   */
+   sinfo_msg("Do the north - south - test");
+
+   cknull(distances = sinfo_north_south_test(im_on_ind, 
+                       cfg->nslits,
+                       cfg->halfWidth,
+                       cfg->fwhm ,
+                       cfg->minDiff,
+                       cfg->estimated_dist,
+                                           cfg->devtol, 
+                                           IMA_PIX_START, 
+                                           IMA_PIX_END ),
+      "North South Test distance determination failed");
+   sinfo_free_image(&im_on_ind);
+    /*
+   sinfo_new_parameter_to_ascii(distances, cfg->nslits - 1, cfg->outName);
+   */
+   check_nomsg(tbl_dist = cpl_table_new(cfg->nslits - 1));
+   check_nomsg(cpl_table_new_column(tbl_dist,"slitlet_distance",
+				    CPL_TYPE_FLOAT));
+   check_nomsg(cpl_table_copy_data_float(tbl_dist,"slitlet_distance",
+					 distances));
+
+   strcpy(tbl_name,cfg->outName);
+
+   check_nomsg(qclog_tbl = cpl_table_new(cfg->nslits + 1));
+   check_nomsg(cpl_table_new_column(qclog_tbl,"key_name", CPL_TYPE_STRING));
+   check_nomsg(cpl_table_new_column(qclog_tbl,"key_type", CPL_TYPE_STRING));
+   check_nomsg(cpl_table_new_column(qclog_tbl,"key_value", CPL_TYPE_STRING));
+   check_nomsg(cpl_table_new_column(qclog_tbl,"key_help", CPL_TYPE_STRING));
+
+   check_nomsg(qc_dist=cpl_vector_new(cfg->nslits - 1));
+ 
+   for(i=0;i<cfg->nslits - 1;i++) {
+         snprintf(key_name,MAX_NAME_SIZE-1,"%s%i","QC SL DIST",i);
+         cpl_table_set_string(qclog_tbl,"key_name",i,key_name);
+         cpl_table_set_string(qclog_tbl,"key_type",i,"CPL_TYPE_DOUBLE");
+         snprintf(key_value,MAX_NAME_SIZE-1,"%g",distances[i]);
+         cpl_table_set_string(qclog_tbl,"key_value",i,key_value);
+         cpl_table_set_string(qclog_tbl,"key_help",i,"Slitlet distance");
+
+         cpl_vector_set(qc_dist,i,distances[i]);
+   }
+   check_nomsg(qc_dist_mean=cpl_vector_get_mean(qc_dist));
+   check_nomsg(qc_dist_stdev=cpl_vector_get_stdev(qc_dist));
+
+   cpl_table_set_string(qclog_tbl,"key_name",cfg->nslits-1,"QC SL DISTAVG");
+   cpl_table_set_string(qclog_tbl,"key_type",cfg->nslits-1,"CPL_TYPE_DOUBLE");
+   snprintf(key_value,MAX_NAME_SIZE-1,"%g",cpl_vector_get_mean(qc_dist));
+   cpl_table_set_string(qclog_tbl,"key_value",cfg->nslits-1,key_value);
+   cpl_table_set_string(qclog_tbl,"key_help",cfg->nslits-1,
+                                  "Average Slitlet distance");
+
+   cpl_table_set_string(qclog_tbl,"key_name",cfg->nslits,"QC SL DISTRMS");
+   cpl_table_set_string(qclog_tbl,"key_type",cfg->nslits,"CPL_TYPE_DOUBLE");
+   snprintf(key_value,MAX_NAME_SIZE-1,"%g",qc_dist_stdev);
+   cpl_table_set_string(qclog_tbl,"key_value",cfg->nslits,key_value);
+   cpl_table_set_string(qclog_tbl,"key_help",cfg->nslits,
+                        "RMS Slitlet distance");
+
+   ck0(sinfo_pro_save_tbl(tbl_dist,ref_set,sof,tbl_name,
+           PRO_SLITLETS_DISTANCE,qclog_tbl,plugin_id,config),
+       "cannot dump tbl %s", tbl_name);
+
+   sinfo_free_my_vector(&qc_dist);
+   sinfo_free_table(&tbl_dist);
+   sinfo_free_table(&qclog_tbl);
+   sinfo_free_float(&distances);
+   sinfo_ns_free (&cfg);
+   sinfo_free_frameset(&raw);
+
+  return 0;
+
+  cleanup:
+  sinfo_free_my_vector(&qc_dist);
+  sinfo_free_table(&tbl_dist);
+  sinfo_free_table(&qclog_tbl);
+  sinfo_free_float(&distances);
+  sinfo_free_table(&tbl_dist);
+  sinfo_free_table(&qclog_tbl);
+  sinfo_free_imagelist(&list_object);
+  sinfo_free_imagelist(&list_off);
+  sinfo_free_image(&im_on);
+  sinfo_free_image(&im_mask);
+  sinfo_free_image(&im_on_gauss);
+  sinfo_free_image(&im_on_sub);
+  sinfo_free_image(&im_off);
+  sinfo_free_image(&im_on_ind);
+  sinfo_ns_free (&cfg);
+  sinfo_free_frameset(&raw);
+  return -1;
+
+
+}
+
+/**@}*/
+
+
diff --git a/sinfoni/sinfo_new_nst.h b/sinfoni/sinfo_new_nst.h
new file mode 100644
index 0000000..6d70e5a
--- /dev/null
+++ b/sinfoni/sinfo_new_nst.h
@@ -0,0 +1,87 @@
+#ifndef SINFO_NEW_NST_H
+#define SINFO_NEW_NST_H
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*****************************************************************************
+* E.S.O. - VLT project
+*
+* "@(#) $Id: sinfo_new_nst.h,v 1.7 2007/09/21 14:49:00 amodigli Exp $"
+*
+* who       when      what
+* --------  --------  ----------------------------------------------
+* amodigli  17/09/03  created
+*/
+
+/************************************************************************
+ * new_nsh.h
+ * Result of a north-south test exposure are 32 continuum spectra of a 
+ * pinhole that means one spectrum in each slitlet at the same spatial 
+ * position.
+ * Each spectrum is fitted in sp[atial direction by a Gaussian to get the 
+ * sub-pixel positions for each row.
+ *
+ * Then the distances are determined in each row and averaged
+ *
+ * Result: are distances of each slitlet from each other => 31 values stored 
+ *  in an ASCII file this Python script needs a frame of a pinhole source with 
+ *  a continuous spectrum, that is shifted exactly perpendicular to the 
+ *  slitlets. It fits the spectra in spatial direction by a Gaussian fit 
+ *  function and therefore determines the sub-pixel position of the source.
+ *
+ *  Then the distances of the slitlets from each other are determined and 
+ *   saved in an ASCII list. 
+ *
+ *----------------------------------------------------------------------
+ */
+
+/*
+ * header files
+ */
+#include <cpl.h>  
+#include "sinfo_msg.h"
+/*----------------------------------------------------------------------------
+ *                        Function ANSI C prototypes
+ *--------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+   Function     :       sinfo_nst()
+   In           :       ini_file: file name of according .ini file
+   Out          :       integer (0 if it worked, -1 if it doesn't) 
+   Job          :
+       
+ * Result of a north-south test exposure are 32 continuum spectra of a 
+ * pinhole that means one spectrum in each slitlet at the same spatial 
+ * position.
+ * Each spectrum is fitted in sp[atial direction by a Gaussian to get the 
+ * sub-pixel positions for each row.
+ *
+ * Then the distances are determined in each row and averaged 
+
+
+ ---------------------------------------------------------------------------*/
+int 
+sinfo_new_nst (const char* plugin_id, 
+               cpl_parameterlist* config,
+               cpl_frameset* set,
+               cpl_frameset* ref_set) ;
+
+
+#endif 
+
+/*--------------------------------------------------------------------------*/
diff --git a/sinfoni/sinfo_new_objnod.c b/sinfoni/sinfo_new_objnod.c
new file mode 100644
index 0000000..986faed
--- /dev/null
+++ b/sinfoni/sinfo_new_objnod.c
@@ -0,0 +1,877 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+   
+   File name    :       sinfo_new_objnod.c
+   Author       :    J. Schreiber
+   Created on   :    December 3, 2003
+   Description  :    Creates data cubes or merges data cubes 
+                        out of jittered object-sky
+                        nodding observations 
+ ---------------------------------------------------------------------------*/
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+/*----------------------------------------------------------------------------
+                                Includes
+ ---------------------------------------------------------------------------*/
+#include "sinfo_new_objnod.h"
+#include "sinfo_hidden.h"
+#include "sinfo_pro_save.h"
+#include "sinfo_objnod_ini_by_cpl.h"
+#include "sinfo_functions.h"
+#include "sinfo_pfits.h"
+#include "sinfo_utilities_scired.h" 
+#include "sinfo_wave_calibration.h"
+#include "sinfo_cube_construct.h"
+#include "sinfo_error.h"
+#include "sinfo_utils_wrappers.h"
+
+/*----------------------------------------------------------------------------
+                                Defines
+ ---------------------------------------------------------------------------*/
+#define PI_NUMB        (3.1415926535897932384626433832795) /* pi */
+
+
+/*----------------------------------------------------------------------------
+                             Function Definitions
+ ---------------------------------------------------------------------------*/
+
+/**@{*/
+/**
+ * @addtogroup sinfo_rec_jitter Cube construction and coaddition
+ *
+ * TBD
+ */
+
+
+/*----------------------------------------------------------------------------
+   Function     : sinfo_new_objnod()
+   In           : ini_file: file name of according .ini file
+   Out          : integer (0 if it worked, -1 if it doesn't) 
+   Job          : this routine carries through the data cube creation of an 
+                  object science observation using object-sky nodding
+                  and jittering. This script expects jittered frames that
+          were already sky-subtracted
+                  averaged, flatfielded, spectral tilt corrected and 
+        interleaved if necessary
+ ---------------------------------------------------------------------------*/
+int sinfo_new_objnod (const char* plugin_id,cpl_parameterlist* config, 
+            cpl_frameset* sof, const char* procatg)
+{
+
+    object_config * cfg=NULL ;
+    cpl_image * im=NULL ;
+    cpl_image * wavemapim=NULL ;
+    cpl_image * resampledImage=NULL ;
+    cpl_image * calim=NULL ;
+    cpl_image * halospec=NULL ;
+    cpl_image * sky_im=NULL;
+    cpl_image* res_flat=NULL;
+    cpl_image* res_sky=NULL;
+    cpl_image* flat_im=NULL;
+    cpl_image* jitter_image=NULL;
+    cpl_image* eima_avg=NULL;
+    cpl_image* eima_med=NULL;
+    cpl_imagelist  * cube=NULL ;
+    cpl_imagelist  * outcube=NULL ;
+    cpl_imagelist  * outcube2=NULL ;
+    cpl_imagelist  ** cubeobject=NULL ;
+    cpl_imagelist  ** cube_tmp=NULL ;
+    cpl_imagelist  * jittercube=NULL ;
+    cpl_imagelist  * maskcube=NULL ;
+    cpl_imagelist* cflat=NULL;
+    cpl_imagelist* cflat2=NULL;
+    cpl_imagelist* csky=NULL;
+    cpl_imagelist* csky2=NULL;
+
+
+    int i=0;
+    int n=0;
+    int partind = 0 ;
+    int centralpix=0 ;
+    int z_siz=0;
+    int z_min=0;
+    int z_max=0;
+    int z=0;
+    int z_stp=100;
+    int scales_sky=0;
+    int ks_clip=0;
+    double kappa=2.0;
+
+    float ref_offx=0;
+    float ref_offy=0;
+    float mi=0 ;
+    float ma=0 ;
+    float fcol=0 ;
+    float center_x=0;
+    float newcenter_x=0 ;
+    float center_y=0;
+    float newcenter_y=0;
+    float cd1_1=0;
+    float cd1_2=0;
+    float cd2_1=0;
+    float cd2_2=0;
+    float pixelscale=0;
+    float angle=0;
+    float radangle=0;
+    double exptime=0;
+
+    float *  correct_dist=NULL ;
+    float * distances=NULL ;
+    double * times=NULL ;
+    float * offsetx=NULL;
+    float * offsety=NULL;
+    float ** slit_edges=NULL ;
+    float offx_min=1.e10;
+    float offy_min=1.e10;
+    float offx_max=-1.e10;
+    float offy_max=-1.e10;
+
+    double dis=0;
+    double centralLambda=0;
+
+    char name_jitter[MAX_NAME_SIZE] ;
+    char pro_mjit[MAX_NAME_SIZE];
+    char pro_obs[MAX_NAME_SIZE];
+    char pro_med[MAX_NAME_SIZE];
+
+
+    char * name=NULL ;
+    char * partname=NULL;
+    char * partname2=NULL;
+    char file_name[MAX_NAME_SIZE];
+    int vllx=0;
+    int vlly=0;
+    int vurx=0;
+    int vury=0;
+
+    int onp=0;
+    int j=0;
+    cpl_image* j_img=NULL;
+    cpl_image* m_img=NULL;
+    cpl_table* qclog_tbl=NULL;
+    cpl_image* ill_cor=NULL;
+    cpl_frame* frame=NULL;
+    cpl_frameset* stk=NULL;
+    cpl_parameter* p=NULL;
+    cpl_propertylist* plist=NULL;
+    int mosaic_max_size=0;
+
+    check_nomsg(p=cpl_parameterlist_find(config,
+					 "sinfoni.objnod.mosaic_max_size"));
+    check_nomsg(mosaic_max_size=cpl_parameter_get_int(p));
+
+     if (strcmp(procatg,PRO_COADD_STD) == 0) {
+    strcpy(pro_mjit,PRO_MASK_COADD_STD);
+    strcpy(pro_obs,PRO_OBS_STD);
+    strcpy(pro_med,PRO_MED_COADD_STD);
+
+    } else if (strcmp(procatg,PRO_COADD_PSF) == 0) {
+    strcpy(pro_mjit,PRO_MASK_COADD_PSF);
+    strcpy(pro_obs,PRO_OBS_PSF);
+    strcpy(pro_med,PRO_MED_COADD_PSF);
+    } else {
+    strcpy(pro_mjit,PRO_MASK_COADD_OBJ);
+    strcpy(pro_obs,PRO_OBS_OBJ);
+    strcpy(pro_med,PRO_MED_COADD_OBJ);
+    }
+
+
+    /*----parse input data and parameters to set cube_config cfg---*/
+    check_nomsg(stk = cpl_frameset_new());
+
+    cknull(cfg = sinfo_parse_cpl_input_objnod(config,sof,&stk),
+       "Error setting parameter configuration");
+ 
+    ck0(sinfo_check_input_data(cfg),"error checking input");
+
+    if ( cfg->jitterind == 1 )
+    {
+        cknull(times = (double*) cpl_calloc (cfg->nframes, sizeof (double)), 
+           " could not allocate memory!") ;
+ 
+        cknull(offsetx = (float*) cpl_calloc (cfg->nframes, sizeof(float)),
+           " could not allocate memory!") ;
+
+        cknull(offsety = (float*) cpl_calloc (cfg->nframes, sizeof(float)),
+           " could not allocate memory!") ;
+    }
+  
+    if (cfg->jitterind == 0)
+    {
+        if ( NULL != (partname = strtok(cfg->outName, "."))) 
+        {
+            partname2 = strtok (NULL, ".") ;
+            partind = 1 ;
+        }
+    }
+
+    ck0(sinfo_auto_size_cube5(cfg,&ref_offx,&ref_offy,
+                                &offx_min,&offy_min,
+                                &offx_max,&offy_max),
+                             "Error resizing cube");
+  
+
+
+    check_nomsg(p=cpl_parameterlist_find(config,"sinfoni.objnod.fcol"));
+    check_nomsg(fcol=cpl_parameter_get_double(p));
+   
+    if(NULL != cpl_frameset_find(sof,PRO_ILL_COR)) {
+     sinfo_msg("Illumination correction cube is provided");
+     frame = cpl_frameset_find(sof,PRO_ILL_COR);
+     ill_cor=cpl_image_load(cpl_frame_get_filename(frame),CPL_TYPE_FLOAT,0,0);
+    } else {
+     sinfo_msg("Illumination correction cube not provided");
+     cpl_error_reset();
+    }
+
+     for ( n = 0 ; n < cfg->nframes ; n++ )
+     {
+
+        sinfo_msg("Read FITS information");
+        name = cfg->framelist[n] ;    
+        if (n == 0)
+    {
+        strcpy (name_jitter, name) ;
+    }   
+        if( sinfo_is_fits_file(name) != 1) {
+          sinfo_msg_error("Input file %s is not FITS",name);
+          goto cleanup;
+    }
+    
+    /* get some header values and compute the CD-sinfo_matrix */
+        plist=cpl_propertylist_load(name,0);
+    pixelscale = sinfo_pfits_get_pixscale(plist) /2;
+    angle = sinfo_pfits_get_posangle(plist) ;
+        /* in PUPIL data there is not posangle info: we reset the error */
+        if(cpl_error_get_code() != CPL_ERROR_NONE) {
+      cpl_error_reset();
+        }
+    sinfo_free_propertylist(&plist);
+    radangle = angle * PI_NUMB / 180. ;
+    cd1_1 = cos(radangle) ;
+    cd1_2 = sin(radangle) ;
+    cd2_1 = -sin(radangle) ;
+    cd2_2 = cos(radangle) ;
+    
+    sinfo_msg("frame no.: %d, name: %s\n", n, name) ;
+    cknull(im = cpl_image_load(name,CPL_TYPE_FLOAT,0,0),
+           " could not load frame %s!",name) ;
+
+    if (cfg->jitterind == 1)
+    {
+      exptime = sinfo_pfits_get_ditndit(name) ;
+
+      if (exptime == FLAG)
+        {
+          sinfo_msg_error("could not read fits header keyword exptime!");
+          goto cleanup;
+        }
+      times[n] = exptime ;
+          ck0(sinfo_new_assign_offset(n,name,offsetx,offsety,
+                                      ref_offx,ref_offy),
+                                      "Error assigning offsets");
+
+    }
+
+        /*
+         *--------------------------------------------------------------    
+         *---------------------RESAMPLING-------------------------------
+     *--------------------------------------------------------------
+         */
+        sinfo_msg("Resampling object");
+    cknull(wavemapim = cpl_image_load(cfg->wavemap,CPL_TYPE_FLOAT,0,0),
+           "could not load wavemap");
+
+        cknull(resampledImage = sinfo_new_defined_resampling( im, 
+                                  wavemapim, 
+                                  cfg->ncoeffs,
+                                  &cfg->nrows,
+                                  &dis,
+                                  &mi,
+                                  &ma,
+                                  &centralLambda,
+                                  &centralpix),
+           " sinfo_definedResampling() failed" ) ;
+
+ 
+    if(n ==0) {
+          if(strcmp(cfg->mflat_dist,"not_found") != 0) {
+        sinfo_msg("Resampling master flat");
+        cknull(flat_im=cpl_image_load(cfg->mflat_dist,CPL_TYPE_FLOAT,0,0),
+                   "Distorted master flat field not found\n"
+                   "You may have set --stack-flat_ind=FALSE\n"
+                   "Flat field resampling skipped");
+            cknull(res_flat = sinfo_new_defined_resampling(flat_im, 
+                               wavemapim,
+                               cfg->ncoeffs,
+                               &cfg->nrows,
+                               &dis,
+                               &mi,
+                               &ma,
+                               &centralLambda,
+                               &centralpix),
+           " sinfo_definedResampling() failed" ) ;
+
+            sinfo_free_image(&flat_im) ;
+      }
+     
+      if(strcmp(cfg->sky_dist,"no_sky")!=0) {
+        sinfo_msg("Resampling sky");
+        check_nomsg(sky_im=cpl_image_load(cfg->sky_dist,
+                                              CPL_TYPE_FLOAT,0,0));
+        cknull(res_sky = sinfo_new_defined_resampling(sky_im,
+                              wavemapim,
+                              cfg->ncoeffs,
+                              &cfg->nrows,
+                              &dis,
+                              &mi,
+                              &ma,
+                              &centralLambda,
+                              &centralpix),
+           " sinfo_definedResampling() failed" );
+
+        sinfo_free_image(&sky_im) ;
+
+       
+      }
+    }
+
+        sinfo_msg ("dispersion %f\n", dis) ;
+        sinfo_msg ("lambda min %f max %f cent %f\n", mi,ma,centralLambda ) ;
+        sinfo_msg ("central pixel %d\n", centralpix) ; 
+
+        sinfo_free_image(&im) ;
+        sinfo_free_image(&wavemapim) ;
+
+    /*
+         *-------------------------------------------------------------------
+         *----------------Calibration----------------------------------------
+         *-------------------------------------------------------------------
+    */
+        /*----Multiply with calibrated halogen lamp spectrum----*/ 
+        if (cfg->halocorrectInd == 1)
+        {     
+      sinfo_msg("Calibration");
+      check_nomsg(halospec = cpl_image_load(cfg->halospectrum,
+                                                CPL_TYPE_FLOAT,0,0)) ;
+
+      cknull(calim = sinfo_new_multiply_image_with_spectrum(resampledImage,
+                                                                halospec),
+                        " sinfo_new_multiply_image_with_spectrum() failed" ) ;
+
+      sinfo_free_image(&halospec) ;
+      sinfo_free_image(&resampledImage) ;
+      resampledImage = cpl_image_duplicate(calim) ;
+      sinfo_free_image(&calim);
+        }
+    
+        /*
+         *-------------------------------------------------------------------
+         *------------------CUBECREATION-------------------------------------
+         *-------------------------------------------------------------------
+     */
+    sinfo_msg("Cube creation");
+    /*---select north-south-test or fitting of slitlet edges--*/
+    if (cfg->northsouthInd == 0) {
+      sinfo_msg("cfg->northsouthInd == 0");
+      cknull(slit_edges = sinfo_read_slitlets_edges(cfg->nslits,cfg->poslist),
+         "error reading slitlets edges");
+    } else {
+      sinfo_msg("cfg->northsouthInd != 0");
+      cknull(distances = sinfo_read_distances(cfg->nslits,cfg->distlist),
+         "error reading distances");
+    }
+ 
+    cknull(correct_dist = (float*) cpl_calloc(cfg->nslits, sizeof (float)),
+           " could not allocate memory!") ;
+
+    sinfo_msg("Create cube object");
+    if (cfg->northsouthInd ==0 ) {
+
+        cknull(cube = sinfo_new_make_cube_spi(resampledImage,
+                                                  slit_edges,
+                                                  correct_dist),
+                                 " could not construct data cube!") ;
+
+    }  else {
+       cknull(cube = sinfo_new_make_cube_dist(resampledImage,
+                                                  fcol,
+                                                  distances,
+                                                  correct_dist),
+                                         " could not construct a data cube!") ;
+    }
+    sinfo_free_image(&resampledImage);
+
+    if(n==0) {
+      if(strcmp(cfg->mflat_dist,"not_found")!=0) {
+        sinfo_msg("Create cube master flat");
+        if (cfg->northsouthInd ==0 ) {
+          cknull(cflat=sinfo_new_make_cube_spi(res_flat,
+                                                   slit_edges,
+                                                   correct_dist),
+                                " could not construct data cube!") ;
+        }  else {
+          cknull(cflat = sinfo_new_make_cube_dist(res_flat,
+                                                      fcol,
+                                                      distances,
+                                                      correct_dist),
+                                        " could not construct a data cube!") ;
+        }
+        sinfo_free_image(&res_flat);
+      }
+      if(strcmp(cfg->sky_dist,"no_sky")!=0) {
+
+        sinfo_msg("Create cube sky");
+        if (cfg->northsouthInd ==0 ) {
+          cknull(csky = sinfo_new_make_cube_spi(res_sky,
+                                                    slit_edges,
+                                                    correct_dist),
+                                           " could not construct data cube!") ;
+        }  else {
+          cknull(csky = sinfo_new_make_cube_dist(res_sky,
+                                                     fcol,
+                                                     distances,
+                                                     correct_dist),
+                                         " could not construct a data cube!") ;
+        }
+        sinfo_free_image(&res_sky);
+      }
+    }
+
+
+        if (cfg->northsouthInd ==0 )
+     {
+       sinfo_new_destroy_2Dfloatarray(&slit_edges,cfg->nslits);
+     }
+    else
+      {
+            sinfo_new_destroy_array(&distances);
+      }
+
+        /*
+         *--------------------------------------------------------------------
+         *------------------------FINETUNING----------------------------------
+         *--------------------------------------------------------------------
+         * shift the rows of the reconstructed images of the data cube to the 
+         * correct sub pixel position select the shift method: polynomial 
+         * interpolation, FFT or cubic spline interpolation
+         *--------------------------------------------------------------------
+         */
+ 
+    if(n==0) {
+      if(strcmp(cfg->sky_dist,"no_sky")!=0) {
+         cknull(csky2=sinfo_new_fine_tune(csky,
+                                             correct_dist,
+                                             cfg->method,
+                                             cfg->order,
+                          cfg->nslits),
+            " could not fine tune the data cube") ;
+
+         sinfo_free_imagelist(&csky);
+         sinfo_msg("Stretch output cube along Y direction");
+ 
+         cknull(csky = sinfo_new_bin_cube(csky2,1,2,0,63,0,63),
+            "error rebinning sky cube");
+         sinfo_free_imagelist(&csky2);
+
+       
+     
+         ck0(sinfo_pro_save_ims(csky,sof,sof,"out_sky_cube.fits",
+                    PRO_OBS_SKY,NULL,plugin_id,config),
+         "cannot dump cube %s", "out_sky_cube.fits");
+ 
+         cknull(eima_med=sinfo_new_median_cube(csky),
+                "Creating an average image");
+         check_nomsg(center_x = cpl_image_get_size_x(eima_med)/ 2. + 0.5);
+         check_nomsg(center_y = cpl_image_get_size_y(eima_med)/ 2. + 0.5);
+
+            sinfo_new_set_wcs_cube(csky, "out_sky_cube.fits", centralLambda, 
+                          dis, centralpix, center_x, center_y);
+
+         sinfo_free_imagelist(&csky) ;
+
+         ck0(sinfo_pro_save_ima(eima_med,sof,sof,"out_sky_med.fits",
+                    PRO_SKY_MED,NULL,plugin_id,config),
+         "cannot save ima %s", "out_sky_med.fits");
+
+            sinfo_new_set_wcs_image(eima_med,"out_sky_med.fits", 
+                                     center_x, center_y);
+         sinfo_free_image(&eima_med);
+      }
+
+
+      if(strcmp(cfg->mflat_dist,"not_found")!=0) {
+
+        cknull(cflat2=sinfo_new_fine_tune(cflat,correct_dist,
+                                              cfg->method,cfg->order,
+                                              cfg->nslits),
+                                       " could not fine tune the data cube") ;
+
+        sinfo_free_imagelist(&cflat);
+        sinfo_msg("Stretch output cube along Y direction");
+ 
+        cknull(cflat = sinfo_new_bin_cube(cflat2,1,2,0,63,0,63),
+           "Error binning flat cube");
+        sinfo_free_imagelist(&cflat2);
+
+        ck0(sinfo_pro_save_ims(cflat,sof,sof,OBJNOD_OUT_MFLAT_CUBE_FILENAME,
+                   PRO_MFLAT_CUBE,NULL,plugin_id,config),
+        "cannot save cube %s", OBJNOD_OUT_MFLAT_CUBE_FILENAME);
+
+        cknull(eima_avg=sinfo_new_average_cube_to_image(cflat),
+               "Creating an average image");
+
+        ck0(sinfo_pro_save_ima(eima_avg,sof,sof,"out_mflat_avg.fits",
+                   "MFLAT_AVG",NULL,plugin_id,config),
+        "cannot save ima %s", "out_mflat_avg.fits");
+
+        sinfo_free_image(&eima_avg);
+
+        cknull(eima_med=sinfo_new_median_cube(cflat),
+           "Error computing median on cube flat");
+
+        ck0(sinfo_pro_save_ima(eima_med,sof,sof,"out_mflat_med.fits",
+                   "MFLAT_MED",NULL,plugin_id,config),
+        "cannot save ima %s", "out_mflat_med.fits");
+
+        sinfo_free_imagelist(&cflat); 
+        sinfo_free_image(&eima_med);
+      }
+    }
+       
+
+        cknull(outcube2=sinfo_new_fine_tune(cube,
+                                            correct_dist,
+                                            cfg->method,
+                                            cfg->order,
+                                            cfg->nslits),
+                                     " could not fine tune the data cube") ;
+
+        sinfo_msg("Stretch output cube along Y direction");
+        cknull(outcube = sinfo_new_bin_cube(outcube2,1,2,0,63,0,63),
+           "Error binning cube");
+        sinfo_free_imagelist(&cube);
+        cknull_nomsg(qclog_tbl=sinfo_qclog_init());
+        sinfo_get_pupil_shift(outcube,n,&qclog_tbl);
+        snprintf(file_name,MAX_NAME_SIZE-1,"%s%2.2d%s",
+		 "out_cube_obj",n,".fits");
+        ck0(sinfo_pro_save_ims(outcube,sof,sof,file_name,
+                   pro_obs,qclog_tbl,plugin_id,config),
+        "cannot save cube %s", file_name);
+
+
+        sinfo_free_table(&qclog_tbl);
+    check_nomsg(center_x = cpl_image_get_size_x(
+                               cpl_imagelist_get(outcube,0))/2.+0.5) ;
+    check_nomsg(center_y = cpl_image_get_size_y(
+                               cpl_imagelist_get(outcube,0))/2.+0.5 );
+   
+
+    sinfo_new_set_wcs_cube(outcube, file_name, centralLambda, dis, 
+                     centralpix, center_x, center_y);
+
+       /* free memory */
+        /* to prevent error message comment next line */
+        sinfo_free_imagelist(&outcube2);
+        sinfo_free_imagelist(&outcube) ;
+    sinfo_free_float(&correct_dist) ;
+
+
+    } /* end loop over n (nframes) */
+ 
+    /* leak free */
+    if(cfg->jitterind == 0) {
+      goto exit;
+    }   
+     
+    /* Here in case of autojitter we estimate the sky */
+    if( (cfg->size_x*cfg->size_y*cfg->nframes) > (100*mosaic_max_size) ) {
+      sinfo_msg_warning("Coadd cube size:%d,%d. N frames: %d",
+                           cfg->size_x,cfg->size_y,cfg->nframes);
+      sinfo_msg_warning("Max allowed should be such that "
+                        "sixeX*sixeY*Nframes < 100*%d",mosaic_max_size);
+      goto exit;
+    } 
+ 
+    if ( cfg->jitterind == 1 )
+    {  
+        check_nomsg(p = cpl_parameterlist_find(config, "sinfoni.objnod.vllx"));
+        check_nomsg(vllx = cpl_parameter_get_int(p));
+        check_nomsg(p = cpl_parameterlist_find(config, "sinfoni.objnod.vlly"));
+        check_nomsg(vlly = cpl_parameter_get_int(p));
+        check_nomsg(p = cpl_parameterlist_find(config, "sinfoni.objnod.vurx"));
+        check_nomsg(vurx = cpl_parameter_get_int(p));
+        check_nomsg(p = cpl_parameterlist_find(config, "sinfoni.objnod.vury"));
+        check_nomsg(vury = cpl_parameter_get_int(p));
+ 
+        cknull(cube_tmp =(cpl_imagelist**) cpl_calloc(cfg->nframes, 
+                                                      sizeof (cpl_imagelist*)),
+                                     "Could not allocate memory for cube_tmp");
+        cknull(cubeobject =(cpl_imagelist**) cpl_calloc(cfg->nframes, 
+                                                        sizeof(cpl_imagelist*)),
+                                    "Could not allocate memory for cubeobject");
+
+    for ( n = 0 ; n < cfg->nframes ; n++ ) {
+          snprintf(file_name,MAX_NAME_SIZE-1,"%s%2.2d%s","out_cube_obj",
+                     n,".fits");
+      check_nomsg(cube_tmp[n] = cpl_imagelist_load(file_name,
+                               CPL_TYPE_FLOAT,0));
+      check_nomsg(cubeobject[n] = sinfo_new_cube_getvig(cube_tmp[n],
+                                1+vllx,1+vlly,
+                                64-vurx,64-vury));
+          check_nomsg(sinfo_free_imagelist(&cube_tmp[n]));
+    }
+        sinfo_free_array_imagelist(&cube_tmp);
+
+    }
+
+    /*
+        ---------------------------------------------------------------------
+        ------------------------JITTERING------------------------------------
+        ---------------------------------------------------------------------
+    */
+
+    if (cfg->jitterind == 1)
+    {
+    sinfo_msg("Jittering...");
+
+        sinfo_msg("Coadded cube size. x: %d y: %d",
+             cfg->size_x,cfg->size_y);
+        check_nomsg(jittercube = cpl_imagelist_new()) ;
+
+
+    /* 
+        ---------------------------------------------------------------------
+        -------------------THOMAS ALGORITHM----------------------------------
+        ---------------------------------------------------------------------
+    */
+       
+        check_nomsg(p=cpl_parameterlist_find(config,
+                                             "sinfoni.objnod.scales_sky"));
+        check_nomsg(scales_sky=cpl_parameter_get_bool(p));
+        check_nomsg(p=cpl_parameterlist_find(config,"sinfoni.objnod.ks_clip"));
+        check_nomsg(ks_clip = cpl_parameter_get_bool(p));
+        check_nomsg(p=cpl_parameterlist_find(config,"sinfoni.objnod.kappa"));
+        check_nomsg(kappa = cpl_parameter_get_double(p));
+
+
+    if(scales_sky == 1) {
+      sinfo_msg("Subtract spatial sinfo_median to each cube plane");
+      for(n=0;n<cfg->nframes;n++) {
+        sinfo_msg("process cube %d\n",n);
+        sinfo_new_sinfoni_correct_median_it(&(cubeobject[n]));
+      }
+    }
+
+
+        /* AMO CHECK */
+
+        cknull(maskcube=cpl_imagelist_new(),"could not allocate cube!");
+        
+    /* Illumination correction */ 
+        if(ill_cor != NULL) {
+      for(n=0;n<cfg->nframes;n++) {
+        sinfo_msg("Illumination correction is applied");
+        cpl_imagelist_divide_image(cubeobject[n],ill_cor);
+      }
+    }
+        sinfo_free_image(&ill_cor);
+    
+    sinfo_msg("Combine jittered cubes");
+
+
+    if(ks_clip == 1) {
+      sinfo_msg("Cube coaddition with kappa-sigma");
+    }
+        check_nomsg(onp=cpl_imagelist_get_size(cubeobject[0]));
+    for(z=0;z<onp;z+=z_stp) {
+      z_siz=(z_stp < (onp-z)) ? z_stp : (onp-z);
+      z_min=z;
+      z_max=z_min+z_siz;
+      sinfo_msg("Coadding cubes: range [%4.4d,%4.4d) of 0-%d\n",
+                           z_min,z_max,onp);
+
+      for(j=z_min;j<z_max;j++) {
+            check_nomsg(j_img=cpl_image_new(cfg->size_x,
+                                            cfg->size_y,CPL_TYPE_FLOAT));
+        check_nomsg(cpl_imagelist_set(jittercube,j_img,j));
+            check_nomsg(m_img = cpl_image_new(cfg->size_x,
+                                              cfg->size_y,CPL_TYPE_FLOAT));
+            check_nomsg(cpl_imagelist_set(maskcube,m_img,j));
+      }
+      if(ks_clip == 1) {
+        sinfo_new_combine_jittered_cubes_thomas_range(cubeobject,
+                            jittercube,
+                            maskcube,
+                            cfg->nframes,
+                            offsetx,offsety,
+                            times,
+                            cfg->kernel_type,
+                            z_min,
+                            z_max,
+                            kappa);
+
+      } else {
+        sinfo_new_combine_jittered_cubes_range(cubeobject, 
+                                             jittercube,
+                                             maskcube,
+                         cfg->nframes,
+                                             offsetx,
+                         offsety, 
+                                             times,
+                         cfg->kernel_type,
+                                             z_min,
+                                             z_max) ;
+      }
+    }
+        sinfo_new_convert_0_to_ZERO_for_cubes(jittercube) ; 
+
+      if (jittercube == NULL)
+    {
+        sinfo_msg_error(" could not allocate new data cube!") ;
+        goto cleanup;
+    }
+
+        if (maskcube == NULL)
+    {
+        sinfo_msg_error(" could not merge the jittered data cubes\n") ;
+            goto cleanup;
+    }
+
+    for ( i = 0 ; i <cfg->nframes  ; i++ ) {
+      sinfo_free_imagelist(&cubeobject[i]);
+    }
+    sinfo_free_array_imagelist(&cubeobject);
+
+        newcenter_x = cfg->size_x / 2. + 0.5 ;
+    newcenter_y = cfg->size_y / 2. + 0.5 ;
+
+        ck0(sinfo_pro_save_ims(jittercube,sof,sof,cfg->outName,
+                   procatg,NULL,plugin_id,config),
+        "cannot save cube %s", cfg->outName);
+
+      sinfo_new_set_wcs_cube(jittercube, cfg->outName, centralLambda, 
+                               dis, centralpix, center_x, center_y);
+
+        cknull(jitter_image = sinfo_new_median_cube(jittercube),
+               " could not do sinfo_medianCube()");
+
+
+        ck0(sinfo_pro_save_ima(jitter_image,sof,sof,cfg->med_cube_name,
+                   pro_med,NULL,plugin_id,config),
+        "cannot save ima %s", cfg->outName);
+
+      sinfo_new_set_wcs_image(jitter_image, cfg->med_cube_name,
+                                center_x,center_y);
+
+        sinfo_free_image(&jitter_image);
+
+        ck0(sinfo_pro_save_ims(maskcube,sof,sof,cfg->maskname,
+                   pro_mjit,NULL,plugin_id,config),
+        "cannot save cube %s", cfg->maskname);
+
+     sinfo_new_set_wcs_cube(maskcube, cfg->maskname, centralLambda, 
+                               dis, centralpix, center_x, center_y);
+
+        sinfo_free_double(&times) ;
+        sinfo_free_float(&offsetx) ;
+        sinfo_free_float(&offsety) ;
+        sinfo_free_imagelist(&maskcube) ;
+        sinfo_free_imagelist(&jittercube) ;         
+
+    } /* end of jittering */
+
+ exit:
+
+ /* free memory */
+    sinfo_objnod_free(&cfg);
+    sinfo_free_frameset(&stk);
+    return 0;   
+
+ cleanup:
+    sinfo_free_propertylist(&plist);
+    sinfo_free_image(&jitter_image);
+    sinfo_free_imagelist(&jittercube) ;
+    sinfo_free_imagelist(&maskcube) ;
+
+    if(cfg != NULL) {
+      if(cube_tmp != NULL) {
+    for ( n = 0 ; n < cfg->nframes ; n++ ) {
+      sinfo_free_imagelist(&(cube_tmp[n]));
+    }
+        sinfo_free_array_imagelist(&cube_tmp);
+      }
+      if(cubeobject != NULL) {
+    for ( n = 0 ; n < cfg->nframes ; n++ ) {
+      sinfo_free_imagelist(&(cubeobject[n]));
+    }
+        sinfo_free_array_imagelist(&cubeobject);
+      }
+
+    }
+
+    sinfo_free_imagelist(&outcube2) ;
+    sinfo_free_imagelist(&outcube) ;
+    sinfo_free_table(&qclog_tbl);
+    sinfo_free_image(&eima_avg);
+    sinfo_free_image(&eima_med);
+    sinfo_free_imagelist(&cflat) ;
+    sinfo_free_imagelist(&cflat2) ;
+    sinfo_free_imagelist(&cube) ;
+    sinfo_free_imagelist(&csky) ;
+    sinfo_free_imagelist(&csky2) ;
+
+    if(cfg!=NULL) {
+      if (cfg->northsouthInd ==0 ) {
+    if(slit_edges != NULL) {
+       sinfo_new_destroy_2Dfloatarray(&slit_edges,cfg->nslits);
+    }
+      } else {
+    if (distances != NULL ) {
+            sinfo_new_destroy_array(&distances);
+    }
+      }
+    }
+
+    sinfo_free_float(&correct_dist);
+    sinfo_free_image(&res_flat);
+    sinfo_free_image(&res_sky);
+    sinfo_free_image(&calim);
+    sinfo_free_image(&halospec) ;
+    sinfo_free_image(&sky_im) ;
+    sinfo_free_image(&resampledImage);
+    sinfo_free_image(&flat_im) ;
+    sinfo_free_image(&wavemapim);
+    sinfo_free_image(&im);
+    sinfo_free_image(&ill_cor);
+    sinfo_free_float(&offsety);
+    sinfo_free_float(&offsetx);
+    sinfo_free_double(&times);
+    sinfo_objnod_free(&cfg);
+    sinfo_free_frameset(&stk);
+
+    return -1;   
+
+
+
+}
+/**@}*/
diff --git a/sinfoni/sinfo_new_objnod.h b/sinfoni/sinfo_new_objnod.h
new file mode 100644
index 0000000..adff3b2
--- /dev/null
+++ b/sinfoni/sinfo_new_objnod.h
@@ -0,0 +1,71 @@
+#ifndef SINFO_NEW_OBJNOD_H
+#define SINFO_NEW_OBJNOD_H
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/************************************************************************
+* E.S.O. - VLT project
+*
+* "@(#) $Id: sinfo_new_objnod.h,v 1.8 2007/06/06 07:10:45 amodigli Exp $"
+*
+* who       when      what
+* --------  --------  ----------------------------------------------
+* schreib  06/05/03  created
+*/
+
+/************************************************************************
+ * sinfo_objnod.h
+ * routines to create a data cube
+ *----------------------------------------------------------------------
+ */
+
+/*
+ * header files
+ */
+#include <math.h>
+#include <cpl.h>   
+#include "sinfo_msg.h"
+/*----------------------------------------------------------------------------
+ *                        Function ANSI C prototypes
+ *--------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+   @name sinfo_new_objnod()
+   @param ini_file: file name of according .ini file
+   @return integer (0 if it worked, -1 if it doesn't) 
+   @doc this routine does the resampling of an offset-corrected,
+        flatfielded, bad pixel corrected and
+        eventually interleaved data frame. Additionally, an intensity 
+    calibration is carried through by using
+        a standard star or a black body measurement. 
+    The spectral features of the flatfield halogen lamp are corrected.
+        Afterwards a data cube is created out of the resampled image.
+    It is the users choice to use either
+        the fitted sinfo_edge positions of the slitlets or the distances
+    of the slitlets gained from a north-south-test. 
+ ---------------------------------------------------------------------------*/
+int 
+sinfo_new_objnod (const char* plugin_id,
+                  cpl_parameterlist* config, 
+                  cpl_frameset* sof, 
+                  const char* procatg) ;
+
+
+#endif /*!SINFO_NEW_OBJNOD_H*/
+
+/*--------------------------------------------------------------------------*/
diff --git a/sinfoni/sinfo_new_prepare_stacked_frames.c b/sinfoni/sinfo_new_prepare_stacked_frames.c
new file mode 100644
index 0000000..223a3fe
--- /dev/null
+++ b/sinfoni/sinfo_new_prepare_stacked_frames.c
@@ -0,0 +1,1409 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+
+     File name    :       sinfo_new_prepare_stacked_frames.c
+   Author       :    A. Modigliani
+   Created on   :    Sep 17, 2003
+   Description  :
+
+  this handles stacks of input frames, that means it takes a clean mean,
+  subtracts the off- from the on-frames, flatfields, corrects for static bad
+  pixels, corrects for a linear tilt of the spectra if necessary, and finally,
+  interleaves dithered exposures or convolves a single exposure with a
+  Gaussian, respectively.
+
+ ---------------------------------------------------------------------------*/
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+/*----------------------------------------------------------------------------
+                                Includes
+ ---------------------------------------------------------------------------*/
+#include "sinfo_new_prepare_stacked_frames.h"
+#include "sinfo_stack_ini_by_cpl.h"
+#include "sinfo_coltilt.h"
+#include "sinfo_image_ops.h"
+#include "sinfo_merge.h"
+#include "sinfo_utilities.h"
+#include "sinfo_wave_calibration.h"
+#include "sinfo_new_bezier.h"
+#include "sinfo_shift_images.h"
+#include "sinfo_product_config.h"
+
+#include "sinfo_pro_save.h"
+#include "sinfo_globals.h"
+#include "sinfo_utilities.h"
+#include "sinfo_dfs.h"
+#include "sinfo_raw_types.h"
+#include "sinfo_wcal_functions.h"
+#include "sinfo_new_bezier.h"
+
+#include "sinfo_hidden.h"
+#include "sinfo_pro_types.h"
+#include "sinfo_functions.h"
+#include "sinfo_utils_wrappers.h"
+#include "sinfo_error.h"
+
+/*----------------------------------------------------------------------------
+                                Defines
+ ---------------------------------------------------------------------------*/
+/**@{*/
+/**
+ * @addtogroup sinfo_rec_jitter Frame stacking
+ *
+ * TBD
+ */
+
+
+
+/*----------------------------------------------------------------------------
+                             Function Definitions
+ ---------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+   Function     :       sinfo_new_prepare_stacked_frames()
+   In           :       ini_file: file name of according .ini file
+   Out          :       integer (0 if it worked, -1 if it doesn't)
+   Job          :
+  this handles stacks of input frames, that means it takes a clean mean,
+  subtracts the off- from the on-frames, flatfields, corrects for static bad
+  pixels, corrects for a linear tilt of the spectra if necessary, and finally,
+  interleaves dithered exposures or convolves a single exposure with a
+  Gaussian, respectively.
+
+ ---------------------------------------------------------------------------*/
+static int
+new_get_names(const char* pcatg, const int ind, stack_config_n ** cfg);
+
+static int
+new_get_names(const char* pcatg, const int ind, stack_config_n **  cfg){
+
+  if (strcmp(pcatg,PRO_FIBRE_NS_STACKED_OFF) == 0) {
+     strcpy((*cfg)->outName,DISTORTION_STACK_OFF_OUT_FILENAME);
+  }
+  if (strcmp(pcatg,PRO_FIBRE_NS_STACKED_ON)  == 0) {
+     strcpy((*cfg)->outName,"out_ns_stack_on.fits");
+  }
+  if (strcmp(pcatg,PRO_FIBRE_NS_STACKED)     == 0) {
+     strcpy((*cfg)->outName,"out_ns_stack.fits");
+  }
+  if (strcmp(pcatg,PRO_WAVE_LAMP_STACKED)    == 0) {
+     strcpy((*cfg)->outName,"out_wcal_stack.fits");
+  }
+  if (strcmp(pcatg,PRO_FIBRE_NS_STACKED_DIST)== 0) {
+     strcpy((*cfg)->outName,"out_ns_stack_warp.fits");
+  }
+  if (strcmp(pcatg,PRO_WAVE_SLITPOS_STACKED) == 0) {
+     strcpy((*cfg)->outName,"out_slit_pos_stack.fits");
+  }
+
+  if (strcmp(pcatg,PRO_PSF_CALIBRATOR_STACKED)== 0) {
+     snprintf((*cfg)->outName,MAX_NAME_SIZE-1,"%s%d%s","out_stack",ind,".fits");
+  }
+  if (strcmp(pcatg,PRO_SKY_PSF_CALIBRATOR_STACKED)== 0) {
+     strcpy((*cfg)->outName,STACKED_OUT_FILENAME);
+  }
+  if (strcmp(pcatg,PRO_STD_NODDING_STACKED) == 0) {
+     snprintf((*cfg)->outName,MAX_NAME_SIZE-1,"%s%d%s","out_stack",ind,".fits");
+  }
+  /* only 1 frame
+  if (strcmp(pcatg,PRO_STD_NODDING_STACKED) == 0) {
+    strcpy((*cfg)->outName,STACKED_OUT_FILENAME);
+  }
+  */
+
+  if (strcmp(pcatg,PRO_SKY_NODDING_STACKED) == 0) {
+    strcpy((*cfg)->outName,STACKED_OUT_FILENAME); /*STD*/
+  }
+  if (strcmp(pcatg,PRO_OBJECT_NODDING_STACKED) == 0) {
+    snprintf((*cfg)->outName,MAX_NAME_SIZE-1,"%s%d%s","out_stack",ind,".fits");
+  }
+  if (strcmp(pcatg,PRO_PUPIL_LAMP_STACKED) == 0) {
+    snprintf((*cfg)->outName,MAX_NAME_SIZE-1,"%s%d%s","out_stack",ind,".fits");
+  }
+  if (strcmp(pcatg,PRO_STACKED) == 0) {
+    snprintf((*cfg)->outName,MAX_NAME_SIZE-1,"%s%d%s","out_stack",ind,".fits");
+  }
+
+  snprintf((*cfg)->sky_name,MAX_NAME_SIZE-1,"%s%d%s","out_sky",ind,".fits");
+
+  return 0;
+
+}
+
+
+int sinfo_new_prepare_stacked_frames (const char* plugin_id,
+                                cpl_parameterlist* config,
+                                cpl_frameset* sof,
+                                cpl_frameset* ref_set,
+                                const char* frm_pro_ctg,
+                                const int frm_ind,
+                                fake* fk)
+{
+
+
+  stack_config_n * cfg =NULL;
+  cpl_imagelist * list_object=NULL ;
+  cpl_imagelist * list_dither_object=NULL;
+  cpl_imagelist * list_dither_sky=NULL;
+  cpl_imagelist * list_sky=NULL;
+  cpl_imagelist * list_dark=NULL;
+  new_Lookup* lookup=NULL;
+  cpl_image * im3=NULL ;
+  cpl_image * im4=NULL ;
+  cpl_image * im5=NULL ;
+  cpl_image * im6=NULL ;
+  cpl_image * im7=NULL ;
+  cpl_image * im8=NULL ;
+  cpl_image * im9=NULL ;
+
+  cpl_image * ref_im1=NULL ;
+  cpl_image * ref_im2=NULL ;
+  cpl_image ** im=NULL ;
+  cpl_image * im_obj=NULL ;
+  cpl_image* simg=NULL;
+
+  cpl_image * im_dark=NULL ;
+  cpl_image * im_sky=NULL ;
+  cpl_image * im_dither=NULL ;
+  cpl_image * im_dither_sky=NULL ;
+  cpl_image * im_obj_sub=NULL ;
+  cpl_image * im_obj_flat=NULL ;
+  cpl_image * im_dither_sub=NULL ;
+  cpl_image * im_dither_flat=NULL ;
+  cpl_image * int_im_shifted=NULL ;
+  cpl_image * int_im_dith_shifted=NULL ;
+  cpl_image * im_conv=NULL ;
+  int sy=0;
+
+  cpl_image * mask_im=NULL ;
+  cpl_image * flat_smooth=NULL ;
+  cpl_image * flat1=NULL ;
+  cpl_image * flat2=NULL ;
+  cpl_image * int_im=NULL ;
+  cpl_image * int_im_dith=NULL ;
+  cpl_image * sky_img_flat=NULL;
+  cpl_image * sky_dist=NULL;
+
+
+  cpl_imagelist * iCube=NULL ;
+  cpl_imagelist * jCube=NULL ;
+  cpl_image * X=NULL ;
+  cpl_image * hX=NULL ;
+  cpl_image * Y=NULL ;
+  cpl_image * Z=NULL ;
+  cpl_table * qclog_tbl=NULL;
+  cpl_image* sky_img=NULL;
+  cpl_image* mdark=NULL;
+
+  char* name=NULL;
+  int typ=0;
+  int pos=0;
+  int i = 0;
+  int n = 0;
+  int cnt = 0 ;
+  float val_x=0;
+  float val_y=0;
+  int status=0;
+
+  float** slit_edges=NULL;
+  char** in_nam=NULL;
+
+  int nob = 0;
+  int nsky = 0;
+  int nobjdith = 0;
+  int nskydith = 0;
+  int nda = 0;
+  char name_list[MAX_NAME_SIZE];
+  char fake_sky_name[MAX_NAME_SIZE];
+  int no=0;
+  float lo_cut=0;
+  float hi_cut=0;
+
+  cpl_imagelist* list_object_tmp=NULL;
+  cpl_imagelist* list_dither_object_tmp=NULL;
+  cpl_imagelist* list_sky_tmp=NULL;
+  cpl_imagelist* list_dither_sky_tmp=NULL;
+
+  cpl_image* flat1_dist=NULL;
+  cpl_image* flat2_dist=NULL;
+
+  cpl_frameset* raw=NULL;
+
+  char file_name[MAX_NAME_SIZE];
+  cpl_table* tbl_index = NULL;
+  cpl_table* tbl_slitpos=NULL;
+  int rhead=0;
+
+  cpl_frame*     sky_frame = NULL;
+  char* sky_name  = NULL;
+  char* sky_tag   = NULL;
+  qc_wcal* qc=sinfo_qc_wcal_new();
+
+  cpl_parameter* p=NULL;
+  int pdensity=0;
+  int mflat_norm_smooth=FALSE;
+
+  int smooth_rad=16;
+  int sub_raw_sky=1;
+
+  /*
+       -----------------------------------------------------------------
+       1) parse the file names and parameters to the psf_config data
+          structure cfg
+       -----------------------------------------------------------------
+  */
+
+
+  check_nomsg(p=cpl_parameterlist_find(config,"sinfoni.product.density"));
+  check_nomsg(pdensity=cpl_parameter_get_int(p));
+
+
+
+  check_nomsg(p=cpl_parameterlist_find(config,
+				       "sinfoni.stacked.mflat_norm_smooth"));
+  check_nomsg(mflat_norm_smooth=cpl_parameter_get_int(p));
+
+
+
+  check_nomsg(p=cpl_parameterlist_find(config,
+				       "sinfoni.stacked.mflat_smooth_rad"));
+  check_nomsg(smooth_rad=cpl_parameter_get_int(p));
+
+  check_nomsg(p=cpl_parameterlist_find(config,"sinfoni.stacked.sub_raw_sky"));
+  check_nomsg(sub_raw_sky=cpl_parameter_get_bool(p));
+
+
+  check_nomsg(raw=cpl_frameset_new());
+  cknull(cfg = sinfo_parse_cpl_input_stack(config,sof,&raw, fk),
+        "could not parse cpl input file!") ;
+
+  ck0(sinfo_det_ncounts(raw, cfg->qc_thresh_max,qc),"computing det ncounts");
+
+
+  if(ref_set != NULL) {
+    sinfo_free_frameset(&raw);
+    raw=cpl_frameset_duplicate(ref_set);
+  }
+  /* defines output file name for stack set i */
+  ck0_nomsg(new_get_names(frm_pro_ctg, frm_ind, &cfg));
+
+  if (cfg->flatInd == 1){
+    if(sinfo_is_fits_file(cfg->flatfield1) != 1) {
+       sinfo_msg_error("Input FF file %s is not FITS",cfg->flatfield1);
+       goto cleanup;
+    }
+
+  }
+  if (cfg->maskInd == 1) {
+    if(sinfo_is_fits_file(cfg->mask) != 1) {
+         sinfo_msg_error("Input mask file %s is not FITS",cfg->mask);
+         goto cleanup;
+    }
+    if(cfg -> indind == 0) {
+      if(sinfo_is_fits_file(cfg->slitposList) != 1) {
+    sinfo_msg_error("Input slitpos file %s is not FITS",cfg->slitposList);
+    goto cleanup;
+      }
+    }
+  }
+
+  /*
+   #---------------------------------------------------------
+   # Take a clean mean of several images
+   # input is 1 or more similar images
+   #---------------------------------------------------------
+  */
+
+  if (cfg->sfInd == 1){
+    if (cfg->contains_dark == 0) {
+      sinfo_msg_warning("no sinfo_dark frames given!");
+    }
+    if (cfg->contains_ref == 0) {
+      sinfo_msg_error("no reference frames given!");
+      goto cleanup;
+    }
+  }
+
+  /* allocate memory for lists of object, sky and dithered frames */
+  check(list_object=cpl_imagelist_new(),
+        "could not allocate memory for object frame");
+
+  if (cfg->contains_dither == 1) {
+    check(list_dither_object=cpl_imagelist_new(),
+          "could not allocate memory for dither object frame");
+  }
+
+  if (cfg->contains_sky == 1) {
+    check(list_sky = cpl_imagelist_new(),
+       "could not allocate memory for off frame list");
+  }
+
+  if (cfg->contains_dither == 1 && cfg->nditheroff > 0) {
+     check(list_dither_sky = cpl_imagelist_new(),
+       "could not allocate memory for dither frame list");
+  }
+
+  if (cfg->contains_dark == 1 && cfg->sfInd == 1) {
+     check(list_dark = cpl_imagelist_new(),
+       "could not allocate memory for sinfo_dark frame");
+  }
+
+  if (cfg->contains_dither == 0 && cfg->nditheroff > 0) {
+     sinfo_msg_error("please use non-dithered off-frames, remove the 2!");
+     goto cleanup;
+  }
+
+  /* build different image lists for the different cases */
+  cknull_nomsg(im=(cpl_image**)cpl_calloc(cfg -> nframes, sizeof(cpl_image*)));
+
+  for (i=0; i< cfg->nframes; i++) {
+     name = cfg->framelist[i];
+     if(sinfo_is_fits_file(name) != 1) {
+       sinfo_msg_error("Input file %s is not FITS",name);
+       goto cleanup;
+     }
+     check_nomsg(im[i] = cpl_image_load( name,CPL_TYPE_FLOAT,0,0));
+  }
+
+  /* up to here leak free */
+  rhead=0;
+  for (i=0; i< cfg->nframes; i++) {
+    typ = sinfo_new_intarray_get_value( cfg->frametype, i );
+    pos = sinfo_new_intarray_get_value( cfg->frameposition, i );
+    cknull(im[i],"could not load image");
+
+    if (pos == 2) {
+      if (typ == 1) {
+        check_nomsg(cpl_imagelist_set(list_object,
+                                      cpl_image_duplicate(im[i]),nob));
+        nob = nob + 1;
+      }
+      else if ( typ == 0 ) {
+        check_nomsg(cpl_imagelist_set(list_sky,
+                    cpl_image_duplicate(im[i]),nsky));
+        nsky = nsky + 1;
+	if(pdensity > 0) {
+	  if(fk->is_fake_sky==1) {
+	    snprintf(fake_sky_name,MAX_NAME_SIZE-1,"%s%d%s","out_fake_sky",
+		     frm_ind,".fits");
+	    check_nomsg(sky_img=cpl_image_load(fake_sky_name,CPL_TYPE_FLOAT,0,0));
+	    ck0(sinfo_pro_save_ima(sky_img,raw,sof,fake_sky_name,
+				   PRO_SKY_DUMMY,NULL,
+				   plugin_id,config),
+		"cannot save sky ima %s", fake_sky_name);
+
+	    sinfo_free_image(&sky_img);
+	  }
+	}
+
+
+        if((pdensity == 3) || (pdensity == 1) ||
+           (pdensity == 2 && frm_ind == 0)) {
+	  check_nomsg(sky_frame = cpl_frameset_get_frame(raw,i));
+	  check_nomsg(sky_name  = (char*) cpl_frame_get_filename(sky_frame));
+	  check_nomsg(sky_tag   = (char*) cpl_frame_get_tag(sky_frame));
+
+          if ( (strstr(frm_pro_ctg,"OBJECT") != NULL) ||
+               (strstr(frm_pro_ctg,"PSF") != NULL) ||
+               (strstr(frm_pro_ctg,"STD") != NULL) ) {
+	    check_nomsg(sky_img = cpl_image_load(sky_name,CPL_TYPE_FLOAT,0,0));
+	    snprintf(sky_name,MAX_NAME_SIZE-1,"%s%2.2d%s","out_sky",
+		     frm_ind,".fits");
+	    ck0(sinfo_pro_save_ima(sky_img,raw,sof,sky_name,
+				   PRO_SKY_STACKED_DUMMY,NULL,
+                                   plugin_id,config),
+		"cannot save sky ima %s", sky_name);
+
+	    sinfo_free_image(&sky_img);
+	    if (cfg->flatInd == 1) {
+	      sinfo_msg("Sky Flatfielding");
+	      check(flat1=cpl_image_load(cfg->flatfield1,CPL_TYPE_FLOAT,0,0 ),
+		    "could not load flatfield image" );
+
+              if(mflat_norm_smooth != 0) {
+
+                if(mflat_norm_smooth == 1) {
+
+                   sy=cpl_image_get_size_y(flat1);
+
+                   cknull(flat_smooth=sinfo_image_smooth_fft(flat1,sy/smooth_rad),
+		       "could not smooth flatfield" );
+                } else if(mflat_norm_smooth == 2) {
+                   cknull(flat_smooth = sinfo_image_smooth_median_y(flat1,
+                                                                    smooth_rad),
+                          "could not smooth flatfield" );
+                 }
+
+	        check_nomsg(cpl_image_divide(flat1,flat_smooth));
+	        sinfo_free_image(&flat_smooth);
+
+	      }
+
+	      check_nomsg(simg = cpl_image_load(sky_name,CPL_TYPE_FLOAT,0,0 ));
+
+	      cknull(sky_img_flat=sinfo_new_div_images_robust(simg,flat1),
+		     "could not carry out flatfield division" );
+	      sinfo_free_image(&simg);
+	      sinfo_free_image(&flat1);
+
+	      /* if (frm_ind == 0) { */
+	      if (cfg->warpfixInd == 1){
+		sinfo_msg("Correct sky for distortions");
+                snprintf(file_name,MAX_NAME_SIZE-1,"%s%d%s",
+                         STACK_SKY_DIST_OUT_FILENAME,frm_ind,".fits");
+		sky_dist = sinfo_new_image_warp_fits(sky_img_flat,
+						     cfg->kernel,
+						     cfg->polyFile);
+
+		ck0(sinfo_pro_save_ima(sky_dist,raw,sof,
+				       file_name,
+				       PRO_STACK_SKY_DIST,NULL,plugin_id,
+				       config),"cannot save ima %s",
+		    STACK_SKY_DIST_OUT_FILENAME);
+
+		sinfo_free_image(&sky_dist);
+	      }
+	      /* } */
+	      sinfo_free_image(&sky_img_flat);
+	    } /* end check on flatind */
+	  } /* end check on procatg */
+	}
+      } else if ( typ == 5 ) {
+    if (cfg->sfInd == 1) {
+      check_nomsg(cpl_imagelist_set(list_dark,
+                      cpl_image_duplicate(im[i]),nda));
+      nda = nda + 1;
+    } else {
+      sinfo_free_image(&(im[i]));
+    }
+      } else if ( typ == 4 ) {
+    if ( cfg->sfInd == 1) {
+      ref_im1 = im[i];
+    } else {
+      sinfo_free_image(&(im[i]));
+    }
+      }
+    } else {
+      if (typ == 1) {
+       check_nomsg(cpl_imagelist_set(list_dither_object,
+                                     cpl_image_duplicate(im[i]),nobjdith));
+       nobjdith = nobjdith + 1;
+      } else if (typ == 0) {
+    check_nomsg(cpl_imagelist_set(list_dither_object,
+                                     cpl_image_duplicate(im[i]),nskydith));
+    nskydith = nskydith + 1;
+      } else if (typ == 4) {
+    if (cfg->sfInd == 1) {
+      ref_im2 = cpl_image_duplicate(im[i]);
+    } else {
+      sinfo_free_image(&(im[i]));
+    }
+      }
+    }
+  } /* end for loop on i */
+
+  if (nob != cfg->nobj ||
+      cfg->noff != nsky ||
+      nobjdith != cfg->nditherobj ||
+      nskydith != cfg->nditheroff) {
+    sinfo_msg_error("something is wrong with the number of the");
+    sinfo_msg_error("different types of frames");
+    /* free memory */
+    goto cleanup;
+
+  }
+
+  if (cfg->sfInd == 1 && nda != cfg->ndark) {
+    sinfo_msg_error("something is wrong with the number of sinfo_dark frames");
+    goto cleanup;
+  }
+  sinfo_msg("Create and fill cubes with the different images");
+
+  /* create and fill cubes with the different image lists */
+  cknull(list_object,"could not create object data cube!");
+
+  /* shift the images in the cubes-if indicated-in spectral direction
+     with respect to the reference image
+  */
+  if (cfg->sfInd == 1) {
+
+  /*
+      first take the mean of the sinfo_dark frames and subtract the result
+      from all cubes
+  */
+  sinfo_msg("Shift cube images in spectral direction with "
+            "respect to reference");
+
+  if (cfg->contains_dark == 1) {
+    sinfo_msg("cfg->contains_dark == 1");
+    if (cfg->loReject*cfg->ndark < 1. && cfg->hiReject * cfg->ndark < 1.) {
+      /*
+          im_dark = sinfo_new_average_cube_to_image( list_dark );
+      */
+      check(im_dark = cpl_imagelist_collapse_create( list_dark ),
+     "sinfo_averageCubeToImage failed" );
+     }
+     else {
+
+       check_nomsg(no=cpl_imagelist_get_size(list_dark));
+       lo_cut=(floor)( cfg->loReject*no+0.5);
+       hi_cut=(floor)( cfg->hiReject*no+0.5);
+       check(im_dark=cpl_imagelist_collapse_minmax_create(list_dark,lo_cut,
+                                                          hi_cut),
+                                     "sinfo_average_with_rejection failed" );
+
+     }
+     sinfo_free_imagelist(&list_dark);
+     check_nomsg(list_object_tmp = cpl_imagelist_duplicate (list_object));
+     check(cpl_imagelist_subtract_image (list_object_tmp, im_dark),
+            "cpl_imagelist_subtract_image failed" );
+     /*
+       cube_object_tmp = sinfo_subImageFromCube (cube_object, im_dark);
+     */
+  } else {
+     sinfo_msg("cfg->contains_dark == 0");
+     check_nomsg(list_object_tmp = cpl_imagelist_duplicate(list_object));
+  }
+  sinfo_free_imagelist(&list_object);
+
+  cknull(list_object = sinfo_align_cube_to_reference (list_object_tmp,
+                              ref_im1,
+                              cfg->sfOrder,
+                              cfg->sfType),
+     "sinfo_align_cube_to_reference failed" );
+
+  sinfo_free_imagelist(&list_object_tmp);
+  if (cfg->contains_dither == 1) {
+    if (cfg->contains_dark == 1) {
+       check_nomsg(list_dither_object_tmp =
+                   cpl_imagelist_duplicate(list_dither_object));
+       check(cpl_imagelist_subtract_image(list_dither_object_tmp,im_dark),
+             "sinfo_average_with_rejection failed" );
+
+       /*
+        list_dither_object_tmp =
+              sinfo_new_sub_image_from_cube(list_dither_object,
+                                                    im_dark);
+    */
+
+    } else {
+       check_nomsg(list_dither_object_tmp=
+                   cpl_imagelist_duplicate(list_dither_object));
+    }
+    sinfo_free_imagelist(&list_dither_object);
+
+    cknull(list_dither_object=
+            sinfo_align_cube_to_reference (list_dither_object_tmp,
+                                 ref_im2,
+                                 cfg->sfOrder,
+                                 cfg->sfType),
+       "sinfo_align_cube_to_reference failed" );
+
+    sinfo_free_imagelist(&list_dither_object_tmp);
+  }
+  if (cfg->contains_sky == 1) {
+    if (cfg->contains_dark == 1) {
+       check_nomsg(list_sky_tmp = cpl_imagelist_duplicate(list_sky));
+       check(cpl_imagelist_subtract_image (list_sky_tmp, im_dark),
+         "sinfo_average_with_rejection failed" );
+       /*
+      cube_sky_tmp = sinfo_subImageFromCube (cube_sky, im_dark);
+       */
+
+    } else {
+       check_nomsg(list_sky_tmp = cpl_imagelist_duplicate(list_sky));
+    }
+    check_nomsg(list_sky_tmp=cpl_imagelist_duplicate(list_sky));
+
+    check(list_sky = sinfo_align_cube_to_reference (list_sky_tmp,
+                            ref_im1,
+                            cfg->sfOrder,
+                            cfg->sfType),
+      "sinfo_alignCubeToReference failed" );
+
+    check_nomsg(cpl_imagelist_delete(list_sky_tmp));
+  }
+  if (cfg->contains_dither == 1 && cfg->contains_sky == 1) {
+    if (cfg->contains_dark == 1) {
+      check_nomsg(list_dither_sky_tmp=cpl_imagelist_duplicate(list_dither_sky));
+      check(cpl_imagelist_subtract_image(list_dither_sky_tmp,im_dark),
+        "sinfo_average_with_rejection failed" );
+       /*
+       cube_dither_sky_tmp = sinfo_subImageFromCube (cube_dither_sky, im_dark);
+       */
+
+    } else {
+      check_nomsg(list_dither_sky_tmp=cpl_imagelist_duplicate(list_dither_sky));
+    }
+    sinfo_free_imagelist(&list_dither_sky);
+
+    check(list_dither_sky=sinfo_align_cube_to_reference(list_dither_sky_tmp,
+                                ref_im2,
+                                cfg->sfOrder,
+                                cfg->sfType),
+      "sinfo_alignCubeToReference failed" );
+
+    sinfo_free_imagelist(&list_dither_sky_tmp);
+  }
+  sinfo_free_image(&ref_im1);
+  if (cfg->contains_dither == 1) {
+    sinfo_free_image(&ref_im2);
+  }
+  if (cfg->contains_dark == 1) {
+    sinfo_free_image(&im_dark);
+  }
+
+  } /* end if over sfInd */
+
+  /* subtracts the master dark from different frames if present */
+  if(cfg->mdark_ind==1){
+    sinfo_msg("Subtract master dark %s ",cfg->mdark);
+
+    check_nomsg(mdark=cpl_image_load(cfg->mdark,CPL_TYPE_FLOAT,0,0));
+    if (list_object !=NULL) {
+      cpl_imagelist_subtract_image (list_object, mdark);
+    }
+    if (list_sky !=NULL) {
+      cpl_imagelist_subtract_image (list_sky, mdark);
+    }
+    sinfo_free_image(&mdark);
+  }
+  /* take the average with rejection of the different cubes */
+  sinfo_msg("Take the average of the different cubes");
+
+  if (cfg->loReject*cfg->nobj < 1. && cfg->hiReject * cfg->nobj < 1.) {
+    check(im_obj = cpl_imagelist_collapse_create(list_object),
+      "Average with rejection failed" );
+  } else {
+
+    check_nomsg(no=cpl_imagelist_get_size(list_object));
+    lo_cut=(floor)( cfg->loReject*no+0.5);
+    hi_cut=(floor)( cfg->hiReject*no+0.5);
+    check(im_obj=cpl_imagelist_collapse_minmax_create(list_object,
+                 lo_cut,hi_cut),"Average with rejection failed" );
+
+  }
+  sinfo_free_imagelist(&list_object);
+
+  if (cfg->contains_sky == 1) {
+    if (cfg->loReject*nsky < 1. && cfg->hiReject*nsky < 1.) {
+      /* here might explode in dither mode */
+      cknull(im_sky = cpl_imagelist_collapse_create( list_sky ),
+         "Average with rejection failed");
+    } else {
+
+      check_nomsg(no=cpl_imagelist_get_size(list_sky));
+      lo_cut=(floor)( cfg->loReject*no+0.5);
+      hi_cut=(floor)( cfg->hiReject*no+0.5);
+      check(im_sky=cpl_imagelist_collapse_minmax_create(list_sky,lo_cut,hi_cut),
+         "Average with rejection failed");
+    }
+    sinfo_free_imagelist(&list_sky);
+  }
+
+  if (cfg->contains_dither == 1) {
+    if (cfg->loReject*nobjdith < 1. && cfg->hiReject*nobjdith < 1.) {
+      check(im_dither = cpl_imagelist_collapse_create( list_dither_object ),
+        "Average with rejection failed");
+    } else {
+
+      check_nomsg(no=cpl_imagelist_get_size(list_dither_object));
+      lo_cut=(floor)( cfg->loReject*no+0.5);
+      hi_cut=(floor)( cfg->hiReject*no+0.5);
+      check(im_dither=cpl_imagelist_collapse_minmax_create(list_dither_object,
+                               lo_cut,hi_cut),
+        "Average with rejection failed");
+
+    }
+    sinfo_free_imagelist(&list_dither_object);
+  }
+
+  if (cfg->contains_dither == 1 && nskydith > 0) {
+    if (cfg->loReject*nskydith < 1. && cfg->hiReject*nskydith < 1.) {
+      check(im_dither_sky = cpl_imagelist_collapse_create( list_dither_sky ),
+        "Average with rejection failed");
+    } else {
+
+      check_nomsg(no=cpl_imagelist_get_size(list_dither_sky));
+      lo_cut=(floor)( cfg->loReject*no+0.5);
+      hi_cut=(floor)( cfg->hiReject*no+0.5);
+      check(im_dither_sky=cpl_imagelist_collapse_minmax_create(list_dither_sky,
+                                   lo_cut,hi_cut),
+        "Average with rejection failed");
+    }
+    sinfo_free_imagelist(&list_dither_sky);
+  }
+
+  /*
+  #---------------------------------------------------------
+  # Subtract the resulting off-frame (sky) from the on-frame
+  #-------------------------------------------------------
+  # finally, subtract off from on frames and store the result
+  # in the object cube
+  */
+
+  if(sub_raw_sky == 1 ) {
+    if (cfg->contains_sky == 1) {
+      sinfo_msg("Subtract the off-frame (sky) from the on-frame");
+      check_nomsg(im_obj_sub = cpl_image_duplicate(im_obj));
+      check(cpl_image_subtract(im_obj_sub, im_sky),
+	    "could not sinfo_sub_image");
+
+      sinfo_free_image(&im_obj);
+      if (((cfg->contains_dither == 1) && (nskydith > 0)) ||
+          cfg->contains_dither == 0) {
+	sinfo_free_image(&im_sky);
+	im_obj = cpl_image_duplicate(im_obj_sub);
+      }
+    }
+
+    if (cfg->contains_dither == 1 && nskydith > 0) {
+      check_nomsg(im_dither_sub = cpl_image_duplicate(im_dither));
+      check(cpl_image_subtract(im_dither_sub, im_dither_sky),
+	    "could not sinfo_sub_image");
+
+      sinfo_free_image(&im_dither);
+      sinfo_free_image(&im_dither_sky);
+      im_dither = cpl_image_duplicate(im_dither_sub);
+
+    } else if (cfg->contains_dither == 1 &&
+	       nskydith == 0 &&
+	       cfg->contains_sky == 1) {
+      check_nomsg(im_dither_sub = cpl_image_duplicate(im_dither));
+      check(cpl_image_subtract(im_dither_sub, im_sky),
+	    "could not sinfo_sub_image");
+
+      sinfo_free_image(&im_dither);
+      sinfo_free_image(&im_sky);
+      im_dither = cpl_image_duplicate(im_dither_sub);
+    }
+  }
+
+  /*
+  #---------------------------------------------------------
+  # Flatfielding
+  #---------------------------------------------------------
+  */
+
+  if (cfg->flatInd == 1) {
+    sinfo_msg("Flatfielding");
+    check(flat1 = cpl_image_load (cfg->flatfield1,CPL_TYPE_FLOAT,0,0),
+      "could not load flatfield image" );
+
+    if(mflat_norm_smooth) {
+
+      //We normalize the flat by a smoothed flat
+      cknull(flat_smooth = sinfo_image_smooth_median_y(flat1,smooth_rad),
+	     "could not smooth flatfield" );
+      check_nomsg(cpl_image_divide(flat1,flat_smooth));
+      sinfo_free_image(&flat_smooth);
+    }
+
+    cknull(im_obj_flat = sinfo_new_div_images_robust( im_obj, flat1),
+       "could not carry out flatfield division" );
+
+    /* AMO ** */
+    if(pdensity > 1) {
+      if (frm_ind == 0) {
+	if (cfg->warpfixInd == 1){
+	  sinfo_msg("Correct FF for distortions");
+	  /* AMO check */
+	  cknull_nomsg(flat1_dist=sinfo_new_image_warp_fits(flat1,cfg->kernel,
+							    cfg->polyFile));
+
+	  ck0(sinfo_pro_save_ima(flat1_dist,raw,sof,
+				 STACK_MFLAT_DIST_OUT_FILENAME,
+				 PRO_STACK_MFLAT_DIST,NULL,plugin_id,config),
+	      "cannot save ima %s", STACK_MFLAT_DIST_OUT_FILENAME);
+	  sinfo_free_image(&flat1_dist);
+	}
+      }
+    }
+    sinfo_free_image(&flat1);
+    sinfo_free_image(&im_obj);
+    im_obj = cpl_image_duplicate(im_obj_flat);
+
+    if(pdensity > 1) {
+      if (cfg->contains_dither == 1) {
+	check(flat2 = cpl_image_load (cfg->flatfield2,CPL_TYPE_FLOAT,0,0),
+	      "could not load flatfield image" );
+
+	if(mflat_norm_smooth) {
+
+	  //We normalize the flat by a smoothed flat
+	  cknull(flat_smooth = sinfo_image_smooth_median_y(flat2,smooth_rad),
+		 "could not smooth flatfield" );
+	  check_nomsg(cpl_image_divide(flat2,flat_smooth));
+	  sinfo_free_image(&flat_smooth);
+
+	}
+
+
+	cknull(im_dither_flat = sinfo_new_div_images_robust( im_dither, flat2),
+	       "could not carry out flatfield division" );
+
+	if (frm_ind == 0) {
+	  if (cfg->warpfixInd == 1) {
+	    sinfo_msg("Correct FF for distortions");
+	    flat2_dist = sinfo_new_image_warp_fits(flat2,
+						   cfg->kernel, cfg->polyFile);
+
+	    ck0(sinfo_pro_save_ima(flat2_dist,raw,sof,
+				   STACK_MFLAT_DITHER_DIST_OUT_FILENAME,
+				   PRO_STACK_MFLAT_DITHER_DIST,
+				   NULL,plugin_id,config),
+		"cannot save ima %s", STACK_MFLAT_DITHER_DIST_OUT_FILENAME);
+	    sinfo_free_image(&flat2_dist);
+	  }
+	}
+	sinfo_free_image(&flat2);
+	sinfo_free_image(&im_dither);
+	im_dither = cpl_image_duplicate(im_dither_flat);
+      }
+    }
+  }
+
+  /*
+  #---------------------------------------------------------
+  # static bad pixel correction
+  #---------------------------------------------------------
+   */
+
+  if (cfg->maskInd == 1) {
+    sinfo_msg("Static bad pixel correction");
+    check(mask_im = cpl_image_load(cfg->mask,CPL_TYPE_FLOAT,0,0),
+      "could not load static bad pixel mask" );
+
+    ck0(sinfo_new_change_mask(mask_im, im_obj),
+    "sinfo_changeMask failed" );
+
+    if (cfg->indind == 0) {
+      /* open the ASCII list of the slitlet positions */
+      /*READ TFITS TABLE*/
+      strcpy(file_name,cfg->slitposList);
+      check(tbl_slitpos = cpl_table_load(file_name,1,0),
+        "error loading slitpos tbl %s ",file_name);
+      if(cpl_table_has_column(tbl_slitpos,"pos1") != 1) {
+        sinfo_msg_error("Column 'pos1' not found in %s table %s",
+                      PRO_SLIT_POS,file_name);
+    goto cleanup;
+      }
+      if(cpl_table_has_column(tbl_slitpos,"pos2") != 1) {
+        sinfo_msg_error("Column 'pos2' not found in %s table %s",
+                      PRO_SLIT_POS,file_name);
+    goto cleanup;
+      }
+
+      check_nomsg(n = cpl_table_get_nrow(tbl_slitpos));
+      cknull_nomsg(slit_edges = sinfo_new_2Dfloatarray(n, 2));
+      for (i =0 ; i< n; i++){
+     check_nomsg(val_x=cpl_table_get_double(tbl_slitpos,"pos1",i,&status));
+    check_nomsg(val_y=cpl_table_get_double(tbl_slitpos,"pos2",i,&status));
+    check_nomsg(sinfo_new_array2D_set_value(slit_edges,val_x,i,0));
+    check_nomsg(sinfo_new_array2D_set_value(slit_edges,val_y,i,1));
+      }
+
+      sinfo_free_table(&tbl_slitpos);
+      cknull(int_im = sinfo_interpol_source_image (im_obj,
+                         mask_im,
+                         cfg->maxRad,
+                         slit_edges),
+     "could not carry out sinfo_interpolSourceImage" );
+
+      sinfo_free_image(&im_obj);
+      im_obj = cpl_image_duplicate(int_im);
+
+     if (cfg->contains_dither == 1) {
+       cknull(int_im_dith = sinfo_interpol_source_image (im_dither,
+                               mask_im,
+                               cfg->maxRad,
+                               slit_edges),
+          "could not carry out sinfo_interpolSourceImage" );
+
+       sinfo_free_image(&im_dither);
+       im_dither = cpl_image_duplicate(int_im_dith);
+     }
+     sinfo_new_destroy_2Dfloatarray(&slit_edges, 32);
+    } else {
+      cknull(int_im = sinfo_new_mult_image_by_mask(im_obj, mask_im),
+         "could not carry out sinfo_multImageByMask" );
+
+      sinfo_free_image(&im_obj);
+      im_obj = cpl_image_duplicate(int_im);
+      if (cfg->contains_dither == 1) {
+    cknull(int_im_dith=sinfo_new_mult_image_by_mask(im_dither, mask_im),
+           "could not carry out sinfo_multImageByMask" );
+
+    sinfo_free_image(&im_dither);
+    im_dither = cpl_image_duplicate(int_im_dith);
+      }
+    }
+    sinfo_free_image(&mask_im);
+  }
+
+  /*
+  #---------------------------------------------------------
+  # static bad pixel correction BEZIER
+  #---------------------------------------------------------
+  */
+
+  if (cfg->maskInd == 2){
+    sinfo_msg("Static bad pixel correction BEZIER");
+    check(mask_im = cpl_image_load(cfg->mask,CPL_TYPE_FLOAT,0,0),
+      "could not load static bad pixel mask" );
+
+    ck0(sinfo_new_change_mask(mask_im, im_obj),
+    "sinfo_changeMask failed" );
+
+    /* #open the FITS table of the slitlet positions-*/
+    strcpy(file_name,cfg->slitposList);
+    check_nomsg(tbl_slitpos = cpl_table_load(file_name,1,0));
+
+    check_nomsg(n = cpl_table_get_nrow(tbl_slitpos));
+    slit_edges = sinfo_new_2Dfloatarray(n, 2);
+
+    for (i =0 ; i< n; i++){
+      val_x=cpl_table_get_double(tbl_slitpos,"pos1",i,&status);
+      val_y=cpl_table_get_double(tbl_slitpos,"pos2",i,&status);
+      sinfo_new_array2D_set_value(slit_edges,val_x,i,0);
+      sinfo_new_array2D_set_value(slit_edges,val_y,i,1);
+    }
+    sinfo_free_table(&tbl_slitpos);
+
+    strcpy(file_name,cfg->indexlist);
+
+    check_nomsg(tbl_index = cpl_table_load(file_name,1,0));
+
+    check_nomsg(n = cpl_table_get_nrow(tbl_index));
+
+    cknull_nomsg(in_nam = (char**) cpl_calloc(n,sizeof(char*)));
+
+    for (i =0 ; i< n; i++){
+      strcpy(in_nam[i],cpl_table_get_string(tbl_index,"name",i));
+    }
+    sinfo_free_table(&tbl_index);
+
+    for (i=0;i<cnt;i++) {
+      if (strcmp("ICube.fits", name) != 0){
+    check_nomsg(iCube=cpl_imagelist_load ("ICube.fits",CPL_TYPE_FLOAT,0));
+      }
+      else if (strcmp("JCube.fits", name) != 0) {
+    check_nomsg(jCube = cpl_imagelist_load ("JCube.fits",CPL_TYPE_FLOAT,0));
+      }
+      else if (strcmp("X.fits",  name) != 0) {
+    check_nomsg(X=cpl_image_load("X.fits",CPL_TYPE_FLOAT,0,0));
+      }
+      else if (strcmp("Y.fits",  name) != 0) {
+    check_nomsg(Y=cpl_image_load("Y.fits",CPL_TYPE_FLOAT,0,0));
+      }
+      else if (strcmp("Z.fits",  name) != 0) {
+    check_nomsg(Z=cpl_image_load("Z.fits",CPL_TYPE_FLOAT,0,0));
+      }
+      else if (strcmp("cX.fits", name) != 0) {
+    check_nomsg(hX=cpl_image_load("cX.fits",CPL_TYPE_FLOAT,0,0));
+      }
+      else {
+    sinfo_msg_error("wrong name in index list or needed file not there!");
+    goto cleanup;
+      }
+    }
+    lookup = sinfo_new_lookup();
+
+    lookup->id=iCube;
+    lookup->jd=jCube;
+    lookup->X=X;
+    lookup->Y=Y;
+    lookup->Z=Z;
+    lookup->hX=hX;
+
+
+    cknull(im_obj=sinfo_new_c_bezier_interpolate_image(im_obj,
+                                                       mask_im,
+                                                       lookup,
+                               cfg->maxRad,
+                               cfg->maxRad,
+                                                       cfg->maxRad,
+                                                       2,
+                                                       slit_edges),
+       "could not carry out sinfo_new_c_bezier_interpolate_image" );
+
+
+    cknull(im_obj=sinfo_new_c_bezier_find_bad( im_obj,
+                           mask_im,
+                           cfg->maxRad,
+                           cfg->maxRad,
+                           cfg->maxRad,
+                           0,
+                           cpl_image_get_size_x(im_obj),
+                           0,
+                           cpl_image_get_size_y(im_obj),
+                           cfg->sigmaFactor),
+       "could not carry out sinfo_new_c_bezier_find_bad" );
+
+
+    if (cfg->contains_dither == 1) {
+         cknull(im_dither=sinfo_new_c_bezier_interpolate_image(im_dither,
+                                   mask_im,
+                                   lookup,
+                                   cfg->maxRad,
+                                   cfg->maxRad,
+                                   cfg->maxRad,
+                                                               2,
+                                                               slit_edges),
+    "could not carry out new_c_bezier_Interpolate_Image on dithered frame" );
+
+     cknull(im_dither=sinfo_new_c_bezier_find_bad(im_dither,
+                              mask_im,
+                              cfg->maxRad,
+                              cfg->maxRad,
+                              cfg->maxRad,
+                              0,
+                              cpl_image_get_size_x(im_obj),
+                              0,
+                              cpl_image_get_size_y(im_obj),
+                              cfg->sigmaFactor),
+        "could not carry out new_c_bezier_find_bad on dithered frame");
+
+    }
+    sinfo_new_destroy_2Dfloatarray(&slit_edges, 32);
+    sinfo_free_image(&mask_im);
+    sinfo_free_imagelist(&iCube);
+    sinfo_free_imagelist(&jCube);
+    sinfo_free_image(&lookup->X);
+    sinfo_free_image(&lookup->X);
+    sinfo_free_image(&lookup->Y);
+    sinfo_free_image(&lookup->hX);
+    sinfo_new_destroy_lookup(lookup);
+  }
+
+  if (cfg->maskInd == 3) {
+    cknull(mask_im = cpl_image_load(cfg->mask,CPL_TYPE_FLOAT,0,0),
+       "could not load static bad pixel mask" );
+
+    /* #open the ASCII list of the slitlet positions-- */
+    strcpy(file_name,cfg->slitposList);
+    check_nomsg(tbl_slitpos = cpl_table_load(file_name,1,0));
+    if(cpl_table_has_column(tbl_slitpos,"pos1") != 1) {
+      sinfo_msg_error("Column 'pos1' not found in %s table %s",
+                      PRO_SLIT_POS,file_name);
+      goto cleanup;
+    }
+
+    if(cpl_table_has_column(tbl_slitpos,"pos2") != 1) {
+       sinfo_msg_error("Column 'pos2' not found in %s table %s",
+                      PRO_SLIT_POS,file_name);
+       goto cleanup;
+    }
+
+    check_nomsg(n = cpl_table_get_nrow(tbl_slitpos));
+    slit_edges = sinfo_new_2Dfloatarray(n, 2);
+
+    for (i =0 ; i< n; i++) {
+      val_x=cpl_table_get_double(tbl_slitpos,"pos1",i,&status);
+      val_y=cpl_table_get_double(tbl_slitpos,"pos2",i,&status);
+      sinfo_new_array2D_set_value(slit_edges,val_x,i,0);
+      sinfo_new_array2D_set_value(slit_edges,val_y,i,1);
+    }
+    sinfo_free_table(&tbl_slitpos);
+
+    strcpy(file_name,cfg->indexlist);
+    check_nomsg(tbl_index = cpl_table_load(file_name,1,0));
+    check_nomsg(n = cpl_table_get_nrow(tbl_index));
+    cknull_nomsg(in_nam = (char**) cpl_calloc(n,sizeof(char*)));
+
+    for (i =0 ; i< n; i++){
+       strcpy(in_nam[i],cpl_table_get_string(tbl_index,"name",i));
+    }
+    sinfo_free_table(&tbl_index);
+
+    for (i=0;i<cnt;i++){
+      if (strcmp("ICube.fits", in_nam[i]) != 0){
+       check_nomsg(iCube=cpl_imagelist_load("ICube.fits",CPL_TYPE_FLOAT,0));
+      }
+      else if (strcmp("JCube.fits", in_nam[i]) != 0){
+      check_nomsg(jCube=cpl_imagelist_load("JCube.fits",CPL_TYPE_FLOAT,0));
+      }
+      else if (strcmp("X.fits", in_nam[i]) != 0){
+    check_nomsg(X=cpl_image_load("X.fits",CPL_TYPE_FLOAT,0,0));
+      }
+      else if (strcmp("Y.fits", in_nam[i]) != 0){
+    check_nomsg(Y=cpl_image_load("Y.fits",CPL_TYPE_FLOAT,0,0));
+      }
+      else if (strcmp("Z.fits", in_nam[i]) != 0){
+    check_nomsg(Z=cpl_image_load("Z.fits",CPL_TYPE_FLOAT,0,0));
+      }
+      else if (strcmp("cX.fits", in_nam[i]) != 0) {
+    check_nomsg(hX=cpl_image_load("cX.fits",CPL_TYPE_FLOAT,0,0));
+      } else {
+     sinfo_msg_error("wrong name in index list or needed file not there!");
+     goto cleanup;
+      }
+    }
+    lookup = sinfo_new_lookup();
+    lookup->id=iCube;
+    lookup->jd=jCube;
+    lookup->X=X;
+    lookup->Y=Y;
+    lookup->Z=Z;
+    lookup->hX=hX;
+
+    cknull(im_obj = sinfo_new_c_bezier_interpolate_image(im_obj,
+                             mask_im,
+                             lookup,
+                             cfg->maxRad,
+                             cfg->maxRad,
+                             cfg->maxRad,
+                             2,
+                             slit_edges ),
+       "could not carry out sinfo_new_c_bezier_interpolate_image" );
+
+    if (cfg->contains_dither == 1) {
+        cknull(im_dither=sinfo_new_c_bezier_interpolate_image( im_dither,
+                                   mask_im,
+                                   lookup,
+                                   cfg->maxRad,
+                                   cfg->maxRad,
+                                   cfg->maxRad,
+                                   2,
+                                   slit_edges ),
+                  "could not carry out sinfo_new_c_bezier_interpolate_image"
+                  " on dithered frame" );
+
+    }
+    sinfo_new_destroy_2Dfloatarray(&slit_edges, 32);
+    sinfo_free_image(&mask_im);
+    sinfo_free_imagelist(&iCube);
+    sinfo_free_imagelist(&jCube);
+    sinfo_free_image(&lookup->X);
+    sinfo_free_image(&lookup->Y);
+    sinfo_free_image(&lookup->Z);
+    sinfo_free_image(&lookup->hX);
+    sinfo_new_destroy_lookup(lookup);
+  }
+
+
+  /*
+  #---------------------------------------------------------
+  # correction of distortions
+  #---------------------------------------------------------
+  */
+
+  /* here memory leak */
+  //sinfo_msg("cfg->warpfixInd=%d",cfg->warpfixInd);
+  if (cfg->warpfixInd == 1){
+    /*#open ASCII file containing the slope parameter and read it*/
+    sinfo_msg("Correct object for distortions");
+    cknull(int_im_shifted=sinfo_new_image_warp_fits(im_obj,
+                                                    cfg->kernel,
+                                                    cfg->polyFile),
+                                "could not carry out sinfo_image_warp_fits" );
+
+    sinfo_free_image(&im_obj);
+    im_obj = cpl_image_duplicate(int_im_shifted);
+    if (cfg->contains_dither == 1){
+      cknull(int_im_dith_shifted=sinfo_new_image_warp_fits(im_dither,
+                                                           cfg->kernel,
+                                                           cfg->polyFile),
+                                 "could not carry out sinfo_image_warp_fits" );
+      sinfo_free_image(&im_dither);
+      im_dither = cpl_image_duplicate(int_im_dith_shifted);
+    }
+  }
+
+  /*
+  #---------------------------------------------------------
+  # merge (interleave) both resulting frames
+  #---------------------------------------------------------
+  */
+  if (cfg->interInd == 1 && cfg->contains_dither == 1){
+    if( pdensity>1) {
+      sinfo_msg("Merge (interleave) frames");
+      cknull(im3 = cpl_image_new(cpl_image_get_size_x(im_obj),
+				 cpl_image_get_size_y(im_obj),CPL_TYPE_FLOAT),
+	     "could not allocate an image" );
+      cknull(im4=sinfo_new_remove_general_offset( im_obj, im_dither,
+						  im3, cfg->noRows ),
+	     "sinfo_removeGeneralOffset failed" );
+
+      cknull(im5 = sinfo_new_remove_regional_tilt ( im_obj, im4, im3 ),
+	     "sinfo_removeRegionalTilt failed" );
+
+      cknull(im6 = sinfo_new_remove_column_offset ( im_obj, im5, im3 ),
+	     "sinfo_removeColumnOffset failed" );
+
+      cknull(im7 = sinfo_new_remove_residual_tilt ( im6, im3 ),
+	     "sinfo_removeResidualTilt failed" );
+
+      cknull(im8 = sinfo_new_remove_residual_offset ( im7, im3 ),
+	     "sinfo_removeResidualOffset failed");
+      cknull(im9 = sinfo_sinfo_merge_images(im_obj, im8, im3),
+	     "sinfo_mergeImages failed" );
+
+      ck0(sinfo_pro_save_ima(im9,raw,sof,cfg->outName,
+			     frm_pro_ctg,NULL,plugin_id,config),
+	  "cannot save ima %s", cfg->outName);
+
+      sinfo_free_image(&im3);
+      sinfo_free_image(&im4);
+      sinfo_free_image(&im5);
+      sinfo_free_image(&im6);
+      sinfo_free_image(&im7);
+      sinfo_free_image(&im8);
+      sinfo_free_image(&im9);
+      sinfo_free_image(&im_obj);
+      sinfo_free_image(&im_dither);
+    }
+    /*
+    #---------------------------------------------------------
+    # convolve spectra with Gaussian
+    #---------------------------------------------------------
+    */
+  } else if (cfg->gaussInd == 1 && cfg->interInd == 0) {
+    sinfo_msg("Convolve spectra with Gaussian");
+    if(pdensity > 1) {
+      cknull(im_conv = sinfo_new_convolve_image_by_gauss ( im_obj, cfg->hw ),
+	     "sinfo_convolveImageByGauss failed" );
+
+      ck0(sinfo_pro_save_ima(im_conv,raw,sof,cfg->outName,
+			     frm_pro_ctg,NULL,plugin_id,config),
+	  "cannot save ima %s", cfg->outName);
+
+      sinfo_free_image(&im_obj);
+      sinfo_free_image(&im_conv);
+      if (cfg->contains_dither == 1){
+	sinfo_free_image(&im_dither);
+      }
+    }
+  } else {
+
+    sinfo_msg("Add QC LOG");
+    /* add QC-LOG */
+    /* sinfo_det_ncounts(raw, cfg->qc_thresh_max); */
+    cknull_nomsg(qclog_tbl = sinfo_qclog_init());
+
+    ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC FRMON MEANFLUX",
+				     qc->avg_on,"Average of flux","%g"));
+/*    ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC FRMON MEANFLUX",
+				     qc->avg_on,"Average of flux","%g"));*/
+    ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC FRMOFF MEANFLUX",
+				     qc->avg_of,"Average of flux","%g"));
+    ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC FRMDIF MEANFLUX",
+				     qc->avg_di,"Average of flux","%g"));
+    ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC FRMON MAXFLUX",
+				     qc->max_on,"Max of flux","%g"));
+    ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC FRMOFF MAXFLUX",
+				     qc->max_of,"Max of flux","%g"));
+    ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC FRMDIF MAXFLUX",
+				     qc->max_di,"Max of flux","%g"));
+    ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC FRMON NPIXSAT",
+				  qc->nsat,
+				  "Number of saturated pixels","%d"));
+    update_bad_pixel_map(im_obj);
+    ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC FRMDIF MEANSTD",
+				     cpl_image_get_mean(im_obj),"mean of the image","%13.6f"));
+
+    ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,
+                                             "QC FRMDIF STDEV",
+                                             cpl_image_get_stdev(im_obj),
+                                             "standard deviation of the image",
+                                             "%13.6f"));
+
+    ck0(sinfo_pro_save_ima(im_obj,raw,sof,cfg->outName,
+			   frm_pro_ctg,qclog_tbl,plugin_id,config),
+	"cannot dump ima %s", cfg->outName);
+
+    sinfo_free_image(&im_obj);
+    sinfo_free_table(&qclog_tbl);
+
+    if (cfg->contains_dither == 1 && cfg->interInd == 0) {
+      if (strstr(cfg->outName, ".fits" ) != NULL ) {
+	snprintf(name_list, MAX_NAME_SIZE-1,"%s%s",
+		 sinfo_new_get_rootname(cfg->outName), "_dith.fits");
+	strcpy(cfg->outName,name_list);
+      } else {
+	strcat(cfg->outName,"_dith");
+      }
+      cpl_free(name_list);
+
+
+
+      ck0(sinfo_pro_save_ima(im_dither,raw,sof,cfg->outName,
+			     frm_pro_ctg,NULL,plugin_id,config),
+	  "cannot save ima %s", cfg->outName);
+
+      if (cfg->contains_dither == 1) {
+	sinfo_free_image(&im_dither);
+      }
+    }
+
+  }
+
+  /* the following generates a valgrind error
+     but without it 8 bytes are leaked */
+  sinfo_free_image_array(&im,cfg->nframes);
+
+  /*AMO: check if those images can be deleted before */
+  sinfo_free_image(&int_im_shifted);
+  sinfo_free_image(&int_im);
+  sinfo_free_image(&im_obj_flat);
+  sinfo_free_image(&im_obj_sub);
+
+  sinfo_stack_free(&cfg);
+  sinfo_free_frameset(&raw);
+  sinfo_qc_wcal_delete(&qc);
+
+  return 0;
+
+ cleanup:
+  sinfo_free_table(&qclog_tbl);
+  sinfo_free_table(&tbl_slitpos);
+  sinfo_free_table(&tbl_index);
+  if(slit_edges!=NULL) sinfo_new_destroy_2Dfloatarray(&slit_edges, 32);
+  sinfo_free_image(&flat1_dist);
+  sinfo_free_image(&flat1);
+  sinfo_free_image(&flat_smooth);
+  sinfo_free_image(&flat2_dist);
+  sinfo_free_image(&int_im);
+  sinfo_free_image(&int_im_dith);
+  sinfo_free_image(&int_im_shifted);
+  sinfo_free_image(&im_dither);
+  sinfo_free_image(&flat2);
+  sinfo_free_image(&im_obj_flat);
+  sinfo_free_image(&im_obj_sub);
+  sinfo_free_image(&im_obj);
+  sinfo_free_image(&mask_im);
+  sinfo_free_image(&im_sky);
+  sinfo_free_imagelist(&list_object_tmp);
+  sinfo_free_image(&sky_img_flat);
+  sinfo_free_image(&sky_dist);
+  sinfo_free_image(&sky_img);
+  sinfo_free_imagelist(&list_object);
+  sinfo_free_imagelist(&list_sky);
+  if(im != NULL) sinfo_free_image_array(&im,cfg->nframes);
+  sinfo_stack_free(&cfg);
+  sinfo_free_frameset(&raw);
+  sinfo_qc_wcal_delete(&qc);
+
+  return -1 ;
+
+}
+/**@}*/
diff --git a/sinfoni/sinfo_new_prepare_stacked_frames.h b/sinfoni/sinfo_new_prepare_stacked_frames.h
new file mode 100644
index 0000000..176c77e
--- /dev/null
+++ b/sinfoni/sinfo_new_prepare_stacked_frames.h
@@ -0,0 +1,81 @@
+#ifndef SINFO_NEW_PREPARE_STACKED_FRAMES_H
+#define SINFO_NEW_PREPARE_STACKED_FRAMES_H
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*****************************************************************************
+* E.S.O. - VLT project
+*
+* "@(#) $Id: sinfo_new_prepare_stacked_frames.h,v 1.7 2007/09/21 14:48:10 amodigli Exp $"
+*
+* who       when      what
+* --------  --------  ----------------------------------------------
+* amodigli  17/09/03  created
+*/
+
+/************************************************************************
+ * preapare_stacked_frames.h
+
+ sinfo_prepare_stacked_frames
+
+  this handles stacks of input frames, that means it takes a clean mean,
+  subtracts the off- from the on-frames, flatfields, corrects for static bad 
+  pixels, corrects for a linear tilt of the spectra if necessary, and finally, 
+  interleaves dithered exposures or convolves a single exposure with a 
+  Gaussian, respectively.
+
+ *----------------------------------------------------------------------
+ */
+
+/*
+ * header files
+ */
+#include <cpl.h>   
+#include "sinfo_globals.h"
+#include "sinfo_msg.h"
+
+
+/*----------------------------------------------------------------------------
+ *                        Function ANSI C prototypes
+ *--------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+   Function     :       sinfo_new_prepare_stacked_frames()
+   In           :       ini_file: file name of according .ini file
+   Out          :       integer (0 if it worked, -1 if it doesn't) 
+   Job          :
+
+  this handles stacks of input frames, that means it takes a clean mean,
+  subtracts the off- from the on-frames, flatfields, corrects for static bad 
+  pixels, corrects for a linear tilt of the spectra if necessary, and finally, 
+  interleaves dithered exposures or convolves a single exposure with a 
+  Gaussian, respectively.
+
+ ---------------------------------------------------------------------------*/
+int 
+sinfo_new_prepare_stacked_frames (const char* plugin_id,
+                                  cpl_parameterlist* config, 
+                                  cpl_frameset* sof, 
+                                  cpl_frameset* ref_set, 
+                                  const char* procatg,
+                                  const int frm_ind, 
+                                  fake* fk) ;
+
+#endif 
+
+/*--------------------------------------------------------------------------*/
diff --git a/sinfoni/sinfo_new_psf.c b/sinfoni/sinfo_new_psf.c
new file mode 100644
index 0000000..3e9252e
--- /dev/null
+++ b/sinfoni/sinfo_new_psf.c
@@ -0,0 +1,2592 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+
+     File name    :       sinfo_new_psf.c
+   Author       :    A. Modigliani
+   Created on   :    Sep 17, 2003
+   Description  :
+
+ sinfo_new_psf.py does the image reconstruction of a set of
+ sky-subtracted, flatfielded,
+ bad pixel corrected and slope of the spectra aligned exposures of a bright
+ star with continuum spectrum. The resulting image can be used to determine
+ the PSF
+ ---------------------------------------------------------------------------*/
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+/*----------------------------------------------------------------------------
+                                Includes
+ ---------------------------------------------------------------------------*/
+#define _GNU_SOURCE
+#include <math.h>
+
+#include <assert.h>
+#include <sinfo_cpl_size.h>
+
+#include <irplib_utils.h>
+#include <irplib_strehl.h>
+#include "sinfo_new_psf.h"
+#include "sinfo_pro_save.h"
+#include "sinfo_hidden.h"
+#include "sinfo_key_names.h"
+#include "sinfo_psf_ini.h"
+#include "sinfo_psf_ini_by_cpl.h"
+#include "sinfo_utilities_scired.h"
+#include "sinfo_hidden.h"
+#include "sinfo_pfits.h"
+#include "sinfo_functions.h"
+#include "sinfo_error.h"
+#include "sinfo_utils_wrappers.h"
+#include "sinfo_globals.h"
+//Used only for sinfo_propertylist_has
+#include "sinfo_dfs.h"
+/*----------------------------------------------------------------------------
+                                Defines
+ ---------------------------------------------------------------------------*/
+                                                   //PSO
+#define SINFO_MATH_PI   3.1415926535897932384626433832795028841971693993751058
+#define SINFO_MATH_PI_2 1.5707963267948966192313216916397514420985846996875529
+#define SINFO_MATH_PI_4 0.7853981633974483096156608458198757210492923498437765
+
+
+
+#define SINFO_STREHL_M1                       8.0  //7.9
+#define SINFO_STREHL_M2                       1.1  //1.33
+#define SINFO_STREHL_BOX_SIZE                 64
+#define SINFO_STREHL_WINDOW                   6
+#define SINFO_PSF_SZ                          4
+#define SINFO_RSTAR                           32//25
+#define SINFO_BKG_R1                          32//25
+#define SINFO_BKG_R2                          33//27
+#define SINFO_STREHL_ERROR_COEFFICIENT    SINFO_MATH_PI * 0.007 / 0.0271
+#ifndef SINFO_STREHL_RAD_CENTRAL
+#define SINFO_STREHL_RAD_CENTRAL 5
+#endif
+
+//constants for perfect PSF generation
+// Dimension of the support for generating the perfect PFS
+#define SINFO_PSF_DIM   1024//256
+#define SINFO_PSF_BLOCKS   63//11
+
+#define SINFO_PSF_BIN    16 // Pixels over "pixel_size"
+#define SINFO_PSF_NPOINT 10000// number of encircled energy sampling points
+#define SINFO_BKG_BOX_SZ 8
+/*----------------------------------------------------------------------------
+                             Function Definitions
+ ---------------------------------------------------------------------------*/
+static cpl_error_code
+sinfo_add_com_psf_qclog(const char* fname,cpl_table** qclog_tbl);
+
+
+static cpl_error_code
+sinfo_get_star_features(const cpl_image* im,
+                        const int radius,
+			const int xpos,
+			const int ypos,
+                        double* xc,
+                        double* yc,
+                        double* pick,
+                        double* flux,
+                        double* bkg);
+
+static double
+sinfo_find_min_of_four(const double n1,
+                       const double n2,
+                       const double n3,
+                       const double n4);
+
+static cpl_table*
+sinfo_get_strehl_from_2images(cpl_image* ima1,
+                             cpl_image* ima2,
+                             cpl_frame* frm1,
+			      cpl_frame* frm2);
+
+
+static int
+sinfo_get_strehl_input1(cpl_frame* frm1,
+		        double* dispersion,
+		        double* centralWave,
+		        double* ws,
+		        double* we,
+		        double* pscale,
+		        double* exptime,
+			double* strehl_star_rad,
+		        double* strehl_bg_rmin,
+		        double* strehl_bg_rmax);
+
+static int
+sinfo_get_strehl_input2(cpl_frame* frm1,cpl_frame* frm2,
+		       double* dispersion,
+		       double* centralWave,
+		       double* ws,
+		       double* we,
+		       double* pscale1,
+		       double* pscale2,
+		       double* exptime1,
+		       double* exptime2,
+		       double* strehl_star_rad1,
+		       double* strehl_star_rad2,
+		       double* strehl_bg_rmin1,
+		       double* strehl_bg_rmin2,
+		       double* strehl_bg_rmax1,
+		       double* strehl_bg_rmax2);
+
+
+static void
+sinfo_check_borders(cpl_size* val,const int max,const int thresh);
+
+static void
+sinfo_get_safe_box(int* llx,
+                   int* lly,
+                   int* urx,
+                   int* ury,
+                   const int xpos,
+                   const int ypos,
+                   const int box,
+                   const int szx,
+                   const int szy);
+
+static int
+sinfo_get_strehl_from_slice(cpl_imagelist* cube,
+                            double disp,
+                            double cWave,
+                            double ws,
+                            double we,
+                            double pscale,
+                            double strehl_star_radius,
+                            double strehl_bg_r1,
+                            double strehl_bg_r2,
+                            double* strehl,
+                            double* strehl_err);
+
+
+static cpl_table*
+sinfo_get_encircled_energy(cpl_frameset* sof,
+                           cpl_image* img,
+                           double* fwhm_x,
+               double* fwhm_y,
+                           cpl_table** qclog);
+
+static double
+sinfo_get_strehl_from_ima(cpl_image* ima,
+                          cpl_frame* frame);
+
+static int
+sinfo_get_strehl_from_image(cpl_image* img,
+                            double ws,
+                            double we,
+                            double pscale,
+                            double strehl_star_radius,
+                            double strehl_bg_r1,
+                            double strehl_bg_r2,
+                            double* strehl,
+                double* strehl_err);
+
+
+
+static cpl_table*
+sinfo_get_strehl_from_cube(cpl_imagelist* cube,
+                           char* name,
+                           cpl_frame* frame);
+
+static int
+sinfo_get_frm12(cpl_frameset* sof,cpl_frame** frm1,cpl_frame** frm2);
+
+
+/**@{*/
+/**
+ * @addtogroup sinfo_rec_jitter PSF data reduction
+ *
+ * TBD
+ */
+
+
+/*----------------------------------------------------------------------------
+   Function     :       sinfo_new_psf()
+   In           :       ini_file: file name of according .ini file
+   Out          :       integer (0 if it worked, -1 if it doesn't)
+   Job          :
+
+ sinfo_new_psf.py does the image reconstruction of a set of sky-subtracted,
+ flatfielded,
+ bad pixel corrected and slope of the spectra aligned exposures of a bright
+ star with continuum spectrum. The resulting image can be used to determine
+ the PSF
+
+ ---------------------------------------------------------------------------*/
+
+int
+sinfo_new_psf (const char* plugin_id,
+               cpl_parameterlist* config,
+               cpl_frameset* sof, cpl_frameset* ref_set)
+{
+
+  cpl_imagelist* cube1=NULL;
+  cpl_imagelist* cube2=NULL;
+  cpl_image * med_img1=NULL ;
+  cpl_image * med_img2=NULL ;
+
+  cpl_table* ao_performance=NULL;
+  cpl_table* enc_energy=NULL;
+
+  cpl_frame* frm1=NULL;
+  cpl_frame* frm2=NULL;
+
+  cpl_table* qclog_tbl=NULL;
+  cpl_frameset* stk=NULL;
+  cpl_propertylist* plist =NULL;
+
+  psf_config * cfg =NULL;
+
+  int nsample=0;
+  int i = 0;
+  int status=0;
+
+
+
+  int strehl_sw=0;
+  int ilx1=0;
+  int ily1=0;
+  int ilx2=0;
+  int ily2=0;
+
+  float cx1=0;
+  float cy1=0;
+  float cx2=0;
+  float cy2=0;
+
+  double fwhm_x=0;
+  double fwhm_y=0;
+  double lam=0;
+  double strehl=0;
+  double strehl1=0;
+  double strehl2=0;
+
+  char fname1[MAX_NAME_SIZE];
+  char fname2[MAX_NAME_SIZE];
+
+  char key_name[MAX_NAME_SIZE];
+
+  char obs_name1[MAX_NAME_SIZE];
+  char hlamp_st='F';
+  char shut2_st='F';
+  cpl_table* tmp_tbl=NULL;
+
+
+  /*
+       -----------------------------------------------------------------
+       1) parse the file names and parameters to the psf_config data
+          structure cfg
+       -----------------------------------------------------------------
+  */
+
+  sinfo_msg("Parsing cpl input");
+  check_nomsg(stk=cpl_frameset_new());
+
+  cknull(cfg = sinfo_parse_cpl_input_psf(sof,&stk),
+      "error parsing cpl input");
+
+  /* TODO the following generate a small leak of 72 bytes */
+  strehl_sw=sinfo_get_strehl_type(sof);
+  if(strehl_sw==0) {
+    sinfo_msg("One target Strehl computation");
+    if(sinfo_is_fits_file(cfg->inFrame) != 1) {
+      sinfo_msg_error("Input file %s is not FITS",cfg->inFrame);
+      goto cleanup;
+    } else {
+      strcpy(fname1,cfg->inFrame);
+    }
+
+     if(NULL != cpl_frameset_find(sof,PRO_COADD_PSF)) {
+      frm1 = cpl_frameset_find(sof,PRO_COADD_PSF);
+    } else if(NULL != cpl_frameset_find(sof,PRO_OBS_PSF)) {
+      frm1 = cpl_frameset_find(sof,PRO_OBS_PSF);
+    } else if(NULL != cpl_frameset_find(sof,PRO_COADD_STD)) {
+      frm1 = cpl_frameset_find(sof,PRO_COADD_STD);
+    } else if(NULL != cpl_frameset_find(sof,PRO_OBS_STD)) {
+      frm1 = cpl_frameset_find(sof,PRO_OBS_STD);
+    } else if(NULL != cpl_frameset_find(sof,PRO_COADD_OBJ)) {
+      frm1 = cpl_frameset_find(sof,PRO_COADD_OBJ);
+    } else if(NULL != cpl_frameset_find(sof,PRO_OBS_OBJ)) {
+      frm1 = cpl_frameset_find(sof,PRO_OBS_OBJ);
+    } else {
+      sinfo_msg_error("Frame %s  or %s or %s  or %s or %s  or %s not found!",
+              PRO_COADD_PSF,PRO_OBS_PSF,
+              PRO_COADD_STD,PRO_OBS_STD,
+              PRO_COADD_OBJ,PRO_OBS_OBJ);
+      goto cleanup;
+    }
+
+    sinfo_get_obsname(frm1,obs_name1);
+    check_nomsg(hlamp_st=sinfo_get_keyvalue_bool(frm1,KEY_NAME_LAMP_HALO));
+    check_nomsg(shut2_st=sinfo_get_keyvalue_bool(frm1,KEY_NAME_SHUT2_ST));
+
+
+    check_nomsg(cube1 = cpl_imagelist_load(fname1,CPL_TYPE_FLOAT,0));
+    cknull(med_img1=sinfo_new_median_cube(cube1),
+      " could not do sinfo_medianCube()");
+
+    check_nomsg(ilx1=cpl_image_get_size_x(med_img1));
+    check_nomsg(ily1=cpl_image_get_size_y(med_img1));
+
+    cx1 = ilx1 / 2. + 0.5;
+    cy1 = ily1 / 2. + 0.5;
+
+    cknull(ao_performance=sinfo_get_strehl_from_cube(cube1,fname1,frm1),
+       "error computing strehl");
+    strehl=sinfo_get_strehl_from_ima(med_img1,frm1);
+    sinfo_free_imagelist(&cube1);
+  } else {
+    sinfo_msg("Two target Strehl computation");
+    sinfo_get_frm12(sof,&frm1,&frm2);
+    strcpy(fname1,cpl_frame_get_filename(frm1));
+    strcpy(fname2,cpl_frame_get_filename(frm2));
+
+    check_nomsg(cube1 = cpl_imagelist_load(fname1,CPL_TYPE_FLOAT,0));
+    check_nomsg(cube2 = cpl_imagelist_load(fname2,CPL_TYPE_FLOAT,0));
+    cknull(med_img1=sinfo_new_median_cube(cube1),"Computing median on cube");
+    cknull(med_img2=sinfo_new_median_cube(cube2),"Computing median on cube");
+    check_nomsg(cpl_image_save(med_img1,"med_img1.fits",CPL_BPP_IEEE_FLOAT,
+			       NULL,CPL_IO_DEFAULT));
+    check_nomsg(cpl_image_save(med_img2,"med_img2.fits",CPL_BPP_IEEE_FLOAT,
+			       NULL,CPL_IO_DEFAULT));
+
+
+    check_nomsg(ilx1=cpl_image_get_size_x(med_img1));
+    check_nomsg(ily1=cpl_image_get_size_y(med_img1));
+    check_nomsg(ilx2=cpl_image_get_size_x(med_img2));
+    check_nomsg(ily2=cpl_image_get_size_y(med_img2));
+
+    cx1 = ilx1 / 2. + 0.5;
+    cy1 = ily1 / 2. + 0.5;
+    cx2 = ilx2 / 2. + 0.5;
+    cy2 = ily2 / 2. + 0.5;
+
+
+    sinfo_free_imagelist(&cube1);
+    sinfo_free_imagelist(&cube2);
+
+    cknull(tmp_tbl=sinfo_get_strehl_from_2images(med_img1,med_img2,frm1,frm2),
+	   "Computing strehl");
+    check_nomsg(strehl=cpl_table_get_double(tmp_tbl,"strehl",0,&status));
+    sinfo_free_table(&tmp_tbl);
+    strehl1=sinfo_get_strehl_from_ima(med_img1,frm1);
+    sinfo_msg_debug("Strehl on 1st image=%f",strehl);
+    strehl2=sinfo_get_strehl_from_ima(med_img2,frm2);
+    sinfo_msg_debug("Strehl on 2nd image=%f",strehl);
+
+    cknull_nomsg(qclog_tbl = sinfo_qclog_init());
+    check_nomsg(sinfo_add_com_psf_qclog(fname1,&qclog_tbl));
+    if(irplib_isnan(strehl1)) strehl1=-100.;
+    ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC STREHL025",strehl1,
+            "STREHL 25 mas","%f"));
+    ck0(sinfo_pro_save_ima(med_img1,ref_set,sof,PSF_MED_CUB_025_FILENAME,
+			   PRO_MED_COADD_PSF,qclog_tbl,plugin_id,config),
+	"cannot save ima %s", PSF_MED_CUB_100_FILENAME);
+    sinfo_free_table(&qclog_tbl);
+
+
+    cknull_nomsg(qclog_tbl = sinfo_qclog_init());
+    check_nomsg(sinfo_add_com_psf_qclog(fname2,&qclog_tbl));
+    if(irplib_isnan(strehl2)) strehl2=-100.;
+    ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC STREHL100",strehl2,
+            "STREHL 100 mas","%f"));
+
+    if(irplib_isnan(strehl)) strehl=-100.;
+
+    ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC STREHL",strehl,
+            "STREHL from both pixel scale images","%f"));
+    ck0(sinfo_pro_save_ima(med_img2,ref_set,sof,PSF_MED_CUB_100_FILENAME,
+			   PRO_MED_COADD_PSF,qclog_tbl,plugin_id,config),
+	"cannot save ima %s", PSF_MED_CUB_100_FILENAME);
+
+    sinfo_free_table(&qclog_tbl);
+    sinfo_free_image(&med_img2);
+
+  }
+  /* STREHL computation */
+
+  check_nomsg(nsample=cpl_table_get_nrow(ao_performance));
+  cknull_nomsg(qclog_tbl = sinfo_qclog_init());
+  check_nomsg(sinfo_add_com_psf_qclog(fname1,&qclog_tbl));
+
+  if(strehl_sw==0) {
+    if(irplib_isnan(strehl)) strehl=-100.;
+
+  ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC STREHL",strehl,
+            "STREHL from image","%f"));
+
+  }
+
+  check_nomsg(strehl=cpl_table_get_column_median(ao_performance,"strehl"));
+
+  ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC STREHL MED",strehl,
+            "STREHL MEDIAN","%f"));
+
+  check_nomsg(strehl=cpl_table_get_column_mean(ao_performance,"strehl"));
+
+  ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC STREHL AVG",strehl,
+            "STREHL AVERAGE","%f"));
+  /*
+  strehl=sinfo_get_strehl_from_ima(med_img1,frm1);
+
+  ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC STREHL AVG",strehl,
+            "STREHL AVERAGE","%f"));
+  */
+  for(i=1;i<nsample;i++) {
+
+    check_nomsg(strehl=cpl_table_get_double(ao_performance,"strehl",
+                                            i,&status));
+    if(irplib_isnan(strehl)) strehl=-100.;
+
+    snprintf(key_name,MAX_NAME_SIZE-1,"%s%d","QC STREHL",i);
+    ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,key_name,strehl,"STREHL","%f"));
+
+    check_nomsg(lam=cpl_table_get_double(ao_performance,"wavelength",
+                                         i,&status));
+    snprintf(key_name,MAX_NAME_SIZE-1,"%s%d","QC LAMBDA",i);
+    ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,key_name,lam,
+                                     "WAVELENGTH","%f"));
+
+  }
+
+  check_nomsg(strehl=cpl_table_get_column_median(ao_performance,
+                                                 "strehl_error"));
+  ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC STREHL MEDERR",strehl,
+                                   "STREHL ERROR MEDIAN","%f"));
+  ck0_nomsg(sinfo_qclog_add_string(qclog_tbl,"OBS NAME",obs_name1,
+                                   "OB name","%s"));
+  ck0_nomsg(sinfo_qclog_add_bool(qclog_tbl,PAF_NAME_LAMP_HALO,hlamp_st,
+                                  KEY_NAME_LAMP_HALO,"%d"));
+  ck0_nomsg(sinfo_qclog_add_bool(qclog_tbl,PAF_NAME_SHUT2_ST,shut2_st,
+                                  KEY_NAME_SHUT2_ST,"%d"));
+
+  ck0(sinfo_pro_save_tbl(ao_performance,ref_set,sof,
+                  PSF_AO_PERFORMANCE_OUT_FILENAME,
+             PRO_AO_PERFORMANCE,qclog_tbl,plugin_id,config),
+    "cannot save tbl %s", PSF_AO_PERFORMANCE_OUT_FILENAME);
+
+  sinfo_free_table(&qclog_tbl);
+  sinfo_free_table(&ao_performance);
+
+  /* Encircled energy & FWHM computation */
+  cknull_nomsg(qclog_tbl=sinfo_qclog_init());
+  cknull(enc_energy=sinfo_get_encircled_energy(sof,
+                           med_img1,
+                           &fwhm_x,
+                           &fwhm_y,
+                           &qclog_tbl),
+           "Computing encircled energy");
+
+  ck0(sinfo_pro_save_tbl(enc_energy,ref_set,sof,PSF_ENC_ENERGY_OUT_FILENAME,
+             PRO_ENC_ENERGY,qclog_tbl,plugin_id,config),
+      "cannot save tbl %s", PSF_ENC_ENERGY_OUT_FILENAME);
+
+  sinfo_free_table(&qclog_tbl);
+  sinfo_free_table(&enc_energy);
+
+  /* QC log */
+  cknull_nomsg(qclog_tbl = sinfo_qclog_init());
+  ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC FWHMX",fwhm_x,
+                                   "QC FWHM X","%f"));
+  ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC FWHMY",fwhm_y,
+                                   "QC FWHM Y","%f"));
+  ck0_nomsg(sinfo_qclog_add_bool(qclog_tbl,PAF_NAME_LAMP_HALO,
+                                 hlamp_st,KEY_NAME_LAMP_HALO,"%d"));
+  ck0_nomsg(sinfo_qclog_add_bool(qclog_tbl,PAF_NAME_SHUT2_ST,shut2_st,
+                                 KEY_NAME_SHUT2_ST,"%d"));
+
+  ck0(sinfo_pro_save_ima(med_img1,ref_set,sof,cfg->outName,PRO_PSF,
+             qclog_tbl,plugin_id,config),
+      "cannot save ima %s", cfg->outName);
+
+  sinfo_free_table(&qclog_tbl);
+  sinfo_new_set_wcs_image(med_img1,cfg->outName,cx1, cy1);
+  sinfo_free_image(&med_img1);
+  sinfo_free_frameset(&stk);
+  sinfo_free_psf(&cfg);
+  return 0;
+
+ cleanup:
+
+  sinfo_free_table(&qclog_tbl);
+  sinfo_free_imagelist(&cube2);
+  sinfo_free_imagelist(&cube1);
+  sinfo_free_table(&enc_energy);
+  sinfo_free_image(&med_img1);
+  sinfo_free_table(&ao_performance);
+  sinfo_free_propertylist(&plist) ;
+  sinfo_free_psf(&cfg);
+  sinfo_free_frameset(&stk);
+
+  return -1 ;
+
+}
+
+
+
+
+static cpl_error_code
+sinfo_add_com_psf_qclog(const char* fname,cpl_table** qclog_tbl)
+{
+
+  cpl_propertylist* plist=NULL;
+
+  /* QC log */
+  cknull(plist = cpl_propertylist_load(fname, 0),
+     "getting header from reference ima frame %s",fname);
+
+  if (sinfo_propertylist_has(plist, KEY_NAME_LOOP_STATE)) {
+    sinfo_qclog_add_string(*qclog_tbl,KEY_NAME_LOOP_STATE,
+                      cpl_propertylist_get_string(plist,KEY_NAME_LOOP_STATE),
+                      KEY_HELP_LOOP_STATE,"%s");
+  }
+
+
+
+  if (sinfo_propertylist_has(plist, KEY_NAME_LOOP_LGS)) {
+    sinfo_qclog_add_int(*qclog_tbl,KEY_NAME_LOOP_LGS,
+                      cpl_propertylist_get_int(plist,KEY_NAME_LOOP_LGS),
+                      KEY_HELP_LOOP_LGS,"%d");
+  }
+
+
+  if (sinfo_propertylist_has(plist, KEY_NAME_INS1_MODE)) {
+    sinfo_qclog_add_string(*qclog_tbl,KEY_NAME_INS1_MODE,
+                      cpl_propertylist_get_string(plist,KEY_NAME_INS1_MODE),
+                      KEY_HELP_INS1_MODE,"%s");
+  }
+
+
+ cleanup:
+  sinfo_free_propertylist(&plist);
+
+  if (cpl_error_get_code() != CPL_ERROR_NONE) {
+    return cpl_error_get_code();
+  } else {
+    return CPL_ERROR_NONE;
+  }
+
+
+}
+
+static int
+sinfo_get_strehl_from_image(cpl_image* img,
+                            double ws,
+                            double we,
+                            double pscale,
+                            double strehl_star_radius,
+                            double strehl_bg_r1,
+                            double strehl_bg_r2,
+                            double* strehl,
+                            double* strehl_err)
+{
+  cpl_errorstate clean_state = cpl_errorstate_get();
+
+  cpl_image* img_dup=NULL;
+
+  double dlam=0.;
+  double lam=0.;
+
+  double max_ima_cx=0.;
+  double max_ima_cy=0.;
+
+  double psf_peak=0.;
+  double psf_flux=0.;
+  double bkg_noise=0.;
+  double star_bkg=0.;
+  double star_peak=0.;
+  double star_flux=0.;
+
+  cpl_size max_ima_x=0;
+  cpl_size max_ima_y=0;
+  int wllx=0;
+  int wlly=0;
+  int wurx=0;
+  int wury=0;
+  int ima_szx=0;
+  int ima_szy=0;
+
+
+  lam = (double)0.5*(ws+we);
+  dlam=we-ws;
+  sinfo_msg_debug("ws=%f we=%f dl=%f",ws,we,dlam);
+  check_nomsg(img_dup=cpl_image_duplicate(img));
+  sinfo_clean_nan(&img_dup);
+  check_nomsg(cpl_image_get_maxpos(img_dup,&max_ima_x,&max_ima_y));
+  sinfo_free_image(&img_dup);
+
+  check_nomsg(ima_szx=cpl_image_get_size_x(img));
+  check_nomsg(ima_szy=cpl_image_get_size_y(img));
+  sinfo_check_borders(&max_ima_x,ima_szx,SINFO_STREHL_WINDOW);
+  sinfo_check_borders(&max_ima_y,ima_szy,SINFO_STREHL_WINDOW);
+  sinfo_get_safe_box(&wllx,&wlly,&wurx,&wury,max_ima_x,max_ima_y,SINFO_PSF_SZ,
+  ima_szx,ima_szy);
+
+  //cpl_image_get_maxpos_window(img,wllx,wlly,wurx,wury,&max_ima_x,&max_ima_y);
+
+  check_nomsg(max_ima_cx=cpl_image_get_centroid_x_window(img,wllx,wlly,
+                                                         wurx,wury));
+  check_nomsg(max_ima_cy=cpl_image_get_centroid_y_window(img,wllx,wlly,
+  wurx,wury));
+
+
+  if(CPL_ERROR_NONE != sinfo_strehl_compute_one(img,
+						SINFO_STREHL_M1,
+						SINFO_STREHL_M2,
+						lam,
+						dlam,
+						pscale,
+						max_ima_x,
+						max_ima_y,
+						strehl_star_radius,
+						strehl_bg_r1,
+						strehl_bg_r2,
+						SINFO_STREHL_BOX_SIZE,
+						strehl,
+						strehl_err,
+						&star_bkg,
+						&star_peak,
+						&star_flux,
+						&psf_peak,
+						&psf_flux,
+						&bkg_noise)) {
+
+
+    *strehl=-1;
+    *strehl_err=0;
+    irplib_error_recover(clean_state,"Problem computing strehl");
+
+  }
+
+  return 0;
+
+ cleanup:
+
+  return -1;
+
+}
+
+
+
+
+
+
+static int
+sinfo_get_strehl_from_slice(cpl_imagelist* cube,
+                            double disp,
+                            double cWave,
+                            double ws,
+                            double we,
+                            double pscale,
+                            double strehl_star_radius,
+                            double strehl_bg_r1,
+                            double strehl_bg_r2,
+                            double* strehl,
+                            double* strehl_err)
+{
+
+
+  cpl_errorstate clean_state = cpl_errorstate_get();
+
+
+  cpl_image* img_dup=NULL;
+  cpl_image* img=NULL;
+
+  double dlam=0.;
+  double lam=0.;
+
+  double max_ima_cx=0.;
+  double max_ima_cy=0.;
+  double psf_peak=0.;
+  double psf_flux=0.;
+  double bkg_noise=0.;
+  double star_bkg=0.;
+  double star_peak=0.;
+  double star_flux=0.;
+
+  cpl_size max_ima_x=0;
+  cpl_size max_ima_y=0;
+  int wllx=0;
+  int wlly=0;
+  int wurx=0;
+  int wury=0;
+  int ima_szx=0;
+  int ima_szy=0;
+
+
+  lam = (double)0.5*(ws+we);
+  dlam=we-ws;
+
+
+  img=sinfo_new_average_cube_to_image_between_waves(cube,disp,cWave,ws,we);
+  check_nomsg(img_dup=cpl_image_duplicate(img));
+  sinfo_clean_nan(&img_dup);
+  check_nomsg(cpl_image_get_maxpos(img_dup,&max_ima_x,&max_ima_y));
+  check_nomsg(cpl_image_delete(img_dup));
+
+
+  check_nomsg(ima_szx=cpl_image_get_size_x(img));
+  check_nomsg(ima_szy=cpl_image_get_size_y(img));
+  sinfo_check_borders(&max_ima_x,ima_szx,SINFO_STREHL_WINDOW);
+  sinfo_check_borders(&max_ima_y,ima_szy,SINFO_STREHL_WINDOW);
+
+
+  sinfo_get_safe_box(&wllx,&wlly,&wurx,&wury,max_ima_x,max_ima_y,SINFO_PSF_SZ,
+                               ima_szx,ima_szy);
+
+  /*
+  cpl_image_get_maxpos_window(img,wllx,wlly,wurx,wury,&max_ima_x,&max_ima_y);
+   */
+  check_nomsg(max_ima_cx=cpl_image_get_centroid_x_window(img,wllx,wlly,
+                                                         wurx,wury));
+
+
+
+  check_nomsg(max_ima_cy=cpl_image_get_centroid_y_window(img,wllx,wlly,
+                                                         wurx,wury));
+
+
+
+  if(CPL_ERROR_NONE != irplib_strehl_mark_bad_and_compute(img,
+                                             SINFO_STREHL_M1,
+                                             SINFO_STREHL_M2,
+                                             lam,
+                                             dlam,
+                                             pscale,
+                                             SINFO_STREHL_BOX_SIZE,
+                                             max_ima_x,
+                                             max_ima_y,
+                                             strehl_star_radius,
+                                             strehl_bg_r1,
+                                             strehl_bg_r2,
+                                             NOISE_HSIZE,
+                                             NOISE_NSAMPLES,
+                                             strehl,
+                                             strehl_err,
+                                             &star_bkg,
+                                             &star_peak,
+                                             &star_flux,
+                                             &psf_peak,
+                                             &psf_flux,
+                                             &bkg_noise)) {
+
+
+     *strehl=-1;
+     *strehl_err=0;
+      irplib_error_recover(clean_state,"Problem computing strehl");
+
+  }
+
+  /*
+  cpl_msg_info(__func__,"stehl=%f err=%f star_bkg=%f star_peak=%f star_flux=%f",
+                          *strehl,*strehl_err,star_bkg,star_peak,star_flux);
+  cpl_msg_info(__func__,"psf_peak=%f psf_flux=%f bkg_noise=%f",
+                         psf_peak,psf_flux,bkg_noise);
+  */
+  sinfo_free_image(&img);
+
+
+  return 0;
+
+ cleanup:
+  return -1;
+
+}
+
+
+
+cpl_table* sinfo_get_encircled_energy(cpl_frameset* sof,
+                                      cpl_image* img,
+                                      double* fwhm_x,
+                                      double* fwhm_y,
+                                      cpl_table** qclog_tbl)
+{
+
+  cpl_errorstate clean_state = cpl_errorstate_get();
+
+  cpl_image* img_dup=NULL;
+  cpl_size max_ima_x=0;
+  cpl_size max_ima_y=0;
+  int wllx=0;
+  int wlly=0;
+  int wurx=0;
+  int wury=0;
+  const double d_mirror = 8.;
+  const double factor = 180/PI_NUMB*3600.;
+  double max_ima_cx=0;
+  double max_ima_cy=0;
+
+  double norm=0.;
+  double xc=0.;
+  double yc=0.;
+  double sx=0.;
+  double sy=0.;
+
+  double flux=0;
+  double flux_max=0;
+  double pix_scale=0;
+  double lam=0.;
+  double pscale=0.;
+  int dr_difr=0;
+
+  double r=0.;
+  double bkg=0.;
+  int i=0;
+  int ni=0;
+  int ir_difr=0;
+  int dr=0;
+  int rmin=0;
+
+  char band[MAX_NAME_SIZE];
+  char spat_res[MAX_NAME_SIZE];
+
+  cpl_table* enc_energy=NULL;
+  cpl_frame* frame=NULL;
+
+  int ima_szx=0;
+  int ima_szy=0;
+
+
+
+  if(NULL != cpl_frameset_find(sof,PRO_COADD_PSF)) {
+    frame = cpl_frameset_find(sof,PRO_COADD_PSF);
+  } else if(NULL != cpl_frameset_find(sof,PRO_OBS_PSF)) {
+    frame = cpl_frameset_find(sof,PRO_OBS_PSF);
+  } else if(NULL != cpl_frameset_find(sof,PRO_COADD_STD)) {
+    frame = cpl_frameset_find(sof,PRO_COADD_STD);
+  } else if(NULL != cpl_frameset_find(sof,PRO_OBS_STD)) {
+    frame = cpl_frameset_find(sof,PRO_OBS_STD);
+  } else if(NULL != cpl_frameset_find(sof,PRO_COADD_OBJ)) {
+    frame = cpl_frameset_find(sof,PRO_COADD_OBJ);
+  } else if(NULL != cpl_frameset_find(sof,PRO_OBS_OBJ)) {
+    frame = cpl_frameset_find(sof,PRO_OBS_OBJ);
+  } else {
+    sinfo_msg_error("Frame %s  or %s or  %s  or %s or %s  or %s not found!",
+            PRO_COADD_PSF,PRO_OBS_PSF,
+            PRO_COADD_STD, PRO_OBS_STD,
+            PRO_COADD_OBJ, PRO_OBS_OBJ);
+    return NULL;
+  }
+
+  sinfo_get_spatial_res(frame,spat_res);
+  sinfo_get_band(frame,band);
+  pix_scale=atof(spat_res);
+  lam=sinfo_get_wave_cent(band);
+  /* factor 2 due to change of detector to 2K */
+  pscale=0.5*pix_scale;
+
+
+
+  dr_difr=factor*1.22*lam*1.e-6/d_mirror/pscale;
+  ir_difr=floor(dr_difr+0.5);
+  if (pix_scale==0.025) {
+    ni=10;
+    rmin=ir_difr;
+    dr=rmin;
+  } else {
+    ni=15;
+    sinfo_msg_warning("Reset diffraction limit");
+    ir_difr=10;
+    rmin=1;
+    dr=2;
+  }
+
+  sinfo_msg("Diffraction limit: %d",ir_difr);
+
+  check_nomsg(img_dup=cpl_image_duplicate(img));
+  sinfo_clean_nan(&img_dup);
+  check_nomsg(cpl_image_get_maxpos(img_dup,&max_ima_x,&max_ima_y));
+  sinfo_free_image(&img_dup);
+
+
+
+  check_nomsg(ima_szx=cpl_image_get_size_x(img));
+  check_nomsg(ima_szy=cpl_image_get_size_y(img));
+  sinfo_check_borders(&max_ima_x,ima_szx,SINFO_STREHL_WINDOW);
+  sinfo_check_borders(&max_ima_y,ima_szy,SINFO_STREHL_WINDOW);
+  sinfo_get_safe_box(&wllx,&wlly,&wurx,&wury,max_ima_x,max_ima_y,SINFO_PSF_SZ,
+                               ima_szx,ima_szy);
+
+  check_nomsg(max_ima_cx=cpl_image_get_centroid_x_window(img,wllx,wlly,
+                                                         wurx,wury));
+  check_nomsg(max_ima_cy=cpl_image_get_centroid_y_window(img,wllx,wlly,
+                                                         wurx,wury));
+
+
+  cpl_image_save(img, "bad_image_psf_c.fits",CPL_BPP_IEEE_DOUBLE, NULL, CPL_IO_CREATE);
+  sinfo_msg("@@@@ sinfo_get_encircled_energy() max_ima_x[%" CPL_SIZE_FORMAT "] max_ima_y[%" CPL_SIZE_FORMAT "] psf_sz[%d]", max_ima_x,
+          max_ima_y,
+          SINFO_PSF_SZ);
+  if(CPL_ERROR_NONE != cpl_image_fit_gaussian(img,max_ima_x,max_ima_y,
+                                              SINFO_PSF_SZ,
+                                              &norm,&xc,&yc,&sx,&sy,
+                                              fwhm_x,fwhm_y)) {
+
+
+      irplib_error_recover(clean_state,"Gaussian fit failed");
+
+  }
+
+ check_nomsg(enc_energy = cpl_table_new(ni));
+ check_nomsg(cpl_table_new_column(enc_energy,"r_pix", CPL_TYPE_INT));
+ check_nomsg(cpl_table_new_column(enc_energy,"r_mas", CPL_TYPE_DOUBLE));
+ check_nomsg(cpl_table_new_column(enc_energy,"r_dif", CPL_TYPE_DOUBLE));
+ check_nomsg(cpl_table_new_column(enc_energy,"abs_energy" , CPL_TYPE_DOUBLE));
+ check_nomsg(cpl_table_new_column(enc_energy,"rel_energy" , CPL_TYPE_DOUBLE));
+ /* encircled energy computation */
+ check_nomsg(bkg=irplib_strehl_ring_background(img,max_ima_x,max_ima_y,
+                    SINFO_BKG_R1,SINFO_BKG_R2,IRPLIB_BG_METHOD_AVER_REJ)) ;
+ r=rmin+(ni-1)*dr;
+ check_nomsg(flux_max=irplib_strehl_disk_flux(img,max_ima_x,max_ima_y,r,bkg));
+ r=rmin;
+
+ for(i=0; i<ni; i++)
+   {
+     check_nomsg(flux=irplib_strehl_disk_flux(img,max_ima_x,max_ima_y,r,bkg));
+     check_nomsg(cpl_table_set_int(enc_energy,"r_pix",i,r));
+     check_nomsg(cpl_table_set_double(enc_energy,"r_mas",i,r*pscale));
+     check_nomsg(cpl_table_set_double(enc_energy,"r_dif",i,r/ir_difr));
+     check_nomsg(cpl_table_set_double(enc_energy,"abs_energy",i,flux));
+     check_nomsg(cpl_table_set_double(enc_energy,"rel_energy",i,flux/flux_max));
+     r+=dr;
+
+   }
+
+ //sinfo_msg("max ima=%d %d\n",max_ima_x,max_ima_y);
+ //sinfo_msg("centroid ima=%f %f\n",max_ima_cx,max_ima_cy);
+ //sinfo_msg("gauss info=%f %f %f %f %f %f %f\n",
+ //                         norm,xc,yc,sx,sy,*fwhm_x,*fwhm_y);
+
+ check_nomsg(flux=irplib_strehl_disk_flux(img,max_ima_x,max_ima_y,
+                                          ir_difr,bkg));
+ ck0_nomsg(sinfo_qclog_add_double(*qclog_tbl,"QC ENC CORE",
+                                  flux/flux_max,
+                                  "Encircled energy within PSF core","%f"));
+
+ return enc_energy;
+
+ cleanup:
+  sinfo_free_image(&img_dup);
+
+  return NULL;
+}
+
+
+static cpl_table* sinfo_get_strehl_from_cube(cpl_imagelist* cube,
+                                            char* name,
+                                            cpl_frame* frame)
+{
+  cpl_table* strehl_tbl=NULL;
+
+  double dispersion=0.;
+  double centralWave=0.;
+  double wrange=0;
+  double wstart=0;
+  double wstep=0;
+  double wend=0;
+  double ws=0;
+  double we=0;
+  double pix_scale=0;
+  double lam=0;
+  double dlam=0;
+  double pscale = 0;
+
+  double strehl_star_radius=0;
+  double strehl_bg_r1=0;
+  double strehl_bg_r2=0;
+  double strehl=0;
+  double strehl_err=0;
+  char spat_res[MAX_NAME_SIZE];
+  cpl_propertylist* plist=NULL;
+
+  int naxis3=0;
+  int nsample=0;
+  int i=0;
+
+
+  sinfo_get_spatial_res(frame,spat_res);
+  pix_scale=atof(spat_res);
+  sinfo_msg("Camera pixel scale=%f",pix_scale);
+  /* factor 2 due to change of detector to 2K */
+  pscale=0.5*pix_scale;
+
+  strehl_star_radius=SINFO_BKG_R1*pscale;
+  strehl_bg_r1=SINFO_BKG_R1*pscale;
+  strehl_bg_r2=SINFO_BKG_R2*pscale;
+
+  plist=cpl_propertylist_load(name,0);
+  dispersion=sinfo_pfits_get_cdelt3(plist);
+  centralWave=sinfo_pfits_get_crval3(plist);
+  naxis3=sinfo_pfits_get_naxis3(plist);
+  sinfo_free_propertylist(&plist);
+  wrange=dispersion*naxis3;
+
+  wstart = centralWave - (float) (cpl_imagelist_get_size(cube) / 2)*
+                                 dispersion+dispersion;
+  wend  =wstart + dispersion * cpl_imagelist_get_size(cube);
+  wstep=0.025;
+ /*
+   note:
+    -wstep as we do not hit the borders where the
+    sinfo_gaussian fit has a problem
+  */
+  nsample=(int)((wend-wstart-wstep)/wstep);
+  check_nomsg(strehl_tbl = cpl_table_new(nsample));
+  check_nomsg(cpl_table_new_column(strehl_tbl,"wavelength",CPL_TYPE_DOUBLE));
+  check_nomsg(cpl_table_new_column(strehl_tbl,"strehl",CPL_TYPE_DOUBLE));
+  check_nomsg(cpl_table_new_column(strehl_tbl,"strehl_error",CPL_TYPE_DOUBLE));
+
+
+  for(i=1;i<nsample;i++) {
+
+    ws=wstart+wstep*i;
+    we=ws+wstep;
+
+    lam = (double)0.5*(ws+we);
+    dlam=wstep;
+
+    check(sinfo_get_strehl_from_slice(cube,
+                                dispersion,
+                                centralWave,
+                                ws,
+                                we,
+                                pscale,
+                                strehl_star_radius,
+                                strehl_bg_r1,
+                                strehl_bg_r2,
+                                &strehl,
+                      &strehl_err),"Error computing strehl");
+
+
+       if((isnan(lam) ==0) &&
+          (isnan(lam) ==0) &&
+          (isnan(lam) ==0)) {
+     check_nomsg(cpl_table_set_double(strehl_tbl,"wavelength",i,lam));
+     check_nomsg(cpl_table_set_double(strehl_tbl,"strehl",i,strehl));
+     check_nomsg(cpl_table_set_double(strehl_tbl,"strehl_error",i,
+                     strehl_err));
+
+       }
+  }
+
+  return strehl_tbl;
+
+ cleanup:
+  return NULL;
+
+
+}
+
+
+static double
+sinfo_get_strehl_from_ima(cpl_image* ima,
+                                        cpl_frame* frame)
+{
+
+  double dispersion=0.;
+  double centralWave=0.;
+  double wstart=0;
+  double wend=0;
+  double pscale = 0;
+
+  double strehl_star_radius=0;
+  double strehl_bg_r1=0;
+  double strehl_bg_r2=0;
+  double strehl=0;
+  double strehl_err=0;
+  double exptime=0;
+
+
+
+  ck0_nomsg(sinfo_get_strehl_input1(frame,&dispersion,&centralWave,
+                                   &wstart,&wend,&pscale,&exptime,
+		                   &strehl_star_radius,&strehl_bg_r1,
+				    &strehl_bg_r2));
+
+
+  check(sinfo_get_strehl_from_image(ima,
+                                wstart,
+                                wend,
+                                pscale,
+                                strehl_star_radius,
+                                strehl_bg_r1,
+                                strehl_bg_r2,
+                                &strehl,
+                &strehl_err),"Computing Strehl");
+
+
+
+
+
+ cleanup:
+  return strehl;
+
+
+}
+
+static int
+sinfo_get_frm12(cpl_frameset* sof,cpl_frame** frm1,cpl_frame** frm2){
+
+  cpl_frameset* obs=NULL;
+  int nobs=0;
+  float eps=0.0001;
+  float* pix_scale=NULL;
+  int i=0;
+  cpl_frame* frame=NULL;
+
+  obs = cpl_frameset_new();
+  sinfo_contains_frames_kind(sof,obs,PRO_OBS_PSF);
+  nobs=cpl_frameset_get_size(obs);
+  if (nobs < 1) {
+     sinfo_contains_frames_kind(sof,obs,PRO_OBS_STD);
+     nobs=cpl_frameset_get_size(obs);
+  }
+
+  nobs=cpl_frameset_get_size(obs);
+
+
+  if (nobs < 1) {
+     sinfo_contains_frames_kind(sof,obs,PRO_OBS_OBJ);
+     nobs=cpl_frameset_get_size(obs);
+  }
+
+  nobs=cpl_frameset_get_size(obs);
+
+  if (nobs < 1) {
+    return -1;
+  } else {
+    pix_scale=cpl_calloc(nobs,sizeof(float));
+    for(i=0;i<nobs;i++) {
+      frame=cpl_frameset_get_frame(obs,i);
+      pix_scale[i]=sinfo_pfits_get_pixelscale(
+                           (char*)cpl_frame_get_filename(frame));
+      if(fabs(pix_scale[i]-0.025)< eps) {
+        *frm1=cpl_frame_duplicate(frame);
+      } else if (fabs(pix_scale[i]-0.1) <eps) {
+        *frm2=cpl_frame_duplicate(frame);
+      } else {
+        sinfo_msg_error("No proper frame found for strehl computation");
+    return -1;
+      }
+    }
+  }
+  cpl_free(pix_scale);
+  cpl_frameset_delete(obs);
+
+  return 0;
+
+}
+
+
+
+
+static int
+sinfo_get_strehl_input1(cpl_frame* frm,
+		       double* dispersion,
+		       double* centralWave,
+		       double* wstart,
+		       double* wend,
+		       double* pscale,
+		       double* exptime,
+		       double* strehl_star_rad,
+		       double* strehl_bg_rmin,
+		       double* strehl_bg_rmax)
+
+{
+
+  cpl_propertylist* plist=NULL;
+  char res[MAX_NAME_SIZE];
+  double pix_scale=0;
+  double wrange=0;
+  char fname[MAX_NAME_SIZE];
+  int naxis3=0;
+
+  sinfo_get_spatial_res(frm,res);
+  pix_scale=atof(res);
+
+  /* factor 2 due to change of detector to 2K
+  *pscale=0.5*pix_scale;
+  */
+
+
+  *pscale=pix_scale;
+
+  *strehl_star_rad=SINFO_RSTAR*(*pscale);
+  *strehl_bg_rmin=SINFO_BKG_R1*(*pscale);
+  *strehl_bg_rmax=SINFO_BKG_R2*(*pscale);
+
+  strcpy(fname,cpl_frame_get_filename(frm));
+  check_nomsg(plist=cpl_propertylist_load(fname,0));
+  check_nomsg(*dispersion=sinfo_pfits_get_cdelt3(plist));
+  *centralWave=sinfo_pfits_get_crval3(plist);
+  check_nomsg(naxis3=sinfo_pfits_get_naxis3(plist));
+  *exptime=sinfo_pfits_get_exp_time(plist);
+  sinfo_free_propertylist(&plist);
+
+  wrange=(*dispersion)*naxis3;
+
+  *wstart = *centralWave - (wrange / 2) +(*dispersion);
+  *wend   = *wstart + wrange;
+
+
+ cleanup:
+  if (cpl_error_get_code() != CPL_ERROR_NONE) {
+    return -1;
+  } else {
+    return 0;
+  }
+
+}
+
+
+static int
+sinfo_get_strehl_input2(cpl_frame* frm1,
+                       cpl_frame* frm2,
+		       double* dispersion,
+		       double* centralWave,
+		       double* wstart,
+		       double* wend,
+		       double* pscale1,
+		       double* pscale2,
+		       double* exptime1,
+		       double* exptime2,
+		       double* strehl_star_rad1,
+		       double* strehl_star_rad2,
+		       double* strehl_bg_rmin1,
+		       double* strehl_bg_rmin2,
+		       double* strehl_bg_rmax1,
+		       double* strehl_bg_rmax2)
+
+{
+
+  cpl_propertylist* plist=NULL;
+  char res1[MAX_NAME_SIZE];
+  char res2[MAX_NAME_SIZE];
+  double pix_scale1=0;
+  double pix_scale2=0;
+  double wrange=0;
+  char fname1[MAX_NAME_SIZE];
+  char fname2[MAX_NAME_SIZE];
+  int naxis3=0;
+
+  sinfo_get_spatial_res(frm1,res1);
+  sinfo_get_spatial_res(frm2,res2);
+  pix_scale1=atof(res1);
+  pix_scale2=atof(res2);
+  /* factor 2 due to change of detector to 2K
+  *pscale1=0.5*pix_scale1;
+  *pscale2=0.5*pix_scale2;
+  */
+
+  *pscale1=pix_scale1;
+  *pscale2=pix_scale2;
+
+
+  *strehl_star_rad1=SINFO_RSTAR*(*pscale1);
+  *strehl_bg_rmin1=SINFO_BKG_R1*(*pscale1);
+  *strehl_bg_rmax1=SINFO_BKG_R2*(*pscale1);
+
+  *strehl_star_rad2=SINFO_RSTAR*(*pscale2);
+  *strehl_bg_rmin2=SINFO_BKG_R1*(*pscale2);
+  *strehl_bg_rmax2=SINFO_BKG_R2*(*pscale2);
+
+  strcpy(fname1,cpl_frame_get_filename(frm1));
+  check_nomsg(plist=cpl_propertylist_load(fname1,0));
+  check_nomsg(*dispersion=sinfo_pfits_get_cdelt3(plist));
+  *centralWave=sinfo_pfits_get_crval3(plist);
+  check_nomsg(naxis3=sinfo_pfits_get_naxis3(plist));
+  *exptime1=sinfo_pfits_get_exp_time(plist);
+  sinfo_free_propertylist(&plist);
+  strcpy(fname2,cpl_frame_get_filename(frm2));
+
+
+  check_nomsg(plist=cpl_propertylist_load(fname2,0));
+  *exptime2=sinfo_pfits_get_exp_time(plist);
+  sinfo_free_propertylist(&plist);
+
+
+
+  wrange=(*dispersion)*naxis3;
+
+  *wstart = *centralWave - (wrange / 2) +(*dispersion);
+  *wend   = *wstart + wrange;
+
+
+ cleanup:
+  if (cpl_error_get_code() != CPL_ERROR_NONE) {
+    return -1;
+  } else {
+    return 0;
+  }
+
+}
+
+
+
+static cpl_table*
+sinfo_get_strehl_from_2images(cpl_image* ima1,
+			      cpl_image* ima2,
+			      cpl_frame* frm1,
+			      cpl_frame* frm2)
+{
+
+  cpl_table* strehl_tbl=NULL;
+
+
+  double dispersion=0.;
+  double centralWave=0.;
+  double wstart=0;
+  double wstep=0;
+  double wend=0;
+  double lam=0;
+  double dlam=0;
+  double pscale1 = 0;
+  double pscale2 = 0;
+
+  double strehl_star_rad1=0;
+  double strehl_star_rad2=0;
+  double strehl_bg_rmin1=0;
+  double strehl_bg_rmin2=0;
+  double strehl_bg_rmax1=0;
+  double strehl_bg_rmax2=0;
+  double strehl=0;
+  double strehl_err=0;
+
+  int nsample=1;
+  double exptime1=0;
+  double exptime2=0;
+  cpl_image* img_dup=NULL;
+
+  cpl_size max_ima1_x=0;
+  cpl_size max_ima1_y=0;
+
+  cpl_size max_ima2_x=0;
+
+
+  cpl_size max_ima2_y=0;
+  double star_bkg=0;
+  double star_peak=0;
+  double star_flux=0;
+
+  double psf_peak=0;
+  double psf_flux=0;
+  double bkg_noise=0;
+
+  cpl_errorstate clean_state = cpl_errorstate_get();
+
+  ck0_nomsg(sinfo_get_strehl_input2(frm1,frm2,&dispersion, &centralWave,
+                                   &wstart,&wend,&pscale1,&pscale2,
+                                   &exptime1,&exptime2,
+                                   &strehl_star_rad1,&strehl_star_rad2,
+                                   &strehl_bg_rmin1,&strehl_bg_rmin2,
+                                   &strehl_bg_rmax1,&strehl_bg_rmax2));
+
+
+
+
+
+  check_nomsg(img_dup=cpl_image_duplicate(ima1));
+  sinfo_clean_nan(&img_dup);
+  check_nomsg(cpl_image_get_maxpos(img_dup,&max_ima1_x,&max_ima1_y));
+  sinfo_free_image(&img_dup);
+
+
+  check_nomsg(img_dup=cpl_image_duplicate(ima2));
+  sinfo_clean_nan(&img_dup);
+  check_nomsg(cpl_image_get_maxpos(img_dup,&max_ima2_x,&max_ima2_y));
+  sinfo_free_image(&img_dup);
+
+  /*
+     note:
+     -wstep as we do not hit the borders where the
+     sinfo_gaussian fit has a problem
+  */
+
+
+
+  check_nomsg(strehl_tbl = cpl_table_new(nsample));
+  check_nomsg(cpl_table_new_column(strehl_tbl,"wavelength",CPL_TYPE_DOUBLE));
+  check_nomsg(cpl_table_new_column(strehl_tbl,"strehl",CPL_TYPE_DOUBLE));
+  check_nomsg(cpl_table_new_column(strehl_tbl,"strehl_error",CPL_TYPE_DOUBLE));
+  wstep  = wend-wstart;
+
+
+
+  lam = (double)0.5*(wstart+wend);
+  dlam=wstep;
+  sinfo_msg("lambda=%f dlambda=%f",lam,dlam);
+  sinfo_msg("wstart=%f wend=%f",wstart,wend);
+  sinfo_msg("wstep=%f",wstep);
+
+
+  if(CPL_ERROR_NONE != sinfo_strehl_compute_two(ima1,ima2,
+					    SINFO_STREHL_M1,SINFO_STREHL_M2,
+					    lam,
+					    pscale1,pscale2,
+					    exptime1,exptime2,
+					    max_ima1_x,max_ima1_y,
+					    max_ima2_x,max_ima2_y,
+					    strehl_star_rad1,
+                                            strehl_bg_rmin1,
+					    strehl_bg_rmax1,
+					    &strehl,&strehl_err,&star_bkg,
+					    &star_peak,&star_flux,
+					    &psf_peak,&psf_flux,&bkg_noise))
+    {
+
+      strehl=-1;
+      strehl_err=0;
+      irplib_error_recover(clean_state,
+			   "Problem computing strehl, set it to -1");
+
+    }
+
+
+  if((isnan(lam) ==0) &&
+     (isnan(lam) ==0) &&
+     (isnan(lam) ==0)) {
+    check_nomsg(cpl_table_set_double(strehl_tbl,"wavelength",0,lam));
+    check_nomsg(cpl_table_set_double(strehl_tbl,"strehl",0,strehl));
+    check_nomsg(cpl_table_set_double(strehl_tbl,"strehl_error",
+				     0,strehl_err));
+
+  }
+
+
+
+  return strehl_tbl;
+ cleanup:
+
+
+  return NULL;
+}
+
+
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Compute the strehl ratio in an image
+  @param    im1            Image with pixel-type float (pick computation)
+  @param    im2            Image with pixel-type float (flux,bkg computation)
+  @param    m1             Diameter of the M1 mirror [m]
+  @param    m2             Diameter of the M2 mirror [m]
+  @param    lam            Central wavelength [micron]
+  @param    dlam           Filter bandwidth [micron]
+  @param    pscale1        Positive pixel scale (of image for pick comput.)
+  @param    pscale2        Positive pixel scale (of image for flux,bkg comput.)
+  @param    exptime1       Exposure time (of image for pick comput.)
+  @param    exptime2       Exposure time (of image for flux,bkg comput.)
+  @param    size           Size of image to be used for internal PSF
+  @param    xpos1          The x position of the ring center
+  @param    ypos1          The y position of the ring center
+  @param    xpos2          The x position of the ring center
+  @param    ypos2          The y position of the ring center
+  @param    r1             The Star Radius, r1 > 0
+  @param    r2             The Internal Radius, r2 > 0
+  @param    r3             The External Radius, r3 > r2
+  @param    noise_box_sz   Pass -1 for default values
+  @param    noise_nsamples Pass -1 for default values
+  @param    strehl         Pointer to the Strehl Error (positive on success)
+  @param    strehl_err     Pointer to the Strehl Error (non-negative on success)
+  @param    star_bkg        Pointer to the Star Background
+  @param    star_peak      Pointer to the Star Peak (positive on success)
+  @param    star_flux      Pointer to the Star Flux (positive on success)
+  @param    psf_peak       Pointer to the PSF Peak (positive on success)
+  @param    psf_flux       Pointer to the PSF Flux (1 on success)
+  @param    bg_noise       Pointer to the Background Noise
+  @return   0 iff ok
+  @note     The output is undefined on error. On success the Strehl Ratio may
+            exceed 1 (e.g. 1.7).
+ */
+/*---------------------------------------------------------------------------*/
+#define irplib_assure_code cpl_ensure_code
+int sinfo_strehl_compute_two(
+        const cpl_image *   im1,
+        const cpl_image *   im2,
+        double              m1,
+        double              m2,
+        double              lam,
+        double              pscale1,
+        double              pscale2,
+        double              exptime1,
+        double              exptime2,
+        int                 xpos1,
+        int                 ypos1,
+        int                 xpos2,
+        int                 ypos2,
+        double              r1,
+        double              r2,
+        double              r3,
+        double          *   strehl,
+        double          *   strehl_err,
+        double          *   star_bkg,
+        double          *   star_peak,
+        double          *   star_flux,
+        double          *   psf_peak,
+        double          *   psf_flux,
+        double          *   bg_noise)
+{
+    double psf_peak1=0;
+    double psf_peak2=0;
+    double psf_flux1=0;
+    double psf_flux2=0;
+    double star_bkg1=0;
+    double star_bkg2=0;
+    double star_flux1=0;
+    double star_flux2=0;
+    double star_peak1=0;
+    double star_peak2=0;
+
+    const double   window_size = 5.0 ;
+    double         star_radius, max_radius ;
+    double       ring[4];
+
+    double prat=pscale2/pscale1;
+    double prat2=prat*prat;
+    double trat=exptime1/exptime2;
+    double frat=sinfo_scale_flux(pscale1,pscale2,exptime1,exptime2);
+    double xc=0;
+    double yc=0;
+
+    int sx=0;
+    int sy=0;
+    int d=16;
+    cpl_errorstate initial_errorstate = cpl_errorstate_get();
+
+
+    /* Test inputs */
+    irplib_assure_code(im1 != NULL,         CPL_ERROR_NULL_INPUT);
+    irplib_assure_code(im2 != NULL,         CPL_ERROR_NULL_INPUT);
+    irplib_assure_code(strehl != NULL,     CPL_ERROR_NULL_INPUT);
+    irplib_assure_code(strehl_err != NULL, CPL_ERROR_NULL_INPUT);
+    irplib_assure_code(star_bkg != NULL,    CPL_ERROR_NULL_INPUT);
+    irplib_assure_code(star_peak != NULL,  CPL_ERROR_NULL_INPUT);
+    irplib_assure_code(star_flux != NULL,  CPL_ERROR_NULL_INPUT);
+    irplib_assure_code(psf_peak != NULL,   CPL_ERROR_NULL_INPUT);
+    irplib_assure_code(psf_flux != NULL,   CPL_ERROR_NULL_INPUT);
+
+    irplib_assure_code(pscale1 > 0.0,      CPL_ERROR_ILLEGAL_INPUT);
+    irplib_assure_code(pscale2 > 0.0,      CPL_ERROR_ILLEGAL_INPUT);
+
+    irplib_assure_code(xpos1-window_size > 0, CPL_ERROR_ACCESS_OUT_OF_RANGE);
+    irplib_assure_code(ypos1-window_size > 0, CPL_ERROR_ACCESS_OUT_OF_RANGE);
+    irplib_assure_code(xpos2-window_size > 0, CPL_ERROR_ACCESS_OUT_OF_RANGE);
+    irplib_assure_code(ypos2-window_size > 0, CPL_ERROR_ACCESS_OUT_OF_RANGE);
+
+    irplib_assure_code(xpos1+window_size <= cpl_image_get_size_x(im1),
+                       CPL_ERROR_ACCESS_OUT_OF_RANGE);
+    irplib_assure_code(ypos1+window_size <= cpl_image_get_size_y(im1),
+                       CPL_ERROR_ACCESS_OUT_OF_RANGE);
+
+    irplib_assure_code(xpos2+window_size <= cpl_image_get_size_x(im2),
+                       CPL_ERROR_ACCESS_OUT_OF_RANGE);
+    irplib_assure_code(ypos2+window_size <= cpl_image_get_size_y(im2),
+                       CPL_ERROR_ACCESS_OUT_OF_RANGE);
+
+    irplib_assure_code(r1 > 0.0,      CPL_ERROR_ILLEGAL_INPUT);
+    irplib_assure_code(r2 > 0.0,      CPL_ERROR_ILLEGAL_INPUT);
+    irplib_assure_code(r3 > r2,       CPL_ERROR_ILLEGAL_INPUT);
+
+    /* Computing a Strehl ratio is a story between an ideal PSF */
+    /* and a candidate image supposed to approximate this ideal PSF. */
+
+    /* Generate first appropriate PSF to find max peak: same pscale as
+       the one of the image where we compute the flux */
+
+
+    sx=cpl_image_get_size_x(im1);
+    sy=cpl_image_get_size_y(im1);
+
+
+    psf_flux1 = 1.0; // The psf flux, cpl_image_get_flux(psf), is always 1
+    psf_flux2 = 1.0; // The psf flux, cpl_image_get_flux(psf), is always 1
+    *psf_flux=1.0;
+    ring[0] = xpos2;
+    ring[1] = ypos2;
+    ring[2] = r2/pscale2;
+    ring[3] = r3/pscale2;
+
+    sinfo_msg_debug("star_pos=%d %d %d %d",xpos1,ypos1,xpos2,ypos2);
+    sinfo_msg_debug("star_ring=%f %f %f %f",ring[0],ring[1],ring[2],ring[3]);
+
+    /* Compute star_radius in pixels */
+    star_radius = r1/pscale2;
+
+     /* Find the peak value on the central part of the candidate image */
+
+
+    /* Find the peak value on the central part of the candidate image */
+    max_radius = window_size < star_radius ? window_size : star_radius;
+
+    check_nomsg(sinfo_get_star_features(im1,d,xpos1,ypos1,&xc,&yc,
+                                        &star_peak1,&star_flux1,&star_bkg1));
+
+
+    *star_peak=star_peak1;
+
+    check_nomsg(sinfo_compute_psf(m1,m2/m1,lam*1.e-6,pscale1,xc,yc,1.,
+				  &psf_peak1));
+
+    check_nomsg(sinfo_get_star_features(im2,d,xpos2,ypos2,&xc,&yc,
+                                        &star_peak2,&star_flux2,&star_bkg2));
+
+    *star_flux=star_flux2;
+    *star_bkg=star_bkg2;
+
+    check_nomsg(sinfo_compute_psf(m1,m2/m1,lam*1.e-6,pscale2,xc,yc,1.,
+				  &psf_peak2));
+
+
+
+
+    sinfo_msg_debug("p1=%g p2=%g",*star_peak,star_peak2);
+    sinfo_msg_debug("corr peak: p1=%g p2=%g",*star_peak,star_peak2/frat);
+    sinfo_msg_debug("corr bkg: bkg1=%g bkg2=%g",star_bkg1/frat,*star_bkg);
+    sinfo_msg_debug("rel diff: %g",
+              fabs(star_peak2/frat- *star_peak)/(star_peak2/frat));
+
+
+
+    sinfo_msg_debug("Rescaled star_flux1=%g star_flux2=%g",
+                 star_flux1*trat,*star_flux);
+
+    //Check that flux value as measured on im1 and on 1m2 are close one
+    //to another. Note that flux1, measured on im1, need to be rescaled
+    //by exposure time to match to flux2=star_flux
+    if ( fabs((star_flux1*frat-*star_flux)/(*star_flux)) > 0.25) {
+      sinfo_msg_debug("Star flux rel diff: %g",
+                        fabs((star_flux1*frat-*star_flux)/(*star_flux)));
+    }
+
+    //Check that pick value as measured on im1 and on 1m2 are close one
+    //to another. Note that peak2, measured on im2, need to be rescaled
+    //by exposure time and pixel scale to match to peak1=star_peak
+    if ( fabs(star_peak2-star_peak1*frat)/(star_peak2) > 0.25) {
+      sinfo_msg_debug("Star pick rel diff: %g",
+                        fabs(star_peak2-star_peak1*frat)/(star_peak2));
+    }
+    sinfo_msg_debug("ak1 star peak=%g",*star_peak);
+    irplib_assure_code(*star_peak > 0.0,      CPL_ERROR_ILLEGAL_OUTPUT);
+    *star_peak=star_peak1;
+
+    *star_bkg=star_bkg2;
+    *star_flux=star_flux2;
+
+    sinfo_msg_debug("ak2");
+
+    //psf1 = irplib_strehl_generate_psf(m1, m2, lam, dlam, pscale1, size*4);
+    //psf_peak1 = cpl_image_get_max(psf1) ;
+
+
+
+    /* Compute Strehl */
+    //*strehl = (*star_peak *prat2/trat/ *star_flux) / (*psf_peak / *psf_flux);
+    *strehl = (*star_peak/(*star_flux*trat)) / (psf_peak1 );
+    //*strehl = (*star_peak/(*star_flux)) / (psf_peak1 / *psf_flux) ;
+    sinfo_msg_debug("peak=%g flux1=%f flux2=%f flux=%f cflux=%g "
+                    "fct=%g psf_peak=%g",
+	      *star_peak,star_flux1,star_flux2,*star_flux,
+              *star_flux/frat*prat2,prat2/frat,psf_peak1);
+    sinfo_msg_debug("=======strehl=%g",*strehl);
+    /*
+    if (*strehl > 1)
+        cpl_msg_warning(cpl_func, "Extreme Strehl-ratio=%g, star_peak=%g, "
+                        "star_flux=%g, psf_peak=%g, psf_flux=%g", *strehl,
+                        *star_peak, *star_flux, *psf_peak, *psf_flux);
+
+
+    // Compute Strehl error
+    if (cpl_flux_get_noise_ring(im2, ring, noise_box_sz, noise_nsamples,
+                                bg_noise, NULL) == CPL_ERROR_NONE) {
+        *strehl_err = SINFO_STREHL_ERROR_COEFFICIENT * (*bg_noise) * pscale2 *
+            star_radius * star_radius / *star_flux;
+        irplib_assure_code(*strehl_err >= 0.0,       CPL_ERROR_ILLEGAL_OUTPUT);
+    } else {
+      sinfo_msg_warning("Problem computing noise");
+    }
+    */
+    *bg_noise=0;
+
+    cleanup:
+
+
+    if (!cpl_errorstate_is_equal(initial_errorstate)) {
+        /* Dump the error history since recipe execution start.
+           At this point the recipe cannot recover from the error */
+        cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
+    }
+
+  if (cpl_error_get_code() != CPL_ERROR_NONE) {
+    return cpl_error_get_code();
+  } else {
+    return CPL_ERROR_NONE;
+  }
+
+}
+
+
+
+
+static cpl_error_code
+sinfo_get_star_features(const cpl_image* im,
+                        const int radius,
+			const int xpos,
+			const int ypos,
+                        double* xc,
+                        double* yc,
+                        double* peak,
+                        double* flux,
+                        double* bkg)
+{
+  int sx=0;
+  int sy=0;
+  int ixm=0;
+  int iym=0;
+  int llx=0;
+  int lly=0;
+  int urx=0;
+  int ury=0;
+  int dim_new=0;
+  double kappa=2;
+  double xm=0;
+  double ym=0;
+  double bkg_stdev=0;
+  int bkg_sx=SINFO_BKG_BOX_SZ;
+  int bkg_sy=SINFO_BKG_BOX_SZ;
+
+  cpl_bivector* iqe=NULL;
+  double* piqe=NULL;
+  cpl_image* im_new=NULL;
+
+  sx=cpl_image_get_size_x(im);
+  sy=cpl_image_get_size_y(im);
+
+  sinfo_msg_debug("star_radius=%d",radius);
+  //We find the image centroid
+  if(NULL != (iqe=cpl_image_iqe(im,sx/2-radius,sy/2-radius,
+				sx/2+radius,sy/2+radius))) {
+
+
+    piqe=cpl_bivector_get_x_data(iqe);
+    //*star_peak=piqe[5];
+    xm=piqe[0];
+    ym=piqe[1];
+    //Extract a square sub-image of minimal size not to hit the image borders
+    //centered on the previous image centroid
+    sinfo_msg_debug("Max ima: %g %g",xm,ym);
+    sinfo_msg_debug("Find min of: %g %g %g %g",xm,sx-xm,ym,sy-ym);
+    ixm=floor(xm);
+    iym=floor(ym);
+    sinfo_msg_debug("ixm=%d iym=%d",ixm,iym);
+    dim_new=floor(sinfo_find_min_of_four(xm,sx-xm,ym,sy-ym));
+    sinfo_msg_debug("dim_new=%d",dim_new);
+    llx=(ixm-dim_new > 1) ? ixm-dim_new : 1;
+    lly=(iym-dim_new > 1) ? iym-dim_new : 1;
+    urx=(ixm+dim_new < sx) ? ixm+dim_new : sx;
+    ury=(iym+dim_new < sy) ? iym+dim_new : sy;
+    sinfo_msg_debug("llx=%d lly=%d urx=%d ury=%d",llx,lly,urx,ury);
+    check_nomsg(im_new=cpl_image_extract(im,llx,lly,urx,ury));
+
+    //compute the background of this last image
+    check_nomsg(sinfo_get_bkg_4corners(im_new,bkg_sx,bkg_sy,bkg,&bkg_stdev));
+
+
+
+    sinfo_free_bivector(&iqe);
+
+    //Determine the image pick on the new coordinate system
+    iqe=cpl_image_iqe(im_new,dim_new-radius,dim_new-radius,
+		      dim_new+radius,dim_new+radius);
+    sinfo_msg_debug("xc=%g yc=%g",piqe[0],piqe[1]);
+    *xc=piqe[0]-dim_new-1;
+    *yc=piqe[1]-dim_new-1;
+
+
+    sinfo_msg_debug("xc=%g yc=%g",*xc,*yc);
+    //*peak=piqe[5];
+    *peak=cpl_image_get_max_window(im_new,dim_new-radius,dim_new-radius,
+				   dim_new+radius,dim_new+radius);
+
+    sinfo_get_flux_above_bkg(im_new,kappa,bkg_stdev,flux);
+    *peak -= (*bkg);
+    sinfo_msg_debug("star peak=%g bkg=%g",*peak,*bkg);
+
+
+    sinfo_free_bivector(&iqe);
+
+
+  } else {
+    sinfo_msg_warning("IQE fit failed");
+    cpl_error_reset();
+    sinfo_msg_debug("xc=%d yc=%d radius=%d",xpos,ypos,radius);
+    *xc=xpos-sx/2;
+    *yc=ypos-sy/2;
+    sinfo_msg_debug("xc=%g yc=%g",*xc,*yc);
+    check_nomsg(sinfo_get_bkg_4corners(im,bkg_sx,bkg_sy,bkg,&bkg_stdev));
+    check_nomsg(sinfo_get_safe_box(&llx, &lly, &urx, &ury, xpos,ypos,radius,
+				   64,64));
+    check_nomsg(*peak=cpl_image_get_max_window(im,llx,lly,urx,ury)-(*bkg));
+    sinfo_get_flux_above_bkg(im,kappa,bkg_stdev,flux);
+    sinfo_msg_debug("star peak=%g bkg=%g",*peak,*bkg);
+
+
+  }
+
+
+
+ cleanup:
+  sinfo_free_image(&im_new);
+  sinfo_free_bivector(&iqe);
+
+
+
+
+  if (cpl_error_get_code() != CPL_ERROR_NONE) {
+    return cpl_error_get_code();
+  } else {
+    return CPL_ERROR_NONE;
+  }
+
+}
+
+
+
+
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Compute the strehl ratio in an image
+  @param    im             Image with pixel-type float
+  @param    m1             Diameter of the M1 mirror [m]
+  @param    m2             Diameter of the M2 mirror [m]
+  @param    lam            Central wavelength [micron]
+  @param    dlam           Filter bandwidth [micron]
+  @param    pscale         Positive pixel scale
+  @param    size           Size of image to be used for internal PSF
+  @param    xpos           The x position of the ring center
+  @param    ypos           The y position of the ring center
+  @param    r1             The Star Radius, r1 > 0
+  @param    r2             The Internal Radius, r2 > 0
+  @param    r3             The External Radius, r3 > r2
+  @param    strehl         Pointer to the Strehl Error (positive on success)
+  @param    strehl_err     Pointer to the Strehl Error (non-negative on success)
+  @param    star_bkg        Pointer to the Star Background
+  @param    star_peak      Pointer to the Star Peak (positive on success)
+  @param    star_flux      Pointer to the Star Flux (positive on success)
+  @param    psf_peak       Pointer to the PSF Peak (positive on success)
+  @param    psf_flux       Pointer to the PSF Flux (1 on success)
+  @param    bg_noise       Pointer to the Background Noise
+  @return   0 iff ok
+  @note     The output is undefined on error. On success the Strehl Ratio may
+            exceed 1.
+ */
+/*----------------------------------------------------------------------------*/
+cpl_error_code
+sinfo_strehl_compute_one(const cpl_image *   im,
+                                     double              m1,
+                                     double              m2,
+                                     double              lam,
+                                     double              dlam,
+                                     double              pscale,
+                                     int                 xpos,
+                                     int                 ypos,
+                                     double              r1,
+                                     double              r2,
+                                     double              r3,
+                                     int                 size,
+                                     double          *   strehl,
+                                     double          *   strehl_err,
+                                     double          *   star_bkg,
+                                     double          *   star_peak,
+                                     double          *   star_flux,
+                                     double          *   psf_peak,
+                                     double          *   psf_flux,
+                                     double          *   bg_noise)
+{
+    cpl_image  * psf;
+    double       star_radius;
+
+    /* FIXME: Arbitrary choice of image border */
+    const double window_size = (double)(SINFO_STREHL_RAD_CENTRAL);
+
+    /* Determined empirically by C. Lidman for Strehl error computation */
+    //Commented as not used
+    //const double strehl_error_coefficient = SINFO_MATH_PI * 0.007 / 0.0271;
+
+#if defined CPL_VERSION_CODE && CPL_VERSION_CODE >= CPL_VERSION(4, 0, 0)
+    double       ring[4];
+#else
+    /* FIXME: Remove this branch once CPL 3.X is no longer supported */
+    int          ring[4];
+#endif
+    cpl_bivector* iqe1=NULL;
+    double xc=0;
+    double yc=0;
+    int d=16;
+
+
+
+    /* Check compile-time constant */
+    cpl_ensure_code(window_size > 0.0,  CPL_ERROR_ILLEGAL_INPUT);
+
+    /* Test inputs */
+    cpl_ensure_code(im != NULL,         CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(strehl != NULL,     CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(strehl_err != NULL, CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(star_bkg != NULL,    CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(star_peak != NULL,  CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(star_flux != NULL,  CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(psf_peak != NULL,   CPL_ERROR_NULL_INPUT);
+    cpl_ensure_code(psf_flux != NULL,   CPL_ERROR_NULL_INPUT);
+
+    cpl_ensure_code(pscale > 0.0,      CPL_ERROR_ILLEGAL_INPUT);
+
+
+    cpl_ensure_code(r1 > 0.0,      CPL_ERROR_ILLEGAL_INPUT);
+    cpl_ensure_code(r2 > 0.0,      CPL_ERROR_ILLEGAL_INPUT);
+
+    cpl_ensure_code(r3 > r2,       CPL_ERROR_ILLEGAL_INPUT);
+
+
+    /* Computing a Strehl ratio is a story between an ideal PSF */
+    check_nomsg(sinfo_compute_psf(m1,m2/m1,lam*1.e-6,pscale,xc,yc,
+				  1.,psf_peak));
+  /* and a candidate image supposed to approximate this ideal PSF. */
+
+    /* Generate first appropriate PSF to find max peak */
+
+    psf = irplib_strehl_generate_psf(m1, m2, lam, dlam, pscale, size);
+    cpl_ensure_code(psf != NULL,      CPL_ERROR_ILLEGAL_OUTPUT);
+
+    /* Compute flux in PSF and find max peak */
+    *psf_peak = cpl_image_get_max(psf);
+
+    cpl_image_delete(psf);
+
+
+
+
+    assert( *psf_peak > 0.0); /* The ideal PSF has a positive maximum */
+    *psf_flux = 1.0; /* The psf flux, cpl_image_get_flux(psf), is always 1 */
+
+
+    /* Compute star_radius in pixels */
+    star_radius = r1/pscale;
+
+
+    check_nomsg(sinfo_get_star_features(im,d,xpos,ypos,&xc,&yc,
+					star_peak,star_flux,star_bkg));
+
+
+    check_nomsg(sinfo_compute_psf(m1,m2/m1,lam*1.e-6,pscale,xc,yc,1.,psf_peak));
+
+
+
+    *star_peak -= *star_bkg;
+
+
+    cpl_ensure_code(*star_peak > 0.0,      CPL_ERROR_ILLEGAL_OUTPUT);
+
+
+    /* Compute Strehl */
+    /* (StarPeak / StarFlux) / (PsfPeak / PsfFlux) */
+    sinfo_msg_debug("Star flux=%g", *star_flux);
+    sinfo_msg_debug("Star peak=%g", *star_peak);
+    sinfo_msg_debug("PSF  flux=%g", *psf_flux);
+    sinfo_msg_debug("PSF  peak=%g", *psf_peak);
+
+    *strehl = (*star_peak * *psf_flux ) / ( *star_flux * *psf_peak);
+
+
+
+     if (*strehl > 1)
+        cpl_msg_warning(cpl_func, "Extreme Strehl-ratio=%g, star_peak=%g, "
+                        "star_flux=%g, psf_peak=%g, psf_flux=%g", *strehl,
+                        *star_peak, *star_flux, *psf_peak, *psf_flux);
+
+    /* Compute Strehl error */
+    ring[0] = xpos;
+    ring[1] = ypos;
+    ring[2] = r2/pscale;
+    ring[3] = r3/pscale;
+    /*
+    *strehl_err = strehl_error_coefficient * (*bg_noise) * pscale *
+        star_radius * star_radius / *star_flux;
+
+    // This check should not be able to fail, but just to be sure
+    cpl_ensure_code(*strehl_err >= 0.0,       CPL_ERROR_ILLEGAL_OUTPUT);
+    */
+    *bg_noise=0;
+
+
+ cleanup:
+    sinfo_free_bivector(&iqe1);
+    if (cpl_error_get_code() != CPL_ERROR_NONE) {
+      return cpl_error_get_code();
+    } else {
+      return CPL_ERROR_NONE;
+    }
+
+
+}
+
+
+
+static void
+sinfo_check_borders(cpl_size* val,const int max,const int thresh)
+{
+
+  *val = ((*val-thresh) > 0) ? *val : thresh;
+  *val = ((*val+thresh) < max) ? *val : max-thresh-1;
+  return;
+}
+
+static void
+sinfo_get_safe_box(int* llx,
+                   int* lly,
+                   int* urx,
+                   int* ury,
+                   const int xpos,
+                   const int ypos,
+                   const int box,
+                   const int szx,
+                   const int szy)
+
+{
+  *llx= ((xpos-box)>0)   ? (xpos-box) : 1;
+  *lly= ((ypos-box)>0)   ? (ypos-box) : 1;
+  *urx= ((xpos+box)<szx) ? (xpos+box) : szx-1 ;
+  *ury= ((ypos+box)<szy) ? (ypos+box) : szy-1 ;
+
+  return;
+}
+
+
+
+
+
+/*---------------------------------------------------------------------------*/
+/**
+ * @brief  Computes bkg from image
+ * @param  img      input image
+ * @param  bkg_sx   x size bkg corner window
+ * @param  bkg_sy   y size bkg corner window
+ * @param  bkg      background value
+ * @param  std      std deviation value of background image 
+ * @return background value as median of pixels in 4 image's corners
+ */
+/*---------------------------------------------------------------------------*/
+cpl_error_code
+sinfo_get_bkg_4corners(const cpl_image *img,
+		       const int bkg_sx,
+                       const int bkg_sy,
+                       double* bkg,
+                       double* std)
+{
+
+  int sx=0;
+  int sy=0;
+  cpl_image* img_bkg=NULL;
+  *bkg=0;
+
+  cknull(img,"NULL input image!");
+  check_nomsg(sx=cpl_image_get_size_x(img));
+  check_nomsg(sy=cpl_image_get_size_y(img));
+
+  check_nomsg(img_bkg=cpl_image_new(2*bkg_sx,2*bkg_sy,CPL_TYPE_FLOAT));
+  check_nomsg(cpl_image_copy(img_bkg,cpl_image_extract(img,1,1,bkg_sx,bkg_sy),
+			     1,1));
+
+  check_nomsg(cpl_image_copy(img_bkg,cpl_image_extract(img,sx-bkg_sx,1,
+						       sx,bkg_sy),bkg_sx+1,1));
+  check_nomsg(cpl_image_copy(img_bkg,cpl_image_extract(img,1,sy-bkg_sy,
+						       bkg_sx,sy),1,bkg_sy+1));
+
+  check_nomsg(cpl_image_copy(img_bkg,
+			     cpl_image_extract(img,sx-bkg_sx,sy-bkg_sy,sx,sy),
+			     bkg_sx+1,bkg_sy+1));
+
+  check_nomsg(*bkg=cpl_image_get_median(img_bkg));
+  check_nomsg(*std=cpl_image_get_stdev(img_bkg));
+  sinfo_msg_debug("sky bkg: %f",*bkg);
+  sinfo_msg_debug("sky stdev: %f",*std);
+
+
+cleanup:
+  sinfo_free_image(&img_bkg);
+
+  if (cpl_error_get_code() != CPL_ERROR_NONE) {
+    return cpl_error_get_code();
+  } else {
+    return CPL_ERROR_NONE;
+  }
+
+
+}
+
+/**
+ * @brief computes theoretical PSF compuatation
+ * @param  dia      telescope diameter [m]
+ * @param  occ      telescope occulter size [% (of dia)]
+ * @param  lambda   wavelength [m]
+ * @param  psize    pixel size ["]
+ * @param  cx psf x offset     [pix]
+ * @param  cy psf y offset     [pix]
+ * @param  anamorph anamorphysm (y/x)
+ * @param  psf_peak theoretical PFS peak
+ * @return error status
+ */
+/*---------------------------------------------------------------------------*/
+cpl_error_code
+sinfo_compute_psf(const double dia,
+		  const double occ,
+		  const double lambda,
+		  const double psize,
+		  const double cx,
+		  const double cy,
+		  const double anamorph,
+		  double* psf_peak)
+{
+
+  int bin=SINFO_PSF_BIN;
+  int npoints=SINFO_PSF_NPOINT;
+
+  int dim=SINFO_PSF_DIM;
+  int blocks=SINFO_PSF_BLOCKS;
+  int sx=dim;
+  int sy=dim;
+
+
+  int i=0;
+  int j=0;
+  double k=0;
+
+  int ii=0;
+  int jj=0;
+  int start=0;
+
+  double nyquist=lambda/dia/2.*206265/psize*bin;
+  double cor=0.;
+  double v0=0;
+  double ll[npoints];
+  double part[npoints];
+  double ee;
+  double dll=0;
+  double tot1=0;
+  double tot2=0;
+
+
+  double fct=0;
+
+  double* pxx=NULL;
+  double* pyy=NULL;
+  double* prr=NULL;
+  double* ppsf0=NULL;
+
+  double* pcor=NULL;
+  double* pairy=NULL;
+  double* pw=NULL;
+
+  cpl_image* img_xx=NULL;
+  cpl_image* img_yy=NULL;
+  cpl_image* img_rr=NULL;
+  cpl_image* img_rrcor=NULL;
+  cpl_image* img_airy=NULL;
+  cpl_image* img_w=NULL;
+  cpl_image* img_psf0=NULL;
+
+
+
+  sinfo_msg_debug("lambda=%g",lambda);
+  sinfo_msg_debug("dia=%f",dia);
+  sinfo_msg_debug("psize=%f",psize);
+  sinfo_msg_debug("bin=%d",bin);
+  sinfo_msg_debug("nyquist=%f",nyquist);
+
+  check_nomsg(img_xx=cpl_image_new(sx,sy,CPL_TYPE_DOUBLE));
+  img_yy=cpl_image_new(sx,sy,CPL_TYPE_DOUBLE);
+  img_rr=cpl_image_new(sx,sy,CPL_TYPE_DOUBLE);
+  img_rrcor=cpl_image_new(sx,sy,CPL_TYPE_DOUBLE);
+
+  pxx=cpl_image_get_data_double(img_xx);
+  pyy=cpl_image_get_data_double(img_yy);
+  prr=cpl_image_get_data_double(img_rr);
+
+  for(j=0;j<sy;j++) {
+    for(i=0;i<sx;i++) {
+      //xz plane increasing along y
+      pxx[j*sx+i]=(i-sx/2-cx*bin)/nyquist*SINFO_MATH_PI/2;
+      //yz plane increasing along x
+      pyy[j*sx+i]=(j-sy/2-cy*bin)/nyquist*SINFO_MATH_PI/2*anamorph;
+
+      //combinex xyz surface
+      prr[j*sx+i]=sqrt(pxx[j*sx+i]*pxx[j*sx+i]+pyy[j*sx+i]*pyy[j*sx+i]);
+    }
+  }
+
+  /*
+  check_nomsg(cpl_image_save(img_xx,"out_xx.fits", CPL_BPP_IEEE_DOUBLE,
+			     NULL,CPL_IO_DEFAULT));
+
+  check_nomsg(cpl_image_save(img_yy,"out_yy.fits", CPL_BPP_IEEE_DOUBLE,
+			     NULL,CPL_IO_DEFAULT));
+
+  check_nomsg(cpl_image_save(img_rr,"out_rr.fits", CPL_BPP_IEEE_DOUBLE,
+			     NULL,CPL_IO_DEFAULT));
+
+  */
+
+  img_rrcor=cpl_image_new(sx,sy,CPL_TYPE_DOUBLE);
+
+  cor=1./(1.-occ*occ);
+  cor*=cor;
+
+  img_rrcor=cpl_image_duplicate(img_rr);
+  cpl_image_multiply_scalar(img_rrcor,cor);
+  pcor=cpl_image_get_data_double(img_rrcor);
+
+  /*
+  check_nomsg(cpl_image_save(img_rrcor,"out_rrcor.fits", CPL_BPP_IEEE_DOUBLE,
+			     NULL,CPL_IO_DEFAULT));
+  */
+
+  img_airy=cpl_image_new(sx,sy,CPL_TYPE_DOUBLE);
+  pairy=cpl_image_get_data_double(img_airy);
+
+
+  if (occ == 0.0) {
+
+    for(j=0;j<sx;j++) {
+      for(i=0;i<sy;i++) {
+	fct=(2.*j1(prr[j*sx+i])/prr[j*sx+i]);
+	pairy[j*sx+i]=fct*fct;
+
+      }
+    }
+
+  } else {
+    for(j=0;j<sy;j++) {
+      for(i=0;i<sx;i++) {
+
+	fct=(2.*j1(prr[j*sx+i])/prr[j*sx+i]-occ*occ*2.*j1(pcor[j*sx+i])/pcor[j*sx+i]);
+	pairy[j*sx+i]=cor*fct*fct;
+
+      }
+    }
+  }
+
+  /*
+  check_nomsg(cpl_image_save(img_airy,"out_airy.fits", CPL_BPP_IEEE_DOUBLE,
+			     NULL,CPL_IO_DEFAULT));
+
+  */
+
+  //To remove an expected NAN value at the PSF centre we re-set PSF(centre)=1
+  img_w=cpl_image_duplicate(img_airy);
+  pw=cpl_image_get_data_double(img_w);
+  pairy=cpl_image_get_data_double(img_airy);
+
+  for(j=0;j<sy;j++) {
+    for(i=0;i<sx;i++) {
+      if(!irplib_isnan(pairy[i+j*sx]) && (pairy[i+j*sx] ==0)) {
+	pairy[i+j*sx]=1.;
+        sinfo_msg_debug("====> %f",pairy[i+j*sx]);
+      }
+    }
+  }
+  pairy[sx/2+sy/2*sx]=1.;
+
+  sinfo_msg_debug("total-airy=%f",cpl_image_get_flux(img_airy));
+
+  /*
+  check_nomsg(cpl_image_save(img_airy,"out_airy1.fits", CPL_BPP_IEEE_DOUBLE,
+			     NULL,CPL_IO_DEFAULT));
+
+  */
+
+
+  // Computation of EE
+
+
+  v0=prr[0+dim/4-1];
+  sinfo_msg_debug("v0=%12.10g",v0);
+  for(i=0;i<npoints;i++) {
+    ll[i]=(double)i/npoints*v0;
+   }
+  dll=ll[1]-ll[0];
+  cor=1./(1.-occ*occ);
+
+  for(i=0;i<npoints;i++) {
+    part[i]=2.*j1(ll[i])/ll[i];
+  }
+  part[0]=1.0;
+
+  tot1=0.;
+  for(i=0;i<npoints;i++) {
+    tot1+=j1(occ*ll[i])*part[i]*dll;
+  }
+  sinfo_msg_debug("tot=%10.8f",tot1);
+
+
+  sinfo_msg_debug("cor=%10.8f",cor);
+
+  ee=(1.-j0(v0)*j0(v0));
+
+  sinfo_msg_debug("(1-j0(v0)*j0(v0))=%10.8f",ee);
+
+
+  ee-=(j1(v0))*(j1(v0));
+  sinfo_msg_debug("j1^2=%10.8f",(j1(v0))*(j1(v0)));
+  sinfo_msg_debug("ee=%10.8f",ee);
+
+  sinfo_msg_debug("factor=%10.8f",
+		  occ*occ*(1-j0(occ*v0)*j0(occ*v0)-j1(occ*v0)*j1(occ*v0)));
+
+
+  ee+=occ*occ*(1-j0(occ*v0)*j0(occ*v0)-j1(occ*v0)*j1(occ*v0));
+  sinfo_msg_debug("ee=%10.8f",ee);
+
+  ee-=2.*occ*tot1;
+  sinfo_msg_debug("ee=%10.8f",ee);
+
+  ee*=cor;
+  sinfo_msg_debug("ee=%10.8f",ee);
+
+
+  tot1=0;
+  pairy=cpl_image_get_data_double(img_airy);
+  prr=cpl_image_get_data_double(img_rr);
+  for(j=0;j<sy;j++) {
+    for(i=0;i<sx;i++) {
+      if(!irplib_isnan(pairy[i+j*sx]) && (prr[i+j*sx] <v0)) {
+	tot1+=pairy[i+j*sx]*ee;
+	//sinfo_msg_debug("tot=%f",tot1);
+
+      }
+    }
+  }
+
+  sinfo_msg_debug("tot=%10.8f",tot1);
+  cpl_image_divide_scalar(img_airy,tot1);
+
+  /*
+  check_nomsg(cpl_image_save(img_airy,"out_airy2.fits", CPL_BPP_IEEE_DOUBLE,
+			     NULL,CPL_IO_DEFAULT));
+
+  */
+
+
+  // Computation of maximum
+
+  sinfo_msg_debug("dim=%d blocks=%d,bin=%d",dim,blocks,bin);
+  start=(dim/2-1)-(blocks/2*bin-1)-bin/2;
+  sinfo_msg_debug("start=%d",start);
+
+  img_psf0=cpl_image_new(blocks,blocks,CPL_TYPE_DOUBLE);
+  ppsf0=cpl_image_get_data_double(img_psf0);
+  tot1=0.;
+  tot2=0.;
+
+  for(j=0;j<blocks;j++) {
+    for(i=0;i<blocks;i++) {
+      tot1=0;
+      for(jj=start+j*bin;jj<start+(j+1)*bin-1;jj++){
+	for(ii=start+i*bin;ii<start+(i+1)*bin-1;ii++){
+          if(!irplib_isnan(pairy[ii+jj*sx])) {
+	    tot1+=pairy[ii+jj*sx];
+	  }
+	}
+      }
+      ppsf0[i+j*blocks]=tot1;
+      tot2+=tot1;
+    }
+  }
+
+  cpl_image_divide_scalar(img_psf0,tot2);
+  /*
+  check_nomsg(cpl_image_save(img_psf0,"out_psf0.fits", CPL_BPP_IEEE_DOUBLE,
+			     NULL,CPL_IO_DEFAULT));
+
+  */
+  k=180.*3600./SINFO_MATH_PI;
+  sinfo_msg_debug("k=%f",k);
+  sinfo_msg_debug("radius of first zero: 1.22*lambda/d*k:=%f",
+		    1.22*lambda/dia*k);
+  sinfo_msg_debug("tot: %f",tot2);
+  sinfo_msg_debug("max: %f",cpl_image_get_max(img_psf0)*tot2);
+  sinfo_msg_debug("max/tot: %f",cpl_image_get_max(img_psf0));
+  *psf_peak=cpl_image_get_max(img_psf0);
+
+  sinfo_msg_debug("d=%g ob=%g w=%g ps=%g cx=%g cy=%g a=%g peak=%10.8g",
+		    dia,occ,lambda,psize,cx,cy,anamorph,*psf_peak);
+
+
+
+ cleanup:
+  sinfo_free_image(&img_xx);
+  sinfo_free_image(&img_yy);
+  sinfo_free_image(&img_rr);
+  sinfo_free_image(&img_rrcor);
+  sinfo_free_image(&img_airy);
+
+
+  if (cpl_error_get_code() != CPL_ERROR_NONE) {
+    return cpl_error_get_code();
+  } else {
+    return CPL_ERROR_NONE;
+  }
+
+}
+
+
+cpl_error_code
+sinfo_get_flux_above_bkg(const cpl_image* img,
+                         const float kappa,
+                         const float std,
+                         double* f)
+{
+
+  const float* pimg=NULL;
+  int sx=0;
+  int sy=0;
+  int i=0;
+  int j=0;
+  int k=0;
+  float tot=0;
+
+  cpl_image* timg=NULL;
+  double sky_bkg=0;
+  double sky_std=0;
+
+  timg=cpl_image_duplicate(img);
+  cpl_image_subtract_scalar(timg,std);
+  check_nomsg(sinfo_get_bkg_4corners(timg,SINFO_BKG_BOX_SZ,SINFO_BKG_BOX_SZ,
+				     &sky_bkg,&sky_std));
+
+  check_nomsg(pimg=cpl_image_get_data_float_const(timg));
+
+  sx=cpl_image_get_size_x(img);
+  sy=cpl_image_get_size_y(img);
+
+  for(j=0;j<sy;j++) {
+    for(i=0;i<sx;i++) {
+      if(!irplib_isnan(pimg[i+j*sx]) &&
+          (pimg[i+j*sx]>(sky_bkg+kappa*sky_std))) {
+	tot+=(double)pimg[i+j*sx];
+	k++;
+      }
+    }
+  }
+
+  *f=(double)(tot-k*sky_bkg);
+
+ cleanup:
+  sinfo_free_image(&timg);
+
+  if (cpl_error_get_code() != CPL_ERROR_NONE) {
+    return cpl_error_get_code();
+  } else {
+    return CPL_ERROR_NONE;
+  }
+
+}
+
+
+
+/*
+cpl_error_code
+sinfo_get_centroid(const cpl_image* img,
+                   const int d,
+                   const double xc,
+                   const double yc,
+                   double* xcen,
+                   double* ycen,
+                   double* xfwhm,
+                   double* yfwhm,
+                   double* angle)
+{
+
+  cpl_bivector* q=NULL;
+  int sx=0;
+  int sy=0;
+  double* pq=NULL;
+  double peak=0;
+  double bkg=0;
+
+  check_nomsg(sx=cpl_image_get_size_x(img));
+  check_nomsg(sy=cpl_image_get_size_y(img));
+
+  check_nomsg(q=cpl_image_iqe(img,sx/2-d,sy/2-d,sx/2+d,sy/2+d));
+  pq=cpl_bivector_get_data(q);
+
+  *xcen=pq[0];
+  *ycen=pq[1];
+  *xfwhm=pq[2];
+  *yfwhm=pq[3];
+  *angle=pq[4];
+  peak=pq[5];
+  bkg=pq[6];
+
+
+ cleanup:
+
+  sinfo_free_bivector(&q);
+
+  if (cpl_error_get_code() != CPL_ERROR_NONE) {
+    return cpl_error_get_code();
+  } else {
+    return CPL_ERROR_NONE;
+  }
+
+}
+*/
+
+
+
+static double
+sinfo_find_min_of_four(const double n1,
+                       const double n2,
+                       const double n3,
+                       const double n4)
+{
+  double min=0;
+  min = (n1 < n2) ? n1 : n2;
+  min = (min < n3) ? min : n3;
+  min = (min < n4) ? min : n4;
+  return min;
+}
+
+double
+sinfo_scale_flux(const double p1,
+                 const double p2,
+                 const double t1,
+                 const double t2)
+{
+
+  return (p2/p1)*(p2/p1)*(t2/t1);
+
+}
+
+
+/**@}*/
diff --git a/sinfoni/sinfo_new_psf.h b/sinfoni/sinfo_new_psf.h
new file mode 100644
index 0000000..2e9696e
--- /dev/null
+++ b/sinfoni/sinfo_new_psf.h
@@ -0,0 +1,155 @@
+#ifndef SINFO_NEW_PSF_H
+#define SINFO_NEW_PSF_H
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*****************************************************************************
+* E.S.O. - VLT project
+*
+* "@(#) $Id: sinfo_new_psf.h,v 1.12 2008/02/12 16:33:50 amodigli Exp $"
+*
+* who       when      what
+* --------  --------  ----------------------------------------------
+* amodigli  17/09/03  created
+*/
+
+/************************************************************************
+ * sinfo_new_psf.h
+
+ sinfo_psf.py does the image reconstruction of a set of sky-subtracted, 
+ flatfielded, 
+ bad pixel corrected and slope of the spectra aligned exposures of a bright 
+ star with continuum spectrum. The resulting image can be used to determine 
+ the PSF
+ *----------------------------------------------------------------------
+ */
+
+/*
+ * header files
+ */
+
+#include <cpl.h> 
+#include <irplib_strehl.h>
+#include "sinfo_msg.h"
+
+/*----------------------------------------------------------------------------
+ *                        Function ANSI C prototypes
+ *--------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+   Function     :       sinfo_new_psf()
+   In           :       ini_file: file name of according .ini file
+   Out          :       integer (0 if it worked, -1 if it doesn't) 
+   Job          :
+
+ sinfo_psf.py does the image reconstruction of a set of sky-subtracted, 
+ flatfielded, bad pixel corrected and slope of the spectra aligned exposures 
+ of a bright star with continuum spectrum. The resulting image can be used 
+ to determine the PSF
+
+ ---------------------------------------------------------------------------*/
+int 
+sinfo_new_psf(const char* plugin_id,
+              cpl_parameterlist* config,
+              cpl_frameset* sof,
+              cpl_frameset* ref_set) ;
+
+
+int sinfo_strehl_compute_two(
+			  const cpl_image *   im1,
+			  const cpl_image *   im2,
+			  double              m1,
+			  double              m2,
+			  double              lam,
+			  double              pscale1,
+			  double              pscale2,
+			  double              exptime1,
+			  double              exptime2,
+			  int                 xpos1,
+			  int                 ypos1,
+			  int                 xpos2,
+			  int                 ypos2,
+			  double              r1,
+			  double              r2,
+			  double              r3,
+			  double          *   strehl,
+			  double          *   strehl_err,
+			  double          *   star_bg,
+			  double          *   star_peak,
+			  double          *   star_flux,
+			  double          *   psf_peak,
+			  double          *   psf_flux,
+			  double          *   bg_noise);
+
+cpl_error_code 
+sinfo_strehl_compute_one(const cpl_image *   im,
+			 double              m1,
+			 double              m2,
+			 double              lam,
+			 double              dlam,
+			 double              pscale,
+			 int                 xpos,
+			 int                 ypos,
+			 double              r1,
+			 double              r2,
+			 double              r3,
+                         int                 noise_box_sz,
+			 double          *   strehl,
+			 double          *   strehl_err,
+			 double          *   star_bg,
+			 double          *   star_peak,
+			 double          *   star_flux,
+			 double          *   psf_peak,
+			 double          *   psf_flux,
+			 double          *   bg_noise);
+
+
+
+
+cpl_error_code 
+sinfo_get_bkg_4corners(const cpl_image *img,
+		       const int bkg_sx,
+                       const int bkg_sy,
+                       double* bkg,
+                       double* std);
+
+cpl_error_code
+sinfo_compute_psf(const double dia, 
+		  const double occ,
+		  const double lambda,
+		  const double psize,
+		  const double cx,
+		  const double cy,
+		  const double anamorph,
+		  double* psf_peak);
+cpl_error_code
+sinfo_get_flux_above_bkg(const cpl_image* img, 
+                         const float kappa, 
+                         const float std, 
+                         double* f);
+
+
+double
+sinfo_scale_flux(const double p1, 
+                 const double p2, 
+                 const double t1, 
+                 const double t2);
+
+#endif 
+
+/*--------------------------------------------------------------------------*/
diff --git a/sinfoni/sinfo_new_resampling.c b/sinfoni/sinfo_new_resampling.c
new file mode 100644
index 0000000..b9bee88
--- /dev/null
+++ b/sinfoni/sinfo_new_resampling.c
@@ -0,0 +1,556 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/*----------------------------------------------------------------------------
+   
+   File name     :    sinfo_new_resampling.c
+   Author         :    Nicolas Devillard
+   Created on    :    Jan 04, 1996
+   Description    :    resampling routines
+
+ ---------------------------------------------------------------------------*/
+
+/*
+    $Id: sinfo_new_resampling.c,v 1.10 2012/03/03 09:50:08 amodigli Exp $
+    $Author: amodigli $
+    $Date: 2012/03/03 09:50:08 $
+    $Revision: 1.10 $
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+/*---------------------------------------------------------------------------
+                                  Includes
+ ---------------------------------------------------------------------------*/
+#include <math.h>
+#include "sinfo_new_resampling.h"
+#include "sinfo_pixel_handling.h"
+#include "sinfo_globals.h"
+/* #include "my_pi.h" */
+#include "sinfo_resampling.h"
+/*---------------------------------------------------------------------------
+                              Private functions
+ ---------------------------------------------------------------------------*/
+
+static void new_reverse_tanh_kernel(double * data, int nn) ;
+static double sinfo_new_sinc(double x);
+
+/*---------------------------------------------------------------------------
+                              Function codes
+ ---------------------------------------------------------------------------*/
+
+/**@{*/
+/**
+ * @defgroup sinfo_new_resampling Image resampling
+ *
+ * TBD
+ */
+
+/*-------------------------------------------------------------------------*/
+/**
+  @name        sinfo_new_generate_interpolation_kernel
+  @memo        Generate an interpolation kernel to use in this module.
+  @param    kernel_type        Type of interpolation kernel.
+  @return    1 newly allocated array of doubles.
+  @doc
+
+  Provide the name of the kernel you want to generate. Supported kernel
+  types are:
+
+  \begin{tabular}{ll}
+  NULL            &    default kernel, currently "tanh" \\
+  "default"        &    default kernel, currently "tanh" \\
+  "tanh"        &    Hyperbolic tangent \\
+  "sinc2"        &    Square sinfo_new_sinc \\
+  "lanczos"        &    Lanczos2 kernel \\
+  "hamming"        &    Hamming kernel \\
+  "hann"        &    Hann kernel
+  \end{tabular}
+
+  The returned array of doubles is ready of use in the various re-sampling
+  functions in this module. It must be deallocated using cpl_free().
+ */
+/*--------------------------------------------------------------------------*/
+
+double   *
+sinfo_new_generate_interpolation_kernel(const char * kernel_type)
+{
+    double  *    tab ;
+    int         i ;
+    double      x ;
+    double        alpha ;
+    double        inv_norm ;
+    int         samples = KERNEL_SAMPLES ;
+
+    if (kernel_type==NULL) {
+        tab = sinfo_new_generate_interpolation_kernel("tanh") ;
+    } else if (!strcmp(kernel_type, "default")) {
+        tab = sinfo_new_generate_interpolation_kernel("tanh") ;
+    } else if (!strcmp(kernel_type, "sinfo_new_sinc")) {
+        tab = cpl_malloc(samples * sizeof(double)) ;
+        tab[0] = 1.0 ;
+        tab[samples-1] = 0.0 ;
+        for (i=1 ; i<samples ; i++) {
+            x = (double)KERNEL_WIDTH * (double)i/(double)(samples-1) ;
+            tab[i] = sinfo_new_sinc(x) ;
+        }
+    } else if (!strcmp(kernel_type, "sinc2")) {
+        tab = cpl_malloc(samples * sizeof(double)) ;
+        tab[0] = 1.0 ;
+        tab[samples-1] = 0.0 ;
+        for (i=1 ; i<samples ; i++) {
+            x = 2.0 * (double)i/(double)(samples-1) ;
+            tab[i] = sinfo_new_sinc(x) ;
+            tab[i] *= tab[i] ;
+        }
+    } else if (!strcmp(kernel_type, "lanczos")) {
+        tab = cpl_malloc(samples * sizeof(double)) ;
+        for (i=0 ; i<samples ; i++) {
+            x = (double)KERNEL_WIDTH * (double)i/(double)(samples-1) ;
+            if (fabs(x)<2) {
+                tab[i] = sinfo_new_sinc(x) * sinfo_new_sinc(x/2) ;
+            } else {
+                tab[i] = 0.00 ;
+            }
+        }
+    } else if (!strcmp(kernel_type, "hamming")) {
+        tab = cpl_malloc(samples * sizeof(double)) ;
+        alpha = 0.54 ;
+        inv_norm  = 1.00 / (double)(samples - 1) ;
+        for (i=0 ; i<samples ; i++) {
+            x = (double)i ;
+            if (i<(samples-1)/2) {
+                tab[i] = alpha + (1-alpha) * cos(2.0*PI_NUMB*x*inv_norm) ;
+            } else {
+                tab[i] = 0.0 ;
+            }
+        }
+    } else if (!strcmp(kernel_type, "hann")) {
+        tab = cpl_malloc(samples * sizeof(double)) ;
+        alpha = 0.50 ;
+        inv_norm  = 1.00 / (double)(samples - 1) ;
+        for (i=0 ; i<samples ; i++) {
+            x = (double)i ;
+            if (i<(samples-1)/2) {
+                tab[i] = alpha + (1-alpha) * cos(2.0*PI_NUMB*x*inv_norm) ;
+            } else {
+                tab[i] = 0.0 ;
+            }
+        }
+    } else if (!strcmp(kernel_type, "tanh")) {
+        tab = sinfo_new_generate_tanh_kernel(TANH_STEEPNESS) ;
+    } else {
+        sinfo_msg_error("unrecognized kernel type [%s]: aborting generation",
+                kernel_type) ;
+        return NULL ;
+    }
+
+    return tab ;
+}
+
+/*-------------------------------------------------------------------------*/
+/**
+  @name        sinfo_new_sinc
+  @memo        Cardinal sine.
+  @param    x    double value.
+  @return    1 double.
+  @doc
+
+  Compute the value of the function sinfo_sinc(x)=sin(pi*x)/(pi*x) at the
+  requested x.
+ */
+/*--------------------------------------------------------------------------*/
+
+double
+sinfo_new_sinc(double x)
+{
+    if (fabs(x)<1e-4)
+        return (double)1.00 ;
+    else
+        return ((sin(x * (double)PI_NUMB)) / (x * (double)PI_NUMB)) ;
+}
+
+
+
+/*-------------------------------------------------------------------------*/
+/**
+  @name        sinfo_new_warp_image_generic
+  @memo        Warp an image according to a polynomial transformation.
+  @param    image_in        Image to warp.
+  @param    kernel_type        Interpolation kernel to use.
+  @param    poly_u            Polynomial transform in U.
+  @param    poly_v            Polynomial transform in V.
+  @return    1 newly allocated image.
+  @doc
+
+  Warp an image according to a polynomial transform. Provide two
+  polynomials (see poly2d.h for polynomials in this library) Pu and Pv such
+  as:
+
+  \begin{verbatim}
+  x = sinfo_poly2d_compute(Pu, u, v)
+  y = sinfo_poly2d_compute(Pv, u, v)
+  \end{verbatim}
+
+  Attention! The polynomials define a reverse transform. (u,v) are
+  coordinates in the warped image and (x,y) are coordinates in the original
+  image. The transform you provide is used to compute from the warped
+  image, which pixels contributed in the original image.
+
+  The output image will have strictly the same size as in the input image.
+  Beware that for extreme transformations, this might lead to blank images
+  as result.
+
+  See the function sinfo_generate_interpolation_kernel() for possible kernel
+  types. If you want to use a default kernel, provide NULL for kernel type.
+
+  The returned image is a newly allocated objet, use cpl_image_delete() to
+  deallocate it.
+
+ */
+/*--------------------------------------------------------------------------*/
+
+cpl_image *
+sinfo_new_warp_image_generic(
+    cpl_image         *    image_in,
+    char          *    kernel_type,
+    cpl_polynomial    *    poly_u,
+    cpl_polynomial    *    poly_v
+)
+{
+    cpl_image    *    image_out ;
+    int             i, j, k ;
+    int             lx_out, ly_out ;
+    double           cur ;
+    double           neighbors[16] ;
+    double           rsc[8],
+                    sumrs ;
+    double           x, y ;
+    int             px, py ;
+    int             pos ;
+    int             tabx, taby ;
+    double      *    kernel ;
+    int                  leaps[16] ;
+    int ilx=0;
+    int ily=0;
+    float* pidata=NULL;
+    float* podata=NULL;
+    cpl_vector* vx=NULL;
+    if (image_in == NULL) return NULL ;
+
+
+    /* Generate default interpolation kernel */
+    kernel = sinfo_new_generate_interpolation_kernel(kernel_type) ;
+    if (kernel == NULL) {
+        sinfo_msg_error("cannot generate kernel: aborting resampling") ;
+        return NULL ;
+    }
+    ilx=cpl_image_get_size_x(image_in);
+    ily=cpl_image_get_size_y(image_in);
+    pidata=cpl_image_get_data_float(image_in);
+
+    /* Compute new image size   */
+    lx_out = (int)ilx ;
+    ly_out = (int)ily ;
+
+    image_out = cpl_image_new(lx_out, ly_out,CPL_TYPE_FLOAT) ;
+    podata=cpl_image_get_data_float(image_out);
+
+    /* Pre compute leaps for 16 closest neighbors positions */
+
+    leaps[0] = -1 - ilx ;
+    leaps[1] =    - ilx ;
+    leaps[2] =  1 - ilx ;
+    leaps[3] =  2 - ilx ;
+
+    leaps[4] = -1 ;
+    leaps[5] =  0 ;
+    leaps[6] =  1 ;
+    leaps[7] =  2 ;
+
+    leaps[8] = -1 + ilx ;
+    leaps[9] =      ilx ;
+    leaps[10]=  1 + ilx ;
+    leaps[11]=  2 + ilx ;
+
+    leaps[12]= -1 + 2*ilx ;
+    leaps[13]=      2*ilx ;
+    leaps[14]=  1 + 2*ilx ;
+    leaps[15]=  2 + 2*ilx ;
+
+    vx=cpl_vector_new(2); /* vector of size 2 = polynomial dimension */
+    /* Double loop on the output image  */
+    for (j=0 ; j < ly_out ; j++) {
+        for (i=0 ; i< lx_out ; i++) {
+            /* Compute the original source for this pixel   */
+      cpl_vector_set(vx,0,(double)i);
+      cpl_vector_set(vx,1,(double)j);
+            x = cpl_polynomial_eval(poly_u, vx);
+            y = cpl_polynomial_eval(poly_v, vx);
+
+            /* Which is the closest integer positioned neighbor?    */
+            px = (int)x ;
+            py = (int)y ;
+
+            if ((px < 1) ||
+                (px > (ilx-3)) ||
+                (py < 1) ||
+                (py > (ily-3)))
+                podata[i+j*lx_out] = (pixelvalue)0.0/0.0 ;
+            else {
+                /* Now feed the positions for the closest 16 neighbors  */
+                pos = px + py * ilx ;
+                for (k=0 ; k<16 ; k++)
+                    neighbors[k] = (double)(pidata[(int)(pos+leaps[k])]) ;
+
+                /* Which tabulated value index shall we use?    */
+                tabx = (x - (double)px) * (double)(TABSPERPIX) ; 
+                taby = (y - (double)py) * (double)(TABSPERPIX) ; 
+
+                /* Compute resampling coefficients  */
+                /* rsc[0..3] in x, rsc[4..7] in y   */
+
+                rsc[0] = kernel[TABSPERPIX + tabx] ;
+                rsc[1] = kernel[tabx] ;
+                rsc[2] = kernel[TABSPERPIX - tabx] ;
+                rsc[3] = kernel[2 * TABSPERPIX - tabx] ;
+                rsc[4] = kernel[TABSPERPIX + taby] ;
+                rsc[5] = kernel[taby] ;
+                rsc[6] = kernel[TABSPERPIX - taby] ;
+                rsc[7] = kernel[2 * TABSPERPIX - taby] ;
+
+                sumrs = (rsc[0]+rsc[1]+rsc[2]+rsc[3]) *
+                        (rsc[4]+rsc[5]+rsc[6]+rsc[7]) ;
+
+                /* Compute interpolated pixel now   */
+                cur =   rsc[4] * (  rsc[0]*neighbors[0] +
+                                    rsc[1]*neighbors[1] +
+                                    rsc[2]*neighbors[2] +
+                                    rsc[3]*neighbors[3] ) +
+                        rsc[5] * (  rsc[0]*neighbors[4] +
+                                    rsc[1]*neighbors[5] +
+                                    rsc[2]*neighbors[6] +
+                                    rsc[3]*neighbors[7] ) +
+                        rsc[6] * (  rsc[0]*neighbors[8] +
+                                    rsc[1]*neighbors[9] +
+                                    rsc[2]*neighbors[10] +
+                                    rsc[3]*neighbors[11] ) +
+                        rsc[7] * (  rsc[0]*neighbors[12] +
+                                    rsc[1]*neighbors[13] +
+                                    rsc[2]*neighbors[14] +
+                                    rsc[3]*neighbors[15] ) ; 
+
+                /* Affect the value to the output image */
+                podata[i+j*lx_out] = (pixelvalue)(cur/sumrs) ;
+                /* done ! */
+            }       
+        }
+    }
+    cpl_vector_delete(vx);
+    cpl_free(kernel) ;
+    return image_out ;
+}
+
+
+/*-------------------------------------------------------------------------*/
+/**
+  @name        sinfo_new_generate_tanh_kernel
+  @memo        Generate a hyperbolic tangent kernel.
+  @param    steep    Steepness of the hyperbolic tangent parts.
+  @return    1 pointer to a newly allocated array of doubles.
+  @doc
+
+  The following function builds up a good approximation of a box filter. It
+  is built from a product of hyperbolic tangents. It has the following
+  properties:
+
+  \begin{itemize}
+  \item It converges very quickly towards +/- 1.
+  \item The converging transition is very sharp.
+  \item It is infinitely differentiable everywhere (i.e. smooth).
+  \item The transition sharpness is scalable.
+  \end{itemize}
+
+  The returned array must be deallocated using cpl_free().
+ */
+/*--------------------------------------------------------------------------*/
+
+#define hk_gen(x,s) (((tanh(s*(x+0.5))+1)/2)*((tanh(s*(-x+0.5))+1)/2))
+
+double * sinfo_new_generate_tanh_kernel(double steep)
+{
+    double  *   kernel ;
+    double  *   x ;
+    double      width ;
+    double      inv_np ;
+    double      ind ;
+    int         i ;
+    int         np ;
+    int         samples ;
+
+    width   = (double)TABSPERPIX / 2.0 ; 
+    samples = KERNEL_SAMPLES ;
+    np      = 32768 ; /* Hardcoded: should never be changed */
+    inv_np  = 1.00 / (double)np ;
+
+    /*
+     * Generate the kernel expression in Fourier space
+     * with a correct frequency ordering to allow standard FT
+     */
+    x = cpl_malloc((2*np+1)*sizeof(double)) ;
+    for (i=0 ; i<np/2 ; i++) {
+        ind      = (double)i * 2.0 * width * inv_np ;
+        x[2*i]   = hk_gen(ind, steep) ;
+        x[2*i+1] = 0.00 ;
+    }
+    for (i=np/2 ; i<np ; i++) {
+        ind      = (double)(i-np) * 2.0 * width * inv_np ;
+        x[2*i]   = hk_gen(ind, steep) ;
+        x[2*i+1] = 0.00 ;
+    }
+
+    /* 
+     * Reverse Fourier to come back to image space
+     */
+    new_reverse_tanh_kernel(x, np) ;
+
+    /*
+     * Allocate and fill in returned array
+     */
+    kernel = cpl_malloc(samples * sizeof(double)) ;
+    for (i=0 ; i<samples ; i++) {
+        kernel[i] = 2.0 * width * x[2*i] * inv_np ;
+    }
+    cpl_free(x) ;
+    return kernel ;
+}
+
+
+/*-------------------------------------------------------------------------*/
+/**
+  @name        new_reverse_tanh_kernel
+  @memo        Bring a hyperbolic tangent kernel from Fourier to normal space.
+  @param    data    Kernel samples in Fourier space.
+  @param    nn        Number of samples in the input kernel.
+  @return    void
+  @doc
+
+  Bring back a hyperbolic tangent kernel from Fourier to normal space. Do
+  not try to understand the implementation and DO NOT MODIFY THIS FUNCTION.
+ */
+/*--------------------------------------------------------------------------*/
+
+#define KERNEL_SW(a,b) tempr=(a);(a)=(b);(b)=tempr
+static void new_reverse_tanh_kernel(double * data, int nn)
+{
+    unsigned long   n,
+                    mmax,
+                    m,
+                    i, j,
+                    istep ;
+    double  wtemp,
+            wr,
+            wpr,
+            wpi,
+            wi,
+            theta;
+    double  tempr,
+            tempi;
+
+    n = (unsigned long)nn << 1;
+    j = 1;
+    for (i=1 ; i<n ; i+=2) {
+        if (j > i) {
+            KERNEL_SW(data[j-1],data[i-1]);
+            KERNEL_SW(data[j],data[i]);
+        }
+        m = n >> 1;
+        while (m>=2 && j>m) {
+            j -= m;
+            m >>= 1;
+        }
+        j += m;
+    }
+    mmax = 2;
+    while (n > mmax) {
+        istep = mmax << 1;
+        theta = 2 * PI_NUMB / mmax;
+        wtemp = sin(0.5 * theta);
+        wpr = -2.0 * wtemp * wtemp;
+        wpi = sin(theta);
+        wr  = 1.0;
+        wi  = 0.0;
+        for (m=1 ; m<mmax ; m+=2) {
+            for (i=m ; i<=n ; i+=istep) {
+                j = i + mmax;
+                tempr = wr * data[j-1] - wi * data[j];
+                tempi = wr * data[j]   + wi * data[j-1];
+                data[j-1] = data[i-1] - tempr;
+                data[j]   = data[i]   - tempi;
+                data[i-1] += tempr;
+                data[i]   += tempi;
+            }
+            wr = (wtemp = wr) * wpr - wi * wpi + wr;
+            wi = wi * wpr + wtemp * wpi + wi;
+        }
+        mmax = istep;
+    }
+}
+#undef KERNEL_SW
+
+
+
+/*-------------------------------------------------------------------------*/
+/**
+  @name        sinfo_new_show_interpolation_kernel
+  @memo        Print out an interpolation kernel values on stdout.
+  @param    kernel_name        Name of the kernel to print out.
+  @return    void
+  @doc
+
+  Takes in input a kernel name, generates the corresponding kernel and
+  prints it out on stdout, then discards the generated kernel.
+
+  For debugging purposes mostly.
+ */
+/*--------------------------------------------------------------------------*/
+
+void sinfo_new_show_interpolation_kernel(char * kernel_name)
+{
+    double    *    ker ;
+    int            i ;
+    double        x ;
+
+
+    ker = sinfo_new_generate_interpolation_kernel(kernel_name) ;
+    if (ker == NULL)
+        return ;
+
+    (void)fprintf(stdout, "# Kernel is %s\n", kernel_name) ;
+    x = 0.00 ;
+    for (i=0 ; i<KERNEL_SAMPLES ; i++) {
+        (void)fprintf(stdout, "%g %g\n", x, ker[i]) ;
+        x += 1.00 / (double)TABSPERPIX ;
+    }
+    cpl_free(ker) ;
+    return ;
+}
+/**@}*/
+
diff --git a/sinfoni/sinfo_new_resampling.h b/sinfoni/sinfo_new_resampling.h
new file mode 100644
index 0000000..f7f4cdb
--- /dev/null
+++ b/sinfoni/sinfo_new_resampling.h
@@ -0,0 +1,209 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/*----------------------------------------------------------------------------
+   
+   File name     :    sinfo_resampling.h
+   Author         :    Nicolas Devillard
+   Created on    :    Jan 04, 1996
+   Description    :    resampling routines
+
+ ---------------------------------------------------------------------------*/
+
+/*
+
+ $Id: sinfo_new_resampling.h,v 1.9 2007/06/06 07:10:45 amodigli Exp $
+ $Author: amodigli $
+ $Date: 2007/06/06 07:10:45 $
+ $Revision: 1.9 $
+
+ */
+
+#ifndef SINFO_NEW_RESAMPLING_H
+#define SINFO_NEW_RESAMPLING_H
+
+/*---------------------------------------------------------------------------
+                                  Includes
+ ---------------------------------------------------------------------------*/
+
+/*
+#include "my_image_handling.h"
+#include "sinfo_matrix.h"
+*/
+#include "sinfo_poly2d.h"
+#include <cpl.h>
+#include "sinfo_msg.h"
+
+
+/*---------------------------------------------------------------------------
+                                  Defines
+ ---------------------------------------------------------------------------*/
+
+
+#define TRANSFO_AFFINE          0
+#define TRANSFO_DEG2            1
+#define TRANSFO_HOMOGRAPHIC     2
+
+/* Number of pixels set to 0 by the shift resampling */
+#define    SHIFT_REJECT_L            2
+#define    SHIFT_REJECT_R            2
+#define    SHIFT_REJECT_T            2
+#define    SHIFT_REJECT_B            2
+
+/*
+ * Kernel definition in terms of sampling
+ */
+
+
+/* Number of tabulations in kernel  */
+#define TABSPERPIX      (1000)
+#define KERNEL_WIDTH    (2.0)
+#define KERNEL_SAMPLES  (1+(int)(TABSPERPIX * KERNEL_WIDTH))
+
+#define TANH_STEEPNESS    (5.0)
+
+
+/*---------------------------------------------------------------------------
+                         Function ANSI C prototypes
+ ---------------------------------------------------------------------------*/
+
+/*-------------------------------------------------------------------------*/
+/**
+  @name     sinfo_new_generate_interpolation_kernel
+  @memo     Generate an interpolation kernel to use in this module.
+  @param    kernel_type     Type of interpolation kernel.
+  @return   1 newly allocated array of doubles.
+  @doc
+ 
+  Provide the name of the kernel you want to generate. Supported kernel
+  types are:
+ 
+  \begin{tabular}{ll}
+  NULL          &   default kernel, currently "tanh" \\
+  "default"     &   default kernel, currently "tanh" \\
+  "tanh"        &   Hyperbolic tangent \\
+  "sinc2"       &   Square sinc \\
+  "lanczos"     &   Lanczos2 kernel \\
+  "hamming"     &   Hamming kernel \\
+  "hann"        &   Hann kernel
+  \end{tabular}
+ 
+  The returned array of doubles is ready of use in the various re-sampling
+  functions in this module. It must be deallocated using free().
+ */
+/*--------------------------------------------------------------------------*/
+
+
+double   *
+sinfo_new_generate_interpolation_kernel(const char * kernel_type) ;
+
+
+/*-------------------------------------------------------------------------*/
+/**
+  @name     sinfo_warp_image_generic
+  @memo     Warp an image according to a polynomial transformation.
+  @param    image_in        Image to warp.
+  @param    kernel_type     Interpolation kernel to use.
+  @param    poly_u          Polynomial transform in U.
+  @param    poly_v          Polynomial transform in V.
+  @return   1 newly allocated image.
+  @doc
+ 
+  Warp an image according to a polynomial transform. Provide two
+  polynomials (see poly2d.h for polynomials in this library) Pu and Pv such
+  as:
+ 
+  \begin{verbatim}
+  x = sinfo_poly2d_compute(Pu, u, v)
+  y = sinfo_poly2d_compute(Pv, u, v)
+  \end{verbatim}
+ 
+  Attention! The polynomials define a reverse transform. (u,v) are
+  coordinates in the warped image and (x,y) are coordinates in the original
+  image. The transform you provide is used to compute from the warped
+  image, which pixels contributed in the original image.
+ 
+  The output image will have strictly the same size as in the input image.
+  Beware that for extreme transformations, this might lead to blank images
+  as result.
+ 
+  See the function sinfo_generate_interpolation_kernel() for possible kernel
+  types. If you want to use a default kernel, provide NULL for kernel type.
+ 
+  The returned image is a newly allocated objet, use cpl_image_delete() to
+  deallocate it.
+ 
+ */
+/*--------------------------------------------------------------------------*/
+
+
+cpl_image *
+sinfo_new_warp_image_generic(
+    cpl_image       *    image_in,
+    char        *    kernel_type,
+    cpl_polynomial  *    poly_u,
+    cpl_polynomial  *    poly_v
+) ;
+
+
+/*-------------------------------------------------------------------------*/
+/**
+  @name     sinfo_new_generate_tanh_kernel
+  @memo     Generate a hyperbolic tangent kernel.
+  @param    steep   Steepness of the hyperbolic tangent parts.
+  @return   1 pointer to a newly allocated array of doubles.
+  @doc
+ 
+  The following function builds up a good approximation of a box filter. It
+  is built from a product of hyperbolic tangents. It has the following
+  properties:
+ 
+  \begin{itemize}
+  \item It converges very quickly towards +/- 1.
+  \item The converging transition is very sharp.
+  \item It is infinitely differentiable everywhere (i.e. smooth).
+  \item The transition sharpness is scalable.
+  \end{itemize}
+ 
+  The returned array must be deallocated using free().
+ */
+/*--------------------------------------------------------------------------*/
+
+double * sinfo_new_generate_tanh_kernel(double steep) ;
+
+
+/*-------------------------------------------------------------------------*/
+/**
+  @name     sinfo_new_show_interpolation_kernel
+  @memo     Print out an interpolation kernel values on stdout.
+  @param    kernel_name     Name of the kernel to print out.
+  @return   void
+  @doc
+ 
+  Takes in input a kernel name, generates the corresponding kernel and
+  prints it out on stdout, then discards the generated kernel.
+ 
+  For debugging purposes mostly.
+ */
+/*--------------------------------------------------------------------------*/ 
+
+void sinfo_new_show_interpolation_kernel(char * kernel_name) ;
+
+
+#endif
diff --git a/sinfoni/sinfo_new_slit_pos.c b/sinfoni/sinfo_new_slit_pos.c
new file mode 100644
index 0000000..b822278
--- /dev/null
+++ b/sinfoni/sinfo_new_slit_pos.c
@@ -0,0 +1,727 @@
+/*----------------------------------------------------------------------------
+ 
+   File name    :       sinfo_new_slit_pos.c
+   Author       :    A. Modigliani
+   Created on   :    Sep 17, 2003
+   Description  : 
+
+ ---------------------------------------------------------------------------*/
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+/*----------------------------------------------------------------------------
+                                Includes
+ ---------------------------------------------------------------------------*/
+#include "sinfo_new_slit_pos.h"
+#include "sinfo_pro_save.h"
+#include "sinfo_pro_types.h"
+#include "sinfo_wavecal_ini_by_cpl.h"
+#include "sinfo_wcal_functions.h"
+#include "sinfo_wave_calibration.h"
+#include "sinfo_utilities.h"
+#include "sinfo_utils_wrappers.h"
+#include "sinfo_hidden.h"
+#include "sinfo_error.h"
+#include "sinfo_globals.h"
+
+/*----------------------------------------------------------------------------
+                                Defines
+ ---------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+                             Function Definitions
+ ---------------------------------------------------------------------------*/
+/**@{*/
+/**
+ * @defgroup sinfo_new_slit_pos Slitlets position determination
+ *
+ * TBD
+ */
+
+/*----------------------------------------------------------------------------
+   Function     :       sinfo_new_slit_pos()
+   In           :       ini_file: file name of according .ini file
+   Out          :       integer (0 if it worked, -1 if it doesn't) 
+   Job          :
+
+
+  Normal method:
+
+  does the wavelength calibration and the fitting of the slitlet sinfo_edge 
+  positions (ASCII file 32 x 2 values) if wished
+  produces an array of the bcoefs and of the fit parameters if wished and a 
+  wavelength calibration map input is an emission line frame and a line list
+
+
+  o searching for lines by cross sinfo_correlation with a line list
+  o Gaussian fitting of emission lines in each column->positions of the lines->
+    resulting fit parameters can be stored in an ASCII file
+  o Fitting of a polynomial to the line positions for each column
+  o Smoothing: fitting of each polynomial coefficient by another polynomial
+    across the whole frame -> resulting polynomial coefficients can be stored 
+    in an ASCII file.
+  o Wavelength calibration map (micron value for each frame pixel) can be
+    produced by using these coefficients and a cross sinfo_correlation to the
+    original frame
+
+  o The slitlet sinfo_edge positions can be fitted:
+    1) Automatically (not really stable) or by using guess sinfo_edge positions
+    2) By using a Boltzmann or a linear slope function
+
+  Slit method:
+
+  does the wavelength calibration and the fitting of the slitlet sinfo_edge 
+  positions (ASCII file 32 x 2 values) if wished produces a list of the fit 
+  parameters and of the smoothed coefficients if wished and a wavelength 
+  calibration map input is an emission line frame and a line list
+
+  o Does the same as other method but smoothes the found polynomial 
+    coefficients within each slitlet and not over the whole frame.
+
+  o Produces always a wavelength calibration map and does not crosscorrelate.
+
+ ---------------------------------------------------------------------------*/
+
+
+
+int sinfo_new_slit_pos (cpl_parameterlist* config, cpl_frameset* sof)
+{
+    wave_config * cfg =NULL;
+    int check = 0;
+    int lx = 0;
+    int ly = 0;
+    int n_lines=0;
+    int i = 0;
+    int j = 0;
+    int n = 0;
+
+    int sum=0;
+
+    int* n_found_lines=NULL;
+    int* sum_pointer=NULL;
+    int** row_clean=NULL;
+
+    float a=0;
+    float shift=0;
+    float* wave=NULL;
+    float* intens=NULL;
+
+    float** acoefs=NULL;
+    float** wavelength_clean=NULL;
+
+    float** sinfo_slit_pos=NULL;
+ 
+    cpl_image *  map=NULL ;
+    cpl_image * im=NULL ;
+
+    FitParams** par=NULL;
+
+    cpl_table* tbl_wcal=NULL;
+    cpl_table* tbl_spos=NULL;
+
+    char* col_name=NULL;
+    char* tbl_name=NULL;
+
+    char* tbl_line_list_name=NULL;
+    cpl_table* tbl_line_list = NULL;
+    int* status=NULL;
+ 
+    cpl_frameset* raw=NULL;
+
+
+    cpl_table * tbl_fp =NULL;
+    char* col=NULL;
+    cpl_table* qclog_tbl=NULL;
+    char* key_name=NULL;
+    double fwhm_med=0;
+    double fwhm_avg=0;
+    double coef_med=0;
+    double coef_avg=0;
+    int trow=0;
+    qc_wcal* qc=sinfo_qc_wcal_new();
+    /*        -----------------------------------------------------------------
+       1) parse the file names and parameters to the ns_config data 
+          structure cfg
+       -----------------------------------------------------------------
+     */
+
+    sinfo_msg("Parsing cpl input");
+    cfg = sinfo_parse_cpl_input_wave(config,sof,&raw) ;
+    
+    if(cfg!=NULL) {
+       cfg->nslitlets=32;
+       cfg->calibIndicator=1;
+       cfg->wavemapInd=0;
+       cfg->slitposIndicator=1;
+    }
+    if(cpl_error_get_code() != CPL_ERROR_NONE) {
+      sinfo_msg_error((char* ) cpl_error_get_message());
+      sinfo_qc_wcal_delete(&qc);
+      return -1;
+    }
+   
+    if (cfg == NULL)
+    {
+        sinfo_msg_error("could not parse cpl input!\n") ;
+        sinfo_qc_wcal_delete(&qc);
+        return -1 ;
+    }
+    if(sinfo_is_fits_file(cfg->inFrame) != 1) {
+      sinfo_msg_error("Input file %s is not FITS",cfg->inFrame);
+      sinfo_qc_wcal_delete(&qc);
+      return -1;
+    }
+
+
+    if (cfg->slitposIndicator == 1 && cfg->estimateIndicator == 1) {
+      if (sinfo_is_fits_file(cfg->slitposGuessName) != 1) {
+        sinfo_msg_error("slitlet position guess list not given!");
+        sinfo_qc_wcal_delete(&qc);
+        return -1;
+      }
+    }
+
+    if (cfg->calibIndicator == 0 && cfg->wavemapInd == 1) {
+      if (sinfo_is_fits_file(cfg->coeffsName) != 1) {
+        sinfo_msg_error("coefficients list not given!");
+        sinfo_qc_wcal_delete(&qc);
+        return -1;
+      }
+    }
+
+
+    if (cfg->slitposIndicator == 1) {
+      if (cfg->calibIndicator != 1 && cfg->estimateIndicator != 1) {
+       
+        if (sinfo_is_fits_file(cfg->paramsList) != 1) {
+      sinfo_msg_error("parameter list not given!");
+          sinfo_qc_wcal_delete(&qc);
+      return -1;
+    }
+    
+      }
+    }
+
+/*---load the emission line frame---*/
+    im = cpl_image_load(cfg->inFrame,CPL_TYPE_FLOAT,0,0);
+    if (im == NULL) {
+      sinfo_msg_error("could not load image\n");
+      sinfo_qc_wcal_delete(&qc);
+      return -1;
+    }
+
+
+    lx = cpl_image_get_size_x(im);
+    ly = cpl_image_get_size_y(im);
+
+
+
+if (cfg->calibIndicator == 1 || cfg->wavemapInd == 1) {
+    /*---open the line list and read the number of lines---*/
+
+    if(cpl_error_get_code() != CPL_ERROR_NONE) {
+      sinfo_msg_error((char* ) cpl_error_get_message());
+      sinfo_qc_wcal_delete(&qc);
+      return -1;
+    }
+
+    tbl_line_list_name=cfg->lineList;
+    tbl_line_list = cpl_table_load(tbl_line_list_name,1,0);
+    if(cpl_error_get_code() != CPL_ERROR_NONE) {
+      sinfo_msg_error((char* ) cpl_error_get_message());
+      sinfo_qc_wcal_delete(&qc);
+      return -1;
+    }
+    n = cpl_table_get_nrow(tbl_line_list);
+    n_lines = n;
+    if(cpl_error_get_code() != CPL_ERROR_NONE) {
+      sinfo_msg_error((char* ) cpl_error_get_message());
+      sinfo_qc_wcal_delete(&qc);
+      return -1;
+    }
+
+    /* THIS ORIGINATES A MEMORY LEAK 
+    wave   = sinfo_new_floatarray (n);
+    intens = sinfo_new_floatarray (n);
+    if (wave == NULL || intens == NULL) {
+      sinfo_msg_error("could not allocate memory for the line list values\n" );
+      sinfo_qc_wcal_delete(&qc);
+      return -1;
+    }
+    */
+
+    wave   = cpl_table_get_data_float(tbl_line_list,"wave");
+    if(cpl_error_get_code() != CPL_ERROR_NONE) {
+      sinfo_msg_error((char* ) cpl_error_get_message());
+      sinfo_qc_wcal_delete(&qc);
+      return -1;
+    }
+
+    intens = cpl_table_get_data_float(tbl_line_list,"int");
+    if(cpl_error_get_code() != CPL_ERROR_NONE) {
+      sinfo_msg_error((char* ) cpl_error_get_message());
+      sinfo_qc_wcal_delete(&qc);
+      return -1;
+    }
+    
+}
+
+
+
+/*
+ ----------------------------------------------------------------------
+ ---------------------------FINDLINES----------------------------------
+ ----------------------------------------------------------------------
+ */
+
+
+/*if not yet done:
+  do the wavelength calibration, that means: 
+  find the dispersion relation and parameterize its coefficients
+ */
+/*
+ sinfo_msg("guessBeginWave=%g",cfg->guessBeginWavelength);
+ sinfo_msg("guessDisp1=%g",cfg->guessDispersion1);
+ sinfo_msg("guessDisp2=%g",cfg->guessDispersion2);
+*/
+if (cfg->calibIndicator == 1 && cfg->wavemapInd == 0) {
+   sinfo_msg("Findlines");
+   acoefs  = sinfo_new_2Dfloatarray(cfg->nrDispCoefficients, lx);
+   /*allocate memory*/
+   n_found_lines    = sinfo_new_intarray(lx); 
+   row_clean        = sinfo_new_2Dintarray(lx, n_lines);
+   wavelength_clean = sinfo_new_2Dfloatarray(lx, n_lines);
+   sum_pointer      = sinfo_new_intarray(1) ;
+   /*find the emission lines in each image column*/
+   sinfo_new_intarray_set_value(sum_pointer, 0, 0);
+   check = sinfo_new_find_lines(im, wave, intens, n_lines, row_clean, 
+                      wavelength_clean, cfg->guessBeginWavelength, 
+             cfg->guessDispersion1, cfg->guessDispersion2,
+                      cfg->mindiff, cfg->halfWidth, 
+                      n_found_lines, cfg->sigma, sum_pointer );
+   if (-1 == check) {
+           sinfo_msg_error("sinfo_findLines failed!\n");
+           sinfo_qc_wcal_delete(&qc);
+           return -1;
+   }
+      
+
+/*---------------------------------------------------------------------
+ *-----------------------WAVE_CALIB-------------------------------------
+ *---------------------------------------------------------------------
+ */
+
+     
+   sinfo_msg("Wave Calibration");
+   sum = sinfo_new_intarray_get_value(sum_pointer,0);
+   /* allocate memory for the fit parameters */
+   par = sinfo_new_fit_params( sum );
+   if (par == NULL) {
+        sinfo_msg_error("sinfo_newFitParams failed!\n");
+        sinfo_qc_wcal_delete(&qc);
+        return -1;
+   }
+
+  /*
+   fit each line, make a polynomial fit and fit the resulting fit 
+   coefficients across the columns of the slitlet
+   */
+   sinfo_slit_pos = sinfo_new_2Dfloatarray(32,2);
+
+   map = sinfo_new_spred_wave_cal(im, 
+                 par, 
+                 acoefs, 
+                 cfg->nslitlets, 
+                 row_clean, 
+                 wavelength_clean, 
+                 n_found_lines, 
+                 cfg->guessDispersion1, 
+                 cfg->halfWidth, 
+                 cfg->minAmplitude, 
+                 cfg->maxResidual, 
+                 cfg->fwhm, 
+                 cfg->nrDispCoefficients, 
+                 cfg->nrCoefCoefficients, 
+                 cfg->sigmaFactor, 
+                 cfg->pixeldist, 
+                 cfg->pixel_tolerance,
+                 sinfo_slit_pos);
+
+ 
+   if (map == NULL ) { 
+          sinfo_msg_error("sinfo_wave_cal failed!\n");
+          sinfo_qc_wcal_delete(&qc);
+      return -1;
+   }
+   sinfo_msg("Check line positions");
+  
+   shift = sinfo_new_check_line_positions (im, acoefs, 
+                                          cfg->nrDispCoefficients,
+                                          cfg->guessDispersion1, par);
+   if (FLAG == shift){ 
+      sinfo_msg_error("checkForLinePositions failed!\n");
+   }
+
+
+    sinfo_det_ncounts(raw, cfg->qc_thresh_max,qc);
+    qclog_tbl = sinfo_qclog_init();
+    ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC WAVE ALL",
+                  n_lines,"Number of found lines","%d"));
+
+    ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC WAVE NPIXSAT",
+                  qc->nsat,"Number of saturated pixels","%d"));
+
+    ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC WAVE MAXFLUX",
+                qc->max_di,"Max int off-lamp subracted frm","%g"));
+
+   if(-1 == sinfo_pro_save_ima(map,raw,sof,cfg->outName,
+         PRO_WAVE_MAP,qclog_tbl,cpl_func,config)) {
+         sinfo_msg_error("cannot save ima %s", cfg->outName);
+    }
+   sinfo_free_table(&qclog_tbl);
+ 
+ 
+   /*
+    #store the resulting polynomial fit coefficients in an 
+     ASCII file if wished
+    */
+
+   if (cfg->writeCoeffsInd == 1) {
+         col_name = (char*) cpl_calloc(MAX_NAME_SIZE,sizeof(char*));
+         tbl_name = (char*) cpl_calloc(MAX_NAME_SIZE,sizeof(char*));
+         tbl_wcal = cpl_table_new(lx);
+         for (i=0; i< cfg->nrDispCoefficients; i++) {
+             snprintf(col_name,MAX_NAME_SIZE-1,"%s%d","coeff",i);
+             cpl_table_new_column(tbl_wcal,col_name, CPL_TYPE_DOUBLE);
+     }
+
+
+         qclog_tbl = sinfo_qclog_init();
+         key_name  = cpl_calloc(FILE_NAME_SZ,sizeof(char));
+         ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC WAVE ALL",
+               n_lines,"Number of found lines","%d"));
+
+
+
+         for (j=0; j< lx; j++) { 
+        for (i=0; i< cfg->nrDispCoefficients; i++) {
+                snprintf(col_name,MAX_NAME_SIZE-1,"%s%d","coeff",i);
+            a = sinfo_new_array2D_get_value(acoefs, i, j);
+        /* fprintf(acoefs_file, "%15.13g ", a) ; */
+                cpl_table_set_double(tbl_wcal,col_name,j,a);
+        }
+
+
+     }
+
+
+     for (i=0; i< cfg->nrDispCoefficients; i++) {
+            snprintf(col_name,MAX_NAME_SIZE-1,"%s%d","coeff",i);
+            coef_avg=cpl_table_get_column_mean(tbl_wcal,col_name);
+            coef_med=cpl_table_get_column_median(tbl_wcal,col_name);
+
+            trow=1+i;
+            snprintf(key_name,MAX_NAME_SIZE-1,"%s%d%s","QC COEF",i," AVG");
+            ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,key_name,coef_avg,
+                         "Average wavecal Coef","%g"));
+
+            trow=1+i+cfg->nrDispCoefficients;
+            snprintf(key_name,MAX_NAME_SIZE-1,"%s%d%s","QC COEF",i," MED");
+            ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,key_name,coef_med,
+                         "Median wavecal Coef","%g"));
+
+     }
+
+     /*
+         fclose(acoefs_file);
+     */
+         strcpy(tbl_name,cfg->coeffsName);
+
+         if(-1 == sinfo_pro_save_tbl(tbl_wcal,raw,sof,tbl_name,
+             PRO_WAVE_COEF_SLIT,qclog_tbl,cpl_func,config)) {
+         sinfo_msg_error("cannot save tbl %s", tbl_name);
+         }
+         sinfo_free_table(&tbl_wcal);
+         sinfo_free_table(&qclog_tbl);
+         cpl_free(key_name);
+
+         cpl_free(col_name);
+         cpl_free(tbl_name);
+
+   }
+
+
+   /*
+    #store the resulting Gaussian fit parameters in an ASCII file if wished
+   */
+   if (cfg->writeParInd == 1) {
+
+
+      sinfo_new_dump_fit_params_to_ascii(par,WAVECAL_FIT_PARAMS_OUT_FILEASCII);
+ 
+      if ( NULL == par )
+      {
+         sinfo_msg_error ("no fit parameters available!") ;
+         sinfo_qc_wcal_delete(&qc);
+         return -1;
+      }
+
+      if ( NULL == cfg->paramsList )
+      {
+         sinfo_msg_error ("no filename available!") ;
+         sinfo_qc_wcal_delete(&qc);
+         return -1;
+      }
+
+      tbl_fp = cpl_table_new(par[0] -> n_params);
+      cpl_table_new_column(tbl_fp,"n_params", CPL_TYPE_INT);
+      cpl_table_new_column(tbl_fp,"column", CPL_TYPE_INT);
+      cpl_table_new_column(tbl_fp,"line", CPL_TYPE_INT);
+      col = (char*) cpl_calloc(MAX_NAME_SIZE,sizeof(char*));
+
+      for(j=0;j<4;j++) {
+         snprintf(col,MAX_NAME_SIZE-1,"%s%d","fpar",j);
+         cpl_table_new_column(tbl_fp,col, CPL_TYPE_DOUBLE);
+         snprintf(col,MAX_NAME_SIZE-1,"%s%d","dpar",j);
+         cpl_table_new_column(tbl_fp,col, CPL_TYPE_DOUBLE);
+      }
+
+
+
+    qclog_tbl = sinfo_qclog_init();
+    ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC NLINES",n_lines,
+                  "Number of Found lines","%d"));
+
+      for ( i = 0 ; i < par[0] -> n_params ; i++ )
+      {
+         cpl_table_set_int(tbl_fp,"n_params",i,par[i]->n_params);
+         cpl_table_set_int(tbl_fp,"column",i,par[i]->column);
+         cpl_table_set_int(tbl_fp,"line",i,par[i]->line);
+
+
+         for(j=0;j<4;j++) {
+        snprintf(col,MAX_NAME_SIZE-1,"%s%d","fpar",j);
+            cpl_table_set_double(tbl_fp,col,i,par[i]->fit_par[j]);
+        snprintf(col,MAX_NAME_SIZE-1,"%s%d","dpar",j);
+            cpl_table_set_double(tbl_fp,col,i,par[i]->derv_par[j]);
+     }
+      }
+
+      fwhm_avg = cpl_table_get_column_mean(tbl_fp,"fpar1");
+      fwhm_med = cpl_table_get_column_median(tbl_fp,"fpar1");
+      ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC FWHM MED",fwhm_med,
+                       "Median FWHM of found lines","%f"));
+
+      ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC FWHM AVG",fwhm_avg,
+                       "Average FWHM of found lines","%f"));
+
+
+      if(-1 == sinfo_pro_save_tbl(tbl_fp,raw,sof,cfg->paramsList,
+         PRO_WAVE_PAR_LIST,qclog_tbl,cpl_func,config)) {
+         sinfo_msg_error("cannot save tbl %s", cfg->paramsList);
+      }
+      sinfo_free_table(&qclog_tbl);
+
+      sinfo_free_table(&tbl_fp) ;
+      cpl_free(col);
+
+   }
+   /* free memory */
+   sinfo_new_destroy_2Dfloatarray ( &wavelength_clean, lx );
+   sinfo_new_destroy_2Dintarray (&row_clean, lx);
+   sinfo_new_destroy_intarray(&n_found_lines );
+   sinfo_new_destroy_intarray(&sum_pointer );
+   sinfo_new_destroy_2Dfloatarray ( &acoefs, cfg->nrDispCoefficients );
+
+/*----------------------------------------------------------------------
+ *-------------------WAVEMAP--------------------------------------------
+ *----------------------------------------------------------------------
+ */
+
+/*
+#---now do the cross sinfo_correlation and produce a wavelength map---
+ */
+} else if (cfg->wavemapInd == 1 && cfg->calibIndicator == 0) { 
+  sinfo_msg("Wavemap");
+  acoefs = sinfo_new_2Dfloatarray ( cfg->nrDispCoefficients, lx);
+   /* #read the parameterized dispersion relation */
+
+   tbl_name = (char*) cpl_calloc(MAX_NAME_SIZE,sizeof(char*));
+   col_name = (char*) cpl_calloc(MAX_NAME_SIZE,sizeof(char*));
+   strcpy(tbl_name,cfg->coeffsName);
+   tbl_wcal = cpl_table_load(tbl_name,1,0);
+    if(cpl_error_get_code() != CPL_ERROR_NONE) {
+      sinfo_msg("cannot load table %s",tbl_name);
+      sinfo_msg_error((char* ) cpl_error_get_message());
+      sinfo_qc_wcal_delete(&qc);
+      return -1;
+    }
+   for (i =0; i < lx; i++) {
+      for (j = 0; j< cfg->nrDispCoefficients; j++) {
+            snprintf(col_name,MAX_NAME_SIZE-1,"%s%d","coeff",j);
+            acoefs[j][i]=cpl_table_get_double(tbl_wcal,col_name,i,status);
+      }
+   }
+    if(cpl_error_get_code() != CPL_ERROR_NONE) {
+      sinfo_msg("cannot read table %s",tbl_name);
+      sinfo_msg_error((char* ) cpl_error_get_message());
+      sinfo_qc_wcal_delete(&qc);
+      return -1;
+    }
+    cpl_free(col_name);
+    cpl_free(tbl_name);
+    sinfo_free_table(&tbl_wcal);
+
+    map = sinfo_new_create_shifted_slit_wavemap2 ( im, 
+                                          acoefs, 
+                                          cfg->nrDispCoefficients,
+                                          wave, 
+                                          intens, 
+                                          n_lines, 
+                                          cfg->magFactor, 
+                      cfg->guessDispersion1, 
+                                          cfg->pixeldist );
+   if (map == NULL) {
+           sinfo_msg_error("sinfo_createShiftedSlitWavemap2 failed!\n");
+           sinfo_qc_wcal_delete(&qc);
+           return -1;
+   }
+
+   par = sinfo_new_fit_params(15*n_lines);
+   sinfo_msg("Check shifts");
+
+   shift = sinfo_new_check_correlated_line_positions ( im, acoefs, 
+                                           cfg->nrDispCoefficients, 
+                                           wave, 
+                                           intens, 
+                                           n_lines, 
+                                           cfg->fwhm, 
+                                           cfg->halfWidth, 
+                                           cfg->minAmplitude, 
+                                           cfg->guessDispersion1, 
+                                           par );
+
+
+   if (FLAG == shift){
+      sinfo_msg_error("sinfo_checkCorrelatedLinePositions failed!\n");
+   }
+
+
+    sinfo_det_ncounts(raw, cfg->qc_thresh_max,qc);
+    qclog_tbl = sinfo_qclog_init();
+    ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC NLINES",n_lines,
+                  "Number of found lines","%d"));
+
+
+
+    fwhm_avg = cpl_table_get_column_mean(tbl_fp,"fpar1");
+    fwhm_med = cpl_table_get_column_median(tbl_fp,"fpar1");
+
+    ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC FWHM MED",fwhm_med,
+                     "Median FWHM of found lines","%f"));
+    ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC FWHM AVG",fwhm_avg,
+                     "Average FWHM of found lines","%f"));
+
+
+    if(-1 == sinfo_pro_save_ima(map,raw,sof,cfg->outName,
+         PRO_WAVE_MAP,qclog_tbl,cpl_func,config)) {
+         sinfo_msg_error("cannot save ima %s", cfg->outName);
+    }
+    sinfo_free_table(&qclog_tbl);
+
+
+   /* # ---free memory--- */
+   sinfo_new_destroy_2Dfloatarray ( &acoefs, cfg->nrDispCoefficients );
+   /* To fix a memory bug we comment the following. But check! */
+
+} else if (cfg->wavemapInd == 1 && cfg->calibIndicator == 1) {
+   sinfo_msg_error("give either wavemapIndicator = yes and calibIndicator = no \
+                or wavemapIndicator = no and calibIndicator = yes") ;
+   sinfo_qc_wcal_delete(&qc);
+   return -1;
+}
+
+
+/*-------------------------------------------------------------------
+ *-------------------SLITFITS----------------------------------------
+ *-------------------------------------------------------------------
+ #--fit the slitlet sinfo_edge positions if desired--
+ */
+if (cfg->slitposIndicator == 1) {
+  sinfo_msg("fit the slitlet sinfo_edge positions");
+
+
+    /* #store the resulting sitlet positions in an TFITS table */
+   tbl_name = (char*) cpl_calloc(MAX_NAME_SIZE,sizeof(char*));
+   tbl_spos = cpl_table_new(32);
+   cpl_table_new_column(tbl_spos,"pos1", CPL_TYPE_DOUBLE);
+   cpl_table_new_column(tbl_spos,"pos2", CPL_TYPE_DOUBLE);
+   cpl_table_set_column_format(tbl_spos,"pos1", "15.9f");
+   cpl_table_set_column_format(tbl_spos,"pos2", "15.9f");
+
+    for (i =0; i< 32; i++) {
+     /*
+     fprintf( slitpos_file, "%15.9f %15.9f \n",
+      sinfo_new_array2D_get_value(sinfo_slit_pos,i,0),
+                        sinfo_new_array2D_get_value(sinfo_slit_pos,i,1));
+     */
+      cpl_table_set_double(tbl_spos,"pos1",i,
+                           sinfo_new_array2D_get_value(sinfo_slit_pos,i,0));
+      cpl_table_set_double(tbl_spos,"pos2",i,
+                           sinfo_new_array2D_get_value(sinfo_slit_pos,i,1));
+     
+   }
+    /* strcpy(tbl_name,cfg->slitposName); */
+    strcpy(tbl_name,"out_guess_slit_pos.fits");
+    if(-1 == sinfo_pro_save_tbl(tbl_spos,raw,sof,tbl_name,
+         PRO_SLIT_POS,NULL,cpl_func,config)) {
+         sinfo_msg_error("cannot save tbl %s", tbl_name);
+    }
+    sinfo_free_table(&tbl_spos);
+    cpl_free(tbl_name);
+   /*# free memory*/
+   sinfo_new_destroy_2Dfloatarray ( &sinfo_slit_pos, 32 );
+   
+   
+}
+
+/* #-----free the rest memory--*/
+if ( (cfg->slitposIndicator == 1 && cfg->estimateIndicator != 1) || 
+     (cfg->calibIndicator == 1)  || (cfg->wavemapInd == 1) ){
+     sinfo_new_destroy_fit_params(&par);
+}
+sinfo_free_image( &im );
+sinfo_free_image( &map );
+sinfo_wavecal_free(&cfg);
+sinfo_qc_wcal_delete(&qc);
+
+ return 0;
+
+ cleanup:
+ return -1;
+
+
+
+}
+
+/**@}*/
+
diff --git a/sinfoni/sinfo_new_slit_pos.h b/sinfoni/sinfo_new_slit_pos.h
new file mode 100644
index 0000000..28dbc68
--- /dev/null
+++ b/sinfoni/sinfo_new_slit_pos.h
@@ -0,0 +1,130 @@
+#ifndef SINFO_NEW_SLIT_POS_H
+#define SINFO_NEW_SLIT_POS_H
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*****************************************************************************
+* E.S.O. - VLT project
+*
+* "@(#) $Id: sinfo_new_slit_pos.h,v 1.5 2007/06/06 07:10:45 amodigli Exp $"
+*
+* who       when      what
+* --------  --------  ----------------------------------------------
+* amodigli  17/09/03  created
+*/
+
+/************************************************************************
+ * sinfo_new_slit_pos.h
+
+  Normal method:
+
+  does the wavelength calibration and the fitting of the slitlet sinfo_edge 
+  positions (ASCII file 32 x 2 values) if wished
+  produces an array of the bcoefs and of the fit parameters if wished and a 
+  wavelength calibration map input is an emission line frame and a line list
+
+  o searching for lines by cross sinfo_correlation with a line list
+  o Gaussian fitting of emission lines in each column->positions of the lines->
+    resulting fit parameters can be stored in an ASCII file
+  o Fitting of a polynomial to the line positions for each column
+  o Smoothing: fitting of each polynomial coefficient by another polynomial
+    across the whole frame -> resulting polynomial coefficients can be stored 
+    in an ASCII file.
+  o Wavelength calibration map (micron value for each frame pixel) can be
+    produced by using these coefficients and a cross sinfo_correlation to the
+    original frame
+
+  o The slitlet sinfo_edge positions can be fitted:
+    1) Automatically (not really stable) or by using guess sinfo_edge positions
+    2) By using a Boltzmann or a linear slope function
+
+
+  Slit method:
+
+  does the wavelength calibration and the fitting of the slitlet sinfo_edge 
+  positions (ASCII file 32 x 2 values) if wished produces a list of the fit 
+  parameters and of the smoothed coefficients if wished and a wavelength 
+  calibration map input is an emission line frame and a line list
+
+  o Does the same as other method but smoothes the found polynomial 
+    coefficients within each slitlet and not over the whole frame.
+
+  o Produces always a wavelength calibration map and does not crosscorrelate.
+
+ *----------------------------------------------------------------------
+ */
+
+/*
+ * header files
+ */
+#include <cpl.h>   
+#include "sinfo_msg.h"
+
+
+/*----------------------------------------------------------------------------
+ *                        Function ANSI C prototypes
+ *--------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+   Function     :       sinfo_new_slit_pos()
+   In           :       ini_file: file name of according .ini file
+   Out          :       integer (0 if it worked, -1 if it doesn't) 
+   Job          :
+
+
+  Normal method:
+
+  does the wavelength calibration and the fitting of the slitlet sinfo_edge 
+  positions (ASCII file 32 x 2 values) if wished
+  produces an array of the bcoefs and of the fit parameters if wished and a 
+  wavelength calibration map input is an emission line frame and a line list
+
+
+  o searching for lines by cross sinfo_correlation with a line list
+  o Gaussian fitting of emission lines in each column->positions of the lines->
+    resulting fit parameters can be stored in an ASCII file
+  o Fitting of a polynomial to the line positions for each column
+  o Smoothing: fitting of each polynomial coefficient by another polynomial
+    across the whole frame -> resulting polynomial coefficients can be stored 
+    in an ASCII file.
+  o Wavelength calibration map (micron value for each frame pixel) can be
+    produced by using these coefficients and a cross sinfo_correlation to the
+    original frame
+
+  o The slitlet sinfo_edge positions can be fitted:
+    1) Automatically (not really stable) or by using guess sinfo_edge positions
+    2) By using a Boltzmann or a linear slope function
+
+  Slit method:
+
+  does the wavelength calibration and the fitting of the slitlet sinfo_edge 
+  positions (ASCII file 32 x 2 values) if wished produces a list of the fit 
+  parameters and of the smoothed coefficients if wished and a wavelength 
+  calibration map input is an emission line frame and a line list
+
+  o Does the same as other method but smoothes the found polynomial 
+    coefficients within each slitlet and not over the whole frame.
+
+  o Produces always a wavelength calibration map and does not crosscorrelate.
+ ---------------------------------------------------------------------------*/
+int sinfo_new_slit_pos (cpl_parameterlist* config, cpl_frameset* sof) ;
+
+
+#endif 
+
+/*--------------------------------------------------------------------------*/
diff --git a/sinfoni/sinfo_new_stdstar.c b/sinfoni/sinfo_new_stdstar.c
new file mode 100644
index 0000000..7f1f281
--- /dev/null
+++ b/sinfoni/sinfo_new_stdstar.c
@@ -0,0 +1,660 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+
+   File name    :       sinfo_new_stdstar.c
+   Author       :    J. Schreiber
+   Created on   :    December 3, 2003
+   Description  :    this routine doess the optimal extraction of a spectrum
+                        of an already reduced data cube of a standard star
+                        observation. Additionally, a conversion factor from
+                        mag to counts/sec can be determined if the magnitude
+                        of the standard star is known.
+                        This is done for a number of jittered data cubes and
+                        the results are averaged by rejecting the extreme
+                        values
+
+ ---------------------------------------------------------------------------*/
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+/*----------------------------------------------------------------------------
+                                Includes
+ ---------------------------------------------------------------------------*/
+#include <math.h>
+
+//Used only for sinfo_propertylist_has
+#include <irplib_stdstar.h>
+#include <sinfo_cpl_size.h>
+#include "irplib_utils.h"
+#include "sinfo_dfs.h"
+#include "sinfo_tpl_utils.h"
+
+#include "sinfo_new_stdstar.h"
+#include "sinfo_standstar_ini_by_cpl.h"
+#include "sinfo_pro_save.h"
+#include "sinfo_pfits.h"
+#include "sinfo_utilities_scired.h"
+#include "sinfo_spectrum_ops.h"
+#include "sinfo_hidden.h"
+#include "sinfo_functions.h"
+#include "sinfo_utl_efficiency.h"
+#include "sinfo_error.h"
+#include "sinfo_utils_wrappers.h"
+/*----------------------------------------------------------------------------
+                                Defines
+ ---------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+                             Function Definitions
+ ---------------------------------------------------------------------------*/
+/* temporally commented out as not yet used
+static int
+sinfo_compute_efficiency(cpl_frameset* sof,
+                              const char* name,
+			      standstar_config ** cfg,
+			      cpl_imagelist  * cube,
+			 cpl_table** tbl_spectrum);
+
+*/
+
+/**@{*/
+/**
+ * @addtogroup sinfo_rec_jitter telluric standard data reduction
+ *
+ * TBD
+ */
+
+/*----------------------------------------------------------------------------
+   Function     :       sinfo_stdstar()
+   In           :       ini_file: file name of according .ini file
+   Out          :       integer (0 if it worked, -1 if it doesn't)
+   Job          :     this routine carries through the data cube creation of an
+                        object science observation using object-sky nodding
+                        and jittering. This script expects jittered frames that
+                were already sky-subtracted
+                        averaged, flatfielded, spectral tilt corrected and
+            interleaved if necessary
+ ---------------------------------------------------------------------------*/
+int
+sinfo_new_stdstar(const char* plugin_id,
+                  cpl_parameterlist* config,
+                  cpl_frameset* sof,cpl_frameset* ref_set)
+{
+
+  cpl_errorstate clean_state = cpl_errorstate_get();
+    standstar_config * cfg=NULL ;
+    cpl_imagelist  * cube=NULL ;
+
+    cpl_imagelist  * list_object=NULL ;
+    cpl_image ** spectrum=NULL ;
+    cpl_image * img_spct=NULL ;
+
+
+
+    cpl_frameset* raw=NULL;
+    cpl_frame* frame=NULL;
+    cpl_image* std_med_ima=NULL;
+    cpl_image* std_med_dup=NULL;
+
+    cpl_table* qclog_tbl=NULL;
+    cpl_table* tbl_spectrum=NULL;
+    cpl_propertylist* plist=NULL;
+    //char band[FILE_NAME_SZ];
+
+    char * name=NULL ;
+    int fra=0;
+    float exptime=0 ;
+    double convfactor=0;
+    double cleanfactor=0;
+    float* factor=NULL;
+
+    char std_med_filename[MAX_NAME_SIZE];
+    char std_cub_filename[MAX_NAME_SIZE];
+
+    double max_ima_cx=0;
+    double max_ima_cy=0;
+    cpl_size max_ima_x=0;
+    cpl_size max_ima_y=0;
+    double norm=0;
+    double xcen=0;
+    double ycen=0;
+    double sig_x=0;
+    double sig_y=0;
+    double fwhm_x=0;
+    double fwhm_y=0;
+    double disp=0;
+    double dispersion=0;
+    int i=0;
+    int wllx=0;
+    int wlly=0;
+    int wurx=0;
+    int wury=0;
+    int psf_sz=40;
+    int qc_info=0;
+    int ima_szx=0;
+    int ima_szy=0;
+    int check1=0;
+    int check2=0;
+    int check3=0;
+    int check4=0;
+    double xshift=0;
+    double yshift=0;
+
+    float cenpix = 0;
+    float cenLambda = 0;
+
+    int no=0;
+    double lo_cut=0.;
+    double hi_cut=0.;
+
+    const char* stdstars=NULL;
+    const char* sed=NULL;
+    cpl_frame* frm_sci=NULL;
+    cpl_frame* frm_atmext=NULL;
+    cpl_frame* frm_std_cat=NULL;
+    cpl_table* tot_eff=NULL;
+    double fpar[7];
+    double dpar[7];
+    int mpar[7];
+    int do_compute_eff=0;
+    cpl_parameter* p=NULL;
+
+
+    //For new way to compute efficiency
+    //char band[80];
+    //const char  *   seds_file=NULL;
+    //const char  *   filter=NULL;
+    //cpl_table* tbl_eff=NULL;
+    /*
+       parse the file names and parameters to the cube_config
+       data structure cfg
+     */
+
+    /* sinfo_msg("Parse cpl input"); */
+     check_nomsg(raw=cpl_frameset_new());
+
+    cknull(cfg=sinfo_parse_cpl_input_standstar(config,sof,&raw),
+       "could not parse cpl input!") ;
+
+ 
+    cknull_nomsg(p = cpl_parameterlist_find(config,
+				     "sinfoni.std_star.compute_eff"));
+ 
+    check_nomsg(do_compute_eff = cpl_parameter_get_bool(p));
+     cknull(list_object = cpl_imagelist_new (),
+       "could not allocate memory");
+
+
+    sed = sinfo_extract_filename(sof, SINFO_CALIB_SED) ;
+    stdstars = sinfo_extract_filename(sof, SINFO_CALIB_STDSTARS) ;
+
+
+    if (cfg->convInd == 1) {
+      factor = sinfo_new_floatarray(cfg->nframes);
+    }
+
+    if(NULL != cpl_frameset_find(sof,PRO_COADD_STD)) {
+      frame = cpl_frameset_find(sof,PRO_COADD_STD);
+      strcpy(std_cub_filename,cpl_frame_get_filename(frame));
+    } else if(NULL != cpl_frameset_find(sof,PRO_COADD_PSF)) {
+      frame = cpl_frameset_find(sof,PRO_COADD_PSF);
+      strcpy(std_cub_filename,cpl_frame_get_filename(frame));
+    } else if(NULL != cpl_frameset_find(sof,PRO_COADD_OBJ)) {
+      frame = cpl_frameset_find(sof,PRO_COADD_OBJ);
+      strcpy(std_cub_filename,cpl_frame_get_filename(frame));
+    } else if(NULL != cpl_frameset_find(sof,PRO_COADD_PUPIL)) {
+      frame = cpl_frameset_find(sof,PRO_COADD_PUPIL);
+      strcpy(std_cub_filename,cpl_frame_get_filename(frame));
+    } else {
+      sinfo_msg_error("Frame %s, %s, %s or %s not found! Exit!",
+                       PRO_COADD_STD,PRO_COADD_PSF,
+                       PRO_COADD_OBJ,PRO_COADD_PUPIL );
+      goto cleanup;
+    }
+
+
+    cknull(plist = cpl_propertylist_load(std_cub_filename, 0),
+      "getting header from reference ima frame %s",std_cub_filename);
+
+    cenpix = sinfo_pfits_get_crpix3(plist);
+    cenLambda = sinfo_pfits_get_crval3(plist);
+    dispersion = sinfo_pfits_get_cdelt3(plist);
+
+
+    if (sinfo_propertylist_has(plist, KEY_NAME_CDELT3)) {
+      disp=cpl_propertylist_get_double(plist, KEY_NAME_CDELT3);
+    } else {
+      sinfo_msg_warning("Keyword %s not found.",KEY_NAME_CDELT3);
+    }
+
+
+    sinfo_free_propertylist(&plist) ;
+
+    /* we find automatiocally extraction parameters */
+
+
+    if(NULL != cpl_frameset_find(sof,PRO_MED_COADD_STD)) {
+      frame = cpl_frameset_find(sof,PRO_MED_COADD_STD);
+      strcpy(std_med_filename,cpl_frame_get_filename(frame));
+      check_nomsg(std_med_ima=cpl_image_load(std_med_filename,
+                                             CPL_TYPE_FLOAT,0,0));
+    } else if(NULL != cpl_frameset_find(sof,PRO_OBS_STD)) {
+      check_nomsg(frame = cpl_frameset_find(sof,PRO_OBS_STD));
+      strcpy(std_cub_filename,cpl_frame_get_filename(frame));
+      check_nomsg(cube = cpl_imagelist_load(std_cub_filename,
+                                             CPL_TYPE_FLOAT,0));
+      strcpy(std_med_filename,STDSTAR_OUT_MED_CUBE);
+      check_nomsg(std_med_ima=cpl_imagelist_collapse_median_create(cube));
+      sinfo_free_imagelist(&cube);
+
+      ck0(sinfo_pro_save_ima(std_med_ima,ref_set,sof,STDSTAR_OUT_MED_CUBE,
+                 PRO_MED_OBS_PSF,NULL,plugin_id,config),
+      "Error saving image %s tag %s",STDSTAR_OUT_MED_CUBE,PRO_MED_OBS_PSF);
+
+    } else if(NULL != cpl_frameset_find(sof,PRO_MED_COADD_PSF)) {
+      check_nomsg(frame = cpl_frameset_find(sof,PRO_MED_COADD_PSF));
+      strcpy(std_med_filename,cpl_frame_get_filename(frame));
+      check_nomsg(std_med_ima=cpl_image_load(std_med_filename,
+                                             CPL_TYPE_FLOAT,0,0));
+    } else if(NULL != cpl_frameset_find(sof,PRO_OBS_PSF)) {
+      check_nomsg(frame = cpl_frameset_find(sof,PRO_OBS_PSF));
+      strcpy(std_cub_filename,cpl_frame_get_filename(frame));
+      check_nomsg(cube=cpl_imagelist_load(std_cub_filename,CPL_TYPE_FLOAT,0));
+      strcpy(std_med_filename,STDSTAR_OUT_MED_CUBE);
+      check_nomsg(std_med_ima=cpl_imagelist_collapse_median_create(cube));
+      sinfo_free_imagelist(&cube);
+
+      ck0(sinfo_pro_save_ima(std_med_ima,ref_set,sof,STDSTAR_OUT_MED_CUBE,
+                 PRO_MED_OBS_PSF,NULL,plugin_id,config),
+      "Error saving image %s tag %s",STDSTAR_OUT_MED_CUBE,PRO_MED_OBS_PSF);
+
+    } else if(NULL != cpl_frameset_find(sof,PRO_MED_COADD_OBJ)) {
+      check_nomsg(frame = cpl_frameset_find(sof,PRO_MED_COADD_OBJ));
+      strcpy(std_med_filename,cpl_frame_get_filename(frame));
+      check_nomsg(std_med_ima=cpl_image_load(std_med_filename,
+                                             CPL_TYPE_FLOAT,0,0));
+    } else if(NULL != cpl_frameset_find(sof,PRO_OBS_OBJ)) {
+      check_nomsg(frame = cpl_frameset_find(sof,PRO_OBS_OBJ));
+      strcpy(std_cub_filename,cpl_frame_get_filename(frame));
+      check_nomsg(cube = cpl_imagelist_load(std_cub_filename,
+                                             CPL_TYPE_FLOAT,0));
+      strcpy(std_med_filename,STDSTAR_OUT_MED_CUBE);
+      check_nomsg(std_med_ima=cpl_imagelist_collapse_median_create(cube));
+      sinfo_free_imagelist(&cube);
+
+      ck0(sinfo_pro_save_ima(std_med_ima,ref_set,sof,STDSTAR_OUT_MED_CUBE,
+                 PRO_MED_OBS_OBJ,NULL,plugin_id,config),
+      "Error saving image %s tag %s",STDSTAR_OUT_MED_CUBE,PRO_MED_OBS_OBJ);
+    } else {
+      sinfo_msg_error("Frame %s %s %s %s %s %s not found! Exit!",
+              PRO_MED_COADD_STD, PRO_OBS_STD,
+                      PRO_MED_COADD_PSF, PRO_OBS_PSF,
+                      PRO_MED_COADD_OBJ, PRO_OBS_OBJ);
+      goto cleanup;
+    }
+
+
+    check_nomsg(std_med_dup=cpl_image_duplicate(std_med_ima));
+    sinfo_clean_nan(&std_med_dup);
+    check_nomsg(cpl_image_get_maxpos(std_med_dup,&max_ima_x,&max_ima_y));
+    sinfo_free_image(&std_med_dup);
+
+
+    ima_szx=cpl_image_get_size_x(std_med_ima);
+    ima_szy=cpl_image_get_size_y(std_med_ima);
+    wllx= ((max_ima_x-psf_sz)>0)       ? (max_ima_x-psf_sz) : 1;
+    wlly= ((max_ima_y-psf_sz)>0)       ? (max_ima_y-psf_sz) : 1;
+    wurx= ((max_ima_x+psf_sz)<ima_szx) ? (max_ima_x+psf_sz) : ima_szx ;
+    wury= ((max_ima_y+psf_sz)<ima_szy) ? (max_ima_y+psf_sz) : ima_szy ;
+    /*
+    sinfo_msg("wllx=%d wlly=%d wurx=%d wury=%d\n",wllx,wlly,wurx,wury);
+    cpl_image_get_maxpos_window(std_med_ima,wllx,wlly,wurx,wury,
+                                &max_ima_x,&max_ima_y);
+    */
+    check_nomsg(qclog_tbl = sinfo_qclog_init());
+    check_nomsg(max_ima_cx=cpl_image_get_centroid_x_window(std_med_ima,wllx,
+                                                           wlly,wurx,wury));
+    check_nomsg(max_ima_cy=cpl_image_get_centroid_y_window(std_med_ima,wllx,
+                                                             wlly,wurx,wury));
+
+
+      xshift=max_ima_cx-ima_szx/2;
+      yshift=max_ima_cy-ima_szy/2;
+
+      ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC SHIFTX",xshift,
+                                       "X shift centroid - center image","%f"));
+
+      ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC SHIFTY",yshift,
+                                       "Y shift centroid - center image","%f"));
+
+    if(
+          ((max_ima_x-psf_sz) < 1) ||
+          ((max_ima_y-psf_sz) < 1) ||
+          ((max_ima_x+psf_sz) > ima_szx) ||
+          ((max_ima_x+psf_sz) > ima_szy)
+      )
+      {
+        psf_sz = (psf_sz < (max_ima_x-1))     ? psf_sz : (max_ima_x-1);
+        psf_sz = (psf_sz < (max_ima_y-1))     ? psf_sz : (max_ima_y-1);
+        psf_sz = (psf_sz < ima_szx-max_ima_x) ? psf_sz : (ima_szx-max_ima_x);
+        psf_sz = (psf_sz < ima_szy-max_ima_y) ? psf_sz : (ima_szy-max_ima_y);
+        //added to prevent seg fault by cpl_image_fit_gaussian
+        psf_sz = (psf_sz > 4) ? psf_sz : 4;
+      }
+
+
+      ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC FWHM LLX",cfg->llx,
+                                    "STD star FWHM LLX","%d"));
+      ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC FWHM LLY",cfg->lly,
+                                    "STD star FWHM LLY","%d"));
+      ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC FWHM HBX",cfg->halfbox_x,
+                                    "STD star FWHM HBX","%d"));
+      ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC FWHM HBX",cfg->halfbox_y,
+                                    "STD star FWHM HBY","%d"));
+
+
+    /* call the 2D-Gaussian fit routine */
+    for ( i = 0 ; i < 7 ; i++ )
+    {
+        mpar[i] = 1 ;
+    }
+
+
+     if(-1 == sinfo_new_fit_2d_gaussian(std_med_ima,
+                                  fpar,
+                                  dpar,
+                                  mpar,
+                                  cfg->llx,
+                                  cfg->lly,
+                                  cfg->halfbox_x,
+                                  cfg->halfbox_y,
+                                  &check4 ) ) {
+      irplib_error_recover(clean_state,"2d Gaussian fit failed");
+      /* return 0; */
+
+     } else {
+
+      ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC FWHM MAJ",fpar[4],
+                                       "STD star FWHM on major axis","%f"));
+      ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC FWHM MIN",fpar[5],
+                                       "STD star FWHM on minor axis","%f"));
+      ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC THETA",fpar[6],
+                                       "STD star ellipsis angle theta","%f"));
+
+
+     }
+
+
+    /*
+    sinfo_msg("Gauss fit params: xc,yc,amp,bkg,fwhm_x,fwhm_y,angle\n");
+    for ( i = 0 ; i < 7 ; i++ )
+      {
+        sinfo_msg("fpar[%d]=%f dpar[%d]=%f\n",i,fpar[i],i,dpar[i]);
+      }
+    */
+    if(CPL_ERROR_NONE == cpl_image_fit_gaussian(std_med_ima,
+                                                max_ima_x,
+                                                max_ima_y,
+                                                psf_sz,
+                                                &norm,
+                                                &xcen,
+                                                &ycen,
+                                                &sig_x,
+                                                &sig_y,
+                                                &fwhm_x,
+                                                &fwhm_y)) {
+
+
+      ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC FWHMX",fwhm_x,
+                                       "STD star FWHM on X","%f"));
+      ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC FWHMY",fwhm_y,
+                                       "STD star FWHM on Y","%f"));
+
+      cfg -> halfbox_x =  (floor)(0.5*(fwhm_x+fwhm_y)*cfg->fwhm_factor+0.5);
+
+      cfg -> halfbox_y =  (floor)(0.5*(fwhm_x+fwhm_y)*cfg->fwhm_factor+0.5);
+
+    } else {
+
+      irplib_error_recover(clean_state,"Problem fitting Gaussian");
+      cpl_error_reset();
+
+    }
+    sinfo_free_image(&std_med_ima);
+
+      /*
+      sinfo_msg("max ima=%d %d psf_sz=%d\n",max_ima_x,max_ima_y,psf_sz);
+      sinfo_msg("centroid ima=%f %f\n",max_ima_cx,max_ima_cy);
+      sinfo_msg("gauss=norm=%f xcen=%f ycen=%f sig_x=%f "
+                "sig_y=%f fwhm_x=%f fwhm_y=%f\n",
+                          norm,xcen,ycen,sig_x,sig_y,fwhm_x,fwhm_y);
+      */
+
+      cfg -> llx = (int)(xcen-cfg->halfbox_x);
+      cfg -> llx = (cfg -> llx  > 0 ) ? cfg -> llx  : 1;
+
+      if((cfg->llx+2*cfg->halfbox_x) >= ima_szx) {
+    cfg -> halfbox_x=(int) ((ima_szx-cfg->llx-1)/2);
+        check1++;
+      }
+
+      cfg -> lly = (int)(ycen-cfg->halfbox_y);
+      cfg -> lly = (cfg -> lly  > 0 ) ? cfg -> lly  : 1;
+      if((cfg->lly+2*cfg->halfbox_y) >= ima_szy) {
+    cfg -> halfbox_y=(int) ((ima_szy-cfg->lly-1)/2);
+        check1++;
+      }
+     ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC CHECK1",check1,
+                                    "Check on evaluation box","%d"));
+
+
+    /*
+      sinfo_msg("llx= %d lly= %d\n",cfg->llx, cfg->lly);
+      sinfo_msg("halfbox_x=%d halfbox_y=%d\n",cfg->halfbox_x,cfg->halfbox_y);
+     */
+
+    /*
+#----------------------------------------------------------------------
+#---------------------------EXTRACTION---------------------------------
+#----------------------------------------------------------------------
+    */
+
+      sinfo_msg("Extraction");
+      cknull(spectrum = (cpl_image**) cpl_calloc (cfg -> nframes,
+                                                  sizeof(cpl_image*)),
+                            "Could not allocate memory for spectrum image");
+
+      for (fra=0; fra < cfg->nframes; fra++) {
+         name = cfg->inFrameList[fra];
+         if(sinfo_is_fits_file(name) != 1) {
+            sinfo_msg_error("Input file %s is not FITS",name);
+            goto cleanup;
+	 }
+         cknull(cube = cpl_imagelist_load(name,CPL_TYPE_FLOAT,0),
+        "could not load data cube" );
+
+         if (exptime == FLAG) {
+	   sinfo_msg_error("could not find exposure time in the fits header");
+	   return -1;
+	 }
+         exptime = sinfo_pfits_get_ditndit(name);
+
+         sinfo_msg("cfg->gain %f",cfg->gain);
+         check_nomsg(tbl_spectrum=cpl_table_new(cpl_imagelist_get_size(cube)));
+        if(NULL==(spectrum[fra]=sinfo_new_optimal_extraction_from_cube( cube,
+                                      cfg->llx,
+                                      cfg->lly,
+                                      cfg->halfbox_x,
+                                      cfg->halfbox_y,
+                                      cfg->fwhm_factor,
+                                      BKG_VARIANCE,
+                                      SKY_FLUX,
+                                      cfg->gain,
+                                      exptime,
+                                      name,
+                                      &tbl_spectrum,
+                                      qc_info,
+                                      &check2))){
+
+      irplib_error_recover(clean_state,
+			   "could not do sinfo_optimalExtractionFromCube");
+     } else {
+     check_nomsg(cpl_imagelist_set(list_object,
+                     cpl_image_duplicate(spectrum[fra]), fra));
+
+     }
+
+
+
+	ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC CHECK2",
+                                       check2,"Check on evaluation box","%d"));
+
+
+        ck0(sinfo_pro_save_tbl(tbl_spectrum,ref_set,sof,
+                                      (char*)STDSTAR_OUT_TABLE,
+                      PRO_STD_STAR_SPECTRA,qclog_tbl,
+                plugin_id,config),
+         "cannot dump ima %s", "out_std_star_spectrum.fits");
+
+
+     sinfo_free_table(&qclog_tbl);
+
+     if (do_compute_eff!=0 && frm_std_cat !=NULL && frm_atmext != NULL) {
+        sinfo_msg("compute efficiency");
+        frm_sci     = cpl_frameset_find(sof,PRO_STD_STAR_SPECTRA);
+        frm_std_cat = cpl_frameset_find(sof,FLUX_STD_CATALOG);
+        frm_atmext  = cpl_frameset_find(sof,EXTCOEFF_TABLE);
+
+
+
+        check_nomsg(tot_eff=sinfo_efficiency_compute(frm_sci,frm_std_cat,
+                                                     frm_atmext));
+        ck0(sinfo_pro_save_tbl(tot_eff,ref_set,sof,(char*)EFFICIENCY_FILENAME,
+                               PRO_EFFICIENCY,qclog_tbl,plugin_id,config),
+            "cannot dump ima %s", "out_.fits");
+     }
+
+
+
+
+     /*
+         if(spectrum[fra] != NULL ) {
+         sinfo_free_image(&(spectrum)[fra]);
+         }
+     */
+     /*----determine the intensity conversion factor if wished--------*/
+     if (cfg->convInd == 1) {
+       sinfo_msg("Determines convertion factor");
+
+           convfactor = sinfo_new_determine_conversion_factor( cube,
+                                                cfg->mag,
+                                                exptime,
+                                                cfg->llx,
+                                                cfg->lly,
+                                                cfg->halfbox_x,
+                                                cfg->halfbox_y,
+                                                &check3 );
+
+
+            if (convfactor < -100000.) {
+            sinfo_msg_warning("could not do sinfo_determineConversionFactor!" );
+           /* goto cleanup; */
+        } else {
+             sinfo_new_array_set_value(factor, convfactor, fra);
+        }
+     }
+     sinfo_free_imagelist(&cube);
+      } /* end loop over fra */
+
+      sinfo_free_table(&tbl_spectrum);
+      sinfo_free_image_array(&spectrum,cfg->nframes);
+      if (cfg->convInd == 1) {
+	sinfo_msg("Determines clean factor");
+        cleanfactor = sinfo_new_clean_mean(factor,
+                                 cfg->nframes,
+                                 cfg->lo_reject*100.,
+                 cfg->hi_reject*100.);
+      }
+      if (cleanfactor > 100000. || cleanfactor == FLAG) {
+	sinfo_msg_error("could not do sinfo_clean_mean!" );
+        goto cleanup;
+      }
+
+
+  /*---read the fits header to change the gain and noise parameter-----*/
+      sinfo_msg("Average with rejection");
+
+      no=cpl_imagelist_get_size(list_object);
+      lo_cut=(floor)(cfg->lo_reject*no+0.5);
+      hi_cut=(floor)(cfg->hi_reject*no+0.5);
+      if(no > 0) {
+         cknull(img_spct=cpl_imagelist_collapse_minmax_create(list_object,
+                                                              lo_cut,hi_cut),
+                          "sinfo_average_with_rejection failed" );
+      }
+
+      sinfo_free_imagelist(&list_object);
+      if(no > 0) {
+	check_nomsg(qclog_tbl = sinfo_qclog_init());
+
+        ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC CONVFCT",cleanfactor,
+                                         "Conversion factor","%g"));
+
+        ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC CHECK3",check3,
+                                      "Check evaluation box","%d"));
+
+
+        ck0(sinfo_pro_save_ima(img_spct,ref_set,sof,cfg->outName,
+                    PRO_STD_STAR_SPECTRUM,qclog_tbl,
+                 plugin_id,config),
+	    "cannot dump ima %s", cfg->outName);
+
+        sinfo_new_set_wcs_spectrum(img_spct,cfg->outName,cenLambda,disp,cenpix);
+        sinfo_free_table(&qclog_tbl);
+      }
+      /*#---free memory---*/
+      if(factor != NULL) sinfo_new_destroy_array(&factor);
+      sinfo_free_image(&img_spct);
+      sinfo_stdstar_free(&cfg);
+      sinfo_free_frameset(&raw);
+
+      return 0;
+
+ cleanup:
+      sinfo_free_table(&tbl_spectrum);
+      sinfo_free_table(&qclog_tbl);
+      sinfo_free_imagelist(&list_object);
+      if(spectrum != NULL) sinfo_free_image_array(&spectrum,cfg->nframes);
+      sinfo_free_image(&std_med_ima);
+      sinfo_free_image(&std_med_dup);
+      sinfo_free_imagelist(&cube);
+      sinfo_free_propertylist(&plist) ;
+      if(factor != NULL) sinfo_new_destroy_array(&factor);
+      sinfo_free_image(&img_spct);
+      sinfo_stdstar_free (&cfg);
+      sinfo_free_frameset(&raw);
+    return -1;
+
+}
+
+
+/**@}*/
diff --git a/sinfoni/sinfo_new_stdstar.h b/sinfoni/sinfo_new_stdstar.h
new file mode 100644
index 0000000..0ecb08d
--- /dev/null
+++ b/sinfoni/sinfo_new_stdstar.h
@@ -0,0 +1,69 @@
+#ifndef SINFO_NEW_STDSTAR_H
+#define SINFO_NEW_STDSTAR_H
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*******************************************************************************
+* E.S.O. - VLT project
+*
+* "@(#) $Id: sinfo_new_stdstar.h,v 1.11 2007/09/21 14:13:43 amodigli Exp $"
+*
+* who       when      what
+* --------  --------  ----------------------------------------------
+* schreib  06/05/03  created
+*/
+
+/************************************************************************
+ * sinfo_new_stdstar.h
+ * routines to create a data cube
+ *----------------------------------------------------------------------
+ */
+
+/*
+ * header files
+ */
+#include <cpl.h>  
+#include "sinfo_msg.h"
+#include <sinfo_standstar_cfg.h>
+/*----------------------------------------------------------------------------
+ *                        Function ANSI C prototypes
+ *--------------------------------------------------------------------------*/
+/*----------------------------------------------------------------------------
+   Function     :       sinfo_new_stdstar()
+   In           :       ini_file: file name of according .ini file
+   Out          :       integer (0 if it worked, -1 if it doesn't) 
+   Description  :    this routine does the optimal extraction of a spectrum 
+                        of an already reduced data cube of a standard star 
+                        observation. Additionally, a conversion factor from 
+                        mag to counts/sec can be determined if the magnitude 
+                        of the standard star is known. 
+                        This is done for a number of jittered data cubes and 
+                        the results are averaged by rejecting the extreme 
+                        values
+ ---------------------------------------------------------------------------*/
+int 
+sinfo_new_stdstar (const char* plugin_id,
+                   cpl_parameterlist* config,
+                   cpl_frameset* sof,cpl_frameset* ref_set) ;
+
+
+
+
+#endif /*!SINFO_STDSTAR_H*/
+
+/*--------------------------------------------------------------------------*/
diff --git a/sinfoni/sinfo_new_wave_cal_slit2.c b/sinfoni/sinfo_new_wave_cal_slit2.c
new file mode 100644
index 0000000..fad807d
--- /dev/null
+++ b/sinfoni/sinfo_new_wave_cal_slit2.c
@@ -0,0 +1,910 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+ 
+   File name    :       sinfo_new_wave_cal_slit2.c
+   Author       :    A. Modigliani
+   Created on   :    Sep 17, 2003
+   Description  : 
+
+ ---------------------------------------------------------------------------*/
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+/*----------------------------------------------------------------------------
+                                Includes
+ ---------------------------------------------------------------------------*/
+#include "sinfo_new_wave_cal_slit2.h"
+#include "sinfo_pro_save.h"
+#include "sinfo_pro_types.h"
+#include "sinfo_wavecal_ini_by_cpl.h"
+#include "sinfo_wcal_functions.h"
+#include "sinfo_absolute.h"
+#include "sinfo_wave_calibration.h"
+#include "sinfo_wavecal.h"
+#include "sinfo_globals.h"
+#include "sinfo_hidden.h"
+
+#include "sinfo_utilities.h"
+#include "sinfo_utils_wrappers.h"
+#include "sinfo_error.h"
+
+
+/*----------------------------------------------------------------------------
+                                Defines
+ ---------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+                             Function Definitions
+ ---------------------------------------------------------------------------*/
+static cpl_error_code
+sinfo_image_resample(const char* plugin_id,
+                     cpl_parameterlist* config,
+                     cpl_frameset* sof,
+                     cpl_frameset* ref_set);
+
+/**@{*/
+/**
+ * @addtogroup sinfo_rec_wavecal wavelength calibration 
+ *
+ * TBD
+ */
+
+/*----------------------------------------------------------------------------
+   Function     :       sinfo_wave_cal_slit()
+   In           :       ini_file: file name of according .ini file
+   Out          :       integer (0 if it worked, -1 if it doesn't) 
+   Job          :
+
+
+  Normal method:
+
+  does the wavelength calibration and the fitting of the slitlet sinfo_edge 
+  positions (ASCII file 32 x 2 values) if wished
+  produces an array of the bcoefs and of the fit parameters if wished and a 
+  wavelength calibration map input is an emission line frame and a line list
+
+
+  o searching for lines by cross sinfo_correlation with a line list
+  o Gaussian fitting of emission lines in each column->positions of the lines->
+    resulting fit parameters can be stored in an ASCII file
+  o Fitting of a polynomial to the line positions for each column
+  o Smoothing: fitting of each polynomial coefficient by another polynomial
+    across the whole frame -> resulting polynomial coefficients can be stored 
+    in an ASCII file.
+  o Wavelength calibration map (micron value for each frame pixel) can be
+    produced by using these coefficients and a cross sinfo_correlation to the
+    original frame
+
+  o The slitlet sinfo_edge positions can be fitted:
+    1) Automatically (not really stable) or by using guess sinfo_edge positions
+    2) By using a Boltzmann or a linear slope function
+
+  Slit method:
+
+  does the wavelength calibration and the fitting of the slitlet sinfo_edge 
+  positions (ASCII file 32 x 2 values) if wished produces a list of the fit 
+  parameters and of the smoothed coefficients if wished and a wavelength 
+  calibration map input is an emission line frame and a line list
+
+  o Does the same as other method but smoothes the found polynomial 
+    coefficients within each slitlet and not over the whole frame.
+
+  o Produces always a wavelength calibration map and does not crosscorrelate.
+
+ ---------------------------------------------------------------------------*/
+
+
+int 
+sinfo_new_wave_cal_slit2(const char* plugin_id,
+                        cpl_parameterlist* config, 
+                        cpl_frameset* sof,cpl_frameset* ref_set)
+{
+  wave_config * cfg =NULL;
+  char col_name[MAX_NAME_SIZE];
+  char tbl_name[MAX_NAME_SIZE];
+  char tbl_fitpar_name[MAX_NAME_SIZE];
+  char tbl_line_list_name[MAX_NAME_SIZE];
+  char tbl_slitpos_guess_name[MAX_NAME_SIZE];
+  char key_name[MAX_NAME_SIZE];
+  char col[MAX_NAME_SIZE];
+  int check = 0;
+  int lx = 0;
+  int ly = 0;
+  int n_lines=0;
+  int i = 0;
+  int j = 0;
+  int n = 0;
+  int readsum=0;
+  int sum=0;
+  int fit=0;
+  int sw=0;
+ 
+  int* status=NULL;
+  int* n_found_lines=NULL;
+  int* sum_pointer=NULL;
+  int** row_clean=NULL;
+
+  float a=0;
+  float shift=0;
+  float val_x=0;
+  float val_y=0;
+
+  float* wave=NULL;
+  float* intens=NULL;
+
+  float** acoefs=NULL;
+  float** wavelength_clean=NULL;
+  float** sinfo_slit_pos=NULL;
+
+  double fwhm_med=0;
+  double fwhm_avg=0;
+  double coef_med=0;
+  double coef_avg=0;
+ 
+  cpl_image * im=NULL ;
+
+  FitParams** par=NULL;
+
+  cpl_table* tbl_wcal=NULL;
+  cpl_table* tbl_spos=NULL;
+  cpl_table* tbl_fitpar = NULL;
+  cpl_table* tbl_line_list = NULL;
+  cpl_table* tbl_slitpos_guess=NULL;
+  cpl_table * tbl_fp =NULL;
+  cpl_table* qclog_tbl=NULL;
+
+  cpl_image* map_img=NULL;
+
+  cpl_frameset* raw=NULL;
+  cpl_parameter* p=NULL;
+
+  qc_wcal* qc=sinfo_qc_wcal_new();
+  int pdensity=0;
+
+  /*   -----------------------------------------------------------------
+       1) parse the file names and parameters to the ns_config data 
+          structure cfg
+       -----------------------------------------------------------------
+  */
+
+  check_nomsg(p=cpl_parameterlist_find(config,"sinfoni.product.density"));
+  check_nomsg(pdensity=cpl_parameter_get_int(p));
+
+
+  sinfo_msg("Parsing cpl input");
+  check_nomsg(raw=cpl_frameset_new());
+  cknull(cfg = sinfo_parse_cpl_input_wave(config,sof,&raw),
+     "could not parse cpl input!") ;
+ 
+  check_nomsg(p = cpl_parameterlist_find(config,
+                                         "sinfoni.wavecal.slitpos_boostrap"));
+  check_nomsg(sw=cpl_parameter_get_bool(p));
+
+  if(sw==1) {
+     cfg->nslitlets=32;
+     cfg->calibIndicator=1;
+     cfg->wavemapInd=0;
+     cfg->slitposIndicator=1;
+     sinfo_msg("***********************************");
+     sinfo_msg("parameter setting for %s",PRO_WAVE_SLITPOS_STACKED);
+     sinfo_msg("***********************************");
+  }
+
+  if(sinfo_is_fits_file(cfg->inFrame) != 1) {
+    sinfo_msg_error("Input file cfg->inFrame %s is not FITS",cfg->inFrame);
+    goto cleanup;
+  }
+
+
+  if (cfg->slitposIndicator == 1 && cfg->estimateIndicator == 1) {
+    if (sinfo_is_fits_file(cfg->slitposGuessName) != 1) {
+      sinfo_msg_error("slitlet position guess list not given!");
+      goto cleanup;
+    }
+  }
+
+  if (cfg->calibIndicator == 0 && cfg->wavemapInd == 1) {
+    if (sinfo_is_fits_file(cfg->coeffsName) != 1) {
+      sinfo_msg_error("coefficients list not given!");
+      goto cleanup;
+    }
+  }
+
+  if (cfg->slitposIndicator == 1) {
+    if (cfg->calibIndicator != 1 && cfg->estimateIndicator != 1) {
+      if (sinfo_is_fits_file(cfg->paramsList) != 1) {
+    sinfo_msg_error("parameter list not given!");
+    goto cleanup;
+      }
+    }
+  }
+ 
+  /*---load the emission line frame---*/
+  check(im = cpl_image_load(cfg->inFrame,CPL_TYPE_FLOAT,0,0)
+        ,"could not load image");
+  lx = cpl_image_get_size_x(im);
+  ly = cpl_image_get_size_y(im);
+
+  if (cfg->calibIndicator == 1 || cfg->wavemapInd == 1) {
+    /*---open the line list and read the number of lines---*/
+    strcpy(tbl_line_list_name,cfg->lineList);
+    check_nomsg(tbl_line_list = cpl_table_load(tbl_line_list_name,1,0));
+    check_nomsg(n = cpl_table_get_nrow(tbl_line_list));
+    n_lines = n;
+
+    check_nomsg(wave   = cpl_table_get_data_float(tbl_line_list,"wave"));
+    check_nomsg(intens = cpl_table_get_data_float(tbl_line_list,"int"));
+  }
+
+  /*
+  ----------------------------------------------------------------------
+  ---------------------------FINDLINES----------------------------------
+  ----------------------------------------------------------------------
+  */
+
+  /*if not yet done:
+    do the wavelength calibration, that means: 
+    find the dispersion relation and parameterize its coefficients
+  */
+  /*
+  sinfo_msg("guessBeginWave=%g",cfg->guessBeginWavelength);
+  sinfo_msg("guessDisp1=%g",cfg->guessDispersion1);
+  sinfo_msg("guessDisp2=%g",cfg->guessDispersion2);
+  */
+  if (cfg->calibIndicator == 1 && cfg->wavemapInd == 0) {
+    sinfo_msg("Findlines");
+    acoefs  = sinfo_new_2Dfloatarray(cfg->nrDispCoefficients, lx);
+
+    /*allocate memory*/
+    n_found_lines    = sinfo_new_intarray(lx); 
+    row_clean        = sinfo_new_2Dintarray(lx, n_lines);
+    wavelength_clean = sinfo_new_2Dfloatarray(lx, n_lines);
+    sum_pointer      = sinfo_new_intarray(1) ;
+
+    /*find the emission lines in each image column*/
+    sinfo_new_intarray_set_value(sum_pointer, 0, 0);
+ 
+    ck0(check = sinfo_new_find_lines(im, 
+                                wave, 
+                                intens, 
+                                n_lines, 
+                                row_clean, 
+                                wavelength_clean, 
+                                cfg->guessBeginWavelength, 
+                        cfg->guessDispersion1, 
+                                cfg->guessDispersion2,
+                                cfg->mindiff, 
+                                cfg->halfWidth, 
+                                n_found_lines, 
+                                cfg->sigma, 
+                                sum_pointer),
+    "sinfo_findLines failed!");
+
+    /*---------------------------------------------------------------------
+     *-----------------------WAVE_CALIB-------------------------------------
+     *---------------------------------------------------------------------
+    */
+    sinfo_msg("Wave Calibration");
+    sum = sinfo_new_intarray_get_value(sum_pointer,0);
+    /* allocate memory for the fit parameters */
+    cknull(par = sinfo_new_fit_params( sum ),
+       "sinfo_newFitParams failed!");
+
+  /*
+   fit each line, make a polynomial fit and fit the resulting fit 
+   coefficients across the columns of the slitlet
+   */
+   cknull(map_img = sinfo_new_wave_cal(im, 
+                  par, 
+                  acoefs,
+                  cfg->nslitlets, 
+                  row_clean,
+                  wavelength_clean,
+                  n_found_lines,
+                  cfg->guessDispersion1,
+                  cfg->halfWidth,
+                  cfg->minAmplitude,
+                  cfg->maxResidual,
+                  cfg->fwhm,
+                  cfg->nrDispCoefficients, 
+                  cfg->nrCoefCoefficients,
+                  cfg->sigmaFactor,
+                  cfg->pixeldist,
+                  cfg->pixel_tolerance),
+      "sinfo_wave_cal failed!");
+
+   sinfo_msg("Check line positions");
+
+   shift=sinfo_new_check_line_positions(im,acoefs,cfg->nrDispCoefficients,
+                    cfg->guessDispersion1,par);
+   if (FLAG == shift){ 
+      sinfo_msg_error("checkForLinePositions failed!\n");
+   }
+
+
+   sinfo_det_ncounts(raw, cfg->qc_thresh_max, qc);
+
+   cknull_nomsg(qclog_tbl = sinfo_qclog_init());
+   ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC WAVE ALL",n_lines,
+                                 "Number of found lines","%d"));
+   ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC WAVE NPIXSAT",qc->nsat,
+                                 "Number of saturated pixels","%d"));
+   ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC WAVE MAXFLUX",qc->max_di,
+                                 "Max int off-lamp subtracted frm","%g"));
+   ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC WAVE POSERR",shift,
+                                 "Overall positioning error in mum","%g"));
+
+   ck0(sinfo_pro_save_ima(map_img,ref_set,sof,cfg->outName,
+              PRO_WAVE_MAP,qclog_tbl,plugin_id,config),
+       "cannot save ima %s", cfg->outName);
+
+   sinfo_free_table(&qclog_tbl);
+   sinfo_free_image(&map_img);
+
+   /*
+    #store the resulting polynomial fit coefficients in an 
+     ASCII file if wished
+   */
+
+   if (cfg->writeCoeffsInd == 1) {
+     check_nomsg(tbl_wcal = cpl_table_new(lx));
+     for (i=0; i< cfg->nrDispCoefficients; i++) {
+       snprintf(col_name,MAX_NAME_SIZE-1,"%s%d","coeff",i);
+       check_nomsg(cpl_table_new_column(tbl_wcal,col_name, CPL_TYPE_DOUBLE));
+     }
+
+     cknull_nomsg(qclog_tbl = sinfo_qclog_init());
+     ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC WAVE ALL",n_lines,
+                                   "Number found lines","%d"));
+
+     for (j=0; j< lx; j++) {
+       for (i=0; i< cfg->nrDispCoefficients; i++) {
+     snprintf(col_name,MAX_NAME_SIZE-1,"%s%d","coeff",i);
+     a = sinfo_new_array2D_get_value(acoefs, i, j);
+     /* fprintf(acoefs_file, "%15.13g ", a) ; */
+     cpl_table_set_double(tbl_wcal,col_name,j,a);
+       }
+     }
+     for (i=0; i< cfg->nrDispCoefficients; i++) {
+       snprintf(col_name,MAX_NAME_SIZE-1,"%s%d","coeff",i);
+       check_nomsg(coef_avg=cpl_table_get_column_mean(tbl_wcal,col_name));
+       check_nomsg(coef_med=cpl_table_get_column_median(tbl_wcal,col_name));
+
+       snprintf(key_name,MAX_NAME_SIZE-1,"%s%d%s","QC COEF",i," AVG");
+       ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,key_name,coef_avg,
+                                        "Average wavecal Coef","%g"));
+
+       snprintf(key_name,MAX_NAME_SIZE-1,"%s%d%s","QC COEF",i," MED");
+       ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,key_name,coef_med,
+                                        "Median wavecal Coef","%g"));
+
+     }
+     if(pdensity >1) {
+     strcpy(tbl_name,cfg->coeffsName);
+     ck0(sinfo_pro_save_tbl(tbl_wcal,ref_set,sof,tbl_name,
+                PRO_WAVE_COEF_SLIT,qclog_tbl,plugin_id,config),
+     "cannot save tbl %s", tbl_name);
+     sinfo_free_table(&tbl_wcal);
+     sinfo_free_table(&qclog_tbl);
+     }
+
+   }
+
+   /*
+    #store the resulting Gaussian fit parameters in an ASCII file if wished
+   */
+   if (cfg->writeParInd == 1) {
+      sinfo_new_dump_fit_params_to_ascii(par,WAVECAL_FIT_PARAMS_OUT_FILEASCII);
+ 
+      cknull(par,"no fit parameters available!") ;
+      cknull(cfg->paramsList,"no filename available!") ;
+      check_nomsg(tbl_fp = cpl_table_new(par[0] -> n_params));
+      check_nomsg(cpl_table_new_column(tbl_fp,"n_params", CPL_TYPE_INT));
+      check_nomsg(cpl_table_new_column(tbl_fp,"column", CPL_TYPE_INT));
+      check_nomsg(cpl_table_new_column(tbl_fp,"line", CPL_TYPE_INT));
+ 
+      for(j=0;j<4;j++) {
+         snprintf(col,MAX_NAME_SIZE-1,"%s%d","fpar",j);
+         cpl_table_new_column(tbl_fp,col, CPL_TYPE_DOUBLE);
+         snprintf(col,MAX_NAME_SIZE-1,"%s%d","dpar",j);
+         cpl_table_new_column(tbl_fp,col, CPL_TYPE_DOUBLE);
+      }
+
+      cknull_nomsg(qclog_tbl = sinfo_qclog_init());
+      ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC NLINES",n_lines,
+                                    "Number of found lines","%d"));
+
+     for ( i = 0 ; i < par[0] -> n_params ; i++ ) {
+      
+         check_nomsg(cpl_table_set_int(tbl_fp,"n_params",i,par[i]->n_params));
+         check_nomsg(cpl_table_set_int(tbl_fp,"column",i,par[i]->column));
+         check_nomsg(cpl_table_set_int(tbl_fp,"line",i,par[i]->line));
+
+         for(j=0;j<4;j++) {
+       snprintf(col,MAX_NAME_SIZE-1,"%s%d","fpar",j);
+       if(isnan(par[i]->fit_par[j])) {
+         cpl_table_set_invalid(tbl_fp,col,i);
+       } else {
+         cpl_table_set_double(tbl_fp,col,i,par[i]->fit_par[j]);
+       }
+       snprintf(col,MAX_NAME_SIZE-1,"%s%d","dpar",j);
+       if(isnan(par[i]->derv_par[j])) {
+         cpl_table_set_invalid(tbl_fp,col,i);
+       } else {
+         cpl_table_set_double(tbl_fp,col,i,par[i]->derv_par[j]);
+       }
+     }
+      }
+
+      check_nomsg(fwhm_avg = cpl_table_get_column_mean(tbl_fp,"fpar1"));
+      check_nomsg(fwhm_med = cpl_table_get_column_median(tbl_fp,"fpar1"));
+      ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC FWHM MED",fwhm_med,
+                                       "Median FWHM of found lines","%f"));
+      ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC FWHM AVG",fwhm_avg,
+                                       "Average FWHM of found lines","%f"));
+
+      if(pdensity > 1) {
+      ck0(sinfo_pro_save_tbl(tbl_fp,ref_set,sof,cfg->paramsList,
+                 PRO_WAVE_PAR_LIST,qclog_tbl,plugin_id,config),
+      "cannot save tbl %s", cfg->paramsList);
+      }
+
+      sinfo_free_table(&qclog_tbl);
+      sinfo_free_table(&tbl_fp) ;
+
+   }
+
+   /* free memory */
+   sinfo_new_destroy_2Dfloatarray ( &wavelength_clean, lx );
+   sinfo_new_destroy_2Dintarray (&row_clean, lx);
+   sinfo_new_destroy_intarray(&n_found_lines );
+   sinfo_new_destroy_intarray(&sum_pointer );
+   sinfo_new_destroy_2Dfloatarray ( &acoefs, cfg->nrDispCoefficients );
+   sinfo_free_table(&tbl_line_list);
+
+   /*----------------------------------------------------------------------
+    *-------------------WAVEMAP--------------------------------------------
+    *----------------------------------------------------------------------
+    */
+
+   /*
+    #---now do the cross sinfo_correlation and produce a wavelength map---
+   */
+
+  } else if (cfg->wavemapInd == 1 && cfg->calibIndicator == 0) { 
+    sinfo_msg("Wavemap");
+    acoefs = sinfo_new_2Dfloatarray ( cfg->nrDispCoefficients, lx);
+    /* #read the parameterized dispersion relation */
+
+    strcpy(tbl_name,cfg->coeffsName);
+    check_nomsg(tbl_wcal = cpl_table_load(tbl_name,1,0));
+
+    for (i =0; i < lx; i++) {
+      for (j = 0; j< cfg->nrDispCoefficients; j++) {
+    snprintf(col_name,MAX_NAME_SIZE-1,"%s%d","coeff",j);
+    acoefs[j][i]=cpl_table_get_double(tbl_wcal,col_name,i,status);
+      }
+    }
+    sinfo_free_table(&tbl_wcal);
+
+    cknull(map_img = sinfo_new_create_shifted_slit_wavemap2(im,
+                           acoefs,
+                           cfg->nrDispCoefficients,
+                           wave,
+                           intens,
+                           n_lines,
+                           cfg->magFactor,
+                           cfg->guessDispersion1,
+                           cfg->pixeldist ),
+           "sinfo_createShiftedSlitWavemap2 failed!");
+
+    par = sinfo_new_fit_params(15*n_lines);
+    sinfo_msg("Check shifts");
+
+    shift = sinfo_new_check_correlated_line_positions ( im, acoefs, 
+                         cfg->nrDispCoefficients, 
+                         wave,
+                         intens,
+                         n_lines,
+                         cfg->fwhm,
+                         cfg->halfWidth,
+                         cfg->minAmplitude,
+                         cfg->guessDispersion1,
+                         par );
+
+    if (FLAG == shift){
+      sinfo_msg_error("sinfo_checkCorrelatedLinePositions failed!\n");
+    }
+
+    sinfo_det_ncounts(raw, cfg->qc_thresh_max,qc);
+    cknull_nomsg(qclog_tbl = sinfo_qclog_init());
+
+    ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC NLINES",n_lines,
+                                  "Number of found lines","%d"));
+
+    check_nomsg(fwhm_avg = cpl_table_get_column_mean(tbl_fp,"fpar1"));
+    check_nomsg(fwhm_med = cpl_table_get_column_median(tbl_fp,"fpar1"));
+
+    ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC FWHM MED",fwhm_med,
+                                  "Median FWHM of found lines","%f"));
+    ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC FWHM AVG",fwhm_avg,
+                                  "Average FWHM of found lines","%f"));
+
+    ck0(sinfo_pro_save_ima(map_img,ref_set,sof,cfg->outName,
+               PRO_WAVE_MAP,qclog_tbl,plugin_id,config),
+    "cannot save ima %s", cfg->outName);
+
+    sinfo_free_table(&qclog_tbl);
+    sinfo_free_image(&map_img);
+
+    /* # ---free memory--- */
+    sinfo_new_destroy_2Dfloatarray ( &acoefs, cfg->nrDispCoefficients );
+    /* To fix a memory bug we comment the following. But check! */
+    /* cpl_free ( wave ); */
+    /* cpl_free ( intens ); */
+
+  } else if (cfg->wavemapInd == 1 && cfg->calibIndicator == 1) {
+    sinfo_msg_error("give either wavemapIndicator = yes and calibIndicator");
+    sinfo_msg_error("= no or wavemapIndicator = no and calibIndicator = yes") ;
+    goto cleanup;
+  }
+
+  /*-------------------------------------------------------------------
+   *-------------------SLITFITS----------------------------------------
+   *-------------------------------------------------------------------
+   #--fit the slitlet sinfo_edge positions if desired--
+  */
+  if (cfg->slitposIndicator == 1) {
+  sinfo_msg("fit the slitlet sinfo_edge positions");
+  if (cfg->calibIndicator != 1 && cfg->estimateIndicator != 1) {
+
+    /*
+      #read the first integer to determine the number of fit 
+      parameters to allocate
+    */
+
+     if(sinfo_is_fits_file(cfg->paramsList) !=1 ) {
+       sinfo_msg_error("cannot read FITS file %s ",cfg->paramsList);
+       goto cleanup;
+     }
+     strcpy(tbl_fitpar_name,cfg->paramsList);
+     check_nomsg(tbl_fitpar = cpl_table_load(tbl_fitpar_name,1,0));
+
+     check_nomsg(readsum=cpl_table_get_int(tbl_fitpar,"n_params",1,status));
+     sinfo_free_table(&tbl_fitpar);
+ 
+     cknull(sinfo_new_fit_params( readsum ),"sinfo_new_fit_params failed!");
+
+     ck0(sinfo_dumpTblToFitParams(par, cfg->paramsList),
+     "reading tbl %s ", cfg->paramsList);
+  }
+
+  /* #allocate memory for the slitlet position array */
+  sinfo_slit_pos = sinfo_new_2Dfloatarray(32,2);
+  /* #now decide which fit model function you want to use by 
+     reading a given character
+  */
+  /*
+  sinfo_msg("cfg->fitBoltzIndicator=%d\n",cfg->fitBoltzIndicator);
+  sinfo_msg("cfg->estimateIndicator=%d\n",cfg->estimateIndicator);
+  sinfo_msg("cfg->fitEdgeIndicator=%d\n",cfg->fitEdgeIndicator);
+  */
+  if (cfg->fitBoltzIndicator == 1) {
+    if (cfg->estimateIndicator == 1) {
+      /* #open the ASCII list of the slitlet positions--- */
+      /*READ TFITS TABLE*/
+      strcpy(tbl_slitpos_guess_name,cfg->slitposGuessName);
+      check_nomsg(tbl_slitpos_guess=cpl_table_load(tbl_slitpos_guess_name,1,0));
+      check_nomsg(n = cpl_table_get_nrow(tbl_slitpos_guess));
+
+      for (i =0 ; i< 32; i++){
+        val_x=cpl_table_get_double(tbl_slitpos_guess,"pos1",i,status);
+        val_y=cpl_table_get_double(tbl_slitpos_guess,"pos2",i,status);
+    sinfo_new_array2D_set_value(sinfo_slit_pos,val_x,i,0);
+    sinfo_new_array2D_set_value(sinfo_slit_pos,val_y,i,1);
+      }
+      sinfo_free_table(&tbl_slitpos_guess);
+
+      sinfo_msg("sinfo_new_fit_slits_boltz_with_estimate");
+      fit = sinfo_new_fit_slits_boltz_with_estimate(im, 
+                                            sinfo_slit_pos, 
+                                  cfg->boxLength, 
+                                            cfg->yBox, 
+                                            cfg->diffTol, 
+                                            cfg->loPos, 
+                                            cfg->hiPos );
+      if (fit < 0){
+    sinfo_msg_error("sinfo_new_fit_slits_boltz_with_estimate failed" );
+    goto cleanup;
+      }
+    } else {
+    sinfo_msg("sinfo_new_fit_slits_boltz");
+    fit = sinfo_new_fit_slits_boltz(im, 
+                                  par, 
+                                  sinfo_slit_pos, 
+                                  cfg->boxLength, 
+                                  cfg->yBox, 
+                                  cfg->diffTol );
+
+    if (fit < 0) {
+      sinfo_msg_error ( "sinfo_new_fit_slits_boltz failed" );
+      goto cleanup;
+    }
+    }
+  } else if (cfg->fitEdgeIndicator == 1) {
+
+    if (cfg->estimateIndicator == 1){
+      /*READ TFITS TABLE*/
+      strcpy(tbl_slitpos_guess_name,cfg->slitposGuessName);
+      check_nomsg(tbl_slitpos_guess=cpl_table_load(tbl_slitpos_guess_name,1,0));
+      check_nomsg(n = cpl_table_get_nrow(tbl_slitpos_guess));
+
+      for (i =0 ; i< 32; i++){
+    val_x=cpl_table_get_double(tbl_slitpos_guess,"pos1",i,status);
+    val_y=cpl_table_get_double(tbl_slitpos_guess,"pos2",i,status);
+    sinfo_new_array2D_set_value(sinfo_slit_pos,val_x,i,0);
+    sinfo_new_array2D_set_value(sinfo_slit_pos,val_y,i,1);
+      }
+      cpl_table_delete(tbl_slitpos_guess);
+
+      sinfo_msg("sinfo_new_fit_slits_edge_with_estimate");
+      fit = sinfo_new_fit_slits_edge_with_estimate(im, 
+                                           sinfo_slit_pos,
+                                           cfg->boxLength, 
+                                           cfg->yBox, 
+                                           cfg->diffTol, 
+                                           cfg->loPos, 
+                                 cfg->hiPos );
+      if (fit < 0) {
+     sinfo_msg_error( "sinfo_new_fit_slits_boltz failed" );
+         goto cleanup;
+      }
+    } else {
+      sinfo_msg("sinfo_new_fit_slits_edge");
+      fit = sinfo_new_fit_slits_edge(im, 
+                               par, 
+                               sinfo_slit_pos, 
+                               cfg->boxLength, 
+                               cfg->yBox, 
+                               cfg->diffTol );
+      if (fit < 0) {
+    sinfo_msg_error("sinfo_new_fit_slits_edge failed" );
+        goto cleanup;
+      }
+    }
+  } else {
+    sinfo_msg_error("no indication of desired fit function given" );
+    goto cleanup;
+  }
+  sinfo_free_image(&im);
+
+  /* #store the resulting sitlet positions in an TFITS table */
+  check_nomsg(tbl_spos = cpl_table_new(32));
+  check_nomsg(cpl_table_new_column(tbl_spos,"pos1", CPL_TYPE_DOUBLE));
+  check_nomsg(cpl_table_new_column(tbl_spos,"pos2", CPL_TYPE_DOUBLE));
+  check_nomsg(cpl_table_set_column_format(tbl_spos,"pos1", "15.9f"));
+  check_nomsg(cpl_table_set_column_format(tbl_spos,"pos2", "15.9f"));
+
+  for (i =0; i< 32; i++) {
+    cpl_table_set_double(tbl_spos,"pos1",i,
+                         sinfo_new_array2D_get_value(sinfo_slit_pos,i,0));
+    cpl_table_set_double(tbl_spos,"pos2",i,
+                         sinfo_new_array2D_get_value(sinfo_slit_pos,i,1));
+     
+  }
+  if(sw == 1) {
+    strcpy(tbl_name,"out_slitpos_guess.fits");
+    ck0(sinfo_pro_save_tbl(tbl_spos,ref_set,sof,tbl_name,
+               PRO_SLIT_POS_GUESS,NULL,plugin_id,config),
+    "cannot save tbl %s", tbl_name);
+  } else {
+    strcpy(tbl_name,cfg->slitposName);
+    ck0(sinfo_pro_save_tbl(tbl_spos,ref_set,sof,tbl_name,
+               PRO_SLIT_POS,NULL,plugin_id,config),
+    "cannot save tbl %s", tbl_name);
+  }
+  sinfo_free_table(&tbl_spos);
+  sinfo_new_destroy_2Dfloatarray ( &sinfo_slit_pos, 32 );
+  }
+
+  if ( (cfg->slitposIndicator == 1 && cfg->estimateIndicator != 1) || 
+       (cfg->calibIndicator == 1)  || (cfg->wavemapInd == 1) ){
+    sinfo_new_destroy_fit_params(&par);
+  }
+
+
+
+
+
+  if(pdensity > 1) {
+     check_nomsg(sinfo_image_resample(plugin_id,config,sof,ref_set));
+
+
+/**
+  //RESAMPLE ThAr frame for QC
+  double dis=0;
+  float mi=0;
+  float ma=0;
+  double cwav=0;
+  int cpix=0;
+  const cpl_frame* frm=NULL;
+  char wstk_name[80];
+  char map_name[80];
+  cpl_image* res_ima=NULL;
+  int ncoeffs=3;
+  int nrows=SINFO_RESAMP_NROWS;
+
+  check_nomsg(p = cpl_parameterlist_find(config,
+                                         "sinfoni.wavecal.n_coeffs"));
+
+  check_nomsg(ncoeffs=cpl_parameter_get_int(p));
+
+  check_nomsg(frm=cpl_frameset_find_const(sof,PRO_WAVE_LAMP_STACKED));
+  check_nomsg(strcpy(wstk_name,cpl_frame_get_filename(frm)));
+  check_nomsg(wstk_img=cpl_image_load(wstk_name,CPL_TYPE_FLOAT,0,0));
+
+
+
+  check_nomsg(frm=cpl_frameset_find_const(sof,PRO_WAVE_MAP));
+  check_nomsg(strcpy(map_name,cpl_frame_get_filename(frm)));
+  check_nomsg(map_img=cpl_image_load(map_name,CPL_TYPE_FLOAT,0,0));
+
+
+
+  cknull(res_ima = sinfo_new_defined_resampling(wstk_img, 
+						map_img, 
+						ncoeffs,
+						&nrows,
+						&dis,
+						&mi,
+						&ma,
+						&cwav,
+						&cpix),
+	 " sinfo_definedResampling() failed" ) ;
+
+
+
+  ck0(sinfo_pro_save_ima(res_ima,ref_set,sof,WAVECAL_RESAMPLED_OUT_FILENAME,
+			 PRO_RESAMPLED_WAVE,NULL,plugin_id,config),
+      "cannot save ima %s",WAVECAL_RESAMPLED_OUT_FILENAME);
+
+
+  sinfo_free_image(&map_img);
+  sinfo_free_image(&res_ima);
+  sinfo_free_image(&wstk_img);
+
+  sinfo_qc_wcal_delete(&qc);
+*/
+  }
+  sinfo_free_frameset(&raw);
+  sinfo_qc_wcal_delete(&qc);
+  sinfo_wavecal_free(&cfg);
+
+  return 0;
+
+  cleanup:
+  sinfo_free_image(&map_img);
+  //sinfo_free_image(&wstk_img);
+  sinfo_free_table(&tbl_spos);
+  sinfo_free_table(&tbl_fitpar);
+  sinfo_free_image(&map_img);
+  sinfo_free_table(&tbl_wcal);
+  sinfo_free_table(&tbl_fp) ;
+  sinfo_free_table(&tbl_line_list);
+  sinfo_free_table(&tbl_wcal);
+  sinfo_free_table(&qclog_tbl);
+  sinfo_free_image(&map_img);
+  sinfo_new_destroy_fit_params(&par);
+  sinfo_new_destroy_2Dfloatarray ( &sinfo_slit_pos, 32 );
+  sinfo_new_destroy_2Dfloatarray ( &wavelength_clean, lx );
+  sinfo_new_destroy_2Dintarray (&row_clean, lx);
+  sinfo_new_destroy_intarray(&n_found_lines );
+  sinfo_new_destroy_intarray(&sum_pointer );
+  if(acoefs!=NULL) {
+     sinfo_new_destroy_2Dfloatarray(&acoefs,cfg->nrDispCoefficients);
+  }
+  sinfo_free_table(&tbl_line_list);
+  sinfo_free_image(&im);
+  sinfo_wavecal_free(&cfg);
+  sinfo_free_frameset(&raw);
+  sinfo_qc_wcal_delete(&qc);
+  return -1 ;
+
+}
+
+
+
+
+
+
+
+
+
+
+
+
+static cpl_error_code
+sinfo_image_resample(const char* plugin_id,
+                     cpl_parameterlist* config,
+                     cpl_frameset* sof,
+                     cpl_frameset* ref_set)
+{
+  //RESAMPLE ThAr frame for QC
+  double dis=0;
+  float mi=0;
+  float ma=0;
+  double cwav=0;
+  int cpix=0;
+  const cpl_frame* frm=NULL;
+  char wstk_name[80];
+  char map_name[80];
+  cpl_image* res_ima=NULL;
+  int ncoeffs=3;
+  int nrows=SINFO_RESAMP_NROWS;
+  cpl_parameter* p=NULL;
+  cpl_image* wstk_img=NULL;
+  cpl_image* map_img=NULL;
+
+  check_nomsg(p = cpl_parameterlist_find(config,
+                                         "sinfoni.wavecal.n_coeffs"));
+
+  check_nomsg(ncoeffs=cpl_parameter_get_int(p));
+
+  check_nomsg(frm=cpl_frameset_find_const(sof,PRO_WAVE_LAMP_STACKED));
+  check_nomsg(strcpy(wstk_name,cpl_frame_get_filename(frm)));
+  check_nomsg(wstk_img=cpl_image_load(wstk_name,CPL_TYPE_FLOAT,0,0));
+
+
+
+  check_nomsg(frm=cpl_frameset_find_const(sof,PRO_WAVE_MAP));
+  check_nomsg(strcpy(map_name,cpl_frame_get_filename(frm)));
+  check_nomsg(map_img=cpl_image_load(map_name,CPL_TYPE_FLOAT,0,0));
+
+
+
+  cknull(res_ima = sinfo_new_defined_resampling(wstk_img, 
+						map_img, 
+						ncoeffs,
+						&nrows,
+						&dis,
+						&mi,
+						&ma,
+						&cwav,
+						&cpix),
+	 " sinfo_definedResampling() failed" ) ;
+
+
+
+  ck0(sinfo_pro_save_ima(res_ima,ref_set,sof,WAVECAL_RESAMPLED_OUT_FILENAME,
+			 PRO_RESAMPLED_WAVE,NULL,plugin_id,config),
+      "cannot save ima %s",WAVECAL_RESAMPLED_OUT_FILENAME);
+
+
+  cleanup:
+
+  sinfo_free_image(&map_img);
+  sinfo_free_image(&res_ima);
+  sinfo_free_image(&wstk_img);
+  return cpl_error_get_code();
+
+
+}
+/**@}*/
diff --git a/sinfoni/sinfo_new_wave_cal_slit2.h b/sinfoni/sinfo_new_wave_cal_slit2.h
new file mode 100644
index 0000000..89040ff
--- /dev/null
+++ b/sinfoni/sinfo_new_wave_cal_slit2.h
@@ -0,0 +1,133 @@
+#ifndef SINFO_NEW_WAVE_CAL_SLIT2_H
+#define SINFO_NEW_WAVE_CAL_SLIT2_H
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/****************************************************************************
+* E.S.O. - VLT project
+*
+* "@(#) $Id: sinfo_new_wave_cal_slit2.h,v 1.7 2007/09/21 14:13:43 amodigli Exp $"
+*
+* who       when      what
+* --------  --------  ----------------------------------------------
+* amodigli  17/09/03  created
+*/
+
+/************************************************************************
+ * sinfo_new_wave_cal_slit2.h
+
+  Normal method:
+
+  does the wavelength calibration and the fitting of the slitlet sinfo_edge 
+  positions (ASCII file 32 x 2 values) if wished
+  produces an array of the bcoefs and of the fit parameters if wished and a 
+  wavelength calibration map input is an emission line frame and a line list
+
+  o searching for lines by cross sinfo_correlation with a line list
+  o Gaussian fitting of emission lines in each column->positions of the lines->
+    resulting fit parameters can be stored in an ASCII file
+  o Fitting of a polynomial to the line positions for each column
+  o Smoothing: fitting of each polynomial coefficient by another polynomial
+    across the whole frame -> resulting polynomial coefficients can be stored 
+    in an ASCII file.
+  o Wavelength calibration map (micron value for each frame pixel) can be
+    produced by using these coefficients and a cross sinfo_correlation to the
+    original frame
+
+  o The slitlet sinfo_edge positions can be fitted:
+    1) Automatically (not really stable) or by using guess sinfo_edge positions
+    2) By using a Boltzmann or a linear slope function
+
+
+  Slit method:
+
+  does the wavelength calibration and the fitting of the slitlet sinfo_edge 
+  positions (ASCII file 32 x 2 values) if wished produces a list of the fit 
+  parameters and of the smoothed coefficients if wished and a wavelength 
+  calibration map input is an emission line frame and a line list
+
+  o Does the same as other method but smoothes the found polynomial 
+    coefficients within each slitlet and not over the whole frame.
+
+  o Produces always a wavelength calibration map and does not crosscorrelate.
+
+ *----------------------------------------------------------------------
+ */
+
+/*
+ * header files
+ */
+
+#include <cpl.h>   
+#include "sinfo_msg.h"
+
+/*----------------------------------------------------------------------------
+ *                        Function ANSI C prototypes
+ *--------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+   Function     :       sinfo_new_wave_cal_slit2()
+   In           :       ini_file: file name of according .ini file
+   Out          :       integer (0 if it worked, -1 if it doesn't) 
+   Job          :
+
+
+  Normal method:
+
+  does the wavelength calibration and the fitting of the slitlet sinfo_edge 
+  positions (ASCII file 32 x 2 values) if wished
+  produces an array of the bcoefs and of the fit parameters if wished and a 
+  wavelength calibration map input is an emission line frame and a line list
+
+
+  o searching for lines by cross sinfo_correlation with a line list
+  o Gaussian fitting of emission lines in each column->positions of the lines->
+    resulting fit parameters can be stored in an ASCII file
+  o Fitting of a polynomial to the line positions for each column
+  o Smoothing: fitting of each polynomial coefficient by another polynomial
+    across the whole frame -> resulting polynomial coefficients can be stored 
+    in an ASCII file.
+  o Wavelength calibration map (micron value for each frame pixel) can be
+    produced by using these coefficients and a cross sinfo_correlation to the
+    original frame
+
+  o The slitlet sinfo_edge positions can be fitted:
+    1) Automatically (not really stable) or by using guess sinfo_edge positions
+    2) By using a Boltzmann or a linear slope function
+
+  Slit method:
+
+  does the wavelength calibration and the fitting of the slitlet sinfo_edge 
+  positions (ASCII file 32 x 2 values) if wished produces a list of the fit 
+  parameters and of the smoothed coefficients if wished and a wavelength 
+  calibration map input is an emission line frame and a line list
+
+  o Does the same as other method but smoothes the found polynomial 
+    coefficients within each slitlet and not over the whole frame.
+
+  o Produces always a wavelength calibration map and does not crosscorrelate.
+ ---------------------------------------------------------------------------*/
+int 
+sinfo_new_wave_cal_slit2 (const char* plugin_id,
+                          cpl_parameterlist* config, 
+                          cpl_frameset* sof,cpl_frameset* ref_set) ;
+
+
+#endif 
+
+/*--------------------------------------------------------------------------*/
diff --git a/sinfoni/sinfo_north_south_test_config.c b/sinfoni/sinfo_north_south_test_config.c
new file mode 100644
index 0000000..fc6c234
--- /dev/null
+++ b/sinfoni/sinfo_north_south_test_config.c
@@ -0,0 +1,162 @@
+/* $Id: sinfo_north_south_test_config.c,v 1.5 2012/03/03 09:50:08 amodigli Exp $
+ *
+ * This file is part of the CPL (Common Pipeline Library)
+ * Copyright (C) 2002 European Southern Observatory
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*
+ * $Author: amodigli $
+ * $Date: 2012/03/03 09:50:08 $
+ * $Revision: 1.5 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+ /****************************************************************
+  *   North_South_Test Frames Data Reduction Parameter Initialization        *
+  ****************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+#include "sinfo_north_south_test_config.h"
+/**@{*/
+/**
+ * @addtogroup sinfo_rec_distortion North South test configuration
+ *
+ * TBD
+ */
+
+
+/**
+ at name sinfo_north_south_test_config_add
+ at brief set parameters and their defaults for north south test
+ at param list parameterlist
+ at return void
+*/
+void
+ sinfo_north_south_test_config_add(cpl_parameterlist *list)
+{
+
+  cpl_parameter *p;
+
+  if (!list) {
+    return;
+  }
+  /* Clean Mean */
+  p = cpl_parameter_new_range("sinfoni.north_south_test.low_rejection",
+                  CPL_TYPE_DOUBLE,
+                              "lower rejection: "
+                              "percentage of rejected low intensity pixels "
+                              "before averaging",
+                              "sinfoni.north_south_test",
+                               0.1,0.0,1.0);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"ns-lo_rej");
+  cpl_parameterlist_append(list, p);
+
+  p = cpl_parameter_new_range("sinfoni.north_south_test.high_rejection",
+                  CPL_TYPE_DOUBLE,
+                              "higher rejection: "
+                              "percentage of rejected high intensity pixels "
+                              "before averaging",
+                              "sinfoni.north_south_test",
+                              0.1,0.0,1.0);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"ns-hi_rej");
+  cpl_parameterlist_append(list, p);
+
+
+  p = cpl_parameter_new_value("sinfoni.north_south_test.mask_ind",
+                  CPL_TYPE_BOOL,
+                              "Mask Index: "
+                             "indicator if a bad pixel mask is applied or not",
+                              "sinfoni.north_south_test",
+                              FALSE);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"ns-mask_ind");
+  cpl_parameterlist_append(list, p);
+
+
+
+  /* Gauss Convolution */
+  p = cpl_parameter_new_value("sinfoni.north_south_test.gauss_ind",
+                  CPL_TYPE_BOOL,
+                              "Gauss Index: ",
+                              "sinfoni.north_south_test",
+                              FALSE);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"ns-gauss_ind");
+  cpl_parameterlist_append(list, p);
+
+  p = cpl_parameter_new_value("sinfoni.north_south_test.kernel_half_width",
+                  CPL_TYPE_INT,
+                              "Kernel Half Width "
+                              "kernel half width of the Gaussian "
+                              "response function",
+                              "sinfoni.north_south_test",
+                               2);
+
+  cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI, "ns-khw");
+  cpl_parameterlist_append(list, p);
+
+
+
+  /* North South Test */
+
+
+  p = cpl_parameter_new_value("sinfoni.north_south_test.half_width",
+                  CPL_TYPE_INT,
+                              "Half Width",
+                              "sinfoni.north_south_test",
+                               4);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"ns-hw");
+  cpl_parameterlist_append(list, p);
+
+  p = cpl_parameter_new_value("sinfoni.north_south_test.fwhm",
+                  CPL_TYPE_DOUBLE,
+                              "FWHM",
+                              "sinfoni.north_south_test",
+                               2.);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"ns-fwhm");
+  cpl_parameterlist_append(list, p);
+
+
+  p = cpl_parameter_new_value("sinfoni.north_south_test.min_diff",
+                  CPL_TYPE_DOUBLE,
+                              "Minimum of Difference",
+                              "sinfoni.north_south_test",
+                              1.);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"ns-min_diff");
+  cpl_parameterlist_append(list, p);
+
+
+
+  p = cpl_parameter_new_value("sinfoni.north_south_test.dev_tol",
+                  CPL_TYPE_DOUBLE,
+                              "Dev Tol",
+                              "sinfoni.north_south_test",
+                              20.);
+
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"ns-dev_tol");
+  cpl_parameterlist_append(list, p);
+
+
+
+}
diff --git a/sinfoni/sinfo_north_south_test_config.h b/sinfoni/sinfo_north_south_test_config.h
new file mode 100644
index 0000000..bc29e17
--- /dev/null
+++ b/sinfoni/sinfo_north_south_test_config.h
@@ -0,0 +1,34 @@
+/* $Id: sinfo_north_south_test_config.h,v 1.1 2006/10/20 08:06:32 amodigli Exp $
+ *
+ * This file is part of the CPL (Common Pipeline Library)
+ * Copyright (C) 2002 European Southern Observatory
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*
+ * $Author: amodigli $
+ * $Date: 2006/10/20 08:06:32 $
+ * $Revision: 1.1 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+ /****************************************************************
+  *   North_South_Test Frames Data Reduction Parameter Initialization        *
+  ****************************************************************/
+#include "cpl.h"    /* defines parlist structure */
+
+void
+sinfo_north_south_test_config_add(cpl_parameterlist *list);
+
diff --git a/sinfoni/sinfo_ns_cfg.c b/sinfoni/sinfo_ns_cfg.c
new file mode 100644
index 0000000..1662e26
--- /dev/null
+++ b/sinfoni/sinfo_ns_cfg.c
@@ -0,0 +1,84 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/*---------------------------------------------------------------------------
+   
+   File name     :    sinfo_ns_cfg.c
+   Author     :       Juergen Schreiber
+   Created on    :    November 2001
+   Description    :    configuration handling tools for the north-south test
+
+ *--------------------------------------------------------------------------*/
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+/*---------------------------------------------------------------------------
+                                   Includes
+ ---------------------------------------------------------------------------*/
+
+#include "sinfo_ns_cfg.h"
+
+/*---------------------------------------------------------------------------
+                              Function codes
+ ---------------------------------------------------------------------------*/
+/**@{*/
+/**
+ * @addtogroup sinfo_rec_distortion North South Test structure configuration
+ *
+ * TBD
+ */
+
+/*---------------------------------------------------------------------------
+   Function :   sinfo_ns_cfg_create()
+   In       :   void
+   Out      :   pointer to allocated base ns_config structure
+   Job      :   allocate memory for a ns_config struct
+   Notice   :   only the main (base) structure is allocated
+ ---------------------------------------------------------------------------*/
+
+ns_config * sinfo_ns_cfg_create(void)
+{
+    return cpl_calloc(1, sizeof(ns_config));
+}
+
+
+/*---------------------------------------------------------------------------
+   Function :   sinfo_ns_cfg_destroy()
+   In       :   ns_config to deallocate
+   Out      :   void
+   Job      :   deallocate all memory associated with a ns_config data structure
+   Notice   :   
+ ---------------------------------------------------------------------------*/
+
+void sinfo_ns_cfg_destroy(ns_config * nc)
+{
+    if (nc==NULL) return ;
+
+    /*cpl_free(nc->frametype);*/
+
+    /* Free main struct */
+    cpl_free(nc);
+
+    return ;
+}
+
+/**@}*/
+
+
diff --git a/sinfoni/sinfo_ns_cfg.h b/sinfoni/sinfo_ns_cfg.h
new file mode 100644
index 0000000..30872e0
--- /dev/null
+++ b/sinfoni/sinfo_ns_cfg.h
@@ -0,0 +1,118 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*---------------------------------------------------------------------------
+   
+   File name     :    sinfo_ns_cfg.h
+   Author    :    Juergen Schreiber
+   Created on    :    November 2001
+   Description    :    ns_ini definitions + handling prototypes
+
+ ---------------------------------------------------------------------------*/
+#ifndef SINFO_NS_CFG_H
+#define SINFO_NS_CFG_H
+/*---------------------------------------------------------------------------
+                                   Includes
+ ---------------------------------------------------------------------------*/
+#include <stdlib.h>
+#include "sinfo_globals.h"
+#include <cpl.h>
+/*---------------------------------------------------------------------------
+                                   Defines
+ ---------------------------------------------------------------------------*/
+/*---------------------------------------------------------------------------
+                                   New types
+ ---------------------------------------------------------------------------*/
+/*
+  data cube creation blackboard container
+
+  This structure holds all information related to the cube creation
+  routine. It is used as a container for the flux of ancillary data,
+  computed values, and algorithm status. Pixel flux is separated from
+  the blackboard.
+  */
+
+typedef struct ns_config {
+/*-------General---------*/
+        char inList[FILE_NAME_SZ] ;  /* name of the input file list 
+                                        containing the on and off-frames */ 
+        char outName[FILE_NAME_SZ] ; /* output name of the ASCII list 
+                                        containing the determined distances */
+        char ** framelist ; /* list of frames */
+        int  *  frametype ; /* list of frame types on or off */
+        int     nframes ;   /* number of frames in frame list */
+        int     nobj ;      /* number of object frames in frame list */
+        int     noff ;      /* number of off frames in frame list */
+
+/*------ CleanMean ------*/
+        /* percentage of rejected low intensity pixels */
+        float loReject ;
+        /* percentage of rejected high intensity pixels */
+        float hiReject ;
+        /* indicator if a bad pixel mask is applied or not */
+        int maskInd ;
+        /* file name of the bad pixel mask fits file */
+        char mask[FILE_NAME_SZ] ;
+/*------ GaussConvolution ------*/
+        /* indicator if Gaussian convolution is applied or not */
+        int gaussInd ;
+        /* kernel half width of the Gaussian response function */
+        int hw ;
+/*------ NorthSouthTest ------*/
+        /* name of the averaged output fits frame */
+        char fitsname[FILE_NAME_SZ] ;      
+        /* number of slitlets */
+        int nslits ;      
+        /* pixel half width of a box within which the spatial profile 
+           is fitted by a Gaussian */
+        int halfWidth ;
+        /* first guess of the fwhm of the Gaussian fit function */
+        float fwhm ;
+        /* minimum amplitude above which the fit is carried out */
+        float minDiff ;
+        /* estimated average distance of spectra */
+        float estimated_dist ;
+        /* maximal pixel tolerance of the slitlet distances */
+        float devtol ;
+} ns_config ;
+
+
+
+/*---------------------------------------------------------------------------
+                               Function prototypes
+ ---------------------------------------------------------------------------*/
+/**
+   @name    sinfo_ns_cfg_create()
+   @memo    allocate memory for a ns_cfg struct
+   @return  pointer to allocated base ns_cfg structure
+   @note    only the main (base) structure is allocated
+*/
+
+ns_config * 
+sinfo_ns_cfg_create(void);
+/**
+   @name sinfo_ns_cfg_destroy()
+   @param ns_config to deallocate
+   @return  void
+   @doc  deallocate all memory associated with a ns_config data structure
+*/
+
+void 
+sinfo_ns_cfg_destroy(ns_config * nc);
+
+#endif
diff --git a/sinfoni/sinfo_ns_ini.h b/sinfoni/sinfo_ns_ini.h
new file mode 100644
index 0000000..856e8b9
--- /dev/null
+++ b/sinfoni/sinfo_ns_ini.h
@@ -0,0 +1,76 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+   
+   File name    :   sinfo_ns_ini.h
+   Author       :    Juergen Schreiber
+   Created on   :    Nov 29, 2001
+   Description  :    ini file handling for the north-south-test, that means
+                        the determination of the distances of the slitlets to 
+                        each other.
+ ---------------------------------------------------------------------------*/
+#ifndef SINFO_NS_INI_H
+#define SINFO_NS_INI_H
+/*---------------------------------------------------------------------------
+                                Includes
+---------------------------------------------------------------------------*/
+#include <cpl.h>
+#include "sinfo_ns_cfg.h"
+/*---------------------------------------------------------------------------
+                                Defines
+---------------------------------------------------------------------------*/
+#define FRAME_ON   1     /* object frames */
+#define FRAME_OFF  0     /* off frames */
+/*----------------------------------------------------------------------------
+                             Function prototypes 
+ ---------------------------------------------------------------------------*/
+/**
+  @name        generateNS_ini_file
+  @memo        Generate a default ini file for the cube creation command.
+  @param    ini_name    Name of the file to generate.
+  @param    name_i        Name of the input file list.
+  @param    name_o        Name of the output file.
+  @return    int 0 if Ok, -1 otherwise.
+  @doc
+
+  This function generates a default ini file for the cube creation command. The
+  generated file will have the requested name. If you do not want to
+  provide names for the input/output/calib files, feed either NULL pointers
+  or character strings starting with (char)0.
+ */
+int generateNS_ini_file(
+        char * ini_name,
+        char * name_i,
+        char * name_o
+);
+
+/**
+  @name     parse_ns_ini_file
+  @memo     Parse a ini_name.ini file and create a blackboard.
+  @param    ini_name    Name of the ASCII file to parse.
+  @return   1 newly allocated ns_config blackboard structure.
+  @doc
+
+  The requested ini file is parsed and a blackboard object is created, then
+  updated accordingly. Returns NULL in case of error.
+ */
+
+ns_config * parse_ns_ini_file(char * ini_name) ;
+
+#endif
diff --git a/sinfoni/sinfo_ns_ini_by_cpl.c b/sinfoni/sinfo_ns_ini_by_cpl.c
new file mode 100644
index 0000000..4dc64f7
--- /dev/null
+++ b/sinfoni/sinfo_ns_ini_by_cpl.c
@@ -0,0 +1,364 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/*----------------------------------------------------------------------------
+   
+   File name    :   sinfo_ns_ini_by_cpl.c
+   Author       :   Andrea Modigliani
+   Created on   :   May 19, 2003
+   Description  :   cpl input handling for the north-south test
+
+ ---------------------------------------------------------------------------*/
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+
+/*---------------------------------------------------------------------------
+                                Includes
+ ---------------------------------------------------------------------------*/
+
+#include <string.h>
+#include "sinfo_ns_ini_by_cpl.h"
+#include "sinfo_pro_types.h"
+#include "sinfo_hidden.h"
+#include "sinfo_functions.h"
+#include "sinfo_file_handling.h"
+
+/*---------------------------------------------------------------------------
+                    Functions private to this module
+ ---------------------------------------------------------------------------*/
+void sinfo_ns_free_alloc(ns_config * cfg);
+static void     
+parse_section_frames (ns_config *,cpl_parameterlist* cpl_cfg,cpl_frameset* sof,
+                     cpl_frameset** raw, int* status);
+static void     
+parse_section_cleanmean (ns_config *,cpl_parameterlist* cpl_cfg);
+static void     
+parse_section_gaussconvolution (ns_config *,cpl_parameterlist* cpl_cfg);
+static void     
+parse_section_northsouthtest(ns_config *,cpl_parameterlist* cpl_cfg);
+
+
+/**@{*/
+/**
+ * @addtogroup sinfo_rec_distortion North South Test initialization
+ *
+ * TBD
+ */
+
+
+
+/* removed generateNS_ini_file */
+
+/*-------------------------------------------------------------------------*/
+/**
+  @name     parse_ns_ini_file
+  @memo     Parse a ini_name.ini file and create a blackboard.
+  @param    ini_name    Name of the ASCII file to parse.
+  @return   1 newly allocate ns_config blackboard structure.
+  @doc
+
+  The requested ini file is parsed and a blackboard object is created, then
+  updated accordingly. Returns NULL in case of error.
+ */
+/*--------------------------------------------------------------------------*/
+
+ns_config * 
+sinfo_parse_cpl_input_ns(cpl_parameterlist * cpl_cfg, cpl_frameset* sof, 
+                   cpl_frameset** raw)
+{
+        ns_config   *         cfg = sinfo_ns_cfg_create();
+        int status=0;
+        /*
+         * Perform sanity checks, fill up the structure with what was
+         * found in the ini file
+         */
+
+        parse_section_cleanmean        (cfg,cpl_cfg);
+        parse_section_gaussconvolution (cfg,cpl_cfg);
+        parse_section_northsouthtest   (cfg,cpl_cfg);
+        parse_section_frames           (cfg,cpl_cfg,sof,raw,&status);
+
+        if (status > 0) {
+                sinfo_msg_error("parsing cpl input");
+                sinfo_ns_cfg_destroy(cfg);
+                cfg = NULL ;
+                return NULL ;
+        }
+        return cfg ;
+}
+
+
+
+
+static void     
+parse_section_frames(ns_config * cfg,
+             cpl_parameterlist * cpl_cfg,
+             cpl_frameset * sof,
+             cpl_frameset ** raw,
+                     int* status)
+{
+   int                     i;
+   int                     nobj ;
+   int                     noff ;
+    int nraw=0;
+   char* tag;
+   cpl_frame* frame   = NULL;
+   cpl_parameter *p;   
+  char spat_res[FILE_NAME_SZ];
+   char lamp_status[FILE_NAME_SZ];
+   char band[FILE_NAME_SZ];
+   int ins_set=0;
+   nstpar* nstp=sinfo_nstpar_new();
+  
+   sinfo_extract_raw_frames_type(sof,raw,PRO_FIBRE_NS_STACKED_DIST);
+  
+   nraw    = cpl_frameset_get_size(*raw);
+
+    if(nraw == 0) {
+     sinfo_msg_error("No input raw frames");
+     sinfo_nstpar_delete(nstp);
+     (*status)++;
+     return;
+   }
+
+   /* Allocate structures to go into the blackboard */
+   cfg->framelist     = cpl_malloc(nraw * sizeof(char*));
+   cfg->frametype     = cpl_malloc(nraw * sizeof(int));
+
+
+    
+   /* Browse through the charmatrix to get names and file types */
+   i=0 ;
+   nobj = 0 ;
+   noff = 0 ;
+   
+   for (i=0 ; i<nraw ; i++) {
+      frame = cpl_frameset_get_frame(*raw,i);
+      if(sinfo_file_exists((char*) cpl_frame_get_filename(frame))==1) 
+    {
+      /* to go on the file must exist */
+       tag=(char*) cpl_frame_get_tag(frame);
+      if(cpl_frame_get_tag(frame) != NULL) {
+        /* If the frame has a tag we process it. Else it is an object */ 
+            if((sinfo_frame_is_on(frame)  == 0)) 
+          {
+            cfg->framelist[i]=(char*) cpl_frame_get_filename(frame);
+            cfg->frametype[i] = FRAME_OFF ;
+            noff++;
+          }
+            else if(sinfo_is_sky_flat(tag))
+          {
+            cfg->framelist[i]=(char*) cpl_frame_get_filename(frame);
+            cfg->frametype[i] = FRAME_OFF ;
+            noff++;
+          }
+            else if((sinfo_frame_is_on(frame)  == 1)) 
+          {
+            cfg->framelist[i]=(char*) cpl_frame_get_filename(frame);
+            cfg->frametype[i] = FRAME_ON ;
+            nobj++;
+          }
+            else  
+              {
+          /* without label the frame is assumed on */
+          cfg->framelist[i]=(char*) cpl_frame_get_filename(frame);
+          cfg->frametype[i] = FRAME_ON ;
+          nobj++;
+        }
+      }
+        else 
+      {
+        /* without label the frame is assumed on */
+          cfg->framelist[i]=(char*) cpl_frame_get_filename(frame);
+          cfg->frametype[i] = FRAME_ON ;
+          nobj++;
+      }
+       /* Store file name into framelist */
+    }
+      else {
+      sinfo_msg_warning("file %s does not exist",
+          cpl_frame_get_filename(frame));
+    }
+        
+    }
+
+
+   if((noff == 0) && (nobj == 0)) {
+     sinfo_msg_error("Wrong input frames");
+     sinfo_nstpar_delete(nstp);
+     sinfo_ns_free_alloc(cfg);
+     (*status)++;
+     return;
+   }
+   /* Copy relevant information into the blackboard */
+   cfg->nframes         = nraw ;
+   cfg->nobj            = nobj ;
+   cfg->noff            = noff ;
+
+   strcpy(cfg -> outName, NS_TEST_DISTANCES_OUT_FILENAME);
+
+
+   frame = cpl_frameset_get_frame(*raw,0);
+   sinfo_get_spatial_res(frame,spat_res);
+ 
+   switch(sinfo_frame_is_on(frame)) 
+     {
+   case 0: 
+      strcpy(lamp_status,"on");
+      break;
+    case 1: 
+      strcpy(lamp_status,"off");
+      break;
+    case -1:
+      strcpy(lamp_status,"undefined");
+      break;
+    default: 
+      strcpy(lamp_status,"undefined");
+      break;
+
+
+     }
+
+   sinfo_get_band(frame,band);
+   sinfo_msg("Spatial resolution: %s lamp_status: %s band: %s \n",
+                     spat_res,    lamp_status,    band);
+
+
+   sinfo_get_ins_set(band,&ins_set);
+
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.north_south_test.fwhm");
+   if(cpl_parameter_get_double(p) != cpl_parameter_get_default_double(p)) {
+     cfg -> fwhm = cpl_parameter_get_double(p);
+   } else {
+     cfg -> fwhm = nstp->fwhm[ins_set];
+   }
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.north_south_test.min_diff");
+   if(cpl_parameter_get_double(p) != cpl_parameter_get_default_double(p)) {
+     cfg -> minDiff = cpl_parameter_get_double(p);
+   } else {
+     cfg -> minDiff = nstp->min_dif[ins_set];
+   }
+    sinfo_nstpar_delete(nstp);
+
+
+   if(cfg -> maskInd) {
+      if(NULL != cpl_frameset_find(sof,PRO_BP_MAP_DI)) {
+         frame = cpl_frameset_find(sof,PRO_BP_MAP_DI);
+         strcpy(cfg -> mask,cpl_frame_get_filename(frame));
+      } else {
+         sinfo_msg_error("Frame %s not found! Exit!", PRO_BP_MAP_DI);
+         sinfo_ns_free_alloc(cfg);
+         (*status)++;
+         return;
+      }
+   }
+
+ 
+     return ;
+}
+
+static void     
+parse_section_cleanmean(ns_config * cfg,cpl_parameterlist * cpl_cfg)
+{
+
+   cpl_parameter *p;                  
+   p = cpl_parameterlist_find(cpl_cfg, 
+                             "sinfoni.north_south_test.low_rejection");
+   cfg -> loReject = cpl_parameter_get_double(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, 
+                              "sinfoni.north_south_test.high_rejection");
+   cfg -> hiReject = cpl_parameter_get_double(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.north_south_test.mask_ind");
+   cfg -> maskInd = cpl_parameter_get_bool(p);
+
+   return ;
+}
+
+static void     
+parse_section_gaussconvolution(ns_config * cfg,cpl_parameterlist * cpl_cfg)
+{
+   cpl_parameter *p;     
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.north_south_test.gauss_ind");
+   cfg -> gaussInd = cpl_parameter_get_bool(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, 
+                              "sinfoni.north_south_test.kernel_half_width");
+   cfg -> hw = cpl_parameter_get_int(p);
+
+}
+
+static void     
+parse_section_northsouthtest(ns_config  * cfg,cpl_parameterlist * cpl_cfg)
+{
+
+   cpl_parameter *p;     
+   strcat(cfg -> fitsname, NS_TEST_OUT_FILENAME);
+   cfg -> nslits = NSLITLETS;
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.north_south_test.half_width");
+   cfg -> halfWidth = cpl_parameter_get_int(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.north_south_test.fwhm");
+   cfg -> fwhm = cpl_parameter_get_double(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.north_south_test.min_diff");
+   cfg -> minDiff = cpl_parameter_get_double(p);
+
+   cfg -> estimated_dist = ESTIMATED_SLITLETS_DISTANCE;
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.north_south_test.dev_tol");
+   cfg -> devtol = cpl_parameter_get_double(p);
+
+   return ;
+}
+
+void
+sinfo_ns_free(ns_config ** cfg)
+{  
+  if(*cfg!=NULL) { 
+    sinfo_ns_free_alloc(*cfg);
+    sinfo_ns_cfg_destroy(*cfg);
+    *cfg=NULL;
+  } 
+  return;
+
+}
+void
+sinfo_ns_free_alloc(ns_config * cfg)
+{
+    if(cfg->framelist != NULL) {
+      cpl_free(cfg->framelist);
+      cfg->framelist=NULL;
+    }
+    if(cfg->frametype != NULL) {
+      cpl_free(cfg->frametype);
+      cfg->frametype=NULL;
+    }
+  
+  return;
+
+}
+/**@}*/
diff --git a/sinfoni/sinfo_ns_ini_by_cpl.h b/sinfoni/sinfo_ns_ini_by_cpl.h
new file mode 100644
index 0000000..dbe5ef7
--- /dev/null
+++ b/sinfoni/sinfo_ns_ini_by_cpl.h
@@ -0,0 +1,69 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+   
+   File name    :   sinfo_ns_ini.h
+   Author       :   Andrea Modigliani
+   Created on   :   May 19, 2004
+   Description  :    parse cpl input for the north-south-test, that means
+                        the determination of the distances of the slitlets to 
+                        each other.
+ ---------------------------------------------------------------------------*/
+#ifndef SINFO_NS_INI_BY_CPL_H
+#define SINFO_NS_INI_BY_CPL_H
+/*---------------------------------------------------------------------------
+                                Includes
+---------------------------------------------------------------------------*/
+#include <cpl.h>
+#include "sinfo_ns_cfg.h"
+#include "sinfo_msg.h"
+/*---------------------------------------------------------------------------
+                                Defines
+---------------------------------------------------------------------------*/
+#define FRAME_ON   1     /* object frames */
+#define FRAME_OFF  0     /* off frames */
+/*----------------------------------------------------------------------------
+                             Function prototypes 
+ ---------------------------------------------------------------------------*/
+/**
+  @name     parse_ns_ini_file
+  @memo     Parse a ini_name.ini file and create a blackboard.
+  @param    cpl_cfg pointer to parameterlist
+  @param    sof pointer to input set of frames
+  @param    raw pointer to input set of raw frames
+  @return   1 newly allocated ns_config blackboard structure.
+  @doc
+
+  The requested ini file is parsed and a blackboard object is created, then
+  updated accordingly. Returns NULL in case of error.
+ */
+/*--------------------------------------------------------------------------*/
+
+ns_config * 
+sinfo_parse_cpl_input_ns(cpl_parameterlist * cpl_cfg, 
+                         cpl_frameset* sof, 
+             cpl_frameset** raw);
+/**
+ at name sinfo_ns_free
+ at memo free ns_config structure
+ at param cfg pointer to ns_config structure
+ at return void
+*/
+void sinfo_ns_free(ns_config ** cfg);
+#endif
diff --git a/sinfoni/sinfo_object_cfg.c b/sinfoni/sinfo_object_cfg.c
new file mode 100644
index 0000000..75f674a
--- /dev/null
+++ b/sinfoni/sinfo_object_cfg.c
@@ -0,0 +1,85 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/*---------------------------------------------------------------------------
+   
+   File name     :   sinfo_object_cfg.c
+   Author     :   Juergen Schreiber
+   Created on    :   April 2002
+   Description    :   configuration handling tools for the creation of an object
+                    data cube
+
+ *--------------------------------------------------------------------------*/
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+/*---------------------------------------------------------------------------
+                                   Includes
+ ---------------------------------------------------------------------------*/
+
+#include "sinfo_object_cfg.h"
+
+
+/*---------------------------------------------------------------------------
+                              Function codes
+ ---------------------------------------------------------------------------*/
+/**@{*/
+/**
+ * @addtogroup sinfo_rec_jitter Objnod structure configuration
+ *
+ * TBD
+ */
+
+/*---------------------------------------------------------------------------
+   Function :   sinfo_object_cfg_create()
+   In       :   void
+   Out      :   pointer to allocated base object_config structure
+   Job      :   allocate memory for an object_config struct
+   Notice   :   only the main (base) structure is allocated
+ ---------------------------------------------------------------------------*/
+
+object_config * sinfo_object_cfg_create(void)
+{
+    return cpl_calloc(1, sizeof(object_config));
+}
+
+
+/*---------------------------------------------------------------------------
+   Function :   sinfo_object_cfg_destroy()
+   In       :   object_config to deallocate
+   Out      :   void
+   Job      :   deallocate all memory associated with an 
+                object_config data structure
+   Notice   :   
+ ---------------------------------------------------------------------------*/
+
+void sinfo_object_cfg_destroy(object_config * cc)
+{
+    if (cc==NULL) return ;
+
+    /* Free main struct */
+    cpl_free(cc);
+
+    return ;
+}
+
+/**@}*/
+
+
diff --git a/sinfoni/sinfo_object_cfg.h b/sinfoni/sinfo_object_cfg.h
new file mode 100644
index 0000000..4dce499
--- /dev/null
+++ b/sinfoni/sinfo_object_cfg.h
@@ -0,0 +1,159 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*---------------------------------------------------------------------------
+
+   File name     :    sinfo_object_cfg.h
+   Author    :    Juergen Schreiber
+   Created on    :    April 2002
+   Description    :    object_ini definitions + handling prototypes
+
+ ---------------------------------------------------------------------------*/
+#ifndef SINFO_OBJECT_CFG_H
+#define SINFO_OBJECT_CFG_H
+/*---------------------------------------------------------------------------
+                                   Includes
+ ---------------------------------------------------------------------------*/
+#include <stdlib.h>
+#include "sinfo_globals.h"
+#include <cpl.h>
+/*---------------------------------------------------------------------------
+                                   Defines
+ ---------------------------------------------------------------------------*/
+/*---------------------------------------------------------------------------
+                                   New types
+ ---------------------------------------------------------------------------*/
+/*
+  data cube creation blackboard container
+
+  This structure holds all information related to the object
+  data cube creation routine. It is used as a container for the
+  flux of ancillary data, computed values, and algorithm status.
+  Pixel flux is separated from the blackboard.
+  */
+
+typedef struct object_config {
+/*-------General---------*/
+   char inFile[FILE_NAME_SZ]  ; /* input file of reduced jittered
+                                        data cubes of a standard star */
+   char ** framelist ; /* input averaged, bad pixel corrected, sky
+                               subtracted, flatfielded and interleaved
+                               jittered frame list */
+   char wavemap[FILE_NAME_SZ] ; /* input wavelength calibration map */
+   char mflat[FILE_NAME_SZ] ;   /* input master flat field  */
+   char outName[FILE_NAME_SZ] ; /* output name of resulting fits
+                                        data cube(s) */
+   char sky_dist[FILE_NAME_SZ] ; /* master flat corrected for distortion */
+   char mflat_dist[FILE_NAME_SZ] ; /* master flat corrected for distortion */
+   char mflat_dither_dist[FILE_NAME_SZ] ; /* master flat dithered
+                                                  corrected for distortion */
+   int     nframes ; /* number of jittered frames */
+
+/*------ jittering ------*/
+   /* jitter mode indicator: 0 for user jittering mode,
+           1 for auto jittering mode */
+   int jitterind ;
+   /* x-pixel size of the final combined data cube */
+   int size_x ;
+   /* y-pixel size of the final combined data cube */
+   int size_y ;
+   /* the name of the interpolation kernel */
+   char kernel_type[FILE_NAME_SZ] ;
+   /* the name of the final image sinfo_median of cube */
+   char med_cube_name[FILE_NAME_SZ] ;
+   /* the name of the final mask cube */
+   char maskname[FILE_NAME_SZ] ;
+   /* the name of the fits file with the polynom for the shift
+    * due atmospheric refraction */
+   char polyshiftname[FILE_NAME_SZ] ;
+
+/*------ Resampling ------*/
+   /* number of coefficients for the polynomial
+   interpolation (order + 1) */
+   int ncoeffs ;
+   /* number of rows in the resulting resampled
+           image = number of spectral bins */
+   int nrows ;
+
+/*------ Calibration ------*/
+   /* indicates if the halogen lamp feature from
+           flatfielding should be corrected for or not */
+   int halocorrectInd ;
+   /* name of the fits file of the calibrated halogen lamp spectrum */
+   char halospectrum[FILE_NAME_SZ] ;
+
+/*------ CubeCreation ------*/
+   /* indicates if the slitlet distances are determined
+           by a north-south test (1)
+           or slitlet edge fits (0) */
+   int northsouthInd  ;
+   /* name of the ASCII list of the distances of the slitlets */
+   char distlist[FILE_NAME_SZ] ;
+   /* name of the ASCII list of the fitted slitlet sinfo_edge positions */
+   char poslist[FILE_NAME_SZ] ;
+   /* number of slitlets (32) */
+   int nslits ;
+   /* sub pixel position of the column position of the left sinfo_edge of
+           the first slitlet needed if the slitlet distances were determined
+           by a north south test */
+   char firstCol[FILE_NAME_SZ] ;
+
+/*------ FineTuning ------*/
+   /* indicator for the shifting method to use */
+   char  method[FILE_NAME_SZ] ;
+   /* order of polynomial if the polynomial interpolation shifting
+           method is used */
+   int order ;
+
+/*------ SkyExtraction ------*/
+   /* percentage of rejected low value pixels when averaging the
+           sky spectra */
+   float  loReject ;
+   /* percentage of rejected high value pixels when averaging the
+           sky spectra */
+   float  hiReject ;
+   /* pixel distance tolerance to the dividing diagonal line,
+           these pixels are not considered to be sure to get only
+           "clean" sky pixels */
+   int    tolerance ;
+} object_config ;
+
+/*---------------------------------------------------------------------------
+                               Function prototypes
+ ---------------------------------------------------------------------------*/
+/**
+   @name   sinfo_object_cfg_create()
+   @memo   allocate memory for a object_cfg struct
+   @return pointer to allocated base object_cfg structure
+   @note   only the main (base) structure is allocated
+*/
+
+object_config *
+sinfo_object_cfg_create(void);
+
+
+/**
+   @name   sinfo_object_cfg_destroy()
+   @memo deallocate all memory associated with a object_config data structure
+   @param  object_config to deallocate
+   @return void
+*/
+void
+sinfo_object_cfg_destroy(object_config * cc);
+
+#endif
diff --git a/sinfoni/sinfo_object_ini.h b/sinfoni/sinfo_object_ini.h
new file mode 100644
index 0000000..2108671
--- /dev/null
+++ b/sinfoni/sinfo_object_ini.h
@@ -0,0 +1,75 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+   
+   File name    :   sinfo_object_ini.h
+   Author       :    Juergen Schreiber
+   Created on   :    April 03, 2002
+   Description  :    ini file handling for SPIFFIs creation of a data cube
+                        from a science object observation
+ ---------------------------------------------------------------------------*/
+#ifndef SINFO_OBJECT_INI_H
+#define SINFO_OBJECT_INI_H
+/*---------------------------------------------------------------------------
+                                Includes
+---------------------------------------------------------------------------*/
+#include <cpl.h>
+#include "sinfo_object_cfg.h"
+/*----------------------------------------------------------------------------
+                             Function prototypes 
+ ---------------------------------------------------------------------------*/
+/**
+  @name        generateObject_ini_file
+  @memo        Generate a default ini file for the object cube 
+                creation command.
+  @param    ini_name    Name of the file to generate.
+  @param    name_i        Name of the input file.
+  @param    name_o        Name of the output file.
+  @param    name_c        Name of the calibration file.
+  @return    int 0 if Ok, -1 otherwise.
+  @doc
+
+  This function generates a default ini file for the object cube 
+  creation command. The
+  generated file will have the requested name. If you do not want to
+  provide names for the input/output/calib files, feed either NULL pointers
+  or character strings starting with (char)0.
+ */
+int generateObject_ini_file(
+        char * ini_name,
+        char * name_i,
+        char * name_o,
+        char * name_c
+);
+
+/**
+  @name     parse_object_ini_file
+  @memo     Parse a ini_name.ini file and create a blackboard.
+  @param    ini_name    Name of the ASCII file to parse.
+  @return   1 newly allocated object_config blackboard structure.
+  @doc
+
+  The requested ini file is parsed and a blackboard object is created, then
+  updated accordingly. Returns NULL in case of error.
+ */
+
+object_config * 
+parse_object_ini_file(char * ini_name) ;
+
+#endif
diff --git a/sinfoni/sinfo_objnod_config.c b/sinfoni/sinfo_objnod_config.c
new file mode 100644
index 0000000..655ff23
--- /dev/null
+++ b/sinfoni/sinfo_objnod_config.c
@@ -0,0 +1,411 @@
+/* $Id: sinfo_objnod_config.c,v 1.11 2012/03/03 09:50:08 amodigli Exp $
+ *
+ * This file is part of the CPL (Common Pipeline Library)
+ * Copyright (C) 2002 European Southern Observatory
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*
+ * $Author: amodigli $
+ * $Date: 2012/03/03 09:50:08 $
+ * $Revision: 1.11 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+ /****************************************************************
+  *   Objnod Frames Data Reduction Parameter Initialization        *
+  ****************************************************************/
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#include "sinfo_objnod_config.h"
+/**@{*/
+/**
+ * @addtogroup sinfo_rec_jitter Objnod parameters definition & initialization
+ *
+ * TBD
+ */
+
+/**
+ at name  sinfo_objnod_config_add
+ at brief Objnod parameters definition & initialization
+ at param list pointer to cpl_parameterlist
+ at return void
+*/
+void
+ sinfo_objnod_config_add(cpl_parameterlist *list)
+{
+
+  cpl_parameter *p;
+
+  if (!list) {
+    return;
+  }
+
+
+
+
+  /* Science */
+  p = cpl_parameter_new_enum("sinfoni.objnod.autojitter_method",
+                  CPL_TYPE_INT,
+                              "Method to reduce autojitter template frames "
+                              "Raw frames are object only exposures. "
+                              "object-fake_sky pairs are generated. "
+                              "0: no sky for all objects ",
+                              "1: fake_sky is next object, "
+                              "2: fake_sky is sinfo_median of all objects "
+                              "sinfoni.objnod",
+                               1,3,0,1,2);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"objnod-aj_method");
+  cpl_parameterlist_append(list, p);
+
+
+  /* Science */
+  p = cpl_parameter_new_value("sinfoni.objnod.scales_sky",
+                  CPL_TYPE_BOOL,
+                              "Spatial median (sky) subtraction from cube: "
+                              "(If autojitter_method==1),"
+                              "indicates if the spatial median of each plane "
+                              "should be subtracted (TRUE) or not (FALSE) "
+                              "from each cube plane",
+                              "sinfoni.objnod",
+                              FALSE);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"objnod-scales_sky");
+  cpl_parameterlist_append(list, p);
+
+
+
+  /* Science */
+  p = cpl_parameter_new_value("sinfoni.objnod.ks_clip",
+                  CPL_TYPE_BOOL,
+                              "Kappa-sigma clipping of coadded cube: "
+                              "indicates if a kappa-sigma clipping "
+                              "should be performed (TRUE) or not (FALSE) "
+                              "on each plane of the coadded cube",
+                              "sinfoni.objnod",
+                              TRUE);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"objnod-ks_clip");
+  cpl_parameterlist_append(list, p);
+
+
+  p = cpl_parameter_new_value("sinfoni.objnod.kappa",
+                  CPL_TYPE_DOUBLE,
+                              "kappa value for kappa-sigma clipping "
+                              "of coadded cube",
+                              "sinfoni.objnod",
+                              2.0);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"objnod-kappa");
+  cpl_parameterlist_append(list, p);
+
+
+
+  /*x-pixel size of the final combined data cube, must lie between 64 and 128 */
+  p = cpl_parameter_new_value("sinfoni.objnod.size_x",
+                  CPL_TYPE_INT,
+                              "Cube x size: "
+                              "x-pixel size of the final combined data cube,"
+                              "must lie between 64 and 128. "
+                              "If 0 it is computed automatically",
+                              "sinfoni.objnod",
+                              0);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"objnod-size_x");
+  cpl_parameterlist_append(list, p);
+
+
+  /*y-pixel size of the final combined data cube, must lie between 64 and 128 */
+  p = cpl_parameter_new_value("sinfoni.objnod.size_y",
+                  CPL_TYPE_INT,
+                              "Cube y size: "
+                              "y-pixel size of the final combined data cube,"
+                              "must lie between 64 and 128."
+                              "If 0 it is computed automatically",
+                              "sinfoni.objnod",
+                              0);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"objnod-size_y");
+  cpl_parameterlist_append(list, p);
+
+  /*Resampling */
+ /* number of coefficients for the polynomial interpolation */
+  p = cpl_parameter_new_value("sinfoni.objnod.n_coeffs",
+                  CPL_TYPE_INT,
+                              "number of coefficients for the polynomial "
+                              "interpolation ",
+                              "sinfoni.objnod",
+                               3);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"objnod-no_coeffs");
+  cpl_parameterlist_append(list, p);
+
+
+  /* Calibration */
+  /* indicates if the halogen lamp features from flatfielding should be 
+     corrected for or not */
+  /*
+  p = cpl_parameter_new_value("sinfoni.objnod.halo_correct_index",
+                  CPL_TYPE_BOOL,
+                              "Halo Correct Index: "
+                              "indicates if the halogen lamp features from "
+                              "flatfielding should be corrected for (TRUE) "
+                              "or not (FALSE)",
+                              "sinfoni.objnod",
+                              FALSE);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"objnod-halo_corr_ind");
+  cpl_parameterlist_append(list, p);
+  */
+
+  /* Cube Creation */
+  /*indicates if the slitlet distances are determined by a north-south-test 
+     (yes) or slitlet edge fits (no)
+  */
+  p = cpl_parameter_new_value("sinfoni.objnod.nord_south_index",
+                  CPL_TYPE_BOOL,
+                              "Nord South Index Switch: "
+                              "indicates if the slitlet distances are "
+                              "determined by a north-south-test (TRUE) "
+                              "or slitlet edge fits (FALSE)",
+                              "sinfoni.objnod",
+                              TRUE);
+
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"objnod-ns_ind");
+  cpl_parameterlist_append(list, p);
+
+  /* Fine tuning */
+  /* Method */
+  p = cpl_parameter_new_enum("sinfoni.objnod.fine_tuning_method",
+                  CPL_TYPE_STRING,
+                              "Fine Tuning Method: "
+                              "indicator for the shifting method to use "
+                              "(P: polynomial interpolation, "
+                 /* " F: FFT, " */
+                              " S: cubic spline interpolation)",
+                              "sinfoni.objnod",
+                              "P",
+                               2,
+                              "P","S");
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"objnod-fine_tune_mtd");
+  cpl_parameterlist_append(list, p);
+
+  p = cpl_parameter_new_value("sinfoni.objnod.order",
+                  CPL_TYPE_INT,
+                              "Fine Tuning polynomial order: " 
+                              "order of the polynomial if the polynomial "
+                              "interpolation shifting method is used.",
+                              "sinfoni.objnod",
+                              2);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"objnod-order");
+  cpl_parameterlist_append(list, p);
+
+  /* Sky Extraction */
+  /*Reconstruction */
+ /* the fraction [0...1] of rejected low intensity pixels when taking 
+the average of columns */
+  p = cpl_parameter_new_value("sinfoni.objnod.low_rejection",
+                  CPL_TYPE_DOUBLE,
+                              "lower rejection: "
+                              "percentage of rejected low value pixels "
+                              "for averaging the sky spectra",
+                              "sinfoni.objnod",
+                              10.);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"objnod-lo_rej");
+  cpl_parameterlist_append(list, p);
+ /* the fraction [0...1] of rejected high intensity pixels when taking 
+the average of columns */
+
+  p = cpl_parameter_new_value("sinfoni.objnod.high_rejection",
+                  CPL_TYPE_DOUBLE,
+                              "higher rejection: "
+                              "percentage of rejected high value pixels "
+                              "for averaging the sky spectra",
+                              "sinfoni.objnod",
+                              10.);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"objnod-hi_rej");
+  cpl_parameterlist_append(list, p);
+  /* pixel tolerance, this distance tolerance to the diagonal dividing 
+     line is not considered for the sky extraction to be sure to have a clean
+     sky due to positioning tolerance and crossing through pixels
+  */
+  p = cpl_parameter_new_value("sinfoni.objnod.tolerance",
+                  CPL_TYPE_INT,
+                              "Tolerance: "
+                              "pixel tolerance, this distance tolerance to "
+                              "the diagonal dividing line is not considered "
+                              "for the sky extraction to be sure to have a "
+                              "clean sky due to positioning tolerance and "
+                              "crossing through pixels",
+                              "sinfoni.objnod",
+                              2);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"objnod-tol");
+  cpl_parameterlist_append(list, p);
+  /* Jittering */
+  /* jitter mode indicator: yes: Auto-Jitter, no: user defined jitter
+     The next three parameters are only used if jitterInd is set to yes, 
+     that means in auto-jittering mode!
+  */
+  p = cpl_parameter_new_value("sinfoni.objnod.jitter_index",
+                  CPL_TYPE_BOOL,
+                              "Jitter Index: "
+                              "jitter mode indicator: "
+                              "TRUE: Auto-Jitter, "
+                              "FALSE: user defined jitter"
+                              "The size_x size_y kernel_type parameters "
+                              "are only used if jitterInd is set to yes, "
+                              "that means in auto-jittering mode!",
+                              "sinfoni.objnod",
+                              TRUE);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"objnod-jit_ind");
+  cpl_parameterlist_append(list, p);
+
+  /* Kernel Type */
+  /* the name of the interpolation kernel to shift the single cubes  to the 
+     correct places inside the big combined cube. That you want to generate 
+     using the eclipse routine sinfo_generate_interpolation_kernel()
+     Supported kernels are:
+
+                                     NULL:      default kernel, currently tanh
+                                     default: dito
+                                     tanh:    Hyperbolic tangent
+                                     sinc2:   Square sinc
+                                     lanczos: Lanczos2 kernel
+                                     hamming: Hamming kernel
+                                     hann:    Hann kernel
+  */
+  p = cpl_parameter_new_enum("sinfoni.objnod.kernel_type",
+                  CPL_TYPE_STRING,
+                              "Kernel Type:"
+                              "the name of the interpolation kernel to shift "
+                              "the single cubes  to the correct places inside "
+                 "the big combined cube",
+                              "sinfoni.objnod",
+                              "tanh",
+                               7,
+                              "NULL","default","tanh","sinc2",
+                              "lanczos","hamming","hann");
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"objnod-kernel_typ");
+  cpl_parameterlist_append(list, p);
+
+
+/* amount of vignetting from output cube before coaddition */
+  p = cpl_parameter_new_range("sinfoni.objnod.vllx",
+                  CPL_TYPE_INT,
+                              "Vignetting on llx: "
+                              "pixels vignetted from lower left corner "
+                              "X coordinate "
+                              "of contributing cubes before coaddition ",
+                              "sinfoni.objnod",
+                              0,0,63);
+
+  cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,"objnod-vllx");
+  cpl_parameterlist_append(list, p);
+
+
+  p = cpl_parameter_new_range("sinfoni.objnod.vlly",
+                  CPL_TYPE_INT,
+                              "Vignetting on lly: "
+                              "pixels vignetted from lower left corner "
+                              "Y coordinate "
+                              "of contributing cubes before coaddition ",
+                              "sinfoni.objnod",
+                              0,0,63);
+
+  cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,"objnod-vlly");
+  cpl_parameterlist_append(list, p);
+
+
+  p = cpl_parameter_new_range("sinfoni.objnod.vurx",
+                  CPL_TYPE_INT,
+                              "Vignetting on urx: "
+                              "pixels vignetted from upper right corner "
+                              "X coordinate "
+                              "of contributing cubes before coaddition ",
+                              "sinfoni.objnod",
+                              0,0,63);
+
+  cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,"objnod-vurx");
+  cpl_parameterlist_append(list, p);
+
+
+  p = cpl_parameter_new_range("sinfoni.objnod.vury",
+                  CPL_TYPE_INT,
+                              "Vignetting on ury: "
+                              "pixels vignetted from upper right corner "
+                              "Y coordinate "
+                              "of contributing cubes before coaddition ",
+                              "sinfoni.objnod",
+                              0,0,63);
+
+  cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,"objnod-vury");
+  cpl_parameterlist_append(list, p);
+
+
+  p = cpl_parameter_new_value("sinfoni.objnod.fcol",
+            CPL_TYPE_DOUBLE,
+            "First column offset: ",
+                        "sinfoni.objnod",
+                         0.);
+
+  cpl_parameter_set_alias(p,  CPL_PARAMETER_MODE_CLI,"objnod-fcol");
+  cpl_parameterlist_append(list, p);
+
+  /* switch to activate the sky residuals correction */
+  p = cpl_parameter_new_value("sinfoni.objnod.sky_cor",
+                  CPL_TYPE_BOOL,
+                              "Sky residuals correction: ",
+                              "sinfoni.objnod",
+                              TRUE);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"objnod-sky_cor");
+  cpl_parameterlist_append(list, p);
+
+
+  /* switch to activate the flux correction correction */
+  p = cpl_parameter_new_value("sinfoni.objnod.flux_cor",
+                  CPL_TYPE_BOOL,
+                              "Apply flux correction after rebinning: ",
+                              "sinfoni.objnod",
+                              TRUE);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"objnod-flux_cor");
+  cpl_parameterlist_append(list, p);
+
+
+  /* switch to activate the flux correction correction */
+  p = cpl_parameter_new_value("sinfoni.objnod.mosaic_max_size",
+			      CPL_TYPE_INT,
+                              "Maximum allowed size for cubes mosaic is "
+                              "100*mosaic_max_size ",
+                              "sinfoni.objnod",
+                              14196);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"objnod-mosaic_max_size");
+  cpl_parameterlist_append(list, p);
+
+
+}
diff --git a/sinfoni/sinfo_objnod_config.h b/sinfoni/sinfo_objnod_config.h
new file mode 100644
index 0000000..bde66bb
--- /dev/null
+++ b/sinfoni/sinfo_objnod_config.h
@@ -0,0 +1,32 @@
+/* $Id: sinfo_objnod_config.h,v 1.1 2006/10/20 08:06:32 amodigli Exp $
+ *
+ * This file is part of the CPL (Common Pipeline Library)
+ * Copyright (C) 2002 European Southern Observatory
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*
+ * $Author: amodigli $
+ * $Date: 2006/10/20 08:06:32 $
+ * $Revision: 1.1 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+ /****************************************************************
+  *   Objnod Frames Data Reduction Parameter Initialization        *
+  ****************************************************************/
+#include "cpl.h"    /* defines parlist structure */
+
+void sinfo_objnod_config_add(cpl_parameterlist *list);
diff --git a/sinfoni/sinfo_objnod_ini_by_cpl.c b/sinfoni/sinfo_objnod_ini_by_cpl.c
new file mode 100644
index 0000000..d25f42c
--- /dev/null
+++ b/sinfoni/sinfo_objnod_ini_by_cpl.c
@@ -0,0 +1,425 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/*----------------------------------------------------------------------------
+
+   File name    :   sinfo_object_ini_by_cpl.c
+   Author       :   Andrea Modigliani
+   Created on   :   May 22, 2004
+   Description  :   object cube creation cpl input handling for SPIFFI
+
+ ---------------------------------------------------------------------------*/
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+
+/*---------------------------------------------------------------------------
+                                Includes
+ ---------------------------------------------------------------------------*/
+
+#include <string.h>
+#include "sinfo_objnod_ini_by_cpl.h"
+#include "sinfo_pro_types.h"
+#include "sinfo_hidden.h"
+#include "sinfo_globals.h"
+#include "sinfo_functions.h"
+
+#include "sinfo_file_handling.h"
+
+/*---------------------------------------------------------------------------
+                    Functions private to this module
+ ---------------------------------------------------------------------------*/
+static void
+parse_section_frames(object_config *,cpl_frameset* sof,
+                     cpl_frameset** stk,  int* status);
+static void parse_section_jittering(object_config *,
+                     cpl_parameterlist * cpl_cfg);
+static void parse_section_resampling(object_config *,
+                     cpl_parameterlist * cpl_cfg);
+static void parse_section_calibration(object_config *);
+static void parse_section_cubecreation(object_config *,
+                     cpl_parameterlist * cpl_cfg);
+static void parse_section_finetuning(object_config *,
+                     cpl_parameterlist * cpl_cfg);
+static void parse_section_skyextraction(object_config *,
+                     cpl_parameterlist * cpl_cfg);
+/**@{*/
+/**
+ * @addtogroup sinfo_rec_jitter Blackboard to objnod structure
+ *
+ * TBD
+ */
+
+
+
+/*-------------------------------------------------------------------------*/
+/**
+  @name     parse_object_ini_file
+  @memo     Parse a ini_name.ini file and create a blackboard.
+  @param    ini_name    Name of the ASCII file to parse.
+  @return   1 newly allocate object_config blackboard structure.
+  @doc
+
+  The requested ini file is parsed and a blackboard object is created, then
+  updated accordingly. Returns NULL in case of error.
+ */
+/*--------------------------------------------------------------------------*/
+
+object_config *
+sinfo_parse_cpl_input_objnod(cpl_parameterlist * cpl_cfg,cpl_frameset* sof,
+               cpl_frameset** stk)
+{
+   object_config   * cfg = sinfo_object_cfg_create();
+   int status=0;
+   /*
+    * Perform sanity checks, fill up the structure with what was
+    * found in the ini file
+    */
+
+
+   parse_section_resampling   (cfg, cpl_cfg);
+   parse_section_calibration  (cfg);
+   parse_section_cubecreation (cfg, cpl_cfg);
+   parse_section_finetuning   (cfg, cpl_cfg);
+   parse_section_skyextraction(cfg, cpl_cfg);
+   parse_section_jittering    (cfg, cpl_cfg);
+   parse_section_frames       (cfg, sof,stk,&status);
+   if (status > 0) {
+                sinfo_msg_error("parsing cpl input");
+                sinfo_objnod_free(&cfg);
+                cfg = NULL ;
+                return NULL ;
+   }
+
+   return cfg ;
+}
+
+static void
+parse_section_frames(object_config * cfg,
+             cpl_frameset* sof,
+                     cpl_frameset** stk,
+                     int* status)
+{
+   int                     nraw_good =0;
+
+
+
+   int nframes=0;
+   int nraw=0;
+   cpl_frame* frame   = NULL;
+   int nstk=0;
+   int i=0;
+    char spat_res[FILE_NAME_SZ];
+   char lamp_status[FILE_NAME_SZ];
+   char band[FILE_NAME_SZ];
+   int ins_set=0;
+
+   nframes = cpl_frameset_get_size(sof);
+
+   sinfo_contains_frames_type(sof,stk,PRO_NODDING_STACKED);
+   nstk = cpl_frameset_get_size(*stk);
+
+   if (nstk == 0) {
+      sinfo_contains_frames_type(sof,stk,PRO_PSF_CALIBRATOR_STACKED);
+      nstk = cpl_frameset_get_size(*stk);
+   }
+   if (nstk == 0) {
+      sinfo_contains_frames_type(sof,stk,PRO_PUPIL_LAMP_STACKED);
+      nstk = cpl_frameset_get_size(*stk);
+   }
+   if (nstk == 0) {
+        sinfo_msg_error( "Cannot find good frames") ;
+        (*status)++;
+        return ;
+   }
+
+
+
+   /* TEMPORALLY COMMENTED OUT */
+    nraw    = cpl_frameset_get_size(*stk);
+    /* Test if the rawframes have been found */
+     if (nraw < 1) {
+        sinfo_msg_error("Cannot find input stacked frames in the input list") ;
+        (*status)++;
+        return ;
+    }
+
+   nraw    = cpl_frameset_get_size(*stk);
+   if (nraw < 1) {
+     sinfo_msg_error( "no raw frame in input, something wrong!");
+     (*status)++;
+     return ;
+   }
+
+   /* Allocate structures to go into the blackboard */
+   cfg->framelist     = cpl_malloc(nraw * sizeof(char*));
+
+  /* read input frames */
+   for (i=0 ; i<nraw ; i++) {
+      frame = cpl_frameset_get_frame(*stk,i);
+      if(sinfo_file_exists((char*)cpl_frame_get_filename(frame))==1)
+    {
+          cfg->framelist[i]=cpl_strdup(cpl_frame_get_filename(frame));
+              nraw_good++;
+    }
+      /* Store file name into framelist */
+   }
+
+
+   if (nraw_good < 1) {
+     sinfo_msg_error("no good raw frame in input!");
+        (*status)++;
+     return;
+   }
+   /* Copy relevant information into the blackboard */
+   cfg->nframes         = nraw ;
+
+   strcpy(cfg -> outName,  OBJNOD_OUT_FILENAME);
+   strcpy(cfg -> maskname, OBJNOD_OUT_BPMAP);
+   strcpy(cfg -> med_cube_name, OBJNOD_OUT_MED_CUBE);
+
+
+   frame = cpl_frameset_get_frame(*stk,0);
+
+   sinfo_get_spatial_res(frame,spat_res);
+  switch(sinfo_frame_is_on(frame))
+    {
+
+    case 0:
+      strcpy(lamp_status,"on");
+      break;
+    case 1:
+      strcpy(lamp_status,"off");
+      break;
+    case -1:
+      strcpy(lamp_status,"undefined");
+      break;
+    default:
+      strcpy(lamp_status,"undefined");
+      break;
+    }
+   sinfo_get_band(frame,band);
+   sinfo_msg("Spatial resolution: %s lamp_status: %s band: %s",
+                     spat_res,    lamp_status,    band);
+
+
+   sinfo_get_ins_set(band,&ins_set);
+
+   if(NULL != cpl_frameset_find(sof,PRO_WAVE_MAP)) {
+     frame = cpl_frameset_find(sof,PRO_WAVE_MAP);
+     strcpy(cfg -> wavemap, cpl_frame_get_filename(frame));
+   } else {
+     sinfo_msg("Frame %s not found!", PRO_WAVE_MAP);
+     sinfo_msg_error((char* ) cpl_error_get_message());
+     (*status)++;
+     return ;
+   }
+
+   if(NULL != cpl_frameset_find(sof,PRO_MASTER_FLAT_LAMP)) {
+     frame = cpl_frameset_find(sof,PRO_MASTER_FLAT_LAMP);
+     strcpy(cfg -> mflat, cpl_frame_get_filename(frame));
+   } else {
+     sinfo_msg("Frame %s not found!", PRO_MASTER_FLAT_LAMP);
+     sinfo_msg_error((char* ) cpl_error_get_message());
+     (*status)++;
+     return ;
+   }
+
+   if(NULL != cpl_frameset_find(sof,PRO_STACK_SKY_DIST)) {
+     frame = cpl_frameset_find(sof,PRO_STACK_SKY_DIST);
+     strcpy(cfg -> sky_dist, cpl_frame_get_filename(frame));
+   } else {
+     sinfo_msg_warning("Frame %s not found!", PRO_STACK_SKY_DIST);
+     strcpy(cfg -> sky_dist,"no_sky");
+   }
+
+   if(NULL != cpl_frameset_find(sof,PRO_STACK_MFLAT_DIST)) {
+     frame = cpl_frameset_find(sof,PRO_STACK_MFLAT_DIST);
+     strcpy(cfg -> mflat_dist, cpl_frame_get_filename(frame));
+   } else {
+     strcpy(cfg -> mflat_dist, "not_found");
+     sinfo_msg("Frame %s not found!", PRO_STACK_MFLAT_DIST);
+   }
+
+
+   if(NULL != cpl_frameset_find(sof,PRO_STACK_MFLAT_DITHER_DIST)) {
+     frame = cpl_frameset_find(sof,PRO_STACK_MFLAT_DITHER_DIST);
+     strcpy(cfg -> mflat_dither_dist, cpl_frame_get_filename(frame));
+   } else {
+     strcpy(cfg -> mflat_dither_dist, "not_found");
+     sinfo_msg("Frame %s not found!", PRO_STACK_MFLAT_DITHER_DIST);
+   }
+
+
+   if(cfg -> northsouthInd) {
+
+     if(NULL != cpl_frameset_find(sof,PRO_SLITLETS_DISTANCE)) {
+       frame = cpl_frameset_find(sof,PRO_SLITLETS_DISTANCE);
+       strcpy(cfg -> distlist, cpl_frame_get_filename(frame));
+     } else {
+       sinfo_msg("Frame %s not found!", PRO_SLITLETS_DISTANCE);
+       (*status)++;
+       return ;
+     }
+
+   } else {
+
+     if(NULL != cpl_frameset_find(sof,PRO_SLIT_POS)) {
+       frame = cpl_frameset_find(sof,PRO_SLIT_POS);
+       strcpy(cfg -> poslist, cpl_frame_get_filename(frame));
+     } else {
+       sinfo_msg("Frame %s not found!", PRO_SLIT_POS);
+       (*status)++;
+       return ;
+     }
+
+   }
+   if(cfg -> halocorrectInd) {
+     if(NULL != cpl_frameset_find(sof,PRO_HALO_SPECT)) {
+       frame = cpl_frameset_find(sof,PRO_HALO_SPECT);
+       strcpy(cfg -> halospectrum, cpl_frame_get_filename(frame));
+     } else {
+       sinfo_msg("Frame %s not found!", PRO_HALO_SPECT);
+       (*status)++;
+       return ;
+     }
+
+   }
+   if(NULL != cpl_frameset_find(sof, PRO_REF_ATM_REF_CORR))
+   {
+       frame = cpl_frameset_find(sof, PRO_REF_ATM_REF_CORR);
+       strcpy(cfg->polyshiftname, cpl_frame_get_filename(frame));
+   } else
+   {
+       sinfo_msg("Frame %s not found, shift due atmospheric refraction "
+    		   "would not be applied!", PRO_REF_ATM_REF_CORR);
+       cfg->polyshiftname[0] = 0;
+//       (*status)++;
+   }
+   /*
+   sinfo_msg("cfg -> wavemap  %s",cfg -> wavemap);
+   sinfo_msg("cfg -> poslist  %s",cfg -> poslist);
+   sinfo_msg("cfg -> firstCol %s",cfg -> firstCol);
+   */
+   return;
+}
+
+
+static void
+parse_section_jittering(object_config * cfg,cpl_parameterlist * cpl_cfg)
+{
+   cpl_parameter* p;
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objnod.jitter_index");
+   cfg -> jitterind = cpl_parameter_get_bool(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objnod.size_x");
+   cfg -> size_x = cpl_parameter_get_int(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objnod.size_y");
+   cfg -> size_y = cpl_parameter_get_int(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objnod.kernel_type");
+   strcpy(cfg -> kernel_type, cpl_parameter_get_string(p));
+
+}
+
+static void
+parse_section_resampling(object_config * cfg,cpl_parameterlist* cpl_cfg)
+{
+   cpl_parameter* p;
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objnod.n_coeffs");
+   cfg -> ncoeffs = cpl_parameter_get_int(p);
+
+   cfg -> nrows = SINFO_RESAMP_NROWS;
+   return ;
+}
+
+static void
+parse_section_calibration(object_config * cfg)
+{
+  cfg -> halocorrectInd=0;
+
+
+}
+
+static void
+parse_section_cubecreation(object_config * cfg,cpl_parameterlist* cpl_cfg)
+{
+   cpl_parameter* p;
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objnod.nord_south_index");
+   cfg -> northsouthInd = cpl_parameter_get_bool(p);
+   cfg -> nslits = NSLITLETS;
+
+   return ;
+}
+
+static void
+parse_section_finetuning(object_config * cfg,cpl_parameterlist* cpl_cfg)
+{
+   cpl_parameter* p;
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objnod.fine_tuning_method");
+   strcpy(cfg -> method, cpl_parameter_get_string(p));
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objnod.order");
+   cfg -> order = cpl_parameter_get_int(p);
+
+}
+
+static void
+parse_section_skyextraction(object_config * cfg,cpl_parameterlist* cpl_cfg)
+{
+
+   cpl_parameter* p;
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objnod.low_rejection");
+   cfg -> loReject = cpl_parameter_get_double(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objnod.high_rejection");
+   cfg -> hiReject = cpl_parameter_get_double(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objnod.tolerance");
+   cfg -> tolerance = cpl_parameter_get_int(p);
+
+}
+
+/*-----------------------------------------------------------------*/
+void
+sinfo_objnod_free(object_config ** cfg) {
+  int i=0;
+  if(*cfg != NULL) {
+    for(i=0;i<(*cfg)->nframes;i++) {
+      if((*cfg)->framelist[i]!=NULL) {
+    cpl_free((*cfg)->framelist[i]);
+    (*cfg)->framelist[i]=NULL;
+      }
+    }
+    if((*cfg)->framelist != NULL) {
+      cpl_free((*cfg)->framelist);
+      (*cfg)->framelist=NULL;
+    }
+    sinfo_object_cfg_destroy (*cfg);
+    *cfg=NULL;
+  }
+  return;
+}
+/**@}*/
diff --git a/sinfoni/sinfo_objnod_ini_by_cpl.h b/sinfoni/sinfo_objnod_ini_by_cpl.h
new file mode 100644
index 0000000..1d4370c
--- /dev/null
+++ b/sinfoni/sinfo_objnod_ini_by_cpl.h
@@ -0,0 +1,68 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+   
+   File name    :   sinfo_object_ini_by_cpl.h
+   Author       :   Andrea Modigliani
+   Created on   :   May 04, 2004
+   Description  :   cpl input handling for SPIFFIs creation of a data cube
+                        from a science object observation
+ ---------------------------------------------------------------------------*/
+#ifndef SINFO_OBJNOD_INI_BY_CPL_H
+#define SINFO_OBJNOD_INI_BY_CPL_H
+/*---------------------------------------------------------------------------
+                                Includes
+---------------------------------------------------------------------------*/
+#include <cpl.h>
+#include "sinfo_msg.h"
+#include "sinfo_object_cfg.h"
+/*----------------------------------------------------------------------------
+                             Function prototypes 
+ ---------------------------------------------------------------------------*/
+/*-------------------------------------------------------------------------*/
+/**
+  @name     sinfo_parse_cpl_input_objnod
+  @memo     Parse a ini_name.ini file and create a blackboard.
+  @param    cpl_cfg pointer to parameterlist
+  @param    sof pointer to input set of frames
+  @param    raw pointer to input set of raw frames
+  @return   1 newly allocated object_config blackboard structure.
+  @doc
+
+  The requested ini file is parsed and a blackboard object is created, then
+  updated accordingly. Returns NULL in case of error.
+ */
+/*--------------------------------------------------------------------------*/
+
+object_config * 
+sinfo_parse_cpl_input_objnod(cpl_parameterlist * cpl_cfg, 
+                             cpl_frameset* sof, 
+                             cpl_frameset** stk) ;
+
+/**
+ at name sinfo_objnod_free
+ at memo deallocates object_config structure
+ at param cfg pointer to object_config structure
+ at return void
+*/
+
+void 
+sinfo_objnod_free(object_config ** cfg);
+
+#endif
diff --git a/sinfoni/sinfo_objspider_config.c b/sinfoni/sinfo_objspider_config.c
new file mode 100644
index 0000000..7beff07
--- /dev/null
+++ b/sinfoni/sinfo_objspider_config.c
@@ -0,0 +1,313 @@
+/* $Id: sinfo_objspider_config.c,v 1.7 2012/03/03 09:50:08 amodigli Exp $
+ *
+ * This file is part of the CPL (Common Pipeline Library)
+ * Copyright (C) 2002 European Southern Observatory
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*
+ * $Author: amodigli $
+ * $Date: 2012/03/03 09:50:08 $
+ * $Revision: 1.7 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+ /****************************************************************
+  *   Objspider Frames Data Reduction Parameter Initialization        *
+  ****************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#include "sinfo_objspider_config.h"
+/**@{*/
+/**
+ * @addtogroup sinfo_rec_jitter Objnod parameters definition & initialization
+ *
+ * TBD
+ */
+
+/**
+ at name  sinfo_objspider_config_add
+ at brief Objspider parameters definition & initialization
+ at param list pointer to cpl_parameterlist
+ at return void
+*/
+
+void
+ sinfo_objspider_config_add(cpl_parameterlist *list)
+{
+
+  cpl_parameter *p;
+
+  if (!list) {
+    return;
+  }
+
+
+  /* Input file name */
+  /* Output file name */
+  /* output name of resulting fits wavelength map */
+  p = cpl_parameter_new_value("sinfoni.objspider.out_filename",
+                  CPL_TYPE_STRING,
+                              "Output File Name: ",
+                              "sinfoni.objspider",
+                              SKYSPIDER_OUT_FILENAME);
+
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"out-skyspider_filename");
+  cpl_parameterlist_append(list, p);
+
+
+  /*Resampling */
+ /* number of coefficients for the polynomial interpolation */
+  p = cpl_parameter_new_value("sinfoni.objspider.n_coeffs",
+                  CPL_TYPE_INT,
+                              "number of coefficients for the polynomial "
+                              "interpolation ",
+                              "sinfoni.objspider",
+                               3);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"objspider-no-coeffs");
+  cpl_parameterlist_append(list, p);
+
+
+  /* Calibration */
+  /* indicates if the halogen lamp features from flatfielding should be 
+     corrected for or not */
+  /*
+  p = cpl_parameter_new_value("sinfoni.objspider.halo_correct_index",
+                  CPL_TYPE_BOOL,
+                              "Halo Correct Index: "
+                               "indicates if the halogen lamp features from "
+                              "flatfielding should be corrected for (TRUE) "
+                              "or not (FALSE)",
+                              "sinfoni.objspider",
+                              FALSE);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"objspider-halo-corr-ind");
+  cpl_parameterlist_append(list, p);
+  */
+
+
+  /* Cube Creation */
+  /*indicates if the slitlet distances are determined by a north-south-test 
+     (yes) or slitlet edge fits (no)
+  */
+  p = cpl_parameter_new_value("sinfoni.objspider.nord_south_index",
+                  CPL_TYPE_BOOL,
+                              "Nord South Index Switch: "
+                               "indicates if the slitlet distances are "
+                              "determined by a north-south-test (TRUE) "
+                              "or slitlet edge fits (FALSE)",
+                              "sinfoni.objspider",
+                              TRUE);
+
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"objspider-ns-ind");
+  cpl_parameterlist_append(list, p);
+
+  p = cpl_parameter_new_value("sinfoni.objspider.slitlets_position_list",
+                  CPL_TYPE_STRING,
+                              "Slitlets positions filename: "
+                               "list of the fitted slitlet edge positions "
+                              "or the distances of the slitlets",
+                              "sinfoni.objspider",
+                              "distances.fits");
+
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"objspider-pos-list");
+  cpl_parameterlist_append(list, p);
+
+  /* number of slitlets (32) */
+  p = cpl_parameter_new_value("sinfoni.objspider.nslits",
+                  CPL_TYPE_INT,
+                              "Number of slitlets: ",
+                              "sinfoni.objspider",
+                              32);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"objspider-pos-nslits");
+  cpl_parameterlist_append(list, p);
+
+  /* Fine tuning */
+  /* Method */
+
+  p = cpl_parameter_new_enum("sinfoni.objspider.fine_tuning_method",
+                  CPL_TYPE_STRING,
+                              "Fine Tuning Method: "
+                               "indicator for the shifting method to use "
+                              "(P: polynomial interpolation, "
+                              " F: FFT, "
+                              " S: cubic spline interpolation)",
+                              "sinfoni.objspider",
+                              "P",
+                               3,"P","F","S");
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"objspider-fine-tune-mtd");
+  cpl_parameterlist_append(list, p);
+
+  p = cpl_parameter_new_value("sinfoni.objspider.order",
+                  CPL_TYPE_INT,
+                              "Fine Tuning polynomial order: " 
+                              "order of the polynomial if the polynomial "
+                              "interpolation shifting method is used.",
+                              "sinfoni.objspider",
+                              2);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"objspider-order");
+  cpl_parameterlist_append(list, p);
+
+  /* Sky Extraction */
+  /*Reconstruction */
+ /* the fraction [0...1] of rejected low intensity pixels when taking 
+the average of columns */
+  p = cpl_parameter_new_value("sinfoni.objspider.lower_rejection",
+                  CPL_TYPE_DOUBLE,
+                              "lower rejection: "
+                              "percentage of rejected low value pixels "
+                              "for averaging the sky spectra",
+                              "sinfoni.objspider",
+                              10.);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"objspider-lo-rejection");
+  cpl_parameterlist_append(list, p);
+
+ /* the fraction [0...1] of rejected high intensity pixels when taking 
+the average of columns */
+  p = cpl_parameter_new_value("sinfoni.objspider.higher_rejection",
+                  CPL_TYPE_DOUBLE,
+                              "higher rejection: "
+                              "percentage of rejected high value pixels "
+                              "for averaging the sky spectra",
+                              "sinfoni.objspider",
+                              10.);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"objspider-hi-rejection");
+  cpl_parameterlist_append(list, p);
+
+  /* pixel tolerance, this distance tolerance to the diagonal dividing 
+     line is not considered for the sky extraction to be sure to have a clean
+     sky due to positioning tolerance and crossing through pixels
+  */
+
+  p = cpl_parameter_new_value("sinfoni.objspider.tolerance",
+                  CPL_TYPE_INT,
+                              "Tolerance: "
+                              "pixel tolerance, this distance tolerance to "
+                              "the diagonal dividing line is not considered "
+                              "for the sky extraction to be sure to have a "
+                              "clean sky due to positioning tolerance and "
+                              "crossing through pixels",
+                              "sinfoni.objspider",
+                              2);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"objspider-tol");
+  cpl_parameterlist_append(list, p);
+
+  /* Jittering */
+  /* jitter mode indicator: yes: Auto-Jitter, no: user defined jitter
+     The next three parameters are only used if jitterInd is set to yes, 
+     that means in auto-jittering mode!
+  */
+
+  p = cpl_parameter_new_value("sinfoni.objspider.jitter_index",
+                  CPL_TYPE_BOOL,
+                              "Jitter Index: "
+                              "jitter mode indicator: "
+                              "TRUE: Auto-Jitter, "
+                              "FALSE: user defined jitter"
+                              "The size_x size_y kernel_type parameters "
+                              "are only used if jitterInd is set to yes, "
+                              "that means in auto-jittering mode!",
+                               "sinfoni.objspider",
+                              FALSE);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"objspider-jit-ind");
+  cpl_parameterlist_append(list, p);
+  /*x-pixel size of the final combined data cube, must lie between 64 and 128 */
+
+  p = cpl_parameter_new_value("sinfoni.objspider.size_x",
+                  CPL_TYPE_INT,
+                              "Cube x size: "
+                              "x-pixel size of the final combined data cube,"
+                              "must lie between 64 and 128. "
+                              "If 0 automatic setting.",
+                              "sinfoni.objspider",
+                              0);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"objspider-size-x");
+  cpl_parameterlist_append(list, p);
+  /*y-pixel size of the final combined data cube, must lie between 64 and 128 */
+
+  p = cpl_parameter_new_value("sinfoni.objspider.size_y",
+                  CPL_TYPE_INT,
+                              "Cube y size: "
+                              "y-pixel size of the final combined data cube,"
+                              "must lie between 64 and 128. "
+                              "If 0 automatic setting.",
+                              "sinfoni.objspider",
+                              0);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"objspider-size-y");
+  cpl_parameterlist_append(list, p);
+
+  /* Kernel Type */
+  /* the name of the interpolation kernel to shift the single cubes  to the 
+     correct places inside the big combined cube. That you want to generate 
+     using the eclipse routine sinfo_generate_interpolation_kernel()
+     Supported kernels are:
+
+                                     NULL:      default kernel, currently tanh
+                                     default: dito
+                                     tanh:    Hyperbolic tangent
+                                     sinc2:   Square sinc
+                                     lanczos: Lanczos2 kernel
+                                     hamming: Hamming kernel
+                                     hann:    Hann kernel
+  */
+  p = cpl_parameter_new_enum("sinfoni.objspider.kernel_type",
+                  CPL_TYPE_STRING,
+                              "Kernel Type:"
+                              "the name of the interpolation kernel to shift "
+                              "the single cubes  to the correct places inside "
+                 "the big combined cube",
+                              "sinfoni.objspider",
+                              "tanh",
+                               6,"NULL","default","tanh",
+                               "sinc2","lanczos","hamming","hann");
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"objspider-kernel-typ");
+  cpl_parameterlist_append(list, p);
+
+  /* name of the final mask data cube, pixel value 0 if no data available,
+     sum of exposure times in the overlapping regions
+  */
+
+ p = cpl_parameter_new_value("sinfoni.objspider.mask_name",
+                  CPL_TYPE_STRING,
+                              "Mask Name: "
+                              "name of the final mask data cube, "
+                              "pixel value 0 if no data available,"
+                              "sum of exposure times in the overlapping "
+                              "regions ",
+                              "sinfoni.objspider",
+                              SKYSPIDER_MASK_OUT_FILENAME);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"objspider-mask");
+  cpl_parameterlist_append(list, p);
+
+}
+/**@}*/
diff --git a/sinfoni/sinfo_objspider_config.h b/sinfoni/sinfo_objspider_config.h
new file mode 100644
index 0000000..4171be7
--- /dev/null
+++ b/sinfoni/sinfo_objspider_config.h
@@ -0,0 +1,33 @@
+/* $Id: sinfo_objspider_config.h,v 1.1 2006/10/20 08:06:32 amodigli Exp $
+ *
+ * This file is part of the CPL (Common Pipeline Library)
+ * Copyright (C) 2002 European Southern Observatory
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*
+ * $Author: amodigli $
+ * $Date: 2006/10/20 08:06:32 $
+ * $Revision: 1.1 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+ /****************************************************************
+  *   Objspider Frames Data Reduction Parameter Initialization        *
+  ****************************************************************/
+#include "cpl.h"    /* defines parlist structure */
+#include "sinfo_hidden.h"
+void
+sinfo_objspider_config_add(cpl_parameterlist *list);
diff --git a/sinfoni/sinfo_objspider_ini_by_cpl.c b/sinfoni/sinfo_objspider_ini_by_cpl.c
new file mode 100644
index 0000000..915c68e
--- /dev/null
+++ b/sinfoni/sinfo_objspider_ini_by_cpl.c
@@ -0,0 +1,397 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/*----------------------------------------------------------------------------
+   
+   File name    :   sinfo_objspider_ini_by_cpl.c
+   Author       :   Andrea Modigliani
+   Created on   :   May 22, 2004
+   Description  :   object cube creation cpl input handling for SPIFFI
+
+ ---------------------------------------------------------------------------*/
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+/*---------------------------------------------------------------------------
+                                Includes
+ ---------------------------------------------------------------------------*/
+#include <string.h>
+#include "sinfo_objspider_ini_by_cpl.h"
+#include "sinfo_functions.h"
+#include "sinfo_pro_types.h"
+#include "sinfo_hidden.h"
+#include "sinfo_cpl_size.h"
+
+#include "sinfo_file_handling.h"
+/*---------------------------------------------------------------------------
+                    Functions private to this module
+ ---------------------------------------------------------------------------*/
+
+static void 
+parse_section_frames(object_config *,
+                     cpl_frameset* sof, cpl_frameset**stk, int* status);
+static void 
+parse_section_jittering(object_config *, cpl_parameterlist * cpl_cfg);
+static void 
+parse_section_resampling(object_config *, cpl_parameterlist * cpl_cfg);
+static void 
+parse_section_calibration(object_config *);
+static void 
+parse_section_cubecreation(object_config *, cpl_parameterlist * cpl_cfg);
+static void 
+parse_section_finetuning(object_config *, cpl_parameterlist * cpl_cfg);
+static void 
+parse_section_skyextraction(object_config *, cpl_parameterlist * cpl_cfg);
+/**@{*/
+/**
+ * @addtogroup sinfo_rec_jitter Blackboard to objspider structure
+ *
+ * TBD
+ */
+
+
+
+/*-------------------------------------------------------------------------*/
+/**
+  @name     parse_objspider_ini_file
+  @memo     Parse a ini_name.ini file and create a blackboard.
+  @param    ini_name    Name of the ASCII file to parse.
+  @return   1 newly allocate object_config blackboard structure.
+  @doc
+
+  The requested ini file is parsed and a blackboard object is created, then
+  updated accordingly. Returns NULL in case of error.
+ */
+/*--------------------------------------------------------------------------*/
+
+object_config * 
+sinfo_parse_cpl_input_objspider(cpl_parameterlist * cpl_cfg,cpl_frameset* sof,
+              cpl_frameset** stk)
+{
+   object_config   *  cfg = sinfo_object_cfg_create();
+   int status=0;
+   /*
+    * Perform sanity checks, fill up the structure with what was
+    * found in the ini file
+    */
+
+   
+   parse_section_resampling   (cfg, cpl_cfg);
+   parse_section_calibration  (cfg);
+   parse_section_cubecreation (cfg, cpl_cfg);
+   parse_section_finetuning   (cfg, cpl_cfg); 
+   parse_section_skyextraction(cfg, cpl_cfg); 
+   parse_section_jittering    (cfg, cpl_cfg);
+   parse_section_frames       (cfg, sof,stk,&status);
+   if (status > 0) {
+                sinfo_msg_error("parsing cpl input");
+                sinfo_object_cfg_destroy(cfg);
+                cfg = NULL ;
+                return NULL ;
+   }
+ 
+   return cfg ;
+}
+
+static void      
+parse_section_frames(object_config * cfg, 
+             cpl_frameset* sof,
+                     cpl_frameset** stk,
+                     int* status)
+{
+   int                     nraw_good =0;
+
+
+
+   int nframes=0;
+   int nraw=0;
+   cpl_frame* frame   = NULL;
+   int nstk=0;
+   cpl_size             *   labels=NULL ;
+   cpl_size                 nlabels=0 ;
+   cpl_frameset    *   cur_set=NULL ;
+   cpl_frame       *   cur_frame=NULL ;
+   char * tag=NULL;
+   int i=0;
+   int wave_map=0;
+   int pos_slit=0;
+   int first_col=0;
+   int halo_sp=0;
+   char spat_res[FILE_NAME_SZ];
+   char lamp_status[FILE_NAME_SZ];
+   char band[FILE_NAME_SZ];
+   int ins_set=0;
+
+   nframes = cpl_frameset_get_size(sof);
+
+   /* Get the raw and the calibration files */
+   /* Labelise the input frames according to their tags */
+   labels = cpl_frameset_labelise(sof, sinfo_compare_tags,&nlabels );
+   if (labels == NULL) {
+     sinfo_msg_error( "Cannot labelise the input frames") ;
+     (*status)++;
+     return ;
+   }
+   if (nlabels == 1) {
+      /* Only one label - all images are objects observations */
+      /* Verify that it is really an observation */
+      cur_frame = cpl_frameset_get_frame(sof, 0) ;
+      tag = (char*)cpl_frame_get_tag(cur_frame) ;
+      if (sinfo_is_stack(tag)) {
+    *stk = cpl_frameset_duplicate(sof) ;
+    nstk++;
+      }
+   } else {
+     /* For each label */
+     for (i=0 ; i<nlabels ; i++) {
+       cur_set = cpl_frameset_extract(sof, labels, i) ;
+       cur_frame = cpl_frameset_get_frame(cur_set, 0) ;
+       tag = (char*)cpl_frame_get_tag(cur_frame) ;
+       if (sinfo_is_stack(tag) == 1) {
+     /* Stacked frame */
+     *stk = cpl_frameset_duplicate(cur_set) ;
+     nstk++;
+       } else if (sinfo_is_wavemap(tag)) {
+     /* pos slit calibration file */
+     strcpy(cfg -> wavemap,cpl_strdup(cpl_frame_get_filename(cur_frame)));
+     wave_map=1;
+       } else if (sinfo_is_distlist(tag)) {
+     /* pos slit calibration file */
+     strcpy(cfg -> poslist,cpl_strdup(cpl_frame_get_filename(cur_frame)));
+     pos_slit=1;
+       } else if (sinfo_is_firstcol(tag)) { 
+     /* first col calibration file */
+     strcpy(cfg -> firstCol,cpl_strdup(cpl_frame_get_filename(cur_frame)));
+     first_col=1;
+       } else if (sinfo_is_halosp(tag)) { 
+     /* first col calibration file */
+     strcpy(cfg->halospectrum,cpl_strdup(cpl_frame_get_filename(cur_frame)));
+     halo_sp=1;
+       }
+       cpl_frameset_delete(cur_set) ;
+     }
+   }
+   cpl_free(labels) ;
+   if (nstk == 0) {
+     sinfo_msg_error( "Cannot find good input frames") ;
+     (*status)++;
+     return ;
+   }
+
+   if (wave_map == 0) {
+     sinfo_msg_error( "Cannot find wave map");
+     (*status)++;
+     return ;
+   }
+   if (pos_slit == 0) {
+     sinfo_msg_error( "Cannot find pos slit") ;
+     (*status)++;
+     return ;
+   }
+   if (first_col == 0) {
+     sinfo_msg_error( "Cannot find first col") ;
+     (*status)++;
+     return ;
+   }
+
+
+   /* TEMPORALLY COMMENTED OUT */
+   nraw    = cpl_frameset_get_size(*stk);
+   /* Test if the rawframes have been found */
+   if (nraw < 1) {
+     sinfo_msg_error("Cannot find input stacked frames in the input list") ;
+     (*status)++;
+     return ;
+   }
+
+   nraw    = cpl_frameset_get_size(*stk);
+   if (nraw < 1) {
+     sinfo_msg_error("no raw frame in input, something wrong!");
+     exit(-1);
+   }
+
+   /* Allocate structures to go into the blackboard */
+   cfg->framelist     = cpl_malloc(nraw * sizeof(char*));
+
+  /* read input frames */
+   for (i=0 ; i<nraw ; i++) {
+     frame = cpl_frameset_get_frame(*stk,i);
+     if(sinfo_file_exists((char*) cpl_frame_get_filename(frame))==1) {
+       cfg->framelist[i]=cpl_strdup(cpl_frame_get_filename(frame));
+       nraw_good++;
+     }
+     /* Store file name into framelist */
+   }
+   if (nraw_good < 1) {
+     sinfo_msg_error("no good raw frame in input!");
+     (*status)++;
+     return;
+   }
+   /* Copy relevant information into the blackboard */
+   cfg->nframes         = nraw ;
+
+   strcpy(cfg -> outName, SKYSPIDER_OUT_FILENAME);
+   strcpy(cfg -> maskname, SKYSPIDER_MASK_OUT_FILENAME);
+
+
+   frame = cpl_frameset_get_frame(*stk,0);
+
+   sinfo_get_spatial_res(frame,spat_res);
+   switch(sinfo_frame_is_on(frame)) {
+
+   case 0: 
+     strcpy(lamp_status,"on");
+     break;
+   case 1: 
+     strcpy(lamp_status,"off");
+     break;
+   case -1:
+     strcpy(lamp_status,"undefined");
+     break;
+   default: 
+     strcpy(lamp_status,"undefined");
+     break;
+   }
+   sinfo_get_band(frame,band);
+   sinfo_msg("Spatial resolution: %s lamp_status: %s band: %s ",
+           spat_res,    lamp_status,    band);
+
+
+   sinfo_get_ins_set(band,&ins_set);
+
+
+
+   return;
+}
+
+
+static void     
+parse_section_jittering(object_config * cfg,cpl_parameterlist * cpl_cfg)
+{
+  cpl_parameter* p;
+
+  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.jitter_index");
+  cfg -> jitterind = cpl_parameter_get_bool(p);
+
+  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.size_x");
+  cfg -> size_x = cpl_parameter_get_int(p);
+
+  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.size_y");
+  cfg -> size_y = cpl_parameter_get_int(p);
+
+  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.kernel_type");
+  strcpy(cfg -> kernel_type, cpl_parameter_get_string(p));
+
+  /*
+  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.mask");
+  strcpy(cfg -> maskname, cpl_parameter_get_string(p));
+  */
+
+}
+
+static void     
+parse_section_resampling(object_config * cfg,cpl_parameterlist* cpl_cfg)
+{
+  cpl_parameter* p;
+
+  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.n_coeffs");
+  cfg -> ncoeffs = cpl_parameter_get_int(p);
+  cfg -> nrows=SINFO_RESAMP_NROWS;
+
+
+  return ;
+}
+
+static void     
+parse_section_calibration(object_config * cfg)
+{
+  /*
+  cpl_parameter* p;
+  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.halo_correct_index");
+  cfg -> halocorrectInd = cpl_parameter_get_bool(p);
+  */
+  cfg -> halocorrectInd=0;
+
+  /*
+  p=cpl_parameterlist_find(cpl_cfg,"sinfoni.objspider.halo_spectrum_filename");
+  strcpy(cfg -> halospectrum, cpl_parameter_get_string(p));
+  */
+
+}
+
+static void     
+parse_section_cubecreation(object_config * cfg,cpl_parameterlist* cpl_cfg)
+{
+  cpl_parameter* p;
+  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.nord_south_index");
+  cfg -> northsouthInd = cpl_parameter_get_bool(p);
+
+  /*
+  p=cpl_parameterlist_find(cpl_cfg,"sinfoni.objspider.slitlets_position_list");
+  strcpy(cfg -> poslist, cpl_parameter_get_string(p));
+  */
+
+  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.nslits");
+  cfg -> nslits = cpl_parameter_get_int(p);
+
+  /*
+  p=cpl_parameterlist_find(cpl_cfg,"sinfoni.objspider.first_column_filename");
+  strcpy(cfg -> firstCol, cpl_parameter_get_string(p));
+  */
+
+   return ;
+}
+
+static void     
+parse_section_finetuning(object_config * cfg,cpl_parameterlist* cpl_cfg)
+{
+  cpl_parameter* p;
+
+  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.fine_tuning_method");
+  strcpy(cfg -> method, cpl_parameter_get_string(p));
+
+  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.order");
+  cfg -> order = cpl_parameter_get_int(p);
+
+}
+
+static void     
+parse_section_skyextraction(object_config * cfg,cpl_parameterlist* cpl_cfg)
+{
+
+  cpl_parameter* p;
+  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.lower_rejection");
+  cfg -> loReject = (float) cpl_parameter_get_double(p);
+
+  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.higher_rejection");
+  cfg -> hiReject = (float) cpl_parameter_get_double(p);
+
+  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objspider.tolerance");
+  cfg -> tolerance = cpl_parameter_get_int(p);
+
+}
+
+/*-----------------------------------------------------------------*/
+void
+sinfo_objspider_free(object_config * cfg) {
+  cpl_free(cfg->framelist);
+  sinfo_object_cfg_destroy (cfg);
+  return;
+}
diff --git a/sinfoni/sinfo_objspider_ini_by_cpl.h b/sinfoni/sinfo_objspider_ini_by_cpl.h
new file mode 100644
index 0000000..8a6fe95
--- /dev/null
+++ b/sinfoni/sinfo_objspider_ini_by_cpl.h
@@ -0,0 +1,67 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+   
+   File name    :   sinfo_object_ini_by_cpl.h
+   Author       :   Andrea Modigliani
+   Created on   :   May 04, 2004
+   Description  :   cpl input handling for SPIFFIs creation of a data cube
+                        from a science object observation
+ ---------------------------------------------------------------------------*/
+#ifndef SINFO_OBJSPIDER_INI_BY_CPL_H
+#define SINFO_OBJSPIDER_INI_BY_CPL_H
+/*---------------------------------------------------------------------------
+                                Includes
+---------------------------------------------------------------------------*/
+#include <cpl.h>
+#include "sinfo_object_cfg.h"
+#include "sinfo_msg.h"
+/*----------------------------------------------------------------------------
+                             Function prototypes 
+ ---------------------------------------------------------------------------*/
+
+/**
+  @name     parse_cpl_input_object
+  @memo     Parse a ini_name.ini file and create a blackboard.
+  @param    cpl_cfg pointer to parameterlist
+  @param    sof pointer to input set of frames
+  @param    raw pointer to input set of raw frames
+  @return   1 newly allocated object_config blackboard structure.
+  @doc
+
+  The requested ini file is parsed and a blackboard object is created, then
+  updated accordingly. Returns NULL in case of error.
+ */
+
+object_config * 
+sinfo_parse_cpl_input_objspider(cpl_parameterlist * cpl_cfg, 
+                                cpl_frameset* sof, 
+                                cpl_frameset** stk) ;
+
+/**
+ at name sinfo_objspider_free
+ at memo deallocates object_config structure
+ at param cfg pointer to object_config structure
+ at return void
+*/
+
+void 
+sinfo_objspider_free(object_config * cfg);
+
+#endif
diff --git a/sinfoni/sinfo_pfits.c b/sinfoni/sinfo_pfits.c
new file mode 100644
index 0000000..4b8317b
--- /dev/null
+++ b/sinfoni/sinfo_pfits.c
@@ -0,0 +1,1076 @@
+/* $Id: sinfo_pfits.c,v 1.14 2012/05/04 08:11:07 amodigli Exp $
+ *
+ * This file is part of the SINFONI Pipeline
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2012/05/04 08:11:07 $
+ * $Revision: 1.14 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+/*----------------------------------------------------------------------------
+                                   Includes
+ ----------------------------------------------------------------------------*/
+#include <ctype.h>
+#include <cpl.h>
+#include "sinfo_pfits.h"
+#include "sinfo_key_names.h"
+#include "sinfo_utils_wrappers.h"
+#include "sinfo_msg.h"
+#include <string.h>
+
+/*---------------------------------------------------------------------------*/
+#define ASCIILINESZ                         1024
+#define PAF_MAGIC_SZ               13
+#define PAF_MAGIC       "PAF.HDR.START"
+
+/*-----------------------------------------------------------------------------
+                              Function codes
+ ----------------------------------------------------------------------------*/
+char * sinfo_paf_query(
+        char    *   filename,
+        char    *   key) ;
+
+static int sinfo_is_paf_file(char * filename) ;
+
+static char * sinfo_strcrop(char * s);
+
+
+/**@{*/
+/**
+ * @defgroup sinfo_pfits In/Out on propertylist cards
+ *
+ * TBD
+ */
+
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Remove blanks at the end of a string.
+  @param    s   String to parse.
+  @return   ptr to statically allocated string.
+
+  This function returns a pointer to a statically allocated string,
+  which is identical to the input string, except that all blank
+  characters at the end of the string have been removed.
+  Do not free or modify the returned string! Since the returned string
+  is statically allocated, it will be modified at each function call
+  (not re-entrant).
+ */
+/*---------------------------------------------------------------------------*/
+static char * sinfo_strcrop(char * s)
+{
+    static char l[ASCIILINESZ+1];
+    char * last ;
+
+    if (s==NULL) return NULL ;
+    memset(l, 0, ASCIILINESZ+1);
+    strcpy(l, s);
+    last = l + strlen(l);
+    while (last > l) {
+        if (!isspace((int)*(last-1)))
+            break ;
+        last -- ;
+    }
+    *last = (char)0;
+    return l ;
+}
+
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Query a PAF file for a value.
+  @param    filename    Name of the PAF to query.
+  @param    key            Name of the key to query.
+  @return    1 pointer to statically allocated string, or NULL.
+
+  This function parses a PAF file and returns the value associated to a
+  given key, as a pointer to an internal statically allocated string.
+  Do not try to free or modify the contents of the returned string!
+
+  If the key is not found, this function returns NULL.
+ */
+/*---------------------------------------------------------------------------*/
+char * sinfo_paf_query(
+        char    *   filename, 
+        char    *   key)
+{
+    static char value[ASCIILINESZ];
+    FILE    *    paf ;
+    char        line[ASCIILINESZ+1];
+    char        val[ASCIILINESZ+1];
+    char        head[ASCIILINESZ+1];
+    int            found ;
+    int            len ;
+
+    /* Check inputs */
+    if (filename==NULL || key==NULL) return NULL ;
+
+    /* Check PAF validity */
+    if (sinfo_is_paf_file(filename)!=1) {
+        sinfo_msg_error("not a PAF file: [%s]", filename);
+        return NULL ;
+    }
+
+    /* Open file and read it */
+    paf = fopen(filename, "r");
+    if (paf==NULL) {
+        sinfo_msg_error("opening [%s]", filename);
+        return NULL ;
+    }
+    
+    found = 0 ;
+    while (fgets(line, ASCIILINESZ, paf)!=NULL) {
+        sscanf(line, "%[^ ]", head);
+        if (!strcmp(head, key)) {
+            /* Get value */
+            sscanf(line, "%*[^ ] %[^;]", value);
+            found ++ ;
+            break ;
+        }
+    }
+    if (!found) {
+      fclose(paf);
+      return NULL ;
+    }
+    
+    /* Remove trailing blanks */
+    strcpy(val, sinfo_strcrop(value));
+    /* Get rid of possible quotes */
+    len = strlen(val);
+    if (val[0]=='\"' && val[len-1]=='\"') {
+        strncpy(value, val+1, len-2);
+        value[len-2]=(char)0;
+    } else {
+        strcpy(value, val);
+    }
+    if(paf!=NULL){
+       fclose(paf);
+    }
+    return value ;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    returns 1 if file is in PAF format, 0 else
+  @param    filename name of the file to check
+  @return    int 0, 1, or -1
+  Returns 1 if the file name corresponds to a valid PAF file. Returns
+  0 else. If the file does not exist, returns -1. Validity of the PAF file 
+  is checked with the presence of PAF.HDR.START at the beginning
+ */
+/*---------------------------------------------------------------------------*/
+static int sinfo_is_paf_file(char * filename)
+{
+    FILE    *    fp ;
+    int            is_paf ;
+    char        line[ASCIILINESZ] ;
+    
+    if (filename==NULL) return -1 ;
+
+    /* Initialize is_paf */
+    is_paf = 0 ;
+
+    /* Open file */
+    if ((fp = fopen(filename, "r"))==NULL) {
+        sinfo_msg_error("cannot open file [%s]", filename) ;
+        return -1 ;
+    }
+
+    /* Parse file */
+    while (fgets(line, ASCIILINESZ, fp) != NULL) {
+        if (line[0] != '#') {
+           if (!strncmp(line, PAF_MAGIC, PAF_MAGIC_SZ)) is_paf = 1 ;
+             (void)fclose(fp) ;
+            return is_paf ;
+        }
+    }
+
+    (void)fclose(fp) ;
+    return is_paf ;
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    find out the character string associated to DET.MODE.NAME
+  @param    plist   pointer to propertylist
+  @return   pointer to statically allocated character string
+ */
+/*---------------------------------------------------------------------------*/
+char * sinfo_pfits_get_mode(const cpl_propertylist * plist)
+{
+
+   return (char*) cpl_propertylist_get_string(plist,"ESO DET MODE NAME");
+  
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    find out the value of the EXPTIME keyword
+  @param    plist    pointer to propertylist 
+  @return   keyword value
+ */
+/*---------------------------------------------------------------------------*/
+double sinfo_pfits_get_exp_time(const cpl_propertylist* plist)
+{
+  
+    return cpl_propertylist_get_double(plist,"EXPTIME");
+
+}
+
+
+
+
+
+/*----------------------------------------------------------------------------
+   Function     :       sinfo_pfits_get_ditndit()
+   In           :       fits file name
+   Out          :       total integration time in sec
+   Job          :       reads the product dit*ndit from the FITS-header 
+ ---------------------------------------------------------------------------*/
+double sinfo_pfits_get_ditndit(const char* name)
+{
+  double dit;
+  int ndit=0;
+  cpl_propertylist* plist=NULL;
+  plist=cpl_propertylist_load(name,0);
+
+  dit = cpl_propertylist_get_double(plist,"ESO DET DIT");
+  ndit = cpl_propertylist_get_int(plist,"ESO DET NDIT");
+  sinfo_free_propertylist(&plist);
+  return dit*ndit ;
+
+}
+
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    find out the character string associated to the EXPTIME keyword
+  @param    filename    sinfoni FITS file name
+  @return   pointer to statically allocated character string
+ */
+/*---------------------------------------------------------------------------*/
+double sinfo_pfits_get_exptime(const char * filename)
+{
+    double exptime ;
+    cpl_propertylist* plist=NULL;
+    plist=cpl_propertylist_load(filename,0);
+    exptime = cpl_propertylist_get_double(plist,"EXPTIME");
+    sinfo_free_propertylist(&plist);
+    
+    return exptime;
+}
+
+
+
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    find out the character string associated to the DET.NCORRS key.
+  @param    plist  input propertylist
+  @return   pointer to statically allocated character string
+ */
+/*---------------------------------------------------------------------------*/
+int sinfo_pfits_get_rom(const cpl_propertylist * plist)
+{
+
+    return  cpl_propertylist_get_int(plist,"ESO DET NCORRS");
+
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    find out the number of the current exposition  
+  @param    plist input propertylist
+  @return   keyword value 
+ */
+/*---------------------------------------------------------------------------*/
+int sinfo_pfits_get_expno(const cpl_propertylist * plist)
+{
+    
+   return cpl_propertylist_get_int(plist,"ESO TPL EXPNO");
+
+}
+
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    find out the airmass start 
+  @param    plist   FITS header
+  @return   pointer to statically allocated character string
+ */
+/*---------------------------------------------------------------------------*/
+double sinfo_pfits_get_airmass_start(const cpl_propertylist * plist)
+{
+
+    return cpl_propertylist_get_double(plist,"ESO TEL AIRM START");
+
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    find out the airmass end 
+  @param    plist   FITS header
+  @return   pointer to statically allocated character string
+ */
+/*---------------------------------------------------------------------------*/
+double sinfo_pfits_get_airmass_end(const cpl_propertylist * plist)
+{
+    return cpl_propertylist_get_double(plist,"ESO TEL AIRM END");
+
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    find out the alpha angle
+  @param    plist   FITS header
+  @return   pointer to statically allocated character string
+ */
+/*---------------------------------------------------------------------------*/
+double sinfo_pfits_get_alpha(const cpl_propertylist * plist)
+{
+  return cpl_propertylist_get_double(plist,"ESO TEL TARG OFFSETALPHA");
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    find out the targ alpha angle
+  @param    plist   FITS header
+  @return   pointer to statically allocated character string
+ */
+/*---------------------------------------------------------------------------*/
+double sinfo_pfits_get_targ_alpha(const cpl_propertylist * plist)
+{
+  return cpl_propertylist_get_double(plist,"ESO INS TARG ALPHA");
+}
+
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    find out the targ delta angle
+  @param    plist   FITS header
+  @return   pointer to statically allocated character string
+ */
+/*---------------------------------------------------------------------------*/
+double sinfo_pfits_get_targ_delta(const cpl_propertylist * plist)
+{
+  return cpl_propertylist_get_double(plist,"ESO INS TARG DELTA");
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    find out the arcfile   
+  @param    plist   FITS header
+  @return   pointer to statically allocated character string
+ */
+/*---------------------------------------------------------------------------*/
+const char * sinfo_pfits_get_arcfile(const cpl_propertylist * plist)
+{
+    return (const char*) cpl_propertylist_get_string(plist,KEY_NAME_ARCFILE);
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    find out the arcfile   
+  @param    plist   FITS header
+  @return   pointer to statically allocated character string
+ */
+/*---------------------------------------------------------------------------*/
+const char * sinfo_pfits_get_rec1raw1name(const cpl_propertylist * plist)
+{
+    return (const char*) cpl_propertylist_get_string(plist,
+                                                  KEY_NAME_PRO_REC1_RAW1_NAME);
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    find out the instrument setup id
+  @param    plist   FITS header
+  @return   pointer to statically allocated character string
+ */
+/*---------------------------------------------------------------------------*/
+const char * sinfo_pfits_get_ins_setup(const cpl_propertylist * plist)
+{
+  if(cpl_propertylist_get_string(plist,"ESO INS SETUP ID")) {
+    return (const char*) cpl_propertylist_get_string(plist,"ESO INS SETUP ID");
+  } else {
+    cpl_error_reset();
+    return "Dark";
+  }
+
+}
+
+
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    find out the central wavelength
+  @param    plist   FITS header
+  @return   pointer to statically allocated character string
+ */
+/*---------------------------------------------------------------------------*/
+double sinfo_pfits_get_wlen(const cpl_propertylist * plist)
+{
+
+    return cpl_propertylist_get_double(plist,"ESO INS GRAT1 WLEN");
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    find out the number of chopping cycles
+  @param    plist   FITS header
+  @return   pointer to statically allocated character string
+ */
+/*---------------------------------------------------------------------------*/
+int sinfo_pfits_get_chop_ncycles(const cpl_propertylist * plist)
+{
+
+    return cpl_propertylist_get_int(plist,"ESO DET CHOP NCYCLES");
+
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    find out the number of chopping cycles
+  @param    plist   FITS header
+  @return   pointer to statically allocated character string
+ */
+/*---------------------------------------------------------------------------*/
+double sinfo_pfits_get_pixscale(const cpl_propertylist * plist)
+{
+  const char* val=NULL;
+  val=cpl_propertylist_get_string(plist,"ESO INS OPTI1 NAME");
+  return atof(val);
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    find out the value of the CUMOFFSETX keyword in a header
+  @param    plist   FITS header
+  @return   keyword value
+ */
+/*---------------------------------------------------------------------------*/
+double sinfo_pfits_get_posangle(const cpl_propertylist * plist)
+{
+    return cpl_propertylist_get_double(plist,"ESO ADA POSANG");
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    find out the value of the CUMOFFSETX keyword in a header
+  @param    plist   FITS header
+  @return   keyword value
+ */
+/*---------------------------------------------------------------------------*/
+double sinfo_pfits_get_DEC(const cpl_propertylist * plist)
+{
+    return cpl_propertylist_get_double(plist,"DEC");
+}
+
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    find out the value of the CUMOFFSETX keyword in a header
+  @param    plist   iput propertylist
+  @return   pointer to statically allocated character string
+ */
+/*---------------------------------------------------------------------------*/
+double sinfo_pfits_get_cumoffsetx(const cpl_propertylist * plist)
+{
+    return cpl_propertylist_get_double(plist,"ESO SEQ CUMOFFSETX");
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    find out the value of the CUMOFFSETY keyword in a header
+  @param    plist  input propertylist 
+  @return   pointer to statically allocated character string
+ */
+/*---------------------------------------------------------------------------*/
+double sinfo_pfits_get_cumoffsety(const cpl_propertylist * plist)
+{
+    return cpl_propertylist_get_double(plist,"ESO SEQ CUMOFFSETY");
+}
+
+/*---------------------------------------------------------------------------*/
+/**     
+  @brief    find out the date of observation  
+  @param    plist   FITS header
+  @return   pointer to statically allocated character string
+ */ 
+/*---------------------------------------------------------------------------*/
+const char * sinfo_pfits_get_date_obs(const cpl_propertylist * plist)
+{
+
+    return (const char*) cpl_propertylist_get_string(plist,"DATE-OBS");
+
+}
+        
+/*---------------------------------------------------------------------------*/
+/** 
+  @brief    find out the DELTA keyword in a SINFONI header
+  @param    plist   FITS header
+  @return   pointer to statically allocated character string
+ */
+/*---------------------------------------------------------------------------*/
+double  sinfo_pfits_get_delta(const cpl_propertylist * plist)
+{
+
+    return cpl_propertylist_get_double(plist,"ESO TEL TARG OFFSETDELTA");
+
+}
+
+/*---------------------------------------------------------------------------*/
+/** 
+  @brief    find out the DEC keyword in a SINFONI header
+  @param    plist   FITS header
+  @return   pointer to statically allocated character string
+ */
+/*---------------------------------------------------------------------------*/
+double  sinfo_pfits_get_dec(const cpl_propertylist * plist)
+{
+    return cpl_propertylist_get_double(plist,"DEC");
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    find out the character string associated to the DIT keyword
+            in an sinfoni header
+  @param    plist   FITS header 
+  @return   dit value
+ */
+/*---------------------------------------------------------------------------*/
+double sinfo_pfits_get_dit(const cpl_propertylist * plist)
+{
+    return cpl_propertylist_get_double(plist,"ESO DET DIT");
+}
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    find out the value of the INS OPTI1 NAME keyword in a header
+  @param    name   filename 
+  @return   pixel scale
+ */
+/*---------------------------------------------------------------------------*/
+float sinfo_pfits_get_pixelscale(const char * name)
+{
+  cpl_propertylist* plist=NULL;
+  float pixscale=0;
+  const char* scale=NULL;
+  plist=cpl_propertylist_load(name,0);
+  scale= cpl_propertylist_get_string(plist,"ESO INS OPTI1 NAME");
+  pixscale=atof(scale);
+  sinfo_free_propertylist(&plist);
+  return pixscale;
+}
+
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    find out the character string associated to the DIT keyword
+            in an sinfoni header
+  @param    plist    FITS header
+  @return   pointer to statically allocated character string
+ */
+/*---------------------------------------------------------------------------*/
+const char * sinfo_pfits_get_ncorrs_name(const cpl_propertylist * plist)
+{
+    return cpl_propertylist_get_string(plist,"ESO DET NCORRS NAME");
+}
+
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    find out the character string associated to the FILT1.NAME keyword
+            in an sinfoni header
+  @param    plist    FITS header
+  @return   pointer to statically allocated character string
+ */
+/*---------------------------------------------------------------------------*/
+const char * sinfo_pfits_get_band(const cpl_propertylist * plist)
+{
+    return cpl_propertylist_get_string(plist,"ESO INS FILT1 NAME");
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    find out the data category as defined by the DataFlow
+  @param    plist   FITS header
+  @return   statically allocated char string, no need to free() it
+ */
+/*---------------------------------------------------------------------------*/
+const char * sinfo_pfits_get_dpr_catg(const cpl_propertylist * plist)
+{
+    return cpl_propertylist_get_string(plist,"ESO DPR CATG");
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    find out the data tech as defined by the DataFlow
+  @param    plist    FITS header
+  @return   statically allocated char string, no need to free() it
+ */
+/*---------------------------------------------------------------------------*/
+const char * sinfo_pfits_get_dpr_tech(const cpl_propertylist * plist)
+{
+    return cpl_propertylist_get_string(plist,"ESO DPR TECH");
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    find out the data type as defined by the DataFlow
+  @param    plist   FITS header
+  @return   statically allocated char string, no need to free() it
+ */
+/*---------------------------------------------------------------------------*/
+const char * sinfo_pfits_get_dpr_type(const cpl_propertylist * plist)
+{
+    return cpl_propertylist_get_string(plist,"ESO DPR TYPE");
+}
+
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    find out the filter in imaging 
+  @param    plist   FITS header
+  @return   pointer to statically allocated character string
+ */
+/*---------------------------------------------------------------------------*/
+const char * sinfo_pfits_get_filter_im(const cpl_propertylist * plist)
+{
+  return cpl_propertylist_get_string(plist,"ESO INS FILT1 NAME");
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    find out the filter in spectroscopy 
+  @param    plist   FITS header
+  @return   pointer to statically allocated character string
+ */
+/*---------------------------------------------------------------------------*/
+const char * sinfo_pfits_get_filter_spec(const cpl_propertylist * plist)
+{
+    return cpl_propertylist_get_string(plist,"ESO INS FILT2 NAME");
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    find out the character string associated to the FOCUS keyword
+  @param    plist   FITS header
+  @return   pointer to statically allocated character string
+ */
+/*---------------------------------------------------------------------------*/
+double sinfo_pfits_get_focus(const cpl_propertylist * plist)
+{
+    return cpl_propertylist_get_double(plist,"ESO TEL FOCU LEN");
+}
+
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    find out the frame type   
+  @param    plist   FITS header
+  @return   pointer to statically allocated character string
+ */
+/*---------------------------------------------------------------------------*/
+const char * sinfo_pfits_get_frame_type(const cpl_propertylist * plist)
+{
+    return cpl_propertylist_get_string(plist,"ESO DET FRAM TYPE");
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    find out the character string associated to the instrument
+  @param    plist   FITS header
+  @return   pointer to statically allocated character string
+ */
+/*---------------------------------------------------------------------------*/
+const char * sinfo_pfits_get_instrument(const cpl_propertylist * plist)
+{
+    return cpl_propertylist_get_string(plist,"INSTRUME");
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    find out the mjd-obs keyword 
+  @param    plist   FITS header
+  @return   pointer to statically allocated character string
+ */
+/*---------------------------------------------------------------------------*/
+double sinfo_pfits_get_mjdobs(const cpl_propertylist * plist)
+{
+    return cpl_propertylist_get_double(plist,"MJD-OBS");
+}
+
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    find out the character string associated to INS.MONOC1.POS
+  @param    plist   FITS header
+  @return   pointer to statically allocated character string
+ */
+/*---------------------------------------------------------------------------*/
+double sinfo_pfits_get_monoc_pos(const cpl_propertylist * plist)
+{
+    return cpl_propertylist_get_double(plist,"INS MONOC1 POS");
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    find out the character string associated to the NDIT keyword
+  @param    plist   FITS header
+  @return   value of NDIT keyword
+ */
+/*---------------------------------------------------------------------------*/
+int sinfo_pfits_get_ndit(const cpl_propertylist * plist)
+{
+    return cpl_propertylist_get_int(plist,"ESO DET NDIT");
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    find out the character string associated to the NAXIS1 keyword
+  @param    plist    FITS header
+  @return   keyword value
+ */
+/*---------------------------------------------------------------------------*/
+int sinfo_pfits_get_naxis1(const cpl_propertylist * plist)
+{
+    return cpl_propertylist_get_int(plist,"NAXIS1");
+}
+
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    find out the character string associated to the NAXIS2 keyword
+  @param    plist    FITS header
+  @return   keyword value
+ */
+/*---------------------------------------------------------------------------*/
+int sinfo_pfits_get_naxis2(const cpl_propertylist * plist)
+{
+    return cpl_propertylist_get_int(plist,"NAXIS2");
+}
+
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    find out the character string associated to the NAXIS3 keyword
+  @param    plist    FITS header
+  @return   keyword value
+ */
+/*---------------------------------------------------------------------------*/
+int sinfo_pfits_get_naxis3(const cpl_propertylist * plist)
+{
+    return cpl_propertylist_get_int(plist,"NAXIS3");
+}
+
+
+
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    find out the character string associated to the CRPIX1 keyword
+  @param    plist    FITS header
+  @return   keyword value
+ */
+/*---------------------------------------------------------------------------*/
+double sinfo_pfits_get_crpix1(const cpl_propertylist * plist)
+{
+    return cpl_propertylist_get_double(plist,"CRPIX1");
+}
+
+
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    find out the character string associated to the CRPIX2 keyword
+  @param    plist    FITS header
+  @return   keyword value
+ */
+/*---------------------------------------------------------------------------*/
+double sinfo_pfits_get_crpix2(const cpl_propertylist * plist)
+{
+    return cpl_propertylist_get_double(plist,"CRPIX2");
+}
+
+
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    find out the character string associated to the CRPIX3 keyword
+  @param    plist    FITS header
+  @return   keyword value
+ */
+/*---------------------------------------------------------------------------*/
+double sinfo_pfits_get_crpix3(const cpl_propertylist * plist)
+{
+    return cpl_propertylist_get_double(plist,"CRPIX3");
+}
+
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    find out the character string associated to the CDELT1 keyword
+  @param    plist    FITS header
+  @return   keyword value
+ */
+/*---------------------------------------------------------------------------*/
+double sinfo_pfits_get_cdelt1(const cpl_propertylist * plist)
+{
+    return cpl_propertylist_get_double(plist,"CDELT1");
+}
+
+
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    find out the character string associated to the CDELT2 keyword
+  @param    plist    FITS header
+  @return   keyword value
+ */
+/*---------------------------------------------------------------------------*/
+double sinfo_pfits_get_cdelt2(const cpl_propertylist * plist)
+{
+    return cpl_propertylist_get_double(plist,"CDELT2");
+}
+
+
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    find out the character string associated to the CDELT3 keyword
+  @param    plist    FITS header
+  @return   keyword value
+ */
+/*---------------------------------------------------------------------------*/
+double sinfo_pfits_get_cdelt3(const cpl_propertylist * plist)
+{
+    return cpl_propertylist_get_double(plist,"CDELT3");
+}
+
+
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    find out the character string associated to the CVRVAL1 keyword
+  @param    plist    FITS header
+  @return   keyword value
+ */
+/*---------------------------------------------------------------------------*/
+double sinfo_pfits_get_crval1(const cpl_propertylist * plist)
+{
+    return cpl_propertylist_get_double(plist,"CRVAL1");
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    find out the character string associated to the CVRVAL2 keyword
+  @param    plist    FITS header
+  @return   keyword value
+ */
+/*---------------------------------------------------------------------------*/
+double sinfo_pfits_get_crval2(const cpl_propertylist * plist)
+{
+    return cpl_propertylist_get_double(plist,"CRVAL2");
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    find out the character string associated to the CVRVAL3 keyword
+  @param    plist    FITS header
+  @return   keyword value
+ */
+/*---------------------------------------------------------------------------*/
+double sinfo_pfits_get_crval3(const cpl_propertylist * plist)
+{
+    return cpl_propertylist_get_double(plist,"CRVAL3");
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    find out the number of expositions  
+  @param    plist    FITS header
+  @return   pointer to statically allocated character string
+ */
+/*---------------------------------------------------------------------------*/
+int sinfo_pfits_get_numbexp(const cpl_propertylist * plist)
+{
+    return cpl_propertylist_get_int(plist,"ESO TPL NEXP");
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    find out the OBS ID keyword 
+  @param    plist   FITS header
+  @return   pointer to statically allocated character string
+ */
+/*---------------------------------------------------------------------------*/
+const char * sinfo_pfits_get_obs_id(const cpl_propertylist * plist)
+{
+    return cpl_propertylist_get_string(plist,"ESO OBS ID");
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    find out the character string associated to nodding position
+  @param    plist   FITS header
+  @return   pointer to statically allocated character string
+*/
+/*---------------------------------------------------------------------------*/
+int sinfo_pfits_get_nodpos(const cpl_propertylist * plist)
+{
+    return cpl_propertylist_get_int(plist,"ESO SEQ NODPOS");
+}
+
+
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    find out the RA keyword in a SINFONI header
+  @param    plist   FITS header
+  @return   pointer to statically allocated character string
+ */
+/*---------------------------------------------------------------------------*/
+double sinfo_pfits_get_ra(const cpl_propertylist * plist)
+{
+    return cpl_propertylist_get_double(plist,"RA");
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    find out the std star name 
+  @param    plist   FITS header
+  @return   pointer to statically allocated character string
+ */
+/*---------------------------------------------------------------------------*/
+const char * sinfo_pfits_get_starname(const cpl_propertylist * plist)
+{
+    return cpl_propertylist_get_string(plist,"ESO OBS TARG NAME");
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    find out the spectral resolution
+  @param    plist    FITS header
+  @return   pointer to statically allocated character string
+ */
+/*---------------------------------------------------------------------------*/
+double sinfo_pfits_get_resol(const cpl_propertylist * plist)
+{
+    return cpl_propertylist_get_double(plist,"ESO INS RESOL");
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    find out the template id    
+  @param    plist    FITS header
+  @return   pointer to statically allocated character string
+*/
+/*---------------------------------------------------------------------------*/
+const char * sinfo_pfits_get_templateid(const cpl_propertylist * plist)
+{
+    return (const char*) cpl_propertylist_get_string(plist,"ESO TPL ID"); 
+}
+/**
+ at brief set hdu keys 
+ at param plist input propertylist
+ at param hduclas1 hdu classification1 value
+ at param hduclas2 hdu classification2 value
+ at param hduclas3 hdu classification3 value
+ at return updated propertylist
+*/
+static cpl_error_code
+sinfo_plist_set_extra_common_keys(cpl_propertylist* plist)
+{
+
+    cpl_propertylist_append_string(plist,"HDUCLASS", "ESO") ;
+    cpl_propertylist_set_comment(plist,"HDUCLASS","hdu classification") ;
+
+    cpl_propertylist_append_string(plist,"HDUDOC", "DICD") ;
+    cpl_propertylist_set_comment(plist,"HDUDOC","hdu reference document") ;
+
+    cpl_propertylist_append_string(plist,"HDUVERS", "DICD V6.0") ;
+    cpl_propertylist_set_comment(plist,"HDUVERS","hdu reference document version") ;
+
+    return cpl_error_get_code();
+}
+
+/**
+ at brief set hdu keys 
+ at param plist input propertylist
+ at param hduclas1 hdu classification1 value
+ at param hduclas2 hdu classification2 value
+ at param hduclas3 hdu classification3 value
+ at param scidata  name of data extension
+ at param errdata  name of errs extension
+ at param qualdata name of qual extension
+ at param type type of extension: 0 data, 1 errs, 2 qual
+ at return updated propertylist
+*/
+cpl_error_code
+sinfo_plist_set_extra_keys(cpl_propertylist* plist,
+			 const char* hduclas1,
+			 const char* hduclas2,
+			 const char* hduclas3,
+			 const char* scidata,
+			 const char* errdata,
+			 const char* qualdata,
+                         const int type)
+{
+
+  cpl_ensure_code(type<3,CPL_ERROR_ILLEGAL_INPUT);
+  cpl_ensure_code(type>=0,CPL_ERROR_ILLEGAL_INPUT);
+
+  sinfo_plist_set_extra_common_keys(plist);
+
+  cpl_propertylist_append_string(plist,"HDUCLAS1",hduclas1) ;
+  cpl_propertylist_set_comment(plist,"HDUCLAS1","hdu format classification") ;
+
+  cpl_propertylist_append_string(plist,"HDUCLAS2",hduclas2) ;
+  cpl_propertylist_set_comment(plist,"HDUCLAS2","hdu type classification") ;
+
+  if(type!=0) {
+    cpl_propertylist_append_string(plist,"HDUCLAS3",hduclas3) ;
+    cpl_propertylist_set_comment(plist,"HDUCLAS3","hdu info classification") ;
+    cpl_propertylist_append_string(plist,"SCIDATA",scidata) ;
+    cpl_propertylist_set_comment(plist,"SCIDATA","name of data extension") ;
+  }
+
+  if(type!=1) {
+/* CASA prefers to have these not set if the extension actually does not exist
+    cpl_propertylist_append_string(plist,"ERRDATA",errdata) ;
+    cpl_propertylist_set_comment(plist,"ERRDATA","name of errs extension") ;
+*/
+  }
+
+  if(type!=2) {
+/* CASA prefers to have these not set if the extension actually does not exist
+    cpl_propertylist_append_string(plist,"QUALDATA",qualdata) ;
+    cpl_propertylist_set_comment(plist,"QUALDATA","name of qual extension") ;
+*/
+  }
+
+  return cpl_error_get_code();
+}
+
+/**@}*/
diff --git a/sinfoni/sinfo_pfits.h b/sinfoni/sinfo_pfits.h
new file mode 100644
index 0000000..2ad9acc
--- /dev/null
+++ b/sinfoni/sinfo_pfits.h
@@ -0,0 +1,127 @@
+/* $Id: sinfo_pfits.h,v 1.6 2012/03/22 15:26:10 amodigli Exp $
+ *
+ * This file is part of the NACO Pipeline
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2012/03/22 15:26:10 $
+ * $Revision: 1.6 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifndef SINFO_PFITS_H
+#define SINFO_PFITS_H
+
+/*-----------------------------------------------------------------------------
+                                   Includes
+ -----------------------------------------------------------------------------*/
+#include <cpl.h>
+
+/*
+#include <sinfo_dfs.h>
+*/
+
+/*-----------------------------------------------------------------------------
+                                   Functions prototypes
+ -----------------------------------------------------------------------------*/
+
+CPL_BEGIN_DECLS
+const char * sinfo_pfits_get_rec1raw1name(const cpl_propertylist * plist) ;
+const char * sinfo_pfits_get_band(const cpl_propertylist * plist);
+float sinfo_pfits_get_pixelscale (const char * filename );
+double sinfo_pfits_get_targ_alpha(const cpl_propertylist * plist);
+double sinfo_pfits_get_targ_delta(const cpl_propertylist * plist);
+
+/*
+char * sinfo_pfits_get_rec1raw1name(const char * filename) ;
+*/
+int sinfo_pfits_get_expno(const cpl_propertylist *) ;
+double  sinfo_pfits_get_exptime(const char *) ;
+char * sinfo_pfits_get_mode(const cpl_propertylist *) ;
+
+double sinfo_pfits_get_pixscale(const cpl_propertylist * plist);
+double sinfo_pfits_get_exp_time(const cpl_propertylist* plist);
+double sinfo_pfits_get_DEC(const cpl_propertylist * plist);
+double sinfo_pfits_get_posangle(const cpl_propertylist * plist);
+int sinfo_pfits_get_rom(const cpl_propertylist * propertylist);
+const char * sinfo_pfits_get_ncorrs_name(const cpl_propertylist * plist) ;
+const char * sinfo_pfits_get_date_obs(const cpl_propertylist * plist) ;
+const char * sinfo_pfits_get_ins_setup(const cpl_propertylist * plist);
+double sinfo_pfits_get_airmass_start(const cpl_propertylist * plist) ;
+const char * sinfo_pfits_get_templateid(const cpl_propertylist * plist) ;
+double sinfo_pfits_get_dit(const cpl_propertylist * plist) ;
+int    sinfo_pfits_get_ndit(const cpl_propertylist * plist) ;
+const char * sinfo_pfits_get_dpr_catg(const cpl_propertylist * plist) ;
+const char * sinfo_pfits_get_dpr_tech(const cpl_propertylist * plist) ;
+const char * sinfo_pfits_get_dpr_type(const cpl_propertylist * plist) ;
+const char * sinfo_pfits_get_arcfile(const cpl_propertylist * plist) ;
+double sinfo_pfits_get_ditndit(const char* name);
+/* not used */
+int sinfo_pfits_get_nodpos(const cpl_propertylist *) ;
+double sinfo_pfits_get_ra(const cpl_propertylist *) ;
+double sinfo_pfits_get_resol(const cpl_propertylist *) ;
+const char * sinfo_pfits_get_starname(const cpl_propertylist *) ;
+const char * sinfo_pfits_get_obs_id(const cpl_propertylist *) ;
+const char * sinfo_pfits_get_instrument(const cpl_propertylist *) ;
+const char * sinfo_pfits_get_filter_spec(const cpl_propertylist *) ;
+const char * sinfo_pfits_get_filter_im(const cpl_propertylist *) ;
+const char * sinfo_pfits_get_frame_type(const cpl_propertylist *) ;
+int sinfo_pfits_get_numbexp(const cpl_propertylist *) ;
+double sinfo_pfits_get_mjdobs(const cpl_propertylist *) ;
+double sinfo_pfits_get_focus(const cpl_propertylist *) ;
+double sinfo_pfits_get_cumoffsetx(const cpl_propertylist *) ;
+double sinfo_pfits_get_cumoffsety(const cpl_propertylist *) ;
+double sinfo_pfits_get_alpha(const cpl_propertylist *) ;
+double sinfo_pfits_get_airmass_end(const cpl_propertylist *) ;
+double sinfo_pfits_get_dec(const cpl_propertylist *) ;
+double sinfo_pfits_get_wlen(const cpl_propertylist *) ;
+double sinfo_pfits_get_delta(const cpl_propertylist *) ;
+int sinfo_pfits_get_naxis1(const cpl_propertylist *) ;
+int sinfo_pfits_get_naxis2(const cpl_propertylist *) ;
+int sinfo_pfits_get_naxis3(const cpl_propertylist *) ;
+
+
+double sinfo_pfits_get_crval1(const cpl_propertylist *) ;
+double sinfo_pfits_get_crval2(const cpl_propertylist *) ;
+double sinfo_pfits_get_crval3(const cpl_propertylist *) ;
+
+double sinfo_pfits_get_crpix1(const cpl_propertylist *) ;
+double sinfo_pfits_get_crpix2(const cpl_propertylist *) ;
+double sinfo_pfits_get_crpix3(const cpl_propertylist *) ;
+
+double sinfo_pfits_get_cdelt1(const cpl_propertylist *) ;
+double sinfo_pfits_get_cdelt2(const cpl_propertylist *) ;
+double sinfo_pfits_get_cdelt3(const cpl_propertylist *) ;
+
+
+/* keys not existent */
+int sinfo_pfits_get_chop_ncycles(const cpl_propertylist * plist) ;
+double sinfo_pfits_get_monoc_pos(const cpl_propertylist *) ;
+cpl_error_code
+sinfo_plist_set_extra_keys(cpl_propertylist* plist,
+			 const char* hduclas1,
+			 const char* hduclas2,
+			 const char* hduclas3,
+			 const char* scidata,
+			 const char* errdata,
+			 const char* qualdata,
+                         const int type);
+CPL_END_DECLS
+
+#endif
diff --git a/sinfoni/sinfo_pixel_handling.c b/sinfoni/sinfo_pixel_handling.c
new file mode 100644
index 0000000..c7f5856
--- /dev/null
+++ b/sinfoni/sinfo_pixel_handling.c
@@ -0,0 +1,141 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+ /*---------------------------------------------------------------------------
+   
+   File name     :    pixel_handling.c
+   Author         :    Nicolas Devillard
+   Created on    :    March 04, 1997
+   Description    :    Functions processing arrays of pixels.
+
+ ---------------------------------------------------------------------------*/
+/*
+
+ $Id: sinfo_pixel_handling.c,v 1.6 2012/03/03 09:50:08 amodigli Exp $
+ $Author: amodigli $
+ $Date: 2012/03/03 09:50:08 $
+ $Revision: 1.6 $
+
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+/*---------------------------------------------------------------------------
+                                  Includes
+ ---------------------------------------------------------------------------*/
+#include <cpl.h>
+#include "sinfo_pixel_handling.h"
+/**@{*/
+/**
+ * @addtogroup sinfo_utilities  Pixel handling
+ *
+ * TBD
+ */
+
+
+
+/*---------------------------------------------------------------------------
+                                Function codes
+ ---------------------------------------------------------------------------*/
+/**
+  @name        sinfo_pixel_qsort
+  @memo        Sort an array of pixels by increasing pixelvalue.
+  @param    pix_arr        Array to sort.
+  @param    npix        Number of pixels in the array.
+  @return    void
+  @doc
+
+  Optimized implementation of a fast pixel sort. The input array is
+  modified.
+ */
+#define PIX_SWAP(a,b) { pixelvalue temp=(a);(a)=(b);(b)=temp; }
+#define PIX_STACK_SIZE 50
+
+void 
+sinfo_pixel_qsort(pixelvalue *pix_arr, int npix)
+{
+    int         i,
+                ir,
+                j,
+                k,
+                l;
+    int        i_stack[PIX_STACK_SIZE*sizeof(pixelvalue)] ;
+    int         j_stack ;
+    pixelvalue  a ;
+
+    ir = npix ;
+    l = 1 ;
+    j_stack = 0 ;
+    for (;;) {
+        if (ir-l < 7) {
+            for (j=l+1 ; j<=ir ; j++) {
+                a = pix_arr[j-1];
+                for (i=j-1 ; i>=1 ; i--) {
+                    if (pix_arr[i-1] <= a) break;
+                    pix_arr[i] = pix_arr[i-1];
+                }
+                pix_arr[i] = a;
+            }
+            if (j_stack == 0) break;
+            ir = i_stack[j_stack-- -1];
+            l  = i_stack[j_stack-- -1];
+        } else {
+            k = (l+ir) >> 1;
+            PIX_SWAP(pix_arr[k-1], pix_arr[l])
+            if (pix_arr[l] > pix_arr[ir-1]) {
+                PIX_SWAP(pix_arr[l], pix_arr[ir-1])
+            }
+            if (pix_arr[l-1] > pix_arr[ir-1]) {
+                PIX_SWAP(pix_arr[l-1], pix_arr[ir-1])
+            }
+            if (pix_arr[l] > pix_arr[l-1]) {
+                PIX_SWAP(pix_arr[l], pix_arr[l-1])
+            }
+            i = l+1;
+            j = ir;
+            a = pix_arr[l-1];
+            for (;;) {
+                do i++; while (pix_arr[i-1] < a);
+                do j--; while (pix_arr[j-1] > a);
+                if (j < i) break;
+                PIX_SWAP(pix_arr[i-1], pix_arr[j-1]);
+            }
+            pix_arr[l-1] = pix_arr[j-1];
+            pix_arr[j-1] = a;
+            j_stack += 2;
+            if (j_stack > PIX_STACK_SIZE) {
+                sinfo_msg_error("stack too small : aborting");
+                exit(-2001) ;
+            }
+            if (ir-i+1 >= j-l) {
+                i_stack[j_stack-1] = ir;
+                i_stack[j_stack-2] = i;
+                ir = j-1;
+            } else {
+                i_stack[j_stack-1] = j-1;
+                i_stack[j_stack-2] = l;
+                l = i;
+            }
+        }
+    }
+}
+#undef PIX_STACK_SIZE
+#undef PIX_SWAP
+
+/**@}*/
diff --git a/sinfoni/sinfo_pixel_handling.h b/sinfoni/sinfo_pixel_handling.h
new file mode 100644
index 0000000..6db2669
--- /dev/null
+++ b/sinfoni/sinfo_pixel_handling.h
@@ -0,0 +1,57 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+ /*---------------------------------------------------------------------------
+   
+   File name     :    sinfo_pixel_handling.c
+   Author         :    Nicolas Devillard
+   Created on    :    March 4th, 1997
+   Description    :    Functions to handle list of pixels and their use
+
+ ---------------------------------------------------------------------------*/
+/*
+ $Id: sinfo_pixel_handling.h,v 1.5 2007/06/06 07:10:45 amodigli Exp $
+ $Author: amodigli $
+ $Date: 2007/06/06 07:10:45 $
+ $Revision: 1.5 $
+ */
+#ifndef SINFO_PIXEL_HANDLING_H
+#define SINFO_PIXEL_HANDLING_H
+/*---------------------------------------------------------------------------
+                                   Includes
+ ---------------------------------------------------------------------------*/
+#include "sinfo_local_types.h"
+#include "sinfo_msg.h"
+/*---------------------------------------------------------------------------
+                                 Function ANSI prototypes
+ ---------------------------------------------------------------------------*/
+/**
+  @name     sinfo_pixel_qsort
+  @memo     Sort an array of pixels by increasing pixelvalue.
+  @param    pix_arr     Array to sort.
+  @param    npix        Number of pixels in the array.
+  @return   void
+  @doc
+ 
+  Optimized implementation of a fast pixel sort. The input array is
+  modified.
+ */
+
+void 
+sinfo_pixel_qsort(pixelvalue *pix_arr, int npix) ;
+#endif
diff --git a/sinfoni/sinfo_poly2d.c b/sinfoni/sinfo_poly2d.c
new file mode 100644
index 0000000..565b2b4
--- /dev/null
+++ b/sinfoni/sinfo_poly2d.c
@@ -0,0 +1,82 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*---------------------------------------------------------------------------
+   
+   File name     :    poly2d.c
+   Author         :    N. Devillard
+   Created on    :    22 Jun 1999
+   Description    :    2D polynomial handling
+
+ *--------------------------------------------------------------------------*/
+/*
+    $Id: sinfo_poly2d.c,v 1.4 2012/03/03 09:50:08 amodigli Exp $
+    $Author: amodigli $
+    $Date: 2012/03/03 09:50:08 $
+    $Revision: 1.4 $
+*/
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+/*---------------------------------------------------------------------------
+                                   Includes
+ ---------------------------------------------------------------------------*/
+#include "sinfo_poly2d.h"
+/**@{*/
+/**
+ * @addtogroup sinfo_utilities  2D polynomial computation 
+ *
+ * TBD
+ */
+
+
+
+/**
+  @name        sinfo_poly2d_compute
+  @memo        Compute the value of a poly2d at a given point.
+  @param    p    Poly2d object.
+  @param    x    x coordinate.
+  @param    y    y coordinate.
+  @return    The value of the 2d polynomial at (x,y) as a double.
+  @doc
+
+  This computes the value of a poly2d in a single point. To
+  compute many values in a row, see sinfo_poly2d_compute_array().
+ */
+
+double
+sinfo_poly2d_compute(
+    poly2d    *    p,
+    double        x,
+    double        y
+)
+{
+    double    z ;
+    int        i ;
+
+    z = 0.00 ;
+
+    for (i=0 ; i<p->nc ; i++) {
+        z += p->c[i] * sinfo_ipow(x, p->px[i]) * sinfo_ipow(y, p->py[i]) ;
+    }
+    return z ;
+}
+/**@}*/
+
+
+
diff --git a/sinfoni/sinfo_poly2d.h b/sinfoni/sinfo_poly2d.h
new file mode 100644
index 0000000..75f25c7
--- /dev/null
+++ b/sinfoni/sinfo_poly2d.h
@@ -0,0 +1,129 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/*---------------------------------------------------------------------------
+   
+   File name     :    sinfo_poly2d.h
+   Author         :    N. Devillard
+   Created on    :    22 Jun 1999
+   Description    :    2D polynomial handling
+
+ *--------------------------------------------------------------------------*/
+
+/*
+    $Id: sinfo_poly2d.h,v 1.4 2007/06/06 07:10:45 amodigli Exp $
+    $Author: amodigli $
+    $Date: 2007/06/06 07:10:45 $
+    $Revision: 1.4 $
+*/
+
+#ifndef SINFO_POLY2D_H
+#define SINFO_POLY2D_H
+
+/*---------------------------------------------------------------------------
+                                   Includes
+ ---------------------------------------------------------------------------*/
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "sinfo_ipow.h"
+#include "sinfo_msg.h"
+#include <cpl.h>
+/*---------------------------------------------------------------------------
+                                   New types
+ ---------------------------------------------------------------------------*/
+
+/**
+  @name        poly2d
+  @memo        2d Polynomial object.
+  @doc
+
+  The following structure defines a 2d polynomial. 'deg' is the
+  highest degree in the polynomial.
+  
+  \begin{itemize}
+  \item 'nc' contains the number of coefficients in px, py, and c.
+  \item 'px' and 'py' contain the powers of resp. x and y.
+  \item 'c' contains the coefficients themselves.
+  \end{itemize}
+
+  For example, if you want to store the following polynomial:
+  \begin{verbatim}
+  p(x,y) = p0 + p1.x + p2.y + p3.x.y + p4.x^2 + p5.y^2
+  \end{verbatim}
+
+  You would have:
+
+  \begin{verbatim}
+  nc  = 6 (from 0 to 5 incl.)
+  px contains:  0  1  0  1  2  0
+  py contains:  0  0  1  1  0  2
+  c  contains: p0 p1 p2 p3 p4 p5
+  So that given x0 and y0, computing the polynomial is done with:
+ 
+  poly2d    p ;
+  int       i ;
+  double    x0, y0, poly ;
+ 
+  poly = 0.00 ;
+  for (i=0 ; i<p.nc ; i++) {
+      poly += p.c[i] * sinfo_ipow(x0, p.px[i]) * sinfo_ipow(y0, p.py[i]) ;
+  }
+
+  or simply:
+  poly = sinfo_poly2d_compute(&p, x0, y0);
+  \end{verbatim}
+ */
+
+struct _2D_POLY_ {
+    int            nc ;        /* number of coefficients in px, py, c */
+    int        *    px ;        /* powers of x                         */
+    int        *    py ;        /* powers of y                         */
+    double    *    c ;            /* polynomial coefficients             */
+} ;
+
+typedef struct _2D_POLY_ poly2d ;
+
+
+
+/*---------------------------------------------------------------------------
+                               Function codes    
+ ---------------------------------------------------------------------------*/
+
+/**
+  @name     sinfo_poly2d_compute
+  @memo     Compute the value of a poly2d at a given point.
+  @param    p   Poly2d object.
+  @param    x   x coordinate.
+  @param    y   y coordinate.
+  @return   The value of the 2d polynomial at (x,y) as a double.
+  @doc
+ 
+  This computes the value of a poly2d in a single point. To
+  compute many values in a row, see sinfo_poly2d_compute_array().
+ */
+
+double
+sinfo_poly2d_compute(
+    poly2d    *    p,
+    double        x,
+    double        y
+);
+
+#endif
diff --git a/sinfoni/sinfo_prepare_stacked_frames_config.c b/sinfoni/sinfo_prepare_stacked_frames_config.c
new file mode 100644
index 0000000..c6d45b4
--- /dev/null
+++ b/sinfoni/sinfo_prepare_stacked_frames_config.c
@@ -0,0 +1,357 @@
+/* $Id: sinfo_prepare_stacked_frames_config.c,v 1.8 2008/02/27 15:10:05 amodigli Exp $
+ *
+ * This file is part of the CPL (Common Pipeline Library)
+ * Copyright (C) 2002 European Southern Observatory
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*
+ * $Author: amodigli $
+ * $Date: 2008/02/27 15:10:05 $
+ * $Revision: 1.8 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+ /**************************************************************************
+  * Prepare_Stacked_Frames Frames Data Reduction Parameter Initialization  *
+  **************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#include "sinfo_prepare_stacked_frames_config.h"
+/**@{*/
+/**
+ * @addtogroup sinfo_rec_jitter Stacking parameters definition & initialization
+ *
+ * TBD
+ */
+
+/**
+ at name  sinfo_prepare_stacked_config_add
+ at brief stacking parameters definition & initialization
+ at param list pointer to cpl_parameterlist
+ at return void
+*/
+void
+ sinfo_prepare_stacked_frames_config_add(cpl_parameterlist *list)
+{
+
+  cpl_parameter *p;
+
+  if (!list) {
+    return;
+  }
+
+/*
+  --------------------------------------------------------------------------
+  Clean Mean 
+  --------------------------------------------------------------------------
+ */
+/* the fraction [0...1] of rejected low intensity pixels when taking 
+the average of columns */
+  p = cpl_parameter_new_range("sinfoni.stacked.low_rejection",
+                  CPL_TYPE_DOUBLE,
+                              "lower rejection",
+                              "sinfoni.stacked",
+                              0.1,0.0,1.0);
+
+  cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI, "stack-lo_rej");
+  cpl_parameterlist_append(list, p);
+
+ /* the fraction [0...1] of rejected high intensity pixels when taking 
+the average of columns */
+  p = cpl_parameter_new_range("sinfoni.stacked.high_rejection",
+                  CPL_TYPE_DOUBLE,
+                              "higher rejection",
+                              "sinfoni.stacked",
+                              0.1,0.0,1.0);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"stack-hi_rej");
+  cpl_parameterlist_append(list, p);
+
+
+/*
+  --------------------------------------------------------------------------
+  Flat Field 
+  --------------------------------------------------------------------------
+ */
+/* indicates if flatfielding is carried through or not */
+  p = cpl_parameter_new_value("sinfoni.stacked.flat_index",
+                  CPL_TYPE_BOOL,
+                              "Flat Index: ",
+                              "sinfoni.stacked",
+                              TRUE);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"stack-flat_ind");
+  cpl_parameterlist_append(list, p);
+
+
+/* indicates if flatfield is normalized to itself 
+   (to remove lamp response curve) */
+  p = cpl_parameter_new_enum("sinfoni.stacked.mflat_norm_smooth",
+                              CPL_TYPE_INT,
+                              "Normalize master flat to its smoothed value "
+                              "(to remove lamp response curve). "
+                              "0 (no smooth). 1 (apply fft filter along y)."
+                              "2 (apply running median filter along y).",
+                              "sinfoni.stacked",
+                             0,3,0,1,2);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"stack-mflat_norm_smooth");
+  cpl_parameterlist_append(list, p);
+
+
+/* indicates if flatfield is normalized to itself 
+   (to remove lamp response curve) */
+  p = cpl_parameter_new_range("sinfoni.stacked.mflat_smooth_rad",
+			      CPL_TYPE_INT,
+                              "Normalization smoothing radii ",
+                              "sinfoni.stacked",
+                              16,3,2048);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"stack-mflat_smooth_rad");
+  cpl_parameterlist_append(list, p);
+
+
+/*
+  --------------------------------------------------------------------------
+  Bad Pixel 
+  --------------------------------------------------------------------------
+ */
+/* indicates if the bad pixels should be interpolated or not */
+  p = cpl_parameter_new_enum("sinfoni.stacked.mask_index",
+                  CPL_TYPE_INT,
+                              "BP Mask Interpolation Switch: "
+                              "indicates if the bad pixel mask should be "
+                 "applied (1) or not (0) ",
+                 /*
+                              "2: indicates that "
+                              "the bad pixels should be interpolated by "
+                              "using bezier splines",
+                 */
+                              "sinfoni.stacked",
+                               1,
+                 2,0,1); /* there was also 2 allowed */
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"stack-mask_ind");
+  cpl_parameterlist_append(list, p);
+
+/* indicates if the bad pixels should be indicated (TRUE) or 
+   interpolated (FALSE)*/
+  p = cpl_parameter_new_value("sinfoni.stacked.ind_index",
+                  CPL_TYPE_BOOL,
+                              "indicates if the bad pixels should be "
+                              "indicated (yes) or interpolated (no)",
+                              "sinfoni.stacked",
+                              FALSE);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"stack-ind_ind");
+  cpl_parameterlist_append(list, p);
+
+
+/* maximal pixel distance from bad pixel to take valid pixels */
+  p = cpl_parameter_new_value("sinfoni.stacked.mask_rad",
+                  CPL_TYPE_INT,
+                              "Max distance bad-good pix: ",
+                              "sinfoni.stacked",
+                              4);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"stack-mask_rad");
+  cpl_parameterlist_append(list, p);
+
+  /* Temporally removed options: index_list, sigma-factor, 
+     used if mask_ind=2,3 */
+  /* file list containing the index files for bezier interpolation */
+  /*
+  p = cpl_parameter_new_value("sinfoni.stacked.index_list",
+                  CPL_TYPE_STRING,
+                              "Contain Index Files: ",
+                              "sinfoni.stacked",
+                              "indexlist");
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"stack-index_list");
+  cpl_parameterlist_append(list, p);
+  */
+
+  /* sigmaFactor for bad pixel search in method maskInd = 3 */
+  /*
+  p = cpl_parameter_new_value("sinfoni.stacked.sigma_factor",
+                  CPL_TYPE_DOUBLE,
+                              "Sigma Factor for bp search: ",
+                              "sinfoni.stacked",
+                              3.);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"stack-sigma_factor");
+  cpl_parameterlist_append(list, p);
+  */
+ 
+/*
+  --------------------------------------------------------------------------
+  Interleaving: only to support dither mode. We comment 
+  --------------------------------------------------------------------------
+ */
+  /* indicates if interleaving should be carried through */
+  /*
+  p = cpl_parameter_new_value("sinfoni.stacked.inter_index",
+                  CPL_TYPE_BOOL,
+                              "Interleaving Switch: ",
+                              "sinfoni.stacked",
+                              FALSE);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"stack-inter_ind");
+  cpl_parameterlist_append(list, p);
+  */
+
+/* number of image rows from which the general offset between the frames is 
+   determined */
+/*
+  p = cpl_parameter_new_value("sinfoni.stacked.no_rows",
+                  CPL_TYPE_INT,
+                              "Number Of Rows",
+                              "sinfoni.stacked",
+                              400);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"stack-no_rows");
+  cpl_parameterlist_append(list, p);
+*/
+
+/*
+  --------------------------------------------------------------------------
+  Gauss Convolution
+  --------------------------------------------------------------------------
+ */
+  /* indicates if a Gaussian convolution is applied or not */
+  p = cpl_parameter_new_value("sinfoni.stacked.gauss_index",
+                  CPL_TYPE_BOOL,
+                              "Gaussian Convolution Switch: ",
+                              "sinfoni.stacked",
+                              FALSE);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"stack-gauss_ind");
+  cpl_parameterlist_append(list, p);
+
+/* kernel half width of the Gaussian response function */
+  p = cpl_parameter_new_value("sinfoni.stacked.kernel_half_width",
+                  CPL_TYPE_INT,
+                              "Kernel Half Width",
+                              "sinfoni.stacked",
+                               2);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"stack-khw");
+  cpl_parameterlist_append(list, p);
+/*
+  --------------------------------------------------------------------------
+  Shift Frames (To be used?)
+  --------------------------------------------------------------------------
+ */
+  /* Suppressed in release 1.1.0 */
+  /* indicates if a Gaussian convolution is applied or not */
+  /*
+  p = cpl_parameter_new_value("sinfoni.stacked.shift_frame_index",
+                  CPL_TYPE_BOOL,
+                              "Shift Frame Switch: ",
+                              "sinfoni.stacked",
+                              FALSE);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"stack-shft_ind");
+  cpl_parameterlist_append(list, p);
+  */
+  /*type of interpolation to be used (0=polynomial , 1=cubic spline) */
+  /*
+  p = cpl_parameter_new_enum("sinfoni.stacked.shift_frame_type",
+                  CPL_TYPE_INT,
+                              "Shift Frame Type: 0 polynomial, 1 cubic,",
+                              "sinfoni.stacked",
+                   1,
+                               2,0,1);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"stack-shft_typ");
+  cpl_parameterlist_append(list, p);
+  */
+  /* order of the interpolation for the spectral shift of frames */
+  /*
+  p = cpl_parameter_new_value("sinfoni.stacked.shift_frame_order",
+                  CPL_TYPE_INT,
+                              "Shift Frame Order",
+                              "sinfoni.stacked",
+                               2);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"stack-shft_ord");
+  cpl_parameterlist_append(list, p);
+  */
+
+/*
+  --------------------------------------------------------------------------
+  WarpFix
+  --------------------------------------------------------------------------
+ */
+  p = cpl_parameter_new_value("sinfoni.stacked.warpfix_ind",
+                  CPL_TYPE_BOOL,
+                              "Warp Fix Index: ",
+                              "sinfoni.stacked",
+                              TRUE);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"stack-warpfix_ind");
+  cpl_parameterlist_append(list, p);
+
+ 
+  p = cpl_parameter_new_enum("sinfoni.stacked.warpfix_kernel",
+                  CPL_TYPE_STRING,
+                 "Warpfix kernel: ",
+                              "sinfoni.stacked",
+                 "tanh",
+                               6,"tanh","sinc","sinc2",
+                              "lanczos","hamming","hann");
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"stack-warpfix_kernel");
+  cpl_parameterlist_append(list, p);
+
+
+ p = cpl_parameter_new_value("sinfoni.stacked.qc_thresh_min",
+                  CPL_TYPE_INT,
+                              "qc_thresh_min",
+                              "sinfoni.stack",
+                              0);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"stack-qc_thresh_min");
+  cpl_parameterlist_append(list, p);
+
+
+  p = cpl_parameter_new_value("sinfoni.stacked.qc_thresh_max",
+                  CPL_TYPE_INT,
+                              "qc_thresh_max",
+                              "sinfoni.stack",
+                              49000);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"stack-qc_thresh_max");
+  cpl_parameterlist_append(list, p);
+
+
+
+  /* indicates if sky raw frame should be subtracted (TRUE) or not (FALSE) */
+  p = cpl_parameter_new_value("sinfoni.stacked.sub_raw_sky",
+			      CPL_TYPE_BOOL,
+                              "indicates if the raw sky frame should be "
+                              "subtracted (TRUE) or (FALSE)",
+                              "sinfoni.stacked",
+                              TRUE);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"stack-sub_raw_sky");
+  cpl_parameterlist_append(list, p);
+
+}
+/**@}*/
diff --git a/sinfoni/sinfo_prepare_stacked_frames_config.h b/sinfoni/sinfo_prepare_stacked_frames_config.h
new file mode 100644
index 0000000..becddd5
--- /dev/null
+++ b/sinfoni/sinfo_prepare_stacked_frames_config.h
@@ -0,0 +1,33 @@
+/* $Id: sinfo_prepare_stacked_frames_config.h,v 1.1 2006/10/20 08:06:33 amodigli Exp $
+ *
+ * This file is part of the CPL (Common Pipeline Library)
+ * Copyright (C) 2002 European Southern Observatory
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*
+ * $Author: amodigli $
+ * $Date: 2006/10/20 08:06:33 $
+ * $Revision: 1.1 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+ /****************************************************************
+  *   Prepare_Stacked_Frames Frames Data Reduction Parameter Initialization 
+  ****************************************************************/
+#include "cpl.h"    /* defines parlist structure */
+
+void
+sinfo_prepare_stacked_frames_config_add(cpl_parameterlist *list);
diff --git a/sinfoni/sinfo_pro_save.c b/sinfoni/sinfo_pro_save.c
new file mode 100644
index 0000000..c2cfb8e
--- /dev/null
+++ b/sinfoni/sinfo_pro_save.c
@@ -0,0 +1,1145 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#include <cpl.h>
+#include "sinfo_pro_save.h"
+#include "sinfo_key_names.h"
+#include "sinfo_functions.h"
+#include "sinfo_utilities.h" 
+#include "sinfo_globals.h" 
+
+static int 
+sinfo_pfits_put_qc(
+		   cpl_propertylist       *   plist,
+		   cpl_table          *   qclog);
+
+static void
+sinfo_log_pro(char* name_o,
+              const char* pro_catg, 
+              int frm_type, 
+              cpl_frameset* ref_set,
+              cpl_frameset** out_set, 
+              cpl_propertylist** plist,
+              cpl_parameterlist* parlist, 
+              const char* recid);
+
+
+static void
+sinfo_check_name(const char* in, char** ou, int type, char** paf);
+
+static void
+sinfo_clean_header(cpl_propertylist** header);
+static void
+sinfo_clean_cube_header(cpl_propertylist** header);
+
+
+static FILE * 
+sinfo_paf_print_header(
+		       const char    *   filename,
+		       const char    *   paf_id,
+		       const char    *   paf_desc,
+		       const char    *   login_name,
+		       char    *   datetime) ;
+
+
+
+/**@{*/
+/**
+ * @defgroup sinfo_pro_save Functions to save a product
+ *
+ * TBD
+ */
+/*--------------------------------------------------------------------------*/
+/**
+   @brief    Open a new PAF file, output a default header.
+   @param    filename    Name of the file to create.
+   @param    paf_id        PAF identificator.
+   @param    paf_desc    PAF description.
+   @param    login_name  Login name
+   @param    datetime    Date
+   @return    Opened file pointer.
+
+   This function creates a new PAF file with the requested file name.
+   If another file already exists with the same name, it will be
+   overwritten (if the file access rights allow it).
+
+   A default header is produced according to the VLT DICB standard. You
+   need to provide an identificator (paf_id) of the producer of the
+   file. Typically, something like "ISAAC/zero_point".
+
+   The PAF description (paf_desc) is meant for humans. Typically,
+   something like "Zero point computation results".
+
+   This function returns an opened file pointer, ready to receive more
+   data through fprintf's. The caller is responsible for fclose()ing
+   the file.
+*/
+/*--------------------------------------------------------------------------*/
+static FILE * 
+sinfo_paf_print_header(
+		       const char    *   filename,
+		       const char    *      paf_id,
+		       const char    *    paf_desc,
+		       const char    *   login_name,
+		       char    *   datetime)
+{
+  FILE * paf ;
+    
+  if ((paf=fopen(filename, "w"))==NULL) {
+    sinfo_msg_error("cannot create PAF file [%s]", filename);
+    return NULL ;
+  }
+  fprintf(paf, "PAF.HDR.START         ;# start of header\n");
+  fprintf(paf, "PAF.TYPE              \"pipeline product\" ;\n");
+  fprintf(paf, "PAF.ID                \"%s\"\n", paf_id);
+  fprintf(paf, "PAF.NAME              \"%s\"\n", filename);
+  fprintf(paf, "PAF.DESC              \"%s\"\n", paf_desc);
+  fprintf(paf, "PAF.CRTE.NAME         \"%s\"\n", login_name) ;
+  fprintf(paf, "PAF.CRTE.DAYTIM       \"%s\"\n", datetime) ;
+  fprintf(paf, "PAF.LCHG.NAME         \"%s\"\n", login_name) ;
+  fprintf(paf, "PAF.LCHG.DAYTIM       \"%s\"\n", datetime) ;
+  fprintf(paf, "PAF.CHCK.CHECKSUM     \"\"\n");
+  fprintf(paf, "PAF.HDR.END           ;# end of header\n");
+  fprintf(paf, "\n");
+  return paf ;
+}
+/**
+   @name sinfo_update_fits_card_int
+   @brief update an integer card in the header of a FITS file
+   @param file file name
+   @param card card name
+   @param value card value
+   @return if success 0 ; else -1
+*/
+
+int 
+sinfo_update_fits_card_int(const char* file,const char* card,int value)
+{
+  cpl_propertylist *   plist =NULL;
+  if ((plist = cpl_propertylist_load(file, 0)) == NULL) {
+    sinfo_msg_error( "getting header from file %s",file);
+    cpl_propertylist_delete(plist) ;
+    return -1 ;
+  }
+
+  if (CPL_ERROR_NONE!=cpl_propertylist_set_int(plist,card,value)){
+    sinfo_msg_error( "setting header of file %s",file);
+    cpl_propertylist_delete(plist) ;
+    return -1 ;
+  }
+  cpl_propertylist_delete(plist) ;
+  return 0;
+}
+
+/**
+   @name sinfo_update_fits_card_float
+   @brief update a float card in the header of a FITS file
+   @param file file name
+   @param card card name
+   @param value card value
+   @return if success 0 ; else -1
+*/
+
+int 
+sinfo_update_fits_card_float(const char* file,const char* card,float value)
+{
+  cpl_propertylist *   plist =NULL;
+  if ((plist = cpl_propertylist_load(file, 0)) == NULL) {
+    sinfo_msg_error( "getting header from file %s",file);
+    sinfo_msg_error((char* ) cpl_error_get_message());
+    sinfo_msg_error((char* ) cpl_error_get_where());
+    cpl_propertylist_delete(plist) ;
+    return -1 ;
+  }
+
+  if (CPL_ERROR_NONE!=cpl_propertylist_set_float(plist,card,value)){
+    sinfo_msg_error( "setting header of file %s",file);
+    sinfo_msg_error((char* ) cpl_error_get_message());
+    sinfo_msg_error((char* ) cpl_error_get_where());
+    cpl_propertylist_delete(plist) ;
+    return -1 ;
+  }
+  cpl_propertylist_delete(plist) ;
+  return 0;
+}
+
+
+/**
+   @name sinfo_update_fits_card_double
+   @brief update a double card in the header of a FITS file
+   @param file file name
+   @param card card name
+   @param value card value
+   @return if success 0 ; else -1
+*/
+
+int 
+sinfo_update_fits_card_double(const char* file,const char* card,double value)
+{
+  cpl_propertylist *   plist =NULL;
+  if ((plist = cpl_propertylist_load(file, 0)) == NULL) {
+    sinfo_msg_error( "getting header from file %s",file);
+    cpl_propertylist_delete(plist) ;
+    return -1 ;
+  }
+
+  if (CPL_ERROR_NONE!=cpl_propertylist_set_double(plist,card,value)){
+    sinfo_msg_error( "gsetting header of file %s",file);
+    cpl_propertylist_delete(plist) ;
+    return -1 ;
+  }
+  cpl_propertylist_delete(plist) ;
+  return 0;
+}
+
+/**
+   @name sinfo_update_fits_card_long
+   @brief update a long card in the header of a FITS file
+   @param file file name
+   @param card card name
+   @param value card value
+   @return if success 0 ; else -1
+*/
+
+int 
+sinfo_update_fits_card_long(const char* file,const char* card,long value)
+{
+  cpl_propertylist *   plist =NULL;
+  if ((plist = cpl_propertylist_load(file, 0)) == NULL) {
+    sinfo_msg_error( "getting header from file %s",file);
+    cpl_propertylist_delete(plist) ;
+    return -1 ;
+  }
+  if (CPL_ERROR_NONE!=cpl_propertylist_set_long(plist,card,value)){
+    sinfo_msg_error( "setting header of file %s",file);
+    cpl_propertylist_delete(plist) ;
+    return -1 ;
+  }
+  cpl_propertylist_delete(plist) ;
+  return 0;
+}
+
+/**
+   @name sinfo_update_fits_card_string
+   @brief update a string card in the header of a FITS file
+   @param file file name
+   @param card card name
+   @param value card value
+   @return if success 0 ; else -1
+*/
+
+int 
+sinfo_update_ims_fits_card_string(cpl_imagelist* iml,
+                                  const char* file, 
+                                  const char* card,
+                                  const char* value)
+{
+
+  cpl_propertylist *   plist =NULL;
+  if ((plist = cpl_propertylist_load(file, 0)) == NULL) {
+    sinfo_msg_error( "getting header from reference ima frame %s",file);
+    cpl_propertylist_delete(plist) ;
+    return -1 ;
+  }
+
+
+  if (CPL_ERROR_NONE!=cpl_propertylist_set_string(plist,card,value)){
+    sinfo_msg_error( "getting header from reference ima frame %s",file);
+    cpl_propertylist_delete(plist) ;
+    return -1 ;
+  }
+
+  if (cpl_imagelist_save(iml,file,CPL_BPP_IEEE_FLOAT,
+                         plist,CPL_IO_DEFAULT)!=CPL_ERROR_NONE) {
+    sinfo_msg_error( "getting header from reference ima frame %s",file);
+    cpl_propertylist_delete(plist) ;
+  }
+  cpl_propertylist_delete(plist) ;
+  return 0;
+}
+/* Not used 
+static int sinfo_save_paf(char* name_p, 
+			  const char* rec_id, 
+			  cpl_table* qclog,
+			  cpl_propertylist*   plist,
+			  const char*      pro_catg)
+{
+
+
+
+  FILE            *   paf ;
+  const char            *   sval ;
+  char            key_name[FILE_NAME_SZ] ;
+  char            key_paf[FILE_NAME_SZ] ;
+  char            key_dpaf[FILE_NAME_SZ] ;
+  char            key_type[FILE_NAME_SZ] ;
+  char            key_value[FILE_NAME_SZ] ;
+  double dval=0;
+
+  int i =0;
+  int n=0;
+  sinfo_msg( "Writing %s" , name_p) ;
+  // Create the default PAF header
+  if ((paf = sinfo_paf_print_header(name_p,rec_id,"QC file","login-name",
+				    sinfo_get_datetime_iso8601())) == NULL) {
+    sinfo_msg_error( "cannot open file [%s] for output", name_p) ;
+    return -1 ;
+  }
+  if (sinfo_check_rec_status(0) == -1) {
+    sinfo_msg_error( "Something was wrong") ;
+    return -1 ;
+  }
+
+  // Test entries
+  sinfo_blank2dot(PAF_NAME_PIPE_ID,key_dpaf);
+  fprintf(paf,"%-21s \"%s\" ;# %s\" \n", key_dpaf,
+	  VERSION,KEY_HELP_PIPE_ID);
+
+  strcpy(key_name,KEY_NAME_PIPEFILE);        
+  strcpy(key_paf,KEY_NAME_PIPEFILE);        
+  sinfo_blank2dot(key_paf,key_dpaf);
+  if (sinfo_propertylist_has(plist, key_name)) {
+    fprintf(paf,"%-21s \"%s\" ;# %s\" \n",key_dpaf,
+	    cpl_propertylist_get_string(plist,key_name),KEY_HELP_PIPEFILE);
+  }
+
+  // Value: "TEMPORARY", "PREPROCESSED", "REDUCED" or "QCPARAM".
+  strcpy(key_name,KEY_NAME_PRO_TYPE);
+  strcpy(key_paf,PAF_NAME_PRO_TYPE);    
+  sinfo_blank2dot(key_paf,key_dpaf);
+  if (sinfo_propertylist_has(plist, key_name)) {
+    fprintf(paf,"%-21s \"%s\" ;# %s\" \n", key_dpaf,
+	    cpl_propertylist_get_string(plist,key_name),KEY_HELP_PRO_TYPE);
+  }
+
+  strcpy(key_name,KEY_NAME_PRO_DATANCOM); 
+  strcpy(key_paf,PAF_NAME_PRO_DATANCOM); 
+  sinfo_blank2dot(key_paf,key_dpaf);
+  if (sinfo_propertylist_has(plist,key_name)) {
+    fprintf(paf,"%-21s %d ;# %s\" \n",key_dpaf,
+	    cpl_propertylist_get_int(plist,key_name),KEY_HELP_PRO_DATANCOM);
+  }
+     
+  strcpy(key_name,KEY_NAME_NCORRS_NAME);
+  strcpy(key_paf,PAF_NAME_NCORRS_NAME);
+  sinfo_blank2dot(key_paf,key_dpaf);
+  if (sinfo_propertylist_has(plist, key_name)) {
+    fprintf(paf,"%-21s \"%s\" ;# %s \n", key_dpaf,
+	    cpl_propertylist_get_string(plist,key_name),KEY_HELP_NCORRS_NAME);
+  }
+
+  strcpy(key_name,KEY_NAME_DET_NDSAMPLES);
+  strcpy(key_paf,PAF_NAME_DET_NDSAMPLES);
+  sinfo_blank2dot(key_paf,key_dpaf);        
+  if (sinfo_propertylist_has(plist, key_name)) {
+    fprintf(paf,"%-21s %d ;# %s \n",key_dpaf, 
+	    cpl_propertylist_get_int(plist,key_name),KEY_HELP_DET_NDSAMPLES);
+  }
+
+  strcpy(key_name,KEY_NAME_FILT_NAME);      
+  strcpy(key_paf,PAF_NAME_FILT_NAME);      
+  sinfo_blank2dot(key_paf,key_dpaf);        
+  if (sinfo_propertylist_has(plist, key_name)) {
+    fprintf(paf,"%-21s \"%s\" ;# %s \n", key_dpaf,
+	    cpl_propertylist_get_string(plist,key_name),KEY_HELP_FILT_NAME);
+  }
+
+  strcpy(key_name,KEY_NAME_FILT_ID);        
+  strcpy(key_paf,PAF_NAME_FILT_ID);        
+  sinfo_blank2dot(key_paf,key_dpaf);        
+  if (sinfo_propertylist_has(plist, key_name)) {
+    fprintf(paf,"%-21s \"%s\" ;# %s \n",key_dpaf, 
+	    cpl_propertylist_get_string(plist,key_name),KEY_HELP_FILT_ID);
+  }
+
+  strcpy(key_name,KEY_NAME_PREOPTICS);        
+  strcpy(key_paf,PAF_NAME_PREOPTICS);        
+  sinfo_blank2dot(key_paf,key_dpaf);        
+  if (sinfo_propertylist_has(plist, key_name)) {
+    fprintf(paf,"%-21s \"%s\" ;# %s \n",key_dpaf, 
+	    cpl_propertylist_get_string(plist,key_name),KEY_HELP_PREOPTICS);
+  }
+
+  strcpy(key_name,KEY_NAME_GRAT_NAME);        
+  strcpy(key_paf,PAF_NAME_GRAT_NAME);        
+  sinfo_blank2dot(key_paf,key_dpaf);        
+  if (sinfo_propertylist_has(plist, key_name)) {
+    fprintf(paf, "%-21s \"%s\" ;# %s \n",key_dpaf, 
+	    cpl_propertylist_get_string(plist,key_name),KEY_HELP_GRAT_NAME);
+  }
+    
+  strcpy(key_name,KEY_NAME_GRAT_WLEN);        
+  strcpy(key_paf,PAF_NAME_GRAT_WLEN);        
+  sinfo_blank2dot(key_paf,key_dpaf);        
+  if (sinfo_propertylist_has(plist, key_name)) {
+    fprintf(paf, "%-21s %f ;# %s \n", key_dpaf,
+	    cpl_propertylist_get_double(plist,key_name),KEY_HELP_GRAT_WLEN);
+  }
+
+  strcpy(key_name,KEY_NAME_PRO_RECID);  
+  strcpy(key_paf,PAF_NAME_PRO_RECID);  
+  sinfo_blank2dot(key_paf,key_dpaf);        
+  if (sinfo_propertylist_has(plist, key_name)) {
+    fprintf(paf,"%-21s \"%s\" ;# %s \n", key_dpaf,
+	    cpl_propertylist_get_string(plist,key_name),KEY_HELP_PRO_RECID);
+  }
+
+
+  // snprintf(cval, MAX_NAME_SIZE-1,"CPL-%s", get_cpl_version());
+  strcpy(key_name,KEY_NAME_PRO_DRSID); 
+  strcpy(key_paf,PAF_NAME_PRO_DRSID); 
+  sinfo_blank2dot(key_paf,key_dpaf);        
+  if (sinfo_propertylist_has(plist, key_name)) {
+    fprintf(paf,"%-21s \"%s\" ;# %s \n",key_dpaf, 
+	    cpl_propertylist_get_string(plist,key_name),KEY_HELP_PRO_DRSID);
+  }
+
+  if (sinfo_propertylist_has(plist,KEY_NAME_DATE_OBS)) {
+    sval = sinfo_pfits_get_date_obs(plist);
+    strcpy(key_paf,KEY_NAME_DATE_OBS); 
+    sinfo_blank2dot(key_paf,key_dpaf);        
+    fprintf(paf, "%-21s \"%s\" ;# %s\n",key_dpaf, 
+	    sval,KEY_HELP_DATE_OBS) ;
+  }
+
+  
+  if (sinfo_propertylist_has(plist,KEY_NAME_TEL_AIRM_START)) {
+    dval = sinfo_pfits_get_airmass_start(plist);
+    strcpy(key_paf,PAF_NAME_TEL_AIRM_START); 
+    sinfo_blank2dot(key_paf,key_dpaf);        
+    fprintf(paf, "%-21s \"%f\" ;# %s \n",key_dpaf, 
+	    dval,KEY_HELP_TEL_AIRM_START) ;
+  }
+   
+  if (sinfo_propertylist_has(plist,KEY_NAME_ARCFILE)) {
+    sval = sinfo_pfits_get_arcfile(plist);
+    strcpy(key_paf,KEY_NAME_ARCFILE);
+    sinfo_blank2dot(key_paf,key_dpaf);      
+    fprintf(paf, "%-21s \"%s\" ;# %s \n", key_dpaf,sval,KEY_HELP_ARCFILE) ;
+
+  } else if (sinfo_propertylist_has(plist,KEY_NAME_PRO_REC1_RAW1_NAME)) {
+    sval = sinfo_pfits_get_rec1raw1name(plist);
+    strcpy(key_paf,KEY_NAME_ARCFILE);
+    sinfo_blank2dot(key_paf,key_dpaf);       
+    fprintf(paf, "%-21s \"%s\" ;# %s \n", key_dpaf,sval,KEY_HELP_ARCFILE) ;
+  } else {
+    sinfo_msg_error("%s is missing QC LOG will fail!",KEY_NAME_ARCFILE);
+  }
+
+  if (sinfo_propertylist_has(plist,KEY_NAME_TPL_ID)) {
+    sval = sinfo_pfits_get_templateid(plist);
+    strcpy(key_paf,PAF_NAME_TPL_ID);
+    sinfo_blank2dot(key_paf,key_dpaf);       
+    fprintf(paf, "%-21s \"%s\" ; # %s\n", key_dpaf,
+	    sval,KEY_HELP_TPL_ID) ;
+ 
+  }
+
+  if (sinfo_propertylist_has(plist,KEY_NAME_DET_DIT)) { 
+    strcpy(key_paf,PAF_NAME_DET_DIT); 
+    sinfo_blank2dot(key_paf,key_dpaf);        
+    fprintf(paf,"%-21s %f ; # %s\n", key_dpaf,
+	    sinfo_pfits_get_dit(plist),KEY_HELP_DET_DIT) ;
+  }
+
+
+  if (sinfo_propertylist_has(plist,KEY_NAME_DET_NDIT)) {
+    strcpy(key_paf,PAF_NAME_DET_NDIT); 
+    sinfo_blank2dot(key_paf,key_dpaf); 
+    fprintf(paf,"%-21s %d ; # %s\n", key_dpaf,
+	    sinfo_pfits_get_ndit(plist),KEY_HELP_DET_NDIT) ;
+  }
+
+  if (sinfo_propertylist_has(plist,KEY_NAME_NCORRS_NAME)) {
+    sval = sinfo_pfits_get_ncorrs_name(plist);
+    strcpy(key_paf,PAF_NAME_NCORRS_NAME); 
+    sinfo_blank2dot(key_paf,key_dpaf);        
+
+    fprintf(paf, "%-21s \"%s\" ; # %s\n", key_dpaf,
+	    sval, KEY_HELP_NCORRS_NAME) ;
+  }
+    
+  if (sinfo_propertylist_has(plist,KEY_NAME_DPR_TYPE)) {
+    sval = sinfo_pfits_get_dpr_type(plist);
+    strcpy(key_paf,PAF_NAME_DPR_TYPE); 
+    sinfo_blank2dot(key_paf,key_dpaf);        
+    fprintf(paf, "%-21s \"%s\" ; # %s\n", key_dpaf,
+	    sval, KEY_HELP_DPR_TYPE) ;
+  }
+
+  if (sinfo_propertylist_has(plist,KEY_NAME_DPR_TECH)) {
+    sval = sinfo_pfits_get_dpr_tech(plist);
+    strcpy(key_paf,PAF_NAME_DPR_TECH); 
+    sinfo_blank2dot(key_paf,key_dpaf);   
+    fprintf(paf, "%-21s \"%s\" ; # %s\n", key_dpaf,
+	    sval, KEY_HELP_DPR_TECH) ;
+  }
+    
+
+  if (sinfo_propertylist_has(plist,KEY_NAME_DPR_CATG)) {
+    sval = sinfo_pfits_get_dpr_catg(plist);
+    strcpy(key_paf,PAF_NAME_DPR_CATG); 
+    sinfo_blank2dot(key_paf,key_dpaf); 
+    fprintf(paf, "%-21s \"%s\" ; # %s\n", key_dpaf,
+	    sval, KEY_HELP_DPR_CATG) ;
+  }
+    
+  strcpy(key_paf,PAF_NAME_PRO_CATG); 
+  sinfo_blank2dot(key_paf,key_dpaf); 
+  fprintf(paf, "%-21s \"%s\" ; # %s\n", key_dpaf,
+	  pro_catg, KEY_HELP_PRO_CATG) ;
+
+  if (sinfo_propertylist_has(plist,KEY_NAME_INS_SETUP)) {
+    sval = sinfo_pfits_get_ins_setup(plist);
+    strcpy(key_paf,PAF_NAME_INS_SETUP); 
+    sinfo_blank2dot(key_paf,key_dpaf); 
+    fprintf(paf, "%-21s \"%s\" ; # %s\n", key_dpaf,
+	    sval, KEY_HELP_INS_SETUP) ;
+  }
+
+  n=cpl_table_get_nrow(qclog);
+  for(i=0;i<n;i++) {
+    strcpy(key_paf,cpl_table_get_string(qclog,"key_name",i));
+    sinfo_blank2dot(key_paf,key_name);
+    strcpy(key_type,cpl_table_get_string(qclog,"key_type",i));
+    strcpy(key_value,cpl_table_get_string(qclog,"key_value",i));
+    if(strcmp(key_type,"CPL_TYPE_STRING") == 0) {
+      strcat(key_name,"               \"%s\"\n");
+      fprintf(paf, key_name, key_value) ;
+    } else if(strcmp(key_type,"CPL_TYPE_BOOL") == 0) {
+      strcat(key_name,"               ");
+      strcat(key_name,"%c\n");
+      fprintf(paf, key_name, atoi(key_value)) ;
+    } else if(strcmp(key_type,"CPL_TYPE_INT") == 0) {
+      strcat(key_name,"               ");
+      strcat(key_name,"%d\n");
+      fprintf(paf, key_name, atoi(key_value)) ;
+    } else if(strcmp(key_type,"CPL_TYPE_FLOAT") == 0) {
+      strcat(key_name,"               ");
+      strcat(key_name,"%g\n");
+      fprintf(paf, key_name, (float) atof(key_value)) ;
+    } else if(strcmp(key_type,"CPL_TYPE_DOUBLE") == 0) {
+      strcat(key_name,"               ");
+      strcat(key_name,"%g\n");
+      fprintf(paf, key_name, atof(key_value)) ;
+    }
+
+  }
+  fprintf(paf, "\n");
+  fclose(paf) ;
+
+  if (sinfo_check_rec_status(1) == -1) {
+    sinfo_msg_error( "Something was wrong reading FITS keys") ;
+    return -1 ;
+  }
+  return 0;
+
+}
+
+*/
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Save the image product on disk
+   @param    ima      the input imagelist 
+   @param    ref      the reference frame set 
+   @param    set      the output frame set
+   @param    out_file the output file name
+   @param    pro_catg the frame product category
+   @param    qclog    the table to store quality control parameters
+   @param    recid    the recipe id
+   @param    parlist  the recipe parameter list
+   @return   0 if everything is ok, -1 otherwise
+*/
+/*---------------------------------------------------------------------------*/
+
+
+int sinfo_pro_save_ima(
+		       cpl_image       *   ima,
+		       cpl_frameset    *   ref,
+		       cpl_frameset    *   set,
+		       const char      *   out_file,
+		       const char      *   pro_catg,
+		       cpl_table       *   qclog,
+		       const char      *   recid,
+		       cpl_parameterlist* parlist)
+
+{
+  char      *         name_o ;
+  char      *         name_p ;
+
+  cpl_propertylist *   plist =NULL;
+  cpl_frame       *   first_frame=NULL;
+  char            *   ref_file=NULL;
+
+  /* Get the reference file  */
+  first_frame = cpl_frameset_get_first(ref) ;
+  ref_file = (char*) cpl_strdup(cpl_frame_get_filename(first_frame)) ;
+ 
+  name_o = cpl_malloc(FILE_NAME_SZ * sizeof(char));
+  name_p = cpl_malloc(FILE_NAME_SZ * sizeof(char));
+  sinfo_check_name(out_file, &name_o, CPL_FRAME_TYPE_IMAGE, &name_p);
+  sinfo_msg( "Writing ima %s pro catg %s" , name_o, pro_catg) ;
+
+  /* Get FITS header from reference file */
+  if ((cpl_error_code)((plist=cpl_propertylist_load(ref_file, 0)) == NULL)) {
+    sinfo_msg_error( "getting header from reference ima frame %s",ref_file);
+    cpl_propertylist_delete(plist) ;
+    cpl_free(ref_file);
+    return -1 ;
+  }
+
+  sinfo_clean_header(&plist);
+  if ( ( strstr(pro_catg,"MASTER_PSF") != NULL ) || 
+       ( strstr(pro_catg,"STD_STAR_SPECTRUM") != NULL ) || 
+       ( strstr(pro_catg,"STD_STAR_SPECTRA") != NULL ) ) {
+    sinfo_clean_cube_header(&plist);
+  }
+
+  /* Add DataFlow keywords and log the saved file in the input frameset */
+  sinfo_log_pro(name_o, pro_catg, CPL_FRAME_TYPE_IMAGE, 
+		ref,&set,&plist,parlist,recid);
+  if(qclog != NULL) {
+    sinfo_pfits_put_qc(plist, qclog) ;
+  }
+
+  /* Save the file */
+  if (cpl_image_save(ima, name_o, CPL_BPP_IEEE_FLOAT, 
+		     plist,CPL_IO_DEFAULT)!=CPL_ERROR_NONE) {
+    sinfo_msg_error( "Cannot save the product %s",name_o);
+    cpl_propertylist_delete(plist) ;
+    cpl_free(ref_file);
+    cpl_free(name_o);
+    cpl_free(name_p);
+    return -1 ;
+  }
+
+  /* THE PAF FILE FOR QC PARAMETERS 
+     if( qclog != NULL) {
+     sinfo_save_paf(name_p,recid,qclog,plist,pro_catg);  
+     }
+  */
+
+  cpl_propertylist_delete(plist) ;
+  cpl_msg_indent_less() ;
+  cpl_free(name_o);
+  cpl_free(name_p);
+  cpl_free(ref_file);
+
+  return 0 ;
+}
+
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Save the table products on disk
+   @param    table    the input table 
+   @param    ref      the reference frame set 
+   @param    set      the output frame set
+   @param    out_file the output file name
+   @param    pro_catg the frame product category
+   @param    qclog    the table to store quality control parameters
+   @param    recid    the recipe id
+   @param    parlist  the recipe parameter list
+   @return   0 if everything is ok, -1 otherwise
+*/
+/*---------------------------------------------------------------------------*/
+
+
+
+int sinfo_pro_save_tbl(
+		       cpl_table       *   table,
+		       cpl_frameset    *   ref,
+		       cpl_frameset    *   set,
+		       const char      *   out_file,
+		       const char      *   pro_catg,      
+		       cpl_table       *   qclog,
+		       const char      *   recid,
+		       cpl_parameterlist* parlist)
+
+{
+  char *    name_o =NULL;
+  char *    name_p =NULL;
+  cpl_propertylist *   plist=NULL ;
+  cpl_frame* first_frame=NULL;
+  char* ref_file=NULL;
+  /* Get the reference file  */
+  first_frame = cpl_frameset_get_first(ref) ;
+  ref_file = cpl_strdup(cpl_frame_get_filename(first_frame)) ;
+ 
+  name_o = cpl_malloc(FILE_NAME_SZ * sizeof(char));
+  name_p = cpl_malloc(FILE_NAME_SZ * sizeof(char));
+  sinfo_check_name(out_file, &name_o, CPL_FRAME_TYPE_TABLE, &name_p);
+  sinfo_msg( "Writing tbl %s pro catg %s" , name_o, pro_catg) ;
+
+  /* Get FITS header from reference file */
+  if ((cpl_error_code)((plist = cpl_propertylist_load(ref_file,0)) == NULL)) 
+    {
+      sinfo_msg_error( "getting header from tbl frame %s",ref_file);
+      cpl_propertylist_delete(plist) ;
+      cpl_free(ref_file);
+      cpl_free(name_o);
+      cpl_free(name_p);
+      return -1 ;
+    }
+  sinfo_clean_header(&plist);
+
+  /* Add DataFlow keywords and log the saved file in the input frameset */
+  sinfo_log_pro(name_o, pro_catg, CPL_FRAME_TYPE_TABLE, 
+		ref,&set,&plist,parlist,recid);
+  if(qclog != NULL) {
+    sinfo_pfits_put_qc(plist, qclog) ;
+  }
+  /* Save the file */
+  if (cpl_table_save(table, plist, NULL, name_o, CPL_IO_DEFAULT) 
+      != CPL_ERROR_NONE) {
+    sinfo_msg_error( "Cannot save the product: %s", name_o);
+    cpl_propertylist_delete(plist) ;
+    cpl_free(ref_file);
+    cpl_free(name_o);
+    cpl_free(name_p);
+    return -1 ;
+  }
+
+ 
+  /* THE PAF FILE FOR QC PARAMETERS 
+     if (qclog != NULL) {
+     sinfo_save_paf(name_p,recid,qclog,plist,pro_catg);
+     }
+  */
+  cpl_propertylist_delete(plist) ;
+  cpl_msg_indent_less() ;
+  cpl_free(name_o);
+  cpl_free(name_p);
+  cpl_free(ref_file);
+  return 0 ;
+}
+
+
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Save the imagelist product on disk
+   @param    ims      the input imagelist 
+   @param    ref      the reference frame set 
+   @param    set      the output frame set
+   @param    out_file the output file name
+   @param    pro_catg the frame product category
+   @param    qclog    the table to store quality control parameters
+   @param    recid    the recipe id
+   @param    parlist  the recipe parameter list
+   @return   0 if everything is ok, -1 otherwise
+*/
+/*---------------------------------------------------------------------------*/
+
+
+
+int sinfo_pro_save_ims(
+		       cpl_imagelist   *   ims,
+		       cpl_frameset    *   ref,
+		       cpl_frameset    *   set,
+		       const char      *   out_file,
+		       const char      *   pro_catg,      
+		       cpl_table       *   qclog,
+		       const char      *   recid,
+		       cpl_parameterlist* parlist)
+
+{
+  char *               name_o=NULL;
+  char *               name_p=NULL;
+
+  cpl_propertylist * plist=NULL ;
+  cpl_frame* first_frame=NULL;
+  char* ref_file=NULL;
+    
+  /* Get the reference file  */
+  first_frame = cpl_frameset_get_first(ref) ;
+  ref_file = cpl_strdup(cpl_frame_get_filename(first_frame)) ;
+
+  name_o = cpl_malloc(FILE_NAME_SZ * sizeof(char));
+  name_p = cpl_malloc(FILE_NAME_SZ * sizeof(char));
+  sinfo_check_name(out_file, &name_o, CPL_FRAME_TYPE_IMAGE, &name_p);
+  sinfo_msg( "Writing ims %s pro catg %s" , name_o, pro_catg) ;
+  /* Get FITS header from reference file */
+  if ((cpl_error_code)((plist = cpl_propertylist_load(ref_file, 0)) == NULL))
+    {
+      sinfo_msg_error( "getting header from ims frame %s",ref_file);
+      cpl_propertylist_delete(plist) ;
+      cpl_free(ref_file);
+      cpl_free(name_o);
+      cpl_free(name_p);
+      return -1 ;
+    }
+  sinfo_clean_header(&plist);
+  if ( ( strstr(pro_catg,"STD") != NULL ) || 
+       ( strstr(pro_catg,"PSF") != NULL ) || 
+       ( strstr(pro_catg,"OBJ") != NULL ) ) {
+    sinfo_clean_cube_header(&plist);
+  }
+
+  /* Add DataFlow keywords and log the saved file in the input frameset */
+  sinfo_log_pro(name_o, pro_catg, CPL_FRAME_TYPE_IMAGE, 
+		ref,&set,&plist,parlist,recid);
+   
+  if(qclog != NULL) {
+    sinfo_pfits_put_qc(plist, qclog) ;
+  }
+   
+
+  /* Save the file */
+  if (cpl_imagelist_save(ims, name_o, CPL_BPP_IEEE_FLOAT, 
+			 plist,CPL_IO_DEFAULT)!=CPL_ERROR_NONE) {
+    sinfo_msg_error( "Cannot save the product %s",name_o);
+    cpl_propertylist_delete(plist) ;
+    cpl_free(ref_file);
+    cpl_free(name_o);
+    cpl_free(name_p);
+    return -1 ;
+  }
+
+  /* THE PAF FILE FOR QC PARAMETERS 
+     if (qclog != NULL) {
+     sinfo_save_paf(name_p,recid,qclog,plist,pro_catg);
+     }
+  */
+  cpl_propertylist_delete(plist) ;
+  cpl_msg_indent_less() ;
+  cpl_free(name_o);
+  cpl_free(name_p);
+  cpl_free(ref_file);
+  return 0 ;
+}
+
+
+
+static void
+sinfo_log_pro(char* name_o, 
+              const char* pro_catg, 
+              int frm_type, 
+              cpl_frameset* ref_set,
+              cpl_frameset** out_set,
+              cpl_propertylist** plist,
+              cpl_parameterlist* parlist, 
+              const char* recid)
+{
+  cpl_frame* product_frame = NULL ;
+  char * pipe_id=NULL;
+  cpl_errorstate initial_errorstate = cpl_errorstate_get();
+
+  pipe_id = cpl_calloc(FILE_NAME_SZ,sizeof(char));
+  snprintf(pipe_id,MAX_NAME_SIZE-1,"%s%s","sinfo/",PACKAGE_VERSION);
+  product_frame = cpl_frame_new() ;
+  cpl_frame_set_filename(product_frame, name_o) ;
+  cpl_frame_set_tag(product_frame, pro_catg) ;
+  cpl_frame_set_type(product_frame, frm_type);
+  cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT);
+  cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL);
+
+#if defined CPL_VERSION_CODE && CPL_VERSION_CODE >= CPL_VERSION(4, 8, 0) 
+  if(cpl_dfs_setup_product_header(*plist,product_frame,ref_set,parlist,recid,
+				  pipe_id,KEY_VALUE_HPRO_DID,NULL) != CPL_ERROR_NONE) {
+    sinfo_msg_warning("Problem in the product DFS-compliance");
+    sinfo_msg_warning((char* ) cpl_error_get_message());
+    cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
+    cpl_error_reset();
+  }
+#else
+  if(cpl_dfs_setup_product_header(*plist,product_frame,ref_set,parlist,recid,
+				  pipe_id,KEY_VALUE_HPRO_DID) != CPL_ERROR_NONE) {
+    sinfo_msg_warning("Problem in the product DFS-compliance");
+    sinfo_msg_warning((char* ) cpl_error_get_message());
+    cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
+    cpl_error_reset();
+  }
+#endif
+  cpl_frameset_insert(*out_set, product_frame);
+  cpl_free(pipe_id);
+
+}
+
+static void
+sinfo_check_name(const char* in, char** ou, int type, char** paf) {
+
+  char* tmp=NULL;
+  char  name_b[512] ;
+  if (strstr(in, "." ) != NULL ) {
+    tmp = sinfo_new_get_rootname(in);
+    strcpy(name_b,tmp);
+  } else {
+    snprintf(name_b, MAX_NAME_SIZE-1,in) ;
+  }
+  strcpy(*ou,name_b);
+  if (type == CPL_FRAME_TYPE_TABLE) {
+    strcat(*ou,".fits");
+  } else {
+    strcat(*ou,".fits");
+  }
+  strcpy(*paf,name_b);
+  strcat(*paf,".paf");
+
+}
+
+
+static void
+sinfo_clean_header(cpl_propertylist** header)
+{
+  cpl_propertylist_erase_regexp(*header, "^ESO PRO .*",0);
+
+}
+
+
+static void
+sinfo_clean_cube_header(cpl_propertylist** header)
+{
+  cpl_propertylist_erase_regexp(*header, "^CRVAL*",0);
+  cpl_propertylist_erase_regexp(*header, "^CRPIX*",0);
+  cpl_propertylist_erase_regexp(*header, "^CTYPE*",0);
+  cpl_propertylist_erase_regexp(*header, "^CUNIT*",0);
+  cpl_propertylist_erase_regexp(*header, "^CD1_1",0);
+  cpl_propertylist_erase_regexp(*header, "^CD1_2",0);
+  cpl_propertylist_erase_regexp(*header, "^CD2_1",0);
+  cpl_propertylist_erase_regexp(*header, "^CD2_2",0);
+
+}
+
+
+
+
+
+
+static int 
+sinfo_pfits_put_qc(
+		   cpl_propertylist       *   plist,
+		   cpl_table          *   qclog)
+{
+  char            key_name[FILE_NAME_SZ];
+  char            key_value[FILE_NAME_SZ];
+  char            key_type[FILE_NAME_SZ];
+  char            key_help[FILE_NAME_SZ] ;
+
+  int             i =0;
+  int n =0;
+  /* Test entries */
+  if (plist == NULL) {
+    sinfo_msg_error("plist=NULL, something strange");
+    return -1 ;
+  }
+  /* Parameter Name:    PIPEFILE */
+
+  n=cpl_table_get_nrow(qclog);
+  for(i=0;i<n;i++) {
+    strcpy(key_name,"ESO ");
+    strcat(key_name,cpl_table_get_string(qclog,"key_name",i));
+    strcpy(key_type,cpl_table_get_string(qclog,"key_type",i));
+    strcpy(key_value,cpl_table_get_string(qclog,"key_value",i));
+    strcpy(key_help,cpl_table_get_string(qclog,"key_help",i));
+
+    /* sinfo_msg("name=%s type=%s value=%s\n",key_name,key_type,key_value); */
+    if(!sinfo_propertylist_has(plist,key_name)) {
+      if(strcmp(key_type,"CPL_TYPE_STRING") == 0) {
+	cpl_propertylist_append_string(plist, key_name,key_value) ;
+	cpl_propertylist_set_comment(plist, key_name,key_help) ;
+      } else if(strcmp(key_type,"CPL_TYPE_BOOL") == 0) {
+	cpl_propertylist_append_bool(plist, key_name,atoi(key_value)) ;
+	cpl_propertylist_set_comment(plist, key_name,key_help) ;
+      } else if(strcmp(key_type,"CPL_TYPE_INT") == 0) {
+	cpl_propertylist_append_int(plist,key_name,atoi(key_value)) ;
+	cpl_propertylist_set_comment(plist, key_name,key_help) ;
+      } else if(strcmp(key_type,"CPL_TYPE_FLOAT") == 0) {
+        cpl_propertylist_append_float(plist, key_name,(float)atof(key_value)) ;
+        cpl_propertylist_set_comment(plist, key_name,key_help) ;
+      } else if(strcmp(key_type,"CPL_TYPE_DOUBLE") == 0) {
+        cpl_propertylist_append_double(plist, key_name,atof(key_value)) ;
+        cpl_propertylist_set_comment(plist, key_name,key_help) ;
+      }
+    }
+
+  }
+
+  return 0 ;
+}
+
+
+
+
+
+
+
+cpl_table *
+sinfo_qclog_init(void)
+{
+
+  cpl_table *table;
+
+  table = cpl_table_new(0);
+  cpl_table_new_column(table,"key_name", CPL_TYPE_STRING);
+  cpl_table_new_column(table,"key_type", CPL_TYPE_STRING);
+  cpl_table_new_column(table,"key_value", CPL_TYPE_STRING);
+  cpl_table_new_column(table,"key_help", CPL_TYPE_STRING);
+
+  return table;
+}
+
+
+
+
+
+int
+sinfo_qclog_add_int(cpl_table* table,
+		    const char*  key_name,  
+		    const int    value,
+		    const char*  key_help,
+		    const char*  format)
+{
+  int sz = cpl_table_get_nrow(table);
+  int raw = sz;
+  char key_value[FILE_NAME_SZ];
+  char key_type[FILE_NAME_SZ];
+
+  snprintf(key_value,MAX_NAME_SIZE-1,format,value);
+  strcpy(key_type,"CPL_TYPE_INT"); 
+ 
+  cpl_table_set_size(table,sz+1);
+
+  cpl_table_set_string(table,"key_name" ,raw,key_name);
+  cpl_table_set_string(table,"key_type" ,raw,key_type);
+  cpl_table_set_string(table,"key_value",raw,key_value);
+  cpl_table_set_string(table,"key_help" ,raw,key_help);
+
+  return 0;
+
+}
+
+
+
+int
+sinfo_qclog_add_bool(cpl_table* table,
+		     const char*  key_name,  
+		     const char   value,
+		     const char*  key_help,
+		     const char*  format)
+{
+  int sz = cpl_table_get_nrow(table);
+  int raw = sz;
+  char key_value[FILE_NAME_SZ];
+  char key_type[FILE_NAME_SZ];
+
+  snprintf(key_value,MAX_NAME_SIZE-1,format,value);
+  strcpy(key_type,"CPL_TYPE_BOOL"); 
+
+  cpl_table_set_size(table,sz+1);
+
+  cpl_table_set_string(table,"key_name" ,raw,key_name);
+  cpl_table_set_string(table,"key_type" ,raw,key_type);
+  cpl_table_set_string(table,"key_value",raw,key_value);
+  cpl_table_set_string(table,"key_help" ,raw,key_help);
+
+  return 0;
+
+}
+
+
+
+int
+sinfo_qclog_add_float(cpl_table* table,
+		      const char*  key_name,  
+		      const float  value,
+		      const char*  key_help,
+		      const char*  format)
+{
+  int sz = cpl_table_get_nrow(table);
+  int raw = sz;
+  char key_value[FILE_NAME_SZ];
+  char key_type[FILE_NAME_SZ];
+
+  snprintf(key_value,MAX_NAME_SIZE-1,format,value);
+  strcpy(key_type,"CPL_TYPE_FLOAT"); 
+ 
+  cpl_table_set_size(table,sz+1);
+
+  cpl_table_set_string(table,"key_name" ,raw,key_name);
+  cpl_table_set_string(table,"key_type" ,raw,key_type);
+  cpl_table_set_string(table,"key_value",raw,key_value);
+  cpl_table_set_string(table,"key_help" ,raw,key_help);
+
+  return 0;
+
+}
+
+
+
+int
+sinfo_qclog_add_double(cpl_table* table,
+		       const char*  key_name,  
+		       const double value,
+		       const char*  key_help,
+		       const char*  format)
+{
+  int sz = cpl_table_get_nrow(table);
+  int raw = sz;
+  char key_value[FILE_NAME_SZ];
+  char key_type[FILE_NAME_SZ];
+
+  snprintf(key_value,MAX_NAME_SIZE-1,format,value);
+  strcpy(key_type,"CPL_TYPE_DOUBLE"); 
+ 
+  cpl_table_set_size(table,sz+1);
+
+  cpl_table_set_string(table,"key_name" ,raw,key_name);
+  cpl_table_set_string(table,"key_type" ,raw,key_type);
+  cpl_table_set_string(table,"key_value",raw,key_value);
+  cpl_table_set_string(table,"key_help" ,raw,key_help);
+
+  return 0;
+
+}
+
+int
+sinfo_qclog_add_string(cpl_table* table,
+		       const char*  key_name,  
+		       const char*  value,
+		       const char*  key_help,
+		       const char*  format)
+{
+  int sz = cpl_table_get_nrow(table);
+  int raw = sz;
+  char key_value[FILE_NAME_SZ];
+  char key_type[FILE_NAME_SZ];
+
+  snprintf(key_value,MAX_NAME_SIZE-1,format,value);
+  strcpy(key_type,"CPL_TYPE_STRING"); 
+ 
+  cpl_table_set_size(table,sz+1);
+
+  cpl_table_set_string(table,"key_name" ,raw,key_name);
+  cpl_table_set_string(table,"key_type" ,raw,key_type);
+  cpl_table_set_string(table,"key_value",raw,key_value);
+  cpl_table_set_string(table,"key_help" ,raw,key_help);
+
+  return 0;
+
+}
+
+
+
+
+/**@}*/
diff --git a/sinfoni/sinfo_pro_save.h b/sinfoni/sinfo_pro_save.h
new file mode 100644
index 0000000..bb0627d
--- /dev/null
+++ b/sinfoni/sinfo_pro_save.h
@@ -0,0 +1,327 @@
+#ifndef SINFO_PRO_SAVE_H
+#define SINFO_PRO_SAVE_H
+
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <cpl.h>
+#include "sinfo_pfits.h"
+#include "sinfo_msg.h"
+/**
+ at name sinfo_update_fits_card_int
+ at memo update FITS card value
+ at param file file name
+ at param card FITS card to update
+ at param value new int value
+*/
+int 
+sinfo_update_fits_card_int(const char* file,const char* card,int value);
+
+/**
+ at name sinfo_update_fits_card_float
+ at memo update FITS card value
+ at param file file name
+ at param card FITS card to update
+ at param value new float value
+*/
+int 
+sinfo_update_fits_card_float(const char* file,const char* card,float value);
+
+/**
+ at name sinfo_update_fits_card_double
+ at memo update FITS card value
+ at param file file name
+ at param card FITS card to update
+ at param value new double value
+*/
+int 
+sinfo_update_fits_card_double(const char* file,const char* card,double value);
+
+
+/**
+ at name sinfo_update_fits_card_long
+ at memo update FITS card value
+ at param file file name
+ at param card FITS card to update
+ at param value new long value
+*/
+int 
+sinfo_update_fits_card_long(const char* file,const char* card,long value);
+
+/**
+ at name sinfo_update_fits_card_string
+ at memo update FITS card value
+ at param file file name
+ at param card FITS card to update
+ at param value new string value
+*/
+int sinfo_update_ims_fits_card_string(cpl_imagelist* iml, 
+                                      const char* file,
+                                      const char* card,
+                                      const char* value);
+
+
+/**
+ at name sinfo_pro_save_tbl
+ at memo save table of FITS file
+ at param tbl input table
+ at param ref reference frame set
+ at param sof output frame set
+ at param name output filename
+ at param proid output PRO.CATG
+ at param qclog qc-log table
+ at param recid recipe ID
+ at param parlist input parameter list
+*/
+
+int
+sinfo_pro_save_tbl(
+    cpl_table* tbl,
+        cpl_frameset* ref,
+        cpl_frameset* sof,
+        const char* name, 
+        const char* proid, 
+        cpl_table* qclog,
+        const char* recid,
+        cpl_parameterlist* parlist);
+
+
+/**
+ at name sinfo_pro_save_ima
+ at memo save image of FITS file
+ at param ima image to ge saved
+ at param ref reference frame set
+ at param sof output frame set
+ at param name output filename
+ at param proid output PRO.CATG
+ at param qclog qc-log table
+ at param recid recipe ID
+ at param parlist input parameter list
+*/
+
+
+int
+sinfo_pro_save_ima(
+        cpl_image* ima,
+        cpl_frameset* ref,
+        cpl_frameset* sof,
+        const char* name, 
+        const char* proid, 
+        cpl_table* qclog,
+        const char* recid,
+        cpl_parameterlist* parlist);
+
+/**
+ at name sinfo_pro_save_ims
+ at memo save imagelist of FITS file
+ at param ims imagelist to be saved
+ at param ref reference frame set
+ at param sof output frame set
+ at param name output filename
+ at param proid output PRO.CATG
+ at param qclog qc-log table
+ at param recid recipe ID
+ at param parlist input parameter list
+*/
+
+int
+sinfo_pro_save_ims(
+        cpl_imagelist* ims,
+        cpl_frameset* ref,
+        cpl_frameset* sof,
+        const char* name, 
+        const char* proid, 
+        cpl_table* qclog,
+        const char* recid,
+        cpl_parameterlist* parlist);
+
+
+
+
+
+
+
+/**
+ at name sinfo_save_pro_tbl
+ at memo save table of FITS file
+ at param tbl input table
+ at param ref reference frame set
+ at param sof output frame set
+ at param name output filename
+ at param proid output PRO.CATG
+ at param qclog qc-log table
+ at param recid recipe ID
+ at param parlist input parameter list
+*/
+
+int
+sinfo_save_pro_tbl(
+    cpl_table* tbl,
+        cpl_frameset* ref,
+        cpl_frameset* sof,
+        const char* name, 
+        const char* proid, 
+        cpl_propertylist* qclog,
+        const char* recid,
+        cpl_parameterlist* parlist);
+
+
+/**
+ at name sinfo_save_pro_ima
+ at memo save image of FITS file
+ at param ima image to ge saved
+ at param ref reference frame set
+ at param sof output frame set
+ at param name output filename
+ at param proid output PRO.CATG
+ at param qclog qc-log table
+ at param recid recipe ID
+ at param parlist input parameter list
+*/
+
+
+int
+sinfo_save_pro_ima(
+        cpl_image* ima,
+        cpl_frameset* ref,
+        cpl_frameset* sof,
+        const char* name, 
+        const char* proid, 
+        cpl_propertylist* qclog,
+        const char* recid,
+        cpl_parameterlist* parlist);
+
+/**
+ at name sinfo_save_pro_ims
+ at memo save imagelist of FITS file
+ at param ims imagelist to be saved
+ at param ref reference frame set
+ at param sof output frame set
+ at param name output filename
+ at param proid output PRO.CATG
+ at param qclog qc-log table
+ at param recid recipe ID
+ at param parlist input parameter list
+*/
+
+int
+sinfo_save_pro_ims(
+        cpl_imagelist* ims,
+        cpl_frameset* ref,
+        cpl_frameset* sof,
+        const char* name, 
+        const char* proid, 
+        cpl_propertylist* qclog,
+        const char* recid,
+        cpl_parameterlist* parlist);
+
+
+
+
+
+cpl_table* sinfo_qclog_init(void);
+
+int
+sinfo_qclog_add_int(cpl_table* table,
+                 const char* name,  
+                 const int   value,
+                 const char* help,
+         const char* format);
+
+
+int
+sinfo_qclog_add_bool(cpl_table* table,
+                 const char* name,  
+                 const char  value,
+                 const char* help,
+         const char* format);
+
+
+int
+sinfo_qclog_add_float(cpl_table* table,
+                 const char* name,  
+                 const float   value,
+                 const char* help,
+         const char* format);
+
+
+int
+sinfo_qclog_add_double(cpl_table* table,
+                 const char* name,  
+                 const double   value,
+                 const char* help,
+         const char* format);
+
+
+int
+sinfo_qclog_add_string(cpl_table* table,
+                 const char* name,  
+                 const char*   value,
+                 const char* help,
+         const char* format);
+
+
+
+cpl_propertylist* sinfo_qc_init(void);
+
+int
+sinfo_qc_add_int(cpl_propertylist* table,
+                 const char* name,  
+                 const int   value,
+                 const char* help,
+         const char* format);
+
+
+int
+sinfo_qc_add_bool(cpl_propertylist* table,
+                 const char* name,  
+                 const char  value,
+                 const char* help,
+         const char* format);
+
+
+int
+sinfo_qc_add_float(cpl_propertylist* table,
+                 const char* name,  
+                 const float   value,
+                 const char* help,
+         const char* format);
+
+
+int
+sinfo_qc_add_double(cpl_propertylist* table,
+                 const char* name,  
+                 const double   value,
+                 const char* help,
+         const char* format);
+
+
+int
+sinfo_qc_add_string(cpl_propertylist* table,
+                 const char* name,  
+                 const char*   value,
+                 const char* help,
+         const char* format);
+
+
+
+#endif /* SINFO_PRO_SAVE */
diff --git a/sinfoni/sinfo_pro_types.h b/sinfoni/sinfo_pro_types.h
new file mode 100644
index 0000000..4d3203d
--- /dev/null
+++ b/sinfoni/sinfo_pro_types.h
@@ -0,0 +1,191 @@
+/* $Id: sinfo_pro_types.h,v 1.10 2010/02/12 17:57:38 amodigli Exp $
+ *
+ * This file is part of the SINFONI Pipeline
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This proram is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later verrtd sion.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2010/02/12 17:57:38 $
+ * $Revision: 1.10 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifndef SINFO_PRO_TYPES_H
+#define SINFO_PRO_TYPES_H
+
+CPL_BEGIN_DECLS
+
+#define PRO_LIN_DET_INFO                   "LIN_DET_INFO"
+#define PRO_GAIN_INFO                      "GAIN_INFO"
+#define PRO_AO_INFO                        "AO_INFO"
+#define PRO_AO_PERFORMANCE                 "AO_PERFORMANCE"
+#define PRO_ENC_ENERGY                     "ENC_ENERGY"
+#define PRO_OBS_SKY                        "OBS_SKY"
+#define PRO_SKY_MED                        "SKY_MED"
+#define PRO_SKY_DUMMY                      "SKY_DUMMY"
+#define PRO_SKY_STACKED_DUMMY              "SKY_STACKED_DUMMY"
+#define PRO_DEFAULT                        "DEFAULT"
+#define PRO_INT_COL_TILT_COR               "INT_COL_TILT_COR"
+#define PRO_STD_STACKED                    "STD_STACKED"
+#define PRO_SKY_STD_STACKED                "SKY_STD_STACKED"
+#define PRO_SKY_OH_STACKED                 "SKY_OH_STACKED"
+#define PRO_SKY_PSF_CALIBRATOR_STACKED     "SKY_PSF_CALIBRATOR_STACKED"
+#define PRO_STD_STAR_STACKED               "STD_STAR_STACKED"
+#define PRO_STD_STAR_DITHER_STACKED        "STD_STAR_DITHER_STACKED"
+#define PRO_SKY_STACKED                    "SKY_STACKED"
+#define PRO_NODDING_STACKED                "_NODDING_STACKED"
+#define PRO_ILLUMCORR                      "ILLUMCORR"
+
+#define SINFO_UTL_STDSTARS_RES             "STDSTARS_CATS"
+#define SINFO_UTL_SEDS_RES                 "SEDS"
+#define SINFO_CALIB_STDSTARS               "STDSTARS_CATS"
+#define SINFO_CALIB_SED                    "SEDS"
+
+#define PRO_STACKED                        "_STACKED"
+
+#define PRO_STACK_SKY_DIST                 "SKY_STACKED_DIST"
+#define PRO_STACK_MFLAT_DIST               "MFLAT_STACKED_DIST"
+#define PRO_STACK_MFLAT_DITHER_DIST        "MFLAT_DITHER_STACKED_DIST"
+
+#define PRO_MFLAT_CUBE                     "MFLAT_CUBE"
+#define PRO_MFLAT_AVG                      "MFLAT_AVG"
+#define PRO_MFLAT_MED                      "MFLAT_MED"
+
+
+#define PRO_ILL_COR                        "ILLUMINATION_CORRECTION"
+#define PRO_BP_MAP                         "BP_MAP"
+#define PRO_BP_MAP_HP                      "BP_MAP_HP"
+#define PRO_BP_MAP_NL                      "BP_MAP_NL"
+#define PRO_BP_MAP_NO                      "BP_MAP_NO"
+#define PRO_BP_MAP_DI                      "BP_MAP_DI"
+#define PRO_BP_MAP_SKY                     "BP_MAP_SKY"
+#define PRO_MASTER_BP_MAP                  "MASTER_BP_MAP"
+#define PRO_BP_MAP                         "BP_MAP"
+#define PRO_MASTER_DARK                    "MASTER_DARK"
+#define PRO_SLOPE                          "SLOPE"
+#define PRO_DISTORTION                     "DISTORTION"
+#define PRO_SLITLETS_DISTANCE              "SLITLETS_DISTANCE"
+#define PRO_MASTER_SLIT                    "MASTER_SLIT"
+#define PRO_MASTER_FLAT_LAMP               "MASTER_FLAT_LAMP"
+#define PRO_MASTER_FLAT_LAMP1              "MASTER_FLAT_LAMP1"
+#define PRO_MASTER_FLAT_LAMP2              "MASTER_FLAT_LAMP2"
+#define PRO_SLIT_POS                       "SLIT_POS"
+#define PRO_REF_ATM_REF_CORR               "ATM_REF_CORR"
+#define PRO_SLITLETS_POS_PREDIST           "SLITLETS_POS_PREDIST"
+#define PRO_SLIT_POS_GUESS                 "SLIT_POS_GUESS"
+#define PRO_FIBRE_EW_STACKED               "FIBRE_EW_STACKED"
+#define PRO_FIBRE_NS_STACKED_ON            "FIBRE_NS_STACKED_ON"
+#define PRO_FIBRE_NS_STACKED_OFF           "FIBRE_NS_STACKED_OFF"
+#define PRO_FIBRE_NS_STACKED               "FIBRE_NS_STACKED"
+#define PRO_FIBRE_NS_STACKED_DIST          "FIBRE_NS_STACKED_DIST"
+#define PRO_FIBRE_LAMP_STACKED             "FIBRE_LAMP_STACKED"
+#define PRO_SLIT_LAMP_STACKED              "SLIT_LAMP_STACKED"
+#define PRO_FLUX_LAMP_STACKED              "FLUX_LAMP_STACKED"
+#define PRO_WAVE_LAMP_STACKED              "WAVE_LAMP_STACKED"
+#define PRO_WAVE_SLITPOS_STACKED           "WAVE_LAMP_SLITPOS_STACKED"
+#define PRO_WAVE_LAMP_DITHER_STACKED       "WAVE_LAMP_DITHER_STACKED"
+#define PRO_WAVE_NS_STACKED                "WAVE_NS_STACKED"
+#define PRO_WAVE_NS_DITHER_STACKED         "WAVE_NS_DITHER_STACKED"
+#define PRO_WAVE_PAR_LIST                  "WAVE_FIT_PARAMS"
+#define PRO_WAVE_COEF_SLIT                 "WAVE_COEF_SLIT"
+#define PRO_PSF_CALIBRATOR_STACKED         "PSF_CALIBRATOR_STACKED"
+#define PRO_FOCUS_STACKED                  "FOCUS_STACKED"
+#define PRO_OBJECT_NODDING_STACKED         "OBJECT_NODDING_STACKED"
+#define PRO_OBJECT_SKYSPIDER_STACKED       "OBJECT_SKYSPIDER_STACKED"
+
+
+#define PRO_RESAMPLED_WAVE                 "RESAMPLED_WAVE"
+#define PRO_RESAMPLED_OBJ                  "RESAMPLED_OBJ"
+#define PRO_RESAMPLED_SKY                  "RESAMPLED_SKY"
+#define PRO_RESAMPLED_FLAT_LAMP            "RESAMPLED_FLAT_LAMP"
+
+#define PRO_OBS_CUBE_SKY                   "OBS_CUBE_SKY"
+#define PRO_STD_CUBE_SKY                   "STD_CUBE_SKY"
+#define PRO_PSF_CUBE_SKY                   "PSF_CUBE_SKY"
+#define PRO_PUPIL_CUBE_SKY                 "PUPIL_CUBE_SKY"
+
+#define PRO_PUPIL_CUBE                     "PUPIL_LAMP_CUBE"
+
+
+#define PRO_OBS_MED_SKY                    "OBS_MED_SKY"
+#define PRO_STD_MED_SKY                    "STD_MED_SKY"
+#define PRO_PSF_MED_SKY                    "PSF_MED_SKY"
+#define PRO_PUPIL_MED_SKY                  "PUPIL_MED_SKY"
+
+#define PRO_PUPIL_LAMP_STACKED             "PUPIL_LAMP_STACKED"
+#define PRO_SKY_NODDING_STACKED            "SKY_NODDING_STACKED"
+#define PRO_STD_NODDING_STACKED            "STD_NODDING_STACKED"
+#define PRO_MASTER_LAMP_SPEC               "MASTER_LAMP_SPEC"
+#define PRO_MASTER_TWIFLAT                 "MASTER_TWIFLAT"
+#define PRO_COEFF_LIST                     "COEFF_LIST"
+#define PRO_INDEX_LIST                     "INDEX_LIST"
+#define PRO_HALO_SPECT                     "HALO_SPECT"
+#define PRO_FIRST_COL                      "FIRST_COL"
+#define PRO_MASK_CUBE                      "MASK_CUBE"  /* not used*/
+#define PRO_PSF                            "MASTER_PSF"
+
+#define TMP_FOCUS                          "FOCUS_STACKED"
+#define TMP_FOCUS_ON                       "FOCUS_ON_STACKED"
+#define TMP_FOCUS_OFF                      "FOCUS_OFF_STACKED"
+
+#define PRO_FOCUS                          "MASTER_FOCUS"
+#define PRO_FOCUS_GAUSS                    "FOCUS_GAUSS"
+#define PRO_WAVE_MAP                       "WAVE_MAP"
+#define PRO_STD_STAR_SPECTRA               "STD_STAR_SPECTRA"
+#define PRO_STD_STAR_SPECTRUM              "STD_STAR_SPECTRUM"
+
+#define PRO_CUBE                           "CUBE"
+#define PRO_IMA                            "IMA"
+#define PRO_SPECTRUM                       "SPECTRUM"
+#define PRO_COADD_SKY                      "COADD_SKY"
+#define PRO_COADD_PSF                      "COADD_PSF"
+#define PRO_COADD_STD                      "COADD_STD"
+#define PRO_COADD_OBJ                      "COADD_OBJ"
+#define PRO_COADD_PUPIL                    "COADD_PUPIL"
+
+#define PRO_OBS_PSF                        "OBS_PSF"
+#define PRO_OBS_STD                        "OBS_STD"
+#define PRO_OBS_OBJ                        "OBS_OBJ"
+#define PRO_OBS_PUPIL                      "OBS_PUPIL"
+#define PRO_SPECTRA_QC                     "SPECTRA_QC"
+
+#define PRO_MED_COADD_PSF                  "MED_COADD_PSF"
+#define PRO_MED_COADD_STD                  "MED_COADD_STD"
+#define PRO_MED_COADD_OBJ                  "MED_COADD_OBJ"
+#define PRO_MED_COADD_PUPIL                "MED_COADD_PUPIL"
+
+
+#define PRO_MED_OBS_PSF                    "MED_OBS_PSF"
+#define PRO_MED_OBS_STD                    "MED_OBS_STD"
+#define PRO_MED_OBS_OBJ                    "MED_OBS_OBJ"
+#define PRO_MED_OBS_PUPIL                  "MED_OBS_PUPIL"
+
+
+#define PRO_CUBE_COLL                      "CUBE_COLL"
+#define PRO_SLOPEX                         "CUBE_COLL_SLOPEX"
+#define PRO_SLOPEY                         "CUBE_COLL_SLOPEY"
+#define PRO_MASK_CUBE                      "MASK_CUBE"
+#define PRO_MASK_COADD_PSF                 "MASK_COADD_PSF"
+#define PRO_MASK_COADD_STD                 "MASK_COADD_STD"
+#define PRO_MASK_COADD_OBJ                 "MASK_COADD_OBJ"
+#define PRO_MASK_COADD_PUPIL               "MASK_COADD_PUPIL"
+#define PRO_OBJ_CUBE                       "OBJ_CUBE"
+#define PRO_BP_COEFF                       "BP_COEFF"
+#define PRO_EFFICIENCY                     "EFFICIENCY"
+CPL_END_DECLS
+#endif
diff --git a/sinfoni/sinfo_product_config.c b/sinfoni/sinfo_product_config.c
new file mode 100644
index 0000000..66bcd9e
--- /dev/null
+++ b/sinfoni/sinfo_product_config.c
@@ -0,0 +1,84 @@
+/* $Id: sinfo_product_config.c,v 1.7 2012/03/03 09:50:08 amodigli Exp $
+ *
+ * This file is part of the CPL (Common Pipeline Library)
+ * Copyright (C) 2002 European Southern Observatory
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*
+ * $Author: amodigli $
+ * $Date: 2012/03/03 09:50:08 $
+ * $Revision: 1.7 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+ /****************************************************************
+  *           Bad pixel search  (normal method)                  *
+  ****************************************************************/
+
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#include "sinfo_product_config.h"
+
+/**@{*/
+/**
+ * @defgroup sinfo_produc_config.c Pipeline products configurations
+ *
+ * TBD
+ */
+
+  /**
+  * @brief
+  *   Adds parameters for the spectrum extraction
+  *
+  * @param list Parameter list to which parameters are added.
+  *
+  * @return Nothing.
+  *
+  * TBD
+  */
+
+  /* General data reduction parameters */
+
+void
+ sinfo_product_config_add(cpl_parameterlist *list)
+{
+
+  cpl_parameter *p;
+
+  if (!list) {
+    return;
+  }
+
+  /* indicates if parameters will be overwritten */
+  p = cpl_parameter_new_enum("sinfoni.product.density",
+			     CPL_TYPE_INT,
+                              "Density of pipeline products: "
+                              "0 (low), 1 (low+skycor), 2 (med-QC), "
+                              "3 (high-debug+skycor)",
+                              "sinfoni.product",
+			     2,4,0,1,2,3);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "product-density");
+  cpl_parameterlist_append(list, p);
+
+
+  return;
+
+}
+/**@}*/
diff --git a/sinfoni/sinfo_product_config.h b/sinfoni/sinfo_product_config.h
new file mode 100644
index 0000000..2e1eb4f
--- /dev/null
+++ b/sinfoni/sinfo_product_config.h
@@ -0,0 +1,37 @@
+/* $Id: sinfo_product_config.h,v 1.1 2006/10/20 08:06:33 amodigli Exp $
+ *
+ * This file is part of the CPL (Common Pipeline Library)
+ * Copyright (C) 2002 European Southern Observatory
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*
+ * $Author: amodigli $
+ * $Date: 2006/10/20 08:06:33 $
+ * $Revision: 1.1 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+ /****************************************************************
+  *           Bad pixel search  (noise method)                  *
+  ****************************************************************/
+#ifndef SINFO_PRODUCT_CONFIG_H
+#define SINFO_PRODUCT_CONFIG_H
+
+#include <cpl.h>   
+
+void sinfo_product_config_add(cpl_parameterlist *list);
+
+#endif
diff --git a/sinfoni/sinfo_psf_cfg.c b/sinfoni/sinfo_psf_cfg.c
new file mode 100644
index 0000000..fa96319
--- /dev/null
+++ b/sinfoni/sinfo_psf_cfg.c
@@ -0,0 +1,82 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*---------------------------------------------------------------------------
+   
+   File name     :    sinfo_psf_cfg.c
+   Author     :       Juergen Schreiber
+   Created on    :    February 2002
+   Description    :    configuration handling tools for the 
+                        psf image reconstruction of a star.
+
+ *--------------------------------------------------------------------------*/
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+/*---------------------------------------------------------------------------
+                                   Includes
+ ---------------------------------------------------------------------------*/
+
+#include "sinfo_psf_cfg.h"
+/**@{*/
+/** 
+ * @addtogroup sinfo_rec_jitter PSF structure definition
+ *
+ * TBD
+ */
+
+/*---------------------------------------------------------------------------
+                              Function codes
+ ---------------------------------------------------------------------------*/
+
+/*---------------------------------------------------------------------------
+   Function :   sinfo_psf_cfg_create()
+   In       :   void
+   Out      :   pointer to allocated base psf_config structure
+   Job      :   allocate memory for a psf_config struct
+   Notice   :   only the main (base) structure is allocated
+ ---------------------------------------------------------------------------*/
+
+psf_config * sinfo_psf_cfg_create(void)
+{
+    return cpl_calloc(1, sizeof(psf_config));
+}
+
+
+/*---------------------------------------------------------------------------
+   Function :   sinfo_psf_cfg_destroy()
+   In       :   psf_config to deallocate
+   Out      :   void
+   Job      :   deallocate all memory associated with a config data structure
+   Notice   :   
+ ---------------------------------------------------------------------------*/
+
+void sinfo_psf_cfg_destroy(psf_config * cc)
+{
+    if (cc==NULL) return ;
+
+    /* Free main struct */
+    cpl_free(cc);
+
+    return ;
+}
+
+/**@}*/
+
+
diff --git a/sinfoni/sinfo_psf_cfg.h b/sinfoni/sinfo_psf_cfg.h
new file mode 100644
index 0000000..1d34016
--- /dev/null
+++ b/sinfoni/sinfo_psf_cfg.h
@@ -0,0 +1,105 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*---------------------------------------------------------------------------
+   
+   File name     :    sinfo_psf_cfg.h
+   Author    :    Juergen Schreiber
+   Created on    :    February 2002
+   Description    :    psf_cfg.c definitions + handling prototypes
+ ---------------------------------------------------------------------------*/
+#ifndef SINFO_PSF_CFG_H
+#define SINFO_PSF_CFG_H
+/*---------------------------------------------------------------------------
+                                   Includes
+ ---------------------------------------------------------------------------*/
+#include <stdlib.h>
+#include "sinfo_globals.h"
+#include <cpl.h>
+/*---------------------------------------------------------------------------
+                                   Defines
+ ---------------------------------------------------------------------------*/
+/*---------------------------------------------------------------------------
+                                   New types
+ ---------------------------------------------------------------------------*/
+/*
+  PSF star image reconstruction blackboard container
+
+  This structure holds all information related to the sinfo_psf reconstruction
+  routine. It is used as a container for the flux of ancillary data,
+  computed values, and algorithm status. Pixel flux is separated from
+  the blackboard.
+  */
+
+typedef struct psf_config {
+/*-------General---------*/
+        char inFrame[FILE_NAME_SZ] ; /* input averaged, bad pixel corrected, 
+                                        off subtracted, flatfielded, spectral 
+                                        tilt corrected list of frames */
+        char outName[FILE_NAME_SZ] ; /* output name of resulting fits 
+                                        data cube */
+
+/*------ Reconstruction ------*/
+        /* the fraction [0...1] of rejected low intensity pixels when taking 
+           the average of columns */
+        float lo_reject ;
+        /* the fraction [0...1] of rejected high intensity pixels when taking 
+           the average of columns */
+        float hi_reject ;
+        /* indicates if the slitlet distances are determined by a 
+           north-south test (1) or slitlet edge fits (0) */ 
+        int northsouthInd  ;
+        /* name of the ASCII list of the fitted slitlet edge positions or 
+           the distances of the slitlets */
+        char poslist[FILE_NAME_SZ] ;
+        /* number of slitlets (32) */
+        int nslits ;
+        /* sub pixel position of the column position of the left sinfo_edge of 
+           the first slitlet needed if the slitlet distances were determined 
+           by a north south test */
+        char  firstCol[FILE_NAME_SZ] ;
+    /* indicator for the shifting method to use */
+    char  method[1] ;
+        /* order of polynomial if the polynomial interpolation shifting 
+           method is used */
+        int order ;
+} psf_config ;
+
+/*---------------------------------------------------------------------------
+                               Function prototypes
+ ---------------------------------------------------------------------------*/
+/**
+   @name    sinfo_psf_cfg_create()
+   @return  pointer to allocated base psf_cfg structure
+   @doc     allocate memory for a psf_config struct
+   @note   only the main (base) structure is allocated
+*/
+
+psf_config * 
+sinfo_psf_cfg_create(void);
+
+/**
+   @name   sinfo_psf_cfg_destroy()
+   @memo  deallocate all memory associated with a psf_config data structure
+   @param  psf_config to deallocate
+   @return void
+*/
+void 
+sinfo_psf_cfg_destroy(psf_config * cc);
+
+#endif
diff --git a/sinfoni/sinfo_psf_config.c b/sinfoni/sinfo_psf_config.c
new file mode 100644
index 0000000..bc9b139
--- /dev/null
+++ b/sinfoni/sinfo_psf_config.c
@@ -0,0 +1,73 @@
+/* $Id: sinfo_psf_config.c,v 1.5 2012/03/03 09:50:08 amodigli Exp $
+ *
+ * This file is part of the CPL (Common Pipeline Library)
+ * Copyright (C) 2002 European Southern Observatory
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*
+ * $Author: amodigli $
+ * $Date: 2012/03/03 09:50:08 $
+ * $Revision: 1.5 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+ /****************************************************************
+  *   Psf Frames Data Reduction Parameter Initialization        *
+  ****************************************************************/
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#include "sinfo_psf_config.h"
+/**@{*/
+/**
+ * @addtogroup sinfo_rec_jitter PSF parameters definition & initialization
+ *
+ * TBD
+ */
+
+/**
+ at name  sinfo_psf_config_add
+ at brief PSF parameters definition & initialization
+ at param list pointer to cpl_parameterlist
+ at return void
+*/
+
+void
+ sinfo_psf_config_add(cpl_parameterlist *list)
+{
+
+  cpl_parameter *p;
+  if (!list) {
+    return;
+  }
+
+  /* Input file name */
+
+  p = cpl_parameter_new_value("sinfoni.psf.switch",
+                  CPL_TYPE_BOOL,
+                              "Switch to activate PSF-related "
+                              "(Strehl/Encircled energy) computation",
+                              "sinfoni.psf",
+                              TRUE);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"psf-switch");
+  cpl_parameterlist_append(list, p);
+
+
+
+}
+/**@}*/
diff --git a/sinfoni/sinfo_psf_config.h b/sinfoni/sinfo_psf_config.h
new file mode 100644
index 0000000..10a0b4d
--- /dev/null
+++ b/sinfoni/sinfo_psf_config.h
@@ -0,0 +1,32 @@
+/* $Id: sinfo_psf_config.h,v 1.1 2006/10/20 08:06:33 amodigli Exp $
+ *
+ * This file is part of the CPL (Common Pipeline Library)
+ * Copyright (C) 2002 European Southern Observatory
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*
+ * $Author: amodigli $
+ * $Date: 2006/10/20 08:06:33 $
+ * $Revision: 1.1 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+ /****************************************************************
+  *   Psf Frames Data Reduction Parameter Initialization        *
+  ****************************************************************/
+#include "cpl.h"    /* defines parlist structure */
+void
+sinfo_psf_config_add(cpl_parameterlist *list);
diff --git a/sinfoni/sinfo_psf_ini.h b/sinfoni/sinfo_psf_ini.h
new file mode 100644
index 0000000..6a5efa6
--- /dev/null
+++ b/sinfoni/sinfo_psf_ini.h
@@ -0,0 +1,76 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+   
+   File name    :  psf_ini.h
+   Author       :    Juergen Schreiber
+   Created on   :    Feb 18, 2002
+   Description  :    ini file handling for SINFONI  PSF star 
+                        image reconstruction
+ ---------------------------------------------------------------------------*/
+#ifndef SINFO_PSF_INI_H
+#define SINFO_PSF_INI_H
+/*---------------------------------------------------------------------------
+                                Includes
+---------------------------------------------------------------------------*/
+#include <cpl.h>
+#include "sinfo_psf_cfg.h"
+/*----------------------------------------------------------------------------
+                             Function prototypes 
+ ---------------------------------------------------------------------------*/
+/**
+  @name        generatePSF_ini_file
+  @memo        Generate a default ini file for the PSF image 
+                reconstruction command.
+  @param    ini_name    Name of the file to generate.
+  @param    name_i        Name of the input file.
+  @param    name_o        Name of the output file.
+  @return    int 0 if Ok, -1 otherwise.
+  @doc
+
+  This function generates a default ini file for the PSF image 
+  reconstruction command. The
+  generated file will have the requested name. If you do not want to
+  provide names for the input/output/calib files, feed either NULL pointers
+  or character strings starting with (char)0.
+ */
+
+int 
+generatePSF_ini_file(
+        char * ini_name,
+        char * name_i,
+        char * name_o
+);
+
+/**
+  @name     parse_psf_ini_file
+  @memo     Parse a ini_name.ini file and create a blackboard.
+  @param    ini_name    Name of the ASCII file to parse.
+  @return   1 newly allocated psf_config blackboard structure.
+  @doc
+
+  The requested ini file is parsed and a blackboard object is created, then
+  updated accordingly. Returns NULL in case of error.
+ */
+
+
+psf_config * 
+parse_psf_ini_file(char * ini_name) ;
+
+#endif
diff --git a/sinfoni/sinfo_psf_ini_by_cpl.c b/sinfoni/sinfo_psf_ini_by_cpl.c
new file mode 100644
index 0000000..2539a26
--- /dev/null
+++ b/sinfoni/sinfo_psf_ini_by_cpl.c
@@ -0,0 +1,208 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+   
+   File name    :   sinfo_psf_ini_by_cpl.c
+   Author       :   Andrea Modigliani
+   Created on   :   May 20, 2004
+   Description  :   cpl input for sinfo_psf step for SPIFFI
+
+
+ ---------------------------------------------------------------------------*/
+
+
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+/*---------------------------------------------------------------------------
+                                Includes
+ ---------------------------------------------------------------------------*/
+
+#include "sinfo_psf_ini_by_cpl.h"
+#include "sinfo_hidden.h"
+
+
+/*---------------------------------------------------------------------------
+                    Functions private to this module
+ ---------------------------------------------------------------------------*/
+static void      parse_section_frames(psf_config *, 
+                   cpl_frameset* sof,cpl_frameset** stk,int* status);
+static void     parse_section_reconstruction(psf_config *);
+
+
+/**@{*/
+/**
+ * @addtogroup sinfo_rec_jitter Blackboard to psf structure
+ *
+ * TBD
+ */
+
+
+/*-------------------------------------------------------------------------*/
+/**
+  @name     parse_psf_ini_file
+  @memo     Parse a ini_name.ini file and create a blackboard.
+  @param    ini_name    Name of the ASCII file to parse.
+  @return   1 newly allocate psf_config blackboard structure.
+  @doc
+
+  The requested ini file is parsed and a blackboard object is created, then
+  updated accordingly. Returns NULL in case of error.
+ */
+/*--------------------------------------------------------------------------*/
+
+psf_config * sinfo_parse_cpl_input_psf(cpl_frameset* sof, 
+                 cpl_frameset** stk)
+{
+        psf_config  *       cfg =NULL;
+        int status=0;
+        /*
+         * Perform sanity checks, fill up the structure with what was
+         * found in the ini file
+         */
+
+        cfg = sinfo_psf_cfg_create();
+        parse_section_reconstruction   (cfg);
+         parse_section_frames       (cfg, sof,stk,&status);
+        if (status > 0) {
+                sinfo_msg_error("parsing cpl input");
+                sinfo_psf_cfg_destroy(cfg);
+                cfg = NULL ;
+                return NULL ;
+        }
+        return cfg ;
+}
+
+static void
+parse_section_frames(psf_config * cfg, 
+             cpl_frameset* sof,
+                     cpl_frameset** stk,
+                     int* status)
+{
+   cpl_frame* frame   = NULL;
+
+   int                 npsf=0;
+   int nraw=0;
+   char spat_res[FILE_NAME_SZ];
+   char lamp_status[FILE_NAME_SZ];
+   char band[FILE_NAME_SZ];
+   int ins_set=0;
+
+     sinfo_contains_frames_type(sof,stk,PRO_PSF_CALIBRATOR_STACKED);
+     npsf = cpl_frameset_get_size(*stk);
+     if (npsf < 1) {
+       sinfo_contains_frames_type(sof,stk,PRO_STD_NODDING_STACKED);
+       npsf = cpl_frameset_get_size(*stk);
+     }
+
+     npsf = cpl_frameset_get_size(*stk);
+     if (npsf < 1) {
+       sinfo_contains_frames_type(sof,stk,PRO_OBJECT_NODDING_STACKED);
+       npsf = cpl_frameset_get_size(*stk);
+     }
+
+
+     npsf = cpl_frameset_get_size(*stk);
+     if (npsf < 1) {
+       sinfo_contains_frames_type(sof,stk,PRO_PUPIL_LAMP_STACKED);
+       npsf = cpl_frameset_get_size(*stk);
+     }
+
+     npsf = cpl_frameset_get_size(*stk);
+     if (npsf < 1) {
+         sinfo_msg_error("Cannot find input stacked frames") ;
+         (*status)++;
+         return;
+     }
+
+    if(NULL != cpl_frameset_find(sof,PRO_COADD_PSF)) {
+      frame = cpl_frameset_find(sof,PRO_COADD_PSF);
+      strcpy(cfg -> inFrame,cpl_frame_get_filename(frame));
+    } else if(NULL != cpl_frameset_find(sof,PRO_OBS_PSF)) {
+      frame = cpl_frameset_find(sof,PRO_OBS_PSF);
+      strcpy(cfg -> inFrame,cpl_frame_get_filename(frame));
+    } else if(NULL != cpl_frameset_find(sof,PRO_COADD_STD)) {
+      frame = cpl_frameset_find(sof,PRO_COADD_STD);
+      strcpy(cfg -> inFrame,cpl_frame_get_filename(frame));
+    } else if(NULL != cpl_frameset_find(sof,PRO_OBS_STD)) {
+      frame = cpl_frameset_find(sof,PRO_OBS_STD);
+      strcpy(cfg -> inFrame,cpl_frame_get_filename(frame));
+    } else if(NULL != cpl_frameset_find(sof,PRO_COADD_OBJ)) {
+      frame = cpl_frameset_find(sof,PRO_COADD_OBJ);
+      strcpy(cfg -> inFrame,cpl_frame_get_filename(frame));
+    } else if(NULL != cpl_frameset_find(sof,PRO_OBS_OBJ)) {
+      frame = cpl_frameset_find(sof,PRO_OBS_OBJ);
+      strcpy(cfg -> inFrame,cpl_frame_get_filename(frame));
+    } else {
+      sinfo_msg_error("Frame %s or %s or %s or %s or %s or %s not found!", 
+       PRO_COADD_PSF,PRO_OBS_PSF,
+       PRO_COADD_STD,PRO_OBS_STD,
+       PRO_COADD_OBJ,PRO_OBS_OBJ);
+      (*status)++;
+      return;
+    }
+
+   strcpy(cfg -> outName, PSF_OUT_FILENAME);
+   nraw    = cpl_frameset_get_size(*stk);
+   frame = cpl_frameset_get_frame(*stk,0);
+
+   sinfo_get_spatial_res(frame,spat_res);
+   switch(sinfo_frame_is_on(frame))
+     {
+
+    case 0: 
+      strcpy(lamp_status,"on");
+      break;
+    case 1: 
+      strcpy(lamp_status,"off");
+      break;
+    case -1:
+      strcpy(lamp_status,"undefined");
+      break;
+    default: 
+      strcpy(lamp_status,"undefined");
+      break;
+
+     }
+
+   sinfo_get_band(frame,band);
+   sinfo_msg("Spatial resolution: %s lamp status: %s band: %s \n",
+                     spat_res,    lamp_status,    band);
+
+   sinfo_get_ins_set(band,&ins_set);
+
+   return;
+
+}
+
+static void     
+parse_section_reconstruction(psf_config * cfg)
+{
+   cfg -> nslits = NSLITLETS;
+   return;
+}
+
+void
+sinfo_free_psf(psf_config ** cfg) {
+   sinfo_psf_cfg_destroy (*cfg);
+   *cfg=NULL;
+  return;
+}
+/**@}*/
diff --git a/sinfoni/sinfo_psf_ini_by_cpl.h b/sinfoni/sinfo_psf_ini_by_cpl.h
new file mode 100644
index 0000000..75317e9
--- /dev/null
+++ b/sinfoni/sinfo_psf_ini_by_cpl.h
@@ -0,0 +1,63 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+   
+   File name    :  sinfo_psf_ini_by_cpl.h
+   Author       :  Andrea Modigliani
+   Created on   :  May 20, 2004
+   Description  :    ini file handling for SPIFFIs PSF star image reconstruction
+ ---------------------------------------------------------------------------*/
+#ifndef SINFO_PSF_INI_BY_CPL_H
+#define SINFO_PSF_INI_BY_CPL_H
+/*---------------------------------------------------------------------------
+                                Includes
+---------------------------------------------------------------------------*/
+#include <cpl.h>
+#include "sinfo_msg.h"
+#include "sinfo_dfs.h"
+#include "sinfo_psf_cfg.h"
+/*----------------------------------------------------------------------------
+                             Function prototypes 
+ ---------------------------------------------------------------------------*/
+/**
+  @name     parse_psf_ini_file
+  @memo     Parse a ini_name.ini file and create a blackboard.
+  @param    cpl_cfg pointer to parameterlist
+  @param    sof pointer to input set of frames
+  @param    raw pointer to input set of raw frames
+  @return   1 newly allocated psf_config blackboard structure.
+  @doc
+
+  The requested ini file is parsed and a blackboard object is created, then
+  updated accordingly. Returns NULL in case of error.
+ */
+
+psf_config * 
+sinfo_parse_cpl_input_psf(cpl_frameset* sof, cpl_frameset** stk);
+
+/**
+ at name sinfo_psf_free
+ at memo deallocates psf_config structure
+ at param cfg pointer to psf_config structure
+ at return void
+*/
+
+void 
+sinfo_free_psf(psf_config ** cfg);
+#endif
diff --git a/sinfoni/sinfo_qr.c b/sinfoni/sinfo_qr.c
new file mode 100644
index 0000000..cd41c2e
--- /dev/null
+++ b/sinfoni/sinfo_qr.c
@@ -0,0 +1,270 @@
+/* $Id: sinfo_qr.c,v 1.5 2012/03/03 10:18:26 amodigli Exp $
+ *
+ * This file is part of the SINFONI Pipeline
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2012/03/03 10:18:26 $
+ * $Revision: 1.5 $
+ * $Name: sinfo-2_3_2 $
+ */
+/**@{*/
+/**
+ * @defgroup sinfo_qr_companion functions for polynomial solution
+ *
+ * TBD
+ */
+
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#include "sinfo_solve_poly_root.h"
+//#include "sinfoni_recipes_defaults.h"
+
+#define GSL_SET_COMPLEX_PACKED(zp,n,x,y) \
+ do {*((zp)+2*(n))=(x); *((zp)+(2*(n)+1))=(y);} while(0)
+#define GSL_DBL_EPSILON        2.2204460492503131e-16
+
+
+int
+sinfo_qr_companion (double *h, size_t nc, gsl_complex_packed_ptr zroot)
+{
+  double t = 0.0;
+
+  size_t iterations, e, i, j, k, m;
+
+  double w, x, y, s, z;
+
+  double p = 0, q = 0, r = 0; 
+
+  /* FIXME: if p,q,r, are not set to zero then the compiler complains
+     that they ``might be used uninitialized in this
+     function''. Looking at the code this does seem possible, so this
+     should be checked. */
+
+  int notlast;
+
+  size_t n = nc;
+
+next_root:
+
+  if (n == 0)
+    return 1 ;
+
+  iterations = 0;
+
+next_iteration:
+
+  for (e = n; e >= 2; e--)
+    {
+      double a1 = fabs (FMAT (h, e, e - 1, nc));
+      double a2 = fabs (FMAT (h, e - 1, e - 1, nc));
+      double a3 = fabs (FMAT (h, e, e, nc));
+
+      if (a1 <= GSL_DBL_EPSILON * (a2 + a3))
+    break;
+    }
+
+  x = FMAT (h, n, n, nc);
+
+  if (e == n)
+    {
+      GSL_SET_COMPLEX_PACKED (zroot, n-1, x + t, 0); /* one real root */
+      n--;
+      goto next_root;
+      /*continue;*/
+    }
+
+  y = FMAT (h, n - 1, n - 1, nc);
+  w = FMAT (h, n - 1, n, nc) * FMAT (h, n, n - 1, nc);
+
+  if (e == n - 1)
+    {
+      p = (y - x) / 2;
+      q = p * p + w;
+      y = sqrt (fabs (q));
+
+      x += t;
+
+      if (q > 0)        /* two real roots */
+    {
+      if (p < 0)
+        y = -y;
+      y += p;
+
+      GSL_SET_COMPLEX_PACKED (zroot, n-1, x - w / y, 0);
+          GSL_SET_COMPLEX_PACKED (zroot, n-2, x + y, 0);
+    }
+      else
+    {
+      GSL_SET_COMPLEX_PACKED (zroot, n-1, x + p, -y);
+      GSL_SET_COMPLEX_PACKED (zroot, n-2, x + p, y);
+    }
+      n -= 2;
+
+      goto next_root;
+      /*continue;*/
+    }
+
+  /* No more roots found yet, do another iteration */
+
+  if (iterations == 60)  /* increased from 30 to 60 */
+    {
+      /* too many iterations - give up! */
+      cpl_msg_error("qr:","too many iterations-give up") ;
+      return -1 ;
+    }
+
+  if (iterations % 10 == 0 && iterations > 0)
+    {
+      /* use an exceptional shift */
+
+      t += x;
+
+      for (i = 1; i <= n; i++)
+    {
+      FMAT (h, i, i, nc) -= x;
+    }
+
+      s = fabs (FMAT (h, n, n - 1, nc)) + fabs (FMAT (h, n - 1, n - 2, nc));
+      y = 0.75 * s;
+      x = y;
+      w = -0.4375 * s * s;
+    }
+
+  iterations++;
+
+  for (m = n - 2; m >= e; m--)
+    {
+      double a1, a2, a3;
+
+      z = FMAT (h, m, m, nc);
+      r = x - z;
+      s = y - z;
+      p = FMAT (h, m, m + 1, nc) + (r * s - w) / FMAT (h, m + 1, m, nc);
+      q = FMAT (h, m + 1, m + 1, nc) - z - r - s;
+      r = FMAT (h, m + 2, m + 1, nc);
+      s = fabs (p) + fabs (q) + fabs (r);
+      p /= s;
+      q /= s;
+      r /= s;
+
+      if (m == e)
+    break;
+      
+      a1 = fabs (FMAT (h, m, m - 1, nc));
+      a2 = fabs (FMAT (h, m - 1, m - 1, nc));
+      a3 = fabs (FMAT (h, m + 1, m + 1, nc));
+
+      if (a1 * (fabs (q) + fabs (r)) <= GSL_DBL_EPSILON * fabs (p) * (a2 + a3))
+        break;
+    }
+
+  for (i = m + 2; i <= n; i++)
+    {
+      FMAT (h, i, i - 2, nc) = 0;
+    }
+
+  for (i = m + 3; i <= n; i++)
+    {
+      FMAT (h, i, i - 3, nc) = 0;
+    }
+
+  /* double QR step */
+
+  for (k = m; k <= n - 1; k++)
+    {
+      notlast = (k != n - 1);
+
+      if (k != m)
+    {
+      p = FMAT (h, k, k - 1, nc);
+      q = FMAT (h, k + 1, k - 1, nc);
+      r = notlast ? FMAT (h, k + 2, k - 1, nc) : 0.0;
+
+      x = fabs (p) + fabs (q) + fabs (r);
+
+      if (x == 0)
+        continue;        /* FIXME????? */
+
+      p /= x;
+      q /= x;
+      r /= x;
+    }
+
+      s = sqrt (p * p + q * q + r * r);
+
+      if (p < 0)
+    s = -s;
+
+      if (k != m)
+    {
+      FMAT (h, k, k - 1, nc) = -s * x;
+    }
+      else if (e != m)
+    {
+      FMAT (h, k, k - 1, nc) *= -1;
+    }
+
+      p += s;
+      x = p / s;
+      y = q / s;
+      z = r / s;
+      q /= p;
+      r /= p;
+
+      /* do row modifications */
+
+      for (j = k; j <= n; j++)
+    {
+      p = FMAT (h, k, j, nc) + q * FMAT (h, k + 1, j, nc);
+
+      if (notlast)
+        {
+          p += r * FMAT (h, k + 2, j, nc);
+          FMAT (h, k + 2, j, nc) -= p * z;
+        }
+
+      FMAT (h, k + 1, j, nc) -= p * y;
+      FMAT (h, k, j, nc) -= p * x;
+    }
+
+      j = (k + 3 < n) ? (k + 3) : n;
+
+      /* do column modifications */
+
+      for (i = e; i <= j; i++)
+    {
+      p = x * FMAT (h, i, k, nc) + y * FMAT (h, i, k + 1, nc);
+
+      if (notlast)
+        {
+          p += z * FMAT (h, i, k + 2, nc);
+          FMAT (h, i, k + 2, nc) -= p * r;
+        }
+      FMAT (h, i, k + 1, nc) -= p * q;
+      FMAT (h, i, k, nc) -= p;
+    }
+    }
+
+  goto next_iteration;
+}
+/**@}*/
diff --git a/sinfoni/sinfo_raw_types.h b/sinfoni/sinfo_raw_types.h
new file mode 100644
index 0000000..6a4a5b9
--- /dev/null
+++ b/sinfoni/sinfo_raw_types.h
@@ -0,0 +1,113 @@
+/* $Id: sinfo_raw_types.h,v 1.5 2008/07/04 13:06:02 amodigli Exp $
+ *
+ * This file is part of the SINFONI Pipeline
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This proram is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2008/07/04 13:06:02 $
+ * $Revision: 1.5 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifndef SINFO_RAW_TYPES_H
+#define SINFO_RAW_TYPES_H
+
+/*------------------------------------------------------------------------
+                                   Raw TYPES
+ --------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------
+                                   Raw Frames
+ --------------------------------------------------------------------------*/
+CPL_BEGIN_DECLS
+
+#define RAW_LINEARITY_LAMP                 "LINEARITY_LAMP"
+#define RAW_DARK                           "DARK"
+
+#define RAW_PINHOLE_LAMP                   "PINHOLE_LAMP"
+#define RAW_SLIT_LAMP                      "SLIT_LAMP"      /* ?? */
+#define RAW_FIBRE_PSF                      "FIBRE_PSF"    
+#define RAW_FIBRE_DARK                     "FIBRE_DARK"    
+#define RAW_FIBRE_LAMP                     "FIBRE_LAMP"    
+#define RAW_FIBRE_NS                       "FIBRE_NS"      
+#define RAW_FIBRE_EW                       "FIBRE_EW"      
+#define RAW_WAVE_LAMP                      "WAVE_LAMP"
+#define RAW_WAVE_LAMP_DITHER               "WAVE_LAMP_DITHER"
+#define RAW_WAVE_NS                        "WAVE_NS"
+#define RAW_WAVE_NS_DITHER                 "WAVE_NS_DITHER"
+
+#define RAW_FLAT_LAMP                      "FLAT_LAMP"
+#define RAW_FLAT_LAMP_DITHER               "FLAT_LAMP_DITHER"
+#define RAW_FLAT_NS                        "FLAT_NS"
+#define RAW_FLAT_NS_DITHER                 "FLAT_NS_DITHER"
+#define RAW_FLAT_SKY                       "FLAT_SKY"
+#define RAW_FLUX_LAMP                      "FLUX_LAMP"
+#define RAW_PSF_CALIBRATOR                 "PSF_CALIBRATOR"
+#define RAW_FOCUS                          "FOCUS"
+#define RAW_SKY_DUMMY                      "SKY_DUMMY"
+
+#define RAW_PUPIL_LAMP                     "PUPIL_LAMP"
+#define RAW_OBJECT                         "OBJECT"
+#define RAW_IMAGE_PRE_OBJECT               "IMAGE_PRE_OBJECT"
+#define RAW_IMAGE_PRE_SKY                  "IMAGE_PRE_SKY"
+#define RAW_OBJECT_SKYSPIDER               "OBJECT_SKYSPIDER"
+#define RAW_OBJECT_SKYSPIDER_DITHER        "OBJECT_SKYSPIDER_DITHER"
+
+#define RAW_OBJECT_NODDING                 "OBJECT_NODDING"
+#define RAW_SKY_NODDING                    "SKY_NODDING"
+#define RAW_OBJECT_JITTER                  "OBJECT_JITTER"
+#define RAW_SKY_JITTER                     "SKY_JITTER"
+#define RAW_OBJECT_NODDING_DITHER          "OBJECT_NODDING_DITHER"
+#define RAW_OBJECT_JITTER_DITHER           "OBJECT_JITTER_DITHER"
+#define RAW_SKY_NODDING_DITHER             "SKY_NODDING_DITHER"
+#define RAW_SKY_JITTER_DITHER              "SKY_JITTER_DITHER"
+
+
+#define RAW_ACQUISITION_SKY                "ACQUISITION_SKY"
+#define RAW_ACQUISITION_OBJECT             "ACQUISITION_OBJECT"
+
+
+#define RAW_STD                            "STD"
+#define RAW_STACKED_SLITPOS                "STACKED_SLITPOS"
+#define RAW_SKY_STD                        "SKY_STD"
+#define RAW_SKY_OH                         "SKY_OH"
+#define RAW_SKY_PSF_CALIBRATOR             "SKY_PSF_CALIBRATOR"
+#define RAW_STD_STAR                       "STD_STAR"
+#define RAW_STD_STAR_DITHER                "STD_STAR_DITHER"
+
+#define SINFO_UTL_STDSTARS_RAW             "STDSTAR_CAT"
+#define SINFO_UTL_SEDS_RAW                 "SED"
+
+/* next are TBD */
+#define RAW_OFF                            "RAW_OFF"
+#define RAW_OFF1                           "OFF1"
+#define RAW_OFF2                           "OFF2"
+
+#define RAW_SKY                            "SKY"
+#define RAW_SKY1                           "SKY1"
+#define RAW_SKY2                           "SKY2"
+
+#define RAW_ON                             "RAW_ON"
+#define RAW_ON1                            "ON1"
+#define RAW_ON2                            "ON2"
+#define RAW_INT_ON                         "INT_ON"
+#define RAW_INT_OFF                        "INT_OFF"
+CPL_END_DECLS
+
+#endif
diff --git a/sinfoni/sinfo_rec_utils.c b/sinfoni/sinfo_rec_utils.c
new file mode 100644
index 0000000..3e7085e
--- /dev/null
+++ b/sinfoni/sinfo_rec_utils.c
@@ -0,0 +1,1370 @@
+/* $Id: sinfo_rec_utils.c,v 1.14 2012/03/03 10:18:26 amodigli Exp $
+ *
+ * This file is part of the SINFONI Pipeline
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*
+ * $Author: amodigli $
+ * $Date: 2012/03/03 10:18:26 $
+ * $Revision: 1.14 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+ /****************************************************************
+  *           Object Data reduction                              *
+  ****************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>          /* allows the program compilation */
+#endif
+
+/*-----------------------------------------------------------------------------
+                                Includes
+-----------------------------------------------------------------------------*/
+//Used only for sinfo_propertylist_has
+#include "sinfo_dfs.h"
+
+#include <stdio.h>
+#include <sinfo_rec_utils.h>
+#include <sinfo_functions.h>
+#include <sinfo_new_cubes_build.h>
+#include <sinfo_error.h>
+#include <sinfo_globals.h>
+#include <sinfo_utils_wrappers.h>
+/*-----------------------------------------------------------------------------
+                            Functions prototypes
+ ----------------------------------------------------------------------------*/
+/**@{*/
+/*---------------------------------------------------------------------------*/
+/**
+ * @defgroup sinfo_rec_utils   Recipe utilities
+ */
+/*---------------------------------------------------------------------------*/
+static const char* sinfo_new_set_stk_procatg(const char* tag);
+/*
+static int
+sinfo_get_obj_sky_frm_pair(cpl_frameset** obj_set,
+                           const int i,
+                           cpl_frame** obj_frm,
+                           cpl_frame** sky_frm);
+*/
+
+/*-----------------------------------------------------------------------------
+                            Static variables
+ ----------------------------------------------------------------------------*/
+
+/*-----------------------------------------------------------------------------
+                                Functions code
+ ----------------------------------------------------------------------------*/
+
+int
+sinfo_new_stack_frames(cpl_parameterlist* cfg,
+                       cpl_frameset* set,
+                       const char* procatg,
+                       const int id,
+                       fake* fk,
+                       const char* plugin_id)
+{
+  int ind=0;
+  sinfo_msg("------------------------------") ;
+  sinfo_msg("PREPARE STACKED SET %d",id) ;
+  sinfo_msg("------------------------------") ;
+  ck0(ind=sinfo_new_prepare_stacked_frames(plugin_id,cfg, set, NULL,procatg,
+                       id,fk)," no: %d", ind) ;
+  sinfo_msg("------------------------------") ;
+  sinfo_msg("PREPARED STACKED SET %d",id) ;
+  sinfo_msg("------------------------------") ;
+  return 0;
+
+ cleanup:
+  return -1;
+
+}
+
+cpl_frame*
+sinfo_new_get_dummy_sky(cpl_frameset* obj_set)
+{
+
+  cpl_imagelist* obj_list=NULL;
+  cpl_image* fake_sky=NULL;
+  cpl_frame* frame=NULL;
+  cpl_frame* sky_frame=NULL;
+
+  cpl_propertylist* plist=NULL;
+  char filename[FILE_NAME_SZ];
+
+  check_nomsg(obj_list=cpl_imagelist_load_frameset(obj_set,CPL_TYPE_FLOAT,0,0));
+  check_nomsg(fake_sky = cpl_imagelist_collapse_median_create(obj_list));
+
+  check_nomsg(frame = cpl_frameset_get_frame(obj_set,0));
+  strcpy(filename,cpl_frame_get_filename(frame));
+
+  check(plist = cpl_propertylist_load(filename, 0),
+    "getting header from reference ima frame %s",filename);
+
+  if (sinfo_propertylist_has(plist, KEY_NAME_DPR_TYPE)) {
+    cpl_propertylist_set_string(plist, KEY_NAME_DPR_TYPE, "SKY");
+  } else {
+    cpl_propertylist_append_string(plist, KEY_NAME_DPR_TYPE,"SKY") ;
+  }
+
+  check(cpl_image_save(fake_sky, "out_fake_sky.fits", CPL_BPP_IEEE_FLOAT,
+               plist,CPL_IO_DEFAULT),
+    "Cannot save the product %s","out_fake_sky.fits");
+
+  sinfo_free_propertylist(&plist);
+
+  check_nomsg(sky_frame = cpl_frame_new()) ;
+  check_nomsg(cpl_frame_set_filename(sky_frame, "out_fake_sky.fits")) ;
+  check_nomsg(cpl_frame_set_tag(sky_frame, PRO_SKY_DUMMY)) ;
+  check_nomsg(cpl_frame_set_type(sky_frame, CPL_FRAME_TYPE_IMAGE));
+  /*
+  check_nomsg(cpl_frame_set_group(sky_frame, CPL_FRAME_GROUP_PRODUCT));
+  */
+  check_nomsg(cpl_frame_set_level(sky_frame, CPL_FRAME_LEVEL_FINAL));
+  sinfo_free_image(&fake_sky);
+  sinfo_free_imagelist(&obj_list);
+
+  return sky_frame;
+
+ cleanup:
+
+  sinfo_free_propertylist(&plist) ;
+
+  return NULL;
+
+}
+
+
+
+int
+sinfo_new_get_dummy_obj_sky_stacked(cpl_frameset* obj_set,cpl_frameset** set,
+cpl_parameterlist* config,fake* fk, char* pro_ctg, const char* plugin_id)
+{
+  int nobj=0;
+  int ncdb=0;
+  int ntot=0;
+  int nstk=0;
+  int nwrk=0;
+  int i=0;
+  int k=0;
+
+  double mjd_obj=0;
+  double mjd_sky_inf=0;
+  double mjd_sky_sup=0;
+  char sky_name[FILE_NAME_SZ];
+  char out_name[FILE_NAME_SZ];
+
+  char fake_sky_name[FILE_NAME_SZ];
+
+  cpl_frame* obj_frm=NULL;
+  cpl_frame* sky_frm=NULL;
+  cpl_frame* cdb_frm=NULL;
+  cpl_frame* wrk_frm=NULL;
+  cpl_frame* tot_frm=NULL;
+  cpl_frame* dup_frm=NULL;
+
+  cpl_frame* sky_frm_inf=NULL;
+  cpl_frame* sky_frm_sup=NULL;
+
+  cpl_propertylist* plist=NULL;
+  cpl_frameset* wrk_set=NULL;
+  cpl_frameset* cdb_set=NULL;
+  cpl_frameset* tot_set=NULL;
+  cpl_frameset* stk_set=NULL;
+  cpl_image* sky_ima=NULL;
+  double obj_cumx=0;
+  double obj_cumy=0;
+
+  double sky_sup_cumx=0;
+  double sky_sup_cumy=0;
+
+  double sky_inf_cumx=0;
+  double sky_inf_cumy=0;
+  double cum_thres=0.5;
+
+  check_nomsg(cdb_set=cpl_frameset_new());
+  ck0(sinfo_extract_mst_frames(*set,cdb_set),"Error extracting CDB frames");
+  nobj=cpl_frameset_get_size(obj_set);
+  ncdb=cpl_frameset_get_size(cdb_set);
+
+
+  check_nomsg(tot_set=cpl_frameset_new());
+
+  for(i=0;i<nobj;i++) {
+
+
+
+
+    check_nomsg(obj_frm=cpl_frameset_get_frame(obj_set,i));
+    mjd_obj    = sinfo_get_mjd_obs(obj_frm);
+    obj_cumx=sinfo_get_cumoffsetx(obj_frm);
+    obj_cumy=sinfo_get_cumoffsety(obj_frm);
+
+    if(i>0) {
+       check_nomsg(sky_frm_inf=cpl_frameset_get_frame(obj_set,i-1));
+       mjd_sky_inf = sinfo_get_mjd_obs(sky_frm_inf);
+       sky_inf_cumx=sinfo_get_cumoffsetx(sky_frm_inf);
+       sky_inf_cumy=sinfo_get_cumoffsety(sky_frm_inf);
+    }
+
+    if(i<nobj-1) {
+      check_nomsg(sky_frm_sup=cpl_frameset_get_frame(obj_set,i+1));
+      mjd_sky_sup = sinfo_get_mjd_obs(sky_frm_sup);
+      sky_sup_cumx=sinfo_get_cumoffsetx(sky_frm_sup);
+      sky_sup_cumy=sinfo_get_cumoffsety(sky_frm_sup);
+    }
+
+
+
+    if(i==0) {
+         sky_frm = sky_frm_sup;
+    }
+    else if(i==(nobj-1)) {
+         sky_frm = sky_frm_inf;
+    } else {
+       if( fabs( mjd_sky_inf - mjd_obj ) <
+           fabs( mjd_sky_sup - mjd_obj ) ) {
+         if((fabs(sky_inf_cumx-obj_cumx) > cum_thres) ||
+            (fabs(sky_inf_cumy-obj_cumy) > cum_thres)) {
+       sky_frm = sky_frm_inf;
+     } else {
+       sky_frm = sky_frm_sup;
+     }
+       } else {
+         if((fabs(sky_sup_cumx-obj_cumx) > cum_thres) ||
+            (fabs(sky_sup_cumy-obj_cumy) > cum_thres)) {
+       sky_frm = sky_frm_sup;
+     } else {
+       sky_frm = sky_frm_inf;
+     }
+       }
+    }
+
+    strcpy(sky_name,cpl_frame_get_filename(sky_frm));
+
+    sinfo_msg("obj: %s",cpl_frame_get_filename(obj_frm));
+    sinfo_msg("sky: %s",sky_name);
+
+    if (strstr(sky_name, "." ) != NULL ) {
+      /*snprintf(fake_sky_name,MAX_NAME_SIZE-1,"%s%s","fake_",
+        basename(sky_name)); */
+      snprintf(fake_sky_name,MAX_NAME_SIZE-1,"%s%d%s","out_fake_sky",i,".fits");
+    } else {
+       snprintf(fake_sky_name, MAX_NAME_SIZE-1,sky_name) ;
+    }
+
+    check_nomsg(sky_ima=cpl_image_load(sky_name,CPL_TYPE_FLOAT,0,0));
+
+    cknull(plist = cpl_propertylist_load(sky_name, 0),
+      "getting header from reference ima frame %s",sky_name);
+
+    if (sinfo_propertylist_has(plist, KEY_NAME_DPR_TYPE)) {
+      cpl_propertylist_set_string(plist, KEY_NAME_DPR_TYPE, "SKY");
+    } else {
+      cpl_propertylist_append_string(plist, KEY_NAME_DPR_TYPE,"SKY") ;
+    }
+
+    check(cpl_image_save(sky_ima, fake_sky_name, CPL_BPP_IEEE_FLOAT,
+                   plist,CPL_IO_DEFAULT),
+                "Cannot save the product %s",fake_sky_name);
+
+    sinfo_free_propertylist(&plist);
+    sinfo_free_image(&sky_ima);
+
+    check_nomsg(cpl_frame_set_filename(sky_frm, fake_sky_name)) ;
+    /* The following makes program crash
+       check_nomsg(cpl_frame_set_tag(sky_frm, PRO_SKY_DUMMY)) ;
+    */
+    check_nomsg(cpl_frame_set_type(sky_frm, CPL_FRAME_TYPE_IMAGE));
+    /* check_nomsg(cpl_frame_set_group(sky_frm, CPL_FRAME_GROUP_PRODUCT)); */
+    check_nomsg(cpl_frame_set_level(sky_frm, CPL_FRAME_LEVEL_FINAL));
+
+
+    check_nomsg(wrk_set=cpl_frameset_new());
+
+    check_nomsg(dup_frm=cpl_frame_duplicate(obj_frm));
+    check_nomsg(cpl_frameset_insert(wrk_set,dup_frm));
+
+    check_nomsg(dup_frm=cpl_frame_duplicate(sky_frm));
+    check_nomsg(cpl_frameset_insert(wrk_set,dup_frm));
+
+
+    for(k=0;k<ncdb;k++) {
+      check_nomsg(cdb_frm=cpl_frameset_get_frame(cdb_set,k));
+      check_nomsg(dup_frm=cpl_frame_duplicate(cdb_frm));
+      check_nomsg(cpl_frameset_insert(wrk_set,dup_frm));
+    }
+    snprintf(out_name,MAX_NAME_SIZE-1,"%s%d%s","out_stack",i,".fits");
+    nwrk=cpl_frameset_get_size(wrk_set);
+
+
+    ck0(sinfo_new_stack_frames(config,wrk_set,pro_ctg,i,fk,plugin_id),
+        "Error stacking frames");
+
+    check_nomsg(cpl_frame_set_filename(sky_frm, sky_name)) ;
+    /* This commented as was screwing up the catalogue.
+    check_nomsg(cpl_frame_set_tag(sky_frm, RAW_OBJECT_NODDING)) ;
+    */
+    check_nomsg(stk_set=cpl_frameset_new());
+    sinfo_contains_frames_kind(wrk_set,stk_set,PRO_STACKED);
+    nstk=cpl_frameset_get_size(stk_set);
+    for(k=0;k<nstk;k++) {
+      check_nomsg(wrk_frm=cpl_frameset_get_frame(stk_set,k));
+      check_nomsg(dup_frm=cpl_frame_duplicate(wrk_frm));
+      check_nomsg(cpl_frameset_insert(tot_set,dup_frm));
+    }
+    sinfo_free_frameset(&stk_set);
+    sinfo_free_frameset(&wrk_set);
+
+  }
+  ntot=cpl_frameset_get_size(tot_set);
+  for(k=0;k<ntot;k++) {
+    check_nomsg(tot_frm=cpl_frameset_get_frame(tot_set,k));
+    check_nomsg(dup_frm=cpl_frame_duplicate(tot_frm));
+    check_nomsg(cpl_frameset_insert(*set,dup_frm));
+  }
+
+  sinfo_free_frameset(&cdb_set);
+  sinfo_free_frameset(&tot_set);
+
+  return 0;
+
+ cleanup:
+  sinfo_free_propertylist(&plist) ;
+  sinfo_free_frameset(&cdb_set);
+  sinfo_free_frameset(&tot_set);
+  return -1;
+
+}
+
+int
+sinfo_get_dummy_obj_sky_stacked_and_cubes(cpl_frameset* obj_set,
+                                          cpl_frameset** set,
+                                          cpl_parameterlist* config,
+                                          fake* fk,
+                                          char* pro_ctg,
+                                          const char* plugin_id)
+{
+  int nobj=0;
+  int ncdb=0;
+  int nwrk=0;
+  int i=0;
+  int k=0;
+  int ind=0;
+
+  double mjd_obj=0;
+  double mjd_sky_inf=0;
+  double mjd_sky_sup=0;
+  char sky_name[FILE_NAME_SZ];
+  char out_name[FILE_NAME_SZ];
+
+  char fake_sky_name[FILE_NAME_SZ];
+
+  cpl_frame* obj_frm=NULL;
+  cpl_frame* sky_frm=NULL;
+  cpl_frame* cdb_frm=NULL;
+  cpl_frame* dup_frm=NULL;
+
+  cpl_frame* sky_frm_inf=NULL;
+  cpl_frame* sky_frm_sup=NULL;
+
+  cpl_propertylist* plist=NULL;
+  cpl_frameset* wrk_set=NULL;
+  cpl_frameset* cdb_set=NULL;
+  cpl_frameset* tot_set=NULL;
+  cpl_frameset* pro_set=NULL;
+  cpl_image* sky_ima=NULL;
+  double obj_cumx=0;
+  double obj_cumy=0;
+
+  double sky_sup_cumx=0;
+  double sky_sup_cumy=0;
+
+  double sky_inf_cumx=0;
+  double sky_inf_cumy=0;
+  double cum_thres=0.5;
+
+  check_nomsg(cdb_set=cpl_frameset_new());
+  ck0(sinfo_extract_mst_frames(*set,cdb_set),"Error extracting CDB frames");
+  nobj=cpl_frameset_get_size(obj_set);
+  ncdb=cpl_frameset_get_size(cdb_set);
+
+
+  check_nomsg(tot_set=cpl_frameset_new());
+
+  for(i=0;i<nobj;i++) {
+
+    check_nomsg(obj_frm=cpl_frameset_get_frame(obj_set,i));
+    mjd_obj    = sinfo_get_mjd_obs(obj_frm);
+    obj_cumx=sinfo_get_cumoffsetx(obj_frm);
+    obj_cumy=sinfo_get_cumoffsety(obj_frm);
+
+    if(i>0) {
+       check_nomsg(sky_frm_inf=cpl_frameset_get_frame(obj_set,i-1));
+       mjd_sky_inf = sinfo_get_mjd_obs(sky_frm_inf);
+       sky_inf_cumx=sinfo_get_cumoffsetx(sky_frm_inf);
+       sky_inf_cumy=sinfo_get_cumoffsety(sky_frm_inf);
+    }
+
+    if(i<nobj-1) {
+      check_nomsg(sky_frm_sup=cpl_frameset_get_frame(obj_set,i+1));
+      mjd_sky_sup = sinfo_get_mjd_obs(sky_frm_sup);
+      sky_sup_cumx=sinfo_get_cumoffsetx(sky_frm_sup);
+      sky_sup_cumy=sinfo_get_cumoffsety(sky_frm_sup);
+    }
+
+
+
+    if(i==0) {
+         sky_frm = sky_frm_sup;
+    }
+    else if(i==(nobj-1)) {
+         sky_frm = sky_frm_inf;
+    } else {
+       if( fabs( mjd_sky_inf - mjd_obj ) <
+           fabs( mjd_sky_sup - mjd_obj ) ) {
+         if((fabs(sky_inf_cumx-obj_cumx) > cum_thres) ||
+            (fabs(sky_inf_cumy-obj_cumy) > cum_thres)) {
+       sky_frm = sky_frm_inf;
+     } else {
+       sky_frm = sky_frm_sup;
+     }
+       } else {
+         if((fabs(sky_sup_cumx-obj_cumx) > cum_thres) ||
+            (fabs(sky_sup_cumy-obj_cumy) > cum_thres)) {
+       sky_frm = sky_frm_sup;
+     } else {
+       sky_frm = sky_frm_inf;
+     }
+       }
+    }
+
+
+    strcpy(sky_name,cpl_frame_get_filename(sky_frm));
+    sinfo_msg("obj: %s",cpl_frame_get_filename(obj_frm));
+    sinfo_msg("sky: %s",sky_name);
+    if (strstr(sky_name, "." ) != NULL ) {
+      /*snprintf(fake_sky_name,MAX_NAME_SIZE-1,"%s%s",
+                 "fake_",basename(sky_name)); */
+      snprintf(fake_sky_name,MAX_NAME_SIZE-1,"%s%d%s","out_fake_sky",i,".fits");
+    } else {
+       snprintf(fake_sky_name, MAX_NAME_SIZE-1,sky_name) ;
+    }
+
+    check_nomsg(sky_ima=cpl_image_load(sky_name,CPL_TYPE_FLOAT,0,0));
+
+    cknull(plist = cpl_propertylist_load(sky_name, 0),
+      "getting header from reference ima frame %s",sky_name);
+
+    if (sinfo_propertylist_has(plist, KEY_NAME_DPR_TYPE)) {
+      cpl_propertylist_set_string(plist, KEY_NAME_DPR_TYPE, "SKY");
+    } else {
+      cpl_propertylist_append_string(plist, KEY_NAME_DPR_TYPE,"SKY") ;
+    }
+    check(cpl_image_save(sky_ima, fake_sky_name, CPL_BPP_IEEE_FLOAT,
+                   plist,CPL_IO_DEFAULT),
+                "Cannot save the product %s",fake_sky_name);
+
+    sinfo_free_propertylist(&plist);
+    sinfo_free_image(&sky_ima);
+
+    check_nomsg(cpl_frame_set_filename(sky_frm, fake_sky_name)) ;
+    /* The following makes program crash
+       check_nomsg(cpl_frame_set_tag(sky_frm, PRO_SKY_DUMMY)) ;
+    */
+    check_nomsg(cpl_frame_set_type(sky_frm, CPL_FRAME_TYPE_IMAGE));
+    /* check_nomsg(cpl_frame_set_group(sky_frm, CPL_FRAME_GROUP_PRODUCT)); */
+    check_nomsg(cpl_frame_set_level(sky_frm, CPL_FRAME_LEVEL_FINAL));
+
+
+    check_nomsg(wrk_set=cpl_frameset_new());
+
+    check_nomsg(dup_frm=cpl_frame_duplicate(obj_frm));
+    check_nomsg(cpl_frameset_insert(wrk_set,dup_frm));
+
+    check_nomsg(dup_frm=cpl_frame_duplicate(sky_frm));
+    check_nomsg(cpl_frameset_insert(wrk_set,dup_frm));
+
+    for(k=0;k<ncdb;k++) {
+      check_nomsg(cdb_frm=cpl_frameset_get_frame(cdb_set,k));
+      check_nomsg(dup_frm=cpl_frame_duplicate(cdb_frm));
+      check_nomsg(cpl_frameset_insert(wrk_set,dup_frm));
+    }
+    snprintf(out_name,MAX_NAME_SIZE-1,"%s%d%s","out_stack",i,".fits");
+    nwrk=cpl_frameset_get_size(wrk_set);
+
+
+    ck0(sinfo_new_stack_frames(config,wrk_set,pro_ctg,i,fk,plugin_id),
+        "Error stacking frames");
+
+
+    check_nomsg(cpl_frame_set_filename(sky_frm, sky_name)) ;
+    /* This commented as was screwing up the catalogue.
+    check_nomsg(cpl_frame_set_tag(sky_frm, RAW_OBJECT_NODDING)) ;
+    */
+    sinfo_msg("--------------------------------------");
+    sinfo_msg("BUILDING CUBE %d",i);
+    sinfo_msg("--------------------------------------");
+
+    /* cube generation */
+    ck0(ind=sinfo_new_cubes_build(plugin_id,config,wrk_set,pro_ctg,i),
+    "GENERATING CUBE no. %d\n", ind) ;
+    sinfo_msg("--------------------------------------");
+    sinfo_msg("BUILT CUBE %d",i);
+    sinfo_msg("--------------------------------------");
+
+
+    check_nomsg(sinfo_extract_frames_group_type(wrk_set,&pro_set,
+                                                CPL_FRAME_GROUP_PRODUCT));
+    check_nomsg(sinfo_frameset_merge(tot_set,pro_set));
+    sinfo_free_frameset(&pro_set);
+    sinfo_free_frameset(&wrk_set);
+
+  } /* end loop over object frames */
+
+  check_nomsg(sinfo_extract_frames_group_type(tot_set,&pro_set,
+                                              CPL_FRAME_GROUP_PRODUCT));
+  check_nomsg(sinfo_frameset_merge(*set,pro_set));
+  sinfo_free_frameset(&pro_set);
+  sinfo_free_frameset(&tot_set);
+  sinfo_free_frameset(&cdb_set);
+
+  return 0;
+
+ cleanup:
+  sinfo_free_image(&sky_ima);
+  sinfo_free_propertylist(&plist) ;
+  sinfo_free_frameset(&wrk_set);
+  sinfo_free_frameset(&pro_set);
+  sinfo_free_frameset(&cdb_set);
+  sinfo_free_frameset(&tot_set);
+  return -1;
+
+}
+
+
+int sinfo_new_sci_stk_frames(cpl_parameterlist* config,
+                                 cpl_frameset** set,
+                                 const char* recipe_id,
+                                 const char** pro_ctg_cube)
+{
+  char tag[FILE_NAME_SZ];
+  char pro_ctg_stack[FILE_NAME_SZ];
+  char outname[FILE_NAME_SZ];
+  char filename[FILE_NAME_SZ];
+
+
+  cpl_frameset * obj_set=NULL;
+  cpl_frameset * sky_set=NULL;
+  cpl_frameset * cdb_set=NULL;
+  cpl_frameset * wrk_set=NULL;
+  cpl_frameset * stk_set=NULL;
+  cpl_frameset * tot_set=NULL;
+  cpl_frame     * obj_frm=NULL;
+  cpl_frame    * sky_frm=NULL;
+  cpl_frame    * cdb_frm=NULL;
+  cpl_frame    * wrk_frm=NULL;
+  cpl_frame    * dup_frm=NULL;
+
+  int nsky=0;
+  int nobj=0;
+  int ncdb=0;
+  int ntot=0;
+  int nstk=0;
+
+  int i=0;
+  int j=0;
+  int k=0;
+  int aj_meth=0;
+
+
+  double mjd_obj=0;
+  double mjd_sky=0;
+  double mjd_sky_frm=0;
+  cpl_parameter* p=NULL;
+  fake* fk=sinfo_fake_new();
+
+  check_nomsg(obj_set=cpl_frameset_new());
+  check_nomsg(sky_set=cpl_frameset_new());
+  check_nomsg(cdb_set=cpl_frameset_new());
+
+  sinfo_extract_obj_frames(*set,obj_set);
+  sinfo_extract_sky_frames(*set,sky_set);
+  sinfo_extract_mst_frames(*set,cdb_set);
+
+
+  cknull(obj_frm = cpl_frameset_get_frame(obj_set,0),
+         "No object frames in input set.");
+
+  strcpy(tag,cpl_frame_get_tag(obj_frm));
+  if(NULL!=sinfo_new_set_obj_procatg(tag)){
+    *pro_ctg_cube=sinfo_new_set_obj_procatg(tag);
+  } else {
+    sinfo_msg_error("Frame tag %s not supported.",tag);
+    goto cleanup;
+  }
+
+
+  if(NULL!=sinfo_new_set_stk_procatg(tag)){
+    strcpy(pro_ctg_stack,sinfo_new_set_stk_procatg(tag));
+  } else {
+    sinfo_msg_error("Frame tag %s not supported.",tag);
+    goto cleanup;
+  }
+
+  nobj=cpl_frameset_get_size(obj_set);
+  nsky=cpl_frameset_get_size(sky_set);
+  ncdb=cpl_frameset_get_size(cdb_set);
+
+  if ((nobj==0) && (nsky==0)) {
+    sinfo_msg_error("Empty input set");
+    goto cleanup;
+  }
+
+
+  if ( (nobj != 0) && (nsky != 0) ) {
+    /* We have either OBJ and SKY: we need to create OBJ-SKY pairs */
+    sinfo_msg("------------------------------") ;
+    sinfo_msg("Generates OBJ-SKY pairs");
+    sinfo_msg("------------------------------") ;
+    check_nomsg(tot_set=cpl_frameset_new());
+    check_nomsg(p=cpl_parameterlist_find(config,
+                                         "sinfoni.objnod.autojitter_method"));
+    check_nomsg(cpl_parameter_set_int(p,0));
+    cpl_msg_warning(cpl_func , "******** 1 *********");
+
+
+    for (i=0;i<nobj;i++) {
+
+       check_nomsg(wrk_set=cpl_frameset_new());
+
+       check_nomsg(obj_frm=cpl_frameset_get_frame(obj_set,i));
+       mjd_obj=sinfo_get_mjd_obs(obj_frm);
+       check_nomsg(sky_frm=cpl_frameset_get_frame(sky_set,0));
+       mjd_sky=sinfo_get_mjd_obs(sky_frm);
+       strcpy(filename,cpl_frame_get_filename(obj_frm));
+
+
+       for (j=1;j<nsky;j++) {
+          check_nomsg(mjd_sky_frm=sinfo_get_mjd_obs(
+                                  cpl_frameset_get_frame(sky_set,j)));
+          if(1000.*(mjd_sky_frm-mjd_obj)*(mjd_sky_frm-mjd_obj) <
+             1000.*(mjd_sky-    mjd_obj)*(mjd_sky-    mjd_obj) ) {
+            mjd_sky=mjd_sky_frm;
+             check_nomsg(sky_frm=cpl_frameset_get_frame(sky_set,j));
+       }
+       }
+
+       strcpy(filename,cpl_frame_get_filename(sky_frm));
+
+
+
+       /* monitors whih obj-sky frames are inserted in each wrk_set */
+       check_nomsg(dup_frm=cpl_frame_duplicate(obj_frm));
+       check_nomsg(cpl_frameset_insert(wrk_set,dup_frm));
+       check_nomsg(dup_frm=cpl_frame_duplicate(sky_frm));
+       check_nomsg(cpl_frameset_insert(wrk_set,dup_frm));
+
+       /* merged CDB frames to work set */
+          for(k=0;k<ncdb;k++) {
+            check_nomsg(cdb_frm=cpl_frameset_get_frame(cdb_set,k));
+            check_nomsg(dup_frm=cpl_frame_duplicate(cdb_frm));
+        check_nomsg(cpl_frameset_insert(wrk_set,dup_frm));
+      }
+
+
+       /* defines a new name for the output stacked frame */
+       snprintf(outname,MAX_NAME_SIZE-1,"%s%d%s","out_stack",i,".fits");
+       ck0(sinfo_new_stack_frames(config,wrk_set,pro_ctg_stack,i,fk,recipe_id),
+     "Cannot stack frames");
+
+       check_nomsg(stk_set=cpl_frameset_new());
+       sinfo_contains_frames_kind(wrk_set,stk_set,PRO_STACKED);
+       nstk=cpl_frameset_get_size(stk_set);
+
+       for(k=0;k<nstk;k++) {
+         check_nomsg(wrk_frm=cpl_frameset_get_frame(stk_set,k));
+         check_nomsg(dup_frm = cpl_frame_duplicate(wrk_frm));
+     check_nomsg(cpl_frameset_insert(tot_set,dup_frm));
+       }
+       sinfo_free_frameset(&stk_set);
+       sinfo_free_frameset(&wrk_set);
+
+     }
+
+    ntot=cpl_frameset_get_size(tot_set);
+    for(k=0;k<ntot;k++) {
+      check_nomsg(wrk_frm=cpl_frameset_get_frame(tot_set,k));
+      check_nomsg(dup_frm=cpl_frame_duplicate(wrk_frm));
+      check_nomsg(cpl_frameset_insert(*set,dup_frm));
+    }
+    sinfo_free_frameset(&tot_set);
+
+  }
+
+ if ( (nobj == 0) && (nsky != 0) ) {
+
+     /* ===============================================================
+        SKY FRAMES STACKING
+        =============================================================== */
+
+    {
+    sinfo_msg("------------------------------") ;
+    sinfo_msg("SKY ONLY FRAMES DATA REDUCTION NOT SUPPORTED") ;
+    sinfo_msg("------------------------------") ;
+        goto cleanup;
+    }
+
+  }
+
+
+
+  if ( (nobj != 0) && (nsky == 0) ) {
+
+     /* ===============================================================
+        OBJ FRAMES STACKING
+        =============================================================== */
+    check_nomsg(p = cpl_parameterlist_find(config,
+                                           "sinfoni.objnod.autojitter_method"));
+    check_nomsg(aj_meth =  cpl_parameter_get_int(p));
+    if(strcmp(pro_ctg_stack,PRO_PUPIL_LAMP_STACKED) == 0) {
+
+      aj_meth = 0;
+
+    }
+
+    if(aj_meth == 2) {
+
+      sinfo_msg("Dummy sky case");
+      sinfo_msg("Fake sky is coming from median of all objects");
+      cknull(sky_frm = sinfo_new_get_dummy_sky(obj_set),
+         "Problem to get dummy frame");
+
+      sinfo_msg("------------------------------") ;
+      sinfo_msg("Generates OBJ-SKY pairs");
+      sinfo_msg("------------------------------") ;
+      check_nomsg(tot_set=cpl_frameset_new());
+
+
+
+      for (i=0;i<nobj;i++) {
+
+    check_nomsg(wrk_set=cpl_frameset_new());
+    check_nomsg(obj_frm=cpl_frameset_get_frame(obj_set,i));
+        check_nomsg(dup_frm=cpl_frame_duplicate(obj_frm));
+    check_nomsg(cpl_frameset_insert(wrk_set,dup_frm));
+        check_nomsg(dup_frm=cpl_frame_duplicate(sky_frm));
+    check_nomsg(cpl_frameset_insert(wrk_set,dup_frm));
+    for(k=0;k<ncdb;k++) {
+      check_nomsg(cdb_frm=cpl_frameset_get_frame(cdb_set,k));
+          check_nomsg(dup_frm=cpl_frame_duplicate(cdb_frm));
+      check_nomsg(cpl_frameset_insert(wrk_set,dup_frm));
+    }
+
+    snprintf(outname,MAX_NAME_SIZE-1,"%s%d%s","out_stack",i,".fits");
+        ck0(sinfo_new_stack_frames(config,wrk_set,pro_ctg_stack,
+                                   i,fk,recipe_id),
+                                   "Error Stacking frame %d",i);
+
+    check_nomsg(stk_set=cpl_frameset_new());
+    sinfo_contains_frames_kind(wrk_set,stk_set,PRO_STACKED);
+    nstk=cpl_frameset_get_size(stk_set);
+    for(k=0;k<nstk;k++) {
+      check_nomsg(wrk_frm=cpl_frameset_get_frame(stk_set,k));
+          check_nomsg(dup_frm=cpl_frame_duplicate(wrk_frm));
+      check_nomsg(cpl_frameset_insert(tot_set,dup_frm));
+    }
+        sinfo_free_frameset(&stk_set);
+        sinfo_free_frameset(&wrk_set);
+
+      }
+      check_nomsg(ntot=cpl_frameset_get_size(tot_set));
+      for(k=0;k<ntot;k++) {
+    check_nomsg(wrk_frm=cpl_frameset_get_frame(tot_set,k));
+        check_nomsg(dup_frm=cpl_frame_duplicate(wrk_frm));
+    check_nomsg(cpl_frameset_insert(*set,dup_frm));
+      }
+      sinfo_free_frameset(&tot_set);
+      sinfo_free_frame(&sky_frm);
+
+    } else if(aj_meth == 1 ) {
+
+      sinfo_msg("Dummy obj-sky case");
+      sinfo_msg("Fake sky is coming from each next object");
+
+    if(nobj > 1) {
+      fk->is_fake_sky=1;
+      ck0(sinfo_new_get_dummy_obj_sky_stacked(obj_set,&(*set),config,
+					      fk,pro_ctg_stack,recipe_id),
+	  "Found error to get obj-sky-stacked frame");
+    } else {
+      sinfo_msg("Only one object frame, no sky");
+          ck0(sinfo_new_stack_frames(config,*set,pro_ctg_stack,0,fk,recipe_id),
+              "Error stacking frame");
+    }
+
+    } else {
+
+      sinfo_msg("------------------------------") ;
+      sinfo_msg("staks each OBJECT ");
+      sinfo_msg("------------------------------") ;
+      tot_set=cpl_frameset_new();
+
+      for (i=0;i<nobj;i++) {
+
+    check_nomsg(wrk_set=cpl_frameset_new());
+    check_nomsg(obj_frm=cpl_frameset_get_frame(obj_set,i));
+        check_nomsg(dup_frm=cpl_frame_duplicate(obj_frm));
+    check_nomsg(cpl_frameset_insert(wrk_set,dup_frm));
+    for(k=0;k<ncdb;k++) {
+      check_nomsg(cdb_frm=cpl_frameset_get_frame(cdb_set,k));
+          check_nomsg(dup_frm=cpl_frame_duplicate(cdb_frm));
+      check_nomsg(cpl_frameset_insert(wrk_set,dup_frm));
+    }
+
+
+    snprintf(outname,MAX_NAME_SIZE-1,"%s%d%s","out_stack",i,".fits");
+        ck0(sinfo_new_stack_frames(config,wrk_set,pro_ctg_stack,
+                                   i,fk,recipe_id),"Error stacking frame %d",i);
+
+    check_nomsg(stk_set=cpl_frameset_new());
+    sinfo_contains_frames_kind(wrk_set,stk_set,PRO_STACKED);
+    check_nomsg(nstk=cpl_frameset_get_size(stk_set));
+    for(k=0;k<nstk;k++) {
+      check_nomsg(wrk_frm=cpl_frameset_get_frame(stk_set,k));
+      check_nomsg(dup_frm=cpl_frame_duplicate(wrk_frm));
+      check_nomsg(cpl_frameset_insert(tot_set,dup_frm));
+    }
+        sinfo_free_frameset(&stk_set);
+        sinfo_free_frameset(&wrk_set);
+
+      }
+
+      check_nomsg(ntot=cpl_frameset_get_size(tot_set));
+      for(k=0;k<ntot;k++) {
+    check_nomsg(wrk_frm=cpl_frameset_get_frame(tot_set,k));
+    check_nomsg(dup_frm=cpl_frame_duplicate(wrk_frm));
+    check_nomsg(cpl_frameset_insert(*set,dup_frm));
+      }
+      sinfo_free_frameset(&tot_set);
+    }
+  }
+
+  sinfo_free_frameset(&obj_set);
+  sinfo_free_frameset(&sky_set);
+  sinfo_free_frameset(&cdb_set);
+  sinfo_fake_delete(&fk);
+
+  return 0;
+
+
+
+ cleanup:
+
+    sinfo_free_frame(&sky_frm);
+    sinfo_free_frameset(&wrk_set);
+    sinfo_free_frameset(&tot_set);
+    sinfo_free_frameset(&obj_set);
+    sinfo_free_frameset(&sky_set);
+    sinfo_free_frameset(&cdb_set);
+    sinfo_fake_delete(&fk);
+    return -1;
+
+}
+
+
+
+
+
+
+
+int sinfo_cub_stk_frames(cpl_parameterlist* config,
+                                 cpl_frameset** set,
+                                 const char* recipe_id,
+                                 const char** pro_ctg_cube)
+{
+  cpl_frame     * obj_frm=NULL;
+  char tag[FILE_NAME_SZ];
+  char pro_ctg_stack[FILE_NAME_SZ];
+  char outname[FILE_NAME_SZ];
+  char filename[FILE_NAME_SZ];
+
+
+  cpl_frameset * obj_set=NULL;
+  cpl_frameset * sky_set=NULL;
+  cpl_frameset * cdb_set=NULL;
+  cpl_frameset * wrk_set=NULL;
+  cpl_frameset * tot_set=NULL;
+  cpl_frameset * pro_set=NULL;
+  cpl_frame    * sky_frm=NULL;
+  cpl_frame    * cdb_frm=NULL;
+  cpl_frame    * dup_frm=NULL;
+
+  int nsky=0;
+  int nobj=0;
+  int ncdb=0;
+
+  int i=0;
+  int j=0;
+  int k=0;
+  int aj_meth=0;
+  int ind=0;
+
+  double mjd_obj=0;
+  double mjd_sky=0;
+  double mjd_sky_frm=0;
+  cpl_parameter* p=NULL;
+  fake* fk=sinfo_fake_new();
+
+  obj_set=cpl_frameset_new();
+  sky_set=cpl_frameset_new();
+  cdb_set=cpl_frameset_new();
+
+  sinfo_extract_obj_frames(*set,obj_set);
+  sinfo_extract_sky_frames(*set,sky_set);
+  sinfo_extract_mst_frames(*set,cdb_set);
+
+  cknull(obj_frm = cpl_frameset_get_frame(obj_set,0),
+         "No object frames in input set.");
+
+
+  strcpy(tag,cpl_frame_get_tag(obj_frm));
+  if(NULL!=sinfo_new_set_obj_procatg(tag)){
+    *pro_ctg_cube=sinfo_new_set_obj_procatg(tag);
+  } else {
+    sinfo_msg_error("Frame tag %s not supported.",tag);
+    goto cleanup;
+  }
+
+
+  if(NULL!=sinfo_new_set_stk_procatg(tag)){
+    strcpy(pro_ctg_stack,sinfo_new_set_stk_procatg(tag));
+  } else {
+    sinfo_msg_error("Frame tag %s not supported.",tag);
+    goto cleanup;
+  }
+
+  nobj=cpl_frameset_get_size(obj_set);
+  nsky=cpl_frameset_get_size(sky_set);
+  ncdb=cpl_frameset_get_size(cdb_set);
+
+  if ((nobj==0) && (nsky==0)) {
+    sinfo_msg_error("Empty input set");
+    goto cleanup;
+  }
+
+
+  if ( (nobj != 0) && (nsky != 0) ) {
+    /* We have either OBJ and SKY: we need to create OBJ-SKY pairs */
+    sinfo_msg("------------------------------") ;
+    sinfo_msg("Generates OBJ-SKY pairs");
+    sinfo_msg("------------------------------") ;
+
+    check_nomsg(tot_set=cpl_frameset_new());
+    check_nomsg(p = cpl_parameterlist_find(config,
+                                           "sinfoni.objnod.autojitter_method"));
+    check_nomsg(cpl_parameter_set_int(p,0));
+
+    for (i=0;i<nobj;i++) {
+
+       cknull_nomsg(wrk_set=cpl_frameset_new());
+       check_nomsg(obj_frm=cpl_frameset_get_frame(obj_set,i));
+       mjd_obj=sinfo_get_mjd_obs(obj_frm);
+       check_nomsg(sky_frm=cpl_frameset_get_frame(sky_set,0));
+       mjd_sky=sinfo_get_mjd_obs(sky_frm);
+       strcpy(filename,cpl_frame_get_filename(obj_frm));
+
+
+       for (j=1;j<nsky;j++) {
+          mjd_sky_frm = sinfo_get_mjd_obs(cpl_frameset_get_frame(sky_set,j));
+          if(1000.*(mjd_sky_frm-mjd_obj)*(mjd_sky_frm-mjd_obj) <
+             1000.*(mjd_sky-    mjd_obj)*(mjd_sky-    mjd_obj) ) {
+            mjd_sky=mjd_sky_frm;
+             check_nomsg(sky_frm=cpl_frameset_get_frame(sky_set,j));
+       }
+       }
+       strcpy(filename,cpl_frame_get_filename(sky_frm));
+
+
+
+       /* monitors whih obj-sky frames are inserted in each wrk_set */
+       cknull_nomsg(dup_frm=cpl_frame_duplicate(obj_frm));
+       check_nomsg(cpl_frameset_insert(wrk_set,dup_frm));
+       cknull_nomsg(dup_frm=cpl_frame_duplicate(sky_frm));
+       check_nomsg(cpl_frameset_insert(wrk_set,dup_frm));
+
+       /* merged CDB frames to work set */
+          for(k=0;k<ncdb;k++) {
+            check_nomsg(cdb_frm=cpl_frameset_get_frame(cdb_set,k));
+            check_nomsg(dup_frm=cpl_frame_duplicate(cdb_frm));
+        check_nomsg(cpl_frameset_insert(wrk_set,dup_frm));
+      }
+
+
+       /* defines a new name for the output stacked frame */
+       snprintf(outname,MAX_NAME_SIZE-1,"%s%d%s","out_stack",i,".fits");
+       ck0(sinfo_new_stack_frames(config,wrk_set,pro_ctg_stack,i,fk,recipe_id),
+       "Cannot stack frames");
+
+       /* cube generation */
+       ck0(ind=sinfo_new_cubes_build(recipe_id,config,wrk_set,
+                     *pro_ctg_cube,i),
+       "GENERATING CUBE no. %d\n", ind) ;
+
+       check_nomsg(sinfo_extract_frames_group_type(wrk_set,
+                                                   &pro_set,
+                                                   CPL_FRAME_GROUP_PRODUCT));
+       check_nomsg(sinfo_frameset_merge(tot_set,pro_set));
+       sinfo_free_frameset(&pro_set);
+       sinfo_free_frameset(&wrk_set);
+
+
+    }
+
+    check_nomsg(sinfo_extract_frames_group_type(tot_set,
+                                                &pro_set,
+                                                CPL_FRAME_GROUP_PRODUCT));
+    check_nomsg(sinfo_frameset_merge(*set,pro_set));
+    sinfo_free_frameset(&pro_set);
+    sinfo_free_frameset(&tot_set);
+
+  }
+
+
+ if ( (nobj == 0) && (nsky != 0) ) {
+
+     /* ===============================================================
+        SKY FRAMES STACKING
+        =============================================================== */
+
+    {
+    sinfo_msg("------------------------------") ;
+    sinfo_msg("SKY ONLY FRAMES DATA REDUCTION NOT SUPPORTED") ;
+    sinfo_msg("------------------------------") ;
+        goto cleanup;
+    }
+
+
+  }
+
+
+
+  if ( (nobj != 0) && (nsky == 0) ) {
+
+     /* ===============================================================
+        OBJ FRAMES STACKING
+        =============================================================== */
+      check_nomsg(p=cpl_parameterlist_find(config,
+                                           "sinfoni.objnod.autojitter_method"));
+      check_nomsg(aj_meth =  cpl_parameter_get_int(p));
+      if(strcmp(pro_ctg_stack,PRO_PUPIL_LAMP_STACKED) == 0) {
+
+    aj_meth = 0;
+
+      }
+
+    if(aj_meth == 2) {
+
+      sinfo_msg("Dummy sky case");
+      sinfo_msg("Fake sky is coming from median of all objects");
+      if( (sky_frm = sinfo_new_get_dummy_sky(obj_set)) == NULL) {
+
+     sinfo_msg_error("Problem to get dummy frame");
+
+    return -1;
+
+      }
+      sinfo_msg("------------------------------") ;
+      sinfo_msg("Generates OBJ-SKY pairs");
+      sinfo_msg("------------------------------") ;
+
+      check_nomsg(tot_set=cpl_frameset_new());
+
+
+      for (i=0;i<nobj;i++) {
+
+    check_nomsg(wrk_set=cpl_frameset_new());
+    check_nomsg(obj_frm=cpl_frameset_get_frame(obj_set,i));
+        check_nomsg(dup_frm=cpl_frame_duplicate(obj_frm));
+    check_nomsg(cpl_frameset_insert(wrk_set,dup_frm));
+        check_nomsg(dup_frm=cpl_frame_duplicate(sky_frm));
+    check_nomsg(cpl_frameset_insert(wrk_set,dup_frm));
+    for(k=0;k<ncdb;k++) {
+      check_nomsg(cdb_frm=cpl_frameset_get_frame(cdb_set,k));
+          check_nomsg(dup_frm=cpl_frame_duplicate(cdb_frm));
+      check_nomsg(cpl_frameset_insert(wrk_set,dup_frm));
+    }
+
+    snprintf(outname,MAX_NAME_SIZE-1,"%s%d%s","out_stack",i,".fits");
+        ck0(sinfo_new_stack_frames(config,wrk_set,pro_ctg_stack,
+                                   i,fk,recipe_id),"Error Stacking frame %d",i);
+
+
+        /* cube generation */
+        ck0(ind=sinfo_new_cubes_build(recipe_id,config,wrk_set,
+                      *pro_ctg_cube,i),
+        "Error GENERATING CUBE no. %d\n", ind) ;
+
+
+
+
+        check_nomsg(sinfo_extract_frames_group_type(wrk_set,
+                                                    &pro_set,
+                                                    CPL_FRAME_GROUP_PRODUCT));
+        check_nomsg(sinfo_frameset_merge(tot_set,pro_set));
+        sinfo_free_frameset(&pro_set);
+        sinfo_free_frameset(&wrk_set);
+
+
+      }
+      check_nomsg(sinfo_extract_frames_group_type(tot_set,
+                                                  &pro_set,
+                                                  CPL_FRAME_GROUP_PRODUCT));
+      check_nomsg(sinfo_frameset_merge(*set,pro_set));
+      sinfo_free_frameset(&pro_set);
+      sinfo_free_frameset(&tot_set);
+      sinfo_free_frame(&sky_frm);
+    } else if(aj_meth == 1 ) {
+
+
+        sinfo_msg("Dummy obj-sky case");
+        sinfo_msg("Fake sky is coming from each next object");
+
+    if(nobj > 1) {
+      fk->is_fake_sky=1;
+      ck0(sinfo_get_dummy_obj_sky_stacked_and_cubes(obj_set,&(*set),config,
+                          fk,pro_ctg_stack,recipe_id),
+         "Found error to get obj-sky-stacked frame");
+
+    } else {
+      sinfo_msg("Only one object frame, no sky");
+      check_nomsg(p=cpl_parameterlist_find(config,
+            "sinfoni.sinfo_utl_skycor.rot_cor"));
+      check_nomsg(cpl_parameter_set_bool(p,FALSE));
+
+          ck0(sinfo_new_stack_frames(config,*set,pro_ctg_stack,0,fk,recipe_id),
+              "Error stacking frame");
+
+      /* cube generation */
+      sinfo_msg("------------------------------") ;
+      sinfo_msg("BUILDING CUBE %d",i);
+      sinfo_msg("------------------------------") ;
+      ck0(sinfo_new_cubes_build(recipe_id,config,*set,*pro_ctg_cube,i),
+          "Error GENERATING CUBE %d", i) ;
+
+      sinfo_msg("------------------------------") ;
+      sinfo_msg("BUILT CUBE %d",i);
+      sinfo_msg("------------------------------") ;
+
+    }
+
+    } else { /* aj_meth == 0 */
+
+      sinfo_msg("------------------------------") ;
+      sinfo_msg("staks each OBJECT ");
+      sinfo_msg("------------------------------") ;
+      check_nomsg(tot_set=cpl_frameset_new());
+
+      for (i=0;i<nobj;i++) {
+
+    check_nomsg(wrk_set=cpl_frameset_new());
+    check_nomsg(obj_frm=cpl_frameset_get_frame(obj_set,i));
+        check_nomsg(dup_frm=cpl_frame_duplicate(obj_frm));
+    check_nomsg(cpl_frameset_insert(wrk_set,dup_frm));
+    for(k=0;k<ncdb;k++) {
+      check_nomsg(cdb_frm=cpl_frameset_get_frame(cdb_set,k));
+          check_nomsg(dup_frm=cpl_frame_duplicate(cdb_frm));
+      check_nomsg(cpl_frameset_insert(wrk_set,dup_frm));
+    }
+
+
+    snprintf(outname,MAX_NAME_SIZE-1,"%s%d%s","out_stack",i,".fits");
+        ck0(sinfo_new_stack_frames(config,wrk_set,pro_ctg_stack,
+                                   i,fk,recipe_id),"Error stacking frame %d",i);
+
+
+        /* cube generation */
+      sinfo_msg("------------------------------") ;
+      sinfo_msg("BUILDING CUBE %d",i);
+      sinfo_msg("------------------------------") ;
+        ck0(ind=sinfo_new_cubes_build(recipe_id,config,wrk_set,
+                      *pro_ctg_cube,i),
+        "Error GENERATING CUBE no. %d\n", ind) ;
+
+      sinfo_msg("------------------------------") ;
+      sinfo_msg("BUILT CUBE %d",i);
+      sinfo_msg("------------------------------") ;
+        check_nomsg(sinfo_extract_frames_group_type(wrk_set,
+                                                    &pro_set,
+                                                    CPL_FRAME_GROUP_PRODUCT));
+        check_nomsg(sinfo_frameset_merge(tot_set,pro_set));
+        sinfo_free_frameset(&pro_set);
+        sinfo_free_frameset(&wrk_set);
+
+
+      }
+
+
+     check_nomsg(sinfo_extract_frames_group_type(tot_set,
+                                                 &pro_set,
+                                                 CPL_FRAME_GROUP_PRODUCT));
+     check_nomsg(sinfo_frameset_merge(*set,pro_set));
+     sinfo_free_frameset(&pro_set);
+     sinfo_free_frameset(&tot_set);
+
+    }
+  }
+  sinfo_free_frameset(&obj_set);
+  sinfo_free_frameset(&sky_set);
+  sinfo_free_frameset(&cdb_set);
+  sinfo_fake_delete(&fk);
+
+  return 0;
+
+ cleanup:
+
+    sinfo_free_frameset(&wrk_set);
+    sinfo_free_frameset(&tot_set);
+    sinfo_free_frameset(&obj_set);
+    sinfo_free_frameset(&sky_set);
+    sinfo_free_frameset(&cdb_set);
+    sinfo_fake_delete(&fk);
+    return -1;
+
+
+}
+
+
+
+static const char* sinfo_new_set_stk_procatg(const char* tag)
+{
+
+  const char* pro_ctg_stack=NULL;
+
+  if(strstr(tag,"OBJ") != NULL) {
+    pro_ctg_stack=PRO_OBJECT_NODDING_STACKED;
+  } else if(strstr(tag,"PSF") != NULL) {
+    pro_ctg_stack=PRO_PSF_CALIBRATOR_STACKED;
+  } else if(strstr(tag,"STD") != NULL) {
+    pro_ctg_stack=PRO_STD_NODDING_STACKED;
+  } else if(strstr(tag,"PUPIL") != NULL) {
+    pro_ctg_stack=PRO_PUPIL_LAMP_STACKED;
+  } else {
+    sinfo_msg_error("frame tag %s not supported",tag);
+    return NULL;
+  }
+
+  return pro_ctg_stack;
+
+}
+const char* sinfo_new_set_obj_procatg(const char* tag)
+{
+  const char* pro_ctg_cube=NULL;
+
+  if(strstr(tag,"OBJ") != NULL) {
+    pro_ctg_cube=PRO_COADD_OBJ;
+  } else if(strstr(tag,"PSF") != NULL) {
+    pro_ctg_cube=PRO_COADD_PSF;
+  } else if(strstr(tag,"STD") != NULL) {
+    pro_ctg_cube=PRO_COADD_STD;
+  } else if(strstr(tag,"PUPIL") != NULL) {
+    pro_ctg_cube=PRO_COADD_PUPIL;
+  } else {
+    sinfo_msg_error("frame tag %s not supported",tag);
+    return NULL;
+  }
+
+  return pro_ctg_cube;
+
+}
+
+/*
+static int
+sinfo_get_obj_sky_frm_pair(
+cpl_frameset** obj_set,
+const int i,
+cpl_frame** obj_frm,
+cpl_frame** sky_frm)
+{
+  double mjd_obj=0;
+  double mjd_sky_inf=0;
+  double mjd_sky_sup=0;
+
+
+  double obj_cumx=0;
+  double obj_cumy=0;
+
+  double sky_sup_cumx=0;
+  double sky_sup_cumy=0;
+
+  double sky_inf_cumx=0;
+  double sky_inf_cumy=0;
+  double cum_thres=0.5;
+  int nobj=0;
+  cpl_frame* sky_frm_inf=NULL;
+  cpl_frame* sky_frm_sup=NULL;
+
+  check_nomsg(*obj_frm=cpl_frameset_get_frame(*obj_set,i));
+  mjd_obj    = sinfo_get_mjd_obs(*obj_frm);
+  obj_cumx=sinfo_get_cumoffsetx(*obj_frm);
+  obj_cumy=sinfo_get_cumoffsety(*obj_frm);
+
+  if(i>0) {
+    check_nomsg(sky_frm_inf=cpl_frameset_get_frame(*obj_set,i-1));
+    mjd_sky_inf = sinfo_get_mjd_obs(sky_frm_inf);
+    sky_inf_cumx=sinfo_get_cumoffsetx(sky_frm_inf);
+    sky_inf_cumy=sinfo_get_cumoffsety(sky_frm_inf);
+  }
+
+  if(i<nobj-1) {
+    check_nomsg(sky_frm_sup=cpl_frameset_get_frame(*obj_set,i+1));
+    mjd_sky_sup = sinfo_get_mjd_obs(sky_frm_sup);
+    sky_sup_cumx=sinfo_get_cumoffsetx(sky_frm_sup);
+    sky_sup_cumy=sinfo_get_cumoffsety(sky_frm_sup);
+  }
+
+  if(i==0) {
+    *sky_frm = sky_frm_sup;
+  } else if(i==(nobj-1)) {
+    *sky_frm = sky_frm_inf;
+  } else {
+       if( fabs( mjd_sky_inf - mjd_obj ) <
+           fabs( mjd_sky_sup - mjd_obj ) ) {
+         if((fabs(sky_inf_cumx-obj_cumx) > cum_thres) ||
+            (fabs(sky_inf_cumy-obj_cumy) > cum_thres)) {
+       *sky_frm = sky_frm_inf;
+     } else {
+       *sky_frm = sky_frm_sup;
+     }
+       } else {
+         if((fabs(sky_sup_cumx-obj_cumx) > cum_thres) ||
+            (fabs(sky_sup_cumy-obj_cumy) > cum_thres)) {
+       *sky_frm = sky_frm_sup;
+     } else {
+       *sky_frm = sky_frm_inf;
+     }
+       }
+  }
+  return 0;
+
+ cleanup:
+  return -1;
+
+}
+*/
+/**@}*/
diff --git a/sinfoni/sinfo_rec_utils.h b/sinfoni/sinfo_rec_utils.h
new file mode 100644
index 0000000..807a08b
--- /dev/null
+++ b/sinfoni/sinfo_rec_utils.h
@@ -0,0 +1,108 @@
+#ifndef SINFO_REC_UTILS_H
+#define SINFO_REC_UTILS_H
+
+/* $Id: sinfo_rec_utils.h,v 1.2 2007/06/06 07:10:45 amodigli Exp $
+ *
+ * This file is part of the CPL (Common Pipeline Library)
+ * Copyright (C) 2002 European Southern Observatory
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*
+ * $Author: amodigli $
+ * $Date: 2007/06/06 07:10:45 $
+ * $Revision: 1.2 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+ /****************************************************************
+  *           Object Data reduction                              *
+  ****************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>          /* allows the program compilation */
+#endif
+
+/*-----------------------------------------------------------------------------
+                                Includes
+-----------------------------------------------------------------------------*/
+
+/* std */
+#include <strings.h>
+#include <string.h>
+#include <stdio.h>
+#include <math.h>
+#include <libgen.h>
+
+/* cpl */
+#include <cpl.h>  
+
+/* sinfoni */
+#include <sinfo_pro_types.h>
+#include <sinfo_key_names.h>
+#include <sinfo_raw_types.h>
+#include <sinfo_globals.h>
+#include <sinfo_new_prepare_stacked_frames.h>
+#include <sinfo_functions.h>
+
+
+/*-----------------------------------------------------------------------------
+                            Functions prototypes
+ ----------------------------------------------------------------------------*/
+
+
+int 
+sinfo_new_get_dummy_obj_sky_stacked(cpl_frameset* obj_set,
+                                    cpl_frameset** set, 
+                                    cpl_parameterlist* config,
+                                    fake* fk,
+                                    char* pro_ctg, 
+                                    const char* plugin_id);
+
+cpl_frame* 
+sinfo_new_get_dummy_sky(cpl_frameset* obj_set);
+
+int 
+sinfo_new_sci_stk_frames(cpl_parameterlist* config,
+                         cpl_frameset** set,
+                         const char* recipe_id,
+             const char** pro_ctg_cube);
+
+int 
+sinfo_cub_stk_frames(cpl_parameterlist* config,
+                     cpl_frameset** set,
+                     const char* recipe_id,
+             const char** pro_ctg_cube);
+
+
+int
+sinfo_new_stack_frames(cpl_parameterlist* cfg, 
+                       cpl_frameset* set, 
+                       const char* procatg,
+                       const int id, 
+                       fake* fk, 
+                       const char* plugin_id);
+
+const char* 
+sinfo_new_set_obj_procatg(const char* tag);
+
+int
+sinfo_get_dummy_obj_sky_stacked_and_cubes(cpl_frameset* obj_set,
+                                          cpl_frameset** set, 
+                                          cpl_parameterlist* config,
+                                          fake* fk, 
+                                          char* pro_ctg, 
+                                          const char* plugin_id);
+#endif /*!SI_REC_UTILS*/
diff --git a/sinfoni/sinfo_recipes.c b/sinfoni/sinfo_recipes.c
new file mode 100644
index 0000000..dfb4962
--- /dev/null
+++ b/sinfoni/sinfo_recipes.c
@@ -0,0 +1,1516 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/***************************************************************************
+* E.S.O. - VLT project
+*
+*
+*
+* who       when      what
+* --------  --------  ----------------------------------------------
+* schreib  05/06/00  created
+*/
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#include "sinfo_vltPort.h"
+
+/*
+ * System Headers
+ */
+
+/*
+ * Local Headers
+ */
+
+#include "sinfo_recipes.h"
+#include "sinfo_globals.h"
+
+/*----------------------------------------------------------------------------
+ *                                    Local variables
+ *--------------------------------------------------------------------------*/
+
+static float  sqrarg ;
+
+static double chi1 ;                    /* old reduced chi-squared */
+static double sinfo_chi2 ;                    /* new reduced chi-squared */
+static double labda ;                   /* mixing parameter */
+static double vec[MAXPAR] ;             /* correction sinfo_vector */
+static double matrix1[MAXPAR][MAXPAR] ; /* original sinfo_matrix */
+static double matrix2[MAXPAR][MAXPAR] ; /* inverse of matrix1 */
+static int    nfree ;                   /* number of free parameters */
+static int    parptr[MAXPAR] ;          /* parameter pointer */
+
+/*----------------------------------------------------------------------------
+ *                                 Defines
+ *--------------------------------------------------------------------------*/
+
+#define SQR(a) (sqrarg = (a) , sqrarg*sqrarg)
+
+/*----------------------------------------------------------------------------
+ *                    Functions private to this module
+ *--------------------------------------------------------------------------*/
+
+
+static int new_inv_mat (void) ;
+
+static void new_get_mat ( float  * xdat,
+                     int    * xdim,
+                     float  * ydat,
+                     float  * wdat,
+                     int    * ndat,
+                     float  * fpar,
+                     float  * epar/*,
+                     int    * npar */) ;
+
+static int new_get_vec ( float  * xdat,
+                    int    * xdim,
+                    float  * ydat,
+                    float  * wdat,
+                    int    * ndat,
+                    float  * fpar,
+                    float  * epar,
+                    int    * npar ) ;
+
+static float 
+new_gaussian ( float * xdat, float * parlist/*, int * npar*/ );
+static void 
+new_gaussian_deriv( float * xdat, float * parlist, 
+                    float * dervs/*, int * npar*/ );
+
+
+
+/**@{*/
+/**
+ * @addtogroup sinfo_recipes Recipe utilities
+ *
+ * TBD
+ */
+
+/*----------------------------------------------------------------------------
+ *                            Function codes
+ *--------------------------------------------------------------------------*/
+
+
+float sinfo_new_f_median(float * array, int n)
+{
+ pixelvalue p_array[100];
+ int i;
+ 
+ for (i=0;i<n;i++)
+     p_array[i]= (pixelvalue) array[i];
+
+ return (float) sinfo_new_median(p_array, n);
+}
+
+
+/**
+ at brief his routine computes the clean mean of a given data
+   @name sinfo_new_clean_mean()
+   @param array: data array to average
+   @param n_elements: number of elements of the data array
+   @param throwaway_low: percentage of low value elements to be 
+                         thrown away before averaging
+   @param throwaway_high: percentage of high value elements to be 
+                          thrown away before averaging
+   @return the clean mean of a data array
+                        FLT_MAX in case of error 
+   @doc
+   this routine computes the clean mean of a given data array that means the 
+   array is first sorted and a given percentage of the lowest and the 
+   highest values is not considered for averaging
+ */
+float sinfo_new_clean_mean( float * array, 
+                  int     n_elements,
+                  float   throwaway_low,
+                  float   throwaway_high )
+{
+    int i, n ;
+    int lo_n, hi_n ;
+    float sum ;
+    
+    if ( array == NULL )
+    {
+        sinfo_msg_error(" no array given in sinfo_clean_mean!") ;
+        return FLT_MAX ;
+    }
+  
+    if ( n_elements <= 0 )
+    {
+        sinfo_msg_error("wrong number of elements given") ;
+        return FLT_MAX ;
+    }
+
+    if ( throwaway_low < 0. || throwaway_high < 0. ||
+         throwaway_low + throwaway_high >= 100. )
+    {
+        sinfo_msg_error("wrong throw away percentage given!") ;
+        return FLT_MAX ;
+    }
+
+    lo_n = (int) (throwaway_low * (float)n_elements / 100.) ;
+    hi_n = (int) (throwaway_high * (float)n_elements / 100.) ;
+
+    /* sort the array */
+    sinfo_pixel_qsort( array, n_elements ) ;
+
+    n = 0 ;
+    sum = 0. ;
+    for ( i = lo_n ; i < n_elements - hi_n ; i++ )
+    {
+        if ( !isnan(array[i]) )
+        {
+            sum += array[i] ;
+            n++ ;
+        }
+    }
+    if ( n == 0 )  
+    {
+        return FLAG ;
+    }
+    else
+    {
+        return sum/(float)n ;
+    }
+}
+
+/*--------------------------------------------------------------------------*/
+/**
+ at brief sorts an array into ascending numerical order
+ at name sinfo_new_median()
+ at param array array of pixelvalues starting at index 0,
+ at param n number of array elements
+ at return median of pixelvalues
+ at doc
+       sorts an array into ascending numerical order by 
+       using sinfo_pixel_qsort(), and derives the sinfo_median depending
+       on an odd or even number of array elements 
+ */
+
+pixelvalue sinfo_new_median(pixelvalue * array, int n)
+{
+    pixelvalue med ;
+    
+    if ( array == NULL || n <= 0 )
+    {
+        sinfo_msg_warning("nothing in the pixelvalue array, ZERO returned");
+        return ZERO ;
+    }
+    
+    if ( n == 1 )
+    {
+        return array[0] ;
+    }
+ 
+    sinfo_pixel_qsort((float*) array, n) ;
+    if ( n % 2 == 1 )
+    {
+        med = array[n/2] ;
+    }
+    else
+    {
+        med = (array[n/2] + array[n/2 - 1])/2. ;
+    }
+    return med ;
+}
+
+
+
+
+
+/**
+ at brief Least square fit of a function to a set of data points
+ at name sinfo_new_lsqfit_c()
+ at param xdat: position, coordinates of data points.
+                              xdat is 2 dimensional: XDAT ( XDIM, NDAT )
+ at param xdim: dimension of fit
+ at param ydat: data points
+ at param wdat: weights for data points
+ at param ndat: number of data points
+ at param fpar: on input contains initial estimates of the 
+                              parameters for non-linear fits, on output the
+                              fitted parameters.
+ at param epar: contains estimates of the errors in fitted parameters
+ at param mpar: logical mask telling which parameters are free (non-zero)
+                              and which parameters are fixed (0)
+ at param npar: number of function parameters ( free + fixed )
+ at param tol:  relative tolerance. sinfo_lsqfit stops when successive iterations
+             fail to produce a decrement in reduced chi-squared less
+             than tol. If tol is less than the minimum tolerance 
+             possible, tol will be set to this value. This means
+             that maximum accuracy can be obtained by setting
+             tol = 0.0.
+ at param its:  maximum number of iterations
+ at param lab:  mixing parameter, lab determines the initial weight
+             of steepest descent method relative to the Taylor method
+             lab should be a small value (i.e. 0.01). lab can only
+             be zero when the partial derivatives are independent
+             of the parameters. In fact in this case lab should be
+             exactly equal to zero.
+ @return returns number of iterations needed to achieve convergence
+         according to tol. When this number is negative, the fitting
+         was not continued because a fatal error occurred:
+#        -1 too many free parameters, maximum is 32
+#        -2 no free parameters
+#        -3 not enough degrees of freedom
+#        -4 maximum number of iterations too small to obtain
+#        a solution which satisfies tol.
+#        -5 diagonal of sinfo_matrix contains elements which are zero
+#        -6 determinant of the coefficient sinfo_matrix is zero
+#        -7 square root of a negative number 
+ at doc     this is a routine for making a least-squares fit of a
+         function to a set of data points. The method used is
+         described in: Marquardt, J.Soc.Ind.Appl.Math. 11. 431 (1963).
+         This method is a mixture of the steepest descent method 
+         and the Taylor method.
+ */
+
+int sinfo_new_lsqfit_c ( float * xdat,
+               int   * xdim,
+               float * ydat,
+               float * wdat,
+               int   * ndat,
+               float * fpar,
+               float * epar,
+               int   * mpar,
+               int   * npar,
+               float * tol ,
+               int   * its ,
+               float * lab  )
+{
+    int i, n, r ;
+    int itc ;                      /* fate of fit */
+    int found ;                    /* fit converged: 1, not yet converged: 0 */
+    int  nuse ;                    /* number of useable data points */
+    double tolerance ;             /* accuracy */
+
+    itc   = 0 ;                    /* fate of fit */
+    found = 0 ;                    /* reset */
+    nfree = 0 ;                    /* number of free parameters */
+    nuse  = 0 ;                    /* number of legal data points */
+
+    if ( *tol < (FLT_EPSILON * 10.0 ) )
+    {
+        tolerance = FLT_EPSILON * 10.0 ;  /* default tolerance */
+    }
+    else
+    {
+        tolerance = *tol ;                /* tolerance */
+    }
+    
+    labda = fabs( *lab ) * LABFAC ;   /* start value for mixing parameter */
+    for ( i = 0 ; i < (*npar) ; i++ )
+    {
+        if ( mpar[i] )
+        {
+            if ( nfree > MAXPAR )         /* too many free parameters */
+            {
+                return -1 ;
+            }
+            parptr[nfree++] = i ;         /* a free parameter */
+        }
+    }
+    
+    if (nfree == 0)                       /* no free parameters */     
+    {
+        return -2 ;
+    }
+    
+    for ( n = 0 ; n < (*ndat) ; n++ )
+    {
+        if ( wdat[n] > 0.0 )              /* legal weight */
+        {
+            nuse ++ ;
+        }
+    }
+    
+    if ( nfree >= nuse )
+    {
+        return -3 ;                       /* no degrees of freedom */
+    }
+    if ( labda == 0.0 )                   /* linear fit */
+    {
+        /* initialize fpar array */
+        for ( i = 0 ; i < nfree ; fpar[parptr[i++]] = 0.0 ) ;  
+        new_get_mat ( xdat, xdim, ydat, wdat, ndat, fpar, epar/*, npar*/ ) ;
+        r =  new_get_vec ( xdat, xdim, ydat, wdat, ndat, fpar, epar, npar ) ;
+        if ( r )                         /* error */
+        {
+            return r ;
+        }
+        for ( i = 0 ; i < (*npar) ; i++ )
+        {
+            fpar[i] = epar[i] ;           /* save new parameters */
+            epar[i] = 0.0 ;               /* and set errors to zero */
+        }
+        chi1 = sqrt( chi1 / (double) (nuse - nfree) ) ;
+        for ( i = 0 ; i < nfree ; i++ )
+        {
+            if ( (matrix1[i][i] <= 0.0 ) || (matrix2[i][i] <= 0.0) )
+            {
+                return -7 ;
+            }
+            epar[parptr[i]] = chi1 * sqrt( matrix2[i][i] ) / 
+                                     sqrt( matrix1[i][i] ) ;
+        }
+    }
+    else                                  /* non-linear fit */
+    {
+        /*----------------------------------------------------------------
+         * the non-linear fit uses the steepest descent method in combination
+         * with the Taylor method. The mixing of these methods is controlled
+         * by labda. In the outer loop ( called the iteration loop ) we build
+         * the matrix and calculate the correction vector. In the inner loop
+         * (called the interpolation loop) we check whether we have obtained a
+         * better solution than the previous one. If so, we leave the inner 
+           loop else we increase labda (give more weight to the steepest 
+           descent method) calculate the correction vector and check again. 
+           After the inner loop we do a final check on the goodness of the 
+           fit and if this satisfies
+         * the tolerance we calculate the errors of the fitted parameters.
+         */
+        while ( !found )                  /* iteration loop */
+        {      
+            if ( itc++ == (*its) )        /* increase iteration counter */
+            {
+                return -4 ;               
+            }
+            new_get_mat( xdat, xdim, ydat, wdat, ndat, fpar, epar/*, npar */) ;
+            
+            /*-------------------------------------------------------------
+             * here we decrease labda since we may assume that each iteration
+             * brings us closer to the answer.
+             */
+            if ( labda > LABMIN )
+            {
+                labda = labda / LABFAC ;         /* decrease labda */
+            }
+            r = new_get_vec( xdat, xdim, ydat, wdat, ndat, fpar, epar, npar ) ;
+            if ( r )                      /* error */
+            {
+                return r ;
+            }
+
+            while ( chi1 >= sinfo_chi2 )        /* interpolation loop */
+            {
+                /*-----------------------------------------------------------
+                 * The next statement is based on experience, not on the 
+                   mathematics of the problem. It is assumed that we have 
+                   reached convergence when the pure steepest descent method 
+                   does not produce a better solution.
+                 */
+                if ( labda > LABMAX )    /* assume solution found */
+                {
+                    break ;
+                }
+                labda = labda * LABFAC ;     /* increase mixing parameter */
+                r = new_get_vec(xdat,xdim,ydat,wdat,ndat,fpar,epar,npar) ;
+                if ( r )                  /* error */
+                {
+                    return r ;
+                }
+            }
+
+            if ( labda <= LABMAX )        /* save old parameters */
+            {
+                for ( i = 0 ; i < *npar ; i++ )
+                {
+                    fpar[i] = epar[i] ;
+                }
+            }
+            if ( (fabs( sinfo_chi2 - chi1 ) <= (tolerance * chi1)) || 
+                 (labda > LABMAX) )
+            {
+                /*-------------------------------------------------------------
+                 * we have a satisfying solution, so now we need to calculate 
+                   the correct errors of the fitted parameters. This we do by 
+                   using the pure Taylor method because we are very close to 
+                   the real solution.
+                 */
+                labda = 0.0 ;              /* for Taylor solution */
+                new_get_mat(xdat,xdim,ydat,wdat,ndat,fpar,epar/*, npar */) ;
+                r = new_get_vec(xdat,xdim,ydat,wdat,ndat,fpar,epar,npar) ;
+
+                if ( r )                    /* error */
+                {
+                    return r ;
+                }
+                for ( i = 0 ; i < (*npar) ; i++ )
+                {
+                    epar[i] = 0.0 ;          /* set error to zero */
+                }
+                sinfo_chi2 = sqrt ( sinfo_chi2 / (double) (nuse - nfree) ) ;
+
+                for ( i = 0 ; i < nfree ; i++ )
+                {
+                    if ( (matrix1[i][i] <= 0.0) || (matrix2[i][i] <= 0.0) )
+                    {
+                        return -7 ;
+                    }
+                    epar[parptr[i]] = sinfo_chi2 * sqrt( matrix2[i][i] ) / 
+                                                   sqrt( matrix1[i][i] ) ;
+                }
+                found = 1 ;                  /* we found a solution */
+            }
+        }
+    }
+    return itc ;                             /* return number of iterations */
+}
+
+
+
+/**
+ at brief this function converts any ZEROs in an image to 0
+  @name sinfo_new_convert_ZEROs_to_0_for_images()
+  @param im input image
+  @return nothing
+ */
+void sinfo_new_convert_ZEROs_to_0_for_images(cpl_image * im)
+{
+    int i ;
+    int ilx=0;
+    int ily=0;
+    float* pidata=NULL;
+
+    if ( im == NULL )
+    {
+        sinfo_msg_error("no input image given!\n") ; 
+        return ;
+    }
+    ilx=cpl_image_get_size_x(im);
+    ily=cpl_image_get_size_y(im);
+    pidata=cpl_image_get_data(im);
+    for ( i = 0 ; i < (int) ilx*ily ; i++ )
+    {
+        if( isnan(pidata[i]) )
+        {
+            pidata[i] = 0. ;
+        }
+    }
+    return ;
+}
+
+/**
+ at brief this function converts any ZEROs in a cube to 0
+ @name sinfo_new_convert_ZEROs_to_0_for_cubes()
+ @param cube input cube
+ @param z_min
+ @param z_max
+ @param nothing 
+*/
+void sinfo_new_convert_ZEROs_to_0_for_cubes(cpl_imagelist * cube)
+{
+    int i ;
+    int inp=0;
+    cpl_image* i_img=NULL;  
+
+    if ( cube == NULL )
+    {
+        sinfo_msg_error("no input cube given!") ; 
+        return ;
+    }
+    inp=cpl_imagelist_get_size(cube);
+
+    for ( i = 0 ; i < inp ; i++ )
+    {
+      i_img=cpl_imagelist_get(cube,i);
+      sinfo_new_convert_ZEROs_to_0_for_images(i_img) ;
+      cpl_imagelist_set(cube,i_img,i);
+    }
+    return ;
+}
+
+
+/**
+ at brief this function converts any ZEROs in a cube to 0
+  @name sinfo_new_convert_ZEROs_to_0_for_cubes_range()
+  @param cube input cube
+  @param z_min 
+  @param z_max
+  @return nothing 
+ */
+void 
+sinfo_new_convert_ZEROs_to_0_for_cubes_range(cpl_imagelist * cube,
+                                             const int z_min,const int z_max)
+{
+    int i ;
+    cpl_image* i_img=NULL;  
+
+    if ( cube == NULL )
+    {
+        sinfo_msg_error("no input cube given!") ; 
+        return ;
+    }
+    for ( i = z_min ; i < z_max ; i++ )
+    {
+      i_img=cpl_imagelist_get(cube,i);
+      sinfo_new_convert_ZEROs_to_0_for_images(i_img) ;
+      cpl_imagelist_set(cube,i_img,i);
+    }
+    return ;
+}
+/**
+ at brief this function converts any 0 in an image to ZEROs
+ @name sinfo_new_convert_0_to_ZEROs_for_images()
+ @param im input image
+ @return nothing 
+ */
+void sinfo_new_convert_0_to_ZEROs_for_images(cpl_image * im)
+{
+    int i ;
+    int ilx=0;
+    int ily=0;
+    float* pidata=NULL;
+
+    if ( im == NULL )
+    {
+        sinfo_msg_error("no input image given!") ;
+        return ;
+    }
+    ilx=cpl_image_get_size_x(im);
+    ily=cpl_image_get_size_y(im);
+    pidata=cpl_image_get_data(im);
+    for ( i = 0 ; i < (int) ilx*ily ; i++ )
+    {
+        if( pidata[i] == 0. )
+        {
+            pidata[i] = ZERO ;
+        }
+    }
+    return ;
+}
+
+/**
+ at brief this function converts any 0 in a cube to ZERO
+ @name new_convert_0_to_ZEROs_for_cubes()
+ @param cube input cube
+ @return nothing 
+ */
+void sinfo_new_convert_0_to_ZERO_for_cubes(cpl_imagelist * cube)
+{
+    int i ;
+    int inp=0;
+    cpl_image* i_img=NULL;
+
+    if ( cube == NULL )
+    {
+        sinfo_msg_error("no input cube given!") ;
+        return ;
+    }
+    inp=cpl_imagelist_get_size(cube);
+    for ( i = 0 ; i < inp ; i++ )
+    {
+      i_img=cpl_imagelist_get(cube,i);
+      sinfo_new_convert_0_to_ZEROs_for_images(i_img) ;
+      cpl_imagelist_set(cube,i_img,i);
+    }
+    return ;
+}
+
+
+/**
+ at brief his function converts any 0 in a cube to ZERO
+   @name new_convert_0_to_ZEROs_for_cubes()
+   @param cube input cube
+   @param z_min  min z to be considered
+   @param z_max  max z to be considered
+   @return nothing
+ */
+void 
+sinfo_new_convert_0_to_ZERO_for_cubes_range(cpl_imagelist * cube,
+                                            const int z_min,const int z_max)
+{
+    int i ;
+    int inp=0;
+    cpl_image* i_img=NULL;
+
+    if ( cube == NULL )
+    {
+        sinfo_msg_error("no input cube given!") ;
+        return ;
+    }
+    inp=cpl_imagelist_get_size(cube);
+    for ( i = z_min ; i < z_max ; i++ )
+    {
+      i_img=cpl_imagelist_get(cube,i);
+      sinfo_new_convert_0_to_ZEROs_for_images(i_img) ;
+      cpl_imagelist_set(cube,i_img,i);
+    }
+    return ;
+}
+/**
+ at brief this function multiplies each image value by -1
+ at name new_invert_image()
+ @param im input image
+ @return inverted input image (overwritten)
+ */
+void sinfo_new_invert(cpl_image * im)
+{
+    int i ;
+    int ilx=0;
+    int ily=0;
+    float* pidata=NULL;
+
+    ilx=cpl_image_get_size_x(im);
+    ily=cpl_image_get_size_y(im);
+    pidata=cpl_image_get_data(im);
+
+    for ( i = 0 ; i < (int) ilx*ily ; i++ )
+    {
+        pidata[i] = -pidata[i] ;
+    }
+    return ;
+}
+
+/**
+ at brief  this routine determines the nearest integer to a specified real value
+   @name sinfo_new_nint()
+   @param x : specified real value
+   @return nearest integer to specified real value 
+ */
+
+int sinfo_new_nint ( double x ) 
+{
+    int k ;
+
+    k = x ;
+    if ( x >= 0. )
+    {
+        if ( (x - (double) k) <= 0.5 )
+        {
+            return k ;
+        }
+        else
+        {
+            return k + 1 ;
+        }
+    }
+    else
+    {
+        if ( (x - (double) k) <= -0.5 )
+        {
+            return k - 1;
+        }
+        else
+        {
+            return k ;
+        }
+    }
+}
+
+
+/**
+   @brief simple cross-correlation of two 1d-signals without FFT
+   @name sinfo_new_xcorrel ()
+   @param line_i:      the reference signal
+   @param width_i:     number of samples in reference signal
+   @param line_t:      candidate signal to compare
+   @param width_t:     number of samples in candidate signal
+   @param half_search: half-size of the search domain 
+   @param delta:       output sinfo_correlation offset.
+   @param maxpos:      position index of the maximum of the output array
+   @param xcorr_max:   maximum value of the output array
+   @return correlation function, must be freed.
+ */
+#define STEP_MIN        (-half_search)
+#define STEP_MAX        (half_search)
+
+double * sinfo_new_xcorrel(
+    float      *    line_i,
+    int             width_i,
+    float      *    line_t,
+    int             width_t,
+    int             half_search,
+    int     *       delta,
+    int       *     maxpos,
+    double     *    xcorr_max 
+    
+)
+{
+    double  * xcorr ;
+    double   mean_i, mean_t ;
+    double   rms_i, rms_t ;
+    double   sum, sqsum ;
+    double   norm ;
+    int      nsteps ;
+    int      i ;
+    int      step ;
+    int      nval ;
+    /*double   r;*/
+
+
+    /* Compute normalization factors */
+    sum = sqsum = 0.00 ;
+    for (i=0 ; i<width_i ; i++) {
+        sum += (double)line_i[i] ;
+        sqsum += (double)line_i[i] * (double)line_i[i];
+    }
+    mean_i = sum / (double)width_i ;
+    sqsum /= (double)width_i ;
+    rms_i = sqsum - mean_i*mean_i ;
+
+    sum = sqsum = 0.00 ;
+    for (i=0 ; i<width_t ; i++) {
+        sum += (double)line_t[i] ;
+        sqsum += (double)line_t[i] * (double)line_t[i];
+    }
+    mean_t = sum / (double)width_t ;
+    sqsum /= (double)width_t ;
+    rms_t = sqsum - mean_t*mean_t ;
+
+    norm = 1.00 / sqrt(rms_i * rms_t);
+
+    nsteps = (STEP_MAX - STEP_MIN)  ;
+    xcorr = cpl_malloc(nsteps * sizeof(double));
+    for (step=STEP_MIN ; step<STEP_MAX ; step++) {
+        xcorr[step-STEP_MIN] = 0.00 ;
+        nval = 0 ;
+        for (i=0 ; i<width_t ; i++) {
+            if ((i+step >= 0) &&
+                (i+step < width_i)) {
+            xcorr[step-STEP_MIN] += ((double)line_t[i] - mean_t) *
+                                    ((double)line_i[i+step] - mean_i) *
+                                    norm ;
+                nval++ ;
+            }
+        }
+        xcorr[step-STEP_MIN] /= (double)nval ;
+    }
+    *xcorr_max = xcorr[0] ;
+    *maxpos    = 0 ;
+    for (i=0 ; i<nsteps ; i++) {
+        if (xcorr[i]>*xcorr_max) {
+            *maxpos = i ;
+            *xcorr_max = xcorr[i];
+        }
+    }
+    (*delta) = + (STEP_MIN + *maxpos);
+    return xcorr ;
+}
+
+/* FILE ELEMENT: sinfo_nev_ille.c                                           */
+/*                                                                    */
+/**********************************************************************/
+/*                                                                    */
+/*                      double sinfo_nev_ille()                             */
+/*                                                                    */
+/**********************************************************************/
+/*                                                                    */
+/*  DESCRIPTION:                                                      */
+/*  For a given table (x , f(x )), i = 0(1)n  and a given argument z  */
+/*  the function computes the interpolated value for the argument z   */
+/*  using Neville's interpolation/ extrapolation algorithm.           */
+/*                                                                    */
+/*  FUNCTIONS CALLED:                                                 */
+/*  System library: <stdio.h> printf(), fabs();                       */
+/*  Numlib library: None                                              */
+/*  Local functions: nevtable();                                      */
+/*  User supplied: None                                               */
+/*                                                                    */
+/*  PROGRAMMED BY: T.Haavie                                           */
+/*  DATE/VERSION: 88-07-06/1.0                                        */
+/*                                                                    */
+/**********************************************************************/
+double sinfo_nev_ille(double x[], double f[], int n, double z, int* flag)
+               /* PARAMETERS(input):                                  */
+/* double x[];     Abscissae values in the table.                      */
+/* double f[];     Function values in the table.                       */
+/* int n;         The number of elements in the table is n+1.         */
+/* double z;       Argument to be used in interpolation/extrapolation. */
+
+
+/*                PARAMETERS(input/output):                           */
+/* int *flag;    Flag parameter(output):                             */
+               /* = 0, n < 0 and/or eps < 0, should be positive+.     */
+               /* = 1, required rel.err. is not obtained.             */
+               /* = 2, required rel. err. is obtained.                */
+
+/* the computed estimate for the interpolated/extrapolated  value re- */
+/* turned through function name sinfo_nev_ille.                             */
+
+{
+        double p[11]; /* Array used for storing the new row elements */
+                       /* in the interpolation/extrapolation table.   */
+        double q[11]; /* Array used for storing the old row elements */
+                       /* in the interpolation/extrapolation table    */
+
+        double factor;
+        int m, k;
+
+       
+
+        if (n < 0 )
+        {
+                *flag = 0;
+                return(0.);
+        }
+
+
+        q[0] = f[0];               /* Set initial value in the table. */
+
+        for (k = 1; k <= n; k++)   /* k counts rows in the table.     */
+        {
+                p[0] = f[k];
+                for (m = 1; m <= k; m++) /* m counts element in row.  */
+                {
+                        factor = (z - x[k]) / (x[k] - x[k-m]);
+                        p[m] = p[m-1] + factor * (p[m-1] - q[m-1]);
+                }
+
+
+                for (m = 0; m <= k; m++) /* Shift old row to new row.  */
+                        q[m] = p[m];
+
+        } /* End of k-loop. */
+
+        *flag = 1;              /* Required rel.error is not obtained. */
+        return(p[n]);
+
+} /* End of sinfo_nev_ille(). */
+
+
+
+float sinfo_new_nev_ille(float x[], float f[], int n, float z, int* flag)
+               /* PARAMETERS(input):                                  */
+/* float x[];     Abscissae values in the table.                      */
+/* float f[];     Function values in the table.                       */
+/* int n;         The number of elements in the table is n+1.         */
+/* float z;       Argument to be used in interpolation/extrapolation. */
+
+
+/*                PARAMETERS(input/output):                           */
+/* int *flag;    Flag parameter(output):                             */
+               /* = 0, n < 0 and/or eps < 0, should be positive+.     */
+               /* = 1, required rel.err. is not obtained.             */
+               /* = 2, required rel. err. is obtained.                */
+
+/* the computed estimate for the interpolated/extrapolated  value re- */
+/* turned through function name sinfo_nev_ille.                             */
+
+{
+        float p[11]; /* Array used for storing the new row elements */
+                       /* in the interpolation/extrapolation table.   */
+        float q[11]; /* Array used for storing the old row elements */
+                       /* in the interpolation/extrapolation table    */
+
+        float factor;
+        int m, k;
+
+       
+
+        if (n < 0 )
+        {
+                *flag = 0;
+                return(0.);
+        }
+
+
+        q[0] = f[0];               /* Set initial value in the table. */
+
+        for (k = 1; k <= n; k++)   /* k counts rows in the table.     */
+        {
+                p[0] = f[k];
+                for (m = 1; m <= k; m++) /* m counts element in row.  */
+                {
+                        factor = (z - x[k]) / (x[k] - x[k-m]);
+                        p[m] = p[m-1] + factor * (p[m-1] - q[m-1]);
+                }
+
+
+                for (m = 0; m <= k; m++) /* Shift old row to new row.  */
+                        q[m] = p[m];
+
+        } /* End of k-loop. */
+
+        *flag = 1;              /* Required rel.error is not obtained. */
+        return(p[n]);
+
+} /* End of sinfo_nev_ille(). */
+
+
+/**
+ at brief calculates the correction vector.
+   @name new_get_vec()
+   @param xdat: position
+   @param xdim: factor of the indices of the position array
+   @param ydat: real data
+   @param wdat: weights
+   @param ndat: number of data points
+   @param fpar: function parameters
+   @param epar: partial derivatives of the function
+   @param npar: number of function parameters
+   @return  integer (
+            #  0         if it had worked, 
+            # -5 or -7   if diagonal element is wrong, or 
+            # -6,        if determinant is zero )
+   @doc
+        The matrix has been
+        built by getmat(), we only have to rescale it for the 
+        current value of labda. The sinfo_matrix is rescaled so that
+        the diagonal gets the value 1 + labda.
+        Next we calculate the inverse of the sinfo_matrix and then
+        the correction vector.
+ */
+            
+static int new_get_vec ( float * xdat,
+                    int   * xdim,
+                    float * ydat,
+                    float * wdat,
+                    int   * ndat,
+                    float * fpar,
+                    float * epar,
+                    int   * npar )
+{
+    double dj ;
+    double dy ;
+    double mii ;
+    double mji ;
+    double mjj ;
+    double wn ;
+    int i, j, n, r ;
+
+    /* loop to modify and scale the sinfo_matrix */
+    for ( j = 0 ; j < nfree ; j++ )
+    {
+        mjj = matrix1[j][j] ;
+        if ( mjj <= 0.0 )             /* diagonal element wrong */
+        {
+            return -5 ;
+        }
+        mjj = sqrt( mjj ) ;
+        for ( i = 0 ; i < j ; i++ )
+        {
+            mji = matrix1[j][i] / mjj / sqrt( matrix1[i][i] ) ;
+            matrix2[i][j] = matrix2[j][i] = mji ;
+        }
+        matrix2[j][j] = 1.0 + labda ;  /* scaled value on diagonal */
+    }    
+    
+    if ( (r = new_inv_mat()) )       /* sinfo_invert sinfo_matrix inlace */
+    {
+        return r ;
+    }
+    
+    for ( i = 0 ; i < (*npar) ; i ++ )
+    {
+        epar[i] = fpar[i] ;
+    }
+    
+    /* loop to calculate correction sinfo_vector */
+    for ( j = 0 ; j < nfree ; j++ )
+    {
+        dj = 0.0 ;
+        mjj = matrix1[j][j] ;
+        if ( mjj <= 0.0)               /* not allowed */
+        {
+            return -7 ;
+        }
+        mjj = sqrt ( mjj ) ;
+        for ( i = 0 ; i < nfree ; i++ )
+        {
+            mii = matrix1[i][i] ;
+            if ( mii <= 0.0 )
+            {
+                return -7 ;
+            }
+            mii = sqrt( mii ) ;
+            dj += vec[i] * matrix2[j][i] / mjj / mii ;
+        }
+        epar[parptr[j]] += dj ;       /* new parameters */
+    }    
+    chi1 = 0.0 ;                      /* reset reduced chi-squared */
+ 
+    /* loop through the data points */
+    for ( n = 0 ; n < (*ndat) ; n++ )
+    {
+        wn = wdat[n] ;               /* get weight */
+        if ( wn > 0.0 )              /* legal weight */
+        {
+            dy = ydat[n] - new_gaussian( &xdat[(*xdim) * n], epar/*, npar*/ ) ;
+            chi1 += wdat[n] * dy * dy ;
+        }
+    }
+    return 0 ;
+}   
+    
+
+/**
+ at brief builds the matrix 
+   @name  new_get_mat()
+   @param xdat: position
+   @param xdim: factor of the indices of the position array
+   @param ydat: real data
+   @param wdat: weights
+   @param ndat: number of data points
+   @param fpar: function parameters
+   @param epar: partial derivatives of the function
+   @param npar: number of function parameters
+   @return void
+ 
+ */
+
+static void new_get_mat ( float * xdat,
+                     int   * xdim,
+                     float * ydat,
+                     float * wdat,
+                     int   * ndat,
+                     float * fpar,
+                     float * epar/*,
+                     int   * npar */)
+{
+    double wd ;
+    double wn ;
+    double yd ;
+    int i, j, n ;
+
+    for ( j = 0 ; j < nfree ; j++ )
+    {
+        vec[j] = 0.0 ; /* zero sinfo_vector */
+        for ( i = 0 ; i<= j ; i++ )   
+        /* zero sinfo_matrix only on and below diagonal */
+        {
+            matrix1[j][i] = 0.0 ;
+        }
+    }
+    sinfo_chi2 = 0.0 ;  /* reset reduced chi-squared */
+    
+    /* loop through data points */
+    for ( n = 0 ; n < (*ndat) ; n++ )
+    {
+        wn = wdat[n] ;
+        if ( wn > 0.0 )  /* legal weight ? */
+        {
+            yd = ydat[n] - new_gaussian( &xdat[(*xdim) * n], fpar/*, npar*/ ) ;
+            new_gaussian_deriv( &xdat[(*xdim) * n], fpar, epar/*, npar*/ ) ;
+            sinfo_chi2 += yd * yd * wn ; /* add to chi-squared */
+            for ( j = 0 ; j < nfree ; j++ )
+            {
+                wd = epar[parptr[j]] * wn ;  /* weighted derivative */
+                vec[j] += yd * wd ;       /* fill sinfo_vector */
+                for ( i = 0 ; i <= j ; i++ ) /* fill sinfo_matrix */
+                {
+                    matrix1[j][i] += epar[parptr[i]] * wd ;
+                }
+            }
+        }
+    }                   
+}  
+   
+
+
+
+
+ 
+/**
+ at brief calculates the inverse of matrix2.
+   @name new_inv_mat()
+   @return integer (0 if it worked, -6 if determinant is zero) 
+   @see The algorithm used is the Gauss-Jordan algorithm described in Stoer,
+        Numerische Mathematik, 1. Teil.
+ */
+
+static int new_inv_mat (void)
+{
+    double even ;
+    double hv[MAXPAR] ;
+    double mjk ;
+    double rowmax ;
+    int evin ;
+    int i, j, k, row ;
+    int per[MAXPAR] ;
+   
+    /* set permutation array */
+    for ( i = 0 ; i < nfree ; i++ )
+    {
+        per[i] = i ;
+    }
+    
+    for ( j = 0 ; j < nfree ; j++ ) /* in j-th column */
+    {
+        /* determine largest element of a row */                               
+        rowmax = fabs ( matrix2[j][j] ) ;
+        row = j ;                         
+
+        for ( i = j + 1 ; i < nfree ; i++ )
+        {
+            if ( fabs ( matrix2[i][j] ) > rowmax )
+            {
+                rowmax = fabs( matrix2[i][j] ) ;
+                row = i ;
+            }
+        }
+
+        /* determinant is zero! */
+        if ( matrix2[row][j] == 0.0 )
+        {
+            return -6 ;
+        }
+        
+        /*if the largest element is not on the diagonal, then permutate rows */
+        if ( row > j )
+        {
+            for ( k = 0 ; k < nfree ; k++ )
+            {
+                even = matrix2[j][k] ;
+                matrix2[j][k] = matrix2[row][k] ;
+                matrix2[row][k] = even ;
+            }
+            /* keep track of permutation */
+            evin = per[j] ;
+            per[j] = per[row] ;
+            per[row] = evin ;
+        }
+        
+        /* modify column */
+        even = 1.0 / matrix2[j][j] ;
+        for ( i = 0 ; i < nfree ; i++ )
+        {
+            matrix2[i][j] *= even ;
+        }
+        matrix2[j][j] = even ;
+        
+        for ( k = 0 ; k < j ; k++ )
+        {
+            mjk = matrix2[j][k] ;
+            for ( i = 0 ; i < j ; i++ )
+            {
+                matrix2[i][k] -= matrix2[i][j] * mjk ;
+            }
+            for ( i = j + 1 ; i < nfree ; i++ )
+            {
+                matrix2[i][k] -= matrix2[i][j] * mjk ;
+            }
+            matrix2[j][k] = -even * mjk ;
+        }
+    
+        for ( k = j + 1 ; k < nfree ; k++ )
+        {
+            mjk = matrix2[j][k] ;
+            for ( i = 0 ; i < j ; i++ )
+            {
+                matrix2[i][k]  -= matrix2[i][j] * mjk ;
+            }
+            for ( i = j + 1 ; i < nfree ; i++ )
+            {
+                matrix2[i][k]  -= matrix2[i][j] * mjk ;
+            }
+            matrix2[j][k] = -even * mjk ;
+        }
+    }
+    
+    /* finally, repermute the columns */
+    for ( i = 0 ; i < nfree ; i++ )
+    {
+        for ( k = 0 ; k < nfree ; k++ )
+        {
+            hv[per[k]] = matrix2[i][k] ;
+        }
+        for ( k = 0 ; k < nfree ; k++ )
+        {
+            matrix2[i][k] = hv[k] ;
+        }
+    }
+        
+    /* all is well */
+    return 0 ;
+}       
+
+
+
+
+ /**
+ at brief  calculates the value of a Gaussian with parameters 
+        parlist at the position xdat 
+   @name new_gaussian()
+   @param xdat position array, 
+   @param parlist parameter list,
+
+ at doc
+   The parameters are:
+   #                     parlist(0): Amplitude
+   #                     parlist(1): FWHM
+   #                     parlist(2): x0, center of gauss versus 
+                                         center of column
+   #                     parlist(3): Zero level
+ @return function value of a 1-d sinfo_gaussian:
+                        F(x) = par(0) * EXP ( -4.0 * LN(2.0) *
+                               [((x - parlist(2))/parlist(1))^2]) + parlist(3)
+                        FWHM^2 = 8 * ln (2) * sigma^2 
+ */
+
+float new_gaussian ( float * xdat, float * parlist/*, int * npar*/ )
+{
+    double  xd ;  /* FWHM's of gauss function */
+    double   x ;  /* position */
+
+    xd = fabs((double) parlist[1]) ;
+    x  = (double) xdat[0] - (double) parlist[2] ;
+    return (float) (
+           (double) parlist[0] * exp( -4.0 * log(2.0) * (x/xd) * (x/xd) )
+           + (double) parlist[3] ) ;
+}
+      
+       
+/**
+ at brief calculates the partial derivatives for a Gaussian with 
+       parameters parlist at position xdat 
+   @name new_gaussian_deriv()
+   @param xdat position array, 
+   @param parlist parameter list, 
+   @param dervs derivatives of params
+
+ at doc 
+                        The parameters are:
+   #                     parlist(0): Amplitude
+   #                     parlist(1): Axis(FWHM)
+   #                     parlist(2): x0, center of gauss versus center of column
+   #                     parlist(3): Zero level
+                          derivative value of Gaussian at position xdat: dervs
+   #                     dervs[0]: partial derivative by the amplitude
+   #                     dervs[1]: partial derivative by FWHM 
+   #                     dervs[2]: partial derivative by the x position 
+                                   (parlist[2])
+   #                     dervs[3]: partial derivative by the zero level
+   @return nothing, void
+ 
+ */
+
+void 
+new_gaussian_deriv(float * xdat,float * parlist,float * dervs/*, int * npar*/ )
+{
+    double xd ; /* FWHM of sinfo_gaussian */
+    double x, expon ; /* position and exponent */
+
+    xd = fabs( (double) parlist[1] ) ;
+    
+    /* offset from peak position */
+    x = (double) xdat[0] - (double) parlist[2] ;
+
+    /* determine the derivatives: */
+    expon = -4.0 * log(2.0) * (x/xd) * (x/xd) ;
+    expon = exp( expon ) ;
+
+    /* partial derivative by the amplitude */
+    dervs[0] = (float) expon ;
+
+    /* calculate a * exp(-arg) */
+    expon = (double) parlist[0] * expon ;
+
+    /* partial derivative by FWHM */
+    dervs[1] = (float) ( expon * 8.0 * log(2.0) * x*x / (xd*xd*xd) ) ;
+
+    /* partial derivative by the x position (parlist[2]) */
+    dervs[2] = (float) (expon * 8.0 * log(2.0) * x/(xd*xd) ) ;
+
+    /* partial derivative by the zero level */
+    dervs[3] = 1.0 ;
+}
+
+
+/*==================================================================*/
+
+
+/**
+ at brief fits a straight line to a set of x, y data points by 
+       minimizing chi-square.
+  @name sinfo_myfit()
+  @param x 
+  @param y set of data points, 
+  @param ndata number of data points 
+  @param sig individual standard deviations,
+  @param mwt
+  @param a
+  @param b
+  @param siga
+  @param sigb
+  @param sinfo_chi2  chi square
+  @param q     goodness of fit probability
+  @return void
+  @see Numeric. Rec. page 665 
+ */
+
+void 
+sinfo_my_fit(float x[], float y[], int ndata, float sig[], int mwt, float *a, 
+           float *b, float *siga, float *sigb, float *chi2, float *q)
+{
+    int i ;
+    float wt, t, sxoss, sx=0., sy=0., st2=0., ss, sigdat ;
+
+    *b = 0. ;             /*accumulate sums ...*/
+    if ( mwt )
+    {
+        ss = 0. ;
+        for ( i = 0 ; i < ndata ; i++ )  /*... with weights*/
+        {
+            wt = 1./SQR(sig[i]) ;
+            ss += wt ;
+            sx += x[i]*wt ;
+            sy += y[i]*wt ;
+        }
+    }
+    else
+    {
+        for ( i = 0 ; i < ndata ; i++ ) /*... or without weights*/
+        {
+             sx += x[i] ;
+             sy += y[i] ;
+        }
+        ss = ndata ;
+    }
+    sxoss = sx/ss ;
+             
+    if ( mwt )
+    {
+        for ( i = 0 ; i < ndata ; i ++ )
+        {
+            t = (x[i] - sxoss)/sig[i] ;
+            st2 += t*t ;
+            *b += t*y[i]/sig[i] ;
+        }
+    }
+    else
+    {
+        for ( i = 0 ; i < ndata ; i++ )
+        {
+            t = x[i] - sxoss ;
+            st2 += t*t ;
+            *b += t*y[i] ;           
+        }
+    }
+
+    *b /= st2 ;
+    *a = (sy - sx*(*b))/ss ;
+    *siga = sqrt ((1.0 + sx*sx/(ss*st2))/ss) ;
+    *sigb = sqrt (1.0/st2) ;
+    *chi2 = 0.0 ;  /*calculate chi-square*/
+    if ( mwt == 0 )
+    {
+        for ( i = 0 ; i < ndata ; i++ )
+        {
+            *chi2 += SQR (y[i] - (*a) - (*b)*x[i]) ;
+        }
+        *q = 1. ;
+        
+        /*------------------------------------------------------------------
+         * for unweighted data evaluate typical sig using chi2, and adjust
+         * the standard deviation
+         */
+        sigdat = sqrt ((*chi2)/(ndata - 2)) ;
+        *siga *= sigdat ;
+        *sigb *= sigdat ;
+    }
+    else
+    {
+        for (i = 0 ; i < ndata ; i++)
+        {
+            *chi2 += SQR ((y[i] - (*a) - (*b) * x[i])/sig[i]) ;
+        }    
+        *q = 1. ; /* delete rest of lines. q is not a good value */
+    }
+}
+
+/**
+ at brief this routine computes the cross correlation between two data
+       arrays of the same size and returns the integer shift between 
+       both arrays
+ at name sinfo_new_correlation()
+ at param data1: first data array
+ at param data2: second data array 
+ at param ndata: number of data elements in the arrays,
+ at note both arrays must have the same number of elements.
+ at return integer shift of the second array with respect to the first array. 
+                        2^32/2 if something went wrong.
+
+ */
+
+int sinfo_new_correlation ( float * data1, float * data2, int ndata )
+{
+    /*float help[3*ndata] ; 
+    float corsum[3*ndata] ;*/
+    float* help=NULL ; 
+    float* corsum=NULL ;
+    float maxval ;
+    int i, j, k, position, shift ;
+    int /*start,end,size,*/ndata3,limit;
+    
+    
+    /*ndata3=3*ndata;*/
+    ndata3=ndata+300;
+
+    if ( NULL == data1 || NULL == data2 || ndata <= 1 )
+    {
+        sinfo_msg_error(" wrong input for sinfo_correlation\n") ;
+        return INT32_MAX ;
+    }
+
+    /* initialize the help arrays with zeros */
+    help=cpl_calloc(ndata+300,sizeof(float));
+    for ( i = 0 ; i < ndata3 ; i++ )
+    {
+        help[i] = 0. ;
+    }
+
+    /* shift the second data array by ndata in the help array */
+    for ( i = 0 ; i < ndata ; i++ )
+    {
+        help[(300/2) + i] = data2[i] ;
+    }
+
+    /* compute the cross sinfo_correlation sum array */
+    corsum=cpl_calloc(ndata+300,sizeof(float));
+    for ( j = 0 ; j < ndata3 ; j++ )
+    {
+        if ( ndata3-j <= ndata) 
+        limit = ndata3-j;
+    else
+        limit = ndata;
+        corsum[j] = 0. ;
+        for ( k = 0 ; k < limit ; k++ )
+        {
+            /*if ( k + j >= ndata3 )
+            {
+                break ;
+            }*/
+            corsum[j] += data1[k] * help[k + j] ;
+        }
+    }
+
+    /* search for the maximal corsum value and determine its position */
+    maxval = -FLT_MAX ;
+    position = -1 ;
+    for ( i = 0 ; i < ndata3 ; i++ )
+    {
+        if ( maxval < corsum[i] )
+        {
+            maxval = corsum[i] ;
+            position = i ;
+        }
+    }
+    
+    /* determine shift of data2 relative to the data1 array */
+    shift = position - 300/2 ;
+    cpl_free(help);
+    cpl_free(corsum);
+ 
+    return shift ;
+}
+
+/*--------------------------------------------------------------------------*/
+/**@}*/
diff --git a/sinfoni/sinfo_recipes.h b/sinfoni/sinfo_recipes.h
new file mode 100644
index 0000000..99b2cf8
--- /dev/null
+++ b/sinfoni/sinfo_recipes.h
@@ -0,0 +1,303 @@
+#ifndef SINFO_RECIPES_H
+#define SINFO_RECIPES_H
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*******************************************************************************
+* E.S.O. - VLT project
+*
+* "@(#) $Id: sinfo_recipes.h,v 1.7 2008/02/12 13:29:09 amodigli Exp $"
+*
+* who       when      what
+* --------  --------  ----------------------------------------------
+* schreib  05/06/00  created
+*/
+
+/************************************************************************
+ * recipes.h
+ * some numerical recipes
+ *----------------------------------------------------------------------
+ */
+
+/*
+ * header files
+ */
+
+#include <cpl.h>
+#include <inttypes.h>
+#include <float.h>
+#include <math.h>
+#include "sinfo_pixel_handling.h"
+#include "sinfo_msg.h"
+
+
+/*----------------------------------------------------------------------------
+ *                        defines
+ *--------------------------------------------------------------------------*/
+/* definitions of initial values for sinfo_lsqfit_c in sinfo_linefit() 
+   (wave_calibration) */
+#define XDIM         1         /* dimension of the x values */
+#define TOL          0.001     /* fitting tolerance */
+#define LAB          0.1       /* labda parameter */
+#define ITS          200       /* maximum number of iterations */
+#define MAXPAR       4         /* number of free parameters */
+#define LABFAC       10.0      /* labda step factor */
+#define LABMAX       1.0e+10   /* maximum value for labda */
+#define LABMIN       1.0e-10   /* minimum value for labda */
+
+/*----------------------------------------------------------------------------
+ *                        Function ANSI C prototypes
+ *--------------------------------------------------------------------------*/
+double sinfo_nev_ille(double x[], double f[], int n, double z, int* flag);
+
+float 
+sinfo_new_f_median(float * array, int n);
+
+float 
+sinfo_new_clean_mean( float * array,
+                  int     n_elements,
+                  float   throwaway_low,
+                  float   throwaway_high ) ;
+
+
+/**
+   @name  sinfo_new_median()
+   @param  array  array of pixelvalues starting at index 0,
+                  number of array elements
+   @result      median of pixelvalues
+   @memo sorts an array into ascending numerical order by using 
+         sinfo_pixel_qsort(), and derives the median depending on an 
+         odd or even number of array elements
+*/
+
+pixelvalue 
+sinfo_new_median(pixelvalue * array, int n) ;
+/**
+   @name   sinfo_new_lsqfit_c()
+   @param  xdat position, coordinates of data points.
+                xdat is 2 dimensional: XDAT ( XDIM, NDAT )
+   @param  xdim dimension of fit
+   @param  ydat data points
+   @param  wdat weights for data points
+   @param  ndat number of data points
+   @param  fpar on input contains initial estimates of the parameters for 
+                non-linear fits, on output the fitted parameters.
+   @param  epar contains estimates of the errors in fitted parameters
+   @param  mpar logical mask telling which parameters are free (non-zero)
+                and which parameters are fixed (0)
+   @param  npar number of function parameters ( free + fixed )
+   @param  tol  relative tolerance. The lsqfit stops when successive iterations
+                fail to produce a decrement in reduced chi-squared less
+                than tol. If tol is less than the minimum tolerance
+                possible, tol will be set to this value. This means
+                that maximum accuracy can be obtained by setting tol = 0.0.
+   @param its   maximum number of iterations
+   @param lab   mixing parameter, lab determines the initial weight
+                of steepest descent method relative to the Taylor method
+                lab should be a small value (i.e. 0.01). lab can only
+                be zero when the partial derivatives are independent
+                of the parameters. In fact in this case lab should be
+                exactly equal to zero.
+  @result       returns number of iterations needed to achieve convergence
+                according to tol. When this number is negative, the fitting
+                was not continued because a fatal error occurred:
+                #        -1 too many free parameters, maximum is 32
+                #        -2 no free parameters
+                #        -3 not enough degrees of freedom
+                #        -4 maximum number of iterations too small to obtain
+                            a solution which satisfies tol.
+                #        -5 diagonal of matrix contains elements which are zero
+                #        -6 determinant of the coefficient sinfo_matrix is zero
+                #        -7 square root of a negative number
+   @doc this is a routine for making a least-squares fit of a function to a 
+        set of data points. The method used is described in: 
+        Marquardt, J.Soc.Ind.Appl.Math. 11. 431 (1963).
+        This method is a mixture of the steepest descent method
+        and the Taylor method.
+*/
+
+int sinfo_new_lsqfit_c ( float  * xdat,
+               int    * xdim,
+               float  * ydat,
+               float  * wdat,
+               int    * ndat,
+               float  * fpar,
+               float  * epar,
+               int    * mpar,
+               int    * npar,
+               float  * tol ,
+               int    * its ,
+               float  * lab  ) ;
+
+/**
+   @name sinfo_my_fit()
+   @memo fits a straight line to a set of x, y data points by
+         minimizing chi-square. Numeric. Rec. page 665
+   @param x     set of data points, 
+   @param y     set of data points,
+   @param ndata number of input data 
+   @param sig   individual standard deviations,
+   @param mwt   weights
+   @param a     parameters of a straight line, 
+   @param b     parameters of a straight line, 
+   @param chi2  chi-square, 
+   @param q     goodness-of-fit probability
+   @return     void
+*/
+
+void 
+sinfo_my_fit (float x[], float y[], int ndata, float sig[], int mwt, float *a,
+           float *b, float *siga, float *sigb, float *chi2, float *q) ;
+
+/**
+   @name      sinfo_new_nint()
+   @memo this routine determines the nearest integer to a specified real value
+   @param     x : specified real value
+   @return      nearest integer to specified real value
+*/
+
+int 
+sinfo_new_nint ( double x ) ;
+
+/**
+   @name  sinfo_new_correlation()
+   @param data1 first data array
+   @param data2 second data array
+   @param ndata number of data elements in the arrays, both arrays must have 
+                the same number of elements.
+   @return integer shift of the second array with respect to the first array.
+                        2^32/2 if something went wrong.
+   @memo this routine computes the cross sinfo_correlation between two data 
+         arrays of the same size and returns the integer shift between both 
+         arrays
+*/
+
+int 
+sinfo_new_correlation ( float * data1, float * data2, int ndata ) ;
+
+/**
+   @name    sinfo_new_convert_ZEROs_to_0_for_images()
+   @memo    this function converts any ZEROs in an image to 0
+   @param   im    input image
+   @return  nothing
+*/
+
+void 
+sinfo_new_convert_ZEROs_to_0_for_images(cpl_image * im) ;
+
+/**
+   @name  sinfo_new_convert_ZEROs_to_0_for_cubes_range()
+   @memo  this function converts any ZEROs in a cube to 0
+   @param input cube
+   @return nothing
+*/
+
+void 
+sinfo_new_convert_ZEROs_to_0_for_cubes_range(cpl_imagelist * cube,
+                                             const int z_min,
+                                             const int z_max);
+
+/**
+   @name  new_convert_0_to_ZEROs_for_cubes()
+   @memo   this function converts any 0 in a cube to ZERO
+   @param cube  input cube
+   @param z_min  min z to be considered
+   @param z_max  max z to be considered
+   @return nothing
+*/
+
+void 
+sinfo_new_convert_0_to_ZERO_for_cubes_range(cpl_imagelist * cube,
+                                            const int z_min,
+                                            const int z_max);
+/**
+   @name  sinfo_new_convert_ZEROs_to_0_for_cubes()
+   @memo   this function converts any ZEROs in a cube to 0
+   @param cube  input cube
+   @return nothing
+*/
+
+void 
+sinfo_new_convert_ZEROs_to_0_for_cubes(cpl_imagelist * cube) ;
+
+
+/**
+   @name sinfo_new_convert_0_to_ZEROs_for_images()
+   @param im   input image
+   @result    nothing
+   @memo  this function converts any 0 in an image to ZEROs
+*/
+
+void 
+sinfo_new_convert_0_to_ZEROs_for_images(cpl_image * im) ;
+
+/**
+   @name   new_convert_0_to_ZEROs_for_cubes()
+   @memo  this function converts any 0 in a cube to ZERO
+   @param  cube    input cube
+   @result nothing
+*/
+
+void 
+sinfo_new_convert_0_to_ZERO_for_cubes(cpl_imagelist * cube) ;
+
+/**
+   @name  new_invert_image()
+   @memo  this function multiplies each image value by -1.
+   @param im     input image
+   @result inverted input image (overwritten)
+*/
+
+void sinfo_new_invert(cpl_image * im) ;
+
+
+/**
+   @name      sinfo_new_xcorrel ()
+   @memo   simple cross-sinfo_correlation of two 1d-signals without FFT
+   @param  line_i      the reference signal
+   @param  width_i     number of samples in reference signal
+   @param  line_t      candidate signal to compare
+   @param  width_t     number of samples in candidate signal
+   @param  half_search half-size of the search domain
+   @param  delta       output sinfo_correlation offset.
+   @param  maxpos      position index of the maximum of the output array
+   @param  xcorr_max   maximum value of the output array
+   @result sinfo_correlation function, must be freed.
+*/
+
+double * 
+sinfo_new_xcorrel(
+    float      *    line_i,
+    int             width_i,
+    float      *    line_t,
+    int             width_t,
+    int             half_search,
+    int     *       delta,
+    int        *    maxpos,
+    double     *    xcorr_max
+
+) ;
+
+float 
+sinfo_new_nev_ille(float [], float [], int, float, int *);
+
+
+#endif /*!SINFO_RECIPES_H*/
+
+/*--------------------------------------------------------------------------*/
+
diff --git a/sinfoni/sinfo_ref_types.h b/sinfoni/sinfo_ref_types.h
new file mode 100644
index 0000000..5596cb4
--- /dev/null
+++ b/sinfoni/sinfo_ref_types.h
@@ -0,0 +1,45 @@
+/* $Id: sinfo_ref_types.h,v 1.4 2010/02/12 17:56:53 amodigli Exp $
+ *
+ * This file is part of the SINFONI Pipeline
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This proram is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2010/02/12 17:56:53 $
+ * $Revision: 1.4 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifndef SINFO_REF_TYPES_H
+#define SINFO_REF_TYPES_H
+CPL_BEGIN_DECLS
+/* reference frames */
+
+#define RAW_REF                            "REF"
+#define REF_LINE_ARC                       "REF_LINE_ARC"
+#define REF_BP_MAP                         "REF_BP_MAP"
+#define REF_SLIT_POS                       "REF_SLIT_POS"
+#define DRS_SETUP_WAVE                     "DRS_SETUP_WAVE"
+#define EXTCOEFF_TABLE                     "EXTCOEFF_TABLE"
+#define FLUX_STD_TABLE                     "FLUX_STD_TABLE"
+/* catalog of flux of standard stars*/
+#define FLUX_STD_CATALOG		   "FLUX_STD_CATALOG"
+
+CPL_END_DECLS
+
+#endif
diff --git a/sinfoni/sinfo_remove_crh_single.c b/sinfoni/sinfo_remove_crh_single.c
new file mode 100644
index 0000000..d279920
--- /dev/null
+++ b/sinfoni/sinfo_remove_crh_single.c
@@ -0,0 +1,497 @@
+/*                                                                            *
+ *   This file is part of the ESO X-shooter Pipeline                          *
+ *   Copyright (C) 2006 European Southern Observatory                         *
+ *                                                                            *
+ *   This library is free software; you can redistribute it and/or modify     *
+ *   it under the terms of the GNU General Public License as published by     *
+ *   the Free Software Foundation; either version 2 of the License, or        *
+ *   (at your option) any later version.                                      *
+ *                                                                            *
+ *   This program is distributed in the hope that it will be useful,          *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of           *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
+ *   GNU General Public License for more details.                             *
+ *                                                                            *
+ *   You should have received a copy of the GNU General Public License        *
+ *   along with this program; if not, write to the Free Software              *
+ *   Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA     *
+ *                                                                            */
+
+/*
+ * $Author: amodigli $
+
+ * $Date: 2012/03/03 10:18:26 $
+ * $Revision: 1.5 $
+ * $Log: sinfo_remove_crh_single.c,v $
+ * Revision 1.5  2012/03/03 10:18:26  amodigli
+ * fixed some doxygen warnings
+ *
+ * Revision 1.4  2010/12/29 12:29:05  amodigli
+ * fixed doxygen warning, and bug in kernel filter indexing
+ *
+ * Revision 1.3  2009/09/03 15:04:48  kmirny
+ * replacing deprecated functions
+ *
+ * Revision 1.2  2009/02/18 10:33:07  amodigli
+ * fixed compiler warning
+ *
+ * Revision 1.1  2009/01/02 08:27:58  amodigli
+ * added to repository
+ *
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+/**@{*/
+/*----------------------------------------------------------------------------*/
+/**
+ * @defgroup sinfo_remove_crh_single  Remove Cosmic Rays single (sinfo_remove_crh_single)
+ * @ingroup drl_functions
+ *
+ * Suppress Cosmic Rays by analysing on files
+ */
+/*----------------------------------------------------------------------------*/
+
+/*-----------------------------------------------------------------------------
+  Includes
+-----------------------------------------------------------------------------*/
+
+#include <math.h>
+
+
+#include <sinfo_error.h>
+#include <sinfo_msg.h>
+#include <sinfo_utils_wrappers.h>
+#include <cpl.h>
+#include "sinfo_utilities.h"
+/*-----------------------------------------------------------------------------
+  Functions prototypes
+ -----------------------------------------------------------------------------*/
+cpl_image * sinfo_remove_crh_single( cpl_image * sci_image,
+				     double crh_frac_max,
+				     double sigma_lim,
+				     double f_lim,
+				     int max_iter,
+				     double gain,
+				     double ron);
+/*-----------------------------------------------------------------------------
+  Implementation
+ -----------------------------------------------------------------------------*/
+
+/* This should be defined in a more clever way, a parameter for example */
+#define MAX_ITERATIONS 6
+
+
+/**
+ * Remove cosmic rays from a single frame.
+ *
+ * @param[in] sci_image
+ *   The science image
+ * @param[in] crh_frac_max
+ *   The maximum fraction of pixel over total detector pixels flagged as CRHs 
+ * @param[in] sigma_lim
+ *        Poisson fluctuation threshold to flag CRHs
+ * @param[in] f_lim
+ *        Minimum contrast between the Laplacian image and the fine structure 
+ *        image that a point must have to be flagged as CRH.
+ * @param[in] max_iter
+ *   Maximum number of iterations performed to flag CRHs
+ * @param[in] gain
+ *   Detector's gain
+ * @param[in] ron
+ *   Detector's read out noise value
+ *
+ * @return The science image after removal of Cosmics
+ */
+cpl_image * sinfo_remove_crh_single( cpl_image * sci_image,
+				     double crh_frac_max,
+				     double sigma_lim,
+				     double f_lim,
+				     int max_iter,
+				     double gain,
+				     double ron)
+{
+  int i,j,k,l,m;
+  double  frac = 0. ;
+  /* Only pointers */
+
+  /* Need to be free */
+  //xsh_localization_list * loc_list = NULL ;
+  cpl_image* laplacian_image = NULL;
+  cpl_image* laplacian_redu_image = NULL;
+  cpl_image* two_sub_sample = NULL;
+  cpl_image* sci_median5_image = NULL;
+  cpl_image* noise_image = NULL;
+  cpl_image* s_image = NULL;
+  cpl_image* s_median_image = NULL;
+  cpl_image* s2_image = NULL;
+  cpl_image* sci_median3_image = NULL;
+  cpl_image* sci_median3_7_image = NULL;
+  cpl_image* f_image = NULL;
+  cpl_image* r_image = NULL;
+  int two_sub_sample_nx = 0;
+  int two_sub_sample_ny = 0;
+  /* Only pointers */
+  float* sci_data = NULL;
+  float* two_sub_sample_data = NULL;
+  float* laplacian_data = NULL;
+  float* laplacian_redu_data = NULL;
+  float* sci_median5_data = NULL;
+  float* sci_median3_data = NULL;
+  float* sci_median3_7_data = NULL;
+  float* noise_data = NULL;
+  float* s_data = NULL;
+  float* s_median_data = NULL;
+  float* s2_data = NULL;
+  float* f_data = NULL;
+  float* r_data = NULL;
+  /* Need to be free */
+  float* cosmic_data = NULL;
+
+  cpl_matrix* laplacian_kernel = NULL;
+  cpl_matrix* median3_kernel = NULL;
+  cpl_matrix* median5_kernel = NULL;
+  cpl_matrix* median7_kernel = NULL;
+  int new_crh =1, nb_crh = 0;
+  int nbiter = 1 ;
+  cpl_vector* median = NULL;
+  //const char * tag = NULL ;
+  int nx=0;
+  int ny=0;
+  cpl_image* res_image=NULL;
+
+  /* Check parameters */
+  cknull( sci_image,"null input image" ) ; ;
+
+  sinfo_msg( "Entering sinfo_remove_crh_single");
+  sinfo_msg( "  Params: frac_max %.1f, sigma_lim %.2f f_lim %.2f, iter %d",
+	   crh_frac_max, sigma_lim, f_lim, max_iter);
+
+  /* Preparing different kernels */
+  nx=cpl_image_get_size_x(sci_image);
+  ny=cpl_image_get_size_y(sci_image);
+
+  /* Laplacian */
+  check_nomsg( laplacian_kernel = cpl_matrix_new(3,3));
+  cpl_matrix_set( laplacian_kernel,0,0,0.0);
+  cpl_matrix_set( laplacian_kernel,0,1,-1.0);
+  cpl_matrix_set( laplacian_kernel,0,2,0.0);
+  cpl_matrix_set( laplacian_kernel,1,0,-1.0);
+  cpl_matrix_set( laplacian_kernel,1,1,4.0);
+  cpl_matrix_set( laplacian_kernel,1,2,-1.0);
+  cpl_matrix_set( laplacian_kernel,2,0,0.0);
+  cpl_matrix_set( laplacian_kernel,2,1,-1.0);
+  cpl_matrix_set( laplacian_kernel,2,2,0.0);
+  cpl_matrix_divide_scalar( laplacian_kernel, 4.0);
+/*
+  cpl_matrix_set( laplacian_kernel,0,0,-1.0);
+  cpl_matrix_set( laplacian_kernel,0,1,-1.0);
+  cpl_matrix_set( laplacian_kernel,0,2,-1.0);
+  cpl_matrix_set( laplacian_kernel,1,0,-1.0);
+  cpl_matrix_set( laplacian_kernel,1,1,8.0);
+  cpl_matrix_set( laplacian_kernel,1,2,-1.0);
+  cpl_matrix_set( laplacian_kernel,2,0,-1.0);
+  cpl_matrix_set( laplacian_kernel,2,1,-1.0);
+  cpl_matrix_set( laplacian_kernel,2,2,-1.0);
+  cpl_matrix_divide_scalar( laplacian_kernel, 8.0);
+*/
+  /* Median 3x3*/
+  check_nomsg( median3_kernel = cpl_matrix_new(3,3));
+  for(j=0; j< 3; j++){
+    for(i=0; i< 3; i++){
+      cpl_matrix_set( median3_kernel, i,j,1.0);
+    }
+  }
+
+  /* Median 5x5 */
+  check_nomsg( median5_kernel = cpl_matrix_new(5,5));
+  for(j=0; j< 5; j++){
+    for(i=0; i< 5; i++){
+      cpl_matrix_set( median5_kernel, i,j,1.0);
+    }
+  }
+
+  /* Median 7x7 */
+  check_nomsg( median7_kernel = cpl_matrix_new(7,7));
+  for(j=0; j< 7; j++){
+    for(i=0; i< 7; i++){
+      cpl_matrix_set( median7_kernel, i,j,1.0);
+    }
+  }
+
+  check_nomsg (res_image = cpl_image_duplicate( sci_image));
+
+  /* Allocate images and pointers */
+  check_nomsg (sci_data = cpl_image_get_data_float( res_image));
+
+  two_sub_sample_nx = nx*2;
+  two_sub_sample_ny = ny*2;
+  check_nomsg( two_sub_sample = cpl_image_new( two_sub_sample_nx,
+    two_sub_sample_ny, CPL_TYPE_FLOAT));
+  check_nomsg(two_sub_sample_data = cpl_image_get_data_float( two_sub_sample));
+  check_nomsg( laplacian_redu_image = cpl_image_new(nx,ny, CPL_TYPE_FLOAT));
+  check_nomsg(laplacian_redu_data = cpl_image_get_data_float(
+    laplacian_redu_image));
+  check_nomsg( noise_image = cpl_image_new(nx,ny, CPL_TYPE_FLOAT));
+  check_nomsg( noise_data = cpl_image_get_data_float( noise_image));
+  check_nomsg( s_image = cpl_image_new(nx,ny, CPL_TYPE_FLOAT));
+  check_nomsg( s_data = cpl_image_get_data_float( s_image));
+  check_nomsg( s2_image = cpl_image_new(nx,ny, CPL_TYPE_FLOAT));
+  check_nomsg( s2_data = cpl_image_get_data_float( s2_image));
+  check_nomsg( f_image = cpl_image_new(nx,ny, CPL_TYPE_FLOAT));
+  check_nomsg( f_data = cpl_image_get_data_float( f_image));
+  check_nomsg( r_image = cpl_image_new(nx,ny, CPL_TYPE_FLOAT));
+  check_nomsg( r_data = cpl_image_get_data_float( r_image));
+  cosmic_data=cpl_calloc(nx*ny, sizeof(float));
+
+  /* LGG - Added limit on frac_max AND limit on nb iterations */
+  while( new_crh > 0 && frac < crh_frac_max && nbiter <= max_iter ){
+    sinfo_msg("Iteration %d",nbiter );
+    /* Create a 2n x 2n images like this
+        | 1 | 2 |  =>  | 1 | 1 | 2 | 2 |
+        | 3 | 4 |      | 1 | 1 | 2 | 2 |
+                       | 3 | 3 | 4 | 4 |
+                       | 3 | 3 | 4 | 4 | */
+    sinfo_msg_debug("Create a 2n images");
+    for( j=0; j< ny; j++){
+      for( i=0; i< nx; i++){
+        float val = sci_data[i+j*nx];
+
+	if ( val < 0. ) val = 0. ;
+        two_sub_sample_data[i*2+j*2*two_sub_sample_nx] = val;
+        two_sub_sample_data[i*2+1+j*2*two_sub_sample_nx] = val;
+        two_sub_sample_data[i*2+(j*2+1)*two_sub_sample_nx] = val;
+        two_sub_sample_data[i*2+1+(j*2+1)*two_sub_sample_nx] = val;
+      }
+    }
+    sinfo_msg_debug("Doing laplacian convolution");
+    /* Doing the laplacian convolution
+        0  -1   0
+       -1   4  -1
+        0  -1   0 */
+    laplacian_image = sinfo_image_filter_linear( two_sub_sample,
+      laplacian_kernel);
+
+    /* multiply by two to normalize correctly the laplacian [RD5]
+       and filter negative values */
+    sinfo_msg_debug("Normalize laplacian");
+    check_nomsg (laplacian_data = cpl_image_get_data_float( laplacian_image));
+    for ( i=0; i< two_sub_sample_nx*two_sub_sample_ny; i++){
+      if (laplacian_data[i] > 0.0){
+        laplacian_data[i] = 2.0 * laplacian_data[i];
+      }
+      else{
+        laplacian_data[i] = 0.0;
+      }
+    }
+    sinfo_msg_debug("Save Lpositive");
+    cpl_image_save(laplacian_image, "Lpositive.fits", CPL_BPP_IEEE_FLOAT, NULL,
+      CPL_IO_DEFAULT);
+
+    /* resample to the original size
+       | 1 | 1 | 2 | 2 |    | 1 | 2 |
+       | 1 | 1 | 2 | 2 |    | 3 | 4 |
+       | 3 | 3 | 4 | 4 | =>
+       | 3 | 3 | 4 | 4 |               */
+
+    sinfo_msg_debug("Resample to the original size");
+
+    for( j=0; j< ny; j++){
+      for( i=0; i< nx; i++){
+        laplacian_redu_data[i+j*nx] =
+          (laplacian_data[i*2+j*2*two_sub_sample_nx]+
+           laplacian_data[i*2+1+j*2*two_sub_sample_nx]+
+           laplacian_data[i*2+(j*2+1)*two_sub_sample_nx]+
+           laplacian_data[i*2+1+(j*2+1)*two_sub_sample_nx])/4.0;
+      }
+    }
+
+    cpl_image_save(laplacian_redu_image, "Lplus.fits", CPL_BPP_IEEE_FLOAT,
+      NULL, CPL_IO_DEFAULT);
+
+    sinfo_msg_debug("Apply median filter");
+    /* Apply 5x5 median filter on data */
+    check_nomsg( sci_median5_image = sinfo_image_filter_median( sci_image,
+      median5_kernel));
+    check_nomsg (sci_median5_data = cpl_image_get_data_float( sci_median5_image));
+
+    sinfo_msg_debug("Compute noise");
+    /* computes the noise image */
+    for( i=0; i< nx*ny; i++){
+      noise_data[i] = sqrt(sci_median5_data[i]*gain+
+        ron*ron)/ gain;
+    }
+
+    sinfo_msg_debug("Compute S");
+    /* compute S image */
+    for( i=0; i< nx*ny; i++){
+      s_data[i] = laplacian_redu_data[i] / (2.0*noise_data[i]);
+    }
+
+    sinfo_msg_debug("Compute S median");
+    /* compute S median image */
+    check_nomsg( s_median_image = sinfo_image_filter_median( s_image,
+      median5_kernel));
+    check_nomsg( s_median_data = cpl_image_get_data_float( s_median_image));
+
+    sinfo_msg_debug("Compute s2");
+    /* compute s2 */
+    for( i=0; i< nx*ny; i++){
+      s2_data[i] = s_data[i] -s_median_data[i];
+    }
+
+       cpl_image_save( s2_image, "S2.fits", CPL_BPP_IEEE_FLOAT, NULL,
+	 CPL_IO_DEFAULT);
+
+    sinfo_msg_debug("Apply 3x3 filter");
+    /* Apply 3x3 median filter on data */
+    check_nomsg( sci_median3_image = sinfo_image_filter_median( sci_image,
+      median3_kernel));
+
+    sinfo_msg_debug("Apply 7x7 filter");
+    /* Apply 7x7 median filter */
+    check_nomsg( sci_median3_7_image = sinfo_image_filter_median( sci_median3_image,
+      median7_kernel));
+    sinfo_msg_debug("Apply 7x7 filter ok");
+    check_nomsg ( sci_median3_data = cpl_image_get_data_float( sci_median3_image));
+    check_nomsg ( sci_median3_7_data = cpl_image_get_data_float(
+      sci_median3_7_image));
+
+    sinfo_msg_debug("Compute F");
+    /* compute F */
+    for( i=0; i< nx*ny; i++){
+      f_data[i] = sci_median3_data[i] -sci_median3_7_data[i];
+      if (f_data[i] < 0.01){
+        f_data[i] = 0.01;
+      }
+    }
+    cpl_image_save( f_image, "F.fits", CPL_BPP_IEEE_FLOAT, NULL,
+      CPL_IO_DEFAULT);
+
+    sinfo_msg_debug("Compute R");
+    /* compute R */
+    for( i=0; i< nx*ny; i++){
+      r_data[i] = laplacian_redu_data[i]/f_data[i];
+    }
+
+    cpl_image_save( r_image, "R.fits", CPL_BPP_IEEE_FLOAT, NULL,
+      CPL_IO_DEFAULT);
+
+    /* Search for cosmics */
+
+    sinfo_msg_debug("Search for cosmic");
+    new_crh = 0;
+    median = cpl_vector_new(24);
+
+    for( j=1; j< ny-1; j++){
+      double *data = NULL;
+      cpl_vector* med_vect = NULL;
+
+      for( i=1; i< nx-1; i++){
+        if ( (s2_data[i+j*nx] >= sigma_lim) &&
+          (r_data[i+j*nx] >= f_lim)){
+          int li,lj,ui,uj;
+          cosmic_data[i+j*nx] = 1.0;
+          new_crh++;
+          li = i-2;
+          lj = j-2;
+          ui = i+2;
+          uj = j+2;
+          m = 0;
+          if (li < 0) li = 0;
+          if (ui >= nx) ui = nx-1;
+          if (lj < 0) lj = 0;
+          if (uj >= ny) uj = ny-1;
+          for( k=lj; k <= uj; k++){
+            for( l=li; l <= ui; l++){
+              //sinfo_msg("REGDEBUG k %d l %d m %d", k, l, m);
+              if ( k < j){
+                cpl_vector_set(median, m, sci_data[l+k*nx]);
+                m++;
+              }
+              else if ( (k == j) && ( l < i)){
+                 cpl_vector_set(median, m, sci_data[l+k*nx]);
+                m++;
+              }
+              else if ( l!=i && k!=j && (s2_data[l+k*nx] < sigma_lim)
+                && (r_data[l+k*nx] < f_lim)){
+                cpl_vector_set(median, m, sci_data[l+k*nx]);
+                m++;
+              }
+            }
+          }
+          check_nomsg( data = cpl_vector_get_data( median));
+          sinfo_msg_debug("REGDEBUG i %d j %d m %d", i, j ,m);
+          check_nomsg( med_vect = cpl_vector_wrap( m, data));
+          check_nomsg( sci_data[i+j*nx] = cpl_vector_get_median( med_vect));
+          cpl_vector_unwrap( med_vect);
+        }
+      }
+    }
+    sinfoni_free_vector( &median ) ;
+    nb_crh += new_crh;
+    frac = (double)nb_crh/(double)(nx*ny) ;
+    sinfo_msg("   new cosmics %d, total %d, frac %.4f [%d pixels]",new_crh,nb_crh,
+	    frac, nx*ny);
+    nbiter++;
+    sinfo_free_image( &laplacian_image);
+    sinfo_free_image( &sci_median3_7_image ) ;
+    sinfo_free_image( &sci_median3_image ) ;
+    sinfo_free_image( &s_median_image ) ;
+    sinfo_free_image( &sci_median5_image ) ;
+  }
+  {
+    FILE *debug = NULL;
+
+    debug = fopen("cosmic.log","w");
+
+    for( j=0; j< ny; j++){
+      for( i=0; i< nx; i++){
+        if ( cosmic_data[i+j*nx] == 1.0){
+          fprintf(debug,"%.1f %.1f\n",i+1.0,j+1.0);
+        }
+      }
+    }
+    fclose(debug);
+  }
+
+  //check_nomsg( res_frame = cpl_frame_duplicate( sci_frame ) ) ;
+  //sinfo_msg( "Saving Result Frame '%s'", res_name ) ;
+  //check_nomsg( add_qc_crh( sci_pre, nb_crh, 1, instrument ) ) ;
+  //check_nomsg( res_frame = xsh_pre_save( sci_pre, res_name, 1 ) ) ;
+  //tag = cpl_frame_get_tag( in_sci_frame ) ;
+  //check_nomsg( cpl_frame_set_tag( res_frame, tag ) ) ;
+
+  cleanup:
+  //xsh_pre_free( &sci_pre);
+  //xsh_localization_list_free( &loc_list ) ;
+
+    /* free kernel */
+    sinfoni_free_matrix( &laplacian_kernel);
+    sinfoni_free_matrix( &median3_kernel);
+    sinfoni_free_matrix( &median5_kernel);
+    sinfoni_free_matrix( &median7_kernel);
+    /* free images */
+    sinfo_free_image( &laplacian_image);
+    sinfo_free_image( &laplacian_redu_image);
+    sinfo_free_image( &two_sub_sample);
+    sinfo_free_image( &sci_median5_image);
+    sinfo_free_image( &noise_image);
+    sinfo_free_image( &s_image);
+    sinfo_free_image( &s_median_image);
+    sinfo_free_image( &s2_image);
+    sinfo_free_image( &sci_median3_image);
+    sinfo_free_image( &sci_median3_7_image);
+    sinfo_free_image( &f_image);
+    sinfo_free_image( &r_image);
+    /* free vector */
+    sinfoni_free_vector( &median);
+    /* free tab */
+    if(cosmic_data!=NULL) cpl_free( cosmic_data);
+    return res_image;
+}
+/**@}*/
+
diff --git a/sinfoni/sinfo_remove_crh_single.h b/sinfoni/sinfo_remove_crh_single.h
new file mode 100644
index 0000000..e093463
--- /dev/null
+++ b/sinfoni/sinfo_remove_crh_single.h
@@ -0,0 +1,7 @@
+cpl_image * sinfo_remove_crh_single( cpl_image * sci_image, 
+				   double frac_max,
+				   double sigma_lim,
+				   double f_lim,
+				     int max_iter,
+				     double gain,
+				     double ron);
diff --git a/sinfoni/sinfo_resampling.c b/sinfoni/sinfo_resampling.c
new file mode 100644
index 0000000..111c8f3
--- /dev/null
+++ b/sinfoni/sinfo_resampling.c
@@ -0,0 +1,388 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+   
+   File name     :    resampling.c
+   Author         :    Nicolas Devillard
+   Created on    :    Jan 04, 1996
+   Description    :    resampling routines
+
+ ---------------------------------------------------------------------------*/
+
+/*
+    $Id: sinfo_resampling.c,v 1.6 2012/03/03 10:18:26 amodigli Exp $
+    $Author: amodigli $
+    $Date: 2012/03/03 10:18:26 $
+    $Revision: 1.6 $
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+/*---------------------------------------------------------------------------
+                                  Includes
+ ---------------------------------------------------------------------------*/
+#include <string.h>
+#include "sinfo_resampling.h"
+#include <math.h>
+#include "sinfo_globals.h"
+/*---------------------------------------------------------------------------
+                              Private functions
+ ---------------------------------------------------------------------------*/
+static void reverse_tanh_kernel(double * data, int nn) ;
+static double * sinfo_generate_tanh_kernel(double steep);
+
+/**@{*/
+/**
+ * @addtogroup sinfo_rec_jitter Image resampling
+ *
+ * TBD
+ */
+
+
+
+/*---------------------------------------------------------------------------
+                              Function codes
+ ---------------------------------------------------------------------------*/
+
+/**
+  @name        sinfo_generate_interpolation_kernel
+  @memo        Generate an interpolation kernel to use in this module.
+  @param    kernel_type        Type of interpolation kernel.
+  @return    1 newly allocated array of doubles.
+  @doc
+
+  Provide the name of the kernel you want to generate. Supported kernel
+  types are:
+
+  \begin{tabular}{ll}
+  NULL            &    default kernel, currently "tanh" \\
+  "default"        &    default kernel, currently "tanh" \\
+  "tanh"        &    Hyperbolic tangent \\
+  "sinc2"        &    Square sinc \\
+  "lanczos"        &    Lanczos2 kernel \\
+  "hamming"        &    Hamming kernel \\
+  "hann"        &    Hann kernel
+  \end{tabular}
+
+  The returned array of doubles is ready of use in the various re-sampling
+  functions in this module. It must be deallocated using cpl_free().
+ */
+
+double   *
+sinfo_generate_interpolation_kernel(const char * kernel_type)
+{
+    double  *    tab ;
+    int         i ;
+    double      x ;
+    double        alpha ;
+    double        inv_norm ;
+    int         samples = KERNEL_SAMPLES ;
+
+    if (kernel_type==NULL) {
+        tab = sinfo_generate_interpolation_kernel("tanh") ;
+    } else if (!strcmp(kernel_type, "default")) {
+        tab = sinfo_generate_interpolation_kernel("tanh") ;
+    } else if (!strcmp(kernel_type, "sinc")) {
+        tab = cpl_malloc(samples * sizeof(double)) ;
+        tab[0] = 1.0 ;
+        tab[samples-1] = 0.0 ;
+        for (i=1 ; i<samples ; i++) {
+            x = (double)KERNEL_WIDTH * (double)i/(double)(samples-1) ;
+            tab[i] = sinfo_sinc(x) ;
+        }
+    } else if (!strcmp(kernel_type, "sinc2")) {
+        tab = cpl_malloc(samples * sizeof(double)) ;
+        tab[0] = 1.0 ;
+        tab[samples-1] = 0.0 ;
+        for (i=1 ; i<samples ; i++) {
+            x = 2.0 * (double)i/(double)(samples-1) ;
+            tab[i] = sinfo_sinc(x) ;
+            tab[i] *= tab[i] ;
+        }
+    } else if (!strcmp(kernel_type, "lanczos")) {
+        tab = cpl_malloc(samples * sizeof(double)) ;
+        for (i=0 ; i<samples ; i++) {
+            x = (double)KERNEL_WIDTH * (double)i/(double)(samples-1) ;
+            if (fabs(x)<2) {
+                tab[i] = sinfo_sinc(x) * sinfo_sinc(x/2) ;
+            } else {
+                tab[i] = 0.00 ;
+            }
+        }
+    } else if (!strcmp(kernel_type, "hamming")) {
+        tab = cpl_malloc(samples * sizeof(double)) ;
+        alpha = 0.54 ;
+        inv_norm  = 1.00 / (double)(samples - 1) ;
+        for (i=0 ; i<samples ; i++) {
+            x = (double)i ;
+            if (i<(samples-1)/2) {
+                tab[i] = alpha + (1-alpha) * cos(2.0*PI_NUMB*x*inv_norm) ;
+            } else {
+                tab[i] = 0.0 ;
+            }
+        }
+    } else if (!strcmp(kernel_type, "hann")) {
+        tab = cpl_malloc(samples * sizeof(double)) ;
+        alpha = 0.50 ;
+        inv_norm  = 1.00 / (double)(samples - 1) ;
+        for (i=0 ; i<samples ; i++) {
+            x = (double)i ;
+            if (i<(samples-1)/2) {
+                tab[i] = alpha + (1-alpha) * cos(2.0*PI_NUMB*x*inv_norm) ;
+            } else {
+                tab[i] = 0.0 ;
+            }
+        }
+    } else if (!strcmp(kernel_type, "tanh")) {
+        tab = sinfo_generate_tanh_kernel(TANH_STEEPNESS) ;
+    } else {
+        sinfo_msg_error("unrecognized kernel type [%s]: aborting generation",
+                kernel_type) ;
+        return NULL ;
+    }
+
+    return tab ;
+}
+
+/**
+  @name        sinfo_sinc
+  @memo        Cardinal sine.
+  @param    x    double value.
+  @return    1 double.
+  @doc
+
+  Compute the value of the function sinfo_sinc(x)=sin(pi*x)/(pi*x) at the
+  requested x.
+ */
+
+double
+sinfo_sinc(double x)
+{
+    if (fabs(x)<1e-4)
+        return (double)1.00 ;
+    else
+        return ((sin(x * (double)PI_NUMB)) / (x * (double)PI_NUMB)) ;
+}
+
+/**
+  @name        sinfo_generate_tanh_kernel
+  @memo        Generate a hyperbolic tangent kernel.
+  @param    steep    Steepness of the hyperbolic tangent parts.
+  @return    1 pointer to a newly allocated array of doubles.
+  @doc
+
+  The following function builds up a good approximation of a box filter. It
+  is built from a product of hyperbolic tangents. It has the following
+  properties:
+
+  \begin{itemize}
+  \item It converges very quickly towards +/- 1.
+  \item The converging transition is very sharp.
+  \item It is infinitely differentiable everywhere (i.e. smooth).
+  \item The transition sharpness is scalable.
+  \end{itemize}
+
+  The returned array must be deallocated using cpl_free().
+ */
+
+#define hk_gen(x,s) (((tanh(s*(x+0.5))+1)/2)*((tanh(s*(-x+0.5))+1)/2))
+
+static double * 
+sinfo_generate_tanh_kernel(double steep)
+{
+    double  *   kernel ;
+    double  *   x ;
+    double      width ;
+    double      inv_np ;
+    double      ind ;
+    int         i ;
+    int         np ;
+    int         samples ;
+
+    width   = (double)TABSPERPIX / 2.0 ; 
+    samples = KERNEL_SAMPLES ;
+    np      = 32768 ; /* Hardcoded: should never be changed */
+    inv_np  = 1.00 / (double)np ;
+
+    /*
+     * Generate the kernel expression in Fourier space
+     * with a correct frequency ordering to allow standard FT
+     */
+    x = cpl_malloc((2*np+1)*sizeof(double)) ;
+    for (i=0 ; i<np/2 ; i++) {
+        ind      = (double)i * 2.0 * width * inv_np ;
+        x[2*i]   = hk_gen(ind, steep) ;
+        x[2*i+1] = 0.00 ;
+    }
+    for (i=np/2 ; i<np ; i++) {
+        ind      = (double)(i-np) * 2.0 * width * inv_np ;
+        x[2*i]   = hk_gen(ind, steep) ;
+        x[2*i+1] = 0.00 ;
+    }
+
+    /* 
+     * Reverse Fourier to come back to image space
+     */
+    reverse_tanh_kernel(x, np) ;
+
+    /*
+     * Allocate and fill in returned array
+     */
+    kernel = cpl_malloc(samples * sizeof(double)) ;
+    for (i=0 ; i<samples ; i++) {
+        kernel[i] = 2.0 * width * x[2*i] * inv_np ;
+    }
+    cpl_free(x) ;
+    return kernel ;
+}
+
+/**
+  @name        reverse_tanh_kernel
+  @memo        Bring a hyperbolic tangent kernel from Fourier to normal space.
+  @param    data    Kernel samples in Fourier space.
+  @param    nn        Number of samples in the input kernel.
+  @return    void
+  @doc
+
+  Bring back a hyperbolic tangent kernel from Fourier to normal space. Do
+  not try to understand the implementation and DO NOT MODIFY THIS FUNCTION.
+ */
+
+#define KERNEL_SW(a,b) tempr=(a);(a)=(b);(b)=tempr
+static void 
+reverse_tanh_kernel(double * data, int nn)
+{
+    unsigned long   n,
+                    mmax,
+                    m,
+                    i, j,
+                    istep ;
+    double  wtemp,
+            wr,
+            wpr,
+            wpi,
+            wi,
+            theta;
+    double  tempr,
+            tempi;
+
+    n = (unsigned long)nn << 1;
+    j = 1;
+    for (i=1 ; i<n ; i+=2) {
+        if (j > i) {
+            KERNEL_SW(data[j-1],data[i-1]);
+            KERNEL_SW(data[j],data[i]);
+        }
+        m = n >> 1;
+        while (m>=2 && j>m) {
+            j -= m;
+            m >>= 1;
+        }
+        j += m;
+    }
+    mmax = 2;
+    while (n > mmax) {
+        istep = mmax << 1;
+        theta = 2 * PI_NUMB / mmax;
+        wtemp = sin(0.5 * theta);
+        wpr = -2.0 * wtemp * wtemp;
+        wpi = sin(theta);
+        wr  = 1.0;
+        wi  = 0.0;
+        for (m=1 ; m<mmax ; m+=2) {
+            for (i=m ; i<=n ; i+=istep) {
+                j = i + mmax;
+                tempr = wr * data[j-1] - wi * data[j];
+                tempi = wr * data[j]   + wi * data[j-1];
+                data[j-1] = data[i-1] - tempr;
+                data[j]   = data[i]   - tempi;
+                data[i-1] += tempr;
+                data[i]   += tempi;
+            }
+            wr = (wtemp = wr) * wpr - wi * wpi + wr;
+            wi = wi * wpr + wtemp * wpi + wi;
+        }
+        mmax = istep;
+    }
+}
+#undef KERNEL_SW
+
+/**
+  @name        sinfo_invert_linear_transform
+  @memo        Invert a linear transformation.
+  @param    trans    Transformation to sinfo_invert.
+  @return    1 newly allocated array of 6 doubles.
+  @doc
+
+  Given 6 parameters a, b, c, d, e, f defining a linear transform such as:
+  \begin{verbatim}
+  u = ax + by + c
+  v = dx + ey + f
+  \end{verbatim}
+
+  The inverse transform is also linear, and is defined by:
+  \begin{verbatim}
+  x = Au + Bv + C
+  y = Du + Ev + F
+  \end{verbatim}
+
+  where:
+
+  \begin{verbatim}
+  if G = (ae-bd)
+
+  A =  e/G
+  B = -b/G
+  C = (bf-ce)/G
+  D = -d/G
+  E =  a/G
+  F = (cd-af)/G
+  \end{verbatim}
+
+  Notice that if G=0 (ae=bd) the transform cannot be reversed.
+
+  The returned array must be deallocated using cpl_free().
+ */
+
+double *
+sinfo_invert_linear_transform(double *trans)
+{
+    double   *    i_trans ;
+    double       det ;
+
+    if (trans==NULL) return NULL ;
+    det = (trans[0] * trans[4]) - (trans[1] * trans[3]) ;
+    if (fabs(det) < 1e-6) {
+        sinfo_msg_error("NULL determinant: cannot sinfo_invert transform") ;
+        return NULL ;
+    }
+
+    i_trans = cpl_calloc(6, sizeof(double)) ;
+
+    i_trans[0] =  trans[4] / det ; 
+    i_trans[1] = -trans[1] / det ;
+    i_trans[2] = ((trans[1] * trans[5]) - (trans[2] * trans[4])) / det ;
+    i_trans[3] = -trans[3] / det ;
+    i_trans[4] =  trans[0] / det ;
+    i_trans[5] = ((trans[2] * trans[3]) - (trans[0] * trans[5])) / det ;
+
+    return i_trans ;
+}
+/**@}*/
diff --git a/sinfoni/sinfo_resampling.h b/sinfoni/sinfo_resampling.h
new file mode 100644
index 0000000..318659a
--- /dev/null
+++ b/sinfoni/sinfo_resampling.h
@@ -0,0 +1,157 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+   
+   File name     :    sinfo_resampling.h
+   Author         :    Nicolas Devillard
+   Created on    :    Jan 04, 1996
+   Description    :    resampling routines
+
+ ---------------------------------------------------------------------------*/
+
+/*
+
+ $Id: sinfo_resampling.h,v 1.4 2007/06/06 07:10:45 amodigli Exp $
+ $Author: amodigli $
+ $Date: 2007/06/06 07:10:45 $
+ $Revision: 1.4 $
+
+ */
+
+#ifndef SINFO_RESAMPLING_H
+#define SINFO_RESAMPLING_H
+
+/*---------------------------------------------------------------------------
+                                  Includes
+ ---------------------------------------------------------------------------*/
+
+#include <cpl.h>
+#include "sinfo_msg.h"
+/*---------------------------------------------------------------------------
+                                  Defines
+ ---------------------------------------------------------------------------*/
+#define TRANSFO_AFFINE          0
+#define TRANSFO_DEG2            1
+#define TRANSFO_HOMOGRAPHIC     2
+
+/* Number of pixels set to 0 by the shift resampling */
+#define    SHIFT_REJECT_L            2
+#define    SHIFT_REJECT_R            2
+#define    SHIFT_REJECT_T            2
+#define    SHIFT_REJECT_B            2
+
+/*
+ * Kernel definition in terms of sampling
+ */
+
+
+/* Number of tabulations in kernel  */
+#define TABSPERPIX      (1000)
+#define KERNEL_WIDTH    (2.0)
+#define KERNEL_SAMPLES  (1+(int)(TABSPERPIX * KERNEL_WIDTH))
+
+#define TANH_STEEPNESS    (5.0)
+
+
+/*---------------------------------------------------------------------------
+                         Function ANSI C prototypes
+ ---------------------------------------------------------------------------*/
+
+/**
+  @name     sinfo_generate_interpolation_kernel
+  @memo     Generate an interpolation kernel to use in this module.
+  @param    kernel_type     Type of interpolation kernel.
+  @return   1 newly allocated array of doubles.
+  @doc
+ 
+  Provide the name of the kernel you want to generate. Supported kernel
+  types are:
+ 
+  \begin{tabular}{ll}
+  NULL          &   default kernel, currently "tanh" \\
+  "default"     &   default kernel, currently "tanh" \\
+  "tanh"        &   Hyperbolic tangent \\
+  "sinc2"       &   Square sinc \\
+  "lanczos"     &   Lanczos2 kernel \\
+  "hamming"     &   Hamming kernel \\
+  "hann"        &   Hann kernel
+  \end{tabular}
+ 
+  The returned array of doubles is ready of use in the various re-sampling
+  functions in this module. It must be deallocated using free().
+ */
+
+double   *
+sinfo_generate_interpolation_kernel(const char * kernel_type) ;
+
+
+/**
+  @name     sinfo_sinc
+  @memo     Cardinal sine.
+  @param    x   double value.
+  @return   1 double.
+  @doc
+ 
+  Compute the value of the function sinfo_sinc(x)=sin(pi*x)/(pi*x) at the
+  requested x.
+ */
+
+double
+sinfo_sinc(double x) ;
+
+/**
+  @name     sinfo_invert_linear_transform
+  @memo     Invert a linear transformation.
+  @param    trans   Transformation to sinfo_invert.
+  @return   1 newly allocated array of 6 doubles.
+  @doc
+ 
+  Given 6 parameters a, b, c, d, e, f defining a linear transform such as:
+  \begin{verbatim}
+  u = ax + by + c
+  v = dx + ey + f
+  \end{verbatim}
+ 
+  The inverse transform is also linear, and is defined by:
+  \begin{verbatim}
+  x = Au + Bv + C
+  y = Du + Ev + F
+  \end{verbatim}
+ 
+  where:
+ 
+  \begin{verbatim}
+  if G = (ae-bd)
+ 
+  A =  e/G
+  B = -b/G
+  C = (bf-ce)/G
+  D = -d/G
+  E =  a/G
+  F = (cd-af)/G
+  \end{verbatim}
+ 
+  Notice that if G=0 (ae=bd) the transform cannot be reversed.
+ 
+  The returned array must be deallocated using free().
+ */
+
+double *
+sinfo_invert_linear_transform(double *trans) ;
+#endif
diff --git a/sinfoni/sinfo_shift_images.c b/sinfoni/sinfo_shift_images.c
new file mode 100644
index 0000000..68bf8fc
--- /dev/null
+++ b/sinfoni/sinfo_shift_images.c
@@ -0,0 +1,790 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*************************************************************************
+* E.S.O. - VLT project
+*
+*
+*
+* who       when      what
+* --------  --------  ----------------------------------------------
+* schreib  05/03/03  created
+*/
+
+/************************************************************************
+*   NAME
+*        sinfo_shift_images.c -
+*        some procedures to shift images in spectral direction
+*
+*   SYNOPSIS
+*   #include "sinfo_shift_images.h"
+*
+*   1) double sinfo_new_determine_shift_by_correlation ( cpl_image * refImage, 
+*                                           cpl_image * shiftedImage )
+*   2) cpl_image * sinfo_new_shift_image_in_spec ( cpl_image * shiftedImage, 
+                                                   double shift, 
+                                                   double * sub_shift )
+*   3) cpl_image * 
+       sinfo_new_fine_shift_image_in_spec_poly(cpl_image * shiftedImage, 
+                                                           double sub_shift, 
+                                                           int order )
+*   4) cpl_image * 
+       sinfo_new_fine_shift_image_in_spec_cubicspline(cpl_image * shiftedImage, 
+                                                      double sub_shift )
+*   5) cpl_imagelist * sinfo_align_cube_to_reference(cpl_imagelist * cube, 
+*                                       cpl_image * refIm,
+*                                       int order,
+*                                       int shift_indicator )
+*
+*
+*   DESCRIPTION
+*
+*   1) determines the sub-pixel shift of to emission line
+*      frames by cross sinfo_correlation and fitting the sinfo_correlation
+*      function by a Gaussian
+*   2) shifts an image by a given amount to integer pixel accuracy
+*   3) shifts an image by a given amount to sub-pixel accuracy
+*   4) shifts an image by a given amount to sub-pixel accuracy
+*   5) shifts images stacked in a cube by a given amount to sub-pixel accuracy
+*
+*   FILES
+*
+*   ENVIRONMENT
+*
+*   RETURN VALUES
+*
+*   CAUTIONS
+*
+*   EXAMPLES
+*
+*   SEE ALSO
+*
+*   BUGS
+*
+*------------------------------------------------------------------------
+*/
+
+/*
+ * System Headers
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+#include "sinfo_vltPort.h"
+#define POSIX_SOURCE 1
+/*
+ * Local Headers
+ */
+#include "sinfo_function_1d.h"
+#include "sinfo_shift_images.h"
+#include "sinfo_new_resampling.h"
+#include "sinfo_globals.h"
+
+
+static int filecounter ;
+/**@{*/
+/**
+ * @defgroup sinfo_shift_images Functions to shift images
+ *
+ * TBD
+ */
+
+/*----------------------------------------------------------------------------
+ *                            Function codes
+ *--------------------------------------------------------------------------*/
+
+/**
+ @brief determines the sub-pixel shift of to emission line frames by 
+        cross sinfo_correlation and fitting the correlation function 
+        by a Gaussian
+ @name sinfo_new_determine_shift_by_correlation()
+ @param refImage: reference image
+ @param shiftedImage: image shifted in spectral direction
+                      with respect to the reference image
+ @return shift in sub-pixel accuracy 
+ */
+
+double sinfo_new_determine_shift_by_correlation ( cpl_image * refImage, 
+                                     cpl_image * shiftedImage )
+{
+    int          col, row ;
+    int           i, j, k, width;
+    unsigned long convsize ;
+    float       * lineref ;
+    float       * line ;
+    float       * offset2 ;
+    double      * result ;
+    double       mean_offset2 ;
+    /*int          magFactor ;*/
+    int          maxlag ;
+    float      * refres ;
+    float      * myres ;
+    int          halfsearch ;
+    int          delta ;
+    double       xcorr_max ;
+    /*float        arg ;*/
+    float      par[MAXPAR] ;
+    float      derv_par[MAXPAR] ;
+    int        iters, xdim, ndat ;
+    int        numpar, its ;
+    int        * mpar ;
+    float      tol, lab ;
+    float      * xdat, * wdat ;
+    Vector     * peak;
+    char       filename[FILE_NAME_SZ] ;
+    FILE       * fp ;
+
+    int rlx=0;
+    int rly=0;
+    int slx=0;
+    int sly=0;
+    float* prdata=NULL;
+    float* psdata=NULL;
+
+    if ( NULL == refImage || NULL == shiftedImage )
+    {
+        sinfo_msg_error("image not given!") ;
+        return ZERO ;
+    }
+    rlx=cpl_image_get_size_x(refImage);
+    rly=cpl_image_get_size_x(refImage);
+    prdata=cpl_image_get_data_float(refImage);
+    slx=cpl_image_get_size_x(shiftedImage);
+    sly=cpl_image_get_size_x(shiftedImage);
+    psdata=cpl_image_get_data_float(shiftedImage);
+
+    if ( rlx != slx || rly != sly )
+    {
+        sinfo_msg_error("image size not compatible!") ;
+        return ZERO ;
+    }
+    snprintf(filename, MAX_NAME_SIZE-1,"offset%d.list", filecounter) ;
+
+    fp = fopen(filename, "w") ;
+
+    convsize = sly;
+
+    lineref = (float*) cpl_calloc(convsize, sizeof(float) ) ;
+    line = (float*) cpl_calloc(convsize, sizeof(float) ) ;
+
+    offset2 = (float*) cpl_calloc(slx, sizeof(float) ) ;
+
+    for ( col = 0 ; col < slx ; col++ )
+    {
+        /* initialize arrays */
+        for ( row = 0 ;  row < (int) convsize ; row++ )
+        {
+            lineref[row] = 0. ;
+            line[row] = 0. ;
+        }
+
+        /* magnify spectral sinfo_vector by magFactor */
+        for ( row = 0 ; row < (sly) ; row++ )
+        {
+      lineref[row] = prdata[col+row*slx] ;   /* AM: why slx? */
+      line[row] = psdata[col+row*slx] ;
+        }
+
+        myres = sinfo_function1d_filter_lowpass(line, convsize, 
+                                                LOW_PASS_GAUSSIAN, 3) ;
+        refres = sinfo_function1d_filter_lowpass(lineref, convsize, 
+                                                 LOW_PASS_GAUSSIAN, 4) ;
+
+        /*  now do a cross correlaton of both convolved spectral vectors */
+        halfsearch = convsize / 2 ;
+        result = sinfo_new_xcorrel( myres, convsize, refres, convsize, 
+                                    halfsearch, &delta, &maxlag, &xcorr_max ) ;
+
+        if ( xcorr_max < 0. )
+        {
+            sinfo_function1d_del ( refres ) ;
+            sinfo_function1d_del ( myres ) ;
+            cpl_free (result) ; 
+            continue ;
+        }
+
+        /* in this section, we fit the sinfo_correlation function with a 
+           gauss, and find its peak, th
+           us getting subpixel-accuracy */
+
+        i = maxlag; j = i+1;
+        while (result[j] < result[i]) 
+        {
+            i++; j++;
+        }
+        i = maxlag; k = i-1;
+        while (result[k] < result[i]) 
+        {
+            i--; k--;
+        }
+        width = j-k+1;
+        /* allocate memory for the spectral sinfo_vector */
+        if ( NULL == (peak = sinfo_new_vector (width)) )
+        {
+            sinfo_msg_error ("cannot allocate new Vector ") ;
+            fclose(fp);
+            return ZERO ;
+        }
+
+
+        /* allocate memory */
+        xdat = (float *) cpl_calloc( peak -> n_elements, sizeof (float) ) ;
+        wdat = (float *) cpl_calloc( peak -> n_elements, sizeof (float) ) ;
+        mpar = (int *)   cpl_calloc( MAXPAR, sizeof (int) ) ;
+
+        /* determine the values of the spectral sinfo_vector given as input */
+        /* go through the chosen column */
+
+        for ( i = 0 ; i < width ; i++ )
+        {
+            peak -> data[i] = result[k+i] ;
+            xdat[i] = i;
+            wdat[i] = 1.0;
+        }
+
+        /* set initial values for the fitting routine */
+        xdim     = XDIM;
+        ndat     = peak -> n_elements ;
+        numpar   = MAXPAR ;
+        tol      = TOL ;
+        lab      = LAB ;
+        its      = ITS ;
+        par[1] = width/2.0 ;
+        par[2] = (float) (maxlag - k) ;
+        par[3] = (peak -> data[0] + peak -> data[peak->n_elements - 1]) / 2.0 ;
+        par[0]  = result[maxlag] - (par[3]) ;
+
+        for ( i = 0 ; i < MAXPAR ; i++ )
+        {
+            derv_par[i] = 0.0 ;
+            mpar[i] = 1 ;
+        }
+
+        /* finally, do the least square fit using a sinfo_gaussian */
+        if ( 0 > ( iters = sinfo_new_lsqfit_c( xdat, &xdim, peak -> data, wdat, 
+                                         &ndat, par, derv_par, mpar,
+                                         &numpar, &tol, &its, &lab )) )
+        {
+            sinfo_msg_warning ("sinfo_new_lsqfit_c: least squares fit failed "
+                               "in col: %d, error no.: %d", col, iters) ;
+            sinfo_new_destroy_vector ( peak ) ;
+            cpl_free ( xdat ) ;
+            cpl_free ( wdat ) ;
+            cpl_free ( mpar ) ;
+            sinfo_function1d_del ( refres ) ;
+            sinfo_function1d_del ( myres ) ;
+            cpl_free (result) ; 
+            continue ;
+        }
+
+        sinfo_new_destroy_vector ( peak ) ;
+        cpl_free (xdat) ;
+        cpl_free (wdat) ;
+        cpl_free (mpar) ;
+        sinfo_function1d_del ( refres ) ;
+        sinfo_function1d_del ( myres ) ;
+        cpl_free (result) ; 
+ 
+        offset2[col] = (float)( k+par[2] - sly/2) ;
+        fprintf(fp, "offset: %f in col: %d\n", offset2[col], col) ;
+    }
+
+    mean_offset2 = (double)sinfo_new_clean_mean (offset2, slx, 15., 15. ) ;
+    fprintf(fp, "mean offset: %f\n", mean_offset2) ;
+    fclose(fp) ;
+
+    cpl_free ( lineref ) ;
+    cpl_free ( line ) ;
+    cpl_free ( offset2 ) ; 
+    filecounter++ ;
+    if (filecounter > 100 ) filecounter = 0 ;
+
+    return mean_offset2 ;
+}
+
+
+/**
+ at brief shifts an image by a given amount to integer pixel accuracy
+ at name  sinfo_new_shift_image_in_spec()
+ at param shiftedImage: image to shift in spectral direction
+ at param shift: amount of shift, output of sinfo_determineShiftByCorrelation 
+ at param sub_shift: non-integer rest of shift < 1
+ at return shifted image  
+ */
+
+
+cpl_image * 
+sinfo_new_shift_image_in_spec ( cpl_image * shiftedImage, 
+                                double shift, 
+                                double * sub_shift )
+{
+    cpl_image * retIm ;
+    int        col, row ;
+    int        intshift ;
+    int ilx=0;
+    int ily=0;
+    int olx=0;
+    int oly=0;
+
+    float* pidata=NULL;
+    float* podata=NULL;
+
+    if ( shiftedImage == NULL )
+    {
+        sinfo_msg_error("no image given!") ;
+        return NULL ;
+    }
+
+    ilx=cpl_image_get_size_x(shiftedImage);
+    ily=cpl_image_get_size_y(shiftedImage);
+    pidata=cpl_image_get_data_float(shiftedImage);
+
+    intshift = sinfo_new_nint (shift) ;
+    *sub_shift = shift - (double) intshift ;
+    if ( intshift == 0 )
+    {
+        retIm =cpl_image_duplicate ( shiftedImage ) ;
+        return retIm ;
+    }
+    else
+    {
+        if ( NULL == (retIm = cpl_image_new(ilx,ily,CPL_TYPE_FLOAT)) )
+        {
+            sinfo_msg_error ("could not allocate memory!") ;
+            return NULL ;
+        }
+    }
+
+    olx=cpl_image_get_size_x(retIm);
+    oly=cpl_image_get_size_y(retIm);
+    podata=cpl_image_get_data_float(retIm);
+
+    for ( col = 0 ; col < ilx ; col++ )
+    {
+        for ( row = 0 ; row < ily ; row++ )
+        {
+            if ( (row-intshift >= 0 ) && (row - intshift < oly) )
+            {
+                podata[col+(row-intshift)*olx] = pidata[col+row*olx] ;
+            }
+        }
+    }
+    return retIm ;
+}
+
+/**
+ at brief shifts an image by a given amount to sub-pixel accuracy
+ at name sinfo_new_fine_shift_image_in_spec_poly()
+ at param shiftedImage: image to shift in spectral direction
+ at param sub_shift: amount of shift < 1, output of  sinfo_shiftImageInSpec
+ at param order:     order of polynomial
+ at return shifted image  
+*/
+
+cpl_image * 
+sinfo_new_fine_shift_image_in_spec_poly ( cpl_image * shiftedImage, 
+                                          double sub_shift, 
+                                          int order )
+{
+    cpl_image * retIm ;
+
+    float* spec=NULL ;
+    float* corrected_spec=NULL ;
+    float* xnum=NULL ;
+
+    float sum, new_sum ;
+    float eval/*, dy*/ ;
+    float * imageptr ;
+    int row, col ;
+    int firstpos ;
+    int n_points ;
+    int i ;
+    int flag;
+    int ilx=0;
+    int ily=0;
+    int olx=0;
+    int oly=0;
+
+    float* pidata=NULL;
+    float* podata=NULL;
+
+    if ( shiftedImage == NULL )
+    {
+        sinfo_msg_error("no image given!") ;
+        return NULL ;
+    }
+    ilx=cpl_image_get_size_x(shiftedImage);
+    ily=cpl_image_get_size_y(shiftedImage);
+    pidata=cpl_image_get_data_float(shiftedImage);
+
+    if ( order <= 0 )
+    {
+        sinfo_msg_error("wrong order of interpolation polynom given!") ;
+        return NULL ;
+    }
+
+    /* allocate memory */
+    if ( NULL == (retIm = cpl_image_new(ilx, ily,CPL_TYPE_FLOAT)) )
+    {
+        sinfo_msg_error ("could not allocate memory!") ;
+        return NULL ;
+    }
+
+    olx=cpl_image_get_size_x(retIm);
+    oly=cpl_image_get_size_y(retIm);
+    podata=cpl_image_get_data_float(retIm);
+
+    n_points = order + 1 ;
+    if ( n_points % 2 == 0 )
+    {
+        firstpos = (int)(n_points/2) - 1 ;
+    }
+    else
+    {
+        firstpos = (int)(n_points/2) ;
+    }
+
+    spec=cpl_calloc(ily,sizeof(float)) ;
+    corrected_spec=cpl_calloc(ily,sizeof(float)) ;
+    xnum=cpl_calloc(order+1,sizeof(float)) ;
+
+
+    /* fill the xa[] array for the polint function */
+    for ( i = 0 ; i < n_points ; i++ )
+    {
+        xnum[i] = i ;
+    }
+
+    for ( col = 0 ; col < ilx ; col++ )
+    {
+        for ( row = 0 ; row < ily ; row++ )
+        {
+            corrected_spec[row] = 0. ;
+        }
+        sum = 0. ;
+        for ( row = 0 ; row < ily ; row++ )
+        {
+            spec[row] = pidata[col + row*ilx] ;
+            if (isnan(spec[row]) )
+            {
+                spec[row] = 0. ;
+                  
+                for ( i = row - firstpos ; i < row-firstpos+n_points ; i++ )
+                {
+                    if ( i < 0 ) continue ;
+                    if ( i >= ily) continue  ;
+                    corrected_spec[i] = ZERO ;
+                }
+            }
+            if ( row != 0 && row != ily - 1 )
+            {
+                sum += spec[row] ;
+            }
+        }
+        
+        new_sum = 0. ;
+        for ( row = 0 ; row < ily ; row++ )
+        {
+            /* ---------------------------------------------------------------
+             * now determine the arrays of size n_points with which the
+             * polynom is determined and determine the position eval
+             * where the polynom is evaluated in polynomial interpolation.
+             * Take care of the points near the row edges!
+             */
+            if (isnan(corrected_spec[row])) continue ;
+            if ( row - firstpos < 0 )
+            {
+                imageptr = &spec[0] ;
+                eval     = sub_shift + row ;
+            }
+            else if ( row - firstpos + n_points >= ily )
+            {
+                imageptr = &spec[ily - n_points] ;
+                eval     = sub_shift + row + n_points - ily ;
+            }
+            else
+            {
+                imageptr = &spec[row-firstpos] ;
+                eval     = sub_shift + firstpos ;
+            }
+
+        flag=0;
+            corrected_spec[row]=sinfo_new_nev_ille( xnum, imageptr, 
+                                                    order, eval, &flag) ;
+            if ( row != 0 && row != ily - 1 )
+            {
+                new_sum += corrected_spec[row] ;
+            }
+        }
+
+        for ( row = 0 ; row < ily ; row++ )
+        {
+            if ( new_sum == 0. )
+            {
+                new_sum = 1. ;
+            }
+            if ( row == 0 )
+            {
+                podata[col+row*olx] = ZERO ;
+            }
+            else if ( row == ily - 1 )
+            {
+                podata[col+row*olx] = ZERO ;
+            }
+            else if ( isnan(corrected_spec[row]) )
+            {
+                podata[col+row*olx] = ZERO ;
+            }
+            else
+            {
+                corrected_spec[row] *= sum / new_sum ;
+                podata[col+row*olx] = corrected_spec[row] ;
+            }
+        }
+    }
+    cpl_free(spec) ;
+    cpl_free(corrected_spec) ;
+    cpl_free(xnum) ;
+    return retIm ;
+}
+/**
+ at brief shifts an image by a given amount to sub-pixel accuracy   
+ at name sinfo_new_fine_shift_image_in_spec_cubicspline()
+ at param shiftedImage: image to shift in spectral direction
+ at param sub_shift: amount of shift < 1, output of  sinfo_shiftImageInSpec
+ at return shifted image  
+ */
+
+cpl_image * 
+sinfo_new_fine_shift_image_in_spec_cubic_spline ( cpl_image * shiftedImage, 
+                                                  double sub_shift )
+{
+    cpl_image * retIm ;
+    /*float second_deriv[shiftedImage -> ly] ;*/
+    float* spec=NULL ;
+    float* corrected_spec=NULL ;
+    float* xnum=NULL ;
+    float* eval=NULL ;
+    float sum, new_sum ;
+    int row, col ;
+    int i ;
+    int ilx=0;
+    int ily=0;
+    int olx=0;
+    int oly=0;
+
+    float* pidata=NULL;
+    float* podata=NULL;
+
+    if ( shiftedImage == NULL )
+    {
+        sinfo_msg_error("no image given!") ;
+        return NULL ;
+    }
+    ilx=cpl_image_get_size_x(shiftedImage);
+    ily=cpl_image_get_size_y(shiftedImage);
+    pidata=cpl_image_get_data_float(shiftedImage);
+
+    /* allocate memory */
+    if ( NULL == (retIm = cpl_image_new(ilx,ily,CPL_TYPE_FLOAT)) )
+    {
+        sinfo_msg_error ("could not allocate memory!") ;
+        return NULL ;
+    }
+    olx=cpl_image_get_size_x(retIm);
+    oly=cpl_image_get_size_y(retIm);
+    podata=cpl_image_get_data_float(retIm);
+
+    xnum=cpl_calloc(ily,sizeof(float)) ;
+    /* fill the xa[] array for the spline function */
+    for ( i = 0 ; i < ily ; i++ )
+    {
+        xnum[i] = i ;
+    }
+
+    spec=cpl_calloc(ily,sizeof(float)) ;
+    corrected_spec=cpl_calloc(ily,sizeof(float)) ;
+    eval=cpl_calloc(ily,sizeof(float)) ;
+
+    for ( col = 0 ; col < ilx ; col++ )
+    {
+        sum = 0. ;
+        for ( row = 0 ; row < ily ; row++ )
+        {
+            spec[row] = pidata[col + row*ilx] ;
+            if (isnan(spec[row]) )
+            {
+                for ( i = row-1 ; i <= row+1 ; i++ )
+                {
+                    if ( i < 0 ) continue ;
+                    if ( i >= ily) continue ;
+                    corrected_spec[i] = ZERO ;
+                }  
+        spec[row] = 0. ;
+            }
+            sum += spec[row] ;
+            eval[row] = (float)sub_shift+(float)row ;
+        }
+        /* now we do the spline interpolation*/
+        if ( -1 == sinfo_function1d_natural_spline( xnum, spec, ily, eval, 
+                                              corrected_spec, ily ) )
+        {
+            sinfo_msg_error("error in spline interpolation!") ;
+            return NULL ;
+        }
+        
+        new_sum = 0. ;
+        for ( row = 0 ; row < ily ; row++ )
+        {
+            if ( isnan(corrected_spec[row]) )
+            {
+                continue ;
+            }   
+        new_sum += corrected_spec[row] ;
+        }
+
+        for ( row = 0 ; row < ily ; row++ )
+        {
+            if ( new_sum == 0. ) new_sum =1. ;
+            {
+                if ( isnan(corrected_spec[row]) )
+                {
+                    podata[col+row*olx] = ZERO ;
+                }
+                else
+                {
+                    corrected_spec[row] *= sum / new_sum ;
+                    podata[col+row*olx] = corrected_spec[row] ;
+                }
+            }
+        }
+    }
+    cpl_free(xnum);
+    cpl_free(spec) ;
+    cpl_free(corrected_spec) ;
+    cpl_free(eval) ;
+
+    return retIm ;
+}
+
+/**
+ at brief shifts images stacked in a cube by a given amount to sub-pixel accuracy
+ at name sinfo_align_cube_to_reference()
+ at param cube: cube containing images to shift in spectral direction
+ at param refIm: reference image (OH spectrum) 
+ at param order: order of polynomial interpolation for the resampling
+ at param shift_indicator: indicator for the polynomial interpolation (0)
+                        or cubic spline interpolation shift (1).
+ at return shifted cube 
+*/
+
+cpl_imagelist * sinfo_align_cube_to_reference (cpl_imagelist * cube, 
+                                 cpl_image * refIm,
+                                 int order,
+                                 int shift_indicator )
+{
+    cpl_imagelist * retCube=NULL ;
+    cpl_image * shiftedIm=NULL ;
+    cpl_image * fineShiftedIm=NULL ;
+    double shift=0 ;
+    double  sub_shift=0 ;
+    int z=0;
+    double * ker=NULL ;
+    cpl_image* img=NULL;
+
+    if (cube == NULL)
+    { 
+        sinfo_msg_error("no input cube given!") ;
+        return NULL ;
+    }
+    if (refIm == NULL)
+    { 
+        sinfo_msg_error("no input ref. image given!") ;
+        return NULL ;
+    }
+
+    /* allocation for a cube structure without the image planes  */
+    retCube = cpl_imagelist_new() ;
+
+    if ( shift_indicator != 0 && shift_indicator != 1 )
+    {
+        ker = sinfo_new_generate_interpolation_kernel("tanh") ;
+        if (ker == NULL)
+        {
+            sinfo_msg_error("kernel generation failure: aborting resampling") ;
+            return NULL ;
+        }
+    }
+    
+    for ( z = 0 ; z < cpl_imagelist_get_size(cube) ; z++ )
+    {
+      /* first determine the shift by correlation with the reference image */
+      img=cpl_imagelist_get(cube,z);
+      if (isnan( shift=sinfo_new_determine_shift_by_correlation(refIm,img)))
+        { 
+            sinfo_msg_error("error in sinfo_determineShiftByCorrelation()!") ;
+            return NULL ;
+        }
+
+        if ( NULL == (shiftedIm = sinfo_new_shift_image_in_spec(img,shift,
+                                                                &sub_shift)) ) 
+        { 
+            sinfo_msg_error("error in sinfo_shiftImageInSpec()!") ;
+            return NULL ;
+        }
+        if ( shift_indicator == 0 )
+        {
+            if ( NULL == (fineShiftedIm = 
+                 sinfo_new_fine_shift_image_in_spec_poly (shiftedIm, 
+                                                          sub_shift, order)))
+            {
+                sinfo_msg_error("error in sinfo_fineShiftImageInSpecPoly()!") ;
+                return NULL ;
+            }
+        }
+        else if ( shift_indicator == 1)
+        {
+          if ( NULL == (fineShiftedIm = 
+               sinfo_new_fine_shift_image_in_spec_cubic_spline (shiftedIm, 
+                                                                  sub_shift)))
+          {
+            sinfo_msg_error("error in fineShiftImageInSpecCubicspline()!") ;
+            return NULL ;
+          }
+        }
+        
+    else
+    {
+      if ( NULL == (fineShiftedIm = 
+               sinfo_new_shift_image(shiftedIm,0.,sub_shift, ker ) ) )
+          {
+           sinfo_msg_error("error in fineShiftImageInSpecCubicspline()!") ;
+           return NULL ;
+          }     
+    }
+    cpl_imagelist_set(retCube,fineShiftedIm,z);
+        cpl_image_delete (shiftedIm) ;
+        cpl_image_delete (fineShiftedIm) ;
+    }
+    if ( shift_indicator != 0 && shift_indicator != 1 ) cpl_free(ker) ;
+    return retCube ;
+}
+
+/*--------------------------------------------------------------------------*/
+/**@}*/
diff --git a/sinfoni/sinfo_shift_images.h b/sinfoni/sinfo_shift_images.h
new file mode 100644
index 0000000..cfc7adb
--- /dev/null
+++ b/sinfoni/sinfo_shift_images.h
@@ -0,0 +1,135 @@
+#ifndef SINFO_SHIFT_IMAGES_H
+#define SINFO_SHIFT_IMAGES_H
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/***************************************************************************
+* E.S.O. - VLT project
+*
+* "@(#) $Id: sinfo_shift_images.h,v 1.5 2008/02/12 14:21:57 amodigli Exp $"
+*
+* who       when      what
+* --------  --------  ----------------------------------------------
+* schreib  05/03/03  created
+*/
+
+/************************************************************************
+ * sinfo_shift_images.h
+ * shift two emission line images on each other
+ *----------------------------------------------------------------------
+ */
+
+/*
+ * header files
+ */
+
+#include <cpl.h>
+#include "sinfo_spectrum_ops.h"
+#include "sinfo_recipes.h"
+#include "sinfo_image_ops.h"
+
+/*----------------------------------------------------------------------------
+ *                        Function ANSI C prototypes
+ *--------------------------------------------------------------------------*/
+
+/**
+   @name     sinfo_new_determine_shift_by_correlation()
+   @memo    determines the sub-pixel shift of to emission line frames by 
+             cross sinfo_correlation and fitting the sinfo_correlation
+             function by a Gaussian
+   @param    refImage: reference image
+   @param    shiftedImage: image shifted in spectral direction
+                                      with respect to the reference image
+   @return   shift in sub-pixel accuracy
+*/
+
+double 
+sinfo_new_determine_shift_by_correlation (cpl_image * refImage,
+                                     cpl_image * shiftedImage ) ;
+
+
+/**
+   @name     sinfo_new_shift_image_in_spec()
+   @memo   shifts an image by a given amount to integer pixel accuracy
+   @param    shiftedImage: image to shift in spectral direction
+   @param    shift: amount of shift, output of 
+             sinfo_determineShiftByCorrelation
+   @param    sub_shift: non-integer rest of shift < 1
+   @result   shifted image
+*/
+
+
+cpl_image * 
+sinfo_new_shift_image_in_spec (cpl_image * shiftedImage, 
+                               double shift, 
+                               double * sub_shift ) ;
+
+
+/**
+   @name   sinfo_new_fine_shift_image_in_spec_poly()
+   @memo   shifts an image by a given amount to sub-pixel accuracy
+   @param  shiftedImage: image to shift in spectral direction
+   @param  sub_shift: amount of shift < 1, output of  sinfo_shiftImageInSpec
+   @param  order:     order of polynomial
+   @result shifted image
+*/
+
+cpl_image * 
+sinfo_new_fine_shift_image_in_spec_poly (cpl_image * shiftedImage, 
+                                         double sub_shift, 
+                                         int order ) ;
+
+/**
+   @name   new_fine_shift_image_in_spec_cubic_spline()
+   @param  shiftedImage: image to shift in spectral direction
+   @param  sub_shift: amount of shift < 1, output of  sinfo_shiftImageInSpec
+   @result shifted image
+   @result shifts an image by a given amount to sub-pixel accuracy
+*/
+
+
+cpl_image * 
+sinfo_new_fine_shift_image_in_spec_cubic_spline (cpl_image * shiftedImage, 
+                                                 double sub_shift ) ;
+
+
+/**
+   @name  sinfo_align_cube_to_reference() 
+   @memo shifts a images stacked in a cube by a given amount to 
+         sub-pixel accuracy
+   @param cube: cube containing images to shift in spectral direction
+   @param refIm: reference image (OH spectrum)
+   @param order: order of polynomial interpolation for the resampling
+   @param shift_indicator: indicator for the polynomial interpolation (0)
+                           or cubic spline interpolation shift (1).
+   @result shifted cube
+ */
+
+
+cpl_imagelist  * 
+sinfo_align_cube_to_reference (cpl_imagelist * cube,
+                                 cpl_image * refIm,
+                                 int order,
+                                 int shift_indicator ) ;
+
+
+
+#endif /*!SINFO_SHIFT_IMAGES_H*/
+
+/*--------------------------------------------------------------------------*/
diff --git a/sinfoni/sinfo_skycor.c b/sinfoni/sinfo_skycor.c
new file mode 100644
index 0000000..973204b
--- /dev/null
+++ b/sinfoni/sinfo_skycor.c
@@ -0,0 +1,7234 @@
+/* $Id: sinfo_skycor.c,v 1.50 2012/05/04 08:11:35 amodigli Exp $
+ *
+ * This file is part of the SINFONI Pipeline
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2012/05/04 08:11:35 $
+ * $Revision: 1.50 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+/*-----------------------------------------------------------------------------
+                                Includes
+ ----------------------------------------------------------------------------*/
+#include <math.h>
+#include <cpl.h>
+#include <sinfo_cpl_size.h>
+
+#include <irplib_utils.h>
+
+#include <sinfo_skycor.h>
+#include <sinfo_new_cube_ops.h>
+#include "sinfo_pfits.h"
+#include "sinfo_functions.h"
+
+#include "sinfo_msg.h"
+#include "sinfo_error.h"
+#include "sinfo_globals.h"
+#include "sinfo_utils_wrappers.h"
+#include "sinfo_utl_cube2spectrum.h"
+#include "sinfo_pro_types.h"
+/*-----------------------------------------------------------------------------
+                                Defines
+ ----------------------------------------------------------------------------*/
+
+#define BAND_H_WAVE_MIN 1.445 //not used
+#define BAND_H_WAVE_MAX 1.820 //not used
+
+#define BAND_K_WAVE_MIN 1.945 //not used
+#define BAND_K_WAVE_MAX 2.460 //not used
+
+#define BAND_J_WAVE_MIN 1.445 //not used
+#define BAND_J_WAVE_MAX 1.82  //not used
+
+#define SINFO_FIT_BKG_TEMP 280.
+#define SKY_THRES 0.95
+#define SKY_LINE_MAX_CUT 4      /* this should be 4 */
+#define SKY_LINE_MIN_CUT 4      /* this should be 4 */
+
+
+#define XCOR_YSHIFT_KS_CLIP 5      /* this should be 5 */
+
+
+#define HPLANK 6.62606876e-34;   // J s
+#define CLIGHT 2.99792458e+08;   // m / s
+#define KBOLTZ 1.3806503e-23;    // J / K
+#define AMOEBA_FTOL 1.e-5
+#define NBOUND 14
+#define NROT   25
+#define N_ITER_FIT_LM 15
+#define N_ITER_FIT_AMOEBA 10
+
+double sinfo_scale_fct=1;
+static cpl_vector* sa_vx=NULL;
+static cpl_vector* sa_vy=NULL;
+
+static cpl_vector* sa_ox=NULL;
+static cpl_vector* sa_oy=NULL;
+static cpl_vector* sa_sy=NULL;
+
+/*-----------------------------------------------------------------------------
+                            Functions prototypes
+-----------------------------------------------------------------------------*/
+cpl_vector* sinfo_sky_background_estimate(cpl_vector *spectrum,
+                                             int msize,
+                                             int fsize);
+
+
+static int
+sinfo_scales_obj_sky_cubes(cpl_imagelist* obj_cub,
+                            cpl_imagelist* sky_cub,
+                            cpl_table* bkg,
+                            cpl_table* rscale,
+                            cpl_imagelist** obj_cor);
+
+static int
+sinfo_sub_thr_bkg_from_obj_cube(cpl_imagelist* obj_cub,
+				cpl_table* int_sky,
+				cpl_imagelist** obj_cor);
+
+static cpl_vector*
+sinfo_filter_min(const cpl_vector* vi, const int size);
+
+static cpl_vector*
+sinfo_filter_max(const cpl_vector* vi, const int size);
+
+static cpl_vector*
+sinfo_filter_smo(const cpl_vector* vi, const int size);
+
+static cpl_imagelist*
+sinfo_cube_zshift_simple(cpl_imagelist* inp,
+                        const float shift);
+
+static void
+sinfo_optimise_sky_sub(const double wtol,
+                       const double line_hw,
+                       const int method,
+                       const int do_rot,
+                       cpl_table* lrange,
+                       cpl_table* lambda,
+                       cpl_table* lr41,
+                       cpl_table* lr52,
+                       cpl_table* lr63,
+                       cpl_table* lr74,
+                       cpl_table* lr02,
+                       cpl_table* lr85,
+                       cpl_table* lr20,
+                       cpl_table* lr31,
+                       cpl_table* lr42,
+                       cpl_table* lr53,
+                       cpl_table* lr64,
+                       cpl_table* lr75,
+                       cpl_table* lr86,
+                       cpl_table* lr97,
+                       cpl_table* lr00,
+                       cpl_table** int_obj,
+                       cpl_table** int_sky,
+                       cpl_table** rscale);
+
+static void
+sinfo_shift_sky(cpl_frame** sky_frm,
+                cpl_table** int_sky,
+                const double zshift);
+
+static double
+sinfo_xcorr(cpl_table* int_obj,
+            cpl_table* int_sky,
+            cpl_table* lambda,
+            const double dispersion,
+            const double line_hw);
+
+static cpl_table*
+sinfo_interpolate_sky(const cpl_table* inp,const cpl_table* lambdas);
+
+static int
+sinfo_check_screw_values(cpl_table** int_obj,
+                         cpl_table** int_sky,
+                         cpl_table* grange,
+                         const double wtol);
+
+static int
+sinfo_choose_good_sky_pixels(cpl_frame* obj_frm,
+                             cpl_image* r_img,
+                             cpl_image* g_img,
+                             const double min_frac,
+                             cpl_image** mask);
+
+
+static int
+sinfo_sum_spectra(const cpl_frame* obj,
+                  const cpl_frame* sky,
+                  cpl_image* mask,
+                  cpl_table* wrange,
+                  const int llx,
+                  const int lly,
+                  const int urx,
+                  const int ury,
+                  cpl_table** int_obj,
+                  cpl_table** int_sky);
+
+int
+sinfo_thermal_background2(cpl_table* int_sky,
+                         cpl_table* lambda,
+                         cpl_table* lrange,
+              cpl_table** bkg);
+
+static int
+sinfo_thermal_background(cpl_table* int_sky,
+                         cpl_table* lambda,
+                         cpl_table* lrange,
+                         const double temp,
+                         const int niter,
+                         const int filter_width,
+                         const double wtol,
+                         cpl_table** bkg,
+                         int* success_fit);
+
+static int
+sinfo_object_flag_sky_pixels(cpl_frame* obj_frm,
+                             cpl_table* lambda,
+                             cpl_table* mrange,
+                 cpl_imagelist* flag_data,
+                             const double tol,
+                             cpl_image** g_img,
+                             cpl_image** r_img,
+                             cpl_image** image);
+
+static int
+sinfo_object_flag_low_values(cpl_frame* obj_frm,
+                             const double cnt,
+                             const double sig,
+                             cpl_imagelist** flag_data);
+
+static int
+sinfo_object_estimate_noise(cpl_frame* obj_frm, const int obj_noise_fit,
+                            double* centre, double* noise);
+
+
+
+static int
+sinfo_set_ranges(cpl_frame* obj_frm,
+                 cpl_frame* sky_frm,
+                 cpl_parameterlist* cfg,
+                 cpl_table** lambda,
+                 cpl_table** lr41,
+                 cpl_table** lr52,
+                 cpl_table** lr63,
+                 cpl_table** lr74,
+                 cpl_table** lr02,
+                 cpl_table** lr85,
+                 cpl_table** lr20,
+                 cpl_table** lr31,
+                 cpl_table** lr42,
+                 cpl_table** lr53,
+                 cpl_table** lr64,
+                 cpl_table** lr75,
+                 cpl_table** lr86,
+                 cpl_table** lr97,
+                 cpl_table** lr00,
+                 cpl_table** lrange,
+                 cpl_table** grange,
+                 cpl_table** lambdas,
+                 cpl_table** mrange,
+                 int* sky_interp_sw,
+                 double* dispersion);
+
+
+static cpl_table*
+sinfo_table_extract_rest(cpl_table* inp,
+                         cpl_table* low,
+                         cpl_table* med,
+                         const double wtol);
+
+static int
+sinfo_get_sub_regions(cpl_table* sky,
+                      cpl_table* x1,
+                      cpl_table* pos,
+                      const double wtol,
+                      const int npixw,
+                      cpl_table** sub_regions);
+
+
+static int
+sinfo_get_obj_sky_wav_sub(cpl_table* obj,
+                          cpl_table* sky,
+                          cpl_table* wav,
+                          cpl_table* sel,
+                          const double wtol,
+                          cpl_table** sub_obj,
+                          cpl_table** sub_sky,
+                          cpl_table** sub_wav);
+
+
+static cpl_table*
+sinfo_find_rot_waves(const double w_rot[],
+                     const int npix_w,
+                     const double w_step,
+                     cpl_table* range);
+static int
+sinfo_compute_line_ratio(cpl_table* obj,
+                         cpl_table* sky,
+                         const double wtol,
+                         const int meth,
+                         const cpl_table* sel_regions,
+                         cpl_table* cont_regions,
+                         double* r);
+
+static cpl_table*
+sinfo_table_subtract_continuum(cpl_table* lin,cpl_table* cnt);
+
+static double
+sinfo_fit_bkg(double p[]);
+
+static double
+sinfo_fit_sky(double p[]);
+
+static int
+sinfo_get_line_ratio_amoeba(cpl_table* obj,
+                            cpl_table* sky,
+                            double* r);
+
+static cpl_table*
+sinfo_table_interpol(cpl_table* obj_lin,
+                     cpl_table* obj_cnt,
+                     cpl_table* sky_lin,
+                     cpl_table* sky_cnt,
+                     const double r);
+
+
+static int
+sinfo_get_line_ratio(cpl_table* obj_lin,
+                     cpl_table* obj_cnt,
+                     cpl_table* sky_lin,
+                     cpl_table* sky_cnt,
+                     const int method,
+                     double* r);
+
+static cpl_table*
+sinfo_table_shift_simple(cpl_table* inp,
+                         const char* col,
+                         const double shift);
+/*
+static int
+sinfo_table_set_column_invalid(cpl_table** int_sky,const char* col);
+*/
+static int
+sinfo_table_set(cpl_table** out,
+                const cpl_table* ref,
+                const double val,
+                const double tol);
+
+static int
+sinfo_table_threshold(cpl_table** t,
+                      const char* column,
+                      const double low_cut,
+                      const double hig_cut,
+                      const double low_ass,
+                      const double hig_ass);
+
+
+
+
+static double sinfo_fac(const double x, const double t);
+
+static int sinfo_fitbkg(const double x[],
+                        const double a[],
+                        double *result);
+static int sinfo_fitbkg_derivative(const double x[],
+                                   const double a[],
+                       double result[]);
+
+
+static int
+sinfo_convolve_kernel(cpl_table** t, const int rad);
+int
+sinfo_convolve_kernel2(cpl_table** t, const int rad);
+
+int
+sinfo_convolve_gauss(cpl_table** t, const int rad, const double fwhm);
+int
+sinfo_convolve_exp(cpl_table** t, const int rad, const double fwhm);
+
+static int
+sinfo_table_sky_obj_flag_nan(cpl_table** s,cpl_table** o, cpl_table** w);
+
+static int
+sinfo_table_set_nan_out_min_max(cpl_table** s,
+                                const char* c,
+                                const double min,
+                                const double max);
+
+
+
+
+static double
+sinfo_gaussian_amp(double area,double sigma,double x,double x0,double off);
+static double
+sinfo_gaussian_area(double amp,double sigma,double x,double x0,double off);
+
+int
+sinfo_table_smooth_column(cpl_table** t, const char* c, const int r);
+
+static int
+sinfo_image_flag_nan(cpl_image** im);
+
+static int
+sinfo_table_flag_nan(cpl_table** t,const char* label);
+
+
+
+static int
+sinfo_cnt_mask_thresh_and_obj_finite(const cpl_image* mask,
+                                     const double t,
+                                     const cpl_image* obj);
+
+
+
+
+static cpl_table*
+sinfo_interpolate(const cpl_table* inp,
+                  const cpl_table* lambdas,
+                  const char* name,
+                  const char* method);
+
+static cpl_table*
+sinfo_image2table(const cpl_image* im);
+
+static int
+sinfo_table_extract_finite(const cpl_table* in1,
+                           const cpl_table* in2,
+                                 cpl_table** ou1,
+                                 cpl_table** ou2);
+
+static cpl_table*
+sinfo_slice_z(const cpl_imagelist* cin,const int i,const int j);
+
+
+
+static cpl_imagelist*
+sinfo_imagelist_select_range(const cpl_imagelist* inp,
+                                  const cpl_table* full,
+                                  const cpl_table* good,
+                                  const double tol);
+
+
+
+static cpl_table*
+sinfo_table_select_range(cpl_table* inp,
+                              cpl_table* ref,
+                              const double tol);
+
+static int
+sinfo_table_fill_column_over_range(cpl_table** inp,
+                                   const cpl_table* ref,
+                                   const char* col,
+                                   const double val,
+                                   const double tol);
+
+
+
+
+static int
+sinfo_table_column_dindgen(cpl_table** t, const char* label);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+/**@{*/
+/*---------------------------------------------------------------------------*/
+/**
+ * @addtogroup sinfo_utl_skycor Functions to correct sky residuals on \
+                              science cubes
+ */
+/*---------------------------------------------------------------------------*/
+
+/**
+ at name sinfo_skycor_qc_new
+ at brief structure to init skycor_qc
+ at return pointer to structure
+
+*/
+sinfo_skycor_qc*
+sinfo_skycor_qc_new(void)
+ {
+   sinfo_skycor_qc * sqc;
+   sqc= cpl_malloc(sizeof(sinfo_skycor_qc));
+
+   sqc->th_fit=0;
+
+   return sqc;
+
+}
+/**
+ at name sinfo_skycor_qc_delete
+ at brief function to free a skycor_qc structure
+ at return void
+
+*/
+void
+sinfo_skycor_qc_delete(sinfo_skycor_qc** sqc)
+{
+  if((*sqc) != NULL) {
+    cpl_free(*sqc);
+    *sqc=NULL;
+  }
+}
+
+
+
+/**
+  @brief    Execute the plugin instance given by the interface
+  @param    config  parameter configuration
+  @param    obj_frm input object frm
+  @param    sky_frm input sky frm
+  @param    sqc      QC parameters
+  @param    obj_cor  corrected object cube
+  @param    int_obj  corrected object spectrum
+  @return   0 if everything is ok, -1 else
+ */
+/*---------------------------------------------------------------------------*/
+int
+sinfo_skycor(cpl_parameterlist * config,
+             cpl_frame* obj_frm,
+             cpl_frame* sky_frm,
+             sinfo_skycor_qc* sqc,
+             cpl_imagelist** obj_cor,
+             cpl_table** int_obj)
+{
+
+  cpl_table* bkg=NULL;
+
+  cpl_table* lambda=NULL;
+  cpl_table* lr41=NULL;
+  cpl_table* lr52=NULL;
+  cpl_table* lr63=NULL;
+  cpl_table* lr74=NULL;
+  cpl_table* lr02=NULL;
+  cpl_table* lr85=NULL;
+  cpl_table* lr20=NULL;
+  cpl_table* lr31=NULL;
+  cpl_table* lr42=NULL;
+  cpl_table* lr53=NULL;
+  cpl_table* lr64=NULL;
+  cpl_table* lr75=NULL;
+  cpl_table* lr86=NULL;
+  cpl_table* lr97=NULL;
+  cpl_table* lr00=NULL;
+  cpl_table* lrange=NULL;
+  cpl_table* mrange=NULL;
+  cpl_table* grange=NULL;
+  cpl_table* lambdas=NULL;
+
+  cpl_table* int_sky=NULL;
+
+  cpl_image* mask=NULL;
+  cpl_image* gpix=NULL;
+  cpl_image* ratio=NULL;
+  cpl_image* ima_sky=NULL;
+  cpl_imagelist* fdata=NULL;
+  cpl_table* rscale=NULL;
+  cpl_parameter* p=NULL;
+
+  int th_fit=0;
+  double dispersion=0;
+  double noise=0;
+  //double temp=252.69284;
+  double centre=0;
+  int sky_interp_sw=0;
+  double wshift=0;
+  double pshift=0;
+  int method=0;
+  int do_rot=0;
+  int obj_noise_fit=0;
+  int niter=3;
+  double min_frac=0.8;
+  double line_hw=7;
+  double fit_temp=280;
+  int filter_width=SINFO_SKY_BKG_FILTER_WIDTH;
+  int llx=0;
+  int lly=0;
+  int urx=64;
+  int ury=64;
+  cpl_imagelist* obj_cub=NULL;
+  cpl_imagelist* sky_cub=NULL;
+  int sub_thr_bkg=0;
+
+
+  check_nomsg(p=cpl_parameterlist_find(config,
+                "sinfoni.sinfo_utl_skycor.min_frac"));
+  check_nomsg(min_frac=cpl_parameter_get_double(p));
+
+  check_nomsg(p=cpl_parameterlist_find(config,
+                "sinfoni.sinfo_utl_skycor.line_half_width"));
+  check_nomsg(line_hw=cpl_parameter_get_double(p));
+
+
+
+  check_nomsg(p=cpl_parameterlist_find(config,
+                "sinfoni.sinfo_utl_skycor.sky_bkg_filter_width"));
+  check_nomsg(filter_width=cpl_parameter_get_int(p));
+
+  check_nomsg(p=cpl_parameterlist_find(config,
+                "sinfoni.sinfo_utl_skycor.scale_method"));
+  check_nomsg(method=cpl_parameter_get_int(p));
+
+
+
+  check_nomsg(p=cpl_parameterlist_find(config,
+                "sinfoni.sinfo_utl_skycor.rot_cor"));
+  check_nomsg(do_rot=cpl_parameter_get_bool(p));
+
+
+  check_nomsg(p=cpl_parameterlist_find(config,
+                "sinfoni.sinfo_utl_skycor.sub_thr_bkg_from_obj"));
+  check_nomsg(sub_thr_bkg=cpl_parameter_get_bool(p));
+
+
+  check_nomsg(p=cpl_parameterlist_find(config,
+                "sinfoni.sinfo_utl_skycor.fit_obj_noise"));
+  check_nomsg(obj_noise_fit=cpl_parameter_get_bool(p));
+
+
+  check_nomsg(p=cpl_parameterlist_find(config,
+                "sinfoni.sinfo_utl_skycor.niter"));
+  check_nomsg(niter=cpl_parameter_get_int(p));
+
+
+  check_nomsg(p=cpl_parameterlist_find(config,
+                "sinfoni.sinfo_utl_skycor.pshift"));
+  check_nomsg(pshift=cpl_parameter_get_double(p));
+
+
+
+  check_nomsg(p=cpl_parameterlist_find(config,
+                "sinfoni.sinfo_utl_skycor.llx"));
+  check_nomsg(llx=cpl_parameter_get_int(p));
+
+
+  check_nomsg(p=cpl_parameterlist_find(config,
+                "sinfoni.sinfo_utl_skycor.lly"));
+  check_nomsg(lly=cpl_parameter_get_int(p));
+
+
+  check_nomsg(p=cpl_parameterlist_find(config,
+                "sinfoni.sinfo_utl_skycor.urx"));
+  check_nomsg(urx=cpl_parameter_get_int(p));
+
+
+  check_nomsg(p=cpl_parameterlist_find(config,
+                "sinfoni.sinfo_utl_skycor.ury"));
+  check_nomsg(ury=cpl_parameter_get_int(p));
+
+  // set wavelength ranges
+  sinfo_msg("Set wavelength ranges");
+  ck0(sinfo_set_ranges(obj_frm,sky_frm,config,&lambda,
+                       &lr41,&lr52,&lr63,&lr74,&lr02,&lr85,&lr20,&lr31,&lr42,
+                       &lr53,&lr64,&lr75,&lr86,&lr97,&lr00,
+                       &lrange,&grange,&lambdas,&mrange,&sky_interp_sw,
+                       &dispersion),"Setting wavelength ranges");
+  //check_nomsg(cpl_table_save(grange, NULL, NULL, "out_grange.fits",
+  //CPL_IO_DEFAULT));
+
+  /*
+  sinfo_msg("lr20=%d",cpl_table_get_nrow(lr20));
+  sinfo_msg("lr31=%d",cpl_table_get_nrow(lr31));
+  sinfo_msg("lr42=%d",cpl_table_get_nrow(lr42));
+  sinfo_msg("lr53=%d",cpl_table_get_nrow(lr53));
+  sinfo_msg("lr64=%d",cpl_table_get_nrow(lr64));
+  sinfo_msg("lr75=%d",cpl_table_get_nrow(lr75));
+  sinfo_msg("lr86=%d",cpl_table_get_nrow(lr86));
+  sinfo_msg("lr97=%d",cpl_table_get_nrow(lr97));
+  sinfo_msg("lr00=%d",cpl_table_get_nrow(lr00));
+
+  sinfo_msg("min_lrange=%f",cpl_table_get_column_min(lrange,"INDEX"));
+  sinfo_msg("min_grange=%f",cpl_table_get_column_min(grange,"INDEX"));
+  sinfo_msg("min_srange=%f",cpl_table_get_column_min(lambdas,"WAVE"));
+  sinfo_msg("min_mrange=%f",cpl_table_get_column_min(mrange,"INDEX"));
+
+  sinfo_msg("max_lrange=%f",cpl_table_get_column_max(lrange,"INDEX"));
+  sinfo_msg("max_grange=%f",cpl_table_get_column_max(grange,"INDEX"));
+  sinfo_msg("max_srange=%f",cpl_table_get_column_max(lambdas,"WAVE"));
+  sinfo_msg("max_mrange=%f",cpl_table_get_column_max(mrange,"INDEX"));
+  */
+
+  sinfo_msg("Estimate noise");
+  ck0(sinfo_object_estimate_noise(obj_frm,obj_noise_fit,&centre,&noise),
+                                  "Estimating noise");
+
+  sinfo_msg("Background=%f Noise=%f",centre,noise);
+  sinfo_msg("Flag object low_levels");
+  ck0(sinfo_object_flag_low_values(obj_frm,centre,noise,&fdata),
+      "Flagging low pix");
+
+  //cpl_imagelist_save(fdata,"out_fdata.fits",
+  //                   CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT);
+
+
+  sinfo_msg("Flag sky pixels");
+  ck0(sinfo_object_flag_sky_pixels(obj_frm,lambda,mrange,fdata,dispersion,
+                                   &gpix,&ratio,&ima_sky),
+                                   "Flagging sky pixels");
+
+  //cpl_image_save(gpix,"out_gpix.fits",CPL_BPP_IEEE_FLOAT,
+  //                 NULL,CPL_IO_DEFAULT);
+  //cpl_image_save(ratio,"out_ratio.fits",CPL_BPP_IEEE_FLOAT,
+  //                 NULL,CPL_IO_DEFAULT);
+  //cpl_image_save(ima_sky,"out_ima_sky.fits",
+  //               CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT);
+
+
+
+
+  // choose pixels which seems to be good sky pixels
+  // (95% spectral pixels are flagged)
+  sinfo_msg("Choose good sky (with > 95%% good spectral) pixels");
+  ck0(sinfo_choose_good_sky_pixels(obj_frm,ratio,gpix,min_frac,&mask),
+      "Choosing good sky pixels");
+
+  //cpl_image_save(mask,"out_mask.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT);
+
+  // threshold ratio for fraction 'minfract' of spatial pixels to be 'sky'
+  //sinfo_msg("To do: flag_threshold_sky_pixels");
+
+
+  // sum spectra of flagged pixels in object and sky frames
+  sinfo_msg("Sum obj and sky spectra");
+  ck0(sinfo_sum_spectra(obj_frm,sky_frm,mask,lambda,llx,lly,urx,ury,int_obj,
+			&int_sky),"summing obj & sky spectra");
+
+  //check_nomsg(cpl_table_save(*int_obj, NULL, NULL, "out_int_obj.fits",
+  // CPL_IO_DEFAULT));
+  //check_nomsg(cpl_table_save(int_sky, NULL, NULL, "out_int_sky.fits",
+  //CPL_IO_DEFAULT));
+
+   // Computes thermal background
+  sinfo_msg("Computes thermal background");
+  /*
+  ck0(sinfo_thermal_background2(int_sky,lambda,lrange,&bkg),
+     "getting termal bkg");
+  */
+
+  ck0(sinfo_thermal_background(int_sky,lambda,lrange,fit_temp,niter,
+                               filter_width,dispersion,&bkg,&th_fit),
+      "getting termal bkg");
+
+
+  check_nomsg(cpl_table_duplicate_column(*int_obj,"INT_SKY_ORG",int_sky,"INT"));
+  check_nomsg(cpl_table_duplicate_column(*int_obj,"INT_BKG_FIT",bkg,"INT2"));
+  check_nomsg(cpl_table_duplicate_column(*int_obj,"INT_BKG_SMO",int_sky,
+                                         "INT_BKG_SMO"));
+
+  sqc->th_fit=th_fit;
+  //check_nomsg(cpl_table_save(bkg,NULL,NULL,"out_thermal_background.fits",
+  //CPL_IO_DEFAULT));
+
+
+  /*
+  ck0(sinfo_pro_save_tbl(bkg,set,set,"out_thermal_background.fits",
+             "THERMAL_BACKGROUND",NULL,cpl_func,config),
+      "Error saving %s","THERMAL_BACKGROUND");
+  */
+
+  sinfo_msg("Subtracts thermal background from integrated OH spectrum");
+  //sinfo_msg("nrow=%d %d",cpl_table_get_nrow(int_sky),
+  //                       cpl_table_get_nrow(bkg));
+  check_nomsg(cpl_table_duplicate_column(int_sky,"BKG",bkg,"INT2"));
+  check_nomsg(cpl_table_duplicate_column(int_sky,"INT0",int_sky,"INT"));
+  check_nomsg(cpl_table_subtract_columns(int_sky,"INT","BKG"));
+
+
+
+  //check_nomsg(cpl_table_duplicate_column(int_obj,"INT",
+  //                                         int_obj,"INT_OBJ_COR"));
+
+  if(sub_thr_bkg == 1) {
+    check_nomsg(cpl_table_duplicate_column(*int_obj,"THR_BKG",bkg,"INT2"));
+    check_nomsg(cpl_table_subtract_columns(*int_obj,"INT","THR_BKG"));
+  }
+
+  //check_nomsg(cpl_table_save(*int_obj, NULL, NULL, "out_int_obj.fits",
+  //CPL_IO_DEFAULT));
+  //check_nomsg(cpl_table_save(int_sky, NULL, NULL, "out_int_sky.fits",
+  //CPL_IO_DEFAULT));
+
+
+  //check_nomsg(cpl_table_erase_column(int_sky,"BKG"));
+  //check_nomsg(cpl_table_save(grange, NULL, NULL, "out_grange_6.fits",
+  //CPL_IO_DEFAULT));
+
+   //check_nomsg(cpl_table_save(int_sky, NULL, NULL, "out_int_sky_sub.fits",
+   //CPL_IO_DEFAULT));
+
+
+
+  // check for screw values at ends of spectrum
+  sinfo_msg("Checks for screw values at ends of spectrum");
+  sinfo_check_screw_values(int_obj,&int_sky,grange,dispersion);
+  //check_nomsg(cpl_table_save(grange, NULL, NULL, "out_grange_7.fits",
+  //CPL_IO_DEFAULT));
+  //check_nomsg(cpl_table_save(*int_obj, NULL, NULL, "out_int_obj_chk.fits",
+  //CPL_IO_DEFAULT));
+  //check_nomsg(cpl_table_save(int_sky, NULL, NULL, "out_int_sky_chk.fits",
+  //CPL_IO_DEFAULT));
+
+
+
+  if(sky_interp_sw == 1) {
+    sinfo_msg("Interpolate sky if necessary");
+    sinfo_interpolate_sky(int_sky,lambdas);
+  }
+
+
+  sinfo_msg("Crosscorrelate obj & sky to check for lambda offset");
+  //check_nomsg(cpl_table_save(*int_obj, NULL, NULL, "out_int_obj_chk.fits",
+  //CPL_IO_DEFAULT));
+  //check_nomsg(cpl_table_save(int_sky, NULL, NULL, "out_int_sky_chk.fits",
+  //CPL_IO_DEFAULT));
+  check_nomsg(wshift=sinfo_xcorr(*int_obj,int_sky,lambda,dispersion,line_hw));
+
+
+  //wshift=-1.7164495*dispersion;
+  sinfo_msg("Dispersion=%f",dispersion);
+  if(pshift == 0) {
+    pshift=wshift/dispersion;
+  }
+  sinfo_msg("Shift sky of %f pixels toward object",pshift);
+
+  check_nomsg(sinfo_shift_sky(&sky_frm,&int_sky,pshift));
+  //check_nomsg(cpl_table_save(*int_obj, NULL, NULL, "out_pip3_int_obj.fits",
+  //CPL_IO_DEFAULT));
+  //check_nomsg(cpl_table_save(int_sky, NULL, NULL, "out_pip3_int_sky.fits",
+  //CPL_IO_DEFAULT));
+
+
+  //DEBUG
+  sinfo_msg("Optimise sky subtraction");
+  check_nomsg(sinfo_optimise_sky_sub(dispersion,line_hw,method,do_rot,
+                                     lrange,lambda,
+                                     lr41,lr52,lr63,lr74,lr02,lr85,
+                                     lr20,lr31,lr42,lr53,lr64,lr75,
+				     lr86,lr97,lr00,int_obj,&int_sky,
+				     &rscale));
+
+
+  //check_nomsg(cpl_table_save(*int_obj, NULL, NULL, "out_int_obj.fits",
+  //CPL_IO_DEFAULT));
+  //check_nomsg(cpl_table_save(int_sky, NULL, NULL, "out_int_sky.fits",
+  //CPL_IO_DEFAULT));
+
+
+  sinfo_msg("Apply same scaling to whole cubes");
+
+
+  cknull_nomsg(obj_cub=cpl_imagelist_load(cpl_frame_get_filename(obj_frm),
+                                          CPL_TYPE_DOUBLE,0));
+  cknull_nomsg(sky_cub=cpl_imagelist_load(cpl_frame_get_filename(sky_frm),
+                                          CPL_TYPE_DOUBLE,0));
+
+
+
+
+  if(sub_thr_bkg == 1) {
+    ck0_nomsg(sinfo_sub_thr_bkg_from_obj_cube(obj_cub,int_sky,obj_cor));
+  } else {
+    check_nomsg(*obj_cor=cpl_imagelist_duplicate(obj_cub));
+  }
+
+  ck0_nomsg(sinfo_scales_obj_sky_cubes(*obj_cor,sky_cub,bkg,rscale,obj_cor));
+
+  check_nomsg(cpl_table_name_column(*int_obj,"INT","INT_OBJ_ORG"));
+  check_nomsg(cpl_table_name_column(*int_obj,"INTC","INT_OBJ_COR"));
+  check_nomsg(cpl_table_name_column(*int_obj,"SKYC","INT_SKY_COR"));
+
+
+ cleanup:
+  sinfo_free_table(&rscale);
+  sinfo_free_imagelist(&fdata);
+
+  sinfo_free_table(&bkg);
+  sinfo_free_table(&lambda);
+  sinfo_free_table(&lrange);
+  sinfo_free_table(&mrange);
+  sinfo_free_table(&grange);
+  sinfo_free_table(&lambdas);
+  sinfo_free_image(&mask);
+
+  sinfo_free_table(&lr41);
+  sinfo_free_table(&lr52);
+  sinfo_free_table(&lr63);
+  sinfo_free_table(&lr74);
+  sinfo_free_table(&lr02);
+  sinfo_free_table(&lr85);
+  sinfo_free_table(&lr20);
+  sinfo_free_table(&lr31);
+  sinfo_free_table(&lr42);
+  sinfo_free_table(&lr53);
+  sinfo_free_table(&lr64);
+  sinfo_free_table(&lr75);
+  sinfo_free_table(&lr86);
+  sinfo_free_table(&lr97);
+  sinfo_free_table(&lr00);
+
+  sinfo_free_image(&gpix);
+  sinfo_free_image(&ratio);
+  sinfo_free_image(&ima_sky);
+  //sinfo_free_table(&int_obj);
+  sinfo_free_table(&int_sky);
+
+  sinfo_free_imagelist(&obj_cub);
+  sinfo_free_imagelist(&sky_cub);
+
+  if (cpl_error_get_code() != CPL_ERROR_NONE) {
+    return -1;
+  } else {
+    return 0;
+  }
+
+
+}
+
+/*-------------------------------------------------------------------------*/
+/**
+  @name        sinfo_set_ranges
+  @memo        defines several wavelength ranges
+  @param obj_frm input object frame
+  @param int_sky input sky spectra table
+  @param obj_cor  output object cube corrected for thermal background
+  @return    int 0, -1
+  @doc
+
+  Returns in case of succes -1 else.
+ */
+/*--------------------------------------------------------------------------*/
+
+
+static int
+sinfo_sub_thr_bkg_from_obj_cube(cpl_imagelist* obj_cub,
+				cpl_table* int_sky,
+				cpl_imagelist** obj_cor)
+
+{
+  double* pthr_bkg=NULL;
+  int zsz=0;
+  int k=0;
+  cpl_image* imgo=NULL;
+
+  check_nomsg(pthr_bkg=cpl_table_get_data_double(int_sky,"BKG"));
+  check_nomsg(zsz=cpl_imagelist_get_size(obj_cub));
+  check_nomsg(*obj_cor=cpl_imagelist_duplicate(obj_cub));
+
+  for(k=0;k<zsz;k++) {
+    check_nomsg(imgo=cpl_imagelist_get(obj_cub,k));
+    check_nomsg(cpl_image_subtract_scalar(imgo,pthr_bkg[k]));
+    check_nomsg(cpl_imagelist_set(*obj_cor,imgo,k));
+  }
+
+ cleanup:
+  if (cpl_error_get_code() != CPL_ERROR_NONE) {
+    return -1;
+  } else {
+    return 0;
+  }
+
+}
+
+/*-------------------------------------------------------------------------*/
+/**
+  @name        sinfo_set_ranges
+  @memo        defines several wavelength ranges
+  @param obj_frm input object frame
+  @param sky_frm input sky frame
+  @param lambda  output wavelength range
+  @param lr41    output wavelength range corresponding to transition 4-1
+  @param lr52    output wavelength range corresponding to transition 5-2
+  @param lr63    output wavelength range corresponding to transition 6-3
+  @param lr74    output wavelength range corresponding to transition 7-4
+  @param lr02    output wavelength range corresponding to transition 0-2
+  @param lr85    output wavelength range corresponding to transition 8-5
+  @param lr20    output wavelength range corresponding to transition 2-0
+  @param lr31    output wavelength range corresponding to transition 3-1
+  @param lr42    output wavelength range corresponding to transition 4-2
+  @param lr53    output wavelength range corresponding to transition 5-3
+  @param lr64    output wavelength range corresponding to transition 6-4
+  @param lr75    output wavelength range corresponding to transition 7-5
+  @param lr86    output wavelength range corresponding to transition 8-6
+  @param lr97    output wavelength range corresponding to transition 9-7
+  @param lr00    output wavelength range corresponding to transition 0-0
+  @param lrange  output wavelength range corresponding to ...
+  @param grange  output wavelength range corresponding to grange
+  @param lambdas output wavelength range corresponding to skyrange
+  @param mrange  output wavelength range corresponding to mrange
+  @return    int 0, -1
+  @doc
+
+  Returns in case of succes -1 else.
+ */
+/*--------------------------------------------------------------------------*/
+
+
+int
+sinfo_set_ranges(cpl_frame* obj_frm,
+                 cpl_frame* sky_frm,
+                 cpl_parameterlist* cfg,
+                 cpl_table** lambda,
+                 cpl_table** lr41,
+                 cpl_table** lr52,
+                 cpl_table** lr63,
+                 cpl_table** lr74,
+                 cpl_table** lr02,
+                 cpl_table** lr85,
+                 cpl_table** lr20,
+                 cpl_table** lr31,
+                 cpl_table** lr42,
+                 cpl_table** lr53,
+                 cpl_table** lr64,
+                 cpl_table** lr75,
+                 cpl_table** lr86,
+                 cpl_table** lr97,
+                 cpl_table** lr00,
+                 cpl_table** lrange,
+                 cpl_table** grange,
+                 cpl_table** lambdas,
+                 cpl_table** mrange,
+                 int* sky_interp_sw,
+                 double* dispersion)
+
+{
+
+  cpl_propertylist* plist=NULL;
+  double crval_obj=0;
+  double cdelt_obj=0;
+  double crpix_obj=0;
+  int xsize_obj=0;
+  int ysize_obj=0;
+  int zsize_obj=0;
+
+
+  double crval_sky=0;
+  double cdelt_sky=0;
+  double crpix_sky=0;
+  int xsize_sky=0;
+  int ysize_sky=0;
+  int zsize_sky=0;
+
+  int nrow=0;
+  /* wavelength min-max J-H-K band */
+  const double w_j_min=1.100;
+  const double w_j_max=1.400;
+  const double w_h_min=1.445;
+  const double w_h_max=1.820;
+  const double w_k_min=1.945;
+  const double w_k_max=2.460;
+
+  double ws=0;
+  double we=0;
+  double mean=0;
+
+  cpl_parameter* p=NULL;
+
+  /* wavelength boundaries between line groups corresponding
+     to transitions 5-2 to 9-7 */
+  double w_bound[NBOUND]={1.067,1.125,1.196,1.252,1.289,
+                          1.400,1.472,1.5543,1.6356,1.7253,
+                          1.840,1.9570,2.095,2.300};
+
+  cpl_table* tmp_tbl=NULL;
+  cpl_table* add1=NULL;
+
+
+
+  /* Get Object relevant information */
+  cknull_nomsg(plist=cpl_propertylist_load(cpl_frame_get_filename(obj_frm),0));
+  check_nomsg(crval_obj=sinfo_pfits_get_crval3(plist));
+  check_nomsg(cdelt_obj=sinfo_pfits_get_cdelt3(plist));
+  check_nomsg(crpix_obj=sinfo_pfits_get_crpix3(plist));
+  check_nomsg(xsize_obj=sinfo_pfits_get_naxis1(plist));
+  check_nomsg(ysize_obj=sinfo_pfits_get_naxis2(plist));
+  check_nomsg(zsize_obj=sinfo_pfits_get_naxis3(plist));
+
+  sinfo_free_propertylist(&plist);
+  *dispersion=cdelt_obj;
+
+  /* defines object related wavelength ranges */
+  check_nomsg(*lambda=cpl_table_new(zsize_obj));
+  cpl_table_new_column(*lambda,"WAVE",CPL_TYPE_DOUBLE);
+  cpl_table_new_column(*lambda,"INDEX",CPL_TYPE_DOUBLE);
+  check_nomsg(sinfo_table_column_dindgen(lambda,"INDEX"));
+  check_nomsg(sinfo_table_column_dindgen(lambda,"WAVE"));
+
+  check_nomsg(cpl_table_add_scalar(*lambda,"WAVE",1.));
+  check_nomsg(cpl_table_subtract_scalar(*lambda,"WAVE",crpix_obj));
+  check_nomsg(cpl_table_multiply_scalar(*lambda,"WAVE",cdelt_obj));
+  check_nomsg(cpl_table_add_scalar(*lambda,"WAVE",crval_obj));
+
+
+
+
+  cknull_nomsg(*lr41=sinfo_where_tab_min_max(*lambda,
+                                             "WAVE",
+                                             CPL_NOT_LESS_THAN,
+                                             w_j_min,
+                                             CPL_LESS_THAN,
+                                             w_bound[0]));
+
+  cknull_nomsg(*lr52=sinfo_where_tab_min_max(*lambda,
+                                             "WAVE",
+                                             CPL_NOT_LESS_THAN,
+                                             w_bound[0],
+                                             CPL_LESS_THAN,
+                                             w_bound[1]));
+
+  cknull_nomsg(*lr63=sinfo_where_tab_min_max(*lambda,
+                                             "WAVE",
+                                             CPL_NOT_LESS_THAN,
+                                             w_bound[1],
+                                             CPL_LESS_THAN,
+                                             w_bound[2]));
+
+
+  cknull_nomsg(*lr74=sinfo_where_tab_min_max(*lambda,
+                                             "WAVE",
+                                             CPL_NOT_LESS_THAN,
+                                             w_bound[2],
+                                             CPL_LESS_THAN,
+                                             w_bound[3]));
+
+ cknull_nomsg(*lr20=sinfo_where_tab_min_max(*lambda,
+                                             "WAVE",
+                                             CPL_NOT_LESS_THAN,
+                                             w_bound[3],
+                                             CPL_LESS_THAN,
+                                             w_bound[4]));
+
+ cknull_nomsg(*lr02=sinfo_where_tab_min_max(*lambda,
+                                             "WAVE",
+                                             CPL_NOT_LESS_THAN,
+                                             w_bound[4],
+                                             CPL_LESS_THAN,
+                                             w_bound[5]));
+
+
+ cknull_nomsg(*lr85=sinfo_where_tab_min_max(*lambda,
+                                             "WAVE",
+                                             CPL_NOT_LESS_THAN,
+                                             w_bound[5],
+                                             CPL_LESS_THAN,
+                                             w_bound[6]));
+
+  cknull_nomsg(*lr31=sinfo_where_tab_min_max(*lambda,
+                                             "WAVE",
+                                             CPL_NOT_LESS_THAN,
+                                             w_bound[6],
+                                             CPL_LESS_THAN,
+                                             w_bound[7]));
+
+  cknull_nomsg(*lr42=sinfo_where_tab_min_max(*lambda,
+                                             "WAVE",
+                                             CPL_NOT_LESS_THAN,
+                                             w_bound[7],
+                                             CPL_LESS_THAN,
+                                             w_bound[8]));
+
+  cknull_nomsg(*lr53=sinfo_where_tab_min_max(*lambda,
+                                             "WAVE",
+                                             CPL_NOT_LESS_THAN,
+                                             w_bound[8],
+                                             CPL_LESS_THAN,
+                                             w_bound[9]));
+
+  cknull_nomsg(*lr64=sinfo_where_tab_min_max(*lambda,
+                                             "WAVE",
+                                             CPL_NOT_LESS_THAN,
+                                             w_bound[0],
+                                             CPL_LESS_THAN,
+                                             w_bound[10]));
+
+  cknull_nomsg(*lr75=sinfo_where_tab_min_max(*lambda,
+                                             "WAVE",
+                                             CPL_NOT_LESS_THAN,
+                                             w_bound[10],
+                                             CPL_LESS_THAN,
+                                             w_bound[11]));
+
+  cknull_nomsg(*lr86=sinfo_where_tab_min_max(*lambda,
+                                             "WAVE",
+                                             CPL_NOT_LESS_THAN,
+                                             w_bound[11],
+                                             CPL_LESS_THAN,
+                                             w_bound[12]));
+
+  cknull_nomsg(*lr97=sinfo_where_tab_min_max(*lambda,
+                                             "WAVE",
+                                             CPL_NOT_LESS_THAN,
+                                             w_bound[12],
+                                             CPL_LESS_THAN,
+                                             w_bound[13]));
+
+  cknull_nomsg(*lr00=sinfo_where_tab_min_max(*lambda,
+                                             "WAVE",
+                                              CPL_NOT_LESS_THAN,
+                                              w_bound[13],
+                                              CPL_LESS_THAN,
+                                              w_k_max));
+
+  /* lrange */
+  cknull_nomsg(*lrange=sinfo_where_tab_min_max(*lambda,
+                                               "WAVE",
+                                               CPL_NOT_LESS_THAN,
+                                               w_j_min,
+                                               CPL_NOT_GREATER_THAN,
+                                               w_j_max));
+
+
+
+  cknull_nomsg(add1=sinfo_where_tab_min_max(*lambda,
+                                               "WAVE",
+                                               CPL_NOT_LESS_THAN,
+                                               w_h_min,
+                                               CPL_NOT_GREATER_THAN,
+                                               w_h_max));
+
+  check_nomsg(nrow=cpl_table_get_nrow(*lrange));
+  check_nomsg(cpl_table_insert(*lrange,add1,nrow));
+  sinfo_free_table(&add1);
+
+  cknull_nomsg(add1=sinfo_where_tab_min_max(*lambda,
+                                               "WAVE",
+                                               CPL_NOT_LESS_THAN,
+                                               w_k_min,
+                                               CPL_NOT_GREATER_THAN,
+                                               w_k_max));
+
+
+  check_nomsg(nrow=cpl_table_get_nrow(*lrange));
+  check_nomsg(cpl_table_insert(*lrange,add1,nrow));
+  sinfo_free_table(&add1);
+
+
+  /* mrange */
+  cknull_nomsg(*grange=sinfo_where_tab_min_max(*lambda,
+                                               "WAVE",
+                                               CPL_NOT_LESS_THAN,
+                                               1.10,
+                                               CPL_NOT_GREATER_THAN,
+                                               1.35));
+
+
+
+
+  cknull_nomsg(add1=sinfo_where_tab_min_max(*lambda,
+                                               "WAVE",
+                                               CPL_NOT_LESS_THAN,
+                                               1.5,
+                                               CPL_NOT_GREATER_THAN,
+                                               1.7));
+
+  check_nomsg(nrow=cpl_table_get_nrow(*grange));
+  check_nomsg(cpl_table_insert(*grange,add1,nrow));
+  sinfo_free_table(&add1);
+
+
+
+  cknull_nomsg(add1=sinfo_where_tab_min_max(*lambda,
+                                            "WAVE",
+                                            CPL_NOT_LESS_THAN,
+                                            2.0,
+                                            CPL_NOT_GREATER_THAN,
+                                            2.3));
+
+  check_nomsg(nrow=cpl_table_get_nrow(*grange));
+  check_nomsg(cpl_table_insert(*grange,add1,nrow));
+  sinfo_free_table(&add1);
+
+
+  /* Get Sky relevant information */
+  cknull_nomsg(plist=cpl_propertylist_load(cpl_frame_get_filename(sky_frm),0));
+  check_nomsg(crval_sky=sinfo_pfits_get_crval3(plist));
+  check_nomsg(cdelt_sky=sinfo_pfits_get_cdelt3(plist));
+  check_nomsg(crpix_sky=sinfo_pfits_get_crpix3(plist));
+  check_nomsg(xsize_sky=sinfo_pfits_get_naxis1(plist));
+  check_nomsg(ysize_sky=sinfo_pfits_get_naxis2(plist));
+  check_nomsg(zsize_sky=sinfo_pfits_get_naxis3(plist));
+  sinfo_free_propertylist(&plist);
+
+  /* defines sky related wavelength ranges */
+  check_nomsg(*lambdas=cpl_table_new(zsize_sky));
+  cpl_table_new_column(*lambdas,"WAVE",CPL_TYPE_DOUBLE);
+  check_nomsg(sinfo_table_column_dindgen(lambdas,"WAVE"));
+
+  check_nomsg(cpl_table_add_scalar(*lambdas,"WAVE",1.));
+  check_nomsg(cpl_table_subtract_scalar(*lambdas,"WAVE",crpix_sky));
+  check_nomsg(cpl_table_multiply_scalar(*lambdas,"WAVE",cdelt_sky));
+  check_nomsg(cpl_table_add_scalar(*lambdas,"WAVE",crval_sky));
+
+  check_nomsg(p=cpl_parameterlist_find(cfg,"sinfoni.sinfo_utl_skycor.mask_ws"));
+  check_nomsg(ws=cpl_parameter_get_double(p));
+  check_nomsg(p=cpl_parameterlist_find(cfg,"sinfoni.sinfo_utl_skycor.mask_we"));
+  check_nomsg(we=cpl_parameter_get_double(p));
+  if((ws != SINFO_MASK_WAVE_MIN) || (we != SINFO_MASK_WAVE_MAX)) {
+    cknull_nomsg(*mrange=sinfo_where_tab_min_max(*lambda,"WAVE",
+                                                 CPL_NOT_LESS_THAN,ws,
+                                                 CPL_NOT_GREATER_THAN,we));
+   } else {
+     check_nomsg(*mrange=cpl_table_duplicate(*lrange));
+  }
+
+
+  check_nomsg(cpl_table_duplicate_column(*lambda,"WDIFF",*lambdas,"WAVE"));
+  check_nomsg(cpl_table_subtract_columns(*lambda,"WDIFF","WAVE"));
+  check_nomsg(mean=cpl_table_get_column_mean(*lambda,"WDIFF"));
+  check_nomsg(nrow=cpl_table_get_nrow(*lambda));
+  sinfo_msg_warning("diff %f",nrow*mean);
+  if((fabs(nrow*mean) > 0) || (zsize_obj != zsize_sky)) {
+    sinfo_msg("We have to interpolate sky frame - this is not good");
+    *sky_interp_sw=1;
+  }
+
+
+  return 0;
+
+ cleanup:
+  sinfo_free_table(&add1);
+  sinfo_free_table(&tmp_tbl);
+  sinfo_free_propertylist(&plist);
+  return -1;
+
+}
+
+/*-------------------------------------------------------------------------*/
+/**
+  @name        sinfo_table_dindgen
+  @memo        Fill a table column with values from 0 to table_size-1
+  @param    t     table to be filled
+  @param    label name of table column
+  @return    int 0, -1
+  @doc
+
+  Returns in case of succes -1 else.
+ */
+/*--------------------------------------------------------------------------*/
+
+static int
+sinfo_table_column_dindgen(cpl_table** t, const char* label)
+{
+
+  int sz=0;
+  int i=0;
+
+  cknull(*t,"Null input vector");
+  check(sz=cpl_table_get_nrow(*t),"Getting size of a vector");
+  for(i=0;i<sz;i++) {
+    cpl_table_set(*t,label,i,(double)i);
+  }
+
+  return 0;
+ cleanup:
+  return -1;
+
+}
+
+/*-------------------------------------------------------------------------*/
+/**
+  @name        sinfo_sum_spectra
+  @memo        Find the obj and sky spectra by collapsing each plane signal
+  @param    obj_frm  object frame
+  @param    sky_frm  sky    frame
+  @param    mask     mask ?
+  @param    int_obj  obj spectrum table
+  @param    int_sky  sky spectrum table
+  @return    int 0 (if success), -1 (else)
+ */
+/*--------------------------------------------------------------------------*/
+
+
+int
+sinfo_sum_spectra(const cpl_frame* obj_frm,
+                  const cpl_frame* sky_frm,
+                  cpl_image* mask,
+                  cpl_table* wrange,
+                  const int llx,
+                  const int lly,
+                  const int urx,
+                  const int ury,
+                  cpl_table** int_obj,
+                  cpl_table** int_sky)
+{
+
+
+
+  cpl_image* obj_slice=NULL;
+  cpl_image* sky_slice=NULL;
+  cpl_image* gslice=NULL;
+  cpl_image* pos_tmp=NULL;
+  cpl_image* msk_tmp=NULL;
+  cpl_imagelist* obj=NULL;
+  cpl_imagelist* sky=NULL;
+
+
+  cpl_table* loop=NULL;
+  cpl_table* opos_tbl=NULL;
+  cpl_table* spos_tbl=NULL;
+  cpl_table* tmp_tbl=NULL;
+  cpl_table* loop_tbl=NULL;
+
+  double med=0;
+  double sdv=0;
+  double avg=0;
+
+  int zsize=0;
+  int i=0;
+  int pos_i=0;
+
+  // sum spectra of flagged spaxels
+
+  cknull_nomsg(obj=cpl_imagelist_load(cpl_frame_get_filename(obj_frm),
+                                      CPL_TYPE_DOUBLE,0));
+  cknull_nomsg(sky=cpl_imagelist_load(cpl_frame_get_filename(sky_frm),
+                                      CPL_TYPE_DOUBLE,0));
+
+  check_nomsg(zsize=cpl_imagelist_get_size(obj));
+  check_nomsg(*int_obj = cpl_table_new(zsize));
+  check_nomsg(*int_sky = cpl_table_new(zsize));
+  check_nomsg(cpl_table_duplicate_column(*int_obj,"WAVE",wrange,"WAVE"));
+  check_nomsg(cpl_table_duplicate_column(*int_sky,"WAVE",wrange,"WAVE"));
+  check_nomsg(cpl_table_new_column(*int_obj,"INT",CPL_TYPE_DOUBLE));
+  check_nomsg(cpl_table_new_column(*int_sky,"INT",CPL_TYPE_DOUBLE));
+  check_nomsg(cpl_table_fill_column_window_double(*int_obj,"INT",0,zsize,0));
+  check_nomsg(cpl_table_fill_column_window_double(*int_sky,"INT",0,zsize,0));
+
+  //loop = where(mask > 0.5);
+  //TO BE REMOVED: loop_tbl is not used
+  cknull_nomsg(loop_tbl=sinfo_image2table(mask));
+  check_nomsg(cpl_table_and_selected_double(loop_tbl,"VALUE",
+                                            CPL_GREATER_THAN,0.5));
+  check_nomsg(loop=cpl_table_extract_selected(loop_tbl));
+  sinfo_free_table(&loop_tbl);
+  sinfo_free_table(&loop);
+
+  //Determines object spectrum
+  for (i=0;i<zsize;i++) {
+    check_nomsg(obj_slice = cpl_imagelist_get(obj,i));
+
+    //pos = where(mask > 0.5 && finite(obj_slice),pos_i);
+    pos_i=sinfo_cnt_mask_thresh_and_obj_finite(mask,0.5,obj_slice);
+    if (pos_i >= 1) {
+      if ((pos_i) < 3 ) {
+    //int_obj[i] = mean(obj_slice[pos]);
+        //TODO here obj_slice should be considered only on pos:
+        //     one should do a selection/thresholding
+        check_nomsg(cpl_table_set_double(*int_obj,"INT",i,
+					 cpl_image_get_mean_window(obj_slice,
+								   llx,lly,
+								   urx,ury)));
+      } else {
+        // select only poisitions where mask>0.5 and obj is finite
+    // gslice = obj_slice[pos];
+        //sinfo_msg("obj pos_i=%d",pos_i);
+
+        check_nomsg(gslice = cpl_image_duplicate(obj_slice));
+        check_nomsg(sinfo_image_flag_nan(&gslice));
+    /*
+        sinfo_msg("obj: min=%f max=%f",
+                  cpl_image_get_min(obj_slice),
+          cpl_image_get_max(obj_slice));
+    */
+        //check_nomsg(cpl_image_threshold(gslice,SINFO_DBL_MIN,3.0e6,1,0));
+        //check_nomsg(cpl_image_multiply(gslice,mask));
+        if(cpl_image_count_rejected(gslice) < 2048) { //2048=64*64/2
+
+	  check_nomsg(med = cpl_image_get_median_window(gslice,llx,lly,urx,ury));
+	  check_nomsg(sdv = cpl_image_get_stdev_window(gslice,llx,lly,urx,ury));
+	  //sinfo_msg("med=%f sdv=%f",med,sdv);
+	  //avg = mean(gslice[where(gslice < med+3*sdv && gslice > med-3*sdv)]);
+	  check_nomsg(cpl_image_threshold(gslice,med-3*sdv,med+3*sdv,0,0));
+	  check_nomsg(avg= cpl_image_get_mean_window(gslice,llx,lly,urx,ury));
+	  check_nomsg(cpl_table_set_double(*int_obj,"INT",i,avg));
+	} else {
+	  check_nomsg(cpl_table_set_invalid(*int_obj,"INT",i));
+	}
+
+        sinfo_free_image(&gslice);
+        //sinfo_msg("sky int=%f",avg);
+      }
+    }
+
+    //Determines sky spectrum
+    check_nomsg(sky_slice = cpl_imagelist_get(sky,i));
+    //pos = where(mask > 0.5 and finite(sky_slice),pos_i);
+    pos_i=sinfo_cnt_mask_thresh_and_obj_finite(mask,0.5,sky_slice);
+    if (pos_i >= 1) {
+      if ((pos_i) < 3) {
+    //int_obj[i] = mean(obj_slice[pos]);
+        //TODO here obj_slice should be considered only on pos:
+        //     one should do a selection/thresholding
+        check_nomsg(cpl_table_set_double(*int_sky,"INT",i,
+					 cpl_image_get_mean_window(sky_slice,
+								   llx,lly,
+								   urx,ury)));
+      } else {
+        //sinfo_msg("pos_i=%d",pos_i);
+        // select only poisitions where mask>0.5 and obj is finite
+    // gslice = obj_slice[pos];
+        check_nomsg(gslice = cpl_image_duplicate(sky_slice));
+        check_nomsg(sinfo_image_flag_nan(&gslice));
+        //check_nomsg(cpl_image_threshold(gslice,SINFO_DBL_MIN,3.0e6,1,0));
+        //check_nomsg(cpl_image_multiply(gslice,mask));
+        if(cpl_image_count_rejected(gslice) < 2048) { //2048=64*64/2
+
+	check_nomsg(med = cpl_image_get_median_window(gslice,llx,lly,urx,ury));
+	check_nomsg(sdv = cpl_image_get_stdev_window(gslice,llx,lly,urx,ury));
+        //avg = mean(gslice[where(gslice < med+3*sdv && gslice > med-3*sdv)]);
+        check_nomsg(cpl_image_threshold(gslice,med-3*sdv,med+3*sdv,0,0));
+	check_nomsg(avg= cpl_image_get_mean_window(gslice,llx,lly,urx,ury));
+        check_nomsg(cpl_table_set_double(*int_sky,"INT",i,avg));
+	} else {
+	  check_nomsg(cpl_table_set_invalid(*int_sky,"INT",i));
+	}
+        sinfo_free_image(&gslice);
+    /*
+        if(i<100) {
+           sinfo_msg("sky: wave=%f int=%f",
+                      cpl_table_get_double(*int_sky,"WAVE",i,&status),avg);
+
+    }
+    */
+      }
+    }
+  }
+
+  sinfo_free_imagelist(&obj);
+  sinfo_free_imagelist(&sky);
+
+
+  return 0;
+
+ cleanup:
+  sinfo_free_image(&gslice);
+  sinfo_free_image(&pos_tmp);
+  sinfo_free_image(&msk_tmp);
+  sinfo_free_table(&tmp_tbl);
+  sinfo_free_table(&opos_tbl);
+  sinfo_free_table(&spos_tbl);
+  sinfo_free_table(&loop_tbl);
+  sinfo_free_table(&loop);
+  sinfo_free_imagelist(&obj);
+  sinfo_free_imagelist(&sky);
+
+  return -1;
+}
+
+
+
+
+
+/*-------------------------------------------------------------------------*/
+/**
+  @name        sinfo_cnt_mask_thresh_and_obj_finite
+  @memo        count pixel values satisfying conditions
+  @param    mask input mask frame
+  @param    t    input mask min threshold
+  @param    obj  input mask frame
+  @return    No of points satisfying condition or -1
+  @doc
+
+ */
+/*--------------------------------------------------------------------------*/
+
+
+static int
+sinfo_cnt_mask_thresh_and_obj_finite(const cpl_image* mask,
+                                     const double t,
+                                     const cpl_image* obj)
+{
+
+  int cnt=0;
+  int sxm=0;
+  int sym=0;
+  int sxo=0;
+  int syo=0;
+  int i=0;
+  const double* pm=NULL;
+  const double* po=NULL;
+
+  check_nomsg(sxm=cpl_image_get_size_x(mask));
+  check_nomsg(sym=cpl_image_get_size_y(mask));
+  check_nomsg(sxo=cpl_image_get_size_x(obj));
+  check_nomsg(syo=cpl_image_get_size_y(obj));
+  if( sxm != sxo || sym != syo) {
+    goto cleanup;
+  }
+  check_nomsg(pm=cpl_image_get_data_double_const(mask));
+  check_nomsg(po=cpl_image_get_data_double_const(obj));
+
+  for(i=0;i<sxm*sym;i++) {
+
+    if( (pm[i] > t) && (!irplib_isnan(po[i]))) { cnt++; }
+
+  }
+
+  return cnt;
+ cleanup:
+  return -1;
+
+}
+
+
+
+
+
+/*-------------------------------------------------------------------------*/
+/**
+  @name        sinfo_flag_nan
+  @memo        reject as bad pix image NANs
+  @param    im input image frame
+  @return    if success
+                   The number of bad bixels
+                else
+                   -1
+
+ */
+/*--------------------------------------------------------------------------*/
+
+
+static int
+sinfo_image_flag_nan(cpl_image** im)
+{
+
+  int cnt=0;
+  int sx=0;
+  int sy=0;
+  int i=0;
+  int j=0;
+
+  double* pi=NULL;
+
+  check_nomsg(sx=cpl_image_get_size_x(*im));
+  check_nomsg(sy=cpl_image_get_size_y(*im));
+  check_nomsg(pi=cpl_image_get_data_double(*im));
+
+  for(j=0;j<sy;j++) {
+    for(i=0;i<sx;i++) {
+     if(irplib_isnan(pi[j*sx+i])) {
+    check_nomsg(cpl_image_reject(*im,i+1,j+1));
+    cnt++;
+      }
+    }
+  }
+  //sinfo_msg("No bad pixels: %d",cnt);
+  return cnt;
+ cleanup:
+  return -1;
+
+}
+
+
+
+/*-------------------------------------------------------------------------*/
+/**
+  @name        sinfo_object_estimate_noise
+  @memo        Estimate object noise
+  @param    obj_frm input object frame
+  @param    centre  output centre of object's intensity histogram
+  @param    noise   output noise
+  @return    int
+                    if success: 0
+                    else -1
+
+ */
+/*--------------------------------------------------------------------------*/
+
+int
+sinfo_object_estimate_noise(cpl_frame* obj_frm,
+                            const int obj_noise_fit,
+                            double* centre,
+                            double* noise)
+{
+
+  const int nbins=HISTO_NBINS;
+
+  int xsz=0;
+  int ysz=0;
+  int zsz=0;
+  int n=0;
+  int i=0;
+  int k=0;
+  int r=0;
+
+  int max_h=0;
+  int min_x=0;
+  int max_x=0;
+  int status=0;
+  int max_pos=0;
+  int min_pos=0;
+  int min_xi_sz=0;
+  int ndist=0;
+
+  double avg_d=0;
+  double std_d=0;
+  double hmin=0;
+  double hmax=0;
+  double kappa=3;
+
+  double* pdata=NULL;
+  double* disth=NULL;
+  double* distx=NULL;
+
+  double peak=0;
+  double tempc=0;
+  double value=0;
+  double thres=0;
+  double val=0;
+  double x0=0;
+  double sigma=0;
+  double area=0;
+  double offset=0;
+  //double mse=0;
+  //double chired=0;
+
+  cpl_propertylist* plist=NULL;
+  cpl_imagelist* obj_cub=NULL;
+  cpl_table* data_tbl=NULL;
+  cpl_table* histo=NULL;
+  cpl_image* img=NULL;
+  cpl_table* dist=NULL;
+  cpl_table* min_xi=NULL;
+  cpl_table* tmp_tbl1=NULL;
+  cpl_table* tmp_tbl2=NULL;
+  cpl_vector* vx=NULL;
+  cpl_vector* vy=NULL;
+  cpl_vector* sx=NULL;
+  cpl_vector* sy=NULL;
+  int counter=0;
+
+  // Get Object relevant information
+  cknull_nomsg(plist=cpl_propertylist_load(cpl_frame_get_filename(obj_frm),0));
+  check_nomsg(xsz=sinfo_pfits_get_naxis1(plist));
+  check_nomsg(ysz=sinfo_pfits_get_naxis2(plist));
+  check_nomsg(zsz=sinfo_pfits_get_naxis3(plist));
+  sinfo_free_propertylist(&plist);
+
+  cknull_nomsg(obj_cub=cpl_imagelist_load(cpl_frame_get_filename(obj_frm),
+                                          CPL_TYPE_DOUBLE,0));
+
+  n=xsz*ysz*zsz;
+  check_nomsg(data_tbl=cpl_table_new(n));
+  check_nomsg(cpl_table_new_column(data_tbl,"DATA",CPL_TYPE_DOUBLE));
+
+
+  for(k=0;k<zsz;k++) {
+    check_nomsg(img=cpl_imagelist_get(obj_cub,k));
+    check_nomsg(pdata=cpl_image_get_data(img));
+    for(i=0;i<xsz*ysz;i++) {
+      if(!irplib_isnan(pdata[i])) {
+    cpl_table_set_double(data_tbl,"DATA",r,pdata[i]);
+        r++;
+      }
+    }
+  }
+  sinfo_free_imagelist(&obj_cub);
+
+  check_nomsg(cpl_table_erase_invalid(data_tbl));
+  check_nomsg(avg_d=cpl_table_get_column_mean(data_tbl,"DATA"));
+  check_nomsg(std_d=cpl_table_get_column_stdev(data_tbl,"DATA"));
+
+  //cpl_table_save(data_tbl, NULL, NULL, "out_data.fits",CPL_IO_DEFAULT);
+  hmin=avg_d-kappa*std_d;
+  hmax=avg_d+kappa*std_d;
+  //sinfo_msg("mean=%f stdv=%f",avg_d,std_d);
+  //sinfo_msg("hmin=%f hmax=%f",hmin,hmax);
+  sinfo_msg("Computes histogram");
+  ck0(sinfo_histogram(data_tbl,nbins,hmin,hmax,&histo),"building histogram");
+
+  value=(double)(hmax-hmin)/nbins/2.;
+  //sinfo_msg("value=%10.8f",value);
+
+
+  while(min_xi_sz < HISTO_MIN_SIZE && counter < 10) {
+    counter++;
+    check_nomsg(max_h=cpl_table_get_column_max(histo,"HY"));
+    //cpl_table_save(histo, NULL, NULL, "out_pippo.fits", CPL_IO_DEFAULT);
+    check_nomsg(max_pos=sinfo_table_get_index_of_max(histo,"HY",CPL_TYPE_INT));
+    //sinfo_msg("max_pos=%d",max_pos);
+
+    /*
+    check_nomsg(max_pos=sinfo_extract_table_rows(histo,"HY",
+                                                 CPL_EQUAL_TO,max_h));
+    sinfo_msg("size max_pos %d",cpl_table_get_nrow(max_pos));
+    sinfo_msg("value max_pos %d",cpl_table_get_int(max_pos,"HY",0,&status));
+    */
+    min_x=max_pos-1;
+    max_x=max_pos+2;
+    //sinfo_msg("min_x=%d max_x=%d",min_x,max_x);
+
+    sinfo_free_table(&tmp_tbl1);
+    //sinfo_msg("x selection threshold: %f %d",
+    //          cpl_table_get(histo,"HL",max_pos,&status),max_pos);
+    check_nomsg(tmp_tbl1=sinfo_extract_table_rows(histo,"HL",
+                                                  CPL_LESS_THAN,
+                                 cpl_table_get(histo,"HL",max_pos,&status)));
+    thres=cpl_table_get_column_max(tmp_tbl1,"HY")/HISTO_Y_CUT;
+    //sinfo_msg("threshold=%f",thres);
+
+
+    sinfo_free_table(&min_xi);
+    check_nomsg(min_xi=sinfo_extract_table_rows(tmp_tbl1,"HY",
+                                                CPL_GREATER_THAN,thres));
+
+    //cpl_table_save(min_xi, NULL, NULL, "out_min_xi.fits", CPL_IO_DEFAULT);
+
+
+
+    min_xi_sz=cpl_table_get_nrow(min_xi);
+    val=cpl_table_get(min_xi,"HL",0,&status);
+
+    check_nomsg(min_pos=sinfo_table_get_index_of_val(histo,"HL",val,
+                                                     CPL_TYPE_DOUBLE));
+    //sinfo_msg("min_pos=%d max_pos=%d max(h)=%d min_xi_sz=%d x[maxpos[0]]=%f",
+    //           min_pos,   max_pos,   max_h,    min_xi_sz, val);
+
+
+
+    if (min_xi_sz > 0) {
+      min_x = min_pos-HISTO_X_LEFT_CUT*(max_pos-min_pos);
+      max_x = max_pos+HISTO_X_RIGHT_CUT*(max_pos-min_pos);
+    }
+
+    //sinfo_msg("min_x=%d max_x=%d",min_x,max_x);
+    check_nomsg(hmin=sinfo_table_column_interpolate(histo,"HL",min_x));
+    check_nomsg(hmax=sinfo_table_column_interpolate(histo,"HL",max_x));
+    //sinfo_msg("hmin=%f hmax=%f min_xi_sz=%d",hmin,hmax,min_xi_sz);
+    //cpl_table_save(histo, NULL, NULL, "out_histo.fits", CPL_IO_DEFAULT);
+    sinfo_free_table(&histo);
+    ck0(sinfo_histogram(data_tbl,nbins,hmin,hmax,&histo),"building histogram");
+    //cpl_table_save(histo, NULL, NULL, "out_histo1.fits", CPL_IO_DEFAULT);
+    check_nomsg(cpl_table_add_scalar(histo,"HL",(hmax-hmin)/nbins/2));
+    //cpl_table_save(histo, NULL, NULL, "out_histo2.fits", CPL_IO_DEFAULT);
+
+
+
+  }
+  sinfo_free_table(&data_tbl);
+  sinfo_free_table(&min_xi);
+
+  //cpl_table_save(histo, NULL, NULL, "out_histo.fits", CPL_IO_DEFAULT);
+
+  check_nomsg(peak=cpl_table_get_column_max(histo,"HY"));
+  //sinfo_msg("peak=%f",peak);
+  sinfo_free_table(&tmp_tbl1);
+
+  check_nomsg(tmp_tbl1=sinfo_extract_table_rows(histo,"HY",CPL_EQUAL_TO,peak));
+
+  //cpl_table_save(tmp_tbl1, NULL, NULL, "out_tmp_tbl1.fits", CPL_IO_DEFAULT);
+
+
+  check_nomsg(*centre=cpl_table_get_column_mean(tmp_tbl1,"HL"));
+  //sinfo_msg("Background level=%f",*centre);
+
+  sinfo_free_table(&tmp_tbl1);
+  check_nomsg(tmp_tbl1=sinfo_extract_table_rows(histo,"HY",
+                                                CPL_GREATER_THAN,
+                                                peak/HISTO_Y_CUT));
+  sinfo_free_table(&tmp_tbl2);
+  check_nomsg(tmp_tbl2=sinfo_extract_table_rows(tmp_tbl1,"HY",
+                                                CPL_LESS_THAN,peak));
+  sinfo_free_table(&tmp_tbl1);
+
+  check_nomsg(tempc=*centre-cpl_table_get_column_min(tmp_tbl2,"HL"));
+  //sinfo_msg("min HX %f",cpl_table_get_column_min(tmp_tbl2,"HL"));
+  sinfo_free_table(&tmp_tbl2);
+  //sinfo_msg("Tempc=%f",tempc);
+  check_nomsg(dist=sinfo_where_tab_min_max(histo,"HL",
+                 CPL_GREATER_THAN,*centre-HISTO_DIST_TEMPC_MIN_FCT*tempc,
+                 CPL_NOT_GREATER_THAN,*centre+HISTO_DIST_TEMPC_MAX_FCT*tempc));
+
+  offset=cpl_table_get_column_min(histo,"HY");
+  sinfo_free_table(&histo);
+
+
+  check_nomsg(ndist=cpl_table_get_nrow(dist));
+  check_nomsg(cpl_table_cast_column(dist,"HY","HYdouble",CPL_TYPE_DOUBLE));
+  check_nomsg(disth=cpl_table_get_data_double(dist,"HYdouble"));
+  check_nomsg(distx=cpl_table_get_data_double(dist,"HL"));
+  //cpl_table_save(dist, NULL, NULL, "out_dist.fits", CPL_IO_DEFAULT);
+
+  //TODO
+  //gaussfit(distx,disty,dista,nterms=3);
+  //*noise=dista[2];
+  *noise=tempc/2;
+  /* THIS DOES NOT WORK */
+  //sinfo_msg("FWHM/2=%f",*noise);
+
+  if(obj_noise_fit == 1) {
+    check_nomsg(vy=cpl_vector_wrap(ndist,disth));
+    check_nomsg(vx=cpl_vector_wrap(ndist,distx));
+    check_nomsg(sx=cpl_vector_new(ndist));
+    check_nomsg(cpl_vector_fill(sx,1.));
+    check_nomsg(sy=cpl_vector_duplicate(sx));
+    x0=*centre;
+    sigma=tempc/2;
+
+    check_nomsg(cpl_vector_fit_gaussian(vx,NULL,
+                                        vy,NULL,
+                                        CPL_FIT_ALL,
+                                        &x0,&sigma,&area,&offset,
+                                        NULL,NULL,NULL));
+    //sinfo_msg("Gauss fit parameters:"
+    //          "x0=%f sigma=%f area=%f offset=%f mse=%f chired=%f",
+    //           x0,sigma,area,offset,mse,chired);
+    //sinfo_msg("Background level=%f",*centre);
+    //sinfo_msg("Noise=%f",sigma);
+    *noise=sigma;
+    sinfo_unwrap_vector(&vx);
+    sinfo_unwrap_vector(&vy);
+    sinfo_free_my_vector(&sx);
+    sinfo_free_my_vector(&sy);
+  }
+  sinfo_free_table(&dist);
+  //*noise=18.7448;
+  //*noise=20.585946;
+  return 0;
+
+ cleanup:
+  sinfo_free_imagelist(&obj_cub);
+  sinfo_free_propertylist(&plist);
+  sinfo_free_table(&min_xi);
+  sinfo_free_table(&tmp_tbl1);
+  sinfo_free_table(&tmp_tbl2);
+  sinfo_free_table(&histo);
+  sinfo_free_table(&dist);
+  sinfo_free_table(&data_tbl);
+  sinfo_free_my_vector(&sx);
+  sinfo_free_my_vector(&sy);
+  sinfo_unwrap_vector(&vx);
+  sinfo_unwrap_vector(&vy);
+
+  return -1;
+
+}
+
+
+/**
+ at name sinfo_where_tab_min_max
+ at brief finds table rows comprised between a min and a max
+ at param t   input table
+ at param col column involved in selection
+ at param op1 first operation of selection
+ at param v1  first threshold value
+ at param op2 second operation of selection
+ at param v2  second threshold value
+ at return new allocated sub table satisfying conditions
+*/
+
+cpl_table*
+sinfo_where_tab_min_max(cpl_table* t,
+                        const char* col,
+                        cpl_table_select_operator op1,
+                        const double v1,
+                        cpl_table_select_operator op2,
+                        const double v2)
+{
+
+  cpl_table* res=NULL;
+  cpl_table* tmp=NULL;
+
+  check_nomsg(cpl_table_and_selected_double(t,col,op1,v1));
+  check_nomsg(tmp=cpl_table_extract_selected(t));
+  check_nomsg(cpl_table_and_selected_double(tmp,col,op2,v2));
+  check_nomsg(res=cpl_table_extract_selected(tmp));
+  check_nomsg(cpl_table_select_all(t));
+  sinfo_free_table(&tmp);
+
+  return res;
+
+ cleanup:
+  sinfo_free_table(&tmp);
+  sinfo_free_table(&res);
+
+  return NULL;
+
+}
+/*-------------------------------------------------------------------------*/
+/**
+  @name        sinfo_histogram
+  @memo        computes histogram
+  @param data  input data table
+  @param nbins input size of histogram bin
+  @param min   input min data to be considered in histogram
+  @param max   input max data to be considered in histogram
+  @param hist  output histogram: table with results:
+       # H: histogram
+       # X: array of data values corresponding to the center of each bin
+       # Xmean: 1D array corresponding to the mean of the data values entering
+                each histogram bin
+  Returns in case of succes -1 else.
+  @doc
+
+       Compute the histogram with the IDL intrinsic function HISTOGRAM, using
+       the input options specified by the parameters Dmin, Dmax, Bin. All
+       the computations are performed in floating-point arithmetics.
+       Then compute arrays of values corresponding to each histogram bin,
+       useful for plots, fitting, etc.
+
+
+ */
+/*--------------------------------------------------------------------------*/
+
+int
+sinfo_histogram(const cpl_table* data,
+                const int nbins,
+                const double min,
+                const double max,
+                cpl_table** histo)
+{
+  cpl_table* tmp_tbl1=NULL;
+  cpl_table* tmp_tbl2=NULL;
+  cpl_table* dat=NULL;
+  int ntot=0;
+  int i=0;
+  int* phy=NULL;
+  double* pdt=NULL;
+  /* double* phx=NULL; */
+
+  double vtmp=0;
+  double vstp=0;
+  double vmax=0;
+  double vmin=0;
+
+  int h=0;
+  check_nomsg(dat=cpl_table_duplicate(data));
+  check_nomsg(cpl_table_cast_column(dat,"DATA","DDATA",CPL_TYPE_DOUBLE));
+  /*
+  sinfo_msg("min=%f max=%f",
+            cpl_table_get_column_min(dat,"DDATA"),
+            cpl_table_get_column_max(dat,"DDATA"));
+  */
+  check_nomsg(cpl_table_and_selected_double(dat,"DDATA",
+                                            CPL_NOT_GREATER_THAN,max));
+  /*
+  check_nomsg(cpl_table_and_selected_double(dat,"DDATA",CPL_LESS_THAN,max));
+  */
+  check_nomsg(tmp_tbl1=cpl_table_extract_selected(dat));
+  /*
+  sinfo_msg("min=%f max=%f",
+             cpl_table_get_column_min(tmp_tbl1,"DDATA"),
+             cpl_table_get_column_max(tmp_tbl1,"DDATA"));
+  */
+  /*
+  check_nomsg(cpl_table_and_selected_double(tmp_tbl1,"DDATA",
+                                            CPL_NOT_LESS_THAN,min));
+  */
+  check_nomsg(cpl_table_and_selected_double(tmp_tbl1,"DDATA",
+                                            CPL_GREATER_THAN,min));
+  check_nomsg(tmp_tbl2=cpl_table_extract_selected(tmp_tbl1));
+  /*
+  sinfo_msg("min=%f max=%f",
+             cpl_table_get_column_min(tmp_tbl2,"DDATA"),
+             cpl_table_get_column_max(tmp_tbl2,"DDATA"));
+  */
+  sinfo_free_table(&tmp_tbl1);
+  /*
+  check_nomsg(tmp_tbl1=sinfo_extract_table_rows(dat,"DDATA",
+                                                CPL_NOT_GREATER_THAN,max));
+  check_nomsg(tmp_tbl2=sinfo_extract_table_rows(tmp_tbl1,"DDATA",
+                                                CPL_NOT_LESS_THAN,min));
+  */
+
+  check_nomsg(ntot=cpl_table_get_nrow(tmp_tbl2));
+  /* not necessry to sort:
+    check_nomsg(sinfo_sort_table_1(tmp_tbl2,"DDATA",FALSE));*/
+  check_nomsg(vmin=cpl_table_get_column_min(tmp_tbl2,"DDATA"));
+  check_nomsg(vmax=cpl_table_get_column_max(tmp_tbl2,"DDATA"));
+  vstp=(vmax-vmin)/(nbins-1);
+  /* sinfo_msg("vmin=%f vmax=%f step=%f",vmin,vmax,vstp); */
+  check_nomsg(*histo=cpl_table_new(nbins));
+  check_nomsg(cpl_table_new_column(*histo,"HX",CPL_TYPE_DOUBLE));
+  check_nomsg(cpl_table_new_column(*histo,"HL",CPL_TYPE_DOUBLE));
+  check_nomsg(cpl_table_new_column(*histo,"HY",CPL_TYPE_INT));
+
+  /*check_nomsg(cpl_table_fill_column_window(*histo,"HX",0,nbins,0)); */
+  check_nomsg(cpl_table_fill_column_window(*histo,"HL",0,nbins,0));
+  check_nomsg(cpl_table_fill_column_window(*histo,"HY",0,nbins,0));
+
+  check_nomsg(phy=cpl_table_get_data_int(*histo,"HY"));
+  /*check_nomsg(phx=cpl_table_get_data_double(*histo,"HX")); */
+  check_nomsg(pdt=cpl_table_get_data_double(dat,"DATA"));
+
+  for(i=0;i<nbins;i++) {
+    cpl_table_set_double(*histo,"HX",i,(double)i);
+    vtmp=vmin+i*vstp;
+    cpl_table_set_double(*histo,"HL",i,vtmp);
+  }
+  h=0;
+
+  for(i=0;i<ntot;i++) {
+    h=floor((pdt[i]-vmin)/vstp);
+    if((h<nbins) && (h>-1)) {
+      phy[h]++;
+    }
+  }
+  //cpl_table_save(*histo, NULL, NULL, "out_histo_p5.fits", CPL_IO_DEFAULT);
+
+  sinfo_free_table(&tmp_tbl2);
+  sinfo_free_table(&dat);
+
+
+  return 0;
+ cleanup:
+  sinfo_free_table(&tmp_tbl1);
+  sinfo_free_table(&tmp_tbl2);
+  sinfo_free_table(&dat);
+
+  return -1;
+
+}
+
+
+/*-------------------------------------------------------------------------*/
+/**
+  @name        sinfo_object_flag_low_values
+  @memo        flags low values in object frame: val>=cnt+2*sig
+  @param obj_frm  input object frame
+  @param cnt      input value involved in thresold
+  @param sig      input value involved in threshold
+  @param flag_data output imagelist
+  @return 0 in case of succes -1 else.
+ */
+/*--------------------------------------------------------------------------*/
+
+int
+sinfo_object_flag_low_values(cpl_frame* obj_frm,
+                             const double cnt,
+                             const double sig,
+                             cpl_imagelist** flag_data)
+{
+
+  int xsz=0;
+  int ysz=0;
+  int zsz=0;
+  int n=0;
+  int i=0;
+  int k=0;
+  int r=0;
+
+  cpl_propertylist* plist=NULL;
+  cpl_table* data_tbl=NULL;
+  cpl_table* flag_tbl=NULL;
+  cpl_image* img=NULL;
+  cpl_imagelist* obj_cub=NULL;
+
+  double* pdata=NULL;
+  double* pflag=NULL;
+
+ /* Get Object relevant information */
+  cknull_nomsg(plist=cpl_propertylist_load(cpl_frame_get_filename(obj_frm),0));
+  check_nomsg(xsz=sinfo_pfits_get_naxis1(plist));
+  check_nomsg(ysz=sinfo_pfits_get_naxis2(plist));
+  check_nomsg(zsz=sinfo_pfits_get_naxis3(plist));
+  sinfo_free_propertylist(&plist);
+
+  cknull_nomsg(obj_cub=cpl_imagelist_load(cpl_frame_get_filename(obj_frm),
+                                          CPL_TYPE_DOUBLE,0));
+
+  n=xsz*ysz*zsz;
+  check_nomsg(data_tbl=cpl_table_new(n));
+  check_nomsg(cpl_table_new_column(data_tbl,"DATA",CPL_TYPE_DOUBLE));
+
+  for(k=0;k<zsz;k++) {
+    check_nomsg(img=cpl_imagelist_get(obj_cub,k));
+    check_nomsg(pdata=cpl_image_get_data_double(img));
+    for(i=0;i<xsz*ysz;i++) {
+      if(!irplib_isnan(pdata[i])) {
+    check_nomsg(cpl_table_set_double(data_tbl,"DATA",r,pdata[i]));
+        r++;
+      }
+    }
+  }
+
+  check_nomsg(cpl_table_erase_invalid(data_tbl));
+  //sinfo_msg("Background level: %f Noise: %f",cnt,sig);
+  check_nomsg(cpl_table_and_selected_double(data_tbl,"DATA",
+                                           CPL_LESS_THAN,cnt+2*sig));
+  check_nomsg(flag_tbl=cpl_table_extract_selected(data_tbl));
+  sinfo_free_table(&data_tbl);
+  //check_nomsg(cpl_table_save(flag_tbl,NULL,NULL,
+  //                             "out_flag.fits",CPL_IO_DEFAULT));
+  sinfo_free_table(&flag_tbl);
+
+  check_nomsg(*flag_data=cpl_imagelist_new());
+  for(i=0;i<zsz;i++) {
+    check_nomsg(img=cpl_image_new(xsz,ysz,CPL_TYPE_DOUBLE));
+    check_nomsg(cpl_image_add_scalar(img,0));
+    check_nomsg(cpl_imagelist_set(*flag_data,cpl_image_duplicate(img),i));
+    sinfo_free_image(&img);
+  }
+  for(k=0;k<zsz;k++) {
+    check_nomsg(img=cpl_imagelist_get(*flag_data,k));
+    pflag=cpl_image_get_data_double(cpl_imagelist_get(*flag_data,k));
+    pdata=cpl_image_get_data_double(cpl_imagelist_get(obj_cub,k));
+    for(i=0;i<xsz*ysz;i++) {
+      if((!irplib_isnan(pdata[i])) && pdata[i] < (cnt+2*sig)) {
+        pflag[i]=1;
+      }
+    }
+  }
+
+  sinfo_free_imagelist(&obj_cub);
+
+
+
+
+  return 0;
+
+ cleanup:
+  sinfo_free_propertylist(&plist);
+  sinfo_free_imagelist(&obj_cub);
+  sinfo_free_table(&data_tbl);
+  sinfo_free_table(&flag_tbl);
+
+  return -1;
+}
+
+/*-------------------------------------------------------------------------*/
+/**
+  @name        sinfo_object_flag_sky_pixels
+  @memo        flags sky pixels in cube object
+  @param obj_frm  input object frame
+  @param lambda   input wavelength range table
+  @param mrange   input wavelength range table
+  @param flag_data input imagelist with flagged data
+  @param tol      input tolerance
+  @param g_img    output image with good pixels
+  @param r_img    output image with ratio good/all pixels
+  @param image    output sky image
+  @return 0 in case of succes, -1 else.
+ */
+/*--------------------------------------------------------------------------*/
+
+
+int
+sinfo_object_flag_sky_pixels(cpl_frame* obj_frm,
+                             cpl_table* lambda,
+                             cpl_table* mrange,
+                 cpl_imagelist* flag_data,
+                             const double tol,
+                             cpl_image** g_img,
+                             cpl_image** r_img,
+                             cpl_image** image)
+{
+
+  int xsz=0;
+  int ysz=0;
+  int zsz=0;
+  int i=0;
+  int j=0;
+  int gpix_i=0;
+  double tot=0;
+  double all_pix=0;
+  double flag_pix=0;
+  double ratio=0;
+
+  double* pr_img=NULL;
+  double* pg_img=NULL;
+  double* pimage=NULL;
+  cpl_propertylist* plist=NULL;
+  cpl_imagelist* osel=NULL;
+  cpl_imagelist* fsel=NULL;
+  cpl_table* gpix=NULL;
+  cpl_table* gspec=NULL;
+  cpl_table* fspec=NULL;
+  cpl_table* ospec=NULL;
+
+  cpl_imagelist* obj_cub=NULL;
+
+  /* Get Object relevant information */
+  cknull_nomsg(plist=cpl_propertylist_load(cpl_frame_get_filename(obj_frm),0));
+
+  check_nomsg(xsz=sinfo_pfits_get_naxis1(plist));
+  check_nomsg(ysz=sinfo_pfits_get_naxis2(plist));
+  check_nomsg(zsz=sinfo_pfits_get_naxis3(plist));
+  sinfo_free_propertylist(&plist);
+  cknull_nomsg(obj_cub=cpl_imagelist_load(cpl_frame_get_filename(obj_frm),
+                                                      CPL_TYPE_DOUBLE,0));
+
+  /* Flag sky pixels in data cube */
+  /* create images */
+  check_nomsg(*r_img=cpl_image_new(xsz,ysz,CPL_TYPE_DOUBLE));
+  check_nomsg(*g_img=cpl_image_new(xsz,ysz,CPL_TYPE_DOUBLE));
+  check_nomsg(*image=cpl_image_new(xsz,ysz,CPL_TYPE_DOUBLE));
+
+  cknull_nomsg(pr_img=cpl_image_get_data_double(*r_img));
+  cknull_nomsg(pg_img=cpl_image_get_data_double(*g_img));
+  cknull_nomsg(pimage=cpl_image_get_data_double(*image));
+
+  /* TODO */
+  // fill image points:
+  // g_img: mask with at least half good pixels along spectral range
+  // r_img: mask with ratio of good pixels along spectral range
+  // image: image with mean of spectrum over good pixels
+
+  //check_nomsg(cpl_table_save(lambda, NULL, NULL,
+  //                             "out_lambda.fits", CPL_IO_DEFAULT));
+  //check_nomsg(cpl_table_save(mrange, NULL, NULL,
+  //                             "out_mrange.fits", CPL_IO_DEFAULT));
+
+  cknull_nomsg(osel=sinfo_imagelist_select_range(obj_cub,lambda,
+                                                      mrange,tol));
+
+  sinfo_free_imagelist(&obj_cub);
+
+  cknull_nomsg(fsel=sinfo_imagelist_select_range(flag_data,lambda,
+                                                      mrange,tol));
+
+  //check_nomsg(cpl_imagelist_save(osel,"out_osel.fits",
+  //                               CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT));
+  //check_nomsg(cpl_imagelist_save(fsel,"out_fsel.fits",
+  //                               CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT));
+
+  for(j=0;j<ysz;j++) {
+    for(i=0;i<xsz;i++) {
+      // consider only planes in the proper wavelegth ranges
+      cknull_nomsg(ospec=sinfo_slice_z(osel,i,j));
+      cknull_nomsg(fspec=sinfo_slice_z(fsel,i,j));
+      // consider only finite pixels
+      check_nomsg(gpix_i=sinfo_table_extract_finite(ospec,fspec,&gpix,&gspec));
+      //sinfo_msg("gpix_i=%d",gpix_i);
+      if(gpix_i > 0) {
+        // build two arrays of proper size
+        all_pix=(double)gpix_i;
+    /*
+        sinfo_msg("flagspec: min=%f max=%f",
+                  cpl_table_get_column_min(fspec,"VALUE"),
+                  cpl_table_get_column_max(fspec,"VALUE"));
+        sinfo_msg("good flagspec: min=%f max=%f",
+                  cpl_table_get_column_min(gspec,"VALUE"),
+                  cpl_table_get_column_max(gspec,"VALUE"));
+        sinfo_msg("nfspec=%d",cpl_table_get_nrow(fspec));
+        check_nomsg(cpl_table_save(fspec, NULL, NULL,
+                    "out_fspec.fits",CPL_IO_DEFAULT));
+        check_nomsg(cpl_table_save(gspec, NULL, NULL,
+                    "out_gspec.fits", CPL_IO_DEFAULT));
+    */
+        //check_nomsg(flag_pix=cpl_table_and_selected_double(fspec,"VALUE",
+        //                                              CPL_GREATER_THAN,0.5));
+        //sinfo_msg("all_pix=%f flag_pix=%f",all_pix,flag_pix);
+
+        check_nomsg(flag_pix=cpl_table_and_selected_double(gspec,"VALUE",
+                                                        CPL_GREATER_THAN,0.5));
+        //sinfo_msg("all_pix=%f flag_pix=%f",all_pix,flag_pix);
+        // flag_pix = float(n_elements(where(fspec[gpix] > 0.5)));
+        // compute the ratio between the two arrays
+        ratio=flag_pix/all_pix;
+        // considers only pixels with have at least half good pixels
+        if(all_pix > cpl_table_get_nrow(mrange)/2) {
+          pg_img[i+j*xsz]=1;
+          pr_img[i+j*xsz]=ratio;
+        }
+        //mean(ospec(gpix))
+        check_nomsg(pimage[i+j*xsz]=cpl_table_get_column_mean(gpix,"VALUE"));
+        //sinfo_msg("ix=%d iy=%d r=%f",i,j,ratio);
+      }
+      sinfo_free_table(&ospec);
+      sinfo_free_table(&fspec);
+      sinfo_free_table(&gpix);
+      sinfo_free_table(&gspec);
+
+    } /* end for over i */
+  } /* end for over j */
+  sinfo_free_imagelist(&osel);
+  sinfo_free_imagelist(&fsel);
+
+  /*
+  cpl_image_save(*r_img,"out_r_img.fits",CPL_BPP_IEEE_FLOAT,
+                 NULL,CPL_IO_DEFAULT);
+  cpl_image_save(*g_img,"out_g_img.fits",CPL_BPP_IEEE_FLOAT,
+                 NULL,CPL_IO_DEFAULT);
+  cpl_image_save(*image,"out_image.fits",CPL_BPP_IEEE_FLOAT,
+                 NULL,CPL_IO_DEFAULT);
+  */
+  // get total(g_arr)
+  check_nomsg(tot=cpl_image_get_flux(*g_img));
+  if(tot < 1) {
+    sinfo_msg_error("no good spaxel");
+    goto cleanup;
+  }
+
+  return 0;
+
+
+ cleanup:
+  sinfo_free_propertylist(&plist);
+  sinfo_free_imagelist(&obj_cub);
+  sinfo_free_imagelist(&osel);
+  sinfo_free_imagelist(&fsel);
+   sinfo_free_table(&ospec);
+  sinfo_free_table(&fspec);
+  sinfo_free_table(&gpix);
+  sinfo_free_table(&gspec);
+
+  return -1;
+
+
+}
+
+/**
+ at name sinfo_choose_good_sky_pixels
+ at param obj_frm  input object frame
+ at param r_img    input image ratio good/all pixels
+ at param g_img    input image with good pixels
+ at param min_frac input threshold setting the minimum fraction of good pixels
+ at param mask     output mask indicating pixels which satisfy the condition
+*/
+int
+sinfo_choose_good_sky_pixels(cpl_frame* obj_frm,
+                             cpl_image* r_img,
+                             cpl_image* g_img,
+                             const double min_frac,
+                             cpl_image** mask)
+{
+
+  int xsz=0;
+  int ysz=0;
+  int zsz=0;
+  int r2i=0;
+  int status=0;
+  double tot=0;
+  double thres=SKY_THRES;
+  double cum_x_max=0;
+
+  cpl_image* r2img=NULL;
+  cpl_propertylist* plist=NULL;
+  cpl_table* cum=NULL;
+  cpl_table* hcum=NULL;
+  cpl_table* thres_tbl=NULL;
+
+  cknull_nomsg(plist=cpl_propertylist_load(cpl_frame_get_filename(obj_frm),0));
+  check_nomsg(xsz=sinfo_pfits_get_naxis1(plist));
+  check_nomsg(ysz=sinfo_pfits_get_naxis2(plist));
+  check_nomsg(zsz=sinfo_pfits_get_naxis3(plist));
+  sinfo_free_propertylist(&plist);
+
+  // choose pixels which seem to be sky (ie 95% of spectral pixels are flagged)
+  check_nomsg(*mask=cpl_image_new(xsz,ysz,CPL_TYPE_DOUBLE));
+  //r2 = where(r_img >= thres,r2i);
+  // count good pixels: set to 0 what < thres and to 1 what > thres
+  check_nomsg(r2img=cpl_image_duplicate(r_img));
+  check_nomsg(cpl_image_threshold(r2img,thres,thres,0,1));
+  check_nomsg(r2i=cpl_image_get_flux(r2img));
+
+  if(r2i>0) {
+    sinfo_free_image(&(*mask));
+    check_nomsg(*mask=cpl_image_duplicate(r2img));
+  }
+  sinfo_free_image(&r2img);
+  check_nomsg(r2img=cpl_image_duplicate(r_img));
+  check_nomsg(cpl_image_threshold(r2img,thres,SINFO_DBL_MAX,0,SINFO_DBL_MAX));
+  sinfo_free_image(&r2img);
+
+  check_nomsg(tot=cpl_image_get_flux(g_img));
+
+
+   sinfo_msg("%2.2d spaxels (%4.1f %% of good pixels) are designated as sky",
+             r2i,100.*r2i/tot);
+
+   //threshold ratio for fraction 'minfrac' of spatial pixels to be 'sky'
+   if (1.*r2i/tot < min_frac) {
+     sinfo_msg("this is too small - will increase it to %4.1f %%",
+           100.*min_frac);
+     check_nomsg(cum=cpl_table_new(xsz*ysz));
+     check_nomsg(cpl_table_new_column(cum,"X",CPL_TYPE_DOUBLE));
+     sinfo_table_column_dindgen(&cum,"X");
+     check_nomsg(cpl_table_add_scalar(cum,"X",1.));
+
+     //hcum = r_img(sort(r_img));
+     hcum = sinfo_image2table(r_img);
+     check_nomsg(sinfo_sort_table_1(hcum,"VALUE",FALSE));
+
+     //thresh = hcum[where(xcum/max(xcum) >= 1.-min_frac)];
+     check_nomsg(cpl_table_duplicate_column(cum,"H",hcum,"VALUE"));
+     check_nomsg(cum_x_max=cpl_table_get_column_max(cum,"X"));
+     check_nomsg(cpl_table_duplicate_column(cum,"R",cum,"X"));
+     check_nomsg(cpl_table_divide_scalar(cum,"R",cum_x_max));
+     check_nomsg(cpl_table_and_selected_double(cum,"R",
+                                              CPL_NOT_LESS_THAN,
+                                              (1.-min_frac)));
+     check_nomsg(thres_tbl=cpl_table_extract_selected(cum));
+
+     check_nomsg(thres = cpl_table_get(thres_tbl,"R",0,&status));
+     //*mask[where(r_img >= thresh)] = 1;
+     sinfo_free_image(&(*mask));
+
+
+     check_nomsg(*mask=cpl_image_duplicate(r_img));
+     check_nomsg(cpl_image_threshold(*mask,thres,thres,0,1));
+  }
+  sinfo_free_table(&cum);
+  sinfo_free_table(&hcum);
+  sinfo_free_table(&thres_tbl);
+
+  return 0;
+ cleanup:
+
+  sinfo_free_propertylist(&plist);
+  sinfo_free_image(&r2img);
+  sinfo_free_table(&cum);
+  sinfo_free_table(&hcum);
+  sinfo_free_table(&thres_tbl);
+
+  return -1;
+
+}
+
+/*-------------------------------------------------------------------------*/
+/**
+  @name        sinfo_fit_bkg
+  @memo        Computes chi2 of difference INT(sky)-thermal_background
+
+  @param sa      pointer to sinfo_amoeba structure
+  @param p           input fit parameters
+  Returns chi2= sum_i[int(sky)_i-therma_i]
+ */
+/*--------------------------------------------------------------------------*/
+
+static double
+sinfo_fit_bkg(double p[])
+
+{
+ double* px=NULL;
+  double* py=NULL;
+  double* pv=NULL;
+  cpl_vector* vtmp=NULL;
+  double max=0;
+  int i=0;
+  int np=0;
+
+  double chi2=0;
+
+  check_nomsg(px= cpl_vector_get_data(sa_vx));
+  check_nomsg(py= cpl_vector_get_data(sa_vy));
+  check_nomsg(np= cpl_vector_get_size(sa_vx));
+  check_nomsg(vtmp=cpl_vector_duplicate(sa_vy));
+  check_nomsg(pv=cpl_vector_get_data(vtmp));
+
+  for(i=0;i<np;i++) {
+    pv[i]=sinfo_fac(px[i],p[2]);
+    //sinfo_msg("x=%g p=%g",px[i],pv[i]);
+  }
+  check_nomsg(max=cpl_vector_get_max(vtmp));
+  if(max> 0) {
+    check_nomsg(cpl_vector_divide_scalar(vtmp,max));
+    check_nomsg(cpl_vector_multiply_scalar(vtmp,p[1]));
+    check_nomsg(cpl_vector_add_scalar(vtmp,p[0]));
+  }
+
+
+  for(i=0;i<np;i++) {
+    chi2+=(py[i]-pv[i])*(py[i]-pv[i]);
+  }
+  sinfo_free_my_vector(&vtmp);
+  return chi2;
+ cleanup:
+  sinfo_free_my_vector(&vtmp);
+  return -1;
+
+}
+
+
+/*-------------------------------------------------------------------------*/
+/**
+  @name        sinfo_termal_background2
+  @memo        computes thermal emission background from the sky at a i
+                given temperature
+  @param int_sky      input sky spectrum table
+  @param lambda       input wavelength table
+  @param lrange       input wavelength table
+  @param temp         input temperature in Kelvin
+  @param bkg          output background
+  Returns in case of succes -1 else.
+ */
+/*--------------------------------------------------------------------------*/
+
+int
+sinfo_thermal_background2(cpl_table* int_sky,
+                         cpl_table* lambda,
+                         cpl_table* lrange,
+                         cpl_table** bkg)
+{
+
+  int n2=0;
+  int i=0;
+  int j=0;
+  int nrow=0;
+
+  cpl_table* tmp1=NULL;
+  cpl_table* tmp2=NULL;
+
+  double max=0;
+  double wmin=0;
+  double wmax=0;
+  double p0[3];
+  const int MP=4;
+  const int NP=3;
+  double y[MP];
+  double** ap=NULL;
+  int nfunc=0;
+  int status=0;
+  int row=0;
+  double bkg_min=0;
+  double bkg_max=0;
+  double p0_min=0;
+  double p0_max=0;
+  double p1_min=0;
+  double p1_max=0;
+  double p2_min=0;
+  double p2_max=0;
+  double* pw=NULL;
+  double* pf=NULL;
+
+  ap=(double**) cpl_calloc(MP,sizeof(double*));
+
+  for(i=0;i<MP;i++) {
+    ap[i]=cpl_calloc(NP,sizeof(double));
+  }
+
+  cknull(int_sky,"Null input table sky");
+  cknull(lambda,"Null input table lambda");
+  cknull(lrange,"Null input table lrange");
+
+
+  //TO BE FIXED: Why lrange to gat wave min and max: int_sky is sufficient
+  check_nomsg(wmin=cpl_table_get_column_min(lrange,"WAVE"));
+  check_nomsg(wmax=cpl_table_get_column_max(lrange,"WAVE"));
+  check_nomsg(cpl_table_and_selected_double(int_sky,"WAVE",
+              CPL_NOT_LESS_THAN,wmin));
+  check_nomsg(cpl_table_and_selected_double(int_sky,"WAVE",
+              CPL_NOT_GREATER_THAN,wmax));
+  check_nomsg(tmp1=cpl_table_extract_selected(int_sky));
+
+  check_nomsg(row=sinfo_table_get_index_of_val(tmp1,"WAVE",
+                                               wmax,CPL_TYPE_DOUBLE));
+  check_nomsg(max=cpl_table_get_double(tmp1,"INT",row,&status));
+  check_nomsg(sinfo_table_flag_nan(&tmp1,"INT"));
+  check_nomsg(cpl_table_erase_invalid(tmp1));
+  check_nomsg(cpl_table_and_selected_double(tmp1,"INT",CPL_NOT_EQUAL_TO,0));
+  check_nomsg(tmp2=cpl_table_extract_selected(tmp1));
+
+  sinfo_free_table(&tmp1);
+  check_nomsg(n2=cpl_table_get_nrow(tmp2));
+  check_nomsg(sa_vx=cpl_vector_wrap(n2,
+              cpl_table_get_data_double(tmp2,"WAVE")));
+  check_nomsg(sa_vy=cpl_vector_wrap(n2,
+              cpl_table_get_data_double(tmp2,"INT")));
+
+
+  for(i=0;i<MP;i++) {
+    for(j=0;j<NP;j++) {
+      ap[i][j]=0;
+    }
+  }
+
+  check_nomsg(bkg_min=cpl_table_get_column_min(tmp2,"INT"));
+  check_nomsg(bkg_max=cpl_table_get_double(tmp2,"INT",row,&status));
+
+
+  //Init amoeba fit parameters
+  p0_min=bkg_min*0.9;
+  p0_max=bkg_min*1.1;
+  p1_min=bkg_max*0.9;
+  p1_max=bkg_max*1.1;
+  p1_min=200;
+  p2_max=300;
+
+  ap[0][0]=p0_min; ap[0][1]=p1_min; ap[0][2]=p2_min;
+  ap[1][0]=p0_max; ap[1][1]=p1_min; ap[1][2]=p2_min;
+  ap[2][0]=p0_min; ap[2][1]=p1_max; ap[2][2]=p2_min;
+  ap[3][0]=p0_min; ap[3][1]=p1_min; ap[3][2]=p2_max;
+
+  sinfo_msg("Before amoeba fit");
+  for(i=0;i<MP;i++) {
+    for(j=0;j<NP;j++) {
+      sinfo_msg("ap[%d][%d]=%g",i,j,ap[i][j]);
+    }
+  }
+
+
+
+
+  for(i=0;i<MP;i++) {
+    p0[0]=ap[i][0];
+    p0[1]=ap[i][1];
+    p0[2]=ap[i][2];
+    y[i]=sinfo_fit_bkg(p0);
+  }
+
+  sinfo_msg("p0=%g %g %g",p0[0],p0[1],p0[2]);
+  for(i=0;i<N_ITER_FIT_AMOEBA;i++) {
+    check_nomsg(sinfo_fit_amoeba(ap,y,NP,AMOEBA_FTOL,sinfo_fit_bkg,&nfunc));
+    sinfo_msg("After amoeba fit");
+    sinfo_msg("iter=%d ap=%g %g %g",i,ap[0][0],ap[0][1],ap[0][2]);
+  }
+  sinfo_unwrap_vector(&sa_vx);
+  sinfo_unwrap_vector(&sa_vy);
+  sinfo_free_table(&tmp2);
+
+
+  sinfo_msg("After amoeba fit");
+  for(i=0;i<MP;i++) {
+    for(j=0;j<NP;j++) {
+      sinfo_msg("ap[%d][%d]=%g",i,j,ap[i][j]);
+    }
+    sinfo_msg("y[%d]=%g",i,y[i]);
+  }
+
+
+
+  check_nomsg(nrow=cpl_table_get_nrow(lambda));
+  check_nomsg(*bkg=cpl_table_new(nrow));
+  check_nomsg(cpl_table_duplicate_column(*bkg,"WAVE",lambda,"WAVE"));
+  check_nomsg(cpl_table_new_column(*bkg,"INT2",CPL_TYPE_DOUBLE));
+  cpl_table_fill_column_window(*bkg,"INT2",0,nrow,0.);
+  check_nomsg(pw=cpl_table_get_data_double(*bkg,"WAVE"));
+  check_nomsg(pf=cpl_table_get_data_double(*bkg,"INT2"));
+
+  for(i=0;i<nrow;i++) {
+    pf[i]=sinfo_fac(pw[i],ap[0][2]);
+  }
+  check_nomsg(max=cpl_table_get_column_max(*bkg,"INT2"));
+
+  if(max != 0) {
+     check_nomsg(cpl_table_divide_scalar(*bkg,"INT2",max));
+  }
+  check_nomsg(cpl_table_multiply_scalar(*bkg,"INT2",ap[0][1]));
+  check_nomsg(cpl_table_add_scalar(*bkg,"INT2",ap[0][0]));
+  //check_nomsg(cpl_table_save(*bkg,NULL,NULL,
+  //"out_amoeba5.fits",CPL_IO_DEFAULT ));
+  sinfo_new_destroy_2Ddoublearray(&ap,MP);
+
+
+  return 0;
+
+ cleanup:
+  sinfo_new_destroy_2Ddoublearray(&ap,MP);
+  sinfo_free_table(&tmp1);
+  sinfo_free_table(&tmp2);
+  sinfo_unwrap_vector(&sa_vx);
+  sinfo_unwrap_vector(&sa_vy);
+  return -1;
+
+}
+
+
+
+/*-------------------------------------------------------------------------*/
+/**
+  @name        sinfo_termal_background
+  @memo        computes thermal emission background from the sky at a i
+                given temperature
+  @param int_sky      input sky spectrum table
+  @param lambda       input wavelength table
+  @param lrange       input wavelength table
+  @param temp         input temperature in Kelvin
+  @param bkg          output background
+  Returns in case of succes -1 else.
+ */
+/*--------------------------------------------------------------------------*/
+
+int
+sinfo_thermal_background(cpl_table* int_sky,
+                         cpl_table* lambda,
+                         cpl_table* lrange,
+                         const double temp,
+                         const int niter,
+                         const int filter_width,
+                         const double tol,
+                         cpl_table** bkg,
+                         int* success_fit)
+{
+
+  int npix=0;
+  int i=0;
+  int row=0;
+  const int ndim=3;/* There are 3 parameters */
+    int ia[ndim];
+
+  int NPOINTS=0;
+
+
+  double temp1=0;
+  double temp2=0;
+
+  //double r0=80.306773;
+  //double r1=450.50027;
+  //double r2=252.17949;
+  double max_tmp2=0;
+  double* ptmp1=NULL;
+  double thermal=0;
+  double* pw=NULL;
+  double p0[3];
+  double wmin=0;
+  double wmax=0;
+  double ga0=0;
+  double ga1=0;
+  //double ga1=0;
+  double ga2=0;
+  double mse=0;
+  double chired=0;
+
+
+  cpl_vector *a = cpl_vector_new(ndim);
+  cpl_table* xlr=NULL;
+  cpl_table* ylr=NULL;
+  cpl_table* wlr=NULL;
+  cpl_table* tmp=NULL;
+  cpl_table* temp2_tbl=NULL;
+
+  cpl_vector* y=NULL;
+  cpl_vector* fy=NULL;
+
+  cpl_vector* sy=NULL;
+
+  cpl_matrix* x_matrix=NULL;
+  double bkg_min=0;
+  double bkg_max=0;
+  int status=0;
+  double avg=0;
+  double sdv=0;
+  double med=0;
+  double* pif=NULL;
+  double* pwf=NULL;
+  double* pws=NULL;
+  int k=0;
+  int nrow=0;
+
+  //check_nomsg(cpl_table_save(int_sky,NULL,NULL,
+  //"out_pippo.fits", CPL_IO_DEFAULT));
+  check_nomsg(wmin=cpl_table_get_column_min(lrange,"WAVE"));
+  check_nomsg(wmax=cpl_table_get_column_max(lrange,"WAVE"));
+
+  bkg_min=sinfo_fac(wmin,temp);
+  bkg_max=sinfo_fac(wmax,temp);
+  //sinfo_msg("bkg: min=%g max=%g",bkg_min,bkg_max);
+  //sinfo_scale_fct=sinfo_scale_fct*bkg_max;
+  //sinfo_scale_fct=sinfo_scale_fct;
+
+  check_nomsg(cpl_table_and_selected_double(lambda,"WAVE",
+                                            CPL_NOT_LESS_THAN,wmin));
+  check_nomsg(tmp=cpl_table_extract_selected(lambda));
+
+  check_nomsg(cpl_table_and_selected_double(tmp,"WAVE",
+                                            CPL_NOT_GREATER_THAN,wmax));
+  check_nomsg(xlr=cpl_table_extract_selected(tmp));
+  sinfo_free_table(&tmp);
+
+
+  check_nomsg(cpl_table_and_selected_double(int_sky,"WAVE",
+                                            CPL_NOT_LESS_THAN,wmin));
+  check_nomsg(tmp=cpl_table_extract_selected(int_sky));
+  check_nomsg(cpl_table_and_selected_double(tmp,"WAVE",
+                                            CPL_NOT_GREATER_THAN,wmax));
+
+
+  //To be sure one has not strange cases
+  check_nomsg(cpl_table_and_selected_double(tmp,"INT",CPL_GREATER_THAN,-2));
+  check_nomsg(ylr=cpl_table_extract_selected(tmp));
+  //check_nomsg(cpl_table_save(ylr,NULL,NULL,"out_ylr_0.fits",CPL_IO_DEFAULT));
+  sinfo_free_table(&tmp);
+  check_nomsg(tmp=cpl_table_duplicate(ylr));
+  sinfo_free_table(&ylr);
+
+  check_nomsg(avg=cpl_table_get_column_mean(tmp,"INT"));
+  check_nomsg(sdv=cpl_table_get_column_stdev(tmp,"INT"));
+  check_nomsg(cpl_table_and_selected_double(tmp,"INT",
+                        CPL_LESS_THAN,avg+10*sdv));
+
+  check_nomsg(ylr=cpl_table_extract_selected(tmp));
+  sinfo_free_table(&tmp);
+
+
+  /*
+  check_nomsg(xlr=sinfo_table_select_range(lambda,lrange,0.003));
+  check_nomsg(ylr=sinfo_table_select_range(int_sky,lrange,0.003));
+  */
+  check_nomsg(cpl_table_and_selected_double(ylr,"INT",CPL_NOT_EQUAL_TO,0));
+
+  check_nomsg(wlr=cpl_table_extract_selected(ylr));
+
+
+  check_nomsg(p0[0]=cpl_table_get_column_min(wlr,"INT"));
+  check_nomsg(row=sinfo_table_get_index_of_val(ylr,"WAVE",
+                                               wmax,CPL_TYPE_DOUBLE));
+  check_nomsg(p0[1]=cpl_table_get_double(ylr,"INT",row,&status));
+  p0[2]=temp;
+
+
+  ga0=p0[0];
+  ga1=p0[1]/bkg_max;
+  //ga1=p0[1];
+  ga2=p0[2];
+
+  //sinfo_msg("p= %g %g %g",p0[0],p0[1],p0[2]);
+  check_nomsg(sinfo_table_flag_nan(&wlr,"INT"));
+  check_nomsg(cpl_table_erase_invalid(wlr));
+  //check_nomsg(cpl_table_save(xlr,NULL,NULL,"out_xlr.fits",CPL_IO_DEFAULT));
+  //check_nomsg(cpl_table_save(ylr,NULL,NULL,"out_ylr.fits",CPL_IO_DEFAULT));
+  //check_nomsg(cpl_table_save(wlr,NULL,NULL,"out_wlr.fits",CPL_IO_DEFAULT));
+
+
+  check_nomsg(NPOINTS=cpl_table_get_nrow(ylr));
+
+  check_nomsg(x_matrix = cpl_matrix_wrap(NPOINTS,1,
+                                       cpl_table_get_data_double(ylr,"WAVE")));
+  check_nomsg(y=cpl_vector_wrap(NPOINTS,cpl_table_get_data_double(ylr,"INT")));
+  //check_nomsg(fy=cpl_vector_filter_median_create(y,1));
+  //check_nomsg(fy=cpl_vector_filter_lowpass_create(y,CPL_LOWPASS_LINEAR,3));
+  //check_nomsg(cpl_table_save(ylr,NULL,NULL,"out_ylr1.fits",CPL_IO_DEFAULT));
+  check_nomsg(fy=sinfo_sky_background_estimate(y,filter_width,filter_width));
+  //check_nomsg(cpl_table_save(ylr,NULL,NULL,"out_ylr2.fits",CPL_IO_DEFAULT));
+  pif=cpl_vector_get_data(fy);
+  pwf=cpl_table_get_data_double(ylr,"WAVE");
+
+
+  check_nomsg(cpl_table_new_column(int_sky,"INT_BKG_SMO",CPL_TYPE_DOUBLE));
+  check_nomsg(cpl_table_new_column(int_sky,"WAVE_SMO",CPL_TYPE_DOUBLE));
+  pws=cpl_table_get_data_double(int_sky,"WAVE");
+
+  k=0;
+  i=0;
+  check_nomsg(nrow=cpl_table_get_nrow(int_sky));
+  if((pws[0]-pwf[0])>0) {
+    for(i=0;i<NPOINTS;i++) {
+      if(fabs(pws[k]-pwf[i]) < tol) {
+    check_nomsg(cpl_table_set_double(int_sky,"INT_BKG_SMO",k,pif[i]));
+    check_nomsg(cpl_table_set_double(int_sky,"WAVE_SMO",k,pws[i]));
+    k++;
+      }
+    }
+  } else {
+    for(k=0;k<nrow;k++) {
+      if((i<NPOINTS) && (fabs(pws[k]-pwf[i]) < tol)) {
+    check_nomsg(cpl_table_set_double(int_sky,"INT_BKG_SMO",k,pif[i]));
+    check_nomsg(cpl_table_set_double(int_sky,"WAVE_SMO",k,pws[i]));
+    i++;
+      }
+    }
+
+  }
+
+  //check_nomsg(cpl_table_save(ylr,NULL,NULL,"out_ylr3.fits",CPL_IO_DEFAULT));
+
+
+  check_nomsg(cpl_vector_set(a, 0, ga0));
+  check_nomsg(cpl_vector_set(a, 1, ga1));
+  check_nomsg(cpl_vector_set(a, 2, ga2));
+
+  check_nomsg(sy=cpl_vector_duplicate(y));
+  check_nomsg(cpl_vector_power(sy,2));
+  check_nomsg(cpl_vector_power(sy,0.5));
+  //check_nomsg(cpl_vector_fill(sy,0.001));
+
+  ia[0] = 1;
+  ia[1] = 1;
+  ia[2] = 1;
+
+
+  for(i=0;i<niter;i++) {
+
+    /*
+    sinfo_msg("before fit: a=%g %g %g",
+              cpl_vector_get(a,0),
+              cpl_vector_get(a,1),
+              cpl_vector_get(a,2));
+    */
+    if(CPL_ERROR_NONE != sinfo_fit_lm(x_matrix,NULL,fy,sy,a,ia,sinfo_fitbkg,
+                      sinfo_fitbkg_derivative,
+                      &mse,&chired,NULL)) {
+      sinfo_msg_warning("Thermal background fit failed");
+      cpl_error_reset();
+      *success_fit=1;
+
+      goto recover;
+    }
+
+    //bkg_max=sinfo_fac(wmax,cpl_vector_get(a,2));
+    //sinfo_scale_fct=sinfo_scale_fct*bkg_max;
+    /*
+    sinfo_msg("after fit: a=%g %g %g chired=%g",
+              cpl_vector_get(a,0),
+          cpl_vector_get(a,1),
+              cpl_vector_get(a,2),
+              chired);
+
+    */
+
+  }
+
+    sinfo_msg("Last fit: a=%g %g %g chired=%g",
+              cpl_vector_get(a,0),
+          cpl_vector_get(a,1),
+              cpl_vector_get(a,2),
+              chired);
+
+  sinfo_free_my_vector(&fy);
+  sinfo_unwrap_vector(&y);
+  sinfo_free_my_vector(&sy);
+  sinfo_unwrap_matrix(&x_matrix);
+  sinfo_free_table(&xlr);
+  sinfo_free_table(&ylr);
+  sinfo_free_table(&wlr);
+
+  ga0=cpl_vector_get(a,0);
+  ga1=cpl_vector_get(a,1);
+  ga2=cpl_vector_get(a,2);
+  //ga2=252.69284;
+  check_nomsg(npix=cpl_table_get_nrow(lrange));
+  check_nomsg(pw=cpl_table_get_data_double(lrange,"WAVE"));
+  check_nomsg(temp2_tbl=cpl_table_new(npix));
+  check_nomsg(cpl_table_new_column(temp2_tbl,"TEMP2",CPL_TYPE_DOUBLE));
+
+  for(i=0;i<npix;i++) {
+    temp2=sinfo_fac(pw[i],ga2);
+    check_nomsg(cpl_table_set_double(temp2_tbl,"TEMP2",i,temp2));
+  }
+  check_nomsg(max_tmp2=cpl_table_get_column_max(temp2_tbl,"TEMP2"));
+  sinfo_free_table(&temp2_tbl);
+
+
+
+  check_nomsg(npix=cpl_table_get_nrow(lambda));
+  check_nomsg(pw=cpl_table_get_data_double(lambda,"WAVE"));
+  check_nomsg(*bkg=cpl_table_new(npix));
+  check_nomsg(cpl_table_new_column(*bkg,"WAVE",CPL_TYPE_DOUBLE));
+  check_nomsg(cpl_table_new_column(*bkg,"TEMP1",CPL_TYPE_DOUBLE));
+  check_nomsg(cpl_table_new_column(*bkg,"INT",CPL_TYPE_DOUBLE));
+  check_nomsg(cpl_table_new_column(*bkg,"INT2",CPL_TYPE_DOUBLE));
+
+  for(i=0;i<npix;i++) {
+    check_nomsg(cpl_table_set_double(*bkg,"WAVE",i,pw[i]));
+    temp1=sinfo_fac(pw[i],ga2);
+    check_nomsg(cpl_table_set_double(*bkg,"TEMP1",i,temp1));
+  }
+
+  check_nomsg(ptmp1=cpl_table_get_data_double(*bkg,"TEMP1"));
+  //bkg_max=sinfo_fac(wmax,ga2);
+
+  for(i=0;i<npix;i++) {
+    thermal=ga0+ptmp1[i]/max_tmp2*ga1;
+    check_nomsg(cpl_table_set_double(*bkg,"INT",i,thermal));
+    thermal=ga0+ga1*sinfo_fac(pw[i],ga2);
+    check_nomsg(cpl_table_set_double(*bkg,"INT2",i,thermal));
+  }
+  sinfo_free_my_vector(&a);
+
+  return 0;
+
+ recover:
+  sinfo_msg_warning("Recover fit of thermal background");
+  check_nomsg(npix=cpl_table_get_nrow(lambda));
+  check_nomsg(*bkg=cpl_table_new(npix));
+  check_nomsg(cpl_table_new_column(*bkg,"TEMP1",CPL_TYPE_DOUBLE));
+  check_nomsg(cpl_table_new_column(*bkg,"INT",CPL_TYPE_DOUBLE));
+  check_nomsg(cpl_table_new_column(*bkg,"INT2",CPL_TYPE_DOUBLE));
+
+  med=cpl_table_get_column_median(ylr,"INT");
+  for(i=0;i<npix;i++) {
+    check_nomsg(cpl_table_set_double(*bkg,"INT",i,med));
+    check_nomsg(cpl_table_set_double(*bkg,"INT2",i,med));
+  }
+
+  sinfo_free_my_vector(&a);
+  sinfo_unwrap_vector(&y);
+  sinfo_free_my_vector(&sy);
+  sinfo_unwrap_matrix(&x_matrix);
+  sinfo_free_table(&xlr);
+  sinfo_free_table(&ylr);
+  sinfo_free_table(&wlr);
+  sinfo_free_table(&tmp);
+
+  return 0;
+
+
+ cleanup:
+  sinfo_free_my_vector(&a);
+  sinfo_unwrap_vector(&y);
+  sinfo_free_my_vector(&sy);
+  sinfo_unwrap_matrix(&x_matrix);
+
+  sinfo_free_table(&xlr);
+  sinfo_free_table(&ylr);
+  sinfo_free_table(&wlr);
+  sinfo_free_table(&tmp);
+  sinfo_free_table(&temp2_tbl);
+
+  return -1;
+
+}
+
+/**
+ at name sinfo_filter_min
+ at memo apply a filter min of a given size to a vector
+ at param vi input vector
+ at param size size of filter
+ at return a new allocated vector resulting from the filter proces
+ at doc
+The following static function passes a min filter of given box
+size on the data buffer. The box size must be a positive odd integer.
+
+*/
+static cpl_vector*
+sinfo_filter_min(const cpl_vector* vi, const int size)
+{
+
+  cpl_vector* vo=NULL;
+  double min=0;
+  int start=size/2;
+  int end=0;
+  int length=0;
+  int i=0;
+  int j=0;
+  const double* pi=NULL;
+  double* po=NULL;
+  cknull(vi,"null input vector");
+  pi=cpl_vector_get_data_const(vi);
+  length=cpl_vector_get_size(vi);
+  end=length-size/2;
+  vo=cpl_vector_new(length);
+  po=cpl_vector_get_data(vo);
+
+  for(i=start; i < end; i++) {
+    min=pi[i-start];
+    for(j=i-start+1;j<i+start+1;j++) {
+      if(min> pi[j]) {
+    min=pi[j];
+      }
+    }
+    po[i]=min;
+
+  }
+
+  // To prevent border effects:
+  for (i = 0; i < start; i++) {
+    po[i] = po[start];
+  }
+
+  for (i = end; i < length; i++) {
+    po[i] = po[end-1];
+  }
+  return vo;
+
+ cleanup:
+  return NULL;
+
+
+}
+
+
+/**
+ at name sinfo_filter_max
+ at memo apply a filter max of a given size to a vector
+ at param vi input vector
+ at param size size of filter
+ at return a new allocated vector resulting from the filter proces
+ at doc
+The following static function passes a max filter of given box
+size on the data buffer. The box size must be a positive odd integer.
+
+*/
+static cpl_vector*
+sinfo_filter_max(const cpl_vector* vi, const int size)
+{
+
+  cpl_vector* vo=NULL;
+  double max=0;
+  int start=size/2;
+  int end=0;
+  int length=0;
+  int i=0;
+  int j=0;
+  const double* pi=NULL;
+  double* po=NULL;
+
+  cknull(vi,"null input vector");
+  pi=cpl_vector_get_data_const(vi);
+  length=cpl_vector_get_size(vi);
+  end=length-size/2;
+  vo=cpl_vector_new(length);
+  po=cpl_vector_get_data(vo);
+
+  for(i=start; i < end; i++) {
+    max=pi[i-start];
+    for(j=i-start+1;j<i+start+1;j++) {
+      if(max< pi[j]) {
+    max=pi[j];
+      }
+    }
+    po[i]=max;
+
+  }
+
+  // To prevent border effects:
+  for (i = 0; i < start; i++) {
+    po[i] = po[start];
+  }
+
+  for (i = end; i < length; i++) {
+    po[i] = po[end-1];
+  }
+  return vo;
+
+ cleanup:
+  return NULL;
+
+
+}
+
+
+
+/**
+ at name sinfo_filter_smo
+ at memo passes a running mean of a given size to a vector
+ at param vi input vector
+ at param size size of filter
+ at return a new allocated vector resulting from the filter proces
+ at doc
+The following static function passes a running mean of given box
+size on the data buffer. The box size must be a positive odd integer.
+
+*/
+static cpl_vector*
+sinfo_filter_smo(const cpl_vector* vi, const int size)
+{
+
+
+  double sum=0;
+  int start=size/2;
+  int end=0;
+  int length=0;
+  int i=0;
+  int j=0;
+  const double* pi=NULL;
+  double* po=NULL;
+  cpl_vector* vo=NULL;
+
+  cknull(vi,"null input vector");
+  length=cpl_vector_get_size(vi);
+  end=length-size/2;
+  vo=cpl_vector_new(length);
+  pi=cpl_vector_get_data_const(vi);
+  po=cpl_vector_get_data(vo);
+
+  for(i=start; i < end; i++) {
+    sum=0;
+    for(j=i - start;j<i+start+1;j++) {
+      sum += pi[j];
+    }
+    po[i]=sum/size;
+
+  }
+
+  // To prevent border effects:
+  for (i = 0; i < start; i++) {
+    po[i] = po[start];
+  }
+
+  for (i = end; i < length; i++) {
+    po[i] = po[end-1];
+  }
+  return vo;
+
+ cleanup:
+  return NULL;
+
+}
+
+/**
+ * @brief
+ *   Background determination on 1D emission line spectrum (arc)
+ *
+ * @param spectrum A 1D emission line spectrum
+ * @param msize    Size of min-filter
+ * @param fsize    Size of running-average-filter
+ *
+ * @return CPL_ERROR_NONE in case of success
+ *
+ * @error
+ *   <table class="ec" align="center">
+ *     <tr>
+ *       <td class="ecl">CPL_ERROR_NULL_INPUT</td>
+ *       <td class="ecr">
+ *         The input spectrum is a <tt>NULL</tt> pointer.
+ *       </td>
+ *     </tr>
+ *     <tr>
+ *       <td class="ecl">CPL_ERROR_ILLEGAL_INPUT</td>
+ *       <td class="ecr">
+ *         Either <i>msize</i> is less than 3, or <i>fsize</i> is less
+ *         than <i>msize</i>, or <i>fsize</i> is greater than <i>length/2</i>.
+ *       </td>
+ *     </tr>
+ *   </table>
+ * @enderror
+ *
+ * This function fills the array @em back with the estimated values
+ * of the background along the input spectrum. The algorithm is
+ * based on the assumption that there is at least one background
+ * value at any position of the min-filter box running along the
+ * spectrum. A min-filter is passed on the spectrum, and the result
+ * is smoothed by averaging on a running box of size @em fsize.
+ * The min-filter is run between the positions @em msize / 2
+ * and @em length - @em msize / 2, and the min value found at
+ * such positions is then repeated up to the spectrum ends. Similarly,
+ * the running average is limited to the interval from @em fsize / 2
+ * and @em length - @em fsize / 2, leaving the most external values
+ * untouched. After this, a max filter and a smoothing using boxes
+ * with double the specified sizes are run, as a way to eliminate
+ * the contamination from occasional cold pixels. Finally, the
+ * min filter and the smoothing are applied again to obviate the
+ * slight background over-estimation introduced by the max filter.
+ *
+ * It is required that the @em back array is at least long as the
+ * array @em spectrum.  Moreover @em msize must be greater than 1,
+ * and @em fsize greater than, or equal to, @em msize. Likewise,
+ * @em length must be greater than twice @em fsize. If such conditions
+ * are not met, or if the input arrays are @c NULL pointers, this
+ * function will set an error code, and leave the @em back array
+ * untouched. If either @em msize or @em fsize are even numbers,
+ * they are made odd by adding 1. Suggested values for @em msize
+ * and @em fsize are 15 pixels for typical arc lamp spectra.
+ */
+
+cpl_vector* sinfo_sky_background_estimate(cpl_vector *spectrum,
+                                             int msize,
+                                             int fsize)
+{
+
+    cpl_vector  * minf=NULL;
+    cpl_vector  * maxf=NULL;
+    cpl_vector  * smof=NULL;
+    cpl_vector  * back=NULL;
+    double* pb=NULL;
+    double* ps=NULL;
+
+    int     i=0;
+    int length=0;
+
+
+    cknull(spectrum,"null input data");
+
+    if (msize % 2 == 0)
+        msize++;
+
+    if (fsize % 2 == 0)
+        fsize++;
+    check_nomsg(length=cpl_vector_get_size(spectrum));
+
+    if (msize < 3 || fsize < msize || length < 2*fsize)
+        return NULL;
+
+
+    cknull_nomsg(minf = sinfo_filter_min(spectrum, msize));
+    cknull_nomsg(smof = sinfo_filter_smo(minf, fsize));
+    cpl_vector_delete(minf);
+    cknull_nomsg(maxf = sinfo_filter_max(smof,2*msize+1));
+    cpl_vector_delete(smof);
+    cknull_nomsg(smof = sinfo_filter_smo(maxf, 2*fsize+1));
+    cpl_vector_delete(maxf);
+    cknull_nomsg(minf = sinfo_filter_min(smof, 2*msize+1));
+    cpl_vector_delete(smof);
+    cknull_nomsg(smof = sinfo_filter_smo(minf, 2*fsize+1));
+    cpl_vector_delete(minf);
+    cknull_nomsg(back=cpl_vector_new(length));
+    cknull_nomsg(pb=cpl_vector_get_data(back));
+    cknull_nomsg(ps=cpl_vector_get_data(smof));
+
+    for (i = 0; i < length; i++) {
+        pb[i] = ps[i];
+     }
+    cpl_vector_delete(smof);
+
+    return back;
+ cleanup:
+
+    return NULL;
+
+}
+
+
+
+/**
+ at name sinfo_slice_z
+ at memo extract a cube slice (spectrum) along z at i,j
+ at param cin input imagelist
+ at param i   inpout position (x)
+ at param j   inpout position (y)
+ at return if success a table containg the spectrum along z at i,j
+        else NULL
+*/
+static cpl_table*
+sinfo_slice_z(const cpl_imagelist* cin,const int i,const int j)
+{
+  int sx=0;
+  int sy=0;
+  int sz=0;
+  int k=0;
+  cpl_table* tout=NULL;
+  const cpl_image* img=NULL;
+  const double* pim=NULL;
+
+  cknull(cin,"null input imagelist");
+  check_nomsg(sz=cpl_imagelist_get_size(cin));
+  check_nomsg(img=cpl_imagelist_get_const(cin,0));
+  check_nomsg(sx=cpl_image_get_size_x(img));
+  check_nomsg(sy=cpl_image_get_size_y(img));
+  check_nomsg(tout=cpl_table_new(sz));
+  check_nomsg(cpl_table_new_column(tout,"VALUE",CPL_TYPE_DOUBLE));
+  for(k=0;k<sz;k++) {
+    check_nomsg(img=cpl_imagelist_get_const(cin,k));
+    check_nomsg(pim=cpl_image_get_data_double_const(img));
+    check_nomsg(cpl_table_set(tout,"VALUE",k,pim[j*sx+i]));
+  }
+
+  return tout;
+ cleanup:
+  sinfo_free_table(&tout);
+
+  return NULL;
+
+}
+
+/**
+ at name sinfo_xcorr
+ at memo cross correlate object and sky spectra considering lines of given \
+      half width
+ at param int_obj  input obj spectrum
+ at param int_sky  input sky spectrum
+ at param lambda   input wavelength range
+ at param dispersion input dispersion value
+ at param line_hw    input line half width
+*/
+double
+sinfo_xcorr(cpl_table* int_obj,
+            cpl_table* int_sky,
+            cpl_table* lambda,
+            const double dispersion,
+            const double line_hw)
+{
+
+  cpl_table* z=NULL;
+  cpl_table* tmp_sky=NULL;
+
+  cpl_table* z_diff=NULL;
+  cpl_table* z_pos=NULL;
+
+  int z_ext=0;
+  double z_mean=0;
+  double z_sdv=0;
+  int nrow=0;
+  int i=0;
+
+  double g_lam=0;
+  double g_err=0;
+
+  double sky_max=0;
+
+  double* pint=NULL;
+  int* ppos=NULL;
+  int status=0;
+  int zsize=0;
+  int iq=0;
+
+  double g_diff=0;
+  int jz=0;
+  int z1=0;
+  int nfit=0;
+  int npos=0;
+  cpl_table* z_good=NULL;
+  cpl_table* w_tbl=NULL;
+  cpl_table* o_tbl=NULL;
+  cpl_table* s_tbl=NULL;
+  cpl_vector* vw=NULL;
+  cpl_vector* vs=NULL;
+  cpl_vector* vo=NULL;
+  cpl_vector* sx=NULL;
+  cpl_vector* sy=NULL;
+
+
+  double o1=0;
+  double o2=0;
+  double oc=0;
+  double om=0;
+
+
+
+  double zfit=0;
+
+
+  double mse=0;
+
+  double ws=0;
+  double wc_s=0;
+  double sig_s=0;
+  double bkg_s=0;
+  double amp_s=0;
+  double area_s=0;
+
+  double wo=0;
+  double wc_o=0;
+  double sig_o=0;
+  double bkg_o=0;
+  double amp_o=0;
+  double area_o=0;
+
+  cpl_polynomial* cfit=NULL;
+  cpl_size pows[2];
+  cpl_vector* vx=NULL;
+  cpl_vector* vy=NULL;
+
+
+  cpl_error_code error_code=CPL_ERROR_NONE;
+
+  // crosscorrelate obj & sky to check for lambda offset
+
+  //if (mean(z[where(finite(z))]) < 0) z = z * (-1);
+  //if sky mean is < 0 flip sky intensity
+  zsize=cpl_table_get_nrow(int_obj);
+  check_nomsg(z = cpl_table_duplicate(int_sky));
+  ck0_nomsg(sinfo_table_flag_nan(&z,"INT"));
+  //check_nomsg(cpl_table_save(z,NULL,NULL,"out_z1.fits",CPL_IO_DEFAULT));
+  check_nomsg(z_mean=cpl_table_get_column_mean(z,"INT"));
+  if(z_mean < 0) {
+    check_nomsg(cpl_table_multiply_scalar(z,"INT",-1));
+  }
+  //check_nomsg(cpl_table_save(z,NULL,NULL,"out_z2.fits",CPL_IO_DEFAULT));
+
+  //z[where(int_sky < max(int_sky[where(finite(int_sky))])/4)] = 0;
+  // take in consideration only strong sky lines (set else to 0)
+  check_nomsg(tmp_sky=cpl_table_duplicate(int_sky));
+  ck0_nomsg(sinfo_table_flag_nan(&tmp_sky,"INT"));
+  check_nomsg(sky_max=cpl_table_get_column_max(tmp_sky,"INT"));
+  sinfo_free_table(&tmp_sky);
+
+  //flag too low values
+  check_nomsg(nrow=cpl_table_get_nrow(z));
+  check_nomsg(pint=cpl_table_get_data_double(z,"INT"));
+  check_nomsg(sky_max=cpl_table_get_column_max(z,"INT"));
+  for(i=0;i<nrow;i++) {
+    if(pint[i]<sky_max/SKY_LINE_MIN_CUT) {
+      pint[i]=0;
+    }
+  }
+
+
+  //check_nomsg(cpl_table_save(z,NULL,NULL,"out_z4.fits",CPL_IO_DEFAULT));
+  //computes gradient
+  //z_diff = z[0:n_elements(z)-2] - z[1:n_elements(z)-1];
+  check_nomsg(z_diff=cpl_table_duplicate(z));
+  check_nomsg(cpl_table_duplicate_column(z_diff,"INT1",z,"INT"));
+  check_nomsg(cpl_table_duplicate_column(z_diff,"INT2",z,"INT"));
+  check_nomsg(cpl_table_shift_column(z_diff,"INT1",-1));
+  check_nomsg(cpl_table_duplicate_column(z_diff,"DIFF",z_diff,"INT2"));
+  check_nomsg(cpl_table_subtract_columns(z_diff,"DIFF","INT1"));
+
+  check_nomsg(cpl_table_erase_window(z_diff,nrow-2,2));
+  //check_nomsg(cpl_table_save(z_diff,NULL,NULL,
+  //                             "out_z_diff.fits",CPL_IO_DEFAULT));
+
+  //identify points positions at which there is a line pick
+  check_nomsg(cpl_table_new_column(z_diff,"POS",CPL_TYPE_INT));
+  check_nomsg(cpl_table_fill_column_window_int(z_diff,"POS",0,nrow,0));
+
+  check_nomsg(pint=cpl_table_get_data_double(z_diff,"DIFF"));
+  check_nomsg(ppos=cpl_table_get_data_int(z_diff,"POS"));
+  check_nomsg(nrow=cpl_table_get_nrow(z_diff));
+  for(i=1;i<nrow;i++) {
+    if(!irplib_isnan(pint[i]) && (pint[i]>0 && pint[i-1]<0)) {
+      ppos[i]=i;
+    }
+  }
+
+  //check_nomsg(cpl_table_save(z_diff,NULL,NULL,"out_z_diff.fits",
+  //                             CPL_IO_DEFAULT));
+  check_nomsg(cpl_table_select_all(z_diff));
+  check_nomsg(cpl_table_and_selected_int(z_diff,"POS",CPL_GREATER_THAN,0));
+  check_nomsg(z_pos=cpl_table_extract_selected(z_diff));
+  sinfo_free_table(&z_diff);
+  //check_nomsg(cpl_table_save(z_pos,NULL,NULL,
+  //                             "out_z_pos.fits",CPL_IO_DEFAULT));
+  //Do a gaussian fit in a range of size 2*zext centered at
+  //each line maximum position (fit the line) to get in corresponding arrays:
+  // 1) line lambda position of object and sky
+  // 2) line object -sky intensity
+  // 3) line object-sky intensity error
+
+
+  g_lam = 0.;
+  g_diff = 0.;
+  g_err = 0.;
+  check_nomsg(npos=cpl_table_get_nrow(z_pos));
+  z_ext = line_hw ;
+  check_nomsg(cpl_table_new_column(z_pos,"STATUS_S",CPL_TYPE_INT));
+  check_nomsg(cpl_table_new_column(z_pos,"STATUS_O",CPL_TYPE_INT));
+  check_nomsg(cpl_table_fill_column_window_int(z_pos,"STATUS_S",0,npos,0));
+  check_nomsg(cpl_table_fill_column_window_int(z_pos,"STATUS_O",0,npos,0));
+  check_nomsg(cpl_table_new_column(z_pos,"SIGS",CPL_TYPE_DOUBLE));
+  check_nomsg(cpl_table_new_column(z_pos,"WAVES",CPL_TYPE_DOUBLE));
+  check_nomsg(cpl_table_new_column(z_pos,"BKGS",CPL_TYPE_DOUBLE));
+  check_nomsg(cpl_table_new_column(z_pos,"AREAS",CPL_TYPE_DOUBLE));
+  check_nomsg(cpl_table_new_column(z_pos,"AMPS",CPL_TYPE_DOUBLE));
+
+
+  check_nomsg(cpl_table_new_column(z_pos,"SIGO",CPL_TYPE_DOUBLE));
+  check_nomsg(cpl_table_new_column(z_pos,"WAVEO",CPL_TYPE_DOUBLE));
+  check_nomsg(cpl_table_new_column(z_pos,"BKGO",CPL_TYPE_DOUBLE));
+  check_nomsg(cpl_table_new_column(z_pos,"AREAO",CPL_TYPE_DOUBLE));
+  check_nomsg(cpl_table_new_column(z_pos,"AMPO",CPL_TYPE_DOUBLE));
+
+  check_nomsg(cpl_table_new_column(z_pos,"WAVEC",CPL_TYPE_DOUBLE));
+  check_nomsg(cpl_table_new_column(z_pos,"WDIF",CPL_TYPE_DOUBLE));
+  check_nomsg(cpl_table_new_column(z_pos,"ERR",CPL_TYPE_DOUBLE));
+
+  nfit=2*z_ext+1;
+  //sinfo_msg("npos=%d z_ext=%d",npos,z_ext);
+  //sinfo_table_column_dump(z_pos,"POS",CPL_TYPE_INT);
+  //check_nomsg(cpl_table_save(z_pos,NULL,NULL,
+  //                             "out_z_pos_0.fits",CPL_IO_DEFAULT));
+  //check_nomsg(cpl_table_save(int_obj,NULL,NULL,
+  //                             "out_int_obj_0.fits",CPL_IO_DEFAULT));
+  //check_nomsg(cpl_table_save(int_sky,NULL,NULL,
+  //                             "out_int_sky_0.fits",CPL_IO_DEFAULT));
+
+  for (jz=0;jz<npos;jz++) {
+    check_nomsg(z1 = cpl_table_get_int(z_pos,"POS",jz,&status));
+    //sinfo_msg("z1=%d",z1);
+    // AMO added if check to prevent array explosion
+    if((z1-z_ext) > 0 && (z1+z_ext) < zsize) {
+      check_nomsg(cpl_table_select_all(int_sky));
+      check_nomsg(cpl_table_select_all(int_obj));
+      check_nomsg(cpl_table_select_all(lambda));
+      check_nomsg(cpl_table_and_selected_window(int_sky,z1-z_ext,nfit));
+      check_nomsg(s_tbl=cpl_table_extract_selected(int_sky));
+      check_nomsg(cpl_table_and_selected_window(lambda,z1-z_ext,nfit));
+      check_nomsg(w_tbl=cpl_table_extract_selected(lambda));
+      check_nomsg(cpl_table_and_selected_window(int_obj,z1-z_ext,nfit));
+      check_nomsg(o_tbl=cpl_table_extract_selected(int_obj));
+
+
+      check_nomsg(vw=cpl_vector_wrap(nfit,
+                     cpl_table_get_data_double(w_tbl,"WAVE")));
+      check_nomsg(vs=cpl_vector_wrap(nfit,
+                     cpl_table_get_data_double(s_tbl,"INT")));
+      check_nomsg(vo=cpl_vector_wrap(nfit,
+                     cpl_table_get_data_double(o_tbl,"INT")));
+
+
+      check_nomsg(sx=cpl_vector_new(nfit));
+      check_nomsg(cpl_vector_fill(sx,10.));
+      check_nomsg(sy=cpl_vector_duplicate(sx));
+
+
+      // Check if the object line is in emission or absorbtion
+      o1=cpl_vector_get(vo,0);
+      o2=cpl_vector_get(vo,nfit-1);
+      oc=(o1+o2)*0.5;
+      om=cpl_vector_get_median_const(vo);
+      if(om<oc) {
+    cpl_vector_multiply_scalar(vo,-1.);
+      }
+      check_nomsg(ws=cpl_table_get_double(lambda,"WAVE",z1,&status));
+      check_nomsg(amp_s=cpl_table_get_double(z_pos,"INT",jz,&status));
+      wc_s=ws;
+      sig_s=z_ext*dispersion;
+      bkg_s=0;
+      area_s=sinfo_gaussian_area(amp_s,sig_s,ws,wc_s,bkg_s);
+      if(wc_s < 2.35) {
+        //sinfo_msg("wc_s=%f",wc_s);
+        //cpl_vector_dump(vw,stdout);
+        //cpl_vector_dump(vs,stdout);
+
+        error_code=cpl_vector_fit_gaussian(vw,NULL,
+                        vs,NULL,
+                       CPL_FIT_ALL,
+                       &wc_s,&sig_s,
+                       &area_s,&bkg_s,
+                       NULL,NULL,NULL);
+        if(error_code == CPL_ERROR_NONE) {
+      amp_s=sinfo_gaussian_amp(area_s,sig_s,ws,wc_s,bkg_s);
+          check_nomsg(cpl_table_set_double(z_pos,"WAVES",jz,wc_s));
+          check_nomsg(cpl_table_set_double(z_pos,"SIGS",jz,sig_s));
+          check_nomsg(cpl_table_set_double(z_pos,"AREAS",jz,area_s));
+          check_nomsg(cpl_table_set_double(z_pos,"BKGS",jz,bkg_s));
+          check_nomsg(cpl_table_set_double(z_pos,"AMPS",jz,amp_s));
+      /*
+          sinfo_msg("Gauss fit parameters:");
+          sinfo_msg("wc_s=%f sig_s=%f area_s=%f bkg_s=%f",
+                     wc_s,sig_s,area_s,bkg_s);
+          sinfo_msg("mse=%f chired=%f amp_s=%f",
+                     mse,chired,amp_s);
+      */
+
+    } else if (error_code == CPL_ERROR_CONTINUE) {
+      cpl_error_reset();
+      amp_s=sinfo_gaussian_amp(area_s,sig_s,ws,wc_s,bkg_s);
+          check_nomsg(cpl_table_set_double(z_pos,"WAVES",jz,wc_s));
+          check_nomsg(cpl_table_set_double(z_pos,"SIGS",jz,sig_s));
+          check_nomsg(cpl_table_set_double(z_pos,"AREAS",jz,area_s));
+          check_nomsg(cpl_table_set_double(z_pos,"BKGS",jz,bkg_s));
+          check_nomsg(cpl_table_set_double(z_pos,"AMPS",jz,amp_s));
+          check_nomsg(cpl_table_set_int(z_pos,"STATUS_S",jz,-1));
+    } else {
+      cpl_error_reset();
+          check_nomsg(cpl_table_set_double(z_pos,"WAVES",jz,wc_s));
+          check_nomsg(cpl_table_set_double(z_pos,"SIGS",jz,sig_s));
+          check_nomsg(cpl_table_set_double(z_pos,"AREAS",jz,area_s));
+          check_nomsg(cpl_table_set_double(z_pos,"BKGS",jz,bkg_s));
+          check_nomsg(cpl_table_set_double(z_pos,"AMPS",jz,amp_s));
+          check_nomsg(cpl_table_set_int(z_pos,"STATUS_S",jz,-2));
+    }
+        check_nomsg(wo=cpl_table_get_double(lambda,"WAVE",z1,&status));
+        check_nomsg(amp_o=cpl_table_get_double(z_pos,"INT",jz,&status));
+        wc_o=wo;
+        sig_o=z_ext*dispersion;
+        bkg_o=0;
+        area_o=sinfo_gaussian_area(amp_o,sig_o,wo,wc_o,bkg_o);
+        error_code = cpl_vector_fit_gaussian(vw,NULL,
+                      vo,sy,
+                     CPL_FIT_ALL,
+                     &wc_o,&sig_o,
+                     &area_o,&bkg_o,
+                     NULL,NULL,NULL);
+
+        if(error_code == CPL_ERROR_NONE) {
+
+          amp_o=sinfo_gaussian_amp(area_o,sig_o,wo,wc_o,bkg_o);
+          check_nomsg(cpl_table_set_double(z_pos,"WAVEO",jz,wc_o));
+          check_nomsg(cpl_table_set_double(z_pos,"SIGO",jz,sig_o));
+          check_nomsg(cpl_table_set_double(z_pos,"AREAO",jz,area_o));
+          check_nomsg(cpl_table_set_double(z_pos,"BKGO",jz,bkg_o));
+          check_nomsg(cpl_table_set_double(z_pos,"AMPO",jz,amp_o));
+      /*
+          sinfo_msg("Gauss fit parameters:");
+          sinfo_msg("wc_o=%f sig_o=%f area_o=%f bkg_o=%f",
+                     wc_o,sig_o,area_o,bkg_o);
+          sinfo_msg("mse=%f chired=%f amp_o=%f",
+                     mse,chired,amp_o);
+      */
+    } else if (error_code == CPL_ERROR_CONTINUE) {
+
+      cpl_error_reset();
+          amp_o=sinfo_gaussian_amp(area_o,sig_o,wo,wc_o,bkg_o);
+          check_nomsg(cpl_table_set_double(z_pos,"WAVEO",jz,wc_o));
+          check_nomsg(cpl_table_set_double(z_pos,"SIGO",jz,sig_o));
+          check_nomsg(cpl_table_set_double(z_pos,"AREAO",jz,area_o));
+          check_nomsg(cpl_table_set_double(z_pos,"BKGO",jz,bkg_o));
+          check_nomsg(cpl_table_set_double(z_pos,"AMPO",jz,amp_o));
+          check_nomsg(cpl_table_set_int(z_pos,"STATUS_O",jz,-1));
+
+    } else {
+      cpl_error_reset();
+          check_nomsg(cpl_table_set_double(z_pos,"WAVEO",jz,wc_o));
+          check_nomsg(cpl_table_set_double(z_pos,"SIGO",jz,sig_o));
+          check_nomsg(cpl_table_set_double(z_pos,"AREAO",jz,area_o));
+          check_nomsg(cpl_table_set_double(z_pos,"BKGO",jz,bkg_o));
+          check_nomsg(cpl_table_set_double(z_pos,"AMPO",jz,amp_o));
+          check_nomsg(cpl_table_set_int(z_pos,"STATUS_O",jz,-2));
+          /*
+          if (lambda[z1] < 2.35 &&
+             total(finite([l1,s1,o1])) == n_elements([l1,s1,o1])) {
+            gs1 = float(gaussfit(l1,s1,as1,nterms=3));
+            go1 = float(gaussfit(l1,o1,ao1,nterms=3));
+            g_lam = [g_lam,(as1[1]+ao1[1])/2.];
+            g_diff = [g_diff,as1[1]-ao1[1]];
+            g_err = [g_err,sqrt(as1[2]^2+ao1[2]^2)];
+          }
+          */
+        }
+        check_nomsg(cpl_table_set_double(z_pos,"ERR",
+                                       jz,sqrt(sig_s*sig_s+sig_o*sig_o)));
+        check_nomsg(cpl_table_set_double(z_pos,"WDIF",jz,wc_s-wc_o));
+        check_nomsg(cpl_table_set_double(z_pos,"WAVEC",jz,(wc_o+wc_s)/2));
+
+      } else {
+          check_nomsg(cpl_table_set_int(z_pos,"STATUS_S",jz,-3));
+          check_nomsg(cpl_table_set_int(z_pos,"STATUS_O",jz,-3));
+      }
+      sinfo_unwrap_vector(&vw);
+      sinfo_unwrap_vector(&vs);
+      sinfo_unwrap_vector(&vo);
+      sinfo_free_my_vector(&sx);
+      sinfo_free_my_vector(&sy);
+      sinfo_free_table(&w_tbl);
+      sinfo_free_table(&s_tbl);
+      sinfo_free_table(&o_tbl);
+    }
+  }
+
+
+  check_nomsg(cpl_table_duplicate_column(z_pos,"YDIF",z_pos,"WDIF"));
+  check_nomsg(cpl_table_divide_scalar(z_pos,"YDIF",dispersion));
+  //sinfo_table_column_dump(z_pos,"WAVEC",CPL_TYPE_DOUBLE);
+  //sinfo_table_column_dump(z_pos,"STATUS",CPL_TYPE_INT);
+  //sinfo_table_column_dump(z_pos,"WDIF",CPL_TYPE_DOUBLE);
+
+  check_nomsg(cpl_table_and_selected_int(z_pos,"STATUS_S",CPL_GREATER_THAN,-2));
+  check_nomsg(cpl_table_and_selected_int(z_pos,"STATUS_O",CPL_GREATER_THAN,-2));
+
+  //check_nomsg(cpl_table_save(z_pos,NULL,NULL,
+  //                             "out_z_pos.fits",CPL_IO_DEFAULT));
+
+  //goto cleanup;
+
+  check_nomsg(z_good=cpl_table_extract_selected(z_pos));
+  check_nomsg(npos=cpl_table_get_nrow(z_good));
+  sinfo_free_table(&z_pos);
+  if(npos == 0) {
+    return 0;
+  }
+  check_nomsg(z_pos=cpl_table_duplicate(z_good));
+  check_nomsg(z_mean = cpl_table_get_column_median(z_pos,"WDIF"));
+  check_nomsg(z_sdv  = cpl_table_get_column_stdev(z_pos,"WDIF"));
+
+  //check_nomsg(cpl_table_save(z_pos,NULL,NULL,
+  //                             "out_z_pos.fits",CPL_IO_DEFAULT));
+
+  check_nomsg(cpl_table_duplicate_column(z_pos,"CHECK",
+                                         z_pos,"WDIF"));
+
+
+  cpl_table_erase_column(z_pos,"AMPO");
+  cpl_table_erase_column(z_pos,"SIGO");
+  cpl_table_erase_column(z_pos,"AREAO");
+  cpl_table_erase_column(z_pos,"BKGO");
+  cpl_table_erase_column(z_pos,"WAVEO");
+  cpl_table_erase_column(z_pos,"AMPS");
+  cpl_table_erase_column(z_pos,"SIGS");
+  cpl_table_erase_column(z_pos,"AREAS");
+  cpl_table_erase_column(z_pos,"BKGS");
+  cpl_table_erase_column(z_pos,"WAVES");
+  cpl_table_erase_column(z_pos,"STATUS_S");
+  cpl_table_erase_column(z_pos,"STATUS_O");
+
+  cpl_table_erase_column(z_pos,"INT");
+  cpl_table_erase_column(z_pos,"INT1");
+  cpl_table_erase_column(z_pos,"INT2");
+  cpl_table_erase_column(z_pos,"ERR");
+  cpl_table_erase_column(z_pos,"POS");
+  cpl_table_erase_column(z_pos,"DIFF");
+
+  //check_nomsg(cpl_table_save(z_good,NULL,NULL,
+  //                             "out_z_good.fits",CPL_IO_DEFAULT));
+  //Do a kappa-sigma clip of the differences of line positions
+  //as determined in the object and in the sky spectrum
+
+  sinfo_msg("ks-clip1");
+  sinfo_msg("iter mean (um) sdv (um) mean (pix) sdv (pix)");
+  //sinfo_table_column_dump(z_pos,"WAVEC",CPL_TYPE_DOUBLE);
+  //sinfo_table_column_dump(z_pos,"WDIF",CPL_TYPE_DOUBLE);
+
+  for (iq = 0;iq<XCOR_YSHIFT_KS_CLIP;iq++) {
+    //sinfo_msg("nval=%d",cpl_table_get_nrow(z_pos));
+    sinfo_msg("  %d  %3.2g   %3.2g  %5.4g     %5.4g",
+               iq,z_mean,z_sdv,z_mean/dispersion,z_sdv/dispersion);
+    //z_good = where(abs(g_diff-z_mean) <= 2*z_sdv);
+
+    check_nomsg(cpl_table_subtract_scalar(z_pos,"CHECK",z_mean));
+    check_nomsg(cpl_table_duplicate_column(z_pos,"CHECKW",z_pos,"CHECK"));
+    check_nomsg(cpl_table_multiply_columns(z_pos,"CHECKW","CHECK"));
+    check_nomsg(cpl_table_power_column(z_pos,"CHECKW",0.5));
+    check_nomsg(cpl_table_add_scalar(z_pos,"CHECK",z_mean));
+    check_nomsg(cpl_table_and_selected_double(z_pos,"CHECKW",
+                                              CPL_NOT_GREATER_THAN,2*z_sdv));
+    sinfo_free_table(&z_good);
+    check_nomsg(z_good=cpl_table_extract_selected(z_pos));
+    //sinfo_msg("ngood=%d",cpl_table_get_nrow(z_good));
+    check_nomsg(cpl_table_select_all(z_pos));
+    //z_mean = median(g_diff[z_good]);
+    //z_sdv = stddev(g_diff[z_good]);
+    check_nomsg(z_mean = cpl_table_get_column_median(z_good,"WDIF"));
+    if(nfit>1) {
+    check_nomsg(z_sdv  = cpl_table_get_column_stdev(z_good,"WDIF"));
+    } else {
+      z_sdv=0;
+    }
+    sinfo_free_table(&z_good);
+    check_nomsg(cpl_table_erase_column(z_pos,"CHECKW"));
+
+  }
+  /* do a poly fit of wdif versus wave*/
+  /*
+  for (iq = 0; iq<3; iq++) {
+    // sinfo_msg("%d %f %f",iq,mean(zfit),zsdv);
+    par1 = poly_fit(g_lam[z_good],g_diff[z_good],poly_n);
+    z_fit = g_diff*0.;
+    for (ii=0;ii<poly_n) z_fit = z_fit + par1[ii]*g_lam^ii;
+    z_res = g_diff-z_fit;
+    z_sdv = stddev(z_res[zgood]);
+    z_good = where(abs(z_res) le 3*z_sdv);
+  }
+  */
+  cpl_table_select_all(z_pos);
+  check_nomsg(cpl_table_new_column(z_pos,"ZFIT",CPL_TYPE_DOUBLE));
+  check_nomsg(nfit=cpl_table_get_nrow(z_pos));
+  check_nomsg(cpl_table_fill_column_window(z_pos,"ZFIT",0,nfit,0));
+  //check_nomsg(cpl_table_save(z_pos,NULL,NULL,
+  //                             "out_z_pos2.fits",CPL_IO_DEFAULT));
+  check_nomsg(z_good=cpl_table_duplicate(z_pos));
+
+  //Do a fit of a uniform function to the residuals line position differences
+  sinfo_msg("ks-clip2");
+  sinfo_msg("iter mean (um) sdv (um) mean (pix) sdv (pix)");
+  check_nomsg(cpl_table_select_all(z_good));
+  //sinfo_table_column_dump(z_pos,"WDIF",CPL_TYPE_DOUBLE);
+  for(iq=0;iq<XCOR_YSHIFT_KS_CLIP;iq++) {
+    //cpl_table_dump(z_pos,0,cpl_table_get_nrow(z_pos),stdout);
+    check_nomsg(nfit=cpl_table_get_nrow(z_good));
+    //sinfo_msg("nfit=%d",nfit);
+    if(nfit>0) {
+    check_nomsg(vx=cpl_vector_wrap(nfit,
+                   cpl_table_get_data_double(z_good,"WAVE")));
+    check_nomsg(vy=cpl_vector_wrap(nfit,
+                   cpl_table_get_data_double(z_good,"WDIF")));
+    check_nomsg(cfit=sinfo_polynomial_fit_1d_create(vx,vy,0,&mse));
+    pows[0]=0;
+    pows[1]=0;
+    check_nomsg(zfit=cpl_polynomial_get_coeff(cfit,pows));
+    sinfo_free_polynomial(&cfit);
+    //sinfo_msg("coeff 0=%g um %g pix",zfit,zfit/dispersion);
+
+    //computes residuals=difference-fit and their standard deviation
+    //and then do a kappa-sigma clip of outliers (out of 3 sigma)
+    check_nomsg(cpl_table_fill_column_window(z_good,"ZFIT",0,nfit,zfit));
+    check_nomsg(cpl_table_duplicate_column(z_good,"WRES",z_good,"WDIF"));
+    check_nomsg(cpl_table_subtract_columns(z_good,"WRES","ZFIT"));
+    if(nfit>1) {
+      //sinfo_msg("nfit=%d",nfit);
+      //cpl_table_dump(z_good,0,nfit,stdout);
+      check_nomsg(z_sdv=cpl_table_get_column_stdev(z_good,"WRES"));
+      //sinfo_msg("z_sdv=%f",z_sdv);
+    } else {
+      z_sdv=0;
+    }
+    check_nomsg(z_mean=cpl_table_get_column_mean(z_good,"WDIF"));
+
+    sinfo_msg("  %d  %3.2g   %3.2g  %5.4g     %5.4g",
+              iq,z_mean,z_sdv,z_mean/dispersion,z_sdv/dispersion);
+
+    check_nomsg(nfit=cpl_table_get_nrow(z_pos));
+    check_nomsg(cpl_table_fill_column_window(z_pos,"ZFIT",0,nfit,zfit));
+    check_nomsg(cpl_table_duplicate_column(z_pos,"WRES",z_pos,"WDIF"));
+    check_nomsg(cpl_table_subtract_columns(z_pos,"WRES","ZFIT"));
+
+    check_nomsg(cpl_table_multiply_columns(z_pos,"WRES","WRES"));
+    check_nomsg(cpl_table_power_column(z_pos,"WRES",0.5));
+    //cpl_table_dump(z_pos,0,cpl_table_get_nrow(z_pos),stdout);
+    /*
+    sinfo_msg("min=%g max=%g ndat=%d",
+              cpl_table_get_column_min(z_pos,"WRES"),
+              cpl_table_get_column_max(z_pos,"WRES"),
+              cpl_table_get_nrow(z_pos));
+    */
+    check_nomsg(cpl_table_and_selected_double(z_pos,"WRES",
+                                              CPL_NOT_GREATER_THAN,3*z_sdv));
+
+    check_nomsg(sinfo_free_table(&z_good));
+    check_nomsg(z_good=cpl_table_extract_selected(z_pos));
+
+
+    check_nomsg(cpl_table_select_all(z_pos));
+    check_nomsg(cpl_table_select_all(z_good));
+    check_nomsg(cpl_table_erase_column(z_good,"WRES"));
+    check_nomsg(cpl_table_erase_column(z_pos,"WRES"));
+
+    sinfo_unwrap_vector(&vx);
+    sinfo_unwrap_vector(&vy);
+
+    }
+
+  }
+  //sinfo_msg(">>mean=%g",cpl_table_get_column_mean(z_good,"WDIF"));
+
+  //check_nomsg(cpl_table_save(z_good,NULL,NULL,
+  //                             "out_z_pos3.fits",CPL_IO_DEFAULT));
+  sinfo_unwrap_vector(&vx);
+  sinfo_unwrap_vector(&vy);
+  sinfo_free_polynomial(&cfit);
+  sinfo_free_table(&z);
+  sinfo_free_table(&z_pos);
+  sinfo_free_table(&z_good);
+
+
+  return zfit;
+ cleanup:
+
+  sinfo_free_table(&z_good);
+  sinfo_free_table(&z);
+  sinfo_free_table(&z_diff);
+  sinfo_free_table(&tmp_sky);
+  sinfo_free_table(&z_pos);
+  sinfo_unwrap_vector(&vw);
+  sinfo_unwrap_vector(&vs);
+  sinfo_unwrap_vector(&vo);
+  sinfo_free_my_vector(&sx);
+  sinfo_free_my_vector(&sy);
+  sinfo_unwrap_vector(&vx);
+  sinfo_unwrap_vector(&vy);
+  sinfo_free_table(&w_tbl);
+  sinfo_free_table(&s_tbl);
+  sinfo_free_table(&o_tbl);
+  sinfo_free_polynomial(&cfit);
+
+  return 0;
+
+
+}
+
+
+
+
+/**
+ at name sinfo_table_flag_nan
+ at memo flag NAN values in a table column
+ at param t input table
+ at param label column name
+ at param min minimum value
+ at param min maximum value
+
+ at return 0 if success, -1 else
+
+*/
+
+static int
+sinfo_table_set_nan_out_min_max(cpl_table** t,
+                                const char* c,
+                                const double min,
+                                const double max)
+
+{
+
+  int sz=0;
+  int i=0;
+  double* pt=NULL;
+
+  check_nomsg(sz=cpl_table_get_nrow(*t));
+  check_nomsg(pt=cpl_table_get_data_double(*t,c));
+  for(i=0;i<sz;i++) {
+    if(pt[i] < min || pt[i] > max) {
+      check_nomsg(cpl_table_set_invalid(*t ,c,i));
+    }
+  }
+
+  return 0;
+
+ cleanup:
+
+  return -1;
+
+
+}
+
+/**
+ at name sinfo_table_flag_nan
+ at memo flag NAN values in a table column
+ at param t input table
+ at param label column name
+ at return 0 if success, -1 else
+
+*/
+
+static int
+sinfo_table_flag_nan(cpl_table** t,const char* label)
+{
+
+  int sz=0;
+  int i=0;
+  double* pt=NULL;
+
+  check_nomsg(sz=cpl_table_get_nrow(*t));
+  check_nomsg(pt=cpl_table_get_data_double(*t,label));
+  for(i=0;i<sz;i++) {
+    if(irplib_isnan(pt[i])) {
+      check_nomsg(cpl_table_set_invalid(*t ,label,i));
+    }
+  }
+
+  return 0;
+
+ cleanup:
+
+  return -1;
+}
+
+/**
+ at name sinfo_table_sky_obj_flag_nan
+ at memo flag raws for which both object and sky table intensity is NAN
+ at param s sky table
+ at param o obj table
+ at param w wavelength table
+ at return 0 if success, -1 else
+*/
+
+static int
+sinfo_table_sky_obj_flag_nan(cpl_table** s,cpl_table** o, cpl_table** w)
+{
+
+  int no=0;
+  int ns=0;
+  int nw=0;
+  int ni=0;
+
+  int i=0;
+  double* po=NULL;
+  double* ps=NULL;
+  double* pw=NULL;
+
+  check_nomsg(no=cpl_table_get_nrow(*o));
+  check_nomsg(ns=cpl_table_get_nrow(*s));
+  check_nomsg(nw=cpl_table_get_nrow(*w));
+  if(no != ns || ns != nw || no != nw) {
+    sinfo_msg_error("different input tables sizes");
+    goto cleanup;
+  }
+  check_nomsg(po=cpl_table_get_data_double(*o,"INT"));
+  check_nomsg(ps=cpl_table_get_data_double(*s,"INT"));
+  check_nomsg(pw=cpl_table_get_data_double(*w,"WAVE"));
+
+  for(i=0;i<no;i++) {
+    if( (0==cpl_table_is_valid(*o,"INT",i)) ||
+        irplib_isnan(po[i]) || irplib_isnan(ps[i]) || irplib_isnan(pw[i]) ) {
+      check_nomsg(cpl_table_set_invalid(*o ,"INT",i));
+      check_nomsg(cpl_table_set_invalid(*s ,"INT",i));
+      check_nomsg(cpl_table_set_invalid(*w ,"WAVE",i));
+      //sinfo_msg_debug("Flagged raw %d",i);
+      ni++;
+    }
+  }
+
+  return no-ni;
+
+ cleanup:
+
+  return -1;
+}
+
+/*
+static void
+sinfo_shift_sky(const int x,const int y)
+{
+
+  //To remove compilation warnings
+  ck0_nomsg(x);
+  ck0_nomsg(y);
+
+  // shift sky spectrum of a given amount
+  if (max(abs(z_fit))/cdelts < 0.01) {
+    sinfo_msg("shift <0.01 pixels will not be applied");
+  } else {
+    sinfo_msg("shifting sky cube by mean of %f pix wrt object",
+             cpl_table_column_mean(z_fit,"VALUE")/cdelto);
+    sinfo_msg("this will take a couple of minutes...");
+    z_good = where(finite(int_sky));
+    new_sky = spline(lambda[z_good]-z_mean,int_sky[z_good],lambda);
+    int_sky = new_sky;
+    sky_out = dblarr(xsize,ysize,zsize) + !values.f_nan;
+    for (ix=0; ix<xsize;ix++) {
+      for (iy=0;iy<ysize;iy++) {
+    old_sky = reform(sky[ix,iy,*]);
+    z_good = where(finite(old_sky),z_good_i);
+    if (z_good_i > 0) {
+          new_sky= spline(lambda[z_good]-z_fit[z_good],old_sky[z_good],lambda);
+          new_fin= where(finite(new_sky,/infinity) ||
+                          finite(old_sky,/nan),newfin_i);
+      if (new_fin_i > 0) new_sky[new_fin] = !values.f_nan;
+      sky_out[ix,iy,*] = new_sky;
+    }
+      }
+    }
+    sky = sky_out;
+  }
+ cleanup:
+  return;
+
+}
+  */
+/**
+ at name  sinfo_optimise_sky_sub
+ at memo  optimse sky subtraction
+ at param wtol    tolerance on wavelength for selection
+ at param line_hw line half width
+ at param method  optimization method to determine ratio line(obj)/line(sky)
+ at param lambda  wavelength range
+ at param lr41    4-1 transition wavelength range table
+ at param lr52    5-2 transition wavelength range table
+ at param lr63    6-3 transition wavelength range table
+ at param lr74    7-4 transition wavelength range table
+ at param lr02    0-2 transition wavelength range table
+ at param lr85    8-5 transition wavelength range table
+ at param lr20    2-0 transition wavelength range table
+ at param lr31    3-1 transition wavelength range table
+ at param lr42    4-2 transition wavelength range table
+ at param lr53    5-3 transition wavelength range table
+ at param lr64    6-4 transition wavelength range table
+ at param lr75    7-5 transition wavelength range table
+ at param lr86    8-6 transition wavelength range table
+ at param lr97    9-7 transition wavelength range table
+ at param lr00    0-0 transition wavelength range table
+ at param int_obj input/output(corrected) object spectrum
+ at param int_sky input/output(corrected) sky spectrum
+ at param rscale  output computed ratio table
+*/
+void
+sinfo_optimise_sky_sub(const double wtol,
+                       const double line_hw,
+                       const int method,
+                       const int do_rot,
+                       cpl_table* lrange,
+                       cpl_table* lambda,
+                       cpl_table* lr41,
+                       cpl_table* lr52,
+                       cpl_table* lr63,
+                       cpl_table* lr74,
+                       cpl_table* lr02,
+                       cpl_table* lr85,
+                       cpl_table* lr20,
+                       cpl_table* lr31,
+                       cpl_table* lr42,
+                       cpl_table* lr53,
+                       cpl_table* lr64,
+                       cpl_table* lr75,
+                       cpl_table* lr86,
+                       cpl_table* lr97,
+                       cpl_table* lr00,
+                       cpl_table** int_obj,
+                       cpl_table** int_sky,
+                       cpl_table** rscale)
+
+{
+
+  int npixw=2*line_hw; //full width in pixels of unresolved emission line
+  cpl_array* do_hk=NULL;
+  cpl_array* rfit=NULL;
+  int i=0;
+  cpl_table* sky_lr=NULL;
+  cpl_table* obj_lr=NULL;
+  cpl_table* wav_lr=NULL;
+  double sky_med=0;
+  double sky_sdv=0;
+  int lr41_i=0;
+  int lr52_i=0;
+  int lr63_i=0;
+  int lr74_i=0;
+  int lr02_i=0;
+  int lr85_i=0;
+  int lr20_i=0;
+  int lr31_i=0;
+  int lr42_i=0;
+  int lr53_i=0;
+  int lr64_i=0;
+  int lr75_i=0;
+  int lr86_i=0;
+  int lr97_i=0;
+  int lr00_i=0;
+
+  int xxx1_i=0;
+  int status=0;
+  int finite_pix_i=0;
+  double sky_thresh=0.;
+
+  cpl_table* rat_sky=NULL;
+
+  cpl_table* xxx1=NULL;
+  cpl_table* xxx2=NULL;
+  cpl_table* xxx1_sub=NULL;
+  cpl_table* line_regions=NULL;
+  cpl_table* cont_regions=NULL;
+  int line_i=0;
+  int cont_i=0;
+  double fmed=0;
+  double fsdv=0;
+  cpl_table* fline_res=NULL;
+  int fclip_i=0;
+  int fline_i=0;
+  cpl_table* rscale0=NULL;
+  double r=0;
+  cpl_table* obj_cont=NULL;
+  cpl_table* sky_cont=NULL;
+  cpl_table* obj_line=NULL;
+  cpl_table* sky_line=NULL;
+
+
+  //Rotational parameters
+  int low_pos_i=0;
+  int med_pos_i=0;
+  int hi_pos_i=0;
+
+  cpl_table* finite_pix=NULL;
+  cpl_table* tmp_tbl=NULL;
+
+  cpl_table* low_scale=NULL;
+  cpl_table* med_scale=NULL;
+  cpl_table* hi_regions=NULL;
+
+  cpl_table* low_regions=NULL;
+  cpl_table* med_regions=NULL;
+
+
+  cpl_table* low_pos=NULL;
+  cpl_table* med_pos=NULL;
+  cpl_table* hi_pos=NULL;
+  cpl_table* llr_xxx1=NULL;
+
+  double rhi=0;
+  double rmed=0;
+  double rlow=0;
+
+  double min_lrange=0;
+  double max_lrange=0;
+
+  int nrow=0;
+
+
+  double w_rot_low[NROT]={1.00852,1.03757,1.09264,1.15388,1.22293,
+                          1.30216,1.45190,1.52410,1.60308,1.69037,
+                          1.78803,2.02758,2.18023,1.02895,1.08343,
+                          1.14399,1.21226,1.29057,1.43444,1.50555,
+                          1.58333,1.66924,1.76532,2.00082,2.15073};
+
+
+  double w_rot_med[NROT]={1.00282,1.02139,1.04212,1.07539,1.09753,
+                          1.13542,1.15917,1.20309,1.22870,1.28070,
+                          1.30853,1.41861,1.46048,1.48877,1.53324,
+                          1.56550,1.61286,1.65024,1.70088,1.74500,
+                          1.79940,1.97719,2.04127,2.12496,2.19956};
+
+
+
+  check_nomsg(do_hk = cpl_array_new(NBOUND+1,CPL_TYPE_INT));
+  check_nomsg(rfit  = cpl_array_new(NBOUND+1,CPL_TYPE_DOUBLE));
+
+  lr41_i=cpl_table_get_nrow(lr41);
+  lr52_i=cpl_table_get_nrow(lr52);
+  lr63_i=cpl_table_get_nrow(lr63);
+  lr74_i=cpl_table_get_nrow(lr74);
+  lr02_i=cpl_table_get_nrow(lr02);
+  lr85_i=cpl_table_get_nrow(lr85);
+  lr20_i=cpl_table_get_nrow(lr20);
+  lr31_i=cpl_table_get_nrow(lr31);
+  lr42_i=cpl_table_get_nrow(lr42);
+  lr53_i=cpl_table_get_nrow(lr53);
+  lr64_i=cpl_table_get_nrow(lr64);
+  lr75_i=cpl_table_get_nrow(lr75);
+  lr86_i=cpl_table_get_nrow(lr86);
+  lr97_i=cpl_table_get_nrow(lr97);
+  check_nomsg(lr00_i=cpl_table_get_nrow(lr00));
+
+  cpl_array_set_int(do_hk,0,lr41_i);
+  cpl_array_set_int(do_hk,1,lr52_i);
+  cpl_array_set_int(do_hk,2,lr63_i);
+  cpl_array_set_int(do_hk,3,lr74_i);
+  cpl_array_set_int(do_hk,4,lr02_i);
+  cpl_array_set_int(do_hk,5,lr85_i);
+  cpl_array_set_int(do_hk,6,lr20_i);
+  cpl_array_set_int(do_hk,7,lr31_i);
+  cpl_array_set_int(do_hk,8,lr42_i);
+  cpl_array_set_int(do_hk,9,lr53_i);
+  cpl_array_set_int(do_hk,10,lr64_i);
+  cpl_array_set_int(do_hk,11,lr75_i);
+  cpl_array_set_int(do_hk,12,lr86_i);
+  cpl_array_set_int(do_hk,13,lr97_i);
+  check_nomsg(cpl_array_set_int(do_hk,14,lr00_i));
+
+  check_nomsg(rscale0=cpl_table_duplicate(*int_sky));
+  check_nomsg(cpl_table_new_column(rscale0,"RATIO",CPL_TYPE_DOUBLE));
+  check_nomsg(nrow=cpl_table_get_nrow(rscale0));
+  check_nomsg(cpl_table_fill_column_window(rscale0,"RATIO",0,nrow,0));
+
+  // For each range extract proper: obj, sky, wave spectra
+  for (i=0;i<NBOUND+1;i++) {
+    if (cpl_array_get_int(do_hk,i,&status) > 0) {
+
+
+      switch(i) {
+
+
+      case 0:
+        ck0_nomsg(sinfo_get_obj_sky_wav_sub(*int_obj,*int_sky,lambda,lr41,wtol,
+                        &obj_lr,&sky_lr,&wav_lr));
+	break;
+
+      case 1:
+        ck0_nomsg(sinfo_get_obj_sky_wav_sub(*int_obj,*int_sky,lambda,lr52,wtol,
+                        &obj_lr,&sky_lr,&wav_lr));
+	break;
+
+      case 2:
+        ck0_nomsg(sinfo_get_obj_sky_wav_sub(*int_obj,*int_sky,lambda,lr63,wtol,
+                        &obj_lr,&sky_lr,&wav_lr));
+	break;
+
+      case 3:
+        ck0_nomsg(sinfo_get_obj_sky_wav_sub(*int_obj,*int_sky,lambda,lr74,wtol,
+                        &obj_lr,&sky_lr,&wav_lr));
+	break;
+
+      case 4:
+        ck0_nomsg(sinfo_get_obj_sky_wav_sub(*int_obj,*int_sky,lambda,lr02,wtol,
+                        &obj_lr,&sky_lr,&wav_lr));
+	break;
+
+      case 5:
+        ck0_nomsg(sinfo_get_obj_sky_wav_sub(*int_obj,*int_sky,lambda,lr85,wtol,
+                        &obj_lr,&sky_lr,&wav_lr));
+	break;
+      case 6:
+        ck0_nomsg(sinfo_get_obj_sky_wav_sub(*int_obj,*int_sky,lambda,lr20,wtol,
+                        &obj_lr,&sky_lr,&wav_lr));
+	break;
+      case 7:
+        ck0_nomsg(sinfo_get_obj_sky_wav_sub(*int_obj,*int_sky,lambda,lr31,wtol,
+                        &obj_lr,&sky_lr,&wav_lr));
+	break;
+      case 8:
+        ck0_nomsg(sinfo_get_obj_sky_wav_sub(*int_obj,*int_sky,lambda,lr42,wtol,
+                        &obj_lr,&sky_lr,&wav_lr));
+	break;
+      case 9:
+        ck0_nomsg(sinfo_get_obj_sky_wav_sub(*int_obj,*int_sky,lambda,lr53,wtol,
+                        &obj_lr,&sky_lr,&wav_lr));
+	break;
+      case 10:
+        ck0_nomsg(sinfo_get_obj_sky_wav_sub(*int_obj,*int_sky,lambda,lr64,wtol,
+                        &obj_lr,&sky_lr,&wav_lr));
+	break;
+      case 11:
+        ck0_nomsg(sinfo_get_obj_sky_wav_sub(*int_obj,*int_sky,lambda,lr75,wtol,
+                        &obj_lr,&sky_lr,&wav_lr));
+	break;
+      case 12:
+        ck0_nomsg(sinfo_get_obj_sky_wav_sub(*int_obj,*int_sky,lambda,lr86,wtol,
+                        &obj_lr,&sky_lr,&wav_lr));
+	break;
+      case 13:
+        ck0_nomsg(sinfo_get_obj_sky_wav_sub(*int_obj,*int_sky,lambda,lr97,wtol,
+                        &obj_lr,&sky_lr,&wav_lr));
+	break;
+      case 14:
+         ck0_nomsg(sinfo_get_obj_sky_wav_sub(*int_obj,*int_sky,lambda,lr00,
+                         wtol,&obj_lr,&sky_lr,&wav_lr));
+	 break;
+      default:
+        sinfo_msg_error("case not supported");
+	goto cleanup;
+      }
+      if(sky_lr == NULL || obj_lr == NULL || wav_lr == NULL) {
+	finite_pix_i=0;
+        sinfo_msg("no good pix left");
+      } else {
+	//AMO: the following 2 seems to be critical for robustness
+	//check_nomsg(cpl_table_save(sky_lr,NULL,NULL,"out_skylr0.fits",
+	//			   CPL_IO_DEFAULT));
+	//check_nomsg(cpl_table_save(obj_lr,NULL,NULL,"out_objlr0.fits",
+	//			   CPL_IO_DEFAULT));
+	//check_nomsg(cpl_table_save(wav_lr,NULL,NULL,"out_wavlr0.fits",
+	//			   CPL_IO_DEFAULT));
+
+
+
+	check_nomsg(finite_pix_i=sinfo_table_sky_obj_flag_nan(&sky_lr,
+                                                              &obj_lr,
+                                                              &wav_lr));
+
+
+      }
+
+
+      if (finite_pix_i > npixw) {
+        // identify sky lines
+        //sinfo_msg("finite_pix_i=%d",finite_pix_i);
+        check_nomsg(cpl_table_erase_invalid(obj_lr));
+	check_nomsg(cpl_table_erase_invalid(sky_lr));
+	check_nomsg(cpl_table_erase_invalid(wav_lr));
+
+
+	check_nomsg(sky_med=cpl_table_get_column_median(sky_lr,"INT"));
+	check_nomsg(sky_sdv=cpl_table_get_column_stdev(sky_lr,"INT"));
+        check_nomsg(cpl_table_select_all(sky_lr));
+        sky_thresh=sky_med+sky_sdv;
+        //sinfo_msg("sky_thresh=%f",sky_thresh);
+        check_nomsg(xxx1_i=cpl_table_and_selected_double(sky_lr,"INT",
+                           CPL_GREATER_THAN,sky_thresh));
+	check_nomsg(xxx1 = cpl_table_extract_selected(sky_lr));
+        check_nomsg(cpl_table_select_all(sky_lr));
+
+	if (xxx1_i > 0) {
+	  //separate line and continuum regions
+          //by convolving with a hat region of large as a line
+          //sinfo_msg("xxx1_i=%d",xxx1_i);
+	  check_nomsg(xxx2 = cpl_table_duplicate(sky_lr));
+          //check_nomsg(cpl_table_save(sky_lr,NULL,NULL,
+          //                           "out_skylr.fits",CPL_IO_DEFAULT));
+          //check_nomsg(cpl_table_save(obj_lr,NULL,NULL,
+          //                             "out_objlr.fits",CPL_IO_DEFAULT));
+          //check_nomsg(cpl_table_save(xxx2,NULL,NULL,
+          //                             "out_xxx2_0.fits",CPL_IO_DEFAULT));
+          ck0_nomsg(sinfo_table_threshold(&xxx2,"INT",sky_thresh,
+                                          sky_thresh,0.,10.));
+          //check_nomsg(cpl_table_save(xxx2,NULL,NULL,
+          //                             "out_xxx2_1.fits",CPL_IO_DEFAULT));
+
+
+          /* TODO
+      xxx2[xxx1] = 10.;
+      */
+          //sinfo_msg("npixw/2=%d",npixw);
+	  check_nomsg(sinfo_convolve_kernel(&xxx2,npixw/2));
+          //check_nomsg(cpl_table_save(xxx2,NULL,NULL,
+          //                             "out_xxx2_2.fits",CPL_IO_DEFAULT));
+
+          // get line_regions
+          check_nomsg(line_i=cpl_table_and_selected_double(xxx2,"CNV",
+                                                         CPL_GREATER_THAN,0));
+
+          check_nomsg(line_regions=cpl_table_extract_selected(xxx2));
+
+          //check_nomsg(cpl_table_save(line_regions,NULL,NULL,
+          //"out_line_regions.fits",CPL_IO_DEFAULT));
+
+	  check_nomsg(cpl_table_erase_column(line_regions,"INT"));
+	  check_nomsg(cpl_table_erase_column(line_regions,"CNV"));
+
+          check_nomsg(cpl_table_select_all(xxx2));
+
+          // get cont_regions
+          check_nomsg(cont_i=cpl_table_and_selected_double(xxx2,"CNV",
+                                                           CPL_EQUAL_TO,0));
+          check_nomsg(cont_regions=cpl_table_extract_selected(xxx2));
+
+          //check_nomsg(cpl_table_save(line_regions,NULL,NULL,
+          //"out_cont_regions.fits",CPL_IO_DEFAULT));
+
+	  check_nomsg(cpl_table_erase_column(cont_regions,"INT"));
+	  check_nomsg(cpl_table_erase_column(cont_regions,"CNV"));
+          check_nomsg(cpl_table_select_all(xxx2));
+	  sinfo_free_table(&xxx2);
+
+
+	  if (line_i >= 3 && cont_i >= 3) {
+            //If we have enough line points and continuum points
+             //sinfo_msg("line_i=%d cont_i=%d",line_i,cont_i);
+	    if (i == 0) sinfo_msg("optimising 4-1 transitions");
+            if (i == 1) sinfo_msg("optimising 5-2 transitions");
+            if (i == 2) sinfo_msg("optimising 6-3 transitions");
+            if (i == 3) sinfo_msg("optimising 7-4 transitions");
+            if (i == 4) sinfo_msg("optimising 0-2 transitions");
+            if (i == 5) sinfo_msg("optimising 8-5 transitions");
+            if (i == 6) sinfo_msg("optimising 2-0 transitions");
+            if (i == 7) sinfo_msg("optimising 3-1 transitions");
+            if (i == 8) sinfo_msg("optimising 4-2 transitions");
+            if (i == 9) sinfo_msg("optimising 5-3 transitions");
+            if (i == 10) sinfo_msg("optimising 6-4 transitions");
+            if (i == 11) sinfo_msg("optimising 7-5 transitions");
+            if (i == 12) sinfo_msg("optimising 8-6 transitions");
+            if (i == 13) sinfo_msg("optimising 9-7 transitions");
+            if (i == 14) sinfo_msg("optimising final bit");
+	    // Fit the object profile='fline_res' of the sky line residuals
+            // left after proper scaled sky spectrum lines (and continua)
+            // subtraction. Then determines median and stdev to flag outliers
+
+	    //Free memory for each loop
+            sinfo_free_table(&obj_cont);
+            sinfo_free_table(&sky_cont);
+            sinfo_free_table(&sky_line);
+            sinfo_free_table(&obj_line);
+	    //Identify obj lines and continuum, same for sky
+            cknull_nomsg(obj_line=sinfo_table_select_range(obj_lr,line_regions,
+                                  wtol));
+
+
+            cknull_nomsg(sky_line=sinfo_table_select_range(sky_lr,line_regions,
+                                  wtol));
+            cknull_nomsg(obj_cont=sinfo_table_select_range(obj_lr,cont_regions,
+                                  wtol));
+             cknull_nomsg(sky_cont=sinfo_table_select_range(sky_lr,cont_regions,
+                                  wtol));
+
+	    //Here was commented
+            //check_nomsg(cpl_table_save(line_regions,NULL,NULL,
+            //            "out_line.fits",CPL_IO_DEFAULT));
+            //check_nomsg(cpl_table_save(cont_regions,NULL,NULL,
+            //            "out_cont.fits",CPL_IO_DEFAULT));
+            //check_nomsg(cpl_table_save(obj_cont,NULL,NULL,
+            //            "out_obj_cont.fits",CPL_IO_DEFAULT));
+            //check_nomsg(cpl_table_save(obj_line,NULL,NULL,
+            //            "out_obj_line.fits",CPL_IO_DEFAULT));
+            //check_nomsg(cpl_table_save(sky_line,NULL,NULL,
+            //            "out_sky_line.fits",CPL_IO_DEFAULT));
+            //check_nomsg(cpl_table_save(sky_cont,NULL,NULL,
+            //            "out_sky_cont.fits",CPL_IO_DEFAULT));
+
+
+            sinfo_free_table(&fline_res);
+            //FIXME: in some cases obj_cont is empty
+            //sinfo_msg("first line ratio determination");
+            ck0_nomsg(sinfo_get_line_ratio(obj_line,obj_cont,
+					   sky_line,sky_cont,method,&r));
+	    sinfo_msg("1st Line ratio %g",r);
+
+
+            if(cpl_table_get_nrow(obj_cont) > 0) {
+               check_nomsg(fline_res=sinfo_table_interpol(obj_line,obj_cont,
+                                                          sky_line,sky_cont,
+                                                          r));
+	    } else {
+              check_nomsg(fline_res=cpl_table_duplicate(obj_line));
+	    }
+
+            // check if there are outliers
+            cpl_table_select_all(fline_res);
+            check_nomsg(fmed = cpl_table_get_column_median(fline_res,"INT"));
+            check_nomsg(fsdv = cpl_table_get_column_stdev(fline_res,"INT"));
+
+            check_nomsg(cpl_table_duplicate_column(fline_res,"AINT",
+                                                   fline_res,"INT"));
+            check_nomsg(cpl_table_multiply_columns(fline_res,"AINT","INT"));
+            check_nomsg(cpl_table_power_column(fline_res,"AINT",0.5));
+            check_nomsg(fclip_i=cpl_table_and_selected_double(fline_res,"AINT",
+                                                  CPL_GREATER_THAN,
+                                                  fmed+3*fsdv));
+
+            check_nomsg(cpl_table_select_all(fline_res));
+
+
+	    if (fclip_i > 0) {
+              // do a k-sigma clip to select a better line region
+              //sinfo_msg("fclip_i=%d",fclip_i);
+              //Find again line_regions
+              check_nomsg(line_i=cpl_table_and_selected_double(fline_res,
+							       "AINT",
+							       CPL_NOT_GREATER_THAN,
+							       fmed+3*fsdv));
+	      // get new (better) line_regions
+	      sinfo_free_table(&line_regions);
+              //sinfo_msg("line_i=%d",line_i);
+              check_nomsg(line_regions=cpl_table_extract_selected(fline_res));
+              check_nomsg(cpl_table_erase_column(line_regions,"INT"));
+              check_nomsg(cpl_table_erase_column(line_regions,"AINT"));
+
+	      sinfo_free_table(&obj_line);
+	      sinfo_free_table(&sky_line);
+
+	      //check_nomsg(cpl_table_save(obj_lr,NULL,NULL,
+              //                           "out_obj_lr.fits",CPL_IO_DEFAULT));
+	      //check_nomsg(cpl_table_save(line_regions,NULL,NULL,
+              //                           "out_line_regions.fits",
+              //                           CPL_IO_DEFAULT));
+
+
+
+
+	      // The following 2 may return an error so we do not check and
+	      // later we reset the error
+              obj_line=sinfo_table_select_range(obj_lr,line_regions,wtol);
+              sky_line=sinfo_table_select_range(sky_lr,line_regions,wtol);
+              fline_i=cpl_table_get_nrow(line_regions);
+
+              //sinfo_msg("fline_i=%d",fline_i);
+              if(fline_i>=3) {
+                // repeat the determination of the line ratio
+                //sinfo_msg("second line ratio determination");
+                ck0_nomsg(sinfo_get_line_ratio(obj_line,obj_cont,
+                                                sky_line,sky_cont,method,&r));
+
+		sinfo_msg("2nd Line ratio %g",r);
+
+	      } else {
+                cpl_error_reset();
+	      }
+
+	      sinfo_free_table(&sky_line);
+	      sinfo_free_table(&obj_line);
+	    }
+
+            cpl_msg_info(cpl_func,"use %" CPL_SIZE_FORMAT 
+                         " pixels for line and %" CPL_SIZE_FORMAT 
+                         " for continuum estimation",
+            cpl_table_get_nrow(line_regions),cpl_table_get_nrow(cont_regions));
+
+	    sinfo_msg("OH spectrum scaling = %f ",r);
+            check_nomsg(cpl_array_set_double(rfit,i,r));
+            ck0_nomsg(sinfo_table_set(&rscale0,wav_lr,r,wtol));
+
+	  } /* end if line_i */
+        } /* end if xxx1_i */
+     } /* end finite_pix_i */
+
+    }
+
+    sinfo_free_table(&xxx1);
+    sinfo_free_table(&xxx2);
+    sinfo_free_table(&sky_lr);
+    sinfo_free_table(&obj_lr);
+    sinfo_free_table(&wav_lr);
+
+    sinfo_free_table(&line_regions);
+    sinfo_free_table(&cont_regions);
+
+  } /* end for loop on i */
+
+  sinfo_free_array(&do_hk);
+  sinfo_free_array(&rfit);
+
+  //sinfo_msg("n scale=%d",cpl_table_get_nrow(rscale0));
+  //check_nomsg(cpl_table_save(rscale0,NULL,NULL,
+  //                                   "out_rscale0.fits",CPL_IO_DEFAULT));
+
+  check_nomsg(cpl_table_select_all(rscale0));
+ /* TODO: here one has to implementa an interpol function
+  check_nomsg(range0_i=cpl_table_and_selected_double(rscale0,"RATIO",
+                                                     CPL_NOT_EQUAL_TO,0));
+ */
+  check_nomsg(*rscale = cpl_table_extract_selected(rscale0));
+  sinfo_free_table(&rscale0);
+
+
+  check_nomsg(rat_sky=cpl_table_duplicate(*int_sky));
+  check_nomsg(cpl_table_duplicate_column(rat_sky,"RATIO",*rscale,"RATIO"));
+  check_nomsg(cpl_table_duplicate_column(*int_obj,"COR_FCT_VIB",
+					 *rscale,"RATIO"));
+  //check_nomsg(cpl_table_save(rat_sky,NULL,NULL,
+  //                           "rat_sky0.fits",CPL_IO_DEFAULT));
+  check_nomsg(cpl_table_multiply_columns(rat_sky,"INT","RATIO"));
+
+
+  //check_nomsg(cpl_table_save(*int_obj,NULL,NULL,
+  //                             "out_obj0.fits",CPL_IO_DEFAULT));
+  //check_nomsg(cpl_table_save(*int_sky,NULL,NULL,
+  //                             "out_sky0.fits",CPL_IO_DEFAULT));
+
+  /*
+  check_nomsg(cpl_table_duplicate_column(*int_obj,"INTC",*int_obj,"INT"));
+  check_nomsg(cpl_table_duplicate_column(*int_obj,"SKYC",*int_sky,"INTC"));
+  check_nomsg(cpl_table_subtract_columns(*int_obj,"INTC","SKYC"));
+  */
+
+  // do simple rotational correction
+  if (do_rot == 1) {
+
+    //finite_pix = where(finite(int_sky) && finite(int_obj),finite_pix_i);
+    check_nomsg(min_lrange=cpl_table_get_column_min(lrange,"WAVE"));
+    check_nomsg(max_lrange=cpl_table_get_column_max(lrange,"WAVE"));
+    //sinfo_msg("min_lrange=%g max_lrange=%g",min_lrange,max_lrange);
+    //check_nomsg(finite_pix_i=sinfo_table_sky_obj_flag_nan(&rat_sky,
+    //                                                      int_obj,
+    //                                                      &lambda));
+    check_nomsg(finite_pix_i=sinfo_table_sky_obj_flag_nan(int_sky,
+                                                          int_obj,
+                                                          &lambda));
+
+
+    check_nomsg(finite_pix=cpl_table_duplicate(lambda));
+    //TODO: lambda invalid values need to be reset to valid (?)
+
+    check_nomsg(cpl_table_erase_invalid(finite_pix));
+
+
+    if (finite_pix_i > npixw) {
+
+      //finite_pix = finite_pix[where(finite_pix > min(lrange) &&
+      //                              finite_pix < max(lrange))];
+
+      check_nomsg(cpl_table_and_selected_double(finite_pix,"WAVE",
+                                                CPL_GREATER_THAN,
+                                                min_lrange));
+
+      check_nomsg(cpl_table_and_selected_double(finite_pix,"WAVE",
+                                                CPL_LESS_THAN,
+                                                max_lrange));
+
+
+
+      check_nomsg(tmp_tbl=cpl_table_extract_selected(finite_pix));
+      sinfo_free_table(&finite_pix);
+      check_nomsg(finite_pix=cpl_table_duplicate(tmp_tbl));
+      sinfo_free_table(&tmp_tbl);
+      sinfo_free_table(&sky_lr);
+      sinfo_free_table(&obj_lr);
+      sinfo_free_table(&wav_lr);
+
+
+      cknull(sky_lr=sinfo_table_select_range(rat_sky,finite_pix,wtol),
+         "extracting sky sub range");
+      cknull(obj_lr=sinfo_table_select_range(*int_obj,finite_pix,wtol),
+         "extracting obj sub range");
+      cknull(wav_lr=sinfo_table_select_range(lambda,finite_pix,wtol),
+         "extracting sky sub range");
+
+
+      //check_nomsg(cpl_table_save(rat_sky,NULL,NULL,
+      //                             "out_rat_sky.fits",CPL_IO_DEFAULT));
+      //check_nomsg(cpl_table_save(finite_pix,NULL,NULL,
+      //                             "out_finite_pix.fits",CPL_IO_DEFAULT));
+      //check_nomsg(cpl_table_save(sky_lr,NULL,NULL,
+      //                             "out_sky_lr.fits",CPL_IO_DEFAULT));
+      //check_nomsg(cpl_table_save(obj_lr,NULL,NULL,
+      //                             "out_obj_lr.fits",CPL_IO_DEFAULT));
+      //check_nomsg(cpl_table_save(wav_lr,NULL,NULL,
+      //                             "out_wav_lr.fits",CPL_IO_DEFAULT));
+
+      //The following may fail (sky_lr may be empty) so we do not check
+      if(1 == cpl_table_has_valid(sky_lr,"INT")) {
+	check_nomsg(sky_med=cpl_table_get_column_median(sky_lr,"INT"));
+	check_nomsg(sky_sdv=cpl_table_get_column_stdev(sky_lr,"INT"));
+	sky_thresh=sky_med+sky_sdv;
+        //xxx1 = where(sky_lr > median(sky_lr)+stddev(sky_lr),xxx1_i);
+        check_nomsg(xxx1_i=cpl_table_and_selected_double(sky_lr,"INT",
+                           CPL_GREATER_THAN,sky_thresh));
+        check_nomsg(xxx1=cpl_table_extract_selected(sky_lr));
+        check_nomsg(cpl_table_select_all(sky_lr));
+      } else {
+        xxx1_i=0;
+      }
+      if (xxx1_i > 0) {
+        sinfo_msg("xxx1_i=%d",xxx1_i);
+
+        sinfo_msg("wav_lr wmin=%g wmax=%g",
+          cpl_table_get_column_min(wav_lr,"WAVE"),
+          cpl_table_get_column_max(wav_lr,"WAVE"));
+
+        cknull_nomsg(llr_xxx1=sinfo_table_select_range(wav_lr,xxx1,wtol));
+        //check_nomsg(cpl_table_save(wav_lr,NULL,NULL,
+        //                             "out_llr_xxx1.fits",CPL_IO_DEFAULT));
+
+        cknull(low_pos=sinfo_find_rot_waves(w_rot_low,npixw,wtol,llr_xxx1),
+	       "Determining low positions");
+
+
+        check_nomsg(low_pos_i=cpl_table_get_nrow(low_pos));
+        //check_nomsg(cpl_table_dump(low_pos,0,low_pos_i,stdout));
+        cknull(med_pos=sinfo_find_rot_waves(w_rot_med,npixw,wtol,llr_xxx1),
+               "Determining med positions");
+        check_nomsg(med_pos_i=cpl_table_get_nrow(med_pos));
+
+
+        //check_nomsg(cpl_table_dump(med_pos,0,med_pos_i,stdout));
+
+        //TODO:
+        //hipos = [0]
+        //for i=0,n_elements(xxx1)-1 do begin
+        //    x1 = where(lowpos eq i,x1_i)
+        //    x2 = where(medpos eq i,x2_i)
+        //    if (x1_i eq 0 and x2_i eq 0) then hipos = [hipos,i]
+        //endfor
+        //hipos = hipos[1:n_elements(hipos)-1]
+        //TODO: hi_pos=sinfo_find_rot_waves(w_rot_hi,npixw,wtol,wav_lr);
+
+
+        cknull(hi_pos=sinfo_table_extract_rest(xxx1,low_pos,med_pos,wtol),
+           "determining hi position");
+        check_nomsg(hi_pos_i=cpl_table_get_nrow(hi_pos));
+        //check_nomsg(cpl_table_dump(hi_pos,0,hi_pos_i,stdout));
+
+
+        //xxx2[xxx1] = 10.;
+        check_nomsg(xxx2 = cpl_table_duplicate(sky_lr));
+        check_nomsg(nrow=cpl_table_get_nrow(sky_lr));
+        //check_nomsg(cpl_table_save(xxx2,NULL,NULL,
+        //                             "out_xxx1.fits",CPL_IO_DEFAULT));
+        //check_nomsg(cpl_table_save(xxx2,NULL,NULL,
+        //                             "out_xxx2_0.fits",CPL_IO_DEFAULT));
+
+        // AMO: Why the following?
+        //check_nomsg(cpl_table_fill_column_window(xxx2,"INT",0,nrow,0));
+
+        //xxx2 = convol(xxx2,replicate(1,npixw),/edge_truncate,/center);
+        //cont_regions = where(xxx2 == 0,cont_i);
+        ck0_nomsg(sinfo_table_threshold(&xxx2,"INT",sky_thresh,
+                    sky_thresh,0.,10.));
+        sinfo_msg("sky_thresh=%g %g %f",sky_thresh,sky_med,sky_sdv);
+        //check_nomsg(cpl_table_save(xxx2,NULL,NULL,
+        //                             "out_xxx2_1.fits",CPL_IO_DEFAULT));
+        check_nomsg(sinfo_convolve_kernel(&xxx2,npixw/2));
+
+        //check_nomsg(cpl_table_save(xxx2,NULL,NULL,
+        //                             "out_xxx2_2.fits",CPL_IO_DEFAULT));
+        check_nomsg(cont_i=cpl_table_and_selected_double(xxx2,"CNV",
+                             CPL_EQUAL_TO,0));
+        check_nomsg(cont_regions=cpl_table_extract_selected(xxx2));
+
+        sinfo_free_table(&xxx2);
+        check_nomsg(cpl_table_erase_column(cont_regions,"INT"));
+        check_nomsg(cpl_table_erase_column(cont_regions,"CNV"));
+
+        check(low_pos_i=sinfo_get_sub_regions(sky_lr,xxx1,low_pos,wtol,
+                         npixw,&low_regions),"failed determining low regions");
+
+        check(med_pos_i=sinfo_get_sub_regions(sky_lr,xxx1,med_pos,wtol,
+                         npixw,&med_regions),"failed determining med regions");
+
+
+        check(hi_pos_i=sinfo_get_sub_regions(sky_lr,xxx1,hi_pos,wtol,
+                        npixw,&hi_regions),"failed determining hi regions");
+    /*
+        sinfo_msg("xxx1: wmin=%g wmax=%g",
+                   cpl_table_get_column_min(xxx1,"WAVE"),
+                   cpl_table_get_column_max(xxx1,"WAVE"));
+
+        sinfo_msg("low_pos: wmin=%g wmax=%g",
+                   cpl_table_get_column_min(low_pos,"WAVE"),
+                   cpl_table_get_column_max(low_pos,"WAVE"));
+    */
+        sinfo_msg("hi_pos_i : %d med_pos_i : %d low_pos_i : %d cont_i: %d",
+                   hi_pos_i,     med_pos_i,     low_pos_i,     cont_i);
+
+
+        if (hi_pos_i >= 3 && med_pos_i >= 3 && low_pos_i >= 3 && cont_i >= 3) {
+
+          //compute line ratio for hi_regions
+          ck0_nomsg(sinfo_compute_line_ratio(obj_lr, sky_lr,wtol, method,
+                                             hi_regions,cont_regions,&rhi));
+          sinfo_msg("high rotational OH scaling %g",rhi);
+
+          //compute line ratio for med_regions
+          ck0_nomsg(sinfo_compute_line_ratio(obj_lr, sky_lr,wtol, method,
+                                             med_regions,cont_regions,&rmed));
+
+          sinfo_msg("P1(3.5) & R1(1.5) rotational OH scaling %g ",rmed);
+
+          //compute line ratio for med_regions
+          ck0_nomsg(sinfo_compute_line_ratio(obj_lr, sky_lr,wtol, method,
+                                             low_regions,cont_regions,&rlow));
+          sinfo_msg("P1(2.5) & Q1(1.5) rotational OH scaling %g",rlow);
+
+          cknull(low_scale=sinfo_find_rot_waves(w_rot_low,npixw,wtol,lambda),
+		 "Determining low scale");
+
+
+
+          cknull(med_scale=sinfo_find_rot_waves(w_rot_low,npixw,wtol,lambda),
+		 "Determining low scale");
+          check_nomsg(cpl_table_multiply_scalar(*rscale,"RATIO",rhi));
+          ck0_nomsg(sinfo_table_fill_column_over_range(rscale,med_scale,
+                                                  "RATIO",rmed/rhi,wtol));
+          ck0_nomsg(sinfo_table_fill_column_over_range(rscale,low_scale,
+                                 "RATIO",rlow/rhi,wtol));
+
+	}
+      } //xxx1_i > 0
+    }//finitepix > npixw
+  }//do_rot==1
+  //end of new rotational bit
+  //check_nomsg(cpl_table_save(*int_obj,NULL,NULL,
+  //                             "out_obj.fits",CPL_IO_DEFAULT));
+  //check_nomsg(cpl_table_save(*int_sky,NULL,NULL,
+  //                             "out_sky.fits",CPL_IO_DEFAULT));
+
+
+  check_nomsg(cpl_table_duplicate_column(*int_sky,"INTC",*int_sky,"INT"));
+  //sinfo_msg("n sky=%d",cpl_table_get_nrow(*int_sky));
+  //sinfo_msg("n scale=%d",cpl_table_get_nrow(*rscale));
+
+  check_nomsg(cpl_table_duplicate_column(*int_obj,"COR_FCT_ALL",
+                                         *rscale,"RATIO"));
+  check_nomsg(cpl_table_duplicate_column(*int_sky,"RATIO",*rscale,"RATIO"));
+  check_nomsg(cpl_table_multiply_columns(*int_sky,"INTC","RATIO"));
+
+  check_nomsg(cpl_table_duplicate_column(*int_obj,"INTC",*int_obj,"INT"));
+  //check_nomsg(cpl_table_save(*int_obj,NULL,NULL,
+  //                             "out_obj1.fits",CPL_IO_DEFAULT));
+  //check_nomsg(cpl_table_save(*int_sky,NULL,NULL,
+  //                             "out_sky1.fits",CPL_IO_DEFAULT));
+
+  check_nomsg(cpl_table_duplicate_column(*int_obj,"SKYC",*int_sky,"INTC"));
+  check_nomsg(cpl_table_subtract_columns(*int_obj,"INTC","SKYC"));
+
+
+  check_nomsg(cpl_table_erase_column(*int_sky,"INT"));
+  check_nomsg(cpl_table_name_column(*int_sky,"INTC","INT"));
+
+
+
+ cleanup:
+  sinfo_free_table(&llr_xxx1);
+  sinfo_free_table(&hi_pos);
+  sinfo_free_table(&low_pos);
+  sinfo_free_table(&med_pos);
+  sinfo_free_table(&low_regions);
+  sinfo_free_table(&med_regions);
+  sinfo_free_table(&hi_regions);
+  sinfo_free_table(&low_scale);
+  sinfo_free_table(&med_scale);
+
+
+  sinfo_free_table(&finite_pix);
+  sinfo_free_table(&xxx1_sub);
+  sinfo_free_table(&tmp_tbl);
+  sinfo_free_table(&rat_sky);
+  sinfo_free_table(&fline_res);
+  sinfo_free_table(&sky_cont);
+  sinfo_free_table(&obj_cont);
+  sinfo_free_table(&obj_line);
+  sinfo_free_table(&sky_line);
+  sinfo_free_table(&rscale0);
+  sinfo_free_table(&xxx1);
+  sinfo_free_table(&xxx2);
+  sinfo_free_table(&line_regions);
+  sinfo_free_table(&cont_regions);
+  sinfo_free_table(&sky_lr);
+  sinfo_free_table(&obj_lr);
+  sinfo_free_table(&wav_lr);
+  sinfo_free_array(&rfit);
+  sinfo_free_array(&do_hk);
+  return;
+
+}
+/**
+ at name sinfo_table_get_index_of_max
+ at memo find raw index of table column's max
+ at param t input table
+ at param name input table column
+ at param type CPL_TYPE of input table column
+ at return table raw correspoinding to table max
+*/
+int
+sinfo_table_get_index_of_max(cpl_table* t,const char* name,cpl_type type)
+{
+
+  int i=0;
+  int result=0;
+  int nrow=0;
+  int* pi=NULL;
+  float* pf=NULL;
+  double* pd=NULL;
+  double max=0;
+
+
+  if(t == NULL) {
+   cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT);
+   return result;
+  }
+  max=cpl_table_get_column_max(t,name);
+  nrow=cpl_table_get_nrow(t);
+  switch(type) {
+
+  case CPL_TYPE_INT:
+    pi=cpl_table_get_data_int(t,name);
+    for(i=0;i<nrow;i++) {
+      if(pi[i]==(int)max) result=i;
+    }
+    break;
+  case CPL_TYPE_FLOAT:
+    pf=cpl_table_get_data_float(t,name);
+    for(i=0;i<nrow;i++) {
+      if(pf[i]==(float)max) result=i;
+    }
+    break;
+  case CPL_TYPE_DOUBLE:
+    pd=cpl_table_get_data_double(t,name);
+    for(i=0;i<nrow;i++) {
+      if(pd[i]==max) result=i;
+    }
+    break;
+  default:
+    sinfo_msg_error("Wrong column type");
+   cpl_error_set(cpl_func, CPL_ERROR_TYPE_MISMATCH);
+   return result;
+
+  }
+  return result;
+}
+
+
+
+/**
+ at name sinfo_table_get_index_of_val
+ at memo get raw index corresponding to input table column's value
+ at param t input table
+ at param name input table column name
+ at param val table column value
+ at param type CPL_TYPE of table column
+*/
+
+int
+sinfo_table_get_index_of_val(cpl_table* t,
+                             const char* name,
+                             double val,
+                             cpl_type type)
+{
+
+  int i=0;
+  int result=0;
+  int nrow=0;
+  int* pi=NULL;
+  float* pf=NULL;
+  double* pd=NULL;
+
+  if(t == NULL) {
+   cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT);
+   return result;
+  }
+
+  nrow=cpl_table_get_nrow(t);
+  switch(type) {
+
+  case CPL_TYPE_INT:
+    pi=cpl_table_get_data_int(t,name);
+    for(i=0;i<nrow;i++) {
+      if(pi[i]==(int)val) result=i;
+    }
+    break;
+  case CPL_TYPE_FLOAT:
+    pf=cpl_table_get_data_float(t,name);
+    for(i=0;i<nrow;i++) {
+      if(pf[i]==(float)val) result=i;
+    }
+    break;
+  case CPL_TYPE_DOUBLE:
+    pd=cpl_table_get_data_double(t,name);
+    for(i=0;i<nrow;i++) {
+      if(pd[i]==val) result=i;
+    }
+    break;
+  default:
+    sinfo_msg_error("Wrong column type");
+   cpl_error_set(cpl_func, CPL_ERROR_TYPE_MISMATCH);
+   return result;
+
+  }
+  return result;
+}
+
+/**
+ at name sinfo_table_column_interpolate
+ at memo interpolate table column
+ at param t     input table
+ at param name  input table column name
+ at param x     (double) raw value at which the column value need to be estimate
+return if success
+          table column value at x
+       else
+          -1
+*/
+
+double
+sinfo_table_column_interpolate(const cpl_table* t,
+                               const char* name,
+                               const double x)
+{
+
+  double val1=0;
+  double val2=0;
+  int x1=0;
+  int x2=0;
+  double m=0;
+  double y=0;
+  int status=0;
+  int nrow=0;
+  nrow=cpl_table_get_nrow(t);
+  if ((1<x) && (x<nrow-1)) {
+    x1=x-1;
+    x2=x+1;
+  } else if (x<2) {
+    x1=0;
+    x2=1;
+  } else {
+    x1=nrow-2;
+    x2=nrow-1;
+  }
+  check_nomsg(val1=cpl_table_get(t,name,x1,&status));
+  check_nomsg(val2=cpl_table_get(t,name,x2,&status));
+
+  m=(val2-val1)/(x2-x1);
+  y=val1+m*(x-x1);
+
+  return y;
+
+ cleanup:
+
+  return -1;
+
+
+}
+
+/**
+ at name sinfo_imagelist_select_range
+ at memo select imagelist planes corresponding to a given range
+ at param inp  input im agelist
+ at param full table specifying full wavelength range
+ at param good table specifying good wavelength range
+ at param tol wavelength tolerance
+*/
+static cpl_imagelist*
+sinfo_imagelist_select_range(const cpl_imagelist* inp,
+                                  const cpl_table* full,
+                                  const cpl_table* good,
+                                  const double tol)
+{
+  cpl_imagelist* out=NULL;
+  int osz=0;
+  int isz=0;
+  int ksz=0;
+  int k=0;
+  int i=0;
+  int status=0;
+
+  double wave_chk=0;
+  double wave_sel=0;
+
+  const cpl_image* img=NULL;
+
+
+  /* Get Object relevant information */
+  /* here one should scan the inp image constructing a wave range from it
+     and not from another table */
+  check_nomsg(osz=cpl_table_get_nrow(good));
+  check_nomsg(ksz=cpl_imagelist_get_size(inp));
+  check_nomsg(isz=cpl_table_get_nrow(good));
+  check_nomsg(out=cpl_imagelist_new());
+
+
+  for(k=0;k<ksz;k++) {
+    check_nomsg(img=cpl_imagelist_get_const(inp,k));
+    check_nomsg(wave_chk=cpl_table_get(full,"WAVE",k,&status));
+    if(i<isz) {
+      check_nomsg(wave_sel=cpl_table_get(good,"WAVE",i,&status));
+    }
+    // insert cubes with wavelengths with appropriate values only
+    if(fabs(wave_chk - wave_sel) < tol) {
+      check_nomsg(cpl_imagelist_set(out,cpl_image_duplicate(img),i));
+      i++;
+    }
+  }
+  if(i==0) {
+    sinfo_msg_error("No lines selected");
+    goto cleanup;
+  }
+  return out;
+
+ cleanup:
+
+  return NULL;
+
+}
+
+/**
+ at name sinfo_table_extract_finite
+ at memo extract finite values from two tables
+ at param in1 1st input table
+ at param in2 2nd input table
+ at param ou1 1st output table
+ at param ou2 2nd output table
+ at return if success 0, else -1
+*/
+static int
+sinfo_table_extract_finite(const cpl_table* in1,
+                           const cpl_table* in2,
+                                 cpl_table** ou1,
+                                 cpl_table** ou2)
+{
+
+  int size1=0;
+  int size2=0;
+  int i=0;
+  int ninv1=0;
+  int ninv2=0;
+  double* pout1=NULL;
+  double* pout2=NULL;
+
+  cknull(in1,"null input image");
+  cknull(in2,"null input image");
+  cknull_nomsg(*ou1=cpl_table_duplicate(in1));
+  cknull_nomsg(*ou2=cpl_table_duplicate(in2));
+
+  check_nomsg(size1=cpl_table_get_nrow(*ou1));
+  check_nomsg(size2=cpl_table_get_nrow(*ou2));
+
+  check_nomsg(pout1=cpl_table_get_data_double(*ou1,"VALUE"));
+  check_nomsg(pout2=cpl_table_get_data_double(*ou2,"VALUE"));
+  for(i=0;i<size1;i++) {
+    if (irplib_isnan(pout1[i])) {
+      check_nomsg(cpl_table_set_invalid(*ou1,"VALUE",i));
+      check_nomsg(cpl_table_set_invalid(*ou2,"VALUE",i));
+    }
+  }
+  ninv1=cpl_table_count_invalid(*ou1,"VALUE");
+  ninv2=cpl_table_count_invalid(*ou2,"VALUE");
+  if(ninv1==size1) {
+    goto cleanup;
+  }
+  if(ninv2==size2) {
+    goto cleanup;
+  }
+  check_nomsg(cpl_table_erase_invalid(*ou1));
+  check_nomsg(cpl_table_erase_invalid(*ou2));
+  return (size1-ninv1);
+
+ cleanup:
+  return 0;
+
+}
+
+/**
+ at name sinfo_image2table
+ at memo convert an image in a table
+ at param im input image
+ at return output table
+*/
+static cpl_table*
+sinfo_image2table(const cpl_image* im)
+{
+  cpl_table* out=NULL;
+  int sx=0;
+  int sy=0;
+  const double* pim=NULL;
+  double* pval=NULL;
+  int i=0;
+  int j=0;
+  int k=0;
+
+  cknull(im,"input image is NULL");
+
+  check_nomsg(sx=cpl_image_get_size_x(im));
+  check_nomsg(sy=cpl_image_get_size_y(im));
+  check_nomsg(pim=cpl_image_get_data_double_const(im));
+  check_nomsg(out=cpl_table_new(sx*sy));
+  check_nomsg(cpl_table_new_column(out,"VALUE",CPL_TYPE_DOUBLE));
+  check_nomsg(pval=cpl_table_get_data_double(out,"VALUE"));
+
+  for(j=0;j<sy;j++) {
+    for(i=0;i<sx;i++) {
+      /*
+      pval[k++]=pim[j*sx+i];
+      sinfo_msg("set tab %f",pim[j*sx+i]);
+      */
+      cpl_table_set_double(out,"VALUE",k++,pim[j*sx+i]);
+    }
+  }
+
+  return out;
+ cleanup:
+  sinfo_free_table(&out);
+  return NULL;
+
+}
+/**
+ at name sinfo_check_screw_values
+ at memo check for screw values at sky spectrum edges
+ at param int_obj  input object spectrum
+ at param int_sky  input sky object spectrum
+ at param grange   good wavelength range
+ at param wtol     wavelength tolerance
+*/
+int
+sinfo_check_screw_values(cpl_table** int_obj,
+                         cpl_table** int_sky,
+                         cpl_table* grange,
+                         const double wtol)
+{
+  // check for screwy values at ends of spectrum
+  cpl_table* xsky=NULL;
+  cpl_table* xobj=NULL;
+
+  double sky_min=0;
+  double sky_max=0;
+  double gsky_min=0;
+  double gsky_max=0;
+  double obj_min=0;
+  double obj_max=0;
+  double gobj_min=0;
+  double gobj_max=0;
+
+  cknull(*int_sky,"Null input sky spectrum");
+  cknull(*int_obj,"Null input obj spectrum");
+  cknull(grange,"Null input wavelength range");
+  //check_nomsg(cpl_table_save(*int_sky,NULL,NULL,
+  //                             "out_grange0.fits",CPL_IO_DEFAULT));
+  cknull_nomsg(xsky=sinfo_table_select_range(*int_sky,grange,wtol));
+  //check_nomsg(cpl_table_save(xsky,NULL,NULL,
+  //                             "out_grange1.fits",CPL_IO_DEFAULT));
+  check_nomsg(sky_min=cpl_table_get_column_min(xsky,"INT"));
+  check_nomsg(sky_max=cpl_table_get_column_max(xsky,"INT"));
+  //sinfo_msg("gskymax=%f gskymin=%f",sky_max,sky_min);
+
+  gsky_max = (sky_max>0) ? sky_max : 0;
+  gsky_min = (sky_min<0) ? sky_min : 0;
+  //gsky_pos = where(int_sky > 1.*gsky_max || int_sky < 1.*gsky_min,gskypos_i);
+  check_nomsg(cpl_table_select_all(*int_sky));
+  ck0_nomsg(sinfo_table_set_nan_out_min_max(int_sky,"INT",gsky_min,gsky_max));
+  //check_nomsg(cpl_table_save(*int_sky,NULL,NULL,
+  //                             "out_gsky_pos.fits",CPL_IO_DEFAULT));
+
+  sinfo_free_table(&xsky);
+  //sinfo_msg("gsky_min=%f gsky_max=%f",gsky_min,gsky_max);
+
+  cknull_nomsg(xobj=sinfo_table_select_range(*int_obj,grange,wtol));
+  check_nomsg(obj_min=cpl_table_get_column_min(xobj,"INT"));
+  check_nomsg(obj_max=cpl_table_get_column_max(xobj,"INT"));
+  //check_nomsg(cpl_table_save(xobj,NULL,NULL,"out_xobj.fits",CPL_IO_DEFAULT));
+  gobj_max = (obj_max>0) ? obj_max : 0;
+  gobj_min = (obj_min<0) ? obj_min : 0;
+  //gobj_pos=where(int_obj > 1.*gobj_max || int_obj < 1.*gobj_min,gobj_pos_i);
+  check_nomsg(cpl_table_select_all(*int_obj));
+  ck0_nomsg(sinfo_table_set_nan_out_min_max(int_obj,"INT",gobj_min,gobj_max));
+  //check_nomsg(cpl_table_save(*int_obj,NULL,NULL,
+  //              "out_gobj_pos.fits",CPL_IO_DEFAULT));
+  //sinfo_msg("gobj_min=%f gobj_max=%f",gobj_min,gobj_max);
+  sinfo_free_table(&xobj);
+
+  return 0;
+ cleanup:
+  sinfo_free_table(&xsky);
+  sinfo_free_table(&xobj);
+
+  return -1;
+
+
+}
+
+
+
+/**
+ at name sinfo_table_fill_column_over_range
+ at param inp input table
+ at param ref input table specifying the wavelength range
+ at param col input table column
+ at param tol input tolerance
+ at return pointer to a new allocated table corresponding to the selection
+*/
+
+static int
+sinfo_table_fill_column_over_range(cpl_table** inp,
+                                   const cpl_table* ref,
+                                   const char* col,
+                                   const double val,
+                                   const double tol)
+{
+
+  int i=0;
+  int k=0;
+  int nref=0;
+  int ninp=0;
+
+  double* pwin=NULL;
+  double* pcin=NULL;
+  const double* pwrf=NULL;
+
+  cknull(inp,"null input table");
+  cknull(ref,"null reference table");
+
+  check_nomsg(ninp=cpl_table_get_nrow(*inp));
+  check_nomsg(nref=cpl_table_get_nrow(ref));
+  check_nomsg(pwin=cpl_table_get_data_double(*inp,"WAVE"));
+  check_nomsg(pcin=cpl_table_get_data_double(*inp,col));
+  check_nomsg(pwrf=cpl_table_get_data_double_const(ref,"WAVE"));
+
+  k=0;
+  i=0;
+  /*
+  sinfo_msg("ninp=%d nref=%d",ninp,nref);
+  sinfo_msg("winp(0)=%f wref(0)=%f tol=%f diff=%f",
+            pwin[0],pwrf[0],tol,fabs(pwin[0]-pwrf[0]));
+  */
+  if(pwin[0]<=pwrf[0]) {
+    //sinfo_msg("case 1");
+    for(i=0;i<ninp;i++) {
+      if(k<nref) {
+    /*
+        sinfo_msg("case1: %f %f %f %f %d %d",
+                  fabs(pwin[i] - pwrf[k]),tol,pwin[i],pwrf[k],i,k);
+    */
+    if(fabs(pwin[i] - pwrf[k])< tol) {
+      pcin[i]=val;
+      k++;
+    }
+      }
+    }
+  } else {
+
+    //pwin[0]>pwrf[0]
+    //sinfo_msg("case 2");
+    for(k=0;k<nref;k++) {
+      if(i<ninp) {
+    /*
+        sinfo_msg("case2: %f %f %f %f %d %d",
+                  fabs(pwin[i] - pwrf[k]),tol,pwin[i],pwrf[k],i,k);
+    */
+    if(fabs(pwin[i] - pwrf[k])< tol) {
+      pcin[i]=val;
+      i++;
+    }
+      }
+    }
+  }
+
+  return 0;
+
+ cleanup:
+  return -1;
+
+}
+
+
+/**
+ at name sinfo_table_select_range
+ at param inp input table
+ at param ref input table specifying the wavelength range
+ at param tol input tolerance
+ at return pointer to a new allocated table corresponding to the selection
+*/
+
+static cpl_table*
+sinfo_table_select_range(cpl_table* inp, cpl_table* ref,const double tol)
+{
+
+  cpl_table* out=NULL;
+  int ninp=0;
+  int nref=0;
+  int nout=0;
+
+  int i=0;
+  int k=0;
+  double* pou;
+  double* prf;
+  double wmin=0;
+  double wmax=0;
+  cpl_table* tmp=NULL;
+  cknull(inp,"null input table");
+  cknull(ref,"null reference table");
+
+  check_nomsg(ninp=cpl_table_get_nrow(inp));
+  check_nomsg(nref=cpl_table_get_nrow(ref));
+  if(ninp != nref) {
+    //sinfo_msg_warning("ninp != nref");
+    check_nomsg(wmin=cpl_table_get_column_min(ref,"WAVE"));
+    check_nomsg(wmax=cpl_table_get_column_max(ref,"WAVE"));
+    //sinfo_msg_debug("wmin=%f wmax=%f",wmin,wmax);
+    cpl_table_select_all(inp);
+    check_nomsg(ninp=cpl_table_and_selected_double(inp,"WAVE",
+                                                   CPL_NOT_LESS_THAN,wmin));
+    check_nomsg(tmp=cpl_table_extract_selected(inp));
+    check_nomsg(ninp=cpl_table_and_selected_double(tmp,"WAVE",
+                                                   CPL_NOT_GREATER_THAN,wmax));
+    check_nomsg(out=cpl_table_extract_selected(tmp));
+    sinfo_free_table(&tmp);
+  } else {
+    check_nomsg(out=cpl_table_duplicate(inp));
+  }
+
+  check_nomsg(nout=cpl_table_get_nrow(out));
+  if(nout == 0) {
+    //sinfo_msg("nout=%d",nout);
+    goto cleanup;
+  }
+  tmp=cpl_table_duplicate(out);
+  sinfo_free_table(&out);
+  check_nomsg(pou=cpl_table_get_data_double(tmp,"WAVE"));
+  check_nomsg(prf=cpl_table_get_data_double(ref,"WAVE"));
+
+  check_nomsg(cpl_table_new_column(tmp,"FLAG",CPL_TYPE_INT));
+  check_nomsg(cpl_table_fill_column_window(tmp,"FLAG",0,nout,-1));
+
+  k=0;
+  i=0;
+
+  //sinfo_msg_debug("nout=%d nref=%d",nout,nref);
+  //sinfo_msg_debug("wout(0)=%f wref(0)=%f tol=%f diff=%f",
+  //          pou[0],prf[0],tol,fabs(pou[0]-prf[0]));
+
+  if(pou[0]<=prf[0]) {
+    //sinfo_msg_debug("case 1");
+    for(i=0;i<nout;i++) {
+      if(k<nref) {
+	if(fabs(pou[i] - prf[k])< tol) {
+	  check_nomsg(cpl_table_set_int(tmp,"FLAG",i,1));
+	  k++;
+	}
+      }
+    }
+  } else {
+
+    //pou[0]>prf[0]
+    //sinfo_msg_debug("case 2");
+    for(k=0;k<nref;k++) {
+      if(i<nout) {
+	/*
+        sinfo_msg("check: %f %f %f %f",
+                  fabs(pou[i] - prf[k]),tol,pou[i],prf[k]);
+	*/
+	if(fabs(pou[i] - prf[k])< tol) {
+	  check_nomsg(cpl_table_set_int(tmp,"FLAG",i,1));
+	  i++;
+	}
+      }
+    }
+  }
+  //check_nomsg(cpl_table_save(tmp,NULL,NULL,"out_pre0.fits",CPL_IO_DEFAULT));
+  check_nomsg(nout=cpl_table_and_selected_int(tmp,"FLAG",CPL_GREATER_THAN,0));
+  check_nomsg(out=cpl_table_extract_selected(tmp));
+  sinfo_free_table(&tmp);
+  check_nomsg(cpl_table_erase_column(out,"FLAG"));
+  if(nout==0) {
+    goto cleanup;
+  }
+  //check_nomsg(cpl_table_save(out,NULL,NULL,"out_post0.fits",CPL_IO_DEFAULT));
+  /* sinfo_msg("nout=%d",nout); */
+  return out;
+
+ cleanup:
+  sinfo_free_table(&tmp);
+  sinfo_free_table(&out);
+  return NULL;
+
+}
+
+/**
+ at name sinfo_interpolate_sky
+ at memo interpolate sky spectrum in case of wavelength shift obj-sky frame
+ at param inp      input table
+ at param lambdas  input table
+ at note TO BE IMPLEMENTED
+*/
+
+
+cpl_table*
+sinfo_interpolate_sky(const cpl_table* inp,const cpl_table* lambdas)
+{
+  //interpolate sky if necessary
+  cpl_table* new=NULL;
+  new = sinfo_interpolate(inp,lambdas,"WAVE","lsquadratic");;
+
+  return new;
+}
+
+
+/**
+ at name sinfo_interpolate
+ at memo interpolate spectrum in case of wavelength shift obj-sky frame
+ at param inp      input table
+ at param lambdas  input table
+ at param name     column name
+ at param method   interpolationg method
+ at note TO BE IMPLEMENTED
+*/
+static cpl_table*
+sinfo_interpolate(const cpl_table* inp,
+                  const cpl_table* lambdas,
+                  const char* name,
+                  const char* method)
+{
+  //TODO
+  cpl_table* out=NULL;
+
+  //To remove compilation warnings
+  cknull_nomsg(lambdas);
+  cknull_nomsg(name);
+  cknull_nomsg(method);
+
+  out=cpl_table_duplicate(inp);
+  return out;
+
+ cleanup:
+
+  return NULL;
+
+}
+
+
+
+/**
+ at name sinfo_gaussian_amp
+ at memo computes Gaussian amplitude
+ at param area  Gaussian area
+ at param sigma Gaussian sigma
+ at param x     Gaussian x position
+ at param x0    Gaussian centre
+ at param off   Gaussian background
+ at return Gaussian value
+*/
+
+
+static double
+sinfo_gaussian_amp(double area,double sigma,double x,double x0,double off)
+{
+  return area/sqrt(2*PI_NUMB*sigma*sigma)*
+         exp(-(x-x0)*(x-x0)/(2*sigma*sigma))+off;
+}
+
+
+/**
+ at name sinfo_gaussian_area
+ at memo computes Gaussian area
+ at param area  Gaussian area
+ at param sigma Gaussian sigma
+ at param x     Gaussian x position
+ at param x0    Gaussian centre
+ at param off   Gaussian background
+ at return Gaussian value
+*/
+
+
+static double
+sinfo_gaussian_area(double amp,double sigma,double x,double x0,double off)
+{
+  return sqrt(2*PI_NUMB*sigma*sigma)*exp((x-x0)*(x-x0)/(2*sigma*sigma))*
+         (amp-off);
+}
+
+
+/**
+ at name sinfo_table_smooth_column
+ at param t input/output(smoothed) table
+ at param c table column
+ at param r smoothing radii
+*/
+int
+sinfo_table_smooth_column(cpl_table** t, const char* c, const int r)
+{
+  int nrow=0;
+  int i=0;
+  int j=0;
+  double* pval=NULL;
+  double sum;
+  check_nomsg(nrow=cpl_table_get_nrow(*t));
+  check_nomsg(pval=cpl_table_get_data_double(*t,c));
+  for(i=r;i<nrow;i++) {
+    sum=0;
+    for(j=-r;j<=r;j++) {
+      sum+=pval[i+j];
+    }
+    pval[i]=sum/(2*r+1);
+  }
+  return 0;
+ cleanup:
+  return -1;
+}
+
+/**
+ at name sinfo_shift_sky
+ at memo shift a frame and sky spectrum in wavelength
+ at param sky_frm input/output(shifted) sky frame
+ at param int_sky input/output(shifted) sky table
+ at param zshift shift in pixels
+ at return void
+*/
+void
+sinfo_shift_sky(cpl_frame** sky_frm,
+                cpl_table** int_sky,
+                const double zshift)
+{
+
+  int xsz=0;
+  int ysz=0;
+  int zsz=0;
+  cpl_propertylist* plist=NULL;
+  cpl_imagelist* sky_cub=NULL;
+  cpl_imagelist* sky_shift=NULL;
+  cpl_table* int_sky_dup=NULL;
+
+  double min=0;
+  double max=0;
+
+ /* Get Object relevant information */
+  cknull_nomsg(plist=cpl_propertylist_load(
+                     cpl_frame_get_filename(*sky_frm),0));
+
+  check_nomsg(xsz=sinfo_pfits_get_naxis1(plist));
+  check_nomsg(ysz=sinfo_pfits_get_naxis2(plist));
+  check_nomsg(zsz=sinfo_pfits_get_naxis3(plist));
+  sinfo_free_propertylist(&plist);
+
+  cknull_nomsg(sky_cub=cpl_imagelist_load(cpl_frame_get_filename(*sky_frm),
+                                            CPL_TYPE_FLOAT,0));
+
+  check_nomsg(min=cpl_table_get_column_min(*int_sky,"INT"));
+  check_nomsg(max=cpl_table_get_column_max(*int_sky,"INT"));
+  int_sky_dup=cpl_table_duplicate(*int_sky);
+  sinfo_free_table(&(*int_sky));
+  /*
+  cknull_nomsg(*int_sky=sinfo_table_shift_column_int(int_sky_dup,
+                                                     "INT", zshift,&zrest));
+  check_nomsg(cpl_table_save(*int_sky, NULL, NULL,
+                             "out_sky_shift1.fits", CPL_IO_DEFAULT));
+  sinfo_free_table(&(*int_sky));
+
+  sinfo_msg("min=%f max=%f",min,max);
+  check_nomsg(cpl_table_save(int_sky_dup, NULL, NULL,
+                             "out_sky_pre2.fits", CPL_IO_DEFAULT));
+  cknull_nomsg(*int_sky=sinfo_table_shift_column_poly(int_sky_dup,
+                                                      "INT", zshift,2));
+  check_nomsg(cpl_table_save(*int_sky, NULL, NULL,
+                             "out_sky_shift2.fits", CPL_IO_DEFAULT));
+  */
+  //check_nomsg(cpl_table_save(int_sky_dup, NULL, NULL,
+  //                             "out_sky_pre2.fits", CPL_IO_DEFAULT));
+  check_nomsg(*int_sky=sinfo_table_shift_simple(int_sky_dup,"INT",zshift));
+  /*
+  sinfo_free_table(&(*int_sky));
+  cknull_nomsg(*int_sky=sinfo_table_shift_column_spline3(int_sky_dup,
+                                                         "INT", zshift));
+  check_nomsg(cpl_table_save(*int_sky, NULL, NULL,
+                             "out_sky_shift3.fits", CPL_IO_DEFAULT));
+  */
+  sinfo_free_table(&int_sky_dup);
+  /*
+  check_nomsg(cpl_table_select_all(*int_sky));
+  check_nomsg(n=cpl_table_and_selected_double(*int_sky,"INT",
+                                              CPL_LESS_THAN,min));
+  ck0_nomsg(sinfo_table_set_column_invalid(int_sky,"INT"));
+  sinfo_msg("n=%d",n);
+  check_nomsg(cpl_table_select_all(*int_sky));
+  check_nomsg(n=cpl_table_and_selected_double(*int_sky,"INT",
+                CPL_GREATER_THAN,max));
+  sinfo_msg("n=%d",n);
+  ck0_nomsg(sinfo_table_set_column_invalid(int_sky,"INT"));
+  check_nomsg(cpl_table_select_all(*int_sky));
+  */
+  //check_nomsg(cpl_table_save(*int_sky, NULL, NULL,
+  //                           "out_sky_shift3.fits", CPL_IO_DEFAULT));
+
+
+
+  check_nomsg(sky_shift=sinfo_cube_zshift_simple(sky_cub,(float)zshift));
+
+  //check_nomsg(sky_shift=sinfo_cube_zshift(sky_cub,zshift,&zrest));
+  //check_nomsg(cpl_imagelist_save(sky_shift,"out_sky1.fits",
+  //                 CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT));
+
+  sinfo_free_imagelist(&sky_shift);
+  //sinfo_free_imagelist(&sky_shift);
+  //sinfo_msg("zrest=%f",zrest);
+
+  //check_nomsg(sky_shift=sinfo_cube_zshift_poly(sky_cub,zshift,2));
+  //check_nomsg(cpl_imagelist_save(sky_shift,"out_sky2.fits",
+  //                               CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT));
+  //sinfo_free_imagelist(&sky_shift);
+
+  //check_nomsg(sky_shift=sinfo_cube_zshift_spline3(sky_cub,zshift));
+  //check_nomsg(cpl_imagelist_save(sky_shift,"out_sky3.fits",
+  //                               CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT));
+  //sinfo_free_imagelist(&sky_shift);
+  sinfo_free_imagelist(&sky_cub);
+
+  return;
+
+ cleanup:
+  sinfo_free_table(&int_sky_dup);
+  sinfo_free_propertylist(&plist);
+  sinfo_free_imagelist(&sky_shift);
+  sinfo_free_imagelist(&sky_cub);
+  return;
+}
+
+
+/**
+ at name sinfo_convolve_kernel
+ at memo convolve a table with a box of a given radii
+ at param t input table
+ at param rad kernel's radii
+*/
+static int
+sinfo_convolve_kernel(cpl_table** t, const int rad)
+{
+  int i=0;
+  int j=0;
+  int np=0;
+  double val=0;
+  double* pidata=NULL;
+  double* pcdata=NULL;
+  double dw=0;
+  //double dr=0;
+  double ws=0;
+  double we=0;
+  cknull(*t,"null input table");
+  check_nomsg(cpl_table_new_column(*t,"CNV",CPL_TYPE_DOUBLE));
+  check_nomsg(pidata=cpl_table_get_data_double(*t,"INT"));
+  check_nomsg(pcdata=cpl_table_get_data_double(*t,"CNV"));
+  check_nomsg(ws=cpl_table_get_column_min(*t,"WAVE"));
+  check_nomsg(we=cpl_table_get_column_max(*t,"WAVE"));
+  check_nomsg(np=cpl_table_get_nrow(*t));
+  dw=(we-ws)/(np-1);
+  //dr=(we-ws)/(rad-1);
+  /* set to 0 edges */
+  for(i=0;i<rad;i++) {
+    pcdata[i]=0.;
+  }
+  for(i=np-rad;i<np;i++) {
+    pcdata[i]=0.;
+  }
+  for(i=rad;i<np-rad;i++) {
+    val=0;
+    for(j=-rad;j<rad;j++) {
+      val+=pidata[i+j];
+    }
+    /*val*=dw; */
+    check_nomsg(cpl_table_set_double(*t,"CNV",i,val));
+  }
+  return 0;
+
+ cleanup:
+  return -1;
+
+}
+
+
+
+/**
+ at name sinfo_convolve_kernel
+ at memo convolve a table with a box of a given radii
+ at param t input table
+ at param rad kernel's radii
+*/
+
+int
+sinfo_convolve_kernel2(cpl_table** t, const int rad)
+{
+  int i=0;
+  int j=0;
+  int np=0;
+  double val=0;
+  double* pidata=NULL;
+  double* pcdata=NULL;
+  double dw=0;
+  double dr=0;
+  double ws=0;
+  double we=0;
+  cknull(*t,"null input table");
+  check_nomsg(cpl_table_new_column(*t,"CNV",CPL_TYPE_DOUBLE));
+  check_nomsg(pidata=cpl_table_get_data_double(*t,"INT"));
+  check_nomsg(pcdata=cpl_table_get_data_double(*t,"CNV"));
+  check_nomsg(ws=cpl_table_get_column_min(*t,"WAVE"));
+  check_nomsg(we=cpl_table_get_column_max(*t,"WAVE"));
+  check_nomsg(np=cpl_table_get_nrow(*t));
+  dw=(we-ws)/(np-1);
+  dr=(we-ws)/(rad-1);
+  /* set to 0 edges */
+  for(i=0;i<rad;i++) {
+    pcdata[i]=0.;
+  }
+  for(i=np-rad;i<np;i++) {
+    pcdata[i]=0.;
+  }
+  for(i=0;i<np-rad;i++) {
+    val=0;
+    for(j=0;j<rad;j++) {
+      val+=pidata[i+j];
+    }
+    /*val*=dw; */
+    check_nomsg(cpl_table_set_double(*t,"CNV",i,val));
+  }
+  return 0;
+
+ cleanup:
+  return -1;
+
+}
+
+
+
+/**
+ at name sinfo_convolve_exp
+ at memo convolve a table with an exponential of a given radii and fwhm
+ at param t input table
+ at param rad Gaussian radii
+ at param fwhm Gaussian radii
+*/
+int
+sinfo_convolve_exp(cpl_table** t, const int rad, const double fwhm)
+{
+  int i=0;
+  int j=0;
+  int np=0;
+  double ln2=0.693147180560;
+  double k=ln2/fwhm;
+  double val=0;
+  double* pidata=NULL;
+  double* pcdata=NULL;
+  double dw=0;
+  //double dr=0;
+  double ws=0;
+  double we=0;
+  cknull(*t,"null input table");
+  check_nomsg(cpl_table_new_column(*t,"CNV",CPL_TYPE_DOUBLE));
+  check_nomsg(pidata=cpl_table_get_data_double(*t,"INT"));
+  check_nomsg(pcdata=cpl_table_get_data_double(*t,"CNV"));
+  check_nomsg(ws=cpl_table_get_column_min(*t,"WAVE"));
+  check_nomsg(we=cpl_table_get_column_max(*t,"WAVE"));
+  check_nomsg(np=cpl_table_get_nrow(*t));
+  dw=(we-ws)/(np-1);
+  //dr=(we-ws)/(rad-1);
+  /* set to 0 edges */
+  for(i=0;i<rad;i++) {
+    pcdata[i]=0.;
+  }
+  for(i=np-rad;i<np;i++) {
+    pcdata[i]=0.;
+  }
+  for(i=rad;i<np-rad;i++) {
+    val=0;
+    for(j=-rad;j<rad;j++) {
+      val+=pidata[i+j]*k*pow(2.0,-2.0*fabs(i-rad)/fwhm);
+    }
+    /*val*=dw; */
+    check_nomsg(cpl_table_set_double(*t,"CNV",i,val));
+  }
+  return 0;
+
+ cleanup:
+  return -1;
+
+}
+
+
+/**
+ at name sinfo_convolve_gauss
+ at memo convolve a table with an Gaussian of a given radii and fwhm
+ at param t input table
+ at param rad Gaussian radii
+ at param fwhm Gaussian radii
+*/
+
+int
+sinfo_convolve_gauss(cpl_table** t, const int rad, const double fwhm)
+{
+  int i=0;
+  int j=0;
+  int np=0;
+  double val=0;
+  double sigma=fwhm/2.3548;
+  double sigma2=sigma*sigma;
+  double* pidata=NULL;
+  double* pcdata=NULL;
+  double dw=0;
+  double dr=0;
+  double ws=0;
+  double we=0;
+  double tx=0;
+
+  cknull(*t,"null input table");
+  check_nomsg(cpl_table_new_column(*t,"CNV",CPL_TYPE_DOUBLE));
+  check_nomsg(pidata=cpl_table_get_data_double(*t,"INT"));
+  check_nomsg(pcdata=cpl_table_get_data_double(*t,"CNV"));
+  check_nomsg(ws=cpl_table_get_column_min(*t,"WAVE"));
+  check_nomsg(we=cpl_table_get_column_max(*t,"WAVE"));
+  check_nomsg(np=cpl_table_get_nrow(*t));
+  dw=(we-ws)/(np-1);
+  dr=(we-ws)/(rad-1);
+  /* set to 0 edges */
+  for(i=0;i<rad;i++) {
+    pcdata[i]=0.;
+  }
+  for(i=np-rad;i<np;i++) {
+    pcdata[i]=0.;
+  }
+  for(i=rad;i<np-rad;i++) {
+    val=0;
+    for(j=-rad;j<rad;j++) {
+      tx=i-rad;
+      val+=pidata[i+j]*exp(-tx*tx/2.0/sigma2)/(sigma*sqrt(2.0*PI_NUMB));
+    }
+    /*val*=dw; */
+    check_nomsg(cpl_table_set_double(*t,"CNV",i,val));
+  }
+  return 0;
+
+ cleanup:
+  return -1;
+
+}
+
+
+
+/**
+ at name sinfo_scales_obj_sky_cubes
+ at param obj_cub input object cube
+ at param sky_cub input sky cube
+ at param bkg     input background
+ at param rscale  scale ratio to be applied to sky frame before subtraction \
+               from object
+ at param obj_cor corrected object
+ at return if success 0, else -1
+*/
+
+static int
+sinfo_scales_obj_sky_cubes(cpl_imagelist* obj_cub,
+                            cpl_imagelist* sky_cub,
+                            cpl_table* bkg,
+                            cpl_table* rscale,
+                            cpl_imagelist** obj_cor)
+{
+
+
+  int i=0;
+  int j=0;
+  int k=0;
+  int xsz=0;
+  int ysz=0;
+  int zsz=0;
+
+  double* podata=NULL;
+  double* psdata=NULL;
+  double* pbdata=NULL;
+  double* pcdata=NULL;
+  double* pscale=NULL;
+
+
+  cpl_image* imgo=NULL;
+  cpl_image* imgs=NULL;
+  cpl_image* imgc=NULL;
+
+
+  check_nomsg(imgo=cpl_imagelist_get(obj_cub,0));
+  check_nomsg(xsz=cpl_image_get_size_x(imgo));
+  check_nomsg(ysz=cpl_image_get_size_y(imgo));
+  check_nomsg(zsz=cpl_imagelist_get_size(obj_cub));
+
+  check_nomsg(*obj_cor=cpl_imagelist_duplicate(obj_cub));
+
+  for(k=0;k<zsz;k++) {
+    check_nomsg(imgo=cpl_imagelist_get(obj_cub,k));
+    check_nomsg(imgc=cpl_imagelist_get(*obj_cor,k));
+    check_nomsg(imgs=cpl_imagelist_get(sky_cub,k));
+
+    check_nomsg(podata=cpl_image_get_data_double(imgo));
+    check_nomsg(pcdata=cpl_image_get_data_double(imgc));
+    check_nomsg(psdata=cpl_image_get_data_double(imgs));
+    check_nomsg(pbdata=cpl_table_get_data_double(bkg,"INT2"));
+    check_nomsg(pscale=cpl_table_get_data_double(rscale,"RATIO"));
+
+    for (j=0;j<ysz; j++) {
+      for (i=0;i<xsz; i++) {
+        if(!irplib_isnan(podata[i+j*xsz]) &&
+           !irplib_isnan(psdata[i+j*xsz]) &&
+           !irplib_isnan(pbdata[k]) &&
+           !irplib_isnan(pscale[k])) {
+    pcdata[i+j*xsz] = podata[i+j*xsz]-
+                          (psdata[i+j*xsz]-pbdata[k])*pscale[k];
+    }
+      }
+    }
+  }
+
+
+  return 0;
+ cleanup:
+
+  return -1;
+}
+
+
+/**
+ at name sinfo_fitbkg
+ at memo Black Body Thermal emission
+ at param x evaluation points
+ at param a function parameters
+ at param result function value
+
+ at doc This function is a Black Body profile
+   c=14387.7
+   y(x,a)=a[0]+a[1]*x^(-5)/(exp{c/(x*a[2])}-1)=a[0]+a[1]*fac(x,a)
+
+   where
+   fac(x,a)=x^(-5)/(exp{c/(x*a[2])}-1)
+
+  */
+
+static int
+sinfo_fitbkg(const double x[],
+             const double a[],
+             double *result)
+{
+
+
+  double fac  = sinfo_fac(x[0],a[2]);
+  /*
+  int n=sizeof(x)/sizeof(double);
+  double fmin = sinfo_fac(x[0],a[2]);
+  double fmax = sinfo_fac(x[n-1],a[2]);
+  sinfo_msg("n=%d",n);
+  if(fmax < 0) sinfo_msg("fmax=%f",fmax);
+  */
+  //*result = a[0]+a[1]*fac/sinfo_scale_fct;
+  *result = a[0]+a[1]*fac;
+
+  return 0;
+}
+
+/**
+ at name sinfo_fitbkg_derivative
+ at memo Black Body Thermal emission derivative
+ at param x evaluation points
+ at param a function parameters
+ at param result derivative value
+
+ at doc This function is a Black Body profile
+
+   c=14387.7
+   y(x,a)=a[0]+a[1]*x^(-5)/(exp{c/(x*a[2])}-1)/fct=a[0]+a[1]*fac(x,a)/fct
+
+   where
+   fac(x,a)=x^(-5)/(exp{c/(x*a[2])}-1)
+
+   dyda[0]=1
+   dyda[1]=x^(-5)/(exp{c/(x*a[2])}-1)=fac/fct
+   dyda[2]=a[1]*x^(-5)*(exp{c/(x*a[2])}-1)^(-2)*c/(x*a[2]^2)
+          =a[1]*fac^(2)*x^(5)*c/(x*a[2])^2
+          =a[1]*fac^(2)*x^4*c/a[2]^2
+
+  */
+
+static int
+sinfo_fitbkg_derivative(const double x[],
+                        const double a[],
+                  double d[])
+{
+  double c=14387.7;
+  /*
+  int n=sizeof(x)/sizeof(double);
+  double fmin = sinfo_fac(x[0],a[2]);
+  double fmax = sinfo_fac(x[n],a[2]);
+  */
+  double fac  = sinfo_fac(x[0],a[2]);
+  double f2=0;
+  //double f1=0;
+  double da=0.001;
+  //f1=a[0]+a[1]*fac;
+  //f2=f1+da*a[0];
+  //f2=a[0]+(a[1]+da*a[1])*fac;
+  f2=a[0]+a[1]*sinfo_fac(x[0],a[2]+da*a[2]);
+  d[0]=1.;
+  d[1]=fac;
+  d[2]=a[1]*fac*fac*x[0]*x[0]*x[0]*x[0]*c/(a[2]*a[2])*exp(c/(x[0]*a[2]));
+  //sinfo_msg("d0=%g d1=%g d2=%g",d[0]*a[0]/f,d[1]*a[1]/f,d[2]*a[2]/f);
+  //sinfo_msg("comp d1=%g",d[2]);
+  //sinfo_msg("real d1=%g",(f2-f1)/(da*a[2]));
+
+  return 0;
+}
+
+
+
+/**
+ at name sinfo_fac
+ at memo Black Body Thermal emission
+ at param x evaluation points
+ at param a function parameters
+ at return result function value
+
+ at doc This function is a Black Body profile
+   c=14387.7
+   fac(x,a)=x^(-5)/(exp{c/(x*a[2])}-1)
+
+  */
+
+static double
+sinfo_fac(const double x, const double t)
+{
+
+  double c=14387.7;
+
+  //return pow(x,-5.)/(exp(c/(x*fabs(t)))-1.)/sinfo_scale_fct;
+  return pow(x,-5.)/(exp(c/(x*fabs(t)))-1.);
+}
+
+/**
+ at name sinfo_table_threshold
+ at param t input/output(thresholded) table
+ at param column input table's column
+ at param low_cut low cut threshold
+ at param hig_cut hight cut threshold
+ at param low_ass value to assign to raws < low cut threshold
+ at param hig_ass value to assign to raws > low cut threshold
+*/
+static int
+sinfo_table_threshold(cpl_table** t,
+                      const char* column,
+                      const double low_cut,
+                      const double hig_cut,
+                      const double low_ass,
+                      const double hig_ass)
+{
+
+  int nrow=0;
+  int i=0;
+  double* pdata=NULL;
+  cknull(*t,"null input table!");
+
+  check_nomsg(nrow=cpl_table_get_nrow(*t));
+  check_nomsg(pdata=cpl_table_get_data_double(*t,column));
+
+  for(i=0;i<nrow;i++) {
+
+    if(pdata[i]<low_cut) {
+      pdata[i]=low_ass;
+    }
+    if (pdata[i] >= hig_cut) {
+      pdata[i]=hig_ass;
+    }
+
+  }
+
+  return 0;
+
+ cleanup:
+
+  return -1;
+}
+
+/**
+ at name sinfo_table_set_column_invalid
+ at param t   input/output table
+ at param col column to check
+
+
+static int
+sinfo_table_set_column_invalid(cpl_table** t,const char* col)
+{
+  int nrow=0;
+  int i=0;
+  cknull(*t,"input table is NULL");
+  check_nomsg(nrow=cpl_table_get_nrow(*t));
+  for(i=0;i<nrow;i++) {
+    if( cpl_table_is_selected(*t,i) ) {
+      cpl_table_set_invalid(*t,col,i);
+    }
+  }
+  return 0;
+ cleanup:
+  return -1;
+
+}
+
+*/
+
+
+
+static int
+sinfo_table_set(cpl_table** inp,
+                const cpl_table* ref,
+                const double val,
+                const double tol)
+{
+
+  int ninp=0;
+  int nref=0;
+  double* piw=NULL;
+  const double* prw=NULL;
+  double* pir=NULL;
+  int i=0;
+  int k=0;
+  cknull(*inp,"NULL input table");
+  cknull(ref,"NULL reference table");
+
+  check_nomsg(ninp=cpl_table_get_nrow(*inp));
+  check_nomsg(nref=cpl_table_get_nrow(ref));
+
+  check_nomsg(prw=cpl_table_get_data_double_const(ref,"WAVE"));
+  check_nomsg(piw=cpl_table_get_data_double(*inp,"WAVE"));
+  check_nomsg(pir=cpl_table_get_data_double(*inp,"RATIO"));
+
+
+  for(i=0;i<ninp;i++) {
+    /*sinfo_msg("check =%g thresh=%g",fabs(piw[i]-prw[k]),tol); */
+    if(fabs(piw[i]-prw[k]) < tol) {
+      check_nomsg(cpl_table_set_double(*inp,"RATIO",i,val));
+      k++;
+    }
+  }
+  return 0;
+
+ cleanup:
+
+  return -1;
+
+}
+
+
+
+static cpl_table*
+sinfo_table_shift_simple(cpl_table* inp,
+                         const char* col,
+                         const double shift)
+{
+
+  int nrow=0;
+  cpl_table* out=NULL;
+  int is=(int)shift;
+  double ds=shift-is;
+  double* pi=NULL;
+  double* po=NULL;
+  double m=0;
+  int i=0;
+  cknull(inp,"null input table");
+
+  check_nomsg(nrow=cpl_table_get_nrow(inp));
+  check_nomsg(out=cpl_table_duplicate(inp));
+  check_nomsg(cpl_table_fill_column_window(out,col,0,nrow,0));
+  check_nomsg(pi=cpl_table_get_data_double(inp,col));
+  check_nomsg(po=cpl_table_get_data_double(out,col));
+
+
+  for(i=0;i<nrow;i++) {
+    if((i+is)>0 && (i+is+1) < nrow) {
+      m=pi[i+is+1]-pi[i+is];
+      po[i]=pi[i+is]+m*ds;
+    }
+  }
+  return out;
+  cleanup:
+  sinfo_free_table(&out);
+  return NULL;
+
+}
+
+
+
+
+static cpl_imagelist*
+sinfo_cube_zshift_simple(cpl_imagelist* inp,
+                        const float shift)
+{
+
+  int nx=0;
+  int ny=0;
+  int nz=0;
+
+  int i=0;
+  int j=0;
+  int k=0;
+  int ks=(int)shift;
+
+  float ds=shift-ks;
+  float* pu=NULL;
+  float* pl=NULL;
+  float* po=NULL;
+
+  float  int2=0;
+  float  int1=0;
+  float m=0;
+
+  cpl_imagelist* out=NULL;
+  cpl_image* imgu=NULL;
+  cpl_image* imgl=NULL;
+  cpl_image* imgo=NULL;
+
+
+  cknull(inp,"null input cube");
+
+  check_nomsg(nz=cpl_imagelist_get_size(inp));
+  check_nomsg(out=cpl_imagelist_duplicate(inp));
+  check_nomsg(imgo=cpl_imagelist_get(out,0));
+  check_nomsg(nx=cpl_image_get_size_x(imgo));
+  check_nomsg(ny=cpl_image_get_size_y(imgo));
+
+  for(k=0;k<nz;k++) {
+    if((k+ks)>0 && (k+ks+1) < nz) {
+
+      check_nomsg(imgu=cpl_imagelist_get(inp,k+ks+1));
+      check_nomsg(imgl=cpl_imagelist_get(inp,k+ks));
+      check_nomsg(imgo=cpl_imagelist_get(out,k));
+
+      check_nomsg(pu=cpl_image_get_data_float(imgu));
+      check_nomsg(pl=cpl_image_get_data_float(imgl));
+      check_nomsg(po=cpl_image_get_data_float(imgo));
+
+
+      for(j=0;j<ny;j++) {
+    for(i=0;i<nx;i++) {
+          int2=pu[nx*j+i];
+          int1=pl[nx*j+i];
+      m=int2-int1;
+      po[nx*j+i]=int1+m*ds;
+    }
+      }
+    }
+
+
+  }
+  return out;
+  cleanup:
+  sinfo_free_imagelist(&out);
+  return NULL;
+
+}
+
+
+/**
+ @name sinfo_get_line_ratio
+ @brief compute line ratio obj_residual/sky
+
+ @param obj input object table
+ @param sky input sky table
+ @param method input method
+ @param r output ratio
+ @return if success 0, else -1
+*/
+static int
+sinfo_get_line_ratio(cpl_table* obj_lin,
+                      cpl_table* obj_cnt,
+                      cpl_table* sky_lin,
+                      cpl_table* sky_cnt,
+                      const int method,
+                      double* r)
+{
+
+  int nobj;
+  int nsky;
+  int i=0;
+
+  cpl_table* obj_dif=NULL;
+  cpl_table* sky_dif=NULL;
+
+  double* poi=NULL;
+  double* psi=NULL;
+  double* pvd=NULL;
+  double* pvn=NULL;
+  double* pvr=NULL;
+
+  cpl_vector* num=NULL;
+  cpl_vector* den=NULL;
+  cpl_vector* rat=NULL;
+  cpl_vector* wav=NULL;
+  double mnum=0;
+  double mden=0;
+  double tnum=0;
+  double tden=0;
+  cpl_size pows[2];
+  cpl_polynomial* cfit=NULL;
+  double mse=0;
+
+  cknull(obj_lin,"null obj line table");
+  cknull(sky_lin,"null sky line table");
+
+  cknull(obj_cnt,"null obj cont table");
+  cknull(sky_cnt,"null sky cont table");
+
+
+  cknull_nomsg(obj_dif=sinfo_table_subtract_continuum(obj_lin,obj_cnt));
+  cknull_nomsg(sky_dif=sinfo_table_subtract_continuum(sky_lin,sky_cnt));
+
+  check_nomsg(nobj=cpl_table_get_nrow(obj_dif));
+  check_nomsg(nsky=cpl_table_get_nrow(sky_dif));
+
+
+
+  if(nobj != nsky) {
+    sinfo_msg_error("obj and sky table must have the same no of rows!");
+    sinfo_msg_error("nobj=%d nsky=%d",nobj,nsky);
+    goto cleanup;
+  }
+  //sinfo_msg("Object sky residuals/Sky lines ratio determination method=%d",
+  //          method);
+  if(method == 0) {
+    ck0_nomsg(sinfo_get_line_ratio_amoeba(obj_dif,sky_dif,r));
+    sinfo_free_table(&obj_dif);
+    sinfo_free_table(&sky_dif);
+   return 0;
+  }
+
+
+  check_nomsg(poi=cpl_table_get_data_double(obj_dif,"INT"));
+  check_nomsg(psi=cpl_table_get_data_double(sky_dif,"INT"));
+
+  check_nomsg(num=cpl_vector_new(nobj));
+  check_nomsg(den=cpl_vector_new(nobj));
+  check_nomsg(rat=cpl_vector_new(nobj));
+  check_nomsg(cpl_vector_fill(num,0));
+  check_nomsg(cpl_vector_fill(den,0));
+  check_nomsg(cpl_vector_fill(rat,0));
+  check_nomsg(pvd=cpl_vector_get_data(den));
+  check_nomsg(pvn=cpl_vector_get_data(num));
+  check_nomsg(pvr=cpl_vector_get_data(rat));
+
+  for(i=0;i<nobj;i++) {
+    if(!irplib_isnan(psi[i]) &&
+       !irplib_isnan(poi[i]) &&
+       !irplib_isinf(psi[i]) &&
+       !irplib_isinf(poi[i]) ) {
+      pvn[i]=psi[i]*poi[i];
+      pvd[i]=psi[i]*psi[i];
+      if(psi[i] != 0) {
+         pvr[i]=poi[i]/psi[i];
+      }
+    }
+  }
+  sinfo_free_table(&sky_dif);
+
+  check_nomsg(mnum=cpl_vector_get_median_const(num));
+  check_nomsg(mden=cpl_vector_get_median_const(den));
+  check_nomsg(tnum=cpl_vector_get_mean(num)*nobj);
+  check_nomsg(tden=cpl_vector_get_mean(den)*nobj);
+
+  //sinfo_msg("mden=%g tden=%g",mden,tden);
+  //sinfo_msg("mnum=%g tnum=%g",mnum,tnum);
+  sinfo_free_my_vector(&num);
+  sinfo_free_my_vector(&den);
+  if(method == 1) {
+    *r=tnum/tden;
+  } else if (method == 2) {
+    *r=mnum/mden;
+  } else if (method == 3) {
+    *r=cpl_vector_get_median_const(rat);
+  } else if (method == 4) {
+    *r=cpl_vector_get_mean(rat);
+  } else if (method == 5) {
+
+    check_nomsg(wav=cpl_vector_wrap(nobj,
+                    cpl_table_get_data_double(obj_dif,"WAVE")));
+    check_nomsg(cfit=sinfo_polynomial_fit_1d_create(wav,rat,0,&mse));
+    sinfo_unwrap_vector(&wav);
+    pows[0]=0;
+    pows[1]=0;
+    check_nomsg(*r=cpl_polynomial_get_coeff(cfit,pows));
+    sinfo_free_polynomial(&cfit);
+
+  }
+
+  sinfo_free_table(&obj_dif);
+  sinfo_free_my_vector(&rat);
+  return 0;
+ cleanup:
+  sinfo_free_table(&obj_dif);
+  sinfo_free_table(&sky_dif);
+  sinfo_free_my_vector(&num);
+  sinfo_free_my_vector(&den);
+  sinfo_free_my_vector(&rat);
+  sinfo_unwrap_vector(&wav);
+
+  return -1;
+}
+
+
+
+
+/**
+ @name sinfo_get_line_ratio_amoeba
+ @brief compute line ratio obj_residual/sky
+
+ @param obj input object table
+ @param sky input sky table
+ @param r output ratio
+ @return if success 0, else -1
+*/
+static int
+sinfo_get_line_ratio_amoeba(cpl_table* obj,
+                            cpl_table* sky,
+                            double* r)
+{
+
+
+  int i=0;
+  const int MP=2;
+  const int NP=1;
+  double y[MP];
+  double p0[NP];
+  double** ap=NULL;
+  int nfunc=0;
+  int np=0;
+  check_nomsg(np=cpl_table_get_nrow(obj));
+  check_nomsg(sa_ox=cpl_vector_wrap(np,cpl_table_get_data_double(obj,"WAVE")));
+  check_nomsg(sa_oy=cpl_vector_wrap(np,cpl_table_get_data_double(obj,"INT")));
+  check_nomsg(sa_sy=cpl_vector_wrap(np,cpl_table_get_data_double(sky,"INT")));
+  // Amoeba part
+
+
+  ap=(double**) cpl_calloc(MP,sizeof(double*));
+  for(i=0;i<MP;i++) {
+    ap[i]=cpl_calloc(NP,sizeof(double));
+  }
+
+  ap[0][0]=-1.;
+  ap[1][0]=+1.;
+
+  //sinfo_msg("Before amoeba fit");
+  //sinfo_msg("ap[0][0]=%g ap[0][1]=%g",ap[0][0],ap[1][0]);
+  for(i=0;i<MP;i++) {
+    p0[0]=ap[i][0];
+    y[i]=sinfo_fit_sky(p0);
+  }
+
+
+  check_nomsg(sinfo_fit_amoeba(ap,y,NP,AMOEBA_FTOL,sinfo_fit_sky,&nfunc));
+
+  sinfo_msg("After amoeba fit");
+  sinfo_msg("ap[0][0]=%g ap[0][1]=%g",ap[0][0],ap[1][0]);
+
+  *r=ap[0][0];
+
+  sinfo_unwrap_vector(&sa_ox);
+  sinfo_unwrap_vector(&sa_oy);
+  sinfo_unwrap_vector(&sa_sy);
+  sinfo_new_destroy_2Ddoublearray(&ap,MP);
+
+
+  return 0;
+
+ cleanup:
+  sinfo_unwrap_vector(&sa_ox);
+  sinfo_unwrap_vector(&sa_oy);
+  sinfo_unwrap_vector(&sa_sy);
+  sinfo_new_destroy_2Ddoublearray(&ap,MP);
+
+  return -1;
+
+}
+
+
+/*-------------------------------------------------------------------------*/
+/**
+  @name        sinfo_fit_sky
+  @memo        Computes rms of difference INT(sky)-thermal_background
+
+  @param sa      pointer to sinfo_amoeba structure
+  @param p           input fit parameters
+  Returns rms= stdev[obj_line-obj_cont-sky*p]
+ */
+/*--------------------------------------------------------------------------*/
+
+static double
+sinfo_fit_sky(double p[])
+
+{
+  double* ps=NULL;
+  double* po=NULL;
+  double* pv=NULL;
+  cpl_vector* vtmp=NULL;
+  int i=0;
+  int np=0;
+  cpl_size pows[2];
+  double mse=0;
+  double cont=0;
+  cpl_polynomial* pfit=NULL;
+
+  double rms=0;
+
+
+  //fit residual obj continuum and subtract it
+  check_nomsg(pfit=sinfo_polynomial_fit_1d_create(sa_ox,sa_oy,0,&mse));
+  pows[0]=0;
+  pows[1]=0;
+  check_nomsg(cont=cpl_polynomial_get_coeff(pfit,pows));
+  check_nomsg(sinfo_free_polynomial(&pfit));
+  check_nomsg(cpl_vector_subtract_scalar(sa_oy,cont));
+
+
+  //fit residual sky continuum and subtract it
+  check_nomsg(pfit=sinfo_polynomial_fit_1d_create(sa_ox,sa_sy,0,&mse));
+  pows[0]=0;
+  pows[1]=0;
+  check_nomsg(cont=cpl_polynomial_get_coeff(pfit,pows));
+  check_nomsg(sinfo_free_polynomial(&pfit));
+  check_nomsg(cpl_vector_subtract_scalar(sa_sy,cont));
+
+  //computes diff=(obj-conto)-(sky-contsky)*p[0]
+  check_nomsg(po= cpl_vector_get_data(sa_oy));
+  check_nomsg(ps= cpl_vector_get_data(sa_sy));
+
+  check_nomsg(np=cpl_vector_get_size(sa_oy));
+  check_nomsg(vtmp=cpl_vector_new(np));
+  check_nomsg(pv= cpl_vector_get_data(vtmp));
+
+
+  for(i=0;i<np;i++) {
+    pv[i]=po[i]-ps[i]*p[0];
+  }
+  //computes rms diff
+  check_nomsg(rms=cpl_vector_get_stdev(vtmp));
+  sinfo_free_my_vector(&vtmp);
+  return rms;
+ cleanup:
+  sinfo_free_my_vector(&vtmp);
+  return -1;
+
+}
+
+
+
+/**
+ @name sinfo_table_interpol
+ @brief interpolate value in table cnt with a uniform fit and subtract that
+        value from column INT of table lin
+ @param obj_lin object line table
+ @param obj_cnt object cont table
+ @param sky_lin sky    line table
+ @param sky_cnt sky    cont table
+ @param r   ratio which minimise diff=(obj_lin-obj_cnt) -r*(sky_lin-sky_cnt)
+ @return new table with corrected intensity.
+*/
+static cpl_table*
+sinfo_table_interpol(cpl_table* obj_lin,
+                     cpl_table* obj_cnt,
+                     cpl_table* sky_lin,
+                     cpl_table* sky_cnt,
+                     const double r)
+{
+
+  cpl_table* out=NULL;
+  cpl_table* obj_dif=NULL;
+  cpl_table* sky_dif=NULL;
+  cknull(obj_lin,"null line table");
+  cknull(obj_cnt,"null cont table");
+
+  cknull_nomsg(obj_dif=sinfo_table_subtract_continuum(obj_lin,obj_cnt));
+  cknull_nomsg(sky_dif=sinfo_table_subtract_continuum(sky_lin,sky_cnt));
+
+  check_nomsg(out=cpl_table_duplicate(obj_dif));
+  check_nomsg(cpl_table_duplicate_column(out,"CSKY",sky_dif,"INT"));
+  check_nomsg(cpl_table_multiply_scalar(out,"CSKY",r));
+  check_nomsg(cpl_table_subtract_columns(out,"INT","CSKY"));
+
+  sinfo_free_table(&obj_dif);
+  sinfo_free_table(&sky_dif);
+
+  return out;
+
+ cleanup:
+  sinfo_free_table(&obj_dif);
+  sinfo_free_table(&sky_dif);
+  sinfo_free_table(&out);
+  return NULL;
+
+}
+
+
+
+
+
+
+/**
+ @name sinfo_table_subtract_column
+ @brief interpolate value in table cnt with a uniform fit and subtract that
+        value from column INT of table lin
+ @param lin input table
+ @param cnt reference table
+ @return new table with corrected intensity.
+*/
+static cpl_table*
+sinfo_table_subtract_continuum(cpl_table* lin,
+                               cpl_table* cnt)
+
+{
+
+  cpl_table* out=NULL;
+  int nlin=0;
+  int ncnt=0;
+  int i=0;
+  double* poi=NULL;
+  cpl_vector* vx=NULL;
+  cpl_vector* vy=NULL;
+  cpl_polynomial* cfit=NULL;
+  cpl_size pows[2];
+  double mse=0;
+  double yfit=0;
+
+  cknull(lin,"null line table");
+  cknull(cnt,"null cont table");
+  check_nomsg(out=cpl_table_duplicate(lin));
+  check_nomsg(cpl_table_new_column(out,"CONT",CPL_TYPE_DOUBLE));
+  check_nomsg(nlin=cpl_table_get_nrow(lin));
+  check_nomsg(ncnt=cpl_table_get_nrow(cnt));
+  //sinfo_msg("nlin=%d",nlin);
+  check_nomsg(cpl_table_fill_column_window(out,"CONT",0,nlin,0));
+
+  //do a uniform fit
+  check_nomsg(vx=cpl_vector_wrap(ncnt,cpl_table_get_data_double(cnt,"WAVE")));
+  check_nomsg(vy=cpl_vector_wrap(ncnt,cpl_table_get_data_double(cnt,"INT")));
+  check_nomsg(cfit=sinfo_polynomial_fit_1d_create(vx,vy,0,&mse));
+  sinfo_unwrap_vector(&vx);
+  sinfo_unwrap_vector(&vy);
+
+  pows[0]=0;
+  pows[1]=0;
+  check_nomsg(yfit=cpl_polynomial_get_coeff(cfit,pows));
+  sinfo_free_polynomial(&cfit);
+  //sinfo_msg("coeff 0=%g",yfit);
+
+  check_nomsg(poi=cpl_table_get_data_double(out,"CONT"));
+  for(i=0;i<nlin;i++) {
+    poi[i]=yfit;
+  }
+
+  check_nomsg(cpl_table_subtract_columns(out,"INT","CONT"));
+  check_nomsg(cpl_table_erase_column(out,"CONT"));
+
+
+
+  return out;
+
+ cleanup:
+  sinfo_unwrap_vector(&vx);
+  sinfo_unwrap_vector(&vy);
+  sinfo_free_polynomial(&cfit);
+  sinfo_free_table(&out);
+  return NULL;
+
+}
+
+
+static int
+sinfo_compute_line_ratio(cpl_table* obj,
+                         cpl_table* sky,
+                         const double wtol,
+                         const int meth,
+                         const cpl_table* sel_regions,
+                         cpl_table* cont_regions,
+                         double* r)
+{
+  cpl_table* line_regions=NULL;
+  cpl_table* obj_cnt=NULL;
+  cpl_table* sky_cnt=NULL;
+  cpl_table* obj_lin=NULL;
+  cpl_table* sky_lin=NULL;
+  cpl_table* lres=NULL;
+  double fmed=0;
+  double fsdv=0;
+  double fthresh=0;
+  int fclip_i=0;
+  int line_i=0;
+
+
+  //line_regions = med_regions;
+  check_nomsg(line_regions = cpl_table_duplicate(sel_regions));
+  //r = amoeba(1.e-5,function_name='fitsky',p0=[1.],scale=[0.1]);
+  //Identify obj lines and continuum, same for sky
+  check_nomsg(obj_lin=sinfo_table_select_range(obj,line_regions,wtol));
+  check_nomsg(sky_lin=sinfo_table_select_range(sky,line_regions,wtol));
+  check_nomsg(obj_cnt=sinfo_table_select_range(obj,cont_regions,wtol));
+  check_nomsg(sky_cnt=sinfo_table_select_range(sky,cont_regions,wtol));
+
+  ck0_nomsg(sinfo_get_line_ratio(obj_lin,obj_cnt,sky_lin,sky_cnt,meth,r));
+
+
+  //fline_res = (obj_lr[line_regions]-
+  //             interpol(obj_lr[cont_regions],llr[cont_regions],
+  //             llr[line_regions])) -
+  //            (sky_lr[line_regions] -
+  //             interpol(sky_lr[cont_regions],llr[cont_regions],
+  //
+  //            llr[line_regions]))*r[0];
+  check_nomsg(lres=sinfo_table_interpol(obj_lin,obj_cnt,sky_lin,sky_cnt,*r));
+
+  check_nomsg(fmed = cpl_table_get_column_median(lres,"INT"));
+  check_nomsg(fsdv = cpl_table_get_column_stdev(lres,"INT"));
+  fthresh=fmed+3*fsdv;
+  //fclip = where(abs(fline_res) > fmed+3*fsdv,fclip_i);
+  check_nomsg(cpl_table_duplicate_column(lres,"AINT",lres,"INT"));
+  check_nomsg(cpl_table_multiply_columns(lres,"AINT","INT"));
+  check_nomsg(cpl_table_power_column(lres,"AINT",0.5));
+  check_nomsg(fclip_i=cpl_table_and_selected_double(lres,"AINT",
+                                                    CPL_GREATER_THAN,
+                                                    fthresh));
+  check_nomsg(cpl_table_select_all(lres));
+
+
+  if (fclip_i > 0) {
+    //line_regions = line_regions[where(abs(fline_res) < fmed+3*fsdv)];
+    check_nomsg(line_i=cpl_table_and_selected_double(lres,"AINT",
+                             CPL_LESS_THAN,
+                             fthresh));
+    sinfo_free_table(&line_regions);
+    check_nomsg(line_regions=cpl_table_extract_selected(lres));
+    sinfo_free_table(&lres);
+
+    check_nomsg(cpl_table_erase_column(line_regions,"INT"));
+    check_nomsg(cpl_table_erase_column(line_regions,"AINT"));
+
+
+    if (line_i >= 3) {
+
+    sinfo_free_table(&obj_lin);
+    sinfo_free_table(&sky_lin);
+    check_nomsg(obj_lin=sinfo_table_select_range(obj,line_regions,wtol));
+    check_nomsg(sky_lin=sinfo_table_select_range(sky,line_regions,wtol));
+
+    sinfo_free_table(&line_regions);
+
+
+     //r = amoeba(1.e-5,function_name='fitsky',p0=[1.],scale=[0.1]);
+      ck0_nomsg(sinfo_get_line_ratio(obj_lin,obj_cnt,sky_lin,sky_cnt,meth,r));
+    }
+  }
+  *r=fabs(*r);
+  //Free memory
+  sinfo_free_table(&obj_cnt);
+  sinfo_free_table(&sky_cnt);
+  sinfo_free_table(&sky_lin);
+  sinfo_free_table(&obj_lin);
+  sinfo_free_table(&lres);
+  sinfo_free_table(&line_regions);
+
+
+  return 0;
+
+
+ cleanup:
+
+
+  sinfo_free_table(&obj_cnt);
+  sinfo_free_table(&sky_cnt);
+  sinfo_free_table(&sky_lin);
+  sinfo_free_table(&obj_lin);
+
+  sinfo_free_table(&lres);
+  sinfo_free_table(&line_regions);
+
+  return -1;
+
+}
+/**
+
+ at name   sinfo_find_rot_waves
+ at memo   find wavelength range corresponding to a given rotational level
+ at param  w_rot array with wavelengths corresponding to rotational levels
+ at param  npix_w number of pixels corresponding to line width
+ at param  w_step wavelength sampling step
+ at param  range full wavelength range
+ at return wavelength range corresponding to a given rotational level
+*/
+
+static cpl_table*
+sinfo_find_rot_waves(
+             const double  w_rot[],
+                     const int npix_w,
+                     const double w_step,
+                     cpl_table* range
+             )
+{
+  int i=0;
+  int x_i=0;
+  int r_start=0;
+  double w_min=0;
+  double w_max=0;
+
+  cpl_table* w_sel=NULL;
+  cpl_table* res=NULL;
+
+  check_nomsg(res = cpl_table_new(0));
+
+  check_nomsg(cpl_table_copy_structure(res,range));
+
+  for (i=0; i< NROT; i++) {
+
+    //x = where(lambda > l_rot_low[i]-npixw*cdelto &&
+    //          lambda < l_rot_low[i]+npixw*cdelto,x_i);
+
+    w_min=w_rot[i]-npix_w*w_step;
+    w_max=w_rot[i]+npix_w*w_step;
+
+    check_nomsg(cpl_table_and_selected_double(range,"WAVE",
+                                              CPL_GREATER_THAN,w_min));
+    check_nomsg(cpl_table_and_selected_double(range,"WAVE",
+                                              CPL_LESS_THAN,w_max));
+    sinfo_free_table(&w_sel);
+    check_nomsg(w_sel=cpl_table_extract_selected(range));
+    check_nomsg(x_i=cpl_table_get_nrow(w_sel));
+
+    if (x_i > 0) {
+      check_nomsg(r_start=cpl_table_get_nrow(res));
+      //sinfo_msg("i=%d x_i=%d w_min=%g w_max=%g",i,x_i,w_min,w_max);
+      check_nomsg(cpl_table_insert(res,w_sel,r_start));
+    }
+    check_nomsg(cpl_table_select_all(range));
+  }
+
+  //res = range[1:cpl_table_get_nrow(res)-1];
+  sinfo_free_table(&w_sel);
+
+
+  return res;
+
+ cleanup:
+  sinfo_free_table(&w_sel);
+  sinfo_free_table(&res);
+  return NULL;
+
+}
+
+/**
+ at name sinfo_get_obj_sky_wav_sub
+ at param obj input object spectrum
+ at param sky input sky spectrum
+ at param wav input full wavelength range
+ at param sel input selection wavelength range
+ at param wtol intup wavelength tolerance
+ at param sub_obj output sub set of object spectrum
+ at param sub_sky output sub set of sky spectrum
+ at param sub_wav output sub set of wavelength range
+*/
+
+static int
+sinfo_get_obj_sky_wav_sub(cpl_table* obj,
+                          cpl_table* sky,
+                          cpl_table* wav,
+                          cpl_table* sel,
+                          const double wtol,
+                          cpl_table** sub_obj,
+                          cpl_table** sub_sky,
+                          cpl_table** sub_wav)
+
+{
+  cknull_nomsg(*sub_obj = sinfo_table_select_range(obj,sel,wtol));
+  cknull_nomsg(*sub_sky = sinfo_table_select_range(sky,sel,wtol));
+  cknull_nomsg(*sub_wav = sinfo_table_select_range(wav,sel,wtol));
+  return 0;
+
+ cleanup:
+  sinfo_free_table(&(*sub_obj));
+  sinfo_free_table(&(*sub_sky));
+  sinfo_free_table(&(*sub_wav));
+
+  return -1;
+
+}
+
+static int
+sinfo_get_sub_regions(cpl_table* sky,
+                      cpl_table* x1,
+                      cpl_table* pos,
+                      const double wtol,
+                      const int npixw,
+                      cpl_table** res)
+{
+
+  cpl_table* x1_sub=NULL;
+  cpl_table* x2=NULL;
+
+  int nrow=0;
+  int np=0;
+
+  cknull(sky,"Null input sky table");
+  cknull(x1 ,"Null input x1 table");
+  cknull(pos,"Null input pos table");
+
+  check_nomsg(x2=cpl_table_duplicate(sky));
+  check_nomsg(nrow=cpl_table_get_nrow(sky));
+  check_nomsg(cpl_table_fill_column_window(x2,"INT",0,nrow,0));
+
+  //x2[x1[pos]] = 10.;
+  //x2 = convol(x2,replicate(1,npixw),/edge_truncate,/center);
+  //res = where(x2 > 0,hi_i);
+  //cpl_table_save(x1, NULL, NULL, "out_x1.fits", CPL_IO_DEFAULT);
+
+  x1_sub=sinfo_table_select_range(x1,pos,wtol);
+
+  if(x1_sub != NULL) {
+    ck0_nomsg(sinfo_table_fill_column_over_range(&x2,x1_sub,"INT",10.,wtol));
+    sinfo_free_table(&x1_sub);
+    check_nomsg(sinfo_convolve_kernel(&x2,npixw/2));
+    check_nomsg(np=cpl_table_and_selected_double(x2,"CNV",CPL_GREATER_THAN,0));
+    check_nomsg(*res=cpl_table_extract_selected(x2));
+    sinfo_free_table(&x2);
+    check_nomsg(cpl_table_erase_column(*res,"INT"));
+    check_nomsg(cpl_table_erase_column(*res,"CNV"));
+
+  } else {
+    cpl_error_reset();
+    sinfo_free_table(&x1_sub);
+    sinfo_free_table(&x2);
+
+    return np;
+  }
+
+  return np;
+ cleanup:
+
+  sinfo_free_table(&x1_sub);
+  sinfo_free_table(&x2);
+  return -1;
+
+}
+
+static cpl_table*
+sinfo_table_extract_rest(cpl_table* inp,
+                         cpl_table* low,
+                         cpl_table* med,
+                         const double wtol)
+{
+
+  cpl_table* out=NULL;
+  double* pinp=NULL;
+  double* plow=NULL;
+  double* pmed=NULL;
+  int nlow=0;
+  int nmed=0;
+
+  int nrow=0;
+  int i=0;
+  int k=0;
+  cpl_table* tmp=NULL;
+
+  cknull(inp,"null input table");
+
+
+  check_nomsg(tmp=cpl_table_duplicate(inp));
+  check_nomsg(nrow=cpl_table_get_nrow(tmp));
+  check_nomsg(cpl_table_new_column(tmp,"SEL",CPL_TYPE_INT));
+  check_nomsg(cpl_table_fill_column_window_int(tmp,"SEL",0,nrow,0));
+
+  check_nomsg(pinp=cpl_table_get_data_double(inp,"WAVE"));
+  check_nomsg(plow=cpl_table_get_data_double(low,"WAVE"));
+  check_nomsg(pmed=cpl_table_get_data_double(med,"WAVE"));
+  nlow=cpl_table_get_nrow(low);
+
+
+  //check_nomsg(cpl_table_save(low,NULL,NULL,"out_low.fits",CPL_IO_DEFAULT));
+  if(nlow > 0) {
+    k=0;
+    for(i=0;i<nrow;i++) {
+      if(fabs(pinp[i]-plow[k]) < wtol) {
+    cpl_table_set_int(tmp,"SEL",k,-1);
+    k++;
+      }
+    }
+  }
+  nmed=cpl_table_get_nrow(med);
+
+  k=0;
+  if(nmed > 0) {
+    for(i=0;i<nrow;i++) {
+      if(fabs(pinp[i]-pmed[k]) < wtol) {
+    cpl_table_set_int(tmp,"SEL",k,-1);
+    k++;
+      }
+    }
+  }
+
+  check_nomsg(cpl_table_and_selected_int(tmp,"SEL",CPL_GREATER_THAN,-1));
+  check_nomsg(out=cpl_table_extract_selected(tmp));
+  sinfo_free_table(&tmp);
+  check_nomsg(cpl_table_erase_column(out,"SEL"));
+
+  return out;
+
+ cleanup:
+  sinfo_free_table(&tmp);
+  return NULL;
+
+}
+
+/**@}*/
diff --git a/sinfoni/sinfo_skycor.h b/sinfoni/sinfo_skycor.h
new file mode 100644
index 0000000..8e6a697
--- /dev/null
+++ b/sinfoni/sinfo_skycor.h
@@ -0,0 +1,107 @@
+/* $Id: sinfo_skycor.h,v 1.13 2007/03/05 07:21:54 amodigli Exp $
+ *
+ * This file is part of the SINFONI Pipeline
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2007/03/05 07:21:54 $
+ * $Revision: 1.13 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifndef SINFO_SKYCOR_H
+#define SINFO_SKYCOR_H
+#include <cpl.h>
+
+#define SINFO_MASK_WAVE_MIN 1.4
+#define SINFO_MASK_WAVE_MAX 2.5
+#define SINFO_MIN_FRAC 0.8
+#define SINFO_LINE_HALF_WIDTH 4.0
+#define SINFO_SKY_BKG_FILTER_WIDTH 12
+
+
+
+#define HISTO_NBINS 100
+#define HISTO_MIN_SIZE 10
+#define HISTO_Y_CUT 10          /* 50 is a better value this 
+                                   affects histo right marging*/
+#define HISTO_X_LEFT_CUT  1.0   /* 0.2 is better */
+#define HISTO_X_RIGHT_CUT  0.5  /* 1.0 is better */
+#define HISTO_DIST_TEMPC_MIN_FCT 5.   /* 5.0 */
+#define HISTO_DIST_TEMPC_MAX_FCT 0.25 /* 0.25 */
+
+struct sinfo_skycor_qc_ {
+  int   th_fit;
+};
+typedef struct sinfo_skycor_qc_ sinfo_skycor_qc; 
+
+sinfo_skycor_qc* sinfo_skycor_qc_new(void);
+void sinfo_skycor_qc_delete(sinfo_skycor_qc** s);
+
+
+int 
+sinfo_skycor(cpl_parameterlist * config, 
+             cpl_frame* obj_frm, 
+             cpl_frame* sky_frm,
+             sinfo_skycor_qc* sqc,
+             cpl_imagelist** obj_cor,
+             cpl_table** int_obj);
+
+
+
+int
+sinfo_histogram(const cpl_table* data,
+                const int nbins, 
+                const double min, 
+                const double max,
+                cpl_table** histo);
+int
+sinfo_table_get_index_of_val(cpl_table* t,
+                             const char* name,
+                             double val,
+                             cpl_type type);
+
+int
+sinfo_table_get_index_of_max(cpl_table* t,
+                             const char* name,
+                             cpl_type type);
+
+
+double
+sinfo_table_column_interpolate(const cpl_table* t,
+                               const char* name,
+                               const double x);
+
+
+
+
+
+cpl_table* 
+sinfo_where_tab_min_max(cpl_table* t, 
+                        const char* col, 
+                        cpl_table_select_operator op1,  
+                        const double v1, 
+                        cpl_table_select_operator op2, 
+                        const double v2);
+
+#endif
diff --git a/sinfoni/sinfo_skycor_config.c b/sinfoni/sinfo_skycor_config.c
new file mode 100644
index 0000000..9081e0a
--- /dev/null
+++ b/sinfoni/sinfo_skycor_config.c
@@ -0,0 +1,229 @@
+/* $Id: sinfo_skycor_config.c,v 1.17 2012/03/03 10:18:26 amodigli Exp $
+ *
+ * This file is part of the CPL (Common Pipeline Library)
+ * Copyright (C) 2002 European Southern Observatory
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*
+ * $Author: amodigli $
+ * $Date: 2012/03/03 10:18:26 $
+ * $Revision: 1.17 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#include "sinfo_skycor_config.h"
+#include "sinfo_skycor.h"
+
+/**@{*/
+/**
+ * @defgroup sinfo_skycor_config Sky residuals corrections configuration 
+ *   parameters
+ *
+ * TBD
+ */
+
+  /**
+  * @brief
+  *   Adds parameters for the spectrum extraction
+  *
+  * @param list Parameter list to which parameters are added.
+  *
+  * @return Nothing.
+  *
+  * TBD
+  */
+
+  /* General data reduction parameters */
+
+void
+ sinfo_skycor_config_add(cpl_parameterlist *list)
+{
+
+  cpl_parameter *p;
+
+  if (!list) {
+    return;
+  }
+
+
+   /* Fill the parameters list */
+    /* --stropt */
+  
+    p = cpl_parameter_new_value("sinfoni.sinfo_utl_skycor.mask_ws", 
+                                CPL_TYPE_DOUBLE, 
+             "Starting wavelength for object-sky cross correlation", 
+                                "sinfoni.sinfo_utl_skycor",
+                                SINFO_MASK_WAVE_MIN) ;
+    cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "skycor-mask_ws") ;
+    cpl_parameterlist_append(list, p) ;
+
+
+    p = cpl_parameter_new_value("sinfoni.sinfo_utl_skycor.mask_we", 
+                                CPL_TYPE_DOUBLE, 
+             "End wavelength for object-sky cross correlation", 
+                                "sinfoni.sinfo_utl_skycor", 
+                                SINFO_MASK_WAVE_MAX) ;
+    cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "skycor-mask_we") ;
+    cpl_parameterlist_append(list, p) ;
+  
+
+    p = cpl_parameter_new_value("sinfoni.sinfo_utl_skycor.min_frac", 
+                                CPL_TYPE_DOUBLE, 
+   "Threshold value for fraction of spatial pixels to be sky", 
+                                "sinfoni.sinfo_utl_skycor", 
+                                SINFO_MIN_FRAC) ;
+    cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "skycor-min_frac") ;
+    cpl_parameterlist_append(list, p) ;
+
+
+
+    p = cpl_parameter_new_range(
+                      "sinfoni.sinfo_utl_skycor.sky_bkg_filter_width", 
+                                CPL_TYPE_INT, 
+                                "Width of sky-thermal background pre filter "
+                                "(to remove emission lines before fitting a "
+                                "Black Body).", 
+                                "sinfoni.sinfo_utl_skycor", 
+                                SINFO_SKY_BKG_FILTER_WIDTH,2,25) ;
+    cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, 
+                              "skycor-sky_bkg_filter_width") ;
+    cpl_parameterlist_append(list, p) ;
+
+    p = cpl_parameter_new_value("sinfoni.sinfo_utl_skycor.line_half_width", 
+                                CPL_TYPE_DOUBLE, 
+                                "Threshold value for full width in pixels "
+                                "of unresolved emission line. Lines with FWHM "
+                                "smaller than this value are not considered " 
+                                "in the object-sky cross correlation and in "
+                                "computation of the optimal sky lines scaling "
+                                "factor", 
+                                "sinfoni.sinfo_utl_skycor", 
+                                SINFO_LINE_HALF_WIDTH) ;
+    cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "skycor-line_hw") ;
+    cpl_parameterlist_append(list, p) ;
+
+    p = cpl_parameter_new_enum("sinfoni.sinfo_utl_skycor.scale_method", 
+                   CPL_TYPE_INT, 
+                               "Optimal sky lines scaling factor computation "
+                   "method: amoeba fit (0), "
+                               "maximum likelihood (1) ",
+                               "sinfoni.sinfo_utl_skycor", 
+                               1,2,0,1) ;
+    cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, 
+                            "skycor-scale_method") ;
+    cpl_parameterlist_append(list, p) ;
+
+
+    p = cpl_parameter_new_value("sinfoni.sinfo_utl_skycor.rot_cor", 
+                                CPL_TYPE_BOOL, 
+                                "Computes scaling factor correction due to "
+                                "rotational levels transitions",
+                                "sinfoni.sinfo_utl_skycor", 
+                                FALSE) ;
+    cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "skycor-rot_cor") ;
+    cpl_parameterlist_append(list, p) ;
+
+
+
+    p = cpl_parameter_new_value("sinfoni.sinfo_utl_skycor.fit_obj_noise", 
+                                CPL_TYPE_BOOL, 
+                                "Do Gaussian fit of object noise",
+                                "sinfoni.sinfo_utl_skycor", 
+                                FALSE) ;
+    cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "skycor-fit_obj_noise");
+    cpl_parameterlist_append(list, p) ;
+
+
+    p = cpl_parameter_new_value("sinfoni.sinfo_utl_skycor.niter", 
+                                CPL_TYPE_INT, 
+                                "Number of iterations of background "
+                                "fit", 
+                                "sinfoni.sinfo_utl_skycor", 
+                                10) ;
+    cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "skycor-niter") ;
+    cpl_parameterlist_append(list, p) ;
+
+    p = cpl_parameter_new_value("sinfoni.sinfo_utl_skycor.pshift", 
+                                CPL_TYPE_DOUBLE, 
+                                "Sky spectrum shift towar object", 
+                                "sinfoni.sinfo_utl_skycor", 
+                                0.) ;
+    cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "skycor-pshift") ;
+    cpl_parameterlist_append(list, p) ;
+
+    p = cpl_parameter_new_value("sinfoni.sinfo_utl_skycor.llx", 
+                                CPL_TYPE_INT, 
+                                "Lower left X defining object "
+                                "spectrum location", 
+                                "sinfoni.sinfo_utl_skycor", 
+                                1) ;
+    cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "skycor-llx") ;
+    cpl_parameterlist_append(list, p) ;
+
+    p = cpl_parameter_new_value("sinfoni.sinfo_utl_skycor.lly", 
+                                CPL_TYPE_INT, 
+                                "Lower left Y defining object "
+                                "spectrum location", 
+                                "sinfoni.sinfo_utl_skycor", 
+                                1) ;
+    cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "skycor-lly") ;
+    cpl_parameterlist_append(list, p) ;
+
+
+
+    p = cpl_parameter_new_value("sinfoni.sinfo_utl_skycor.urx", 
+                                CPL_TYPE_INT, 
+                                "Upper right X defining object "
+                                "spectrum location", 
+                                "sinfoni.sinfo_utl_skycor", 
+                                64) ;
+    cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "skycor-urx") ;
+    cpl_parameterlist_append(list, p) ;
+
+
+    p = cpl_parameter_new_value("sinfoni.sinfo_utl_skycor.ury", 
+                                CPL_TYPE_INT, 
+                                "Upper right Y defining object "
+                                "spectrum location", 
+                                "sinfoni.sinfo_utl_skycor", 
+                                64) ;
+    cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "skycor-ury") ;
+    cpl_parameterlist_append(list, p) ;
+
+
+
+    p = cpl_parameter_new_value(
+     
+                              "sinfoni.sinfo_utl_skycor.sub_thr_bkg_from_obj", 
+                                CPL_TYPE_BOOL, 
+                                "Subtract thermal background contribute from "
+                                "object spectra. Set it to TRUE if "
+                                "stack-sub_raw_sky is set to FALSE",
+                                "sinfoni.sinfo_utl_skycor", 
+                                FALSE) ;
+
+    cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, 
+			    "skycor-sub_thr_bkg_from_obj") ;
+    cpl_parameterlist_append(list, p) ;
+
+
+}
+/**@}*/
diff --git a/sinfoni/sinfo_skycor_config.h b/sinfoni/sinfo_skycor_config.h
new file mode 100644
index 0000000..ba20f10
--- /dev/null
+++ b/sinfoni/sinfo_skycor_config.h
@@ -0,0 +1,37 @@
+/* $Id: sinfo_skycor_config.h,v 1.1 2006/11/27 16:55:26 amodigli Exp $
+ *
+ * This file is part of the CPL (Common Pipeline Library)
+ * Copyright (C) 2002 European Southern Observatory
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*
+ * $Author: amodigli $
+ * $Date: 2006/11/27 16:55:26 $
+ * $Revision: 1.1 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+ /****************************************************************
+  *           Bad pixel search  (noise method)                  *
+  ****************************************************************/
+#ifndef SINFO_SKYCOR_CONFIG_H
+#define SINFO_SKYCOR_CONFIG_H
+
+#include <cpl.h>   
+
+void sinfo_skycor_config_add(cpl_parameterlist *list);
+
+#endif
diff --git a/sinfoni/sinfo_solve_poly_root.c b/sinfoni/sinfo_solve_poly_root.c
new file mode 100644
index 0000000..2b80549
--- /dev/null
+++ b/sinfoni/sinfo_solve_poly_root.c
@@ -0,0 +1,131 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+/*#include "companion.c"*/
+/*#include "balance.c"*/
+/*#include "qr.c"*/
+#include "sinfo_solve_poly_root.h"
+
+/**@{*/
+/**
+ * @addtogroup sinfo_utilities Utilities to find roots of a polynomial
+ *
+ * TBD
+ */
+
+
+gsl_poly_complex_workspace *
+sinfo_gsl_poly_complex_workspace_alloc (size_t n)
+{
+  size_t nc ;
+
+  gsl_poly_complex_workspace * w ;
+ 
+  if (n == 0)
+    {
+      sinfo_msg_error ("sinfo_matrix size n must be positive integer");
+      return NULL ;
+    }
+
+  w = (gsl_poly_complex_workspace *)
+    cpl_malloc (sizeof(gsl_poly_complex_workspace));
+
+  if (w == 0)
+    {
+      sinfo_msg_error ("failed to allocate space for struct");
+      return NULL ;
+    }
+
+  nc = n - 1;
+
+  w->nc = nc;
+
+  w->sinfo_matrix = (double *) cpl_malloc (nc * nc * sizeof(double));
+
+  if (w->sinfo_matrix == 0)
+    {
+      cpl_free (w) ;       /* error in constructor, avoid memory leak */
+      sinfo_msg_error("failed to allocate for workspace sinfo_matrix") ;
+      return  NULL ;
+    }
+
+  return w ;
+}
+
+void
+sinfo_gsl_poly_complex_workspace_free (gsl_poly_complex_workspace * w)
+{
+  cpl_free(w->sinfo_matrix) ;
+  cpl_free(w);
+}
+
+
+int
+sinfo_gsl_poly_complex_solve (const double *a, size_t n,
+            gsl_poly_complex_workspace * w,
+            gsl_complex_packed_ptr z)
+{
+  int status;
+  double *m;
+
+  if (n == 0)
+    {
+      sinfo_msg_error ("number of terms must be a positive integer");
+      return -1 ;
+    }
+
+  if (n == 1)
+    {
+      sinfo_msg_error ("cannot solve for only one term");
+      return -1 ;
+    }
+
+  if (a[n - 1] == 0)
+    {
+      sinfo_msg_error ("leading term of polynomial must be non-zero") ;
+      return -1 ;
+    }
+
+  if (w->nc != n - 1)
+    {
+      sinfo_msg_error ("size of workspace does not match polynomial");
+      return -1 ;
+    }
+  
+  m = w->sinfo_matrix;
+
+  sinfo_set_companion_matrix (a, n - 1, m);
+
+  sinfo_balance_companion_matrix (m, n - 1);
+
+  status = sinfo_qr_companion (m, n - 1, z);
+
+  if (status == -1)
+    {
+      sinfo_msg_error("root solving qr method failed to converge");
+      return -1 ;
+    }
+
+  return 1;
+}
+
+/**@}*/
+
diff --git a/sinfoni/sinfo_solve_poly_root.h b/sinfoni/sinfo_solve_poly_root.h
new file mode 100644
index 0000000..0360b8c
--- /dev/null
+++ b/sinfoni/sinfo_solve_poly_root.h
@@ -0,0 +1,77 @@
+#ifndef SINFO_SOLVE_POLY_ROOT_H
+#define SINFO_SOLVE_POLY_ROOT_H
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/*
+#include <stdio.h>
+*/
+#include <stdlib.h>
+#include <math.h>
+#include <stdlib.h>
+#include <cpl.h>
+#include "sinfo_msg.h"
+
+/* C-style sinfo_matrix elements */
+#define MAT(m,i,j,n) ((m)[(i)*(n) + (j)])
+
+/* Fortran-style sinfo_matrix elements */
+#define FMAT(m,i,j,n) ((m)[((i)-1)*(n) + ((j)-1)])
+
+
+#undef __BEGIN_DECLS
+#undef __END_DECLS
+#ifdef __cplusplus
+# define __BEGIN_DECLS extern "C" {
+# define __END_DECLS }
+#else
+# define __BEGIN_DECLS /* empty */
+# define __END_DECLS /* empty */
+#endif
+
+typedef double *       gsl_complex_packed_ptr ;
+
+void sinfo_balance_companion_matrix (double *m, size_t nc);
+int sinfo_qr_companion (double *h, size_t nc, gsl_complex_packed_ptr z);
+void sinfo_set_companion_matrix (const double *a, size_t n, double *m);
+
+__BEGIN_DECLS
+
+/* Solve for the complex roots of a general real polynomial */
+
+typedef struct 
+{ 
+  size_t nc ;
+  double * sinfo_matrix ; 
+} 
+gsl_poly_complex_workspace ;
+
+gsl_poly_complex_workspace * sinfo_gsl_poly_complex_workspace_alloc (size_t n);
+void sinfo_gsl_poly_complex_workspace_free (gsl_poly_complex_workspace * w);
+
+int
+sinfo_gsl_poly_complex_solve (const double * a, size_t n, 
+                        gsl_poly_complex_workspace * w,
+                        gsl_complex_packed_ptr z);
+            
+            
+
+__END_DECLS
+
+#endif /* SINFO_SOLVE_POLY_ROOT_H */
diff --git a/sinfoni/sinfo_spectrum_ops.c b/sinfoni/sinfo_spectrum_ops.c
new file mode 100644
index 0000000..98a4ea7
--- /dev/null
+++ b/sinfoni/sinfo_spectrum_ops.c
@@ -0,0 +1,2674 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/***************************************************************************
+* E.S.O. - VLT project
+*
+*
+*
+* who       when      what
+* --------  --------  ----------------------------------------------
+* schreib  25/05/00  created
+*/
+
+/************************************************************************
+*   NAME
+*        sinfo_spectrum_ops.c -
+*        some sinfo_vector procedures to operate on spectra
+*
+*   SYNOPSIS
+*   #include "sinfo_spectrum_ops.h"
+*
+*   1) Vector * sinfo_new_vector( ulong32 n_elements )
+*   2) void * sinfo_new_destroy_vector( Vector *sinfo_vector )
+*   3) cpl_image * sinfo_new_vector_to_image( Vector * spectrum )
+*   4) Vector * sinfo_new_image_to_vector( cpl_image * spectrum )
+*   5) cpl_image * 
+       sinfo_new_extract_spectrum_from_resampled_flat(cpl_image * resflat,
+*                                                   float      loreject,
+*                                                   float      hireject ) 
+*   6) cpl_image * sinfo_new_multiply_image_with_spectrum(cpl_image * image, 
+                                                          cpl_image * spectrum)
+*   7) cpl_image * sinfo_new_optimal_extraction_from_cube(cpl_imagelist * cube, 
+*                                            int       halfbox_x, 
+*                                            int       halfbox_y,
+*                                            float     fwhm_factor,
+*                                            float     backvariance,
+*                                            float     sky,
+*                                            float     gain,
+*                                            float     exptime)
+*   8) Vector * sinfo_new_extract_sky_from_cube( cpl_imagelist * cube,
+*                                   float     loReject,
+*                                   float     hiReject,
+*                                   int     * position,
+*                                   int       tolerance,
+*                                   int       posindicator )
+*    9) Vector * sinfo_new_sum_rectangle_of_cube_spectra( cpl_imagelist * cube,
+*                                     int llx,
+*                                     int lly,
+*                                     int urx,
+*                                     int ury )
+*   10) Vector * sinfo_new_sum_circle_of_cube_spectra( cpl_imagelist * cube,
+*                                        int       centerx,
+*                                        int       centery,
+*                                        int       radius )
+*   11) Vector * 
+        sinfo_new_mean_rectangle_of_cube_spectra( cpl_imagelist * cube,
+*                                            int llx,
+*                                            int lly,
+*                                            int urx,
+*                                            int ury )
+*   12) Vector * sinfo_new_mean_circle_of_cube_spectra( cpl_imagelist * cube,
+*                                         int       centerx,
+*                                         int       centery,
+*                                         int       radius )
+*   13) Vector * 
+        sinfo_new_blackbody_spectrum(char * templateSpec, double temp )
+*   14) Vector * 
+        sinfo_new_median_rectangle_of_cube_spectra(cpl_imagelist * cube,
+*                                               int llx,
+*                                               int lly,
+*                                               int urx,
+*                                               int ury )
+*   15) Vector * sinfo_new_median_circle_of_cube_spectra( cpl_imagelist * cube,
+*                                           int       centerx,
+*                                           int       centery,
+*                                           int       radius )
+*   16) Vector * 
+        sinfo_new_cleanmean_rectangle_of_cube_spectra(cpl_imagelist * cube,
+*                                                 int llx,
+*                                                 int lly,
+*                                                 int urx,
+*                                                 int ury,
+*                                                 float lo_reject,
+*                                                 float hi_reject )
+*   17) Vector * 
+        sinfo_new_cleanmean_circle_of_cube_spectra( cpl_imagelist * cube,
+*                                              int       centerx,
+*                                              int       centery,
+*                                              int       radius,
+*                                              float     lo_reject,
+*                                              float     hi_reject )
+*   18) float * sinfo_new_shift_array ( float * input, 
+                                        int n_elements, 
+                                        float shift, 
+                                        double * ker ) 
+*
+*   DESCRIPTION
+*   1) allocates memory for a new sinfo_vector
+*   2) frees memory of a sinfo_vector
+*   3) converts a spectral sinfo_vector to a fits image
+*      remark: sinfo_vector object spectrum is destroyed
+*   4) converts a fits image to a spectral sinfo_vector
+*      remark: input image is destroyed
+*   5) builds one spectrum in a fits image out of a resampled
+*      flatfield frame by taking a clean mean along the spatial pixels
+*   6) multiplys a resampled image with a resampled spectrum
+*      (calibrated halogen lamp spectrum) in the same spectral range
+*      that means all image columns are multiplied with the same spectrum
+*   7) does the optimal extraction of a standard star spectrum
+*      according to the equation:
+*       S = sum { (P^2 / V) * (I - B) / P } / sum{ P^2 / V } 
+*       S: spectral flux at a particular wavelength
+*       P: normalized PSF (determined by a 2D-Gaussian fit)
+*       I: pixel value
+*       B: background pixel value determined by the background parameter 
+           of the 2D-Gaussian fit
+*       V: estimated variance of a pixel: 
+           V = [R^2 + D + sky + I,c/exptime]/gain
+*          where R is the read noise, and D the sinfo_dark current variance.
+*          backvariance is R^2 + D in counts/sec. 
+           I,c is the source intensity in counts
+*          Remember: sigma,e[e-] = gain[e/count] * sigma,c [counts] = 
+                     sqrt(I,e) = sqrt(gain*I,c)
+*          => V,c = sigma,c^2 = sigma,e^2/gain^2 
+*          => sigma,c = sqrt(I,c/gain) => V,c = I,c/gain
+*   8) extracts a sky spectrum from a reduced sky spider observation, that
+*      means from a data cube. Therefore, the position of the sky within the
+*      field of view must be first read from the fits header.  
+       A pixel tolerance is subtracted.
+*      The found sky spectra are averaged by rejecting the extreme 
+       high and low values.
+*   9) summing routine for a reduced data to get a better spectral S/N
+*      only for a rectangular aperture.
+*   10) summing routine for a reduced data to get a better spectral S/N
+*       only for a circular aperture.
+*   11) averaging routine for a reduced data to get a better spectral S/N
+*       only for a rectangular aperture.
+*   12) averaging routine for a reduced data to get a better spectral S/N
+*       only for a circular aperture.
+*   13) computes a blackbody spectral intensity distribution
+*       (W/(m^2 lambda ster)) 
+*   14) sinfo_median routine for a reduced data to get a better spectral S/N
+*       only for a rectangular aperture.
+*   15) sinfo_median routine for a reduced data to get a better spectral S/N
+*       only for a circular aperture.
+*   16) clean averaging routine for a reduced data to get a better spectral S/N
+*       only for a rectangular aperture.
+*   17) clean averaging routine for a reduced data to get a better spectral S/N
+*       only for a circular aperture.
+*   18) shifts an array by a sub-pixel shift value using a tanh
+*       interpolation kernel
+*
+*   FILES
+*
+*   ENVIRONMENT
+*
+*   RETURN VALUES
+*
+*   CAUTIONS
+*
+*   EXAMPLES
+*
+*   SEE ALSO
+*
+*   BUGS
+*
+*------------------------------------------------------------------------
+*/
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#define POSIX_SOURCE 1
+#include "sinfo_vltPort.h"
+
+/*
+ * System Headers
+ */
+
+/*
+ * Local Headers
+ */
+#include "sinfo_pfits.h"
+#include "sinfo_spectrum_ops.h"
+#include "sinfo_resampling.h"
+#include "sinfo_utilities.h"
+#include "sinfo_utils_wrappers.h"
+/*----------------------------------------------------------------------------
+ *                            Function codes
+ *--------------------------------------------------------------------------*/
+
+/**@{*/
+/**
+ * @defgroup sinfo_spectrum_ops Operations on spectra
+ *
+ * TBD
+ */
+
+
+
+/**
+ at brief convert an image in a table spectrum 
+ at name sinfo_stectrum_ima2table
+ at param spc       input image spectrum
+ at param filename  input filename
+ at param tbl       output table
+*/
+
+int sinfo_stectrum_ima2table(
+                 const cpl_image* spc,
+                 const char* filename,
+                 cpl_table** tbl)
+{
+  const float* pidata=NULL;
+  int nx=0;
+  int ny=0;
+  int nraw=0;
+  int i=0;
+  double amp=0;
+  double wav=0;
+ 
+  double step=0;
+  double ws=0;
+  double we=0;
+  double wc=0;
+  cpl_propertylist* plist=NULL;
+
+  if(spc == NULL){
+    sinfo_msg_error("Input image is null");
+    return -1;
+  }
+
+  pidata = cpl_image_get_data_const(spc);
+  nx=cpl_image_get_size_x(spc);
+  ny=cpl_image_get_size_y(spc);
+
+  if((nx == 0) || (ny == 0)) {
+    sinfo_msg_error("Input image has improper size: nx=%d ny=%d",nx,ny);
+    return -1;
+  }
+  if((nx > 1) && (ny > 1)) {
+    sinfo_msg_error("Input image has improper size: nx=%d ny=%d",nx,ny);
+    return -1;
+  }
+
+
+  nraw=nx*ny;
+  *tbl = cpl_table_new(nraw);
+  cpl_table_new_column(*tbl,"WAVE",CPL_TYPE_DOUBLE);
+  cpl_table_new_column(*tbl,"INT",CPL_TYPE_DOUBLE);
+
+
+  if ((cpl_error_code)((plist = cpl_propertylist_load(filename, 0)) == NULL)) {
+      sinfo_msg_error( "getting header from reference frame %s",filename);
+      cpl_propertylist_delete(plist) ;
+      return -1 ;
+  }
+
+
+  if(nx>1) {
+    step=sinfo_pfits_get_cdelt1(plist);
+    wc=sinfo_pfits_get_crval1(plist);
+  } else {
+
+    step=sinfo_pfits_get_cdelt2(plist);
+    wc=sinfo_pfits_get_crval2(plist);
+  }
+
+  ws=wc-nraw*step/2;
+  we=wc+nraw*step/2;
+  wav=ws;
+  sinfo_msg("ws=%f we=%f step=%f",ws,we,step);
+  cpl_table_set_double(*tbl,"WAVE",0,wav);
+  cpl_table_set_double(*tbl,"INT",0,pidata[i]);
+
+  for(i=1;i<nraw;i++) {
+    wav+=step;
+    amp=(double)pidata[i];
+    cpl_table_set_double(*tbl,"WAVE",i,wav);
+    cpl_table_set_double(*tbl,"INT",i,amp);
+  }
+  cpl_propertylist_delete(plist);
+  return 0;
+
+
+}
+
+
+
+/**
+ at brief allocates memory for a new sinfo_vector
+ at name sinfo_new_vector()
+ at param n_elements number of sinfo_vector elements
+ at return Vector 
+*/
+
+
+
+Vector * sinfo_new_vector( ulong32 n_elements )
+{
+    Vector * local_new_vector ;
+
+    if ( n_elements <= 0 )
+    {
+        sinfo_msg_error (" wrong number of elements\n") ;
+        return NullVector ;
+    }
+    
+    /* allocate memory for a sinfo_vector with the given number of elements */
+    local_new_vector = (Vector *) cpl_malloc (sizeof (Vector)) ; 
+    local_new_vector -> n_elements = n_elements ;
+    local_new_vector -> data = (pixelvalue *) cpl_calloc (n_elements, 
+                                                  sizeof (pixelvalue)) ;
+
+    return local_new_vector ;
+}
+
+/**
+ at brief frees memory of a sinfo_vector
+ at name sinfo_free_svector()
+ at param sinfo_vector to destroy
+ at return nothing 
+*/
+
+void sinfo_free_svector( Vector **svector )
+{
+    if ( *svector != NULL )   
+    {
+       
+      if((*svector) -> data != NULL) {
+    cpl_free ( (*svector) -> data ) ;
+    (*svector)->data = NULL;
+      }
+      cpl_free ( *svector ) ;
+      *svector = NULL;
+    }
+    return ;
+}
+
+/**
+ at brief frees memory of a sinfo_vector
+ at name sinfo_new_destroy_vector()
+ at param sinfo_vector to destroy
+ at return nothing 
+*/
+
+void sinfo_new_destroy_vector( Vector *sinfo_vector )
+{
+    if ( sinfo_vector == NULL )   
+    {
+        sinfo_msg_error(" NULL Vector given!\n") ;
+        return ;
+    }    
+    
+    cpl_free ( sinfo_vector -> data ) ;
+    cpl_free ( sinfo_vector ) ;
+}
+
+/**
+ at brief converts a spectral sinfo_vector to a fits image
+ at name sinfo_new_vector_to_image()
+ at param spectral sinfo_vector that should be converted to a fits image
+ at return image with lx = 1 and ly = length of sinfo_vector
+ at note sinfo_vector object spectrum is destroyed
+*/
+
+cpl_image * sinfo_new_vector_to_image( Vector * spectrum )
+{
+    cpl_image * returnIm ;
+    int i ;
+   
+    float* podata=NULL;
+
+
+    if ( spectrum == NULL )
+    {
+        sinfo_msg_error(" no spectrum given!\n") ;
+        return NULL ;
+    }
+ 
+    /* allocate memory */
+    if ( NULL == (returnIm = cpl_image_new(1, spectrum->n_elements,
+                                           CPL_TYPE_FLOAT)) )
+    {
+        sinfo_msg_error(" no spectrum given!\n") ;
+        sinfo_new_destroy_vector(spectrum) ;
+        return NULL ;
+    }
+
+    podata=cpl_image_get_data_float(returnIm);
+    for ( i = 0 ; i < spectrum->n_elements ; i++ )
+    {
+        podata[i] = spectrum -> data[i] ;
+    }
+
+    sinfo_new_destroy_vector (spectrum) ;
+    return returnIm ;
+}
+
+/**
+ at brief converts a fits image to a spectral sinfo_vector
+ at name sinfo_new_image_to_vector()
+ at param 1-D Fits image that should be converted to a spectral sinfo_vector
+ at return spectral sinfo_vector with length ly 
+ at note input image is destroyed
+*/
+
+Vector * sinfo_new_image_to_vector( cpl_image * spectrum )
+{
+    Vector * returnVector ;
+    int i ;
+    int ilx=0;
+    int ily=0;
+  
+    float* pidata=NULL;
+
+    if ( spectrum == NULL )
+    {
+        sinfo_msg_error(" no spectrum given!") ;
+        return NULL ;
+    }
+    ilx=cpl_image_get_size_x(spectrum);
+    ily=cpl_image_get_size_y(spectrum);
+
+    /* allocate memory */
+    if ( NULL == (returnVector = sinfo_new_vector(ilx*ily)) )
+    {
+        sinfo_msg_error(" cannot allocate memory!") ;
+        cpl_image_delete(spectrum) ;
+        return NULL ;
+    }
+
+    pidata=cpl_image_get_data_float(spectrum);
+    for ( i = 0 ; i < (int) ilx*ily ; i++ )
+    {
+        returnVector -> data[i] = pidata[i] ;
+    }
+
+    cpl_image_delete (spectrum) ;
+    return returnVector ;
+}
+
+/**
+ at brief extracts a spectrum from an image image 
+ at name sinfo_new_extract_spectrum_from_resampled_flat()
+ at param resflat: resampled halogen lamp frame, bad pixel corrected
+ at param loreject, 
+ at param hireject: percentage of extreme low and high intensity values
+                 to be rejected from averaging
+ at return fits image that contains the final halogen lamp spectrum
+ at doc builds one spectrum in a fits image out of a resampled flatfield 
+     frame by taking a clean mean along the spatial pixels
+*/
+
+cpl_image * 
+sinfo_new_extract_spectrum_from_resampled_flat( cpl_image * resflat,
+                                             float      loreject,
+                                             float      hireject ) 
+{
+    cpl_image * retIm ;
+    int col, row ;
+    int n ;
+    float* array=NULL ;
+    float cleanMean ;
+    Vector * spectrum ;
+
+    int ilx=0;
+    int ily=0;
+  
+    float* pidata=NULL;
+  
+    if ( resflat == NULL )
+    {
+        sinfo_msg_error(" no flatfield given!") ;
+        return NULL ;
+    }
+    ilx=cpl_image_get_size_x(resflat);
+    ily=cpl_image_get_size_y(resflat);
+
+    /* allocate memory */
+    if ( NullVector == (spectrum = sinfo_new_vector(ily) ) )
+    {
+        sinfo_msg_error(" could not allocate memory!") ;
+        return NULL ;
+    }
+
+    array=cpl_calloc(ily,sizeof(float)) ;
+
+    pidata=cpl_image_get_data_float(resflat);
+    for ( row = 0 ; row < ily ; row++ )
+    {
+        n = 0 ;
+        for ( col = 0 ; col < ilx ; col++ )
+        {
+            if ( !isnan(pidata[col + row*ilx]) )
+            {
+                array[n] = pidata[col+row*ilx] ;
+                n++ ;
+            }
+        }
+        if ( n == 0 )
+        {
+            sinfo_msg_warning(" only bad pixels in row: %d!", row) ;
+            cleanMean = ZERO ;
+        }
+        else
+        {
+            if ( FLT_MAX == (cleanMean = sinfo_new_clean_mean(array, n, 
+                                                              loreject, 
+                                                              hireject)) )
+            {
+                sinfo_msg_error(" could not do sinfo_clean_mean!") ;
+                sinfo_new_destroy_vector(spectrum) ;
+                return NULL ;
+            }
+        }
+        spectrum->data[row] = cleanMean ; 
+    }
+    if ( NULL == ( retIm = sinfo_new_vector_to_image( spectrum ) ) )
+    {
+        sinfo_msg_error(" could not do sinfo_vectorToImage!") ;
+        sinfo_new_destroy_vector(spectrum) ;
+        return NULL ;
+    }
+    cpl_free(array) ;
+
+    return retIm ;
+}
+
+/**
+ at brief multiplies a resampled image with a resampled spectrum in the 
+       same spectral range
+ at name sinfo_new_multiply_image_with_spectrum()
+ at param image: resampled image
+ at param spectrum: resampled spectrum in image format
+ at return resulting image
+ at doc
+multiplys a resampled image with a resampled spectrum (calibrated halogen lamp
+spectrum) in the same spectral range that means all image columns are 
+multiplied with the same spectrum
+ */
+
+cpl_image * 
+sinfo_new_multiply_image_with_spectrum( cpl_image * image, 
+                                        cpl_image * spectrum )
+{
+    int col, row ;
+    cpl_image * retImage ;
+
+
+    int ilx=0;
+    int ily=0;
+    int slx=0;
+    int sly=0;
+
+    float* pidata=NULL;
+    float* psdata=NULL;
+    float* podata=NULL;
+
+
+    if ( image == NULL )
+    {
+        sinfo_msg_error(" no image given!") ;
+        return NULL ;
+    }
+    ilx=cpl_image_get_size_x(image);
+    ily=cpl_image_get_size_y(image);
+
+    if ( spectrum == NULL )
+    {
+        sinfo_msg_error(" no spectrum image given!") ;
+        return NULL ;
+    }
+    slx=cpl_image_get_size_x(spectrum);
+    sly=cpl_image_get_size_y(spectrum);
+
+    if ( sly != ily )
+    {
+        sinfo_msg_error(" images are not compatible in pixel length!") ;
+        return NULL ;
+    }
+
+    if ( NULL == (retImage = cpl_image_duplicate(image)) )
+    {
+        sinfo_msg_error(" could not copy original image!\n") ;
+        return NULL ;
+    }
+
+    pidata=cpl_image_get_data_float(image);
+    psdata=cpl_image_get_data_float(spectrum);
+    podata=cpl_image_get_data_float(retImage);
+
+    for ( col = 0 ; col < ilx ; col++ )
+    {
+        for ( row = 0 ; row < ily ; row++ )
+        {
+            if ( !isnan(pidata[col+row*ilx]) &&
+                 !isnan(psdata[col+row*ilx]))
+            {
+                podata[col+row*ilx] = pidata[col+row*ilx] * psdata[row] ;
+                                                   
+            }
+        }
+    }
+    return retImage ;
+}
+
+/**
+ at brief does the optimal extraction of a standard star spectrum
+ at name sinfo_new_optimal_extraction_from_cube()
+ at param cube: input data cube
+ at param llx, 
+ at param lly: lower left sinfo_edge points of the 2d Gaussian fitting box
+ at param halfbox_x, 
+ at param halfbox_y: half width of a box inside which a 
+                  2D-Gaussian fit is carried out
+ at param fwhm_factor: factor applied to the found fwhms of a 2D-Gaussian
+                    fit, defines the radius of the aperture inside which the 
+                    spectral extraction is carried out (default: 0.6).
+ at param backvariance: (readnoise^2 + sinfo_dark current variance) 
+                     needed to determine 
+                     the noise variance of the background. Must be given
+                     in counts/sec.
+ at param sky:         estimated sky variance in counts/sec
+ at param gain:        conversion factor electrons/count
+ at param exptime:     total exposure time
+ at return resulting spectrum stored in a 1D-image
+ at doc does the optimal extraction of a standard star spectrum according 
+  to the equation:
+S = sum { (P^2 / V) * (I - B) / P } / sum{ P^2 / V } 
+S: spectral flux at a particular wavelength
+P: normalized PSF (determined by a 2D-Gaussian fit)
+I: pixel value
+B: background pixel value determined by the background 
+   parameter of the 2D-Gaussian fit
+V: estimated variance of a pixel: V = [R^2 + D + sky + I,c/exptime]/gain
+   where R is the read noise, and D the sinfo_dark current variance.
+   backvariance is R^2 + D in counts/sec. 
+   I,c is the source intensity in counts
+ at note: sigma,e[e-] = gain[e/count] * sigma,c [counts] = sqrt(I,e) = 
+       sqrt(gain*I,c)
+       => V,c = sigma,c^2 = sigma,e^2/gain^2 
+       => sigma,c = sqrt(I,c/gain) => V,c = I,c/gain
+ */
+
+cpl_image * sinfo_new_optimal_extraction_from_cube( cpl_imagelist * cube, 
+                                      int       llx,
+                                      int       lly,
+                                      int       halfbox_x, 
+                                      int       halfbox_y,
+                                      float     fwhm_factor,
+                                      float     backvariance,
+                                      float     sky,
+                                      float     gain,
+                                      float     exptime,
+                                      const char* name,
+                                      cpl_table** spectrum,
+                      int       qc_info,
+                                      int*      check2)
+{
+    int col, row, z ;
+    cpl_image * averagedIm ; 
+    cpl_image * retIm ;
+    double fit_par[7] ;
+    double derv_par[7] ;
+    int mpar[7] ;
+    double gfit_par[7] ;
+    double gderv_par[7] ;
+    int gmpar[7] ;
+    int fitInd ;
+    int i ;
+    double sum ;
+    double** weight=NULL ;
+    double** sinfo_psf=NULL ;
+
+    double variance ;
+    double xdat[2] ;
+    float weighted_sum ;
+    float counts_tot ;
+    float counts_bkg ;
+    float bkg_tot ;
+
+
+    int first_col, last_col ;
+    int first_row, last_row ;
+    float norm ;
+    float sum_psf=0;
+    float sum_wgt=0;
+    float cenpix = 0;
+    float cenLambda = 0;
+    float dispersion = 0;
+    float lambda=0;
+    float lambda_start=0;
+
+    int ilx=0;
+    int ily=0;
+    int inp=0;
+    float* pidata=NULL;
+    float* padata=NULL;
+    float* podata=NULL;
+    float tmp_val=0;
+    cpl_propertylist* plist=NULL;
+    cpl_image* i_img=NULL;
+
+
+    /* TODO: the sky here is not really used. We remove compilation warning */
+    sky=0;
+
+    if ( NULL == cube )
+    {
+        sinfo_msg_error(" no cube given!\n") ;
+        return NULL ;
+    }
+
+
+    ilx=cpl_image_get_size_x(cpl_imagelist_get(cube,0));
+    ily=cpl_image_get_size_y(cpl_imagelist_get(cube,0));
+    inp=cpl_imagelist_get_size(cube);
+
+    if ( llx < 0 || llx + 2*halfbox_x >= ilx || 
+         lly < 0 || lly + 2*halfbox_y >= ily )
+    {
+      sinfo_msg("llx=%d, lly=%d,  llx + 2*halfbox_x=%d, "
+                "lly + 2*halfbox_y=%d",
+                llx,lly,llx + 2*halfbox_x,lly + 2*halfbox_y);
+      sinfo_msg("tresh_min_x=%d, tresh_min_y=%d, "
+                "tresh_max_x=%d, tresh_max_y=%d",0,0,ilx,ily);
+        sinfo_msg_error(" lower left sinfo_edge points wrong position!") ;
+        return NULL ;
+    }
+    if ( halfbox_x <= 0 || halfbox_y <= 0 || 
+         2*halfbox_x > ilx || 2*halfbox_y > ily )
+    {
+        sinfo_msg_error(" wrong halfbox width given!") ;
+        return NULL ;
+    }
+    if ( fwhm_factor <= 0. )
+    {
+        sinfo_msg_error(" wrong fwhm_factor given!") ;
+        return NULL ;
+    }
+    if ( backvariance < 0. )
+    {
+        sinfo_msg_error(" wrong backvariance given!") ;
+        return NULL ;
+    }
+    if ( exptime <= 0. || exptime == FLAG )
+    {
+        sinfo_msg_error(" wrong exposure time given!") ;
+        return NULL ;
+    }
+
+    /* allocate memory for spectrum */
+    if ( NULL == (retIm = cpl_image_new(1, inp,CPL_TYPE_FLOAT)) )
+    {
+        sinfo_msg_error(" memory allocation failed!\n") ;
+        return NULL ;
+    }
+    /* collapse the cube to be able to compute the weights 
+       for optimal extraction */
+    if ( NULL == (averagedIm = sinfo_new_average_cube_to_image(cube)) )
+    {
+        sinfo_msg_error(" sinfo_averageCubeToImage failed!") ;
+        cpl_image_delete(retIm) ;
+        return NULL ;
+    }
+
+    /* call the 2D-Gaussian fit routine */
+    for ( i = 0 ; i < 7 ; i++ )
+    {
+        mpar[i] = 1 ;
+    }
+
+    if ( -1 == (fitInd = sinfo_new_fit_2d_gaussian(averagedIm,
+                                                   fit_par,
+                                                   derv_par,
+                                                   mpar,
+                                                   llx,
+                                                   lly,
+                                                   halfbox_x,
+                                                   halfbox_y,
+                                                   check2 )) )
+    {
+        sinfo_msg_warning("sinfo_fit2dGaussian failed!") ;
+        cpl_image_delete(retIm) ;
+        cpl_image_delete(averagedIm) ;
+        return NULL ;
+    }
+
+    /* determine the PSF by using the found 2D-Gaussian */
+    sinfo_psf=sinfo_new_2Ddoublearray(ilx,ily) ;
+    sum = 0 ;
+    for ( row = 0 ; row < ily ; row++ )
+    {
+        for ( col = 0 ; col < ilx ; col++ )
+        {
+            xdat[0] = (double) col ;
+            xdat[1] = (double) row ;
+            sinfo_psf[col][row] = sinfo_new_gaussian_ellipse(xdat,fit_par) - 
+                                  fit_par[3] ;
+            sum += sinfo_psf[col][row] ;
+        }
+    }
+    /* Scale the PSF and determine the pixel variances and the 
+       normalization factor */
+    norm = 0. ;
+    variance = 0. ;
+    sum_psf=0;
+
+    weight=sinfo_new_2Ddoublearray(ilx,ily) ;
+
+    padata=cpl_image_get_data_float(averagedIm);
+    for ( row = 0 ; row < ily ; row++ )
+    {
+        for ( col = 0 ; col < ilx ; col++ )
+        {
+            sinfo_psf[col][row] /= sum ;
+        sum_psf +=  sinfo_psf[col][row];
+            if ( !isnan(padata[col+row*ilx]) )
+            {
+          /*
+                variance = (backvariance + sky + padata[col+row*ilx] / 
+                            exptime) / gain ;
+          */
+                variance = padata[col+row*ilx] / gain ;
+
+            }
+            else 
+            {
+                weight[col][row] = 0. ;
+            }
+            if (variance == 0.)
+            {
+                weight[col][row] = 0. ;
+            }
+            else
+            {
+         
+                weight[col][row] = sinfo_psf[col][row]/variance ;
+           
+                norm += weight[col][row] * weight[col][row] * variance ;
+
+            }
+        
+        }
+    }
+
+    sum_wgt=0;
+    for ( row = 0 ; row < ily ; row++ )
+    {
+        for ( col = 0 ; col < ilx ; col++ )
+        {
+      weight[col][row] /= norm;
+          sum_wgt += weight[col][row]*sinfo_psf[col][row];
+    }
+    }
+    sinfo_msg_debug("sum_psf=%f sum_wgt=%f norm=%f",sum_psf,sum_wgt,norm);
+    cpl_image_delete(averagedIm) ;
+    if ( norm == 0. )
+    {
+        sinfo_msg_error(" normalization sum is zero\n") ;
+        cpl_image_delete(retIm) ;
+        return NULL ;
+    }
+
+    /* limit the extraction region to the Gaussian, center +- fwhmx/y * 
+                 cos(theta)  */
+    /*
+    sinfo_msg("fit_par: %f %f %f %f %f %f %f", 
+              fit_par[0],fit_par[1],fit_par[2],fit_par[3],
+              fit_par[4],fit_par[5],fit_par[6]);
+    sinfo_msg("fwhm_factor=%f",fwhm_factor);
+    */
+
+    if(fabs(fit_par[6]) > PI_NUMB/4) {
+      fit_par[6]=0;
+    }
+    first_col = (int) (fit_par[0] - 
+                       fwhm_factor*fit_par[4]*cos((double)fit_par[6])) ;
+    first_col = (first_col > 2 ) ? first_col : 2;
+
+    last_col =  (int) (fit_par[0] + 
+                       fwhm_factor*fit_par[4]*cos((double)fit_par[6])) ;
+    last_col = (last_col < 63 ) ? last_col : 63;
+
+    first_row = (int) (fit_par[1] - 
+                       fwhm_factor*fit_par[5]*cos((double)fit_par[6])) ;
+    first_row = (first_row > 2 ) ? first_row : 2;
+    last_row =  (int) (fit_par[1] + 
+                       fwhm_factor*fit_par[5]*cos((double)fit_par[6])) ;
+    last_row = (last_row < 63 ) ? last_row : 63;
+
+    
+    if(first_col > last_col) {
+      tmp_val=last_col;
+      last_col=first_col;
+      first_col=tmp_val;
+    }
+
+    if(first_row > last_row) {
+      tmp_val=last_row;
+      last_col=first_row;
+      first_col=tmp_val;
+    }
+    if(abs(first_col- last_col) < 1) {
+      first_col -=1;
+      last_col +=1;
+    }
+    if(abs(first_row- last_row) < 1) {
+      first_row -=1;
+      last_row +=1;
+    }
+
+    if ( first_col < 0 || first_row < 0 || last_col >= ilx || last_row >= ily )
+    {
+        sinfo_msg_error(" star badly centered in FOV!") ;
+        cpl_image_delete(retIm) ;
+        return NULL ;
+    }
+
+
+    cpl_table_new_column(*spectrum,"wavelength", CPL_TYPE_FLOAT);
+    /* cpl_table_new_column(*spectrum,"intensity" , CPL_TYPE_FLOAT); */
+    cpl_table_new_column(*spectrum,"counts_tot" , CPL_TYPE_FLOAT);
+    cpl_table_new_column(*spectrum,"counts_bkg" , CPL_TYPE_FLOAT);
+    cpl_table_new_column(*spectrum,"bkg_tot" , CPL_TYPE_FLOAT);
+
+    if(qc_info==1) {
+       cpl_table_new_column(*spectrum,"AMP" , CPL_TYPE_FLOAT);
+       cpl_table_new_column(*spectrum,"XC" , CPL_TYPE_FLOAT);
+       cpl_table_new_column(*spectrum,"YC" , CPL_TYPE_FLOAT);
+       cpl_table_new_column(*spectrum,"BKG" , CPL_TYPE_FLOAT);
+       cpl_table_new_column(*spectrum,"FWHMX" , CPL_TYPE_FLOAT);
+       cpl_table_new_column(*spectrum,"FWHMY" , CPL_TYPE_FLOAT);
+       cpl_table_new_column(*spectrum,"ANGLE" , CPL_TYPE_FLOAT);
+    }
+    plist=cpl_propertylist_load(name,0);
+    cenpix = sinfo_pfits_get_crpix3(plist);
+    cenLambda = sinfo_pfits_get_crval3(plist);
+    dispersion = sinfo_pfits_get_cdelt3(plist);
+    cpl_propertylist_delete(plist);
+    lambda_start=cenLambda-cenpix*dispersion;
+
+    sinfo_msg_debug("frow %d lrow %d fcol %d lcol %d",
+                     first_row, last_row, first_col, last_col);
+    /* go through the planes */
+    podata=cpl_image_get_data_float(retIm);
+    for ( z = 0 ; z < inp ; z++ )
+    {
+      i_img=cpl_imagelist_get(cube,z);
+      pidata=cpl_image_get_data_float(i_img);
+        weighted_sum = 0. ;
+        counts_tot=0.;
+        counts_bkg=0.;
+
+        bkg_tot=0.;
+
+        if(qc_info==1) {
+           sinfo_new_fit_2d_gaussian(i_img,gfit_par,
+                                     gderv_par,gmpar,llx,lly,
+                                     halfbox_x,halfbox_y,check2);
+    }
+
+        for ( row = first_row ; row <= last_row ; row++ )
+        {
+            for ( col = first_col ; col < last_col ; col++ )
+            {
+                if ( !isnan(pidata[col+row*ilx]) )
+                {
+          
+                    weighted_sum += weight[col][row] * (pidata[col+row*ilx] - 
+                                    fit_par[3]);
+            
+                    counts_bkg += (pidata[col+row*ilx] - fit_par[3]);
+                    counts_tot += (pidata[col+row*ilx]);
+                    bkg_tot += fit_par[3];
+            
+                } 
+            }
+        }    
+
+        if (weighted_sum == 0.)
+        {
+            weighted_sum = ZERO ;
+            counts_tot = ZERO;
+            counts_bkg = ZERO;
+            bkg_tot = ZERO;
+
+        }
+        else
+        {
+      /*
+            weighted_sum /= norm ;
+      */
+      
+      
+        }
+
+        podata[z] = weighted_sum ;
+        lambda=lambda_start+z*dispersion;
+        cpl_table_set_float(*spectrum,"wavelength" ,z,lambda);
+        /* cpl_table_set_float(*spectrum,"intensity" ,z,weighted_sum); */
+        cpl_table_set_float(*spectrum,"counts_tot" ,z,counts_tot);
+        cpl_table_set_float(*spectrum,"counts_bkg" ,z,counts_bkg);
+        cpl_table_set_float(*spectrum,"bkg_tot" ,z,bkg_tot);
+        sinfo_msg_debug("w=%f I=%f b=%f a=%f",
+                         lambda,counts_tot,counts_bkg,bkg_tot);
+        if(qc_info==1) {
+           cpl_table_set_float(*spectrum,"AMP" ,z,gfit_par[0]);
+           cpl_table_set_float(*spectrum,"XC" ,z,gfit_par[1]);
+           cpl_table_set_float(*spectrum,"YC" ,z,gfit_par[2]);
+           cpl_table_set_float(*spectrum,"BKG" ,z,gfit_par[3]);
+           cpl_table_set_float(*spectrum,"FWHMX" ,z,gfit_par[4]);
+           cpl_table_set_float(*spectrum,"FWHMY" ,z,gfit_par[5]);
+           cpl_table_set_float(*spectrum,"ANGLE" ,z,gfit_par[6]);
+    }
+
+    }
+
+    sinfo_new_destroy_2Ddoublearray(&sinfo_psf,ilx) ;
+    sinfo_new_destroy_2Ddoublearray(&weight,ilx) ;
+
+    return retIm ;
+}
+
+/**
+ at brief extracts a sky spectrum from a data cube
+ at name sinfo_new_extract_sky_from_cube()
+ at param cube: reduced cube from sky spider observation
+ at param loReject, 
+ at param hiReject: fraction (percentage) of the extreme high and low
+                 sky spectrum values that are rejected before 
+                 averaging the found sky spectra.
+ at param position: end pixel positions of the straight line in the image
+                 dividing the sky from the object pixels.
+ at param tolerance: pixel tolerance which are not considered and subtracted from
+                  the diagonal line to be sure to get a clean sky, default: 2  
+ at param posindicator: indicates in which sinfo_edge of the field of view 
+                     the sky is projected. output of 
+                     spiffi_get_spiderposindex() in fitshead.c
+ at return resulting averaged sky spectrum
+ at doc extracts a sky spectrum from a reduced sky spider observation, that means 
+     from a data cube. Therefore, the position of the sky within the field of 
+     view must be first read from the fits header. A pixel tolerance is 
+     subtracted. The found sky spectra are averaged by rejecting the extreme 
+     high and low values.
+*/
+
+Vector * sinfo_new_extract_sky_from_cube( cpl_imagelist * cube,
+                             float     loReject,
+                             float     hiReject,
+                             int     * position,
+                             int       tolerance,
+                             int       posindicator )
+{
+    Vector * spectrum ;
+    int x, y, z ;
+    int n ;
+    int n_sky ;
+    int x_low , x_high ;
+    int y_low , y_high ;
+    int hi_x, lo_x ;
+    float * to_average ;
+    float   cleanMean ;
+
+    int ilx=0;
+    int ily=0;
+    int inp=0;
+    float* pidata=NULL;
+    cpl_image* i_img=NULL;
+
+
+    ilx=cpl_image_get_size_x(cpl_imagelist_get(cube,0));
+    ily=cpl_image_get_size_y(cpl_imagelist_get(cube,0));
+    inp=cpl_imagelist_get_size(cube);
+
+    if ( NULL == cube )
+    {
+        sinfo_msg_error(" no cube given!\n") ;
+        return NullVector ;
+    }
+    if ( loReject < 0. || hiReject < 0. || loReject + hiReject >= 90. )
+    {
+        sinfo_msg_error("wrong or unrealistic loReject and hiReject values!") ;
+        return NullVector ;
+    }
+    if ( position == NULL)
+    {
+        sinfo_msg_error(" no position array given!") ;
+        return NullVector ;
+    }
+    if ( position[0] < 0 || position[1] < 0 || 
+         position[0] > ilx  || position[1] > ily )
+    {
+        sinfo_msg_error(" wrong position of sky spider!") ;
+        return NullVector ;
+    }
+    if ( tolerance < 0 || tolerance >= ilx )
+    {
+        sinfo_msg_error(" wrong tolerance given!") ;
+        return NullVector ;
+    }
+    if ( posindicator == 0 )
+    {
+        sinfo_msg_error(" no sinfo_edge indicator given!") ;
+        return NullVector ;
+    }
+
+    /* determine the edge of the image where the sky spectra are placed */
+    switch(posindicator)
+    {
+        /* lower right sinfo_edge */
+        case 1:
+            x_low  = position[0] + tolerance ;
+            x_high = ilx ;
+            y_low  = 0 ;
+            y_high = position[1] - tolerance ;
+            break ;
+        /* upper right sinfo_edge */
+        case 2:
+            x_low  = position[0] + tolerance ;
+            x_high = ilx ;
+            y_low  = position[1] + tolerance ;
+            y_high = ily ;
+            break ;
+        /* upper left sinfo_edge */
+        case 3:
+            x_low  = 0 ;
+            x_high = position[0] - tolerance ;
+            y_low  = position [1] + tolerance ;
+            y_high = ily ;
+            break ;
+        default:
+            sinfo_msg_error(" wrong position indicator index!") ;
+            return NullVector ;
+            break ;
+    }
+    if ( x_low >= ilx || x_high < 1 || y_low >= ily || y_high < 1 )
+    {
+        sinfo_msg_error(" tolerance too high!") ;
+        return NullVector ;
+    }
+    if ( x_high - x_low != y_high - y_low )
+    {
+        sinfo_msg_error(" sky sinfo_edge is not a diagonal line!\n") ;
+        return NullVector ;
+    }
+
+    /* determine the number of sky pixels in one image plane, take only 
+       the full sky pixels which are not cut by the diagonal line */
+    n_sky = (x_high - x_low) * (x_high - x_low - 1) / 2 ;
+    if ( n_sky <= 0 )
+    {
+        sinfo_msg_error(" no sky spectrum in found in cube!") ;
+        return NullVector ;
+    }
+    if ( n_sky == 1 )
+    {
+        sinfo_msg_warning(" only one sky spectrum is taken, no averaging!") ;
+    }
+
+    /* allocate memory for the output spectrum */
+    if ( NullVector == (spectrum = sinfo_new_vector(inp)) )
+    {
+        sinfo_msg_error(" could not allocate memory!") ;
+        return NullVector ;
+    }
+
+    /* go through the image planes */
+    for ( z = 0 ; z < inp ; z++ )
+    {
+      i_img=cpl_imagelist_get(cube,z);
+      pidata=cpl_image_get_data_float(i_img);
+        /* allocate memory for the sky pixels in one image plane */
+        if (NULL == (to_average = (float*) cpl_calloc(n_sky, sizeof (float))))
+        {
+            sinfo_msg_error(" could not allocate memory!") ;
+            sinfo_new_destroy_vector(spectrum) ;
+            return NullVector ;
+        }
+        n = 0 ;
+        switch(posindicator)
+        {
+            /* lower right sinfo_edge */
+            case 1:
+                lo_x = x_low ;
+                for ( y = y_low ; y < y_high - 1 ; y++ )
+                {
+                    lo_x++ ;
+                    for ( x = lo_x ; x < x_high ; x++ )
+                    {
+                        to_average[n] = pidata[x+y*ilx] ;
+                        n++ ;
+                    }
+                }
+                break ;
+            /* lower left sinfo_edge */
+            case 2:
+                hi_x = x_high ;
+                for ( y = y_low ; y < y_high - 1 ; y++ )
+                {
+                    hi_x-- ;
+                    for ( x = x_low ; x < hi_x ; x++ )
+                    {
+                        to_average[n] = pidata[x+y*ilx] ;
+                        n++ ;
+                    }
+                }
+                break ;
+            /* upper right sinfo_edge */
+            case 3:
+                lo_x = x_high ;
+                for ( y = y_low+1 ; y < y_high ; y++ )
+                {
+                    lo_x-- ;
+                    for ( x = lo_x ; x < x_high ; x++ )
+                    {
+                        to_average[n] = pidata[x+y*ilx] ;
+                        n++ ;
+                    }
+                }
+                break ;
+            /* upper left sinfo_edge */
+            case 4:
+                hi_x = x_low ;
+                for ( y = y_low+1 ; y < y_high ; y++ )
+                {
+                    hi_x++ ;
+                    for ( x = x_low ; x < hi_x ; x++ )
+                    {
+                        to_average[n] = pidata[x+y*ilx] ;
+                        n++ ;
+                    }
+                }
+                break ;
+            default:
+                sinfo_msg_error(" wrong position indicator index!\n") ;
+                return NullVector ;
+                break ;
+        }
+        if ( n != n_sky )
+        {
+            sinfo_msg_warning("number of stored sky image pixels does "
+                              "not equal number of computed sky pixels!") ;
+        }
+
+        /* now take a clean mean of the sky "image" */
+        cleanMean = sinfo_new_clean_mean (to_average, n, loReject, hiReject) ;
+        if (cleanMean == FLT_MAX)
+        {
+            sinfo_msg_error(" could not take a clean mean!\n") ;
+            sinfo_new_destroy_vector(spectrum) ;
+            cpl_free(to_average) ;
+            return NullVector ;
+        }
+        spectrum->data[z] = cleanMean ;
+        cpl_free (to_average) ;
+    }
+     
+    return spectrum ;
+}
+
+/**
+ at brief summing routine for a reduced data to get a better spectral S/N only 
+       for a rectangular aperture
+ at name sinfo_new_sum_rectangle_of_cube_spectra()
+ at param cube: 1 allocated cube, 
+ at param llx, 
+ at param lly, 
+ at param urx, 
+ at param ury: lower left and upper right position of rectangle in x-y plane ,
+                                            image coordinates 0...
+ at return result spectrum sinfo_vector
+ */
+
+Vector * sinfo_new_sum_rectangle_of_cube_spectra( cpl_imagelist * cube,
+                                     int llx,
+                                     int lly,
+                                     int urx,
+                                     int ury )
+{
+    Vector          * sum ;
+    pixelvalue      *local_rectangle ;
+    int             i, j, k, l, m ;
+    int             recsize ;
+    int ilx=0;
+    int ily=0;
+    int inp=0;
+    float* pidata=NULL;
+    cpl_image* i_img=NULL;
+
+
+    ilx=cpl_image_get_size_x(cpl_imagelist_get(cube,0));
+    ily=cpl_image_get_size_y(cpl_imagelist_get(cube,0));
+    inp=cpl_imagelist_get_size(cube);
+
+    if ( cube == NULL || inp < 1 )
+    {
+        sinfo_msg_error (" no cube to take the mean of his spectra\n") ;
+        return NullVector ;
+    }
+
+    if ((llx<0) || (llx>=ilx) ||
+        (urx<0) || (urx>=ilx) ||
+        (lly<0) || (lly>=ily) ||
+        (ury<0) || (ury>=ily) ||
+        (llx>=urx) || (lly>=ury))
+    {
+        sinfo_msg_error(" invalid rectangle coordinates:") ;
+        sinfo_msg_error("lower left is [%d %d] upper right is [%d %d]", 
+                         llx, lly, urx, ury) ;
+        return NullVector ;
+    }
+
+    recsize = (urx - llx + 1) * (ury - lly + 1) ;
+
+    /* allocate a new sinfo_vector to store the average spectral values */
+    if (NULL == (sum = sinfo_new_vector (inp)) )
+    {
+        sinfo_msg_error (" cannot allocate a new sinfo_vector") ;
+        return NullVector ;
+    }
+
+    /*------------------------------------------------------------------------
+     *  loop through the cube planes, through the x axis and the y-axis of the
+     *  plane rectangle and store pixel values in a buffer.
+     */
+    for ( i = 0 ; i < inp ; i++ )
+    {
+      i_img=cpl_imagelist_get(cube,i);
+      pidata=cpl_image_get_data_float(i_img);
+        m = 0 ;
+        local_rectangle = (pixelvalue *) cpl_calloc (recsize, 
+                                         sizeof (pixelvalue*));
+
+        for ( j = lly ; j <= ury ; j++ )
+        {
+            for ( k = llx ; k <= urx ; k++ )
+            {
+                local_rectangle[m] = pidata[k + j * ilx] ;
+                m ++ ;
+            }
+        }
+        for ( l = 0 ; l < recsize ; l++ )
+        {
+            if ( isnan(local_rectangle[l]) )
+            {
+                continue ;
+            }
+            sum -> data[i] += local_rectangle[l] ;
+        }
+        cpl_free ( local_rectangle ) ;
+    }
+    return sum ;
+}
+
+/**
+ at brief summing routine for a reduced data to get a better spectral S/N 
+       only for a circular aperture.
+ at name sinfo_new_sum_circle_of_cube_spectra()
+ at param cube: 1 allocated cube, 
+ at param centerx, 
+ at param centery: center pixel of circular aperture in image coordinates
+ at param radius: integer radius of circular aperture
+ at return result spectrum sinfo_vector 
+*/
+
+Vector * sinfo_new_sum_circle_of_cube_spectra( cpl_imagelist * cube,
+                                  int       centerx,
+                                  int       centery,
+                                  int       radius )
+{
+    Vector          * sum ;
+    pixelvalue      * circle ;
+    int             i, j, k, l, m, n ;
+    int             circsize ;
+    int ilx=0;
+    int ily=0;
+    int inp=0;
+    float* pidata=NULL;
+    cpl_image* i_img=NULL;
+
+
+    ilx=cpl_image_get_size_x(cpl_imagelist_get(cube,0));
+    ily=cpl_image_get_size_y(cpl_imagelist_get(cube,0));
+    inp=cpl_imagelist_get_size(cube);
+
+    if ( cube == NULL || inp < 1 )
+    {
+        sinfo_msg_error (" no cube to take the mean of his spectra\n") ;
+        return NullVector ;
+    }
+
+    if ((centerx+radius>=ilx) ||
+        (centery+radius>=ily) ||
+        (centerx-radius<0) ||
+        (centery-radius<0))
+    {
+        sinfo_msg_error(" invalid circular coordinates") ;
+        return NullVector ;
+    }
+
+    n = 0 ;
+    for ( j = centery - radius ; j <= centery + radius ; j++ )
+    {
+        for ( k = centerx - radius ; k <= centerx + radius ; k++ )
+        {
+            if ( (k-centerx)*(k-centerx)+(j-centery)*(j-centery) <= 
+                           radius*radius )
+            {
+                n ++ ;
+            }
+        }
+    }
+    if (n == 0)
+    {
+        sinfo_msg_error (" no data points found!") ;
+        return NullVector ;
+    }
+    circsize = n ;
+
+    /* allocate a new sinfo_vector to store the average spectral values */
+    if (NULL == (sum = sinfo_new_vector (inp)) )
+    {
+        sinfo_msg_error ("  cannot allocate a new sinfo_vector") ;
+        return NullVector ;
+    }
+
+    /*------------------------------------------------------------------------
+     *  loop through the cube planes, through the x axis and the y-axis of the
+     *  plane circle and store pixel values in a buffer.
+     */
+    for ( i = 0 ; i < inp ; i++ )
+    {
+      i_img=cpl_imagelist_get(cube,i);
+      pidata=cpl_image_get_data_float(i_img);
+        m = 0 ;
+        circle = (pixelvalue *) cpl_calloc (circsize, sizeof (pixelvalue*));
+
+        for ( j = centery - radius ; j <= centery + radius ; j++ )
+        {
+            for ( k = centerx - radius ; k <= centerx + radius ; k++ )
+            {
+                if ( (k-centerx)*(k-centerx)+(j-centery)*(j-centery) <= 
+                     radius*radius )
+                {
+                    circle[m] = pidata[k + j * ilx] ;
+                    m ++ ;
+                }
+            }
+        }
+
+        for ( l = 0 ; l < circsize ; l++ )
+        {
+            if ( isnan(circle[l]) )
+            {
+                continue ;
+            }
+            sum -> data[i] += circle[l] ;
+        }
+        cpl_free (circle) ;
+    }
+    return sum ;
+}
+
+/**
+ at brief averaging routine for a reduced data to get a better 
+       spectral S/N only for a rectangular aperture.
+ at name sinfo_new_mean_rectangle_of_cube_spectra()
+ at param cube: 1 allocated cube, 
+ at param llx, 
+ at param lly, 
+ at param urx, 
+ at param ury: lower left and upper right position of rectangle in x-y plane ,
+            image coordinates 0...
+ at return result spectrum sinfo_vector 
+*/
+
+Vector * sinfo_new_mean_rectangle_of_cube_spectra( cpl_imagelist * cube,
+                                     int llx,
+                                     int lly,
+                                     int urx,
+                                     int ury )
+{
+    Vector          * mean ;
+    pixelvalue      *local_rectangle ;
+    int             i, j, k, l, m ;
+    int             recsize, nv ;
+    int ilx=0;
+    int ily=0;
+    int inp=0;
+    float* pidata=NULL;
+    cpl_image* i_img=NULL;
+
+
+    ilx=cpl_image_get_size_x(cpl_imagelist_get(cube,0));
+    ily=cpl_image_get_size_y(cpl_imagelist_get(cube,0));
+    inp=cpl_imagelist_get_size(cube);
+
+    if ( cube == NULL || inp < 1 )
+    {
+        sinfo_msg_error ("  no cube to take the mean of his spectra\n") ;
+        return NullVector ;
+    }
+
+    if ((llx<0) || (llx>=ilx) ||
+        (urx<0) || (urx>=ilx) ||
+        (lly<0) || (lly>=ily) ||
+        (ury<0) || (ury>=ily) ||
+        (llx>=urx) || (lly>=ury))
+    {
+        sinfo_msg_error("  invalid rectangle coordinates:") ;
+        sinfo_msg_error("lower left is [%d %d] upper right is [%d %d]",
+                 llx, lly, urx, ury) ;
+        return NullVector ;
+    }
+
+    recsize = (urx - llx + 1) * (ury - lly + 1) ;
+
+    /* allocate a new sinfo_vector to store the average spectral values */
+    if (NULL == (mean = sinfo_new_vector (inp)) )
+    {
+        sinfo_msg_error (" cannot allocate a new sinfo_vector") ;
+        return NullVector ;
+    }
+
+    /*------------------------------------------------------------------------
+     *  loop through the cube planes, through the x axis and the y-axis of the
+     *  plane rectangle and store pixel values in a buffer.
+     */
+    for ( i = 0 ; i < inp ; i++ )
+    {
+      i_img=cpl_imagelist_get(cube,i);
+      pidata=cpl_image_get_data_float(i_img);
+        m = 0 ;
+        local_rectangle = (pixelvalue *) cpl_calloc (recsize, 
+                           sizeof (pixelvalue*));
+
+        for ( j = lly ; j <= ury ; j++ )
+        {
+            for ( k = llx ; k <= urx ; k++ )
+            {
+                local_rectangle[m] = pidata[k + j * ilx] ;
+                m ++ ;
+            }
+        }
+        nv = 0 ;
+        for ( l = 0 ; l < recsize ; l++ )
+        {
+            if ( isnan(local_rectangle[l]) )
+            {
+                continue ;
+            }
+            mean -> data[i] += local_rectangle[l] ;
+            nv ++;
+        }
+        if ( nv == 0 )
+        {
+            mean -> data[i] = ZERO ;
+        }
+        else
+        {
+            mean -> data[i] /= nv ;
+        }
+        cpl_free ( local_rectangle ) ;
+    }
+    return mean ;
+}
+
+/**
+ at brief averaging routine for a reduced data to get a better 
+       spectral S/N only for a circular aperture.
+ at name sinfo_new_mean_circle_of_cube_spectra()
+ at param cube: 1 allocated cube, 
+ at param centerx, 
+ at param centery: center pixel of circular aperture in image coordinates
+ at param radius: integer radius of circular aperture
+ at return result spectrum sinfo_vector
+*/
+
+Vector * 
+sinfo_new_mean_circle_of_cube_spectra( cpl_imagelist * cube,
+                                  int       centerx,
+                                  int       centery,
+                                  int       radius )
+{
+    Vector          * mean ;
+    pixelvalue      * circle ;
+    int             i, j, k, l, m, n ;
+    int             circsize, nv ;
+    int ilx=0;
+    int ily=0;
+    int inp=0;
+    float* pidata=NULL;
+    cpl_image* i_img=NULL;
+
+
+    ilx=cpl_image_get_size_x(cpl_imagelist_get(cube,0));
+    ily=cpl_image_get_size_y(cpl_imagelist_get(cube,0));
+    inp=cpl_imagelist_get_size(cube);
+
+    if ( cube == NULL || inp < 1 )
+    {
+        sinfo_msg_error ("no cube to take the mean of his spectra") ;
+        return NullVector ;
+    }
+
+    if ((centerx+radius>=ilx) ||
+        (centery+radius>=ily) ||
+        (centerx-radius<0) ||
+        (centery-radius<0))
+    {
+        sinfo_msg_error(" invalid circular coordinates") ;
+        return NullVector ;
+    }
+
+    n = 0 ;
+    for ( j = centery - radius ; j <= centery + radius ; j++ )
+    {
+        for ( k = centerx - radius ; k <= centerx + radius ; k++ )
+        {
+            if ( (k-centerx)*(k-centerx)+(j-centery)*(j-centery) <= 
+                 radius*radius )
+            {
+                n ++ ;
+            }
+        }
+    }
+    if (n == 0)
+    {
+        sinfo_msg_error (" no data points found!\n") ;
+        return NullVector ;
+    }
+    circsize = n ;
+
+    /* allocate a new sinfo_vector to store the average spectral values */
+    if (NULL == (mean = sinfo_new_vector (inp)) )
+    {
+        sinfo_msg_error (" cannot allocate a new sinfo_vector \n") ;
+        return NullVector ;
+    }
+
+    /*------------------------------------------------------------------------
+     *  loop through the cube planes, through the x axis and the y-axis of the
+     *  plane circle and store pixel values in a buffer.
+     */
+    for ( i = 0 ; i < inp ; i++ )
+    {
+      i_img=cpl_imagelist_get(cube,i);
+      pidata=cpl_image_get_data_float(i_img);
+        m = 0 ;
+        circle = (pixelvalue *) cpl_calloc (circsize, sizeof (pixelvalue*));
+
+        for ( j = centery - radius ; j <= centery + radius ; j++ )
+        {
+            for ( k = centerx - radius ; k <= centerx + radius ; k++ )
+            {
+                if ( (k-centerx)*(k-centerx)+(j-centery)*(j-centery) <= 
+                     radius*radius )
+                {
+                    circle[m] = pidata[k + j * ilx] ;
+                    m ++ ;
+                }
+            }
+        }
+
+        nv = 0 ;
+        for ( l = 0 ; l < circsize ; l++ )
+        {
+            if ( isnan(circle[l]) )
+            {
+                continue ;
+            }
+            mean -> data[i] += circle[l] ;
+            nv ++;
+        }
+        if ( nv == 0 )
+        {
+            mean -> data[i] = ZERO ;
+        }
+        else
+        {
+            mean -> data[i] /= nv ;
+        }
+
+        cpl_free (circle) ;
+    }
+    return mean ;
+}
+
+/**
+ at brief computes a blackbody spectral intensity 
+       distribution (W/(m^2 lambda ster)) 
+ at name sinfo_new_blackbody_spectrum()
+ at param templateSpec: spectrum of a standard star (1-d image with fits header)
+ at param temp: blackbody temperature in Kelvin (standard Star temp), 
+ at return resulting spectrum sinfo_vector 
+*/
+
+Vector * sinfo_new_blackbody_spectrum( char * templateSpec, double temp )
+{
+    Vector * retSpec ;
+    int n ;
+    double cenpix ;
+    int npix ;
+    double cenLambda ;
+    double firstLambda ;
+    double disp ;
+    double lambda ;
+    double intens ;
+    double denom ;
+    double norm ;
+    cpl_propertylist* plist=NULL;
+
+    if ( NULL == templateSpec )
+    {
+        sinfo_msg_error (" now input image given!\n") ;
+        return NULL ;
+    }
+    if ( temp < 0. )
+    {
+        sinfo_msg_error (" wrong temperature given!\n") ;
+        return NULL ;
+    }
+    /* get the fits header information needed */
+    if ((cpl_error_code)((plist=cpl_propertylist_load(templateSpec,0))==NULL)){
+      sinfo_msg_error( "getting header from frame %s",templateSpec);
+      cpl_propertylist_delete(plist) ;
+      return NULL ;
+    }
+
+
+    cenpix = sinfo_pfits_get_crpix2(plist);
+    if(cpl_error_get_code() != CPL_ERROR_NONE) {
+        sinfo_msg_error (" cannot get CRPIX2\n") ;
+        sinfo_free_propertylist(&plist) ;
+        return NULL ;
+    }
+
+    cenLambda = sinfo_pfits_get_crval2(plist);
+    if(cpl_error_get_code() != CPL_ERROR_NONE) {
+        sinfo_msg_error (" cannot get CRVAL2\n") ;
+        sinfo_free_propertylist(&plist) ;
+        return NULL ;
+    }
+    disp = sinfo_pfits_get_cdelt2(plist);
+    if(cpl_error_get_code() != CPL_ERROR_NONE) {
+        sinfo_msg_error (" cannot get CDELT2\n") ;
+        sinfo_free_propertylist(&plist) ;
+        return NULL ;
+    }
+    npix = sinfo_pfits_get_naxis2(plist);
+    if(cpl_error_get_code() != CPL_ERROR_NONE) {
+        sinfo_msg_error (" cannot get NAXIS2\n") ;
+        sinfo_free_propertylist(&plist) ;
+        return NULL ;
+    }
+    sinfo_free_propertylist(&plist) ;
+
+
+    if (NULL == (retSpec = sinfo_new_vector (npix)))
+    {
+        sinfo_msg_error (" could not allocate memory!\n") ;
+        return NULL ;
+    }
+    
+    /* shift from fits to image coordinates */
+    cenpix-- ;
+  
+    firstLambda = cenLambda - cenpix * disp ;
+    for ( n = 0 ; n < npix ; n++ )
+    {
+        lambda = firstLambda + disp * (double)n ;
+        /* convert from microns to m */
+
+        lambda /= 1.0e6 ;
+        denom = 1./(exp(PLANCK*SPEED_OF_LIGHT/(lambda*BOLTZMANN*temp)) - 1.) ;
+        intens = 2.*PI_NUMB*PLANCK*SPEED_OF_LIGHT*SPEED_OF_LIGHT / 
+                 pow(lambda, 5) * denom ;
+        retSpec->data[n] = intens ;   
+    }
+    norm = retSpec->data[npix/2] ;
+    for ( n = 0 ; n < npix ; n++ )
+    {
+        retSpec->data[n] /= norm ;
+    }
+    
+    return retSpec ;
+}
+
+
+/**
+ at brief sinfo_median routine for a reduced data to get a better 
+       spectral S/N only for a rectangular aperture.
+ at name sinfo_new_median_rectangle_of_cube_spectra()
+ at param cube: 1 allocated cube, 
+ at param llx, 
+ at param lly, 
+ at param urx, 
+ at param ury: lower left and upper right position of rectangle in x-y plane ,
+            image coordinates 0...
+ at return result spectrum sinfo_vector
+*/
+
+Vector * sinfo_new_median_rectangle_of_cube_spectra( cpl_imagelist * cube,
+                                             int llx,
+                                             int lly,
+                                             int urx,
+                                             int ury )
+{
+    Vector          * med ;
+    pixelvalue      *local_rectangle ;
+    int             i, j, k, m ;
+    int             recsize ;
+    int ilx=0;
+    int ily=0;
+    int inp=0;
+    float* pidata=NULL;
+    cpl_image* i_img=NULL;
+
+
+    ilx=cpl_image_get_size_x(cpl_imagelist_get(cube,0));
+    ily=cpl_image_get_size_y(cpl_imagelist_get(cube,0));
+    inp=cpl_imagelist_get_size(cube);
+
+    if ( cube == NULL || inp < 1 )
+    {
+        sinfo_msg_error (" no cube to take the mean of his spectra\n") ;
+        return NullVector ;
+    }
+
+    if ((llx<0) || (llx>=ilx) ||
+        (urx<0) || (urx>=ilx) ||
+        (lly<0) || (lly>=ily) ||
+        (ury<0) || (ury>=ily) ||
+        (llx>=urx) || (lly>=ury))
+    {
+        sinfo_msg_error(" invalid rectangle coordinates:") ;
+        sinfo_msg_error("lower left is [%d %d] upper right is [%d %d]", 
+                        llx, lly, urx, ury) ;
+        return NullVector ;
+    }
+
+    recsize = (urx - llx + 1) * (ury - lly + 1) ;
+
+    /* allocate a new sinfo_vector to store the average spectral values */
+    if (NULL == (med = sinfo_new_vector (inp)) )
+    {
+        sinfo_msg_error (" cannot allocate a new sinfo_vector \n") ;
+        return NullVector ;
+    }
+
+    /*------------------------------------------------------------------------
+     *  loop through the cube planes, through the x axis and the y-axis of the
+     *  plane rectangle and store pixel values in a buffer.
+     */
+    for ( i = 0 ; i < inp ; i++ )
+    {
+
+      i_img=cpl_imagelist_get(cube,i);
+      pidata=cpl_image_get_data_float(i_img);
+      m = 0 ;
+      local_rectangle=(pixelvalue *)cpl_calloc(recsize, sizeof (pixelvalue*));
+
+        for ( j = lly ; j <= ury ; j++ )
+        {
+            for ( k = llx ; k <= urx ; k++ )
+            {
+                if ( isnan(pidata[k+j*ilx]) )
+                {
+                    continue ;
+                }
+                else
+                {
+                    local_rectangle[m] = pidata[k + j * ilx] ;
+                    m ++ ;
+                }
+            }
+        }
+        if ( m == 0 )
+        {
+            med->data[i] = 0. ;
+        }
+        else
+        {
+            med->data[i] = sinfo_new_median(local_rectangle, m) ;
+        }
+        cpl_free ( local_rectangle ) ;
+    }
+    return med ;
+}
+
+/**
+ at brief sinfo_median routine for a reduced data to get a better 
+       spectral S/N only for a circular aperture.
+ at name sinfo_new_median_circle_of_cube_spectra()
+ at param cube: 1 allocated cube, 
+ at param centerx, 
+ at param centery: center pixel of circular aperture in image coordinates
+ at param radius: integer radius of circular aperture
+ at return result spectrum sinfo_vector 
+*/
+
+Vector * sinfo_new_median_circle_of_cube_spectra( cpl_imagelist * cube,
+                                  int       centerx,
+                                  int       centery,
+                                  int       radius )
+{
+    Vector          * med ;
+    pixelvalue      * circle ;
+    int             i, j, k, l, m, n ;
+    int             circsize, nv ;
+    int ilx=0;
+    int ily=0;
+    int inp=0;
+    float* pidata=NULL;
+    cpl_image* i_img=NULL;
+
+
+    ilx=cpl_image_get_size_x(cpl_imagelist_get(cube,0));
+    ily=cpl_image_get_size_y(cpl_imagelist_get(cube,0));
+    inp=cpl_imagelist_get_size(cube);
+
+    if ( cube == NULL || inp < 1 )
+    {
+        sinfo_msg_error (" no cube to take the mean of his spectra\n") ;
+        return NullVector ;
+    }
+
+    if ((centerx+radius>=ilx) ||
+        (centery+radius>=ily) ||
+        (centerx-radius<0) ||
+        (centery-radius<0))
+    {
+        sinfo_msg_error(" invalid circular coordinates") ;
+        return NullVector ;
+    }
+
+    n = 0 ;
+    for ( j = centery - radius ; j <= centery + radius ; j++ )
+    {
+        for ( k = centerx - radius ; k <= centerx + radius ; k++ )
+        {
+            if ( (k-centerx)*(k-centerx)+(j-centery)*(j-centery) <= 
+                  radius*radius )
+            {
+                n ++ ;
+            }
+        }
+    }
+    if (n == 0)
+    {
+        sinfo_msg_error (" no data points found!") ;
+        return NullVector ;
+    }
+    circsize = n ;
+
+    /* allocate a new sinfo_vector to store the average spectral values */
+    if (NULL == (med = sinfo_new_vector (inp)) )
+    {
+        sinfo_msg_error (" cannot allocate a new sinfo_vector") ;
+        return NullVector ;
+    }
+
+    /*------------------------------------------------------------------------
+     *  loop through the cube planes, through the x axis and the y-axis of the
+     *  plane circle and store pixel values in a buffer.
+     */
+    for ( i = 0 ; i < inp ; i++ )
+    {
+      i_img=cpl_imagelist_get(cube,i);
+      pidata=cpl_image_get_data_float(i_img);
+        m = 0 ;
+        circle = (pixelvalue *) cpl_calloc (circsize, sizeof (pixelvalue*));
+
+        for ( j = centery - radius ; j <= centery + radius ; j++ )
+        {
+            for ( k = centerx - radius ; k <= centerx + radius ; k++ )
+            {
+                if ( (k-centerx)*(k-centerx)+(j-centery)*(j-centery) <= 
+                      radius*radius )
+                {
+                    circle[m] = pidata[k + j * ilx] ;
+                    m ++ ;
+                }
+            }
+        }
+
+        nv = 0 ;
+        for ( l = 0 ; l < circsize ; l++ )
+        {
+            if ( isnan(circle[l]) )
+            {
+                continue ;
+            }
+            med -> data[i] += circle[l] ;
+            nv ++;
+        }
+        if ( nv == 0 )
+        {
+            med->data[i] = 0. ;
+        }
+        else
+        {
+            med->data[i] = sinfo_new_median(circle, nv) ; 
+        }
+        cpl_free (circle) ;
+    }
+    return med ;
+}
+
+/**
+ at brief clean averaging routine for a reduced data to get a 
+       better spectral S/N only for a rectangular aperture.
+ at name sinfo_new_cleanmean_rectangle_of_cube_spectra()
+ at param cube: 1 allocated cube, 
+ at param llx, 
+ at param lly, 
+ at param urx, 
+ at param ury: lower left and upper right position of rectangle in x-y plane ,
+            image coordinates 0...
+ at return result spectrum sinfo_vector 
+*/
+
+Vector * 
+sinfo_new_cleanmean_rectangle_of_cube_spectra( cpl_imagelist * cube,
+                                          int llx,
+                                          int lly,
+                                          int urx,
+                                          int ury,
+                                          float lo_reject,
+                                          float hi_reject )
+{
+    Vector          * clean ;
+    pixelvalue      *local_rectangle ;
+    int             i, j, k, m ;
+    int             recsize ;
+    int ilx=0;
+    int ily=0;
+    int inp=0;
+    float* pidata=NULL;
+    cpl_image* i_img=NULL;
+
+
+    ilx=cpl_image_get_size_x(cpl_imagelist_get(cube,0));
+    ily=cpl_image_get_size_y(cpl_imagelist_get(cube,0));
+    inp=cpl_imagelist_get_size(cube);
+
+    if ( cube == NULL || inp < 1 )
+    {
+        sinfo_msg_error (" no cube to take the mean of his spectra\n") ;
+        return NullVector ;
+    }
+
+    if ((llx<0) || (llx>=ilx) ||
+        (urx<0) || (urx>=ilx) ||
+        (lly<0) || (lly>=ily) ||
+        (ury<0) || (ury>=ily) ||
+        (llx>=urx) || (lly>=ury))
+    {
+        sinfo_msg_error(" invalid rectangle coordinates:") ;
+        sinfo_msg_error("lower left is [%d %d] upper right is [%d %d]",
+                 llx, lly, urx, ury) ;
+        return NullVector ;
+    }
+
+    recsize = (urx - llx + 1) * (ury - lly + 1) ;
+
+    /* allocate a new sinfo_vector to store the average spectral values */
+    if (NULL == (clean = sinfo_new_vector (inp)) )
+    {
+        sinfo_msg_error (" cannot allocate a new sinfo_vector") ;
+        return NullVector ;
+    }
+
+    /*------------------------------------------------------------------------
+     *  loop through the cube planes, through the x axis and the y-axis of the
+     *  plane rectangle and store pixel values in a buffer.
+     */
+    for ( i = 0 ; i < inp ; i++ )
+    {
+      i_img=cpl_imagelist_get(cube,i);
+      pidata=cpl_image_get_data_float(i_img);
+      m = 0 ;
+      local_rectangle=(pixelvalue *) cpl_calloc(recsize, sizeof (pixelvalue*));
+
+        for ( j = lly ; j <= ury ; j++ )
+        {
+            for ( k = llx ; k <= urx ; k++ )
+            {
+                if ( isnan(pidata[k+j*ilx]) )
+                {
+                    continue ;
+                }
+                else
+                {
+                    local_rectangle[m] = pidata[k + j * ilx] ;
+                    m ++ ;
+                }
+            }
+        }
+        if ( m == 0 )
+        {
+            clean->data[i] = 0. ;
+        }
+        else
+        {
+            clean->data[i] = sinfo_new_clean_mean(local_rectangle, m, 
+                                                  lo_reject, hi_reject) ;
+        }
+        cpl_free ( local_rectangle ) ;
+    }
+    return clean ;
+}
+
+/**
+ at brief clean averaging routine for a reduced data to get a better 
+       spectral S/N only for a circular aperture.
+ at name sinfo_new_cleanmean_circle_of_cube_spectra()
+ at param cube: 1 allocated cube, 
+ at param centerx, 
+ at param centery: center pixel of circular aperture in image coordinates
+ at param radius: integer radius of circular aperture
+ at return result spectrum sinfo_vector 
+*/
+
+Vector * 
+sinfo_new_cleanmean_circle_of_cube_spectra( cpl_imagelist * cube,
+                                  int       centerx,
+                                  int       centery,
+                                  int       radius,
+                                  float     lo_reject,
+                                  float     hi_reject )
+{
+    Vector          * clean ;
+    pixelvalue      * circle ;
+    int             i, j, k, l, m, n ;
+    int             circsize, nv ;
+    int ilx=0;
+    int ily=0;
+    int inp=0;
+    float* pidata=NULL;
+    cpl_image* i_img=NULL;
+
+    ilx=cpl_image_get_size_x(cpl_imagelist_get(cube,0));
+    ily=cpl_image_get_size_y(cpl_imagelist_get(cube,0));
+    inp=cpl_imagelist_get_size(cube);
+
+    if ( cube == NULL || inp < 1 )
+    {
+        sinfo_msg_error (" no cube to take the mean of his spectra\n") ;
+        return NullVector ;
+    }
+
+    if ((centerx+radius>=ilx) ||
+        (centery+radius>=ily) ||
+        (centerx-radius<0) ||
+        (centery-radius<0))
+    {
+        sinfo_msg_error(" invalid circular coordinates") ;
+        return NullVector ;
+    }
+
+    n = 0 ;
+    for ( j = centery - radius ; j <= centery + radius ; j++ )
+    {
+        for ( k = centerx - radius ; k <= centerx + radius ; k++ )
+        {
+            if ( (k-centerx)*(k-centerx)+(j-centery)*(j-centery) <= 
+                  radius*radius )
+            {
+                n ++ ;
+            }
+        }
+    }
+    if (n == 0)
+    {
+        sinfo_msg_error (" no data points found!\n") ;
+        return NullVector ;
+    }
+    circsize = n ;
+
+    /* allocate a new sinfo_vector to store the average spectral values */
+    if (NULL == (clean = sinfo_new_vector (inp)) )
+    {
+        sinfo_msg_error (" cannot allocate a new sinfo_vector \n") ;
+        return NullVector ;
+    }
+
+    /*------------------------------------------------------------------------
+     *  loop through the cube planes, through the x axis and the y-axis of the
+     *  plane circle and store pixel values in a buffer.
+     */
+    for ( i = 0 ; i < inp ; i++ )
+    {
+      i_img=cpl_imagelist_get(cube,i);
+      pidata=cpl_image_get_data_float(i_img);
+        m = 0 ;
+        circle = (pixelvalue *) cpl_calloc (circsize, sizeof (pixelvalue*));
+
+        for ( j = centery - radius ; j <= centery + radius ; j++ )
+        {
+            for ( k = centerx - radius ; k <= centerx + radius ; k++ )
+            {
+                if ( (k-centerx)*(k-centerx)+(j-centery)*(j-centery) <= 
+                     radius*radius )
+                {
+                    circle[m] = pidata[k + j * ilx] ;
+                    m ++ ;
+                }
+            }
+        }
+
+        nv = 0 ;
+        for ( l = 0 ; l < circsize ; l++ )
+        {
+            if ( isnan(circle[l]) )
+            {
+                continue ;
+            }
+            clean -> data[i] += circle[l] ;
+            nv ++;
+        }
+        if ( nv == 0 )
+        {
+            clean->data[i] = 0. ;
+        }
+        else
+        {
+            clean->data[i] = sinfo_new_clean_mean(circle, nv, 
+                                                  lo_reject, hi_reject) ; 
+        }
+        cpl_free (circle) ;
+    }
+    return clean ;
+}
+
+/**
+ at brief shifts an array by a sub-pixel shift value using a tanh 
+       interpolation kernel
+ at name sinfo_new_shift_array()
+ at param input: input array, 
+ at param n_elements: number of elements in input array
+ at param shift: sub-pixel shift value (must be < 1.)
+ at param ker: interpolation kernel
+ at return resulting float array  
+*/
+
+float * 
+sinfo_new_shift_array ( float * input, int n_elements, 
+                        float shift, double * ker ) 
+{
+    float  *         shifted ;
+    int              samples = KERNEL_SAMPLES ;
+    int           i ;
+    float            fx ;
+    float            rx ;
+    int              px ;
+    int              tabx ;
+    float            value ;
+    /*size_t           pos ;*/
+    register float * pix ;
+    int              mid;
+    float            norm ;
+
+    /* error handling: test entries */
+    if (input==NULL) 
+    {
+        sinfo_msg_error(" no input array given!\n") ;
+        return NULL ;
+    }
+    if (n_elements<=0) 
+    {
+        sinfo_msg_error(" wrong number of elements in input array given!\n") ;
+        return NULL ;
+    }
+
+    shifted    = (float*) cpl_calloc(n_elements, sizeof(float)) ;
+
+    /* Shifting by a zero offset returns a copy of the input image */
+    if ((fabs(shift)<1e-2))
+    {
+        for (i = 0 ; i <  n_elements ; i++ )
+        {
+            shifted[i] = input[i] ;
+        }
+        return shifted ;
+    }
+    
+    mid = (int)samples/(int)2 ;
+
+    for (i=1 ; i<  n_elements-2 ; i++) 
+    {
+        fx = (float)i+shift ;
+        px = sinfo_new_nint(fx) ;
+        rx = fx - (float)px ;
+        pix = input ;
+
+        if ((px>=1) && (px<(n_elements-2))) 
+        {
+            tabx = (int)(fabs((float)mid * rx)) ;
+            /* exclude blank (ZERO) pixels from interpolation */
+            if (isnan(pix[i]))
+            {
+                value = ZERO ;
+            }
+            else
+            {
+                if (isnan(pix[i-1]))
+                {
+                    pix[i-1] = 0. ;
+                }
+                if (isnan(pix[i+1]))
+                {
+                    pix[i+1] = 0. ;
+                }
+                if (isnan(pix[i+2]))
+                {
+                    pix[i+2] = 0. ;
+                }
+
+                /*
+                 * Sum up over 4 closest pixel values,
+                 * weighted by interpolation kernel values
+                 */
+                value =     pix[i-1] * ker[mid+tabx] +
+                            pix[i] *   ker[tabx] +
+                            pix[i+1] * ker[mid-tabx] +
+                            pix[i+2] * ker[samples-tabx-1] ;
+                /*
+                 * Also sum up interpolation kernel coefficients
+                 * for further normalization
+                 */
+                norm =      ker[mid+tabx] +
+                            ker[tabx] +
+                            ker[mid-tabx] +
+                            ker[samples-tabx-1] ;
+                if (fabs(norm) > 1e-4) 
+                {
+                    value /= norm ;
+                }
+            }
+        }   
+        else 
+        {
+            value = 0.0 ;
+        }
+        if ( isnan(value) )
+        {
+            shifted[i] = ZERO ;
+        }
+        else
+        {
+            shifted[i] = value ;
+        }
+    }  
+    return shifted ;
+}
+
+
+/*--------------------------------------------------------------------------*/
+
+/**
+ at brief divides a resampled image with a resampled spectrum 
+       in the same spectral range
+ at name sinfo_new_div_image_by_spectrum()
+ at param image: resampled image
+ at param spectrum: resampled spectrum in image format
+ at return resulting image
+ at doc 
+divides a resampled image with a resampled spectrum in the same spectral range
+that means all image columns are multiplied with the same spectrum
+*/
+cpl_image * 
+sinfo_new_div_image_by_spectrum( cpl_image * image, cpl_image * spectrum )
+{
+    int col, row ;
+    cpl_image * retImage ;
+    int ilx=0;
+    int ily=0;
+
+    int slx=0;
+    int sly=0;
+
+    float* pidata=NULL;
+    float* psdata=NULL;
+    float* podata=NULL;
+
+    if ( image == NULL )
+    {
+        sinfo_msg_error("no image given!") ;
+        return NULL ;
+    }
+    ilx=cpl_image_get_size_x(image);
+    ily=cpl_image_get_size_y(image);
+
+
+    if ( spectrum == NULL )
+    {
+        sinfo_msg_error("no spectrum image given!") ;
+        return NULL ;
+    }
+    slx=cpl_image_get_size_x(spectrum);
+    sly=cpl_image_get_size_y(spectrum);
+
+    if ( sly != ily )
+    {
+        sinfo_msg_error("images are not compatible in pixel length!") ;
+        return NULL ;
+    }
+    if ( NULL == (retImage = cpl_image_duplicate(image)) )
+    {
+        sinfo_msg_error("could not copy original image!") ;
+        return NULL ;
+    }
+    pidata=cpl_image_get_data_float(image);
+    psdata=cpl_image_get_data_float(spectrum);
+    podata=cpl_image_get_data_float(retImage);
+
+    for ( col = 0 ; col < ilx ; col++ )
+    {
+        for ( row = 0 ; row < ily ; row++ )
+        {
+            if ( !isnan(pidata[col+row*ilx]) &&
+                 !isnan(psdata[col+row*ilx]))
+            {
+                podata[col+row*ilx] = pidata[col+row*ilx] / psdata[row] ;
+            }
+         }
+    }
+    return retImage ;
+}
+
+/*---------------------------------------------------------------------------
+   Function     :       sinfo_new_clean_mean_circle_of_cube_spectra()
+   In           :       cube: 1 allocated cube, 
+                        centerx, centery: center pixel of circular aperture 
+                                          in image coordinates
+                        radius: integer radius of circular aperture
+   Out          :       result spectrum vector
+   Job          :       clean averaging routine for a reduced data to get 
+                        a better spectral S/N only for a circular aperture.
+ ---------------------------------------------------------------------------*/
+
+Vector * sinfo_new_clean_mean_circle_of_cube_spectra(cpl_imagelist * cube,
+                                  int       centerx,
+                                  int       centery,
+                                  int       radius,
+                                  float     lo_reject,
+                                  float     hi_reject )
+{
+    Vector          * clean ;
+    pixelvalue      * circle ;
+    int             i, j, k, l, m, n ;
+    int             circsize, nv ;
+    int lx=0;
+    int ly=0;
+    int lz=0;
+    float* pidata=NULL;
+    cpl_image* img=NULL;
+
+    lz=cpl_imagelist_get_size(cube);
+
+    if ( cube == NULL || lz < 1 )
+    {
+        sinfo_msg_error (" no cube to take the mean of his spectra") ;
+        return NullVector ;
+    }
+    img=cpl_imagelist_get(cube,0);
+    lx=cpl_image_get_size_x(img);
+    ly=cpl_image_get_size_y(img);
+
+    if ((centerx+radius>=lx) ||
+        (centery+radius>=ly) ||
+        (centerx-radius<0) ||
+        (centery-radius<0))
+    {
+        sinfo_msg_error(" invalid circular coordinates") ;
+        return NullVector ;
+    }
+
+    n = 0 ;
+    for ( j = centery - radius ; j <= centery + radius ; j++ )
+    {
+        for ( k = centerx - radius ; k <= centerx + radius ; k++ )
+        {
+            if ( (k-centerx)*(k-centerx)+(j-centery)*(j-centery) <= 
+                 radius*radius )
+            {
+                n ++ ;
+            }
+        }
+    }
+    if (n == 0)
+    {
+        sinfo_msg_error (" no data points found!") ;
+        return NullVector ;
+    }
+    circsize = n ;
+
+    /* allocate a new vector to store the average spectral values */
+    if (NULL == (clean = sinfo_new_vector (lz)) )
+    {
+        sinfo_msg_error (" cannot allocate a new vector") ;
+        return NullVector ;
+    }
+
+    /*------------------------------------------------------------------------
+     *  loop through the cube planes, through the x axis and the y-axis of the
+     *  plane circle and store pixel values in a buffer.
+     */
+    for ( i = 0 ; i < lz ; i++ )
+    {
+      img=cpl_imagelist_get(cube,i);
+      pidata=cpl_image_get_data(img);
+      m = 0 ;
+      circle = (pixelvalue *) cpl_calloc (circsize, sizeof (pixelvalue*));
+
+      for ( j = centery - radius ; j <= centery + radius ; j++ )
+        {
+            for ( k = centerx - radius ; k <= centerx + radius ; k++ )
+            {
+                if ( (k-centerx)*(k-centerx)+(j-centery)*(j-centery) <= 
+                     radius*radius )
+                {
+                     circle[m] = pidata[k + j * lx] ;
+                    m ++ ;
+                }
+            }
+        }
+
+        nv = 0 ;
+        for ( l = 0 ; l < circsize ; l++ )
+        {
+            if ( isnan(circle[l]) )
+            {
+                continue ;
+            }
+            clean -> data[i] += circle[l] ;
+            nv ++;
+        }
+        if ( nv == 0 )
+        {
+            clean->data[i] = 0. ;
+        }
+        else
+        {
+            clean->data[i] = sinfo_new_clean_mean(circle, nv, 
+                                                  lo_reject, hi_reject) ; 
+        }
+        cpl_free (circle) ;
+    }
+    return clean ;
+}
+
+
+
+/*---------------------------------------------------------------------------
+   Function     :       sinfo_new_clean_mean_rectangle_of_cube_spectra()
+   In           :       cube: 1 allocated cube, 
+                        llx, lly, urx, ury: lower left and upper right
+                                            position of rectangle in x-y plane ,
+                                            image coordinates 0...
+   Out          :       result spectrum vector
+   Job          :       clean averaging routine for a reduced data to get a
+                        better spectral S/N only for a rectangular aperture.
+ ---------------------------------------------------------------------------*/
+
+Vector * sinfo_new_clean_mean_rectangle_of_cube_spectra( cpl_imagelist * cube,
+                                          int llx,
+                                          int lly,
+                                          int urx,
+                                          int ury,
+                                          float lo_reject,
+                                          float hi_reject )
+{
+    Vector          * clean ;
+    pixelvalue      *rectangle ;
+    int             i, j, k, m ;
+    int             recsize ;
+    int lx=0;
+    int ly=0;
+    int lz=0;
+    float* pidata=0;
+    cpl_image* img=NULL;
+
+    lz=cpl_imagelist_get_size(cube);
+
+    if ( cube == NULL || lz < 1 )
+    {
+        sinfo_msg_error (" no cube to take the mean of his spectra") ;
+        return NullVector ;
+    }
+    img=cpl_imagelist_get(cube,0);
+    lx=cpl_image_get_size_x(img);
+    ly=cpl_image_get_size_y(img);
+
+    if ((llx<0) || (llx>=lx) ||
+        (urx<0) || (urx>=lx) ||
+        (lly<0) || (lly>=ly) ||
+        (ury<0) || (ury>=ly) ||
+        (llx>=urx) || (lly>=ury))
+    {
+        sinfo_msg_error(" invalid rectangle coordinates:") ;
+        sinfo_msg_error("lower left is [%d %d] upper right is [%d %d]",
+                 llx, lly, urx, ury) ;
+        return NullVector ;
+    }
+
+    recsize = (urx - llx + 1) * (ury - lly + 1) ;
+
+    /* allocate a new vector to store the average spectral values */
+    if (NULL == (clean = sinfo_new_vector (lz)) )
+    {
+        sinfo_msg_error (" cannot allocate a new vector") ;
+        return NullVector ;
+    }
+
+    /*------------------------------------------------------------------------
+     *  loop through the cube planes, through the x axis and the y-axis of the
+     *  plane rectangle and store pixel values in a buffer.
+     */
+    for ( i = 0 ; i < lz ; i++ )
+    {
+        m = 0 ;
+        rectangle = (pixelvalue *) cpl_calloc (recsize, sizeof (pixelvalue*));
+        img=cpl_imagelist_get(cube,i);
+        pidata=cpl_image_get_data(img);
+        for ( j = lly ; j <= ury ; j++ )
+        {
+            for ( k = llx ; k <= urx ; k++ )
+            {
+                if ( isnan(pidata[k+j*lx]) )
+                {
+                    continue ;
+                }
+                else
+                {
+                    rectangle[m] = pidata[k + j * lx] ;
+                    m ++ ;
+                }
+            }
+        }
+        if ( m == 0 )
+        {
+            clean->data[i] = 0. ;
+        }
+        else
+        {
+            clean->data[i] = sinfo_new_clean_mean(rectangle, m, 
+                                                  lo_reject, hi_reject) ;
+        }
+        cpl_free ( rectangle ) ;
+    }
+    return clean ;
+}
+
+/*--------------------------------------------------------------------------*/
+/**@}*/
diff --git a/sinfoni/sinfo_spectrum_ops.h b/sinfoni/sinfo_spectrum_ops.h
new file mode 100644
index 0000000..fbbdf36
--- /dev/null
+++ b/sinfoni/sinfo_spectrum_ops.h
@@ -0,0 +1,476 @@
+#ifndef SINFO_SPECTRUM_OPS_H
+#define SINFO_SPECTRUM_OPS_H
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/************************************************************************
+* E.S.O. - VLT project
+*
+* "@(#) $Id: sinfo_spectrum_ops.h,v 1.4 2007/06/06 07:10:45 amodigli Exp $"
+*
+* who       when      what
+* --------  --------  ----------------------------------------------
+* schreib  25/05/00  created
+*/
+
+/************************************************************************
+ * sinfo_spectrum_ops.h
+ * spectral sinfo_vector routines
+ *----------------------------------------------------------------------
+ */
+
+#define  SPEED_OF_LIGHT 2.99792458e8
+#define  PLANCK            6.62606876e-34
+#define  BOLTZMANN      1.3806503e-23
+
+/*
+ * header files
+ */
+
+#include <cpl.h>
+#include "sinfo_focus.h"
+#include "sinfo_recipes.h"
+#include "sinfo_new_cube_ops.h"
+#include "sinfo_msg.h"
+/*----------------------------------------------------------------------------
+ *                        Function ANSI C prototypes
+ *--------------------------------------------------------------------------*/
+
+
+/**
+ at brief convert an image in a table spectrum 
+ at param spc       input image spectrum
+ at param filename  input filename
+ at param tbl       output table
+*/
+int 
+sinfo_stectrum_ima2table(
+                 const cpl_image* spc,
+                 const char* filename,
+                 cpl_table** tbl);
+
+/**
+ at brief clean averaging routine for a reduced data to get a 
+       better spectral S/N only for a rectangular aperture.
+ at name sinfo_new_cleanmean_rectangle_of_cube_spectra()
+ at param cube: 1 allocated cube, 
+ at param llx, 
+ at param lly, 
+ at param urx, 
+ at param ury: lower left and upper right position of rectangle in x-y plane ,
+            image coordinates 0...
+ at return result spectrum sinfo_vector 
+*/
+
+Vector * 
+sinfo_new_cleanmean_rectangle_of_cube_spectra( cpl_imagelist * cube,
+                                          int llx,
+                                          int lly,
+                                          int urx,
+                                          int ury,
+                                          float lo_reject,
+                            float hi_reject );
+/**
+ at brief clean averaging routine for a reduced data to get 
+       a better spectral S/N only for a circular aperture.
+ at name sinfo_new_cleanmean_circle_of_cube_spectra()
+ at param cube: 1 allocated cube, 
+ at param centerx, 
+ at param centery: center pixel of circular aperture in image coordinates
+ at param radius: integer radius of circular aperture
+ at return result spectrum sinfo_vector 
+*/
+
+Vector * 
+sinfo_new_cleanmean_circle_of_cube_spectra( cpl_imagelist * cube,
+                                  int       centerx,
+                                  int       centery,
+                                  int       radius,
+                                  float     lo_reject,
+                             float     hi_reject );
+/**
+   @name sinfo_new_div_image_by_spectrum()
+   @param  image resampled image
+   @param  spectrum resampled spectrum in image format
+   @result resulting image
+   @memo   divides a resampled image with a resampled spectrum in the same 
+           spectral range that means all image columns are multiplied with 
+           the same spectrum
+*/
+
+cpl_image * 
+sinfo_new_div_image_by_spectrum( cpl_image * image, cpl_image * spectrum ) ;
+
+/**
+ at brief frees memory of a sinfo_vector
+ at name sinfo_free_svector()
+ at param sinfo_vector to destroy
+ at return nothing 
+*/
+
+void 
+sinfo_free_svector( Vector **svector );
+
+/**
+   @name     sinfo_new_vector()
+   @memo allocates memory for a new sinfo_vector
+   @param    number of sinfo_vector elements
+   @result     sinfo_vector
+*/
+
+Vector * 
+sinfo_new_vector( ulong32 n_elements ) ;
+
+
+/**
+   @name   sinfo_new_destroy_vector()
+   @param  sinfo_vector to destroy
+   @result nothing
+   @memo frees memory of a sinfo_vector
+*/
+
+void 
+sinfo_new_destroy_vector( Vector *sinfo_vector ) ;
+
+/**
+   @name   sinfo_new_vector_to_image()
+   @param spectrum spectral vector that should be converted to a fits image
+   @result mage with lx = 1 and ly = length of sinfo_vector
+   @doc   converts a spectral vector to a fits image
+   @note the sinfo_vector object spectrum is destroyed
+*/
+
+
+cpl_image * 
+sinfo_new_vector_to_image( Vector * spectrum ) ;
+
+/**
+   @name  sinfo_imageToVector()
+   @memo converts a fits image to a spectral sinfo_vector
+   @param spectrum   1-D Fits image that should be converted to a 
+                     spectral vector
+   @result  spectral sinfo_vector with length ly
+   @note input image is destroyed
+*/
+
+Vector * 
+sinfo_new_image_to_vector( cpl_image * spectrum ) ;
+
+
+/**
+   @name sinfo_new_extract_spectrum_from_resampled_flat()
+   @memo   builds one spectrum in a fits image out of a resampled
+           flatfield frame by taking a clean mean along the spatial pixels
+   @param resflat: resampled halogen lamp frame, bad pixel corrected
+   @param loreject
+   @param hireject percentage of extreme low and high intensity values
+                   to be rejected from averaging
+   @result fits image that contains the final halogen lamp spectrum
+*/
+
+cpl_image * 
+sinfo_new_extract_spectrum_from_resampled_flat( cpl_image * resflat,
+                                             float      loreject,
+                                             float      hireject ) ;
+
+/**
+   @name  sinfo_new_multiply_image_with_spectrum()
+   @param  image: resampled image
+   @param  spectrum: resampled spectrum in image format
+   @result resulting image
+   @doc    multiplys a resampled image with a resampled spectrum
+           (calibrated halogen lamp spectrum) in the same spectral range
+           that means all image columns are multiplied with the same spectrum
+*/
+
+cpl_image * 
+sinfo_new_multiply_image_with_spectrum(cpl_image * image,
+                                       cpl_image * spectrum ) ;
+
+/**
+   @name   sinfo_new_optimal_extraction_from_cube()
+   @param  cube: input data cube
+   @param  llx lower left edge x point of 2d Gaussian fitting box.
+   @param  lly lower left edge y point of 2d Gaussian fitting box.
+   @param  halfbox_x half width of a box inside which
+                                              a 2D-Gaussian fit is carried out
+   @param  halfbox_y half width of a box inside which
+                                              a 2D-Gaussian fit is carried out
+   @param  fwhm_factor factor applied to the found fwhms of a 2D-Gaussian
+                       fit, defines the radius of the aperture inside which the
+                       spectral extraction is carried out (default: 0.6).
+   @param  backvariance (readnoise^2 + dark current variance) needed to 
+                        determine the noise variance of the background. 
+                        Must be given in counts/sec.
+   @param  sky          estimated sky variance in counts/sec
+   @param  gain         conversion factor electrons/count
+   @param  exptime     total exposure time
+   @result  resulting spectrum stored in a 1D-image
+   @doc     does the optimal extraction of a standard star spectrum
+            according to the equation:
+            S = sum { (P^2 / V) * (I - B) / P } / sum{ P^2 / V }
+            S: spectral flux at a particular wavelength
+            P: normalized PSF (determined by a 2D-Gaussian fit)
+            I: pixel value
+            B: background pixel value determined by the 
+               background parameter of the 2D-Gaussian fit
+            V: estimated variance of a pixel: 
+            V = [R^2 + D + sky + I,c/exptime]/gain
+            where R is the read noise, and D the sinfo_dark current variance.
+            backvariance is R^2 + D in counts/sec. 
+            I,c is the source intensity in counts
+            Remember: 
+            sigma,e[e-] = gain[e/count] * sigma,c [counts] 
+                        = sqrt(I,e) = sqrt(gain*I,c)
+                      => V,c = sigma,c^2 = sigma,e^2/gain^2
+                      => sigma,c = sqrt(I,c/gain) => V,c = I,c/gain
+*/
+
+
+cpl_image * 
+sinfo_new_optimal_extraction_from_cube( cpl_imagelist * cube,
+                                      int llx,
+                                      int lly,
+                                      int halfbox_x,
+                                      int halfbox_y,
+                                      float fwhm_factor,
+                                      float backvariance,
+                                      float sky,
+                                      float gain,
+                                      float exptime,
+                                      const char* name,
+                                      cpl_table** spectrum,
+                                      int qc_info,
+                                      int* check2) ;
+
+/**
+   @name       sinfo_new_extract_sky_from_cube()
+   @param      cube reduced cube from sky spider observation
+   @param      loReject
+   @param      hiReject: fraction (percentage) of the extreme high and low
+                         sky spectrum values that are rejected before
+                         averaging the found sky spectra.
+   @param      position: end pixel positions of the straight line in the image
+                         dividing the sky from the object pixels.
+   @param      tolerance: pixel tolerance which are not considered and 
+                          subtracted from the diagonal line to be sure to get 
+                          a clean sky, default: 2
+   @param      posindicator: indicates in which sinfo_edge of the field of 
+                             view the sky is projected. output of 
+                             spiffi_get_spiderposindex() in fitshead.c
+   @result resulting averaged sky spectrum
+   @doc    extracts a sky spectrum from a reduced sky spider observation, that
+           means from a data cube. Therefore, the position of the sky within 
+           the field of view must be first read from the fits header. A pixel 
+           tolerance is subtracted. The found sky spectra are averaged by 
+           rejecting the extreme high and low values.
+*/
+
+Vector * 
+sinfo_new_extract_sky_from_cube( cpl_imagelist * cube,
+                             float     loReject,
+                             float     hiReject,
+                             int     * position,
+                             int       tolerance,
+                             int       posindicator ) ;
+
+/**
+   @name    sinfo_new_sum_rectangle_of_cube_spectra()
+   @memo averaging routine for a reduced data to get a better spectral S/N
+         only for a rectangular aperture.
+   @param   cube: 1 allocated cube,
+   @param   llx lower left x position of rectangle in x-y plane 
+   @param   lly lower left y position of rectangle in x-y plane 
+   @param   urx upper right x position of rectangle in x-y plane 
+   @param   ury upper right y position of rectangle in x-y plane 
+                                       of rectangle in x-y plane ,
+                                         
+   @result spectrum vector
+*/
+
+Vector * 
+sinfo_new_sum_rectangle_of_cube_spectra( cpl_imagelist * cube,
+                                     int llx,
+                                     int lly,
+                                     int urx,
+                                     int ury ) ;
+
+/**
+   @name   sinfo_new_sum_circle_of_cube_spectra()
+   @memo averaging routine for a reduced data to get a better spectral S/N
+         only for a circular aperture.
+   @param  cube: 1 allocated cube,
+   @param  centerx x center pixel of circular aperture in image coordinates
+   @param  centery y center pixel of circular aperture in image coordinates
+   @param  radius integer radius of circular aperture
+   @result spectrum sinfo_vector
+*/
+
+Vector * 
+sinfo_new_sum_circle_of_cube_spectra( cpl_imagelist * cube,
+                                  int       centerx,
+                                  int       centery,
+                                  int       radius ) ;
+
+
+/**
+   @name sinfo_new_mean_rectangle_of_cube_spectra()
+   @memo averaging routine for a reduced data to get a better spectral S/N
+         only for a rectangular aperture.
+   @param  cube: 1 allocated cube,
+   @param   llx lower left x position of rectangle in x-y plane 
+   @param   lly lower left y position of rectangle in x-y plane 
+   @param   urx upper right x position of rectangle in x-y plane 
+   @param   ury upper right y position of rectangle in x-y plane 
+                                       of rectangle in x-y plane ,
+   @return  result spectrum vector
+*/
+
+Vector * 
+sinfo_new_mean_rectangle_of_cube_spectra( cpl_imagelist * cube,
+                                     int llx,
+                                     int lly,
+                                     int urx,
+                                     int ury ) ;
+
+/**
+   @name   sinfo_new_mean_circle_of_cube_spectra()
+   @memo averaging routine for a reduced data to get a better spectral S/N
+         only for a circular aperture.
+   @param  cube: 1 allocated cube
+   @param  centerx center pixel of circular aperture in image coordinates
+   @param  centery center pixel of circular aperture in image coordinates
+   @param  radius integer radius of circular aperture
+   @result result spectrum vector
+*/
+
+Vector * 
+sinfo_new_mean_circle_of_cube_spectra( cpl_imagelist * cube,
+                                  int       centerx,
+                                  int       centery,
+                                  int       radius ) ;
+
+/**
+   @name   sinfo_new_blackbody_spectrum()
+   @memo   computes a blackbody spectral intensity distribution
+           (W/(m^2 lambda ster))
+   @param  templateSpec spectrum of a standard star
+                        (1-d image with fits header)
+   @param  temp blackbody temperature in Kelvin (standard Star temp),
+   @return resulting spectrum sinfo_vector
+*/
+
+Vector * 
+sinfo_new_blackbody_spectrum( char * templateSpec, double temp ) ;
+
+/**
+   @name    sinfo_new_median_rectangle_of_cube_spectra()
+   @memo averaging routine for a reduced data to get a better spectral S/N
+         only for a rectangular aperture.
+   @param   cube: 1 allocated cube,
+   @param   llx lower left x position of rectangle in x-y plane 
+   @param   lly lower left y position of rectangle in x-y plane 
+   @param   urx upper right x position of rectangle in x-y plane 
+   @param   ury upper right y position of rectangle in x-y plane 
+                                       of rectangle in x-y plane ,
+   @result  result spectrum vector
+*/
+
+Vector * 
+sinfo_new_median_rectangle_of_cube_spectra( cpl_imagelist * cube,
+                                             int llx,
+                                             int lly,
+                                             int urx,
+                                             int ury ) ;
+
+/**
+   @name  sinfo_new_median_circle_of_cube_spectra()
+   @memo averaging routine for a reduced data to get a better spectral S/N
+         only for a circular aperture.
+   @param cube: 1 allocated cube,
+   @param  centerx center pixel of circular aperture in image coordinates
+   @param  centery center pixel of circular aperture in image coordinates
+   @param  radius integer radius of circular aperture
+   @result result spectrum vector
+*/
+
+Vector * 
+sinfo_new_median_circle_of_cube_spectra( cpl_imagelist * cube,
+                                  int       centerx,
+                                  int       centery,
+                                  int       radius ) ;
+
+
+/**
+   @name   sinfo_new_clean_mean_rectangle_of_cube_spectra()
+   @memo averaging routine for a reduced data to get a better spectral S/N
+         only for a rectangular aperture.
+   @param  cube: 1 allocated cube,
+   @param   llx lower left x position of rectangle in x-y plane 
+   @param   lly lower left y position of rectangle in x-y plane 
+   @param   urx upper right x position of rectangle in x-y plane 
+   @param   ury upper right y position of rectangle in x-y plane 
+                                       of rectangle in x-y plane ,
+   @result  result spectrum vector
+*/
+
+Vector * 
+sinfo_new_clean_mean_rectangle_of_cube_spectra( cpl_imagelist * cube,
+                                             int llx,
+                                             int lly,
+                                             int urx,
+                                             int ury,
+                                             float lo_reject,
+                                             float hi_reject ) ;
+
+/**
+   @name    sinfo_new_clean_mean_circle_of_cube_spectra()
+   @memo averaging routine for a reduced data to get a better spectral S/N
+         only for a circular aperture.
+   @param       cube: 1 allocated cube,
+   @param  centerx center pixel of circular aperture in image coordinates
+   @param  centery center pixel of circular aperture in image coordinates
+   @param  radius integer radius of circular aperture
+   @result result spectrum vector
+ ---------------------------------------------------------------------------*/
+
+Vector * 
+sinfo_new_clean_mean_circle_of_cube_spectra( cpl_imagelist * cube,
+                                  int       centerx,
+                                  int       centery,
+                                  int       radius,
+                                  float     lo_reject,
+                                  float     hi_reject ) ;
+
+/**
+   @name sinfo_new_shift_array()
+   @memo   shifts an array by a sub-pixel shift value using a tanh
+           interpolation kernel
+   @param  input input array,
+   @param  n_elements number of elements in input array
+   @param  shift sub-pixel shift value (must be < 1.)
+   @param  ker    interpolation kernel
+   @result resulting float array
+*/
+
+float * 
+sinfo_new_shift_array(float * input,int n_elements,float shift,double * ker ) ;
+
+#endif /*!SINFO_SPECTRUM_OPS_H*/
+
diff --git a/sinfoni/sinfo_spiffi_types.h b/sinfoni/sinfo_spiffi_types.h
new file mode 100644
index 0000000..ad320be
--- /dev/null
+++ b/sinfoni/sinfo_spiffi_types.h
@@ -0,0 +1,153 @@
+#ifndef SINFO_SPIFFI_TYPES_H
+#define SINFO_SPIFFI_TYPES_H
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*******************************************************************************
+* E.S.O. - VLT project
+*
+* "@(#) $Id: sinfo_spiffi_types.h,v 1.3 2007/06/06 07:10:45 amodigli Exp $"
+*
+* who       when      what
+* --------  --------  ----------------------------------------------
+* schreib  25/05/00  created
+*/
+
+/************************************************************************
+ * sinfo_spiffi_types.h
+ * all shared local new data types and defines for spiffi data reduction
+ *----------------------------------------------------------------------
+ */
+
+/*
+ * header files
+ */
+
+#include <sys/types.h>
+#include <limits.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "sinfo_local_types.h"
+
+/*----------------------------------------------------------------------------
+                                   Defines
+ *--------------------------------------------------------------------------*/
+
+#define NullVector   (Vector *) NULL
+#define SLOPE        1000.  /*slope limit of the linear fit*/
+#define SATURATION   50000. /*saturation level of the detector pixel values*/
+#define ESTIMATE     200    /*estimation of number of parameters stored in an
+                              ascii file*/
+#define THRESH       100000. /* Threshold for operation 1/pixelvalue of 
+                                an image division*/
+
+/*--------------------------------------------------------------------------*/
+
+#define PIXEL_WIDTH  0.0185 /* mm */
+#define FOCAL_LENGTH 178.   /* mm */
+ 
+#define N_SLITLETS   32     /* number of slitlets */
+#define SLITLENGTH   64     /* nominal pixel length of one slitlet */
+#define SLIT_LEN_ERR  5     /* error on SLITLENGTH */
+#define SLIT_POS_ERR  5     /* error on SLITLENGTH */
+
+#define LOW_REJECT   0.1    /* fraction of rejected extreme low values of fit 
+                               coefficients in sinfo_coefsCrossFit() */
+#define HIGH_REJECT  0.9    /* fraction of rejected extreme high values of fit
+                               coefficients in sinfo_coefsCrossFit() */
+#define PIXEL        25     /* number of pixels for offsets in 
+                               sinfo_coeffsCrossSlitFit() */
+
+#define CENTRALLAMBDA_K 2.2 /* defined central wavelengths and pixel 
+                               dispersions for each grating for 
+                               sinfo_definedResampling() */
+#define CENTRALLAMBDA_H    1.65
+#define CENTRALLAMBDA_J    1.25
+#define CENTRALLAMBDA_HK   1.95
+#define DISPERSION_K       0.00049
+#define DISPERSION_K_DITH  0.000245
+#define DISPERSION_H       0.00039
+#define DISPERSION_H_DITH  0.000195
+#define DISPERSION_J       0.00029
+#define DISPERSION_J_DITH  0.000145
+#define DISPERSION_HK      0.001
+#define DISPERSION_HK_DITH 0.0005
+
+/*----------------------------------------------------------------------------
+                                   New types
+ ---------------------------------------------------------------------------*/
+
+/*--------------------------------------------------------------------------*/
+/* The following structure stores a sinfo_vector                           */
+/*--------------------------------------------------------------------------*/
+
+typedef struct _VECTOR_
+{
+    int           n_elements ;       /* number of sinfo_vector elements */
+    pixelvalue    *       data ;         /* array of sinfo_vector values */
+} Vector ;   
+
+/*--------------------------------------------------------------------------*/
+/* The following structure stores the (gauss) fitting parameters of the     */
+/* emission lines of the calibration lamps                                  */
+/*--------------------------------------------------------------------------*/
+
+typedef struct _FIT_PARAMS_
+{
+    int      n_params ;        /* total number of fits to allocate 
+                                  FitParams array */
+    int      column ;          /* index of the column in image coordinates */
+    int      line   ;          /* index of fitted emission line 
+                                  of the column */            
+    float    wavelength ;      /* associated wavelength of the calibration 
+                                  lamp emission line taken from the 
+                                  line center list file */
+    float  * fit_par ;         /* fit_par[0]: amplitude,
+                                  fit_par[1]: FWHM,
+                                  fit_par[2]: position of 
+                                              center of gauss,
+                                  fit_par[3]: zero level offset */
+    float  * derv_par ;        /* corresponding derivatives of fit_par[] */
+} FitParams ;   
+
+typedef struct _STATS_
+{
+    float cleanmean ;          /* mean of pixel values without considering 
+                                  the extreme values */
+    float cleanstdev ;         /* standard deviation of pixel values without 
+                                  considering the extreme values */
+    int   npix ;               /* number of clean pixel values */
+} Stats ;
+
+typedef struct _BCOEFFS_
+{
+    int slitlet ;              /* current slitlet */
+    int n_slitlets ;           /* number of slitlets */
+    int n_acoeffs ;            /* number of a fit coefficients */
+    int n_bcoeffs ;            /* number of b fit coefficients */
+    float ** b ;               /* sinfo_matrix of fit coefficients: 
+                                  b[index acoefs][index bcoefs] */
+} Bcoeffs ;
+
+#endif /*!SINFO_SPIFFI_TYPES_H*/
+
+/*--------------------------------------------------------------------------*/
+
+
diff --git a/sinfoni/sinfo_stack_cfg.c b/sinfoni/sinfo_stack_cfg.c
new file mode 100644
index 0000000..e99532a
--- /dev/null
+++ b/sinfoni/sinfo_stack_cfg.c
@@ -0,0 +1,85 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/*---------------------------------------------------------------------------
+   
+   File name     :    stack_cfg.c
+   Author         : Juergen Schreiber
+   Created on    :    September 2001
+   Description    :    prepare stacked frames configuration handling tools
+
+ *--------------------------------------------------------------------------*/
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+/*---------------------------------------------------------------------------
+                                   Includes
+ ---------------------------------------------------------------------------*/
+
+#include "sinfo_stack_cfg.h"
+/**@{*/
+/**
+ * @addtogroup sinfo_rec_jitter Stack structure configuration
+ *
+ * TBD
+ */
+
+/*---------------------------------------------------------------------------
+                              Function codes
+ ---------------------------------------------------------------------------*/
+
+/**
+ at brief allocate memory for a stack_config struct
+ at name sinfo_stack_cfg_create()
+ at param void
+ at return pointer to allocated base stack_config structure 
+ at note only the main (base) structure is allocated
+*/
+
+stack_config_n * sinfo_stack_cfg_create_n(void)
+{
+    return cpl_calloc(1, sizeof(stack_config_n));
+}
+
+
+/**
+ at brief deallocate all memory associated with a stack_config data structure
+ at name sinfo_stack_cfg_destroy()
+ at param stack_config to deallocate
+ at return void
+*/
+
+void sinfo_stack_cfg_destroy_n(stack_config_n * sc)
+{
+    if (sc==NULL) return ;
+
+    /* Free list of frame types */
+    /*cpl_free(sc->frametype);*/
+    /* Free positions */
+    /*cpl_free(sc->frameposition);*/
+    /* Free main struct */
+    cpl_free(sc);
+
+    return ;
+}
+/**@}*/
+
+
+
diff --git a/sinfoni/sinfo_stack_cfg.h b/sinfoni/sinfo_stack_cfg.h
new file mode 100644
index 0000000..d395f4e
--- /dev/null
+++ b/sinfoni/sinfo_stack_cfg.h
@@ -0,0 +1,176 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*---------------------------------------------------------------------------
+   
+   File name     :    stack_cfg.h
+   Author         :    Juergen Schreiber
+   Created on    :    September 2001
+   Description    :    stack_ini definitions + handling prototypes
+ ---------------------------------------------------------------------------*/
+#ifndef SINFO_STACK_CFG_H
+#define SINFO_STACK_CFG_H
+/*---------------------------------------------------------------------------
+                                   Includes
+ ---------------------------------------------------------------------------*/
+#include <stdlib.h>
+#include <cpl.h>
+#include "sinfo_globals.h"
+/*---------------------------------------------------------------------------
+                                   Defines
+ ---------------------------------------------------------------------------*/
+/*---------------------------------------------------------------------------
+                                   New types
+ ---------------------------------------------------------------------------*/
+/*
+  prepare stacked images blackboard container
+
+  This structure holds all information related to the stacked images handling
+  routine. It is used as a container for the flux of ancillary data,
+  computed values, and algorithm status. Pixel flux is separated from
+  the blackboard.
+  */
+
+typedef struct stack_config_n {
+/*-------General---------*/
+        char inFile[FILE_NAME_SZ] ; /* file name of the file containing 
+                                       the list of all input frames */
+        char outName[FILE_NAME_SZ] ; /* output name of resulting fits 
+                                        wavelength map */
+        char sky_name[FILE_NAME_SZ] ; /* output name of resulting fits 
+                                         sky frame */
+        char ** framelist ; /* list of frames */
+        int  * frametype ; /* list of frame types on or off */
+        int  * frameposition ; /* list of grating positions */  
+        int    contains_sky ; /* indicates if off or sky frames were exposed */
+        int    contains_ref ; /* indicates if ref frames were exposed */
+        int    contains_dither ; /* indicates if spectral dithering 
+                                    was applied */
+        int    contains_dark ; /* indicates if spectral 
+                                  dithering was applied */
+        int    nframes ; /* number of frames in frame list */
+        int    nobj ;  /* number of object frames in frame list */
+        int    noff ;  /* number of off frames in frame list */
+        int    ndark ;  /* number of sinfo_dark frames in frame list */
+        int    nditherobj ;  /* number of dithered object 
+                                frames in frame list */
+        int    nditheroff ;  /* number of dithered off frames in frame list */
+
+/*------ CleanMean ------*/
+        /* percentage of rejected low intensity pixels */
+        float loReject ;      
+        /* percentage of rejected high intensity pixels */
+        float hiReject ;
+
+/*------ Flatfielding ------*/
+        /* indicator if a flatfielding is carried through or not */
+        int flatInd ;
+        char flatfield1[FILE_NAME_SZ] ; /* name of the flatfield fits file 
+                                           for grating position 1 */
+        char flatfield2[FILE_NAME_SZ] ; /* name of the flatfield fits file 
+                                           for grating position 2 */
+
+/*------ BadPixel ------*/
+        /* indicates if the bad pixel mask should be applied or not */
+        int maskInd ;
+        /* indicates if the pixels should be interpolated or indicated */
+        int indind ;
+        /* file name of the bad pixel mask fits file */
+        char mask[FILE_NAME_SZ] ;
+        /* maximal pixel distance from the bad pixel to which valid 
+           pixels are searched for*/ 
+        int maxRad ;
+        /* file name of the slitlet sinfo_edge position list */
+        char slitposList[FILE_NAME_SZ] ;
+        /* index file list*/
+        char indexlist[FILE_NAME_SZ] ;
+        /* sigma factor for the additional bad pixel search 
+           in method maskInd = 2 */
+        float sigmaFactor ;
+
+/*------ ColTilt ------*/
+        /* indicator if the tilt correction should be carried through */
+        /*int coltiltInd ;*/
+        /* file name of the ASCII file containing the slope value */
+        /*char slopeFile[FILE_NAME_SZ] ;*/
+        /* order of polynomial used for polynomial interpolation 
+           for the row shifting */
+        /*int order ;*/
+/*------ WarpFix ------*/
+        /* indicator if the warping should be carried through */
+        int warpfixInd ;
+        /* file name of the ASCII file containing the polynomial values */
+        char polyFile[FILE_NAME_SZ] ;
+        /* file name of MASTER DARK */
+        char mdark[FILE_NAME_SZ] ;
+  /* swich to indicate if a mdark file has been found */
+        int mdark_ind;  
+      /* kernel to be used for the interpolation */
+        char kernel[FILE_NAME_SZ] ;
+
+/*------ Interleaving ------*/
+        /* indicator if the interleaving or Convolution with a 
+           Gaussian or nothing should take place */
+        int interInd ;
+    /* number of rows from which the general offset between 
+           the frames is determined */
+    int noRows ;
+
+/*------ GaussConvolution ------*/
+    /* indicator if Gaussian convolution is applied or not */
+        int gaussInd ;
+    /* kernel half width of the Gaussian response function */
+    int hw ;
+
+/*------ ShifFrames ------*/
+    /* indicator if shiftting frames is applied or not */
+        int sfInd;
+    /* interpolation type*/
+    int sfType;
+    /* interpolation order*/
+    int sfOrder;
+
+  /* qc log */
+  int qc_thresh_min;
+  int qc_thresh_max;
+
+} stack_config_n ;
+/*---------------------------------------------------------------------------
+                               Function prototypes
+ ---------------------------------------------------------------------------*/
+/**
+   @name  sinfo_stack_cfg_create()
+   @memo   allocate memory for a stack_cfg struct
+   @return pointer to allocated base stack_cfg structure
+   @note   only the main (base) structure is allocated
+*/
+
+stack_config_n * 
+sinfo_stack_cfg_create_n(void);
+
+
+/**
+   @name   sinfo_stack_cfg_destroy()
+   @memo  deallocate all memory associated with a stack_config data structure
+   @param  stack_config to deallocate
+   @return   void
+*/
+void 
+sinfo_stack_cfg_destroy_n(stack_config_n * sc);
+
+#endif
diff --git a/sinfoni/sinfo_stack_ini.h b/sinfoni/sinfo_stack_ini.h
new file mode 100644
index 0000000..7cb3038
--- /dev/null
+++ b/sinfoni/sinfo_stack_ini.h
@@ -0,0 +1,95 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/*----------------------------------------------------------------------------
+   
+   File name    :   sinfo_stack_ini.h
+   Author       :    Juergen Schreiber
+   Created on   :    Sept 25, 2001
+   Description  :    preparing stack of frames ini file handling for SPIFFI
+
+ ---------------------------------------------------------------------------*/
+
+
+#ifndef SINFO_STACK_INI_H
+#define SINFO_STACK_INI_H
+
+
+/*---------------------------------------------------------------------------
+                                Includes
+---------------------------------------------------------------------------*/
+
+#include <cpl.h>
+
+#include "sinfo_stack_cfg.h"
+
+ 
+/*---------------------------------------------------------------------------
+                                Defines
+---------------------------------------------------------------------------*/
+
+#define FRAME_ON     1  /* object frames */
+#define FRAME_OFF    0  /* off frames, that means sky frames or calibration 
+                           frames with lamp switched off */
+#define FRAME_POS1   2  /* frames exposed with grating position 1 */
+#define FRAME_POS2   3  /* frames exposed with dithered grating position 2 */
+ 
+/*----------------------------------------------------------------------------
+                             Function prototypes 
+ ---------------------------------------------------------------------------*/
+
+
+/*-------------------------------------------------------------------------*/
+/**
+  @name        generateStack_ini_file
+  @memo        Generate a default ini file for the preparing of stack 
+                frames command.
+  @param    ini_name    Name of the file to generate.
+  @param    name_i        Name of the input file.
+  @param    name_o        Name of the output file.
+  @return    int 0 if Ok, -1 otherwise.
+  @doc
+
+  This function generates a default ini file for the preparing of 
+  stacked frames command. The
+  generated file will have the requested name. 
+ */
+/*--------------------------------------------------------------------------*/
+int generateStack_ini_file(
+        char * ini_name,
+        char * name_i,
+        char * name_o
+);
+
+/*-------------------------------------------------------------------------*/
+/**
+  @name     parse_stack_ini_file
+  @memo     Parse a ini_name.ini file and create a blackboard.
+  @param    ini_name    Name of the ASCII file to parse.
+  @return   1 newly allocated stack_config blackboard structure.
+  @doc
+
+  The requested ini file is parsed and a blackboard object is created, then
+  updated accordingly. Returns NULL in case of error.
+ */
+/*--------------------------------------------------------------------------*/
+
+stack_config * parse_stack_ini_file(char * ini_name) ;
+
+#endif
diff --git a/sinfoni/sinfo_stack_ini_by_cpl.c b/sinfoni/sinfo_stack_ini_by_cpl.c
new file mode 100644
index 0000000..034af8f
--- /dev/null
+++ b/sinfoni/sinfo_stack_ini_by_cpl.c
@@ -0,0 +1,712 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+   
+   File name    :   stack_ini_by_cpl.c
+   Author       :   Andrea Modigliani
+   Created on   :   May 23, 2004
+   Description  :   prepare stacked frames cpl input handling for SPIFFI
+
+ ---------------------------------------------------------------------------*/
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+/*---------------------------------------------------------------------------
+                                Includes
+ ---------------------------------------------------------------------------*/
+
+#include <string.h>
+#include "sinfo_stack_ini_by_cpl.h"
+#include "sinfo_error.h"
+#include "sinfo_pro_types.h"
+#include "sinfo_raw_types.h"
+#include "sinfo_ref_types.h"
+#include "sinfo_functions.h"
+
+#include "sinfo_file_handling.h"
+
+/*---------------------------------------------------------------------------
+                    Functions private to this module
+ ---------------------------------------------------------------------------*/
+static void sinfo_stack_free_alloc(stack_config_n * cfg);  
+
+
+static void     
+parse_section_frames(stack_config_n *, 
+                     cpl_frameset* sof, 
+                     cpl_frameset** raw,
+                     int* status,
+                     fake* fk);
+
+static void     
+parse_section_cleanmean(stack_config_n *, cpl_parameterlist* cpl_cfg);
+static void     
+parse_section_flatfield(stack_config_n *, cpl_parameterlist* cpl_cfg);
+static void     
+parse_section_badpixel(stack_config_n *, cpl_parameterlist* cpl_cfg);
+static void     
+parse_section_interleaving(stack_config_n *);
+static void     
+parse_section_gaussconvolution(stack_config_n *, cpl_parameterlist* cpl_cfg);
+static void     
+parse_section_shiftframes(stack_config_n *);
+static void     
+parse_section_warpfix(stack_config_n *,  cpl_parameterlist* cpl_cfg);
+static void     
+parse_section_qclog(stack_config_n *,  cpl_parameterlist* cpl_cfg);
+/**@{*/
+/**
+ * @addtogroup sinfo_rec_jitter Initialize stack structure configuration
+ *
+ * TBD
+ */
+
+/* generateStack_ini_file */
+/*-------------------------------------------------------------------------*/
+/**
+  @name     parse_stack_ini_file
+  @memo     Parse a ini_name.ini file and create a blackboard.
+  @param    ini_name    Name of the ASCII file to parse.
+  @return   1 newly allocated stack_config blackboard structure.
+  @doc
+
+  The requested ini file is parsed and a blackboard object is created, then
+  updated accordingly. Returns NULL in case of error.
+ */
+/*--------------------------------------------------------------------------*/
+
+stack_config_n * sinfo_parse_cpl_input_stack(cpl_parameterlist* cpl_cfg, 
+                                       cpl_frameset* sof, 
+                                       cpl_frameset** raw,
+                                       fake* fk)
+{
+    stack_config_n   *       cfg =sinfo_stack_cfg_create_n();
+    int status=0;
+   
+
+
+    /*
+     * Perform sanity checks, fill up the structure with what was
+     * found in the ini file
+     */
+
+    parse_section_cleanmean        (cfg, cpl_cfg);
+    parse_section_flatfield        (cfg, cpl_cfg);
+    parse_section_badpixel         (cfg, cpl_cfg); 
+    parse_section_interleaving     (cfg); 
+    parse_section_gaussconvolution (cfg, cpl_cfg); 
+    parse_section_shiftframes      (cfg); 
+    parse_section_warpfix          (cfg, cpl_cfg);
+    parse_section_qclog            (cfg, cpl_cfg);
+    parse_section_frames           (cfg, sof, raw, &status, fk);
+          if (status > 0) {
+                sinfo_msg_error("parsing cpl input");
+                sinfo_stack_cfg_destroy_n(cfg);
+                cfg = NULL ;
+                return NULL ;
+        }
+    return cfg ;
+}
+/**
+ at name parse_section_frames
+ at memo Parse input frames
+ at param stack_config_n input stack configuration structer
+ at param sof input set of frames
+ at param raw output raw stack frames list
+ at param status result operation
+ at param fk fake frame structure
+*/
+static void     
+parse_section_frames(stack_config_n * cfg, 
+                     cpl_frameset* sof, cpl_frameset** raw_set,int* status, 
+                     fake* fk)
+{
+
+   int                     i;
+   const char            *       name;
+   char                        file[FILE_NAME_SZ];
+   int                     nobj, noff, ndark ;
+   int                     nditherobj, nditheroff ;
+   int                     found_sky ;
+   int                     found_ref ;
+   int                     found_dither ;
+   int                     found_dark   ;
+    int nraw=0;
+    int nsof=0;
+
+   cpl_frame* frame   = NULL;
+
+    char spat_res[FILE_NAME_SZ];
+   char lamp_status[FILE_NAME_SZ];
+   char band[FILE_NAME_SZ];
+   int ins_set=0;
+   char* tag=NULL;
+   char* do_class=NULL;
+  
+   nsof    = cpl_frameset_get_size(sof);
+
+
+   do_class=fk->pro_class;
+   /* sinfo_msg("do_class=%s",do_class); */ 
+   if(strcmp(do_class,"DEFAULT") == 0) {
+      sinfo_extract_raw_stack_frames(sof,raw_set);
+   } else if (strcmp(do_class,PRO_FIBRE_NS_STACKED_DIST) == 0) {
+      sinfo_is_fibres_on_off(sof,*raw_set);
+   } else if (strcmp(do_class,PRO_FIBRE_NS_STACKED) == 0) {
+      sinfo_contains_frames_kind(sof,*raw_set,(char*)PRO_FIBRE_NS_STACKED);
+   } else if (strcmp(do_class,RAW_STACKED_SLITPOS) == 0) {
+      sinfo_extract_raw_stack_frames(sof,raw_set);
+   } else {
+      sinfo_extract_raw_frames_type(sof,raw_set,do_class);
+   }
+   nraw    = cpl_frameset_get_size(*raw_set);
+   if (nraw < 1) {
+      sinfo_msg_error("Too few raw frames present in frameset!");
+      (*status)++;
+      return;
+   }
+
+ 
+   /* Allocate structures to go into the blackboard */
+   cfg->framelist     = cpl_malloc(nraw * sizeof(char*));
+   cfg->frametype     = cpl_malloc(nraw * sizeof(int));
+   cfg->frameposition = cpl_malloc(nraw * sizeof(int));
+
+   for (i=0;i<nraw;i++) {
+     cfg->framelist[i]=NULL;
+     cfg->frametype[i]=-1;
+     cfg->frameposition[i]=-1;
+   }
+
+   found_sky     = 0 ;
+   found_ref     = 0 ;
+   found_dither  = 0 ;
+   found_dark    = 0 ;
+   nobj          = 0 ;
+   noff          = 0 ;
+   ndark         = 0 ;
+   nditherobj    = 0 ;
+   nditheroff    = 0 ;
+
+
+
+   /* Browse through the charmatrix to get names and file types */
+   /*   for (i=0 ; i<nraw ; i++) { */
+   for (i=0 ; i<nraw ; i++) {
+      frame = cpl_frameset_get_frame(*raw_set,i);
+      name=cpl_frame_get_filename(frame);
+       if(sinfo_file_exists((char*)name)==1) {
+    /* to go on the file must exist */
+    if(cpl_frame_get_tag(frame) != NULL) {
+      /* If the frame has a tag we process it. Else it is an object */ 
+      tag= (char*) cpl_frame_get_tag(frame);
+          if((sinfo_frame_is_on(frame)  == 0) || 
+             (sinfo_frame_is_sky(frame)  == 1)) 
+      {
+             cfg->framelist[i]=cpl_strdup(cpl_frame_get_filename(frame));
+             cfg->frametype[i] = FRAME_OFF ;
+             found_sky = 1;
+             if (sinfo_frame_is_dither(frame)) 
+           {
+                cfg->frameposition[i] = FRAME_POS2 ;
+                nditheroff++ ;
+           }
+             else 
+           {
+                cfg->frameposition[i] = FRAME_POS1 ;
+                noff++ ;
+           }
+      }
+          else if(strstr(tag,RAW_REF)  != NULL) 
+      {
+          cfg->framelist[i]=cpl_strdup(cpl_frame_get_filename(frame));
+          cfg->frametype[i] = FRAME_REF ;
+              found_ref=1;
+          if (sinfo_frame_is_dither(frame))
+        {
+          cfg->frameposition[i] = FRAME_POS2 ;
+        }
+              else 
+        {
+          cfg->frameposition[i] = FRAME_POS1 ;
+        }
+      }
+          else if(sinfo_is_dark(tag)) 
+        {
+          cfg->framelist[i]=cpl_strdup(cpl_frame_get_filename(frame));
+          cfg->frametype[i] = FRAME_DRK ;
+          cfg->frameposition[i] = FRAME_POS1 ;
+              found_dark=1;
+              ndark++;
+          sinfo_msg("Frame is sinfo_dark on\n");
+        }
+          else 
+        {
+
+          cfg->framelist[i]=cpl_strdup(cpl_frame_get_filename(frame));
+          cfg->frametype[i] = FRAME_ON ;
+              found_ref=1;
+          if (sinfo_frame_is_dither(frame))
+        {
+          cfg->frameposition[i] = FRAME_POS2 ;
+                  found_dither=1;
+                  nditherobj++;
+        }
+              else 
+        {
+          cfg->frameposition[i] = FRAME_POS1 ;
+                  nobj++;
+        }
+        }
+    }
+        else 
+      {
+            /* No type means an object */
+        cfg->frametype[i] = FRAME_ON ;
+            /* No type means position 1 */
+        cfg->frameposition[i] = FRAME_POS1 ;
+            
+        nobj ++ ;
+      }
+      }
+      
+      /* Store file name into framelist */
+    }
+   
+   sinfo_msg("Noff= %d Nobj= %d Nditheroff= %d Nditherobj= %d",
+           noff,nobj,nditheroff,nditherobj);
+   
+
+
+   /* Copy relevant information into the blackboard */
+   cfg->nframes         = nraw ;
+   cfg->nobj            = nobj ;
+   cfg->noff            = noff ;
+   cfg->ndark           = ndark ;
+   cfg->nditherobj      = nditherobj ;
+   cfg->nditheroff      = nditheroff ;
+   cfg->contains_sky    = found_sky ;
+   cfg->contains_ref    = found_ref ;
+   cfg->contains_dither = found_dither ;
+   cfg->contains_dark   = found_dark ;
+
+
+   frame = cpl_frameset_get_frame(*raw_set,0);
+
+   ck0_nomsg(sinfo_get_spatial_res(frame,spat_res));
+
+
+
+   if(sinfo_frame_is_on(frame) == 1) {
+     strcpy(lamp_status,"on");
+   } else {
+     strcpy(lamp_status,"off");
+   }
+   switch(sinfo_frame_is_on(frame)) 
+     {
+   case 0: 
+      strcpy(lamp_status,"on");
+      break;
+    case 1: 
+      strcpy(lamp_status,"off");
+      break;
+    case -1:
+      strcpy(lamp_status,"undefined");
+      break;
+    default: 
+      strcpy(lamp_status,"undefined");
+      break;
+
+
+     }
+   sinfo_get_band(frame,band);
+
+
+   sinfo_msg("Spatial resolution: %s lamp status: %s band: %s",
+                     spat_res,              lamp_status,    band);
+
+   sinfo_get_ins_set(band,&ins_set);
+   frame = cpl_frameset_get_frame(*raw_set,0);
+   tag=(char*)cpl_frame_get_tag(frame);
+
+
+   /* Update flatInd setting if we had changed the mflat switch */
+    /* take care of NS test special case */
+    if(fk->frm_switch==1) {
+     /* 
+        In this case we force certain values indipendently from the 
+        setting occurring during CPL parameters parsing 
+      */
+
+    cfg->maskInd = fk->mask_index;
+    cfg->indind = fk->ind_index;
+    cfg->flatInd = fk->flat_index;
+        cfg -> loReject = fk->low_rej;
+        cfg -> hiReject = fk->hig_rej;
+        cfg -> warpfixInd =  fk->wfix_index;
+    /*
+        sinfo_msg("Fake frame: reset parameter values: ");
+        sinfo_msg("maskInd:  %d", cfg->maskInd);
+        sinfo_msg("indind:   %d", cfg->indind);
+        sinfo_msg("flatInd:  %d", cfg->flatInd);
+        sinfo_msg("loReject: %f", cfg->loReject);
+        sinfo_msg("hiReject: %f", cfg->hiReject);
+    */
+   }
+  
+  
+
+
+ 
+   if(cfg -> flatInd) { 
+      if(NULL != cpl_frameset_find(sof,PRO_MASTER_FLAT_LAMP)) {
+         frame = cpl_frameset_find(sof,PRO_MASTER_FLAT_LAMP);
+         strcpy(file,cpl_frame_get_filename(frame));
+         strcpy(cfg -> flatfield1, file);
+      } else if(NULL != cpl_frameset_find(sof,PRO_MASTER_FLAT_LAMP1)) {
+         frame = cpl_frameset_find(sof,PRO_MASTER_FLAT_LAMP1);
+         strcpy(file,cpl_frame_get_filename(frame));
+         strcpy(cfg -> flatfield1, file);
+      } else {
+         sinfo_msg_error("Frame %s not found!", PRO_MASTER_FLAT_LAMP);
+         sinfo_msg_error("Frame %s not found!", PRO_MASTER_FLAT_LAMP1);
+         sinfo_stack_free_alloc(cfg);  
+         (*status)++;
+         return;
+      }
+
+      if(found_dither) {
+         if(NULL != cpl_frameset_find(sof,PRO_MASTER_FLAT_LAMP2)) {
+            frame = cpl_frameset_find(sof,PRO_MASTER_FLAT_LAMP2);
+            strcpy(file,cpl_frame_get_filename(frame));
+            strcpy(cfg -> flatfield2, file);
+         } else {
+            sinfo_msg("Frame %s not found!", PRO_MASTER_FLAT_LAMP2);
+         }
+      }
+   }
+
+   /* bad pixel section */
+   if(cfg->maskInd != 0) {
+     if(strstr(do_class,"FIBRE_NS") != NULL) {
+        if(NULL != cpl_frameset_find(sof,PRO_BP_MAP_DI)) {
+           frame = cpl_frameset_find(sof,PRO_BP_MAP_DI);
+           strcpy(file,cpl_frame_get_filename(frame));
+           strcpy(cfg -> mask, file);
+        } else {
+           sinfo_msg_error("Frame %s not found!", PRO_BP_MAP_DI);
+           sinfo_stack_free_alloc(cfg);  
+           (*status)++;
+           return;
+        }
+
+     } else {
+
+        if(NULL != cpl_frameset_find(sof,PRO_MASTER_BP_MAP)) {
+           frame = cpl_frameset_find(sof,PRO_MASTER_BP_MAP);
+           strcpy(file,cpl_frame_get_filename(frame));
+           strcpy(cfg -> mask, file);
+        } else {
+           sinfo_msg_error("Frame %s not found!", PRO_MASTER_BP_MAP);
+           sinfo_stack_free_alloc(cfg);  
+           (*status)++;
+           return;
+        }
+
+     }
+
+     if (strcmp(do_class,RAW_STACKED_SLITPOS) == 0) {
+       cfg -> indind = 1;
+     }
+
+      if(cfg -> indind == 0) { 
+          if(NULL != cpl_frameset_find(sof,PRO_SLIT_POS)) {
+            frame = cpl_frameset_find(sof,PRO_SLIT_POS);
+            strcpy(file,cpl_frame_get_filename(frame));
+            strcpy(cfg -> slitposList, file);
+            sinfo_msg("Using %s to interpolate bad pixels",
+                             PRO_SLIT_POS);
+            cpl_error_reset();
+          } else if(NULL != cpl_frameset_find(sof,PRO_SLIT_POS_GUESS)) {
+            frame = cpl_frameset_find(sof,PRO_SLIT_POS_GUESS);
+            strcpy(file,cpl_frame_get_filename(frame));
+            strcpy(cfg -> slitposList, file);
+            sinfo_msg("Using %s to interpolated bad pixels",
+                             PRO_SLIT_POS_GUESS);
+            cpl_error_reset();
+          } else {
+            sinfo_msg_error("Frame %s nor %s found!", 
+                              PRO_SLIT_POS,PRO_SLIT_POS_GUESS);
+            sinfo_stack_free_alloc(cfg);  
+            (*status)++;
+            return;
+          }
+
+     
+      }
+      if(cfg -> maskInd == 2) {
+         if(NULL != cpl_frameset_find(sof,PRO_INDEX_LIST)) {
+            frame = cpl_frameset_find(sof,PRO_INDEX_LIST);
+            strcpy(file,cpl_frame_get_filename(frame));
+            strcpy(cfg ->indexlist, file);
+         } else {
+            sinfo_msg_error("Frame %s not found!", PRO_INDEX_LIST);
+            sinfo_stack_free_alloc(cfg);  
+            (*status)++;
+            return;
+         }
+
+      }
+   }
+
+   cfg -> warpfixInd =  fk->wfix_index;
+   if(cfg->warpfixInd != 0) {
+        if(NULL != cpl_frameset_find(sof,PRO_DISTORTION)) {
+            frame = cpl_frameset_find(sof,PRO_DISTORTION);
+            strcpy(file,cpl_frame_get_filename(frame));
+            strcpy(cfg -> polyFile, file);
+         } else {
+            sinfo_msg_error("Frame %s not found!", PRO_DISTORTION);
+            sinfo_stack_free_alloc(cfg);  
+            (*status)++;
+            return;
+         }
+   }
+
+   if(NULL != cpl_frameset_find(sof,PRO_MASTER_DARK)) {
+     frame = cpl_frameset_find(sof,PRO_MASTER_DARK);
+     strcpy(file,cpl_frame_get_filename(frame));
+     strcpy(cfg -> mdark, file);
+     cfg->mdark_ind=1;
+
+   } else {
+     sinfo_msg("Frame %s not found", PRO_MASTER_DARK);
+     cfg->mdark_ind=0;
+   }
+
+  cleanup:
+   return ;
+}
+
+/**
+ at brief reads parameters for clean mean
+ at name parse_section_cleanmean
+ at param stack_config_n configuration structure
+ at param cpl_config parameter list
+
+*/
+static void     
+parse_section_cleanmean(stack_config_n * cfg,cpl_parameterlist* cpl_cfg)
+{
+
+   cpl_parameter* p;
+   p = cpl_parameterlist_find(cpl_cfg,"sinfoni.stacked.low_rejection");
+   cfg -> loReject = cpl_parameter_get_double(p);
+
+   p = cpl_parameterlist_find(cpl_cfg,"sinfoni.stacked.high_rejection");
+   cfg -> hiReject = cpl_parameter_get_double(p);
+
+        return ;
+}
+/**
+ at brief reads parameters for flatfield
+ at name parse_section_flatfield
+ at param stack_config_n configuration structure
+ at param cpl_config parameter list
+*/
+static void     
+parse_section_flatfield(stack_config_n * cfg,cpl_parameterlist* cpl_cfg)
+{
+
+   cpl_parameter* p;
+   p = cpl_parameterlist_find(cpl_cfg,"sinfoni.stacked.flat_index");
+   cfg -> flatInd = cpl_parameter_get_bool(p);
+
+}
+/**
+ at brief reads parameters for bad pixel search
+ at name parse_section_badpixel
+ at param stack_config_n configuration structure
+ at param cpl_config parameter list
+*/
+static void     
+parse_section_badpixel(stack_config_n * cfg,cpl_parameterlist* cpl_cfg)
+{
+  cpl_parameter* p;
+
+
+   p = cpl_parameterlist_find(cpl_cfg,"sinfoni.stacked.ind_index");
+   cfg -> indind = cpl_parameter_get_bool(p);
+
+   p = cpl_parameterlist_find(cpl_cfg,"sinfoni.stacked.mask_index");
+   cfg -> maskInd = cpl_parameter_get_int(p);
+
+   p = cpl_parameterlist_find(cpl_cfg,"sinfoni.stacked.mask_rad");
+   cfg -> maxRad = cpl_parameter_get_int(p);
+   /*
+   p = cpl_parameterlist_find(cpl_cfg,"sinfoni.stacked.sigma_factor");
+   */
+   cfg -> sigmaFactor = 3.;
+
+}
+/**
+ at brief reads parameters for frame interleaving
+ at name parse_section_interleaving
+ at param stack_config_n configuration structure
+*/
+static void     
+parse_section_interleaving(stack_config_n * cfg)
+{
+   cfg -> interInd = 0;
+   cfg -> noRows = 400;
+
+}
+/**
+ at brief reads parameters for Gaussian convolution
+ at name parse_section_gaussconvolution
+ at param stack_config_n configuration structure
+ at param cpl_config parameter list
+*/
+static void     
+parse_section_gaussconvolution(stack_config_n * cfg,cpl_parameterlist* cpl_cfg)
+{
+
+   cpl_parameter* p;
+   p = cpl_parameterlist_find(cpl_cfg,"sinfoni.stacked.gauss_index");
+   cfg -> gaussInd = cpl_parameter_get_bool(p);
+
+   p = cpl_parameterlist_find(cpl_cfg,"sinfoni.stacked.kernel_half_width");
+   cfg -> hw = cpl_parameter_get_int(p);
+
+}
+/**
+ at brief reads parameters for frame shift
+ at name parse_section_shiftframes
+ at param stack_config_n configuration structure
+*/
+static void     
+parse_section_shiftframes(stack_config_n * cfg)
+{
+  /*
+   cpl_parameter* p;
+   p = cpl_parameterlist_find(cpl_cfg,"sinfoni.stacked.shift_frame_index");
+   cfg -> sfInd  = cpl_parameter_get_bool(p);
+
+   p = cpl_parameterlist_find(cpl_cfg,"sinfoni.stacked.shift_frame_type");
+   cfg -> sfType = cpl_parameter_get_int(p);
+
+   p = cpl_parameterlist_find(cpl_cfg,"sinfoni.stacked.shift_frame_order");
+   cfg -> sfOrder = cpl_parameter_get_int(p);
+  */
+
+   cfg -> sfInd  = 0;
+   cfg -> sfType = 1;
+   cfg -> sfOrder = 2;
+
+}
+/**
+ at brief reads parameters for warping
+ at name parse_section_warpfix
+ at param stack_config_n configuration structure
+ at param cpl_config parameter list
+*/
+static void     
+parse_section_warpfix(stack_config_n * cfg,cpl_parameterlist * cpl_cfg)
+{
+       
+   cpl_parameter* p;
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.stacked.warpfix_ind");
+   cfg -> warpfixInd =  cpl_parameter_get_bool(p);
+
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.stacked.warpfix_kernel");
+   strcpy(cfg -> kernel, cpl_parameter_get_string(p));
+
+   return ;
+}
+
+/**
+ at brief reads parameters for qclog
+ at name parse_section_cleanmean
+ at param stack_config_n configuration structure
+ at param cpl_config parameter list
+*/
+static void     
+parse_section_qclog(stack_config_n * cfg,cpl_parameterlist * cpl_cfg)
+{
+       
+   cpl_parameter* p;
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.stacked.qc_thresh_min");
+   cfg -> qc_thresh_min =  cpl_parameter_get_int(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.stacked.qc_thresh_max");
+   cfg -> qc_thresh_max =  cpl_parameter_get_int(p);
+
+   return ;
+}
+/**
+ at brief free memory
+ at name sinfo_stack_free
+ at param stack_config_n configuration structure
+*/
+void
+sinfo_stack_free(stack_config_n ** cfg)
+{  
+  if(*cfg != NULL) {
+    sinfo_stack_free_alloc(*cfg);
+    sinfo_stack_cfg_destroy_n(*cfg);
+    *cfg = NULL;
+  }
+  return;
+
+}
+
+/**
+ at brief free memory
+ at name sinfo_stack_free_alloc
+ at param stack_config_n configuration structure
+*/
+static void
+sinfo_stack_free_alloc(stack_config_n * cfg)
+{  
+  int i=0;
+  for (i=0; i< cfg->nframes; i++) {
+    if(cfg->framelist[i]  != NULL) {
+        cpl_free(cfg->framelist[i]);
+             cfg->framelist[i]=NULL;
+    }
+  }
+  if(cfg->frametype != NULL) {
+    cpl_free(cfg->frametype); 
+    cfg->frametype=NULL;
+  }
+  if(cfg->framelist != NULL)   {
+    cpl_free(cfg->framelist); 
+    cfg->framelist=NULL;
+  }
+  if(cfg->frameposition != NULL) {
+    cpl_free(cfg->frameposition); 
+    cfg->frameposition=NULL;
+  }
+}
+/**@}*/
diff --git a/sinfoni/sinfo_stack_ini_by_cpl.h b/sinfoni/sinfo_stack_ini_by_cpl.h
new file mode 100644
index 0000000..48d51c5
--- /dev/null
+++ b/sinfoni/sinfo_stack_ini_by_cpl.h
@@ -0,0 +1,69 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+   
+   File name    :   stack_ini_by_cpl.h
+   Author       :   Andrea Modigliani
+   Created on   :   May 23, 2004
+   Description  :   preparing stack of frames cpl input handling for SPIFFI
+ ---------------------------------------------------------------------------*/
+#ifndef SINFO_STACK_INI_BY_CPL_H
+#define SINFO_STACK_INI_BY_CPL_H
+/*---------------------------------------------------------------------------
+                                Includes
+---------------------------------------------------------------------------*/
+#include <cpl.h>
+#include "sinfo_msg.h"
+#include "sinfo_globals.h"
+#include "sinfo_stack_cfg.h"
+/*---------------------------------------------------------------------------
+                                Defines
+---------------------------------------------------------------------------*/
+#define FRAME_OFF    0  /* off frames, that means sky frames 
+                           or calibration frames with lamp switched off */
+#define FRAME_ON     1  /* object frames */
+#define FRAME_POS1   2  /* frames exposed with grating position 1 */
+#define FRAME_POS2   3  /* frames exposed with dithered grating position 2 */
+#define FRAME_REF    4  /* reference frames */
+#define FRAME_DRK    5  /* sinfo_dark frame*/
+/*----------------------------------------------------------------------------
+                             Function prototypes 
+ ---------------------------------------------------------------------------*/
+/* generateStack_ini_file */
+/**
+  @name     parse_stack_ini_file
+  @memo     Parse a ini_name.ini file and create a blackboard.
+  @param    cpl_cfg pointer to parameterlist
+  @param    sof pointer to input set of frames
+  @param    raw pointer to input set of raw frames
+  @return   1 newly allocated stack_config blackboard structure.
+  @doc
+
+  The requested ini file is parsed and a blackboard object is created, then
+  updated accordingly. Returns NULL in case of error.
+ */
+/*--------------------------------------------------------------------------*/
+stack_config_n * 
+sinfo_parse_cpl_input_stack(cpl_parameterlist * cpl_cfg, 
+                            cpl_frameset* sof, 
+                            cpl_frameset** raw, 
+                            fake* fk) ;
+void sinfo_stack_free(stack_config_n ** cfg);
+
+#endif
diff --git a/sinfoni/sinfo_stacked_hidden_config.c b/sinfoni/sinfo_stacked_hidden_config.c
new file mode 100644
index 0000000..b40214e
--- /dev/null
+++ b/sinfoni/sinfo_stacked_hidden_config.c
@@ -0,0 +1,83 @@
+/* $Id: sinfo_stacked_hidden_config.c,v 1.5 2012/03/03 10:18:26 amodigli Exp $
+ *
+ * This file is part of the CPL (Common Pipeline Library)
+ * Copyright (C) 2002 European Southern Observatory
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*
+ * $Author: amodigli $
+ * $Date: 2012/03/03 10:18:26 $
+ * $Revision: 1.5 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+ /**************************************************************************
+  *  Prepare_Stacked_Frames Frames Data Reduction Parameter Initialization *
+  **************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#include "sinfo_stacked_hidden_config.h"
+/**@{*/
+/**
+ * @addtogroup sinfo_rec_jitter Objnod structure configuration
+ *
+ * TBD
+ */
+
+
+/**
+ at name sinfo_stacked_hidden_config_add
+ at param list pointer to input parameter list]
+ at return void
+*/
+void
+ sinfo_stacked_hidden_config_add(cpl_parameterlist *list)
+{
+
+  cpl_parameter *p;
+
+  if (!list) {
+    return;
+  }
+
+
+/*
+  --------------------------------------------------------------------------
+  In/Out  
+  --------------------------------------------------------------------------
+ */
+
+
+
+  /* Output file name */
+  /* output name of resulting fits wavelength map */
+  p = cpl_parameter_new_value("sinfoni.stacked.output_filename",
+                  CPL_TYPE_STRING,
+                              "Output File Name: ",
+                              "sinfoni.stacked",
+                              "out_stack.fits");
+
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"out-stack_filename");
+  cpl_parameterlist_append(list, p);
+
+
+
+
+}
diff --git a/sinfoni/sinfo_stacked_hidden_config.h b/sinfoni/sinfo_stacked_hidden_config.h
new file mode 100644
index 0000000..1de4b29
--- /dev/null
+++ b/sinfoni/sinfo_stacked_hidden_config.h
@@ -0,0 +1,33 @@
+/* $Id: sinfo_stacked_hidden_config.h,v 1.1 2006/10/20 08:06:33 amodigli Exp $
+ *
+ * This file is part of the CPL (Common Pipeline Library)
+ * Copyright (C) 2002 European Southern Observatory
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*
+ * $Author: amodigli $
+ * $Date: 2006/10/20 08:06:33 $
+ * $Revision: 1.1 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+ /****************************************************************
+  *   Prepare_Stacked_Frames Frames Data Reduction Parameter Initialization 
+  ****************************************************************/
+#include "cpl.h"    /* defines parlist structure */
+
+void
+sinfo_stacked_hidden_config_add(cpl_parameterlist *list);
diff --git a/sinfoni/sinfo_standard_star_config.c b/sinfoni/sinfo_standard_star_config.c
new file mode 100644
index 0000000..f5c6369
--- /dev/null
+++ b/sinfoni/sinfo_standard_star_config.c
@@ -0,0 +1,154 @@
+/* $Id: sinfo_standard_star_config.c,v 1.7 2012/03/03 10:18:26 amodigli Exp $
+ *
+ * This file is part of the CPL (Common Pipeline Library)
+ * Copyright (C) 2002 European Southern Observatory
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*
+ * $Author: amodigli $
+ * $Date: 2012/03/03 10:18:26 $
+ * $Revision: 1.7 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+ /****************************************************************
+  *   Standard_Star Frames Data Reduction Parameter Initialization        *
+  ****************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#include <string.h>
+#include "sinfo_standard_star_config.h"
+/**@{*/
+/**
+ * @addtogroup sinfo_rec_jitter Define and initialize std star parameters
+ *
+ * TBD
+ */
+
+
+/**
+ at name sinfo_standard_star_config_add
+ at param list pointer to input parameter list
+ at return void
+*/
+void
+ sinfo_standard_star_config_add(cpl_parameterlist *list)
+{
+
+  cpl_parameter *p;
+
+  if (!list) {
+    return;
+  }
+
+
+/*
+  --------------------------------------------------------------------------
+  In/Out  
+  --------------------------------------------------------------------------
+ */
+
+  /* switch to generate the extracted spectrum */
+  /*
+  p = cpl_parameter_new_value("sinfoni.std_star.qc_info",
+                  CPL_TYPE_BOOL,
+                              "Switch to activate extra QC information "
+                              "together with the spectrum",
+                              "sinfoni.std_star",
+                              FALSE);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"std_star-qc_info");
+  cpl_parameterlist_append(list, p);
+  */
+
+  p = cpl_parameter_new_value("sinfoni.std_star.switch",
+                  CPL_TYPE_BOOL,
+                              "Switch to activate spectrum extraction",
+                              "sinfoni.std_star",
+                              TRUE);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"std_star-switch");
+  cpl_parameterlist_append(list, p);
+
+/* the fraction [0...1] of rejected low intensity pixels when taking 
+the average of columns */
+  p = cpl_parameter_new_value("sinfoni.std_star.low_rejection",
+                  CPL_TYPE_DOUBLE,
+                              "lower rejection",
+                              "sinfoni.std_star",
+                              0.1);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"std_star-lo_rej");
+  cpl_parameterlist_append(list, p);
+
+ /* the fraction [0...1] of rejected high intensity pixels when taking 
+the average of columns */
+  p = cpl_parameter_new_value("sinfoni.std_star.high_rejection",
+                  CPL_TYPE_DOUBLE,
+                              "high rejection",
+                              "sinfoni.std_star",
+                              0.1);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"std_star-hi_rej");
+  cpl_parameterlist_append(list, p);
+
+
+/* factor applied to the found fwhms of a 2D-Gaussian fit, defines the radius 
+   of the aperture inside which the spectral extraction is carried out.
+ */
+  p = cpl_parameter_new_value("sinfoni.std_star.fwhm_factor",
+                  CPL_TYPE_DOUBLE,
+                              "Factor to find 2D-Gauss FWHM. "
+                              "The extraction box is: "
+                              "halfbox_x=halfbox_y="
+                              "fwhm_factor*(fwhm_x+fwhm_y)*0.5",
+                              "sinfoni.std_star",
+                              5.0);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"std_star-fwhm_fct");
+  cpl_parameterlist_append(list, p);
+
+
+/* indicator if the intensity conversion factor should be determined or not
+ */
+
+
+  p = cpl_parameter_new_value("sinfoni.std_star.conversion_index",
+                  CPL_TYPE_BOOL,
+                              "Intensity Conversion Index: ",
+                              "sinfoni.std_star",
+                              TRUE);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"std_star-conv_ind");
+  cpl_parameterlist_append(list, p);
+
+  p = cpl_parameter_new_value("sinfoni.std_star.compute_eff",
+			      CPL_TYPE_BOOL,
+                              "Compute efficiency: TRUE/FALSE",
+                              "sinfoni.std_star",
+                              TRUE);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"std_star-compute_eff");
+  cpl_parameterlist_append(list, p);
+
+
+
+
+}
+/**@}*/
diff --git a/sinfoni/sinfo_standard_star_config.h b/sinfoni/sinfo_standard_star_config.h
new file mode 100644
index 0000000..d1647c4
--- /dev/null
+++ b/sinfoni/sinfo_standard_star_config.h
@@ -0,0 +1,33 @@
+/* $Id: sinfo_standard_star_config.h,v 1.1 2006/10/20 08:06:33 amodigli Exp $
+ *
+ * This file is part of the CPL (Common Pipeline Library)
+ * Copyright (C) 2002 European Southern Observatory
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*
+ * $Author: amodigli $
+ * $Date: 2006/10/20 08:06:33 $
+ * $Revision: 1.1 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+ /****************************************************************
+  *   Standard_Star Frames Data Reduction Parameter Initialization        *
+  ****************************************************************/
+#include "cpl.h"    /* defines parlist structure */
+void
+sinfo_standard_star_config_add(cpl_parameterlist *list);
+
diff --git a/sinfoni/sinfo_standstar_cfg.c b/sinfoni/sinfo_standstar_cfg.c
new file mode 100644
index 0000000..c47eb00
--- /dev/null
+++ b/sinfoni/sinfo_standstar_cfg.c
@@ -0,0 +1,86 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/*---------------------------------------------------------------------------
+   
+   File name     :    sinfo_standstar_cfg.c
+   Author     :       Juergen Schreiber
+   Created on    :    March 2002
+   Description    :    configuration handling tools for the 
+                        standard star data reduction
+
+ *--------------------------------------------------------------------------*/
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+/*---------------------------------------------------------------------------
+                                   Includes
+ ---------------------------------------------------------------------------*/
+
+#include "sinfo_standstar_cfg.h"
+
+/**@{*/
+/**
+ * @addtogroup sinfo_rec_jitter std star structure configuration
+ *
+ * TBD
+ */
+
+/*---------------------------------------------------------------------------
+                              Function codes
+ ---------------------------------------------------------------------------*/
+
+/*---------------------------------------------------------------------------
+   @name   sinfo_standstar_cfg_create()
+   @param  void
+   @return pointer to allocated base standstar_config structure
+   @brief  allocate memory for a standstar_config struct
+   @note   only the main (base) structure is allocated
+ ---------------------------------------------------------------------------*/
+
+standstar_config * sinfo_standstar_cfg_create(void)
+{
+    return cpl_calloc(1, sizeof(standstar_config));
+}
+
+
+/*---------------------------------------------------------------------------
+   @name    sinfo_standstar_cfg_destroy()
+   @param   cc   standstar_config to deallocate
+   @return  void
+   @brief   deallocate all memory associated with a \
+            standstar_config data structure
+     
+ ---------------------------------------------------------------------------*/
+
+void sinfo_standstar_cfg_destroy(standstar_config * cc)
+{
+    if (cc==NULL) return ;
+
+    /* Free main struct */
+    cpl_free(cc);
+
+    return ;
+}
+
+/**@}*/
+
+
diff --git a/sinfoni/sinfo_standstar_cfg.h b/sinfoni/sinfo_standstar_cfg.h
new file mode 100644
index 0000000..30ae953
--- /dev/null
+++ b/sinfoni/sinfo_standstar_cfg.h
@@ -0,0 +1,135 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/*---------------------------------------------------------------------------
+   
+   File name     :    sinfo_standstar_cfg.h
+   Author    :    Juergen Schreiber
+   Created on    :    March 2002
+   Description    :    standstar_ini definitions + handling prototypes
+
+ ---------------------------------------------------------------------------*/
+
+
+#ifndef SINFO_STANDSTAR_CFG_H
+#define SINFO_STANDSTAR_CFG_H
+
+/*---------------------------------------------------------------------------
+                                   Includes
+ ---------------------------------------------------------------------------*/
+
+#include <stdlib.h>
+#include "sinfo_globals.h"
+#include <cpl.h>
+
+
+/*---------------------------------------------------------------------------
+                                   Defines
+ ---------------------------------------------------------------------------*/
+
+
+/*---------------------------------------------------------------------------
+                                   New types
+ ---------------------------------------------------------------------------*/
+
+
+/*
+  standard star data reduction blackboard container
+
+  This structure holds all information related to the standard 
+  star data reduction
+  routine. It is used as a container for the flux of ancillary data,
+  computed values, and algorithm status. Pixel flux is separated from
+  the blackboard.
+  */
+
+typedef struct standstar_config {
+/*-------General---------*/
+        char inFile[FILE_NAME_SZ]  ;/* input file of reduced jittered 
+                                       data cubes of a standard star */
+        char ** inFrameList ; /* input list of cubes */
+        int     nframes ;         /* number of input frames */
+        char outName[FILE_NAME_SZ] ; /* output name of resulting 
+                                        extracted spectrum stored 
+                                        as fits image */
+
+/*------ spectral extraction and determination of conversion factor ------*/
+        /* the fraction [0...1] of rejected low intensity pixels when 
+           taking the average of jittered spectra */
+        float lo_reject ;
+        /* the fraction [0...1] of rejected high intensity pixels when 
+           taking the average of jittered spectra */
+        float hi_reject ;
+        /* lower left sinfo_edge coordinates of fitting box for 
+           2d Gaussian fit */
+        int llx ;
+        int lly ;
+        /* size of a box inside which the 2D-Gaussian fit is carried through */
+        int halfbox_x ;
+        int halfbox_y ;
+    
+        /* factor applied to the found fwhms of a 2D-Gaussian
+           fit, defines the radius of the aperture from which the
+           spectral extraction is carried out (default: 0.7). */
+        float fwhm_factor ;
+        /* (readnoise^2 + sinfo_dark current) needed to determine the 
+           noise variance of the background. Must be given in counts/sec. */
+        float backvariance ;
+        /* estimated sky counts/sec */
+        float sky ;
+        /* gain: counts per electron */
+        float gain ;
+        /* indicator if an intensity conversion factor should be 
+           determined or not */
+        int convInd ;      
+        /* name of the ASCII file that stores the intensity conversion factor */
+        char convName[FILE_NAME_SZ] ;      
+        /* magnitude of the standard star */
+        float mag ;      
+} standstar_config ;
+
+
+
+/*---------------------------------------------------------------------------
+                               Function prototypes
+ ---------------------------------------------------------------------------*/
+
+
+/*---------------------------------------------------------------------------
+   Function :   sinfo_standstar_cfg_create()
+   In       :   void
+   Out      :   pointer to allocated base standstar_config structure
+   Job      :   allocate memory for a standstar_config struct
+   Notice   :   only the main (base) structure is allocated
+ ---------------------------------------------------------------------------*/
+
+standstar_config * sinfo_standstar_cfg_create(void);
+
+
+/*---------------------------------------------------------------------------
+   Function :   sinfo_standstar_cfg_destroy()
+   In       :   standstar_config to deallocate
+   Out      :   void
+   Job      :   deallocate all memory associated with a 
+                standstar_config data structure
+   Notice   :   
+ ---------------------------------------------------------------------------*/
+void sinfo_standstar_cfg_destroy(standstar_config * cc);
+
+#endif
diff --git a/sinfoni/sinfo_standstar_ini.h b/sinfoni/sinfo_standstar_ini.h
new file mode 100644
index 0000000..f58ceec
--- /dev/null
+++ b/sinfoni/sinfo_standstar_ini.h
@@ -0,0 +1,88 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/*----------------------------------------------------------------------------
+   
+   File name    :   sinfo_standstar_ini.h
+   Author       :    Juergen Schreiber
+   Created on   :    Mar 25, 2002
+   Description  :    ini file handling for SINFONI data reduction 
+                        of a standard star
+
+ ---------------------------------------------------------------------------*/
+
+
+#ifndef SINFO_STANDSTAR_INI_H
+#define SINFO_STANDSTAR_INI_H
+
+
+/*---------------------------------------------------------------------------
+                                Includes
+---------------------------------------------------------------------------*/
+
+#include <cpl.h>
+#include "standstar_cfg.h"
+
+ 
+ 
+/*----------------------------------------------------------------------------
+                             Function prototypes 
+ ---------------------------------------------------------------------------*/
+
+
+/*-------------------------------------------------------------------------*/
+/**
+  @name        generateStandstar_ini_file
+  @memo        Generate a default ini file for the data reduction 
+                of a standard star.
+  @param    ini_name    Name of the file to generate.
+  @param    name_i        Name of the input file.
+  @param    name_o        Name of the output file.
+  @return    int 0 if Ok, -1 otherwise.
+  @doc
+
+  This function generates a default ini file for the reduction 
+  of standard star data command. The
+  generated file will have the requested name. If you do not want to
+  provide names for the input/output/calib files, feed either NULL pointers
+  or character strings starting with (char)0.
+ */
+/*--------------------------------------------------------------------------*/
+int generateStandstar_ini_file(
+        char * ini_name,
+        char * name_i,
+        char * name_o
+);
+
+/*-------------------------------------------------------------------------*/
+/**
+  @name     parse_standstar_ini_file
+  @memo     Parse a ini_name.ini file and create a blackboard.
+  @param    ini_name    Name of the ASCII file to parse.
+  @return   1 newly allocated standstar_config blackboard structure.
+  @doc
+
+  The requested ini file is parsed and a blackboard object is created, then
+  updated accordingly. Returns NULL in case of error.
+ */
+/*--------------------------------------------------------------------------*/
+
+standstar_config * parse_standstar_ini_file(char * ini_name) ;
+
+#endif
diff --git a/sinfoni/sinfo_standstar_ini_by_cpl.c b/sinfoni/sinfo_standstar_ini_by_cpl.c
new file mode 100644
index 0000000..7073d7f
--- /dev/null
+++ b/sinfoni/sinfo_standstar_ini_by_cpl.c
@@ -0,0 +1,252 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/*----------------------------------------------------------------------------
+   
+   File name    :   sinfo_standstar_ini_by_cpl.c
+   Author       :   Andrea Modigliani
+   Created on   :   May 23, 2004
+   Description  :   standard star reduction cpl input handling for SPIFFI
+
+ ---------------------------------------------------------------------------*/
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+
+/*---------------------------------------------------------------------------
+                                Includes
+ ---------------------------------------------------------------------------*/
+#include <string.h>
+#include "sinfo_standstar_ini_by_cpl.h"
+#include "sinfo_pro_types.h"
+#include "sinfo_hidden.h"
+#include "sinfo_functions.h"
+#include "sinfo_file_handling.h"
+
+
+
+/*---------------------------------------------------------------------------
+                    Functions private to this module
+ ---------------------------------------------------------------------------*/
+
+static void 
+parse_section_frames(standstar_config *,
+                    cpl_frameset* sof, 
+                    cpl_frameset** raw, 
+                    int* status);
+static void 
+parse_section_extraction(standstar_config *, cpl_parameterlist* cpl_cfg);
+/**@{*/
+/**
+ * @addtogroup sinfo_rec_jitter blackboard for standard star structure 
+ *  configuration
+ *
+ * TBD
+ */
+
+
+/*-------------------------------------------------------------------------*/
+/**
+  @name     parse_standstar_ini_file
+  @memo     Parse a ini_name.ini file and create a blackboard.
+  @param    ini_name    Name of the ASCII file to parse.
+  @return   1 newly allocate standstar_config blackboard structure.
+  @doc
+
+  The requested ini file is parsed and a blackboard object is created, then
+  updated accordingly. Returns NULL in case of error.
+ */
+/*--------------------------------------------------------------------------*/
+
+standstar_config * 
+sinfo_parse_cpl_input_standstar(cpl_parameterlist* cpl_cfg, 
+                                cpl_frameset* sof, 
+                                cpl_frameset** raw)
+{
+
+        standstar_config   *  cfg = sinfo_standstar_cfg_create();
+        int status=0;
+        /*
+         * Perform sanity checks, fill up the structure with what was
+         * found in the ini file
+         */
+        parse_section_extraction   (cfg, cpl_cfg);
+        parse_section_frames       (cfg, sof, raw,&status);
+        if (status > 0) {
+                sinfo_msg_error("parsing cpl input");
+                sinfo_standstar_cfg_destroy(cfg);
+                cfg = NULL ;
+                return NULL ;
+        }
+        return cfg ;
+}
+
+static void     
+parse_section_frames(standstar_config * cfg,
+             cpl_frameset* sof,
+             cpl_frameset** raw,
+                     int* status)
+{
+    int                     i;
+    int                     nval ;
+    cpl_frame*      frame=NULL;
+   char spat_res[FILE_NAME_SZ];
+   char lamp_status[FILE_NAME_SZ];
+   char band[FILE_NAME_SZ];
+   int ins_set=0;
+   cpl_frameset* tmp=NULL;
+    /* AMO BEWARE only STD frames should be here checked for */
+    sinfo_extract_frames_group_type(sof,&tmp,CPL_FRAME_GROUP_PRODUCT);
+    sinfo_extract_raw_frames_type(tmp,raw,PRO_COADD_STD);
+    cpl_frameset_delete(tmp);
+    nval = cpl_frameset_get_size(*raw);
+    if (nval < 1) {
+       sinfo_extract_raw_frames_type(sof,raw,PRO_OBS_STD);
+    }
+    nval = cpl_frameset_get_size(*raw);
+    if (nval < 1) {
+       sinfo_extract_raw_frames_type(sof,raw,PRO_COADD_PSF);
+    }
+    nval = cpl_frameset_get_size(*raw);
+    if (nval < 1) {
+       sinfo_extract_raw_frames_type(sof,raw,PRO_OBS_PSF);
+    }
+    nval = cpl_frameset_get_size(*raw);
+    if (nval < 1) {
+       sinfo_extract_raw_frames_type(sof,raw,PRO_COADD_OBJ);
+    }
+    nval = cpl_frameset_get_size(*raw);
+    if (nval < 1) {
+       sinfo_extract_raw_frames_type(sof,raw,PRO_OBS_OBJ);
+    }
+    nval = cpl_frameset_get_size(*raw);
+    if (nval < 1) {
+      sinfo_msg_error("Too few (%d) raw frames "
+                          "(%s or %s or %s or %s or %s or %s ) "
+              "present in frameset!Aborting...",nval,
+              PRO_COADD_STD,PRO_OBS_STD,
+              PRO_COADD_PSF,PRO_OBS_PSF,
+              PRO_COADD_OBJ,PRO_OBS_OBJ);
+          (*status)++;
+          return;
+    } 
+
+    /* Allocate structures to go into the blackboard */
+    cfg->inFrameList     = cpl_malloc(nval * sizeof(char*));
+    /* Browse through the charmatrix to get names and file types */
+  /* read input frames */
+   for (i=0 ; i<nval ; i++) {
+      frame = cpl_frameset_get_frame(*raw,i);
+      if(sinfo_file_exists((char*) cpl_frame_get_filename(frame))==1) 
+    {
+         /* Store file name into framelist */
+          cfg->inFrameList[i]=cpl_strdup(cpl_frame_get_filename(frame));
+    }
+   }
+ 
+   /* Copy relevant information into the blackboard */
+   cfg->nframes         = nval ;
+
+   strcpy(cfg -> outName, STDSTAR_OUT_FILENAME);
+   
+
+
+
+
+   frame = cpl_frameset_get_frame(*raw,0);
+
+   sinfo_get_spatial_res(frame,spat_res);
+  switch(sinfo_frame_is_on(frame)) 
+    {
+
+    case 0: 
+      strcpy(lamp_status,"on");
+      break;
+    case 1: 
+      strcpy(lamp_status,"off");
+      break;
+    case -1:
+      strcpy(lamp_status,"undefined");
+      break;
+    default: 
+      strcpy(lamp_status,"undefined");
+      break;
+    }
+   sinfo_get_band(frame,band);
+   sinfo_msg("Spatial resolution: %s lamp_status: %s band: %s",
+                     spat_res,    lamp_status,    band);
+
+
+   sinfo_get_ins_set(band,&ins_set);
+   return ;
+}
+
+static void     
+parse_section_extraction(standstar_config * cfg,cpl_parameterlist* cpl_cfg)
+{
+   cpl_parameter* p;
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.std_star.low_rejection");
+   cfg -> lo_reject = cpl_parameter_get_double(p);
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.std_star.high_rejection");
+   cfg -> hi_reject =  cpl_parameter_get_double(p);
+
+   cfg -> llx = 8;
+   cfg -> lly = 8;
+   cfg -> halfbox_x = 16;
+   cfg -> halfbox_y = 16;
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.std_star.fwhm_factor");
+   cfg -> fwhm_factor =  cpl_parameter_get_double(p);
+
+   cfg -> backvariance =  BKG_VARIANCE;
+   cfg -> sky = SKY_FLUX;
+   cfg -> gain = GAIN ;
+
+   p = cpl_parameterlist_find(cpl_cfg, "sinfoni.std_star.conversion_index");
+   cfg -> convInd = cpl_parameter_get_bool(p);
+ 
+   strcpy(cfg -> convName, STDSTAR_CONV_OUT_FILENAME);
+ 
+   cfg -> mag = 0;
+
+ 
+   return ;
+}
+
+void
+sinfo_stdstar_free(standstar_config  ** cfg)
+{
+  int i=0;
+  if((*cfg) != NULL) {
+    for (i=0 ; i<(*cfg)->nframes ; i++) {
+      if((*cfg)->inFrameList[i] != NULL) {
+    cpl_free((*cfg)->inFrameList[i]);
+    (*cfg)->inFrameList[i]= NULL;
+      }
+    }
+    cpl_free((*cfg)->inFrameList);
+    (*cfg)->inFrameList=NULL;
+    sinfo_standstar_cfg_destroy (*cfg);
+    (*cfg) = NULL;
+  }
+}
+/**@}*/
diff --git a/sinfoni/sinfo_standstar_ini_by_cpl.h b/sinfoni/sinfo_standstar_ini_by_cpl.h
new file mode 100644
index 0000000..20b644e
--- /dev/null
+++ b/sinfoni/sinfo_standstar_ini_by_cpl.h
@@ -0,0 +1,72 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/*----------------------------------------------------------------------------
+   
+   File name    :   sinfo_standstar_ini_by_cpl.h
+   Author       :   Andrea Modigliani
+   Created on   :   May 23, 2004
+   Description  :   cpl input handling for SINFONI data reduction 
+                    of a standard star
+
+ ---------------------------------------------------------------------------*/
+
+
+#ifndef SINFO_STANDSTAR_INI_BY_CPL_H
+#define SINFO_STANDSTAR_INI_BY_CPL_H
+
+
+/*---------------------------------------------------------------------------
+                                Includes
+---------------------------------------------------------------------------*/
+
+#include <stdio.h>
+#include <cpl.h>
+#include "sinfo_standstar_cfg.h"
+#include "sinfo_msg.h"
+ 
+ 
+/*----------------------------------------------------------------------------
+                             Function prototypes 
+ ---------------------------------------------------------------------------*/
+
+
+/* generateStandstar_ini_file */
+
+/*-------------------------------------------------------------------------*/
+/**
+  @name     parse_standstar_ini_file
+  @memo     Parse a ini_name.ini file and create a blackboard.
+  @param    ini_name    Name of the ASCII file to parse.
+  @return   1 newly allocated standstar_config blackboard structure.
+  @doc
+
+  The requested ini file is parsed and a blackboard object is created, then
+  updated accordingly. Returns NULL in case of error.
+ */
+/*--------------------------------------------------------------------------*/
+
+void
+sinfo_stdstar_free(standstar_config  ** cfg);
+standstar_config * 
+sinfo_parse_cpl_input_standstar(cpl_parameterlist * cpl_cfg, 
+                                cpl_frameset* sof, 
+                                cpl_frameset** raw) ;
+
+#endif
diff --git a/sinfoni/sinfo_star_index.c b/sinfoni/sinfo_star_index.c
new file mode 100644
index 0000000..ef65718
--- /dev/null
+++ b/sinfoni/sinfo_star_index.c
@@ -0,0 +1,325 @@
+/* $Id: sinfo_star_index.c,v 1.9 2012/03/03 10:18:26 amodigli Exp $
+ *
+ * This file is part of the X-Shooter Pipeline
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*
+ * $Author: amodigli $
+ * $Date: 2012/03/03 10:18:26 $
+ * $Revision: 1.9 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>          /* allows the program compilation */
+#endif
+
+#include <cpl.h>
+#include <string.h>
+#include <math.h>
+
+
+//#include "sinfo_pro_save.h"
+//#include "sinfo_pfits.h"
+//#include "sinfo_utilities_scired.h"
+//#include "sinfo_hidden.h"
+//#include "sinfo_functions.h"
+#include "sinfo_error.h"
+#include "sinfo_msg.h"
+#include "sinfo_utils_wrappers.h"
+//#include "sinfo_globals.h"
+#include "sinfo_star_index.h"
+
+struct _star_index_
+{
+	cpl_table* index_table;
+	char* fits_file_name;
+	int index_size;
+	cpl_table** cache;
+	int cache_size;
+	int* cache_index;
+};
+
+//typedef struct _star_index_ star_index;
+static const char* COL_NAME_EXTID 	= "ext_id";
+static const char* COL_NAME_NAME 	= "name";
+static const char* COL_NAME_RA 	= "ra";
+static const char* COL_NAME_DEC 	= "dec";
+
+static star_index* star_index_construct(const char* fits_file);
+static void star_index_destruct(star_index* pindex);
+// private functions
+
+static star_index* star_index_construct(const char* fits_file)
+{
+	star_index* pret = cpl_malloc(sizeof(star_index));
+	pret->index_size = 0;
+	pret->index_table = 0;
+	pret->cache_size = 0;
+	pret->cache = 0;
+	pret->cache_index = 0;
+	if (fits_file)
+	{
+		size_t bt = strlen(fits_file) * sizeof(*fits_file)+1;
+		pret->fits_file_name = cpl_malloc(bt);
+		strcpy(pret->fits_file_name, fits_file);
+	}
+	else
+	{
+		pret->fits_file_name = 0;
+	}
+	return pret;
+}
+
+static void star_index_destruct(star_index* pindex)
+{
+	if(pindex)
+	{
+		if (pindex->cache)
+		{
+			int i = 0;
+			for ( i = 0; i < pindex->cache_size; i++)
+			{
+				cpl_table_delete(pindex->cache[i]);
+			}
+			cpl_free(pindex->cache);
+			pindex->cache = 0;
+			pindex->cache_size = 0;
+		}
+		cpl_table_delete(pindex->index_table);
+		if(pindex->fits_file_name)
+		{
+			cpl_free(pindex->fits_file_name);
+		}
+		cpl_free(pindex->cache_index);
+		cpl_free(pindex);
+	}
+
+}
+
+/**@{*/
+
+star_index* star_index_create(void)
+{
+	star_index* pret = star_index_construct(0);
+	// initialize table
+	check_nomsg(pret->index_table = cpl_table_new(pret->index_size));
+	// create columns ext_id, name, ra, dec
+	cpl_table_new_column(pret->index_table, COL_NAME_EXTID, CPL_TYPE_INT);
+	cpl_table_new_column(pret->index_table, COL_NAME_NAME, CPL_TYPE_STRING);
+	cpl_table_new_column(pret->index_table, COL_NAME_RA, CPL_TYPE_DOUBLE);
+	cpl_table_new_column(pret->index_table, COL_NAME_DEC, CPL_TYPE_DOUBLE);
+
+	return pret;
+	cleanup:
+	star_index_destruct(pret);
+	return 0;
+}
+star_index* star_index_load(const char* fits_file)
+{
+	star_index* pret = star_index_construct(fits_file);
+	// load index table from the file
+	cpl_table* pindex = 0;
+	check_nomsg(pindex = cpl_table_load(fits_file,1,0));
+	// TODO check_nomsg the structure of the table
+	pret->index_table = pindex;
+	check_nomsg(pret->index_size = cpl_table_get_nrow(pindex));
+	return pret;
+	cleanup:
+	star_index_destruct(pret);
+	cpl_error_reset();
+	return 0;
+}
+void star_index_delete(star_index* pindex)
+{
+	star_index_destruct(pindex);
+}
+int star_index_add(star_index* pindex, double RA, double DEC, const char* star_name, cpl_table* ptable)
+{
+	int retval = 0;
+	if (pindex)
+	{
+		// expand the index table
+		check_nomsg(cpl_table_insert_window(pindex->index_table, pindex->index_size++, 1));
+		if (!pindex->cache)
+		{
+			pindex->cache_size = 1;
+			pindex->cache = cpl_malloc(sizeof(cpl_table*) * pindex->cache_size);
+			pindex->cache_index = cpl_malloc(sizeof(pindex->cache_index[0]) * pindex->cache_size);
+		}
+		else
+		{
+			// add new entry
+			pindex->cache_size++;
+			pindex->cache = cpl_realloc(pindex->cache, sizeof(cpl_table*) * pindex->cache_size);
+		}
+		check_nomsg(pindex->cache[pindex->cache_size - 1] = cpl_table_duplicate(ptable));
+		// fill the index table with values
+		check_nomsg(cpl_table_set_string(pindex->index_table, COL_NAME_NAME, pindex->index_size - 1 ,star_name));
+		check_nomsg(cpl_table_set(pindex->index_table, COL_NAME_RA, pindex->index_size - 1 ,RA));
+		check_nomsg(cpl_table_set(pindex->index_table, COL_NAME_DEC, pindex->index_size - 1,DEC));
+		check_nomsg(cpl_table_set_int(pindex->index_table, COL_NAME_EXTID, pindex->index_size - 1 ,pindex->index_size + 1));
+		retval = pindex->index_size;
+	}
+	return retval;
+
+	cleanup:
+	//printf ("error: %s\n", cpl_error_get_message());
+	return 0;
+}
+
+int start_index_get_size(star_index* pindex)
+{
+	return pindex ? pindex->index_size : 0;
+}
+
+int star_index_remove_by_name(star_index* pindex, const char* starname)
+{
+	int i = 0;
+	int index_pos = -1;
+	for (i = 0; i < pindex->index_size; i++)
+	{
+		const char* curr_star_name = 0;
+		check_nomsg(curr_star_name = cpl_table_get_string(pindex->index_table, COL_NAME_NAME, i));
+		if (strcmp(curr_star_name, starname) == 0)
+		{
+			index_pos = i;
+			break;
+		}
+	}
+	if (index_pos >= 0)
+	{
+		// star is found
+		// clear only the index table, real data would be cleaned during save operation
+		cpl_table_set_int(pindex->index_table, COL_NAME_EXTID, index_pos, -1);
+		if (index_pos - pindex->index_size + pindex->cache_size  >= 0)
+		{
+			// clear cache
+			int cache_index = index_pos - pindex->index_size + pindex->cache_size;
+			cpl_table_delete(pindex->cache[cache_index]);
+			pindex->cache[cache_index] = 0;
+		}
+	}
+	cleanup:
+	return index_pos;
+}
+
+int star_index_save(star_index* pindex, const char* fits_file)
+{
+	int i  = 0;
+	int inull = 0;
+	cpl_table* pnew_index = 0;
+	int nrows = 0;
+	// firstly save the index table - deleted entries should be removed firstly
+	check_nomsg(cpl_table_unselect_all(pindex->index_table));
+	check_nomsg(cpl_table_or_selected_int(pindex->index_table, COL_NAME_EXTID, CPL_EQUAL_TO, -1));
+	// inverse selection
+	check_nomsg(cpl_table_not_selected(pindex->index_table));
+	check_nomsg(pnew_index = cpl_table_extract_selected(pindex->index_table));
+
+	nrows = cpl_table_get_nrow(pnew_index);
+//	printf("rows to save[%d]\n", nrows);
+	for (i = 0; i < nrows; i++)
+	{
+		cpl_table_set_int(pnew_index, COL_NAME_EXTID, i, i+2); // ext in fits starts from 1, and another 1 is used by index_table
+	}
+//	printf("writing index [%s]\n", fits_file);
+	check_nomsg(cpl_table_save(pnew_index, NULL, NULL, fits_file, CPL_IO_CREATE));
+	cpl_table_delete(pnew_index);
+	pnew_index = 0;
+	// save the data
+	for (i = 0;i < pindex->index_size; i++)
+	{
+//		printf("saving ext [%d]\n", i);
+		// 2. save cache
+		int saved_ext = cpl_table_get_int(pindex->index_table, COL_NAME_EXTID, i, &inull);
+//		printf("saving 1\n");
+		if (saved_ext > 0) // check_nomsg that was not removed
+		{
+			cpl_table* ptable = 0;
+//			printf("saving 2\n");
+			if (i < pindex->index_size - pindex->cache_size)
+			{
+//				printf("saving 3\n");
+				check_nomsg(ptable = cpl_table_load(pindex->fits_file_name, saved_ext, 0));
+			}
+			else
+			{
+//				printf("saving 4\n");
+				ptable = cpl_table_duplicate(pindex->cache[i - pindex->index_size + pindex->cache_size ]);
+			}
+//			printf("saving 5\n");
+			check_nomsg(cpl_table_save(ptable, NULL, NULL, fits_file, CPL_IO_EXTEND));
+//			printf("saving 6\n");
+			cpl_table_delete(ptable);
+//			printf("saving 7\n");
+		}
+//		printf("saving 8\n");
+	}
+//	printf("saving exit\n");
+	return nrows;
+	cleanup:
+//	printf("error during save\n");
+	return 0;
+}
+cpl_table* star_index_get(star_index* pindex, double RA, double DEC, double RA_EPS, double DEC_EPS, const char** pstar_name)
+{
+	int i = 0;
+	cpl_table* pret = 0;
+	int inull = 0;
+
+	for (i = 0; i < pindex->index_size; i++)
+	{
+		double curr_ra = 0;
+		double curr_dec = 0;
+		int ext_id = 0;
+
+		check_nomsg(ext_id = cpl_table_get_int(pindex->index_table, COL_NAME_EXTID, i ,&inull));
+		check_nomsg(curr_ra = cpl_table_get(pindex->index_table, COL_NAME_RA, i,&inull));
+		check_nomsg(curr_dec = cpl_table_get(pindex->index_table, COL_NAME_DEC, i,&inull));
+		if ((ext_id > 0) && (fabs(curr_ra - RA) < RA_EPS) && (fabs(curr_dec - DEC) < DEC_EPS))
+		{
+			// found
+			// retrieve the data
+			if (i - pindex->index_size + pindex->cache_size  >= 0)
+			{
+				// data is in cache
+				pret = cpl_table_duplicate(pindex->cache[i - pindex->index_size + pindex->cache_size ]);
+			}
+			else
+			{
+				// data is on disk
+				pret = cpl_table_load(pindex->fits_file_name, ext_id, 0);
+			}
+			if (pret && pstar_name)
+			{
+				check_nomsg(*pstar_name = cpl_table_get_string(pindex->index_table, COL_NAME_NAME, i));
+			}
+			break;
+		}
+	}
+	cleanup:
+	return pret;
+}
+
+void star_index_dump(star_index* pindex, FILE* pfile)
+{
+	cpl_table_dump(pindex->index_table, 0, 	cpl_table_get_nrow(pindex->index_table), pfile);
+}
+/**@}*/
diff --git a/sinfoni/sinfo_star_index.h b/sinfoni/sinfo_star_index.h
new file mode 100644
index 0000000..4633ede
--- /dev/null
+++ b/sinfoni/sinfo_star_index.h
@@ -0,0 +1,62 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004-2009 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*
+ * $Author: kmirny $
+ * $Date: 2009/09/02 11:34:23 $
+ * $Revision: 1.4 $
+ * $Log: sinfo_star_index.h,v $
+ * Revision 1.4  2009/09/02 11:34:23  kmirny
+ * fixing compiler warning
+ *
+ * Revision 1.3  2009/07/13 14:40:39  kmirny
+ * fixing unit test failure in star catalog
+ *
+ * Revision 1.2  2009/06/19 14:37:58  kmirny
+ * star index implementation
+ *
+ * Revision 1.1  2009/06/16 15:18:26  kmirny
+ * star catalog implementation for calculating efficiency
+ *
+*/
+#ifndef _SINFONI_SINFO_STAR_INDEX_H_
+#define _SINFONI_SINFO_STAR_INDEX_H_
+
+
+typedef struct _star_index_ star_index;
+
+/* Loading the index from the fits file
+ * */
+star_index* star_index_load(const char* fits_file);
+
+/*Save the index to the fits file
+ * */
+star_index* star_index_create(void);
+/* Add a new start to the index. To save the changed index to the file star_index_save() should be called
+ * */
+int star_index_add(star_index* pindex, double RA, double DEC, const char* star_name, cpl_table* ptable);
+int star_index_remove_by_name(star_index* pindex, const char* starname);
+int start_index_get_size(star_index* pindex);
+int star_index_save(star_index* pindex, const char* fits_file_name);
+cpl_table* star_index_get(star_index* pindex, double RA, double DEC, double RA_EPS, double DEC_EPS, const char** pstar_name);
+void star_index_delete(star_index* pindex);
+void star_index_dump(star_index* pindex, FILE* pfile);
+
+
+
+#endif
diff --git a/sinfoni/sinfo_svd.c b/sinfoni/sinfo_svd.c
new file mode 100644
index 0000000..6071e53
--- /dev/null
+++ b/sinfoni/sinfo_svd.c
@@ -0,0 +1,433 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/**************************************************************************
+* E.S.O. - VLT project
+*
+*
+*
+* who       when      what
+* --------  --------  ----------------------------------------------
+* schreib  16/04/03  created
+*/
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#include "sinfo_svd.h"
+#include "sinfo_msg.h"
+/**@{*/
+/**
+ * @addtogroup sinfo_utilities Single Value Decomposition utilities
+ *
+ * TBD
+ */
+
+void sinfo_fpol(float x, float *p, int np)
+{
+    int j ;
+    
+    p[1] = 1.0 ;
+    for ( j = 2 ; j <= np ; j++ )
+    {
+        p[j] = p[j-1]*x ;
+    }
+}
+
+void 
+sinfo_svb_kas(float **u, float w[], float **v, int m, 
+              int n, float b[],float x[])
+
+
+{
+        int jj,j,i;
+        float s,*tmp;
+
+        tmp=sinfo_vector(1,n);
+        for (j=1;j<=n;j++) {
+                s=0.0;
+                if (w[j]) {
+                        for (i=1;i<=m;i++) s += u[i][j]*b[i];
+                        s /= w[j];
+                }
+                tmp[j]=s;
+        }
+        for (j=1;j<=n;j++) {
+                s=0.0;
+                for (jj=1;jj<=n;jj++) s += v[j][jj]*tmp[jj];
+                x[j]=s;
+        }
+        sinfo_free_vector(tmp,1/*,n*/);
+}
+
+void sinfo_svd_variance(float **v , int ma , float w[] , float **cvm)
+{
+        int k,j,i;
+        float sum,*wti;
+
+        wti=sinfo_vector(1,ma);
+        for (i=1;i<=ma;i++) {
+                wti[i]=0.0;
+                if (w[i]) wti[i]=1.0/(w[i]*w[i]);
+        }
+        for (i=1;i<=ma;i++) {
+            for (j=1;j<=i;j++) {
+               for (sum=0.0,k=1;k<=ma;k++) sum += (v[i][k]*v[j][k]*wti[k]);
+               cvm[j][i]=cvm[i][j]=sum;
+            }
+        }
+        sinfo_free_vector(wti,1/*,ma*/);
+}
+
+#define TOL 1.0e-5
+
+void sinfo_svd_fitting ( float *x,
+                   float *y,
+                   float *sig,
+                   int   ndata,
+                   float *a,
+                   int   ma,
+                   float **u,
+                   float **v,
+                   float *w,
+                   float **cvm,
+                   float *chisq,
+                   void (*funcs)(float,float *,int) )
+{
+        int j,i;
+        float /*sini,*/wmax,tmp,thresh,sum,*b,*afunc;
+
+
+        b=sinfo_vector(1,ndata);
+        afunc=sinfo_vector(1,ma);
+        for (i=1;i<=ndata;i++) {
+
+                (*funcs)(x[i],afunc,ma);
+                tmp=1.0/sig[i];
+                for (j=1;j<=ma;j++) {
+                        u[i][j]=afunc[j]*tmp;
+                }
+                b[i]=y[i]*tmp;
+        }
+        sinfo_svd_compare(u,ndata,ma,w,v);
+
+        wmax=0.0;
+        for (j=1;j<=ma;j++)
+                if (w[j] > wmax) wmax=w[j];
+        thresh=TOL*wmax;
+        for (j=1;j<=ma;j++) {
+          if (w[j] < thresh) {
+            w[j]=0.0;
+            sinfo_msg_warning("SVD_FITTING detected singular value in fit !");
+          }
+        }
+        sinfo_svb_kas(u,w,v,ndata,ma,b,a);
+        *chisq=0.0;
+        for (i=1;i<=ndata;i++) {
+                (*funcs)(x[i],afunc,ma);
+                for (sum=0.0,j=1;j<=ma;j++) sum += a[j]*afunc[j];
+                *chisq += (tmp=(y[i]-sum)/sig[i],tmp*tmp);
+        }
+        sinfo_free_vector(afunc,1/*,ma*/);
+        sinfo_free_vector(b,1/*,ndata*/);
+        sinfo_svd_variance(v,ma,w,cvm);
+
+}
+
+#undef TOL
+
+
+
+static float at,bt,ct;
+#define SINFO_PYTHAG(a,b) ((at=fabs(a)) > (bt=fabs(b)) ? \
+(ct=bt/at,at*sqrt(1.0+ct*ct)) : (bt ? (ct=at/bt,bt*sqrt(1.0+ct*ct)): 0.0))
+
+
+static float maxarg1,maxarg2;
+#define SINFO_MAX(a,b) (maxarg1=(a),maxarg2=(b),(maxarg1) > (maxarg2) ?\
+        (maxarg1) : (maxarg2))
+#define SINFO_SIGN(a,b) ((b) >= 0.0 ? fabs(a) : -fabs(a))
+
+void sinfo_svd_compare(float **a,int m,int n,float w[],float **v)
+{
+        int flag,i,its,j,jj,k,l=0,nm=0;
+        float c,f,h,s,x,y,z;
+        float anorm=0.0,g=0.0,scale=0.0;
+        float *rv1;
+
+        if (m < n) {
+           sinfo_msg_error("SVDCMP: You must augment A with extra zero rows");
+        }
+        rv1=sinfo_vector(1,n);
+        for (i=1;i<=n;i++) {
+                l=i+1;
+                rv1[i]=scale*g;
+                g=s=scale=0.0;
+                if (i <= m) {
+                        for (k=i;k<=m;k++) scale += fabs(a[k][i]);
+                        if (scale) {
+                                for (k=i;k<=m;k++) {
+                                        a[k][i] /= scale;
+                                        s += a[k][i]*a[k][i];
+                                }
+                                f=a[i][i];
+
+                                g = -SINFO_SIGN(sqrt(s),f);
+                                h=f*g-s;
+                                a[i][i]=f-g;
+                                if (i != n) {
+                                        for (j=l;j<=n;j++) {
+                                                for (s=0.0,k=i;k<=m;k++) {
+                                                  s += a[k][i]*a[k][j];
+                                                }
+                                                f=s/h;
+                                                for (k=i;k<=m;k++) {
+                                                  a[k][j] += f*a[k][i];
+                                                }
+                                        }
+                                }
+                                for (k=i;k<=m;k++) a[k][i] *= scale;
+                        }
+                }
+                w[i]=scale*g;
+                g=s=scale=0.0;
+                if (i <= m && i != n) {
+                        for (k=l;k<=n;k++) scale += fabs(a[i][k]);
+                        if (scale) {
+                          for (k=l;k<=n;k++) {
+                                 a[i][k] /= scale;
+                                 s += a[i][k]*a[i][k];
+                          }
+                          f=a[i][l];
+
+                          g = -SINFO_SIGN(sqrt(s),f);
+                          h=f*g-s;
+                          a[i][l]=f-g;
+                          for (k=l;k<=n;k++) rv1[k]=a[i][k]/h;
+                          if (i != m) {
+                            for (j=l;j<=m;j++) {
+                              for (s=0.0,k=l;k<=n;k++) s += a[j][k]*a[i][k];
+                              for (k=l;k<=n;k++) a[j][k] += s*rv1[k];
+                            }
+                          }
+                          for (k=l;k<=n;k++) a[i][k] *= scale;
+                        }
+                }
+                anorm=SINFO_MAX(anorm,(fabs(w[i])+fabs(rv1[i])));
+        }
+
+        for (i=n;i>=1;i--) {
+                if (i < n) {
+                        if (g) {
+                          for (j=l;j<=n;j++)
+                              v[j][i]=(a[i][j]/a[i][l])/g;
+                          for (j=l;j<=n;j++) {
+                              for (s=0.0,k=l;k<=n;k++) s += a[i][k]*v[k][j];
+                              for (k=l;k<=n;k++) v[k][j] += s*v[k][i];
+                          }
+                        }
+                        for (j=l;j<=n;j++) v[i][j]=v[j][i]=0.0;
+                }
+                v[i][i]=1.0;
+                g=rv1[i];
+                l=i;
+        }
+        for (i=n;i>=1;i--) {
+                l=i+1;
+                g=w[i];
+                if (i < n)
+                        for (j=l;j<=n;j++) a[i][j]=0.0;
+                if (g) {
+                        g=1.0/g;
+                        if (i != n) {
+                            for (j=l;j<=n;j++) {
+                              for (s=0.0,k=l;k<=m;k++) s += a[k][i]*a[k][j];
+                              f=(s/a[i][i])*g;
+                              for (k=i;k<=m;k++) a[k][j] += f*a[k][i];
+                            }
+                        }
+                        for (j=i;j<=m;j++) a[j][i] *= g;
+                } else {
+                        for (j=i;j<=m;j++) a[j][i]=0.0;
+                }
+                ++a[i][i];
+        }
+        for (k=n;k>=1;k--) {
+                for (its=1;its<=30;its++) {
+                        flag=1;
+                        for (l=k;l>=1;l--) {
+                                nm=l-1;
+                                if (fabs(rv1[l])+anorm == anorm) {
+                                        flag=0;
+                                        break;
+                                }
+                                if (fabs(w[nm])+anorm == anorm) break;
+                        }
+                        if (flag) {
+                                c=0.0;
+                                s=1.0;
+                                for (i=l;i<=k;i++) {
+                                        f=s*rv1[i];
+                                        if (fabs(f)+anorm != anorm) {
+                                                g=w[i];
+
+                                                h=SINFO_PYTHAG(f,g);
+                                                w[i]=h;
+                                                h=1.0/h;
+                                                c=g*h;
+                                                s=(-f*h);
+                                                for (j=1;j<=m;j++) {
+                                                        y=a[j][nm];
+                                                        z=a[j][i];
+                                                        a[j][nm]=y*c+z*s;
+                                                        a[j][i]=z*c-y*s;
+                                                }
+                                        }
+                                }
+                        }
+                        z=w[k];
+                        if (l == k) {
+                                if (z < 0.0) {
+                                        w[k] = -z;
+                                        for (j=1;j<=n;j++) v[j][k]=(-v[j][k]);
+                                }
+                                break;
+                        }
+                        if (its == 30) {
+                         sinfo_msg_error("No convergence in 30 "
+                                         "SVDCMP iterations");
+                        }
+                        x=w[l];
+                        nm=k-1;
+                        y=w[nm];
+                        g=rv1[nm];
+                        h=rv1[k];
+                        f=((y-z)*(y+z)+(g-h)*(g+h))/(2.0*h*y);
+
+                        g=SINFO_PYTHAG(f,1.0);
+                        f=((x-z)*(x+z)+h*((y/(f+SINFO_SIGN(g,f)))-h))/x;
+                        c=s=1.0;
+                        for (j=l;j<=nm;j++) {
+                                i=j+1;
+                                g=rv1[i];
+                                y=w[i];
+                                h=s*g;
+                                g=c*g;
+
+                                z=SINFO_PYTHAG(f,h);
+                                rv1[j]=z;
+                                c=f/z;
+                                s=h/z;
+                                f=x*c+g*s;
+                                g=g*c-x*s;
+                                h=y*s;
+                                y=y*c;
+                                for (jj=1;jj<=n;jj++) {
+                                        x=v[jj][j];
+                                        z=v[jj][i];
+                                        v[jj][j]=x*c+z*s;
+                                        v[jj][i]=z*c-x*s;
+                                }
+
+                                z=SINFO_PYTHAG(f,h);
+                                w[j]=z;
+                                if (z) {
+                                        z=1.0/z;
+                                        c=f*z;
+                                        s=h*z;
+                                }
+                                f=(c*g)+(s*y);
+                                x=(c*y)-(s*g);
+                                for (jj=1;jj<=m;jj++) {
+                                        y=a[jj][j];
+                                        z=a[jj][i];
+                                        a[jj][j]=y*c+z*s;
+                                        a[jj][i]=z*c-y*s;
+                                }
+                        }
+                        rv1[l]=0.0;
+                        rv1[k]=f;
+                        w[k]=x;
+                }
+        }
+        sinfo_free_vector(rv1,1/*,n*/);
+}
+
+#undef SINFO_SIGN
+#undef SINFO_MAX
+#undef SINFO_PYTHAG
+
+#define NR_END 1
+#define FREE_ARG char*
+
+void sinfo_nerror(const char error_text[])
+{
+        fprintf(stderr,"Runtime ERROR ...\n");
+        fprintf(stderr,"%s\n",error_text);
+        fprintf(stderr,"exiting system \n");
+    return;
+}
+
+float *sinfo_vector(long nl, long nh)
+{
+        float *v;
+
+        v=(float *)cpl_malloc((size_t) ((nh-nl+1+NR_END)*sizeof(float)));
+        if (!v) {
+           sinfo_msg_error("allocation failure in sinfo_vector()");
+        }
+        return v-nl+NR_END;
+
+}
+
+void sinfo_free_vector(float *v, long nl/* , long nh*/)
+
+{
+        cpl_free((FREE_ARG) (v+nl-NR_END));
+}
+
+float **sinfo_matrix(long nrl, long nrh, long ncl, long nch)
+{
+        long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
+        float **m;
+
+        m=(float **) cpl_malloc((size_t)((nrow+NR_END)*sizeof(float*)));
+        if (!m) {
+          sinfo_msg_error("aloccation failure 1 in sinfo_matrix()");
+        }
+        m += NR_END;
+        m -= nrl;
+
+        m[nrl]=(float *)cpl_malloc((size_t)((nrow*ncol+NR_END)*sizeof(float)));
+        if (!m[nrl]) {
+           sinfo_msg_error("allocation failure 2 in sinfo_matrix()");
+        }
+        m[nrl] += NR_END;
+        m[nrl] -= ncl;
+
+        for(i=nrl+1;i<=nrh;i++) m[i] = m[i-1]+ncol;
+        return m;
+}
+
+void sinfo_free_matrix(float **m,long nrl/*, long nrh*/, long ncl/*, long nch*/)
+{
+        cpl_free((FREE_ARG)(m[nrl]+ncl-NR_END));
+        cpl_free((FREE_ARG)(m+nrl-NR_END));
+}
+
+/**@}*/
diff --git a/sinfoni/sinfo_svd.h b/sinfoni/sinfo_svd.h
new file mode 100644
index 0000000..9cd54c6
--- /dev/null
+++ b/sinfoni/sinfo_svd.h
@@ -0,0 +1,85 @@
+#ifndef SINFO_SVD_H
+#define SINFO_SVD_H
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*******************************************************************************
+* E.S.O. - VLT project
+*
+* "@(#) $Id: sinfo_svd.h,v 1.4 2007/06/06 07:10:45 amodigli Exp $"
+*
+* who       when      what
+* --------  --------  ----------------------------------------------
+* schreib  16/04/03  created
+*/
+
+/************************************************************************
+ * sinfo_svd.h
+ * singular value decomposition fit routines
+ *----------------------------------------------------------------------
+ */
+
+/*
+ * header files
+ */
+
+#include <math.h>
+#include <cpl.h>
+
+/*----------------------------------------------------------------------------
+ *                        Function ANSI C prototypes
+ *--------------------------------------------------------------------------*/
+
+void sinfo_fpol(float x, float *p, int np) ;
+
+void 
+sinfo_svb_kas(float **u, float w[], float **v, int m, 
+              int n, float b[],float x[]) ;
+
+void sinfo_svd_variance(float **v , int ma , float w[] , float **cvm) ;
+
+void sinfo_svd_fitting ( float *x,
+                   float *y,
+                   float *sig,
+                   int   ndata,
+                   float *a,
+                   int   ma,
+                   float **u,
+                   float **v,
+                   float *w,
+                   float **cvm,
+                   float *chisq,
+                   void (*funcs)(float,float *,int) ) ;
+
+void sinfo_svd_compare(float **a,int m,int n,float w[],float **v) ;
+
+void sinfo_nerror(const char error_text[]) ;
+
+float *sinfo_vector(long nl, long nh) ;
+
+void sinfo_free_vector(float *v, long nl /*, long nh*/) ;
+
+float **sinfo_matrix(long nrl, long nrh, long ncl, long nch) ;
+
+void 
+sinfo_free_matrix(float **m,long nrl/*, long nrh*/, long ncl/*, long nch*/) ;
+
+
+#endif /*!SINFO_SVD_H*/
+
+/*--------------------------------------------------------------------------*/
diff --git a/sinfoni/sinfo_tilt_cfg.c b/sinfoni/sinfo_tilt_cfg.c
new file mode 100644
index 0000000..1145544
--- /dev/null
+++ b/sinfoni/sinfo_tilt_cfg.c
@@ -0,0 +1,84 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/*---------------------------------------------------------------------------
+   
+   File name     :    tilt_cfg.c
+   Autor    :       Juergen Schreiber
+   Created on    :    October 2001
+   Description    :    handles the data structure tilt_config
+
+ *--------------------------------------------------------------------------*/
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+/*---------------------------------------------------------------------------
+                                   Includes
+ ---------------------------------------------------------------------------*/
+
+#include "sinfo_tilt_cfg.h"
+/**@{*/
+/**
+ * @defgroup sinfo_tilt_cfg tilt computation
+ *
+ * TBD
+ */
+
+/*---------------------------------------------------------------------------
+                              Function codes
+ ---------------------------------------------------------------------------*/
+
+/*---------------------------------------------------------------------------
+   Function :   sinfo_tilt_cfg_create()
+   In       :   void
+   Out      :   pointer to allocated base tilt_config structure
+   Job      :   allocate memory for a tilt_config struct
+   Notice   :   only the main (base) structure is allocated
+ ---------------------------------------------------------------------------*/
+
+tilt_config * sinfo_tilt_cfg_create(void)
+{
+    return cpl_calloc(1, sizeof(tilt_config));
+}
+
+
+/*---------------------------------------------------------------------------
+   Function :   sinfo_tilt_cfg_destroy()
+   In       :   tilt_config to deallocate
+   Out      :   void
+   Job      :   deallocate all memory associated with a 
+                tilt_config data structure
+   Notice   :   
+ ---------------------------------------------------------------------------*/
+
+void sinfo_tilt_cfg_destroy(tilt_config * sc)
+{
+    if (sc==NULL) return ;
+   /* cpl_free(sc->frametype);*/
+    
+    /* Free main struct */
+    cpl_free(sc);
+
+    return ;
+}
+
+
+/**@}*/
+
diff --git a/sinfoni/sinfo_tilt_cfg.h b/sinfoni/sinfo_tilt_cfg.h
new file mode 100644
index 0000000..704919f
--- /dev/null
+++ b/sinfoni/sinfo_tilt_cfg.h
@@ -0,0 +1,103 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*---------------------------------------------------------------------------
+   File name     :    sinfo_tilt_cfg.h
+   Author         :    Juergen Schreiber
+   Created on    :    October 2001
+   Description    :    tilt_ini definitions + handling prototypes
+ ---------------------------------------------------------------------------*/
+#ifndef SINFO_TILT_CFG_H
+#define SINFO_TILT_CFG_H
+/*---------------------------------------------------------------------------
+                                   Includes
+ ---------------------------------------------------------------------------*/
+#include <stdlib.h>
+#include "sinfo_globals.h"
+#include <cpl.h>
+/*---------------------------------------------------------------------------
+                                   Defines
+ ---------------------------------------------------------------------------*/
+/*---------------------------------------------------------------------------
+                                   New types
+ ---------------------------------------------------------------------------*/
+/*
+  determination of spectral tilt blackboard container
+
+  This structure holds all information related to the determination 
+  of the spectral tilt routine. It is used as a container for the flux 
+  of ancillary data, computed values, and algorithm status. Pixel flux 
+  is separated from the blackboard.
+  */
+
+typedef struct tilt_config {
+/*-------General---------*/
+        char inFile[FILE_NAME_SZ] ;    /* file name of the file containing 
+                                          the list of all input frames */
+        char outName[FILE_NAME_SZ] ;   /* output name of resulting fits 
+                                          wavelength map */
+        char ** framelist ; /* list of frames */
+        int  *  frametype ; /* list of frame types on or off */
+        int     nframes ;   /* number of frames in frame list */
+        int     nobj ;      /* number of object frames in frame list */
+        int     noff ;      /* number of off frames in frame list */
+
+/*------ CleanMean ------*/
+        /* percentage of rejected low intensity pixels */
+        float loReject ;
+        /* percentage of rejected high intensity pixels */
+        float hiReject ;
+        /* file name of the bad pixel mask fits file */
+        char mask[FILE_NAME_SZ] ;
+
+/*------ Slope ------*/
+        /* width of a box along the slitlets within which the spectrum 
+           is fitted by a Gaussian */
+        int box_length ;
+        /* initial guess of the FWHM */
+        float fwhm ;
+        /* amplitude below which the fit is not carried through */
+        float minDiff ;
+
+} tilt_config ;
+
+/*---------------------------------------------------------------------------
+                               Function prototypes
+ ---------------------------------------------------------------------------*/
+/**
+   @name   sinfo_tilt_cfg_create()
+   @memo   allocate memory for a tilt_cfg struct
+   @return pointer to allocated base tilt_cfg structure
+   @note  only the main (base) structure is allocated
+*/
+
+tilt_config * 
+sinfo_tilt_cfg_create(void);
+
+
+/**
+   @name    sinfo_tilt_cfg_destroy()
+   @memo   deallocate all memory associated with a tilt_config data structure
+   @param   tilt_config to deallocate
+   @return  void
+*/
+
+void 
+sinfo_tilt_cfg_destroy(tilt_config * sc);
+
+#endif
diff --git a/sinfoni/sinfo_tilt_ini.h b/sinfoni/sinfo_tilt_ini.h
new file mode 100644
index 0000000..4635444
--- /dev/null
+++ b/sinfoni/sinfo_tilt_ini.h
@@ -0,0 +1,78 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+   
+   File name    :   sinfo_tilt_ini.h
+   Author       :    Juergen Schreiber
+   Created on   :    Oct 25, 2001
+   Description  :    prepare handling of .ini file for the determination
+                        of the spectral tilt
+ ---------------------------------------------------------------------------*/
+#ifndef SINFO_TILT_INI_H
+#define SINFO_TILT_INI_H
+/*---------------------------------------------------------------------------
+                                Includes
+---------------------------------------------------------------------------*/
+#include <cpl.h>
+#include "sinfo_tilt_cfg.h"
+/*---------------------------------------------------------------------------
+                                Defines
+---------------------------------------------------------------------------*/
+#define FRAME_ON   1     /* object frames */
+#define FRAME_OFF  0     /* off frames */
+/*----------------------------------------------------------------------------
+                             Function prototypes 
+ ---------------------------------------------------------------------------*/
+/**
+  @name        generateTilt_ini_file
+  @memo        Generate a default ini file for the spectral 
+                tilt determination command.
+  @param    ini_name    Name of the file to generate.
+  @param    name_i        Name of the input file.
+  @param    name_o        Name of the output file.
+  @return    int 0 if Ok, -1 otherwise.
+  @doc
+
+  This function generates a default ini file for the spectral 
+  tilt determination command. The
+  generated file will have the requested name. 
+ */
+
+int 
+generateTilt_ini_file(
+        char * ini_name,
+        char * name_i,
+        char * name_o
+);
+
+/**
+  @name     parse_tilt_ini_file
+  @memo     Parse an ini_name.ini file and create a blackboard.
+  @param    ini_name    Name of the ASCII file to parse.
+  @return   1 newly allocated tilt_config blackboard structure.
+  @doc
+
+  The requested ini file is parsed and a blackboard object is created, then
+  updated accordingly. Returns NULL in case of error.
+ */
+
+tilt_config * 
+parse_tilt_ini_file(char * ini_name) ;
+
+#endif
diff --git a/sinfoni/sinfo_time.c b/sinfoni/sinfo_time.c
new file mode 100644
index 0000000..101c74c
--- /dev/null
+++ b/sinfoni/sinfo_time.c
@@ -0,0 +1,244 @@
+/* $Id: sinfo_time.c,v 1.5 2012/03/03 10:17:31 amodigli Exp $
+ *
+ * This file is part of the ESO QFITS Library
+ * Copyright (C) 2001-2004 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2012/03/03 10:17:31 $
+ * $Revision: 1.5 $
+ * $Name: sinfo-2_3_2 $
+ */
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+/*-----------------------------------------------------------------------------
+                                   Includes
+ -----------------------------------------------------------------------------*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <pwd.h>
+#include <unistd.h>
+#include <sys/time.h>
+
+#include "sinfo_time.h"
+#include "sinfo_globals.h"
+
+/*-----------------------------------------------------------------------------
+                                   Macros
+ -----------------------------------------------------------------------------*/
+
+/* Get century from a date in long format */
+#define GET_CENTURY(d)      (int) ( (d) / 1000000L)
+/* Get century year from a date in long format */
+#define GET_CCYEAR(d)       (int) ( (d) / 10000L)
+/* Get year from a date in long format */
+#define GET_YEAR(d)         (int) (((d) % 1000000L) / 10000L)
+/* Get month from a date in long format */
+#define GET_MONTH(d)        (int) (((d) % 10000L) / 100)
+/* Get day from a date in long format */
+#define GET_DAY(d)          (int) ( (d) % 100)
+
+/* Get hours from a date in long format */
+#define GET_HOUR(t)         (int) ( (t) / 1000000L)
+/* Get minutes from a date in long format */
+#define GET_MINUTE(t)       (int) (((t) % 1000000L) / 10000L)
+/* Get seconds from a date in long format */
+#define GET_SECOND(t)       (int) (((t) % 10000L) / 100)
+/* Get centi-seconds from a date in long format */
+#define GET_CENTI(t)        (int) ( (t) % 100)
+
+/* Make date in long format from its components */
+#define MAKE_DATE(c,y,m,d)  (long) (c) * 1000000L +                          \
+                            (long) (y) * 10000L +                            \
+                            (long) (m) * 100 + (d)
+/* Make time in long format from its components */
+#define MAKE_TIME(h,m,s,c)  (long) (h) * 1000000L +                          \
+                            (long) (m) * 10000L +                            \
+                            (long) (s) * 100 + (c)
+
+/*  Interval values, specified in centiseconds */
+#define INTERVAL_CENTI      1
+#define INTERVAL_SEC        100
+#define INTERVAL_MIN        6000
+#define INTERVAL_HOUR       360000L
+#define INTERVAL_DAY        8640000L
+
+/*-----------------------------------------------------------------------------
+                            Private to this module
+ -----------------------------------------------------------------------------*/
+
+static long timer_to_date(time_t time_secs) ;
+static long timer_to_time(time_t time_secs) ;
+static long sinfo_time_now(void) ;
+static long sinfo_date_now (void) ;
+
+/**@{*/
+/*----------------------------------------------------------------------------*/
+/**
+ * @defgroup    sinfo_time  Get date/time, possibly in ISO8601 format
+ *
+ * This module contains various utilities to get the current date/time, 
+ * and possibly format it according to the ISO 8601 format.
+ */
+/*----------------------------------------------------------------------------*/
+
+/*-----------------------------------------------------------------------------
+                              Function codes
+ -----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Returns the current date and time as a static string.
+  @return   Pointer to statically allocated string
+ 
+  Build and return a string containing the date of today and the
+  current time in ISO8601 format. The returned pointer points to a
+  statically allocated string in the function, so no need to free it.
+ */
+/*----------------------------------------------------------------------------*/
+char * sinfo_get_datetime_iso8601(void)
+{
+    static char date_iso8601[MAX_NAME_SIZE] ;
+    long        curdate ;
+    long        curtime ;
+
+    curdate  = sinfo_date_now() ;
+    curtime  = sinfo_time_now() ;
+
+    snprintf(date_iso8601, MAX_NAME_SIZE-1,
+            "%04d-%02d-%02dT%02d:%02d:%02d",
+            GET_CCYEAR(curdate),
+            GET_MONTH(curdate),
+            GET_DAY(curdate),
+            GET_HOUR(curtime),
+            GET_MINUTE(curtime),
+            GET_SECOND(curtime));
+    return date_iso8601 ;
+}
+
+/**@}*/
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Returns the current date as a long (CCYYMMDD).
+  @return    The current date as a long number.
+
+  Returns the current date as a long value (CCYYMMDD). Since most
+  system clocks do not return a century, this function assumes that
+  all years 80 and above are in the 20th century, and all years 00 to
+  79 are in the 21st century.  For best results, consume before 1 Jan
+  2080.
+  Example:    19 Oct 2000 is returned as 20001019
+ */
+/*----------------------------------------------------------------------------*/
+static long sinfo_date_now (void)
+{
+    return (timer_to_date (time (NULL)));
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Returns the current time as a long (HHMMSSCC).
+  @return    The current time as a long number.
+
+  Returns the current time as a long value (HHMMSSCC). If the system
+  clock does not return centiseconds, these are set to zero.
+
+  Example: 15:36:12.84 is returned as 15361284
+ */
+/*----------------------------------------------------------------------------*/
+static long sinfo_time_now(void)
+{
+    struct timeval time_struct;
+
+    gettimeofday (&time_struct, 0);
+    return (timer_to_time (time_struct.tv_sec)
+                         + time_struct.tv_usec / 10000);
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Converts a timer value to a date.
+  @param    time_secs    Current time definition in seconds.
+  @return    Current date as a long (CCYYMMDD).
+
+  Converts the supplied timer value into a long date value. Dates are
+  stored as long values: CCYYMMDD. If the supplied value is zero,
+  returns zero.  If the supplied value is out of range, returns 1
+  January, 1970 (19700101). The timer value is assumed to be UTC
+  (GMT).
+ */
+/*----------------------------------------------------------------------------*/
+static long timer_to_date(time_t time_secs)
+{
+    struct tm *time_struct;
+
+    if (time_secs == 0) {
+        return 0;
+    } else {
+        /*  Convert into a long value CCYYMMDD */
+        time_struct = localtime (&time_secs);
+        if (time_struct) {
+            time_struct-> tm_year += 1900;
+            return (MAKE_DATE (    time_struct-> tm_year / 100,
+                                time_struct-> tm_year % 100,
+                                time_struct-> tm_mon + 1,
+                                time_struct-> tm_mday));
+        } else {
+            return (19700101);
+        }
+    }
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Convert a timer value to a time.
+  @param    time_secs    Current time definition in seconds.
+  @return    Current time as a long.
+
+  Converts the supplied timer value into a long time value.  Times are
+  stored as long values: HHMMSS00.  Since the timer value does not
+  hold centiseconds, these are set to zero.  If the supplied value was
+  zero or invalid, returns zero.  The timer value is assumed to be UTC
+  (GMT).
+ */
+/*----------------------------------------------------------------------------*/
+static long timer_to_time(time_t time_secs)
+{
+    struct tm *time_struct;
+
+    if (time_secs == 0) {
+        return 0;
+    } else {
+        /*  Convert into a long value HHMMSS00 */
+        time_struct = localtime (&time_secs);
+        if (time_struct) {
+            return (MAKE_TIME (time_struct-> tm_hour,
+                               time_struct-> tm_min,
+                               time_struct-> tm_sec,
+                               0));
+        } else {
+            return 0;
+        }
+    }
+}
+
diff --git a/sinfoni/sinfo_time.h b/sinfoni/sinfo_time.h
new file mode 100644
index 0000000..27a5898
--- /dev/null
+++ b/sinfoni/sinfo_time.h
@@ -0,0 +1,37 @@
+/* $Id: sinfo_time.h,v 1.1 2006/11/11 14:13:03 amodigli Exp $
+ *
+ * This file is part of the ESO QFITS Library
+ * Copyright (C) 2001-2004 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2006/11/11 14:13:03 $
+ * $Revision: 1.1 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifndef SINFO_TIME_H
+#define SINFO_TIME_H
+
+/*-----------------------------------------------------------------------------
+                        Function ANSI C prototypes
+ -----------------------------------------------------------------------------*/
+
+char * sinfo_get_datetime_iso8601(void) ;
+
+#endif
diff --git a/sinfoni/sinfo_tpl_dfs.c b/sinfoni/sinfo_tpl_dfs.c
new file mode 100644
index 0000000..9f2cdda
--- /dev/null
+++ b/sinfoni/sinfo_tpl_dfs.c
@@ -0,0 +1,247 @@
+/* $Id: sinfo_tpl_dfs.c,v 1.13 2012/03/03 10:17:31 amodigli Exp $
+ *
+ * This file is part of the SINFONI Pipeline
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2012/03/03 10:17:31 $
+ * $Revision: 1.13 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+/*-----------------------------------------------------------------------------
+                                   Includes
+ -----------------------------------------------------------------------------*/
+
+#include <string.h>
+#include <math.h>
+
+#include <cpl.h>
+#include "sinfo_utilities.h"
+
+#include "sinfo_tpl_dfs.h"
+#include "sinfo_pro_types.h"
+#include "sinfo_raw_types.h"
+#include "sinfo_ref_types.h"
+#include "sinfo_error.h"
+#include "sinfo_msg.h"
+
+
+/**@{*/
+/*----------------------------------------------------------------------------*/
+/**
+ * @defgroup sinfo_tpl_dfs  DFS related functions
+ *
+ * TBD
+ */
+/*----------------------------------------------------------------------------*/
+
+
+
+/*----------------------------------------------------------------------------*/
+/**
+ * @brief
+ *   Check if all SOF files exist
+ *
+ * @param frameset The input set-of-frames
+ *
+ * @return 1 if not all files exist, 0 if they all exist.
+ *
+ */
+/*----------------------------------------------------------------------------*/
+static int
+sinfo_dfs_files_dont_exist(cpl_frameset *frameset)
+{
+    const char *func = "dfs_files_dont_exist";
+    cpl_frame  *frame;
+
+
+    if (frameset == NULL) {
+        cpl_error_set(func, CPL_ERROR_NULL_INPUT);
+        return 1;
+    }
+
+    if (cpl_frameset_is_empty(frameset)) {
+        return 0;
+    }
+
+    frame = cpl_frameset_get_first(frameset);
+
+    while (frame) {
+        if (access(cpl_frame_get_filename(frame), F_OK)) {
+            cpl_msg_error(func, "File %s (%s) was not found",
+                          cpl_frame_get_filename(frame),
+                          cpl_frame_get_tag(frame));
+            cpl_error_set(func, CPL_ERROR_FILE_NOT_FOUND);
+        }
+
+        frame = cpl_frameset_get_next(frameset);
+    }
+
+    if (cpl_error_get_code())
+        return 1;
+
+    return 0;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Set the group as RAW or CALIB in a frameset
+  @param    set     the input frameset
+  @return   0 if ok, -1 in error case
+ */
+/*----------------------------------------------------------------------------*/
+int sinfo_dfs_set_groups(cpl_frameset * set)
+{
+    cpl_frame   *   cur_frame=NULL ;
+    const char  *   tag=NULL ;
+    int             nframes=0 ;
+    int             i=0 ;
+
+    sinfo_skip_if (cpl_error_get_code());
+
+    /* Check entries */
+    if (set == NULL) return -1 ;
+
+    /* Initialize */
+    nframes = cpl_frameset_get_size(set) ;
+
+    /* Loop on frames */
+    for (i=0 ; i<nframes ; i++) {
+        cur_frame = cpl_frameset_get_frame(set, i) ;
+        tag = cpl_frame_get_tag(cur_frame) ;
+        if (cpl_error_get_code()) break;
+        if (tag == NULL) sinfo_msg_warning( "Frame %d has no tag", i);
+        /* RAW frames */
+        else if (!strcmp(tag, RAW_LINEARITY_LAMP) ||
+             !strcmp(tag, RAW_ON) ||
+             !strcmp(tag, RAW_OFF) ||
+             !strcmp(tag, RAW_DARK) ||
+                 !strcmp(tag, RAW_FIBRE_NS) ||
+                 !strcmp(tag, RAW_FIBRE_PSF) ||
+                 !strcmp(tag, RAW_FIBRE_DARK) ||
+                 !strcmp(tag, RAW_FLAT_NS) ||
+                 !strcmp(tag, RAW_WAVE_NS) ||
+                 !strcmp(tag, RAW_FLAT_LAMP) ||
+                 !strcmp(tag, RAW_WAVE_LAMP) ||
+                 !strcmp(tag, RAW_PSF_CALIBRATOR) ||
+             !strcmp(tag, RAW_SKY_PSF_CALIBRATOR) ||
+             !strcmp(tag, RAW_STD) ||
+             !strcmp(tag, RAW_SKY) ||
+                 !strcmp(tag, RAW_SKY_STD) ||
+             !strcmp(tag, RAW_OBJECT_NODDING) ||
+             !strcmp(tag, RAW_SKY_NODDING) ||
+                 !strcmp(tag, RAW_OBJECT_JITTER) ||
+                 !strcmp(tag, RAW_SKY_JITTER) ||
+                 !strcmp(tag, RAW_PUPIL_LAMP) ||
+                 !strcmp(tag, RAW_IMAGE_PRE_OBJECT) ||
+                 !strcmp(tag, RAW_IMAGE_PRE_SKY) ||
+                 !strcmp(tag, RAW_OBJECT_SKYSPIDER))
+            cpl_frame_set_group(cur_frame, CPL_FRAME_GROUP_RAW) ;
+        /* CALIB frames */
+        else if (!strcmp(tag, PRO_BP_MAP_HP)  ||
+         !strcmp(tag,SINFO_UTL_STDSTARS_RAW) ||
+         !strcmp(tag,SINFO_CALIB_STDSTARS) ||
+         !strcmp(tag,SINFO_CALIB_SED) ||
+         !strcmp(tag,PRO_BP_MAP_NL) ||
+         !strcmp(tag,PRO_BP_MAP_NO) ||
+         !strcmp(tag,PRO_BP_MAP_DI) ||
+         !strcmp(tag,PRO_BP_MAP_NL) ||
+         !strcmp(tag,PRO_BP_MAP_NO) ||
+         !strcmp(tag,PRO_BP_MAP) ||
+         !strcmp(tag,PRO_ILL_COR) ||
+         !strcmp(tag,PRO_MASTER_BP_MAP) ||
+         !strcmp(tag,PRO_MASTER_DARK) ||
+                 !strcmp(tag,PRO_DISTORTION) ||
+         !strcmp(tag,PRO_SLITLETS_DISTANCE) ||
+         !strcmp(tag,PRO_MASTER_FLAT_LAMP) ||
+         !strcmp(tag,PRO_SLIT_POS) ||
+         !strcmp(tag,PRO_SLIT_POS_GUESS) ||
+         !strcmp(tag,PRO_FIRST_COL) ||
+         !strcmp(tag,PRO_WAVE_MAP ) ||
+         !strcmp(tag,REF_LINE_ARC ) ||
+         !strcmp(tag,DRS_SETUP_WAVE ) ||
+         !strcmp(tag,EXTCOEFF_TABLE ) ||
+         !strcmp(tag,FLUX_STD_TABLE ) ||
+         !strcmp(tag,FLUX_STD_CATALOG ) ||
+         !strcmp(tag,PRO_IMA ) ||
+         !strcmp(tag,PRO_CUBE ) ||
+         !strcmp(tag,REF_BP_MAP ) ||
+         !strcmp(tag,PRO_SKY_DUMMY ) ||
+         !strcmp(tag,PRO_REF_ATM_REF_CORR) ||
+         !strcmp(tag,PRO_SPECTRUM))
+            cpl_frame_set_group(cur_frame, CPL_FRAME_GROUP_CALIB) ;
+        else if (!strcmp(tag, PRO_OBS_OBJ)  ||
+         !strcmp(tag,PRO_MED_OBS_OBJ) ||
+         !strcmp(tag,PRO_OBS_STD) ||
+         !strcmp(tag,PRO_MED_OBS_STD) ||
+         !strcmp(tag,PRO_OBS_PSF) ||
+         !strcmp(tag,PRO_MED_OBS_PSF) ||
+         !strcmp(tag,PRO_COADD_OBJ) ||
+         !strcmp(tag,PRO_COADD_STD) ||
+         !strcmp(tag,PRO_COADD_PSF) ||
+         !strcmp(tag,PRO_COADD_PUPIL) ||
+         !strcmp(tag,PRO_MED_COADD_OBJ) ||
+         !strcmp(tag,PRO_MED_COADD_STD) ||
+         !strcmp(tag,PRO_MED_COADD_PSF) ||
+         !strcmp(tag,PRO_MED_COADD_PUPIL) ||
+         !strcmp(tag,PRO_MASK_COADD_OBJ) ||
+         !strcmp(tag,PRO_MASK_COADD_STD) ||
+         !strcmp(tag,PRO_MASK_COADD_PSF) ||
+         !strcmp(tag,PRO_MASK_COADD_PUPIL) ||
+         !strcmp(tag,PRO_PSF_CALIBRATOR_STACKED) ||
+         !strcmp(tag,PRO_SKY_PSF_CALIBRATOR_STACKED) ||
+         !strcmp(tag,PRO_AO_PERFORMANCE) ||
+         !strcmp(tag,PRO_ENC_ENERGY) ||
+         !strcmp(tag,PRO_PSF) ||
+         !strcmp(tag,PRO_STD_STAR_SPECTRA) ||
+         !strcmp(tag,PRO_STD_STAR_SPECTRUM) ||
+         !strcmp(tag,PRO_MFLAT_CUBE) ||
+         !strcmp(tag,PRO_MFLAT_AVG) ||
+         !strcmp(tag,PRO_MFLAT_MED) ||
+         !strcmp(tag,PRO_STACK_MFLAT_DIST) ||
+         !strcmp(tag,PRO_WAVE_LAMP_STACKED ) ||
+         !strcmp(tag,PRO_FIBRE_NS_STACKED_OFF) ||
+         !strcmp(tag,PRO_FIBRE_NS_STACKED_ON) ||
+         !strcmp(tag,PRO_FIBRE_NS_STACKED) ||
+         !strcmp(tag,PRO_SLITLETS_POS_PREDIST) ||
+         !strcmp(tag,PRO_OBS_SKY) ||
+         !strcmp(tag,PRO_SKY_MED) ||
+         !strcmp(tag,PRO_FIBRE_NS_STACKED_DIST))
+            cpl_frame_set_group(cur_frame, CPL_FRAME_GROUP_PRODUCT) ;
+        else sinfo_msg_warning( "Frame %d has unknown tag: %s", i, tag);
+    }
+    ck0_nomsg(sinfo_dfs_files_dont_exist(set));
+    sinfo_skip_if (i != nframes);
+
+    sinfo_end_skip;
+
+    if (cpl_error_get_code())
+        sinfo_msg_error( "Could not identify RAW and CALIB frames (in "
+                      "frame set of size %d)", nframes);
+
+
+    return cpl_error_get_code();
+}
+
+/**@}*/
diff --git a/sinfoni/sinfo_tpl_dfs.h b/sinfoni/sinfo_tpl_dfs.h
new file mode 100644
index 0000000..225371f
--- /dev/null
+++ b/sinfoni/sinfo_tpl_dfs.h
@@ -0,0 +1,74 @@
+/* $Id: sinfo_tpl_dfs.h,v 1.3 2008/07/09 09:53:23 amodigli Exp $
+ *
+ * This file is part of the SINFONI Pipeline
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2008/07/09 09:53:23 $
+ * $Revision: 1.3 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifndef SINFO_TPL_DFS_H
+#define SINFO_TPL_DFS_H
+
+/*-----------------------------------------------------------------------------
+                                   Define
+ -----------------------------------------------------------------------------*/
+
+/* Define here the PRO.CATG keywords */
+#define SI_UTL_IMA_ARITH_PROIMA               "PRO_IMA"
+#define SINFO_RAW                           "RAW"
+#define SINFO_CAL                           "CAL"
+
+/* Define here the DO.CATG keywords */
+#define SI_UTL_IMA_ARITH_IMA1                 "IMA1"
+#define SI_UTL_IMA_ARITH_IMA2                 "IMA2"
+#define SI_UTL_CUBE2IMA_CUBE                  "CUBE"
+#define SI_UTL_CUBE2SPECTRUM_CUBE             "CUBE"
+#define SI_UTL_CUBE_ARITH_CUBE                "CUBE"
+#define SI_UTL_CUBE_ARITH_SPECTRUM            "SPECTRUM"
+#define SI_UTL_CUBE2IMA_PROIMA                "PRO_IMA"
+#define SI_UTL_CUBE2SPECTRUM_PROIMA           "PRO_IMA"
+#define SI_UTL_CUBE_ARITH_PROCUBE             "PRO_CUBE_COADD"
+#define SI_UTL_CUBE_COMBINE_PROCUBE           "PRO_CUBE"
+#define SI_UTL_CUBE_COMBINE_PROMASK           "PRO_BP_MAP_CUBE_COADD"
+#define SI_UTL_SPECTRUM_ARITH_PROSPECTRUM     "PRO_SPECTRUM"
+#define SI_UTL_SPECTRUM_ARITH_SPECTRUM        "SPECTRUM"
+#define SI_UTL_SPECTRUM_WAVELENGTH_SHIFT_PROSPECTRUM     "PRO_SPECTRUM"
+#define SI_UTL_SPECTRUM_WAVELENGTH_SHIFT_SPECTRUM        "SPECTRUM"
+#define SI_UTL_SPECTRUM_DIVIDE_BY_BLACKBODY_PROSPECTRUM     "PRO_SPECTRUM"
+#define SI_UTL_SPECTRUM_DIVIDE_BY_BLACKBODY_SPECTRUM        "SPECTRUM"
+#define SI_UTL_GENLOOKUP_CUBE1                "CUBE1"
+#define SI_UTL_GENLOOKUP_CUBE2                "CUBE2"
+#define SI_UTL_GENLOOKUP_PROIMA1              "PRO_IMA1"
+#define SI_UTL_GENLOOKUP_PROIMA2              "PRO_IMA2"
+#define SI_UTL_GENLOOKUP_PROIMA3              "PRO_IMA3"
+#define SI_UTL_GENLOOKUP_PROIMA4              "PRO_IMA4"
+#define SI_SKYMAP_CUBE                        "PRO_CUBE"
+#define SI_SKYMAP_PROIMA                      "PRO_IMA"
+
+
+/*-----------------------------------------------------------------------------
+                                Functions prototypes
+ -----------------------------------------------------------------------------*/
+
+int sinfo_dfs_set_groups(cpl_frameset *) ;
+
+#endif
diff --git a/sinfoni/sinfo_tpl_utils.c b/sinfoni/sinfo_tpl_utils.c
new file mode 100644
index 0000000..cdef69c
--- /dev/null
+++ b/sinfoni/sinfo_tpl_utils.c
@@ -0,0 +1,175 @@
+/* $Id: sinfo_tpl_utils.c,v 1.3 2012/03/03 10:17:31 amodigli Exp $
+ *
+ * This file is part of the SINFONI Pipeline
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2012/03/03 10:17:31 $
+ * $Revision: 1.3 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+/*-----------------------------------------------------------------------------
+                                                                Includes
+ -----------------------------------------------------------------------------*/
+#include <string.h>
+#include <cpl.h>
+
+#include "sinfo_tpl_utils.h"
+
+/**@{*/
+/*----------------------------------------------------------------------------*/
+/**
+ * @defgroup sinfo_tpl_utils     Miscellaneous Utilities
+ */
+/*----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief        Get the pipeline copyright and license
+  @return   The copyright and license string
+
+  The function returns a pointer to the statically allocated license string.
+  This string should not be modified using the returned pointer.
+ */
+/*----------------------------------------------------------------------------*/
+const char * sinfo_get_license(void)
+{
+    const char *   sinfoni_license =
+        "This file is part of the SINFONI Instrument Pipeline\n"
+        "Copyright (C) 2002,2003 European Southern Observatory\n"
+        "\n"
+        "This program is free software; you can redistribute it and/or modify\n"
+        "it under the terms of the GNU General Public License as published by\n"
+        "the Free Software Foundation; either version 2 of the License, or\n"
+        "(at your option) any later version.\n"
+        "\n"
+        "This program is distributed in the hope that it will be useful,\n"
+        "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
+        "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n"
+        "GNU General Public License for more details.\n"
+        "\n"
+        "You should have received a copy of the GNU General Public License\n"
+        "along with this program; if not, write to the Free Software\n"
+        "Foundation, Inc., 59 Temple Place, Suite 330, Boston, \n"
+        "MA  02111-1307  USA" ;
+
+    return sinfoni_license ;
+}
+
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief   Extract the frames with the given tag from a frameset
+   @param   in      A non-empty frameset
+   @param   tag     The tag of the requested frames   
+   @return  The newly created frameset or NULL on error
+
+   The returned frameset must be de allocated with cpl_frameset_delete()
+ */
+/*---------------------------------------------------------------------------*/
+cpl_frameset * sinfo_extract_frameset(
+        const cpl_frameset  *   in,
+        const char          *   tag)
+{
+    cpl_frameset    *   out ;
+    const cpl_frame *   cur_frame ;
+    cpl_frame       *   loc_frame ;
+    int                 nbframes, nbext ;
+    int                 i ;
+
+    /* Test entries */
+    if (in == NULL) return NULL ;
+    if (tag == NULL) return NULL ;
+
+    /* Initialise */
+    nbframes = cpl_frameset_get_size(in) ;
+
+    /* Count the frames with the tag */
+    if ((nbext = cpl_frameset_count_tags(in, tag)) == 0) return NULL ;
+
+    /* Create the output frameset */
+    out = cpl_frameset_new() ;
+
+    /* Loop on the requested frames and store them in out */
+    nbext = 0 ;
+    for (i=0 ; i<nbframes ; i++) {
+        cur_frame = cpl_frameset_get_frame_const(in, i) ;
+        if (!strcmp(cpl_frame_get_tag(cur_frame), tag)) {
+            loc_frame = cpl_frame_duplicate(cur_frame) ;
+            cpl_frameset_insert(out, loc_frame) ;
+            nbext ++ ;
+        }
+    }
+    return out ;
+}
+/*----------------------------------------------------------------------------*/
+/** 
+   @brief   Extract the filename ffor the first frame of the given tag
+   @param   in      A non-empty frameset
+   @param   tag     The tag of the requested file 
+   @return  Pointer to the file
+ */
+/*----------------------------------------------------------------------------*/
+const char * sinfo_extract_filename(
+        const cpl_frameset  *   in,
+        const char          *   tag)
+{
+    const cpl_frame *   cur_frame ;
+
+    /* Get the frame  */
+    if ((cur_frame = cpl_frameset_find_const(in, tag)) == NULL) return NULL ;
+    return cpl_frame_get_filename(cur_frame) ;
+}
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Return a band name
+  @param    band    a BB
+  @return   1 pointer to a static band name.
+ */
+/*--------------------------------------------------------------------------*/
+const char * sinfo_std_band_name(sinfo_band band)
+{
+    switch (band) {
+        case SINFO_BAND_J:        return "J" ;
+        case SINFO_BAND_JS:       return "Js" ;
+        case SINFO_BAND_JBLOCK:   return "J+Block" ;
+        case SINFO_BAND_H:        return "H" ;
+        case SINFO_BAND_K:        return "K" ;
+        case SINFO_BAND_KS:       return "Ks" ;
+        case SINFO_BAND_L:        return "L" ;
+        case SINFO_BAND_M:        return "M" ;
+        case SINFO_BAND_LP:       return "Lp" ;
+        case SINFO_BAND_MP:       return "Mp" ;
+        case SINFO_BAND_Z:        return "Z" ;
+        case SINFO_BAND_SZ:       return "SZ" ;
+        case SINFO_BAND_SH:       return "SH" ;
+        case SINFO_BAND_SK:       return "SK" ;
+        case SINFO_BAND_SL:       return "SL" ;
+        default:            return "Unknown" ;
+    } 
+}
+
+/**@}*/
diff --git a/sinfoni/sinfo_tpl_utils.h b/sinfoni/sinfo_tpl_utils.h
new file mode 100644
index 0000000..ef89752
--- /dev/null
+++ b/sinfoni/sinfo_tpl_utils.h
@@ -0,0 +1,65 @@
+/* $Id: sinfo_tpl_utils.h,v 1.2 2007/08/20 10:03:49 amodigli Exp $
+ *
+ * This file is part of the SINFONI Pipeline
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2007/08/20 10:03:49 $
+ * $Revision: 1.2 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifndef SINFO_TPL_UTILS_H
+#define SINFO_TPL_UTILS_H
+
+/*-----------------------------------------------------------------------------
+                                                                Includes
+ -----------------------------------------------------------------------------*/
+
+#include <cpl.h>
+
+typedef enum _SINFO_BAND_ {
+    SINFO_BAND_J,
+    SINFO_BAND_JS,
+    SINFO_BAND_JBLOCK,
+    SINFO_BAND_H,
+    SINFO_BAND_K,
+    SINFO_BAND_KS,
+    SINFO_BAND_L,
+    SINFO_BAND_M,
+    SINFO_BAND_LP,
+    SINFO_BAND_MP,
+    SINFO_BAND_Z,
+    SINFO_BAND_SZ,
+    SINFO_BAND_SH,
+    SINFO_BAND_SK,
+    SINFO_BAND_SL,
+    SINFO_BAND_UNKNOWN
+} sinfo_band ;
+
+/*-----------------------------------------------------------------------------
+                                                                Prototypes
+ -----------------------------------------------------------------------------*/
+
+const char * sinfo_get_license(void) ;
+cpl_frameset * sinfo_extract_frameset(const cpl_frameset *, const char *) ;
+const char * sinfo_extract_filename(const cpl_frameset *, const char *) ;
+
+const char * sinfo_std_band_name(sinfo_band) ;
+#endif
diff --git a/sinfoni/sinfo_utilities.c b/sinfoni/sinfo_utilities.c
new file mode 100644
index 0000000..76c5940
--- /dev/null
+++ b/sinfoni/sinfo_utilities.c
@@ -0,0 +1,1152 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+#include "sinfo_utilities.h"
+#include "sinfo_error.h"
+#include "sinfo_dfs.h"
+#include "sinfo_utils_wrappers.h"
+#include "sinfo_function_1d.h"
+/**@{*/
+/**
+ * @defgroup sinfo_utilities utilities
+ *
+ * TBD
+ */
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Convert a vector to a 1d image
+  @param    vector to convert
+  @param    type   of image
+
+  @return   a new allocated 1d image whose elements are the same as the vector
+  @em The image need to be allocated .
+
+ */
+/*----------------------------------------------------------------------------*/
+
+cpl_image*
+sinfo_vector_to_image(const cpl_vector* vector,cpl_type type)
+{
+  int i=0;
+  cpl_image* image=NULL;
+  int size=0;
+  const double* pv=NULL;
+  int* pi=NULL;
+  float* pf=NULL;
+  double* pd=NULL;
+
+
+      size=cpl_vector_get_size(vector);
+      image=cpl_image_new(size,1,type);
+      pv=cpl_vector_get_data_const(vector);
+      if(type == CPL_TYPE_INT) {
+        pi=cpl_image_get_data_int(image);
+        for(i=0;i<size;i++) {
+	  pi[i]=pv[i];
+	}
+      } else if (type == CPL_TYPE_FLOAT) {
+        pf=cpl_image_get_data_float(image);
+        for(i=0;i<size;i++) {
+	  pf[i]=pv[i];
+	}
+      } else if (type == CPL_TYPE_DOUBLE) {
+        pd=cpl_image_get_data_double(image);
+        for(i=0;i<size;i++) {
+	  pd[i]=pv[i];
+	}
+      } else {
+        assure( 0, CPL_ERROR_INVALID_TYPE,
+            "No CPL type to represent BITPIX = %d", type);
+      }
+
+ cleanup:
+    if (cpl_error_get_code() != CPL_ERROR_NONE){
+      sinfo_free_image(&image);
+    }
+
+    return image;
+
+}
+
+
+cpl_error_code
+sinfo_ima_line_cor(cpl_parameterlist * parlist, cpl_frameset* in)
+{
+  int n=0;
+  int i=0;
+  int kappa=18;
+  int filt_rad=3;
+  int width=4;
+
+  cpl_frame* frm=NULL;
+  const char* name=NULL;
+  const char* bname=NULL;
+
+  cpl_image * ima=NULL ;
+  cpl_image * ima_out=NULL ;
+  cpl_parameter* p=NULL;
+  cpl_propertylist* plist=NULL;
+  char* tag=NULL;
+  char name_deb[80];
+
+
+  check_nomsg(p=cpl_parameterlist_find(parlist, "sinfoni.general.lc_kappa"));
+  check_nomsg(kappa=cpl_parameter_get_int(p));
+  check_nomsg(p=cpl_parameterlist_find(parlist,
+				       "sinfoni.general.lc_filt_rad"));
+  check_nomsg(filt_rad = cpl_parameter_get_int(p)) ;
+
+  n=cpl_frameset_get_size(in);
+
+  for(i=0;i<n;i++) {
+    check_nomsg(frm=cpl_frameset_get_frame(in,i));
+    tag= (char*) cpl_frame_get_tag(frm);
+    if(sinfo_frame_is_raw(tag) == 1) {
+      check_nomsg(name=cpl_frame_get_filename(frm));
+
+      bname=sinfo_new_get_basename(name);
+      check_nomsg(ima=cpl_image_load(name,CPL_TYPE_FLOAT,0,0));
+      check_nomsg(sinfo_image_line_corr(width,filt_rad,kappa,ima,&ima_out));
+      check_nomsg(plist=cpl_propertylist_load(name,0));
+      //sprintf(name_deb,"dark_org_%d.fits",i);
+      sprintf(name_deb,"org_%2.2d_%s",i,bname);
+
+      check(cpl_image_save(ima,
+			   name_deb,
+			   CPL_BPP_IEEE_FLOAT,
+			   plist,
+			   CPL_IO_DEFAULT),
+	    "Could not save product");
+
+
+      check(cpl_image_save(ima_out,
+			   bname,
+			   CPL_BPP_IEEE_FLOAT,
+			   plist,
+			   CPL_IO_DEFAULT),
+	    "Could not save product");
+
+      cpl_frame_set_filename(frm,bname);
+      sinfo_free_image(&ima);
+      sinfo_free_propertylist(&plist);
+    }
+
+  }
+
+ cleanup:
+  sinfo_free_image(&ima);
+  sinfo_free_propertylist(&plist);
+
+  return cpl_error_get_code();
+
+}
+
+int
+sinfo_table_column_dump(cpl_table* t, const char* name, cpl_type type)
+{
+  int nrow=0;
+  int i=0;
+  int* pi=NULL;
+  float* pf=NULL;
+  double* pd=NULL;
+  char** ps=NULL;
+
+  nrow=cpl_table_get_nrow(t);
+
+  switch(type) {
+
+  case CPL_TYPE_INT:
+    pi=cpl_table_get_data_int(t,name);
+    for(i=0;i<nrow;i++) {
+      sinfo_msg("val=%d",pi[i]);
+    }
+    break;
+  case CPL_TYPE_FLOAT:
+    pf=cpl_table_get_data_float(t,name);
+    for(i=0;i<nrow;i++) {
+      sinfo_msg("val=%g",pf[i]);
+    }
+    break;
+  case CPL_TYPE_DOUBLE:
+    pd=cpl_table_get_data_double(t,name);
+    for(i=0;i<nrow;i++) {
+      sinfo_msg("val=%g",pd[i]);
+    }
+    break;
+  case CPL_TYPE_STRING:
+    ps=cpl_table_get_data_string(t,name);
+    for(i=0;i<nrow;i++) {
+      sinfo_msg("val=%s",ps[i]);
+    }
+    break;
+  default:
+    sinfo_msg_error("Wrong column type");
+    cpl_error_set(cpl_func, CPL_ERROR_TYPE_MISMATCH);
+    return 0;
+
+  }
+  return 0;
+}
+
+
+
+/**
+ at name sinfo_table_shift_column_spline3
+ at param shift a table of an double shift
+ at param t input table
+ at param col input table's column
+ at param shift shift to be applied
+ at return pointer to a new allocated shifted table
+*/
+
+cpl_table*
+sinfo_table_shift_column_spline3(cpl_table* t,
+                                 const char* col,
+                                 const double shift)
+{
+  cpl_table* out=NULL;
+  int nrow=0;
+  int i=0;
+  int z=0;
+
+  float sum=0;
+  float new_sum=0;
+
+  float* pi=NULL;
+  float* po=NULL;
+  float* eval=NULL;
+  float* xnum=NULL;
+  float* spec=NULL;
+  float* corrected_spec=NULL;
+
+  cknull(t,"null input table");
+  out=cpl_table_duplicate(t);
+
+  nrow=cpl_table_get_nrow(t);
+  check_nomsg(cpl_table_cast_column(t,col,"FINT",CPL_TYPE_FLOAT));
+  check_nomsg(cpl_table_cast_column(out,col,"FINT",CPL_TYPE_FLOAT));
+  pi=cpl_table_get_data_float(t,"FINT");
+  po=cpl_table_get_data_float(out,"FINT");
+
+
+
+  xnum=cpl_calloc(nrow,sizeof(float)) ;
+  /* fill the xa[] array for the spline function */
+  for ( i = 0 ; i < nrow ; i++ ) {
+    xnum[i] = i ;
+  }
+
+  spec=cpl_calloc(nrow,sizeof(float)) ;
+  corrected_spec=cpl_calloc(nrow,sizeof(float)) ;
+  eval=cpl_calloc(nrow,sizeof(float)) ;
+
+  sum = 0. ;
+  for ( z = 0 ; z < nrow ; z++ ) {
+    spec[z] = pi[z] ;
+    if (isnan(spec[z]) ) {
+      for ( i = z-1 ; i <= z+1 ; i++ ) {
+    if ( i < 0 ) continue ;
+    if ( i >= nrow) continue ;
+    corrected_spec[i] = ZERO ;
+      }
+      spec[z] = 0. ;
+    }
+    sum += spec[z] ;
+    eval[z] = (float)shift+(float)z ;
+  }
+  /* now we do the spline interpolation*/
+  if ( -1 == sinfo_function1d_natural_spline(xnum,spec, nrow,
+                                             eval,corrected_spec, nrow))
+    {
+      sinfo_msg_error("error in spline interpolation!") ;
+      goto cleanup;
+    }
+
+  new_sum = 0. ;
+  for ( z = 0 ; z < nrow ; z++ ) {
+    if ( isnan(corrected_spec[z]) ) {
+      continue ;
+    }
+    new_sum += corrected_spec[z] ;
+  }
+  /* fill output imagelist */
+  for ( z = 0 ; z < nrow ; z++ ) {
+    if ( new_sum == 0. ) new_sum =1. ;
+    {
+      if ( isnan(corrected_spec[z]) ) {
+    po[z] = ZERO ;
+      } else {
+    corrected_spec[z] *= sum / new_sum ;
+    po[z] = corrected_spec[z] ;
+      }
+    }
+  }
+
+  sinfo_free_float(&xnum);
+  sinfo_free_float(&spec) ;
+  sinfo_free_float(&corrected_spec) ;
+  sinfo_free_float(&eval) ;
+
+  check_nomsg(cpl_table_erase_column(t,"FINT"));
+  check_nomsg(cpl_table_erase_column(out,col));
+  check_nomsg(cpl_table_cast_column(out,"FINT",col,CPL_TYPE_DOUBLE));
+  check_nomsg(cpl_table_erase_column(out,"FINT"));
+
+  return out;
+ cleanup:
+
+  sinfo_free_float(&xnum);
+  sinfo_free_float(&spec) ;
+  sinfo_free_float(&corrected_spec) ;
+  sinfo_free_float(&eval) ;
+  sinfo_free_table(&out);
+  return NULL;
+
+
+}
+
+
+/**
+ at name sinfo_table_shift_column_int
+ at param shift a table of an integer step
+ at param t input table
+ at param col input table's column
+ at param s shift to be applied
+ at param r shift rest
+ at return pointer to a new allocated shifted table
+*/
+cpl_table*
+sinfo_table_shift_column_int(const cpl_table* t,
+                             const char* col,
+                             const double s,
+                                   double* r)
+{
+  cpl_table* out=NULL;
+  int is=(int)s;
+  int nrow=0;
+  int i=0;
+
+  const double* pi=NULL;
+  double* po=NULL;
+
+  cknull(t,"null input table");
+  out=cpl_table_duplicate(t);
+  *r=s-is;
+  nrow=cpl_table_get_nrow(t);
+  pi=cpl_table_get_data_double_const(t,col);
+  po=cpl_table_get_data_double(out,col);
+  for(i=0;i<nrow;i++) {
+    if( ((i-is) >=0) && ((i-is) < nrow)) {
+      po[i-is]=pi[i];
+    }
+  }
+  return out;
+ cleanup:
+  sinfo_free_table(&out);
+  return NULL;
+
+}
+
+
+/**
+ at name sinfo_table_shift_column_poly
+ at param shift a table of an double shift
+ at param t input table
+ at param col input table's column
+ at param shift shift to be applied
+ at param order polynomial order
+ at return pointer to a new allocated shifted table
+*/
+
+cpl_table*
+sinfo_table_shift_column_poly(cpl_table* t,
+                              const char* col,
+                              const double shift,
+                              const int order)
+{
+  cpl_table* out=NULL;
+  int nrow=0;
+  int i=0;
+  int flag=0;
+  int n_points=0;
+  int firstpos=0;
+  int z=0;
+  float eval=0;
+  float sum=0;
+  float new_sum=0;
+  float* pi=NULL;
+  float* po=NULL;
+  float* spec=NULL ;
+  float* corrected_spec=NULL ;
+  float* xnum=NULL ;
+  float* tableptr=NULL;
+
+  cknull(t,"null input table");
+  if ( order <= 0 ) {
+    sinfo_msg_error("wrong order of interpolation polynom given!") ;
+    goto cleanup;
+  }
+
+  out=cpl_table_duplicate(t);
+
+  nrow=cpl_table_get_nrow(t);
+  cpl_table_cast_column(t,col,"FINT",CPL_TYPE_FLOAT);
+  cpl_table_cast_column(out,col,"FINT",CPL_TYPE_FLOAT);
+  pi=cpl_table_get_data_float(t,"FINT");
+  po=cpl_table_get_data_float(out,"FINT");
+
+  n_points = order + 1 ;
+  if ( n_points % 2 == 0 ) {
+    firstpos = (int)(n_points/2) - 1 ;
+  } else {
+    firstpos = (int)(n_points/2) ;
+  }
+  spec=cpl_calloc(nrow,sizeof(float)) ;
+  corrected_spec=cpl_calloc(nrow,sizeof(float)) ;
+  xnum=cpl_calloc(order+1,sizeof(float)) ;
+  /* fill the xa[] array for the polint function */
+  for ( i = 0 ; i < n_points ; i++ ) {
+    xnum[i] = i ;
+  }
+
+
+  for(i=0;i<nrow;i++) {
+    corrected_spec[i] = 0. ;
+  }
+
+  sum = 0. ;
+  for ( z = 0 ; z < nrow ; z++ ) {
+    spec[z] = pi[z] ;
+    if (isnan(spec[z]) ) {
+      spec[z] = 0. ;
+
+      for ( i = z - firstpos ; i < z-firstpos+n_points ; i++ ) {
+    if ( i < 0 ) continue ;
+    if ( i >= nrow) continue  ;
+    corrected_spec[i] = ZERO ;
+      }
+    }
+    if ( z != 0 && z != nrow - 1 ) {
+      sum += spec[z] ;
+    }
+  }
+
+  new_sum = 0. ;
+  for ( z = 0 ; z < nrow ; z++ ) {
+    /* ---------------------------------------------------------------
+     * now determine the arrays of size n_points with which the
+     * polynom is determined and determine the position eval
+     * where the polynom is evaluated in polynomial interpolation.
+     * Take care of the points near the row edges!
+     */
+    if (isnan(corrected_spec[z])) continue ;
+    if ( z - firstpos < 0 ) {
+      tableptr = &spec[0] ;
+      eval     = shift + z ;
+    } else if ( z - firstpos + n_points >= nrow ) {
+      tableptr = &spec[nrow - n_points] ;
+      eval     = shift + z + n_points - nrow ;
+    } else {
+      tableptr = &spec[z-firstpos] ;
+      eval     = shift + firstpos ;
+    }
+
+    flag=0;
+    corrected_spec[z]=sinfo_new_nev_ille(xnum,tableptr,order,eval,&flag);
+    if ( z != 0 && z != nrow - 1 ) {
+      new_sum += corrected_spec[z] ;
+    }
+  }
+
+  /* fill the output spectrum */
+  for (z = 0 ; z < nrow ; z++ ) {
+    if ( new_sum == 0. ) {
+      new_sum = 1. ;
+    }
+    if ( z == 0 ) {
+      po[z] = ZERO ;
+    } else if ( z == nrow - 1 ) {
+      po[z] = ZERO ;
+    } else if ( isnan(corrected_spec[z]) ) {
+      po[z] = ZERO ;
+    } else {
+      corrected_spec[z] *= sum / new_sum ;
+      po[z] = corrected_spec[z] ;
+    }
+  }
+  check_nomsg(cpl_table_erase_column(t,"FINT"));
+  check_nomsg(cpl_table_erase_column(out,col));
+  check_nomsg(cpl_table_cast_column(out,"FINT",col,CPL_TYPE_DOUBLE));
+  check_nomsg(cpl_table_erase_column(out,"FINT"));
+
+  sinfo_free_float(&spec) ;
+  sinfo_free_float(&corrected_spec) ;
+  sinfo_free_float(&xnum) ;
+
+  return out;
+ cleanup:
+
+
+  sinfo_free_float(&spec) ;
+  sinfo_free_float(&corrected_spec) ;
+  sinfo_free_float(&xnum) ;
+  sinfo_free_table(&out);
+  return NULL;
+
+
+}
+
+
+
+
+    void sinfo_new_array_set_value( float * array, float value, int i )
+    {
+        array[i] = value ;
+    }
+    float sinfo_new_array_get_value( float * array, int i )
+    {
+        return array[i] ;
+    }
+
+
+
+    void sinfo_new_destroy_array(float ** array)
+    {
+      if(*array != NULL) {
+        cpl_free( *array ) ;
+        *array = NULL;
+      }
+    }
+
+    void sinfo_new_destroy_stringarray(char ** array, int size_x)
+    {
+        int i ;
+
+        for ( i = 0 ; i < size_x ; i++ )
+        {
+            cpl_free( array[i] ) ;
+        }
+        cpl_free( array ) ;
+    }
+
+    void sinfo_new_destroy_2Dintarray(int *** array, int size_x)
+    {
+        int i ;
+
+        if((*array) != NULL) {
+      for ( i = 0 ; i < size_x ; i++ ) {
+        if((*array)[i] != NULL) {
+          cpl_free( (*array)[i] );
+          (*array)[i]=NULL;
+        }
+      }
+      cpl_free( *array ) ;
+      *array=NULL;
+    }
+
+    }
+
+
+    void sinfo_new_intarray_set_value( int * array, int value, int i )
+    {
+        array[i] = value ;
+    }
+    float sinfo_new_array2D_get_value( float ** array, int x, int y )
+    {
+        return array[x][y] ;
+    }
+    int ** sinfo_new_2Dintarray( int size_x, int size_y)
+    {
+        int ** retVal ;
+        int i ;
+
+        retVal = (int **) cpl_calloc( size_x, sizeof (int*) ) ;
+        for ( i = 0 ; i < size_x ; i++ )
+        {
+            retVal[i] = (int *) cpl_calloc( size_y, sizeof (int)) ;
+        }
+        return retVal ;
+    }
+
+    float * sinfo_new_floatarray( int size)
+    {
+        return (float *) cpl_calloc( size, sizeof (float) ) ;
+    }
+
+
+    void sinfo_new_destroy_2Dfloatarray(float *** array, int size_x)
+    {
+        int i ;
+        if((*array) != NULL) {
+      for ( i = 0 ; i < size_x ; i++ ) {
+        if((*array)[i] != NULL) {
+          cpl_free( (*array)[i] );
+          (*array)[i]=NULL;
+        }
+      }
+      cpl_free( *array ) ;
+      *array=NULL;
+    }
+    }
+
+    void sinfo_new_destroy_2Ddoublearray(double *** array, int size_x)
+    {
+        int i ;
+
+        if((*array) != NULL) {
+      for ( i = 0 ; i < size_x ; i++ ) {
+        if((*array)[i] != NULL) {
+          cpl_free( (*array)[i] );
+          (*array)[i]=NULL;
+        }
+      }
+      cpl_free( *array ) ;
+      *array=NULL;
+    }
+
+    }
+
+
+    void sinfo_new_array2D_set_value(float ** array,float value,int x,int y)
+    {
+        array[x][y] = value ;
+    }
+
+    double sinfo_new_doublearray_get_value( double * array, int i )
+    {
+        return array[i] ;
+    }
+    void sinfo_new_doublearray_set_value( double * array, double value, int i )
+    {
+        array[i] = value ;
+    }
+
+   void sinfo_new_destroy_doublearray(double * array)
+    {
+        cpl_free( array ) ;
+    }
+    double * sinfo_new_doublearray( int size)
+    {
+        return (double *) cpl_calloc( size, sizeof (double) ) ;
+    }
+
+    double ** sinfo_new_2Ddoublearray( int size_x, int size_y)
+    {
+        double ** retVal ;
+        int i ;
+
+        retVal = (double **) cpl_calloc( size_x, sizeof (double*) ) ;
+        for ( i = 0 ; i < size_x ; i++ )
+        {
+            retVal[i] = (double *) cpl_calloc( size_y, sizeof (double)) ;
+        }
+        return retVal ;
+    }
+
+    float ** sinfo_new_2Dfloatarray( int size_x, int size_y)
+    {
+        float ** retVal ;
+        int i ;
+
+        retVal = (float **) cpl_calloc( size_x, sizeof (float*) ) ;
+        for ( i = 0 ; i < size_x ; i++ )
+        {
+            retVal[i] = (float *) cpl_calloc( size_y, sizeof (float)) ;
+        }
+        return retVal ;
+    }
+
+
+    int * sinfo_new_intarray( int size)
+    {
+        return (int *) cpl_calloc( size, sizeof (int) ) ;
+    }
+    void sinfo_new_destroy_intarray(int ** array)
+    {
+        cpl_free( *array ) ;
+        *array=NULL;
+    }
+
+    int sinfo_new_intarray_get_value( int * array, int i )
+    {
+        return array[i] ;
+    }
+
+    float sinfo_new_Stats_get_cleanstdev(Stats * stats)
+    {
+        return stats -> cleanstdev ;
+    }
+    float sinfo_new_Stats_get_cleanmean(Stats * stats)
+    {
+        return stats -> cleanmean ;
+    }
+
+char * sinfo_new_get_basename(const char *filename)
+{
+  char *p ;
+  p = strrchr (filename, '/');
+  return p ? p + 1 : (char *) filename;
+}
+
+
+
+char * sinfo_new_get_rootname(const char * filename)
+{
+    static char path[MAX_NAME_SIZE+1];
+    char * lastdot ;
+
+    if (strlen(filename)>MAX_NAME_SIZE) return NULL ;
+    memset(path, MAX_NAME_SIZE, 0);
+    strcpy(path, filename);
+    lastdot = strrchr(path, '.');
+    if (lastdot == NULL) return path ;
+    if ((!strcmp(lastdot, ".fits")) || (!strcmp(lastdot, ".FITS")) ||
+        (!strcmp(lastdot, ".paf")) || (!strcmp(lastdot, ".PAF")) ||
+        (!strcmp(lastdot, ".dat")) || (!strcmp(lastdot, ".DAT")) ||
+        (!strcmp(lastdot, ".fits")) || (!strcmp(lastdot, ".TFITS")) ||
+        (!strcmp(lastdot, ".ascii")) || (!strcmp(lastdot, ".ASCII")))
+    {
+        lastdot[0] = (char)0;
+    }
+    return path ;
+}
+
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Convert a NACO frameset to an images set
+  @param    fset    input frames set
+  @return   the newly allocated images set or NULL in error case
+
+  The first plane of the primary unit of each frame is loaded
+ */
+/*----------------------------------------------------------------------------*/
+cpl_imagelist * sinfo_new_frameset_to_iset(cpl_frameset * fset)
+{
+    cpl_imagelist   *   iset=NULL ;
+    char        **  filenames ;
+    int             nfiles=0 ;
+
+    /* Test entries */
+    if (fset == NULL) return NULL ;
+
+    /* Get the filenames */
+    if ((filenames = sinfo_new_frameset_to_filenames(fset, &nfiles)) == NULL) {
+        sinfo_msg_error( "Cannot get the files names") ;
+        return NULL ;
+    }
+    /* Load image set */
+    if ((iset = sinfo_new_imagelist_load_frameset(fset,
+                                         CPL_TYPE_FLOAT, 0, 0)) == NULL) {
+        sinfo_msg_error( "Cannot load *** the image set") ;
+        sinfo_msg_error((char* ) cpl_error_get_message());
+
+        cpl_free(filenames) ;
+        return NULL ;
+    }
+
+    /* Free and Return  */
+    cpl_free(filenames) ;
+    return iset ;
+}
+#include "cpl_imagelist_io.h"
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Load an imagelist from a frameset
+  @param    frameset  A frameset containing name(s) of image FITS files
+  @param    type      cpl_type
+  @param    pnum      The plane (FITS NAXIS3) number (0 for all planes)
+  @param    extnum    The required FITS extension (-1 for all)
+  @return   The newly created imagelist or NULL on error
+  @see      cpl_imset_load()
+
+ */
+/*----------------------------------------------------------------------------*/
+cpl_imagelist *
+sinfo_new_imagelist_load_frameset(const cpl_frameset * frameset,
+                                  cpl_type type,
+                                  int pnum,
+                                  int extnum)
+{
+    cpl_image  * image     = NULL;
+    cpl_imagelist  * imagelist = NULL;
+    const cpl_frame  * frame     = cpl_frameset_get_first_const(frameset);
+    const int nz = cpl_frameset_get_size(frameset);
+    int       i;
+
+    /* Require imagelist to contain at least one image */
+    cpl_ensure(nz > 0, CPL_ERROR_DATA_NOT_FOUND, NULL);
+
+    for (i = 0; frame != NULL;
+         i++, frame = cpl_frameset_get_next_const(frameset)) {
+
+        const char * name = cpl_frame_get_filename(frame);
+        if (name == NULL) break; /* Error check */
+
+
+        image = cpl_image_load(name, type, pnum, extnum);
+
+        if (image == NULL) break; /* Error check */
+
+        if (i == 0) {
+            const int nx = cpl_image_get_size_x(image);
+            const int ny = cpl_image_get_size_y(image);
+
+            if (nx < 1 || ny < 1) break; /* Error check */
+            imagelist = cpl_imagelist_new();
+        if (imagelist == NULL) break; /* Error check */
+        }
+
+        if (cpl_imagelist_set(imagelist, image, i)) break;
+        image = NULL; /* Image is now part of the imagelist */
+
+    }
+
+    if (i != nz) {
+        /* Error handling */
+        cpl_image_delete(image);
+        cpl_imagelist_delete(imagelist);
+        imagelist = NULL;
+    }
+    return imagelist;
+
+}
+
+/**
+ * @brief
+ *   Get the list of filenames from a cpl_frameset
+ *
+ * @param set     input frame set
+ * @param nfiles  the number of file names returned
+ *
+ * @return the newly allocated list of filenames
+ */
+
+char ** sinfo_new_frameset_to_filenames(cpl_frameset *set, int *nfiles)
+{
+    char **filenames=NULL;
+
+    int nbframes=0;
+    int i=0;
+
+    cpl_frame *curr_frame;
+
+    if (set == NULL) {
+        return NULL;
+    }
+
+    nbframes = cpl_frameset_get_size(set);
+
+    if (nbframes < 1) {
+        return NULL;
+    }
+    /*
+     * Create the list of filenames and fill it
+     */
+    filenames = cpl_malloc(nbframes * sizeof(char *));
+
+    curr_frame = cpl_frameset_get_first(set);
+    for (i = 0; i < nbframes; i++) {
+       filenames[i]=(char*) cpl_frame_get_filename(curr_frame);
+        curr_frame = cpl_frameset_get_next(set);
+    }
+
+
+    /*
+     * Set the number of files found
+     */
+    *nfiles = nbframes;
+
+    return filenames;
+
+}
+
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief        Spline interpolation based on Hermite polynomials
+   @param xp     x-value to interpolate
+   @param x      x-values
+   @param y      y-values
+   @param n      array length
+   @param istart    (input/output) initial row (set to 0 to search all row)
+
+   @return The interpolated value.
+
+   The x column must be sorted (ascending or descending) and all x column
+   values must be different.
+
+   Adopted from: Cristian Levin - ESO La Silla, 1-Apr-1991
+*/
+/*----------------------------------------------------------------------------*/
+double sinfo_spline_hermite(double xp,
+                            const double *x,
+                            const double *y,
+                              int n,
+                              int *istart )
+{
+    double yp1, yp2, yp = 0;
+    double xpi, xpi1, l1, l2, lp1, lp2;
+    int i;
+
+    if ( x[0] <= x[n-1] && (xp < x[0] || xp > x[n-1]) )    return 0.0;
+    if ( x[0] >  x[n-1] && (xp > x[0] || xp < x[n-1]) )    return 0.0;
+
+    if ( x[0] <= x[n-1] )
+    {
+        for ( i = (*istart)+1; i <= n && xp >= x[i-1]; i++ )
+        ;
+    }
+    else
+    {
+        for ( i = (*istart)+1; i <= n && xp <= x[i-1]; i++ )
+        ;
+    }
+
+    *istart = i;
+    i--;
+
+    lp1 = 1.0 / (x[i-1] - x[i]);
+    lp2 = -lp1;
+
+    if ( i == 1 )
+    {
+        yp1 = (y[1] - y[0]) / (x[1] - x[0]);
+    }
+    else
+    {
+        yp1 = (y[i] - y[i-2]) / (x[i] - x[i-2]);
+    }
+
+    if ( i >= n - 1 )
+    {
+        yp2 = (y[n-1] - y[n-2]) / (x[n-1] - x[n-2]);
+    }
+    else
+    {
+        yp2 = (y[i+1] - y[i-1]) / (x[i+1] - x[i-1]);
+    }
+
+    xpi1 = xp - x[i];
+    xpi  = xp - x[i-1];
+    l1   = xpi1*lp1;
+    l2   = xpi*lp2;
+
+    yp = y[i-1]*(1 - 2.0*lp1*xpi)*l1*l1 +
+         y[i]*(1 - 2.0*lp2*xpi1)*l2*l2 +
+         yp1*xpi*l1*l1 + yp2*xpi1*l2*l2;
+
+    return yp;
+}
+
+/**
+  @brief    Update the bad pixel map for the image - mark all pixels with NaN value as a bad
+  @param    im             Image with pixel-type float or double
+  @return   0 iff ok
+  */
+cpl_error_code update_bad_pixel_map(cpl_image* im)
+{
+	int szx = cpl_image_get_size_x(im);
+	int szy = cpl_image_get_size_y(im);
+	int x = 0;
+	cpl_mask* bpm = cpl_image_get_bpm(im);
+
+	for (x = 1; x <=szx; x++)
+	{
+		int y = 0;
+		for(y = 1; y <= szy; y++)
+		{
+			int isnull = 0;
+			double value = cpl_image_get(im, x, y, &isnull);
+			if (isnan(value))
+			{
+				cpl_mask_set(bpm, x, y, CPL_BINARY_1);
+			}
+		}
+	}
+	return cpl_error_get_code();
+}
+cpl_polynomial * sinfo_polynomial_fit_2d_create(cpl_bivector     *  xy_pos,
+                                              cpl_vector       *  values,
+                                              cpl_size                 degree,
+                                              double           *  mse)
+{
+	typedef double* (*get_data)(cpl_bivector*);
+	get_data data_extractor[2] = { &cpl_bivector_get_x_data, &cpl_bivector_get_y_data};
+	//samppos matrix must
+	// have two rows with copies of the two vectors in the x_pos bivector.
+
+    double rechisq = 0;
+    int i, j;
+    cpl_vector     * fitresidual = 0;
+    cpl_matrix     * samppos2d = 0;
+    cpl_polynomial * fit2d = cpl_polynomial_new(2);
+    int xy_size = cpl_bivector_get_size(xy_pos);
+
+    samppos2d = cpl_matrix_new(2, xy_size);
+    for (i = 0; i < 2; i++)
+    {
+    	for (j = 0; j < xy_size; j++)
+    	{
+    		double value = data_extractor[i](xy_pos)[j];
+    		cpl_matrix_set(samppos2d, i, j, value);
+    	}
+    }
+
+   cpl_polynomial_fit(fit2d, samppos2d, NULL, values, NULL, CPL_FALSE,
+                             NULL, &degree);
+
+    fitresidual = cpl_vector_new(xy_size);
+    cpl_vector_fill_polynomial_fit_residual(fitresidual, values, NULL, fit2d,
+                                            samppos2d, &rechisq);
+    if (mse)
+    {
+        *mse = cpl_vector_product(fitresidual, fitresidual)
+            / cpl_vector_get_size(fitresidual);
+    }
+    cpl_matrix_delete(samppos2d);
+    cpl_vector_delete(fitresidual);
+    return fit2d;
+}
+
+cpl_polynomial * sinfo_polynomial_fit_1d_create(
+		const cpl_vector    *   x_pos,
+        const cpl_vector    *   values,
+        int                     degree,
+        double              *   mse
+        )
+{
+    cpl_polynomial * fit1d = cpl_polynomial_new(1);
+//    cpl_vector* x_copy = cpl_vector_duplicate(x_pos);
+//    cpl_vector* values_copy = cpl_vector_duplicate(values);
+    int x_size = cpl_vector_get_size(x_pos);
+    double rechisq = 0;
+    cpl_size loc_deg=(cpl_size)degree;
+    cpl_matrix     * samppos = cpl_matrix_wrap(1, x_size,
+                                               (double*)cpl_vector_get_data_const(x_pos));
+    cpl_vector     * fitresidual = cpl_vector_new(x_size);
+
+    cpl_polynomial_fit(fit1d, samppos, NULL, values, NULL,
+                       CPL_FALSE, NULL, &loc_deg);
+    cpl_ensure(!cpl_error_get_code(), cpl_error_get_code(), NULL);
+    cpl_vector_fill_polynomial_fit_residual(fitresidual, values, NULL, fit1d,
+                                            samppos, &rechisq);
+    cpl_ensure(!cpl_error_get_code(), cpl_error_get_code(), NULL);
+    if (mse)
+    {
+        *mse = cpl_vector_product(fitresidual, fitresidual)
+            / cpl_vector_get_size(fitresidual);
+    }
+    cpl_matrix_unwrap(samppos);
+    cpl_vector_delete(fitresidual);
+    return fit1d;
+}
+
+//cpl_image * sinfo_image_filter_
+static cpl_image * sinfo_image_filter_wrapper(const cpl_image *b, const cpl_matrix *k, cpl_filter_mode mode)
+{
+	const double EPSILON = 1E-5;
+	int nx   = cpl_image_get_size_x(b);
+	int ny   = cpl_image_get_size_y(b);
+	int nrow = cpl_matrix_get_nrow(k);
+	int ncol = cpl_matrix_get_ncol(k);
+	int i, j;
+	cpl_type type = cpl_image_get_type(b);
+	cpl_image * a = cpl_image_new(nx, ny, type);
+	// where m is a cpl_mask with a CPL_BINARY_1 whereever k has a 1.0.
+	cpl_mask* m = cpl_mask_new(ncol, nrow);
+	cpl_msg_warning(cpl_func, "nx[%d], ny[%d], ncol[%d], nrow[%d]", nx, ny, ncol, nrow);
+	for (i = 0; i < ncol ; i++)
+	{
+		for (j = 0; j < nrow ; j++)
+		{
+			double value = cpl_matrix_get(k, j, i);
+			if (fabs(value - 1.0) < EPSILON)
+			{
+				cpl_mask_set(m, i + 1, j + 1, CPL_BINARY_1);
+			}
+		}
+	}
+
+	cpl_image_filter_mask(a, b, m, mode, CPL_BORDER_FILTER);
+	cpl_mask_delete(m);
+	return a;
+ }
+
+
+static cpl_image*
+sinfo_image_filter_mode(const cpl_image* b,
+                      const cpl_matrix * ker,
+                      cpl_filter_mode filter)
+{
+  int nx   = cpl_image_get_size_x(b);
+  int ny   = cpl_image_get_size_y(b);
+  int type = cpl_image_get_type(b);
+  cpl_image * a = cpl_image_new(nx, ny, type);
+
+  switch(filter) {
+  case CPL_FILTER_MEDIAN:
+    check_nomsg(cpl_image_filter(a, b, ker, CPL_FILTER_MEDIAN, CPL_BORDER_FILTER));
+    break;
+  case CPL_FILTER_LINEAR:
+    check_nomsg(cpl_image_filter(a, b, ker, CPL_FILTER_LINEAR, CPL_BORDER_FILTER));
+    break;
+  case CPL_FILTER_STDEV:
+    cpl_image_filter(a, b, ker, CPL_FILTER_STDEV, CPL_BORDER_FILTER);
+    break;
+  case CPL_FILTER_MORPHO:
+    cpl_image_filter(a, b, ker, CPL_FILTER_MORPHO, CPL_BORDER_FILTER);
+    break;
+  default:
+    sinfo_msg_error("Filter type not supported");
+    return NULL;
+  }
+ cleanup:
+
+  return a;
+
+}
+
+cpl_image * 
+sinfo_image_filter_linear(const cpl_image *img, const cpl_matrix * mx)
+{
+	return sinfo_image_filter_mode(img, mx, CPL_FILTER_LINEAR);
+
+}
+
+cpl_image * sinfo_image_filter_linear2(const cpl_image *img, const cpl_matrix * mx)
+{
+	return sinfo_image_filter_wrapper(img, mx, CPL_FILTER_LINEAR);
+
+}
+
+
+cpl_image * sinfo_image_filter_median(const cpl_image * img, const cpl_matrix * mx)
+{
+	return sinfo_image_filter_wrapper(img, mx, CPL_FILTER_MEDIAN);
+}
+
+
+/**@}*/
diff --git a/sinfoni/sinfo_utilities.h b/sinfoni/sinfo_utilities.h
new file mode 100644
index 0000000..171d6cd
--- /dev/null
+++ b/sinfoni/sinfo_utilities.h
@@ -0,0 +1,214 @@
+/* $Id: sinfo_utilities.h,v 1.13 2011/12/09 07:47:42 amodigli Exp $
+ *
+ * This file is part of the SINFONI Pipeline
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2011/12/09 07:47:42 $
+ * $Revision: 1.13 $
+ * $Name: sinfo-2_3_2 $
+ */
+#ifndef SINFO_UTILITIES_H
+#define SINFO_UTILITIES_H
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+#include <sinfo_cpl_size.h>
+
+/*
+  This recipe implements error handling cleanly using a pair of macros called
+  sinfo_skip_if() and sinfo_end_skip.
+
+  sinfo_skip_if() takes one argument, which is a logical expression.
+  If the logical expression is false sinfo_skip_if() takes no action and
+  program execution continues.
+  If the logical expression is true this indicates an error. In this case
+  sinfo_skip_if() will set the location of the error to the point where it
+  was invoked in the recipe code (unless the error location is already in the
+  recipe code). If no error code had been set, then sinfo_skip_if() will set
+  one. Finally, sinfo_skip_if() causes program execution to skip to the
+  macro 'sinfo_end_skip'.
+  The macro sinfo_end_skip is located towards the end of the function, after
+  which all resource deallocation and the function return is located.
+
+  The use of sinfo_skip_if() assumes the following coding practice:
+  1) Pointers used for dynamically allocated memory that they "own" shall
+     always
+     point to either NULL or to allocated memory (including CPL-objects).
+  2) Such pointers may not be reused to point to memory whose deallocation
+     requires calls to different functions.
+  3) Pointers of type FILE should be set NULL when not pointing to an open
+     stream and their closing calls (fclose(), freopen(), etc.) following the
+     'sinfo_end_skip' should be guarded against such NULL pointers.
+
+  Error checking with sinfo_skip_if() is encouraged due to the following
+  advantages:
+  1) It ensures that a CPL-error code is set.
+  2) It ensures that the location of the error in the _recipe_ code is noted.
+  3) The error checking may be confined to a single concise line.
+  4) It is not necessary to replicate memory deallocation for every error
+     condition.
+  5) If more extensive error reporting/handling is required it is not precluded
+     by the use of sinfo_skip_if().
+  6) It allows for a single point of function return.
+  7) It allows for optional, uniformly formatted debugging/tracing information
+     at each macro invocation.
+
+  The implementation of sinfo_skip_if() uses a goto/label construction.
+  According to Kerningham & Ritchie, The C Programming Language, 2nd edition,
+  Section 3.8:
+  "This organization is handy if the error-handling code is non-trivial,
+  and if errors can occur in several places."
+
+  The use of goto for any other purpose should be avoided.
+
+*/
+
+#define sinfo_skip_if(CONDITION) \
+  do if (CONDITION) { \
+    if (cpl_error_get_code()) { \
+        cpl_msg_debug("", "Skip in %s line %d due to '%s' with error '%s' " \
+                      "at %s", __FILE__, __LINE__, #CONDITION, \
+                      cpl_error_get_message(), cpl_error_get_where());  \
+        if (strstr(cpl_error_get_where(), "visir") == NULL) \
+            cpl_error_set_where(""); \
+    } else { \
+        cpl_msg_debug("", "Skip in %s line %d due to '%s'", \
+                        __FILE__, __LINE__, #CONDITION);  \
+        cpl_error_set("", CPL_ERROR_UNSPECIFIED); \
+    } \
+    goto cleanup; \
+  } else { \
+    if (cpl_error_get_code()) \
+        cpl_msg_debug("", "No skip in %s line %d due to '%s' with error '%s' " \
+                      "at %s", __FILE__, __LINE__, #CONDITION, \
+                      cpl_error_get_message(), cpl_error_get_where()); \
+    else \
+        cpl_msg_debug("", "No skip in %s line %d due to '%s'", \
+                      __FILE__, __LINE__, #CONDITION);  \
+  } while (0)
+
+
+#define sinfo_end_skip \
+    do { \
+        cleanup: \
+        if (cpl_error_get_code()) \
+            cpl_msg_debug("", "Cleanup in %s line %d with error '%s' at %s", \
+                           __FILE__, __LINE__, \
+                          cpl_error_get_message(), cpl_error_get_where()); \
+        else \
+            cpl_msg_debug("", "Cleanup in %s line %d", \
+                          __FILE__, __LINE__);  \
+    } while (0)
+
+
+#include <cpl.h>
+#include <sinfo_image_ops.h>
+#include "sinfo_globals.h"
+CPL_BEGIN_DECLS
+
+
+cpl_image*
+sinfo_vector_to_image(const cpl_vector* vector,cpl_type type);
+
+int
+sinfo_table_column_dump(cpl_table* t, const char* name, cpl_type type);
+
+cpl_table*
+sinfo_table_shift_column_spline3(cpl_table* t,
+                                 const char* col,
+                                 const double s);
+
+cpl_table*
+sinfo_table_shift_column_poly(cpl_table* t,
+                              const char* col,
+                              const double s,
+                              const int order);
+
+cpl_table*
+sinfo_table_shift_column_int(const cpl_table* t,
+                             const char* col,
+                             const double s,
+                                   double* r);
+
+cpl_error_code
+sinfo_ima_line_cor(cpl_parameterlist * parlist, cpl_frameset* in);
+
+
+void sinfo_new_array_set_value( float * array, float value, int i );
+float sinfo_new_array_get_value( float * array, int i );
+void sinfo_new_destroy_array(float ** array);
+void sinfo_new_destroy_stringarray(char ** array, int size_x);
+void sinfo_new_intarray_set_value( int * array, int value, int i );
+void sinfo_new_array2D_set_value( float ** array, float value, int x, int y );
+void sinfo_new_destroy_2Dintarray(int *** array, int size_x);
+void sinfo_new_destroy_2Dfloatarray(float *** array, int size_x);
+void sinfo_new_destroy_2Ddoublearray(double *** array, int size_x);
+void sinfo_new_destroy_intarray(int ** array);
+void sinfo_new_destroy_doublearray(double * array);
+void sinfo_new_doublearray_set_value( double * array, double value, int i );
+int sinfo_new_intarray_get_value( int * array, int i );
+int * sinfo_new_intarray( int size);
+int ** sinfo_new_2Dintarray( int size_x, int size_y);
+double ** sinfo_new_2Ddoublearray( int size_x, int size_y);
+char * sinfo_new_get_rootname(const char * filename);
+char * sinfo_new_get_basename(const char *filename);
+float sinfo_new_Stats_get_cleanstdev(Stats * stats);
+float sinfo_new_Stats_get_cleanmean(Stats * stats);
+float sinfo_new_array2D_get_value( float ** array, int x, int y );
+float * sinfo_new_floatarray( int size);
+float ** sinfo_new_2Dfloatarray( int size_x, int size_y);
+double   sinfo_new_doublearray_get_value( double * array, int i );
+
+double * sinfo_new_doublearray( int size);
+/*
+FitParams ** sinfo_new_fit_params( int n_params ) ;
+*/
+cpl_imagelist * sinfo_new_frameset_to_iset(cpl_frameset *) ;
+cpl_imagelist *
+sinfo_new_imagelist_load_frameset(const cpl_frameset * frameset,cpl_type type,
+                                            int pnum,int extnum);
+
+char ** sinfo_new_frameset_to_filenames(cpl_frameset *set, int *nfiles);
+char ** new_frameset_to_tags(cpl_frameset *set, int *ntags);
+double sinfo_spline_hermite(double xp,
+                            const double *x,
+                            const double *y,
+                                  int n,
+                                  int *istart );
+
+cpl_error_code update_bad_pixel_map(cpl_image* im);
+/* replacement of deprecated functions */
+cpl_polynomial * sinfo_polynomial_fit_2d_create(cpl_bivector     *  xy_pos,
+                                              cpl_vector       *  values,
+                                              cpl_size                 degree,
+                                              double           *  mse);
+cpl_polynomial * sinfo_polynomial_fit_1d_create(
+		const cpl_vector    *   x_pos,
+        const cpl_vector    *   values,
+        int                     degree,
+        double              *   mse
+        );
+cpl_image * sinfo_image_filter_median(const cpl_image *, const cpl_matrix *);
+cpl_image * sinfo_image_filter_linear(const cpl_image *, const cpl_matrix *);
+cpl_image * sinfo_image_filter_linear2(const cpl_image *, const cpl_matrix *);
+CPL_END_DECLS
+
+#endif
diff --git a/sinfoni/sinfo_utilities_scired.c b/sinfoni/sinfo_utilities_scired.c
new file mode 100644
index 0000000..df318b5
--- /dev/null
+++ b/sinfoni/sinfo_utilities_scired.c
@@ -0,0 +1,2165 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+#include <irplib_stdstar.h>
+
+//Used only for sinfo_propertylist_has
+#include "sinfo_dfs.h"
+
+//Used only for sinfo_band
+#include "sinfo_tpl_utils.h"
+
+#include "sinfo_utilities_scired.h"
+#include "sinfo_functions.h"
+#include "sinfo_pfits.h"
+#include "sinfo_spiffi_types.h"
+#include "sinfo_utils_wrappers.h"
+#include "sinfo_error.h"
+
+static double
+sinfo_sess2deg(const double sess);
+
+static void
+sinfo_set_spect_coord1(cpl_propertylist** plist,
+               const int crpix1,
+               const double crval1,
+               const double cdelt1);
+
+static void
+sinfo_set_spect_coord2(cpl_propertylist** plist,
+               const int crpix2,
+               const double crval2,
+               const double cdelt2);
+
+
+static void
+sinfo_set_coord1(cpl_propertylist** plist,
+                 const double crpix1,
+                 const double crval1,
+                 const double cdelt1);
+static void
+sinfo_set_coord2(cpl_propertylist** plist,
+                 const double crpix2,
+                 const double crval2,
+                 const double cdelt2);
+static void
+sinfo_set_coord3(cpl_propertylist** plist,
+                 const int crpix3,
+                 const double crval3,
+                 const double cdelt3);
+
+
+static void
+sinfo_set_cd_matrix2(cpl_propertylist** plist,
+            const double cd1_1,
+            const double cd1_2,
+            const double cd2_1,
+            const double cd2_2);
+
+
+static void
+sinfo_set_cd_matrix3(cpl_propertylist** plist,
+                     const double cd1_3,
+                     const double cd2_3,
+                     const double cd3_1,
+                     const double cd3_2,
+                     const double cd3_3);
+
+
+static void
+sinfo_new_change_plist_cube (cpl_propertylist * plist,
+                             float cenLambda,
+                             float dispersion,
+                             int   center_z,
+                             float center_x,
+			     float center_y );
+
+
+static void
+sinfo_new_change_plist_image (cpl_propertylist * plist,
+                              float center_x,
+			      float center_y );
+
+
+static void
+sinfo_new_change_plist_spectrum (cpl_propertylist * plist,
+				 double cenLambda,
+				 double dispersion,
+				 int   cenpix);
+
+static cpl_image *
+sinfo_new_image_getvig(
+        cpl_image    *   image_in,
+        int             loleft_x,
+        int             loleft_y,
+        int             upright_x,
+        int             upright_y);
+
+
+
+/**@{*/
+
+/**
+ * @addtogroup sinfo_utilities science utilities
+ *
+ * TBD
+ */
+/**
+  @brief    Check input data
+  @param    cfg   object configuration parameter
+  @return 0 if suggess, else -1;
+*/
+int
+sinfo_check_input_data(object_config* cfg)
+{
+
+
+    if (cfg == NULL)
+    {
+        sinfo_msg_error (" could not parse cpl input!\n") ;
+        return -1 ;
+    }
+
+
+    if(sinfo_is_fits_file(cfg->wavemap) != 1) {
+      sinfo_msg_error("Input file wavemap %s is not FITS",cfg->wavemap);
+      return -1;
+    }
+
+
+    if (cfg->halocorrectInd == 1)
+    {
+       if(sinfo_is_fits_file(cfg->halospectrum) != 1) {
+          sinfo_msg_error("Input file %s is not FITS",cfg->halospectrum);
+          return -1;
+       }
+
+    }
+
+    if (cfg->northsouthInd == 0) {
+      if (sinfo_is_fits_file(cfg->poslist) != 1)
+    {
+      sinfo_msg_error("File %s with tag %s is not FITS!",
+                          cfg->poslist,PRO_SLIT_POS);
+      return -1 ;
+    }
+    } else {
+
+      if (sinfo_is_fits_file(cfg->distlist) != 1)
+    {
+      sinfo_msg_error("File %s with tag %s is not FITS!",
+                           cfg->distlist,PRO_SLITLETS_DISTANCE);
+      return -1;
+    }
+    }
+
+
+    return 0;
+
+
+}
+/**
+  @brief    Convert a double from ssessagesimal to deg:
+            110905.197316= 11h:09m:05.197316s = 167.271655483
+  @param    sess   angle in seesagesimal units (see above)
+  @return 0 if suggess, else -1;
+*/
+
+static double
+sinfo_hms2deg(const double hms)
+{
+  int hrs=0;
+  int min=0;
+  double sec=0;
+  double deg=0;
+  double rest=hms;
+  int sign=1;
+
+  //sinfo_msg("hms=%f",hms);
+
+  if(hms<0) {
+    sign=-1;
+    rest=-hms;
+  }
+  //sinfo_msg("rest=%f",rest);
+  //sinfo_msg("sign=%d",sign);
+
+  hrs=(int)(rest/10000.);
+  //sinfo_msg("hrs=%d",hrs);
+
+  rest=rest-(double)(hrs*10000.);
+  min=(int)(rest/100.);
+  //sinfo_msg("min=%d",min);
+
+  sec=rest-(double)(min*100.);
+  //sinfo_msg("sec=%f",sec);
+
+  deg=hrs*15+(double)(min/4.)+(double)(sec/240.);
+  //sinfo_msg("deg=%f",deg);
+
+  deg=sign*deg;
+  //sinfo_msg("deg=%f",deg);
+
+  return deg;
+
+}
+
+/**
+  @brief    Convert a double from ssessagesimal to deg:
+            203049.197= 20:30:49.197 = 20.5136658333
+  @param    sess   angle in seesagesimal units (see above)
+  @return 0 if suggess, else -1;
+*/
+
+static double
+sinfo_sess2deg(const double sess)
+{
+  int grad=0;
+  int min=0;
+  double sec=0;
+  double deg=0;
+  double rest=sess;
+  int sign=1;
+
+  //sinfo_msg("sess=%f",sess);
+
+  if(sess<0) {
+    sign=-1;
+    rest=-sess;
+  }
+  //sinfo_msg("rest=%f",rest);
+  //sinfo_msg("sign=%d",sign);
+
+  grad=(int)(rest/10000.);
+  //sinfo_msg("grad=%d",grad);
+
+  rest=rest-(double)(grad*10000.);
+  min=(int)(rest/100.);
+  //sinfo_msg("min=%d",min);
+
+  sec=rest-(double)(min*100.);
+  //sinfo_msg("sec=%f",sec);
+
+  deg=grad+(double)(min/60.)+(double)(sec/3600.);
+  //sinfo_msg("deg=%f",deg);
+
+  deg=sign*deg;
+  //sinfo_msg("deg=%f",deg);
+
+  return deg;
+
+}
+
+
+/**
+  @brief    Computes size of coadded cube
+  @param    offsetx  input offset list
+  @param    offsety  input offset list
+  @param    nframes  input number of values
+  @param    ref_offx input reference offset array
+  @param    ref_offy input reference offset array
+  @param    size_x   input/output coadded cube x size
+  @param    size_y   input/output coadded cube y size
+  @return   size of  coadded cube
+*/
+
+int
+sinfo_auto_size_cube(float* offsetx,
+                      float* offsety,
+              const int nframes,
+                    float* ref_offx,
+                    float* ref_offy,
+                    int* size_x,
+                    int* size_y)
+{
+
+  int n=0;
+  float offx=0;
+  float offy=0;
+  float min_offx=0;
+  float max_offx=0;
+  float min_offy=0;
+  float max_offy=0;
+
+  sinfo_msg ("Computation of output cube size") ;
+  for ( n = 0 ; n < nframes ; n++ ) {
+    offx = offsetx[n];  /* was - */
+    offy = offsety[n];  /* was - */
+    /* sinfo_msg("frame %d offx=%f offy=%f",n,offx,offy); */
+    if(n==0) {
+      min_offx=offx;
+      min_offy=offy;
+      max_offx=offx;
+      max_offy=offy;
+    } else {
+      if(offx > max_offx) max_offx=offx;
+      if(offy > max_offy) max_offy=offy;
+      if(offx < min_offx) min_offx=offx;
+      if(offy < min_offy) min_offy=offy;
+    }
+  }
+  /*
+  sinfo_msg("max_offx=%f max_offy=%f",max_offx,max_offy);
+  sinfo_msg("min_offx=%f min_offy=%f",min_offx,min_offy);
+  */
+  *ref_offx=(min_offx+max_offx)/2;
+  *ref_offy=(min_offy+max_offy)/2;
+  *size_x+=2*floor(max_offx-min_offx+0.5);
+  *size_y+=2*floor(max_offy-min_offy+0.5);
+  sinfo_msg("Output cube size: %d x %d",*size_x,*size_y);
+  sinfo_msg("Ref offset. x: %f y: %f",*ref_offx,*ref_offy);
+  sinfo_msg_debug("Max offset. x: %f y: %f",max_offx,max_offy);
+  sinfo_msg_debug("Min offset. x: %f y: %f",min_offx,min_offy);
+  return 0;
+
+}
+
+/**
+  @brief    Computes size of coadded cube
+  @param    cfg          inpout parameters configuration
+  @param    ref_offx     inpout reference offset array
+  @param    ref_offy     inpout reference offset array
+  @return   size of coadded cube
+*/
+int
+sinfo_auto_size_cube5(object_config * cfg,
+                    float* ref_offx, float* ref_offy,
+                    float* min_offx, float* min_offy,
+                    float* max_offx, float* max_offy)
+{
+
+  char* name =NULL;
+  int n=0;
+  float offx=0;
+  float offy=0;
+
+  cpl_propertylist * plist=NULL;
+  sinfo_msg ("Automatic computation of output cube size") ;
+  for ( n = 0 ; n < cfg->nframes ; n++ ) {
+    name = cfg->framelist[n] ;
+    plist=cpl_propertylist_load(name,0);
+    offx = sinfo_pfits_get_cumoffsetx(plist);  /* was - */
+    if(cpl_error_get_code() != CPL_ERROR_NONE) {
+      sinfo_msg_warning(" could not read fits header keyword cummoffsetx!");
+      sinfo_msg_warning(" set it to  0");
+      offx = 0;
+      cpl_error_reset();
+      /* return -1 ; */
+    }
+
+    offy = sinfo_pfits_get_cumoffsety(plist); /* was - */
+    sinfo_free_propertylist(&plist);
+    if(cpl_error_get_code() != CPL_ERROR_NONE) {
+      sinfo_msg_warning(" could not read fits header keyword! cumoffsety") ;
+      sinfo_msg_warning(" set it to 0");
+      offy = 0;
+      cpl_error_reset();
+      /* return -1 ; */
+    }
+    //sinfo_msg("n=%d offx=%f offy=%f",n,offx,offy);
+
+    if(n==0) {
+      *min_offx=offx;
+      *min_offy=offy;
+      *max_offx=offx;
+      *max_offy=offy;
+    } else {
+      if(offx > *max_offx) *max_offx=offx;
+      if(offy > *max_offy) *max_offy=offy;
+      if(offx < *min_offx) *min_offx=offx;
+      if(offy < *min_offy) *min_offy=offy;
+    }
+  }
+  *ref_offx=(*min_offx+*max_offx)/2;
+  *ref_offy=(*min_offy+*max_offy)/2;
+
+  if(cfg->size_x == 0) cfg->size_x=2*floor(*max_offx-*min_offx+0.5)+64 ;
+/* The formula above doesn't give always the right result (DSF07663)
+ * for example, if diff in offset is 35.5, the formula gives 72 but 71 would be
+ * enough, the following candidate is working fine:
+ *   if(cfg->size_x == 0)
+	  cfg->size_x=floor(2.0*(*max_offx-*min_offx + 0.5 - 0.00001))+64 ;
+	  Currently the ticket is suspended, because the formula above
+	  would change the scientific results for the previous data.
+	  The same is actual for Y axis.
+*/
+  if(cfg->size_y == 0) cfg->size_y=2*floor(*max_offy-*min_offy+0.5)+64 ;
+
+  sinfo_msg("Output cube size: %d x %d",cfg->size_x,cfg->size_y);
+  sinfo_msg("Ref offset. x: %f y: %f",*ref_offx,*ref_offy);
+  sinfo_msg("Max offset. x: %f y: %f",*max_offx,*max_offy);
+  sinfo_msg("Min offset. x: %f y: %f",*min_offx,*min_offy);
+  return 0;
+
+
+}
+
+/**
+  @brief    Read slitlets distances
+  @param    nslits input number of slitlets
+  @param    distlist input slit distances file name
+  @return   array with slitlet distances
+*/
+
+
+
+float*
+sinfo_read_distances(const int nslits, const char* distlist)
+{
+  int i=0;
+  int* status=NULL;
+  float * distances = NULL;
+  float tmp_float=0;
+  char tbl_distances_name[FILE_NAME_SZ];
+  cpl_table* tbl_distances = NULL;
+
+  sinfo_msg("Read distances");
+  distances = (float*) cpl_calloc (nslits - 1, sizeof (float));
+
+  if ( NULL == distances )
+    {
+      sinfo_msg_error ("could allocate memory!") ;
+      return NULL ;
+    }
+
+            /*READ TFITS TABLE*/
+  if(cpl_error_get_code() != CPL_ERROR_NONE) {
+    sinfo_msg_error("Before loading input table");
+    sinfo_msg_error((char* ) cpl_error_get_message());
+    return NULL;
+  }
+  strcpy(tbl_distances_name,distlist);
+  tbl_distances = cpl_table_load(tbl_distances_name,1,0);
+  if(cpl_error_get_code() != CPL_ERROR_NONE) {
+    sinfo_msg_error("loading input table %s",tbl_distances_name);
+    sinfo_msg_error((char* ) cpl_error_get_message());
+    return NULL;
+  }
+
+  for (i =0 ; i< nslits-1; i++){
+    tmp_float=cpl_table_get_float(tbl_distances,"slitlet_distance",i,status);
+    if(cpl_error_get_code() != CPL_ERROR_NONE) {
+      sinfo_msg_error("reading col %s from table %s","slitlet_distance",
+                       tbl_distances_name);
+      sinfo_msg_error((char* ) cpl_error_get_message());
+      return NULL;
+    }
+    sinfo_new_array_set_value(distances,tmp_float,i);
+  }
+  cpl_table_delete(tbl_distances);
+  return distances;
+
+}
+
+
+
+/**
+  @brief    Read slitlets edges
+  @param    nslits number of input slitlets
+  @param    poslist input file name with slit positions
+  @return   array with slitlet edges
+*/
+
+float**
+sinfo_read_slitlets_edges(const int nslits, const char* poslist)
+{
+
+
+  char tbl_slitpos_name[FILE_NAME_SZ];
+  cpl_table* tbl_slitpos=NULL;
+  int n=0;
+  int i=0;
+  int* status=NULL;
+  float edge_x=0;
+  float edge_y=0;
+  float ** slit_edges = NULL;
+
+  slit_edges = sinfo_new_2Dfloatarray(nslits, 2) ;
+
+  strcpy(tbl_slitpos_name,poslist);
+  tbl_slitpos = cpl_table_load(tbl_slitpos_name,1,0);
+  if(cpl_error_get_code() != CPL_ERROR_NONE) {
+    sinfo_msg_error("error loading tbl %s",tbl_slitpos_name);
+    sinfo_msg_error((char* ) cpl_error_get_message());
+    return NULL;
+  }
+  n = cpl_table_get_nrow(tbl_slitpos);
+  if (n != nslits) {
+    sinfo_msg_error("No of slitlets in table is n = %d != %d !",n,nslits);
+    return NULL;
+  }
+
+  for (i =0 ; i< nslits; i++){
+    edge_x=cpl_table_get_double(tbl_slitpos,"pos1",i,status);
+    edge_y=cpl_table_get_double(tbl_slitpos,"pos2",i,status);
+    if(cpl_error_get_code() != CPL_ERROR_NONE) {
+      sinfo_msg_error("error reading tbl %s row %d",tbl_slitpos_name,i);
+      sinfo_msg_error((char* ) cpl_error_get_message());
+      return NULL;
+    }
+    sinfo_new_array2D_set_value(slit_edges,edge_x,i,0);
+    sinfo_new_array2D_set_value(slit_edges,edge_y,i,1);
+  }
+  cpl_table_delete(tbl_slitpos);
+  if(cpl_error_get_code() != CPL_ERROR_NONE) {
+    sinfo_msg_error("error reading tbl %s",tbl_slitpos_name);
+    sinfo_msg_error((char* ) cpl_error_get_message());
+    return NULL;
+  }
+
+  return slit_edges;
+
+}
+
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Extract a rectangular zone from a cube into another cube.
+  @param    cube_in     Input cube
+  @param    loleft_x    Lower left X coordinate
+  @param    loleft_y    Lower left Y coordinate
+  @param    upright_x   Upper right X coordinate
+  @param    upright_y   Upper right Y coordinate
+  @return   1 newly allocated cube.
+
+  The input coordinates define the extracted region by giving the
+  coordinates of the lower left and upper right corners (inclusive).
+
+  Coordinates must be provided in the FITS convention: lower left
+  corner of the image is at (1,1), x growing from left to right,
+  y growing from bottom to top.
+
+  The same rectangle is extracted from each plane in the input cube,
+  and appended to the output cube.
+
+  The returned cube contains pixel copies of the input pixels. It must be
+  freed using cube_del().
+ */
+/*---------------------------------------------------------------------------*/
+cpl_imagelist * sinfo_new_cube_getvig(
+        cpl_imagelist *        cube_in,
+        int             loleft_x,
+        int             loleft_y,
+        int             upright_x,
+        int             upright_y)
+{
+    cpl_imagelist     *        cube_out ;
+    int                 i ;
+    int                 outlx,
+                                        outly ;
+
+    int ilx=0;
+    int ily=0;
+    int inp=0;
+    cpl_image* i_img=NULL;
+    cpl_image* o_img=NULL;
+
+    if (cube_in==NULL) return NULL ;
+
+    ilx=cpl_image_get_size_x(cpl_imagelist_get(cube_in,0));
+    ily=cpl_image_get_size_y(cpl_imagelist_get(cube_in,0));
+    inp=cpl_imagelist_get_size(cube_in);
+
+        if ((loleft_x>upright_x) ||
+            (loleft_y>upright_y)) {
+            sinfo_msg_error("ill-defined slit for extraction: aborting");
+            return NULL ;
+        }
+
+    /* Extraction coordinates include rectangular zone  */
+    outlx = upright_x - loleft_x + 1 ;
+    outly = upright_y - loleft_y + 1 ;
+    /*
+    cube_out = sinfo_new_cube(outlx, outly, cube_in->np) ;
+    */
+    cube_out = cpl_imagelist_new() ;
+    /* Loop on all input planes */
+    for (i=0 ; i<cpl_imagelist_get_size(cube_in) ; i++) {
+
+      i_img=cpl_imagelist_get(cube_in,i);
+        /* Extract a slit from this plane   */
+                o_img = sinfo_new_image_getvig(i_img,
+                        loleft_x, loleft_y,
+                        upright_x, upright_y) ;
+        cpl_imagelist_set(cube_out,o_img,i);
+    }
+    return cube_out ;
+}
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Extract a rectangular zone from an image into another image.
+  @param    image_in    Input image
+  @param    loleft_x    Lower left X coordinate
+  @param    loleft_y    Lower left Y coordinate
+  @param    upright_x   Upper right X coordinate
+  @param    upright_y   Upper right Y coordinate
+  @return   1 newly allocated image.
+
+  The input coordinates define the extracted region by giving the
+  coordinates of the lower left and upper right corners (inclusive).
+
+  Coordinates must be provided in the FITS convention: lower left
+  corner of the image is at (1,1), x growing from left to right,
+  y growing from bottom to top.
+ */
+/*---------------------------------------------------------------------------*/
+
+static cpl_image *
+sinfo_new_image_getvig(
+        cpl_image    *    image_in,
+        int             loleft_x,
+        int             loleft_y,
+        int             upright_x,
+        int             upright_y)
+{
+    cpl_image    *        slit_img ;
+    int                 i, j ;
+    register
+    pixelvalue  *       inpt,
+                                *       outpt ;
+    int         outlx, outly ;
+    int ilx=0;
+    int ily=0;
+
+    float* pidata=NULL;
+    float* podata=NULL;
+
+    if (image_in==NULL) return NULL ;
+
+    ilx=cpl_image_get_size_x(image_in);
+    ily=cpl_image_get_size_y(image_in);
+    pidata=cpl_image_get_data_float(image_in);
+
+    if ((loleft_x<1) || (loleft_x>ilx) ||
+        (loleft_y<1) || (loleft_y>ily) ||
+        (upright_x<1) || (upright_x>ilx) ||
+        (upright_y<1) || (upright_y>ily) ||
+        (loleft_x>upright_x) || (loleft_y>upright_y)) {
+        sinfo_msg_error("extraction zone is [%d %d] [%d %d]\n"
+                        "cannot extract such zone: aborting slit extraction",
+                loleft_x, loleft_y, upright_x, upright_y) ;
+        return NULL ;
+    }
+
+    outlx = upright_x - loleft_x + 1 ;
+    outly = upright_y - loleft_y + 1 ;
+    slit_img = cpl_image_new(outlx, outly,CPL_TYPE_FLOAT) ;
+    podata=cpl_image_get_data_float(slit_img);
+
+    for (j=0 ; j<outly ; j++) {
+        inpt = pidata+loleft_x-1 + (j+loleft_y-1)*ilx ;
+        outpt = podata + j*outlx ;
+        for (i=0 ; i<outlx ; i++) {
+            *outpt++ = *inpt++ ;
+        }
+    }
+    return slit_img ;
+}
+
+/**
+ at brief set world coordinate system for a cube
+ at name sinfo_new_set_wcs_cube
+ at param cub input cube
+ at param name file name
+ at param clambda central wawelength
+ at param dis   dispersion
+ at param cpix central pixel
+ at param cx   center x
+ at param cy   center y
+*/
+int
+sinfo_new_set_wcs_cube(cpl_imagelist* cub, const char* name, double clambda,
+         double dis, double cpix, double cx, double cy)
+{
+  cpl_propertylist* plist=NULL;
+
+  if ((cpl_error_code)((plist = cpl_propertylist_load(name, 0)) == NULL)) {
+    sinfo_msg_error( "getting header from frame %s",name);
+    cpl_propertylist_delete(plist) ;
+    return -1 ;
+  }
+
+  sinfo_new_change_plist_cube(plist, clambda, dis, cpix, cx, cy) ;
+  sinfo_plist_set_extra_keys(plist,"IMAGE","DATA","RMSE",
+			     "DATA","ERRS","QUAL",0);
+  if (cpl_imagelist_save(cub, name, CPL_BPP_IEEE_FLOAT,
+                         plist,CPL_IO_DEFAULT)!=CPL_ERROR_NONE) {
+    sinfo_msg_error( "Cannot save the product %s",name);
+    cpl_propertylist_delete(plist) ;
+    return -1 ;
+  }
+  cpl_propertylist_delete(plist) ;
+  return 0;
+
+}
+/**
+ at brief set world coordinate system for an image
+ at name sinfo_new_set_wcs_image
+ at param img input image
+ at param name file name
+ at param cx   center x
+ at param cy   center y
+*/
+int
+sinfo_new_set_wcs_image(cpl_image* img,
+                        const char* name,
+                        double cx,
+                        double cy)
+{
+  cpl_propertylist* plist=NULL;
+
+  if ((cpl_error_code)((plist = cpl_propertylist_load(name, 0)) == NULL)) {
+    sinfo_msg_error( "getting header from frame %s",name);
+    cpl_propertylist_delete(plist) ;
+    return -1 ;
+  }
+  sinfo_new_change_plist_image(plist, cx, cy) ;
+
+  if (cpl_image_save(img, name, CPL_BPP_IEEE_FLOAT,
+                     plist,CPL_IO_DEFAULT)!=CPL_ERROR_NONE) {
+    sinfo_msg_error( "Cannot save the product %s",name);
+    cpl_propertylist_delete(plist) ;
+    return -1 ;
+  }
+  cpl_propertylist_delete(plist) ;
+  return 0;
+
+}
+
+
+/**
+ at brief set world coordinate system for a spectrum image
+ at name sinfo_new_set_wcs_spectrum
+ at param cub input image spectrum
+ at param name file name
+ at param clambda central wawelength
+ at param dis   dispersion
+ at param cpix central pixel
+*/
+int
+sinfo_new_set_wcs_spectrum(cpl_image* img, const char* name, double clambda,
+             double dis, double cpix)
+{
+  cpl_propertylist* plist=NULL;
+
+  if ((cpl_error_code)((plist = cpl_propertylist_load(name, 0)) == NULL)) {
+    sinfo_msg_error( "getting header from frame %s",name);
+    cpl_propertylist_delete(plist) ;
+    return -1 ;
+  }
+  sinfo_new_change_plist_spectrum(plist, clambda, dis,cpix) ;
+
+  if (cpl_image_save(img, name, CPL_BPP_IEEE_FLOAT,
+                     plist,CPL_IO_DEFAULT)!=CPL_ERROR_NONE) {
+    sinfo_msg_error( "Cannot save the product %s",name);
+    cpl_propertylist_delete(plist) ;
+    return -1 ;
+  }
+  cpl_propertylist_delete(plist) ;
+  return 0;
+
+}
+/**
+ at brief set world coordinate system for a cube
+ at name sinfo_new_change_plist_cube
+ at param plist input propertylist
+ at param name file name
+ at param cenLambda central wawelength
+ at param dispersion   dispersion
+ at param cenpix central pixel
+ at param center_x   center x
+ at param center_y   center y
+*/
+static void
+sinfo_new_change_plist_cube (cpl_propertylist * plist,
+            float cenLambda,
+            float dispersion,
+            int   center_z,
+            float center_x,
+            float center_y )
+{
+
+    float pixelscale ;
+    double ra ;
+    double dec ;
+    double angle ;
+    float radangle ;
+    double cd1_1, cd1_2, cd2_1, cd2_2 ;
+    int sign_swap = -1;
+    char firsttext[2*FILE_NAME_SZ] ;
+
+    double cdelt1=0;
+    double cdelt2=0;
+    double cdelt3=dispersion;
+
+    double crpix1=center_x;
+    double crpix2=center_y;
+    int crpix3=center_z;
+
+    double crval1=0;
+    double crval2=0;
+    double crval3=cenLambda;
+
+
+    strcpy(firsttext, "sinfo_rec_objnod -f \0") ;
+
+    pixelscale = sinfo_pfits_get_pixscale(plist)/2. ;
+    ra = sinfo_pfits_get_ra(plist) ;
+    dec = sinfo_pfits_get_DEC(plist) ;
+
+    //get better coordinate values
+    ra=sinfo_pfits_get_targ_alpha(plist);
+    dec=sinfo_pfits_get_targ_delta(plist);
+    //sinfo_msg("ra=%f",ra);
+    //sinfo_msg("dec=%f",dec);
+    ra=sinfo_hms2deg(ra);
+    dec=sinfo_sess2deg(dec);
+    //sinfo_msg("ra=%f",ra);
+    //sinfo_msg("dec=%f",dec);
+
+    crval1=ra;
+    crval2=dec;
+
+    angle = sinfo_pfits_get_posangle(plist) ;
+    /* in PUPIL data there is not posangle info: we reset the error */
+    if(cpl_error_get_code() != CPL_ERROR_NONE) {
+       cpl_error_reset();
+    }
+    cdelt1=sign_swap*pixelscale / 3600.;
+    cdelt2=         +pixelscale / 3600.;
+
+
+    radangle = angle * PI_NUMB / 180. ;
+    cd1_1 = +cdelt1*cos(radangle);
+    cd1_2 = -cdelt2*sin(radangle);
+    cd2_1 = +cdelt1*sin(radangle);
+    cd2_2 = +cdelt2*cos(radangle);
+
+
+    sinfo_set_coord1(&plist,crpix1,crval1,cdelt1);
+    sinfo_set_coord2(&plist,crpix2,crval2,cdelt2);
+    sinfo_set_coord3(&plist,crpix3,crval3,cdelt3);
+    sinfo_set_cd_matrix2(&plist,cd1_1,cd1_2,cd2_1,cd2_2);
+    sinfo_set_cd_matrix3(&plist,0,0,0,0,dispersion);
+
+
+    }
+
+
+
+
+/**
+ at brief set world coordinate system
+ at param plist input propertylist
+ at param crpix1 value of CRPIX1 (ref pixel axis 1 coord in pix coordinates)
+ at param crval1 value of CRVAL1 (ref pixel axis 1 coord in sky coordinates)
+ at param cdelt1 value of CDELT1 (ref pixel axis 1 size )
+ at return updated propertylist
+*/
+static void
+sinfo_set_coord1(cpl_propertylist** plist,
+                 const double crpix1,
+                 const double crval1,
+                 const double cdelt1)
+{
+   cpl_propertylist_erase_regexp(*plist, "^CTYPE1",0);
+    cpl_propertylist_insert_after_string(*plist,"EXPTIME","CTYPE1","RA---TAN");
+    cpl_propertylist_set_comment(*plist, "CTYPE1", "Projected Rectascension");
+    cpl_propertylist_erase_regexp(*plist, "^CRPIX1",0);
+    cpl_propertylist_insert_after_double(*plist,"CTYPE1","CRPIX1", crpix1) ;
+    cpl_propertylist_set_comment(*plist, "CRPIX1","Reference pixel in RA" ) ;
+
+    cpl_propertylist_erase_regexp(*plist, "^CRVAL1",0);
+    cpl_propertylist_insert_after_double(*plist, "CRPIX1", "CRVAL1", crval1 ) ;
+    cpl_propertylist_set_comment(*plist, "CRVAL1","Reference RA" ) ;
+
+    cpl_propertylist_erase_regexp(*plist, "^CDELT1",0);
+    cpl_propertylist_insert_after_double(*plist,"CRVAL1","CDELT1",cdelt1 ) ;
+    cpl_propertylist_set_comment(*plist, "CDELT1","pixel scale" ) ;
+
+    cpl_propertylist_erase_regexp(*plist, "^CUNIT1",0);
+    cpl_propertylist_insert_after_string(*plist, "CDELT1",  "CUNIT1", "deg" ) ;
+    cpl_propertylist_set_comment(*plist, "CUNIT1","RA-UNIT" ) ;
+
+    return;
+}
+
+
+/**
+ at brief set world coordinate system
+ at param plist input propertylist
+ at param crpix2 value of CRPIX2 (ref pixel axis 2 coord in pix coordinates)
+ at param crval2 value of CRVAL2 (ref pixel axis 2 coord in sky coordinates)
+ at param cdelt2 value of CDELT2 (ref pixel axis 2 size )
+ at return updated propertylist
+*/
+static void
+sinfo_set_coord2(cpl_propertylist** plist,
+                 const double crpix2,
+                 const double crval2,
+                 const double cdelt2)
+{
+    cpl_propertylist_erase_regexp(*plist, "^CTYPE2",0);
+    cpl_propertylist_insert_after_string(*plist,"CUNIT1","CTYPE2","DEC--TAN");
+    cpl_propertylist_set_comment(*plist, "CTYPE2", "Projected Declination") ;
+
+    cpl_propertylist_erase_regexp(*plist, "^CRPIX2",0);
+    cpl_propertylist_insert_after_double(*plist,"CTYPE2","CRPIX2",crpix2 ) ;
+    cpl_propertylist_set_comment(*plist, "CRPIX2", "Reference pixel in DEC") ;
+
+    cpl_propertylist_erase_regexp(*plist,"^CRVAL2",0);
+    cpl_propertylist_insert_after_double(*plist,"CRPIX2","CRVAL2",crval2) ;
+    cpl_propertylist_set_comment(*plist,"CRVAL2","Reference DEC") ;
+
+    cpl_propertylist_erase_regexp(*plist,"^CDELT2",0);
+    cpl_propertylist_insert_after_double(*plist,"CRVAL2","CDELT2",cdelt2 ) ;
+    cpl_propertylist_set_comment(*plist,"CDELT2","pixel scale") ;
+
+    cpl_propertylist_erase_regexp(*plist,"^CUNIT2",0);
+    cpl_propertylist_insert_after_string(*plist,"CDELT2","CUNIT2", "deg" ) ;
+    cpl_propertylist_set_comment(*plist,"CUNIT2","DEC-UNIT") ;
+
+
+}
+
+
+
+/**
+ at brief set world coordinate system
+ at param plist input propertylist
+ at param crpix3 value of CRPIX3 (ref pixel axis 3 coord in pix coordinates)
+ at param crval3 value of CRVAL3 (ref pixel axis 3 coord in sky coordinates)
+ at param cdelt3 value of CDELT3 (ref pixel axis 3 size )
+ at return updated propertylist
+*/
+static void
+sinfo_set_coord3(cpl_propertylist** plist,
+                 const int crpix3,
+                 const double crval3,
+                 const double cdelt3)
+{
+    cpl_propertylist_erase_regexp(*plist, "^CTYPE3",0);
+    cpl_propertylist_insert_after_string(*plist,"EXPTIME", "CTYPE3", "WAVE" ) ;
+    cpl_propertylist_set_comment(*plist,"CTYPE3","wavelength axis in microns") ;
+
+    cpl_propertylist_erase_regexp(*plist, "^CRPIX3",0);
+    cpl_propertylist_insert_after_double(*plist,"CTYPE3","CRPIX3", (double)crpix3 ) ;
+    cpl_propertylist_set_comment(*plist, "CRPIX3", "Reference pixel in z") ;
+
+    cpl_propertylist_erase_regexp(*plist, "^CRVAL3",0);
+    cpl_propertylist_insert_after_double(*plist,"CRPIX3", "CRVAL3", crval3) ;
+    cpl_propertylist_set_comment(*plist, "CRVAL3", "central wavelength") ;
+
+    cpl_propertylist_erase_regexp(*plist, "^CDELT3",0);
+
+    cpl_propertylist_insert_after_double(*plist,"CRVAL3","CDELT3",cdelt3) ;
+    cpl_propertylist_set_comment(*plist, "CDELT3", "microns per pixel") ;
+
+    cpl_propertylist_erase_regexp(*plist, "^CUNIT3",0);
+    cpl_propertylist_insert_after_string(*plist,"CDELT3", "CUNIT3", "um" ) ;
+    cpl_propertylist_set_comment(*plist, "CUNIT3",  "spectral unit" ) ;
+
+    cpl_propertylist_erase_regexp(*plist, "^SPECSYS",0);
+    cpl_propertylist_insert_after_string(*plist,"CUNIT3", "SPECSYS", "TOPOCENT" ) ;
+    cpl_propertylist_set_comment(*plist, "SPECSYS",  "Coordinate reference frame" ) ;
+}
+
+
+/**
+ at brief set world coordinate system: CD matrix
+ at param plist input propertylist
+ at param cd1_1 value of CD1_1
+ at param cd1_2 value of CD1_2
+ at param cd2_1 value of CD2_1
+ at param cd2_2 value of CD2_2
+ at return updated propertylist
+*/
+
+static void
+sinfo_set_cd_matrix2(cpl_propertylist** plist,
+            const double cd1_1,
+            const double cd1_2,
+            const double cd2_1,
+            const double cd2_2)
+{
+
+    check_nomsg(cpl_propertylist_erase_regexp(*plist, "^CD1_1",0));
+    check_nomsg(cpl_propertylist_insert_after_double(*plist,"EXPTIME",
+						     "CD1_1", cd1_1 )) ;
+    check_nomsg(cpl_propertylist_set_comment(*plist, "CD1_1",
+					     "CD rotation matrix" )) ;
+
+    check_nomsg(cpl_propertylist_erase_regexp(*plist, "^CD1_2",0));
+    check_nomsg(cpl_propertylist_insert_after_double(*plist, "CD1_1",
+						     "CD1_2", cd1_2 )) ;
+    check_nomsg(cpl_propertylist_set_comment(*plist, "CD1_2",
+					     "CD rotation matrix" )) ;
+
+    check_nomsg(cpl_propertylist_erase_regexp(*plist, "^CD2_1",0));
+    check_nomsg(cpl_propertylist_insert_after_double(*plist, "CD1_2",
+						     "CD2_1", cd2_1 )) ;
+    check_nomsg(cpl_propertylist_set_comment(*plist, "CD2_1",
+					     "CD rotation matrix" )) ;
+
+    check_nomsg(cpl_propertylist_erase_regexp(*plist, "^CD2_2",0));
+    check_nomsg(cpl_propertylist_insert_after_double(*plist, "CD2_1",
+						     "CD2_2", cd2_2 )) ;
+    check_nomsg(cpl_propertylist_set_comment(*plist, "CD2_2",
+					     "CD rotation matrix" )) ;
+
+ cleanup:
+    return;
+
+
+}
+
+
+/**
+ at brief set world coordinate system: CD matrix
+ at param plist input propertylist
+ at param cd1_3 value of CD1_3
+ at param cd2_3 value of CD2_3
+ at param cd3_1 value of CD3_1
+ at param cd3_2 value of CD3_2
+ at param cd3_3 value of CD3_3
+
+ at return updated propertylist
+*/
+
+static void
+sinfo_set_cd_matrix3(cpl_propertylist** plist,
+                     const double cd1_3,
+                     const double cd2_3,
+                     const double cd3_1,
+                     const double cd3_2,
+                     const double cd3_3)
+{
+
+
+    check_nomsg(cpl_propertylist_erase_regexp(*plist, "^CD1_3",0));
+    check_nomsg(cpl_propertylist_insert_after_double(*plist,"EXPTIME",
+						     "CD1_3", cd1_3 )) ;
+    check_nomsg(cpl_propertylist_set_comment(*plist, "CD1_3",
+					     "CD rotation matrix" )) ;
+
+
+    check_nomsg(cpl_propertylist_erase_regexp(*plist, "^CD2_3",0));
+    check_nomsg(cpl_propertylist_insert_after_double(*plist,"CD1_3",
+						     "CD2_3", cd2_3 )) ;
+    check_nomsg(cpl_propertylist_set_comment(*plist, "CD2_3",
+					     "CD rotation matrix" )) ;
+
+
+
+    check_nomsg(cpl_propertylist_erase_regexp(*plist, "^CD3_1",0));
+    check_nomsg(cpl_propertylist_insert_after_double(*plist,"CD2_3",
+						     "CD3_1", cd3_1 )) ;
+    check_nomsg(cpl_propertylist_set_comment(*plist, "CD3_1",
+					     "CD rotation matrix" )) ;
+
+    check_nomsg(cpl_propertylist_erase_regexp(*plist, "^CD3_2",0));
+    check_nomsg(cpl_propertylist_insert_after_double(*plist, "CD3_1",
+						     "CD3_2", cd3_2 )) ;
+    check_nomsg(cpl_propertylist_set_comment(*plist, "CD3_2",
+					     "CD rotation matrix" )) ;
+
+    check_nomsg(cpl_propertylist_erase_regexp(*plist, "^CD3_3",0));
+    check_nomsg(cpl_propertylist_insert_after_double(*plist, "CD3_2",
+						     "CD3_3", cd3_3 )) ;
+    check_nomsg(cpl_propertylist_set_comment(*plist, "CD3_3",
+					     "CD rotation matrix" )) ;
+
+ cleanup:
+    return;
+
+
+}
+
+
+/**
+ at brief set world coordinate system
+ at param plist input propertylist
+ at param crpix1 value of CRPIX1 (ref pixel axis 1 coord in pix coordinates)
+ at param crval1 value of CRVAL1 (ref pixel axis 1 coord in sky coordinates)
+ at param cdelt1 value of CDELT1 (ref pixel axis 1 size )
+ at return updated propertylist
+*/
+static void
+sinfo_set_spect_coord1(cpl_propertylist** plist,
+                 const int crpix1,
+                 const double crval1,
+                 const double cdelt1)
+{
+
+    cpl_propertylist_erase_regexp(*plist, "^CTYPE1",0);
+    cpl_propertylist_insert_after_string(*plist,"EXPTIME",  "CTYPE1", "PIXEL");
+    cpl_propertylist_set_comment(*plist, "CTYPE1", "Pixel coordinate system.");
+
+    cpl_propertylist_erase_regexp(*plist, "^CRPIX1",0);
+    cpl_propertylist_insert_after_double(*plist, "CTYPE1",  "CRPIX1", (double)crpix1 ) ;
+    cpl_propertylist_set_comment(*plist, "CRPIX1", "Reference pixel in x") ;
+
+    cpl_propertylist_erase_regexp(*plist, "^CRVAL1",0);
+    cpl_propertylist_insert_after_double(*plist,"CRPIX1",  "CRVAL1", crval1 ) ;
+    cpl_propertylist_set_comment(*plist, "CRVAL1", "value of ref pixel.") ;
+
+    cpl_propertylist_erase_regexp(*plist, "^CDELT1",0);
+    cpl_propertylist_insert_after_double(*plist,"CRVAL1",  "CDELT1", cdelt1 ) ;
+    cpl_propertylist_set_comment(*plist,"CDELT1", "pixel scale") ;
+
+
+    cpl_propertylist_erase_regexp(*plist, "^CUNIT1",0);
+    cpl_propertylist_insert_after_string(*plist,"CDELT1",  "CUNIT1", "Pixel" );
+    cpl_propertylist_set_comment(*plist, "CUNIT1",  "spectral unit" );
+
+}
+
+
+
+
+
+/**
+ at brief set world coordinate system
+ at param plist input propertylist
+ at param crpix2 value of CRPIX2 (ref pixel axis 2 coord in pix coordinates)
+ at param crval2 value of CRVAL2 (ref pixel axis 2 coord in sky coordinates)
+ at param cdelt2 value of CDELT2 (ref pixel axis 2 size )
+ at return updated propertylist
+*/
+static void
+sinfo_set_spect_coord2(cpl_propertylist** plist,
+                 const int crpix2,
+                 const double crval2,
+                 const double cdelt2)
+{
+
+    cpl_propertylist_erase_regexp(*plist, "^CTYPE2",0);
+    cpl_propertylist_insert_after_string(*plist, "EXPTIME","CTYPE2","WAVE" );
+    cpl_propertylist_set_comment(*plist,"CTYPE2","wavelength axis in microns");
+
+    cpl_propertylist_erase_regexp(*plist, "^CRPIX2",0);
+    cpl_propertylist_insert_after_double(*plist, "CTYPE2",  "CRPIX2",(double)crpix2 ) ;
+    cpl_propertylist_set_comment(*plist, "CRPIX2", "Reference pixel in x") ;
+
+    cpl_propertylist_erase_regexp(*plist, "^CRVAL2",0);
+    cpl_propertylist_insert_after_double(*plist, "CRPIX2","CRVAL2",crval2 ) ;
+    cpl_propertylist_set_comment(*plist,"CRVAL2", "central wavelength") ;
+
+    cpl_propertylist_erase_regexp(*plist, "^CDELT2",0);
+    cpl_propertylist_insert_after_double(*plist, "CRVAL2", "CDELT2",cdelt2);
+    cpl_propertylist_set_comment(*plist,"CDELT2", "microns per pixel");
+
+    cpl_propertylist_erase_regexp(*plist, "^CUNIT2",0);
+    cpl_propertylist_insert_after_string(*plist,"CDELT2",  "CUNIT2", "um");
+    cpl_propertylist_set_comment(*plist, "CUNIT2",  "spectral unit" );
+
+
+}
+/**
+ at brief set world coordinate system for a spectrum
+ at name sinfo_new_change_plist_spectrum
+ at param plist input propertylist
+ at param cenLambda central wawelength
+ at param dispersion   dispersion
+ at param cenpix central pixel
+ at return updated propertylist
+*/
+static void
+sinfo_new_change_plist_spectrum (cpl_propertylist * plist,
+                double cenLambda,
+                double dispersion,
+                int   cenpix)
+{
+
+  int crpix1=1;
+  double crval1=1;
+  double cdelt1=1;
+
+  int crpix2=cenpix;
+  double crval2=cenLambda;
+  double cdelt2=dispersion;
+
+
+
+  cpl_propertylist_erase_regexp(plist, "^CTYPE3",0);
+  cpl_propertylist_erase_regexp(plist, "^CRPIX3",0);
+  cpl_propertylist_erase_regexp(plist, "^CRVAL3",0);
+  cpl_propertylist_erase_regexp(plist, "^CDELT3",0);
+  cpl_propertylist_erase_regexp(plist, "^CUNIT3",0);
+
+  cpl_propertylist_erase_regexp(plist, "^CTYPE2",0);
+  cpl_propertylist_erase_regexp(plist, "^CRPIX2",0);
+  cpl_propertylist_erase_regexp(plist, "^CRVAL2",0);
+  cpl_propertylist_erase_regexp(plist, "^CDELT2",0);
+  cpl_propertylist_erase_regexp(plist, "^CUNIT2",0);
+
+
+  cpl_propertylist_erase_regexp(plist, "^CD1_1",0);
+  cpl_propertylist_erase_regexp(plist, "^CD1_2",0);
+  cpl_propertylist_erase_regexp(plist, "^CD2_1",0);
+  cpl_propertylist_erase_regexp(plist, "^CD2_2",0);
+
+
+
+
+  sinfo_set_spect_coord1(&plist,crpix1,crval1,cdelt1);
+  sinfo_set_spect_coord2(&plist,crpix2,crval2,cdelt2);
+
+
+
+}
+/**
+ at brief set world coordinate system for an image
+ at name sinfo_new_change_plist_image
+ at param plist input propertylist
+ at param name file name
+ at param center_x center x
+ at param center_y center y
+*/
+
+static void
+sinfo_new_change_plist_image (cpl_propertylist * plist,
+            float center_x,
+            float center_y )
+{
+
+    float pixelscale ;
+    double ra ;
+    double dec ;
+    double angle ;
+    float radangle ;
+    float cd1_1, cd1_2, cd2_1, cd2_2 ;
+    char firsttext[2*FILE_NAME_SZ] ;
+    int sign_swap = -1;
+
+
+    double cdelt1=0;
+    double cdelt2=0;
+
+    double crpix1=center_x;
+    double crpix2=center_y;
+
+    double crval1=0;
+    double crval2=0;
+
+
+
+
+    strcpy(firsttext, "sinfo_rec_objnod -f \0") ;
+
+    pixelscale = sinfo_pfits_get_pixscale(plist)/2. ;
+    ra = sinfo_pfits_get_ra(plist) ;
+    dec = sinfo_pfits_get_DEC(plist) ;
+
+
+
+    //get better coordinate values
+    ra=sinfo_pfits_get_targ_alpha(plist);
+    dec=sinfo_pfits_get_targ_delta(plist);
+    ra=sinfo_hms2deg(ra);
+    dec=sinfo_sess2deg(dec);
+
+
+
+    crval1=ra;
+    crval2=dec;
+
+    angle = sinfo_pfits_get_posangle(plist) ;
+    /* in PUPIL data there is not posangle info: we reset the error */
+    if(cpl_error_get_code() != CPL_ERROR_NONE) {
+       cpl_error_reset();
+    }
+
+    radangle = angle * PI_NUMB / 180. ;
+
+    cdelt1=sign_swap * pixelscale / 3600. ;
+    cdelt2=            pixelscale / 3600. ;
+
+
+    cd1_1 = +cdelt1*cos(radangle) ;
+    cd1_2 = -cdelt2*sin(radangle) ;
+    cd2_1 = +cdelt1*sin(radangle) ;
+    cd2_2 = +cdelt2*cos(radangle) ;
+
+
+
+
+
+    check_nomsg(sinfo_set_coord1(&plist,crpix1,crval1,cdelt1));
+    check_nomsg(sinfo_set_coord2(&plist,crpix2,crval2,cdelt2));
+    check_nomsg(sinfo_set_cd_matrix2(&plist,cd1_1,cd1_2,cd2_1,cd2_2));
+
+
+ cleanup:
+    return;
+}
+
+/**
+ at brief subtract from each cube's plane its median
+ at name sinfo_new_sinfoni_correct_median
+ at param cubes input imagelist
+ at param n_cubes number of cubes
+*/
+
+cpl_imagelist**
+sinfo_new_sinfoni_correct_median(cpl_imagelist** cubes, const int n_cubes)
+{
+  int i=0;
+  cpl_imagelist** cubes_cor=NULL;
+  double local_median=0;
+  int z=0;
+  cpl_image* i_img=NULL;
+  cpl_image* o_img=NULL;
+
+
+  if ( cubes == NULL ) {
+    sinfo_msg_error ("no cube list given!") ;
+    return NULL ;
+  }
+  if ( n_cubes <= 0 ) {
+    sinfo_msg_error ("wrong number of data cubes in list!") ;
+    return NULL ;
+  }
+
+  cubes_cor = (cpl_imagelist**) cpl_calloc (n_cubes, sizeof (cpl_imagelist*)) ;
+
+  for ( i = 0 ; i < n_cubes ; i++ ) {
+    cubes_cor[i] = cpl_imagelist_new();
+    for(z=0;z< cpl_imagelist_get_size(cubes[i]); z++) {
+      i_img=cpl_imagelist_get(cubes[i],z);
+      local_median=cpl_image_get_median(i_img);;
+      o_img=cpl_image_duplicate(i_img);
+      if(!isnan(local_median)) {
+        cpl_image_subtract_scalar(o_img,local_median);
+       }
+      cpl_imagelist_set(cubes_cor[i],o_img,z);
+    }
+  }
+
+  return cubes_cor;
+}
+
+/**
+ at brief subtract from each cube's plane its median
+ at name sinfo_new_sinfoni_correct_median_it
+ at param inp input imagelist
+*/
+
+int sinfo_new_sinfoni_correct_median_it(cpl_imagelist** inp)
+{
+
+  double local_median=0;
+  int z=0;
+  cpl_image* img=NULL;
+
+  for(z=0;z< cpl_imagelist_get_size((*inp)); z++) {
+    img=cpl_imagelist_get((*inp),z);
+    local_median=sinfo_new_my_median_image(img);
+    if(!isnan(local_median)) {
+      cpl_image_subtract_scalar(img,local_median);
+    }  else {
+      sinfo_msg_error("local_median is NAN");
+    }
+    cpl_imagelist_set((*inp),img,z);
+  }
+
+  return 0;
+}
+
+/**
+ at brief subtract from each object cube's plane each sky cube's
+       plane and return the sky cube
+ at name sinfo_new_sinfoni_correct_sky
+ at param inp input imagelist
+ at param nc  size of cube
+ at param sky_cube output sky cube
+*/
+
+cpl_imagelist** sinfo_new_sinfoni_correct_sky(cpl_imagelist** cubes,
+                  const int nc,
+                  cpl_imagelist* sky_cube)
+
+{
+  cpl_imagelist** cubes_sky=NULL;
+  int x=0;
+  int y=0;
+  int z=0;
+  int i=0;
+  float k=0.5;
+  int ovr=0;
+  int ks=0;
+  int nclip=0;
+  double med=0;
+  double avg=0;
+  double sig=0;
+  int msk_sum=0;
+  double val_msk_sum=0;
+  cpl_vector* val=NULL;
+  cpl_vector* msk=NULL;
+  int ilx=0;
+  int ily=0;
+  int inp=0;
+
+
+  int sky_lx=0;
+  int sky_ly=0;
+
+  float* pidata=NULL;
+  float* p_sky_data=NULL;
+  cpl_image* i_img=NULL;
+  cpl_image* sky_img=NULL;
+
+
+  if ( cubes == NULL ) {
+    sinfo_msg_error ("no cube list given!") ;
+    return NULL ;
+  }
+  ilx=cpl_image_get_size_x(cpl_imagelist_get(cubes[0],0));
+  ily=cpl_image_get_size_y(cpl_imagelist_get(cubes[0],0));
+  inp=cpl_imagelist_get_size(cubes[0]);
+
+
+  sky_lx=cpl_image_get_size_x(cpl_imagelist_get(sky_cube,0));
+  sky_ly=cpl_image_get_size_y(cpl_imagelist_get(sky_cube,0));
+  if ( nc <= 0 ) {
+    sinfo_msg_error ("wrong number of data cubes in list!") ;
+    return NULL ;
+  }
+
+  cubes_sky = (cpl_imagelist**) cpl_calloc (nc, sizeof (cpl_imagelist*)) ;
+  for(z=0;z< inp; z++) {
+    sky_img=cpl_imagelist_get(sky_cube,z);
+    p_sky_data=cpl_image_get_data_float(sky_img);
+    for(y=0;y< ily; y++) {
+      for(x=0;x< ilx; x++) {
+        /* here we start to do a k-s clipping */
+    msk=cpl_vector_new(nc);
+    for (i=0;i<nc;i++) {
+      cpl_vector_set(msk,i,1);
+    }
+        nclip=0;
+        for (ks=0;ks<nc;ks++) {
+      sig=0;
+      med=0;
+      ovr=0;
+      val=cpl_vector_new(nc-nclip);
+
+      for ( i = 0 ; i < nc ; i++ ) {
+            i_img=cpl_imagelist_get(cubes[i],z);
+            pidata=cpl_image_get_data_float(i_img);
+        if ((!isnan(pidata[x+y*ilx])) &&
+                 (cpl_vector_get(msk,i) != 0) ) {
+          cpl_vector_set(val,ovr,(double)pidata[x+y*ilx]);
+          ovr++;
+        }
+      }
+
+      if(ovr>0) {
+        avg=cpl_vector_get_mean(val);
+        med=cpl_vector_get_median_const(val);
+        if(ovr>1) {
+          sig=cpl_vector_get_stdev(val);
+        } else {
+              sig=0;
+        }
+      } else {
+        avg=cpl_vector_get(val,0);
+        med=avg;
+        sig=0;
+      }
+
+      cpl_vector_delete(val);
+      for ( i = 0 ; i < nc ; i++ ) {
+            i_img=cpl_imagelist_get(cubes[i],z);
+            pidata=cpl_image_get_data_float(i_img);
+      /* Do k-s clipping at each pixel */
+        if ((!isnan(pidata[x+y*ilx])) &&
+                (cpl_vector_get(msk,i) != 0)) {
+          if(abs((pidata[x+y*ilx]-med))> k*sig) {
+        cpl_vector_set(msk,i,0);
+                nclip++;
+          }
+        }
+      }
+    }/* end of k-s clipping */
+    msk_sum=0;
+    val_msk_sum=0;
+    for ( i = 0 ; i < nc ; i++ ) {
+      /* computes sky at each point */
+      if (!isnan(pidata[x+y*ilx])) {
+        msk_sum+=cpl_vector_get(msk,i);
+                val_msk_sum+=pidata[x+y*ilx]*
+          cpl_vector_get(msk,i);
+      }
+    }
+    p_sky_data[x+y*sky_lx]=val_msk_sum/msk_sum;
+    cpl_vector_delete(msk);
+      } /* end loop over x */
+    } /* end loop over y */
+  } /* end loop over z */
+  for ( i = 0 ; i < nc ; i++ ) {
+    cubes_sky[i]=cpl_imagelist_duplicate(cubes[i]);
+    /* subtract the variable clean sky */
+    cpl_imagelist_subtract(cubes_sky[i],sky_cube);
+
+  }
+
+
+  return cubes_sky;
+}
+
+/**
+ at brief subtract from each object cube's plane each sky cube's plane and
+       output a sky, a median, a mask, an average, a sigma and and
+       overlapping imagelist
+ at name sinfo_new_sinfoni_correct_sky2
+ at param inp input imagelist
+ at param nc  size of imagelist
+ at param sky_cube sky
+ at param med_cube median
+ at param msk_cube mask
+ at param avg_cube average
+ at param sig_cube sigma
+ at param ovr_cube overlapping points
+*/
+cpl_imagelist** sinfo_new_sinfoni_correct_sky2(cpl_imagelist** cubes,
+                  const int nc,
+                  cpl_imagelist* sky_cube,
+                              cpl_imagelist* med_cube,
+                              cpl_imagelist* msk_cube,
+                              cpl_imagelist* avg_cube,
+                              cpl_imagelist* sig_cube,
+                              cpl_imagelist* ovr_cube)
+{
+  cpl_imagelist** cubes_sky=NULL;
+  int x=0;
+  int y=0;
+  int z=0;
+  int i=0;
+  float k=0.5;
+  int ovr=0;
+  int ks=0;
+  int nclip=0;
+  double med=0;
+  double avg=0;
+  double sig=0;
+  int msk_sum=0;
+  double val_msk_sum=0;
+  cpl_vector* val=NULL;
+  cpl_vector* msk=NULL;
+
+  int ilx=0;
+  int ily=0;
+  int inp=0;
+
+  int ovr_lx=0;
+  int msk_lx=0;
+  int avg_lx=0;
+  int sig_lx=0;
+  int sky_lx=0;
+  int med_lx=0;
+
+
+  float* p_ovr_data=NULL;
+  float* p_msk_data=NULL;
+  float* p_avg_data=NULL;
+  float* p_sig_data=NULL;
+  float* p_sky_data=NULL;
+  float* p_med_data=NULL;
+
+  float* pidata=NULL;
+
+  if ( cubes == NULL ) {
+    sinfo_msg_error ("no cube list given!") ;
+    return NULL ;
+  }
+
+  ilx=cpl_image_get_size_x(cpl_imagelist_get(cubes[0],0));
+  ily=cpl_image_get_size_y(cpl_imagelist_get(cubes[0],0));
+  inp=cpl_imagelist_get_size(cubes[0]);
+
+  if ( nc <= 0 ) {
+    sinfo_msg_error ("wrong number of data cubes in list!") ;
+    return NULL ;
+  }
+
+  cubes_sky = (cpl_imagelist**) cpl_calloc (nc, sizeof (cpl_imagelist*)) ;
+
+  ovr_lx=ilx;
+  msk_lx=ilx;
+  avg_lx=ilx;
+  sig_lx=ilx;
+  sky_lx=ilx;
+  med_lx=ilx;
+
+  for(z=0;z< inp; z++) {
+    p_ovr_data=cpl_image_get_data_float(cpl_imagelist_get(ovr_cube,z));
+    p_msk_data=cpl_image_get_data_float(cpl_imagelist_get(msk_cube,z));
+    p_avg_data=cpl_image_get_data_float(cpl_imagelist_get(avg_cube,z));
+    p_sig_data=cpl_image_get_data_float(cpl_imagelist_get(sig_cube,z));
+    p_sky_data=cpl_image_get_data_float(cpl_imagelist_get(sky_cube,z));
+    p_med_data=cpl_image_get_data_float(cpl_imagelist_get(med_cube,z));
+
+
+    for(y=0;y< ily; y++) {
+      for(x=0;x< ilx; x++) {
+        /* here we start to do a k-s clipping */
+    msk=cpl_vector_new(nc);
+    for (i=0;i<nc;i++) {
+      cpl_vector_set(msk,i,1);
+    }
+    p_ovr_data[x+y*ovr_lx]=nc;
+    p_msk_data[x+y*msk_lx]=nc;
+        nclip=0;
+        for (ks=0;ks<nc;ks++) {
+      sig=0;
+      med=0;
+      ovr=0;
+      val=cpl_vector_new(nc-nclip);
+
+      for ( i = 0 ; i < nc ; i++ ) {
+            pidata=cpl_image_get_data_float(cpl_imagelist_get(cubes[i],z));
+        if ((!isnan(pidata[x+y*ilx])) &&
+                 (cpl_vector_get(msk,i) != 0) ) {
+          cpl_vector_set(val,ovr,(double)pidata[x+y*ilx]);
+          ovr++;
+        }
+      }
+
+      if(ovr>1) {
+        avg=cpl_vector_get_mean(val);
+        med=cpl_vector_get_median_const(val);
+        sig=cpl_vector_get_stdev(val);
+      } else {
+        avg=cpl_vector_get(val,0);
+        med=avg;
+        sig=0;
+      }
+
+      p_med_data[x+y*med_lx]=med;
+      p_avg_data[x+y*avg_lx]=avg;
+      p_sig_data[x+y*sig_lx]=sig;
+      cpl_vector_delete(val);
+      for ( i = 0 ; i < nc ; i++ ) {
+           pidata=cpl_image_get_data_float(cpl_imagelist_get(cubes[i],z));
+      /* Do k-s clipping at each pixel */
+        if ((!isnan(pidata[x+y*ilx])) &&
+                (cpl_vector_get(msk,i) != 0)) {
+          if(abs((pidata[x+y*ilx]-med))> k*sig) {
+        /* pidata[x+y*ilx]=0; */
+        p_msk_data[x+y*msk_lx]-=1;
+        cpl_vector_set(msk,i,0);
+                nclip++;
+          }
+        }
+      }
+    }/* end of k-s clipping */
+    msk_sum=0;
+    val_msk_sum=0;
+    for ( i = 0 ; i < nc ; i++ ) {
+           pidata=cpl_image_get_data_float(cpl_imagelist_get(cubes[i],z));
+      /* computes sky at each point */
+      if (!isnan(pidata[x+y*ilx])) {
+        /*
+        msk_sum+=p_msk_data[x+y*msk_lx];
+                val_msk_sum+=pidata[x+y*cubes[i]->lx]*
+          p_msk_data[x+y*msk_lx];
+        */
+        msk_sum+=cpl_vector_get(msk,i);
+                val_msk_sum+=pidata[x+y*ilx]*
+          cpl_vector_get(msk,i);
+      }
+    }
+    p_sky_data[x+y*sky_lx]=val_msk_sum/msk_sum;
+    cpl_vector_delete(msk);
+      } /* end loop over x */
+    } /* end loop over y */
+  } /* end loop over z */
+  for ( i = 0 ; i < nc ; i++ ) {
+    cubes_sky[i]=cpl_imagelist_duplicate(cubes[i]);
+    /* subtract the variable clean sky */
+    cpl_imagelist_subtract(cubes_sky[i],sky_cube);
+  }
+
+
+  return cubes_sky;
+}
+
+
+/**
+ at brief extracts from each object frame set information
+       relative to the ao setting
+ at name sinfo_new_assign_offset
+ at param n      frame index in list
+ at param name   file name
+ at param offsetx  reference frame X offset
+ at param offsety  reference frame Y offset
+ at param offsetx frames X offset array
+ at param offsety frames Y offset array
+*/
+
+int
+sinfo_new_assign_offset(const int n,
+                        const char* name,
+                        float* offsetx,
+                        float* offsety,
+                        const float ref_offx,
+                        const float ref_offy)
+{
+
+  float offx=0;
+  float offy=0;
+  double mjd_obs=0;
+  /*
+  double pixelscale=0;
+  double angle=0;
+  double radangle=0;
+  double cd1_1=0;
+  double cd1_2=0;
+  double cd2_1=0;
+  double cd2_2=0;
+  double ra=0;
+  double dec=0;
+  */
+
+  cpl_propertylist * plist=NULL;
+  sinfo_msg_debug("Assign offsets");
+
+  if ((cpl_error_code)((plist = cpl_propertylist_load(name, 0)) == NULL)) {
+    sinfo_msg_error( "getting header from reference frame %s",name);
+    cpl_propertylist_delete(plist) ;
+    return -1 ;
+  }
+
+  offx = sinfo_pfits_get_cumoffsetx(plist) - ref_offx ;  /* was - */
+  if(cpl_error_get_code() != CPL_ERROR_NONE) {
+    sinfo_msg_warning(" could not read fits header keyword cummoffsetx!") ;
+    sinfo_msg_warning(" Set relative offset to 0 - %f!",ref_offx) ;
+    offx =  - ref_offx;
+    cpl_error_reset();
+    /* return -1 ; */
+  }
+
+  offy = sinfo_pfits_get_cumoffsety(plist) - ref_offy ; /* was - */
+  if(cpl_error_get_code() != CPL_ERROR_NONE) {
+    sinfo_msg_warning(" could not read fits header keyword! cumoffsety") ;
+    sinfo_msg_warning(" Set relative offset to 0 - %f!",ref_offx) ;
+    offy =  - ref_offy;
+    cpl_error_reset();
+    /* return -1 ; */
+  }
+  sinfo_msg_debug("offx=%f offy=%f",offx,offy);
+
+  if (sinfo_propertylist_has(plist, KEY_NAME_MJD_OBS)) {
+    mjd_obs=cpl_propertylist_get_double(plist, KEY_NAME_MJD_OBS);
+  } else {
+    sinfo_msg_error("keyword %s does not exist",KEY_NAME_MJD_OBS);
+    cpl_propertylist_delete(plist) ;
+    return -1;
+  }
+
+  cpl_propertylist_delete(plist) ;
+
+  if (mjd_obs > 53825. ) {
+    /* April 1st 2006 */
+    //sinfo_msg("New cumoffset setting convention");
+    sinfo_new_array_set_value(offsetx,2*offx,n);
+    sinfo_new_array_set_value(offsety,2*offy,n);
+  } else if ((mjd_obs > 53421.58210082 ) && (mjd_obs <= 53825.)){
+    /* after detector's upgrade */
+    /*
+    sinfo_new_array_set_value(offsetx,-offx*2,n);
+    sinfo_new_array_set_value(offsety,+offy*2,n);
+    */
+    sinfo_new_array_set_value(offsetx,-2*offx,n);
+    sinfo_new_array_set_value(offsety,2*offy,n);
+  } else {
+    /* before detector's upgrade */
+    /*
+    sinfo_new_array_set_value(offsetx,+offx*2,n);
+    sinfo_new_array_set_value(offsety,-offy*2,n);
+    */
+    sinfo_new_array_set_value(offsetx,2*offx,n);
+    sinfo_new_array_set_value(offsety,-2*offy,n);
+  }
+
+  return 0;
+
+
+}
+
+
+
+
+
+/**
+ at brief extracts from each object frame set information
+       relative to the ao setting
+ at name sinfo_new_assign_offset
+ at param n      frame index in list
+ at param name   file name
+ at param offsetx  reference frame X offset
+ at param offsety  reference frame Y offset
+ at param offsetx frames X offset array
+ at param offsety frames Y offset array
+*/
+
+int
+sinfo_new_assign_offset2(const int n,
+                        const char* name,
+                        float* offsetx,
+                        float* offsety,
+                        const float ref_offx,
+                        const float ref_offy)
+{
+
+  float offx=0;
+  float offy=0;
+  double mjd_obs=0;
+
+  cpl_propertylist * plist=NULL;
+  sinfo_msg_debug("Assign offsets as set by user");
+  offx = offsetx[n] - ref_offx ;  /* was - */
+  offy = offsety[n] - ref_offy ;  /* was - */
+  sinfo_msg_debug("offx=%f offy=%f",offx,offy);
+
+  sinfo_msg_debug("Assign offsets");
+
+  if ((cpl_error_code)((plist = cpl_propertylist_load(name, 0)) == NULL)) {
+    sinfo_msg_error( "getting header from reference frame %s",name);
+    cpl_propertylist_delete(plist) ;
+    return -1 ;
+  }
+
+  if (sinfo_propertylist_has(plist, KEY_NAME_MJD_OBS)) {
+    mjd_obs=cpl_propertylist_get_double(plist, KEY_NAME_MJD_OBS);
+  } else {
+    sinfo_msg_error("keyword %s does not exist",KEY_NAME_MJD_OBS);
+    cpl_propertylist_delete(plist) ;
+    return -1;
+  }
+  cpl_propertylist_delete(plist) ;
+
+  //sinfo_new_array_set_value(offsetx,-2*offx,n);
+  //sinfo_new_array_set_value(offsety,2*offy,n);
+
+  if (mjd_obs > 53825. ) {
+    /* April 1st 2006 */
+    //sinfo_msg("New cumoffset setting convention");
+    sinfo_new_array_set_value(offsetx,2*offx,n);
+    sinfo_new_array_set_value(offsety,2*offy,n);
+  } else if ((mjd_obs > 53421.58210082 ) && (mjd_obs <= 53825.)){
+    /* after detector's upgrade */
+    /*
+    sinfo_new_array_set_value(offsetx,-offx*2,n);
+    sinfo_new_array_set_value(offsety,+offy*2,n);
+    */
+    sinfo_new_array_set_value(offsetx,-2*offx,n);
+    sinfo_new_array_set_value(offsety,2*offy,n);
+  } else {
+    /* before detector's upgrade */
+    /*
+    sinfo_new_array_set_value(offsetx,+offx*2,n);
+    sinfo_new_array_set_value(offsety,-offy*2,n);
+    */
+    sinfo_new_array_set_value(offsetx,2*offx,n);
+    sinfo_new_array_set_value(offsety,-2*offy,n);
+  }
+
+
+  return 0;
+
+
+}
+
+
+/**
+ at brief extracts from each object frame set information
+       relative to the ao setting
+ at name sinfo_new_assign_offset
+ at param n      frame index in list
+ at param name   file name
+ at param offsetx  reference frame X offset
+ at param offsety  reference frame Y offset
+ at param offsetx frames X offset array
+ at param offsety frames Y offset array
+*/
+
+int
+sinfo_new_object_assign_offset(const char* name,
+                               const int n,
+                               double* ref_offx,
+                               double* ref_offy,
+                               float** offsetx,
+                               float** offsety)
+{
+
+  float offx=0;
+  float offy=0;
+  double mjd_obs=0;
+  cpl_propertylist * plist=NULL;
+  sinfo_msg_debug("Assign offsets");
+
+  if ((cpl_error_code)((plist = cpl_propertylist_load(name, 0)) == NULL)) {
+    sinfo_msg_error( "getting header from reference frame %s",name);
+    cpl_propertylist_delete(plist) ;
+    return -1 ;
+  }
+  if ( n == 0 ) {
+
+    *ref_offx = sinfo_pfits_get_cumoffsetx(plist) ;
+    if(cpl_error_get_code() != CPL_ERROR_NONE) {
+      sinfo_msg_error(" could not read fits header keyword cummoffsetx!") ;
+      /* return -1 ; */
+      cpl_error_reset();
+    }
+
+    *ref_offy = sinfo_pfits_get_cumoffsety(plist) ;
+    if(cpl_error_get_code() != CPL_ERROR_NONE) {
+      sinfo_msg_error(" could not read fits header keyword! cumoffsety") ;
+      cpl_error_reset();
+       /* return -1 ; */
+    }
+    sinfo_msg_debug("Reference offx=%f offy=%f",*ref_offx,*ref_offy);
+
+    offx = 0. ;
+    offy = 0. ;
+
+  } else {
+
+    offx = sinfo_pfits_get_cumoffsetx(plist) - *ref_offx ;  /* was - */
+    if(cpl_error_get_code() != CPL_ERROR_NONE) {
+      sinfo_msg_error(" could not read fits header keyword cummoffsetx!") ;
+      cpl_error_reset();
+      /* return -1 ; */
+    }
+
+    offy = sinfo_pfits_get_cumoffsety(plist) - *ref_offy ; /* was - */
+    if(cpl_error_get_code() != CPL_ERROR_NONE) {
+      sinfo_msg_error(" could not read fits header keyword! cumoffsety") ;
+      /* return -1 ; */
+      cpl_error_reset();
+    }
+    sinfo_msg_debug("offx=%f offy=%f",offx,offy);
+  }
+
+
+    /* rotate the coordinates
+       offx_rot = cd1_1 * offx + cd2_1 * offy ;
+       offy_rot = cd1_2 * offx + cd2_2 * offy ;
+        convert the coordinates to pixel units
+       offx_rot_pix = offx_rot / pixelscale ;
+       offy_rot_pix = offy_rot / pixelscale ;
+       offsetx[i] = offx_rot_pix ;
+       offsety[i] = offy_rot_pix ;
+    */
+
+
+  if (sinfo_propertylist_has(plist, KEY_NAME_MJD_OBS)) {
+    mjd_obs=cpl_propertylist_get_double(plist, KEY_NAME_MJD_OBS);
+  } else {
+    sinfo_msg_error("keyword %s does not exist",KEY_NAME_MJD_OBS);
+    cpl_propertylist_delete(plist) ;
+    return -1;
+  }
+
+  cpl_propertylist_delete(plist) ;
+
+  if (mjd_obs > 53825. ) {
+    /* April 1st 2006 */
+    //sinfo_msg("New cumoffset setting convention");
+    sinfo_new_array_set_value(*offsetx,2*offx,n);
+    sinfo_new_array_set_value(*offsety,2*offy,n);
+  } else if ((mjd_obs > 53421.58210082 ) && (mjd_obs <= 53825.)){
+    /* after detector's upgrade */
+    sinfo_new_array_set_value(*offsetx,-offx*2,n);
+    sinfo_new_array_set_value(*offsety,+offy*2,n);
+  } else {
+    /* before detector's upgrade */
+    sinfo_new_array_set_value(*offsetx,+offx*2,n);
+    sinfo_new_array_set_value(*offsety,-offy*2,n);
+  }
+
+  return 0;
+}
+
+/**
+ at brief Fine tune slitlet distances values
+ at name sinfo_new_fine_tune
+ at param cube input imagelist
+ at param correct_dist array with correct distances
+ at param method  fine tune method
+ at param order   polynomial order
+ at param nslits number of slits
+*/
+
+
+cpl_imagelist*
+sinfo_new_fine_tune(cpl_imagelist* cube,
+              float* correct_dist,
+              const char* method,
+              const int order,
+              const int nslits) {
+  int i =0;
+  cpl_imagelist* outcube2=NULL;
+  float* neg_dist=NULL;
+  sinfo_msg("Finetuning, method=%s",method);
+
+  if (strcmp(method,"P")==0)
+    {
+      outcube2 = sinfo_new_fine_tune_cube( cube, correct_dist, order ) ;
+      if (outcube2 == NULL)
+    {
+      sinfo_msg_error (" could not fine tune the data cube\n") ;
+      return NULL ;
+    }
+    }
+  else if (strcmp(method,"F")==0)
+    {
+      neg_dist=cpl_calloc(nslits,sizeof(float));
+      for ( i = 0 ; i < nslits ; i++ )
+    {
+      neg_dist[i] = -correct_dist[i] ;
+    }
+      outcube2 = sinfo_new_fine_tune_cube_by_FFT( cube, neg_dist ) ;
+     cpl_free(neg_dist);
+      if ( outcube2 == NULL )
+    {
+      sinfo_msg_error (" could not fine tune the data cube\n") ;
+      return NULL ;
+    }
+    }
+  else if (strcmp(method,"S")==0)
+    {
+      outcube2 = sinfo_new_fine_tune_cube_by_spline( cube, correct_dist ) ;
+      if ( outcube2 == NULL )
+    {
+      sinfo_msg_error (" could not fine tune the data cube\n") ;
+      return NULL ;
+    }
+    }
+  else
+    {
+      sinfo_msg_error (" wrong method indicator given!") ;
+      return NULL ;
+    }
+
+
+
+return outcube2;
+
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Get the broad band filter
+  @param    f           the filter name
+  @return   the broadband filter id
+ */
+/*----------------------------------------------------------------------------*/
+sinfo_band sinfo_get_associated_filter(const char * f)
+{
+    if (!strcmp(f, "J"))            return SINFO_BAND_J ;
+    if (!strcmp(f, "Js"))           return SINFO_BAND_JS ;
+    if (!strcmp(f, "Z"))            return SINFO_BAND_Z ;
+    if (!strcmp(f, "SZ"))           return SINFO_BAND_SZ ;
+    if (!strcmp(f, "SH"))           return SINFO_BAND_SH ;
+    if (!strcmp(f, "H"))            return SINFO_BAND_H ;
+    if (!strcmp(f, "Ks"))           return SINFO_BAND_KS ;
+    if (!strcmp(f, "K"))            return SINFO_BAND_K ;
+    if (!strcmp(f, "SK"))           return SINFO_BAND_SK ;
+    if (!strcmp(f, "L"))            return SINFO_BAND_L ;
+    if (!strcmp(f, "SL"))           return SINFO_BAND_SL ;
+    if (!strcmp(f, "M"))            return SINFO_BAND_M ;
+    if (!strcmp(f, "M_NB"))         return SINFO_BAND_M ;
+    if (!strcmp(f, "NB_1.06"))      return SINFO_BAND_J ;
+    if (!strcmp(f, "NB_1.08"))      return SINFO_BAND_J ;
+    if (!strcmp(f, "NB_1.19"))      return SINFO_BAND_J ;
+    if (!strcmp(f, "NB_1.21"))      return SINFO_BAND_J ;
+    if (!strcmp(f, "NB_1.26"))      return SINFO_BAND_J ;
+    if (!strcmp(f, "NB_1.28"))      return SINFO_BAND_J ;
+    if (!strcmp(f, "NB_1.64"))      return SINFO_BAND_H ;
+    if (!strcmp(f, "NB_1.71"))      return SINFO_BAND_H ;
+    if (!strcmp(f, "NB_2.07"))      return SINFO_BAND_KS ;
+    if (!strcmp(f, "NB_2.09"))      return SINFO_BAND_KS ;
+    if (!strcmp(f, "NB_2.13"))      return SINFO_BAND_KS ;
+    if (!strcmp(f, "NB_2.17"))      return SINFO_BAND_KS ;
+    if (!strcmp(f, "NB_2.19"))      return SINFO_BAND_KS ;
+    if (!strcmp(f, "NB_2.25"))      return SINFO_BAND_KS ;
+    if (!strcmp(f, "NB_2.29"))      return SINFO_BAND_KS ;
+    if (!strcmp(f, "NB_2.34"))      return SINFO_BAND_KS ;
+    if (!strcmp(f, "NB_3.21"))      return SINFO_BAND_L ;
+    if (!strcmp(f, "NB_3.28"))      return SINFO_BAND_L ;
+    if (!strcmp(f, "NB_3.80"))      return SINFO_BAND_L ;
+    if (!strcmp(f, "NB_4.07"))      return SINFO_BAND_L ;
+    return SINFO_BAND_UNKNOWN ;
+}
+
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Get the broad band filter
+  @param    f           the filter name
+  @return   the broadband filter id
+ */
+/*----------------------------------------------------------------------------*/
+sinfo_band sinfo_get_bbfilter(const char * f)
+{
+    if (!strcmp(f, "J"))            return SINFO_BAND_J ;
+    if (!strcmp(f, "J+Block"))      return SINFO_BAND_J ;
+    if (!strcmp(f, "Js"))           return SINFO_BAND_J ;
+    if (!strcmp(f, "Z"))            return SINFO_BAND_J ;
+    if (!strcmp(f, "SZ"))           return SINFO_BAND_J ;
+    if (!strcmp(f, "SH"))           return SINFO_BAND_H ;
+    if (!strcmp(f, "H"))            return SINFO_BAND_H ;
+    if (!strcmp(f, "Ks"))           return SINFO_BAND_KS ;
+    if (!strcmp(f, "K"))            return SINFO_BAND_K ;
+    if (!strcmp(f, "SK"))           return SINFO_BAND_K ;
+    if (!strcmp(f, "L"))            return SINFO_BAND_L ;
+    if (!strcmp(f, "SL"))           return SINFO_BAND_L ;
+    if (!strcmp(f, "M"))            return SINFO_BAND_M ;
+    if (!strcmp(f, "M_NB"))         return SINFO_BAND_M ;
+    if (!strcmp(f, "NB_1.06"))      return SINFO_BAND_J ;
+    if (!strcmp(f, "NB_1.08"))      return SINFO_BAND_J ;
+    if (!strcmp(f, "NB_1.19"))      return SINFO_BAND_J ;
+    if (!strcmp(f, "NB_1.21"))      return SINFO_BAND_J ;
+    if (!strcmp(f, "NB_1.26"))      return SINFO_BAND_J ;
+    if (!strcmp(f, "NB_1.28"))      return SINFO_BAND_J ;
+    if (!strcmp(f, "NB_1.64"))      return SINFO_BAND_H ;
+    if (!strcmp(f, "NB_1.71"))      return SINFO_BAND_H ;
+    if (!strcmp(f, "NB_2.07"))      return SINFO_BAND_KS ;
+    if (!strcmp(f, "NB_2.09"))      return SINFO_BAND_KS ;
+    if (!strcmp(f, "NB_2.13"))      return SINFO_BAND_KS ;
+    if (!strcmp(f, "NB_2.17"))      return SINFO_BAND_KS ;
+    if (!strcmp(f, "NB_2.19"))      return SINFO_BAND_KS ;
+    if (!strcmp(f, "NB_2.25"))      return SINFO_BAND_KS ;
+    if (!strcmp(f, "NB_2.29"))      return SINFO_BAND_KS ;
+    if (!strcmp(f, "NB_2.34"))      return SINFO_BAND_KS ;
+    if (!strcmp(f, "NB_3.21"))      return SINFO_BAND_L ;
+    if (!strcmp(f, "NB_3.28"))      return SINFO_BAND_L ;
+    if (!strcmp(f, "NB_3.80"))      return SINFO_BAND_L ;
+    if (!strcmp(f, "NB_4.07"))      return SINFO_BAND_L ;
+    return SINFO_BAND_UNKNOWN ;
+}
+
+
+/**@}*/
diff --git a/sinfoni/sinfo_utilities_scired.h b/sinfoni/sinfo_utilities_scired.h
new file mode 100644
index 0000000..e0e3ed9
--- /dev/null
+++ b/sinfoni/sinfo_utilities_scired.h
@@ -0,0 +1,146 @@
+#ifndef SINFO_UTILITIES_SCIRED_H
+#define SINFO_UTILITIES_SCIRED_H
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+#include <cpl.h>
+#include "sinfo_tpl_utils.h"
+#include "sinfo_key_names.h"
+#include "sinfo_pro_types.h"
+#include "sinfo_msg.h"
+#include "sinfo_cube_construct.h"
+#include "sinfo_utilities.h"
+#include "sinfo_object_cfg.h"
+
+float*
+sinfo_read_distances(const int nslits, const char* distlist);
+
+float** 
+sinfo_read_slitlets_edges(const int nslits, const char* poslist);
+
+
+int 
+sinfo_check_input_data(object_config* cfg);  
+
+int
+sinfo_auto_size_cube(float* offsetx, 
+                      float* offsety,
+              const int nframes, 
+                    float* ref_offx, 
+                    float* ref_offy,
+                    int* size_x,
+		     int* size_y);
+
+int
+sinfo_auto_size_cube4(float* offsetx, 
+                      float* offsety,
+              const int nframes, 
+                    float* ref_offx, 
+                    float* ref_offy,
+                    int* size_x,
+              int* size_y);
+
+
+
+int
+sinfo_auto_size_cube5(object_config * cfg, 
+                    float* ref_offx, float* ref_offy,
+                    float* min_offx, float* min_offy,
+              float* max_offx, float* max_offy);
+
+cpl_imagelist * 
+sinfo_new_cube_getvig(
+        cpl_imagelist *       cube_in,
+        int             loleft_x,
+        int             loleft_y,
+        int             upright_x,
+        int             upright_y);
+
+
+int
+sinfo_new_set_wcs_cube(cpl_imagelist* cub, const char* name, double clambda, 
+         double dis, double cpix, double cx, double cy);
+
+int
+sinfo_new_set_wcs_image(cpl_image* img, const char* name,  
+                        double cx, double cy);
+
+int
+sinfo_new_set_wcs_spectrum(cpl_image* img, const char* name,   
+                           double clambda, double dis, double cpix);
+
+
+
+cpl_imagelist* 
+sinfo_new_fine_tune(cpl_imagelist* cube,float* correct_dist, 
+                    const char* method, const int order, const int nslits) ;
+
+int
+sinfo_new_object_assign_offset(const char* name, const int n, double* ref_offx, 
+                               double* ref_offy, float** offsetx, 
+                               float** offsety);
+
+int
+sinfo_new_assign_offset2(const int n,
+                        const char* name,
+                        float* offsetx,
+                        float* offsety,
+                        const float ref_offx,
+             const float ref_offy);
+
+int
+sinfo_new_assign_offset(const int n,const char* name,float* offsetx,
+                        float* offsety,const float ref_offx,
+                        const float ref_offy);
+
+
+cpl_imagelist** 
+sinfo_new_sinfoni_correct_median(cpl_imagelist** cubeobject, const int n_cubes);
+
+cpl_imagelist** 
+sinfo_new_sinfoni_correct_sky2(cpl_imagelist** cubes,
+                  const int nc,
+                  cpl_imagelist* sky_cube,
+                              cpl_imagelist* med_cube,
+                              cpl_imagelist* msk_cube,
+                              cpl_imagelist* avg_cube,
+                              cpl_imagelist* sig_cube,
+                              cpl_imagelist* ovr_cube);
+
+cpl_imagelist** 
+sinfo_new_sinfoni_correct_sky(cpl_imagelist** cubes,
+                  const int nc,
+                  cpl_imagelist* sky_cube);
+
+int 
+sinfo_new_sinfoni_correct_median_it(cpl_imagelist** inp);
+
+
+int sinfo_calib_flux_std(
+        const char  *   seds_file,
+        const char  *   stdstars,
+        const char  *   filter,
+        cpl_frame   *   frame,
+        cpl_table   *   tab,
+        double          mag);
+
+
+sinfo_band sinfo_get_associated_filter(const char * f);
+sinfo_band sinfo_get_bbfilter(const char * f);
+
+#endif
diff --git a/sinfoni/sinfo_utils.c b/sinfoni/sinfo_utils.c
new file mode 100644
index 0000000..68053ae
--- /dev/null
+++ b/sinfoni/sinfo_utils.c
@@ -0,0 +1,139 @@
+/*                                                                           *
+ *   This file is part of the ESO SINFONI Pipeline                           *
+ *   Copyright (C) 2004,2005 European Southern Observatory                   *
+ *                                                                           *
+ *   This library is free software; you can redistribute it and/or modify    *
+ *   it under the terms of the GNU General Public License as published by    *
+ *   the Free Software Foundation; either version 2 of the License, or       *
+ *   (at your option) any later version.                                     *
+ *                                                                           *
+ *   This program is distributed in the hope that it will be useful,         *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
+ *   GNU General Public License for more details.                            *
+ *                                                                           *
+ *   You should have received a copy of the GNU General Public License       *
+ *   along with this program; if not, write to the Free Software             *
+ *   Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA    *
+ *                                                                           */
+/*
+ * $Author: amodigli $
+ * $Date: 2012/03/03 10:17:31 $
+ * $Revision: 1.7 $
+ * $Name: sinfo-2_3_2 $
+ * $Log: sinfo_utils.c,v $
+ * Revision 1.7  2012/03/03 10:17:31  amodigli
+ * fixed some doxygen warnings
+ *
+ * Revision 1.6  2010/09/30 14:00:03  kmirny
+ * moving function from wavecal to utils
+ *
+ * Revision 1.5  2007/05/25 06:28:35  amodigli
+ * fixed plugintest warnings
+ *
+ * Revision 1.4  2006/11/07 07:13:25  amodigli
+ * added doxygen
+ *
+ * Revision 1.3  2006/11/04 15:28:36  amodigli
+ * doxygen
+ *
+ * Revision 1.2  2006/10/17 07:02:24  amodigli
+ * shorten line length
+ *
+ * Revision 1.1  2006/08/09 12:26:36  amodigli
+ * added sinfo_utils.h sinfo_utils.c
+ *
+
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+/**@{*/
+/*---------------------------------------------------------------------------*/
+/**
+ * @defgroup sinfo_utils  Utility functions
+ *
+ * This module contains various functions that are shared between multiple 
+   recipes
+ */
+/*---------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+                            Includes
+ ----------------------------------------------------------------------------*/
+
+#include <sinfo_utils.h>
+/**
+ * @addtogroup sinfo_utilities utilities 
+ *
+ * TBD
+ */
+
+/*----------------------------------------------------------------------------
+                            Functions prototypes
+ ----------------------------------------------------------------------------*/
+/*----------------------------------------------------------------------------
+                            Implementation
+ ----------------------------------------------------------------------------*/
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief   Round a number to the nearest integer
+   @param   x       The number to round
+   @return  Nearest integer
+
+   This is implemented as a function rather than a macro to avoid multiple
+   evaluations of expressions that have side effects.
+*/
+/*---------------------------------------------------------------------------*/
+long
+sinfo_round_double(double x)
+{
+    return (x >=0) ? (long)(x+0.5) : (long)(x-0.5);
+}
+/**
+    @brief    Check if an input parameter has been changed by the user
+    @param    p input parameter
+    @return  if has not changed 0, else 1;
+ */
+int
+sinfo_parameter_get_default_flag ( const cpl_parameter* p )
+{
+   int flag_gasgano=0;
+   int flag_norm=0;
+   int flag=0;
+   cpl_type type =0;
+
+   flag_norm = ( cpl_parameter_get_default_flag ( p ) == 0 ) ? 1 : 0;
+   type=cpl_parameter_get_type ( p );
+
+   switch ( type )
+   {
+      case CPL_TYPE_BOOL:
+         flag_gasgano = ( cpl_parameter_get_default_bool ( p ) ==
+                          cpl_parameter_get_bool ( p ) ) ? 1:0;
+         break;
+      case CPL_TYPE_INT:
+         flag_gasgano = ( cpl_parameter_get_default_int ( p ) ==
+                          cpl_parameter_get_int ( p ) ) ? 1:0;
+         break;
+      case CPL_TYPE_DOUBLE:
+         flag_gasgano = ( cpl_parameter_get_default_double ( p ) ==
+                          cpl_parameter_get_double ( p ) ) ? 1:0;
+         break;
+      case CPL_TYPE_STRING:
+         flag_gasgano = ( cpl_parameter_get_default_string ( p ) ==
+                          cpl_parameter_get_string ( p ) ) ? 1:0;
+         break;
+
+      default:
+         cpl_msg_error (cpl_func, "type not supported" );
+   }
+
+   flag = ( flag_gasgano && flag_norm ) ? 0 : 1;
+
+   return flag;
+}
+/**@}*/
diff --git a/sinfoni/sinfo_utils.h b/sinfoni/sinfo_utils.h
new file mode 100644
index 0000000..ce283ba
--- /dev/null
+++ b/sinfoni/sinfo_utils.h
@@ -0,0 +1,99 @@
+/*
+ * This file is part of the ESO SINFO Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: kmirny $
+ * $Date: 2010/09/30 14:00:03 $
+ * $Revision: 1.5 $
+ * $Name: sinfo-2_3_2 $
+ *
+ */
+#ifndef SINFO_UTILS_H
+#define SINFO_UTILS_H
+
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+#include <math.h>
+#include <sinfo_msg.h>
+#include <sinfo_error.h>
+#include <cpl.h>
+/*
+ * The purpose of this target is to
+ * decrease the amount of messages
+ * printed at the debug level.
+ *
+ * If set to non-zero, even more messages
+ * are printed at the debug level
+ * (sometimes 50 - 100 MB)
+ *
+ */
+#ifndef WANT_BIG_LOGFILE
+#define WANT_BIG_LOGFILE 0
+#endif
+
+/*
+ * Set to 1 to show timing
+ * information on msg-level = info
+ */
+#ifndef WANT_TIME_MEASURE
+#define WANT_TIME_MEASURE 0
+#endif
+
+
+#if WANT_TIME_MEASURE
+#define SINFO_TIME_START(what) sinfo_msg("Timing (%s, l%d) %s start", \
+                                       __FILE__, __LINE__, what)
+#define SINFO_TIME_END         sinfo_msg("Timing (%s, l%d) end", \
+                                       __FILE__, __LINE__)
+#else
+#define SINFO_TIME_START(what) sinfo_msg_debug("Timing (%s, l%d) %s start", \
+                                             __FILE__, __LINE__, what)
+#define SINFO_TIME_END         sinfo_msg_debug("Timing (%s, l%d) end", \
+                                             __FILE__, __LINE__)
+#endif
+
+
+
+
+#ifndef stringify
+#ifndef make_str
+#define stringify(X) #X
+#define make_str(X) stringify(X)
+#endif
+#endif
+
+#define TWOSQRT2LN2 2.35482004503095
+
+#ifndef M_PI
+#define M_PI 3.1415926535897932384626433832795
+#endif
+
+#define COS_DEG(x) cos(((x)/180)*M_PI)
+#define SIN_DEG(x) sin(((x)/180)*M_PI)
+#define ACOS_DEG(x) (acos(x)*180/M_PI)
+
+
+
+long sinfo_round_double(double x);
+int
+sinfo_parameter_get_default_flag ( const cpl_parameter* p );
+
+#endif
diff --git a/sinfoni/sinfo_utils_wrappers.c b/sinfoni/sinfo_utils_wrappers.c
new file mode 100644
index 0000000..bc54d31
--- /dev/null
+++ b/sinfoni/sinfo_utils_wrappers.c
@@ -0,0 +1,496 @@
+
+/*                                                                           *
+ *   This file is part of the ESO SINFO Pipeline                             *
+ *   Copyright (C) 2004,2005 European Southern Observatory                   *
+ *                                                                           *
+ *   This library is free software; you can redistribute it and/or modify    *
+ *   it under the terms of the GNU General Public License as published by    *
+ *   the Free Software Foundation; either version 2 of the License, or       *
+ *   (at your option) any later version.                                     *
+ *                                                                           *
+ *   This program is distributed in the hope that it will be useful,         *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
+ *   GNU General Public License for more details.                            *
+ *                                                                           *
+ *   You should have received a copy of the GNU General Public License       *
+ *   along with this program; if not, write to the Free Software             *
+ *   Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA    *
+ *                                                                           */
+
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+/**@{*/
+/*---------------------------------------------------------------------------*/
+/**
+   @defgroup sinfo_utils_wrappers  Utility functions (wrappers)
+
+   This module contains wrapper functions, convenience functions and simple 
+   extensions of CPL functions.
+ 
+ */
+/*--------------------------------------------------------------------------*/
+
+
+#include <sinfo_utils_wrappers.h>
+#include <sinfo_functions.h>
+#include <sinfo_dump.h>
+#include <sinfo_utils.h>
+#include <sinfo_error.h>
+#include "sinfo_msg.h"
+/*---------------------------------------------------------------------------*/
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Sort a table by one column
+   @param    t        Table
+   @param    column   Column name
+   @param    reverse  Flag indicating if column values are sorted descending
+                      (CPL_TRUE) or ascending (CPL_FALSE)
+   @return   CPL_ERROR_NONE iff OK
+
+   This is a wrapper of @c cpl_table_sort().
+
+*/
+/*---------------------------------------------------------------------------*/
+cpl_error_code
+sinfo_sort_table_1(cpl_table *t, const char *column, cpl_boolean reverse)
+{
+    cpl_propertylist *plist = NULL;
+    
+    assure(t != NULL, CPL_ERROR_NULL_INPUT, "Null table");
+    assure(cpl_table_has_column(t, column), CPL_ERROR_ILLEGAL_INPUT, 
+       "No column '%s'", column);
+
+    check(( plist = cpl_propertylist_new(),
+        cpl_propertylist_append_bool(plist, column, reverse)),
+       "Could not create property list for sorting");
+
+    check( cpl_table_sort(t, plist), "Could not sort table");
+
+  cleanup:
+    sinfo_free_propertylist(&plist);
+    return cpl_error_get_code();
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Sort a table by two columns
+   @param    t        Table
+   @param    column1  1st column name
+   @param    column2  2nd column name
+   @param    reverse1  Flag indicating if 1st column values are sorted
+                       descending (true) or ascending (CPL_FALSE)
+   @param    reverse2  Flag indicating if 2nd column values are sorted
+                       descending (true) or ascending (CPL_TRUE)
+   @return   CPL_ERROR_NONE iff OK
+
+   This is a wrapper of @c cpl_table_sort(). @em column1 is the more
+   significant column (i.e. values in @em column2 are compared, only if the
+   values in @em column1 are equal).
+*/
+/*---------------------------------------------------------------------------*/
+cpl_error_code
+sinfo_sort_table_2(cpl_table *t, const char *column1, const char *column2, 
+          cpl_boolean reverse1, cpl_boolean reverse2)
+{
+    cpl_propertylist *plist = NULL;
+    
+    assure(t != NULL, CPL_ERROR_NULL_INPUT, "Null table");
+    assure(cpl_table_has_column(t, column1), CPL_ERROR_ILLEGAL_INPUT, 
+       "No column '%s'", column1);
+    assure(cpl_table_has_column(t, column2), CPL_ERROR_ILLEGAL_INPUT,
+       "No column '%s'", column2);
+
+    check(( plist = cpl_propertylist_new(),
+        cpl_propertylist_append_bool(plist, column1, reverse1),
+        cpl_propertylist_append_bool(plist, column2, reverse2)),
+       "Could not create property list for sorting");
+    check( cpl_table_sort(t, plist), "Could not sort table");
+    
+  cleanup:
+    sinfo_free_propertylist(&plist);
+    return cpl_error_get_code();
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Extract table rows
+   @param    t        Table
+   @param    column   Column name
+   @param    operator Logical operator
+   @param    value    Value used for comparison
+   @return   A new table containing the extracted rows
+
+   A table row is extracted if and only if the value in @em column is in the
+   relation @em operator to the specified @em value. The specified column
+   must have type CPL_TYPE_DOUBLE or CPL_TYPE_INT. If integer, the integer
+   nearest to @em value is used for the comparison.
+
+   Also see @c cpl_table_and_selected_<type>().
+
+*/
+/*---------------------------------------------------------------------------*/
+cpl_table *
+sinfo_extract_table_rows(const cpl_table *t, const char *column,
+            cpl_table_select_operator operator, double value)
+{
+    cpl_table *result = NULL;
+    assure( t != NULL, CPL_ERROR_NULL_INPUT, "Null table");
+    assure( cpl_table_has_column(t, column), CPL_ERROR_INCOMPATIBLE_INPUT,
+        "No such column: %s", column);
+    
+    /* 1. Extract (duplicate) the entire table
+       2. remove rows *not* satisfying the criterion */
+
+    check(result = cpl_table_duplicate(t),"selecting");
+    check(sinfo_select_table_rows(result, column, operator, value),"select");
+    check(cpl_table_not_selected(result),"Inverses selection");
+    check(cpl_table_erase_selected(result),"erase selection");//problems
+
+    /*
+    check(( result = cpl_table_duplicate(t),
+        sinfo_select_table_rows(result, column, operator, value),
+        cpl_table_not_selected(result),  // Inverses selection 
+        cpl_table_erase_selected(result)),
+       "Error extracting rows");
+    */
+    
+  cleanup:
+    if (cpl_error_get_code() != CPL_ERROR_NONE)
+    {
+        sinfo_free_table(&result);
+    }
+    return result;
+}
+
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Select table rows
+   @param    t        Table
+   @param    column   Column name
+   @param    operator Logical operator
+   @param    value    Value used for comparison
+   @return   Number of selected rows
+
+   A row is selected if and only if the value in @em column is in the
+   relation @em operator to the specified @em value. The specified column must
+   have type CPL_TYPE_DOUBLE or CPL_TYPE_INT. If integer, the integer nearest
+   to @em value is used for the comparison.
+
+   Also see @c cpl_table_and_selected_<type>().
+
+*/
+/*---------------------------------------------------------------------------*/
+
+int
+sinfo_select_table_rows(cpl_table *t,  const char *column, 
+               cpl_table_select_operator operator, double value)
+{
+    int result = 0;
+    cpl_type type;
+    assure( t != NULL, CPL_ERROR_NULL_INPUT, "Null table");
+    assure( cpl_table_has_column(t, column), CPL_ERROR_INCOMPATIBLE_INPUT, 
+        "No such column: %s", column);
+
+    type = cpl_table_get_column_type(t, column);
+
+    assure( type == CPL_TYPE_DOUBLE ||
+        type == CPL_TYPE_INT, CPL_ERROR_INVALID_TYPE,
+        "Column '%s' must be double or int. %s found", column, 
+        sinfo_tostring_cpl_type(type));
+
+    check( cpl_table_select_all(t), "Error selecting rows");
+    
+    if      (type == CPL_TYPE_DOUBLE)
+    {
+        result = cpl_table_and_selected_double(t, column, operator, value);
+    }
+    else if (type == CPL_TYPE_INT)
+    {
+        result = cpl_table_and_selected_int   (t, column, operator, 
+                             sinfo_round_double(value));
+    }
+    else { /*impossible*/ passure(CPL_FALSE, ""); }
+    
+  cleanup:
+    return result;
+
+}
+
+/**
+   @brief    Deallocate an image and set the pointer to NULL
+   @param    p        parameter to deallocate
+*/
+/*---------------------------------------------------------------------------*/
+void sinfo_free_parameter(cpl_parameter **p) 
+{if(p){cpl_parameter_delete(*p);            *p = NULL;}}
+
+
+
+/**
+   @brief    Deallocate an aperture and set the pointer to NULL
+   @param    a        parameter to deallocate
+*/
+/*---------------------------------------------------------------------------*/
+void sinfo_free_apertures(cpl_apertures **a) 
+{if(a){cpl_apertures_delete(*a);            *a = NULL;}}
+/*---------------------------------------------------------------------------*/
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Deallocate an image and set the pointer to NULL
+   @param    i        Image to deallocate
+*/
+/*---------------------------------------------------------------------------*/
+void sinfo_free_image(cpl_image **i)  {if(i){cpl_image_delete(*i); *i = NULL;}}
+
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Deallocate an image and set the pointer to NULL
+   @param    v Vector to deallocate
+*/
+/*---------------------------------------------------------------------------*/
+void sinfoni_free_vector(cpl_vector **v)  {if(v){cpl_vector_delete(*v); *v = NULL;}}
+
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Deallocate an array and set the pointer to NULL
+   @param    i        array to deallocate
+*/
+/*---------------------------------------------------------------------------*/
+void sinfo_free_array(cpl_array **i)  {if(i){cpl_array_delete(*i); *i = NULL;}}
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Deallocate an image mask and set the pointer to NULL
+   @param    m        Mask to deallocate
+*/
+/*---------------------------------------------------------------------------*/
+void sinfo_free_mask(cpl_mask **m)  {if(m){cpl_mask_delete(*m); *m = NULL;}}
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Deallocate an image list and set the pointer to NULL
+   @param    i        Image list to deallocate
+*/
+/*---------------------------------------------------------------------------*/
+void sinfo_free_imagelist(cpl_imagelist **i) 
+{if(i){cpl_imagelist_delete(*i);        *i = NULL;}}
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Deallocate a table and set the pointer to NULL
+   @param    t        Table to deallocate
+*/
+/*---------------------------------------------------------------------------*/
+void sinfo_free_table(cpl_table **t) {if(t){cpl_table_delete(*t); *t = NULL;}}
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Deallocate a property list and set the pointer to NULL
+   @param    p        Property list to deallocate
+*/
+/*---------------------------------------------------------------------------*/
+void sinfo_free_propertylist(cpl_propertylist **p)   
+{if(p){cpl_propertylist_delete(*p);     *p = NULL;}}
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Deallocate a polynomial and set the pointer to NULL
+   @param    p        Polynomial to deallocate
+*/
+/*---------------------------------------------------------------------------*/
+void sinfo_free_polynomial(cpl_polynomial **p)       
+{if(p){cpl_polynomial_delete(*p);       *p = NULL;}}
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Deallocate a matrix and set the pointer to NULL
+   @param    m        Matrix to deallocate
+*/
+/*---------------------------------------------------------------------------*/
+/* similar also present in svd.c */
+void sinfoni_free_matrix(cpl_matrix **m) 
+{if(m){cpl_matrix_delete(*m); *m = NULL;}}
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Deallocate a parameter list and set the pointer to NULL
+   @param    p        Parameter list to deallocate
+*/
+/*---------------------------------------------------------------------------*/
+void sinfo_free_parameterlist(cpl_parameterlist **p) 
+{if(p){cpl_parameterlist_delete(*p);    *p = NULL;}}
+/*----------------------------------------------------------------------------*/
+/**
+   @brief    Deallocate a vector and set the pointer to NULL
+   @param    f        Frame set to deallocate
+*/
+/*---------------------------------------------------------------------------*/
+void sinfo_free_frameset(cpl_frameset **f) 
+{if(f){cpl_frameset_delete(*f);    *f = NULL;}}
+
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Deallocate a vector and set the pointer to NULL
+   @param    f        Frame to deallocate
+*/
+/*---------------------------------------------------------------------------*/
+void sinfo_free_frame(cpl_frame **f) 
+{if(f){cpl_frame_delete(*f);    *f = NULL;}}
+
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Deallocate a vector and set the pointer to NULL
+   @param    i        int to deallocate
+*/
+/*---------------------------------------------------------------------------*/
+void sinfo_free_int(int **i) {if(i){cpl_free(*i);    *i = NULL;}}
+
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Deallocate a vector and set the pointer to NULL
+   @param    f float to deallocate
+*/
+/*---------------------------------------------------------------------------*/
+void sinfo_free_float(float **f) {if(f){cpl_free(*f);    *f = NULL;}}
+
+
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Deallocate a vector and set the pointer to NULL
+   @param    d double to deallocate
+*/
+/*---------------------------------------------------------------------------*/
+void sinfo_free_double(double **d) {if(d){cpl_free(*d);    *d = NULL;}}
+
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Deallocate a vector and set the pointer to NULL
+   @param    a array to deallocate
+*/
+/*---------------------------------------------------------------------------*/
+void sinfo_free_array_imagelist(cpl_imagelist ***a) 
+{if(*a){cpl_free(*a); *a = NULL;}}
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Deallocate a vector and set the pointer to NULL
+   @param    a array to deallocate
+*/
+/*---------------------------------------------------------------------------*/
+void sinfo_free_array_image(cpl_image ***a) {if(*a){cpl_free(*a); *a = NULL;}}
+
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Deallocate an image array and set the pointer to NULL
+   @param    a array to deallocate
+   @param    n array size
+*/
+/*---------------------------------------------------------------------------*/
+void sinfo_free_image_array(cpl_image ***a, const int n) 
+{
+  int i=0;
+  if((*a) != NULL) {
+    for (i=0; i < n; i++) {
+      if((*a)[i] != NULL) {
+    sinfo_free_image(&(*a)[i]);
+    (*a)[i]=NULL;
+      }
+    }
+    sinfo_free_array_image(&(*a));
+    *a=NULL;
+  }
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Deallocate an array of float arrays and set the pointer to NULL
+   @param    a array to deallocate
+   @param    n array size
+*/
+/*---------------------------------------------------------------------------*/
+void sinfo_free_float_array(float ***a, const int n) 
+{
+  int i=0;
+  if((*a) != NULL) {
+    for (i=0; i < n; i++) {
+      if((*a)[i] != NULL) {
+    sinfo_free_float(&(*a)[i]);
+    (*a)[i]=NULL;
+      }
+    }
+    cpl_free(*a);
+    *a=NULL;
+  }
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Deallocate a vector and set the pointer to NULL
+   @param    v        Vector to deallocate
+*/
+/*---------------------------------------------------------------------------*/
+
+void 
+sinfo_free_my_vector(cpl_vector **v) {if(v){cpl_vector_delete(*v);*v = NULL;}}
+
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Deallocate a vector and set the pointer to NULL
+   @param    bv        Vector to deallocate
+*/
+/*---------------------------------------------------------------------------*/
+
+void 
+sinfo_free_bivector(cpl_bivector **bv) {
+  if(bv){
+     cpl_bivector_delete(*bv);
+     *bv = NULL;
+  }
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Deallocate a stats object and set the pointer to NULL
+   @param    s        Stats object to deallocate
+*/
+/*---------------------------------------------------------------------------*/
+void sinfo_free_stats(cpl_stats **s) {if(s){cpl_stats_delete(*s); *s = NULL;}}
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Unwrap a vector and set the pointer to NULL
+   @param    v        Vector to unwrap
+*/
+/*---------------------------------------------------------------------------*/
+void 
+sinfo_unwrap_vector(cpl_vector **v) {if(v){cpl_vector_unwrap(*v); *v = NULL;}}
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Unwrap a matrix and set the pointer to NULL
+   @param    m        matrix to unwrap
+*/
+/*---------------------------------------------------------------------------*/
+void sinfo_unwrap_matrix(cpl_matrix **m) 
+{if(m){cpl_matrix_unwrap(*m); *m = NULL;}}
+
+/*---------------------------------------------------------------------------*/
+/**
+   @brief    Unwrap a bi-vector and set the pointer to NULL
+   @param    b        Bi-vector to deallocate
+*/
+/*---------------------------------------------------------------------------*/
+void sinfo_unwrap_bivector_vectors(cpl_bivector **b) 
+{if(b){cpl_bivector_unwrap_vectors(*b); *b = NULL;}}
+
+/**@}*/
diff --git a/sinfoni/sinfo_utils_wrappers.h b/sinfoni/sinfo_utils_wrappers.h
new file mode 100644
index 0000000..1c458e3
--- /dev/null
+++ b/sinfoni/sinfo_utils_wrappers.h
@@ -0,0 +1,84 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+#ifndef SINFO_UTILS_WRAPPERS_H
+#define SINFO_UTILS_WRAPPERS_H
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+/*-----------------------------------------------------------------------------
+                    Includes
+ -----------------------------------------------------------------------------*/
+
+#include <cpl.h>
+
+/*-----------------------------------------------------------------------------
+                             Defines
+ -----------------------------------------------------------------------------*/
+
+
+/*-----------------------------------------------------------------------------
+                                   Prototypes
+ -----------------------------------------------------------------------------*/
+void sinfo_free_float_array(float ***a, const int n) ;
+
+cpl_table *
+sinfo_extract_table_rows(const cpl_table *t, const char *column,
+             cpl_table_select_operator operator, double value);
+int
+sinfo_select_table_rows(cpl_table *t,  const char *column, 
+            cpl_table_select_operator operator, double value);
+
+cpl_error_code sinfo_sort_table_1(cpl_table *t, const char *column1,
+                 cpl_boolean reverse1);
+cpl_error_code sinfo_sort_table_2(cpl_table *t, const char *column1, 
+                 const char *column2, cpl_boolean reverse1, 
+                 cpl_boolean reverse2);
+
+void sinfoni_free_vector(cpl_vector **v);
+void sinfo_free_array(cpl_array **i);
+void sinfo_free_apertures(cpl_apertures **a);
+void sinfo_free_parameter(cpl_parameter **p);
+void sinfo_free_image(cpl_image **i);
+void sinfo_free_mask(cpl_mask **m);
+void sinfo_free_imagelist(cpl_imagelist **i);
+void sinfo_free_table(cpl_table **t);
+void sinfo_free_propertylist(cpl_propertylist **p);
+void sinfo_free_polynomial(cpl_polynomial **p);
+void sinfo_free_stats(cpl_stats **s);
+void sinfo_unwrap_matrix(cpl_matrix **m);
+void sinfo_unwrap_vector(cpl_vector **v);
+void sinfo_unwrap_bivector_vectors(cpl_bivector **b);
+void sinfo_free_parameterlist(cpl_parameterlist **p);
+void sinfo_free_frameset(cpl_frameset **f);
+void sinfo_free_frame(cpl_frame **f);
+void sinfo_free_int(int **i);
+void sinfo_free_float(float **i);
+void sinfo_free_double(double **i);
+void sinfo_free_array_imagelist(cpl_imagelist ***a);
+void sinfo_free_array_image(cpl_image ***a);
+void sinfo_free_image_array(cpl_image ***a,const int n);
+/* similar are also defined with same name in svd.h */
+void sinfoni_free_matrix(cpl_matrix **m);
+void sinfo_free_my_vector(cpl_vector **v);
+void sinfo_free_bivector(cpl_bivector **bv);
+
+
+#endif
diff --git a/sinfoni/sinfo_utl_cube2ima.c b/sinfoni/sinfo_utl_cube2ima.c
new file mode 100644
index 0000000..9616fed
--- /dev/null
+++ b/sinfoni/sinfo_utl_cube2ima.c
@@ -0,0 +1,244 @@
+/* $Id: sinfo_utl_cube2ima.c,v 1.8 2012/03/03 10:17:31 amodigli Exp $
+ *
+ * This file is part of the IIINSTRUMENT Pipeline
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2012/03/03 10:17:31 $
+ * $Revision: 1.8 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+/*-----------------------------------------------------------------------------
+                                Includes
+ -----------------------------------------------------------------------------*/
+
+#include "sinfo_functions.h"
+#include "sinfo_new_cube_ops.h"
+#include "sinfo_utl_cube2ima.h"
+#include "sinfo_key_names.h"
+#include <sinfo_error.h>
+#include <sinfo_utils_wrappers.h>
+
+/*-----------------------------------------------------------------------------
+                            Functions prototypes
+ -----------------------------------------------------------------------------*/
+
+
+
+/*-----------------------------------------------------------------------------
+                            Static variables
+ -----------------------------------------------------------------------------*/
+
+/*-----------------------------------------------------------------------------
+                                Functions code
+ -----------------------------------------------------------------------------*/
+
+/**@{*/
+/**
+ * @addtogroup sinfo_utl_cube2ima Cube to image transformation
+ *
+ * TBD
+ */
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Get the command line options and execute the data reduction
+  @param    parlist     the parameters list
+  @param    framelist   the frames list
+  @return   0 if everything is ok
+ */
+/*----------------------------------------------------------------------------*/
+int sinfo_utl_cube2ima(
+        cpl_parameterlist   *   parlist, 
+        cpl_frameset        *   framelist)
+{
+    cpl_parameter       *   param =NULL ;
+    const char          *   name_i =NULL;
+    const char          *   name_o =NULL;
+
+    double                  ws=0 ;
+    double                  we=0 ;
+    double                  wc=0 ;
+    double                  wd=0 ;
+
+
+    int naxis3=0;
+    double lams=0;
+    double lame=0;
+
+    cpl_frame           *   frm_cub=NULL ;
+ 
+    cpl_propertylist    *   plist=NULL ;
+    cpl_frame           *   product_frame=NULL;
+
+    cpl_imagelist * cube=NULL;
+    cpl_image * img=NULL;
+
+   
+    /* HOW TO RETRIEVE INPUT PARAMETERS */
+    /* --stropt */
+    name_o ="out_ima.fits";
+ 
+    /* --doubleopt */
+    check_nomsg(param = cpl_parameterlist_find(parlist,
+                                            "sinfoni.sinfo_utl_cube2ima.ws"));
+    check_nomsg(ws = cpl_parameter_get_double(param)) ;
+
+    /* --doubleopt */
+    check_nomsg(param = cpl_parameterlist_find(parlist,
+                                            "sinfoni.sinfo_utl_cube2ima.we"));
+    check_nomsg(we = cpl_parameter_get_double(param)) ;
+
+    /* Identify the RAW and CALIB frames in the input frameset */
+    check(sinfo_dfs_set_groups(framelist),
+        "Cannot identify RAW and CALIB frames");
+ 
+    /* HOW TO ACCESS INPUT DATA */
+    check(frm_cub = cpl_frameset_find(framelist, SI_UTL_CUBE2IMA_CUBE),
+        "SOF does not have a file tagged as %s",SI_UTL_CUBE2IMA_CUBE);
+
+    check_nomsg(name_i = cpl_frame_get_filename(frm_cub));
+
+    plist=cpl_propertylist_load(name_i,0);
+    naxis3=sinfo_pfits_get_naxis3(plist);
+    wd=sinfo_pfits_get_cdelt3(plist);
+    wc=sinfo_pfits_get_crval3(plist);
+    sinfo_free_propertylist(&plist);
+
+    lams=wc-naxis3*wd/2+wd;
+    lame=lams+(naxis3-2)*wd;
+
+    check_nomsg(param = cpl_parameterlist_find(parlist,
+                                            "sinfoni.sinfo_utl_cube2ima.ws"));
+
+    if(ws != cpl_parameter_get_default_double(param)) {
+      if (ws < lams) {
+        sinfo_msg_warning("ws =%f too low set it to %f",ws,lams);
+        ws=lams;
+      }
+      else if (ws >= lame) {
+        sinfo_msg_warning("ws =%f too high set it to %f",ws,lams);
+        ws=lams;
+      }
+    } else {
+      ws=lams;
+    }
+
+    check_nomsg(param = cpl_parameterlist_find(parlist,
+                                             "sinfoni.sinfo_utl_cube2ima.we"));
+    if(we != cpl_parameter_get_default_double(param)) {
+      if (we > lame) {
+        sinfo_msg_warning("we =%f too low set it to %f",we,lame);
+        we=lame;
+      }
+      else if (we <= lams) {
+        sinfo_msg_warning("we =%f too low set it to %f",we,lame);
+        we=lame;
+      }
+    } else {
+      we=lame;
+    }
+
+    check(plist=cpl_propertylist_load(cpl_frame_get_filename(frm_cub),0),
+          "Cannot read the FITS header") ;
+
+    /* recipe's algorithm */
+    check_nomsg(cube = cpl_imagelist_load((char*)name_i,CPL_TYPE_FLOAT,0));
+    if(NULL==(img=sinfo_new_average_cube_to_image_between_waves(cube,wd,wc,
+                                                                ws,we))) {
+     sinfo_msg_error("Cannot average cube to image in wavelength "
+                     "range [%f,%f] um",ws,we) ;
+
+       sinfo_free_imagelist(&cube);
+       sinfo_free_propertylist(&plist);    
+
+    }
+    sinfo_free_imagelist(&cube);
+
+    /* HOW TO SAVE A PRODUCT ON DISK  */
+    /* Create product frame */
+    check_nomsg(product_frame = cpl_frame_new());
+    check_nomsg(cpl_frame_set_filename(product_frame, name_o)) ;
+    check_nomsg(cpl_frame_set_tag(product_frame, SI_UTL_CUBE2IMA_PROIMA)) ;
+    check_nomsg(cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_IMAGE)) ;
+    check_nomsg(cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT)) ;
+    check(cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL), 
+     "Error while initialising the product frame") ;
+
+
+    /* Add DataFlow keywords */
+    check_nomsg(cpl_propertylist_erase_regexp(plist, "^ESO PRO CATG",0));
+#if defined CPL_VERSION_CODE && CPL_VERSION_CODE >= CPL_VERSION(4, 8, 0) 
+    check(cpl_dfs_setup_product_header(plist, 
+                                       product_frame, 
+                                       framelist, 
+                                       parlist,
+                                       "si_sinfo_utl_cube2ima", 
+                                       "SINFONI", 
+                                       KEY_VALUE_HPRO_DID,NULL),
+      "Problem in the product DFS-compliance") ;
+#else
+    check(cpl_dfs_setup_product_header(plist, 
+                                       product_frame, 
+                                       framelist, 
+                                       parlist,
+                                       "si_sinfo_utl_cube2ima", 
+                                       "SINFONI", 
+                                       KEY_VALUE_HPRO_DID),
+      "Problem in the product DFS-compliance") ;
+#endif
+   
+    /* Save the file */
+    check_nomsg(cpl_propertylist_erase_regexp(plist, "^CTYPE3",0));
+    check_nomsg(cpl_propertylist_erase_regexp(plist, "^CRPIX3",0));
+    check_nomsg(cpl_propertylist_erase_regexp(plist, "^CRVAL3",0));
+    check_nomsg(cpl_propertylist_erase_regexp(plist, "^CDELT3",0));
+    check_nomsg(cpl_propertylist_erase_regexp(plist, "^CUNIT3",0));
+
+    check(cpl_image_save(img, 
+                         name_o, 
+                         CPL_BPP_IEEE_FLOAT, 
+                         plist,
+                         CPL_IO_DEFAULT),
+      "Could not save product");
+
+    check_nomsg(sinfo_free_propertylist(&plist)) ;
+  
+    /* Log the saved file in the input frameset */
+    check_nomsg(cpl_frameset_insert(framelist, product_frame)) ;
+    check_nomsg(sinfo_free_image(&img)) ;
+ 
+    /* Return */
+
+ cleanup:
+       sinfo_free_imagelist(&cube);
+       sinfo_free_propertylist(&plist);    
+       sinfo_free_image(&img);
+
+    if (cpl_error_get_code()) 
+        return -1 ;
+    else 
+        return 0 ;
+}
+/**@}*/
diff --git a/sinfoni/sinfo_utl_cube2ima.h b/sinfoni/sinfo_utl_cube2ima.h
new file mode 100644
index 0000000..b85d706
--- /dev/null
+++ b/sinfoni/sinfo_utl_cube2ima.h
@@ -0,0 +1,42 @@
+/* $Id: sinfo_utl_cube2ima.h,v 1.1 2006/10/22 14:12:28 amodigli Exp $
+ *
+ * This file is part of the IIINSTRUMENT Pipeline
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2006/10/22 14:12:28 $
+ * $Revision: 1.1 $
+ * $Name: sinfo-2_3_2 $
+ */
+/*-----------------------------------------------------------------------------
+                                Includes
+-----------------------------------------------------------------------------*/
+#ifndef SINFO_UTL_CUBE2IMA_H
+#define SINFO_UTL_CUBE2IMA_H
+#include <cpl.h>
+#include "sinfo_tpl_utils.h"
+#include "sinfo_pfits.h"
+#include "sinfo_tpl_dfs.h"
+
+/*-----------------------------------------------------------------------------
+                            Functions prototypes
+-----------------------------------------------------------------------------*/
+int sinfo_utl_cube2ima(cpl_parameterlist *, cpl_frameset *) ;
+
+#endif
diff --git a/sinfoni/sinfo_utl_cube2spectrum.c b/sinfoni/sinfo_utl_cube2spectrum.c
new file mode 100644
index 0000000..59a2c36
--- /dev/null
+++ b/sinfoni/sinfo_utl_cube2spectrum.c
@@ -0,0 +1,488 @@
+/* $Id: sinfo_utl_cube2spectrum.c,v 1.11 2012/03/03 10:17:31 amodigli Exp $
+ *
+ * This file is part of the IIINSTRUMENT Pipeline
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2012/03/03 10:17:31 $
+ * $Revision: 1.11 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+/*----------------------------------------------------------------------------
+                                Includes
+ ----------------------------------------------------------------------------*/
+
+
+#include "sinfo_utl_cube2spectrum.h"
+#include "sinfo_functions.h"
+#include "sinfo_spectrum_ops.h"
+#include "sinfo_key_names.h"
+#include "sinfo_pro_save.h"
+#include "sinfo_utilities_scired.h"
+#include "sinfo_globals.h"
+#include "sinfo_error.h"
+#include "sinfo_utils_wrappers.h"
+/*----------------------------------------------------------------------------
+                            Functions prototypes
+ ----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+                            Static variables
+ ----------------------------------------------------------------------------*/
+
+static int
+sinfo_change_header(const char * name);
+/**@{*/
+/**
+ * @addtogroup sinfo_utl_cube2spectrum Cube to spectrum trasformation
+ *
+ * TBD
+ */
+
+/*-----------------------------------------------------------------------------
+                            Function implementation
+ ----------------------------------------------------------------------------*/
+
+static int
+sinfo_change_header(const char * name) {
+  int cenpix=0;
+  double cenLambda=0;
+  double dispersion=0;
+  cpl_propertylist* plist=NULL;
+
+  plist=cpl_propertylist_load(name,0);
+  cenpix = sinfo_pfits_get_crpix3(plist);
+  cenLambda = sinfo_pfits_get_crval3(plist);
+  dispersion = sinfo_pfits_get_cdelt3(plist);
+
+  
+  check(cpl_propertylist_set_string(plist,"CTYPE2","WAVE"),"Setting CTYPE2");
+  check_nomsg(cpl_propertylist_set_comment(plist,"CTYPE2",
+					   "wavelength axis in microns"));
+
+  check(cpl_propertylist_set_double(plist,"CRPIX2",(double)cenpix),
+	"Setting CRPIX2");
+  check_nomsg(cpl_propertylist_set_comment(plist,"CRPIX2","Reference pixel"));
+ 
+  check(cpl_propertylist_set_double(plist,"CRVAL2",cenLambda),
+	"Setting CRVAL2");
+  check_nomsg(cpl_propertylist_set_comment(plist,"CRVAL2",
+					   "central wavelength"));
+
+  check(cpl_propertylist_set_double(plist,"CDELT2",dispersion),
+	"Setting CDELT2");
+  check_nomsg(cpl_propertylist_set_comment(plist,"CDELT2",
+					   "microns per pixel"));
+
+  check(cpl_propertylist_set_string(plist,"CUNIT2","um"),"Setting CUNIT2"); 
+  check_nomsg(cpl_propertylist_set_comment(plist,"CUNIT2","spectral unit")); 
+
+  check(cpl_propertylist_set_string(plist,"CTYPE1","ONESPEC"),
+	"Setting CTYPE1");
+  check_nomsg(cpl_propertylist_set_comment(plist,"CTYPE1",
+					   "one spectrum in y-direction"));
+
+  if(cpl_propertylist_has(plist,"CRPIX1")==1) {
+    check(cpl_propertylist_erase_regexp(plist, "CRPIX1",0),"Erasing CRPIX1");
+  }
+
+  if(cpl_propertylist_has(plist,"CRVAL1")==1) {
+    check(cpl_propertylist_erase_regexp(plist, "CRVAL1",0),"Erasing CRVAL1");
+  }
+
+  if(cpl_propertylist_has(plist,"CDELT1")==1) {
+    check(cpl_propertylist_erase_regexp(plist, "CDELT1",0),"Erasing CDELT1");
+  }
+
+
+  if(cpl_propertylist_has(plist,"CUNIT1")==1) {
+    check(cpl_propertylist_erase_regexp(plist, "CUNIT1",0),"Erasing CUNIT1");
+  }
+
+
+  if(cpl_propertylist_has(plist,"CTYPE3")==1) {
+    check(cpl_propertylist_erase_regexp(plist, "CTYPE3",0),"Erasing CTYPE3");
+  }
+
+
+  if(cpl_propertylist_has(plist,"CRPIX3")==1) {
+    check(cpl_propertylist_erase_regexp(plist, "CRPIX3",0),"Erasing CRPIX3");
+  }
+
+  if(cpl_propertylist_has(plist,"CRVAL3")==1) {
+    check(cpl_propertylist_erase_regexp(plist, "CRVAL3",0),"Erasing CRVAL3");
+  }
+
+  if(cpl_propertylist_has(plist,"CDELT3")==1) {
+    check(cpl_propertylist_erase_regexp(plist, "CDELT3",0),"Erasing CDELT3");
+  }
+
+  if(cpl_propertylist_has(plist,"CUNIT3")==1) {
+    check(cpl_propertylist_erase_regexp(plist, "CUNIT3",0),"Erasing CUNIT3");
+  }
+
+
+  if(cpl_propertylist_has(plist,"CD1_1")==1) {
+    check(cpl_propertylist_erase_regexp(plist, "CD1_1",0),"Erasing CD1_1");
+  }
+
+
+  if(cpl_propertylist_has(plist,"CD1_2")==1) {
+    check(cpl_propertylist_erase_regexp(plist, "CD1_2",0),"Erasing CD1_2");
+  }
+
+  if(cpl_propertylist_has(plist,"CD2_1")==1) {
+    check(cpl_propertylist_erase_regexp(plist, "CD2_1",0),"Erasing CD2_1");
+  }
+
+  if(cpl_propertylist_has(plist,"CD2_2")==1) {
+    check(cpl_propertylist_erase_regexp(plist, "CD2_2",0),"Erasing CD2_2");
+  }
+
+ cleanup:
+  sinfo_free_propertylist(&plist);
+
+   /* Return */
+    if (cpl_error_get_code()) 
+        return -1 ;
+    else 
+        return 0 ;
+
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Get the command line options and execute the data reduction
+  @param    parlist     the parameters list
+  @param    framelist   the frames list
+  @param    tag         frame tag
+  @return   0 if everything is ok
+ */
+/*---------------------------------------------------------------------------*/
+int sinfo_utl_cube2spectrum(
+        cpl_parameterlist   *   parlist, 
+        cpl_frameset        *   framelist,
+         const char* tag)
+{
+    cpl_parameter       *   param =NULL;
+    const char          *   operation =NULL;
+    const char          *   aperture =NULL;
+    char  name_i [MAX_NAME_SIZE];
+    int                    llx=0;
+    int                    urx=0;
+    int                    lly=0;
+    int                    ury=0;
+    int                    lo_rej=0;
+    int                    hi_rej=0;
+    int                    centerx=0;
+    int                    centery=0;
+    int                    radius=0;
+    int                    clx=0;
+    int                    cly=0;
+    
+    double                 disp=0;
+    double                 cpix=0;
+    double                 clam=0;
+
+    cpl_frame           *   frm_cub=NULL;
+
+    char ima_o[MAX_NAME_SIZE];
+    char tbl_o[MAX_NAME_SIZE];
+    char tag_i[MAX_NAME_SIZE];
+    char tag_o[MAX_NAME_SIZE];
+    cpl_propertylist    *   plist =NULL;
+    cpl_image           *   image =NULL;
+    cpl_frame           *   product_frame=NULL;
+
+    cpl_image * im_spec=NULL;
+    cpl_table * tbl_spec=NULL;
+    cpl_image * img=NULL;
+    cpl_imagelist  * cube=NULL;
+    Vector * spec=NULL;
+    /*fits_header* head=NULL; */
+
+     /* HOW TO RETRIEVE INPUT PARAMETERS */
+    /* --stropt */
+    check_nomsg(param=cpl_parameterlist_find(parlist, 
+                                         "sinfoni.sinfo_utl_cube2spectrum.op"));
+    check_nomsg(operation=cpl_parameter_get_string(param));
+ 
+    /* --stropt */
+    check_nomsg(param=cpl_parameterlist_find(parlist, 
+                                         "sinfoni.sinfo_utl_cube2spectrum.ap"));
+    check_nomsg(aperture=cpl_parameter_get_string(param));
+     /* --stropt */
+
+ 
+    if (tag == NULL) {
+      strcpy(ima_o,"out_spec_ima.fits");
+      strcpy(tbl_o,"out_spec_tbl.fits");
+      strcpy(tag_i,SI_UTL_CUBE2SPECTRUM_CUBE);
+      strcpy(tag_o,SI_UTL_CUBE2SPECTRUM_PROIMA);
+    } else {
+      snprintf(ima_o,MAX_NAME_SIZE-1,"%s%s",tag,"_spec_ima.fits");
+      snprintf(tbl_o,MAX_NAME_SIZE-1,"%s%s",tag,"_spec_tbl.fits");
+      snprintf(tag_o,MAX_NAME_SIZE-1,"%s%s",tag,"_SPCT");
+      strcpy(tag_i,  tag);
+    }
+ 
+
+    /* --intopt */
+    check_nomsg(param=cpl_parameterlist_find(parlist,
+                                    "sinfoni.sinfo_utl_cube2spectrum.llx"));
+    check_nomsg(llx=cpl_parameter_get_int(param));
+
+    /* --intopt */
+    check_nomsg(param=cpl_parameterlist_find(parlist,
+                                    "sinfoni.sinfo_utl_cube2spectrum.lly"));
+    check_nomsg(lly=cpl_parameter_get_int(param));
+
+    /* --intopt */
+    check_nomsg(param=cpl_parameterlist_find(parlist,
+                                    "sinfoni.sinfo_utl_cube2spectrum.urx"));
+    check_nomsg(urx=cpl_parameter_get_int(param));
+
+    /* --intopt */
+    check_nomsg(param=cpl_parameterlist_find(parlist,
+                                    "sinfoni.sinfo_utl_cube2spectrum.ury"));
+    check_nomsg(ury=cpl_parameter_get_int(param));
+
+    /* --intopt */
+    check_nomsg(param=cpl_parameterlist_find(parlist,
+                                  "sinfoni.sinfo_utl_cube2spectrum.lo_rej"));
+    check_nomsg(lo_rej=cpl_parameter_get_int(param));
+
+    /* --intopt */
+    check_nomsg(param=cpl_parameterlist_find(parlist,
+                                  "sinfoni.sinfo_utl_cube2spectrum.hi_rej"));
+    check_nomsg(hi_rej=cpl_parameter_get_int(param));
+
+    /* --intopt */
+    check_nomsg(param=cpl_parameterlist_find(parlist,
+                                  "sinfoni.sinfo_utl_cube2spectrum.centerx"));
+    check_nomsg(centerx=cpl_parameter_get_int(param));
+
+    /* --intopt */
+    check_nomsg(param=cpl_parameterlist_find(parlist,
+                                  "sinfoni.sinfo_utl_cube2spectrum.centery"));
+    check_nomsg(centery=cpl_parameter_get_int(param));
+
+    /* --intopt */
+    check_nomsg(param=cpl_parameterlist_find(parlist,
+                                  "sinfoni.sinfo_utl_cube2spectrum.radius"));
+    check_nomsg(radius=cpl_parameter_get_int(param));
+  
+    /* Identify the RAW and CALIB frames in the input frameset */
+    if (sinfo_dfs_set_groups(framelist)) {
+        sinfo_msg_error( "Cannot identify RAW and CALIB frames") ;
+        goto cleanup;
+    }
+
+    /* HOW TO ACCESS INPUT DATA */
+    cknull(frm_cub=cpl_frameset_find(framelist,tag_i),
+      "SOF does not have a file tagged as %s",tag_i);
+   
+    /* Now performing the data reduction */
+    /* Let's generate one image for the example */
+    check_nomsg(strcpy(name_i,cpl_frame_get_filename(frm_cub)));
+    check_nomsg(cube = cpl_imagelist_load((char*)name_i,CPL_TYPE_FLOAT,0));
+
+    check_nomsg(img=cpl_imagelist_get(cube,0));
+    check_nomsg(clx=cpl_image_get_size_x(img));
+    check_nomsg(cly=cpl_image_get_size_y(img));
+    check(plist=cpl_propertylist_load(name_i,0),
+      "Cannot read the FITS header") ;
+
+    cpix = (double) sinfo_pfits_get_crpix3(plist);
+    clam = (double) sinfo_pfits_get_crval3(plist);
+    disp = (double) sinfo_pfits_get_cdelt3(plist);
+    sinfo_free_propertylist(&plist);
+    if(strcmp(aperture,"rectangle") ==0) {
+      if (llx<0) {
+        sinfo_msg_warning("llx=%d too low set it to 0",llx);
+        llx=0;
+      }   
+      if (lly<0) {
+        sinfo_msg_warning("lly=%d too low set it to 0",lly);
+        lly=0;
+      }   
+      if (urx>clx-1) {
+        sinfo_msg_warning("urx=%d too large set it to %d",urx,clx-1);
+        urx=clx-1;
+      }   
+      if (ury>cly-1) {
+        sinfo_msg_warning("ury=%d too large set it to %d",ury,cly-1);
+        ury=cly-1;
+      }   
+      if(llx>=urx) {
+        sinfo_msg_error("llx>=urx!");
+        goto cleanup;
+      }
+      if(lly>=ury) {
+        sinfo_msg_error("lly>=ury!");
+        goto cleanup;
+      }
+
+    } 
+
+    if(strcmp(aperture,"circle") ==0) {
+      if((centerx-radius) < 0) {
+    sinfo_msg_error("It is not possible to set centerx-radius<0.");
+        goto cleanup;
+      }
+
+      if((centery-radius) < 0) {
+    sinfo_msg_error("It is not possible to set centery-radius<0.");
+        goto cleanup;
+      }
+
+      if((centerx+radius) >= clx) {
+    sinfo_msg_error("It is not possible to set centerx+radius >= cube x sixe");
+        goto cleanup;
+      }
+
+      if((centery+radius) >= cly) {
+    sinfo_msg_error("It is not possible to set centery+radius >= cube y size.");
+        goto cleanup;
+      }
+
+      if((radius) < 0) {
+    sinfo_msg_error("It is not possible to set radius<0.");
+        goto cleanup;
+      }
+
+    }
+
+    if(strcmp(operation,"average") ==0) {
+       if (strcmp(aperture,"rectangle") ==0) {
+          spec = sinfo_new_mean_rectangle_of_cube_spectra(cube,llx,lly,urx,ury);
+       } else if (strcmp(aperture,"circle")==0) {
+          spec = sinfo_new_mean_circle_of_cube_spectra(cube,centerx,
+                                                       centery,radius);
+       } else {
+          sinfo_msg_error("Aperture not supported");
+          sinfo_msg("Supported apertures are only:");
+          sinfo_msg("rectangle, circle:");
+        goto cleanup;
+       }
+    } else if (strcmp(operation,"clean_mean") ==0) {
+      if (strcmp(aperture,"rectangle") == 0) {
+          spec = sinfo_new_clean_mean_rectangle_of_cube_spectra(cube,llx,lly,
+                                                                urx,ury,
+                                                                lo_rej,hi_rej);
+      } else if (strcmp(aperture,"circle")==0) {
+          spec = sinfo_new_clean_mean_circle_of_cube_spectra(cube,centerx,
+                                                             centery,radius,
+                                                             lo_rej,hi_rej); 
+      } else {
+          sinfo_msg_error("Aperture not supported");
+          sinfo_msg("Supported apertures are only:");
+          sinfo_msg("rectangle, circle:");
+          goto cleanup;
+      }
+    } else if (strcmp(operation,"median") ==0) {
+       if (strcmp(aperture,"rectangle")==0) {
+          spec = sinfo_new_median_rectangle_of_cube_spectra(cube,llx,lly,
+                                                            urx,ury);
+       } else if (strcmp(aperture,"circle")==0) {
+          spec = sinfo_new_median_circle_of_cube_spectra(cube,centerx,
+                                                         centery,radius);
+       } else {
+          sinfo_msg_error("Aperture not supported");
+          sinfo_msg("Supported apertures are only:");
+          sinfo_msg("rectangle, circle:");
+          goto cleanup;
+       }
+    } else if (strcmp(operation,"sum") ==0) {
+       if (strcmp(aperture,"rectangle")==0) {
+          spec = sinfo_new_sum_rectangle_of_cube_spectra(cube,llx,lly,urx,ury);
+       } else if (strcmp(aperture,"circle")==0) {
+          spec = sinfo_new_sum_circle_of_cube_spectra(cube,centerx,
+                                                      centery,radius);
+       } else {
+          sinfo_msg_error("Aperture not supported");
+          sinfo_msg("Supported apertures are only:");
+          sinfo_msg("rectangle, circle:");
+          goto cleanup;
+       }
+    } else if (strcmp(operation,"extract") == 0) {
+       if (strcmp(aperture,"rectangle")==0) {
+      spec = sinfo_new_median_rectangle_of_cube_spectra(cube,llx,lly,
+                                                            urx,ury); 
+       } else if (strcmp(aperture,"circle")==0) {
+     spec = sinfo_new_median_circle_of_cube_spectra(cube,centerx,
+                                                        centery,radius);
+       } else {
+          sinfo_msg_error("Aperture not supported");
+          sinfo_msg("Supported apertures are only:");
+          sinfo_msg("rectangle, circle:");
+          goto cleanup;
+       }
+    } else {
+      sinfo_msg_error("Operation not supported");
+      sinfo_msg("Supported operations are only:");
+      sinfo_msg("average, clean_mean, median, sum, extract :");
+      goto cleanup;
+    }
+    im_spec = sinfo_new_vector_to_image(spec);
+    /* head = sinfo_fits_read_header((char*)name_i); */
+    sinfo_msg("name_i=%s",name_i);
+    ck0_nomsg(sinfo_change_header(name_i));
+
+    /* HOW TO SAVE A PRODUCT ON DISK  */
+    /* Set the file name */
+ 
+    /* Create product frame */
+    ck0(sinfo_pro_save_ima(im_spec,framelist,framelist,ima_o,
+               tag_o,NULL,cpl_func,parlist),"failed to save ima");
+
+
+    sinfo_new_set_wcs_spectrum (im_spec,ima_o,clam, disp, cpix);
+
+    sinfo_stectrum_ima2table(im_spec,ima_o,&tbl_spec);
+     ck0(sinfo_pro_save_tbl(tbl_spec,framelist,framelist,tbl_o,
+               tag_o,NULL,cpl_func,parlist),
+                           "failed to save spectrum");
+
+ cleanup:
+    sinfo_free_propertylist(&plist) ;
+    sinfo_free_frame(&product_frame) ;
+    sinfo_free_image(&image) ;
+    sinfo_free_imagelist(&cube);
+    sinfo_free_image(&im_spec);
+    /* This generate seg fault
+    if(spec != NULL) sinfo_free_svector(&spec);
+    */
+    sinfo_free_table(&tbl_spec);
+    /*if(head != NULL) sinfo_fits_header_destroy(head); */
+ 
+    /* Return */
+    if (cpl_error_get_code()) 
+        return -1 ;
+    else 
+        return 0 ;
+
+
+}
+/**@}*/
diff --git a/sinfoni/sinfo_utl_cube2spectrum.h b/sinfoni/sinfo_utl_cube2spectrum.h
new file mode 100644
index 0000000..966ac6f
--- /dev/null
+++ b/sinfoni/sinfo_utl_cube2spectrum.h
@@ -0,0 +1,44 @@
+/* $Id: sinfo_utl_cube2spectrum.h,v 1.1 2006/10/22 14:12:28 amodigli Exp $
+ *
+ * This file is part of the IIINSTRUMENT Pipeline
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2006/10/22 14:12:28 $
+ * $Revision: 1.1 $
+ * $Name: sinfo-2_3_2 $
+ */
+/*-----------------------------------------------------------------------------
+                                Includes
+-----------------------------------------------------------------------------*/
+#ifndef SINFO_UTL_CUBE2SPECTRUM_H
+#define SINFO_UTL_CUBE2SPECTRUM_H
+
+#include <cpl.h>
+#include "sinfo_tpl_utils.h"
+#include "sinfo_pfits.h"
+#include "sinfo_tpl_dfs.h"
+/*-----------------------------------------------------------------------------
+                            Functions prototypes
+-----------------------------------------------------------------------------*/
+
+int sinfo_utl_cube2spectrum(cpl_parameterlist *, cpl_frameset *, const char*) ;
+
+#endif
+
diff --git a/sinfoni/sinfo_utl_cube_arith.c b/sinfoni/sinfo_utl_cube_arith.c
new file mode 100644
index 0000000..efee5b2
--- /dev/null
+++ b/sinfoni/sinfo_utl_cube_arith.c
@@ -0,0 +1,331 @@
+/* $Id: sinfo_utl_cube_arith.c,v 1.14 2012/03/03 10:17:31 amodigli Exp $
+ *
+ * This file is part of the IIINSTRUMENT Pipeline
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2012/03/03 10:17:31 $
+ * $Revision: 1.14 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+/*----------------------------------------------------------------------------
+                                Includes
+ ----------------------------------------------------------------------------*/
+
+#include "sinfo_utl_cube_arith.h"
+#include <sinfo_spectrum_ops.h>
+#include <sinfo_new_cube_ops.h>
+#include "sinfo_key_names.h"
+#include "sinfo_pro_types.h"
+#include <sinfo_error.h>
+#include <sinfo_utilities.h>
+#include <sinfo_utils_wrappers.h>
+
+
+
+/*-----------------------------------------------------------------------------
+                            Functions prototypes
+ ----------------------------------------------------------------------------*/
+/*-----------------------------------------------------------------------------
+                            Static variables
+ ----------------------------------------------------------------------------*/
+
+/**@{*/
+/**
+ * @addtogroup sinfo_utl_cube_arith Cube arithmetics
+ *
+ * TBD
+ */
+
+/*-----------------------------------------------------------------------------
+                                Functions code
+ ----------------------------------------------------------------------------*/
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Get the command line options and execute the data reduction
+  @param    parlist     the parameters list
+  @param    framelist   the frames list
+  @return   0 if everything is ok
+ */
+/*---------------------------------------------------------------------------*/
+int sinfo_utl_cube_arith(
+   cpl_parameterlist   *   parlist, 
+   cpl_frameset        *   framelist)
+{
+   cpl_parameter       *   param =NULL;
+   const char          *   operation =NULL;
+   const char          *   name_c =NULL;
+   const char          *   name_s =NULL;
+   const char          *   name_o =NULL;
+   const char          *   name_d ="start";
+
+   /* double                  temp=0 ; */
+   double                  value=0 ;
+   double                  def_value=0 ;
+
+   cpl_parameter *         p=NULL;
+   cpl_frame           *   frm_cube=NULL ;
+   cpl_frame           *   frm_spct=NULL ;
+
+   cpl_propertylist    *   plist=NULL ;
+   cpl_image           *   image=NULL ;
+   cpl_frame           *   product_frame=NULL;
+   cpl_imagelist       *   cub_ims=NULL;
+   cpl_imagelist * cube_i=NULL;
+   cpl_imagelist * cube_o=NULL;
+   cpl_imagelist * cube_d=NULL;
+   cpl_image * std_star=NULL;
+   Vector * bb=NULL;
+   Vector*   spectrum=NULL;
+   cpl_vector* vec=NULL;
+   /* Identify the RAW and CALIB frames in the input frameset */
+   check(sinfo_dfs_set_groups(framelist),
+         "Cannot identify RAW and CALIB frames") ;
+
+ 
+   /* HOW TO RETRIEVE INPUT PARAMETERS */
+   /* --stropt */
+   check_nomsg(param = cpl_parameterlist_find(parlist, 
+                                              "sinfoni.sinfo_utl_cube_arith.op"));
+   check_nomsg(operation = cpl_parameter_get_string(param));
+   name_o = "out_cube.fits";
+
+
+   /* --doubleopt */
+   check_nomsg(param = cpl_parameterlist_find(parlist,
+                                              "sinfoni.sinfo_utl_cube_arith.value"));
+   check_nomsg(value = cpl_parameter_get_double(param));
+
+   /* HOW TO ACCESS INPUT DATA */
+   check(frm_cube = cpl_frameset_find(framelist, SI_UTL_CUBE_ARITH_CUBE),
+         "SOF does not have a file tagged as %s",SI_UTL_CUBE_ARITH_CUBE);
+    
+   check_nomsg(name_c = cpl_frame_get_filename(frm_cube));
+   check_nomsg(p = cpl_parameterlist_find(parlist, 
+                                          "sinfoni.sinfo_utl_cube_arith.value"));
+   check_nomsg(def_value = cpl_parameter_get_default_double(p));
+   if (value == def_value) {
+      if ((frm_spct = cpl_frameset_find(framelist, 
+                                        SI_UTL_CUBE_ARITH_SPECTRUM))==NULL) {
+         sinfo_msg( "SOF does not have a file tagged as %s",
+                    SI_UTL_CUBE_ARITH_SPECTRUM);
+         cpl_error_reset();
+      } else {
+         sinfo_msg( "SOF contains a file tagged as %s",
+                    SI_UTL_CUBE_ARITH_SPECTRUM);
+         name_s = cpl_frame_get_filename(frm_spct);
+         name_d = "spectrum";
+      }
+   }
+
+   if (value == def_value) {
+      if ((frm_spct = cpl_frameset_find(framelist, PRO_SPECTRUM))!=NULL) {
+         sinfo_msg( "SOF contains a file tagged as %s",PRO_SPECTRUM);
+         name_s = cpl_frame_get_filename(frm_spct);
+         name_d = "spectrum";
+      } else if ((frm_spct = cpl_frameset_find(framelist, PRO_IMA))!=NULL) {
+         sinfo_msg( "SOF contains a file tagged as %s",PRO_IMA);
+         name_s = cpl_frame_get_filename(frm_spct);
+         name_d = "image";
+      } else {
+         sinfo_msg( "SOF does not contains a file tagged as %s nor as %s",
+		    PRO_SPECTRUM,PRO_IMA);
+         sinfo_msg( "Assume operation by a constant");
+         cpl_error_reset();
+      }
+   }
+   check(plist=cpl_propertylist_load(cpl_frame_get_filename(frm_cube),0),
+         "Cannot read the FITS header") ;
+     
+
+   /* Now performing the data reduction */
+   /* Let's generate one image for the example */
+   check_nomsg(cube_i= cpl_imagelist_load((char*)name_c,CPL_TYPE_FLOAT,0));
+   if (value == def_value) {
+      sinfo_msg("value equal to default");
+      if( strcmp(name_d,"spectrum") == 0 ) {
+         sinfo_msg("Operation by spectrum");
+         sinfo_msg("loading spectrum image file %s",name_s);
+         check_nomsg(std_star=cpl_image_load((char*)name_s,CPL_TYPE_FLOAT,0,0));
+
+         //check_nomsg(std_star=sinfo_vector_to_image(vec,CPL_TYPE_FLOAT));
+         check_nomsg(spectrum  = sinfo_new_image_to_vector(std_star));
+         if (strcmp(operation,"/") == 0) {
+            cube_o = sinfo_new_div_cube_by_spectrum (cube_i, spectrum);
+         } else if (strcmp(operation,"-") == 0) {
+            cube_o = sinfo_new_sub_spectrum_from_cube(cube_i, spectrum);
+         } else if (strcmp(operation,"+") == 0) {
+            cube_o = sinfo_new_add_spectrum_to_cube(cube_i, spectrum);
+         } else if (strcmp(operation,"*") == 0) {
+            cube_o = sinfo_new_mul_spectrum_to_cube(cube_i, spectrum);
+            /*
+              } else if (strcmp(operation,"calib") == 0) {
+              bb = sinfo_new_blackbody_spectrum ((char*)name_s, temp); 
+              cube_d   = sinfo_new_div_cube_by_Spectrum (cube_i, spectrum);
+              cube_o = sinfo_new_mul_spectrum_to_cube(cube_d, bb); 
+            */
+      
+         } else {
+            sinfo_msg_error("operation %s not supported",operation);
+            sinfo_msg("If an input spectrum is given and no value is set");
+            sinfo_msg("operations supported are: `/`,`-`,`+`,'*'");
+            goto cleanup;
+         }
+         if (strcmp(operation,"calib") == 0) {
+            goto cleanup;
+         }
+      } else if ( strcmp(name_d,"image") == 0) {
+         sinfo_msg("Operation by image");
+         check_nomsg(std_star=cpl_image_load ((char*)name_s,
+                                              CPL_TYPE_FLOAT,0,0));
+         if(strcmp(operation,"+") == 0) {
+            cknull(cube_o = sinfo_new_add_image_to_cube(cube_i,std_star),
+                   "operation %s failed",operation);
+         } else if (strcmp(operation,"-") == 0) {
+            cknull(cube_o = sinfo_new_sub_image_from_cube(cube_i,std_star),
+                   "operation %s failed",operation);
+         } else if (strcmp(operation,"*") == 0) {
+            cknull(cube_o = sinfo_new_mul_image_to_cube(cube_i,std_star),
+                   "operation %s failed",operation);
+         } else if (strcmp(operation,"/") == 0) {
+            cknull(cube_o = sinfo_new_div_cube_by_image(cube_i,std_star),
+                   "operation %s failed",operation);
+         } else {
+            sinfo_msg_error("operation %s not supported",operation);
+            sinfo_msg("If an input image is set");
+            sinfo_msg("operations supported are: `-`, `+`, `*`, `/`");
+            goto cleanup;
+         }
+      } else {
+         sinfo_msg("Operation %s by constant",operation);
+
+         check_nomsg(cube_o = cpl_imagelist_duplicate(cube_i));
+
+         if(strcmp(operation,"+") == 0) {
+            check(cpl_imagelist_add_scalar(cube_o,value),
+                  "operation %s failed",operation);
+         } else if (strcmp(operation,"-") == 0) {
+            check(cpl_imagelist_subtract_scalar(cube_o,value),
+                  "operation %s failed",operation);
+         } else if (strcmp(operation,"*") == 0) {
+            check(cpl_imagelist_multiply_scalar(cube_o,value),
+                  "operation %s failed",operation);
+         } else if (strcmp(operation,"/") == 0) {
+            check(cpl_imagelist_divide_scalar(cube_o,value),
+                  "operation %s failed",operation);
+         } else {
+            sinfo_msg_error("operation %s not supported",operation);
+            sinfo_msg("If an input value is set");
+            sinfo_msg("operations supported are: `-`, `+`, `*`, `/`");
+            goto cleanup;
+         }
+
+      } /* env case op by constant && value == default */
+
+   } else {
+
+      sinfo_msg("Operation %s by constant",operation);
+
+      check_nomsg(cube_o = cpl_imagelist_duplicate(cube_i));
+
+      if(strcmp(operation,"+") == 0) {
+         check(cpl_imagelist_add_scalar(cube_o,value),
+               "operation %s failed",operation);
+      } else if (strcmp(operation,"-") == 0) {
+         check(cpl_imagelist_subtract_scalar(cube_o,value),
+               "operation %s failed",operation);
+      } else if (strcmp(operation,"*") == 0) {
+         check(cpl_imagelist_multiply_scalar(cube_o,value),
+               "operation %s failed",operation);
+      } else if (strcmp(operation,"/") == 0) {
+         check(cpl_imagelist_divide_scalar(cube_o,value),
+               "operation %s failed",operation);
+      } else {
+         sinfo_msg_error("operation %s not supported",operation);
+         sinfo_msg("If an input value is set");
+         sinfo_msg("operations supported are: `-`, `+`, `*`, `/`");
+         goto cleanup;
+      }
+
+   }
+   /* HOW TO SAVE A PRODUCT ON DISK  */
+   /* Set the file name */
+   /* Create product frame */
+   check_nomsg(product_frame = cpl_frame_new());
+   check_nomsg(cpl_frame_set_filename(product_frame, name_o)) ;
+   check_nomsg(cpl_frame_set_tag(product_frame, SI_UTL_CUBE_ARITH_PROCUBE)) ;
+   check_nomsg(cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_IMAGE)) ;
+   check_nomsg(cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT)) ;
+   check(cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL),
+           "Error while initialising the product frame") ;
+ /* Add DataFlow keywords */
+   check_nomsg(cpl_propertylist_erase_regexp(plist, "^ESO PRO CATG",0));
+
+#if defined CPL_VERSION_CODE && CPL_VERSION_CODE >= CPL_VERSION(4, 8, 0)  
+   check(cpl_dfs_setup_product_header(plist, product_frame, framelist, 
+                                      parlist,
+                                      "si_sinfo_utl_cube_arith", 
+                                      "SINFONI", KEY_VALUE_HPRO_DID,NULL),
+         "Problem in the product DFS-compliance") ;
+#else
+   check(cpl_dfs_setup_product_header(plist, product_frame, framelist, 
+                                      parlist,
+                                      "si_sinfo_utl_cube_arith", 
+                                      "SINFONI", KEY_VALUE_HPRO_DID),
+         "Problem in the product DFS-compliance") ;
+#endif
+
+  /* Save the file */
+   check(cpl_imagelist_save(cube_o, name_o, CPL_BPP_IEEE_FLOAT, plist,
+                            CPL_IO_DEFAULT),
+         "Could not save product");
+ 
+
+   /* Log the saved file in the input frameset */
+   check_nomsg(cpl_frameset_insert(framelist, product_frame)) ;
+
+
+
+  cleanup:
+   sinfoni_free_vector(&vec);
+   sinfo_free_svector(&spectrum);
+   sinfo_free_svector(&bb);
+
+   sinfo_free_imagelist(&cube_d);
+   sinfo_free_imagelist(&cube_i);
+   sinfo_free_imagelist(&cube_o);
+   //If I free the next image I get core dump!
+   //sinfo_free_image(&std_star);
+   sinfo_free_image(&image);
+   sinfo_free_imagelist(&cub_ims);
+   sinfo_free_propertylist(&plist);
+    
+    /* Return */
+   if (cpl_error_get_code()) 
+      return -1 ;
+   else 
+      return 0 ;
+}
+/**@}*/
diff --git a/sinfoni/sinfo_utl_cube_arith.h b/sinfoni/sinfo_utl_cube_arith.h
new file mode 100644
index 0000000..a241655
--- /dev/null
+++ b/sinfoni/sinfo_utl_cube_arith.h
@@ -0,0 +1,43 @@
+/* $Id: sinfo_utl_cube_arith.h,v 1.1 2006/10/22 14:12:28 amodigli Exp $
+ *
+ * This file is part of the IIINSTRUMENT Pipeline
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2006/10/22 14:12:28 $
+ * $Revision: 1.1 $
+ * $Name: sinfo-2_3_2 $
+ */
+/*-----------------------------------------------------------------------------
+                                Includes
+ -----------------------------------------------------------------------------*/
+#ifndef SINFO_UTL_CUBE_ARITH_H
+#define SINFO_UTL_CUBE_ARITH_H
+
+#include <cpl.h>
+#include "sinfo_tpl_utils.h"
+#include "sinfo_pfits.h"
+#include "sinfo_tpl_dfs.h"
+/*-----------------------------------------------------------------------------
+                            Functions prototypes
+-----------------------------------------------------------------------------*/
+
+int sinfo_utl_cube_arith(cpl_parameterlist *, cpl_frameset *) ;
+
+#endif
diff --git a/sinfoni/sinfo_utl_cube_combine.c b/sinfoni/sinfo_utl_cube_combine.c
new file mode 100644
index 0000000..482c1d6
--- /dev/null
+++ b/sinfoni/sinfo_utl_cube_combine.c
@@ -0,0 +1,381 @@
+/* $Id: sinfo_utl_cube_combine.c,v 1.20 2012/03/03 10:17:31 amodigli Exp $
+ *
+ * This file is part of the IIINSTRUMENT Pipeline
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2012/03/03 10:17:31 $
+ * $Revision: 1.20 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+/*----------------------------------------------------------------------------
+                                Includes
+ ---------------------------------------------------------------------------*/
+
+#include "sinfo_utl_cube_combine.h"
+#include "sinfo_utilities.h"
+#include "sinfo_utilities_scired.h"
+#include <stdio.h>
+#include "sinfo_key_names.h"
+#include "sinfo_error.h"
+#include "sinfo_utils_wrappers.h"
+#include "sinfo_pro_save.h"
+/*-----------------------------------------------------------------------------
+                            Functions prototypes
+ ----------------------------------------------------------------------------*/
+
+
+/*-----------------------------------------------------------------------------
+                            Static variables
+ ----------------------------------------------------------------------------*/
+
+
+/*-----------------------------------------------------------------------------
+                                Functions code
+ ----------------------------------------------------------------------------*/
+/**@{*/
+/**
+ * @addtogroup sinfo_utl_cube_combine Utility to combine cubes
+ *
+ * TBD
+ */
+
+
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Get the command line options and execute the data reduction
+  @param    parlist     the parameters list
+  @param    framelist   the frames list
+  @return   0 if everything is ok
+ */
+/*---------------------------------------------------------------------------*/
+int sinfo_utl_cube_combine(
+        cpl_parameterlist   *   parlist, 
+        cpl_frameset        *   framelist)
+{
+    cpl_parameter       *   param=NULL ;
+    const char                *   name_o=NULL ;
+    const char                *   name_i=NULL ;
+    const char                *   name_m=NULL ;
+   
+    cpl_propertylist    *   plist=NULL ;
+    cpl_image           *   image=NULL ;
+    cpl_frame           *   product_frame=NULL;
+    cpl_frame           *   prod_frm=NULL;
+    cpl_frame           *   frame=NULL;
+  
+    int z=0;
+    int z_min=0;
+    int z_max=0;
+    int z_siz=0;
+    int z_stp=100;
+    int xsize=0;
+    int ysize=0;
+    int scales_sky=0;
+
+    int i=0;
+    int j=0;
+    int n=0;
+
+    int size_x=0;
+    int size_y=0;
+    cpl_image* j_img=NULL;
+    cpl_image* m_img=NULL;
+ 
+    cpl_imagelist ** cube_object=NULL;
+    cpl_imagelist * cube_jitter=NULL;
+    cpl_imagelist * cube_mask=NULL;
+ 
+    const char**    files=NULL;
+    int nframes=0;
+
+    double * times=NULL;
+    float * offsetx=NULL;
+    float * offsety=NULL;
+    float  ref_offx=0;
+    float  ref_offy=0;
+    float tmpoffx=0;
+    float tmpoffy=0;
+    double kappa=2;
+    int ks_clip=0;
+    int min_size_x=9999;
+    int min_size_y=9999;
+    const char* name=NULL;
+
+ 
+    FILE* file_list=NULL;
+    int cnt=0;
+    int onp=0;
+  
+    /* HOW TO RETRIEVE INPUT PARAMETERS */
+    /* --stropt */
+    check_nomsg(param = cpl_parameterlist_find(parlist, 
+                        "sinfoni.sinfo_utl_cube_combine.ks_clip"));
+    check_nomsg(ks_clip = cpl_parameter_get_bool(param));
+
+    check_nomsg(param = cpl_parameterlist_find(parlist, 
+                        "sinfoni.sinfo_utl_cube_combine.scale_sky"));
+    check_nomsg(scales_sky = cpl_parameter_get_bool(param));
+
+
+    check_nomsg(param = cpl_parameterlist_find(parlist, 
+                        "sinfoni.sinfo_utl_cube_combine.kappa"));
+    check_nomsg(kappa = cpl_parameter_get_double(param));
+
+    check_nomsg(param = cpl_parameterlist_find(parlist, 
+                        "sinfoni.sinfo_utl_cube_combine.name_i"));
+    check_nomsg(name_i = cpl_parameter_get_string(param));
+
+    check_nomsg(param = cpl_parameterlist_find(parlist, 
+                        "sinfoni.sinfo_utl_cube_combine.name_o"));
+    check_nomsg(name_o = cpl_parameter_get_string(param));
+
+
+    /* --doubleopt */
+    check_nomsg(param = cpl_parameterlist_find(parlist,
+                        "sinfoni.sinfo_utl_cube_combine.xsize"));
+    check_nomsg(xsize = cpl_parameter_get_int(param));
+
+    check_nomsg(param = cpl_parameterlist_find(parlist,
+                        "sinfoni.sinfo_utl_cube_combine.ysize"));
+    check_nomsg(ysize = cpl_parameter_get_int(param));
+
+  
+  /* Identify the RAW and CALIB frames in the input frameset */
+    check(sinfo_dfs_set_groups(framelist),
+         "Cannot identify RAW and CALIB frames") ;
+ 
+
+    /* HOW TO ACCESS INPUT DATA */
+    n=cpl_frameset_get_size(framelist);
+    if(n<1) {
+      sinfo_msg_error("Empty input frame list!");
+      goto cleanup ;
+    }
+    for (i=0;i<n;i++) {
+       frame=cpl_frameset_get_frame(framelist,i);
+       cpl_frame_set_group(frame,CPL_FRAME_GROUP_RAW);
+    }
+
+   
+
+    /* Now performing the data reduction */
+    /* Let's generate one image for the example */
+    
+    if ( NULL == (file_list = fopen (name_i, "r" ) ) )
+    {      
+      sinfo_msg_error("cannot open %s\n", name_i) ;
+      goto cleanup ;
+    }
+ 
+    cnt = 0 ;
+    while ( fscanf( file_list, "%f %f",&tmpoffx, &tmpoffy) != EOF )
+    {
+      cnt ++ ;
+    }
+    fclose(file_list);
+   
+    nframes= cnt ;
+    cknull(times = (double*) cpl_calloc (nframes, sizeof (double)), 
+           " could not allocate memory!") ;
+ 
+    cknull(offsetx = (float*) cpl_calloc (nframes, sizeof(float)),
+           " could not allocate memory!") ;
+
+    cknull(offsety = (float*) cpl_calloc (nframes, sizeof(float)),
+           " could not allocate memory!") ;
+  
+    files = (const char**) cpl_calloc(MAX_NAME_SIZE,sizeof(const char*));
+    if ( NULL == (file_list = fopen (name_i, "r" ) ) )
+    {
+      sinfo_msg_error("cannot open %s\n", name_i) ;
+      return -1 ;
+    }
+
+
+    cnt=0;   
+    while ( fscanf( file_list, "%f %f",&tmpoffx,&tmpoffy ) != EOF ) {
+      frame=cpl_frameset_get_frame(framelist,cnt);
+      files[cnt]= cpl_frame_get_filename(frame);
+      times[cnt]=sinfo_pfits_get_exptime(files[cnt]);
+      offsetx[cnt]=tmpoffx;
+      offsety[cnt]=tmpoffy;
+      plist=cpl_propertylist_load(files[cnt],0);
+      size_x=sinfo_pfits_get_naxis1(plist);
+      size_y=sinfo_pfits_get_naxis2(plist);
+      sinfo_free_propertylist(&plist);
+      if(size_x < min_size_x) min_size_x=size_x;
+      if(size_y < min_size_y) min_size_y=size_y;
+      cnt ++ ;
+    }
+    sinfo_msg("Min input cube size x=%d y=%d",min_size_x,min_size_y);
+ 
+    nframes=cnt;
+    fclose(file_list);
+ 
+    ck0(sinfo_auto_size_cube(offsetx,offsety,nframes,
+                              &ref_offx,&ref_offy,&size_x,&size_y),
+         "Error resizing cube");
+    sinfo_msg("output ima size=%dx%d",size_x,size_y); 
+    cknull(cube_object = cpl_calloc(nframes,sizeof(cpl_imagelist*)),
+       "could not allocate memory") ;
+ 
+    for (i=0;i<nframes;i++) {
+      frame=cpl_frameset_get_frame(framelist,i);
+      name=cpl_frame_get_filename(frame);
+      check_nomsg(cube_object[i]=cpl_imagelist_load(name,CPL_TYPE_FLOAT,0));
+      ck0(sinfo_new_assign_offset2(i,name,offsetx,offsety,
+                                  ref_offx,ref_offy),
+                                  "Error assigning offsets");
+    }
+    onp = cpl_imagelist_get_size(cube_object[0]);
+
+
+    check(cube_jitter = cpl_imagelist_new(),"allocating new data cube object");
+    check(cube_mask = cpl_imagelist_new(),"allocating new data cube mask");
+
+    check(plist=cpl_propertylist_load(files[0],0),
+      "Cannot read the FITS header") ;
+
+   if(scales_sky == 1) {
+      sinfo_msg("Subtract spatial sinfo_median to each cube plane");
+      for(n=0;n<nframes;n++) {
+    sinfo_msg("process cube %d\n",n);
+    sinfo_new_sinfoni_correct_median_it(&(cube_object[n]));
+      }
+    }
+
+   for(z=0;z<onp;z+=z_stp) {
+     z_siz=(z_stp < (onp-z)) ? z_stp : (onp-z);
+     z_min=z;
+     z_max=z_min+z_siz;
+     sinfo_msg("Coadding cubes: range [%4.4d,%4.4d) of 0-%d\n",
+	       z_min,z_max,onp);
+
+     for(j=z_min;j<z_max;j++) {
+
+       check_nomsg(j_img=cpl_image_new(size_x,size_y,CPL_TYPE_FLOAT));
+       check_nomsg(cpl_imagelist_set(cube_jitter,j_img,j));
+       check_nomsg(m_img = cpl_image_new(size_x,size_y,CPL_TYPE_FLOAT));
+       check_nomsg(cpl_imagelist_set(cube_mask,m_img,j));
+     }
+     if(ks_clip == 1){
+       sinfo_new_combine_jittered_cubes_thomas_range(cube_object,
+						     cube_jitter,
+						     cube_mask,
+						     nframes,
+						     offsetx,offsety,
+						     times,
+						     (char*) "tanh",
+						     z_min,
+						     z_max,
+						     kappa);
+     } else {
+       sinfo_new_combine_jittered_cubes_range(cube_object, 
+					      cube_jitter,
+					      cube_mask,
+					      nframes,
+					      offsetx,
+					      offsety,
+					      times,
+					      (char*) "tanh",
+					      z_min,
+					      z_max) ;
+     }
+      
+   }
+   sinfo_new_convert_0_to_ZERO_for_cubes(cube_jitter) ; 
+ 
+    name_m="out_cube_mask.fits";
+     /* HOW TO SAVE A PRODUCT ON DISK  */
+
+    /* Create product frame */
+    check_nomsg(product_frame = cpl_frame_new());
+    check_nomsg(cpl_frame_set_filename(product_frame, name_o)) ;
+    check_nomsg(cpl_frame_set_tag(product_frame, SI_UTL_CUBE_COMBINE_PROCUBE));
+    check_nomsg(cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_IMAGE)) ;
+    check_nomsg(cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT)) ;
+    check_nomsg(cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL)) ;
+      
+    /* Add DataFlow keywords */
+#if defined CPL_VERSION_CODE && CPL_VERSION_CODE >= CPL_VERSION(4, 8, 0)  
+    check(cpl_dfs_setup_product_header(plist, product_frame, 
+                                       framelist, parlist,
+                                       "sinfo_utl_cube_combine", 
+                                       "SINFONI", KEY_VALUE_HPRO_DID,NULL),
+      "Problem in the product DFS-compliance") ;
+#else
+    check(cpl_dfs_setup_product_header(plist, product_frame, 
+                                       framelist, parlist,
+                                       "sinfo_utl_cube_combine",
+                                       "SINFONI", KEY_VALUE_HPRO_DID),
+      "Problem in the product DFS-compliance") ;
+#endif    
+    check(cpl_imagelist_save(cube_jitter, name_o, CPL_BPP_IEEE_FLOAT, plist,
+                 CPL_IO_DEFAULT),"Could not save product");
+    check_nomsg(cpl_frameset_insert(framelist, product_frame));
+    
+   
+    check_nomsg(prod_frm = cpl_frame_new());
+    check_nomsg(cpl_frame_set_filename(prod_frm, name_m)) ;
+    check_nomsg(cpl_frame_set_tag(prod_frm, SI_UTL_CUBE_COMBINE_PROMASK)) ;
+    check_nomsg(cpl_frame_set_type(prod_frm, CPL_FRAME_TYPE_IMAGE)) ;
+    check_nomsg(cpl_frame_set_group(prod_frm, CPL_FRAME_GROUP_PRODUCT)) ;
+    check_nomsg(cpl_frame_set_level(prod_frm, CPL_FRAME_LEVEL_FINAL)) ;
+
+    check(cpl_imagelist_save(cube_mask, name_m, CPL_BPP_IEEE_FLOAT, plist,
+                 CPL_IO_DEFAULT),"Could not save product");
+    check_nomsg(cpl_frameset_insert(framelist, prod_frm));
+    
+ cleanup:
+    sinfo_free_imagelist(&cube_jitter) ;
+    sinfo_free_image(&image) ;
+    sinfo_free_imagelist(&cube_mask) ;
+
+
+    if(cube_object != NULL) {
+      for (i=0;i< nframes;i++){
+    sinfo_free_imagelist(&(cube_object[i]));      
+      }
+      sinfo_free_array_imagelist(&cube_object);
+    }
+    sinfo_free_propertylist(&plist);
+    if(files != NULL) {
+      cpl_free(files);
+      files=NULL;
+    }
+    sinfo_free_double(&times);
+    sinfo_free_float(&offsetx);
+    sinfo_free_float(&offsety);
+ 
+    /* Return */
+    if (cpl_error_get_code()) {
+        return -1 ;
+    }
+    else { 
+        return 0 ;
+    }
+}
+/**@}*/
diff --git a/sinfoni/sinfo_utl_cube_combine.h b/sinfoni/sinfo_utl_cube_combine.h
new file mode 100644
index 0000000..1dc0f5a
--- /dev/null
+++ b/sinfoni/sinfo_utl_cube_combine.h
@@ -0,0 +1,43 @@
+/* $Id: sinfo_utl_cube_combine.h,v 1.1 2006/10/22 14:12:28 amodigli Exp $
+ *
+ * This file is part of the IIINSTRUMENT Pipeline
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2006/10/22 14:12:28 $
+ * $Revision: 1.1 $
+ * $Name: sinfo-2_3_2 $
+ */
+/*-----------------------------------------------------------------------------
+                                Includes
+ -----------------------------------------------------------------------------*/
+#ifndef SINFO_UTL_CUBE_COMBINE_H
+#define SINFO_UTL_CUBE_COMBINE_H
+
+#include <cpl.h>
+#include "sinfo_tpl_utils.h"
+#include "sinfo_pfits.h"
+#include "sinfo_tpl_dfs.h"
+
+/*-----------------------------------------------------------------------------
+                            Functions prototypes
+-----------------------------------------------------------------------------*/
+int sinfo_utl_cube_combine(cpl_parameterlist *, cpl_frameset *) ;
+
+#endif
diff --git a/sinfoni/sinfo_utl_efficiency.c b/sinfoni/sinfo_utl_efficiency.c
new file mode 100644
index 0000000..0a08ce7
--- /dev/null
+++ b/sinfoni/sinfo_utl_efficiency.c
@@ -0,0 +1,734 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004-2009 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*
+ * $Author: amodigli $
+ * $Date: 2012/03/03 10:17:31 $
+ * $Revision: 1.17 $
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <string.h>
+#include <math.h>
+#include <cpl.h>
+/* irplib */
+#include <irplib_utils.h>
+
+#include <sinfo_pfits.h>
+#include <sinfo_msg.h>
+#include <sinfo_dfs.h>
+#include <sinfo_error.h>
+#include <sinfo_utils_wrappers.h>
+#include "sinfo_utl_efficiency.h"
+#include <sinfo_star_index.h>
+
+#define PRO_STD_STAR_SPECTRA "STD_STAR_SPECTRA"
+static const char COL_NAME_WAVELENGTH[] = "WAVELENGTH";
+static const char COL_NAME_WAVELENGTH_C[] = "WAVELENGTH";
+static const char COL_NAME_LAMBDA[] 	= "LAMBDA";
+static const char COL_NAME_LA_SILLA[]	= "LA_SILLA";
+static const char COL_NAME_REF[]		= "REF";
+static const char COL_NAME_COR[]		= "COR";
+static const char COL_NAME_SRC_COR[]	= "SRC_COR";
+static const char COL_NAME_COUNTS_BKG[]	= "INT_OBJ";//"counts_tot";
+static const char COL_NAME_FLUX[]		= "FLUX";
+static const char COL_NAME_EPHOT[]		= "EPHOT";
+static const char COL_NAME_EXT[]		= "EXT";
+static const char COL_NAME_SRC_EFF[]	= "EFF";
+static const char PAR_NAME_DIT[]		= "ESO DET DIT";
+
+static char FRM_RAW_IMA_SLIT[]	= PRO_STD_STAR_SPECTRA;
+static char FRM_FLUX_STD_TAB[]	= FLUX_STD_TABLE;
+static char FRM_FLUX_STD_CAT[]	= FLUX_STD_CATALOG;
+static char FRM_EXTCOEFF_TAB[]	= EXTCOEFF_TABLE;
+
+static int 
+sinfo_column_to_double(cpl_table* ptable, const char* column);
+
+static double 
+sinfo_table_interpolate(cpl_table* tbl,
+		  double wav,
+		  const char* colx,
+		  const char* coly);
+static double* 
+sinfo_create_column_double(cpl_table* tbl, const char* col_name, int nrow);
+
+
+
+cpl_error_code
+sinfo_get_std_obs_values(cpl_propertylist* plist,
+                       double* exptime,
+                       double* airmass,
+                       double* dRA,
+                       double* dDEC);
+
+/*--------------------------------------------------------------------------*/
+
+/**@{*/
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    load reference table
+
+  @param    frames    input frames list
+  @param    dRA       Right Ascension
+  @param    dDEC      Declination
+  @param    EPSILON   tolerance to find ref spectra on catalog on (ra,dec)
+  @param    ptable    pointer to new table
+  @return   Interpolated data points
+ */
+/*---------------------------------------------------------------------------*/
+
+void 
+sinfo_load_ref_table(cpl_frameset* frames, 
+                   double dRA, 
+                   double dDEC, 
+                   double EPSILON, 
+                   cpl_table** pptable)
+{
+  const char* name = NULL;
+  cpl_frame* frm_ref = NULL;
+
+  /* REF STD frame */
+  frm_ref=cpl_frameset_find(frames,FRM_FLUX_STD_TAB);
+  if (!frm_ref)
+    {
+      sinfo_msg("REF frame is not found, trying to get REF from the catalog");
+     /* REF STD catalog frame */
+      // get from catalog
+      check_nomsg(frm_ref=cpl_frameset_find(frames,FRM_FLUX_STD_CAT));
+      if (frm_ref)
+	{
+	  check_nomsg(name=cpl_frame_get_filename(frm_ref));
+	  if (name)
+	    {
+	      star_index* pstarindex = star_index_load(name);
+	      if (pstarindex)
+		{
+		  const char* star_name = 0;
+		  sinfo_msg("The catalog is loaded, looking for star in RA[%f] DEC[%f] tolerance[%f]", dRA, dDEC, EPSILON);
+		  *pptable = star_index_get(pstarindex, dRA, dDEC, EPSILON, EPSILON, &star_name);
+		  if (*pptable && star_name)
+		    {
+		      sinfo_msg("REF table is found in the catalog, star name is [%s]", star_name);
+		    }
+		  else
+		    {
+		      sinfo_msg("ERROR - REF table could not be found in the catalog");
+		    }
+		}
+	      else
+		{
+		  sinfo_msg("ERROR - could not load the catalog");
+		}
+	    }
+	}
+    }
+  else
+    {
+      sinfo_msg("REF frame is found");
+      check_nomsg(name=cpl_frame_get_filename(frm_ref));
+      check_nomsg(*pptable=cpl_table_load(name,1,0));
+    }
+  return;
+ cleanup:
+  return;
+}
+
+
+
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    load reference table
+
+  @param    cat        input frame catalog
+  @param    dRA        Right Ascension
+  @param    dDEC       Declination
+  @param    EPSILON    tolerance to find ref spectra on catalog on (ra,dec)
+  @param    ptable     pointer to new table
+  @return   Interpolated data points
+ */
+/*---------------------------------------------------------------------------*/
+
+static void 
+sinfo_parse_catalog_std_stars(cpl_frame* cat, 
+			    double dRA, 
+			    double dDEC, 
+			    double EPSILON, 
+			    cpl_table** pptable)
+{
+  const char* name = NULL;
+
+  if (cat) {
+    check_nomsg(name=cpl_frame_get_filename(cat));
+    if (name) {
+      star_index* pstarindex = star_index_load(name);
+      if (pstarindex) {
+	const char* star_name = 0;
+	sinfo_msg("The catalog is loaded, looking for star in RA[%f] DEC[%f] tolerance[%f]", dRA, dDEC, EPSILON);
+	*pptable = star_index_get(pstarindex, dRA, dDEC, EPSILON, EPSILON, &star_name);
+	if (*pptable && star_name) {
+	  sinfo_msg("REF table is found in the catalog, star name is [%s]", star_name);
+	}
+	else {
+	  sinfo_msg("ERROR - REF table could not be found in the catalog");
+	}
+      }
+      else {
+	sinfo_msg("ERROR - could not load the catalog");
+      }
+
+    }
+  }
+
+ cleanup:
+  return;
+}
+
+
+
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Interpolate efficiency data points
+  @param    wav       wavelength
+     number of table raws
+  @param    pw        pointer to wave array
+  @param    pe        pointer to efficiency array
+  @return   Interpolated data points
+ */
+/*---------------------------------------------------------------------------*/
+
+
+double
+sinfo_data_interpolate(
+		     double wav,
+		     int nrow,
+		     double* pw,
+		     double* pe
+		     )
+{
+  double y = 0;
+  double w1=pw[0];
+  double w2=pw[nrow-1];
+  double y1_=pe[0]; /*was changed from y1 to y1_ due a warning from compiler - shadowed variable*/
+  double y2=pe[nrow-1];
+  if(wav < pw[0])
+    {
+      w1=pw[0];
+      w2=pw[1];
+      y1_=pe[0];
+      y2=pe[1];
+    }
+  else if (wav > pw[nrow - 1])
+    {
+      w1=pw[nrow - 2];
+      w2=pw[nrow - 1];
+      y1_=pe[nrow - 2];
+      y2=pe[nrow - 1];
+    }
+  else
+    {
+      int l = 0;
+      int h = nrow - 1;
+      int curr_row = 0;
+      curr_row = (h-l) / 2;
+      while( h-l >1 )
+	{
+	  if(wav < pw[curr_row])
+	    {
+	      h = curr_row;
+	    }
+	  else
+	    {
+	      l = curr_row;
+	    }
+	  curr_row = (h-l) / 2 + l;
+	}
+      w1=pw[curr_row];
+      w2=pw[curr_row + 1];
+      y1_=pe[curr_row];
+      y2=pe[curr_row + 1];
+    }
+  y=y1_+(y2-y1_)/(w2-w1)*(wav-w1);
+  return y;
+}
+static double
+sinfo_table_interpolate(cpl_table* tbl,
+		  double wav,
+		  const char* colx,
+		  const char* coly)
+{
+
+  double y=0;
+  double* pe=NULL;
+  double* pw=NULL;
+  int nrow=0;
+
+  check_nomsg(pw=cpl_table_get_data_double(tbl,colx));
+  check_nomsg(pe=cpl_table_get_data_double(tbl,coly));
+  check_nomsg(nrow=cpl_table_get_nrow(tbl));
+
+  y = sinfo_data_interpolate(wav, nrow, pw, pe);
+ cleanup:
+  return y;
+
+}
+
+static double* 
+sinfo_create_column_double(cpl_table* tbl, const char* col_name, int nrow)
+{
+  double* retval = 0;
+  check_nomsg(cpl_table_new_column(tbl, col_name, CPL_TYPE_DOUBLE));
+  check_nomsg(cpl_table_fill_column_window_double(tbl, col_name, 0, nrow, -1));
+  check_nomsg(retval = cpl_table_get_data_double(tbl,col_name));
+  return retval;
+ cleanup:
+  return retval;
+}
+
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    get STD star observation exptime, airmass, RA, DEC
+  @param    plist    (input) property list
+  @param    exptime  (output) exposure time
+  @param    airmass  (output) airmass (average of start and end)
+  @param    dRA      (output) Right Ascension
+  @param    dDEC     (output) Declination
+  @return   CPL error code
+ */
+/*---------------------------------------------------------------------------*/
+
+cpl_error_code
+sinfo_get_std_obs_values(cpl_propertylist* plist,
+                       double* exptime,
+                       double* airmass,
+                       double* dRA,
+                       double* dDEC)
+{
+   double airmass_start=0;
+   double airmass_end=0;
+
+   check_nomsg(*exptime=sinfo_pfits_get_exp_time(plist));
+   airmass_start=sinfo_pfits_get_airmass_start(plist);
+   airmass_end=sinfo_pfits_get_airmass_end(plist);
+   *dRA=sinfo_pfits_get_ra(plist);
+   *dDEC=sinfo_pfits_get_dec(plist);
+   *airmass=0.5*(airmass_start+airmass_end);
+
+ cleanup:
+   return cpl_error_get_code();
+
+}
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief Compute efficiency
+  @param frames     input frameset
+  @param prod_name  the product name
+  @param dGain      detector's gain value
+  @param dEpsilon   tolerance to find ref spectra on catalog on (ra,dec)
+  @param airprim    airmass
+  @param col_name_atm_wave atmospheric extinction table wave column name
+  @param col_name_atm_abs  atmospheric extinction table absorption column name
+  @param col_name_ref_wave reference flux std table wave column name
+  @param col_name_ref_flux reference flux std table flux column name
+  @param col_name_obj_wave observed std table wave column name
+  @param col_name_obj_flux observed std table flux column name
+
+  @return   0 if everything is ok
+ */
+/*---------------------------------------------------------------------------*/
+
+cpl_table*
+sinfo_utl_efficiency(
+		     cpl_frameset * frames,
+		     double dGain,
+		     double dEpsilon,
+		     double aimprim,
+                     const char* col_name_atm_wave,
+		     const char* col_name_atm_abs,
+                     const char* col_name_ref_wave,
+                     const char* col_name_ref_flux,
+                     const char* col_name_ref_bin,
+                     const char* col_name_obj_wave,
+                     const char* col_name_obj_flux
+		     )
+{
+  cpl_frame* frm_sci = NULL;
+  cpl_frame* frm_atmext = NULL;
+  cpl_table* tbl_obj_spectrum = NULL; // input table with spectrum
+  cpl_table* tbl_atmext = NULL;
+  double exptime = 600;
+
+  cpl_propertylist* plist = NULL;
+  cpl_table* tbl_ref = NULL;
+  cpl_table* tbl_result=NULL;
+
+  const char* name=NULL;
+  double dRA = 0;
+  double dDEC = 0;
+
+  double airmass=0;
+  const double mk2AA=1E4; /* mkm/AA */
+
+
+  // read all input data and call the internal function
+  // read the input tables
+  // 1. observation
+  check_nomsg(frm_sci=cpl_frameset_find(frames, FRM_RAW_IMA_SLIT));
+  check_nomsg(name=cpl_frame_get_filename(frm_sci));
+  sinfo_msg("name=%s",name);
+  check_nomsg(tbl_obj_spectrum=cpl_table_load(name,1,0));
+  check_nomsg(plist=cpl_propertylist_load(name,0));
+
+  sinfo_get_std_obs_values(plist,&exptime,&airmass,&dRA,&dDEC);
+
+  // 2. reference table
+  sinfo_load_ref_table(frames, dRA, dDEC, dEpsilon, &tbl_ref);
+  if (tbl_ref)
+    {
+      // 3. atmext
+      check_nomsg(frm_atmext=cpl_frameset_find(frames,FRM_EXTCOEFF_TAB));
+      check_nomsg(name=cpl_frame_get_filename(frm_atmext));
+      check_nomsg(tbl_atmext=cpl_table_load(name,1,0));
+
+      tbl_result = sinfo_utl_efficiency_internal(
+						 tbl_obj_spectrum,
+						 tbl_atmext,
+						 tbl_ref,
+						 exptime,
+						 airmass,
+						 aimprim,
+						 dGain,
+                                                 1,
+                                                 mk2AA,//valid only for SINFONI
+                                                 col_name_atm_wave,
+                                                 col_name_atm_abs,
+                                                 col_name_ref_wave,
+                                                 col_name_ref_flux,
+                                                 col_name_ref_bin,
+                                                 col_name_obj_wave,
+                                                 col_name_obj_flux
+         );
+     }
+
+ cleanup:
+  sinfo_free_propertylist(&plist);
+  sinfo_free_table(&tbl_atmext);
+  sinfo_free_table(&tbl_obj_spectrum);
+  sinfo_free_table(&tbl_ref);
+  return tbl_result;
+}
+static int 
+sinfo_column_to_double(cpl_table* ptable, const char* column)
+{
+  const char* TEMP = "_temp_";
+  check_nomsg(cpl_table_duplicate_column(ptable, TEMP, ptable, column));
+  check_nomsg(cpl_table_erase_column(ptable, column));
+  check_nomsg(cpl_table_cast_column(ptable, TEMP, column, CPL_TYPE_DOUBLE));
+  check_nomsg(cpl_table_erase_column(ptable, TEMP ));
+  return 0;
+ cleanup:
+  sinfo_msg(" error column to double [%s]", column);
+  return -1;
+}
+
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief Compute efficiency
+  @param tbl_obj_spectrum     input object spectrum
+  @param tbl_atmext           input atmospheric extinction table
+  @param tbl_ref              input reference flux STD table
+  @param exptime              input exposure time
+  @param airprim              input airmass
+  @param gain                 input gain
+  @param src2ref_wave_sampling input cnversion factor to pass from src 2 ref units
+  @param airprim              input airmass
+
+  @param col_name_atm_wave atmospheric extinction table wave column name
+  @param col_name_atm_abs  atmospheric extinction table absorption column name
+  @param col_name_ref_wave reference flux std table wave column name
+  @param col_name_ref_flux reference flux std table flux column name
+  @param col_name_obj_wave observed std table wave column name
+  @param col_name_obj_flux observed std table flux column name
+
+  @return   0 if everything is ok
+ */
+/*---------------------------------------------------------------------------*/
+
+cpl_table* 
+sinfo_utl_efficiency_internal(
+			      cpl_table* tbl_obj_spectrum,
+			      cpl_table* tbl_atmext,
+			      cpl_table* tbl_ref,
+			      double exptime,
+			      double airmass,
+			      double aimprim,
+			      double gain,
+			      int    biny,
+                              double src2ref_wave_sampling,
+                              const char* col_name_atm_wave,
+                              const char* col_name_atm_abs,
+                              const char* col_name_ref_wave,
+                              const char* col_name_ref_flux,
+                              const char* col_name_ref_bin,
+                              const char* col_name_obj_wave,
+                              const char* col_name_obj_flux
+			      )
+{
+
+  const double TEL_AREA		= 51.2e4; /* collecting area in cm2 */
+  double cdelta1 = 0;
+  int i = 0;
+  cpl_table* tbl_sel = NULL;
+
+  /* structure of the input table
+   * col			type	description
+   * wavelength	double
+   * flux			double
+   * */
+  cpl_table* tbl_result = NULL; // output table
+
+  /*
+   * structure of the output table
+   * col			type	description
+   * wavelength	double
+   * EFF			double	efficiency in range 0-1
+   * */
+
+  double* pref = NULL;
+  double* pext = NULL;
+  double* pcor = NULL;
+  double* peph = NULL;
+
+  double* pw = NULL; // wavelength of the input table
+  double* pf = NULL; // flux of the input table
+  int nrow = 0;
+  double ref_bin_size=0;
+
+  nrow = cpl_table_get_nrow(tbl_obj_spectrum);
+  sinfo_msg("Starting efficiency calculation: exptime[%f] airmass[%f] nrow[%d]", 
+	  exptime, airmass, nrow);
+
+  //cpl_table_dump(tbl_obj_spectrum,0,3,stdout);
+  //sinfo_msg("col wave=%s col_flux=%s",col_name_obj_wave,col_name_obj_flux);
+
+  /* convert to double */
+  sinfo_column_to_double(tbl_obj_spectrum,col_name_obj_wave);
+  sinfo_column_to_double(tbl_obj_spectrum,col_name_obj_flux);
+
+  check_nomsg(sinfo_column_to_double(tbl_atmext,col_name_atm_wave ));
+  check_nomsg(sinfo_column_to_double(tbl_atmext,col_name_atm_abs ));
+  check_nomsg(sinfo_column_to_double(tbl_ref,col_name_ref_wave ));
+  check_nomsg(sinfo_column_to_double(tbl_ref,col_name_ref_flux ));
+  check_nomsg(sinfo_column_to_double(tbl_ref,col_name_ref_bin ));
+
+  /* get bin size of ref STD star spectrum */
+  ref_bin_size=cpl_table_get_double(tbl_ref,col_name_ref_bin,0,NULL);
+  sinfo_msg("ref_bin_size[AA]=%g",ref_bin_size);
+  /*
+  sinfo_msg("Unit conversion factor src/ref STD spectrum=%g",
+          src2ref_wave_sampling);
+  */
+
+  /* convert obj spectrum wave unit to the same of the reference one */
+  check_nomsg(cpl_table_multiply_scalar(tbl_obj_spectrum,col_name_obj_wave,
+                                 src2ref_wave_sampling));
+
+  check_nomsg(cpl_table_save(tbl_ref,NULL,NULL,"ref2.fits",CPL_IO_DEFAULT));
+  check_nomsg(cpl_table_save(tbl_atmext,NULL,NULL,"atm2.fits",CPL_IO_DEFAULT));
+  check_nomsg(cpl_table_save(tbl_obj_spectrum,NULL,NULL,"sci2.fits",CPL_IO_DEFAULT));
+  sinfo_msg("object 2 src std %g",src2ref_wave_sampling);
+  check_nomsg(pw=cpl_table_get_data_double(tbl_obj_spectrum,col_name_obj_wave));
+  check_nomsg(pf=cpl_table_get_data_double(tbl_obj_spectrum,col_name_obj_flux));
+
+  // prepare columns for the output data
+  check_nomsg(tbl_result=cpl_table_new(nrow));
+  check_nomsg(pref=sinfo_create_column_double(tbl_result, COL_NAME_REF, nrow));
+  check_nomsg(pext=sinfo_create_column_double(tbl_result, COL_NAME_EXT, nrow));
+  check_nomsg(pcor=sinfo_create_column_double(tbl_result, COL_NAME_COR, nrow));
+  check_nomsg(peph=sinfo_create_column_double(tbl_result, COL_NAME_EPHOT, nrow));
+  sinfo_msg("wave range: [%g,%g]",pw[0],pw[nrow-1]); 
+  sinfo_msg("src_bin_size[AA]=%g",pw[1] - pw[0]);
+  
+  cdelta1 = (pw[1] - pw[0]) / src2ref_wave_sampling ; /* we want the delta in original units. As we rescaled to AA we need to correct for this */
+  //sinfo_msg("nrow=%d cdelta1=%g",nrow,cdelta1);
+  for (i = 0; i < nrow; i++)
+    {
+      check_nomsg(pext[i] = sinfo_table_interpolate(tbl_atmext, pw[i],col_name_atm_wave, col_name_atm_abs));
+      check_nomsg(pref[i] = sinfo_table_interpolate(tbl_ref, pw[i], col_name_ref_wave,col_name_ref_flux));
+      pcor[i] = pow(10,(0.4*pext[i] * (aimprim - airmass)));
+      peph[i] = 1.e7*1.986e-19/(pw[i]*1e-4);
+      /* ph energy: 1.986*10^-19(J.ph^-1)/lam(um) ==> 
+         in as pw is expressed in Angstrom units we need to multiply by 10-4 
+       */
+      /*
+      if(i< 2) {
+         sinfo_msg("pw[i]=%g,pcor=%g peph=%g",pw[i],pcor[i],peph[i]);
+      }
+      */
+    }
+
+
+  /*
+  sinfo_msg("atm: %s, %s ref: %s, %s obj: %s, %s",
+          col_name_atm_wave,col_name_atm_abs,
+          col_name_ref_wave,col_name_ref_flux,
+          col_name_obj_wave,col_name_obj_flux);
+  */
+  check_nomsg(cpl_table_duplicate_column(tbl_result,COL_NAME_SRC_COR,
+				   tbl_obj_spectrum, col_name_obj_flux));
+  check_nomsg(cpl_table_duplicate_column(tbl_result,col_name_obj_wave,
+				   tbl_obj_spectrum,col_name_obj_wave));
+  /* correct for atmospheric extintion */
+  check_nomsg(cpl_table_multiply_columns(tbl_result,COL_NAME_SRC_COR,COL_NAME_COR));
+
+  /* correct object flux by binning: 
+      divides by binsize in ref_wave_sampling (usually AA): 
+     cdelt1[src_sampling]*src2ref_wave_sampling */
+  cpl_table_divide_scalar(tbl_result, COL_NAME_SRC_COR, src2ref_wave_sampling);
+
+  cpl_table_divide_scalar(tbl_result, COL_NAME_SRC_COR, cdelta1);
+  /* correct for spatial bin size */
+
+  cpl_table_divide_scalar(tbl_result,COL_NAME_SRC_COR,biny); 
+
+
+  /*correct ref std star flux by binning: 
+    divides by the bin size in ref_wave_sampling (usually AA) */
+  check_nomsg(cpl_table_divide_scalar(tbl_result,COL_NAME_REF,ref_bin_size));
+
+  check_nomsg(cpl_table_duplicate_column(tbl_result,COL_NAME_SRC_EFF,
+				   tbl_result,COL_NAME_SRC_COR));
+
+
+  /* correct for detector gain, exposure time, telescope area */
+  check_nomsg(cpl_table_multiply_scalar(tbl_result,COL_NAME_SRC_EFF,
+				  gain / (exptime * TEL_AREA)));
+
+  /* correct for photon energy */
+  check_nomsg(cpl_table_multiply_columns(tbl_result,COL_NAME_SRC_EFF,
+				   COL_NAME_EPHOT));
+
+
+  check_nomsg(cpl_table_divide_columns(tbl_result,COL_NAME_SRC_EFF,COL_NAME_REF));
+  /* apply factor 1.e16 as reference catalog has fluxes in units of 1e-16 */
+  check_nomsg(cpl_table_multiply_scalar(tbl_result,COL_NAME_SRC_EFF,1.e16));
+  //check_nomsg(cpl_table_save(tbl_result,NULL,NULL,"pippo.fits", CPL_IO_DEFAULT));
+  /* clean from outliers */
+  cpl_table_and_selected_double(tbl_result,COL_NAME_SRC_EFF,
+				CPL_GREATER_THAN,1.e-5);
+  cpl_table_and_selected_double(tbl_result,COL_NAME_SRC_EFF,
+				CPL_LESS_THAN,100.);
+  tbl_sel=cpl_table_extract_selected(tbl_result);
+  check_nomsg(cpl_table_save(tbl_result,NULL,NULL,"result9.fits",CPL_IO_DEFAULT));
+
+ cleanup:
+  sinfo_free_table(&tbl_result);
+  return tbl_sel;
+}
+
+
+cpl_table*
+sinfo_efficiency_compute(cpl_frame* frm_sci, 
+                       cpl_frame* frm_cat,
+                       cpl_frame* frm_atmext)
+
+{
+
+  cpl_propertylist* plist=NULL;
+
+  cpl_table* tbl_eff=NULL;
+  cpl_table* tbl_ref=NULL;
+  cpl_table* tbl_atmext=NULL;
+  cpl_table* tbl_sci=NULL;
+
+  double exptime=600;
+  double airmass=0;
+  double airmass_start=0;
+  double airmass_end=0;
+  double dRA=0;
+  double dDEC=0;
+  double gain=0;
+  double aimprim=0;
+  double dEpsilon=0.1;
+  double um2AA=1.e4;
+
+  int nrow=0;
+  int biny=1;
+
+  const char* name_sci=NULL;
+  const char* name_atm=NULL;
+
+  name_sci=cpl_frame_get_filename(frm_sci);
+  sinfo_msg("name_sci=%s",name_sci);     
+  check_nomsg(plist=cpl_propertylist_load(name_sci,0));
+  check_nomsg(tbl_sci=cpl_table_load(name_sci,1,0));
+  check_nomsg(dRA=sinfo_pfits_get_ra(plist));
+  dDEC=sinfo_pfits_get_dec(plist);
+  airmass_start=sinfo_pfits_get_airmass_end(plist);
+  airmass_end=sinfo_pfits_get_airmass_end(plist);
+  airmass=0.5*(airmass_start+airmass_end);
+  gain=2.42;
+  biny=1;
+  check_nomsg(exptime=sinfo_pfits_get_dit(plist));
+  sinfo_free_propertylist(&plist);
+  sinfo_msg("gain=%g airm=%g exptime=%g airmass=%g ra=%g dec=%g",
+          gain,airmass,exptime,airmass,dRA,dDEC);
+
+  sinfo_msg("table sci spectra=%s",name_sci);
+  nrow=cpl_table_get_nrow(tbl_sci);
+
+  check_nomsg(name_atm=cpl_frame_get_filename(frm_atmext));
+  check_nomsg(tbl_atmext=cpl_table_load(name_atm,1,0));
+ 
+  check_nomsg(sinfo_parse_catalog_std_stars(frm_cat,dRA,dDEC,dEpsilon,&tbl_ref));
+ 
+  if(tbl_ref == NULL) {
+    sinfo_msg_error("Provide std sar catalog frame");
+    return NULL;
+  //cpl_table_dump(tbl_ref,0,3,stdout);
+  }
+
+  check_nomsg(cpl_table_save(tbl_sci,NULL,NULL,"sci.fits",CPL_IO_DEFAULT));
+  check_nomsg(tbl_eff=sinfo_utl_efficiency_internal(tbl_sci,tbl_atmext,tbl_ref,
+                                                 exptime,airmass,aimprim,gain,
+                                                 biny,um2AA,
+                                                 "LAMBDA",
+                                                 "LA_SILLA",
+                                                 "LAMBDA",
+                                                 "F_LAMBDA",
+                                                 "BIN_WIDTH",
+                                                 "wavelength",
+                                                 "counts_bkg"));
+
+  cleanup:
+  sinfo_free_table(&tbl_ref);
+  sinfo_free_table(&tbl_atmext);
+  sinfo_free_propertylist(&plist);
+ 
+  return tbl_eff;
+
+}
+/**@}*/
diff --git a/sinfoni/sinfo_utl_efficiency.h b/sinfoni/sinfo_utl_efficiency.h
new file mode 100644
index 0000000..b17d3d3
--- /dev/null
+++ b/sinfoni/sinfo_utl_efficiency.h
@@ -0,0 +1,91 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004-2009 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*
+ * $Author: amodigli $
+ * $Date: 2010/02/08 07:18:21 $
+ * $Revision: 1.9 $
+ *
+ */
+
+#ifndef SINFO_UTL_EFFICIENCY_H_
+#define SINFO_UTL_EFFICIENCY_H_
+#include <cpl.h>
+
+
+void 
+sinfo_load_ref_table(cpl_frameset* frames, 
+                   double dRA, 
+                   double dDEC, 
+                   double EPSILON, 
+                   cpl_table** pptable);
+
+
+
+cpl_table*
+sinfo_utl_efficiency(
+		     cpl_frameset * frames,
+		     double dGain,
+		     double dEpsilon,
+		     double aimprim,
+                     const char* col_name_atm_wave,
+                     const char* col_name_atm_abs,
+                     const char* col_name_ref_wave,
+                     const char* col_name_ref_flux,
+                     const char* col_name_ref_bin,
+                     const char* col_name_obj_wave,
+                     const char* col_name_obj_flux
+   );
+
+cpl_table* 
+sinfo_utl_efficiency_internal(
+			      cpl_table* tbl_obj_spectrum,
+			      cpl_table* tbl_atmext,
+			      cpl_table* tbl_ref,
+			      double exptime,
+			      double airmass,
+			      double aimprim,
+			      double gain,
+			      int    biny,
+                              double src2ref_wave_sampling,
+                              const char* col_name_atm_wave,
+                              const char* col_name_atm_abs,
+                              const char* col_name_ref_wave,
+                              const char* col_name_ref_flux,
+                              const char* col_name_ref_bin,
+                              const char* col_name_obj_wave,
+                              const char* col_name_obj_flux
+   );
+
+double
+sinfo_data_interpolate(
+		     double wav,
+		     int nrow,
+		     double* pw,
+		     double* pe
+		     );
+
+
+
+cpl_table*
+sinfo_efficiency_compute(cpl_frame* frm_sci, 
+                       cpl_frame* frm_cat,
+                       cpl_frame* frm_atmext);
+
+
+#endif
diff --git a/sinfoni/sinfo_utl_spectrum_divide_by_blackbody.c b/sinfoni/sinfo_utl_spectrum_divide_by_blackbody.c
new file mode 100644
index 0000000..0bb5a6a
--- /dev/null
+++ b/sinfoni/sinfo_utl_spectrum_divide_by_blackbody.c
@@ -0,0 +1,161 @@
+/* $Id: sinfo_utl_spectrum_divide_by_blackbody.c,v 1.8 2012/03/03 10:17:31 amodigli Exp $
+ *
+ * This file is part of the IIINSTRUMENT Pipeline
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2012/03/03 10:17:31 $
+ * $Revision: 1.8 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+/*----------------------------------------------------------------------------
+                                Includes
+ ----------------------------------------------------------------------------*/
+
+#include <string.h>
+#include "sinfo_utl_spectrum_divide_by_blackbody.h"
+#include <sinfo_spectrum_ops.h>
+#include "sinfo_key_names.h"
+#include "sinfo_error.h"
+#include "sinfo_utils_wrappers.h"
+#include "sinfo_msg.h"
+/*----------------------------------------------------------------------------
+                            Functions prototypes
+ ----------------------------------------------------------------------------*/
+/*----------------------------------------------------------------------------
+                            Static variables
+ ----------------------------------------------------------------------------*/
+
+/**@{*/
+/**
+ * @addtogroup sinfo_utl_spectrum_divide_by_blackbody Utility to divide a \
+   spectrum by a black body
+ *
+ * TBD
+ */
+
+/*----------------------------------------------------------------------------
+                                Functions code
+ ----------------------------------------------------------------------------*/
+
+/*---------------------------------------------------------------------------*/
+/**
+  @brief    Get the command line options and execute the data reduction
+  @param    parlist     the parameters list
+  @param    framelist   the frames list
+  @return   0 if everything is ok
+ */
+/*---------------------------------------------------------------------------*/
+int sinfo_utl_spectrum_divide_by_blackbody(
+        cpl_parameterlist   *   parlist, 
+        cpl_frameset        *   framelist)
+{
+    cpl_parameter       *   param =NULL;
+    const char          *   name_i =NULL;
+    const char          *   name_o =NULL;
+
+    double                  temp=0 ;
+
+    cpl_frame           *   frm_spct=NULL ;
+
+    cpl_propertylist    *   plist=NULL ;
+
+
+    cpl_frame           *   product_frame=NULL;
+    cpl_image * bb_img=NULL;
+    cpl_image * image_o=NULL;
+    cpl_image * image_i=NULL;
+
+    Vector*   bb=NULL;
+    /* double * ker=NULL; */
+
+    /* HOW TO RETRIEVE INPUT PARAMETERS */
+    /* --stropt */
+    name_o = "out_ima.fits";
+
+    /* --doubleopt */
+
+    check_nomsg(param = cpl_parameterlist_find(parlist,
+                "sinfoni.sinfo_utl_spectrum_divide_by_blackbody.temperature"));
+    check_nomsg(temp = cpl_parameter_get_double(param));
+   
+    /* HOW TO ACCESS INPUT DATA */
+    check(frm_spct = cpl_frameset_find(framelist, 
+                    SI_UTL_SPECTRUM_DIVIDE_BY_BLACKBODY_SPECTRUM),
+                    "SOF does not have a file tagged as %s",
+                    SI_UTL_SPECTRUM_DIVIDE_BY_BLACKBODY_SPECTRUM);
+
+    check(plist=cpl_propertylist_load(cpl_frame_get_filename(frm_spct), 
+                        0),"Cannot read the FITS header") ;
+
+    /* Now performing the data reduction */
+    /* Let's generate one image for the example */
+    check_nomsg(name_i = cpl_frame_get_filename(frm_spct));
+    check_nomsg(image_i= cpl_image_load((char*)name_i, CPL_TYPE_FLOAT,0,0));  
+    cknull_nomsg(bb= sinfo_new_blackbody_spectrum ((char*)name_i, temp));
+    cknull_nomsg(bb_img = sinfo_new_vector_to_image(bb));
+    cknull_nomsg(image_o = sinfo_new_div_image_by_spectrum (image_i,bb_img));
+    
+    /* HOW TO SAVE A PRODUCT ON DISK  */
+    /* Set the file name */
+
+    /* Create product frame */
+    check_nomsg(product_frame = cpl_frame_new());
+    check_nomsg(cpl_frame_set_filename(product_frame, name_o)) ;
+    check_nomsg(cpl_frame_set_tag(product_frame, 
+                        SI_UTL_SPECTRUM_DIVIDE_BY_BLACKBODY_PROSPECTRUM));
+    check_nomsg(cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_IMAGE));
+    check_nomsg(cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT));
+    check_nomsg(cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL));
+
+    /* Add DataFlow keywords */
+       /*
+    check(cpl_dfs_setup_product_header(plist, product_frame, 
+                                             framelist, parlist,
+            "sinfo_utl_spectrum_divide_by_blackbody", "SINFONI", 
+                KEY_VALUE_HPRO_DID),"Problem in the product DFS-compliance") ;
+       */
+ 
+    /* Save the file */
+    check(cpl_image_save(image_o, name_o, CPL_BPP_IEEE_FLOAT, plist,
+                   CPL_IO_DEFAULT),"Could not save product");
+
+    /* Log the saved file in the input frameset */
+    check_nomsg(cpl_frameset_insert(framelist, product_frame));
+
+ cleanup:
+
+       sinfo_free_propertylist(&plist) ;
+       sinfo_free_image(&image_i);
+       sinfo_free_image(&image_o);
+       sinfo_free_image(&bb_img);
+     
+
+    /* Return */
+    if (cpl_error_get_code()) 
+        return -1 ;
+    else 
+        return 0 ;
+}
+/**@}*/
diff --git a/sinfoni/sinfo_utl_spectrum_divide_by_blackbody.h b/sinfoni/sinfo_utl_spectrum_divide_by_blackbody.h
new file mode 100644
index 0000000..74bf296
--- /dev/null
+++ b/sinfoni/sinfo_utl_spectrum_divide_by_blackbody.h
@@ -0,0 +1,46 @@
+/* $Id: sinfo_utl_spectrum_divide_by_blackbody.h,v 1.1 2006/10/22 14:12:28 amodigli Exp $
+ *
+ * This file is part of the IIINSTRUMENT Pipeline
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2006/10/22 14:12:28 $
+ * $Revision: 1.1 $
+ * $Name: sinfo-2_3_2 $
+ */
+/*-----------------------------------------------------------------------------
+                                Includes
+-----------------------------------------------------------------------------*/
+#ifndef SINFO_UTL_SPECTRUM_DIVIDE_BY_BLACKBODY_H
+#define SINFO_UTL_SPECTRUM_DIVIDE_BY_BLACKBODY_H
+
+#include <cpl.h>
+#include "sinfo_tpl_utils.h"
+#include "sinfo_pfits.h"
+#include "sinfo_tpl_dfs.h"
+
+
+/*-----------------------------------------------------------------------------
+                            Functions prototypes
+ ----------------------------------------------------------------------------*/
+
+int 
+sinfo_utl_spectrum_divide_by_blackbody(cpl_parameterlist *, cpl_frameset *) ;
+
+#endif
diff --git a/sinfoni/sinfo_utl_spectrum_wavelength_shift.c b/sinfoni/sinfo_utl_spectrum_wavelength_shift.c
new file mode 100644
index 0000000..6b4fb64
--- /dev/null
+++ b/sinfoni/sinfo_utl_spectrum_wavelength_shift.c
@@ -0,0 +1,189 @@
+/* $Id: sinfo_utl_spectrum_wavelength_shift.c,v 1.8 2012/03/03 10:17:31 amodigli Exp $
+ *
+ * This file is part of the IIINSTRUMENT Pipeline
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2012/03/03 10:17:31 $
+ * $Revision: 1.8 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+/*-----------------------------------------------------------------------------
+                                Includes
+ -----------------------------------------------------------------------------*/
+
+#include <string.h>
+
+#include "sinfo_utl_spectrum_wavelength_shift.h"
+#include "sinfo_spectrum_ops.h"
+#include "sinfo_shift_images.h"
+#include "sinfo_key_names.h"
+#include "sinfo_error.h"
+#include "sinfo_utils_wrappers.h"
+#include "sinfo_msg.h"
+/*-----------------------------------------------------------------------------
+                            Functions prototypes
+ -----------------------------------------------------------------------------*/
+/*-----------------------------------------------------------------------------
+                            Static variables
+ -----------------------------------------------------------------------------*/
+
+/**@{*/
+/**
+ * @addtogroup sinfo_utl_spectrum_wavelength_shift operations to shift a \
+   spectrum in wavelength
+ *
+ * TBD
+ */
+
+/*-----------------------------------------------------------------------------
+                                Functions code
+ -----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief    Get the command line options and execute the data reduction
+  @param    parlist     the parameters list
+  @param    framelist   the frames list
+  @return   0 if everything is ok
+ */
+/*----------------------------------------------------------------------------*/
+int sinfo_utl_spectrum_wavelength_shift(
+        cpl_parameterlist   *   parlist, 
+        cpl_frameset        *   framelist)
+{
+    cpl_parameter       *   param =NULL;
+    const char          *   method =NULL;
+    const char          *   name_i =NULL;
+    const char          *   name_o =NULL;
+
+    double                  shift=0 ;
+
+    cpl_frame           *   frm_spct=NULL ;
+
+    cpl_propertylist    *   plist=NULL ;
+
+    cpl_frame           *   product_frame=NULL;
+    cpl_image * image_o=NULL;
+    cpl_image * image_i=NULL;
+    cpl_image * image_s=NULL;
+
+    double* sub_shift=NULL;
+    /* double * ker=NULL; */
+
+    /* HOW TO RETRIEVE INPUT PARAMETERS */
+    /* --stropt */
+    name_o = "out_ima.fits";
+ 
+    /* --doubleopt */
+    check_nomsg(param = cpl_parameterlist_find(parlist, 
+                                  "sinfoni.sinfo_utl_spectrum_arith.method"));
+    check_nomsg(method = cpl_parameter_get_string(param));
+
+
+    check_nomsg(param = cpl_parameterlist_find(parlist,
+                         "sinfoni.sinfo_utl_spectrum_wavelength_shift.shift"));
+    check_nomsg(shift = cpl_parameter_get_double(param));
+  
+   
+    /* HOW TO ACCESS INPUT DATA */
+    check(frm_spct = cpl_frameset_find(framelist, 
+                                   SI_UTL_SPECTRUM_WAVELENGTH_SHIFT_SPECTRUM),
+                                   "SOF does not have a file tagged as %s",
+                                   SI_UTL_SPECTRUM_WAVELENGTH_SHIFT_SPECTRUM);
+
+    check(plist=cpl_propertylist_load(cpl_frame_get_filename(frm_spct), 
+                        0),"Cannot read the FITS header") ;
+   /* Now performing the data reduction */
+    /* Let's generate one image for the example */
+    check_nomsg(name_i = cpl_frame_get_filename(frm_spct));
+    check_nomsg(image_i= cpl_image_load ((char*)name_i,CPL_TYPE_FLOAT,0,0));  
+    sub_shift = sinfo_new_doublearray(1);
+    sinfo_new_doublearray_set_value(sub_shift, 0., 0);
+    cknull(image_s = sinfo_new_shift_image_in_spec (image_i, shift, sub_shift),
+         "error in sinfo_new_shift_image_in_spec()");
+
+    shift = sinfo_new_doublearray_get_value(sub_shift, 0);
+ 
+    if (strcmp(method,"S")==0) {
+
+       cknull(image_o = sinfo_new_fine_shift_image_in_spec_cubic_spline (
+                       image_s, shift ),
+                       "error in fine_shift_image_in_spec_cubic_spline()");
+
+       } else if (strcmp(method,"P")==0) {
+     cknull(image_o = sinfo_new_fine_shift_image_in_spec_poly(
+                            image_s,shift,2),
+                            "error in sinfo_fineShiftImageInSpecPoly()");
+      /*
+       } else if (strcmp (method, "T")==0) {
+      ker = sinfo_new_generate_interpolation_kernel("tanh");
+          cknull(image_o = sinfo_new_shift_image ( image_s, 0, shift, ker ),
+              "error in sinfo_new_fine_shift_image_in_spec_poly()");
+      */
+          /* sinfo_new_destroy_doublearray(ker); */
+       }  else {
+          sinfo_msg_error("wrong method %s",method);
+          goto cleanup;
+       }
+    
+    /* HOW TO SAVE A PRODUCT ON DISK  */
+    /* Set the file name */
+
+    /* Create product frame */
+    check_nomsg(product_frame = cpl_frame_new());
+    check_nomsg(cpl_frame_set_filename(product_frame, name_o)) ;
+    check_nomsg(cpl_frame_set_tag(product_frame, 
+                                SI_UTL_SPECTRUM_WAVELENGTH_SHIFT_PROSPECTRUM)) ;
+    check_nomsg(cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_IMAGE));
+    check_nomsg(cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT)) ;
+    check_nomsg(cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL)) ;
+
+    /* Add DataFlow keywords */
+    /*
+    check(cpl_dfs_setup_product_header(plist, product_frame, 
+                                      framelist, parlist,
+                                      "si_sinfo_utl_spectrum_wavelength_shift", 
+                                      "SINFONI", KEY_VALUE_HPRO_DID),
+        "Problem in the product DFS-compliance") ;
+    */
+   
+   
+    /* Save the file */
+    check(cpl_image_save(image_o, name_o, CPL_BPP_IEEE_FLOAT, plist,
+             CPL_IO_DEFAULT),"Could not save product");
+    check_nomsg(cpl_frameset_insert(framelist, product_frame));
+ cleanup:
+    sinfo_free_image(&image_i);
+    sinfo_free_image(&image_o);
+    sinfo_free_image(&image_s);
+    if(sub_shift != NULL) sinfo_new_destroy_doublearray(sub_shift);
+    sinfo_free_propertylist(&plist);
+
+    if (cpl_error_get_code()) 
+        return -1 ;
+    else 
+        return 0 ;
+}
+/**@}*/
diff --git a/sinfoni/sinfo_utl_spectrum_wavelength_shift.h b/sinfoni/sinfo_utl_spectrum_wavelength_shift.h
new file mode 100644
index 0000000..70019ef
--- /dev/null
+++ b/sinfoni/sinfo_utl_spectrum_wavelength_shift.h
@@ -0,0 +1,45 @@
+/* $Id: sinfo_utl_spectrum_wavelength_shift.h,v 1.1 2006/10/22 14:12:28 amodigli Exp $
+ *
+ * This file is part of the IIINSTRUMENT Pipeline
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2006/10/22 14:12:28 $
+ * $Revision: 1.1 $
+ * $Name: sinfo-2_3_2 $
+ */
+/*-----------------------------------------------------------------------------
+                                Includes
+ -----------------------------------------------------------------------------*/
+
+#ifndef SINFO_UTL_SPECTRUM_WAVELENGTH_SHIFT_H
+#define SINFO_UTL_SPECTRUM_WAVELENGTH_SHIFT_H
+
+#include <cpl.h>
+#include "sinfo_tpl_utils.h"
+#include "sinfo_pfits.h"
+#include "sinfo_tpl_dfs.h"
+
+/*-----------------------------------------------------------------------------
+                            Functions prototypes
+-----------------------------------------------------------------------------*/
+
+int sinfo_utl_spectrum_wavelength_shift(cpl_parameterlist *, cpl_frameset *) ;
+
+#endif
diff --git a/sinfoni/sinfo_vltPort.h b/sinfoni/sinfo_vltPort.h
new file mode 100644
index 0000000..22a7702
--- /dev/null
+++ b/sinfoni/sinfo_vltPort.h
@@ -0,0 +1,101 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*************************************************************************
+* E.S.O. - VLT project
+*
+* "@(#) $Id: sinfo_vltPort.h,v 1.3 2006/10/25 06:46:09 amodigli Exp $" 
+*
+* vltPort.h for Sun Solaris 2
+*
+* who        when      what
+* --------  --------  ----------------------------------------------
+* gfilippi  22/05/96  created form vltPort.h
+* gfilippi  23/05/96  define SUN_COMP added
+*
+*/
+
+/************************************************************************
+*  vltPort.h - Include file to mask differences between platforms.
+*              This file should be included in all source files.
+*              It relies on macro definitions preceeding the
+*              inclusion of this file.
+*                
+*  REMARK: This file belongs to the "vltMake" module.
+*------------------------------------------------------------------------
+*/
+
+#ifndef SINFO_VLTPORT_H
+#define SINFO_VLTPORT_H
+
+/*
+* When it is used, vltPort.h MUST be the very first file included
+* in ANSI ".c" files.
+* Cause a syntax error if we detect that any other include file has been
+* included before vltPort.h in an ANSI ".c" file.
+*/
+#if defined(__STDC__) && \
+                         (defined(_H_STANDARDS) || \
+                          defined(_SYS_STDSYMS_INCLUDED) || \
+                          defined(_STANDARDS_H_))
+#    error "vltPort.h MUST BE THE VERY FIRST FILE INCLUDED IN ANSI '.c' FILES"
+#endif
+
+/*
+ * This file is used also by some VxWorks code.
+ * To be compatible with existing code, SUN_COMP is defined for both
+ * gcc and cc68k, but the following definitiond do not influence cc68k
+ */
+ 
+#define SUN_COMP
+
+/* 
+ * at present, SELECT is defined in the code using it. It should be done here
+ * for all. May be in the next release.
+ */
+
+/*
+ * Adjust name-space information.
+ */
+#if defined(_ALL_SOURCE)
+#    undef _POSIX_C_SOURCE
+#endif
+
+#if defined(_XOPEN_SOURCE)
+#    undef _POSIX_C_SOURCE
+#endif
+
+#ifndef MAKE_VXWORKS
+#include <stddef.h>
+#include <sys/types.h>
+#include <sys/time.h>
+
+#if !defined(timercmp)
+/*
+AMO: 03/09/03 commented out for Linux
+    struct timeval
+        {
+        long      tv_sec;         
+        long      tv_usec;        
+        };
+*/
+#define crTIMEVAL_TIMEZONE_DEFINED
+#endif
+#endif /* MAKE_VXWORKS */
+
+#endif /*!SINFO_VLTPORT_H*/
diff --git a/sinfoni/sinfo_wave_calibration.c b/sinfoni/sinfo_wave_calibration.c
new file mode 100644
index 0000000..050612d
--- /dev/null
+++ b/sinfoni/sinfo_wave_calibration.c
@@ -0,0 +1,2919 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*************************************************************************
+* E.S.O. - VLT project
+*
+* 
+*
+* who       when      what
+* --------  --------  ----------------------------------------------
+* schreib  13/07/00  created
+*/
+
+/************************************************************************
+*   NAME
+*     sinfo_wave_calibration.c -
+*     routines needed for wavelength calibration
+*
+*   SYNOPSIS
+* 
+*   1) FitParams ** sinfo_new_fit_params( int n_params )
+*
+*   2) void sinfo_new_destroy_fit_params ( FitParams ** params )
+*
+*   3) void sinfo_new_dump_fit_params_to_ascii(FitParams ** params,
+                                               const char * filename )
+*
+*   4) void sinfo_new_dump_ascii_to_fit_params ( FitParams ** params, 
+                                                 char * filename )
+*
+*   5) int sinfo_new_find_lines(cpl_image * lineImage, 
+*                     float    * wave_position, 
+*                     float    * wave_intensity,
+*                     int        n_lines, 
+*                     int     ** row_clean,
+*                     float   ** wavelength_clean,
+*                     float      beginWave, 
+*                     float      dispersion,
+*                     float      mindiff, 
+*                     int        halfWidth,
+*                     int      * n_found_lines,
+*                     float      sigma,
+*                     int      * sum_lines )
+*
+*   6) int sinfo_new_read_list( char * listname, 
+                                float * lineCenter, 
+                                float * lineIntensity )
+*
+*
+*   7) int sinfo_new_line_fit ( cpl_image  *  mergedImage, 
+*                    FitParams *  par,
+*                    float        fwhm,
+*                    int          lineInd,
+*                    int          column, 
+*                    int          halfWidth, 
+*                    int          lineRow,
+*                    float        min_amplitude )
+*
+*   8) int sinfo_new_fit_lines ( cpl_image  *  line_image, 
+*                     FitParams ** allParams,
+*                     float        fwhm,
+*                     int       *  n_lines, 
+*                     int       ** row,
+*                     float     ** wavelength, 
+*                     int          width,
+*                     float        min_amplitude ) 
+*
+*   9) float sinfo_new_polyfit( FitParams ** par, 
+*                     int          column,
+*                     int          n_lines,
+*                     int          n_rows,
+*                     float        dispersion,
+*                     float        max_residual,
+*                     float *      acoefs, 
+*                     float *      dacoefs, 
+*                     int   *      n_reject,
+*                     int          n_fitcoefs )
+*
+*   10) float sinfo_new_coefs_cross_fit ( int      n_columns,
+*                            float *  acoefs,
+*                            float *  dacoefs, 
+*                            float *  bcoefs,
+*                            int      n_fitcoefs,
+*                            float    sigma_factor )
+*
+*
+*  11) cpl_image * sinfo_new_wave_map( cpl_image * lineImage,
+*                          float   ** bcoefs,
+*                          int        n_a_fitcoefs,
+*                          int        n_b_fitcoefs,
+*                          float    * wavelength,
+*                          float    * intensity,
+*                          int        n_lines,
+*                          int        magFactor,
+*                          int      * bad_column_mask,
+*                          int        n_bad_columns )
+*
+*  12) int sinfo_new_wavelength_calibration( cpl_image   * image, 
+*                                 FitParams ** par ,
+*                                 float     ** bcoefs,
+*                                 float      * wave,
+*                                 int          n_lines,
+*                                 int       ** row_clean,
+*                                 float     ** wavelength_clean,
+*                                 int        * n_found_lines,
+*                                 float        dispersion,
+*                                 int          halfWidth,
+*                                 float        minAmplitude,
+*                                 float        max_residual,
+*                                 float        fwhm,
+*                                 int          n_a_fitcoefs,
+*                                 int          n_b_fitcoefs,
+*                                 float        sigmaFactor )
+*
+*  13) cpl_image * sinfo_new_convolve_image_by_gauss( cpl_image * lineImage,
+*                                       int        hw )
+*
+*  14) cpl_image * sinfo_new_defined_resampling( cpl_image * image,
+*                                    cpl_image * calimage,
+*                                    int        n_params,
+*                                    int        n_rows,
+*                                    double   * dispersion,
+*                                    float    * minval,
+*                                    float    * maxval,
+*                                    double   * centralLambda,
+*                                    int      * centralpix )
+*
+*   DESCRIPTION
+*
+*   1) allocates memory for a new sinfo_vector of 
+*      FitParams data structures
+*   2) frees memory of a sinfo_vector of FitParams data structures
+*   3) dumps the fit parameters to an ASCII file
+*   4) dumps ASCII information to an allocated FitParams data structure
+*   5) determines the pixel shift between the line list 
+*      and the real image by using the beginning wavelength
+*      on the detector and the dispersion estimate.
+*   6) reads the line data of the calibration lamps
+*   7) fits a sinfo_gaussian to a 1-dimensional slice of an image, 
+*      this routine uses the routine sinfo_new_lsqfit_c as a non-linear
+*      least square fit method (Levenberg-Marquardt).               
+*   8) calculates and stores the fit parameters of the neon 
+*      emission lines of a neon frame by using the sinfo_linefit 
+*      routine.
+*   9) fits a second order polynom 
+*      lambda[i] = a1 + a2*pos[i] + a3*pos[i]^2
+*      to determine the connection between the listed wave-
+*      length values and the gauss-fitted positions for each
+*      image column using the singular value decomposition 
+*      method. 
+*  10) Fits the each single parameter of the three fit parameters 
+*      acoefs from sinfo_polyfit through the image columns
+*  11) this routine determines a wavelength calibration map 
+*      frame associating a wavelength value to each pixel
+*      by using the fit coefficients determined before.
+*  12) this routine takes an image from a calibration
+*      emission lamp and delivers the fit coefficients of  
+*      a polynomial fit across the columns 
+*      of the coefficients of the polynomial line position
+*      fits as output. Furthermore it delivers an array of the fit parameters
+*      as output. This routine expects Nyquist sampled spectra 
+*     (either an interleaved image or an image convolved with an 
+*      appropriate function in spectral direction)
+*  13) convolves an emission line image with a sinfo_gaussian
+*      with user given integer half width by using the eclipse 
+*      routine sinfo_function1d_filter_lowpass().
+*  14) Given a source image and a corresponding wavelength
+*      calibration file this routine produces an image
+*      in which elements in a given row are associated
+*      with a single wavelength. It thus corrects for 
+*      the wavelength shifts between adjacent elements
+*      in the rows of the input image. The output image
+*      is larger in the wavelength domain than the input
+*      image with pixels in each column corresponding to 
+*      undefined (blank, ZERO) values. The distribution
+*      of these undefined values varies from column to
+*      column. The input image is resampled at discrete
+*      wavelength intervals using a polynomial interpolation
+*      routine. 
+*      The wavelength intervals (dispersion) and the 
+*      central wavelength are defined and stable for each
+*      used grating. Thus, each row has a defined wavelength
+*      for each grating. Only the number of rows can be 
+*      changed by the user. 
+*
+*   FILES
+*
+*   ENVIRONMENT
+*
+*   RETURN VALUES 
+*
+*   CAUTIONS 
+*
+*   EXAMPLES
+*
+*   SEE ALSO
+*
+*   BUGS   
+*
+*------------------------------------------------------------------------
+*/
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+#include "sinfo_vltPort.h"
+
+/* 
+ * System Headers
+ */
+
+/* 
+ * Local Headers
+ */
+
+#include "sinfo_function_1d.h"
+#include "sinfo_wave_calibration.h"
+#include "sinfo_solve_poly_root.h"
+#include "sinfo_recipes.h"
+#include "sinfo_globals.h"
+#include "sinfo_svd.h"
+#include "sinfo_msg.h"
+
+
+/**@{*/
+/**
+ * @addtogroup sinfo_rec_wavecal wavelength calibration functions
+ *
+ * TBD
+ */
+
+
+/**
+ at brief allocates memory for a new array of FitParams data structures
+ at name sinfo_new_fit_params()
+ at param n_params number of spectral lines that will be fitted
+ at return allocated array of FitParams data structures 
+*/
+
+FitParams ** sinfo_new_fit_params( int n_params )
+{
+    FitParams ** new_params =NULL;
+    FitParams  * temp_params =NULL;
+    float * temp_fit_mem =NULL;
+    float * temp_derv_mem=NULL;
+    int i ;
+
+    
+    if ( n_params <= 0 )
+    {
+        sinfo_msg_error (" wrong number of lines to fit\n") ;
+        return NULL ;
+    }
+
+    if (NULL==(new_params=(FitParams **) cpl_calloc ( n_params , 
+                                         sizeof (FitParams*) ) ) )
+    {
+        sinfo_msg_error (" could not allocate memory\n") ;
+        return NULL ;
+    }
+    if ( NULL == (temp_params = cpl_calloc ( n_params , sizeof (FitParams) ) ) )
+    {
+        sinfo_msg_error (" could not allocate memory\n") ;
+        return NULL ;
+    }
+    if ( NULL == (temp_fit_mem = (float *) cpl_calloc( n_params*MAXPAR, 
+                                     sizeof (float) ) ) )
+    {
+        sinfo_msg_error (" could not allocate memory\n") ;
+        return NULL ;
+    }
+
+
+    if ( NULL == (temp_derv_mem   = 
+             (float *) cpl_calloc( n_params*MAXPAR, sizeof (float) ) ) )
+    {
+        sinfo_msg_error (" could not allocate memory\n") ;
+        return NULL ;
+    }
+
+    for ( i = 0 ; i < n_params ; i ++ )
+    {
+        new_params[i] = temp_params+i;
+        new_params[i] -> fit_par    = temp_fit_mem+i*MAXPAR;
+        new_params[i] -> derv_par   = temp_derv_mem+i*MAXPAR;
+        new_params[i] -> column     = 0 ;
+        new_params[i] -> line       = 0 ;
+        new_params[i] -> wavelength = 0. ;
+        new_params[i] -> n_params   = n_params ;
+    }
+
+    return new_params ;
+}
+
+/**
+ at brief frees memory of an array of FitParams data structures
+ at name sinfo_new_destroy_fit_params()
+ at param params fit params to destroy
+ at return nothing
+*/
+
+void sinfo_new_destroy_fit_params ( FitParams *** params )
+{ 
+    
+    if ( *params == NULL )
+    {
+        return ;
+    }
+
+    cpl_free ( (*params)[0] -> fit_par ) ;
+    (*params)[0] -> fit_par=NULL;
+    cpl_free ( (*params)[0] -> derv_par ) ;
+    (*params)[0] -> derv_par=NULL;
+    cpl_free ( (*params)[0] ) ;
+    (*params)[0]=NULL;
+    cpl_free ( (*params) ) ;
+    (*params)=NULL;
+}
+
+/**
+ at brief dumps the fit parameters to an ASCII file
+ at name sinfo_new_dump_fit_params_to_ascii()
+ at param params: fit params to dump
+ at param filename
+ at return filled ASCII file 
+*/
+
+void sinfo_new_dump_fit_params_to_ascii ( FitParams ** params, const char * filename )
+{
+    FILE * fp ;
+    int    i ;
+
+    if ( NULL == params )
+    {
+        sinfo_msg_error (" no fit parameters available!\n") ;
+        return ;
+    }
+
+    if ( NULL == filename )
+    {
+        sinfo_msg_error (" no filename available!\n") ;
+        return ;
+    }
+
+    if ( NULL == (fp = fopen ( filename, "w" ) ) )
+    {
+        sinfo_msg_error(" cannot open %s\n", filename) ;
+        return ;
+    }
+
+    for ( i = 0 ; i < params[0] -> n_params ; i++ )
+    {
+        fprintf(fp, "%d %d %d %f %f %f %f %f %f %f %f %f\n", 
+                     params[i]->n_params, 
+                     params[i]->column, 
+                     params[i]->line, 
+                     params[i]->wavelength, 
+                     params[i]->fit_par[0], 
+                     params[i]->fit_par[1], 
+                     params[i]->fit_par[2], 
+                     params[i]->fit_par[3],
+                     params[i]->derv_par[0], 
+                     params[i]->derv_par[1], 
+                     params[i]->derv_par[2], 
+                     params[i]->derv_par[3] ) ; 
+    }
+    fclose(fp) ;
+}
+
+/**
+ at brief dumps ASCII information to an allocated FitParams data structure
+ at name dump_ascii_to_fit_params()
+ at param params allocated dummy for the fit params 
+ at param filename
+ at return params: filled FitParams object
+*/
+
+void 
+sinfo_new_dump_ascii_to_fit_params ( FitParams ** params, char * filename )
+{
+    FILE * fp ;
+    int i ;
+
+    if ( NULL == params )
+    {
+        sinfo_msg_error (" no fit parameters available!\n") ;
+        return ;
+    }
+
+    if ( NULL == filename )
+    {
+        sinfo_msg_error (" no filename available!\n") ;
+        return ;
+    }
+
+    if ( NULL == (fp = fopen ( filename, "r" ) ) )
+    {
+        sinfo_msg_error(" cannot open %s\n", filename) ;
+        return ;
+    }
+    
+    for ( i = 0 ; i < params[0]->n_params ; i++ )
+    {
+        fscanf(fp, "%d %d %d %f %f %f %f %f %f %f %f %f\n", 
+                    &params[i]->n_params, 
+                    &params[i]->column, 
+                    &params[i]->line, 
+                    &params[i]->wavelength, 
+                    &params[i]->fit_par[0], 
+                    &params[i]->fit_par[1], 
+                    &params[i]->fit_par[2], 
+                    &params[i]->fit_par[3],
+                    &params[i]->derv_par[0], 
+                    &params[i]->derv_par[1], 
+                    &params[i]->derv_par[2], 
+                    &params[i]->derv_par[3] ) ; 
+    }
+    fclose(fp) ;
+}
+
+/**
+ at brief determines the pixel shift between the line list and the real image
+ at name sinfo_new_find_lines()
+ at param lineImage: merged emission line image,
+ at param wave_position: wavelength list in Angstroems
+ at param wave_intensity: corresponding intensity list 
+ at param n_lines: number of lines in list
+ at param row_clean: resulting list of the row indices but without 
+                  the lines that are too close to each other for the fit
+ at param wavelength_clean: corrected wavelength list corresponding 
+                         to the row_clean array
+ at param beginWave: beginning wavelength on detector in microns 
+ at param dispersion: dispersion of the grating on the detector
+                   (microns per pixel, attention: merged image).
+ at param mindiff: minimal difference of mean and median column
+                intensity to do the correlation. 
+                This is done to avoid correlations in columns 
+                without emission line intensity.
+ at param halfWidth:   half width of the box where the line must sit,
+ at param n_found_lines: number of found and correlated emission lines in a column.
+ at param sigma: sigma of Gaussian that is convolved with the artificial spectrum
+ at return 0 if all went o.k.
+        # row: resulting list of the row indices of the line positions
+        # row_clean: resulting list of the row indices but without the 
+                     lines that are too close to each other for the fit
+        # wavelength: wavelength from the list corresponding to 
+                      the found row positions
+        # wavelength_clean: corrected wavelength list corresponding 
+                            to the row_clean array
+        # n_found_lines: number of found and correlated 
+                         emission lines in a column.
+        # sum_lines: total sum of found and correlated emission lines
+                     -1 if something has gone wrong 
+ at doc determines the pixel shift between the line list and the 
+     real image by using the 
+     beginning wavelength on the detector and the dispersion estimate.
+*/
+
+int sinfo_new_find_lines(cpl_image * lineImage, 
+               float    * wave_position, 
+               float    * wave_intensity,
+               int        n_lines, 
+               int     ** row_clean,
+               float   ** wavelength_clean,
+               float      beginWave, 
+               float      dispersion1,
+               float      dispersion2,
+               float      mindiff, 
+               int        halfWidth,
+               int      * n_found_lines,
+               float      sigma,
+               int      * sum_lines )
+{
+    int     ** row ;
+    float   ** wavelength ;
+    float buf1, buf2 ;
+    float meanval ;
+    float colmedian ;
+    float * column, * tempcol ;
+    float * lines ;
+    float * conv_lines ;
+    float * wave_buffer ;
+    float * wave_mem;
+    int   * dummy_row ;
+    int i, j, k, m ;
+    int position ;
+    int gmax, gmin ;
+    int col ;
+    int * row_mem;
+    float sum ;
+    float angst ;
+
+    int lx=0;
+    int ly=0;
+    float* pdata=NULL;
+
+    if ( NULL == lineImage )
+    {
+        sinfo_msg_error (" no image given\n") ;
+        return -1 ;
+    }
+
+    lx=cpl_image_get_size_x(lineImage);
+    ly=cpl_image_get_size_y(lineImage);
+    pdata=cpl_image_get_data_float(lineImage);
+
+    if ( n_lines <= 0 || NULL == wave_position ) 
+    {
+        sinfo_msg_error(" no line list given\n") ;
+        return -1 ;
+    }
+    if ( NULL == wave_intensity ) 
+    {
+        sinfo_msg_error(" no intensity list given\n") ;
+        return -1 ;
+    }
+     
+    if ( dispersion1 == 0. )
+    {
+        sinfo_msg_error(" wrong dispersion given\n") ;
+        return -1 ;
+    }
+   
+    if ( row_clean == NULL )
+    {
+        sinfo_msg_error(" row_clean array is not allocated\n") ;
+        return -1 ;
+    }
+
+    if ( wavelength_clean == NULL )
+    {
+        sinfo_msg_error(" wavelength_clean array is not allocated\n") ;
+        return -1 ;
+    }
+
+    if ( beginWave <= 0. )
+    {
+        sinfo_msg_error (" impossible beginWave given\n") ;
+        return -1 ;
+    }
+    if ( mindiff < -100. )
+    {
+        sinfo_msg_error (" wrong mindiff value\n") ;
+        return -1 ;
+    }
+
+    if ( halfWidth <= 0 )
+    {
+        sinfo_msg_error(" wrong half width of fit box given\n") ;
+        return -1 ;
+    }
+
+    if ( n_found_lines == NULL )
+    {
+        sinfo_msg_error(" n_found_lines not allocated\n") ;
+        return -1 ;
+    }
+
+    if ( sigma <= 0. || sigma >= ly / 2)
+    {
+        sinfo_msg_error(" wrong sigma given\n") ;
+        return -1 ;
+    }
+    
+    /* allocate memory */
+    row        = (int**) cpl_calloc( lx, sizeof(int*)) ;
+    wavelength = (float**) cpl_calloc( lx, sizeof(float*)) ;
+    row_mem = cpl_calloc( n_lines*lx, sizeof(int) ) ;
+    wave_mem = cpl_calloc( n_lines*lx, sizeof(float) ) ;
+    for ( i = 0 ; i <lx ; i++ )
+    {
+        row[i] = row_mem + i*n_lines;
+        wavelength[i] = wave_mem + i*n_lines;
+    }
+
+    /* find if the wavelength is given in microns, nanometers or Angstroem */
+    if ( wave_position[0] > 10000. )
+    {
+    /* Angstroem */
+        angst = 10000. ;
+    }
+    else if ( wave_position[0] > 1000. && wave_position[0] < 10000. )
+    {
+    /* nanometers */
+    angst = 1000. ;
+    }
+    else
+    {
+    /* microns */
+    angst = 1. ;
+    }
+
+    /*----------------------------------------------------------------------
+     * compute the mean and median intensity value in the given 
+       column and determine if there is enough intensity in the column to 
+       do the correlation
+     */
+    tempcol = (float*) cpl_calloc(ly, sizeof(float)) ;
+    *sum_lines = 0 ;
+    buf1 = 0. ;
+    buf2 = 0. ;
+    /* allocate memory */
+    column      = (float*) cpl_calloc(ly, sizeof (float)) ;
+    lines       = (float*) cpl_calloc(ly, sizeof (float)) ;
+    conv_lines  = (float*) cpl_calloc(ly, sizeof (float)) ;
+    wave_buffer = (float*) cpl_calloc(ly, sizeof (float)) ;
+    dummy_row   = (int*)   cpl_calloc(n_lines, sizeof(int)) ;
+
+    for ( col = 0 ; col < lx ; col++ )
+    {
+        n_found_lines[col] = 0 ;
+        sum = 0. ;
+        for ( i = 0 ; i < ly ; i++ )
+        {
+            if (isnan(pdata[col + i*lx]) )
+            {
+                tempcol[i] = 0. ;
+                continue ;
+            }
+
+        sum = sum + pdata[col + i*lx] ;
+        tempcol[i] = pdata[col + i*lx];
+        }
+        meanval = sum / ly ;
+        /* lets assume the sinfo_new_median is the background */
+        colmedian =  sinfo_new_median ( tempcol, ly);
+
+        if ( meanval - colmedian < mindiff )
+        {
+        sinfo_msg_warning(" sorry, not enough intensity "
+                              "(mean: %f, diff: %f) in image column: "
+                               "%d to correlate emission lines\n", 
+                                meanval, meanval - colmedian,col) ;
+        continue ;
+    }
+
+        for ( i = 0 ; i < ly ; i++ )
+    	  {
+      conv_lines[i]=0;
+      wave_buffer[i]=0;
+    }
+    for ( i = 0 ; i < n_lines ; i++ )
+    {
+      dummy_row[i] = 0;
+    }
+
+        /* go through the column with index col */
+        for ( i = 0 ; i < ly ; i++ )
+        {
+            if ( isnan(pdata[col+i*lx]) )
+            {
+                column[i] = 0. ;
+            }
+            else
+            {
+                column[i] = pdata[col + i*lx] ;
+            }
+
+            /* determine the line position on the pixels */
+            /*lines[i] = (dispersion * (float) i + beginWave) * angst ;*/ 
+            lines[i] = (dispersion1 * (float) (i-ly/2) + 
+                        dispersion2 * (float) (i-ly/2) * 
+                                      (float) (i-ly/2) + 
+                                              beginWave) * angst ; 
+
+            /* ---------------------------------------------------------------
+             * find the nearest line position for each wavelength in the list 
+             * and set this position to the given line intensity as weight 
+             */
+            for ( j = 0 ; j < n_lines ; j ++ )
+            {
+                buf1 = 0. ;
+                buf2 = 0. ;
+                if ( (wave_position[j] >= (lines[i] - 
+                      fabs(dispersion1)/2.*angst)) && 
+                     (wave_position[j] <= (lines[i] + 
+                      fabs(dispersion1)/2.*angst)) ) 
+                {
+                    buf1 = wave_intensity[j] ; /* set the given line intensity 
+                                                  as weight */
+                    buf2 = wave_position[j] ;
+                    break ;
+                }
+            }
+            lines[i] = buf1 ;
+            wave_buffer[i] = buf2 ; /* get the wavelength associated 
+                                       with the corresponding 
+                                           found emission line */
+    
+            /* convolve the artificial spectrum by a Gaussian 
+               with given sigma value */
+            if ( lines[i] != 0. )
+            {
+                /* consider only +- 2 sigma */
+                gmin = sinfo_new_nint((float) i - 2. * sigma) ;
+                gmax = sinfo_new_nint((float) i + 2. * sigma) ;
+
+                /* be aware of image margins */
+                if ( gmin < 0 )
+                {
+                    gmin = 0 ;
+                }
+                if ( gmax >= ly )
+                {
+                    gmax = ly - 1 ;
+                } 
+                for ( j = gmin ; j <= gmax ; j++ )
+                {
+                    conv_lines[j] += 
+                        lines[i] * exp( (double)( -0.5*((j - i)*(j - i)))/
+                                        (double) (sigma*sigma) ) ; 
+                }
+            }
+        }
+
+        /* do the cross sinfo_new_correlitioation */
+        position = INT32_MAX ;
+        position = sinfo_new_correlation(column+5, conv_lines+5, ly-10 ) ; 
+        if ( abs (position) > ly / 4 )
+        {
+            sinfo_msg_warning(" sorry, shift of artificial data relative to"
+                              " image (%d) seems to be too high in column: %d",
+                              position, col) ;
+            continue ;
+        }
+
+        //AMO we initialize this to -999 and later check that it is not
+        //-999 to prevent an invalid read out due to the fact that not
+        //all elements of row are filled by the the loop below
+        for ( j = 0 ; j < n_lines ; j ++ ) {
+          row[col][j] = -999;
+	}
+
+        //The following loop does not fill all elements
+        j = 0 ;
+        for ( i = 0 ; i < ly ; i ++ )
+        {
+            if ( lines[i] != 0.0 )
+            {
+                if ( (i - position) >= 0 && (i - position) < ly )
+                {
+                    row[col][j] = i - position ;
+                    /* get the wavelength corresponding to 
+                       found line row index */
+                    wavelength[col][j] = wave_buffer[i] / angst ;
+                    j++ ;
+                }
+            }
+        }
+
+
+        /* ------------------------------------------------------------------
+         *  determine the row_clean array, that means, take only the row 
+            values if the distance between adjacent lines is large enough 
+            for the fit
+         */
+        //sinfo_msg("lx=%d",lx);
+        for ( k = 1 ; k <= j && k<(lx-1); k ++ )
+        {
+            if (dummy_row[k-1] != -1)
+            {
+                dummy_row[k-1] = row[col][k-1] ;
+            }
+            if ( (row[col][k] - row[col][k-1]) <= 2*halfWidth )
+            {
+                dummy_row[k-1] = -1 ;
+		if (k<n_lines) {
+                  dummy_row[k]   = -1 ;
+		}
+            }
+            /* the following gives invalid read size 4: check that k+1<lx */
+            
+            //sinfo_msg("col=%d k=%d row1=%d row2=%d",
+            //           col,k,row[col][k+1],row[col][k]);
+            if ( (row[col][j] != -999) && 
+                 (row[col][k+1] - row[col][k]) <= 2*halfWidth)
+            {
+	      if (k<n_lines) {
+                  dummy_row[k]   = -1 ;
+	      }
+	      if (k+1<n_lines) {
+                  dummy_row[k+1] = -1 ;
+	      }
+            }
+        }
+
+        m = 0 ;
+        for ( k = 0 ; k < j ; k ++ )
+        {
+            if ( dummy_row[k] != -1 && dummy_row[k] != 0 )
+            {
+                row_clean[col][m] = dummy_row[k] ;
+                wavelength_clean[col][m] = wavelength[col][k] ;
+                m ++ ;
+            }
+        }
+
+        n_found_lines[col] = m ;
+
+        *sum_lines += n_found_lines[col] ;
+    }
+    cpl_free (column) ;
+    cpl_free (lines) ;
+    cpl_free (conv_lines) ;
+    cpl_free (dummy_row) ;
+    cpl_free (wave_buffer) ;
+    cpl_free (row_mem) ;
+    cpl_free (wave_mem) ;
+    cpl_free (tempcol) ;
+    cpl_free (row) ;
+    cpl_free (wavelength) ;
+
+    return 0 ;
+}
+
+/**
+ at brief reads the line data of the calibration lamps
+ at name sinfo_new_read_list()
+ at param listname name of the list file, arrays to store the wavelength 
+                and the intensities of the emission lines
+ at param  lineCenter 
+ at param lineIntensity
+*/
+
+int 
+sinfo_new_read_list( char * listname, 
+                     float * lineCenter, 
+                     float * lineIntensity )
+{
+    FILE * fp ;
+    int i, n_lines ;
+    
+    if ( NULL == lineCenter )
+    {
+        sinfo_msg_error(" lineCenter array is not allocated\n") ;
+        return -1 ;
+    }
+
+    if ( NULL == lineIntensity )
+    {
+        sinfo_msg_error(" lineIntensity array is not allocated\n") ;
+        return -1 ;
+    }
+
+    if ( NULL == (fp = fopen ( listname, "r" ) ) )
+    {
+        sinfo_msg_error(" cannot open %s\n", listname) ;
+        return -1 ;
+    }
+
+    i = 0 ;
+    while ( fscanf( fp, "%f %f", &lineCenter[i], &lineIntensity[i] ) != EOF )
+    {
+        i ++ ;
+    }
+    n_lines = i ;
+    fclose(fp) ;
+           
+    return n_lines ;
+}
+
+
+/**
+ at brief fits a Gaussian to a 1-dimensional slice of an image
+ at name sinfo_new_line_fit()
+ at param mergedImage: image of a calibration emission lamp,
+ at param par:         dummys for the resulting fitting parameters,
+ at param fwhm:        guess value for full width of half maximum of Gaussian
+ at param lineInd:     index of the emission line,
+ at param column:      present index of the image column,
+ at param halfWidth:   half width of the box where the line must sit,
+ at param lineRow:     row index where the line is expected,
+ at param min_amplitude: minimum line amplitude with respect to the 
+                      background to do the fit
+ at return the fitting parameter data structure containing the resulting 
+        parameters.
+        # integers: number of iterations if all was ok,
+        #  -8   if no input image was given,
+        #  -9   if no dummy for the fit parameters is given,
+        # -10  if the wrong column index was given,
+        # -11  if the wrong box width was given,
+        # -12  if the wrong row index was given,
+        # -13  if a wrong minimum amplitude factor was given
+        # -14  if the spectral sinfo_vector data structure memory 
+               could not be allocated          
+        # -15  wrong row index or box width was given,
+        # -16  signal too low to fit,         
+        # -17  least squares fit failed
+ at doc fits a Gaussian to a 1-dimensional slice of an image, this routine 
+     uses the routine sinfo_new_lsqfit_c as a non-linear least square fit 
+     method (Levenberg-Marquardt).               
+*/
+
+int sinfo_new_line_fit ( cpl_image  *  mergedImage, 
+              FitParams *  par,
+              float        fwhm,
+              int          lineInd,
+              int          column, 
+              int          halfWidth, 
+              int          lineRow,
+              float        min_amplitude,
+          Vector    *  line,
+          int       *  mpar,
+          float     *  xdat,
+          float     *  wdat )
+{
+    int i, j ;
+    int iters, xdim, ndat ;
+    int numpar, its ;
+    int position ;
+    float maxval, tol, lab ;
+    int lx=0;
+    int ly=0;
+    float* pdata=NULL;
+
+    if ( mergedImage == NULL )
+    {
+        sinfo_msg_error (" no image given as input\n") ;
+        return -8 ;
+    }
+    lx=cpl_image_get_size_x(mergedImage);
+    ly=cpl_image_get_size_y(mergedImage);
+    pdata=cpl_image_get_data_float(mergedImage);
+
+
+    if ( par == NULL )
+    {
+        sinfo_msg_error(" fit parameters not given\n") ;
+        return -9 ;
+    }
+    if ( column < 0 || column > lx )
+    {
+        sinfo_msg_error (" wrong column number\n") ;
+        return -10 ;
+    }
+    if ( halfWidth < 0 || halfWidth > ly )
+    {
+        sinfo_msg_error (" wrong width given\n") ;
+        return -11 ;
+    }
+    if ( lineRow < 0 || lineRow > ly )
+    {
+        sinfo_msg_error (" wrong number of row of the line given\n") ;
+        return -12 ;
+    }
+    if ( min_amplitude < 1. )
+    {
+        sinfo_msg_error (" wrong minimum amplitude\n") ;
+        return -13 ;
+    }
+    
+    /* initialise the Vector */
+    for ( i = 0 ; i < line -> n_elements ; i++) 
+    {
+        line->data[i] = 0;
+    }
+    
+    par -> column = column  ;
+    par -> line   = lineInd ;
+
+    /* determine the values of the spectral sinfo_vector given as input */
+    /* go through the chosen column */
+
+    j = 0 ;
+    for ( i = lineRow-halfWidth ; i <= lineRow+halfWidth ; i++ ) 
+    {
+        if ( i < 0 || i >= ly )
+        {
+            sinfo_msg_error (" wrong line position or width given\n") ;
+            return -15 ;
+        }
+        else
+        {
+            line -> data[j] = pdata[column + i*lx] ;
+            j ++ ;
+        }
+    } 
+
+    /*-------------------------------------------------------------------- 
+     * go through the spectral sinfo_vector 
+     * determine the maximum pixel value in the spectral sinfo_vector 
+     */
+    maxval = -FLT_MAX ;
+    position = -INT32_MAX ;
+    for ( i = 0 ; i < line -> n_elements ; i++ )
+    {
+        xdat[i] = i ;
+        wdat[i] = 1.0 ;
+        if ( line -> data[i] >= maxval )
+        {
+            maxval = line -> data[i] ;
+            position = i ;
+        }
+    }
+
+    /* set initial values for the fitting routine */
+    xdim     = XDIM ;
+    ndat     = line -> n_elements ;
+    numpar   = MAXPAR ;
+    tol      = TOL ;
+    lab      = LAB ;
+    its      = ITS ;
+    par -> fit_par[1] = fwhm ;
+    par -> fit_par[2] = (float) position ;
+    par -> fit_par[3] = (float) (line -> data[0] + 
+                                 line -> data[line->n_elements - 1]) / 2.0 ;
+    par -> fit_par[0]  = maxval - (par -> fit_par[3]) ;
+
+    /* exclude low signal cases */
+    if ( par->fit_par[0] < min_amplitude )
+    {
+        cpl_msg_debug ("sinfo_linefit:",
+                       " sorry, amplitude of line too low to fit: %f",
+                       par->fit_par[0] ) ;
+        return -16 ;
+    }
+
+    for ( i = 0 ; i < MAXPAR ; i++ )
+    {
+        par -> derv_par[i] = 0.0 ;
+        mpar[i] = 1 ;
+    }
+
+    /* finally, do the least square fit using a sinfo_gaussian */
+    if ( 0 > ( iters = sinfo_new_lsqfit_c( xdat, &xdim, 
+                                           line -> data, wdat, 
+                                           &ndat, par -> fit_par,  
+                                           par -> derv_par, mpar, 
+                                           &numpar, &tol, &its, &lab )) )  
+    {
+        cpl_msg_debug ("sinfo_linefit:",
+                       " sinfo_new_lsqfit_c: least squares fit failed,"
+                       " error no.: %d\n", iters) ; 
+        return -17 ;
+    }
+
+    /* correct the fitted position for the given row of the 
+       line in image coordinates */
+    par -> fit_par[2] =  (float) (lineRow - halfWidth) + par -> fit_par[2] ;
+
+    /* all was o.k. */
+    return iters ;
+}
+
+/**
+ at brief calculates and stores the fit parameters of the neon emission 
+       lines of a neon frame by using the linefit routine.
+ at name sinfo_new_fit_lines
+ at param line_image: merged image of a calibration lamp ,
+ at param allParams:  allocated sinfo_vector of FitParams data structures,
+ at param fwhm:       guess value for full width of half maximum of Gaussian
+ at param n_lines:    number of neon lines that will be fitted in one column ,
+ at param row:        list of the rows of the fitted lines
+ at param wavelength: list of wavelength corresponding to the found line rows
+ at param width:      half width of a box around the found rows within the line 
+                   is fitted
+ at param min_amplitude: minimum line amplitude with respect to the background 
+                   to do the fit
+ at return filled FitParams data structure sinfo_vector, number of successfully 
+                  fitted lines,
+      # errors: negative integers resulting from the linefit routine and:
+      # -18: no image given,
+      # -19: number of emission lines or number of slitlets is wrong,
+      # -20: sinfo_vector of the slitlet boundaries or of the line rows 
+             or of the half width are empty.
+      # -21: no wavelength array given.
+*/
+
+int sinfo_new_fit_lines ( cpl_image  *  line_image, 
+               FitParams ** allParams,
+               float        fwhm,
+               int       *  n_lines, 
+               int       ** row,
+               float     ** wavelength, 
+               int          width,
+               float        min_amplitude ) 
+{
+    int i, k, l ;
+    int result ;
+    Vector * line;
+    int    * mpar;
+    float  * xdat, * wdat;
+    int lx=0;
+    int ly=0;
+    float* pdata=NULL;
+
+    if ( line_image == NULL )
+    {
+        sinfo_msg_error (" no image given\n") ;
+        return -18 ;
+    }
+    lx=cpl_image_get_size_x(line_image);
+    ly=cpl_image_get_size_y(line_image);
+    pdata=cpl_image_get_data_float(line_image);
+
+    if ( n_lines == NULL )
+    {
+        sinfo_msg_error (" no counter of emission lines\n") ;
+        return -19 ;
+    } 
+    if ( row == NULL || width <= 0 )
+    {
+        sinfo_msg_error (" row or width vectors are empty\n") ;
+        return -20 ;
+    }
+    if ( wavelength == NULL )
+    {
+        sinfo_msg_error (" no wavelength array given\n") ;
+        return -21 ;
+    }
+
+    k = 0 ;
+
+    /* allocate memory for the spectral sinfo_vector */
+    line = sinfo_new_vector (2*width + 1) ;
+    /* allocate memory */
+    xdat = (float *) cpl_calloc( line -> n_elements, sizeof (float) ) ;
+    wdat = (float *) cpl_calloc( line -> n_elements, sizeof (float) ) ;
+    mpar = (int *)   cpl_calloc( MAXPAR, sizeof (int) ) ;
+    
+    /* go through the columns */
+    for ( i = 0 ; i < lx ; i++ )
+    {
+        if ( n_lines[i] == 0 )
+        {
+            continue ;
+        }
+        /* go through the emission lines in a column */
+        for ( l = 0 ; l < n_lines[i] ; l++ )
+        {
+            if ( row[i][l] <= 0 )
+            {
+                continue ;
+            }
+
+            /* --------------------------------------------------------------
+             * fit the single lines using sinfo_linefit and store the 
+               parameters in
+             * an array of the FitParams data structure allParams[].
+             */ 
+            if ( (result = sinfo_new_line_fit ( line_image, 
+                                                allParams[k], fwhm, l, i, 
+                                                width, row[i][l], 
+                                                min_amplitude,line,mpar,
+                                                xdat,wdat ) ) < 0 )
+            {
+                cpl_msg_debug ("sinfo_fitLines:",
+                               " sinfo_linefit failed, error no.: %d,"
+                               " column: %d, row: %d, line: %d\n", 
+                               result, i, row[i][l], l) ;
+                continue ;
+            }
+            if ( (allParams[k] -> fit_par[0] <= 0.) || 
+                 (allParams[k] -> fit_par[1] <= 0.)
+                  || (allParams[k] -> fit_par[2] <= 0.) )
+            {
+                sinfo_msg_warning (" negative fit parameters in column: %d,"
+                                   " line: %d\n", i, l) ;
+                continue ;
+            }
+            allParams[k] -> wavelength = wavelength[i][l] ;
+            k++ ;
+        }
+    }
+
+    /* free memory */
+    sinfo_new_destroy_vector(line);
+    cpl_free(xdat);
+    cpl_free(wdat);
+    cpl_free(mpar);
+    
+    /* all is o.k. */
+    return k ;
+}    
+
+/**
+ at brief fits a polynomial to determine the connection between the 
+       listed wavelength values and the gauss-fitted positions for 
+       each image column using the singular value decomposition method.
+ at name sinfo_new_polyfit()
+ at param par:          filled array of fit parameter structure
+ at param column:       image column index
+ at param n_lines:      number of found lines in column
+ at param n_rows:       number of image rows
+ at param dispersion:   microns per pixel
+ at param max_residual: maximum residual value, beyond that value the fit is 
+                     rejected.
+ at param acoefs:       array of the 3 coefficients of the fitted parabola
+ at param dacoefs:      array of standard deviations of the 3 coefficients
+ at param n_reject:     rejected number of fits due to high residuals
+ at param n_fitcoefs:   number of polynomial coefficients to fit
+ at return # chisq, the three fit coefficients acoefs[i] and their standard 
+                     deviations dacoefs[i], 
+               the rejected number of fits due to too high residuals: n_reject
+        # FLT_MAX in case of error
+ at doc fits a polynomial
+     lambda[i] = a1 + a2*pos[i] + a3*pos[i]^2 +...
+     to determine the connection between the listed wavelength values 
+     and the gauss-fitted positions for each image column using the 
+     singular value decomposition method.
+*/
+
+float sinfo_new_polyfit( FitParams ** par,
+               int          column,
+               int          n_lines,
+               int          n_rows,
+               float        dispersion,
+               float        max_residual,
+               float *      acoefs,
+               float *      dacoefs,
+               int   *      n_reject,
+               int          n_fitcoefs )
+{
+    float ** ucoefs, ** vcoefs, ** covar ;
+    float *mem;
+    float * lambda, * posit ;
+    float * weight, * resid ;
+    float * newlam, * newpos, * newwet ;
+    float * wcoefs=NULL ;
+    float chisq, result ;
+    float offset ;
+    int num, found ;
+    int i, j, k, n ;
+
+    /* reset the fit coefficients and their errors */
+    for ( i = 0 ; i < n_fitcoefs ; i++ )
+    {
+        acoefs[i]  = 0. ;
+        dacoefs[i] = 0. ;
+    }
+    if ( NULL == par )
+    {
+        sinfo_msg_error(" no fit params given\n");
+        return FLT_MAX ;
+    }
+
+    if ( 0 >= n_lines )
+    {
+      /*
+        sinfo_msg_warning (" sorry, number of lines is wrong") ;
+      */
+        return FLT_MAX ;
+    }
+    if ( 0 >= n_rows )
+    {
+        sinfo_msg_error (" sorry, number of rows is wrong") ;
+        return FLT_MAX ;
+    }
+    if ( dispersion == 0. )
+    {
+        sinfo_msg_error (" sorry, wrong dispersion given") ;
+        return FLT_MAX ;
+    }
+
+    offset = (float)(n_rows - 1)/2. ;
+
+    /* allocate memory */
+    
+    mem = (float*) cpl_calloc( n_lines*7, sizeof (float) ) ;
+    lambda = mem;
+    posit  = mem + n_lines;
+    weight = mem + n_lines*2;
+    resid  = mem + n_lines*3;
+    newlam = mem + n_lines*4;
+    newpos = mem + n_lines*5;
+    newwet = mem + n_lines*6;
+    
+    /*lambda = (float*) cpl_calloc( n_lines, sizeof (float) ) ;
+    posit  = (float*) cpl_calloc( n_lines, sizeof (float) ) ;
+    weight = (float*) cpl_calloc( n_lines, sizeof (float) ) ;
+    resid  = (float*) cpl_calloc( n_lines, sizeof (float) ) ;
+    newlam = (float*) cpl_calloc( n_lines, sizeof (float) ) ;
+    newpos = (float*) cpl_calloc( n_lines, sizeof (float) ) ;
+    newwet = (float*) cpl_calloc( n_lines, sizeof (float) ) ;*/
+
+    /* allocate coefficient matrices*/
+    ucoefs = sinfo_matrix ( 1, n_lines, 1, n_fitcoefs ) ;
+    vcoefs = sinfo_matrix ( 1, n_lines, 1, n_fitcoefs ) ;
+    covar  = sinfo_matrix ( 1, n_fitcoefs, 1, n_fitcoefs ) ;
+    wcoefs=cpl_calloc(n_fitcoefs,sizeof(float)) ;
+
+    /* go through all fit parameters */
+    n = 0 ;
+    for ( i = 0 ; i < (par[0] -> n_params) ; i ++ )
+    {
+        found = -1 ;
+        /* find the given column and go through the lines in that column */
+        for ( j = 0 ; j < n_lines ; j ++ )
+        {
+            if ( (par[i] -> column == column) && (par[i] -> line == j) )
+            {
+                found = i ;
+            }
+            else
+            {
+                continue ;
+            }
+
+            /* store only fit params with reasonable values */
+            if ( par[found] -> derv_par[2] != 0. && 
+                 par[found] -> fit_par[2] > 0. &&
+                 par[found] -> wavelength > 0. && 
+                 par[found] -> fit_par[1] > 0. &&
+                 par[found] -> fit_par[0] > 0. )
+            {
+                /* ----------------------------------------------------------
+                 * store the found position, error of the position as 
+                   weight and the associated
+                 * wavelength values of the fitted lines
+                 */
+                posit[n]  = par[found] -> fit_par[2] ;
+                weight[n] = par[found] -> derv_par[2] ;
+                lambda[n] = par[found] -> wavelength ;
+                n ++ ;
+            }
+            else
+            {
+                continue ;
+            }
+        }
+
+    }
+
+    num = n ;
+    if ( num < n_fitcoefs )
+    {
+        sinfo_msg_warning("not enough lines found in column %d to "
+                          "determine the three coefficients.\n", column) ;
+        for ( i = 0 ; i < n_fitcoefs ; i++ )
+        {
+            acoefs[i]  = ZERO ;
+            dacoefs[i] = ZERO ;
+        }
+        sinfo_free_matrix ( ucoefs, 1/*, n_lines*/,    1/*, n_fitcoefs*/ ) ;
+        sinfo_free_matrix ( vcoefs, 1/*, n_lines*/,    1/*, n_fitcoefs*/ ) ;
+        sinfo_free_matrix ( covar,  1/*, n_fitcoefs*/, 1/*, n_fitcoefs*/ ) ;
+        /*cpl_free (lambda) ;
+        cpl_free (posit) ;
+        cpl_free (weight) ;
+        cpl_free (resid) ;
+        cpl_free (newlam) ;
+        cpl_free (newpos) ;
+        cpl_free (newwet) ;*/
+    cpl_free (mem);
+        return FLT_MAX ;
+    }
+
+    /*-------------------------------------------------------------------------
+     * scale the pixel position values to smaller than 1 and transform 
+       the weights to wavelength units 
+     */
+
+    for ( i = 0 ; i < num ; i ++ )
+    {
+        posit[i] = (posit[i] - offset)/offset ;
+        weight[i] *= fabs(dispersion) ;
+    }
+
+    /* do the fit using the singular value decomposition method */
+    sinfo_svd_fitting( posit - 1, lambda - 1, 
+                      weight - 1, num, acoefs-1, n_fitcoefs,
+            ucoefs, vcoefs, wcoefs-1, covar, &chisq, sinfo_fpol ) ;
+
+    /* scale the linear and the quadratic coefficient */
+    for ( i = 1 ; i < n_fitcoefs ; i++ )
+    {
+        acoefs[i] /= pow(offset, i) ;
+    }
+
+    /* now that we have determined the fit coefficients, find the residuals */
+    *n_reject = 0 ;
+
+    j = 0 ;
+    for ( i = 0 ; i < num ; i++ )
+    {
+        result = 0. ;
+        for ( k = 0 ; k < n_fitcoefs ; k++ )
+        {
+            result += acoefs[k] * pow(posit[i], k) ;
+        }
+
+        resid[i] = lambda[i] - result ;
+
+        if ( fabs( resid[i] ) > max_residual)
+        {
+            (*n_reject) ++ ;
+        }
+        else
+        {
+            newlam[j] = lambda[i] ;
+            newpos[j] = posit[i] ;
+            newwet[j] = weight[i] ;
+            j++ ;
+        }
+    }
+
+    num = j ;
+    if ( num >= n_fitcoefs )
+    {
+        sinfo_svd_fitting( newpos - 1, newlam - 1, 
+                           newwet - 1, num, acoefs-1, n_fitcoefs, ucoefs,
+                vcoefs, wcoefs-1, covar, &chisq, sinfo_fpol ) ;
+
+        /* scale the resulting coefficients */
+        for ( i = 0 ; i < n_fitcoefs ; i++ )
+        {
+            acoefs[i] /= pow(offset, i) ;
+            dacoefs[i] = sqrt( (double) covar[i+1][i+1] ) / pow(offset, i) ;
+        }
+    }
+    else
+    {
+        sinfo_msg_warning (" too many lines rejected (number: %d) "
+                           "due to high residuals, fit coefficients are set "
+                           "zero, in column: %d\n", *n_reject, column) ;
+        for ( i = 0 ; i < n_fitcoefs ; i++ )
+        {
+            acoefs[i]  = ZERO ;
+            dacoefs[i] = ZERO ;
+        }
+    }
+
+    sinfo_free_matrix ( ucoefs, 1/*, n_lines*/,    1/*, n_fitcoefs*/ ) ;
+    sinfo_free_matrix ( vcoefs, 1/*, n_lines*/,    1/*, n_fitcoefs*/ ) ;
+    sinfo_free_matrix ( covar,  1/*, n_fitcoefs*/, 1/*, n_fitcoefs*/ ) ;
+    /*cpl_free (lambda) ;
+    cpl_free (posit) ;
+    cpl_free (weight) ;
+    cpl_free (resid) ;
+    cpl_free (newlam) ;
+    cpl_free (newpos) ;
+    cpl_free (newwet) ;*/
+    cpl_free (mem);
+    cpl_free(wcoefs) ;
+
+    return chisq ;
+}
+
+/**
+ at brief Fits each single polnomial coefficient acoefs resulting 
+       from sinfo_polyfit across the image columns
+ at name sinfo_new_coefs_cross_fit()
+ at param n_columns:    number of image columns
+ at param acoefs:       coeffs fitted in sinfo_polyfit
+ at param note: this is a sinfo_vector of coefficients with the same 
+             index for all columns
+ at param dacoefs:      fit errors of the corresponding acoefs
+ at param bcoefs:       the fitted coefs
+ at param n_fitcoefs:   number of fit coefficients
+ at param sigma_factor: factor of sigma beyond which the column 
+                     coefficients are discarded for the fit
+ at return chisq, the found fit coefficients 
+*/
+
+float sinfo_new_coefs_cross_fit ( int      n_columns,
+                      float *  acoefs,
+                      float *  dacoefs,
+                      float *  bcoefs,
+                      int      n_fitcoefs,
+                      float    sigma_factor )
+{
+    float col_index;
+    float* sub_col_index=NULL ;
+    float* sub_acoefs=NULL ;
+    float* sub_dacoefs=NULL ;
+    float* wcoefs=NULL ;
+    float ** ucoefs, **vcoefs, **covar ;
+    float chisq ;
+    float * acoefsclean ;
+    double sum, sumq, mean ;
+    double sigma ;
+    double cliphi, cliplo ;
+    float offset ;
+    int i, n, num, ndata ;
+    int nc ;
+
+
+    if ( n_columns < 1 )
+    {
+        sinfo_msg_error(" wrong number of image columns given\n") ;
+        return FLT_MAX ;
+    }
+    if ( acoefs == NULL || dacoefs == NULL )
+    {
+        sinfo_msg_error(" coeffs or errors of coefficients are not given\n") ;
+        return FLT_MAX ;
+    }
+    if ( bcoefs == NULL )
+    {
+        sinfo_msg_error(" coeffs are not allocated\n") ;
+        return FLT_MAX ;
+    }
+
+    if ( n_fitcoefs < 1 )
+    {
+        sinfo_msg_error(" wrong number of fit coefficients\n") ;
+        return FLT_MAX ;
+    }
+    if ( sigma_factor <= 0. )
+    {
+        sinfo_msg_error(" impossible sigma_factor given!\n") ;
+        return FLT_MAX ;
+    }
+
+    offset = (float)(n_columns - 1) / 2. ;
+
+    /* ----------------------------------------------------------
+     * determine the clean mean and sigma value of the coefficients,
+     * that means reject 10 % of the extreme low and high values
+     */
+
+    wcoefs=cpl_calloc(n_fitcoefs,sizeof(float)) ;
+
+    nc = 0 ;
+    for ( i = 0 ; i < n_columns ; i++ )
+    {
+        if ( isnan(acoefs[i]) || acoefs[i] == 0. || dacoefs[i] == 0. )
+        {
+            continue ;
+        }
+        else
+        {
+            nc++ ;
+        }
+    }
+    acoefsclean = (float*) cpl_calloc(nc , sizeof(float)) ;
+    nc = 0 ;
+    for ( i = 0 ; i < n_columns ; i++ )
+    {
+        if ( isnan(acoefs[i]) || acoefs[i] == 0. || dacoefs[i] == 0. )
+        {
+            continue ;
+        }
+        else
+        {
+            acoefsclean[nc] = acoefs[i] ;
+            nc++ ;
+        }
+    }
+    sinfo_pixel_qsort(acoefsclean, nc) ;
+    sum   = 0. ;
+    sumq  = 0. ;
+    mean  = 0. ;
+    sigma = 0. ;
+    n     = 0 ;
+    for ( i = (int)((float)nc*LOW_REJECT) ; 
+          i < (int)((float)nc*HIGH_REJECT) ; i++ )
+    {
+        sum  += (double)acoefsclean[i] ;
+        sumq += ((double)acoefsclean[i] * (double)acoefsclean[i]) ;
+        n ++ ;
+    }
+    mean          = sum/(double)n ;
+    sigma         = sqrt( sumq/(double)n - (mean * mean) ) ;
+    cliphi        = mean + sigma * (double)sigma_factor ;
+    cliplo        = mean - sigma * (double)sigma_factor ;
+
+    sub_col_index=cpl_calloc(n_columns,sizeof(float)) ;
+    sub_acoefs=cpl_calloc(n_columns,sizeof(float));
+    sub_dacoefs=cpl_calloc(n_columns,sizeof(float)) ;
+
+    /* fit only the reasonnable values */
+    num = 0 ;
+    for ( i = 0 ; i < n_columns ; i++ )
+    {
+        /* associate the column indices to the corresponding array */
+        col_index = (float) i ;
+
+        /* take only the reasonnable coefficients */
+        if ( !isnan(acoefs[i]) && 
+             (acoefs[i] <= cliphi) && (acoefs[i] >= cliplo) &&
+             (dacoefs[i] != 0. ) && (acoefs[i] != 0.) )
+        {
+            sub_acoefs[num]    = acoefs[i] ;
+            sub_dacoefs[num]   = dacoefs[i] ;
+            sub_col_index[num] = col_index ;
+            num ++ ;
+        }
+    }
+    ndata = num ;
+
+    if ( ndata < n_fitcoefs )
+    {
+        sinfo_msg_error("not enough data found to determine "
+                        "the fit coefficients.\n") ;
+
+        return FLT_MAX ;
+    }
+
+    /* allocate coefficient matrices */
+    ucoefs = sinfo_matrix(1, ndata, 1, n_fitcoefs) ;
+    vcoefs = sinfo_matrix(1, ndata, 1, n_fitcoefs) ;
+    covar  = sinfo_matrix ( 1, n_fitcoefs, 1, n_fitcoefs ) ;
+
+    /* scale the x-values for the fit */
+    for ( i = 0 ; i < ndata ; i++ )
+    {
+        sub_col_index[i] = (sub_col_index[i] - offset) / offset ;
+    }
+
+    /* finally, do the singular value decomposition fit */
+    sinfo_svd_fitting ( sub_col_index-1, sub_acoefs-1, 
+                        sub_dacoefs-1, ndata, bcoefs-1,
+                        n_fitcoefs, ucoefs, vcoefs, 
+                        wcoefs-1, covar, &chisq, sinfo_fpol ) ;
+
+    /* scale the found coefficients */
+    for ( i = 0 ; i < n_fitcoefs ; i ++ )
+    {
+        bcoefs[i] /= pow(offset, i) ;
+    }
+
+    /* free memory */
+    cpl_free (acoefsclean) ;
+    sinfo_free_matrix( ucoefs, 1/*, ndata*/, 1/*, n_fitcoefs */) ;
+    sinfo_free_matrix( vcoefs, 1/*, ndata*/, 1/*, n_fitcoefs */) ;
+    sinfo_free_matrix ( covar, 1/*, n_fitcoefs*/, 1/*, n_fitcoefs*/ ) ;
+
+    cpl_free(sub_col_index) ;
+    cpl_free(sub_acoefs) ;
+    cpl_free(sub_dacoefs) ;
+    cpl_free(wcoefs) ;
+
+    return chisq ;
+}
+
+
+/**
+ at brief determines a wavelength calibration map
+ at name sinfo_new_wave_map()
+ at param lineImage:    image from a calibration emission lamp,
+ at param bcoefs:       transformed fit coefficients
+ at param n_a_fitcoefs: number of fit coefficients for the single  
+                     column fits lambda-position
+ at param n_b_fitcoefs: number of fit coefficients for the fits of
+                     the single a coefficients across the columns
+ at param wavelength:   wavelength list from lamp file
+ at param intensity:    corresponding line intensity from line list
+ at param n_lines:      number of lines in the list
+ at param magFactor:    magnifying factor of the image for FFT
+ at return wavelength calibration map image.
+ at doc this routine determines a wavelength calibration map frame 
+                   associating a wavelength value to 
+     each pixel by using the fit coefficients determined before.
+ */
+
+cpl_image * sinfo_new_wave_map( cpl_image * lineImage,
+                    float   ** bcoefs,
+                    int        n_a_fitcoefs,
+                    int        n_b_fitcoefs,
+                    float    * wavelength,
+                    float    * intensity,
+                    int        n_lines,
+                    int        magFactor)
+{
+    cpl_image * retImage ;
+    float cenpos, cenpix ;
+    float centreval, centrepix, wavelag ;
+    float  pixvalue ;
+    float a_initial ;
+    int i, j, k, l/*, m*/, line, col, row, found, sign ;
+    int var, maxlag, cmin, cmax, offset ;
+    double * result ;
+    float col_off ;
+    float angst ;
+    double xcorr_max ;
+    int delta ;
+
+    double* z=NULL ;
+    double* a=NULL ;
+    double*  wave=NULL ;
+    float* emline=NULL ;
+    float* spec=NULL ;
+    int ilx=0;
+    int ily=0;
+    int olx=0;
+    int oly=0;
+    float* pidata=NULL;
+    float* podata=NULL;
+
+
+    gsl_poly_complex_workspace * w ;
+    
+    if ( NULL == lineImage )
+    {
+        sinfo_msg_error("no image given\n") ;
+        return NULL ;
+    }
+    ilx=cpl_image_get_size_x(lineImage);
+    ily=cpl_image_get_size_y(lineImage);
+    pidata=cpl_image_get_data_float(lineImage);
+
+    if ( NULL == wavelength || n_lines <= 0 )
+    {
+        sinfo_msg_error("no wavelength list given\n") ;
+        return NULL ;
+    }
+
+    if ( NULL == intensity )
+    {
+        sinfo_msg_error("no intensity list given\n") ;
+        return NULL ;
+    }
+
+    if ( NULL == bcoefs )
+    {
+        sinfo_msg_error("no coefficients given\n") ;
+        return NULL ;
+    }
+
+    if ( magFactor <= 1 )
+    {
+        sinfo_msg_error("wrong magnifying factor given\n") ;
+        return NULL ;
+    }
+    
+    /* allocate memory */
+    if ( NULL == ( retImage = cpl_image_new( ilx, ily,CPL_TYPE_FLOAT ) ))
+    {
+        sinfo_msg_error("cannot allocate a new image\n");
+        return NULL ;
+    }
+    olx=cpl_image_get_size_x(retImage);
+    oly=cpl_image_get_size_y(retImage);
+    podata=cpl_image_get_data_float(retImage);
+
+
+    var    = (magFactor - 1)*(magFactor - 1) ;
+    offset = ily * (magFactor/4 + 1) ;
+
+    /* find out if Angstroem or microns are used */
+    if ( wavelength[0] > 10000. )
+    {
+    /* Angstroem */
+        angst = 10000. ;
+    }
+    else if ( wavelength[0] > 1000. && wavelength[0] < 10000. )
+    {
+    /* nanometers */
+    angst = 1000. ;
+    }
+    else
+    {
+    /* microns */
+    angst = 1. ;
+    }
+
+    z=cpl_calloc(2*(n_a_fitcoefs - 1),sizeof(double)) ;
+    a=cpl_calloc(n_a_fitcoefs,sizeof(double));
+    wave=cpl_calloc(n_lines,sizeof(double)) ;
+    emline=cpl_calloc(2*magFactor*ily,sizeof(float));
+    spec=cpl_calloc(2*magFactor*ily,sizeof(float)) ;
+
+    /* go through the image columns */
+    for ( col = 0 ; col < ilx ; col++ )
+    {
+        /* initialize the emline array for each column */
+        for ( i = 0 ; i < 2*magFactor*ily ; i++ )
+        {
+            emline[i] = 0. ;
+        }
+        col_off = (float)col - (float)(ilx-1)/2. ;
+
+        /* determine the coefficients by using the given bcoefs */
+        for ( i = 0 ; i < n_a_fitcoefs ; i++ ) 
+        {
+            /* initialize coefficients and solution */
+            a[i] = 0. ;
+            if (i < n_a_fitcoefs-1)
+            {
+                z[2*i] = 0. ;
+                z[2*i+1] = 0. ;
+            }
+            for ( j = 0 ; j < n_b_fitcoefs ; j++ )
+            {
+                a[i] += bcoefs[i][j] * pow(col_off, j) ;
+            }
+        }
+        a_initial = a[0] ;
+        
+        /* go through the lines and generate an artificial spectrum */
+        for ( line = 0 ; line < n_lines ; line++ )
+        {
+            /* go from Angstroem to micron */
+            wave[line] = wavelength[line]/angst ;
+
+            /* ---------------------------------------------------------------
+             * solve the polynomial for the exact offset of the line that means
+             * find the root of the polynomial of order n_fitcoefs - 1
+             */
+            a[0] = a_initial - wave[line] ;
+
+            if(NULL==(w=sinfo_gsl_poly_complex_workspace_alloc(n_a_fitcoefs)))
+            {
+                sinfo_msg_error("could not allocate complex workspace!") ;
+                cpl_image_delete(retImage) ;
+                return NULL ;
+            }
+            if (-1 == sinfo_gsl_poly_complex_solve(a, n_a_fitcoefs, w, z))
+            {
+                sinfo_msg_error("sinfo_gsl_poly_complex_solve did not work!") ;
+                cpl_image_delete(retImage) ;
+                return NULL ;
+            }
+            sinfo_gsl_poly_complex_workspace_free(w) ;
+
+            
+            j = 0 ;
+            found = -1 ;
+            for ( i = 0 ; i < n_a_fitcoefs - 1  ; i++ )
+            {
+                /* test for appropriate solution */
+                if( z[2*i] > (-1.)*(float) ily/2. && 
+                    z[2*i] < (float)ily/2. && z[2*i+1] == 0. )
+                {
+                    found = 2*i ;
+                    j ++ ;
+                }
+                else
+                {
+                    continue ;
+                } 
+            }
+            if ( j == 0 )
+            {
+                sinfo_msg_warning("no offset solution found "
+                                  "for line %d in column %d\n", line, col) ;
+                continue ;
+            } 
+            else if ( j == 1 )
+            {
+                cenpos = z[found] + (float) ily /2. ;
+            }
+            else
+            {
+                sinfo_msg_warning("two or more offset solutions found "
+                                  "for line %d in column %d\n", line, col) ;
+                continue ;
+            }
+             
+            /*---------------------------------------------------------------
+             * magnify image by the given factor add an additional offset 
+             */
+            cenpix = cenpos * (float) magFactor + (float) offset ;  
+            
+            /* determine max and min pixel limits over 
+               which line should be convolved */
+            cmin = (sinfo_new_nint(cenpix) - (var-1)) > 0 ? 
+                    sinfo_new_nint(cenpix) - (var-1) : 0 ;
+            cmax = (sinfo_new_nint(cenpix) + (var-1)) < 2*magFactor * ily ? 
+                    sinfo_new_nint(cenpix) + (var-1) :  2*magFactor * ily ;
+
+            /* convolve neon lines with Gaussian function */
+            for ( j = cmin ; j < cmax ; j++ )
+            {
+                emline[j] += intensity[line] * 
+                exp((double)(-0.5*(j-cenpix)*(j-cenpix))/(double)var) ;
+            }
+        }
+                
+        /*--------------------------------------------------------------------- 
+         * for each column, map the image data points onto an magFactor times 
+           bigger element grid for FFT in the cross sinfo_new_correlation, 
+           first initialize the two helping arrays for each new column.
+         */
+        for ( k = 0 ; k < 2*magFactor * ily ; k++ )
+        {
+            spec[k] =  0. ;
+        }
+   
+        /* now take the image data points of the column and put them 
+           into the spec array */
+        for ( row = 0 ; row < ily ; row++ ) /* go through the column */
+        {
+            /* insert 8 values for each image row (magnification) and 
+               add same offset as for emline array */
+            for ( l = 0 ; l < magFactor ; l++ )   
+        {
+            /* set bad pixels or negative values to zero */
+                if (!isnan(pidata[col + row * ilx]) &&
+                                (pidata[col + row * ilx] > 0.))
+                {
+                    spec[offset + l + (row * magFactor)] = 
+                pidata[col + row * ilx] ;     
+                }
+                else
+                {
+                    spec[offset + l + (row * magFactor)] = 0. ;
+                }
+            }
+    }
+ 
+        /* now call the cross sinfo_new_correlation routine */
+        if (NULL == (result = sinfo_new_xcorrel(spec, 2*magFactor * ily, 
+                                                emline, 2*magFactor * ily, 
+                                                magFactor * ily, &delta, 
+                                                &maxlag, &xcorr_max)) ) 
+        {
+        sinfo_msg_warning ("cross sinfo_new_correlation did not work,"
+                               " col: %d is set ZERO\n", col) ;
+            for ( row = 0 ; row < ily ; row++ )
+            {
+                podata[col + row * ilx] = ZERO ;
+            }
+            continue ;
+        }
+    
+        if ( xcorr_max <= 0. )
+        {
+            sinfo_msg_warning ("cross sinfo_new_correlation sum is negative,"
+                               " col: %d is set ZERO\n", col) ;
+            for ( row = 0 ; row < ily ; row++ )
+            {
+                podata[col + row * ilx] = ZERO ;
+            }
+            cpl_free(result) ;
+            continue ;
+        }
+
+        wavelag = (float) -delta / (float) magFactor ;
+        if ( fabs(wavelag) > (float)ily/20. )
+        {
+            sinfo_msg_warning("wave lag too big, col: %d is set ZERO\n", col) ;
+            for ( row = 0 ; row < ily ; row++ )
+            {
+                podata[col + row * ilx] = ZERO ;
+            }
+            cpl_free(result) ;
+        continue ;
+        }
+
+        /*-------------------------------------------------------------------- 
+         * determine new zero order coefficient centreval, of which the 
+           formula is determined by setting equal a polynomial shifted by 
+           wavelag with the same higher order coefficients and set the new 
+           zero order coefficient to get both sides of the equation 
+           approximately equal.
+         */ 
+        centreval = a_initial ;
+        for ( i = 1 ; i < n_a_fitcoefs ; i++ )
+        {
+            if ( i%2 == 0 )
+            {
+                sign = -1 ;
+            }
+            else
+            {
+                sign = 1 ;
+            }
+            centreval += (float)sign * a[i]*pow(wavelag, i) ;
+        }
+
+        /* prepare to write out wavelength as pixel values */
+        for ( row = 0 ; row < ily ; row++ )
+        {
+            centrepix = (float)row - ((float)ily - 1.)/2. ;
+            pixvalue = 0. ;
+            for ( i = 1 ; i < n_a_fitcoefs ; i++ )
+            {
+                pixvalue += a[i]*pow(centrepix, i) ; 
+            }
+            podata[col + row * ilx] = centreval + pixvalue ; 
+        }
+        cpl_free(result) ;   
+    }
+
+
+
+    cpl_free(z) ;
+    cpl_free(a) ;
+    cpl_free(wave) ;
+    cpl_free(emline) ;
+    cpl_free(spec) ;
+
+    return retImage ;
+}                    
+
+/**
+ at brief
+ at name sinfo_new_wavelength_calibration()
+ at param image:        merged image from a calibration emission lamp,
+ at param wave:         wavelength array read from the wavelength list
+ at param n_lines:      number of lines in the wavelength list
+ at param row_clean: resulting list of the row indices but without the
+                     lines that are too close to each other for the fit
+                     output of sinfo_findLines()
+ at param wavelength_clean: corrected wavelength list corresponding to
+                     the row_clean array
+                     output of sinfo_findLines()
+ at param n_found_lines: output of sinfo_findLines(): total number of 
+                      found emission lines
+ at param dispersion:   dispersion of spectrum: micron per pixel
+ at param halfWidth:    half width of the box where the line must sit
+ at param minAmplitude: minimum amplitude of the Gaussian to do the fit
+ at param max_residual: maximum residual value, beyond that value
+                     the polynomial lambda-position fit is rejected.
+ at param fwhm:         first guess for the full width of half maximum
+                     of the sinfo_gaussian line fit
+ at param n_a_fitcoefs: number of fit coefficients for the single
+                     column fits: lambda-position
+ at param n_b_fitcoefs: number of fit coefficients for the fits of
+                     the single a coefficients across the columns
+ at param sigmaFactor:  factor of the standard deviation of the determined
+                     polynomial coefficients of the columns beyond
+                     which these coefficients are not used to carry out
+                     the polynomial fit across the columns.
+ at param pixel_tolerance: maximum tolerated difference between estimated
+                     and fitted line positions.
+ at return 0 if all went o.k., -1 if something went wrong.
+        # bcoefs: array of cooefficients of the polynomial fit 
+                  across the columns.
+        # par: array of the resulting FitParams data structure
+ at doc this routine takes an image from a calibration emission lamp and 
+     delivers the fit coefficients of a polynomial fit across the columns 
+     of the coefficients of the polynomial line position fits as output. 
+     Furthermore it delivers an array of the fit parameters as output. This 
+     routine expects Nyquist sampled spectra (either an interleaved image 
+     or an image convolved with an
+     appropriate function in spectral direction)
+ */
+
+int sinfo_new_wavelength_calibration( cpl_image   * image,
+                           FitParams ** par ,
+                           float     ** bcoefs,
+                           float      * wave,
+                           int          n_lines,
+                           int       ** row_clean,
+                           float     ** wavelength_clean,
+                           int        * n_found_lines,
+                           float        dispersion,
+                           int          halfWidth,
+                           float        minAmplitude,
+                           float        max_residual,
+                           float        fwhm,
+                           int          n_a_fitcoefs,
+                           int          n_b_fitcoefs,
+                           float        sigmaFactor,
+                           float        pixel_tolerance )
+
+{
+    int          i, j, k ;
+    int          n_fit ;
+    int          n_reject ;
+    float     *  acoefs ;
+    float     *  dacoefs ;
+    float     ** abuf ;
+    float     ** dabuf ;
+    float        chisq_poly, chisq_cross ;
+    int          zeroind ;
+    /*float     *  mem ;*/
+    int lx=0;
+    int ly=0;
+    float* pdata=NULL;
+
+    if (  NULL == image )
+    {
+        sinfo_msg_error("no image given\n") ;
+        return -1 ;
+    }
+    lx=cpl_image_get_size_x(image);
+    ly=cpl_image_get_size_y(image);
+    pdata=cpl_image_get_data_float(image);
+
+    if ( par == NULL )
+    {
+        sinfo_msg_error("no fit parameter data structure given\n") ;
+        return -1 ;
+    }
+    if ( wave == NULL )
+    {
+        sinfo_msg_error("no wavelength list given\n") ;
+        return -1 ;
+    }
+    if ( n_lines <= 0 )
+    {
+        sinfo_msg_error("impossible number of lines in line list given\n") ;
+        return -1 ;
+    }
+    if ( row_clean == NULL )
+    {
+        sinfo_msg_error("no row_clean array given\n") ;
+        return -1 ;
+    }
+    if ( wavelength_clean == NULL )
+    {
+        sinfo_msg_error("no wavelength_clean array given\n") ;
+        return -1 ;
+    }
+
+    if ( dispersion == 0. )
+    {
+        sinfo_msg_error("impossible dispersion given\n") ;
+        return -1 ;
+    }
+
+    if ( halfWidth <= 0 || halfWidth > ly/2 )
+    {
+        sinfo_msg_error("impossible half width of the fitting box given\n") ;
+        return -1 ;
+    }
+    if ( minAmplitude < 1. )
+    {
+        sinfo_msg_error("impossible minimal amplitude\n") ;
+        return -1 ;
+    }
+
+    if ( max_residual <= 0. || max_residual > 1. )
+    {
+        sinfo_msg_error("impossible max_residual given\n") ;
+        return -1 ;
+    }
+
+    if ( fwhm <= 0. || fwhm > 10. )
+    {
+        sinfo_msg_error("impossible fwhm given\n") ;
+
+        return -1 ;
+    }
+
+    if ( n_a_fitcoefs <= 0 || n_a_fitcoefs > 9 )
+    {
+        sinfo_msg_error("unrealistic n_a_fitcoefs given\n") ;
+        return -1 ;
+    }
+
+    if ( n_b_fitcoefs <= 0 || n_b_fitcoefs > 9 )
+    {
+        sinfo_msg_error(" unrealistic n_b_fitcoefs given\n") ;
+        return -1 ;
+    }
+    if ( sigmaFactor <= 0. )
+    {
+        sinfo_msg_error(" impossible sigmaFactor given\n") ;
+        return -1 ;
+    }
+
+    /* initialize the variables */
+    n_reject = 0 ;
+    n_fit = 0 ;
+
+    /* fit each found line by using a Gaussian function and determine the 
+       exact position */
+    if ( 0 > (n_fit = sinfo_new_fit_lines( image , par, fwhm, 
+                                           n_found_lines, row_clean, 
+                                           wavelength_clean,
+                                halfWidth, minAmplitude )) )
+    {
+        sinfo_msg_error(" cannot fit the lines, "
+                        "error code of sinfo_fitLines: %d\n", n_fit) ;
+        return -1 ;
+    }
+
+    /* first check for faked lines like bad pixels */
+    if ( -1 == sinfo_new_check_for_fake_lines (par, dispersion, 
+                                               wavelength_clean, row_clean, 
+                                               n_found_lines,
+                                               lx, pixel_tolerance) )
+    {
+        sinfo_msg_error("cannot fit the lines, "
+                        "error code of sinfo_fitLines: %d", n_fit) ;
+        return -1 ;
+    }
+
+    /* allocate memory */
+    if (NULL == (acoefs = (float*) cpl_calloc (n_a_fitcoefs, sizeof(float*))) ||
+        NULL == (dacoefs = (float*)cpl_calloc (n_a_fitcoefs, sizeof(float*))) ||
+        NULL == (abuf = (float**) cpl_calloc (n_a_fitcoefs, sizeof(float*))) ||
+        NULL == (dabuf = (float**) cpl_calloc (n_a_fitcoefs, sizeof(float*))) )
+    {
+        sinfo_msg_error(" cannot allocate memory\n") ;
+        return -1 ;
+    }
+
+    for ( i = 0 ; i < n_a_fitcoefs ; i++ )
+    {
+        if ( NULL == (abuf[i] = (float*) cpl_calloc(lx, sizeof(float))) ||
+             NULL == (dabuf[i] = (float*) cpl_calloc(lx, sizeof(float))) )
+        {
+            sinfo_msg_error(" cannot allocate memory\n") ;
+            cpl_free(abuf) ;
+            cpl_free(dabuf) ;
+            return -1 ;
+        }
+    }
+
+    /* fit wavelengths to the corresponding found positions for each column */
+    k = 0 ;
+    
+    for ( i = 0 ; i < lx ; i++ )
+    {
+        zeroind = 0 ;
+        if ( FLT_MAX == (chisq_poly = sinfo_new_polyfit( par, i, 
+                                                         n_found_lines[i], 
+                                                         ly, dispersion,
+                                                         max_residual, acoefs, 
+                                                         dacoefs, &n_reject, 
+                                                         n_a_fitcoefs)) )
+        {
+      /* 
+           sinfo_msg_warning (" error in polyfitt in column: %d\n", i) ;
+       */
+            for ( j = 0 ; j < n_a_fitcoefs ; j++ )
+            {
+                acoefs[j] = ZERO ;
+                dacoefs[j] = ZERO ;
+            }
+        }
+
+        for ( j = 0 ; j < n_a_fitcoefs ; j++ )
+        {
+            if ( acoefs[0] <= 0. || acoefs[1] ==0. ||
+                 dacoefs[j] == 0. || isnan(acoefs[j]) )
+            {
+                zeroind = 1 ;
+
+            }
+        }
+        for ( j = 0 ; j < n_a_fitcoefs ; j++ )
+        {
+            if ( zeroind == 0 )
+            {
+                abuf[j][i]  = acoefs[j] ;
+                dabuf[j][i] = dacoefs[j] ;
+            }
+            else
+            {
+                abuf[j][i]  = ZERO ;
+                dabuf[j][i] = ZERO ;
+            }
+        }
+    }
+
+    /* fit each acoefs across the columns to smooth the result */
+    for ( i = 0 ; i < n_a_fitcoefs ; i++ )
+    {
+        if ( FLT_MAX == (chisq_cross = sinfo_new_coefs_cross_fit(lx, 
+                                                                 abuf[i], 
+                                                                 dabuf[i],
+                                                                 bcoefs[i],
+                                                                 n_b_fitcoefs,
+                                                                 sigmaFactor)))
+        {
+            sinfo_msg_error (" cannot carry out the fitting of coefficients"
+                             " across the columns, for the coefficient with"
+                             " index: %d\n", i) ;
+            for ( i = 0 ; i < n_a_fitcoefs ; i++ )
+            {
+                cpl_free (abuf[i]) ;
+                cpl_free (dabuf[i]) ;
+            }
+            cpl_free ( acoefs ) ;
+            cpl_free ( dacoefs ) ;
+            cpl_free ( abuf ) ;
+            cpl_free ( dabuf ) ;
+            return -1 ;
+        }
+    }
+
+    /* free all allocated memory */
+    for ( i = 0 ; i < n_a_fitcoefs ; i++ )
+    {
+        cpl_free (abuf[i]) ;
+        cpl_free (dabuf[i]) ;
+    }
+    cpl_free ( acoefs ) ;
+    cpl_free ( dacoefs ) ;
+    cpl_free ( abuf ) ;
+    cpl_free ( dabuf ) ;
+
+    return 0 ;   
+}
+
+                           
+/**
+ at brief
+ at name sinfo_new_convolve_image_by_gauss()
+ at param lineImage:  emission line image  
+ at param hw:         kernel half width of the sinfo_gaussian response function
+ at return emission line image convolved with a Gaussian
+ at doc convolves an emission line image with a Gaussian with user given 
+       integer half width by 
+     using the eclipse routine sinfo_function1d_filter_lowpass().
+*/
+
+cpl_image * sinfo_new_convolve_image_by_gauss( cpl_image * lineImage,
+                                 int        hw )
+{
+    cpl_image * returnImage ;
+    float* column_buffer=NULL ;
+    float * filter ;
+    int col, row ;
+    int ilx=0;
+    int ily=0;
+    int olx=0;
+    int oly=0;
+    float* pidata=NULL;
+    float* podata=NULL;
+
+    if ( lineImage == NULL )
+    {
+        sinfo_msg_error(" no input image given!\n") ;
+        return NULL ;
+    }
+    ilx=cpl_image_get_size_x(lineImage);
+    ily=cpl_image_get_size_y(lineImage);
+    pidata=cpl_image_get_data_float(lineImage);
+
+    if ( hw < 1 )
+    {
+        sinfo_msg_error(" wrong half width given!\n") ;
+        return NULL ;
+    }
+
+    /* allocate memory for returned image */
+    if ( NULL == ( returnImage = cpl_image_new(ilx,ily,CPL_TYPE_FLOAT ) ))
+    {
+        sinfo_msg_error(" cannot allocate a new image\n");
+        return NULL ;
+    }
+    olx=cpl_image_get_size_x(returnImage);
+    oly=cpl_image_get_size_y(returnImage);
+    podata=cpl_image_get_data_float(returnImage);
+
+    column_buffer=cpl_calloc(ily,sizeof(float)) ;
+
+    /* go through the image columns and save them in a buffer */
+    for ( col = 0 ; col < ilx ; col++ )
+    { 
+        for ( row = 0 ; row < ily ; row++ )
+        {
+            column_buffer[row] = pidata[col + row*ilx] ;
+        }
+         
+        /*--------------------------------------------------------------------- 
+         * now low pass filter the columns by the sinfo_gaussian and fill 
+           the return image.
+         */  
+        filter = sinfo_function1d_filter_lowpass( column_buffer,
+                                            ily,
+                                            LOW_PASS_GAUSSIAN,
+                                            hw ) ;
+        for ( row = 0 ; row < ily ; row++ )
+        {
+            podata[col + row*ilx] = filter[row] ;
+        }
+        sinfo_function1d_del(filter) ;
+    }
+                        
+    cpl_free(column_buffer);
+    return returnImage ;
+}
+
+/**
+ at brief Given a source image and a corresponding wavelength calibration 
+       file this routine produces an image in which elements in a given 
+       row are associated with a single wavelength.
+ at name sinfo_new_defined_resampling()
+ at param image:      source image to be calibrated
+ at param calimage:   wavelength map image 
+ at param n_params:   number of fit parameters for the polynomial interpolation 
+                   standard should be 3 that means order of polynom + 1
+ at param n_rows:     desired number of rows for the final image, 
+                   this will be the final number 
+                   of spectral pixels in the final data cube.
+ at param dispersion: dummy for the resulting dispersion
+ at param minval:     dummy for minimal wavelength value,
+ at param maxval:     dummy for maximal wavelength value 
+ at param centralLambda: dummy for the final central wavelength
+ at return # wavelength calibrated source image, 
+        # dispersion: resulting spectral dispersion (microns/pixel)
+                      is chosen as the minimum dispersion found in 
+                      the wavelength map - 2% of this value
+        # minval:     minimal wavelength value,
+        # maxval:     maximal wavelength value 
+        # centralLambda: final central wavelength value
+        # centralpix: row of central wavelength (in image coordinates!)
+ at doc Given a source image and a corresponding wavelength calibration file 
+     this routine produces an image in which elements in a given row are 
+     associated with a single wavelength. It thus corrects 
+     for the wavelength shifts between adjacent elements in the rows of 
+     the input image. The output image is larger in the wavelength domain 
+     than the input image with pixels in each column 
+     corresponding to undefined (blank, ZERO) values. The distribution of
+     these undefined values varies from column to column. The input image is
+     resampled at discrete wavelength intervals using
+     a polynomial interpolation routine. The wavelength intervals (dispersion) 
+     and the central wavelength are defined and stable for each used grating.
+     Thus, each row has a defined wavelength
+     for each grating. Only the number of rows can be changed by the user. 
+*/
+
+cpl_image * sinfo_new_defined_resampling( cpl_image * image,
+                              cpl_image * calimage,
+                              int        n_params,
+                              int*       n_rows,
+                              double   * dispersion,
+                              float    * minval,
+                              float    * maxval,
+                              double   * centralLambda,
+                              int    * centralpix )
+{
+    cpl_image * retImage ;
+    cpl_image * tempCalImage ;
+    cpl_image * tempImage ;
+    float lambda ;
+    float dif, lambda_renorm ;
+    float * retimagecol = NULL;//[2560] ; /* retimagecol[n_rows] ; */
+
+    float* imagecol=NULL ;
+    float* calcol=NULL ;
+    float* x_renorm=NULL ;
+
+    float * imageptr ;
+    float sum, new_sum ;
+    float disp, mindisp ;
+    int *calcolpos=NULL;//[2560];
+    int i/*, j*/, col, row, testrow ;
+    int half_width, firstpos ;
+    int dispInd ;
+    int n ;
+    int flag;
+    float temprow;
+    float minLambda = 0. ;
+    /*dpoint list[n_params] ;*/
+    /*double * polycoeffs ;*/
+    double poly ;
+    /*float error;*/
+    int zeroind ;
+    int ilx=0;
+    int ily=0;
+    int clx=0;
+    int cly=0;
+    int olx=0;
+    int oly=0;
+
+    float* podata=NULL;
+    float* pidata=NULL;
+    float* pcdata=NULL;
+    float* ptidata=NULL;
+    float* ptcdata=NULL;
+
+    if ( NULL == image )
+    {
+        sinfo_msg_error(" source image not given\n") ;
+        return NULL ;
+    }
+    ilx=cpl_image_get_size_x(image);
+    ily=cpl_image_get_size_y(image);
+    pidata=cpl_image_get_data_float(image);
+
+
+    if ( NULL == calimage )
+    {
+        sinfo_msg_error(" wavelength map image not given\n") ;
+        return NULL ;
+    }
+    clx=cpl_image_get_size_x(calimage);
+    cly=cpl_image_get_size_y(calimage);
+    pcdata=cpl_image_get_data_float(calimage);
+    if ( ilx != clx ||
+         ily != cly )
+    {
+        sinfo_msg_error("source image and wavelength map image "
+                        "are not compatible in size\n") ;
+        return NULL ;
+    }                              
+  
+    if ( n_params < 1 )
+    {
+        sinfo_msg_error (" wrong number of fit parameters given\n") ;
+        return NULL ;
+    }
+
+    if ( n_params > 4 )
+    {
+        sinfo_msg_warning(" attention: very high number of fit "
+                          "parameters given, not tested !!!\n") ;
+    }
+
+    imagecol=cpl_calloc(ily,sizeof(float)) ;
+    calcol=cpl_calloc(cly,sizeof(float)) ;
+    x_renorm=cpl_calloc(n_params,sizeof(float)) ;
+
+
+    /*if ( n_rows <= cly)
+    {
+        sinfo_msg_error (" number of rows of resampled image will be "
+                         " smaller than in wavelength calibration map,"
+                         " information would get lost!") ;
+        return NULL ;
+    }*/
+   
+    dispInd = 0 ;
+
+    /* first determine the dispersion direction */
+    for ( col = 0 ; col < clx ; col++ )
+    {
+        if ( isnan(pcdata[col]) || pcdata[col] <= 0. )
+        {
+            continue ;
+        }
+        if ((pcdata[col] - pcdata[col+(clx)*(cly-1)]) > 0. )
+        {
+           dispInd--  ;
+        }
+        else if ((pcdata[col] - pcdata[col+(clx)*(cly-1)]) < 0. )
+        {
+           dispInd++ ;
+        }
+        else
+        {
+            continue ;
+        }
+    }
+
+    if ( dispInd == 0 )
+    {
+        sinfo_msg_error(" zero dispersion?\n");
+        return NULL ;
+    }
+   
+    /* mirror the wavelength map and the raw image if 
+       the dispersion is negative */
+    if ( dispInd < 0 )
+    {
+
+        /* allocate a temp image */
+        if ( NULL == ( tempCalImage = cpl_image_new(clx,cly,CPL_TYPE_FLOAT)))
+        {
+            sinfo_msg_error(" cannot allocate a new image\n");
+            return NULL ;
+        }
+        ptcdata=cpl_image_get_data_float(tempCalImage);
+        if ( NULL == ( tempImage = cpl_image_new( ilx, ily,CPL_TYPE_FLOAT)))
+        {
+            sinfo_msg_error(" cannot allocate a new image\n");
+            cpl_image_delete(tempCalImage) ;
+            return NULL ;
+        }
+        ptidata=cpl_image_get_data_float(tempImage);
+
+        for ( col = 0 ; col < clx ; col++ )
+        {
+            n = cly - 1 ;
+            for ( row = 0 ; row < cly ; row++ )
+            {
+                ptcdata[col+row*clx] = pcdata[col+n*clx] ;
+                ptidata[col+row*clx] = pidata[col+n*clx] ;
+                n-- ;
+            }
+        }
+
+        for ( i = 0 ; i < (int) ilx*ily ; i++ )
+        {
+            pidata[i] = ptidata[i] ;
+            pcdata[i] = ptcdata[i] ;
+        }
+        cpl_image_delete(tempCalImage) ;
+        cpl_image_delete(tempImage) ;
+    }
+
+    /* determine the max and min pixel value in the first and the last row */
+    *maxval = -FLT_MAX ;
+    *minval =  FLT_MAX ;
+    mindisp = FLT_MAX ;
+    for ( col = 0 ; col < clx ; col++ )
+    {
+        if ( isnan(pcdata[col]) || pcdata[col] <= 0. )
+        {
+           continue ;
+        }
+        disp = (pcdata[col+(clx)*((cly)-1)]
+               - pcdata[col]) / (float)cly ;
+        if ( mindisp > disp )
+        {
+            mindisp = disp ;
+        }
+        if ( *minval >= pcdata[col] )
+        {
+            *minval = pcdata[col] ;
+        }
+        if ( *maxval <= pcdata[col + (clx)*((cly)-1)] )
+        {
+            *maxval = pcdata[col + (clx)*((cly)-1)] ;
+        }
+    }
+
+    /* find the used grating and set the dispersion to the defined value */
+    if (*minval > 1.9 )
+    {
+        if ( cly > 1024 && cly < 3000)
+        {
+            *dispersion = DISPERSION_K_DITH ;
+            *centralLambda = CENTRALLAMBDA_K ;
+        }
+        else if ( cly < 2000)
+        {
+            *dispersion = DISPERSION_K ;
+            *centralLambda = CENTRALLAMBDA_K ;
+        }
+        else
+        {
+            *dispersion = DISPERSION_K_DITH/2 ;
+            *centralLambda = CENTRALLAMBDA_K ;
+        }
+    }
+    else if (*minval < 1.2 )
+    {
+        if ( cly > 1024 )
+        {
+            *dispersion = DISPERSION_J_DITH ;
+            *centralLambda = CENTRALLAMBDA_J ;
+        }
+        else
+        {
+            *dispersion = DISPERSION_J ;
+            *centralLambda = CENTRALLAMBDA_J ;
+        }
+    }
+    else 
+    {
+        if ( *maxval > 2.3 )
+        {
+            if ( cly > 1024 )
+            {
+                *dispersion = DISPERSION_HK_DITH ;
+                *centralLambda = CENTRALLAMBDA_HK ;
+            }
+            else
+            {
+                *dispersion = DISPERSION_HK ;
+                *centralLambda = CENTRALLAMBDA_HK ;
+            }
+        }
+        else 
+        {
+            if ( cly > 1024 )
+            {
+                *dispersion = DISPERSION_H_DITH ;
+                *centralLambda = CENTRALLAMBDA_H ;
+            }
+            else
+            {
+                *dispersion = DISPERSION_H ;
+                *centralLambda = CENTRALLAMBDA_H ;
+            }
+        }
+    }
+
+    /*if ( *minval + (float)n_rows * *dispersion < *maxval ) 
+    {
+        sinfo_msg_error(" given number of rows too small!\n");
+        return NULL ;
+    }*/
+    if ( (*maxval - *minval) / *dispersion < (float)cly ) 
+    {
+        sinfo_msg_error(" must be something wrong with the wavelength map!\n");
+        return NULL ;
+    }
+   
+    /* determine the central pixel and the lambda in the first image row */
+    *n_rows = floor(floor(0.5+(*maxval - *minval) / *dispersion)/2+0.5)*2;
+    *centralpix = *n_rows / 2 ; 
+    minLambda  = *centralLambda - *dispersion * (float)*centralpix ;
+    /*if ( (minLambda + *dispersion * n_rows) < *maxval ) 
+    {
+        sinfo_msg_error(" not enough rows defined \n");
+        return NULL ;
+    }
+    if ( minLambda  > *minval ) 
+    {
+        sinfo_msg_error(" not enough rows defined \n");
+        return NULL ;
+    }*/
+
+    /* allocate memory */
+    if ( NULL == ( retImage = cpl_image_new( ilx, *n_rows,CPL_TYPE_FLOAT ) ))
+    {
+        sinfo_msg_error(" cannot allocate a new image\n");
+        return NULL ;
+    }
+    podata=cpl_image_get_data_float(retImage);
+    olx=cpl_image_get_size_x(retImage);
+    oly=cpl_image_get_size_y(retImage);
+    /* now go through the columns */
+    retimagecol = cpl_malloc(*n_rows * sizeof(retimagecol[0]));
+    calcolpos = cpl_malloc(*n_rows * sizeof(calcolpos[0]));    
+    for ( col = 0 ; col < olx ; col++ )
+    {
+        /*------------------------------------------------------------------ 
+         * copy the columns of the source image and the wavemap image into
+         * buffer arrays to speed things up
+         */
+        sum = 0. ;
+        for ( row = 0 ; row < ily ; row++ )
+        {
+            imagecol[row] = pidata[col + row*ilx] ; 
+            if (!isnan(imagecol[row]))
+            {
+                sum += imagecol[row] ;
+            }
+            calcol[row]   = pcdata[col + row*clx] ; 
+        }
+
+        for ( row = 0 ; row < oly ; row++ )
+        {
+            retimagecol[row] = 0. ;
+            calcolpos[row] = -1;
+        }
+
+    for ( row=0 ; row < cly ; row++)
+    {
+        temprow = (calcol[row]- minLambda)/ *dispersion;
+        if (temprow >= 0 && temprow < oly)
+            calcolpos[(int) temprow]  = row;
+    }
+        
+    zeroind = 0 ;
+       
+
+        for ( row = 0 ; row < oly ; row++ )
+        {
+            lambda = minLambda + *dispersion * (float) row ;
+      
+            /*--------------------------------------------------------------- 
+             * lambda must lie between the two available wavelength extremes
+             * otherwise the image pixels are set to ZERO 
+             */
+            if ( row < cly )
+            {
+                if ( isnan(calcol[row]) )
+                {
+                    zeroind = 1 ;
+                } 
+            }
+
+            if ( (lambda < calcol[0]) || 
+                 (lambda > calcol[(cly)-1]) || zeroind == 1 )
+            {
+                retimagecol[row] = ZERO ;
+                continue ;
+            }
+            /*testrow = 0 ; 
+            while ( lambda > calcol[testrow] )
+            {
+                testrow++ ;
+            }*/
+	    if (calcolpos[row]==-1) {
+                if(row>= (*n_rows-1)) calcolpos[row] = calcolpos[row-1];
+                if(row<  (*n_rows-1)) calcolpos[row] = calcolpos[row+1];
+	    }
+	    if(calcolpos[row]>0) {
+	      if (lambda-calcol[calcolpos[row]-1]==0.) {
+		calcolpos[row]=calcolpos[row]-1;
+	      }
+	    }
+	    testrow = calcolpos[row];
+
+            /*-----------------------------------------------------------------
+             * at this point calcol[testrow-1] < lambda <= calcol[testrow] 
+             * now determine the box position in which the polint fit is 
+               carried through.
+             * the half width of the box is half the number of fit parameters.
+             * Now we determine the start position of the fitting box and treat
+             * the special case of being near the sinfo_edge.
+             */
+
+            if ( n_params % 2 == 0 )
+            {
+                half_width = (int)(n_params/2) - 1 ;
+            }
+            else
+            {
+                half_width = (int)(n_params/2) ;
+            }
+
+
+            if ( isnan(imagecol[testrow]) )
+            {
+                for ( i = row-half_width ; i < row-half_width+n_params ; i++ )
+                { 
+                    if (i < 0) continue ;
+                    if ( i >= oly ) continue  ;
+                    retimagecol[i] = ZERO ;
+                }
+                imagecol[testrow] = 0. ;
+            }
+
+        }
+
+        /* now loop over the rows and establish the lambda for each row */
+        new_sum = 0. ;
+        for ( row = 0 ; row < oly ; row++ )
+        {
+            if ( isnan(retimagecol[row]) )
+            {
+                continue ;
+            }
+        lambda = minLambda + *dispersion * (float) row ;
+      
+            /*--------------------------------------------------------------- 
+             * lambda must lie between the two available wavelength extremes
+             * otherwise the image pixels are set to ZERO 
+             */
+            if ( (lambda < calcol[0]) || (lambda > calcol[(cly)-1]) ) 
+            {
+                retimagecol[row] = ZERO ;
+                continue ;
+            }
+            /*testrow = 0 ; 
+            while ( lambda > calcol[testrow] )
+            {
+                testrow++ ;
+            }*/
+        if (calcolpos[row]==-1) {
+               if(row >= (*n_rows-1)) calcolpos[row] = calcolpos[row-1];
+               if(row <  (*n_rows-1)) calcolpos[row] = calcolpos[row+1];
+        }
+
+        testrow = calcolpos[row];
+
+            /*--------------------------------------------------------------
+             * at this point calcol[testrow-1] < lambda <= calcol[testrow] 
+             * now determine the box position in which the polynomial 
+               interpolation is carried through.
+             * the half width of the box is half the number of fit parameters.
+             * Now we determine the start position of the fitting box and treat
+             * the special case of being near the sinfo_edge.
+             */
+
+            if ( n_params % 2 == 0 )
+            {
+                half_width = (int)(n_params/2) - 1 ;
+            }
+            else
+            {
+                half_width = (int)(n_params/2) ;
+            }
+
+            firstpos   = testrow - half_width ;
+            if ( firstpos < 0 )
+            {
+                firstpos = 0 ;
+            }
+            else if ( firstpos > ((cly)-n_params) )
+            {
+               firstpos = cly - n_params ;
+            }
+            if ( isnan(imagecol[firstpos]) )
+            {
+                retimagecol[row] = ZERO ;
+                continue ;
+            }
+            
+
+            /* we must rescale the x-values (smaller than 1) 
+               for the fitting routine */
+            dif = calcol[firstpos+n_params-1] - calcol[firstpos] ;
+            for ( i = 0 ; i < n_params ; i++ )
+            {
+            x_renorm[i] = (calcol[firstpos + i] - calcol[firstpos]) / dif ;
+        }
+        
+           
+            lambda_renorm = ( lambda - calcol[firstpos] ) / dif ; 
+        
+        imageptr = &imagecol[firstpos] ;
+        
+        flag = 0;
+        poly=sinfo_new_nev_ille(x_renorm, imageptr, 
+                                    n_params-1, lambda_renorm, &flag);
+        
+            new_sum += poly ;
+            retimagecol[row] = poly ; 
+    }
+    
+        /* now renorm the total flux */
+        for ( row = 0 ; row < oly ; row++ )
+        {
+            if ( new_sum == 0. ) new_sum = 1. ;
+            if ( isnan(retimagecol[row]) )
+            {
+                podata[col+row*olx] = ZERO ;
+            }
+            else
+            {
+                /* rescaling is commented out because it delivers wrong results
+                   in case of appearance of blanks or bad pixels */
+                podata[col+row*olx] = retimagecol[row] /* * sum/new_sum*/ ;
+            }
+        }
+
+    }
+    cpl_free(retimagecol);
+    cpl_free(calcolpos);
+    cpl_free(imagecol) ;
+    cpl_free(calcol) ;
+    cpl_free(x_renorm) ;
+    
+    return retImage ;
+}
+
+/**@}*/
+/*___oOo___*/
diff --git a/sinfoni/sinfo_wave_calibration.h b/sinfoni/sinfo_wave_calibration.h
new file mode 100644
index 0000000..9f1dac7
--- /dev/null
+++ b/sinfoni/sinfo_wave_calibration.h
@@ -0,0 +1,450 @@
+#ifndef SINFO_WAVE_CALIBRATION_H
+#define SINFO_WAVE_CALIBRATION_H
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*******************************************************************************
+* E.S.O. - VLT project
+*
+* "@(#) $Id: sinfo_wave_calibration.h,v 1.5 2008/03/25 08:20:43 amodigli Exp $"
+*
+* who       when      what
+* --------  --------  ----------------------------------------------
+* schreib  13/07/00  created
+*/
+
+/************************************************************************
+ * wave_calibration.h
+ * routines needed for wavelength calibration
+ *----------------------------------------------------------------------
+ */
+
+/*
+ * header files
+ */
+
+#include <cpl.h>
+#include "sinfo_wavecal.h"
+/*
+ * function prototypes
+ */
+
+/**
+   @name sinfo_new_fit_params()
+   @memo allocates memory for a new sinfo_vector of FitParams data structures
+   @param n_params number of parameters that will be fitted
+   @return allocated sinfo_vector of FitParams data structures
+*/
+
+FitParams ** 
+sinfo_new_fit_params( int n_params ) ;
+
+/**
+   @name      sinfo_new_destroy_fit_params()
+   @memo   frees memory of a sinfo_vector of FitParams data structures
+   @param     params  fit params to destroy
+   @return    void
+*/
+
+void 
+sinfo_new_destroy_fit_params ( FitParams *** params ) ;
+
+/**
+   @name   sinfo_new_dump_fit_params_to_ascii()
+   @memo   dumps the fit parameters to an ASCII file
+   @param  params fit params to dump
+   @param  filename
+   @return filled ASCII file
+*/
+
+void 
+sinfo_new_dump_fit_params_to_ascii ( FitParams ** params, const char * filename ) ;
+
+/**
+   @name   sinfo_new_dump_ascii_to_fit_params()
+   @memo   dumps ASCII information to an allocated FitParams data structure
+   @param  params allocated dummy for the fit params
+   @param  filename
+   @return params: filled FitParams object
+*/
+
+void 
+sinfo_new_dump_ascii_to_fit_params ( FitParams ** params, char * filename ) ;
+
+/**
+   @name  sinfo_new_find_lines()
+   @memo determines the pixel shift between the line list and the real image 
+         by using the beginning wavelength on the detector and the dispersion 
+         estimate.
+
+   @param lineImage merged emission line image,
+   @param wave_position wavelength list in Angstroems
+   @param wave_intensity corresponding intensity list
+   @param n_lines number of lines in list
+   @param row_clean resulting list of the row indices but without the
+                    lines that are too close to each other for the fit
+   @param wavelength_clean corrected wavelength list corresponding to
+                           the row_clean array
+   @param beginWave beginning wavelength on detector in microns
+   @param dispersion dispersion of the grating on the detector
+                     (microns per pixel, attention: merged image).
+   @param mindiff minimal difference of mean and sinfo_median column
+                  intensity to do the sinfo_correlation.
+                  This is done to avoid correlations in columns
+                  without emission line intensity.
+   @param halfWidth   half width of the box where the line must sit,
+   @param n_found_lines number of found and correlated
+                        emission lines in a column.
+   @param sigma sigma of Gaussian that is convolved with the artificial 
+          spectrum
+   @return 0 if all went o.k.
+   @param row resulting list of the row indices of the line positions
+   @param row_clean resulting list of the row indices but without the
+                    lines that are too close to each other for the fit
+   @param wavelength wavelength from the list corresponding to the
+                     found row positions
+   @param wavelength_clean corrected wavelength list corresponding to
+                           the row_clean array
+   @param n_found_lines number of found and correlated
+                        emission lines in a column.
+   @param sum_lines total sum of found and correlated emission lines
+                    INT32_MAX = 2^32/2 if something has gone wrong
+
+*/
+int 
+sinfo_new_find_lines(cpl_image * lineImage,
+               float    * wave_position,
+               float    * wave_intensity,
+               int        n_lines,
+               int     ** row_clean,
+               float   ** wavelength_clean,
+               float      beginWave,
+               float      dispersion1,
+               float      dispersion2,
+               float      mindiff,
+               int        halfWidth,
+               int      * n_found_lines,
+               float      sigma,
+               int      * sum_lines ) ;
+
+/**
+   @name   sinfo_new_read_list()
+   @memo   reads the line data  of the calibration lamps
+   @param  listname name of the list file, arrays to store the wavelength
+                    and the intensities of the emission lines
+   @return number of lines in file
+*/
+
+int 
+sinfo_new_read_list( char * listname, 
+                     float * lineCenter, 
+                     float * lineIntensity ) ;
+
+/**
+   @name    sinfo_new_line_fit()
+   @param   mergedImage image of a calibration emission lamp,
+   @param   par         dummys for the resulting fitting parameters,
+   @param   fwhm:        guess for full width of half maximum of Gaussian
+   @param   lineInd     index of the emission line,
+   @param   column      present index of the image column,
+   @param   halfWidth   half width of the box where the line must sit,
+   @param   lineRow     row index where the line is expected,
+   @param   min_amplitude minimum amplitude of the Gaussian with
+                          respect to the background to do the fit
+   @return  the fitting parameter data structure containing the resulting 
+         parameters. integers: number of iterations if all was ok,
+                   #    -8   if no input image was given,
+                   #    -9   if no dummy for the fit parameters is given,
+                   #    -10  if the wrong column index was given,
+                   #    -11  if the wrong box width was given,
+                   #    -12  if the wrong row index was given,
+                   #    -13  if a wrong minimum amplitude factor was given
+                   #    -14  if the spectral sinfo_vector data structure memory
+                             could not be allocated
+                   #     -15  wrong row index or box width was given,
+                   #     -16  negative peak or signal too low to fit
+                   #     -17 least squares fit failed
+   @doc   fits a Gaussian to a 1-dimensional slice of an image,
+          this routine uses the routine sinfo_lsqfit_c as a non-linear
+          least square fit method (Levenberg-Marquardt).
+*/
+
+int 
+sinfo_new_line_fit (cpl_image  * mergedImage,
+              FitParams * par,
+              float       fwhm,
+              int         lineInd,
+              int         column,
+              int         halfWidth,
+              int         lineRow,
+              float       min_amplitude,
+          Vector    *  line,
+          int       *  mpar,
+          float     *  xdat,
+          float     *  wdat ) ;
+
+/**
+   @name    sinfo_new_fit_lines
+   @param   line_image merged image of a calibration lamp ,
+   @param   allParams  allocated sinfo_vector of FitParams data structures,
+   @param   fwhm       guess for full width of half maximum of Gaussian,
+   @param   n_lines  number of neon lines that will be fitted in one column,
+   @param   row        list of the rows of the fitted lines
+   @param   wavelength list of wavelength corresponding to the found line rows
+   @param   width      list of the half widths
+                       around the corresponding rows to find line
+   @param   min_amplitude minimal amplitude of the Gaussian beyond which 
+              the fit is carried through.
+   @return filled FitParams data structure sinfo_vector, number of successfully
+           fitted lines, errors: negative integers resulting from the 
+           sinfo_linefit routine and:
+           # -18: no image given,
+           # -19: number of emission lines or number of slitlets is wrong,
+           # -20: sinfo_vector of the slitlet boundaries or of the line rows or
+                  of the half width are empty.
+           # -21: no wavelength array given.
+   @memo   calculates and stores the fit parameters of the neon
+           emission lines of a neon frame by using the sinfo_linefit routine.
+*/
+
+int 
+sinfo_new_fit_lines (cpl_image  *  line_image,
+               FitParams ** allParams,
+               float        fwhm,
+               int       *  n_lines,
+               int       ** row,
+               float     ** wavelength,
+               int          width,
+               float        min_amplitude ) ;
+
+/**
+   @name      sinfo_new_polyfit()
+   @memo    fits a second order polynom
+            lambda[i] = a1 + a2*pos[i] + a3*pos[i]^2
+            to determine the connection between the listed wavelength values 
+            and the gauss-fitted positions for each image column using the 
+            singular value decomposition method.
+
+   @param     par          filled array of fit parameter structure
+   @param     column       image column index
+   @param     n_lines      number of lines found in column
+   @param     n_rows       number of image rows
+   @param     dispersion   microns per pixel
+   @param     max_residual maximum residual value, beyond that value
+                           the fit is rejected.
+   @param     acoefs       array of the 3 coefficients of the fitted parabola
+   @param     dacoefs      variances of parabola coefficients  
+   @param     n_reject     rejected number of fits due to high residuals
+   @param     n_fitcoefs   number of polynomial coefficients to fit
+   @return   chisq        chi2 of polyfit
+*/
+
+float 
+sinfo_new_polyfit( FitParams ** par,
+               int          column,
+               int          n_lines,
+               int          n_rows,
+               float        dispersion,
+               float        max_residual,
+               float *      acoefs,
+               float *      dacoefs,
+               int   *      n_reject,
+               int          n_fitcoefs ) ;
+
+/**
+   @name     sinfo_new_coefs_cross_fit()
+   @param    n_columns    number of image columns
+   @param    acoefs       coeffs fitted in sinfo_polyfit
+   @param    dacoefs      fit errors of the corresponding acoefs
+   @param    bcoefs       the fitted coefs
+   @param    n_fitcoefs   number of fit coefficients
+   @param    sigma_factor factor of sigma beyond which the
+                          column coefficients are discarded for the fit
+
+   @return   chisq, the found fit coefficients
+   @doc      Fits the each single parameter of the three fit parameters
+             acoefs from sinfo_polyfit through the image columns
+   @note this is a vector of coefficients with the same index for all columns
+*/
+
+float 
+sinfo_new_coefs_cross_fit ( int      n_columns,
+                      float *  acoefs,
+                      float *  dacoefs,
+                      float *  bcoefs,
+                      int      n_fitcoefs,
+                      float    sigma_factor ) ;
+
+/**
+   @name   sinfo_new_wave_map()
+   @param  lineImage    image from a calibration emission lamp,
+   @param  bcoefs       transformed fit coefficients
+   @param  n_a_fitcoefs number of fit coefficients for the single
+                        column fits lambda-position
+   @param  n_b_fitcoefs number of fit coefficients for the fits of
+                        the single a coefficients across the columns
+   @param  wavelength   wavelength list from lamp file
+   @param  intensity    corresponding line intensity from line list
+   @param  n_lines      number of lines in the list
+   @param  magFactor    magnifying factor of the image for FFT
+   @return wavelength calibration map image.
+   @memo   determines a wavelength calibration map frame associating a 
+           wavelength value to each pixel by using the fit coefficients 
+           determined before.
+*/
+
+cpl_image * 
+sinfo_new_wave_map(cpl_image * lineImage,
+                    float   ** bcoefs,
+                    int        n_a_fitcoefs,
+                    int        n_b_fitcoefs,
+                    float    * wavelength,
+                    float    * intensity,
+                    int        n_lines,
+                    int        magFactor) ;
+
+/**
+   @name  sinfo_new_wavelength_calibration()
+   @memo  takes an image from a calibration emission lamp and delivers the fit 
+          coefficients of a polynomial fit across the columns of the 
+          coefficients of the polynomial line position fits as output. 
+          Furthermore it delivers an array of the fit parameters as output. 
+          This routine expects Nyquist sampled spectra (either an interleaved 
+          image or an image convolved with an appropriate function in spectral 
+          direction).
+
+   @param image merged image from a calibration emission lamp,
+   @param  par array of the resulting FitParams data structure
+   @param  bcoefs array of cooefficients of the polynomial fit 
+           across the columns.
+   @param wave  wavelength array read from the wavelength list
+   @param n_lines  number of lines in the wavelength list
+   @param row_clean resulting list of the row indices but without the
+                    lines that are too close to each other for the fit
+                    output of sinfo_findLines()
+   @param wavelength_clean corrected wavelength list corresponding to
+                           the row_clean array output of sinfo_findLines()
+   @param n_found_lines output of sinfo_findLines(): total number of 
+                        found emission lines
+   @param dispersion   dispersion of spectrum: micron per pixel
+   @param halfWidth    half width of the box where the line must sit
+   @param minAmplitude minimum amplitude of the Gaussian beyond which
+                       the fit is carried out
+   @param max_residual maximum residual value, beyond that value
+                       the polynomial lambda-position fit is rejected.
+   @param fwhm         first guess for the full width of half maximum
+                       of the sinfo_gaussian line fit
+   @param n_a_fitcoefs number of fit coefficients for the single
+                       column fits: lambda-position
+   @param n_b_fitcoefs number of fit coefficients for the fits of
+                       the single a coefficients across the columns
+   @param sigmaFactor  factor of the standard deviation of the determined
+                       polynomial coefficients of the columns beyond
+                       which these coefficients are not used to carry out
+                       the polynomial fit across the columns.
+   @param pixel_tolerance maximum tolerated difference between estimated
+                          and fitted line positions.
+   @return  0 if all went o.k., -1 if something went wrong.
+  */
+
+int 
+sinfo_new_wavelength_calibration(cpl_image   * image,
+                           FitParams ** par ,
+                           float     ** bcoefs,
+                           float      * wave,
+                           int          n_lines,
+                           int       ** row_clean,
+                           float     ** wavelength_clean,
+                           int        * n_found_lines,
+                           float        dispersion,
+                           int          halfWidth,
+                           float        minAmplitude,
+                           float        max_residual,
+                           float        fwhm,
+                           int          n_a_fitcoefs,
+                           int          n_b_fitcoefs,
+                           float        sigmaFactor,
+               float        pixel_tolerance ) ;
+
+/**
+   @name     sinfo_new_convolve_image_by_gauss()
+   @param    lineImage  emission line image
+   @param    hw         kernel half width of the sinfo_gaussian
+                        response function
+   @return   emission line image convolved with a sinfo_gaussian
+   @doc convolves an emission line image with a Gaussian with user given 
+        integer half width by using the eclipse routine 
+        sinfo_function1d_filter_lowpass().
+*/
+
+cpl_image * 
+sinfo_new_convolve_image_by_gauss(cpl_image * lineImage,
+                                 int        hw ) ;
+
+/**
+   @name    sinfo_new_defined_resampling()
+   @param   image      source image to be calibrated
+   @param   calimage   wavelength map image
+   @param   n_params   number of fit parameters for polynomial interpolation
+                       standard should be 3 that means order of polynom + 1
+   @param   n_rows     desired number of rows for the final image, this will be
+                       the final number of spectral pixels in the final data 
+                       cube.
+   @param dispersion   resulting spectral dispersion (microns/pixel)
+                       is chosen as the minimum dispersion found in
+                       the wavelength map - 2% of this value
+   @param minval       minimal wavelength value,
+   @param maxval       maximal wavelength value
+   @param centralLambda final central wavelength value
+   @param  centralpix    row of central wavelength (in image coordinates!)
+
+   @return wavelength   calibrated source image,
+
+   @doc   Given a source image and a corresponding wavelength
+          calibration file this routine produces an image
+          in which elements in a given row are associated
+          with a single wavelength. It thus corrects for
+          the wavelength shifts between adjacent elements
+          in the rows of the input image. The output image
+          is larger in the wavelength domain than the input
+          image with pixels in each column corresponding to
+          undefined (blank, ZERO) values. The distribution
+          of these undefined values varies from column to
+          column. The input image is resampled at discrete
+          wavelength intervals using the polynomial interpolation
+          routine.
+          The wavelength intervals (dispersion) and the
+          central wavelength are defined and stable for each
+          used grating. Thus, each row has a defined wavelength
+          for each grating. Only the number of rows can be
+          changed by the user.
+*/
+
+cpl_image * 
+sinfo_new_defined_resampling(cpl_image * image,
+                              cpl_image * calimage,
+                              int        n_params,
+                              int*        n_rows,
+                              double   * dispersion,
+                              float    * minval,
+                              float    * maxval,
+                              double   * centralLambda,
+                              int    * centralpix ) ;
+
+
+#endif /*!SINFO_WAVE_CALIBRATION_H*/
diff --git a/sinfoni/sinfo_wavecal.c b/sinfoni/sinfo_wavecal.c
new file mode 100644
index 0000000..8969cc6
--- /dev/null
+++ b/sinfoni/sinfo_wavecal.c
@@ -0,0 +1,3889 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*************************************************************************
+* E.S.O. - VLT project
+*
+* 
+*
+* who       when      what
+* --------  --------  ----------------------------------------------
+* schreib  22/01/02  created
+*/
+
+/************************************************************************
+*   NAME
+*     sinfo_wavecal.c -
+*     routines needed for wavelength calibration with smoothing only
+*     within the slitlets
+*
+*   SYNOPSIS
+*  1) Bcoeffs * sinfo_new_b_coeffs( int n_slitlets,
+*                           int n_acoeffs,
+*                           int n_bcoeffs )
+*  2) void sinfo_new_destroy_b_coeffs ( Bcoeffs * bco )
+*  3) int   sinfo_new_coeffs_cross_slit_fit ( int      n_columns,
+*                                float ** acoefs,
+*                                float ** dacoefs,
+*                                Bcoeffs* bco,
+*                                float    sigma_factor,
+*                                float    dispersion,
+*                                float    pixel_dist,
+*                                float  * chisq )
+*  4) cpl_image * sinfo_new_wave_map_slit ( float ** acoefs,
+*                              int      n_acoefs,
+*                              int      n_rows,
+*                              int      n_columns )
+*  5) cpl_image * sinfo_new_wave_cal( cpl_image   * image, 
+*                         FitParams ** par ,
+*                         float     ** abuf,
+*                         int          n_slitlets,
+*                         int       ** row_clean,
+*                         float     ** wavelength_clean,
+*                         int        * n_found_lines,
+*                         float        dispersion,
+*                         int          halfWidth,
+*                         float        minAmplitude,
+*                         float        max_residual,
+*                         float        fwhm,
+*                         int          n_a_fitcoefs,
+*                         int          n_b_fitcoefs,
+*                         float        sigmaFactor,
+*                         float        pixel_dist )
+*  6) int sinfo_new_check_for_fake_lines ( FitParams ** par,
+*                             float        dispersion,
+*                             float     ** wavelength_clean,
+*                             int       ** row_clean,
+*                             int        * n_found_lines,
+*                             int          n_columns,
+*                             float        pixel_tolerance )
+*  7) cpl_image * sinfo_new_create_shifted_slit_wavemap ( cpl_image * lineIm,
+*                                           float    ** coeffs,
+*                                           int      n_fitcoeffs,
+*                                           float  * wavelength,
+*                                           float  * intensity,
+*                                           int      n_lines,
+*                                           int      magFactor )
+*   
+*   DESCRIPTION
+*  1) allocates memory for a new array of 
+*     Bcoeffs data structures
+*  2) frees memory of an array of Bcoeffs data structures
+*  3) Fits each single polynomial coefficient acoefs resulting from 
+      sinfo_polyfit 
+*     across the columns of each slitlet and use the result of this fit to
+*     smooth the acoefs.
+*  4) builds a new wavelength calibration map as fits image
+*     by using the fit coeficients.
+*  5) this routine takes an image from a calibration
+*     emission lamp and delivers the smoothed fit coefficients of  
+*     a polynomial fit along the columns of the line positions as output. 
+*     This routine expects Nyquist sampled spectra 
+*     (either an interleaved image or an image convolved with an 
+*      appropriate function in spectral direction)
+*  6) this routine searches for successfully fitted fake lines like
+*     bad pixels by comparing the found line positons with 
+*     estimated template positions. This routine should be
+*     inserted in the wavelength calibration routine just after
+*     the sinfo_fitLines() routine.
+*  7) This routine cross-correlates a shifted emission line frames 
+*     and determines the shift to the old one which is given by
+*     its polynomial coefficients.
+*     Then the a0 coefficients is recalculated and afterwards
+*     a new wavelength calibration map is generated using the 
+*     already calculated smoothed polynomial coefficients.
+*
+*   FILES
+*
+*   ENVIRONMENT
+*
+*   RETURN VALUES 
+*
+*   CAUTIONS 
+*
+*   EXAMPLES
+*
+*   SEE ALSO
+*
+*   BUGS   
+*
+*------------------------------------------------------------------------
+*/
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+#include "sinfo_vltPort.h"
+#include <math.h>
+
+/* 
+ * System Headers
+ */
+/* 
+ * Local Headers
+ */
+
+#include "sinfo_function_1d.h"
+#include "sinfo_recipes.h"
+#include "sinfo_wavecal.h"
+#include "sinfo_wave_calibration.h"
+#include "sinfo_solve_poly_root.h"
+#include "sinfo_utils_wrappers.h"
+#include "sinfo_error.h"
+
+#include "sinfo_svd.h"
+/*
+ * Private functions prototype
+ */
+static Bcoeffs * 
+sinfo_new_b_coeffs( int n_slitlets,
+                      int n_acoeffs,
+                      int n_bcoeffs ) ;
+
+static void 
+sinfo_new_destroy_b_coeffs ( Bcoeffs * bco ) ;
+
+static int   
+sinfo_new_coeffs_cross_slit_fit ( int      n_columns,
+                           float ** acoefs,
+                           float ** dacoefs,
+                           Bcoeffs* bco,
+                           float    sigma_factor,
+                           float    dispersion,
+                           float    pixel_dist,
+                           float  * chisq ) ;
+
+
+static int   
+sinfo_new_spred_coeffs_cross_slit_fit ( int      n_columns,
+                            float ** acoefs,
+                            float ** dacoefs,
+                            Bcoeffs* bco,
+                            float    sigma_factor,
+                            float    dispersion,
+                            float    pixel_dist,
+                            float  * chisq,
+                          float ** sinfo_slit_pos) ;
+/*
+ * function definitions
+ */
+/**@{*/
+/**
+ * @addtogroup sinfo_rec_wavecal wavelength calibration functions
+ *
+ * TBD
+ */
+/**
+   @brief allocates memory for a new array of Bcoeffs data structures
+   @name   sinfo_new_b_coeffs()
+   @param  n_slitlets: number of slitlets
+   @param  n_acoeffs: number of acoeffs
+   @param  n_bcoeffs: number of bcoeffs
+   @return allocated array of Bcoeffs data structures
+ */
+
+static Bcoeffs * 
+sinfo_new_b_coeffs( int n_slitlets,
+                      int n_acoeffs,
+                      int n_bcoeffs )
+{
+    int i, n ;
+    Bcoeffs * returnbco ;
+
+    if(NULL == (returnbco=(Bcoeffs*) cpl_calloc(n_slitlets, sizeof(Bcoeffs))) )
+    {
+        sinfo_msg_error ("could not allocate memory") ;
+        return NULL ;
+    }
+    returnbco -> n_slitlets = n_slitlets ;
+    returnbco -> n_acoeffs  = n_acoeffs ;
+    returnbco -> n_bcoeffs  = n_bcoeffs ;
+    for ( i = 0 ; i < n_slitlets ; i++ )
+    {
+        returnbco[i].slitlet = i ;
+        if ( NULL == (returnbco[i].b = (float**)cpl_calloc(n_acoeffs, 
+                                                sizeof(float*)) ) ) 
+        {
+            sinfo_msg_error ("could not allocate memory") ;
+            return NULL ;
+        }
+        for ( n = 0 ; n < n_acoeffs ; n++ )
+        {
+            if ( NULL == (returnbco[i].b[n] = (float*)cpl_calloc(n_bcoeffs, 
+                                               sizeof(float))) )
+            {
+                sinfo_msg_error ("could not allocate memory") ;
+                return NULL ;
+            }
+        }  
+    }
+    return returnbco ;
+}
+
+/**
+ at brief frees memory of an array of Bcoeffs data structures
+ at name sinfo_new_destroy_b_coeffs()
+ at param bcoeffs to destroy
+ at return nothing
+*/
+
+static void 
+sinfo_new_destroy_b_coeffs ( Bcoeffs * bco )
+{
+    int i, n ;
+  
+    for ( i = 0 ; i < bco->n_slitlets ; i++ )
+    {
+        for ( n = 0 ; n < bco->n_acoeffs ; n++ )
+        {
+            cpl_free (bco[i].b[n]) ;
+        }
+        cpl_free(bco[i].b) ;
+    }
+    
+    cpl_free (bco) ;  
+}
+
+/**
+ at brief Fits each single polynomial coefficient acoefs resulting from 
+       polyfit across the columns of each slitlet and use the result 
+       of this fit to smooth the acoefs.
+ at name  sinfo_new_coeffs_cross_slit_fit()
+ at param n_columns:    number of image columns
+ at param acoefs:       coeffs fitted in sinfo_polyfit
+ at note: this is a sinfo_matrix of the polynomial
+       coefficients, each index for each column:
+       acoefs[index][column]
+ at param dacoefs:      fit errors of the corresponding acoefs
+ at param bco:          the fitted Bcoeffs data structure for each slitlet
+ at param sigma_factor: factor of sigma beyond which the
+       column coefficients are discarded for the fit
+ at param dispersion:   estimate of the dispersion
+ at param pixel_dist:   estimate of minimal pixel distance in spectral 
+                     direction between slitlets
+ at return 
+           # 0 if all went o.k
+           # -1 if an error occurred
+           # the found fit coefficients bco data structure to calculate
+           # the smoothed acoefs
+           # chisq:        list of the chi squared of each fit for each slitlet
+ */
+
+static int   
+sinfo_new_coeffs_cross_slit_fit ( int      n_columns,
+                           float ** acoefs,
+                           float ** dacoefs,
+                           Bcoeffs* bco,
+                           float    sigma_factor,
+                           float    dispersion,
+                           float    pixel_dist,
+                           float  * chisq )
+{
+    float col_index;
+    float ** ucoefs, **vcoefs, **covar ;
+    float * acoefsclean ;
+    double sum, sumq, mean ;
+    double sigma ;
+    double cliphi, cliplo ;
+    float offset ;
+    float threshold ;
+    float* sub_col_index=NULL ;
+    float* sub_acoefs=NULL;
+    float* sub_dacoefs=NULL ;
+    float* wcoefs=NULL ;
+    int* edge=NULL ;
+
+    int ed1, ed2 ;
+    int i, n, num, ndata ;
+    int nc, ns ;
+    int loc_index ;
+    int last_i=PIXEL;
+    
+    if ( n_columns < 1 )
+    {
+        sinfo_msg_error("wrong number of image columns given") ;
+        return -1 ;
+    }
+    if ( acoefs == NULL || dacoefs == NULL )
+    {
+        sinfo_msg_error("acoeffs or errors of coefficients are not given") ;
+        return -1 ;
+    }
+    if ( bco == NULL )
+    {
+        sinfo_msg_error("bcoeffs are not allocated") ;
+        return -1 ;
+    }
+    if ( sigma_factor <= 0. )
+    {
+        sinfo_msg_error("impossible sigma_factor given!") ;
+        return -1 ;
+    }
+    if ( dispersion == 0. )
+    {
+        sinfo_msg_error("impossible dispersion given!") ;
+        return -1 ;
+    }
+
+    /*-------------------------------------------------------------------------
+     * search for the slitlet edges by comparing the a0 coefficients along 
+       the columns if a bigger deviation occurrs it is assumed that there 
+       is an edge.
+     */
+
+    edge=cpl_calloc(bco->n_slitlets,sizeof(int)) ;
+    wcoefs=cpl_calloc(bco->n_bcoeffs,sizeof(float)) ;
+
+    n = 0 ;
+    threshold = pixel_dist * fabs(dispersion) ;
+    for ( i = PIXEL ; i < n_columns - PIXEL ; )
+    {
+        if ( !isnan(acoefs[0][i+1]) && 
+                    acoefs[0][i+1] != 0. && 
+                    acoefs[0][i] != 0.  &&
+                    dacoefs[0][i+1] != 0.)
+        {
+            if ( isnan(acoefs[0][i]) || acoefs[0][i] == 0. )
+            {
+                if (fabs(acoefs[0][i+1] - acoefs[0][i-1]) >= threshold )
+                {
+           if( (i-last_i) < 60 && (i > 80) ) {
+             sinfo_msg_warning("skip1 i=%d diff=%d\n",i,i-last_i);
+             goto skip;
+                   } else {  
+             /*
+                 sinfo_msg("diff1=%f i=%d threshold-%f size=%d\n", 
+                               fabs(acoefs[0][i+1] - acoefs[0][i-1]),i,
+                               threshold,i-last_i);
+             */
+                     edge[n] = i+1 ;
+             //sinfo_msg("1found edge: %d",edge[n]);
+                     n++ ;
+                     last_i = i;
+                     i += PIXEL ;
+           }
+                }
+            }
+            else
+            {
+                if ((fabs(acoefs[0][i+1] - acoefs[0][i]) >= threshold) || 
+                    (i-last_i) > 63 )
+                {
+           if( (i-last_i) < 60 && ((i> 80) || (i<PIXEL+2))) {
+             sinfo_msg_warning("skip2 i=%d diff=%d\n",i,i-last_i);
+             goto skip;
+                   } else {  
+                      
+             /*
+                      sinfo_msg_warning("diff2=%f i=%d threshold-%f size=%d",
+                      fabs(acoefs[0][i+1] - acoefs[0][i]),
+                      i,threshold,i-last_i);                      
+                      */
+              
+ 
+                  
+                      edge[n] = i+1 ;
+                //sinfo_msg("2found edge: %d",edge[n]);
+                      n++ ;
+                      last_i = i;
+                      i += PIXEL ;
+           }
+                }
+            }
+        /* sometimes a slitlet may be lost due to divergences in acoeffs[0]
+               we try to recover it */
+            if( ( (i-last_i) > 63 ) && 
+                ( isnan(fabs(acoefs[0][i+1] - acoefs[0][i])) ||
+                  isnan(fabs(acoefs[0][i+1] - acoefs[0][i-1])) ) ) 
+          {
+        edge[n] = i+1 ;
+        //sinfo_msg("3found edge: %d",edge[n]);
+        n++ ;
+        last_i = i;
+                sinfo_msg_warning("recovered slitlet edge i=%d",i);
+        i += PIXEL ;
+
+          }
+    }
+      skip:
+        i++ ;
+    }
+    /*
+    printf("X min %d max %d last %d\n", PIXEL, n_columns - PIXEL, i);
+    printf("n=%d check=%d\n",n,bco->n_slitlets - 1);
+    */
+    if ( n != bco->n_slitlets - 1 )
+    {
+        sinfo_msg_error("could not find the right number "
+                        "of slitlets, found: %d",n+1) ;
+        return -1 ;
+    }
+ 
+    sub_col_index=cpl_calloc(n_columns,sizeof(float)) ;
+    sub_acoefs=cpl_calloc(n_columns,sizeof(float));
+    sub_dacoefs=cpl_calloc(n_columns,sizeof(float)) ;
+
+    /* go through the coefficents indices */
+    for ( loc_index = 0 ; loc_index < bco->n_acoeffs ; loc_index++ )
+    {
+        /* go through the single slitlets */
+        for ( ns = 0 ; ns < bco->n_slitlets ; ns++ )
+        {
+            /* determine the slitlet edges */
+            if ( ns == 0 )
+            {
+                ed1 = 0 ;
+                ed2 = edge[0] ;
+            }
+            else if ( ns == bco->n_slitlets - 1 )
+            {
+                ed1 = edge[bco->n_slitlets - 2] ;
+                ed2 = n_columns ;
+            }
+            else
+            {
+                ed1 = edge[ns-1] ;
+                ed2 = edge[ns] ;
+            }
+
+            nc = 0 ;
+            for ( i = ed1 ; i < ed2 ; i++ )
+            {
+                if ( isnan(acoefs[loc_index][i]) || 
+                           acoefs[loc_index][i] == 0. || 
+                          dacoefs[loc_index][i] == 0. )
+                {
+                    continue ;
+                }
+                else
+                {
+                    nc++ ;
+                }
+            }
+            if (NULL==(acoefsclean = (float*) cpl_calloc(nc , sizeof(float))) )
+            {
+                sinfo_msg_error("could not allocate memory for acoefsclean!") ;
+                return -1 ;
+            }
+            nc = 0 ;
+            for ( i = ed1 ; i < ed2 ; i++ )
+            {
+                if ( isnan(acoefs[loc_index][i]) || 
+                      acoefs[loc_index][i] == 0. || 
+                     dacoefs[loc_index][i] == 0. )
+                {
+                    continue ;
+                }
+                else
+                {
+                    acoefsclean[nc] = acoefs[loc_index][i] ;
+                    nc++ ;
+                }
+            }
+
+            /* ----------------------------------------------------------
+             * determine the clean mean and sigma value of the coefficients,
+             * that means reject 10 % of the extreme low and high values
+             */
+            sinfo_pixel_qsort(acoefsclean, nc) ;
+
+            sum   = 0. ;
+            sumq  = 0. ;
+            mean  = 0. ;
+            sigma = 0. ;
+            n     = 0 ;
+            for ( i = (int)((float)nc*LOW_REJECT) ; 
+                  i < (int)((float)nc*HIGH_REJECT) ; i++ )
+            {
+                sum  += (double)acoefsclean[i] ;
+                sumq += ((double)acoefsclean[i] * (double)acoefsclean[i]) ;
+                n ++ ;
+            }
+            mean          = sum/(double)n ;
+            sigma         = sqrt( sumq/(double)n - (mean * mean) ) ;
+            cliphi        = mean + sigma * (double)sigma_factor ;
+            cliplo        = mean - sigma * (double)sigma_factor ;
+            /* fit only the reasonnable values */
+            num = 0 ;
+            col_index = 0 ;
+            /*
+            printf("ed1=%d ed2=%d\n",ed1,ed2);
+        */
+            for ( i = ed1 ; i < ed2 ; i++ )
+            {
+                /* take only the reasonnable coefficients */
+                 /*
+        printf("acoeffs=%f dacoefs=%f cliphi=%f cliplo=%f\n",
+                   acoefs[loc_index][i],dacoefs[loc_index][i],cliphi,cliplo);
+         */
+                if ( !isnan(acoefs[loc_index][i])     && 
+                     (acoefs[loc_index][i] <= cliphi) && 
+                     (acoefs[loc_index][i] >= cliplo) &&
+                     (dacoefs[loc_index][i] != 0. )   && 
+                     (acoefs[loc_index][i] != 0.)     )
+                {
+                    sub_acoefs[num]    = acoefs[loc_index][i] ;
+                    sub_dacoefs[num]   = dacoefs[loc_index][i] ;
+                    sub_col_index[num] = col_index ;
+                    num ++ ;
+                }
+                col_index++ ;
+            }
+            ndata = num ;
+            offset = (float)(col_index-1) / 2. ;
+            /* printf("ndata=%d bco->n_bcoeffs=%d\n",ndata,bco->n_bcoeffs); */
+
+            if ( ndata < bco->n_bcoeffs )
+            {
+                sinfo_msg_error("not enough data found in slitlet %d to "
+                                "determine the fit coefficients.", ns) ;
+                cpl_free(acoefsclean) ;
+                return -1 ;
+            }
+
+            /* allocate coefficient matrices */
+            ucoefs = sinfo_matrix(1, ndata, 1, bco->n_bcoeffs) ;
+            vcoefs = sinfo_matrix(1, ndata, 1, bco->n_bcoeffs) ;
+            covar  = sinfo_matrix(1, bco->n_bcoeffs, 1, bco->n_bcoeffs) ;
+
+            /* scale the x-values for the fit */
+            for ( i = 0 ; i < ndata ; i++ )
+            {
+                sub_col_index[i] = (sub_col_index[i] - offset) / offset ;
+            }
+
+            /* finally, do the singular value decomposition fit */
+            sinfo_svd_fitting ( sub_col_index-1, sub_acoefs-1, 
+                                sub_dacoefs-1, ndata, bco[ns].b[loc_index]-1,
+                                bco->n_bcoeffs, ucoefs, vcoefs, 
+                                wcoefs-1, covar, &chisq[ns], sinfo_fpol ) ;
+
+            /* scale the found coefficients */
+            for ( i = 0 ; i < bco->n_bcoeffs ; i ++ )
+            {
+                bco[ns].b[loc_index][i] /= pow( offset, i ) ;
+            }
+
+            /* free memory */
+            cpl_free (acoefsclean) ;
+            sinfo_free_matrix( ucoefs, 1/*, ndata*/, 1/*, bco->n_bcoeffs */) ;
+            sinfo_free_matrix( vcoefs, 1/*, ndata*/, 1/*, bco->n_bcoeffs */) ;
+            sinfo_free_matrix( covar, 1/*, bco->n_bcoeffs*/, 
+                                1/*, bco->n_bcoeffs */) ;
+
+            /* now calculate the smoothed acoefs for each column */
+            col_index = 0 ;
+            for ( i = ed1 ; i < ed2  ; i++ )
+            {
+                acoefs[loc_index][i] = 0. ;
+                for ( n = 0 ; n < bco->n_bcoeffs ; n++ )
+                {
+                    acoefs[loc_index][i] += bco[ns].b[loc_index][n] * 
+                                        pow(col_index - offset, n) ;
+                }
+                col_index++ ;
+            }
+
+        }
+    }
+
+    cpl_free(sub_col_index) ;
+    cpl_free(sub_acoefs) ;
+    cpl_free(sub_dacoefs) ;
+
+
+    cpl_free(edge) ;
+    cpl_free(wcoefs) ;
+
+    return 0 ;
+}
+
+
+/**
+ at brief builds a new wavelength calibration map as fits image by using 
+       the fit coeficients
+ at name sinfo_new_wave_map_slit()
+ at param acoefs: fit coefficient sinfo_matrix: output of 
+               sinfo_coeffsCrossSlitFit()
+ at param n_acoefs: number of acoefs, polynomial order + 1
+ at param n_rows: number of final image rows
+ at param n_columns: number of final image columns
+ at return wavemap calibration map image
+*/
+
+cpl_image * sinfo_new_wave_map_slit ( float ** acoefs,
+                         int      n_acoefs,
+                         int      n_rows,
+                         int      n_columns )
+{
+    cpl_image * newIm=NULL ;
+    float lambda=0 ;
+    float offset=0 ;
+    int col=0;
+    int row=0 ;
+    int i=0 ;
+    float row_index=0 ;
+    float* podata=NULL;
+    if ( NULL == acoefs )
+    {
+        sinfo_msg_error (" no coefficient sinfo_matrix given!") ;
+        return NULL ;
+    }
+
+    /* allocate new image */
+    if ( NULL == (newIm = cpl_image_new(n_columns , n_rows,CPL_TYPE_FLOAT)) )
+    {
+        sinfo_msg_error ("could not allocate new image!") ;
+        return NULL ;
+    }
+    podata=cpl_image_get_data_float(newIm);
+
+    /* make the parabola symmetric to the image */
+    offset = (float)(n_rows - 1) / 2. ; 
+
+    /* go through the rows */
+    for ( col = 0 ; col < n_columns ; col++ )
+    {
+        /* go through the columns */
+        for ( row = 0 ; row < n_rows ; row++ )
+        {
+            lambda = 0. ;
+            row_index = (float)row - offset ;
+            for ( i = 0 ; i < n_acoefs ; i++ )
+            {
+                lambda += acoefs[i][col] * pow(row_index, i) ;
+            }
+            podata[col+row*n_columns] = lambda ;
+        }
+    }
+    return newIm ;
+}
+
+
+/**
+ at brief takes an image from a calibration emission lamp and delivers the 
+       smoothed fit coefficients of a polynomial fit along the columns of the 
+       line positions as output.
+ at name  sinfo_new_wave_cal()
+ at param image:        merged image from a calibration emission lamp,
+ at param par:          fit parameters data structure storage
+ at param abuf:         buffer array for fit coefficients abuf[index][column]
+ at param row_clean: resulting list of the row indices but without the lines 
+                     that are too close to 
+                     each other for the fit output of sinfo_findLines()
+ at param wavelength_clean: corrected wavelength list corresponding to the 
+                         row_clean array
+                         output of sinfo_findLines()
+ at param n_found_lines: output of sinfo_findLines(): total number of found 
+                      emission lines
+ at param dispersion:   dispersion of spectrum: micron per pixel
+ at param halfWidth:    half width of the box where the line must sit
+ at param minAmplitude: minimum amplitude of the Gaussian to do the fit
+ at param max_residual: maximum residual value, beyond that value
+                     the polynomial lambda-position fit is rejected.
+ at param fwhm:         first guess for the full width of half maximum
+                     of the sinfo_gaussian line fit
+ at param n_a_fitcoefs: number of fit coefficients for the single
+                     column fits: lambda-position
+ at param n_b_fitcoefs: number of fit coefficients for the fits of
+                     the single a coefficients across the columns
+ at param sigmaFactor:  factor of the standard deviation of the determined
+                     polynomial coefficients of the columns beyond
+                     which these coefficients are not used to carry out
+                     the polynomial fit across the columns.
+ at param pixel_dist:   estimate of minimal pixel distance in spectral 
+                     direction between slitlets
+ at param pixel_tolerance: maximum tolerated difference between estimated 
+                        and fitted line positions.
+ at return # wavelength map image
+        # abuf: array of smoothed coefficients of the polynomial fit 
+          along the columns:
+                              abuf[loc_index][column].
+        # par: array of the resulting FitParams data structure
+ at doc this routine takes an image from a calibration emission lamp and 
+     delivers the smoothed fit coefficients of a polynomial fit along the 
+     columns of the line positions as output. This routine expects Nyquist 
+     sampled spectra (either an interleaved image or an image 
+     convolved with an appropriate function in spectral direction)
+*/
+cpl_image * sinfo_new_wave_cal( cpl_image   * image,
+                    FitParams ** par ,
+                    float     ** abuf,
+                    int          n_slitlets,
+                    int       ** row_clean,
+                    float     ** wavelength_clean,
+                    int        * n_found_lines,
+                    float        dispersion,
+                    int          halfWidth,
+                    float        minAmplitude,
+                    float        max_residual,
+                    float        fwhm,
+                    int          n_a_fitcoefs,
+                    int          n_b_fitcoefs,
+                    float        sigmaFactor,
+                    float        pixel_dist,
+                    float        pixel_tolerance )
+
+{
+    int          i=0, j=0, k=0 ;
+    int          n_fit=0 ;
+    int          n_reject=0 ;
+    float     *  acoefs=NULL ;
+    float     *  dacoefs=NULL ;
+    float     ** dabuf=NULL ;
+    float        chisq_poly=0 ;
+    float     *  chisq_cross=NULL ;
+    int          zeroind=0 ;
+    int          crossInd=0 ;
+    Bcoeffs   *  bco=NULL ;
+    cpl_image  *  wavemap=NULL ;
+    int ilx=0;
+    int ily=0;
+    float* pidata=NULL;
+
+
+    if (  NULL == image )
+    {
+        sinfo_msg_error("no image given") ;
+        return NULL ;
+    }
+    check_nomsg(ilx=cpl_image_get_size_x(image));
+    check_nomsg(ily=cpl_image_get_size_y(image));
+    check_nomsg(pidata=cpl_image_get_data_float(image));
+
+    if ( par == NULL )
+    {
+        sinfo_msg_error("no fit parameter data structure given") ;
+        return NULL ;
+    }
+    if ( abuf == NULL )
+    {
+        sinfo_msg_error("no buffer for fit coefficients given") ;
+        return NULL ;
+    }
+    if ( n_slitlets <= 0 )
+    {
+        sinfo_msg_error("impossible number of slitlets given") ;
+        return NULL ;
+    }
+    if ( row_clean == NULL )
+    {
+        sinfo_msg_error("no row_clean array given") ;
+        return NULL ;
+    }
+    if ( wavelength_clean == NULL )
+    {
+        sinfo_msg_error("no wavelength_clean array given") ;
+        return NULL ;
+    }
+
+    if ( dispersion == 0. )
+    {
+        sinfo_msg_error("impossible dispersion given") ;
+        return NULL ;
+    }
+
+    if ( halfWidth <= 0 || halfWidth > ily/2 )
+    {
+        sinfo_msg_error("impossible half width of the fitting box given") ;
+        return NULL ;
+    }
+    if ( minAmplitude < 1. )
+    {
+        sinfo_msg_error("impossible minimal amplitude") ;
+        return NULL ;
+    }
+
+    if ( max_residual <= 0. || max_residual > 1. )
+    {
+        sinfo_msg_error("impossible max_residual given") ;
+        return NULL ;
+    }
+    if ( fwhm <= 0. || fwhm > 10. )
+    {
+        sinfo_msg_error("impossible fwhm given") ;
+        return NULL ;
+    }
+
+    if ( n_a_fitcoefs <= 0 || n_a_fitcoefs > 9 )
+    {
+        sinfo_msg_error("unrealistic n_a_fitcoefs given") ;
+        return NULL ;
+    }
+
+    if ( n_b_fitcoefs <= 0 || n_b_fitcoefs > 9 )
+    {
+        sinfo_msg_error("unrealistic n_b_fitcoefs given") ;
+        return NULL ;
+    }
+    if ( sigmaFactor <= 0. )
+    {
+        sinfo_msg_error("impossible sigmaFactor given") ;
+        return NULL ;
+    }
+
+    /* initialize the variables */
+    n_reject = 0 ;
+    n_fit = 0 ;
+
+
+    /* fit each found line by using a Gaussian function and determine 
+       the exact position */
+    if ( 0 > (n_fit = sinfo_new_fit_lines( image , par, fwhm, n_found_lines, 
+                                     row_clean, wavelength_clean,
+                                     halfWidth, minAmplitude )) )
+    {
+        sinfo_msg_error("cannot fit the lines, error code of "
+                        "sinfo_fitLines: %d", n_fit) ;
+        return NULL ;
+    }
+
+    /* first check for faked lines like bad pixels */
+    if ( -1 == sinfo_new_check_for_fake_lines (par, dispersion, 
+                                               wavelength_clean, 
+                                         row_clean, n_found_lines,
+                                         ilx, pixel_tolerance) )
+    {
+        sinfo_msg_error("cannot fit the lines, error code of "
+                        "sinfo_fitLines: %d", n_fit) ;
+        return NULL ;
+    }
+
+    /* allocate memory */
+    if (NULL == (acoefs = (float*) cpl_calloc(n_a_fitcoefs, sizeof(float))) ||
+        NULL == (dacoefs = (float*) cpl_calloc(n_a_fitcoefs, sizeof(float))) ||
+        NULL == (dabuf = (float**) cpl_calloc(n_a_fitcoefs, sizeof(float*))) ||
+        NULL == (chisq_cross = (float*) cpl_calloc(n_slitlets, sizeof(float))))
+    {
+        sinfo_msg_error("cannot allocate memory\n") ;
+        return NULL ;
+    }
+    for ( i = 0 ; i < n_a_fitcoefs ; i++ )
+    {
+        if (  NULL == (dabuf[i] = (float*) cpl_calloc(ilx, sizeof(float))) )
+        {
+            sinfo_msg_error("cannot allocate memory") ;
+            sinfo_free_float (&acoefs ) ;
+            sinfo_free_float ( &dacoefs ) ;
+            sinfo_free_float ( &chisq_cross ) ;
+            sinfo_free_float_array(&dabuf,n_a_fitcoefs) ;
+            return NULL ;
+        }
+    }
+
+
+    /* fit wavelengths to the corresponding found positions for each column */
+    k = 0 ;
+    for ( i = 0 ; i < ilx ; i++ )
+    {
+        zeroind = 0 ;
+        if ( FLT_MAX == (chisq_poly = sinfo_new_polyfit( par, i, 
+                                                         n_found_lines[i], 
+                                                   ily, dispersion,
+                                                   max_residual, acoefs, 
+                                                   dacoefs, &n_reject, 
+                                                   n_a_fitcoefs)) )
+        {
+      /*
+            sinfo_msg_warning ("error in sinfo_polyfit in column: %d\n", i) ;
+      */
+            for ( j = 0 ; j < n_a_fitcoefs ; j++ )
+            {
+                acoefs[j] = ZERO ;
+                dacoefs[j] = ZERO ;
+            }
+        }
+
+        for ( j = 0 ; j < n_a_fitcoefs ; j++ )
+        {
+
+            if ( acoefs[0] <= 0. || acoefs[1] ==0. ||
+                 dacoefs[j] == 0. || isnan(acoefs[j]) )
+            {
+                zeroind = 1 ;
+            }
+        }
+        for ( j = 0 ; j < n_a_fitcoefs ; j++ )
+        {
+            if ( zeroind == 0 )
+            {
+                abuf[j][i]  = acoefs[j] ;
+                dabuf[j][i] = dacoefs[j] ;
+            }
+            else
+            {
+                abuf[j][i]  = ZERO ;
+                dabuf[j][i] = ZERO ;
+            }
+        }
+    }
+ 
+    /* allocate memory for the fitting coefficients */
+    if ( NULL == ( bco = sinfo_new_b_coeffs( n_slitlets, 
+                                             n_a_fitcoefs, n_b_fitcoefs)) )
+    {
+        sinfo_msg_error ("cannot allocate memory for the bcoeffs") ;
+        sinfo_free_float_array(&dabuf,n_a_fitcoefs) ;
+        sinfo_free_float (&acoefs ) ;
+        sinfo_free_float (&dacoefs ) ;
+        sinfo_free_float (&chisq_cross ) ;
+        return NULL ;
+    }
+
+    /* fit each acoefs across the slitlets to smooth the result */
+    if ( -1 == ( crossInd = sinfo_new_coeffs_cross_slit_fit( ilx, 
+                                                abuf, 
+                                                dabuf,
+                                                bco, 
+                                                sigmaFactor, 
+                                                dispersion, 
+                                                pixel_dist, 
+                                                chisq_cross )) )
+    {
+        sinfo_msg_error ("cannot carry out the fitting of "
+                         "coefficients across the columns") ;
+        sinfo_free_float_array(&dabuf,n_a_fitcoefs) ;
+        sinfo_free_float (&acoefs ) ;
+        sinfo_free_float (&dacoefs ) ;
+        sinfo_free_float (&chisq_cross ) ;
+        return NULL ;
+    }
+  
+
+    if ( NULL == (wavemap = sinfo_new_wave_map_slit (abuf, n_a_fitcoefs, 
+                                                     ily, ilx)) )
+    {
+        sinfo_msg_error ("cannot carry out wavemap creation") ;
+        sinfo_free_float_array(&dabuf,n_a_fitcoefs) ;
+        sinfo_free_float (&acoefs ) ;
+        sinfo_free_float (&dacoefs ) ;
+        sinfo_free_float (&chisq_cross ) ;
+        sinfo_new_destroy_b_coeffs(bco) ;
+        return NULL ;
+    }
+
+    /* free all allocated memory */
+    sinfo_free_float_array(&dabuf,n_a_fitcoefs) ;
+    sinfo_free_float (&acoefs ) ;
+    sinfo_free_float (&dacoefs ) ;
+    sinfo_free_float (&chisq_cross ) ;
+    sinfo_new_destroy_b_coeffs(bco) ;
+
+    return wavemap ;
+ cleanup:
+    sinfo_free_float (&acoefs ) ;
+    sinfo_free_float ( &dacoefs ) ;
+    sinfo_free_float ( &chisq_cross ) ;
+    sinfo_free_float_array(&dabuf,n_a_fitcoefs) ;
+    sinfo_new_destroy_b_coeffs(bco) ;
+    return NULL;
+}
+
+
+
+/**
+  @brief  searches for successfully fitted fake lines like bad pixels 
+          by comparing the found line positons with estimated templatate
+          positions.
+   @name  sinfo_new_check_for_fake_lines()
+   @param par: array of the fit parameter data structure FitParams
+   @param dispersion: estimated dispersion
+   @param wavelength_clean: corrected wavelength list
+   @param row_clean: corrected row list corresponding to the wavelength list
+   @param n_found_lines: array of numbers of found lines of each column
+   @param n_columns: total number of image columns
+   @param pixel_tolerance: maximum tolerated difference between estimated 
+                           and fitted line positions.
+   @return # par: corrected FitParams
+           # 0 in case of success
+           # -1 in case of error
+ at doc this routine searches for successfully fitted fake lines like bad 
+     pixels by comparing the found line positons with estimated template 
+     positions. This routine should be inserted in the wavelength calibration 
+     routine just after the sinfo_fitLines() routine.
+ */
+
+int sinfo_new_check_for_fake_lines ( FitParams ** par,
+                        float        dispersion,
+            float     ** wavelength_clean,
+            int       ** row_clean,
+            int        * n_found_lines,
+            int          n_columns,
+            float        pixel_tolerance )
+{
+    int i,  k ;
+    int col ;
+    int found ;
+    float row ;
+    float * beginWave ;
+    float firstWave ;
+
+    if ( par == NULL )
+    {
+        sinfo_msg_error("no fit parameter data structure given") ;
+        return -1 ;
+    }
+    if ( dispersion == 0. )
+    {
+        sinfo_msg_error("dispersion zero given!") ;
+        return -1 ;
+    }
+    if ( wavelength_clean == NULL )
+    {
+        sinfo_msg_error("no wavelength array given!") ;
+        return -1 ;
+    }
+    if ( row_clean == NULL )
+    {
+        sinfo_msg_error("no row array given!") ;
+        return -1 ;
+    }
+    if ( n_found_lines == NULL )
+    {
+        sinfo_msg_error("no number of lines given!") ;
+        return -1 ;
+    }
+    if ( n_columns < 200 )
+    {
+        sinfo_msg_error("wrong number of columns given!") ;
+        return -1 ;
+    }
+
+    /* first determine the estimated beginning wavelength of the first row */
+    for ( col = 0 ; col < n_columns ; col++ )
+    {
+        if ( n_found_lines[col] == 0 )
+        {
+        continue ;
+        } 
+        if ( NULL == (beginWave = (float*) cpl_calloc( n_found_lines[col], 
+                                                       sizeof(float) ) ) )
+        {
+            sinfo_msg_error("could not allocate memory!") ;
+            return -1 ;
+    }
+    for ( k = 0 ; k < n_found_lines[col] ; k++ ) 
+    {
+        beginWave[k] = wavelength_clean[col][k] - 
+                           (float)row_clean[col][k] * dispersion ;
+        }
+    /* determine the clean mean of the estimated 
+           beginning wavelengths of one column */
+    if ( FLT_MAX == (firstWave = sinfo_new_clean_mean (beginWave, 
+                                                           n_found_lines[col], 
+                                                           10., 10.) ) )
+    {
+            sinfo_msg_error("clean mean did not work!") ;
+            return -1 ;
+    }
+
+        cpl_free (beginWave) ;
+        /* go through the lines in that column and select the 
+           correct FitParam structure */
+        for ( k = 0 ; k < n_found_lines[col] ; k++ ) 
+        {    
+        /* compute the estimated line position */
+        row = ( wavelength_clean[col][k] - firstWave ) / dispersion ;
+
+            /* go through all fit parameters and find the corresponding one */
+        found = -1 ;
+            for ( i = 0 ; i < (par[0] -> n_params) ; i ++ )
+            {    
+            /* find the given column and go through the 
+                   lines in that column */
+        if ( (par[i] -> column == col) && (par[i] -> line == k) && 
+             (par[i] -> wavelength == wavelength_clean[col][k]) )
+        {
+                found = i ;
+            break ;
+                }
+            }
+        if ( found != -1 )
+        {
+            /* set fit params to zero where the fitted row 
+                   position and the estimated 
+            row positions are outside the tolerance */
+                if ( fabs(row - par[found]->fit_par[2]) > pixel_tolerance ) 
+            {
+                sinfo_msg_warning("found bad line in col: "
+                                      "%d line: %d in row: %f difference: %f", 
+                                      col, k, par[found]->fit_par[2],
+                                      row - par[found]->fit_par[2])  ;
+                par[found]->fit_par[2] = 0. ;
+                }
+            }
+        else
+        {
+        sinfo_msg_warning("fit parameter of col %d and line "
+                                  "no %d not found!\n", col, k ) ;
+        }
+        }
+    }
+
+    return 0 ;
+}
+
+/**
+ at brief
+ at name sinfo_new_create_shifted_slit_wavemap()
+ at param lineIm:       new shifted emission line frame
+ at param coeffs:       calculated polynomial coefficients,
+                                      output of sinfo_coeffsCrossSlitFit()
+ at param n_fitcoeffs:  number of polynomial coefficients, order + 1
+ at param wavelength:   wavelength list from line list
+ at param intensity:    corresponding line intensity from line list
+ at param n_lines:      number of lines in the list
+ at return wavelength map  
+ at doc This routine cross-correlates a shifted emission line frames and 
+     determines the shift to the old one which is given by its polynomial 
+     coefficients.  Then the a0 coefficients is recalculated and afterwards 
+     a new wavelength calibration map is generated using the already 
+     calculated smoothed polynomial coefficients.
+*/
+
+cpl_image * 
+sinfo_new_create_shifted_slit_wavemap ( cpl_image * lineIm,
+                              float    ** coeffs,
+                          int      n_fitcoeffs,
+                                      float  * wavelength,
+                                      float  * intensity,
+                                      int      n_lines,
+                                      int      magFactor )
+{
+    cpl_image * wavemap ;
+    float* emline=NULL ;
+    float* spec=NULL ;
+    float* wave=NULL ;
+    double* a=NULL ;
+    float* par=NULL ;
+    float* derv_par=NULL ;
+    double* z=NULL ;
+
+    double  * result ;
+    float * filter_spec ;
+    float centreval ;
+    float centrepix ;
+    float cenpos, cenpix ;
+    float pixvalue ;
+    float wavelag ;
+    float angst ;
+    float a_initial ;
+    int        numpar, its ;
+    int        * mpar ;
+    float      tol, lab ;
+    float      * xdat, * wdat ;
+    Vector     * peak;
+    int   iters, xdim, ndat ;
+    int   row , col ;
+    int   i, j, k/*, l, m*/ ;
+    int   sign, found, line, width ;
+    int var, maxlag, cmin, cmax ;
+    gsl_poly_complex_workspace * w ;
+    double xcorr_max ;
+    int delta ;
+    int ilx=0;
+    int ily=0;
+    int olx=0;
+    int oly=0;
+    float* pidata=NULL;
+    float* podata=NULL;
+
+
+    if ( lineIm == NULL )
+    {
+        sinfo_msg_error ("no input image given!") ;
+        return NULL ;
+    }
+    ilx=cpl_image_get_size_x(lineIm);
+    ily=cpl_image_get_size_y(lineIm);
+    pidata=cpl_image_get_data_float(lineIm);
+
+    if ( coeffs == NULL )
+    {
+        sinfo_msg_error ("no coefficient sinfo_matrix given!") ;
+        return NULL ;
+    }
+    if ( n_fitcoeffs < 2 )
+    {
+        sinfo_msg_error ("wrong number of polynomial coefficients given!") ;
+        return NULL ;
+    }
+    if ( wavelength == NULL || intensity == NULL )
+    {
+        sinfo_msg_error ("no input image given!") ;
+        return NULL ;
+    }
+    if ( n_lines < 1 )
+    {
+        sinfo_msg_error ("no input image given!") ;
+        return NULL ;
+    }
+
+    /* find out if Angstroem or microns are used */
+    if ( wavelength[0] > 10000. )
+    {
+        /* Angstroem */
+        angst = 10000. ;
+    }
+    else if ( wavelength[0] > 1000. && wavelength[0] < 10000. )
+    {
+        /* nanometers */
+        angst = 1000. ;
+    }
+    else
+    {
+        /* microns */
+        angst = 1. ;
+    }
+
+    /* allocate memory */
+    if ( NULL == (wavemap = cpl_image_new ( ilx, ily, CPL_TYPE_FLOAT)) )
+    {
+        sinfo_msg_error ("could not allocate memory!") ;
+        return NULL ;
+    }
+    olx=cpl_image_get_size_x(wavemap);
+    oly=cpl_image_get_size_y(wavemap);
+    podata=cpl_image_get_data_float(wavemap);
+
+    var = (magFactor-1)*(magFactor-1) ;
+
+
+ 
+    emline=cpl_calloc(ily,sizeof(float)) ;
+    spec=cpl_calloc(ily,sizeof(float)) ;
+    wave=cpl_calloc(n_lines,sizeof(float)) ;
+    par=cpl_calloc(MAXPAR,sizeof(float)) ;
+    derv_par=cpl_calloc(MAXPAR,sizeof(float)) ;
+
+    a=cpl_calloc(n_fitcoeffs,sizeof(double)) ;
+    z=cpl_calloc(2*(n_fitcoeffs - 1),sizeof(double)) ;
+
+   
+    /* first store each spectrum in a buffer */
+    for ( col = 0 ; col < ilx ; col++ )
+    {
+        /* initialize the emline array for each column */
+        for ( i = 0 ; i < ily ; i++ )
+        {
+            emline[i] = 0. ;
+        }
+        /* determine the coefficients by using the given bcoefs */
+        for ( i = 0 ; i < n_fitcoeffs ; i++ )
+        {
+            /* initialize coefficients and solution */
+            if (i < n_fitcoeffs-1)
+            {
+                z[2*i] = 0. ;
+                z[2*i+1] = 0. ;
+            }
+            a[i] = coeffs[i][col] ;
+        }
+         
+        a_initial = coeffs[0][col] ;
+        /* go through the lines and generate an artificial spectrum */
+        for ( line = 0 ; line < n_lines ; line++ )
+        {
+            /* go from Angstroem to micron */
+            wave[line] = wavelength[line]/angst ;
+
+            /* -----------------------------------------------------------
+             * solve the polynomial for the exact offset of the line that means
+             * find the root of the polynomial of order n_fitcoefs - 1
+             */
+            a[0] = a_initial - wave[line] ;
+
+            if(NULL==(w=sinfo_gsl_poly_complex_workspace_alloc(n_fitcoeffs))) 
+            {
+                sinfo_msg_error("could not allocate complex workspace!") ;
+                cpl_image_delete(wavemap) ;
+                return NULL ;
+            }
+            if (-1 == sinfo_gsl_poly_complex_solve(a, n_fitcoeffs, w, z)) 
+            {
+                sinfo_msg_error("sinfo_gsl_poly_complex_solve did not work!") ;
+                cpl_image_delete(wavemap) ;
+                return NULL ;
+            }
+            sinfo_gsl_poly_complex_workspace_free(w) ;           
+
+            j = 0 ;
+            found = -1 ;
+            for ( i = 0 ; i < n_fitcoeffs - 1 ; i++ )
+            {
+                /* test for appropriate solution */
+                if( (z[2*i] > (-1.)*(float) ily/2. &&
+                     z[2*i] < (float)ily/2.) && z[2*i+1] == 0. )
+                {
+                    found = 2*i ;
+                    j ++ ;
+                }
+                else
+                {
+                    continue ;
+                }
+            }
+            if ( j == 0 )
+            {
+                sinfo_msg_warning("no offset solution found for line %d in "
+                                  "column %d", line, col) ;
+                continue ;
+            }
+            else if ( j == 1 )
+            {
+                cenpos = z[found] + (float) ily /2. ;
+            }
+            else
+            {
+                sinfo_msg_warning("two or more offset solutions found for "
+                                  "line %d in column %d", line, col) ;
+                continue ;
+            }
+
+            /*-----------------------------------------------------------------
+             * magnify image by the given factor add an additional offset
+             */
+            cenpix = cenpos ;
+
+            /* determine max and min pixel limits over 
+               which line should be convolved */
+            cmin = (sinfo_new_nint(cenpix) - (var-1)) > 0 ? 
+                    sinfo_new_nint(cenpix) - (var-1) : 0 ;
+            cmax = (sinfo_new_nint(cenpix) + (var-1)) < ily ?
+                    sinfo_new_nint(cenpix) + (var-1) : ily ;
+
+            /* convolve neon lines with Gaussian function */
+            for ( j = cmin ; j < cmax ; j++ )
+            {
+                emline[j] += intensity[line] * 
+                     exp((double)(-0.5*(j-cenpix)*(j-cenpix))/(double)var) ;
+            }
+        }
+
+        /*-------------------------------------------------------------------
+         * for each column, map the image data points onto an magFactor times 
+           bigger element grid for FFT in the cross sinfo_correlation, first 
+           initialize the two helping arrays for each new column.
+         */
+        for ( k = 0 ; k < ily ; k++ )
+        {
+            spec[k] = 0. ;
+        }
+
+        /* now take the image data points of the column and put 
+           them into the spec array */
+        for ( row = 0 ; row < ily ; row++ ) /* go through the column */
+        {
+            /* set bad pixels or negative values to zero */
+            if (!isnan(pidata[col + row*ilx]) &&
+                (pidata[col + row*ilx] > 0.))
+            {
+                spec[row] = pidata[col + row*ilx] ;
+            }
+            else
+            {
+                spec[row] = 0. ;
+            }
+        }
+        /* convolve the spectrum by Gaussian */
+        filter_spec = sinfo_function1d_filter_lowpass(spec, ily, 
+                                                      LOW_PASS_GAUSSIAN, 
+                                                      magFactor) ; 
+
+        /* now call the cross sinfo_correlation routine */
+        result = sinfo_new_xcorrel( filter_spec, ily, emline, ily,
+                          ily/2, &delta, &maxlag, &xcorr_max) ;
+
+        if ( xcorr_max <= 0. )
+        {
+            sinfo_msg_warning("no positive cross correlation sum , "
+                              "col %d set to ZERO \n", col) ;
+            for ( row = 0 ; row < ily ; row++ )
+            {
+                podata[col + row*ilx] = ZERO ;
+            }
+            sinfo_function1d_del(filter_spec) ;
+            cpl_free(result) ;
+            continue ;
+        }
+
+       /* in this section, we fit the correlation function with a gauss, 
+          and find its peak, thus getting subpixel-accuracy */
+
+        i = maxlag; j = i+1;
+        while (result[j] < result[i])
+        {
+            i++; j++;
+        }
+        i = maxlag; k = i-1;
+        while (result[k] < result[i])
+        {
+            i--; k--;
+        }
+        width = j-k+1;
+        /* allocate memory for the spectral sinfo_vector */
+        if ( NULL == (peak = sinfo_new_vector (width)) )
+        {
+            sinfo_msg_error ("cannot allocate new Vector \n") ;
+            sinfo_function1d_del(filter_spec) ;
+            cpl_free(result) ;
+            return NULL ;
+        }
+
+
+        /* allocate memory */
+        xdat = (float *) cpl_calloc( peak -> n_elements, sizeof (float) ) ;
+        wdat = (float *) cpl_calloc( peak -> n_elements, sizeof (float) ) ;
+        mpar = (int *)   cpl_calloc( MAXPAR, sizeof (int) ) ;
+
+        /* determine the values of the spectral sinfo_vector given as input */
+        /* go through the chosen column */
+
+        for ( i = 0 ; i < width ; i++ )
+        {
+            peak -> data[i] = result[k+i]/xcorr_max * 100. ;
+            xdat[i] = i;
+            wdat[i] = 1.0;
+        }
+
+        /* set initial values for the fitting routine */
+        xdim     = XDIM;
+        ndat     = peak -> n_elements ;
+        numpar   = MAXPAR ;
+        tol      = TOL ;
+        lab      = LAB ;
+        its      = ITS ;
+        par[1] = width/2.0 ;
+        par[2] = (float) (maxlag - k) ;
+        par[3] = (peak -> data[0] + peak -> data[peak->n_elements - 1]) / 2.0 ;
+        par[0]  = result[maxlag]/xcorr_max * 100. - (par[3]) ;
+
+        for ( i = 0 ; i < MAXPAR ; i++ )
+        {
+            derv_par[i] = 0.0 ;
+            mpar[i] = 1 ;
+        }
+
+        /* finally, do the least square fit using a sinfo_gaussian */
+        if ( 0 > ( iters = sinfo_new_lsqfit_c( xdat, &xdim, 
+                                               peak -> data, wdat, 
+                                               &ndat, par, derv_par, mpar,
+                                               &numpar, &tol, &its, &lab )) )
+        {
+            sinfo_msg_warning ("sinfo_new_lsqfit_c: least squares fit failed "
+                               "in col: %d, error no.: %d", col, iters) ;
+            sinfo_new_destroy_vector ( peak ) ;
+            cpl_free ( xdat ) ;
+            cpl_free ( wdat ) ;
+            cpl_free ( mpar ) ;
+            sinfo_function1d_del(filter_spec) ;
+            cpl_free(result) ;
+            continue ;
+        }
+
+        sinfo_new_destroy_vector ( peak ) ;
+        cpl_free (xdat) ;
+        cpl_free (wdat) ;
+        cpl_free (mpar) ;
+        sinfo_function1d_del(filter_spec) ;
+        cpl_free(result) ;
+
+        wavelag =((float)ily/2 - (float)k - par[2]) ;
+
+        if ( fabs(wavelag) > (float)ily/20. )
+        {
+            sinfo_msg_warning("wavelag very big , col %d set to ZERO", col) ;
+            for ( row = 0 ; row < ily ; row++ )
+            {
+                podata[col + row*ilx] = ZERO ;
+            }
+            continue ;
+        }
+
+        /*--------------------------------------------------------------------
+         * determine new zero order coefficient centreval, of which the 
+         * formula is determined by setting equal a polynomial shifted by 
+         * wavelag with the same higher order coefficients and set the new 
+         * zero order coefficient to
+         * get both sides of the equation approximately equal.
+         */
+        centreval = a_initial ;
+        for ( i = 1 ; i < n_fitcoeffs ; i++ )
+        {
+            if ( i%2 == 0 ) 
+            {
+                sign = -1 ;
+            }
+            else
+            {
+                sign = 1 ;
+            }
+            centreval += (float)sign * coeffs[i][col]*pow(wavelag, i) ;
+        }
+
+        /* prepare to write out wavelength as pixel values */
+        for ( row = 0 ; row < oly ; row++ )
+        {
+            centrepix = (float)row - ((float)oly - 1.)/2. ;
+            pixvalue = 0. ;
+            for ( i = 1 ; i < n_fitcoeffs ; i++ )
+            {
+                pixvalue += coeffs[i][col]*pow(centrepix, i) ;
+            }
+            podata[col+row*olx] = centreval + pixvalue ;
+        }
+    }
+
+
+    cpl_free(emline) ;
+    cpl_free(spec) ;
+    cpl_free(wave) ;
+    cpl_free(par) ;
+    cpl_free(derv_par) ;
+
+    cpl_free(a) ;
+    cpl_free(z) ;
+
+
+
+    return wavemap ;
+}
+
+/**
+ at brief This routine cross-correlates a shifted emission line frames and 
+       determines the shift to the old one which is given by its polynomial 
+       coefficients.
+ at name  sinfo_new_create_shifted_slit_wavemap2()
+ at param lineIm:       new shifted emission line frame
+ at param coeffs:       calculated polynomial coefficients,
+                     output of sinfo_coeffsCrossSlitFit()
+ at param n_fitcoeffs:  number of polynomial coefficients, order + 1
+ at param wavelength:   wavelength list from line list
+ at param intensity:    corresponding line intensity from line list
+ at param n_lines:      number of lines in the list
+ at param magFactor:    magnification factor for help arrays
+ at param dispersion:   estimate of the dispersion
+ at param pixel_dist:   estimate of minimal pixel distance in spectral direction
+                     between slitlets
+ at return wavelength map
+ at doc This routine cross-correlates a shifted emission line frames and 
+     determines the shift to the old one which is given by its polynomial 
+     coefficients. Then the a0 coefficients is recalculated and afterwards 
+     a new wavelength calibration map 
+     is generated using the already calculated smoothed polynomial coefficients.
+*/
+
+cpl_image * sinfo_new_create_shifted_slit_wavemap2 ( cpl_image * lineIm,
+                                      float    ** coeffs,
+                                      int      n_fitcoeffs,
+                                      float  * wavelength,
+                                      float  * intensity,
+                                      int      n_lines,
+                                      int      magFactor,
+                                      float    dispersion,
+                                      float    pixel_dist )
+{
+    cpl_image * wavemap ;
+    double * result ;
+    float * filter_spec ;
+    float centreval ;
+    float centrepix ;
+    float cenpos, cenpix ;
+    float pixvalue ;
+    float wavelag ;
+    /*float maxres ;*/
+    float angst ;
+    /*float temp ;*/
+    float a_initial ;
+    int        numpar, its ;
+    int        * mpar ;
+    float      tol, lab ;
+    float      * xdat, * wdat ;
+    Vector     * peak;
+    int   iters, xdim, ndat ;
+    int   row , col ;
+    int   i, j, k/*, l, m*/, n ;
+    int   sign, found, line, width ;
+    int var, maxlag, cmin, cmax ;
+    float offset2 ;
+    float threshold ;
+    int ed1, ed2 ;
+
+    int edge[N_SLITLETS] ;
+    float par[MAXPAR] ;
+    float derv_par[MAXPAR] ;
+
+    float* emline=NULL ;
+    float* spec=NULL ;
+    float* wave=NULL ;
+    float* a0=NULL ;
+    float* a0_clean=NULL ;
+
+
+    float* sub_col_index=NULL ;
+    float* sub_acoefs=NULL;
+    float* sub_dacoefs=NULL ;
+    double* z=NULL ;
+    double* a=NULL ;
+
+    float** bcoef=NULL ;
+    float* wcoefs=NULL ;
+
+
+    int ns, nc ;
+    float * acoefsclean ;
+    float col_index;
+
+    float ** ucoefs, **vcoefs, **covar ;
+    double sum, sumq, mean ;
+    double sigma ;
+    double cliphi, cliplo ;
+    float chisq ;
+    int num, ndata ;
+    gsl_poly_complex_workspace * w ;
+    double xcorr_max ;
+    int delta ;
+    int ilx=0;
+    int ily=0;
+    int olx=0;
+    int oly=0;
+    float* pidata=NULL;
+    float* podata=NULL;
+
+
+    if ( lineIm == NULL )
+    {
+        sinfo_msg_error (" no input image given!\n") ;
+        return NULL ;
+    }
+
+    ilx=cpl_image_get_size_x(lineIm);
+    ily=cpl_image_get_size_y(lineIm);
+    pidata=cpl_image_get_data_float(lineIm);
+
+    if ( coeffs == NULL )
+    {
+        sinfo_msg_error (" no coefficient sinfo_matrix given!\n") ;
+        return NULL ;
+    }
+    if ( n_fitcoeffs < 2 )
+    {
+        sinfo_msg_error (" wrong number of polynomial coefficients given!\n") ;
+        return NULL ;
+    }
+    if ( wavelength == NULL || intensity == NULL )
+    {
+        sinfo_msg_error (" no input image given!\n") ;
+        return NULL ;
+    }
+    if ( n_lines < 1 || magFactor < 1 )
+    {
+        sinfo_msg_error (" no input image given!\n") ;
+        return NULL ;
+    }
+    var    = (magFactor - 1)*(magFactor - 1) ;
+    /* find out if Angstroem or microns are used */
+    if ( wavelength[0] > 10000. )
+    {
+        /* Angstroem */
+        angst = 10000. ;
+    }
+    else if ( wavelength[0] > 1000. && wavelength[0] < 10000. )
+    {
+        /* nanometers */
+        angst = 1000. ;
+    }
+    else
+    {
+        /* microns */
+        angst = 1. ;
+    }
+
+    bcoef=sinfo_new_2Dfloatarray(N_SLITLETS,n_fitcoeffs) ;
+    wcoefs=cpl_calloc(n_fitcoeffs,sizeof(float)) ;
+
+    emline=cpl_calloc(ily,sizeof(float)) ;
+    spec=cpl_calloc(ily,sizeof(float)) ;
+    wave=cpl_calloc(n_lines,sizeof(float)) ;
+    a0=cpl_calloc(ilx,sizeof(float)) ;
+    a0_clean=cpl_calloc(ilx,sizeof(float)) ;
+
+
+
+    sub_col_index=cpl_calloc(ilx,sizeof(float)) ;
+    sub_acoefs=cpl_calloc(ilx,sizeof(float));
+    sub_dacoefs=cpl_calloc(ilx,sizeof(float)) ;
+
+    a=cpl_calloc(n_fitcoeffs,sizeof(double)) ;
+    z=cpl_calloc(2*(n_fitcoeffs - 1),sizeof(double)) ;
+
+    /* find the slitlet edges from the a0 coefficient */
+    n = 0 ;
+    threshold = pixel_dist * fabs(dispersion) ;
+    for ( i = PIXEL ; i < ilx - PIXEL ; )
+    {
+        if (fabs(coeffs[0][i+1] - coeffs[0][i]) >= threshold )
+        {
+            edge[n] = i+1 ;
+            n++ ;
+            i += PIXEL ;
+        }
+        i++ ;
+    }
+
+
+    /* allocate memory */
+    if ( NULL == (wavemap = cpl_image_new ( ilx, ily, CPL_TYPE_FLOAT)) )
+    {
+        sinfo_msg_error (" could not allocate memory!\n") ;
+        return NULL ;
+    }
+    olx=cpl_image_get_size_x(wavemap);
+    oly=cpl_image_get_size_y(wavemap);
+    podata=cpl_image_get_data_float(wavemap);
+
+    /* first store each spectrum in a buffer */
+    for ( col = 0 ; col < ilx ; col++ )
+    {
+        /* initialize the emline array for each column */
+        for ( i = 0 ; i < ily ; i++ )
+        {
+            emline[i] = 0. ;
+        }
+        /* determine the coefficients by using the given bcoefs */
+        for ( i = 0 ; i < n_fitcoeffs ; i++ )
+        {
+            /* initialize coefficients and solution */
+            if (i < n_fitcoeffs-1)
+            {
+                z[2*i] = 0. ;
+                z[2*i+1] = 0. ;
+            }
+            a[i] = coeffs[i][col] ;
+        }
+         
+        a_initial = coeffs[0][col] ;
+        /* go through the lines and generate an artificial spectrum */
+        for ( line = 0 ; line < n_lines ; line++ )
+        {
+            /* go from Angstroem to micron */
+            wave[line] = wavelength[line]/angst ;
+
+            /* ------------------------------------------------------------
+             * solve the polynomial for the exact offset of the line that means
+             * find the root of the polynomial of order n_fitcoefs - 1
+             */
+            a[0] = a_initial - wave[line] ;
+
+            if (NULL==(w=sinfo_gsl_poly_complex_workspace_alloc(n_fitcoeffs))) 
+            {
+                sinfo_msg_error(" could not allocate complex workspace!") ;
+                cpl_image_delete(wavemap) ;
+                return NULL ;
+            }
+            if (-1 == sinfo_gsl_poly_complex_solve(a, n_fitcoeffs, w, z)) 
+            {
+                sinfo_msg_error(" sinfo_gsl_poly_complex_solve did not work!") ;
+                cpl_image_delete(wavemap) ;
+                return NULL ;
+            }
+            sinfo_gsl_poly_complex_workspace_free(w) ;           
+
+            j = 0 ;
+            found = -1 ;
+            for ( i = 0 ; i < n_fitcoeffs - 1 ; i++ )
+            {
+                /* test for appropriate solution */
+                if( (z[2*i] > (-1.)*(float) ily/2. &&
+                     z[2*i] < (float)ily/2.) && z[2*i+1] == 0. )
+                {
+                    found = 2*i ;
+                    j ++ ;
+                }
+                else
+                {
+                    continue ;
+                }
+            }
+            if ( j == 0 )
+            {
+                sinfo_msg_warning(" no offset solution found for "
+                                  "line %d in column %d\n", line, col) ;
+                continue ;
+            }
+            else if ( j == 1 )
+            {
+                cenpos = z[found] + (float) ily/2. ;
+            }
+            else
+            {
+                sinfo_msg_warning(" two or more offset solutions found "
+                                  "for line %d in column %d", line, col) ;
+                continue ;
+            }
+
+            /*----------------------------------------------------------------
+             * magnify image by the given factor add an additional offset
+             */
+            cenpix = cenpos ;
+
+            /* determine max and min pixel limits over which line should 
+               be convolved */
+            cmin = (sinfo_new_nint(cenpix) - (var-1)) > 0 ? 
+                    sinfo_new_nint(cenpix) - (var-1) : 0 ;
+            cmax = (sinfo_new_nint(cenpix) + (var-1)) < ily ?
+                    sinfo_new_nint(cenpix) + (var-1)  : ily ;
+
+            /* convolve neon lines with Gaussian function */
+            for ( j = cmin ; j < cmax ; j++ )
+            {
+                emline[j] += intensity[line] * 
+                       exp((double)(-0.5*(j-cenpix)*(j-cenpix))/(double)var) ;
+            }
+        }
+
+        /*--------------------------------------------------------------------
+         * for each column, map the image data points onto an magFactor times 
+           bigger element grid for FFT  in the cross sinfo_correlation, first 
+           initialize the two helping arrays for each new column.
+         */
+        for ( k = 0 ; k < ily ; k++ )
+        {
+            spec[k] = 0. ;
+        }
+
+        /* now take the image data points of the column and put them into 
+           the spec array */
+        for ( row = 0 ; row < ily ; row++ ) /* go through the column */
+        {
+            /* set bad pixels or negative values to zero */
+            if (!isnan(pidata[col + row*ilx]) &&
+                (pidata[col + row*ilx] > 0.))
+            {
+                spec[row] = pidata[col + row*ilx] ;
+            }
+            else
+            {
+                spec[row] = 0. ;
+            }
+        }
+        /* convolve the spectrum by Gaussian */
+        filter_spec = sinfo_function1d_filter_lowpass(spec,ily, 
+                                                      LOW_PASS_GAUSSIAN, 
+                                                      magFactor) ; 
+
+        /* now call the cross sinfo_correlation routine */
+        result = sinfo_new_xcorrel( filter_spec, ily, emline, ily,
+                          ily/2, &delta, &maxlag, &xcorr_max) ;
+
+        if ( xcorr_max <= 0. )
+        {
+            sinfo_msg_warning("no positive cross sinfo_correlation "
+                              "sum , col %d set to ZERO \n", col) ;
+            for ( row = 0 ; row < ily ; row++ )
+            {
+                podata[col + row*ilx] = ZERO ;
+            }
+            sinfo_function1d_del(filter_spec) ;
+            cpl_free(result) ;
+            continue ;
+        }
+
+       /* in this section, we fit the sinfo_correlation function with a gauss, 
+          and find its peak, thus getting subpixel-accuracy */
+
+        i = maxlag; j = i+1;
+        while (result[j] < result[i])
+        {
+            i++; j++;
+        }
+        i = maxlag; k = i-1;
+        while (result[k] < result[i])
+        {
+            i--; k--;
+        }
+        width = j-k+1;
+        /* allocate memory for the spectral sinfo_vector */
+        if ( NULL == (peak = sinfo_new_vector (width)) )
+        {
+            sinfo_msg_error (" cannot allocate new Vector \n") ;
+            sinfo_function1d_del(filter_spec) ;
+            cpl_free(result) ;
+            return NULL ;
+        }
+
+
+        /* allocate memory */
+        xdat = (float *) cpl_calloc( peak -> n_elements, sizeof (float) ) ;
+        wdat = (float *) cpl_calloc( peak -> n_elements, sizeof (float) ) ;
+        mpar = (int *)   cpl_calloc( MAXPAR, sizeof (int) ) ;
+
+        /* determine the values of the spectral sinfo_vector given as input */
+        /* go through the chosen column */
+
+        for ( i = 0 ; i < width ; i++ )
+        {
+            peak -> data[i] = result[k+i]/xcorr_max * 100. ;
+            xdat[i] = i;
+            wdat[i] = 1.0;
+        }
+
+        /* set initial values for the fitting routine */
+        xdim     = XDIM;
+        ndat     = peak -> n_elements ;
+        numpar   = MAXPAR ;
+        tol      = TOL ;
+        lab      = LAB ;
+        its      = ITS ;
+        par[1] = width/2.0 ;
+        par[2] = (float) (maxlag - k) ;
+        par[3] = (peak -> data[0] + peak -> data[peak->n_elements - 1]) / 2.0 ;
+        par[0]  = result[maxlag]/xcorr_max * 100. - (par[3]) ;
+
+        for ( i = 0 ; i < MAXPAR ; i++ )
+        {
+            derv_par[i] = 0.0 ;
+            mpar[i] = 1 ;
+        }
+
+        /* finally, do the least square fit using a sinfo_gaussian */
+        if ( 0 > ( iters = sinfo_new_lsqfit_c( xdat, &xdim, peak -> data, 
+                                               wdat, &ndat, par, 
+                                               derv_par, mpar,
+                                               &numpar, &tol, &its, &lab )) )
+        {
+            sinfo_msg_warning (" sinfo_new_lsqfit_c: least squares fit "
+                               "failed in col: %d, error no.: %d", col, iters);
+            sinfo_new_destroy_vector ( peak ) ;
+            cpl_free ( xdat ) ;
+            cpl_free ( wdat ) ;
+            cpl_free ( mpar ) ;
+            sinfo_function1d_del(filter_spec) ;
+            cpl_free(result) ;
+            continue ;
+        }
+
+        sinfo_new_destroy_vector ( peak ) ;
+        cpl_free (xdat) ;
+        cpl_free (wdat) ;
+        cpl_free (mpar) ;
+        sinfo_function1d_del(filter_spec) ;
+        cpl_free(result) ;
+
+        wavelag =((float)ily/2 - (float)k - par[2]) ;
+
+        if ( fabs(wavelag) > (float)ily/20. )
+        {
+            sinfo_msg_warning("wavelag very big , col %d set to ZERO ", col) ;
+            for ( row = 0 ; row < ily ; row++ )
+            {
+                podata[col + row*ilx] = ZERO ;
+            }
+            continue ;
+        }
+
+        /*--------------------------------------------------------------------
+         * determine new zero order coefficient centreval, of which the 
+         * formula is determined by setting equal a polynomial shifted by 
+         * wavelag with the same higher order coefficients and set the new 
+         * zero order coefficient to get both sides of the equation 
+         * approximately equal.
+         */
+        centreval = a_initial ;
+        for ( i = 1 ; i < n_fitcoeffs ; i++ )
+        {
+            if ( i%2 == 0 )
+            {
+                sign = -1 ;
+            }
+            else
+            {
+                sign = 1 ;
+            }
+            centreval += (float)sign * coeffs[i][col]*pow(wavelag, i) ;
+        }
+        a0[col] = centreval ;
+    }
+
+    /* go through the single slitlets */
+    for ( ns = 0 ; ns < N_SLITLETS ; ns++ )
+    {
+        /* determine the slitlet edges */
+        if ( ns == 0 )
+        {
+            ed1 = 0 ;
+            ed2 = edge[0] ;
+        }
+        else if ( ns == N_SLITLETS - 1 )
+        {
+            ed1 = edge[N_SLITLETS - 2] ;
+            ed2 = ilx ;
+        }
+        else
+        {
+            ed1 = edge[ns-1] ;
+            ed2 = edge[ns] ;
+        }
+
+        nc = 0 ;
+        for ( i = ed1 ; i < ed2 ; i++ )
+        {
+            if ( isnan(a0[i]) || a0[i] == 0. )
+            {
+                continue ;
+            }
+            else
+            {
+                nc++ ;
+            }
+        }
+        if ( NULL == (acoefsclean = (float*) cpl_calloc(nc , sizeof(float))) )
+        {
+            sinfo_msg_error("could not allocate memory for acoefsclean!\n") ;
+            return NULL ;
+        }
+        nc = 0 ;
+        for ( i = ed1 ; i < ed2 ; i++ )
+        {
+            if ( isnan(a0[i]) || a0[i] == 0. )
+            {
+                continue ;
+            }
+            else
+            {
+                acoefsclean[nc] = a0[i] ;
+                nc++ ;
+            }
+        }
+
+        /* ----------------------------------------------------------
+         * determine the clean mean and sigma value of the coefficients,
+         * that means reject 10 % of the extreme low and high values
+         */
+        sinfo_pixel_qsort(acoefsclean, nc) ;
+        sum   = 0. ;
+        sumq  = 0. ;
+        mean  = 0. ;
+        sigma = 0. ;
+        n     = 0 ;
+        for ( i = (int)((float)nc*LOW_REJECT) ; 
+              i < (int)((float)nc*HIGH_REJECT) ; i++ )
+        {
+            sum  += (double)acoefsclean[i] ;
+            sumq += ((double)acoefsclean[i] * (double)acoefsclean[i]) ;
+            n ++ ;
+        }
+        mean          = sum/(double)n ;
+        sigma         = sqrt( sumq/(double)n - (mean * mean) ) ;
+        cliphi        = mean + sigma * (double)3. ;
+        cliplo        = mean - sigma * (double)3. ;
+        /* fit only the reasonnable values */
+        num = 0 ;
+        col_index = 0 ;
+        for ( i = ed1 ; i < ed2 ; i++ )
+        {
+            /* take only the reasonnable coefficients */
+            if ( !isnan(a0[i]) && (a0[i] <= cliphi) && (a0[i] >= cliplo) &&
+                 (a0[i] != 0.) )
+            {
+                sub_acoefs[num]    = a0[i] ;
+                sub_dacoefs[num]   = 0.0000005 ;
+                sub_col_index[num] = col_index ;
+                num ++ ;
+            }
+            col_index++ ;
+        }
+        ndata = num ;
+        offset2 = (float)(col_index-1) / 2. ;
+
+        if ( ndata < n_fitcoeffs )
+        {
+            sinfo_msg_error(" not enough data found in slitlet %d\
+                    to determine the fit coefficients.\n", ns) ;
+            cpl_free(acoefsclean) ;
+            return NULL ;
+        }
+
+        /* allocate coefficient matrices, see numerical recipe function 
+           sinfo_matrix */
+        ucoefs = sinfo_matrix(1, ndata, 1, n_fitcoeffs) ;
+        vcoefs = sinfo_matrix(1, ndata, 1, n_fitcoeffs) ;
+        covar  = sinfo_matrix(1, n_fitcoeffs, 1, n_fitcoeffs) ;
+
+        /* scale the x-values for the fit */
+        for ( i = 0 ; i < ndata ; i++ )
+        {
+            sub_col_index[i] = (sub_col_index[i] - offset2) / offset2 ;
+        }
+
+        /* finally, do the singular value decomposition fit */
+        sinfo_svd_fitting ( sub_col_index-1, sub_acoefs-1, 
+                            sub_dacoefs-1, ndata, bcoef[ns]-1,
+                            n_fitcoeffs, ucoefs, vcoefs, wcoefs-1, 
+                            covar, &chisq, sinfo_fpol ) ;
+
+        /* scale the found coefficients */
+        for ( i = 0 ; i < n_fitcoeffs ; i ++ )
+        {
+            bcoef[ns][i] /= pow( offset2, i ) ;
+        }
+
+        /* free memory */
+        cpl_free (acoefsclean) ;
+        sinfo_free_matrix( ucoefs, 1/*, ndata*/, 1/*, n_fitcoeffs */) ;
+        sinfo_free_matrix( vcoefs, 1/*, ndata*/, 1/*, n_fitcoeffs */) ;
+        sinfo_free_matrix( covar, 1/*, n_fitcoeffs*/, 1/*, n_fitcoeffs*/) ;
+
+        /* now calculate the smoothed acoefs for each column */
+        col_index = 0 ;
+        for ( i = ed1 ; i < ed2 ; i++ )
+        {
+            a0_clean[i] = 0. ;
+            for ( n = 0 ; n < n_fitcoeffs ; n++ )
+            {
+              a0_clean[i] += bcoef[ns][n] * 
+                             pow((float)col_index - offset2, n) ;
+            }
+            col_index++ ;
+        }
+
+    }
+
+    for ( col = 0 ; col < ilx ; col++ )
+    {
+        /* prepare to write out wavelength as pixel values */
+        for ( row = 0 ; row < oly ; row++ )
+        {
+            centrepix = (float)row - ((float)oly - 1.)/2. ;
+            pixvalue = 0. ;
+            for ( i = 1 ; i < n_fitcoeffs ; i++ )
+            {
+                pixvalue += coeffs[i][col]*pow(centrepix, i) ;
+            }
+            podata[col+row*olx] = a0_clean[col] + pixvalue ;
+        }
+    }
+
+
+    cpl_free(emline) ;
+    cpl_free(spec) ;
+    cpl_free(wave) ;
+    cpl_free(a0) ;
+    cpl_free(a0_clean) ;
+
+
+    cpl_free(sub_col_index) ;
+    cpl_free(sub_acoefs);
+    cpl_free(sub_dacoefs) ;
+
+    cpl_free(a) ;
+    cpl_free(z) ;
+
+    sinfo_new_destroy_2Dfloatarray(&bcoef,n_fitcoeffs) ;
+    cpl_free(wcoefs) ;
+
+    return wavemap ;
+}
+
+/**
+ at brief This routine cross-correlates a shifted emission line frames and 
+       determines the shift to the old one which is given by its polynomial 
+       coefficients.
+ at name  sinfo_new_create_shifted_slit_wavemap3()
+ at param lineIm:       new shifted emission line frame
+ at param coeffs:       calculated polynomial coefficients,
+                                      output of sinfo_coeffsCrossSlitFit()
+ at param n_fitcoeffs:  number of polynomial coefficients, order + 1
+ at param wavelength:   wavelength list from line list
+ at param intensity:    corresponding line intensity from line list
+ at param n_lines:      number of lines in the list
+ at param magFactor:    magnification factor for help arrays
+ at return wavelength map  
+ at doc   This routine cross-correlates a shifted emission line frames and 
+       determines the shift to the old one which is given by its polynomial 
+       coefficients.
+       Then the a0 coefficients is recalculated by using a clean mean of the 
+       determined offset (shift) over the whole frame and afterwards a new 
+       wavelength calibration map is generated 
+       using the already calculated smoothed polynomial coefficients.
+*/
+
+cpl_image * sinfo_new_create_shifted_slit_wavemap3 ( cpl_image * lineIm,
+                              float    ** coeffs,
+                          int      n_fitcoeffs,
+                                      float  * wavelength,
+                                      float  * intensity,
+                                      int      n_lines,
+                                      int      magFactor )
+{
+
+    cpl_image * wavemap ;
+    double * result ;
+    float * filter_spec ;
+    float centreval ;
+    float centrepix ;
+    float cenpos, cenpix ;
+    float pixvalue ;
+    float wavelag_mean ;
+    /*float maxres ;*/
+    float angst ;
+    /*float temp ;*/
+    float a_initial ;
+    /*float solution[n_fitcoeffs-1], im_solution[n_fitcoeffs-1] ;*/
+
+    float par[MAXPAR] ;
+    float derv_par[MAXPAR] ;
+    int        numpar, its ;
+    int        * mpar ;
+    float      tol, lab ;
+    float      * xdat, * wdat ;
+    Vector     * peak;
+    int   iters, xdim, ndat ;
+    int   row , col ;
+    int   i, j, k/*, l, m, n*/ ;
+    int   sign, found, line, width ;
+    int var, maxlag, cmin, cmax ;
+
+    float* emline=NULL ;
+    float* spec=NULL ;
+    float* wavelag=NULL ;
+    float* wave=NULL ;
+    double* a=NULL ;
+    double* z=NULL ;
+
+    gsl_poly_complex_workspace * w ;
+    double xcorr_max ;
+    int delta ;
+    
+    int ilx=0;
+    int ily=0;
+    float* pidata=NULL;
+    int olx=0;
+    int oly=0;
+    float* podata=NULL;
+
+
+
+    if ( lineIm == NULL )
+    {
+        sinfo_msg_error (" no input image given!\n") ;
+        return NULL ;
+    }
+    ilx=cpl_image_get_size_x(lineIm);
+    ily=cpl_image_get_size_y(lineIm);
+    pidata=cpl_image_get_data_float(lineIm);
+
+    if ( coeffs == NULL )
+    {
+        sinfo_msg_error (" no coefficient sinfo_matrix given!\n") ;
+        return NULL ;
+    }
+    if ( n_fitcoeffs < 2 )
+    {
+        sinfo_msg_error (" wrong number of polynomial coefficients given!\n") ;
+        return NULL ;
+    }
+
+    if ( wavelength == NULL || intensity == NULL )
+    {
+        sinfo_msg_error (" no wavelength list given!\n") ;
+        return NULL ;
+    }
+    if ( n_lines < 1 || magFactor < 1 )
+    {
+        sinfo_msg_error (" wrong n_lines or magFactor given!\n") ;
+        return NULL ;
+    }
+    
+    var    = (magFactor - 1)*(magFactor - 1) ;
+    /* find out if Angstroem or microns are used */
+    if ( wavelength[0] > 10000. )
+    {
+        /* Angstroem */
+        angst = 10000. ;
+    }
+    else if ( wavelength[0] > 1000. && wavelength[0] < 10000. )
+    {
+        /* nanometers */
+        angst = 1000. ;
+    }
+    else
+    {
+        /* microns */
+        angst = 1. ;
+    }
+
+
+
+    /* allocate memory */
+    if ( NULL == (wavemap = cpl_image_new ( ilx, ily,CPL_TYPE_FLOAT)) )
+    {
+        sinfo_msg_error (" could not allocate memory!\n") ;
+        return NULL ;
+    }
+    podata=cpl_image_get_data_float(lineIm);
+    olx=ilx;
+    oly=ily;
+
+    emline=cpl_calloc(ily,sizeof(float)) ;
+    spec=cpl_calloc(ily,sizeof(float)) ;
+    wavelag=cpl_calloc(ilx,sizeof(float)) ;
+    wave=cpl_calloc(n_lines,sizeof(float)) ;
+    a=cpl_calloc(n_fitcoeffs,sizeof(double)) ;
+    z=cpl_calloc(2*(n_fitcoeffs - 1),sizeof(double)) ;
+
+    
+    /* first store each spectrum in a buffer */
+    for ( col = 0 ; col < ilx ; col++ )
+    {
+        /* initialize the emline array for each column */
+        for ( i = 0 ; i < ily ; i++ )
+        {
+            emline[i] = 0. ;
+        }
+        /* determine the coefficients by using the given bcoefs */
+        for ( i = 0 ; i < n_fitcoeffs ; i++ )
+        {
+            /* initialize coefficients and solution */
+            if (i < n_fitcoeffs-1)
+            {
+                z[2*i] = 0. ;
+                z[2*i+1] = 0. ;
+            }
+            a[i] = coeffs[i][col] ;
+        }
+         
+        a_initial = coeffs[0][col] ;
+        /* go through the lines and generate an artificial spectrum */
+        for ( line = 0 ; line < n_lines ; line++ )
+        {
+            /* go from Angstroem to micron */
+            wave[line] = wavelength[line]/angst ;
+
+            /* ----------------------------------------------------------------
+             * solve the polynomial for the exact offset of the line that means
+             * find the root of the polynomial of order n_fitcoefs - 1
+             */
+            a[0] = a_initial - wave[line] ;
+
+            if (NULL==(w=sinfo_gsl_poly_complex_workspace_alloc(n_fitcoeffs))) 
+            {
+                sinfo_msg_error(" could not allocate complex workspace!") ;
+                cpl_image_delete(wavemap) ;
+                return NULL ;
+            }
+            if (-1 == sinfo_gsl_poly_complex_solve(a, n_fitcoeffs, w, z)) 
+            {
+                sinfo_msg_error("sinfo_gsl_poly_complex_solve did not work!") ;
+                cpl_image_delete(wavemap) ;
+                return NULL ;
+            }
+            sinfo_gsl_poly_complex_workspace_free(w) ;           
+
+            j = 0 ;
+            found = -1 ;
+            for ( i = 0 ; i < n_fitcoeffs - 1 ; i++ )
+            {
+                /* test for appropriate solution */
+                if( (z[2*i] > (-1.)*(float) ily/2. &&
+                     z[2*i] < (float)ily/2.) && z[2*i+1] == 0. )
+                {
+                    found = 2*i ;
+                    j ++ ;
+                }
+                else
+                {
+                    continue ;
+                }
+            }
+            if ( j == 0 )
+            {
+                sinfo_msg_warning("no offset solution found for line %d "
+                                  "in column %d\n", line, col) ;
+                continue ;
+            }
+            else if ( j == 1 )
+            {
+                cenpos = z[found] + (float) ily /2. ;
+            }
+            else
+            {
+                sinfo_msg_warning("two or more offset solutions found for "
+                                  "line %d in column %d\n", line, col) ;
+                continue ;
+            }
+
+            /*-----------------------------------------------------------------
+             * magnify image by the given factor add an additional offset
+             */
+            cenpix = cenpos ;
+
+            /* determine max and min pixel limits over which 
+               line should be convolved */
+            cmin = (sinfo_new_nint(cenpix) - (var-1)) > 0 ? 
+                    sinfo_new_nint(cenpix) - (var-1) : 0 ;
+            cmax = (sinfo_new_nint(cenpix) + (var-1)) < ily ?
+                    sinfo_new_nint(cenpix) + (var-1)  : ily ;
+
+            /* convolve neon lines with Gaussian function */
+            for ( j = cmin ; j < cmax ; j++ )
+            {
+                emline[j] += intensity[line] * 
+                        exp((double)(-0.5*(j-cenpix)*(j-cenpix))/(double)var) ;
+            }
+        }
+
+        /*--------------------------------------------------------------------
+         * for each column, map the image data points onto an magFactor times 
+           bigger element grid for FFT in the cross sinfo_correlation, first 
+           initialize the two helping arrays for each new column.
+         */
+        for ( k = 0 ; k < ily ; k++ )
+        {
+            spec[k] = 0. ;
+        }
+
+        /* now take the image data points of the column and put them into 
+           the spec array */
+        for ( row = 0 ; row < ily ; row++ ) /* go through the column */
+        {
+            /* set bad pixels or negative values to zero */
+            if (!isnan(pidata[col + row*ilx]) &&
+                            (pidata[col + row*ilx] > 0.))
+            {
+                spec[row] = pidata[col + row*ilx] ;
+            }
+            else
+            {
+                spec[row] = 0. ;
+            }
+        }
+        /* convolve the spectrum by Gaussian */
+        filter_spec = sinfo_function1d_filter_lowpass(spec, ily, 
+                                                      LOW_PASS_GAUSSIAN, 
+                                                      magFactor) ; 
+
+        /* now call the cross sinfo_correlation routine */
+        result = sinfo_new_xcorrel( filter_spec, ily, emline, ily,
+                          ily/2, &delta, &maxlag, &xcorr_max) ;
+
+        if ( xcorr_max <= 0. )
+        {
+            sinfo_msg_warning("no positive cross correlation sum , "
+                              "col %d set to ZERO \n", col) ;
+            for ( row = 0 ; row < ily ; row++ )
+            {
+                podata[col + row*ilx] = ZERO ;
+            }
+            sinfo_function1d_del(filter_spec) ;
+            cpl_free(result) ;
+            continue ;
+        }
+
+       /* in this section, we fit the sinfo_correlation function with a 
+           gauss, and find its peak, thus getting subpixel-accuracy */
+
+        i = maxlag; j = i+1;
+        while (result[j] < result[i])
+        {
+            i++; j++;
+        }
+        i = maxlag; k = i-1;
+        while (result[k] < result[i])
+        {
+            i--; k--;
+        }
+        width = j-k+1;
+        /* allocate memory for the spectral sinfo_vector */
+        if ( NULL == (peak = sinfo_new_vector (width)) )
+        {
+            sinfo_msg_error (" cannot allocate new Vector \n") ;
+            sinfo_function1d_del(filter_spec) ;
+            cpl_free(result) ;
+            return NULL ;
+        }
+
+
+        /* allocate memory */
+        xdat = (float *) cpl_calloc( peak -> n_elements, sizeof (float) ) ;
+        wdat = (float *) cpl_calloc( peak -> n_elements, sizeof (float) ) ;
+        mpar = (int *)   cpl_calloc( MAXPAR, sizeof (int) ) ;
+
+        /* determine the values of the spectral sinfo_vector given as input */
+        /* go through the chosen column */
+
+        for ( i = 0 ; i < width ; i++ )
+        {
+            peak -> data[i] = result[k+i]/xcorr_max * 100. ;
+            xdat[i] = i;
+            wdat[i] = 1.0;
+        }
+
+        /* set initial values for the fitting routine */
+        xdim     = XDIM;
+        ndat     = peak -> n_elements ;
+        numpar   = MAXPAR ;
+        tol      = TOL ;
+        lab      = LAB ;
+        its      = ITS ;
+        par[1] = width/2.0 ;
+        par[2] = (float) (maxlag - k) ;
+        par[3] = (peak -> data[0] + peak -> data[peak->n_elements - 1]) / 2.0 ;
+        par[0]  = result[maxlag]/xcorr_max * 100. - (par[3]) ;
+
+        for ( i = 0 ; i < MAXPAR ; i++ )
+        {
+            derv_par[i] = 0.0 ;
+            mpar[i] = 1 ;
+        }
+
+        /* finally, do the least square fit using a sinfo_gaussian */
+        if ( 0 > ( iters = sinfo_new_lsqfit_c( xdat, &xdim, 
+                                               peak -> data, wdat, 
+                                               &ndat, par, derv_par, mpar,
+                                               &numpar, &tol, &its, &lab )) )
+        {
+            sinfo_msg_warning (" sinfo_new_lsqfit_c: least squares fit"
+                               " failed in col: %d, error no.: %d\n", 
+                               col, iters) ;
+            sinfo_new_destroy_vector ( peak ) ;
+            cpl_free ( xdat ) ;
+            cpl_free ( wdat ) ;
+            cpl_free ( mpar ) ;
+            sinfo_function1d_del(filter_spec) ;
+            cpl_free(result) ;
+            continue ;
+        }
+
+        sinfo_new_destroy_vector ( peak ) ;
+        cpl_free (xdat) ;
+        cpl_free (wdat) ;
+        cpl_free (mpar) ;
+        sinfo_function1d_del(filter_spec) ;
+        cpl_free(result) ;
+
+        wavelag[col] =((float)ily/2 - (float)k - par[2]) ;
+
+    }
+    
+    if (FLT_MAX==(wavelag_mean=sinfo_new_clean_mean(wavelag, ilx, 10., 10.)) )
+    {
+        sinfo_msg_error(" could not determine a mean offset\n") ;
+        return NULL ;
+    }
+
+    if ( fabs(wavelag_mean) > (float)ily/20. )
+    {
+        sinfo_msg_error(" wavelag too big \n") ;
+        return NULL ;
+    }
+
+    
+
+    for ( col = 0 ; col < ilx ; col++ )
+    {
+        /*--------------------------------------------------------------------
+         * determine new zero order coefficient centreval, of which the 
+         * formula is determined by setting equal a polynomial shifted by 
+         * wavelag with the same higher order coefficients and set the new 
+         * zero order coefficient to get both sides of the equation 
+         * approximately equal.
+         */
+        a_initial = coeffs[0][col] ;
+    centreval = a_initial ;
+    for ( i = 1 ; i < n_fitcoeffs ; i++ )
+        {
+            if ( i%2 == 0 )
+            {
+                sign = -1 ;
+            }
+            else
+            {
+                sign = 1 ;
+            }
+            centreval += (float)sign * coeffs[i][col]*pow(wavelag_mean, i) ;
+        }
+
+    
+        /* prepare to write out wavelength as pixel values */
+        for ( row = 0 ; row < oly ; row++ )
+        {
+            centrepix = (float)row - ((float)oly - 1.)/2. ;
+            pixvalue = 0. ;
+            for ( i = 1 ; i < n_fitcoeffs ; i++ )
+            {
+                pixvalue += coeffs[i][col]*pow(centrepix, i) ;
+            }
+            podata[col+row*olx] = centreval + pixvalue ;
+        }
+    }
+
+
+
+    cpl_free(emline) ;
+    cpl_free(spec) ;
+    cpl_free(wavelag) ;
+    cpl_free(wave) ;
+    cpl_free(a) ;
+    cpl_free(z) ;
+
+
+    return wavemap ;
+}
+
+/**
+ at brief his routine determines the clean averaged error (shift) of the 
+       brightest lines in the emission line image with respect to the 
+       expected positions from the wavelength calibration.
+ at name       sinfo_new_check_line_positions()
+ at param lineIm:       new shifted emission line frame
+ at param coeffs:       calculated polynomial coefficients, output of 
+                     sinfo_coeffsCrossSlitFit()
+ at param n_fitcoeffs:  number of polynomial coefficients, order + 1
+ at param   guess_disp1  guess dispersion (to have positioning error in pix)
+ at param par:          fit parameters
+ at return clean averaged position error (shift) of the brightest lines in the 
+        emission line image with respect to the expected positions from the 
+        wavelength calibration (error in the wavelength regime (microns)).
+ at doc This routine determines the clean averaged error (shift) of the brightest 
+     lines in the emission line image with respect to the expected positions 
+     from the wavelength calibration. 
+     The error is given in the wavelength regime (microns).
+     It should give the user an impression of the quality of the wavelength 
+     calibration.  
+*/
+
+float sinfo_new_check_line_positions ( cpl_image     * lineIm,
+                       float       ** coeffs,
+                       int            n_fitcoeffs,
+                       float            gdisp1,
+                       FitParams   ** par )
+{
+    float wave_shift=0 ;
+    float amp[100] ;
+    float sort_amp[100] ;
+    float offset=0 ;
+    float shift=0 ;
+    float position=0;
+    float lambda=0;
+    float wave=0 ;
+    int i=0;
+    int j=0;
+    int k=0;
+    int l=0;
+    int m=0;
+    int n=0;
+    int col=0;
+    int firstj=0;
+    float* shift_col=NULL ;
+    int* foundit=NULL ;
+    int n_lines=0;
+    int lin, found=0 ;
+    int lx=0;
+    int ly=0;
+    float* pdata=NULL;
+
+    if ( lineIm == NULL )
+    {
+        sinfo_msg_error (" no input image given!\n") ;
+        return FLAG ;
+    }
+    lx=cpl_image_get_size_x(lineIm);
+    ly=cpl_image_get_size_y(lineIm);
+    pdata=cpl_image_get_data_float(lineIm);
+
+    if ( coeffs == NULL )
+    {
+        sinfo_msg_error (" no coefficient sinfo_matrix given!\n") ;
+        return FLAG ;
+    }
+    if ( par == NULL )
+    {
+        sinfo_msg_error (" no fit parameters given!\n") ;
+        return FLAG ;
+    }
+    if ( n_fitcoeffs < 2 )
+    {
+        sinfo_msg_error (" wrong number of polynomial coefficients given!\n") ;
+        return FLAG ;
+    }
+
+    offset = (float) (ly -1.) / 2. ;
+    n_lines = par[0]->n_params/lx ;
+
+    shift_col=cpl_calloc(lx,sizeof(float)) ;
+    foundit=cpl_calloc(par[0]->n_params,sizeof(int)) ;
+    
+    /*search for the brightest 5 lines in each column and compute the 
+      wavelength difference*/
+    for ( col = 0 ; col < lx ; col++ )
+    {
+        n = 0 ;
+        for ( i = 0 ; i < par[0]->n_params ; i++ )
+        {
+            if (par[i]->column == col && par[i]->fit_par[2] != 0. && 
+                par[i]->fit_par[1] > 1. && par[i]->fit_par[1] < 7. )
+            {
+                foundit[n] = i ;
+                amp[n] = par[i]->fit_par[0] ;
+                sort_amp[n] = amp[n] ;
+                n++ ;
+            }
+        }
+        sinfo_pixel_qsort(sort_amp, n) ;
+
+        if ( n > 5 )
+        {
+            firstj = n - 5 ;
+        }
+        else
+        {
+            firstj = 0 ;
+        }
+        l = 0 ; 
+        shift = 0 ;
+        for ( j = firstj ; j < n ; j++ )
+        {
+            for ( m = 0 ; m < n ; m++ )
+            {
+                if ( sort_amp[j] == amp[m] )
+                {
+                    position = par[foundit[m]]->fit_par[2] ; 
+                    lambda   = par[foundit[m]]->wavelength ;
+                    wave = 0 ;
+                    for ( k = 0 ; k < n_fitcoeffs ; k++ ) 
+                    {
+                        wave += coeffs[k][col]*pow(position-offset, k) ;
+                    }
+                    shift += lambda - wave ;
+                    l++ ;
+                }
+            }
+        }
+        if ( l == 0 ) continue ;
+        shift_col[col] = shift/(float)l ; 
+    }
+    wave_shift = sinfo_new_clean_mean(shift_col, lx, 10., 10.) ;
+    sinfo_msg("Overall positioning error: %3.2g [um] %3.2g [pix]", 
+               wave_shift,wave_shift/fabs(gdisp1)) ;
+
+
+    /* determine positioning error for each found line */
+    for ( lin = 0 ; lin < n_lines ; lin++ )
+    {
+        for ( col = 0 ; col < lx ; col++ )
+        {
+            shift_col[col] = 0. ;
+            found = -1 ;
+            for ( i = 0 ; i < par[0]->n_params ; i++ )
+            {
+                if (par[i]->column == col && par[i]->fit_par[2] != 0. && 
+                    par[i]->fit_par[1] > 1. && par[i]->fit_par[1] < 7. && 
+                    par[i]->line == lin )
+                {
+                    found = i ;
+                }
+            }
+            if (found == -1) break ;
+
+            position = par[found]->fit_par[2] ; 
+            lambda  = par[found]->wavelength ;
+            wave = 0 ;
+            for ( k = 0 ; k < n_fitcoeffs ; k++ ) 
+            {
+                wave += coeffs[k][col]*pow(position-offset, k) ;
+            }
+            shift_col[col] = lambda - wave ;
+        }
+        if (found != -1 )
+        {
+      sinfo_msg("shift: %3.2g [um] %3.2g (pix) at: %4.3f [um]",
+            sinfo_new_clean_mean(shift_col,lx, 10., 10.),
+                    sinfo_new_clean_mean(shift_col,lx, 10., 10.)/fabs(gdisp1),
+                    lambda) ;
+        }
+    }
+    cpl_free(shift_col) ;
+    cpl_free(foundit) ;
+
+    return wave_shift ;
+}
+
+
+/**
+ at brief This routine determines the clean averaged error (shift) of the 
+       brightest lines in the emission line image with respect to the 
+       expected positions from the wavelength calibration.
+ at name  sinfo_new_check_correlated_line_positions()
+ at param lineIm:       new shifted emission line frame
+ at param coeffs:       calculated polynomial coefficients,
+                                      output of sinfo_coeffsCrossSlitFit()
+ at param n_fitcoeffs:  number of polynomial coefficients, order + 1
+ at param wavelength:   wavelength list from line list
+ at param intensity:    corresponding line intensity from line list
+ at param n_lines:      number of lines in list
+ at param fwhm:         guess value for full width of half maximum of 
+                     sinfo_gaussian
+ at param width:        half width of the box where the line must sit
+ at param min_amplitude: minimum line amplitude with respect to the background to 
+                      do the fit
+ at param par:          fit parameters
+ at return clean averaged position error (shift) of the brightest lines in the 
+        emission line image with respect to the expected positions from the 
+        wavelength calibration (error in the wavelength regime (microns)).
+ at doc This routine determines the clean averaged error (shift) of the brightest 
+     lines in the emission line image with respect to the expected positions 
+     from the wavelength calibration.  The error is given in the wavelength 
+     regime (microns). It should give the user an impression of the quality 
+     of the wavelength calibration.  
+*/
+
+float sinfo_new_check_correlated_line_positions ( cpl_image     * lineIm,
+                                     float       ** coeffs,
+                                     int            n_fitcoeffs,
+                                     float        * wavelength,
+                                     float        * intensity,
+                                     int            n_lines,
+                                     float          fwhm, 
+                                     float          width,
+                                     float          min_amplitude,
+                                     float          dispersion,
+                                     FitParams   ** par )
+{
+    float wave_shift=0 ;
+    float offset=0;
+    float shift=0;
+    float position=0;
+    float lambda=0;
+    float wave=0;
+    int i=0;
+    int j=0;
+    int k=0;  /*, l, m*/
+    int n=0;
+    int c=0;
+    int z=0;
+    int col=0;/*, firstj*/
+    int found=0;/*lin,*/
+    int line=0;
+    int result=0;
+    float cenpos=0;
+    float angst=0;
+    float a_initial=0;
+
+    int* foundit=NULL ;
+    float* shift_col=NULL ;
+    float* wave_cor=NULL ;
+    double* a=NULL ;
+    double* zroot=NULL ;
+
+    gsl_poly_complex_workspace * w=NULL ;
+    Vector * vline=NULL;
+    int    * mpar=NULL;
+    float  * xdat=NULL;
+    float  * wdat=NULL;
+    int lx=0;
+    int ly=0;
+    float* pdata=NULL;
+
+    if ( lineIm == NULL )
+    {
+        sinfo_msg_error (" no input image given!\n") ;
+        return FLAG ;
+    }
+    lx=cpl_image_get_size_x(lineIm);
+    ly=cpl_image_get_size_y(lineIm);
+    pdata=cpl_image_get_data_float(lineIm);
+
+
+    if ( coeffs == NULL )
+    {
+        sinfo_msg_error (" no coefficient sinfo_matrix given!\n") ;
+        return FLAG ;
+    }
+    if ( par == NULL )
+    {
+        sinfo_msg_error (" no fit parameters given!\n") ;
+        return FLAG ;
+    }
+    if ( n_fitcoeffs < 2 )
+    {
+        sinfo_msg_error (" wrong number of polynomial coefficients given!\n") ;
+        return FLAG ;
+    }
+    if ( wavelength == NULL || intensity == NULL )
+    {
+        sinfo_msg_error (" no line list given!\n") ;
+        return FLAG ;
+    }
+    if ( fwhm <= 0 )
+    {
+        sinfo_msg_error (" wrong guess fwhm given!\n") ;
+        return FLAG ;
+    }
+    if ( width <= 0 )
+    {
+        sinfo_msg_error (" wrong half width given!\n") ;
+        return FLAG ;
+    } 
+    if ( min_amplitude <= 0 )
+    {
+        sinfo_msg_error (" wrong guess amplitude given!\n") ;
+        return FLAG ;
+    } 
+
+    /* allocate memory for the spectral sinfo_vector */
+    if ( NULL == (vline = sinfo_new_vector (2*width + 1)) )
+    {
+        sinfo_msg_error (" cannot allocate new Vector \n") ;
+        return -14 ;
+    }
+    /* allocate memory */
+    xdat = (float *) cpl_calloc( vline -> n_elements, sizeof (float) ) ;
+    wdat = (float *) cpl_calloc( vline -> n_elements, sizeof (float) ) ;
+    mpar = (int *)   cpl_calloc( MAXPAR, sizeof (int) ) ;
+
+
+    foundit=cpl_calloc(par[0]->n_params,sizeof(int)) ;
+    shift_col=cpl_calloc(lx,sizeof(float)) ;
+    wave_cor=cpl_calloc(n_lines,sizeof(float)) ;
+    a=cpl_calloc(n_fitcoeffs,sizeof(float)) ;
+    zroot=cpl_calloc(2*(n_fitcoeffs - 1),sizeof(float)) ;
+
+
+
+    /* determine the approximate line positions using the line list and the 
+       coefficients */
+    /* find out if Angstroem or microns are used */
+    if ( wavelength[0] > 10000. )
+    {
+        /* Angstroem */
+        angst = 10000. ;
+    }
+    else if ( wavelength[0] > 1000. && wavelength[0] < 10000. )
+    {
+        /* nanometers */
+        angst = 1000. ;
+    }
+    else
+    {
+        /* microns */
+        angst = 1. ;
+    }
+    offset = ((float) ly -1.) / 2. ;
+
+    k = 0 ;
+    for ( col = 10 ; col < 25 ; col++ )
+    {
+        /* determine the coefficients by using the given bcoefs */
+        for ( i = 0 ; i < n_fitcoeffs ; i++ )
+        {
+            /* initialize coefficients and solution */
+            if (i < n_fitcoeffs-1)
+            {
+                zroot[2*i] = 0. ;
+                zroot[2*i+1] = 0. ;
+            }
+            a[i] = coeffs[i][col] ;
+        }
+        a_initial = a[0] ;
+
+        /* go through the lines */
+        for ( line = 0 ; line < n_lines ; line++ )
+        {
+            /* go from Angstroem to micron */
+            wave_cor[line] = wavelength[line]/angst ;
+            if (line > 0 && line < n_lines-1)
+            {
+                if (fabs((wave_cor[line] - wave_cor[line-1]) / 
+                         dispersion ) < 2*width ||
+                    fabs((wave_cor[line] - wave_cor[line+1]) / 
+                         dispersion ) < 2*width )
+                {
+                    continue ;
+                }
+            }
+
+            a[0] = a_initial - wave_cor[line] ;
+
+            if (NULL==(w=sinfo_gsl_poly_complex_workspace_alloc(n_fitcoeffs)))
+            {
+                sinfo_msg_error(" could not allocate complex workspace!") ;
+                return FLAG ;
+            }
+            if (-1 == sinfo_gsl_poly_complex_solve(a, n_fitcoeffs, w, zroot))
+            {
+                sinfo_msg_error(" sinfo_gsl_poly_complex_solve did not work!") ;
+                return FLAG ;
+            }
+            sinfo_gsl_poly_complex_workspace_free(w) ;
+
+            j = 0 ;
+            found = -1 ;
+            for ( i = 0 ; i < n_fitcoeffs - 1 ; i++ )
+            {
+                /* test for appropriate solution */
+                if( (zroot[2*i] > (-1.)*(float) ly/2. &&
+                     zroot[2*i] < (float)ly/2.) && zroot[2*i+1] == 0. )
+                {
+                    found = 2*i ;
+                    j ++ ;
+                }
+                else
+                {
+                    continue ;
+                }
+            }
+
+            if ( j == 0 )
+            {
+                sinfo_msg_warning(" no offset solution found for line %d "
+                                  "in column %d\n", line, col) ;
+                continue ;
+            }
+            else if ( j == 1 )
+            {
+                cenpos = zroot[found] + (float)ly / 2. ; ;
+            }
+            else
+            {
+                sinfo_msg_warning(" two or more offset solutions found for \
+                       line %d in column %d\n", line, col) ;
+                continue ;
+            }
+
+            if ( cenpos <= 0 )
+            {
+                continue ;
+            }
+
+            /* --------------------------------------------------------------
+             * fit the single lines using sinfo_linefit and store the 
+             * parameters in
+             * an array of the FitParams data structure allParams[].
+             */
+            if ( (result = sinfo_new_line_fit ( lineIm, par[k], 
+                                                fwhm, line, col,
+                                         width, cenpos, min_amplitude, vline,
+                                         mpar, xdat, wdat ) ) < 0 )
+            {
+             sinfo_msg_debug ("sinfo_linefit failed, error no.: %d, "
+                              "column: %d, row: %f, line: %d\n", 
+                              result, col, cenpos, line) ;
+                continue ;
+            }
+            if ( (par[k] -> fit_par[0] <= 0.) || (par[k] -> fit_par[1] <= 0.)
+                  || (par[k] -> fit_par[2] <= 0.) )
+            {
+                sinfo_msg_warning ("negative fit parameters in column: %d, "
+                                   "line: %d\n", col, line) ;
+                continue ;
+            }
+            par[k] -> wavelength = wavelength[line] ;
+            k++ ;
+        }
+
+    }
+    
+    /* free memory */
+    sinfo_new_destroy_vector(vline);
+    cpl_free(xdat);
+    cpl_free(wdat);
+    cpl_free(mpar);
+
+    
+    c = 0 ;
+    for ( col = 10 ; col < 25 ; col++ )
+    {
+        n = 0 ;
+        for ( i = 0 ; i < k ; i++ )
+        {
+            if (par[i]->column == col && par[i]->fit_par[2] != 0. && 
+                par[i]->fit_par[1] > 1. && par[i]->fit_par[1] < 7. )
+            {
+                foundit[n] = i ;
+                n++ ;
+            }
+        }
+        if ( n == 0 ) continue ;
+
+        shift = 0 ;
+        z = 0 ;
+        for ( j = 0 ; j < n ; j++ )
+        {
+            position = par[foundit[j]]->fit_par[2] ; 
+            lambda   = par[foundit[j]]->wavelength ;
+            line     = par[foundit[j]]->line ;
+            if (line > 0 && line < n_lines-1)
+            {
+                if (fabs((wave_cor[line] - wave_cor[line-1]) / 
+                          dispersion ) < 2*width ||
+                    fabs((wave_cor[line] - wave_cor[line+1]) / 
+                          dispersion ) < 2*width )
+                {
+                    continue ;
+                }
+            }
+            wave = 0 ;
+            for ( i = 0 ; i < n_fitcoeffs ; i++ ) 
+            {
+                wave += coeffs[i][col]*pow(position-offset, i) ;
+            }
+            shift += lambda - wave ;
+            z++ ;
+        }
+        shift_col[c] = shift/(float)z ; 
+        c++ ;
+    }
+    if ( c > 0 )
+    {
+        wave_shift = sinfo_new_clean_mean(shift_col, c, 10., 10.) ;
+        sinfo_msg("overall positioning error in microns: %g", wave_shift) ;
+    }
+
+    /* determine positioning error for each found line */
+    for ( line = 0 ; line < n_lines ; line++ )
+    {
+        if (line > 0 && line < n_lines-1)
+        {
+            if (fabs((wave_cor[line] - wave_cor[line-1]) / dispersion ) < 
+                                         2*width ||
+                fabs((wave_cor[line] - wave_cor[line+1]) / dispersion ) < 
+                                         2*width )
+            {
+                continue ;
+            }
+        }
+
+        c = 0 ;
+        for ( col = 10 ; col < 25 ; col++ )
+        {
+            shift_col[c] = 0. ;
+            found = -1 ;
+            for ( i = 0 ; i < k ; i++ )
+            {
+                if (par[i]->column == col && par[i]->fit_par[2] != 0. && 
+                    par[i]->fit_par[1] > 1. && par[i]->fit_par[1] < 7. && 
+                    par[i]->line == line )
+                {
+                    found = i ;
+                }
+            }
+            if (found == -1) break ;
+
+            position = par[found]->fit_par[2] ; 
+            lambda  = par[found]->wavelength ;
+            wave = 0 ;
+            for ( i = 0 ; i < n_fitcoeffs ; i++ ) 
+            {
+                wave += coeffs[i][col]*pow(position-offset, i) ;
+            }
+            shift_col[c] = lambda - wave ;
+            c++ ;
+        }
+        if (found != -1 && c > 0 )
+        {
+            sinfo_msg("shift in microns: %g at wavelength: %f\n", 
+            sinfo_new_clean_mean(shift_col, c, 20., 20.), lambda) ;
+        }
+    }
+
+
+
+    cpl_free(foundit) ;
+    cpl_free(shift_col) ;
+    cpl_free(wave_cor) ;
+    cpl_free(a) ;
+    cpl_free(zroot) ;
+
+    return wave_shift ;
+}
+
+
+
+/**
+ at brief Fits each single polynomial coefficient acoefs resulting from polyfit 
+       across the columns of each slitlet and use the result of this fit to 
+       smooth the acoefs.
+ at name sinfo_new_coeffs_cross_slit_fit()
+ at param n_columns:    number of image columns
+ at param acoefs:       coeffs fitted in sinfo_polyfit
+ at note: this is a sinfo_matrix of the polynomial
+       coefficients, each loc_index for each column:
+       acoefs[loc_index][column]
+ at param dacoefs:      fit errors of the corresponding acoefs
+ at param bco:          the fitted Bcoeffs data structure for each slitlet
+ at param sigma_factor: factor of sigma beyond which the
+                     column coefficients are discarded for the fit
+ at param dispersion:   estimate of the dispersion
+ at param pixel_dist:   estimate of minimal pixel distance in spectral direction 
+                     between slitlets
+ at return 
+           # 0 if all went o.k
+           # -1 if an error occurred
+           # the found fit coefficients bco data structure to calculate
+           # the smoothed acoefs
+           # chisq:        list of the chi squared of each fit for each slitlet
+ */
+ static int   
+sinfo_new_spred_coeffs_cross_slit_fit ( int      n_columns,
+                            float ** acoefs,
+                            float ** dacoefs,
+                            Bcoeffs* bco,
+                            float    sigma_factor,
+                            float    dispersion,
+                            float    pixel_dist,
+                            float  * chisq,
+                          float ** sinfo_slit_pos )
+ {
+     float col_index;
+
+
+     float ** ucoefs, **vcoefs, **covar ;
+     float * acoefsclean ;
+     double sum, sumq, mean ;
+     double sigma ;
+     double cliphi, cliplo ;
+     float offset ;
+     float threshold ;
+
+     int* edge=NULL ;
+     float* sub_col_index=NULL ;
+     float* sub_acoefs=NULL;
+     float* sub_dacoefs=NULL ;
+     float* wcoefs=NULL ;
+
+
+     int ed1, ed2 ;
+     int i, n, num, ndata ;
+     int nc, ns ;
+     int loc_index ;
+     int sl_index;
+     int last_i=PIXEL;
+ 
+     if ( n_columns < 1 )
+     {
+         sinfo_msg_error(" wrong number of image columns given\n") ;
+         return -1 ;
+     }
+     if ( acoefs == NULL || dacoefs == NULL )
+     {
+         sinfo_msg_error(" acoeffs or errors of coefficients are not given") ;
+         return -1 ;
+     }
+     if ( bco == NULL )
+     {
+         sinfo_msg_error(" bcoeffs are not allocated\n") ;
+         return -1 ;
+     }
+     if ( sigma_factor <= 0. )
+     {
+         sinfo_msg_error(" impossible sigma_factor given!\n") ;
+         return -1 ;
+     }
+     if ( dispersion == 0. )
+     {
+         sinfo_msg_error(" impossible dispersion given!\n") ;
+         return -1 ;
+     }
+
+
+     edge=cpl_calloc(bco->n_slitlets,sizeof(int)) ;
+     sub_col_index=cpl_calloc(n_columns,sizeof(float)) ;
+     sub_acoefs=cpl_calloc(n_columns,sizeof(float));
+     sub_dacoefs=cpl_calloc(n_columns,sizeof(float)) ;
+
+     wcoefs=cpl_calloc(bco->n_bcoeffs,sizeof(float)) ;
+
+     /*------------------------------------------------------------------------
+      * search for the slitlet edges by comparing the a0 coefficients along i
+      * the columns
+      * if a bigger deviation occurrs it is assumed that there is an edge.
+      */
+     n = 0 ;
+     threshold = pixel_dist * fabs(dispersion) ;
+     sinfo_slit_pos[0][0]=0 ;
+     sl_index  = 0;
+     /* it was for ( i = PIXEL ; i  < n_columns - PIXEL ; ) */
+     for ( i = 0 ; i  < n_columns - PIXEL ; )
+     {
+         if ( !isnan(acoefs[0][i+1]) && 
+                     acoefs[0][i+1] != 0. && 
+                     acoefs[0][i] != 0.
+                   && dacoefs[0][i+1] != 0.)
+         {
+             if ( isnan(acoefs[0][i]) || acoefs[0][i] == 0. )
+             {
+                 if (fabs(acoefs[0][i+1] - acoefs[0][i-1]) >= threshold )
+             {
+             /* printf("case a pos1 %d pos2 %d \n",i,i+1); */
+                     edge[n] = i+1 ;
+             sinfo_slit_pos[sl_index][1] = i ;
+             sinfo_slit_pos[sl_index+1][0] = i + 1 ;
+             sl_index++;
+                     n++ ;
+             last_i = i;
+                     i += PIXEL ;
+                 }
+             }
+             else
+             {
+                 if (fabs(acoefs[0][i+1] - acoefs[0][i]) >= threshold )
+             {
+             /* printf("case b pos1 %d pos2 %d \n",i,i+1); */
+                     edge[n] = i+1 ;
+             sinfo_slit_pos[sl_index][1] = i ;
+             sinfo_slit_pos[sl_index+1][0] = i + 1 ;
+             sl_index++;
+                     n++ ;
+             last_i = i;
+                     i += PIXEL ;
+                 }
+             }
+
+
+            /* sometimes a slitlet may be lost due to divergences in 
+                acoeffs[0] we try to recover it */
+             if( ( (i-last_i) > 63 ) && 
+                ( isnan(fabs(acoefs[0][i+1] - acoefs[0][i])) ||
+                  isnan(fabs(acoefs[0][i+1] - acoefs[0][i-1])) ) ) 
+         {
+                     edge[n] = i+1 ;
+                     sinfo_slit_pos[sl_index][1] = i ;
+                     sinfo_slit_pos[sl_index+1][0] = i + 1 ;
+                     sl_index++;
+                     n++ ;
+
+                     last_i = i;
+                     sinfo_msg_warning("2 recovered slitlet edge i=%d",i);
+                     i += PIXEL ;
+
+         }
+         }
+         i++ ;
+     }
+     sinfo_slit_pos[sl_index][1]  = 2047;
+     /* printf("2 Found n slitlest: %d check %d\n", n,bco->n_slitlets - 1); */
+     if ( n != bco->n_slitlets - 1 )
+     {
+         sinfo_msg_error("could not find the right number of "
+                         "slitlets, found: %d\n",n+1) ;
+         return -1 ;
+     }
+
+     /* go through the coefficents indices */
+     for ( loc_index = 0 ; loc_index < bco->n_acoeffs ; loc_index++ )
+     {
+         /* go through the single slitlets */
+         for ( ns = 0 ; ns < bco->n_slitlets ; ns++ )
+         {
+             /* determine the slitlet edges */
+             if ( ns == 0 )
+             {
+                 ed1 = 0 ;
+                 ed2 = edge[0] ;
+             }
+             else if ( ns == bco->n_slitlets - 1 )
+             {
+                 ed1 = edge[bco->n_slitlets - 2] ;
+                 ed2 = n_columns ;
+             }
+             else
+             {
+                 ed1 = edge[ns-1] ;
+                 ed2 = edge[ns] ;
+             }
+
+             nc = 0 ;
+             for ( i = ed1 ; i < ed2 ; i++ )
+             {
+                 if ( isnan(acoefs[loc_index][i]) || 
+                            acoefs[loc_index][i] == 0. || 
+                           dacoefs[loc_index][i] == 0. )
+                 {
+                     continue ;
+                 }
+                 else
+                 {
+                     nc++ ;
+                 }
+             }
+             if (NULL==(acoefsclean=(float*) cpl_calloc(nc , sizeof(float))) )
+             {
+                 sinfo_msg_error("could not allocate memory for acoefsclean!");
+                 return -1 ;
+             }
+             nc = 0 ;
+             for ( i = ed1 ; i  < ed2 ; i++ )
+            {
+                if ( isnan(acoefs[loc_index][i]) || 
+                           acoefs[loc_index][i] == 0. || 
+                          dacoefs[loc_index][i] == 0. )
+                {
+                    continue ;
+                }
+                else
+                {
+                    acoefsclean[nc] = acoefs[loc_index][i] ;
+                    nc++ ;
+                }
+            }
+
+            /* ----------------------------------------------------------
+             * determine the clean mean and sigma value of the coefficients,
+             * that means reject 10 % of the extreme low and high values
+             */
+            sinfo_pixel_qsort(acoefsclean, nc) ;
+
+            sum   = 0. ;
+            sumq  = 0. ;
+            mean  = 0. ;
+            sigma = 0. ;
+            n     = 0 ;
+            for ( i = (int)((float)nc*LOW_REJECT) ; 
+                  i < (int)((float)nc*HIGH_REJECT) ; i++ )
+            {
+                sum  += (double)acoefsclean[i] ;
+                sumq += ((double)acoefsclean[i] * (double)acoefsclean[i]) ;
+                n ++ ;
+            }
+            mean          = sum/(double)n ;
+            sigma         = sqrt( sumq/(double)n - (mean * mean) ) ;
+            cliphi        = mean + sigma * (double)sigma_factor ;
+            cliplo        = mean - sigma * (double)sigma_factor ;
+            /* fit only the reasonnable values */
+            num = 0 ;
+            col_index = 0 ;
+            for ( i = ed1 ; i < ed2 ; i++ )
+            {
+                /* take only the reasonnable coefficients */
+                if ( !isnan(acoefs[loc_index][i]) && 
+                           (acoefs[loc_index][i] <= cliphi) && 
+                           (acoefs[loc_index][i] >= cliplo) &&
+                     (dacoefs[loc_index][i] != 0. ) && 
+		     (acoefs[loc_index][i] != 0.) )
+                {
+                    sub_acoefs[num]    = acoefs[loc_index][i] ;
+                    sub_dacoefs[num]   = dacoefs[loc_index][i] ;
+                    sub_col_index[num] = col_index ;
+                    num ++ ;
+                }
+                col_index++ ;
+            }
+            ndata = num ;
+            offset = (float)(col_index-1) / 2. ;
+
+            if ( ndata < bco->n_bcoeffs )
+            {
+                sinfo_msg_error(" not enough data found in slitlet %da"
+                                " to determine the fit coefficients.\n", ns) ;
+                cpl_free(acoefsclean) ;
+                return -1 ;
+            }
+
+            /* allocate coefficient matrices */
+            ucoefs = sinfo_matrix(1, ndata, 1, bco->n_bcoeffs) ;
+            vcoefs = sinfo_matrix(1, ndata, 1, bco->n_bcoeffs) ;
+            covar  = sinfo_matrix(1, bco->n_bcoeffs, 1, bco->n_bcoeffs) ;
+
+            /* scale the x-values for the fit */
+            for ( i = 0 ; i < ndata ; i++ )
+            {
+                sub_col_index[i] = (sub_col_index[i] - offset) / offset ;
+            }
+
+            /* finally, do the singular value decomposition fit */
+            sinfo_svd_fitting ( sub_col_index-1, sub_acoefs-1, 
+                                sub_dacoefs-1, ndata, bco[ns].b[loc_index]-1,
+                                bco->n_bcoeffs, ucoefs, vcoefs, wcoefs-1, 
+                                covar, &chisq[ns], sinfo_fpol ) ;
+
+            /* scale the found coefficients */
+            for ( i = 0 ; i < bco->n_bcoeffs ; i ++ )
+            {
+                bco[ns].b[loc_index][i] /= pow( offset, i ) ;
+            }
+
+            /* free memory */
+            cpl_free (acoefsclean) ;
+            sinfo_free_matrix( ucoefs, 1/*, ndata*/, 1/*, bco->n_bcoeffs */) ;
+            sinfo_free_matrix( vcoefs, 1/*, ndata*/, 1/*, bco->n_bcoeffs */) ;
+            sinfo_free_matrix( covar, 1/*, bco->n_bcoeffs*/, 
+                               1/*, bco->n_bcoeffs */) ;
+
+            /* now calculate the smoothed acoefs for each column */
+            col_index = 0 ;
+            for ( i = ed1 ; i < ed2  ; i++ )
+            {
+                acoefs[loc_index][i] = 0. ;
+                for ( n = 0 ; n < bco->n_bcoeffs ; n++ )
+                {
+                    acoefs[loc_index][i] += bco[ns].b[loc_index][n] * 
+                                        pow(col_index - offset, n) ;
+                }
+                col_index++ ;
+            }
+
+        }
+    }
+
+
+    cpl_free(edge) ;
+    cpl_free(sub_col_index) ;
+    cpl_free(sub_acoefs);
+    cpl_free(sub_dacoefs) ;
+    cpl_free(wcoefs) ;
+
+    return 0 ;
+}
+
+
+/**
+ at brief takes an image from a calibration emission lamp and delivers the 
+       smoothed fit coefficients of a polynomial fit along the columns of 
+       the line positions as output.
+ at name  sinfo_new_spred_wave_cal()
+ at param image:        merged image from a calibration emission lamp,
+ at param par:          fit parameters data structure storage
+ at param abuf:         buffer array for fit coefficients abuf[index][column]
+ at param row_clean:    resulting list of the row indices but without the lines 
+                     that are too close to 
+                     each other for the fit output of sinfo_findLines()
+ at param wavelength_clean: corrected wavelength list corresponding to the 
+                         row_clean array
+                         output of sinfo_findLines()
+ at param n_found_lines: output of sinfo_findLines(): total number of found 
+                      emission lines
+ at param dispersion:   dispersion of spectrum: micron per pixel
+ at param halfWidth:    half width of the box where the line must sit
+ at param minAmplitude: minimum amplitude of the Gaussian to do the fit
+ at param max_residual: maximum residual value, beyond that value
+                     the polynomial lambda-position fit is rejected.
+ at param fwhm:         first guess for the full width of half maximum
+                     of the sinfo_gaussian line fit
+ at param n_a_fitcoefs: number of fit coefficients for the single
+                     column fits: lambda-position
+ at param n_b_fitcoefs: number of fit coefficients for the fits of
+                     the single a coefficients across the columns
+ at param sigmaFactor:  factor of the standard deviation of the determined
+                     polynomial coefficients of the columns beyond
+                     which these coefficients are not used to carry out
+                     the polynomial fit across the columns.
+ at param pixel_dist:   estimate of minimal pixel distance in spectral direction 
+                     between slitlets
+ at param pixel_tolerance: maximum tolerated difference between estimated and 
+                        fitted line positions.
+ at return # wavelength map image
+        # abuf: array of smoothed coefficients of the polynomial fit along 
+                the columns:
+                              abuf[index][column].
+        # par: array of the resulting FitParams data structure
+ at doc this routine takes an image from a calibration emission lamp and 
+     delivers the smoothed fit coefficients of a polynomial fit along the 
+     columns of the line positions as output.
+     This routine expects Nyquist sampled spectra (either an interleaved 
+     image or an image 
+     convolved with an appropriate function in spectral direction)
+*/
+
+cpl_image * sinfo_new_spred_wave_cal( cpl_image   * image,
+                    FitParams ** par ,
+                    float     ** abuf,
+                    int          n_slitlets,
+                    int       ** row_clean,
+                    float     ** wavelength_clean,
+                    int        * n_found_lines,
+                    float        dispersion,
+                    int          halfWidth,
+                    float        minAmplitude,
+                    float        max_residual,
+                    float        fwhm,
+                    int          n_a_fitcoefs,
+                    int          n_b_fitcoefs,
+                    float        sigmaFactor,
+                    float        pixel_dist,
+                    float        pixel_tolerance,
+                  float ** sinfo_slit_pos)
+
+
+{
+    int          i, j, k ;
+    int          n_fit ;
+    int          n_reject ;
+    float     *  acoefs ;
+    float     *  dacoefs ;
+    float     ** dabuf ;
+    float        chisq_poly ;
+    float     *  chisq_cross ;
+    int          zeroind ;
+    int          crossInd ;
+    Bcoeffs   *  bco ;
+    cpl_image  *  wavemap ;
+    int ilx=0;
+    int ily=0;
+    float* pidata=NULL;
+
+
+    if (  NULL == image )
+    {
+        sinfo_msg_error(" no image given\n") ;
+        return NULL ;
+    }
+    ilx=cpl_image_get_size_x(image);
+    ily=cpl_image_get_size_y(image);
+    pidata=cpl_image_get_data_float(image);
+
+    if ( par == NULL )
+    {
+        sinfo_msg_error(" no fit parameter data structure given\n") ;
+        return NULL ;
+    }
+    if ( abuf == NULL )
+    {
+        sinfo_msg_error(" no buffer for fit coefficients given\n") ;
+        return NULL ;
+    }
+    if ( n_slitlets <= 0 )
+    {
+        sinfo_msg_error(" impossible number of slitlets given\n") ;
+        return NULL ;
+    }
+    if ( row_clean == NULL )
+    {
+        sinfo_msg_error(" no row_clean array given\n") ;
+        return NULL ;
+    }
+    if ( wavelength_clean == NULL )
+    {
+        sinfo_msg_error(" no wavelength_clean array given\n") ;
+        return NULL ;
+    }
+
+    if ( dispersion == 0. )
+    {
+        sinfo_msg_error(" impossible dispersion given\n") ;
+        return NULL ;
+    }
+
+    if ( halfWidth <= 0 || halfWidth > ily/2 )
+    {
+        sinfo_msg_error(" impossible half width of the fitting box given\n") ;
+        return NULL ;
+    }
+    if ( minAmplitude < 1. )
+     {
+         sinfo_msg_error(" impossible minimal amplitude\n") ;
+         return NULL ;
+     }
+
+     if ( max_residual <= 0. || max_residual > 1. )
+     {
+         sinfo_msg_error(" impossible max_residual given\n") ;
+         return NULL ;
+     }
+     if ( fwhm <= 0. || fwhm > 10. )
+     {
+         sinfo_msg_error(" impossible fwhm given\n") ;
+         return NULL ;
+     }
+
+     if ( n_a_fitcoefs <= 0 || n_a_fitcoefs > 9 )
+     {
+         sinfo_msg_error(" unrealistic n_a_fitcoefs given\n") ;
+         return NULL ;
+     }
+
+     if ( n_b_fitcoefs <= 0 || n_b_fitcoefs > 9 )
+     {
+         sinfo_msg_error(" unrealistic n_b_fitcoefs given\n") ;
+         return NULL ;
+     }
+     if ( sigmaFactor <= 0. )
+     {
+         sinfo_msg_error(" impossible sigmaFactor given\n") ;
+         return NULL ;
+     }
+
+     /* initialize the variables */
+     n_reject = 0 ;
+     n_fit = 0 ;
+
+     /* fit each found line by using a sinfo_gaussian function and 
+        determine the exact position */
+     if ( 0 > (n_fit = sinfo_new_fit_lines( image , par, fwhm, n_found_lines, 
+                                      row_clean, wavelength_clean,
+                                      halfWidth, minAmplitude )) )
+     {
+         sinfo_msg_error(" cannot fit the lines, error code of "
+                         "sinfo_fitLines: %d", n_fit) ;
+         return NULL ;
+     }
+
+     /* first check for faked lines like bad pixels */
+     if ( -1 == sinfo_new_check_for_fake_lines (par, 
+                                                dispersion, 
+                                                wavelength_clean, 
+                                                row_clean, 
+                                                n_found_lines,
+                                                ilx, 
+                                                pixel_tolerance) )
+     {
+         sinfo_msg_error(" cannot fit the lines, error code of "
+                         " sinfo_fitLines: %d\n", n_fit) ;
+         return NULL ;
+     }
+
+
+     /* allocate memory */
+     if (NULL==(acoefs = (float*) cpl_calloc (n_a_fitcoefs, sizeof(float))) ||
+         NULL==(dacoefs = (float*) cpl_calloc (n_a_fitcoefs, sizeof(float))) ||
+         NULL==(dabuf = (float**) cpl_calloc (n_a_fitcoefs, sizeof(float*))) ||
+         NULL==(chisq_cross = (float*) cpl_calloc(n_slitlets, sizeof(float))) )
+     {
+         sinfo_msg_error(" cannot allocate memory\n") ;
+         return NULL ;
+     }
+     for ( i = 0 ; i < n_a_fitcoefs ; i++ )
+     {
+         if (  NULL == (dabuf[i] = (float*) cpl_calloc(ilx, sizeof(float))) )
+         {
+             sinfo_msg_error(" cannot allocate memory\n") ;
+             cpl_free ( acoefs ) ;
+             cpl_free ( dacoefs ) ;
+             cpl_free ( chisq_cross ) ;
+             cpl_free(dabuf) ;
+             return NULL ;
+         }
+     }
+
+     /* fit wavelengths to the corresponding found positions for each column */
+     k = 0 ;
+     for ( i = 0 ; i < ilx ; i++ )
+     {
+         zeroind = 0 ;
+         if ( FLT_MAX == (chisq_poly = sinfo_new_polyfit( par, i, 
+                                                         n_found_lines[i], 
+                                                         ily, dispersion,
+                                                         max_residual, acoefs,
+                                                         dacoefs, &n_reject, 
+                                                         n_a_fitcoefs)) )
+         {
+             sinfo_msg_warning (" error in sinfo_polyfit in column: %d\n", i) ;
+             for ( j = 0 ; j < n_a_fitcoefs ; j++ )
+             {
+                 acoefs[j] = ZERO ;
+                 dacoefs[j] = ZERO ;
+             }
+         }
+
+         for ( j = 0 ; j < n_a_fitcoefs ; j++ )
+         {
+
+             if ( acoefs[0] <= 0. || acoefs[1] ==0. ||
+                  dacoefs[j] == 0. || isnan(acoefs[j]) )
+             {
+                 zeroind = 1 ;
+             }
+         }
+         for ( j = 0 ; j < n_a_fitcoefs ; j++ )
+         {
+             if ( zeroind == 0 )
+             {
+                 abuf[j][i]  = acoefs[j] ;
+                 dabuf[j][i] = dacoefs[j] ;
+             }
+             else
+             {
+                 abuf[j][i]  = ZERO ;
+                 dabuf[j][i] = ZERO ;
+             }
+         }
+     }
+
+     /* allocate memory for the fitting coefficients */
+     if ( NULL == ( bco = sinfo_new_b_coeffs( n_slitlets, 
+                                              n_a_fitcoefs, n_b_fitcoefs)) )
+     {
+         sinfo_msg_error (" cannot allocate memory for the bcoeffs\n") ;
+         for ( i = 0 ; i < n_a_fitcoefs ; i++ )
+         {
+             cpl_free (dabuf[i]) ;
+         }
+         cpl_free (dabuf) ;
+         cpl_free ( acoefs ) ;
+         cpl_free ( dacoefs ) ;
+         cpl_free ( chisq_cross ) ;
+         return NULL ;
+     }
+
+     /* fit each acoefs across the slitlets to smooth the result */
+     if ( -1 == ( crossInd = sinfo_new_spred_coeffs_cross_slit_fit( ilx, abuf, 
+                                                                    dabuf,
+                                                             bco, sigmaFactor,
+                                                             dispersion, 
+                                                             pixel_dist, 
+                                                             chisq_cross,
+                                                             sinfo_slit_pos )) )
+     {
+         sinfo_msg_error (" cannot carry out the fitting of "
+                          "coefficients across the columns\n") ;
+         for ( i = 0 ; i < n_a_fitcoefs ; i++ )
+         {
+             cpl_free (dabuf[i]) ;
+         }
+
+         cpl_free (dabuf) ;
+         cpl_free ( acoefs ) ;
+         cpl_free ( dacoefs ) ;
+         sinfo_new_destroy_b_coeffs(bco) ;
+         cpl_free ( chisq_cross ) ;
+         return NULL ;
+     }
+
+     if ( NULL == (wavemap = sinfo_new_wave_map_slit (abuf, n_a_fitcoefs, 
+                                                      ily, ilx)))
+     {
+         sinfo_msg_error (" cannot carry out wavemap creation\n") ;
+         for ( i = 0 ; i < n_a_fitcoefs ; i++ )
+         {
+             cpl_free (dabuf[i]) ;
+         }
+
+         cpl_free (dabuf) ;
+         cpl_free ( acoefs ) ;
+         cpl_free ( dacoefs ) ;
+         sinfo_new_destroy_b_coeffs(bco) ;
+         cpl_free ( chisq_cross ) ;
+         return NULL ;
+     }
+
+     /* free all allocated memory */
+     for ( i = 0 ; i < n_a_fitcoefs ; i++ )
+     {
+         cpl_free (dabuf[i]) ;
+     }
+     cpl_free (dabuf) ;
+     cpl_free ( acoefs ) ;
+     cpl_free ( dacoefs ) ;
+     sinfo_new_destroy_b_coeffs(bco) ;
+     cpl_free ( chisq_cross ) ;
+
+     return wavemap ;
+ }
+
+/**@}*/
+/*___oOo___*/
diff --git a/sinfoni/sinfo_wavecal.h b/sinfoni/sinfo_wavecal.h
new file mode 100644
index 0000000..2693217
--- /dev/null
+++ b/sinfoni/sinfo_wavecal.h
@@ -0,0 +1,375 @@
+#ifndef SINFO_WAVECAL_H
+#define SINFO_WAVECAL_H
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/************************************************************************
+* E.S.O. - VLT project
+*
+* "@(#) $Id: sinfo_wavecal.h,v 1.5 2007/06/06 07:10:46 amodigli Exp $"
+*
+* who       when      what
+* --------  --------  ----------------------------------------------
+* schreib  13/07/00  created
+*/
+
+/************************************************************************
+ * sinfo_wavecal.h
+ * routines needed for wavelength calibration
+ *----------------------------------------------------------------------
+ */
+
+/*
+ * header files
+ */
+#include <cpl.h>
+#include "sinfo_spectrum_ops.h"
+
+/*
+ * function prototypes
+ */
+
+/**
+   @name    sinfo_new_wave_map_slit()
+   @param   acoefs fit coefficient sinfo_matrix: output of 
+            sinfo_coeffsCrossSlitFit()
+   @param  n_acoefs number of acoefs, polynomial order + 1
+   @param  n_rows number of final image rows
+   @param  n_columns number of final image columns
+   @return wavemap calibration map image
+*/
+
+cpl_image * 
+sinfo_new_wave_map_slit ( float ** acoefs,
+                         int      n_acoefs,
+                         int      n_rows,
+                         int      n_columns ) ;
+
+/**
+   @name       sinfo_new_wave_cal()
+   @param      par array of the resulting FitParams data structure
+   @param      abuf array of smoothed coefficients of the polynomial fit 
+               along the columns abuf[index][column].
+   @param      image        merged image from a calibration emission lamp,
+   @param      par          fit parameters data structure storage
+   @param      abuf         buffer array for fit coefficients 
+                            abuf[index][column]
+   @param      row_clean resulting list of the row indices but without the
+                         lines that are too close to each other for the fit
+                         output of sinfo_findLines()
+   @param      wavelength_clean corrected wavelength list corresponding to
+                                the row_clean array
+                                output of sinfo_findLines()
+   @param      n_found_lines output of sinfo_findLines(): 
+                             total number of found emission lines
+   @param      dispersion   dispersion of spectrum: micron per pixel
+   @param      halfWidth    half width of the box where the line must sit
+   @param      minAmplitude minimum amplitude of the Gaussian to do the fit
+   @param      max_residual maximum residual value, beyond that value
+                            the polynomial lambda-position fit is rejected.
+   @param      fwhm         first guess for the full width of half maximum
+                            of the sinfo_gaussian line fit
+   @param      n_a_fitcoefs number of fit coefficients for the single
+                            column fits: lambda-position
+   @param      n_b_fitcoefs number of fit coefficients for the fits of
+                            the single a coefficients across the columns
+   @param      sigmaFactor  factor of the standard deviation of the determined
+                            polynomial coefficients of the columns beyond
+                            which these coefficients are not used to carry out
+                            the polynomial fit across the columns.
+   @param      pixel_dist   estimate of minimal pixel distance in spectral 
+                            direction between slitlets
+   @param      pixel_tolerance maximum tolerated difference between estimated
+                   and fitted line positions.
+   @return     wavelength map image.
+   @doc   this routine takes an image from a calibration emission lamp and 
+          delivers the smoothed fit coefficients of a polynomial fit along 
+          the columns of the line positions as output. This routine expects 
+          Nyquist sampled spectra (either an interleaved image or an image 
+          convolved with an appropriate function in spectral direction)
+*/
+
+cpl_image * 
+sinfo_new_wave_cal(cpl_image   * image,
+                    FitParams ** par ,
+                    float     ** abuf,
+                    int          n_slitlets,
+                    int       ** row_clean,
+                    float     ** wavelength_clean,
+                    int        * n_found_lines,
+                    float        dispersion,
+                    int          halfWidth,
+                    float        minAmplitude,
+                    float        max_residual,
+                    float        fwhm,
+                    int          n_a_fitcoefs,
+                    int          n_b_fitcoefs,
+                    float        sigmaFactor,
+                    float        pixel_dist,
+            float        pixel_tolerance ) ;
+
+
+/**
+   @name       sinfo_new_spred_wave_cal()
+   @param      par array of the resulting FitParams data structure
+   @param      abuf array of smoothed coefficients of the polynomial fit 
+               along the columns abuf[index][column].
+   @param      image        merged image from a calibration emission lamp,
+   @param      par          fit parameters data structure storage
+   @param      abuf         buffer array for fit coefficients 
+                            abuf[index][column]
+   @param      row_clean resulting list of the row indices but without the
+                         lines that are too close to each other for the fit
+                         output of sinfo_findLines()
+   @param      wavelength_clean corrected wavelength list corresponding to
+                                the row_clean array
+                                output of sinfo_findLines()
+   @param      n_found_lines output of sinfo_findLines(): 
+                             total number of found emission lines
+   @param      dispersion   dispersion of spectrum: micron per pixel
+   @param      halfWidth    half width of the box where the line must sit
+   @param      minAmplitude minimum amplitude of the Gaussian to do the fit
+   @param      max_residual maximum residual value, beyond that value
+                            the polynomial lambda-position fit is rejected.
+   @param      fwhm         first guess for the full width of half maximum
+                            of the sinfo_gaussian line fit
+   @param      n_a_fitcoefs number of fit coefficients for the single
+                            column fits: lambda-position
+   @param      n_b_fitcoefs number of fit coefficients for the fits of
+                            the single a coefficients across the columns
+   @param      sigmaFactor  factor of the standard deviation of the determined
+                            polynomial coefficients of the columns beyond
+                            which these coefficients are not used to carry out
+                            the polynomial fit across the columns.
+   @param      pixel_dist   estimate of minimal pixel distance in 
+                            spectral direction between slitlets
+   @param      pixel_tolerance maximum tolerated difference between estimated
+                   and fitted line positions.
+   @return     wavelength map image.
+   @doc   this routine takes an image from a calibration emission lamp and 
+          delivers the smoothed fit coefficients of a polynomial fit along 
+          the columns of the line positions as output. This routine expects 
+          Nyquist sampled spectra (either an interleaved image or an image 
+          convolved with an appropriate function in spectral direction)
+*/
+ cpl_image * sinfo_new_spred_wave_cal(cpl_image   * image,
+                     FitParams ** par ,
+                     float     ** abuf,
+                     int          n_slitlets,
+                     int       ** row_clean,
+                     float     ** wavelength_clean,
+                     int        * n_found_lines,
+                     float        dispersion,
+                     int          halfWidth,
+                     float        minAmplitude,
+                     float        max_residual,
+                     float        fwhm,
+                     int          n_a_fitcoefs,
+                     int          n_b_fitcoefs,
+                     float        sigmaFactor,
+                     float        pixel_dist,
+                     float        pixel_tolerance,
+                     float **sinfo_slit_pos ) ;
+
+
+/**
+   @name   sinfo_new_check_for_fake_lines()
+   @param  par array of the fit parameter data structure FitParams
+   @param  dispersion estimated dispersion
+   @param  wavelength_clean: corrected wavelength list
+   @param  row_clean corrected row list corresponding to the wavelength list
+   @param  n_found_lines array of numbers of found lines of each column
+   @param  n_columns total number of image columns
+   @param  pixel_tolerance maximum tolerated difference between estimated
+               and fitted line positions.
+   @return par corrected FitParams 0 in case of success -1 in case of error
+   @doc this routine searches for successfully fitted fake lines like
+    bad pixels by comparing the found line positons with estimated 
+        template positions. This routine should be inserted in the wavelength 
+        calibration routine just after the sinfo_fitLines() routine.
+*/
+
+int 
+sinfo_new_check_for_fake_lines ( FitParams ** par,
+                       float        dispersion,
+                        float     ** wavelength_clean,
+            int       ** row_clean,
+            int        * n_found_lines,
+            int          n_columns,
+            float        pixel_tolerance ) ;
+
+
+/**
+   @name   sinfo_new_create_shifted_slit_wavemap()
+   @param  lineIm  new shifted emission line frame
+   @param  coeffs  calculated polynomial coefficients,
+                   output of sinfo_coeffsCrossSlitFit()
+   @param  n_fitcoeffs  number of polynomial coefficients, order + 1
+   @param  wavelength   wavelength list from line list
+   @param  intensity    corresponding line intensity from line list
+   @param  n_lines      number of lines in the list
+   @param  magFactor    magnification factor for help arrays
+   @return wavelength map
+   @doc This routine cross-correlates a shifted emission line frames
+        and determines the shift to the old one which is given by
+        its polynomial coefficients. Then the a0 coefficients is recalculated 
+        and afterwards a new wavelength calibration map is generated using the
+        already calculated smoothed polynomial coefficients.
+*/
+
+cpl_image * 
+sinfo_new_create_shifted_slit_wavemap (cpl_image * lineIm,
+                                      float    ** coeffs,
+                                      int      n_fitcoeffs,
+                                      float  * wavelength,
+                                      float  * intensity,
+                                      int      n_lines,
+                                      int      magFactor ) ;
+/**
+   @name  sinfo_new_create_shifted_slit_wavemap2()
+   @param lineIm       new shifted emission line frame
+   @param coeffs       calculated polynomial coefficients,
+                       output of sinfo_coeffsCrossSlitFit()
+   @param n_fitcoeffs  number of polynomial coefficients, order + 1
+   @param wavelength   wavelength list from line list
+   @param intensity    corresponding line intensity from line list
+   @param n_lines      number of lines in the list
+   @param magFactor    magnification factor for help arrays
+   @param dispersion   estimate of the dispersion
+   @param pixel_dist   estimate of minimal pixel distance in spectral 
+                       direction between slitlets
+   @return wavelength map
+   @doc This routine cross-correlates a shifted emission line frames
+        and determines the shift to the old one which is given by
+        its polynomial coefficients.
+        Then the a0 coefficients is recalculated and afterwards
+        a new wavelength calibration map is generated using the
+        already calculated smoothed polynomial coefficients.
+*/
+
+
+cpl_image * 
+sinfo_new_create_shifted_slit_wavemap2 (cpl_image * lineIm,
+                                      float    ** coeffs,
+                                      int      n_fitcoeffs,
+                                      float  * wavelength,
+                                      float  * intensity,
+                                      int      n_lines,
+                                      int      magFactor,
+                                      float    dispersion,
+                                      float    pixel_dist ) ;
+
+
+/**
+   @name    sinfo_new_create_shifted_slit_wavemap3()
+   @param   lineIm       new shifted emission line frame
+   @param   coeffs       calculated polynomial coefficients,
+                         output of sinfo_coeffsCrossSlitFit()
+   @param   n_fitcoeffs  number of polynomial coefficients, order + 1
+   @param   wavelength   wavelength list from line list
+   @param   intensity    corresponding line intensity from line list
+   @param   n_lines      number of lines in the list
+   @param   magFactor    magnification factor for help arrays
+   @result  wavelength map
+   @doc     This routine cross-correlates a shifted emission line frames
+            and determines the shift to the old one which is given by
+            its polynomial coefficients.
+            Then the a0 coefficients is recalculated by using a clean mean
+            of the determined offset (shift) over the whole frame
+            and afterwards a new wavelength calibration map is generated using 
+            the already calculated smoothed polynomial coefficients.
+*/
+
+
+cpl_image * 
+sinfo_new_create_shifted_slit_wavemap3 (cpl_image * lineIm,
+                                      float    ** coeffs,
+                                      int      n_fitcoeffs,
+                                      float  * wavelength,
+                                      float  * intensity,
+                                      int      n_lines,
+                                      int      magFactor ) ;
+
+
+/**
+   @name    sinfo_new_check_line_positions()
+   @param   lineIm       new shifted emission line frame
+   @param   coeffs       calculated polynomial coefficients,
+                         output of sinfo_coeffsCrossSlitFit()
+   @param   n_fitcoeffs  number of polynomial coefficients, order + 1
+   @param   guess_disp1  guess dispersion (to have positioning error in pix)
+   @param   par          fit parameters
+   @doc     clean averaged position error (shift) of the brightest lines in 
+            the emission line image with respect to the expected positions 
+            from the wavelength calibration (error in the wavelength regime 
+            (microns)).
+   @doc     This routine determines the clean averaged error (shift) of the 
+            brightest lines in the emission line image with respect to the 
+            expected positions from the wavelength calibration. The error is 
+            given in the wavelength regime (microns).
+            It should give the user an impression for the quality
+            of the wavelength calibration.
+*/
+
+float sinfo_new_check_line_positions ( cpl_image     * lineIm,
+                       float       ** coeffs,
+                       int            n_fitcoeffs,
+                       float           guess_disp1,
+                       FitParams   ** par );
+
+/**
+   @name   sinfo_new_check_correlated_line_positions()
+   @param  lineIm       new shifted emission line frame
+   @param  coeffs       calculated polynomial coefficients,
+                        output of sinfo_coeffsCrossSlitFit()
+   @param  n_fitcoeffs  number of polynomial coefficients, order + 1
+   @param  wavelength   wavelength list from line list
+   @param  intensity    corresponding line intensity from line list
+   @param  n_lines      number of lines in list
+   @param  fwhm         guess value for full width of half maximum of Gaussian
+   @param  width        half width of the box where the line must sit
+   @param  min_amplitude minimum line amplitude with respect to the background
+                         to do the fit
+   @param  par           fit parameters
+   @return clean averaged position error (shift) of the brightest lines in the
+           emission line image with respect to the expected positions from the 
+           wavelength calibration (error in the wavelength regime (microns)).
+   @doc    This routine determines the clean averaged error (shift) of the 
+           brightest lines in the emission line image with respect to the 
+           expected positions from the wavelength calibration. The error is 
+           given in the wavelength regime (microns).
+           It should give the user an impression of the quality
+           of the wavelength calibration.
+*/
+
+float 
+sinfo_new_check_correlated_line_positions (cpl_image     * lineIm,
+                                     float       ** coeffs,
+                                     int            n_fitcoeffs,
+                                     float        * wavelength,
+                                     float        * intensity,
+                                     int            n_lines,
+                                     float          fwhm,
+                                     float          width,
+                                     float          min_amplitude,
+                                     float          dispersion,
+                                     FitParams   ** par ) ;
+
+
+
+#endif /*!SINFO_WAVECAL_H*/
diff --git a/sinfoni/sinfo_wavecal_cfg.c b/sinfoni/sinfo_wavecal_cfg.c
new file mode 100644
index 0000000..dc0820d
--- /dev/null
+++ b/sinfoni/sinfo_wavecal_cfg.c
@@ -0,0 +1,84 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/*---------------------------------------------------------------------------
+   
+   File name     :    sinfo_wavecal_cfg.c
+   Author         : Juergen Schreiber
+   Created on    :    September 2001
+   Description    :    wavelength calibration configuration handling tools
+
+ *--------------------------------------------------------------------------*/
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+/*---------------------------------------------------------------------------
+                                   Includes
+ ---------------------------------------------------------------------------*/
+
+#include "sinfo_wavecal_cfg.h"
+
+/**@{*/
+/**
+ * @addtogroup sinfo_rec_wavecal wavecal structure configuration
+ *
+ * TBD
+ */
+
+/*---------------------------------------------------------------------------
+                              Function codes
+ ---------------------------------------------------------------------------*/
+
+/*---------------------------------------------------------------------------
+   Function :   sinfo_wave_cfg_create()
+   In       :   void
+   Out      :   pointer to allocated base wave_config structure
+   Job      :   allocate memory for a wave_config struct
+   Notice   :   only the main (base) structure is allocated
+ ---------------------------------------------------------------------------*/
+
+wave_config * sinfo_wave_cfg_create(void)
+{
+    return cpl_calloc(1, sizeof(wave_config));
+}
+
+
+/*---------------------------------------------------------------------------
+   Function :   sinfo_wave_cfg_destroy()
+   In       :   wave_config to deallocate
+   Out      :   void
+   Job      :   deallocate all memory associated with a wave_config
+   Notice   :   
+ ---------------------------------------------------------------------------*/
+
+void sinfo_wave_cfg_destroy(wave_config * wc)
+{
+    if (wc==NULL) return ;
+
+    /* Free main struct */
+    cpl_free(wc);
+
+    return ;
+}
+/**@}*/
+
+
+
diff --git a/sinfoni/sinfo_wavecal_cfg.h b/sinfoni/sinfo_wavecal_cfg.h
new file mode 100644
index 0000000..fa651af
--- /dev/null
+++ b/sinfoni/sinfo_wavecal_cfg.h
@@ -0,0 +1,171 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*---------------------------------------------------------------------------
+   
+   File name     :    sinfo_wavecal_cfg.h
+   Author         :    Juergen Schreiber
+   Created on    :    September 2001
+   Description    :    wavecal_ini definitions + handling prototypes
+ ---------------------------------------------------------------------------*/
+#ifndef SINFO_WAVECAL_CFG_H
+#define SINFO_WAVECAL_CFG_H
+/*---------------------------------------------------------------------------
+                                   Includes
+ ---------------------------------------------------------------------------*/
+#include <stdlib.h>
+#include <cpl.h>
+#include "sinfo_globals.h"
+/*---------------------------------------------------------------------------
+                                   Defines
+ ---------------------------------------------------------------------------*/
+/*---------------------------------------------------------------------------
+                                   New types
+ ---------------------------------------------------------------------------*/
+/*
+  Wavelength calibration blackboard container
+
+  This structure holds all information related to the wavelength calibration
+  routine. It is used as a container for the flux of ancillary data,
+  computed values, and algorithm status. Pixel flux is separated from
+  the blackboard.
+  */
+
+typedef struct wave_config {
+/*-------General---------*/
+        char inFrame[FILE_NAME_SZ] ; /* input emission line frame */
+        char lineList[FILE_NAME_SZ] ; /* input wavelength and intensity 
+                                         line list */
+        char outName[FILE_NAME_SZ] ;  /* output name of resulting 
+                                         fits wavelength map */
+        char drs_setup[FILE_NAME_SZ] ; /* DRS setup table */
+
+/*------ FindLines ------*/
+        /* indicates if the dispersion relation is already determined or not */
+        int calibIndicator ;      
+        /* estimated central wavelength of the image */
+        float guessBeginWavelength ;
+        /* estimated linear dispersion of emission line frame */
+        float guessDispersion1 ;
+        /* estimated square dispersion of emission line frame */
+        float guessDispersion2 ;
+        /* minimal difference of mean and sinfo_median column intensity */
+        float mindiff ;
+        /* half width of a box within which the line must sit */
+        int halfWidth ;
+        /* sigma of Gaussian of artificial model spectra */
+        float sigma ; 
+
+/*------ WaveCalib ------*/
+        /* guess value for fwhm of emission lines */ 
+        float fwhm ;
+        /* minimum amplitude of a line to be fitted */
+        float minAmplitude ;
+        /* maximal residual value for a valid fit */
+        float maxResidual ;
+        /* # of polynomial coefficients used for the dispersion relation */
+        int nrDispCoefficients ;
+        /* # of polynomial coefficients used for the fit of 
+             the dispersion coefficients */
+        int nrCoefCoefficients ;
+        /* minimal factor of the standard deviation of the fit coefficients */
+        float sigmaFactor ;
+        /* indicates if the parameterized dispersion relation coefficients 
+       should be written into an ASCII file */
+        int writeCoeffsInd ;
+        /* indicates if the fit parameters should be written 
+           into an ASCII file */
+        int writeParInd ;
+        /* name of the ASCII file containing the fit parameters */
+        char paramsList[FILE_NAME_SZ] ;
+        /* name of the ASCII file containing the coefficients 
+           of the parameterized dispersion relation */
+        char coeffsName[FILE_NAME_SZ] ;
+        /* number of slitlets */
+        int    nslitlets ;
+        /* minimal pixel distance of slitlets in spectral direction */
+        int    pixeldist ;
+        /* allowed pixel position tolerance between estimated 
+           and fitted line position */
+        float  pixel_tolerance  ;
+
+/*------ WaveMap ------*/
+        /* indicator if wavelength map should be generated or not */
+        int wavemapInd ;
+    /* magnifying factor for FFT */
+    int magFactor ;
+
+/*------ FitSlits ------*/
+        /* indicator if the fit of the slit edge positions is carried 
+           through or not */
+        int slitposIndicator ;
+        /* indicator if the fit model function is a Boltzmann 
+           function or not */
+        int fitBoltzIndicator ;
+        /* indicator if the fit model function is a simple edge 
+           function or not */
+        int fitEdgeIndicator ;
+        /* indicator if the fit guess position are user given or 
+           calculated automatically */
+        int estimateIndicator ;
+    /* pixel length of the row box within which the fit of the 
+           slitlet positions is carried out*/
+    int boxLength ;
+        /* lower row position for the estimate fit */
+    int loPos ;
+        /* upper row position for the estimate fit */
+    int hiPos ;
+    /* float box half width in spectral direction */
+        float yBox ;
+        /* maximal tolerable difference to the expected slitlet positions */
+        float diffTol ;
+        /* name of the ASCII file containing the slitlet edge positions */
+        char slitposName[FILE_NAME_SZ] ;
+        /* name of the ASCII file containing the estimated slitlet 
+           edge positions */
+        char slitposGuessName[FILE_NAME_SZ] ;
+
+
+  int qc_thresh_min;
+  int qc_thresh_max;
+
+} wave_config ;
+
+/*---------------------------------------------------------------------------
+                               Function prototypes
+ ---------------------------------------------------------------------------*/
+/**
+   @name    sinfo_wave_cfg_create()
+   @memo    allocate memory for a wave_cfg struct
+   @return  pointer to allocated base wave_cfg structure
+   @note   only the main (base) structure is allocated
+*/
+
+wave_config * 
+sinfo_wave_cfg_create(void);
+/**
+   @name   sinfo_wave_cfg_destroy()
+   @param  wave_config to deallocate
+   @return void
+   @doc    deallocate all memory associated with a wave_config data structure
+*/
+
+void 
+sinfo_wave_cfg_destroy(wave_config * jc);
+
+#endif
diff --git a/sinfoni/sinfo_wavecal_config.c b/sinfoni/sinfo_wavecal_config.c
new file mode 100644
index 0000000..8ffc662
--- /dev/null
+++ b/sinfoni/sinfo_wavecal_config.c
@@ -0,0 +1,428 @@
+/* $Id: sinfo_wavecal_config.c,v 1.6 2012/03/03 10:35:14 amodigli Exp $
+ *
+ * This file is part of the CPL (Common Pipeline Library)
+ * Copyright (C) 2002 European Southern Observatory
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*
+ * $Author: amodigli $
+ * $Date: 2012/03/03 10:35:14 $
+ * $Revision: 1.6 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+ /****************************************************************
+  *   Wavecal Frames Data Reduction Parameter Initialization        *
+  ****************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#include "sinfo_wavecal_config.h"
+/**@{*/  
+/**
+ * @addtogroup sinfo_rec_wavecal wavecal recipe parameters definition \
+      and initialization
+ *
+ * TBD
+ */
+
+
+void
+ sinfo_wavecal_config_add(cpl_parameterlist *list)
+{
+
+  cpl_parameter *p;
+
+  if (!list) {
+    return;
+  }
+
+  p = cpl_parameter_new_value("sinfoni.wavecal.slitpos_boostrap",
+                  CPL_TYPE_BOOL,
+                           "Switch to get a new slitpos without a reference: ",
+                              "sinfoni.wavecal",
+                              FALSE);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"wcal-slitpos_bootstrap");
+  cpl_parameterlist_append(list, p);
+
+  /*
+  p = cpl_parameter_new_value("sinfoni.wavecal.mflat_frm_switch",
+                  CPL_TYPE_BOOL,
+                              "Switch for master lampflat input: ",
+                              "sinfoni.wavecal",
+                              TRUE);
+
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"wcal-mflat_frm_switch");
+  cpl_parameterlist_append(list, p);
+  */
+
+
+/* Find Lines */
+/* indicates if the dispersion relation is already determined or not */
+  p = cpl_parameter_new_value("sinfoni.wavecal.calib_indicator",
+                  CPL_TYPE_BOOL,
+                              "Calib Indicator: "
+                              "FALSE: if the dispersion relation is already "
+                            "known, the routine can jump to the sinfo_waveMap "
+                              "section "
+                              "TRUE: if the dispersion relation "
+                              "must first be determined",
+                              "sinfoni.wavecal",
+                              TRUE);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"wcal-calib_indicator");
+  cpl_parameterlist_append(list, p);
+
+
+/* minimal difference of mean and sinfo_median column intensity */
+  p = cpl_parameter_new_value("sinfoni.wavecal.min_diff",
+                  CPL_TYPE_DOUBLE,
+                              "Minimum Of Difference: "
+                          "minimum difference of mean and sinfo_median column "
+                          "intensity to carry out the cross sinfo_correlation",
+                              "sinfoni.wavecal",
+                              1.);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"wcal-min_diff");
+  cpl_parameterlist_append(list, p);
+
+/* half width of a box within which the line must sit */
+  p = cpl_parameter_new_value("sinfoni.wavecal.half_width",
+                  CPL_TYPE_INT,
+                              "Half Width: "
+                              "half width of a box within which the line "
+                              "must be placed",
+                              "sinfoni.wavecal",
+                              7);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"wcal-hw");
+  cpl_parameterlist_append(list, p);
+
+/* sigma of Gaussian of artificial model spectra */
+  p = cpl_parameter_new_value("sinfoni.wavecal.sigma",
+                  CPL_TYPE_DOUBLE,
+                              "Sigma: sigma of Gaussian which is convolved "
+                              "with the artificial spectrum generated using "
+                              "the line list",
+                              "sinfoni.wavecal",
+                               2.);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"wcal-sigma");
+  cpl_parameterlist_append(list, p);
+
+  /* Wavelength Calibration */
+/* guess value for fwhm of emission lines */
+  p = cpl_parameter_new_value("sinfoni.wavecal.fwhm",
+                  CPL_TYPE_DOUBLE,
+                              "FWHM: initial guess value for the fwhm of "
+                              "the Gaussian used for the line fit",
+                              "sinfoni.wavecal",
+                               2.83);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"wcal-fwhm");
+  cpl_parameterlist_append(list, p);
+
+/* minimum amplitude of a line to be fitted */
+  p = cpl_parameter_new_value("sinfoni.wavecal.min_amplitude",
+                  CPL_TYPE_DOUBLE,
+                              "Minimum Of Amplitude: "
+                              "of the Gaussian to do the fit",
+                              "sinfoni.wavecal",
+                              5.);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"wcal-min_amplitude");
+  cpl_parameterlist_append(list, p);
+
+/* maximal residual value for a valid fit */
+  p = cpl_parameter_new_value("sinfoni.wavecal.max_residual",
+                  CPL_TYPE_DOUBLE,
+                              "Maximum Residuals value: "
+                              "beyond this value the fit is rejected",
+                              "sinfoni.wavecal",
+                              0.5);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"wcal-max_residual");
+  cpl_parameterlist_append(list, p);
+
+/* # of polynomial coefficients used for the dispersion relation */
+  p = cpl_parameter_new_value("sinfoni.wavecal.n_a_coefficients",
+                  CPL_TYPE_INT,
+                              "Number of A coefficients: number of "
+                              "polynomial coefficients for the "
+                              "dispersion relation",
+                              "sinfoni.wavecal",
+                              4);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"wcal-n_a_coeffs");
+  cpl_parameterlist_append(list, p);
+
+ /* # of polynomial coefficients used for the fit of 
+    the dispersion coefficients */
+  p = cpl_parameter_new_value("sinfoni.wavecal.n_b_coefficients",
+                  CPL_TYPE_INT,
+                              "Number of B coefficients: "
+                              "number of polynomial coefficients for the "
+                              "polynomial fit of the dispersion coefficients",
+                              "sinfoni.wavecal",
+                              2);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"wcal-n_b_coeffs");
+  cpl_parameterlist_append(list, p);
+
+ /* minimal factor of the standard deviation of the fit coefficients */
+  p = cpl_parameter_new_value("sinfoni.wavecal.sigma_factor",
+                  CPL_TYPE_DOUBLE,
+                              "Sigma Factor: "
+                              "Factor of the standard deviation of the "
+                              "polynomial coefficients of the dispersion "
+                              "relation beyond which the coefficients are "
+                              "not used for the fit",
+                              "sinfoni.wavecal",
+                              1.5);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"wcal-sigma_factor");
+  cpl_parameterlist_append(list, p);
+
+  /* indicates if the parameterized dispersion relation coefficients 
+       should be written into an ASCII file */
+  p = cpl_parameter_new_value("sinfoni.wavecal.write_coeffs_ind",
+                  CPL_TYPE_BOOL,
+                              "Write Coefficients Index: "
+                              "indicates if the coefficients should "
+                              "be written into a file or not",
+                              "sinfoni.wavecal",
+                              TRUE);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"wcal-wcoeff_ind");
+  cpl_parameterlist_append(list, p);
+
+  /* indicates if the fit parameters should be written into an ASCII file */
+  p = cpl_parameter_new_value("sinfoni.wavecal.write_par_ind",
+                  CPL_TYPE_BOOL,
+                              "Write Parameter Index: "
+                              "indicates if the fit parameters should "
+                              "be written into a file or not ",
+                              "sinfoni.wavecal",
+                              TRUE);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"wcal-par_ind");
+  cpl_parameterlist_append(list, p);
+
+
+
+
+
+
+
+
+
+  /* dispersion relation */
+
+
+
+  /* minimal distance of the slitlets in spectral direction */
+  p = cpl_parameter_new_value("sinfoni.wavecal.pixel_dist",
+                  CPL_TYPE_INT,
+                         "Minimal Slitlets's Distance in spectral direction",
+                              "sinfoni.wavecal",
+                              15);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"wcal-pixel_dist");
+  cpl_parameterlist_append(list, p);
+
+
+
+  /* allowed pixel position tolerance between estimated and fitted line 
+     position
+  */
+
+  p = cpl_parameter_new_value("sinfoni.wavecal.pixel_tol",
+                  CPL_TYPE_DOUBLE,
+                              "Pixel Tolerance: allowed pixel position "
+                              "tolerance between estimated and fitted "
+                  "line position",
+                              "sinfoni.wavecal",
+                              5.0);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"wcal-pixel_tol");
+  cpl_parameterlist_append(list, p);
+
+  /* Wavelength Map */
+/* indicator if wavelength map should be generated or not */
+  p = cpl_parameter_new_value("sinfoni.wavecal.wave_map_ind",
+                  CPL_TYPE_BOOL,
+                              "Wavelength Map Indicator: "
+                              "indicates if the wavelength calibration map "
+                              "should be generated (TRUE) or not (FALSE)",
+                              "sinfoni.wavecal",
+                              FALSE);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"wcal-wave_map_ind");
+  cpl_parameterlist_append(list, p);
+
+  /* magnifying factor for FFT */
+  p = cpl_parameter_new_value("sinfoni.wavecal.mag_factor",
+                  CPL_TYPE_INT,
+                              "Magnificator Factor: "
+                              "magnifying factor for the number of pixels "
+                              "in the columns needed for FFT",
+                              "sinfoni.wavecal",
+                              8);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"wcal-mag_factor");
+  cpl_parameterlist_append(list, p);
+
+/* Fits Slits */
+/* indicator if the fit of the slit edge positions is carried through or not */
+  p = cpl_parameter_new_value("sinfoni.wavecal.slit_pos_indicator",
+                  CPL_TYPE_BOOL,
+                              "Slit Position Indicator: "
+                              "indicates if the fits of the slitlet "
+                              "edge positions should be carried "
+                              "through or not",
+                              "sinfoni.wavecal",
+                              TRUE);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"wcal-slit_pos_ind");
+  cpl_parameterlist_append(list, p);
+
+/* indicator if the fit model function is a Boltzmann function or not */
+  p = cpl_parameter_new_value("sinfoni.wavecal.fit_boltz_indicator",
+                  CPL_TYPE_BOOL ,
+                              "Fit Boltzmann Indicator: "
+                              "indicates if the fits of the slitlet edge "
+                              "positions is carried trough by using a "
+                              "Boltzmann function as model function",
+                              "sinfoni.wavecal",
+                              TRUE);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"wcal-fit_boltz_ind");
+  cpl_parameterlist_append(list, p);
+
+/* indicator if the fit model function 
+   is a simple edge function or not */
+  p = cpl_parameter_new_value("sinfoni.wavecal.fit_edge_indicator",
+                  CPL_TYPE_BOOL,
+                              "Fit Edge Indicator: "
+                              "indicates if the fits of the slitlet edge "
+                              "positions is carried through by using a "
+                              "simple edge function as model function",
+                              "sinfoni.wavecal",
+                              FALSE);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"wcal-fit_edge_ind");
+  cpl_parameterlist_append(list, p);
+
+ /* indicator if the fit guess position are 
+    user given or calculated automatically */
+
+  p = cpl_parameter_new_value("sinfoni.wavecal.estimate_indicator",
+                  CPL_TYPE_BOOL,
+                              "Estimate Indicator: "
+                              "indicates if the fits of the slitlet edge "
+                              "positions is carried through by using a list "
+                              "of estimated guess positions in a file (TRUE)"
+                              "or if the initial positions are calculated "
+                              "automatically (FALSE). The estimation case "
+                              "is more stable",
+                              "sinfoni.wavecal",
+                              FALSE);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"wcal-estimate_ind");
+  cpl_parameterlist_append(list, p);
+
+/* pixel length of the row box within which the fit of the 
+   slitlet positions is carried out*/
+
+  p = cpl_parameter_new_value("sinfoni.wavecal.box_length",
+                  CPL_TYPE_INT,
+                              "Box Length: "
+                              "pixel length of the row box within "
+                              "which the fit is carried out",
+                              "sinfoni.wavecal",
+                              32);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"wcal-box_len");
+  cpl_parameterlist_append(list, p);
+
+/* float box half width in spectral direction */
+  p = cpl_parameter_new_value("sinfoni.wavecal.y_box",
+                  CPL_TYPE_DOUBLE,
+                              "Y Box: half width of a small box in "
+                              "spectral direction within which the "
+                              "maximal intensity pixel is searched",
+                              "sinfoni.wavecal",
+                              5.);
+
+ cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"wcal-y_box");
+  cpl_parameterlist_append(list, p);
+
+
+/* maximal tolerable difference to the expected slitlet positions */
+  p = cpl_parameter_new_value("sinfoni.wavecal.diff_tol",
+                  CPL_TYPE_DOUBLE,
+                              "Difference Tolearance: "
+                              "maximal tolerable difference of the "
+                              "resulting fit positions of the slitlet "
+                              "edges with respect to the expected positions",
+                              "sinfoni.wavecal",
+                              2.);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"wcal-diff_toll");
+  cpl_parameterlist_append(list, p);
+
+
+
+ p = cpl_parameter_new_value("sinfoni.wavecal.qc_thresh_min",
+                  CPL_TYPE_INT,
+                              "qc_thresh_min",
+                              "sinfoni.wavecal",
+                              0);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"wcal-qc_thresh_min");
+  cpl_parameterlist_append(list, p);
+
+
+  p = cpl_parameter_new_value("sinfoni.wavecal.qc_thresh_max",
+                  CPL_TYPE_INT,
+                              "qc_thresh_max",
+                              "sinfoni.wavecal",
+                              49000);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"wcal-qc_thresh_max");
+  cpl_parameterlist_append(list, p);
+
+
+  /*Resampling */
+ /* number of coefficients for the polynomial interpolation */
+  p = cpl_parameter_new_value("sinfoni.wavecal.n_coeffs",
+                  CPL_TYPE_INT,
+                              "number of coefficients for the polynomial "
+                              "interpolation ",
+                              "sinfoni.wavecal",
+                               3);
+
+  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"wcal-no_coeffs");
+  cpl_parameterlist_append(list, p);
+
+
+
+}
+/**@}*/
diff --git a/sinfoni/sinfo_wavecal_config.h b/sinfoni/sinfo_wavecal_config.h
new file mode 100644
index 0000000..0d7cf33
--- /dev/null
+++ b/sinfoni/sinfo_wavecal_config.h
@@ -0,0 +1,32 @@
+/* $Id: sinfo_wavecal_config.h,v 1.1 2006/10/20 08:06:33 amodigli Exp $
+ *
+ * This file is part of the CPL (Common Pipeline Library)
+ * Copyright (C) 2002 European Southern Observatory
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*
+ * $Author: amodigli $
+ * $Date: 2006/10/20 08:06:33 $
+ * $Revision: 1.1 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+ /****************************************************************
+  *   Wavecal Frames Data Reduction Parameter Initialization        *
+  ****************************************************************/
+#include <cpl.h>    /* defines parlist structure */
+void
+sinfo_wavecal_config_add(cpl_parameterlist *list);
diff --git a/sinfoni/sinfo_wavecal_ini.h b/sinfoni/sinfo_wavecal_ini.h
new file mode 100644
index 0000000..b5a300b
--- /dev/null
+++ b/sinfoni/sinfo_wavecal_ini.h
@@ -0,0 +1,78 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+   File name    :   sinfo_wavecal_ini.h
+   Author       :    Juergen Schreiber
+   Created on   :    Sept 14, 2001
+   Description  :    wavelength calibration ini file handling for SPIFFI
+ ---------------------------------------------------------------------------*/
+#ifndef SINFO_WAVECAL_INI_H
+#define SINFO_WAVECAL_INI_H
+/*---------------------------------------------------------------------------
+                                Includes
+---------------------------------------------------------------------------*/
+#include <cpl.h>
+#include "sinfo_wavecal_cfg.h"
+/*----------------------------------------------------------------------------
+                             Function prototypes 
+ ---------------------------------------------------------------------------*/
+
+/**
+  @name        generateWave_ini_file
+  @memo        Generate a default ini file for the wavelength 
+                calibration command.
+  @param    ini_name    Name of the file to generate.
+  @param    name_i        Name of the input file.
+  @param    name_o        Name of the output file.
+  @param    name_c        Name of the calibration file.
+  @return    int 0 if Ok, -1 otherwise.
+  @doc
+
+  This function generates a default ini file for the wavelength 
+  calibration command. The
+  generated file will have the requested name. If you do not want to
+  provide names for the input/output/calib files, feed either NULL pointers
+  or character strings starting with (char)0.
+ */
+
+int 
+generateWave_ini_file(
+        char * ini_name,
+        char * name_i,
+        char * name_o,
+        char * name_c
+);
+ 
+
+/**
+  @name     parse_wave_ini_file
+  @memo     Parse a ini_name.ini file and create a blackboard.
+  @param    ini_name    Name of the ASCII file to parse.
+  @return   1 newly allocated wave_config blackboard structure.
+  @doc
+
+  The requested ini file is parsed and a blackboard object is created, then
+  updated accordingly. Returns NULL in case of error.
+ */
+
+wave_config * 
+parse_wave_ini_file(char * ini_name) ;
+ 
+
+#endif
diff --git a/sinfoni/sinfo_wavecal_ini_by_cpl.c b/sinfoni/sinfo_wavecal_ini_by_cpl.c
new file mode 100644
index 0000000..418ab4a
--- /dev/null
+++ b/sinfoni/sinfo_wavecal_ini_by_cpl.c
@@ -0,0 +1,560 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+
+   File name    :   sinfo_wavecal_ini_by_cpl.c
+   Author       :   Andrea Modigliani
+   Created on   :   May 21, 2004
+   Description  :   wavelength calibration cpl input handling for SPIFFI
+
+ ---------------------------------------------------------------------------*/
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+
+/*---------------------------------------------------------------------------
+                                Includes
+ ---------------------------------------------------------------------------*/
+
+#include <string.h>
+#include "sinfo_wavecal_ini_by_cpl.h"
+#include "sinfo_raw_types.h"
+#include "sinfo_pro_types.h"
+#include "sinfo_ref_types.h"
+#include "sinfo_hidden.h"
+#include "sinfo_functions.h"
+#include "sinfo_utils.h"
+/*---------------------------------------------------------------------------
+                    Functions private to this module
+ ---------------------------------------------------------------------------*/
+
+static void
+parse_section_frames ( wave_config *, cpl_parameterlist* cpl_cfg, cpl_frameset* sof,
+                       cpl_frameset** raw, int* status );
+
+static void
+parse_section_findlines ( wave_config *, cpl_parameterlist* cpl_cfg );
+static void
+parse_section_wavecalib ( wave_config *, cpl_parameterlist* cpl_cfg );
+static void
+parse_section_wavemap ( wave_config *, cpl_parameterlist* cpl_cfg );
+static void
+parse_section_qclog ( wave_config *, cpl_parameterlist* cpl_cfg );
+static void
+parse_section_fitslits ( wave_config *, cpl_parameterlist* cpl_cfg );
+
+
+
+/**@{*/
+/**
+ * @addtogroup sinfo_rec_wavecal wavecal structure initialization
+ *
+ * TBD
+ */
+
+
+/*-------------------------------------------------------------------------*/
+/**
+  @name     generateWave_ini_file
+  @memo     Generate a default ini file for the SPIFFI wavelength calibration.
+  @param    ini_name    Name of the file to generate.
+  @param    name_i      Name of the input file, that means the name of the
+                        interleaved or convolved emission line frame.
+  @param    name_o      Name of the output file.
+  @param    name_c      Name of the calibration file, that means the name
+                        of the line list.
+  @return   int 0 if Ok, -1 otherwise.
+  @doc
+
+  This function generates a default ini file for the wavelength calibration.
+  The generated file will have the requested name. If you do not want to
+  provide names for the input/output/calib files, feed either NULL pointers
+  or character strings starting with (char)0.
+ */
+/*--------------------------------------------------------------------------*/
+
+/* Removed  generateWave_ini_file */
+
+/*-------------------------------------------------------------------------*/
+/**
+  @name     parse_wave_ini_file
+  @memo     Parse a ini_name.ini file and create a blackboard.
+  @param    ini_name    Name of the ASCII file to parse.
+  @return   1 newly allocated wave_config blackboard structure.
+  @doc
+
+  The requested ini file is parsed and a blackboard object is created, then
+  updated accordingly. Returns NULL in case of error.
+ */
+/*--------------------------------------------------------------------------*/
+
+wave_config *
+sinfo_parse_cpl_input_wave ( cpl_parameterlist* cpl_cfg,
+                             cpl_frameset* sof, cpl_frameset** raw )
+{
+
+	int  status=0;
+	wave_config   * cfg= sinfo_wave_cfg_create();
+	/*
+	 * Perform sanity checks, fill up the structure with what was
+	 * found in the ini file
+	 */
+
+	parse_section_findlines ( cfg, cpl_cfg );
+	parse_section_wavecalib ( cfg, cpl_cfg );
+	parse_section_wavemap ( cfg, cpl_cfg );
+	parse_section_fitslits ( cfg, cpl_cfg );
+	parse_section_qclog ( cfg, cpl_cfg );
+	parse_section_frames ( cfg, cpl_cfg, sof, raw, &status );
+
+	if ( status > 0 )
+	{
+		sinfo_msg_error ( "parsing cpl input" );
+		sinfo_wave_cfg_destroy ( cfg );
+		cfg = NULL ;
+		return NULL ;
+	}
+	return cfg ;
+}
+
+
+/*---------------------------------------------------------------------------
+   Functions:   parse_section_xxx()
+   In           :       symbolic table read from ini file
+   Out          :       void
+   Job          :       update a wave_config structure from what can be
+                            found in the ini file.
+   Notice       :       all of these functions update a status integer to
+                        indicate if an error occurred, or leave it as it is if
+                        everything went Ok.
+
+        parse_section_general()
+        parse_section_findlines()
+        parse_section_wavecalib()
+        parse_section_wavemap()
+        parse_section_fitslits()
+
+ ---------------------------------------------------------------------------*/
+
+
+
+static void
+parse_section_frames ( wave_config * cfg,cpl_parameterlist* cpl_cfg, cpl_frameset* sof,
+                       cpl_frameset** raw, int* status )
+{
+	cpl_frame* frame   = NULL;
+	char spat_res[FILE_NAME_SZ];
+	char lamp_status[FILE_NAME_SZ];
+	char band[FILE_NAME_SZ];
+	int ins_set=0;
+	int nraw=0;
+	cpl_parameter* p=NULL;
+	cpl_table* drs_tab=NULL;
+	wcal* w=sinfo_wcal_new();
+	int check=0;
+
+	sinfo_extract_raw_frames_type ( sof,raw,PRO_WAVE_LAMP_STACKED );
+	nraw=cpl_frameset_get_size ( *raw );
+	if ( nraw==0 )
+	{
+		sinfo_extract_raw_frames_type ( sof,raw,PRO_WAVE_NS_STACKED );
+	}
+	nraw=cpl_frameset_get_size ( *raw );
+	if ( nraw==0 )
+	{
+		sinfo_extract_raw_frames_type ( sof,raw,PRO_WAVE_SLITPOS_STACKED );
+	}
+
+	nraw=cpl_frameset_get_size ( *raw );
+	if ( nraw==0 )
+	{
+		sinfo_msg ( "Frame %s or %s or %s not found!",
+		            PRO_WAVE_LAMP_STACKED,PRO_WAVE_NS_STACKED,PRO_WAVE_SLITPOS_STACKED );
+		( *status ) ++;
+		return   ;
+	}
+
+	frame = cpl_frameset_get_frame ( *raw,0 );
+	sinfo_get_spatial_res ( frame,spat_res );
+
+	switch ( sinfo_frame_is_on ( frame ) )
+	{
+		case 0:
+			strcpy ( lamp_status,"on" );
+			break;
+		case 1:
+			strcpy ( lamp_status,"off" );
+			break;
+		case -1:
+			strcpy ( lamp_status,"undefined" );
+			break;
+		default:
+			strcpy ( lamp_status,"undefined" );
+			break;
+
+
+	}
+
+	sinfo_get_band ( frame,band );
+	sinfo_msg ( "Spatial resolution: %s lamp status: %s band: %s \n",
+	            spat_res,              lamp_status,    band );
+
+
+	sinfo_get_ins_set ( band,&ins_set );
+	if ( NULL != cpl_frameset_find ( sof,PRO_WAVE_LAMP_STACKED ) )
+	{
+		frame = cpl_frameset_find ( sof,PRO_WAVE_LAMP_STACKED );
+		strcpy ( cfg -> inFrame,cpl_frame_get_filename ( frame ) );
+	}
+	else if ( NULL != cpl_frameset_find ( sof,PRO_WAVE_NS_STACKED ) )
+	{
+		frame = cpl_frameset_find ( sof,PRO_WAVE_NS_STACKED );
+		strcpy ( cfg -> inFrame,cpl_frame_get_filename ( frame ) );
+	}
+	else if ( NULL != cpl_frameset_find ( sof,PRO_WAVE_SLITPOS_STACKED ) )
+	{
+		frame = cpl_frameset_find ( sof,PRO_WAVE_SLITPOS_STACKED );
+		strcpy ( cfg -> inFrame,cpl_frame_get_filename ( frame ) );
+	}
+	else
+	{
+		sinfo_msg_error ( "Frame %s or %s not found! Exit!",
+		                  PRO_WAVE_LAMP_STACKED,PRO_WAVE_NS_STACKED );
+		( *status ) ++;
+		return;
+	}
+
+
+	if ( NULL != cpl_frameset_find ( sof,DRS_SETUP_WAVE ) )
+	{
+		frame = cpl_frameset_find ( sof,DRS_SETUP_WAVE );
+		strcpy ( cfg -> drs_setup,cpl_frame_get_filename ( frame ) );
+		drs_tab = cpl_table_load ( cfg->drs_setup,1,0 );
+		w->wstart=cpl_table_get_double ( drs_tab,"W_START",ins_set,&check );
+		w->wgdisp1=cpl_table_get_double ( drs_tab,"W_DISP1",ins_set,&check );
+		w->wgdisp2=cpl_table_get_double ( drs_tab,"W_DISP2",ins_set,&check );
+		w->hw=cpl_table_get_int ( drs_tab,"W_HW",ins_set,&check );
+		w->fwhm=cpl_table_get_double ( drs_tab,"W_FWHM",ins_set,&check );
+		w->min_amp=cpl_table_get_double ( drs_tab,"W_MIN_AMP",ins_set,&check );
+		/*
+		    w->min_dif=cpl_table_get_double(drs_tab,"W_MIN_DIF",ins_set,&check);
+		    w->na_coef=cpl_table_get_int(drs_tab,"W_NA_COEFF",ins_set,&check);
+		    w->nb_coef=cpl_table_get_int(drs_tab,"W_NB_COEFF",ins_set,&check);
+		    w->pixel_tol=cpl_table_get_double(drs_tab,"W_PIX_TOL",ins_set,&check);
+		    w->y_box=cpl_table_get_double(drs_tab,"W_Y_BOX",ins_set,&check);
+		    */
+		w->low_pos=cpl_table_get_int ( drs_tab,"W_LOW_POS",ins_set,&check );
+		w->hig_pos=cpl_table_get_int ( drs_tab,"W_HI_POS",ins_set,&check );
+
+		cfg -> guessBeginWavelength = w->wstart;
+		cfg -> guessDispersion1 =  w->wgdisp1;
+		cfg -> guessDispersion2 =  w->wgdisp2;
+		p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.half_width" );
+		if ( sinfo_parameter_get_default_flag ( p ) == 0 )
+		{
+/*         cpl_msg_info(cpl_func, "param sinfoni.wavecal.half_width - using value from DRS [%i]", w->hw);*/
+			cfg -> halfWidth =         w->hw;
+		}
+   else
+   {
+/*         cpl_msg_info(cpl_func, "param sinfoni.wavecal.half_width - using value from command line [%g]", cfg -> halfWidth);   */
+   }
+       
+		p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.fwhm" );
+		if ( sinfo_parameter_get_default_flag ( p ) == 0 )
+		{
+			cfg -> fwhm =              w->fwhm;
+/*         cpl_msg_info(cpl_func, "param sinfoni.wavecal.fwhm - using value from DRS [%g]", cfg -> fwhm);  */
+		}
+      else
+      {
+/*         cpl_msg_info(cpl_func, "param sinfoni.wavecal.fwhm - using value from command line [%g]", cfg -> fwhm);     */
+      }
+		p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.min_amplitude" );
+		if ( sinfo_parameter_get_default_flag ( p ) == 0 )
+		{
+			cfg -> minAmplitude =      w->min_amp;
+/*         cpl_msg_info(cpl_func, "param sinfoni.wavecal.min_amplitude - using value from DRS [%g]", cfg -> minAmplitude);         */
+		}
+      else
+      {
+/*         cpl_msg_info(cpl_func, "param sinfoni.wavecal.min_amplitude - using value from command line [%g]", cfg -> minAmplitude);     */
+      }      
+		/*
+		cfg -> mindiff =           w->min_dif;
+		cfg -> nrDispCoefficients = w->na_coef;
+		cfg -> nrCoefCoefficients = w->nb_coef;
+		cfg -> pixel_tolerance =    w->pixel_tol;
+		cfg -> yBox =               w->y_box;
+		*/
+		cfg -> loPos =              w->low_pos;
+		cfg -> hiPos =              w->hig_pos;
+		/* cfg -> pixel_tolerance =    w->pixel_tol; */
+		/*
+		    sinfo_msg("cfg->guessBeginWavelength %g",cfg -> guessBeginWavelength);
+		    sinfo_msg("cfg->guessDispersion1 %g",cfg -> guessDispersion1);
+		    sinfo_msg("cfg->guessDispersion2 %g",cfg -> guessDispersion2);
+		    sinfo_msg("cfg->mindiff %g",cfg -> mindiff);
+		    sinfo_msg("cfg->halfWidth %d",cfg ->  halfWidth);
+		    sinfo_msg("cfg->fwhm %g",cfg -> fwhm);
+		    sinfo_msg("cfg->minAmplitude %g",cfg -> minAmplitude);
+		    sinfo_msg("cfg->nrDispCoefficients %d",cfg -> nrDispCoefficients); 
+		    sinfo_msg("cfg->nrCoefCoefficients %d",cfg -> nrCoefCoefficients);
+		    sinfo_msg("cfg->pixel_tolerance  %g",cfg -> pixel_tolerance);
+		    sinfo_msg("cfg->loPos %d",cfg -> loPos);
+		    sinfo_msg("cfg->hiPos %d",cfg -> hiPos);
+		    sinfo_msg("cfg->yBox  %f",cfg -> yBox);
+		*/
+
+		sinfo_wcal_delete ( w );
+		cpl_table_delete ( drs_tab );
+		if ( -1 == sinfo_check_rec_status ( 0 ) )
+		{
+			( *status ) ++;
+			return;
+		}
+
+	}
+	else
+	{
+		sinfo_msg_error ( "Frame %s not found! Exit!", DRS_SETUP_WAVE );
+		( *status ) ++;
+		return;
+	}
+
+
+	if ( NULL != cpl_frameset_find ( sof,REF_LINE_ARC ) )
+	{
+		frame = cpl_frameset_find ( sof,REF_LINE_ARC );
+		strcpy ( cfg -> lineList,cpl_frame_get_filename ( frame ) );
+	}
+	else
+	{
+		sinfo_msg_error ( "Frame %s not found! Exit!", REF_LINE_ARC );
+		( *status ) ++;
+		return;
+	}
+
+
+	if ( NULL != cpl_frameset_find ( sof,PRO_SLIT_POS_GUESS ) )
+	{
+		frame = cpl_frameset_find ( sof,PRO_SLIT_POS_GUESS );
+		strcpy ( cfg -> slitposGuessName,cpl_frame_get_filename ( frame ) );
+	}
+	else
+	{
+		sinfo_msg ( "Frame %s not found!", PRO_SLIT_POS_GUESS );
+	}
+
+	if ( cfg -> writeParInd ==0 )
+	{
+		if ( NULL != cpl_frameset_find ( sof,PRO_WAVE_PAR_LIST ) )
+		{
+			frame = cpl_frameset_find ( sof,PRO_WAVE_PAR_LIST );
+			strcpy ( cfg ->  paramsList,cpl_frame_get_filename ( frame ) );
+		}
+		else
+		{
+			sinfo_msg ( "Frame %s not found!", PRO_WAVE_PAR_LIST );
+			( *status ) ++;
+			return   ;
+		}
+
+	}
+	else
+	{
+
+		strcpy ( cfg -> paramsList, WAVECAL_FIT_PARAMS_OUT_FILENAME );
+		sinfo_msg ( "cfg -> paramsList %s not given\n",cfg -> paramsList );
+
+	}
+
+
+
+	if ( cfg -> calibIndicator ==  0 )
+	{
+		if ( NULL != cpl_frameset_find ( sof,PRO_WAVE_COEF_SLIT ) )
+		{
+			frame = cpl_frameset_find ( sof,PRO_WAVE_COEF_SLIT );
+			strcpy ( cfg -> coeffsName,cpl_frame_get_filename ( frame ) );
+		}
+		else
+		{
+			sinfo_msg_error ( "Frame %s not found! Exit!", PRO_WAVE_COEF_SLIT );
+			( *status ) ++;
+			return;
+		}
+	}
+	else
+	{
+
+		strcpy ( cfg -> coeffsName, WAVECAL_COEFF_SLIT_OUT_FILENAME );
+		sinfo_msg ( "cfg -> coeffsName %s not given\n",cfg -> coeffsName );
+
+	}
+
+	strcpy ( cfg -> outName, WAVECAL_OUT_FILENAME );
+	strcpy ( cfg -> slitposName, WAVECAL_SLIT_POS_OUT_FILENAME );
+
+	return;
+}
+
+
+static void
+parse_section_findlines ( wave_config * cfg,cpl_parameterlist* cpl_cfg )
+{
+
+	cpl_parameter* p;
+
+	p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.calib_indicator" );
+	cfg -> calibIndicator = cpl_parameter_get_bool ( p );
+
+	p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.min_diff" );
+	cfg -> mindiff =  cpl_parameter_get_double ( p );
+
+	p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.half_width" );
+	cfg -> halfWidth = cpl_parameter_get_int ( p );
+
+	p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.sigma" );
+	cfg -> sigma =  cpl_parameter_get_double ( p );
+
+	return ;
+}
+
+static void
+parse_section_wavecalib ( wave_config * cfg,cpl_parameterlist* cpl_cfg )
+{
+	cpl_parameter* p;
+
+	p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.fwhm" );
+	cfg -> fwhm =  cpl_parameter_get_double ( p );
+
+	p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.min_amplitude" );
+	cfg -> minAmplitude =  cpl_parameter_get_double ( p );
+
+	p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.max_residual" );
+	cfg -> maxResidual =  cpl_parameter_get_double ( p );
+
+	p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.n_a_coefficients" );
+	cfg -> nrDispCoefficients = cpl_parameter_get_int ( p );
+
+	p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.n_b_coefficients" );
+	cfg -> nrCoefCoefficients = cpl_parameter_get_int ( p );
+
+	p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.sigma_factor" );
+	cfg -> sigmaFactor =  cpl_parameter_get_double ( p );
+
+	p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.write_coeffs_ind" );
+	cfg -> writeCoeffsInd = cpl_parameter_get_bool ( p );
+
+	p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.write_par_ind" );
+	cfg -> writeParInd = cpl_parameter_get_bool ( p );
+
+	cfg -> nslitlets = NSLITLETS;
+
+	p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.pixel_dist" );
+	cfg -> pixeldist = cpl_parameter_get_int ( p );
+
+	p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.pixel_tol" );
+	cfg -> pixel_tolerance = cpl_parameter_get_double ( p );
+
+}
+
+static void
+parse_section_wavemap ( wave_config * cfg,cpl_parameterlist* cpl_cfg )
+{
+	cpl_parameter* p;
+
+	p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.wave_map_ind" );
+	cfg -> wavemapInd = cpl_parameter_get_bool ( p );
+
+	p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.mag_factor" );
+	cfg -> magFactor = cpl_parameter_get_int ( p );
+
+
+}
+
+static void
+parse_section_fitslits ( wave_config * cfg,cpl_parameterlist* cpl_cfg )
+{
+
+	cpl_parameter* p;
+
+	p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.slit_pos_indicator" );
+	cfg -> slitposIndicator = cpl_parameter_get_bool ( p );
+
+	p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.fit_boltz_indicator" );
+	cfg -> fitBoltzIndicator = cpl_parameter_get_bool ( p );
+
+	p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.fit_edge_indicator" );
+	cfg -> fitEdgeIndicator = cpl_parameter_get_bool ( p );
+
+	p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.estimate_indicator" );
+	cfg -> estimateIndicator = cpl_parameter_get_bool ( p );
+
+	cfg -> loPos =  750;
+	cfg -> hiPos =  1000;
+
+	p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.box_length" );
+	cfg -> boxLength = cpl_parameter_get_int ( p );
+
+	p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.y_box" );
+	cfg -> yBox = cpl_parameter_get_double ( p );
+
+	p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.diff_tol" );
+	cfg -> diffTol =  cpl_parameter_get_double ( p );
+
+	/* input CDB
+	p = cpl_parameterlist_find(cpl_cfg, "sinfoni.wavecal.slit_pos_guess_name");
+	strcpy(cfg -> slitposGuessName, cpl_parameter_get_default_string(p));
+	*/
+
+}
+
+static void
+parse_section_qclog ( wave_config * cfg, cpl_parameterlist* cpl_cfg )
+{
+	cpl_parameter* p;
+
+	p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.qc_thresh_min" );
+	cfg ->  qc_thresh_min = cpl_parameter_get_int ( p );
+
+
+	p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.qc_thresh_max" );
+	cfg ->  qc_thresh_max = cpl_parameter_get_int ( p );
+
+
+}
+
+void
+sinfo_wavecal_free ( wave_config ** cfg )
+{
+	if ( *cfg != NULL )
+	{
+		sinfo_wave_cfg_destroy ( *cfg );
+		*cfg=NULL;
+	}
+	return;
+
+}
+
+
+/**@}*/
diff --git a/sinfoni/sinfo_wavecal_ini_by_cpl.h b/sinfoni/sinfo_wavecal_ini_by_cpl.h
new file mode 100644
index 0000000..4989f68
--- /dev/null
+++ b/sinfoni/sinfo_wavecal_ini_by_cpl.h
@@ -0,0 +1,64 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004,2005 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*----------------------------------------------------------------------------
+   
+   File name    :   sinfo_wavecal_ini_by_cpl.h
+   Author       :   Andrea Modigliani
+   Created on   :   May 21, 2004
+   Description  :   wavelength calibration cpl input handling for SPIFFI
+ ---------------------------------------------------------------------------*/
+#ifndef SINFO_WAVECAL_INI_BY_CPL_H
+#define SINFO_WAVECAL_INI_BY_CPL_H
+/*---------------------------------------------------------------------------
+                                Includes
+---------------------------------------------------------------------------*/
+#include <cpl.h>
+#include "sinfo_wavecal_cfg.h"
+#include "sinfo_msg.h"
+/*----------------------------------------------------------------------------
+                             Function prototypes 
+ ---------------------------------------------------------------------------*/
+/**
+  @name     parse_wave_ini_file
+  @memo     Parse a ini_name.ini file and create a blackboard.
+  @param    cpl_cfg pointer to parameterlist
+  @param    sof pointer to input set of frames
+  @param    raw pointer to input set of raw frames
+  @return   1 newly allocated wave_config blackboard structure.
+  @doc
+
+  The requested ini file is parsed and a blackboard object is created, then
+  updated accordingly. Returns NULL in case of error.
+ */
+
+wave_config * 
+sinfo_parse_cpl_input_wave(cpl_parameterlist * cpl_cfg, 
+                           cpl_frameset* sof, 
+               cpl_frameset** raw) ;
+
+/**
+ at name sinfo_wavecal_free
+ at memo deallocates wave_config structure
+ at param cfg pointer to wave_config structure
+ at return void
+*/
+void 
+sinfo_wavecal_free(wave_config ** cfg);
+
+#endif
diff --git a/sinfoni/sinfo_wcal_functions.c b/sinfoni/sinfo_wcal_functions.c
new file mode 100644
index 0000000..eec099a
--- /dev/null
+++ b/sinfoni/sinfo_wcal_functions.c
@@ -0,0 +1,414 @@
+/* $Id: sinfo_wcal_functions.c,v 1.9 2012/03/03 10:35:14 amodigli Exp $
+ *
+ * This file is part of the SINFONI Pipeline
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2012/03/03 10:35:14 $
+ * $Revision: 1.9 $
+ * $Name: sinfo-2_3_2 $
+ */
+
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+/*-----------------------------------------------------------------------------
+                                   Includes
+ ----------------------------------------------------------------------------*/
+
+#include "sinfo_wcal_functions.h"
+#include "sinfo_globals.h"
+#include "sinfo_error.h"
+#include "sinfo_utils_wrappers.h"
+
+/* struct qc_wcal qc_wcal_par; */
+/**@{*/
+/**
+ * @addtogroup sinfo_rec_wavecal wavecal functions
+ *
+ * TBD
+ */
+
+qc_wcal* sinfo_qc_wcal_new(void)
+{  
+
+  qc_wcal * qc;
+  qc= cpl_malloc(sizeof(qc_wcal));
+
+  qc->avg_on=0; 
+  qc->std_on=0;
+  qc->avg_of=0; 
+  qc->std_of=0;
+  qc->avg_di=0; 
+  qc->std_di=0;
+  qc->max_on=0;
+  qc->max_of=0;
+  qc->max_di=0;
+  qc->nsat_on=0;
+  qc->noise_on=0;
+  qc->noise_of=0;
+  qc->flux_on=0;
+  qc->nsat=0;
+  return qc;
+}
+
+void sinfo_qc_wcal_delete(qc_wcal** qc)
+{
+  cpl_free(*qc);
+  *qc = NULL;
+}
+
+int sinfo_dumpTblToFitParams ( FitParams ** params, char * filename )
+{
+    cpl_table * fp =NULL;
+    char* col=NULL;
+    int i =0;
+    int j =0;
+    int status=0;
+
+
+    if ( NULL == params )
+    {
+        sinfo_msg_error ("no fit parameters available!") ;
+        return -1;
+    }
+
+    if ( NULL == filename )
+    {
+        sinfo_msg_error ("no filename available!") ;
+        return -1;
+    }
+   
+
+    fp=cpl_table_load(filename,1,0);
+    if(cpl_error_get_code() != CPL_ERROR_NONE) {
+      sinfo_msg("cannot load table %s",filename);
+      sinfo_msg_error((char* ) cpl_error_get_message());
+      return -1;
+    }
+
+    col = (char*) cpl_calloc(MAX_NAME_SIZE,sizeof(char*));
+    for ( i = 0 ; i < params[0]->n_params ; i++ )
+    {
+       params[i]->n_params=cpl_table_get_int(fp,"n_params",i,&status);
+       params[i]->column  =cpl_table_get_int(fp,"column",i,&status);
+       params[i]->line    =cpl_table_get_int(fp,"line",i,&status);
+       for (j=0 ; j < 4; j++) {
+     snprintf(col,MAX_NAME_SIZE-1,"%s%d","fpar",j);
+         params[i]->fit_par[j]=cpl_table_get_double(fp,col,i,&status);
+     snprintf(col,MAX_NAME_SIZE-1,"%s%d","dpar",j);
+         params[i]->derv_par[j]=cpl_table_get_double(fp,col,i,&status);
+       }
+    }
+    cpl_free(col);
+    cpl_table_delete(fp) ;
+    return 0;
+}
+
+
+
+
+int sinfo_det_ncounts(cpl_frameset* raw, int thresh_max, qc_wcal* qc)
+{
+ int i=0;
+ int j=0;
+
+ long nraw=0;
+ int non=0;
+ int noff=0;
+ int nsat=0;
+
+ double mean=0;
+ double max=0;
+
+ double mjd_on=0;
+ double mjd_of=0;
+ double mjd_of_frm=0;
+
+ char name[FILE_NAME_SZ];
+ char filename[FILE_NAME_SZ];
+
+
+ cpl_vector* avg_on=NULL;
+ cpl_vector* avg_of=NULL;
+ cpl_vector* avg_di=NULL;
+
+
+ cpl_vector* max_on=NULL;
+ cpl_vector* max_of=NULL;
+ cpl_vector* max_di=NULL;
+
+ cpl_vector* vec_nsat=NULL;
+
+ cpl_frame* frm=NULL;
+ cpl_frame* frm_dup=NULL;
+ cpl_frame* on_frm=NULL;
+ cpl_frame* of_frm=NULL;
+ cpl_frame* tmp_of_frm=NULL;
+
+ cpl_image* dif_ima=NULL;
+ cpl_image* on_ima=NULL;
+ cpl_image* of_ima=NULL;
+ cpl_image* tmp_ima=NULL;
+
+ cpl_frameset* on_set=NULL;
+ cpl_frameset* of_set=NULL;
+ 
+ on_set=cpl_frameset_new();
+ of_set=cpl_frameset_new();
+ nraw = cpl_frameset_get_size(raw);
+
+
+ for (i=0; i< nraw; i++) {
+   check_nomsg(frm = cpl_frameset_get_frame(raw,i));
+   check_nomsg(frm_dup = cpl_frame_duplicate(frm));
+   if(sinfo_frame_is_on(frm) == 1) {
+     cpl_frameset_insert(on_set,frm_dup);
+     non++;
+   } else {
+     cpl_frameset_insert(of_set,frm_dup);
+     noff++;
+   }
+ }
+
+
+ if (non == noff) {   
+     sinfo_msg("Monitor counts: case Non==Noff");
+
+
+    avg_on = cpl_vector_new(non);
+    avg_of = cpl_vector_new(non);
+    avg_di = cpl_vector_new(non);
+
+    max_on = cpl_vector_new(non);
+    max_of = cpl_vector_new(non);
+    max_di = cpl_vector_new(non);
+
+
+
+    vec_nsat = cpl_vector_new(non);
+    for (i=0; i< non; i++) {
+      check_nomsg(on_frm = cpl_frameset_get_frame(on_set,i));
+      strcpy(name,cpl_frame_get_filename(on_frm));
+      check_nomsg(on_ima = cpl_image_load(name,CPL_TYPE_FLOAT,0,0));
+
+      check_nomsg(mean= cpl_image_get_mean(on_ima));
+      check_nomsg(cpl_vector_set(avg_on,i,mean));
+      check_nomsg(max= cpl_image_get_max(on_ima));
+      check_nomsg(cpl_vector_set(max_on,i,max));
+      check_nomsg(tmp_ima = cpl_image_duplicate(on_ima));
+      check_nomsg(cpl_image_threshold(tmp_ima,thresh_max,thresh_max,0,1));
+      check_nomsg(nsat=cpl_image_get_flux(tmp_ima));
+      check_nomsg(cpl_vector_set(vec_nsat,i,nsat));
+
+
+      check_nomsg(of_frm = cpl_frameset_get_frame(of_set,i));
+      strcpy(name,cpl_frame_get_filename(of_frm));
+      check_nomsg(of_ima = cpl_image_load(name,CPL_TYPE_FLOAT,0,0));
+      check_nomsg(mean= cpl_image_get_mean(of_ima));
+      check_nomsg(cpl_vector_set(avg_of,i,mean));
+      check_nomsg(max= cpl_image_get_max(of_ima));
+      check_nomsg(cpl_vector_set(max_of,i,max));
+     
+      check_nomsg(dif_ima = cpl_image_subtract_create(on_ima,of_ima));
+      check_nomsg(mean= cpl_image_get_mean(dif_ima));
+      check_nomsg(cpl_vector_set(avg_di,i,mean));
+      check_nomsg(max= cpl_image_get_max(dif_ima));
+      check_nomsg(cpl_vector_set(max_di,i,max));
+
+      sinfo_free_image(&on_ima);
+      sinfo_free_image(&of_ima);
+      sinfo_free_image(&dif_ima);
+      sinfo_free_image(&tmp_ima);
+
+    }
+
+    check_nomsg(qc->avg_on=cpl_vector_get_mean(avg_on));
+    check_nomsg(qc->avg_of=cpl_vector_get_mean(avg_of));
+    check_nomsg(qc->avg_di=cpl_vector_get_mean(avg_di));
+
+    check_nomsg(qc->max_on=cpl_vector_get_max(max_on));
+    check_nomsg(qc->max_of=cpl_vector_get_max(max_of));
+    check_nomsg(qc->max_di=cpl_vector_get_max(max_di));
+
+    check_nomsg(qc->nsat=cpl_vector_get_mean(vec_nsat));
+
+    if (non > 1) {
+      check_nomsg(qc->std_on=cpl_vector_get_stdev(avg_on));
+      check_nomsg(qc->std_of=cpl_vector_get_stdev(avg_of));
+      check_nomsg(qc->std_di=cpl_vector_get_stdev(avg_di));
+    }
+
+    sinfo_free_my_vector(&avg_on);
+    sinfo_free_my_vector(&avg_of);
+    sinfo_free_my_vector(&avg_di);    
+
+    sinfo_free_my_vector(&max_on);
+    sinfo_free_my_vector(&max_of);
+    sinfo_free_my_vector(&max_di);
+
+    sinfo_free_my_vector(&vec_nsat);
+
+
+ } else if ( ((non ==0) | (noff == 0)) && (nraw > 0 ) ) {
+    sinfo_msg("Monitor counts: case Nraw == 1");
+    check_nomsg(avg_di = cpl_vector_new(nraw));
+    check_nomsg(max_di = cpl_vector_new(nraw));
+    check_nomsg(vec_nsat = cpl_vector_new(nraw));
+
+    for (i=0; i< nraw; i++) {
+      check_nomsg(frm = cpl_frameset_get_frame(raw,i));
+      strcpy(name,cpl_frame_get_filename(frm));
+      check_nomsg(dif_ima = cpl_image_load(name,CPL_TYPE_FLOAT,0,0));
+
+      check_nomsg(mean= cpl_image_get_mean(dif_ima));
+      check_nomsg(tmp_ima=cpl_image_duplicate(dif_ima));
+      sinfo_clean_nan(&tmp_ima);
+      check_nomsg(mean= cpl_image_get_mean(tmp_ima));
+      check_nomsg(cpl_vector_set(avg_di,i,mean));
+      check_nomsg(max= cpl_image_get_max(tmp_ima));
+      check_nomsg(cpl_vector_set(max_di,i,max));
+      check_nomsg(cpl_image_threshold(tmp_ima,thresh_max,thresh_max,0,1));
+      check_nomsg(nsat=cpl_image_get_flux(tmp_ima));
+      check_nomsg(cpl_vector_set(vec_nsat,i,nsat));
+
+      sinfo_free_image(&tmp_ima);
+      sinfo_free_image(&dif_ima);
+
+    }
+
+    qc->avg_di=cpl_vector_get_mean(avg_di);
+    if (nraw > 1) {
+      check_nomsg(qc->std_di=cpl_vector_get_stdev(avg_di));
+    }
+    check_nomsg(qc->max_di=cpl_vector_get_max(max_di));
+    check_nomsg(qc->nsat=cpl_vector_get_mean(vec_nsat));
+
+    sinfo_free_my_vector(&avg_di);
+    sinfo_free_my_vector(&max_di);
+    sinfo_free_my_vector(&vec_nsat);
+
+ } else {
+   sinfo_msg("Monitor counts: else case");
+
+    avg_on = cpl_vector_new(non);
+    avg_of = cpl_vector_new(non);
+    avg_di = cpl_vector_new(non);
+
+    max_on = cpl_vector_new(non);
+    max_of = cpl_vector_new(non);
+    max_di = cpl_vector_new(non);
+
+    vec_nsat = cpl_vector_new(non);
+
+    for (i=0;i<non;i++) {
+      check_nomsg(on_frm=cpl_frameset_get_frame(on_set,i));
+      check_nomsg(mjd_on=sinfo_get_mjd_obs(on_frm));
+      check_nomsg(of_frm=cpl_frameset_get_frame(of_set,0));
+      check_nomsg(mjd_of=sinfo_get_mjd_obs(of_frm));
+      strcpy(filename,cpl_frame_get_filename(of_frm));
+
+      for (j=1;j<noff;j++) {
+	check_nomsg(tmp_of_frm = cpl_frameset_get_frame(of_set,j));
+        check_nomsg(mjd_of_frm = sinfo_get_mjd_obs(tmp_of_frm));
+
+          if(1000.*(mjd_of_frm-mjd_on)*(mjd_of_frm-mjd_on) <
+             1000.*(mjd_of-    mjd_on)*(mjd_of-    mjd_on) ) {
+            mjd_of=mjd_of_frm;
+             of_frm=tmp_of_frm;
+	  }
+      }
+
+       strcpy(filename,cpl_frame_get_filename(of_frm));
+       check_nomsg(of_ima = cpl_image_load(filename,CPL_TYPE_FLOAT,0,0));
+       check_nomsg(mean= cpl_image_get_mean(of_ima));
+       check_nomsg(cpl_vector_set(avg_of,i,mean));
+       check_nomsg(max= cpl_image_get_max(of_ima));
+       check_nomsg(cpl_vector_set(max_of,i,max));
+
+       strcpy(filename,cpl_frame_get_filename(on_frm));
+       check_nomsg(on_ima = cpl_image_load(filename,CPL_TYPE_FLOAT,0,0));
+       check_nomsg(mean= cpl_image_get_mean(on_ima)); 
+       check_nomsg(cpl_vector_set(avg_on,i,mean));
+       check_nomsg(max= cpl_image_get_mean(on_ima)); 
+       check_nomsg(cpl_vector_set(max_on,i,max));
+
+       check_nomsg(tmp_ima = cpl_image_duplicate(on_ima));     
+       check_nomsg(cpl_image_threshold(tmp_ima,thresh_max,thresh_max,0,1));
+       check_nomsg(nsat=cpl_image_get_flux(tmp_ima));
+       check_nomsg(cpl_vector_set(vec_nsat,i,nsat));
+
+       check_nomsg(dif_ima = cpl_image_subtract_create(on_ima,of_ima));
+       check_nomsg(mean= cpl_image_get_mean(dif_ima));
+       check_nomsg(cpl_vector_set(avg_di,i,mean));
+       check_nomsg(max= cpl_image_get_max(dif_ima));
+       check_nomsg(cpl_vector_set(max_di,i,max));
+
+       sinfo_free_image(&on_ima);
+       sinfo_free_image(&of_ima);
+       sinfo_free_image(&dif_ima);
+       sinfo_free_image(&tmp_ima);
+
+   }
+
+    sinfo_free_my_vector(&avg_on);
+    sinfo_free_my_vector(&avg_of);
+    sinfo_free_my_vector(&avg_di);
+
+    sinfo_free_my_vector(&max_on);
+    sinfo_free_my_vector(&max_of);
+    sinfo_free_my_vector(&max_di);
+
+    sinfo_free_my_vector(&vec_nsat);
+
+ }
+
+ /*
+ sinfo_msg("avg_on=%g std_on=%g ",qc->avg_on,qc_wcal.std_on);
+ sinfo_msg("avg_of=%g std_of=%g ",qc->avg_of,qc_wcal.std_of);
+ sinfo_msg("avg_di=%g std_di=%g ",qc->avg_di,qc_wcal.std_di);
+ sinfo_msg("max_fl=%g nsat_on=%g ",qc->max_di,qc_wcal.nsat);
+ */
+ cleanup:
+ 
+ sinfo_free_image(&on_ima);
+ sinfo_free_image(&of_ima);
+ sinfo_free_image(&dif_ima);
+ sinfo_free_image(&tmp_ima);
+
+ sinfo_free_my_vector(&avg_on);
+ sinfo_free_my_vector(&avg_of);
+ sinfo_free_my_vector(&avg_di);
+
+ sinfo_free_my_vector(&max_on);
+ sinfo_free_my_vector(&max_of);
+ sinfo_free_my_vector(&max_di);
+
+ sinfo_free_my_vector(&vec_nsat);
+
+ sinfo_free_frameset(&on_set);
+ sinfo_free_frameset(&of_set);
+
+ return 0;
+
+}
+
+
+/**@}*/
diff --git a/sinfoni/sinfo_wcal_functions.h b/sinfoni/sinfo_wcal_functions.h
new file mode 100644
index 0000000..13464b0
--- /dev/null
+++ b/sinfoni/sinfo_wcal_functions.h
@@ -0,0 +1,68 @@
+/* $Id: sinfo_wcal_functions.h,v 1.2 2006/10/22 14:12:28 amodigli Exp $
+ *
+ * This file is part of the SINFONI Pipeline
+ * Copyright (C) 2002,2003 European Southern Observatory
+ *
+ * This proram is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2006/10/22 14:12:28 $
+ * $Revision: 1.2 $
+ * $Name: sinfo-2_3_2 $
+ */
+#ifndef SINFO_WCAL_FUNCTIONS_H
+#define SINFO_WCAL_FUNCTIONS_H
+struct qc_wcal_ {
+
+  double avg_on; 
+  double std_on;
+  double avg_of; 
+  double std_of;
+  double avg_di; 
+  double std_di;
+  double max_on;
+  double max_of;
+  double max_di;
+  double nsat_on;
+  double noise_on;
+  double noise_of;
+  double flux_on;
+  double    nsat;
+
+};
+ 
+
+
+typedef struct qc_wcal_ qc_wcal;
+
+/* extern struct qc_wcal qc_wcal_par; */
+#include "sinfo_functions.h"
+#include <cpl.h>
+#include <sinfo_globals.h>
+#include <sinfo_spiffi_types.h>
+#include <sinfo_wavecal_cfg.h>
+#include "sinfo_msg.h"
+/* ---------------------------------------------------------------------- 
+   group of frames
+---------------------------------------------------------------------- */
+int sinfo_dumpTblToFitParams ( FitParams ** params, char * filename );
+int sinfo_det_ncounts(cpl_frameset* raw, int thresh_max, qc_wcal* qc);
+qc_wcal* sinfo_qc_wcal_new(void);
+void sinfo_qc_wcal_delete(qc_wcal** qc);
+CPL_END_DECLS
+
+#endif
diff --git a/sinfoni/tests/Makefile.am b/sinfoni/tests/Makefile.am
new file mode 100644
index 0000000..927cd90
--- /dev/null
+++ b/sinfoni/tests/Makefile.am
@@ -0,0 +1,84 @@
+## Process this file with automake to produce Makefile.in
+
+##   This file is part of the SINFONI Pipeline Library
+##   Copyright (C) 2002,2003 European Southern Observatory
+
+##   This library is free software; you can redistribute it and/or modify
+##   it under the terms of the GNU General Public License as published by
+##   the Free Software Foundation; either version 2 of the License, or
+##   (at your option) any later version.
+
+##   This program is distributed in the hope that it will be useful,
+##   but WITHOUT ANY WARRANTY; without even the implied warranty of
+##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+##   GNU General Public License for more details.
+
+##   You should have received a copy of the GNU General Public License
+##   along with this program; if not, write to the Free Software
+##   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+AUTOMAKE_OPTIONS = 1.6 foreign
+
+DISTCLEANFILES = *~ .logfile
+
+if MAINTAINER_MODE
+
+MAINTAINERCLEANFILES = Makefile.in
+
+endif
+
+#LIBSINFONI = $(top_builddir)/sinfoni/libsinfo.la
+
+#INCLUDES = -I$(top_builddir)/sinfoni -I$(top_builddir)/irplib
+INCLUDES = $(all_includes)
+LDADD = $(LIBSINFONI)
+AM_LDFLAGS = -static
+
+noinst_HEADERS = 
+
+check_PROGRAMS = sinfo_skycor_test \
+		sinfo_strehl_test \
+		sinfo_cube_coadd_test \
+		sinfo_image_ops_test \
+		sinfo_table_ops_test \
+		sinfo_cube_ops_test \
+		sinfo_kappa_sigma_test \
+		sinfo_efficiency_test \
+		sinfo_gauss_fit_test \
+		sinfo_star_index_test \
+		sinfo_star_catalog \
+		sinfo_line_corr_test \
+		test_atmo_disp
+
+TESTS = sinfo_skycor_test sinfo_strehl_test sinfo_cube_coadd_test \
+	sinfo_image_ops_test sinfo_cube_ops_test sinfo_table_ops_test \
+	sinfo_kappa_sigma_test sinfo_efficiency_test sinfo_gauss_fit_test \
+	sinfo_star_index_test sinfo_star_catalog sinfo_line_corr_test \
+	test_atmo_disp
+
+sinfo_skycor_test_SOURCES = sinfo_skycor_test.c 
+sinfo_strehl_test_SOURCES = sinfo_strehl_test.c
+sinfo_cube_coadd_test_SOURCES = sinfo_cube_coadd_test.c
+sinfo_image_ops_test_SOURCES = sinfo_image_ops_test.c
+sinfo_cube_ops_test_SOURCES = sinfo_cube_ops_test.c
+sinfo_table_ops_test_SOURCES = sinfo_table_ops_test.c
+sinfo_kappa_sigma_test_SOURCES = sinfo_kappa_sigma_test.c
+sinfo_efficiency_test_SOURCES = sinfo_efficiency_test.c
+sinfo_gauss_fit_test_SOURCES = sinfo_gauss_fit_test.c
+sinfo_star_index_test_SOURCES = sinfo_star_index_test.c
+sinfo_star_catalog_SOURCES = sinfo_star_catalog.c
+sinfo_line_corr_test_SOURCES = sinfo_line_corr_test.c
+test_atmo_disp_SOURCES = test_atmo_disp.c
+# Be sure to reexport important environment variables.
+TESTS_ENVIRONMENT = MAKE="$(MAKE)" CC="$(CC)" CFLAGS="$(CFLAGS)" \
+        CPPFLAGS="$(CPPFLAGS)" LD="$(LD)" LDFLAGS="$(LDFLAGS)" \
+        LIBS="$(LIBS)" LN_S="$(LN_S)" NM="$(NM)" RANLIB="$(RANLIB)" \
+        OBJEXT="$(OBJEXT)" EXEEXT="$(EXEEXT)"
+
+if PURIFY
+include $(top_builddir)/Makefile.purify 
+endif
+
+# We need to remove any files that the above tests created.
+clean-local:
+	 $(RM) *.fits *.log
diff --git a/sinfoni/tests/Makefile.in b/sinfoni/tests/Makefile.in
new file mode 100644
index 0000000..56fb04a
--- /dev/null
+++ b/sinfoni/tests/Makefile.in
@@ -0,0 +1,777 @@
+# Makefile.in generated by automake 1.11 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009  Free Software Foundation,
+# Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+ at SET_MAKE@
+
+VPATH = @srcdir@
+pkgdatadir = $(datadir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkglibexecdir = $(libexecdir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
+target_triplet = @target@
+check_PROGRAMS = sinfo_skycor_test$(EXEEXT) sinfo_strehl_test$(EXEEXT) \
+	sinfo_cube_coadd_test$(EXEEXT) sinfo_image_ops_test$(EXEEXT) \
+	sinfo_table_ops_test$(EXEEXT) sinfo_cube_ops_test$(EXEEXT) \
+	sinfo_kappa_sigma_test$(EXEEXT) sinfo_efficiency_test$(EXEEXT) \
+	sinfo_gauss_fit_test$(EXEEXT) sinfo_star_index_test$(EXEEXT) \
+	sinfo_star_catalog$(EXEEXT) sinfo_line_corr_test$(EXEEXT) \
+	test_atmo_disp$(EXEEXT)
+TESTS = sinfo_skycor_test$(EXEEXT) sinfo_strehl_test$(EXEEXT) \
+	sinfo_cube_coadd_test$(EXEEXT) sinfo_image_ops_test$(EXEEXT) \
+	sinfo_cube_ops_test$(EXEEXT) sinfo_table_ops_test$(EXEEXT) \
+	sinfo_kappa_sigma_test$(EXEEXT) sinfo_efficiency_test$(EXEEXT) \
+	sinfo_gauss_fit_test$(EXEEXT) sinfo_star_index_test$(EXEEXT) \
+	sinfo_star_catalog$(EXEEXT) sinfo_line_corr_test$(EXEEXT) \
+	test_atmo_disp$(EXEEXT)
+subdir = sinfoni/tests
+DIST_COMMON = $(noinst_HEADERS) $(srcdir)/Makefile.am \
+	$(srcdir)/Makefile.in
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/m4macros/cpl.m4 \
+	$(top_srcdir)/m4macros/eso.m4 \
+	$(top_srcdir)/m4macros/libtool.m4 \
+	$(top_srcdir)/m4macros/ltoptions.m4 \
+	$(top_srcdir)/m4macros/ltsugar.m4 \
+	$(top_srcdir)/m4macros/ltversion.m4 \
+	$(top_srcdir)/m4macros/lt~obsolete.m4 \
+	$(top_srcdir)/m4macros/purify.m4 $(top_srcdir)/acinclude.m4 \
+	$(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+	$(ACLOCAL_M4)
+mkinstalldirs = $(install_sh) -d
+CONFIG_HEADER = $(top_builddir)/config.h
+CONFIG_CLEAN_FILES =
+CONFIG_CLEAN_VPATH_FILES =
+am_sinfo_cube_coadd_test_OBJECTS = sinfo_cube_coadd_test.$(OBJEXT)
+sinfo_cube_coadd_test_OBJECTS = $(am_sinfo_cube_coadd_test_OBJECTS)
+sinfo_cube_coadd_test_LDADD = $(LDADD)
+am__DEPENDENCIES_1 =
+sinfo_cube_coadd_test_DEPENDENCIES = $(am__DEPENDENCIES_1)
+am_sinfo_cube_ops_test_OBJECTS = sinfo_cube_ops_test.$(OBJEXT)
+sinfo_cube_ops_test_OBJECTS = $(am_sinfo_cube_ops_test_OBJECTS)
+sinfo_cube_ops_test_LDADD = $(LDADD)
+sinfo_cube_ops_test_DEPENDENCIES = $(am__DEPENDENCIES_1)
+am_sinfo_efficiency_test_OBJECTS = sinfo_efficiency_test.$(OBJEXT)
+sinfo_efficiency_test_OBJECTS = $(am_sinfo_efficiency_test_OBJECTS)
+sinfo_efficiency_test_LDADD = $(LDADD)
+sinfo_efficiency_test_DEPENDENCIES = $(am__DEPENDENCIES_1)
+am_sinfo_gauss_fit_test_OBJECTS = sinfo_gauss_fit_test.$(OBJEXT)
+sinfo_gauss_fit_test_OBJECTS = $(am_sinfo_gauss_fit_test_OBJECTS)
+sinfo_gauss_fit_test_LDADD = $(LDADD)
+sinfo_gauss_fit_test_DEPENDENCIES = $(am__DEPENDENCIES_1)
+am_sinfo_image_ops_test_OBJECTS = sinfo_image_ops_test.$(OBJEXT)
+sinfo_image_ops_test_OBJECTS = $(am_sinfo_image_ops_test_OBJECTS)
+sinfo_image_ops_test_LDADD = $(LDADD)
+sinfo_image_ops_test_DEPENDENCIES = $(am__DEPENDENCIES_1)
+am_sinfo_kappa_sigma_test_OBJECTS = sinfo_kappa_sigma_test.$(OBJEXT)
+sinfo_kappa_sigma_test_OBJECTS = $(am_sinfo_kappa_sigma_test_OBJECTS)
+sinfo_kappa_sigma_test_LDADD = $(LDADD)
+sinfo_kappa_sigma_test_DEPENDENCIES = $(am__DEPENDENCIES_1)
+am_sinfo_line_corr_test_OBJECTS = sinfo_line_corr_test.$(OBJEXT)
+sinfo_line_corr_test_OBJECTS = $(am_sinfo_line_corr_test_OBJECTS)
+sinfo_line_corr_test_LDADD = $(LDADD)
+sinfo_line_corr_test_DEPENDENCIES = $(am__DEPENDENCIES_1)
+am_sinfo_skycor_test_OBJECTS = sinfo_skycor_test.$(OBJEXT)
+sinfo_skycor_test_OBJECTS = $(am_sinfo_skycor_test_OBJECTS)
+sinfo_skycor_test_LDADD = $(LDADD)
+sinfo_skycor_test_DEPENDENCIES = $(am__DEPENDENCIES_1)
+am_sinfo_star_catalog_OBJECTS = sinfo_star_catalog.$(OBJEXT)
+sinfo_star_catalog_OBJECTS = $(am_sinfo_star_catalog_OBJECTS)
+sinfo_star_catalog_LDADD = $(LDADD)
+sinfo_star_catalog_DEPENDENCIES = $(am__DEPENDENCIES_1)
+am_sinfo_star_index_test_OBJECTS = sinfo_star_index_test.$(OBJEXT)
+sinfo_star_index_test_OBJECTS = $(am_sinfo_star_index_test_OBJECTS)
+sinfo_star_index_test_LDADD = $(LDADD)
+sinfo_star_index_test_DEPENDENCIES = $(am__DEPENDENCIES_1)
+am_sinfo_strehl_test_OBJECTS = sinfo_strehl_test.$(OBJEXT)
+sinfo_strehl_test_OBJECTS = $(am_sinfo_strehl_test_OBJECTS)
+sinfo_strehl_test_LDADD = $(LDADD)
+sinfo_strehl_test_DEPENDENCIES = $(am__DEPENDENCIES_1)
+am_sinfo_table_ops_test_OBJECTS = sinfo_table_ops_test.$(OBJEXT)
+sinfo_table_ops_test_OBJECTS = $(am_sinfo_table_ops_test_OBJECTS)
+sinfo_table_ops_test_LDADD = $(LDADD)
+sinfo_table_ops_test_DEPENDENCIES = $(am__DEPENDENCIES_1)
+am_test_atmo_disp_OBJECTS = test_atmo_disp.$(OBJEXT)
+test_atmo_disp_OBJECTS = $(am_test_atmo_disp_OBJECTS)
+test_atmo_disp_LDADD = $(LDADD)
+test_atmo_disp_DEPENDENCIES = $(am__DEPENDENCIES_1)
+DEFAULT_INCLUDES = -I. at am__isrc@ -I$(top_builddir)
+depcomp = $(SHELL) $(top_srcdir)/admin/depcomp
+am__depfiles_maybe = depfiles
+am__mv = mv -f
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+	--mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
+	$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+CCLD = $(CC)
+LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+	--mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
+	$(LDFLAGS) -o $@
+SOURCES = $(sinfo_cube_coadd_test_SOURCES) \
+	$(sinfo_cube_ops_test_SOURCES) \
+	$(sinfo_efficiency_test_SOURCES) \
+	$(sinfo_gauss_fit_test_SOURCES) \
+	$(sinfo_image_ops_test_SOURCES) \
+	$(sinfo_kappa_sigma_test_SOURCES) \
+	$(sinfo_line_corr_test_SOURCES) $(sinfo_skycor_test_SOURCES) \
+	$(sinfo_star_catalog_SOURCES) $(sinfo_star_index_test_SOURCES) \
+	$(sinfo_strehl_test_SOURCES) $(sinfo_table_ops_test_SOURCES) \
+	$(test_atmo_disp_SOURCES)
+DIST_SOURCES = $(sinfo_cube_coadd_test_SOURCES) \
+	$(sinfo_cube_ops_test_SOURCES) \
+	$(sinfo_efficiency_test_SOURCES) \
+	$(sinfo_gauss_fit_test_SOURCES) \
+	$(sinfo_image_ops_test_SOURCES) \
+	$(sinfo_kappa_sigma_test_SOURCES) \
+	$(sinfo_line_corr_test_SOURCES) $(sinfo_skycor_test_SOURCES) \
+	$(sinfo_star_catalog_SOURCES) $(sinfo_star_index_test_SOURCES) \
+	$(sinfo_strehl_test_SOURCES) $(sinfo_table_ops_test_SOURCES) \
+	$(test_atmo_disp_SOURCES)
+HEADERS = $(noinst_HEADERS)
+ETAGS = etags
+CTAGS = ctags
+am__tty_colors = \
+red=; grn=; lgn=; blu=; std=
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+ACLOCAL = @ACLOCAL@
+AMTAR = @AMTAR@
+AR = @AR@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CPL_INCLUDES = @CPL_INCLUDES@
+CPL_LDFLAGS = @CPL_LDFLAGS@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CX_INCLUDES = @CX_INCLUDES@
+CX_LDFLAGS = @CX_LDFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+DOXYGEN = @DOXYGEN@
+DSYMUTIL = @DSYMUTIL@
+DUMPBIN = @DUMPBIN@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+ESO_DEBUG_FLAGS = @ESO_DEBUG_FLAGS@
+EXEEXT = @EXEEXT@
+FGREP = @FGREP@
+GREP = @GREP@
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+IRPLIB_INCLUDES = @IRPLIB_INCLUDES@
+IRPLIB_LDFLAGS = @IRPLIB_LDFLAGS@
+LATEX = @LATEX@
+LD = @LD@
+LDFLAGS = @LDFLAGS@
+LIBCEXT = @LIBCEXT@
+LIBCPLCORE = @LIBCPLCORE@
+LIBCPLDFS = @LIBCPLDFS@
+LIBCPLDRS = @LIBCPLDRS@
+LIBCPLUI = @LIBCPLUI@
+LIBIRPLIB = @LIBIRPLIB@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LIBSINFONI = @LIBSINFONI@
+LIBTOOL = @LIBTOOL@
+LIBTOOL_DEPS = @LIBTOOL_DEPS@
+LIPO = @LIPO@
+LN_S = @LN_S@
+LTLIBOBJS = @LTLIBOBJS@
+LT_AGE = @LT_AGE@
+LT_CURRENT = @LT_CURRENT@
+LT_REVISION = @LT_REVISION@
+MAINT = @MAINT@
+MAKEINFO = @MAKEINFO@
+MKDIR_P = @MKDIR_P@
+NM = @NM@
+NMEDIT = @NMEDIT@
+OBJDUMP = @OBJDUMP@
+OBJEXT = @OBJEXT@
+OTOOL = @OTOOL@
+OTOOL64 = @OTOOL64@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+PURIFY_CMD = @PURIFY_CMD@
+RANLIB = @RANLIB@
+SED = @SED@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+SINFONI_BINARY_AGE = @SINFONI_BINARY_AGE@
+SINFONI_BINARY_VERSION = @SINFONI_BINARY_VERSION@
+SINFONI_INCLUDES = @SINFONI_INCLUDES@
+SINFONI_INTERFACE_AGE = @SINFONI_INTERFACE_AGE@
+SINFONI_LDFLAGS = @SINFONI_LDFLAGS@
+SINFONI_MAJOR_VERSION = @SINFONI_MAJOR_VERSION@
+SINFONI_MICRO_VERSION = @SINFONI_MICRO_VERSION@
+SINFONI_MINOR_VERSION = @SINFONI_MINOR_VERSION@
+SINFONI_VERSION = @SINFONI_VERSION@
+STRIP = @STRIP@
+VERSION = @VERSION@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
+all_includes = @all_includes@
+all_ldflags = @all_ldflags@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build = @build@
+build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
+builddir = @builddir@
+configdir = @configdir@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
+exec_prefix = @exec_prefix@
+host = @host@
+host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localedir = @localedir@
+localstatedir = @localstatedir@
+lt_ECHO = @lt_ECHO@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+pipedocsdir = @pipedocsdir@
+plugindir = @plugindir@
+prefix = @prefix@
+privatelibdir = @privatelibdir@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
+sysconfdir = @sysconfdir@
+target = @target@
+target_alias = @target_alias@
+target_cpu = @target_cpu@
+target_os = @target_os@
+target_vendor = @target_vendor@
+top_build_prefix = @top_build_prefix@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+AUTOMAKE_OPTIONS = 1.6 foreign
+DISTCLEANFILES = *~ .logfile
+ at MAINTAINER_MODE_TRUE@MAINTAINERCLEANFILES = Makefile.in
+
+#LIBSINFONI = $(top_builddir)/sinfoni/libsinfo.la
+
+#INCLUDES = -I$(top_builddir)/sinfoni -I$(top_builddir)/irplib
+INCLUDES = $(all_includes)
+LDADD = $(LIBSINFONI)
+AM_LDFLAGS = -static
+noinst_HEADERS = 
+sinfo_skycor_test_SOURCES = sinfo_skycor_test.c 
+sinfo_strehl_test_SOURCES = sinfo_strehl_test.c
+sinfo_cube_coadd_test_SOURCES = sinfo_cube_coadd_test.c
+sinfo_image_ops_test_SOURCES = sinfo_image_ops_test.c
+sinfo_cube_ops_test_SOURCES = sinfo_cube_ops_test.c
+sinfo_table_ops_test_SOURCES = sinfo_table_ops_test.c
+sinfo_kappa_sigma_test_SOURCES = sinfo_kappa_sigma_test.c
+sinfo_efficiency_test_SOURCES = sinfo_efficiency_test.c
+sinfo_gauss_fit_test_SOURCES = sinfo_gauss_fit_test.c
+sinfo_star_index_test_SOURCES = sinfo_star_index_test.c
+sinfo_star_catalog_SOURCES = sinfo_star_catalog.c
+sinfo_line_corr_test_SOURCES = sinfo_line_corr_test.c
+test_atmo_disp_SOURCES = test_atmo_disp.c
+# Be sure to reexport important environment variables.
+TESTS_ENVIRONMENT = MAKE="$(MAKE)" CC="$(CC)" CFLAGS="$(CFLAGS)" \
+        CPPFLAGS="$(CPPFLAGS)" LD="$(LD)" LDFLAGS="$(LDFLAGS)" \
+        LIBS="$(LIBS)" LN_S="$(LN_S)" NM="$(NM)" RANLIB="$(RANLIB)" \
+        OBJEXT="$(OBJEXT)" EXEEXT="$(EXEEXT)"
+
+all: all-am
+
+.SUFFIXES:
+.SUFFIXES: .c .lo .o .obj
+$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am  $(am__configure_deps)
+	@for dep in $?; do \
+	  case '$(am__configure_deps)' in \
+	    *$$dep*) \
+	      ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+	        && { if test -f $@; then exit 0; else break; fi; }; \
+	      exit 1;; \
+	  esac; \
+	done; \
+	echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign sinfoni/tests/Makefile'; \
+	$(am__cd) $(top_srcdir) && \
+	  $(AUTOMAKE) --foreign sinfoni/tests/Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+	@case '$?' in \
+	  *config.status*) \
+	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+	  *) \
+	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
+	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+	esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(am__aclocal_m4_deps):
+
+clean-checkPROGRAMS:
+	@list='$(check_PROGRAMS)'; test -n "$$list" || exit 0; \
+	echo " rm -f" $$list; \
+	rm -f $$list || exit $$?; \
+	test -n "$(EXEEXT)" || exit 0; \
+	list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \
+	echo " rm -f" $$list; \
+	rm -f $$list
+sinfo_cube_coadd_test$(EXEEXT): $(sinfo_cube_coadd_test_OBJECTS) $(sinfo_cube_coadd_test_DEPENDENCIES) 
+	@rm -f sinfo_cube_coadd_test$(EXEEXT)
+	$(LINK) $(sinfo_cube_coadd_test_OBJECTS) $(sinfo_cube_coadd_test_LDADD) $(LIBS)
+sinfo_cube_ops_test$(EXEEXT): $(sinfo_cube_ops_test_OBJECTS) $(sinfo_cube_ops_test_DEPENDENCIES) 
+	@rm -f sinfo_cube_ops_test$(EXEEXT)
+	$(LINK) $(sinfo_cube_ops_test_OBJECTS) $(sinfo_cube_ops_test_LDADD) $(LIBS)
+sinfo_efficiency_test$(EXEEXT): $(sinfo_efficiency_test_OBJECTS) $(sinfo_efficiency_test_DEPENDENCIES) 
+	@rm -f sinfo_efficiency_test$(EXEEXT)
+	$(LINK) $(sinfo_efficiency_test_OBJECTS) $(sinfo_efficiency_test_LDADD) $(LIBS)
+sinfo_gauss_fit_test$(EXEEXT): $(sinfo_gauss_fit_test_OBJECTS) $(sinfo_gauss_fit_test_DEPENDENCIES) 
+	@rm -f sinfo_gauss_fit_test$(EXEEXT)
+	$(LINK) $(sinfo_gauss_fit_test_OBJECTS) $(sinfo_gauss_fit_test_LDADD) $(LIBS)
+sinfo_image_ops_test$(EXEEXT): $(sinfo_image_ops_test_OBJECTS) $(sinfo_image_ops_test_DEPENDENCIES) 
+	@rm -f sinfo_image_ops_test$(EXEEXT)
+	$(LINK) $(sinfo_image_ops_test_OBJECTS) $(sinfo_image_ops_test_LDADD) $(LIBS)
+sinfo_kappa_sigma_test$(EXEEXT): $(sinfo_kappa_sigma_test_OBJECTS) $(sinfo_kappa_sigma_test_DEPENDENCIES) 
+	@rm -f sinfo_kappa_sigma_test$(EXEEXT)
+	$(LINK) $(sinfo_kappa_sigma_test_OBJECTS) $(sinfo_kappa_sigma_test_LDADD) $(LIBS)
+sinfo_line_corr_test$(EXEEXT): $(sinfo_line_corr_test_OBJECTS) $(sinfo_line_corr_test_DEPENDENCIES) 
+	@rm -f sinfo_line_corr_test$(EXEEXT)
+	$(LINK) $(sinfo_line_corr_test_OBJECTS) $(sinfo_line_corr_test_LDADD) $(LIBS)
+sinfo_skycor_test$(EXEEXT): $(sinfo_skycor_test_OBJECTS) $(sinfo_skycor_test_DEPENDENCIES) 
+	@rm -f sinfo_skycor_test$(EXEEXT)
+	$(LINK) $(sinfo_skycor_test_OBJECTS) $(sinfo_skycor_test_LDADD) $(LIBS)
+sinfo_star_catalog$(EXEEXT): $(sinfo_star_catalog_OBJECTS) $(sinfo_star_catalog_DEPENDENCIES) 
+	@rm -f sinfo_star_catalog$(EXEEXT)
+	$(LINK) $(sinfo_star_catalog_OBJECTS) $(sinfo_star_catalog_LDADD) $(LIBS)
+sinfo_star_index_test$(EXEEXT): $(sinfo_star_index_test_OBJECTS) $(sinfo_star_index_test_DEPENDENCIES) 
+	@rm -f sinfo_star_index_test$(EXEEXT)
+	$(LINK) $(sinfo_star_index_test_OBJECTS) $(sinfo_star_index_test_LDADD) $(LIBS)
+sinfo_strehl_test$(EXEEXT): $(sinfo_strehl_test_OBJECTS) $(sinfo_strehl_test_DEPENDENCIES) 
+	@rm -f sinfo_strehl_test$(EXEEXT)
+	$(LINK) $(sinfo_strehl_test_OBJECTS) $(sinfo_strehl_test_LDADD) $(LIBS)
+sinfo_table_ops_test$(EXEEXT): $(sinfo_table_ops_test_OBJECTS) $(sinfo_table_ops_test_DEPENDENCIES) 
+	@rm -f sinfo_table_ops_test$(EXEEXT)
+	$(LINK) $(sinfo_table_ops_test_OBJECTS) $(sinfo_table_ops_test_LDADD) $(LIBS)
+test_atmo_disp$(EXEEXT): $(test_atmo_disp_OBJECTS) $(test_atmo_disp_DEPENDENCIES) 
+	@rm -f test_atmo_disp$(EXEEXT)
+	$(LINK) $(test_atmo_disp_OBJECTS) $(test_atmo_disp_LDADD) $(LIBS)
+
+mostlyclean-compile:
+	-rm -f *.$(OBJEXT)
+
+distclean-compile:
+	-rm -f *.tab.c
+
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_cube_coadd_test.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_cube_ops_test.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_efficiency_test.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_gauss_fit_test.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_image_ops_test.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_kappa_sigma_test.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_line_corr_test.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_skycor_test.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_star_catalog.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_star_index_test.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_strehl_test.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sinfo_table_ops_test.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/test_atmo_disp.Po at am__quote@
+
+.c.o:
+ at am__fastdepCC_TRUE@	$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+ at am__fastdepCC_TRUE@	$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCC_FALSE@	$(COMPILE) -c $<
+
+.c.obj:
+ at am__fastdepCC_TRUE@	$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
+ at am__fastdepCC_TRUE@	$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCC_FALSE@	$(COMPILE) -c `$(CYGPATH_W) '$<'`
+
+.c.lo:
+ at am__fastdepCC_TRUE@	$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+ at am__fastdepCC_TRUE@	$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCC_FALSE@	$(LTCOMPILE) -c -o $@ $<
+
+mostlyclean-libtool:
+	-rm -f *.lo
+
+clean-libtool:
+	-rm -rf .libs _libs
+
+ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
+	list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	mkid -fID $$unique
+tags: TAGS
+
+TAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
+		$(TAGS_FILES) $(LISP)
+	set x; \
+	here=`pwd`; \
+	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	shift; \
+	if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
+	  test -n "$$unique" || unique=$$empty_fix; \
+	  if test $$# -gt 0; then \
+	    $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+	      "$$@" $$unique; \
+	  else \
+	    $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+	      $$unique; \
+	  fi; \
+	fi
+ctags: CTAGS
+CTAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
+		$(TAGS_FILES) $(LISP)
+	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	test -z "$(CTAGS_ARGS)$$unique" \
+	  || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+	     $$unique
+
+GTAGS:
+	here=`$(am__cd) $(top_builddir) && pwd` \
+	  && $(am__cd) $(top_srcdir) \
+	  && gtags -i $(GTAGS_ARGS) "$$here"
+
+distclean-tags:
+	-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+
+check-TESTS: $(TESTS)
+	@failed=0; all=0; xfail=0; xpass=0; skip=0; \
+	srcdir=$(srcdir); export srcdir; \
+	list=' $(TESTS) '; \
+	$(am__tty_colors); \
+	if test -n "$$list"; then \
+	  for tst in $$list; do \
+	    if test -f ./$$tst; then dir=./; \
+	    elif test -f $$tst; then dir=; \
+	    else dir="$(srcdir)/"; fi; \
+	    if $(TESTS_ENVIRONMENT) $${dir}$$tst; then \
+	      all=`expr $$all + 1`; \
+	      case " $(XFAIL_TESTS) " in \
+	      *[\ \	]$$tst[\ \	]*) \
+		xpass=`expr $$xpass + 1`; \
+		failed=`expr $$failed + 1`; \
+		col=$$red; res=XPASS; \
+	      ;; \
+	      *) \
+		col=$$grn; res=PASS; \
+	      ;; \
+	      esac; \
+	    elif test $$? -ne 77; then \
+	      all=`expr $$all + 1`; \
+	      case " $(XFAIL_TESTS) " in \
+	      *[\ \	]$$tst[\ \	]*) \
+		xfail=`expr $$xfail + 1`; \
+		col=$$lgn; res=XFAIL; \
+	      ;; \
+	      *) \
+		failed=`expr $$failed + 1`; \
+		col=$$red; res=FAIL; \
+	      ;; \
+	      esac; \
+	    else \
+	      skip=`expr $$skip + 1`; \
+	      col=$$blu; res=SKIP; \
+	    fi; \
+	    echo "$${col}$$res$${std}: $$tst"; \
+	  done; \
+	  if test "$$all" -eq 1; then \
+	    tests="test"; \
+	    All=""; \
+	  else \
+	    tests="tests"; \
+	    All="All "; \
+	  fi; \
+	  if test "$$failed" -eq 0; then \
+	    if test "$$xfail" -eq 0; then \
+	      banner="$$All$$all $$tests passed"; \
+	    else \
+	      if test "$$xfail" -eq 1; then failures=failure; else failures=failures; fi; \
+	      banner="$$All$$all $$tests behaved as expected ($$xfail expected $$failures)"; \
+	    fi; \
+	  else \
+	    if test "$$xpass" -eq 0; then \
+	      banner="$$failed of $$all $$tests failed"; \
+	    else \
+	      if test "$$xpass" -eq 1; then passes=pass; else passes=passes; fi; \
+	      banner="$$failed of $$all $$tests did not behave as expected ($$xpass unexpected $$passes)"; \
+	    fi; \
+	  fi; \
+	  dashes="$$banner"; \
+	  skipped=""; \
+	  if test "$$skip" -ne 0; then \
+	    if test "$$skip" -eq 1; then \
+	      skipped="($$skip test was not run)"; \
+	    else \
+	      skipped="($$skip tests were not run)"; \
+	    fi; \
+	    test `echo "$$skipped" | wc -c` -le `echo "$$banner" | wc -c` || \
+	      dashes="$$skipped"; \
+	  fi; \
+	  report=""; \
+	  if test "$$failed" -ne 0 && test -n "$(PACKAGE_BUGREPORT)"; then \
+	    report="Please report to $(PACKAGE_BUGREPORT)"; \
+	    test `echo "$$report" | wc -c` -le `echo "$$banner" | wc -c` || \
+	      dashes="$$report"; \
+	  fi; \
+	  dashes=`echo "$$dashes" | sed s/./=/g`; \
+	  if test "$$failed" -eq 0; then \
+	    echo "$$grn$$dashes"; \
+	  else \
+	    echo "$$red$$dashes"; \
+	  fi; \
+	  echo "$$banner"; \
+	  test -z "$$skipped" || echo "$$skipped"; \
+	  test -z "$$report" || echo "$$report"; \
+	  echo "$$dashes$$std"; \
+	  test "$$failed" -eq 0; \
+	else :; fi
+
+distdir: $(DISTFILES)
+	@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+	topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+	list='$(DISTFILES)'; \
+	  dist_files=`for file in $$list; do echo $$file; done | \
+	  sed -e "s|^$$srcdirstrip/||;t" \
+	      -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+	case $$dist_files in \
+	  */*) $(MKDIR_P) `echo "$$dist_files" | \
+			   sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+			   sort -u` ;; \
+	esac; \
+	for file in $$dist_files; do \
+	  if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+	  if test -d $$d/$$file; then \
+	    dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+	    if test -d "$(distdir)/$$file"; then \
+	      find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+	    fi; \
+	    if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+	      cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
+	      find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+	    fi; \
+	    cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
+	  else \
+	    test -f "$(distdir)/$$file" \
+	    || cp -p $$d/$$file "$(distdir)/$$file" \
+	    || exit 1; \
+	  fi; \
+	done
+check-am: all-am
+	$(MAKE) $(AM_MAKEFLAGS) $(check_PROGRAMS)
+	$(MAKE) $(AM_MAKEFLAGS) check-TESTS
+check: check-am
+all-am: Makefile $(HEADERS)
+installdirs:
+install: install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+	@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+	$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+	  install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+	  `test -z '$(STRIP)' || \
+	    echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+	-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+	-test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
+	-test -z "$(DISTCLEANFILES)" || rm -f $(DISTCLEANFILES)
+
+maintainer-clean-generic:
+	@echo "This command is intended for maintainers to use"
+	@echo "it deletes files that may require special tools to rebuild."
+	-test -z "$(MAINTAINERCLEANFILES)" || rm -f $(MAINTAINERCLEANFILES)
+clean: clean-am
+
+clean-am: clean-checkPROGRAMS clean-generic clean-libtool clean-local \
+	mostlyclean-am
+
+distclean: distclean-am
+	-rm -rf ./$(DEPDIR)
+	-rm -f Makefile
+distclean-am: clean-am distclean-compile distclean-generic \
+	distclean-tags
+
+dvi: dvi-am
+
+dvi-am:
+
+html: html-am
+
+html-am:
+
+info: info-am
+
+info-am:
+
+install-data-am:
+
+install-dvi: install-dvi-am
+
+install-dvi-am:
+
+install-exec-am:
+
+install-html: install-html-am
+
+install-html-am:
+
+install-info: install-info-am
+
+install-info-am:
+
+install-man:
+
+install-pdf: install-pdf-am
+
+install-pdf-am:
+
+install-ps: install-ps-am
+
+install-ps-am:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+	-rm -rf ./$(DEPDIR)
+	-rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-compile mostlyclean-generic \
+	mostlyclean-libtool
+
+pdf: pdf-am
+
+pdf-am:
+
+ps: ps-am
+
+ps-am:
+
+uninstall-am:
+
+.MAKE: check-am install-am install-strip
+
+.PHONY: CTAGS GTAGS all all-am check check-TESTS check-am clean \
+	clean-checkPROGRAMS clean-generic clean-libtool clean-local \
+	ctags distclean distclean-compile distclean-generic \
+	distclean-libtool distclean-tags distdir dvi dvi-am html \
+	html-am info info-am install install-am install-data \
+	install-data-am install-dvi install-dvi-am install-exec \
+	install-exec-am install-html install-html-am install-info \
+	install-info-am install-man install-pdf install-pdf-am \
+	install-ps install-ps-am install-strip installcheck \
+	installcheck-am installdirs maintainer-clean \
+	maintainer-clean-generic mostlyclean mostlyclean-compile \
+	mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
+	tags uninstall uninstall-am
+
+
+ at PURIFY_TRUE@include $(top_builddir)/Makefile.purify 
+
+# We need to remove any files that the above tests created.
+clean-local:
+	 $(RM) *.fits *.log
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/sinfoni/tests/sinfo_cube_coadd_test.c b/sinfoni/tests/sinfo_cube_coadd_test.c
new file mode 100644
index 0000000..28467fc
--- /dev/null
+++ b/sinfoni/tests/sinfo_cube_coadd_test.c
@@ -0,0 +1,622 @@
+/*                                                                            *
+ *   This file is part of the ESO SINFO Pipeline                              *
+ *   Copyright (C) 2004,2005 European Southern Observatory                    *
+ *                                                                            *
+ *   This library is free software; you can redistribute it and/or modify     *
+ *   it under the terms of the GNU General Public License as published by     *
+ *   the Free Software Foundation; either version 2 of the License, or        *
+ *   (at your option) any later version.                                      *
+ *                                                                            *
+ *   This program is distributed in the hope that it will be useful,          *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of           *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
+ *   GNU General Public License for more details.                             *
+ *                                                                            *
+ *   You should have received a copy of the GNU General Public License        *
+ *   along with this program; if not, write to the Free Software              *
+ *   Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA     *
+ *                                                                            */
+ 
+/*
+ * $Author: amodigli $
+ * $Date: 2009/06/05 06:06:11 $
+ * $Revision: 1.9 $
+ * $Name: sinfo-2_3_2 $
+ * $Log: sinfo_cube_coadd_test.c,v $
+ * Revision 1.9  2009/06/05 06:06:11  amodigli
+ * updated init/end to cpl5
+ *
+ * Revision 1.8  2008/02/12 10:09:49  amodigli
+ * shortened lines
+ *
+ * Revision 1.7  2008/02/12 09:09:13  amodigli
+ * updated sinfo_cube_coadd_test
+ *
+ * Revision 1.6  2007/08/14 06:04:40  amodigli
+ * activate synthetic test
+ *
+ * Revision 1.5  2007/08/11 10:42:46  amodigli
+ * make test work
+ *
+ * Revision 1.4  2007/08/10 08:50:21  amodigli
+ * added some more comments
+ *
+ * Revision 1.3  2007/08/10 08:10:03  amodigli
+ * updated cube test
+ *
+ * Revision 1.2  2007/08/10 06:36:47  amodigli
+ * fixed leaks
+ *
+ * Revision 1.1  2007/08/09 13:00:31  amodigli
+ * added to repository
+ *
+ * Revision 1.2  2007/03/27 14:38:48  amodigli
+ * fixed compilation warnings
+ *
+ * Revision 1.1  2007/02/23 13:10:24  amodigli
+ * added test
+ *
+ */
+
+/*-----------------------------------------------------------------------------
+                                Includes
+ -----------------------------------------------------------------------------*/
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+#include <stdio.h>
+#include <cpl.h>
+#include <cpl_test.h>
+#include <sinfo_pro_save.h>
+#include <sinfo_utilities_scired.h>
+#include <sinfo_error.h>
+#include <sinfo_msg.h>
+#include <sinfo_new_cube_ops.h>
+#include <sinfo_utils_wrappers.h>
+/*-----------------------------------------------------------------------------
+                                Defines
+ -----------------------------------------------------------------------------*/
+
+/*-----------------------------------------------------------------------------
+                            Functions prototypes
+ -----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------*/
+/**
+ * @defgroup sinfo_cube_coadd_test  SINFO library unit tests
+ */
+/*----------------------------------------------------------------------------*/
+/**@{*/
+   
+
+/**
+   @brief      test cube coaddition compuatation
+ */
+/*---------------------------------------------------------------------------*/
+#define SIZE 255
+static cpl_imagelist*
+sinfo_cube_gen_gauss2d_with_noise(const int sx, 
+                                 const int sy, 
+                                 const int sz, 
+				 const double xc,
+				 const double yc,
+		                 const double amp,
+                                 const double sigx,
+                                 const double sigy,
+                                 const double min_noise,
+                                 const double max_noise)
+{
+
+  int z=0;
+  cpl_imagelist* cube=NULL;
+  cpl_image* img_o=NULL;
+  cpl_image* img_s=NULL;
+  double a0=1;
+  double a1=-2;
+  double a2=1;
+  double x=100;
+  double y=0;
+
+  char name[SIZE];
+
+  sinfo_msg_warning("Prepare data cube with 2D Gauss");
+ 
+  cube=cpl_imagelist_new();
+  for(z=0;z<sz;z++) {
+    y =a0+a1*x*z+a2*x*z*z;
+    //sinfo_msg_warning("amp=%f",y);
+    check_nomsg(img_o=cpl_image_new(sx,sy,CPL_TYPE_FLOAT));
+    check_nomsg(img_s=cpl_image_new(sx,sy,CPL_TYPE_FLOAT));
+    check_nomsg(cpl_image_fill_gaussian(img_o,xc,yc,y,sigx,sigy));
+    check_nomsg(cpl_image_fill_noise_uniform(img_s,min_noise,max_noise));
+    check_nomsg(cpl_image_add(img_o,img_s));
+    sinfo_free_image(&img_s);
+    sprintf(name,"%s%d%s","img_",z,".fits");
+    check_nomsg(cpl_image_save(img_o,name,CPL_BPP_IEEE_FLOAT,
+			       NULL,CPL_IO_DEFAULT));
+    check_nomsg(cpl_imagelist_set(cube,img_o,z));
+  }
+
+
+ cleanup:
+  return cube;
+
+}
+
+
+
+
+/**
+   @brief      test cube coaddition compuatation
+ */
+/*---------------------------------------------------------------------------*/
+#define SIZE 255
+static void
+test_cube_coadd_gauss2d(void)
+{
+  int sx=64;
+  int sy=64;
+  int sz=16;
+  int nc=3;
+  int i=0;
+  int z=0;
+
+
+  int onp=0;
+
+  double xc0=sx/2;
+  double yc0=sy/2;
+  double xc=sx/2;
+  double yc=sy/2;
+  double sigx=sx/16;
+  double sigy=sy/16;
+  double min_noise=-1;
+  double max_noise=+1;
+  int z_siz=0;
+  int z_stp=8;
+  int z_min=0;
+  int z_max=0;
+  int kappa=2;
+  int j=0;
+
+  int vllx=0;
+  int vlly=0;
+  int vurx=0;
+  int vury=0;
+  int off=5;
+  double * times=NULL ;
+  float * offx=NULL;
+  float * offy=NULL;
+  float * roffx=NULL;
+  float * roffy=NULL;
+  float shftx=0;
+  float shfty=0;
+
+  float min_offx=0;
+  float min_offy=0;
+  float max_offx=0;
+  float max_offy=0;
+  float ref_offx=0;
+  float ref_offy=0;
+  int rsx=0;
+  int rsy=0;
+
+  cpl_imagelist* cube_out=NULL;
+  cpl_imagelist** cube_bas=NULL;
+  cpl_imagelist* cube_msk=NULL;
+
+  cpl_imagelist** cube_obj=NULL;
+  cpl_imagelist** cube_tmp=NULL;
+  double amp=1000;
+
+  cpl_image* img_o=NULL;
+  cpl_image* img_s=NULL;
+  cpl_image* img_m=NULL;
+  cpl_image* img_j=NULL;
+
+  char name[SIZE];
+  cknull(times = (double*) cpl_calloc (nc, sizeof (double)),
+	 " could not allocate memory!") ;
+ 
+  cknull(offx = (float*) cpl_calloc (nc, sizeof(float)),
+	 " could not allocate memory!") ;
+
+  cknull(offy = (float*) cpl_calloc (nc, sizeof(float)),
+	 " could not allocate memory!") ;
+
+
+  cknull(roffx = (float*) cpl_calloc (nc, sizeof(float)),
+	 " could not allocate memory!") ;
+
+  cknull(roffy = (float*) cpl_calloc (nc, sizeof(float)),
+	 " could not allocate memory!") ;
+
+  cknull(cube_bas = (cpl_imagelist**) cpl_calloc (nc,sizeof (cpl_imagelist*)),
+	 "Could not allocate memory for cube_out");
+    
+  sinfo_msg_warning("Prepare data cubes with 2D Gauss");
+  for(i=0;i<nc;i++) {
+    times[1]=1;
+    offx[i]=+off*i;
+    offy[i]=-off*i;
+    xc=xc0+offx[i];
+    yc=yc0+offy[i];
+
+    sinfo_msg_warning("xc0= %f %f, offset = %f %f xc= %f %f",
+		      xc0,yc0,offx[i],offy[i],xc,yc);
+    check_nomsg(cube_bas[i]=sinfo_cube_gen_gauss2d_with_noise(sx,sy,sz,xc,yc,
+							      amp,sigx,sigy,
+						              min_noise,
+							      max_noise));
+    sprintf(name,"%s%d%s","cub_bas",i,".fits");
+    check_nomsg(cpl_imagelist_save(cube_bas[i],name,CPL_BPP_IEEE_FLOAT,
+				   NULL,CPL_IO_DEFAULT));
+
+  }
+
+
+
+  //Get ref offset
+  for ( i = 0 ; i < nc ; i++ ) {
+     if(i==0) {
+      min_offx=offx[i];
+      min_offy=offy[i];
+      max_offx=offx[i];
+      max_offy=offy[i];
+    } else {
+      if(offx[i] > max_offx) max_offx=offx[i];
+      if(offy[i] > max_offy) max_offy=offy[i];
+      if(offx[i] < min_offx) min_offx=offx[i];
+      if(offy[i] < min_offy) min_offy=offy[i];
+    }
+  }
+  ref_offx=(min_offx+max_offx)/2;
+  ref_offy=(min_offy+max_offy)/2;
+
+  rsx=2*floor(max_offx-min_offx+0.5)+64;
+  rsy=2*floor(max_offy-min_offy+0.5)+64;
+  sinfo_msg_warning("Output cube size: %d x %d",rsx,rsy);
+
+  //reassign offsets
+  for ( i = 0 ; i < nc ; i++ ) {
+    shftx=offx[i]-ref_offx;
+    shfty=offy[i]-ref_offy;
+
+    sinfo_new_array_set_value(roffx,2*shftx,i);
+    sinfo_new_array_set_value(roffy,2*shfty,i);
+  }
+
+
+
+
+
+  sinfo_msg_warning("Allocate memory");
+
+  cknull(cube_tmp = (cpl_imagelist**) cpl_calloc (nc, sizeof (cpl_imagelist*)),
+	 "Could not allocate memory for cube_tmp");
+
+  cknull(cube_obj = (cpl_imagelist**) cpl_calloc (nc,sizeof (cpl_imagelist*)),
+	 "Could not allocate memory for cubeobject");
+
+  sinfo_msg_warning("Reload data");
+
+  for(i=0;i<nc;i++) {
+
+    sprintf(name,"%s%d%s","cub_bas",i,".fits");
+    check_nomsg(cube_tmp[i] = cpl_imagelist_load(name,CPL_TYPE_FLOAT,0));
+    sprintf(name,"%s%d%s","cub_load",i,".fits");
+    check_nomsg(cpl_imagelist_save(cube_tmp[i],name,CPL_BPP_IEEE_FLOAT,
+				   NULL,CPL_IO_DEFAULT));
+
+    check_nomsg(cube_obj[i] = sinfo_new_cube_getvig(cube_tmp[i],
+                                                    1+vllx,
+                                                    1+vlly,
+                                                    64-vurx,
+                                                    64-vury));
+    check_nomsg(sinfo_free_imagelist(&cube_tmp[i]));
+
+    sprintf(name,"%s%d%s","cub_object",i,".fits");
+    check_nomsg(cpl_imagelist_save(cube_obj[i],name,CPL_BPP_IEEE_FLOAT,
+				   NULL,CPL_IO_DEFAULT));
+  }
+
+
+  cknull(cube_msk=cpl_imagelist_new(),"could not allocate cube!");
+  cknull(cube_out=cpl_imagelist_new(),"could not allocate cube!");
+
+  check_nomsg(onp=cpl_imagelist_get_size(cube_obj[0]));
+
+
+  sinfo_msg_warning("Coadd data");
+
+  for(z=0;z<onp;z+=z_stp) {
+
+    z_siz=(z_stp < (onp-z)) ? z_stp : (onp-z);
+    z_min=z;
+    z_max=z_min+z_siz;
+    sinfo_msg("Coadding cubes: range [%4.4d,%4.4d) of 0-%d\n",z_min,z_max,onp);
+                          
+    for(j=z_min;j<z_max;j++) {
+      check_nomsg(img_j=cpl_image_new(rsx,rsy,CPL_TYPE_FLOAT));
+      check_nomsg(cpl_imagelist_set(cube_out,img_j,j)); 
+      check_nomsg(img_m = cpl_image_new(rsx,rsy,CPL_TYPE_FLOAT));
+      check_nomsg(cpl_imagelist_set(cube_msk,img_m,j));
+    }
+
+    sinfo_new_combine_jittered_cubes_thomas_range(cube_obj,
+						  cube_out,
+						  cube_msk,
+						  nc,
+						  roffx,
+                                                  roffy,
+						  times,
+						  "tanh",
+						  z_min,
+						  z_max,
+						  kappa);
+
+
+
+  }
+  sinfo_msg_warning("Save final products");
+
+  sprintf(name,"%s","cub_pro.fits");
+  check_nomsg(cpl_imagelist_save(cube_out,name,CPL_BPP_IEEE_FLOAT,
+				 NULL,CPL_IO_DEFAULT));
+
+  sprintf(name,"%s","cub_pro_msk.fits");
+  check_nomsg(cpl_imagelist_save(cube_msk,name,CPL_BPP_IEEE_FLOAT,
+				 NULL,CPL_IO_DEFAULT));
+
+
+ cleanup:
+
+  sinfo_free_float(&offy);
+  sinfo_free_float(&offx);
+  sinfo_free_float(&roffy);
+  sinfo_free_float(&roffx);
+
+  sinfo_free_double(&times);
+  sinfo_free_image(&img_s);
+  sinfo_free_image(&img_o);
+  sinfo_free_imagelist(&cube_out);
+  sinfo_free_imagelist(&cube_msk);
+
+  for ( i = 0 ; i <nc  ; i++ ) {
+
+     sinfo_free_imagelist(&cube_bas[i]);
+
+  }
+  sinfo_free_array_imagelist(&cube_bas);
+
+  //Free the memory
+  for ( i = 0 ; i <nc  ; i++ ) {
+      sinfo_free_imagelist(&cube_obj[i]);
+  }
+  sinfo_free_array_imagelist(&cube_obj);
+
+  sinfo_free_array_imagelist(&cube_tmp);
+
+  return;
+
+}
+
+
+
+
+
+
+/**
+   @brief      test cube coaddition compuatation
+ */
+/*---------------------------------------------------------------------------*/
+
+static void
+test_cube_coadd_data(void)
+{
+  int sx=64;
+  int sy=64;
+  int nc=1;
+  int i=0;
+  int z=0;
+
+
+  int onp=0;
+
+
+  int z_siz=0;
+  int z_stp=100;
+  int z_min=0;
+  int z_max=0;
+  int kappa=2;
+  int j=0;
+
+  int vllx=0;
+  int vlly=0;
+  int vurx=0;
+  int vury=0;
+
+  double * times=NULL ;
+  float * offx=NULL;
+  float * offy=NULL;
+
+  cpl_imagelist* cube_out=NULL;
+  cpl_imagelist* cube_tst=NULL;
+
+  cpl_imagelist** cube_bas=NULL;
+  cpl_imagelist* cube_msk=NULL;
+
+  cpl_imagelist** cube_obj=NULL;
+  cpl_imagelist** cube_tmp=NULL;
+
+
+  cpl_image* img_o=NULL;
+  cpl_image* img_s=NULL;
+  cpl_image* img_m=NULL;
+  cpl_image* img_j=NULL;
+
+  char name[SIZE];
+  //char* src_data="/data2/sinfoni/sinfo_demo/pro/sinfo_rec_jitter_objnod_358/";
+  char* src_data="/data2/sinfoni/sinfo_demo/test/ref/";
+
+
+  sinfo_msg_warning("allocate memory");
+  cknull(times = (double*) cpl_calloc (nc, sizeof (double)),
+	 " could not allocate memory!") ;
+ 
+  cknull(offx = (float*) cpl_calloc (nc, sizeof(float)),
+	 " could not allocate memory!") ;
+
+  cknull(offy = (float*) cpl_calloc (nc, sizeof(float)),
+	 " could not allocate memory!") ;
+
+
+  //We use input data generated by the pipeline
+  sprintf(name,"%s%s%2.2d%s",src_data,"out_cube_obj",i,"_cpl40.fits");
+  //sprintf(name,"%s%s%4.4d%s",src_data,"out_",12,".fits");
+  sinfo_msg_warning("name=%s",name);
+
+  check_nomsg(cube_tst = cpl_imagelist_load(name,CPL_TYPE_FLOAT,0));
+  sprintf(name,"%s","cub_tst.fits");
+  check_nomsg(cpl_imagelist_save(cube_tst,name,CPL_BPP_IEEE_FLOAT,
+				 NULL,CPL_IO_DEFAULT));
+
+  cknull(cube_tmp = (cpl_imagelist**) cpl_calloc (nc, sizeof (cpl_imagelist*)),
+	 "Could not allocate memory for cube_tmp");
+
+  cknull(cube_obj = (cpl_imagelist**) cpl_calloc (nc,sizeof (cpl_imagelist*)),
+	 "Could not allocate memory for cubeobject");
+
+  sinfo_msg_warning("Load pipe data");
+
+  for(i=0;i<nc;i++) {
+    times[i]=600;
+    offx[i]=0;
+    offy[i]=0;
+
+    sprintf(name,"%s%s%2.2d%s",src_data,"out_cube_obj",i,"_cpl40.fits");
+    //sprintf(name,"%s%s%4.4d%s",src_data,"out_",12,".fits");
+    sinfo_msg("name=%s",name);
+    check_nomsg(cube_tmp[i] = cpl_imagelist_load(name,CPL_TYPE_FLOAT,0));
+
+
+    sprintf(name,"%s%d%s","cub_load",i,".fits");
+    check_nomsg(cpl_imagelist_save(cube_tmp[i],name,CPL_BPP_IEEE_FLOAT,
+				   NULL,CPL_IO_DEFAULT));
+
+    check_nomsg(cube_obj[i] = sinfo_new_cube_getvig(cube_tmp[i],
+                                                    1+vllx,
+                                                    1+vlly,
+                                                    64-vurx,
+                                                    64-vury));
+    check_nomsg(sinfo_free_imagelist(&cube_tmp[i]));
+
+    sprintf(name,"%s%d%s","cub_object",i,".fits");
+    check_nomsg(cpl_imagelist_save(cube_obj[i],name,CPL_BPP_IEEE_FLOAT,
+                                   NULL,CPL_IO_DEFAULT));
+  }
+
+
+  cknull(cube_msk=cpl_imagelist_new(),"could not allocate cube!");
+  cknull(cube_out=cpl_imagelist_new(),"could not allocate cube!");
+
+  check_nomsg(onp=cpl_imagelist_get_size(cube_obj[0]));
+
+  sinfo_msg_warning("Shift pipe data");
+
+  for(z=0;z<onp;z+=z_stp) {
+
+    z_siz=(z_stp < (onp-z)) ? z_stp : (onp-z);
+    z_min=z;
+    z_max=z_min+z_siz;
+    sinfo_msg("Coadding cubes: range [%4.4d,%4.4d) of 0-%d\n",z_min,z_max,onp);
+                          
+    for(j=z_min;j<z_max;j++) {
+      check_nomsg(img_j=cpl_image_new(sx,sy,CPL_TYPE_FLOAT));
+      check_nomsg(cpl_imagelist_set(cube_out,img_j,j)); 
+      check_nomsg(img_m = cpl_image_new(sx,sy,CPL_TYPE_FLOAT));
+      check_nomsg(cpl_imagelist_set(cube_msk,img_m,j));
+    }
+
+    sinfo_new_combine_jittered_cubes_thomas_range(cube_obj,
+						  cube_out,
+						  cube_msk,
+						  nc,
+						  offx,
+                                                  offy,
+						  times,
+						  "tanh",
+						  z_min,
+						  z_max,
+						  kappa);
+
+
+
+  }
+
+  sinfo_msg_warning("Save final products");
+
+  sprintf(name,"%s","cub_pro.fits");
+  check_nomsg(cpl_imagelist_save(cube_out,name,CPL_BPP_IEEE_FLOAT,
+				 NULL,CPL_IO_DEFAULT));
+
+  sprintf(name,"%s","cub_pro_msk.fits");
+  check_nomsg(cpl_imagelist_save(cube_msk,name,CPL_BPP_IEEE_FLOAT,
+				 NULL,CPL_IO_DEFAULT));
+
+
+ cleanup:
+
+  sinfo_free_float(&offy);
+  sinfo_free_float(&offx);
+  sinfo_free_double(&times);
+
+  sinfo_free_image(&img_s);
+  sinfo_free_image(&img_o);
+  sinfo_free_imagelist(&cube_out);
+  sinfo_free_imagelist(&cube_msk);
+
+  for ( i = 0 ; i <nc  ; i++ ) {
+      sinfo_free_imagelist(&cube_bas[i]);
+  }
+  sinfo_free_array_imagelist(&cube_bas);
+
+
+  //Free the memory
+  for ( i = 0 ; i <nc  ; i++ ) {
+      sinfo_free_imagelist(&cube_obj[i]);
+  }
+  sinfo_free_array_imagelist(&cube_obj);
+
+  sinfo_free_array_imagelist(&cube_tmp);
+  sinfo_free_imagelist(&cube_tst);
+
+  return;
+
+}
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief   SINFONI pipeline unit test for cube coadd
+
+**/
+/*----------------------------------------------------------------------------*/
+
+int main(void)
+{
+  cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
+
+  /* Initialize CPL + SINFO messaging */
+  check(test_cube_coadd_gauss2d(),"Fail testing cube_gauss2d");
+  //check(test_cube_coadd_data(),"Fail testing cube_gauss2d");
+
+ cleanup:
+  return cpl_test_end(0);
+
+}
+
+
+/**@}*/
diff --git a/sinfoni/tests/sinfo_cube_ops_test.c b/sinfoni/tests/sinfo_cube_ops_test.c
new file mode 100644
index 0000000..dc9817c
--- /dev/null
+++ b/sinfoni/tests/sinfo_cube_ops_test.c
@@ -0,0 +1,153 @@
+/*                                                                            *
+ *   This file is part of the ESO SINFO Pipeline                              *
+ *   Copyright (C) 2004,2005 European Southern Observatory                    *
+ *                                                                            *
+ *   This library is free software; you can redistribute it and/or modify     *
+ *   it under the terms of the GNU General Public License as published by     *
+ *   the Free Software Foundation; either version 2 of the License, or        *
+ *   (at your option) any later version.                                      *
+ *                                                                            *
+ *   This program is distributed in the hope that it will be useful,          *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of           *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
+ *   GNU General Public License for more details.                             *
+ *                                                                            *
+ *   You should have received a copy of the GNU General Public License        *
+ *   along with this program; if not, write to the Free Software              *
+ *   Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA     *
+ *                                                                           */
+ 
+/*
+ * $Author: amodigli $
+ * $Date: 2009/06/05 06:06:11 $
+ * $Revision: 1.6 $
+ * $Name: sinfo-2_3_2 $
+ * $Log: sinfo_cube_ops_test.c,v $
+ * Revision 1.6  2009/06/05 06:06:11  amodigli
+ * updated init/end to cpl5
+ *
+ * Revision 1.5  2008/02/12 10:09:49  amodigli
+ * shortened lines
+ *
+ * Revision 1.4  2007/08/11 10:42:46  amodigli
+ * make test work
+ *
+ * Revision 1.3  2007/08/10 08:50:21  amodigli
+ * added some more comments
+ *
+ * Revision 1.2  2007/08/10 08:10:03  amodigli
+ * updated cube test
+ *
+ * Revision 1.1  2007/08/10 06:36:21  amodigli
+ * added to repository
+ *
+ * Revision 1.1  2007/08/09 13:00:31  amodigli
+ * added to repository
+ *
+ * Revision 1.2  2007/03/27 14:38:48  amodigli
+ * fixed compilation warnings
+ *
+ * Revision 1.1  2007/02/23 13:10:24  amodigli
+ * added test
+ *
+ */
+
+/*-----------------------------------------------------------------------------
+                                Includes
+ -----------------------------------------------------------------------------*/
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+#include <stdio.h>
+#include <cpl.h>
+#include <cpl_test.h>
+#include <sinfo_pro_save.h>
+#include <sinfo_error.h>
+#include <sinfo_msg.h>
+#include <sinfo_utils_wrappers.h>
+/*-----------------------------------------------------------------------------
+                                Defines
+ -----------------------------------------------------------------------------*/
+
+/*-----------------------------------------------------------------------------
+                            Functions prototypes
+ -----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------*/
+/**
+ * @defgroup sinfo_cube_ops_test  SINFO library unit tests
+ */
+#define SIZE 256
+/*----------------------------------------------------------------------------*/
+/**@{*/
+   
+
+
+/**
+   @brief      test cube load
+ */
+/*---------------------------------------------------------------------------*/
+
+static void
+test_cube_load_data(void)
+{
+  cpl_imagelist* cube_tst=NULL;
+  cpl_image* img=NULL;
+  char name[SIZE];
+  int i=0;
+  int sz=0;
+  //char* src_data="/data2/sinfoni/sinfo_demo/pro/sinfo_rec_jitter_objnod_358/";
+  //char* src_data="/data2/sinfoni/sinfo_demo/test/";
+  char* src_data="/home/amodigli/pipeline/sinfonip/sinfoni/tests/";
+
+  //We use input data generated by the pipeline
+  //sprintf(name,"%s%s%2.2d%s",src_data,"out_cube_obj",i,".fits");
+  sprintf(name,"%s%s",src_data,"cub_bas0.fits");
+  sinfo_msg_warning("name=%s",name);
+  check_nomsg(cube_tst = cpl_imagelist_load(name,CPL_TYPE_FLOAT,0));
+  sz=cpl_imagelist_get_size(cube_tst);
+
+  for(i=sz/2;i<sz/2+10;i++) {
+    check_nomsg(img=cpl_imagelist_get(cube_tst,i));
+    sprintf(name,"%s%4.4d%s","ima_tst",i,".fits");
+    check_nomsg(cpl_image_save(img,name,CPL_BPP_IEEE_FLOAT,
+			       NULL,CPL_IO_DEFAULT));
+  }
+
+  sprintf(name,"%s","cub_tst.fits");
+  check_nomsg(cpl_imagelist_save(cube_tst,name,CPL_BPP_IEEE_FLOAT,
+				 NULL,CPL_IO_DEFAULT));
+  sinfo_msg_warning("Note that fails before this line");
+ cleanup:
+  sinfo_msg_warning("about to exit");
+
+  sinfo_free_imagelist(&cube_tst);
+
+  return;
+
+}
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  @brief   SINFONI pipeline unit test for cube load
+
+**/
+/*----------------------------------------------------------------------------*/
+
+int main(void)
+{
+  cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
+
+    /* Initialize CPL + SINFO messaging */
+  //check(test_cube_load_data(),"Fail testing cube_load");
+
+ cleanup:
+  return cpl_test_end(0);
+
+}
+
+
+/**@}*/
diff --git a/sinfoni/tests/sinfo_efficiency_test.c b/sinfoni/tests/sinfo_efficiency_test.c
new file mode 100644
index 0000000..6450e9b
--- /dev/null
+++ b/sinfoni/tests/sinfo_efficiency_test.c
@@ -0,0 +1,313 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004-2009 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*
+ * $Author: amodigli $
+ * $Date: 2010/02/08 07:20:41 $
+ * $Revision: 1.8 $
+ * $Log: sinfo_efficiency_test.c,v $
+ * Revision 1.8  2010/02/08 07:20:41  amodigli
+ * several changes to reflect efficiency functions API changes
+ *
+ * Revision 1.7  2010/01/14 14:09:14  amodigli
+ * added prefix sinfo_ to data_interpolate function call
+ *
+ * Revision 1.6  2009/06/19 14:37:58  kmirny
+ * star index implementation
+ *
+ * Revision 1.5  2009/06/16 15:13:43  kmirny
+ * fit gaussian test
+ *
+ * Revision 1.4  2009/06/15 08:17:12  kmirny
+ * put aimprim level up to prepared to use as a recipe parameter
+ *
+ * Revision 1.3  2009/06/10 14:58:31  kmirny
+ * sinfoni efficiency utility recipe
+ *
+ * Revision 1.2  2009/06/09 14:58:04  kmirny
+ * sinfoni efficiency unit test
+ *
+ * Revision 1.1  2009/06/09 08:57:18  kmirny
+ * adding test for sinfo_utl_efficiency
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#include <stdio.h>
+#include <cpl.h>
+#include <cpl_test.h>
+#include <sinfo_pro_save.h>
+#include <sinfo_error.h>
+#include <sinfo_msg.h>
+#include <sinfo_utils_wrappers.h>
+#include <sinfo_utl_efficiency.h>
+
+const float EPSILON = 1E-5;
+
+#define TEST_SERIE 5
+#define TEST_SEQ_EVEN   10
+#define TEST_SEQ_ODD   11
+struct _Interpol_test_data_even
+{
+	double dataX[TEST_SEQ_EVEN];
+	double dataY[TEST_SEQ_EVEN];
+	double dataW[TEST_SERIE];
+	double data_result[TEST_SERIE];
+};
+
+typedef struct _Interpol_test_data_even Interpol_test_data_even;
+
+struct _Interpol_test_data_odd
+{
+	double dataX[TEST_SEQ_ODD];
+	double dataY[TEST_SEQ_ODD];
+	double dataW[TEST_SERIE];
+	double data_result[TEST_SERIE];
+};
+
+typedef struct _Interpol_test_data_odd Interpol_test_data_odd;
+
+
+const char* SINFO_EFF_BUG_REPORT = "kmirny at eso.org";
+
+
+static const char COL_NAME_WAVELENGTH[] = "WAVELENGTH";
+static const char COL_NAME_FLUX[] 		= "FLUX";
+static const char COL_NAME_LAMBDA[] 	= "LAMBDA";
+static const char COL_NAME_LA_SILLA[]	= "LA_SILLA";
+static const char COL_NAME_EFF[]		= "EFF";
+static const double C_GAIN				= 2.42;
+
+void interpolation_test_even(void)
+{
+	Interpol_test_data_even test_data[] = {
+			{
+					{0,1,2,3,4,6,7,8,10,11},
+					{0,1,2,3,4,6,7,8,10,11},
+					{-1, 5, 20, 4.5, 1.001},
+					{-1, 5, 20, 4.5, 1.001},
+			},
+			{
+					{0,1,2,3,4,6,7,8,10,11},
+					{11,10,8,7,6,4,3,2,1,0},
+					{-1, 5, 20, 1.5, 7.99999},
+					{12, 5, -9, 9, 2.00001},
+			},
+			{
+					{1,2,3,4,5,6,7,8,10,11},
+					{1,1,1,1,1,1,1,1,1,1},
+					{-1, 9, 20, 5.000001, 6.9999999},
+					{1, 1, 1, 1, 1},
+			},
+			{
+					{1, 2, 3, 4, 5, 6, 7, 8, 10, 11},
+					{1, 0, 1, 0, 1, 0, 1, 0, 1,  0},
+					{0, 5, 9, 8.99, 8.000001},
+					{2, 1, 0.5, 0.495, 0},
+			},
+			{
+					{1, 2, 3, 4, 5, 6, 7, 8, 10, 11},
+					{1, 4, 9, 16, 25, 36, 49, 64, 100,  121},
+					{0, 5, 9, 5.5, 9.9},
+					{-2, 25, 82, 30.5, 98.2},
+			},
+	};
+	int n_test = sizeof(test_data) / sizeof(test_data[0]);
+	int i = 0;
+	for (i = 0; i < n_test; i++)
+	{
+		int d = 0;
+		for (d = 0; d < TEST_SERIE; d++)
+		{
+			float result = sinfo_data_interpolate(test_data[i].dataW[d],TEST_SEQ_EVEN, test_data[i].dataX, test_data[i].dataY);
+			cpl_test_abs(result, test_data[i].data_result[d], EPSILON);
+		}
+	}
+
+	return;
+}
+void interpolation_test_odd(void)
+{
+	Interpol_test_data_odd test_data[] = {
+			{
+					{0,1,2,3,4,6,7,8,10,11, 12},
+					{0,1,2,3,4,6,7,8,10,11, 12},
+					{-1, 5, 20, 4.5, 1.001},
+					{-1, 5, 20, 4.5, 1.001},
+			},
+			{
+					{0,1,2,3,4,6,7,8,10,11, 12},
+					{11,10,8,7,6,4,3,2,1,0, -1},
+					{-1, 5, 20, 1.5, 7.99999},
+					{12, 5, -9, 9, 2.00001},
+			},
+			{
+					{1,2,3,4,5,6,7,8,10,11, 12},
+					{1,1,1,1,1,1,1,1,1,1, 1},
+					{-1, 9, 20, 5.000001, 6.9999999},
+					{1, 1, 1, 1, 1},
+			},
+			{
+					{1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12},
+					{1, 0, 1, 0, 1, 0, 1, 0, 1,  0, 1},
+					{0, 5, 9, 8.99, 8.000001},
+					{2, 1, 0.5, 0.495, 0},
+			},
+			{
+					{1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12},
+					{1, 4, 9, 16, 25, 36, 49, 64, 100,  121, 144},
+					{0, 5, 9, 5.5, 9.9},
+					{-2, 25, 82, 30.5, 98.2},
+			},
+	};
+	int n_test = sizeof(test_data) / sizeof(test_data[0]);
+	int i = 0;
+	for (i = 0; i < n_test; i++)
+	{
+		int d = 0;
+		for (d = 0; d < TEST_SERIE; d++)
+		{
+			double result = sinfo_data_interpolate(test_data[i].dataW[d],TEST_SEQ_ODD, test_data[i].dataX, test_data[i].dataY);
+			cpl_test_abs(result, test_data[i].data_result[d], EPSILON);
+		}
+	}
+
+	return;
+}
+void fill_table(cpl_table* ptable, int nrows, const double* data, const char* col_name )
+{
+	cpl_table_new_column(ptable, col_name, CPL_TYPE_DOUBLE);
+	int i = 0;
+	for ( i = 0; i < nrows; i++)
+	{
+		cpl_table_set(ptable,col_name, i,data[i]);
+	};
+}
+const int NROWS_SPECTRUM 	= 10;
+const int NROWS_ATMEXT 		= 10;
+const int NROWS_REF			= 10;
+cpl_table* prepare_spectrum(void)
+{
+	const double wavelength_buf[] = {0.5,0.6,0.7,0.8,0.9,1.0,1.1,1.2,1.3,1.4}; // should be ordered
+	const double flux_buf[] = {2e-13 , 2.1e-13, 2.2e-13, 2.3e-13, 2.4e-13, 2.5e-13, 2.6e-13, 2.7e-13, 2.8e-13, 2.9e-13};
+
+	cpl_test(NROWS_SPECTRUM == sizeof(wavelength_buf) / sizeof(wavelength_buf[0]));
+	cpl_test(NROWS_SPECTRUM == sizeof(flux_buf) / sizeof(flux_buf[0]));
+
+	cpl_table* retval = cpl_table_new(NROWS_SPECTRUM);
+	fill_table(retval,NROWS_SPECTRUM,wavelength_buf,  COL_NAME_WAVELENGTH);
+	fill_table(retval,NROWS_SPECTRUM,flux_buf,  COL_NAME_FLUX);
+	return retval;
+}
+cpl_table* prepare_atmext(void)
+{
+	const double wavelength_buf[] = {0.5,0.6,0.7,0.8,0.9,1.0,1.1,1.2,1.3,1.4}; // should be ordered
+	const double flux_buf[] = {1,1,1,1,1,1,1,1,1,1};
+
+	cpl_test(NROWS_ATMEXT == sizeof(wavelength_buf) / sizeof(wavelength_buf[0]));
+	cpl_test(NROWS_ATMEXT == sizeof(flux_buf) / sizeof(flux_buf[0]));
+
+	cpl_table* retval = cpl_table_new(NROWS_ATMEXT);
+	fill_table(retval,NROWS_ATMEXT,wavelength_buf,  COL_NAME_LAMBDA);
+	fill_table(retval,NROWS_ATMEXT,flux_buf,  COL_NAME_LA_SILLA);
+	return retval;
+}
+cpl_table* prepare_ref(double exp_time, double tel_area)
+{
+	const double wavelength_buf[] = {0.5,0.6,0.7,0.8,0.9,1.0,1.1,1.2,1.3,1.4}; // should be ordered
+	double flux_buf[] = {2e-13, 2.1e-13, 2.2e-13, 2.3e-13, 2.4e-13, 2.5e-13, 2.6e-13, 2.7e-13, 2.8e-13, 2.9e-13};
+
+	cpl_test(NROWS_REF == sizeof(wavelength_buf) / sizeof(wavelength_buf[0]));
+	cpl_test(NROWS_REF == sizeof(flux_buf) / sizeof(flux_buf[0]));
+	int i = 0;
+	for (i = 0; i < sizeof(flux_buf) / sizeof(flux_buf[0]); i++)
+	{
+		flux_buf[i] /= exp_time * tel_area;
+	}
+
+	cpl_table* retval = cpl_table_new(NROWS_REF);
+	fill_table(retval,NROWS_REF,wavelength_buf,  COL_NAME_WAVELENGTH);
+	fill_table(retval,NROWS_REF,flux_buf, COL_NAME_FLUX);
+	return retval;
+}
+void eff_test(void)
+{
+	cpl_table* tbl_obj_spectrum = 0;
+	cpl_table* tbl_atmext = 0;
+	cpl_table* tbl_ref = 0;
+	double exptime = 600;
+	double airmass = 1;
+	double EFF_INDEX[] = {1,1,1,1,1,1,1,1,1,1};
+	double tel_area = 51.2e4;
+	double airprim = 1.446;
+	int i = 0;
+	tbl_obj_spectrum = prepare_spectrum();
+	tbl_atmext = prepare_atmext();
+	tbl_ref = prepare_ref(exptime, tel_area);
+	const double mk2AA=1E4; /* mkm/AA */
+	cpl_table* tbl_result = sinfo_utl_efficiency_internal(
+							      tbl_obj_spectrum,
+							      tbl_atmext,
+							      tbl_ref,
+							      exptime,
+							      airmass,
+							      airprim,
+							      C_GAIN,1,mk2AA,
+							      "LAMBDA",
+							      "LA_SILLA",
+							      "LAMBDA",
+							      "F_LAMBDA",
+							      "BIN_WIDTH",
+							      "WAVELENGTH",
+							      "INT_OBJ");
+
+
+	// check the result table
+	cpl_assert(tbl_result);
+
+	// size should be the same as the spectrum table
+	int result_size = cpl_table_get_nrow(tbl_result);
+	cpl_table_dump(tbl_result, 0, result_size, stdout);
+	cpl_test(result_size == NROWS_SPECTRUM);
+	for (i = 0; i < result_size; i++)
+	{
+		int px = 0;
+		double eff_value = 0;
+		check_nomsg(eff_value = cpl_table_get_double(tbl_result, COL_NAME_EFF, i, &px));
+		cpl_test_abs(eff_value, EFF_INDEX[i], EPSILON);
+	}
+cleanup:
+	// cleanup
+	cpl_table_delete(tbl_obj_spectrum);
+	cpl_table_delete(tbl_atmext);
+	cpl_table_delete(tbl_ref);
+	cpl_table_delete(tbl_result);
+	return;
+}
+int main(void)
+{
+	cpl_test_init(SINFO_EFF_BUG_REPORT, CPL_MSG_WARNING);
+	interpolation_test_even();
+	interpolation_test_odd();
+	//eff_test();
+	return cpl_test_end(0);
+}
+
diff --git a/sinfoni/tests/sinfo_gauss_fit_test.c b/sinfoni/tests/sinfo_gauss_fit_test.c
new file mode 100644
index 0000000..99bc5e3
--- /dev/null
+++ b/sinfoni/tests/sinfo_gauss_fit_test.c
@@ -0,0 +1,98 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004-2009 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*
+ * $Author: amodigli $
+ * $Date: 2010/06/18 06:55:06 $
+ * $Revision: 1.4 $
+ * $Log: sinfo_gauss_fit_test.c,v $
+ * Revision 1.4  2010/06/18 06:55:06  amodigli
+ * added comment to make this test working
+ *
+ * Revision 1.3  2010/06/17 11:45:34  kmirny
+ * changed the image file
+ *
+ * Revision 1.2  2009/07/13 14:40:39  kmirny
+ * fixing unit test failure in star catalog
+ *
+ * Revision 1.1  2009/06/16 15:13:43  kmirny
+ * fit gaussian test
+ *
+ * Revision 1.4  2009/06/15 08:17:12  kmirny
+ * put aimprim level up to prepared to use as a recipe parameter
+ *
+ * Revision 1.3  2009/06/10 14:58:31  kmirny
+ * sinfoni efficiency utility recipe
+ *
+ * Revision 1.2  2009/06/09 14:58:04  kmirny
+ * sinfoni efficiency unit test
+ *
+ * Revision 1.1  2009/06/09 08:57:18  kmirny
+ * adding test for sinfo_utl_efficiency
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#include <stdio.h>
+#include <cpl.h>
+#include <cpl_test.h>
+#include <sinfo_pro_save.h>
+#include <sinfo_error.h>
+#include <sinfo_msg.h>
+#include <sinfo_utils_wrappers.h>
+//const char* FITS_FILE_IMAGE = "bad_gauss_fit.fits";
+//const char* FITS_FILE_IMAGE = "bad_gauss_fit_psf.fits";
+const char* FITS_FILE_IMAGE = "__img.fits";
+
+const char* SINFO_GAUSS_BUG_REPORT = "kmirny at eso.org";
+void fit_test()
+{
+	double norm = 0;
+	double xcen = 0;
+	double ycen = 0;
+	double sig_x = 0;
+	double sig_y = 0;
+	double fwhm_x = 0;
+	double fwhm_y = 0;
+	// load image
+	cpl_image* pimage = 0;
+	pimage = cpl_image_load(FITS_FILE_IMAGE, CPL_TYPE_DOUBLE, 0, 0);
+	cpl_test(pimage);
+	cpl_test(CPL_ERROR_NONE == cpl_image_fit_gaussian(pimage,
+	                                                31,//41,
+	                                                36, //33,
+	                                                12, //Min to success
+	                                                &norm,
+	                                                &xcen,
+	                                                &ycen,
+	                                                &sig_x,
+	                                                &sig_y,
+	                                                &fwhm_x,
+	                                                &fwhm_y));
+	cpl_image_delete(pimage);
+}
+
+int main(void)
+{
+	cpl_test_init(SINFO_GAUSS_BUG_REPORT, CPL_MSG_WARNING);
+	//fit_test();
+	return cpl_test_end(0);
+}
diff --git a/sinfoni/tests/sinfo_image_ops_test.c b/sinfoni/tests/sinfo_image_ops_test.c
new file mode 100644
index 0000000..0e7b48f
--- /dev/null
+++ b/sinfoni/tests/sinfo_image_ops_test.c
@@ -0,0 +1,205 @@
+/*                                                                            *
+ *   This file is part of the ESO SINFO Pipeline                              *
+ *   Copyright (C) 2004,2005 European Southern Observatory                    *
+ *                                                                            *
+ *   This library is free software; you can redistribute it and/or modify     *
+ *   it under the terms of the GNU General Public License as published by     *
+ *   the Free Software Foundation; either version 2 of the License, or        *
+ *   (at your option) any later version.                                      *
+ *                                                                            *
+ *   This program is distributed in the hope that it will be useful,          *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of           *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
+ *   GNU General Public License for more details.                             *
+ *                                                                            *
+ *   You should have received a copy of the GNU General Public License        *
+ *   along with this program; if not, write to the Free Software              *
+ *   Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA     *
+ *                                                                           */
+ 
+/*
+ * $Author: amodigli $
+ * $Date: 2009/06/05 06:06:11 $
+ * $Revision: 1.8 $
+ * $Name: sinfo-2_3_2 $
+ * $Log: sinfo_image_ops_test.c,v $
+ * Revision 1.8  2009/06/05 06:06:11  amodigli
+ * updated init/end to cpl5
+ *
+ * Revision 1.7  2008/02/12 10:09:49  amodigli
+ * shortened lines
+ *
+ * Revision 1.6  2008/01/28 13:32:55  amodigli
+ * added test on line_corr
+ *
+ * Revision 1.5  2008/01/22 07:37:21  amodigli
+ * comment out tests wich require external input
+ *
+ * Revision 1.4  2008/01/22 07:35:15  amodigli
+ * added test case to test sinfoni bad line correction
+ *
+ * Revision 1.3  2008/01/17 07:21:54  amodigli
+ * removed clipm modeules
+ *
+ * Revision 1.2  2007/08/10 06:36:47  amodigli
+ * fixed leaks
+ *
+ * Revision 1.1  2007/08/09 13:00:31  amodigli
+ * added to repository
+ *
+ * Revision 1.2  2007/03/27 14:38:48  amodigli
+ * fixed compilation warnings
+ *
+ * Revision 1.1  2007/02/23 13:10:24  amodigli
+ * added test
+ *
+ */
+
+/*-----------------------------------------------------------------------------
+                                Includes
+ -----------------------------------------------------------------------------*/
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+#include <stdio.h>
+#include <cpl.h>
+#include <cpl_test.h>
+#include <sinfo_pro_save.h>
+#include <sinfo_error.h>
+#include <sinfo_msg.h>
+#include <sinfo_resampling.h>
+#include <sinfo_image_ops.h>
+#include <sinfo_utils_wrappers.h>
+/*-----------------------------------------------------------------------------
+                                Defines
+ -----------------------------------------------------------------------------*/
+
+/*-----------------------------------------------------------------------------
+                            Functions prototypes
+ -----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------*/
+/**
+ * @defgroup sinfo_image_ops_test  SINFO library unit tests
+ */
+/*----------------------------------------------------------------------------*/
+/**@{*/
+   
+
+
+
+
+
+
+
+static void
+test_line_corr(void)
+{
+
+  int width=4;
+  int filt_rad=3;
+  int kappa=18;//good value to indentify reasonably deviating bad pixels.
+
+  const char* dir="/data2/sinfoni/sinfo_demo/raw/DARK/";
+  const char* name="SINFO.2005-08-22T11:28:56.699.fits";
+
+  char file[256];
+  cpl_image* ima=NULL;
+  cpl_image* ima_out=NULL;
+
+
+  sprintf(file,"%s%s",dir,name);
+
+  check_nomsg(ima=cpl_image_load(file,CPL_TYPE_FLOAT,0,0));
+
+  check_nomsg(sinfo_image_line_corr(width,filt_rad,kappa,ima,&ima_out));
+
+  check_nomsg(cpl_image_save(ima_out,"ima_new.fits",CPL_BPP_IEEE_FLOAT,
+			     NULL,CPL_IO_DEFAULT));
+
+
+ cleanup:
+
+  return ;
+
+
+}
+
+
+/**
+   @brief      Shift an image 
+ */
+/*---------------------------------------------------------------------------*/
+#define SIZE 80
+static void
+test_image_shift(void)
+{
+  int sx=64;
+  int sy=64;
+
+  double xc=sx/2;
+  double yc=sy/2;
+  double sigx=sx/16;
+  double sigy=sy/16;
+  double min_noise=-0;
+  double max_noise=+30;
+  double y=1000;
+  double shift_x=sx/8;
+  double shift_y=sy/8;
+  double * kernel =NULL;
+
+  cpl_image* img_o=NULL;
+  cpl_image* img_s=NULL;
+
+  char name[SIZE];
+  char * kernel_type = "tanh";
+ 
+
+  check_nomsg(img_o=cpl_image_new(sx,sy,CPL_TYPE_FLOAT));
+  check_nomsg(img_s=cpl_image_new(sx,sy,CPL_TYPE_FLOAT));
+  check_nomsg(cpl_image_fill_gaussian(img_o,xc,yc,y,sigx,sigy));
+  check_nomsg(cpl_image_fill_noise_uniform(img_s,min_noise,max_noise));
+  check_nomsg(cpl_image_add(img_o,img_s));
+  sinfo_free_image(&img_s);
+
+  sprintf(name,"%s","img.fits");
+  check_nomsg(cpl_image_save(img_o,name,CPL_BPP_IEEE_FLOAT,
+			     NULL,CPL_IO_DEFAULT));
+  cknull_nomsg(kernel = sinfo_generate_interpolation_kernel( kernel_type )); 
+  check_nomsg(img_s=sinfo_new_shift_image(img_o,shift_x, shift_y,kernel));
+  sprintf(name,"%s","img_shift.fits");
+  check_nomsg(cpl_image_save(img_s,name,CPL_BPP_IEEE_FLOAT,
+			     NULL,CPL_IO_DEFAULT));
+
+ cleanup:
+  cpl_free(kernel);
+  sinfo_free_image(&img_s);
+  sinfo_free_image(&img_o);
+  return;
+
+}
+/*----------------------------------------------------------------------------*/
+/**
+  @brief   SINFONI pipeline unit test for cube coadd
+
+**/
+/*----------------------------------------------------------------------------*/
+
+int main(void)
+{
+  cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
+
+    /* Initialize CPL + SINFO messaging */
+  check(test_image_shift(),"Fail testing image shift");
+  //check(test_line_corr(),"Fail testing line corr");
+
+ cleanup:
+
+  return cpl_test_end(0);
+
+}
+
+
+/**@}*/
diff --git a/sinfoni/tests/sinfo_kappa_sigma_test.c b/sinfoni/tests/sinfo_kappa_sigma_test.c
new file mode 100644
index 0000000..faeb352
--- /dev/null
+++ b/sinfoni/tests/sinfo_kappa_sigma_test.c
@@ -0,0 +1,745 @@
+/*                                                                            *
+ *   This file is part of the ESO SINFO Pipeline                              *
+ *   Copyright (C) 2004,2005 European Southern Observatory                    *
+ *                                                                            *
+ *   This library is free software; you can redistribute it and/or modify     *
+ *   it under the terms of the GNU General Public License as published by     *
+ *   the Free Software Foundation; either version 2 of the License, or        *
+ *   (at your option) any later version.                                      *
+ *                                                                            *
+ *   This program is distributed in the hope that it will be useful,          *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of           *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
+ *   GNU General Public License for more details.                             *
+ *                                                                            *
+ *   You should have received a copy of the GNU General Public License        *
+ *   along with this program; if not, write to the Free Software              *
+ *   Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA     *
+ *                                                                           */
+ /*
+ * $Author: amodigli $
+ * $Date: 2012/04/26 15:23:49 $
+ * $Revision: 1.6 $
+ * $Name: sinfo-2_3_2 $
+ * $Log: sinfo_kappa_sigma_test.c,v $
+ * Revision 1.6  2012/04/26 15:23:49  amodigli
+ * cleaned errors from Jenkins static checks
+ *
+ * Revision 1.5  2009/07/29 09:06:24  amodigli
+ * fixed compiler error due to change API of cube_coad_with_ks_optimized
+ *
+ * Revision 1.4  2009/06/03 12:56:49  kmirny
+ * round-shift test for kappa-sigma clipping
+ *
+ * Revision 1.3  2009/06/03 11:13:51  kmirny
+ * unit test with gaussian
+ *
+ * Revision 1.2  2009/06/02 15:02:23  kmirny
+ * mask for NAN value was fixed
+ *
+ * Revision 1.1  2009/05/29 13:10:43  kmirny
+ * kappa-sigma clipping test
+ *
+  */
+/*
+ * set of libraries for testing kappa-sigma clipping
+ */
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+#include <stdio.h>
+#include <cpl.h>
+#include <cpl_test.h>
+#include <sinfo_globals.h>
+#include <sinfo_pro_save.h>
+#include <sinfo_error.h>
+#include <sinfo_msg.h>
+#include <sinfo_utils_wrappers.h>
+#include <sinfo_new_cube_ops.h>
+
+
+const int BUF_ARRAY_SIZE = 10;
+const double EPSILON = 1E-5;
+const char* KAPPA_SIGMA_BUG_REPORT = "kmirny at eso.org";
+
+const double GAUSS_NORM = 1E7;
+const int GAUSS_FWHM = 30;
+const double K = 2.35482;//1. / (2. * sqrt(2.* ln(2.)));
+
+const double DEFECT_LEVEL = 500;
+
+struct _KS_Array_Data
+{
+	/*input parameters*/
+	double buf[10];
+	double kappa;
+	/*output parameters*/
+	int nInvalidPoints;
+	double dResult;
+
+};
+typedef struct _KS_Array_Data KS_Array_Data;
+
+// forward declarations
+cpl_image* prepare_plane_gauss(int sizeX, int sizeY, double noiseLevel, double signal_level, int GAUSS_CENTER_X, int GAUSS_CENTER_Y, double gNORM, double gSIGMA);
+cpl_image* prepare_plane_noise(int sizeX, int sizeY, double SIGNAL_LEVEL, double SIGNAL_NOISE_LEVEL);
+cpl_image* prepare_plane_square_shape();
+void set_defect(cpl_image* pImage, int defectX, int defectY, double value);
+///////////
+
+int check_arr_data(KS_Array_Data* pData)
+{
+	int z = 0;
+	const double exptimes [] = {0,0,0,0,0,0,0,0,0,0};
+
+	cpl_array* pArray = cpl_array_new(BUF_ARRAY_SIZE, CPL_TYPE_DOUBLE);
+
+	for (z = 0; z < BUF_ARRAY_SIZE; z++)
+	{
+		double value = pData->buf[z];
+		if (!isnan(value))
+			cpl_array_set(pArray, z, value);
+	}
+	double result = kappa_sigma_array_with_mask(pArray, BUF_ARRAY_SIZE, pData->kappa,0, exptimes, 0, 0,0);
+	cpl_test_abs(result,pData->dResult,EPSILON);
+	int resInvalidPoints = cpl_array_count_invalid(pArray);
+	cpl_test_eq(resInvalidPoints, pData->nInvalidPoints);
+	cpl_array_delete(pArray);
+	return 0;
+}
+
+
+int kappa_sigma_array_test(void)
+{
+	int retval = 0;
+
+	KS_Array_Data DataToCheck[] = {
+			{
+				{1,	2,	3,	4,	5,	6,	7,	8,	9,	1000},
+				3,
+				1,
+				5,
+			},
+			{
+				{4,	2,	3,	5,	5,	6,	7,	8,	1001,	1000},
+				2,
+				2,
+				5,
+			},
+			{
+				{1,	2,	3,	5,	5,	6,	7,	8,	4,	15},
+				2,
+				1,
+				4.55556,
+			},
+			{
+				{1,	2,	3,	5,	5,	6,	7,	8,	4,	15},
+				3,
+				0,
+				5.6,
+			},
+			{
+				{10,20,	23,	25,	25,	26,	27,	22,	21,	30},
+				1.5,
+				5,
+				25.2,
+			},
+/*			{
+				{nan(""),20,	22,	nan(""),20,	22,	nan(""),20,	22,	nan("")},
+				3,
+				0,
+				21,
+			},*/
+			{
+				{ZERO,20,	21, 22,	ZERO,20,	22,	ZERO,20,	22},
+				3,
+				3,
+				21,
+			},
+/*			{
+				{50,100,	50,	100,	50,	100,	50,	100,	50,	100},
+				1.5,
+				0,
+				75,
+			},
+			{
+				{50,100,	50,	100,	50,	100,	50,	100,	50,	100},
+				3,
+				0,
+				75,
+			},
+			*/
+	};
+
+	int sz = sizeof(DataToCheck) / sizeof(DataToCheck[0]);
+	int z = 0;
+	for (z = 0; z < sz; z++)
+	{
+		retval += check_arr_data(&DataToCheck[z]);
+	}
+	return retval;
+}
+
+int kappa_sigma_chessboard_test()
+{
+	// create a 2*N images with chessboard with 1 pixel shift for each
+	// coaddition should produce an image with the same values for the each pixel (in the overlayed area)
+	const int sizeX = 24;
+	const int sizeY = 24;
+	const int nCubes = 2; // should be even
+	double exptimes[nCubes];
+	const double dBlackValue = 100;
+	const double dWhiteValue = 50;
+	const int shiftX = 3; // should be odd
+	const int shiftY = 2; // should be even
+
+	// coords of the overlapping image
+	const int xminOver = (nCubes-1) * shiftX + 1;
+	const int yminOver = (nCubes-1) * shiftY + 1;
+	const int xmaxOver = sizeX;
+	const int ymaxOver = sizeY;
+
+
+	const double kappa = 3;
+	cpl_imagelist* ppCubes[nCubes];
+
+	int resSizeX = sizeX + (nCubes-1) * shiftX;
+	int resSizeY = sizeY + (nCubes-1) * shiftY;
+	int pOffsetX[nCubes];
+	int pOffsetY[nCubes];
+
+	cpl_imagelist* ilResult = cpl_imagelist_new();
+	cpl_assert(ilResult);
+	int z = 0;
+	for (z = 0; z < nCubes; z++)
+	{
+		cpl_imagelist* pCube = cpl_imagelist_new();
+		cpl_image* pImage = cpl_image_new(sizeX, sizeY, CPL_TYPE_DOUBLE);
+		int x = 0;
+		for (x = 1; x <= sizeX; x++)
+		{
+			int y = 0;
+			for (y = 1; y <= sizeY; y++)
+			{
+				double value = ((x+y) & 1)? dBlackValue : dWhiteValue;
+				check_nomsg(cpl_image_set(pImage, x,y,value));
+			}
+		}
+		check_nomsg(cpl_imagelist_set(pCube, pImage, 0));
+		ppCubes[z] = pCube;
+		pOffsetX[z] = z * shiftX;
+		pOffsetY[z] = z * shiftY;
+	}
+
+	cpl_image* imResult = 0;
+	check_nomsg(imResult = cpl_image_new(resSizeX, resSizeY, CPL_TYPE_DOUBLE));
+	check_nomsg(cpl_imagelist_set(ilResult, imResult ,0));
+	cpl_imagelist* ilMask = cpl_imagelist_new();
+	cpl_imagelist_set(ilMask, cpl_image_new(resSizeX, resSizeY, CPL_TYPE_DOUBLE), 0);
+	sinfo_coadd_with_ks_clip_optimized(
+				0,
+				1,
+				nCubes,
+				kappa,
+				pOffsetX,
+				pOffsetY,
+	            exptimes,
+				ilMask,
+				ilResult,
+				ppCubes);
+
+	check_nomsg( imResult = cpl_imagelist_get(ilResult, 0));
+	cpl_assert(imResult);
+	double dExpectedValue = (dBlackValue + dWhiteValue) / 2;
+
+	// check result in the overlapping region
+	int x = 0;
+	for (x = xminOver; x <= xmaxOver; x++)
+	{
+		int y = 0;
+		for (y = yminOver; y <= ymaxOver; y++)
+		{
+			int px = 0;
+			double value = 0;
+			cpl_assert(x <= resSizeX );
+			cpl_assert(y <= resSizeY );
+			check_nomsg(value = cpl_image_get(imResult, x,y, &px));
+			cpl_test_abs(value,dExpectedValue,EPSILON);
+		}
+	}
+	cpl_imagelist_delete(ilMask);
+	cpl_imagelist_delete(ilResult);
+	for (z = 0; z < nCubes; z++)
+	{
+		cpl_imagelist_delete(ppCubes[z]);
+	}
+	return 0;
+	cleanup:
+	cpl_assert(!"error in cpl function");
+	return 1;
+}
+
+enum _TEST_IMAGE_TYPE
+{
+	IT_NOISE,
+	IT_GAUSS,
+	IT_SQUARE,
+};
+typedef enum _TEST_IMAGE_TYPE TEST_IMAGE_TYPE;
+
+int prepare_cube(cpl_imagelist** ppCubes, TEST_IMAGE_TYPE type, int sizeX, int sizeY, int nCubes, double noiseLevel, double signal_level, int defectX, int defectY)
+{
+	int z = 0;
+	for (z = 0; z < nCubes; z++)
+	{
+		cpl_imagelist* pCube = cpl_imagelist_new();
+		cpl_image* pImage;
+		ppCubes[z] = pCube;
+		// create a plane
+		switch(type)
+		{
+			case  IT_NOISE:
+				pImage = prepare_plane_noise(sizeY, sizeY, signal_level, noiseLevel);
+				break;
+			case IT_GAUSS:
+				{
+					double GAUSS_SIGMA = GAUSS_FWHM / K;
+					pImage = prepare_plane_gauss(sizeX, sizeY,noiseLevel, signal_level, sizeX / 2, sizeY / 2, GAUSS_NORM, GAUSS_SIGMA);
+				}
+				break;
+			case IT_SQUARE:
+				cpl_assert(!"not implemented");
+				pImage = prepare_plane_square_shape();
+				break;
+			default:
+				cpl_assert(!"unknown plane type");
+		}
+		cpl_assert(pImage);
+		if (z == 0 && (defectX * defectY > 0))
+		{
+			// put a defect only to the first cube
+			set_defect(pImage, defectX, defectY, DEFECT_LEVEL);
+		};
+		check_nomsg(cpl_imagelist_set(pCube, pImage, 0));
+	}
+	return 0;
+	cleanup:
+	cpl_assert(!"error in prepare_cube");
+	return 1;
+}
+
+cpl_image* prepare_plane_gauss(int sizeX, int sizeY, double noiseLevel, double signal_level, int GAUSS_CENTER_X, int GAUSS_CENTER_Y, double gNORM, double gSIGMA)
+{
+	cpl_image *pRet = 0;
+	cpl_image* pNoise = cpl_image_new(sizeX, sizeY, CPL_TYPE_DOUBLE);
+
+	check_nomsg(cpl_image_fill_noise_uniform(pNoise, signal_level - noiseLevel, signal_level + noiseLevel));
+	cpl_image* imGauss = cpl_image_new(sizeX, sizeY, CPL_TYPE_DOUBLE);
+	check_nomsg(cpl_image_fill_gaussian(imGauss, GAUSS_CENTER_X, GAUSS_CENTER_Y, gNORM, gSIGMA, gSIGMA));
+	check_nomsg(pRet = cpl_image_add_create(imGauss, pNoise));
+	cpl_image_delete(imGauss);
+	cpl_image_delete(pNoise);
+	return pRet;
+	cleanup:
+	cpl_assert(!"error in prepare_plane gauss");
+	return 0;
+}
+
+cpl_image* prepare_plane_noise(int sizeX, int sizeY, double SIGNAL_LEVEL, double SIGNAL_NOISE_LEVEL)
+{
+	// plane with noise
+	cpl_image* pRet = cpl_image_new(sizeX, sizeY, CPL_TYPE_DOUBLE);
+	check_nomsg(cpl_image_fill_noise_uniform(pRet, SIGNAL_LEVEL - SIGNAL_NOISE_LEVEL, SIGNAL_LEVEL + SIGNAL_NOISE_LEVEL));
+	return pRet;
+	cleanup:
+	cpl_assert(!"error in prepare_plain_noise");
+	return 0;
+}
+
+cpl_image* prepare_plane_square_shape()
+{
+	// TODO
+	cpl_image* pRet = 0;
+
+	return pRet;
+}
+
+void set_defect(cpl_image* pImage, int defectX, int defectY, double value)
+{
+	cpl_image_set(pImage, defectX-1, defectY+1, value);
+	cpl_image_set(pImage, defectX+1, defectY+1, value);
+	cpl_image_set(pImage, defectX-1, defectY-1, value);
+	cpl_image_set(pImage, defectX+1, defectY-1, value);
+	// NAN point to the center
+	cpl_image_set(pImage, defectX, defectY,ZERO);
+}
+
+double image_get_max(cpl_image* imResult, int sizeX, int sizeY)
+{
+	double retval = 0;
+	int x = 0;
+	int y = 0;
+	for (x = 1; x <= sizeX; x++)
+	{
+		for (y = 1; y <= sizeY; y++)
+		{
+			int px = 0;
+			double value = cpl_image_get(imResult, x, y, &px);
+			if (!isnan(value))
+			{
+				if (value > retval)
+				{
+					retval = value;
+				}
+			}
+		}
+	}
+	return retval;
+}
+
+int kappa_sigma_gauss_narrow_test()
+{
+
+	const int sizeX = 64;
+	const int sizeY = 64;
+	const int defectPointX = 55;
+	const int defectPointY = 55;
+	const int nCubes = 10;
+	double exptimes[nCubes];
+	const double SIGNAL_LEVEL = 50;
+	const double SIGNAL_NOISE_LEVEL = 5;
+	const double kappa = 3;
+	int pOffsetX[nCubes];
+	int pOffsetY[nCubes];
+	int z = 0;
+	memset(&pOffsetX[0], 0, nCubes * sizeof(pOffsetX[0]));
+	memset(&pOffsetY[0], 0, nCubes * sizeof(pOffsetY[0]));
+	cpl_imagelist* ppCubes[nCubes];
+
+	cpl_imagelist* ilResult = cpl_imagelist_new();
+	cpl_assert(ilResult);
+	cpl_image* imResult = 0;
+	check_nomsg(imResult = cpl_image_new(sizeX, sizeY, CPL_TYPE_DOUBLE));
+	check_nomsg(cpl_imagelist_set(ilResult, imResult ,0));
+
+	prepare_cube(ppCubes, IT_GAUSS, sizeX,sizeY, nCubes, SIGNAL_NOISE_LEVEL,SIGNAL_LEVEL, defectPointX, defectPointY);
+
+	cpl_imagelist* ilMask = cpl_imagelist_new();
+	cpl_imagelist_set(ilMask, cpl_image_new(sizeX, sizeY, CPL_TYPE_DOUBLE), 0);
+	sinfo_coadd_with_ks_clip_optimized(
+				0,
+				1,
+				nCubes,
+				kappa,
+				pOffsetX,
+				pOffsetY,
+	            exptimes,
+				ilMask,
+				ilResult,
+				ppCubes);
+
+	check_nomsg( imResult = cpl_imagelist_get(ilResult, 0));
+
+	///////////////////   checking the result
+
+	// check the gauss maximum point
+	int gaussX = sizeX / 2;
+	int gaussY = sizeY / 2;
+	int px = 0;
+	// the peak on the result image
+	double gauss_value = cpl_image_get(imResult, gaussX, gaussY, &px);
+
+	double gauss_expected_max_value = 0;
+	for (z = 0; z < nCubes; z++) // through all input images
+	{
+		gauss_expected_max_value += image_get_max(cpl_imagelist_get(ppCubes[z],0), sizeX, sizeY);
+	}
+	gauss_expected_max_value /= nCubes;
+	cpl_test_abs(gauss_value, gauss_expected_max_value, SIGNAL_NOISE_LEVEL / 2);
+
+	// 3. check FWHM
+	double half_width_value = (gauss_expected_max_value -  SIGNAL_NOISE_LEVEL / 2) / 2;
+	int x_max = 1;
+	int y_stripe = sizeY / 2;
+	double curr_value  =0;
+	do
+	{
+		check_nomsg (curr_value = cpl_image_get(imResult, x_max, y_stripe, &px));
+		if (curr_value > half_width_value )
+		{
+			break;
+		}
+		x_max++;
+	}
+	while(x_max < sizeX / 2);
+	if (curr_value > 0)
+	{
+		x_max = (sizeX / 2 - x_max) * 2;
+		// check the expected value
+		cpl_test_abs(GAUSS_FWHM, x_max, 1);
+	}
+	else
+	{
+		cpl_assert(!"FWHM is not reached");
+	}
+
+
+	///////////////////////////////
+
+	/*
+	 *  Cleanup
+	 */
+	cpl_imagelist_delete(ilResult);
+	cpl_imagelist_delete(ilMask);
+
+	for (z = 0; z < nCubes; z++)
+	{
+		cpl_imagelist_delete(ppCubes[z]);
+	}
+	return 0;
+	cleanup:
+	cpl_assert(!"error in cpl function");
+	return 1;
+}
+
+void kappa_sigma_round_shift_test()
+{
+	const int sizeX = 8;
+	const int sizeY = 8;
+	const int globalSizeX = 12;
+	const int globalSizeY = 12;
+	const int shift_index_X[] = {0, 0, 1, 1};
+	const int shift_index_Y[] = {0, 1, 1, 0};
+	const int nCubes = 4;
+	double exptimes[nCubes];
+	int pOffsetX[nCubes];
+	int pOffsetY[nCubes];
+	const double signal_levels[] = {11, 23, 37, 43};
+	int minOver = 5;
+	int maxOver = 8;
+	double kappa = 3;
+	double EXPOSITION_DEFAULT = 100;
+
+	cpl_imagelist* ppCubes[nCubes];
+	cpl_imagelist* ilResult = cpl_imagelist_new();
+	cpl_image* imResult = 0;
+	cpl_imagelist* ilMask = cpl_imagelist_new();
+	cpl_image* imMask = cpl_image_new(globalSizeX, globalSizeY, CPL_TYPE_DOUBLE);
+	int x = 0;
+	int z = 0;
+	check_nomsg(imResult = cpl_image_new(globalSizeX, globalSizeY, CPL_TYPE_DOUBLE));
+	check_nomsg(cpl_imagelist_set(ilResult, imResult ,0));
+	//1. prepare the cubes
+
+	for (z = 0; z < nCubes; z++)
+	{
+
+		cpl_imagelist* pImList = cpl_imagelist_new();
+		cpl_image* pImage = cpl_image_new(sizeX, sizeY, CPL_TYPE_DOUBLE);
+		int x = 0;
+		int y = 0;
+		int value_index = 0;
+		for (x = 1; x <= sizeX; x++)
+		{
+			for(y = 1; y <= sizeY; y++)
+			{
+				int index = value_index % nCubes;
+				double value = (index == z) ? signal_levels[index] : ZERO ;
+				check_nomsg(cpl_image_set(pImage, x, y, value));
+				value_index++;
+			}
+			value_index--;
+		}
+		check_nomsg(cpl_imagelist_set(pImList, pImage, 0));
+		ppCubes[z] = pImList;
+		pOffsetX[z] = nCubes * shift_index_X[z];
+		pOffsetY[z] = nCubes * shift_index_Y[z];
+	}
+	// prepare the mask
+	for (x = 1; x <= sizeX; x++)
+	{
+		int y = 0;
+		for (y = 1; y <= sizeY; y++)
+		{
+			check_nomsg(cpl_image_set(imMask, x, y, EXPOSITION_DEFAULT));
+		}
+	}
+	// setup exposition values
+	for (x = 0; x < nCubes; x++)
+	{
+		exptimes[x] = EXPOSITION_DEFAULT;
+	}
+	check_nomsg(cpl_imagelist_set(ilMask, imMask, 0));
+	sinfo_coadd_with_ks_clip_optimized(
+				0,
+				1,
+				nCubes,
+				kappa,
+				pOffsetX,
+				pOffsetY,
+	            exptimes,
+				ilMask,
+				ilResult,
+				ppCubes);
+
+	check_nomsg( imResult = cpl_imagelist_get(ilResult, 0));
+	// check the result
+	// values in the overlapping region should come from the same rule as during calculating input,
+	// but without holes (NAN values);
+
+	int index = 0;
+	for (x = minOver; x <= maxOver; x++)
+	{
+		int y = 0;
+		for (y = minOver; y <= maxOver; y++)
+		{
+			int px = 0;
+			double value_expected = signal_levels[index % nCubes];
+			double value = cpl_image_get(imResult, x, y, &px);
+			cpl_test_abs(value, value_expected, EPSILON);
+			index ++;
+		}
+		index--;
+	}
+	// cleanup
+	cpl_imagelist_delete(ilResult);
+	cpl_imagelist_delete(ilMask);
+	for (z = 0; z < nCubes; z++)
+	{
+		cpl_imagelist_delete(ppCubes[z]);
+	}
+	return;
+	cleanup:
+	cpl_assert(!"error in cpl function");
+	return;
+}
+
+void kappa_sigma_outlier_test()
+{
+	// make a defect on the image with noise. kappa-sigma should remove the defect, defect should appear
+	// then on the mask image
+	const int sizeX = 10;
+	const int sizeY = 10;
+
+	const int nCubes = 10;
+	double exptimes[nCubes];
+	const double SIGNAL_LEVEL = 250;
+	const double SIGNAL_NOISE_LEVEL = 10;
+	const double kappa = 3;
+	const double EXPOSITION_DEFAULT = 100;
+	const int DEFECT_X = 5;
+	const int DEFECT_Y = 5;
+
+	int pOffsetX[nCubes];
+	int pOffsetY[nCubes];
+	memset(&pOffsetX[0], 0, nCubes * sizeof(pOffsetX[0]));
+	memset(&pOffsetY[0], 0, nCubes * sizeof(pOffsetY[0]));
+
+
+
+	cpl_imagelist* ppCubes[nCubes];
+	cpl_imagelist* ilResult = cpl_imagelist_new();
+	cpl_assert(ilResult);
+	cpl_image* imResult = 0;
+	check_nomsg(imResult = cpl_image_new(sizeX, sizeY, CPL_TYPE_DOUBLE));
+	check_nomsg(cpl_imagelist_set(ilResult, imResult ,0));
+
+	prepare_cube(ppCubes, IT_NOISE, sizeX,sizeY, nCubes, SIGNAL_NOISE_LEVEL,SIGNAL_LEVEL, DEFECT_X, DEFECT_Y);
+
+	cpl_imagelist* ilMask = cpl_imagelist_new();
+	cpl_image* imMask = cpl_image_new(sizeX, sizeY, CPL_TYPE_DOUBLE);
+	int x = 0;
+	for (x = 1; x <= sizeX; x++)
+	{
+		int y = 0;
+		for (y = 1; y <= sizeY; y++)
+		{
+			cpl_image_set(imMask, x, y, EXPOSITION_DEFAULT);
+		}
+	}
+	// setup exposition values
+	for (x = 0; x < nCubes; x++)
+	{
+		exptimes[x] = EXPOSITION_DEFAULT;
+	}
+	cpl_imagelist_set(ilMask, imMask, 0);
+	sinfo_coadd_with_ks_clip_optimized(
+				0,
+				1,
+				nCubes,
+				kappa,
+				pOffsetX,
+				pOffsetY,
+	            exptimes,
+				ilMask,
+				ilResult,
+				ppCubes);
+
+	check_nomsg( imResult = cpl_imagelist_get(ilResult, 0));
+	//
+
+///////////////// check the result //////////////////////////////
+	/*
+	 * all points should have a value of signal +- noise - all defect pixels should be removed
+	 * */
+
+	for (x = 1; x <= sizeX; x++)
+	{
+		int y = 0;
+		for (y = 1;y <= sizeY; y++)
+		{
+			int px = 0;
+			double result_value = 0;
+			result_value = cpl_image_get(imResult, x,y, &px);
+			cpl_test_abs(result_value,SIGNAL_LEVEL,SIGNAL_NOISE_LEVEL);
+		}
+	}
+	/*
+	 * check the mask image - pixels on the defect places should be 0
+	 * */
+	double mask_value = 0;
+	imMask = cpl_imagelist_get(ilMask, 0);
+	cpl_assert(imMask);
+
+	int px = 0;
+
+	// value for the NAN point
+	check_nomsg(mask_value = cpl_image_get(imMask, DEFECT_X, DEFECT_Y, &px));
+	cpl_test_abs(mask_value, 0, EPSILON);
+	// values for defect points (defect_level)
+	check_nomsg(mask_value = cpl_image_get(imMask, DEFECT_X + 1, DEFECT_Y + 1, &px));
+	cpl_test_abs(mask_value, 0, EPSILON);
+	check_nomsg(mask_value = cpl_image_get(imMask, DEFECT_X - 1, DEFECT_Y - 1, &px));
+	cpl_test_abs(mask_value, 0, EPSILON);
+	check_nomsg(mask_value = cpl_image_get(imMask, DEFECT_X + 1, DEFECT_Y - 1, &px));
+	cpl_test_abs(mask_value, 0, EPSILON);
+	check_nomsg(mask_value = cpl_image_get(imMask, DEFECT_X - 1, DEFECT_Y + 1, &px));
+	cpl_test_abs(mask_value, 0, EPSILON);
+
+////////////////////////////////////////
+	// cleanup
+	cpl_imagelist_delete(ilResult);
+	cpl_imagelist_delete(ilMask);
+	int z = 0;
+	for (z = 0; z < nCubes; z++)
+	{
+		cpl_imagelist_delete(ppCubes[z]);
+	}
+	return;
+	cleanup:
+	cpl_assert(!"error in cpl function");
+	return;
+}
+
+int main(void)
+{
+	cpl_test_init(KAPPA_SIGMA_BUG_REPORT, CPL_MSG_WARNING);
+	kappa_sigma_array_test();
+	kappa_sigma_chessboard_test();
+	kappa_sigma_outlier_test();
+	kappa_sigma_gauss_narrow_test();
+	kappa_sigma_round_shift_test();
+	return cpl_test_end(0);
+}
+
+/**@}*/
diff --git a/sinfoni/tests/sinfo_line_corr_test.c b/sinfoni/tests/sinfo_line_corr_test.c
new file mode 100644
index 0000000..5e45307
--- /dev/null
+++ b/sinfoni/tests/sinfo_line_corr_test.c
@@ -0,0 +1,106 @@
+/*                                                                            *
+ *   This file is part of the ESO SINFO Pipeline                              *
+ *   Copyright (C) 2004,2005 European Southern Observatory                    *
+ *                                                                            *
+ *   This library is free software; you can redistribute it and/or modify     *
+ *   it under the terms of the GNU General Public License as published by     *
+ *   the Free Software Foundation; either version 2 of the License, or        *
+ *   (at your option) any later version.                                      *
+ *                                                                            *
+ *   This program is distributed in the hope that it will be useful,          *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of           *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
+ *   GNU General Public License for more details.                             *
+ *                                                                            *
+ *   You should have received a copy of the GNU General Public License        *
+ *   along with this program; if not, write to the Free Software              *
+ *   Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA     *
+ *                                                                           */
+
+/*
+ * $Author: kmirny $
+ * $Date: 2009/09/02 12:18:02 $
+ * $Revision: 1.1 $
+ * $Name: sinfo-2_3_2 $
+ * $Log: sinfo_line_corr_test.c,v $
+ * Revision 1.1  2009/09/02 12:18:02  kmirny
+ * updating unit tests
+ *
+ * */
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+#include <cpl.h>
+#include <cpl_test.h>
+#include <sinfo_image_ops.h>
+
+const char* SINFO_EFF_BUG_REPORT = "kmirny at eso.org";
+cpl_image* prepare_image(double* sigma)
+{
+	const int IMG_SZX = 500;
+	const int IMG_SZY = 500;
+	int i = 0;
+	int j = 0;
+	const float FLUX_MIN = 6;
+	const float FLUX_MAX = 7;
+	const float FLUX_OFFSET = 2;
+	const float LINE_VALUE = 3;
+	const int LINE_POS = 100;
+	cpl_image* pimage = cpl_image_new(IMG_SZX, IMG_SZY, CPL_TYPE_FLOAT);
+	cpl_image_fill_noise_uniform(pimage, FLUX_MIN, FLUX_MAX);
+	for (j = 0; j < IMG_SZY; j++)
+	{
+		for (i = 0; i < 4; i++)
+		{
+			int pis_rejected;
+			double value = cpl_image_get(pimage,i + 1,  j + 1, &pis_rejected);
+			cpl_image_set(pimage, i + 1, j + 1, (value - FLUX_OFFSET) > 0 ? (value - FLUX_OFFSET) : FLUX_MIN - FLUX_OFFSET);
+			cpl_image_set(pimage, IMG_SZX - 4 + i + 1, j + 1, (value - FLUX_OFFSET) > 0 ? (value - FLUX_OFFSET) : FLUX_MIN - FLUX_OFFSET);
+		}
+	}
+	*sigma = cpl_image_get_stdev(pimage);
+	// create a line
+	for (i = 3; i < IMG_SZX - 4; i++)
+	{
+		int pis_rejected;
+		double value = cpl_image_get(pimage,i + 1,  LINE_POS + (i%5), &pis_rejected);
+		cpl_image_set(pimage, i + 1, LINE_POS, /*value*/ LINE_VALUE);
+		cpl_image_set(pimage, i + 1, LINE_POS + 100, /*value*/ LINE_VALUE);
+	}
+	return pimage;
+
+}
+void check_image(cpl_image* pimage, double sigma)
+{
+	double new_sigma = cpl_image_get_stdev(pimage);
+	cpl_msg_warning(cpl_func, "old sigma [%f], new [%f]", sigma, new_sigma);
+}
+void line_correction_test()
+{
+	int width = 4;
+	int filt_rad = 3;
+	int kappa = 3;
+	double sigma = 0;
+	cpl_image * pimage = 0;
+	cpl_image* poutput = 0;
+	pimage = prepare_image(&sigma);
+	cpl_test(pimage);
+	cpl_error_code err =
+		sinfo_image_line_corr(width, filt_rad, kappa,
+								pimage,  &poutput);
+	cpl_test(err == CPL_ERROR_NONE);
+	check_image(poutput, sigma);
+	cpl_image_save(pimage, "corr_in.fits", CPL_BPP_IEEE_FLOAT, NULL, CPL_IO_CREATE);
+	cpl_image_save(poutput, "corr_out.fits", CPL_BPP_IEEE_FLOAT, NULL, CPL_IO_CREATE);
+	cpl_image_delete(pimage);
+	cpl_image_delete(poutput);
+}
+
+
+int main(void)
+{
+	cpl_test_init(SINFO_EFF_BUG_REPORT, CPL_MSG_WARNING);
+	line_correction_test();
+	return cpl_test_end(0);
+}
diff --git a/sinfoni/tests/sinfo_skycor_test.c b/sinfoni/tests/sinfo_skycor_test.c
new file mode 100644
index 0000000..ed247e1
--- /dev/null
+++ b/sinfoni/tests/sinfo_skycor_test.c
@@ -0,0 +1,87 @@
+/*                                                                            *
+ *   This file is part of the ESO SINFO Pipeline                              *
+ *   Copyright (C) 2004,2005 European Southern Observatory                    *
+ *                                                                            *
+ *   This library is free software; you can redistribute it and/or modify     *
+ *   it under the terms of the GNU General Public License as published by     *
+ *   the Free Software Foundation; either version 2 of the License, or        *
+ *   (at your option) any later version.                                      *
+ *                                                                            *
+ *   This program is distributed in the hope that it will be useful,          *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of           *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
+ *   GNU General Public License for more details.                             *
+ *                                                                            *
+ *   You should have received a copy of the GNU General Public License        *
+ *   along with this program; if not, write to the Free Software              *
+ *   Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA     *
+ *                                                                           */
+ 
+/*
+ * $Author: amodigli $
+ * $Date: 2009/06/05 06:06:11 $
+ * $Revision: 1.5 $
+ * $Name: sinfo-2_3_2 $
+ * $Log: sinfo_skycor_test.c,v $
+ * Revision 1.5  2009/06/05 06:06:11  amodigli
+ * updated init/end to cpl5
+ *
+ * Revision 1.4  2008/02/12 10:09:49  amodigli
+ * shortened lines
+ *
+ * Revision 1.3  2008/01/03 12:06:39  amodigli
+ * added IRPLIB_TEST_INIT/END
+ *
+ * Revision 1.2  2007/03/27 14:38:48  amodigli
+ * fixed compilation warnings
+ *
+ * Revision 1.1  2007/02/23 13:10:24  amodigli
+ * added test
+ *
+ */
+
+/*-----------------------------------------------------------------------------
+                                Includes
+ -----------------------------------------------------------------------------*/
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+#include<sinfo_msg.h>
+#include <cpl_test.h>
+/*-----------------------------------------------------------------------------
+                                Defines
+ -----------------------------------------------------------------------------*/
+
+/*-----------------------------------------------------------------------------
+                            Functions prototypes
+ -----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------*/
+/**
+ * @defgroup sinfo_skycor_test  SINFO library unit tests
+ */
+/*----------------------------------------------------------------------------*/
+/**@{*/
+   
+/*----------------------------------------------------------------------------*/
+/**
+  @brief   SINFONI pipeline unit test for skycor
+
+**/
+/*----------------------------------------------------------------------------*/
+
+int main(void)
+{
+    /* Initialize CPL + SINFO messaging */
+  cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
+
+  sinfo_msg("Hello World!");
+
+  return cpl_test_end(0);
+
+}
+
+
+/**@}*/
diff --git a/sinfoni/tests/sinfo_star_catalog.c b/sinfoni/tests/sinfo_star_catalog.c
new file mode 100644
index 0000000..26ffddb
--- /dev/null
+++ b/sinfoni/tests/sinfo_star_catalog.c
@@ -0,0 +1,303 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004-2009 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*
+ * $Author: kmirny $
+ * $Date: 2010/08/20 08:59:16 $
+ * $Revision: 1.3 $
+ * $Log: sinfo_star_catalog.c,v $
+ * Revision 1.3  2010/08/20 08:59:16  kmirny
+ * fixing problem with removing from catalog
+ *
+ * Revision 1.2  2009/09/02 12:18:02  kmirny
+ * updating unit tests
+ *
+ * Revision 1.1  2009/07/17 07:29:03  kmirny
+ * star catalog
+ *
+ */
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#include <stdio.h>
+//#include <unistd.h>
+
+#include <cpl.h>
+#include <cpl_test.h>
+#include <sinfo_pro_save.h>
+#include <sinfo_error.h>
+#include <sinfo_msg.h>
+#include <sinfo_utils_wrappers.h>
+#include <sinfo_star_index.h>
+#include <getopt.h>
+
+const char* SINFO_STAR_BUG_REPORT = "kmirny at eso.org";
+const double EPSILON = 1E-5;
+const double DATA_1		= 209384.23;
+const double DATA_2		= 378455.4398;
+const char* COL_NAME_DATA = "DATA";
+const char* FILE_NAME_FITS = "tmp_star_catalog.fits";
+const char* FILE_NAME_FITS2 = "tmp_star_catalog2.fits";
+
+typedef struct _STAR_COORD_
+{
+	double RA;
+	double DEC;
+	double data_value;
+	const char* STAR_NAME;
+};
+
+typedef struct _STAR_COORD_ STAR_COORD;
+
+const STAR_COORD coords[] = {
+		{300.982347, 18.34958, 958.229384, "STAR_UNO"},
+		{30.234434, 180.23409, 2817.23847, "STAR_DUO"},
+};
+
+const STAR_COORD coords2[] = {
+		{305.34892, 53.4319, 9545.234, "STAR_TRE"},
+		{32.234434, 180.23409, 21348.78653, "STAR_QUA"},
+		{2.234434, 45.2239, 8746.1236, "STAR_CIN"},
+};
+
+void create_empty_test()
+{
+	star_index* pindex = star_index_create();
+	cpl_test(pindex);
+	star_index_delete(pindex);
+}
+cpl_table* create_data_table(double data_value)
+{
+	cpl_table* retval = cpl_table_new(1);
+	cpl_test(retval);
+	cpl_test(CPL_ERROR_NONE == cpl_table_new_column(retval, COL_NAME_DATA, CPL_TYPE_DOUBLE));
+	cpl_table_set_double(retval, COL_NAME_DATA, 0, data_value);
+	return retval;
+}
+void check_index(star_index* pindex, STAR_COORD* pcoords, int size)
+{
+	int i = 0;
+	for (i = 0; i < size; i++)
+	{
+		cpl_table* presult_data = star_index_get(pindex, pcoords[i].RA, pcoords[i].DEC, EPSILON, EPSILON, NULL);
+		cpl_test(presult_data);
+		int inull = 0;
+		double result_data = cpl_table_get_double(presult_data, COL_NAME_DATA, 0, &inull);
+		cpl_test_abs(result_data, pcoords[i].data_value, EPSILON);
+		cpl_table_delete(presult_data);
+	}
+}
+void fill_index(star_index* pindex, STAR_COORD* pcoords, int size)
+{
+	int i = 0;
+	for (i = 0; i < size; i++ )
+	{
+		cpl_table* pdata = create_data_table(pcoords[i].data_value);
+		star_index_add(pindex, pcoords[i].RA, pcoords[i].DEC, pcoords[i].STAR_NAME, pdata);
+		cpl_table_delete(pdata);
+	};
+}
+void add_data_test()
+{
+
+	star_index* pindex = star_index_create();
+	cpl_test(pindex);
+	int i = 0;
+	fill_index (pindex,coords, sizeof(coords) / sizeof(coords[0]));
+	check_index(pindex,coords, sizeof(coords) / sizeof(coords[0]));
+	star_index_save(pindex, FILE_NAME_FITS);
+	star_index_delete(pindex);
+}
+
+void load_file_test()
+{
+	star_index* pindex = star_index_load(FILE_NAME_FITS);
+	check_index(pindex, coords, sizeof(coords) / sizeof(coords[0]));
+	fill_index(pindex,coords2, sizeof(coords2) / sizeof(coords2[0]));
+	check_index(pindex,coords2, sizeof(coords2) / sizeof(coords2[0]));
+	check_index(pindex, coords, sizeof(coords) / sizeof(coords[0]));
+	// remove from cache and main
+	star_index_remove_by_name(pindex, coords[0].STAR_NAME);
+	star_index_remove_by_name(pindex, coords2[0].STAR_NAME);
+	check_index(pindex,coords2 + 1, sizeof(coords2) / sizeof(coords2[0]) - 1);
+	check_index(pindex, coords + 1, sizeof(coords) / sizeof(coords[0]) - 1);
+	// save, load and check again
+	star_index_save(pindex, FILE_NAME_FITS2);
+	star_index* pindex2 = star_index_load(FILE_NAME_FITS2);
+	cpl_test(pindex2);
+	check_index(pindex2,coords2 + 1, sizeof(coords2) / sizeof(coords2[0]) - 1);
+	check_index(pindex2, coords + 1, sizeof(coords) / sizeof(coords[0]) - 1);
+	star_index_delete(pindex);
+	star_index_delete(pindex2);
+}
+void create()
+{
+	star_index* pindex = star_index_load("star_index.fits");
+	if (pindex)
+	{
+		cpl_table* pdata = cpl_table_load("gd71_stisnic_002.fits",1,0);
+		if (pdata)
+		{
+			star_index_add(pindex, 88.115075, 15.88654, "gd71_stisnic", pdata);
+			cpl_table_delete(pdata);
+			star_index_save(pindex, "11star_index_v0_0_.fits");
+		}
+		star_index_delete(pindex);
+	}
+}
+cpl_error_code add_star(star_index* pindex, const char*name, double RA, double DEC, const char* fits_file_name)
+{
+	cpl_error_code err = CPL_ERROR_NONE;
+	cpl_table* tbl = 0;
+	tbl = cpl_table_load(fits_file_name, 1,0);
+	if (tbl)
+	{
+		int pos = star_index_add(pindex, RA, DEC, name, tbl);
+		if (pos == 0)
+		{
+			err = CPL_ERROR_ILLEGAL_INPUT;
+		}
+		cpl_table_delete(tbl);
+	}
+	else
+	{
+		fprintf(stderr,"cannot load table[%s]\n",fits_file_name);
+		err = CPL_ERROR_FILE_IO;
+	}
+	return err;
+}
+
+void list_catalog(star_index* pindex, FILE* file)
+{
+	star_index_dump(pindex, file);
+}
+
+void remove_star(star_index* pindex, const char* star_name)
+{
+	star_index_remove_by_name(pindex, star_name);
+}
+
+void save_catalog(star_index* pindex, const char* fits_file_name)
+{
+	const char* TMP_FILE_NAME = "star_index_tmp.fits";
+	const char* EXT_BAK = ".bak";
+	//1. save to the new file
+	star_index_save(pindex, TMP_FILE_NAME);
+	//2. rename old file to .bak
+	const char* bak_filename = cpl_malloc(strlen(fits_file_name) + strlen(EXT_BAK) + 1);
+	strcpy(bak_filename, fits_file_name);
+	strcpy(bak_filename + strlen(fits_file_name) , EXT_BAK);
+	rename(fits_file_name, bak_filename); // don't care about result
+	//3. rename new file
+	rename(TMP_FILE_NAME, fits_file_name);
+	cpl_free(bak_filename);
+}
+int main(int argc, char * const argv[])
+{
+	cpl_test_init(SINFO_STAR_BUG_REPORT, CPL_MSG_WARNING);
+    int print_usage = 0;
+	const char* index_file = 0 ;
+	int opt = 0;
+
+	if (argc < 2)
+	{
+		print_usage = 1;
+	}
+	else
+	{
+		index_file = argv[1];
+	}
+	if (index_file == 0)
+	{
+		print_usage = 1;
+	}
+	if(print_usage)
+	{
+		fprintf(stderr, "usage: %s catalog_name [-l | -a star_name RA DEC "
+				"ref_fits_file.fits | -r star_name]\n"
+				"-a option creates a new catalog, if catalog_name is not "
+				"presented\n", argv[0]);
+		return 0;
+	}
+	// open an index file
+	star_index* pindex = star_index_load(index_file);
+
+	// try to get a parameters, if nothing use -list as default
+	opt = getopt(argc,argv,"lr:a:");
+	if(pindex == NULL && opt=='a')
+	{
+		printf ("cannot open index file [%s], create new one\n", index_file);
+		pindex = star_index_create();
+	}
+	if (pindex == NULL)
+	{
+		fprintf(stderr, "cannot open index file [%s]", index_file);
+		return -1;
+	}
+	if (opt != -1)
+	{
+		switch (opt)
+		{
+		case 'l':
+			printf("LIST\n");
+			list_catalog(pindex, stdout);
+			break;
+		case 'r':
+		{
+			const char* star_name = optarg;
+			printf("REMOVE [%s]\n", star_name);
+			remove_star(pindex, star_name);
+			save_catalog(pindex,index_file);
+			//star_index_save(pindex,index_file);
+		}
+			break;
+		case 'a':
+		{
+			const char* star_name = optarg;
+			double RA = atof(argv[optind]);
+			double DEC = atof(argv[optind+1]);;
+			const char* fits_file = argv[optind+2];
+			printf("ADD [%s] coord[%f:%f] file:%s\n", star_name, RA, DEC, fits_file);
+			cpl_error_code err = add_star(pindex, star_name, RA, DEC, fits_file);
+			if (err == CPL_ERROR_NONE)
+			{
+				printf ("save to [%s]\n", index_file);
+				save_catalog(pindex,index_file);
+			}
+			else
+			{
+				printf("error during add\n");
+			}
+		}
+			break;
+		default:
+			fprintf(stderr, " Urecognized option, usage: %s catalog_name [-l | -a star_name RA DEC ref_fits_file.fits | -r star_name]\n", argv[0]);
+			break;
+
+		}
+	}
+
+
+//	create_empty_test();
+//	add_data_test();
+//	load_file_test();
+//	create();
+//	cpl_test_end(0);
+	return 0;//
+}
diff --git a/sinfoni/tests/sinfo_star_index_test.c b/sinfoni/tests/sinfo_star_index_test.c
new file mode 100644
index 0000000..9dddb09
--- /dev/null
+++ b/sinfoni/tests/sinfo_star_index_test.c
@@ -0,0 +1,174 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004-2009 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+/*
+ * $Author: kmirny $
+ * $Date: 2009/07/13 14:40:39 $
+ * $Revision: 1.2 $
+ * $Log: sinfo_star_index_test.c,v $
+ * Revision 1.2  2009/07/13 14:40:39  kmirny
+ * fixing unit test failure in star catalog
+ *
+ * Revision 1.1  2009/06/19 14:43:25  kmirny
+ * sinfo star index test
+ *
+ */
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#include <stdio.h>
+#include <cpl.h>
+#include <cpl_test.h>
+#include <sinfo_pro_save.h>
+#include <sinfo_error.h>
+#include <sinfo_msg.h>
+#include <sinfo_utils_wrappers.h>
+#include <sinfo_star_index.h>
+
+const char* SINFO_STAR_BUG_REPORT = "kmirny at eso.org";
+const double EPSILON = 1E-5;
+const double DATA_1		= 209384.23;
+const double DATA_2		= 378455.4398;
+const char* COL_NAME_DATA = "DATA";
+const char* FILE_NAME_FITS = "tmp_star_catalog.fits";
+const char* FILE_NAME_FITS2 = "tmp_star_catalog2.fits";
+
+typedef struct _STAR_COORD_
+{
+	double RA;
+	double DEC;
+	double data_value;
+	const char* STAR_NAME;
+
+};
+typedef struct _STAR_COORD_ STAR_COORD;
+
+const STAR_COORD coords[] = {
+		{300.982347, 18.34958, 958.229384, "STAR_UNO"},
+		{30.234434, 180.23409, 2817.23847, "STAR_DUO"},
+};
+
+const STAR_COORD coords2[] = {
+		{305.34892, 53.4319, 9545.234, "STAR_TRE"},
+		{32.234434, 180.23409, 21348.78653, "STAR_QUA"},
+		{2.234434, 45.2239, 8746.1236, "STAR_CIN"},
+};
+
+void create_empty_test()
+{
+	star_index* pindex = star_index_create();
+	cpl_test(pindex);
+	star_index_delete(pindex);
+}
+cpl_table* create_data_table(double data_value)
+{
+	cpl_table* retval = cpl_table_new(1);
+	cpl_test(retval);
+	cpl_test(CPL_ERROR_NONE == cpl_table_new_column(retval, COL_NAME_DATA, CPL_TYPE_DOUBLE));
+	cpl_table_set_double(retval, COL_NAME_DATA, 0, data_value);
+	return retval;
+}
+void check_index(star_index* pindex, STAR_COORD* pcoords, int size)
+{
+	int i = 0;
+	for (i = 0; i < size; i++)
+	{
+		cpl_table* presult_data = star_index_get(pindex, pcoords[i].RA, pcoords[i].DEC, EPSILON, EPSILON, NULL);
+		cpl_test(presult_data);
+		int inull = 0;
+		double result_data = cpl_table_get_double(presult_data, COL_NAME_DATA, 0, &inull);
+		cpl_test_abs(result_data, pcoords[i].data_value, EPSILON);
+		cpl_table_delete(presult_data);
+	}
+}
+void fill_index(star_index* pindex, STAR_COORD* pcoords, int size)
+{
+	int i = 0;
+	for (i = 0; i < size; i++ )
+	{
+		cpl_table* pdata = create_data_table(pcoords[i].data_value);
+		star_index_add(pindex, pcoords[i].RA, pcoords[i].DEC, pcoords[i].STAR_NAME, pdata);
+		cpl_table_delete(pdata);
+	};
+}
+void add_data_test()
+{
+	star_index* pindex = star_index_create();
+	cpl_test(pindex);
+	int i = 0;
+	fill_index (pindex,coords, sizeof(coords) / sizeof(coords[0]));
+	check_index(pindex,coords, sizeof(coords) / sizeof(coords[0]));
+	star_index_save(pindex, FILE_NAME_FITS);
+	star_index_delete(pindex);
+}
+
+void load_file_test()
+{
+	star_index* pindex = star_index_load(FILE_NAME_FITS);
+	check_index(pindex, coords, sizeof(coords) / sizeof(coords[0]));
+	fill_index(pindex,coords2, sizeof(coords2) / sizeof(coords2[0]));
+	check_index(pindex,coords2, sizeof(coords2) / sizeof(coords2[0]));
+	check_index(pindex, coords, sizeof(coords) / sizeof(coords[0]));
+	// remove from cache and main
+	star_index_remove_by_name(pindex, coords[0].STAR_NAME);
+	star_index_remove_by_name(pindex, coords2[0].STAR_NAME);
+	check_index(pindex,coords2 + 1, sizeof(coords2) / sizeof(coords2[0]) - 1);
+	check_index(pindex, coords + 1, sizeof(coords) / sizeof(coords[0]) - 1);
+	// save, load and check again
+	star_index_save(pindex, FILE_NAME_FITS2);
+	star_index* pindex2 = star_index_load(FILE_NAME_FITS2);
+	cpl_test(pindex2);
+	check_index(pindex2,coords2 + 1, sizeof(coords2) / sizeof(coords2[0]) - 1);
+	check_index(pindex2, coords + 1, sizeof(coords) / sizeof(coords[0]) - 1);
+	star_index_delete(pindex);
+	star_index_delete(pindex2);
+}
+void create()
+{
+	star_index* pindex = star_index_load("star_index.fits");
+	star_index_delete(pindex);
+	return;
+	cpl_table* pdata = cpl_table_load("gd71_stisnic_002.fits",1,0);
+	if (pdata)
+	{
+		star_index_add(pindex, 88.115075, 15.88654, "gd71_stisnic", pdata);
+		cpl_table_delete(pdata);
+		star_index_save(pindex, "11star_index_v0_1.fits");
+	}
+	else
+	{
+		printf ("cannot load ref data\n");
+		cpl_error_reset();
+	}
+	star_index_delete(pindex);
+}
+
+int main(void)
+{
+	cpl_test_init(SINFO_STAR_BUG_REPORT, CPL_MSG_WARNING);
+	printf("test 1 \n");
+	create_empty_test();
+	printf("test 2 \n");
+	add_data_test();
+	printf("test 3 \n");
+	load_file_test();
+	printf("test 4 \n");
+	create();
+	return cpl_test_end(0);
+}
diff --git a/sinfoni/tests/sinfo_strehl_test.c b/sinfoni/tests/sinfo_strehl_test.c
new file mode 100644
index 0000000..c694a7b
--- /dev/null
+++ b/sinfoni/tests/sinfo_strehl_test.c
@@ -0,0 +1,1155 @@
+/*                                                                            *
+ *   This file is part of the ESO SINFO Pipeline                              *
+ *   Copyright (C) 2004,2005 European Southern Observatory                    *
+ *                                                                            *
+ *   This library is free software; you can redistribute it and/or modify     *
+ *   it under the terms of the GNU General Public License as published by     *
+ *   the Free Software Foundation; either version 2 of the License, or        *
+ *   (at your option) any later version.                                      *
+ *                                                                            *
+ *   This program is distributed in the hope that it will be useful,          *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of           *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
+ *   GNU General Public License for more details.                             *
+ *                                                                            *
+ *   You should have received a copy of the GNU General Public License        *
+ *   along with this program; if not, write to the Free Software              *
+ *   Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA     *
+ *                                                                           */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2009/06/05 06:06:11 $
+ * $Revision: 1.17 $
+ * $Name: sinfo-2_3_2 $
+ * $Log: sinfo_strehl_test.c,v $
+ * Revision 1.17  2009/06/05 06:06:11  amodigli
+ * updated init/end to cpl5
+ *
+ * Revision 1.16  2008/02/28 10:49:37  amodigli
+ * fixed compilation errors due to changed interface
+ *
+ * Revision 1.15  2008/02/12 10:09:49  amodigli
+ * shortened lines
+ *
+ * Revision 1.14  2008/02/12 09:09:52  amodigli
+ * fixed seg fault due to function name change
+ *
+ * Revision 1.13  2008/01/22 07:37:21  amodigli
+ * comment out tests wich require external input
+ *
+ * Revision 1.12  2008/01/22 07:34:44  amodigli
+ * cleaned output
+ *
+ * Revision 1.11  2008/01/17 07:21:54  amodigli
+ * removed clipm modeules
+ *
+ * Revision 1.10  2008/01/07 08:03:52  amodigli
+ * added tests to check MSM results
+ *
+ * Revision 1.9  2007/08/15 14:31:36  amodigli
+ * fixed errors in strehl computation, added expected-measured values
+ *
+ * Revision 1.8  2007/08/09 12:59:36  amodigli
+ * removed irplib_error_dump
+ *
+ * Revision 1.7  2007/07/28 13:33:05  amodigli
+ * fixed typo
+ *
+ * Revision 1.6  2007/07/27 06:29:51  amodigli
+ * replaced CPL_BPP_DEFAULT with CPL_BPP_IEEE_FLOAT
+ *
+ * Revision 1.5  2007/05/09 08:28:52  amodigli
+ * removed test3 and shortened line length
+ *
+ * Revision 1.4  2007/04/14 23:34:57  amodigli
+ * added test_strehl3 test_strehl4
+ *
+ * Revision 1.3  2007/04/06 07:10:06  amodigli
+ * cleaning
+ *
+ * Revision 1.2  2007/04/03 14:26:06  amodigli
+ * Factorised common variable setting
+ *
+ * Revision 1.1  2007/03/05 07:31:51  amodigli
+ * added sinfo_strehl_test
+ *
+ * Revision 1.1  2007/02/23 13:10:24  amodigli
+ * added test
+ *
+ */
+
+/*-----------------------------------------------------------------------------
+                                Includes
+ ----------------------------------------------------------------------------*/
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+
+#include <math.h>
+#include <cpl_test.h>
+#include <irplib_strehl.h>
+#include <cpl.h>
+#include <sinfo_new_psf.h>
+#include <sinfo_error.h>
+#include <sinfo_msg.h>
+#include <sinfo_utils_wrappers.h>
+/*-----------------------------------------------------------------------------
+                                Defines
+ ----------------------------------------------------------------------------*/
+#define SINFO_TEST_STREHL_M1                      8.0
+#define SINFO_TEST_STREHL_M2                       1.1
+#define SINFO_TEST_STREHL_BOX_SIZE                 64 
+#define SINFO_TEST_STREHL_WINDOW                   6
+#define SINFO_TEST_PSF_SZ                          3
+#define SINFO_TEST_PI   3.1415926535897932384626433832795028841971693993751058
+#define SINFO_TEST_STREHL_ERROR_COEFFICIENT    SINFO_TEST_PI * 0.007 / 0.0271
+#define SINFO_TEST_NOISE_NSAMPLES                100
+#define SINFO_TEST_NOISE_HSIZE                     4
+
+#define SINFO_TEST_FLUX0                        1.e6
+#define SINFO_TEST_BKG                          1.e2
+#define SINFO_TEST_EXP1                            1
+#define SINFO_TEST_EXP2                            1 //3
+#define SINFO_TEST_PS1                        0.025 //0.0125 half due 2K cam
+#define SINFO_TEST_PS2                             0.100 //0.05
+#define SINFO_TEST_NX                              64 // 64
+#define SINFO_TEST_NY                              64 // 64
+#define SINFO_TEST_SX                              4
+#define SINFO_TEST_SY                              4
+
+#define SINFO_TEST_WAV                             2.2
+#define SINFO_TEST_DWAV                            1.00352//0.543410
+//#define SINFO_TEST_DWAV                            0.543410
+#define SINFO_TEST_R1                             27//27
+#define SINFO_TEST_R2                             32//32
+#define SINFO_BKG_CSX 8
+#define SINFO_BKG_CSY 8
+
+
+
+
+/*-----------------------------------------------------------------------------
+                            Functions prototypes
+ ----------------------------------------------------------------------------*/
+
+/*---------------------------------------------------------------------------*/
+/**
+ * @defgroup sinfo_strehl_test  SINFO library unit tests
+ */
+/*---------------------------------------------------------------------------*/
+/**@{*/
+
+
+static void
+test_small(void)
+{
+
+  const char* name="xshTHE_vis.fits";
+  cpl_table* the=NULL;
+  cpl_propertylist* plist=NULL;
+  int nrow=0;
+  float* pf=NULL;
+  int* po=NULL;
+  int i=0;
+
+
+    check_nomsg(the=cpl_table_load("xshTHE_vis.fits",1,0));
+    check_nomsg(plist=cpl_propertylist_load("xshTHE_vis.fits",0));
+  
+  check_nomsg(cpl_table_erase_column(the,"Wavelength"));
+  check_nomsg(cpl_table_duplicate_column(the,"tmp",the,"IDENT"));
+  check_nomsg(cpl_table_cast_column(the,"tmp","Wavelength",CPL_TYPE_FLOAT));
+  check_nomsg(cpl_table_erase_column(the,"tmp"));
+
+  check_nomsg(cpl_table_cast_column(the,"x_position","detector_x",
+				    CPL_TYPE_DOUBLE));
+  check_nomsg(cpl_table_erase_column(the,"x_position"));
+
+  check_nomsg(cpl_table_cast_column(the,"y_position","detector_y",
+				    CPL_TYPE_DOUBLE));
+  check_nomsg(cpl_table_erase_column(the,"y_position"));
+
+  cpl_table_new_column(the,"Pippo",CPL_TYPE_INT);
+  po=cpl_table_get_data_int(the,"Pippo");
+  pf=cpl_table_get_data_float(the,"ORDER");
+  nrow=cpl_table_get_nrow(the);
+  for(i=0;i<nrow;i++) {
+    po[i]=1;
+  }
+  
+  for(i=0;i<nrow;i++) {
+    po[i]=(int)pf[i];
+  }
+
+  
+  check_nomsg(cpl_table_save(the,plist,NULL,"xshTHE_vis_new.fits",
+			     CPL_IO_DEFAULT));
+
+ cleanup:
+  sinfo_free_propertylist(&plist);
+  sinfo_free_table(&the);
+
+}
+
+/**
+   @brief      test PSF compuatation
+ */
+/*---------------------------------------------------------------------------*/
+static void
+test_flux(void)
+{
+
+  int mx=SINFO_BKG_CSX;
+  int my=SINFO_BKG_CSY;
+  int sx=SINFO_TEST_NX;
+  int sy=SINFO_TEST_NY;
+  cpl_image* mask=NULL;
+  cpl_image* img_w=NULL;
+  int* pm=NULL;
+  int i=0;
+  int j=0;
+
+  mask=cpl_image_new(sx,sy,CPL_TYPE_INT);
+  pm=cpl_image_get_data_int(mask);
+
+  //Fill 4 corners
+  for(j=0;j<my;j++) {
+    for(i=0;i<mx;i++) {
+      pm[i+j*sx]=1;
+    }
+  }
+
+  for(j=sy-my;j<my;j++) {
+    for(i=0;i<mx;i++) {
+      pm[i+j*sx]=1;
+    }
+  }
+
+
+
+  for(j=sy-my;j<my;j++) {
+    for(i=sx-mx;i<mx;i++) {
+      pm[i+j*sx]=1;
+    }
+  }
+
+
+  for(j=0;j<my;j++) {
+    for(i=sx-mx;i<mx;i++) {
+      pm[i+j*sx]=1;
+    }
+  }
+
+
+
+
+
+}
+
+
+
+/**
+   @brief      test PSF compuatation
+ */
+/*---------------------------------------------------------------------------*/
+cpl_error_code
+test_psf(void)
+{
+
+  double peak=0;
+  double m1=SINFO_TEST_STREHL_M1;
+  double m2=SINFO_TEST_STREHL_M2;
+  double w=2.2e-6;
+  double p1=0.0125;
+  double p2=0.0250;
+  double p3=0.0500;
+  double p4=0.100;
+  double pr=p2;
+
+  sinfo_msg_warning("change pixel scale");
+  /*
+  check(sinfo_compute_psf(m1,m2/m1,w,p1,0.,0.,1.,&peak),"test psf");
+  check(sinfo_compute_psf(m1,m2/m1,w,p2,0.,0.,1.,&peak),"test psf");
+  check(sinfo_compute_psf(m1,m2/m1,w,p3,0.,0.,1.,&peak),"test psf");
+  check(sinfo_compute_psf(m1,m2/m1,w,p4,0.,0.,1.,&peak),"test psf");
+
+
+  sinfo_msg_warning("change PSF centroid position");
+  check(sinfo_compute_psf(m1,m2/m1,w,pr,+0.0,+0.0,1.,&peak),"test psf");
+
+  check(sinfo_compute_psf(m1,m2/m1,w,pr,-1.0,+0.0,1.,&peak),"test psf");
+  check(sinfo_compute_psf(m1,m2/m1,w,pr,+0.0,-1.0,1.,&peak),"test psf");
+  check(sinfo_compute_psf(m1,m2/m1,w,pr,-1.0,-1.0,1.,&peak),"test psf");
+
+
+  check(sinfo_compute_psf(m1,m2/m1,w,pr,+1.0,+0.0,1.,&peak),"test psf");
+  check(sinfo_compute_psf(m1,m2/m1,w,pr,+0.0,+1.0,1.,&peak),"test psf");
+  check(sinfo_compute_psf(m1,m2/m1,w,pr,+1.0,+1.0,1.,&peak),"test psf");
+
+
+  check(sinfo_compute_psf(m1,m2/m1,w,pr,-2.0,-2.0,1.,&peak),"test psf");
+  check(sinfo_compute_psf(m1,m2/m1,w,pr,+2.0,+2.0,1.,&peak),"test psf");
+
+
+ check(sinfo_compute_psf(m1,m2/m1,w,pr,+0.5,+0.5,1.,&peak),"test psf");
+ check(sinfo_compute_psf(m1,m2/m1,w,pr,+0.5,+1.5,1.,&peak),"test psf");
+ check(sinfo_compute_psf(m1,m2/m1,w,pr,+0.5,+2.5,1.,&peak),"test psf");
+ check(sinfo_compute_psf(m1,m2/m1,w,pr,+0.5,+3.5,1.,&peak),"test psf");
+ check(sinfo_compute_psf(m1,m2/m1,w,pr,+0.5,+4.5,1.,&peak),"test psf");
+ check(sinfo_compute_psf(m1,m2/m1,w,pr,+0.5,+5.5,1.,&peak),"test psf");
+
+
+ check(sinfo_compute_psf(m1,m2/m1,w,pr,+0.5,-0.5,1.,&peak),"test psf");
+ check(sinfo_compute_psf(m1,m2/m1,w,pr,+1.5,-0.5,1.,&peak),"test psf");
+ check(sinfo_compute_psf(m1,m2/m1,w,pr,+2.5,-0.5,1.,&peak),"test psf");
+ check(sinfo_compute_psf(m1,m2/m1,w,pr,+3.5,-0.5,1.,&peak),"test psf");
+ check(sinfo_compute_psf(m1,m2/m1,w,pr,+4.5,-0.5,1.,&peak),"test psf");
+ check(sinfo_compute_psf(m1,m2/m1,w,pr,+5.5,-0.5,1.,&peak),"test psf");
+  */
+
+  /*
+ sinfo_msg_warning("change anamorphism");
+ check(sinfo_compute_psf(m1,m2/m1,w,pr,+0.0,+0.0,0.1,&peak),"test psf");
+ check(sinfo_compute_psf(m1,m2/m1,w,pr,+0.0,+0.0,0.3,&peak),"test psf");
+ check(sinfo_compute_psf(m1,m2/m1,w,pr,+0.0,+0.0,0.5,&peak),"test psf");
+ check(sinfo_compute_psf(m1,m2/m1,w,pr,+0.0,+0.0,0.7,&peak),"test psf");
+ check(sinfo_compute_psf(m1,m2/m1,w,pr,+0.0,+0.0,0.9,&peak),"test psf");
+ check(sinfo_compute_psf(m1,m2/m1,w,pr,+0.0,+0.0,1.0,&peak),"test psf");
+ check(sinfo_compute_psf(m1,m2/m1,w,pr,+0.0,+0.0,1.1,&peak),"test psf");
+ check(sinfo_compute_psf(m1,m2/m1,w,pr,+0.0,+0.0,1.3,&peak),"test psf");
+ check(sinfo_compute_psf(m1,m2/m1,w,pr,+0.0,+0.0,1.5,&peak),"test psf");
+ check(sinfo_compute_psf(m1,m2/m1,w,pr,+0.0,+0.0,1.7,&peak),"test psf");
+ check(sinfo_compute_psf(m1,m2/m1,w,pr,+0.0,+0.0,1.9,&peak),"test psf");
+
+
+
+ check(sinfo_compute_psf(m1,m2/m1,w,pr,+0.0,+0.0,-0.1,&peak),"test psf");
+ check(sinfo_compute_psf(m1,m2/m1,w,pr,+0.0,+0.0,-0.3,&peak),"test psf");
+ check(sinfo_compute_psf(m1,m2/m1,w,pr,+0.0,+0.0,-0.5,&peak),"test psf");
+ check(sinfo_compute_psf(m1,m2/m1,w,pr,+0.0,+0.0,-0.7,&peak),"test psf");
+ check(sinfo_compute_psf(m1,m2/m1,w,pr,+0.0,+0.0,-0.9,&peak),"test psf");
+ check(sinfo_compute_psf(m1,m2/m1,w,pr,+0.0,+0.0,-1.0,&peak),"test psf");
+ check(sinfo_compute_psf(m1,m2/m1,w,pr,+0.0,+0.0,-1.1,&peak),"test psf");
+ check(sinfo_compute_psf(m1,m2/m1,w,pr,+0.0,+0.0,-1.3,&peak),"test psf");
+ check(sinfo_compute_psf(m1,m2/m1,w,pr,+0.0,+0.0,-1.5,&peak),"test psf");
+ check(sinfo_compute_psf(m1,m2/m1,w,pr,+0.0,+0.0,-1.7,&peak),"test psf");
+ check(sinfo_compute_psf(m1,m2/m1,w,pr,+0.0,+0.0,-1.9,&peak),"test psf");
+  */
+
+ sinfo_msg_warning("Test given values");
+ check(sinfo_compute_psf(m1,m2/m1,w,p3,+3.78751,0.172931,1.,&peak),"test psf");
+ check(sinfo_compute_psf(m1,m2/m1,w,p3,+0.46594,0.534966,1.,&peak),"test psf");
+
+
+
+ cleanup:
+ 
+  if (cpl_error_get_code() != CPL_ERROR_NONE) {
+    return cpl_error_get_code();
+  } else {
+    return CPL_ERROR_NONE;
+  }
+}
+
+
+
+/**
+   @brief      test Strehl compuatation
+ */
+/*---------------------------------------------------------------------------*/
+static void
+test_strehl_one(void)
+{
+  const char* fname="med_img1_num1.fits";
+  cpl_image* ima=NULL;
+  double m1= SINFO_TEST_STREHL_M1;
+  double m2= SINFO_TEST_STREHL_M2;
+  double lam=2.2;
+
+  double dlam=0.543410;
+  double pscale=0.025;
+  //double pscale=0.10;
+  double xpos=0;
+  double ypos=0;
+  double r1=SINFO_TEST_R1*pscale;
+  double r2=SINFO_TEST_R1*pscale;
+  double r3=SINFO_TEST_R2*pscale;
+
+  int size=SINFO_TEST_STREHL_BOX_SIZE;
+  int noise_box_sz=SINFO_TEST_STREHL_BOX_SIZE;
+  int noise_nsamples=SINFO_TEST_NOISE_NSAMPLES;
+  double strehl=0;
+  double strehl_err=0;
+  double star_bkg=0;
+  double star_peak=0;
+  double star_flux=0;
+  double psf_peak=0;
+  double psf_flux=0;
+  double bg_noise=0;
+  cpl_bivector* iqe1=NULL;
+  double* piqe=NULL;
+  int sx=0;
+  int sy=0;
+
+
+  sinfo_msg_warning("ok11");
+  check_nomsg(ima=cpl_image_load(fname,CPL_TYPE_FLOAT,0,0));
+
+  sinfo_msg_warning("ok12");
+  
+  sx=cpl_image_get_size_x(ima);
+  sy=cpl_image_get_size_y(ima);
+  if(NULL != (iqe1=cpl_image_iqe(ima,1,1,64,64))) {
+
+
+    piqe=cpl_bivector_get_x_data(iqe1);
+    //*star_peak=piqe[5];
+    xpos=piqe[0];
+    ypos=piqe[1];
+    sinfo_msg_warning("xc=%f yc=%f",piqe[0],piqe[1]); 
+    sinfo_free_bivector(&iqe1);
+
+
+  } else {
+    xpos=sx/2;
+    ypos=sy/2;
+
+    sinfo_msg_warning("IQE fit failed"); 
+    cpl_error_reset();
+
+  }
+  
+  //check_nomsg(cpl_image_get_maxpos(ima,&xpos,&ypos));
+  sinfo_msg_warning("ok13 xpos=%g ypos=%g",xpos,ypos);
+  check_nomsg(sinfo_strehl_compute_one(ima,m1,m2,lam,dlam,pscale,
+                                       (int)xpos,(int)ypos,
+                                       r1,r2,r3,size,
+                                       &strehl,&strehl_err,
+                                       &star_bkg,&star_peak,&star_flux,
+                                       &psf_peak,&psf_flux,&bg_noise));
+
+  sinfo_msg_warning("ok14");
+
+  sinfo_msg_warning("strehl=%g",strehl);
+ cleanup:
+  sinfo_free_image(&ima);
+  sinfo_free_bivector(&iqe1);
+
+  return;
+
+}
+
+
+
+static void
+test_strehl_two(void)
+{
+  const char* fname1="med_img1_num4.fits";
+  const char* fname2="med_img2_num4.fits";
+  double exptime1=240; //120-150-60-240-60
+  double exptime2=60;  // 20- 30- 5- 60- 5
+  cpl_image* ima1=NULL;
+  cpl_image* ima2=NULL;
+  double m1= SINFO_TEST_STREHL_M1;
+  double m2= SINFO_TEST_STREHL_M2;
+  double lam=2.2;
+
+  double dlam=0.543410;
+  double pscale1=0.025;
+  double pscale2=0.10;
+  double xpos1=0;
+  double ypos1=0;
+  double xpos2=0;
+  double ypos2=0;
+  double r1=SINFO_TEST_R1*pscale1;
+  double r2=SINFO_TEST_R1*pscale1;
+  double r3=SINFO_TEST_R2*pscale1;
+
+  int size=SINFO_TEST_STREHL_BOX_SIZE;
+  int noise_box_sz=SINFO_TEST_STREHL_BOX_SIZE;
+  int noise_nsamples=SINFO_TEST_NOISE_NSAMPLES;
+  double strehl=0;
+  double strehl_err=0;
+  double star_bkg=0;
+  double star_peak=0;
+  double star_flux=0;
+  double psf_peak=0;
+  double psf_flux=0;
+  double bg_noise=0;
+  cpl_bivector* iqe1=NULL;
+  double* piqe=NULL;
+  int sx=0;
+  int sy=0;
+  int d=16;
+
+
+  sinfo_msg_warning("ok11");
+  check_nomsg(ima1=cpl_image_load(fname1,CPL_TYPE_FLOAT,0,0));
+  check_nomsg(ima2=cpl_image_load(fname2,CPL_TYPE_FLOAT,0,0));
+
+  sinfo_msg_warning("ok12");
+  
+  sx=cpl_image_get_size_x(ima1);
+  sy=cpl_image_get_size_y(ima1);
+  if(NULL != (iqe1=cpl_image_iqe(ima1,sx/2-d,sy/2-d,sx/2+d,sy/2+d))) {
+
+
+    piqe=cpl_bivector_get_x_data(iqe1);
+    //*star_peak=piqe[5];
+    xpos1=piqe[0];
+    ypos1=piqe[1];
+    sinfo_msg_warning("xc1=%f yc1=%f",piqe[0],piqe[1]); 
+    sinfo_msg_warning("peak1=%f",piqe[5]); 
+    sinfo_free_bivector(&iqe1);
+
+
+  } else {
+    xpos1=sx/2;
+    ypos1=sy/2;
+
+    sinfo_msg_warning("IQE fit failed"); 
+    cpl_error_reset();
+
+  }
+  
+  sinfo_msg_warning("ok13 xpos1=%g ypos1=%g",xpos1,ypos1);
+
+
+  sx=cpl_image_get_size_x(ima2);
+  sy=cpl_image_get_size_y(ima2);
+  if(NULL != (iqe1=cpl_image_iqe(ima2,sx/2-d,sy/2-d,sx/2+d,sy/2+d))) {
+
+
+    piqe=cpl_bivector_get_x_data(iqe1);
+    //*star_peak=piqe[5];
+    xpos2=piqe[0];
+    ypos2=piqe[1];
+    sinfo_msg_warning("xc2=%f yc2=%f",piqe[0],piqe[1]); 
+    sinfo_msg_warning("peak2=%f",piqe[5]); 
+    sinfo_free_bivector(&iqe1);
+
+
+  } else {
+    xpos2=sx/2;
+    ypos2=sy/2;
+
+    sinfo_msg_warning("IQE fit failed"); 
+    cpl_error_reset();
+
+  }
+  
+
+
+  //check_nomsg(cpl_image_get_maxpos(ima,&xpos,&ypos));
+  sinfo_msg_warning("ok13 xpos2=%g ypos2=%g",xpos2,ypos2);
+  check_nomsg(sinfo_strehl_compute_two(ima1,ima2,
+                                       m1,m2,
+                                       lam,
+				       pscale1,pscale2,
+                                       exptime1,exptime2,
+				       xpos1,ypos1,
+                                       xpos2,ypos2,
+                                       r1,r2,r3,
+                                       &strehl,&strehl_err,
+                                    &star_bkg,&star_peak,&star_flux,
+                                    &psf_peak,&psf_flux,&bg_noise));
+
+  sinfo_msg_warning("ok14");
+
+  sinfo_msg_warning("strehl=%g",strehl);
+ cleanup:
+  sinfo_free_image(&ima1);
+  sinfo_free_image(&ima2);
+  sinfo_free_bivector(&iqe1);
+
+  return;
+
+}
+
+/**
+   @brief      test Strehl compuatation
+ */
+/*---------------------------------------------------------------------------*/
+static void
+test_strehl(const double accuracy)
+{
+
+  const int nx=SINFO_TEST_NX;
+  const int ny=SINFO_TEST_NY;
+  double xcen=nx/2;
+  double ycen=ny/2;
+
+  double sig_x=SINFO_TEST_SX;
+  double sig_y=SINFO_TEST_SY;
+
+  double norm=SINFO_TEST_FLUX0;
+  double bkg_val=SINFO_TEST_BKG;
+  double min_pix=-sqrt(bkg_val);
+  double max_pix=+sqrt(bkg_val);
+
+
+  cpl_image* ima_obj=NULL;
+  cpl_image* ima_noise=NULL;
+
+  int max_ima_x=0;
+  int max_ima_y=0;
+
+  double lam=SINFO_TEST_WAV;
+  double dlam=SINFO_TEST_DWAV;
+
+  double pscale=SINFO_TEST_PS1;
+  double strehl_star_radius=SINFO_TEST_R1*pscale;
+  double strehl_bg_r1=SINFO_TEST_R1*pscale;
+  double strehl_bg_r2=SINFO_TEST_R2*pscale;
+
+  double strehl=0;
+  double strehlm=0;
+  double strehl_err=0;
+  double star_bkg=0;
+  double star_peak=0;
+  double star_flux=0;
+
+  double flux=norm;
+  double fluxm=0;
+  double noise_min=min_pix;
+  double noise_max=max_pix;
+  double bkg=bkg_val;
+  double bkgm=bkg_val;
+  int bkg_sx=SINFO_BKG_CSX;
+  int bkg_sy=SINFO_BKG_CSY;
+
+  double psf_peak=0;
+  double psf_flux=0;
+  double bkg_noise=0;
+  double bkg_stdevm=0;
+  double* dx=NULL;
+  //double fct=sqrt(2*log(2));
+  cpl_bivector* ima_qual=NULL;
+  cpl_image* psf=NULL;
+
+  sinfo_msg_warning("Strehl Test1 pscale=%f",pscale);
+  check_nomsg(ima_obj=cpl_image_new(nx,ny,CPL_TYPE_FLOAT));
+  check_nomsg(ima_noise=cpl_image_new(nx,ny,CPL_TYPE_FLOAT));
+  check_nomsg(cpl_image_fill_gaussian(ima_obj,xcen,ycen,flux,sig_x,sig_y));
+  check_nomsg(cpl_image_fill_noise_uniform(ima_noise,noise_min,noise_max));
+
+  fluxm=cpl_image_get_flux(ima_obj);
+
+  assure(fabs((fluxm-flux)/flux) <accuracy, CPL_ERROR_UNSPECIFIED,
+	 "Flux ima[e/m]=[%g/%g]",flux,fluxm);
+
+  check_nomsg(cpl_image_add(ima_obj,ima_noise));
+  check_nomsg(cpl_image_add_scalar(ima_obj,bkg));
+
+  check_nomsg(sinfo_get_bkg_4corners(ima_obj,bkg_sx,bkg_sy,&bkgm,&bkg_stdevm));
+
+  sinfo_get_flux_above_bkg(ima_obj,2,bkg_stdevm,&fluxm);
+  sinfo_msg_warning("flux=%g",fluxm);
+  assure(fabs((bkgm-bkg)/bkg) <accuracy,CPL_ERROR_UNSPECIFIED,
+	 "Bkg  ima[e/m]=[%g/%g]", bkg,bkgm);
+
+
+  check_nomsg(ima_qual=cpl_image_iqe(ima_obj,1,1,nx,nx));
+  dx=cpl_bivector_get_x_data(ima_qual);
+
+
+  assure(fabs((bkgm-bkg)/bkg) <accuracy,CPL_ERROR_UNSPECIFIED,
+	 "Bkg  ima[e/m]=[%g/%g]", bkg,bkgm);
+
+
+  assure(fabs((dx[0]-xcen)/xcen) <accuracy,CPL_ERROR_UNSPECIFIED,
+               "Image quality: X [e/m]=[%f/%f]",
+		    xcen,dx[0]);
+
+
+  assure(fabs((dx[1]-ycen)/ycen) <accuracy,CPL_ERROR_UNSPECIFIED,
+               "Image quality: Y [e/m]=[%f/%f]",
+		    ycen,dx[1]);
+
+
+
+  sinfo_msg_warning("Image quality: FWHM_X[m/'']=%f/%f FWHM_Y[m/'']="
+		    "%f/%f pscale=%f",
+		    dx[2],dx[2]*pscale,dx[3],dx[3]*pscale,pscale);
+  //sinfo_msg_warning("Image quality: SIG_X=%f SIG_Y=%f",fct*dx[2],fct*dx[3]);
+  sinfo_msg_warning("Image quality: ANGLE=%f Peak=%g BKG=%g",dx[4],dx[5],dx[6]);
+  psf = irplib_strehl_generate_psf(SINFO_TEST_STREHL_M1,
+				   SINFO_TEST_STREHL_M2,
+				   lam, dlam, pscale,
+				   SINFO_TEST_STREHL_BOX_SIZE);
+
+  psf_peak = cpl_image_get_max(psf) ;
+
+  cpl_image_delete(psf) ;
+
+  sinfo_msg_warning("psf_peak=%f",psf_peak);
+
+
+  assure(fabs((dx[1]-ycen)/ycen) <accuracy,CPL_ERROR_UNSPECIFIED,
+               "Image quality: Y [e/m]=[%f/%f]",
+		    ycen,dx[1]);
+
+
+  strehl=((dx[5]-SINFO_TEST_BKG)/flux)/psf_peak;
+  strehlm=((dx[5]-bkgm)/(cpl_image_get_flux(ima_obj)-bkgm*nx*ny))/psf_peak;
+
+  assure(fabs((strehlm-strehl)/strehl) <accuracy,CPL_ERROR_UNSPECIFIED,
+               "Strehl: [e/m]=[%f/%f]",strehl,strehlm);
+
+  check_nomsg(cpl_image_save(ima_obj,"out_strehl.fits", CPL_BPP_IEEE_FLOAT, 
+			     NULL,CPL_IO_DEFAULT));
+ 
+  check_nomsg(cpl_image_get_maxpos(ima_obj,&max_ima_x,&max_ima_y));
+  /*
+  sinfo_msg("input par: ima=%p,M1=%f,M2=%f,lam=%f,dlam=%f,pscale=%f,"
+	    "BOX_SIZE=%d,max_ima_x=%d,max_ima_y=%d,star_radius=%f,bg_r1=%f,"
+            "bg_r2=%f,HSIZE=%d,NSAMPLES=%d",
+             ima_obj,
+                                            SINFO_TEST_STREHL_M1,
+                                             SINFO_TEST_STREHL_M2,
+                                             lam,
+                                             dlam,
+                                             pscale,
+			                     SINFO_TEST_STREHL_BOX_SIZE,
+                                             max_ima_x,
+                                             max_ima_y,
+			                     strehl_star_radius,
+                                             strehl_bg_r1,
+                                             strehl_bg_r2,
+		 	                     SINFO_TEST_NOISE_HSIZE,
+                                             SINFO_TEST_NOISE_NSAMPLES);
+  */
+
+
+  if(CPL_ERROR_NONE != sinfo_strehl_compute_one(ima_obj,
+                                             SINFO_TEST_STREHL_M1,
+                                             SINFO_TEST_STREHL_M2,
+                                             lam,
+                                             dlam,
+                                             pscale,
+                                             max_ima_x,
+                                             max_ima_y,
+			                     strehl_star_radius,
+                                             strehl_bg_r1,
+                                             strehl_bg_r2,
+			                     SINFO_TEST_STREHL_BOX_SIZE,
+			                     &strehl,
+                                             &strehl_err,
+                                             &star_bkg,
+                                             &star_peak,
+                                             &star_flux,
+			                     &psf_peak,
+                                             &psf_flux,
+                                             &bkg_noise)) {
+
+
+     sinfo_msg_warning("Problem computing strehl");
+     strehl=-1;
+     strehl_err=0;
+
+  }
+
+  sinfo_msg_warning("strehl=%f strehl_err=%f "
+                    "star_bkg=%g star_peak=%g star_flux=%g "
+                    "psf_peak=%g psf_flux=%g bkg_noise=%g",
+                    strehl,strehl_err,
+                    star_bkg,star_peak,star_flux,
+                    psf_peak,psf_flux,bkg_noise);
+  sinfo_msg_warning("--------END-----");
+
+
+ cleanup:
+  sinfo_free_bivector(&ima_qual);
+  sinfo_free_image(&ima_obj);
+  sinfo_free_image(&ima_noise);
+  return;
+
+}
+
+
+/**
+   @brief      test streehl compuatation
+ */
+/*----------------------------------------------------------------------------*/
+static void
+test_strehl2(const double accuracy)
+{
+
+  const int nx=SINFO_TEST_NX;
+  const int ny=SINFO_TEST_NY;
+  double xcen=nx/2;
+  double ycen=ny/2;
+
+  double norm=SINFO_TEST_FLUX0;
+
+  cpl_image* ima1_obj=NULL;
+  cpl_image* ima1_noise=NULL;
+  cpl_image* ima2_obj=NULL;
+  cpl_image* ima2_noise=NULL;
+
+
+  double bkg_val=SINFO_TEST_BKG;
+  double min_pix=-sqrt(bkg_val);
+  double max_pix=+sqrt(bkg_val);
+  int max_ima_x1=0;
+  int max_ima_y1=0;
+  int max_ima_x2=0;
+  int max_ima_y2=0;
+
+  double lam=SINFO_TEST_WAV;
+  double dlam=SINFO_TEST_DWAV;
+
+  double pscale1=SINFO_TEST_PS1;
+  double pscale2=SINFO_TEST_PS2;
+  double t1=SINFO_TEST_EXP1; //9
+  double t2=SINFO_TEST_EXP2; //3
+
+  double frat=sinfo_scale_flux(pscale1,pscale2,t1,t2);
+
+  double sig1_x=SINFO_TEST_SX;
+  double sig1_y=SINFO_TEST_SY;
+  double sig2_x=SINFO_TEST_SX*pscale1/pscale2;
+  double sig2_y=SINFO_TEST_SY*pscale1/pscale2;
+
+
+  double strehl_star_radius=SINFO_TEST_R1*pscale2;
+  double strehl_bg_r1=SINFO_TEST_R1*pscale2;
+  double strehl_bg_r2=SINFO_TEST_R2*pscale2;
+
+  double strehl=0;
+  double strehl_err=0;
+  double star_bkg=0;
+  double star_peak=0;
+  double star_flux=0;
+
+  double psf_peak=0;
+  double psf_peak1=0;
+  double psf_peak2=0;
+  double psf_flux=1;
+  //double psf_flux1=1;
+  //double psf_flux2=1;
+  double bkg_noise=0;
+  cpl_bivector* ima_qual=NULL;
+  double* dx=NULL;
+
+  double bkg1=bkg_val;
+  double bkg2=bkg_val*frat;
+  double flux1=norm;
+  double flux2=norm*t2/t1;
+  double fluxm1=0;
+  double fluxm2=0;
+  double prat=pscale2/pscale1;
+  double prat2=prat*prat;
+		   
+
+
+
+  double noise_min1=min_pix;
+  double noise_min2=min_pix*frat;
+
+  double noise_max1=max_pix;
+  double noise_max2=max_pix*frat;
+  double peak1=0;
+  double peak2=0;
+  cpl_image* psf1=NULL;
+  cpl_image* psf2=NULL;
+  //double fct=sqrt(2*log(2));
+
+
+  double bkg1m=bkg_val;
+  double bkg2m=bkg_val;
+  double bkg_stdev1m=0;
+  double bkg_stdev2m=0;
+
+  int bkg_sx=SINFO_BKG_CSX;
+  int bkg_sy=SINFO_BKG_CSY;
+
+  sinfo_msg_warning("Strehl Test2: Flux1=%g Bkg1=%g Flux2=%g Bkg2=%g frat=%g",
+	    flux1,bkg1,flux2,bkg2,frat);
+  check_nomsg(ima1_obj=cpl_image_new(nx,ny,CPL_TYPE_FLOAT));
+  check_nomsg(ima1_noise=cpl_image_new(nx,ny,CPL_TYPE_FLOAT));
+  check_nomsg(ima2_obj=cpl_image_new(nx,ny,CPL_TYPE_FLOAT));
+  check_nomsg(ima2_noise=cpl_image_new(nx,ny,CPL_TYPE_FLOAT));
+
+  check_nomsg(cpl_image_fill_gaussian(ima1_obj,xcen,ycen,flux1,sig1_x,sig1_y));
+  check_nomsg(cpl_image_fill_noise_uniform(ima1_noise,noise_min1,noise_max1));
+
+  check_nomsg(cpl_image_fill_gaussian(ima2_obj,xcen,ycen,flux2,sig2_x,sig2_y));
+  check_nomsg(cpl_image_fill_noise_uniform(ima2_noise,noise_min2,noise_max2));
+
+
+  fluxm1=cpl_image_get_flux(ima1_obj);
+  fluxm2=cpl_image_get_flux(ima2_obj);
+
+  //assure(fabs((fluxm1-flux1)/flux1) <accuracy, CPL_ERROR_UNSPECIFIED,
+  // "Flux1 ima[e/m]=[%g/%g]",flux1,fluxm1);
+
+  //assure(fabs((fluxm2-flux2)/flux2) <accuracy, CPL_ERROR_UNSPECIFIED,
+  // "Flux2 ima[e/m]=[%g/%g]",flux2,fluxm2);
+
+   
+
+
+  check_nomsg(cpl_image_add(ima1_obj,ima1_noise));
+  check_nomsg(cpl_image_add_scalar(ima1_obj,bkg1));
+
+  check_nomsg(ima_qual=cpl_image_iqe(ima1_obj,1,1,nx,ny));
+  dx=cpl_bivector_get_x_data(ima_qual);
+
+
+  //assure(fabs((dx[0]-xcen)/xcen) <accuracy,CPL_ERROR_UNSPECIFIED,
+  //           "Image1 quality: X [e/m]=[%f/%f]",xcen,dx[0]);
+
+  //assure(fabs((dx[1]-ycen)/ycen) <accuracy,CPL_ERROR_UNSPECIFIED,
+  //             "Image1 quality: X [e/m]=[%f/%f]",ycen,dx[1]);
+
+
+  sinfo_msg_warning("Image1 quality: FWHM_X[m/'']=%f/%f FWHM_Y[m/'']=%f/%f",
+		    dx[2],dx[2]*pscale1,dx[3],dx[3]*pscale1);
+
+  //sinfo_msg_warning("Image1 quality: SIG_X=%f SIG_Y=%f",fct*dx[2],fct*dx[3]);
+  sinfo_msg_warning("Image1 quality: ANGLE=%f",dx[4]);
+  sinfo_msg_warning("Image1 quality: Peak=%g BKG=%g",dx[5],dx[6]);
+
+  peak1=cpl_image_get_max(ima1_obj);
+
+  check_nomsg(sinfo_get_bkg_4corners(ima1_obj,bkg_sx,bkg_sy,
+				     &bkg1m,&bkg_stdev1m));
+
+
+
+  sinfo_msg_warning("4 corners Bkg1  [e/m]=[%g/%g]", bkg1,bkg1m);
+  sinfo_msg_warning("Image1 peak=%g BKG=%g",peak1,bkg1m);
+  sinfo_free_bivector(&ima_qual);
+
+  sinfo_get_flux_above_bkg(ima1_obj,2,bkg_stdev1m,&fluxm1);
+
+
+
+
+
+  check_nomsg(cpl_image_add(ima2_obj,ima2_noise));
+  check_nomsg(cpl_image_add_scalar(ima2_obj,bkg2));
+
+  check_nomsg(ima_qual=cpl_image_iqe(ima2_obj,1,1,nx,ny));
+  dx=cpl_bivector_get_x_data(ima_qual);
+
+  //assure(fabs((dx[0]-xcen)/xcen) <accuracy,CPL_ERROR_UNSPECIFIED,
+  //             "Image1 quality: X [e/m]=[%f/%f]",xcen,dx[0]);
+
+  //assure(fabs((dx[1]-ycen)/ycen) <accuracy,CPL_ERROR_UNSPECIFIED,
+  //             "Image1 quality: X [e/m]=[%f/%f]",ycen,dx[1]);
+
+  sinfo_msg_warning("Image2 quality: FWHM_X[m/'']=%f/%f FWHM_Y[m/'']=%f/%f",
+		    dx[2],dx[2]*pscale2,dx[3],dx[3]*pscale2);
+  //sinfo_msg_warning("Image2 quality: SIG_X=%f SIG_Y=%f",fct*dx[2],fct*dx[3]);
+  sinfo_msg_warning("Image2 quality: ANGLE=%f",dx[4]);
+  sinfo_msg_warning("Image1 quality: Peak=%g BKG=%g",dx[5],dx[6]);
+
+  
+  peak2=cpl_image_get_max(ima2_obj);
+
+  check_nomsg(sinfo_get_bkg_4corners(ima2_obj,bkg_sx,bkg_sy,
+				     &bkg2m,&bkg_stdev2m));
+
+  sinfo_msg_warning("4 corners Bkg2  [e/m]=%g/%g", bkg2,bkg2m);
+  sinfo_msg_warning("Image1 peak=%g BKG=%g",peak2,bkg2m);
+
+  sinfo_get_flux_above_bkg(ima2_obj,2,bkg_stdev2m,&fluxm2);
+ 
+
+
+
+  sinfo_msg_warning("Scaled Bkg1 [e/m]=%g/%g",bkg1,bkg2m/frat);
+
+  bkg1m=bkg2m/frat;
+
+  psf1 = irplib_strehl_generate_psf(SINFO_TEST_STREHL_M1,
+				   SINFO_TEST_STREHL_M2,
+				   lam, dlam, pscale1,
+				   SINFO_TEST_STREHL_BOX_SIZE);
+
+  psf_peak1 = cpl_image_get_max(psf1) ;
+
+  sinfo_free_image(&psf1) ;
+
+  sinfo_msg_warning("psf peak1=%g",psf_peak1);
+
+  sinfo_msg_warning("Strehl1 [e/m]=%g/%g",
+	    (peak1-bkg1)/flux1/psf_peak1,
+	    (peak1-bkg1m)/
+            ((cpl_image_get_flux(ima1_obj)-bkg1m*nx*ny))/psf_peak1);
+
+  psf2 = irplib_strehl_generate_psf(SINFO_TEST_STREHL_M1,
+				   SINFO_TEST_STREHL_M2,
+				   lam, dlam, pscale2,
+				   SINFO_TEST_STREHL_BOX_SIZE);
+
+  psf_peak2 = cpl_image_get_max(psf2) ;
+
+  sinfo_free_image(&psf2) ;
+
+  sinfo_msg_warning("psf peak2=%g",psf_peak2);
+
+  sinfo_msg_warning("Strehl2 [e/m]=%g/%g",
+	   (peak2-bkg2)/flux2/psf_peak1,
+	    (peak2-bkg2m)/(cpl_image_get_flux(ima2_obj)-bkg2m*nx*ny)/
+             psf_peak1);
+
+  sinfo_free_bivector(&ima_qual);
+
+  check_nomsg(cpl_image_save(ima1_obj,"out_strehl1.fits", CPL_BPP_IEEE_FLOAT, 
+			     NULL,CPL_IO_DEFAULT));
+
+  check_nomsg(cpl_image_save(ima2_obj,"out_strehl2.fits", CPL_BPP_IEEE_FLOAT, 
+			     NULL,CPL_IO_DEFAULT));
+ 
+  check_nomsg(cpl_image_get_maxpos(ima1_obj,&max_ima_x1,&max_ima_y1));
+  check_nomsg(cpl_image_get_maxpos(ima2_obj,&max_ima_x2,&max_ima_y2));
+  /*
+  sinfo_msg("input par: ima=%p,M1=%f,M2=%f,lam=%f,dlam=%f,pscale=%f,"
+	    "BOX_SIZE=%d,max_ima_x=%d,max_ima_y=%d,star_radius=%f,bg_r1=%f,"
+            "bg_r2=%f,HSIZE=%d,NSAMPLES=%d",
+             ima_obj,
+                                            SINFO_TEST_STREHL_M1,
+                                             SINFO_TEST_STREHL_M2,
+                                             lam,
+                                             dlam,
+                                             pscale,
+			                     SINFO_TEST_STREHL_BOX_SIZE,
+                                             max_ima_x,
+                                             max_ima_y,
+			                     strehl_star_radius,
+                                             strehl_bg_r1,
+                                             strehl_bg_r2,
+		 	                     SINFO_TEST_NOISE_HSIZE,
+                                             SINFO_TEST_NOISE_NSAMPLES);
+  */
+
+  if(CPL_ERROR_NONE != sinfo_strehl_compute_two(ima1_obj,ima2_obj,
+                                             SINFO_TEST_STREHL_M1,
+                                             SINFO_TEST_STREHL_M2,
+                                             lam,
+                                             pscale1,
+                                             pscale2,
+					     t1,
+                                             t2,
+                                             max_ima_x1,
+                                             max_ima_y1,
+                                             max_ima_x2,
+                                             max_ima_y2,
+			                     strehl_star_radius,
+                                             strehl_bg_r1,
+                                             strehl_bg_r2,
+			                     &strehl,
+                                             &strehl_err,
+                                             &star_bkg,
+                                             &star_peak,
+                                             &star_flux,
+			                     &psf_peak,
+                                             &psf_flux,
+                                             &bkg_noise)) {
+
+
+     sinfo_msg_warning("Problem computing strehl");
+     strehl=-1;
+     strehl_err=0;
+
+  }
+
+  sinfo_msg_warning("strehl=%g strehl_err=%g star_bkg=%g "
+                    "star_peak=%g star_flux=%g "
+		    "psf_peak=%g psf_flux=%g bkg_noise=%g",
+		    strehl,strehl_err,star_bkg,star_peak,star_flux,psf_peak,
+		    psf_flux,bkg_noise);
+
+
+
+  sinfo_msg_warning("Combined Strehl1 [e/m]=%10.8g/%10.8g",
+		    (peak1-bkg2/frat)/(flux2/frat)/psf_peak1,
+		    (peak1-bkg2m/frat)/
+                    ((cpl_image_get_flux(ima2_obj)-bkg2m*nx*ny)/frat)/
+		    psf_peak1);
+
+
+ sinfo_msg_warning("Correct Combined Strehl1 [e/m]=%10.8g/%10.8g",
+		   (peak1-bkg2/frat)/(flux2/frat)/psf_peak1/prat2,
+		    (peak1-bkg2m/frat)/
+                    ((cpl_image_get_flux(ima2_obj)-bkg2m*nx*ny)/frat)/
+		   psf_peak1/prat2);
+
+  sinfo_msg_warning("peak_psf1=%g psf_peak2=%g",psf_peak1,psf_peak2);
+  sinfo_msg_warning("prat2=%g",prat2);
+
+  sinfo_msg_warning("Combined Strehl2 [e/m]=%g/%g",
+		    (peak2-bkg1*frat)/(flux1*frat)/psf_peak1,
+		    (peak2-bkg1m*frat)/
+                    ((cpl_image_get_flux(ima1_obj)-bkg1m*nx*ny)*frat)/
+		    psf_peak1);
+
+
+ sinfo_msg_warning("Correct Combined Strehl2 [e/m]=%g/%g",
+		    (peak2-bkg1*frat)/(flux1*frat)/psf_peak1*prat2,
+		    (peak2-bkg1m*frat)/
+                    ((cpl_image_get_flux(ima1_obj)-bkg1m*nx*ny)*frat)/
+		    psf_peak1*prat2);
+
+
+ cleanup:
+
+  sinfo_free_bivector(&ima_qual);
+  sinfo_free_image(&ima1_obj);
+  sinfo_free_image(&ima1_noise);
+  sinfo_free_image(&ima2_obj);
+  sinfo_free_image(&ima2_noise);
+  sinfo_free_image(&psf1) ;
+  sinfo_free_image(&psf2) ;
+  ;
+  return;
+
+}
+
+
+
+   
+/*----------------------------------------------------------------------------*/
+/**
+  @brief   SINFONI pipeline unit test for skycor
+
+**/
+/*----------------------------------------------------------------------------*/
+
+
+int main(int args, char *argv[])
+{
+  cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
+  cpl_errorstate initial_errorstate = cpl_errorstate_get();
+
+  /* Initialize CPL + SINFO messaging */
+  printf("Hello World!\n");
+  //check(test_strehl(0.003),"Fail testing strehl");
+  //check(test_strehl2(0.003),"Fail testing strehl");
+  //check(test_strehl4(),"Fail testing strehl");
+  //check(test_psf(),"Fail testing psf");
+  //check(test_strehl_one(),"Fail test_strehl_one");
+  //check(test_strehl_two(),"Fail test_strehl_two");
+  //check(test_small(),"Fail test_small");
+
+
+
+    if (!cpl_errorstate_is_equal(initial_errorstate)) {                      
+        /* Dump the error history since recipe execution start.                
+           At this point the recipe cannot recover from the error */           
+        cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);              
+    } 
+
+ cleanup:
+
+  return cpl_test_end(0);
+}
+
+
+/**@}*/
diff --git a/sinfoni/tests/sinfo_table_ops_test.c b/sinfoni/tests/sinfo_table_ops_test.c
new file mode 100644
index 0000000..d97d2e5
--- /dev/null
+++ b/sinfoni/tests/sinfo_table_ops_test.c
@@ -0,0 +1,173 @@
+/*                                                                            *
+ *   This file is part of the ESO SINFO Pipeline                              *
+ *   Copyright (C) 2004,2005 European Southern Observatory                    *
+ *                                                                            *
+ *   This library is free software; you can redistribute it and/or modify     *
+ *   it under the terms of the GNU General Public License as published by     *
+ *   the Free Software Foundation; either version 2 of the License, or        *
+ *   (at your option) any later version.                                      *
+ *                                                                            *
+ *   This program is distributed in the hope that it will be useful,          *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of           *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
+ *   GNU General Public License for more details.                             *
+ *                                                                            *
+ *   You should have received a copy of the GNU General Public License        *
+ *   along with this program; if not, write to the Free Software              *
+ *   Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA     *
+ *                                                                           */
+ 
+/*
+ * $Author: amodigli $
+ * $Date: 2012/04/26 15:23:49 $
+ * $Revision: 1.5 $
+ * $Name: sinfo-2_3_2 $
+ * $Log: sinfo_table_ops_test.c,v $
+ * Revision 1.5  2012/04/26 15:23:49  amodigli
+ * cleaned errors from Jenkins static checks
+ *
+ * Revision 1.4  2009/06/05 06:06:11  amodigli
+ * updated init/end to cpl5
+ *
+ * Revision 1.3  2008/08/26 11:21:05  amodigli
+ * separate comments
+ *
+ * Revision 1.2  2008/02/12 10:09:49  amodigli
+ * shortened lines
+ *
+ * Revision 1.1  2007/08/29 10:59:37  amodigli
+ * added to repository
+ *
+ * Revision 1.2  2007/08/10 06:36:47  amodigli
+ * fixed leaks
+ *
+ * Revision 1.1  2007/08/09 13:00:31  amodigli
+ * added to repository
+ *
+ * Revision 1.2  2007/03/27 14:38:48  amodigli
+ * fixed compilation warnings
+ *
+ * Revision 1.1  2007/02/23 13:10:24  amodigli
+ * added test
+ *
+ */
+
+/*-----------------------------------------------------------------------------
+                                Includes
+ -----------------------------------------------------------------------------*/
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+#include <stdio.h>
+#include <math.h>
+
+#include <cpl.h>
+#include <cpl_test.h>
+#include <sinfo_globals.h>
+#include <sinfo_pro_save.h>
+#include <sinfo_error.h>
+#include <sinfo_msg.h>
+#include <sinfo_utils_wrappers.h>
+/*-----------------------------------------------------------------------------
+                                Defines
+ -----------------------------------------------------------------------------*/
+
+/*-----------------------------------------------------------------------------
+                            Functions prototypes
+ -----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------*/
+/**
+ * @defgroup sinfo_table_ops_test  SINFO library unit tests
+ */
+/*----------------------------------------------------------------------------*/
+/**@{*/
+   
+
+
+
+
+
+/**
+   @brief      test streehl compuatation
+ */
+/*---------------------------------------------------------------------------*/
+#define SIZE 80
+static void
+test_table_flag_nan(void)
+{
+ 
+  cpl_table* tab=NULL;
+  const int sz=10;
+  int i=0;
+
+   int* pseq=NULL;
+  double* pval=NULL;
+
+
+  check_nomsg(tab=cpl_table_new(sz));
+  check_nomsg(cpl_table_new_column(tab,"SEQ",CPL_TYPE_INT));
+  check_nomsg(cpl_table_new_column(tab,"VAL",CPL_TYPE_DOUBLE));
+  check_nomsg(cpl_table_fill_column_window_int(tab,"SEQ",0,sz,0));
+  check_nomsg(cpl_table_fill_column_window_double(tab,"VAL",0,sz,0));
+
+
+  check_nomsg(pseq=cpl_table_get_data_int(tab,"SEQ"));
+  check_nomsg(pval=cpl_table_get_data_double(tab,"VAL"));
+
+  for(i=0;i<sz;i++) {
+    sinfo_msg_warning("pval=%f",pval[i]);
+    sinfo_msg_warning("pseq=%f",pseq[i]);
+    check_nomsg(pseq[i]=i);
+    check_nomsg(pval[i]=(double)sqrt(fabs(i)));
+    sinfo_msg("seg=%d val=%g",pseq[i],pval[i]);
+
+  }
+  check_nomsg(cpl_table_set_double(tab,"VAL",sz/2,ZERO));
+  cpl_table_dump(tab,0,sz,stdout);
+  check_nomsg(cpl_table_save(tab, NULL, NULL,"tab.fits", CPL_IO_DEFAULT));
+  for(i=0;i<sz;i++) {
+    if(isnan(pval[i])) {
+      cpl_table_set_invalid(tab,"VAL",i);
+      cpl_table_set_invalid(tab,"SEQ",i);
+      sinfo_msg_warning("pval=%f pseq=%f",pval[i],pseq[i]);
+    }
+  }
+
+  check_nomsg(cpl_table_save(tab, NULL, NULL,"tab_flag.fits", CPL_IO_DEFAULT));
+ 
+
+ cleanup:
+ 
+  sinfo_free_table(&tab);
+ 
+ 
+  return;
+
+}
+/*----------------------------------------------------------------------------*/
+/**
+  @brief   SINFONI pipeline unit test for cube coadd
+
+**/
+/*----------------------------------------------------------------------------*/
+
+int main(void)
+{
+
+  cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
+  cpl_errorstate ESTATE=cpl_errorstate_get();
+
+  check(test_table_flag_nan(),"Fail testing table NAN flagging");
+
+  cleanup:
+  cpl_errorstate_dump(ESTATE, CPL_FALSE, cpl_errorstate_dump_one);
+
+  return cpl_test_end(0);
+
+}
+
+
+/**@}*/
diff --git a/sinfoni/tests/test_atmo_disp.c b/sinfoni/tests/test_atmo_disp.c
new file mode 100644
index 0000000..3e20d8e
--- /dev/null
+++ b/sinfoni/tests/test_atmo_disp.c
@@ -0,0 +1,1080 @@
+/*
+ * This file is part of the ESO SINFONI Pipeline
+ * Copyright (C) 2004-2009 European Southern Observatory
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * $Author: amodigli $
+ * $Date: 2010/02/08 07:20:07 $
+ * $Revision: 1.8 $
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#include <stdio.h>
+#include <cpl.h>
+#include <cpl_test.h>
+#include <sinfo_atmo_disp.h>
+#include <sinfo_utils_wrappers.h>
+#include <sinfo_utilities.h>
+#include <sinfo_msg.h>
+
+const char* SINFO_STAR_BUG_REPORT = "kmirny at eso.org";
+const double EPSILON = 1E-8;
+const char* COL_NAME_ID = "id";
+const char* COL_NAME_CENTRE_X = "center_x";
+const char* COL_NAME_CENTRE_Y = "center_y";
+const char* COL_NAME_AIRMASS = "airmass";
+const char* COL_NAME_WAVELENGTH = "wavelength";
+const char* COL_NAME_ANGLE = "angle";
+const char* COL_NAME_OFFSET_X = "offset_x";
+const char* COL_NAME_OFFSET_Y = "offset_y";
+static void atmo_process_fits_data_file(cpl_table** ptable, const char* filename,
+		double general_lambda0);
+static void atmo_save_gauss_info(cpl_table * ptable, cpl_imagelist* pCube);
+static cpl_error_code atmo_disp_load_params(		const char* fits_file,
+		int * centpix,
+		double* lambda0,
+		double *Tc,
+		double* rh,
+		double* airm,
+		double* p,
+		double*	parallactic,
+		double* pixelscale,
+		double* pixelsz);
+static void atmo_test_dispersion_cube( const char* fits_file, const char* out_file);
+static double atmo_get_general_lambda0(const char* fits_file);
+static void atmo_init_offset_table(cpl_table** big_table, int big_table_size);
+static void atmo_rotate_offset(cpl_table* ptable, double rot_angle);
+static void atmo_rotate_point(double* x_value, double* y_value, double rot_angle);
+static void atmo_prepare_offset_table(const char* cfg_filename,
+		const char* output_filename);
+static cpl_polynomial*  atmo_prepare_polyfit(const char* input_filename);
+static void atmo_filter_resultset(double value_min, double value_max,
+		const char* column_name,
+		const char* fits_file_input,
+		const char* fits_file_output);
+static void atmo_prepare_fit_025_HK(const char* input_filename,
+		const char* output_filename);
+static void atmo_prepare_poly_net(cpl_polynomial* poly, const char* filename);
+static void atmo_apply_cube_polynomial_shift(cpl_polynomial* poly,
+		const char* fits_file,
+		const char* out_file);
+static void atmo_apply_cube_polynomial_shift_list(
+		cpl_polynomial* poly,
+		const char* list_file);
+static void atmo_save_polynom(cpl_polynomial* poly,
+		const char* filename,
+		cpl_propertylist* plist);
+static cpl_polynomial* atmo_load_polynom(const char* filename);
+/*------------------------------------------------------------*/
+
+static cpl_error_code atmo_disp_load_params(
+		const char* fits_file,
+		int * centpix,
+		double* lambda0,
+		double *Tc,
+		double* rh,
+		double* airm,
+		double* p,
+		double*	parallactic,
+		double* pixelscale,
+		double* pixelsz)
+{
+	double * VALS_DOUBLE[10];
+	const char* NAME_DOUBLE[10] = {
+			"CRVAL3",
+			"ESO TEL AMBI TEMP",
+			"ESO TEL AMBI RHUM",
+			"ESO TEL AIRM START",
+			"ESO TEL AIRM END",
+			"ESO TEL AMBI PRES START",
+			"ESO TEL AMBI PRES END",
+			"ESO ADA ABSROT START",
+			"ESO ADA ABSROT END",
+//			"ESO TEL PARANG START",
+//			"ESO TEL PARANG END",
+			"CDELT3"
+	};
+	double airmass_start;
+	double airmass_end;
+	double pres_start,	pres_end;
+	double parang_start, parang_end;
+	cpl_propertylist* plist = cpl_propertylist_load(fits_file, 0);
+	cpl_error_code err = CPL_ERROR_NONE;
+	int sz = 0;
+	int i ;
+
+
+	VALS_DOUBLE[0] = lambda0;
+	VALS_DOUBLE[1] = Tc;
+	VALS_DOUBLE[2] = rh;
+	VALS_DOUBLE[3] = &airmass_start;
+	VALS_DOUBLE[4] = &airmass_end;
+	VALS_DOUBLE[5] = &pres_start;
+	VALS_DOUBLE[6] = &pres_end;
+
+	VALS_DOUBLE[7] =  &parang_start;
+	VALS_DOUBLE[8] =  &parang_end;
+	VALS_DOUBLE[9] =  pixelsz;
+
+
+	cpl_test(plist);
+	if (plist == 0)
+	{
+		cpl_msg_warning (cpl_func, "could not open the file[%s]", fits_file);
+		cpl_error_reset();
+		return CPL_ERROR_FILE_IO;
+	}
+	sz = sizeof(NAME_DOUBLE) / sizeof(NAME_DOUBLE[0]);
+	for (i = 0; i < sz; i++)
+	{
+		*(VALS_DOUBLE[i]) = cpl_propertylist_get_double(plist, NAME_DOUBLE[i]);
+		err = cpl_error_get_code();
+		if(err != CPL_ERROR_NONE)
+		{
+			cpl_error_reset();
+			return err;
+		}
+	}
+
+	*centpix = cpl_propertylist_get_int(plist, "CRPIX3");
+	{
+		const char* optiname = cpl_propertylist_get_string(plist, "ESO INS OPTI1 NAME");
+
+		float f = 0;
+		sscanf(optiname, "%f", &f);
+		*pixelscale = f;
+	}
+
+	err = cpl_error_get_code();
+	if (err != CPL_ERROR_NONE)
+	{
+		cpl_error_reset();
+		return err;
+	}
+	*airm = (airmass_start + airmass_end) / 2;
+	*p = (pres_start + pres_end) / (2 * 0.750064); // 0.75 for conversion from mm to mbar
+	*parallactic = (parang_start + parang_end) / 2;
+	cpl_propertylist_delete(plist);
+	return err;
+}
+
+
+static void
+sinfo_fit_poly(cpl_table* ptable,
+               const char* col_x,
+               const char* col_y,
+               const int order)
+{
+   /*
+    * The "dummy" table is just a tool for eliminating invalid
+    * points from the vectors to be fitted.
+    */
+   cpl_polynomial *py=NULL;
+   int nrows=0;
+   cpl_vector* vx=NULL;
+   cpl_vector* vy=NULL;
+   int i=0;
+   cpl_error_code err = CPL_ERROR_NONE;
+
+   nrows=cpl_table_get_nrow(ptable);
+   vx = cpl_vector_new(nrows);
+   vy = cpl_vector_new(nrows);
+   for (i = 0; i < nrows; i++)
+   {
+	   int inull = 0;
+	   double dy = cpl_table_get_double(ptable, col_y, i, &inull);
+	   double dx = cpl_table_get_int(ptable, col_x, i, &inull);
+	   cpl_vector_set(vy, i, dy);
+	   cpl_vector_set(vx, i, dx);
+   }
+//   cpl_table_save(dummy,NULL,NULL,"pippo.fits",CPL_IO_DEFAULT);
+//   cpl_table_save(ptable,NULL,NULL,"or_pippo.fits",CPL_IO_DEFAULT);
+
+   if (nrows < 2 * order)
+   {
+	  cpl_msg_warning(cpl_func, "number of points is not enough for fit");
+      goto cleanup;
+   }
+//   cpl_table_fill_invalid_double(dummy, "x", 0);
+//   cpl_table_fill_invalid_double(dummy, "y", 0);
+   err = cpl_error_get_code();
+   if (err == CPL_ERROR_NONE)
+   {
+	   py = sinfo_polynomial_fit_1d_create(vx, vy, order, NULL);
+	   cpl_polynomial_dump(py,stdout);
+/*	   coef=cpl_vector_new(order);
+	   pows[0]=0;
+
+	   for(i=0;i<order;i++)
+	   {
+		  pows[0]=i;
+		  cpl_vector_set(coef,i,cpl_polynomial_get_coeff(py,pows));
+		  sinfo_msg("coef=%g",cpl_polynomial_get_coeff(py,pows));
+	   }
+	   cpl_vector_dump(coef,stdout);*/
+   }
+   else
+   {
+	   cpl_msg_warning(cpl_func, "cpl error occured [2]");
+   }
+  cleanup:
+//   sinfoni_free_vector(&coef);
+//   sinfo_free_table(&dummy);
+   cpl_vector_delete(vx);
+   cpl_vector_delete(vy);
+   cpl_polynomial_delete(py);
+   return;
+}
+static void atmo_save_gauss_info(cpl_table * ptable, cpl_imagelist* pCube)
+{
+	int sz = cpl_imagelist_get_size(pCube);
+	int i;
+	cpl_table_new_column(ptable, COL_NAME_ID, CPL_TYPE_INT);
+	cpl_table_new_column(ptable, COL_NAME_CENTRE_X, CPL_TYPE_DOUBLE);
+	cpl_table_new_column(ptable, COL_NAME_CENTRE_Y, CPL_TYPE_DOUBLE);
+	for (i = 0; i < sz; i++)
+	{
+		cpl_image * pimage = cpl_imagelist_get(pCube, i);
+		double    	 norm;
+		double   	xcen;
+		double   	ycen;
+		double   	sig_x;
+		double   	sig_y;
+		double   	fwhm_x;
+		double   	fwhm_y;
+		cpl_error_code err = cpl_image_fit_gaussian(pimage, 32, 32, 15,
+				&norm,
+				&xcen,
+				&ycen,
+				&sig_x,
+				&sig_y,
+				&fwhm_x,
+				&fwhm_y);
+		if (err == CPL_ERROR_NONE && (!isnan(xcen)) && (!isnan(ycen)))
+		{
+			// write to the table
+			cpl_table_set_int(ptable, COL_NAME_ID, i, i);
+			cpl_table_set(ptable, COL_NAME_CENTRE_X, i, xcen);
+			cpl_table_set(ptable, COL_NAME_CENTRE_Y, i, ycen);
+		}
+		else
+		{
+			//cpl_msg_warning(cpl_func, "fit gaussian failed on the image #%d", i);
+			cpl_error_reset();
+		}
+	}
+
+//	sinfo_fit_poly(ptable,COL_NAME_ID, COL_NAME_CENTRE_X, 3);
+//	sinfo_fit_poly(ptable,COL_NAME_ID, COL_NAME_CENTRE_Y, 3);
+
+
+}
+static double atmo_get_general_lambda0(const char* fits_file)
+{
+	int centpix 	= 0;
+	double lambda0	= 0;
+    double Tc 		= 0;
+    double rh 		= 0;
+    double airm 	= 0;
+    double p 		= 0;
+    double parallactic = 0;
+    double pixelscale = 0;
+    double pixelsz = 0;
+    /*cpl_error_code err = */atmo_disp_load_params(fits_file, &centpix, &lambda0, &Tc, &rh, &airm, &p, &parallactic, &pixelscale, &pixelsz);
+    return lambda0;
+}
+static void atmo_test_dispersion_cube( const char* fits_file, const char* out_file)
+{
+	int centpix 	= 0;
+	double lambda0	= 0;
+    double Tc 		= 0;
+    double rh 		= 0;
+    double airm 	= 0;
+    double p 		= 0;
+    double parallactic = 0;
+    double pixelscale = 0;
+    double pixelsz = 0;
+    cpl_table* ptable = 0;
+    cpl_table* ptableresult = 0;
+    cpl_imagelist* pCube = 0;
+    cpl_propertylist* plist = 0;
+    cpl_error_code err = atmo_disp_load_params(fits_file, &centpix, &lambda0, &Tc, &rh, &airm, &p, &parallactic, &pixelscale, &pixelsz);
+    cpl_test(err == CPL_ERROR_NONE);
+    // read the cube
+    pCube = cpl_imagelist_load(fits_file, CPL_TYPE_FLOAT, 0);
+    ptable = cpl_table_new(cpl_imagelist_get_size(pCube));
+    atmo_save_gauss_info(ptable, pCube);
+    cpl_msg_warning(cpl_func, "atmo_test_dispersion_cube parallactic[%f] pixescale[%f]", parallactic, pixelscale);
+    err = sinfo_atm_dispersion_cube(
+    		 pCube,
+       		centpix, // central plane in the cube
+       		lambda0, // wavelength of the central plane
+    		Tc, // temperature in Celsius TEL.AMBI.TEMP
+    		rh, // relative humidity in % TEL.AMBI.RHUM
+    		airm, // airmass for the moment of observation TEL.AMBI.PRES
+    		p, // atmospheric pressure TEL.AMBI.PRES
+    		parallactic, // TEL.PARANG
+    		pixelscale, // couble be for SINFONI 0.025, 0.100, 0.250
+    		pixelsz);
+    ptableresult = cpl_table_new(cpl_imagelist_get_size(pCube));
+    atmo_save_gauss_info(ptableresult, pCube);
+    cpl_test(err == CPL_ERROR_NONE);
+    plist = cpl_propertylist_load(fits_file, 0);
+ //   cpl_imagelist_save(pCube, out_file, CPL_BPP_IEEE_DOUBLE, plist, CPL_IO_CREATE);
+    cpl_table_save(ptable, NULL, NULL, "origin.fits", CPL_IO_CREATE);
+    cpl_table_save(ptableresult, NULL, NULL, out_file, CPL_IO_CREATE);
+    cpl_propertylist_delete(plist);
+    cpl_imagelist_delete(pCube);
+    cpl_table_delete(ptable);
+    cpl_table_delete(ptableresult);
+}
+static void atmo_apply_cube_polynomial_shift(cpl_polynomial* poly, const char* fits_file, const char* out_file)
+{
+	cpl_error_code 	err = CPL_ERROR_NONE;
+    cpl_imagelist* pCube = 0;
+    double lambda0 = 0;
+    double Tc = 0;
+    double rh = 0;
+	double airmass = 0;
+	double p = 0;
+	double parallactic = 0;
+	double pixelscale = 0;
+	double pixelsz = 0;
+	cpl_vector* vparams = 0;
+	int centpix = 0;
+	double * kernel = sinfo_generate_interpolation_kernel("default");
+
+
+	err = atmo_disp_load_params(fits_file, &centpix, &lambda0, &Tc, &rh, &airmass, &p, &parallactic, &pixelscale, &pixelsz);
+	cpl_msg_warning(cpl_func, "centpix[%d] lambda0[%f] angle[%f]", centpix, lambda0, parallactic);
+	parallactic = parallactic * PI_NUMB / 180; // convert to radian
+    pCube = cpl_imagelist_load(fits_file, CPL_TYPE_FLOAT, 0);
+
+    if (pCube && (err == CPL_ERROR_NONE))
+    {
+    	int cubesize = 0;
+    	int i = 0;
+    	double l0_shift_x = 0; // shift for the central point by X
+    	double l0_shift_y = 0; // shift for the central point by Y
+
+    	vparams = cpl_vector_new(2);
+    	cpl_vector_set(vparams, 0, airmass);
+		cpl_vector_set(vparams, 1, lambda0);
+
+		l0_shift_y = cpl_polynomial_eval(poly, vparams); // North - South
+		l0_shift_x = 0; // (EAST-WEST direction)
+
+		// rotate the shift
+   		atmo_rotate_point(&l0_shift_x, &l0_shift_y, parallactic);
+
+
+    	cpl_test(err == CPL_ERROR_NONE);
+        cubesize = cpl_imagelist_get_size(pCube);
+    	for (i = 0; i < cubesize; i++)
+    	{
+    		cpl_image* plane = cpl_imagelist_get(pCube, i);
+    		cpl_image* pimresult = 0;
+    		// calculate the wavelength
+    		double lambda = lambda0 - (centpix - i) * pixelsz;
+    		double shift_y = 0;
+    		double shift_x = 0;
+
+    		cpl_vector_set(vparams, 1, lambda);
+    		// calc the shift
+    		shift_y = cpl_polynomial_eval(poly, vparams); // North - South
+    		shift_x = 0; // (EAST-WEST direction)
+
+    		// rotate the shift
+    		atmo_rotate_point(&shift_x, &shift_y, parallactic);
+    		// apply shift
+    		pimresult = sinfo_new_shift_image(
+    		    plane,
+    		    -(shift_x - l0_shift_x),
+    		    -(shift_y - l0_shift_y),
+    		    kernel);
+    		err = cpl_imagelist_set(pCube, pimresult, i);
+    		if (err != CPL_ERROR_NONE)
+    			break;
+    	}
+    }
+    else
+    {
+    	cpl_msg_warning(cpl_func, "Cannot load the cube [%s]", fits_file);
+    }
+	if (err != CPL_ERROR_NONE)
+	{
+		cpl_msg_warning(cpl_func, "An error during shifting image");
+	}
+	else
+	{
+		cpl_propertylist* plist = 0;
+		plist = cpl_propertylist_load(fits_file, 0);
+		sinfo_new_convert_0_to_ZERO_for_cubes(pCube);
+		cpl_imagelist_save(pCube, out_file, CPL_BPP_IEEE_DOUBLE, plist, CPL_IO_CREATE);
+		cpl_propertylist_delete(plist);
+	}
+	cpl_imagelist_delete(pCube);
+    cpl_vector_delete(vparams);
+	cpl_free(kernel);
+}
+
+static void atmo_init_offset_table(cpl_table** big_table, int big_table_size)
+{
+	*big_table = cpl_table_new(big_table_size);
+	cpl_table_new_column(*big_table, COL_NAME_CENTRE_X, CPL_TYPE_DOUBLE);
+	cpl_table_new_column(*big_table, COL_NAME_CENTRE_Y, CPL_TYPE_DOUBLE);
+	cpl_table_new_column(*big_table, COL_NAME_AIRMASS, CPL_TYPE_DOUBLE);
+	cpl_table_new_column(*big_table, COL_NAME_WAVELENGTH, CPL_TYPE_DOUBLE);
+	cpl_table_new_column(*big_table, COL_NAME_ANGLE, CPL_TYPE_DOUBLE);
+	cpl_table_new_column(*big_table, COL_NAME_OFFSET_X, CPL_TYPE_DOUBLE);
+	cpl_table_new_column(*big_table, COL_NAME_OFFSET_Y, CPL_TYPE_DOUBLE);
+}
+static void atmo_process_fits_data_file(cpl_table** ptable, const char* filename, double general_lambda0)
+{
+	cpl_error_code err = CPL_ERROR_NONE;
+	// open the file
+	const int CUTOFF_PLANES = 80;
+	int centpix 	= 0;
+	double lambda0	= 0;
+	double Tc 		= 0;
+	double rh 		= 0;
+	double airm 	= 0;
+	double p 		= 0;
+	double parallactic = 0;
+	double pixelscale = 0;
+	double pixelsz = 0;
+	int row_lambda0 = -1;
+	int i = 0;
+	int nrow = 0;
+	int cubesize = 0;
+//	cpl_table* ptableresult = 0;
+	cpl_imagelist* pCube = 0;
+	// read the airmass from the file
+
+	err = atmo_disp_load_params(filename, &centpix, &lambda0, &Tc, &rh, &airm, &p, &parallactic, &pixelscale, &pixelsz);
+	if(err != CPL_ERROR_NONE)
+	{
+		cpl_msg_warning(cpl_func, "error [%s]", filename);
+		cpl_error_reset();
+		return;
+	}
+    pCube = cpl_imagelist_load(filename, CPL_TYPE_FLOAT, 0);
+    cubesize = cpl_imagelist_get_size(pCube);
+    atmo_init_offset_table(ptable, cubesize);
+	for (i = CUTOFF_PLANES; i < cubesize - CUTOFF_PLANES; i++)
+	{
+		cpl_image* plane = cpl_imagelist_get(pCube, i);
+		// calculate the wavelength
+		double lambda = lambda0 - (centpix - i) * pixelsz;
+		// for each wavelength
+		// Gaussian fit for x and y
+		// write row to the table:
+		// wavelength, airmass, x_offset, y_offset, sourcefilename
+
+		double    	norm;
+		double   	xcen;
+		double   	ycen;
+		double   	sig_x;
+		double   	sig_y;
+		double   	fwhm_x;
+		double   	fwhm_y;
+
+		err = cpl_image_fit_gaussian(plane, 32, 32, 32,
+				&norm,
+				&xcen,
+				&ycen,
+				&sig_x,
+				&sig_y,
+				&fwhm_x,
+				&fwhm_y);
+//		cpl_msg_warning(cpl_func, "xcen[%f] ycen[%f] lambda[%f] airm[%f] ", xcen,ycen,lambda,airm );
+		if (err == CPL_ERROR_NONE && (!isnan(xcen)) && (!isnan(ycen)))
+		{
+			// write to the table
+			cpl_table_set(*ptable, COL_NAME_CENTRE_X, i, xcen -1);
+			cpl_table_set(*ptable, COL_NAME_CENTRE_Y, i, ycen -1);
+			cpl_table_set(*ptable, COL_NAME_OFFSET_X, i, xcen -1);
+			cpl_table_set(*ptable, COL_NAME_OFFSET_Y, i, ycen -1);
+			cpl_table_set(*ptable, COL_NAME_WAVELENGTH, i, lambda);
+			cpl_table_set(*ptable, COL_NAME_AIRMASS, i, airm);
+			cpl_table_set(*ptable, COL_NAME_ANGLE, i, parallactic);
+			if (fabs(lambda - lambda0) < EPSILON)
+			{
+				row_lambda0 = i;
+			}
+			nrow++;
+		}
+		else
+		{
+//			cpl_msg_warning(cpl_func, "fit gaussian failed on the file[%s]image #%d", filename, i);
+			cpl_error_reset();
+		}
+
+		/*if (i % 10 == 0)
+			cpl_msg_warning(cpl_func, " shift image #%d, size[%d:%d] dx[%f] dy[%f]", i, szx, szy, shiftx, shifty);*/
+
+	}
+	if (row_lambda0 > 0 && (nrow > (cubesize / 3)))
+	{
+		double x_median = 0;
+		double y_median = 0;
+		int isnull = 0;
+		atmo_rotate_offset(*ptable, -parallactic * PI_NUMB / 180);
+		x_median = cpl_table_get(*ptable, COL_NAME_OFFSET_X, row_lambda0, &isnull);
+		y_median = cpl_table_get(*ptable, COL_NAME_OFFSET_Y, row_lambda0, &isnull);
+		cpl_table_erase_invalid_rows(*ptable);
+		cpl_table_add_scalar(*ptable, COL_NAME_OFFSET_X, -x_median);
+		cpl_table_add_scalar(*ptable, COL_NAME_OFFSET_Y, -y_median);
+
+	}
+	else
+	{
+		// the values for lambda0 was not computed - remove the table
+		cpl_msg_warning(cpl_func, "---[%s] is not taken",filename );
+		cpl_table_select_all(*ptable);
+		cpl_table_erase_selected(*ptable);
+	}
+	cpl_imagelist_delete(pCube);
+}
+static void atmo_rotate_offset(cpl_table* ptable, double rot_angle)
+{
+	int i = 0;
+	int nrow = cpl_table_get_nrow(ptable);
+
+	for (i = 0; i < nrow; i++)
+	{
+		int isnull = 0;
+		double x_value = cpl_table_get(ptable,COL_NAME_CENTRE_X, i, &isnull );
+		double y_value = cpl_table_get(ptable,COL_NAME_CENTRE_Y, i, &isnull );
+		if (isnull == 0)
+		{
+			atmo_rotate_point(&x_value, &y_value, rot_angle);
+			cpl_table_set(ptable,COL_NAME_OFFSET_X, i, x_value);
+			cpl_table_set(ptable,COL_NAME_OFFSET_Y, i, y_value);
+		}
+	}
+}
+
+static void atmo_rotate_point(double* x_value, double* y_value, double rot_angle)
+{
+	double newx = *x_value * cos(rot_angle) - *y_value * sin(rot_angle);
+	double newy = *x_value * sin(rot_angle) + *y_value * cos(rot_angle);
+	*x_value = newx;
+	*y_value = newy;
+}
+static void atmo_prepare_offset_table(const char* cfg_filename, const char* output_filename)
+{
+	FILE * pFile;
+    char fitsfilename [1024];
+    cpl_table* tables[1500];
+    cpl_table* big_table = 0;
+    int next_table = 0;
+    int big_table_size = 0;
+    int next_row = 0;
+    pFile = fopen (cfg_filename , "r");
+    memset(&tables[0], 0, sizeof(cpl_table*) * 200);
+	if (pFile == NULL)
+	{
+		perror ("Error opening file");
+		return;
+	}
+	else
+	{
+		double lambda0 = 0;
+		int isLambda0 = 0;
+		// prepare table
+		while (fgets (fitsfilename , 1024 , pFile))
+		{
+			if(fitsfilename[0] != '#')
+			{
+				cpl_table** pptable = 0;
+				if (fitsfilename[strlen(fitsfilename)-1] != 's') // s means "fits"
+				{
+					// remove end-of-line
+					fitsfilename[strlen(fitsfilename)-1] = 0;
+				}
+				cpl_msg_warning(cpl_func, "Process file: [%s]", fitsfilename);
+				if (isLambda0 == 0)
+				{
+					isLambda0 = 1;
+					lambda0 = atmo_get_general_lambda0(fitsfilename);
+				}
+				pptable = &(tables[next_table++]);
+				atmo_process_fits_data_file(pptable, fitsfilename, lambda0);
+				if (*pptable)
+				{
+					big_table_size += cpl_table_get_nrow(*pptable);
+				}
+				else
+				{
+					next_table--;
+				}
+//				cpl_msg_warning(cpl_func, "table size[%d]", big_table_size);
+			}
+
+		}
+		fclose (pFile);
+	}
+
+	// integrate and save the tables
+	cpl_msg_warning(cpl_func, "------------integrate and save the tables");
+	atmo_init_offset_table(&big_table, big_table_size);
+	next_row = 0;
+	for (int i = 0; i < next_table; i++)
+	{
+		int nrow = 0;
+		int j = 0;
+		cpl_table* ptable = tables[i];
+		if (ptable == 0)
+		{
+			cpl_msg_warning(cpl_func, "end of file reached");
+			break;
+		}
+		nrow = cpl_table_get_nrow(ptable);
+
+		for ( j = 0; j < nrow; j++)
+		{
+			int inull;
+			// read from the table
+			double lambda = cpl_table_get(ptable,COL_NAME_WAVELENGTH , j, &inull);
+			double airmas = cpl_table_get(ptable,COL_NAME_AIRMASS , j, &inull);
+			double x_center = cpl_table_get(ptable,COL_NAME_CENTRE_X , j, &inull);
+			double y_center = cpl_table_get(ptable,COL_NAME_CENTRE_Y , j, &inull);
+			double x_offset = cpl_table_get(ptable,COL_NAME_OFFSET_X , j, &inull);
+			double y_offset = cpl_table_get(ptable,COL_NAME_OFFSET_Y , j, &inull);
+			double angle = cpl_table_get(ptable,COL_NAME_ANGLE , j, &inull);
+			// write to the table
+			cpl_table_set(big_table, COL_NAME_OFFSET_X, next_row, x_offset);
+			cpl_table_set(big_table, COL_NAME_OFFSET_Y, next_row, y_offset);
+			cpl_table_set(big_table, COL_NAME_CENTRE_X, next_row, x_center);
+			cpl_table_set(big_table, COL_NAME_CENTRE_Y, next_row, y_center);
+			cpl_table_set(big_table, COL_NAME_WAVELENGTH, next_row, lambda);
+			cpl_table_set(big_table, COL_NAME_AIRMASS, next_row, airmas);
+			cpl_table_set(big_table, COL_NAME_ANGLE, next_row, angle);
+			next_row++;
+		}
+		cpl_table_delete(ptable);
+	}
+	// save the big table
+	cpl_table_save(big_table, NULL, NULL, output_filename, CPL_IO_CREATE);
+	cpl_table_delete(big_table);
+	// release the tables
+}
+static void atmo_filter_resultset(double value_min, double value_max,
+		const char* column_name,
+		const char* fits_file_input,
+		const char* fits_file_output)
+{
+	const char* COLS[] = {
+			COL_NAME_CENTRE_X,
+			COL_NAME_CENTRE_Y,
+			COL_NAME_AIRMASS,
+			COL_NAME_WAVELENGTH,
+			COL_NAME_ANGLE,
+			COL_NAME_OFFSET_X,
+			COL_NAME_OFFSET_Y,
+	};
+	cpl_table* ptable = 0;
+	int nrow = 0;
+	cpl_table* ptableresult = 0;
+	static int ncols = sizeof(COLS) / sizeof(COLS[0]);
+	// open the file
+	ptable = cpl_table_load(fits_file_input, 1,0);
+	if (ptable == 0)
+	{
+		cpl_msg_warning(cpl_func, "cannot load table from file[%s]", fits_file_input);
+		return;
+	}
+	nrow = cpl_table_get_nrow(ptable);
+	atmo_init_offset_table(&ptableresult, nrow);
+	if (ptableresult)
+	{
+		int i;
+		int result_pos = 0;
+		for (i = 0; i < nrow; i++)
+		{
+			int inull = 0;
+			double value = cpl_table_get(ptable, column_name, i, &inull);
+			if (inull == 0 && value <= value_max && value >= value_min)
+			{
+				// copy values to the new table
+				int j;
+				for (j = 0; j < ncols; j++)
+				{
+					double dvalue = cpl_table_get(ptable, COLS[j], i, &inull);
+					cpl_table_set(ptableresult, COLS[j], result_pos, dvalue);
+				}
+				result_pos++;
+			}
+		}
+		cpl_table_erase_invalid_rows(ptableresult);
+		cpl_table_save(ptableresult, NULL, NULL,fits_file_output, CPL_IO_CREATE);
+	}
+	else
+	{
+		cpl_msg_warning(cpl_func, "cannot create result table");
+	}
+	cpl_table_delete(ptable);
+	cpl_table_delete(ptableresult);
+}
+static void atmo_prepare_fit_025_HK(const char* input_filename, const char* output_filename)
+{
+	const double AIRMASS_MIN = 1.07;
+	const double AIRMASS_MAX = 2.25;
+	const double WAVELENGTH_MIN = 1.45;
+	const double WAVELENGTH_MAX = 2.5;
+	const double OFFSET_Y_MIN = -7;
+	const double OFFSET_Y_MAX = 5;
+	atmo_filter_resultset(AIRMASS_MIN,AIRMASS_MAX, COL_NAME_AIRMASS, input_filename, output_filename);
+	atmo_filter_resultset(WAVELENGTH_MIN,WAVELENGTH_MAX, COL_NAME_WAVELENGTH, output_filename, output_filename);
+	atmo_filter_resultset(OFFSET_Y_MIN,OFFSET_Y_MAX, COL_NAME_OFFSET_Y, output_filename, output_filename);
+}
+static void atmo_prepare_fit_025_J(const char* input_filename, const char* output_filename)
+{
+	const double OFFSET_Y_MIN = -6;
+	const double OFFSET_Y_MAX = 4;
+	atmo_filter_resultset(OFFSET_Y_MIN,OFFSET_Y_MAX, COL_NAME_OFFSET_Y, input_filename, output_filename);
+}
+static void atmo_filter_angle(const char* input_filename, const char* output_filename, double min, double max)
+{
+	atmo_filter_resultset(min,max, COL_NAME_ANGLE, input_filename, output_filename);
+}
+
+static cpl_polynomial* atmo_prepare_polyfit(const char* input_filename)
+{
+	cpl_polynomial  * fit2d = 0;
+	cpl_matrix      * points = 0;
+	cpl_vector      * fitvals = 0;
+	cpl_error_code    err = CPL_ERROR_NONE;
+	int maxdeg2d = 3;
+	cpl_table* ptable;
+
+	ptable = cpl_table_load(input_filename, 1,0);
+	if (ptable)
+	{
+		int nrow = 0;
+		int i = 0;
+		int inull = 0;
+		nrow = cpl_table_get_nrow(ptable);
+		points = cpl_matrix_new(2, nrow);
+		fitvals = cpl_vector_new(nrow);
+		for (i = 0; i < nrow; i++)
+		{
+			double airmass = cpl_table_get(ptable, COL_NAME_AIRMASS, i, &inull);
+			double wavelength= cpl_table_get(ptable, COL_NAME_WAVELENGTH, i, &inull);
+			double offsety 	= cpl_table_get(ptable, COL_NAME_OFFSET_Y, i, &inull);
+			if (inull == 0)
+			{
+				cpl_matrix_set(points, 0, i,airmass );
+				cpl_matrix_set(points, 1, i,wavelength );
+				cpl_vector_set(fitvals, i, offsety);
+			}
+			else
+			{
+				cpl_msg_warning(cpl_func, "invalid element #%d", i);
+			}
+		}
+		err = cpl_error_get_code();
+		if (err == CPL_ERROR_NONE)
+		{
+			fit2d = cpl_polynomial_new(2);
+			err = cpl_polynomial_fit(fit2d, points, NULL, fitvals, NULL, CPL_FALSE,
+										 NULL, &maxdeg2d);
+			if (err == CPL_ERROR_NONE)
+			{
+				cpl_polynomial_dump(fit2d, stdout);
+			}
+			else
+			{
+				cpl_msg_error(cpl_func, "error during polyfit");
+				cpl_polynomial_delete(fit2d);
+				fit2d = 0;
+			}
+		}
+		else
+		{
+			cpl_msg_error(cpl_func, "error before polyfit");
+		}
+	}
+	cpl_vector_delete(fitvals);
+	cpl_matrix_delete(points);
+	cpl_table_delete(ptable);
+	return fit2d;
+}
+static void atmo_prepare_poly_net(cpl_polynomial* poly, const char* filename)
+{
+	const double AIRMASS_MIN = 1.0;
+	const double AIRMASS_MAX = 2.4;
+	const double WAVELENGTH_MIN = 1.4;
+	const double WAVELENGTH_MAX = 2.5;
+	const int N_AIRMASS = 100;
+	const int N_WAVELENGTH = 1000;
+	cpl_table* ptable = 0;
+	int i, j;
+	cpl_vector* vargs = 0;
+
+	vargs = cpl_vector_new(2);
+	ptable = cpl_table_new(N_AIRMASS * N_WAVELENGTH);
+	cpl_table_new_column(ptable, COL_NAME_AIRMASS, CPL_TYPE_DOUBLE);
+	cpl_table_new_column(ptable, COL_NAME_WAVELENGTH, CPL_TYPE_DOUBLE);
+	cpl_table_new_column(ptable, COL_NAME_OFFSET_Y, CPL_TYPE_DOUBLE);
+	for (i = 0; i < N_AIRMASS; i++)
+	{
+		double airmass =
+			1.0* AIRMASS_MIN + i * (AIRMASS_MAX - AIRMASS_MIN) / N_AIRMASS;
+		for (j = 0; j < N_WAVELENGTH; j++)
+		{
+			double wavelength =
+				1.0 * WAVELENGTH_MIN +  j *(WAVELENGTH_MAX - WAVELENGTH_MIN) / N_WAVELENGTH;
+			double result = 0;
+			cpl_vector_set(vargs, 0, airmass);
+			cpl_vector_set(vargs, 1, wavelength);
+			result = cpl_polynomial_eval(poly, vargs);
+			cpl_table_set(ptable, COL_NAME_AIRMASS, i * N_WAVELENGTH + j, airmass);
+			cpl_table_set(ptable, COL_NAME_WAVELENGTH, i * N_WAVELENGTH + j, wavelength);
+			cpl_table_set(ptable, COL_NAME_OFFSET_Y, i * N_WAVELENGTH + j, result);
+		}
+	}
+	cpl_table_save(ptable, NULL, NULL,filename, CPL_IO_CREATE);
+	cpl_table_delete(ptable);
+	cpl_vector_delete(vargs);
+}
+static void atmo_apply_cube_polynomial_shift_list(cpl_polynomial* poly, const char* list_file)
+{
+	FILE * pFile;
+    char fitsfilename [1024];
+    pFile = fopen (list_file , "r");
+
+    if (pFile == NULL)
+ 	{
+ 		perror ("Error opening file");
+ 		return;
+ 	}
+ 	else
+ 	{
+ 		// prepare table
+ 		while (fgets (fitsfilename , 1024 , pFile))
+ 		{
+ 			if(fitsfilename[0] != '#')
+ 			{
+ 				char output_file_name[1024];
+ 				memset(&output_file_name[0], 0, 1024);
+ 				if (fitsfilename[strlen(fitsfilename)-1] != 's') // s means "fits"
+ 				{
+ 					// remove end-of-line
+ 					fitsfilename[strlen(fitsfilename)-1] = 0;
+ 				}
+ 				// prepare outputfilename
+ 				sprintf(output_file_name, "output/%s.corrected.fits", fitsfilename);
+ 				cpl_msg_warning(cpl_func, "Process file: [%s]", fitsfilename);
+ 				atmo_apply_cube_polynomial_shift(poly, fitsfilename, output_file_name);
+ 			}
+
+ 		}
+ 		fclose (pFile);
+ 	}
+
+}
+static void atmo_get_poly_coeff(
+		cpl_polynomial* poly,
+		int dim ,
+		int degree,
+		int* exp,
+		int step,
+		cpl_table* ptable,
+		int* curr_row)
+{
+	int i = 0;
+	for (i = 0; i <= degree; i++)
+	{
+		exp[step] = i;
+		if(step == dim - 1)
+		{
+			double coeff = cpl_polynomial_get_coeff(poly, exp);
+			if (fabs(coeff) > EPSILON)
+			{
+				int j = 0;
+				for (j = 0; j < dim; j++)
+				{
+					char col_name[255];
+					sprintf(col_name, "col_%d", j);
+					cpl_table_set_int(ptable, col_name, *curr_row, exp[j]);
+				}
+				cpl_table_set(ptable, "value", *curr_row, coeff);
+				(*curr_row)++;
+			}
+		}
+		else
+		{
+			atmo_get_poly_coeff(poly, dim, degree - i, exp, step + 1,
+					ptable, curr_row);
+		}
+	}
+}
+static void atmo_save_polynom(cpl_polynomial* poly,
+		const char* filename,
+		cpl_propertylist* plist)
+{
+	cpl_table* ptable = 0;
+	int dim = 0;
+	int degree = 0;
+	int* exp = 0;
+	int i = 0;
+	int curr_row = 0;
+	if (!poly)
+		return;
+	if (!filename)
+		return;
+
+	dim = cpl_polynomial_get_dimension(poly);
+	degree = cpl_polynomial_get_degree(poly);
+	exp = cpl_malloc(dim * sizeof(exp[0]));
+	memset(&exp[0], 0, dim * sizeof(exp[0]));
+
+	ptable = cpl_table_new(pow(degree + 1, dim));
+	for (i = 0; i < dim; i++)
+	{
+		char col_name[255];
+		sprintf(col_name, "col_%d", i);
+		cpl_table_new_column(ptable, col_name, CPL_TYPE_INT);
+	}
+	cpl_table_new_column(ptable, "value", CPL_TYPE_DOUBLE);
+	atmo_get_poly_coeff(poly, dim, degree, exp,0, ptable, &curr_row);
+	cpl_table_erase_invalid_rows(ptable);
+	cpl_table_save(ptable, plist, NULL, filename, CPL_IO_CREATE);
+	cpl_table_delete(ptable);
+	cpl_free(exp);
+}
+
+static cpl_polynomial* atmo_load_polynom(const char* filename)
+{
+	cpl_polynomial* poly = 0;
+	cpl_table* ptable = 0;
+
+	ptable = cpl_table_load(filename, 1, 0);
+	if (ptable)
+	{
+		int dim = 0;
+		int nrows = 0;
+		int i = 0;
+		int* exp = 0;
+
+		dim = cpl_table_get_ncol(ptable) - 1;
+		poly = cpl_polynomial_new(dim );
+		nrows = cpl_table_get_nrow(ptable);
+		exp = cpl_malloc(dim * sizeof(exp[0]));
+		memset(&exp[0], 0, dim * sizeof(exp[0]));
+		for (int i = 0; i < nrows; i++)
+		{
+			int j = 0;
+			int inull = 0;
+			double value = 0;
+			for (j = 0; j < dim; j++)
+			{
+				char col_name[255];
+				sprintf(col_name, "col_%d", j);
+				exp[j] = cpl_table_get_int(ptable, col_name, i, &inull);
+			}
+			value = cpl_table_get(ptable, "value", i, &inull);
+			cpl_polynomial_set_coeff(poly, exp, value);
+		}
+		cpl_free(exp);
+	}
+	cpl_table_delete(ptable);
+	return poly;
+}
+int frame_cmp(cpl_frame* frame1, cpl_frame* frame2)
+{
+	return 1; //(frame1 == frame2) ? 1 : 0;
+}
+int main(int argc, char* argv[])
+{
+	cpl_polynomial * poly = 0;
+	cpl_test_init(SINFO_STAR_BUG_REPORT, CPL_MSG_WARNING);
+	/*********************************
+	 */
+	/*{
+		int ncount = 10;
+		int i = 0;
+		int nb_labels = 0;
+		int* selection = 0;
+		cpl_frameset* p = cpl_frameset_new();
+		cpl_frameset* p_extracted = 0;
+		for (i = 0; i < ncount; i++)
+		{
+			cpl_frame* pframe = cpl_frame_new();
+			cpl_frameset_insert(p, pframe);
+		}
+		selection = cpl_frameset_labelise(p, frame_cmp, &nb_labels);
+		for (i = -10; i < ncount + 10; i++)
+		{
+			p_extracted = cpl_frameset_extract(p, selection, i);
+			cpl_frameset_delete(p_extracted);
+		}
+		cpl_frameset_delete(p);
+		cpl_free(selection);
+		return 0;
+	}*/
+
+	 /***************************/
+	if (argc<3)
+	{
+		return 0;
+	}
+//	atmo_prepare_offset_table(argv[1], argv[2]);
+//	atmo_prepare_fit_025_J(argv[1], argv[2]);
+//	atmo_filter_angle(argv[1], argv[2], -150, 20);
+	poly = atmo_prepare_polyfit(argv[1]);
+	if (poly)
+	{
+		cpl_propertylist* plist = cpl_propertylist_new();
+		cpl_propertylist_append_string(plist, "HIERARCH ESO INS OPTI1 NAME", "0.025");
+		atmo_save_polynom(poly, argv[2], plist);
+/*		cpl_polynomial* poly_saved = atmo_load_polynom(argv[2]);
+		if (cpl_polynomial_compare(poly, poly_saved, EPSILON) == 0)
+		{
+			cpl_msg_warning(cpl_func, "Polynomials are the same");
+		}
+		else
+		{
+			cpl_msg_warning(cpl_func, "Polynomials are different");
+		}*/
+		atmo_prepare_poly_net(poly, argv[3]);
+//		atmo_apply_cube_polynomial_shift_list(poly, argv[2]);
+//		atmo_apply_cube_polynomial_shift(poly, argv[2], argv[3]);*/
+		cpl_polynomial_delete(poly);
+//		cpl_polynomial_delete(poly_saved);
+		cpl_propertylist_delete(plist);
+	}
+
+//	atmo_prepare_offset_table("/diskb/kmirny/sinfoni/atm_disp/250/250.input", "/diskb/kmirny/sinfoni/atm_disp/250/250.result.fits");
+//	atmo_prepare_offset_table(argv[1], argv[2]);
+//	atmo_test_dispersion_cube("/diskb/kmirny/sinfoni/sinfo_demo/pro/sinfo_rec_jitter_stdstar/out_0013.fits",
+//			"out_0013a.fits");
+//	atmo_test_dispersion_cube("/diskb/kmirny/sinfoni/atm_dispersion/SI_SCDJ_291811_2008-02-07T03:36:17.586_5_H+K_025.fits",
+//			"/diskb/kmirny/sinfoni/atm_dispersion/SSI_SCDJ_291811_2008-02-07T03:36:17.586_5_H+K_025_result.fits");
+//		atmo_test_dispersion_cube("/diskb/kmirny/sinfoni/atm_dispersion/SI_PCST_080124A_H+K_025.fits",
+//				"/diskb/kmirny/sinfoni/atm_dispersion/SI_PCST_080124A_H+K_025_result.fits");
+//	atmo_test_dispersion_cube("/diskb/kmirny/sinfoni/atm_dispersion/diffract_std/SI_PCST_050512A_H+K_025.fits",
+//			"/diskb/kmirny/sinfoni/atm_dispersion/diffract_std/SI_PCST_050512A_H+K_025_result.fits");
+
+	return cpl_test_end(0);
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/cpl-plugin-sinfo.git



More information about the debian-science-commits mailing list